Line data Source code
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" 15 : #include "MFEMVectorMagnitudeCoefficient.h" 16 : 17 : registerMooseObject("MooseApp", MFEMVariable); 18 : 19 : InputParameters 20 8529 : MFEMVariable::validParams() 21 : { 22 8529 : InputParameters params = MFEMObject::validParams(); 23 : // Create user-facing 'boundary' input for restricting inheriting object to boundaries. 24 25587 : params.addRequiredParam<MFEMFESpaceName>("fespace", 25 : "The finite element space this variable is defined on."); 26 : // Require moose variable parameters (not used!) 27 8529 : params += MooseVariableBase::validParams(); 28 17058 : params.addClassDescription( 29 : "Class for adding MFEM variables to the problem (`mfem::ParGridFunction`s)."); 30 17058 : params.registerBase("MooseVariableBase"); 31 17058 : params.registerSystemAttributeName("MooseVariableBase"); 32 25587 : params.addParam<VariableName>( 33 : "time_derivative", 34 : "Optional name to assign to the time derivative of the variable in transient problems."); 35 8529 : return params; 36 0 : } 37 : 38 3352 : MFEMVariable::MFEMVariable(const InputParameters & parameters) 39 : : MFEMObject(parameters), 40 3352 : _fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace", 41 10056 : getParam<MFEMFESpaceName>("fespace"))), 42 3352 : _gridfunction(buildGridFunction()), 43 3364 : _time_derivative_name( 44 10056 : isParamValid("time_derivative") 45 3352 : ? getParam<VariableName>("time_derivative") 46 : : VariableName( 47 3340 : getMFEMProblem().getProblemData().time_derivative_map.createTimeDerivativeName( 48 6692 : name()))) 49 : { 50 3352 : *_gridfunction = 0.0; 51 3352 : } 52 : 53 : const std::shared_ptr<mfem::ParGridFunction> 54 3352 : MFEMVariable::buildGridFunction() 55 : { 56 3352 : return std::make_shared<mfem::ParGridFunction>(_fespace.getFESpace().get()); 57 : } 58 : 59 : void 60 3352 : MFEMVariable::declareCoefficients() 61 : { 62 : // Get continuity type to 63 3352 : const MFEMFESpace & mfem_fespace = getFESpace(); 64 3352 : const int cont_type = mfem_fespace.getFEC()->GetContType(); 65 3352 : if (getFESpace().isScalar()) 66 : { 67 4170 : getMFEMProblem().getCoefficients().declareScalar<mfem::GridFunctionCoefficient>( 68 4170 : name(), getGridFunction().get()); 69 : // If gradient is well-defined on this variable, create auxiliary coefficient 70 2085 : if (cont_type == mfem::FiniteElementCollection::CONTINUOUS) 71 : { 72 3100 : getMFEMProblem().getCoefficients().declareVector<mfem::GradientGridFunctionCoefficient>( 73 3100 : name() + "_grad", getGridFunction().get()); 74 4650 : getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>( 75 3100 : name() + "_grad_mag", 76 3100 : getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_grad")); 77 : } 78 : } 79 : else 80 : { 81 2534 : getMFEMProblem().getCoefficients().declareVector<mfem::VectorGridFunctionCoefficient>( 82 2534 : name(), getGridFunction().get()); 83 3801 : getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>( 84 3801 : name() + "_mag", getMFEMProblem().getCoefficients().getVectorCoefficient(name())); 85 : // If curl is well-defined on this variable, create auxiliary coefficient 86 1267 : if (cont_type == mfem::FiniteElementCollection::TANGENTIAL || 87 : cont_type == mfem::FiniteElementCollection::CONTINUOUS) 88 : { 89 1728 : getMFEMProblem().getCoefficients().declareVector<mfem::CurlGridFunctionCoefficient>( 90 1728 : name() + "_curl", getGridFunction().get()); 91 2592 : getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>( 92 1728 : name() + "_curl_mag", 93 1728 : getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_curl")); 94 : } 95 : // If divergence is well-defined on this variable, create auxiliary coefficient 96 1267 : if (cont_type == mfem::FiniteElementCollection::NORMAL || 97 : cont_type == mfem::FiniteElementCollection::CONTINUOUS) 98 814 : getMFEMProblem().getCoefficients().declareScalar<mfem::DivergenceGridFunctionCoefficient>( 99 814 : name() + "_div", getGridFunction().get()); 100 : } 101 3352 : } 102 : 103 : #endif