https://mooseframework.inl.gov
MFEMComplexVariable.C
Go to the documentation of this file.
1 #ifdef MOOSE_MFEM_ENABLED
2 
3 #include "MFEMComplexVariable.h"
4 #include "MooseVariableBase.h"
5 #include "MFEMProblem.h"
6 #include "MFEMFESpace.h"
8 
10 
13 {
15  params.addRequiredParam<MFEMFESpaceName>("fespace",
16  "The finite element space this variable is defined on.");
18  params.addClassDescription(
19  "Class for adding complex MFEM variables to the problem (`mfem::ParComplexGridFunction`s).");
20  params.registerBase("MooseVariableBase");
21  params.registerSystemAttributeName("MooseVariableBase");
22 
23  return params;
24 }
25 
27  : MFEMObject(parameters),
28  _fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace",
29  getParam<MFEMFESpaceName>("fespace"))),
30  _cmplx_gridfunction(buildComplexGridFunction())
31 {
32  *_cmplx_gridfunction = 0.0;
33 }
34 
35 const std::shared_ptr<mfem::ParComplexGridFunction>
37 {
38  return std::make_shared<mfem::ParComplexGridFunction>(_fespace.getFESpace().get());
39 }
40 
41 void
43 {
44  const MFEMFESpace & mfem_fespace = getFESpace();
45  const int cont_type = mfem_fespace.getFEC()->GetContType();
46  if (mfem_fespace.isScalar())
47  {
48  getMFEMProblem().getCoefficients().declareScalar<mfem::GridFunctionCoefficient>(
49  name() + "_real", &getComplexGridFunction()->real());
50  getMFEMProblem().getCoefficients().declareScalar<mfem::GridFunctionCoefficient>(
51  name() + "_imag", &getComplexGridFunction()->imag());
52  // If gradient is well-defined on this variable, create auxiliary coefficient
53  if (cont_type == mfem::FiniteElementCollection::CONTINUOUS)
54  {
55  getMFEMProblem().getCoefficients().declareVector<mfem::GradientGridFunctionCoefficient>(
56  name() + "_real_grad", &getComplexGridFunction()->real());
58  name() + "_real_grad_mag",
60  getMFEMProblem().getCoefficients().declareVector<mfem::GradientGridFunctionCoefficient>(
61  name() + "_imag_grad", &getComplexGridFunction()->imag());
63  name() + "_imag_grad_mag",
65  }
66  }
67  else
68  {
69  getMFEMProblem().getCoefficients().declareVector<mfem::VectorGridFunctionCoefficient>(
70  name() + "_real", &getComplexGridFunction()->real());
72  name() + "_real_mag",
74  getMFEMProblem().getCoefficients().declareVector<mfem::VectorGridFunctionCoefficient>(
75  name() + "_imag", &getComplexGridFunction()->imag());
77  name() + "_imag_mag",
79  // If curl is well-defined on this variable, create auxiliary coefficient
80  if (cont_type == mfem::FiniteElementCollection::TANGENTIAL ||
81  cont_type == mfem::FiniteElementCollection::CONTINUOUS)
82  {
83  getMFEMProblem().getCoefficients().declareVector<mfem::CurlGridFunctionCoefficient>(
84  name() + "_real_curl", &getComplexGridFunction()->real());
86  name() + "_real_curl_mag",
88  getMFEMProblem().getCoefficients().declareVector<mfem::CurlGridFunctionCoefficient>(
89  name() + "_imag_curl", &getComplexGridFunction()->imag());
91  name() + "_imag_curl_mag",
93  }
94  // If divergence is well-defined on this variable, create auxiliary coefficient
95  if (cont_type == mfem::FiniteElementCollection::NORMAL ||
96  cont_type == mfem::FiniteElementCollection::CONTINUOUS)
97  {
98  getMFEMProblem().getCoefficients().declareScalar<mfem::DivergenceGridFunctionCoefficient>(
99  name() + "_real_div", &getComplexGridFunction()->real());
100  getMFEMProblem().getCoefficients().declareScalar<mfem::DivergenceGridFunctionCoefficient>(
101  name() + "_imag_div", &getComplexGridFunction()->imag());
102  }
103  }
104 }
105 
106 #endif
static InputParameters validParams()
Thin base for MFEM objects backed directly by MooseObject instead of UserObject.
Definition: MFEMObject.h:25
Constructs and stores an mfem::ParComplexGridFunction object.
std::shared_ptr< mfem::ParComplexGridFunction > getComplexGridFunction() const
Returns a shared pointer to the constructed gridfunction.
static InputParameters validParams()
MFEMComplexVariable(const InputParameters &parameters)
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition: MFEMObject.h:45
const MFEMFESpace & getFESpace() const
Returns a reference to the fespace used by the gridfunction.
mfem::VectorCoefficient & getVectorCoefficient(const std::string &name)
Return a vector coefficient with the given name or, if that doesn&#39;t exists, try interpreting the name...
registerMooseObject("MooseApp", MFEMComplexVariable)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::shared_ptr< mfem::ParComplexGridFunction > _cmplx_gridfunction
Stores the constructed gridfunction.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
std::shared_ptr< mfem::FiniteElementCollection > getFEC() const
Returns a shared pointer to the constructed fec.
Definition: MFEMFESpace.h:44
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
virtual bool isScalar() const =0
mfem::Coefficient & declareScalar(const std::string &name, const std::string &existing_or_literal)
Declare an alias to an existing scalar coefficient or, if it does not exist, try interpreting the nam...
const std::shared_ptr< mfem::ParComplexGridFunction > buildComplexGridFunction()
Constructs the gridfunction.
mfem::VectorCoefficient & declareVector(const std::string &name, const std::string &existing_or_literal)
Declare an alias to an existing vector coefficientor or, if it does not exist, try interpreting the n...
Moose::MFEM::CoefficientManager & getCoefficients()
Method to get the PropertyManager object for storing material properties and converting them to MFEM ...
Definition: MFEMProblem.h:248
Constructs and stores an mfem::ParFiniteElementSpace object.
Definition: MFEMFESpace.h:20
const MFEMFESpace & _fespace
static InputParameters validParams()
Declare the common parameters required by MFEM MooseObject-backed classes.
Definition: MFEMObject.C:17
std::shared_ptr< mfem::ParFiniteElementSpace > getFESpace() const
Returns a shared pointer to the constructed fespace.
Definition: MFEMFESpace.h:36
Scalar coefficient that evaluates the magnitude of a vector coefficient.