@@ -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 SGet 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
@@ -1589,30 +1603,58 @@ int CeedOperatorGetName(CeedOperator op, const char **name) {
15891603**/
15901604static int CeedOperatorView_Core (CeedOperator op , FILE * stream , bool is_full ) {
15911605 bool has_name , is_composite , is_at_points ;
1592- const char * name = NULL ;
1606+ char * tabs = NULL ;
1607+ const char * name = NULL ;
1608+ CeedInt num_tabs = 0 ;
15931609
15941610 CeedCall (CeedOperatorGetName (op , & name ));
15951611 has_name = name ? strlen (name ) : false;
15961612 CeedCall (CeedOperatorIsComposite (op , & is_composite ));
15971613 CeedCall (CeedOperatorIsAtPoints (op , & is_at_points ));
1614+ // Set tabs
1615+ CeedCall (CeedOperatorGetNumViewTabs (op , & num_tabs ));
1616+ CeedCall (CeedCalloc (2 * (num_tabs + is_composite ) + 1 , & tabs ));
1617+ for (CeedInt i = 0 ; i < 2 * num_tabs ; i ++ ) tabs [i ] = ' ' ;
15981618 if (is_composite ) {
15991619 CeedInt num_suboperators ;
16001620 CeedOperator * sub_operators ;
16011621
16021622 CeedCall (CeedOperatorCompositeGetNumSub (op , & num_suboperators ));
16031623 CeedCall (CeedOperatorCompositeGetSubList (op , & sub_operators ));
1624+ fprintf (stream , tabs );
16041625 fprintf (stream , "Composite CeedOperator%s%s\n" , has_name ? " - " : "" , has_name ? name : "" );
1626+ tabs [2 * num_tabs + 0 ] = ' ' ;
1627+ tabs [2 * num_tabs + 1 ] = ' ' ;
16051628
16061629 for (CeedInt i = 0 ; i < num_suboperators ; i ++ ) {
16071630 has_name = sub_operators [i ]-> name ;
1608- fprintf (stream , " SubOperator%s %" CeedInt_FMT "%s%s%s\n" , is_at_points ? " AtPoints" : "" , i , has_name ? " - " : "" ,
1631+ fprintf (stream , tabs );
1632+ fprintf (stream , "SubOperator%s %" CeedInt_FMT "%s%s%s\n" , is_at_points ? " AtPoints" : "" , i , has_name ? " - " : "" ,
16091633 has_name ? sub_operators [i ]-> name : "" , is_full ? ":" : "" );
1610- if (is_full ) CeedCall (CeedOperatorSingleView (sub_operators [i ], 1 , stream ));
1634+ if (is_full ) CeedCall (CeedOperatorSingleView (sub_operators [i ], tabs , stream ));
16111635 }
16121636 } else {
1637+ fprintf (stream , tabs );
16131638 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 ));
1639+ if (is_full ) CeedCall (CeedOperatorSingleView (op , tabs , stream ));
16151640 }
1641+ CeedCall (CeedFree (& tabs ));
1642+ return CEED_ERROR_SUCCESS ;
1643+ }
1644+
1645+ /**
1646+ @brief Set the number of tabs to indent for @ref CeedOperatorView() output
1647+
1648+ @param[in] op `CeedOperator` to set the number of view tabs
1649+ @param[in] num_tabs Number of view tabs to set
1650+
1651+ @return Error code: 0 - success, otherwise - failure
1652+
1653+ @ref User
1654+ **/
1655+ int CeedOperatorSetNumViewTabs (CeedOperator op , CeedInt num_tabs ) {
1656+ CeedCheck (num_tabs >= 0 , CeedOperatorReturnCeed (op ), CEED_ERROR_MINOR , "Number of view tabs must be non-negative" );
1657+ op -> num_tabs = num_tabs ;
16161658 return CEED_ERROR_SUCCESS ;
16171659}
16181660
0 commit comments