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 2 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 Consult the COPYING file in the top-level source directory of this
22 module for the precise wording of the license and the list of
23 copyright holders.
24*/
25#ifndef OPM_TPSA_VECTOR_HPP
26#define OPM_TPSA_VECTOR_HPP
27
29
30#include <dune/common/fvector.hh>
31
32#include <array>
33#include <cmath>
34#include <cstddef>
35
36namespace Opm::Linear
37{
38
48template <class ScalarT>
50{
51public:
53 using Scalar = ScalarT;
54
56 using field_type = ScalarT;
57
59 using EqVector = Dune::FieldVector<Scalar, numTpsaEq>;
60
63
66
68 using size_type = std::size_t;
69
76 {
77 public:
85 EntryProxy(IstlVector& v, std::size_t dofIdx)
86 : v_(&v)
87 , i_(dofIdx)
88 {
89 }
90
96 static constexpr std::size_t size()
97 {
98 return numTpsaEq;
99 }
100
108 Scalar& operator[](std::size_t eqIdx)
109 {
110 return at_(eqIdx);
111 }
112
120 Scalar operator[](std::size_t eqIdx) const
121 {
122 return at_(eqIdx);
123 }
124
133 operator EqVector() const;
134
143
152
161
170
179
188
189 private:
197 Scalar& at_(std::size_t eqIdx) const;
198
199 IstlVector* v_;
200 std::size_t i_;
201 };
202
204 TpsaVector() = default;
205
211 explicit TpsaVector(std::size_t numDof)
212 {
213 resize(numDof);
214 }
215
221 void resize(std::size_t numDof);
222
228 std::size_t size() const
229 {
230 return size_;
231 }
232
234 std::size_t N() const
235 {
236 return size_;
237 }
238
247
256
265
274
284 void scaleFields(const std::array<Scalar, numTpsaFields>& factors);
285
292
299
306 {
307 return std::sqrt(two_norm2());
308 }
309
316
324 EqVector operator[](std::size_t dofIdx) const;
325
333 EntryProxy operator[](std::size_t dofIdx)
334 {
335 return EntryProxy(v_, dofIdx);
336 }
337
344 {
345 return v_;
346 }
347
349 const IstlVector& istlVector() const
350 {
351 return v_;
352 }
353
354private:
355 IstlVector v_{};
356 std::size_t size_{0};
357};
358
359} // namespace Opm::Linear
360
361#endif // OPM_TPSA_VECTOR_HPP
Mutable reference to the seven equations of a single cell.
Definition: TpsaVector.hpp:76
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:85
static constexpr std::size_t size()
Number of equations the proxy exposes.
Definition: TpsaVector.hpp:96
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:120
Scalar & operator[](std::size_t eqIdx)
Access one equation of the cell.
Definition: TpsaVector.hpp:108
EntryProxy & operator=(const EqVector &value)
Scatter a dense 7x1 block into the sub-vectors.
Vector type for TPSA linear elasticity.
Definition: TpsaVector.hpp:50
EntryProxy operator[](std::size_t dofIdx)
Writable handle on the seven equations of cell dofIdx.
Definition: TpsaVector.hpp:333
Scalar two_norm() const
Euclidean norm of the vector.
Definition: TpsaVector.hpp:305
IstlVector & istlVector()
The underlying multi-type vector handed to the linear solver.
Definition: TpsaVector.hpp:343
std::size_t size_type
Type used for sizes and indices.
Definition: TpsaVector.hpp:68
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:59
TpsaMultiVector< Scalar > IstlVector
What the linear solver operates on.
Definition: TpsaVector.hpp:65
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:211
ScalarT Scalar
Field type of the vector entries.
Definition: TpsaVector.hpp:53
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:62
std::size_t N() const
Number of cells the vector holds equations for.
Definition: TpsaVector.hpp:234
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:56
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:349
std::size_t size() const
Number of cells the vector holds equations for.
Definition: TpsaVector.hpp:228
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:120
constexpr int numTpsaEq
Total number of TPSA equations per cell.
Definition: TpsaTypes.hpp:49