LCOV - code coverage report
Current view: top level - src/mfem/variables - MFEMVariable.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 39a256 Lines: 48 49 98.0 %
Date: 2026-07-14 14:36:17 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14