https://mooseframework.inl.gov
MFEMComplexSumAux.C
Go to the documentation of this file.
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 
16 
19 {
21  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  MFEMExecutedObject::addRequiredDependencyParam<std::vector<VariableName>>(
26  params, "source_variables", "The names of the MFEM complex variables to sum");
27  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  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  return params;
35 }
36 
38  : MFEMComplexAuxKernel(parameters),
39  _var_names(getParam<std::vector<VariableName>>("source_variables")),
40  _scale_factors_real(parameters.isParamValid("scale_factors_real")
41  ? getParam<std::vector<mfem::real_t>>("scale_factors_real")
42  : std::vector<mfem::real_t>(_var_names.size(), 1.0)),
43  _scale_factors_imag(parameters.isParamValid("scale_factors_imag")
44  ? getParam<std::vector<mfem::real_t>>("scale_factors_imag")
45  : std::vector<mfem::real_t>(_var_names.size(), 0.0))
46 {
47  if (_var_names.size() != _scale_factors_real.size())
48  paramError("scale_factors_real",
49  "Number of MFEM variables to sum over is different from the number of provided "
50  "real scale factors.");
51  if (_var_names.size() != _scale_factors_imag.size())
52  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  for (const auto & var_name : _var_names)
57  {
58  const mfem::ParComplexGridFunction * gf =
59  getMFEMProblem().getComplexGridFunction(var_name).get();
60  if (gf->ParFESpace() == _result_var.ParFESpace())
61  _summed_vars.push_back(gf);
62  else
63  paramError("source_variables",
64  "The MFEM variable ",
65  var_name,
66  " being summed has a different FESpace from ",
68  }
69 }
70 
71 void
73 {
74  // result = sum_i ((_scale_factor_i_real+i*scale_factor_i_imag) * _summed_var_i)
75  _result_var.real() = 0.0;
76  _result_var.imag() = 0.0;
77  for (const auto i : index_range(_summed_vars))
78  {
79  std::complex<mfem::real_t> scale(_scale_factors_real[i], _scale_factors_imag[i]);
81  }
82 }
83 
84 #endif
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition: MFEMObject.h:45
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:467
void scale(MeshBase &mesh, const Real xs, const Real ys=0., const Real zs=0.)
const std::vector< mfem::real_t > _scale_factors_imag
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
MFEMComplexSumAux(const InputParameters &parameters)
std::vector< const mfem::ParComplexGridFunction * > _summed_vars
Pointers to input variable gridfunctions.
std::shared_ptr< mfem::ParComplexGridFunction > getComplexGridFunction(const std::string &name)
Definition: MFEMProblem.h:327
mfem::ParComplexGridFunction & _result_var
Reference to result complex gridfunction.
const std::vector< mfem::real_t > _scale_factors_real
void complexAdd(mfem::ParComplexGridFunction &a, const mfem::ParComplexGridFunction &b, const std::complex< mfem::real_t > scale={1.0, 0.0})
Method to add a scaled complex variable to another complex variable.
const std::vector< VariableName > & _var_names
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
static InputParameters validParams()
auto index_range(const T &sizable)
const AuxVariableName _result_var_name
Name of complex auxvariable to store the result of the auxkernel in.
Class to construct an auxiliary solver used to update a complex auxvariable.
virtual void execute() override
Perform the main work for this object.
registerMooseObject("MooseApp", MFEMComplexSumAux)