PRISMS-PF Manual
Loading...
Searching...
No Matches
mf_operator.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2025 PRISMS Center at the University of Michigan
2// SPDX-License-Identifier: GNU Lesser General Public Version 2.1
3
4#pragma once
5
6#include <deal.II/base/vectorization.h>
7#include <deal.II/matrix_free/matrix_free.h>
8#include <deal.II/matrix_free/operators.h>
9
17#include <prismspf/core/types.h>
18
20
21#include <prismspf/config.h>
22
23#include <vector>
24
25#if DEAL_II_VERSION_MAJOR >= 9 && DEAL_II_VERSION_MINOR >= 7
26# include <deal.II/base/enable_observer_pointer.h>
27# define MATRIX_FREE_OPERATOR_BASE dealii::EnableObserverPointer
28#else
29# include <deal.II/base/subscriptor.h>
30# define MATRIX_FREE_OPERATOR_BASE dealii::Subscriptor
31#endif
32
34
48template <unsigned int dim, unsigned int degree, typename number>
50{
51public:
52 using ScalarValue = dealii::VectorizedArray<number>;
53 using VectorValue = dealii::Tensor<1, dim, ScalarValue>;
54
56 FieldContainer<dim, degree, number> &, /* variable_list */
57 const SimulationTimer &, /* sim_timer */
58 unsigned int /* solve_group_id */
59 ) const;
60
61 template <TensorRank Rank>
62 using Value = std::conditional_t<Rank == TensorRank::Scalar,
64 dealii::Tensor<int(Rank), dim, ScalarValue>>;
65
66 template <TensorRank Rank>
69 {
70 if constexpr (Rank == TensorRank::Scalar)
71 {
72 return ScalarValue(1.0);
73 }
74 else
75 {
76 static Value<Rank> ident = []()
77 {
80 {
82 }
83 }();
84 return ident;
85 }
86 }
87
88 template <TensorRank Rank>
91 {
92 if constexpr (Rank == TensorRank::Scalar)
93 {
94 return ScalarValue(0.0);
95 }
96 else
97 {
98 return Value<Rank>();
99 }
100 }
101
123
139 void
141 {
142 solve_group = dst_solution.get_solve_group();
143 data = &(dst_solution.get_matrix_free(relative_level));
144 field_to_block_index = dst_solution.get_global_to_block_index();
145 for (unsigned int field_index : solve_group.field_indices)
146 {
147 dependency_map[field_index]; // creates entry if not already present
148 }
149 }
150
151 // public:
156 void
159
160private:
165 void
166 compute_local_operator(const MatrixFree<dim, number> &_data,
169 const std::pair<unsigned int, unsigned int> &cell_range) const;
170
171 // public:
172 // /**
173 // * @brief Compute the diagonal of this operator.
174 // */
175 // void
176 // compute_diagonal();
177 //
178 // private:
179 // /**
180 // * @brief Local computation of the diagonal of the operator.
181 // */
182 // void
183 // compute_local_diagonal(const MatrixFree<dim, number> &_data,
184 // BlockVector<number> &dst,
185 // const unsigned int &dummy,
186 // const std::pair<unsigned int, unsigned int> &cell_range)
187 // const;
188 //
189 // template <TensorRank Rank>
190 // dealii::AlignedVector<Value<Rank>>
191 // compute_field_diagonal(FieldContainer<dim, degree, number> &variable_list,
192 // DSTContainer<dim, degree, number> &dst_fields,
193 // unsigned int field_index) const;
194
195public:
199 void
201 const std::vector<const SolutionVector<number> *> &diagonal)
202 {
205 }
206
210 dealii::types::global_dof_index
211 m() const;
212
218 number
219 el(const unsigned int &row, const unsigned int &col) const;
220
225 void
226 clear();
227
231 // void
232 // set_constrained_entries_to_one(SolutionVector<number> &dst) const;
233
238 const MatrixFree<dim, number> *
239 get_matrix_free() const;
240
244 const std::shared_ptr<dealii::DiagonalMatrix<SolutionVector<number>>> &
246
251 void
253
254 // NOLINTBEGIN(readability-identifier-naming)
255
259 void
261
262 // NOLINTEND(readability-identifier-naming)
263
264private:
268 std::vector<FieldAttributes> field_attributes;
269
274
283
291 unsigned int relative_level;
292
297
302
306 std::vector<const SolutionVector<number> *> scaling_diagonal;
307
311 bool scale_by_diagonal = false;
312
316 std::vector<unsigned int> field_to_block_index;
317
322
326 std::vector<std::vector<unsigned int>> edge_constrained_indices;
327
331 std::shared_ptr<dealii::DiagonalMatrix<SolutionVector<number>>> diagonal_entries;
332
336 std::shared_ptr<dealii::DiagonalMatrix<SolutionVector<number>>>
338};
339
This class permits the access of a subset of indexed fields and gives an error if any non-allowed fie...
Definition field_container.h:50
This class exists to evaluate a single user-defined operator for the matrix-free implementation of so...
Definition mf_operator.h:50
dealii::types::global_dof_index m() const
Return the number of DoFs.
Definition mf_operator.cc:203
Value< Rank > identity()
Definition mf_operator.h:68
Operator pde_op
The actual PDE operator function ptr (eg. compute_rhs) for user defined PDEs.
Definition mf_operator.h:282
Value< Rank > zero()
Definition mf_operator.h:90
void(PDEOperatorBase< dim, degree, number >::*)(FieldContainer< dim, degree, number > &, const SimulationTimer &, unsigned int) const Operator
Definition mf_operator.h:59
std::shared_ptr< dealii::DiagonalMatrix< SolutionVector< number > > > diagonal_entries
The diagonal matrix.
Definition mf_operator.h:331
void compute_local_operator(const MatrixFree< dim, number > &_data, BlockVector< number > &dst, const BlockVector< number > &src, const std::pair< unsigned int, unsigned int > &cell_range) const
Calls user-defined operator.
Definition mf_operator.cc:32
MFOperator(const PDEOperatorBase< dim, degree, number > &operator_owner, Operator oper, const std::vector< FieldAttributes > &_field_attributes, const SolutionIndexer< dim, number > &_solution_indexer, unsigned int _relative_level, DependencyMap _dependency_map, const SimulationTimer &_sim_timer)
Constructor.
Definition mf_operator.h:107
void Tvmult(BlockVector< number > &dst, const BlockVector< number > &src) const
Transpose matrix-vector multiplication.
Definition mf_operator.cc:284
dealii::VectorizedArray< number > ScalarValue
Definition mf_operator.h:52
std::shared_ptr< dealii::DiagonalMatrix< SolutionVector< number > > > inverse_diagonal_entries
The inverse diagonal matrix.
Definition mf_operator.h:337
unsigned int relative_level
Level so that correct fields are read from indexer.
Definition mf_operator.h:291
const std::shared_ptr< dealii::DiagonalMatrix< SolutionVector< number > > > & get_matrix_diagonal_inverse() const
Get read access to the inverse diagonal of this operator.
Definition mf_operator.cc:265
DependencyMap dependency_map
Which fields should be available to the solve.
Definition mf_operator.h:296
std::vector< const SolutionVector< number > * > scaling_diagonal
Result of operator gets scaled by this (invm for explicit fields)
Definition mf_operator.h:306
dealii::Tensor< 1, dim, ScalarValue > VectorValue
Definition mf_operator.h:53
std::vector< unsigned int > field_to_block_index
Mapping from field index to block index (only for dst).
Definition mf_operator.h:316
void clear()
Release all memory and return to state like having called the default constructor.
Definition mf_operator.cc:231
void initialize(const GroupSolutionHandler< dim, number > &dst_solution)
Initialize.
Definition mf_operator.h:140
const SimulationTimer * sim_timer
Simulation timer.
Definition mf_operator.h:301
std::vector< std::vector< unsigned int > > edge_constrained_indices
Indices of DoFs on edge in case the operator is used in GMG context.
Definition mf_operator.h:326
const MatrixFree< dim, number > * get_matrix_free() const
Set constrained entries to one.
Definition mf_operator.cc:258
void compute_operator(BlockVector< number > &dst, const BlockVector< number > &src=BlockVector< number >()) const
Calls cell_loop on function that calls user-defined operator.
Definition mf_operator.cc:17
const PDEOperatorBase< dim, degree, number > * pde_operator
PDE operator object (owning class instance of pde_op) for user defined PDEs.
Definition mf_operator.h:278
std::conditional_t< Rank==TensorRank::Scalar, ScalarValue, dealii::Tensor< int(Rank), dim, ScalarValue > > Value
Definition mf_operator.h:64
void set_scaling_diagonal(bool scale, const std::vector< const SolutionVector< number > * > &diagonal)
Set scaling diagonal.
Definition mf_operator.h:200
SolveGroup solve_group
The group being solved.
Definition mf_operator.h:273
bool scale_by_diagonal
Whether or not to scale after operator result.
Definition mf_operator.h:311
const SolutionIndexer< dim, number > * solution_indexer
Read-access to fields.
Definition mf_operator.h:287
number el(const unsigned int &row, const unsigned int &col) const
Return the value of the matrix entry. This function is only valid when row == col and when the diagon...
Definition mf_operator.cc:222
const MatrixFree< dim, number > * data
Matrix-free object.
Definition mf_operator.h:321
void vmult(BlockVector< number > &dst, const BlockVector< number > &src) const
Matrix-vector multiplication.
Definition mf_operator.cc:274
std::vector< FieldAttributes > field_attributes
The attribute list of the relevant variables.
Definition mf_operator.h:268
Definition simulation_timer.h:13
Structure to hold the attributes of a solve-group.
Definition solve_group.h:59
std::set< Types::Index > field_indices
Indices of the fields to be solved in this group.
Definition solve_group.h:98
std::map< Types::Index, Dependency > DependencyMap
Definition dependencies.h:129
@ Value
Use value of the variable as a criterion for refinement.
Definition grid_refiner_criterion.h:31
dealii::LinearAlgebra::distributed::BlockVector< number > BlockVector
Typedef for solution block vector.
Definition group_solution_handler.h:29
#define MATRIX_FREE_OPERATOR_BASE
Definition mf_operator.h:30
Definition conditional_ostreams.cc:20
Definition vectorized_operations.h:17
@ Scalar
Definition type_enums.h:32