From 0d9b238991e9c57a2dfe7a6f2f7efcd85d1e64d1 Mon Sep 17 00:00:00 2001 From: Xander Date: Wed, 11 Dec 2024 13:20:12 -0500 Subject: [PATCH] reorganized variable attributes --- applications/allenCahn_conserved/customPDE.h | 8 +- applications/main.cc | 14 +-- include/core/inputFileReader.h | 9 +- include/core/matrixFreePDE.h | 8 +- include/core/userInputParameters.h | 32 +++--- include/core/variableAttributeLoader.h | 18 +++- include/core/variableAttributes.h | 2 + .../boundary_conditions/boundaryConditions.cc | 14 +-- src/core/buildFields.cc | 6 +- src/core/checkpoint.cc | 8 +- src/core/init.cc | 2 +- .../initial_conditions/initialConditions.cc | 11 +-- src/core/inputFileReader.cc | 24 ++--- src/core/matrixFreePDE.cc | 2 + src/core/outputResults.cc | 4 +- src/core/postprocessing/postprocessor.cc | 3 +- src/core/reinit.cc | 2 +- .../solvers/setNonlinearEqInitialGuess.cc | 2 +- src/core/solvers/solveIncrement.cc | 4 +- src/core/userInputParameters.cc | 97 +++++++++---------- src/core/variableAttributeLoader.cc | 28 ++++-- src/grains/reassignGrains.cc | 2 +- tests/automatic_tests/main.cc | 15 +-- tests/automatic_tests/test_results.txt | 9 ++ 24 files changed, 174 insertions(+), 150 deletions(-) diff --git a/applications/allenCahn_conserved/customPDE.h b/applications/allenCahn_conserved/customPDE.h index aef59ab4e..4d0a5bae2 100644 --- a/applications/allenCahn_conserved/customPDE.h +++ b/applications/allenCahn_conserved/customPDE.h @@ -202,7 +202,7 @@ customPDE::solveIncrement(bool skip_time_dependent) this->fields[fieldIndex].pdetype == TIME_INDEPENDENT) { if (this->currentIncrement % userInputs.skip_print_steps == 0 && - this->var_attributes.attributes.at(fieldIndex).is_nonlinear) + this->var_attributes.at(fieldIndex).is_nonlinear) { snprintf(buffer, sizeof(buffer), @@ -222,12 +222,12 @@ customPDE::solveIncrement(bool skip_time_dependent) } else if (this->fields[fieldIndex].pdetype == AUXILIARY) { - if (this->var_attributes.attributes.at(fieldIndex).is_nonlinear || + if (this->var_attributes.at(fieldIndex).is_nonlinear || nonlinear_it_index == 0) { // If the equation for this field is nonlinear, save the // old solution - if (this->var_attributes.attributes.at(fieldIndex).is_nonlinear) + if (this->var_attributes.at(fieldIndex).is_nonlinear) { if (this->fields[fieldIndex].type == SCALAR) { @@ -258,7 +258,7 @@ customPDE::solveIncrement(bool skip_time_dependent) } // Check to see if this individual variable has converged - if (this->var_attributes.attributes.at(fieldIndex).is_nonlinear) + if (this->var_attributes.at(fieldIndex).is_nonlinear) { if (MatrixFreePDE::userInputs .nonlinear_solver_parameters.getToleranceType( diff --git a/applications/main.cc b/applications/main.cc index e22680a54..cad7b7006 100644 --- a/applications/main.cc +++ b/applications/main.cc @@ -62,8 +62,12 @@ main(int argc, char **argv) // postprocessing variables there are, how many sets of elastic constants // there are, and how many user-defined constants there are. - variableAttributeLoader variable_attributes; - inputFileReader input_file_reader(parameters_filename, variable_attributes); + const variableAttributeLoader attribute_loader; + const AttributesList var_attributes = attribute_loader.get_var_attributes(); + const AttributesList pp_attributes = attribute_loader.get_pp_attributes(); + inputFileReader input_file_reader(parameters_filename, + var_attributes, + pp_attributes); // Continue based on the number of dimensions and degree of the elements // specified in the input file @@ -72,8 +76,7 @@ main(int argc, char **argv) case 2: { userInputParameters<2> userInputs(input_file_reader, - input_file_reader.parameter_handler, - variable_attributes); + input_file_reader.parameter_handler); switch (userInputs.degree) { case (1): @@ -130,8 +133,7 @@ main(int argc, char **argv) case 3: { userInputParameters<3> userInputs(input_file_reader, - input_file_reader.parameter_handler, - variable_attributes); + input_file_reader.parameter_handler); switch (userInputs.degree) { case (1): diff --git a/include/core/inputFileReader.h b/include/core/inputFileReader.h index 3506b8d7d..ba27f9437 100644 --- a/include/core/inputFileReader.h +++ b/include/core/inputFileReader.h @@ -18,8 +18,9 @@ class inputFileReader /** * \brief Constructor. */ - inputFileReader(const std::string &input_file_name, - variableAttributeLoader &_variable_attributes); + inputFileReader(const std::string &input_file_name, + const AttributesList &_var_attributes, + const AttributesList &_pp_attributes); /** * \brief Method to get a list of entry values from multiple subsections in an input @@ -77,9 +78,9 @@ class inputFileReader static bool check_keyword_match(std::string &line, const std::string &keyword); - variableAttributeLoader &variable_attributes; + const AttributesList &var_attributes; + const AttributesList &pp_attributes; dealii::ParameterHandler parameter_handler; - unsigned int num_pp_vars; unsigned int num_constants; std::vector model_constant_names; unsigned int number_of_dimensions; diff --git a/include/core/matrixFreePDE.h b/include/core/matrixFreePDE.h index ced7900de..77d730720 100644 --- a/include/core/matrixFreePDE.h +++ b/include/core/matrixFreePDE.h @@ -141,10 +141,10 @@ class MatrixFreePDE : public Subscriptor unsigned int totalDOFs; - // Virtual methods to set the attributes of the primary field variables and - // the postprocessing field variables virtual void setVariableAttriubutes() = - // 0; virtual void setPostProcessingVariableAttriubutes(){}; - variableAttributeLoader var_attributes; + // The attributes of the primary field variables and + // the postprocessing field variables + const AttributesList &var_attributes; + const AttributesList &pp_attributes; // Elasticity matrix variables const static unsigned int CIJ_tensor_size = 2 * dim - 1 + dim / 3; diff --git a/include/core/userInputParameters.h b/include/core/userInputParameters.h index c27121cab..87225450f 100644 --- a/include/core/userInputParameters.h +++ b/include/core/userInputParameters.h @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -43,8 +43,7 @@ class userInputParameters * member variables. */ userInputParameters(inputFileReader &input_file_reader, - dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader variable_attributes); + dealii::ParameterHandler ¶meter_handler); /** * \brief Creates a list of BCs to store in BC_list object. @@ -176,7 +175,7 @@ class userInputParameters // Method to load in the variable attributes void - loadVariableAttributes(const variableAttributeLoader &variable_attributes); + loadVariableAttributes(); // Nucleation attribute methods [[nodiscard]] std::vector @@ -258,7 +257,8 @@ class userInputParameters // Variable inputs (I might be able to leave some/all of these in // variable_attributes) - unsigned int number_of_variables; + const AttributesList &var_attributes; + const AttributesList &pp_attributes; // Variables needed to calculate the RHS unsigned int num_var_explicit_RHS, num_var_nonexplicit_RHS; @@ -280,7 +280,6 @@ class userInputParameters std::vector checkpointTimeStepList; // Postprocessing parameters - unsigned int pp_number_of_variables; unsigned int num_integrated_fields; bool postProcessingRequired; std::vector integrated_field_indices; @@ -337,31 +336,27 @@ class userInputParameters * spatial discretiziation. */ void - assign_spatial_discretization_parameters(dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes); + assign_spatial_discretization_parameters(dealii::ParameterHandler ¶meter_handler); /** * \brief Assign the provided user inputs to parameters for anything related to the * temporal discretiziation. */ void - assign_temporal_discretization_parameters(dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes); + assign_temporal_discretization_parameters(dealii::ParameterHandler ¶meter_handler); /** * \brief Assign the provided user inputs to parameters for anything related to linear * solves. */ void - assign_linear_solve_parameters(dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes); + assign_linear_solve_parameters(dealii::ParameterHandler ¶meter_handler); /** * \brief Assign the provided user inputs to parameters for anything related to * nonlinear solves. */ void - assign_nonlinear_solve_parameters(dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes); + assign_nonlinear_solve_parameters(dealii::ParameterHandler ¶meter_handler); /** * \brief Assign the provided user inputs to parameters for anything related to @@ -382,24 +377,21 @@ class userInputParameters * nucleation. */ void - assign_nucleation_parameters(dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes); + assign_nucleation_parameters(dealii::ParameterHandler ¶meter_handler); /** * \brief Assign the provided user inputs to parameters for anything related to * grain remapping and grain vtk load-in. */ void - assign_grain_parameters(dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes); + assign_grain_parameters(dealii::ParameterHandler ¶meter_handler); /** * \brief Assign the provided user inputs to parameters for anything related to * boundary conditions. */ void - assign_boundary_condition_parameters(dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes); + assign_boundary_condition_parameters(dealii::ParameterHandler ¶meter_handler); // Method to create the list of time steps where the results should be output // (called from loadInputParameters) diff --git a/include/core/variableAttributeLoader.h b/include/core/variableAttributeLoader.h index 17ecc8e7a..4f05e627d 100644 --- a/include/core/variableAttributeLoader.h +++ b/include/core/variableAttributeLoader.h @@ -140,21 +140,33 @@ class variableAttributeLoader void set_output_integral(const unsigned int &index, const bool &flag) const; + /** + * \brief getter function for variable attributes list (copy). + */ + AttributesList + get_var_attributes() const; + + /** + * \brief getter function for postprocessing attributes list (copy). + */ + AttributesList + get_pp_attributes() const; + /** * \brief The solutions variable attributes */ - std::map attributes; + AttributesList var_attributes; /** * \brief The postprocessing variable attributes */ - std::map pp_attributes; + AttributesList pp_attributes; /** * \brief Useful pointer for setting whether solution or postprocessiong variables are * being loaded */ - std::map *relevant_attributes = nullptr; + AttributesList *relevant_attributes = nullptr; private: /** diff --git a/include/core/variableAttributes.h b/include/core/variableAttributes.h index 05ad6a81f..ddace6ee5 100644 --- a/include/core/variableAttributes.h +++ b/include/core/variableAttributes.h @@ -86,4 +86,6 @@ struct variableAttributes eval_flags_for_eq_type(const variableAttributes &other_variable); }; +using AttributesList = std::map; + #endif diff --git a/src/core/boundary_conditions/boundaryConditions.cc b/src/core/boundary_conditions/boundaryConditions.cc index eca5508ca..c34acdd1f 100644 --- a/src/core/boundary_conditions/boundaryConditions.cc +++ b/src/core/boundary_conditions/boundaryConditions.cc @@ -22,7 +22,7 @@ MatrixFreePDE::applyNeumannBCs() unsigned int starting_BC_list_index = 0; for (unsigned int i = 0; i < currentFieldIndex; i++) { - if (var_attributes.attributes.at(i).var_type == SCALAR) + if (var_attributes.at(i).var_type == SCALAR) { starting_BC_list_index++; } @@ -32,7 +32,7 @@ MatrixFreePDE::applyNeumannBCs() } } - if (var_attributes.attributes.at(currentFieldIndex).var_type == SCALAR) + if (var_attributes.at(currentFieldIndex).var_type == SCALAR) { for (unsigned int direction = 0; direction < 2 * dim; direction++) { @@ -102,7 +102,7 @@ MatrixFreePDE::applyDirichletBCs() for (unsigned int i = 0; i < currentFieldIndex; i++) { - if (var_attributes.attributes.at(i).var_type == SCALAR) + if (var_attributes.at(i).var_type == SCALAR) { starting_BC_list_index++; } @@ -112,7 +112,7 @@ MatrixFreePDE::applyDirichletBCs() } } - if (var_attributes.attributes.at(currentFieldIndex).var_type == SCALAR) + if (var_attributes.at(currentFieldIndex).var_type == SCALAR) { for (unsigned int direction = 0; direction < 2 * dim; direction++) { @@ -250,7 +250,7 @@ MatrixFreePDE::setPeriodicityConstraints( unsigned int starting_BC_list_index = 0; for (unsigned int i = 0; i < currentFieldIndex; i++) { - if (var_attributes.attributes.at(i).var_type == SCALAR) + if (var_attributes.at(i).var_type == SCALAR) { starting_BC_list_index++; } @@ -291,8 +291,8 @@ MatrixFreePDE::set_rigid_body_mode_constraints( // Determine the number of components in the field. For a scalar field this is 1, for a // vector dim, etc. unsigned int n_components = 0; - var_attributes.attributes.at(currentFieldIndex).var_type == VECTOR ? n_components = dim - : n_components = 1; + var_attributes.at(currentFieldIndex).var_type == VECTOR ? n_components = dim + : n_components = 1; // Loop over each locally owned cell for (const auto &cell : dof_handler->active_cell_iterators()) diff --git a/src/core/buildFields.cc b/src/core/buildFields.cc index 1509ce9c9..48ab71d5c 100644 --- a/src/core/buildFields.cc +++ b/src/core/buildFields.cc @@ -16,10 +16,8 @@ void MatrixFreePDE::buildFields() { // Build each of the fields in the system - for (unsigned int i = 0; i < userInputs.number_of_variables; i++) + for (const auto &[index, variable] : var_attributes) { - fields.push_back(Field(var_attributes.attributes.at(i).var_type, - var_attributes.attributes.at(i).eq_type, - var_attributes.attributes.at(i).name)); + fields.push_back(Field(variable.var_type, variable.eq_type, variable.name)); } } diff --git a/src/core/checkpoint.cc b/src/core/checkpoint.cc index 92c481932..14f5ef035 100644 --- a/src/core/checkpoint.cc +++ b/src/core/checkpoint.cc @@ -45,7 +45,7 @@ MatrixFreePDE::save_checkpoint() // First, get lists of scalar and vector fields std::vector scalar_var_indices; std::vector vector_var_indices; - for (const auto &[index, variable] : var_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.var_type == SCALAR) { @@ -60,7 +60,7 @@ MatrixFreePDE::save_checkpoint() // Second, build one solution set list for scalars and one for vectors std::vector solSet_transfer_scalars; std::vector solSet_transfer_vectors; - for (const auto &[index, variable] : var_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.var_type == SCALAR) { @@ -151,7 +151,7 @@ MatrixFreePDE::load_checkpoint_fields() // First, get lists of scalar and vector fields std::vector scalar_var_indices; std::vector vector_var_indices; - for (const auto &[index, variable] : var_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.var_type == SCALAR) { @@ -166,7 +166,7 @@ MatrixFreePDE::load_checkpoint_fields() // Second, build one solution set list for scalars and one for vectors std::vector solSet_transfer_scalars; std::vector solSet_transfer_vectors; - for (const auto &[index, variable] : var_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.var_type == SCALAR) { diff --git a/src/core/init.cc b/src/core/init.cc index 46fbd9a8f..a4fb0a29b 100644 --- a/src/core/init.cc +++ b/src/core/init.cc @@ -281,7 +281,7 @@ MatrixFreePDE::init() if (fields[fieldIndex].pdetype == TIME_INDEPENDENT || fields[fieldIndex].pdetype == IMPLICIT_TIME_DEPENDENT || (fields[fieldIndex].pdetype == AUXILIARY && - var_attributes.attributes.at(fieldIndex).is_nonlinear)) + var_attributes.at(fieldIndex).is_nonlinear)) { if (fields[fieldIndex].type == SCALAR) { diff --git a/src/core/initial_conditions/initialConditions.cc b/src/core/initial_conditions/initialConditions.cc index 038faa911..335494732 100644 --- a/src/core/initial_conditions/initialConditions.cc +++ b/src/core/initial_conditions/initialConditions.cc @@ -52,8 +52,7 @@ MatrixFreePDE::applyInitialConditions() // Clear the order parameter fields unsigned int op_list_index = 0; - for (unsigned int var_index = 0; var_index < userInputs.number_of_variables; - var_index++) + for (unsigned int var_index = 0; var_index < var_attributes.size(); var_index++) { if (op_list_index < userInputs.variables_for_remapping.size()) { @@ -69,7 +68,7 @@ MatrixFreePDE::applyInitialConditions() // Get the index of one of the scalar fields unsigned int scalar_field_index = 0; - for (const auto &[index, variable] : var_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.var_type == SCALAR) { @@ -315,7 +314,7 @@ MatrixFreePDE::applyInitialConditions() // Create map of vtk files that are read in std::unordered_map> file_field_map; - for (size_t i = 0; i < userInputs.number_of_variables; ++i) + for (size_t i = 0; i < var_attributes.size(); ++i) { if (userInputs.load_ICs[i]) { @@ -382,7 +381,7 @@ MatrixFreePDE::applyInitialConditions() // Find the scalar field in the file ScalarField &field = body.find_scalar_field(var_name); - if (var_attributes.attributes.at(index).var_type == SCALAR) + if (var_attributes.at(index).var_type == SCALAR) { pcout << "Applying PField initial condition for " << userInputs.load_field_name[index] << "...\n"; @@ -400,7 +399,7 @@ MatrixFreePDE::applyInitialConditions() } unsigned int op_list_index = 0; - for (const auto &[var_index, variable] : var_attributes.attributes) + for (const auto &[var_index, variable] : var_attributes) { bool is_remapped_op = false; if (op_list_index < userInputs.variables_for_remapping.size()) diff --git a/src/core/inputFileReader.cc b/src/core/inputFileReader.cc index e790db42e..7b62d6cd7 100644 --- a/src/core/inputFileReader.cc +++ b/src/core/inputFileReader.cc @@ -5,10 +5,11 @@ #include #include -inputFileReader::inputFileReader(const std::string &input_file_name, - variableAttributeLoader &_variable_attributes) - : variable_attributes(_variable_attributes) - , num_pp_vars(_variable_attributes.pp_attributes.size()) +inputFileReader::inputFileReader(const std::string &input_file_name, + const AttributesList &_var_attributes, + const AttributesList &_pp_attributes) + : var_attributes(_var_attributes) + , pp_attributes(_pp_attributes) { num_constants = get_number_of_entries(input_file_name, "set", "Model constant"); @@ -18,7 +19,8 @@ inputFileReader::inputFileReader(const std::string &input_file_name, if (dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0) { std::cout << "Number of constants: " << num_constants << "\n"; - std::cout << "Number of post-processing variables: " << num_pp_vars << "\n"; + std::cout << "Number of post-processing variables: " << pp_attributes.size() + << "\n"; } // Read in all of the parameters now @@ -352,7 +354,7 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_handler, dealii::Patterns::Integer(), "The number of time steps between mesh refinement operations."); - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { std::string subsection_text = "Refinement criterion: "; subsection_text.append(variable.name); @@ -402,7 +404,7 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_handler, dealii::Patterns::Double(), "The value of simulated time where the simulation ends."); - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.eq_type == TIME_INDEPENDENT || variable.eq_type == IMPLICIT_TIME_DEPENDENT) @@ -437,7 +439,7 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_handler, "The maximum number of nonlinear solver " "iterations before the loop is stopped."); - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.is_nonlinear) { @@ -580,7 +582,7 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_handler, /*---------------------- | Boundary conditions -----------------------*/ - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.var_type == SCALAR) { @@ -626,7 +628,7 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_handler, /*---------------------- | Pinning point -----------------------*/ - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { std::string pinning_text = "Pinning point: "; pinning_text.append(variable.name); @@ -683,7 +685,7 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_handler, dealii::Patterns::Double(), "The time after which no nucleation occurs."); - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.nucleating_variable) { diff --git a/src/core/matrixFreePDE.cc b/src/core/matrixFreePDE.cc index d503f9ab8..40a407862 100644 --- a/src/core/matrixFreePDE.cc +++ b/src/core/matrixFreePDE.cc @@ -8,6 +8,8 @@ MatrixFreePDE::MatrixFreePDE(userInputParameters _userInputs) : Subscriptor() , pcout(std::cout, Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0) , userInputs(_userInputs) + , var_attributes(_userInputs.var_attributes) + , pp_attributes(_userInputs.var_attributes) , triangulation(MPI_COMM_WORLD) , currentFieldIndex(0) , isTimeDependentBVP(false) diff --git a/src/core/outputResults.cc b/src/core/outputResults.cc index e1d1fcd7c..42f8186fd 100644 --- a/src/core/outputResults.cc +++ b/src/core/outputResults.cc @@ -86,7 +86,7 @@ MatrixFreePDE::outputResults() output_file << currentTime; } - for (const auto &[pp_index, pp_variable] : var_attributes.pp_attributes) + for (const auto &[pp_index, pp_variable] : pp_attributes) { if (pp_variable.calc_integral) { @@ -111,7 +111,7 @@ MatrixFreePDE::outputResults() } // Add the postprocessed fields to data_out - for (const auto &[fieldIndex, pp_variable] : var_attributes.pp_attributes) + for (const auto &[fieldIndex, pp_variable] : pp_attributes) { // mark field as scalar/vector unsigned int components = 0; diff --git a/src/core/postprocessing/postprocessor.cc b/src/core/postprocessing/postprocessor.cc index 972d9fac8..aa11ccf79 100644 --- a/src/core/postprocessing/postprocessor.cc +++ b/src/core/postprocessing/postprocessor.cc @@ -6,8 +6,7 @@ MatrixFreePDE::computePostProcessedFields( std::vector &postProcessedSet) { // Initialize the postProcessedSet - for (unsigned int fieldIndex = 0; fieldIndex < userInputs.pp_number_of_variables; - fieldIndex++) + for (unsigned int fieldIndex = 0; fieldIndex < pp_attributes.size(); fieldIndex++) { vectorType *U = nullptr; U = new vectorType; diff --git a/src/core/reinit.cc b/src/core/reinit.cc index 22b868788..71171dc60 100644 --- a/src/core/reinit.cc +++ b/src/core/reinit.cc @@ -138,7 +138,7 @@ MatrixFreePDE::reinit() if (fields[fieldIndex].pdetype == TIME_INDEPENDENT || fields[fieldIndex].pdetype == IMPLICIT_TIME_DEPENDENT || (fields[fieldIndex].pdetype == AUXILIARY && - var_attributes.attributes.at(fieldIndex).is_nonlinear)) + var_attributes.at(fieldIndex).is_nonlinear)) { if (fields[fieldIndex].type == SCALAR) { diff --git a/src/core/solvers/setNonlinearEqInitialGuess.cc b/src/core/solvers/setNonlinearEqInitialGuess.cc index 6d8d482eb..65308acc9 100644 --- a/src/core/solvers/setNonlinearEqInitialGuess.cc +++ b/src/core/solvers/setNonlinearEqInitialGuess.cc @@ -16,7 +16,7 @@ MatrixFreePDE::setNonlinearEqInitialGuess() time.start(); char buffer[200]; - for (const auto &[fieldIndex, variable] : var_attributes.attributes) + for (const auto &[fieldIndex, variable] : var_attributes) { if ((variable.eq_type == TIME_INDEPENDENT) && variable.is_nonlinear && userInputs.nonlinear_solver_parameters.getLaplaceInitializationFlag(fieldIndex)) diff --git a/src/core/solvers/solveIncrement.cc b/src/core/solvers/solveIncrement.cc index f1a5cc455..b7334f1ef 100644 --- a/src/core/solvers/solveIncrement.cc +++ b/src/core/solvers/solveIncrement.cc @@ -81,7 +81,7 @@ MatrixFreePDE::solveIncrement(bool skip_time_dependent) // not too terrible computeNonexplicitRHS(); - for (const auto &[fieldIndex, variable] : var_attributes.attributes) + for (const auto &[fieldIndex, variable] : var_attributes) { currentFieldIndex = fieldIndex; // Used in computeLHS() @@ -358,7 +358,7 @@ MatrixFreePDE::updateImplicitSolution(unsigned int fieldIndex, "solver tolerance.\n"; } - if (var_attributes.attributes.at(fieldIndex).is_nonlinear) + if (var_attributes.at(fieldIndex).is_nonlinear) { // Now that we have the calculated change in the solution, // we need to select a damping coefficient diff --git a/src/core/userInputParameters.cc b/src/core/userInputParameters.cc index 15e7c24d3..48e7abf1f 100644 --- a/src/core/userInputParameters.cc +++ b/src/core/userInputParameters.cc @@ -8,8 +8,7 @@ template void userInputParameters::assign_spatial_discretization_parameters( - dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes) + dealii::ParameterHandler ¶meter_handler) { // Domain size & subdivisions domain_size.push_back(parameter_handler.get_double("Domain size X")); @@ -54,7 +53,7 @@ userInputParameters::assign_spatial_discretization_parameters( } // The adaptivity criterion for each variable has its own subsection - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { std::string subsection_text = "Refinement criterion: "; subsection_text.append(variable.name); @@ -132,8 +131,7 @@ userInputParameters::assign_spatial_discretization_parameters( template void userInputParameters::assign_temporal_discretization_parameters( - dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes) + dealii::ParameterHandler ¶meter_handler) { dtValue = parameter_handler.get_double("Time step"); const int totalIncrements_temp = @@ -143,7 +141,7 @@ userInputParameters::assign_temporal_discretization_parameters( // If all of the variables are ELLIPTIC, then totalIncrements should be 1 and // finalTime should be 0 bool only_time_independent_pdes = true; - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.eq_type == EXPLICIT_TIME_DEPENDENT || variable.eq_type == IMPLICIT_TIME_DEPENDENT) @@ -197,10 +195,9 @@ userInputParameters::assign_temporal_discretization_parameters( template void userInputParameters::assign_linear_solve_parameters( - dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes) + dealii::ParameterHandler ¶meter_handler) { - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.eq_type == TIME_INDEPENDENT || variable.eq_type == IMPLICIT_TIME_DEPENDENT) @@ -259,13 +256,12 @@ userInputParameters::assign_linear_solve_parameters( template void userInputParameters::assign_nonlinear_solve_parameters( - dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes) + dealii::ParameterHandler ¶meter_handler) { nonlinear_solver_parameters.setMaxIterations( parameter_handler.get_integer("Maximum nonlinear solver iterations")); - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.is_nonlinear) { @@ -356,7 +352,7 @@ userInputParameters::assign_nonlinear_solve_parameters( // Set the max number of nonlinear iterations bool any_nonlinear = false; - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { any_nonlinear |= variable.is_nonlinear; } @@ -444,7 +440,7 @@ userInputParameters::assign_load_initial_condition_parameters( if (boost::iequals(load_ICs_temp.at(0), "void")) { - for (unsigned int var = 0; var < number_of_variables; var++) + for (unsigned int var = 0; var < var_attributes.size(); var++) { load_ICs.push_back(false); load_parallel_file.push_back(false); @@ -452,7 +448,7 @@ userInputParameters::assign_load_initial_condition_parameters( } else { - for (unsigned int var = 0; var < number_of_variables; var++) + for (unsigned int var = 0; var < var_attributes.size(); var++) { if (boost::iequals(load_ICs_temp.at(var), "true")) { @@ -482,10 +478,9 @@ userInputParameters::assign_load_initial_condition_parameters( template void userInputParameters::assign_nucleation_parameters( - dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes) + dealii::ParameterHandler ¶meter_handler) { - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.nucleating_variable) { @@ -574,8 +569,7 @@ userInputParameters::assign_nucleation_parameters( template void userInputParameters::assign_grain_parameters( - dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes) + dealii::ParameterHandler ¶meter_handler) { // Load the grain remapping parameters grain_remapping_activated = parameter_handler.get_bool("Activate grain reassignment"); @@ -601,7 +595,7 @@ userInputParameters::assign_grain_parameters( for (const auto &field : variables_for_remapping_str) { bool field_found = false; - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (boost::iequals(field, variable.name)) { @@ -635,13 +629,12 @@ userInputParameters::assign_grain_parameters( template void userInputParameters::assign_boundary_condition_parameters( - dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader &variable_attributes) + dealii::ParameterHandler ¶meter_handler) { // Load the boundary condition variables into list of BCs (where each element // of the vector is one component of one variable) std::vector list_of_BCs; - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.var_type == SCALAR) { @@ -674,7 +667,7 @@ userInputParameters::assign_boundary_condition_parameters( /*---------------------- | Pinning point -----------------------*/ - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { std::string pinning_text = "Pinning point: "; pinning_text.append(variable.name); @@ -709,22 +702,23 @@ userInputParameters::assign_boundary_condition_parameters( // NOLINTBEGIN(cppcoreguidelines-pro-type-member-init, hicpp-member-init) template userInputParameters::userInputParameters(inputFileReader &input_file_reader, - dealii::ParameterHandler ¶meter_handler, - variableAttributeLoader variable_attributes) + dealii::ParameterHandler ¶meter_handler) + : var_attributes(input_file_reader.var_attributes) + , pp_attributes(input_file_reader.pp_attributes) { - loadVariableAttributes(variable_attributes); + loadVariableAttributes(); // Spatial discretization - assign_spatial_discretization_parameters(parameter_handler, variable_attributes); + assign_spatial_discretization_parameters(parameter_handler); // Time stepping parameters - assign_temporal_discretization_parameters(parameter_handler, variable_attributes); + assign_temporal_discretization_parameters(parameter_handler); // Linear solver parameters - assign_linear_solve_parameters(parameter_handler, variable_attributes); + assign_linear_solve_parameters(parameter_handler); // Non-linear solver parameters - assign_nonlinear_solve_parameters(parameter_handler, variable_attributes); + assign_nonlinear_solve_parameters(parameter_handler); // Output parameters assign_output_parameters(parameter_handler); @@ -733,13 +727,13 @@ userInputParameters::userInputParameters(inputFileReader &input_fi assign_load_initial_condition_parameters(parameter_handler); // Nucleation parameters - assign_nucleation_parameters(parameter_handler, variable_attributes); + assign_nucleation_parameters(parameter_handler); // Grain remapping & vtk load-in parameters - assign_grain_parameters(parameter_handler, variable_attributes); + assign_grain_parameters(parameter_handler); // Boundary conditions - assign_boundary_condition_parameters(parameter_handler, variable_attributes); + assign_boundary_condition_parameters(parameter_handler); // Load the user-defined constants load_user_constants(input_file_reader, parameter_handler); @@ -924,13 +918,10 @@ userInputParameters::setTimeStepList( template void -userInputParameters::loadVariableAttributes( - const variableAttributeLoader &variable_attributes) +userInputParameters::loadVariableAttributes() { - number_of_variables = variable_attributes.attributes.size(); - pp_number_of_variables = variable_attributes.pp_attributes.size(); // Load some nucleation parameters - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.nucleating_variable) { @@ -946,7 +937,7 @@ userInputParameters::loadVariableAttributes( // Load variable information for calculating the RHS for explicit equations num_var_explicit_RHS = 0; - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (!static_cast(variable.eval_flags_explicit_RHS & dealii::EvaluationFlags::nothing)) @@ -955,7 +946,7 @@ userInputParameters::loadVariableAttributes( } } varInfoListExplicitRHS.reserve(num_var_explicit_RHS); - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { variable_info varInfo {}; @@ -975,7 +966,7 @@ userInputParameters::loadVariableAttributes( // Load variable information for calculating the RHS for nonexplicit equations num_var_nonexplicit_RHS = 0; - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (!static_cast(variable.eval_flags_nonexplicit_RHS & dealii::EvaluationFlags::nothing)) @@ -984,7 +975,7 @@ userInputParameters::loadVariableAttributes( } } varInfoListNonexplicitRHS.reserve(num_var_nonexplicit_RHS); - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { variable_info varInfo {}; @@ -1004,7 +995,7 @@ userInputParameters::loadVariableAttributes( // Load variable information for calculating the LHS num_var_LHS = 0; - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (!static_cast(variable.eval_flags_nonexplicit_LHS & dealii::EvaluationFlags::nothing)) @@ -1014,7 +1005,7 @@ userInputParameters::loadVariableAttributes( } varInfoListLHS.reserve(num_var_LHS); - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { variable_info varInfo {}; @@ -1033,7 +1024,7 @@ userInputParameters::loadVariableAttributes( } varChangeInfoListLHS.reserve(num_var_LHS); - for (const auto &[index, variable] : variable_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { variable_info varInfo {}; @@ -1054,8 +1045,8 @@ userInputParameters::loadVariableAttributes( // Load variable information for postprocessing // First, the info list for the base field variables - pp_baseVarInfoList.reserve(number_of_variables); - for (const auto &[index, variable] : variable_attributes.attributes) + pp_baseVarInfoList.reserve(var_attributes.size()); + for (const auto &[index, variable] : var_attributes) { variable_info varInfo {}; @@ -1074,10 +1065,10 @@ userInputParameters::loadVariableAttributes( // Now load the information for the post-processing variables // Parameters for postprocessing - postProcessingRequired = pp_number_of_variables > 0; + postProcessingRequired = !pp_attributes.empty(); num_integrated_fields = 0; - for (const auto &[pp_index, pp_variable] : variable_attributes.pp_attributes) + for (const auto &[pp_index, pp_variable] : pp_attributes) { if (pp_variable.calc_integral) { @@ -1087,8 +1078,8 @@ userInputParameters::loadVariableAttributes( } // The info list for the postprocessing field variables - pp_varInfoList.reserve(pp_number_of_variables); - for (const auto &[pp_index, pp_variable] : variable_attributes.pp_attributes) + pp_varInfoList.reserve(pp_attributes.size()); + for (const auto &[pp_index, pp_variable] : pp_attributes) { variable_info varInfo {}; diff --git a/src/core/variableAttributeLoader.cc b/src/core/variableAttributeLoader.cc index db6cfe347..152cc4303 100644 --- a/src/core/variableAttributeLoader.cc +++ b/src/core/variableAttributeLoader.cc @@ -6,7 +6,7 @@ // NOLINTBEGIN(cppcoreguidelines-prefer-member-initializer) variableAttributeLoader::variableAttributeLoader() { - relevant_attributes = &attributes; + relevant_attributes = &var_attributes; loadVariableAttributes(); relevant_attributes = &pp_attributes; loadPostProcessorVariableAttributes(); @@ -24,7 +24,7 @@ variableAttributeLoader::variableAttributeLoader() pp_variable.eq_type = EXPLICIT_TIME_DEPENDENT; } - for (auto &[index, variable] : attributes) + for (auto &[index, variable] : var_attributes) { variable.format_dependencies(); } @@ -33,10 +33,10 @@ variableAttributeLoader::variableAttributeLoader() pp_variable.format_dependencies(); } validate_attributes(); - for (auto &[index, variable] : attributes) + for (auto &[index, variable] : var_attributes) { variable.parse_residual_dependencies(); - variable.parse_dependencies(attributes); + variable.parse_dependencies(var_attributes); variable.parse_dependencies(pp_attributes); } for (auto &[index, pp_variable] : pp_attributes) @@ -47,6 +47,18 @@ variableAttributeLoader::variableAttributeLoader() // NOLINTEND(cppcoreguidelines-prefer-member-initializer) +AttributesList +variableAttributeLoader::get_var_attributes() const +{ + return var_attributes; +} + +AttributesList +variableAttributeLoader::get_pp_attributes() const +{ + return pp_attributes; +} + // Methods to set the various variable attributes void variableAttributeLoader::set_variable_name(const unsigned int &index, @@ -101,7 +113,7 @@ variableAttributeLoader::set_dependencies_value_term_RHS(const unsigned int &ind std::set(dependencies_set.begin(), dependencies_set.end()); */ if (relevant_attributes != &pp_attributes) { - attributes[index].dependencies_value_RHS = + var_attributes[index].dependencies_value_RHS = std::set(dependencies_set.begin(), dependencies_set.end()); } else @@ -122,7 +134,7 @@ variableAttributeLoader::set_dependencies_gradient_term_RHS( std::set(dependencies_set.begin(), dependencies_set.end()); */ if (relevant_attributes != &pp_attributes) { - attributes[index].dependencies_gradient_RHS = + var_attributes[index].dependencies_gradient_RHS = std::set(dependencies_set.begin(), dependencies_set.end()); } else @@ -272,7 +284,7 @@ variableAttributeLoader::validate_attributes() // Populate the expected variable dependencies and check that variable names are mostly // well-formed. - for (const auto &[index, variable] : attributes) + for (const auto &[index, variable] : var_attributes) { name_list.insert(variable.name); @@ -302,7 +314,7 @@ variableAttributeLoader::validate_attributes() pp_index); } // Check dependencies - for (const auto &[index, variable] : attributes) + for (const auto &[index, variable] : var_attributes) { validate_dependencies(variable.dependencies_RHS, "RHS", diff --git a/src/grains/reassignGrains.cc b/src/grains/reassignGrains.cc index 4d2fa4100..ec28ec3e6 100644 --- a/src/grains/reassignGrains.cc +++ b/src/grains/reassignGrains.cc @@ -16,7 +16,7 @@ MatrixFreePDE::reassignGrains() // Get the index of the first scalar field (used to get the FE object and // DOFHandler) unsigned int scalar_field_index = 0; - for (const auto &[index, variable] : var_attributes.attributes) + for (const auto &[index, variable] : var_attributes) { if (variable.var_type == SCALAR) { diff --git a/tests/automatic_tests/main.cc b/tests/automatic_tests/main.cc index e22680a54..1bc0af127 100644 --- a/tests/automatic_tests/main.cc +++ b/tests/automatic_tests/main.cc @@ -7,6 +7,7 @@ #include #include #include +#include // Header file for postprocessing that may or may not exist #ifdef POSTPROCESS_FILE_EXISTS @@ -62,8 +63,12 @@ main(int argc, char **argv) // postprocessing variables there are, how many sets of elastic constants // there are, and how many user-defined constants there are. - variableAttributeLoader variable_attributes; - inputFileReader input_file_reader(parameters_filename, variable_attributes); + const variableAttributeLoader attribute_loader; + const AttributesList var_attributes = attribute_loader.get_var_attributes(); + const AttributesList pp_attributes = attribute_loader.get_pp_attributes(); + inputFileReader input_file_reader(parameters_filename, + var_attributes, + pp_attributes); // Continue based on the number of dimensions and degree of the elements // specified in the input file @@ -72,8 +77,7 @@ main(int argc, char **argv) case 2: { userInputParameters<2> userInputs(input_file_reader, - input_file_reader.parameter_handler, - variable_attributes); + input_file_reader.parameter_handler); switch (userInputs.degree) { case (1): @@ -130,8 +134,7 @@ main(int argc, char **argv) case 3: { userInputParameters<3> userInputs(input_file_reader, - input_file_reader.parameter_handler, - variable_attributes); + input_file_reader.parameter_handler); switch (userInputs.degree) { case (1): diff --git a/tests/automatic_tests/test_results.txt b/tests/automatic_tests/test_results.txt index 31a30082b..55c479b4e 100644 --- a/tests/automatic_tests/test_results.txt +++ b/tests/automatic_tests/test_results.txt @@ -1792,3 +1792,12 @@ Time: 66.96555471420288 Tests Passed: 5/5 --------------------------------------------------------- +--------------------------------------------------------- +Regression test on 2024-12-11 12:51 +Architecture: x86_64 +Model name: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz +CPU(s): 8 +CPU max/min MHz: None, None +Hypervisor vendor: Microsoft +Number of processes: 1 +---------------------------------------------------------