https://mooseframework.inl.gov
ElementIDOutputAction.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 // MOOSE includes
11 #include "ElementIDOutputAction.h"
12 #include "MooseMesh.h"
13 #include "FEProblemBase.h"
14 #include "AddOutputAction.h"
15 #include "Assembly.h"
16 
17 registerMooseAction("MooseApp", ElementIDOutputAction, "add_aux_kernel");
18 
21 {
23  params.addClassDescription(
24  "Action for copying extra element IDs into auxiliary variables for output.");
25  return params;
26 }
27 
29 
30 void
32 {
33  // Do nothing if the application does not have output
34  if (!_app.actionWarehouse().hasActions("add_output"))
35  return;
36 
37  if (_current_task == "add_aux_kernel")
38  {
39  const auto & output_actions = _app.actionWarehouse().getActionListByName("add_output");
40  for (const auto & act : output_actions)
41  {
42  // Extract the Output action
43  AddOutputAction * action = dynamic_cast<AddOutputAction *>(act);
44  if (!action)
45  continue;
46 
47  InputParameters & params = action->getObjectParams();
48  if (params.isParamValid("output_extra_element_ids") &&
49  params.get<bool>("output_extra_element_ids"))
50  {
51  bool has_element_id_names = params.isParamValid("extra_element_ids_to_output");
52  std::vector<std::string> element_id_names;
53  if (has_element_id_names)
54  element_id_names = params.get<std::vector<std::string>>("extra_element_ids_to_output");
55 
56  auto var_params = _factory.getValidParams("MooseVariableConstMonomial");
57  auto kernel_params = _factory.getValidParams("ExtraElementIDAux");
58  kernel_params.set<ExecFlagEnum>("execute_on") = EXEC_INITIAL;
59  for (unsigned int i = 0; i < _problem->assembly(0, 0).numExtraElemIntegers(); ++i)
60  {
61  auto & var_name = _mesh->getMesh().get_elem_integer_name(i);
62  if (!has_element_id_names ||
63  (std::find(element_id_names.begin(), element_id_names.end(), var_name) !=
64  element_id_names.end()))
65  {
66  // Create aux variables based on the extra element id name
67  _problem->addAuxVariable("MooseVariableConstMonomial", var_name, var_params);
68 
69  // Create aux kernels based on the extra element id name
70  kernel_params.set<AuxVariableName>("variable") = var_name;
71  kernel_params.set<std::vector<ExtraElementIDName>>("extra_id_name") = {var_name};
72  _problem->addAuxKernel("ExtraElementIDAux", "_output_" + var_name, kernel_params);
73  }
74  }
75  }
76  }
77  }
78 }
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
registerMooseAction("MooseApp", ElementIDOutputAction, "add_aux_kernel")
virtual void act()
Method to add objects to the simulation or perform other setup tasks.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition: Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const std::list< Action * > & getActionListByName(const std::string &task) const
Retrieve a constant list of Action pointers associated with the passed in task.
Base class for actions.
Definition: Action.h:33
Factory & _factory
The Factory associated with the MooseApp.
Action for creating output objects.
static InputParameters validParams()
Definition: Action.C:24
InputParameters & getObjectParams()
Retrieve the parameters of the object to be created by this action.
static InputParameters validParams()
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition: Action.h:162
ActionWarehouse & actionWarehouse()
Return a writable reference to the ActionWarehouse associated with this app.
Definition: MooseApp.h:237
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
std::shared_ptr< MooseMesh > & _mesh
Definition: Action.h:164
bool hasActions(const std::string &task) const
Check if Actions associated with passed in task exist.
ElementIDOutputAction(const InputParameters &parameters)
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...
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:168
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:28