Skip to content

Commit

Permalink
Merge pull request #29697 from GiudGiud/PR_mem_locality
Browse files Browse the repository at this point in the history
Minor optimizations on MooseVariableData
  • Loading branch information
GiudGiud authored Feb 6, 2025
2 parents 758838b + da00183 commit e29a964
Show file tree
Hide file tree
Showing 6 changed files with 347 additions and 841 deletions.
2 changes: 1 addition & 1 deletion framework/include/utils/MooseTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ struct IsADType<MetaPhysicL::DualNumber<T, Args...>>
* error with constexpr-based if conditions. The templating delays the triggering
* of the static assertion until the template is instantiated.
*/
template <class T>
template <class... Ts>
constexpr std::false_type always_false{};

} // namespace Moose
Expand Down
17 changes: 13 additions & 4 deletions framework/include/variables/MooseVariableData.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,15 @@ class MooseVariableData : public MooseVariableDataBase<OutputType>
void assignADNodalValue(const ADReal & value, const unsigned int & component);
void fetchADNodalValues();

/**
* Internal method for computeValues() and computeMonomialValues()
*
* Monomial is a template parameter so that we get compile time optimization
* for monomial vs non-monomial
*/
template <bool monomial>
void computeValuesInternal();

const libMesh::FEType & _fe_type;

const unsigned int _var_num;
Expand Down Expand Up @@ -554,19 +563,19 @@ class MooseVariableData : public MooseVariableDataBase<OutputType>
FieldVariableValue _u_dot;

/// u_dotdot (second time derivative)
FieldVariableValue _u_dotdot, _u_dotdot_bak;
FieldVariableValue _u_dotdot;

/// u_dot_old (time derivative)
FieldVariableValue _u_dot_old, _u_dot_old_bak;
FieldVariableValue _u_dot_old;

/// u_dotdot_old (second time derivative)
FieldVariableValue _u_dotdot_old, _u_dotdot_old_bak;
FieldVariableValue _u_dotdot_old;

/// derivative of u_dot wrt u
VariableValue _du_dot_du;

/// derivative of u_dotdot wrt u
VariableValue _du_dotdot_du, _du_dotdot_du_bak;
VariableValue _du_dotdot_du;

/// The current qrule. This has to be a reference because the current qrule will be constantly
/// changing. If we initialized this to point to one qrule, then in the next calculation we would
Expand Down
8 changes: 4 additions & 4 deletions framework/include/variables/MooseVariableDataFV.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,19 +373,19 @@ class MooseVariableDataFV : public MooseVariableDataBase<OutputType>, public Mes
FieldVariableValue _u_dot;

/// u_dotdot (second time derivative)
FieldVariableValue _u_dotdot, _u_dotdot_bak;
FieldVariableValue _u_dotdot;

/// u_dot_old (time derivative)
FieldVariableValue _u_dot_old, _u_dot_old_bak;
FieldVariableValue _u_dot_old;

/// u_dotdot_old (second time derivative)
FieldVariableValue _u_dotdot_old, _u_dotdot_old_bak;
FieldVariableValue _u_dotdot_old;

/// derivative of u_dot wrt u
VariableValue _du_dot_du;

/// derivative of u_dotdot wrt u
VariableValue _du_dotdot_du, _du_dotdot_du_bak;
VariableValue _du_dotdot_du;

/// Pointer to time integrator
const TimeIntegrator * const _time_integrator;
Expand Down
32 changes: 4 additions & 28 deletions framework/src/variables/MooseVariableConstMonomial.C
Original file line number Diff line number Diff line change
Expand Up @@ -42,50 +42,26 @@ void
MooseVariableConstMonomial::computeElemValues()
{
_element_data->setGeometry(Moose::Volume);

// We have not optimized AD calculations for const monomials yet, so we fall back on the
// non-optimized routine
if (_element_data->needsAD())
_element_data->computeValues();
else
_element_data->computeMonomialValues();
_element_data->computeMonomialValues();
}

void
MooseVariableConstMonomial::computeElemValuesFace()
{
_element_data->setGeometry(Moose::Face);

// We have not optimized AD calculations for const monomials yet, so we fall back on the
// non-optimized routine
if (_element_data->needsAD())
_element_data->computeValues();
else
_element_data->computeMonomialValues();
_element_data->computeMonomialValues();
}

void
MooseVariableConstMonomial::computeNeighborValues()
{
_neighbor_data->setGeometry(Moose::Volume);

// We have not optimized AD calculations for const monomials yet, so we fall back on the
// non-optimized routine
if (_neighbor_data->needsAD())
_neighbor_data->computeValues();
else
_neighbor_data->computeMonomialValues();
_neighbor_data->computeMonomialValues();
}

void
MooseVariableConstMonomial::computeNeighborValuesFace()
{
_neighbor_data->setGeometry(Moose::Face);

// We have not optimized AD calculations for const monomials yet, so we fall back on the
// non-optimized routine
if (_neighbor_data->needsAD())
_neighbor_data->computeValues();
else
_neighbor_data->computeMonomialValues();
_neighbor_data->computeMonomialValues();
}
Loading

0 comments on commit e29a964

Please sign in to comment.