24 const REAL
TOL=1.e-10;
32 static LoggerPtr logger(Logger::getLogger(
"pz.frontstrmatrix.frontnonsym"));
40 for(i=0;i<this->fLocal.NElements();i++){
41 if(this->fLocal[i]!=-1) out << i <<
" ";
44 for(i=0;i<this->fLocal.NElements();i++){
45 if(this->fLocal[i]==-1)
continue;
46 for(j=0;j<this->fLocal.NElements();j++){
47 if(this->fLocal[j]==-1)
continue;
48 out << Element(this->fLocal[i],this->fLocal[j]) <<
" ";
59 if(name) out << name << endl;
60 int64_t i,j,loop_limit;
63 out <<
"Frontal Matrix Size "<< this->fFront << endl;
64 out <<
"Maximum Frontal Matrix Size "<< this->fMaxFront << endl;
67 out <<
"Local Indexation "<< endl;
68 out <<
"Position "<<
" Local index"<< endl;
69 for(i=0;i<this->fLocal.NElements();i++){
70 out << i <<
" " << this->fLocal[i] << endl;
74 out <<
"Global Indexation "<< endl;
75 out <<
"Position "<<
" Global index"<< endl;
77 for(i=0;i<this->fGlobal.NElements();i++){
78 out << i <<
" "<< this->fGlobal[i] << endl;
82 out <<
"Local Freed Equations "<< this->fFree.NElements() << endl;
83 out <<
"position "<<
"Local Equation "<<endl;
84 loop_limit=this->fFree.NElements();
85 for(i=0;i<loop_limit;i++){
86 out << i <<
" " << this->fFree[i] << endl;
88 out <<
"Frontal Matrix "<< endl;
89 if(this->fData.NElements() > 0) {
90 for(i=0;i<this->fFront;i++){
91 for(j=0;j<this->fFront;j++) out << Element(i,j) <<
" ";
100 this->fData.Resize(this->fMaxFront*this->fMaxFront);
101 this->fGlobal.Fill(-1);
102 this->fData.Fill(0.);
110 this->fData.Resize(0);
111 this->fFree.Resize(0);
113 this->fGlobal.Resize(0);
114 this->fLocal.Resize(GlobalSize);
115 this->fLocal.Fill(-1);
118 this->fNextRigidBodyMode = GlobalSize;
124 return this->fFree.NElements();
131 if(this->fLocal[global]!=-1)
return this->fLocal[global];
132 if(this->fFree.NElements()){
133 index=this->fFree.Pop();
138 if(index >= this->fMaxFront) {
141 Expand(index+this->fExpandRatio);
143 this->fLocal[global]=index;
144 if(index==this->fFront) this->fFront++;
145 if(this->fGlobal.NElements()<=index) this->fGlobal.Resize(index+1);
146 this->fGlobal[index]=global;
153 if(this->fLocal[global]==-1){
154 cout <<
"TPZFront FreeGlobal was called with wrong parameters !" << endl;
158 index=this->fLocal[global];
159 this->fGlobal[index]=-1;
160 this->fLocal[global]=-1;
161 this->fFree.Push(index);
193 double diagonal=
fabs(Element(ilocal,ilocal));
194 std::stringstream sout;
195 sout<<
" Valor da Diagonal ( " << ilocal<<
", "<< ilocal<<
" ) = "<< diagonal<<std::endl;
201 if(
fabs(Element(ilocal,ilocal)) <
TOL)
203 Local(this->fNextRigidBodyMode);
213 for(i=0;i<this->fFront;i++){
214 AuxVecCol[i]=Element(i,ilocal);
215 AuxVecRow[i]=Element(ilocal,i);
219 TVar diag = AuxVecRow[ilocal];
222 if (this->fNextRigidBodyMode < this->fLocal.NElements()) {
223 int jlocal = Local(this->fNextRigidBodyMode);
226 AuxVecRow[ilocal] = 1.;
227 AuxVecRow[jlocal] = -1.;
228 AuxVecCol[jlocal] = -1.;
230 Element(ilocal, jlocal) = -1.;
231 Element(jlocal, ilocal) = -1.;
232 Element(jlocal, jlocal) = 1.;
233 this->fNextRigidBodyMode++;
242 for(i=0;i<this->fFront;i++){
246 this->fWork+=this->fFront*this->fFront;
283 if(this->fProductMTData){
284 this->ProductTensorMT( AuxVecCol, AuxVecRow );
287 for(j=0;j<this->fFront;j++){
288 for(i=0;i<this->fFront;i++)
289 Element(i,j)-=AuxVecCol[i]*AuxVecRow[j];
296 AuxVecRow[ilocal]=1.;
299 for(i=0;i<this->fFront;i++) {
300 if(i!=ilocal && this->fGlobal[i]!= -1 && AuxVecRow[i] != 0.) eqnarray.
AddTerm(this->fGlobal[i],AuxVecRow[i]);
306 for(i=0;i<this->fFront;i++) {
307 if(i!=ilocal && this->fGlobal[i]!= -1 && AuxVecCol[i] != 0.) eqnarray.
AddTerm(this->fGlobal[i],AuxVecCol[i]);
316 for(i=0;i<this->fFront;i++){
317 Element(i,ilocal)=0.;
318 Element(ilocal,i)=0.;
323 this->fDecomposeType=
ELU;
327 template <
class TVar>
334 const int Nthreads = data->
NThreads();
336 for(
int j = 0 + ithread; j < n; j += Nthreads){
337 const TVar RowVal = data->
fAuxVecRow->operator[](j);
339 TVar * ElemPtr = &(this->Element(i,j));
340 TVar * ColValPtr = &(data->
fAuxVecCol->operator[](i));
341 for(; i < n; i++, ColValPtr++, ElemPtr++){
342 (*ElemPtr) -= (*ColValPtr) * RowVal;
352 int64_t i, j, ilocal, jlocal, nel;
354 for (i = 0; i < nel; i++) {
356 ilocal = this->Local(destinationindex[i]);
357 for (j = 0; j < nel; j++) {
359 jlocal = this->Local(destinationindex[j]);
362 this->Element(ilocal, jlocal)+=elmat(sourceindex[i],sourceindex[j]);
370 int64_t i, j, ilocal, jlocal, nel;
373 ilocal = this->Local(destinationindex[i]);
375 jlocal=this->Local(destinationindex[j]);
376 this->Element(ilocal, jlocal)+=elmat(i,j);
384 this->fData.Resize(larger*larger,0.);
386 for(j=this->fFront-1;j>=0;j--){
387 for(i=this->fFront-1;i>=0;i--){
388 this->fData[j*larger + i]=this->fData[j*this->fMaxFront + i];
389 if(j) this->fData[j*this->fMaxFront+i] = 0.;
392 this->fMaxFront = larger;
402 for(i = 0; i < this->fFront; i++){
403 if(this->fGlobal[i] != -1) from.
Push(i);
411 for(i=0;i<nfound;i++) {
412 this->fGlobal[i]=this->fGlobal[from[i]];
414 this->fLocal[this->fGlobal[i]] = i;
416 for(;i<this->fGlobal.NElements();i++) this->fGlobal[i] = -1;
418 if(nfound+this->fFree.NElements()!=this->fFront) cout <<
"TPZFront.Compress inconsistent data structure\n";
420 this->fFront = nfound;
421 this->fFree.Resize(0);
422 this->fGlobal.Resize(this->fFront);
423 if(this->fData.NElements()==0)
return;
425 for(j = 0; j < nfound; j++){
426 for(i = 0; i < nfound; i++){
427 Element(i,j) = Element(from[i], from[j]);
428 if(from[i]!=i || from[j]!=j) Element(from[i],from[j])=0.;
436 int64_t i, loop_limit, aux;
438 for(i=0;i<loop_limit;i++){
439 aux=destinationindex[i];
441 this->fFront = this->fGlobal.NElements();
443 this->fMaxFront=(this->fFront<this->fMaxFront)?this->fMaxFront:this->fFront;
451 for(i=mineq;i<=maxeq;i++) FreeGlobal(i);
462 for (ieq = mineq; ieq <= maxeq; ieq++) {
464 this->DecomposeOneEquation(ieq, eqnarray);
503 for(i=0;i<matsize;i++) {
504 for(j=i;j<matsize;j++) {
506 double rnd = (random*matsize)/0x7fff;
508 TestMatrix(j,i)=TestMatrix(i,j);
509 if(i==j) TestMatrix(i,j)=6000.;
517 Prova.
Print(
"TPZFMatrix<TVar> Cholesky");
523 for(i=0;i<matsize;i++) DestIndex[i]=i;
529 OutFile =
"TPZFrontNonSymTest.txt";
531 ofstream output(OutFile.c_str(),ios::app);
537 TestFront.
AddKel(TestMatrix, DestIndex);
541 ofstream outeqn(
"TestEQNArray.txt",ios::app);
543 Result.
Print(
"TestEQNArray.txt",outeqn);
548 for(i=0;i<matsize;i++) {
550 double rnd = (random*matsize)/0x7fff;
571 return "Non symmetric matrix";
581 int ilocal =
Local(ieq);
586 for(mineq=0; mineq<maxeq; mineq++)
if(this->
fLocal[mineq] != -1)
break;
587 int64_t numeq = maxeq-mineq;
588 front.
Redim(numeq,numeq);
590 for(ieq=mineq;ieq<maxeq;ieq++) {
591 if(this->
fLocal[ieq] == -1)
continue;
592 int64_t il = ieq-mineq;
593 for(jeq=0;jeq<maxeq;jeq++) {
594 if(this->
fLocal[jeq] == -1)
continue;
595 int64_t jl = jeq-mineq;
void AddKel(TPZFMatrix< TVar > &elmat, TPZVec< int64_t > &destinationindex)
Add a contribution of a stiffness matrix.
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ fabs
void EqnForward(TPZFMatrix< TVar > &F, DecomposeType dec)
Forward substitution on equations stored in EqnArray.
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 Expand(int largefrontsize)
Expand the front matrix.
It is an equation array, generally in its decomposed form. Frontal.
TPZVec< int64_t > fLocal
Front equation to each global equation.
TPZFrontNonSym()
Simple constructor.
TPZVec< TVar > * fAuxVecCol
vetores de operacao
TPZVec< TVar > * fAuxVecRow
Contains the TPZFrontNonSym class which implements storage and decomposition process of the frontal m...
virtual void TensorProductIJ(int ithread, typename TPZFront< TVar >::STensorProductMTData *data) override
struct para paralelizar a decomposicao da matriz
int NThreads()
num threads
void Compress()
Compress data structure.
void BeginEquation(int eq)
It starts an equation storage.
Contains the TPZEqnArray class which implements an equation array.
void Print(const char *name, std::ostream &out)
It prints all terms stored in TPZEqnArray.
TPZVec< pz_semaphore_t > fWorkSem
semaforos para sincronizar os threads de calculo
const REAL TOL
Initializing tolerance for current implementations.
void Reset(int64_t GlobalSize=0)
Resets data structure.
Abstract class implements storage and decomposition process of the frontal matrix. Frontal.
void AllocData()
Allocates data for Front.
DecomposeType fDecomposeType
Used Decomposition method.
void DecomposeEquations(int64_t mineq, int64_t maxeq, TPZEqnArray< TVar > &result)
Decompose these equations and put the result in eqnarray. Default decompose method is LU...
void Push(const T object)
Pushes a copy of the object on the stack.
int ClassId() const override
Define the class id associated with the class.
void FreeGlobal(int64_t global)
Sets the global equation as freed, allowing the space used by this equation to be used by future ass...
#define DebugStop()
Returns a message to user put a breakpoint in.
void EqnBackward(TPZFMatrix< TVar > &U, DecomposeType dec)
Backward substitution on equations stored in EqnArray.
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
virtual void ExtractFrontMatrix(TPZFMatrix< TVar > &front) override
Extract the front matrix.
void Reset()
Resets data structure.
void SetNonSymmetric()
Sets EqnArray to a non symmetric form.
void AddTerm(int col, TVar val)
Add a term to the current equation.
~TPZFrontNonSym()
Simple destructor.
int64_t fNextRigidBodyMode
Equation where rigid body modes can be stored.
Full matrix class. Matrix.
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
TVar & Element(int64_t i, int64_t j)
Returns the ith,jth element of the matrix. .
void EndEquation()
Ends the current equation.
void SemaphoreWait(pz_semaphore_t &s)
void SymbolicAddKel(TPZVec< int64_t > &destinationindex)
Add a contribution of a stiffness matrix using the indexes to compute the frontwidth.
void SymbolicDecomposeEquations(int64_t mineq, int64_t maxeq)
Decompose these equations in a symbolic way and store freed indexes in fFree.
virtual int64_t NFree() override
Returns the number of free equations.
virtual void Print(std::ostream &out) const
int64_t NElements() const
Returns the number of elements of the vector.
void DecomposeOneEquation(int64_t ieq, TPZEqnArray< TVar > &eqnarray)
Decomposes ieq equation and add the result to EqnArray.
void Print(const char *name, std::ostream &out) const
It prints TPZFront data.
int Local(int64_t global)
Returns a local index corresponding to a global equation number.
std::string GetMatrixType()
Type of matrix.
void PrintGlobal(const char *name, std::ostream &out)
Abstract class implements storage and decomposition process of the frontal matrix involving non-simet...
virtual int SolveDirect(TPZFMatrix< TVar > &F, const DecomposeType dt, std::list< int64_t > &singular)
Solves the linear system using Direct methods.
DecomposeType
Defines decomposition type for any matrix classes.