16 #include <deal.II/base/function.h> 17 #include <deal.II/base/quadrature.h> 18 #include <deal.II/base/work_stream.h> 19 #include <deal.II/base/geometry_info.h> 20 #include <deal.II/base/quadrature.h> 21 #include <deal.II/dofs/dof_handler.h> 22 #include <deal.II/dofs/dof_accessor.h> 23 #include <deal.II/dofs/dof_tools.h> 24 #include <deal.II/fe/fe.h> 25 #include <deal.II/fe/fe_values.h> 26 #include <deal.II/fe/mapping_q1.h> 27 #include <deal.II/grid/tria_iterator.h> 28 #include <deal.II/hp/fe_values.h> 29 #include <deal.II/hp/mapping_collection.h> 30 #include <deal.II/numerics/matrix_tools.h> 31 #include <deal.II/lac/vector.h> 32 #include <deal.II/lac/block_vector.h> 33 #include <deal.II/lac/full_matrix.h> 34 #include <deal.II/lac/sparse_matrix.h> 35 #include <deal.II/lac/block_sparse_matrix.h> 37 #ifdef DEAL_II_WITH_PETSC 38 # include <deal.II/lac/petsc_parallel_sparse_matrix.h> 39 # include <deal.II/lac/petsc_sparse_matrix.h> 40 # include <deal.II/lac/petsc_parallel_vector.h> 41 # include <deal.II/lac/petsc_vector.h> 42 # include <deal.II/lac/petsc_parallel_block_sparse_matrix.h> 45 #ifdef DEAL_II_WITH_TRILINOS 46 # include <deal.II/lac/trilinos_sparse_matrix.h> 47 # include <deal.II/lac/trilinos_vector.h> 48 # include <deal.II/lac/trilinos_block_sparse_matrix.h> 49 # include <deal.II/lac/trilinos_block_vector.h> 57 DEAL_II_NAMESPACE_OPEN
62 #ifdef DEAL_II_WITH_PETSC 68 template <
typename PETScMatrix,
typename PETScVector>
72 PETScVector &solution,
73 PETScVector &right_hand_side,
74 const bool eliminate_columns)
76 (void)eliminate_columns;
79 Assert (matrix.n() == right_hand_side.size(),
81 Assert (matrix.n() == solution.size(),
87 if (boundary_values.size() > 0)
89 const std::pair<types::global_dof_index, types::global_dof_index> local_range
90 = matrix.local_range();
91 Assert (local_range == right_hand_side.local_range(),
93 Assert (local_range == solution.local_range(),
100 PetscScalar average_nonzero_diagonal_entry = 1;
102 if (matrix.diag_element(i) != PetscScalar ())
104 average_nonzero_diagonal_entry = std::abs(matrix.diag_element(i));
110 std::vector<types::global_dof_index> constrained_rows;
111 for (std::map<types::global_dof_index,PetscScalar>::const_iterator
112 dof = boundary_values.begin();
113 dof != boundary_values.end();
115 if ((dof->first >= local_range.first) &&
116 (dof->first < local_range.second))
117 constrained_rows.push_back (dof->first);
130 matrix.clear_rows (constrained_rows, average_nonzero_diagonal_entry);
132 std::vector<types::global_dof_index> indices;
133 std::vector<PetscScalar> solution_values;
134 for (std::map<types::global_dof_index,PetscScalar>::const_iterator
135 dof = boundary_values.begin();
136 dof != boundary_values.end();
138 if ((dof->first >= local_range.first) &&
139 (dof->first < local_range.second))
141 indices.push_back (dof->first);
142 solution_values.push_back (dof->second);
144 solution.set (indices, solution_values);
148 for (
unsigned int i=0; i<solution_values.size(); ++i)
149 solution_values[i] *= average_nonzero_diagonal_entry;
151 right_hand_side.set (indices, solution_values);
157 std::vector<types::global_dof_index> constrained_rows;
158 matrix.clear_rows (constrained_rows, 1.);
175 const bool eliminate_columns)
179 internal::PETScWrappers::apply_boundary_values (boundary_values, matrix, solution,
180 right_hand_side, eliminate_columns);
190 const bool eliminate_columns)
194 internal::PETScWrappers::apply_boundary_values (boundary_values, matrix, solution,
195 right_hand_side, eliminate_columns);
204 const bool eliminate_columns)
210 Assert (matrix.n_block_rows() == matrix.n_block_cols(),
213 const unsigned int n_blocks = matrix.n_block_rows();
219 std::vector<std::map<::types::global_dof_index,PetscScalar> > block_boundary_values(n_blocks);
223 for (std::map<types::global_dof_index,PetscScalar>::const_iterator
224 dof = boundary_values.begin();
225 dof != boundary_values.end();
228 if (dof->first >= matrix.block(block,0).m() + offset)
230 offset += matrix.block(block,0).m();
234 block_boundary_values[block].insert(std::pair<types::global_dof_index, PetscScalar> (index,dof->second));
241 for (
unsigned int block=0; block<n_blocks; ++block)
242 internal::PETScWrappers::apply_boundary_values(block_boundary_values[block],
243 matrix.block(block,block),
244 solution.
block(block),
245 right_hand_side.
block(block),
252 for (
unsigned int block_m=0; block_m<n_blocks; ++block_m)
254 const std::pair<types::global_dof_index, types::global_dof_index> local_range
255 = matrix.block(block_m,0).local_range();
257 std::vector<types::global_dof_index> constrained_rows;
258 for (std::map<types::global_dof_index,PetscScalar>::const_iterator
259 dof = block_boundary_values[block_m].begin();
260 dof != block_boundary_values[block_m].end();
262 if ((dof->first >= local_range.first) &&
263 (dof->first < local_range.second))
264 constrained_rows.push_back (dof->first);
266 for (
unsigned int block_n=0; block_n<n_blocks; ++block_n)
267 if (block_m != block_n)
268 matrix.block(block_m,block_n).clear_rows(constrained_rows);
276 #ifdef DEAL_II_WITH_TRILINOS 282 template <
typename TrilinosMatrix,
typename TrilinosVector>
285 TrilinosMatrix &matrix,
286 TrilinosVector &solution,
287 TrilinosVector &right_hand_side,
288 const bool eliminate_columns)
291 (void)eliminate_columns;
293 Assert (matrix.n() == right_hand_side.size(),
295 Assert (matrix.n() == solution.size(),
301 if (boundary_values.size() > 0)
303 const std::pair<types::global_dof_index, types::global_dof_index> local_range
304 = matrix.local_range();
305 Assert (local_range == right_hand_side.local_range(),
307 Assert (local_range == solution.local_range(),
314 TrilinosScalar average_nonzero_diagonal_entry = 1;
316 if (matrix.diag_element(i) != 0)
318 average_nonzero_diagonal_entry = std::fabs(matrix.diag_element(i));
324 std::vector<types::global_dof_index> constrained_rows;
325 for (std::map<types::global_dof_index,TrilinosScalar>::const_iterator
326 dof = boundary_values.begin();
327 dof != boundary_values.end();
329 if ((dof->first >= local_range.first) &&
330 (dof->first < local_range.second))
331 constrained_rows.push_back (dof->first);
340 matrix.clear_rows (constrained_rows, average_nonzero_diagonal_entry);
342 std::vector<types::global_dof_index> indices;
343 std::vector<TrilinosScalar> solution_values;
344 for (std::map<types::global_dof_index,TrilinosScalar>::const_iterator
345 dof = boundary_values.begin();
346 dof != boundary_values.end();
348 if ((dof->first >= local_range.first) &&
349 (dof->first < local_range.second))
351 indices.push_back (dof->first);
352 solution_values.push_back (dof->second);
354 solution.set (indices, solution_values);
358 for (
unsigned int i=0; i<solution_values.size(); ++i)
359 solution_values[i] *= matrix.diag_element(indices[i]);
361 right_hand_side.set (indices, solution_values);
367 std::vector<types::global_dof_index> constrained_rows;
368 matrix.clear_rows (constrained_rows, 1.);
379 template <
typename TrilinosMatrix,
typename TrilinosBlockVector>
381 apply_block_boundary_values (
const std::map<types::global_dof_index,TrilinosScalar> &boundary_values,
382 TrilinosMatrix &matrix,
383 TrilinosBlockVector &solution,
384 TrilinosBlockVector &right_hand_side,
385 const bool eliminate_columns)
389 Assert (matrix.n() == right_hand_side.size(),
391 Assert (matrix.n() == solution.size(),
393 Assert (matrix.n_block_rows() == matrix.n_block_cols(),
396 const unsigned int n_blocks = matrix.n_block_rows();
402 std::vector<std::map<types::global_dof_index,TrilinosScalar> > block_boundary_values(n_blocks);
406 for (std::map<types::global_dof_index,TrilinosScalar>::const_iterator
407 dof = boundary_values.begin();
408 dof != boundary_values.end();
411 if (dof->first >= matrix.block(block,0).m() + offset)
413 offset += matrix.block(block,0).m();
417 block_boundary_values[block].insert(
418 std::pair<types::global_dof_index, TrilinosScalar> (index,dof->second));
425 for (
unsigned int block=0; block<n_blocks; ++block)
426 TrilinosWrappers::apply_boundary_values(block_boundary_values[block],
427 matrix.block(block,block),
428 solution.block(block),
429 right_hand_side.block(block),
436 for (
unsigned int block_m=0; block_m<n_blocks; ++block_m)
438 const std::pair<types::global_dof_index, types::global_dof_index> local_range
439 = matrix.block(block_m,0).local_range();
441 std::vector<types::global_dof_index> constrained_rows;
442 for (std::map<types::global_dof_index,TrilinosScalar>::const_iterator
443 dof = block_boundary_values[block_m].begin();
444 dof != block_boundary_values[block_m].end();
446 if ((dof->first >= local_range.first) &&
447 (dof->first < local_range.second))
448 constrained_rows.push_back (dof->first);
450 for (
unsigned int block_n=0; block_n<n_blocks; ++block_n)
451 if (block_m != block_n)
452 matrix.block(block_m,block_n).clear_rows(constrained_rows);
466 const bool eliminate_columns)
470 internal::TrilinosWrappers::apply_boundary_values (boundary_values, matrix, solution,
471 right_hand_side, eliminate_columns);
481 const bool eliminate_columns)
485 internal::TrilinosWrappers::apply_boundary_values (boundary_values, matrix, solution,
486 right_hand_side, eliminate_columns);
496 const bool eliminate_columns)
498 internal::TrilinosWrappers::apply_block_boundary_values (boundary_values, matrix,
499 solution, right_hand_side,
510 const bool eliminate_columns)
512 internal::TrilinosWrappers::apply_block_boundary_values (boundary_values, matrix,
513 solution, right_hand_side,
521 DEAL_II_NAMESPACE_CLOSE
unsigned int global_dof_index
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcNotQuadratic()
static ::ExceptionBase & ExcNotImplemented()
BlockType & block(const unsigned int i)
static ::ExceptionBase & ExcInternalError()