Skip to content

Commit

Permalink
removed varInfoLists
Browse files Browse the repository at this point in the history
Now variableContainer operates on variableAttributes objects instead.
Moderate refactor of variableContainer.
Single-constructor.
Functionalized error messages for debug for field get-functions.

Note: Some "var_needed" logic may be redundant and can be removed.
  • Loading branch information
fractalsbyx committed Jan 2, 2025
1 parent 389726b commit 1b85537
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 489 deletions.
12 changes: 12 additions & 0 deletions include/core/solveTypeEnums.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef INCLUDE_SOLVETYPEENUMS_H
#define INCLUDE_SOLVETYPEENUMS_H

enum class solveType
{
EXPLICIT_RHS,
NONEXPLICIT_RHS,
LHS,
POSTPROCESS
};

#endif
14 changes: 2 additions & 12 deletions include/core/userInputParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,8 @@ class userInputParameters
const AttributesList &var_attributes;
const AttributesList &pp_attributes;

// Variables needed to calculate the RHS
unsigned int num_var_explicit_RHS, num_var_nonexplicit_RHS;
std::vector<variable_info> varInfoListExplicitRHS, varInfoListNonexplicitRHS;

// Variables needed to calculate the LHS
unsigned int num_var_LHS;
std::vector<variable_info> varInfoListLHS;
std::vector<variable_info> varChangeInfoListLHS;
// Variables needed to calculate each expression
AttributesList attributes_RHS_exp, attributes_RHS_nonexp, attributes_LHS;

// Variables for loading in initial conditions
std::vector<bool> load_ICs;
Expand All @@ -287,10 +281,6 @@ class userInputParameters
bool postProcessingRequired;
std::vector<unsigned int> integrated_field_indices;

// Variable and residual info
std::vector<variable_info> pp_varInfoList;
std::vector<variable_info> pp_baseVarInfoList;

// List of boundary conditions
std::vector<varBCs<dim>> BC_list;

Expand Down
2 changes: 0 additions & 2 deletions include/core/variableAttributeLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include <map>
#include <string>

using EvalFlags = dealii::EvaluationFlags::EvaluationFlags;

/**
* \brief Class to manage the variable attributes that the user specifies.
*/
Expand Down
30 changes: 29 additions & 1 deletion include/core/variableAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <deal.II/matrix_free/evaluation_flags.h>

#include <core/solveTypeEnums.h>
#include <core/varTypeEnums.h>
#include <map>
#include <set>
Expand All @@ -19,7 +20,7 @@ using AttributesList = std::map<uint, variableAttributes>;
struct variableAttributes
{
// Variable attributes
std::string name = "";
std::string name;
fieldType var_type = UNDEFINED_FIELD;
PDEType eq_type = UNDEFINED_PDE;
bool need_value_nucleation = false;
Expand Down Expand Up @@ -86,6 +87,33 @@ struct variableAttributes
*/
std::set<EvalFlags *>
eval_flags_for_eq_type(const variableAttributes &other_variable);

/**
* \brief Helper function that returns a set of pointers to the evaluation flags needed
* for an expression type
*
* \param solve_type EXPLICIT_RHS, NONEXPLICIT_RHS, LHS, POSTPROCESS
*/
[[nodiscard]] const EvalFlags &
eval_flags_for_solve(const solveType &solve_type) const;

/**
* \brief Helper function that returns a set of pointers to the residual flags needed
* for an expression type
*
* \param solve_type EXPLICIT_RHS, NONEXPLICIT_RHS, LHS, POSTPROCESS
*/
[[nodiscard]] const EvalFlags &
residual_flags_for_solve(const solveType &solve_type) const;

/**
* \brief Helper function that returns true if this variable is needed for an expression
* type
*
* \param solve_type EXPLICIT_RHS, NONEXPLICIT_RHS, LHS, POSTPROCESS
*/
[[nodiscard]] bool
var_needed(const solveType &solve_type) const;
};

#endif
38 changes: 18 additions & 20 deletions include/core/variableContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

#include <boost/unordered_map.hpp>

#include "core/solveTypeEnums.h"
#include "core/variableAttributes.h"
#include "varTypeEnums.h"

#include <core/model_variables.h>

template <int dim, int degree, typename T>
Expand All @@ -22,16 +26,8 @@ class variableContainer

// Standard contructor, used for most situations
variableContainer(const dealii::MatrixFree<dim, double> &data,
const std::vector<variable_info> &_varInfoList,
const std::vector<variable_info> &_varChangeInfoList);

variableContainer(const dealii::MatrixFree<dim, double> &data,
const std::vector<variable_info> &_varInfoList);
// Nonstandard constructor, used when only one index of "data" should be used,
// use with care!
variableContainer(const dealii::MatrixFree<dim, double> &data,
const std::vector<variable_info> &_varInfoList,
const unsigned int &fixed_index);
AttributesList _subset_attributes,
solveType solve_type);

// Methods to get the value/grad/hess in the residual method (this is how the
// user gets these values in equations.h)
Expand Down Expand Up @@ -93,7 +89,7 @@ class variableContainer
void
reinit_and_eval_change_in_solution(const vectorType &src,
unsigned int cell,
unsigned int var_being_solved);
const uint &var_index);

