LCOV - code coverage report
Current view: top level - src/mfem/variables - MFEMComplexVariable.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 329044 Lines: 58 63 92.1 %
Date: 2026-08-03 21:12:22 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        2286 : MFEMComplexVariable::validParams()
      13             : {
      14        2286 :   InputParameters params = MFEMObject::validParams();
      15        6858 :   params.addRequiredParam<MFEMFESpaceName>("fespace",
      16             :                                            "The finite element space this variable is defined on.");
      17        2286 :   params += MooseVariableBase::validParams();
      18        4572 :   params.addClassDescription(
      19             :       "Class for adding complex MFEM variables to the problem (`mfem::ParComplexGridFunction`s).");
      20        4572 :   params.registerBase("MooseVariableBase");
      21        2286 :   params.registerSystemAttributeName("MooseVariableBase");
      22             : 
      23        2286 :   return params;
      24           0 : }
      25             : 
      26          77 : MFEMComplexVariable::MFEMComplexVariable(const InputParameters & parameters)
      27             :   : MFEMObject(parameters),
      28          77 :     _fespace(getMFEMProblem().getMFEMObject<MFEMFESpace>("MFEMFESpace",
      29         231 :                                                          getParam<MFEMFESpaceName>("fespace"))),
      30         154 :     _cmplx_gridfunction(buildComplexGridFunction())
      31             : {
      32          77 :   *_cmplx_gridfunction = 0.0;
      33          77 : }
      34             : 
      35             : const std::shared_ptr<mfem::ParComplexGridFunction>
      36          77 : MFEMComplexVariable::buildComplexGridFunction()
      37             : {
      38          77 :   return std::make_shared<mfem::ParComplexGridFunction>(_fespace.getFESpace().get());
      39             : }
      40             : 
      41             : void
      42          77 : MFEMComplexVariable::declareCoefficients()
      43             : {
      44          77 :   const MFEMFESpace & mfem_fespace = getFESpace();
      45          77 :   const int cont_type = mfem_fespace.getFEC()->GetContType();
      46          77 :   if (mfem_fespace.isScalar())
      47             :   {
      48         140 :     getMFEMProblem().getCoefficients().declareScalar<mfem::GridFunctionCoefficient>(
      49         140 :         name() + "_real", &getComplexGridFunction()->real());
      50         140 :     getMFEMProblem().getCoefficients().declareScalar<mfem::GridFunctionCoefficient>(
      51         140 :         name() + "_imag", &getComplexGridFunction()->imag());
      52             :     // If gradient is well-defined on this variable, create auxiliary coefficient
      53          70 :     if (cont_type == mfem::FiniteElementCollection::CONTINUOUS)
      54             :     {
      55         132 :       getMFEMProblem().getCoefficients().declareVector<mfem::GradientGridFunctionCoefficient>(
      56         132 :           name() + "_real_grad", &getComplexGridFunction()->real());
      57         198 :       getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      58         132 :           name() + "_real_grad_mag",
      59         132 :           getMFEMProblem().getCoefficients().getVectorCoefficient(name() + "_real_grad"));
      60         132 :       getMFEMProblem().getCoefficients().declareVector<mfem::GradientGridFunctionCoefficient>(
      61         132 :           name() + "_imag_grad", &getComplexGridFunction()->imag());
      62         198 :       getMFEMProblem().getCoefficients().declareScalar<MFEMVectorMagnitudeCoefficient>(
      63         132 :           name() + "_imag_grad_mag",
      64         132 :           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          77 : }
     105             : 
     106             : #endif

Generated by: LCOV version 1.14