@@ -87,16 +87,16 @@ static int CeedOperatorCheckField(Ceed ceed, CeedQFunctionField qf_field, CeedEl
8787 @param[in] op_field `CeedOperator` Field to view
8888 @param[in] qf_field `CeedQFunction` Field (carries field name)
8989 @param[in] field_number Number of field being viewed
90- @param[in] sub true indicates sub-operator, which increases indentation; false for top-level operator
90+ @param[in] tabs Tabs to append before each line
9191 @param[in] input true for an input field; false for output field
9292 @param[in] stream Stream to view to, e.g., `stdout`
9393
9494 @return An error code: 0 - success, otherwise - failure
9595
9696 @ref Utility
9797**/
98- static int CeedOperatorFieldView (CeedOperatorField op_field , CeedQFunctionField qf_field , CeedInt field_number , bool sub , bool input , FILE * stream ) {
99- const char * pre = sub ? " " : "" ;
98+ static int CeedOperatorFieldView (CeedOperatorField op_field , CeedQFunctionField qf_field , CeedInt field_number , const char * tabs , bool input ,
99+ FILE * stream ) {
100100 const char * in_out = input ? "Input" : "Output" ;
101101 const char * field_name ;
102102 CeedInt size ;
@@ -112,12 +112,12 @@ static int CeedOperatorFieldView(CeedOperatorField op_field, CeedQFunctionField
112112 "%s %s field %" CeedInt_FMT
113113 ":\n"
114114 "%s Name: \"%s\"\n" ,
115- pre , in_out , field_number , pre , field_name );
116- fprintf (stream , "%s Size: %" CeedInt_FMT "\n" , pre , size );
117- fprintf (stream , "%s EvalMode: %s\n" , pre , CeedEvalModes [eval_mode ]);
118- if (basis == CEED_BASIS_NONE ) fprintf (stream , "%s No basis\n" , pre );
119- if (vec == CEED_VECTOR_ACTIVE ) fprintf (stream , "%s Active vector\n" , pre );
120- else if (vec == CEED_VECTOR_NONE ) fprintf (stream , "%s No vector\n" , pre );
115+ tabs , in_out , field_number , tabs , field_name );
116+ fprintf (stream , "%s Size: %" CeedInt_FMT "\n" , tabs , size );
117+ fprintf (stream , "%s EvalMode: %s\n" , tabs , CeedEvalModes [eval_mode ]);
118+ if (basis == CEED_BASIS_NONE ) fprintf (stream , "%s No basis\n" , tabs );
119+ if (vec == CEED_VECTOR_ACTIVE ) fprintf (stream , "%s Active vector\n" , tabs );
120+ else if (vec == CEED_VECTOR_NONE ) fprintf (stream , "%s No vector\n" , tabs );
121121
122122 CeedCall (CeedVectorDestroy (& vec ));
123123 CeedCall (CeedBasisDestroy (& basis ));
@@ -128,16 +128,15 @@ static int CeedOperatorFieldView(CeedOperatorField op_field, CeedQFunctionField
128128 @brief View a single `CeedOperator`
129129
130130 @param[in] op `CeedOperator` to view
131- @param[in] sub Boolean flag for sub-operator
131+ @param[in] tabs Tabs to append before each new line
132132 @param[in] stream Stream to write; typically `stdout` or a file
133133
134134 @return Error code: 0 - success, otherwise - failure
135135
136136 @ref Utility
137137**/
138- int CeedOperatorSingleView (CeedOperator op , bool sub , FILE * stream ) {
138+ int CeedOperatorSingleView (CeedOperator op , const char * tabs , FILE * stream ) {
139139 bool is_at_points ;
140- const char * pre = sub ? " " : "" ;
141140 CeedInt num_elem , num_qpts , total_fields = 0 , num_input_fields , num_output_fields ;
142141 CeedQFunction qf ;
143142 CeedQFunctionField * qf_input_fields , * qf_output_fields ;
@@ -158,23 +157,38 @@ int CeedOperatorSingleView(CeedOperator op, bool sub, FILE *stream) {
158157
159158 CeedCall (CeedOperatorAtPointsGetPoints (op , & rstr_points , NULL ));
160159 CeedCall (CeedElemRestrictionGetMaxPointsInElement (rstr_points , & max_points ));
161- fprintf (stream , "%s %" CeedInt_FMT " elements with %" CeedInt_FMT " max points each\n" , pre , num_elem , max_points );
160+ fprintf (stream , "%s %" CeedInt_FMT " elements with %" CeedInt_FMT " max points each\n" , tabs , num_elem , max_points );
162161 CeedCall (CeedElemRestrictionDestroy (& rstr_points ));
163162 } else {
164- fprintf (stream , "%s %" CeedInt_FMT " elements with %" CeedInt_FMT " quadrature points each\n" , pre , num_elem , num_qpts );
163+ fprintf (stream , "%s %" CeedInt_FMT " elements with %" CeedInt_FMT " quadrature points each\n" , tabs , num_elem , num_qpts );
165164 }
166- fprintf (stream , "%s %" CeedInt_FMT " field%s\n" , pre , total_fields , total_fields > 1 ? "s" : "" );
167- fprintf (stream , "%s %" CeedInt_FMT " input field%s:\n" , pre , num_input_fields , num_input_fields > 1 ? "s" : "" );
165+ fprintf (stream , "%s %" CeedInt_FMT " field%s\n" , tabs , total_fields , total_fields > 1 ? "s" : "" );
166+ fprintf (stream , "%s %" CeedInt_FMT " input field%s:\n" , tabs , num_input_fields , num_input_fields > 1 ? "s" : "" );
168167 for (CeedInt i = 0 ; i < num_input_fields ; i ++ ) {
169- CeedCall (CeedOperatorFieldView (op_input_fields [i ], qf_input_fields [i ], i , sub , 1 , stream ));
168+ CeedCall (CeedOperatorFieldView (op_input_fields [i ], qf_input_fields [i ], i , tabs , 1 , stream ));
170169 }
171- fprintf (stream , "%s %" CeedInt_FMT " output field%s:\n" , pre , num_output_fields , num_output_fields > 1 ? "s" : "" );
170+ fprintf (stream , "%s %" CeedInt_FMT " output field%s:\n" , tabs , num_output_fields , num_output_fields > 1 ? "s" : "" );
172171 for (CeedInt i = 0 ; i < num_output_fields ; i ++ ) {
173- CeedCall (CeedOperatorFieldView (op_output_fields [i ], qf_output_fields [i ], i , sub , 0 , stream ));
172+ CeedCall (CeedOperatorFieldView (op_output_fields [i ], qf_output_fields [i ], i , tabs , 0 , stream ));
174173 }
175174 return CEED_ERROR_SUCCESS ;
176175}
177176
177+ /**
178+ @brief Get the number of tabs to indent for @ref CeedOperatorView() output
179+
180+ @param[in] op `CeedOperator` to get the number of view tabs
181+ @param[out] num_tabs Number of view tabs
182+
183+ @return Error code: 0 - success, otherwise - failure
184+
185+ @ref User
186+ **/
187+ int CeedOperatorGetNumViewTabs (CeedOperator op , CeedInt * num_tabs ) {
188+ * num_tabs = op -> num_tabs ;
189+ return CEED_ERROR_SUCCESS ;
190+ }
191+
178192/**
179193 @brief Find the active input vector `CeedBasis` for a non-composite `CeedOperator`.
180194
@@ -1588,31 +1602,58 @@ int CeedOperatorGetName(CeedOperator op, const char **name) {
15881602 @ref Developer
15891603**/
15901604static int CeedOperatorView_Core (CeedOperator op , FILE * stream , bool is_full ) {
1591- bool has_name , is_composite , is_at_points ;
1592- const char * name = NULL ;
1605+ bool has_name , is_composite , is_at_points ;
1606+ char * tabs = NULL ;
1607+ const char * name = NULL ;
1608+ const CeedInt tab_width = 2 ;
1609+ CeedInt num_tabs = 0 ;
15931610
15941611 CeedCall (CeedOperatorGetName (op , & name ));
15951612 has_name = name ? strlen (name ) : false;
15961613 CeedCall (CeedOperatorIsComposite (op , & is_composite ));
15971614 CeedCall (CeedOperatorIsAtPoints (op , & is_at_points ));
1615+ // Set tabs
1616+ CeedCall (CeedOperatorGetNumViewTabs (op , & num_tabs ));
1617+ CeedCall (CeedCalloc (tab_width * (num_tabs + is_composite ) + 1 , & tabs ));
1618+ for (CeedInt i = 0 ; i < tab_width * num_tabs ; i ++ ) tabs [i ] = ' ' ;
15981619 if (is_composite ) {
15991620 CeedInt num_suboperators ;
16001621 CeedOperator * sub_operators ;
16011622
16021623 CeedCall (CeedOperatorCompositeGetNumSub (op , & num_suboperators ));
16031624 CeedCall (CeedOperatorCompositeGetSubList (op , & sub_operators ));
1625+ fprintf (stream , tabs );
16041626 fprintf (stream , "Composite CeedOperator%s%s\n" , has_name ? " - " : "" , has_name ? name : "" );
1605-
1627+ for ( CeedInt i = 0 ; i < tab_width ; i ++ ) tabs [ tab_width * num_tabs + i ] = ' ' ;
16061628 for (CeedInt i = 0 ; i < num_suboperators ; i ++ ) {
16071629 has_name = sub_operators [i ]-> name ;
1608- fprintf (stream , " SubOperator%s %" CeedInt_FMT "%s%s%s\n" , is_at_points ? " AtPoints" : "" , i , has_name ? " - " : "" ,
1630+ fprintf (stream , tabs );
1631+ fprintf (stream , "SubOperator%s %" CeedInt_FMT "%s%s%s\n" , is_at_points ? " AtPoints" : "" , i , has_name ? " - " : "" ,
16091632 has_name ? sub_operators [i ]-> name : "" , is_full ? ":" : "" );
1610- if (is_full ) CeedCall (CeedOperatorSingleView (sub_operators [i ], 1 , stream ));
1633+ if (is_full ) CeedCall (CeedOperatorSingleView (sub_operators [i ], tabs , stream ));
16111634 }
16121635 } else {
1636+ fprintf (stream , tabs );
16131637 fprintf (stream , "CeedOperator%s%s%s\n" , is_at_points ? " AtPoints" : "" , has_name ? " - " : "" , has_name ? name : "" );
1614- if (is_full ) CeedCall (CeedOperatorSingleView (op , 0 , stream ));
1638+ if (is_full ) CeedCall (CeedOperatorSingleView (op , tabs , stream ));
16151639 }
1640+ CeedCall (CeedFree (& tabs ));
1641+ return CEED_ERROR_SUCCESS ;
1642+ }
1643+
1644+ /**
1645+ @brief Set the number of tabs to indent for @ref CeedOperatorView() output
1646+
1647+ @param[in] op `CeedOperator` to set the number of view tabs
1648+ @param[in] num_tabs Number of view tabs to set
1649+
1650+ @return Error code: 0 - success, otherwise - failure
1651+
1652+ @ref User
1653+ **/
1654+ int CeedOperatorSetNumViewTabs (CeedOperator op , CeedInt num_tabs ) {
1655+ CeedCheck (num_tabs >= 0 , CeedOperatorReturnCeed (op ), CEED_ERROR_MINOR , "Number of view tabs must be non-negative" );
1656+ op -> num_tabs = num_tabs ;
16161657 return CEED_ERROR_SUCCESS ;
16171658}
16181659
0 commit comments