Merge branch 'master' into cvm

This commit is contained in:
graham
2008-10-29 15:20:38 +00:00
149 changed files with 17246 additions and 1725 deletions

View File

@ -33,9 +33,13 @@ Description
#include "IOstreams.H"
#include "IStringStream.H"
#include "labelList.H"
#include "DynamicList.H"
#include "face.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
@ -43,12 +47,12 @@ int main(int argc, char *argv[])
{
List<label> lstA(10);
List<label> lstC(IStringStream("(1 2 3 4)")());
forAll(lstA, i)
{
lstA[i] = i;
}
Info<< "lstA: " << lstA << endl;
Info<< "lstC: " << lstC << endl;
@ -72,10 +76,10 @@ int main(int argc, char *argv[])
Info<< "lstC: " << lstC << endl;
xB = xA;
List<label> lstD(xferCopy(lstC));
List<label> lstE(xferMove(lstC));
// this must be empty
List<label> lstF = xferCopy(lstC);
@ -88,12 +92,30 @@ int main(int argc, char *argv[])
Info<< "lstE: " << lstE << endl;
Info<< "lstF: " << lstF << endl;
Info<< "xB size: " << xB->size() << endl;
Info<< "xB[" << xB->size() << "]\n";
// clear the underlying List
xB->clear();
Info<< "xB size: " << xB->size() << endl;
Info<< "xB[" << xB->size() << "]\n";
DynamicList<label> dl(10);
for (label i = 0; i < 5; i++)
{
dl.append(i);
}
face f1(dl);
face f2(xferCopy<labelList>(dl));
Info<< "dl[" << dl.size() << "/" << dl.allocSize() << "] " << dl << endl;
Info<< "f1: " << f1 << endl;
Info<< "f2: " << f2 << endl;
// note: using xferMoveTo to ensure the correct transfer() method is called
face f3( xferMoveTo<labelList>(dl) );
Info<< "dl[" << dl.size() << "/" << dl.allocSize() << "] " << dl << endl;
Info<< "f3: " << f3 << endl;
return 0;
}

View File

@ -0,0 +1,726 @@
724 4 0
1 48 170 84 171
2 78 202 171 213
3 16 48 45 171
4 128 159 108 191
5 167 168 77 200
6 72 166 25 199
7 8 197 44 198
8 162 166 72 199
9 50 84 83 196
10 67 126 17 172
11 48 125 45 171
12 103 150 63 210
13 102 177 59 194
14 119 172 75 213
15 10 157 69 208
16 126 167 119 172
17 30 157 107 190
18 52 182 180 209
19 88 192 105 205
20 152 194 104 203
21 107 187 150 190
22 23 141 86 192
23 97 99 140 184
24 55 189 133 207
25 97 138 31 151
26 35 142 60 194
27 27 118 74 164
28 101 127 21 152
29 126 171 167 200
30 90 109 55 133
31 21 178 152 203
32 134 173 93 174
33 27 83 50 84
34 85 127 29 211
35 164 176 111 202
36 65 153 105 156
37 149 186 59 203
38 88 87 129 130
39 23 141 97 151
40 177 178 136 203
41 76 164 43 198
42 84 176 126 202
43 89 116 90 133
44 40 112 71 113
45 40 70 71 112
46 125 126 45 171
47 133 161 66 176
48 65 105 14 156
49 66 189 187 207
50 67 68 38 110
51 60 144 62 61
52 124 165 33 204
53 52 128 108 191
54 26 90 89 116
55 114 164 76 198
56 150 190 104 192
57 59 186 102 194
58 69 157 103 190
59 120 170 196 122
60 116 164 117 197
61 5 112 41 113
62 37 110 107 157
63 132 181 32 189
64 121 122 18 196
65 84 123 27 202
66 73 195 163 199
67 182 204 137 209
68 140 97 23 99
69 96 136 135 178
70 28 80 57 81
71 23 99 97 141
72 153 156 63 193
73 100 152 21 178
74 148 151 146 190
75 115 43 15 213
76 138 186 139 188
77 48 125 84 170
78 105 153 65 155
79 108 204 182 209
80 104 193 192 205
81 18 83 40 121
82 32 111 89 133
83 59 95 94 149
84 135 136 34 178
85 95 137 132 189
86 57 80 52 108
87 104 151 149 186
88 186 194 59 203
89 152 191 150 193
90 115 197 8 198
91 170 125 201 48
92 140 183 7 184
93 9 108 52 128
94 70 5 71 112
95 44 116 26 117
96 84 126 125 171
97 66 159 126 161
98 52 191 108 209
99 41 112 72 113
100 108 191 159 209
101 125 170 201 160
102 77 168 167 169
103 103 157 30 190
104 52 9 57 108
105 127 152 101 193
106 38 68 37 110
107 133 189 66 207
108 8 76 115 198
109 65 153 143 154
110 31 151 138 206
111 62 144 6 61
112 192 193 105 205
113 153 154 101 211
114 72 163 111 199
115 13 101 100 212
116 104 187 150 191
117 13 154 101 212
118 23 97 86 151
119 102 61 144 194
120 153 193 63 211
121 20 159 126 160
122 14 88 130 156
123 30 107 37 159
124 65 154 2 155
125 42 111 89 162
126 85 150 30 191
127 194 205 142 212
128 97 141 99 151
129 120 82 50 170
130 22 60 61 102
131 66 161 126 176
132 30 128 85 191
133 59 139 102 186
134 54 89 26 90
135 70 112 40 114
136 66 159 107 187
137 32 132 91 181
138 49 124 80 160
139 56 91 12 92
140 126 159 37 161
141 78 168 46 169
142 144 177 102 194
143 113 121 40 196
144 86 148 129 192
145 7 184 183 185
146 17 109 90 133
147 141 192 88 205
148 167 168 45 169
149 97 184 139 185
150 2 154 64 155
151 111 195 181 199
152 78 123 47 171
153 84 176 111 195
154 49 160 80 201
155 43 197 115 198
156 38 67 24 68
157 93 174 173 189
158 150 152 104 191
159 24 167 77 200
160 122 170 49 201
161 71 112 5 113
162 163 195 111 199
163 17 172 126 176
164 124 160 49 195
165 37 106 30 159
166 40 113 71 121
167 136 178 96 203
168 127 191 152 193
169 67 167 126 172
170 139 185 102 186
171 66 187 107 207
172 104 187 149 206
173 40 74 19 114
174 84 170 123 171
175 107 110 37 161
176 42 164 114 198
177 63 193 150 211
178 39 161 107 207
179 50 123 84 170
180 49 170 160 201
181 46 168 4 169
182 84 170 49 196
183 49 195 84 196
184 183 184 99 185
185 111 114 42 164
186 31 158 146 190
187 109 161 39 207
188 54 90 55 175
189 44 197 117 198
190 111 163 84 195
191 117 164 42 198
192 73 121 113 163
193 86 97 31 151
194 90 133 55 175
195 125 160 84 170
196 80 160 81 201
197 160 176 126 195
198 144 100 34 177
199 139 149 59 188
200 103 146 69 190
201 74 114 40 163
202 107 150 30 190
203 74 118 43 164
204 4 168 77 169
205 27 84 50 123
206 189 206 187 207
207 151 192 141 205
208 163 195 73 196
209 71 18 40 121
210 149 151 138 186
211 43 118 15 213
212 35 145 141 205
213 146 148 86 151
214 100 194 152 203
215 36 138 97 139
216 147 192 190 210
217 107 158 39 207
218 95 132 94 149
219 60 102 22 145
220 183 140 99 184
221 89 111 32 162
222 28 81 48 201
223 34 177 100 178
224 146 147 53 148
225 111 162 72 199
226 60 142 13 194
227 181 195 66 204
228 108 160 33 204
229 31 138 93 206
230 119 167 126 171
231 107 161 66 207
232 180 191 52 209
233 126 202 176 213
234 45 126 68 200
235 53 146 103 147
236 38 37 10 110
237 15 118 78 213
238 101 152 100 212
239 138 151 149 206
240 26 116 89 117
241 10 110 37 157
242 171 202 126 213
243 129 147 87 148
244 100 101 21 152
245 97 98 36 139
246 52 80 33 108
247 48 170 79 201
248 98 184 7 185
249 153 154 65 155
250 55 173 133 189
251 149 151 104 206
252 143 2 65 154
253 78 171 119 213
254 58 108 9 128
255 9 52 51 128
256 60 62 144 194
257 94 138 93 188
258 132 149 95 189
259 9 58 57 108
260 104 190 151 192
261 105 192 156 193
262 69 103 53 146
263 70 40 19 114
264 95 149 137 189
265 192 193 150 210
266 58 81 57 108
267 102 145 60 194
268 57 81 80 108
269 52 127 51 191
270 12 92 91 179
271 60 61 102 194
272 150 192 104 193
273 30 150 103 190
274 130 88 87 156
275 13 142 100 194
276 53 147 129 148
277 125 126 84 160
278 55 109 39 207
279 129 131 88 130
280 30 159 128 191
281 86 141 23 151
282 153 155 105 193
283 40 114 112 163
284 27 196 84 202
285 85 128 51 191
286 160 195 33 204
287 94 134 93 174
288 109 133 17 161
289 109 110 39 161
290 84 160 49 170
291 89 90 54 175
292 96 137 92 179
293 31 146 86 151
294 117 197 164 198
295 15 78 46 119
296 91 92 56 166
297 112 113 40 163
298 45 168 167 200
299 68 126 67 200
300 136 177 34 178
301 49 122 121 196
302 92 137 91 179
303 63 103 85 150
304 92 165 56 166
305 167 171 45 200
306 81 160 125 201
307 29 85 51 127
308 46 119 78 169
309 172 176 75 213
310 131 130 129 3
311 88 129 87 192
312 119 171 126 213
313 39 158 55 207
314 105 193 155 212
315 15 119 75 213
316 33 182 108 204
317 104 187 152 203
318 16 123 48 171
319 107 159 66 161
320 123 170 48 171
321 84 125 48 171
322 124 195 165 204
323 146 151 31 190
324 74 83 27 163
325 37 159 107 161
326 47 4 46 168
327 136 149 59 203
328 20 68 45 126
329 82 123 50 170
330 20 106 68 126
331 37 110 68 161
332 80 81 28 201
333 24 68 67 200
334 46 78 47 168
335 67 126 68 161
336 93 138 134 188
337 68 106 37 126
338 20 126 125 160
339 163 196 27 202
340 72 114 111 163
341 33 108 80 160
342 55 173 54 175
343 45 125 20 126
344 50 170 84 196
345 133 173 55 175
346 80 124 33 160
347 63 193 156 210
348 68 126 37 161
349 104 152 150 193
350 133 164 116 176
351 145 194 186 205
352 126 160 66 176
353 107 206 158 207
354 12 96 92 179
355 118 164 27 202
356 164 197 43 198
357 89 133 90 175
358 67 109 17 161
359 105 193 35 205
360 55 133 109 207
361 33 160 124 195
362 173 174 11 175
363 137 187 149 203
364 79 170 122 201
365 39 158 107 190
366 150 191 85 211
367 40 121 83 196
368 32 133 132 189
369 56 165 25 166
370 42 114 111 162
371 141 145 99 205
372 27 163 83 196
373 92 137 96 182
374 149 187 104 203
375 126 167 67 200
376 137 180 96 182
377 102 186 145 194
378 62 60 13 194
379 15 75 115 213
380 85 103 30 150
381 49 160 84 195
382 137 181 66 204
383 59 149 139 186
384 98 139 97 184
385 51 127 85 191
386 149 187 137 189
387 91 166 32 181
388 139 184 98 185
389 31 190 151 206
390 100 178 177 194
391 150 187 107 191
392 149 186 138 188
393 51 128 52 191
394 108 182 52 209
395 59 136 95 149
396 93 138 94 149
397 94 149 132 189
398 132 133 32 175
399 135 136 96 179
400 92 182 33 204
401 137 187 66 189
402 137 181 132 189
403 88 141 23 192
404 187 206 107 207
405 107 110 39 208
406 37 126 106 159
407 94 149 138 188
408 11 173 134 174
409 159 191 187 209
410 13 100 62 194
411 105 155 142 212
412 35 205 193 212
413 152 187 104 191
414 60 145 35 194
415 14 105 88 156
416 33 165 92 204
417 133 181 66 189
418 107 190 157 208
419 39 190 107 208
420 20 125 81 160
421 80 108 81 160
422 100 177 144 194
423 138 139 36 188
424 49 170 122 196
425 132 174 94 189
426 139 186 149 188
427 134 138 36 188
428 144 62 100 194
429 91 137 92 181
430 92 166 91 181
431 107 187 159 191
432 141 151 86 192
433 165 199 181 204
434 150 159 30 191
435 129 148 87 192
436 100 142 13 212
437 52 180 21 191
438 107 159 150 191
439 142 205 35 212
440 37 107 30 157
441 21 127 52 191
442 92 181 137 204
443 129 88 131 192
444 103 147 146 190
445 137 182 92 204
446 87 156 88 192
447 91 137 95 179
448 135 96 12 179
449 164 202 118 213
450 110 157 10 208
451 101 193 152 212
452 152 205 194 212
453 21 152 127 191
454 193 205 152 212
455 59 149 94 188
456 30 106 58 159
457 67 110 109 161
458 68 110 67 161
459 66 204 108 209
460 32 181 133 189
461 17 126 67 161
462 106 126 20 159
463 111 114 72 162
464 40 83 74 163
465 48 79 28 201
466 30 150 107 159
467 108 128 58 159
468 58 128 30 159
469 39 110 107 161
470 83 121 18 196
471 134 94 93 188
472 86 129 131 192
473 126 159 66 160
474 66 159 108 160
475 166 181 165 199
476 186 194 104 205
477 81 108 58 160
478 108 159 58 160
479 81 106 20 160
480 106 159 20 160
481 99 186 151 205
482 52 108 33 182
483 178 194 100 203
484 78 169 119 171
485 58 106 81 160
486 58 159 106 160
487 112 114 72 163
488 111 164 133 176
489 54 173 11 175
490 177 194 178 203
491 25 166 165 199
492 19 74 43 164
493 19 114 74 164
494 111 163 114 164
495 114 163 74 164
496 152 178 100 203
497 111 181 162 199
498 76 19 43 164
499 76 114 19 164
500 89 117 116 164
501 116 133 89 164
502 42 117 89 164
503 89 111 42 164
504 89 133 111 164
505 48 82 79 170
506 82 48 16 170
507 48 123 16 170
508 16 123 82 170
509 43 115 76 198
510 75 164 116 197
511 126 171 84 202
512 84 196 163 202
513 84 171 123 202
514 78 118 27 202
515 120 1 82 170
516 120 122 1 170
517 82 1 79 170
518 1 122 79 170
519 47 168 78 171
520 45 168 47 171
521 16 45 47 171
522 47 123 16 171
523 59 194 177 203
524 152 191 21 203
525 32 133 89 175
526 104 186 149 203
527 119 169 167 171
528 167 169 45 171
529 45 169 168 171
530 168 169 78 171
531 104 194 186 203
532 59 177 136 203
533 137 149 95 203
534 95 149 136 203
535 17 161 133 176
536 126 161 17 176
537 116 164 75 176
538 75 172 116 176
539 90 133 116 176
540 116 172 90 176
541 17 133 90 176
542 90 172 17 176
543 150 193 63 210
544 195 199 165 204
545 66 181 137 189
546 81 125 48 201
547 165 166 92 181
548 32 162 111 181
549 32 166 162 181
550 45 171 126 200
551 111 133 32 181
552 147 148 146 190
553 105 156 153 193
554 66 161 133 207
555 91 132 95 181
556 132 137 95 181
557 95 137 91 181
558 99 151 141 205
559 111 176 133 181
560 133 176 66 181
561 66 176 111 181
562 40 163 113 196
563 145 186 99 205
564 88 105 35 205
565 113 163 121 196
566 84 195 163 196
567 121 163 73 196
568 187 191 152 203
569 83 163 40 196
570 83 84 27 196
571 138 149 93 206
572 107 190 158 206
573 97 151 99 186
574 144 61 60 194
575 187 190 107 206
576 157 190 69 208
577 22 145 102 186
578 102 185 22 186
579 104 192 151 205
580 126 176 84 195
581 67 167 24 200
582 116 117 44 197
583 97 139 138 186
584 138 151 97 186
585 162 181 166 199
586 66 181 111 195
587 99 145 22 186
588 97 185 139 186
589 66 176 160 195
590 183 99 22 186
591 183 185 99 186
592 22 185 183 186
593 99 184 97 186
594 99 185 184 186
595 184 185 97 186
596 111 176 66 195
597 84 160 126 195
598 35 141 88 205
599 87 148 147 192
600 137 204 66 209
601 86 151 148 192
602 181 199 195 204
603 174 175 173 189
604 173 175 133 189
605 132 175 174 189
606 133 175 132 189
607 133 161 109 207
608 159 187 66 209
609 93 149 94 189
610 94 174 93 189
611 146 190 158 208
612 158 190 39 208
613 66 187 137 209
614 180 182 137 209
615 108 159 66 209
616 190 192 150 210
617 85 191 127 211
618 127 193 101 211
619 101 193 153 211
620 103 190 150 210
621 69 190 146 208
622 88 156 105 192
623 63 150 85 211
624 23 131 88 192
625 86 131 23 192
626 151 190 148 192
627 148 190 147 192
628 101 154 143 211
629 29 127 101 211
630 29 101 143 211
631 143 154 153 211
632 78 119 15 213
633 118 202 78 213
634 33 195 124 204
635 93 158 31 206
636 158 190 31 206
637 107 157 110 208
638 66 160 108 204
639 165 181 92 204
640 66 195 160 204
641 156 193 192 210
642 149 189 93 206
643 187 189 149 206
644 170 120 196 50
645 73 124 121 196
646 73 195 124 196
647 121 124 49 196
648 124 195 49 196
649 50 83 18 196
650 50 18 120 196
651 18 122 120 196
652 151 186 104 205
653 73 165 124 199
654 165 195 124 199
655 124 195 73 199
656 73 163 113 199
657 25 165 73 199
658 73 113 41 199
659 41 113 72 199
660 113 72 163 112
661 72 113 163 199
662 41 72 25 199
663 25 73 41 199
664 111 176 84 202
665 27 123 78 202
666 123 171 78 202
667 84 163 111 202
668 163 164 111 202
669 74 163 27 202
670 74 164 163 202
671 27 164 74 202
672 95 179 137 203
673 136 179 95 203
674 137 179 96 203
675 96 179 136 203
676 96 178 21 203
677 147 190 103 210
678 156 192 87 210
679 87 192 147 210
680 96 180 137 203
681 21 180 96 203
682 35 194 145 205
683 43 164 118 213
684 142 194 35 205
685 152 193 104 205
686 104 194 152 205
687 126 176 172 213
688 126 172 119 213
689 151 190 104 206
690 150 187 104 206
691 150 190 187 206
692 104 190 150 206
693 93 206 189 207
694 158 206 93 207
695 158 173 55 207
696 173 189 55 207
697 93 173 158 207
698 93 189 173 207
699 187 203 137 209
700 137 203 180 209
701 191 203 187 209
702 21 191 180 209
703 21 203 191 209
704 180 203 21 209
705 150 193 191 211
706 191 193 127 211
707 13 142 64 212
708 64 154 13 212
709 152 194 100 212
710 100 194 142 212
711 105 142 35 212
712 35 193 105 212
713 64 155 154 212
714 142 155 64 212
715 154 155 153 212
716 155 193 153 212
717 101 154 153 212
718 153 193 101 212
719 75 176 164 213
720 176 202 164 213
721 43 197 164 213
722 164 197 75 213
723 75 197 115 213
724 115 197 43 213
# Generated by tetgen -qfa0.005 beam.poly

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,215 @@
213 3 0 0
1 0 0 0
2 2 0 0
3 2 1 0
4 0 1 0
5 0 0 1
6 2 0 1
7 2 1 1
8 0 1 1
9 1.0000469999999999 0 0
10 0.999668 1 0
11 0.99944500000000003 1 1
12 1.000594 0 1
13 2 0 0.50021530000000003
14 2 0.50012599999999996 0
15 0 1 0.50045629999999997
16 0 0.49964989999999998 0
17 0.62483357601847556 1 0.49991643678795222
18 0 0 0.5
19 0 0.5 1
20 0.62494657145582122 0.49985790875808178 0
21 1.375120204581187 0 0.4997949845615941
22 2 0.5 1
23 2 1 0.5
24 0.499834 1 0
25 0.50029699999999999 0 1
26 0.49972250000000001 1 1
27 0 0.50000006130646835 0.49999993869353165
28 0.50002349999999995 0 0
29 1.5000235 0 0
30 1.1458145624989733 0.5000553177266871 0
31 1.3748336567109987 1 0.5000836868059465
32 0.75044549999999999 0.49971323947400004 1
33 0.75044549999999999 0 0.50013668162500002
34 1.500297 0 1
35 2 0.49999999206099965 0.49999999206099965
36 1.4997225000000001 1 1
37 0.88530655619767451 0.69523571541331353 0
38 0.74975100000000006 1 0
39 0.99985800700011418 1 0.39062501526316751
40 0 0.2500000613064608 0.7499999386935392
41 0.2501485 0 1
42 0.37527044007359472 0.62466041202689604 1
43 0 0.7497720581817594 0.74999999997204392
44 0.24986125000000001 1 1
45 0.31241083060970776 0.68739558038665782 0
46 0 1 0.25022814999999998
47 0 0.74982495000000005 0
48 0.3125356465289606 0.31239559711921033 0
49 0.37524548555134551 0 0.37523962153691648
50 0 0.25000000002145584 0.25017492745143088
51 1.2500352499999998 0 0
52 1.0626973305232652 0 0.34361890927552119
53 1.4998339999999999 1 0
54 0.74958374999999999 1 1
55 0.88519156134454835 1 0.69523493182271912
56 0.75044549999999999 0 1
57 0.75003524999999993 0 0
58 0.88545457775712011 0.3046775110714553 0
59 1.4999999173907641 0.49999999435116604 1
60 2 0.25010760364761792 0.74999999999829137
61 2 0.25 1
62 2 0 0.75010765000000001
63 1.5729133203896351 0.4271084905205621 0
64 2 0 0.25010765000000001
65 2 0.25006299999999998 0
66 0.81619988117037301 0.51616065956439328 0.48387527405505287
67 0.62479250000000008 1 0.23434098330631092
68 0.62479250000000008 0.7655391212272894 0
69 1.2497509999999998 1 0
70 0 0.25 1
71 0 0 0.75
72 0.37522274999999999 0.29980854989635936 1
73 0.37522274999999999 0 0.70013946473134281
74 0 0.49988605975809192 0.74988593714516283
75 0.31255174452459605 1 0.65638401293888804
76 0 0.75 1
77 0.249917 1 0
78 0 0.70831779089254521 0.29167340665919461
79 0.25001174999999998 0 0
80 0.62526649037406934 0 0.25017085386153537
81 0.625029375 0.23429805042184107 0
82 0 0.24982494999999999 0
83 0 0.25008755567468249 0.50008743306175329
84 0.33552291795286748 0.37713361953826796 0.37295234921245662
85 1.3275022682494733 0.27703395451399626 0
86 1.6873917295541676 1 0.31254602883562033
87 1.7393002110516891 0.73944000928409781 0
88 2 0.7499999999989998 0.25006298412499983
89 0.62528740222670842 0.74964177558619371 1
90 0.62465312500000003 1 0.76556323888302447
91 0.87551975000000004 0.24985661973700002 1
92 0.87551975000000004 0 0.75006834081249996
93 1.1922864636768418 1 0.75390684273024755
94 1.24958375 0.74986113453803516 1
95 1.1698804466514103 0.41956399899988917 1
96 1.187959730551635 0 0.74997433471920583
97 1.6874419282782818 1 0.68754603555472626
98 1.7498612499999999 1 1
99 2 0.74999999206099988 0.74999999206099988
100 1.6597700161872737 0 0.69432640578660343
101 1.6597808229817657 0 0.30542952755181008
102 1.7499999601075902 0.375 1
103 1.3990667318832528 0.69603906683685635 0
104 1.4950021306707608 0.49065317884606224 0.49500212996719484
105 2 0.37509449999999989 0.24996850198475024
106 0.82837583873678577 0.49993500845038119 0
107 1.0695558475797649 0.66971322958604163 0.29687786818700823
108 0.85307867962811157 0.24362257622712302 0.31516017245746403
109 0.82827226523186892 1 0.49992109713449329
110 0.85617934854666022 1 0.20723770847200895
111 0.52956259724790877 0.46221182650782827 0.70815142735106607
112 0.197844687328108 0.19781366296788089 1
113 0.19785716305721113 0 0.8021738538924329
114 0.2208783106844166 0.46225714309073845 1
115 0 1 0.75022814999999998
116 0.43264896150206789 1 0.81375076634557386
117 0.374791875 0.83312128766119486 1
118 0 0.72915434172921567 0.52082680685839422
119 0.25758862433333551 1 0.37534222499999997
120 0 0 0.25
121 0.22089000562634489 0 0.53767874257955828
122 0.21890193241166289 0 0.21890047052636122
123 0 0.48262354769989868 0.23265983080935737
124 0.52955330709238257 0 0.53770034194467331
125 0.49219718763882514 0.367036574432759 0
126 0.5505556528350013 0.63265541955504201 0.30493806376468496
127 1.4081582558189005 0 0.24254676799800692
128 1.1015512434437607 0.21206527974784434 0
129 1.7499169999999999 1 0
130 2 0.75006299999999992 0
131 2 1 0.25
132 0.99401036538229792 0.63676792199224752 1
133 0.75067050430146165 0.71769786903092825 0.71464771158468776
134 1.24958375 1 1
135 1.2504455000000001 0 1
136 1.3860715978416591 0.24993221667186555 1
137 1.0317202752404047 0.31469238410894046 0.6853270709080328
138 1.4426349216014702 1 0.74140038799848562
139 1.6247918750000001 0.75006931305374525 1
140 2 1 0.75
141 2 0.74996849602949978 0.50003148809249964
142 2 0.24999994966813449 0.49999998078418173
143 1.7500117500000001 0 0
144 1.7501484999999999 0 1
145 2 0.5000537978534545 0.74994618626854503
146 1.3747924999999996 1 0.23440908488585499
147 1.5571177737167572 0.81232629338982021 0
148 1.5545253193695066 1 0.17972930755262501
149 1.3104200347998118 0.56041577372755713 0.74814782862252316
150 1.3685266838244452 0.48564116582667954 0.21802764397288932
151 1.5873602781685263 0.78126669962189421 0.50005942609143139
152 1.5838618227448735 0.20899413185535243 0.49987585715718413
153 1.7498120256325995 0.25018792583716926 0
154 1.8148371462917434 0 0.18519382949207305
155 2 0.18752406345187056 0.18753523208397008
156 1.7770110643184227 0.51886547556217666 0
157 1.1389013076817112 0.76226887437066193 0
158 1.1602175406966813 1 0.53828850106094039
159 0.90095306490776128 0.48470516503498373 0.2446998657917499
160 0.57742475390278236 0.27551969863450299 0.27345305390889807
161 0.81036655925196366 0.7630643710333207 0.35054165377955776
162 0.52956259724790877 0.46221182650782827 1
163 0.29250079461431827 0.2842960350422109 0.71570127112180726
164 0.27385619515889037 0.6248453002643185 0.71436194557321087
165 0.62168045737651678 0 0.77560610491729931
166 0.62537124999999993 0.2188435803315899 1
167 0.40196038774740384 1 0.20267603513549107
168 0.17704223351222992 0.82288246470050785 0
169 0.18892018646284411 1 0.18899622733072144
170 0.23373058746113159 0.23679172957531613 0.21078402860060638
171 0.24428427259573549 0.59937304517793366 0.24724219230200442
172 0.42388190576270124 1 0.4887158204143946
173 1.0208555875954755 1 0.81817459887813815
174 1.0669175695053206 0.81733378836053194 1
175 0.8464712840664248 0.80134170756139955 1
176 0.60552202714220704 0.62419153018194229 0.54239960836207701
177 1.606777848712118 0.19973253606683206 1
178 1.4250560553222698 0 0.732249791887851
179 1.12551975 0.19352873225326209 1
180 1.1620342234529084 0 0.53548179044497457
181 0.77419059143108437 0.35536625456813642 0.76865650139332142
182 0.95600842566592681 0 0.52050427577014857
183 2 0.75 1
184 1.8229055680968635 1 0.82294606919028224
185 1.8124074661770861 0.8124421408239394 1
186 1.6847465495324894 0.55699324455967203 0.74450659675858755
187 1.1945125727535346 0.47020737648361044 0.48501348343009743
188 1.4371531545555845 0.81243056656291324 1
189 1.0230031981183827 0.60745624022002409 0.70905352953001077
190 1.3178218537541635 0.74283221838842173 0.24644567916733129
191 1.2298563370114035 0.23209604059822986 0.27403980288191482
192 1.7289412043422971 0.73378563235104455 0.27218740896208421
193 1.6944192651948711 0.39497422853539144 0.28096087015676863
194 1.719021973042385 0.27206088666699435 0.73925099693622187
195 0.51628118103442489 0.26487001488387318 0.53136856951372224
196 0.22693818747394334 0.22584860839480125 0.50499300132112901
197 0.18870598201308805 1 0.81131589108741564
198 0.18140974929389231 0.81855222162009078 1
199 0.52377345173705003 0.22575111801259504 0.77599180569982884
200 0.44512574719134834 0.82031319413422632 0
201 0.43769402753141229 0 0.18763960779463965
202 0.23194582827732274 0.56348972010969589 0.48517047319960538
203 1.404605953982319 0.2885118284317002 0.71332319773860509
204 0.83285106746651061 0.22679389369216291 0.56316489552371896
205 1.746191712341544 0.57096666984982924 0.48834249131610469
206 1.2698479063322867 0.73902081556323673 0.53223169180184582
207 1.0027339377070847 0.7783240018776667 0.51915438810718473
208 1.1247094999999998 1 0.19525173141898322
209 1.0585177272595161 0.22306568484158776 0.45497453797743681
210 1.5766743500280587 0.62019545180903912 0
211 1.5362846212581589 0.2135856104587727 0
212 1.7956396187713533 0.19223457391785517 0.37621602432494938
213 0.2338562054207384 0.80644498148268706 0.52587899633894741
# Generated by tetgen -qfa0.005 beam.poly

View File

@ -154,10 +154,77 @@ void insertDuplicateMerge
}
labelList findBaffles(const polyMesh& mesh, const labelList& boundaryFaces)
{
// Get all duplicate face labels (in boundaryFaces indices!).
labelList duplicates = localPointRegion::findDuplicateFaces
(
mesh,
boundaryFaces
);
// Check that none are on processor patches
const polyBoundaryMesh& patches = mesh.boundaryMesh();
forAll(duplicates, bFaceI)
{
if (duplicates[bFaceI] != -1)
{
label faceI = mesh.nInternalFaces() + bFaceI;
label patchI = patches.whichPatch(faceI);
if (isA<processorPolyPatch>(patches[patchI]))
{
FatalErrorIn("findBaffles(const polyMesh&, const labelList&)")
<< "Duplicate face " << faceI
<< " is on a processorPolyPatch."
<< "This is not allowed." << nl
<< "Face:" << faceI
<< " is on patch:" << patches[patchI].name()
<< abort(FatalError);
}
}
}
// Write to faceSet for ease of postprocessing.
{
faceSet duplicateSet
(
mesh,
"duplicateFaces",
(mesh.nFaces() - mesh.nInternalFaces())/256
);
forAll(duplicates, bFaceI)
{
label otherFaceI = duplicates[bFaceI];
if (otherFaceI != -1 && otherFaceI > bFaceI)
{
duplicateSet.insert(mesh.nInternalFaces() + bFaceI);
duplicateSet.insert(mesh.nInternalFaces() + otherFaceI);
}
}
Pout<< "Writing " << duplicateSet.size()
<< " duplicate faces to faceSet " << duplicateSet.objectPath()
<< nl << endl;
duplicateSet.write();
}
return duplicates;
}
int main(int argc, char *argv[])
{
argList::validOptions.insert("split", "");
argList::validOptions.insert("overwrite", "");
argList::validOptions.insert("detectOnly", "");
# include "setRootCase.H"
# include "createTime.H"
runTime.functionObjects().off();
@ -165,6 +232,7 @@ int main(int argc, char *argv[])
bool split = args.options().found("split");
bool overwrite = args.options().found("overwrite");
bool detectOnly = args.options().found("detectOnly");
// Collect all boundary faces
labelList boundaryFaces(mesh.nFaces() - mesh.nInternalFaces());
@ -175,6 +243,15 @@ int main(int argc, char *argv[])
}
if (detectOnly)
{
findBaffles(mesh, boundaryFaces);
return 0;
}
// Read objects in time directory
IOobjectList objects(mesh, runTime.timeName());
@ -238,62 +315,7 @@ int main(int argc, char *argv[])
<< nl << endl;
// Get all duplicate face labels (in boundaryFaces indices!).
labelList duplicates = localPointRegion::findDuplicateFaces
(
mesh,
boundaryFaces
);
// Check that none are on processor patches
const polyBoundaryMesh& patches = mesh.boundaryMesh();
forAll(duplicates, bFaceI)
{
if (duplicates[bFaceI] != -1)
{
label faceI = mesh.nInternalFaces() + bFaceI;
label patchI = patches.whichPatch(faceI);
if (isA<processorPolyPatch>(patches[patchI]))
{
FatalErrorIn(args.executable())
<< "Duplicate face " << faceI
<< " is on a processorPolyPatch."
<< "This is not allowed." << nl
<< "Face:" << faceI
<< " is on patch:" << patches[patchI].name()
<< abort(FatalError);
}
}
}
// Write to faceSet for ease of postprocessing.
{
faceSet duplicateSet
(
mesh,
"duplicateFaces",
(mesh.nFaces() - mesh.nInternalFaces())/256
);
forAll(duplicates, bFaceI)
{
label otherFaceI = duplicates[bFaceI];
if (otherFaceI != -1 && otherFaceI > bFaceI)
{
duplicateSet.insert(mesh.nInternalFaces() + bFaceI);
duplicateSet.insert(mesh.nInternalFaces() + otherFaceI);
}
}
Pout<< "Writing " << duplicateSet.size()
<< " duplicate faces to faceSet " << duplicateSet.objectPath()
<< nl << endl;
duplicateSet.write();
}
labelList duplicates(findBaffles(mesh, boundaryFaces));
// Merge into internal faces.
insertDuplicateMerge(mesh, duplicates, meshMod);

