NeoPZ
TPZStructMatrixBase.cpp
Go to the documentation of this file.
1 #include "TPZStructMatrixBase.h"
2 
3 #include "pzcmesh.h"
4 #include "pzcheckmesh.h"
5 #include "pzerror.h"
6 #include "pzsubcmesh.h"
7 #include "pzanalysis.h"
8 #include "TPZThreadPool.h"
9 
10 #ifdef LOG4CXX
11 #include "pzlog.h"
12 static LoggerPtr logger(Logger::getLogger("pz.strmatrix.TPZStructMatrixOR"));
13 static LoggerPtr loggerel(Logger::getLogger("pz.strmatrix.element"));
14 static LoggerPtr loggerel2(Logger::getLogger("pz.strmatrix.elementinterface"));
15 static LoggerPtr loggerelmat(Logger::getLogger("pz.strmatrix.elementmat"));
16 static LoggerPtr loggerCheck(Logger::getLogger("pz.strmatrix.checkconsistency"));
17 static LoggerPtr loggerGlobStiff(Logger::getLogger("pz.strmatrix.globalstiffness"));
18 #endif
19 
20 TPZStructMatrixBase::TPZStructMatrixBase() : fMesh(NULL), fEquationFilter(0) {
21  this->SetNumThreads(TPZThreadPool::globalInstance().threadCount());
22 }
23 
25  : fEquationFilter(0) {
26  SetMesh(mesh);
27  this->SetNumThreads(TPZThreadPool::globalInstance().threadCount());
28 }
29 
31  : fEquationFilter(0) {
32  SetMesh(mesh);
33  this->SetNumThreads(TPZThreadPool::globalInstance().threadCount());
34 }
35 
37  : fMesh(copy.fMesh), fCompMesh(copy.fCompMesh),
39  fNumThreads(copy.fNumThreads) {
40 }
41 
43  fMesh = mesh;
44  fEquationFilter.SetNumEq(mesh ? mesh->NEquations() : 0);
45 #ifdef PZDEBUG
46  if (mesh) {
47  TPZCheckMesh checkmesh(fMesh, &std::cout);
48  if (checkmesh.CheckConnectSeqNumberConsistency() != 0) {
49  DebugStop();
50  }
51  }
52 #endif
53 }
54 
56  fCompMesh = mesh;
57  SetMesh(mesh.operator->());
58 }
59 
62  TPZMatrix<STATE> *stiff = Create();
63 
64  int64_t cols = MAX(1, rhs.Cols());
65  rhs.Redim(fEquationFilter.NEqExpand(), cols);
66  Assemble(*stiff, rhs, guiInterface);
67 
68 #ifdef LOG4CXX2
69  if (loggerel->isDebugEnabled()) {
70  std::stringstream sout;
71  stiff->Print("Stiffness matrix", sout);
72  rhs.Print("Right hand side", sout);
73  LOGPZ_DEBUG(loggerel, sout.str())
74  }
75 #endif
76  return stiff;
77 }
78 
80 {
81  //destindex = origindex;
82  fEquationFilter.Filter(origindex, destindex);
83 
84 }
85 
86 void TPZStructMatrixBase::SetMaterialIds(const std::set<int> &materialids)
87 {
88  fMaterialIds = materialids;
89 #ifdef LOG4CXX
90  if (logger->isDebugEnabled())
91  {
92  std::set<int>::const_iterator it;
93  std::stringstream sout;
94  sout << "setting input material ids ";
95  for(it=materialids.begin(); it!= materialids.end(); it++)
96  {
97  sout << *it << " ";
98  }
99  LOGPZ_DEBUG(logger,sout.str())
100  }
101 #endif
102  if(!fMesh)
103  {
104  LOGPZ_WARN(logger,"SetMaterialIds called without mesh")
105  return;
106  }
107  int64_t iel;
109  int64_t nel = elvec.NElements();
110  for(iel=0; iel<nel; iel++)
111  {
112  TPZCompEl *cel = elvec[iel];
113  if(!cel) continue;
114  TPZSubCompMesh *subcmesh = dynamic_cast<TPZSubCompMesh *> (cel);
115  if(!subcmesh) continue;
116  TPZAutoPointer<TPZAnalysis> analysis = subcmesh->Analysis();
117  if(!analysis)
118  {
119  LOGPZ_ERROR(logger,"SetMaterialIds called for substructure without analysis object")
120  DebugStop();
121  }
122  TPZStructMatrixBase *str = analysis->StructMatrix().operator->();
123  if(!str)
124  {
125  LOGPZ_WARN(logger,"SetMaterialIds called for substructure without structural matrix")
126  continue;
127  }
128  str->SetMaterialIds(materialids);
129  }
130 }
131 
133  return Hash("TPZStructMatrixBase");
134 }
135 
136 void TPZStructMatrixBase::Read(TPZStream& buf, void* context) {
137  fMesh = dynamic_cast<TPZCompMesh *>(TPZPersistenceManager::GetInstance(&buf));
138  fCompMesh = TPZAutoPointerDynamicCast<TPZCompMesh>(TPZPersistenceManager::GetAutoPointer(&buf));
139  fEquationFilter.Read(buf,context);
140  buf.Read(fMaterialIds);
141  buf.Read(&fNumThreads);
142 }
143 
144 void TPZStructMatrixBase::Write(TPZStream& buf, int withclassid) const {
146  TPZPersistenceManager::WritePointer(fCompMesh.operator ->(), &buf);
147  fEquationFilter.Write(buf,withclassid);
148  buf.Write(fMaterialIds);
149  buf.Write(&fNumThreads);
150 }
int fNumThreads
Number of threads in Assemble process.
virtual TPZMatrix< STATE > * CreateAssemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
int CheckConnectSeqNumberConsistency()
This method verifies if the sequence numbers of dependent connects and/or condensed connect are order...
virtual void SetMesh(TPZCompMesh *)
Contains TPZAnalysis class which implements the sequence of actions to perform a finite element analy...
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.
int64_t NEquations()
This computes the number of equations associated with non-restrained nodes.
Definition: pzcmesh.cpp:721
void Filter(TPZVec< int64_t > &orig, TPZVec< int64_t > &dest) const
Defines PZError.
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
TPZEquationFilter fEquationFilter
Object which will determine which equations will be assembled.
static TPZThreadPool & globalInstance()
int64_t NElements() const
Access method to query the number of elements of the vector.
Implements a chunk vector with free store administration. Utility.
Definition: TPZStream.h:39
#define LOGPZ_WARN(A, B)
Define log for warnings.
Definition: pzlog.h:91
#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.
static TPZSavable * GetInstance(const int64_t &objId)
void SetNumEq(const int64_t numEq)
virtual void Assemble(TPZMatrix< STATE > &stiffness, TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)=0
TPZCompMesh * fMesh
Pointer to the computational mesh from which the matrix will be generated.
TPZAutoPointer< TPZStructMatrix > StructMatrix()
Returns a reference to the structural matrix.
Definition: pzanalysis.h:182
static TPZAutoPointer< TPZSavable > GetAutoPointer(const int64_t &objId)
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
Implements a group of computational elements as a mesh and an element. Computational Mesh...
Definition: pzsubcmesh.h:36
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
virtual void SetNumThreads(int n)
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
Definition: pzlog.h:87
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.
Contains declaration of TPZCheckMesh class which verifies the consistency of the datastructure of a T...
std::set< int > fMaterialIds
Set of material ids to be considered. It is a private attribute.
#define LOGPZ_ERROR(A, B)
Define log for errors (cout)
Definition: pzlog.h:93
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
TPZAutoPointer< TPZAnalysis > Analysis()
Definition: pzsubcmesh.h:123
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
Contains declaration of TPZSubCompMesh class which implements a group of computational elements as a ...
virtual TPZMatrix< STATE > * Create()=0
virtual void SetMaterialIds(const std::set< int > &materialids)
Set the set of material ids which will be considered when assembling the system.
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
TPZAdmChunkVector< TPZCompEl * > & ElementVec()
Returns a reference to the element pointers vector.
Definition: pzcmesh.h:183
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
virtual void FilterEquations(TPZVec< int64_t > &origindex, TPZVec< int64_t > &destindex) const
Filter out the equations which are out of the range.
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
void Read(TPZStream &buf, void *context) override
read objects from the stream
Defines the interface of a computational element. Computational Element.
Definition: pzcompel.h:59
static void WritePointer(const TPZSavable *obj, TPZStream *stream)
void Read(TPZStream &buf, void *context) override
read objects from the stream
TPZAutoPointer< TPZCompMesh > fCompMesh
Autopointer control of the computational mesh.
virtual void Read(bool &val)
Definition: TPZStream.cpp:91
This class verifies the consistency of the datastructure of a TPZCompMesh object. Computational Mesh...
Definition: pzcheckmesh.h:20