Skip to content

Commit

Permalink
Add H(div) helper functions and types (idaholab#26105)
Browse files Browse the repository at this point in the history
Co-authored-by: Nuno Nobre <nuno.nobre@stfc.ac.uk>
  • Loading branch information
2 people authored and chaibhave committed Dec 6, 2023
1 parent 7ef654e commit 0bdd94e
Show file tree
Hide file tree
Showing 9 changed files with 386 additions and 0 deletions.
88 changes: 88 additions & 0 deletions framework/include/base/Assembly.h
Expand Up @@ -1328,6 +1328,10 @@ class Assembly
{
return _vector_curl_phi;
}
const VectorVariablePhiDivergence & divPhi(const MooseVariableField<RealVectorValue> &) const
{
return _vector_div_phi;
}

const VectorVariablePhiValue & phiFace(const MooseVariableField<RealVectorValue> &) const
{
Expand All @@ -1345,6 +1349,10 @@ class Assembly
{
return _vector_curl_phi_face;
}
const VectorVariablePhiDivergence & divPhiFace(const MooseVariableField<RealVectorValue> &) const
{
return _vector_div_phi_face;
}

const VectorVariablePhiValue & phiNeighbor(const MooseVariableField<RealVectorValue> &) const
{
Expand All @@ -1364,6 +1372,10 @@ class Assembly
{
return _vector_curl_phi_neighbor;
}
const VectorVariablePhiDivergence & divPhiNeighbor(const MooseVariableField<RealVectorValue> &) const
{
return _vector_div_phi_neighbor;
}

const VectorVariablePhiValue & phiFaceNeighbor(const MooseVariableField<RealVectorValue> &) const
{
Expand All @@ -1384,6 +1396,11 @@ class Assembly
{
return _vector_curl_phi_face_neighbor;
}
const VectorVariablePhiDivergence &
divPhiFaceNeighbor(const MooseVariableField<RealVectorValue> &) const
{
return _vector_div_phi_face_neighbor;
}

// Writeable references
VariablePhiValue & phi(const MooseVariableField<Real> &) { return _phi; }
Expand Down Expand Up @@ -1431,6 +1448,10 @@ class Assembly
{
return _vector_curl_phi;
}
VectorVariablePhiDivergence & divPhi(const MooseVariableField<RealVectorValue> &)
{
return _vector_div_phi;
}

VectorVariablePhiValue & phiFace(const MooseVariableField<RealVectorValue> &)
{
Expand All @@ -1448,6 +1469,10 @@ class Assembly
{
return _vector_curl_phi_face;
}
VectorVariablePhiDivergence & divPhiFace(const MooseVariableField<RealVectorValue> &)
{
return _vector_div_phi_face;
}

VectorVariablePhiValue & phiNeighbor(const MooseVariableField<RealVectorValue> &)
{
Expand All @@ -1465,6 +1490,10 @@ class Assembly
{
return _vector_curl_phi_neighbor;
}
VectorVariablePhiDivergence & divPhiNeighbor(const MooseVariableField<RealVectorValue> &)
{
return _vector_div_phi_neighbor;
}
VectorVariablePhiValue & phiFaceNeighbor(const MooseVariableField<RealVectorValue> &)
{
return _vector_phi_face_neighbor;
Expand All @@ -1481,6 +1510,10 @@ class Assembly
{
return _vector_curl_phi_face_neighbor;
}
VectorVariablePhiDivergence & divPhiFaceNeighbor(const MooseVariableField<RealVectorValue> &)
{
return _vector_div_phi_face_neighbor;
}

// Writeable references with array variable
VariablePhiValue & phi(const MooseVariableField<RealEigenVector> &) { return _phi; }
Expand Down Expand Up @@ -1670,6 +1703,38 @@ class Assembly
return _fe_shape_data_face_neighbor[type]->_curl_phi;
}

template <typename OutputType>
const typename OutputTools<OutputType>::VariablePhiDivergence & feDivPhi(FEType type) const
{
_need_div[type] = true;
buildFE(type);
return _fe_shape_data[type]->_div_phi;
}

template <typename OutputType>
const typename OutputTools<OutputType>::VariablePhiDivergence & feDivPhiFace(FEType type) const
{
_need_div[type] = true;
buildFaceFE(type);
return _fe_shape_data_face[type]->_div_phi;
}

template <typename OutputType>
const typename OutputTools<OutputType>::VariablePhiDivergence & feDivPhiNeighbor(FEType type) const
{
_need_div[type] = true;
buildNeighborFE(type);
return _fe_shape_data_neighbor[type]->_div_phi;
}

template <typename OutputType>
const typename OutputTools<OutputType>::VariablePhiDivergence & feDivPhiFaceNeighbor(FEType type) const
{
_need_div[type] = true;
buildFaceNeighborFE(type);
return _fe_shape_data_face_neighbor[type]->_div_phi;
}

/// On-demand computation of volume element accounting for RZ/RSpherical
Real elementVolume(const Elem * elem) const;

Expand Down Expand Up @@ -2597,21 +2662,25 @@ class Assembly
VectorVariablePhiGradient _vector_grad_phi;
VectorVariablePhiSecond _vector_second_phi;
VectorVariablePhiCurl _vector_curl_phi;
VectorVariablePhiDivergence _vector_div_phi;

VectorVariablePhiValue _vector_phi_face;
VectorVariablePhiGradient _vector_grad_phi_face;
VectorVariablePhiSecond _vector_second_phi_face;
VectorVariablePhiCurl _vector_curl_phi_face;
VectorVariablePhiDivergence _vector_div_phi_face;

VectorVariablePhiValue _vector_phi_neighbor;
VectorVariablePhiGradient _vector_grad_phi_neighbor;
VectorVariablePhiSecond _vector_second_phi_neighbor;
VectorVariablePhiCurl _vector_curl_phi_neighbor;
VectorVariablePhiDivergence _vector_div_phi_neighbor;

VectorVariablePhiValue _vector_phi_face_neighbor;
VectorVariablePhiGradient _vector_grad_phi_face_neighbor;
VectorVariablePhiSecond _vector_second_phi_face_neighbor;
VectorVariablePhiCurl _vector_curl_phi_face_neighbor;
VectorVariablePhiDivergence _vector_div_phi_face_neighbor;

class FEShapeData
{
Expand All @@ -2620,6 +2689,7 @@ class Assembly
VariablePhiGradient _grad_phi;
VariablePhiSecond _second_phi;
VariablePhiCurl _curl_phi;
VariablePhiDivergence _div_phi;
};

class VectorFEShapeData
Expand All @@ -2629,6 +2699,7 @@ class Assembly
VectorVariablePhiGradient _grad_phi;
VectorVariablePhiSecond _second_phi;
VectorVariablePhiCurl _curl_phi;
VectorVariablePhiDivergence _div_phi;
};

/// Shape function values, gradients, second derivatives for each FE type
Expand Down Expand Up @@ -2735,6 +2806,7 @@ class Assembly
mutable std::map<FEType, bool> _need_second_derivative;
mutable std::map<FEType, bool> _need_second_derivative_neighbor;
mutable std::map<FEType, bool> _need_curl;
mutable std::map<FEType, bool> _need_div;

/// The map from global index to variable scaling factor
const NumericVector<Real> * _scaling_vector = nullptr;
Expand Down Expand Up @@ -2893,6 +2965,22 @@ template <>
const typename OutputTools<VectorValue<Real>>::VariablePhiCurl &
Assembly::feCurlPhiFaceNeighbor<VectorValue<Real>>(FEType type) const;

template <>
const typename OutputTools<VectorValue<Real>>::VariablePhiDivergence &
Assembly::feDivPhi<VectorValue<Real>>(FEType type) const;

template <>
const typename OutputTools<VectorValue<Real>>::VariablePhiDivergence &
Assembly::feDivPhiFace<VectorValue<Real>>(FEType type) const;

template <>
const typename OutputTools<VectorValue<Real>>::VariablePhiDivergence &
Assembly::feDivPhiNeighbor<VectorValue<Real>>(FEType type) const;

template <>
const typename OutputTools<VectorValue<Real>>::VariablePhiDivergence &
Assembly::feDivPhiFaceNeighbor<VectorValue<Real>>(FEType type) const;

template <>
inline const ADTemplateVariablePhiGradient<RealVectorValue> &
Assembly::adGradPhi<RealVectorValue>(const MooseVariableFE<RealVectorValue> & v) const
Expand Down
9 changes: 9 additions & 0 deletions framework/include/utils/MooseTypes.h
Expand Up @@ -301,43 +301,52 @@ typedef typename OutputTools<Real>::VariableValue VariableValue;
typedef typename OutputTools<Real>::VariableGradient VariableGradient;
typedef typename OutputTools<Real>::VariableSecond VariableSecond;
typedef typename OutputTools<Real>::VariableCurl VariableCurl;
typedef typename OutputTools<Real>::VariableDivergence VariableDivergence;
typedef typename OutputTools<Real>::VariablePhiValue VariablePhiValue;
typedef typename OutputTools<Real>::VariablePhiGradient VariablePhiGradient;
typedef typename OutputTools<Real>::VariablePhiSecond VariablePhiSecond;
typedef typename OutputTools<Real>::VariablePhiCurl VariablePhiCurl;
typedef typename OutputTools<Real>::VariablePhiDivergence VariablePhiDivergence;
typedef typename OutputTools<Real>::VariableTestValue VariableTestValue;
typedef typename OutputTools<Real>::VariableTestGradient VariableTestGradient;
typedef typename OutputTools<Real>::VariableTestSecond VariableTestSecond;
typedef typename OutputTools<Real>::VariableTestCurl VariableTestCurl;
typedef typename OutputTools<Real>::VariableTestDivergence VariableTestDivergence;

// types for vector variable
typedef typename OutputTools<RealVectorValue>::VariableValue VectorVariableValue;
typedef typename OutputTools<RealVectorValue>::VariableGradient VectorVariableGradient;
typedef typename OutputTools<RealVectorValue>::VariableSecond VectorVariableSecond;
typedef typename OutputTools<RealVectorValue>::VariableCurl VectorVariableCurl;
typedef typename OutputTools<RealVectorValue>::VariableDivergence VectorVariableDivergence;
typedef typename OutputTools<RealVectorValue>::VariablePhiValue VectorVariablePhiValue;
typedef typename OutputTools<RealVectorValue>::VariablePhiGradient VectorVariablePhiGradient;
typedef typename OutputTools<RealVectorValue>::VariablePhiSecond VectorVariablePhiSecond;
typedef typename OutputTools<RealVectorValue>::VariablePhiCurl VectorVariablePhiCurl;
typedef typename OutputTools<RealVectorValue>::VariablePhiDivergence VectorVariablePhiDivergence;
typedef typename OutputTools<RealVectorValue>::VariableTestValue VectorVariableTestValue;
typedef typename OutputTools<RealVectorValue>::VariableTestGradient VectorVariableTestGradient;
typedef typename OutputTools<RealVectorValue>::VariableTestSecond VectorVariableTestSecond;
typedef typename OutputTools<RealVectorValue>::VariableTestCurl VectorVariableTestCurl;
typedef typename OutputTools<RealVectorValue>::VariableTestDivergence VectorVariableTestDivergence;

// types for array variable
typedef typename OutputTools<RealEigenVector>::VariableValue ArrayVariableValue;
typedef typename OutputTools<RealEigenVector>::VariableGradient ArrayVariableGradient;
typedef typename OutputTools<RealEigenVector>::VariableSecond ArrayVariableSecond;
typedef typename OutputTools<RealEigenVector>::VariableCurl ArrayVariableCurl;
typedef typename OutputTools<RealEigenVector>::VariableDivergence ArrayVariableDivergence;
typedef typename OutputTools<RealEigenVector>::VariablePhiValue ArrayVariablePhiValue;
typedef typename OutputTools<RealEigenVector>::VariablePhiGradient ArrayVariablePhiGradient;
typedef std::vector<std::vector<Eigen::Map<RealDIMValue>>> MappedArrayVariablePhiGradient;
typedef typename OutputTools<RealEigenVector>::VariablePhiSecond ArrayVariablePhiSecond;
typedef typename OutputTools<RealEigenVector>::VariablePhiCurl ArrayVariablePhiCurl;
typedef typename OutputTools<RealEigenVector>::VariablePhiDivergence ArrayVariablePhiDivergence;
typedef typename OutputTools<RealEigenVector>::VariableTestValue ArrayVariableTestValue;
typedef typename OutputTools<RealEigenVector>::VariableTestGradient ArrayVariableTestGradient;
typedef typename OutputTools<RealEigenVector>::VariableTestSecond ArrayVariableTestSecond;
typedef typename OutputTools<RealEigenVector>::VariableTestCurl ArrayVariableTestCurl;
typedef typename OutputTools<RealEigenVector>::VariableTestDivergence ArrayVariableTestDivergence;

/**
* AD typedefs
Expand Down
42 changes: 42 additions & 0 deletions framework/include/variables/MooseVariableData.h
Expand Up @@ -190,6 +190,16 @@ class MooseVariableData : public MooseVariableDataBase<OutputType>
*/
const FieldVariablePhiCurl & curlPhiFace() const;

/**
* divergence_phi getter
*/
const FieldVariablePhiDivergence & divPhi() const;

/**
* divergence_phi_face getter
*/
const FieldVariablePhiDivergence & divPhiFace() const;

/**
* ad_grad_phi getter
*/
Expand Down Expand Up @@ -223,6 +233,11 @@ class MooseVariableData : public MooseVariableDataBase<OutputType>
*/
bool computingCurl() const { return _need_curl || _need_curl_old; }

/**
* Whether or not this variable is computing the divergence
*/
bool computingDiv() const { return _need_div || _need_div_old; }

//////////////////////////////// Nodal stuff ///////////////////////////////////////////

bool isNodal() const override { return _is_nodal; }
Expand Down Expand Up @@ -271,6 +286,12 @@ class MooseVariableData : public MooseVariableDataBase<OutputType>
*/
const FieldVariableCurl & curlSln(Moose::SolutionState state) const;

/**
* Local solution divergence getter
* @param state The state of the simulation: current, old, older
*/
const FieldVariableDivergence & divSln(Moose::SolutionState state) const;

const ADTemplateVariableValue<OutputType> & adSln() const
{
_need_ad = _need_ad_u = true;
Expand Down Expand Up @@ -476,6 +497,11 @@ class MooseVariableData : public MooseVariableDataBase<OutputType>
mutable bool _need_curl_old;
mutable bool _need_curl_older;

/// divergence flags
mutable bool _need_div;
mutable bool _need_div_old;
mutable bool _need_div_older;

/// AD flags
mutable bool _need_ad;
mutable bool _need_ad_u;
Expand All @@ -500,6 +526,11 @@ class MooseVariableData : public MooseVariableDataBase<OutputType>
FieldVariableCurl _curl_u_old;
FieldVariableCurl _curl_u_older;

/// divergence_u
FieldVariableDivergence _div_u;
FieldVariableDivergence _div_u_old;
FieldVariableDivergence _div_u_older;

/// AD u
ADTemplateVariableValue<OutputType> _ad_u;
ADTemplateVariableGradient<OutputType> _ad_grad_u;
Expand Down Expand Up @@ -542,6 +573,7 @@ class MooseVariableData : public MooseVariableDataBase<OutputType>
const FieldVariablePhiGradient * _grad_phi;
mutable const FieldVariablePhiSecond * _second_phi;
mutable const FieldVariablePhiCurl * _curl_phi;
mutable const FieldVariablePhiDivergence * _div_phi;

// Mapped array phi
MappedArrayVariablePhiGradient _mapped_grad_phi;
Expand All @@ -554,6 +586,7 @@ class MooseVariableData : public MooseVariableDataBase<OutputType>
const FieldVariablePhiGradient * _grad_phi_face;
mutable const FieldVariablePhiSecond * _second_phi_face;
mutable const FieldVariablePhiCurl * _curl_phi_face;
mutable const FieldVariablePhiDivergence * _div_phi_face;

const ADTemplateVariablePhiGradient<OutputShape> * _ad_grad_phi;
const ADTemplateVariablePhiGradient<OutputShape> * _ad_grad_phi_face;
Expand All @@ -563,6 +596,7 @@ class MooseVariableData : public MooseVariableDataBase<OutputType>
const FieldVariablePhiGradient * _current_grad_phi;
const FieldVariablePhiSecond * _current_second_phi;
const FieldVariablePhiCurl * _current_curl_phi;
const FieldVariablePhiDivergence * _current_div_phi;
const ADTemplateVariablePhiGradient<OutputShape> * _current_ad_grad_phi;

// dual mortar
Expand Down Expand Up @@ -596,6 +630,14 @@ class MooseVariableData : public MooseVariableDataBase<OutputType>
FEType)>
_curl_phi_face_assembly_method;

std::function<const typename OutputTools<OutputShape>::VariablePhiDivergence &(const Assembly &,
FEType)>
_div_phi_assembly_method;

std::function<const typename OutputTools<OutputShape>::VariablePhiDivergence &(const Assembly &,
FEType)>
_div_phi_face_assembly_method;

std::function<const ADTemplateVariablePhiGradient<OutputShape> &(const Assembly &, FEType)>
_ad_grad_phi_assembly_method;
std::function<const ADTemplateVariablePhiGradient<OutputShape> &(const Assembly &, FEType)>
Expand Down

0 comments on commit 0bdd94e

Please sign in to comment.