22 static LoggerPtr logger(Logger::getLogger(
"pz.matrix.tpzmatred"));
30 template<
class TVar,
class TS
ideMatrix>
33 TPZMatrix<TVar>( 0, 0 ), fK11(0,0),fK01(0,0),fK10(0,0),fF0(0,0),fF1(0,0), fMaxRigidBodyModes(0), fNumberRigidBodyModes(0)
42 template<
class TVar,
class TS
ideMatrix>
45 TPZMatrix<TVar>( dim,dim ),
fK11(dim-dim00,dim-dim00,0.),
fK01(dim00,dim-dim00,0.),
46 fK10(dim-dim00,dim00,0.),
fF0(dim00,1,0.),
fF1(dim-dim00,1,0.),
fMaxRigidBodyModes(0),
fNumberRigidBodyModes(0)
56 template<
class TVar,
class TS
ideMatrix>
60 template<
class TVar,
class TS
ideMatrix>
62 if(
fK00)
return this->
fK00->IsSimetric();
66 template<
class TVar,
class TS
ideMatrix>
71 if(!
fK00 || !this->
fK00->IsSimetric())
return;
86 template<
class TVar,
class TS
ideMatrix>
89 int64_t row(r),col(c);
92 if (row<fDim0 && col>=
fDim0)
fK01.PutVal(row,col-
fDim0,(TVar)value);
99 template<
class TVar,
class TS
ideMatrix>
102 int64_t row(r),col(c);
106 if (row<fDim0 && col>=
fDim0)
return (
fK01.GetVal(row,col-
fDim0) );
112 template<
class TVar,
class TS
ideMatrix>
114 int64_t row(r),col(c);
118 if (row<fDim0 && col>=
fDim0)
return ( (TVar &)
fK01.s(row,col-
fDim0) );
124 template<
class TVar,
class TS
ideMatrix>
127 fK00=solver->Matrix();
132 template<
class TVar,
class TS
ideMatrix>
139 template<
class TVar,
class TS
ideMatrix>
143 int64_t FCols=F.
Cols(),c,r,r1;
149 for(c=0; c<FCols; c++){
151 for(r=0; r<
fDim0; r++){
155 for( ;r<fDim0+
fDim1; r++){
160 if (logger->isDebugEnabled()) {
161 std::stringstream sout;
162 F.
Print(
"F Input",sout);
163 fF0.Print(
"fF0 Initialized",sout);
164 fF1.Print(
"fF1 Initialized",sout);
170 template<class TVar, class TSideMatrix>
179 if (logger->isDebugEnabled()) {
180 std::stringstream sout;
181 sout <<
"fF0 input " << std::endl;
194 if (logger->isDebugEnabled()) {
195 std::stringstream sout;
196 sout <<
"After computing F0Invert" << std::endl;
203 if (logger->isDebugEnabled()) {
204 std::stringstream sout;
205 sout <<
"Input fF1" << std::endl;
206 fF1.Print(
"fF1",sout);
213 if (logger->isDebugEnabled()) {
214 std::stringstream sout;
215 F1Red.
Print(
"F1 Reduced", sout);
222 template<
class TVar,
class TS
ideMatrix>
234 std::cout <<
"Address " << (
void *) step <<
" Number of singular modes " << step->
Singular().size() << std::endl;
237 if(logger->isDebugEnabled())
239 std::stringstream sout;
240 sout <<
"K01 after reduction\n";
258 std::cout << __PRETTY_FUNCTION__ <<
" should never be called\n";
266 std::cout << __PRETTY_FUNCTION__ <<
" should never be called\n";
274 std::cout << __PRETTY_FUNCTION__ <<
" should never be called\n";
282 std::cout << __PRETTY_FUNCTION__ <<
" should never be called\n";
288 template<
class TVar ,
class TS
ideMatrix>
321 fK01.MultAdd(U1,(
fF0),u0,-1,0);
326 for(c=0; c<
fF0.Cols(); c++)
329 for(r=0; r<
fDim0; r++)
331 result.
PutVal( r,c,u0.GetVal(r,c) ) ;
334 for( ;r<fDim0+
fDim1; r++)
341 template<
class TVar,
class TS
ideMatrix>
357 fK01.MultAdd(U1,(
fF0),u0,-1,1);
360 fK01.MultAdd(U1,
fF0,K01U1,-1.,1.);
367 if(logger->isDebugEnabled())
369 std::stringstream sout;
381 for(c=0; c<
fF0.Cols(); c++)
384 for(r=0; r<
fDim0; r++)
386 result.
PutVal( r,c,u0.GetVal(r,c) ) ;
389 for( ;r<fDim0+
fDim1; r++)
396 template<
class TVar,
class TS
ideMatrix>
412 fK01.MultAdd(U1,(
fF0),u0,-1,1);
415 fK01.MultAdd(U1,
fF0,K01U1,-1.,1.);
422 if(logger->isDebugEnabled())
424 std::stringstream sout;
425 fF0.Print(
"fF0 ",sout);
426 u0.Print(
"u0 " ,sout);
437 for(c=0; c<
fF0.Cols(); c++)
440 for(r=0; r<
fDim0; r++)
442 result(r,c) = u0(r,c) ;
447 result(r,c) =
U1(r1++,c);
453 template<
class TVar,
class TS
ideMatrix>
457 out <<
"Writing matrix 'TPZMatRed<TSideMatrix>::" << name;
458 out <<
"' (" << this->
Dim() <<
" x " << this->
Dim() <<
"):\n";
459 out <<
"fIsReduced " << this->
fIsReduced << std::endl;
464 fK00->Print(
"K00 =",out,form);
465 fK01.Print(
"K01 = ",out,form);
466 fK10.Print(
"K10 = ",out,form);
467 fK11.Print(
"K11 = ",out,form);
470 fF0.Print(
"F0 = ",out,form);
471 fF1.Print(
"F1 = ",out,form);
480 template<
class TVar,
class TS
ideMatrix>
504 template<
class TVar,
class TS
ideMatrix>
520 template<
class TVar,
class TS
ideMatrix>
523 const TVar alpha,
const TVar beta,
529 LOGPZ_WARN(logger,
"TPZMatRed not reduced, expect trouble")
544 fK01.Multiply(x,l_Res,0);
547 if(logger->isDebugEnabled())
549 std::stringstream sout;
550 l_Res.Print(
"Internal solution",sout);
555 fK11.Multiply(x,l_ResFinal,0);
557 if(logger->isDebugEnabled())
559 std::stringstream sout;
560 l_ResFinal.Print(
"Intermediate product l_ResFinal",sout);
564 fK10.MultAdd(l_Res,l_ResFinal,z,-alpha,alpha,opt);
566 if(logger->isDebugEnabled())
568 std::stringstream sout;
569 z.
Print(
"Final result z ",sout);
581 template<
class TVar,
class TS
ideMatrix>
584 if(
fK00->IsDecomposed())
607 directsolve = stepsolve;
616 directsolve = prestep;
622 std::list<int64_t> &singular = directsolve->
Singular();
623 std::list<int64_t>::iterator it;
624 int nsing = singular.size();
627 std::cout <<
"Number of rigid body modes larger than provision\n";
628 std::cout <<
"Number of singular modes " << nsing << std::endl;
629 std::cout <<
"Number of rigid body modes reserved " <<
fMaxRigidBodyModes << std::endl;
630 std::cout <<
"Rigid body modes ";
631 for (it=singular.begin(); it != singular.end(); it++) {
632 std::cout <<
" " << *it;
634 std::cout << std::endl;
637 for (it=singular.begin(); it != singular.end(); it++) {
643 if(stepsolve != directsolve)
645 TVar diag = stepsolve->
Matrix()->GetVal(*it, *it)+ (TVar)1.;
646 stepsolve->
Matrix()->PutVal(*it, *it, diag);
658 template<
class TVar,
class TS
ideMatrix>
672 this->
fF0.Write(buf, 0);
673 this->
fF1.Write(buf, 0);
675 this->
fK01.Write(buf, 0);
676 this->
fK10.Write(buf, 0);
677 this->
fK11.Write(buf, 0);
680 std::cout <<
"Error\n";
695 template<
class TVar,
class TS
ideMatrix>
709 this->
fF0.Read(buf, 0);
710 this->
fF1.Read(buf, 0);
717 this->
fK01.Read(buf, 0);
718 this->
fK10.Read(buf, 0);
719 this->
fK11.Read(buf, 0);
722 if (sav && !matsolv) {
int ClassId() const override
Saveable methods.
Contains definitions to LOGPZ_DEBUG, LOGPZ_INFO, LOGPZ_WARN, LOGPZ_ERROR and LOGPZ_FATAL, and the implementation of the inline InitializePZLOG(string) function using log4cxx library or not. It must to be called out of "#ifdef LOG4CXX" scope.
void Write(TPZStream &buf, int withclassid) const override
Packs the object structure in a stream of bytes.
static int Error(const char *msg, const char *msg2=0)
Returns error messages.
void SimetrizeMatRed()
If fK00 is simetric, only part of the matrix is accessible to external objects.
void F1Red(TPZFMatrix< TVar > &F1)
Computes the reduced version of the right hand side .
static void Swap(int64_t *row, int64_t *col)
Swaps the row and column index.
void UGlobal(const TPZFMatrix< TVar > &U1, TPZFMatrix< TVar > &result)
Computes the complete vector based on the solution u1.
TPZFMatrix< TVar > & K11()
Defines a abstract class of solvers which will be used by matrix classes. Solver. ...
Defines step solvers class. Solver.
MatrixOutputFormat
Defines output format.
int64_t fRow
Number of rows in matrix.
void SetF(const TPZFMatrix< TVar > &F)
Copies the F vector in the internal data structure.
void UGlobal2(TPZFMatrix< TVar > &U1, TPZFMatrix< TVar > &result)
Defines a class of matrix solvers. Solver.
void PrepareZ(const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar beta, const int opt) const
Is an auxiliar method used by MultiplyAdd.
#define LOGPZ_WARN(A, B)
Define log for warnings.
virtual TPZMatrixSolver< TVar >::MSolver Solver() override
Contains TPZMatRed class which implements a simple substructuring of a linear system of equations...
virtual void MultAdd(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar alpha=1., const TVar beta=0., const int opt=0) const
It computes z = beta * y + alpha * opt(this)*x but z and x can not overlap in memory.
void SetK00(TPZAutoPointer< TPZMatrix< TVar > > K00)
Sets the matrix pointer of the upper left matrix to K00.
void MultAdd(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar alpha, const TVar beta, const int opt) const override
It computes z = beta * y + alpha * opt(this)*x but z and x can not overlap in memory.
bool fK01IsComputed
Is true if has been computed and overwritten .
void SetSolver(TPZAutoPointer< TPZMatrixSolver< TVar > > solver)
virtual TVar & s(const int64_t row, const int64_t col) override
The operators check on the bounds if the DEBUG variable is defined.
void Print(const char *name=NULL, std::ostream &out=std::cout, const MatrixOutputFormat=EFormatted) const override
Prints the object data structure.
static TPZAutoPointer< TPZSavable > GetAutoPointer(const int64_t &objId)
std::list< int64_t > & Singular()
returns the equations for which the equations had zero pivot
void Read(TPZStream &buf, void *context) override
read objects from the stream
TPZFMatrix< TVar > fF0
Right hand side or force matrix.
virtual void Write(const bool val)
virtual void Decompose() override
Decompose the system of equations if a direct solver is used.
virtual void UpdateFrom(TPZAutoPointer< TPZMatrix< TVar > > matrix) override
Updates the values of the current matrix based on the values of the matrix.
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
TPZAutoPointer< TPZMatrixSolver< TVar > > fSolver
Solution method for inverting .
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define DebugStop()
Returns a message to user put a breakpoint in.
Implements a matrix whose nonzero elements are stored in binary tree. Matrix.
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
bool fF0IsComputed
Is true if has been computed and overwritten .
bool fIsReduced
Is true if the declared dimension of the matrix is fDim0.
TPZAutoPointer< TPZMatrix< TVar > > fK00
Stiffnes matrix.
void Read(TPZStream &buf, void *context) override
Unpacks the object structure from a stream of bytes.
TPZFMatrix< TVar > fK11
Full Stiffnes matrix.
virtual int Redim(const int64_t newRows, const int64_t newCols)
Redimensions the matrix reinitializing it with zero.
Full matrix class. Matrix.
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
int Redim(const int64_t dim, const int64_t dim00) override
Redim: Set the dimension of the complete matrix and reduced matrix.
virtual int64_t Dim() const
Returns the dimension of the matrix if the matrix is square.
void DecomposeK00()
Decompose K00 and adjust K01 and K10 to reflect rigid body modes.
int64_t fCol
Number of cols in matrix.
virtual int PutVal(const int64_t row, const int64_t col, const TVar &value) override
Put and Get values without bounds checking these methods are faster than "Put" e "Get" if DEBUG is de...
int fNumberRigidBodyModes
Number of rigid body modes identified during the decomposition of fK00.
Implements a simple substructuring of a linear system of equations, composed of 4 submatrices...
TPZSolver< TVar > * PreConditioner()
access method to the preconditioner
TPZAutoPointer< TPZMatrix< TVar > > K00()
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
void K11Reduced(TPZFMatrix< TVar > &K11, TPZFMatrix< TVar > &F1)
Computes the K11 reduced .
TPZAutoPointer< TPZMatrix< TVar > > Matrix() const
Returns a pointer to TPZMatrix<>
virtual int IsSimetric() const override
returns 1 or 0 depending on whether the fK00 matrix is zero or not
Contains TPZStepSolver class which defines step solvers class.
Contains TPZVerySparseMatrix class which implements a matrix whose nonzero elements are stored in bin...
int64_t Cols() const
Returns number of cols.
virtual void Print(std::ostream &out) const
int Resize(const int64_t newRows, const int64_t wCols) override
Redimension a matrix, but maintain your elements.
Defines the interface for saving and reading data. Persistency.
int64_t fDim0
Stores matricess dimensions.
TPZFMatrix< TVar > & F1()
virtual const TVar & GetVal(const int64_t row, const int64_t col) const override
Get values without bounds checking This method is faster than "Get" if DEBUG is defined.
int fMaxRigidBodyModes
Number of rigid body modes foreseen in the computational mesh.
~TPZMatRed()
Simple destructor.
REAL ZeroTolerance()
Returns the tolerance to Zero value. Actually: .
int PutVal(const int64_t row, const int64_t col, const TVar &value) override
Put values without bounds checking This method is faster than "Put" if DEBUG is defined.
const TVar & GetVal(const int64_t row, const int64_t col) const override
Get values without bounds checking This method is faster than "Get" if DEBUG is defined.
static void WritePointer(const TPZSavable *obj, TPZStream *stream)
virtual int Zero() override
This method will zero all submatrices associated with this reducable matrix class.
Implements an interface to register a class id and a restore function. Persistence.
virtual int SolveDirect(TPZFMatrix< TVar > &F, const DecomposeType dt, std::list< int64_t > &singular)
Solves the linear system using Direct methods.
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
TPZMatRed()
Simple constructor.
virtual void Read(bool &val)
void U1(TPZFMatrix< TVar > &F)
Returns the second vector, inverting K11.
Root matrix class (abstract). Matrix.
This class implements a reference counter mechanism to administer a dynamically allocated object...