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