Permalink
Browse files

Merge pull request #12811 from cpgr/pf12762

Make sure PorousFlow actions add all versions of materials as needed
  • Loading branch information...
permcody committed Feb 4, 2019
2 parents 38a2cbf + 4b295dd commit 1bc46a1884eebdeb3eb729694d55530b815fd539
Showing with 1,192 additions and 319 deletions.
  1. +41 −6 modules/porous_flow/include/actions/PorousFlowActionBase.h
  2. +4 −2 modules/porous_flow/include/actions/PorousFlowBasicTHM.h
  3. +5 −1 modules/porous_flow/include/actions/PorousFlowFullySaturated.h
  4. +7 −4 modules/porous_flow/include/actions/PorousFlowSinglePhaseBase.h
  5. +9 −2 modules/porous_flow/include/actions/PorousFlowUnsaturated.h
  6. +69 −2 modules/porous_flow/src/actions/PorousFlowActionBase.C
  7. +6 −0 modules/porous_flow/src/actions/PorousFlowAddMaterialAction.C
  8. +43 −34 modules/porous_flow/src/actions/PorousFlowBasicTHM.C
  9. +110 −90 modules/porous_flow/src/actions/PorousFlowFullySaturated.C
  10. +84 −63 modules/porous_flow/src/actions/PorousFlowSinglePhaseBase.C
  11. +120 −102 modules/porous_flow/src/actions/PorousFlowUnsaturated.C
  12. +15 −0 modules/porous_flow/src/utils/PorousFlowDependencies.C
  13. +132 −0 modules/porous_flow/test/tests/actions/basicthm_h.i
  14. +157 −0 modules/porous_flow/test/tests/actions/basicthm_hm.i
  15. +158 −0 modules/porous_flow/test/tests/actions/basicthm_th.i
  16. +192 −0 modules/porous_flow/test/tests/actions/basicthm_thm.i
  17. BIN modules/porous_flow/test/tests/actions/gold/basicthm_h_out.e
  18. BIN modules/porous_flow/test/tests/actions/gold/basicthm_hm_out.e
  19. BIN modules/porous_flow/test/tests/actions/gold/basicthm_th_out.e
  20. BIN modules/porous_flow/test/tests/actions/gold/basicthm_thm_out.e
  21. +40 −8 modules/porous_flow/test/tests/actions/tests
  22. +0 −5 modules/porous_flow/test/tests/dispersion/diff01_action.i
@@ -20,10 +20,16 @@ template <>
InputParameters validParams<PorousFlowActionBase>();

