NeoPZ
pzcheckmesh.cpp
Go to the documentation of this file.
1 
6 #include "pzcheckmesh.h"
7 #include "pzgeoelside.h"
8 #include "pzstack.h"
9 #include "pzintel.h"
10 #include "TPZMaterial.h"
11 
12 using namespace std;
13 
14 TPZCheckMesh::TPZCheckMesh(TPZCompMesh *mesh, std::ostream *out) {
15  fMesh = mesh;
16  fOut = out;
17  fNState = 1;
18 }
19 
20 void TPZCheckMesh::BuildDependList(int connect, TPZStack<int> &dependlist) {
21  int nconnects = fMesh->ConnectVec().NElements();
22  int ic;
23  for(ic=0; ic<nconnects; ic++) {
24  TPZConnect::TPZDepend *dep = fMesh->ConnectVec()[ic].FirstDepend();
25  if(dep && dep->HasDepend(connect)) {
26  dependlist.Push(ic);
27  continue;
28  }
29  }
30 }
31 
33  int nelem = fMesh->ElementVec().NElements();
34  int el;
35  for(el=0; el<nelem; el++) {
36  TPZCompEl *cel = fMesh->ElementVec()[el];
37  if(!cel) continue;
38  TPZInterpolatedElement *intel = dynamic_cast<TPZInterpolatedElement *>(cel);
39  TPZGeoEl *gel = cel->Reference();
40  int ns = gel->NSides();
41 
42  for(int side=0; side<ns; side++) {
43  int nsc = intel->NSideConnects(side);
44  for (int ic=0; ic<nsc; ic++)
45  {
46  int64_t index = intel->SideConnectIndex(ic, side);
47  if(index == connect) {
48  return TPZCompElSide(cel,side);
49  }
50  }
51  }
52  }
53  TPZCompElSide nullside;
54  return nullside;
55 }
56 
58  int check = 1;
59  TPZConnect &df = fMesh->ConnectVec()[connect];
60  if(df.HasDependency() || df.IsCondensed() || !df.NElConnected() || df.SequenceNumber() == -1) return check;
61  int dofsize = df.NShape()*df.NState();
62  // check the consistency between the block size and the data structure of the connect
63  {
64  int seqnum = df.SequenceNumber();
65  int blsize = fMesh->Block().Size(seqnum);
66  if (blsize != dofsize) {
67  check = 0;
68  }
69  }
70  return check;
71 }
72 
73 int TPZCheckMesh::VerifyConnect(int connect) {
74 
75  int check = 1;
76 
77  {
78  TPZCompElSide elcon = FindElement(connect);
79  TPZConnect &c = fMesh->ConnectVec()[connect];
80  TPZCompElSide large = elcon.LowerLevelElementList(1);
81  if (c.HasDependency() && !large) {
82  *fOut << "Connect " << connect << " has dependency but no large element\n";
83  check = 0;
84  }
85  if(c.NShape() && !c.HasDependency() && large)
86  {
87  *fOut << "Connect " << connect << " has no dependency but has large element\n";
88  check = 0;
89  }
90  }
91  TPZStack<int> deplist;
92  BuildDependList(connect,deplist);
93  int ndep = deplist.NElements();
94  int id;
95  for(id=0; id<ndep; id++) {
96  TPZCompElSide smalll = FindElement(deplist[id]);
97  TPZCompElSide large = smalll.LowerLevelElementList(1);
98  if(!large.Exists()) {
99  check = 0;
100  (*fOut) << "VerifyConnect of connect " << connect << std::endl;
101  (*fOut) << "deplist = " << deplist << " deplist[id] = " << deplist[id] << std::endl;
102  (*fOut) << "Connect index of connect which is restrained deplist[id] = " << deplist[id] << std::endl;
103  TPZConnect &c = fMesh->ConnectVec()[deplist[id]];
104  c.Print(*fMesh,(*fOut));
105  (*fOut) << "Element/side which contains deplist[id] side = " << smalll.Side() << "\n";
106  smalll.Element()->Print(*fOut);
107  (*fOut) << "VerifyConnect of " << connect << " inconsistent\n";
108  continue;
109  }
110  TPZCompEl *cel = large.Element();
111  int ncl = cel->NConnects();
112  int icl;
113  for(icl=0; icl<ncl; icl++) {
114  if(cel->ConnectIndex(icl) == connect) break;
115  }
116  if(icl == ncl) {
117  check = 0;
118  (*fOut) << "VerifyConnect of " << connect << " inconsistent\n";
119  }
120  }
121  return check;
122 }
123 
125 
126  (*fOut) << "DependencyReport for connect " << connect << endl;
127  TPZCompElSide large = FindElement(connect);
128  DependencyReport(connect, large);
129 }
130 
131 void TPZCheckMesh::DependencyReport(int connect, TPZCompElSide & large) {
132 
134  large.HigherLevelElementList(smalll,1,1);
135  int nsmall = smalll.NElements();
136  int is;
137  for(is=0; is<nsmall; is++) {
138  int conind = smalll[is].Element()->ConnectIndex(smalll[is].Side());
139  (*fOut) << "Connect " << conind << " may depend on " << connect << endl;
140  }
141  if(large.Reference().Dimension() == 1) {
143  large.EqualLevelElementList(equal,1,0);
144  equal.Push(large);
145  TPZStack<TPZCompElSide> highdim;
146  int neq = equal.NElements();
147  int eq;
148  for(eq=0; eq<neq; eq++) equal[eq].HigherDimensionElementList(highdim,1,0);
149  large.HigherDimensionElementList(highdim,1,0);
150  int nhigh = highdim.NElements();
151  int ih;
152  for(ih=0; ih<nhigh; ih++) {
153  DependencyReport(connect,highdim[ih]);
154  }
155  }
156 }
157 
159  int ncon = fMesh->NConnects();
160  int i;
161  int check = 1;
162  for (i=0; i<ncon; i++){
163  //(*fOut) << "Startint to check consistency for connect " << i << endl;
164  if (!VerifyConnect(i) || !VerifyCompatibilityBetweenNShapesAndBlockSize(i)) {
165  check = 0;
166  (*fOut) << "Check failed for connect: " << i << endl;
167  }
168  }
169  return check;
170 }
171 
173  int check = 0;
174  check = CheckElementShapeDimension();
175  int check2 = CheckConstraintDimension();
176  return (check || check2);
177 }
178 
180  int check = 0;
181  int nelem = fMesh->ElementVec().NElements();
182  int el;
183  for(el=0; el<nelem; el++) {
184  TPZCompEl *cel = fMesh->ElementVec()[el];
185  if(!cel) continue;
186  TPZInterpolatedElement *cint = dynamic_cast<TPZInterpolatedElement *> (cel);
187  if(!cint) continue;
188  int nc = cint->NConnects();
189  int ic;
190  for(ic=0; ic<nc; ic++) {
191  int cind = cint->ConnectIndex(ic);
192  TPZConnect &c = cint->Connect(ic);
193  int nshape = cint->NConnectShapeF(ic,c.Order());
194  if (c.NShape() != nshape) {
195  cout << "TPZCheckMesh::CheckElement.. el = " << el << " connect = "
196  << cind << " nshape = " << nshape << " c.NShape " << c.NShape() << endl;
197  check =1 ;
198  }
199  fNState = 1;
200  int seqnum = fMesh->ConnectVec()[cind].SequenceNumber();
201  int blsize = fMesh->Block().Size(seqnum);
202  if(nshape*fNState != blsize) {
203  cout << "TPZCheckMesh::CheckElement.. el = " << el << " connect = "
204  << cind << " nshape = " << nshape << " blsize " << blsize << endl;
205  cint->Print(cout);
206  check = 1;
207  }
208  }
209  }
210  return check;
211 }
212 
214 {
215  int check = 0;
216  int ncon = fMesh->ConnectVec().NElements();
217  std::set<int64_t> badcon;
218  for(int64_t ic=0; ic<ncon; ic++) {
219  TPZConnect &con = fMesh->ConnectVec()[ic];
220  int iseqnum = con.SequenceNumber();
221  if (iseqnum < 0) {
222  continue;
223  }
224  int iblsize = fMesh->Block().Size(iseqnum);
225  if(con.HasDependency()) {
226  TPZConnect::TPZDepend *dep = con.FirstDepend();
227  while(dep) {
228  int r = dep->fDepMatrix.Rows();
229  int c = dep->fDepMatrix.Cols();
230  int jcind = dep->fDepConnectIndex;
231  TPZConnect &jcon = fMesh->ConnectVec()[jcind];
232  int jseqnum = jcon.SequenceNumber();
233  int jblsize = fMesh->Block().Size(jseqnum);
234  if(r*fNState != iblsize || c*fNState != jblsize) {
235  badcon.insert(ic);
236  cout << "TPZCheckMesh::CheckConstraintDi.. ic = " << ic
237  << " depends on " << jcind << " r " << r << " iblsize "
238  << iblsize << " c " << c << " jblsize " << jblsize << endl;
239  check = 1;
240  }
241  dep = dep->fNext;
242  }
243  }
244  }
245  TPZVec<int64_t> connecttoel(fMesh->NConnects(),-1);
246  int64_t nelem = fMesh->NElements();
247  for (int64_t el=0; el<nelem; el++) {
248  TPZCompEl *cel = fMesh->Element(el);
249  if (!cel) {
250  continue;
251  }
252  int nc = cel->NConnects();
253  for (int ic=0; ic<nc; ic++) {
254  int64_t cindex = cel->ConnectIndex(ic);
255  if (connecttoel[cindex] == -1) {
256  connecttoel[cindex] = el;
257  }
258  }
259  }
260  std::set<int64_t> badelements;
261  for (std::set<int64_t>::iterator it = badcon.begin(); it != badcon.end(); it++) {
263  if (connecttoel[*it] == -1) {
264  std::cout << "Connect " << *it << " has dependency but does not belong to an element\n";
265  }
266  TPZCompEl *cel = fMesh->Element(connecttoel[*it]);
267  TPZInterpolatedElement *intel = dynamic_cast<TPZInterpolatedElement *>(cel);
268  if (!intel) {
269  std::cout << "I dont understand\n";
270  continue;
271  }
272  int nc = intel->NConnects();
273  for (int ic = 0; ic<nc; ic++) {
274  if (intel->ConnectIndex(ic) == *it)
275  {
276  TPZGeoEl *ref = intel->Reference();
277  TPZGeoElSide gelside(ref,ic);
278  TPZCompElSide large = gelside.LowerLevelCompElementList2(1);
279  if (!large) {
280  std::cout << "I dont understand\n";
281  continue;
282  }
283  TPZGeoElSide gellarge = large.Reference();
285  gellarge.EqualLevelCompElementList(equal, 1, 0);
286  equal.Push(large);
287  std::cout << "Connect index " << *it << " belongs to element " << connecttoel[*it] << " and is restrained by element ";
288  for(int i=0; i< equal.size(); i++) std::cout << equal[i].Element()->Index() << " ";
289  std::cout << std::endl;
290  badelements.insert(large.Element()->Index());
291 
292  int nclarge = large.Element()->NConnects();
293  std::set<int64_t> largecon;
294  for (int icl=0; icl< nclarge; icl++) {
295  largecon.insert(large.Element()->ConnectIndex(icl));
296  }
297  TPZConnect &c = fMesh->ConnectVec()[*it];
299  while(dep)
300  {
301  if (largecon.find(dep->fDepConnectIndex) == largecon.end()) {
302  std::cout << "The connect " << *it << " belongs to element " << connecttoel[*it] << " as connect " << ic << std::endl;
303  std::cout << "The element is restrained along this side to element " << large.Element()->Index() << std::endl;
304  std::cout << "The connect " << *it << " depends on connect " << dep->fDepConnectIndex << " The connect of the large element are ";
305  for (int ic=0; ic<nclarge; ic++) {
306  std::cout << large.Element()->ConnectIndex(ic) << " ";
307  }
308  std::cout << std::endl;
309  }
310  dep = dep->fNext;
311  }
312  }
313  }
314  }
315  for (std::set<int64_t>::iterator it=badelements.begin(); it != badelements.end(); it++) {
316  fMesh->Element(*it)->Print();
317  }
318  return check;
319 }
320 
322 
323  int nel = fMesh->ElementVec().NElements();
324  int nstate = (fMesh->MaterialVec().begin()->second)->NStateVariables();
325  int iel;
326  for(iel = 0; iel<nel; iel++) {
327  TPZCompEl *cel = fMesh->ElementVec()[iel];
328  if(!cel) continue;
329  TPZInterpolatedElement *intel = dynamic_cast<TPZInterpolatedElement *>(cel);
330  if(!intel->CheckElementConsistency()) {
331  intel->Print();
332  return iel;
333  }
334  int nc = intel->NConnects();
335  int ic;
336  for(ic = 0; ic<nc; ic++) {
337  TPZConnect &c = intel->Connect(ic);
338  int nshape = intel->NConnectShapeF(ic,c.Order());
339  if(c.CheckDependency(nshape, fMesh, nstate) == -1) {
340  cout << "TPZCheckMesh inconsistent dependency" << endl;
341  intel->Print();
342  return iel;
343  }
344  }
345  }
346  return -1;
347 }
348 
353 {
354  bool wrong = false;
355  int64_t numindepconnect = 0;
356  int64_t nconnect = fMesh->NConnects();
357  for (int64_t ic=0; ic<nconnect; ic++) {
358  TPZConnect &c = fMesh->ConnectVec()[ic];
359  if (!c.HasDependency() && c.NElConnected() && !c.IsCondensed()) {
360  numindepconnect++;
361  }
362  }
363  if (numindepconnect == 0) {
364  return 0;
365  }
366  for (int64_t ic=0; ic<nconnect; ic++) {
367  TPZConnect &c = fMesh->ConnectVec()[ic];
368  if (c.HasDependency() || !c.NElConnected() || c.IsCondensed()) {
369  int64_t seqnum = c.SequenceNumber();
370  if (seqnum < numindepconnect && seqnum != -1) { // @omar need more information about this case seqnum != -1
371  *fOut << "Connect index " << ic << " has inconsistent sequence number " << seqnum << " nindependent connects " << numindepconnect << std::endl;
372  wrong = true;
373  }
374  }
375  }
376  if (wrong == false) {
377  return 0;
378  }
379  else
380  {
381  return 1;
382  }
383 }
384 
385 
int CheckConnectSeqNumberConsistency()
This method verifies if the sequence numbers of dependent connects and/or condensed connect are order...
void BuildDependList(int connect, TPZStack< int > &dependlist)
This method will build a list of all connect indices which depend on the connect passed in the argume...
Definition: pzcheckmesh.cpp:20
TPZCompElSide LowerLevelElementList(int onlyinterpolated)
Returns all connected elements which have level lower to the current element.
Definition: pzcompel.cpp:824
Implements computational element and a side. Computational Element.
Definition: pzcompel.h:632
Represents a set of shape functions associated with a computational element/side. Computational Eleme...
Definition: pzconnect.h:30
Contains declaration of TPZGeoElSide class which represents an element and its side, and TPZGeoElSideIndex class which represents an TPZGeoElSide index.
void DependencyReport(int connect)
This method will write a report to the std::ostream about all connects which potentially depend on th...
virtual int NConnectShapeF(int icon, int order) const =0
Returns the number of shapefunctions associated with a connect.
int CheckConnectOrderConsistency()
This method will verify whether the fSiderOrder data structure is in sink with the Order of the Conne...
TPZGeoElSide Reference() const
Reference to the geometric element.
Definition: pzcompel.cpp:748
virtual void Print(std::ostream &out=std::cout) const override
Prints the relevant data of the element to the output stream.
Definition: pzintel.cpp:1528
TPZCompElSide LowerLevelCompElementList2(int onlyinterpolated)
return the element/side pair which contains this/side and has a computational element associated ...
Utility class which represents an element with its side. The Geometric approximation classes Geometry...
Definition: pzgeoelside.h:83
virtual int NSides() const =0
Returns the number of connectivities of the element.
void EqualLevelCompElementList(TPZStack< TPZCompElSide > &elsidevec, int onlyinterpolated, int removeduplicates)
Returns all connected computational elements which have equal level to the current element...
int CheckDependency(int nshape, TPZCompMesh *mesh, int nstate)
Definition: pzconnect.cpp:326
int CheckConstraintDimension()
int VerifyAllConnects()
Loop over all connects verifying dependency and the compatibility between number of shapes in connect...
int CheckDimensions()
void HigherLevelElementList(TPZStack< TPZCompElSide > &elsidevec, int onlyinterpolated, int removeduplicates)
Returns all connected elements which have level higher to the current element.
Definition: pzcompel.cpp:761
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
int VerifyConnect(int connect)
This method will verify if the connects which depend on the connect passed in the argument list will ...
Definition: pzcheckmesh.cpp:73
unsigned char Order() const
Access function to return the order associated with the connect.
Definition: pzconnect.h:217
int64_t SequenceNumber() const
Returns the Sequence number of the connect object.
Definition: pzconnect.h:158
void Push(const T object)
Pushes a copy of the object on the stack.
Definition: pzstack.h:80
void EqualLevelElementList(TPZStack< TPZCompElSide > &elsidevec, int onlyinterpolated, int removeduplicates)
Returns all connected elements which have equal level to the current element This method will not put...
Definition: pzcompel.cpp:771
int64_t fDepConnectIndex
Definition: pzconnect.h:69
Structure to reference dependency.
Definition: pzconnect.h:67
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
unsigned int NShape() const
Definition: pzconnect.h:151
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
int HasDependency() const
Returns whether exist dependecy information.
Definition: pzconnect.h:292
TPZCompElSide FindElement(int connect)
This method will search in the mesh for an element/side which corresponds to the connect index passed...
Definition: pzcheckmesh.cpp:32
Contains declaration of TPZCheckMesh class which verifies the consistency of the datastructure of a T...
int Exists() const
Verifies if the object is non null (initialized)
Definition: pzcompel.h:697
TPZDepend * fNext
Definition: pzconnect.h:71
int64_t Index() const
Returns element index of the mesh fELementVec list.
Definition: pzcompel.h:821
virtual int NConnects() const override=0
Returns the number of connect objects of the element.
virtual TPZConnect & Connect(int i) const
Returns a pointer to the ith node.
Definition: pzcompel.cpp:298
virtual int CheckElementConsistency()
Checks element data structure consistancy.
Definition: pzintel.cpp:1093
unsigned char NState() const
Number of state variables associated with the connect.
Definition: pzconnect.h:146
A simple stack.
virtual int64_t ConnectIndex(int i) const =0
Returns the index of the ith connectivity of the element.
virtual int NConnects() const =0
Returns the number of nodes of the element.
TPZFNMatrix< 50, REAL > fDepMatrix
Definition: pzconnect.h:70
TPZCompEl * Element() const
Gives a pointer to the reference computational element.
Definition: pzcompel.h:675
TPZDepend * HasDepend(int64_t DepConnectIndex)
Definition: pzconnect.cpp:292
TPZGeoEl * Reference() const
Return a pointer to the corresponding geometric element if such exists, return 0 otherwise.
Definition: pzcompel.cpp:1137
virtual int NSideConnects(int iside) const override=0
Returns the number of dof nodes along side iside.
int Dimension() const
the dimension associated with the element/side
int64_t SideConnectIndex(int icon, int is) const
Returns the index of the c th connect object along side is.
Definition: pzintel.cpp:101
TPZDepend * FirstDepend()
Definition: pzconnect.h:296
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
int CheckElementShapeDimension()
virtual void Print(std::ostream &out=std::cout) const
Prints element data.
Definition: pzcompel.cpp:322
int NElConnected() const
Returns fNElConnected.
Definition: pzconnect.h:264
Contains declaration of TPZInterpolatedElement class which implements computational element of the in...
int Side() const
Returns the side index.
Definition: pzcompel.h:688
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
void HigherDimensionElementList(TPZStack< TPZCompElSide > &elsidevec, int onlyinterpolated, int removeduplicates)
Pushes all element/sides which have higher dimension than the current element/side.
Definition: pzcompel.cpp:781
TPZCheckMesh(TPZCompMesh *mesh, std::ostream *out)
Constructor.
Definition: pzcheckmesh.cpp:14
void Print(const TPZCompMesh &mesh, std::ostream &out=std::cout)
Print the information for the connect element.
Definition: pzconnect.cpp:67
Defines the interface of a computational element. Computational Element.
Definition: pzcompel.h:59
bool IsCondensed() const
Access method to return the indication whether the connect is condensed or not.
Definition: pzconnect.h:223
Implements computational element based on an interpolation space. Computational Element.
Definition: pzintel.h:27
int VerifyCompatibilityBetweenNShapesAndBlockSize(int connect)
This method will verify if the number of shape functions in connect is compatible with the size of th...
Definition: pzcheckmesh.cpp:57