NeoPZ
substruct.cpp
Go to the documentation of this file.
1 
8 #ifdef HAVE_CONFIG_H
9 #include <pz_config.h>
10 #endif
11 
12 #include <iostream>
13 #include <cstdlib>
14 
15 #include "tpzdohrsubstruct.h"
16 #include "tpzdohrmatrix.h"
17 #include "tpzdohrprecond.h"
18 #include "pzdohrstructmatrix.h"
19 #include "pzstepsolver.h"
20 #include "pzcompel.h"
21 #include "pzgeoelbc.h"
22 
23 #include "pzelast3d.h"
24 #include "pzbndcond.h"
25 
26 #include "tpzdohrassembly.h"
27 
28 #include "pzlog.h"
29 #include "tpzgensubstruct.h"
30 #include "tpzpairstructmatrix.h"
31 #include "pzviscoelastic.h"
32 #include "TPZVTKGeoMesh.h"
33 #include "pzgeotetrahedra.h"
34 #include "pzskylstrmatrix.h"
35 
36 #include "tpzarc3d.h"
37 #include "tpzdohrmatrix.h"
38 
39 #include "pzvtkmesh.h"
40 #include "pzfstrmatrix.h"
41 
42 #include "pzlog.h"
43 
44 #include "pzbfilestream.h" // TPZBFileStream, TPZFileStream
45 #include "pzmd5stream.h"
46 
47 #include <fstream>
48 #include <string>
49 
50 #ifdef LOG4CXX
51 static LoggerPtr loggerconverge(Logger::getLogger("pz.converge"));
52 static LoggerPtr logger(Logger::getLogger("main"));
53 #endif
54 
55 //#include "timing_analysis.h"
56 #include "arglib.h"
57 #include "run_stats_table.h"
58 
59 #ifdef HAS_GETRUSAGE
60 #include <sys/resource.h> // getrusage
61 #endif
62 
63 #ifdef USING_TBB
64 #include "tbb/task_scheduler_init.h"
65 using namespace tbb;
66 // If you have issues with: dyld: Library not loaded: libtbb.dylib
67 // try setting the LD path. Ex:
68 // export DYLD_FALLBACK_LIBRARY_PATH=/Users/borin/Desktop/neopz/tbb40_297oss/lib/
69 #endif
70 
71 #ifdef USING_MKL
72 #include "mkl_service.h"
73 #endif
74 
80 void SetPointBC(TPZGeoMesh *gr, TPZVec<REAL> &x, int bc);
81 REAL Height(TPZGeoMesh *gmesh);
82 int SubStructure(TPZAutoPointer<TPZCompMesh> cmesh, REAL height);
83 
84 using namespace std;
85 
86 void help(const char* prg)
87 {
88  cout << "Compute ...." << endl;
89  cout << "The application is divided in four main steps: s1, s2, s3 and s4" << endl;
90  cout << endl;
91  cout << " Step 1 (mp/mc -> ckpt 1): " << endl;
92  cout << " Step 2 (ckpt 1 -> ckpt 2): dohrstruct->Create()" << endl;
93  cout << " Step 3 (ckpt 2 -> ckpt 3): dohrstruct->Assemble(), dohrstruct->Preconditioner() " << endl;
94  cout << " Step 4 (ckpt 3 -> end ): cg.solve() ..." << endl << endl;
95  cout << "Usage: " << prg << "starting_point stop_point file [-of output_file]" << endl << endl;
96  cout << " starting_point = {-cf1|-cf2|-cf3|-mc|-mp} input_file" << endl;
97  cout << " starting_point = {-st1|-st2|-st3}" << endl;
98 
99  clarg::arguments_descriptions(cout, " ", "\n");
100 }
101 
102 clarg::argString cf1("-cf1", "starts execution from checkpoint 1 (read checkpoint file)", "ckpt1.ckpt");
103 clarg::argString cf2("-cf2", "starts execution from checkpoint 2 (read checkpoint file)", "ckpt2.ckpt");
104 clarg::argString cf3("-cf3", "starts execution from checkpoint 3 (read checkpoint file)", "ckpt3.ckpt");
105 clarg::argBool st1("-st1", "stop at checkpoint 1 (after dump)", false);
106 clarg::argBool st2("-st2", "stop at checkpoint 2 (after dump)", false);
107 clarg::argBool st3("-st3", "stop at checkpoint 3 (after dump)", false);
108 
109 clarg::argString gen_sig_ckpt1("-gen_c1_md5", "generates MD5 signature for checkpoint 1 and dump into file.", "ckpt1.md5");
110 clarg::argString chk_sig_ckpt1("-chk_c1_md5", "compute MD5 signature for checkpoint 1 and check against MD5 at file.", "ckpt1.md5");
111 clarg::argString gen_sig_ckpt2("-gen_c2_md5", "generates MD5 signature for checkpoint 2 and dump into file.", "ckpt2.md5");
112 clarg::argString chk_sig_ckpt2("-chk_c2_md5", "compute MD5 signature for checkpoint 2 and check against MD5 at file.", "ckpt2.md5");
113 clarg::argString gen_sig_ckpt3("-gen_c3_md5", "generates MD5 signature for checkpoint 3 and dump into file.", "ckpt3.md5");
114 clarg::argString chk_sig_ckpt3("-chk_c3_md5", "compute MD5 signature for checkpoint 3 and check against MD5 at file.", "ckpt3.md5");
115 clarg::argString gen_sig_ckpt4("-gen_c4_md5", "generates MD5 signature for checkpoint 4 and dump into file.", "ckpt4.md5");
116 clarg::argString chk_sig_ckpt4("-chk_c4_md5", "compute MD5 signature for checkpoint 4 and check against MD5 at file.", "ckpt4.md5");
117 
118 clarg::argString dc1("-dc1", "dump checkpoint 1 to file", "ckpt1.ckpt");
119 clarg::argString dc2("-dc2", "dump checkpoint 2 to file", "ckpt2.ckpt");
120 clarg::argString dc3("-dc3", "dump checkpoint 3 to file", "ckpt3.ckpt");
121 clarg::argString mc("-mc", "starts execution from beginning - read a \"malha_cubo\" input file",
122  "../cube1.txt");
123 clarg::argString mp("-mp", "starts execution from beginning - read a \"malha_predio\" input file",
124  "../8andares02.txt");
125 
126 clarg::argInt plevel ("-p", "plevel", 1);
127 clarg::argInt num_it ("-num_it", "number limit of iterations to the CG solver", 1000);
128 clarg::argInt nt_sm("-nt_sm", "Dohr (l1): number of threads to process the submeshes", 0);
129 clarg::argInt nt_d("-nt_d", "Dohr (l1): number of threads to decompose each submesh", 0);
130 clarg::argInt nt_a("-nt_a", "Pair (l2): number of threads to assemble each submesh (multiply by nt_sm)", 0);
131 clarg::argBool dohr_tbb("-dohr_tbb", "assemble TPZDohrStructMatrix (level 1) using TBB", false);
132 clarg::argBool pair_tbb("-pair_tbb", "assemble TPZPairStructMatrix (level 2) using TBB", false);
133 clarg::argInt nt_multiply("-nt_m", "number of threads to multiply", 0);
134 clarg::argInt nsub("-nsub", "number of substructs", 4);
135 
136 clarg::argInt dim_arg("-dim", "dim???", 3);
137 clarg::argInt maxlevel("-maxlevel", "maxlevel???", 5);
138 clarg::argInt sublevel("-sublevel", "sublevel???", 3);
139 
140 clarg::argInt verb_level("-v", "verbosity level", 0);
141 
142 clarg::argBool bc("-bc", "binary checkpoints", false);
143 
144 clarg::argBool h("-h", "help message", false);
145 
146 clarg::argInt refin("-ref", "refine mesh", 1);
147 
148 /* Run statistics. */
149 RunStatsTable total_rst ("-tot_rdt", "Whole program (total) statistics raw data table");
150 RunStatsTable create_rst ("-cre_rdt", "Create statistics raw data table (step 2)");
151 RunStatsTable assemble_rst("-ass_rdt", "Assemble statistics raw data table (step 3)");
152 RunStatsTable precond_rst ("-pre_rdt", "Precond statistics raw data table (step 3)");
153 RunStatsTable solve_rst ("-sol_rdt", "Solver statistics raw data table (step 4)");
154 
155 #ifdef USING_LIKWID
156 #define PERF_START(obj) \
157 likwid_markerStartRegion(#obj); \
158 obj.start()
159 #define PERF_STOP(obj) \
160 obj.stop(); \
161 likwid_markerStopRegion(#obj)
162 #else
163 #define PERF_START(obj) obj.start()
164 #define PERF_STOP(obj) obj.stop()
165 #endif
166 
167 
168 class FileStreamWrapper
169 {
170 public:
173 
174  void OpenWrite(const std::string& fn)
175  {
176  if (bc.was_set())
177  bfs.OpenWrite(fn);
178  else
179  fs.OpenWrite(fn);
180  }
181 
182  void OpenRead(const std::string& fn)
183  {
184  if (bc.was_set())
185  bfs.OpenRead(fn);
186  else
187  fs.OpenRead(fn);
188  }
189 
190  operator TPZStream&()
191  {
192  if (bc.was_set())
193  return bfs;
194  else
195  return fs;
196  }
197 
198 protected:
199  TPZFileStream fs;
200  TPZBFileStream bfs;
201 };
202 
203 #ifdef USING_LIKWID
204 #include<likwid.h>
205 
206 struct likwid_manager_t {
207  likwid_manager_t() {
208  std::cout << "Calling likwid_markerInit()" << std::endl;
209  likwid_markerInit();
210  }
211  ~likwid_manager_t() {
212  likwid_markerClose();
213  std::cout << "Calling likwid_markerClose()" << std::endl;
214  }
215 };
216 
217 #endif
218 
219 int main(int argc, char *argv[])
220 {
221 
222 #ifdef USING_LIKWID
223  likwid_manager_t likwid_manager;
224 #endif
225 
226 #ifdef LOG4CXX
227  InitializePZLOG("log4cxx.cfg");
228 #endif
229 
230 #ifdef USING_BLAS
231  setenv("VECLIB_MAXIMUM_THREADS", "1", true);
232 #endif
233 
234 #ifdef USING_MKL
235  mkl_set_num_threads(1);
236 #endif
237 
238  int main_ret = EXIT_SUCCESS;
239 
240  /* Parse the arguments */
241  if (clarg::parse_arguments(argc, argv)) {
242  cerr << "Error when parsing the arguments!" << endl;
243  return 1;
244  }
245 
246  if (h.get_value() == true) {
247  help(argv[0]);
248  return 1;
249  }
250 
251 #ifdef USING_TBB
252  int number_tbb=nt_a.get_value();
253  if(number_tbb<=0)number_tbb=1;
254  task_scheduler_init init(number_tbb);
255 #endif
256 
257  /* Verbose macro. */
258  unsigned verbose = verb_level.get_value();
259 # define VERBOSE(level,...) if (level <= verbose) cout << __VA_ARGS__
260 
261  if (verbose >= 1) {
262  std::cout << "- Arguments -----------------------" << std::endl;
263  clarg::values(std::cout, false);
264  std::cout << "-----------------------------------" << std::endl;
265  }
266 
267  if (!mp.was_set() && !mc.was_set() && !cf1.was_set() &&
268  !cf2.was_set() && !cf3.was_set())
269  {
270  cerr << "A \"starting_point\" must be provided!" << endl;
271  help(argv[0]);
272  return 1;
273  }
274 
275  PERF_START(total_rst);
276 
277  if (pair_tbb.was_set())
279  else
281 
282  TPZGeoMesh *gmesh = 0;
283  TPZAutoPointer<TPZCompMesh> cmeshauto = 0;
284  TPZDohrStructMatrix* dohrstruct = 0;
285  TPZFMatrix<STATE> *rhs = NULL;
286  TPZMatrix<STATE> *matptr = 0;
287  int dim = dim_arg.get_value();
289 
290  bool running = false;
291 
292  /* Start from malha_cubo or malha_predio? */
293  if (mp.was_set() || mc.was_set())
294  {
295  if (mp.was_set()) // Predio Elastisco
296  {
297  if (running) {
298  cerr << "ERROR: you must select only one of the start modes: "
299  << "mp, mc, cf1, cf2 or cf3" << endl;
300  exit(1);
301  }
302  else
303  running = true;
304 
305  gmesh = MalhaPredio();
306  cmeshauto = new TPZCompMesh(gmesh);
307  cmeshauto->SetDimModel(dim);
308  InsertElasticity(cmeshauto);
309  cmeshauto->AutoBuild();
310  }
311  if (mc.was_set()) // Cubo Elastico
312  {
313  if (running) {
314  cerr << "ERROR: you must select only one of the start modes: "
315  << "mp, mc, cf1, cf2 or cf3" << endl;
316  exit(1);
317  }
318  else running = true;
319 
320  VERBOSE(1, "Reading MalhaCubo from file: " << mc.get_value() << endl);
321  gmesh = MalhaCubo();
322  cmeshauto = new TPZCompMesh(gmesh);
323  cmeshauto->SetDimModel(dim);
324  cmeshauto->SetDefaultOrder(plevel.get_value());
325  //cmeshauto->SetAllCreateFunctionsContinuousWithMem();
326  //cmeshauto->SetAllCreateFunctionsContinuous();
327  InsertElasticityCubo(cmeshauto);
328  cmeshauto->AutoBuild();
329  }
330 
331  VERBOSE(1, "Number of equations " << cmeshauto->NEquations() << endl);
332 
333 //#define ASSEMBLE_PERF
334 #ifdef ASSEMBLE_PERF
335  TPZFStructMatrix fullstruct(cmeshauto);
336  fullstruct.SetNumThreads(nt_a.get_value());
337 
338  int64_t sz = cmeshauto->NEquations();
339 
340  /*
341  // ************** PARALELO **************
342  TPZFMatrix<STATE> rhs_t(sz, 1, 0.);
343  fullstruct.Assemble(rhs_t, 0);
344 
345  // ************** SERIAL *************
346  fullstruct.SetNumThreads(0);
347  TPZFMatrix<STATE> rhs_b(sz, 1, 0.);
348  fullstruct.Assemble(rhs_b, 0);
349 
350  for (int i=0; i<sz; i++) {
351  if(fabs(rhs_b(i,0)-rhs_t(i,0))>1.e-9) {
352  printf("%d - %.5f %.5f\n",i, rhs_b(i,0),rhs_t(i,0));
353  exit(101);
354  }
355  }
356  return 0;
357 */
358  TPZFMatrix<STATE> rhs_t(sz, 1, 0.);
359  PERF_START(assemble_rst);
360  fullstruct.Assemble(rhs_t, 0);
361  PERF_STOP(assemble_rst);
362 
363  return 0;
364 #endif
365 
366  dohrstruct = new TPZDohrStructMatrix(cmeshauto);
367  dohrstruct->IdentifyExternalConnectIndexes();
368 
369  VERBOSE(1, "Substructuring the mesh" << endl);
370 
371  dohrstruct->SubStructure(nsub.get_value());
372 
373 #ifdef LOG4CXX
374  {
375  std::stringstream str;
376  cmeshauto->Print(str);
377  LOGPZ_DEBUG(logger,str.str());
378  }
379 #endif
380 
381  /* Dump checkpoint 1? */
382  if (dc1.was_set() && running)
383  {
384  VERBOSE(1, "Dumping checkpoint 1 into: " << dc1.get_value() << endl);
385  FileStreamWrapper CheckPoint1;
386  CheckPoint1.OpenWrite(dc1.get_value());
387  cmeshauto->Reference()->Write(CheckPoint1, 0);
388  cmeshauto->Write(CheckPoint1, 0);
389  dohrstruct->Write(CheckPoint1);
390  }
391  /* Gen/Check checkpoint 1 MD5 signature? */
392  if ((gen_sig_ckpt1.was_set() || chk_sig_ckpt1.was_set()) && running)
393  {
394  TPZMD5Stream sig;
395  cmeshauto->Reference()->Write(sig, 0);
396  cmeshauto->Write(sig, 0);
397  dohrstruct->Write(sig);
398  if (chk_sig_ckpt1.was_set()) {
399  int ret;
400  if ((ret=sig.CheckMD5(chk_sig_ckpt1.get_value()))) {
401  cerr << "ERROR: MD5 Signature for checkpoint 1 does not match. (ret = " << ret << ")" << endl;
402  return 1;
403  }
404  }
405  if (gen_sig_ckpt1.was_set()) {
406  int ret;
407  if ((ret = sig.WriteMD5(gen_sig_ckpt1.get_value()))) {
408  cerr << "ERROR when writing ckpt 1 MD5 Signature to file (ret = " << ret << "): "
409  << gen_sig_ckpt1.get_value() << endl;
410  return 1;
411  }
412  }
413  }
414  }
415 
416  if(st1.was_set()) running = false;
417 
418  // Start from Checkpoint 1
419  if (cf1.was_set())
420  {
421  if (running) {
422  cerr << "ERROR: you must select only one of the start modes: mp, mc, cf1, cf2 or cf3" << endl;
423  exit(1);
424  }
425  else
426  running = true;
427 
428  gmesh = new TPZGeoMesh;
429  cmeshauto = new TPZCompMesh(gmesh);
430  dohrstruct = new TPZDohrStructMatrix(cmeshauto);
431  /* Read the checkpoint. */
432  {
433  FileStreamWrapper CheckPoint1;
434  CheckPoint1.OpenRead(cf1.get_value());
435  gmesh->Read(CheckPoint1, 0);
436  cmeshauto->Read(CheckPoint1, gmesh);
437  dohrstruct->Read(CheckPoint1);
438  }
439 
440  dim = cmeshauto->Dimension();
441  VERBOSE(1, "Reading dim from file. new dim = " << dim << ", old dim = " << dim_arg.get_value() << endl);
442 
443  }
444 
445  /* Work between checkpoint 1 and checkpoint 2 */
446  if (running) {
447 
448  PERF_START(create_rst);
449  matptr = dohrstruct->Create();
450  PERF_STOP(create_rst);
451 
452  if (dc2.was_set())
453  {
454  VERBOSE(1, "Dumping checkpoint 2 into: " << dc2.get_value() << endl);
455  FileStreamWrapper CheckPoint2;
456  CheckPoint2.OpenWrite(dc2.get_value());
457  SAVEABLE_STR_NOTE(CheckPoint2,"cmeshauto->Reference()->Write()");
458  cmeshauto->Reference()->Write(CheckPoint2, 0);
459  SAVEABLE_STR_NOTE(CheckPoint2,"cmeshauto->Write()");
460  cmeshauto->Write(CheckPoint2, 0);
461  SAVEABLE_STR_NOTE(CheckPoint2,"matptr->Write()");
462  matptr->Write(CheckPoint2, 1);
463  SAVEABLE_STR_NOTE(CheckPoint2,"dohrstruct->Write()");
464  dohrstruct->Write(CheckPoint2);
465  }
466 
467  /* Gen/Check checkpoint 2 MD5 signature? */
468  if (gen_sig_ckpt2.was_set() || chk_sig_ckpt2.was_set())
469  {
470  TPZMD5Stream sig;
471  cmeshauto->Reference()->Write(sig, 0);
472  cmeshauto->Write(sig, 0);
473  matptr->Write(sig, 1);
474  dohrstruct->Write(sig);
475 
476  if (chk_sig_ckpt2.was_set()) {
477  if (sig.CheckMD5(chk_sig_ckpt2.get_value())) {
478  cerr << "ERROR: MD5 Signature for checkpoint 2 does not match." << endl;
479  return 1;
480  }
481  }
482  if (gen_sig_ckpt2.was_set()) {
483  if (sig.WriteMD5(gen_sig_ckpt2.get_value())) {
484  cerr << "ERROR when writing ckpt 2 MD5 Signature to file: "
485  << gen_sig_ckpt2.get_value() << endl;
486  return 1;
487  }
488  }
489  }
490  }
491 
492  if(st2.was_set()) running = false;
493 
494  // Start from Checkpoint 2
495  if (cf2.was_set())
496  {
497  if (running) {
498  cerr << "ERROR: you must select only one of the start modes: mp, mc, cf1, cf2 or cf3" << endl;
499  exit(1);
500  }
501  else
502  running = true;
503 
504  FileStreamWrapper CheckPoint2;
505  CheckPoint2.OpenRead(cf2.get_value());
506  gmesh = new TPZGeoMesh;
507  SAVEABLE_SKIP_NOTE(CheckPoint2);
508  gmesh->Read(CheckPoint2,0);
509  cmeshauto = new TPZCompMesh(gmesh);
510  SAVEABLE_SKIP_NOTE(CheckPoint2);
511  cmeshauto->Read(CheckPoint2, &gmesh);
512  SAVEABLE_SKIP_NOTE(CheckPoint2);
513  matptr = dynamic_cast<TPZMatrix<STATE> *>(TPZSavable::Restore(CheckPoint2, 0));
514  dohrstruct = new TPZDohrStructMatrix(cmeshauto);
515  SAVEABLE_SKIP_NOTE(CheckPoint2);
516  dohrstruct->Read(CheckPoint2);
517  }
518 
519  TPZAutoPointer<TPZMatrix<STATE> > precond = NULL;
520  /* Work between checkpoint 2 and checkpoint 3 */
521  if (running)
522  {
523  if (nt_multiply.was_set() && nt_multiply.get_value() != 1)
524  {
525  dohrstruct->SetNumThreads(nt_multiply.get_value());
526  }
527 
528  PERF_START(assemble_rst);
530  rhs = new TPZFMatrix<STATE>(cmeshauto->NEquations(),1,0.);
531  VERBOSE(1,"dohrstruct->Assemble()" << endl);
532  if (dohr_tbb.was_set())
533  dohrstruct->AssembleTBB(*matptr,*rhs, gui);
534  else
535  dohrstruct->Assemble(*matptr,*rhs, gui, nt_sm.get_value(), nt_d.get_value());
536  PERF_STOP(assemble_rst);
537 
538  PERF_START(precond_rst);
539  precond = dohrstruct->Preconditioner();
540  PERF_STOP(precond_rst);
541 
542  if (dc3.was_set())
543  {
544  VERBOSE(1, "Dumping checkpoint 3 into: " << dc3.get_value() << endl);
545  FileStreamWrapper CheckPoint3;
546  CheckPoint3.OpenWrite(dc3.get_value());
547  cmeshauto->Reference()->Write(CheckPoint3, 0);
548  cmeshauto->Write(CheckPoint3, 0);
549  matptr->Write(CheckPoint3, 1);
550  precond->Write(CheckPoint3, 1);
551  rhs->Write(CheckPoint3, 0);
552  }
553 
554  /* Gen/Check checkpoint 3 MD5 signature? */
555  if (gen_sig_ckpt3.was_set() || chk_sig_ckpt3.was_set())
556  {
557  TPZMD5Stream sig;
558  cmeshauto->Reference()->Write(sig, 0);
559  cmeshauto->Write(sig, 0);
560  matptr->Write(sig, 1);
561  precond->Write(sig, 1);
562  rhs->Write(sig, 0);
563  int ret;
564  if (chk_sig_ckpt3.was_set()) {
565  if ((ret=sig.CheckMD5(chk_sig_ckpt3.get_value()))) {
566  cerr << "ERROR(ret=" << ret << ") : MD5 Signature for checkpoint 3 does not match." << endl;
567  return 1;
568  }
569  }
570  if (gen_sig_ckpt3.was_set()) {
571  if ((ret=sig.WriteMD5(gen_sig_ckpt3.get_value()))) {
572  cerr << "ERROR (ret=" << ret << ") when writing ckpt 3 MD5 Signature to file: "
573  << gen_sig_ckpt3.get_value() << endl;
574  return 1;
575  }
576  }
577  }
578  }
579 
580  if(st3.was_set()) running = false;
581 
582  // Start from Checkpoint 3
583  if (cf3.was_set())
584  {
585  if (running) {
586  cerr << "ERROR: you must select only one of the start modes: mp, mc, cf1, cf2 or cf3" << endl;
587  exit(1);
588  }
589  else
590  running = true;
591  gmesh = new TPZGeoMesh;
592  cmeshauto = new TPZCompMesh(gmesh);
593  dohrstruct = new TPZDohrStructMatrix(cmeshauto);
594 
595  dim = cmeshauto->Dimension();
596  VERBOSE(1, "Reading dim from file. new dim = " << dim << ", old dim = " << dim_arg.get_value() << endl);
597 
598  FileStreamWrapper CheckPoint3;
599  CheckPoint3.OpenRead(cf3.get_value());
600  gmesh->Read(CheckPoint3, 0);
601  cmeshauto->Read(CheckPoint3, gmesh);
602  matptr = dynamic_cast<TPZMatrix<STATE> *>(TPZSavable::Restore(CheckPoint3, 0));
603  precond = dynamic_cast<TPZMatrix<STATE> *>(TPZSavable::Restore(CheckPoint3, matptr));
604  rhs = new TPZFMatrix<STATE>(cmeshauto->NEquations(),1,0.);
605  rhs->Read(CheckPoint3, 0);
606  }
607 
608  int neq, iterations;
609  neq = iterations = 0;
610 
611 
612 
613  if (running) {
614 
615  /* Work after checkpoint 3 */
616  TPZAutoPointer<TPZMatrix<STATE> > dohr = matptr;
617 
618  neq = dohr->Rows();
619  TPZFMatrix<STATE> diag(neq,1,0.), produto(neq,1);
620 
621  VERBOSE(1, "Number of equations " << neq << endl);
622 
623  TPZStepSolver<STATE> pre(precond);
624  pre.SetMultiply();
625  TPZStepSolver<STATE> cg(dohr);
626 
627  /* Configure the CG solver to iterate:
628  - until it converges (residual <= 1.e-8), or
629  - until it reaches 500 itearations.
630  */
631  cg.SetCG(num_it.get_value(),pre,1.e-8,0);
632 
633  PERF_START(solve_rst);
634  cg.Solve(*rhs,diag);
635  PERF_STOP(solve_rst);
636 
637 
638  iterations = cg.NumIterations();
639 
640  /* checking if the solver converged */
641  if (cg.GetTolerance() > 1.e-8)
642  {
643  cerr << "ERROR: solver do not converged with the limit of iterations." << endl;
644  exit(1);
645  }
646 
648  dynamic_cast<TPZDohrMatrix<STATE,TPZDohrSubstructCondense<STATE> > *> (dohr.operator->());
649 
650  if (!dohrptr) {
651  DebugStop();
652  }
653 
654  dohrptr->AddInternalSolution(diag);
655 
656 
657  /* Gen/Check checkpoint 4 MD5 signature? */
658  if (gen_sig_ckpt4.was_set() || chk_sig_ckpt4.was_set())
659  {
660  TPZMD5Stream sig;
661 
662  dohrptr->Write(sig, 0);
663  diag.Write(sig, 0);
664  cg.Write(sig, 0);
665  //cmeshauto->Reference()->Write(sig, 0);
666  //cmeshauto->Write(sig, 0);
667  //matptr->Write(sig, 1);
668  //precond->Write(sig, 1);
669  //rhs->Write(sig, 0);
670 
671  int ret;
672  if (chk_sig_ckpt4.was_set()) {
673  if ((ret=sig.CheckMD5(chk_sig_ckpt4.get_value()))) {
674  cerr << "ERROR(ret=" << ret << ") : MD5 Signature for checkpoint 4 does not match." << endl;
675  main_ret = 1;
676  }
677  }
678  if (gen_sig_ckpt4.was_set()) {
679  if ((ret=sig.WriteMD5(gen_sig_ckpt4.get_value()))) {
680  cerr << "ERROR (ret=" << ret << ") when writting ckpt 4 MD5 Signature to file: "
681  << gen_sig_ckpt4.get_value() << endl;
682  main_ret = 2;
683  }
684  }
685  }
686 
687  typedef std::list<TPZAutoPointer<TPZDohrSubstructCondense<STATE> > > subtype;
688  const subtype &sublist = dohrptr->SubStructures();
689  subtype::const_iterator it = sublist.begin();
690  int subcount=0;
691  while (it != sublist.end()) {
692 
693  TPZFMatrix<STATE> subext,subu;
694  dohrptr->fAssembly->Extract(subcount,diag,subext);
695  (*it)->UGlobal(subext,subu);
696  TPZCompMesh *submesh = SubMesh(cmeshauto, subcount);
697  submesh->LoadSolution(subu);
698 
699  //ViscoElastico
700  //Atualizando memoria do material
701  std::map<int ,TPZMaterial * > materialmap(submesh->MaterialVec());
702  std::map<int ,TPZMaterial * >::iterator itmat;
703  for (itmat = materialmap.begin(); itmat != materialmap.end() ; itmat++)
704  {
705  TPZMaterial * mat = itmat->second;
706  TPZViscoelastic *vmat = dynamic_cast< TPZViscoelastic *> (mat);
707  if(vmat)
708  {
709  DebugStop(); // Should never enter because it is using elasticity
710  vmat->SetUpdateMem(true);
711  }
712  }
713  subcount++;
714  it++;
715  }
716 
717 #ifdef LOG4CXX
718  {
719  std::stringstream sout;
720  diag.Print("Resultado do processo iterativo",sout);
721  LOGPZ_INFO(loggerconverge,sout.str())
722  }
723 #endif
724 
725  TPZMaterial * mat = cmeshauto->FindMaterial(1);
726  int nstate = mat->NStateVariables();
727  int nscal = 0, nvec = 0;
728  if(nstate ==1)
729  {
730  nscal = 1;
731  }
732  else
733  {
734  nvec = 1;
735  }
736  TPZManVector<std::string> scalnames(nscal),vecnames(nvec);
737  if(nscal == 1)
738  {
739  scalnames[0]="state";
740  }
741  else
742  {
743  vecnames[0] = "state";
744  }
745  std::string postprocessname("dohrmann_visco.vtk"); // Remember it is not viscoelastic, just elastic!
746  TPZVTKGraphMesh vtkmesh(cmeshauto.operator->(),dim,mat,scalnames,vecnames);
747  vtkmesh.SetFileName(postprocessname);
748  vtkmesh.SetResolution(1);
749  int numcases = 1;
750 
751 
752  // Iteracoes de tempo
753  int istep = 0;
754  vtkmesh.DrawMesh(numcases);
755  vtkmesh.DrawSolution(istep, 1.);
756  }
757 
758  PERF_STOP(total_rst);
759 
760  cout << " -- Execution Data -- " << endl;
761  cout << "Input : ";
762  if (mc.was_set())
763  {
764  cout << mc.get_value() << endl;
765  } else {
766  cout << mp.get_value() << endl;
767  }
768  cout << "Nsub : " << nsub.get_value() << endl;
769  cout << "Equations (cmeshauto->NEquations) : " << cmeshauto->NEquations() << endl;
770  cout << "Corner Equations : " << dohrstruct->NumberCornerEqs() << endl;
771  cout << "Equations (dohr->Rows) : " << neq << endl;
772  cout << "Iterations (CG) : " << iterations << endl;
773 
774  if (gmesh != NULL) delete gmesh;
775 
776  return main_ret;
777 }
778 
780 {
781  mesh->SetDimModel(3);
782  int nummat = 1;
783  STATE E = 1.e6;
784  STATE poisson = 0.3;
785  TPZManVector<STATE> force(3,0.);
786  force[1] = 20.;
787  TPZElasticity3D *elast = new TPZElasticity3D(nummat,E,poisson,force);
788  TPZMaterial * elastauto(elast);
789  TPZFMatrix<STATE> val1(3,3,0.),val2(3,1,0.);
790  TPZBndCond *bc = elast->CreateBC(elastauto, -1, 0, val1, val2);
791  TPZMaterial * bcauto(bc);
792  mesh->InsertMaterialObject(elastauto);
793  mesh->InsertMaterialObject(bcauto);
794 }
795 
797 {
798  mesh->SetDimModel(3);
799  int nummat = 1;
800  TPZManVector<STATE> force(3,0.);
801  force[1] = 20.;
802  STATE ElaE = 1000., poissonE = 0.2, ElaV = 100., poissonV = 0.1;
803 
804  STATE lambdaV = 0, muV = 0, alpha = 0, deltaT = 0;
805  lambdaV = 11.3636;
806  muV = 45.4545;
807  alpha = 1.;
808  deltaT = 0.01;
809 
810  TPZViscoelastic *viscoelast = new TPZViscoelastic(nummat);
811  viscoelast->SetMaterialDataHooke(ElaE, poissonE, ElaV, poissonV, alpha, deltaT, force);
812 
813  TPZMaterial * viscoelastauto(viscoelast);
814  TPZFMatrix<STATE> val1(3,3,0.),val2(3,1,0.);
815  TPZBndCond *bc = viscoelast->CreateBC(viscoelastauto, -1, 0, val1, val2);
816  TPZFNMatrix<6,STATE> qsi(6,1,0.);
817  viscoelast->SetDefaultMem(qsi); //elast
818  viscoelast->PushMemItem(); //elast
819  TPZMaterial * bcauto(bc);
820  mesh->InsertMaterialObject(viscoelastauto);
821  mesh->InsertMaterialObject(bcauto);
822 }
823 
825 {
826  mesh->SetDimModel(3);
827  int nummat = 1, neumann = 1, mixed = 2;
828  // int dirichlet = 0;
829  int dir1 = -1, dir2 = -2, dir3 = -3, neumann1 = -4., neumann2 = -5;
830  TPZManVector<STATE> force(3,0.);
831  //force[1] = 0.;
832  REAL Ela = 1000., poisson = 0.;
833  REAL lambdaV = 0, muV = 0, alphaT = 0;
834  lambdaV = 11.3636;
835  muV = 45.4545;
836  alphaT = 0.01;
837 
838 
839  //TPZViscoelastic *viscoelast = new TPZViscoelastic(nummat, Ela, poisson, lambdaV, muV, alphaT, force);
840  TPZElasticity3D *elast = new TPZElasticity3D(nummat, Ela, poisson, force);
841 
842  TPZFNMatrix<6> qsi(6,1,0.);
843  //viscoelast->SetDefaultMem(qsi); //elast
844  //int index = viscoelast->PushMemItem(); //elast
845  TPZMaterial * elastauto(elast);
846  mesh->InsertMaterialObject(elastauto);
847 
848  // Neumann em x = 1;
849  TPZFMatrix<STATE> val1(3,3,0.),val2(3,1,0.);
850  val2(0,0) = 1.;
851  TPZBndCond *bc4 = elast->CreateBC(elastauto, neumann1, neumann, val1, val2);
852  TPZMaterial * bcauto4(bc4);
853  mesh->InsertMaterialObject(bcauto4);
854 
855  // Neumann em x = -1;
856  val2(0,0) = -1.;
857  TPZBndCond *bc5 = elast->CreateBC(elastauto, neumann2, neumann, val1, val2);
858  TPZMaterial * bcauto5(bc5);
859  mesh->InsertMaterialObject(bcauto5);
860 
861  val2.Zero();
862  // Dirichlet em -1 -1 -1 xyz;
863  val1(0,0) = 1.e4;
864  val1(1,1) = 1.e4;
865  val1(2,2) = 1.e4;
866  TPZBndCond *bc1 = elast->CreateBC(elastauto, dir1, mixed, val1, val2);
867  TPZMaterial * bcauto1(bc1);
868  mesh->InsertMaterialObject(bcauto1);
869 
870  // Dirichlet em 1 -1 -1 yz;
871  val1(0,0) = 0.;
872  val1(1,1) = 1.e4;
873  val1(2,2) = 1.e4;
874  TPZBndCond *bc2 = elast->CreateBC(elastauto, dir2, mixed, val1, val2);
875  TPZMaterial * bcauto2(bc2);
876  mesh->InsertMaterialObject(bcauto2);
877 
878  // Dirichlet em 1 1 -1 z;
879  val1(0,0) = 0.;
880  val1(1,1) = 0.;
881  val1(2,2) = 1.e4;
882  TPZBndCond *bc3 = elast->CreateBC(elastauto, dir3, mixed, val1, val2);
883  TPZMaterial * bcauto3(bc3);
884  mesh->InsertMaterialObject(bcauto3);
885 }
886 
888 {
889  //int nBCs = 1;
890  int numnodes=-1;
891  int numelements=-1;
892 
893  string FileName = mp.get_value();
894  {
895  bool countnodes = false;
896  bool countelements = false;
897 
898  ifstream read (FileName.c_str());
899  if (!read.is_open()) {
900  cerr << "Could not open file: " << FileName << endl;
901  exit(1);
902  }
903 
904  while(read)
905  {
906  char buf[1024];
907  read.getline(buf, 1024);
908  std::string str(buf);
909  if(str == "Coordinates") countnodes = true;
910  if(str == "end coordinates") countnodes = false;
911  if(countnodes) numnodes++;
912 
913  if(str == "Elements") countelements = true;
914  if(str == "end elements") countelements = false;
915  if(countelements) numelements++;
916  }
917  }
918 
919  TPZGeoMesh * gMesh = new TPZGeoMesh;
920 
921  gMesh -> NodeVec().Resize(numnodes);
922 
923  TPZVec <int64_t> TopolTetra(4);
924 
925  const int Qnodes = numnodes;
926  TPZVec <TPZGeoNode> Node(Qnodes);
927 
928  //setting nodes coords
929  int64_t nodeId = 0, elementId = 0, matElId = 1;
930 
931  ifstream read;
932  read.open(FileName.c_str());
933 
934  double nodecoordX , nodecoordY , nodecoordZ ;
935 
936  char buf[1024];
937  read.getline(buf, 1024);
938  read.getline(buf, 1024);
939  std::string str(buf);
940  int in;
941  for(in=0; in<numnodes; in++)
942  {
943  read >> nodeId;
944  read >> nodecoordX;
945  read >> nodecoordY;
946  read >> nodecoordZ;
947  Node[nodeId-1].SetNodeId(nodeId);
948  Node[nodeId-1].SetCoord(0,nodecoordX);
949  Node[nodeId-1].SetCoord(1,nodecoordY);
950  Node[nodeId-1].SetCoord(2,nodecoordZ);
951  gMesh->NodeVec()[nodeId-1] = Node[nodeId-1];
952  }
953 
954  {
955  read.close();
956  read.open(FileName.c_str());
957 
958  int l , m = numnodes+5;
959  for(l=0; l<m; l++)
960  {
961  read.getline(buf, 1024);
962  }
963 
964  int el;
965  int matBCid = -1;
966  //std::set<int> ncoordz; //jeitoCaju
967  for(el=0; el<numelements; el++)
968  {
969  read >> elementId;
970  read >> TopolTetra[0]; //node 1
971  read >> TopolTetra[1]; //node 2
972  read >> TopolTetra[2]; //node 3
973  read >> TopolTetra[3]; //node 4
974 
975  // O GID comeca com 1 na contagem dos nodes, e nao zero como no PZ, assim o node 1 na verdade é o node 0
976  TopolTetra[0]--;
977  TopolTetra[1]--;
978  TopolTetra[2]--;
979  TopolTetra[3]--;
980 
981  int index = el;
982 
983  new TPZGeoElRefPattern< pzgeom::TPZGeoTetrahedra> (index, TopolTetra, matElId, *gMesh);
984  }
985 
986  gMesh->BuildConnectivity();
987  // Colocando as condicoes de contorno
988 
989  for(el=0; el<numelements; el++)
990  {
991  TPZManVector <TPZGeoNode,4> Nodefinder(4);
992  TPZManVector <REAL,3> nodecoord(3);
993  TPZGeoEl *tetra = gMesh->ElementVec()[el];
994  // na face z = 0
995  TPZVec<int64_t> ncoordzVec(0); int64_t sizeOfVec = 0;
996  for (int i = 0; i < 4; i++)
997  {
998  int64_t pos = tetra->NodeIndex(i);
999  Nodefinder[i] = gMesh->NodeVec()[pos];
1000  Nodefinder[i].GetCoordinates(nodecoord);
1001  if (nodecoord[2] == 0.)
1002  {
1003  sizeOfVec++;
1004  ncoordzVec.Resize(sizeOfVec);
1005  ncoordzVec[sizeOfVec-1] = pos;
1006  }
1007  }
1008  if(ncoordzVec.NElements() == 3)
1009  {
1010  int lado = tetra->WhichSide(ncoordzVec);
1011  TPZGeoElSide tetraSide(tetra, lado);
1012  TPZGeoElBC(tetraSide,matBCid);
1013  }
1014  }
1015  }
1016 
1017 
1018  ofstream arg("malhaPZ.txt");
1019  gMesh->Print(arg);
1020  ofstream predio("GeoPredio.vtk");
1021  TPZVTKGeoMesh::PrintGMeshVTK(gMesh,predio,true);
1022 
1023  return gMesh;
1024 }
1025 
1027 {
1028  int numnodes=-1;
1029  int numelements=-1;
1030 
1031  string FileName = mc.get_value();
1032  {
1033  bool countnodes = false;
1034  bool countelements = false;
1035 
1036  ifstream read (FileName.c_str());
1037  if (!read.is_open()) {
1038  cerr << "Could not open file: " << FileName << endl;
1039  exit(1);
1040  }
1041 
1042  while(read)
1043  {
1044  char buf[1024];
1045  read.getline(buf, 1024);
1046  std::string str(buf);
1047  if(str == "Coordinates") countnodes = true;
1048  if(str == "end coordinates") countnodes = false;
1049  if(countnodes) numnodes++;
1050 
1051  if(str == "Elements") countelements = true;
1052  if(str == "end elements") countelements = false;
1053  if(countelements) numelements++;
1054  }
1055  }
1056 
1057  TPZGeoMesh * gMesh = new TPZGeoMesh;
1058 
1059  gMesh -> NodeVec().Resize(numnodes);
1060 
1061  TPZManVector <int64_t> TopolTetra(4);
1062 
1063  const int Qnodes = numnodes;
1064  TPZVec <TPZGeoNode> Node(Qnodes);
1065 
1066  //setting nodes coords
1067  int64_t nodeId = 0, elementId = 0, matElId = 1;
1068 
1069  ifstream read;
1070  read.open(FileName.c_str());
1071 
1072  double nodecoordX , nodecoordY , nodecoordZ ;
1073 
1074  char buf[1024];
1075  read.getline(buf, 1024);
1076  read.getline(buf, 1024);
1077  std::string str(buf);
1078  int in;
1079  for(in=0; in<numnodes; in++)
1080  {
1081  read >> nodeId;
1082  read >> nodecoordX;
1083  read >> nodecoordY;
1084  read >> nodecoordZ;
1085  Node[nodeId-1].SetNodeId(nodeId);
1086  Node[nodeId-1].SetCoord(0,nodecoordX);
1087  Node[nodeId-1].SetCoord(1,nodecoordY);
1088  Node[nodeId-1].SetCoord(2,nodecoordZ);
1089  gMesh->NodeVec()[nodeId-1] = Node[nodeId-1];
1090  }
1091 
1092  {
1093  read.close();
1094  read.open(FileName.c_str());
1095 
1096  int l , m = numnodes+5;
1097  for(l=0; l<m; l++)
1098  {
1099  read.getline(buf, 1024);
1100  }
1101 
1102 
1103  int el;
1104  int neumann1 = -4, neumann2 = -5;
1105  //std::set<int> ncoordz; //jeitoCaju
1106  for(el=0; el<numelements; el++)
1107  {
1108  read >> elementId;
1109  read >> TopolTetra[0]; //node 1
1110  read >> TopolTetra[1]; //node 2
1111  read >> TopolTetra[2]; //node 3
1112  read >> TopolTetra[3]; //node 4
1113 
1114  // O GID comeca com 1 na contagem dos nodes, e nao zero como no PZ, assim o node 1 na verdade é o node 0
1115  TopolTetra[0]--;
1116  TopolTetra[1]--;
1117  TopolTetra[2]--;
1118  TopolTetra[3]--;
1119 
1120  int64_t index = el;
1121 
1122  new TPZGeoElRefPattern< pzgeom::TPZGeoTetrahedra> (index, TopolTetra, matElId, *gMesh);
1123  }
1124 
1125  gMesh->BuildConnectivity();
1126 
1127  // Colocando as condicoes de contorno
1128  for(el=0; el<numelements; el++)
1129  {
1130  TPZManVector <TPZGeoNode,4> Nodefinder(4);
1131  TPZManVector <REAL,3> nodecoord(3);
1132  TPZGeoEl *tetra = gMesh->ElementVec()[el];
1133 
1134  // na face x = 1
1135  TPZVec<int64_t> ncoordzVec(0); int64_t sizeOfVec = 0;
1136  for (int i = 0; i < 4; i++)
1137  {
1138  int64_t pos = tetra->NodeIndex(i);
1139  Nodefinder[i] = gMesh->NodeVec()[pos];
1140  Nodefinder[i].GetCoordinates(nodecoord);
1141  if (nodecoord[0] == 1.)
1142  {
1143  sizeOfVec++;
1144  ncoordzVec.Resize(sizeOfVec);
1145  ncoordzVec[sizeOfVec-1] = pos;
1146  }
1147  }
1148  if(ncoordzVec.NElements() == 3)
1149  {
1150  int lado = tetra->WhichSide(ncoordzVec);
1151  TPZGeoElSide tetraSide(tetra, lado);
1152  TPZGeoElBC(tetraSide,neumann1);
1153  }
1154 
1155  // Na face x = -1
1156  ncoordzVec.Resize(0);
1157  sizeOfVec = 0;
1158  for (int i = 0; i < 4; i++)
1159  {
1160  int64_t pos = tetra->NodeIndex(i);
1161  Nodefinder[i] = gMesh->NodeVec()[pos];
1162 
1163  Nodefinder[i].GetCoordinates(nodecoord);
1164  if (nodecoord[0] == -1.)
1165  {
1166  sizeOfVec++;
1167  ncoordzVec.Resize(sizeOfVec);
1168  ncoordzVec[sizeOfVec-1] = pos;
1169  }
1170  }
1171  if(ncoordzVec.NElements() == 3)
1172  {
1173  int lado = tetra->WhichSide(ncoordzVec);
1174  TPZGeoElSide tetraSide(tetra, lado);
1175  TPZGeoElBC(tetraSide,neumann2);
1176  }
1177 
1178  }
1179 
1180  TPZVec <REAL> xyz(3,-1.), yz(3,-1.), z(3,1.);
1181  yz[0] = 1.;
1182  z[2] = -1;
1183  int bcidxyz = -1, bcidyz = -2, bcidz = -3;
1184  SetPointBC(gMesh, xyz, bcidxyz);
1185  SetPointBC(gMesh, yz, bcidyz);
1186  SetPointBC(gMesh, z, bcidz);
1187 
1188  }
1189 
1190  /* refine mesh */
1191  if (refin.was_set()) {
1192 
1193  int nh = refin.get_value();
1194 
1195  for ( int ref = 0; ref < nh; ref++ ){
1196  TPZVec<TPZGeoEl *> filhos;
1197  int n = gMesh->NElements();
1198  for ( int i = 0; i < n; i++ ){
1199  TPZGeoEl * gel = gMesh->ElementVec() [i];
1200 
1201  if(!gel) continue;
1202  if(gel->Dimension() < 1) continue;
1203  if(gel->HasSubElement()) continue;
1204 
1205  gel->Divide (filhos);
1206  }
1207  }
1208  }
1209 
1210  ofstream arg("malhaPZ1BC.txt");
1211  gMesh->Print(arg);
1212 
1213  std::ofstream out("Cube.vtk");
1214  TPZVTKGeoMesh::PrintGMeshVTK(gMesh, out, true);
1215 
1216  return gMesh;
1217 }
1218 
1220 void SetPointBC(TPZGeoMesh *gr, TPZVec<REAL> &x, int bc)
1221 {
1222  // look for an element/corner node whose distance is close to start
1223  TPZGeoNode *gn1 = gr->FindNode(x);
1224  int64_t iel;
1225  int64_t nelem = gr->ElementVec().NElements();
1226  TPZGeoEl *gel;
1227  for (iel = 0; iel<nelem; iel++) {
1228  gel = gr->ElementVec()[iel];
1229  if(!gel) continue;
1230  int nc = gel->NCornerNodes();
1231  int c;
1232  for (c=0; c<nc; c++) {
1233  TPZGeoNode *gn = gel->NodePtr(c);
1234  if (gn == gn1) {
1235  break;
1236  }
1237  }
1238  if (c<nc) {
1239  TPZGeoElBC(gel, c, bc);
1240  return;
1241  }
1242  }
1243 }
1244 
1245 REAL Height(TPZGeoMesh *gmesh)
1246 {
1247  TPZAdmChunkVector<TPZGeoNode> &nodevec = gmesh->NodeVec();
1248  int64_t nnodes = nodevec.NElements();
1249  int64_t in;
1250  REAL maxz = 0.;
1251  for (in=0; in<nnodes; in++) {
1252  REAL z = nodevec[in].Coord(2);
1253  maxz = (maxz < z) ? z : maxz;
1254  }
1255  return maxz;
1256 }
1257 
1259 {
1260  int nelem = cmesh->NElements();
1261  TPZManVector<int> subindex(nelem,-1);
1262  int iel;
1263  int nsub = 0;
1264  for (iel=0; iel<nelem; iel++)
1265  {
1266  TPZCompEl *cel = cmesh->ElementVec()[iel];
1267  if (!cel) {
1268  continue;
1269  }
1270  TPZGeoEl *gel = cel->Reference();
1271  if (!gel) {
1272  continue;
1273  }
1274  int nsides = gel->NSides();
1275  TPZManVector<REAL> center(gel->Dimension(),0.), xco(3,0.);
1276  gel->CenterPoint(nsides-1,center);
1277  gel->X(center,xco);
1278  REAL z = xco[2];
1279  int floor = (int) z/height;
1280  nsub = (floor+1) > nsub ? (floor+1) : nsub;
1281  subindex[iel] = floor;
1282  }
1283 
1284 #ifdef PZDEBUG
1285  {
1286  TPZGeoMesh *gmesh = cmesh->Reference();
1287  int nelgeo = gmesh->NElements();
1288  TPZVec<int> domaincolor(nelgeo,-999);
1289  int cel;
1290  int nel = cmesh->NElements();
1291  for (cel=0; cel<nel; cel++) {
1292  TPZCompEl *compel = cmesh->ElementVec()[cel];
1293  if(!compel) continue;
1294  TPZGeoEl *gel = compel->Reference();
1295  if (!gel) {
1296  continue;
1297  }
1298  domaincolor[gel->Index()] = subindex[cel];
1299  }
1300  ofstream vtkfile("partition.vtk");
1301  TPZVTKGeoMesh::PrintGMeshVTK(gmesh, vtkfile, domaincolor);
1302  }
1303 #endif
1304 
1305  int isub;
1306  TPZManVector<TPZSubCompMesh *> submeshes(nsub,0);
1307  for (isub=0; isub<nsub; isub++)
1308  {
1309  int64_t index;
1310  std::cout << '^'; std::cout.flush();
1311  submeshes[isub] = new TPZSubCompMesh(cmesh,index);
1312 
1313  if (index < subindex.NElements())
1314  {
1315  subindex[index] = -1;
1316  }
1317  }
1318  for (iel=0; iel<nelem; iel++)
1319  {
1320  int domindex = subindex[iel];
1321  if (domindex >= 0)
1322  {
1323  TPZCompEl *cel = cmesh->ElementVec()[iel];
1324  if (!cel)
1325  {
1326  continue;
1327  }
1328  submeshes[domindex]->TransferElement(cmesh.operator->(),iel);
1329  }
1330  }
1331  cmesh->ComputeNodElCon();
1332  for (isub=0; isub<nsub; isub++)
1333  {
1334  submeshes[isub]->MakeAllInternal();
1335  std::cout << '*'; std::cout.flush();
1336  }
1337 
1338  cmesh->ComputeNodElCon();
1339  cmesh->CleanUpUnconnectedNodes();
1340  return nsub;
1341 }
int64_t NElements() const
Number of computational elements allocated.
Definition: pzcmesh.h:169
Contains a class to record running statistics on CSV tables.
RunStatsTable assemble_rst("-ass_rdt", "Assemble statistics raw data table (step 3)")
TPZGeoMesh * Reference() const
Returns a pointer to the geometrical mesh associated.
Definition: pzcmesh.h:209
void Extract(int isub, const TPZFMatrix< TVar > &global, TPZFMatrix< TVar > &local) const
Extract the values from the global matrix into the local matrix.
clarg::argInt nt_a("-nt_a", "Pair (l2): number of threads to assemble each submesh (multiply by nt_sm)", 0)
clarg::argString cf2("-cf2", "starts execution from checkpoint 2 (read checkpoint file)", "ckpt2.ckpt")
static void SetgOrder(int order)
Sets the value of the default interpolation order.
Definition: pzcompel.h:825
TPZGeoNode * NodePtr(int i) const
Returns a pointer to the ith node of the element.
Definition: pzgeoel.cpp:2566
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.
Contains declaration of the TPZMD5Stream class which implements the interface to write and check md5 ...
Implements a vector class which allows to use external storage provided by the user. Utility.
Definition: pzquad.h:16
void Write(TPZStream &buf, int withclassid) const override
Packs the object structure in a stream of bytes.
Definition: pzmatrix.cpp:1420
RunStatsTable total_rst("-tot_rdt", "Whole program (total) statistics raw data table")
clarg::argBool bc("-bc", "binary checkpoints", false)
RunStatsTable create_rst("-cre_rdt", "Create statistics raw data table (step 2)")
Contains the TPZDohrSubstruct class which implements sub structure matrices using Dohrman algorithm...
void values(ostream &os, bool defined_only)
Definition: arglib.cpp:183
int main(int argc, char *argv[])
Definition: substruct.cpp:219
void OpenRead(const std::string &fn)
Definition: substruct.cpp:182
clarg::argInt nsub("-nsub", "number of substructs", 4)
int64_t NEquations()
This computes the number of equations associated with non-restrained nodes.
Definition: pzcmesh.cpp:721
clarg::argInt verb_level("-v", "verbosity level", 0)
Contains the TPZVTKGraphMesh class which implements the graphical mesh to VTK environment.
Contains declaration of TPZCompEl class which defines the interface of a computational element...
TPZGeoMesh * MalhaPredio()
Definition: substruct.cpp:887
static TPZSubCompMesh * SubMesh(TPZAutoPointer< TPZCompMesh > compmesh, int isub)
return a pointer to the isub submesh
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzgmesh.cpp:1505
Defines step solvers class. Solver.
Definition: pzmganalysis.h:17
virtual int NCornerNodes() const =0
Returns the number of corner nodes of the element.
This class implements a 3D isotropic elasticity material.
Definition: pzelast3d.h:21
Contains the TPZDohrMatrix class which implements a matrix divided into substructures. Also contains the TPZDohrThreadMultData and TPZDohrThreadMultList structs.
To export a graphical mesh to VTK environment. Post processing.
Definition: pzvtkmesh.h:19
int64_t NElements() const
Number of elements of the mesh.
Definition: pzgmesh.h:129
virtual int NStateVariables() const =0
Returns the number of state variables associated with the material.
clarg::argBool pair_tbb("-pair_tbb", "assemble TPZPairStructMatrix (level 2) using TBB", false)
Utility class which represents an element with its side. The Geometric approximation classes Geometry...
Definition: pzgeoelside.h:83
clarg::argString chk_sig_ckpt4("-chk_c4_md5", "compute MD5 signature for checkpoint 4 and check against MD5 at file.", "ckpt4.md5")
Contains declaration of TPZGeoElBC class, it is a structure to help the construction of geometric ele...
virtual void SetDefaultMem(TMEM &defaultMem)
Sets the default memory settings for initialization.
int64_t NElements() const
Access method to query the number of elements of the vector.
void OpenWrite(const std::string &fn)
Definition: substruct.cpp:174
clarg::argString cf3("-cf3", "starts execution from checkpoint 3 (read checkpoint file)", "ckpt3.ckpt")
clarg::argBool dohr_tbb("-dohr_tbb", "assemble TPZDohrStructMatrix (level 1) using TBB", false)
REAL GetTolerance() const
return the value of tolerance from the solver
Definition: pzstepsolver.h:57
virtual int NSides() const =0
Returns the number of connectivities of the element.
void SetPointBC(TPZGeoMesh *gr, TPZVec< REAL > &x, int bc)
Generate a boundary geometric element at the indicated node.
Definition: substruct.cpp:1220
virtual void Divide(TPZVec< TPZGeoEl *> &pv)
Divides the element and puts the resulting elements in the vector.
Definition: pzgeoel.h:742
Implements a matrix divided into substructures. Matrix Sub structure.
Definition: tpzdohrmatrix.h:30
virtual int64_t NodeIndex(int i) const =0
Returns the index of the ith node the index is the location of the node in the nodevector of the mesh...
Contains the TPZDohrAssembly class which implements assembling using Dohrmann algorithm.
TPZGeoMesh * MalhaCubo()
Definition: substruct.cpp:1026
clarg::argBool st1("-st1", "stop at checkpoint 1 (after dump)", false)
#define PERF_START(obj)
Definition: substruct.cpp:163
clarg::argInt refin("-ref", "refine mesh", 1)
static TPZGraphNode gn
Definition: pzgraphmesh.cpp:76
int WhichSide(TPZVec< int64_t > &SideNodeIds)
Returns the side number which is connected to the SideNodes returns -1 if no side is found...
Definition: pzgeoel.cpp:165
Contains the TPZDohrStructMatrix class which implements structural matrix divided in sub structures...
const int bc3
Definition: main.cpp:88
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
void Read(TPZStream &buf, void *context) override
read objects from the stream
Definition: pzgmesh.cpp:1487
clarg::argBool h("-h", "help message", false)
fn
Definition: test.py:253
clarg::argString gen_sig_ckpt1("-gen_c1_md5", "generates MD5 signature for checkpoint 1 and dump into file.", "ckpt1.md5")
RunStatsTable precond_rst("-pre_rdt", "Precond statistics raw data table (step 3)")
TPZGeoNode * FindNode(TPZVec< REAL > &co)
Returns the nearest node to the coordinate. This method is VERY INEFFICIENT.
Definition: pzgmesh.cpp:419
Contains the TPZElasticity3D class which implements a 3D isotropic elasticity material.
Contains the TPZFStructMatrix class which implements Full Structural Matrices.
const int bc4
Definition: main.cpp:89
void SetDefaultOrder(int order)
Definition: pzcmesh.h:403
clarg::argInt maxlevel("-maxlevel", "maxlevel???", 5)
This abstract class defines the behaviour which each derived class needs to implement.
Definition: TPZMaterial.h:39
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...
Contains the TPZBndCond class which implements a boundary condition for TPZMaterial objects...
clarg::argInt plevel("-p", "plevel", 1)
int NumberCornerEqs() const
Return the number of cornereqs.
clarg::argString dc3("-dc3", "dump checkpoint 3 to file", "ckpt3.ckpt")
int Zero() override
Makes Zero all the elements.
Definition: pzfmatrix.h:651
clarg::argString mp("-mp", "starts execution from beginning - read a \alha_predio\input file", "../8andares02.txt")
TPZAutoPointer< TPZMatrix< STATE > > Preconditioner()
This will return the pointer to the preconditioner AND abandon the pointer.
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
Contains the TPZGenSubStruct class which is an interface to "feed" the datastructure of the Dohrmann ...
#define VERBOSE(level,...)
int CheckMD5(const std::string &filename)
Check Stream MD5 signature against MD5 signature store on file.
Definition: pzmd5stream.h:65
void AssembleTBB(TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
void LoadSolution(const TPZFMatrix< STATE > &sol)
Given the solution of the global system of equations, computes and stores the solution for the restri...
Definition: pzcmesh.cpp:441
void Write(TPZStream &str, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
void SetCG(const int64_t numiterations, const TPZMatrixSolver< TVar > &pre, const REAL tol, const int64_t FromCurrent)
clarg::argInt dim_arg("-dim", "dim???", 3)
clarg::argString dc2("-dc2", "dump checkpoint 2 to file", "ckpt2.ckpt")
#define LOGPZ_INFO(A, B)
Define log for informations.
Definition: pzlog.h:89
Implements reading from and writing to an ascii file. Persistency.
Definition: TPZFileStream.h:15
virtual void Print(std::ostream &out=std::cout) const
Print the information of the grid to an ostream.
Definition: pzgmesh.cpp:130
Implements a generic geometric element which is refined according to a generic refinement pattern...
Definition: pzgmesh.h:35
Defines the behaviour of all geometric elements. GeometryTPZGeoEl is the common denominator for all g...
Definition: pzgeoel.h:43
void InsertElasticity(TPZAutoPointer< TPZCompMesh > mesh)
Definition: substruct.cpp:779
clarg::argString gen_sig_ckpt3("-gen_c3_md5", "generates MD5 signature for checkpoint 3 and dump into file.", "ckpt3.md5")
clarg::argInt sublevel("-sublevel", "sublevel???", 3)
#define PERF_STOP(obj)
Definition: substruct.cpp:164
int64_t Index() const
Returns the index of the element within the element vector of the mesh.
Definition: pzgeoel.h:730
Contains the TPZGeoTetrahedra class which implements the geometry of a tetrahedral element...
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
void Read(TPZStream &buf, void *context) override
Read the element data from a stream.
Definition: pzcmesh.cpp:2006
clarg::argString chk_sig_ckpt2("-chk_c2_md5", "compute MD5 signature for checkpoint 2 and check against MD5 at file.", "ckpt2.md5")
clarg::argInt nt_sm("-nt_sm", "Dohr (l1): number of threads to process the submeshes", 0)
int parse_arguments(int argc, char *argv[])
Definition: arglib.cpp:195
virtual void SetNumThreads(int n)
def read(filename)
Definition: stats.py:13
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
Definition: pzlog.h:87
This class defines the boundary condition for TPZMaterial objects.
Definition: pzbndcond.h:29
Contains the TPZSkylineStructMatrix class which implements SkyLine Structural Matrices.
virtual void SetUpdateMem(bool update=1)
Sets/Unsets the internal memory data to be updated in the next assemble/contribute call...
RunStatsTable solve_rst("-sol_rdt", "Solver statistics raw data table (step 4)")
int Dimension() const
Returns the dimension of the simulation.
Definition: pzcmesh.h:148
clarg::argBool st2("-st2", "stop at checkpoint 2 (after dump)", false)
virtual void ComputeNodElCon()
Compute the number of elements connected to each connect object.
Definition: pzcmesh.cpp:668
virtual int PushMemItem(int sourceIndex=-1) override
Pushes a new entry in the context of materials with memory.
virtual void Assemble(TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface, unsigned numthreads_assemble, unsigned numthreads_decompose) override
Assemble the global system of equations into the matrix which has already been created.
TPZMaterial * FindMaterial(int id)
Find the material with identity id.
Definition: pzcmesh.cpp:297
TPZAdmChunkVector< TPZGeoNode > & NodeVec()
Definition: pzgmesh.h:140
Contains the TPZDohrPrecond class which implements a matrix which computes the preconditioner develop...
virtual void AutoBuild(const std::set< int > *MaterialIDs)
Creates the computational elements, and the degree of freedom nodes.
Definition: pzcmesh.cpp:308
virtual TPZMatrix< STATE > * Create() override
This will create a DohrMatrix.
Contains the TPZPairStructMatrix class.
void IdentifyExternalConnectIndexes()
Identify the external connects.
clarg::argInt num_it("-num_it", "number limit of iterations to the CG solver", 1000)
void Read(TPZStream &buf, void *context) override
Unpacks the object structure from a stream of bytes.
Definition: pzmatrix.cpp:1413
void AddInternalSolution(TPZFMatrix< TVar > &solution)
Add the solution corresponding to the internal residual.
void arguments_descriptions(ostream &os, string prefix, string suffix)
Definition: arglib.cpp:189
static void PrintGMeshVTK(TPZGeoMesh *gmesh, std::ofstream &file, bool matColor=true)
Default constructor for graphical mesh with VTK format.
void help(const char *prg)
Definition: substruct.cpp:86
void Solve(const TPZFMatrix< TVar > &F, TPZFMatrix< TVar > &result, TPZFMatrix< TVar > *residual=0) override
Solves the system of linear equations.
void InsertElasticityCubo(TPZAutoPointer< TPZCompMesh > mesh)
Definition: substruct.cpp:824
void SetDimModel(int dim)
Set de dimension of the domain of the problem.
Definition: pzcmesh.h:139
void InsertViscoElasticity(TPZAutoPointer< TPZCompMesh > mesh)
Definition: substruct.cpp:796
std::map< int,TPZMaterial *> & MaterialVec()
Returns a reference to the material pointers vector.
Definition: pzcmesh.h:203
clarg::argString chk_sig_ckpt1("-chk_c1_md5", "compute MD5 signature for checkpoint 1 and check against MD5 at file.", "ckpt1.md5")
virtual int HasSubElement() const =0
Return 1 if the element has subelements.
virtual void SetFileName(const std::string &filename)
Sets the filename to output of graph.
clarg::argInt nt_multiply("-nt_m", "number of threads to multiply", 0)
Implements Full Structural Matrices. Structural Matrix.
Definition: pzfstrmatrix.h:19
Structure to help the construction of geometric elements along side of a given geometric element...
Definition: pzgeoelbc.h:21
void BuildConnectivity()
Build the connectivity of the grid.
Definition: pzgmesh.cpp:967
virtual TPZBndCond * CreateBC(TPZMaterial *reference, int id, int typ, TPZFMatrix< STATE > &val1, TPZFMatrix< STATE > &val2)
Creates an object TPZBndCond derived of TPZMaterial.
int InsertMaterialObject(TPZMaterial *mat)
Insert a material object in the datastructure.
Definition: pzcmesh.cpp:287
int WriteMD5(const std::string &filename)
Write computed MD5 signature to file.
Definition: pzmd5stream.h:121
void InitializePZLOG()
Initializes log file for log4cxx with commom name log4cxx.cfg.
Definition: pzlog.cpp:14
virtual void CleanUpUnconnectedNodes()
Delete the nodes which have no elements connected to them.
Definition: pzcmesh.cpp:498
virtual int Dimension() const =0
Returns the dimension of the element.
Contains the TPZArc3D class which implements three dimensional arc.
int NumIterations()
Number of iterations of last solve.
Definition: pzstepsolver.h:98
TPZGeoEl * Reference() const
Return a pointer to the corresponding geometric element if such exists, return 0 otherwise.
Definition: pzcompel.cpp:1137
Implements a geometric node in the pz environment. Geometry.
Definition: pzgnode.h:31
const SubsList & SubStructures() const
Definition: tpzdohrmatrix.h:64
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...
This class implements a geometric mesh for the pz environment. Geometry.
Definition: pzgmesh.h:48
This class implements an isotropic viscoelasticity material.
int verbose
Definition: decompose.cpp:67
bool was_set() const
Definition: arglib.h:138
const int bc1
Definition: main.cpp:86
clarg::argString dc1("-dc1", "dump checkpoint 1 to file", "ckpt1.ckpt")
REAL Height(TPZGeoMesh *gmesh)
Definition: substruct.cpp:1245
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
const T & get_value() const
Definition: arglib.h:177
TPZAdmChunkVector< TPZCompEl * > & ElementVec()
Returns a reference to the element pointers vector.
Definition: pzcmesh.h:183
clarg::argInt nt_d("-nt_d", "Dohr (l1): number of threads to decompose each submesh", 0)
clarg::argString gen_sig_ckpt2("-gen_c2_md5", "generates MD5 signature for checkpoint 2 and dump into file.", "ckpt2.md5")
void Write(TPZStream &buf, int withclassid) const override
Packs the object structure in a stream of bytes.
Contains TPZStepSolver class which defines step solvers class.
const int bc2
Definition: main.cpp:87
clarg::argString chk_sig_ckpt3("-chk_c3_md5", "compute MD5 signature for checkpoint 3 and check against MD5 at file.", "ckpt3.md5")
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
clarg::argString cf1("-cf1", "starts execution from checkpoint 1 (read checkpoint file)", "ckpt1.ckpt")
clarg::argBool st3("-st3", "stop at checkpoint 3 (after dump)", false)
#define SAVEABLE_STR_NOTE(buf, str)
Definition: TPZSavable.h:42
clarg::argString m("-m", "input matrix file name (text format)", "matrix.txt")
clarg::argString gen_sig_ckpt4("-gen_c4_md5", "generates MD5 signature for checkpoint 4 and dump into file.", "ckpt4.md5")
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzfmatrix.cpp:2225
Defines the interface of a computational element. Computational Element.
Definition: pzcompel.h:59
Contains the TPZVTKGeoMesh class which implements the graphical mesh to VTK environment to geometric ...
void SetMaterialDataHooke(STATE ElaE, STATE poissonE, STATE ElaV, STATE poissonV, STATE alpha, STATE deltaT, TPZVec< STATE > &force)
Set material Data with hooke constants.
int SubStructure(TPZAutoPointer< TPZCompMesh > cmesh, REAL height)
Definition: substruct.cpp:1258
void Read(TPZStream &str, void *context) override
read objects from the stream
clarg::argString mc("-mc", "starts execution from beginning - read a \alha_cubo\input file", "../cube1.txt")
Implements the interface to write and check MD5 files. Persistency.
Definition: pzmd5stream.h:22
void Write(TPZStream &buf, int withclassid) const override
Save the element data to a stream.
Definition: pzcmesh.cpp:1975
TPZAutoPointer< TPZDohrAssembly< TVar > > fAssembly
Definition: tpzdohrmatrix.h:45
void SubStructure(int nsub)
Partition the mesh in submeshes.
#define SAVEABLE_SKIP_NOTE(buf)
Definition: TPZSavable.h:43
virtual void Print(std::ostream &out=std::cout) const
Prints mesh data.
Definition: pzcmesh.cpp:236
Implements structural matrix divided in sub structures. Structural Matrix Sub structure.
TPZAdmChunkVector< TPZGeoEl * > & ElementVec()
Methods for handling pzlists.
Definition: pzgmesh.h:138