TpsaVector.hpp
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 Copyright 2025 NORCE AS
5
6 This file is part of the Open Porous Media project (OPM).
7
8 OPM is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 OPM is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with OPM. If not, see <http://www.gnu.org/licenses/>.
20*/
21#ifndef OPM_TPSA_VECTOR_HPP
22#define OPM_TPSA_VECTOR_HPP
23
25
26#include <dune/common/fvector.hh>
27
28#include <array>
29#include <cmath>
30#include <cstddef>
31
32namespace Opm::Linear
33{
34
44template <class ScalarT>
46{
47public:
49 using Scalar = ScalarT;
50
52 using field_type = ScalarT;
53
55 using EqVector = Dune::FieldVector<Scalar, numTpsaEq>;
56
59
62
64 using size_type = std::size_t;
65
72 {
73 public:
81 EntryProxy(IstlVector& v, std::size_t dofIdx)
82 : v_(&v)
83 , i_(dofIdx)
84 {
85 }
86
92 static constexpr std::size_t size()
93 {
94 return numTpsaEq;
95 }
96
104 Scalar& operator[](std::size_t eqIdx)
105 {
106 return at_(eqIdx);
107 }
108
116 Scalar operator[](std::size_t eqIdx) const
117 {
118 return at_(eqIdx);
119 }
120
129 operator EqVector() const;
130
139
148
157
166
175
184
185 private:
193 Scalar& at_(std::size_t eqIdx) const;
194
195 IstlVector* v_;
196 std::size_t i_;
197 };
198
200 TpsaVector() = default;
201
207 explicit TpsaVector(std::size_t numDof)
208 {
209 resize(numDof);
210 }
211
217 void resize(std::size_t numDof);
218
224 std::size_t size() const
225 {
226 return size_;
227 }
228
230 std::size_t N() const
231 {
232 return size_;
233 }
234
243
252
261
270
280 void scaleFields(const std::array<Scalar, numTpsaFields>& factors);
281
288
295
302 {
303 return std::sqrt(two_norm2());
304 }
305
312
320 EqVector operator[](std::size_t dofIdx) const;
321
329 EntryProxy operator[](std::size_t dofIdx)
330 {
331 return EntryProxy(v_, dofIdx);
332 }
333
340 {
341 return v_;
342 }
343
345 const IstlVector& istlVector() const
346 {
347 return v_;
348 }
349
350private:
351 IstlVector v_{};
352 std::size_t size_{0};
353};
354
355} // namespace Opm::Linear
356
357#endif // OPM_TPSA_VECTOR_HPP
Mutable reference to the seven equations of a single cell.
Definition: TpsaVector.hpp:72
EntryProxy & operator-=(const EqVector &value)
Subtract a dense 7x1 block from the equations of the cell.
EntryProxy & operator=(const EntryProxy &other)
Copy the equations of one cell to another.
EntryProxy & operator+=(const EqVector &value)
Add a dense 7x1 block to the equations of the cell.
EntryProxy(IstlVector &v, std::size_t dofIdx)
Construct a handle on the equations of one cell.
Definition: TpsaVector.hpp:81
static constexpr std::size_t size()
Number of equations the proxy exposes.
Definition: TpsaVector.hpp:92
EntryProxy & operator=(Scalar value)
Set all seven equations of the cell to a scalar.
EntryProxy & operator*=(Scalar factor)
Scale all seven equations of the cell.
Scalar operator[](std::size_t eqIdx) const
Read one equation of the cell.
Definition: TpsaVector.hpp:116
Scalar & operator[](std::size_t eqIdx)
Access one equation of the cell.
Definition: TpsaVector.hpp:104
EntryProxy & operator=(const EqVector &value)
Scatter a dense 7x1 block into the sub-vectors.
Vector type for TPSA linear elasticity.
Definition: TpsaVector.hpp:46
EntryProxy operator[](std::size_t dofIdx)
Writable handle on the seven equations of cell dofIdx.
Definition: TpsaVector.hpp:329
Scalar two_norm() const
Euclidean norm of the vector.
Definition: TpsaVector.hpp:301
IstlVector & istlVector()
The underlying multi-type vector handed to the linear solver.
Definition: TpsaVector.hpp:339
std::size_t size_type
Type used for sizes and indices.
Definition: TpsaVector.hpp:64
EqVector operator[](std::size_t dofIdx) const
The seven equations of cell dofIdx, gathered into a dense block.
Dune::FieldVector< Scalar, numTpsaEq > EqVector
Dense block holding the seven equations of a single cell.
Definition: TpsaVector.hpp:55
TpsaMultiVector< Scalar > IstlVector
What the linear solver operates on.
Definition: TpsaVector.hpp:61
Scalar infinity_norm() const
Largest absolute value over all entries.
void resize(std::size_t numDof)
Resize every sub-vector to the given number of cells.
void scaleFields(const std::array< Scalar, numTpsaFields > &factors)
Multiply each field by factor.
TpsaVector(std::size_t numDof)
Construct a vector sized for the given number of cells.
Definition: TpsaVector.hpp:207
ScalarT Scalar
Field type of the vector entries.
Definition: TpsaVector.hpp:49
TpsaVector & operator*=(Scalar factor)
Scale every entry of every field.
EqVector block_type
Dense block holding the seven equations of a single cell.
Definition: TpsaVector.hpp:58
std::size_t N() const
Number of cells the vector holds equations for.
Definition: TpsaVector.hpp:230
Scalar two_norm2() const
Sum of the squares of all entries.
Scalar one_norm() const
Sum of the absolute values of all entries.
ScalarT field_type
Field type of the vector entries.
Definition: TpsaVector.hpp:52
TpsaVector & operator+=(const TpsaVector &other)
Add another vector field by field.
TpsaVector()=default
Construct an empty vector; call resize() before use.
TpsaVector & operator=(Scalar value)
Set every entry of every field to a scalar.
TpsaVector & operator-=(const TpsaVector &other)
Subtract another vector field by field.
const IstlVector & istlVector() const
The underlying multi-type vector handed to the linear solver.
Definition: TpsaVector.hpp:345
std::size_t size() const
Number of cells the vector holds equations for.
Definition: TpsaVector.hpp:224
Definition: bicgstabsolver.hh:42
Dune::MultiTypeBlockVector< DispVector0T< Scalar >, DispVector1T< Scalar >, DispVector2T< Scalar >, RotVectorT< Scalar >, SPresVectorT< Scalar > > TpsaMultiVector
The vector the Krylov solver and the preconditioner operate on.
Definition: TpsaTypes.hpp:116
constexpr int numTpsaEq
Total number of TPSA equations per cell.
Definition: TpsaTypes.hpp:45