www.mooseframework.org
DisplayGhostingAction.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 #include "DisplayGhostingAction.h"
11 #include "FEProblemBase.h"
12 
13 registerMooseAction("MooseApp", DisplayGhostingAction, "add_aux_variable");
14 
15 registerMooseAction("MooseApp", DisplayGhostingAction, "add_aux_kernel");
16 
17 registerMooseAction("MooseApp", DisplayGhostingAction, "add_user_object");
18 
21 {
23  params.addParam<bool>("output_ghosting", false, "Boolean to turn on ghosting auxiliary fields");
24  params.addParam<bool>("include_local_in_ghosting",
25  false,
26  "Boolean used to toggle on the inclusion of local elements along with the "
27  "ghost elements for a complete partition map");
28 
29  params.addClassDescription(
30  "Action to setup AuxVariables and AuxKernels to display ghosting when running in parallel");
31 
32  return params;
33 }
34 
36  : Action(params),
37  _display_ghosting(getParam<bool>("output_ghosting")),
38  _include_local(getParam<bool>("include_local_in_ghosting"))
39 {
40 }
41 
42 void
44 {
45  if (_display_ghosting == false)
46  return;
47 
48  auto n_procs = _app.n_processors();
49 
50  if (_current_task == "add_aux_variable")
51  {
52  auto params = _factory.getValidParams("MooseVariableConstMonomial");
53  params.set<MooseEnum>("order") = "CONSTANT";
54  params.set<MooseEnum>("family") = "MONOMIAL";
55 
56  for (unsigned int i = 0; i < 2; ++i)
57  {
58  std::string var_name_base = (i == 0 ? "geometric" : "algebraic");
59  for (decltype(n_procs) proc_id = 0; proc_id < n_procs; ++proc_id)
60  _problem->addAuxVariable(
61  "MooseVariableConstMonomial", var_name_base + std::to_string(proc_id), params);
62  }
63  }
64  else if (_current_task == "add_aux_kernel")
65  {
66  for (unsigned int i = 0; i < 2; ++i)
67  {
68  std::string aux_kernel_name_base = i == 0 ? "geometric" : "algebraic";
69  for (decltype(n_procs) proc_id = 0; proc_id < n_procs; ++proc_id)
70  {
71  std::string name = aux_kernel_name_base + std::to_string(proc_id);
72 
73  auto params = _factory.getValidParams("GhostingAux");
74  params.set<processor_id_type>("pid") = proc_id;
75  params.set<MooseEnum>("functor_type") = aux_kernel_name_base;
76  params.set<UserObjectName>("ghost_uo") = "ghost_uo";
77  params.set<AuxVariableName>("variable") = name;
78  params.set<bool>("include_local_elements") = _include_local;
79 
80  _problem->addAuxKernel("GhostingAux", name, params);
81  }
82  }
83  }
84  else if (_current_task == "add_user_object")
85  {
86  auto params = _factory.getValidParams("GhostingUserObject");
87  _problem->addUserObject("GhostingUserObject", "ghost_uo", params);
88  }
89 }
registerMooseAction("MooseApp", DisplayGhostingAction, "add_aux_variable")
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:67
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
Base class for actions.
Definition: Action.h:38
Factory & _factory
The Factory associated with the MooseApp.
uint8_t processor_id_type
processor_id_type n_processors() const
static InputParameters validParams()
Definition: Action.C:24
Class to setup multiple AuxVariables and AuxKernels to display the ghosting when running in parallel...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition: Action.h:173
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
DisplayGhostingAction(const InputParameters &params)
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:179
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...
static InputParameters validParams()