-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpzsfulmat.h
247 lines (208 loc) · 7.31 KB
/
pzsfulmat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/**
* @file
* @brief Contains TPZSFMatrix class which implements a symmetric full matrix.
*/
#ifndef _TSFULMATHH_
#define _TSFULMATHH_
#include "pzmatrix.h"
#include "pzfmatrix.h"
#ifdef OOPARLIB
#include "pzsaveable.h"
#include "pzmatdefs.h"
#endif
/**
* @brief Implements a symmetric full matrix. \ref matrix "Matrix"
* @ingroup matrix
*/
template<class TVar>
class TPZSFMatrix : public TPZMatrix<TVar> {
public:
TPZSFMatrix () : TPZRegisterClassId(&TPZSFMatrix::ClassId),
TPZMatrix<TVar>( 0,0 ) { fElem = NULL; }
TPZSFMatrix (const int64_t dim );
TPZSFMatrix (const TPZSFMatrix<TVar> & );
TPZSFMatrix (TPZSFMatrix<TVar> && );
// Usa o maior bloco quadrado possivel, comecado em (0,0).
// E inicializa com a parte triangular inferior do bloco.
TPZSFMatrix (const TPZMatrix<TVar> & );
TPZSFMatrix &operator= (const TPZSFMatrix<TVar> &A );
TPZSFMatrix &operator= (TPZSFMatrix<TVar> &&A );
inline TPZSFMatrix<TVar>*NewMatrix() const override {return new TPZSFMatrix<TVar>{};}
CLONEDEF(TPZSFMatrix)
~TPZSFMatrix();
/** @brief Checks if the current matrix is symmetric */
virtual int IsSymmetric() const override {
return 1;
}
friend class TPZSFMatrix<float>;
friend class TPZSFMatrix<double>;
/// copy the values from a matrix with a different precision
template<class TVar2>
void CopyFromDiffPrecision(TPZSFMatrix<TVar2> &orig)
{
Resize(orig.Rows(), orig.Cols());
TPZMatrix<TVar>::CopyFromDiffPrecision(orig);
int64_t nel = (this->Rows()*(this->Rows()+1))/2;
for (int64_t el=0; el<nel; el++) {
fElem[el] = orig.fElem[el];
}
}
/** @brief Creates a copy from another TPZSFMatrix*/
void CopyFrom(const TPZMatrix<TVar> * mat) override
{
auto *from = dynamic_cast<const TPZSFMatrix<TVar> *>(mat);
if (from) {
*this = *from;
}
else
{
PZError<<__PRETTY_FUNCTION__;
PZError<<"\nERROR: Called with incompatible type\n.";
PZError<<"Aborting...\n";
DebugStop();
}
}
int PutVal(const int64_t row,const int64_t col,const TVar &value ) override;
const TVar GetVal(const int64_t row,const int64_t col ) const override;
/**
* @name Operators with Full simmetric matrices.
* @{
*/
TPZSFMatrix operator+ (const TPZSFMatrix<TVar> &A ) const;
TPZSFMatrix operator- (const TPZSFMatrix<TVar> &A ) const;
TPZSFMatrix &operator+=(const TPZSFMatrix<TVar> &A );
TPZSFMatrix &operator-=(const TPZSFMatrix<TVar> &A );
/** @} */
/**
* @name Operators with generic matrices.
* @{
*/
TPZSFMatrix &operator= (const TPZMatrix<TVar> &A );
TPZSFMatrix operator+ (const TPZMatrix<TVar> &A ) const;
TPZSFMatrix operator- (const TPZMatrix<TVar> &A ) const;
TPZSFMatrix &operator+=(const TPZMatrix<TVar> &A );
TPZSFMatrix &operator-=(const TPZMatrix<TVar> &A );
/** @} */
/**
* @name Operators with numeric values.
* @{
*/
TPZSFMatrix &operator= (const TVar val );
TPZSFMatrix operator+ (const TVar val ) const;
TPZSFMatrix operator- (const TVar val ) const { return operator+( -val ); }
TPZSFMatrix operator* (const TVar val ) const;
TPZSFMatrix &operator+=(const TVar val );
TPZSFMatrix &operator-=(const TVar val ) { return operator+=( -val ); }
TPZSFMatrix &operator*=(const TVar val ) override;
/** @} */
TPZSFMatrix operator-() const { return operator*( -1.0 ); }
/** @brief Resize the array but keeps its entirety. */
int Resize(const int64_t newDim, const int64_t ) override;
/** @brief Resize the array and resets ist entirety. */
int Redim(const int64_t newRows ,const int64_t) override;
int Redim(const int64_t newDim) {return Redim(newDim,newDim);}
/** @brief Resets all elements. */
int Zero() override;
/**
* @name To solve linear systems
* @{
*/
virtual int Decompose_Cholesky() override;
virtual int Decompose_LDLt() override;
virtual int Decompose_Cholesky(std::list<int64_t> &singular) override;
virtual int Decompose_LDLt(std::list<int64_t> &singular) override;
virtual int Subst_Forward ( TPZFMatrix<TVar> *B ) const override;
virtual int Subst_Backward ( TPZFMatrix<TVar> *B ) const override;
virtual int Subst_LForward ( TPZFMatrix<TVar> *B ) const override;
virtual int Subst_LBackward( TPZFMatrix<TVar> *B ) const override;
virtual int Subst_Diag ( TPZFMatrix<TVar> *B ) const override;
/** @} */
#ifdef OOPARLIB
virtual int Unpack( TReceiveStorage *buf );
static TSaveable *Restore(TReceiveStorage *buf);
virtual int Pack( TSendStorage *buf ) const;
virtual std::string ClassName() const { return( "TPZSFMatrix"); }
virtual int DerivedFrom(const int64_t Classid) const;
virtual int DerivedFrom(const char *classname) const;
#endif
int ClassId() const override;
protected:
/** @brief Checks compatibility of matrices before Add/Subtract operations*/
inline void CheckTypeCompatibility(const TPZMatrix<TVar>*A,
const TPZMatrix<TVar>*B)const override
{
auto aPtr = dynamic_cast<const TPZSFMatrix<TVar>*>(A);
auto bPtr = dynamic_cast<const TPZSFMatrix<TVar>*>(B);
if(!aPtr || !bPtr){
PZError<<__PRETTY_FUNCTION__;
PZError<<"\nERROR: incompatible matrices.Aborting...\n";
DebugStop();
}
}
inline TVar *&Elem() override
{
return fElem;
}
inline const TVar *Elem() const override
{
return fElem;
}
int64_t Size() const override { return (this->Dim() * (this->Dim()+1)) >> 1; }
private:
int Clear() override;
TVar *fElem;
};
/**************/
/*** PutVal ***/
template<class TVar>
inline int
TPZSFMatrix<TVar> ::PutVal(const int64_t row,const int64_t col,const TVar &value )
{
int64_t locrow = row, loccol = col;
if ( locrow < loccol )
this->Swap( &locrow, &loccol );
this->fDecomposed = 0;
this->fElem[ ((locrow*(locrow+1)) >> 1) + loccol ] = value;
return( 1 );
}
/**************/
/*** GetVal ***/
template<class TVar>
inline const TVar
TPZSFMatrix<TVar> ::GetVal(const int64_t row,const int64_t col ) const
{
if ( row < col ){
if constexpr (is_complex<TVar>::value){
return( std::conj(fElem[ ((col*(col+1)) >> 1) + row ]) );
}else{
return( fElem[ ((col*(col+1)) >> 1) + row ] );
}
}
return( fElem[ ((row*(row+1)) >> 1) + col ] );
}
/**************************/
/*** @name Operadores Globais ***/
/** @{ */
/** @brief Increments value for all entries of the A matrix */
template<class TVar>
inline TPZSFMatrix<TVar>
operator+( const TVar value, const TPZSFMatrix<TVar> &A )
{
return( A + value );
}
/** @brief Decrements value for all entries of the A matrix */
template<class TVar>
inline TPZSFMatrix<TVar>
operator-( const TVar value,const TPZSFMatrix<TVar> &A )
{
return( A - value );
}
/** @brief Implements the scalar product value*A */
template<class TVar>
inline TPZSFMatrix<TVar>
operator*( const TVar value, const TPZSFMatrix<TVar> &A )
{
return( A * value );
}
/** @} */
#endif