Nektar++
XmlToTecplotWireFrame.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <cstdlib>
3 
4 #include <MultiRegions/ExpList.h>
5 
6 using namespace Nektar;
7 
8 int main(int argc, char *argv[])
9 {
11  Array<OneD,NekDouble> xc0,xc1,xc2;
12 
13  if(argc != 2)
14  {
15  fprintf(stderr,"Usage: XmlToTecplotWireFrame meshfile\n");
16  exit(1);
17  }
18 
21 
22  //----------------------------------------------
23  // Read in mesh from input file
24  string meshfile(argv[argc-1]);
26  //----------------------------------------------
27 
28  //----------------------------------------------
29  // Define Expansion
30  int expdim = mesh->GetMeshDimension();
31 
32  switch(expdim)
33  {
34  case 1:
35  ASSERTL0(false,"1D not set up");
36  break;
37  case 2:
38  {
39  NekDouble x,y,z;
40  string outname(strtok(argv[argc-1],"."));
41  outname += ".dat";
42  FILE *fp = fopen(outname.c_str(),"w");
43 
44  SpatialDomains::TriGeomMap trigeom = mesh->GetAllTriGeoms();
45  SpatialDomains::QuadGeomMap quadgeom = mesh->GetAllQuadGeoms();
46 
47  int nverts = mesh->GetNvertices();
48 
49  fprintf(fp,"Variables = x, y\n");
50  fprintf(fp,"Zone,N=%d, E=%d,DATAPACKING=POINT,ZONETYPE=FEQUADRILATERAL\n",nverts,(int)(trigeom.size()+quadgeom.size()));
51 
52  for(int i = 0; i < nverts; ++i)
53  {
54  mesh->GetVertex(i)->GetCoords(x,y,z);
55  fprintf(fp,"%lf %lf\n",x,y);
56  }
57 
59  for(triIter = trigeom.begin(); triIter != trigeom.end(); ++triIter)
60  {
61  fprintf(fp,"%d %d %d %d\n",(triIter->second)->GetVid(0)+1,(triIter->second)->GetVid(1)+1,(triIter->second)->GetVid(2)+1,(triIter->second)->GetVid(2)+1);
62  }
63 
65  for(quadIter = quadgeom.begin(); quadIter != quadgeom.end(); ++quadIter)
66  {
67  fprintf(fp,"%d %d %d %d\n",(quadIter->second)->GetVid(0)+1,(quadIter->second)->GetVid(1)+1,(quadIter->second)->GetVid(2)+1,(quadIter->second)->GetVid(3)+1);
68  }
69  }
70  break;
71  case 3:
72  {
73  int i;
74  NekDouble x,y,z;
75  string outname(strtok(argv[argc-1],"."));
76  outname += ".dat";
77  FILE *fp = fopen(outname.c_str(),"w");
78 
79  SpatialDomains::TetGeomMap tetgeom = mesh->GetAllTetGeoms();
80  SpatialDomains::PyrGeomMap pyrgeom = mesh->GetAllPyrGeoms();
81  SpatialDomains::PrismGeomMap prismgeom = mesh->GetAllPrismGeoms();
82  SpatialDomains::HexGeomMap hexgeom = mesh->GetAllHexGeoms();
83 
88 
89  int nverts = mesh->GetNvertices();
90 
91  map<int, int> vertid;
92  vector<int> vertord;
93 
94  int cnt = 0;
95  // set up list of all vertex ids
96  for(tetIter = tetgeom.begin(); tetIter != tetgeom.end(); ++tetIter)
97  {
98  for(i = 0; i < 4; ++i)
99  {
100  int vid = (tetIter->second)->GetVid(i);
101  if(vertid.count(vid) == 0)
102  {
103  vertord.push_back(vid);
104  vertid[vid] = cnt++;
105  }
106  }
107  }
108 
109  for(pyrIter = pyrgeom.begin(); pyrIter != pyrgeom.end(); ++pyrIter)
110  {
111  for(i = 0; i < 5; ++i)
112  {
113  int vid = (pyrIter->second)->GetVid(i);
114  if(vertid.count(vid) == 0)
115  {
116  vertord.push_back(vid);
117  vertid[vid] = cnt++;
118  }
119  }
120  }
121 
122 
123  for(prismIter = prismgeom.begin(); prismIter != prismgeom.end(); ++prismIter)
124  {
125  for(i = 0; i < 5; ++i)
126  {
127  int vid = (prismIter->second)->GetVid(i);
128  if(vertid.count(vid) == 0)
129  {
130  vertord.push_back(vid);
131  vertid[vid] = cnt++;
132  }
133  }
134  }
135 
136  for(hexIter = hexgeom.begin(); hexIter != hexgeom.end(); ++hexIter)
137  {
138  for(i = 0; i < 6; ++i)
139  {
140  int vid = (hexIter->second)->GetVid(i);
141  if(vertid.count(vid) == 0)
142  {
143  vertord.push_back(vid);
144  vertid[vid] = cnt++;
145  }
146  }
147  }
148 
149  ASSERTL0(cnt == nverts,"Vertex count did not match");
150 
151  fprintf(fp,"Variables = x, y, z\n");
152  fprintf(fp,"Zone,N=%d, E=%d,DATAPACKING=POINT,ZONETYPE=FEBRICK\n",nverts,(int)(tetgeom.size() + pyrgeom.size() + prismgeom.size() + hexgeom.size()));
153 
154  Array<OneD, NekDouble> xc(nverts),yc(nverts),zc(nverts);
155 
157  for(i = 0; i < nverts; ++i)
158  {
159  mesh->GetVertex(vertord[i])->GetCoords(x,y,z);
160  fprintf(fp,"%lf %lf %lf \n",x,y,z);
161  xc[i] = x;
162  yc[i] = y;
163  zc[i] = z;
164  }
165 
166  cnt = 0;
167  for(tetIter = tetgeom.begin(); tetIter != tetgeom.end(); ++tetIter)
168  {
169 
170  fprintf(fp,"%d %d %d %d %d %d %d %d\n",
171  vertid[(tetIter->second)->GetVid(0)]+1,
172  vertid[(tetIter->second)->GetVid(1)]+1,
173  vertid[(tetIter->second)->GetVid(2)]+1,
174  vertid[(tetIter->second)->GetVid(2)]+1,
175  vertid[(tetIter->second)->GetVid(3)]+1,
176  vertid[(tetIter->second)->GetVid(3)]+1,
177  vertid[(tetIter->second)->GetVid(3)]+1,
178  vertid[(tetIter->second)->GetVid(3)]+1);
179  }
180 
181 
182  for(pyrIter = pyrgeom.begin(); pyrIter != pyrgeom.end(); ++pyrIter)
183  {
184  fprintf(fp,"%d %d %d %d %d %d %d %d\n",
185  vertid[(pyrIter->second)->GetVid(0)]+1,
186  vertid[(pyrIter->second)->GetVid(1)]+1,
187  vertid[(pyrIter->second)->GetVid(3)]+1,
188  vertid[(pyrIter->second)->GetVid(2)]+1,
189  vertid[(pyrIter->second)->GetVid(4)]+1,
190  vertid[(pyrIter->second)->GetVid(4)]+1,
191  vertid[(pyrIter->second)->GetVid(4)]+1,
192  vertid[(pyrIter->second)->GetVid(4)]+1);
193  }
194 
195  for(prismIter = prismgeom.begin(); prismIter != prismgeom.end(); ++prismIter)
196  {
197  fprintf(fp,"%d %d %d %d %d %d %d %d\n",
198  vertid[(prismIter->second)->GetVid(0)]+1,
199  vertid[(prismIter->second)->GetVid(1)]+1,
200  vertid[(prismIter->second)->GetVid(3)]+1,
201  vertid[(prismIter->second)->GetVid(2)]+1,
202  vertid[(prismIter->second)->GetVid(4)]+1,
203  vertid[(prismIter->second)->GetVid(4)]+1,
204  vertid[(prismIter->second)->GetVid(5)]+1,
205  vertid[(prismIter->second)->GetVid(5)]+1);
206  }
207 
208  for(hexIter = hexgeom.begin(); hexIter != hexgeom.end(); ++hexIter)
209  {
210  fprintf(fp,"%d %d %d %d %d %d %d %d\n",
211  vertid[(hexIter->second)->GetVid(0)]+1,
212  vertid[(hexIter->second)->GetVid(1)]+1,
213  vertid[(hexIter->second)->GetVid(3)]+1,
214  vertid[(hexIter->second)->GetVid(2)]+1,
215  vertid[(hexIter->second)->GetVid(4)]+1,
216  vertid[(hexIter->second)->GetVid(5)]+1,
217  vertid[(hexIter->second)->GetVid(7)]+1,
218  vertid[(hexIter->second)->GetVid(6)]+1);
219  }
220 
221  }
222 
223  break;
224  default:
225  ASSERTL0(false,"Expansion dimension not recognised");
226  break;
227  }
228 
229  //-----------------------------------------------
230 
231  return 0;
232 }
233 
234 class Ord
235 {
236 public:
237  double x;
238  double y;
239  double z;
240 };
241 
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
static boost::shared_ptr< MeshGraph > Read(const LibUtilities::SessionReaderSharedPtr &pSession, DomainRangeShPtr &rng=NullDomainRangeShPtr)
Definition: MeshGraph.cpp:119
std::map< int, PrismGeomSharedPtr > PrismGeomMap
Definition: PrismGeom.h:112
std::map< int, PyrGeomSharedPtr > PyrGeomMap
Definition: PyrGeom.h:86
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:50
std::map< int, TetGeomSharedPtr > TetGeomMap
Definition: TetGeom.h:109
std::map< int, TriGeomSharedPtr > TriGeomMap
Definition: TriGeom.h:62
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
double NekDouble
int main(int argc, char *argv[])
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
std::map< int, QuadGeomSharedPtr > QuadGeomMap
Definition: QuadGeom.h:57
boost::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:432
std::map< int, HexGeomSharedPtr > HexGeomMap
Definition: HexGeom.h:113