https://mooseframework.inl.gov
MFEMVariable.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 "MFEMVariable.h"
13 #include "MFEMProblem.h"
14 #include "MooseVariableBase.h"
16 
18 
21 {
23  // Create user-facing 'boundary' input for restricting inheriting object to boundaries.
24  params.addRequiredParam<MFEMFESpaceName>("fespace",
25  "The finite element space this variable is defined on.");
26  // Require moose variable parameters (not used!)
28  params.addClassDescription(
29  "Class for adding MFEM variables to the problem (`mfem::ParGridFunction`s).");
30  params.registerBase("MooseVariableBase");
31  params.registerSystemAttributeName("MooseVariableBase");
32  params.addParam<VariableName>(
33  "time_derivative",
34  "Optional name to assign to the time derivative of the variable in transient problems.");
35  return params;
36 }
37 
39  : MFEMObject(parameters),
40  _fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace",
41  getParam<MFEMFESpaceName>("fespace"))),
42  _gridfunction(buildGridFunction()),
43  _time_derivative_name(
44  isParamValid("time_derivative")
45  ? getParam<VariableName>("time_derivative")
46  : VariableName(
47  getMFEMProblem().getProblemData().time_derivative_map.createTimeDerivativeName(
48  name())))
49 {
50  *_gridfunction = 0.0;
51 }
52 
53 const std::shared_ptr<mfem::ParGridFunction>
55 {
56  return std::make_shared<mfem::ParGridFunction>(_fespace.getFESpace().get());
57 }
58 
59 void
61 {
62  // Get continuity type to
63  const MFEMFESpace & mfem_fespace = getFESpace();
64  const int cont_type = mfem_fespace.getFEC()->GetContType();
65  if (getFESpace().isScalar())
66  {
67  getMFEMProblem().getCoefficients().declareScalar<mfem::GridFunctionCoefficient>(
68  name(), getGridFunction().get());
69  // If gradient is well-defined on this variable, create auxiliary coefficient
70  if (cont_type == mfem::FiniteElementCollection::CONTINUOUS)
71  {
72  getMFEMProblem().getCoefficients().declareVector<mfem::GradientGridFunctionCoefficient>(
73  name() + "_grad", getGridFunction().get());
75  name() + "_grad_mag",
77  }
78  }
79  else
80  {
81  getMFEMProblem().getCoefficients().declareVector<mfem::VectorGridFunctionCoefficient>(
82  name(), getGridFunction().get());
85  // If curl is well-defined on this variable, create auxiliary coefficient
86  if (cont_type == mfem::FiniteElementCollection::TANGENTIAL ||
87  cont_type == mfem::FiniteElementCollection::CONTINUOUS)
88  {
89  getMFEMProblem().getCoefficients().declareVector<mfem::CurlGridFunctionCoefficient>(
90  name() + "_curl", getGridFunction().get());
92  name() + "_curl_mag",
94  }
95  // If divergence is well-defined on this variable, create auxiliary coefficient
96  if (cont_type == mfem::FiniteElementCollection::NORMAL ||
97  cont_type == mfem::FiniteElementCollection::CONTINUOUS)
98  getMFEMProblem().getCoefficients().declareScalar<mfem::DivergenceGridFunctionCoefficient>(
99  name() + "_div", getGridFunction().get());
100  }
101 }
102 
103 #endif
static InputParameters validParams()
std::string name(const ElemQuality q)
Thin base for MFEM objects backed directly by MooseObject instead of UserObject.
Definition: MFEMObject.h:25
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition: MFEMObject.h:45
const MFEMFESpace & _fespace
Definition: MFEMVariable.h:40
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", MFEMVariable)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::shared_ptr< mfem::ParGridFunction > _gridfunction
Stores the constructed gridfunction.
Definition: MFEMVariable.h:47
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...
Constructs and stores an mfem::ParGridFunction object.
Definition: MFEMVariable.h:20
MFEMVariable(const InputParameters &parameters)
Definition: MFEMVariable.C:38
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
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 & 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:257
const std::shared_ptr< mfem::ParGridFunction > buildGridFunction()
Constructs the gridfunction.
Definition: MFEMVariable.C:54
const MFEMFESpace & getFESpace() const
Returns a reference to the fespace used by the gridfunction.
Definition: MFEMVariable.h:31
std::shared_ptr< mfem::ParGridFunction > getGridFunction() const
Returns a shared pointer to the constructed gridfunction.
Definition: MFEMVariable.h:28
Constructs and stores an mfem::ParFiniteElementSpace object.
Definition: MFEMFESpace.h:20
static InputParameters validParams()
Declare the common parameters required by MFEM MooseObject-backed classes.
Definition: MFEMObject.C:17
static InputParameters validParams()
Definition: MFEMVariable.C:20
std::shared_ptr< mfem::ParFiniteElementSpace > getFESpace() const
Returns a shared pointer to the constructed fespace.
Definition: MFEMFESpace.h:36
void declareCoefficients()
Declare default coefficients associated with this gridfunction.
Definition: MFEMVariable.C:60
Scalar coefficient that evaluates the magnitude of a vector coefficient.