NeoPZ
pzstrmatrixcs.cpp
Go to the documentation of this file.
1 
6 #include "pzstrmatrixcs.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 
29 using namespace std;
30 
31 #include "pzlog.h"
32 
33 #include "pz_pthread.h"
34 
35 #include "run_stats_table.h"
36 
37 #ifdef LOG4CXX
38 static LoggerPtr logger(Logger::getLogger("pz.strmatrix.TPZStructMatrixCS"));
39 static LoggerPtr loggerel(Logger::getLogger("pz.strmatrix.element"));
40 static LoggerPtr loggerel2(Logger::getLogger("pz.strmatrix.elementinterface"));
41 static LoggerPtr loggerelmat(Logger::getLogger("pz.strmatrix.elementmat"));
42 static LoggerPtr loggerCheck(Logger::getLogger("pz.strmatrix.checkconsistency"));
43 #endif
44 
45 #ifdef CHECKCONSISTENCY
46 static TPZCheckConsistency stiffconsist("ElementStiff");
47 #endif
48 
49 
51 
52 }
53 
55 
56 }
57 
59 
60 }
61 
63  cout << "TPZStructMatrixCS::Create should never be called\n";
64  return 0;
65 }
66 
68  cout << "TPZStructMatrixCS::Clone should never be called\n";
69  return 0;
70 }
71 
72 static RunStatsTable ass_stiff("-ass_stiff", "Assemble Stiffness");
73 static RunStatsTable ass_rhs("-ass_rhs", "Assemble Stiffness");
74 
76 
77  ass_stiff.start();
78 
79  if (fEquationFilter.IsActive()) {
80  int64_t neqcondense = fEquationFilter.NActiveEquations();
81 #ifdef PZDEBUG
82  if (stiffness.Rows() != neqcondense) {
83  DebugStop();
84  }
85 #endif
86  TPZFMatrix<STATE> rhsloc(neqcondense,rhs.Cols(),0.);
87  if(this->fNumThreads){
88  this->MultiThread_Assemble(stiffness,rhsloc,guiInterface);
89  }
90  else{
91  this->Serial_Assemble(stiffness,rhsloc,guiInterface);
92  }
93 
94  fEquationFilter.Scatter(rhsloc, rhs);
95  }
96  else
97  {
98  if(this->fNumThreads){
99  this->MultiThread_Assemble(stiffness,rhs,guiInterface);
100  }
101  else{
102  this->Serial_Assemble(stiffness,rhs,guiInterface);
103  }
104  }
105  ass_stiff.stop();
106 }
107 
109  ass_rhs.start();
111  {
112  int64_t neqcondense = fEquationFilter.NActiveEquations();
113  int64_t neqexpand = fEquationFilter.NEqExpand();
114  if(rhs.Rows() != neqexpand || Norm(rhs) != 0.)
115  {
116  DebugStop();
117  }
118  TPZFMatrix<STATE> rhsloc(neqcondense,1,0.);
119  if(this->fNumThreads)
120  {
121  this->MultiThread_Assemble(rhsloc,guiInterface);
122  }
123  else
124  {
125  this->Serial_Assemble(rhsloc,guiInterface);
126  }
127  fEquationFilter.Scatter(rhsloc,rhs);
128  }
129  else
130  {
131  if(this->fNumThreads){
132  this->MultiThread_Assemble(rhs,guiInterface);
133  }
134  else{
135  this->Serial_Assemble(rhs,guiInterface);
136  }
137  }
138  ass_rhs.stop();
139 }
140 
141 
142 
144 
145  if(!fMesh){
146  LOGPZ_ERROR(logger,"Serial_Assemble called without mesh")
147  DebugStop();
148  }
149 #ifdef LOG4CXX
150  if(dynamic_cast<TPZSubCompMesh * >(fMesh))
151  {
152  std::stringstream sout;
153  sout << "AllEig = {};";
154  LOGPZ_DEBUG(loggerelmat,sout.str())
155 
156  }
157 #endif
158 #ifdef PZDEBUG
159  if (rhs.Rows() != fEquationFilter.NActiveEquations()) {
160  DebugStop();
161  }
162 #endif
163 
164  int64_t iel;
165  int64_t nelem = fMesh->NElements();
167 #ifdef LOG4CXX
168  bool globalresult = true;
169  bool writereadresult = true;
170 #endif
171  TPZTimer calcstiff("Computing the stiffness matrices");
172  TPZTimer assemble("Assembling the stiffness matrices");
174 
175  int64_t count = 0;
176  for(iel=0; iel < nelem; iel++) {
177  TPZCompEl *el = elementvec[iel];
178  if(!el) continue;
179  int matidsize = fMaterialIds.size();
180  if(matidsize){
181  TPZMaterial * mat = el->Material();
182  TPZSubCompMesh *submesh = dynamic_cast<TPZSubCompMesh *> (el);
183  if (!mat)
184  {
185  if (!submesh) {
186  continue;
187  }
188  else if(submesh->NeedsComputing(fMaterialIds) == false) continue;
189  }
190  else
191  {
192  int matid = mat->Id();
193  if (this->ShouldCompute(matid) == false) continue;
194  }
195  }
196 
197  count++;
198  if(!(count%1000))
199  {
200  std::cout << '*';
201  std::cout.flush();
202  }
203  if(!(count%20000))
204  {
205  std::cout << "\n";
206  }
207  calcstiff.start();
208 
209  el->CalcStiff(ek,ef);
210 
211  if(guiInterface) if(guiInterface->AmIKilled()){
212  return;
213  }
214 
215 #ifdef LOG4CXX
216  if(dynamic_cast<TPZSubCompMesh * >(fMesh))
217  {
218  std::stringstream objname;
219  objname << "Element" << iel;
220  std::string name = objname.str();
221  objname << " = ";
222  std::stringstream sout;
223  ek.fMat.Print(objname.str().c_str(),sout,EMathematicaInput);
224  sout << "AppendTo[AllEig,Eigenvalues[" << name << "]];";
225 
226  LOGPZ_DEBUG(loggerelmat,sout.str())
227  /* if(iel == 133)
228  {
229  std::stringstream sout2;
230  el->Reference()->Print(sout2);
231  el->Print(sout2);
232  LOGPZ_DEBUG(logger,sout2.str())
233  }
234  */
235  }
236 
237 #endif
238 
239 #ifdef CHECKCONSISTENCY
240  //extern TPZCheckConsistency stiffconsist("ElementStiff");
241  stiffconsist.SetOverWrite(true);
242  bool result;
243  result = stiffconsist.CheckObject(ek.fMat);
244  if(!result)
245  {
246  globalresult = false;
247  std::stringstream sout;
248  sout << "element " << iel << " computed differently";
249  LOGPZ_ERROR(loggerCheck,sout.str())
250  }
251 
252 #endif
253 
254  calcstiff.stop();
255  assemble.start();
256 
257  if(!el->HasDependency()) {
258  ek.ComputeDestinationIndices();
259  fEquationFilter.Filter(ek.fSourceIndex, ek.fDestinationIndex);
260  // TPZSFMatrix<STATE> test(stiffness);
261  // TPZFMatrix<STATE> test2(stiffness.Rows(),stiffness.Cols(),0.);
262  // stiffness.Print("before assembly",std::cout,EMathematicaInput);
263  stiffness.AddKel(ek.fMat,ek.fSourceIndex,ek.fDestinationIndex);
264  rhs.AddFel(ef.fMat,ek.fSourceIndex,ek.fDestinationIndex);
265  // stiffness.Print("stiffness after assembly STK = ",std::cout,EMathematicaInput);
266  // rhs.Print("rhs after assembly Rhs = ",std::cout,EMathematicaInput);
267  // test2.AddKel(ek.fMat,ek.fSourceIndex,ek.fDestinationIndex);
268  // test -= stiffness;
269  // test.Print("matriz de rigidez diference",std::cout);
270  // test2.Print("matriz de rigidez interface",std::cout);
271 
272 #ifdef LOG4CXX
273  if(loggerel->isDebugEnabled())
274  {
275  std::stringstream sout;
276  TPZGeoEl *gel = el->Reference();
277  if(gel)
278  {
279  TPZManVector<REAL> center(gel->Dimension()),xcenter(3,0.);
280  gel->CenterPoint(gel->NSides()-1, center);
281  gel->X(center, xcenter);
282  sout << "Stiffness for computational element index " << el->Index() << std::endl;
283  sout << "Stiffness for geometric element " << gel->Index() << " center " << xcenter << std::endl;
284  }
285  else {
286  sout << "Stiffness for computational element without associated geometric element\n";
287  }
288  ek.Print(sout);
289  ef.Print(sout);
290  LOGPZ_DEBUG(loggerel,sout.str())
291  }
292 #endif
293  } else {
294  // the element has dependent nodes
295  ek.ApplyConstraints();
296  ef.ApplyConstraints();
297  ek.ComputeDestinationIndices();
298  fEquationFilter.Filter(ek.fSourceIndex, ek.fDestinationIndex);
299  stiffness.AddKel(ek.fConstrMat,ek.fSourceIndex,ek.fDestinationIndex);
300  rhs.AddFel(ef.fConstrMat,ek.fSourceIndex,ek.fDestinationIndex);
301 #ifdef LOG4CXX
302  if(loggerel->isDebugEnabled() && ! dynamic_cast<TPZSubCompMesh *>(fMesh))
303  {
304  std::stringstream sout;
305  TPZGeoEl *gel = el->Reference();
306  TPZManVector<REAL> center(gel->Dimension()),xcenter(3,0.);
307  gel->CenterPoint(gel->NSides()-1, center);
308  gel->X(center, xcenter);
309  sout << "Stiffness for geometric element " << gel->Index() << " center " << xcenter << std::endl;
310  ek.Print(sout);
311  ef.Print(sout);
312  LOGPZ_DEBUG(loggerel,sout.str())
313  }
314 #endif
315  }
316 
317  assemble.stop();
318  }//fim for iel
319  if(count > 20) std::cout << std::endl;
320 
321 #ifdef LOG4CXX
322  if(loggerCheck->isDebugEnabled())
323  {
324  std::stringstream sout;
325  sout << "The comparaison results are : consistency check " << globalresult << " write read check " << writereadresult;
326  //stiffness.Print("Matriz de Rigidez: ",sout);
327  stiffness.Print("Matriz de Rigidez: ",sout,EMathematicaInput);
328  rhs.Print("Right Handside", sout,EMathematicaInput);
329  LOGPZ_DEBUG(loggerCheck,sout.str())
330  }
331 
332 #endif
333 
334 }
335 
337 
338  int64_t iel;
339  int64_t nelem = fMesh->NElements();
340 
341  TPZTimer calcresidual("Computing the residual vector");
342  TPZTimer assemble("Assembling the residual vector");
343 
345 
346  for(iel=0; iel < nelem; iel++) {
347  TPZCompEl *el = elementvec[iel];
348  if(!el) continue;
349 
350  TPZMaterial * mat = el->Material();
351  if (!mat) continue;
352  int matid = mat->Id();
353  if (this->ShouldCompute(matid) == false) continue;
354 
356 
357  calcresidual.start();
358 
359  el->CalcResidual(ef);
360 
361  calcresidual.stop();
362 
363  assemble.start();
364 
365  if(!el->HasDependency()) {
368  rhs.AddFel(ef.fMat, ef.fSourceIndex, ef.fDestinationIndex);
369  } else {
370  // the element has dependent nodes
371  ef.ApplyConstraints();
375  }
376 
377  assemble.stop();
378 
379  }//fim for iel
380 #ifdef LOG4CXX
381  {
382  if(logger->isDebugEnabled())
383  {
384  std::stringstream sout;
385  sout << calcresidual.processName() << " " << calcresidual << std::endl;
386  sout << assemble.processName() << " " << assemble;
387  LOGPZ_DEBUG(logger,sout.str().c_str());
388  }
389  }
390 #endif
391  //std::cout << std::endl;
392 }
393 
395 {
396  TPZMatrix<STATE> *stiff = Create();
397 
398  //int64_t neq = stiff->Rows();
399  int64_t cols = MAX(1, rhs.Cols());
400  rhs.Redim(fEquationFilter.NEqExpand(),cols);
401  Assemble(*stiff,rhs,guiInterface);
402 
403 #ifdef LOG4CXX2
404  if(loggerel->isDebugEnabled())
405  {
406  std::stringstream sout;
407  stiff->Print("Stiffness matrix",sout);
408  rhs.Print("Right hand side", sout);
409  LOGPZ_DEBUG(loggerel,sout.str())
410  }
411 #endif
412  return stiff;
413 
414 }
415 
416 
418 {
419  ThreadData threaddata(this,mat,rhs,fMaterialIds,guiInterface);
420 #ifdef USING_TBB
421  AssembleTask tasks(&threaddata);
422  tbb::parallel_for(tbb::blocked_range<size_t>(0, fMesh->NElements()), tasks);
423 #else
424  const int numthreads = this->fNumThreads;
425  TPZVec<pthread_t> allthreads(numthreads);
426  int itr;
427  if(guiInterface){
428  if(guiInterface->AmIKilled()){
429  return;
430  }
431  }
432 
433  for(itr=0; itr<numthreads; itr++)
434  {
435  PZ_PTHREAD_CREATE(&allthreads[itr], NULL,ThreadData::ThreadWork,
436  &threaddata, __FUNCTION__);
437  }
438 
439  for(itr=0; itr<numthreads; itr++)
440  {
441  PZ_PTHREAD_JOIN(allthreads[itr], NULL, __FUNCTION__);
442  }
443 #endif
444 
445 #ifdef LOG4CXX
446  if(loggerCheck->isDebugEnabled())
447  {
448  std::stringstream sout;
449  //stiffness.Print("Matriz de Rigidez: ",sout);
450  mat.Print("Matriz de Rigidez: ",sout,EMathematicaInput);
451  rhs.Print("Right Handside", sout,EMathematicaInput);
452  LOGPZ_DEBUG(loggerCheck,sout.str())
453  }
454 #endif
455 }
456 
457 
459 {
460  ThreadData threaddata(this,rhs,fMaterialIds,guiInterface);
461 
462 #ifdef USING_TBB
463  AssembleTask tasks(&threaddata);
464  tbb::parallel_for(tbb::blocked_range<size_t>(0, fMesh->NElements()), tasks);
465 #else
466  const int numthreads = this->fNumThreads;
467  TPZVec<pthread_t> allthreads(numthreads);
468  int itr;
469  if(guiInterface){
470  if(guiInterface->AmIKilled()){
471  return;
472  }
473  }
474 
475  for(itr=0; itr<numthreads; itr++)
476  {
477  PZ_PTHREAD_CREATE(&allthreads[itr], NULL,ThreadData::ThreadWork,
478  &threaddata, __FUNCTION__);
479  }
480 
481  for(itr=0; itr<numthreads; itr++)
482  {
483  PZ_PTHREAD_JOIN(allthreads[itr], NULL, __FUNCTION__);
484  }
485 #endif
486 }
487 
488 
489 
491  TPZFMatrix<STATE> &rhs,
492  std::set<int> &MaterialIds,
493  TPZAutoPointer<TPZGuiInterface> guiInterface)
494 : fStruct(strmat), fGuiInterface(guiInterface), fGlobMatrix(&mat), fGlobRhs(&rhs), fNextElement(0)
495 {
496 
497  PZ_PTHREAD_MUTEX_INIT(&fAccessElement,NULL,"TPZStructMatrixCS::ThreadData::ThreadData()");
500  /* sem_t *sem_open( ... );
501  int sem_close(sem_t *sem);
502  int sem_unlink(const char *name);
503  */
504  /*
505  #ifdef MACOSX
506  std::stringstream sout;
507  static int counter = 0;
508  sout << "AssemblySem" << counter++;
509  fAssembly = sem_open(sout.str().c_str(), O_CREAT,777,1);
510  if(fAssembly == SEM_FAILED)
511  {
512  std::cout << __PRETTY_FUNCTION__ << " could not open the semaphore\n";
513  DebugStop();
514  }
515  #else
516  int sem_result = sem_init(&fAssembly,0,0);
517  if(sem_result != 0)
518  {
519  std::cout << __PRETTY_FUNCTION__ << " could not open the semaphore\n";
520  }
521  #endif
522  */
523 }
524 
526  TPZFMatrix<STATE> &rhs,
527  std::set<int> &MaterialIds,
528  TPZAutoPointer<TPZGuiInterface> guiInterface)
529 : fStruct(strmat),fGuiInterface(guiInterface), fGlobMatrix(0), fGlobRhs(&rhs), fNextElement(0)
530 {
531 
532  PZ_PTHREAD_MUTEX_INIT(&fAccessElement,NULL,"TPZStructMatrixCS::ThreadData::ThreadData()");
535  /* sem_t *sem_open( ... );
536  int sem_close(sem_t *sem);
537  int sem_unlink(const char *name);
538  */
539  /*
540  #ifdef MACOSX
541  std::stringstream sout;
542  static int counter = 0;
543  sout << "AssemblySem" << counter++;
544  fAssembly = sem_open(sout.str().c_str(), O_CREAT,777,1);
545  if(fAssembly == SEM_FAILED)
546  {
547  std::cout << __PRETTY_FUNCTION__ << " could not open the semaphore\n";
548  DebugStop();
549  }
550  #else
551  int sem_result = sem_init(&fAssembly,0,0);
552  if(sem_result != 0)
553  {
554  std::cout << __PRETTY_FUNCTION__ << " could not open the semaphore\n";
555  }
556  #endif
557  */
558 }
559 
561 {
562  PZ_PTHREAD_MUTEX_DESTROY(&fAccessElement,"TPZStructMatrixCS::ThreadData::~ThreadData()");
565 
566  /*
567 
568  #ifdef MACOSX
569  sem_close(fAssembly);
570  #else
571  sem_destroy(&fAssembly);
572  #endif
573  */
574 }
575 
577 {
578  ThreadData *data = (ThreadData *) datavoid;
579  // compute the next element (this method is threadsafe)
580  int64_t iel = data->NextElement();
581  TPZCompMesh *cmesh = data->fStruct->fMesh;
582  TPZAutoPointer<TPZGuiInterface> guiInterface = data->fGuiInterface;
583  int64_t nel = cmesh->NElements();
584  while(iel < nel)
585  {
586 #ifdef LOG4CXX
587  if (logger->isDebugEnabled()) {
588  std::stringstream sout;
589  sout << "Computing element " << iel;
590  LOGPZ_DEBUG(logger, sout.str())
591  }
592 #endif
593 #ifdef LOG4CXX
594  std::stringstream sout;
595  sout << "Element " << iel << " elapsed time ";
596  TPZTimer timeforel(sout.str());
597  timeforel.start();
598 #endif
599 
602  if (data->fGlobMatrix) {
603  ek = new TPZElementMatrix(cmesh,TPZElementMatrix::EK);
604  }
605  else
606  {
607  ek = ef;
608  }
609 
610  TPZCompEl *el = cmesh->ElementVec()[iel];
611  TPZElementMatrix *ekp = ek.operator->();
612  TPZElementMatrix *efp = ef.operator->();
613  TPZElementMatrix &ekr = *ekp;
614  TPZElementMatrix &efr = *efp;
615 
616  if (data->fGlobMatrix) {
617  el->CalcStiff(ekr,efr);
618  }
619  else
620  {
621  el->CalcResidual(efr);
622  }
623 
624  if(guiInterface) if(guiInterface->AmIKilled()){
625  break;
626  }
627 
628  if(!el->HasDependency()) {
630 
631  if(data->fStruct->HasRange())
632  {
634  }
635 #ifdef LOG4CXX
636  if(loggerel->isDebugEnabled())
637  {
638  std::stringstream sout;
639  sout << "Element index " << iel << std::endl;
640  ek->fMat.Print("Element stiffness matrix",sout);
641  ef->fMat.Print("Element right hand side", sout);
642  LOGPZ_DEBUG(loggerel,sout.str())
643  }
644 #endif
645  } else {
646  // the element has dependent nodes
647  if (data->fGlobMatrix) {
648  ek->ApplyConstraints();
649  }
650  ef->ApplyConstraints();
652  if(data->fStruct->HasRange())
653  {
655  }
656 #ifdef LOG4CXX
657  if(loggerel2->isDebugEnabled() && el->Reference() && el->Reference()->MaterialId() == 1 && el->IsInterface())
658  {
659  std::stringstream sout;
660  el->Reference()->Print(sout);
661  el->Print(sout);
662  ek->Print(sout);
663  // ef->Print(sout);
664  LOGPZ_DEBUG(loggerel2,sout.str())
665  }
666 #endif
667 #ifdef LOG4CXX
668  if(loggerel->isDebugEnabled())
669  {
670  std::stringstream sout;
671  sout << "Element index " << iel << std::endl;
672  ek->fConstrMat.Print("Element stiffness matrix",sout);
673  ef->fConstrMat.Print("Element right hand side", sout);
674  LOGPZ_DEBUG(loggerel,sout.str())
675  }
676 #endif
677  }
678 
679  // Assemble the matrix
680 
681  if(!ek->HasDependency())
682  {
683  if (data->fGlobMatrix) {
687 
688  }
690  data->fGlobRhs->AddFel(ef->fMat,ek->fSourceIndex,ek->fDestinationIndex);
692  }
693  else
694  {
695  if (data->fGlobMatrix) {
699  }
703  }
704 #ifdef LOG4CXX
705  timeforel.stop();
706  if (logger->isDebugEnabled())
707  {
708  std::stringstream sout;
709  sout << timeforel.processName() << timeforel;
710  LOGPZ_DEBUG(logger, sout.str())
711  }
712 #endif
713 
714  // compute the next element (this method is threadsafe)
715  iel = data->NextElement();
716  }
717 
718  return 0;
719 }
720 
722 {
723  TPZCompMesh *cmesh = fStruct->fMesh;
724  TPZAdmChunkVector<TPZCompEl *> &elementvec = cmesh->ElementVec();
725 
726  int64_t nel = elementvec.NElements();
727  int64_t my_el;
728 
729  while (1) {
730 
731  PZ_PTHREAD_MUTEX_LOCK(&fAccessElement,"TPZStructMatrix::ThreadData::NextElement()");
732  my_el = fNextElement++;
733  PZ_PTHREAD_MUTEX_UNLOCK(&fAccessElement,"TPZStructMatrix::ThreadData::NextElement()");
734 
735  if (my_el >= nel-1)
736  break;
737 
738  TPZCompEl *el = elementvec[my_el];
739  if(!el) continue;
740  if(fStruct->fMaterialIds.size() == 0) break;
741  TPZMaterial * mat = el->Material();
742  TPZSubCompMesh *submesh = dynamic_cast<TPZSubCompMesh *> (el);
743  if(!mat)
744  {
745  if(!submesh)
746  {
747  continue;
748  }
749  else if(submesh->NeedsComputing(fStruct->fMaterialIds) == false) continue;
750  }
751  else
752  {
753  int matid = mat->Id();
754  if(this->ShouldCompute(matid) == false) continue;
755  }
756  break;
757  }
758 
759  return my_el;
760 }
761 
762 #ifdef USING_TBB
763 void TPZStructMatrixCS::AssembleTask::operator()(const tbb::blocked_range<size_t>& range) const
764 {
765  TPZCompMesh *cmesh = data->fStruct->fMesh;
766  TPZAutoPointer<TPZGuiInterface> guiInterface = data->fGuiInterface;
767 
768  for(size_t iel=range.begin(); iel!=range.end(); ++iel )
769  {
770 #ifdef LOG4CXX
771  if (logger->isDebugEnabled()) {
772  std::stringstream sout;
773  sout << "Computing element " << iel;
774  LOGPZ_DEBUG(logger, sout.str())
775  }
776 #endif
777 #ifdef LOG4CXX
778  std::stringstream sout;
779  sout << "Element " << iel << " elapsed time ";
780  TPZTimer timeforel(sout.str());
781  timeforel.start();
782 #endif
783 
786  if (data->fGlobMatrix) {
787  ek = new TPZElementMatrix(cmesh,TPZElementMatrix::EK);
788  }
789  else
790  {
791  ek = ef;
792  }
793 
794  TPZCompEl *el = cmesh->ElementVec()[iel];
795 
796  if (el) {
797 
798  TPZElementMatrix *ekp = ek.operator->();
799  TPZElementMatrix *efp = ef.operator->();
800  TPZElementMatrix &ekr = *ekp;
801  TPZElementMatrix &efr = *efp;
802 
803  if (data->fGlobMatrix) {
804  el->CalcStiff(ekr,efr);
805  }
806  else
807  {
808  el->CalcResidual(efr);
809  }
810 
811  if(guiInterface) if(guiInterface->AmIKilled()){
812  break;
813  }
814 
815  if(!el->HasDependency()) {
817 
818  if(data->fStruct->HasRange())
819  {
820  data->fStruct->FilterEquations(ek->fSourceIndex,ek->fDestinationIndex);
821  }
822 #ifdef LOG4CXX
823  if(loggerel->isDebugEnabled())
824  {
825  std::stringstream sout;
826  sout << "Element index " << iel << std::endl;
827  ek->fMat.Print("Element stiffness matrix",sout);
828  ef->fMat.Print("Element right hand side", sout);
829  LOGPZ_DEBUG(loggerel,sout.str())
830  }
831 #endif
832  } else {
833  // the element has dependent nodes
834  if (data->fGlobMatrix) {
835  ek->ApplyConstraints();
836  }
837  ef->ApplyConstraints();
839  if(data->fStruct->HasRange())
840  {
841  data->fStruct->FilterEquations(ek->fSourceIndex,ek->fDestinationIndex);
842  }
843 #ifdef LOG4CXX
844  if(loggerel2->isDebugEnabled() && el->Reference() && el->Reference()->MaterialId() == 1 && el->IsInterface())
845  {
846  std::stringstream sout;
847  el->Reference()->Print(sout);
848  el->Print(sout);
849  ek->Print(sout);
850  // ef->Print(sout);
851  LOGPZ_DEBUG(loggerel2,sout.str())
852  }
853 #endif
854 #ifdef LOG4CXX
855  if(loggerel->isDebugEnabled())
856  {
857  std::stringstream sout;
858  sout << "Element index " << iel << std::endl;
859  ek->fConstrMat.Print("Element stiffness matrix",sout);
860  ef->fConstrMat.Print("Element right hand side", sout);
861  LOGPZ_DEBUG(loggerel,sout.str())
862  }
863 #endif
864  }
865 
866 #ifdef LOG4CXX
867  timeforel.stop();
868  if (logger->isDebugEnabled())
869  {
870  std::stringstream sout;
871  sout << timeforel.processName() << timeforel;
872  LOGPZ_DEBUG(logger, sout.str())
873  }
874 #endif
875  // Assemble the matrix
876 
877  if(!ek->HasDependency())
878  {
879  if (data->fGlobMatrix) {
880  PZ_PTHREAD_MUTEX_LOCK(&data->fAccessElementK,"");
881  data->fGlobMatrix->AddKel(ek->fMat,ek->fSourceIndex,ek->fDestinationIndex);
882  PZ_PTHREAD_MUTEX_UNLOCK(&data->fAccessElementK,"");
883 
884  }
885  PZ_PTHREAD_MUTEX_LOCK(&data->fAccessElementF,"");
886  data->fGlobRhs->AddFel(ef->fMat,ek->fSourceIndex,ek->fDestinationIndex);
887  PZ_PTHREAD_MUTEX_UNLOCK(&data->fAccessElementF,"");
888  }
889  else
890  {
891  if (data->fGlobMatrix) {
892  PZ_PTHREAD_MUTEX_LOCK(&data->fAccessElementK,"");
893  data->fGlobMatrix->AddKel(ek->fConstrMat,ek->fSourceIndex,ek->fDestinationIndex);
894  PZ_PTHREAD_MUTEX_UNLOCK(&data->fAccessElementK,"");
895  }
896  PZ_PTHREAD_MUTEX_LOCK(&data->fAccessElementF,"");
897  data->fGlobRhs->AddFel(ef->fConstrMat,ek->fSourceIndex,ek->fDestinationIndex);
898  PZ_PTHREAD_MUTEX_UNLOCK(&data->fAccessElementF,"");
899  }
900  }
901  }
902 }
903 #endif
904 
906  return Hash("TPZStructMatrixCS") ^ TPZStructMatrixBase::ClassId() << 1;
907 }
908 
909 void TPZStructMatrixCS::Read(TPZStream& buf, void* context) {
910  TPZStructMatrixBase::Read(buf, context);
911 
912 }
913 
914 void TPZStructMatrixCS::Write(TPZStream& buf, int withclassid) const {
915  TPZStructMatrixBase::Write(buf, withclassid);
916 
917 }
918 
int64_t NElements() const
Number of computational elements allocated.
Definition: pzcmesh.h:169
Contains a class to record running statistics on CSV tables.
int fNumThreads
Number of threads in Assemble process.
#define PZ_PTHREAD_MUTEX_UNLOCK(mutex, fn)
Definition: pz_pthread.h:79
virtual TPZMatrix< STATE > * Create() override
Sets number of threads in Assemble process.
The timer class. Utility.
Definition: TPZTimer.h:46
static RunStatsTable ass_rhs("-ass_rhs", "Assemble Stiffness")
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.
pthread_mutex_t fAccessElementF
Mutexes (to choose which element is next)
int MaterialId() const
Returns the material index of the element.
Definition: pzgeoel.h:250
Timing class. Absolutely copied from GNU time. Take a look at
Contains declaration of TPZGeoNode class which defines a geometrical node.
void Filter(TPZVec< int64_t > &orig, TPZVec< int64_t > &dest) const
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
Contains declaration of TPZCompEl class which defines the interface of a computational element...
Templated vector implementation.
Refines geometrical mesh (all the elements) num times.
Definition: pzstrmatrixcs.h:39
virtual void CalcStiff(TPZElementMatrix &ek, TPZElementMatrix &ef)
Computes the element stifness matrix and right hand side.
Definition: pzcompel.h:794
int64_t fNextElement
Current element.
Contains the TPZStructMatrixCS class which responsible for a interface among Matrix and Finite Elemen...
TPZEquationFilter fEquationFilter
Object which will determine which equations will be assembled.
Declarates the TPZBlock<REAL>class which implements block matrices.
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
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 MAX(a, b)
Gets maxime value between a and b.
Definition: pzreal.h:81
virtual int NSides() const =0
Returns the number of connectivities of the element.
int ClassId() const override
Define the class id associated with the class.
virtual void Serial_Assemble(TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
Assemble the global system of equations into the matrix which has already been created.
TPZManVector< int64_t > fDestinationIndex
Definition: pzelmat.h:53
void ComputeDestinationIndices()
Definition: pzelmat.cpp:126
static RunStatsTable ass_stiff("-ass_stiff", "Assemble Stiffness")
pthread_mutex_t fAccessElement
Mutexes (to choose which element is next)
virtual int IsInterface()
Definition: pzcompel.h:159
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
Contains declaration of TPZElementMatrix struct which associates an element matrix with the coeficien...
virtual void CenterPoint(int side, TPZVec< REAL > &masscent) const =0
It returns the coordinates from the center of the side of the element in the element coordinate space...
TPZCompMesh * fMesh
Pointer to the computational mesh from which the matrix will be generated.
#define PZ_PTHREAD_JOIN(thread, val, fn)
Definition: pz_pthread.h:34
virtual const std::set< int > & MaterialIds()
Returns the material ids.
virtual TPZMaterial * Material() const
Identify the material object associated with the element.
Definition: pzcompel.cpp:959
void Print(std::ostream &out)
Definition: pzelmat.cpp:47
void Read(TPZStream &buf, void *context) override
read objects from the stream
pthread_mutex_t fAccessElementK
Mutexes (to choose which element is next)
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.
#define PZ_PTHREAD_MUTEX_LOCK(mutex, fn)
Definition: pz_pthread.h:76
std::string & processName()
Gets the process name (for reporting purposes).
Definition: TPZTimer.h:168
void start()
Turns the timer on.
Definition: TPZTimer.cpp:28
TPZMatrix< STATE > * fGlobMatrix
Global matrix.
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
virtual void MultiThread_Assemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
Assemble the global right hand side.
int64_t Index() const
Returns the index of the element within the element vector of the mesh.
Definition: pzgeoel.h:730
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
Contains TPZMatrixclass which implements full matrix (using column major representation).
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
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
Definition: pzlog.h:87
Free store vector implementation.
void parallel_for(int n, body_t &obj)
Definition: pzparallel.h:24
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
virtual TPZMatrix< STATE > * CreateAssemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface, unsigned numthreads_assemble, unsigned numthreads_decompose)
Definition: pzstrmatrixcs.h:57
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.
#define PZ_PTHREAD_MUTEX_DESTROY(mutex, fn)
Definition: pz_pthread.h:73
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.
TPZFMatrix< STATE > * fGlobRhs
Global rhs vector.
int64_t Index() const
Returns element index of the mesh fELementVec list.
Definition: pzcompel.h:821
virtual bool ShouldCompute(int matid) const
Establish whether the element should be computed.
Implements an interface to check the consistency of two implementations. Utility. ...
TPZManVector< int64_t > fSourceIndex
Definition: pzelmat.h:53
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
ThreadData(TPZStructMatrixCS *strmat, TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, std::set< int > &MaterialIds, TPZAutoPointer< TPZGuiInterface > guiInterface)
Initialize the mutex semaphores and others.
Contains declaration of TPZCompMesh class which is a repository for computational elements...
TPZAutoPointer< TPZGuiInterface > fGuiInterface
Gui interface object.
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
Definition: pzfmatrix.h:616
bool NeedsComputing(const std::set< int > &matids) override
Verifies if any element needs to be computed corresponding to the material ids.
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
~ThreadData()
Destructor: Destroy the mutex semaphores and others.
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
TPZStructMatrixCS * fStruct
Current structmatrix object.
void ApplyConstraints()
Apply the constraints applied to the nodes by transforming the tangent matrix and right hand side...
Definition: pzelmat.cpp:186
Contains declaration of TPZSubCompMesh class which implements a group of computational elements as a ...
int ClassId() const override
Define the class id associated with the class.
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
virtual TPZStructMatrixCS * Clone() override
virtual void X(TPZVec< REAL > &qsi, TPZVec< REAL > &result) const =0
Return the coordinate in real space of the point coordinate in the master element space...
int64_t NextElement()
Look for an element index which needs to be computed and put it on the stack.
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
TPZAdmChunkVector< TPZCompEl * > & ElementVec()
Returns a reference to the element pointers vector.
Definition: pzcmesh.h:183
virtual void Print(std::ostream &out=std::cout) const
Prints element data.
Definition: pzcompel.cpp:322
#define PZ_PTHREAD_CREATE(thread, attr, routine, args, fn)
Definition: pz_pthread.h:31
Contains declaration of TPZInterpolatedElement class which implements computational element of the in...
int Id() const
Definition: TPZMaterial.h:170
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 stop()
Turns the timer off, and computes the elapsed time.
Definition: TPZTimer.cpp:36
#define PZ_PTHREAD_MUTEX_INIT(mutex, attr, fn)
Definition: pz_pthread.h:70
virtual void Print(std::ostream &out=std::cout)
Print all relevant data of the element to cout.
Definition: pzgeoel.cpp:238
bool ShouldCompute(int matid)
Establish whether the element should be computed.
Defines the interface of a computational element. Computational Element.
Definition: pzcompel.h:59
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.
Structure to manipulate thread to solve system equations.
Definition: pzstrmatrixcs.h:99
virtual int HasDependency()
Returns 1 if the element has at least one dependent node. Returns 0 otherwise.
Definition: pzcompel.cpp:565
virtual bool HasRange() const
Verify if a range has been specified.
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.
static void * ThreadWork(void *threaddata)
The function which will compute the matrices.