NeoPZ
TPZMultiphysicsCompMesh.cpp
Go to the documentation of this file.
1 //
2 // TPZMultiphysicsCompMesh.cpp
3 // pz
4 //
5 // Created by Omar DurĂ¡n on 3/21/19.
6 //
7 
9 #include "pzmultiphysicscompel.h"
10 #include "pzlog.h"
11 
12 #ifdef LOG4CXX
13 static LoggerPtr logger(Logger::getLogger("pz.mulptiphysicscompmesh"));
14 #endif
15 
16 
18 
21 }
22 
24 
27 }
28 
31 
32 }
33 
37 }
38 
41 {
44 }
45 
46 
47 
49 
50  if (this != & other) // prevent self-assignment
51  {
55  }
56  return *this;
57 }
58 
60  return m_mesh_vector;
61 }
62 
65 }
66 
69 {
70  TPZManVector<int> active(mesh_vector.size(),1);
71  BuildMultiphysicsSpace(active,mesh_vector);
72 }
73 
75 
76  m_active_approx_spaces = active_approx_spaces;
77  m_mesh_vector = mesh_vector;
79  std::cout<< "TPZMultiphysicsCompMesh:: The vector provided should have the same size." << std::endl;
80  DebugStop();
81  }
82 
83  int n_approx_spaces = m_mesh_vector.size();
84 
85  SetNMeshes(n_approx_spaces);
88  // delete all elements and connects in the mesh
91  AddElements();
92  AddConnects();
94 }
95 
97  m_active_approx_spaces = active_approx_spaces;
98  m_mesh_vector = mesh_vector;
100  std::cout<< "TPZMultiphysicsCompMesh:: The vector provided should have the same size." << std::endl;
101  DebugStop();
102  }
103 
104  int n_approx_spaces = m_mesh_vector.size();
105 
106  SetNMeshes(n_approx_spaces);
110  // delete all elements and connects in the mesh
113  AddElements();
114  AddConnects();
116 
117  int nel_res = NElements();
118  for (long el = 0; el < nel_res; el++) {
119  TPZCompEl *cel = Element(el);
120  TPZMultiphysicsElement *mfcel = dynamic_cast<TPZMultiphysicsElement *>(cel);
121  if (!mfcel) {
122  continue;
123  }
124  mfcel->PrepareIntPtIndices();
125  }
126 
127 }
128 
130 
131  m_mesh_vector = mesh_vector;
133  for(int64_t i = 0; i< m_active_approx_spaces.size(); i++) m_active_approx_spaces[i] = 1;
134  int n_approx_spaces = m_mesh_vector.size();
135  SetNMeshes(n_approx_spaces);
138  // delete all elements and connects in the mesh
140  TPZCompMesh::AutoBuild(gelindexes);
141  AddElements();
142  AddConnects();
144 }
145 
146 
148 
149  std::cout << __PRETTY_FUNCTION__ << " has not been implemented. Use BuildMultiphysicsSpace instead\n";
150  DebugStop();
151 }
152 
154 
155  TPZGeoMesh * geometry = Reference();
156  geometry->ResetReference();
157  int64_t n_cels = NElements();
158  int n_approx_spaces = m_mesh_vector.size();
159  for(int i_as = 0; i_as < n_approx_spaces; i_as++)
160  {
161  if(!m_mesh_vector[i_as]) continue;
162  m_mesh_vector[i_as]->LoadReferences();
163  {
164  std::ofstream out("gmesh.txt");
165  geometry->Print(out);
166  }
167  int64_t icel;
168  for(icel=0; icel < n_cels; icel++)
169  {
170  TPZCompEl * cel = ElementVec()[icel];
171  TPZMultiphysicsElement * mfcel = dynamic_cast<TPZMultiphysicsElement *> (cel);
173  if(mfcel)
174  {
175  int64_t found = 0;
176  TPZGeoEl * gel = mfcel->Reference();
177  TPZStack<TPZCompElSide> celstack;
178  TPZGeoElSide gelside(gel,gel->NSides()-1);
179 
180  if (gel->Reference()) {
181  mfcel->AddElement(gel->Reference(), i_as);
182  continue;
183  }
184  else
185  {
186  TPZGeoEl *gelF = gel;
187  while(gelF->Father())
188  {
189  gelF = gelF->Father();
190  if (gelF->Reference()) {
191 #ifdef PZDEBUG
192  if (gelF->MaterialId() != gel->MaterialId()) {
193  DebugStop();
194  }
195 #endif
196  mfcel->AddElement(gelF->Reference(), i_as);
197  found = true;
198  break;
199  }
200  }
201  }
202  if (!found) {
203  mfcel->AddElement(0, i_as);
204  }
205  }
206  else if (mfint) {
207  //set up interface
208  }
209  else {
210  DebugStop();
211  }
212  }
213  geometry->ResetReference();
214  }
215 
216  for (int64_t icel = 0; icel < n_cels; icel++) {
217  TPZCompEl *cel = Element(icel);
218  TPZMultiphysicsElement *mfel = dynamic_cast<TPZMultiphysicsElement *>(cel);
219  if (!mfel) {
220  continue;
221  }
224  }
225 
226 }
227 
229 
230  int n_approx_spaces = m_mesh_vector.size();
231 
232  TPZVec<int64_t> FirstConnect(n_approx_spaces,0);
233  int64_t nconnects = 0;
234  for (int i_as = 0; i_as < n_approx_spaces; i_as++)
235  {
236  if (m_active_approx_spaces[i_as] == 0) {
237  continue;
238  }
239  FirstConnect[i_as] = nconnects;
240  nconnects += m_mesh_vector[i_as]->ConnectVec().NElements();
241  }
242  ConnectVec().Resize(nconnects);
243  Block().SetNBlocks(nconnects);
244 
245  int64_t counter = 0;
246  int64_t seqnum = 0;
247  for (int i_as = 0; i_as < n_approx_spaces; i_as++)
248  {
249  if (m_active_approx_spaces[i_as] == 0) {
250  continue;
251  }
252 
253  int64_t ic;
254  int64_t nc = m_mesh_vector[i_as]->ConnectVec().NElements();
255  for (ic=0; ic<nc; ic++)
256  {
257  TPZConnect &refcon = m_mesh_vector[i_as]->ConnectVec()[ic];
258  ConnectVec()[counter] = refcon;
259  if (refcon.SequenceNumber() >= 0) {
260  ConnectVec()[counter].SetSequenceNumber(seqnum);
261  ConnectVec()[counter].SetNState(refcon.NState());
262  ConnectVec()[counter].SetNShape(refcon.NShape());
263  ConnectVec()[counter].SetLagrangeMultiplier(refcon.LagrangeMultiplier());
264  int ndof = refcon.NDof(*m_mesh_vector[i_as]);
265  Block().Set(seqnum,ndof);
266  seqnum++;
267  }
268  counter++;
269  }
270 
271  for (ic=0; ic<nc; ic++)
272  {
273  TPZConnect &cn = ConnectVec()[FirstConnect[i_as]+ic];
274  if (cn.HasDependency())
275  {
277  while (dep) {
278  dep->fDepConnectIndex = dep->fDepConnectIndex+FirstConnect[i_as];
279  dep = dep->fNext;
280  }
281  }
282  }
283  }
284 
285  Block().SetNBlocks(seqnum);
286  ExpandSolution();
287  int64_t iel;
288  int64_t nelem = NElements();
289  for (iel = 0; iel < nelem; iel++)
290  {
291 
292 
293  TPZCompEl *celorig = ElementVec()[iel];
294  TPZMultiphysicsElement *cel = dynamic_cast<TPZMultiphysicsElement *> (celorig);
295  TPZMultiphysicsInterfaceElement *interfacee = dynamic_cast<TPZMultiphysicsInterfaceElement *> (celorig);
296  if (interfacee) {
297  continue;
298  }
299  if (!cel) {
300  continue;
301  }
302  TPZStack<int64_t> connectindexes;
303  int64_t imesh;
304  std::list<TPZOneShapeRestraint> oneshape;
305  for (int i_as = 0; i_as < n_approx_spaces; i_as++) {
306 
307  if (m_active_approx_spaces[i_as] == 0) {
308  continue;
309  }
310 
311  TPZCompEl *celref = cel->ReferredElement(i_as);
312  if (!celref) {
313  continue;
314  }
315  std::list<TPZOneShapeRestraint> celrest;
316  celrest = celref->GetShapeRestraints();
317  for (std::list<TPZOneShapeRestraint>::iterator it = celrest.begin(); it != celrest.end(); it++) {
318  TPZOneShapeRestraint rest = *it;
319  TPZOneShapeRestraint convertedrest(rest);
320  for(int face = 0; face < rest.fFaces.size(); face++)
321  {
322  int ic = rest.fFaces[face].first;
323  convertedrest.fFaces[face].first = ic+FirstConnect[i_as];
324  }
325  oneshape.push_back(convertedrest);
326  }
327  int64_t ncon = celref->NConnects();
328  int64_t ic;
329  for (ic=0; ic<ncon; ic++) {
330  connectindexes.Push(celref->ConnectIndex(ic)+FirstConnect[i_as]);
331  }
332  }
333  cel->SetConnectIndexes(connectindexes);
334  for (std::list<TPZOneShapeRestraint>::iterator it = oneshape.begin(); it != oneshape.end(); it++) {
335  cel->AddShapeRestraint(*it);
336  }
337  }
338 
339 }
340 
342 {
343  int n_approx_spaces = m_active_approx_spaces.size();
344  TPZManVector<int64_t> FirstConnectIndex(n_approx_spaces+1,0);
345  for (int i_as = 0; i_as < n_approx_spaces; i_as++) {
346  if (m_active_approx_spaces[i_as] == 0) {
347  continue;
348  }
349  FirstConnectIndex[i_as+1] = FirstConnectIndex[i_as]+m_mesh_vector[i_as]->NConnects();
350  }
351  TPZBlock<STATE> &blockMF = Block();
352  for (int i_as = 0; i_as < n_approx_spaces; i_as++) {
353 
354  if (m_active_approx_spaces[i_as] == 0) {
355  continue;
356  }
357 
358  int64_t ncon = m_mesh_vector[i_as]->NConnects();
359  TPZBlock<STATE> &block = m_mesh_vector[i_as]->Block();
360  int64_t ic;
361  for (ic=0; ic<ncon; ic++) {
362  TPZConnect &con = m_mesh_vector[i_as]->ConnectVec()[ic];
363  int64_t seqnum = con.SequenceNumber();
364  if(seqnum<0) continue;
365  int blsize = block.Size(seqnum);
366  TPZConnect &conMF = ConnectVec()[FirstConnectIndex[i_as]+ic];
367  int64_t seqnumMF = conMF.SequenceNumber();
368  if(seqnumMF < 0) continue;
369  for (int idf=0; idf<blsize; idf++) {
370  blockMF.Put(seqnumMF, idf, 0, block.Get(seqnum, idf, 0));
371  }
372  }
373  }
374 }
375 
377 {
378  int n_approx_spaces = m_active_approx_spaces.size();
379  TPZManVector<int64_t> FirstConnectIndex(n_approx_spaces+1,0);
380  for (int i_as = 0; i_as < n_approx_spaces; i_as++) {
381  if (m_active_approx_spaces[i_as] == 0) {
382  continue;
383  }
384  FirstConnectIndex[i_as+1] = FirstConnectIndex[i_as]+m_mesh_vector[i_as]->NConnects();
385  }
386  TPZBlock<STATE> &blockMF = Block();
387  for (int i_as = 0; i_as < n_approx_spaces; i_as++) {
388 
389  if (m_active_approx_spaces[i_as] == 0) {
390  continue;
391  }
392 
393  int64_t ncon = m_mesh_vector[i_as]->NConnects();
394  TPZBlock<STATE> &block = m_mesh_vector[i_as]->Block();
395  int64_t ic;
396  for (ic=0; ic<ncon; ic++) {
397  TPZConnect &con = m_mesh_vector[i_as]->ConnectVec()[ic];
398  int64_t seqnum = con.SequenceNumber();
399  if(seqnum<0) continue;
400  int blsize = block.Size(seqnum);
401  TPZConnect &conMF = ConnectVec()[FirstConnectIndex[i_as]+ic];
402  int nelconnected = conMF.NElConnected();
403  if (nelconnected == 0) {
404  continue;
405  }
406  int64_t seqnumMF = conMF.SequenceNumber();
407  int idf;
408  for (idf=0; idf<blsize; idf++) {
409  block.Put(seqnum, idf, 0, blockMF.Get(seqnumMF, idf, 0));
410  }
411  }
412  }
413 #ifdef LOG4CXX
414  if (logger->isDebugEnabled()) {
415  std::stringstream sout;
416  sout << "Solutions of the referred meshes";
417  }
418 #endif
419  for (int i_as = 0; i_as < n_approx_spaces; i_as++) {
420  if (m_active_approx_spaces[i_as] == 0) {
421  continue;
422  }
423  m_mesh_vector[i_as]->LoadSolution(m_mesh_vector[i_as]->Solution());
424  }
425 }
426 
429 {
430  int64_t nel = NElements();
431  for (int64_t el = 0; el<nel; el++) {
432  TPZCompEl *cel = Element(el);
433  if(cel)
434  {
435  delete cel;
436  fElementVec[el] = 0;
437  }
438  }
439  fElementVec.Resize(0);
440  nel = fConnectVec.NElements();
441  for (int64_t el=0; el<nel; el++) {
442  fConnectVec[el].RemoveDepend();
443  }
444  fConnectVec.Resize(0);
445 }
int64_t NElements() const
Number of computational elements allocated.
Definition: pzcmesh.h:169
TPZGeoMesh * Reference() const
Returns a pointer to the geometrical mesh associated.
Definition: pzcmesh.h:209
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 void InitializeIntegrationRule() override=0
After adding the elements initialize the integration rule.
TPZManVector< int, 5 > m_active_approx_spaces
int MaterialId() const
Returns the material index of the element.
Definition: pzgeoel.h:250
TPZAdmChunkVector< TPZCompEl * > fElementVec
List of pointers to elements.
Definition: pzcmesh.h:60
virtual void AddShapeRestraint(TPZOneShapeRestraint restraint) override
Add a shape restraint (meant to fit the pyramid to restraint.
virtual void AddElement(TPZCompEl *cel, int64_t mesh)=0
Definition of the retraint associated with the top of the pyramid.
Utility class which represents an element with its side. The Geometric approximation classes Geometry...
Definition: pzgeoelside.h:83
const TVar & Get(const int block_row, const int block_col, const int r, const int c) const
Gets a element from matrix verifying.
Definition: pzblock.cpp:191
int64_t NElements() const
Access method to query the number of elements of the vector.
int NDof(TPZCompMesh &mesh)
Number of degrees of freedom associated with the object.
Definition: pzconnect.cpp:317
TPZManVector< std::pair< int64_t, int >, 4 > fFaces
Faces which are related. First item is the connect index, second item is the degree of freedom...
virtual int NSides() const =0
Returns the number of connectivities of the element.
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
void AutoBuild()
Automatic builder for the computational mesh structure.
It has the declaration of the TPZMultiphysicsCompEl class.
unsigned char LagrangeMultiplier() const
Access method to return the indication whether the connect is associated with a pressure lagrange mul...
Definition: pzconnect.h:230
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
TPZCompEl * Element(int64_t iel)
Definition: pzcmesh.h:185
void Resize(const int newsize)
Increase the size of the chunk vector.
Definition: pzadmchunk.h:280
TPZCreateApproximationSpace & ApproxSpace()
Definition: pzcmesh.h:498
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
TPZVec< TPZCompMesh * > & MeshVector()
Get the vector of computational meshes.
int64_t fDepConnectIndex
Definition: pzconnect.h:69
virtual void Print(std::ostream &out=std::cout) const
Print the information of the grid to an ostream.
Definition: pzgmesh.cpp:130
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
void AddElements()
add the elements from the atomic meshes to the multiphysics elements
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
TPZManVector< TPZCompMesh *, 3 > m_mesh_vector
Vector of computational meshes.
virtual void ExpandSolution()
Adapt the solution vector to new block dimensions.
Definition: pzcmesh.cpp:396
virtual TPZCompEl * ReferredElement(int64_t mesh)=0
TPZCompEl * Reference() const
Return a pointer to the element referenced by the geometric element.
Definition: pzgeoel.h:750
unsigned int NShape() const
Definition: pzconnect.h:151
int HasDependency() const
Returns whether exist dependecy information.
Definition: pzconnect.h:292
TPZMultiphysicsCompMesh & operator=(const TPZMultiphysicsCompMesh &other)
Assignement constructor.
const TPZBlock< STATE > & Block() const
Access the block structure of the solution vector.
Definition: pzcmesh.h:213
void SetNMeshes(int64_t nmeshes)
Definition: pzcmesh.h:445
TPZDepend * fNext
Definition: pzconnect.h:71
TPZAdmChunkVector< TPZConnect > & ConnectVec()
Return a reference to the connect pointers vector.
Definition: pzcmesh.h:198
int SetNBlocks(const int num_of_blocks)
Sets number of blocks on diagonal matrix.
Definition: pzblock.cpp:91
void BuildMultiphysicsSpaceWithMemory(TPZVec< int > &active_approx_spaces, TPZVec< TPZCompMesh * > &mesh_vector)
Set active approximation spaces.
unsigned char NState() const
Number of state variables associated with the connect.
Definition: pzconnect.h:146
virtual void SetConnectIndexes(TPZVec< int64_t > &indexes)=0
virtual int64_t ConnectIndex(int i) const =0
Returns the index of the ith connectivity of the element.
virtual void SetActiveApproxSpaces(TPZManVector< int, 5 > &active_approx_space)
Set the active approximation spaces.
virtual int NConnects() const =0
Returns the number of nodes of the element.
virtual std::list< TPZOneShapeRestraint > GetShapeRestraints() const
Return a list with the shape restraints.
Definition: pzcompel.h:432
virtual void PrepareIntPtIndices()
Prepare the vector of the material withmem with the correct integration point indexes.
Definition: pzcompel.h:395
static int idf[6]
int Put(const int block_row, const int block_col, const int r, const int c, const TVar &value)
Puts a element to matrix verifying.
Definition: pzblock.cpp:217
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 geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
Computes the contribution over an interface between two discontinuous elements. Computational Element...
TPZDepend * FirstDepend()
Definition: pzconnect.h:296
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
int Size(const int block_diagonal) const
Returns block dimension.
Definition: pzblock.h:171
TPZVec< int > & GetActiveApproximationSpaces()
Get the vector of active physics.
TPZAdmChunkVector< TPZCompEl * > & ElementVec()
Returns a reference to the element pointers vector.
Definition: pzcmesh.h:183
int NElConnected() const
Returns fNElConnected.
Definition: pzconnect.h:264
TPZCompMesh & operator=(const TPZCompMesh &copy)
copy the content of the mesh
Definition: pzcmesh.cpp:1683
void BuildMultiphysicsSpace(TPZVec< int > &active_approx_spaces, TPZVec< TPZCompMesh * > &mesh_vector)
Set active approximation spaces.
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
void SetAllCreateFunctionsMultiphysicElemWithMem()
Definition: pzcmesh.h:547
void CleanElementsConnects()
delete the elements and connects
void ResetReference()
Resets all load references in elements and nodes.
Definition: pzgmesh.cpp:197
Defines the interface of a computational element. Computational Element.
Definition: pzcompel.h:59
void SetAllCreateFunctionsMultiphysicElem()
Definition: pzcmesh.h:542
TPZGeoEl * Father() const
Computes the normal vectors needed for forming HDiv vector valued shape functions.
Definition: pzgeoel.cpp:2574
TPZFMatrix< STATE > & Solution()
Access the solution vector.
Definition: pzcmesh.h:219
TPZMultiphysicsCompMesh()
Default constructor.
virtual void AutoBuild()
Creates the computational elements, and the degree of freedom nodes.
Definition: pzcmesh.h:474
TPZAdmChunkVector< TPZConnect > fConnectVec
List of pointers to nodes.
Definition: pzcmesh.h:62
void AddConnects()
add the connects from the atomic meshes