@@ -153,23 +153,24 @@ static int CeedGivensRotation(CeedScalar *A, CeedScalar c, CeedScalar s, CeedTra
153153 @param[in] m Number of rows in array
154154 @param[in] n Number of columns in array
155155 @param[in] a Array to be viewed
156+ @param[in] tabs Tabs to append before each new line
156157 @param[in] stream Stream to view to, e.g., `stdout`
157158
158159 @return An error code: 0 - success, otherwise - failure
159160
160161 @ref Developer
161162**/
162- static int CeedScalarView (const char * name , const char * fp_fmt , CeedInt m , CeedInt n , const CeedScalar * a , FILE * stream ) {
163+ static int CeedScalarView (const char * name , const char * fp_fmt , CeedInt m , CeedInt n , const CeedScalar * a , const char * tabs , FILE * stream ) {
163164 if (m > 1 ) {
164- fprintf (stream , " %s:\n" , name );
165+ fprintf (stream , "%s %s:\n" , tabs , name );
165166 } else {
166167 char padded_name [12 ];
167168
168169 snprintf (padded_name , 11 , "%s:" , name );
169- fprintf (stream , " %-10s" , padded_name );
170+ fprintf (stream , "%s %-10s" , tabs , padded_name );
170171 }
171172 for (CeedInt i = 0 ; i < m ; i ++ ) {
172- if (m > 1 ) fprintf (stream , " [%" CeedInt_FMT "]" , i );
173+ if (m > 1 ) fprintf (stream , "%s [%" CeedInt_FMT "]" , tabs , i );
173174 for (CeedInt j = 0 ; j < n ; j ++ ) fprintf (stream , fp_fmt , fabs (a [i * n + j ]) > 1E-14 ? a [i * n + j ] : 0 );
174175 fputs ("\n" , stream );
175176 }
@@ -723,6 +724,21 @@ int CeedBasisGetCollocatedGrad(CeedBasis basis, CeedScalar *collo_grad_1d) {
723724 return CEED_ERROR_SUCCESS ;
724725}
725726
727+ /**
728+ @brief Get the number of tabs to indent for @ref CeedBasisView() output
729+
730+ @param[in] basis `CeedBasis` to get the number of view tabs
731+ @param[out] num_tabs Number of view tabs
732+
733+ @return Error code: 0 - success, otherwise - failure
734+
735+ @ref Backend
736+ **/
737+ int CeedBasisGetNumViewTabs (CeedBasis basis , CeedInt * num_tabs ) {
738+ * num_tabs = basis -> num_tabs ;
739+ return CEED_ERROR_SUCCESS ;
740+ }
741+
726742/**
727743 @brief Return 1D interpolation matrix to Chebyshev polynomial coefficients on quadrature space
728744
@@ -1892,6 +1908,22 @@ int CeedBasisReferenceCopy(CeedBasis basis, CeedBasis *basis_copy) {
18921908 return CEED_ERROR_SUCCESS ;
18931909}
18941910
1911+ /**
1912+ @brief Set the number of tabs to indent for @ref CeedBasisView() output
1913+
1914+ @param[in] basis `CeedBasis` to set the number of view tabs
1915+ @param[in] num_tabs Number of view tabs to set
1916+
1917+ @return Error code: 0 - success, otherwise - failure
1918+
1919+ @ref User
1920+ **/
1921+ int CeedBasisSetNumViewTabs (CeedBasis basis , CeedInt num_tabs ) {
1922+ CeedCheck (num_tabs >= 0 , CeedBasisReturnCeed (basis ), CEED_ERROR_MINOR , "Number of view tabs must be non-negative" );
1923+ basis -> num_tabs = num_tabs ;
1924+ return CEED_ERROR_SUCCESS ;
1925+ }
1926+
18951927/**
18961928 @brief View a `CeedBasis`
18971929
@@ -1904,6 +1936,7 @@ int CeedBasisReferenceCopy(CeedBasis basis, CeedBasis *basis_copy) {
19041936**/
19051937int CeedBasisView (CeedBasis basis , FILE * stream ) {
19061938 bool is_tensor_basis ;
1939+ char * tabs = NULL ;
19071940 CeedElemTopology topo ;
19081941 CeedFESpace fe_space ;
19091942
@@ -1912,14 +1945,22 @@ int CeedBasisView(CeedBasis basis, FILE *stream) {
19121945 CeedCall (CeedBasisGetTopology (basis , & topo ));
19131946 CeedCall (CeedBasisGetFESpace (basis , & fe_space ));
19141947
1948+ {
1949+ CeedInt num_tabs = 0 ;
1950+
1951+ CeedCall (CeedBasisGetNumViewTabs (basis , & num_tabs ));
1952+ CeedCall (CeedCalloc (CEED_TAB_WIDTH * num_tabs + 1 , & tabs ));
1953+ for (CeedInt i = 0 ; i < CEED_TAB_WIDTH * num_tabs ; i ++ ) tabs [i ] = ' ' ;
1954+ }
1955+
19151956 // Print FE space and element topology of the basis
1916- fprintf (stream , "CeedBasis in a %s on a %s element\n" , CeedFESpaces [fe_space ], CeedElemTopologies [topo ]);
1957+ fprintf (stream , "%sCeedBasis in a %s on a %s element\n" , tabs , CeedFESpaces [fe_space ], CeedElemTopologies [topo ]);
19171958 if (is_tensor_basis ) {
1918- fprintf (stream , " P: %" CeedInt_FMT "\n Q: %" CeedInt_FMT "\n" , basis -> P_1d , basis -> Q_1d );
1959+ fprintf (stream , "%s P: %" CeedInt_FMT "\n%s Q: %" CeedInt_FMT "\n" , tabs , basis -> P_1d , tabs , basis -> Q_1d );
19191960 } else {
1920- fprintf (stream , " P: %" CeedInt_FMT "\n Q: %" CeedInt_FMT "\n" , basis -> P , basis -> Q );
1961+ fprintf (stream , "%s P: %" CeedInt_FMT "\n%s Q: %" CeedInt_FMT "\n" , tabs , basis -> P , tabs , basis -> Q );
19211962 }
1922- fprintf (stream , " dimension: %" CeedInt_FMT "\n field components: %" CeedInt_FMT "\n" , basis -> dim , basis -> num_comp );
1963+ fprintf (stream , "%s dimension: %" CeedInt_FMT "\n%s field components: %" CeedInt_FMT "\n" , tabs , basis -> dim , tabs , basis -> num_comp );
19231964 // Print quadrature data, interpolation/gradient/divergence/curl of the basis
19241965 if (is_tensor_basis ) { // tensor basis
19251966 CeedInt P_1d , Q_1d ;
@@ -1932,10 +1973,10 @@ int CeedBasisView(CeedBasis basis, FILE *stream) {
19321973 CeedCall (CeedBasisGetInterp1D (basis , & interp_1d ));
19331974 CeedCall (CeedBasisGetGrad1D (basis , & grad_1d ));
19341975
1935- CeedCall (CeedScalarView ("qref1d" , "\t% 12.8f" , 1 , Q_1d , q_ref_1d , stream ));
1936- CeedCall (CeedScalarView ("qweight1d" , "\t% 12.8f" , 1 , Q_1d , q_weight_1d , stream ));
1937- CeedCall (CeedScalarView ("interp1d" , "\t% 12.8f" , Q_1d , P_1d , interp_1d , stream ));
1938- CeedCall (CeedScalarView ("grad1d" , "\t% 12.8f" , Q_1d , P_1d , grad_1d , stream ));
1976+ CeedCall (CeedScalarView ("qref1d" , "\t% 12.8f" , 1 , Q_1d , q_ref_1d , tabs , stream ));
1977+ CeedCall (CeedScalarView ("qweight1d" , "\t% 12.8f" , 1 , Q_1d , q_weight_1d , tabs , stream ));
1978+ CeedCall (CeedScalarView ("interp1d" , "\t% 12.8f" , Q_1d , P_1d , interp_1d , tabs , stream ));
1979+ CeedCall (CeedScalarView ("grad1d" , "\t% 12.8f" , Q_1d , P_1d , grad_1d , tabs , stream ));
19391980 } else { // non-tensor basis
19401981 CeedInt P , Q , dim , q_comp ;
19411982 const CeedScalar * q_ref , * q_weight , * interp , * grad , * div , * curl ;
@@ -1950,23 +1991,24 @@ int CeedBasisView(CeedBasis basis, FILE *stream) {
19501991 CeedCall (CeedBasisGetDiv (basis , & div ));
19511992 CeedCall (CeedBasisGetCurl (basis , & curl ));
19521993
1953- CeedCall (CeedScalarView ("qref" , "\t% 12.8f" , 1 , Q * dim , q_ref , stream ));
1954- CeedCall (CeedScalarView ("qweight" , "\t% 12.8f" , 1 , Q , q_weight , stream ));
1994+ CeedCall (CeedScalarView ("qref" , "\t% 12.8f" , 1 , Q * dim , q_ref , tabs , stream ));
1995+ CeedCall (CeedScalarView ("qweight" , "\t% 12.8f" , 1 , Q , q_weight , tabs , stream ));
19551996 CeedCall (CeedBasisGetNumQuadratureComponents (basis , CEED_EVAL_INTERP , & q_comp ));
1956- CeedCall (CeedScalarView ("interp" , "\t% 12.8f" , q_comp * Q , P , interp , stream ));
1997+ CeedCall (CeedScalarView ("interp" , "\t% 12.8f" , q_comp * Q , P , interp , tabs , stream ));
19571998 if (grad ) {
19581999 CeedCall (CeedBasisGetNumQuadratureComponents (basis , CEED_EVAL_GRAD , & q_comp ));
1959- CeedCall (CeedScalarView ("grad" , "\t% 12.8f" , q_comp * Q , P , grad , stream ));
2000+ CeedCall (CeedScalarView ("grad" , "\t% 12.8f" , q_comp * Q , P , grad , tabs , stream ));
19602001 }
19612002 if (div ) {
19622003 CeedCall (CeedBasisGetNumQuadratureComponents (basis , CEED_EVAL_DIV , & q_comp ));
1963- CeedCall (CeedScalarView ("div" , "\t% 12.8f" , q_comp * Q , P , div , stream ));
2004+ CeedCall (CeedScalarView ("div" , "\t% 12.8f" , q_comp * Q , P , div , tabs , stream ));
19642005 }
19652006 if (curl ) {
19662007 CeedCall (CeedBasisGetNumQuadratureComponents (basis , CEED_EVAL_CURL , & q_comp ));
1967- CeedCall (CeedScalarView ("curl" , "\t% 12.8f" , q_comp * Q , P , curl , stream ));
2008+ CeedCall (CeedScalarView ("curl" , "\t% 12.8f" , q_comp * Q , P , curl , tabs , stream ));
19682009 }
19692010 }
2011+ CeedCall (CeedFree (& tabs ));
19702012 return CEED_ERROR_SUCCESS ;
19712013}
19722014
0 commit comments