12#ifndef __PDETOOLS_ASSEMBLER_AssemblerUtilities_HPP
13#define __PDETOOLS_ASSEMBLER_AssemblerUtilities_HPP
22namespace Assembler_Utilities
26 std::vector<std::reference_wrapper<const Polydim::PDETools::DOFs::DOFsManager::DOFsData>>
dofs_data;
54 const unsigned int numDOFHandler = dofs_data.size();
60 for (
unsigned int i = 1; i < numDOFHandler; i++)
73template <
unsigned int dimension>
75 const unsigned int cell_index,
76 const std::vector<std::reference_wrapper<const Polydim::PDETools::DOFs::DOFsManager::DOFsData>> &dofs_data)
79 data.
num_total_dofs = dofs_data[0].get().CellsGlobalDOFs[dimension].at(cell_index).size();
81 const unsigned int numDOFHandler = dofs_data.size();
85 for (
unsigned int i = 1; i < numDOFHandler; i++)
87 data.
num_total_dofs += dofs_data[i].get().CellsGlobalDOFs[dimension].at(cell_index).size();
89 data.
offsets_DOFs[i - 1] + dofs_data[i - 1].get().CellsGlobalDOFs[dimension].at(cell_index).size();
95template <
unsigned int dimension>
99 std::vector<std::reference_wrapper<const Polydim::PDETools::DOFs::DOFsManager::DOFsData>> dofs_data_ref;
100 dofs_data_ref.reserve(1);
103 return local_count_dofs<dimension>(cell_index, dofs_data_ref);
106template <
unsigned int dimension>
108local_count_dofs(
const unsigned int cell_index,
const std::vector<Polydim::PDETools::DOFs::DOFsManager::DOFsData> &dofs_data)
110 std::vector<std::reference_wrapper<const Polydim::PDETools::DOFs::DOFsManager::DOFsData>> dofs_data_ref;
111 dofs_data_ref.reserve(dofs_data.size());
112 for (
unsigned int c = 0; c < dofs_data.size(); c++)
115 return local_count_dofs<dimension>(cell_index, dofs_data_ref);
118template <
unsigned int dimension,
typename global_solution_type>
120 const unsigned int cell_index,
121 const std::vector<std::reference_wrapper<const Polydim::PDETools::DOFs::DOFsManager::DOFsData>> &dofs_data,
122 const unsigned int &num_local_DOFs,
123 const std::vector<size_t> &local_offsets_DOFs,
124 const std::vector<size_t> &global_offsets_DOFs,
125 const std::vector<size_t> &global_offsets_Strongs,
126 const global_solution_type &global_solution_DOFs,
127 const global_solution_type &global_solution_Strongs)
129 Eigen::VectorXd local_solution_dofs = Eigen::VectorXd::Zero(num_local_DOFs);
131 const unsigned int numDOFHandler = dofs_data.size();
132 for (
unsigned int h = 0; h < numDOFHandler; h++)
134 const auto &dofs = dofs_data[h].get();
135 const auto &global_dof = dofs.CellsGlobalDOFs[dimension].at(cell_index);
136 for (
unsigned int loc_i = 0; loc_i < global_dof.size(); ++loc_i)
138 const auto &global_dof_i = global_dof.at(loc_i);
139 const auto &local_dof_i =
140 dofs.CellsDOFs.at(global_dof_i.Dimension).at(global_dof_i.CellIndex).at(global_dof_i.DOFIndex);
142 switch (local_dof_i.Type)
145 local_solution_dofs[loc_i + local_offsets_DOFs[h]] =
146 global_solution_Strongs.GetValue(local_dof_i.Global_Index + global_offsets_Strongs[h]);
149 local_solution_dofs[loc_i + local_offsets_DOFs[h]] =
150 global_solution_DOFs.GetValue(local_dof_i.Global_Index + global_offsets_DOFs[h]);
153 throw std::runtime_error(
"Unknown DOF Type");
158 return local_solution_dofs;
161template <
unsigned int dimension,
typename global_solution_type>
164 const unsigned int &num_local_DOFs,
165 const std::vector<size_t> &local_offsets_DOFs,
166 const std::vector<size_t> &global_offsets_DOFs,
167 const std::vector<size_t> &global_offsets_Strongs,
168 const global_solution_type &global_solution_DOFs,
169 const global_solution_type &global_solution_Strongs)
171 std::vector<std::reference_wrapper<const Polydim::PDETools::DOFs::DOFsManager::DOFsData>> dofs_data_ref;
172 dofs_data_ref.reserve(1);
175 return global_solution_to_local_solution<dimension, global_solution_type>(cell_index,
180 global_offsets_Strongs,
181 global_solution_DOFs,
182 global_solution_Strongs);
185template <
unsigned int dimension,
typename global_solution_type>
187 const std::vector<Polydim::PDETools::DOFs::DOFsManager::DOFsData> &dofs_data,
188 const unsigned int &num_local_DOFs,
189 const std::vector<size_t> &local_offsets_DOFs,
190 const std::vector<size_t> &global_offsets_DOFs,
191 const std::vector<size_t> &global_offsets_Strongs,
192 const global_solution_type &global_solution_DOFs,
193 const global_solution_type &global_solution_Strongs)
195 std::vector<std::reference_wrapper<const Polydim::PDETools::DOFs::DOFsManager::DOFsData>> dofs_data_ref;
196 dofs_data_ref.reserve(dofs_data.size());
197 for (
unsigned int c = 0; c < dofs_data.size(); c++)
200 return global_solution_to_local_solution<dimension, global_solution_type>(cell_index,
205 global_offsets_Strongs,
206 global_solution_DOFs,
207 global_solution_Strongs);
210template <
unsigned int dimension,
typename local_lhs_type,
typename local_rhs_type,
typename global_lhs_type,
typename global_rhs_type>
214 const local_lhs_type &local_lhs,
215 const local_rhs_type &local_rhs,
216 global_lhs_type &global_lhs_DOFs,
217 global_lhs_type &global_lhs_Strongs,
218 global_rhs_type &global_rhs)
220 for (
size_t test_f = 0; test_f < test_functions_dofs_data.
dofs_data.size(); ++test_f)
222 const auto &test_dofs_data = test_functions_dofs_data.
dofs_data.at(test_f).get();
223 const auto &test_global_dofs = test_dofs_data.CellsGlobalDOFs.at(dimension).at(cell_index);
225 const auto test_local_offset = test_functions_dofs_data.
local_offsets[test_f];
227 for (
size_t test_loc_i = 0; test_loc_i < test_global_dofs.size(); ++test_loc_i)
229 const auto global_dof_i = test_global_dofs.at(test_loc_i);
230 const auto local_dof_i =
231 test_dofs_data.CellsDOFs.at(global_dof_i.Dimension).at(global_dof_i.CellIndex).at(global_dof_i.DOFIndex);
233 switch (local_dof_i.Type)
240 throw std::runtime_error(
"Unknown DOF Type");
243 const unsigned int global_index_i = local_dof_i.Global_Index + test_global_offset_DOFs;
245 global_rhs.AddValue(global_index_i, local_rhs[test_loc_i + test_local_offset]);
247 for (
unsigned int trial_f = 0; trial_f < trial_functions_dofs_data.
dofs_data.size(); ++trial_f)
249 const auto &trial_dofs_data = trial_functions_dofs_data.
dofs_data.at(trial_f).get();
250 const auto &trial_global_dofs = trial_dofs_data.CellsGlobalDOFs.at(dimension).at(cell_index);
251 const auto trial_global_offset_DOFs = trial_functions_dofs_data.
global_offsets_DOFs[trial_f];
252 const auto trial_local_offset = trial_functions_dofs_data.
local_offsets[trial_f];
255 for (
unsigned int trial_loc_j = 0; trial_loc_j < trial_global_dofs.size(); ++trial_loc_j)
257 const auto &global_dof_j = trial_global_dofs.at(trial_loc_j);
258 const auto &local_dof_j =
259 trial_dofs_data.CellsDOFs.at(global_dof_j.Dimension).at(global_dof_j.CellIndex).at(global_dof_j.DOFIndex);
261 const unsigned int global_index_j = local_dof_j.Global_Index;
262 const double loc_A_element = local_lhs(test_loc_i + test_local_offset, trial_loc_j + trial_local_offset);
264 switch (local_dof_j.Type)
267 global_lhs_Strongs.Triplet(global_index_i, global_index_j + trial_global_offset_Strongs, loc_A_element);
270 global_lhs_DOFs.Triplet(global_index_i, global_index_j + trial_global_offset_DOFs, loc_A_element);
273 throw std::runtime_error(
"Unknown DOF Type");
281template <
unsigned int dimension,
typename local_lhs_type,
typename global_lhs_type>
285 const local_lhs_type &local_lhs,
286 global_lhs_type &global_lhs_DOFs,
287 global_lhs_type &global_lhs_Strongs)
289 for (
size_t test_f = 0; test_f < test_functions_dofs_data.
dofs_data.size(); ++test_f)
291 const auto &test_dofs_data = test_functions_dofs_data.
dofs_data.at(test_f).get();
292 const auto &test_global_dofs = test_dofs_data.CellsGlobalDOFs.at(dimension).at(cell_index);
294 const auto test_local_offset = test_functions_dofs_data.
local_offsets[test_f];
296 for (
size_t test_loc_i = 0; test_loc_i < test_global_dofs.size(); ++test_loc_i)
298 const auto global_dof_i = test_global_dofs.at(test_loc_i);
299 const auto local_dof_i =
300 test_dofs_data.CellsDOFs.at(global_dof_i.Dimension).at(global_dof_i.CellIndex).at(global_dof_i.DOFIndex);
302 switch (local_dof_i.Type)
309 throw std::runtime_error(
"Unknown DOF Type");
312 const unsigned int global_index_i = local_dof_i.Global_Index + test_global_offset_DOFs;
314 for (
unsigned int trial_f = 0; trial_f < trial_functions_dofs_data.
dofs_data.size(); ++trial_f)
316 const auto &trial_dofs_data = trial_functions_dofs_data.
dofs_data.at(trial_f).get();
317 const auto &trial_global_dofs = trial_dofs_data.CellsGlobalDOFs.at(dimension).at(cell_index);
318 const auto trial_global_offset_DOFs = trial_functions_dofs_data.
global_offsets_DOFs[trial_f];
319 const auto trial_local_offset = trial_functions_dofs_data.
local_offsets[trial_f];
322 for (
unsigned int trial_loc_j = 0; trial_loc_j < trial_global_dofs.size(); ++trial_loc_j)
324 const auto &global_dof_j = trial_global_dofs.at(trial_loc_j);
325 const auto &local_dof_j =
326 trial_dofs_data.CellsDOFs.at(global_dof_j.Dimension).at(global_dof_j.CellIndex).at(global_dof_j.DOFIndex);
328 const unsigned int global_index_j = local_dof_j.Global_Index;
329 const double loc_A_element = local_lhs(test_loc_i + test_local_offset, trial_loc_j + trial_local_offset);
331 switch (local_dof_j.Type)
334 global_lhs_Strongs.Triplet(global_index_i, global_index_j + trial_global_offset_Strongs, loc_A_element);
337 global_lhs_DOFs.Triplet(global_index_i, global_index_j + trial_global_offset_DOFs, loc_A_element);
340 throw std::runtime_error(
"Unknown DOF Type");
348template <
unsigned int dimension,
typename local_rhs_type,
typename global_rhs_type>
351 const local_rhs_type &local_rhs,
352 global_rhs_type &global_rhs)
354 for (
size_t test_f = 0; test_f < test_functions_dofs_data.
dofs_data.size(); ++test_f)
356 const auto &test_dofs_data = test_functions_dofs_data.
dofs_data.at(test_f).get();
357 const auto &test_global_dofs = test_dofs_data.CellsGlobalDOFs.at(dimension).at(cell_index);
359 const auto test_local_offset = test_functions_dofs_data.
local_offsets[test_f];
361 for (
size_t test_loc_i = 0; test_loc_i < test_global_dofs.size(); ++test_loc_i)
363 const auto global_dof_i = test_global_dofs.at(test_loc_i);
364 const auto local_dof_i =
365 test_dofs_data.CellsDOFs.at(global_dof_i.Dimension).at(global_dof_i.CellIndex).at(global_dof_i.DOFIndex);
367 switch (local_dof_i.Type)
374 throw std::runtime_error(
"Unknown DOF Type");
377 const unsigned int global_index_i = local_dof_i.Global_Index + test_global_offset_DOFs;
379 global_rhs.AddValue(global_index_i, local_rhs[test_loc_i + test_local_offset]);
Definition FEM_MCC_2D_LocalSpace.cpp:17