https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
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
71void
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
registerMooseObject("MooseApp", MFEMComplexSumAux)
Real scale
Definition MortarUtils.C:62
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
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.
Class to construct an auxiliary solver used to update a complex auxvariable.
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 AuxVariableName _result_var_name
Name of complex auxvariable to store the result of the auxkernel in.
mfem::ParComplexGridFunction & _result_var
Reference to result complex gridfunction.
static InputParameters validParams()
const std::vector< VariableName > & _var_names
const std::vector< mfem::real_t > _scale_factors_real
virtual void execute() override
Perform the main work for this object.
const std::vector< mfem::real_t > _scale_factors_imag
static InputParameters validParams()
MFEMComplexSumAux(const InputParameters &parameters)
std::vector< const mfem::ParComplexGridFunction * > _summed_vars
Pointers to input variable gridfunctions.
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition MFEMObject.h:45
std::shared_ptr< mfem::ParComplexGridFunction > getComplexGridFunction(const std::string &name)
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:457