LCOV - code coverage report
Current view: top level - src/mfem/variables - MFEMComplexVariable.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 58 63 92.1 %
Date: 2026-05-29 20:35:17 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        2222 : MFEMComplexVariable::validParams()
      13             : {
      14        2222 :   InputParameters params = MFEMObject::validParams();
      15        6666 :   params.addRequiredParam<MFEMFESpaceName>("fespace",
      16             :                                            "The finite element space this variable is defined on.");
      17        2222 :   params += MooseVariableBase::validParams();
      18        4444 :   params.addClassDescription(
      19             :       "Class for adding complex MFEM variables to the problem (`mfem::ParComplexGridFunction`s).");
      20        4444 :   params.registerBase("MooseVariableBase");
      21        2222 :   params.registerSystemAttributeName("MooseVariableBase");
      22             : 
      23        2222 :   return params;
      24           0 : }
      25             : 
      26          62 : MFEMComplexVariable::MFEMComplexVariable(const InputParameters & parameters)
      27             :   : MFEMObject(parameters),
      28          62 :     _fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace",
      29         186 :                                                          getParam<MFEMFESpaceName>("fespace"))),
      30         124 :     _cmplx_gridfunction(buildComplexGridFunction())
      31             : {
      32          62 :   *_cmplx_gridfunction = 0.0;
      33          62 : }
      34             : 
      35             : const std::shared_ptr<mfem::ParComplexGridFunction>
      36          62 : MFEMComplexVariable::buildComplexGridFunction()
      37             : {
      38          62 :   return std::make_shared<mfem::ParComplexGridFunction>(_fespace.getFESpace().get());
      39             : }
      40             : 
      41             : void
      42          62 : MFEMComplexVariable::declareCoefficients()
      43             : {
      44          62 :   const MFEMFESpace & mfem_fespace = getFESpace();
      45          62 :   const int cont_type = mfem_fespace.getFEC()->GetContType();
      46          62 :   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          12 :     getMFEMProblem().getCoefficients().declareVector<mfem::VectorGridFunctionCoefficient>(
      70          12 :         name() + "_real", &getComplexGridFunction()->real());
      71          18 :     getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      72          12 :         name() + "_real_mag",
      73          12 :         getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_real"));
      74          12 :     getMFEMProblem().getCoefficients().declareVector<mfem::VectorGridFunctionCoefficient>(
      75          12 :         name() + "_imag", &getComplexGridFunction()->imag());
      76          18 :     getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      77          12 :         name() + "_imag_mag",
      78          12 :         getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_imag"));
      79             :     // If curl is well-defined on this variable, create auxiliary coefficient
      80           6 :     if (cont_type == mfem::FiniteElementCollection::TANGENTIAL ||
      81             :         cont_type == mfem::FiniteElementCollection::CONTINUOUS)
      82             :     {
      83          12 :       getMFEMProblem().getCoefficients().declareVector<mfem::CurlGridFunctionCoefficient>(
      84          12 :           name() + "_real_curl", &getComplexGridFunction()->real());
      85          18 :       getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      86          12 :           name() + "_real_curl_mag",
      87          12 :           getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_real_curl"));
      88          12 :       getMFEMProblem().getCoefficients().declareVector<mfem::CurlGridFunctionCoefficient>(
      89          12 :           name() + "_imag_curl", &getComplexGridFunction()->imag());
      90          18 :       getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      91          12 :           name() + "_imag_curl_mag",
      92          12 :           getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_imag_curl"));
      93             :     }
      94             :     // If divergence is well-defined on this variable, create auxiliary coefficient
      95           6 :     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          62 : }
     105             : 
     106             : #endif

Generated by: LCOV version 1.14