34 bool const use_monolithic_scheme);
38 std::vector<std::reference_wrapper<MeshLib::Mesh>>
const& submeshes,
39 std::vector<std::vector<std::string>>
const& residuum_names,
40 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
const&
64 std::vector<ProcessLib::Assembly::SubmeshAssemblyData>
71 std::optional<ProcessLib::Assembly::BulkMeshAssemblyData>
93template <
typename Process>
124 std::vector<std::reference_wrapper<MeshLib::Mesh>>
const& submeshes,
125 std::vector<std::vector<std::string>>
const& residuum_names)
128 derived().getMesh(), submeshes, residuum_names,
129 derived().getProcessVariables());
141 double const t,
double const dt, std::vector<GlobalVector*>
const& x,
142 std::vector<GlobalVector*>
const& x_prev,
int const process_id,
144 std::vector<std::size_t>
const*
const sorted_element_subset =
nullptr,
145 bool const copy_residua_to_mesh =
false)
147 DBUG(
"AssemblyMixin assemble(t={:g}, dt={:g}, process_id={}).", t, dt,
152 std::vector<NumLib::LocalToGlobalIndexMap const*>
const dof_tables =
155 std::exception_ptr
const exception =
158 M, K, b, sorted_element_subset)
160 M, K, b, sorted_element_subset,
161 copy_residua_to_mesh);
169 dt, *x[process_id], *x_prev[process_id], M, K, b);
172 neg_res_bulkmesh, *(dof_tables[process_id]),
181 double const t,
double const dt, std::vector<GlobalVector*>
const& x,
182 std::vector<GlobalVector*>
const& x_prev,
int const process_id,
184 std::vector<std::size_t>
const*
const sorted_element_subset =
nullptr,
185 bool const copy_residua_to_mesh =
false)
188 "AssemblyMixin assembleWithJacobian(t={:g}, dt={:g}, "
202 "You specified that this process is linear. The assembly for "
203 "the Newton-Raphson method will be run anyways.");
206 std::vector<NumLib::LocalToGlobalIndexMap const*>
const dof_tables =
209 std::exception_ptr
const exception =
213 process_id, b, Jac, sorted_element_subset)
215 t, dt, x, x_prev, dof_tables, process_id, b, Jac,
216 sorted_element_subset, copy_residua_to_mesh);
228 b, *(dof_tables[process_id]),
235 std::vector<GlobalVector*>
const& x,
236 std::vector<GlobalVector*>
const& x_prev,
237 int const process_id)
241 WARN(
"AssemblyMixin. Skipping preOutput() step.");
260 return static_cast<Process const&
>(*this);
267 std::vector<GlobalVector*>
const& x,
268 std::vector<GlobalVector*>
const& x_prev,
269 std::vector<NumLib::LocalToGlobalIndexMap const*>
const& dof_tables,
271 std::vector<std::size_t>
const*
const sorted_element_subset)
273 std::exception_ptr exception =
nullptr;
277 auto const& loc_asms =
derived().local_assemblers_;
283 dof_tables, t, dt, x, x_prev, process_id, M, K, b);
287 exception = std::current_exception();
296 DBUG(
"Saving global M, K, b for later reuse.");
303 INFO(
"[time] Saving global M, K, b took {:g} s",
311 double const t,
double const dt, std::vector<GlobalVector*>
const& x,
312 std::vector<GlobalVector*>
const& x_prev,
313 std::vector<NumLib::LocalToGlobalIndexMap const*>
const& dof_tables,
315 std::vector<std::size_t>
const*
const sorted_element_subset)
321 x_prev, dof_tables, process_id, M, K, b, sorted_element_subset);
324 DBUG(
"Reusing saved global M, K, b.");
327 time_restore.
start();
334 INFO(
"[time] Restoring global M, K, b took {:g} s",
341 double const t,
double const dt, std::vector<GlobalVector*>
const& x,
342 std::vector<GlobalVector*>
const& x_prev,
343 std::vector<NumLib::LocalToGlobalIndexMap const*>
const& dof_tables,
345 std::vector<std::size_t>
const*
const sorted_element_subset,
346 bool const copy_residua_to_mesh)
353 std::unique_ptr<GlobalMatrix> M_tmp;
354 std::unique_ptr<GlobalMatrix> K_tmp;
355 std::unique_ptr<GlobalVector> b_tmp;
357 auto getMKb = [&M_tmp, &K_tmp, &b_tmp,
365 if (!(M_tmp && K_tmp && b_tmp))
375 return std::tie(*M_tmp, *K_tmp, *b_tmp);
378 std::exception_ptr exception =
nullptr;
379 for (
auto const& [sad, mat_cache] :
383 auto [M_submesh, K_submesh, b_submesh] = getMKb(mat_cache);
385 if (!mat_cache.hasMKb())
392 sad, mat_cache, t, dt, x, x_prev, dof_tables, process_id,
393 M_submesh, K_submesh, b_submesh, sorted_element_subset);
403 if (copy_residua_to_mesh)
408 M_submesh, K_submesh, b_submesh);
411 process_id, neg_res_submesh, *(dof_tables[process_id]),
421 [[nodiscard]] std::exception_ptr
424 double const dt, std::vector<GlobalVector*>
const& x,
425 std::vector<GlobalVector*>
const& x_prev,
426 std::vector<NumLib::LocalToGlobalIndexMap const*>
const& dof_tables,
428 std::vector<std::size_t>
const*
const sorted_element_subset)
430 auto const& loc_asms =
derived().local_assemblers_;
431 std::exception_ptr exception =
nullptr;
435 pvma_.assembleWithJacobian(
439 dof_tables, t, dt, x, x_prev, process_id, b, Jac);
443 exception = std::current_exception();
452 double const t,
double const dt, std::vector<GlobalVector*>
const& x,
453 std::vector<GlobalVector*>
const& x_prev,
454 std::vector<NumLib::LocalToGlobalIndexMap const*>
const& dof_tables,
456 std::vector<std::size_t>
const*
const sorted_element_subset,
459 std::exception_ptr exception =
nullptr;
467 b_submesh->setZero();
470 sad, t, dt, x, x_prev, dof_tables, process_id, *b_submesh, Jac,
471 sorted_element_subset);
480 process_id, *b_submesh, *(dof_tables[process_id]), sad);
489 std::vector<GlobalVector*>
const& x,
490 std::vector<GlobalVector*>
const& x_prev,
491 int const process_id)
493 auto const matrix_specification =
497 matrix_specification);
499 matrix_specification);
501 matrix_specification);
507 assemble(t, dt, x, x_prev, process_id, *M, *K, *b,
nullptr,
true);
512 std::vector<GlobalVector*>
const& ,
513 std::vector<GlobalVector*>
const& ,
519 auto const matrix_specification =
523 matrix_specification);
525 matrix_specification);
MathLib::EigenMatrix GlobalMatrix
MathLib::EigenVector GlobalVector
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
double elapsed() const
Get the elapsed time in seconds.
void start()
Start the timer.
Base class for Jacobian assemblers.
void initializeAssemblyOnSubmeshes(MeshLib::Mesh &bulk_mesh, std::vector< std::reference_wrapper< MeshLib::Mesh > > const &submeshes, std::vector< std::vector< std::string > > const &residuum_names, std::vector< std::vector< std::reference_wrapper< ProcessVariable > > > const &pvs)
AssemblyMixinBase(AbstractJacobianAssembler &jacobian_assembler, bool const is_linear, bool const use_monolithic_scheme)
Assembly::ParallelVectorMatrixAssembler pvma_
static void copyResiduumVectorsToBulkMesh(GlobalVector const &rhs, NumLib::LocalToGlobalIndexMap const &local_to_global_index_map, std::vector< std::reference_wrapper< MeshLib::PropertyVector< double > > > residuum_vectors)
@ NO_DEACTIVATED_SUBDOMAINS
@ HAS_DEACTIVATED_SUBDOMAINS
std::optional< NumLib::NonlinearSolverTag > last_assembly_was_
void updateActiveElementsImpl(Process const &process)
std::vector< AssembledMatrixCache > submesh_matrix_cache_
AssembledMatrixCache for each submesh.
static void copyResiduumVectorsToSubmesh(int const process_id, GlobalVector const &rhs, NumLib::LocalToGlobalIndexMap const &local_to_global_index_map, ProcessLib::Assembly::SubmeshAssemblyData const &sad)
ActiveElementIDsState ids_state_
void updateActiveElements(ProcessLib::Process const &process)
std::vector< ProcessLib::Assembly::SubmeshAssemblyData > submesh_assembly_data_
SubmeshAssemblyData for each submesh.
std::optional< ProcessLib::Assembly::BulkMeshAssemblyData > bulk_mesh_assembly_data_
Empty if submesh assembly is used.
AssembledMatrixCache bulk_mesh_matrix_cache_
AssemblyMixinBase(AbstractJacobianAssembler &jacobian_assembler, bool const is_linear, bool const use_monolithic_scheme)
void assemble(double const 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, std::vector< std::size_t > const *const sorted_element_subset=nullptr, bool const copy_residua_to_mesh=false)
std::exception_ptr assembleOnSubmeshes(double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, std::vector< std::size_t > const *const sorted_element_subset, bool const copy_residua_to_mesh)
std::exception_ptr assembleOnBulkMeshOrOnSubmeshCommon(Assembly::CommonAssemblyData const &assembly_data, AssembledMatrixCache &mat_cache, double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, std::vector< std::size_t > const *const sorted_element_subset)
Common code for Picard assembly on the bulk mesh or on submeshes.
Process const & derived() const
std::exception_ptr assembleWithJacobianOnBulkMeshOrOnSubmeshCommon(Assembly::CommonAssemblyData const &assembly_data, double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, int const process_id, GlobalVector &b, GlobalMatrix &Jac, std::vector< std::size_t > const *const sorted_element_subset)
void preOutputPicard(double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id)
std::exception_ptr assembleOnBulkMesh(double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, std::vector< std::size_t > const *const sorted_element_subset)
void updateActiveElements()
void preOutput(double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id)
void preOutputNewton(double const, double const, std::vector< GlobalVector * > const &, std::vector< GlobalVector * > const &, int const)
void initializeAssemblyOnSubmeshes(std::vector< std::reference_wrapper< MeshLib::Mesh > > const &submeshes, std::vector< std::vector< std::string > > const &residuum_names)
void assembleWithJacobian(double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalVector &b, GlobalMatrix &Jac, std::vector< std::size_t > const *const sorted_element_subset=nullptr, bool const copy_residua_to_mesh=false)
std::exception_ptr assembleWithJacobianOnSubmeshes(double const t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, int const process_id, GlobalVector &b, GlobalMatrix &Jac, std::vector< std::size_t > const *const sorted_element_subset, bool const)
std::vector< NumLib::LocalToGlobalIndexMap const * > getDOFTables(int const number_of_processes) const
MathLib::MatrixSpecifications getMatrixSpecifications(const int process_id) const override
void allRanksThrowOrNone(std::exception_ptr const &exception, auto &&warning_callback)
void finalizeAssembly(PETScMatrix &A)
void copy(PETScVector const &x, PETScVector &y)
void axpy(PETScVector &y, PetscScalar const a, PETScVector const &x)
GlobalVector computeResiduum(double const dt, GlobalVector const &x, GlobalVector const &x_prev, GlobalMatrix const &M, GlobalMatrix const &K, GlobalVector const &b)
Stores assembled global M, K, b matrices/vectors for later reuse.
void storeMKb(GlobalMatrix const &M, GlobalMatrix const &K, GlobalVector const &b)
Store data.
std::shared_ptr< std::vector< std::size_t > const > activeElementIDsSorted(std::vector< std::size_t > const *const sorted_element_subset) const