From: Wolfgang Bangerth Date: Tue, 27 Aug 2019 23:16:43 +0000 (-0600) Subject: Rearrange code for better readability. X-Git-Tag: v9.2.0-rc1~1165^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d2d8e8a80d7c618f608daa8bd4e03b950d1d307;p=dealii.git Rearrange code for better readability. Specifically, use a 'switch' statement instead of a sequence of if-else-if, and move the simplest case to the top. So far, the simplest case was just the fall-through, but it actually has a name -- so I test that as well and make the fall-through into an assertion. --- diff --git a/include/deal.II/numerics/data_out_dof_data.templates.h b/include/deal.II/numerics/data_out_dof_data.templates.h index 26697b0102..f0d1459e45 100644 --- a/include/deal.II/numerics/data_out_dof_data.templates.h +++ b/include/deal.II/numerics/data_out_dof_data.templates.h @@ -1348,89 +1348,105 @@ DataOut_DoFData:: for (unsigned int i = 0; i < (*d)->n_output_variables;) // see what kind of data we have here. note that for the purpose of the // current function all we care about is vector data - if ((*d)->data_component_interpretation[i] == - DataComponentInterpretation::component_is_part_of_vector) + switch ((*d)->data_component_interpretation[i]) { - // ensure that there is a continuous number of next space_dim - // components that all deal with vectors - Assert(i + patch_space_dim <= (*d)->n_output_variables, - Exceptions::DataOutImplementation::ExcInvalidVectorDeclaration( - i, (*d)->names[i])); - for (unsigned int dd = 1; dd < patch_space_dim; ++dd) - Assert( - (*d)->data_component_interpretation[i + dd] == - DataComponentInterpretation::component_is_part_of_vector, - Exceptions::DataOutImplementation::ExcInvalidVectorDeclaration( - i, (*d)->names[i])); - - // all seems alright, so figure out whether there is a common name to - // these components. if not, leave the name empty and let the output - // format writer decide what to do here - std::string name = (*d)->names[i]; - for (unsigned int dd = 1; dd < patch_space_dim; ++dd) - if (name != (*d)->names[i + dd]) - { - name = ""; - break; - } - - // finally add a corresponding range - ranges.emplace_back(std::forward_as_tuple( - output_component, - output_component + patch_space_dim - 1, - name, - DataComponentInterpretation::component_is_part_of_vector)); - - // increase the 'component' counter by the appropriate amount, same - // for 'i', since we have already dealt with all these components - output_component += patch_space_dim; - i += patch_space_dim; - } - else if ((*d)->data_component_interpretation[i] == - DataComponentInterpretation::component_is_part_of_tensor) - { - const unsigned int size = patch_space_dim * patch_space_dim; - // ensure that there is a continuous number of next - // space_dim*space_dim components that all deal with tensors - Assert(i + size <= (*d)->n_output_variables, - Exceptions::DataOutImplementation::ExcInvalidTensorDeclaration( - i, (*d)->names[i])); - for (unsigned int dd = 1; dd < size; ++dd) - Assert( - (*d)->data_component_interpretation[i + dd] == - DataComponentInterpretation::component_is_part_of_tensor, - Exceptions::DataOutImplementation::ExcInvalidTensorDeclaration( - i, (*d)->names[i])); - - // all seems alright, so figure out whether there is a common name to - // these components. if not, leave the name empty and let the output - // format writer decide what to do here - std::string name = (*d)->names[i]; - for (unsigned int dd = 1; dd < size; ++dd) - if (name != (*d)->names[i + dd]) - { - name = ""; - break; - } - - // finally add a corresponding range - ranges.emplace_back(std::forward_as_tuple( - output_component, - output_component + size - 1, - name, - DataComponentInterpretation::component_is_part_of_tensor)); - - // increase the 'component' counter by the appropriate amount, same - // for 'i', since we have already dealt with all these components - output_component += size; - i += size; - } - else - { - // just move one component forward by one, or two if the vector - // happens to be complex-valued - ++i; - output_component += ((*d)->is_complex_valued() ? 2 : 1); + case DataComponentInterpretation::component_is_scalar: + { + // just move one component forward by one, or two if the component + // happens to be complex-valued + ++i; + output_component += ((*d)->is_complex_valued() ? 2 : 1); + + break; + } + + case DataComponentInterpretation::component_is_part_of_vector: + { + // ensure that there is a continuous number of next space_dim + // components that all deal with vectors + Assert( + i + patch_space_dim <= (*d)->n_output_variables, + Exceptions::DataOutImplementation::ExcInvalidVectorDeclaration( + i, (*d)->names[i])); + for (unsigned int dd = 1; dd < patch_space_dim; ++dd) + Assert( + (*d)->data_component_interpretation[i + dd] == + DataComponentInterpretation::component_is_part_of_vector, + Exceptions::DataOutImplementation:: + ExcInvalidVectorDeclaration(i, (*d)->names[i])); + + // all seems alright, so figure out whether there is a common name + // to these components. if not, leave the name empty and let the + // output format writer decide what to do here + std::string name = (*d)->names[i]; + for (unsigned int dd = 1; dd < patch_space_dim; ++dd) + if (name != (*d)->names[i + dd]) + { + name = ""; + break; + } + + // finally add a corresponding range + ranges.emplace_back(std::forward_as_tuple( + output_component, + output_component + patch_space_dim - 1, + name, + DataComponentInterpretation::component_is_part_of_vector)); + + // increase the 'component' counter by the appropriate amount, + // same for 'i', since we have already dealt with all these + // components + output_component += patch_space_dim; + i += patch_space_dim; + + break; + } + + case DataComponentInterpretation::component_is_part_of_tensor: + { + const unsigned int size = patch_space_dim * patch_space_dim; + // ensure that there is a continuous number of next + // space_dim*space_dim components that all deal with tensors + Assert( + i + size <= (*d)->n_output_variables, + Exceptions::DataOutImplementation::ExcInvalidTensorDeclaration( + i, (*d)->names[i])); + for (unsigned int dd = 1; dd < size; ++dd) + Assert( + (*d)->data_component_interpretation[i + dd] == + DataComponentInterpretation::component_is_part_of_tensor, + Exceptions::DataOutImplementation:: + ExcInvalidTensorDeclaration(i, (*d)->names[i])); + + // all seems alright, so figure out whether there is a common name + // to these components. if not, leave the name empty and let the + // output format writer decide what to do here + std::string name = (*d)->names[i]; + for (unsigned int dd = 1; dd < size; ++dd) + if (name != (*d)->names[i + dd]) + { + name = ""; + break; + } + + // finally add a corresponding range + ranges.emplace_back(std::forward_as_tuple( + output_component, + output_component + size - 1, + name, + DataComponentInterpretation::component_is_part_of_tensor)); + + // increase the 'component' counter by the appropriate amount, + // same for 'i', since we have already dealt with all these + // components + output_component += size; + i += size; + + break; + } + + default: + Assert(false, ExcNotImplemented()); } // note that we do not have to traverse the list of cell data here because