View File

@ -316,11 +316,10 @@ autoPtr<mapPolyMesh> reorderMesh
mesh.resetPrimitives
(
mesh.nFaces(),
mesh.points(),
newFaces,
newOwner,
newNeighbour,
xfer<pointField>::null(),
xferMove(newFaces),
xferMove(newOwner),
xferMove(newNeighbour),
patchSizes,
patchStarts
);

View File

@ -714,9 +714,11 @@ commandStatus parseAction(const word& actionName)
int main(int argc, char *argv[])
{
# include "addRegionOption.H"
# include "addTimeOptions.H"
argList::validOptions.insert("noVTK", "");
argList::validOptions.insert("batch", "file");
# include "addTimeOptions.H"
# include "setRootCase.H"
# include "createTime.H"
@ -730,7 +732,7 @@ int main(int argc, char *argv[])
runTime.setTime(Times[startTime], startTime);
# include "createPolyMesh.H"
# include "createNamedPolyMesh.H"
// Print some mesh info
printMesh(runTime, mesh);

View File

@ -79,12 +79,12 @@ int main(int argc, char *argv[])
Info<< " Reading volScalarField " << fieldName << endl;
volScalarField field(fieldHeader, mesh);
scalar area = sum(mesh.magSf().boundaryField()[patchi]);
scalar area = gSum(mesh.magSf().boundaryField()[patchi]);
scalar sumField = 0;
if (area > 0)
{
sumField = sum
sumField = gSum
(
mesh.magSf().boundaryField()[patchi]
* field.boundaryField()[patchi]

View File

@ -75,14 +75,14 @@ int main(int argc, char *argv[])
}
// Give patch area
Info<< " Patch area = " << sum(mesh.Sf().boundaryField()[patchi]) << endl;
Info<< " Patch area = " << gSum(mesh.Sf().boundaryField()[patchi]) << endl;
if (fieldHeader.headerClassName() == "volScalarField")
{
Info<< " Reading volScalarField " << fieldName << endl;
volScalarField field(fieldHeader, mesh);
vector sumField = sum
vector sumField = gSum
(
mesh.Sf().boundaryField()[patchi]
* field.boundaryField()[patchi]
@ -97,7 +97,7 @@ int main(int argc, char *argv[])
Info<< " Reading surfaceScalarField " << fieldName << endl;
surfaceScalarField field(fieldHeader, mesh);
scalar sumField = sum(field.boundaryField()[patchi]);
scalar sumField = gSum(field.boundaryField()[patchi]);
Info<< " Integral of " << fieldName << " over patch "
<< patchName << '[' << patchi << ']' << " = "

View File

@ -1,40 +1,46 @@
09/01/04
2008-10-23
Contents:
surfaceAdd
adds to surface files. (but does not intersect or anything)
- adds to surface files. (but does not intersect or anything)
surfaceBooleanOp
Boolean operations (add, or, xor) on closed surfaces. Probably not working.
- Boolean operations (add, or, xor) on closed surfaces. Probably not working.
surfaceCheck
checks surface for incorrect topology. Checks normals of neighbouring faces.
- checks surface for incorrect topology. Checks normals of neighbouring faces.
surfaceCoarsen
Stan Melax coarsening algorithm
- Stan Melax coarsening algorithm
surfaceConvert
Converts surfaces to/from various formats
- Converts surfaces to/from various formats
surfaceFind
Finds nearest vertex and face to given point.
- Finds nearest vertex and face to given point.
surfaceMeshTriangulate
Triangulate external facses of mesh and write as surface.
- Triangulate external facses of mesh and write as surface.
surfacePointMerge
Explicit point merge of surface.
- Explicit point merge of surface.
surfaceSetOutside
Orient normals on (closed) surface.
- Orient normals on (closed) surface.
surfaceSmooth
Laplacian smoothing on surface vertices
- Laplacian smoothing on surface vertices
surfaceSubset
Subsets surface
- Subsets surface
surfaceToPatch
Applies region information of surfaces to mesh. Each external face of mesh
gets region number of nearest surface triangle.
- Applies region information of surfaces to mesh.
Each external face of mesh gets region number of nearest surface triangle.
-------------------------------------------------------------------------------
surfaceMeshConvert
- Similar to surfaceConvert, but uses surfMesh library

View File

@ -0,0 +1,3 @@
surfaceMeshConvert.C
EXE = $(FOAM_APPBIN)/surfaceMeshConvert

View File

@ -0,0 +1,5 @@
EXE_INC = \
-I$(LIB_SRC)/triSurface/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude
EXE_LIBS = -lsurfMesh

View File

@ -0,0 +1,145 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Application
surfaceMeshConvert
Description
Converts from one surface mesh format to another
Usage
- surfaceMeshConvert inputFile outputFile [OPTION]
@param -clean \n
Perform some surface checking/cleanup on the input surface
@param -scale \<scale\> \n
Specify a scaling factor for writing the files
@param -triSurface \n
Use triSurface library for input/output
Note
The filename extensions are used to determine the file format type.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "timeSelector.H"
#include "Time.H"
#include "polyMesh.H"
#include "meshedSurface.H"
#include "triSurface.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
argList::validArgs.append("inputFile");
argList::validArgs.append("outputFile");
argList::validOptions.insert("scale", "scale");
argList::validOptions.insert("clean", "");
argList::validOptions.insert("triSurface", "");
# include "setRootCase.H"
const stringList& params = args.additionalArgs();
scalar scaleFactor = 0;
if (args.options().found("scale"))
{
IStringStream(args.options()["scale"])() >> scaleFactor;
}
fileName importName(params[0]);
fileName exportName(params[1]);
if
(
!meshedSurface::canRead(importName.ext(), true)
|| !meshedSurface::canWrite(exportName.ext(), true)
)
{
return 1;
}
if (args.options().found("triSurface"))
{
// # include "createTime.H"
// instantList timeDirs = timeSelector::select0(runTime, args);
// # include "createPolyMesh.H"
triSurface surf(importName);
if (args.options().found("clean"))
{
surf.cleanup(true);
surf.checkOrientation(true);
}
Info << "writing " << exportName;
if (scaleFactor <= 0)
{
Info<< " without scaling" << endl;
}
else
{
Info<< " triSurface does not yet support scaling "
<< scaleFactor << endl;
// surf.scalePoints(scaleFactor);
}
surf.write(exportName);
}
else
{
meshedSurface surf(importName);
if (args.options().found("clean"))
{
surf.cleanup(true);
surf.checkOrientation(true);
}
surf.scalePoints(scaleFactor);
Info<< "writing " << exportName;
if (scaleFactor <= 0)
{
Info<< " without scaling" << endl;
}
else
{
Info<< " with scaling " << scaleFactor << endl;
}
surf.write(exportName);
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -36,7 +36,7 @@ usage() {
usage: ${0##*/} <type> {args}
* create a new standard OpenFOAM source file
* create a new standard OpenFOAM source or template file
type: (source|template)
@ -46,25 +46,24 @@ USAGE
if [ "$#" -lt 2 ]
then
usage "wrong number of arguments, expected 2 (or more)"
usage "wrong number of arguments, expected 2 (or more)"
fi
case "$1" in
-h | -help)
usage
;;
usage
;;
source)
shift
$WM_PROJECT_DIR/bin/foamTemplates/source/newSource $*
;;
shift
$WM_PROJECT_DIR/bin/foamTemplates/source/newSource $*
;;
template)
shift
$WM_PROJECT_DIR/bin/foamTemplates/sourceTemplate/newSourceTemplate $*
;;
shift
$WM_PROJECT_DIR/bin/foamTemplates/sourceTemplate/newSourceTemplate $*
;;
*)
usage "unknown type"
;;
usage "unknown type"
;;
esac
#------------------------------------------------------------------------------

View File

@ -38,20 +38,20 @@ packFile=${packDir}_${timeStamp}.gtgz
if [ ! -d $packDir ]
then
echo "Error: directory $packDir does not exist"
exit 1
echo "Error: directory $packDir does not exist" 1>&2
exit 1
fi
# add optional output directory
if [ -d "$1" ]
then
packFile="$1/$packFile"
packFile="$1/$packFile"
fi
if [ -f $packFile ]
then
echo "Error: $packFile already exists"
exit 1
echo "Error: $packFile already exists" 1>&2
exit 1
fi
# Create time stamp file
@ -102,10 +102,10 @@ tar czpf $packFile --files-from $tmpFile
if [ $? = 0 ]
then
echo "Finished packing and compressing $packDir into file $packFile"
echo "Finished packing and compressing $packDir into file $packFile"
else
echo "Error: failure packing $packDir into file $packFile"
rm -f $packFile 2>/dev/null
echo "Error: failure packing $packDir into file $packFile" 1>&2
rm -f $packFile 2>/dev/null
fi
#------------------------------------------------------------------------------

View File

@ -34,6 +34,7 @@ packDir=$WM_PROJECT-$WM_PROJECT_VERSION
packTag=_Doxygen.gtgz
usage() {
while [ $# -gt 0 ]; do echo "$1" 1>&2; shift; done
cat <<USAGE 1>&2
Usage: ${0##*/} [-prefix DIR] [-o outputDir]
@ -47,38 +48,38 @@ unset prefix outputDir
while [ "$#" -gt 0 ]
do
case $1 in
-prefix | --prefix )
prefix=${2%%/}
shift 2
;;
-o | -output )
outputDir=${2%%/}
shift 2
;;
-h | -help )
usage
;;
-*)
usage "unknown option: '$*'"
;;
esac
case $1 in
-prefix | --prefix )
prefix=${2%%/}
shift 2
;;
-o | -output )
outputDir=${2%%/}
shift 2
;;
-h | -help )
usage
;;
-*)
usage "unknown option: '$*'"
;;
esac
done
# if packing from within the directory, use -prefix form
if [ "${PWD##*/}" = "$packDir" ]
then
: ${prefix:=$packDir}
: ${prefix:=$packDir}
fi
# pack the directories directly and add prefix afterwards
if [ -n "$prefix" ]
then
packDir="$prefix"
packDir="$prefix"
elif [ ! -d $packDir ]
then
echo "Error: directory $packDir does not exist"
exit 1
echo "Error: directory $packDir does not exist" 1>&2
exit 1
fi
#

View File

@ -36,26 +36,25 @@
foamVersion=$WM_PROJECT_VERSION
usage() {
cat<<USAGE
cat<<USAGE
usage: ${0##*/} [OPTION] <file1> ... <fileN>
options:
-v "<version>" specifies the version to be written in the header
-h help
-v VER specifies the version to be written in the header
-h help
Updates the header of application files.
Updates the header of application files and removes consecutive blank lines.
By default, writes current version in the header.
Alternatively version can be specified with -v option.
Also removes consecutive blank lines from file.
An alternative version can be specified with -v option.
USAGE
exit 1
exit 1
}
printHeader() {
cat<<HEADER
cat<<HEADER
/*--------------------------------*- C++ -*----------------------------------*\\
| ========= | |
| \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
@ -78,7 +77,7 @@ HEADER
# extract attribute '$1' from file '$2'
#
FoamFileAttribute() {
sed -n -e 's/[ ;]*$//' -e "s/^ *$1 *//p" $2
sed -n -e 's/[ ;]*$//' -e "s/^ *$1 *//p" $2
}
@ -88,22 +87,22 @@ FoamFileAttribute() {
OPTS=`getopt hv: $*`
if [ $? -ne 0 ]
then
echo "Aborting due to invalid option"
usage
echo "Aborting due to invalid option"
usage
fi
eval set -- '$OPTS'
while [ "$1" != "--" ]
do
case $1 in
-v)
foamVersion=$2
shift
;;
-h)
usage
;;
esac
shift
case $1 in
-v)
foamVersion=$2
shift
;;
-h)
usage
;;
esac
shift
done
shift
@ -118,24 +117,24 @@ foamVersion=`printf %-36s $foamVersion`
#
for caseFile
do
if grep FoamFile $caseFile >/dev/null 2>&1
then
echo "Updating case file: $caseFile"
sed -n '/FoamFile/,/}/p' $caseFile > FoamFile.tmp
if grep FoamFile $caseFile >/dev/null 2>&1
then
echo "Updating case file: $caseFile"
sed -n '/FoamFile/,/}/p' $caseFile > FoamFile.tmp
CLASS=`FoamFileAttribute class FoamFile.tmp`
OBJECT=`FoamFileAttribute object FoamFile.tmp`
FORMAT=`FoamFileAttribute format FoamFile.tmp`
CLASS=`FoamFileAttribute class FoamFile.tmp`
OBJECT=`FoamFileAttribute object FoamFile.tmp`
FORMAT=`FoamFileAttribute format FoamFile.tmp`
printHeader $FORMAT $CLASS $OBJECT $NOTE > FoamFile.tmp
sed '1,/}/d' $caseFile | sed '/./,/^$/!d' >> FoamFile.tmp
printHeader $FORMAT $CLASS $OBJECT $NOTE > FoamFile.tmp
sed '1,/}/d' $caseFile | sed '/./,/^$/!d' >> FoamFile.tmp
# use cat to avoid removing/replace soft-links
[ -s FoamFile.tmp ] && cat FoamFile.tmp >| $caseFile
rm FoamFile.tmp
else
echo " Invalid case file: $caseFile"
fi
# use cat to avoid removing/replace soft-links
[ -s FoamFile.tmp ] && cat FoamFile.tmp >| $caseFile
rm FoamFile.tmp
else
echo " Invalid case file: $caseFile" 1>&2
fi
done
#------------------------------------------------------------------------------

View File

