www.mooseframework.org
AddElementalFieldAction.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 // MOOSE includes
12 #include "FEProblem.h"
13 #include "MooseMesh.h"
14 
15 #include "libmesh/fe.h"
16 
17 registerMooseAction("MooseApp", AddElementalFieldAction, "add_elemental_field_variable");
18 
19 template <>
22 {
24  params.addParam<std::vector<SubdomainName>>("block", "The block id where this object lives.");
25 
26  return params;
27 }
28 
30 
31 void
33 {
34  std::set<SubdomainID> blocks;
35  std::vector<SubdomainName> block_param = getParam<std::vector<SubdomainName>>("block");
36  for (const auto & subdomain_name : block_param)
37  {
38  SubdomainID blk_id = _problem->mesh().getSubdomainID(subdomain_name);
39  blocks.insert(blk_id);
40  }
41 
42  FEType fe_type(CONSTANT, MONOMIAL);
43 
44  std::string variable = name();
45 
46  if (blocks.empty())
47  _problem->addAuxVariable(variable, fe_type);
48  else
49  _problem->addAuxVariable(variable, fe_type, &blocks);
50 }
registerMooseAction("MooseApp", AddElementalFieldAction, "add_elemental_field_variable")
const std::string & name() const
The name of the action.
Definition: Action.h:76
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Base class for actions.
Definition: Action.h:35
subdomain_id_type SubdomainID
InputParameters validParams< AddElementalFieldAction >()
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
AddElementalFieldAction(InputParameters params)
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:216
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
InputParameters validParams< Action >()
Definition: Action.C:22