Skip to content
Snippets Groups Projects
Commit 758bccde authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[PL] pass a list of variables to process constructor

parent 887391d1
No related branches found
No related tags found
No related merge requests found
......@@ -44,13 +44,12 @@ public:
MeshLib::Mesh& mesh,
typename Process<GlobalSetup>::NonlinearSolver& nonlinear_solver,
std::unique_ptr<typename Process<GlobalSetup>::TimeDiscretization>&& time_discretization,
ProcessVariable& variable,
std::vector<std::reference_wrapper<ProcessVariable>>&& process_variables,
GroundwaterFlowProcessData&& process_data)
: Process<GlobalSetup>(mesh, nonlinear_solver, std::move(time_discretization))
: Process<GlobalSetup>(mesh, nonlinear_solver, std::move(time_discretization),
std::move(process_variables))
, _process_data(std::move(process_data))
{
Base::_process_variables.emplace_back(variable);
if (dynamic_cast<NumLib::ForwardEuler<GlobalVector>*>(
&Base::getTimeDiscretization()) != nullptr)
{
......@@ -169,10 +168,8 @@ createGroundwaterFlowProcess(
DBUG("Create GroundwaterFlowProcess.");
// Process variable.
ProcessVariable& process_variable =
findProcessVariable(config, "process_variable", variables);
DBUG("Associate hydraulic_head with process variable \'%s\'.",
process_variable.getName().c_str());
auto process_variables =
findProcessVariables(variables, config, { "process_variable" });
// Hydraulic conductivity parameter.
auto& hydraulic_conductivity =
......@@ -189,9 +186,10 @@ createGroundwaterFlowProcess(
return std::unique_ptr<GroundwaterFlowProcess<GlobalSetup>>{
new GroundwaterFlowProcess<GlobalSetup>{
mesh, nonlinear_solver,std::move(time_discretization),
process_variable,
std::move(process_variables),
std::move(process_data)
}};
}
};
}
} // namespace GroundwaterFlow
......
......@@ -18,11 +18,11 @@
namespace ProcessLib
{
ProcessVariable& findProcessVariable(
BaseLib::ConfigTree const& process_config, std::string const& tag,
std::vector<ProcessVariable> const& variables)
std::vector<ProcessVariable> const& variables,
BaseLib::ConfigTree const& pv_config, std::string const& tag)
{
// Find process variable name in process config.
std::string const name = process_config.getConfParam<std::string>(tag);
std::string const name = pv_config.getConfParam<std::string>(tag);
// Find corresponding variable by name.
auto variable = std::find_if(variables.cbegin(), variables.cend(),
......@@ -39,10 +39,29 @@ ProcessVariable& findProcessVariable(
name.c_str(), tag.c_str());
std::abort();
}
DBUG("Found process variable \'%s\'.", variable->getName().c_str());
DBUG("Found process variable \'%s\' for config tag <%s>.",
variable->getName().c_str(), tag.c_str());
// Const cast is needed because of variables argument constness.
return const_cast<ProcessVariable&>(*variable);
}
std::vector<std::reference_wrapper<ProcessVariable>>
findProcessVariables(
std::vector<ProcessVariable> const& variables,
BaseLib::ConfigTree const& process_config,
std::initializer_list<std::string> tag_names)
{
std::vector<std::reference_wrapper<ProcessVariable>> vars;
vars.reserve(tag_names.size());
auto const pv_conf = process_config.getConfSubtree("process_variables");
for (auto const& tag : tag_names) {
vars.emplace_back(findProcessVariable(variables, pv_conf, tag));
}
return vars;
}
} // namespace ProcessLib
......@@ -60,10 +60,13 @@ public:
Process(MeshLib::Mesh& mesh,
NonlinearSolver& nonlinear_solver,
std::unique_ptr<TimeDiscretization>&& time_discretization)
std::unique_ptr<TimeDiscretization>&& time_discretization,
std::vector<std::reference_wrapper<ProcessVariable>>&&
process_variables)
: _mesh(mesh)
, _nonlinear_solver(nonlinear_solver)
, _nonlinear_solver(nonlinear_solver)
, _time_discretization(std::move(time_discretization))
, _process_variables(std::move(process_variables))
{}
/// Preprocessing before starting assembly for new timestep.
......@@ -340,10 +343,6 @@ private:
*_local_to_global_index_map, _mesh));
}
protected:
/// Variables used by this process.
std::vector<std::reference_wrapper<ProcessVariable>> _process_variables;
private:
unsigned const _integration_order = 2;
......@@ -360,23 +359,34 @@ private:
NonlinearSolver& _nonlinear_solver;
std::unique_ptr<TimeDiscretization> _time_discretization;
/// Variables used by this process.
std::vector<std::reference_wrapper<ProcessVariable>> _process_variables;
};
/// Find a process variable for a name given in the process configuration under
/// the tag.
/// Find process variables in \c variables whose names match the settings under
/// the given \c tag_names in the \c process_config.
///
/// In the process config a process variable is referenced by a name. For
/// example it will be looking for a variable named "H" in the list of process
/// variables when the tag is "hydraulic_head":
/// \code
/// <process>
/// ...
/// <hydraulic_head>H</hydraulic_head>
/// <process_variables>
/// <hydraulic_head>H</hydraulic_head>
/// ...
/// </process_variables>
/// ...
/// </process>
/// \endcode
/// and return a reference to that variable.
ProcessVariable& findProcessVariable(
BaseLib::ConfigTree const& process_config, std::string const& tag,
std::vector<ProcessVariable> const& variables);
///
/// \return a vector of references to the found variable(s).
std::vector<std::reference_wrapper<ProcessVariable>>
findProcessVariables(
std::vector<ProcessVariable> const& variables,
BaseLib::ConfigTree const& process_config,
std::initializer_list<std::string> tag_names);
/// Find a parameter of specific type for a name given in the process
/// configuration under the tag.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment