ASPECT
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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>
27 
28 #include <aspect/simulator.h>
29 
30 #include <deal.II/matrix_free/matrix_free.h>
31 #include <deal.II/matrix_free/operators.h>
32 #include <deal.II/matrix_free/fe_evaluation.h>
33 
34 #include <deal.II/multigrid/mg_constrained_dofs.h>
35 #include <deal.II/multigrid/multigrid.h>
36 #include <deal.II/multigrid/mg_transfer_matrix_free.h>
37 #include <deal.II/multigrid/mg_transfer_global_coarsening.templates.h>
38 #include <deal.II/multigrid/mg_tools.h>
39 #include <deal.II/multigrid/mg_coarse.h>
40 #include <deal.II/multigrid/mg_smoother.h>
41 #include <deal.II/multigrid/mg_matrix.h>
42 
43 #include <deal.II/lac/vector.h>
44 #include <deal.II/lac/block_vector.h>
45 #include <deal.II/lac/la_parallel_vector.h>
46 #include <deal.II/lac/la_parallel_block_vector.h>
47 
51 using GMGNumberType = double;
52 
53 namespace aspect
54 {
55  namespace internal
56  {
62  namespace ChangeVectorTypes
63  {
64  void import(TrilinosWrappers::MPI::Vector &out,
65  const ::LinearAlgebra::ReadWriteVector<double> &rwv,
66  const VectorOperation::values operation);
67 
69  const ::LinearAlgebra::distributed::Vector<double> &in);
70 
71  void copy(::LinearAlgebra::distributed::Vector<double> &out,
73 
75  const ::LinearAlgebra::distributed::BlockVector<double> &in);
76 
77  void copy(::LinearAlgebra::distributed::BlockVector<double> &out,
79  }
80  }
81 
85  namespace MatrixFreeStokesOperators
86  {
87 
98  template <int dim, typename number>
100  {
105 
110 
115 
121 
126 
133  Table<2, VectorizedArray<number>> viscosity;
134 
139  Table<2, SymmetricTensor<2, dim, VectorizedArray<number>>> strain_rate_table;
140 
146  Table<2, VectorizedArray<number>> newton_factor_wrt_pressure_table;
147 
155  Table<2, SymmetricTensor<2, dim, VectorizedArray<number>>>
157 
163  Table<2, Tensor<1, dim, VectorizedArray<number>>> free_surface_stabilization_term_table;
164 
168  std::set<types::boundary_id> free_surface_boundary_indicators;
169 
174  std::size_t
175  memory_consumption() const;
176 
180  void clear();
181  };
182 
186  template <int dim, int degree_v, typename number>
188  : public MatrixFreeOperators::Base<dim, ::LinearAlgebra::distributed::BlockVector<number>>
189  {
190  public:
191 
195  StokesOperator ();
196 
200  void clear () override;
201 
205  void set_cell_data (const OperatorCellData<dim,number> &data);
206 
212  void compute_diagonal () override;
213 
214  private:
215 
220  void apply_add (::LinearAlgebra::distributed::BlockVector<number> &dst,
221  const ::LinearAlgebra::distributed::BlockVector<number> &src) const override;
222 
226  void local_apply (const ::MatrixFree<dim, number> &data,
227  ::LinearAlgebra::distributed::BlockVector<number> &dst,
228  const ::LinearAlgebra::distributed::BlockVector<number> &src,
229  const std::pair<unsigned int, unsigned int> &cell_range) const;
230 
234  void local_apply_face (const ::MatrixFree<dim, number> &data,
235  ::LinearAlgebra::distributed::BlockVector<number> &dst,
236  const ::LinearAlgebra::distributed::BlockVector<number> &src,
237  const std::pair<unsigned int, unsigned int> &face_range) const;
238 
242  void local_apply_boundary_face (const ::MatrixFree<dim, number> &data,
243  ::LinearAlgebra::distributed::BlockVector<number> &dst,
244  const ::LinearAlgebra::distributed::BlockVector<number> &src,
245  const std::pair<unsigned int, unsigned int> &face_range) const;
246 
251  };
252 
256  template <int dim, int degree_p, typename number>
258  : public MatrixFreeOperators::Base<dim, ::LinearAlgebra::distributed::Vector<number>>
259  {
260  public:
261 
266 
270  void clear () override;
271 
275  void set_cell_data (const OperatorCellData<dim,number> &data);
276 
282  void compute_diagonal () override;
283 
284  private:
285 
290  void apply_add (::LinearAlgebra::distributed::Vector<number> &dst,
291  const ::LinearAlgebra::distributed::Vector<number> &src) const override;
292 
296  void local_apply (const ::MatrixFree<dim, number> &data,
297  ::LinearAlgebra::distributed::Vector<number> &dst,
298  const ::LinearAlgebra::distributed::Vector<number> &src,
299  const std::pair<unsigned int, unsigned int> &cell_range) const;
300 
304  void inner_cell_operation(FEEvaluation<dim,
305  degree_p,
306  degree_p+2,
307  1,
308  number> &pressure) const;
309 
314  };
315 
320  template <int dim, int degree_v, typename number>
322  : public MatrixFreeOperators::Base<dim, ::LinearAlgebra::distributed::Vector<number>>
323  {
324  public:
325 
329  ABlockOperator ();
330 
334  void clear () override;
335 
339  void set_cell_data (const OperatorCellData<dim,number> &data);
340 
346  void compute_diagonal () override;
347 
353  void set_diagonal (const ::LinearAlgebra::distributed::Vector<number> &diag);
354 
355  private:
360  void inner_cell_operation(FEEvaluation<dim,
361  degree_v,
362  degree_v+1,
363  dim,
364  number> &velocity) const;
365 
370  void cell_operation(FEEvaluation<dim,
371  degree_v,
372  degree_v+1,
373  dim,
374  number> &velocity) const;
375 
381  void apply_add (::LinearAlgebra::distributed::Vector<number> &dst,
382  const ::LinearAlgebra::distributed::Vector<number> &src) const override;
383 
387  void local_apply (const ::MatrixFree<dim, number> &data,
388  ::LinearAlgebra::distributed::Vector<number> &dst,
389  const ::LinearAlgebra::distributed::Vector<number> &src,
390  const std::pair<unsigned int, unsigned int> &cell_range) const;
391 
396  };
397  }
398 
403  template <int dim>
405  {
406  public:
411  virtual void setup_dofs()=0;
412 
420  virtual void assemble()=0;
421 
427  virtual void build_preconditioner()=0;
428 
432  static
433  void declare_parameters (ParameterHandler &prm);
434 
439  virtual const DoFHandler<dim> &
440  get_dof_handler_v () const = 0;
441 
446  virtual const DoFHandler<dim> &
447  get_dof_handler_p () const = 0;
448 
453  virtual const DoFHandler<dim> &
454  get_dof_handler_projection () const = 0;
455 
460  virtual const AffineConstraints<double> &
461  get_constraints_v () const = 0;
462 
467  virtual const AffineConstraints<double> &
468  get_constraints_p () const = 0;
469 
474  virtual const MGTransferMF<dim,GMGNumberType> &
475  get_mg_transfer_A () const = 0;
476 
481  virtual const MGTransferMF<dim,GMGNumberType> &
482  get_mg_transfer_S () const = 0;
483 
488  virtual std::size_t get_cell_data_memory_consumption() const = 0;
489  };
490 
501  template <int dim, int velocity_degree>
503  {
504  public:
511  const Parameters<dim> &parameters);
512 
516  ~StokesMatrixFreeHandlerImplementation() override = default;
517 
521  void initialize() override;
522 
526  std::string name() const override;
527 
548  solve(const LinearAlgebra::BlockSparseMatrix &system_matrix,
549  const LinearAlgebra::BlockVector &system_rhs,
550  const bool solve_newton_system,
551  const double last_pressure_normalization_adjustment,
552  LinearAlgebra::BlockVector &solution_vector) override;
553 
558  void setup_dofs() override;
559 
567  void assemble() override;
568 
573  void build_preconditioner() override;
574 
578  static
579  void declare_parameters (ParameterHandler &prm);
580 
584  void parse_parameters (ParameterHandler &prm) override;
585 
590  const DoFHandler<dim> &
591  get_dof_handler_v () const override;
592 
597  const DoFHandler<dim> &
598  get_dof_handler_p () const override;
599 
604  const DoFHandler<dim> &
605  get_dof_handler_projection () const override;
606 
611  const AffineConstraints<double> &
612  get_constraints_v () const override;
613 
618  const AffineConstraints<double> &
619  get_constraints_p () const override;
620 
626  get_mg_transfer_A () const override;
627 
633  get_mg_transfer_S () const override;
634 
635 
640  std::size_t get_cell_data_memory_consumption() const override;
641 
642  private:
648  void evaluate_material_model();
649 
654  void correct_stokes_rhs();
655 
656 
658 
660 
666 
672 
673  DoFHandler<dim> dof_handler_v;
674  DoFHandler<dim> dof_handler_p;
675  DoFHandler<dim> dof_handler_projection;
676 
677  FESystem<dim> fe_v;
678  FESystem<dim> fe_p;
679  FESystem<dim> fe_projection;
680 
685 
689  MGLevelObject<MatrixFreeStokesOperators::OperatorCellData<dim, GMGNumberType>> level_cell_data;
690 
694 
697 
701 
702  AffineConstraints<double> constraints_v;
703  AffineConstraints<double> constraints_p;
704 
705  MGLevelObject<GMGABlockMatrixType> mg_matrices_A_block;
706  MGLevelObject<GMGSchurComplementMatrixType> mg_matrices_Schur_complement;
707 
708  MGConstrainedDoFs mg_constrained_dofs_A_block;
711 
714 
715  std::vector<std::shared_ptr<MatrixFree<dim,double>>> matrix_free_objects;
716  };
717 }
718 
719 
720 #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:268
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
::TrilinosWrappers::MPI::Vector Vector
Definition: global.h:262
const OperatorCellData< dim, number > * cell_data
::TrilinosWrappers::BlockSparseMatrix BlockSparseMatrix
Definition: global.h:279
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
void copy(TrilinosWrappers::MPI::Vector &out, const ::LinearAlgebra::distributed::Vector< double > &in)
Table< 2, VectorizedArray< number > > newton_factor_wrt_pressure_table
double GMGNumberType