NeoPZ
pzstrmatrixst.cpp
Go to the documentation of this file.
1 
6 #include "pzstrmatrixst.h"
7 
8 #include "pzvec.h"
9 #include "pzfmatrix.h"
10 #include "pzmanvector.h"
11 #include "pzadmchunk.h"
12 #include "pzcmesh.h"
13 #include "pzgmesh.h"
14 #include "pzelmat.h"
15 #include "pzcompel.h"
16 #include "pzintel.h"
17 #include "pzsubcmesh.h"
18 #include "pzanalysis.h"
19 #include "pzsfulmat.h"
20 
21 #include "pzgnode.h"
22 #include "TPZTimer.h"
23 #include "TPZThreadTools.h"
24 
25 
26 #include "pzcheckconsistency.h"
27 #include "TPZMaterial.h"
28 #include "run_stats_table.h"
29 
30 using namespace std;
31 
32 #include "pzlog.h"
33 
34 #include "pz_pthread.h"
35 
36 #ifdef LOG4CXX
37 static LoggerPtr logger(Logger::getLogger("pz.strmatrix.TPZStructMatrixST"));
38 static LoggerPtr loggerel(Logger::getLogger("pz.strmatrix.element"));
39 static LoggerPtr loggerel2(Logger::getLogger("pz.strmatrix.elementinterface"));
40 static LoggerPtr loggerelmat(Logger::getLogger("pz.strmatrix.elementmat"));
41 static LoggerPtr loggerCheck(Logger::getLogger("pz.strmatrix.checkconsistency"));
42 #endif
43 
44 #ifdef CHECKCONSISTENCY
45 static TPZCheckConsistency stiffconsist("ElementStiff");
46 #endif
47 
48 
50 
51 }
52 
54 
55 }
56 
58 
59 }
60 
62  cout << "TPZStructMatrixST::Create should never be called\n";
63  return 0;
64 }
65 
67  cout << "TPZStructMatrixST::Clone should never be called\n";
68  return 0;
69 }
70 
71 
72 static RunStatsTable ass_stiff("-ass_stiff", "Assemble Stiffness");
73 static RunStatsTable ass_rhs("-ass_rhs", "Assemble Stiffness");
74 
76  ass_stiff.start();
77  if (fEquationFilter.IsActive()) {
78  int64_t neqcondense = fEquationFilter.NActiveEquations();
79 #ifdef PZDEBUG
80  if (stiffness.Rows() != neqcondense) {
81  DebugStop();
82  }
83 #endif
84  TPZFMatrix<STATE> rhsloc(neqcondense,rhs.Cols(),0.);
85 
86  this->OnlyAssemble(&stiffness, &rhsloc, guiInterface);
87 
88  fEquationFilter.Scatter(rhsloc, rhs);
89  }
90  else
91  {
92  this->OnlyAssemble(&stiffness, &rhs, guiInterface);
93  }
94  ass_stiff.stop();
95 }
96 
98  ass_rhs.start();
100  {
101  int64_t neqcondense = fEquationFilter.NActiveEquations();
102  int64_t neqexpand = fEquationFilter.NEqExpand();
103  if(rhs.Rows() != neqexpand || Norm(rhs) != 0.)
104  {
105  DebugStop();
106  }
107  TPZFMatrix<STATE> rhsloc(neqcondense,1,0.);
108 
109  OnlyAssemble(&rhsloc, guiInterface);
110 
111  fEquationFilter.Scatter(rhsloc,rhs);
112  }
113  else
114  {
115  OnlyAssemble(&rhs, guiInterface);
116  }
117  ass_rhs.stop();
118 }
119 
120 
122 
123 
126 
127 #pragma omp parallel for private(ek, ef) schedule(dynamic, 1)
128  for(int iel=0; iel<fMesh->NElements(); iel++)
129  {
130 
131  TPZCompEl *el = fMesh->ElementVec()[iel];
132 
133  if(el) {
134 
135  if (fGlobMatrix)
136  el->CalcStiff(ek,ef);
137  else
138  el->CalcResidual(ef);
139 
140  if(!el->HasDependency()) {
141 
142  if (fGlobMatrix) {
145  } else {
148  }
149 
150  } else {
151  // the element has dependent nodes
152  if (fGlobMatrix) {
153  ek.ApplyConstraints();
154  ef.ApplyConstraints();
157  } else {
158  ef.ApplyConstraints();
161  }
162 
163  }
164 
165 
166 
167  if(fGlobMatrix) {
168  // assemble the matrix
169  if(!ek.HasDependency()) {
170  fGlobMatrix->AddKel(ek.fMat,ek.fSourceIndex,ek.fDestinationIndex);
171  fGlobRhs->AddFel(ef.fMat,ek.fSourceIndex,ek.fDestinationIndex);
172  } else {
173  fGlobMatrix->AddKel(ek.fConstrMat,ek.fSourceIndex,ek.fDestinationIndex);
174  fGlobRhs->AddFel(ef.fConstrMat,ek.fSourceIndex,ek.fDestinationIndex);
175  }
176  } else {
177  if(!ef.HasDependency()) {
178  fGlobRhs->AddFel(ef.fMat,ef.fSourceIndex,ef.fDestinationIndex);
179  } else {
180  fGlobRhs->AddFel(ef.fConstrMat,ef.fSourceIndex,ef.fDestinationIndex);
181  }
182  }
183 
184 
185  }
186 
187  }
188 
189 }
190 
192  // Checking if the interface still exists
193  if(guiInterface && guiInterface->AmIKilled()){
194  return;
195  }
196  ExecuteAssemble(stiffness, rhs, guiInterface);
197 }
198 
200  // Checking if the interface still exists
201  if(guiInterface && guiInterface->AmIKilled()){
202  return;
203  }
204  ExecuteAssemble(0, rhs, guiInterface);
205 }
206 
208  TPZMatrix<STATE> *stiff = Create();
209  int64_t cols = MAX(1, rhs.Cols());
210  rhs.Redim(fEquationFilter.NEqExpand(),cols);
211  Assemble(*stiff,rhs,guiInterface);
212 #ifdef LOG4CXX2
213  if(loggerel->isDebugEnabled()) {
214  std::stringstream sout;
215  stiff->Print("Stiffness matrix",sout);
216  rhs.Print("Right hand side", sout);
217  LOGPZ_DEBUG(loggerel,sout.str())
218  }
219 #endif
220  return stiff;
221 
222 }
223 
225  return Hash("TPZStructMatrixST") ^ TPZStructMatrixBase::ClassId() << 1;
226 }
227 
228 void TPZStructMatrixST::Read(TPZStream& buf, void* context) {
229  TPZStructMatrixBase::Read(buf,context);
230 }
231 
232 void TPZStructMatrixST::Write(TPZStream& buf, int withclassid) const {
233  TPZStructMatrixBase::Write(buf, withclassid);
234 }
235 
int64_t NElements() const
Number of computational elements allocated.
Definition: pzcmesh.h:169
Contains a class to record running statistics on CSV tables.
Contains TPZAnalysis class which implements the sequence of actions to perform a finite element analy...
void Scatter(const TPZFMatrix< TVar > &vsmall, TPZFMatrix< TVar > &vexpand) const
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.
TPZEquationFilter fEquationFilter
Object which will determine which equations will be assembled.
Timing class. Absolutely copied from GNU time. Take a look at
Contains declaration of TPZGeoNode class which defines a geometrical node.
void AddFel(TPZFMatrix< TVar > &rhs, TPZVec< int64_t > &destination)
Performs a right hand side assemblage.
Definition: pzfmatrix.cpp:209
TPZFNMatrix< 1000, STATE > fMat
Pointer to a blocked matrix object.
Definition: pzelmat.h:41
virtual TPZMatrix< STATE > * CreateAssemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface) override
Contains declaration of TPZCompEl class which defines the interface of a computational element...
Templated vector implementation.
virtual void CalcStiff(TPZElementMatrix &ek, TPZElementMatrix &ef)
Computes the element stifness matrix and right hand side.
Definition: pzcompel.h:794
virtual void FilterEquations(TPZVec< int64_t > &origindex, TPZVec< int64_t > &destindex) const override
Filter out the equations which are out of the range.
TPZCompMesh * fMesh
Pointer to the computational mesh from which the matrix will be generated.
Declarates the TPZBlock<REAL>class which implements block matrices.
#define MAX(a, b)
Gets maxime value between a and b.
Definition: pzreal.h:81
int ClassId() const override
Define the class id associated with the class.
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
It is responsible for a interface among Matrix and Finite Element classes. Structural Matrix...
Definition: pzstrmatrixst.h:30
TPZManVector< int64_t > fDestinationIndex
Definition: pzelmat.h:53
void ComputeDestinationIndices()
Definition: pzelmat.cpp:126
virtual TPZStructMatrixST * Clone() override
Contains declaration of TPZElementMatrix struct which associates an element matrix with the coeficien...
static RunStatsTable ass_rhs("-ass_rhs", "Assemble Stiffness")
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
int64_t NActiveEquations() const
Retorna o numero de equacoes ativas do sistema.
virtual void ExecuteAssemble(TPZMatrix< STATE > *fGlobMatrix, TPZFMatrix< STATE > *fGlobRhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
Definition: pzlog.h:87
Free store vector implementation.
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
virtual void Assemble(TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface) override
Assemble the global system of equations into the matrix which has already been created.
virtual void AddKel(TPZFMatrix< TVar > &elmat, TPZVec< int64_t > &destinationindex)
Add a contribution of a stiffness matrix.
Definition: pzmatrix.cpp:506
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
int64_t NEqExpand() const
Retorna o numero de equacoes do sistema original.
Implements an interface to check the consistency of two implementations. Utility. ...
TPZManVector< int64_t > fSourceIndex
Definition: pzelmat.h:53
Contains declaration of TPZCompMesh class which is a repository for computational elements...
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
Define the class id associated with the class.
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
This class associates an element matrix with the coeficients of its contribution in the global stiffn...
Definition: pzelmat.h:30
TPZFNMatrix< 1000, STATE > fConstrMat
Pointer to the constrained matrix object.
Definition: pzelmat.h:48
void ApplyConstraints()
Apply the constraints applied to the nodes by transforming the tangent matrix and right hand side...
Definition: pzelmat.cpp:186
Contains the TPZStructMatrixST class which responsible for a interface among Matrix and Finite Elemen...
Contains declaration of TPZSubCompMesh class which implements a group of computational elements as a ...
virtual void CalcResidual(TPZElementMatrix &ef)
Computes the element right hand side.
Definition: pzcompel.cpp:610
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
TPZAdmChunkVector< TPZCompEl * > & ElementVec()
Returns a reference to the element pointers vector.
Definition: pzcmesh.h:183
void Read(TPZStream &buf, void *context) override
read objects from the stream
Contains declaration of TPZInterpolatedElement class which implements computational element of the in...
virtual TPZMatrix< STATE > * Create() override
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
static RunStatsTable ass_stiff("-ass_stiff", "Assemble Stiffness")
virtual void OnlyAssemble(TPZMatrix< STATE > *mat, TPZFMatrix< STATE > *rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
Assemble the global system of equations into the matrix which has already been created.
Defines the interface of a computational element. Computational Element.
Definition: pzcompel.h:59
virtual int HasDependency()
Returns 1 if the element has at least one dependent node. Returns 0 otherwise.
Definition: pzcompel.cpp:565
bool HasDependency()
Returns true if the element has at least one dependent node. Returns false otherwise.
Definition: pzelmat.cpp:482
void Read(TPZStream &buf, void *context) override
read objects from the stream
Implements an interface to register a class id and a restore function. Persistence.
Definition: TPZSavable.h:150
Contains TPZSFMatrix class which implements a symmetric full matrix.