NeoPZ
pzseqsolver.cpp
Go to the documentation of this file.
1 
6 #include "pzseqsolver.h"
8 
9 using namespace std;
10 
11 template<class TVar>
13 TPZMatrixSolver<TVar>(refmat), fSolvers() {
14 }
15 
16 template<class TVar>
18 TPZMatrixSolver<TVar>(copy) {
19  int nums = copy.fSolvers.NElements();
20  int s;
21  for(s=0; s<nums; s++) AppendSolver(*copy.fSolvers[s]);
22 }
23 
24 template <class TVar>
26  return new TPZSequenceSolver(*this);
27 }
28 
29 template<class TVar>
32 }
33 
34 template <class TVar>
36  int nums = fSolvers.NElements();
37  int s;
38  for(s=0; s<nums; s++) delete fSolvers.Pop();
39 }
40 
41 template<class TVar>
43  if(!this->Matrix()) {
44  cout << "TPZSequenceSolver::Solve called without a matrix pointer\n";
45  }
46  TPZAutoPointer<TPZMatrix<TVar> > mat = this->Matrix();
47  if(result.Rows() != mat->Rows() || result.Cols() != F.Cols()) {
48  result.Redim(mat->Rows(),F.Cols());
49  }
50 
51  this->fScratch = F;
52  TPZFMatrix<TVar> delu(result.Rows(),result.Cols(),0.);
53  TPZFMatrix<TVar> resloc(F.Rows(),F.Cols(),0.);
54  result.Zero();
55  if(this->fScratch.Rows() != result.Rows() || this->fScratch.Cols() != result.Cols()) {
56  this->fScratch.Redim(result.Rows(),result.Cols());
57  }
58  int nums = fSolvers.NElements();
59  int s;
60  for(s=0; s<nums; s++) {
61  fSolvers[s]->Solve(this->fScratch,delu,&resloc);
62  result += delu;
63  mat->Residual(result,F,this->fScratch);
64  }
65  if(residual) *residual = this->fScratch;
66 }
67 
68 
73 template<class TVar>
75 {
76  int nums = fSolvers.NElements();
77  int s;
78  for(s=0; s<nums; s++) {
79  fSolvers[s]->ResetMatrix();
80  }
82 }
83 
87 template <class TVar>
89 {
90  int nums = fSolvers.NElements();
91  int s;
92  for(s=0; s<nums; s++) {
93  fSolvers[s]->UpdateFrom(matrix);
94  }
96 }
97 
98 template<class TVar>
99 void TPZSequenceSolver<TVar>::Write(TPZStream &buf, int withclassid) const
100 {
101  TPZMatrixSolver<TVar>::Write(buf, withclassid);
102  int StackSz = fSolvers.NElements();
103  buf.Write(&StackSz, 1);
104  int i = 0;
105  for(i = 0; i < StackSz; i++)
106  {
108  }
109 
110 }
111 template <class TVar>
112 void TPZSequenceSolver<TVar>::Read(TPZStream &buf, void *context)
113 {
114  TPZMatrixSolver<TVar>::Read(buf, context);
115  int StackSz = 0;
116  buf.Read(&StackSz, 1);
117  fSolvers.Resize(StackSz);
118  for(int i = 0; i< StackSz; i++)
119  {
121  }
122 }
123 
124 template class TPZSequenceSolver<float>;
126 template class TPZSequenceSolver<double>;
128 template class TPZSequenceSolver<long double>;
130 
131 #ifndef BORLAND
138 #endif
int ClassId() const override
Define the class id associated with the class.
Definition: pzsbndmat.cpp:1989
void ResetMatrix() override
Resets current object.
Definition: pzsolve.cpp:50
void ResetSolver()
This method will reinitialize the solver object, including the solution procedure.
Definition: pzseqsolver.cpp:35
virtual void UpdateFrom(TPZAutoPointer< TPZMatrix< TVar > > matrix) override
Updates the values of the current matrix based on the values of the matrix.
Definition: pzsolve.h:121
TPZSequenceSolver(TPZMatrix< TVar > *refmat=0)
Constructor with initialization parameter.
Definition: pzseqsolver.cpp:12
TPZStack< TPZMatrixSolver< TVar > *> fSolvers
Definition: pzseqsolver.h:62
Defines a abstract class of solvers which will be used by matrix classes. Solver. ...
Definition: pzmatrix.h:32
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzsolve.cpp:65
Defines a class of matrix solvers. Solver.
Definition: pzanalysis.h:24
void AppendSolver(TPZMatrixSolver< TVar > &solve)
Definition: pzseqsolver.cpp:30
virtual TPZSolver< TVar > * Clone() const override
Clones the current object returning a pointer of type TPZSolver.
Definition: pzseqsolver.cpp:25
static TPZSavable * GetInstance(const int64_t &objId)
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzseqsolver.cpp:99
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
void Solve(const TPZFMatrix< TVar > &F, TPZFMatrix< TVar > &result, TPZFMatrix< TVar > *residual=0) override
Solves the system of linear equations.
Definition: pzseqsolver.cpp:42
TPZSkylMatrix< REAL > matrix
Definition: numatst.cpp:255
virtual TVar & s(const int64_t row, const int64_t col)
The operators check on the bounds if the DEBUG variable is defined.
Definition: pzmatrix.h:879
int Zero() override
Makes Zero all the elements.
Definition: pzfmatrix.h:651
virtual void ResetMatrix() override
This method will reset the matrix associated with the solver.
Definition: pzseqsolver.cpp:74
void Push(const T object)
Pushes a copy of the object on the stack.
Definition: pzstack.h:80
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
void Read(TPZStream &buf, void *context) override
read objects from the stream
Definition: pzsolve.cpp:106
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
Contains TPZSequenceSolver class which defines sequence solvers.
void Read(TPZStream &buf, void *context) override
read objects from the stream
virtual void UpdateFrom(TPZAutoPointer< TPZMatrix< TVar > > mat) override
Updates the values of the preconditioner based on the values of the matrix.
Definition: pzseqsolver.cpp:88
TPZFMatrix< TVar > fScratch
Manipulation matrix.
Definition: pzsolve.h:169
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
Definition: pzfmatrix.h:616
int ClassId() const override
Saveable specific methods.
Definition: pzseqsolver.h:66
virtual TPZSolver * Clone() const =0
Clones the current object returning a pointer of type TPZSolver.
T Pop()
Retrieve an object from the stack.
Definition: pzstack.h:87
Defines sequence solvers. Solver.
Definition: pzseqsolver.h:23
TPZAutoPointer< TPZMatrix< TVar > > Matrix() const
Returns a pointer to TPZMatrix<>
Definition: pzsolve.h:138
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
static void WritePointer(const TPZSavable *obj, TPZStream *stream)
Implements an interface to register a class id and a restore function. Persistence.
Definition: TPZSavable.h:150
virtual void Read(bool &val)
Definition: TPZStream.cpp:91
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60
This class implements a reference counter mechanism to administer a dynamically allocated object...