LCOV - code coverage report
Current view: top level - src/mfem/variables - MFEMComplexVariable.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: fa5e60 Lines: 58 63 92.1 %
Date: 2026-06-24 08:03:36 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #ifdef MOOSE_MFEM_ENABLED
       2             : 
       3             : #include "MFEMComplexVariable.h"
       4             : #include "MooseVariableBase.h"
       5             : #include "MFEMProblem.h"
       6             : #include "MFEMFESpace.h"
       7             : #include "MFEMVectorMagnitudeCoefficient.h"
       8             : 
       9             : registerMooseObject("MooseApp", MFEMComplexVariable);
      10             : 
      11             : InputParameters
      12        2224 : MFEMComplexVariable::validParams()
      13             : {
      14        2224 :   InputParameters params = MFEMObject::validParams();
      15        6672 :   params.addRequiredParam<MFEMFESpaceName>("fespace",
      16             :                                            "The finite element space this variable is defined on.");
      17        2224 :   params += MooseVariableBase::validParams();
      18        4448 :   params.addClassDescription(
      19             :       "Class for adding complex MFEM variables to the problem (`mfem::ParComplexGridFunction`s).");
      20        4448 :   params.registerBase("MooseVariableBase");
      21        2224 :   params.registerSystemAttributeName("MooseVariableBase");
      22             : 
      23        2224 :   return params;
      24           0 : }
      25             : 
      26          63 : MFEMComplexVariable::MFEMComplexVariable(const InputParameters & parameters)
      27             :   : MFEMObject(parameters),
      28          63 :     _fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace",
      29         189 :                                                          getParam<MFEMFESpaceName>("fespace"))),
      30         126 :     _cmplx_gridfunction(buildComplexGridFunction())
      31             : {
      32          63 :   *_cmplx_gridfunction = 0.0;
      33          63 : }
      34             : 
      35             : const std::shared_ptr<mfem::ParComplexGridFunction>
      36          63 : MFEMComplexVariable::buildComplexGridFunction()
      37             : {
      38          63 :   return std::make_shared<mfem::ParComplexGridFunction>(_fespace.getFESpace().get());
      39             : }
      40             : 
      41             : void
      42          63 : MFEMComplexVariable::declareCoefficients()
      43             : {
      44          63 :   const MFEMFESpace & mfem_fespace = getFESpace();
      45          63 :   const int cont_type = mfem_fespace.getFEC()->GetContType();
      46          63 :   if (mfem_fespace.isScalar())
      47             :   {
      48         112 :     getMFEMProblem().getCoefficients().declareScalar<mfem::GridFunctionCoefficient>(
      49         112 :         name() + "_real", &getComplexGridFunction()->real());
      50         112 :     getMFEMProblem().getCoefficients().declareScalar<mfem::GridFunctionCoefficient>(
      51         112 :         name() + "_imag", &getComplexGridFunction()->imag());
      52             :     // If gradient is well-defined on this variable, create auxiliary coefficient
      53          56 :     if (cont_type == mfem::FiniteElementCollection::CONTINUOUS)
      54             :     {
      55         112 :       getMFEMProblem().getCoefficients().declareVector<mfem::GradientGridFunctionCoefficient>(
      56         112 :           name() + "_real_grad", &getComplexGridFunction()->real());
      57         168 :       getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      58         112 :           name() + "_real_grad_mag",
      59         112 :           getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_real_grad"));
      60         112 :       getMFEMProblem().getCoefficients().declareVector<mfem::GradientGridFunctionCoefficient>(
      61         112 :           name() + "_imag_grad", &getComplexGridFunction()->imag());
      62         168 :       getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      63         112 :           name() + "_imag_grad_mag",
      64         112 :           getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_imag_grad"));
      65             :     }
      66             :   }
      67             :   else
      68             :   {
      69          14 :     getMFEMProblem().getCoefficients().declareVector<mfem::VectorGridFunctionCoefficient>(
      70          14 :         name() + "_real", &getComplexGridFunction()->real());
      71          21 :     getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      72          14 :         name() + "_real_mag",
      73          14 :         getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_real"));
      74          14 :     getMFEMProblem().getCoefficients().declareVector<mfem::VectorGridFunctionCoefficient>(
      75          14 :         name() + "_imag", &getComplexGridFunction()->imag());
      76          21 :     getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      77          14 :         name() + "_imag_mag",
      78          14 :         getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_imag"));
      79             :     // If curl is well-defined on this variable, create auxiliary coefficient
      80           7 :     if (cont_type == mfem::FiniteElementCollection::TANGENTIAL ||
      81             :         cont_type == mfem::FiniteElementCollection::CONTINUOUS)
      82             :     {
      83          14 :       getMFEMProblem().getCoefficients().declareVector<mfem::CurlGridFunctionCoefficient>(
      84          14 :           name() + "_real_curl", &getComplexGridFunction()->real());
      85          21 :       getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      86          14 :           name() + "_real_curl_mag",
      87          14 :           getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_real_curl"));
      88          14 :       getMFEMProblem().getCoefficients().declareVector<mfem::CurlGridFunctionCoefficient>(
      89          14 :           name() + "_imag_curl", &getComplexGridFunction()->imag());
      90          21 :       getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      91          14 :           name() + "_imag_curl_mag",
      92          14 :           getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_imag_curl"));
      93             :     }
      94             :     // If divergence is well-defined on this variable, create auxiliary coefficient
      95           7 :     if (cont_type == mfem::FiniteElementCollection::NORMAL ||
      96             :         cont_type == mfem::FiniteElementCollection::CONTINUOUS)
      97             :     {
      98           0 :       getMFEMProblem().getCoefficients().declareScalar<mfem::DivergenceGridFunctionCoefficient>(
      99           0 :           name() + "_real_div", &getComplexGridFunction()->real());
     100           0 :       getMFEMProblem().getCoefficients().declareScalar<mfem::DivergenceGridFunctionCoefficient>(
     101           0 :           name() + "_imag_div", &getComplexGridFunction()->imag());
     102             :     }
     103             :   }
     104          63 : }
     105             : 
     106             : #endif

Generated by: LCOV version 1.14