Plugins
Loading...
Searching...
No Matches
df_transform.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Gesellschaft fuer Anlagen- und Reaktorsicherheit gGmbH
3 * SPDX-License-Identifier: EUPL-1.2
4 * SPDX-FileContributor: Arne Naegel
5 * SPDX-FileContributor: Goethe Universität Frankfurt
6 * SPDX-FileType: SOURCE
7 *
8 * This file is part of d3f++.
9 * d3f++ is an extension for UG4. Licensing information and citation requirements of UG4 are provided in LICENSES/UG4-LGPL_2.1
10 */
11
12#ifndef __H__UG__DF_TRANSFORM_H_
13#define __H__UG__DF_TRANSFORM_H_
14
15#include <vector>
16
17
18
19namespace ug{
20namespace df{
21
22
23
24
25
26
27template<class TAlgebra>
29{
30
31public:
32
33
34 typedef typename TAlgebra::matrix_type matrix_type;
35 typedef typename TAlgebra::vector_type vector_type;
36
37protected:
38
40
41
42 static int transform_operator(const std::vector<double> &sigma, const matrix_type &A, matrix_type &Anew)
43 {
44
45 // std::cout << "DFLeftTransformMatrix....";
46
47 // copy
48 Anew.set_as_copy_of(A);
49
50 // eliminate off-diag entries of diagonal element
51 const size_t N = A.num_rows();
52 for(size_t i=0; i < N; i++)
53 {
54 // eliminate off-diag entries of diagonal element
55 // "eliminate" i-th row of A
56 const typename TAlgebra::matrix_type::row_iterator rowEnd = Anew.end_row(i);
57 for(typename TAlgebra::matrix_type::row_iterator ij_iter = Anew.begin_row(i);
58 ij_iter != rowEnd; ++ij_iter)
59 {
60 typename TAlgebra::matrix_type::value_type &Aij = ij_iter.value();
61 //std::cout << Aij << "->" << sigma[i];
62
63
64 for (size_t beta=0; beta<GetCols(Aij); ++beta)
65 {
66 BlockRef(Aij, CONCENTRATION, beta) -= sigma[i] * BlockRef(Aij, PRESSURE, beta);
67 }
68
69 //std::cout << "->" << Aij << std::endl;
70 }
71 }
72
73 return 0;
74 };
75
76
77 static int transform_rhs(const std::vector<double> &sigma, const vector_type &rhs, vector_type &rhs_new)
78 {
79 // std::cout << "DFLeftTransformRHS....";
80
81 // copy
82 rhs_new=rhs;
83
84 // transform
85 const size_t N = rhs_new.size();
86 for(size_t i=1; i < N; i++)
87 {
88 // eliminate off-diag entries of diagonal element
89 BlockRef(rhs_new[i], CONCENTRATION) -= sigma[i] * BlockRef(rhs_new[i], PRESSURE);
90 //std::cout << BlockRef(rhs[i], CONCENTRATION) << "->"<< BlockRef(rhs_new[i], CONCENTRATION) << std::endl;
91 }
92 return 0;
93 };
94
95};
96
97template<class TAlgebra>
98class DFAlgebraicLeftTransform : public DFTransform<TAlgebra>
99{
100
101
102public:
103 typedef typename TAlgebra::matrix_type matrix_type;
104 typedef typename TAlgebra::vector_type vector_type;
106
107 // called once
108 void init(const matrix_type &A, const vector_type *sol)
109 {
110 const size_t N = A.num_rows();
111 sigma.resize(N);
112
113 for(size_t i=1; i < N; i++)
114 {
115 const typename TAlgebra::matrix_type::value_type &Aii=A(i,i);
116
119 }
120 }
121
124
125 int transform_rhs(const vector_type &rhs, vector_type &rhs_new)
126 { return DFTransform<TAlgebra>::transform_rhs(sigma, rhs, rhs_new); }
127
128protected:
129 std::vector<double> sigma;
130};
131
132
133template<class TAlgebra>
134class DFLeftTransform : public DFTransform<TAlgebra>
135{
136
137
138public:
139 typedef typename TAlgebra::matrix_type matrix_type;
140 typedef typename TAlgebra::vector_type vector_type;
141
143
144 void init(const matrix_type &A, const vector_type *sol)
145 {
146 const size_t N = A.num_rows();
147 sigma.resize(N);
148
149 for(size_t i=1; i < N; i++)
150 {
151 const typename TAlgebra::matrix_type::value_type &Aii=A(i,i);
152
155 }
156 }
157
160
161 int transform_rhs(const vector_type &rhs, vector_type &rhs_new)
162 { return DFTransform<TAlgebra>::transform_rhs(sigma, rhs, rhs_new); }
163
164protected:
165 std::vector<double> sigma;
166};
167
168
169
170} // namespace df
171} // namespace ug
172#endif /* DF_PRECOND_H_ */
Definition df_transform.h:99
int transform_rhs(const vector_type &rhs, vector_type &rhs_new)
Definition df_transform.h:125
TAlgebra::matrix_type matrix_type
Definition df_transform.h:103
void init(const matrix_type &A, const vector_type *sol)
Definition df_transform.h:108
TAlgebra::vector_type vector_type
Definition df_transform.h:104
DFAlgebraicLeftTransform()
Definition df_transform.h:105
std::vector< double > sigma
Definition df_transform.h:129
int transform_operator(const matrix_type &A, matrix_type &Anew)
Definition df_transform.h:122
Definition df_transform.h:135
int transform_operator(const matrix_type &A, matrix_type &Anew)
Definition df_transform.h:158
DFLeftTransform()
Definition df_transform.h:142
void init(const matrix_type &A, const vector_type *sol)
Definition df_transform.h:144
std::vector< double > sigma
Definition df_transform.h:165
int transform_rhs(const vector_type &rhs, vector_type &rhs_new)
Definition df_transform.h:161
TAlgebra::matrix_type matrix_type
Definition df_transform.h:139
TAlgebra::vector_type vector_type
Definition df_transform.h:140
Definition df_transform.h:29
TAlgebra::matrix_type matrix_type
Definition df_transform.h:34
TAlgebra::vector_type vector_type
Definition df_transform.h:35
static int transform_operator(const std::vector< double > &sigma, const matrix_type &A, matrix_type &Anew)
Definition df_transform.h:42
DFComponents
Definition df_transform.h:39
@ PRESSURE
Definition df_transform.h:39
@ CONCENTRATION
Definition df_transform.h:39
static int transform_rhs(const std::vector< double > &sigma, const vector_type &rhs, vector_type &rhs_new)
Definition df_transform.h:77
const number & BlockRef(const number &m, size_t i)
size_t GetCols(const DenseMatrix< T > &t)