Skip to content

Commit

Permalink
reorganized variable attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalsbyx committed Dec 11, 2024
1 parent 992e172 commit 2fcd9bc
Show file tree
Hide file tree
Showing 23 changed files with 165 additions and 150 deletions.
8 changes: 4 additions & 4 deletions applications/allenCahn_conserved/customPDE.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ customPDE<dim, degree>::solveIncrement(bool skip_time_dependent)
this->fields[fieldIndex].pdetype == TIME_INDEPENDENT)
{
if (this->currentIncrement % userInputs.skip_print_steps == 0 &&
this->var_attributes.attributes.at(fieldIndex).is_nonlinear)
this->var_attributes.at(fieldIndex).is_nonlinear)
{
snprintf(buffer,
sizeof(buffer),
Expand All @@ -222,12 +222,12 @@ customPDE<dim, degree>::solveIncrement(bool skip_time_dependent)
}
else if (this->fields[fieldIndex].pdetype == AUXILIARY)
{
if (this->var_attributes.attributes.at(fieldIndex).is_nonlinear ||
if (this->var_attributes.at(fieldIndex).is_nonlinear ||
nonlinear_it_index == 0)
{
// If the equation for this field is nonlinear, save the
// old solution
if (this->var_attributes.attributes.at(fieldIndex).is_nonlinear)
if (this->var_attributes.at(fieldIndex).is_nonlinear)
{
if (this->fields[fieldIndex].type == SCALAR)
{
Expand Down Expand Up @@ -258,7 +258,7 @@ customPDE<dim, degree>::solveIncrement(bool skip_time_dependent)
}

// Check to see if this individual variable has converged
if (this->var_attributes.attributes.at(fieldIndex).is_nonlinear)
if (this->var_attributes.at(fieldIndex).is_nonlinear)
{
if (MatrixFreePDE<dim, degree>::userInputs
.nonlinear_solver_parameters.getToleranceType(
Expand Down
14 changes: 8 additions & 6 deletions applications/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ main(int argc, char **argv)
// postprocessing variables there are, how many sets of elastic constants
// there are, and how many user-defined constants there are.

variableAttributeLoader variable_attributes;
inputFileReader input_file_reader(parameters_filename, variable_attributes);
const variableAttributeLoader attribute_loader;
const AttributesList var_attributes = attribute_loader.get_var_attributes();
const AttributesList pp_attributes = attribute_loader.get_pp_attributes();
inputFileReader input_file_reader(parameters_filename,
var_attributes,
pp_attributes);

// Continue based on the number of dimensions and degree of the elements
// specified in the input file
Expand All @@ -72,8 +76,7 @@ main(int argc, char **argv)
case 2:
{
userInputParameters<2> userInputs(input_file_reader,
input_file_reader.parameter_handler,
variable_attributes);
input_file_reader.parameter_handler);
switch (userInputs.degree)
{
case (1):
Expand Down Expand Up @@ -130,8 +133,7 @@ main(int argc, char **argv)
case 3:
{
userInputParameters<3> userInputs(input_file_reader,
input_file_reader.parameter_handler,
variable_attributes);
input_file_reader.parameter_handler);
switch (userInputs.degree)
{
case (1):
Expand Down
15 changes: 9 additions & 6 deletions automatic_tests/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <core/ParseCommandLineOpts.h>
#include <core/inputFileReader.h>
#include <core/variableAttributeLoader.h>
#include <core/variableAttributes.h>

// Header file for postprocessing that may or may not exist
#ifdef POSTPROCESS_FILE_EXISTS
Expand Down Expand Up @@ -62,8 +63,12 @@ main(int argc, char **argv)
// postprocessing variables there are, how many sets of elastic constants
// there are, and how many user-defined constants there are.

variableAttributeLoader variable_attributes;
inputFileReader input_file_reader(parameters_filename, variable_attributes);
const variableAttributeLoader attribute_loader;
const AttributesList var_attributes = attribute_loader.get_var_attributes();
const AttributesList pp_attributes = attribute_loader.get_pp_attributes();
inputFileReader input_file_reader(parameters_filename,
var_attributes,
pp_attributes);

// Continue based on the number of dimensions and degree of the elements
// specified in the input file
Expand All @@ -72,8 +77,7 @@ main(int argc, char **argv)
case 2:
{
userInputParameters<2> userInputs(input_file_reader,
input_file_reader.parameter_handler,
variable_attributes);
input_file_reader.parameter_handler);
switch (userInputs.degree)
{
case (1):
Expand Down Expand Up @@ -130,8 +134,7 @@ main(int argc, char **argv)
case 3:
{
userInputParameters<3> userInputs(input_file_reader,
input_file_reader.parameter_handler,
variable_attributes);
input_file_reader.parameter_handler);
switch (userInputs.degree)
{
case (1):
Expand Down
9 changes: 5 additions & 4 deletions include/core/inputFileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class inputFileReader
/**
* \brief Constructor.
*/
inputFileReader(const std::string &input_file_name,
variableAttributeLoader &_variable_attributes);
inputFileReader(const std::string &input_file_name,
const AttributesList &_var_attributes,
const AttributesList &_pp_attributes);

/**
* \brief Method to get a list of entry values from multiple subsections in an input
Expand Down Expand Up @@ -77,9 +78,9 @@ class inputFileReader
static bool
check_keyword_match(std::string &line, const std::string &keyword);

variableAttributeLoader &variable_attributes;
const AttributesList &var_attributes;
const AttributesList &pp_attributes;
dealii::ParameterHandler parameter_handler;
unsigned int num_pp_vars;
unsigned int num_constants;
std::vector<std::string> model_constant_names;
unsigned int number_of_dimensions;
Expand Down
8 changes: 4 additions & 4 deletions include/core/matrixFreePDE.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ class MatrixFreePDE : public Subscriptor

unsigned int totalDOFs;

// Virtual methods to set the attributes of the primary field variables and
// the postprocessing field variables virtual void setVariableAttriubutes() =
// 0; virtual void setPostProcessingVariableAttriubutes(){};
variableAttributeLoader var_attributes;
// The attributes of the primary field variables and
// the postprocessing field variables
const AttributesList &var_attributes;
const AttributesList &pp_attributes;

// Elasticity matrix variables
const static unsigned int CIJ_tensor_size = 2 * dim - 1 + dim / 3;
Expand Down
32 changes: 12 additions & 20 deletions include/core/userInputParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <core/model_variables.h>
#include <core/refinement/RefinementCriterion.h>
#include <core/solvers/SolverParameters.h>
#include <core/variableAttributeLoader.h>
#include <core/variableAttributes.h>
#include <nucleation/nucleationParameters.h>
#include <unordered_map>
#include <vector>
Expand All @@ -43,8 +43,7 @@ class userInputParameters
* member variables.
*/
userInputParameters(inputFileReader &input_file_reader,
dealii::ParameterHandler &parameter_handler,
variableAttributeLoader variable_attributes);
dealii::ParameterHandler &parameter_handler);

/**
* \brief Creates a list of BCs to store in BC_list object.
Expand Down Expand Up @@ -176,7 +175,7 @@ class userInputParameters

// Method to load in the variable attributes
void
loadVariableAttributes(const variableAttributeLoader &variable_attributes);
loadVariableAttributes();

// Nucleation attribute methods
[[nodiscard]] std::vector<double>
Expand Down Expand Up @@ -258,7 +257,8 @@ class userInputParameters

// Variable inputs (I might be able to leave some/all of these in
// variable_attributes)
unsigned int number_of_variables;
const AttributesList &var_attributes;
const AttributesList &pp_attributes;

// Variables needed to calculate the RHS
unsigned int num_var_explicit_RHS, num_var_nonexplicit_RHS;
Expand All @@ -280,7 +280,6 @@ class userInputParameters
std::vector<unsigned int> checkpointTimeStepList;

// Postprocessing parameters
unsigned int pp_number_of_variables;
unsigned int num_integrated_fields;
bool postProcessingRequired;
std::vector<unsigned int> integrated_field_indices;
Expand Down Expand Up @@ -337,31 +336,27 @@ class userInputParameters
* spatial discretiziation.
*/
void
assign_spatial_discretization_parameters(dealii::ParameterHandler &parameter_handler,
variableAttributeLoader &variable_attributes);
assign_spatial_discretization_parameters(dealii::ParameterHandler &parameter_handler);

/**
* \brief Assign the provided user inputs to parameters for anything related to the
* temporal discretiziation.
*/
void
assign_temporal_discretization_parameters(dealii::ParameterHandler &parameter_handler,
variableAttributeLoader &variable_attributes);
assign_temporal_discretization_parameters(dealii::ParameterHandler &parameter_handler);
/**
* \brief Assign the provided user inputs to parameters for anything related to linear
* solves.
*/
void
assign_linear_solve_parameters(dealii::ParameterHandler &parameter_handler,
variableAttributeLoader &variable_attributes);
assign_linear_solve_parameters(dealii::ParameterHandler &parameter_handler);

/**
* \brief Assign the provided user inputs to parameters for anything related to
* nonlinear solves.
*/
void
assign_nonlinear_solve_parameters(dealii::ParameterHandler &parameter_handler,
variableAttributeLoader &variable_attributes);
assign_nonlinear_solve_parameters(dealii::ParameterHandler &parameter_handler);

/**
* \brief Assign the provided user inputs to parameters for anything related to
Expand All @@ -382,24 +377,21 @@ class userInputParameters
* nucleation.
*/
void
assign_nucleation_parameters(dealii::ParameterHandler &parameter_handler,
variableAttributeLoader &variable_attributes);
assign_nucleation_parameters(dealii::ParameterHandler &parameter_handler);

/**
* \brief Assign the provided user inputs to parameters for anything related to
* grain remapping and grain vtk load-in.
*/
void
assign_grain_parameters(dealii::ParameterHandler &parameter_handler,
variableAttributeLoader &variable_attributes);
assign_grain_parameters(dealii::ParameterHandler &parameter_handler);

/**
* \brief Assign the provided user inputs to parameters for anything related to
* boundary conditions.
*/
void
assign_boundary_condition_parameters(dealii::ParameterHandler &parameter_handler,
variableAttributeLoader &variable_attributes);
assign_boundary_condition_parameters(dealii::ParameterHandler &parameter_handler);

// Method to create the list of time steps where the results should be output
// (called from loadInputParameters)
Expand Down
18 changes: 15 additions & 3 deletions include/core/variableAttributeLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,33 @@ class variableAttributeLoader
void
set_output_integral(const unsigned int &index, const bool &flag) const;

/**
* \brief getter function for variable attributes list (copy).
*/
AttributesList
get_var_attributes() const;

/**
* \brief getter function for postprocessing attributes list (copy).
*/
AttributesList
get_pp_attributes() const;

/**
* \brief The solutions variable attributes
*/
std::map<uint, variableAttributes> attributes;
AttributesList var_attributes;

/**
* \brief The postprocessing variable attributes
*/
std::map<uint, variableAttributes> pp_attributes;
AttributesList pp_attributes;

/**
* \brief Useful pointer for setting whether solution or postprocessiong variables are
* being loaded
*/
std::map<uint, variableAttributes> *relevant_attributes = nullptr;
AttributesList *relevant_attributes = nullptr;

private:
/**
Expand Down
2 changes: 2 additions & 0 deletions include/core/variableAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ struct variableAttributes
eval_flags_for_eq_type(const variableAttributes &other_variable);
};

using AttributesList = std::map<uint, variableAttributes>;

#endif
14 changes: 7 additions & 7 deletions src/core/boundary_conditions/boundaryConditions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MatrixFreePDE<dim, degree>::applyNeumannBCs()
unsigned int starting_BC_list_index = 0;
for (unsigned int i = 0; i < currentFieldIndex; i++)
{
if (var_attributes.attributes.at(i).var_type == SCALAR)
if (var_attributes.at(i).var_type == SCALAR)
{
starting_BC_list_index++;
}
Expand All @@ -32,7 +32,7 @@ MatrixFreePDE<dim, degree>::applyNeumannBCs()
}
}

if (var_attributes.attributes.at(currentFieldIndex).var_type == SCALAR)
if (var_attributes.at(currentFieldIndex).var_type == SCALAR)
{
for (unsigned int direction = 0; direction < 2 * dim; direction++)
{
Expand Down Expand Up @@ -102,7 +102,7 @@ MatrixFreePDE<dim, degree>::applyDirichletBCs()

for (unsigned int i = 0; i < currentFieldIndex; i++)
{
if (var_attributes.attributes.at(i).var_type == SCALAR)
if (var_attributes.at(i).var_type == SCALAR)
{
starting_BC_list_index++;
}
Expand All @@ -112,7 +112,7 @@ MatrixFreePDE<dim, degree>::applyDirichletBCs()
}
}

if (var_attributes.attributes.at(currentFieldIndex).var_type == SCALAR)
if (var_attributes.at(currentFieldIndex).var_type == SCALAR)
{
for (unsigned int direction = 0; direction < 2 * dim; direction++)
{
Expand Down Expand Up @@ -250,7 +250,7 @@ MatrixFreePDE<dim, degree>::setPeriodicityConstraints(
unsigned int starting_BC_list_index = 0;
for (unsigned int i = 0; i < currentFieldIndex; i++)
{
if (var_attributes.attributes.at(i).var_type == SCALAR)
if (var_attributes.at(i).var_type == SCALAR)
{
starting_BC_list_index++;
}
Expand Down Expand Up @@ -291,8 +291,8 @@ MatrixFreePDE<dim, degree>::set_rigid_body_mode_constraints(
// Determine the number of components in the field. For a scalar field this is 1, for a
// vector dim, etc.
unsigned int n_components = 0;
var_attributes.attributes.at(currentFieldIndex).var_type == VECTOR ? n_components = dim
: n_components = 1;
var_attributes.at(currentFieldIndex).var_type == VECTOR ? n_components = dim
: n_components = 1;

// Loop over each locally owned cell
for (const auto &cell : dof_handler->active_cell_iterators())
Expand Down
6 changes: 2 additions & 4 deletions src/core/buildFields.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ void
MatrixFreePDE<dim, degree>::buildFields()
{
// Build each of the fields in the system
for (unsigned int i = 0; i < userInputs.number_of_variables; i++)
for (const auto &[index, variable] : var_attributes)
{
fields.push_back(Field<dim>(var_attributes.attributes.at(i).var_type,
var_attributes.attributes.at(i).eq_type,
var_attributes.attributes.at(i).name));
fields.push_back(Field<dim>(variable.var_type, variable.eq_type, variable.name));
}
}
Loading

0 comments on commit 2fcd9bc

Please sign in to comment.