/**
* Base class for PorousFlow actions. This act() method simply
* defines the name of the PorousFlowDictator. However, this
* class also contains a number of utility functions that may
* be used by derived classes
* Base class for PorousFlow actions. This act() method makes consistency checks and
* calls several methods that should be implemented in derived classes. This class also
* contains a number of utility functions that may be used by derived classes.
*
* Derived classes should typically only override the following methods:
* * addUserObjects()
* * addMaterialDependencies()
* * addMaterials()
* * addAuxObjects()
* * addKernels()
*/
class PorousFlowActionBase : public Action, public PorousFlowDependencies
{
@@ -34,11 +40,11 @@ class PorousFlowActionBase : public Action, public PorousFlowDependencies

protected:
/**
* List of Kernels, AuxKernels, Materials, etc, to be added.
* List of Kernels, AuxKernels, Materials, etc, that are added in this input file.
* This list will be used to determine what Materials need
* to be added. Actions may add or remove things from this list
*/
std::vector<std::string> _objects_to_add;
std::vector<std::string> _included_objects;

/// The name of the PorousFlowDictator object to be added
const std::string _dictator_name;
@@ -78,11 +84,40 @@ class PorousFlowActionBase : public Action, public PorousFlowDependencies
/// Coordinate system of the simulation (eg RZ, XYZ, etc)
Moose::CoordinateSystemType _coord_system;

/// Flag to denote if the simulation is transient
bool _transient;

/**
* Add the PorousFlowDictator object
*/
virtual void addDictator() = 0;

/**
* Add all other UserObjects
*/
virtual void addUserObjects();

/**
* Add all AuxVariables and AuxKernels
*/
virtual void addAuxObjects();

/**
* Add all Kernels
*/
virtual void addKernels();

/**
* Add all material dependencies so that the correct
* version of each material can be added
*/
virtual void addMaterialDependencies();

/**
* Add all Materials
*/
virtual void addMaterials();

/**
* Add an AuxVariable and AuxKernel to calculate saturation
* @param phase Saturation for this fluid phase
@@ -28,9 +28,11 @@ class PorousFlowBasicTHM : public PorousFlowSinglePhaseBase
public:
PorousFlowBasicTHM(const InputParameters & params);

virtual void act() override;

protected:
virtual void addKernels() override;
virtual void addMaterialDependencies() override;
virtual void addMaterials() override;

// Whether to multiply the fluid kernels by the fluid density
const bool _multiply_by_density;
};
@@ -25,7 +25,11 @@ class PorousFlowFullySaturated : public PorousFlowSinglePhaseBase
public:
PorousFlowFullySaturated(const InputParameters & params);

virtual void act() override;
protected:
virtual void addKernels() override;
virtual void addMaterialDependencies() override;
virtual void addMaterials() override;
virtual void addUserObjects() override;
};

#endif // POROUSFLOWFULLYSATURATED_H
@@ -25,10 +25,12 @@ class PorousFlowSinglePhaseBase : public PorousFlowActionBase
public:
PorousFlowSinglePhaseBase(const InputParameters & params);

virtual void act() override;

protected:
virtual void addDictator() override;
virtual void addKernels() override;
virtual void addAuxObjects() override;
virtual void addMaterialDependencies() override;
virtual void addMaterials() override;

/// Porepressure NonlinearVariable name
const NonlinearVariableName _pp_var;
@@ -41,8 +43,9 @@ class PorousFlowSinglePhaseBase : public PorousFlowActionBase
ThermoHydroMechanical
} _coupling_type;

/// Whether steady or transient simulation
const enum class SimulationTypeChoiceEnum { STEADY, TRANSIENT } _simulation_type;
/// Flags to indicate whether thermal or mechanical effects are included
const bool _thermal;
const bool _mechanical;

/// Name of the fluid-properties UserObject
const UserObjectName & _fp;
@@ -27,9 +27,13 @@ class PorousFlowUnsaturated : public PorousFlowSinglePhaseBase
public:
PorousFlowUnsaturated(const InputParameters & params);

virtual void act() override;

protected:
virtual void addKernels() override;
virtual void addAuxObjects() override;
virtual void addMaterialDependencies() override;
virtual void addMaterials() override;
virtual void addUserObjects() override;

/// Add an Aux Variable to record saturation
const bool _add_saturation_aux;

@@ -47,6 +51,9 @@ class PorousFlowUnsaturated : public PorousFlowSinglePhaseBase

/// Residual saturation to use in the relative permeability expressions
const Real _s_res;

/// Name of the capillary pressure UserObject
const std::string _capillary_pressure_name;
};

#endif // POROUSFLOWUNSATURATED_H
@@ -13,6 +13,9 @@
#include "MooseMesh.h"
#include "libmesh/string_to_enum.h"
#include "Conversion.h"
#include "AddKernelAction.h"
#include "AddPostprocessorAction.h"
#include "AddBCAction.h"

template <>
InputParameters
@@ -80,7 +83,7 @@ validParams<PorousFlowActionBase>()
PorousFlowActionBase::PorousFlowActionBase(const InputParameters & params)
: Action(params),
PorousFlowDependencies(),
_objects_to_add(),
_included_objects(),
_dictator_name(getParam<std::string>("dictator_name")),
_num_aqueous_equilibrium(getParam<unsigned int>("number_aqueous_equilibrium")),
_num_aqueous_kinetic(getParam<unsigned int>("number_aqueous_kinetic")),
@@ -102,6 +105,10 @@ PorousFlowActionBase::PorousFlowActionBase(const InputParameters & params)
void
PorousFlowActionBase::act()
{
// Check if the simulation is transient (note: can't do this in the ctor)
_transient = _problem->isTransient();

// Make sure that all mesh subdomains have the same coordinate system
const auto & all_subdomains = _problem->mesh().meshSubdomains();
if (all_subdomains.empty())
mooseError("No subdomains found");
@@ -111,8 +118,68 @@ PorousFlowActionBase::act()
mooseError(
"The PorousFlow Actions require all subdomains to have the same coordinate system.");

// Note: this must be called before addMaterials!
addMaterialDependencies();

// Make the vector of added objects unique
std::sort(_included_objects.begin(), _included_objects.end());
_included_objects.erase(std::unique(_included_objects.begin(), _included_objects.end()),
_included_objects.end());

if (_current_task == "add_user_object")
addDictator();
addUserObjects();

if (_current_task == "add_aux_variable" || _current_task == "add_aux_kernel")
addAuxObjects();

if (_current_task == "add_kernel")
addKernels();

if (_current_task == "add_material")
addMaterials();
}

void
PorousFlowActionBase::addMaterialDependencies()
{
// Check to see if there are any other PorousFlow objects like BCs that
// may require specific versions of materials added using this action

// Unique list of auxkernels added in input file
auto auxkernels = _awh.getActions<AddKernelAction>();
for (auto & auxkernel : auxkernels)
_included_objects.push_back(auxkernel->getMooseObjectType());

// Unique list of postprocessors added in input file
auto postprocessors = _awh.getActions<AddPostprocessorAction>();
for (auto & postprocessor : postprocessors)
_included_objects.push_back(postprocessor->getMooseObjectType());

// Unique list of BCs added in input file
auto bcs = _awh.getActions<AddBCAction>();
for (auto & bc : bcs)
_included_objects.push_back(bc->getMooseObjectType());
}

void
PorousFlowActionBase::addUserObjects()
{
addDictator();
}

void
PorousFlowActionBase::addAuxObjects()
{
}

void
PorousFlowActionBase::addKernels()
{
}

void
PorousFlowActionBase::addMaterials()
{
}

void
@@ -12,6 +12,7 @@
#include "AddMaterialAction.h"
#include "AddPostprocessorAction.h"
#include "AddUserObjectAction.h"
#include "AddBCAction.h"
#include "PorousFlowActionBase.h"
#include "ActionWarehouse.h"
#include "ActionFactory.h"
@@ -132,6 +133,11 @@ PorousFlowAddMaterialAction::createDependencyList()
auto userobjects = _awh.getActions<AddUserObjectAction>();
for (auto & userobject : userobjects)
_dependency_list.insert(userobject->getMooseObjectType());

// Unique list of BCs added in input file
auto bcs = _awh.getActions<AddBCAction>();
for (auto & bc : bcs)
_dependency_list.insert(bc->getMooseObjectType());
}

bool
@@ -55,32 +55,38 @@ PorousFlowBasicTHM::PorousFlowBasicTHM(const InputParameters & params)
if (_num_mass_fraction_vars != 0)
mooseError("PorousFlowBasicTHM can only be used for a single-component fluid, so that no "
"mass-fraction variables should be provided");
_objects_to_add.push_back("PorousFlowFullySaturatedDarcyBase");
if (_simulation_type == SimulationTypeChoiceEnum::TRANSIENT)
_objects_to_add.push_back("PorousFlowFullySaturatedMassTimeDerivative");
if (_coupling_type == CouplingTypeEnum::ThermoHydro ||
_coupling_type == CouplingTypeEnum::ThermoHydroMechanical)
_objects_to_add.push_back("PorousFlowFullySaturatedHeatAdvection");
}

void
PorousFlowBasicTHM::act()
PorousFlowBasicTHM::addMaterialDependencies()
{
PorousFlowSinglePhaseBase::act();
PorousFlowSinglePhaseBase::addMaterialDependencies();

// add the kernels
if (_current_task == "add_kernel")
{
std::string kernel_name = "PorousFlowBasicTHM_DarcyFlow";
std::string kernel_type = "PorousFlowFullySaturatedDarcyBase";
InputParameters params = _factory.getValidParams(kernel_type);
params.set<UserObjectName>("PorousFlowDictator") = _dictator_name;
params.set<RealVectorValue>("gravity") = _gravity;
params.set<bool>("multiply_by_density") = _multiply_by_density;
params.set<NonlinearVariableName>("variable") = _pp_var;
_problem->addKernel(kernel_type, kernel_name, params);
}
if (_current_task == "add_kernel" && _simulation_type == SimulationTypeChoiceEnum::TRANSIENT)
// Add necessary objects to list of PorousFlow objects added by this action
_included_objects.push_back("PorousFlowFullySaturatedDarcyBase");

if (_transient)
_included_objects.push_back("PorousFlowFullySaturatedMassTimeDerivative");

if (_thermal)
_included_objects.push_back("PorousFlowFullySaturatedHeatAdvection");
}

void
PorousFlowBasicTHM::addKernels()
{
PorousFlowSinglePhaseBase::addKernels();

std::string kernel_name = "PorousFlowBasicTHM_DarcyFlow";
std::string kernel_type = "PorousFlowFullySaturatedDarcyBase";
InputParameters params = _factory.getValidParams(kernel_type);
params.set<UserObjectName>("PorousFlowDictator") = _dictator_name;
params.set<RealVectorValue>("gravity") = _gravity;
params.set<bool>("multiply_by_density") = _multiply_by_density;
params.set<NonlinearVariableName>("variable") = _pp_var;
_problem->addKernel(kernel_type, kernel_name, params);

if (_transient)
{
std::string kernel_name = "PorousFlowBasicTHM_MassTimeDerivative";
std::string kernel_type = "PorousFlowFullySaturatedMassTimeDerivative";
@@ -93,9 +99,7 @@ PorousFlowBasicTHM::act()
_problem->addKernel(kernel_type, kernel_name, params);
}

if ((_coupling_type == CouplingTypeEnum::ThermoHydro ||
_coupling_type == CouplingTypeEnum::ThermoHydroMechanical) &&
_current_task == "add_kernel")
if (_thermal)
{
std::string kernel_name = "PorousFlowBasicTHM_HeatAdvection";
std::string kernel_type = "PorousFlowFullySaturatedHeatAdvection";
@@ -105,9 +109,14 @@ PorousFlowBasicTHM::act()
params.set<RealVectorValue>("gravity") = _gravity;
_problem->addKernel(kernel_type, kernel_name, params);
}
}

// add Materials
if (_deps.dependsOn(_objects_to_add, "pressure_saturation_qp") && _current_task == "add_material")
void
PorousFlowBasicTHM::addMaterials()
{
PorousFlowSinglePhaseBase::addMaterials();

if (_deps.dependsOn(_included_objects, "pressure_saturation_qp"))
{
std::string material_type = "PorousFlow1PhaseFullySaturated";
InputParameters params = _factory.getValidParams(material_type);
@@ -117,8 +126,8 @@ PorousFlowBasicTHM::act()
params.set<bool>("at_nodes") = false;
_problem->addMaterial(material_type, material_name, params);
}
if (_deps.dependsOn(_objects_to_add, "pressure_saturation_nodal") &&
_current_task == "add_material")

if (_deps.dependsOn(_included_objects, "pressure_saturation_nodal"))
{
std::string material_type = "PorousFlow1PhaseFullySaturated";
InputParameters params = _factory.getValidParams(material_type);
@@ -129,14 +138,14 @@ PorousFlowBasicTHM::act()
_problem->addMaterial(material_type, material_name, params);
}

if ((_deps.dependsOn(_objects_to_add, "volumetric_strain_qp") ||
_deps.dependsOn(_objects_to_add, "volumetric_strain_nodal")) &&
(_coupling_type == CouplingTypeEnum::HydroMechanical ||
_coupling_type == CouplingTypeEnum::ThermoHydroMechanical))
if ((_deps.dependsOn(_included_objects, "volumetric_strain_qp") ||
_deps.dependsOn(_included_objects, "volumetric_strain_nodal")) &&
_mechanical)
addVolumetricStrainMaterial(_coupled_displacements, false);

if (_deps.dependsOn(_objects_to_add, "relative_permeability_qp"))
if (_deps.dependsOn(_included_objects, "relative_permeability_qp"))
addRelativePermeabilityCorey(false, 0, 0.0, 0.0, 0.0);
if (_deps.dependsOn(_objects_to_add, "relative_permeability_nodal"))

if (_deps.dependsOn(_included_objects, "relative_permeability_nodal"))
addRelativePermeabilityCorey(true, 0, 0.0, 0.0, 0.0);
}
Oops, something went wrong.

0 comments on commit 1bc46a1

Please sign in to comment.