https://mooseframework.inl.gov
MFEMComplexAuxKernel.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 "MFEMComplexAuxKernel.h"
13 #include "MFEMProblem.h"
14 
17 {
19  params.registerBase("AuxKernel");
20  params.addClassDescription("Base class for MFEM objects that update auxiliary variables outside "
21  "of the main solve step.");
22  params.addRequiredParam<AuxVariableName>("variable",
23  "The name of the variable that this object applies to");
24  return params;
25 }
26 
28  : MFEMExecutedObject(parameters),
29  _result_var_name(getParam<AuxVariableName>("variable")),
30  _result_var(*getMFEMProblem().getComplexGridFunction(_result_var_name))
31 {
32 }
33 
34 std::optional<std::string>
36 {
37  return _result_var_name;
38 }
39 
40 void
41 MFEMComplexAuxKernel::complexAdd(mfem::ParComplexGridFunction & a,
42  const mfem::ParComplexGridFunction & b,
43  const std::complex<mfem::real_t> scale)
44 {
45  // a += scale * b
46 
47  // check that the parfespaces match
48  if (a.ParFESpace() != b.ParFESpace())
49  mooseError("MFEMComplexAuxKernel::complexAdd: ParFESpaces of input variables do not match.");
50 
51  a.real().Add(scale.real(), b.real());
52  a.real().Add(-scale.imag(), b.imag());
53  a.imag().Add(scale.imag(), b.real());
54  a.imag().Add(scale.real(), b.imag());
55 }
56 
57 void
58 MFEMComplexAuxKernel::complexScale(mfem::ParComplexGridFunction & a,
59  const std::complex<mfem::real_t> scale)
60 {
61  // a *= scale
62 
63  mfem::ParComplexGridFunction b(a.ParFESpace());
64  static_cast<mfem::Vector &>(b) = a;
65 
66  complexAdd(a, b, scale - 1);
67 }
68 
69 #endif
Base class for MFEM objects that participate in execution ordering but are not UserObjects.
void scale(MeshBase &mesh, const Real xs, const Real ys=0., const Real zs=0.)
MFEMComplexAuxKernel(const InputParameters &parameters)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
Declare the common parameters used by MFEM executed objects.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
static InputParameters validParams()
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
virtual std::optional< std::string > suppliedVariableName() const override
Return the variable name supplied by this object, or std::nullopt if none.
void complexScale(mfem::ParComplexGridFunction &a, const std::complex< mfem::real_t > scale={1.0, 0.0})
Method to scale a complex variable by a complex constant.
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.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:281
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...
const AuxVariableName _result_var_name
Name of complex auxvariable to store the result of the auxkernel in.