LCOV - code coverage report
Current view: top level - src/mfem/auxkernels - MFEMComplexSumAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 32 34 94.1 %
Date: 2026-05-29 20:35:17 Functions: 3 3 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 "MFEMComplexSumAux.h"
      13             : #include "MFEMProblem.h"
      14             : 
      15             : registerMooseObject("MooseApp", MFEMComplexSumAux);
      16             : 
      17             : InputParameters
      18        2106 : MFEMComplexSumAux::validParams()
      19             : {
      20        2106 :   InputParameters params = MFEMComplexAuxKernel::validParams();
      21        4212 :   params.addClassDescription(
      22             :       "Calculates the sum of an arbitrary number of complex variables sharing an FE space, each "
      23             :       "optionally scaled by a complex constant, and stores the result in an auxiliary complex "
      24             :       "variable.");
      25        8424 :   MFEMExecutedObject::addRequiredDependencyParam<std::vector<VariableName>>(
      26             :       params, "source_variables", "The names of the MFEM complex variables to sum");
      27        8424 :   params.addParam<std::vector<mfem::real_t>>(
      28             :       "scale_factors_real",
      29             :       "The real parts of the factors to scale each MFEM variable by during summation");
      30        6318 :   params.addParam<std::vector<mfem::real_t>>(
      31             :       "scale_factors_imag",
      32             :       "The imaginary parts of the factors to scale each MFEM variable by during summation");
      33             : 
      34        2106 :   return params;
      35           0 : }
      36             : 
      37           6 : MFEMComplexSumAux::MFEMComplexSumAux(const InputParameters & parameters)
      38             :   : MFEMComplexAuxKernel(parameters),
      39          12 :     _var_names(getParam<std::vector<VariableName>>("source_variables")),
      40          36 :     _scale_factors_real(parameters.isParamValid("scale_factors_real")
      41           6 :                             ? getParam<std::vector<mfem::real_t>>("scale_factors_real")
      42           6 :                             : std::vector<mfem::real_t>(_var_names.size(), 1.0)),
      43          30 :     _scale_factors_imag(parameters.isParamValid("scale_factors_imag")
      44           6 :                             ? getParam<std::vector<mfem::real_t>>("scale_factors_imag")
      45          18 :                             : std::vector<mfem::real_t>(_var_names.size(), 0.0))
      46             : {
      47           6 :   if (_var_names.size() != _scale_factors_real.size())
      48           6 :     paramError("scale_factors_real",
      49             :                "Number of MFEM variables to sum over is different from the number of provided "
      50             :                "real scale factors.");
      51           4 :   if (_var_names.size() != _scale_factors_imag.size())
      52           0 :     paramError("scale_factors_imag",
      53             :                "Number of MFEM variables to sum over is different from the number of provided "
      54             :                "imaginary scale factors.");
      55             : 
      56          12 :   for (const auto & var_name : _var_names)
      57             :   {
      58             :     const mfem::ParComplexGridFunction * gf =
      59          10 :         getMFEMProblem().getComplexGridFunction(var_name).get();
      60          10 :     if (gf->ParFESpace() == _result_var.ParFESpace())
      61           8 :       _summed_vars.push_back(gf);
      62             :     else
      63          10 :       paramError("source_variables",
      64             :                  "The MFEM variable ",
      65             :                  var_name,
      66             :                  " being summed has a different FESpace from ",
      67           2 :                  _result_var_name);
      68             :   }
      69          18 : }
      70             : 
      71             : void
      72           2 : MFEMComplexSumAux::execute()
      73             : {
      74             :   // result = sum_i ((_scale_factor_i_real+i*scale_factor_i_imag) * _summed_var_i)
      75           2 :   _result_var.real() = 0.0;
      76           2 :   _result_var.imag() = 0.0;
      77           8 :   for (const auto i : index_range(_summed_vars))
      78             :   {
      79           6 :     std::complex<mfem::real_t> scale(_scale_factors_real[i], _scale_factors_imag[i]);
      80           6 :     complexAdd(_result_var, *_summed_vars[i], scale);
      81             :   }
      82           2 : }
      83             : 
      84             : #endif

Generated by: LCOV version 1.14