https://mooseframework.inl.gov
MFEMSumAux.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 "MFEMSumAux.h"
13 #include "MFEMProblem.h"
14 
15 registerMooseObject("MooseApp", MFEMSumAux);
16 
19 {
21  params.addClassDescription(
22  "Calculates the sum of two variables sharing an FE space, each optionally scaled by a real "
23  "constant, and stores the result in a third.");
24  params.addRequiredParam<std::vector<VariableName>>("source_variables",
25  "The names of MFEM variables to sum over");
26  params.addParam<std::vector<mfem::real_t>>(
27  "scale_factors", "The factors to scale each MFEM variable by during summation");
28  return params;
29 }
30 
32  : MFEMAuxKernel(parameters),
33  _var_names(getParam<std::vector<VariableName>>("source_variables")),
34  _scale_factors(parameters.isParamValid("scale_factors")
35  ? getParam<std::vector<mfem::real_t>>("scale_factors")
36  : std::vector<mfem::real_t>(_var_names.size(), 1.0))
37 {
38  if (_var_names.size() != _scale_factors.size())
39  paramError("scale_factors",
40  "Number of MFEM variables to sum over is different from the number of provided "
41  "scale factors.");
42  for (const auto & var_name : _var_names)
43  {
44  const mfem::ParGridFunction * gf =
46  if (gf->ParFESpace() == _result_var.ParFESpace())
47  _summed_vars.push_back(gf);
48  else
49  paramError("source_variables",
50  "The MFEM variable ",
51  var_name,
52  " being summed has a different FESpace from ",
54  }
55 }
56 
57 void
59 {
60  // result = sum_i (_scale_factor_i * _summed_var_i)
61  _result_var = 0.0;
62  for (const auto i : index_range(_summed_vars))
64 }
65 
66 #endif
MFEMProblemData & getProblemData()
Method to get the current MFEMProblemData object storing the current data specifying the FE problem...
Definition: MFEMProblem.h:186
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:439
const std::vector< VariableName > & _var_names
Definition: MFEMSumAux.h:35
const AuxVariableName _result_var_name
Name of auxvariable to store the result of the auxkernel in.
Definition: MFEMAuxKernel.h:29
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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...
registerMooseObject("MooseApp", MFEMSumAux)
MFEMSumAux(const InputParameters &parameters)
Definition: MFEMSumAux.C:31
virtual void execute() override
Execute method.
Definition: MFEMSumAux.C:58
mfem::ParGridFunction & _result_var
Reference to result gridfunction.
Definition: MFEMAuxKernel.h:36
T * Get(const std::string &field_name) const
Returns a non-owning pointer to the field. This is guaranteed to return a non-null pointer...
std::vector< const mfem::ParGridFunction * > _summed_vars
Pointers to input variable gridfunctions.
Definition: MFEMSumAux.h:39
Class to construct an auxiliary solver used to update an auxvariable.
Definition: MFEMAuxKernel.h:20
static InputParameters validParams()
Definition: MFEMAuxKernel.C:16
const std::vector< mfem::real_t > _scale_factors
Definition: MFEMSumAux.h:37
MFEMProblem & getMFEMProblem()
Returns a reference to the MFEMProblem instance.
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...
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...
static InputParameters validParams()
Definition: MFEMSumAux.C:18
Moose::MFEM::GridFunctions gridfunctions
auto index_range(const T &sizable)