diff --git a/applications/allenCahn_conserved/customPDE.h b/applications/allenCahn_conserved/customPDE.h index 711ffcc74..5812e5bc7 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 && - userInputs.var_nonlinear[fieldIndex]) + this->var_attributes.attributes.at(fieldIndex).is_nonlinear) { snprintf(buffer, sizeof(buffer), @@ -222,11 +222,12 @@ customPDE::solveIncrement(bool skip_time_dependent) } else if (this->fields[fieldIndex].pdetype == AUXILIARY) { - if (userInputs.var_nonlinear[fieldIndex] || nonlinear_it_index == 0) + if (this->var_attributes.attributes.at(fieldIndex).is_nonlinear || + nonlinear_it_index == 0) { // If the equation for this field is nonlinear, save the // old solution - if (userInputs.var_nonlinear[fieldIndex]) + if (this->var_attributes.attributes.at(fieldIndex).is_nonlinear) { if (this->fields[fieldIndex].type == SCALAR) { @@ -257,7 +258,7 @@ customPDE::solveIncrement(bool skip_time_dependent) } // Check to see if this individual variable has converged - if (userInputs.var_nonlinear[fieldIndex]) + if (this->var_attributes.attributes.at(fieldIndex).is_nonlinear) { if (MatrixFreePDE::userInputs .nonlinear_solver_parameters.getToleranceType( diff --git a/include/EquationDependencyParser.h b/include/EquationDependencyParser.h deleted file mode 100644 index 4a8dd1b03..000000000 --- a/include/EquationDependencyParser.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef INCLUDE_EQUATIONDEPENDECYPARSER_H_ -#define INCLUDE_EQUATIONDEPENDECYPARSER_H_ - -#include - -#include "varTypeEnums.h" - -#include -#include -#include - -/** - * This is a class to parse the strings the user puts into the - * variableAttributeLoader to specify which variable values, gradients, - * hessians, etc are needed for each governing equation. - */ -class EquationDependencyParser -{ -public: - void - parse(std::vector &var_name, - std::vector var_eq_type, - std::vector sorted_dependencies_value_RHS, - std::vector sorted_dependencies_gradient_RHS, - std::vector sorted_dependencies_value_LHS, - std::vector sorted_dependencies_gradient_LHS, - std::vector &var_nonlinear); - - void - pp_parse(std::vector &var_name, - std::vector &pp_var_name, - std::vector sorted_dependencies_value, - std::vector sorted_dependencies_gradient); - - // Evaluation flags for each type of solution variable (e.g., explicit, nonexplicit, - // nonexplicit_change, etc.) - std::vector eval_flags_explicit_RHS; - std::vector eval_flags_nonexplicit_RHS; - std::vector eval_flags_nonexplicit_LHS; - std::vector eval_flags_change_nonexplicit_LHS; - - std::vector eval_flags_residual_explicit_RHS; - std::vector - eval_flags_residual_nonexplicit_RHS; - std::vector - eval_flags_residual_nonexplicit_LHS; - - // All of the vectors of flags for what is needed for the postprocessing - // variables - std::vector eval_flags_postprocess; - std::vector eval_flags_residual_postprocess; - -protected: - /* - * Method to strip excess whitespace for the dependency lists - */ - void - strip_dependency_whitespace(std::string &dependency_list); - - /** - * Method to parse the RHS dependency strings and populate the vectors for - * whether values, gradients, or hessians are needed. - */ - void - parseDependencyListRHS( - std::vector &variable_name_list, - std::vector variable_eq_type, - unsigned int variable_index, - std::string &value_dependencies, - std::string &gradient_dependencies, - std::vector &evaluation_flags, - std::vector &residual_flags, - bool &is_nonlinear); - - /** - * Method to parse the LHS dependency strings and populate the vectors for - * whether values, gradients, or hessians are needed. - */ - void - parseDependencyListLHS( - std::vector &variable_name_list, - std::vector variable_eq_type, - unsigned int variable_index, - std::string &value_dependencies, - std::string &gradient_dependencies, - std::vector &evaluation_flags, - std::vector &change_flags, - std::vector &residual_flags, - bool &is_nonlinear); - - /** - * Method to parse the postprocessing dependency strings and populate the - * vectors for whether values, gradients, or hessians are needed. - */ - void - parseDependencyListPP( - std::vector &variable_name_list, - unsigned int variable_index, - std::string &value_dependencies, - std::string &gradient_dependencies, - std::vector &evaluation_flags, - std::vector &residual_flags); -}; - -#endif diff --git a/include/inputFileReader.h b/include/inputFileReader.h index 9364c5394..a847e45b8 100644 --- a/include/inputFileReader.h +++ b/include/inputFileReader.h @@ -16,7 +16,7 @@ class inputFileReader public: // Constructor inputFileReader(const std::string &input_file_name, - variableAttributeLoader &variable_attributes); + variableAttributeLoader &_variable_attributes); // Method to get a list of entry values from multiple subsections in an input // file @@ -41,11 +41,8 @@ class inputFileReader // Method to declare the parameters to be read from an input file void - declare_parameters(dealii::ParameterHandler ¶meter_handler, - const std::vector &var_types, - const std::vector &var_eq_types, - const unsigned int num_of_constants, - const std::vector &var_nucleates) const; + declare_parameters(dealii::ParameterHandler ¶meter_handler, + const unsigned int num_of_constants) const; // Method to check if a line has the desired contents and if so, extract it bool @@ -56,16 +53,12 @@ class inputFileReader bool expect_equals_sign) const; // Variables + variableAttributeLoader &variable_attributes; dealii::ParameterHandler parameter_handler; - std::vector var_types; - std::vector var_eq_types; unsigned int num_pp_vars; unsigned int num_constants; std::vector model_constant_names; - std::vector var_names; unsigned int number_of_dimensions; - std::vector var_nucleates; - std::vector var_nonlinear; }; #endif /* INCLUDE_INPUTFILEREADER_H_ */ diff --git a/include/sortIndexEntryPairList.h b/include/sortIndexEntryPairList.h deleted file mode 100644 index 71673f26e..000000000 --- a/include/sortIndexEntryPairList.h +++ /dev/null @@ -1,32 +0,0 @@ -// At some point, rewrite the following four methods as a single templated -// method -#ifndef INCLUDE_SORTINDEXENTRYPAIRLIST_H_ -#define INCLUDE_SORTINDEXENTRYPAIRLIST_H_ - -#include "varTypeEnums.h" - -#include -#include - -std::vector -sortIndexEntryPairList( - const std::vector> &unsorted_pair_list, - unsigned int number_of_variables, - bool default_value); -std::vector -sortIndexEntryPairList( - const std::vector> &unsorted_pair_list, - unsigned int number_of_variables, - const std::string &default_value); -std::vector -sortIndexEntryPairList( - const std::vector> &unsorted_pair_list, - unsigned int number_of_variables, - fieldType default_value); -std::vector -sortIndexEntryPairList( - const std::vector> &unsorted_pair_list, - unsigned int number_of_variables, - PDEType default_value); - -#endif diff --git a/include/userInputParameters.h b/include/userInputParameters.h index 542919ad8..db16191af 100644 --- a/include/userInputParameters.h +++ b/include/userInputParameters.h @@ -168,7 +168,7 @@ class userInputParameters // Method to load in the variable attributes void - loadVariableAttributes(variableAttributeLoader variable_attributes); + loadVariableAttributes(const variableAttributeLoader &variable_attributes); // Nucleation attribute methods std::vector @@ -252,12 +252,6 @@ class userInputParameters // variable_attributes) unsigned int number_of_variables; - std::vector var_name; - std::vector var_type; - std::vector var_eq_type; - - std::vector var_nonlinear; - // Variables needed to calculate the RHS unsigned int num_var_explicit_RHS, num_var_nonexplicit_RHS; std::vector varInfoListExplicitRHS, varInfoListNonexplicitRHS; @@ -281,12 +275,8 @@ class userInputParameters unsigned int pp_number_of_variables; unsigned int num_integrated_fields; bool postProcessingRequired; - std::vector pp_calc_integral; std::vector integrated_field_indices; - std::vector pp_var_name; - std::vector pp_var_type; - // Variable and residual info std::vector pp_varInfoList; std::vector pp_baseVarInfoList; diff --git a/include/varTypeEnums.h b/include/varTypeEnums.h index ad42741c2..6bf238cc6 100644 --- a/include/varTypeEnums.h +++ b/include/varTypeEnums.h @@ -3,12 +3,14 @@ enum fieldType { + UNDEFINED_FIELD, SCALAR, VECTOR }; enum PDEType { + UNDEFINED_PDE, EXPLICIT_TIME_DEPENDENT, IMPLICIT_TIME_DEPENDENT, TIME_INDEPENDENT, diff --git a/include/variableAttributeLoader.h b/include/variableAttributeLoader.h index cf45bbd5a..3bd8d2d4c 100644 --- a/include/variableAttributeLoader.h +++ b/include/variableAttributeLoader.h @@ -1,110 +1,176 @@ -// Class to hold the variable attributes that will be passed to a -// userInputParameters object #ifndef VARIABLEATTRIBUTELOADER_H #define VARIABLEATTRIBUTELOADER_H -#include "EquationDependencyParser.h" -#include "model_variables.h" #include "varTypeEnums.h" +#include "variableAttributes.h" +#include #include -#include +using EvalFlags = dealii::EvaluationFlags::EvaluationFlags; + +/** + * \brief Class to manage the variable attributes that the user specifies. + */ class variableAttributeLoader { public: - // Constructor + /** + * \brief Constructor. Executes the user-facing functions and constructs the variable + * attributes. + */ variableAttributeLoader(); - // Methods where the attributes are set + /** + * \brief User-facing method where the variable attributes are set. + */ void loadVariableAttributes(); + + /** + * \brief User-facing method where the postprocessing variable attributes are set. + */ void loadPostProcessorVariableAttributes(); - // Methods to set the parameter_attributes - bool setting_primary_field_attributes; + /** + * \brief Set the name of the variable at `index` to `name`. + * + * \param index Index of variable + * \param name Name of variable at `index` + */ void - set_variable_name(unsigned int index, std::string name); + set_variable_name(const unsigned int &index, const std::string &name); + + /** + * \brief Set the field type of the variable at `index` to `var_type` where `var_type` + * can be `SCALAR` or `VECTOR`. + * + * \param index Index of variable + * \param var_type Field type of variable at `index` (`SCALAR` or `VECTOR`). + */ void - set_variable_type(unsigned int index, fieldType); + set_variable_type(const unsigned int &index, const fieldType &var_type); + + /** + * \brief Set the PDE type of the variable at `index` to `var_eq_type` where + *`var_eq_type`can be `EXPLICIT_TIME_DEPENDENT`, `IMPLICIT_TIME_DEPENDENT`, + *`TIME_INDEPENDENT`, `AUXILIARY`. + * + * \param index Index of variable + * \param var_eq_type PDE type of variable at `index`. + */ void - set_variable_equation_type(unsigned int index, PDEType); - + set_variable_equation_type(const unsigned int &index, const PDEType &var_eq_type); + + /** + * \brief Set the dependencies for the value term of the RHS equation of the variable at + * `index`. + * + * \param index Index of variable + * \param dependencies String containing comma-separated list of dependencies for + * variable at `index` Hint: "variable, grad(variable), hess(variable)" + */ void - set_need_value_nucleation(unsigned int index, bool); + set_dependencies_value_term_RHS(const unsigned int &index, + const std::string &dependencies); + + /** + * \brief Set the dependencies for the gradient term of the RHS equation of the variable + * at `index`. + * + * \param index Index of variable + * \param dependencies String containing comma-separated list of dependencies for + * variable at `index` Hint: "variable, grad(variable), hess(variable)" + */ void - set_allowed_to_nucleate(unsigned int index, bool); - + set_dependencies_gradient_term_RHS(const unsigned int &index, + const std::string &dependencies); + + /** + * \brief Set the dependencies for the value term of the LHS equation of the variable at + * `index`. + * + * \param index Index of variable + * \param dependencies String containing comma-separated list of dependencies for + * variable at `index` Hint: "variable, grad(variable), hess(variable)" + */ void - set_output_integral(unsigned int index, bool); - - // Variable inputs (v2.0) - std::vector> var_name_list; - std::vector> var_type_list; - std::vector> var_eq_type_list; - std::vector> need_value_list; - std::vector> need_gradient_list; - std::vector> need_hessian_list; - std::vector> need_value_residual_list; - std::vector> need_gradient_residual_list; - std::vector> need_value_list_LHS; - std::vector> need_gradient_list_LHS; - std::vector> need_hessian_list_LHS; - std::vector> need_value_residual_list_LHS; - std::vector> need_gradient_residual_list_LHS; - - std::vector> need_value_change_list_LHS; - std::vector> need_gradient_change_list_LHS; - std::vector> need_hessian_change_list_LHS; - - std::vector> need_value_list_PP; - std::vector> need_gradient_list_PP; - std::vector> need_hessian_list_PP; - std::vector> need_value_list_nucleation; - std::vector> nucleating_variable_list; - - std::vector> var_name_list_PP; - std::vector> var_type_list_PP; - std::vector> output_integral_list; - std::vector> need_value_residual_list_PP; - std::vector> need_gradient_residual_list_PP; - + set_dependencies_value_term_LHS(const unsigned int &index, + const std::string &dependencies); + + /** + * \brief Set the dependencies for the gradient term of the LHS equation of the variable + * at `index`. + * + * \param index Index of variable + * \param dependencies String containing comma-separated list of dependencies for + * variable at `index` Hint: "variable, grad(variable), hess(variable)" + */ void - set_dependencies_value_term_RHS(unsigned int index, std::string dependencies); + set_dependencies_gradient_term_LHS(const unsigned int &index, + const std::string &dependencies); + + /** + * \brief Flag whether the variable at `index` is needed to calculate the nucleation + * probability. + * + * \param index Index of variable + * \param flag true: variable is needed, false: variable is not needed. + */ void - set_dependencies_gradient_term_RHS(unsigned int index, std::string dependencies); + set_need_value_nucleation(const unsigned int &index, const bool &flag); + + /** + * \brief Flag whether the variable at `index` is can have a nucleation event. + * + * \param index Index of variable + * \param flag true: variable can nucleate, false: variable can not nucleate. + */ void - set_dependencies_value_term_LHS(unsigned int index, std::string dependencies); + set_allowed_to_nucleate(const unsigned int &index, const bool &flag); + + /** + * \brief (Postprocess only) Flag whether the postprocessing variable at `index` should + * have its domain integral calculated and output. + * + * \param index Index of variable + * \param flag true: calculate and output the integral of the field over the domain, + * false: do nothing + */ void - set_dependencies_gradient_term_LHS(unsigned int index, std::string dependencies); - - std::vector> var_eq_dependencies_value_RHS; - std::vector> var_eq_dependencies_gradient_RHS; - std::vector> var_eq_dependencies_value_LHS; - std::vector> var_eq_dependencies_gradient_LHS; - - std::vector> var_eq_dependencies_value_PP; - std::vector> var_eq_dependencies_gradient_PP; - - EquationDependencyParser equation_dependency_parser; - - unsigned int number_of_variables; - - std::vector var_name; - std::vector var_type; - std::vector var_eq_type; - - std::vector var_nonlinear; - - std::vector nucleating_variable; - std::vector need_value_nucleation; - - unsigned int pp_number_of_variables; - - std::vector pp_var_name; - std::vector pp_var_type; - std::vector pp_calc_integral; + set_output_integral(const unsigned int &index, const bool &flag); + + /** + * \brief The solutions variable attributes + */ + std::map attributes; + + /** + * \brief The postprocessing variable attributes + */ + std::map pp_attributes; + + /** + * \brief Useful pointer for setting whether solution or postprocessiong variables are + * being loaded + */ + std::map *relevant_attributes = nullptr; + +private: + /** + * \brief Perform a suite of assertions on attributes and pp_attributes to ensure that + * the user's inputs are well-formed + */ + void + validate_attributes(); + + /** + * \brief Utility to remove whitespace from strings + */ + std::string + strip_whitespace(const std::string &text); + // The above function should be moved to a 'utilities' module }; #endif diff --git a/include/variableAttributes.h b/include/variableAttributes.h new file mode 100644 index 000000000..ca663bc5f --- /dev/null +++ b/include/variableAttributes.h @@ -0,0 +1,90 @@ +#ifndef VARIABLEATTRIBUTES_H +#define VARIABLEATTRIBUTES_H + +#include + +#include "varTypeEnums.h" + +#include +#include +#include + +using EvalFlags = dealii::EvaluationFlags::EvaluationFlags; + +/** + * \brief Structure to hold the variable attributes that will be passed to a + * setInputParameters object. + */ +struct variableAttributes +{ + // Variable attributes + std::string name = ""; + fieldType var_type = UNDEFINED_FIELD; + PDEType eq_type = UNDEFINED_PDE; + bool need_value_nucleation = false; + bool nucleating_variable = false; + bool is_pp = false; + bool is_nonlinear = false; + bool calc_integral = false; + bool output_integral = false; + + // This variable's dependencies + std::set dependencies_value_RHS; + std::set dependencies_gradient_RHS; + std::set dependencies_RHS; + std::set dependencies_value_LHS; + std::set dependencies_gradient_LHS; + std::set dependencies_LHS; + std::set dependencies_value_PP; + std::set dependencies_gradient_PP; + std::set dependencies_PP; + + std::set dependency_set; + + // Evaluation Flags. Tells deal.II whether or not to retrieve the value, grad, hess, + // etc. for equations + EvalFlags eval_flags_explicit_RHS = dealii::EvaluationFlags::nothing; + EvalFlags eval_flags_nonexplicit_RHS = dealii::EvaluationFlags::nothing; + EvalFlags eval_flags_nonexplicit_LHS = dealii::EvaluationFlags::nothing; + + EvalFlags eval_flags_change_nonexplicit_LHS = dealii::EvaluationFlags::nothing; + + EvalFlags eval_flags_residual_explicit_RHS = dealii::EvaluationFlags::nothing; + EvalFlags eval_flags_residual_nonexplicit_RHS = dealii::EvaluationFlags::nothing; + EvalFlags eval_flags_residual_nonexplicit_LHS = dealii::EvaluationFlags::nothing; + + EvalFlags eval_flags_postprocess = dealii::EvaluationFlags::nothing; + EvalFlags eval_flags_residual_postprocess = dealii::EvaluationFlags::nothing; + + /** + * \brief Combine 'value' and 'gradient' residual dependencies to one dependency set per + * RHS, LHS, PP. + */ + void + format_dependencies(); + + /** + * \brief Take user-defined dependency sets to set the evaluation flags for each + * variable. + */ + void + parse_dependencies(std::map &other_var_attributes); + + /** + * \brief Take user-defined dependency sets to set the residual flags for each + * variable. + */ + void + parse_residual_dependencies(); + + /** + * \brief Helper function that returns a set of pointers to the flags that need to be + * set when `other_variable` is dependent on this variable. + * + * \param other_variable Variable that is dependent on this variable. + */ + std::set + eval_flags_for_eq_type(const variableAttributes &other_variable); +}; + +#endif diff --git a/src/EquationDependencyParser/EquationDependencyParser.cc b/src/EquationDependencyParser/EquationDependencyParser.cc deleted file mode 100644 index ba199ba84..000000000 --- a/src/EquationDependencyParser/EquationDependencyParser.cc +++ /dev/null @@ -1,492 +0,0 @@ -#include "../../include/EquationDependencyParser.h" - -#include -#include - -#include - -void -EquationDependencyParser::strip_dependency_whitespace(std::string &dependency_list) -{ - dependency_list.erase(std::remove(dependency_list.begin(), dependency_list.end(), ' '), - dependency_list.end()); -} - -void -EquationDependencyParser::parse(std::vector &var_name, - std::vector var_eq_type, - std::vector sorted_dependencies_value_RHS, - std::vector sorted_dependencies_gradient_RHS, - std::vector sorted_dependencies_value_LHS, - std::vector sorted_dependencies_gradient_LHS, - std::vector &var_nonlinear) -{ - // Determine the number of variables - size_t n_variables = var_name.size(); - - // Resize the dependency evaluation flag vectors - eval_flags_explicit_RHS.resize(n_variables, dealii::EvaluationFlags::nothing); - eval_flags_nonexplicit_RHS.resize(n_variables, dealii::EvaluationFlags::nothing); - eval_flags_nonexplicit_LHS.resize(n_variables, dealii::EvaluationFlags::nothing); - eval_flags_change_nonexplicit_LHS.resize(n_variables, dealii::EvaluationFlags::nothing); - - // Resize the residual evaluation flag vectors - eval_flags_residual_explicit_RHS.resize(n_variables, dealii::EvaluationFlags::nothing); - eval_flags_residual_nonexplicit_RHS.resize(n_variables, - dealii::EvaluationFlags::nothing); - eval_flags_residual_nonexplicit_LHS.resize(n_variables, - dealii::EvaluationFlags::nothing); - - // Now parse the dependency strings to set the flags to true where needed - for (unsigned int i = 0; i < var_name.size(); i++) - { - // Strip excess whitespace - strip_dependency_whitespace(sorted_dependencies_value_RHS[i]); - strip_dependency_whitespace(sorted_dependencies_gradient_RHS[i]); - - // Now check for each variable_eq_type - if (var_eq_type[i] == EXPLICIT_TIME_DEPENDENT) - { - bool single_var_nonlinear; - - parseDependencyListRHS(var_name, - var_eq_type, - i, - sorted_dependencies_value_RHS[i], - sorted_dependencies_gradient_RHS[i], - eval_flags_explicit_RHS, - eval_flags_residual_explicit_RHS, - single_var_nonlinear); - - var_nonlinear.push_back(single_var_nonlinear); - } - else if (var_eq_type[i] == AUXILIARY) - { - bool single_var_nonlinear; - - parseDependencyListRHS(var_name, - var_eq_type, - i, - sorted_dependencies_value_RHS[i], - sorted_dependencies_gradient_RHS[i], - eval_flags_nonexplicit_RHS, - eval_flags_residual_nonexplicit_RHS, - single_var_nonlinear); - - var_nonlinear.push_back(single_var_nonlinear); - } - else if (var_eq_type[i] == IMPLICIT_TIME_DEPENDENT || - var_eq_type[i] == TIME_INDEPENDENT) - { - bool single_var_nonlinear_RHS, single_var_nonlinear_LHS; - - parseDependencyListRHS(var_name, - var_eq_type, - i, - sorted_dependencies_value_RHS[i], - sorted_dependencies_gradient_RHS[i], - eval_flags_nonexplicit_RHS, - eval_flags_residual_nonexplicit_RHS, - single_var_nonlinear_RHS); - - parseDependencyListLHS(var_name, - var_eq_type, - i, - sorted_dependencies_value_LHS[i], - sorted_dependencies_gradient_LHS[i], - eval_flags_nonexplicit_LHS, - eval_flags_change_nonexplicit_LHS, - eval_flags_residual_nonexplicit_LHS, - single_var_nonlinear_LHS); - - var_nonlinear.push_back(single_var_nonlinear_RHS || single_var_nonlinear_LHS); - } - } -} - -void -EquationDependencyParser::parseDependencyListRHS( - std::vector &variable_name_list, - std::vector variable_eq_type, - unsigned int variable_index, - std::string &value_dependencies, - std::string &gradient_dependencies, - std::vector &evaluation_flags, - std::vector &residual_flags, - bool &is_nonlinear) -{ - // Split the dependency strings into lists of entries - std::vector split_value_dependency_list = - dealii::Utilities::split_string_list(value_dependencies); - std::vector split_gradient_dependency_list = - dealii::Utilities::split_string_list(gradient_dependencies); - - // Check if either is empty and set value and gradient flags for the - // residual appropriately - if (split_value_dependency_list.size() > 0) - { - residual_flags[variable_index] |= dealii::EvaluationFlags::values; - } - if (split_gradient_dependency_list.size() > 0) - { - residual_flags[variable_index] |= dealii::EvaluationFlags::gradients; - } - - // Merge the lists of dependency entries - std::vector split_dependency_list = split_value_dependency_list; - split_dependency_list.insert(split_dependency_list.end(), - split_gradient_dependency_list.begin(), - split_gradient_dependency_list.end()); - - // Set nonlinearity to false - is_nonlinear = false; - - // Cycle through each dependency entry - for (const auto &dependency : split_dependency_list) - { - // Flag to make sure we have assigned a dependency entry - [[maybe_unused]] bool dependency_entry_assigned = false; - - // Loop through all known variable names [x, grad(x), and hess(x)] to see which ones - // are on our dependency list. If we have two variables x and y this will loop twice - // to see if the supplied dependency needs either two of the variables. A successful - // match will update the values/gradient/hessian flag for that dependency variable. - std::size_t dependency_variable_index = 0; - for (const auto &variable : variable_name_list) - { - // Create grad() and hess() variants of the variable name - std::string gradient_variable = {"grad()"}; - gradient_variable.insert(--gradient_variable.end(), - variable.begin(), - variable.end()); - - std::string hessian_variable = {"hess()"}; - hessian_variable.insert(--hessian_variable.end(), - variable.begin(), - variable.end()); - - // Is the variable we are finding the dependencies for explicit - bool variable_is_explicit = - variable_eq_type[variable_index] == EXPLICIT_TIME_DEPENDENT; - - // Is the dependency variable explicit - bool dependency_variable_is_explicit = - variable_eq_type[dependency_variable_index] == EXPLICIT_TIME_DEPENDENT; - - // Is the dependency the variable - bool same_variable = variable_index == dependency_variable_index; - - // Case if the dependency is x - if (dependency == variable) - { - evaluation_flags[dependency_variable_index] |= - dealii::EvaluationFlags::values; - dependency_entry_assigned = true; - } - // Case if the dependency is grad(x) - else if (dependency == gradient_variable) - { - evaluation_flags[dependency_variable_index] |= - dealii::EvaluationFlags::gradients; - dependency_entry_assigned = true; - } - // Case if the dependency is hess(x) - else if (dependency == hessian_variable) - { - evaluation_flags[dependency_variable_index] |= - dealii::EvaluationFlags::hessians; - dependency_entry_assigned = true; - } - - // Check for nonlinearity - is_nonlinear = - !variable_is_explicit && !same_variable && !dependency_variable_is_explicit; - - // Increment counter - ++dependency_variable_index; - } - - Assert(dependency_entry_assigned, - dealii::StandardExceptions::ExcMessage("PRISMS-PF Error: Dependency entry " + - dependency + " is not valid.")); - } -} - -void -EquationDependencyParser::parseDependencyListLHS( - std::vector &variable_name_list, - std::vector variable_eq_type, - unsigned int variable_index, - std::string &value_dependencies, - std::string &gradient_dependencies, - std::vector &evaluation_flags, - std::vector &change_flags, - std::vector &residual_flags, - bool &is_nonlinear) -{ - // Split the dependency strings into lists of entries - std::vector split_value_dependency_list = - dealii::Utilities::split_string_list(value_dependencies); - std::vector split_gradient_dependency_list = - dealii::Utilities::split_string_list(gradient_dependencies); - - // Check if either is empty and set value and gradient flags for the - // residual appropriately - if (split_value_dependency_list.size() > 0) - { - residual_flags[variable_index] |= dealii::EvaluationFlags::values; - } - if (split_gradient_dependency_list.size() > 0) - { - residual_flags[variable_index] |= dealii::EvaluationFlags::gradients; - } - - // Merge the lists of dependency entries - std::vector split_dependency_list = split_value_dependency_list; - split_dependency_list.insert(split_dependency_list.end(), - split_gradient_dependency_list.begin(), - split_gradient_dependency_list.end()); - - // Set nonlinearity to false - is_nonlinear = false; - - // Cycle through each dependency entry - for (const auto &dependency : split_dependency_list) - { - // Flag to make sure we have assigned a dependency entry - [[maybe_unused]] bool dependency_entry_assigned = false; - - // Loop through all known variable names [x, grad(x), and hess(x)] to see which ones - // are on our dependency list. If we have two variables x and y this will loop twice - // to see if the supplied dependency needs either two of the variables. A successful - // match will update the values/gradient/hessian flag for that dependency variable. - std::size_t dependency_variable_index = 0; - for (const auto &variable : variable_name_list) - { - // Create grad(), hess(), change(), grad(change()), and hess(change()) variants - // of the variable name - std::string gradient_variable = {"grad()"}; - gradient_variable.insert(--gradient_variable.end(), - variable.begin(), - variable.end()); - - std::string hessian_variable = {"hess()"}; - hessian_variable.insert(--hessian_variable.end(), - variable.begin(), - variable.end()); - - std::string change_value_variable = {"change()"}; - change_value_variable.insert(--change_value_variable.end(), - variable.begin(), - variable.end()); - - std::string change_gradient_variable = {"grad(change())"}; - change_gradient_variable.insert(--(--change_gradient_variable.end()), - variable.begin(), - variable.end()); - - std::string change_hessian_variable = {"hess(change())"}; - change_hessian_variable.insert(--(--change_hessian_variable.end()), - variable.begin(), - variable.end()); - - // Is the variable we are finding the dependencies for explicit - bool dependency_variable_is_explicit = - variable_eq_type[dependency_variable_index] == EXPLICIT_TIME_DEPENDENT; - - // Case if the dependency is x - if (dependency == variable) - { - evaluation_flags[dependency_variable_index] |= - dealii::EvaluationFlags::values; - dependency_entry_assigned = true; - - // Check for nonlinearity - is_nonlinear = !dependency_variable_is_explicit; - } - // Case if the dependency is grad(x) - else if (dependency == gradient_variable) - { - evaluation_flags[dependency_variable_index] |= - dealii::EvaluationFlags::gradients; - dependency_entry_assigned = true; - - // Check for nonlinearity - is_nonlinear = !dependency_variable_is_explicit; - } - // Case if the dependency is hess(x) - else if (dependency == hessian_variable) - { - evaluation_flags[dependency_variable_index] |= - dealii::EvaluationFlags::hessians; - dependency_entry_assigned = true; - - // Check for nonlinearity - is_nonlinear = !dependency_variable_is_explicit; - } - // Case if the dependency is change(x) - else if (dependency == change_value_variable) - { - change_flags[dependency_variable_index] |= dealii::EvaluationFlags::values; - dependency_entry_assigned = true; - - Assert(variable_index == dependency_variable_index, - dealii::StandardExceptions::ExcMessage( - "PRISMS-PF Error: Dependency entry " + dependency + - " is not valid because the change in a variable can " - "only be accessed in its own governing equation.")); - } - // Case if the dependency is grad(change(x)) - else if (dependency == change_gradient_variable) - { - change_flags[dependency_variable_index] |= - dealii::EvaluationFlags::gradients; - dependency_entry_assigned = true; - - Assert(variable_index == dependency_variable_index, - dealii::StandardExceptions::ExcMessage( - "PRISMS-PF Error: Dependency entry " + dependency + - " is not valid because the change in a variable can " - "only be accessed in its own governing equation.")); - } - // Case if the dependency is hess(change(x)) - else if (dependency == change_hessian_variable) - { - change_flags[dependency_variable_index] |= - dealii::EvaluationFlags::hessians; - dependency_entry_assigned = true; - - Assert(variable_index == dependency_variable_index, - dealii::StandardExceptions::ExcMessage( - "PRISMS-PF Error: Dependency entry " + dependency + - " is not valid because the change in a variable can " - "only be accessed in its own governing equation.")); - } - - // Increment counter - ++dependency_variable_index; - } - - Assert(dependency_entry_assigned, - dealii::StandardExceptions::ExcMessage("PRISMS-PF Error: Dependency entry " + - dependency + " is not valid.")); - } -} - -void -EquationDependencyParser::pp_parse(std::vector &var_name, - std::vector &pp_var_name, - std::vector sorted_dependencies_value, - std::vector sorted_dependencies_gradient) -{ - // Determine the number of variables - size_t n_variables = var_name.size(); - size_t n_postprocess_variables = pp_var_name.size(); - - // Resize the dependency evaluation flag vectors - eval_flags_postprocess.resize(n_variables, dealii::EvaluationFlags::nothing); - - // Resize the residual evaluation flag vectors - eval_flags_residual_postprocess.resize(n_postprocess_variables, - dealii::EvaluationFlags::nothing); - - // Now parse the dependency strings to set the flags to true where needed - for (unsigned int i = 0; i < pp_var_name.size(); i++) - { - // Strip excess whitespace - strip_dependency_whitespace(sorted_dependencies_value[i]); - strip_dependency_whitespace(sorted_dependencies_gradient[i]); - - parseDependencyListPP(var_name, - i, - sorted_dependencies_value[i], - sorted_dependencies_gradient[i], - eval_flags_postprocess, - eval_flags_residual_postprocess); - } -} - -void -EquationDependencyParser::parseDependencyListPP( - std::vector &variable_name_list, - unsigned int variable_index, - std::string &value_dependencies, - std::string &gradient_dependencies, - std::vector &evaluation_flags, - std::vector &residual_flags) -{ - // Split the dependency strings into lists of entries - std::vector split_value_dependency_list = - dealii::Utilities::split_string_list(value_dependencies); - std::vector split_gradient_dependency_list = - dealii::Utilities::split_string_list(gradient_dependencies); - - // Check if either is empty and set value and gradient flags for the - // residual appropriately - if (split_value_dependency_list.size() > 0) - { - residual_flags[variable_index] |= dealii::EvaluationFlags::values; - } - if (split_gradient_dependency_list.size() > 0) - { - residual_flags[variable_index] |= dealii::EvaluationFlags::gradients; - } - - // Merge the lists of dependency entries - std::vector split_dependency_list = split_value_dependency_list; - split_dependency_list.insert(split_dependency_list.end(), - split_gradient_dependency_list.begin(), - split_gradient_dependency_list.end()); - - // Cycle through each dependency entry - for (const auto &dependency : split_dependency_list) - { - // Flag to make sure we have assigned a dependency entry - [[maybe_unused]] bool dependency_entry_assigned = false; - - // Loop through all known variable names [x, grad(x), and hess(x)] to see which ones - // are on our dependency list. If we have two variables x and y this will loop twice - // to see if the supplied dependency needs either two of the variables. A successful - // match will update the values/gradient/hessian flag for that dependency variable. - std::size_t dependency_variable_index = 0; - for (const auto &variable : variable_name_list) - { - // Create grad() and hess() variants of the variable name - std::string gradient_variable = {"grad()"}; - gradient_variable.insert(--gradient_variable.end(), - variable.begin(), - variable.end()); - - std::string hessian_variable = {"hess()"}; - hessian_variable.insert(--hessian_variable.end(), - variable.begin(), - variable.end()); - - if (dependency == variable) - { - evaluation_flags[dependency_variable_index] |= - dealii::EvaluationFlags::values; - dependency_entry_assigned = true; - } - else if (dependency == gradient_variable) - { - evaluation_flags[dependency_variable_index] |= - dealii::EvaluationFlags::gradients; - dependency_entry_assigned = true; - } - else if (dependency == hessian_variable) - { - evaluation_flags[dependency_variable_index] |= - dealii::EvaluationFlags::hessians; - dependency_entry_assigned = true; - } - - // Increment counter - ++dependency_variable_index; - } - - Assert(dependency_entry_assigned, - dealii::StandardExceptions::ExcMessage("PRISMS-PF Error: Dependency entry " + - dependency + " is not valid.")); - } -} diff --git a/src/inputFileReader/inputFileReader.cc b/src/inputFileReader/inputFileReader.cc index baa2ec5d2..b2e2b2f86 100644 --- a/src/inputFileReader/inputFileReader.cc +++ b/src/inputFileReader/inputFileReader.cc @@ -4,29 +4,16 @@ #include #include -#include "../../include/EquationDependencyParser.h" +// #include "variableAttributeLoader.h" + #include "../../include/RefinementCriterion.h" -#include "../../include/sortIndexEntryPairList.h" #include // Constructor inputFileReader::inputFileReader(const std::string &input_file_name, - variableAttributeLoader &variable_attributes) + variableAttributeLoader &_variable_attributes) + : variable_attributes(_variable_attributes) { - // Extract an ordered vector of the variable types from variable_attributes - unsigned int number_of_variables = variable_attributes.var_name_list.size(); - var_types = variable_attributes.var_type; - var_eq_types = variable_attributes.var_eq_type; - var_names = variable_attributes.var_name; - - var_nonlinear = variable_attributes.var_nonlinear; - - var_nucleates = sortIndexEntryPairList(variable_attributes.nucleating_variable_list, - number_of_variables, - false); - - num_pp_vars = variable_attributes.var_name_list_PP.size(); - num_constants = get_number_of_entries(input_file_name, "set", "Model constant"); model_constant_names = @@ -39,11 +26,7 @@ inputFileReader::inputFileReader(const std::string &input_file_name, } // Read in all of the parameters now - declare_parameters(parameter_handler, - var_types, - var_eq_types, - num_constants, - var_nucleates); + declare_parameters(parameter_handler, num_constants); #if (DEAL_II_VERSION_MAJOR < 9 && DEAL_II_VERSION_MINOR < 5) parameter_handler.read_input(input_file_name); #else @@ -271,11 +254,8 @@ inputFileReader::get_entry_name_ending_list(const std::string ¶meters_file_n } void -inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_handler, - const std::vector &var_types, - const std::vector &var_eq_types, - const unsigned int num_of_constants, - const std::vector &var_nucleates) const +inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_handler, + const unsigned int num_of_constants) const { // Declare all of the entries parameter_handler.declare_entry("Number of dimensions", @@ -335,10 +315,10 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_hand dealii::Patterns::Integer(), "The number of time steps between mesh refinement operations."); - for (unsigned int i = 0; i < var_types.size(); i++) + for (const auto &[index, variable] : variable_attributes.attributes) { std::string subsection_text = "Refinement criterion: "; - subsection_text.append(var_names.at(i)); + subsection_text.append(variable.name); parameter_handler.enter_subsection(subsection_text); { parameter_handler.declare_entry( @@ -385,13 +365,13 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_hand dealii::Patterns::Double(), "The value of simulated time where the simulation ends."); - for (unsigned int i = 0; i < var_types.size(); i++) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (var_eq_types.at(i) == TIME_INDEPENDENT || - var_eq_types.at(i) == IMPLICIT_TIME_DEPENDENT) + if (variable.eq_type == TIME_INDEPENDENT || + variable.eq_type == IMPLICIT_TIME_DEPENDENT) { std::string subsection_text = "Linear solver parameters: "; - subsection_text.append(var_names.at(i)); + subsection_text.append(variable.name); parameter_handler.enter_subsection(subsection_text); { parameter_handler.declare_entry("Tolerance type", @@ -420,12 +400,12 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_hand "The maximum number of nonlinear solver " "iterations before the loop is stopped."); - for (unsigned int i = 0; i < var_types.size(); i++) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (var_nonlinear.at(i)) + if (variable.is_nonlinear) { std::string subsection_text = "Nonlinear solver parameters: "; - subsection_text.append(var_names.at(i)); + subsection_text.append(variable.name); parameter_handler.enter_subsection(subsection_text); { parameter_handler.declare_entry( @@ -563,12 +543,12 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_hand /*---------------------- | Boundary conditions -----------------------*/ - for (unsigned int i = 0; i < var_types.size(); i++) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (var_types[i] == SCALAR) + if (variable.var_type == SCALAR) { std::string bc_text = "Boundary condition for variable "; - bc_text.append(var_names.at(i)); + bc_text.append(variable.name); parameter_handler.declare_entry( bc_text, "", @@ -578,7 +558,7 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_hand else { std::string bc_text = "Boundary condition for variable "; - bc_text.append(var_names.at(i)); + bc_text.append(variable.name); bc_text.append(", x component"); parameter_handler.declare_entry( bc_text, @@ -587,7 +567,7 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_hand "The boundary conditions for one of the governing equations)."); bc_text = "Boundary condition for variable "; - bc_text.append(var_names.at(i)); + bc_text.append(variable.name); bc_text.append(", y component"); parameter_handler.declare_entry( bc_text, @@ -596,7 +576,7 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_hand "The boundary conditions for one of the governing equations)."); bc_text = "Boundary condition for variable "; - bc_text.append(var_names.at(i)); + bc_text.append(variable.name); bc_text.append(", z component"); parameter_handler.declare_entry( bc_text, @@ -609,10 +589,10 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_hand /*---------------------- | Pinning point -----------------------*/ - for (unsigned int i = 0; i < var_types.size(); i++) + for (const auto &[index, variable] : variable_attributes.attributes) { std::string pinning_text = "Pinning point: "; - pinning_text.append(var_names.at(i)); + pinning_text.append(variable.name); parameter_handler.enter_subsection(pinning_text); { parameter_handler.declare_entry("x", @@ -666,12 +646,12 @@ inputFileReader::declare_parameters(dealii::ParameterHandler ¶meter_hand dealii::Patterns::Double(), "The time after which no nucleation occurs."); - for (unsigned int i = 0; i < var_types.size(); i++) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (var_nucleates.at(i)) + if (variable.nucleating_variable) { std::string nucleation_text = "Nucleation parameters: "; - nucleation_text.append(var_names.at(i)); + nucleation_text.append(variable.name); parameter_handler.enter_subsection(nucleation_text); { parameter_handler.declare_entry( diff --git a/src/matrixfree/boundaryConditions.cc b/src/matrixfree/boundaryConditions.cc index 8053e41dd..aa75d017a 100644 --- a/src/matrixfree/boundaryConditions.cc +++ b/src/matrixfree/boundaryConditions.cc @@ -22,7 +22,7 @@ MatrixFreePDE::applyNeumannBCs() unsigned int starting_BC_list_index = 0; for (unsigned int i = 0; i < currentFieldIndex; i++) { - if (userInputs.var_type[i] == SCALAR) + if (var_attributes.attributes.at(i).var_type == SCALAR) { starting_BC_list_index++; } @@ -32,7 +32,7 @@ MatrixFreePDE::applyNeumannBCs() } } - if (userInputs.var_type[currentFieldIndex] == SCALAR) + if (var_attributes.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 (userInputs.var_type[i] == SCALAR) + if (var_attributes.attributes.at(i).var_type == SCALAR) { starting_BC_list_index++; } @@ -112,7 +112,7 @@ MatrixFreePDE::applyDirichletBCs() } } - if (userInputs.var_type[currentFieldIndex] == SCALAR) + if (var_attributes.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 (userInputs.var_type[i] == SCALAR) + if (var_attributes.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; - userInputs.var_type[currentFieldIndex] == VECTOR ? n_components = dim - : n_components = 1; + var_attributes.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/matrixfree/buildFields.cc b/src/matrixfree/buildFields.cc index 041110307..9e26b2f3b 100644 --- a/src/matrixfree/buildFields.cc +++ b/src/matrixfree/buildFields.cc @@ -18,9 +18,9 @@ MatrixFreePDE::buildFields() // Build each of the fields in the system for (unsigned int i = 0; i < userInputs.number_of_variables; i++) { - fields.push_back(Field(userInputs.var_type[i], - userInputs.var_eq_type[i], - userInputs.var_name[i])); + fields.push_back(Field(var_attributes.attributes.at(i).var_type, + var_attributes.attributes.at(i).eq_type, + var_attributes.attributes.at(i).name)); } } diff --git a/src/matrixfree/checkpoint.cc b/src/matrixfree/checkpoint.cc index 827a57127..f564f304e 100644 --- a/src/matrixfree/checkpoint.cc +++ b/src/matrixfree/checkpoint.cc @@ -40,30 +40,30 @@ MatrixFreePDE::save_checkpoint() // First, get lists of scalar and vector fields std::vector scalar_var_indices, vector_var_indices; - for (unsigned int var = 0; var < userInputs.number_of_variables; var++) + for (const auto &[index, variable] : var_attributes.attributes) { - if (userInputs.var_type[var] == SCALAR) + if (variable.var_type == SCALAR) { - scalar_var_indices.push_back(var); + scalar_var_indices.push_back(index); } else { - vector_var_indices.push_back(var); + vector_var_indices.push_back(index); } } // Second, build one solution set list for scalars and one for vectors std::vector solSet_transfer_scalars; std::vector solSet_transfer_vectors; - for (unsigned int var = 0; var < userInputs.number_of_variables; ++var) + for (const auto &[index, variable] : var_attributes.attributes) { - if (userInputs.var_type[var] == SCALAR) + if (variable.var_type == SCALAR) { - solSet_transfer_scalars.push_back(solutionSet[var]); + solSet_transfer_scalars.push_back(solutionSet[index]); } else { - solSet_transfer_vectors.push_back(solutionSet[var]); + solSet_transfer_vectors.push_back(solutionSet[index]); } } @@ -145,30 +145,30 @@ MatrixFreePDE::load_checkpoint_fields() // First, get lists of scalar and vector fields std::vector scalar_var_indices, vector_var_indices; - for (unsigned int var = 0; var < userInputs.number_of_variables; var++) + for (const auto &[index, variable] : var_attributes.attributes) { - if (userInputs.var_type[var] == SCALAR) + if (variable.var_type == SCALAR) { - scalar_var_indices.push_back(var); + scalar_var_indices.push_back(index); } else { - vector_var_indices.push_back(var); + vector_var_indices.push_back(index); } } // Second, build one solution set list for scalars and one for vectors std::vector solSet_transfer_scalars; std::vector solSet_transfer_vectors; - for (unsigned int var = 0; var < userInputs.number_of_variables; ++var) + for (const auto &[index, variable] : var_attributes.attributes) { - if (userInputs.var_type[var] == SCALAR) + if (variable.var_type == SCALAR) { - solSet_transfer_scalars.push_back(solutionSet[var]); + solSet_transfer_scalars.push_back(solutionSet[index]); } else { - solSet_transfer_vectors.push_back(solutionSet[var]); + solSet_transfer_vectors.push_back(solutionSet[index]); } } diff --git a/src/matrixfree/init.cc b/src/matrixfree/init.cc index 58d4342d9..8b6cfc19b 100644 --- a/src/matrixfree/init.cc +++ b/src/matrixfree/init.cc @@ -281,7 +281,7 @@ MatrixFreePDE::init() if (fields[fieldIndex].pdetype == TIME_INDEPENDENT || fields[fieldIndex].pdetype == IMPLICIT_TIME_DEPENDENT || (fields[fieldIndex].pdetype == AUXILIARY && - userInputs.var_nonlinear[fieldIndex])) + var_attributes.attributes.at(fieldIndex).is_nonlinear)) { if (fields[fieldIndex].type == SCALAR) { diff --git a/src/matrixfree/initialConditions.cc b/src/matrixfree/initialConditions.cc index 70e2b36a2..c7582c26a 100644 --- a/src/matrixfree/initialConditions.cc +++ b/src/matrixfree/initialConditions.cc @@ -68,11 +68,11 @@ MatrixFreePDE::applyInitialConditions() // Get the index of one of the scalar fields unsigned int scalar_field_index = 0; - for (unsigned int var = 0; var < userInputs.number_of_variables; var++) + for (const auto &[index, variable] : var_attributes.attributes) { - if (userInputs.var_type.at(var) == SCALAR) + if (variable.var_type == SCALAR) { - scalar_field_index = var; + scalar_field_index = index; break; } } @@ -376,12 +376,12 @@ MatrixFreePDE::applyInitialConditions() for (const auto &index : index_list) { - std::string var_name = userInputs.load_field_name[index]; + std::string var_name = var_attributes.attributes.at(index).name; // Find the scalar field in the file ScalarField &field = body.find_scalar_field(var_name); - if (userInputs.var_type[index] == SCALAR) + if (var_attributes.attributes.at(index).var_type == SCALAR) { pcout << "Applying PField initial condition for " << userInputs.load_field_name[index] << "...\n"; @@ -399,8 +399,7 @@ MatrixFreePDE::applyInitialConditions() } unsigned int op_list_index = 0; - for (unsigned int var_index = 0; var_index < userInputs.number_of_variables; - var_index++) + for (const auto &[var_index, variable] : var_attributes.attributes) { bool is_remapped_op = false; if (op_list_index < userInputs.variables_for_remapping.size()) @@ -418,7 +417,7 @@ MatrixFreePDE::applyInitialConditions() { pcout << "Applying non-PField initial condition...\n"; - if (userInputs.var_type[var_index] == SCALAR) + if (variable.var_type == SCALAR) { VectorTools::interpolate(*dofHandlersSet[var_index], InitialCondition(var_index, @@ -426,7 +425,7 @@ MatrixFreePDE::applyInitialConditions() this), *solutionSet[var_index]); } - else if (userInputs.var_type[var_index] == VECTOR) + else if (variable.var_type == VECTOR) { VectorTools::interpolate(*dofHandlersSet[var_index], InitialConditionVector(var_index, diff --git a/src/matrixfree/outputResults.cc b/src/matrixfree/outputResults.cc index aac7d1078..51f4864bb 100644 --- a/src/matrixfree/outputResults.cc +++ b/src/matrixfree/outputResults.cc @@ -84,24 +84,20 @@ MatrixFreePDE::outputResults() output_file << currentTime; } - for (unsigned int i = 0; i < userInputs.pp_number_of_variables; i++) + for (const auto &[pp_index, pp_variable] : var_attributes.pp_attributes) { - if (userInputs.pp_calc_integral[i]) + if (pp_variable.calc_integral) { double integrated_field; - computeIntegral(integrated_field, i, postProcessedSet); - pcout << "Integrated value of " - << userInputs.pp_var_name[userInputs.integrated_field_indices[i]] - << ": " << integrated_field << std::endl; + computeIntegral(integrated_field, pp_index, postProcessedSet); + pcout << "Integrated value of " << pp_variable.name << ": " + << integrated_field << std::endl; if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0) { - output_file - << "\t" - << userInputs.pp_var_name[userInputs.integrated_field_indices[i]] - << "\t" << integrated_field; + output_file << "\t" << pp_variable.name << "\t" << integrated_field; } integrated_postprocessed_fields.at( - userInputs.integrated_field_indices[i]) = integrated_field; + userInputs.integrated_field_indices[pp_index]) = integrated_field; } } if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0) @@ -113,8 +109,7 @@ MatrixFreePDE::outputResults() } // Add the postprocessed fields to data_out - for (unsigned int fieldIndex = 0; fieldIndex < userInputs.pp_number_of_variables; - fieldIndex++) + for (const auto &[fieldIndex, pp_variable] : var_attributes.pp_attributes) { // mark field as scalar/vector unsigned int components; @@ -123,9 +118,8 @@ MatrixFreePDE::outputResults() components = 1; std::vector dataType(components, DataComponentInterpretation::component_is_scalar); - std::vector solutionNames( - components, - userInputs.pp_var_name[fieldIndex].c_str()); + std::vector solutionNames(components, + pp_variable.name.c_str()); // add field to data_out data_out.add_data_vector(*dofHandlersSet[0], *postProcessedSet[fieldIndex], @@ -138,9 +132,8 @@ MatrixFreePDE::outputResults() std::vector dataType(components, DataComponentInterpretation::component_is_part_of_vector); - std::vector solutionNames( - components, - userInputs.pp_var_name[fieldIndex].c_str()); + std::vector solutionNames(components, + pp_variable.name.c_str()); // add field to data_out data_out.add_data_vector(*dofHandlersSet[0], *postProcessedSet[fieldIndex], diff --git a/src/matrixfree/reassignGrains.cc b/src/matrixfree/reassignGrains.cc index be6f86293..2bfe401c3 100644 --- a/src/matrixfree/reassignGrains.cc +++ b/src/matrixfree/reassignGrains.cc @@ -16,11 +16,11 @@ 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 (unsigned int var = 0; var < userInputs.number_of_variables; var++) + for (const auto &[index, variable] : var_attributes.attributes) { - if (userInputs.var_type.at(var) == SCALAR) + if (variable.var_type == SCALAR) { - scalar_field_index = var; + scalar_field_index = index; break; } } diff --git a/src/matrixfree/reinit.cc b/src/matrixfree/reinit.cc index 031598846..51207f588 100644 --- a/src/matrixfree/reinit.cc +++ b/src/matrixfree/reinit.cc @@ -137,7 +137,7 @@ MatrixFreePDE::reinit() if (fields[fieldIndex].pdetype == TIME_INDEPENDENT || fields[fieldIndex].pdetype == IMPLICIT_TIME_DEPENDENT || (fields[fieldIndex].pdetype == AUXILIARY && - userInputs.var_nonlinear[fieldIndex])) + var_attributes.attributes.at(fieldIndex).is_nonlinear)) { if (fields[fieldIndex].type == SCALAR) { diff --git a/src/matrixfree/setNonlinearEqInitialGuess.cc b/src/matrixfree/setNonlinearEqInitialGuess.cc index 1f8953147..6bf49918b 100644 --- a/src/matrixfree/setNonlinearEqInitialGuess.cc +++ b/src/matrixfree/setNonlinearEqInitialGuess.cc @@ -14,10 +14,9 @@ MatrixFreePDE::setNonlinearEqInitialGuess() Timer time; char buffer[200]; - for (unsigned int fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++) + for (const auto &[fieldIndex, variable] : var_attributes.attributes) { - if ((userInputs.var_eq_type[fieldIndex] == TIME_INDEPENDENT) && - userInputs.var_nonlinear[fieldIndex] && + if ((variable.eq_type == TIME_INDEPENDENT) && variable.is_nonlinear && userInputs.nonlinear_solver_parameters.getLaplaceInitializationFlag(fieldIndex)) { currentFieldIndex = fieldIndex; // Used in computeLaplaceLHS() diff --git a/src/matrixfree/solveIncrement.cc b/src/matrixfree/solveIncrement.cc index 3199cf0ff..974643fb8 100644 --- a/src/matrixfree/solveIncrement.cc +++ b/src/matrixfree/solveIncrement.cc @@ -80,7 +80,7 @@ MatrixFreePDE::solveIncrement(bool skip_time_dependent) // not too terrible computeNonexplicitRHS(); - for (unsigned int fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++) + for (const auto &[fieldIndex, variable] : var_attributes.attributes) { currentFieldIndex = fieldIndex; // Used in computeLHS() @@ -89,7 +89,7 @@ MatrixFreePDE::solveIncrement(bool skip_time_dependent) fields[fieldIndex].pdetype == TIME_INDEPENDENT) { if (currentIncrement % userInputs.skip_print_steps == 0 && - userInputs.var_nonlinear[fieldIndex]) + variable.is_nonlinear) { snprintf(buffer, sizeof(buffer), @@ -109,11 +109,11 @@ MatrixFreePDE::solveIncrement(bool skip_time_dependent) } else if (fields[fieldIndex].pdetype == AUXILIARY) { - if (userInputs.var_nonlinear[fieldIndex] || nonlinear_it_index == 0) + if (variable.is_nonlinear || nonlinear_it_index == 0) { // If the equation for this field is nonlinear, save the old // solution - if (userInputs.var_nonlinear[fieldIndex]) + if (variable.is_nonlinear) { if (fields[fieldIndex].type == SCALAR) { @@ -144,7 +144,7 @@ MatrixFreePDE::solveIncrement(bool skip_time_dependent) } // Check to see if this individual variable has converged - if (userInputs.var_nonlinear[fieldIndex]) + if (variable.is_nonlinear) { if (userInputs.nonlinear_solver_parameters.getToleranceType( fieldIndex) == ABSOLUTE_SOLUTION_CHANGE) @@ -358,7 +358,7 @@ MatrixFreePDE::updateImplicitSolution(unsigned int fieldIndex, "solver tolerance.\n"; } - if (userInputs.var_nonlinear[fieldIndex]) + if (var_attributes.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/userInputParameters/loadVariableAttributes.cc b/src/userInputParameters/loadVariableAttributes.cc index 942936973..237bed8f0 100644 --- a/src/userInputParameters/loadVariableAttributes.cc +++ b/src/userInputParameters/loadVariableAttributes.cc @@ -1,152 +1,124 @@ -#include "../../include/EquationDependencyParser.h" #include "../../include/userInputParameters.h" template void userInputParameters::loadVariableAttributes( - variableAttributeLoader variable_attributes) + const variableAttributeLoader &variable_attributes) { - // Pull some variable values from variable_attributes - number_of_variables = variable_attributes.number_of_variables; - var_name = variable_attributes.var_name; - var_type = variable_attributes.var_type; - var_eq_type = variable_attributes.var_eq_type; - - var_nonlinear = variable_attributes.var_nonlinear; - - pp_calc_integral = variable_attributes.pp_calc_integral; - - pp_number_of_variables = variable_attributes.pp_number_of_variables; - pp_var_name = variable_attributes.pp_var_name; - pp_var_type = variable_attributes.pp_var_type; - + number_of_variables = variable_attributes.attributes.size(); + pp_number_of_variables = variable_attributes.pp_attributes.size(); // Load some nucleation parameters - for (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (variable_attributes.nucleating_variable.at(i) == true) + if (variable.nucleating_variable) { - nucleating_variable_indices.push_back(i); + nucleating_variable_indices.push_back(index); } - if (variable_attributes.need_value_nucleation.at(i) || - variable_attributes.nucleating_variable.at(i)) + if (variable.need_value_nucleation || variable.nucleating_variable) { - nucleation_need_value.push_back(i); + nucleation_need_value.push_back(index); } } - nucleating_variable_indices.size() > 0 ? nucleation_occurs = true - : nucleation_occurs = false; - - // Load these attributes into the varInfoList objects + nucleation_occurs = !nucleating_variable_indices.empty(); // Load variable information for calculating the RHS for explicit equations num_var_explicit_RHS = 0; - for (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (!(variable_attributes.equation_dependency_parser.eval_flags_explicit_RHS[i] & - dealii::EvaluationFlags::nothing)) + if (!(variable.eval_flags_explicit_RHS & dealii::EvaluationFlags::nothing)) { num_var_explicit_RHS++; } } varInfoListExplicitRHS.reserve(num_var_explicit_RHS); - for (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { variable_info varInfo; - varInfo.evaluation_flags = - variable_attributes.equation_dependency_parser.eval_flags_explicit_RHS[i]; + varInfo.evaluation_flags = variable.eval_flags_explicit_RHS; - varInfo.residual_flags = variable_attributes.equation_dependency_parser - .eval_flags_residual_explicit_RHS[i]; + varInfo.residual_flags = variable.eval_flags_residual_explicit_RHS; - varInfo.global_var_index = i; + varInfo.global_var_index = index; varInfo.var_needed = !(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing); - varInfo.is_scalar = var_type[i] == SCALAR; + varInfo.is_scalar = variable.var_type == SCALAR; varInfoListExplicitRHS.push_back(varInfo); } // Load variable information for calculating the RHS for nonexplicit equations num_var_nonexplicit_RHS = 0; - for (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (!(variable_attributes.equation_dependency_parser.eval_flags_nonexplicit_RHS[i] & - dealii::EvaluationFlags::nothing)) + if (!(variable.eval_flags_nonexplicit_RHS & dealii::EvaluationFlags::nothing)) { num_var_nonexplicit_RHS++; } } varInfoListNonexplicitRHS.reserve(num_var_nonexplicit_RHS); - for (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { variable_info varInfo; - varInfo.evaluation_flags = - variable_attributes.equation_dependency_parser.eval_flags_nonexplicit_RHS[i]; + varInfo.evaluation_flags = variable.eval_flags_nonexplicit_RHS; - varInfo.residual_flags = variable_attributes.equation_dependency_parser - .eval_flags_residual_nonexplicit_RHS[i]; + varInfo.residual_flags = variable.eval_flags_residual_nonexplicit_RHS; - varInfo.global_var_index = i; + varInfo.global_var_index = index; varInfo.var_needed = !(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing); - varInfo.is_scalar = var_type[i] == SCALAR; + varInfo.is_scalar = variable.var_type == SCALAR; varInfoListNonexplicitRHS.push_back(varInfo); } // Load variable information for calculating the LHS num_var_LHS = 0; - for (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (!(variable_attributes.equation_dependency_parser.eval_flags_nonexplicit_LHS[i] & - dealii::EvaluationFlags::nothing)) + if (!(variable.eval_flags_nonexplicit_LHS & dealii::EvaluationFlags::nothing)) { num_var_LHS++; } } varInfoListLHS.reserve(num_var_LHS); - for (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { variable_info varInfo; - varInfo.evaluation_flags = - variable_attributes.equation_dependency_parser.eval_flags_nonexplicit_LHS[i]; + varInfo.evaluation_flags = variable.eval_flags_nonexplicit_LHS; - varInfo.residual_flags = variable_attributes.equation_dependency_parser - .eval_flags_residual_nonexplicit_LHS[i]; + varInfo.residual_flags = variable.eval_flags_residual_nonexplicit_LHS; - varInfo.global_var_index = i; + varInfo.global_var_index = index; varInfo.var_needed = !(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing); - varInfo.is_scalar = var_type[i] == SCALAR; + varInfo.is_scalar = variable.var_type == SCALAR; varInfoListLHS.push_back(varInfo); } varChangeInfoListLHS.reserve(num_var_LHS); - for (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { variable_info varInfo; - varInfo.evaluation_flags = variable_attributes.equation_dependency_parser - .eval_flags_change_nonexplicit_LHS[i]; + varInfo.evaluation_flags = variable.eval_flags_change_nonexplicit_LHS; // FOR NOW, TAKING THESE FROM THE VARIABLE ITSELF!! - varInfo.residual_flags = variable_attributes.equation_dependency_parser - .eval_flags_residual_nonexplicit_LHS[i]; + varInfo.residual_flags = variable.eval_flags_residual_nonexplicit_LHS; - varInfo.global_var_index = i; + varInfo.global_var_index = index; varInfo.var_needed = !(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing); - varInfo.is_scalar = var_type[i] == SCALAR; + varInfo.is_scalar = variable.var_type == SCALAR; varChangeInfoListLHS.push_back(varInfo); } @@ -154,50 +126,49 @@ userInputParameters::loadVariableAttributes( // Load variable information for postprocessing // First, the info list for the base field variables pp_baseVarInfoList.reserve(number_of_variables); - for (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { variable_info varInfo; - varInfo.evaluation_flags = - variable_attributes.equation_dependency_parser.eval_flags_postprocess[i]; + varInfo.evaluation_flags = variable.eval_flags_postprocess; - varInfo.global_var_index = i; + varInfo.global_var_index = index; varInfo.var_needed = !(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing); - varInfo.is_scalar = var_type[i] == SCALAR; + varInfo.is_scalar = variable.var_type == SCALAR; pp_baseVarInfoList.push_back(varInfo); } // Now load the information for the post-processing variables // Parameters for postprocessing - pp_number_of_variables > 0 ? postProcessingRequired = true - : postProcessingRequired = false; + + postProcessingRequired = pp_number_of_variables > 0; num_integrated_fields = 0; - for (unsigned int i = 0; i < pp_number_of_variables; i++) + for (const auto &[pp_index, pp_variable] : variable_attributes.pp_attributes) { - if (pp_calc_integral[i]) + if (pp_variable.calc_integral) { num_integrated_fields++; - integrated_field_indices.push_back(i); + integrated_field_indices.push_back(pp_index); } } // The info list for the postprocessing field variables pp_varInfoList.reserve(pp_number_of_variables); - for (unsigned int i = 0; i < pp_number_of_variables; i++) + for (const auto &[pp_index, pp_variable] : variable_attributes.pp_attributes) { variable_info varInfo; + varInfo.var_needed = true; - varInfo.residual_flags = - variable_attributes.equation_dependency_parser.eval_flags_residual_postprocess[i]; + varInfo.residual_flags = pp_variable.eval_flags_residual_postprocess; - varInfo.global_var_index = i; + varInfo.global_var_index = pp_index; - varInfo.is_scalar = pp_var_type[i] == SCALAR; + varInfo.is_scalar = pp_variable.var_type == SCALAR; pp_varInfoList.push_back(varInfo); } diff --git a/src/userInputParameters/userInputParameters.cc b/src/userInputParameters/userInputParameters.cc index ce2e62bbf..0d9656927 100644 --- a/src/userInputParameters/userInputParameters.cc +++ b/src/userInputParameters/userInputParameters.cc @@ -62,19 +62,19 @@ userInputParameters::userInputParameters(inputFileReader &input_fi } // The adaptivity criterion for each variable has its own subsection - for (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { std::string subsection_text = "Refinement criterion: "; - subsection_text.append(input_file_reader.var_names.at(i)); + subsection_text.append(variable.name); parameter_handler.enter_subsection(subsection_text); { std::string crit_type_string = parameter_handler.get("Criterion type"); - if (crit_type_string.size() > 0) + if (!crit_type_string.empty()) { RefinementCriterion new_criterion; - new_criterion.variable_index = i; - new_criterion.variable_name = input_file_reader.var_names.at(i); + new_criterion.variable_index = index; + new_criterion.variable_name = variable.name; if (boost::iequals(crit_type_string, "VALUE")) { new_criterion.criterion_type = criterion_value; @@ -145,13 +145,13 @@ userInputParameters::userInputParameters(inputFileReader &input_fi finalTime = parameter_handler.get_double("Simulation end time"); // Linear solver parameters - for (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (input_file_reader.var_eq_types.at(i) == TIME_INDEPENDENT || - input_file_reader.var_eq_types.at(i) == IMPLICIT_TIME_DEPENDENT) + if (variable.eq_type == TIME_INDEPENDENT || + variable.eq_type == IMPLICIT_TIME_DEPENDENT) { std::string subsection_text = "Linear solver parameters: "; - subsection_text.append(input_file_reader.var_names.at(i)); + subsection_text.append(variable.name); parameter_handler.enter_subsection(subsection_text); { @@ -193,7 +193,7 @@ userInputParameters::userInputParameters(inputFileReader &input_fi unsigned int temp_max_iterations = parameter_handler.get_integer("Maximum linear solver iterations"); - linear_solver_parameters.loadParameters(i, + linear_solver_parameters.loadParameters(index, temp_type, temp_value, temp_max_iterations); @@ -203,17 +203,15 @@ userInputParameters::userInputParameters(inputFileReader &input_fi } // Non-linear solver parameters - std::vector var_nonlinear = variable_attributes.var_nonlinear; - nonlinear_solver_parameters.setMaxIterations( parameter_handler.get_integer("Maximum nonlinear solver iterations")); - for (unsigned int i = 0; i < var_nonlinear.size(); i++) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (var_nonlinear.at(i)) + if (variable.is_nonlinear) { std::string subsection_text = "Nonlinear solver parameters: "; - subsection_text.append(input_file_reader.var_names.at(i)); + subsection_text.append(variable.name); parameter_handler.enter_subsection(subsection_text); { @@ -267,7 +265,7 @@ userInputParameters::userInputParameters(inputFileReader &input_fi // the IC in ICs_and_BCs.h as the initial guess for nonlinear, time // independent equations bool temp_laplace_for_initial_guess; - if (var_eq_type[i] == TIME_INDEPENDENT) + if (variable.eq_type == TIME_INDEPENDENT) { temp_laplace_for_initial_guess = parameter_handler.get_bool( "Use Laplace's equation to determine the initial guess"); @@ -280,14 +278,14 @@ userInputParameters::userInputParameters(inputFileReader &input_fi std::cout << "PRISMS-PF Warning: Laplace's equation is only used " "to generate the initial guess for time independent " "equations. The equation for variable " - << var_name[i] + << variable.name << " is not a time independent equation. No initial " "guess is needed for this equation." << std::endl; } } - nonlinear_solver_parameters.loadParameters(i, + nonlinear_solver_parameters.loadParameters(index, temp_type, temp_value, temp_backtrack_damping, @@ -301,7 +299,12 @@ userInputParameters::userInputParameters(inputFileReader &input_fi } // Set the max number of nonlinear iterations - if (var_nonlinear.size() == 0) + bool any_nonlinear = false; + for (const auto &[index, variable] : variable_attributes.attributes) + { + any_nonlinear |= variable.is_nonlinear; + } + if (!any_nonlinear) { nonlinear_solver_parameters.setMaxIterations(0); } @@ -346,9 +349,10 @@ userInputParameters::userInputParameters(inputFileReader &input_fi // 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 &var_type : var_eq_type) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (var_type == EXPLICIT_TIME_DEPENDENT || var_type == IMPLICIT_TIME_DEPENDENT) + if (variable.eq_type == EXPLICIT_TIME_DEPENDENT || + variable.eq_type == IMPLICIT_TIME_DEPENDENT) { only_time_independent_pdes = false; break; @@ -464,16 +468,16 @@ userInputParameters::userInputParameters(inputFileReader &input_fi // Parameters for nucleation - for (unsigned int i = 0; i < input_file_reader.var_types.size(); i++) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (input_file_reader.var_nucleates.at(i)) + if (variable.nucleating_variable) { std::string nucleation_text = "Nucleation parameters: "; - nucleation_text.append(input_file_reader.var_names.at(i)); + nucleation_text.append(variable.name); parameter_handler.enter_subsection(nucleation_text); { - unsigned int var_index = i; + unsigned int var_index = index; std::vector semiaxes = dealii::Utilities::string_to_double(dealii::Utilities::split_string_list( parameter_handler.get("Nucleus semiaxes (x, y, z)"))); @@ -578,12 +582,11 @@ userInputParameters::userInputParameters(inputFileReader &input_fi for (const auto &field : variables_for_remapping_str) { bool field_found = false; - for (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (boost::iequals(field, variable_attributes.var_name_list[i].second)) + if (boost::iequals(field, variable.name)) { - variables_for_remapping.push_back( - variable_attributes.var_name_list[i].first); + variables_for_remapping.push_back(index); field_found = true; break; } @@ -613,30 +616,30 @@ userInputParameters::userInputParameters(inputFileReader &input_fi // 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 (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { - if (var_type[i] == SCALAR) + if (variable.var_type == SCALAR) { std::string bc_text = "Boundary condition for variable "; - bc_text.append(var_name.at(i)); + bc_text.append(variable.name); list_of_BCs.push_back(parameter_handler.get(bc_text)); } else { std::string bc_text = "Boundary condition for variable "; - bc_text.append(var_name.at(i)); + bc_text.append(variable.name); bc_text.append(", x component"); list_of_BCs.push_back(parameter_handler.get(bc_text)); bc_text = "Boundary condition for variable "; - bc_text.append(var_name.at(i)); + bc_text.append(variable.name); bc_text.append(", y component"); list_of_BCs.push_back(parameter_handler.get(bc_text)); if (dim > 2) { bc_text = "Boundary condition for variable "; - bc_text.append(var_name.at(i)); + bc_text.append(variable.name); bc_text.append(", z component"); list_of_BCs.push_back(parameter_handler.get(bc_text)); } @@ -646,10 +649,10 @@ userInputParameters::userInputParameters(inputFileReader &input_fi /*---------------------- | Pinning point -----------------------*/ - for (unsigned int i = 0; i < number_of_variables; i++) + for (const auto &[index, variable] : variable_attributes.attributes) { std::string pinning_text = "Pinning point: "; - pinning_text.append(input_file_reader.var_names.at(i)); + pinning_text.append(variable.name); parameter_handler.enter_subsection(pinning_text); // Skip if the default @@ -662,14 +665,14 @@ userInputParameters::userInputParameters(inputFileReader &input_fi // Otherwise, fill out point if (dim == 2) { - pinned_point[i] = dealii::Point(parameter_handler.get_double("x"), - parameter_handler.get_double("y")); + pinned_point[index] = dealii::Point(parameter_handler.get_double("x"), + parameter_handler.get_double("y")); } else { - pinned_point[i] = dealii::Point(parameter_handler.get_double("x"), - parameter_handler.get_double("y"), - parameter_handler.get_double("z")); + pinned_point[index] = dealii::Point(parameter_handler.get_double("x"), + parameter_handler.get_double("y"), + parameter_handler.get_double("z")); } parameter_handler.leave_subsection(); } diff --git a/src/utilities/sortIndexEntryPairList.cc b/src/utilities/sortIndexEntryPairList.cc deleted file mode 100644 index 3bf75d1ff..000000000 --- a/src/utilities/sortIndexEntryPairList.cc +++ /dev/null @@ -1,133 +0,0 @@ -#include "../../include/sortIndexEntryPairList.h" - -std::vector -sortIndexEntryPairList( - const std::vector> &unsorted_pair_list, - unsigned int number_of_variables, - bool default_value) -{ - std::vector sorted_vec; - unsigned int entry_index; - for (unsigned int i = 0; i < number_of_variables; i++) - { - bool entry_found = false; - for (unsigned int j = 0; j < unsorted_pair_list.size(); j++) - { - if (i == unsorted_pair_list.at(j).first) - { - entry_found = true; - entry_index = j; - break; - } - } - - if (entry_found) - { - sorted_vec.push_back(unsorted_pair_list.at(entry_index).second); - } - else - { - sorted_vec.push_back(default_value); - } - } - return sorted_vec; -} - -std::vector -sortIndexEntryPairList( - const std::vector> &unsorted_pair_list, - unsigned int number_of_variables, - const std::string &default_value) -{ - std::vector sorted_vec; - unsigned int entry_index; - for (unsigned int i = 0; i < number_of_variables; i++) - { - bool entry_found = false; - for (unsigned int j = 0; j < unsorted_pair_list.size(); j++) - { - if (i == unsorted_pair_list.at(j).first) - { - entry_found = true; - entry_index = j; - break; - } - } - - if (entry_found) - { - sorted_vec.push_back(unsorted_pair_list.at(entry_index).second); - } - else - { - sorted_vec.push_back(default_value); - } - } - return sorted_vec; -} - -std::vector -sortIndexEntryPairList( - const std::vector> &unsorted_pair_list, - unsigned int number_of_variables, - fieldType default_value) -{ - std::vector sorted_vec; - unsigned int entry_index; - for (unsigned int i = 0; i < number_of_variables; i++) - { - bool entry_found = false; - for (unsigned int j = 0; j < unsorted_pair_list.size(); j++) - { - if (i == unsorted_pair_list.at(j).first) - { - entry_found = true; - entry_index = j; - break; - } - } - - if (entry_found) - { - sorted_vec.push_back(unsorted_pair_list.at(entry_index).second); - } - else - { - sorted_vec.push_back(default_value); - } - } - return sorted_vec; -} - -std::vector -sortIndexEntryPairList( - const std::vector> &unsorted_pair_list, - unsigned int number_of_variables, - PDEType default_value) -{ - std::vector sorted_vec; - unsigned int entry_index; - for (unsigned int i = 0; i < number_of_variables; i++) - { - bool entry_found = false; - for (unsigned int j = 0; j < unsorted_pair_list.size(); j++) - { - if (i == unsorted_pair_list.at(j).first) - { - entry_found = true; - entry_index = j; - break; - } - } - - if (entry_found) - { - sorted_vec.push_back(unsorted_pair_list.at(entry_index).second); - } - else - { - sorted_vec.push_back(default_value); - } - } - return sorted_vec; -} diff --git a/src/variableAttributeLoader/variableAttributeLoader.cc b/src/variableAttributeLoader/variableAttributeLoader.cc index 1a15ab204..c4947b353 100644 --- a/src/variableAttributeLoader/variableAttributeLoader.cc +++ b/src/variableAttributeLoader/variableAttributeLoader.cc @@ -1,193 +1,275 @@ #include "../../include/variableAttributeLoader.h" -#include "../../include/sortIndexEntryPairList.h" +#include +#include -// Constructor variableAttributeLoader::variableAttributeLoader() { - setting_primary_field_attributes = true; - loadVariableAttributes(); // This is the user-facing function + relevant_attributes = &attributes; + loadVariableAttributes(); // This is a user-facing function + relevant_attributes = &pp_attributes; + loadPostProcessorVariableAttributes(); // This is a user-facing function + relevant_attributes = nullptr; - number_of_variables = var_name_list.size(); - - var_name = sortIndexEntryPairList(var_name_list, number_of_variables, "var"); - var_type = sortIndexEntryPairList(var_type_list, number_of_variables, SCALAR); - var_eq_type = sortIndexEntryPairList(var_eq_type_list, - number_of_variables, - EXPLICIT_TIME_DEPENDENT); - - std::vector sorted_dependencies_value_RHS = - sortIndexEntryPairList(var_eq_dependencies_value_RHS, number_of_variables, ""); - - std::vector sorted_dependencies_gradient_RHS = - sortIndexEntryPairList(var_eq_dependencies_gradient_RHS, number_of_variables, ""); - - std::vector sorted_dependencies_value_LHS = - sortIndexEntryPairList(var_eq_dependencies_value_LHS, number_of_variables, ""); - - std::vector sorted_dependencies_gradient_LHS = - sortIndexEntryPairList(var_eq_dependencies_gradient_LHS, number_of_variables, ""); - - nucleating_variable = - sortIndexEntryPairList(nucleating_variable_list, number_of_variables, false); - need_value_nucleation = - sortIndexEntryPairList(need_value_list_nucleation, number_of_variables, false); - - equation_dependency_parser.parse(var_name, - var_eq_type, - sorted_dependencies_value_RHS, - sorted_dependencies_gradient_RHS, - sorted_dependencies_value_LHS, - sorted_dependencies_gradient_LHS, - var_nonlinear); - - setting_primary_field_attributes = false; - loadPostProcessorVariableAttributes(); // This is the user-facing function - - pp_number_of_variables = var_name_list_PP.size(); - - pp_var_name = sortIndexEntryPairList(var_name_list_PP, pp_number_of_variables, "var"); - pp_var_type = sortIndexEntryPairList(var_type_list_PP, pp_number_of_variables, SCALAR); - - std::vector pp_sorted_dependencies_value = - sortIndexEntryPairList(var_eq_dependencies_value_PP, pp_number_of_variables, ""); - - std::vector pp_sorted_dependencies_gradient = - sortIndexEntryPairList(var_eq_dependencies_gradient_PP, pp_number_of_variables, ""); - - pp_calc_integral = - sortIndexEntryPairList(output_integral_list, pp_number_of_variables, false); - - equation_dependency_parser.pp_parse(var_name, - pp_var_name, - pp_sorted_dependencies_value, - pp_sorted_dependencies_gradient); -} - -// Methods to set the various variable attributes -void -variableAttributeLoader::set_variable_name(unsigned int index, std::string name) -{ - std::pair var_pair; - var_pair.first = index; - var_pair.second = std::move(name); + for (auto &[pp_index, pp_variable] : pp_attributes) + { + pp_variable.is_pp = true; + Assert(pp_variable.eq_type == EXPLICIT_TIME_DEPENDENT || + pp_variable.eq_type == UNDEFINED_PDE, + dealii::ExcMessage("PRISMS-PF Error: Warning: Postprocess variables can " + "only be explicit.\nProblem postprocessing index: " + + std::to_string(pp_index) + + ", Variable name: " + pp_variable.name + "\n")); + pp_variable.eq_type = EXPLICIT_TIME_DEPENDENT; + } - if (setting_primary_field_attributes) + for (auto &[index, variable] : attributes) { - var_name_list.push_back(var_pair); + variable.format_dependencies(); } - else + for (auto &[pp_index, pp_variable] : pp_attributes) { - var_name_list_PP.push_back(var_pair); + pp_variable.format_dependencies(); } -} - -void -variableAttributeLoader::set_variable_type(unsigned int index, fieldType var_type) -{ - std::pair var_pair; - var_pair.first = index; - var_pair.second = var_type; - - if (setting_primary_field_attributes) + validate_attributes(); + for (auto &[index, variable] : attributes) { - var_type_list.push_back(var_pair); + variable.parse_residual_dependencies(); + variable.parse_dependencies(attributes); + variable.parse_dependencies(pp_attributes); } - else + for (auto &[index, pp_variable] : pp_attributes) { - var_type_list_PP.push_back(var_pair); + pp_variable.parse_residual_dependencies(); } } +// Methods to set the various variable attributes void -variableAttributeLoader::set_variable_equation_type(unsigned int index, - PDEType var_eq_type) +variableAttributeLoader::set_variable_name(const unsigned int &index, + const std::string &name) { - std::pair var_pair; - var_pair.first = index; - var_pair.second = var_eq_type; - var_eq_type_list.push_back(var_pair); + (*relevant_attributes)[index].name = name; } void -variableAttributeLoader::set_need_value_nucleation(unsigned int index, bool flag) +variableAttributeLoader::set_variable_type(const unsigned int &index, + const fieldType &var_type) { - std::pair var_pair; - var_pair.first = index; - var_pair.second = flag; - need_value_list_nucleation.push_back(var_pair); + (*relevant_attributes)[index].var_type = var_type; } void -variableAttributeLoader::set_allowed_to_nucleate(unsigned int index, bool flag) +variableAttributeLoader::set_variable_equation_type(const unsigned int &index, + const PDEType &var_eq_type) { - std::pair var_pair; - var_pair.first = index; - var_pair.second = flag; - nucleating_variable_list.push_back(var_pair); + (*relevant_attributes)[index].eq_type = var_eq_type; } void -variableAttributeLoader::set_output_integral(unsigned int index, bool flag) +variableAttributeLoader::set_need_value_nucleation(const unsigned int &index, + const bool &flag) { - std::pair var_pair; - var_pair.first = index; - var_pair.second = flag; - output_integral_list.push_back(var_pair); + (*relevant_attributes)[index].need_value_nucleation = flag; } void -variableAttributeLoader::set_dependencies_value_term_RHS(unsigned int index, - std::string dependencies) +variableAttributeLoader::set_allowed_to_nucleate(const unsigned int &index, + const bool &flag) { - std::pair var_pair; - var_pair.first = index; - var_pair.second = std::move(dependencies); + (*relevant_attributes)[index].nucleating_variable = flag; +} - if (setting_primary_field_attributes) +void +variableAttributeLoader::set_output_integral(const unsigned int &index, const bool &flag) +{ + (*relevant_attributes)[index].output_integral = flag; + (*relevant_attributes)[index].calc_integral = flag; +} + +void +variableAttributeLoader::set_dependencies_value_term_RHS(const unsigned int &index, + const std::string &dependencies) +{ + std::vector dependencies_set = + dealii::Utilities::split_string_list(strip_whitespace(dependencies)); + /* (*relevant_attributes)[index].dependencies_value_RHS = + std::set(dependencies_set.begin(), dependencies_set.end()); */ + if (relevant_attributes != &pp_attributes) { - var_eq_dependencies_value_RHS.push_back(var_pair); + attributes[index].dependencies_value_RHS = + std::set(dependencies_set.begin(), dependencies_set.end()); } else { - var_eq_dependencies_value_PP.push_back(var_pair); + pp_attributes[index].dependencies_value_PP = + std::set(dependencies_set.begin(), dependencies_set.end()); } } void -variableAttributeLoader::set_dependencies_gradient_term_RHS(unsigned int index, - std::string dependencies) +variableAttributeLoader::set_dependencies_gradient_term_RHS( + const unsigned int &index, + const std::string &dependencies) { - std::pair var_pair; - var_pair.first = index; - var_pair.second = std::move(dependencies); - - if (setting_primary_field_attributes) + std::vector dependencies_set = + dealii::Utilities::split_string_list(strip_whitespace(dependencies)); + /* (*relevant_attributes)[index].dependencies_gradient_RHS = + std::set(dependencies_set.begin(), dependencies_set.end()); */ + if (relevant_attributes != &pp_attributes) { - var_eq_dependencies_gradient_RHS.push_back(var_pair); + attributes[index].dependencies_gradient_RHS = + std::set(dependencies_set.begin(), dependencies_set.end()); } else { - var_eq_dependencies_gradient_PP.push_back(var_pair); + pp_attributes[index].dependencies_gradient_PP = + std::set(dependencies_set.begin(), dependencies_set.end()); } } void -variableAttributeLoader::set_dependencies_value_term_LHS(unsigned int index, - std::string dependencies) +variableAttributeLoader::set_dependencies_value_term_LHS(const unsigned int &index, + const std::string &dependencies) { - std::pair var_pair; - var_pair.first = index; - var_pair.second = std::move(dependencies); - var_eq_dependencies_value_LHS.push_back(var_pair); + std::vector dependencies_set = + dealii::Utilities::split_string_list(strip_whitespace(dependencies)); + (*relevant_attributes)[index].dependencies_value_LHS = + std::set(dependencies_set.begin(), dependencies_set.end()); } void -variableAttributeLoader::set_dependencies_gradient_term_LHS(unsigned int index, - std::string dependencies) +variableAttributeLoader::set_dependencies_gradient_term_LHS( + const unsigned int &index, + const std::string &dependencies) { - std::pair var_pair; - var_pair.first = index; - var_pair.second = std::move(dependencies); - var_eq_dependencies_gradient_LHS.push_back(var_pair); + std::vector dependencies_set = + dealii::Utilities::split_string_list(strip_whitespace(dependencies)); + (*relevant_attributes)[index].dependencies_gradient_LHS = + std::set(dependencies_set.begin(), dependencies_set.end()); } + +void +variableAttributeLoader::validate_attributes() +{ + // Make sure main attributes arent set in pp_attributes + // Make sure dependencies are all variable names and if there are "change()" deps, they + // are correctly placed + const std::set> reg_delimiters = { + {"", "" }, + {"grad(", ")"}, + {"hess(", ")"} + }; + const std::set forbidden_names = {"grad(", "hess(", "change("}; + std::set name_list, pp_name_list, reg_possible_deps; + std::map> change_possible_deps; + // Populate name_list, pp_name_list, reg_possible_deps, change_possible_deps + // Check that variable names are mostly well-formed + for (const auto &[index, variable] : attributes) + { + name_list.insert(variable.name); + for (const auto &delims : reg_delimiters) + { + reg_possible_deps.insert(delims.first + variable.name + delims.second); + change_possible_deps[index].insert(delims.first + "change(" + variable.name + + ")" + delims.second); + } + Assert(!variable.name.empty(), + dealii::ExcMessage( + "PRISMS-PF Error: Variable names must not be empty.\nProblem index: " + + std::to_string(index) + "\n")); + for ([[maybe_unused]] const std::string &forbidden_name : forbidden_names) + { + Assert(variable.name.find(forbidden_name) == std::string::npos, + dealii::ExcMessage( + "PRISMS-PF Error: Variable names must not contain \"grad()\", " + "\"hess()\", \"change()\".\nProblem index: " + + std::to_string(index) + ", Variable name: " + variable.name + "\n")); + } + } + for (const auto &[pp_index, pp_variable] : pp_attributes) + { + pp_name_list.insert(pp_variable.name); + Assert(!pp_variable.name.empty(), + dealii::ExcMessage( + "PRISMS-PF Error: (postprocess) Variable names must not be " + "empty.\nProblem index: " + + std::to_string(pp_index) + "\n")); + for ([[maybe_unused]] const std::string &forbidden_name : forbidden_names) + { + Assert(pp_variable.name.find(forbidden_name) == std::string::npos, + dealii::ExcMessage("PRISMS-PF Error: (postprocess) Variable names must " + "not contain \"grad()\", " + "\"hess()\", \"change()\".\nProblem index: " + + std::to_string(pp_index) + + ", Variable name: " + pp_variable.name + "\n")); + } + } + // Check Dependencies & PP + for (const auto &[index, variable] : attributes) + { + for ([[maybe_unused]] const std::string &RHS_dep : variable.dependencies_RHS) + { + Assert( + reg_possible_deps.find(RHS_dep) != reg_possible_deps.end() || + change_possible_deps.at(index).find(RHS_dep) != + change_possible_deps.at(index).end(), + dealii::ExcMessage( + "PRISMS-PF Error: Invalid RHS dependency.\nProblem index: " + + std::to_string(index) + ", Variable name: " + variable.name + + ", Invalid dependency name: " + RHS_dep + + "\n(HINT: Dependencies that contain \"change(variable_A)\" can only be " + "used for the " + "field \"variable_A\")\n")); + } + for ([[maybe_unused]] const std::string &LHS_dep : variable.dependencies_LHS) + { + Assert( + reg_possible_deps.find(LHS_dep) != reg_possible_deps.end() || + change_possible_deps.at(index).find(LHS_dep) != + change_possible_deps.at(index).end(), + dealii::ExcMessage( + "PRISMS-PF Error: Invalid LHS dependency.\nProblem index: " + + std::to_string(index) + ", Variable name: " + variable.name + + ", Invalid dependency name: " + LHS_dep + + "\n(HINT: Dependencies that contain \"change(variable_A)\" can only be " + "used for the " + "field \"variable_A\")\n")); + } + } + for (const auto &[pp_index, pp_variable] : pp_attributes) + { + Assert(name_list.find(pp_variable.name) == name_list.end(), + dealii::ExcMessage( + "PRISMS-PF Error: Postprocess variable names must be named differently " + "than solution variable names.\nProblem postprocessing index: " + + std::to_string(pp_index) + ", Variable name: " + pp_variable.name + "\n")); + for ([[maybe_unused]] const std::string &PP_dep : pp_variable.dependencies_PP) + { + Assert(reg_possible_deps.find(PP_dep) != reg_possible_deps.end(), + dealii::ExcMessage( + "PRISMS-PF Error: Invalid postprocessing RHS dependency.\nProblem " + "postprocessing index: " + + std::to_string(pp_index) + ", Variable name: " + pp_variable.name + + ", Invalid dependency name: " + PP_dep + "\n")); + } + Assert(pp_variable.dependencies_LHS.empty(), + dealii::ExcMessage( + "PRISMS-PF Error: Warning: Postprocess variables can only have RHS " + "dependencies.\nProblem postprocessing index: " + + std::to_string(pp_index) + ", Variable name: " + pp_variable.name + "\n")); + Assert(!pp_variable.nucleating_variable && !pp_variable.need_value_nucleation, + dealii::ExcMessage( + "PRISMS-PF Error: Warning: Postprocess variables cannot " + "be used for nucleation.\nProblem postprocessing index: " + + std::to_string(pp_index) + ", Variable name: " + pp_variable.name + "\n")); + } +} + +std::string +variableAttributeLoader::strip_whitespace(const std::string &_text) +{ + std::string text = _text; + text.erase(std::remove(text.begin(), text.end(), ' '), text.end()); + return text; +} \ No newline at end of file diff --git a/src/variableAttributes/variableAttributes.cc b/src/variableAttributes/variableAttributes.cc new file mode 100644 index 000000000..396856b6b --- /dev/null +++ b/src/variableAttributes/variableAttributes.cc @@ -0,0 +1,159 @@ +#include "../../include/variableAttributes.h" + +void +variableAttributes::format_dependencies() +{ + dependencies_RHS.insert(dependencies_value_RHS.begin(), dependencies_value_RHS.end()); + dependencies_RHS.insert(dependencies_gradient_RHS.begin(), + dependencies_gradient_RHS.end()); + + dependencies_LHS.insert(dependencies_value_LHS.begin(), dependencies_value_LHS.end()); + dependencies_LHS.insert(dependencies_gradient_LHS.begin(), + dependencies_gradient_LHS.end()); + + dependencies_PP.insert(dependencies_value_PP.begin(), dependencies_value_PP.end()); + dependencies_PP.insert(dependencies_gradient_PP.begin(), + dependencies_gradient_PP.end()); + + dependency_set.insert(dependencies_RHS.begin(), dependencies_RHS.end()); + dependency_set.insert(dependencies_LHS.begin(), dependencies_LHS.end()); + dependency_set.insert(dependencies_PP.begin(), dependencies_PP.end()); +} + +void +variableAttributes::parse_residual_dependencies() +{ // Check if either is empty and set value and gradient flags for the + // residual appropriately + const std::map< + PDEType, + std::set *, std::set *>>>> + dependencies_for = { + {EXPLICIT_TIME_DEPENDENT, + {{&eval_flags_residual_explicit_RHS, + {&dependencies_value_RHS, &dependencies_gradient_RHS}}}}, + {AUXILIARY, + {{&eval_flags_residual_nonexplicit_RHS, + {&dependencies_value_RHS, &dependencies_gradient_RHS}}}}, + {IMPLICIT_TIME_DEPENDENT, + {{&eval_flags_residual_nonexplicit_RHS, + {&dependencies_value_RHS, &dependencies_gradient_RHS}}, + {&eval_flags_residual_nonexplicit_LHS, + {&dependencies_value_LHS, &dependencies_gradient_LHS}}}}, + {TIME_INDEPENDENT, + {{&eval_flags_residual_nonexplicit_RHS, + {&dependencies_value_RHS, &dependencies_gradient_RHS}}, + {&eval_flags_residual_nonexplicit_LHS, + {&dependencies_value_LHS, &dependencies_gradient_LHS}}}} + }; + + if (is_pp) + { + EvalFlags &residual_flags = eval_flags_residual_postprocess; + std::set &value_dependency_set = dependencies_value_PP; + std::set &gradient_dependency_set = dependencies_gradient_PP; + + if (!value_dependency_set.empty()) + { + residual_flags |= dealii::EvaluationFlags::values; + } + if (!gradient_dependency_set.empty()) + { + residual_flags |= dealii::EvaluationFlags::gradients; + } + return; + } + + for (const std::pair *, std::set *>> + &eval_dep_pair : dependencies_for.at(eq_type)) + { + EvalFlags &residual_flags = *(eval_dep_pair.first); + auto &dep_pair = eval_dep_pair.second; + std::set &value_dependency_set = *(dep_pair.first); + std::set &gradient_dependency_set = *(dep_pair.second); + + if (!value_dependency_set.empty()) + { + residual_flags |= dealii::EvaluationFlags::values; + } + if (!gradient_dependency_set.empty()) + { + residual_flags |= dealii::EvaluationFlags::gradients; + } + } +} + +void +variableAttributes::parse_dependencies( + std::map &other_var_attributes) +{ + const std::map relevant_flag { + {"val", dealii::EvaluationFlags::values }, + {"grad", dealii::EvaluationFlags::gradients}, + {"hess", dealii::EvaluationFlags::hessians }, + {"val_change", dealii::EvaluationFlags::values }, + {"grad_change", dealii::EvaluationFlags::gradients}, + {"hess_change", dealii::EvaluationFlags::hessians } + }; + const std::map> delimiters = { + {"val", {"", ""} }, + {"grad", {"grad(", ")"} }, + {"hess", {"hess(", ")"} }, + {"val_change", {"change(", ")"} }, + {"grad_change", {"grad(change(", "))"}}, + {"hess_change", {"hess(change(", "))"}} + }; + + for (const auto &[variation, delimiter] : delimiters) + { + bool is_change = variation == "val_change" || variation == "grad_change" || + variation == "hess_change"; + std::string possible_dependency = delimiter.first + name + delimiter.second; + if (is_change && dependency_set.find(possible_dependency) != dependency_set.end()) + { + eval_flags_change_nonexplicit_LHS |= relevant_flag.at(variation); + } + else + { + for (auto &[other_index, other_variable] : other_var_attributes) + { + if (other_variable.dependency_set.find(possible_dependency) != + other_variable.dependency_set.end()) + { + for (auto &eval_flag : eval_flags_for_eq_type(other_variable)) + { + *eval_flag |= relevant_flag.at(variation); + } + other_variable.is_nonlinear |= + (eq_type != EXPLICIT_TIME_DEPENDENT) && + (other_variable.eq_type != EXPLICIT_TIME_DEPENDENT) && + (&other_variable != this); + } + } + } + } +} + +std::set +variableAttributes::eval_flags_for_eq_type(const variableAttributes &other_variable) +{ + PDEType other_eq_type = other_variable.eq_type; + if (other_variable.is_pp) + { + return {&eval_flags_postprocess}; + } + if (other_eq_type == EXPLICIT_TIME_DEPENDENT) + { + return {&eval_flags_explicit_RHS}; + } + if (other_eq_type == AUXILIARY) + { + return {&eval_flags_nonexplicit_RHS}; + } + if (other_eq_type == IMPLICIT_TIME_DEPENDENT || other_eq_type == TIME_INDEPENDENT) + { + return {&eval_flags_nonexplicit_RHS, &eval_flags_nonexplicit_LHS}; + } + return {}; +} diff --git a/tests/unit_tests/main.cc b/tests/unit_tests/main.cc index c4f0546df..6c9c2d0a9 100644 --- a/tests/unit_tests/main.cc +++ b/tests/unit_tests/main.cc @@ -9,6 +9,7 @@ #include "../../include/vectorBCFunction.h" #include "../../src/userInputParameters/userInputParameters.cc" #include "../../src/utilities/vectorBCFunction.cc" +#include "../../src/variableAttributes/variableAttributes.cc" #include int @@ -117,28 +118,6 @@ main(int argc, char **argv) pass = NonlinearSolverParameters_tester.test_NonlinearSolverParameters(); tests_passed += pass; - // Unit tests for the "parseDependences" method in the "UserInputParameters" - // class - total_tests++; - unitTest<2, double> EquationDependencyParser_tester1; - pass = EquationDependencyParser_tester1 - .test_EquationDependencyParser_variables_and_residuals_needed(); - tests_passed += pass; - - // Unit tests for the "parseDependences" method in the "UserInputParameters" - // class - total_tests++; - unitTest<2, double> EquationDependencyParser_tester2; - pass = EquationDependencyParser_tester2.test_EquationDependencyParser_nonlinear(); - tests_passed += pass; - - // Unit tests for the "parseDependences" method in the "UserInputParameters" - // class - total_tests++; - unitTest<2, double> EquationDependencyParser_tester3; - pass = EquationDependencyParser_tester3.test_EquationDependencyParser_postprocessing(); - tests_passed += pass; - // Unit tests for the FloodFiller class total_tests++; unitTest<2, double> FloodFiller_tester; diff --git a/tests/unit_tests/test_EquationDependencyParser.h b/tests/unit_tests/test_EquationDependencyParser.h deleted file mode 100644 index 3cce2fdfb..000000000 --- a/tests/unit_tests/test_EquationDependencyParser.h +++ /dev/null @@ -1,672 +0,0 @@ -template -bool -unitTest::test_EquationDependencyParser_variables_and_residuals_needed() -{ - char buffer[100]; - - std::cout << "\nTesting 'EquationDependencyParser'... " << std::endl; - bool pass = true; - - // Declare all of the variables that go into the function call - std::vector sorted_dependencies_value_RHS, - sorted_dependencies_gradient_RHS, sorted_dependencies_value_LHS, - sorted_dependencies_gradient_LHS; - - // Populate the variable names and equation types - std::vector var_name; - var_name.push_back("a"); - var_name.push_back("bc"); - - std::vector var_eq_type; - var_eq_type.push_back(EXPLICIT_TIME_DEPENDENT); - var_eq_type.push_back(TIME_INDEPENDENT); - - // Populate the dependency strings - sorted_dependencies_value_RHS.push_back("a, grad(a), bc"); - sorted_dependencies_value_RHS.push_back("hess(a),grad(bc)"); - - sorted_dependencies_gradient_RHS.push_back("grad(bc), bc"); - sorted_dependencies_gradient_RHS.push_back("a,grad(bc)"); - - sorted_dependencies_value_LHS.push_back(""); - sorted_dependencies_value_LHS.push_back("change(bc),grad(bc),grad(change(bc))"); - - sorted_dependencies_gradient_LHS.push_back(""); - sorted_dependencies_gradient_LHS.push_back("bc"); - - std::vector var_nonlinear; - - EquationDependencyParser equation_dependency_parser; - - equation_dependency_parser.parse(var_name, - var_eq_type, - sorted_dependencies_value_RHS, - sorted_dependencies_gradient_RHS, - sorted_dependencies_value_LHS, - sorted_dependencies_gradient_LHS, - var_nonlinear); - - // Check that the boolean vectors were generated correctly - bool result; - unsigned int subtest_index = 0; - - // Check need_value_explicit_RHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_explicit_RHS.size() == 2) - { - if (equation_dependency_parser.eval_flags_explicit_RHS[0] & - dealii::EvaluationFlags::values && - equation_dependency_parser.eval_flags_explicit_RHS[1] & - dealii::EvaluationFlags::values) - { - result = true; - } - } - std::cout << "Subtest " << subtest_index - << " result for 'need_value_explicit_RHS': " << result << std::endl; - pass = pass && result; - - // Check need_gradient_explicit_RHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_explicit_RHS.size() == 2) - { - if (equation_dependency_parser.eval_flags_explicit_RHS[0] & - dealii::EvaluationFlags::gradients && - equation_dependency_parser.eval_flags_explicit_RHS[1] & - dealii::EvaluationFlags::gradients) - { - result = true; - } - } - - std::cout << "Subtest " << subtest_index - << " result for 'need_gradient_explicit_RHS': " << result << std::endl; - pass = pass && result; - - // Check need_hessian_explicit_RHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_explicit_RHS.size() == 2) - { - if (!(equation_dependency_parser.eval_flags_explicit_RHS[0] & - dealii::EvaluationFlags::hessians) && - !(equation_dependency_parser.eval_flags_explicit_RHS[1] & - dealii::EvaluationFlags::hessians)) - { - result = true; - } - } - - std::cout << "Subtest " << subtest_index - << " result for 'need_hessian_explicit_RHS': " << result << std::endl; - pass = pass && result; - - // Check need_value_nonexplicit_RHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_nonexplicit_RHS.size() == 2) - { - if (equation_dependency_parser.eval_flags_nonexplicit_RHS[0] & - dealii::EvaluationFlags::values && - !(equation_dependency_parser.eval_flags_nonexplicit_RHS[1] & - dealii::EvaluationFlags::values)) - { - result = true; - } - } - - std::cout << "Subtest " << subtest_index - << " result for 'need_value_nonexplicit_RHS': " << result << std::endl; - pass = pass && result; - - // Check need_gradient_nonexplicit_RHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_nonexplicit_RHS.size() == 2) - { - if (!(equation_dependency_parser.eval_flags_nonexplicit_RHS[0] & - dealii::EvaluationFlags::gradients) && - equation_dependency_parser.eval_flags_nonexplicit_RHS[1] & - dealii::EvaluationFlags::gradients) - { - result = true; - } - } - - std::cout << "Subtest " << subtest_index - << " result for 'need_gradient_nonexplicit_RHS': " << result << std::endl; - pass = pass && result; - - // Check need_hessian_nonexplicit_RHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_nonexplicit_RHS.size() == 2) - { - if (equation_dependency_parser.eval_flags_nonexplicit_RHS[0] & - dealii::EvaluationFlags::hessians && - !(equation_dependency_parser.eval_flags_nonexplicit_RHS[1] & - dealii::EvaluationFlags::hessians)) - { - result = true; - } - } - - std::cout << "Subtest " << subtest_index - << " result for 'need_hessian_nonexplicit_RHS': " << result << std::endl; - pass = pass && result; - - // Check need_value_nonexplicit_LHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_nonexplicit_LHS.size() == 2) - { - if (!(equation_dependency_parser.eval_flags_nonexplicit_LHS[0] & - dealii::EvaluationFlags::values) && - equation_dependency_parser.eval_flags_nonexplicit_LHS[1] & - dealii::EvaluationFlags::values) - { - result = true; - } - } - - std::cout << "Subtest " << subtest_index - << " result for 'need_value_nonexplicit_LHS': " << result << std::endl; - pass = pass && result; - - // Check need_gradient_nonexplicit_LHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_nonexplicit_LHS.size() == 2) - { - if (!(equation_dependency_parser.eval_flags_nonexplicit_LHS[0] & - dealii::EvaluationFlags::gradients) && - equation_dependency_parser.eval_flags_nonexplicit_LHS[1] & - dealii::EvaluationFlags::gradients) - { - result = true; - } - } - - std::cout << "Subtest " << subtest_index - << " result for 'need_gradient_nonexplicit_LHS': " << result << std::endl; - pass = pass && result; - - // Check need_hessian_nonexplicit_LHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_nonexplicit_LHS.size() == 2) - { - if (!(equation_dependency_parser.eval_flags_nonexplicit_LHS[0] & - dealii::EvaluationFlags::hessians) && - !(equation_dependency_parser.eval_flags_nonexplicit_LHS[1] & - dealii::EvaluationFlags::hessians)) - { - result = true; - } - } - - std::cout << "Subtest " << subtest_index - << " result for 'need_hessian_nonexplicit_LHS': " << result << std::endl; - pass = pass && result; - - // Check need_value_change_nonexplicit_LHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_change_nonexplicit_LHS.size() == 2) - { - if (!(equation_dependency_parser.eval_flags_change_nonexplicit_LHS[0] & - dealii::EvaluationFlags::values) && - equation_dependency_parser.eval_flags_change_nonexplicit_LHS[1] & - dealii::EvaluationFlags::values) - { - result = true; - } - } - - std::cout << "Subtest " << subtest_index - << " result for 'need_value_change_nonexplicit_LHS': " << result << std::endl; - pass = pass && result; - - // Check need_gradient_change_nonexplicit_LHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_change_nonexplicit_LHS.size() == 2) - { - if (!(equation_dependency_parser.eval_flags_change_nonexplicit_LHS[0] & - dealii::EvaluationFlags::gradients) && - equation_dependency_parser.eval_flags_change_nonexplicit_LHS[1] & - dealii::EvaluationFlags::gradients) - { - result = true; - } - } - - std::cout << "Subtest " << subtest_index - << " result for 'need_gradient_change_nonexplicit_LHS': " << result - << std::endl; - pass = pass && result; - - // Check need_hessian_nonexplicit_LHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_change_nonexplicit_LHS.size() == 2) - { - if (!(equation_dependency_parser.eval_flags_change_nonexplicit_LHS[0] & - dealii::EvaluationFlags::hessians) && - !(equation_dependency_parser.eval_flags_change_nonexplicit_LHS[1] & - dealii::EvaluationFlags::hessians)) - { - result = true; - } - } - std::cout << "Subtest " << subtest_index - << " result for 'need_hessian_change_nonexplicit_LHS': " << result - << std::endl; - pass = pass && result; - - // Check need_value_residual_explicit_RHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_residual_explicit_RHS.size() == 2) - { - if (equation_dependency_parser.eval_flags_residual_explicit_RHS[0] & - dealii::EvaluationFlags::values && - !(equation_dependency_parser.eval_flags_residual_explicit_RHS[1] & - dealii::EvaluationFlags::values)) - { - result = true; - } - } - std::cout << "Subtest " << subtest_index - << " result for 'need_value_residual_explicit_RHS': " << result << std::endl; - pass = pass && result; - - // Check need_gradient_residual_explicit_RHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_residual_explicit_RHS.size() == 2) - { - if (equation_dependency_parser.eval_flags_residual_explicit_RHS[0] & - dealii::EvaluationFlags::gradients && - !(equation_dependency_parser.eval_flags_residual_explicit_RHS[1] & - dealii::EvaluationFlags::gradients)) - { - result = true; - } - } - std::cout << "Subtest " << subtest_index - << " result for 'need_gradient_residual_explicit_RHS': " << result - << std::endl; - pass = pass && result; - - // Check need_value_residual_nonexplicit_RHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_residual_nonexplicit_RHS.size() == 2) - { - if (!(equation_dependency_parser.eval_flags_residual_nonexplicit_RHS[0] & - dealii::EvaluationFlags::values) && - equation_dependency_parser.eval_flags_residual_nonexplicit_RHS[1] & - dealii::EvaluationFlags::values) - { - result = true; - } - } - std::cout << "Subtest " << subtest_index - << " result for 'need_value_residual_nonexplicit_RHS': " << result - << std::endl; - pass = pass && result; - - // Check need_gradient_residual_nonexplicit_RHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_residual_nonexplicit_RHS.size() == 2) - { - if (!(equation_dependency_parser.eval_flags_residual_nonexplicit_RHS[0] & - dealii::EvaluationFlags::gradients) && - equation_dependency_parser.eval_flags_residual_nonexplicit_RHS[1] & - dealii::EvaluationFlags::gradients) - { - result = true; - } - } - std::cout << "Subtest " << subtest_index - << " result for 'need_gradient_residual_nonexplicit_RHS': " << result - << std::endl; - pass = pass && result; - - // Check need_value_residual_nonexplicit_LHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_residual_nonexplicit_LHS.size() == 2) - { - if (!(equation_dependency_parser.eval_flags_residual_nonexplicit_LHS[0] & - dealii::EvaluationFlags::values) && - equation_dependency_parser.eval_flags_residual_nonexplicit_LHS[1] & - dealii::EvaluationFlags::values) - { - result = true; - } - } - std::cout << "Subtest " << subtest_index - << " result for 'need_value_residual_nonexplicit_LHS': " << result - << std::endl; - pass = pass && result; - - // Check need_gradient_residual_nonexplicit_LHS - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_residual_nonexplicit_LHS.size() == 2) - { - if (!(equation_dependency_parser.eval_flags_residual_nonexplicit_LHS[0] & - dealii::EvaluationFlags::gradients) && - equation_dependency_parser.eval_flags_residual_nonexplicit_LHS[1] & - dealii::EvaluationFlags::gradients) - { - result = true; - } - } - std::cout << "Subtest " << subtest_index - << " result for 'need_gradient_residual_nonexplicit_LHS': " << result - << std::endl; - pass = pass && result; - - snprintf(buffer, - sizeof(buffer), - "Test result for 'EquationDependencyParser': %u\n", - pass); - std::cout << buffer; - - return pass; -} - -template -bool -unitTest::test_EquationDependencyParser_nonlinear() -{ - char buffer[100]; - - std::cout << "\nTesting 'EquationDependencyParser'... " << std::endl; - bool pass = true; - - // Declare all of the variables that go into the function call - std::vector sorted_dependencies_value_RHS, - sorted_dependencies_gradient_RHS, sorted_dependencies_value_LHS, - sorted_dependencies_gradient_LHS; - - // Populate the variable names and equation types - std::vector var_name; - var_name.push_back("a"); - var_name.push_back("bc"); - var_name.push_back("def"); - var_name.push_back("ghij"); - var_name.push_back("klmno"); - - std::vector var_eq_type; - var_eq_type.push_back(EXPLICIT_TIME_DEPENDENT); // Not nonlinear by definition - var_eq_type.push_back(TIME_INDEPENDENT); // Crafted to be nonlinear due to RHS - var_eq_type.push_back( - TIME_INDEPENDENT); // Crafted to be nonlinear due to LHS (due to needed - // non-change version of governing variable) - var_eq_type.push_back(TIME_INDEPENDENT); // Crafted to be nonlinear due to LHS (due to - // needing a non-governing variable) - var_eq_type.push_back(TIME_INDEPENDENT); // Crafted to be linear - - // Populate the dependency strings - sorted_dependencies_value_RHS.push_back("bc, def, grad(bc)"); - sorted_dependencies_value_RHS.push_back("bc, def"); - sorted_dependencies_value_RHS.push_back("def"); - sorted_dependencies_value_RHS.push_back("a, ghij"); - sorted_dependencies_value_RHS.push_back("a, klmno"); - - sorted_dependencies_gradient_RHS.push_back("hess(def), ghij"); - sorted_dependencies_gradient_RHS.push_back("grad(bc)"); - sorted_dependencies_gradient_RHS.push_back(""); - sorted_dependencies_gradient_RHS.push_back("grad(ghij)"); - sorted_dependencies_gradient_RHS.push_back("grad(klmno)"); - - sorted_dependencies_value_LHS.push_back(""); - sorted_dependencies_value_LHS.push_back("change(bc)"); - sorted_dependencies_value_LHS.push_back("change(def)"); - sorted_dependencies_value_LHS.push_back("change(ghij), grad(def)"); - sorted_dependencies_value_LHS.push_back("change(klmno), grad(a)"); - - sorted_dependencies_gradient_LHS.push_back(""); - sorted_dependencies_gradient_LHS.push_back(""); - sorted_dependencies_gradient_LHS.push_back("grad(def)"); - sorted_dependencies_gradient_LHS.push_back(""); - sorted_dependencies_gradient_LHS.push_back("hess(change(klmno))"); - - std::vector var_nonlinear; - - EquationDependencyParser equation_dependency_parser; - - equation_dependency_parser.parse(var_name, - var_eq_type, - sorted_dependencies_value_RHS, - sorted_dependencies_gradient_RHS, - sorted_dependencies_value_LHS, - sorted_dependencies_gradient_LHS, - var_nonlinear); - - // Check that the boolean vectors were generated correctly - bool result; - unsigned int subtest_index = 0; - - // Check explicit parabolic equation - subtest_index++; - result = false; - if (var_nonlinear[0] == false) - { - result = true; - } - std::cout << "Subtest " << subtest_index - << " result for an explicit parabolic equation: " << result << std::endl; - pass = pass && result; - - // Check nonlinear time independent equation w/ nonlinearity due result for - // nonlinearity due to needing a non-governing variable on the RHS - subtest_index++; - result = false; - if (var_nonlinear[1] == true) - { - result = true; - } - std::cout << "Subtest " << subtest_index - << " result for nonlinearity due to needing a non-governing " - "variable on the RHS: " - << result << std::endl; - pass = pass && result; - - // Check nonlinear time independent equation w/ nonlinearity due to needed - // non-change version of governing variable on the LHS - subtest_index++; - result = false; - if (var_nonlinear[2] == true) - { - result = true; - } - std::cout << "Subtest " << subtest_index - << " result for nonlinearity due to needed non-change version of " - "governing variable on the LHS: " - << result << std::endl; - pass = pass && result; - - // Check nonlinear time independent equation w/ nonlinearity due to needing a - // non-governing variable on the LHS - subtest_index++; - result = false; - if (var_nonlinear[3] == true) - { - result = true; - } - std::cout << "Subtest " << subtest_index - << " result for nonlinearity due to needing a non-governing " - "variable on the LHS: " - << result << std::endl; - pass = pass && result; - - // Check linear time independent equation - subtest_index++; - result = false; - if (var_nonlinear[4] == false) - { - result = true; - } - std::cout << "Subtest " << subtest_index - << " result for linear time independent: " << result << std::endl; - pass = pass && result; - - snprintf(buffer, - sizeof(buffer), - "Test result for 'EquationDependencyParser': %u\n", - pass); - std::cout << buffer; - - return pass; -} - -template -bool -unitTest::test_EquationDependencyParser_postprocessing() -{ - char buffer[100]; - - std::cout << "\nTesting 'EquationDependencyParser'... " << std::endl; - bool pass = true; - - // Declare all of the variables that go into the function call - std::vector sorted_dependencies_value, sorted_dependencies_gradient; - - // Populate the variable names and equation types - std::vector var_name; - var_name.push_back("a"); - var_name.push_back("bc"); - - std::vector pp_var_name; - pp_var_name.push_back("pp1"); - pp_var_name.push_back("pp2"); - pp_var_name.push_back("pp3"); - - // Populate the dependency strings - sorted_dependencies_value.push_back("bc, a, grad(bc)"); - sorted_dependencies_value.push_back(""); - sorted_dependencies_value.push_back("a"); - - sorted_dependencies_gradient.push_back("hess(a), bc"); - sorted_dependencies_gradient.push_back("grad(bc)"); - sorted_dependencies_gradient.push_back("a"); - - EquationDependencyParser equation_dependency_parser; - - equation_dependency_parser.pp_parse(var_name, - pp_var_name, - sorted_dependencies_value, - sorted_dependencies_gradient); - - // Check that the boolean vectors were generated correctly - bool result; - unsigned int subtest_index = 0; - - // Check pp_need_value - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_postprocess.size() == 2) - { - if (equation_dependency_parser.eval_flags_postprocess[0] & - dealii::EvaluationFlags::values && - equation_dependency_parser.eval_flags_postprocess[1] & - dealii::EvaluationFlags::values) - { - result = true; - } - } - std::cout << "Subtest " << subtest_index << " result for 'pp_need_value': " << result - << std::endl; - pass = pass && result; - - // Check pp_need_gradient - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_postprocess.size() == 2) - { - if (!(equation_dependency_parser.eval_flags_postprocess[0] & - dealii::EvaluationFlags::gradients) && - equation_dependency_parser.eval_flags_postprocess[1] & - dealii::EvaluationFlags::gradients) - { - result = true; - } - } - - std::cout << "Subtest " << subtest_index << " result for 'pp_need_gradient': " << result - << std::endl; - pass = pass && result; - - // Check pp_need_hessian - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_postprocess.size() == 2) - { - if (equation_dependency_parser.eval_flags_postprocess[0] & - dealii::EvaluationFlags::hessians && - !(equation_dependency_parser.eval_flags_postprocess[1] & - dealii::EvaluationFlags::hessians)) - { - result = true; - } - } - - std::cout << "Subtest " << subtest_index << " result for 'pp_need_hessian': " << result - << std::endl; - pass = pass && result; - - // Check pp_need_value_residual - subtest_index++; - result = false; - if (equation_dependency_parser.eval_flags_residual_postprocess.size() == 3) - { - if (equation_dependency_parser.eval_flags_residual_postprocess[0] & - dealii::EvaluationFlags::values && - !(equation_dependency_parser.eval_flags_residual_postprocess[1] & - dealii::EvaluationFlags::values) && - equation_dependency_parser.eval_flags_residual_postprocess[2] & - dealii::EvaluationFlags::values) - { - result = true; - } - } - std::cout << "Subtest " << subtest_index - << " result for 'pp_need_value_residual': " << result << std::endl; - pass = pass && result; - - // Check pp_need_gradient_residual - subtest_index++; - result = false; - - if (equation_dependency_parser.eval_flags_residual_postprocess.size() == 3) - { - if (equation_dependency_parser.eval_flags_residual_postprocess[0] & - dealii::EvaluationFlags::gradients && - equation_dependency_parser.eval_flags_residual_postprocess[1] & - dealii::EvaluationFlags::gradients && - equation_dependency_parser.eval_flags_residual_postprocess[2] & - dealii::EvaluationFlags::gradients) - { - result = true; - } - } - std::cout << "Subtest " << subtest_index - << " result for 'pp_need_gradient_residual': " << result << std::endl; - pass = pass && result; - - snprintf(buffer, - sizeof(buffer), - "Test result for 'EquationDependencyParser': %u\n", - pass); - std::cout << buffer; - - return pass; -} diff --git a/tests/unit_tests/test_setOutputTimeSteps.h b/tests/unit_tests/test_setOutputTimeSteps.h index 6ce114fa1..5252defe0 100644 --- a/tests/unit_tests/test_setOutputTimeSteps.h +++ b/tests/unit_tests/test_setOutputTimeSteps.h @@ -13,17 +13,7 @@ unitTest::test_setOutputTimeSteps() dealii::ParameterHandler parameter_handler; variableAttributeLoader variable_attributes; inputFileReader input_file_reader("parameters_test.prm", variable_attributes); - std::vector var_types; - var_types.push_back(SCALAR); - std::vector var_eq_types; - var_eq_types.push_back(TIME_INDEPENDENT); - std::vector var_nucleates; - var_nucleates.push_back(false); - input_file_reader.declare_parameters(parameter_handler, - var_types, - var_eq_types, - 0, - var_nucleates); + input_file_reader.declare_parameters(parameter_handler, 0); #if (DEAL_II_VERSION_MAJOR < 9 && DEAL_II_VERSION_MINOR < 5) parameter_handler.read_input("parameters_test.prm"); #else @@ -34,9 +24,6 @@ unitTest::test_setOutputTimeSteps() // Subtest 1 (EQUAL_SPACING) parameter_handler.set("Output condition", "EQUAL_SPACING"); - input_file_reader.var_types = var_types; - input_file_reader.num_pp_vars = 0; - input_file_reader.num_constants = 0; // userInputs.loadInputParameters(input_file_reader,parameter_handler,var_types.size(),0,0,0); userInputParameters userInputs1(input_file_reader, diff --git a/tests/unit_tests/unitTest.h b/tests/unit_tests/unitTest.h index c11df5fdf..22963c43a 100644 --- a/tests/unit_tests/unitTest.h +++ b/tests/unit_tests/unitTest.h @@ -63,7 +63,6 @@ computeStress(const dealii::Table<2, double> &CIJ, #include "../../src/userInputParameters/load_BC_list.cc" #include "../../src/userInputParameters/load_user_constants.cc" #include "../../src/userInputParameters/setTimeStepList.cc" -#include "../../src/utilities/sortIndexEntryPairList.cc" #include "../../src/variableAttributeLoader/variableAttributeLoader.cc" #include "../../src/variableContainer/variableContainer.cc" @@ -116,7 +115,6 @@ class unitTest test_OrderParameterRemapper(); }; -#include "test_EquationDependencyParser.h" #include "test_FloodFiller.h" #include "test_LinearSolverParameters.h" #include "test_NonlinearSolverParameters.h" @@ -134,5 +132,4 @@ class unitTest #include "variableAttributeLoader_test.cc" #include "../../include/SolverParameters.h" -#include "../../src/EquationDependencyParser/EquationDependencyParser.cc" #include "../../src/SolverParameters/SolverParameters.cc" diff --git a/tests/unit_tests/unit_test_results.txt b/tests/unit_tests/unit_test_results.txt index 463ab3429..0121a8fa5 100644 --- a/tests/unit_tests/unit_test_results.txt +++ b/tests/unit_tests/unit_test_results.txt @@ -1,2 +1,2 @@ -22 -22 +19 +19