OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
t3dinterface.C
Go to the documentation of this file.
1 /*
2  *
3  * ##### ##### ###### ###### ### ###
4  * ## ## ## ## ## ## ## ### ##
5  * ## ## ## ## #### #### ## # ##
6  * ## ## ## ## ## ## ## ##
7  * ## ## ## ## ## ## ## ##
8  * ##### ##### ## ###### ## ##
9  *
10  *
11  * OOFEM : Object Oriented Finite Element Code
12  *
13  * Copyright (C) 1993 - 2013 Borek Patzak
14  *
15  *
16  *
17  * Czech Technical University, Faculty of Civil Engineering,
18  * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19  *
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  *
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33  */
34 
35 #include "t3dinterface.h"
36 #include "errorestimator.h"
37 #include "domain.h"
38 #include "node.h"
39 #include "element.h"
40 #include "engngm.h"
41 #include "remeshingcrit.h"
42 #include "oofemtxtdatareader.h"
43 #include "dynamicinputrecord.h"
44 
45 #include "crosssection.h"
46 #include "classfactory.h"
47 
48 #include "nonlocalbarrier.h"
49 #include "initialcondition.h"
50 #include "classfactory.h"
51 //#include "loadtimefunction.h"
52 #include "function.h"
53 #include "outputmanager.h"
54 
55 #include <cmath>
56 
57 namespace oofem {
58 REGISTER_Mesher(T3DInterface, MPT_T3D);
59 
60 
62 T3DInterface :: createMesh(TimeStep *tStep, int domainNumber, int domainSerNum, Domain **dNew)
63 {
64  * dNew = NULL;
65  if ( this->createInput(this->domain, tStep) ) {
67  } else {
68  return MI_FAILED;
69  }
70 }
71 
72 int
74 {
75  int nnodes = d->giveNumberOfDofManagers(), nelem = d->giveNumberOfElements();
76  double density;
77  FILE *outputStrem;
78  Node *inode;
79  Element *ielem;
80  int edges, trias, quads, tetras, pyrams, wedges, hexas;
81  IntArray edgeIdArray, triaIdArray, quadIdArray, tetraIdArray, pyramIdArray, wedgeIdArray, hexaIdArray;
82  bool tri_tetra = false;
83  char fileName [ 32 ];
84 
85  edges = trias = quads = tetras = pyrams = wedges = hexas = 0;
86  for ( int i = 1; i <= nelem; i++ ) {
87  ielem = d->giveElement(i);
88  switch ( ielem->giveGeometryType() ) {
89  case EGT_point:
90  break;
91  case EGT_line_1:
92  case EGT_line_2:
93  edges++;
94  break;
95  case EGT_triangle_1:
96  case EGT_triangle_2:
97  trias++;
98  break;
99  case EGT_quad_1:
100  case EGT_quad_2:
101  quads++;
102  break;
103  case EGT_tetra_1:
104  case EGT_tetra_2:
105  tetras++;
106  break;
107  case EGT_wedge_1:
108  case EGT_wedge_2:
109  wedges++;
110  break;
111  case EGT_hexa_1:
112  case EGT_hexa_2:
113  hexas++;
114  break;
115  default:
116  OOFEM_ERROR( "unknown element type (%s)",
118  }
119  }
120 
121  edgeIdArray.resize(edges);
122  triaIdArray.resize(trias);
123  quadIdArray.resize(quads);
124  tetraIdArray.resize(tetras);
125  pyramIdArray.resize(pyrams);
126  wedgeIdArray.resize(wedges);
127  hexaIdArray.resize(hexas);
128 
129  edges = trias = quads = tetras = pyrams = wedges = hexas = 0;
130  for ( int i = 1; i <= nelem; i++ ) {
131  ielem = d->giveElement(i);
132  switch ( ielem->giveGeometryType() ) {
133  case EGT_point:
134  break;
135  case EGT_line_1:
136  case EGT_line_2:
137  edgeIdArray.at(++edges) = i;
138  break;
139  case EGT_triangle_1:
140  case EGT_triangle_2:
141  triaIdArray.at(++trias) = i;
142  break;
143  case EGT_quad_1:
144  case EGT_quad_2:
145  quadIdArray.at(++quads) = i;
146  break;
147  case EGT_tetra_1:
148  case EGT_tetra_2:
149  tetraIdArray.at(++tetras) = i;
150  break;
151  case EGT_wedge_1:
152  case EGT_wedge_2:
153  wedgeIdArray.at(++wedges) = i;
154  break;
155  case EGT_hexa_1:
156  case EGT_hexa_2:
157  hexaIdArray.at(++hexas) = i;
158  break;
159  default:
160  break;
161  }
162  }
163 
164  if ( quads + hexas + pyrams + wedges == 0 ) {
165  tri_tetra = true;
166  }
167 
168  if ( d->giveEngngModel()->isParallel() ) {
169  sprintf( fileName, "%s.%d", BMF_FILENAME, d->giveEngngModel()->giveRank() );
170  } else {
171  sprintf(fileName, "%s", BMF_FILENAME);
172  }
173 
174  outputStrem = fopen(fileName, "w");
175  if ( tri_tetra == true ) {
176  fprintf(outputStrem, "3 1 -1\n");
177  fprintf(outputStrem, "%d %d %d %d\n", nnodes, edges, trias, tetras);
178  } else {
179  fprintf(outputStrem, "7 1 -1\n");
180  fprintf(outputStrem, "%d %d %d %d %d %d %d %d\n", nnodes, edges, trias, quads, tetras, pyrams, wedges, hexas);
181  }
182 
183  // loop over nodes
184  for ( int i = 1; i <= nnodes; i++ ) {
186  inode = d->giveNode(i);
187  fprintf(outputStrem, "%d %e %e %e %e\n", i, inode->giveCoordinate(1), inode->giveCoordinate(2), inode->giveCoordinate(3), density);
188  }
189 
190  // loop separately for each type of element
191  // since T3ds support only linear elements in bg mesh, only corner nodes are stored
192  // alternatively quadratic elements may be splitted to linear (not supported now)
193 
194  if ( edges != 0 ) {
195  for ( int i = 1; i <= edges; i++ ) {
196  ielem = d->giveElement( edgeIdArray.at(i) );
197  fprintf(outputStrem, "%d", i);
198  for ( int j = 1; j <= 2; j++ ) {
199  fprintf( outputStrem, " %d", ielem->giveNode(j)->giveNumber() );
200  }
201 
202  fprintf(outputStrem, "\n");
203  }
204  }
205 
206  if ( trias != 0 ) {
207  for ( int i = 1; i <= trias; i++ ) {
208  ielem = d->giveElement( triaIdArray.at(i) );
209  fprintf(outputStrem, "%d", i);
210  for ( int j = 1; j <= 3; j++ ) {
211  fprintf( outputStrem, " %d", ielem->giveNode(j)->giveNumber() );
212  }
213 
214  fprintf(outputStrem, "\n");
215  }
216  }
217 
218  if ( quads != 0 ) {
219  for ( int i = 1; i <= quads; i++ ) {
220  ielem = d->giveElement( quadIdArray.at(i) );
221  fprintf(outputStrem, "%d", i);
222  for ( int j = 1; j <= 4; j++ ) {
223  fprintf( outputStrem, " %d", ielem->giveNode(j)->giveNumber() );
224  }
225 
226  fprintf(outputStrem, "\n");
227  }
228  }
229 
230  if ( tetras != 0 ) {
231  for ( int i = 1; i <= tetras; i++ ) {
232  ielem = d->giveElement( tetraIdArray.at(i) );
233  fprintf(outputStrem, "%d", i);
234  for ( int j = 1; j <= 4; j++ ) {
235  fprintf( outputStrem, " %d", ielem->giveNode(j)->giveNumber() );
236  }
237 
238  fprintf(outputStrem, "\n");
239  }
240  }
241 
242  if ( pyrams != 0 ) {
243  for ( int i = 1; i <= pyrams; i++ ) {
244  ielem = d->giveElement( pyramIdArray.at(i) );
245  fprintf(outputStrem, "%d", i);
246  for ( int j = 1; j <= 5; j++ ) {
247  fprintf( outputStrem, " %d", ielem->giveNode(j)->giveNumber() );
248  }
249 
250  fprintf(outputStrem, "\n");
251  }
252  }
253 
254  if ( wedges != 0 ) {
255  for ( int i = 1; i <= wedges; i++ ) {
256  ielem = d->giveElement( wedgeIdArray.at(i) );
257  fprintf(outputStrem, "%d", i);
258  for ( int j = 1; j <= 6; j++ ) {
259  fprintf( outputStrem, " %d", ielem->giveNode(j)->giveNumber() );
260  }
261 
262  fprintf(outputStrem, "\n");
263  }
264  }
265 
266  if ( hexas != 0 ) {
267  for ( int i = 1; i <= hexas; i++ ) {
268  ielem = d->giveElement( hexaIdArray.at(i) );
269  fprintf(outputStrem, "%d", i);
270  for ( int j = 1; j <= 8; j++ ) {
271  fprintf( outputStrem, " %d", ielem->giveNode(j)->giveNumber() );
272  }
273 
274  fprintf(outputStrem, "\n");
275  }
276  }
277 
278  fclose(outputStrem);
279 
280  OOFEM_LOG_INFO("t3d.bmf file created\n");
281  return 1;
282 }
283 
284 
285 
286 
287 
288 int
289 T3DInterface :: t3d_2_OOFEM(const char *t3dOutFile, Domain **dNew)
290 {
291 
292  std::ifstream inputStream;
293  inputStream.open( t3dOutFile );
294  if ( !inputStream.is_open() ) {
295  OOFEM_ERROR("OOFEMTXTDataReader::OOFEMTXTDataReader: Can't open T3D input stream (%s)", t3dOutFile);
296  return 0;
297  }
298  // create new domain
299  ( * dNew ) = new Domain( 2, this->domain->giveSerialNumber() + 1, this->domain->giveEngngModel() );
300  ( * dNew )->setDomainType( this->domain->giveDomainType() );
301 
302  std::string line;
303 
304  //read first line from t3d out file - 4 numbers
305  // 2 degree of interpolation
306  // other are not important so far
307  std::getline(inputStream, line);
308  //convert const char to char in order to use strtok
309  char *currentLine = new char[line.size() + 1];
310  std::strcpy ( currentLine, line.c_str() );
311  // tokenizing line
312  char *token = std::strtok(currentLine, " ");
313  // set counter to 0
314  int i = 0;
315  while (token != NULL) {
316  if(i == 0)
317  {}//int n1 = atoi(token);
318  else if (i == 1)
319  {}//int interp = atoi(token);
320  else if(i == 2)
321  {}//int n3 = atoi(token);
322  else if(i == 3)
323  {}//int n4 = atoi(token);
324  else
325  break;
326  token = std::strtok(NULL, " ");
327  i++;
328  }
329 
330 
331  int nnodes,ntriangles,ntetras; // nedges,
332 
333  /*read second line from t3d out file
334  4 numbers
335  1 - number of nodes
336  2 - number of edges
337  3 - number of triangles
338  4 - number of tetras
339  */
340  std::getline(inputStream, line);
341  //convert const char to char in order to use strtok
342  currentLine = new char[line.size() + 1];
343  std::strcpy ( currentLine, line.c_str() );
344  // tokenizing line
345  token = std::strtok(currentLine, " ");
346  // set counter to 0
347  i = 0;
348  while (token != NULL) {
349  if(i == 0)
350  nnodes = atoi(token);
351  else if (i == 1)
352  {}//nedges = atoi(token);
353  else if(i == 2)
354  ntriangles = atoi(token);
355  else if(i == 3)
356  ntetras = atoi(token);
357  else
358  break;
359  token = std::strtok(NULL, " ");
360  i++;
361  }
362  // create new domain
363  (*dNew)->resizeDofManagers(nnodes);
364 
365 
366  //one empty line
367  std::getline(inputStream, line);
368  // create nodes
369  Node *node;
370  // read dofs
371  const IntArray dofIDArrayPtr = domain->giveDefaultNodeDofIDArry();
372  int ndofs = dofIDArrayPtr.giveSize();
373  // loop over number of nodes, read coordinates and create new nodes
374  for ( int inode = 1; inode <= nnodes; inode++ ) {
375  FloatArray coords(3);
376  std::getline(inputStream, line);
377  //convert const char to char in order to use strtok
378  currentLine = new char[line.size() + 1];
379  std::strcpy ( currentLine, line.c_str() );
380  // tokenizing line
381  token = std::strtok(currentLine, " ");
382  // set counter to 0
383  i = 0;
384  while (token != NULL) {
385  if(i == 0)
386  {}//int nodeNum = atoi(token);
387  else if (i == 1)
388  coords.at(1) = atof(token);
389  else if(i == 2)
390  coords.at(2) = atof(token);
391  else if(i == 3)
392  coords.at(3) = atof(token);
393  else
394  break;
395  token = std::strtok(NULL, " ");
396  i++;
397  }
398  // newly created node
399  node = new Node(inode, * dNew);
400  //create new node with default DOFs
401  node->setNumberOfDofs(ndofs);
402  node->setCoordinates( coords );
403  // how to set boundary condition ??
404  // node->setBoundaryFlag( mesh->giveNode(inode)->isBoundary() );
405  // ( * dNew )->setDofManager(inode, node);
406 
407  }//end loop over nodes
408 
409  //read empty line
410  std::getline(inputStream, line);
411 
412 
413 
414  Element *parentElementPtr, *elem;
415  parentElementPtr = domain->giveElement(1); //??km??
416  // loop over triangles, read dofman numbers and create new elements
417  for (int itriangle = 1; itriangle <= ntriangles; itriangle++) {
418  int elemNumber;
419  IntArray dofManagers(3);
420  std::getline(inputStream, line);
421  //convert const char to char in order to use strtok
422  currentLine = new char[line.size() + 1];
423  std::strcpy ( currentLine, line.c_str() );
424  // tokenizing line
425  token = std::strtok(currentLine, " ");
426  // set counter to 0
427  i = 0;
428  while (token != NULL) {
429  if(i == 0)
430  elemNumber = atoi(token);
431  else if (i >= 1 && i<=4)
432  dofManagers.at(i) = atof(token);
433  else
434  break;
435  token = std::strtok(NULL, " ");
436  i++;
437  }
438  elem = classFactory.createElement(parentElementPtr->giveClassName(), elemNumber, * dNew);
439  elem->setDofManagers( dofManagers );
440  elem->setMaterial( parentElementPtr->giveMaterial()->giveNumber() );
441  elem->setCrossSection( parentElementPtr->giveCrossSection()->giveNumber() );
442  //
443  // ...
444  //
445 
446  }//end loop over triangles
447 
448 
449 // loop over tetras, read dofman numbers and create new elements
450  for (int itetra = 1; itetra <= ntetras; itetra++) {
451  int elemNumber;
452  IntArray dofManagers(4);
453  std::getline(inputStream, line);
454  //convert const char to char in order to use strtok
455  currentLine = new char[line.size() + 1];
456  std::strcpy ( currentLine, line.c_str() );
457  // tokenizing line
458  token = std::strtok(currentLine, " ");
459  // set counter to 0
460  i = 0;
461  while (token != NULL) {
462  if(i == 0)
463  elemNumber = atoi(token);
464  else if (i >= 1 && i<=4)
465  dofManagers.at(i) = atof(token);
466  else
467  break;
468  token = std::strtok(NULL, " ");
469  i++;
470  }
471  //elem = classFactory.createElement(parentElementPtr->giveClassName(), elemNumber, * dNew);
472  elem = classFactory.createElement("LTRSpace", elemNumber, * dNew);
473  elem->setDofManagers( dofManagers );
474  elem->setMaterial( parentElementPtr->giveMaterial()->giveNumber() );
475  elem->setCrossSection( parentElementPtr->giveCrossSection()->giveNumber() );
476  (*dNew)->setElement(elemNumber, elem);
477  }//end loop over tetras
478 
479 
480 
481  CrossSection *crossSection;
482  Material *mat;
483  NonlocalBarrier *barrier;
485  InitialCondition *ic;
486  //LoadTimeFunction *ltf;
487  Function *ltf;
488  std::string name;
489 
490  // copy of crossections from old domain
491  int ncrosssect = domain->giveNumberOfCrossSectionModels();
492  ( * dNew )->resizeCrossSectionModels(ncrosssect);
493  for ( int i = 1; i <= ncrosssect; i++ ) {
496  ir.giveRecordKeywordField(name);
497 
498  crossSection = classFactory.createCrossSection(name.c_str(), i, * dNew);
499  crossSection->initializeFrom(&ir);
500  ( * dNew )->setCrossSection(i, crossSection);
501  }
502 
503  // copy of materials from old domain
504  int nmat = domain->giveNumberOfMaterialModels();
505  ( * dNew )->resizeMaterials(nmat);
506  for ( int i = 1; i <= nmat; i++ ) {
509  ir.giveRecordKeywordField(name);
510 
511  mat = classFactory.createMaterial(name.c_str(), i, * dNew);
512  mat->initializeFrom(&ir);
513  ( * dNew )->setMaterial(i, mat);
514  }
515 
516  // copy of crossections from old domain
517  int nbarriers = domain->giveNumberOfNonlocalBarriers();
518  ( * dNew )->resizeNonlocalBarriers(nbarriers);
519  for ( int i = 1; i <= nbarriers; i++ ) {
522  ir.giveRecordKeywordField(name);
523 
524  barrier = classFactory.createNonlocalBarrier(name.c_str(), i, * dNew);
525  barrier->initializeFrom(&ir);
526  ( * dNew )->setNonlocalBarrier(i, barrier);
527  }
528 
529  // copy of boundary conditions from old domain
531  ( * dNew )->resizeBoundaryConditions(nbc);
532  for ( int i = 1; i <= nbc; i++ ) {
534  domain->giveBc(i)->giveInputRecord(ir);
535  ir.giveRecordKeywordField(name);
536 
537  bc = classFactory.createBoundaryCondition(name.c_str(), i, * dNew);
538  bc->initializeFrom(&ir);
539  ( * dNew )->setBoundaryCondition(i, bc);
540  }
541 
542  // copy of initial conditions from old domain
544  ( * dNew )->resizeInitialConditions(nic);
545  for ( int i = 1; i <= nic; i++ ) {
547  domain->giveIc(i)->giveInputRecord(ir);
548  ir.giveRecordKeywordField(name);
549 
550  ic = new InitialCondition(i, *dNew);
551  ic->initializeFrom(&ir);
552  ( * dNew )->setInitialCondition(i, ic);
553  }
554 
555  // copy of load time functions from old domain
556  // int nltf = domain->giveNumberOfLoadTimeFunctions();
557  int nltf = domain->giveNumberOfFunctions();
558  // ( * dNew )->resizeLoadTimeFunctions(nltf);
559  ( * dNew )->resizeFunctions(nltf);
560  for ( int i = 1; i <= nltf; i++ ) {
562  //domain->giveLoadTimeFunction(i)->giveInputRecord(ir);
564  ir.giveRecordKeywordField(name);
565 
566  //ltf = classFactory.createLoadTimeFunction(name.c_str(), i, * dNew);
567  ltf = classFactory.createFunction(name.c_str(), i, * dNew);
568  ltf->initializeFrom(&ir);
569  //( * dNew )->setLoadTimeFunction(i, ltf);
570  ( * dNew )->setFunction(i, ltf);
571  }
572 
573  // copy output manager settings from old domain
574  ( * dNew )->giveOutputManager()->beCopyOf( domain->giveOutputManager() );
575  return 1;
576 
577 }
578 
579 // used by HTS element to create export mesh to vtk
580 
581 int
583 {
584  FILE *inputStrem;
585  inputStrem = fopen(t3dInFile, "w");
586 
587  int nnodes = e->giveNumberOfDofManagers();
588  // loop over nodes and write vertexes into t3d input file
589  for ( int i = 1; i <= nnodes; i++ ) {
590  Node *inode;
591  inode = e->giveNode(i);
592  fprintf(inputStrem, "vertex %d xyz %e %e %e\n", i, inode->giveCoordinate(1), inode->giveCoordinate(2), inode->giveCoordinate(3));
593  }
594  for (int i = 1; i<=nnodes; i++) {
595  if( i< nnodes)
596  fprintf(inputStrem, "curve %d order 2 vertex %d %d\n", i, i, i+1);
597  else
598  fprintf(inputStrem, "curve %d order 2 vertex %d %d\n", i, i, 1);
599  }
600  fprintf(inputStrem, "patch 1 normal 0 0 1 boundary curve");
601  for (int i = 1; i<=nnodes; i++) {
602  fprintf(inputStrem, " %d", i);
603  }
604  fclose(inputStrem);
605 
606  return 1;
607 
608 }
609 
610 
611 
612 
613 
614 
615 
616 int
617 T3DInterface :: createVTKExportMesh(const char *t3dOutFile,std::vector<FloatArray> &nodeCoords, std::vector<IntArray> &cellNodes, IntArray &cellTypes )
618 {
619 
620  std::ifstream inputStream;
621  inputStream.open( t3dOutFile );
622  if ( !inputStream.is_open() ) {
623  OOFEM_ERROR("OOFEMTXTDataReader::OOFEMTXTDataReader: Can't open T3D input stream (%s)", t3dOutFile);
624  return 0;
625  }
626  std::string line;
627  //read and skip first line from t3d out file - 4 numbers
628  std::getline(inputStream, line);
629  /*read second line from t3d out file
630  4 numbers
631  1 - number of nodes
632  2 - number of edges
633  3 - number of triangles
634  4 - number of tetras
635  */
636  int nnodes,ntriangles;// nedges, ntetras
637  std::getline(inputStream, line);
638  //convert const char to char in order to use strtok
639  char *currentLine = new char[line.size() + 1];
640  std::strcpy ( currentLine, line.c_str() );
641  // tokenizing line
642  char *token = std::strtok(currentLine, " ");
643  // set counter to 0
644  int i = 0;
645  while (token != NULL) {
646  if(i == 0)
647  nnodes = atoi(token);
648  else if (i == 1)
649  {}//nedges = atoi(token);
650  else if(i == 2)
651  ntriangles = atoi(token);
652  else if(i == 3)
653  {}//ntetras = atoi(token);
654  else
655  break;
656  token = std::strtok(NULL, " ");
657  i++;
658  }
659  delete [] currentLine;
660  //read one empty line
661  std::getline(inputStream, line);
662 
663 
664  // loop over number of nodes, read coordinates and put them into nodeCoords Array
665  for ( int inode = 1; inode <= nnodes; inode++ ) {
666  // int nodeNum;
667  FloatArray coords(3);
668  std::getline(inputStream, line);
669  //convert const char to char in order to use strtok
670  currentLine = new char[line.size() + 1];
671  std::strcpy ( currentLine, line.c_str() );
672  // tokenizing line
673  token = std::strtok(currentLine, " ");
674  // set counter to 0
675  i = 0;
676  while (token != NULL) {
677  if(i == 0)
678  {}// nodeNum = atoi(token);
679  else if (i == 1)
680  coords.at(1) = atof(token);
681  else if(i == 2)
682  coords.at(2) = atof(token);
683  else if(i == 3)
684  coords.at(3) = atof(token);
685  else
686  break;
687  token = std::strtok(NULL, " ");
688  i++;
689  }
690 
691  nodeCoords.push_back(coords);
692  delete [] currentLine;
693  }//end loop over nodes
694 
695 
696 
697  //one empty line
698  std::getline(inputStream, line);
699  cellTypes.resize(ntriangles);
700  // loop over triangles, and fill nodeCoords, cellNodes nad cellTypes arrays
701  for (int itriangle = 1; itriangle <= ntriangles; itriangle++) {
702  // int elemNumber;
703  IntArray dofManagers(3);
704  std::getline(inputStream, line);
705  //convert const char to char in order to use strtok
706  currentLine = new char[line.size() + 1];
707  std::strcpy ( currentLine, line.c_str() );
708  // tokenizing line
709  token = std::strtok(currentLine, " ");
710  // set counter to 0
711  i = 0;
712  while (token != NULL) {
713  if(i == 0)
714  {}//elemNumber = atoi(token);
715  else if (i >= 1 && i<=3)
716  dofManagers.at(i) = atof(token) - 1;
717  else
718  break;
719  token = std::strtok(NULL, " ");
720  i++;
721  }
722  cellNodes.push_back(dofManagers);
723  // in vtk number 5 corresponds to linear triangle
724  cellTypes.at(itriangle) = 5;
725  delete [] currentLine;
726  }//end loop over triangles
727 
728  return 1;
729 }
730 
731 
732 
733 
734 
735 int
736 T3DInterface :: createQCInterpolationMesh(const char *t3dOutFile,std::vector<FloatArray> &nodeCoords, std::vector<IntArray> &cellNodes, IntArray &cellTypes )
737 //
738 // create interpolation mest from t3dOutFile
739 // node coordinates and element nodes are saved in "matrix" vector<FloatArray/IntArray>
740 //
741 {
742 
743  std::ifstream inputStream;
744  inputStream.open( t3dOutFile );
745  if ( !inputStream.is_open() ) {
746  OOFEM_ERROR("OOFEMTXTDataReader::OOFEMTXTDataReader: Can't open T3D input stream (%s)", t3dOutFile);
747  return 0;
748  }
749  std::string line;
750  //read and skip first line from t3d out file - 4 numbers
751  std::getline(inputStream, line);
752  /*read second line from t3d out file
753  4 numbers
754  1 - number of nodes
755  2 - number of edges
756  3 - number of triangles
757  4 - number of tetras
758  */
759  int nnodes,ntriangles,ntetras;//nedges,
760  std::getline(inputStream, line);
761  //convert const char to char in order to use strtok
762  char *currentLine = new char[line.size() + 1];
763  std::strcpy ( currentLine, line.c_str() );
764  // tokenizing line
765  char *token = std::strtok(currentLine, " ");
766  // set counter to 0
767  int i = 0;
768  while (token != NULL) {
769  if(i == 0)
770  nnodes = atoi(token);
771  else if (i == 1)
772  {}//nedges = atoi(token);
773  else if(i == 2)
774  ntriangles = atoi(token);
775  else if(i == 3)
776  ntetras = atoi(token);
777  else
778  break;
779  token = std::strtok(NULL, " ");
780  i++;
781  }
782  delete [] currentLine;
783  //read one empty line
784  std::getline(inputStream, line);
785 
786  // check the number of interpolation element
787  if (ntriangles!=0 && ntetras!=0 ) {
788  OOFEM_ERROR( "T3DInterface: 2D and 3D interpolation elements are not supported together");
789  } else if (ntriangles!=0) {
790  cellTypes.resize(ntriangles);
791  } else if (ntetras!=0) {
792  cellTypes.resize(ntetras);
793  } else {
794  OOFEM_ERROR( "T3DInterface: No interpolation element found in %s", t3dOutFile);
795  }
796 
797  // loop over number of nodes, read coordinates and put them into nodeCoords Array
798  for ( int inode = 1; inode <= nnodes; inode++ ) {
799  FloatArray coords(3);
800  // int nodeNum;
801  std::getline(inputStream, line);
802  //convert const char to char in order to use strtok
803  currentLine = new char[line.size() + 1];
804  std::strcpy ( currentLine, line.c_str() );
805  // tokenizing line
806  token = std::strtok(currentLine, " ");
807  // set counter to 0
808  i = 0;
809  while (token != NULL) {
810  if(i == 0)
811  {}// nodeNum = atoi(token);
812  else if (i == 1)
813  coords.at(1) = atof(token);
814  else if(i == 2)
815  coords.at(2) = atof(token);
816  else if(i == 3)
817  coords.at(3) = atof(token);
818  else
819  break;
820  token = std::strtok(NULL, " ");
821  i++;
822  }
823 
824  nodeCoords.push_back(coords);
825  delete [] currentLine;
826  }//end loop over nodes
827 
828  //one empty line
829  std::getline(inputStream, line);
830 
831 // loop over triangles, and fill nodeCoords, cellNodes nad cellTypes arrays
832  for (int itriangle = 1; itriangle <= ntriangles; itriangle++) {
833  IntArray dofManagers(3);
834  // int elemNumber;
835  std::getline(inputStream, line);
836  //convert const char to char in order to use strtok
837  currentLine = new char[line.size() + 1];
838  std::strcpy ( currentLine, line.c_str() );
839  // tokenizing line
840  token = std::strtok(currentLine, " ");
841  // set counter to 0
842  i = 0;
843  while (token != NULL) {
844  if(i == 0)
845  {}//elemNumber = atoi(token);
846  else if (i >= 1 && i<=3)
847  dofManagers.at(i) = atof(token);
848  else
849  break;
850  token = std::strtok(NULL, " ");
851  i++;
852  }
853  cellNodes.push_back(dofManagers);
854  // in vtk number 5 corresponds to linear triangle
855  cellTypes.at(itriangle) = 5;
856  delete [] currentLine;
857  }//end loop over triangles
858 
859 // loop over tetras, read dofman numbers and fill nodeCoords, cellNodes nad cellTypes arrays
860  for (int itetra = 1; itetra <= ntetras; itetra++) {
861  IntArray dofManagers(4);
862  // int elemNumber;
863  std::getline(inputStream, line);
864  //convert const char to char in order to use strtok
865  currentLine = new char[line.size() + 1];
866  std::strcpy ( currentLine, line.c_str() );
867  // tokenizing line
868  token = std::strtok(currentLine, " ");
869  // set counter to 0
870  i = 0;
871  while (token != NULL) {
872  if(i == 0)
873  {}//elemNumber = atoi(token);
874  else if (i >= 1 && i<=4)
875  dofManagers.at(i) = atof(token);
876  else
877  break;
878  token = std::strtok(NULL, " ");
879  i++;
880  }
881  cellNodes.push_back(dofManagers);
882  // in vtk number 5 corresponds to linear triangle
883  cellTypes.at(itetra) = 5; // ??km?? TODO: number for tetras in vtk = ???
884  delete [] currentLine;
885  }//end loop over tetras
886 
887 
888  return 1;
889 }
890 
891 
892 
893 } // end namespace oofem
CrossSection * giveCrossSection()
Definition: element.C:495
Material * createMaterial(const char *name, int num, Domain *domain)
Creates new instance of material corresponding to given keyword.
Definition: classfactory.C:199
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Definition: crosssection.C:67
int createVTKExportMesh(const char *t3dOutFile, std::vector< FloatArray > &nodeCoords, std::vector< IntArray > &cellNodes, IntArray &cellTypes)
Definition: t3dinterface.C:617
Function * createFunction(const char *name, int num, Domain *domain)
Creates new instance of load time function corresponding to given keyword.
Definition: classfactory.C:219
Class and object Domain.
Definition: domain.h:115
Abstract base class for all nonlocal barriers.
Class implementing general initial condition.
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
InitialCondition * giveIc(int n)
Service for accessing particular domain ic.
Definition: domain.C:255
int giveNumberOfDofManagers() const
Returns number of dof managers in domain.
Definition: domain.h:432
REGISTER_Mesher(FreemInterface, MPT_FREEM)
int giveNumberOfBoundaryConditions() const
Returns number of boundary conditions in domain.
Definition: domain.h:440
NonlocalBarrier * giveNonlocalBarrier(int n)
Service for accessing particular domain nonlocal barrier representation.
Definition: domain.C:351
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
NonlocalBarrier * createNonlocalBarrier(const char *name, int num, Domain *domain)
Creates new instance of nonlocal barrier corresponding to given keyword.
Definition: classfactory.C:229
int giveNumberOfInitialConditions() const
Returns number of initial conditions in domain.
Definition: domain.h:442
EngngModel * giveEngngModel()
Returns engineering model to which receiver is associated.
Definition: domain.C:433
const IntArray & giveDefaultNodeDofIDArry()
Returns default DofID array which defines physical meaning of particular DOFs.
Definition: domain.C:1004
bool isParallel() const
Returns true if receiver in parallel mode.
Definition: engngm.h:1056
Abstract base class for all finite elements.
Definition: element.h:145
CrossSection * createCrossSection(const char *name, int num, Domain *domain)
Creates new instance of cross section corresponding to given keyword.
Definition: classfactory.C:189
int giveNumberOfElements() const
Returns number of elements in domain.
Definition: domain.h:434
GeneralBoundaryCondition * createBoundaryCondition(const char *name, int num, Domain *domain)
Creates new instance of boundary condition corresponding to given keyword.
Definition: classfactory.C:179
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
Definition: material.C:110
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
Definition: crosssection.C:82
virtual double giveCoordinate(int i)
Definition: node.C:82
domainType giveDomainType()
Returns domain type.
Definition: domain.h:560
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
Definition: femcmpnn.C:77
Class implementing an array of integers.
Definition: intarray.h:61
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
virtual double giveRequiredDofManDensity(int num, TimeStep *tStep, int relative=0)=0
Returns the required mesh size n given dof manager.
virtual int giveNumberOfDofManagers() const
Definition: element.h:656
GeneralBoundaryCondition * giveBc(int n)
Service for accessing particular domain bc.
Definition: domain.C:243
Base abstract class representing cross section in finite element mesh.
Definition: crosssection.h:107
ErrorEstimator * giveErrorEstimator()
Returns Error Estimator associated to receiver.
Definition: domain.C:1429
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
CrossSection * giveCrossSection(int n)
Service for accessing particular domain cross section model.
Definition: domain.C:339
virtual returnCode createMesh(TimeStep *tStep, int domainNumber, int domainSerNum, Domain **dNew)
Runs the mesh generation, mesh will be written to corresponding domain din file.
Definition: t3dinterface.C:62
#define OOFEM_LOG_INFO(...)
Definition: logger.h:127
Material * giveMaterial(int n)
Service for accessing particular domain material model.
Definition: domain.C:281
Element * giveElement(int n)
Service for accessing particular domain fe element.
Definition: domain.C:160
#define OOFEM_ERROR(...)
Definition: error.h:61
void setDomainType(domainType _dType)
Sets domain type.
Definition: domain.h:562
int giveNumberOfCrossSectionModels() const
Returns number of cross section models in domain.
Definition: domain.h:438
int giveNumberOfMaterialModels() const
Returns number of material models in domain.
Definition: domain.h:436
virtual void setCrossSection(int csIndx)
Sets the cross section model of receiver.
Definition: element.h:653
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Definition: femcmpnn.C:89
Abstract base class for all boundary conditions of problem.
virtual RemeshingCriteria * giveRemeshingCrit()=0
Returns reference to associated remeshing criteria.
Abstract base class for all material models.
Definition: material.h:95
void resize(int n)
Checks size of receiver towards requested bounds.
Definition: intarray.C:124
void setDofManagers(const IntArray &dmans)
Sets receiver dofManagers.
Definition: element.C:550
virtual const char * giveClassName() const
Definition: element.h:1147
Function * giveFunction(int n)
Service for accessing particular domain load time function.
Definition: domain.C:268
Class representing vector of real numbers.
Definition: floatarray.h:82
void setNumberOfDofs(int _ndofs)
Sets number of dofs of the receiver; Deallocates existing DOFs; Resizes the dofArray accordingly...
Definition: dofmanager.C:286
int giveSerialNumber()
Returns domain serial (version) number.
Definition: domain.h:270
Abstract base class representing a function with vector input and output.
Definition: function.h:88
void setCoordinates(FloatArray coords)
Sets node coordinates to given array.
Definition: node.h:126
int giveNumberOfFunctions() const
Returns number of load time functions in domain.
Definition: domain.h:444
const char * __Element_Geometry_TypeToString(Element_Geometry_Type _value)
Definition: cltypes.C:318
int giveRank() const
Returns domain rank in a group of collaborating processes (0..groupSize-1)
Definition: engngm.h:1058
void setMaterial(int matIndx)
Sets the material of receiver.
Definition: element.h:647
int giveNumberOfNonlocalBarriers() const
Returns number of nonlocal integration barriers.
Definition: domain.h:448
Class representing the a dynamic Input Record.
ClassFactory & classFactory
Definition: classfactory.C:59
#define BMF_FILENAME
Definition: t3dinterface.h:44
OutputManager * giveOutputManager()
Returns domain output manager.
Definition: domain.C:1436
virtual void giveInputRecord(DynamicInputRecord &input)
Setups the input record string of receiver.
int t3d_2_OOFEM(const char *t3dOutFile, Domain **dNew)
Definition: t3dinterface.C:289
int giveSize() const
Definition: intarray.h:203
virtual Element_Geometry_Type giveGeometryType() const
Returns the element geometry type.
Definition: element.C:1529
Node * giveNode(int n)
Service for accessing particular domain node.
Definition: domain.h:371
the oofem namespace is to define a context or scope in which all oofem names are defined.
virtual IRResultType giveRecordKeywordField(std::string &answer, int &value)
Reads the record id field (type of record) and its corresponding number.
Class implementing node in finite element mesh.
Definition: node.h:87
int giveNumber() const
Definition: femcmpnn.h:107
Element * createElement(const char *name, int num, Domain *domain)
Creates new instance of element corresponding to given keyword.
Definition: classfactory.C:159
Node * giveNode(int i) const
Returns reference to the i-th node of element.
Definition: element.h:610
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Definition: material.C:89
Class representing solution step.
Definition: timestep.h:80
int createInput(Element *e, char *t3dInFile)
Definition: t3dinterface.C:582
virtual Material * giveMaterial()
Definition: element.C:484
int createQCInterpolationMesh(const char *t3dOutFile, std::vector< FloatArray > &nodeCoords, std::vector< IntArray > &cellNodes, IntArray &cellTypes)
Definition: t3dinterface.C:736

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:31 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011