// Only initialize the FEEvaluation object for each variable (used for
// post-processing)
Expand All @@ -104,17 +100,16 @@ class variableContainer
void
integrate_and_distribute(std::vector<vectorType *> &dst);
void
integrate_and_distribute_change_in_solution_LHS(vectorType &dst,
const unsigned int var_being_solved);
integrate_and_distribute_change_in_solution_LHS(vectorType &dst, const uint &var_index);

// The quadrature point index, a method to get the number of quadrature points
// per cell, and a method to get the xyz coordinates for the quadrature point
unsigned int q_point;
unsigned int q_point = 0;

unsigned int
[[nodiscard]] unsigned int
get_num_q_points() const;

dealii::Point<dim, T>
[[nodiscard]] dealii::Point<dim, T>
get_q_point_location() const;

private:
Expand All @@ -133,11 +128,14 @@ class variableContainer

// Object containing some information about each variable (indices, whether
// the val/grad/hess is needed, etc)
std::vector<variable_info> varInfoList;
std::vector<variable_info> varChangeInfoList;
const AttributesList subset_attributes;
const solveType solve_type;

// The number of variables
unsigned int num_var;
void
AssertValid(const uint &var_index,
const fieldType &field_type,
const EvalFlags &eval_flag,
bool is_change) const;
};

#endif
2 changes: 1 addition & 1 deletion src/core/outputResults.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ MatrixFreePDE<dim, degree>::outputResults()
{
// mark field as scalar/vector
unsigned int components = 0;
if (userInputs.pp_varInfoList[fieldIndex].is_scalar)
if (pp_variable.var_type == SCALAR)
{
components = 1;
std::vector<DataComponentInterpretation::DataComponentInterpretation>
Expand Down
11 changes: 4 additions & 7 deletions src/core/postprocessing/postprocessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ MatrixFreePDE<dim, degree>::computePostProcessedFields(
// Initialize the postProcessedSet
for (unsigned int fieldIndex = 0; fieldIndex < pp_attributes.size(); fieldIndex++)
{
vectorType *U = nullptr;
U = new vectorType;
vectorType *U = new vectorType;
postProcessedSet.push_back(U);
matrixFreeObject.initialize_dof_vector(*U, 0);
}
Expand All @@ -31,12 +30,10 @@ MatrixFreePDE<dim, degree>::getPostProcessedFields(
const std::pair<unsigned int, unsigned int> &cell_range)
{
// initialize FEEvaulation objects
variableContainer<dim, degree, dealii::VectorizedArray<double>> variable_list(
data,
userInputs.pp_baseVarInfoList);
variableContainer<dim, degree, dealii::VectorizedArray<double>>
pp_variable_list(data, userInputs.pp_varInfoList, 0);

variable_list(data, var_attributes, solveType::POSTPROCESS);
variableContainer<dim, degree, dealii::VectorizedArray<double>>
pp_variable_list(data, pp_attributes, solveType::POSTPROCESS);
// loop over cells
for (unsigned int cell = cell_range.first; cell < cell_range.second; ++cell)
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/solvers/computeLHS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ MatrixFreePDE<dim, degree>::getLHS(
const std::pair<unsigned int, unsigned int> &cell_range) const
{
variableContainer<dim, degree, dealii::VectorizedArray<double>>
variable_list(data, userInputs.varInfoListLHS, userInputs.varChangeInfoListLHS);
variable_list(data, userInputs.attributes_LHS, solveType::LHS);

// loop over cells
for (unsigned int cell = cell_range.first; cell < cell_range.second; ++cell)
Expand Down
10 changes: 4 additions & 6 deletions src/core/solvers/computeRHS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ MatrixFreePDE<dim, degree>::getExplicitRHS(
const std::vector<vectorType *> &src,
const std::pair<unsigned int, unsigned int> &cell_range) const
{
variableContainer<dim, degree, dealii::VectorizedArray<double>> variable_list(
data,
userInputs.varInfoListExplicitRHS);
variableContainer<dim, degree, dealii::VectorizedArray<double>>
variable_list(data, userInputs.attributes_RHS_exp, solveType::EXPLICIT_RHS);

// loop over cells
for (unsigned int cell = cell_range.first; cell < cell_range.second; ++cell)
Expand Down Expand Up @@ -87,9 +86,8 @@ MatrixFreePDE<dim, degree>::getNonexplicitRHS(
const std::vector<vectorType *> &src,
const std::pair<unsigned int, unsigned int> &cell_range) const
{
variableContainer<dim, degree, dealii::VectorizedArray<double>> variable_list(
data,
userInputs.varInfoListNonexplicitRHS);
variableContainer<dim, degree, dealii::VectorizedArray<double>>
variable_list(data, userInputs.attributes_RHS_nonexp, solveType::NONEXPLICIT_RHS);

// loop over cells
for (unsigned int cell = cell_range.first; cell < cell_range.second; ++cell)
Expand Down
Loading

0 comments on commit 1b85537

Please sign in to comment.