https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMComplexVariable.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#ifdef MOOSE_MFEM_ENABLED
11
12#include "MFEMComplexVariable.h"
13#include "MooseVariableBase.h"
14#include "MFEMProblem.h"
15#include "MFEMFESpace.h"
17
19
22{
24 params.addRequiredParam<MFEMFESpaceName>("fespace",
25 "The finite element space this variable is defined on.");
28 "Class for adding complex MFEM variables to the problem (`mfem::ParComplexGridFunction`s).");
29 params.registerBase("MooseVariableBase");
30 params.registerSystemAttributeName("MooseVariableBase");
31
32 return params;
33}
34
36 : MFEMObject(parameters),
37 _fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace",
38 getParam<MFEMFESpaceName>("fespace"))),
39 _cmplx_gridfunction(buildComplexGridFunction())
40{
42}
43
44const std::shared_ptr<mfem::ParComplexGridFunction>
46{
47 return std::make_shared<mfem::ParComplexGridFunction>(_fespace.getFESpace().get());
48}
49
50void
52{
53 const MFEMFESpace & mfem_fespace = getFESpace();
54 const int cont_type = mfem_fespace.getFEC()->GetContType();
55 if (mfem_fespace.isScalar())
56 {
57 getMFEMProblem().getCoefficients().declareScalar<mfem::GridFunctionCoefficient>(
58 name() + "_real", &getComplexGridFunction()->real());
59 getMFEMProblem().getCoefficients().declareScalar<mfem::GridFunctionCoefficient>(
60 name() + "_imag", &getComplexGridFunction()->imag());
61 // If gradient is well-defined on this variable, create auxiliary coefficient
62 if (cont_type == mfem::FiniteElementCollection::CONTINUOUS)
63 {
64 getMFEMProblem().getCoefficients().declareVector<mfem::GradientGridFunctionCoefficient>(
65 name() + "_real_grad", &getComplexGridFunction()->real());
67 name() + "_real_grad_mag",
69 getMFEMProblem().getCoefficients().declareVector<mfem::GradientGridFunctionCoefficient>(
70 name() + "_imag_grad", &getComplexGridFunction()->imag());
72 name() + "_imag_grad_mag",
74 }
75 }
76 else
77 {
78 getMFEMProblem().getCoefficients().declareVector<mfem::VectorGridFunctionCoefficient>(
79 name() + "_real", &getComplexGridFunction()->real());
81 name() + "_real_mag",
83 getMFEMProblem().getCoefficients().declareVector<mfem::VectorGridFunctionCoefficient>(
84 name() + "_imag", &getComplexGridFunction()->imag());
86 name() + "_imag_mag",
88 // If curl is well-defined on this variable, create auxiliary coefficient
89 if (cont_type == mfem::FiniteElementCollection::TANGENTIAL ||
90 cont_type == mfem::FiniteElementCollection::CONTINUOUS)
91 {
92 getMFEMProblem().getCoefficients().declareVector<mfem::CurlGridFunctionCoefficient>(
93 name() + "_real_curl", &getComplexGridFunction()->real());
95 name() + "_real_curl_mag",
97 getMFEMProblem().getCoefficients().declareVector<mfem::CurlGridFunctionCoefficient>(
98 name() + "_imag_curl", &getComplexGridFunction()->imag());
100 name() + "_imag_curl_mag",
102 }
103 // If divergence is well-defined on this variable, create auxiliary coefficient
104 if (cont_type == mfem::FiniteElementCollection::NORMAL ||
105 cont_type == mfem::FiniteElementCollection::CONTINUOUS)
106 {
107 getMFEMProblem().getCoefficients().declareScalar<mfem::DivergenceGridFunctionCoefficient>(
108 name() + "_real_div", &getComplexGridFunction()->real());
109 getMFEMProblem().getCoefficients().declareScalar<mfem::DivergenceGridFunctionCoefficient>(
110 name() + "_imag_div", &getComplexGridFunction()->imag());
111 }
112 }
113}
114
115#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 exist, 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...