13#include <range/v3/algorithm/any_of.hpp>
14#include <range/v3/algorithm/set_algorithm.hpp>
15#include <range/v3/view/drop.hpp>
16#include <range/v3/view/transform.hpp>
27 std::vector<GlobalVector*>
const& x_prev)
29 for (
auto*
const solution : x)
33 for (
auto*
const solution : x_prev)
47 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
48 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>
const& parameters,
49 unsigned const integration_order,
50 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
53 const bool use_monolithic_scheme)
54 : name(std::move(name_)),
56 _secondary_variables(std::move(secondary_variables)),
57 cell_average_data_(mesh),
58 _jacobian_assembler(std::move(jacobian_assembler)),
59 _global_assembler(*_jacobian_assembler),
60 _use_monolithic_scheme(use_monolithic_scheme),
61 _integration_order(integration_order),
62 _process_variables(std::move(process_variables)),
64 [&](const std::size_t number_of_process_variables)
67 std::vector<BoundaryConditionCollection> pcs_BCs;
68 pcs_BCs.reserve(number_of_process_variables);
69 for (std::size_t i = 0; i < number_of_process_variables; i++)
74 }(_process_variables.size())),
75 _source_term_collections(
76 [&](
const std::size_t number_of_processes)
77 -> std::vector<SourceTermCollection>
79 std::vector<SourceTermCollection> pcs_sts;
80 pcs_sts.reserve(number_of_processes);
81 for (std::size_t i = 0; i < number_of_processes; i++)
86 }(_process_variables.size()))
92 std::map<
int, std::shared_ptr<MaterialPropertyLib::Medium>>
const& media)
97 per_process_BCs.addBCsForProcessVariables(per_process_variables, dof_table,
101 per_process_sts.addSourceTermsForProcessVariables(
106 std::map<
int, std::shared_ptr<MaterialPropertyLib::Medium>>
const& media)
112 for (std::size_t pcs_id = 0; pcs_id < number_of_processes; pcs_id++)
120 std::map<
int, std::shared_ptr<MaterialPropertyLib::Medium>>
const& media)
122 DBUG(
"Initialize process.");
124 DBUG(
"Construct dof mappings.");
127 DBUG(
"Compute sparsity pattern");
130 DBUG(
"Initialize the extrapolator");
136 DBUG(
"Initialize boundary conditions.");
141 std::vector<GlobalVector*>& process_solutions,
142 std::vector<GlobalVector*>
const& process_solutions_prev,
144 int const process_id)
146 auto& x = *process_solutions[process_id];
147 auto& x_prev = *process_solutions_prev[process_id];
150 auto const& dof_table_of_process =
getDOFTable(process_id);
153 for (std::size_t variable_id = 0;
154 variable_id < per_process_variables.size();
160 auto const& pv = per_process_variables[variable_id];
161 DBUG(
"Set the initial condition of variable {:s} of process {:d}.",
162 pv.get().getName().data(), process_id);
164 auto const& ic = pv.get().getInitialCondition();
166 auto const num_comp = pv.get().getNumberOfGlobalComponents();
168 for (
int component_id = 0; component_id < num_comp; ++component_id)
170 auto const& mesh_subset =
171 dof_table_of_process.getMeshSubset(variable_id, component_id);
172 auto const mesh_id = mesh_subset.getMeshID();
173 for (
auto const* node : mesh_subset.getNodes())
180 auto const& ic_value = ic(t, pos);
183 std::abs(dof_table_of_process.getGlobalIndex(l, variable_id,
194 if (global_index == x.size())
197 x.set(global_index, ic_value[component_id]);
215 return {l.dofSizeWithoutGhosts(), l.dofSizeWithoutGhosts(),
220 const int process_id)
223 for (
auto const& variable : variables_per_process)
225 variable.get().updateDeactivatedSubdomains(time);
230 auto active_elements_ids = ranges::views::transform(
231 [](
auto const& variable)
232 {
return variable.get().getActiveElementIDs(); });
235 if (ranges::any_of(variables_per_process | active_elements_ids,
236 [](
auto const& vector) {
return vector.empty(); }))
245 variables_per_process[0].get().getActiveElementIDs();
247 for (
auto const& pv_active_element_ids :
248 variables_per_process | ranges::views::drop(1) | active_elements_ids)
250 std::vector<std::size_t> new_active_elements;
252 pv_active_element_ids.size());
254 std::back_inserter(new_active_elements));
267 std::vector<GlobalVector*>
const& x,
268 std::vector<GlobalVector*>
const& x_prev,
272 assert(x.size() == x_prev.size());
274 setLocalAccessibleVectors(x, x_prev);
288 std::vector<GlobalVector*>
const& x,
289 std::vector<GlobalVector*>
const& x_prev,
293 assert(x.size() == x_prev.size());
295 setLocalAccessibleVectors(x, x_prev);
317 const int specified_process_id = 0;
328 std::vector<MeshLib::MeshSubset> all_mesh_subsets;
334 std::generate_n(std::back_inserter(all_mesh_subsets),
335 pv.getNumberOfGlobalComponents(),
336 [&]() { return *_mesh_subset_all_nodes; });
340 std::vector<int> vec_var_n_components;
342 back_inserter(vec_var_n_components),
347 std::make_unique<NumLib::LocalToGlobalIndexMap>(
348 std::move(all_mesh_subsets), vec_var_n_components,
355 const int specified_process_id)
362 std::vector<MeshLib::MeshSubset> all_mesh_subsets;
365 std::vector<int> vec_var_n_components;
367 std::generate_n(std::back_inserter(all_mesh_subsets),
370 .getNumberOfGlobalComponents(),
376 .getNumberOfGlobalComponents());
378 std::make_unique<NumLib::LocalToGlobalIndexMap>(
379 std::move(all_mesh_subsets), vec_var_n_components,
386 int const number_of_processes)
const
388 std::vector<NumLib::LocalToGlobalIndexMap const*> dof_tables;
389 dof_tables.reserve(number_of_processes);
390 std::generate_n(std::back_inserter(dof_tables), number_of_processes,
391 [&]() {
return &
getDOFTable(dof_tables.size()); });
395std::tuple<NumLib::LocalToGlobalIndexMap*, bool>
402 const bool manage_storage =
false;
408 std::vector<MeshLib::MeshSubset> all_mesh_subsets_single_component;
411 const bool manage_storage =
true;
414 std::move(all_mesh_subsets_single_component),
425 std::tie(dof_table_single_component, manage_storage) =
428 std::unique_ptr<NumLib::Extrapolator> extrapolator(
430 *dof_table_single_component));
434 std::move(extrapolator), dof_table_single_component, manage_storage);
444 const double delta_t,
const int process_id)
446 for (
auto*
const solution : x)
454 std::vector<GlobalVector*>
const& x_prev,
455 const double t,
const double delta_t,
456 int const process_id)
458 setLocalAccessibleVectors(x, x_prev);
466 std::vector<GlobalVector*>
const& x_prev,
467 const double t,
double const dt,
468 int const process_id)
470 setLocalAccessibleVectors(x, x_prev);
477 std::vector<GlobalVector*>
const& x,
479 int const process_id)
481 for (
auto const* solution : x)
501 std::vector<GlobalVector*>
const& x,
502 std::vector<GlobalVector*>
const& x_prev,
503 int const process_id)
505 for (
auto const* solution : x)
511std::vector<GlobalIndexType>
514 std::vector<GlobalIndexType> indices;
519 auto const& dof_table_of_process =
getDOFTable(process_id);
522 for (std::size_t variable_id = 0;
523 variable_id < per_process_variables.size();
526 auto const& pv = per_process_variables[variable_id];
527 DBUG(
"Set the initial condition of variable {:s} of process {:d}.",
528 pv.get().getName().data(), process_id);
530 if ((pv.get().compensateNonEquilibriumInitialResiduum()))
535 auto const num_comp = pv.get().getNumberOfGlobalComponents();
537 for (
int component_id = 0; component_id < num_comp; ++component_id)
539 auto const& mesh_subset = dof_table_of_process.getMeshSubset(
540 variable_id, component_id);
541 auto const mesh_id = mesh_subset.getMeshID();
542 for (
auto const* node : mesh_subset.getNodes())
548 std::abs(dof_table_of_process.getGlobalIndex(
549 l, variable_id, component_id));
551 indices.push_back(global_index);
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Global vector based on Eigen vector.
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
void setNodeID(std::size_t node_id)
void setCoordinates(MathLib::Point3d const &coordinates)
int getNumberOfGlobalComponents() const
Returns the number of components of the process variable.
virtual NumLib::IterationResult postIterationConcreteProcess(GlobalVector const &)
virtual void preTimestepConcreteProcess(std::vector< GlobalVector * > const &, const double, const double, const int)
std::vector< BoundaryConditionCollection > _boundary_conditions
std::vector< NumLib::LocalToGlobalIndexMap const * > getDOFTables(int const number_of_processes) const
virtual void preIterationConcreteProcess(const unsigned, GlobalVector const &)
void constructDofTableOfSpecifiedProcessStaggeredScheme(const int specified_process_id)
static PROCESSLIB_EXPORT const std::string constant_one_parameter_name
void preAssemble(const double t, double const dt, GlobalVector const &x) final
virtual void initializeBoundaryConditions(std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media)
void initialize(std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media)
void initializeProcessBoundaryConditionsAndSourceTerms(const NumLib::LocalToGlobalIndexMap &dof_table, const int process_id, std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media)
virtual void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order)=0
Process specific initialization called by initialize().
std::vector< std::size_t > _ids_of_active_elements
Union of active element ids per process variable.
void assemble(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b) final
virtual void postTimestepConcreteProcess(std::vector< GlobalVector * > const &, std::vector< GlobalVector * > const &, const double, const double, int const)
Process(std::string name_, MeshLib::Mesh &mesh, std::unique_ptr< AbstractJacobianAssembler > &&jacobian_assembler, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const ¶meters, unsigned const integration_order, std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > &&process_variables, SecondaryVariableCollection &&secondary_variables, const bool use_monolithic_scheme=true)
virtual void computeSecondaryVariableConcrete(double const, double const, std::vector< GlobalVector * > const &, GlobalVector const &, int const)
std::unique_ptr< MeshLib::MeshSubset const > _mesh_subset_all_nodes
void preOutput(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id)
virtual void assembleConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b)=0
std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > _process_variables
virtual NumLib::LocalToGlobalIndexMap const & getDOFTable(const int) const
virtual void setInitialConditionsConcreteProcess(std::vector< GlobalVector * > &, double const, int const)
NumLib::IterationResult postIteration(GlobalVector const &x) final
void postTimestep(std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, const double t, const double delta_t, int const process_id)
Postprocessing after a complete timestep.
virtual void assembleWithJacobianConcreteProcess(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalVector &b, GlobalMatrix &Jac)=0
void preTimestep(std::vector< GlobalVector * > const &x, const double t, const double delta_t, const int process_id)
Preprocessing before starting assembly for new timestep.
void computeSecondaryVariable(double const t, double const dt, std::vector< GlobalVector * > const &x, GlobalVector const &x_prev, int const process_id)
compute secondary variables for the coupled equations or for output.
void initializeExtrapolator()
virtual void postNonLinearSolverConcreteProcess(std::vector< GlobalVector * > const &, std::vector< GlobalVector * > const &, const double, double const, int const)
virtual void constructDofTable()
void constructMonolithicProcessDofTable()
virtual void preAssembleConcreteProcess(const double, double const, GlobalVector const &)
void postNonLinearSolver(std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, const double t, double const dt, int const process_id)
std::vector< GlobalIndexType > getIndicesOfResiduumWithoutInitialCompensation() const override
unsigned const _integration_order
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _local_to_global_index_map
std::vector< SourceTermCollection > _source_term_collections
void updateDeactivatedSubdomains(double const time, const int process_id)
void computeSparsityPattern()
MathLib::MatrixSpecifications getMatrixSpecifications(const int process_id) const override
void setInitialConditions(std::vector< GlobalVector * > &process_solutions, std::vector< GlobalVector * > const &process_solutions_prev, double const t, int const process_id)
void assembleWithJacobian(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalVector &b, GlobalMatrix &Jac) final
virtual void preOutputConcreteProcess(const double, double const, std::vector< GlobalVector * > const &, std::vector< GlobalVector * > const &, int const)
std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > const & getProcessVariables() const
ExtrapolatorData _extrapolator_data
GlobalSparsityPattern _sparsity_pattern
void preIteration(const unsigned iter, GlobalVector const &x) final
const bool _use_monolithic_scheme
virtual std::tuple< NumLib::LocalToGlobalIndexMap *, bool > getDOFTableForExtrapolatorData() const
Handles configuration of several secondary variables from the project file.
IterationResult
Status flags telling the NonlinearSolver if an iteration succeeded.
void finalizeAssembly(PETScMatrix &A)
void copy(PETScVector const &x, PETScVector &y)
void setLocalAccessibleVector(PETScVector const &x)
@ BY_LOCATION
Ordering data by spatial location.
GlobalSparsityPattern computeSparsityPattern(LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh)
Computes a sparsity pattern for the given inputs.
void setLocalAccessibleVectors(std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev)