OGS
ProcessLib::Assembly::ParallelVectorMatrixAssembler Class Reference

Detailed Description

Definition at line 20 of file ParallelVectorMatrixAssembler.h.

#include <ParallelVectorMatrixAssembler.h>

Collaboration diagram for ProcessLib::Assembly::ParallelVectorMatrixAssembler:
[legend]

Public Member Functions

 ParallelVectorMatrixAssembler (AbstractJacobianAssembler &jacobian_assembler)
 
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)
 

Private Attributes

AbstractJacobianAssemblerjacobian_assembler_
 
LocalMatrixOutput local_matrix_output_
 
GlobalMatrixOutput global_matrix_output_
 
int const num_threads_
 

Constructor & Destructor Documentation

◆ ParallelVectorMatrixAssembler()

ProcessLib::Assembly::ParallelVectorMatrixAssembler::ParallelVectorMatrixAssembler ( AbstractJacobianAssembler & jacobian_assembler)
explicit

Member Function Documentation

◆ assembleWithJacobian()

void ProcessLib::Assembly::ParallelVectorMatrixAssembler::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 )

Definition at line 228 of file ParallelVectorMatrixAssembler.cpp.

236{
237 // checks //////////////////////////////////////////////////////////////////
238 if (dof_tables.size() != xs.size())
239 {
240 OGS_FATAL("Different number of DOF tables and solution vectors.");
241 }
242
243 std::size_t const number_of_processes = xs.size();
244 // algorithm ///////////////////////////////////////////////////////////////
245
247 ConcurrentMatrixView b_view(b);
248 ConcurrentMatrixView Jac_view(Jac);
249
250 ThreadException exception;
251#pragma omp parallel num_threads(num_threads_)
252 {
253#ifdef _OPENMP
254#pragma omp single nowait
255 {
256 INFO("Number of threads: {}", omp_get_num_threads());
257 }
258#endif
259
260 // temporary data only stored here in order to avoid frequent memory
261 // reallocations.
262 std::vector<double> local_b_data;
263 std::vector<double> local_Jac_data;
264
265 // copy to avoid concurrent access
266 auto const jac_asm = jacobian_assembler_.copy();
267 auto stats_this_thread = stats->clone();
268
269 MultiMatrixElementCache cache{b_view, Jac_view,
270 stats_this_thread->data};
271
272 auto local_matrix_output = [&](std::ptrdiff_t element_id)
273 {
274 local_matrix_output_(t, process_id, element_id, local_b_data,
275 local_Jac_data);
276 };
277
278 // TODO corner case: what if all elements on a submesh are deactivated?
279
280 // Monolithic scheme
281 if (number_of_processes == 1)
282 {
283 assert(process_id == 0);
284 auto const& dof_table = *dof_tables[0];
285 auto const& x = *xs[0];
286 auto const& x_prev = *x_prevs[0];
287
289 collectActiveLocalAssemblers(local_assemblers, active_elements),
290 exception, local_matrix_output,
291 [&](auto element_id, auto& loc_asm)
292 {
294 element_id, loc_asm, dof_table, t, dt, x, x_prev,
295 local_b_data, local_Jac_data, *jac_asm, cache);
296 });
297 }
298 else // Staggered scheme
299 {
301 collectActiveLocalAssemblers(local_assemblers, active_elements),
302 exception, local_matrix_output,
303 [&](auto element_id, auto& loc_asm)
304 {
306 element_id, loc_asm, dof_tables, t, dt, xs, x_prevs,
307 process_id, local_b_data, local_Jac_data, *jac_asm,
308 cache);
309 });
310 }
311 }
312
313 stats->print();
314
315 global_matrix_output_(t, process_id, b, Jac);
316 exception.rethrow();
317}
#define OGS_FATAL(...)
Definition Error.h:26
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
virtual std::unique_ptr< AbstractJacobianAssembler > copy() const =0
static std::shared_ptr< CumulativeStats< Data > > create()
ConcurrentMatrixView(GlobalVector &) -> ConcurrentMatrixView< 1 >
std::vector< std::tuple< std::ptrdiff_t, std::reference_wrapper< ProcessLib::LocalAssemblerInterface > > > collectActiveLocalAssemblers(BaseLib::PolymorphicRandomAccessContainerView< ProcessLib::LocalAssemblerInterface > const &local_assemblers, std::vector< std::size_t > const &active_elements)
Returns a vector of active element ids with corresponding local assemblers.
void assembleWithJacobianOneElement(const std::size_t mesh_item_id, ProcessLib::LocalAssemblerInterface &local_assembler, const NumLib::LocalToGlobalIndexMap &dof_table, const double t, const double dt, const GlobalVector &x, const GlobalVector &x_prev, std::vector< double > &local_b_data, std::vector< double > &local_Jac_data, ProcessLib::AbstractJacobianAssembler &jacobian_assembler, ProcessLib::Assembly::MultiMatrixElementCache &cache)
void assembleWithJacobianForStaggeredSchemeOneElement(const std::size_t mesh_item_id, ProcessLib::LocalAssemblerInterface &local_assembler, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, const double t, const double dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, std::vector< double > &local_b_data, std::vector< double > &local_Jac_data, ProcessLib::AbstractJacobianAssembler &jacobian_assembler, ProcessLib::Assembly::MultiMatrixElementCache &cache)
void runAssembly(std::vector< std::tuple< std::ptrdiff_t, std::reference_wrapper< ProcessLib::LocalAssemblerInterface > > > const &ids_local_assemblers, ThreadException &exception, auto local_matrix_output, auto assemble)

References ProcessLib::AbstractJacobianAssembler::copy(), ProcessLib::Assembly::CumulativeStats< Data >::create(), global_matrix_output_, INFO(), jacobian_assembler_, local_matrix_output_, OGS_FATAL, and ThreadException::rethrow().

Referenced by ProcessLib::AssemblyMixin< Process >::assembleWithJacobian(), and ProcessLib::ThermoRichardsFlow::ThermoRichardsFlowProcess::assembleWithJacobianConcreteProcess().

Member Data Documentation

◆ global_matrix_output_

GlobalMatrixOutput ProcessLib::Assembly::ParallelVectorMatrixAssembler::global_matrix_output_
private

Definition at line 38 of file ParallelVectorMatrixAssembler.h.

Referenced by assembleWithJacobian().

◆ jacobian_assembler_

AbstractJacobianAssembler& ProcessLib::Assembly::ParallelVectorMatrixAssembler::jacobian_assembler_
private

Definition at line 36 of file ParallelVectorMatrixAssembler.h.

Referenced by assembleWithJacobian().

◆ local_matrix_output_

LocalMatrixOutput ProcessLib::Assembly::ParallelVectorMatrixAssembler::local_matrix_output_
private

Definition at line 37 of file ParallelVectorMatrixAssembler.h.

Referenced by assembleWithJacobian().

◆ num_threads_

int const ProcessLib::Assembly::ParallelVectorMatrixAssembler::num_threads_
private

Definition at line 40 of file ParallelVectorMatrixAssembler.h.


The documentation for this class was generated from the following files: