NeoPZ
pzelementgroup.cpp
Go to the documentation of this file.
1 
6 #include "pzelementgroup.h"
7 #include "pzlog.h"
8 #include "pzstepsolver.h"
9 #include "pzcmesh.h"
10 
11 #ifdef LOG4CXX
12 static LoggerPtr logger(Logger::getLogger("pz.mesh.tpzelementgroup"));
13 #endif
14 
17 TPZCompEl(), fElGroup(), fConnectIndexes()
18 {
19 }
20 
21 
23 {
24  if (fElGroup.size()) {
25  DebugStop();
26  }
27 }
28 
31 TPZCompEl(mesh, copy)
32 {
34  int nel = copy.fElGroup.size();
35  for (int el=0; el<nel; el++) {
36  newel.Push(copy.fElGroup[el]->Clone(mesh) );
37  }
38  for (int el=0; el<nel; el++) {
39  AddElement(newel[el]);
40  }
41 }
42 
46 {
47  fElGroup.Push(cel);
48  std::set<int64_t> connects;
49  int nc = fConnectIndexes.size();
50  for (int ic=0; ic<nc; ic++) {
51  connects.insert(fConnectIndexes[ic]);
52  }
53  nc = cel->NConnects();
54  for (int ic=0; ic<nc; ic++) {
55  connects.insert(cel->ConnectIndex(ic));
56  }
57  nc = connects.size();
58  if (nc != fConnectIndexes.size()) {
59  fConnectIndexes.Resize(nc, 0);
60  std::set<int64_t>::iterator it = connects.begin();
61  for (int ic = 0; it != connects.end(); it++,ic++) {
62  fConnectIndexes[ic] = *it;
63  }
64  }
65  int64_t elindex = cel->Index();
66  Mesh()->ElementVec()[elindex] = 0;
67  std::list<TPZOneShapeRestraint> ellist = cel->GetShapeRestraints();
68  for (std::list<TPZOneShapeRestraint>::iterator it=ellist.begin(); it != ellist.end(); it++) {
69  int64_t cindex = it->fFaces[0].first;
70  fRestraints[cindex] = *it;
71  }
72 #ifdef LOG4CXX2
73  if (logger->isDebugEnabled())
74  {
75  std::stringstream sout;
76  sout << "Hiding element index " << elindex << " from the mesh data structure";
77  LOGPZ_DEBUG(logger, sout.str())
78  }
79 #endif
80 
81 }
82 
85 {
86  int nel = fElGroup.size();
87  for (int el=0; el<nel; el++) {
88  int64_t elindex = fElGroup[el]->Index();
89  Mesh()->ElementVec()[elindex] = fElGroup[el];
90  }
91  fElGroup.Resize(0);
93  delete this;
94 }
95 
101 void TPZElementGroup::SetConnectIndex(int inode, int64_t index)
102 {
103  LOGPZ_ERROR(logger,"SetConnectIndex should never be called")
104  DebugStop();
105 }
106 
119  std::map<int64_t,int64_t> & gl2lcConMap,
120  std::map<int64_t,int64_t> & gl2lcElMap) const
121 {
122  int64_t index;
123  TPZElementGroup *result = new TPZElementGroup(mesh,index);
124  int nel = fElGroup.size();
125  for (int el=0; el<nel; el++) {
126  TPZCompEl *cel = fElGroup[el]->ClonePatchEl(mesh,gl2lcConMap,gl2lcElMap);
127  result->AddElement(cel);
128  }
129  return result;
130 }
131 
134  int64_t rows = ek.fMat.Rows();
135  ek.fMat.Redim(rows, rows);
138  std::map<int64_t,TPZOneShapeRestraint>::const_iterator it;
139  for (it = fRestraints.begin(); it != fRestraints.end(); it++) {
140  ek.fOneRestraints.push_back(it->second);
141  ef.fOneRestraints.push_back(it->second);
142  }
143 }//void
144 
146  const int ncon = this->NConnects();
147  int numeq = 0;
148  ef.fBlock.SetNBlocks(ncon);
149  for (int ic=0; ic<ncon; ic++) {
150  TPZConnect &c = Connect(ic);
151  int blsize = c.NShape()*c.NState();
152  numeq += blsize;
153  ef.fBlock.Set(ic, blsize);
154  }
155  const int numloadcases = 1;
156  ef.fMesh = Mesh();
158  ef.fMat.Redim(numeq,numloadcases);
159  ef.fConnect.Resize(ncon);
160  for(int i=0; i<ncon; i++){
161  (ef.fConnect)[i] = ConnectIndex(i);
162  }
163  std::map<int64_t,TPZOneShapeRestraint>::const_iterator it;
164  for (it = fRestraints.begin(); it != fRestraints.end(); it++) {
165  ef.fOneRestraints.push_back(it->second);
166  }
167 }//void
168 
169 
176 {
177  std::map<int64_t,int64_t> locindex;
178  int64_t ncon = fConnectIndexes.size();
179  for (int64_t ic=0; ic<ncon ; ic++) {
180  locindex[fConnectIndexes[ic]] = ic;
181  }
182 #ifdef LOG4CXX
183  if(logger->isDebugEnabled())
184  {
185  std::stringstream sout;
186  sout << "Calcstiff Element Group Index " << Index();
187  LOGPZ_DEBUG(logger, sout.str())
188  }
189 #endif
190  InitializeElementMatrix(ek, ef);
191  int64_t nel = fElGroup.size();
192  TPZElementMatrix ekloc,efloc;
193  for (int64_t el = 0; el<nel; el++) {
194  TPZCompEl *cel = fElGroup[el];
195 
196 #ifdef PZDEBUG
197  if(!cel){
198  DebugStop();
199  }
200 #endif
201 
202  cel->CalcStiff(ekloc, efloc);
203 #ifdef LOG4CXX
204  if (logger->isDebugEnabled() ) {
205  TPZGeoEl *gel = cel->Reference();
206 
207  int matid = 0;
208  if(gel) matid = gel->MaterialId();
209  std::stringstream sout;
210  if (gel) {
211  sout << "Material id " << matid <<std::endl;
212  }
213  else
214  {
215  sout << "No associated geometry\n";
216  }
217  sout << "Connect indexes ";
218  for (int i=0; i<cel->NConnects(); i++) {
219  sout << cel->ConnectIndex(i) << " ";
220  }
221  efloc.Print(sout);
222  sout << std::endl;
223  sout << "Local indexes ";
224  for (int i=0; i<cel->NConnects(); i++) {
225  sout << locindex[cel->ConnectIndex(i)] << " ";
226  }
227  sout << std::endl;
228  ekloc.fMat.Print("EKElement =",sout,EMathematicaInput);
229 // ekloc.fBlock.Print("EKBlock =",sout,&ekloc.fMat);
230  efloc.fMat.Print("Vetor de carga",sout);
231  LOGPZ_DEBUG(logger, sout.str())
232  }
233 
234 #endif
235  int nelcon = ekloc.NConnects();
236  for (int ic=0; ic<nelcon; ic++) {
237  int iblsize = ekloc.fBlock.Size(ic);
238  int icindex = ekloc.fConnect[ic];
239  int ibldest = locindex[icindex];
240  for (int idf = 0; idf<iblsize; idf++) {
241  ef.fBlock(ibldest,0,idf,0) += efloc.fBlock(ic,0,idf,0);
242  }
243  for (int jc = 0; jc<nelcon; jc++) {
244  int jblsize = ekloc.fBlock.Size(jc);
245  int jcindex = ekloc.fConnect[jc];
246  int jbldest = locindex[jcindex];
247  for (int idf = 0; idf<iblsize; idf++) {
248  for (int jdf=0; jdf<jblsize; jdf++) {
249  ek.fBlock(ibldest,jbldest,idf,jdf) += ekloc.fBlock(ic,jc,idf,jdf);
250  }
251  }
252  }
253 
254  }
255 #ifdef LOG4CXX2
256  if (logger->isDebugEnabled()) {
257  std::stringstream sout;
258  sout << "Connect indices " << fConnectIndexes << std::endl;
259  ek.fBlock.Print("EKBlockAssembled = ",sout,&ek.fMat);
260  ek.fMat.Print("EKAssembled = ",sout,EMathematicaInput);
261  LOGPZ_DEBUG(logger, sout.str())
262  }
263 #endif
264  }
265 }
266 
268 bool TPZElementGroup::HasMaterial(const std::set<int> &materialids) const {
269 
270  int64_t nel = fElGroup.size();
271  TPZElementMatrix efloc;
272  for (int64_t el = 0; el<nel; el++) {
273  TPZCompEl *cel = fElGroup[el];
274 #ifdef PZDEBUG
275  if(!cel){
276  DebugStop();
277  }
278 #endif
279  bool has_material_Q = cel->HasMaterial(materialids);
280  if (has_material_Q) {
281  return true;
282  }
283  }
284  return false;
285 }
286 
287 
293 {
294  std::map<int64_t,int64_t> locindex;
295  int64_t ncon = fConnectIndexes.size();
296  for (int64_t ic=0; ic<ncon ; ic++) {
297  locindex[fConnectIndexes[ic]] = ic;
298  }
300  int64_t nel = fElGroup.size();
301  TPZElementMatrix efloc;
302  for (int64_t el = 0; el<nel; el++) {
303  TPZCompEl *cel = fElGroup[el];
304 #ifdef PZDEBUG
305  if(!cel){
306  DebugStop();
307  }
308 #endif
309  cel->CalcResidual(efloc);
310  int nelcon = efloc.NConnects();
311  for (int ic=0; ic<nelcon; ic++) {
312  int iblsize = efloc.fBlock.Size(ic);
313  int icindex = efloc.fConnect[ic];
314  int ibldest = locindex[icindex];
315  for (int idf = 0; idf<iblsize; idf++) {
316  ef.fBlock(ibldest,0,idf,0) += efloc.fBlock(ic,0,idf,0);
317  }
318  }
319  }
320 }
321 
328 void TPZElementGroup::EvaluateError(std::function<void(const TPZVec<REAL> &loc,TPZVec<STATE> &val,TPZFMatrix<STATE> &deriv)> fp,
329  TPZVec<REAL> &errors, bool store_error)
330 {
331  int nerr = errors.size();
332  errors.Fill(0.);
333  int meshdim = Mesh()->Dimension();
334  int nel = fElGroup.size();
335  for (int el=0; el<nel; el++) {
336  TPZManVector<REAL,10> errloc(nerr,0.);
337  TPZGeoEl *elref = fElGroup[el]->Reference();
338  if (elref && elref->Dimension() != meshdim) {
339  continue;
340  }
341  fElGroup[el]->EvaluateError(fp, errloc, store_error);
342  if (errloc.size() != nerr) {
343  nerr = errloc.size();
344  errors.Resize(nerr, 0.);
345  }
346  for (int i=0; i<errloc.size(); i++) {
347  errors[i] += errloc[i]*errloc[i];
348  }
349  }
350  for (int i=0; i<errors.size(); i++) {
351  errors[i] = sqrt(errors[i]);
352  }
353 }
354 
356  return Hash("TPZElementGroup") ^ TPZCompEl::ClassId() << 1;
357 }
358 
360 bool TPZElementGroup::NeedsComputing(const std::set<int> &matids)
361 {
362  bool result = false;
363  for (int el=0; el<fElGroup.size(); el++) {
364  result = fElGroup[el]->NeedsComputing(matids);
365  if (result == true) {
366  return result;
367  }
368  }
369  return result;
370 }
371 
int Set(const int index, const int dim, const int pos=-1)
Modifies existing block dimensions or creates a new block with given index.
Definition: pzblock.cpp:104
Represents a set of shape functions associated with a computational element/side. Computational Eleme...
Definition: pzconnect.h:30
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.
virtual int64_t ConnectIndex(int i) const override
Returns the index of the ith connectivity of the element.
int MaterialId() const
Returns the material index of the element.
Definition: pzgeoel.h:250
void Unwrap()
put the elements in the element group back in the mesh and delete the element group ...
TPZStack< TPZCompEl *, 5 > fElGroup
virtual int NConnects() const override
Returns the number of nodes of the element.
virtual void EvaluateError(std::function< void(const TPZVec< REAL > &loc, TPZVec< STATE > &val, TPZFMatrix< STATE > &deriv)> func, TPZVec< REAL > &errors, bool store_error) override
Performs an error estimate on the elemen.
TPZStack< int64_t > fConnect
Vector of pointers to TPZConnect objects.
Definition: pzelmat.h:39
TPZManVector< int64_t, 27 > fConnectIndexes
TPZFNMatrix< 1000, STATE > fMat
Pointer to a blocked matrix object.
Definition: pzelmat.h:41
virtual void CalcResidual(TPZElementMatrix &ef) override
Computes the element right hand side.
Contains the declaration of the TPZElementGroup class, which implements an computational element whic...
std::list< TPZOneShapeRestraint > fOneRestraints
list of one degree of freedom restraints
Definition: pzelmat.h:56
virtual void CalcStiff(TPZElementMatrix &ek, TPZElementMatrix &ef)
Computes the element stifness matrix and right hand side.
Definition: pzcompel.h:794
Class which groups elements to characterize dense matrices.
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
TPZBlock< STATE > fBlock
Block structure associated with fMat.
Definition: pzelmat.h:43
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
virtual ~TPZElementGroup()
virtual int ClassId() const override
Define the class id associated with the class.
Definition: pzcompel.cpp:1129
void Print(std::ostream &out)
Definition: pzelmat.cpp:47
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
Definition: pzvec.h:373
void Push(const T object)
Pushes a copy of the object on the stack.
Definition: pzstack.h:80
int NConnects()
Returns the number of nodes of TElementMatrix.
Definition: pzelmat.h:87
virtual TPZCompEl * ClonePatchEl(TPZCompMesh &mesh, std::map< int64_t, int64_t > &gl2lcConMap, std::map< int64_t, int64_t > &gl2lcElMap) const override
Method for creating a copy of the element in a patch mesh.
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
virtual bool HasMaterial(const std::set< int > &materialids) const
Verifies if the material associated with the element is contained in the set.
Definition: pzcompel.cpp:968
#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
TPZCompMesh * Mesh() const
Return a pointer to the grid of the element.
Definition: pzcompel.cpp:288
int Dimension() const
Returns the dimension of the simulation.
Definition: pzcmesh.h:148
unsigned int NShape() const
Definition: pzconnect.h:151
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
Definition: tfadfunc.h:120
TPZCompMesh * fMesh
Definition: pzelmat.h:36
int64_t Index() const
Returns element index of the mesh fELementVec list.
Definition: pzcompel.h:821
#define LOGPZ_ERROR(A, B)
Define log for errors (cout)
Definition: pzlog.h:93
int SetNBlocks(const int num_of_blocks)
Sets number of blocks on diagonal matrix.
Definition: pzblock.cpp:91
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
virtual TPZConnect & Connect(int i) const
Returns a pointer to the ith node.
Definition: pzcompel.cpp:298
unsigned char NState() const
Number of state variables associated with the connect.
Definition: pzconnect.h:146
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
virtual int64_t ConnectIndex(int i) const =0
Returns the index of the ith connectivity of the element.
This class associates an element matrix with the coeficients of its contribution in the global stiffn...
Definition: pzelmat.h:30
virtual void SetConnectIndex(int inode, int64_t index) override
Set the index i to node inode.
virtual int NConnects() const =0
Returns the number of nodes of the element.
virtual void CalcStiff(TPZElementMatrix &ek, TPZElementMatrix &ef) override
Computes the element stifness matrix and right hand side.
virtual std::list< TPZOneShapeRestraint > GetShapeRestraints() const
Return a list with the shape restraints.
Definition: pzcompel.h:432
static int idf[6]
virtual int Dimension() const =0
Returns the dimension of the element.
virtual void CalcResidual(TPZElementMatrix &ef)
Computes the element right hand side.
Definition: pzcompel.cpp:610
TPZGeoEl * Reference() const
Return a pointer to the corresponding geometric element if such exists, return 0 otherwise.
Definition: pzcompel.cpp:1137
This class implements a stack object. Utility.
Definition: pzcheckmesh.h:14
virtual int ClassId() const override
Define the class id associated with the class.
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
int Size(const int block_diagonal) const
Returns block dimension.
Definition: pzblock.h:171
TPZAdmChunkVector< TPZCompEl * > & ElementVec()
Returns a reference to the element pointers vector.
Definition: pzcmesh.h:183
void Fill(const T &copy, const int64_t from=0, const int64_t numelem=-1)
Will fill the elements of the vector with a copy object.
Definition: pzvec.h:460
Contains TPZStepSolver class which defines step solvers class.
void InitializeElementMatrix(TPZElementMatrix &ek, TPZElementMatrix &ef) const
Initialize the datastructure of ek and ef based on the connect information.
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
void Print(const char *title="", TPZostream &out=std::cout, TPZMatrix< TVar > *mat=NULL)
Prints all the blocks of the matrix.
Definition: pzblock.cpp:424
Defines the interface of a computational element. Computational Element.
Definition: pzcompel.h:59
virtual void AddElement(TPZCompEl *cel)
add an element to the element group
bool NeedsComputing(const std::set< int > &matids) override
Verifies if any element needs to be computed corresponding to the material ids.
virtual bool HasMaterial(const std::set< int > &materialids) const override
Verifies if the material associated with the element is contained in the set.
std::map< int64_t, TPZOneShapeRestraint > fRestraints