@ -37,7 +37,7 @@
#------------------------------------------------------------------------------
usage() {
cat<<USAGE
cat<<USAGE
usage: ${0##*/} <turbulenceProperties>
@ -57,42 +57,42 @@ USAGE
#
convertDict()
{
echo "Identified $1 turbulence model in '$3'"
outputPath=`dirname $3`
echo "Identified $1 turbulence model in '$3'"
outputPath=`dirname $3`
if [ -e "$outputPath/$1Properties" ]
then
echo "Error: file already exists $outputPath/$1Properties'"
else
sed -e "s/turbulenceProperties/$1Properties/" \
-e "s/$2/$1Model/" \
-e "s/[a-zA-Z0-9]* [ ]*\[[0-9 ]*\]//" \
$3 > "$outputPath/$1Properties"
if [ -e "$outputPath/$1Properties" ]
then
echo "Error: file already exists $outputPath/$1Properties'" 1>&2
else
sed -e "s/turbulenceProperties/$1Properties/" \
-e "s/$2/$1Model/" \
-e "s/[a-zA-Z0-9]* [ ]*\[[0-9 ]*\]//" \
$3 > "$outputPath/$1Properties"
echo " wrote $outputPath/$1Properties"
fi
echo " wrote $outputPath/$1Properties"
fi
}
[ $# -ge 1 ] || usage
for turbDict
do
# Identify type of turbulence model and convert
if [ -f $turbDict ]
then
if grep turbulenceModel $turbDict >/dev/null 2>&1
then
convertDict RAS turbulenceModel $turbDict
elif grep LESmodel $turbDict >/dev/null 2>&1
then
convertDict LES LESmodel $turbDict
else
echo "Unable to determine turbulence model type in '$turbDict'"
echo " - nothing changed"
fi
else
echo "Error: file '$turbDict' does not exist"
fi
# Identify type of turbulence model and convert
if [ -f $turbDict ]
then
if grep turbulenceModel $turbDict >/dev/null 2>&1
then
convertDict RAS turbulenceModel $turbDict
elif grep LESmodel $turbDict >/dev/null 2>&1
then
convertDict LES LESmodel $turbDict
else
echo "Unable to determine turbulence model type in '$turbDict'" 1>&2
echo " - nothing changed" 1>&2
fi
else
echo "Error: file '$turbDict' does not exist" 1>&2
fi
done
#------------------------------------------------------------------------------

View File

@ -3,22 +3,23 @@
# default is pwd
if [ "$#" -eq 0 ]
then
set -- .
set -- .
elif [ "$1" = "-h" -o "$1" = "-help" ]
then
echo "Usage: ${0##*/} [dir1] .. [dirN]"
echo " remove all .class files"
exit 1
echo "Usage: ${0##*/} [dir1] .. [dirN]"
echo " remove all .class files"
exit 1
fi
for i
do
if [ -d "$i" ]
then
echo "removing all .class files"
find $i -name '*.class' -print | xargs -t rm
else
echo "no directory: $i"
fi
if [ -d "$i" ]
then
echo "removing all .class files: $i"
find $i -name '*.class' -print | xargs -t rm 2>/dev/null
else
echo "no directory: $i" 1>&2
fi
done
#------------------------------------------------------------------------------

View File

@ -3,23 +3,23 @@
# default is pwd
if [ "$#" -eq 0 ]
then
set -- .
set -- .
elif [ "$1" = "-h" -o "$1" = "-help" ]
then
echo "Usage: ${0##*/} [dir1] .. [dirN]"
echo " remove all core files"
exit 1
echo "Usage: ${0##*/} [dir1] .. [dirN]"
echo " remove all core files"
exit 1
fi
for i
do
if [ -d "$i" ]
then
echo "removing all core files"
find $i \( -type f -name 'core' -o -name 'core.[1-9]*' -o -name 'vgcore.*' \) -print | xargs -t rm
else
echo "no directory: $i"
fi
if [ -d "$i" ]
then
echo "removing all core files: $i"
find $i \( -type f -name 'core' -o -name 'core.[1-9]*' -o -name 'vgcore.*' \) -print | xargs -t rm 2>/dev/null
else
echo "no directory: $i" 1>&2
fi
done
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------

View File

@ -2,18 +2,18 @@
if [ "$1" = "-h" -o "$1" = "-help" -o "$#" -gt 1 ]
then
echo "Usage: ${0##*/} : remove all .dep files"
echo " ${0##*/} <file> : remove all .dep files referring to <file>"
exit 1
echo "Usage: ${0##*/} : remove all .dep files"
echo " ${0##*/} <file> : remove all .dep files referring to <file>"
exit 1
fi
if [ "$#" -eq 0 ]
then
echo "removing all .dep files"
find . -name '*.dep' -print | xargs -t rm
echo "removing all .dep files"
find . -name '*.dep' -print | xargs -t rm 2>/dev/null
else
echo "removing all .dep files containing $1..."
find . -name '*.dep' -exec grep "$1" '{}' \; -exec rm '{}' \;
echo "removing all .dep files containing $1..."
find . -name '*.dep' -exec grep "$1" '{}' \; -exec rm '{}' \;
fi
#------------------------------------------------------------------------------

View File

@ -3,22 +3,23 @@
# default is pwd
if [ "$#" -eq 0 ]
then
set -- .
set -- .
elif [ "$1" = "-h" -o "$1" = "-help" ]
then
echo "Usage: ${0##*/} [dir1] .. [dirN]"
echo " remove all .o files"
exit 1
echo "Usage: ${0##*/} [dir1] .. [dirN]"
echo " remove all .o files"
exit 1
fi
for i
do
if [ -d "$i" ]
then
echo "removing all .o files: $i"
find $i -name '*.o' -print | xargs -t rm
else
echo "no directory: $i"
fi
if [ -d "$i" ]
then
echo "removing all .o files: $i"
find $i -name '*.o' -print | xargs -t rm 2>/dev/null
else
echo "no directory: $i" 1>&2
fi
done
#------------------------------------------------------------------------------

View File

@ -3,22 +3,23 @@
# default is pwd
if [ "$#" -eq 0 ]
then
set -- .
set -- .
elif [ "$1" = "-h" -o "$1" = "-help" ]
then
echo "Usage: ${0##*/} [dir1] .. [dirN]"
echo " remove all *~ files"
exit 1
echo "Usage: ${0##*/} [dir1] .. [dirN]"
echo " remove all *~ files"
exit 1
fi
for i
do
if [ -d "$i" ]
then
echo "removing all *~ files"
find $i \( -name '*~' -o -name '.*~' \) -print | xargs -t rm
else
echo "no directory: $i"
fi
if [ -d "$i" ]
then
echo "removing all *~ files: $i"
find $i \( -name '*~' -o -name '.*~' \) -print | xargs -t rm 2>/dev/null
else
echo "no directory: $i" 1>&2
fi
done
#------------------------------------------------------------------------------

View File

@ -31,7 +31,7 @@
#
#------------------------------------------------------------------------------
export CINTSYSDIR=~/pub/CINT/cint
export CINTSYSDIR=~/pub/CINT/cint7
export PATH=$PATH:$CINTSYSDIR
export MANPATH=$MANPATH:$CINTSYSDIR/doc
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$CINTSYSDIR

View File

@ -193,9 +193,17 @@ endsw
_foamAddLib $FOAM_MPI_LIBBIN
# Set the MPI buffer size (used by all platforms except SGI MPI)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
setenv MPI_BUFFER_SIZE 20000000
# Set the minimum MPI buffer size (used by all platforms except SGI MPI)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set minBufferSize=20000000
if ( $?MPI_BUFFER_SIZE ) then
if ( $MPI_BUFFER_SIZE < $minBufferSize ) then
setenv MPI_BUFFER_SIZE $minBufferSize
endif
else
setenv MPI_BUFFER_SIZE $minBufferSize
endif
# CGAL library if available
@ -217,5 +225,6 @@ endif
unalias _foamAddPath
unalias _foamAddLib
unalias _foamMkDir
unset minBufferSize
# -----------------------------------------------------------------------------

View File

@ -223,9 +223,15 @@ esac
_foamAddLib $FOAM_MPI_LIBBIN
# Set the MPI buffer size (used by all platforms except SGI MPI)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export MPI_BUFFER_SIZE=20000000
# Set the minimum MPI buffer size (used by all platforms except SGI MPI)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
minBufferSize=20000000
if [ "${MPI_BUFFER_SIZE:=$minBufferSize}" -lt $minBufferSize ]
then
MPI_BUFFER_SIZE=$minBufferSize
fi
export MPI_BUFFER_SIZE
# CGAL library if available
@ -242,6 +248,6 @@ export MPI_BUFFER_SIZE=20000000
# cleanup environment:
# ~~~~~~~~~~~~~~~~~~~~
unset _foamAddPath _foamAddLib _foamMkDir
unset _foamAddPath _foamAddLib _foamMkDir minBufferSize
# -----------------------------------------------------------------------------

View File

@ -13,6 +13,7 @@ wmake libso lagrangian/basic
wmake libso triSurface
wmake libso edgeMesh
wmake libso surfMesh
wmake libso meshTools
wmake libso finiteVolume

View File

@ -54,7 +54,6 @@ class Map
{
public:
// Constructors
//- Construct given initial map size
@ -74,6 +73,15 @@ public:
:
HashTable<T, label, Hash<label> >(map)
{}
//- Return a null Map
static const Map<T>& null()
{
Map<T>* nullPtr = reinterpret_cast<Map<T>*>(0);
return *nullPtr;
}
};

View File

@ -39,6 +39,7 @@ SourceFiles
#define Keyed_H
#include "List.H"
#include "xfer.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -48,6 +49,7 @@ namespace Foam
// Forward declaration of friend functions and operators
template<class T> class Keyed;
template<class T> class xfer;
template<class T> Istream& operator>>(Istream&, Keyed<T>&);
template<class T> Ostream& operator<<(Ostream&, const Keyed<T>&);
@ -92,6 +94,9 @@ public:
//- Construct as a copy of item, with a key
inline Keyed(const T& item, const label key=0);
//- Construct by transferring the item, with a key
inline Keyed(const xfer<T>& item, const label key=0);
//- Construct from Istream
inline Keyed(Istream&);

View File

@ -30,7 +30,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
//- Construct null
template<class T>
inline Foam::Keyed<T>::Keyed()
:
@ -38,7 +37,6 @@ inline Foam::Keyed<T>::Keyed()
{}
//- Construct from components
template<class T>
inline Foam::Keyed<T>::Keyed(const T& item, const label key)
:
@ -47,6 +45,14 @@ inline Foam::Keyed<T>::Keyed(const T& item, const label key)
{}
template<class T>
inline Foam::Keyed<T>::Keyed(const xfer<T>& item, const label key)
:
T(item),
key_(key)
{}
template<class T>
inline Foam::Keyed<T>::Keyed(Istream& is)
{

View File

@ -62,7 +62,7 @@ public:
// Constructors
//- Store object pointer
inline explicit autoPtr(T* = NULL);
inline explicit autoPtr(T* = 0);
//- Construct as copy by transfering pointer to this autoPtr and
// setting the arguments pointer to NULL
@ -90,11 +90,11 @@ public:
//- Set pointer to that given.
// If object pointer already set issue a FatalError.
inline void set(T* p);
inline void set(T*);
//- If object pointer already set delete object and
// set pointer to that given
inline void reset(T* p = NULL);
inline void reset(T* = 0);
//- If object pointer points to valid object:
// delete object and set pointer to NULL

View File

@ -29,9 +29,9 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
inline Foam::autoPtr<T>::autoPtr(T* tPtr)
inline Foam::autoPtr<T>::autoPtr(T* p)
:
ptr_(tPtr)
ptr_(p)
{}
@ -40,7 +40,7 @@ inline Foam::autoPtr<T>::autoPtr(const autoPtr<T>& ap)
:
ptr_(ap.ptr_)
{
ap.ptr_ = NULL;
ap.ptr_ = 0;
}
@ -64,7 +64,7 @@ template<class T>
inline T* Foam::autoPtr<T>::ptr()
{
T* ptr = ptr_;
ptr_ = NULL;
ptr_ = 0;
return ptr;
}
@ -74,7 +74,7 @@ inline void Foam::autoPtr<T>::set(T* p)
{
if (ptr_)
{
FatalErrorIn("void autoPtr<T>::set(T* p)")
FatalErrorIn("void autoPtr<T>::set(T*)")
<< "object already allocated"
<< abort(FatalError);
}
@ -98,7 +98,7 @@ inline void Foam::autoPtr<T>::reset(T* p)
template<class T>
inline void Foam::autoPtr<T>::clear()
{
reset(NULL);
reset(0);
}

View File

@ -98,16 +98,11 @@ public:
// or a temporary that has been allocated
inline bool valid() const;
// Edit
//- Return tmp pointer for reuse
inline T* ptr() const;
//- If object pointer points to valid object:
// delete object and set pointer to NULL
inline void clear();
//- If object pointer points to valid object:
// delete object and set pointer to NULL
inline void clear() const;

View File

@ -26,15 +26,10 @@ License
#include "error.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
inline tmp<T>::tmp(T* tPtr)
inline Foam::tmp<T>::tmp(T* tPtr)
:
isTmp_(true),
ptr_(tPtr),
@ -43,16 +38,16 @@ inline tmp<T>::tmp(T* tPtr)
template<class T>
inline tmp<T>::tmp(const T& tRef)
inline Foam::tmp<T>::tmp(const T& tRef)
:
isTmp_(false),
ptr_(NULL),
ptr_(0),
ref_(tRef)
{}
template<class T>
inline tmp<T>::tmp(const tmp<T>& t)
inline Foam::tmp<T>::tmp(const tmp<T>& t)
:
isTmp_(t.isTmp_),
ptr_(t.ptr_),
@ -75,14 +70,14 @@ inline tmp<T>::tmp(const tmp<T>& t)
template<class T>
inline tmp<T>::~tmp()
inline Foam::tmp<T>::~tmp()
{
if (isTmp_ && ptr_)
{
if (ptr_->okToDelete())
{
delete ptr_;
ptr_ = NULL;
ptr_ = 0;
}
else
{
@ -95,21 +90,21 @@ inline tmp<T>::~tmp()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline bool tmp<T>::isTmp() const
inline bool Foam::tmp<T>::isTmp() const
{
return isTmp_;
}
template<class T>
inline bool tmp<T>::valid() const
inline bool Foam::tmp<T>::valid() const
{
return (!isTmp_ || (isTmp_ && ptr_));
}
template<class T>
inline T* tmp<T>::ptr() const
inline T* Foam::tmp<T>::ptr() const
{
if (isTmp_)
{
@ -121,7 +116,7 @@ inline T* tmp<T>::ptr() const
}
T* ptr = ptr_;
ptr_ = NULL;
ptr_ = 0;
ptr->resetRefCount();
@ -135,27 +130,20 @@ inline T* tmp<T>::ptr() const
template<class T>
inline void tmp<T>::clear()
inline void Foam::tmp<T>::clear() const
{
if (isTmp_ && ptr_) // && ptr_->okToDelete())
{
delete ptr_;
ptr_ = NULL;
ptr_ = 0;
}
}
template<class T>
inline void tmp<T>::clear() const
{
const_cast<tmp<T>&>(*this).clear();
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
inline T& tmp<T>::operator()()
inline T& Foam::tmp<T>::operator()()
{
if (isTmp_)
{
@ -181,7 +169,7 @@ inline T& tmp<T>::operator()()
template<class T>
inline const T& tmp<T>::operator()() const
inline const T& Foam::tmp<T>::operator()() const
{
if (isTmp_)
{
@ -202,14 +190,14 @@ inline const T& tmp<T>::operator()() const
template<class T>
inline tmp<T>::operator const T&() const
inline Foam::tmp<T>::operator const T&() const
{
return operator()();
}
template<class T>
inline T* tmp<T>::operator->()
inline T* Foam::tmp<T>::operator->()
{
if (isTmp_)
{
@ -230,21 +218,21 @@ inline T* tmp<T>::operator->()
template<class T>
inline const T* tmp<T>::operator->() const
inline const T* Foam::tmp<T>::operator->() const
{
return const_cast<tmp<T>&>(*this).operator->();
}
template<class T>
inline void tmp<T>::operator=(const tmp<T>& t)
inline void Foam::tmp<T>::operator=(const tmp<T>& t)
{
if (isTmp_ && ptr_)
{
if (ptr_->okToDelete())
{
delete ptr_;
ptr_ = NULL;
ptr_ = 0;
}
else
{
@ -277,8 +265,4 @@ inline void tmp<T>::operator=(const tmp<T>& t)
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -26,19 +26,33 @@ Class
Foam::xfer
Description
A simple container that can be used to copy or transfer the contents
of objects of type \<T\>.
Since it is decided upon construction of the xfer object whether the
parameter is to be copied or transferred, the contents of the resulting
object can be transferred unconditionally.
This greatly simplifies defining the constructors for other classes
with mixed transfer/copy semantics.
A simple container for copying or transferring objects of type \<T\>.
The wrapped object of type \<T\> must implement a transfer() method and
an operator=() copy method.
Since it is decided upon construction of the xfer object whether the
parameter is to be copied or transferred, the contents of the resulting
xfer object can be transferred unconditionally. This greatly simplifies
defining constructors or methods in other classes with mixed
transfer/copy semantics without requiring 2^N different versions.
When transferring between dissimilar types, the xferCopyTo() and
xferMoveTo() functions can prove useful. An example is transferring
from a DynamicList to a List. Since the
List\<T\>::transfer(List\<T\>&) method could result in some allocated
memory becoming inaccessible, the xferMoveTo() function can be used to
invoke the correct List\<T\>::transfer(DynamicList\<T\>&) method.
@code
DynamicList<label> dynLst;
...
labelList plainLst( xferMoveTo<labelList>(dynLst) );
@endcode
SeeAlso
xferCopy, xferCopyTo, xferMove, xferMoveTo, xferTmp
SourceFiles
xferI.H
@ -64,7 +78,7 @@ class xfer
{
// Private data
//- Pointer to temporary object
//- Pointer to underlying datatype
mutable T* ptr_;
public:
@ -88,6 +102,11 @@ public:
inline ~xfer();
// Member Functions
//- Return a null object reference
inline static const xfer<T>& null();
// Member Operators
//- Transfer the contents into the object
@ -108,49 +127,56 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
/**
* @fn template<class T> xferCopy(const T&)
* Construct by copying the contents of the @a arg
*
* @sa xferMove, xferTmp and Foam::xfer
* @sa xferCopyTo, xferMove, xferMoveTo, xferTmp and Foam::xfer
*/
template<class T>
Foam::xfer<T> xferCopy(const T& t)
{
return Foam::xfer<T>(t);
}
inline xfer<T> xferCopy(const T&);
/**
* Construct by transferring the contents of the @a arg
*
* @sa xferCopy, xferCopyTo, xferMoveTo, xferTmp and Foam::xfer
*/
template<class T>
inline xfer<T> xferMove(T&);
/**
* @fn template<class T> xferMove(T&)
* Construct by transferring the contents of the @a arg
*
* @sa xferCopy, xferCopyTo, xferMove, xferMoveTo and Foam::xfer
*/
template<class T>
inline xfer<T> xferTmp(Foam::tmp<T>&);
/**
* Construct by copying the contents of the @a arg
* between dissimilar types
*
* @sa xferCopy, xferMove, xferMoveTo, xferTmp and Foam::xfer
*/
template<class To, class From>
inline xfer<To> xferCopyTo(const From&);
/**
* Construct by transferring the contents of the @a arg
* between dissimilar types
*
* @par Example Use
* @code
* List<label> a;
* DynamicList<label> dynLst;
* ...
* List<label> b(xferMove(a));
* labelList plainLst( xferMoveTo<labelList>(dynLst) );
* @endcode
*
* @sa xferCopy, xferTmp and Foam::xfer
* @sa xferCopy, xferCopyTo, xferMove, xferTmp and Foam::xfer
*/
template<class T>
Foam::xfer<T> xferMove(T& t)
{
return Foam::xfer<T>(t, true);
}
/**
* @fn template<class T> xferTmp(tmp<T>&)
* Construct by transferring the contents of the @a arg
*
* @sa xferCopy, xferMove and Foam::xfer
*/
template<class T>
Foam::xfer<T> xferTmp(Foam::tmp<T>& tt)
{
return Foam::xfer<T>(tt(), tt.isTmp());
}
template<class To, class From>
inline xfer<To> xferMoveTo(From&);
} // End namespace Foam

View File

@ -77,6 +77,16 @@ inline Foam::xfer<T>::~xfer()
}
// * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * * //
template<class T>
inline const Foam::xfer<T>& Foam::xfer<T>::null()
{
xfer<T>* nullPtr = reinterpret_cast<xfer<T>*>(0);
return *nullPtr;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
@ -89,7 +99,7 @@ inline void Foam::xfer<T>::operator=(T& t)
template<class T>
inline void Foam::xfer<T>::operator=(const xfer<T>& t)
{
// silently ignore copy to self
// silently ignore attempted copy to self
if (this != &t)
{
ptr_->transfer(*(t.ptr_));
@ -110,4 +120,46 @@ inline T* Foam::xfer<T>::operator->() const
return ptr_;
}
// * * * * * * * * * * * * * Helper Functions * * * * * * * * * * * * * * * //
template<class T>
inline Foam::xfer<T> Foam::xferCopy(const T& t)
{
return Foam::xfer<T>(t);
}
template<class T>
inline Foam::xfer<T> Foam::xferMove(T& t)
{
return Foam::xfer<T>(t, true);
}
template<class T>
inline Foam::xfer<T> Foam::xferTmp(Foam::tmp<T>& tt)
{
return Foam::xfer<T>(tt(), tt.isTmp());
}
template<class To, class From>
inline Foam::xfer<To> Foam::xferCopyTo(const From& t)
{
Foam::xfer<To> xf;
xf() = t;
return xf;
}
template<class To, class From>
inline Foam::xfer<To> Foam::xferMoveTo(From& t)
{
Foam::xfer<To> xf;
xf().transfer(t);
return xf;
}
// ************************************************************************* //

View File

@ -76,7 +76,10 @@ public:
explicit inline cell(label);
//- Construct from components
explicit inline cell(const labelList& f);
explicit inline cell(const labelList&);
//- Construct by transferring the parameter contents
explicit inline cell(const xfer<labelList>&);
//- Construct from Istream
inline cell(Istream&);

View File

@ -26,34 +26,35 @@ Description
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
//- Construct null
inline cell::cell()
// Construct null
inline Foam::cell::cell()
{}
// Construct given size
inline cell::cell(label s)
inline Foam::cell::cell(label s)
:
labelList(s, -1)
{}
//- Construct from components
inline cell::cell(const labelList& f)
// Construct from components
inline Foam::cell::cell(const labelList& lst)
:
labelList(f)
labelList(lst)
{}
inline Foam::cell::cell(const xfer<labelList>& lst)
:
labelList(lst)
{}
// Construct from Istream
inline cell::cell(Istream& is)
inline Foam::cell::cell(Istream& is)
:
labelList(is)
{}
@ -61,21 +62,16 @@ inline cell::cell(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
//- Number of faces
inline label cell::nFaces() const
// Number of faces
inline Foam::label Foam::cell::nFaces() const
{
return size();
}
inline bool operator!=(const cell& a, const cell& b)
inline bool Foam::operator!=(const cell& a, const cell& b)
{
return (!(a == b));
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -588,22 +588,19 @@ Foam::vector Foam::face::normal(const pointField& p) const
Foam::face Foam::face::reverseFace() const
{
// reverse the label list and return
// Changed to make sure that the starting point of the original
// and the reverse face is identical.
//
const labelList& myList = *this;
// The starting points of the original and reverse face are identical.
const labelList& f = *this;
labelList newList(size());
newList[0] = myList[0];
newList[0] = f[0];
for (label pointI = 1; pointI < newList.size(); pointI++)
{
newList[pointI] = myList[size() - pointI];
newList[pointI] = f[size() - pointI];
}
return face(newList);
return face(xferMove(newList));
}
@ -643,7 +640,6 @@ Foam::scalar Foam::face::sweptVol
label nPoints = size();
point nextOldPoint = centreOldPoint;
point nextNewPoint = centreNewPoint;
register label pI;

View File

@ -138,6 +138,9 @@ public:
//- Construct from labelList
explicit inline face(const labelList&);
//- Construct by transferring the parameter contents
explicit inline face(const xfer<labelList>&);
//- Construct from Istream
inline face(Istream&);

View File

@ -24,20 +24,17 @@ License
\*---------------------------------------------------------------------------*/
namespace Foam
{
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Edge to the right of face vertex i
inline label face::right(const label i) const
inline Foam::label Foam::face::right(const label i) const
{
return i;
}
// Edge to the left of face vertex i
inline label face::left(const label i) const
inline Foam::label Foam::face::left(const label i) const
{
return i == 0 ? size() - 1 : (i - 1);
}
@ -46,26 +43,32 @@ inline label face::left(const label i) const
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct NULL
inline face::face()
inline Foam::face::face()
{}
// Construct given size
inline face::face(label s)
inline Foam::face::face(label s)
:
labelList(s, -1)
{}
// Construct from components
inline face::face(const labelList& l)
inline Foam::face::face(const labelList& lst)
:
labelList(l)
labelList(lst)
{}
// Construct from components
inline Foam::face::face(const xfer<labelList>& lst)
:
labelList(lst)
{}
// Construct from Istream
inline face::face(Istream& is)
inline Foam::face::face(Istream& is)
{
is >> *this;
}
@ -73,7 +76,7 @@ inline face::face(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline pointField face::points(const pointField& meshPoints) const
inline Foam::pointField Foam::face::points(const pointField& meshPoints) const
{
// There are as many points as there labels for them
pointField p(size());
@ -90,34 +93,34 @@ inline pointField face::points(const pointField& meshPoints) const
}
inline scalar face::mag(const pointField& p) const
inline Foam::scalar Foam::face::mag(const pointField& p) const
{
return ::Foam::mag(normal(p));
}
inline label face::nEdges() const
inline Foam::label Foam::face::nEdges() const
{
// for a closed polygon a number of edges is the same as number of points
return size();
}
inline edge face::faceEdge(const label n) const
inline Foam::edge Foam::face::faceEdge(const label n) const
{
return edge(operator[](n), operator[](fcIndex(n)));
}
// Next vertex on face
inline label face::nextLabel(const label i) const
inline Foam::label Foam::face::nextLabel(const label i) const
{
return operator[](fcIndex(i));
}
// Previous vertex on face
inline label face::prevLabel(const label i) const
inline Foam::label Foam::face::prevLabel(const label i) const
{
return operator[](rcIndex(i));
}
@ -125,13 +128,13 @@ inline label face::prevLabel(const label i) const
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
inline bool operator==(const face& a, const face& b)
inline bool Foam::operator==(const face& a, const face& b)
{
return face::compare(a,b) != 0;
}
inline bool operator!=(const face& a, const face& b)
inline bool Foam::operator!=(const face& a, const face& b)
{
return face::compare(a,b) == 0;
}
@ -139,7 +142,7 @@ inline bool operator!=(const face& a, const face& b)
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
inline Istream& operator>>(Istream& is, face& f)
inline Foam::Istream& Foam::operator>>(Istream& is, face& f)
{
if (is.version() == IOstream::originalVersion)
{
@ -166,9 +169,4 @@ inline Istream& operator>>(Istream& is, face& f)
return is;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -32,6 +32,7 @@ Description
class, a tetrahedron cell shape model and a tetCell
SourceFiles
tetCell.C
tetCellI.H
\*---------------------------------------------------------------------------*/
@ -77,6 +78,9 @@ public:
const label d
);
//- Construct from FixedList
inline tetCell(const FixedList<label, 4>&);
//- Construct from Istream
inline tetCell(Istream&);

View File

@ -56,6 +56,12 @@ inline tetCell::tetCell
}
inline tetCell::tetCell(const FixedList<label, 4>& lst)
:
FixedList<label, 4>(lst)
{}
inline tetCell::tetCell(Istream& is)
:
FixedList<label, 4>(is)
@ -130,7 +136,7 @@ inline label tetCell::edgeAdjacentFace
{3, -1, -1, 0},
{1, 0, -1, -1}
};
# ifdef FULLDEBUG
if (facei >= 4)
{
@ -161,7 +167,7 @@ inline edge tetCell::tetEdge(const label edgei) const
{
// Warning. Ordering of edges needs to be the same for a tetrahedron
// class, a tetrahedron cell shape model and a tetCell
//
//
static const label start[] = {0, 0, 0, 3, 1, 3};
static const label end[] = {1, 2, 3, 1, 2, 2};

View File

@ -230,7 +230,7 @@ Foam::polyMesh::polyMesh(const IOobject& io)
}
else
{
cellIOList c
cellIOList cLst
(
IOobject
(
@ -243,9 +243,8 @@ Foam::polyMesh::polyMesh(const IOobject& io)
)
);
// Set the primitive mesh
initMesh(c);
initMesh(cLst);
owner_.write();
neighbour_.write();
@ -271,162 +270,6 @@ Foam::polyMesh::polyMesh(const IOobject& io)
}
Foam::polyMesh::polyMesh
(
const IOobject& io,
const pointField& points,
const faceList& faces,
const labelList& owner,
const labelList& neighbour,
const bool syncPar
)
:
objectRegistry(io),
primitiveMesh(),
points_
(
IOobject
(
"points",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
points
),
faces_
(
IOobject
(
"faces",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
faces
),
owner_
(
IOobject
(
"owner",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
owner
),
neighbour_
(
IOobject
(
"neighbour",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
neighbour
),
clearedPrimitives_(false),
boundary_
(
IOobject
(
"boundary",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
*this,
0
),
bounds_(points_, syncPar),
directions_(Vector<label>::zero),
pointZones_
(
IOobject
(
"pointZones",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::NO_WRITE
),
*this,
0
),
faceZones_
(
IOobject
(
"faceZones",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::NO_WRITE
),
*this,
0
),
cellZones_
(
IOobject
(
"cellZones",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::NO_WRITE
),
*this,
0
),
globalMeshDataPtr_(NULL),
moving_(false),
changing_(false),
curMotionTimeIndex_(time().timeIndex()),
oldPointsPtr_(NULL)
{
// Check if the faces and cells are valid
forAll (faces_, faceI)
{
const face& curFace = faces_[faceI];
if (min(curFace) < 0 || max(curFace) > points_.size())
{
FatalErrorIn
(
"polyMesh::polyMesh\n"
"(\n"
" const IOobject& io,\n"
" const pointField& points,\n"
" const faceList& faces,\n"
" const cellList& cells\n"
")\n"
) << "Face " << faceI << "contains vertex labels out of range: "
<< curFace << " Max point index = " << points_.size()
<< abort(FatalError);
}
}
// Set the primitive mesh
initMesh();
}
Foam::polyMesh::polyMesh
(
const IOobject& io,
@ -583,183 +426,6 @@ Foam::polyMesh::polyMesh
}
Foam::polyMesh::polyMesh
(
const IOobject& io,
const pointField& points,
const faceList& faces,
const cellList& cells,
const bool syncPar
)
:
objectRegistry(io),
primitiveMesh(),
points_
(
IOobject
(
"points",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
points
),
faces_
(
IOobject
(
"faces",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
faces
),
owner_
(
IOobject
(
"owner",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
0
),
neighbour_
(
IOobject
(
"neighbour",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
0
),
clearedPrimitives_(false),
boundary_
(
IOobject
(
"boundary",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
*this,
0
),
bounds_(points_, syncPar),
directions_(Vector<label>::zero),
pointZones_
(
IOobject
(
"pointZones",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::NO_WRITE
),
*this,
0
),
faceZones_
(
IOobject
(
"faceZones",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::NO_WRITE
),
*this,
0
),
cellZones_
(
IOobject
(
"cellZones",
instance(),
meshSubDir,
*this,
IOobject::NO_READ,
IOobject::NO_WRITE
),
*this,
0
),
globalMeshDataPtr_(NULL),
moving_(false),
changing_(false),
curMotionTimeIndex_(time().timeIndex()),
oldPointsPtr_(NULL)
{
// Check if the faces and cells are valid
forAll (faces_, faceI)
{
const face& curFace = faces_[faceI];
if (min(curFace) < 0 || max(curFace) > points_.size())
{
FatalErrorIn
(
"polyMesh::polyMesh\n"
"(\n"
" const IOobject& io,\n"
" const pointField& points,\n"
" const faceList& faces,\n"
" const cellList& cells\n"
")\n"
) << "Face " << faceI << "contains vertex labels out of range: "
<< curFace << " Max point index = " << points_.size()
<< abort(FatalError);
}
}
// Check if the faces and cells are valid
forAll (cells, cellI)
{
const cell& curCell = cells[cellI];
if (min(curCell) < 0 || max(curCell) > faces_.size())
{
FatalErrorIn
(
"polyMesh::polyMesh\n"
"(\n"
" const IOobject& io,\n"
" const pointField& points,\n"
" const faceList& faces,\n"
" const cellList& cells\n"
")\n"
) << "Cell " << cellI << "contains face labels out of range: "
<< curCell << " Max face index = " << faces_.size()
<< abort(FatalError);
}
}
// Set the primitive mesh
initMesh(const_cast<cellList&>(cells));
}
Foam::polyMesh::polyMesh
(
const IOobject& io,
@ -910,7 +576,8 @@ Foam::polyMesh::polyMesh
}
}
const cellList& cLst = cells();
// transfer in cell list
cellList cLst(cells);
// Check if cells are valid
forAll (cLst, cellI)
@ -935,130 +602,12 @@ Foam::polyMesh::polyMesh
}
// Set the primitive mesh
initMesh(cells);
initMesh(cLst);
}
void Foam::polyMesh::resetPrimitives
(
const label nUsedFaces,
const pointField& points,
const faceList& faces,
const labelList& owner,
const labelList& neighbour,
const labelList& patchSizes,
const labelList& patchStarts,
const bool validBoundary
)
{
// Clear addressing. Keep geometric props for mapping.
clearAddressing();
// Take over new primitive data. Note extra optimization to prevent
// assignment to self.
if (&points_ != &points)
{
points_ = points;
bounds_ = boundBox(points_, validBoundary);
}
if (&faces_ != &faces)
{
faces_ = faces;
}
if (&owner_ != &owner)
{
owner_ = owner;
}
if (&neighbour_ != &neighbour)
{
neighbour_ = neighbour;
}
// Reset patch sizes and starts
forAll(boundary_, patchI)
{
boundary_[patchI] = polyPatch
(
boundary_[patchI].name(),
patchSizes[patchI],
patchStarts[patchI],
patchI,
boundary_
);
}
// Flags the mesh files as being changed
setInstance(time().timeName());
// Check if the faces and cells are valid
forAll (faces_, faceI)
{
const face& curFace = faces_[faceI];
if (min(curFace) < 0 || max(curFace) > points_.size())
{
FatalErrorIn
(
"polyMesh::polyMesh::resetPrimitives\n"
"(\n"
" const label nUsedFaces,\n"
" const pointField& points,\n"
" const faceList& faces,\n"
" const labelList& owner,\n"
" const labelList& neighbour,\n"
" const labelList& patchSizes,\n"
" const labelList& patchStarts\n"
")\n"
) << "Face " << faceI << " contains vertex labels out of range: "
<< curFace << " Max point index = " << points_.size()
<< abort(FatalError);
}
}
// Set the primitive mesh from the owner_, neighbour_. Works
// out from patch end where the active faces stop.
initMesh();
if (validBoundary)
{
// Note that we assume that all the patches stay the same and are
// correct etc. so we can already use the patches to do
// processor-processor comms.
// Calculate topology for the patches (processor-processor comms etc.)
boundary_.updateMesh();
// Calculate the geometry for the patches (transformation tensors etc.)
boundary_.calcGeometry();
// Warn if global empty mesh (constructs globalData!)
if (globalData().nTotalPoints() == 0 || globalData().nTotalCells() == 0)
{
FatalErrorIn
(
"polyMesh::polyMesh::resetPrimitives\n"
"(\n"
" const label nUsedFaces,\n"
" const pointField& points,\n"
" const faceList& faces,\n"
" const labelList& owner,\n"
" const labelList& neighbour,\n"
" const labelList& patchSizes,\n"
" const labelList& patchStarts\n"
")\n"
)
<< "no points or no cells in mesh" << endl;
}
}
}
void Foam::polyMesh::resetPrimitives
(
const label nUsedFaces,
const xfer<pointField>& points,
const xfer<faceList>& faces,
const xfer<labelList>& owner,
@ -1072,12 +621,28 @@ void Foam::polyMesh::resetPrimitives
clearAddressing();
// Take over new primitive data.
points_.transfer(points());
bounds_ = boundBox(points_, validBoundary);
// Optimized to avoid overwriting data at all
if (&points)
{
points_.transfer(points());
bounds_ = boundBox(points_, validBoundary);
}
if (&faces)
{
faces_.transfer(faces());
}
if (&owner)
{
owner_.transfer(owner());
}
if (&neighbour)
{
neighbour_.transfer(neighbour());
}
faces_.transfer(faces());
owner_.transfer(owner());
neighbour_.transfer(neighbour());
// Reset patch sizes and starts
forAll(boundary_, patchI)
@ -1107,7 +672,6 @@ void Foam::polyMesh::resetPrimitives
(
"polyMesh::polyMesh::resetPrimitives\n"
"(\n"
" const label nUsedFaces,\n"
" const xfer<pointField>&,\n"
" const xfer<faceList>&,\n"
" const xfer<labelList>& owner,\n"
@ -1122,8 +686,8 @@ void Foam::polyMesh::resetPrimitives
}
// Set the primitive mesh from the owner_, neighbour_. Works
// out from patch end where the active faces stop.
// Set the primitive mesh from the owner_, neighbour_.
// Works out from patch end where the active faces stop.
initMesh();
@ -1146,7 +710,6 @@ void Foam::polyMesh::resetPrimitives
(
"polyMesh::polyMesh::resetPrimitives\n"
"(\n"
" const label nUsedFaces,\n"
" const xfer<pointField>&,\n"
" const xfer<faceList>&,\n"
" const xfer<labelList>& owner,\n"
@ -1306,9 +869,9 @@ void Foam::polyMesh::addZones
(
"void addZones\n"
"(\n"
" const List<pointZone*>& pz,\n"
" const List<faceZone*>& fz,\n"
" const List<cellZone*>& cz\n"
" const List<pointZone*>&,\n"
" const List<faceZone*>&,\n"
" const List<cellZone*>&\n"
")"
) << "point, face or cell zone already exists"
<< abort(FatalError);

View File

@ -116,8 +116,8 @@ private:
//- Boundary mesh
mutable polyBoundaryMesh boundary_;
//- Mesh bounding-box. created from points on construction
// and updated when the mesh moves
//- Mesh bounding-box.
// Created from points on construction, updated when the mesh moves
boundBox bounds_;
//- vector of valid directions in mesh
@ -170,9 +170,6 @@ private:
//- Initialise the polyMesh from the given set of cells
void initMesh(cellList& c);
//- Initialise the polyMesh from the given set of cells
void initMesh(const xfer<cellList>& c);
//- Calculate the valid directions in the mesh from the boundaries
void calcDirections() const;
@ -217,18 +214,6 @@ public:
//- Construct from IOobject
explicit polyMesh(const IOobject& io);
//- Construct without boundary from components.
// Boundary is added using addPatches() member function
polyMesh
(
const IOobject& io,
const pointField& points,
const faceList& faces,
const labelList& owner,
const labelList& neighbour,
const bool syncPar = true
);
//- Construct without boundary from components.
// Boundary is added using addPatches() member function
polyMesh
@ -241,17 +226,6 @@ public:
const bool syncPar = true
);
//- Construct without boundary with cells rather than owner/neighbour.
// Boundary is added using addPatches() member function
polyMesh
(
const IOobject& io,
const pointField& points,
const faceList& faces,
const cellList& cells,
const bool syncPar = true
);
//- Construct without boundary with cells rather than owner/neighbour.
// Boundary is added using addPatches() member function
polyMesh
@ -267,7 +241,7 @@ public:
polyMesh
(
const IOobject& io,
const pointField& points,
const xfer<pointField>& points,
const cellShapeList& shapes,
const faceListList& boundaryFaces,
const wordList& boundaryPatchNames,
@ -460,24 +434,6 @@ public:
// patch ends at nActiveFaces) and change patches with addPatches.
void resetPrimitives
(
const label nUsedFaces,
const pointField& points,
const faceList& faces,
const labelList& owner,
const labelList& neighbour,
const labelList& patchSizes,
const labelList& patchStarts,
const bool validBoundary = true
);
//- Reset mesh primitive data. Assumes all patch info correct
// (so does e.g. parallel communication). If not use
// validBoundary=false
// (still assumes patchStarts[0] = nInternalFaces and last
// patch ends at nActiveFaces) and change patches with addPatches.
void resetPrimitives
(
const label nUsedFaces,
const xfer<pointField>& points,
const xfer<faceList>& faces,
const xfer<labelList>& owner,

View File

@ -39,7 +39,7 @@ Foam::labelListList Foam::polyMesh::cellShapePointCells
const cellShapeList& c
) const
{
List<DynamicList<label, primitiveMesh::cellsPerPoint_> >
List<DynamicList<label, primitiveMesh::cellsPerPoint_> >
pc(points().size());
// For each cell
@ -136,7 +136,7 @@ Foam::labelList Foam::polyMesh::facePatchFaceCells
Foam::polyMesh::polyMesh
(
const IOobject& io,
const pointField& points,
const xfer<pointField>& points,
const cellShapeList& cellsAsShapes,
const faceListList& boundaryFaces,
const wordList& boundaryPatchNames,
@ -311,7 +311,7 @@ Foam::polyMesh::polyMesh
// Insertion cannot be done in one go as the faces need to be
// added into the list in the increasing order of neighbour
// cells. Therefore, all neighbours will be detected first
// and then added in the correct order.
// and then added in the correct order.
const faceList& curFaces = cellsFaceShapes[cellI];
@ -414,8 +414,8 @@ Foam::polyMesh::polyMesh
(
"polyMesh::polyMesh\n"
"(\n"
" const IOobject& io,\n"
" const pointField& points,\n"
" const IOobject&,\n"
" const xfer<pointField>&,\n"
" const cellShapeList& cellsAsShapes,\n"
" const faceListList& boundaryFaces,\n"
" const wordList& boundaryPatchTypes,\n"
@ -472,8 +472,8 @@ Foam::polyMesh::polyMesh
(
"polyMesh::polyMesh\n"
"(\n"
" const IOobject& io,\n"
" const pointField& points,\n"
" const IOobject&,\n"
" const xfer<pointField>&,\n"
" const cellShapeList& cellsAsShapes,\n"
" const faceListList& boundaryFaces,\n"
" const wordList& boundaryPatchTypes,\n"

View File

@ -284,12 +284,28 @@ Foam::polyMesh::readUpdateState Foam::polyMesh::readUpdate()
*this
);
pointZones_.setSize(newPointZones.size());
forAll (pointZones_, pzI)
label oldSize = pointZones_.size();
if (newPointZones.size() <= pointZones_.size())
{
pointZones_[pzI] = newPointZones[pzI];
pointZones_.setSize(newPointZones.size());
}
// Reset existing ones
forAll (pointZones_, czI)
{
pointZones_[czI] = newPointZones[czI];
}
// Extend with extra ones
pointZones_.setSize(newPointZones.size());
for (label czI = oldSize; czI < newPointZones.size(); czI++)
{
pointZones_.set(czI, newPointZones[czI].clone(pointZones_));
}
faceZoneMesh newFaceZones
(
IOobject
@ -305,7 +321,14 @@ Foam::polyMesh::readUpdateState Foam::polyMesh::readUpdate()
*this
);
faceZones_.setSize(newFaceZones.size());
oldSize = faceZones_.size();
if (newFaceZones.size() <= faceZones_.size())
{
faceZones_.setSize(newFaceZones.size());
}
// Reset existing ones
forAll (faceZones_, fzI)
{
faceZones_[fzI].resetAddressing
@ -315,6 +338,15 @@ Foam::polyMesh::readUpdateState Foam::polyMesh::readUpdate()
);
}
// Extend with extra ones
faceZones_.setSize(newFaceZones.size());
for (label fzI = oldSize; fzI < newFaceZones.size(); fzI++)
{
faceZones_.set(fzI, newFaceZones[fzI].clone(faceZones_));
}
cellZoneMesh newCellZones
(
IOobject
@ -330,12 +362,28 @@ Foam::polyMesh::readUpdateState Foam::polyMesh::readUpdate()
*this
);
cellZones_.setSize(newCellZones.size());
oldSize = cellZones_.size();
if (newCellZones.size() <= cellZones_.size())
{
cellZones_.setSize(newCellZones.size());
}
// Reset existing ones
forAll (cellZones_, czI)
{
cellZones_[czI] = newCellZones[czI];
}
// Extend with extra ones
cellZones_.setSize(newCellZones.size());
for (label czI = oldSize; czI < newCellZones.size(); czI++)
{
cellZones_.set(czI, newCellZones[czI].clone(cellZones_));
}
if (boundaryChanged)
{
return polyMesh::TOPO_PATCH_CHANGE;

View File

@ -154,11 +154,4 @@ void Foam::polyMesh::initMesh(cellList& c)
neighbour_.note() = meshInfo;
}
void Foam::polyMesh::initMesh(const xfer<cellList>& clst)
{
initMesh(clst());
}
// ************************************************************************* //

View File

@ -218,7 +218,8 @@ Foam::label Foam::autoSnapDriver::getCollocatedPoints
// Calculate displacement as average of patch points.
Foam::pointField Foam::autoSnapDriver::smoothPatchDisplacement
(
const motionSmoother& meshMover
const motionSmoother& meshMover,
const List<labelPair>& baffles
) const
{
const indirectPrimitivePatch& pp = meshMover.patch();
@ -253,6 +254,34 @@ Foam::pointField Foam::autoSnapDriver::smoothPatchDisplacement
const pointField& points = pp.points();
const polyMesh& mesh = meshMover.mesh();
// Get labels of faces to count (master of coupled faces and baffle pairs)
PackedList<1> isMasterFace(syncTools::getMasterFaces(mesh));
{
forAll(baffles, i)
{
label f0 = baffles[i].first();
label f1 = baffles[i].second();
if (isMasterFace.get(f0) == 1)
{
// Make f1 a slave
isMasterFace.set(f1, 0);
}
else if (isMasterFace.get(f1) == 1)
{
isMasterFace.set(f0, 0);
}
else
{
FatalErrorIn("autoSnapDriver::smoothPatchDisplacement(..)")
<< "Both sides of baffle consisting of faces " << f0
<< " and " << f1 << " are already slave faces."
<< abort(FatalError);
}
}
}
// Get average position of boundary face centres
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -266,9 +295,14 @@ Foam::pointField Foam::autoSnapDriver::smoothPatchDisplacement
forAll(pFaces, pfI)
{
avgBoundary[patchPointI] += pp[pFaces[pfI]].centre(points);
label faceI = pFaces[pfI];
if (isMasterFace.get(pp.addressing()[faceI]) == 1)
{
avgBoundary[patchPointI] += pp[faceI].centre(points);
nBoundary[patchPointI]++;
}
}
nBoundary[patchPointI] = pFaces.size();
}
syncTools::syncPointList
@ -886,7 +920,7 @@ void Foam::autoSnapDriver::preSmoothPatch
checkFaces[faceI] = faceI;
}
pointField patchDisp(smoothPatchDisplacement(meshMover));
pointField patchDisp(smoothPatchDisplacement(meshMover, baffles));
// The current mesh is the starting mesh to smooth from.
meshMover.setDisplacement(patchDisp);
@ -1008,9 +1042,11 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface
// Displacement per patch point
vectorField patchDisp(localPoints.size(), vector::zero);
if (returnReduce(localPoints.size(), sumOp<label>()) > 0)
{
// Current surface snapped to
labelList snapSurf(localPoints.size(), -1);
// Divide surfaces into zoned and unzoned
labelList zonedSurfaces;
labelList unzonedSurfaces;
@ -1039,16 +1075,9 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface
patchDisp[pointI] =
hitInfo[pointI].hitPoint()
- localPoints[pointI];
snapSurf[pointI] = hitSurface[pointI];
}
//else
//{
// WarningIn("autoSnapDriver::calcNearestSurface(..)")
// << "For point:" << pointI
// << " coordinate:" << localPoints[pointI]
// << " did not find any surface within:"
// << 4*snapDist[pointI]
// << " meter." << endl;
//}
}
}
@ -1060,6 +1089,7 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface
// Surfaces with zone information
const wordList& faceZoneNames = surfaces.faceZoneNames();
// Current best snap distance
scalarField minSnapDist(snapDist);
forAll(zonedSurfaces, i)
@ -1105,19 +1135,25 @@ Foam::vectorField Foam::autoSnapDriver::calcNearestSurface
minSnapDist[pointI],
mag(patchDisp[pointI])
);
}
else
{
WarningIn("autoSnapDriver::calcNearestSurface(..)")
<< "For point:" << pointI
<< " coordinate:" << localPoints[pointI]
<< " did not find any surface within:"
<< 4*minSnapDist[pointI]
<< " meter." << endl;
snapSurf[pointI] = zoneSurfI;
}
}
}
// Check if all points are being snapped
forAll(snapSurf, pointI)
{
if (snapSurf[pointI] == -1)
{
WarningIn("autoSnapDriver::calcNearestSurface(..)")
<< "For point:" << pointI
<< " coordinate:" << localPoints[pointI]
<< " did not find any surface within:"
<< minSnapDist[pointI]
<< " meter." << endl;
}
}
{
scalarField magDisp(mag(patchDisp));

View File

@ -100,7 +100,11 @@ class autoSnapDriver
//- Calculate displacement per patch point to smooth out patch.
// Quite complicated in determining which points to move where.
pointField smoothPatchDisplacement(const motionSmoother&) const;
pointField smoothPatchDisplacement
(
const motionSmoother&,
const List<labelPair>&
) const;
//- Check that face zones are synced
void checkCoupledFaceZones() const;

View File

@ -382,10 +382,12 @@ private:
//- Finds zone per cell for cells inside closed named surfaces.
// (uses geometric test for insideness)
// Adapts namedSurfaceIndex so all faces on boundary of cellZone
// have corresponding faceZone.
void findCellZoneGeometric
(
const labelList& closedNamedSurfaces,
const labelList& namedSurfaceIndex,
labelList& namedSurfaceIndex,
const labelList& surfaceToCellZone,
labelList& cellToZone
) const;

View File

@ -47,6 +47,7 @@ License
#include "motionSmoother.H"
#include "polyMeshGeometry.H"
#include "IOmanip.H"
#include "cellSet.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -1490,7 +1491,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::mergeBaffles
void Foam::meshRefinement::findCellZoneGeometric
(
const labelList& closedNamedSurfaces, // indices of closed surfaces
const labelList& namedSurfaceIndex, // per face index of named surface
labelList& namedSurfaceIndex, // per face index of named surface
const labelList& surfaceToCellZone, // cell zone index per surface
labelList& cellToZone
@ -1627,6 +1628,76 @@ void Foam::meshRefinement::findCellZoneGeometric
}
}
}
// Adapt the namedSurfaceIndex
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
// for if any cells were not completely covered.
for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
{
label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
label neiZone = cellToZone[mesh_.faceNeighbour()[faceI]];
if (namedSurfaceIndex[faceI] == -1 && (ownZone != neiZone))
{
// Give face the zone of the owner
namedSurfaceIndex[faceI] = findIndex
(
surfaceToCellZone,
max(ownZone, neiZone)
);
}
}
labelList neiCellZone(mesh_.nFaces()-mesh_.nInternalFaces());
for
(
label faceI = mesh_.nInternalFaces();
faceI < mesh_.nFaces();
faceI++
)
{
label own = mesh_.faceOwner()[faceI];
neiCellZone[faceI-mesh_.nInternalFaces()] = cellToZone[own];
}
syncTools::swapBoundaryFaceList(mesh_, neiCellZone, false);
const polyBoundaryMesh& patches = mesh_.boundaryMesh();
forAll(patches, patchI)
{
const polyPatch& pp = patches[patchI];
if (pp.coupled())
{
forAll(pp, i)
{
label faceI = pp.start()+i;
label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
label neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
if (namedSurfaceIndex[faceI] == -1 && (ownZone != neiZone))
{
// Give face the zone of the owner
namedSurfaceIndex[faceI] = findIndex
(
surfaceToCellZone,
max(ownZone, neiZone)
);
}
}
}
}
// Sync
syncTools::syncFaceList
(
mesh_,
namedSurfaceIndex,
maxEqOp<label>(),
false
);
}
@ -1656,7 +1727,7 @@ void Foam::meshRefinement::findCellZoneTopo
blockedFace[faceI] = true;
}
}
syncTools::syncFaceList(mesh_, blockedFace, orEqOp<bool>(), false);
// No need to sync since namedSurfaceIndex already is synced
// Set region per cell based on walking
regionSplit cellRegion(mesh_, blockedFace);
@ -2149,8 +2220,8 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::splitMesh
{
FatalErrorIn
(
"meshRefinement::findCellZoneTopo"
"(const point&, const labelList&, const labelList&, labelList&)"
"meshRefinement::splitMesh"
"(const label, const labelList&, const point&)"
) << "Point " << keepPoint
<< " is not inside the mesh." << nl
<< "Bounding box of the mesh:" << mesh_.globalData().bb()
@ -2703,6 +2774,79 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::zonify
}
// Put the cells into the correct zone
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Closed surfaces with cellZone specified.
labelList closedNamedSurfaces(surfaces_.getClosedNamedSurfaces());
// Zone per cell:
// -2 : unset
// -1 : not in any zone
// >=0: zoneID
labelList cellToZone(mesh_.nCells(), -2);
// Set using geometric test
// ~~~~~~~~~~~~~~~~~~~~~~~~
if (closedNamedSurfaces.size() > 0)
{
findCellZoneGeometric
(
closedNamedSurfaces, // indices of closed surfaces
namedSurfaceIndex, // per face index of named surface
surfaceToCellZone, // cell zone index per surface
cellToZone
);
}
//{
// Pout<< "** finding out blocked faces." << endl;
//
// cellSet zonedCellsGeom(mesh_, "zonedCellsGeom", 100);
// forAll(cellToZone, cellI)
// {
// if (cellToZone[cellI] >= 0)
// {
// zonedCellsGeom.insert(cellI);
// }
// }
// Pout<< "Writing zoned cells to " << zonedCellsGeom.objectPath()
// << endl;
// zonedCellsGeom.write();
//
//
// faceSet zonedFaces(mesh_, "zonedFaces", 100);
// forAll(namedSurfaceIndex, faceI)
// {
// label surfI = namedSurfaceIndex[faceI];
//
// if (surfI != -1)
// {
// zonedFaces.insert(faceI);
// }
// }
// Pout<< "Writing zoned faces to " << zonedFaces.objectPath() << endl;
// zonedFaces.write();
//}
// Set using walking
// ~~~~~~~~~~~~~~~~~
//if (returnReduce(nSet, sumOp<label>()) < mesh_.globalData().nTotalCells())
{
// Topological walk
findCellZoneTopo
(
keepPoint,
namedSurfaceIndex,
surfaceToCellZone,
cellToZone
);
}
// Topochange container
polyTopoChange meshMod(mesh_);
@ -2770,50 +2914,6 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::zonify
// Put the cells into the correct zone
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Closed surfaces with cellZone specified.
labelList closedNamedSurfaces(surfaces_.getClosedNamedSurfaces());
// Zone per cell:
// -2 : unset
// -1 : not in any zone
// >=0: zoneID
labelList cellToZone(mesh_.nCells(), -2);
// Set using geometric test
// ~~~~~~~~~~~~~~~~~~~~~~~~
if (closedNamedSurfaces.size() > 0)
{
findCellZoneGeometric
(
closedNamedSurfaces, // indices of closed surfaces
namedSurfaceIndex, // per face index of named surface
surfaceToCellZone, // cell zone index per surface
cellToZone
);
}
// Set using walking
// ~~~~~~~~~~~~~~~~~
//if (returnReduce(nSet, sumOp<label>()) < mesh_.globalData().nTotalCells())
{
// Topological walk
findCellZoneTopo
(
keepPoint,
namedSurfaceIndex,
surfaceToCellZone,
cellToZone
);
}
// Actually move the cells to their zone
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
forAll(cellToZone, cellI)
{
label zoneI = cellToZone[cellI];

View File

@ -142,9 +142,9 @@ Foam::autoPtr<Foam::polyMesh> Foam::meshReader::mesh
"constant",
registry
),
points_,
meshFaces_,
cellPolys_
xferMove(points_),
xferMove(meshFaces_),
xferMove(cellPolys_)
)
);
@ -166,14 +166,7 @@ void Foam::meshReader::writeMesh
IOstream::streamFormat fmt
) const
{
fileName meshDir = mesh.objectRegistry::path()/mesh.meshDir();
// remove some directories and files - this should be easier
mesh.removeFiles(mesh.instance());
if (dir(meshDir/"sets"))
{
rmDir(meshDir/"sets");
}
mesh.removeFiles();
Info<< "Writing polyMesh" << endl;
mesh.writeObject

View File

@ -1349,11 +1349,10 @@ void Foam::polyDualMesh::calcDual
// Assign to mesh.
resetPrimitives
(
dualFaces.size(),
dualPoints,
dualFaces,
dualOwner,
dualNeighbour,
xferMove(dualPoints),
xferMove(dualFaces),
xferMove(dualOwner),
xferMove(dualNeighbour),
patchSizes,
patchStarts
);

View File

@ -959,7 +959,7 @@ void Foam::polyMeshAdder::mergeFaceZones
)
{
zoneNames.setSize(fz0.size() + fz1.size());
append(fz0.names(), zoneNames);
from1ToAll.setSize(fz1.size());
@ -1041,7 +1041,7 @@ void Foam::polyMeshAdder::mergeCellZones
)
{
zoneNames.setSize(cz0.size() + cz1.size());
append(cz0.names(), zoneNames);
from1ToAll.setSize(cz1.size());
@ -1168,7 +1168,7 @@ void Foam::polyMeshAdder::addZones
mesh.pointZones()
);
}
List<faceZone*> fZones(fzFaces.size());
forAll(fZones, i)
{
@ -1398,10 +1398,10 @@ Foam::autoPtr<Foam::polyMesh> Foam::polyMeshAdder::add
new polyMesh
(
io,
allPoints,
allFaces,
allOwner,
allNeighbour
xferMove(allPoints),
xferMove(allFaces),
xferMove(allOwner),
xferMove(allNeighbour)
)
);
polyMesh& mesh = tmesh();
@ -1557,7 +1557,7 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::polyMeshAdder::add
// Inplace extend mesh0 patches (note that patches0.size() now also
// has changed)
polyBoundaryMesh& allPatches =
polyBoundaryMesh& allPatches =
const_cast<polyBoundaryMesh&>(mesh0.boundaryMesh());
allPatches.setSize(allPatchNames.size());
@ -1702,11 +1702,10 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::polyMeshAdder::add
mesh0.resetMotion(); // delete any oldPoints.
mesh0.resetPrimitives
(
allFaces.size(),
allPoints,
allFaces,
allOwner,
allNeighbour,
xferMove(allPoints),
xferMove(allFaces),
xferMove(allOwner),
xferMove(allNeighbour),
patchSizes, // size
patchStarts, // patchstarts
validBoundary // boundary valid?
@ -1792,7 +1791,7 @@ Foam::Map<Foam::label> Foam::polyMeshAdder::findSharedPoints
}
}
// Assign single master for every shared with multiple geometric points
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -852,7 +852,7 @@ void Foam::polyTopoChange::compact
<< " at position " << faceI << endl
<< "Probably face has not been adapted for"
<< " removed points." << abort(FatalError);
}
}
localPointMap[pointI] = newPointI++;
}
}
@ -904,7 +904,7 @@ void Foam::polyTopoChange::compact
<< " at position " << faceI << endl
<< "Probably face has not been adapted for"
<< " removed points." << abort(FatalError);
}
}
localPointMap[pointI] = newPointI++;
}
}
@ -2097,29 +2097,20 @@ Foam::polyTopoChange::polyTopoChange
void Foam::polyTopoChange::clear()
{
points_.clear();
points_.setSize(0);
pointMap_.clear();
pointMap_.setSize(0);
reversePointMap_.clear();
reversePointMap_.setSize(0);
points_.clearStorage();
pointMap_.clearStorage();
reversePointMap_.clearStorage();
pointZone_.clear();
pointZone_.resize(0);
retiredPoints_.clear();
retiredPoints_.resize(0);
faces_.clear();
faces_.setSize(0);
region_.clear();
region_.setSize(0);
faceOwner_.clear();
faceOwner_.setSize(0);
faceNeighbour_.clear();
faceNeighbour_.setSize(0);
faceMap_.clear();
faceMap_.setSize(0);
reverseFaceMap_.clear();
reverseFaceMap_.setSize(0);
faces_.clearStorage();
region_.clearStorage();
faceOwner_.clearStorage();
faceNeighbour_.clearStorage();
faceMap_.clearStorage();
reverseFaceMap_.clearStorage();
faceFromPoint_.clear();
faceFromPoint_.resize(0);
faceFromEdge_.clear();
@ -2132,12 +2123,9 @@ void Foam::polyTopoChange::clear()
faceZoneFlip_.resize(0);
nActiveFaces_ = 0;
cellMap_.clear();
cellMap_.setSize(0);
reverseCellMap_.clear();
reverseCellMap_.setSize(0);
cellZone_.clear();
cellZone_.setSize(0);
cellMap_.clearStorage();
reverseCellMap_.clearStorage();
cellZone_.clearStorage();
cellFromPoint_.clear();
cellFromPoint_.resize(0);
cellFromEdge_.clear();
@ -2987,13 +2975,12 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::changeMesh
mesh.resetPrimitives
(
nActiveFaces_,
xferMove<pointField>(renumberedMeshPoints),
xferMove<faceList>(faces_),
xferMove<labelList>(faceOwner_),
xferMove<labelList>(faceNeighbour_),
xferMove<labelList>(patchSizes),
xferMove<labelList>(patchStarts),
xferMove(renumberedMeshPoints),
xferMoveTo<faceList>(faces_),
xferMoveTo<labelList>(faceOwner_),
xferMoveTo<labelList>(faceNeighbour_),
patchSizes,
patchStarts,
syncParallel
);
@ -3004,13 +2991,12 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::polyTopoChange::changeMesh
// Set new points.
mesh.resetPrimitives
(
nActiveFaces_,
xferMove<pointField>(newPoints),
xferMove<faceList>(faces_),
xferMove<labelList>(faceOwner_),
xferMove<labelList>(faceNeighbour_),
xferMove<labelList>(patchSizes),
xferMove<labelList>(patchStarts),
xferMove(newPoints),
xferMoveTo<faceList>(faces_),
xferMoveTo<labelList>(faceOwner_),
xferMoveTo<labelList>(faceNeighbour_),
patchSizes,
patchStarts,
syncParallel
);
// Invalidate new points to go into map.

View File

@ -431,17 +431,17 @@ public:
return faces_;
}
const DynamicList<label>& region()const
const DynamicList<label>& region() const
{
return region_;
}
const DynamicList<label>& faceOwner()const
const DynamicList<label>& faceOwner() const
{
return faceOwner_;
}
const DynamicList<label>& faceNeighbour()const
const DynamicList<label>& faceNeighbour() const
{
return faceNeighbour_;
}

View File

@ -225,38 +225,6 @@ Foam::fvMesh::fvMesh(const IOobject& io)
}
Foam::fvMesh::fvMesh
(
const IOobject& io,
const pointField& points,
const faceList& faces,
const labelList& allOwner,
const labelList& allNeighbour,
const bool syncPar
)
:
polyMesh(io, points, faces, allOwner, allNeighbour, syncPar),
surfaceInterpolation(*this),
boundary_(*this),
lduPtr_(NULL),
curTimeIndex_(time().timeIndex()),
VPtr_(NULL),
V0Ptr_(NULL),
V00Ptr_(NULL),
SfPtr_(NULL),
magSfPtr_(NULL),
CPtr_(NULL),
CfPtr_(NULL),
phiPtr_(NULL)
{
if (debug)
{
Info<< "Constructing fvMesh from components"
<< endl;
}
}
Foam::fvMesh::fvMesh
(
const IOobject& io,
@ -283,39 +251,7 @@ Foam::fvMesh::fvMesh
{
if (debug)
{
Info<< "Constructing fvMesh from components"
<< endl;
}
}
Foam::fvMesh::fvMesh
(
const IOobject& io,
const pointField& points,
const faceList& faces,
const cellList& cells,
const bool syncPar
)
:
polyMesh(io, points, faces, cells, syncPar),
surfaceInterpolation(*this),
boundary_(*this),
lduPtr_(NULL),
curTimeIndex_(time().timeIndex()),
VPtr_(NULL),
V0Ptr_(NULL),
V00Ptr_(NULL),
SfPtr_(NULL),
magSfPtr_(NULL),
CPtr_(NULL),
CfPtr_(NULL),
phiPtr_(NULL)
{
if (debug)
{
Info<< "Constructing fvMesh from components"
<< endl;
Info<< "Constructing fvMesh from components" << endl;
}
}
@ -345,8 +281,7 @@ Foam::fvMesh::fvMesh
{
if (debug)
{
Info<< "Constructing fvMesh from components"
<< endl;
Info<< "Constructing fvMesh from components" << endl;
}
}

View File

@ -93,7 +93,7 @@ class fvMesh
//- Current time index for cell volumes
// Note. The whole mechanism will be replaced once the
// dimensionedField is created and the dimensionedField
// will take care of the old-time levels.
// will take care of the old-time levels.
mutable label curTimeIndex_;
//- Cell volumes old time level
@ -168,18 +168,6 @@ public:
//- Construct from IOobject
explicit fvMesh(const IOobject& io);
//- Construct from components without boundary.
// Boundary is added using addFvPatches() member function
fvMesh
(
const IOobject& io,
const pointField& points,
const faceList& faces,
const labelList& allOwner,
const labelList& allNeighbour,
const bool syncPar = true
);
//- Construct from components without boundary.
// Boundary is added using addFvPatches() member function
fvMesh
@ -192,20 +180,7 @@ public:
const bool syncPar = true
);
//- Construct from components with cells rather than owner
// and neighbourwithout boundary.
// Boundary is added using addPatches() member function
fvMesh
(
const IOobject& io,
const pointField& points,
const faceList& faces,
const cellList& cells,
const bool syncPar = true
);
//- Construct from components with cells rather than owner
// and neighbourwithout boundary.
//- Construct without boundary from cells rather than owner/neighbour.
// Boundary is added using addPatches() member function
fvMesh
(
@ -252,7 +227,7 @@ public:
return *this;
}
//- Return reference to name
//- Return reference to name
// Note: name() is currently ambiguous due to derivation from
// surfaceInterpolation
const word& name() const

View File

@ -107,6 +107,7 @@ $(pointSources)/faceToPoint/faceToPoint.C
$(pointSources)/boxToPoint/boxToPoint.C
$(pointSources)/surfaceToPoint/surfaceToPoint.C
$(pointSources)/zoneToPoint/zoneToPoint.C
$(pointSources)/nearestToPoint/nearestToPoint.C
surfaceSets/surfaceSets.C

View File

@ -237,7 +237,7 @@ bool Foam::polyMeshZipUpCells(polyMesh& mesh)
// Go through the points and start from the point used twice
// check all the edges to find the edges starting from this point
// add the
// add the
labelListList edgesToInsert(singleEdges.size());
label nEdgesToInsert = 0;
@ -438,7 +438,7 @@ bool Foam::polyMeshZipUpCells(polyMesh& mesh)
// Warning: the ordering must be parametric, because in
// the case of multiple point insertion onto the same edge
// it is possible to get non-cyclic loops
//
//
const labelList& unorderedEdge = edgesToInsert[edgeToInsertI];
@ -678,7 +678,7 @@ bool Foam::polyMeshZipUpCells(polyMesh& mesh)
<< oldFaces[currentFaceIndex] << nl
<< "newFace: " << newFace << endl;
# endif
// Check for duplicate points in the new face
forAll (newFace, checkI)
{
@ -756,11 +756,10 @@ bool Foam::polyMeshZipUpCells(polyMesh& mesh)
// (patches guaranteed to be in increasing order)
mesh.resetPrimitives
(
patchStarts[bMesh.size()-1] + patchSizes[bMesh.size()-1],
mesh.points(),
newFaces,
mesh.faceOwner(),
mesh.faceNeighbour(),
xfer<pointField>::null(),
xferMove(newFaces),
xfer<labelList>::null(),
xfer<labelList>::null(),
patchSizes,
patchStarts,
true // boundary forms valid boundary mesh.

View File

@ -1904,8 +1904,8 @@ void Foam::distributedTriSurfaceMesh::distribute
}
else
{
dict_.set("bounds", procBb_[Pstream::myProcNo()]);
procBb_.transfer(newProcBb);
dict_.set("bounds", procBb_[Pstream::myProcNo()]);
}
}

View File

@ -26,7 +26,6 @@ License
#include "searchableSurfaceWithGaps.H"
#include "addToRunTimeSelectionTable.H"
#include "SortableList.H"
#include "Time.H"
#include "ListOps.H"
@ -82,7 +81,7 @@ Foam::Pair<Foam::vector> Foam::searchableSurfaceWithGaps::offsetVecs
// Do second offset vector perp to original edge and first offset vector
offsets[1] = n ^ offsets[0];
offsets[1] *= gap_/mag(offsets[1]);
offsets[1] *= gap_;
}
return offsets;
@ -207,6 +206,10 @@ void Foam::searchableSurfaceWithGaps::findLine
List<pointIndexHit>& info
) const
{
// Test with unperturbed vectors
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
surface().findLine(start, end, info);
// Count number of misses. Determine map
@ -215,6 +218,10 @@ void Foam::searchableSurfaceWithGaps::findLine
if (returnReduce(nMiss, sumOp<label>()) > 0)
{
//Pout<< "** retesting with offset0 " << nMiss << " misses out of "
// << start.size() << endl;
// extract segments according to map
pointField compactStart(start, compactMap);
pointField compactEnd(end, compactMap);
@ -228,20 +235,36 @@ void Foam::searchableSurfaceWithGaps::findLine
offset1
);
// Test with offset0 perturbed vectors
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test in pairs: only if both perturbations hit something
// do we accept the hit.
const vectorField smallVec(SMALL*(compactEnd-compactStart));
List<pointIndexHit> plusInfo;
surface().findLine(compactStart+offset0, compactEnd+offset0, plusInfo);
surface().findLine
(
compactStart+offset0-smallVec,
compactEnd+offset0+smallVec,
plusInfo
);
List<pointIndexHit> minInfo;
surface().findLine(compactStart-offset0, compactEnd-offset0, minInfo);
surface().findLine
(
compactStart-offset0-smallVec,
compactEnd-offset0+smallVec,
minInfo
);
// Extract any hits
forAll(plusInfo, i)
{
if (plusInfo[i].hit() && minInfo[i].hit())
{
info[compactMap[i]] = plusInfo[i].hitPoint()-offset0[i];
info[compactMap[i]] = plusInfo[i];
info[compactMap[i]].rawPoint() -= offset0[i];
}
}
@ -250,6 +273,12 @@ void Foam::searchableSurfaceWithGaps::findLine
if (returnReduce(nMiss, sumOp<label>()) > 0)
{
//Pout<< "** retesting with offset1 " << nMiss << " misses out of "
// << start.size() << endl;
// Test with offset1 perturbed vectors
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Extract (inplace possible because of order)
forAll(plusMissMap, i)
{
@ -266,17 +295,18 @@ void Foam::searchableSurfaceWithGaps::findLine
offset0.setSize(plusMissMap.size());
offset1.setSize(plusMissMap.size());
const vectorField smallVec(SMALL*(compactEnd-compactStart));
surface().findLine
(
compactStart+offset1,
compactEnd+offset1,
compactStart+offset1-smallVec,
compactEnd+offset1+smallVec,
plusInfo
);
surface().findLine
(
compactStart-offset1,
compactEnd-offset1,
compactStart-offset1-smallVec,
compactEnd-offset1+smallVec,
minInfo
);
@ -285,7 +315,8 @@ void Foam::searchableSurfaceWithGaps::findLine
{
if (plusInfo[i].hit() && minInfo[i].hit())
{
info[compactMap[i]] = plusInfo[i].hitPoint()-offset1[i];
info[compactMap[i]] = plusInfo[i];
info[compactMap[i]].rawPoint() -= offset1[i];
}
}
}

View File

@ -27,7 +27,13 @@ Class
Description
searchableSurface using multiple slightly shifted underlying surfaces
to make sure pierces don't go through gaps.
to make sure pierces don't go through gaps:
- shift test vector with two small vectors (of size gap_) perpendicular
to the original.
Test with + and - this vector. Only if both register a hit is it seen
as one.
- extend the test vector slightly (with SMALL) to account for numerical
inaccuracies.
SourceFiles
searchableSurfaceWithGaps.C

View File

@ -0,0 +1,154 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "nearestToPoint.H"
#include "polyMesh.H"
#include "meshSearch.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(nearestToPoint, 0);
addToRunTimeSelectionTable(topoSetSource, nearestToPoint, word);
addToRunTimeSelectionTable(topoSetSource, nearestToPoint, istream);
}
Foam::topoSetSource::addToUsageTable Foam::nearestToPoint::usage_
(
nearestToPoint::typeName,
"\n Usage: nearestToPoint (pt0 .. ptn)\n\n"
" Select the nearest point for each of the points pt0 ..ptn\n\n"
);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::nearestToPoint::combine(topoSet& set, const bool add) const
{
// Do linear search since usually just a few points.
forAll(points_, pointI)
{
const pointField& pts = mesh_.points();
if (pts.size() > 0)
{
label minPointI = 0;
scalar minDistSqr = magSqr(pts[minPointI] - points_[pointI]);
for (label i = 1; i < pts.size(); i++)
{
scalar distSqr = magSqr(pts[i] - points_[pointI]);
if (distSqr < minDistSqr)
{
minDistSqr = distSqr;
minPointI = i;
}
}
addOrDelete(set, minPointI, add);
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
Foam::nearestToPoint::nearestToPoint
(
const polyMesh& mesh,
const pointField& points
)
:
topoSetSource(mesh),
points_(points)
{}
// Construct from dictionary
Foam::nearestToPoint::nearestToPoint
(
const polyMesh& mesh,
const dictionary& dict
)
:
topoSetSource(mesh),
points_(dict.lookup("points"))
{}
// Construct from Istream
Foam::nearestToPoint::nearestToPoint
(
const polyMesh& mesh,
Istream& is
)
:
topoSetSource(mesh),
points_(checkIs(is))
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::nearestToPoint::~nearestToPoint()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::nearestToPoint::applyToSet
(
const topoSetSource::setAction action,
topoSet& set
) const
{
if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
{
Info<< " Adding points nearest to " << points_ << endl;
combine(set, true);
}
else if (action == topoSetSource::DELETE)
{
Info<< " Removing points nearest to " << points_ << endl;
combine(set, false);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,122 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::nearestToPoint
Description
A topoSetSource to select points nearest to points.
SourceFiles
nearestToPoint.C
\*---------------------------------------------------------------------------*/
#ifndef nearestToPoint_H
#define nearestToPoint_H
#include "topoSetSource.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class nearestToPoint Declaration
\*---------------------------------------------------------------------------*/
class nearestToPoint
:
public topoSetSource
{
// Private data
//- Add usage string
static addToUsageTable usage_;
//- points to select nearest to
pointField points_;
// Private Member Functions
void combine(topoSet& set, const bool add) const;
public:
//- Runtime type information
TypeName("nearestToPoint");
// Constructors
//- Construct from components
nearestToPoint
(
const polyMesh& mesh,
const pointField& points
);
//- Construct from dictionary
nearestToPoint
(
const polyMesh& mesh,
const dictionary& dict
);
//- Construct from Istream
nearestToPoint
(
const polyMesh& mesh,
Istream&
);
// Destructor
virtual ~nearestToPoint();
// Member Functions
virtual void applyToSet
(
const topoSetSource::setAction action,
topoSet&
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

23
src/surfMesh/Make/files Normal file
View File

@ -0,0 +1,23 @@
keyedSurface/keyedSurface.C
keyedSurface/keyedSurfaceCleanup.C
keyedSurface/newKeyedSurface.C
meshedSurface/meshedSurface.C
meshedSurface/meshedSurfaceCleanup.C
meshedSurface/newMeshedSurface.C
fileFormats = keyedSurface/fileFormats
$(fileFormats)/ac3d/AC3DfileFormat.C
$(fileFormats)/gts/GTSfileFormat.C
$(fileFormats)/nas/NASfileFormat.C
$(fileFormats)/obj/OBJfileFormat.C
$(fileFormats)/off/OFFfileFormat.C
$(fileFormats)/smesh/SMESHfileFormat.C
$(fileFormats)/starcd/STARCDfileFormat.C
$(fileFormats)/stl/STLfileFormat.C
$(fileFormats)/stl/STLfileFormatASCII.L
$(fileFormats)/tri/TRIfileFormat.C
$(fileFormats)/vtk/VTKfileFormat.C
LIB = $(FOAM_LIBBIN)/libsurfMesh

View File

@ -0,0 +1,5 @@
EXE_INC = \
-I$(LIB_SRC)/triSurface/lnInclude
LIB_LIBS = \
-ltriSurface

View File

@ -0,0 +1,588 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "AC3DfileFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "tensor.H"
#include "primitivePatch.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
addNamedToRunTimeSelectionTable
(
keyedSurface,
AC3DfileFormat,
fileExtension,
ac
);
addNamedToMemberFunctionSelectionTable
(
keyedSurface,
AC3DfileFormat,
write,
fileExtension,
ac
);
addNamedToMemberFunctionSelectionTable
(
meshedSurface,
AC3DfileFormat,
write,
fileExtension,
ac
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
Type Foam::fileFormats::AC3DfileFormat::parse(const string& str)
{
IStringStream ss(str);
Type t;
ss >> t;
return t;
}
bool Foam::fileFormats::AC3DfileFormat::readCmd
(
IFstream& is,
string& cmd,
string& args
)
{
if (is.good())
{
string line;
is.getLine(line);
string::size_type space = line.find(' ');
if (space != string::npos)
{
cmd = line.substr(0, space);
args = line.substr(space+1);
return true;
}
}
return false;
}
// Read up to line starting with cmd. Sets args to rest of line.
// Returns true if found, false if stream is not good anymore.
bool Foam::fileFormats::AC3DfileFormat::cueTo
(
IFstream& is,
const string& cmd,
string& args
)
{
while (is.good())
{
string line;
is.getLine(line);
string::size_type space = line.find(' ');
if (space != string::npos)
{
if (line.substr(0, space) == cmd)
{
args = line.substr(space+1);
return true;
}
}
}
return false;
}
// Similar to cueTo(), but throws error if cmd not found
Foam::string Foam::fileFormats::AC3DfileFormat::cueToOrDie
(
IFstream& is,
const string& cmd,
const string& errorMsg
)
{
string args;
if (!cueTo(is, cmd, args))
{
FatalErrorIn
(
"fileFormats::AC3DfileFormat::AC3DfileFormat"
"(const fileName&)"
)
<< "Cannot find command " << cmd
<< " " << errorMsg
<< exit(FatalError);
}
return args;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::AC3DfileFormat::AC3DfileFormat()
:
Foam::keyedSurface()
{}
Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
(
const fileName& fName,
const bool triangulate
)
:
Foam::keyedSurface()
{
IFstream is(fName);
if (!is.good())
{
FatalErrorIn
(
"fileFormats::AC3DfileFormat::AC3DfileFormat"
"(const fileName&)"
)
<< "Cannot read file " << fName
<< exit(FatalError);
}
string line, cmd, args;
is.getLine(line);
string version = line.substr(4);
if (version != "b")
{
WarningIn
(
"fileFormats::AC3DfileFormat::AC3DfileFormat"
"(const fileName&)"
)
<< "When reading AC3D file " << fName
<< " read header " << line << " with version "
<< version << endl
<< "Only tested reading with version 'b'."
<< " This might give problems" << endl;
}
if (!cueTo(is, "OBJECT", args) || (args != "world"))
{
FatalErrorIn
(
"fileFormats::AC3DfileFormat::AC3DfileFormat"
"(const fileName&)"
)
<< "Cannot find \"OBJECT world\" in file " << fName
<< exit(FatalError);
}
// # of kids is the # of patches
args = cueToOrDie(is, "kids");
label nPatches = parse<int>(args);
// Start of vertices for object/patch
label patchVertOffset = 0;
DynamicList<point> pointLst;
DynamicList<keyedFace> faceLst;
// patchId => patchName
Map<word> regionNames;
for (label patchI = 0; patchI < nPatches; ++patchI)
{
word patchName = word("patch") + Foam::name(patchI);
args = cueToOrDie(is, "OBJECT", "while reading " + patchName);
// number of vertices for this patch
label nPatchPoints = 0;
vector location(pTraits<vector>::zero);
// tensor rotation(I);
// Read all info for current patch
while (is.good())
{
// Read line and get first word. If end of file break since
// patch should always end with 'kids' command ?not sure.
if (!readCmd(is, cmd, args))
{
FatalErrorIn
(
"fileFormats::AC3DfileFormat::AC3DfileFormat"
"(const fileName&)"
)
<< "Did not read up to \"kids 0\" while reading patch "
<< patchI << " from file " << fName
<< exit(FatalError);
}
if (cmd == "name")
{
// name %s
string str = parse<string>(args);
string::stripInvalid<word>(str);
patchName = str;
}
else if (cmd == "rot")
{
// rot %f %f %f %f %f %f %f %f %f
// IStringStream lineStream(args);
//
// lineStream
// >> rotation.xx() >> rotation.xy() >> rotation.xz()
// >> rotation.yx() >> rotation.yy() >> rotation.yz()
// >> rotation.zx() >> rotation.zy() >> rotation.zz();
WarningIn
(
"fileFormats::AC3DfileFormat::AC3DfileFormat"
"(const fileName&)"
)
<< "rot (rotation tensor) command not implemented"
<< "Line:" << cmd << ' ' << args << endl
<< "while reading patch " << patchI << endl;
}
else if (cmd == "loc")
{
// loc %f %f %f
IStringStream lineStream(args);
lineStream
>> location.x()
>> location.y()
>> location.z();
}
else if (cmd == "numvert")
{
// numvert %d
nPatchPoints = parse<int>(args);
for (label vertI = 0; vertI < nPatchPoints; ++vertI)
{
is.getLine(line);
IStringStream lineStream(line);
point pt;
lineStream
>> pt.x() >> pt.y() >> pt.z();
// Offset with current translation vector
pointLst.append(location + pt);
}
}
else if (cmd == "numsurf")
{
label nFaces = parse<int>(args);
for (label faceI = 0; faceI < nFaces; ++faceI)
{
static string errorMsg =
string(" while reading face ")
+ Foam::name(faceI) + " on patch "
+ Foam::name(patchI)
+ " from file " + fName;
cueToOrDie(is, "SURF", errorMsg);
cueToOrDie(is, "mat", errorMsg);
args = cueToOrDie(is, "refs", errorMsg);
label nVert = parse<int>(args);
List<label> verts(nVert);
forAll(verts, vertI)
{
is.getLine(line);
verts[vertI] = parse<int>(line) + patchVertOffset;
}
if (triangulate && verts.size() > 3)
{
face fTri(3);
// simple face triangulation about f[0].
// cannot use face::triangulation
// since points are incomplete
fTri[0] = verts[0];
for (label fp1 = 1; fp1 < verts.size() - 1; ++fp1)
{
label fp2 = (fp1 + 1) % verts.size();
fTri[1] = verts[fp1];
fTri[2] = verts[fp2];
faceLst.append(keyedFace(fTri, patchI));
}
}
else
{
faceLst.append(keyedFace(face(verts), patchI));
}
}
// Done the current patch.
// Increment the offset vertices are stored at
patchVertOffset += nPatchPoints;
}
else if (cmd == "kids")
{
// 'kids' denotes the end of the current patch.
label nKids = parse<int>(args);
if (nKids != 0)
{
FatalErrorIn
(
"fileFormats::AC3DfileFormat::AC3DfileFormat"
"(const fileName&)"
)
<< "Can only read objects without kids."
<< " Encountered " << nKids << " kids when"
<< " reading patch " << patchI
<< exit(FatalError);
}
// Done reading current patch
regionNames.insert(patchI, patchName);
break;
}
}
}
// transfer to normal lists
points().transfer(pointLst);
faces().transfer(faceLst);
setPatches(regionNames);
stitchFaces(SMALL);
}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::AC3DfileFormat::writeHeader
(
Ostream& os,
const List<surfacePatch>& patchLst
)
{
// Write with patches as separate objects under "world" object.
// Header is taken over from sample file.
// Defines separate materials for all patches. Recycle colours.
// Define 8 standard colours as r,g,b components
static scalar colourMap[] =
{
1, 1, 1,
1, 0, 0,
0, 1, 0,
0, 0, 1,
1, 1, 0,
0, 1, 1,
1, 0, 1,
0.5, 0.5, 1
};
// Write header. Define materials.
os << "AC3Db" << nl;
forAll(patchLst, patchI)
{
const word& pName = patchLst[patchI].name();
label colourI = patchI % 8;
label colourCompI = 3 * colourI;
os << "MATERIAL \"" << pName << "Mat\" rgb "
<< colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
<< ' ' << colourMap[colourCompI+2]
<< " amb 0.2 0.2 0.2 emis 0 0 0 spec 0.5 0.5 0.5 shi 10"
<< " trans 0"
<< nl;
}
os << "OBJECT world" << nl
<< "kids " << patchLst.size() << endl;
}
void Foam::fileFormats::AC3DfileFormat::write
(
Ostream& os,
const keyedSurface& surf
)
{
labelList faceMap;
List<surfacePatch> patchLst = surf.sortedRegions(faceMap);
writeHeader(os, patchLst);
label faceIndex = 0;
forAll(patchLst, patchI)
{
const surfacePatch& sp = patchLst[patchI];
os << "OBJECT poly" << nl
<< "name \"" << sp.name() << '"' << endl;
// Create patch with only patch faces included for ease of addressing
boolList include(surf.size(), false);
forAll(sp, patchFaceI)
{
const label faceI = faceMap[faceIndex++];
include[faceI] = true;
}
labelList pMap;
labelList fMap;
keyedSurface patch = surf.subsetMesh
(
include, pMap, fMap
);
// Now we have triSurface for this patch alone. Write it.
os << "numvert " << patch.nPoints() << endl;
forAll(patch.localPoints(), ptI)
{
const point& pt = patch.localPoints()[ptI];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
}
os << "numsurf " << patch.localFaces().size() << endl;
forAll(patch.localFaces(), faceI)
{
const keyedFace& f = patch.localFaces()[faceI];
os << "SURF 0x20" << nl // polygon
<< "mat " << patchI << nl
<< "refs " << f.size() << nl;
forAll(f, fp)
{
os << f[fp] << " 0 0" << nl;
}
}
os << "kids 0" << endl;
}
}
void Foam::fileFormats::AC3DfileFormat::write
(
Ostream& os,
const meshedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<face>& faceLst = surf.faces();
const List<surfacePatch>& patchLst = surf.patches();
writeHeader(os, patchLst);
forAll(patchLst, patchI)
{
const surfacePatch& sp = patchLst[patchI];
os << "OBJECT poly" << nl
<< "name \"" << sp.name() << '"' << endl;
// Temporary primitivePatch to calculate compact points & faces
primitivePatch patch
(
SubList<face>
(
faceLst,
sp.start(),
sp.size()
),
pointLst
);
os << "numvert " << patch.nPoints() << endl;
forAll(patch.localPoints(), ptI)
{
const point& pt = patch.localPoints()[ptI];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
}
os << "numsurf " << patch.localFaces().size() << endl;
forAll(patch.localFaces(), faceI)
{
const keyedFace& f = patch.localFaces()[faceI];
os << "SURF 0x20" << nl // polygon
<< "mat " << patchI << nl
<< "refs " << f.size() << nl;
forAll(f, fp)
{
os << f[fp] << " 0 0" << nl;
}
}
os << "kids 0" << endl;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,167 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::AC3DfileFormat
Description
Provide a means of reading/writing AC3D format.
http://www.inivis.com/ac3d/man/ac3dfileformat.html
Note
Since the faces are already organized as patches, the reader could be
optimized for this, but at expense of losing a common reading approach.
SourceFiles
AC3DfileFormat.C
\*---------------------------------------------------------------------------*/
#ifndef AC3DfileFormat_H
#define AC3DfileFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "keyedSurface.H"
#include "meshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
class AC3DfileFormat;
/*---------------------------------------------------------------------------*\
Class AC3DfileFormat Declaration
\*---------------------------------------------------------------------------*/
class AC3DfileFormat
:
public keyedSurface
{
// Private Member Functions
//- Read a type via IStringStream
template<class Type>
static Type parse(const string&);
//- Read cmd, args from IFstream
static bool readCmd(IFstream&, string& cmd, string& args);
//- Cue up to cmd, reading args
static bool cueTo(IFstream&, const string& cmd, string& args);
//- Cue up to cmd, reading args or exit with a FatalError
// returns the command args
static string cueToOrDie
(
IFstream&,
const string& cmd,
const string& errorMsg=string::null
);
//- Write header with materials
static void writeHeader(Ostream&, const List<surfacePatch>&);
//- Disallow default bitwise copy construct
AC3DfileFormat(const AC3DfileFormat&);
//- Disallow default bitwise assignment
void operator=(const AC3DfileFormat&);
public:
// Constructors
//- Construct null
AC3DfileFormat();
//- Construct from file name
AC3DfileFormat(const fileName&, const bool triangulate=false);
// Selectors
//- Read file and return keyedSurface
static autoPtr<keyedSurface> New
(
const fileName& fName,
const bool triangulate=false
)
{
return autoPtr<keyedSurface>
(
new AC3DfileFormat(fName, triangulate)
);
}
// Destructor
// Member Functions
// Write
//- Write keyedSurface
static void write(Ostream&, const keyedSurface&);
//- Write keyedSurface
static void write(const fileName& fName, const keyedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write meshedSurface
static void write(Ostream&, const meshedSurface&);
//- Write meshedSurface
static void write(const fileName& fName, const meshedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
{
write(os, *this);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,440 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "GTSfileFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "tensor.H"
#include "primitivePatch.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
addNamedToRunTimeSelectionTable
(
keyedSurface,
GTSfileFormat,
fileExtension,
gts
);
addNamedToMemberFunctionSelectionTable
(
keyedSurface,
GTSfileFormat,
write,
fileExtension,
gts
);
addNamedToMemberFunctionSelectionTable
(
meshedSurface,
GTSfileFormat,
write,
fileExtension,
gts
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::GTSfileFormat::GTSfileFormat()
:
Foam::keyedSurface()
{}
Foam::fileFormats::GTSfileFormat::GTSfileFormat
(
const fileName& fName,
const bool triangulate
)
:
Foam::keyedSurface()
{
IFstream is(fName);
if (!is.good())
{
FatalErrorIn
(
"fileFormats::GTSfileFormat::GTSfileFormat"
"(const fileName&)"
)
<< "Cannot read file " << fName
<< exit(FatalError);
}
// Read header
string line = getLineNoComment(is);
label nPoints, nEdges, nElems;
{
IStringStream lineStream(line);
lineStream
>> nPoints
>> nEdges
>> nElems;
}
pointField pointLst(nPoints);
// Read points
forAll(pointLst, pointI)
{
scalar x, y, z;
line = getLineNoComment(is);
{
IStringStream lineStream(line);
lineStream
>> x >> y >> z;
}
pointLst[pointI] = point(x, y, z);
}
// Read edges (Foam indexing)
edgeList edges(nEdges);
forAll(edges, edgei)
{
label beg, end;
line = getLineNoComment(is);
{
IStringStream lineStream(line);
lineStream
>> beg >> end;
}
edges[edgei] = edge(beg - 1, end - 1);
}
// Read triangles. Convert references to edges into pointlabels
List<keyedFace> faceLst(nElems);
label maxPatch = 0;
forAll(faceLst, faceI)
{
label e0Label, e1Label, e2Label;
label region = 0;
line = getLineNoComment(is);
{
IStringStream lineStream(line);
lineStream
>> e0Label >> e1Label >> e2Label;
// Optional region number: read first, then check state on stream
if (lineStream)
{
label num;
lineStream >> num;
if (!lineStream.bad())
{
region = num;
if (maxPatch < region)
{
maxPatch = region;
}
}
}
}
// Determine ordering of edges e0, e1
// common: common vertex, shared by e0 and e1
// e0Far: vertex on e0 which is not common
// e1Far: vertex on e1 which is not common
const edge& e0 = edges[e0Label - 1];
const edge& e1 = edges[e1Label - 1];
const edge& e2 = edges[e2Label - 1];
label common01 = e0.commonVertex(e1);
if (common01 == -1)
{
FatalErrorIn
(
"fileFormats::GTSfileFormat::GTSfileFormat"
"(const fileName&)"
)
<< "Edges 0 and 1 of triangle " << faceI
<< " do not share a point.\n"
<< " edge0:" << e0 << nl
<< " edge1:" << e1
<< exit(FatalError);
}
label e0Far = e0.otherVertex(common01);
label e1Far = e1.otherVertex(common01);
label common12 = e1.commonVertex(e2);
if (common12 == -1)
{
FatalErrorIn
(
"fileFormats::GTSfileFormat::GTSfileFormat"
"(const fileName&)"
)
<< "Edges 1 and 2 of triangle " << faceI
<< " do not share a point.\n"
<< " edge1:" << e1 << nl
<< " edge2:" << e2
<< exit(FatalError);
}
label e2Far = e2.otherVertex(common12);
// Does edge2 sit between edge1 and 0?
if (common12 != e1Far || e2Far != e0Far)
{
FatalErrorIn
(
"fileFormats::GTSfileFormat::GTSfileFormat"
"(const fileName&)"
)
<< "Edges of triangle " << faceI
<< " reference more than three points.\n"
<< " edge0:" << e0 << nl
<< " edge1:" << e1 << nl
<< " edge2:" << e2 << nl
<< exit(FatalError);
}
keyedFace lface(face(3), region);
lface[0] = e0Far;
lface[1] = common01;
lface[2] = e1Far;
faceLst[faceI] = lface;
}
// transfer to normal lists
points().transfer(pointLst);
faces().transfer(faceLst);
setPatches(maxPatch);
// stitchFaces(SMALL);
}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::GTSfileFormat::write
(
Ostream& os,
const keyedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<keyedFace>& faceLst = surf.faces();
// It is too annoying to triangulate on-the-fly
// just issue a warning and get out
label nNonTris = 0;
forAll(faceLst, faceI)
{
if (faceLst[faceI].size() > 3)
{
++nNonTris;
}
}
if (nNonTris)
{
FatalErrorIn
(
"fileFormats::GTSfileFormat::write"
"(Ostream&, const keyedSurface&)"
)
<< "Surface has " << nNonTris << "/" << faceLst.size()
<< " non-triangulated faces - not writing!" << endl;
return;
}
labelList faceMap;
List<surfacePatch> patchLst = surf.sortedRegions(faceMap);
// Write header, print patch names as comment
os << "# GTS file" << nl
<< "# Regions:" << nl;
forAll(patchLst, patchI)
{
os << "# " << patchI << " "
<< patchLst[patchI].name() << nl;
}
os << "#" << endl;
os << "# nPoints nEdges nTriangles" << nl
<< pointLst.size() << ' ' << surf.nEdges() << ' '
<< surf.size() << endl;
// Write vertex coords
forAll(pointLst, pointI)
{
os << pointLst[pointI].x() << ' '
<< pointLst[pointI].y() << ' '
<< pointLst[pointI].z() << endl;
}
// Write edges.
// Note: edges are in local point labels so convert
const edgeList& es = surf.edges();
const labelList& meshPts = surf.meshPoints();
forAll(es, edgeI)
{
os << meshPts[es[edgeI].start()] + 1 << ' '
<< meshPts[es[edgeI].end()] + 1 << endl;
}
// Write faces in terms of edges.
const labelListList& faceEs = surf.faceEdges();
label faceIndex = 0;
forAll(patchLst, patchI)
{
forAll(patchLst[patchI], patchFaceI)
{
const labelList& fEdges = faceEs[faceMap[faceIndex++]];
os << fEdges[0] + 1 << ' '
<< fEdges[1] + 1 << ' '
<< fEdges[2] + 1 << ' '
<< patchI << endl;
}
}
}
void Foam::fileFormats::GTSfileFormat::write
(
Ostream& os,
const meshedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<surfacePatch>& patchLst = surf.patches();
const List<face>& faceLst = surf.faces();
// It is too annoying to triangulate on-the-fly
// just issue a warning and get out
label nNonTris = 0;
forAll(faceLst, faceI)
{
if (faceLst[faceI].size() > 3)
{
++nNonTris;
}
}
if (nNonTris)
{
WarningIn
(
"fileFormats::GTSfileFormat::write"
"(Ostream&, const meshedSurface&)"
)
<< "Surface has " << nNonTris << "/" << faceLst.size()
<< " non-triangulated faces - not writing!" << endl;
return;
}
// Write header, print patch names as comment
os << "# GTS file" << nl
<< "# Regions:" << nl;
forAll(patchLst, patchI)
{
os << "# " << patchI << " "
<< patchLst[patchI].name() << nl;
}
os << "#" << endl;
os << "# nPoints nEdges nTriangles" << nl
<< pointLst.size() << ' ' << surf.nEdges() << ' '
<< surf.size() << endl;
// Write vertex coords
forAll(pointLst, pointI)
{
os << pointLst[pointI].x() << ' '
<< pointLst[pointI].y() << ' '
<< pointLst[pointI].z() << endl;
}
// Write edges.
// Note: edges are in local point labels so convert
const edgeList& es = surf.edges();
const labelList& meshPts = surf.meshPoints();
forAll(es, edgei)
{
os << meshPts[es[edgei].start()] + 1 << ' '
<< meshPts[es[edgei].end()] + 1 << endl;
}
// Write faces in terms of edges.
const labelListList& faceEs = surf.faceEdges();
label faceIndex = 0;
forAll(patchLst, patchI)
{
const surfacePatch& patch = patchLst[patchI];
forAll(patch, patchFaceI)
{
const labelList& fEdges = faceEs[faceIndex++];
os << fEdges[0] + 1 << ' '
<< fEdges[1] + 1 << ' '
<< fEdges[2] + 1 << ' '
<< patchI << endl;
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,139 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::GTSfileFormat
Description
Provide a means of reading/writing GTS format.
SourceFiles
GTSfileFormat.C
\*---------------------------------------------------------------------------*/
#ifndef GTSfileFormat_H
#define GTSfileFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "keyedSurface.H"
#include "meshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
class GTSfileFormat;
/*---------------------------------------------------------------------------*\
Class GTSfileFormat Declaration
\*---------------------------------------------------------------------------*/
class GTSfileFormat
:
public keyedSurface
{
// Private Member Functions
//- Disallow default bitwise copy construct
GTSfileFormat(const GTSfileFormat&);
//- Disallow default bitwise assignment
void operator=(const GTSfileFormat&);
public:
// Constructors
//- Construct null
GTSfileFormat();
//- Construct from file name
GTSfileFormat(const fileName&, const bool triangulate=true);
// Selectors
//- Read file and return keyedSurface
static autoPtr<keyedSurface> New
(
const fileName& fName,
const bool triangulate=true
)
{
return autoPtr<keyedSurface>
(
new GTSfileFormat(fName, triangulate)
);
}
// Destructor
// Member Functions
// Write
//- Write keyedSurface
static void write(Ostream&, const keyedSurface&);
//- Write keyedSurface
static void write(const fileName& fName, const keyedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write meshedSurface
static void write(Ostream&, const meshedSurface&);
//- Write meshedSurface
static void write(const fileName& fName, const meshedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
{
write(os, *this);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,461 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "NASfileFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
// .bdf (Bulk Data Format)
addNamedToRunTimeSelectionTable
(
keyedSurface,
NASfileFormat,
fileExtension,
bdf
);
// .nas (Nastran)
addNamedToRunTimeSelectionTable
(
keyedSurface,
NASfileFormat,
fileExtension,
nas
);
// addNamedToMemberFunctionSelectionTable
// (
// keyedSurface,
// NASfileFormat,
// write,
// fileExtension,
// nas
// );
//
// addNamedToMemberFunctionSelectionTable
// (
// meshedSurface,
// NASfileFormat,
// write,
// fileExtension,
// nas
// );
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Do weird things to extract number
Foam::scalar Foam::fileFormats::NASfileFormat::parseNASCoord(const string& s)
{
size_t expSign = s.find_last_of("+-");
if (expSign != string::npos && expSign > 0 && !isspace(s[expSign-1]))
{
scalar mantissa = readScalar(IStringStream(s.substr(0, expSign))());
scalar exponent = readScalar(IStringStream(s.substr(expSign+1))());
if (s[expSign] == '-')
{
exponent = -exponent;
}
return mantissa*pow(10, exponent);
}
else
{
return readScalar(IStringStream(s)());
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::NASfileFormat::NASfileFormat()
:
Foam::keyedSurface()
{}
Foam::fileFormats::NASfileFormat::NASfileFormat
(
const fileName& fName,
const bool triangulate
)
:
Foam::keyedSurface()
{
IFstream is(fName);
if (!is.good())
{
FatalErrorIn("fileFormats::NASfileFormat::NASfileFormat(const fileName&)")
<< "Cannot read file " << fName
<< exit(FatalError);
}
DynamicList<point> pointLst;
// Nastran index of points
DynamicList<label> pointId;
DynamicList<keyedFace> faceLst;
HashTable<label> groupToPatch;
// From face groupId to patchId
Map<label> groupIdToPatchId;
label nPatches = 0;
// Name for face group
Map<word> groupIdToName;
// Ansa tags. Denoted by $ANSA_NAME. These will appear just before the
// first use of a type. We read them and store the pshell types which
// are used to name the patches.
label ansaId = -1;
word ansaType;
word ansaName;
// leave faces that didn't have a group in 0
// label groupID = 0;
// label maxGroupID = -1;
// A single warning per unrecognized command
HashSet<word> unhandledCmd;
while (is.good())
{
string line;
is.getLine(line);
// Ansa extension
if (line.substr(0, 10) == "$ANSA_NAME")
{
string::size_type sem0 = line.find (';', 0);
string::size_type sem1 = line.find (';', sem0+1);
string::size_type sem2 = line.find (';', sem1+1);
if
(
sem0 != string::npos
&& sem1 != string::npos
&& sem2 != string::npos
)
{
ansaId = readLabel
(
IStringStream(line.substr(sem0+1, sem1-sem0-1))()
);
ansaType = line.substr(sem1+1, sem2-sem1-1);
string rawName;
is.getLine(rawName);
if (rawName[rawName.size()-1] == '\r')
{
rawName = rawName.substr(1, rawName.size()-2);
}
else
{
rawName = rawName.substr(1, rawName.size()-1);
}
string::stripInvalid<word>(rawName);
ansaName = rawName;
// Info<< "ANSA tag for NastranID:" << ansaID
// << " of type " << ansaType
// << " name " << ansaName << endl;
}
}
// Hypermesh extension
// $HMNAME COMP 1"partName"
if
(
line.substr(0, 12) == "$HMNAME COMP"
&& line.find ('"') != string::npos
)
{
label groupId = readLabel
(
IStringStream(line.substr(16, 16))()
);
IStringStream lineStream(line.substr(32));
string rawName;
lineStream >> rawName;
string::stripInvalid<word>(rawName);
word groupName(rawName);
groupIdToName.insert(groupId, groupName);
Info<< "group " << groupId << " => " << groupName << endl;
}
// Skip empty or comment
if (line.size() == 0 || line[0] == '$')
{
continue;
}
// Check if character 72 is continuation
if (line.size() > 72 && line[72] == '+')
{
line = line.substr(0, 72);
while (true)
{
string buf;
is.getLine(buf);
if (buf.size() > 72 && buf[72] == '+')
{
line += buf.substr(8, 64);
}
else
{
line += buf.substr(8, buf.size()-8);
break;
}
}
}
// Read first word
IStringStream lineStream(line);
word cmd;
lineStream >> cmd;
if (cmd == "CTRIA3")
{
face fTri(3);
label groupId = readLabel(IStringStream(line.substr(16,8))());
fTri[0] = readLabel(IStringStream(line.substr(24,8))());
fTri[1] = readLabel(IStringStream(line.substr(32,8))());
fTri[2] = readLabel(IStringStream(line.substr(40,8))());
// Convert groupID into patchID
Map<label>::const_iterator iter = groupIdToPatchId.find(groupId);
label patchI;
if (iter == groupIdToPatchId.end())
{
patchI = nPatches++;
groupIdToPatchId.insert(groupId, patchI);
Info<< "patch " << patchI << " => group " << groupId << endl;
}
else
{
patchI = iter();
}
faceLst.append(keyedFace(fTri, patchI));
}
else if (cmd == "CQUAD4")
{
face fQuad(4);
label groupId = readLabel(IStringStream(line.substr(16,8))());
fQuad[0] = readLabel(IStringStream(line.substr(24,8))());
fQuad[1] = readLabel(IStringStream(line.substr(32,8))());
fQuad[2] = readLabel(IStringStream(line.substr(40,8))());
fQuad[3] = readLabel(IStringStream(line.substr(48,8))());
// Convert group into patch
Map<label>::const_iterator iter = groupIdToPatchId.find(groupId);
label patchI;
if (iter == groupIdToPatchId.end())
{
patchI = nPatches++;
groupIdToPatchId.insert(groupId, patchI);
Info<< "patch " << patchI << " => group " << groupId << endl;
}
else
{
patchI = iter();
}
if (triangulate)
{
face fTri(3);
// simple face triangulation about f[0].
// cannot use face::triangulation since points are incomplete
fTri[0] = fQuad[0];
for (label fp1 = 1; fp1 < fQuad.size() - 1; fp1++)
{
label fp2 = (fp1 + 1) % fQuad.size();
fTri[1] = fQuad[fp1];
fTri[2] = fQuad[fp2];
faceLst.append(keyedFace(fTri, patchI));
}
}
else
{
faceLst.append(keyedFace(fQuad, patchI));
}
}
else if (cmd == "PSHELL")
{
// Read shell type since group gives patchnames.
label groupId = readLabel(IStringStream(line.substr(8,8))());
if (groupId == ansaId && ansaType == "PSHELL")
{
groupIdToName.insert(groupId, ansaName);
Info<< "group " << groupId << " => " << ansaName << endl;
}
}
else if (cmd == "GRID")
{
label index = readLabel(IStringStream(line.substr(8,8))());
scalar x = parseNASCoord(line.substr(24, 8));
scalar y = parseNASCoord(line.substr(32, 8));
scalar z = parseNASCoord(line.substr(40, 8));
pointId.append(index);
pointLst.append(point(x, y, z));
}
else if (cmd == "GRID*")
{
// Long format is on two lines with '*' continuation symbol
// on start of second line.
// Typical line (spaces compacted)
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02
// * 2.14897901E+02
label index = readLabel(IStringStream(line.substr(8,16))());
scalar x = parseNASCoord(line.substr(40, 16));
scalar y = parseNASCoord(line.substr(56, 16));
is.getLine(line);
if (line[0] != '*')
{
FatalErrorIn
(
"fileFormats::NASfileFormat::NASfileFormat"
"(const fileName&)"
)
<< "Expected continuation symbol '*' when reading GRID*"
<< " (double precision coordinate) output" << nl
<< "Read:" << line << nl
<< "File:" << is.name()
<< " line:" << is.lineNumber()
<< exit(FatalError);
}
scalar z = parseNASCoord(line.substr(8, 16));
pointId.append(index);
pointLst.append(point(x, y, z));
}
else if (unhandledCmd.insert(cmd))
{
Info<< "Unhandled Nastran command " << line << nl
<< "File:" << is.name()
<< " line:" << is.lineNumber()
<< endl;
}
}
Info<< "Read faces:" << faceLst.size()
<< " points:" << pointLst.size()
<< endl;
// transfer to normal lists
points().transfer(pointLst);
pointId.shrink();
faceLst.shrink();
{
// Build inverse mapping (index to point)
Map<label> nasToFoamPoint(2*pointId.size());
forAll(pointId, i)
{
nasToFoamPoint.insert(pointId[i], i);
}
pointId.clearStorage();
// Relabel faces
forAll(faceLst, i)
{
keyedFace& f = faceLst[i];
forAll(f, fp)
{
f[fp] = nasToFoamPoint[f[fp]];
}
}
}
// convert Nastran groupId => name to patchId => name
Map<word> regionNames;
forAllConstIter(Map<word>, groupIdToName, iter)
{
Map<label>::const_iterator iter2 = groupIdToPatchId.find(iter.key());
if (iter2 != groupIdToPatchId.end())
{
regionNames.insert(iter2.key(), iter());
}
}
// transfer to normal lists
faces().transfer(faceLst);
setPatches(regionNames);
}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// ************************************************************************* //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,122 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::NASfileFormat
Description
Nastran surface reader.
- Uses the Ansa "$ANSA_NAME" or the Hypermesh "$HMNAME COMP" extensions
to obtain patch names.
- Handles Nastran short and long formats, but not free format.
- Properly handles the Nastran compact floating point notation: \n
@verbatim
GRID 28 10.20269-.030265-2.358-8
@endverbatim
SourceFiles
NASfileFormat.C
\*---------------------------------------------------------------------------*/
#ifndef NASfileFormat_H
#define NASfileFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "keyedSurface.H"
#include "meshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class NASfileFormat Declaration
\*---------------------------------------------------------------------------*/
class NASfileFormat
:
public keyedSurface
{
// Private Member Functions
//- Do weird things to extract number
static scalar parseNASCoord(const string&);
//- Disallow default bitwise copy construct
NASfileFormat(const NASfileFormat&);
//- Disallow default bitwise assignment
void operator=(const NASfileFormat&);
public:
// Constructors
//- Construct null
NASfileFormat();
//- Construct from file name
NASfileFormat(const fileName&, const bool triangulate=false);
// Selectors
//- Read file and return keyedSurface
static autoPtr<keyedSurface> New
(
const fileName& fName,
const bool triangulate=false
)
{
return autoPtr<keyedSurface>
(
new NASfileFormat(fName,triangulate)
);
}
// Destructor
// Member Functions
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,371 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "OBJfileFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
addNamedToRunTimeSelectionTable
(
keyedSurface,
OBJfileFormat,
fileExtension,
obj
);
addNamedToMemberFunctionSelectionTable
(
keyedSurface,
OBJfileFormat,
write,
fileExtension,
obj
);
addNamedToMemberFunctionSelectionTable
(
meshedSurface,
OBJfileFormat,
write,
fileExtension,
obj
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::OBJfileFormat::OBJfileFormat()
:
Foam::keyedSurface()
{}
Foam::fileFormats::OBJfileFormat::OBJfileFormat
(
const fileName& fName,
const bool triangulate
)
:
Foam::keyedSurface()
{
IFstream is(fName);
if (!is.good())
{
FatalErrorIn("fileFormats::OBJfileFormat::OBJfileFormat(const fileName&)")
<< "Cannot read file " << fName
<< exit(FatalError);
}
DynamicList<point> pointLst;
DynamicList<keyedFace> faceLst;
HashTable<label> groupToPatch;
// leave faces that didn't have a group in 0
label groupID = 0;
label maxGroupID = -1;
while (is.good())
{
string line = getLineNoComment(is);
// handle continuations
if (line[line.size()-1] == '\\')
{
line.substr(0, line.size()-1);
line += getLineNoComment(is);
}
// Read first word
IStringStream lineStream(line);
word cmd;
lineStream >> cmd;
if (cmd == "v")
{
scalar x, y, z;
lineStream >> x >> y >> z;
pointLst.append(point(x, y, z));
}
else if (cmd == "g")
{
word groupName;
lineStream >> groupName;
HashTable<label>::const_iterator findGroup =
groupToPatch.find(groupName);
if (findGroup != groupToPatch.end())
{
groupID = findGroup();
}
else
{
// special treatment if any initial faces were not in a group
if (maxGroupID == -1 && faceLst.size())
{
groupToPatch.insert("patch0", 0);
maxGroupID = 0;
}
groupID = ++maxGroupID;
groupToPatch.insert(groupName, groupID);
}
}
else if (cmd == "f")
{
DynamicList<label> verts;
// Assume 'f' is followed by space.
string::size_type endNum = 1;
while (true)
{
string::size_type startNum = line.find_first_not_of(' ', endNum);
if (startNum == string::size_type(string::npos))
{
break;
}
endNum = line.find(' ', startNum);
string vertexSpec;
if (endNum != string::size_type(string::npos))
{
vertexSpec = line.substr(startNum, endNum-startNum);
}
else
{
vertexSpec = line.substr(startNum, line.size() - startNum);
}
string::size_type slashPos = vertexSpec.find('/');
label vertI = 0;
if (slashPos != string::size_type(string::npos))
{
IStringStream intStream(vertexSpec.substr(0, slashPos));
intStream >> vertI;
}
else
{
IStringStream intStream(vertexSpec);
intStream >> vertI;
}
verts.append(vertI - 1);
}
verts.shrink();
if (triangulate && verts.size() > 3)
{
face fTri(3);
// simple face triangulation about f[0].
// Cannot use face::triangulation since points are incomplete
fTri[0] = verts[0];
for (label fp1 = 1; fp1 < verts.size() - 1; fp1++)
{
label fp2 = (fp1 + 1) % verts.size();
fTri[1] = verts[fp1];
fTri[2] = verts[fp2];
faceLst.append(keyedFace(fTri, groupID));
}
}
else
{
faceLst.append
(
keyedFace
(
face( xferMoveTo<labelList>(verts) ),
groupID
)
);
}
}
}
// transfer to normal lists
points().transfer(pointLst);
faces().transfer(faceLst);
setPatches(groupToPatch);
}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::OBJfileFormat::write
(
Ostream& os,
const keyedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<keyedFace>& faceLst = surf.faces();
labelList faceMap;
List<surfacePatch> patchLst = surf.sortedRegions(faceMap);
os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl
<< "o " << os.name().lessExt().name() << nl
<< nl
<< "# points : " << pointLst.size() << nl
<< "# faces : " << faceLst.size() << nl
<< "# patches: " << patchLst.size() << nl;
// Print patch names as comment
forAll(patchLst, patchI)
{
os << "# " << patchI << " " << patchLst[patchI].name()
<< " (nFaces: " << patchLst[patchI].size() << ")" << nl;
}
os << nl
<< "# <points count=\"" << pointLst.size() << "\">" << endl;
// Write vertex coords
forAll(pointLst, ptI)
{
os << "v " << pointLst[ptI].x()
<< ' ' << pointLst[ptI].y()
<< ' ' << pointLst[ptI].z() << nl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << faceLst.size() << "\">" << endl;
label faceIndex = 0;
forAll(patchLst, patchI)
{
// Print all faces belonging to this region
const surfacePatch& patch = patchLst[patchI];
os << "g " << patch.name() << endl;
forAll(patch, patchFaceI)
{
const face& f = faceLst[faceMap[faceIndex++]];
os << 'f';
forAll(f, fp)
{
os << ' ' << f[fp] + 1;
}
os << endl;
}
}
os << "# </faces>" << endl;
}
void Foam::fileFormats::OBJfileFormat::write
(
Ostream& os,
const meshedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<face>& faceLst = surf.faces();
const List<surfacePatch>& patchLst = surf.patches();
os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl
<< "o " << os.name().lessExt().name() << nl
<< nl
<< "# points : " << pointLst.size() << nl
<< "# faces : " << faceLst.size() << nl
<< "# patches: " << patchLst.size() << nl;
// Print patch names as comment
forAll(patchLst, patchI)
{
os << "# " << patchI << " " << patchLst[patchI].name()
<< " (nFaces: " << patchLst[patchI].size() << ")" << nl;
}
os << nl
<< "# <points count=\"" << pointLst.size() << "\">" << endl;
// Write vertex coords
forAll(pointLst, ptI)
{
os << "v " << pointLst[ptI].x()
<< ' ' << pointLst[ptI].y()
<< ' ' << pointLst[ptI].z() << nl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << faceLst.size() << "\">" << endl;
label faceIndex = 0;
forAll(patchLst, patchI)
{
const surfacePatch& patch = patchLst[patchI];
os << "g " << patch.name() << endl;
forAll(patch, patchFaceI)
{
const face& f = faceLst[faceIndex++];
os << 'f';
forAll(f, fp)
{
os << ' ' << f[fp] + 1;
}
os << endl;
}
}
os << "# </faces>" << endl;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,139 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::OBJfileFormat
Description
Provide a means of reading/writing Alias/Wavefront OBJ format.
Does not handle negative face indices.
SourceFiles
OBJfileFormat.C
\*---------------------------------------------------------------------------*/
#ifndef OBJfileFormat_H
#define OBJfileFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "keyedSurface.H"
#include "meshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class OBJfileFormat Declaration
\*---------------------------------------------------------------------------*/
class OBJfileFormat
:
public keyedSurface
{
// Private Member Functions
//- Disallow default bitwise copy construct
OBJfileFormat(const OBJfileFormat&);
//- Disallow default bitwise assignment
void operator=(const OBJfileFormat&);
public:
// Constructors
//- Construct null
OBJfileFormat();
//- Construct from file name
OBJfileFormat(const fileName&, const bool triangulate=false);
// Selectors
//- Read file and return keyedSurface
static autoPtr<keyedSurface> New
(
const fileName& fName,
const bool triangulate = false
)
{
return autoPtr<keyedSurface>
(
new OBJfileFormat(fName, triangulate)
);
}
// Destructor
// Member Functions
// Write
//- Write keyedSurface
static void write(Ostream&, const keyedSurface&);
//- Write keyedSurface
static void write(const fileName& fName, const keyedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write meshedSurface
static void write(Ostream&, const meshedSurface&);
//- Write meshedSurface
static void write(const fileName& fName, const meshedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
{
write(os, *this);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,326 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "OFFfileFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
addNamedToRunTimeSelectionTable
(
keyedSurface,
OFFfileFormat,
fileExtension,
off
);
addNamedToMemberFunctionSelectionTable
(
keyedSurface,
OFFfileFormat,
write,
fileExtension,
off
);
addNamedToMemberFunctionSelectionTable
(
meshedSurface,
OFFfileFormat,
write,
fileExtension,
off
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::OFFfileFormat::OFFfileFormat()
:
keyedSurface()
{}
Foam::fileFormats::OFFfileFormat::OFFfileFormat
(
const fileName& fName,
const bool triangulate
)
:
keyedSurface()
{
IFstream is(fName);
if (!is.good())
{
FatalErrorIn("fileFormats::OFFfileFormat(const fileName&)")
<< "Cannot read file " << fName
<< exit(FatalError);
}
// Read header
string hdr = getLineNoComment(is);
if (hdr != "OFF")
{
FatalErrorIn("fileFormats::OFFfileFormat(const fileName&)")
<< "OFF file " << fName
<< " does not start with 'OFF'"
<< exit(FatalError);
}
// get dimensions
label nPoints, nEdges, nElems;
string line = getLineNoComment(is);
{
IStringStream lineStream(line);
lineStream >> nPoints >> nElems >> nEdges;
}
// Read points
pointField pointLst(nPoints);
forAll(pointLst, pointI)
{
scalar x, y, z;
line = getLineNoComment(is);
{
IStringStream lineStream(line);
lineStream >> x >> y >> z;
}
pointLst[pointI] = point(x, y, z);
}
// Read faces - ignore optional region information
// use a DynamicList for possible on-the-fly triangulation
DynamicList<keyedFace> faceLst(nElems);
forAll(faceLst, faceI)
{
line = getLineNoComment(is);
{
IStringStream lineStream(line);
label nVerts;
lineStream >> nVerts;
face f(nVerts);
forAll(f, fp)
{
lineStream >> f[fp];
}
if (triangulate && f.size() > 3)
{
face fTri(3);
// simple face triangulation about f[0].
// cannot use face::triangulation since points are incomplete
fTri[0] = f[0];
for (label fp1 = 1; fp1 < f.size() - 1; fp1++)
{
label fp2 = (fp1 + 1) % f.size();
fTri[1] = f[fp1];
fTri[2] = f[fp2];
faceLst.append(keyedFace(fTri, 0));
}
}
else
{
faceLst.append(keyedFace(f, 0));
}
}
}
// no region information
points().transfer(pointLst);
faces().transfer(faceLst);
setPatches(0);
}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::OFFfileFormat::write
(
Ostream& os,
const keyedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<keyedFace>& faceLst = surf.faces();
labelList faceMap;
List<surfacePatch> patchLst = surf.sortedRegions(faceMap);
// Write header
os << "OFF" << endl
<< "# Geomview OFF file written " << clock::dateTime().c_str() << nl
<< nl
<< "# points : " << pointLst.size() << nl
<< "# faces : " << faceLst.size() << nl
<< "# patches: " << patchLst.size() << nl;
// Print patch names as comment
forAll(patchLst, patchI)
{
os << "# " << patchI << " " << patchLst[patchI].name()
<< " (nFaces: " << patchLst[patchI].size() << ")" << nl;
}
os << nl
<< "# nPoints nFaces nEdges" << nl
<< pointLst.size() << ' ' << faceLst.size() << ' ' << 0 << nl;
os << nl
<< "# <points count=\"" << pointLst.size() << "\">" << endl;
// Write vertex coords
forAll(pointLst, ptI)
{
os << pointLst[ptI].x() << ' '
<< pointLst[ptI].y() << ' '
<< pointLst[ptI].z() << " #" << ptI << endl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << faceLst.size() << "\">" << endl;
label faceIndex = 0;
forAll(patchLst, patchI)
{
os << "# <patch name=\"" << patchLst[patchI].name() << "\">" << endl;
forAll(patchLst[patchI], patchFaceI)
{
const face& f = faceLst[faceMap[faceIndex++]];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
// add optional region information
os << ' ' << patchI << endl;
}
os << "# </patch>" << endl;
}
os << "# </faces>" << endl;
}
void Foam::fileFormats::OFFfileFormat::write
(
Ostream& os,
const meshedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<face>& faceLst = surf.faces();
const List<surfacePatch>& patchLst = surf.patches();
// Write header
os << "OFF" << endl
<< "# Geomview OFF file written " << clock::dateTime().c_str() << nl
<< nl
<< "# points : " << pointLst.size() << nl
<< "# faces : " << faceLst.size() << nl
<< "# patches: " << patchLst.size() << nl;
// Print patch names as comment
forAll(patchLst, patchI)
{
os << "# " << patchI << " " << patchLst[patchI].name()
<< " (nFaces: " << patchLst[patchI].size() << ")" << nl;
}
os << nl
<< "# nPoints nFaces nEdges" << nl
<< pointLst.size() << ' ' << faceLst.size() << ' ' << 0 << nl;
os << nl
<< "# <points count=\"" << pointLst.size() << "\">" << endl;
// Write vertex coords
forAll(pointLst, ptI)
{
os << pointLst[ptI].x() << ' '
<< pointLst[ptI].y() << ' '
<< pointLst[ptI].z() << " #" << ptI << endl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << faceLst.size() << "\">" << endl;
label faceIndex = 0;
forAll(patchLst, patchI)
{
os << "# <patch name=\"" << patchLst[patchI].name() << "\">" << endl;
forAll(patchLst[patchI], patchFaceI)
{
const face& f = faceLst[faceIndex++];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
// add optional region information
os << ' ' << patchI << endl;
}
os << "# </patch>" << endl;
}
os << "# </faces>" << endl;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,146 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::OFFfileFormat
Description
Provide a means of reading/writing Geomview OFF polyList format.
See Also
The <a href="http://www.geoview.org">Geoview</a>
file format information:
http://www.geomview.org/docs/html/OFF.html#OFF
Note
When reading, the optional @a colorspec is ignored.
When writing, it is set to the region number (integer).
SourceFiles
OFFfileFormat.C
\*---------------------------------------------------------------------------*/
#ifndef OFFfileFormat_H
#define OFFfileFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "keyedSurface.H"
#include "meshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class OFFfileFormat Declaration
\*---------------------------------------------------------------------------*/
class OFFfileFormat
:
public keyedSurface
{
// Private Member Functions
//- Disallow default bitwise copy construct
OFFfileFormat(const OFFfileFormat&);
//- Disallow default bitwise assignment
void operator=(const OFFfileFormat&);
public:
// Constructors
//- Construct null
OFFfileFormat();
//- Construct from file name
OFFfileFormat(const fileName&, const bool triangulate=false);
// Selectors
//- Read file and return keyedSurface
static autoPtr<keyedSurface> New
(
const fileName& fName,
const bool triangulate=false
)
{
return autoPtr<keyedSurface>
(
new OFFfileFormat(fName,triangulate)
);
}
// Destructor
// Member Functions
// Write
//- Write keyedSurface
static void write(Ostream&, const keyedSurface&);
//- Write keyedSurface
static void write(const fileName& fName, const keyedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write meshedSurface
static void write(Ostream&, const meshedSurface&);
//- Write meshedSurface
static void write(const fileName& fName, const meshedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
{
write(os, *this);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,185 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "SMESHfileFormat.H"
#include "clock.H"
#include "IStringStream.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
addNamedToMemberFunctionSelectionTable
(
keyedSurface,
SMESHfileFormat,
write,
fileExtension,
smesh
);
addNamedToMemberFunctionSelectionTable
(
meshedSurface,
SMESHfileFormat,
write,
fileExtension,
smesh
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::SMESHfileFormat::SMESHfileFormat()
:
keyedSurface()
{}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void
Foam::fileFormats::SMESHfileFormat::write
(
Ostream& os,
const keyedSurface& surf
)
{
const pointField& pointLst= surf.points();
const List<keyedFace>& faceLst = surf.faces();
labelList faceMap;
List<surfacePatch> patchLst = surf.sortedRegions(faceMap);
os << "# tetgen .smesh file written " << clock::dateTime().c_str() << nl;
os << "# <points count=\"" << pointLst.size() << "\">" << endl;
os << pointLst.size() << " 3" << nl; // 3: dimensions
// Write vertex coords
forAll(pointLst, ptI)
{
os << ptI
<< ' ' << pointLst[ptI].x()
<< ' ' << pointLst[ptI].y()
<< ' ' << pointLst[ptI].z() << nl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << faceLst.size() << "\">" << endl;
os << faceLst.size() << " 1" << endl; // one attribute: region number
label faceIndex = 0;
forAll(patchLst, patchI)
{
forAll(patchLst[patchI], patchFaceI)
{
const face& f = faceLst[faceMap[faceIndex++]];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << patchI << endl;
}
}
os << "# </faces>" << nl
<< nl
<< "# no holes or regions:" << nl
<< '0' << nl // holes
<< '0' << endl; // regions
}
void
Foam::fileFormats::SMESHfileFormat::write
(
Ostream& os,
const meshedSurface& surf
)
{
const pointField& pointLst= surf.points();
const List<face>& faceLst = surf.faces();
const List<surfacePatch>& patchLst = surf.patches();
os << "# tetgen .smesh file written " << clock::dateTime().c_str() << nl;
os << "# <points count=\"" << pointLst.size() << "\">" << endl;
os << pointLst.size() << " 3" << nl; // 3: dimensions
// Write vertex coords
forAll(pointLst, ptI)
{
os << ptI
<< ' ' << pointLst[ptI].x()
<< ' ' << pointLst[ptI].y()
<< ' ' << pointLst[ptI].z() << nl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << faceLst.size() << "\">" << endl;
os << faceLst.size() << " 1" << endl; // one attribute: region number
label faceIndex = 0;
forAll(patchLst, patchI)
{
forAll(patchLst[patchI], patchFaceI)
{
const face& f = faceLst[faceIndex++];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << patchI << endl;
}
}
os << "# </faces>" << nl
<< nl
<< "# no holes or regions:" << nl
<< '0' << nl // holes
<< '0' << endl; // regions
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,128 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::SMESHfileFormat
Description
Provide a means of writing tetgen SMESH format.
Tetgen http://tetgen.berlios.de
See Also
File format information:
http://tetgen.berlios.de/fformats.smesh.html
SourceFiles
SMESHfileFormat.C
\*---------------------------------------------------------------------------*/
#ifndef SMESHfileFormat_H
#define SMESHfileFormat_H
#include "IFstream.H"
#include "OFstream.H"
#include "Ostream.H"
#include "keyedSurface.H"
#include "meshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class SMESHfileFormat Declaration
\*---------------------------------------------------------------------------*/
class SMESHfileFormat
:
public keyedSurface
{
// Private data
// Private Member Functions
//- Disallow default bitwise copy construct
SMESHfileFormat(const SMESHfileFormat&);
//- Disallow default bitwise assignment
void operator=(const SMESHfileFormat&);
public:
// Constructors
//- Construct null
SMESHfileFormat();
// Selectors
// Destructor
// Member Functions
//- Write keyedSurface
static void write(Ostream&, const keyedSurface&);
//- Write meshedSurface
static void write(Ostream&, const meshedSurface&);
//- Write keyedSurface
static void write(const fileName& fName, const keyedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write meshedSurface
static void write(const fileName& fName, const meshedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
{
write(os, *this);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,478 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "STARCDfileFormat.H"
#include "clock.H"
#include "OSspecific.H"
#include "IStringStream.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
addNamedToRunTimeSelectionTable
(
keyedSurface,
STARCDfileFormat,
fileExtension,
inp
);
addNamedToMemberFunctionSelectionTable
(
keyedSurface,
STARCDfileFormat,
write,
fileExtension,
inp
);
addNamedToMemberFunctionSelectionTable
(
meshedSurface,
STARCDfileFormat,
write,
fileExtension,
inp
);
}
}
//! @cond localScope
const int starcdShellShape = 3;
const int starcdShellType = 4;
//! @endcond localScope
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::fileFormats::STARCDfileFormat::readHeader
(
IFstream& is,
const word& signature
)
{
if (!is.good())
{
FatalErrorIn("fileFormats::STARCDfileFormat::readHeader()")
<< "cannot read " << signature << " " << is.name()
<< abort(FatalError);
}
word header;
label majorVersion;
string line;
is.getLine(line);
IStringStream(line)() >> header;
is.getLine(line);
IStringStream(line)() >> majorVersion;
// add other checks ...
if (header != signature)
{
Info<< "header mismatch " << signature << " " << is.name()
<< endl;
}
return true;
}
void Foam::fileFormats::STARCDfileFormat::writeHeader
(
Ostream& os,
const char* filetype
)
{
os << "PROSTAR_" << filetype << nl
<< 4000
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< " " << 0
<< endl;
}
void Foam::fileFormats::STARCDfileFormat::writePoints
(
Ostream& os,
const pointField& pointLst
)
{
writeHeader(os, "VERTEX");
// Set the precision of the points data to 10
os.precision(10);
// force decimal point for Fortran input
os.setf(std::ios::showpoint);
forAll(pointLst, ptI)
{
os
<< ptI + 1 << " "
<< pointLst[ptI].x() << " "
<< pointLst[ptI].y() << " "
<< pointLst[ptI].z() << nl;
}
os.flush();
}
inline void Foam::fileFormats::STARCDfileFormat::writeShell
(
Ostream& os,
const face& f,
const label cellId,
const label cellTableId
)
{
os
<< cellId // includes 1 offset
<< " " << starcdShellShape // 3(shell)
<< " " << f.size()
<< " " << cellTableId
<< " " << starcdShellType; // 4(shell)
// primitives have <= 8 vertices, but prevent overrun anyhow
// indent following lines for ease of reading
label count = 0;
forAll(f, fp)
{
if ((count % 8) == 0)
{
os
<< nl
<< " " << cellId;
}
os << " " << f[fp] + 1;
count++;
}
os << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::STARCDfileFormat::STARCDfileFormat()
:
Foam::keyedSurface()
{}
// .vrt file format:
/*---------------------------------------------------------------------------*\
Line 1:
PROSTAR_VERTEX [newline]
Line 2:
<version> 0 0 0 0 0 0 0 [newline]
Body:
<vertexId> <x> <y> <z> [newline]
\*---------------------------------------------------------------------------*/
Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
(
const fileName& fName,
const bool triangulation
)
:
Foam::keyedSurface()
{
fileName baseName = fName.lessExt();
autoPtr<IFstream> isPtr;
DynamicList<point> pointLst;
// STAR-CD index of points
DynamicList<label> pointId;
//
// read .vrt file
//
isPtr.reset(new IFstream(baseName + ".vrt"));
if (!isPtr().good())
{
FatalErrorIn
(
"fileFormats::STARCDfileFormat::STARCDfileFormat(const fileName&)"
)
<< "Cannot read file " << (baseName + ".vrt")
<< exit(FatalError);
}
readHeader(isPtr(), "PROSTAR_VERTEX");
label lineLabel;
while ((isPtr() >> lineLabel).good())
{
pointId.append(lineLabel);
scalar x, y, z;
isPtr() >> x >> y >> z;
pointLst.append(point(x, y, z));
}
// transfer to normal lists
points().transfer(pointLst);
// Build inverse mapping (index to point)
pointId.shrink();
Map<label> mapToFoamPointId(2*pointId.size());
forAll(pointId, i)
{
mapToFoamPointId.insert(pointId[i], i);
}
pointId.clear();
DynamicList<keyedFace> faceLst;
// From face cellTableId to patchId
Map<label> cellTableToPatchId;
label nPatches = 0;
//
// read .cel file
//
isPtr.reset(new IFstream(baseName + ".cel"));
if (!isPtr().good())
{
FatalErrorIn
(
"fileFormats::STARCDfileFormat::STARCDfileFormat(const fileName&)"
)
<< "Cannot read file " << (baseName + ".cel")
<< exit(FatalError);
}
readHeader(isPtr(), "PROSTAR_CELL");
label shapeId, nLabels, cellTableId, typeId;
labelList starLabels(64);
while ((isPtr() >> lineLabel).good())
{
isPtr() >> shapeId >> nLabels >> cellTableId >> typeId;
if (nLabels > starLabels.size())
{
starLabels.setSize(nLabels);
}
starLabels = -1;
// read indices - max 8 per line
for (label i = 0; i < nLabels; ++i)
{
if ((i % 8) == 0)
{
isPtr() >> lineLabel;
}
isPtr() >> starLabels[i];
}
if (typeId == starcdShellType)
{
// Convert groupID into patchID
Map<label>::const_iterator iter =
cellTableToPatchId.find(cellTableId);
label patchI;
if (iter == cellTableToPatchId.end())
{
patchI = nPatches++;
cellTableToPatchId.insert(cellTableId, patchI);
}
else
{
patchI = iter();
}
// convert orig vertex id to point label
for (label i=0; i < nLabels; ++i)
{
starLabels[i] = mapToFoamPointId[starLabels[i]];
}
if (triangulation && nLabels > 3)
{
face f
(
SubList<label>(starLabels, nLabels)
);
faceList triFaces(f.nTriangles(points()));
label nTri = 0;
f.triangles(points(), nTri, triFaces);
forAll(triFaces, faceI)
{
faceLst.append
(
keyedFace
(
triFaces[faceI],
patchI
)
);
}
}
else
{
faceLst.append
(
keyedFace
(
face(SubList<label>(starLabels, nLabels)),
patchI
)
);
}
}
}
mapToFoamPointId.clear();
// convert cellTable_N patchId => name
Map<word> regionNames;
forAllConstIter(Map<label>, cellTableToPatchId, iter)
{
regionNames.insert
(
iter(),
"cellTable_" + Foam::name(iter.key())
);
}
// transfer to normal lists
faces().transfer(faceLst);
setPatches(regionNames);
}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::STARCDfileFormat::write
(
const fileName& fName,
const keyedSurface& surf
)
{
const List<keyedFace>& faceLst = surf.faces();
fileName baseName = fName.lessExt();
autoPtr<OFstream> osPtr;
osPtr.reset(new OFstream(baseName + ".vrt"));
writePoints(osPtr(), surf.points());
labelList faceMap;
List<surfacePatch> patchLst = surf.sortedRegions(faceMap);
osPtr.reset(new OFstream(baseName + ".cel"));
writeHeader(osPtr(), "CELL");
label faceIndex = 0;
forAll(patchLst, patchI)
{
const surfacePatch& patch = patchLst[patchI];
forAll(patch, patchFaceI)
{
const face& f = faceLst[faceMap[faceIndex++]];
writeShell(osPtr(), f, faceIndex, patchI + 1);
}
}
}
void Foam::fileFormats::STARCDfileFormat::write
(
const fileName& fName,
const meshedSurface& surf
)
{
const List<face>& faceLst = surf.faces();
const List<surfacePatch>& patchLst = surf.patches();
fileName baseName = fName.lessExt();
autoPtr<OFstream> osPtr;
osPtr.reset(new OFstream(baseName + ".vrt"));
writePoints(osPtr(), surf.points());
osPtr.reset(new OFstream(baseName + ".cel"));
writeHeader(osPtr(), "CELL");
label faceIndex = 0;
forAll(patchLst, patchI)
{
const surfacePatch& patch = patchLst[patchI];
forAll(patch, patchFaceI)
{
const face& f = faceLst[faceIndex++];
writeShell(osPtr(), f, faceIndex, patchI + 1);
}
}
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,149 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::STARCDfileFormat
Description
Read/write the surface shells from pro-STAR vrt/cel files.
Note
Uses the extension @a .inp (input) to denote the format.
See Also
Foam::meshReaders::STARCD
SourceFiles
STARCDfileFormat.C
\*---------------------------------------------------------------------------*/
#ifndef STARCDfileFormat_H
#define STARCDfileFormat_H
#include "STLtriangle.H"
#include "IFstream.H"
#include "Ostream.H"
#include "OFstream.H"
#include "keyedSurface.H"
#include "meshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class STARCDfileFormat Declaration
\*---------------------------------------------------------------------------*/
class STARCDfileFormat
:
public keyedSurface
{
// Private data
// Private Member Functions
//- Disallow default bitwise copy construct
STARCDfileFormat(const STARCDfileFormat&);
//- Disallow default bitwise assignment
void operator=(const STARCDfileFormat&);
static bool readHeader(IFstream&, const word&);
static void writeHeader(Ostream&, const char* filetype);
static void writePoints(Ostream&, const pointField&);
static inline void writeShell
(
Ostream&,
const face&,
const label cellId,
const label cellTableId
);
public:
// Constructors
//- Construct null
STARCDfileFormat();
//- Construct from file name
STARCDfileFormat(const fileName&, const bool triangulate=true);
// Selectors
//- Read file and return keyedSurface
static autoPtr<keyedSurface> New
(
const fileName& fName,
const bool triangulate=true
)
{
return autoPtr<keyedSurface>
(
new STARCDfileFormat(fName, triangulate)
);
}
// Destructor
// Member Functions
// Write
//- Write keyedSurface
static void write(const fileName&, const keyedSurface&);
//- Write meshedSurface
static void write(const fileName&, const meshedSurface&);
//- Write to Ostream as one large file - not really useful
virtual void write(Ostream&) const
{
notImplemented("fileFormats::STARCDfileFormat::write(Ostream&)");
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,590 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "STLfileFormat.H"
#include "clock.H"
#include "OSspecific.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
addNamedToRunTimeSelectionTable
(
keyedSurface,
STLfileFormat,
fileExtension,
stl
);
addNamedToRunTimeSelectionTable
(
keyedSurface,
STLfileFormat,
fileExtension,
stlb
);
addNamedToMemberFunctionSelectionTable
(
keyedSurface,
STLfileFormat,
write,
fileExtension,
stl
);
addNamedToMemberFunctionSelectionTable
(
keyedSurface,
STLfileFormat,
write,
fileExtension,
stlb
);
addNamedToMemberFunctionSelectionTable
(
meshedSurface,
STLfileFormat,
write,
fileExtension,
stl
);
addNamedToMemberFunctionSelectionTable
(
meshedSurface,
STLfileFormat,
write,
fileExtension,
stlb
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// check binary by getting the header and number of facets
// this seems to work better than the old token-based method
// - some programs (eg, pro-STAR) have 'solid' as the first word in
// the binary header.
// - using wordToken can cause an abort if non-word (binary) content
// is detected ... this is not exactly what we want.
bool Foam::fileFormats::STLfileFormat::detectBINARY
(
const fileName& fName
)
{
off_t fileSize = Foam::size(fName);
IFstream ifs(fName, IOstream::BINARY);
istream& is = ifs.stdStream();
// Read the STL header
char header[headerSize];
is.read(header, headerSize);
// Check that stream is OK, if not this may be an ASCII file
if (!is.good())
{
return false;
}
// Read the number of triangles in the STl file
// (note: read as int so we can check whether >2^31)
int nTris;
is.read(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
// Check that stream is OK and number of triangles is positive,
// if not this maybe an ASCII file
//
// Also compare the file size with that expected from the number of tris
// If the comparison is not sensible then it may be an ASCII file
if
(
!is
|| nTris < 0
|| nTris < (fileSize - headerSize)/50
|| nTris > (fileSize - headerSize)/25
)
{
return false;
}
// looks like it might be BINARY
return true;
}
#undef DEBUG_STLBINARY
bool Foam::fileFormats::STLfileFormat::readBINARY
(
IFstream& ifs,
const off_t fileSize
)
{
istream& is = ifs.stdStream();
// Read the STL header
char header[headerSize];
is.read(header, headerSize);
// Check that stream is OK, if not this may be an ASCII file
if (!is.good())
{
FatalErrorIn("fileFormats::STLfileFormat::readBINARY(Istream&)")
<< "problem reading header, perhaps file is not binary "
<< exit(FatalError);
}
// Read the number of triangles in the STl file
// (note: read as int so we can check whether >2^31)
int nTris;
is.read(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
// Check that stream is OK and number of triangles is positive,
// if not this maybe an ASCII file
//
// Also compare the file size with that expected from the number of tris
// If the comparison is not sensible then it may be an ASCII file
if
(
!is
|| nTris < 0
|| nTris < (fileSize - headerSize)/50
|| nTris > (fileSize - headerSize)/25
)
{
FatalErrorIn("fileFormats::STLfileFormat::readBINARY(Istream&)")
<< "problem reading number of triangles, perhaps file is not binary"
<< exit(FatalError);
}
#ifdef DEBUG_STLBINARY
Info<< "# " << nTris << " facets" << endl;
label prevRegion = -1;
#endif
pointField pointLst(3*nTris);
List<keyedFace> faceLst(nTris);
label maxRegionId = 0;
label pointI = 0;
forAll(faceLst, faceI)
{
// Read an STL triangle
STLtriangle stlTri(is);
// Set the rawPoints to the vertices of the STL triangle
// and set the point labels of the face
face f(3);
pointLst[pointI] = stlTri.a();
f[0] = pointI++;
pointLst[pointI] = stlTri.b();
f[1] = pointI++;
pointLst[pointI] = stlTri.c();
f[2] = pointI++;
if (maxRegionId < stlTri.region())
{
maxRegionId = stlTri.region();
}
// interprete colour as a region
faceLst[faceI] = keyedFace(f, stlTri.region());
#ifdef DEBUG_STLBINARY
if
(
prevRegion != stlTri.region()
)
{
if (prevRegion != -1)
{
Info<< "endsolid region" << prevRegion << nl;
}
prevRegion = stlTri.region();
Info<< "solid region" << prevRegion << nl;
}
Info<< " facet normal " << stlTri.normal() << nl;
Info<< " outer loop" << nl;
Info<< " vertex " << stlTri.a() << nl;
Info<< " vertex " << stlTri.b() << nl;
Info<< " vertex " << stlTri.c() << nl;
Info<< " outer loop" << nl;
Info<< " endfacet" << endl;
#endif
}
#ifdef DEBUG_STLBINARY
Info<< "endsolid region" << prevRegion << nl;
#endif
points().transfer(pointLst);
faces().transfer(faceLst);
setPatches(maxRegionId);
stitchFaces(SMALL);
return true;
}
inline void Foam::fileFormats::STLfileFormat::writeShell
(
Ostream& os,
const pointField& pointLst,
const face& f,
const vector& norm
)
{
// simple triangulation about f[0].
// better triangulation should have been done before
const point& p0 = pointLst[f[0]];
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
{
label fp2 = (fp1 + 1) % f.size();
const point& p1 = pointLst[f[fp1]];
const point& p2 = pointLst[f[fp2]];
// write STL triangle
os << " facet normal "
<< norm.x() << ' ' << norm.y() << ' ' << norm.z() << nl
<< " outer loop\n"
<< " vertex "
<< p0.x() << ' ' << p0.y() << ' ' << p0.z() << nl
<< " vertex "
<< p1.x() << ' ' << p1.y() << ' ' << p1.z() << nl
<< " vertex "
<< p2.x() << ' ' << p2.y() << ' ' << p2.z() << nl
<< " endloop\n"
<< " endfacet" << endl;
}
}
inline void Foam::fileFormats::STLfileFormat::writeShell
(
ostream& os,
const pointField& pointLst,
const face& f,
const vector& norm,
const label patchI
)
{
// simple triangulation about f[0].
// better triangulation should have been done before
const point& p0 = pointLst[f[0]];
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
{
label fp2 = (fp1 + 1) % f.size();
STLtriangle stlTri
(
norm,
p0,
pointLst[f[fp1]],
pointLst[f[fp2]],
patchI
);
stlTri.write(os);
}
}
// write sorted:
void Foam::fileFormats::STLfileFormat::writeASCII
(
Ostream& os,
const keyedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<keyedFace>& faceLst = surf.faces();
const vectorField& normLst = surf.faceNormals();
labelList faceMap;
List<surfacePatch> patchLst = surf.sortedRegions(faceMap);
label faceIndex = 0;
forAll(patchLst, patchI)
{
// Print all faces belonging to this region
const surfacePatch& patch = patchLst[patchI];
os << "solid " << patch.name() << endl;
forAll(patch, patchFaceI)
{
const label faceI = faceMap[faceIndex++];
writeShell(os, pointLst, faceLst[faceI], normLst[faceI]);
}
os << "endsolid " << patch.name() << endl;
}
}
// write sorted:
void Foam::fileFormats::STLfileFormat::writeASCII
(
Ostream& os,
const meshedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<face>& faceLst = surf.faces();
const List<surfacePatch>& patchLst = surf.patches();
const vectorField& normLst = surf.faceNormals();
// force triangulation, but just do the cheapest form possible
label faceIndex = 0;
forAll(patchLst, patchI)
{
// Print all faces belonging to this region
const surfacePatch& patch = patchLst[patchI];
os << "solid " << patch.name() << endl;
forAll(patch, patchFaceI)
{
const label faceI = faceIndex++;
writeShell(os, pointLst, faceLst[faceI], normLst[faceI]);
}
os << "endsolid " << patch.name() << endl;
}
}
// write unsorted:
void Foam::fileFormats::STLfileFormat::writeBINARY
(
ostream& os,
const keyedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<keyedFace>& faceLst = surf.faces();
const vectorField& normLst = surf.faceNormals();
// Write the STL header
string header("STL binary file", headerSize);
// clear possible trailing junk
for (label i = header.size(); i < headerSize; ++i)
{
header[i] = 0;
}
os.write(header.c_str(), headerSize);
// force triangulation, but just do the cheapest form possible
unsigned int nTris = 0;
forAll(faceLst, faceI)
{
nTris += faceLst[faceI].size() - 2;
}
os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
forAll(faceLst, faceI)
{
writeShell
(
os,
pointLst,
faceLst[faceI],
normLst[faceI],
faceLst[faceI].key()
);
}
}
void Foam::fileFormats::STLfileFormat::writeBINARY
(
ostream& os,
const meshedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<face>& faceLst = surf.faces();
const surfacePatchList& patchLst = surf.patches();
const vectorField& normLst = surf.faceNormals();
// Write the STL header
string header("STL binary file", headerSize);
os.write(header.c_str(), headerSize);
// force triangulation, but just do the cheapest form possible
unsigned int nTris = 0;
forAll(faceLst, faceI)
{
nTris += faceLst[faceI].size() - 2;
}
os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
label faceIndex = 0;
forAll(patchLst, patchI)
{
forAll(patchLst[patchI], patchFaceI)
{
writeShell
(
os,
pointLst,
faceLst[faceIndex],
normLst[faceIndex],
patchI
);
++faceIndex;
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::STLfileFormat::STLfileFormat()
:
Foam::keyedSurface()
{}
Foam::fileFormats::STLfileFormat::STLfileFormat
(
const fileName& fName,
const bool
)
:
Foam::keyedSurface()
{
off_t fileSize = Foam::size(fName);
// auto-detect ascii/binary
if (detectBINARY(fName))
{
readBINARY(IFstream(fName, IOstream::BINARY)(), fileSize);
}
else
{
readASCII(IFstream(fName)(), fileSize);
}
}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::STLfileFormat::write
(
Ostream& os,
const keyedSurface& surf
)
{
writeASCII(os, surf);
}
void Foam::fileFormats::STLfileFormat::write
(
Ostream& os,
const meshedSurface& surf
)
{
writeASCII(os, surf);
}
void Foam::fileFormats::STLfileFormat::write
(
const fileName& fName,
const keyedSurface& surf
)
{
const word ext = fName.ext();
// handle 'stlb' as binary directly
if (ext == "stlb")
{
std::ofstream ofs(fName.c_str(), std::ios::binary);
writeBINARY(ofs, surf);
}
else
{
writeASCII(OFstream(fName)(), surf);
}
}
void Foam::fileFormats::STLfileFormat::write
(
const fileName& fName,
const meshedSurface& surf
)
{
const word ext = fName.ext();
// handle 'stlb' as binary directly
if (ext == "stlb")
{
std::ofstream ofs(fName.c_str(), std::ios::binary);
writeBINARY(ofs, surf);
}
else
{
writeASCII(OFstream(fName)(), surf);
}
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,177 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::STLfileFormat
Description
Provide a means of reading/writing STL files (ASCII and binary).
SourceFiles
STLfileFormat.C
STLfileFormatASCII.L
\*---------------------------------------------------------------------------*/
#ifndef STLfileFormat_H
#define STLfileFormat_H
#include "STLtriangle.H"
#include "IFstream.H"
#include "Ostream.H"
#include "OFstream.H"
#include "keyedSurface.H"
#include "meshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class STLfileFormat Declaration
\*---------------------------------------------------------------------------*/
class STLfileFormat
:
public keyedSurface
{
// Private data
//- The number of bytes in the STL binary header
static const int headerSize=80;
// Private Member Functions
//- Disallow default bitwise copy construct
STLfileFormat(const STLfileFormat&);
//- Disallow default bitwise assignment
void operator=(const STLfileFormat&);
bool detectBINARY(const fileName&);
bool readASCII(IFstream&, const off_t);
bool readBINARY(IFstream&, const off_t);
//- write face in ASCII
static inline void writeShell
(
Ostream&,
const pointField&,
const face&,
const vector& norm
);
//- write face in BINARY
static inline void writeShell
(
ostream&,
const pointField&,
const face&,
const vector&,
const label patchI
);
//- Write keySurface
static void writeASCII(Ostream&, const keyedSurface&);
//- Write keyedSurface
static void writeBINARY(ostream&, const keyedSurface&);
//- Write meshedSurface
static void writeASCII(Ostream&, const meshedSurface&);
//- Write meshedSurface
static void writeBINARY(ostream&, const meshedSurface&);
public:
// Constructors
//- Construct null
STLfileFormat();
//- Construct from file name
STLfileFormat(const fileName&, const bool triangulate=true);
// Selectors
//- Read file and return keyedSurface
static autoPtr<keyedSurface> New
(
const fileName& fName,
const bool triangulate=true
)
{
return autoPtr<keyedSurface>
(
new STLfileFormat(fName,triangulate)
);
}
// Destructor
// Member Functions
// Write
//- Write keyedSurface
// The ASCII output is sorted by patch, the binary output is unsorted
static void write(Ostream&, const keyedSurface&);
//- Write keyedSurface
// The ASCII output is sorted by patch, the binary output is unsorted
static void write(const fileName&, const keyedSurface&);
//- Write meshedSurface
static void write(Ostream&, const meshedSurface&);
//- Write meshedSurface
static void write(const fileName&, const meshedSurface&);
//- Write object
virtual void write(Ostream& os) const
{
write(os, *this);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,426 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
%{
#undef yyFlexLexer
/* ------------------------------------------------------------------------ *\
------ local definitions
\* ------------------------------------------------------------------------ */
#include "STLfileFormat.H"
using namespace Foam;
// Dummy yyFlexLexer::yylex() to keep the linker happy. It is not called
//! @cond dummy
int yyFlexLexer::yylex()
{
FatalErrorIn("yyFlexLexer::yylex()")
<< "Should not have called this function"
<< abort(FatalError);
return 0;
}
//! @endcond dummy
// Dummy yywrap to keep yylex happy at compile time.
// It is called by yylex but is not used as the mechanism to change file.
// See <<EOF>>
//! @cond dummy
#if YY_FLEX_SUBMINOR_VERSION < 34
extern "C" int yywrap()
#else
int yyFlexLexer::yywrap()
#endif
{
return 1;
}
//! @endcond dummy
//- A lexer for parsing STL ASCII files.
// Returns DynamicList(s) of points and facets (regionIds).
// Since the facets appear within a solid/endsolid grouping,
// they are always within a region
class STLASCIILexer
:
public yyFlexLexer
{
// Private data
short groupID_; // current region
short maxGroupID_; // max region
label lineNo_;
word startError_;
DynamicList<point> points_;
DynamicList<label> facets_;
HashTable<label> groupToPatch_;
public:
// Constructors
//- From input stream and the approximate number of vertices in the STL
STLASCIILexer(istream* is, const label approxNpoints);
// Member Functions
//- The lexer function itself
int lex();
// Access
//- A list of points corresponding to a pointField
DynamicList<point>& points()
{
return points_;
}
//- A list of facet IDs (region IDs)
// corresponds to the number of triangles
DynamicList<label>& facets()
{
return facets_;
}
//- region names
const HashTable<label>& groupToPatch() const
{
return groupToPatch_;
}
};
STLASCIILexer::STLASCIILexer(istream* is, const label approxNpoints)
:
yyFlexLexer(is),
groupID_(-1),
maxGroupID_(-1),
lineNo_(1),
points_(approxNpoints),
facets_(approxNpoints)
{}
/* ------------------------------------------------------------------------ *\
------ cppLexer::yylex()
\* ------------------------------------------------------------------------ */
#define YY_DECL int STLASCIILexer::lex()
%}
one_space [ \t\f\r]
space {one_space}*
some_space {one_space}+
cspace ","{space}
alpha [_A-Za-z]
digit [0-9]
dec_digit [0-9]
octal_digit [0-7]
hex_digit [0-9a-fA-F]
identifier {alpha}({alpha}|{digit})*
integer {dec_digit}+
label [1-9]{dec_digit}*
zeroLabel {digit}*
signedInteger [-+]?{integer}
word ([[:alnum:]]|[[:punct:]])*
string {word}({some_space}{word})*
exponent_part [eE][-+]?{digit}+
fractional_constant [-+]?(({digit}*"."{digit}+)|({digit}+"."?))
double (({fractional_constant}{exponent_part}?)|({digit}+{exponent_part}))
float {double}
x {float}
y {float}
z {float}
solid {space}("solid"|"SOLID"){space}
color {space}("color"|"COLOR"){some_space}{float}{some_space}{float}{some_space}{float}{space}
facet {space}("facet"|"FACET"){space}
normal {space}("normal"|"NORMAL"){space}
point {space}{x}{some_space}{y}{some_space}{z}{space}
outerloop {space}("outer"{some_space}"loop")|("OUTER"{some_space}"LOOP"){space}
vertex {space}("vertex"|"VERTEX"){space}
endloop {space}("endloop"|"ENDLOOP"){space}
endfacet {space}("endfacet"|"ENDFACET"){space}
endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})*
/* ------------------------------------------------------------------------ *\
----- Exclusive start states -----
\* ------------------------------------------------------------------------ */
%option stack
%x readSolidName
%x readFacet
%x readNormal
%x readVertices
%x readVertex
%x stlError
%%
%{
// End of read character pointer returned by strtof
// char* endPtr;
STLpoint normal;
STLpoint vertex;
label cmpt = 0; // component index used for reading vertex
static const char* stateNames[7] =
{
"reading solid",
"reading solid name",
"reading facet",
"reading normal",
"reading vertices",
"reading vertex",
"error"
};
static const char* stateExpects[7] =
{
"'solid', 'color', 'facet' or 'endsolid'",
"<string>",
"'normal', 'outer loop' or 'endfacet'",
"<float> <float> <float>",
"'vertex' or 'endloop'",
"<float> <float> <float>",
""
};
%}
/* ------------------------------------------------------------------------ *\
------ Start Lexing ------
\* ------------------------------------------------------------------------ */
/* ------ Reading control header ------ */
{solid} {
BEGIN(readSolidName);
}
<readSolidName>{string} {
word group(Foam::string::validate<word>(YYText()));
HashTable<label>::const_iterator findGroup =
groupToPatch_.find(group);
if (findGroup != groupToPatch_.end())
{
groupID_ = findGroup();
}
else
{
groupID_ = ++maxGroupID_;
groupToPatch_.insert(group, groupID_);
}
BEGIN(INITIAL);
}
<readSolidName>{space}\n {
word group("solid");
HashTable<label>::const_iterator findGroup =
groupToPatch_.find(group);
if (findGroup != groupToPatch_.end())
{
groupID_ = findGroup();
}
else
{
groupID_ = ++maxGroupID_;
groupToPatch_.insert(group, groupID_);
}
lineNo_++;
BEGIN(INITIAL);
}
{color} {
}
{facet} {
BEGIN(readFacet);
}
<readFacet>{normal} {
BEGIN(readNormal);
}
<readNormal>{point} {
/*
skip reading normals:
normal.x() = strtof(YYText(), &endPtr);
normal.y() = strtof(endPtr, &endPtr);
normal.z() = strtof(endPtr, &endPtr);
normals_.append(normal);
*/
BEGIN(readFacet);
}
<readFacet>{outerloop} {
BEGIN(readVertices);
}
<readVertices>{vertex} {
BEGIN(readVertex);
}
<readVertex>{space}{signedInteger}{space} {
vertex[cmpt++] = atol(YYText());
if (cmpt == 3)
{
cmpt = 0;
points_.append(vertex);
BEGIN(readVertices);
}
}
<readVertex>{space}{float}{space} {
vertex[cmpt++] = atof(YYText());
if (cmpt == 3)
{
cmpt = 0;
points_.append(vertex);
BEGIN(readVertices);
}
}
<readVertices>{endloop} {
BEGIN(readFacet);
}
<readFacet>{endfacet} {
facets_.append(groupID_);
BEGIN(INITIAL);
}
{endsolid} {
}
/* ------------------ Ignore remaining space and \n s. -------------------- */
<*>{space} {}
<*>\n { lineNo_++; }
/* ------------------- Any other characters are errors -------------------- */
<*>. {
startError_ = YYText();
yy_push_state(stlError);
}
/* ---------------------------- Error handler ----------------------------- */
<stlError>.* {
yy_pop_state();
FatalErrorIn
(
"fileFormats::STLfileFormat::readASCII(const fileName& STLfileName)"
) << "while " << stateNames[YY_START] << " on line " << lineNo_ << nl
<< " expected " << stateExpects[YY_START]
<< " but found '" << startError_.c_str() << YYText() << "'"
<< exit(FatalError);
}
/* ------------------------ On EOF terminate ---------------------------- */
<<EOF>> {
yyterminate();
}
%%
//
// member function
//
bool
Foam::fileFormats::STLfileFormat::readASCII
(
IFstream& ifs,
const off_t fileSize
)
{
// Create the lexer with the approximate number of vertices in the STL
// from the file size
STLASCIILexer lexer(&ifs.stdStream(), fileSize/400);
while (lexer.lex() != 0) {}
DynamicList<point>& pointLst = lexer.points();
DynamicList<label>& facetsLst = lexer.facets();
// transfer to normal list
points().transfer(pointLst);
// make our triangles
facetsLst.shrink();
List<keyedFace> faceLst(facetsLst.size());
face fTri(3);
label ptI = 0;
forAll(facetsLst, faceI)
{
fTri[0] = ptI++;
fTri[1] = ptI++;
fTri[2] = ptI++;
faceLst[faceI] = keyedFace(fTri, facetsLst[faceI]);
}
facetsLst.clearStorage();
// transfer to normal list
faces().transfer(faceLst);
setPatches(lexer.groupToPatch());
stitchFaces(SMALL);
return true;
}
/* ------------------------------------------------------------------------ *\
------ End of STLfileFormatASCII.L
\* ------------------------------------------------------------------------ */

View File

@ -0,0 +1,93 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::STLpoint
Description
A vertex point representation for STL files.
SourceFiles
STLpointI.H
\*---------------------------------------------------------------------------*/
#ifndef STLpoint_H
#define STLpoint_H
#include "point.H"
#include "Istream.H"
#include "Ostream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class STLpoint Declaration
\*---------------------------------------------------------------------------*/
class STLpoint
:
public Vector<float>
{
public:
// Constructors
//- Construct null
inline STLpoint();
//- Construct from components
inline STLpoint(float x, float y, float z);
//- Construct from point
inline STLpoint(const point&);
//- Construct from istream
inline STLpoint(Istream&);
// Member Operators
inline operator point() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "STLpointI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,60 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::STLpoint::STLpoint()
{}
inline Foam::STLpoint::STLpoint(float x, float y, float z)
:
Vector<float>(x, y, z)
{}
inline Foam::STLpoint::STLpoint(const point& pt)
:
Vector<float>(float(pt.x()), float(pt.y()), float(pt.z()))
{}
inline Foam::STLpoint::STLpoint(Istream& is)
:
Vector<float>(is)
{}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline Foam::STLpoint::operator point() const
{
return point(x(), y(), z());
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,122 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::STLtriangle
Description
A triangle representation for STL files.
SourceFiles
STLtriangleI.H
\*---------------------------------------------------------------------------*/
#ifndef STLtriangle_H
#define STLtriangle_H
#include "STLpoint.H"
#include "Istream.H"
#include "Ostream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class STLtriangle Declaration
\*---------------------------------------------------------------------------*/
class STLtriangle
{
// Private data
typedef unsigned short STLregion;
STLpoint normal_, a_, b_, c_;
STLregion region_;
public:
// Constructors
//- Construct null
inline STLtriangle();
//- Construct from components
inline STLtriangle
(
const STLpoint& normal,
const STLpoint& a,
const STLpoint& b,
const STLpoint& c,
unsigned short region
);
//- Construct from istream (read binary)
inline STLtriangle(istream&);
// Member Functions
// Access
inline const STLpoint& normal() const;
inline const STLpoint& a() const;
inline const STLpoint& b() const;
inline const STLpoint& c() const;
inline unsigned short region() const;
// Read
//- Read from istream (binary)
inline void read(istream&);
// Write
//- Write to ostream (binary)
inline void write(ostream&);
// Ostream operator
inline friend Ostream& operator<<(Ostream&, const STLtriangle&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "STLtriangleI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,115 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::STLtriangle::STLtriangle()
{}
inline Foam::STLtriangle::STLtriangle
(
const STLpoint& normal,
const STLpoint& a,
const STLpoint& b,
const STLpoint& c,
unsigned short region
)
:
normal_(normal),
a_(a),
b_(b),
c_(c),
region_(region)
{}
inline Foam::STLtriangle::STLtriangle(istream& is)
{
read(is);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::STLpoint& Foam::STLtriangle::normal() const
{
return normal_;
}
inline const Foam::STLpoint& Foam::STLtriangle::a() const
{
return a_;
}
inline const Foam::STLpoint& Foam::STLtriangle::b() const
{
return b_;
}
inline const Foam::STLpoint& Foam::STLtriangle::c() const
{
return c_;
}
inline unsigned short Foam::STLtriangle::region() const
{
return region_;
}
inline void Foam::STLtriangle::read(istream& is)
{
is.read(reinterpret_cast<char*>(this), 4*sizeof(STLpoint));
is.read(reinterpret_cast<char*>(&region_), sizeof(STLregion));
}
inline void Foam::STLtriangle::write(ostream& os)
{
os.write(reinterpret_cast<char*>(this), 4*sizeof(STLpoint));
os.write(reinterpret_cast<char*>(&region_), sizeof(STLregion));
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
inline Foam::Ostream& Foam::operator<<(Ostream& os, const STLtriangle& t)
{
os << t.normal_ << token::SPACE
<< t.a_ << token::SPACE
<< t.b_ << token::SPACE
<< t.c_ << token::SPACE
<< t.region_;
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,287 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "TRIfileFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "IOmanip.H"
#include "IStringStream.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
addNamedToRunTimeSelectionTable
(
keyedSurface,
TRIfileFormat,
fileExtension,
tri
);
addNamedToMemberFunctionSelectionTable
(
keyedSurface,
TRIfileFormat,
write,
fileExtension,
tri
);
addNamedToMemberFunctionSelectionTable
(
meshedSurface,
TRIfileFormat,
write,
fileExtension,
tri
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
inline void Foam::fileFormats::TRIfileFormat::writeShell
(
Ostream& os,
const pointField& pointLst,
const face& f,
const label patchI
)
{
// simple triangulation about f[0].
// better triangulation should have been done before
const point& p0 = pointLst[f[0]];
for (label fp1 = 1; fp1 < f.size() - 1; ++fp1)
{
label fp2 = (fp1 + 1) % f.size();
const point& p1 = pointLst[f[fp1]];
const point& p2 = pointLst[f[fp2]];
os << p0.x() << ' ' << p0.y() << ' ' << p0.z() << ' '
<< p1.x() << ' ' << p1.y() << ' ' << p1.z() << ' '
<< p2.x() << ' ' << p2.y() << ' ' << p2.z() << ' '
// region as colour
<< "0x" << hex << patchI << dec << endl;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::TRIfileFormat::TRIfileFormat()
:
Foam::keyedSurface()
{}
Foam::fileFormats::TRIfileFormat::TRIfileFormat
(
const fileName& fName,
const bool triangulate
)
:
Foam::keyedSurface()
{
IFstream is(fName);
if (!is.good())
{
FatalErrorIn("fileFormats::TRIfileFormat(const fileName&)")
<< "Cannot read file " << fName
<< exit(FatalError);
}
// uses similar structure as STL, just some points
DynamicList<point> pointLst;
DynamicList<label> facetsLst;
HashTable<label> groupToPatch;
// leave faces that didn't have a group in 0
label nUngrouped = 0;
label groupID = 0;
label maxGroupID = -1;
while (is.good())
{
string line = getLineNoComment(is);
// handle continuations ?
// if (line[line.size()-1] == '\\')
// {
// line.substr(0, line.size()-1);
// line += getLineNoComment(is);
// }
IStringStream lineStream(line);
point p
(
readScalar(lineStream),
readScalar(lineStream),
readScalar(lineStream)
);
if (!lineStream) break;
pointLst.append(p);
pointLst.append
(
point
(
readScalar(lineStream),
readScalar(lineStream),
readScalar(lineStream)
)
);
pointLst.append
(
point
(
readScalar(lineStream),
readScalar(lineStream),
readScalar(lineStream)
)
);
// Region/colour in .tri file starts with 0x. Skip.
// ie, instead of having 0xFF, skip 0 and leave xFF to
// get read as a word and name it "patchFF"
char zero;
lineStream >> zero;
word rawName(lineStream);
word groupName("patch" + rawName(1, rawName.size()-1));
HashTable<label>::const_iterator findGroup =
groupToPatch.find(groupName);
if (findGroup != groupToPatch.end())
{
groupID = findGroup();
}
else
{
// special treatment if any initial faces were not in a group
if (maxGroupID == -1 && facetsLst.size())
{
groupToPatch.insert("patch0", 0);
nUngrouped = facetsLst.size();
maxGroupID = 0;
}
groupID = ++maxGroupID;
groupToPatch.insert(groupName, groupID);
}
facetsLst.append(groupID);
}
// transfer to normal list
points().transfer(pointLst);
// make our triangles
facetsLst.shrink();
List<keyedFace> faceLst(facetsLst.size());
face fTri(3);
label ptI = 0;
forAll(facetsLst, faceI)
{
fTri[0] = ptI++;
fTri[1] = ptI++;
fTri[2] = ptI++;
faceLst[faceI] = keyedFace(fTri, facetsLst[faceI]);
}
facetsLst.clearStorage();
faces().transfer(faceLst);
setPatches(groupToPatch);
stitchFaces(SMALL);
}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::TRIfileFormat::write
(
Ostream& os,
const keyedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<keyedFace>& faceLst = surf.faces();
labelList faceMap;
List<surfacePatch> patchLst = surf.sortedRegions(faceMap);
label faceIndex = 0;
forAll(patchLst, patchI)
{
forAll(patchLst[patchI], patchFaceI)
{
const face& f = faceLst[faceMap[faceIndex++]];
writeShell(os, pointLst, f, patchI);
}
}
}
void Foam::fileFormats::TRIfileFormat::write
(
Ostream& os,
const meshedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<face>& faceLst = surf.faces();
const List<surfacePatch>& patchLst = surf.patches();
label faceIndex = 0;
forAll(patchLst, patchI)
{
forAll(patchLst[patchI], patchFaceI)
{
const face& f = faceLst[faceIndex++];
writeShell(os, pointLst, f, patchI);
}
}
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,145 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::TRIfileFormat
Description
Provide a means of reading/writing .tri format.
SourceFiles
TRIfileFormat.C
\*---------------------------------------------------------------------------*/
#ifndef TRIfileFormat_H
#define TRIfileFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "keyedSurface.H"
#include "meshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class TRIfileFormat Declaration
\*---------------------------------------------------------------------------*/
class TRIfileFormat
:
public keyedSurface
{
// Private Member Functions
//- Disallow default bitwise copy construct
TRIfileFormat(const TRIfileFormat&);
//- Disallow default bitwise assignment
void operator=(const TRIfileFormat&);
static inline void writeShell
(
Ostream&,
const pointField&,
const face&,
const label patchI
);
public:
// Constructors
//- Construct null
TRIfileFormat();
//- Construct from file name
TRIfileFormat(const fileName&, const bool triangulate=true);
// Selectors
//- Read file and return keyedSurface
static autoPtr<keyedSurface> New
(
const fileName& fName,
const bool triangulate=true
)
{
return autoPtr<keyedSurface>
(
new TRIfileFormat(fName, triangulate)
);
}
// Destructor
// Member Functions
// Write
//- Write keyedSurface
static void write(Ostream&, const keyedSurface&);
//- Write keyedSurface
static void write(const fileName& fName, const keyedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write meshedSurface
static void write(Ostream&, const meshedSurface&);
//- Write meshedSurface
static void write(const fileName& fName, const meshedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
{
write(os, *this);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,233 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "VTKfileFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
addNamedToMemberFunctionSelectionTable
(
keyedSurface,
VTKfileFormat,
write,
fileExtension,
vtk
);
addNamedToMemberFunctionSelectionTable
(
meshedSurface,
VTKfileFormat,
write,
fileExtension,
vtk
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fileFormats::VTKfileFormat::writeHead
(
Ostream& os,
const pointField& pointLst
)
{
// Write header
os << "# vtk DataFile Version 2.0" << nl
<< "surface written " << clock::dateTime().c_str() << nl
<< "ASCII" << nl
<< nl
<< "DATASET POLYDATA" << nl;
// Write vertex coords
os << "POINTS " << pointLst.size() << " float" << nl;
forAll(pointLst, ptI)
{
os << pointLst[ptI].x() << ' '
<< pointLst[ptI].y() << ' '
<< pointLst[ptI].z() << nl;
}
}
void Foam::fileFormats::VTKfileFormat::writeTail
(
Ostream& os,
const List<surfacePatch>& patchLst
)
{
label nFaces = 0;
forAll(patchLst, patchI)
{
nFaces += patchLst[patchI].size();
}
// Print region numbers
os << nl
<< "CELL_DATA " << nFaces << nl
<< "FIELD attributes 1" << nl
<< "region 1 " << nFaces << " float" << nl;
forAll(patchLst, patchI)
{
forAll(patchLst[patchI], patchFaceI)
{
if (patchFaceI)
{
if ((patchFaceI % 20) == 0)
{
os << nl;
}
else
{
os << ' ';
}
}
os << patchI + 1;
}
os << nl;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::VTKfileFormat::VTKfileFormat()
:
Foam::keyedSurface()
{}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::VTKfileFormat::write
(
Ostream& os,
const keyedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<keyedFace>& faceLst = surf.faces();
labelList faceMap;
List<surfacePatch> patchLst = surf.sortedRegions(faceMap);
writeHead(os, pointLst);
label nNodes = 0;
forAll(faceLst, faceI)
{
nNodes += faceLst[faceI].size();
}
os << nl
<< "POLYGONS " << faceLst.size() << ' '
<< faceLst.size() + nNodes << nl;
label faceIndex = 0;
forAll(patchLst, patchI)
{
forAll(patchLst[patchI], patchFaceI)
{
const face& f = faceLst[faceMap[faceIndex++]];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << nl;
}
}
// Print region numbers
writeTail(os, patchLst);
}
void Foam::fileFormats::VTKfileFormat::write
(
Ostream& os,
const meshedSurface& surf
)
{
const pointField& pointLst = surf.points();
const List<face>& faceLst = surf.faces();
const List<surfacePatch>& patchLst = surf.patches();
writeHead(os, pointLst);
label nNodes = 0;
forAll(faceLst, faceI)
{
nNodes += faceLst[faceI].size();
}
os << nl
<< "POLYGONS " << faceLst.size() << ' '
<< faceLst.size() + nNodes << nl;
label faceIndex = 0;
forAll(patchLst, patchI)
{
forAll(patchLst[patchI], patchFaceI)
{
const face& f = faceLst[faceIndex++];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << nl;
}
}
// Print region numbers
writeTail(os, patchLst);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,124 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::VTKfileFormat
Description
Provide a means of writing VTK legacy format.
SourceFiles
VTKfileFormat.C
\*---------------------------------------------------------------------------*/
#ifndef VTKfileFormat_H
#define VTKfileFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "keyedSurface.H"
#include "meshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class VTKfileFormat Declaration
\*---------------------------------------------------------------------------*/
class VTKfileFormat
:
public keyedSurface
{
// Private Member Functions
//- Disallow default bitwise copy construct
VTKfileFormat(const VTKfileFormat&);
//- Disallow default bitwise assignment
void operator=(const VTKfileFormat&);
static void writeHead(Ostream&, const pointField&);
static void writeTail(Ostream&, const List<surfacePatch>&);
public:
// Constructors
//- Construct null
VTKfileFormat();
// Selectors
// Destructor
// Member Functions
// Write
//- Write keyedSurface
static void write(Ostream&, const keyedSurface&);
//- Write keyedSurface
static void write(const fileName& fName, const keyedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write meshedSurface
static void write(Ostream&, const meshedSurface&);
//- Write meshedSurface
static void write(const fileName& fName, const meshedSurface& surf)
{
write(OFstream(fName)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
{
write(os, *this);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,461 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::keyedSurface
Description
A surface geometry mesh, in which the patch information is conveyed by
the 'key' attached to each face.
This form of surface description is particularly useful for reading in
surface meshes from third-party formats (eg, obj, stl, gts, etc.). It
can also be particularly useful for situations in which the surface
many be adjusted in an arbitrary manner without worrying about needed
to adjust the patch information (eg, surface refinement).
See Also
The Foam::meshedSurface - which is organized as a surface mesh, but
with independent patch information.
SourceFiles
keyedSurface.C
\*---------------------------------------------------------------------------*/
#ifndef keyedSurface_H
#define keyedSurface_H
#include "pointField.H"
#include "PrimitivePatchExtra.H"
#include "boolList.H"
#include "geometricSurfacePatchList.H"
#include "surfacePatchList.H"
#include "face.H"
#include "Keyed.H"
#include "xfer.H"
#include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class Time;
class IFstream;
class meshedSurface;
class polyBoundaryMesh;
/*---------------------------------------------------------------------------*\
Class keyedSurface Declaration
\*---------------------------------------------------------------------------*/
class keyedSurface
:
public PrimitivePatchExtra<Keyed<face>, ::Foam::List, pointField, point>
{
friend class meshedSurface;
protected:
// Protected Member Data
//- Typedef if this type has not already been defined
typedef Keyed<face> keyedFace;
//- Typedef for similar code in keyedSurface and meshedSurface
typedef keyedFace FaceType;
private:
// Private Member Data
// Private typedefs
typedef PrimitivePatchExtra
<
FaceType,
::Foam::List,
pointField,
point
>
MeshStorage;
// Private data
//- Patch information (face ordering nFaces/startFace only used
// during reading and writing)
geometricSurfacePatchList geoPatches_;
// Private member functions
//- Read in Foam format
bool read(Istream&);
//- Generic read routine. Chooses reader based on extension.
//? bool read(const fileName&, const word& ext);
protected:
// Static protected functions
//- Read non-comment line
static string getLineNoComment(IFstream&);
// Protected Member functions
//- Sets default patch names based on the maximum patch number
void setPatches(const label maxPatch);
//- Finds maximum patch number and sets default patch names
void setPatches();
//- Sets patch names from hashed values (id -> name)
void setPatches
(
const Map<word>& regionNames,
const label maxPatch = -1
);
//- Sets patch names from hashed values (name -> id)
void setPatches(const HashTable<label>& groupToPatch);
//- Join the faces by removing duplicate points.
// Returns true if any points merged
bool stitchFaces(const scalar tol=SMALL, const bool verbose=false);
//- Return non-const access to global points
pointField& points()
{
return const_cast<pointField&>(MeshStorage::points());
}
//- Return non-const access to the faces
List<FaceType>& faces()
{
return static_cast<List<FaceType> &>(*this);
}
public:
//- Runtime type information
ClassName("keyedSurface");
//- Return the default geometric patch type (usually "empty")
static word defaultGeometricType;
// Static
//- Name of keyedSurface directory to use.
static fileName triSurfInstance(const Time&);
//- Name of keyedSurface directory to use.
static fileName triSurfName(const Time&);
// Constructors
//- Construct null
keyedSurface();
//- Construct from components (points, labelled faces, patches).
keyedSurface
(
const pointField&,
const List<keyedFace>&,
const geometricSurfacePatchList&
);
//- Construct by transferring components
// (points, labelled faces, patches.
keyedSurface
(
const xfer<pointField>&,
const xfer<List<keyedFace> >&,
const xfer<geometricSurfacePatchList>&
);
//- Construct by transferring points and labelled faces
// With region names per map or set to default.
keyedSurface
(
const xfer<pointField>&,
const xfer<List<keyedFace> >&,
const Map<word>& regionNames = Map<word>::null()
);
//- Construct by transferring points and labelled faces
// with patch-names from hash
keyedSurface
(
const xfer<pointField>&,
const xfer<List<keyedFace> >&,
const HashTable<label>& labelToRegion
);
//- Construct by transferring points, copying unlabelled faces.
// Set single default patch.
keyedSurface
(
const xfer<pointField>&,
const List<face>&
);
//- Construct from a boundary mesh with local points/faces
keyedSurface
(
const polyBoundaryMesh&,
const bool globalPoints=false
);
//- Construct from a meshedSurface
keyedSurface(const meshedSurface&);
//- Construct from file name (uses extension to determine type)
keyedSurface
(
const fileName&,
const bool triangulate=false
);
//- Construct from file name (uses extension to determine type)
keyedSurface
(
const fileName&,
const word&,
const bool triangulate=false
);
//- Construct from Istream
keyedSurface(Istream&);
//- Construct from objectRegistry
keyedSurface(const Time&);
//- Construct as copy
keyedSurface(const keyedSurface&);
//- Construct by transferring the contents from a keyedSurface
keyedSurface(const xfer<keyedSurface>&);
//- Construct by transferring the contents from a meshedSurface
keyedSurface(const xfer<meshedSurface>&);
// Declare run-time constructor selection table
declareRunTimeSelectionTable
(
autoPtr,
keyedSurface,
fileExtension,
(
const fileName& fName,
const bool triangulate
),
(fName, triangulate)
);
// Selectors
//- Select constructed from filename (implicit extension)
static autoPtr<keyedSurface> New
(
const fileName& fName,
const bool triangulate=false
);
//- Select constructed from filename (explicit extension)
static autoPtr<keyedSurface> New
(
const fileName& fName,
const word& ext,
const bool triangulate=false
);
// Destructor
~keyedSurface();
// Member Function Selectors
declareMemberFunctionSelectionTable
(
void,
keyedSurface,
write,
fileExtension,
(
const fileName& fName,
const keyedSurface& surf
),
(fName, surf)
);
//- Write to file
static void write(const fileName&, const keyedSurface&);
//- Can we read this file format?
static bool canRead(const word& ext, const bool verbose=false);
//- Can we write this file format?
static bool canWrite(const word& ext, const bool verbose=false);
// Member Functions
// Access
//- Return the number of points
label nPoints() const
{
return points().size();
}
//- Return the number of faces
label nFaces() const
{
return faces().size();
}
//- The surface size is the number of faces
label size() const
{
return nFaces();
}
//- Return const access to global points
const pointField& points() const
{
return MeshStorage::points();
}
//- Return const access to the faces
const List<FaceType>& faces() const
{
return static_cast<const List<FaceType> &>(*this);
}
const geometricSurfacePatchList& geoPatches() const
{
return geoPatches_;
}
geometricSurfacePatchList& geoPatches()
{
return geoPatches_;
}
//- Determine the sort order from the face regions.
// Returns patch list and sets faceMap to index within faceLst
static surfacePatchList sortedRegions
(
const List<keyedFace>& faceLst,
const Map<word>& patchNames,
labelList& faceMap
);
//- Determine the sort order from the region list.
// Returns patch list and sets faceMap to indices within faceLst
static surfacePatchList sortedRegions
(
const List<label>& regionLst,
const Map<word>& patchNames,
labelList& faceMap
);
//- Sort faces according to region.
// Returns patch list and sets faceMap to index within faces()
surfacePatchList sortedRegions(labelList& faceMap) const;
// Edit
//- Move points
virtual void movePoints(const pointField&);
//- Scale points. A non-positive factor is ignored
virtual void scalePoints(const scalar&);
void checkFaces(const bool verbose);
//- Remove invalid faces
void cleanup(const bool verbose);
//- Return new surface. Returns pointMap, faceMap from
// subsetMeshMap
keyedSurface subsetMesh
(
const boolList& include,
labelList& pointMap,
labelList& faceMap
) const;
//- Transfer the contents of the argument and annull the argument
void transfer(keyedSurface&);
//- Transfer the contents of the argument and annull the argument
void transfer(meshedSurface&);
// Write
//- Write to Ostream in simple FOAM format
virtual void write(Ostream&) const;
//- Generic write routine. Chooses writer based on extension.
virtual void write(const fileName& fName) const
{
write(fName, *this);
}
//- Write to database
void write(const Time&) const;
//- Write some statistics
void writeStats(Ostream&) const;
// Friend Functions
// Member operators
void operator=(const keyedSurface&);
// Ostream Operator
friend Ostream& operator<<(Ostream&, const keyedSurface&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,235 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "keyedSurface.H"
#include "mergePoints.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Remove badly degenerate faces, double faces.
void Foam::keyedSurface::cleanup(const bool verbose)
{
// merge points (already done for STL, TRI)
stitchFaces(SMALL, verbose);
checkFaces(verbose);
checkEdges(verbose);
}
bool Foam::keyedSurface::stitchFaces(const scalar tol, const bool verbose)
{
pointField& pointLst = points();
// Merge points
labelList pointMap(pointLst.size());
pointField newPoints(pointLst.size());
bool hasMerged = mergePoints(pointLst, tol, verbose, pointMap, newPoints);
if (!hasMerged)
{
return false;
}
if (verbose)
{
Info<< "keyedSurface::stitchFaces : Renumbering all faces"
<< endl;
}
// Set the coordinates to the merged ones
pointLst.transfer(newPoints);
List<FaceType>& faceLst = faces();
// Reset the point labels to the unique points array
label newFaceI = 0;
forAll (faceLst, faceI)
{
FaceType& f = faceLst[faceI];
forAll (f, fp)
{
f[fp] = pointMap[f[fp]];
}
if (f.collapse() >= 3)
{
if (newFaceI != faceI)
{
faceLst[newFaceI] = f;
}
newFaceI++;
}
else if (verbose)
{
Pout<< "keyedSurface::stitchFaces : "
<< "Removing collapsed face " << faceI << endl
<< " vertices :" << f << endl;
}
}
if (newFaceI != faceLst.size())
{
if (verbose)
{
Pout<< "keyedSurface::stitchFaces : "
<< "Removed " << faceLst.size() - newFaceI
<< " faces" << endl;
}
faceLst.setSize(newFaceI);
}
// Merging points might have changed geometric factors
clearOut();
return true;
}
// Remove badly degenerate faces and double faces.
void Foam::keyedSurface::checkFaces(const bool verbose)
{
// Simple check on indices ok.
const label maxPointI = points().size() - 1;
List<FaceType>& faceLst = faces();
// Phase 0: detect badly labelled faces
forAll (faceLst, faceI)
{
const FaceType& f = faceLst[faceI];
forAll (f, fp)
{
if (f[fp] < 0 || f[fp] > maxPointI)
{
FatalErrorIn("keyedSurface::checkFaces(bool)")
<< "face " << f
<< " uses point indices outside point range 0.."
<< maxPointI
<< exit(FatalError);
}
}
}
// Two phase process
// 1. mark invalid faces
// 2. pack
// Done to keep numbering constant in phase 1
const labelListList& fFaces = faceFaces();
label newFaceI = 0;
forAll (faceLst, faceI)
{
FaceType& f = faceLst[faceI];
// avoid degenerate faces
if (f.collapse() >= 3)
{
// duplicate face check
bool okay = true;
const labelList& neighbours = fFaces[faceI];
// Check if faceNeighbours use same points as this face.
// Note: discards normal information - sides of baffle are merged.
forAll (neighbours, neighI)
{
if (neighbours[neighI] <= faceI)
{
// lower numbered faces already checked
continue;
}
const face& nei = faceLst[neighbours[neighI]];
if (f == nei)
{
okay = false;
if (verbose)
{
WarningIn
(
"keyedSurface::checkFaces(bool verbose)"
) << "faces share the same vertices:\n"
<< " face 1 :" << faceI << endl;
// printFace(Warning, " ", f, points());
Warning
<< endl
<< " face 2 :"
<< neighbours[neighI] << endl;
// printFace(Warning, " ", nei, points());
}
break;
}
}
if (okay)
{
if (newFaceI != faceI)
{
faceLst[newFaceI] = f;
}
newFaceI++;
}
}
else if (verbose)
{
WarningIn
(
"keyedSurface::checkFaces(bool verbose)"
) << "face " << faceI
<< " does not at least three unique vertices:\n";
// printFace(Warning, " ", f, points());
}
}
if (newFaceI < faceLst.size())
{
if (verbose)
{
WarningIn
(
"keyedSurface::checkFaces(bool verbose)"
) << "Removed " << faceLst.size() - newFaceI
<< " illegal faces." << endl;
}
faceLst.setSize(newFaceI);
// Topology can change because of renumbering
clearOut();
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,95 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "keyedSurface.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::autoPtr<Foam::keyedSurface>
Foam::keyedSurface::New
(
const fileName& fName,
const word& ext,
const bool triangulate
)
{
if (debug)
{
Info<< "keyedSurface::New"
"(const fileName&, const word&, const bool) : "
"constructing keyedSurface"
<< endl;
}
fileExtensionConstructorTable::iterator cstrIter =
fileExtensionConstructorTablePtr_->find(ext);
if (cstrIter == fileExtensionConstructorTablePtr_->end())
{
FatalErrorIn
(
"keyedSurface::New(const fileName&, const word&, const bool) : "
"constructing keyedSurface"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << nl
<< fileExtensionConstructorTablePtr_->toc()
<< exit(FatalError);
}
return autoPtr<keyedSurface>(cstrIter()(fName, triangulate));
}
Foam::autoPtr<Foam::keyedSurface>
Foam::keyedSurface::New
(
const fileName& fName,
const bool triangulate
)
{
const word ext = fName.ext();
if (debug)
{
Info<< "keyedSurface::New(const fileName&, const bool) : "
"constructing keyedSurface"
<< endl;
}
// TODO:
// if (ext == "gz")
// {
// fileName unzipName = fName.lessExt();
//
// return New(unzipName, unzipName.ext(), ext);
// }
return New(fName, ext, triangulate);
}
// ************************************************************************* //

View File

@ -0,0 +1,988 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "meshedSurface.H"
#include "keyedSurface.H"
#include "demandDrivenData.H"
#include "IFstream.H"
#include "OFstream.H"
#include "Time.H"
#include "boundBox.H"
#include "SortableList.H"
#include "ListOps.H"
#include "polyBoundaryMesh.H"
#include "polyMesh.H"
// #include "surfMesh.H"
#include "primitivePatch.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(meshedSurface, 0);
defineMemberFunctionSelectionTable
(
meshedSurface,
write,
fileExtension
);
}
Foam::word Foam::meshedSurface::defaultGeometricType("empty");
// File extension for 'native' raw format
//! @cond localscope
const char * const nativeExt = "ftr";
//! @endcond localscope
// * * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * //
Foam::fileName Foam::meshedSurface::triSurfInstance(const Time& d)
{
fileName foamName(d.caseName() + "." + nativeExt);
// Search back through the time directories list to find the time
// closest to and lower than current time
instantList ts = d.times();
label i;
for (i=ts.size()-1; i>=0; i--)
{
if (ts[i].value() <= d.timeOutputValue())
{
break;
}
}
// Noting that the current directory has already been searched
// for mesh data, start searching from the previously stored time directory
if (i>=0)
{
for (label j=i; j>=0; j--)
{
if (file(d.path()/ts[j].name()/typeName/foamName))
{
if (debug)
{
Pout<< " meshedSurface::triSurfInstance(const Time& d)"
<< "reading " << foamName
<< " from " << ts[j].name()/typeName
<< endl;
}
return ts[j].name();
}
}
}
if (debug)
{
Pout<< " meshedSurface::triSurfInstance(const Time& d)"
<< "reading " << foamName
<< " from constant/" << endl;
}
return "constant";
}
Foam::fileName Foam::meshedSurface::triSurfName(const Time& d)
{
fileName foamName(d.caseName() + "." + nativeExt);
// Search back through the time directories list to find the time
// closest to and lower than current time
instantList ts = d.times();
label i;
for (i=ts.size()-1; i>=0; i--)
{
if (ts[i].value() <= d.timeOutputValue())
{
break;
}
}
// Noting that the current directory has already been searched
// for mesh data, start searching from the previously stored time directory
if (i>=0)
{
for (label j=i; j>=0; j--)
{
fileName testName(d.path()/ts[j].name()/typeName/foamName);
if (file(testName))
{
if (debug)
{
Pout<< " meshedSurface::triSurfName(const Time& d)"
<< "reading " << foamName
<< " from " << ts[j].name()/typeName
<< endl;
}
return testName;
}
}
}
if (debug)
{
Pout<< " meshedSurface::triSurfName(const Time& d)"
<< "reading " << foamName
<< " from constant/" << endl;
}
return d.path()/"constant"/typeName/foamName;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::meshedSurface::onePatch()
{
// set single default patch
patches_.setSize(1);
patches_[0] = surfacePatch
(
defaultGeometricType,
"patch0",
size(), // patch size
0, // patch start
0 // patch index
);
}
void Foam::meshedSurface::checkPatches()
{
// extra safety, ensure we have at some patches,
// and they cover all the faces
// fix start silently
if (patches_.size() > 1)
{
label count = 0;
forAll(patches_, patchI)
{
patches_[patchI].start() = count;
count += patches_[patchI].size();
}
if (count < size())
{
WarningIn
(
"meshedSurface::checkPatches()\n"
)
<< "more nFaces " << size()
<< " than patches " << count
<< " ... extending final patch"
<< endl;
patches_[patches_.size()-1].size() += count - size();
}
else if (count > size())
{
FatalErrorIn
(
"meshedSurface::checkPatches()\n"
)
<< "more patches " << count
<< " than nFaces " << size()
<< exit(FatalError);
}
}
else if (patches_.size() == 1)
{
// like onePatch, but preserve the name
patches_[0].start() = 0;
patches_[0].size() = size();
if (!patches_[0].name().size())
{
patches_[0].name() = "patch0";
}
}
else
{
onePatch();
}
}
// Read triangles, points from Istream
bool Foam::meshedSurface::read(Istream& is)
{
is >> patches_ >> points() >> faces();
return true;
}
#if 0
// Read from file in given format
bool Foam::meshedSurface::read(const fileName& name, const word& ext)
{
if (ext == "gz")
{
fileName unzipName = name.lessExt();
return read(unzipName, unzipName.ext());
}
}
#endif
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::meshedSurface::meshedSurface()
:
MeshStorage(List<FaceType>(), pointField()),
patches_()
{}
Foam::meshedSurface::meshedSurface
(
const pointField& pointLst,
const List<FaceType>& faceLst,
const surfacePatchList& patchLst
)
:
MeshStorage(faceLst, pointLst),
patches_(patchLst)
{}
Foam::meshedSurface::meshedSurface
(
const xfer<pointField>& pointLst,
const xfer<List<FaceType> >& faceLst,
const xfer<surfacePatchList>& patchLst
)
:
MeshStorage(List<FaceType>(), pointField()),
patches_(patchLst)
{
faces().transfer(faceLst());
points().transfer(pointLst());
}
Foam::meshedSurface::meshedSurface
(
const xfer<pointField>& pointLst,
const xfer<List<FaceType> >& faceLst,
const List<label>& patchSizes,
const List<word>& patchNames,
const List<word>& patchTypes
)
:
MeshStorage(List<FaceType>(), pointField()),
patches_()
{
points().transfer(pointLst());
faces().transfer(faceLst());
surfacePatchList newPatches(patchSizes.size());
label start = 0;
forAll(newPatches, patchI)
{
newPatches[patchI] = surfacePatch
(
defaultGeometricType,
patchNames[patchI],
patchSizes[patchI],
start,
patchI
);
start += patchSizes[patchI];
}
patches_.transfer(newPatches);
}
Foam::meshedSurface::meshedSurface
(
const xfer<pointField>& pointLst,
const xfer<List<FaceType> >& faceLst,
const List<label>& regionLst,
const Map<word>& regionNames
)
:
MeshStorage(List<FaceType>(), pointField()),
patches_()
{
points().transfer(pointLst());
faces().transfer(faceLst());
const List<FaceType>& unsortedFaces = faces();
if (regionLst.size() == 0)
{
onePatch();
}
else if (regionLst.size() != unsortedFaces.size())
{
FatalErrorIn
(
"meshedSurface::meshedSurface(\n"
"(\n"
" const pointField&,\n"
" const List<FaceType>&,\n"
" const List<label>& regionLst,\n"
" const Map<word>& regionNames\n"
" )\n"
)
<< "size mismatch : regionLst.size() != faceLst.size()"
<< exit(FatalError);
}
else
{
labelList faceMap;
surfacePatchList newPatches = keyedSurface::sortedRegions
(
regionLst,
regionNames,
faceMap
);
patches_.transfer(newPatches);
// this is somewhat like ListOps reorder and/or IndirectList
List<FaceType> newFaces(unsortedFaces.size());
forAll(newFaces, faceI)
{
newFaces[faceI] = unsortedFaces[faceMap[faceI]];
}
faceMap.clear();
faces().transfer(newFaces);
}
}
Foam::meshedSurface::meshedSurface
(
const xfer<pointField>& pointLst,
const xfer<List<FaceType> >& faceLst
)
:
MeshStorage(List<FaceType>(), pointField()),
patches_()
{
faces().transfer(faceLst());
points().transfer(pointLst());
onePatch();
}
Foam::meshedSurface::meshedSurface
(
const xfer<pointField>& pointLst,
const List<keyedFace>& faceLst,
const Map<word>& regionNames
)
:
MeshStorage(List<FaceType>(), pointField()),
patches_()
{
points().transfer(pointLst());
labelList faceMap;
surfacePatchList newPatches = keyedSurface::sortedRegions
(
faceLst,
regionNames,
faceMap
);
patches_.transfer(newPatches);
// this is somewhat like ListOps reorder and/or IndirectList
List<FaceType> newFaces(faceLst.size());
forAll(newFaces, faceI)
{
newFaces[faceI] = faceLst[faceMap[faceI]];
}
faces().transfer(newFaces);
}
Foam::meshedSurface::meshedSurface
(
const xfer<pointField>& pointLst,
const List<keyedFace>& faceLst,
const HashTable<label>& nameToRegionMapping
)
:
MeshStorage(List<FaceType>(), pointField()),
patches_()
{
points().transfer(pointLst());
Map<word> regionNames;
forAllConstIter(HashTable<label>, nameToRegionMapping, iter)
{
regionNames.insert(iter(), iter.key());
}
labelList faceMap;
surfacePatchList newPatches = keyedSurface::sortedRegions
(
faceLst,
regionNames,
faceMap
);
patches_.transfer(newPatches);
List<FaceType> newFaces(faceLst.size());
// this is somewhat like ListOps reorder and/or IndirectList
forAll(newFaces, faceI)
{
newFaces[faceI] = faceLst[faceMap[faceI]];
}
faces().transfer(newFaces);
}
Foam::meshedSurface::meshedSurface
(
const polyBoundaryMesh& bMesh,
const bool useGlobalPoints
)
:
MeshStorage(List<FaceType>(), pointField()),
patches_()
{
const polyMesh& mesh = bMesh.mesh();
const polyPatchList& bPatches = bMesh;
const label nIntFaces = mesh.nInternalFaces();
// Get patch for all of outside
primitivePatch allBoundary
(
SubList<FaceType>
(
mesh.faces(),
mesh.nFaces() - nIntFaces,
nIntFaces
),
mesh.points()
);
if (useGlobalPoints)
{
// copy in the global points and the global face addressing
points() = mesh.points();
faces() = allBoundary;
}
else
{
// copy in the local points and the local face addressing
points() = allBoundary.localPoints();
faces() = allBoundary.localFaces();
}
// create patch list
surfacePatchList newPatches(bPatches.size());
label startFaceI = 0;
forAll(bPatches, patchI)
{
const polyPatch& p = bPatches[patchI];
newPatches[patchI] = surfacePatch
(
defaultGeometricType,
p.name(),
p.size(),
startFaceI,
patchI
);
startFaceI += p.size();
}
patches_.transfer(newPatches);
}
#if 0
// in preparation
Foam::meshedSurface::meshedSurface
(
const surfMesh& sMesh
)
:
MeshStorage(List<FaceType>(sMesh.faces()), sMesh.points()),
patches_()
{
const surfPatchList& sPatches = sMesh.boundaryMesh();
// create patch list
surfacePatchList newPatches(sPatches.size());
label startFaceI = 0;
forAll(sPatches, patchI)
{
const surfPatch& p = sPatches[patchI];
newPatches[patchI] = surfacePatch
(
defaultGeometricType,
p.name(),
p.size(),
startFaceI,
patchI
);
startFaceI += p.size();
}
patches_.transfer(newPatches);
}
#endif
Foam::meshedSurface::meshedSurface
(
const keyedSurface& surf
)
:
MeshStorage(List<FaceType>(), surf.points()),
patches_()
{
labelList faceMap;
surfacePatchList newPatches = surf.sortedRegions(faceMap);
patches_.transfer(newPatches);
const List<keyedFace>& origFaces = surf.faces();
List<FaceType> newFaces(origFaces.size());
// this is somewhat like ListOps reorder and/or IndirectList
forAll(newFaces, faceI)
{
newFaces[faceI] = origFaces[faceMap[faceI]];
}
faces().transfer(newFaces);
}
Foam::meshedSurface::meshedSurface
(
const fileName& fName,
const word& ext,
const bool triangulate
)
:
MeshStorage(List<FaceType>(), pointField()),
patches_()
{
// use selector mechanism
autoPtr<meshedSurface> surfPtr = New(fName, ext, triangulate);
transfer(surfPtr());
}
Foam::meshedSurface::meshedSurface
(
const fileName& fName,
const bool triangulate
)
:
MeshStorage(List<FaceType>(), pointField()),
patches_()
{
// use selector mechanism
autoPtr<meshedSurface> surfPtr = New(fName, triangulate);
transfer(surfPtr());
}
Foam::meshedSurface::meshedSurface(Istream& is)
:
MeshStorage(List<FaceType>(), pointField()),
patches_()
{
read(is);
// setDefaultPatches();
}
Foam::meshedSurface::meshedSurface(const Time& d)
:
MeshStorage(List<FaceType>(), pointField()),
patches_()
{
read(IFstream(triSurfName(d))());
// setDefaultPatches();
}
Foam::meshedSurface::meshedSurface(const meshedSurface& surf)
:
MeshStorage(surf.faces(), surf.points()),
patches_(surf.patches_)
{}
Foam::meshedSurface::meshedSurface(const xfer<keyedSurface>& surf)
:
MeshStorage(List<FaceType>(), pointField()),
patches_()
{
transfer(surf());
}
Foam::meshedSurface::meshedSurface(const xfer<meshedSurface>& surf)
:
MeshStorage(List<FaceType>(), pointField()),
patches_()
{
transfer(surf());
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::meshedSurface::~meshedSurface()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
//- Move points
void Foam::meshedSurface::movePoints(const pointField& newPoints)
{
// Remove all geometry dependent data
clearTopology();
// Adapt for new point position
MeshStorage::movePoints(newPoints);
// Copy new points
points() = newPoints;
}
//- scale points
void Foam::meshedSurface::scalePoints(const scalar& scaleFactor)
{
// avoid bad scaling
if (scaleFactor > 0 && scaleFactor != 1.0)
{
// Remove all geometry dependent data
clearTopology();
// Adapt for new point position
MeshStorage::movePoints(pointField());
points() *= scaleFactor;
}
}
Foam::meshedSurface Foam::meshedSurface::subsetMesh
(
const boolList& include,
labelList& pointMap,
labelList& faceMap
) const
{
const pointField& locPoints = localPoints();
const List<FaceType>& locFaces = localFaces();
// Fill pointMap, faceMap
subsetMap(include, pointMap, faceMap);
// Create compact coordinate list and forward mapping array
pointField newPoints(pointMap.size());
labelList oldToNew(locPoints.size());
forAll(pointMap, pointI)
{
newPoints[pointI] = locPoints[pointMap[pointI]];
oldToNew[pointMap[pointI]] = pointI;
}
// create a new patch list
surfacePatchList newPatches(patches_);
forAll(newPatches, patchI)
{
newPatches[patchI].size() = 0;
}
// Renumber face node labels and compact
List<FaceType> newFaces(faceMap.size());
forAll(faceMap, faceI)
{
// Get old vertex labels
label origFaceI = faceMap[faceI];
const FaceType& oldFace = locFaces[origFaceI];
newFaces[faceI] = FaceType(oldFace);
// Renumber labels for face
FaceType& f = newFaces[faceI];
forAll(f, fp)
{
f[fp] = oldToNew[oldFace[fp]];
}
// adjust patch sizes
forAllReverse (newPatches, patchI)
{
if
(
origFaceI >= patches_[patchI].start()
&& patches_[patchI].size()
)
{
newPatches[patchI].size()++;
break;
}
}
}
// adjust patch start
label startFaceI = 0;
forAll(newPatches, patchI)
{
newPatches[patchI].start() = startFaceI;
startFaceI += newPatches[patchI].size();
}
// Construct an empty subsurface and fill
meshedSurface subSurf;
subSurf.patches_.transfer(newPatches);
subSurf.points().transfer(newPoints);
subSurf.faces().transfer(newFaces);
return subSurf;
}
void Foam::meshedSurface::transfer(meshedSurface& surf)
{
clearOut();
faces().transfer(surf.faces());
points().transfer(surf.points());
patches_.transfer(surf.patches_);
surf.clearOut();
}
void Foam::meshedSurface::transfer(keyedSurface& surf)
{
clearOut();
points().transfer(surf.points());
labelList faceMap;
surfacePatchList newPatches = surf.sortedRegions(faceMap);
patches_.transfer(newPatches);
const List<keyedFace>& origFaces = surf.faces();
List<FaceType> newFaces(origFaces.size());
// this is somewhat like ListOps reorder and/or IndirectList
forAll(newFaces, faceI)
{
newFaces[faceI] = origFaces[faceMap[faceI]];
}
faces().transfer(newFaces);
surf.faces().clear();
surf.clearOut();
}
bool Foam::meshedSurface::canRead(const word& ext, const bool verbose)
{
return keyedSurface::canRead(ext, verbose);
}
bool Foam::meshedSurface::canWrite(const word& ext, const bool verbose)
{
// perhaps we got sent an entire name
word fExt(ext);
// FIXME: this looks horrible, but I don't have STL docs here
string::size_type dot = ext.find_last_of(".");
if (dot != string::npos)
{
fExt = ext.substr(dot+1);
}
// handle 'native' format directly
if (fExt == nativeExt)
{
return true;
}
writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(fExt);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
if (verbose)
{
const wordList& known =
writefileExtensionMemberFunctionTablePtr_->toc();
Info<<"Unknown file extension for writing: " << fExt << nl;
// compact output:
Info<<"Valid types: ( " << nativeExt;
forAll(known, i)
{
Info<<" " << known[i];
}
Info<<" )" << endl;
}
return false;
}
return true;
}
void Foam::meshedSurface::write
(
const fileName& fName,
const meshedSurface& surf
)
{
if (debug)
{
Info<< "meshedSurface::write(const fileName&, const meshedSurface&) : "
"writing meshedSurface to " << fName
<< endl;
}
const word ext = fName.ext();
// handle 'native' format directly
if (ext == nativeExt)
{
surf.write(OFstream(fName)());
}
else
{
writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(ext);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
FatalErrorIn
(
"meshedSurface::write(const fileName&)"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< writefileExtensionMemberFunctionTablePtr_->toc()
<< exit(FatalError);
}
mfIter()(fName, surf);
}
}
void Foam::meshedSurface::write(Ostream& os) const
{
// quick-hack
os << patches_.size() << nl << token::BEGIN_LIST;
forAll(patches_, patchI)
{
patches_[patchI].writeDict(os);
}
os << token::END_LIST;
// Note: Write with global point numbering
os << points() << nl << faces() << endl;
// Check state of Ostream
os.check("meshedSurface::write(Ostream&)");
}
void Foam::meshedSurface::write(const Time& d) const
{
write(OFstream(triSurfName(d))());
}
void Foam::meshedSurface::writeStats(Ostream& os) const
{
os << "Faces : " << size() << endl
<< "Edges : " << nEdges() << endl
<< "Vertices : " << nPoints() << endl
<< "Bounding Box : " << boundBox(localPoints(), false) << endl;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::meshedSurface::operator=(const meshedSurface& surf)
{
clearOut();
faces() = surf.faces();
points() = surf.points();
patches_ = surf.patches_;
}
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const meshedSurface& surf)
{
surf.write(os);
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,437 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::meshedSurface
Description
A surface geometry mesh with patch information, not to be confused
with a similarily named surfaceMesh, which actually refers to
the cell faces of a volume mesh!
The meshedSurface is intended to surfaces from a variety of sources.
- A set of points and faces without any patch information.
- A set of points and faces with randomly sorted patch information.
This could arise, for example, from reading external file formats
such as STL, etc.
SourceFiles
meshedSurface.C
\*---------------------------------------------------------------------------*/
#ifndef meshedSurface_H
#define meshedSurface_H
#include "pointField.H"
#include "PrimitivePatchExtra.H"
#include "boolList.H"
#include "geometricSurfacePatchList.H"
#include "surfacePatchList.H"
#include "face.H"
#include "Keyed.H"
#include "xfer.H"
#include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class Time;
class keyedSurface;
class polyBoundaryMesh;
class surfMesh;
/*---------------------------------------------------------------------------*\
Class meshedSurface Declaration
\*---------------------------------------------------------------------------*/
class meshedSurface
:
public PrimitivePatchExtra<face, ::Foam::List, pointField, point>
{
friend class keyedSurface;
protected:
// Protected Member Data
//- Typedef if this type has not already been defined
typedef Keyed<face> keyedFace;
//- Typedef for similar code in keyedSurface and meshedSurface
typedef face FaceType;
private:
// Private Member Data
// Private typedefs
typedef PrimitivePatchExtra
<
FaceType,
::Foam::List,
pointField,
point
>
MeshStorage;
// Private data
//- Patch information (face ordering nFaces/startFace only used
// during reading and writing)
surfacePatchList patches_;
// Private member functions
//- set a single patch
void onePatch();
//- basic sanity check on patches
void checkPatches();
//- Read in Foam format
bool read(Istream&);
// Static private functions
public:
// Protected Member Data
// Protected Member functions
//- Return non-const access to global points
pointField& points()
{
return const_cast<pointField&>(MeshStorage::points());
}
//- Return non-const access to the faces
List<FaceType>& faces()
{
return static_cast<List<FaceType> &>(*this);
}
public:
//- Runtime type information
ClassName("meshedSurface");
//- Return the default geometric patch type (usually "empty")
static word defaultGeometricType;
// Static
//- Name of meshedSurface directory to use.
static fileName triSurfInstance(const Time&);
//- Name of meshedSurface directory to use.
static fileName triSurfName(const Time&);
// Constructors
//- Construct null
meshedSurface();
//- Construct from components (points, faces and patches).
meshedSurface
(
const pointField&,
const List<face>&,
const surfacePatchList&
);
//- Construct by transferring components
//- (points, faces and patches).
meshedSurface
(
const xfer<pointField>&,
const xfer<List<face> >&,
const xfer<surfacePatchList>&
);
//- Construct from points, faces, and patch information
meshedSurface
(
const xfer<pointField>&,
const xfer<List<face> >&,
const List<label>& patchSizes,
const List<word>& patchNames,
const List<word>& patchTypes
);
//- Construct from points, faces, a list of (unsorted) region Ids
// and with the names of the regions.
meshedSurface
(
const xfer<pointField>&,
const xfer<List<face> >&,
const List<label>& regionIds,
const Map<word>& regionNames
);
//- Construct by transferring points, faces
// with a single default patch
meshedSurface
(
const xfer<pointField>&,
const xfer<List<face> >&
);
//- Construct by transferring points and copying labelled faces
// With region names per map or set to default.
meshedSurface
(
const xfer<pointField>&,
const List<keyedFace>&,
const Map<word>& regionNames
);
//- Construct by transferring points and labelled faces
//- with patch-names from hash
meshedSurface
(
const xfer<pointField>&,
const List<keyedFace>&,
const HashTable<label>& nameToRegionMapping
);
//- Construct from a boundary mesh with local points/faces
meshedSurface
(
const polyBoundaryMesh&,
const bool globalPoints=false
);
//- Construct from a keyedSurface
meshedSurface(const keyedSurface&);
//- Construct from a surfMesh
meshedSurface(const surfMesh&);
//- Construct by transferring the contents from a keyedSurface
meshedSurface(const xfer<keyedSurface>&);
//- Construct by transferring the contents from a meshedSurface
meshedSurface(const xfer<meshedSurface>&);
//- Construct from file name (uses extension to determine type)
meshedSurface
(
const fileName&,
const bool triangulate=false
);
//- Construct from file name (uses extension to determine type)
meshedSurface
(
const fileName&,
const word&,
const bool triangulate=false
);
//- Construct from Istream
meshedSurface(Istream&);
//- Construct from objectRegistry
meshedSurface(const Time&);
//- Construct as copy
meshedSurface(const meshedSurface&);
// Selectors
//- Select constructed from filename (implicit extension)
static autoPtr<meshedSurface> New
(
const fileName&,
const bool triangulate=false
);
//- Select constructed from filename (explicit extension)
static autoPtr<meshedSurface> New
(
const fileName&,
const word&,
const bool triangulate=false
);
// Destructor
~meshedSurface();
// Member Function Selectors
declareMemberFunctionSelectionTable
(
void,
meshedSurface,
write,
fileExtension,
(
const fileName& fName,
const meshedSurface& surf
),
(fName, surf)
);
//- Write to file
static void write(const fileName&, const meshedSurface&);
//- Can we read this file format?
static bool canRead(const word& ext, const bool verbose=false);
//- Can we write this file format?
static bool canWrite(const word& ext, const bool verbose=false);
// Member Functions
// Access
//- Return the number of points
label nPoints() const
{
return points().size();
}
//- Return the number of faces
label nFaces() const
{
return faces().size();
}
//- The surface size is the number of faces
label size() const
{
return nFaces();
}
//- Return const access to global points
const pointField& points() const
{
return MeshStorage::points();
}
//- Return const access to the faces
const List<FaceType>& faces() const
{
return static_cast<const List<FaceType> &>(*this);
}
const surfacePatchList& patches() const
{
return patches_;
}
surfacePatchList& patches()
{
return patches_;
}
// Edit
//- Move points
virtual void movePoints(const pointField&);
//- Scale points. A non-positive factor is ignored
virtual void scalePoints(const scalar&);
//- Triangulate the surface, return the number of added faces.
// The patch list will be adjusted accordingly.
label triangulate();
//- Join the faces by removing duplicate points.
// Returns true if any points merged
bool stitchFaces(const scalar tol=SMALL, const bool verbose=false);
//- Check/fix duplicate/degenerate faces
void checkFaces(const bool verbose);
//- Remove invalid faces
void cleanup(const bool verbose);
//- Return new surface.
// Returns pointMap, faceMap from subsetMeshMap
meshedSurface subsetMesh
(
const boolList& include,
labelList& pointMap,
labelList& faceMap
) const;
//- Transfer the contents of the argument and annull the argument
void transfer(meshedSurface&);
//- Transfer the contents of the argument and annull the argument
void transfer(keyedSurface&);
// Write
//- Write to Ostream in simple FOAM format
virtual void write(Ostream&) const;
//- Generic write routine. Chooses writer based on extension.
virtual void write(const fileName& fName) const
{
write(fName, *this);
}
//- Write to database
void write(const Time&) const;
//- Write some statistics
void writeStats(Ostream&) const;
// Member operators
void operator=(const meshedSurface&);
// Ostream Operator
friend Ostream& operator<<(Ostream&, const meshedSurface&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,330 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "meshedSurface.H"
#include "mergePoints.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Remove badly degenerate faces, double faces.
void Foam::meshedSurface::cleanup(const bool verbose)
{
// merge points (already done for STL, TRI)
stitchFaces(SMALL, verbose);
checkFaces(verbose);
checkEdges(verbose);
}
bool Foam::meshedSurface::stitchFaces(const scalar tol, const bool verbose)
{
pointField& pointLst = points();
// Merge points
labelList pointMap(pointLst.size());
pointField newPoints(pointLst.size());
bool hasMerged = mergePoints(pointLst, tol, verbose, pointMap, newPoints);
if (!hasMerged)
{
return false;
}
if (verbose)
{
Info<< "meshedSurface::stitchFaces : Renumbering all faces"
<< endl;
}
// Set the coordinates to the merged ones
pointLst.transfer(newPoints);
List<FaceType>& faceLst = faces();
// ensure we have at some patches, and they cover all the faces
checkPatches();
// Reset the point labels to the unique points array
label oldFaceI = 0;
label newFaceI = 0;
forAll (patches_, patchI)
{
surfacePatch& surfPatch = patches_[patchI];
// adjust patch start
surfPatch.start() = newFaceI;
label patchEnd = oldFaceI + surfPatch.size();
for (; oldFaceI < patchEnd; ++oldFaceI)
{
FaceType& f = faceLst[oldFaceI];
forAll (f, fp)
{
f[fp] = pointMap[f[fp]];
}
if (f.collapse() >= 3)
{
if (newFaceI != oldFaceI)
{
faceLst[newFaceI] = f;
}
newFaceI++;
}
else if (verbose)
{
Pout<< "meshedSurface::stitchFaces : "
<< "Removing collapsed face " << oldFaceI << endl
<< " vertices :" << f << endl;
}
}
// adjust patch size
surfPatch.size() = newFaceI - surfPatch.size();
}
if (newFaceI != faceLst.size())
{
if (verbose)
{
Pout<< "meshedSurface::stitchFaces : "
<< "Removed " << faceLst.size() - newFaceI
<< " faces" << endl;
}
faceLst.setSize(newFaceI);
}
// Merging points might have changed geometric factors
clearOut();
return true;
}
// Remove badly degenerate faces and double faces.
void Foam::meshedSurface::checkFaces(const bool verbose)
{
// Simple check on indices ok.
const label maxPointI = points().size() - 1;
List<FaceType>& faceLst = faces();
// Phase 0: detect badly labelled faces
forAll (faceLst, faceI)
{
const FaceType& f = faceLst[faceI];
forAll (f, fp)
{
if (f[fp] < 0 || f[fp] > maxPointI)
{
FatalErrorIn("meshedSurface::checkFaces(bool)")
<< "face " << f
<< " uses point indices outside point range 0.."
<< maxPointI
<< exit(FatalError);
}
}
}
// ensure we have patches, and they cover all the faces
checkPatches();
// Phase 1: find and skip over invalid faces
// Phase 2: pack
const labelListList& fFaces = faceFaces();
label oldFaceI = 0;
label newFaceI = 0;
forAll (patches_, patchI)
{
surfacePatch& surfPatch = patches_[patchI];
// correct the patch start
surfPatch.start() = newFaceI;
label patchEnd = oldFaceI + surfPatch.size();
for (; oldFaceI < patchEnd; ++oldFaceI)
{
FaceType& f = faceLst[oldFaceI];
// 'degenerate' face check
if (f.collapse() >= 3)
{
// duplicate face check
bool okay = true;
const labelList& neighbours = fFaces[oldFaceI];
// Check if faceNeighbours use same points as this face.
// Note: discards normal information - sides of baffle are merged.
forAll (neighbours, neighI)
{
if (neighbours[neighI] <= oldFaceI)
{
// lower numbered faces already checked
continue;
}
const face& nei = faceLst[neighbours[neighI]];
if (f == nei)
{
okay = false;
if (verbose)
{
WarningIn
(
"meshedSurface::checkFaces(bool verbose)"
) << "faces share the same vertices:\n"
<< " face 1 :" << oldFaceI << endl;
// printFace(Warning, " ", f, points());
Warning
<< endl
<< " face 2 :"
<< neighbours[neighI] << endl;
// printFace(Warning, " ", nei, points());
}
break;
}
}
if (okay)
{
if (newFaceI != oldFaceI)
{
faceLst[newFaceI] = f;
}
newFaceI++;
}
}
else if (verbose)
{
WarningIn
(
"meshedSurface::checkFaces(bool verbose)"
) << "face " << oldFaceI
<< " has fewer than three unique vertices:\n";
// printTriangle(Warning, " ", f, points());
}
}
// adjust patch size
surfPatch.size() = newFaceI - surfPatch.start();
}
if (newFaceI < faceLst.size())
{
if (verbose)
{
WarningIn
(
"meshedSurface::checkFaces(bool verbose)"
) << "Removed " << faceLst.size() - newFaceI
<< " illegal faces." << endl;
}
faceLst.setSize(newFaceI);
// Topology can change because of renumbering
clearOut();
}
}
Foam::label Foam::meshedSurface::triangulate()
{
label nTri = 0;
List<FaceType>& faceLst = faces();
// estimate how may triangles are needed
forAll (faceLst, faceI)
{
nTri += faceLst[faceI].size() - 2;
}
// nothing to do
if (nTri <= faceLst.size())
{
return 0;
}
List<FaceType> newFaces(nTri);
// note the number of *additional* faces
nTri -= faceLst.size();
// Reset the point labels to the unique points array
label oldFaceI = 0;
label newFaceI = 0;
forAll (patches_, patchI)
{
surfacePatch& surfPatch = patches_[patchI];
// adjust patch start
surfPatch.start() = newFaceI;
label patchEnd = oldFaceI + surfPatch.size();
for (; oldFaceI < patchEnd; ++oldFaceI)
{
const FaceType& f = faceLst[oldFaceI];
FaceType fTri(3);
// Do simple face triangulation around f[0].
// we could also use face::triangulation
fTri[0] = f[0];
for (label fp = 1; fp < f.size() - 1; ++fp)
{
label fp1 = (fp + 1) % f.size();
fTri[1] = f[fp];
fTri[2] = f[fp1];
newFaces[newFaceI++] = fTri;
}
}
// adjust patch size
surfPatch.size() = newFaceI - surfPatch.start();
}
faceLst.transfer(newFaces);
return nTri;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

Some files were not shown because too many files have changed in this diff Show More