https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMComplexVariable.C
Go to the documentation of this file.
1#ifdef MOOSE_MFEM_ENABLED
2
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.");
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{
33}
34
35const std::shared_ptr<mfem::ParComplexGridFunction>
37{
38 return std::make_shared<mfem::ParComplexGridFunction>(_fespace.getFESpace().get());
39}
40
41void
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
registerMooseObject("MooseApp", MFEMComplexVariable)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void registerSystemAttributeName(const std::string &value)
This method is used to define the MOOSE system name that is used by the TheWarehouse object for stori...
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...
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
Constructs and stores an mfem::ParComplexGridFunction object.
std::shared_ptr< mfem::ParComplexGridFunction > getComplexGridFunction() const
Returns a shared pointer to the constructed gridfunction.
MFEMComplexVariable(const InputParameters &parameters)
const MFEMFESpace & getFESpace() const
Returns a reference to the fespace used by the gridfunction.
const MFEMFESpace & _fespace
const std::shared_ptr< mfem::ParComplexGridFunction > buildComplexGridFunction()
Constructs the gridfunction.
const std::shared_ptr< mfem::ParComplexGridFunction > _cmplx_gridfunction
Stores the constructed gridfunction.
static InputParameters validParams()
Constructs and stores an mfem::ParFiniteElementSpace object.
Definition MFEMFESpace.h:21
virtual bool isScalar() const =0
std::shared_ptr< mfem::FiniteElementCollection > getFEC() const
Returns a shared pointer to the constructed fec.
Definition MFEMFESpace.h:44
std::shared_ptr< mfem::ParFiniteElementSpace > getFESpace() const
Returns a shared pointer to the constructed fespace.
Definition MFEMFESpace.h:36
Thin base for MFEM objects backed directly by MooseObject instead of UserObject.
Definition MFEMObject.h:30
static InputParameters validParams()
Declare the common parameters required by MFEM MooseObject-backed classes.
Definition MFEMObject.C:17
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition MFEMObject.h:45
Moose::MFEM::CoefficientManager & getCoefficients()
Method to get the PropertyManager object for storing material properties and converting them to MFEM ...
Scalar coefficient that evaluates the magnitude of a vector coefficient.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
static InputParameters validParams()
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...
mfem::VectorCoefficient & getVectorCoefficient(const std::string &name)
Return a vector coefficient with the given name or, if that doesn't exists, try interpreting the name...
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...