ASPECT
interface.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2022 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_assemblers_interface_h
22 #define _aspect_simulator_assemblers_interface_h
23 
24 #include <aspect/global.h>
27 
28 #include <deal.II/fe/fe_values.h>
29 
30 namespace aspect
31 {
32  using namespace dealii;
33 
34  template <int dim>
35  class Simulator;
36 
37  struct AdvectionField;
38 
46  namespace internal
47  {
48  namespace Assembly
49  {
50  namespace Scratch
51  {
58  template <int dim>
59  struct ScratchBase
60  {
62  :
63  cell(),
64  face_number(numbers::invalid_unsigned_int)
65  {}
66 
67  ScratchBase(const ScratchBase &scratch)
68  :
69  cell(scratch.cell),
70  face_number(scratch.face_number)
71  {}
72 
73  virtual ~ScratchBase () = default;
74 
78  typename DoFHandler<dim>::active_cell_iterator cell;
79 
86  unsigned face_number;
87  };
88 
93  template <int dim>
94  struct StokesPreconditioner: public ScratchBase<dim>
95  {
96  StokesPreconditioner (const FiniteElement<dim> &finite_element,
97  const Quadrature<dim> &quadrature,
98  const Mapping<dim> &mapping,
99  const UpdateFlags update_flags,
100  const unsigned int n_compositional_fields,
101  const unsigned int stokes_dofs_per_cell,
102  const bool add_compaction_pressure,
103  const bool rebuild_matrix);
104  StokesPreconditioner (const StokesPreconditioner &scratch);
105 
106  ~StokesPreconditioner () override;
107 
108  FEValues<dim> finite_element_values;
109 
110  void reinit (const typename DoFHandler<dim>::active_cell_iterator &cell_ref);
111 
112  std::vector<types::global_dof_index> local_dof_indices;
113  std::vector<unsigned int> dof_component_indices;
114  std::vector<SymmetricTensor<2,dim>> grads_phi_u;
115  std::vector<double> div_phi_u;
116  std::vector<double> phi_p;
117  std::vector<double> phi_p_c;
118  std::vector<Tensor<1,dim>> grad_phi_p;
119 
126 
133  };
134 
135 
136 
147  template <int dim>
148  struct StokesSystem : public StokesPreconditioner<dim>
149  {
150  StokesSystem (const FiniteElement<dim> &finite_element,
151  const Mapping<dim> &mapping,
152  const Quadrature<dim> &quadrature,
153  const Quadrature<dim-1> &face_quadrature,
154  const UpdateFlags update_flags,
155  const UpdateFlags face_update_flags,
156  const unsigned int n_compositional_fields,
157  const unsigned int stokes_dofs_per_cell,
158  const bool add_compaction_pressure,
159  const bool use_reference_density_profile,
160  const bool rebuild_stokes_matrix,
161  const bool rebuild_newton_stokes_matrix);
162 
163  StokesSystem (const StokesSystem<dim> &scratch);
164 
165  FEFaceValues<dim> face_finite_element_values;
166 
168 
169  void reinit (const typename DoFHandler<dim>::active_cell_iterator &cell_ref,
170  const unsigned face_number_ref);
171 
172  std::vector<Tensor<1,dim>> phi_u;
173  std::vector<Tensor<1,dim>> velocity_values;
174  std::vector<double> velocity_divergence;
175  std::vector<Tensor<1,dim>> temperature_gradients;
176 
187 
197  std::vector<double> reference_densities;
199 
206  };
207 
208 
209 
214  template <int dim>
215  struct AdvectionSystem: public ScratchBase<dim>
216  {
217  AdvectionSystem (const FiniteElement<dim> &finite_element,
218  const FiniteElement<dim> &advection_element,
219  const Mapping<dim> &mapping,
220  const Quadrature<dim> &quadrature,
221  const Quadrature<dim-1> &face_quadrature,
222  const UpdateFlags update_flags,
223  const UpdateFlags face_update_flags,
224  const unsigned int n_compositional_fields,
225  const typename Simulator<dim>::AdvectionField &field);
226  AdvectionSystem (const AdvectionSystem &scratch);
227 
228  FEValues<dim> finite_element_values;
229 
230  void reinit (const typename DoFHandler<dim>::active_cell_iterator &cell_ref);
231 
232  std::unique_ptr<FEFaceValues<dim>> face_finite_element_values;
233  std::unique_ptr<FEFaceValues<dim>> neighbor_face_finite_element_values;
234  std::unique_ptr<FESubfaceValues<dim>> subface_finite_element_values;
235 
236  std::vector<types::global_dof_index> local_dof_indices;
237 
246  std::vector<double> phi_field;
247  std::vector<Tensor<1,dim>> grad_phi_field;
248  std::vector<double> laplacian_phi_field;
249  std::vector<double> face_phi_field;
250  std::vector<Tensor<1,dim>> face_grad_phi_field;
251  std::vector<double> neighbor_face_phi_field;
252  std::vector<Tensor<1,dim>> neighbor_face_grad_phi_field;
253 
254  std::vector<Tensor<1,dim>> old_velocity_values;
255  std::vector<Tensor<1,dim>> old_old_velocity_values;
256 
257  std::vector<double> old_pressure;
258  std::vector<double> old_old_pressure;
259  std::vector<Tensor<1,dim>> old_pressure_gradients;
260  std::vector<Tensor<1,dim>> old_old_pressure_gradients;
261 
262  std::vector<SymmetricTensor<2,dim>> old_strain_rates;
263  std::vector<SymmetricTensor<2,dim>> old_old_strain_rates;
264 
265  std::vector<double> old_temperature_values;
266  std::vector<double> old_old_temperature_values;
267 
268  std::vector<double> old_field_values;
269  std::vector<double> old_old_field_values;
270  std::vector<Tensor<1,dim>> old_field_grads;
271  std::vector<Tensor<1,dim>> old_old_field_grads;
272  std::vector<double> old_field_laplacians;
273  std::vector<double> old_old_field_laplacians;
274 
275  std::vector<std::vector<double>> old_composition_values;
276  std::vector<std::vector<double>> old_old_composition_values;
277 
278  std::vector<double> current_temperature_values;
279  std::vector<Tensor<1,dim>> current_velocity_values;
280  std::vector<Tensor<1,dim>> face_current_velocity_values;
281  std::vector<Tensor<1,dim>> mesh_velocity_values;
282  std::vector<Tensor<1,dim>> face_mesh_velocity_values;
283 
284  std::vector<SymmetricTensor<2,dim>> current_strain_rates;
285  std::vector<std::vector<double>> current_composition_values;
286  std::vector<double> current_velocity_divergences;
287 
294 
297 
300 
311 
320 
326  };
327  }
328 
329 
330 
343  namespace CopyData
344  {
350  template <int dim>
352  {
353  virtual ~CopyDataBase () = default;
354  };
355 
361  template <int dim>
362  struct StokesPreconditioner: public CopyDataBase<dim>
363  {
364  StokesPreconditioner (const unsigned int stokes_dofs_per_cell);
365 
366  StokesPreconditioner (const StokesPreconditioner &data);
367 
368  ~StokesPreconditioner () override = default;
369  StokesPreconditioner<dim> &operator= (const StokesPreconditioner<dim> &data) = default;
370 
371  FullMatrix<double> local_matrix;
372  std::vector<types::global_dof_index> local_dof_indices;
373 
379  void extract_stokes_dof_indices(const std::vector<types::global_dof_index> &all_dof_indices,
380  const Introspection<dim> &introspection,
381  const FiniteElement<dim> &finite_element);
382  };
383 
389  template <int dim>
390  struct StokesSystem : public StokesPreconditioner<dim>
391  {
392  StokesSystem (const unsigned int stokes_dofs_per_cell,
393  const bool do_pressure_rhs_compatibility_modification);
394  StokesSystem (const StokesSystem<dim> &data);
395 
396  ~StokesSystem () override = default;
397  StokesSystem<dim> &operator= (const StokesSystem<dim> &data) = default;
398 
399  Vector<double> local_rhs;
401  };
402 
408  template <int dim>
409  struct AdvectionSystem: public CopyDataBase<dim>
410  {
419  AdvectionSystem (const FiniteElement<dim> &finite_element,
420  const bool field_is_discontinuous);
421 
426  FullMatrix<double> local_matrix;
427 
439  std::vector<FullMatrix<double>> local_matrices_int_ext;
440  std::vector<FullMatrix<double>> local_matrices_ext_int;
441  std::vector<FullMatrix<double>> local_matrices_ext_ext;
442 
447  Vector<double> local_rhs;
448 
455  std::vector<bool> assembled_matrices;
456 
466  std::vector<types::global_dof_index> local_dof_indices;
467 
476  std::vector<std::vector<types::global_dof_index>> neighbor_dof_indices;
477  };
478  }
479  }
480  }
481 
486  namespace Assemblers
487  {
488 
498  unsigned int
499  n_interface_matrices (const ReferenceCell &reference_cell);
500 
506  unsigned int
507  nth_interface_matrix (const ReferenceCell &reference_cell,
508  const unsigned int face);
509 
515  unsigned int
516  nth_interface_matrix (const ReferenceCell &reference_cell,
517  const unsigned int face,
518  const unsigned int sub_face);
519 
534  template <int dim>
535  class Interface
536  {
537  public:
541  virtual ~Interface () = default;
542 
556  virtual
557  void
560 
594  virtual
595  void
596  create_additional_material_model_outputs(MaterialModel::MaterialModelOutputs<dim> &) const;
597 
611  virtual
612  std::vector<double>
613  compute_residual(internal::Assembly::Scratch::ScratchBase<dim> &) const;
614  };
615 
616 
617 
625  template <int dim>
627  {
628  public:
630 
640  virtual
641  std::vector<double>
642  advection_prefactors(internal::Assembly::Scratch::ScratchBase<dim> &scratch_base) const;
643 
653  virtual
654  std::vector<double>
655  diffusion_prefactors(internal::Assembly::Scratch::ScratchBase<dim> &scratch_base) const;
656  };
657 
658 
659 
686  template <int dim>
687  class Manager
688  {
689  public:
690 
694  void reset ();
695 
700  std::vector<std::unique_ptr<Assemblers::Interface<dim>>> stokes_preconditioner;
701 
707  std::vector<std::unique_ptr<Assemblers::Interface<dim>>> stokes_system;
708 
716  std::vector<std::unique_ptr<Assemblers::Interface<dim>>> stokes_system_on_boundary_face;
717 
722  std::vector<std::unique_ptr<Assemblers::Interface<dim>>> advection_system;
723 
731  std::vector<std::unique_ptr<Assemblers::Interface<dim>>> advection_system_on_boundary_face;
732 
740  std::vector<std::unique_ptr<Assemblers::Interface<dim>>> advection_system_on_interior_face;
741 
761  struct Properties
762  {
767  Properties ();
768 
777 
786 
792 
799  UpdateFlags needed_update_flags;
800  };
801 
811  std::vector<Properties> advection_system_assembler_properties;
813  };
814  }
815 }
816 
817 
818 #endif
std::vector< SymmetricTensor< 2, dim > > old_strain_rates
Definition: interface.h:262
std::vector< Tensor< 1, dim > > old_field_grads
Definition: interface.h:270
std::vector< types::global_dof_index > local_dof_indices
Definition: interface.h:466
std::vector< Tensor< 1, dim > > old_velocity_values
Definition: interface.h:254
std::vector< std::unique_ptr< Assemblers::Interface< dim > > > stokes_system
Definition: interface.h:707
Properties stokes_preconditioner_assembler_properties
Definition: interface.h:808
MaterialModel::MaterialModelInputs< dim > face_material_model_inputs
Definition: interface.h:185
std::vector< Tensor< 1, dim > > face_mesh_velocity_values
Definition: interface.h:282
std::vector< Tensor< 1, dim > > grad_phi_field
Definition: interface.h:247
std::vector< Tensor< 1, dim > > face_grad_phi_field
Definition: interface.h:250
MaterialModel::MaterialModelOutputs< dim > material_model_outputs
Definition: interface.h:293
MaterialModel::MaterialModelInputs< dim > material_model_inputs
Definition: interface.h:292
HeatingModel::HeatingModelOutputs face_heating_model_outputs
Definition: interface.h:309
MaterialModel::MaterialModelOutputs< dim > neighbor_face_material_model_outputs
Definition: interface.h:299
std::vector< Tensor< 1, dim > > mesh_velocity_values
Definition: interface.h:281
const Simulator< dim >::AdvectionField * advection_field
Definition: interface.h:319
std::vector< Tensor< 1, dim > > old_pressure_gradients
Definition: interface.h:259
std::vector< SymmetricTensor< 2, dim > > old_old_strain_rates
Definition: interface.h:263
std::vector< Tensor< 1, dim > > old_old_field_grads
Definition: interface.h:271
std::vector< std::unique_ptr< Assemblers::Interface< dim > > > advection_system_on_interior_face
Definition: interface.h:740
unsigned int n_interface_matrices(const ReferenceCell &reference_cell)
std::vector< Tensor< 1, dim > > temperature_gradients
Definition: interface.h:175
std::vector< SymmetricTensor< 2, dim > > current_strain_rates
Definition: interface.h:284
ScratchBase(const ScratchBase &scratch)
Definition: interface.h:67
unsigned int nth_interface_matrix(const ReferenceCell &reference_cell, const unsigned int face, const unsigned int sub_face)
std::vector< Tensor< 1, dim > > current_velocity_values
Definition: interface.h:279
std::vector< Properties > advection_system_assembler_properties
Definition: interface.h:811
MaterialModel::MaterialModelOutputs< dim > face_material_model_outputs
Definition: interface.h:296
HeatingModel::HeatingModelOutputs neighbor_face_heating_model_outputs
Definition: interface.h:310
std::vector< Tensor< 1, dim > > neighbor_face_grad_phi_field
Definition: interface.h:252
std::unique_ptr< FEFaceValues< dim > > neighbor_face_finite_element_values
Definition: interface.h:233
std::vector< std::vector< types::global_dof_index > > neighbor_dof_indices
Definition: interface.h:476
std::vector< FullMatrix< double > > local_matrices_int_ext
Definition: interface.h:439
std::vector< Tensor< 1, dim > > old_old_velocity_values
Definition: interface.h:255
std::vector< std::unique_ptr< Assemblers::Interface< dim > > > advection_system_on_boundary_face
Definition: interface.h:731
std::vector< FullMatrix< double > > local_matrices_ext_int
Definition: interface.h:440
std::vector< std::unique_ptr< Assemblers::Interface< dim > > > advection_system
Definition: interface.h:722
std::vector< std::vector< double > > old_composition_values
Definition: interface.h:275
std::vector< SymmetricTensor< 2, dim > > grads_phi_u
Definition: interface.h:114
Properties stokes_system_assembler_on_boundary_face_properties
Definition: interface.h:810
DoFHandler< dim >::active_cell_iterator cell
Definition: interface.h:78
std::vector< std::vector< double > > old_old_composition_values
Definition: interface.h:276
MaterialModel::MaterialModelOutputs< dim > face_material_model_outputs
Definition: interface.h:186
std::vector< Tensor< 1, dim > > old_old_pressure_gradients
Definition: interface.h:260
std::vector< types::global_dof_index > local_dof_indices
Definition: interface.h:372
std::vector< Tensor< 1, dim > > velocity_values
Definition: interface.h:173
HeatingModel::HeatingModelOutputs heating_model_outputs
Definition: interface.h:308
std::vector< Properties > advection_system_assembler_on_face_properties
Definition: interface.h:812
std::vector< double > reference_densities_depth_derivative
Definition: interface.h:198
MaterialModel::MaterialModelInputs< dim > neighbor_face_material_model_inputs
Definition: interface.h:298
std::unique_ptr< FESubfaceValues< dim > > subface_finite_element_values
Definition: interface.h:234
std::vector< std::unique_ptr< Assemblers::Interface< dim > > > stokes_system_on_boundary_face
Definition: interface.h:716
std::vector< Tensor< 1, dim > > face_current_velocity_values
Definition: interface.h:280
std::vector< FullMatrix< double > > local_matrices_ext_ext
Definition: interface.h:441
std::vector< Tensor< 1, dim > > phi_u
Definition: interface.h:172
MaterialModel::MaterialModelInputs< dim > face_material_model_inputs
Definition: interface.h:295
MaterialModel::MaterialModelInputs< dim > material_model_inputs
Definition: interface.h:124
std::vector< std::vector< double > > current_composition_values
Definition: interface.h:285
std::unique_ptr< FEFaceValues< dim > > face_finite_element_values
Definition: interface.h:232
Definition: compat.h:88
std::vector< std::unique_ptr< Assemblers::Interface< dim > > > stokes_preconditioner
Definition: interface.h:700
MaterialModel::MaterialModelOutputs< dim > material_model_outputs
Definition: interface.h:125
Properties stokes_system_assembler_properties
Definition: interface.h:809
std::vector< types::global_dof_index > local_dof_indices
Definition: interface.h:236
std::vector< types::global_dof_index > local_dof_indices
Definition: interface.h:112