proteus  1.8.1
C/C++/Fortran libraries
Domain.cpp
Go to the documentation of this file.
1 
2 #include "Domain.h"
3 #include <fstream>
4 #include <iostream>
5 #include <string>
6 #include <vector>
7 #include <cstring>
8 #include <cassert>
9 
10 using namespace std;
11 
12 
13 D_base::D_base(int dimIn, string nameIn, string unitsIn):
14  dim(dimIn),
15  name(nameIn),
16  units(unitsIn)
17 {}
18 
19 RectangularDomain::RectangularDomain(int dimIn, string nameIn, string unitsIn):
20  D_base(dimIn,nameIn,unitsIn)
21 {}
22 
23 RectangularDomain::RectangularDomain(double x0, double Lx, string nameIn, string unitsIn):
24  D_base(1,nameIn,unitsIn)
25 {
26  x.push_back(x0);
27  L.push_back(Lx);
28 }
29 
30 RectangularDomain::RectangularDomain(double x0, double y0, double Lx ,double Ly, string nameIn, string unitsIn):
31  D_base(2,nameIn,unitsIn)
32 {
33  x.push_back(x0);
34  x.push_back(y0);
35  L.push_back(Lx);
36  L.push_back(Ly);
37 }
38 
39 RectangularDomain::RectangularDomain(double x0, double y0, double z0, double Lx, double Ly, double Lz, string nameIn, string unitsIn):
40  D_base(3,nameIn,unitsIn)
41 {
42  x.push_back(x0);
43  x.push_back(y0);
44  x.push_back(z0);
45  L.push_back(Lx);
46  L.push_back(Ly);
47  L.push_back(Lz);
48 }
49 
50 void RectangularDomain::writePoly(const char* filename)
51 {
52  ofstream outfile(filename);
53  if(dim == 2)
54  {
55 
56  outfile << "#vertices" << endl;
57  outfile << "4 2 0 0 " << endl;
58  outfile << "1" << " " << x[0] << " " << x[1] << " 1" << endl;
59  outfile << "2" << " " << x[0]+L[0] << " " << x[1] << " " << "2" << endl;
60  outfile << "3" << " " << x[0]+L[0] << " " << x[1]+L[1] << " " << "3" << endl;
61  outfile << "4" << " " << x[0] << " " << x[1]+L[1] << " " << "4" << endl;
62  outfile << "#segments" << endl;
63  outfile << "4 1" << endl;
64  outfile << "1 1 2 1" << endl;
65  outfile << "2 2 3 2" << endl;
66  outfile << "3 3 4 3" << endl;
67  outfile << "4 4 1 4" << endl;
68  outfile << "#holes" << endl;
69  outfile << "0" << endl;
70  outfile << "#regions" << endl;
71  outfile << "1" << endl;
72  outfile << "1" << " " << (x[0]+L[0])/2 << " " << (x[1]+L[1])/2 << " " << "1" << endl;
73  outfile.close();
74  }
75  else if (dim == 3)
76  {
77 
78  outfile << "#vertices" << endl;
79  outfile << "8 3 0 0" << endl;
80  outfile << "1" << " " << x[0] << " " << x[1] << " " << x[2] << " 1" << endl;
81  outfile << "2" << " " << x[0] << " " << x[1]+L[1] << " " << x[2] << " 2" << endl;
82  outfile << "3" << " " << x[0]+L[0] << " " << x[1]+L[1] << " " << x[2] << " 3" << endl;
83  outfile << "4" << " " << x[0]+L[0] << " " << x[1] << " " << x[2] << " 4" << endl;
84  outfile << "5" << " " << x[0] << " " << x[1] << " " << x[2]+L[2] << " 5" << endl;
85  outfile << "6" << " " << x[0] << " " << x[1]+L[1] << " " << x[2]+L[2] << " 6" << endl;
86  outfile << "7" << " " << x[0]+L[0] << " " << x[1]+L[1] << " " << x[2]+L[2] << " 7" << endl;
87  outfile << "8" << " " << x[0]+L[0] << " " << x[1] << " " << x[2]+L[2] << " 8" << endl;
88  outfile << "#facets" << endl;
89  outfile << "6 1" << endl;
90  outfile << "1 0 1" << endl;
91  outfile << "4 1 2 3 4\t\t#bottom" << endl;
92  outfile << "1 0 2" << endl;
93  outfile << "4 1 5 8 4\t\t#front" << endl;
94  outfile << "1 0 3" << endl;
95  outfile << "4 1 5 6 2\t\t#left" << endl;
96  outfile << "1 0 4" << endl;
97  outfile << "4 5 6 7 8\t\t#top" << endl;
98  outfile << "1 0 5" << endl;
99  outfile << "4 4 8 7 3\t\t#right" << endl;
100  outfile << "1 0 6" << endl;
101  outfile << "4 3 7 6 2\t\t#back" << endl;
102  outfile << "#holes" << endl;
103  outfile << "0" << endl;
104  outfile << "#regions" << endl;
105  outfile << "1" << endl;
106  outfile << "1" << " " << (x[0]+L[0])/2.0 << " " << (x[1]+L[1])/2.0 << " " << (x[2]+L[2])/2.9 << " 1" << endl;
107  outfile.close();
108  }
109 }
110 
111 
112 void RectangularDomain::writeAsymptote(const char* filename)
113 {
114 
115  ofstream outfile(filename);
116 
117 
118  if (dim == 1)
119  {//interval1D
120  outfile << "unitsize(4.0 inches/" << L[0] << ");" << endl;
121  outfile << "size(6 inches);" << endl;
122  outfile << "real L=" << L[0] << ";" << endl;
123  outfile << "real offset=.0125L;" << endl;
124  outfile << "real x=" << x[0] << ";" << endl;
125  outfile << "string str=\"$" << L[0] << "\\mbox{" << units << "}$\";" << endl;
126  outfile << "import graph;" << endl;
127  outfile << "import palette;" << endl;
128  outfile << "pen[] allPens=Wheel();" << endl;
129  outfile << "pen[] myPens = new pen[3];" << endl;
130  outfile << "for(int i=0;i< 3;++i)" << endl;
131  outfile << "{" << endl;
132  outfile << " int iPen = round(i*allPens.length/3);" << endl;
133  outfile << " myPens[i] = allPens[iPen];" << endl;
134  outfile << " }" << endl;
135  outfile << "draw((x,0)--(x+L,0)^^(x,offset)--(x+L,offset),myPens[0]);" << endl;
136  outfile << "draw((x,0)--(x,offset),myPens[1]);" << endl;
137  outfile << "draw((x+L,0)--(x+L,offset),myPens[2]);" << endl;
138  outfile << "draw(str,(x,-offset)--(x+L,-offset),black,Bars,Arrows,PenMargins)" << ";" << endl;
139  }else if (dim == 2)
140  {
141 
142  //Rectangle 2D
143  outfile << "import math;" << endl;
144  outfile << "import graph;" << endl;
145  outfile << "unitsize(4.0 inches /" << L[0] << ");" << endl;
146  outfile << "size(6 inches);" << endl;
147  outfile << "real Lx = " << L[0] << ";" << endl;
148  outfile << "real Ly = " << L[1] << ";" << endl;
149  outfile << "real offset = 0.0125Lx;" << endl;
150  outfile << "real x = " << x[0] << ";" << endl;
151  outfile << "real y = " << x[1] << ";" << endl;
152  outfile << "string strx=\"$" << L[0]<< "\\mbox{" << units << "}$\";" << endl;
153  outfile << "string stry=\"$" << L[1]<< "\\mbox{" << units << "}$\";" << endl;
154  outfile << "import graph;" << endl;
155  outfile << "import palette;" << endl;
156  outfile << "pen[] allPens=Wheel();" << endl;
157  outfile << "pen[] myPens = new pen[4];" << endl;
158  outfile << "for(int i=0;i< 4;++i)" << endl;
159  outfile << "{" << endl;
160  outfile << "int iPen = round(i*allPens.length/4);" << endl;
161  outfile << " myPens[i] = allPens[iPen];" << endl;
162  outfile << "}" << endl;
163  outfile << "draw((x,y)--(x+Lx,y),myPens[0]);" << endl;
164  outfile << "draw((x,y+Ly)--(x+Lx,y+Ly),myPens[1]);" << endl;
165  outfile << "draw((x,y)--(x,y+Ly),myPens[2]);" << endl;
166  outfile << "draw((x+Lx,y)--(x+Lx,y+Ly),myPens[3]);" << endl;
167  outfile << "draw(strx,(x,y-offset)--(x+Lx,y-offset),S,black,Bars,Arrows,PenMargins);" << endl;
168  outfile << "draw(stry,(x-offset,y)--(x-offset,y+Ly),W,black,Bars,Arrows,PenMargins);" << endl;
169  }else
170  {
171  outfile << "import three;" << endl;
172  outfile << "currentlight=adobe;" << endl;
173  outfile << "currentprojection=perspective(-2,-2,1,up=Z,target=O,showtarget=true,autoadjust=true,center=false);" << endl;
174  outfile << "unitsize(4.0 inches/" << L[0] <<");" << endl;
175  outfile << "size(6 inches);" << endl;
176  outfile << "real Lx=" << L[0] << ";" << endl;
177  outfile << "real Ly=" << L[1] << ";" << endl;
178  outfile << "real Lz=" << L[2] << ";" << endl;
179  outfile << "real offset=.0125Lx;" << endl;
180  outfile << "real x=" << x[0] << ";" << endl;
181  outfile << "real y=" << x[1] << ";" << endl;
182  outfile << "real z=" << x[2]<< ";" << endl;
183  outfile << "triple p0=(" << x[0] << "," << x[1] << ","<< x[2] << ");" << endl;
184  outfile << "triple p1=(" << x[0] << "," << x[1]+L[1] << ","<< x[2] << ");" << endl;
185  outfile << "triple p2=(" << x[0]+L[0] << "," << x[1]+L[1] << "," << x[2] << ");" << endl;
186  outfile << "triple p3=(" << x[0]+L[0] << "," << x[1] << "," << x[2] << ");" << endl;
187  outfile << "triple p4=(" << x[0] << "," << x[1] << ","<< x[2]+L[2] << ");" << endl;
188  outfile << "triple p5=(" << x[0] << "," << x[1]+L[1] << "," << x[2]+ L[2] << ");" << endl;
189  outfile << "triple p6=(x+Lx,y+Ly,z+Lz);" << endl;
190  outfile << "triple p7=(x+Lx,y,z+Lz);" << endl;
191  outfile << "string strx=\"$" << L[0] << "\\mbox{" << units << "}$\";"<< endl;
192  outfile << "string stry=\"$" << L[1] << "\\mbox{" << units << "}$\";" << endl;
193  outfile << "string strz=\"$" << L[2] << "\\mbox{" << units << "}$\";" << endl;
194  outfile << "draw(surface(p0--p1--p2--p3--cycle),red);" << endl;
195  outfile << "draw(surface(p4--p5--p6--p7--cycle),blue);" << endl;
196  outfile << "draw(surface(p0--p1--p5--p4--cycle),green);" << endl;
197  outfile << "draw(surface(p1--p2--p6--p5--cycle),orange);" << endl;
198  outfile << "draw(surface(p2--p3--p7--p6--cycle),purple);" << endl;
199  outfile << "draw(surface(p3--p0--p4--p7--cycle),yellow);" << endl;
200  outfile << "draw(strx,(x,y-offset,z-offset)--(x+Lx,y-offset,z-offset),-(Y+Z),black,Bars3(Z),Arrows3);" << endl;
201  outfile << "draw(stry,(x-offset,y,z-offset)--(x-offset,y+Ly,z-offset),-(X+Z),black,Bars3(Z),Arrows3);" << endl;
202  outfile << "draw(strz,(x-offset,y-offset,z)--(x-offset,y-offset,z+Lz),-(X+Z),black,Bars3(Z),Arrows3);" << endl;
203  outfile << "shipout();" << endl;
204  }
205  outfile.close();
206 }
207 
208 
209 PlanarStraightLineGraphDomain::PlanarStraightLineGraphDomain(int dimIn, string nameIn, string unitsIn):
210  D_base(dimIn,nameIn,unitsIn)
211 {
212 }
213 
214 PlanarStraightLineGraphDomain::PlanarStraightLineGraphDomain(const vector<vector<double> >& verticesIn, const vector< vector<int> >& segmentsIn, const vector< vector<double> >& holesIn, const vector<double>& regionsIn, const vector<int>& vertexFlagsIn, const vector<int>& segmentFlagsIn, string nameIn,string unitsIn):
215  vertices(verticesIn),
216  segments(segmentsIn),
217  holes(holesIn),
218  regions(regionsIn),
219  vertexFlags(vertexFlagsIn),
220  segmentFlags(segmentFlagsIn),
221  D_base(2,nameIn,unitsIn)
222 {
223 }
224 
226 {}
228 {
229  ofstream outfile(filename);
230 
231  if(!filename)
232  {
233  if(vertexFlags.size() > 0)
234  hasVertexFlags = 1;
235  else
236  hasVertexFlags = 0;
237  if(segmentFlags.size() > 0)
238  hasSegmentFlags = 1;
239  else
240  hasSegmentFlags = 0;
241  outfile << vertices.size() << "\t" << "2\t" << "0\t" << hasVertexFlags << endl;
242  //write the vertices
243  for(int i = 0; i < vertices.size(); i++)
244  for(int j =0; j < 3; j++)
245  {
246  vN[i*3 + j] = vertices[i][j];
247  outfile << vN.size()+1 << "\t" << v[0] << "\t" << v[1] << endl;
248  }
249  //import pdb; pdb.set_trace()
250  // if(vertexFlags.size() > 0)
251 // outfile << vertexFlags[vN] << endl;
252 // else
253 // outfile << endl;
254 // //write the segments
255 // outfile << segments.size() << "\t" << hasSegmentFlags << endl;
256 // for(int i = 0; i < segments.size();i++)
257 // for(int j = 0; j < 3; j++)
258 // {
259 // sN[i*3+j] = segments[i][j];
260 // outfile << sN.size()+1 <<"\t" << s[0]+1 << "\t" << s[1]+1 << endl;
261 // }
262 // if(segmentFlags.size() > 0)
263 // outfile << segmentFlags[sN] << endl;
264 // else
265 // outfile << endl;
266 // if(holes.size() > 0)
267 // {
268 // outfile << holes.size() << endl;
269 // for(int i = 0; i < holes.size(); i++)
270 // for(int j = 0; j < 3; j++)
271 // {
272 // hN[i*3 + j] = holes[i][j];
273 // outfile << hN.size()+1 << "\t" << h[0] << "\t" << h[1] << endl;
274 // }
275 // }
276 // else
277 // outfile << "0" << endl;
278 // if(regions.size() > 0)
279 // {
280 // outfile << regions.size() << endl;
281 // for(int i = 0; i < regions.size(); i++)
282 // {
283 // rN[i*3] = regions[i];
284 // outfile << rN.size()+1 << "\t" << r[0] << "\t" << r[1] << endl;
285 // }
286 // if(regionFlags.size() > 0)
287 // outfile << regionFlags[rN] << endl;
288 // else
289 // outfile << endl;
290 // }
291 // else
292 // outfile << "0" << endl;
293 // outfile.close();
294  }
295  else
296  cout << "File already exists, not writing polyfile: " << filename << endl;
297 }
298 
300 {
301  ofstream outfile(filename);
302 
303 
304  outfile << "unitsize(4.0 inches/ " << L[0] << ");" << endl;
305  outfile << "size(6 inches);" << endl;
306  outfile << "real Lx=" << L[0] << ";" << endl;
307  outfile << "real Ly=" << L[1]<< ";" << endl;
308  outfile << "real offset=0.0125Lx;" << endl;
309  outfile << "real x=" << x[0] << ";" << endl;
310  outfile << "real y=" << x[1] << ";" << endl;
311  outfile << "string strx=\"$" << L[0] << "\\mbox{" << units << "}$\";" << endl;
312  outfile << "string stry=\"$" << L[1] << "\\mbox{" << units << "}$\";" << endl;
313  outfile << "draw(strx,(x,y-offset)--(x+Lx,y-offset),S,black,Bars,Arrows,PenMargins);" << endl;
314  outfile << "draw(stry,(x-offset,y)--(x-offset,y+Ly),W,black,Bars,Arrows,PenMargins);" << endl;
315  outfile << "import graph;" << endl;
316  outfile << "import palette;" << endl;
317  outfile << "pen[] allPens=wheel();" << endl;
318  outfile << "pen[] myPens = new pen[" << segmentFlags.size() + 1 << "];" << endl;
319  outfile << "for(int i= 0; i<" << segmentFlags.size() +1 << ";++i)" << endl;
320  outfile << "{" << endl;
321  outfile << "int iPen = round(i*allPens.length//" << segmentFlags.size() + 1 << ");" << endl;
322  outfile << "myPens[i] = allPens[iPen];" << endl;
323  outfile << "}" << endl;
324  outfile << "shipout();" << endl;
325  for(int i = 0; i<segments.size();i++)
326  for(int j = 0; j < 3; j++)
327  s[i*3 + j] = segments[i][j];
328  for(int i = 0; i < segmentFlags.size();i++)
329  sFlags[i*3] = segmentFlags[i];
330  // outfile << "draw((" << vertices[s[0]] << "," << vertices[s[1]] << ")--(" <<
331 
332 // //for loop in python code
333 
334 // //#now loop over segments
335 // // for s,sFlag in zip(self.segments,self.segmentFlags):
336 // // fileString+="draw((%f,%f)--(%f,%f),myPens[%d]);\n" % tuple(self.vertices[s[0]]+self.vertices[s[1]]+[sFlag])
337 
338  outfile.close();
339 }
340 
342 {
343  // sMin = segmentFlags[0];
344 // sMax = segmentFlags[0];
345 // for(int i = 0; i < segmentFlags.size(); i++)
346 // {
347 // s[i] = segmentFlags[i];
348 
349 // }
350 // if(s > sMax)
351 // sMax = s;
352 // if(s < sMin)
353 // sMin = s;
354 
355 
356 }
357 
359 {
360  xMax = vertices[0][0];
361  xMin = vertices[0][0];
362  yMax = vertices[0][1];
363  yMin = vertices[0][1];
364  for(int i =0; i < vertices.size(); i++)
365  for(int j = 0; j <3; j++)
366  {
367  v[i*3 + j] = vertices[i][j];
368  if (v[0] > xMax)
369  xMax = v[0];
370  if (v[1] > yMax)
371  yMax = v[1];
372  if (v[0] < xMin)
373  xMin = v[0];
374  if (v[1] < yMin)
375  yMin = v[1];
376  }
377  x.push_back(xMin);
378  x.push_back(yMin);
379  L.push_back(xMax-xMin);
380  L.push_back(yMax-yMin);
381 }
382 
383 
384 void PlanarStraightLineGraphDomain::readPoly(const char* filename)
385 {
386 // ifstream infile;
387 // infile.open(filename);
388 
389 // while(!infile)
390 // {
391 // infile.close();
392 // infile.clear();
393 
394 // cout << "Error: Invalid filename. Please re-enter: ";
395 // cin >> filename;
396 
397 // infile.open(filename);
398 // }
399 // while(firstLine.length() == 0 || firstLine[0][0] == "#")
400 // {
401 // infile >> nVertices >> dim >> nVertexAttributes >> hasVertexFlags;
402 // }
403 // infile.close();
404 }
405 
406 
407 
408 
409 // //Constructors for TriangulatedSurfaceDomain
410 
411 
412 // TriangulatedSurfaceDomain::TriangulatedSurfaceDomain()
413 // {
414 // //vertices = 0.0;
415 // triangles = 0.0;
416 // // nodes = 0.0;
417 // name = "DefaultTriangulatedSurfaceDomain";
418 // units = "m";
419 // dim = 3;
420 // }
421 
422 
423 // TriangulatedSurfaceDomain::~TriangulatedSurfaceDomain()
424  // {}
425 
426 // void TriangulatedSurfaceDomain::writeAsymptote(const char* filename)
427 // {
428 // ofstream outfile(filename);
429 
430 // }
431 
432 
433 
434 
435 
436 //PiecewiseLinearComplexDomain
437 PiecewiseLinearComplexDomain::PiecewiseLinearComplexDomain(int dimIn, string nameIn, string unitsIn):
438  D_base(dimIn,nameIn,unitsIn)
439 {}
440 
441 PiecewiseLinearComplexDomain::PiecewiseLinearComplexDomain(const vector<vector < vector <double> > >& verticesIn,const vector< vector < vector < vector <int> > > >& facetsIn, const vector<vector<double> >& holesIn, const vector<double>& regionsIn, const vector<int>& vertexFlagsIn,const vector <int>& facetFlagsIn, string nameIn = string("Domain"),string unitsIn = string("m")):
442  vertices(verticesIn),
443  facets(facetsIn),
444  holes(holesIn),
445  regions(regionsIn),
446  vertexFlags(vertexFlagsIn),
447  facetFlags(facetFlagsIn),
448  D_base(3,nameIn,unitsIn)
449 {}
451 {}
452 
454 {
455  ofstream outfile(filename);
456 
457 
458  outfile << "import three;" << endl;
459  outfile << "currentlight=adobe;" << endl;
460  outfile << "currentprojection=perspective(-2,-2,1,up=Z,target=(%(xc)f,%(yc)f,%(zc)f),showtarget=true,autoadjust=true,center=false);" << endl;
461  outfile << "unitsize(4.0 inches/%(Lx)f);" << endl;
462  outfile << "size(6 inches);" << endl;
463  outfile << "real Lx=%(Lx)f;" << endl;
464  outfile << "real Ly=%(Ly)f;" << endl;
465  outfile << "real Lz=%(Lz)f;" << endl;
466  outfile << "real offset=.0125Lx;" << endl;
467  outfile << "real x=%(x)f;" << endl;
468  outfile << "real y=%(y)f;" << endl;
469  outfile << "real z=%(z)f;" << endl;
470  outfile << "triple p0=(x,y,z);" << endl;
471  outfile << "triple p1=(x,y+Ly,z);" << endl;
472  outfile << "triple p2=(x+Lx,y+Ly,z);" << endl;
473  outfile << "triple p3=(x+Lx,y,z);" << endl;
474  outfile << "triple p4=(x,y,z+Lz);" << endl;
475  outfile << "triple p5=(x,y+Ly,z+Lz);" << endl;
476  outfile << "triple p6=(x+Lx,y+Ly,z+Lz);" << endl;
477  outfile << "triple p7=(x+Lx,y,z+Lz);" << endl;
478  outfile << "string strx=\"$%(Lx)2.2f\\mbox{%(units)s}$\";" << endl;
479  outfile << "string stry=\"$%(Ly)2.2f\\mbox{%(units)s}$\";" << endl;
480  outfile << "string strz=\"$%(Lz)2.2f\\mbox{%(units)s}$\";" << endl;
481  outfile << "draw(strx,(x,y-offset,z-offset)--(x+Lx,y-offset,z-offset),-(Y+Z),black,Bars3(Z),Arrows3);" << endl;
482  outfile << "draw(stry,(x-offset,y,z-offset)--(x-offset,y+Ly,z-offset),-(X+Z),black,Bars3(Z),Arrows3);" << endl;
483  outfile << "draw(strz,(x-offset,y-offset,z)--(x-offset,y-offset,z+Lz),-(X+Y),black,Bars3(X),Arrows3);" << endl;
484 
485 // for (int i = 0; i < facets.size(); i++)
486 // for(int j = 0; j < vertexList.size(); j++)
487 
488 // outfile << "draw(surface((" << vertices[vertexList[0]] << "," << vertices[vertexList[1]] << "," << vertices[vertexList[2]] << "))";
489 // for(int k = 0; k < vN; k++)
490 // //outfile << "(--(" << vertices[vN] <<
491 // //Python Loop found in Domain.py
492  /*
493  {'Lx':self.L[0],'Ly':self.L[1],'Lz':self.L[2],'x':self.x[0],'y':self.x[1],'z':self.x[2],'units':self.units,
494  'xc':(self.x[0]+0.5*self.L[0]),
495  'yc':(self.x[1]+0.5*self.L[1]),
496  'zc':(self.x[2]+0.5*self.L[2])}
497  f.write(fileString)
498  for facet in self.facets:
499  for vertexList in facet:
500  f.write("draw(surface((%f,%f,%f)" % tuple(self.vertices[vertexList[0]]))
501  for vN in vertexList[1:]:
502  f.write("--(%f,%f,%f)" % tuple(self.vertices[vN]))
503  f.write("--cycle));\n")
504 
505 
506  outfile.close();
507 
508  */
509 }
510 // void PiecewiseLinearComplex::getBoundingBox(vector<double> & v)
511 // {}
512 void PiecewiseLinearComplexDomain::writePoly(const char* filename)
513 {
514  if(!filename)
515  {
516  ofstream outfile;
517 
518  if(vertexFlags.size() > 1)
519  hasVertexFlags = 1;
520  else
521  hasVertexFlags = 0;
522  if(facetFlags >1)
523  hasFacetFlags.size() = 1;
524  else
525  hasFacetFlags = 0;
526  outfile << vertices.size() << " 3" << " 0 " << hasVertexFlags << endl;
527  //write the vertices
528  for(int i = 0; i < vertices.size(); i++)
529  for(int j =0; j < 3; j++)
530  {
531  vN[i*3 + j] = vertices[i][j];
532  outfile << vN.size()+1 << "\t" << v[0] << "\t" << v[1] << endl;
533  }
534  if(vertexFlags.size() > 1);
535  outfile << vertexFlags[vN] << endl;
536  else
537  outfile << endl;
538  //write facets
539  outfile << facets.size() << " " << hasFacetFlags;
540  for(int i = 0; i < facets.size(); i++)
541  for(int j = 0; j < 3; j++)
542  {
543  fN[i*3+j] = facets[i][j];
544  }
545  if(facetHoles.size() > 1)
546  nFacetHoles = facetHoles[fN].size();
547  else
548  nFacetHoles = 0;
549  if(hasFacetFlags = 1)
550  outfile << f.size() << " " << nFacetHoles << " " << facetFlags[fN] << endl;
551  else
552  outfile << fN.size()+1 << " " << nFacetHoles << endl;
553  for(int i = 0; i < f.size(); i++)
554  {
555  f = segmentList[i];
556  outfile << segmentList.size()+1 << endl;
557  }
558 
559  for(int j = 0; j < segmentList.size(); j++)
560  {
561  segmentList = vN[j];
562  outfile << vN+1 << " ";
563  }
564  outfile << endl;
565  if(facetHoles > 0)
566  {
567  for(int i = 0; i < facetHoles[fN].size(); i++)
568  {
569  h = facetHoles[i];
570  outfile << facetHoles[i] << " " << endl;
571  }
572  if(holes > 0)
573  {
574  outfile << holes.size() << endl;
575  for(int i = 0; i < holes.size(); i++)
576  for(int j = 0; j < 3; j++)
577  {
578  hN[i*3+j] = holes[i][j];
579  outfile << hN+1 << " " << h[0] << " " << h[1] << endl;
580  if(regionFlags > 0)
581  outfile << regionFlags[rN] << endl;
582  else
583  outfile << endl;
584 
585  }
586 
587  }
588  else
589  outfile << "0" << endl;
590 
591  }
592  else
593  outfile.close();
594  }
595  else
596  cout <<"File already exits, not writing polyfile: " << filename << endl;
597 }
598 
599 // void PiecewiseLinearComplex::readPoly(const char* filename)
600 // {
601 
602 // /*
603 // self.polyfile = fileprefix+".poly"
604 // self.name=fileprefix
605 // f = open(self.polyfile,'r')
606 // firstLine=f.readline().split()
607 // while len(firstLine) == 0 or firstLine[0][0] == '#':
608 // firstLine = f.readline()
609 // nVertices = int(firstLine[0])
610 // self.dim = int(firstLine[1])
611 // assert(self.dim == 3)
612 // nVertexAttributes = int(firstLine[2])
613 // self.vertexAttributes = [[] for j in range(nVertexAttributes)]
614 // hasVertexFlag = bool(firstLine[3])
615 // self.vertices=[]
616 // self.base=None
617 // if hasVertexFlag:
618 // self.vertexFlags=[]
619 // for i in range(nVertices):
620 // line = f.readline().split()
621 // while len(line) == 0 or line[0][0] == '#':
622 // line = f.readline().split()
623 // if self.base is None:
624 // self.base = int(line[0])
625 // self.vertices.append([float(line[1]),float(line[2]),float(line[3])])
626 // for j in range(nVertexAttributes):
627 // self.attributes[j].append(float(line[4+j]))
628 // if hasVertexFlag:
629 // self.vertexFlags.append(line[4+nVertexAttributes+1])
630 // facetLine = f.readline().split()
631 // while len(facetLine) == 0 or facetLine[0][0] == '#':
632 // facetLine = f.readline().split()
633 // nFacets = int(facetLine[0])
634 // hasFacetFlag = bool(facetLine[1])
635 // self.facets=[]
636 // self.facetHoles=[]
637 // if hasFacetFlag:
638 // self.facetFlags=[]
639 // for i in range(nFacets):
640 // line = f.readline().split()
641 // while len(line) == 0 or line[0][0] == '#':
642 // line = f.readline().split()
643 // self.facets.append([])
644 // self.facetHoles.append([])
645 // nPolygons = int(line[0])
646 // nHoles = int(line[1])
647 // if hasFacetFlag:
648 // self.facetFlags.append(int(line[2]))
649 // for j in range(nPolygons):
650 // line = f.readline().split()
651 // while len(line) == 0 or line[0][0] == '#':
652 // line = f.readline().split()
653 // nSegments = int(line[0])
654 // self.facets[-1].append([int(line[1+k])-self.base for k in range(nSegments)])
655 // for j in range(nHoles):
656 // line = f.readline().split()
657 // while len(line) == 0 or line[0][0] == '#':
658 // line = f.readline().split()
659 // self.facetHoles[-1].append([float(line[0]),
660 // float(line[1]),
661 // float(line[2])])
662 // holeLine = f.readline().split()
663 // while len(holeLine) == 0 or holeLine[0][0] == '#':
664 // holeLine = f.readline().split()
665 // nHoles = int(holeLine[0])
666 // self.holes=[]
667 // for i in range(nHoles):
668 // line = f.readline().split()
669 // while len(line) == 0 or line[0][0] == '#':
670 // line = f.readline().split()
671 // self.holes.append([float(line[0]),float(line[1])])
672 // regionLine = f.readline().split()
673 // while len(regionLine) == 0 or regionLine[0][0] == '#':
674 // regionLine = f.readline().split()
675 // nRegions = int(regionLine[0])
676 // self.regions=[]
677 // self.regionAttributes=[]
678 // self.areaConstraings=[]
679 // for i in range(nRegions):
680 // line = f.readline().split()
681 // while len(line) == 0 or line[0][0] == '#':
682 // line = f.readline().split()
683 // self.regions.append([float(line[1]),float(line[2]),float(line[3])])
684 // if len(line) > 4:
685 // self.regionAttributes.append(int(line[4]))
686 // if len(line) > 5:
687 // self.areaConstraint.append(float(line[5]))
688 // self.getBoundingBox()
689 // */
690 // }
691 
692 
693 
694 
PlanarStraightLineGraphDomain::yMax
int yMax
Definition: Domain.h:69
PlanarStraightLineGraphDomain::xMin
int xMin
Definition: Domain.h:68
PiecewiseLinearComplexDomain::vN
vector< int > vN
Definition: Domain.h:120
PlanarStraightLineGraphDomain::hasSegmentFlags
int hasSegmentFlags
Definition: Domain.h:72
PlanarStraightLineGraphDomain::getSegmentPartition
void getSegmentPartition(vector< int > &s)
Definition: Domain.cpp:341
PiecewiseLinearComplexDomain::facets
vector< vector< vector< int > > > facets
Definition: Domain.h:112
PlanarStraightLineGraphDomain::~PlanarStraightLineGraphDomain
virtual ~PlanarStraightLineGraphDomain()
Definition: Domain.cpp:225
PlanarStraightLineGraphDomain::xMax
int xMax
Definition: Domain.h:68
PlanarStraightLineGraphDomain::sFlags
vector< int > sFlags
Definition: Domain.h:62
PlanarStraightLineGraphDomain::readPoly
void readPoly(const char *filename)
Definition: Domain.cpp:384
PiecewiseLinearComplexDomain::vertices
vector< vector< vector< double > > > vertices
Definition: Domain.h:111
Domain.h
PlanarStraightLineGraphDomain::getBoundingBox
void getBoundingBox(vector< double > &v)
Definition: Domain.cpp:358
D_base::dim
int dim
Definition: Domain.h:17
s
Double s
Definition: Headers.h:84
PiecewiseLinearComplexDomain::fN
vector< int > fN
Definition: Domain.h:123
RectangularDomain::RectangularDomain
RectangularDomain(int dimIn=3, string nameIn=string("Domain"), string unitsIn=string("m"))
Definition: Domain.cpp:19
PlanarStraightLineGraphDomain::s
vector< int > s
Definition: Domain.h:61
PiecewiseLinearComplexDomain::holes
vector< double > holes
Definition: Domain.h:114
PiecewiseLinearComplexDomain::hasFacetFlags
int hasFacetFlags
Definition: Domain.h:119
PlanarStraightLineGraphDomain::vN
vector< int > vN
Definition: Domain.h:59
PiecewiseLinearComplexDomain::vertexFlags
vector< int > vertexFlags
Definition: Domain.h:116
PlanarStraightLineGraphDomain::segmentFlags
vector< int > segmentFlags
Definition: Domain.h:56
PiecewiseLinearComplexDomain::f
vector< int > f
Definition: Domain.h:122
PlanarStraightLineGraphDomain::v
vector< double > v
Definition: Domain.h:58
RectangularDomain::writeAsymptote
void writeAsymptote(const char *filename)
Definition: Domain.cpp:112
PiecewiseLinearComplexDomain::facetHoles
vector< int > facetHoles
Definition: Domain.h:115
PiecewiseLinearComplexDomain::writePoly
void writePoly(const char *filename)
Definition: Domain.cpp:512
PlanarStraightLineGraphDomain::segments
vector< vector< int > > segments
Definition: Domain.h:49
PiecewiseLinearComplexDomain::facetFlags
vector< int > facetFlags
Definition: Domain.h:117
v
Double v
Definition: Headers.h:95
D_base::D_base
D_base(int dimIn=3, string nameIn=string("Domain"), string unitsIn=string("m"))
Definition: Domain.cpp:13
PlanarStraightLineGraphDomain::yMin
int yMin
Definition: Domain.h:69
PlanarStraightLineGraphDomain::hasVertexFlags
int hasVertexFlags
Definition: Domain.h:71
D_base::L
vector< double > L
Definition: Domain.h:21
D_base::units
string units
Definition: Domain.h:19
RectangularDomain::writePoly
void writePoly(const char *filename)
Definition: Domain.cpp:50
PiecewiseLinearComplexDomain::~PiecewiseLinearComplexDomain
virtual ~PiecewiseLinearComplexDomain()
Definition: Domain.cpp:450
PlanarStraightLineGraphDomain::vertexFlags
vector< int > vertexFlags
Definition: Domain.h:55
PlanarStraightLineGraphDomain::writeAsymptote
void writeAsymptote(const char *filename)
Definition: Domain.cpp:299
PiecewiseLinearComplexDomain::hasVertexFlags
int hasVertexFlags
Definition: Domain.h:118
PiecewiseLinearComplexDomain::writeAsymptote
void writeAsymptote(const char *filename)
Definition: Domain.cpp:453
PlanarStraightLineGraphDomain::vertices
vector< vector< double > > vertices
Definition: Domain.h:48
PlanarStraightLineGraphDomain::PlanarStraightLineGraphDomain
PlanarStraightLineGraphDomain(int dimIn=2, string nameIn=string("Domain"), string unitsIn=string("m"))
Definition: Domain.cpp:209
vector
float * vector(long nl, long nh)
PiecewiseLinearComplexDomain::PiecewiseLinearComplexDomain
PiecewiseLinearComplexDomain(int dimIn=3, string nameIn=string("Domain"), string unitsIn=string("m"))
Definition: Domain.cpp:437
PiecewiseLinearComplexDomain::v
vector< double > v
Definition: Domain.h:121
D_base::x
vector< double > x
Definition: Domain.h:20
PlanarStraightLineGraphDomain::writePoly
void writePoly(const char *filename)
Definition: Domain.cpp:227
D_base
Definition: Domain.h:11