ASPECT
stokes_matrix_free.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 
22 #ifndef _aspect_stokes_matrix_free_h
23 #define _aspect_stokes_matrix_free_h
24 
25 #include <aspect/global.h>
26 
27 #include <aspect/simulator.h>
28 
29 #include <deal.II/matrix_free/matrix_free.h>
30 #include <deal.II/matrix_free/operators.h>
31 #include <deal.II/matrix_free/fe_evaluation.h>
32 
33 #include <deal.II/multigrid/mg_constrained_dofs.h>
34 #include <deal.II/multigrid/multigrid.h>
35 #include <deal.II/multigrid/mg_transfer_matrix_free.h>
36 #include <deal.II/multigrid/mg_transfer_global_coarsening.templates.h>
37 #include <deal.II/multigrid/mg_tools.h>
38 #include <deal.II/multigrid/mg_coarse.h>
39 #include <deal.II/multigrid/mg_smoother.h>
40 #include <deal.II/multigrid/mg_matrix.h>
41 
42 #include <deal.II/lac/vector.h>
43 #include <deal.II/lac/block_vector.h>
44 #include <deal.II/lac/la_parallel_vector.h>
45 #include <deal.II/lac/la_parallel_block_vector.h>
46 
50 using GMGNumberType = double;
51 
52 namespace aspect
53 {
54  using namespace dealii;
55 
56  namespace internal
57  {
63  namespace ChangeVectorTypes
64  {
65  void import(TrilinosWrappers::MPI::Vector &out,
66  const ::LinearAlgebra::ReadWriteVector<double> &rwv,
67  const VectorOperation::values operation);
68 
70  const ::LinearAlgebra::distributed::Vector<double> &in);
71 
72  void copy(::LinearAlgebra::distributed::Vector<double> &out,
74 
76  const ::LinearAlgebra::distributed::BlockVector<double> &in);
77 
78  void copy(::LinearAlgebra::distributed::BlockVector<double> &out,
80  }
81  }
82 
86  namespace MatrixFreeStokesOperators
87  {
88 
99  template <int dim, typename number>
101  {
106 
111 
116 
122 
127 
134  Table<2, VectorizedArray<number>> viscosity;
135 
140  Table<2, SymmetricTensor<2, dim, VectorizedArray<number>>> strain_rate_table;
141 
147  Table<2, VectorizedArray<number>> newton_factor_wrt_pressure_table;
148 
156  Table<2, SymmetricTensor<2, dim, VectorizedArray<number>>>
158 
164  Table<2, Tensor<1, dim, VectorizedArray<number>>> free_surface_stabilization_term_table;
165 
169  std::set<types::boundary_id> free_surface_boundary_indicators;
170 
175  std::size_t
176  memory_consumption() const;
177 
181  void clear();
182  };
183 
187  template <int dim, int degree_v, typename number>
189  : public MatrixFreeOperators::Base<dim, ::LinearAlgebra::distributed::BlockVector<number>>
190  {
191  public:
192 
196  StokesOperator ();
197 
201  void clear () override;
202 
206  void set_cell_data (const OperatorCellData<dim,number> &data);
207 
213  void compute_diagonal () override;
214 
215  private:
216 
221  void apply_add (::LinearAlgebra::distributed::BlockVector<number> &dst,
222  const ::LinearAlgebra::distributed::BlockVector<number> &src) const override;
223 
227  void local_apply (const ::MatrixFree<dim, number> &data,
228  ::LinearAlgebra::distributed::BlockVector<number> &dst,
229  const ::LinearAlgebra::distributed::BlockVector<number> &src,
230  const std::pair<unsigned int, unsigned int> &cell_range) const;
231 
235  void local_apply_face (const ::MatrixFree<dim, number> &data,
236  ::LinearAlgebra::distributed::BlockVector<number> &dst,
237  const ::LinearAlgebra::distributed::BlockVector<number> &src,
238  const std::pair<unsigned int, unsigned int> &face_range) const;
239 
243  void local_apply_boundary_face (const ::MatrixFree<dim, number> &data,
244  ::LinearAlgebra::distributed::BlockVector<number> &dst,
245  const ::LinearAlgebra::distributed::BlockVector<number> &src,
246  const std::pair<unsigned int, unsigned int> &face_range) const;
247 
252  };
253 
257  template <int dim, int degree_p, typename number>
259  : public MatrixFreeOperators::Base<dim, ::LinearAlgebra::distributed::Vector<number>>
260  {
261  public:
262 
267 
271  void clear () override;
272 
276  void set_cell_data (const OperatorCellData<dim,number> &data);
277 
283  void compute_diagonal () override;
284 
285  private:
286 
291  void apply_add (::LinearAlgebra::distributed::Vector<number> &dst,
292  const ::LinearAlgebra::distributed::Vector<number> &src) const override;
293 
297  void local_apply (const ::MatrixFree<dim, number> &data,
298  ::LinearAlgebra::distributed::Vector<number> &dst,
299  const ::LinearAlgebra::distributed::Vector<number> &src,
300  const std::pair<unsigned int, unsigned int> &cell_range) const;
301 
302 
306  void local_compute_diagonal (const MatrixFree<dim,number> &data,
307  ::LinearAlgebra::distributed::Vector<number> &dst,
308  const unsigned int &dummy,
309  const std::pair<unsigned int,unsigned int> &cell_range) const;
310 
315  };
316 
321  template <int dim, int degree_v, typename number>
323  : public MatrixFreeOperators::Base<dim, ::LinearAlgebra::distributed::Vector<number>>
324  {
325  public:
326 
330  ABlockOperator ();
331 
335  void clear () override;
336 
340  void set_cell_data (const OperatorCellData<dim,number> &data);
341 
347  void compute_diagonal () override;
348 
354  void set_diagonal (const ::LinearAlgebra::distributed::Vector<number> &diag);
355 
356  private:
361  void inner_cell_operation(FEEvaluation<dim,
362  degree_v,
363  degree_v+1,
364  dim,
365  number> &velocity) const;
366 
371  void cell_operation(FEEvaluation<dim,
372  degree_v,
373  degree_v+1,
374  dim,
375  number> &velocity) const;
376 
382  void apply_add (::LinearAlgebra::distributed::Vector<number> &dst,
383  const ::LinearAlgebra::distributed::Vector<number> &src) const override;
384 
388  void local_apply (const ::MatrixFree<dim, number> &data,
389  ::LinearAlgebra::distributed::Vector<number> &dst,
390  const ::LinearAlgebra::distributed::Vector<number> &src,
391  const std::pair<unsigned int, unsigned int> &cell_range) const;
392 
397  };
398  }
399 
404  template <int dim>
406  {
407  public:
411  virtual ~StokesMatrixFreeHandler() = default;
412 
422  virtual std::pair<double,double> solve(LinearAlgebra::BlockVector &solution_vector) = 0;
423 
428  virtual void setup_dofs()=0;
429 
437  virtual void assemble()=0;
438 
444  virtual void build_preconditioner()=0;
445 
449  static
450  void declare_parameters (ParameterHandler &prm);
451 
456  virtual const DoFHandler<dim> &
457  get_dof_handler_v () const = 0;
458 
463  virtual const DoFHandler<dim> &
464  get_dof_handler_p () const = 0;
465 
470  virtual const DoFHandler<dim> &
471  get_dof_handler_projection () const = 0;
472 
477  virtual const AffineConstraints<double> &
478  get_constraints_v () const = 0;
479 
484  virtual const AffineConstraints<double> &
485  get_constraints_p () const = 0;
486 
491  virtual const MGTransferMF<dim,GMGNumberType> &
492  get_mg_transfer_A () const = 0;
493 
498  virtual const MGTransferMF<dim,GMGNumberType> &
499  get_mg_transfer_S () const = 0;
500 
505  virtual std::size_t get_cell_data_memory_consumption() const = 0;
506  };
507 
518  template <int dim, int velocity_degree>
520  {
521  public:
528  StokesMatrixFreeHandlerImplementation(Simulator<dim> &, ParameterHandler &prm);
529 
533  ~StokesMatrixFreeHandlerImplementation() override = default;
534 
544  std::pair<double,double> solve(LinearAlgebra::BlockVector &solution_vector) override;
545 
550  void setup_dofs() override;
551 
559  void assemble() override;
560 
565  void build_preconditioner() override;
566 
570  static
571  void declare_parameters (ParameterHandler &prm);
572 
577  const DoFHandler<dim> &
578  get_dof_handler_v () const override;
579 
584  const DoFHandler<dim> &
585  get_dof_handler_p () const override;
586 
591  const DoFHandler<dim> &
592  get_dof_handler_projection () const override;
593 
598  const AffineConstraints<double> &
599  get_constraints_v () const override;
600 
605  const AffineConstraints<double> &
606  get_constraints_p () const override;
607 
613  get_mg_transfer_A () const override;
614 
620  get_mg_transfer_S () const override;
621 
622 
627  std::size_t get_cell_data_memory_consumption() const override;
628 
629  private:
633  void parse_parameters (ParameterHandler &prm);
634 
640  void evaluate_material_model();
641 
646  void correct_stokes_rhs();
647 
648 
650 
652 
658 
664 
665  DoFHandler<dim> dof_handler_v;
666  DoFHandler<dim> dof_handler_p;
667  DoFHandler<dim> dof_handler_projection;
668 
669  FESystem<dim> fe_v;
670  FESystem<dim> fe_p;
671  FESystem<dim> fe_projection;
672 
677 
681  MGLevelObject<MatrixFreeStokesOperators::OperatorCellData<dim, GMGNumberType>> level_cell_data;
682 
686 
689 
693 
694  AffineConstraints<double> constraints_v;
695  AffineConstraints<double> constraints_p;
696 
697  MGLevelObject<GMGABlockMatrixType> mg_matrices_A_block;
698  MGLevelObject<GMGSchurComplementMatrixType> mg_matrices_Schur_complement;
699 
700  MGConstrainedDoFs mg_constrained_dofs_A_block;
703 
706 
707  std::vector<std::shared_ptr<MatrixFree<dim,double>>> matrix_free_objects;
708  };
709 }
710 
711 
712 #endif
const OperatorCellData< dim, number > * cell_data
std::set< types::boundary_id > free_surface_boundary_indicators
MGLevelObject< MatrixFreeStokesOperators::OperatorCellData< dim, GMGNumberType > > level_cell_data
::TrilinosWrappers::MPI::BlockVector BlockVector
Definition: global.h:261
MatrixFreeStokesOperators::OperatorCellData< dim, GMGNumberType > active_cell_data
MGLevelObject< GMGSchurComplementMatrixType > mg_matrices_Schur_complement
MGLevelObject< GMGABlockMatrixType > mg_matrices_A_block
const OperatorCellData< dim, number > * cell_data
Table< 2, Tensor< 1, dim, VectorizedArray< number > > > free_surface_stabilization_term_table
void copy(::LinearAlgebra::distributed::BlockVector< double > &out, const TrilinosWrappers::MPI::BlockVector &in)
::TrilinosWrappers::MPI::Vector Vector
Definition: global.h:255
const OperatorCellData< dim, number > * cell_data
void declare_parameters(ParameterHandler &prm)
Table< 2, SymmetricTensor< 2, dim, VectorizedArray< number > > > strain_rate_table
MGTransferMF< dim, GMGNumberType > mg_transfer_A_block
MGTransferMatrixFree< dim, NumberType > MGTransferMF
Definition: compat.h:45
std::vector< std::shared_ptr< MatrixFree< dim, double > > > matrix_free_objects
Definition: compat.h:59
MGTransferMF< dim, GMGNumberType > mg_transfer_Schur_complement
Table< 2, VectorizedArray< number > > viscosity
Table< 2, SymmetricTensor< 2, dim, VectorizedArray< number > > > newton_factor_wrt_strain_rate_table
SchurComplementMatrixType Schur_complement_block_matrix
Definition: compat.h:42
Table< 2, VectorizedArray< number > > newton_factor_wrt_pressure_table
double GMGNumberType