OGS
AssemblyMixin.h
Go to the documentation of this file.
1
11#pragma once
12
18
19namespace ProcessLib
20{
24{
25 explicit SubmeshAssemblyData(
26 MeshLib::Mesh const& mesh,
27 std::vector<std::vector<
28 std::reference_wrapper<MeshLib::PropertyVector<double>>>>&&
30
33 std::vector<std::size_t> active_element_ids;
34 std::vector<
35 std::vector<std::reference_wrapper<MeshLib::PropertyVector<double>>>>
37};
38
42{
49
50protected:
51 explicit AssemblyMixinBase(AbstractJacobianAssembler& jacobian_assembler)
52 : pvma_{jacobian_assembler} {};
53
55 MeshLib::Mesh& bulk_mesh,
56 std::vector<std::reference_wrapper<MeshLib::Mesh>> const& submeshes,
57 std::vector<std::vector<std::string>> const& residuum_names,
58 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>> const&
59 pvs);
60
61 void updateActiveElements(ProcessLib::Process const& process);
62
64 GlobalVector const& rhs,
65 NumLib::LocalToGlobalIndexMap const& local_to_global_index_map,
66 std::vector<std::reference_wrapper<MeshLib::PropertyVector<double>>>
67 residuum_vectors);
68
70 int const process_id,
71 GlobalVector const& rhs,
72 NumLib::LocalToGlobalIndexMap const& local_to_global_index_map,
73 SubmeshAssemblyData const& sad);
74
75private:
76 void updateActiveElementsImpl(Process const& process);
77
78protected:
79 std::vector<SubmeshAssemblyData> submesh_assembly_data_;
80 std::vector<
81 std::vector<std::reference_wrapper<MeshLib::PropertyVector<double>>>>
83
85 std::size_t b_submesh_id_ = 0;
86
88
89private:
91};
92
98template <typename Process>
100{
101 // Enforce correct use of CRTP, i.e., that Process is derived from
102 // AssemblyMixin<Process>.
104 friend Process;
105
106public:
129 std::vector<std::reference_wrapper<MeshLib::Mesh>> const& submeshes,
130 std::vector<std::vector<std::string>> const& residuum_names)
131 {
133 derived().getMesh(), submeshes, residuum_names,
134 derived().getProcessVariables());
135 }
136
141
142 // cppcheck-suppress functionStatic
143 void assemble(double const t, double const dt,
144 std::vector<GlobalVector*> const& /*x*/,
145 std::vector<GlobalVector*> const& /*x_prev*/,
146 int const process_id, GlobalMatrix& /*M*/,
147 GlobalMatrix& /*K*/, GlobalVector& /*b*/)
148 {
149 DBUG("AssemblyMixin assemble(t={}, dt={}, process_id={}).", t, dt,
150 process_id);
151
155 OGS_FATAL("AssemblyMixin for Picard scheme is not yet implemented.");
156 }
157
158 void assembleWithJacobian(double const t, double const dt,
159 std::vector<GlobalVector*> const& x,
160 std::vector<GlobalVector*> const& x_prev,
161 int const process_id, GlobalVector& b,
162 GlobalMatrix& Jac)
163 {
164 DBUG("AssemblyMixin assembleWithJacobian(t={}, dt={}, process_id={}).",
165 t, dt, process_id);
166
167 std::vector<NumLib::LocalToGlobalIndexMap const*> const dof_tables =
168 derived().getDOFTables(x.size());
169
170 auto const& loc_asms = derived().local_assemblers_;
171
172 if (!submesh_assembly_data_.empty())
173 {
175 b, b_submesh_id_);
176
177 for (auto const& sad : submesh_assembly_data_)
178 {
179 b_submesh.setZero();
180
181 pvma_.assembleWithJacobian(loc_asms, sad.active_element_ids,
182 dof_tables, t, dt, x, x_prev,
183 process_id, b_submesh, Jac);
184
185 MathLib::LinAlg::axpy(b, 1.0, b_submesh);
186
188 process_id, b_submesh, *(dof_tables[process_id]), sad);
189 }
190
192 }
193 else
194 {
196 loc_asms, derived().getActiveElementIDs(), dof_tables, t, dt, x,
197 x_prev, process_id, b, Jac);
198 }
199
201 b, *(dof_tables[process_id]), residuum_vectors_bulk_[process_id]);
202 }
203
204private:
205 Process& derived() { return static_cast<Process&>(*this); }
206 Process const& derived() const
207 {
208 return static_cast<Process const&>(*this);
209 }
210};
211
212} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:26
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Global vector based on Eigen vector.
Definition EigenVector.h:25
virtual GlobalVector & getVector(std::size_t &id)=0
Get an uninitialized vector with the given id.
virtual void releaseVector(GlobalVector const &x)=0
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)
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)
void updateActiveElementsImpl(Process const &process)
std::size_t b_submesh_id_
ID of the b vector on submeshes, cf. NumLib::VectorProvider.
ActiveElementIDsState ids_state_
void updateActiveElements(ProcessLib::Process const &process)
static void copyResiduumVectorsToSubmesh(int const process_id, GlobalVector const &rhs, NumLib::LocalToGlobalIndexMap const &local_to_global_index_map, SubmeshAssemblyData const &sad)
std::vector< SubmeshAssemblyData > submesh_assembly_data_
std::vector< std::vector< std::reference_wrapper< MeshLib::PropertyVector< double > > > > residuum_vectors_bulk_
void assemble(double const t, double const dt, std::vector< GlobalVector * > const &, std::vector< GlobalVector * > const &, int const process_id, GlobalMatrix &, GlobalMatrix &, GlobalVector &)
Process const & derived() 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)
void assembleWithJacobian(BaseLib::PolymorphicRandomAccessContainerView< LocalAssemblerInterface > const &local_assemblers, std::vector< std::size_t > const &active_elements, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, const double t, double const dt, std::vector< GlobalVector * > const &xs, std::vector< GlobalVector * > const &x_prevs, int const process_id, GlobalVector &b, GlobalMatrix &Jac)
std::vector< NumLib::LocalToGlobalIndexMap const * > getDOFTables(int const number_of_processes) const
Definition Process.cpp:385
void axpy(PETScVector &y, PetscScalar const a, PETScVector const &x)
Definition LinAlg.cpp:57
OGSMesh getMesh(std::string const &name)
static NUMLIB_EXPORT VectorProvider & provider
std::vector< std::vector< std::reference_wrapper< MeshLib::PropertyVector< double > > > > residuum_vectors
MeshLib::PropertyVector< std::size_t > const & bulk_node_ids
MeshLib::PropertyVector< std::size_t > const & bulk_element_ids
std::vector< std::size_t > active_element_ids
SubmeshAssemblyData(MeshLib::Mesh const &mesh, std::vector< std::vector< std::reference_wrapper< MeshLib::PropertyVector< double > > > > &&residuum_vectors)