Loading [MathJax]/jax/input/TeX/config.js
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 232 of file ParallelVectorMatrixAssembler.cpp.

240{
241 // checks //////////////////////////////////////////////////////////////////
242 if (dof_tables.size() != xs.size())
243 {
244 OGS_FATAL("Different number of DOF tables and solution vectors.");
245 }
246
247 std::size_t const number_of_processes = xs.size();
248 // algorithm ///////////////////////////////////////////////////////////////
249
251 ConcurrentMatrixView b_view(b);
252 ConcurrentMatrixView Jac_view(Jac);
253
254 ThreadException exception;
255#pragma omp parallel num_threads(num_threads_)
256 {
257#ifdef _OPENMP
258#pragma omp single nowait
259 {
260 INFO("Number of threads: {}", omp_get_num_threads());
261 }
262#endif
263
264 // temporary data only stored here in order to avoid frequent memory
265 // reallocations.
266 std::vector<double> local_b_data;
267 std::vector<double> local_Jac_data;
268
269 // copy to avoid concurrent access
270 auto const jac_asm = jacobian_assembler_.copy();
271 auto stats_this_thread = stats->clone();
272
273 MultiMatrixElementCache cache{b_view, Jac_view,
274 stats_this_thread->data};
275
276 auto local_matrix_output = [&](std::ptrdiff_t element_id)
277 {
278 local_matrix_output_(t, process_id, element_id, local_b_data,
279 local_Jac_data);
280 };
281
282 // TODO corner case: what if all elements on a submesh are deactivated?
283
284 // Monolithic scheme
285 if (number_of_processes == 1)
286 {
287 assert(process_id == 0);
288 auto const& dof_table = *dof_tables[0];
289 auto const& x = *xs[0];
290 auto const& x_prev = *x_prevs[0];
291
293 collectActiveLocalAssemblers(local_assemblers, active_elements),
294 exception, local_matrix_output,
295 [&](auto element_id, auto& loc_asm)
296 {
298 element_id, loc_asm, dof_table, t, dt, x, x_prev,
299 local_b_data, local_Jac_data, *jac_asm, cache);
300 });
301 }
302 else // Staggered scheme
303 {
305 collectActiveLocalAssemblers(local_assemblers, active_elements),
306 exception, local_matrix_output,
307 [&](auto element_id, auto& loc_asm)
308 {
310 element_id, loc_asm, dof_tables, t, dt, xs, x_prevs,
311 process_id, local_b_data, local_Jac_data, *jac_asm,
312 cache);
313 });
314 }
315 }
316
317 stats->print();
318
319 global_matrix_output_(t, process_id, b, Jac);
320 exception.rethrow();
321}
#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: