Skip to content

Commit

Permalink
simplifications to variable_info struct
Browse files Browse the repository at this point in the history
  • Loading branch information
landinjm committed Sep 16, 2024
1 parent 1bd6540 commit 8cb19c8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 156 deletions.
1 change: 0 additions & 1 deletion include/model_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class modelResidual
struct variable_info
{
bool is_scalar;
unsigned int variable_index;
unsigned int global_var_index;
dealii::EvaluationFlags::EvaluationFlags evaluation_flags;
dealii::EvaluationFlags::EvaluationFlags residual_flags;
Expand Down
142 changes: 13 additions & 129 deletions src/userInputParameters/loadVariableAttributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ userInputParameters<dim>::loadVariableAttributes(
}
}
varInfoListExplicitRHS.reserve(num_var_explicit_RHS);
unsigned int scalar_var_index = 0;
unsigned int vector_var_index = 0;
for (unsigned int i = 0; i < number_of_variables; i++)
{
variable_info varInfo;
Expand All @@ -64,28 +62,9 @@ userInputParameters<dim>::loadVariableAttributes(

varInfo.global_var_index = i;

!(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing)
? varInfo.var_needed = true
: varInfo.var_needed = false;
varInfo.var_needed = !(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing);

if (var_type[i] == SCALAR)
{
varInfo.is_scalar = true;
if (varInfo.var_needed)
{
varInfo.variable_index = scalar_var_index;
scalar_var_index++;
}
}
else
{
varInfo.is_scalar = false;
if (varInfo.var_needed)
{
varInfo.variable_index = vector_var_index;
vector_var_index++;
}
}
varInfo.is_scalar = var_type[i] == SCALAR;

varInfoListExplicitRHS.push_back(varInfo);
}
Expand All @@ -101,8 +80,6 @@ userInputParameters<dim>::loadVariableAttributes(
}
}
varInfoListNonexplicitRHS.reserve(num_var_nonexplicit_RHS);
scalar_var_index = 0;
vector_var_index = 0;
for (unsigned int i = 0; i < number_of_variables; i++)
{
variable_info varInfo;
Expand All @@ -115,28 +92,9 @@ userInputParameters<dim>::loadVariableAttributes(

varInfo.global_var_index = i;

!(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing)
? varInfo.var_needed = true
: varInfo.var_needed = false;
varInfo.var_needed = !(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing);

if (var_type[i] == SCALAR)
{
varInfo.is_scalar = true;
if (varInfo.var_needed)
{
varInfo.variable_index = scalar_var_index;
scalar_var_index++;
}
}
else
{
varInfo.is_scalar = false;
if (varInfo.var_needed)
{
varInfo.variable_index = vector_var_index;
vector_var_index++;
}
}
varInfo.is_scalar = var_type[i] == SCALAR;

varInfoListNonexplicitRHS.push_back(varInfo);
}
Expand All @@ -153,8 +111,6 @@ userInputParameters<dim>::loadVariableAttributes(
}

varInfoListLHS.reserve(num_var_LHS);
scalar_var_index = 0;
vector_var_index = 0;
for (unsigned int i = 0; i < number_of_variables; i++)
{
variable_info varInfo;
Expand All @@ -167,35 +123,14 @@ userInputParameters<dim>::loadVariableAttributes(

varInfo.global_var_index = i;

!(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing)
? varInfo.var_needed = true
: varInfo.var_needed = false;
varInfo.var_needed = !(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing);

if (var_type[i] == SCALAR)
{
varInfo.is_scalar = true;
if (varInfo.var_needed)
{
varInfo.variable_index = scalar_var_index;
scalar_var_index++;
}
}
else
{
varInfo.is_scalar = false;
if (varInfo.var_needed)
{
varInfo.variable_index = vector_var_index;
vector_var_index++;
}
}
varInfo.is_scalar = var_type[i] == SCALAR;

varInfoListLHS.push_back(varInfo);
}

varChangeInfoListLHS.reserve(num_var_LHS);
scalar_var_index = 0;
vector_var_index = 0;
for (unsigned int i = 0; i < number_of_variables; i++)
{
variable_info varInfo;
Expand All @@ -209,37 +144,16 @@ userInputParameters<dim>::loadVariableAttributes(

varInfo.global_var_index = i;

!(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing)
? varInfo.var_needed = true
: varInfo.var_needed = false;
varInfo.var_needed = !(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing);

if (var_type[i] == SCALAR)
{
varInfo.is_scalar = true;
if (varInfo.var_needed)
{
varInfo.variable_index = scalar_var_index;
scalar_var_index++;
}
}
else
{
varInfo.is_scalar = false;
if (varInfo.var_needed)
{
varInfo.variable_index = vector_var_index;
vector_var_index++;
}
}
varInfo.is_scalar = var_type[i] == SCALAR;

varChangeInfoListLHS.push_back(varInfo);
}

// Load variable information for postprocessing
// First, the info list for the base field variables
pp_baseVarInfoList.reserve(number_of_variables);
scalar_var_index = 0;
vector_var_index = 0;
for (unsigned int i = 0; i < number_of_variables; i++)
{
variable_info varInfo;
Expand All @@ -249,28 +163,9 @@ userInputParameters<dim>::loadVariableAttributes(

varInfo.global_var_index = i;

!(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing)
? varInfo.var_needed = true
: varInfo.var_needed = false;
varInfo.var_needed = !(varInfo.evaluation_flags & dealii::EvaluationFlags::nothing);

if (var_type[i] == SCALAR)
{
varInfo.is_scalar = true;
if (varInfo.var_needed)
{
varInfo.variable_index = scalar_var_index;
scalar_var_index++;
}
}
else
{
varInfo.is_scalar = false;
if (varInfo.var_needed)
{
varInfo.variable_index = vector_var_index;
vector_var_index++;
}
}
varInfo.is_scalar = var_type[i] == SCALAR;

pp_baseVarInfoList.push_back(varInfo);
}
Expand All @@ -292,8 +187,6 @@ userInputParameters<dim>::loadVariableAttributes(

// The info list for the postprocessing field variables
pp_varInfoList.reserve(pp_number_of_variables);
scalar_var_index = 0;
vector_var_index = 0;
for (unsigned int i = 0; i < pp_number_of_variables; i++)
{
variable_info varInfo;
Expand All @@ -303,18 +196,9 @@ userInputParameters<dim>::loadVariableAttributes(
variable_attributes.equation_dependency_parser.eval_flags_residual_postprocess[i];

varInfo.global_var_index = i;
if (pp_var_type[i] == SCALAR)
{
varInfo.is_scalar = true;
varInfo.variable_index = scalar_var_index;
scalar_var_index++;
}
else
{
varInfo.is_scalar = false;
varInfo.variable_index = vector_var_index;
vector_var_index++;
}

varInfo.is_scalar = pp_var_type[i] == SCALAR;

pp_varInfoList.push_back(varInfo);
}
}
Expand Down
42 changes: 16 additions & 26 deletions src/variableContainer/variableContainer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ variableContainer<dim, degree, T>::variableContainer(

if (var_info.var_needed)
{
const unsigned int var_index = var_info.variable_index;
const unsigned int var_index = var_info.global_var_index;

if (var_info.is_scalar)
{
Expand Down Expand Up @@ -64,7 +64,7 @@ variableContainer<dim, degree, T>::variableContainer(
continue;
}

const unsigned int var_index = var_info.variable_index;
const unsigned int var_index = var_info.global_var_index;

if (var_info.is_scalar)
{
Expand Down Expand Up @@ -96,7 +96,7 @@ variableContainer<dim, degree, T>::variableContainer(
continue;
}

const unsigned int var_index = var_info.variable_index;
const unsigned int var_index = var_info.global_var_index;

if (var_info.is_scalar)
{
Expand Down Expand Up @@ -183,7 +183,7 @@ variableContainer<dim, degree, T>::reinit_and_eval(const std::vector<vectorType
continue;
}

const unsigned int var_index = var_info.variable_index;
const unsigned int var_index = var_info.global_var_index;

if (var_info.is_scalar)
{
Expand Down Expand Up @@ -242,7 +242,7 @@ variableContainer<dim, degree, T>::reinit(unsigned int cell)
continue;
}

const unsigned int var_index = var_info.variable_index;
const unsigned int var_index = var_info.global_var_index;

if (var_info.is_scalar)
{
Expand All @@ -269,7 +269,7 @@ variableContainer<dim, degree, T>::integrate_and_distribute(
continue;
}

const unsigned int var_index = var_info.variable_index;
const unsigned int var_index = var_info.global_var_index;

if (var_info.is_scalar)
{
Expand Down Expand Up @@ -317,8 +317,7 @@ variableContainer<dim, degree, T>::get_scalar_value(
if (varInfoList[global_variable_index].evaluation_flags &
dealii::EvaluationFlags::values)
{
return scalar_vars_map.at(varInfoList[global_variable_index].variable_index)
->get_value(q_point);
return scalar_vars_map.at(global_variable_index)->get_value(q_point);
}
else
{
Expand All @@ -338,8 +337,7 @@ variableContainer<dim, degree, T>::get_scalar_gradient(
if (varInfoList[global_variable_index].evaluation_flags &
dealii::EvaluationFlags::gradients)
{
return scalar_vars_map.at(varInfoList[global_variable_index].variable_index)
->get_gradient(q_point);
return scalar_vars_map.at(global_variable_index)->get_gradient(q_point);
}
else
{
Expand All @@ -359,8 +357,7 @@ variableContainer<dim, degree, T>::get_scalar_hessian(
if (varInfoList[global_variable_index].evaluation_flags &
dealii::EvaluationFlags::hessians)
{
return scalar_vars_map.at(varInfoList[global_variable_index].variable_index)
->get_hessian(q_point);
return scalar_vars_map.at(global_variable_index)->get_hessian(q_point);
}
else
{
Expand All @@ -380,8 +377,7 @@ variableContainer<dim, degree, T>::get_vector_value(
if (varInfoList[global_variable_index].evaluation_flags &
dealii::EvaluationFlags::values)
{
return vector_vars_map.at(varInfoList[global_variable_index].variable_index)
->get_value(q_point);
return vector_vars_map.at(global_variable_index)->get_value(q_point);
}
else
{
Expand All @@ -401,8 +397,7 @@ variableContainer<dim, degree, T>::get_vector_gradient(
if (varInfoList[global_variable_index].evaluation_flags &
dealii::EvaluationFlags::gradients)
{
return vector_vars_map.at(varInfoList[global_variable_index].variable_index)
->get_gradient(q_point);
return vector_vars_map.at(global_variable_index)->get_gradient(q_point);
}
else
{
Expand All @@ -422,8 +417,7 @@ variableContainer<dim, degree, T>::get_vector_hessian(
if (varInfoList[global_variable_index].evaluation_flags &
dealii::EvaluationFlags::hessians)
{
return vector_vars_map.at(varInfoList[global_variable_index].variable_index)
->get_hessian(q_point);
return vector_vars_map.at(global_variable_index)->get_hessian(q_point);
}
else
{
Expand Down Expand Up @@ -564,8 +558,7 @@ variableContainer<dim, degree, T>::set_scalar_value_term_RHS(
unsigned int global_variable_index,
T val)
{
scalar_vars_map[varInfoList[global_variable_index].variable_index]
->submit_value(val, q_point);
scalar_vars_map[global_variable_index]->submit_value(val, q_point);
}

template <int dim, int degree, typename T>
Expand All @@ -574,8 +567,7 @@ variableContainer<dim, degree, T>::set_scalar_gradient_term_RHS(
unsigned int global_variable_index,
dealii::Tensor<1, dim, T> grad)
{
scalar_vars_map[varInfoList[global_variable_index].variable_index]
->submit_gradient(grad, q_point);
scalar_vars_map[global_variable_index]->submit_gradient(grad, q_point);
}

template <int dim, int degree, typename T>
Expand All @@ -584,8 +576,7 @@ variableContainer<dim, degree, T>::set_vector_value_term_RHS(
unsigned int global_variable_index,
dealii::Tensor<1, dim, T> val)
{
vector_vars_map[varInfoList[global_variable_index].variable_index]
->submit_value(val, q_point);
vector_vars_map[global_variable_index]->submit_value(val, q_point);
}

template <int dim, int degree, typename T>
Expand All @@ -594,8 +585,7 @@ variableContainer<dim, degree, T>::set_vector_gradient_term_RHS(
unsigned int global_variable_index,
dealii::Tensor<2, dim, T> grad)
{
vector_vars_map[varInfoList[global_variable_index].variable_index]
->submit_gradient(grad, q_point);
vector_vars_map[global_variable_index]->submit_gradient(grad, q_point);
}

template <int dim, int degree, typename T>
Expand Down

0 comments on commit 8cb19c8

Please sign in to comment.