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 33 of file PorousFlowAddMaterialAction.C.

34  : Action(params), PorousFlowDependencies()
35 {
36 }

Member Function Documentation

◆ act()

void PorousFlowAddMaterialAction::act ( )
overridevirtual

Definition at line 39 of file PorousFlowAddMaterialAction.C.

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

Referenced by act().

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

◆ 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 108 of file PorousFlowAddMaterialAction.C.

Referenced by act().

109 {
110  // Unique list of kernels added in input file
111  auto kernels = _awh.getActions<AddKernelAction>();
112  for (auto & kernel : kernels)
113  _dependency_list.insert(kernel->getMooseObjectType());
114 
115  // Unique list of PorousFlowActions added in input file
116  auto actions = _awh.getActions<PorousFlowActionBase>();
117  for (auto & action : actions)
118  _dependency_list.insert(action->name());
119 
120  // Unique list of auxkernels added in input file
121  auto auxkernels = _awh.getActions<AddKernelAction>();
122  for (auto & auxkernel : auxkernels)
123  _dependency_list.insert(auxkernel->getMooseObjectType());
124 
125  // Unique list of postprocessors added in input file
126  auto postprocessors = _awh.getActions<AddPostprocessorAction>();
127  for (auto & postprocessor : postprocessors)
128  _dependency_list.insert(postprocessor->getMooseObjectType());
129 }
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 149 of file PorousFlowAddMaterialAction.C.

Referenced by act().

150 {
151  // Need to check that it hasn't been added in the input file also to
152  // avoid a duplicate material property error
153  for (auto & ama_material : _ama_materials)
154  {
155  if (ama_material->name() != material->name() &&
156  ama_material->getMooseObjectType() == material->getMooseObjectType())
157  {
158  InputParameters & mat_params = ama_material->getObjectParams();
159  const bool mat_at_nodes = mat_params.get<bool>("at_nodes");
160 
161  InputParameters & pars = material->getObjectParams();
162 
163  // If the material isn't related to a fluid phase, it is present if
164  // its at_nodes parameter is equal to the given at_nodes
165  if (mat_at_nodes == at_nodes && !pars.isParamValid("phase"))
166  return true;
167 
168  // If the material is related to a fluid phase, it is present if
169  // its at_nodes parameter is equal to the given at_nodes, and its
170  // phase is equal to phase
171  if (pars.isParamValid("phase"))
172  {
173  const unsigned int phase = pars.get<unsigned int>("phase");
174 
175  if (mat_params.isParamValid("phase") && mat_params.get<unsigned int>("phase") == phase)
176  return true;
177  }
178  }
179  }
180 
181  // If all of these conditions aren't satisfied, then the material is already present
182  return false;
183 }
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 132 of file PorousFlowAddMaterialAction.C.

Referenced by act().

133 {
134  const std::string nodal_ext = at_nodes ? "_nodal" : "_qp";
135 
136  // Check if this material is required by looping through the list of dependencies
137  bool required = false;
138  for (auto item : _dependency_list)
139  {
140  required = _deps.dependsOn(item, pf_material_type + nodal_ext);
141  if (required)
142  break;
143  }
144 
145  return required;
146 }
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

All dependencies of kernels, auxkernels, materials, etc, are stored in _dependencies.

Definition at line 38 of file PorousFlowDependencies.h.

Referenced by PorousFlowFullySaturated::act(), PorousFlowSinglePhaseBase::act(), PorousFlowUnsaturated::act(), PorousFlowBasicTHM::act(), isPFMaterialRequired(), and PorousFlowDependencies::PorousFlowDependencies().

◆ _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: