ASPECT
matrix_free_operators.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018 - 2024 by the authors of the ASPECT code.
3 
4  This file is part of ASPECT.
5 
6  ASPECT is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2, or (at your option)
9  any later version.
10 
11  ASPECT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with ASPECT; see the file LICENSE. If not see
18  <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef _aspect_simulator_stokes_matrix_free_operators_h
22 #define _aspect_simulator_stokes_matrix_free_operators_h
23 
24 #include <aspect/global.h>
26 #include <aspect/simulator.h>
27 
28 #include <deal.II/matrix_free/matrix_free.h>
29 #include <deal.II/matrix_free/operators.h>
30 #include <deal.II/matrix_free/fe_evaluation.h>
31 
32 #include <deal.II/multigrid/mg_constrained_dofs.h>
33 #include <deal.II/multigrid/multigrid.h>
34 #include <deal.II/multigrid/mg_transfer_matrix_free.h>
35 #include <deal.II/multigrid/mg_transfer_global_coarsening.templates.h>
36 #include <deal.II/multigrid/mg_tools.h>
37 #include <deal.II/multigrid/mg_coarse.h>
38 #include <deal.II/multigrid/mg_smoother.h>
39 #include <deal.II/multigrid/mg_matrix.h>
40 
41 #include <deal.II/lac/vector.h>
42 #include <deal.II/lac/block_vector.h>
43 #include <deal.II/lac/la_parallel_vector.h>
44 #include <deal.II/lac/la_parallel_block_vector.h>
45 
46 namespace aspect
47 {
48  namespace internal
49  {
55  namespace ChangeVectorTypes
56  {
57  void import(aspect::LinearAlgebra::Vector &out,
58  const ::LinearAlgebra::ReadWriteVector<double> &rwv,
59  const VectorOperation::values operation);
60 
62  const ::LinearAlgebra::distributed::Vector<double> &in);
63 
64  void copy(::LinearAlgebra::distributed::Vector<double> &out,
66 
68  const ::LinearAlgebra::distributed::BlockVector<double> &in);
69 
70  void copy(::LinearAlgebra::distributed::BlockVector<double> &out,
72  }
73  }
74 
78  namespace MatrixFreeStokesOperators
79  {
80 
91  template <int dim, typename number>
93  {
98 
103 
108 
113 
119 
124 
129 
136  Table<2, VectorizedArray<number>> viscosity;
137 
142  Table<2, SymmetricTensor<2, dim, VectorizedArray<number>>> strain_rate_table;
143 
149  Table<2, VectorizedArray<number>> newton_factor_wrt_pressure_table;
150 
158  Table<2, SymmetricTensor<2, dim, VectorizedArray<number>>>
160 
166  Table<2, VectorizedArray<number>> dilation_lhs_term_table;
167 
175  Table<2, VectorizedArray<number>>
177 
182  Table<2, SymmetricTensor<2, dim, VectorizedArray<number>>>
184 
190  Table<2, Tensor<1, dim, VectorizedArray<number>>> free_surface_stabilization_term_table;
191 
195  std::set<types::boundary_id> free_surface_boundary_indicators;
196 
201  std::size_t
202  memory_consumption() const;
203 
207  void clear();
208  };
209 
213  template <int dim, int degree_v, typename number>
215  : public MatrixFreeOperators::Base<dim, ::LinearAlgebra::distributed::BlockVector<number>>
216  {
217  public:
218 
222  StokesOperator ();
223 
227  void clear () override;
228 
232  void set_cell_data (const OperatorCellData<dim,number> &data);
233 
239  void compute_diagonal () override;
240 
241  private:
242 
247  void apply_add (::LinearAlgebra::distributed::BlockVector<number> &dst,
248  const ::LinearAlgebra::distributed::BlockVector<number> &src) const override;
249 
253  void local_apply (const ::MatrixFree<dim, number> &data,
254  ::LinearAlgebra::distributed::BlockVector<number> &dst,
255  const ::LinearAlgebra::distributed::BlockVector<number> &src,
256  const std::pair<unsigned int, unsigned int> &cell_range) const;
257 
261  void local_apply_face (const ::MatrixFree<dim, number> &data,
262  ::LinearAlgebra::distributed::BlockVector<number> &dst,
263  const ::LinearAlgebra::distributed::BlockVector<number> &src,
264  const std::pair<unsigned int, unsigned int> &face_range) const;
265 
269  void local_apply_boundary_face (const ::MatrixFree<dim, number> &data,
270  ::LinearAlgebra::distributed::BlockVector<number> &dst,
271  const ::LinearAlgebra::distributed::BlockVector<number> &src,
272  const std::pair<unsigned int, unsigned int> &face_range) const;
273 
278  };
279 
280 
281 
285  template <int dim, int degree_v, typename number>
287  : public MatrixFreeOperators::Base<dim, ::LinearAlgebra::distributed::BlockVector<number>>
288  {
289  public:
290 
294  BTBlockOperator ();
295 
299  void clear () override;
300 
304  void set_cell_data (const OperatorCellData<dim,number> &data);
305 
311  void compute_diagonal () override;
312 
313  private:
314 
319  void apply_add (::LinearAlgebra::distributed::BlockVector<number> &dst,
320  const ::LinearAlgebra::distributed::BlockVector<number> &src) const override;
321 
325  void local_apply (const ::MatrixFree<dim, number> &data,
326  ::LinearAlgebra::distributed::BlockVector<number> &dst,
327  const ::LinearAlgebra::distributed::BlockVector<number> &src,
328  const std::pair<unsigned int, unsigned int> &cell_range) const;
329 
333  void local_apply_face (const ::MatrixFree<dim, number> &data,
334  ::LinearAlgebra::distributed::BlockVector<number> &dst,
335  const ::LinearAlgebra::distributed::BlockVector<number> &src,
336  const std::pair<unsigned int, unsigned int> &face_range) const;
337 
342  };
343 
344 
345 
349  template <int dim, int degree_p, typename number>
351  : public MatrixFreeOperators::Base<dim, ::LinearAlgebra::distributed::Vector<number>>
352  {
353  public:
354 
359 
363  void clear () override;
364 
369  void reinit(const Mapping<dim> &mapping,
370  const DoFHandler<dim> &dof_handler_v,
371  const DoFHandler<dim> &dof_handler_p,
372  const AffineConstraints<number> &constraints_v,
373  const AffineConstraints<number> &constraints_p,
374  std::shared_ptr<MatrixFree<dim,double>> mf_storage,
375  const unsigned int level = numbers::invalid_unsigned_int);
376 
380  void set_cell_data (const OperatorCellData<dim,number> &data);
381 
387  void compute_diagonal () override;
388 
389  private:
390 
395  void apply_add (::LinearAlgebra::distributed::Vector<number> &dst,
396  const ::LinearAlgebra::distributed::Vector<number> &src) const override;
397 
401  void local_apply (const ::MatrixFree<dim, number> &data,
402  ::LinearAlgebra::distributed::Vector<number> &dst,
403  const ::LinearAlgebra::distributed::Vector<number> &src,
404  const std::pair<unsigned int, unsigned int> &cell_range) const;
405 
409  void inner_cell_operation(FEEvaluation<dim,
410  degree_p,
411  degree_p+2,
412  1,
413  number> &pressure) const;
414 
419  };
420 
425  template <int dim, int degree_v, typename number>
427  : public MatrixFreeOperators::Base<dim, ::LinearAlgebra::distributed::Vector<number>>
428  {
429  public:
430 
434  ABlockOperator ();
435 
439  void clear () override;
440 
445  void reinit(const Mapping<dim> &mapping,
446  const DoFHandler<dim> &dof_handler_v,
447  const DoFHandler<dim> &dof_handler_p,
448  const AffineConstraints<number> &constraints_v,
449  const AffineConstraints<number> &constraints_p,
450  std::shared_ptr<MatrixFree<dim,double>> mf_storage,
451  const unsigned int level = numbers::invalid_unsigned_int);
455  void set_cell_data (const OperatorCellData<dim,number> &data);
456 
462  void compute_diagonal () override;
463 
469  void set_diagonal (const ::LinearAlgebra::distributed::Vector<number> &diag);
470 
471  private:
476  void inner_cell_operation(FEEvaluation<dim,
477  degree_v,
478  degree_v+1,
479  dim,
480  number> &velocity) const;
481 
486  void cell_operation(FEEvaluation<dim,
487  degree_v,
488  degree_v+1,
489  dim,
490  number> &velocity) const;
491 
497  void apply_add (::LinearAlgebra::distributed::Vector<number> &dst,
498  const ::LinearAlgebra::distributed::Vector<number> &src) const override;
499 
503  void local_apply (const ::MatrixFree<dim, number> &data,
504  ::LinearAlgebra::distributed::Vector<number> &dst,
505  const ::LinearAlgebra::distributed::Vector<number> &src,
506  const std::pair<unsigned int, unsigned int> &cell_range) const;
507 
512  };
513  }
514 
515 }
516 
517 #endif
Table< 2, VectorizedArray< number > > dilation_derivative_wrt_pressure_table
const OperatorCellData< dim, number > * cell_data
std::set< types::boundary_id > free_surface_boundary_indicators
::TrilinosWrappers::MPI::BlockVector BlockVector
Definition: global.h:269
const OperatorCellData< dim, number > * cell_data
void copy(aspect::LinearAlgebra::Vector &out, const ::LinearAlgebra::distributed::Vector< double > &in)
Table< 2, Tensor< 1, dim, VectorizedArray< number > > > free_surface_stabilization_term_table
::TrilinosWrappers::MPI::Vector Vector
Definition: global.h:263
const OperatorCellData< dim, number > * cell_data
Table< 2, SymmetricTensor< 2, dim, VectorizedArray< number > > > strain_rate_table
const OperatorCellData< dim, number > * cell_data
Table< 2, SymmetricTensor< 2, dim, VectorizedArray< number > > > dilation_derivative_wrt_strain_rate_table
Table< 2, VectorizedArray< number > > dilation_lhs_term_table
Table< 2, SymmetricTensor< 2, dim, VectorizedArray< number > > > newton_factor_wrt_strain_rate_table
Table< 2, VectorizedArray< number > > newton_factor_wrt_pressure_table