www.mooseframework.org
PorousFlowAddMaterialJoiner.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 
11 #include "AddMaterialAction.h"
12 #include "ActionWarehouse.h"
13 #include "FEProblem.h"
14 #include "Material.h"
15 #include "UserObject.h"
16 #include "PorousFlowDictator.h"
17 
18 registerMooseAction("PorousFlowApp", PorousFlowAddMaterialJoiner, "add_joiners");
19 
20 template <>
21 InputParameters
23 {
24  InputParameters params = validParams<Action>();
25  params.addClassDescription(
26  "Adds PorousFlowJoiner materials as required for each phase-dependent property");
27  return params;
28 }
29 
31  : Action(params), _already_joined()
32 {
33 }
34 
35 void
37 {
38  // This task only runs after the UserObject and material actions have run,
39  // so we can get the name of the PorousFlowDictator UserObject and all material
40  // types
41  if (_current_task == "add_joiners")
42  {
43  // Get the user objects that have been added to get the name of the PorousFlowDictator
44  std::vector<UserObject *> userobjects;
45  _problem->theWarehouse()
46  .query()
47  .condition<AttribSystem>("UserObject")
48  .condition<AttribThread>(0)
49  .queryInto(userobjects);
50  for (auto & userobject : userobjects)
51  if (dynamic_cast<PorousFlowDictator *>(userobject))
52  _dictator_name = userobject->name();
53 
54  // Get the list of materials that have been added
55  auto materials = _problem->getMaterialWarehouse().getObjects();
56  for (auto & mat : materials)
57  {
58  const InputParameters & params = mat->parameters();
59 
60  // Only check PorousFlowMaterials
61  if (params.isParamValid("pf_material_type"))
62  {
63  const std::string pf_material_type = params.get<std::string>("pf_material_type");
64 
65  // Check if the material is evaluated at the nodes or qps
66  const bool at_nodes = params.get<bool>("at_nodes");
67 
68  // Add joiner material for fluid properties materials
69  if (pf_material_type == "fluid_properties")
70  {
71  // Key the addition of the joiner off the phase 0 fluid so it is only added once
72  if (params.get<unsigned int>("phase") == 0)
73  {
74  // Join density and viscosity if they are calculated
75  if (params.get<bool>("compute_density_and_viscosity"))
76  {
77  if (at_nodes)
78  {
79  addJoiner(at_nodes,
80  "PorousFlow_fluid_phase_density_nodal",
81  "PorousFlow_density_nodal_all");
82  addJoiner(at_nodes, "PorousFlow_viscosity_nodal", "PorousFlow_viscosity_nodal_all");
83  }
84  else
85  {
86  addJoiner(
87  at_nodes, "PorousFlow_fluid_phase_density_qp", "PorousFlow_density_qp_all");
88  addJoiner(at_nodes, "PorousFlow_viscosity_qp", "PorousFlow_viscosity_qp_all");
89  }
90  }
91 
92  // Join enthalpy if it is calculated
93  if (params.get<bool>("compute_enthalpy"))
94  {
95  if (at_nodes)
96  addJoiner(at_nodes,
97  "PorousFlow_fluid_phase_enthalpy_nodal",
98  "PorousFlow_enthalpy_nodal_all");
99  else
100  addJoiner(
101  at_nodes, "PorousFlow_fluid_phase_enthalpy_qp", "PorousFlow_enthalpy_qp_all");
102  }
103 
104  // Join internal energy if it is calculated
105  if (params.get<bool>("compute_internal_energy"))
106  {
107  if (at_nodes)
108  addJoiner(at_nodes,
109  "PorousFlow_fluid_phase_internal_energy_nodal",
110  "PorousFlow_internal_energy_nodal_all");
111  else
112  addJoiner(at_nodes,
113  "PorousFlow_fluid_phase_internal_energy_qp",
114  "PorousFlow_internal_energy_qp_all");
115  }
116  }
117  }
118 
119  // Add joiner materials for relative permeability materials
120  if (pf_material_type == "relative_permeability")
121  {
122  // Key the addition of the joiner off the phase 0 fluid so it is only added once
123  if (params.get<unsigned int>("phase") == 0)
124  {
125  if (at_nodes)
126  addJoiner(at_nodes,
127  "PorousFlow_relative_permeability_nodal",
128  "PorousFlow_relative_permeability_nodal_all");
129  else
130  addJoiner(at_nodes,
131  "PorousFlow_relative_permeability_qp",
132  "PorousFlow_relative_permeability_qp_all");
133  }
134  }
135  }
136  }
137  }
138 }
139 
140 void
142  const std::string & material_property,
143  const std::string & output_name)
144 {
145  bool is_joined = false;
146 
147  // Check if this material is already joined
148  if (std::find(_already_joined.begin(), _already_joined.end(), material_property) !=
149  _already_joined.end())
150  is_joined = true;
151 
152  if (hasJoiner(material_property))
153  is_joined = true;
154 
155  if (!is_joined)
156  {
157  std::string material_type = "PorousFlowJoiner";
158  InputParameters params = _factory.getValidParams(material_type);
159  params.set<UserObjectName>("PorousFlowDictator") = _dictator_name;
160  params.set<bool>("at_nodes") = at_nodes;
161  params.set<std::string>("material_property") = material_property;
162  _problem->addMaterial(material_type, output_name, params);
163 
164  // Add material to the already joined list
165  _already_joined.push_back(material_property);
166  }
167 }
168 
169 bool
171 {
172  // Get the list of materials in the input file
173  auto actions = _awh.getActions<AddMaterialAction>();
174 
175  for (auto & action : actions)
176  {
177  AddMaterialAction * material = const_cast<AddMaterialAction *>(action);
178 
179  if (material->getMooseObjectType() == "PorousFlowJoiner")
180  {
181  // If a PorousFlowJoiner material has been included in the input file,
182  // let the user know that it should be removed
183  mooseDeprecated("PorousFlowJoiner materials are no longer required in the input "
184  "file.\nPlease remove all PorousFlowJoiner materials from this input file to "
185  "get rid of this warning");
186 
187  const std::string joiner_property =
188  material->getObjectParams().get<std::string>("material_property");
189 
190  // Check if the given material property is joined by this material
191  if (joiner_property == property)
192  return true;
193  }
194  }
195 
196  // If no PorousFlowJoiner materials matched property, return false
197  return false;
198 }
PorousFlowDictator.h
registerMooseAction
registerMooseAction("PorousFlowApp", PorousFlowAddMaterialJoiner, "add_joiners")
PorousFlowAddMaterialJoiner::PorousFlowAddMaterialJoiner
PorousFlowAddMaterialJoiner(const InputParameters &params)
Definition: PorousFlowAddMaterialJoiner.C:30
PorousFlowAddMaterialJoiner::_dictator_name
std::string _dictator_name
Name of the PorousFlowDictator.
Definition: PorousFlowAddMaterialJoiner.h:50
validParams< PorousFlowAddMaterialJoiner >
InputParameters validParams< PorousFlowAddMaterialJoiner >()
Definition: PorousFlowAddMaterialJoiner.C:22
PorousFlowAddMaterialJoiner::act
virtual void act() override
Definition: PorousFlowAddMaterialJoiner.C:36
PorousFlowAddMaterialJoiner.h
PorousFlowAddMaterialJoiner::_already_joined
std::vector< std::string > _already_joined
Vector of already joined materials (to avoid joining them again)
Definition: PorousFlowAddMaterialJoiner.h:53
PorousFlowAddMaterialJoiner
Action to programatically add PorousFlowJoiner materials without having to manually enter them in the...
Definition: PorousFlowAddMaterialJoiner.h:23
PorousFlowAddMaterialJoiner::hasJoiner
bool hasJoiner(std::string property)
Helper method to determine if a PorousFLowJoiner material is already present in the input file for th...
Definition: PorousFlowAddMaterialJoiner.C:170
PorousFlowAddMaterialJoiner::addJoiner
void addJoiner(bool at_nodes, const std::string &material_property, const std::string &output_name)
Adds a PorousFlowJoiner for the given material property.
Definition: PorousFlowAddMaterialJoiner.C:141