www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PorousFlowAddMaterialAction Class Reference

Action to automatically ensure that PorousFlowMaterials are correctly evaluated at either the qps, nodes, or both. More...

#include <PorousFlowAddMaterialAction.h>

Inheritance diagram for PorousFlowAddMaterialAction:
[legend]

Public Member Functions

 PorousFlowAddMaterialAction (const InputParameters &params)
 
virtual void act () override
 

Protected Member Functions

void createDependencyList ()
 Creates a set of all actions, kernels, etc to check material dependency against in order to determine whether to add nodal and/or qp materials. More...
 
bool isPFMaterialRequired (std::string pf_material_type, bool at_nodes)
 Check to see if the material with a given at_nodes parameter is required. More...
 
bool isPFMaterialPresent (AddMaterialAction *material, bool at_nodes)
 Check to see if the material with a given at_nodes parameter has already been included in the input file (to void duplicate material property errors) More...
 
void addPFMaterial (AddMaterialAction *material, bool at_nodes)
 Adds the material for the given at_nodes parameter. More...
 

Protected Attributes

std::string _dictator_name
 Name of the PorousFlowDictator. More...
 
std::set< std::string > _dependency_list
 List of kernels, actions etc that may depend on PorousFlow materials. More...
 
std::vector< AddMaterialAction * > _ama_materials
 List of all materials added in the input file by AddMaterialAction. More...
 
DependencyResolver< std::string > _deps
 All dependencies of kernels, auxkernels, materials, etc, are stored in _dependencies. More...
 

Detailed Description

Action to automatically ensure that PorousFlowMaterials are correctly evaluated at either the qps, nodes, or both.

This action works by checking all materials added in the input file. If a material is a valid PorousFlowMaterial, then it does one of the following: 1) If the at_nodes parameter has been set by the user, then it leaves that material alone (this assumes that the user has correctly added that material). 2) If the at_nodes parameter has not been set by the user, then the action checks to see if this material is required at the qps, nodes or both, and makes sure that the correct versions are added. 3) If a PorousFlowJoiner material is included in the input file, it does nothing (as the PorousFlowAddMaterialJoiner action will check for these and give a message that these materials are no longer required in the input file)

Definition at line 37 of file PorousFlowAddMaterialAction.h.

Constructor & Destructor Documentation

◆ PorousFlowAddMaterialAction()

PorousFlowAddMaterialAction::PorousFlowAddMaterialAction ( const InputParameters &  params)

Definition at line 35 of file PorousFlowAddMaterialAction.C.

36  : Action(params), PorousFlowDependencies()
37 {
38 }

Member Function Documentation

◆ act()

void PorousFlowAddMaterialAction::act ( )
overridevirtual

Definition at line 41 of file PorousFlowAddMaterialAction.C.

42 {
43  // Create the list of kernels, auxkernels, actions etc that each material may be
44  // required by
46 
47  // Get the list of materials that have been added
48  auto actions = _awh.getActions<AddMaterialAction>();
49 
50  for (auto & action : actions)
51  _ama_materials.push_back(const_cast<AddMaterialAction *>(action));
52 
53  for (auto & material : _ama_materials)
54  {
55  InputParameters & pars = material->getObjectParams();
56 
57  // Check if the material is a PorousFlow material
58  if (pars.isParamValid("pf_material_type"))
59  {
60  const std::string pf_material_type = pars.get<std::string>("pf_material_type");
61 
62  // PorousFlowJoiner materials are added automatically by the PorousFlowAddMaterialJoiner
63  // action, so no need to check these here
64  if (pf_material_type != "joiner")
65  {
66  // There are two possibilities that must be considered:
67  // 1) The parameter at_nodes has been set by the user. In this case, the material will
68  // be added as normal by AddMaterialAction
69  // 2) The parameter at_nodes has not been set by the user. In this case, this action
70  // will check to see if the material is required at the qps, at the nodes, or possibly both
71 
72  // Only chech the second possibility
73  if (!pars.isParamSetByUser("at_nodes"))
74  {
75  bool qp_material_required = false;
76 
77  // First, check the case at_nodes = false, as this is the default behaviour for the
78  // at_nodes parameter. Note: the local variable at_nodes is set to true, so the material
79  // is at the qps when !at_nodes
80  const bool at_nodes = true;
81 
82  if (isPFMaterialRequired(pf_material_type, !at_nodes))
83  {
84  // This material is required at the qps, so add it as normal (setting the paramter
85  // at_nodes = false for clarity)
86  pars.set<bool>("at_nodes") = !at_nodes;
87  qp_material_required = true;
88  }
89 
90  // Check if the material is required at the nodes as well and that it isn't already
91  // added in the input file. If it is needed and not already supplied, then it is added
92  // in one of two ways: 1) If the material wasn't also required at the qps (checked above),
93  // then we can simply set the at_nodes parameter to true. 2) If it was also required at
94  // the qps, then a new material action is required to be added to the action warehouse
95  if (isPFMaterialRequired(pf_material_type, at_nodes) &&
96  !isPFMaterialPresent(material, at_nodes))
97  {
98  if (!qp_material_required)
99  pars.set<bool>("at_nodes") = at_nodes;
100  else
101  addPFMaterial(material, at_nodes);
102  }
103  }
104  }
105  }
106  }
107 }
bool isPFMaterialPresent(AddMaterialAction *material, bool at_nodes)
Check to see if the material with a given at_nodes parameter has already been included in the input f...
void addPFMaterial(AddMaterialAction *material, bool at_nodes)
Adds the material for the given at_nodes parameter.
bool isPFMaterialRequired(std::string pf_material_type, bool at_nodes)
Check to see if the material with a given at_nodes parameter is required.
std::vector< AddMaterialAction * > _ama_materials
List of all materials added in the input file by AddMaterialAction.
void createDependencyList()
Creates a set of all actions, kernels, etc to check material dependency against in order to determine...

◆ addPFMaterial()

void PorousFlowAddMaterialAction::addPFMaterial ( AddMaterialAction *  material,
bool  at_nodes 
)
protected

Adds the material for the given at_nodes parameter.

Parameters
materialpointer to the material in the action warehouse
at_nodestrue if material is evaluates at the nodes, false otherwise

Definition at line 198 of file PorousFlowAddMaterialAction.C.

Referenced by act().

199 {
200  const std::string nodal_ext = at_nodes ? "_nodal" : "_qp";
201 
202  // Input parameters for the material that is being added
203  InputParameters & pars = material->getObjectParams();
204 
205  // PorousFlowMaterial type
206  const std::string pf_material_type = pars.get<std::string>("pf_material_type");
207  const std::string moose_object_type = material->getMooseObjectType();
208 
209  // If it is a material that also has a fluid phase, then extract that to add to name
210  std::string phase_str;
211  if (pars.isParamValid("phase"))
212  {
213  unsigned int phase = pars.get<unsigned int>("phase");
214  phase_str = "_phase" + Moose::stringify(phase);
215  }
216 
217  // Add material to the action warehouse
218  InputParameters action_params = _action_factory.getValidParams("AddMaterialAction");
219  action_params.set<ActionWarehouse *>("awh") = &_awh;
220 
221  // Setup action for passed in material type
222  action_params.set<std::string>("type") = moose_object_type;
223 
224  const std::string material_name = material->name() + phase_str + nodal_ext;
225 
226  auto action = MooseSharedNamespace::dynamic_pointer_cast<MooseObjectAction>(
227  _action_factory.create("AddMaterialAction", material_name, action_params));
228 
229  action->getObjectParams().applyParameters(pars);
230  action->getObjectParams().set<bool>("at_nodes") = at_nodes;
231 
232  _awh.addActionBlock(action);
233 }

◆ createDependencyList()

void PorousFlowAddMaterialAction::createDependencyList ( )
protected

Creates a set of all actions, kernels, etc to check material dependency against in order to determine whether to add nodal and/or qp materials.

Definition at line 110 of file PorousFlowAddMaterialAction.C.

Referenced by act().

111 {
112  // Unique list of kernels added in input file
113  auto kernels = _awh.getActions<AddKernelAction>();
114  for (auto & kernel : kernels)
115  _dependency_list.insert(kernel->getMooseObjectType());
116 
117  // Unique list of PorousFlowActions added in input file
118  auto actions = _awh.getActions<PorousFlowActionBase>();
119  for (auto & action : actions)
120  _dependency_list.insert(action->name());
121 
122  // Unique list of auxkernels added in input file
123  auto auxkernels = _awh.getActions<AddKernelAction>();
124  for (auto & auxkernel : auxkernels)
125  _dependency_list.insert(auxkernel->getMooseObjectType());
126 
127  // Unique list of postprocessors added in input file
128  auto postprocessors = _awh.getActions<AddPostprocessorAction>();
129  for (auto & postprocessor : postprocessors)
130  _dependency_list.insert(postprocessor->getMooseObjectType());
131 
132  // Unique list of userojects added in input file
133  auto userobjects = _awh.getActions<AddUserObjectAction>();
134  for (auto & userobject : userobjects)
135  _dependency_list.insert(userobject->getMooseObjectType());
136 
137  // Unique list of BCs added in input file
138  auto bcs = _awh.getActions<AddBCAction>();
139  for (auto & bc : bcs)
140  _dependency_list.insert(bc->getMooseObjectType());
141 }
std::set< std::string > _dependency_list
List of kernels, actions etc that may depend on PorousFlow materials.
Base class for PorousFlow actions.

◆ isPFMaterialPresent()

bool PorousFlowAddMaterialAction::isPFMaterialPresent ( AddMaterialAction *  material,
bool  at_nodes 
)
protected

Check to see if the material with a given at_nodes parameter has already been included in the input file (to void duplicate material property errors)

Parameters
materialpointer to the material in the action warehouse
at_nodestrue if material is evaluated at the nodes, false otherwise
Returns
true is the material is already added in the input file, false otherwise

Definition at line 161 of file PorousFlowAddMaterialAction.C.

Referenced by act().

162 {
163  // Need to check that it hasn't been added in the input file also to
164  // avoid a duplicate material property error
165  for (auto & ama_material : _ama_materials)
166  {
167  if (ama_material->name() != material->name() &&
168  ama_material->getMooseObjectType() == material->getMooseObjectType())
169  {
170  InputParameters & mat_params = ama_material->getObjectParams();
171  const bool mat_at_nodes = mat_params.get<bool>("at_nodes");
172 
173  InputParameters & pars = material->getObjectParams();
174 
175  // If the material isn't related to a fluid phase, it is present if
176  // its at_nodes parameter is equal to the given at_nodes
177  if (mat_at_nodes == at_nodes && !pars.isParamValid("phase"))
178  return true;
179 
180  // If the material is related to a fluid phase, it is present if
181  // its at_nodes parameter is equal to the given at_nodes, and its
182  // phase is equal to phase
183  if (pars.isParamValid("phase"))
184  {
185  const unsigned int phase = pars.get<unsigned int>("phase");
186 
187  if (mat_params.isParamValid("phase") && mat_params.get<unsigned int>("phase") == phase)
188  return true;
189  }
190  }
191  }
192 
193  // If all of these conditions aren't satisfied, then the material is already present
194  return false;
195 }
std::vector< AddMaterialAction * > _ama_materials
List of all materials added in the input file by AddMaterialAction.

◆ isPFMaterialRequired()

bool PorousFlowAddMaterialAction::isPFMaterialRequired ( std::string  pf_material_type,
bool  at_nodes 
)
protected

Check to see if the material with a given at_nodes parameter is required.

Parameters
at_nodestrue if material is evaluated at the nodes, false otherwise
Returns
true is the material is required, false otherwise

Definition at line 144 of file PorousFlowAddMaterialAction.C.

Referenced by act().

145 {
146  const std::string nodal_ext = at_nodes ? "_nodal" : "_qp";
147 
148  // Check if this material is required by looping through the list of dependencies
149  bool required = false;
150  for (auto item : _dependency_list)
151  {
152  required = _deps.dependsOn(item, pf_material_type + nodal_ext);
153  if (required)
154  break;
155  }
156 
157  return required;
158 }
std::set< std::string > _dependency_list
List of kernels, actions etc that may depend on PorousFlow materials.
DependencyResolver< std::string > _deps
All dependencies of kernels, auxkernels, materials, etc, are stored in _dependencies.

Member Data Documentation

◆ _ama_materials

std::vector<AddMaterialAction *> PorousFlowAddMaterialAction::_ama_materials
protected

List of all materials added in the input file by AddMaterialAction.

Definition at line 80 of file PorousFlowAddMaterialAction.h.

Referenced by act(), and isPFMaterialPresent().

◆ _dependency_list

std::set<std::string> PorousFlowAddMaterialAction::_dependency_list
protected

List of kernels, actions etc that may depend on PorousFlow materials.

Definition at line 78 of file PorousFlowAddMaterialAction.h.

Referenced by createDependencyList(), and isPFMaterialRequired().

◆ _deps

DependencyResolver<std::string> PorousFlowDependencies::_deps
protectedinherited

◆ _dictator_name

std::string PorousFlowAddMaterialAction::_dictator_name
protected

Name of the PorousFlowDictator.

Definition at line 76 of file PorousFlowAddMaterialAction.h.


The documentation for this class was generated from the following files: