OGS
anonymous_namespace{ParallelVectorMatrixAssembler.cpp} Namespace Reference

Functions

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)
 
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 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)
 

Function Documentation

◆ assembleWithJacobianForStaggeredSchemeOneElement()

void anonymous_namespace{ParallelVectorMatrixAssembler.cpp}::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 )

Definition at line 61 of file ParallelVectorMatrixAssembler.cpp.

70{
71 std::vector<std::vector<GlobalIndexType>> indices_of_processes;
72 indices_of_processes.reserve(dof_tables.size());
73 transform(cbegin(dof_tables), cend(dof_tables),
74 back_inserter(indices_of_processes),
75 [&](auto const* dof_table)
76 { return NumLib::getIndices(mesh_item_id, *dof_table); });
77
78 auto local_coupled_xs =
79 ProcessLib::getCoupledLocalSolutions(x, indices_of_processes);
80 auto const local_x = MathLib::toVector(local_coupled_xs);
81
82 auto local_coupled_x_prevs =
83 ProcessLib::getCoupledLocalSolutions(x_prev, indices_of_processes);
84 auto const local_x_prev = MathLib::toVector(local_coupled_x_prevs);
85
86 std::vector<GlobalIndexType> const& indices =
87 indices_of_processes[process_id];
88
89 local_b_data.clear();
90 local_Jac_data.clear();
91
93 local_assembler, t, dt, local_x, local_x_prev, process_id, local_b_data,
94 local_Jac_data);
95
96 if (local_Jac_data.empty())
97 {
99 "No Jacobian has been assembled! This might be due to "
100 "programming errors in the local assembler of the "
101 "current process.");
102 }
103
104 cache.add(local_b_data, local_Jac_data, indices);
105}
#define OGS_FATAL(...)
Definition Error.h:26
virtual void assembleWithJacobianForStaggeredScheme(LocalAssemblerInterface &, double const, double const, Eigen::VectorXd const &, Eigen::VectorXd const &, int const, std::vector< double > &, std::vector< double > &)
void add(std::vector< double > const &local_b_data, std::vector< double > const &local_Jac_data, std::vector< GlobalIndexType > const &indices)
Eigen::Map< const Vector > toVector(std::vector< double > const &data, Eigen::VectorXd::Index size)
Creates an Eigen mapped vector from the given data vector.
std::vector< GlobalIndexType > getIndices(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table)
std::vector< double > getCoupledLocalSolutions(std::vector< GlobalVector * > const &global_solutions, std::vector< std::vector< GlobalIndexType > > const &indices)

References ProcessLib::Assembly::MultiMatrixElementCache::add(), ProcessLib::AbstractJacobianAssembler::assembleWithJacobianForStaggeredScheme(), ProcessLib::getCoupledLocalSolutions(), NumLib::getIndices(), OGS_FATAL, and MathLib::toVector().

◆ assembleWithJacobianOneElement()

void anonymous_namespace{ParallelVectorMatrixAssembler.cpp}::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 )

Definition at line 29 of file ParallelVectorMatrixAssembler.cpp.

37{
38 std::vector<GlobalIndexType> const& indices =
39 NumLib::getIndices(mesh_item_id, dof_table);
40
41 local_b_data.clear();
42 local_Jac_data.clear();
43
44 auto const local_x = x.get(indices);
45 auto const local_x_prev = x_prev.get(indices);
46 jacobian_assembler.assembleWithJacobian(local_assembler, t, dt, local_x,
47 local_x_prev, local_b_data,
48 local_Jac_data);
49
50 if (local_Jac_data.empty())
51 {
53 "No Jacobian has been assembled! This might be due to "
54 "programming errors in the local assembler of the "
55 "current process.");
56 }
57
58 cache.add(local_b_data, local_Jac_data, indices);
59}
double get(IndexType rowId) const
get entry
Definition EigenVector.h:59
virtual void assembleWithJacobian(LocalAssemblerInterface &local_assembler, double const t, double const dt, std::vector< double > const &local_x, std::vector< double > const &local_x_prev, std::vector< double > &local_b_data, std::vector< double > &local_Jac_data)=0

References ProcessLib::Assembly::MultiMatrixElementCache::add(), ProcessLib::AbstractJacobianAssembler::assembleWithJacobian(), MathLib::EigenVector::get(), NumLib::getIndices(), and OGS_FATAL.

◆ collectActiveLocalAssemblers()

std::vector< std::tuple< std::ptrdiff_t, std::reference_wrapper< ProcessLib::LocalAssemblerInterface > > > anonymous_namespace{ParallelVectorMatrixAssembler.cpp}::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.

Definition at line 111 of file ParallelVectorMatrixAssembler.cpp.

115{
116 auto create_ids_asm_pairs = [&](auto const& element_ids)
117 {
118 std::vector<std::tuple<
119 std::ptrdiff_t,
120 std::reference_wrapper<ProcessLib::LocalAssemblerInterface>>>
121 result;
122 result.reserve(static_cast<std::size_t>(element_ids.size()));
123 for (auto const id : element_ids)
124 {
125 result.push_back({id, local_assemblers[id]});
126 }
127 return result;
128 };
129
130 if (active_elements.empty())
131 {
132 return create_ids_asm_pairs(ranges::views::iota(
133 static_cast<std::size_t>(0), local_assemblers.size()));
134 }
135 return create_ids_asm_pairs(active_elements);
136}

◆ runAssembly()

void anonymous_namespace{ParallelVectorMatrixAssembler.cpp}::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 )

Definition at line 138 of file ParallelVectorMatrixAssembler.cpp.

146{
147 std::ptrdiff_t n_elements =
148 static_cast<std::ptrdiff_t>(ids_local_assemblers.size());
149
150#pragma omp for nowait
151 for (std::ptrdiff_t i = 0; i < n_elements; ++i)
152 {
153 if (exception)
154 {
155 continue;
156 }
157 auto [element_id, loc_asm] = ids_local_assemblers[i];
158
159 try
160 {
161 assemble(element_id, loc_asm);
162 }
163 catch (...)
164 {
165 exception.capture();
166 continue;
167 }
168
169 local_matrix_output(element_id);
170 }
171}

References ThreadException::capture().