OGS
AssembledMatrixCache.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <memory>
14
15#include "BaseLib/RunTime.h"
23
24namespace ProcessLib
25{
26
28{
29 AssembledMatrixCache(bool const is_linear,
30 bool const use_monolithic_scheme);
31
32 template <typename VectorOfLocalAssemblers>
33 void assemble(
34 const double t, double const dt, std::vector<GlobalVector*> const& x,
35 std::vector<GlobalVector*> const& x_prev, int const process_id,
36 GlobalMatrix* const M, GlobalMatrix* const K, GlobalVector* const b,
37 std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_tables,
38 VectorMatrixAssembler& global_assembler,
39 VectorOfLocalAssemblers const& local_assemblers,
40 std::vector<std::size_t> const& active_element_ids);
41
42 bool isLinear() const { return is_linear_; }
43
44private:
45 bool const is_linear_;
46
47 std::unique_ptr<GlobalMatrix> M_{};
48 std::unique_ptr<GlobalMatrix> K_{};
49 std::unique_ptr<GlobalVector> b_{};
50};
51
52template <typename VectorOfLocalAssemblers>
54 const double t, double const dt, std::vector<GlobalVector*> const& x,
55 std::vector<GlobalVector*> const& x_prev, int const process_id,
56 GlobalMatrix* const M, GlobalMatrix* const K, GlobalVector* const b,
57 std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_tables,
58 VectorMatrixAssembler& global_assembler,
59 VectorOfLocalAssemblers const& local_assemblers,
60 std::vector<std::size_t> const& active_element_ids)
61{
62 if (bool const cache_empty = K_ == nullptr; cache_empty)
63 {
64 BaseLib::RunTime time_asm;
65 time_asm.start();
66
67 // Call global assembler for each local assembly item.
69 global_assembler, &VectorMatrixAssembler::assemble,
70 local_assemblers, active_element_ids, dof_tables, t, dt, x, x_prev,
71 process_id, M, K, b);
72
76
77 INFO("[time] Calling local assemblers took {:g} s", time_asm.elapsed());
78
79 if (is_linear_)
80 {
81 DBUG("Saving global K, M, b for later reuse.");
82
83 BaseLib::RunTime time_save;
84 time_save.start();
85
89
90 INFO("[time] Saving global K, M, b took {:g} s",
91 time_save.elapsed());
92 }
93 }
94 else
95 {
96 DBUG("Reusing saved global K, M, b.");
97
98 BaseLib::RunTime time_restore;
99 time_restore.start();
100
104
105 INFO("[time] Restoring global K, M, b took {:g} s",
106 time_restore.elapsed());
107 }
108}
109} // namespace ProcessLib
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Definition of the RunTime class.
Count the running time.
Definition RunTime.h:29
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:42
void start()
Start the timer.
Definition RunTime.h:32
Global vector based on Eigen vector.
Definition EigenVector.h:25
void assemble(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, 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)
void copy(PETScVector const &x, PETScVector &y)
Definition LinAlg.cpp:37
void finalizeVectorAssembly(VEC_T &)
General function to finalize the vector assembly.
bool finalizeMatrixAssembly(MAT_T &)
static void executeSelectedMemberDereferenced(Object &object, Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
std::unique_ptr< GlobalMatrix > M_
void assemble(const double t, double const dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, GlobalMatrix *const M, GlobalMatrix *const K, GlobalVector *const b, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, VectorMatrixAssembler &global_assembler, VectorOfLocalAssemblers const &local_assemblers, std::vector< std::size_t > const &active_element_ids)
AssembledMatrixCache(bool const is_linear, bool const use_monolithic_scheme)
std::unique_ptr< GlobalMatrix > K_
std::unique_ptr< GlobalVector > b_