LCOV - code coverage report
Current view: top level - src/mfem/variables - MFEMVariable.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32463 (9b8a52) with base a052fd Lines: 48 49 98.0 %
Date: 2026-05-26 14:49:46 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        8595 : MFEMVariable::validParams()
      21             : {
      22        8595 :   InputParameters params = MFEMObject::validParams();
      23             :   // Create user-facing 'boundary' input for restricting inheriting object to boundaries.
      24       25785 :   params.addRequiredParam<MFEMFESpaceName>("fespace",
      25             :                                            "The finite element space this variable is defined on.");
      26             :   // Require moose variable parameters (not used!)
      27        8595 :   params += MooseVariableBase::validParams();
      28       17190 :   params.addClassDescription(
      29             :       "Class for adding MFEM variables to the problem (`mfem::ParGridFunction`s).");
      30       17190 :   params.registerBase("MooseVariableBase");
      31       17190 :   params.registerSystemAttributeName("MooseVariableBase");
      32       25785 :   params.addParam<VariableName>(
      33             :       "time_derivative",
      34             :       "Optional name to assign to the time derivative of the variable in transient problems.");
      35        8595 :   return params;
      36           0 : }
      37             : 
      38        3385 : MFEMVariable::MFEMVariable(const InputParameters & parameters)
      39             :   : MFEMObject(parameters),
      40        3385 :     _fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace",
      41       10155 :                                                          getParam<MFEMFESpaceName>("fespace"))),
      42        3385 :     _gridfunction(buildGridFunction()),
      43        3397 :     _time_derivative_name(
      44       10155 :         isParamValid("time_derivative")
      45        3385 :             ? getParam<VariableName>("time_derivative")
      46             :             : VariableName(
      47        3373 :                   getMFEMProblem().getProblemData().time_derivative_map.createTimeDerivativeName(
      48        6758 :                       name())))
      49             : {
      50        3385 :   *_gridfunction = 0.0;
      51        3385 : }
      52             : 
      53             : const std::shared_ptr<mfem::ParGridFunction>
      54        3385 : MFEMVariable::buildGridFunction()
      55             : {
      56        3385 :   return std::make_shared<mfem::ParGridFunction>(_fespace.getFESpace().get());
      57             : }
      58             : 
      59             : void
      60        3385 : MFEMVariable::declareCoefficients()
      61             : {
      62             :   // Get continuity type to
      63        3385 :   const MFEMFESpace & mfem_fespace = getFESpace();
      64        3385 :   const int cont_type = mfem_fespace.getFEC()->GetContType();
      65        3385 :   if (getFESpace().isScalar())
      66             :   {
      67        4192 :     getMFEMProblem().getCoefficients().declareScalar<mfem::GridFunctionCoefficient>(
      68        4192 :         name(), getGridFunction().get());
      69             :     // If gradient is well-defined on this variable, create auxiliary coefficient
      70        2096 :     if (cont_type == mfem::FiniteElementCollection::CONTINUOUS)
      71             :     {
      72        3122 :       getMFEMProblem().getCoefficients().declareVector<mfem::GradientGridFunctionCoefficient>(
      73        3122 :           name() + "_grad", getGridFunction().get());
      74        4683 :       getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      75        3122 :           name() + "_grad_mag",
      76        3122 :           getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_grad"));
      77             :     }
      78             :   }
      79             :   else
      80             :   {
      81        2578 :     getMFEMProblem().getCoefficients().declareVector<mfem::VectorGridFunctionCoefficient>(
      82        2578 :         name(), getGridFunction().get());
      83        3867 :     getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      84        3867 :         name() + "_mag", getMFEMProblem().getCoefficients().getVectorCoefficient(name()));
      85             :     // If curl is well-defined on this variable, create auxiliary coefficient
      86        1289 :     if (cont_type == mfem::FiniteElementCollection::TANGENTIAL ||
      87             :         cont_type == mfem::FiniteElementCollection::CONTINUOUS)
      88             :     {
      89        1750 :       getMFEMProblem().getCoefficients().declareVector<mfem::CurlGridFunctionCoefficient>(
      90        1750 :           name() + "_curl", getGridFunction().get());
      91        2625 :       getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      92        1750 :           name() + "_curl_mag",
      93        1750 :           getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_curl"));
      94             :     }
      95             :     // If divergence is well-defined on this variable, create auxiliary coefficient
      96        1289 :     if (cont_type == mfem::FiniteElementCollection::NORMAL ||
      97             :         cont_type == mfem::FiniteElementCollection::CONTINUOUS)
      98         836 :       getMFEMProblem().getCoefficients().declareScalar<mfem::DivergenceGridFunctionCoefficient>(
      99         836 :           name() + "_div", getGridFunction().get());
     100             :   }
     101        3385 : }
     102             : 
     103             : #endif

Generated by: LCOV version 1.14