ASPECT
stokes_matrix_free.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018 - 2023 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 
417  virtual std::pair<double,double> solve()=0;
418 
423  virtual void setup_dofs()=0;
424 
432  virtual void assemble()=0;
433 
439  virtual void build_preconditioner()=0;
440 
444  static
445  void declare_parameters (ParameterHandler &prm);
446 
451  virtual const DoFHandler<dim> &
452  get_dof_handler_v () const = 0;
453 
458  virtual const DoFHandler<dim> &
459  get_dof_handler_p () const = 0;
460 
465  virtual const DoFHandler<dim> &
466  get_dof_handler_projection () const = 0;
467 
472  virtual const AffineConstraints<double> &
473  get_constraints_v () const = 0;
474 
479  virtual const AffineConstraints<double> &
480  get_constraints_p () const = 0;
481 
486  virtual const MGTransferMF<dim,GMGNumberType> &
487  get_mg_transfer_A () const = 0;
488 
493  virtual const MGTransferMF<dim,GMGNumberType> &
494  get_mg_transfer_S () const = 0;
495 
500  virtual std::size_t get_cell_data_memory_consumption() const = 0;
501  };
502 
513  template<int dim, int velocity_degree>
515  {
516  public:
523  StokesMatrixFreeHandlerImplementation(Simulator<dim> &, ParameterHandler &prm);
524 
528  ~StokesMatrixFreeHandlerImplementation() override = default;
529 
534  std::pair<double,double> solve() override;
535 
540  void setup_dofs() override;
541 
549  void assemble() override;
550 
555  void build_preconditioner() override;
556 
560  static
561  void declare_parameters (ParameterHandler &prm);
562 
567  const DoFHandler<dim> &
568  get_dof_handler_v () const override;
569 
574  const DoFHandler<dim> &
575  get_dof_handler_p () const override;
576 
581  const DoFHandler<dim> &
582  get_dof_handler_projection () const override;
583 
588  const AffineConstraints<double> &
589  get_constraints_v () const override;
590 
595  const AffineConstraints<double> &
596  get_constraints_p () const override;
597 
603  get_mg_transfer_A () const override;
604 
610  get_mg_transfer_S () const override;
611 
612 
617  std::size_t get_cell_data_memory_consumption() const override;
618 
619  private:
623  void parse_parameters (ParameterHandler &prm);
624 
630  void evaluate_material_model();
631 
636  void correct_stokes_rhs();
637 
638 
640 
642 
648 
654 
655  DoFHandler<dim> dof_handler_v;
656  DoFHandler<dim> dof_handler_p;
657  DoFHandler<dim> dof_handler_projection;
658 
659  FESystem<dim> fe_v;
660  FESystem<dim> fe_p;
661  FESystem<dim> fe_projection;
662 
667 
671  MGLevelObject<MatrixFreeStokesOperators::OperatorCellData<dim, GMGNumberType>> level_cell_data;
672 
676 
679 
683 
684  AffineConstraints<double> constraints_v;
685  AffineConstraints<double> constraints_p;
686 
687  MGLevelObject<GMGABlockMatrixType> mg_matrices_A_block;
688  MGLevelObject<GMGSchurComplementMatrixType> mg_matrices_Schur_complement;
689 
690  MGConstrainedDoFs mg_constrained_dofs_A_block;
693 
696 
697  std::vector<std::shared_ptr<MatrixFree<dim,double>>> matrix_free_objects;
698  };
699 }
700 
701 
702 #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:239
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:233
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
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