OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
set_surface_lines.cpp
Go to the documentation of this file.
1//Copyright> OpenRadioss
2//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3//Copyright>
4//Copyright> This program is free software: you can redistribute it and/or modify
5//Copyright> it under the terms of the GNU Affero General Public License as published by
6//Copyright> the Free Software Foundation, either version 3 of the License, or
7//Copyright> (at your option) any later version.
8//Copyright>
9//Copyright> This program is distributed in the hope that it will be useful,
10//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12//Copyright> GNU Affero General Public License for more details.
13//Copyright>
14//Copyright> You should have received a copy of the GNU Affero General Public License
15//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16//Copyright>
17//Copyright>
18//Copyright> Commercial Alternative: Altair Radioss Software
19//Copyright>
20//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21//Copyright> software under a commercial license. Contact Altair to discuss further if the
22//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23#include <iostream>
24#include <iterator>
25#include<tuple> // for tuple
26#include <vector>
27#include <algorithm>
28
29#define _FCALL
30
31#ifdef _WIN64
32#define get_merged_surface_ GET_MERGED_SURFACE
33#define get_merged_lines_ GET_MERGED_LINES
34
35#define union_surface_ UNION_SURFACE
36#define delete_surface_ DELETE_SURFACE
37#define intersect_surface_ INTERSECT_SURFACE
38
39#define union_line_ UNION_LINE
40#define delete_line_ DELETE_LINE
41#define intersect_line_ INTERSECT_LINE
42
43#define surf_remove_duplicates_ SURF_REMOVE_DUPLICATES
44#define line_remove_duplicates_ LINE_REMOVE_DUPLICATES
45
46#endif
47
48using namespace std;
49
50
51/* Tuple surface_memb;
52 1st int : node 1
53 2nd int : node 2
54 3rd int : node 3
55 4th int : node 4
56 5th int : eltype
57 6xt int : elid
58*/
59
60#define STUPL tuple < int,int,int,int,int,int >
61vector < STUPL > surface;
62
63
64/* Tuple line_memb;
65 1st int : node 1
66 2nd int : node 2
67 3rd int : eltype
68 4th int : elid
69*/
70#define LTUPL tuple < int,int,int,int >
71vector < LTUPL > lines;
72
73
74
75
76/* ----------------------------------------------------------------------------
77 STUPL create_surface_member : create a new STUPL with all its members : 4 nodes + eltype + elid
78 ---------------------------------------------------------------------------- */
79STUPL create_surface_member (int n1,int n2,int n3,int n4 , int eltype, int elid){
80 STUPL new_member = make_tuple ( n1,n2,n3,n4,eltype,elid);
81 return new_member;
82}
83
84/* ----------------------------------------------------------------------------
85 STUPL create_line_member : create a new STUPL with all its members : 4 nodes + eltype + elid
86 ---------------------------------------------------------------------------- */
87LTUPL create_line_member (int n1,int n2, int eltype, int elid){
88 LTUPL new_member = make_tuple ( n1,n2,eltype,elid);
89 return new_member;
90}
91
92/* ----------------------------------------------------------------------------
93 comp : compare 2 integers a & b
94 ----------------------------------------------------------------------------
95INPUT
96 a,b : integer
97RESULT
98 0 if a == b
99 1 if a > b
100 -1 if a < b
101 --------------------------------------------------------- */
102int comp (int a,int b)
103{
104 int res;
105 if (a==b) res=0;
106 if (a > b) res=1;
107 if (a < b) res=-1;
108
109 return res;
110}
111
112/* ----------------------------------------------------------------------------
113 tupl_compare : compare 2 surfaces with their Element ID
114 each surface is described with a TUPL containing the values
115 comparison take cares on the surface 4 nodes only
116 ----------------------------------------------------------------------------
117 STUPL lhs : lef had side surface Tuple
118 STUPL rhs : right hnd side surface tuple
119
120 return value : 1 if lhs > rhs
121 0 if lhs = rhs
122 -1 if lhs < rhs
123 --------------------------------------------------------- */
124int tupl_compare( STUPL lhs, STUPL rhs ){
125
126 int res;
127 int a,b;
128
129 a=get<5>(lhs);
130 b=get<5>(rhs);
131
132 res = comp ( a, b);
133 return res;
134}
135
136
137/* ----------------------------------------------------------------------------
138 tupl_compare_surf : compare 2 surfaces with their nodeID + EltID
139 each surface is described with a TUPL containing the values
140 comparison take cares on the surface 4 nodes only
141 ----------------------------------------------------------------------------
142 STUPL lhs : lef had side surface Tuple
143 STUPL rhs : right hnd side surface tuple
144
145 return value : 1 if lhs > rhs
146 0 if lhs = rhs
147 -1 if lhs < rhs
148 --------------------------------------------------------- */
150
151 int res;
152 int a,b;
153
154 a=get<0>(lhs); // first node
155 b=get<0>(rhs);
156
157 res = comp ( a, b);
158 if (res != 0) return res;
159
160 a=get<1>(lhs); // 2nd node
161 b=get<1>(rhs);
162
163 res = comp ( a, b);
164 if (res != 0) return res;
165
166 a=get<2>(lhs); // 3rd node
167 b=get<2>(rhs);
168
169 res = comp ( a, b);
170 if (res != 0) return res;
171
172 a=get<3>(lhs); // 4th node
173 b=get<3>(rhs);
174
175 res = comp ( a, b);
176 if (res != 0) return res;
177
178 a=get<5>(lhs); // eltID
179 b=get<5>(rhs);
180
181 res = comp ( a, b);
182
183 return res;
184}
185
186/* ----------------------------------------------------------------------------
187 tupl_compare : compare 2 lines with their Node + Element ID
188 each surface is described with a TUPL containing the values
189 comparison take cares on the surface 4 nodes only
190 ----------------------------------------------------------------------------
191 STUPL lhs : lef hand side line Tuple
192 STUPL rhs : right hand side line tuple
193
194 return value : 1 if lhs > rhs
195 0 if lhs = rhs
196 -1 if lhs < rhs
197 --------------------------------------------------------- */
198int ltupl_compare( LTUPL lhs, LTUPL rhs ){
199
200 int res;
201 int a,b;
202
203// Compare first node
204 a=get<0>(lhs);
205 b=get<0>(rhs);
206
207 res = comp ( a, b);
208 if (res != 0) return res;
209
210// Compare second node
211 a=get<1>(lhs);
212 b=get<1>(rhs);
213 res = comp ( a, b);
214 if (res != 0) return res;
215
216// Compare element ID
217 a=get<3>(lhs);
218 b=get<3>(rhs);
219 res = comp ( a, b);
220 return res;
221}
222
223/* ----------------------------------------------------------------------------
224 void print_surface() : debug print the merged surface
225 ---------------------------------------------------------------------------- */
227{
228 cout << "Number of members= " << surface.size() << endl;
229 int i=0;
230 for (auto mem = surface.begin(); mem != surface.end(); mem++){
231 STUPL member = *mem;
232 i++;
233 cout << i << " -- nodes : " << get<0>(member) << " , " << get<1>(member) << " , " << get<2>(member) << " , " << get<3>(member) <<
234 " -- eltyp :" << get<4>(member) << " -- elid :" << get<5>(member) << endl;
235 }
236
237}
238
239/* ----------------------------------------------------------------------------
240 void print_surface() : debug print the merged surface
241 ---------------------------------------------------------------------------- */
243{
244 cout << "Number of members= " << lines.size() << endl;
245 int i=0;
246 for (auto mem = lines.begin(); mem != lines.end(); mem++){
247 LTUPL member = *mem;
248 i++;
249 cout << i << " -- nodes : " << get<0>(member) << " , " << get<1>(member) << " -- eltyp :" << get<2>(member) << " -- elid :" << get<3>(member) << endl;
250 }
251
252}
253
254
255/* ----------------------------------------------------------------------------
256 C/Fortran usable
257 ---------------------------------------------------------------------------- */
258extern "C"
259{
260/* ----------------------------------------------------------------------------
261 union_surface : union of 2 surfaces according to their 4 node IDs
262 this is dedicated for Fortran call
263 -> fills a global vector in C++,
264 other routine pass the values back to Fortran
265 ----------------------------------------------------------------------------
266 INPUT
267 s1_nd1 - s1_nd4 : 1st surface - 4 nodes
268 s1_eltyp : 1st surface - element type
269 s1_elid : 1st surface - element ID
270 s1_nmemb : 1st surface - number of surfzce segments.
271
272 s2_nd1 - s2_nd4 : 2nd surface - 4 nodes
273 s2_eltyp : 2nd surface - element type
274 s2_elid : 2nd surface - element ID
275 s2_nmemb : 2nd surface - number of surface segments.
276
277 OUTPUT
278 int * nmember : number of surface segments
279 ----------------------------------------------------------------------------
280*/
281
282void union_surface_(int * s1_nd1, int * s1_nd2, int * s1_nd3, int* s1_nd4,int * s1_eltyp,int * s1_elid,int * s1_nmemb,
283 int * s2_nd1, int * s2_nd2, int * s2_nd3, int* s2_nd4,int * s2_eltyp,int * s2_elid,int * s2_nmemb,
284 int * nmember )
285{
286 bool iterator;
287 int i1, i2;
288
289 iterator = true;
290 i1 = 0;
291 i2 = 0;
292
293 while (iterator == true ){
294 if (i1 == (*s1_nmemb) ) {
295 for (int j=i2; j< *s2_nmemb; j++){
296 STUPL member = create_surface_member (s2_nd1[j],s2_nd2[j],s2_nd3[j],s2_nd4[j],s2_eltyp[j],s2_elid[j] );
297 surface.push_back(member);
298 }
299 * nmember = surface.size();
300 return;
301 }
302
303 if (i2 == (*s2_nmemb) ) {
304 for (int j=i1; j< * s1_nmemb; j++){
305 STUPL member = create_surface_member (s1_nd1[j],s1_nd2[j],s1_nd3[j],s1_nd4[j],s1_eltyp[j],s1_elid[j] );
306 surface.push_back(member);
307 }
308 * nmember = surface.size();
309 return;
310 }
311
312 STUPL member1 = create_surface_member (s1_nd1[i1],s1_nd2[i1],s1_nd3[i1],s1_nd4[i1],s1_eltyp[i1],s1_elid[i1] );
313 STUPL member2 = create_surface_member (s2_nd1[i2],s2_nd2[i2],s2_nd3[i2],s2_nd4[i2],s2_eltyp[i2],s2_elid[i2] );
314
315 int res = tupl_compare_surf( member1, member2 );
316 if (res == 1) { surface.push_back(member2); i2++ ; }
317 else if (res == -1) { surface.push_back(member1); i1++; }
318 else { surface.push_back(member1); i1++; i2++; }
319
320 }
321
322}
323
324
325
326/* ----------------------------------------------------------------------------
327 delete_surface : remove all elements from surface 2 in surface 1
328 this is dedicated for Fortran call
329 -> fills a global vector in C++,
330 other routine pass the values back to Fortran
331 ----------------------------------------------------------------------------
332 INPUT
333 s1_nd1 - s1_nd4 : 1st surface - 4 nodes
334 s1_eltyp : 1st surface - element type
335 s1_elid : 1st surface - element ID
336 s1_nmemb : 1st surface - number of surface segments.
337
338 s2_nd1 - s2_nd4 : 2nd surface - 4 nodes
339 s2_eltyp : 2nd surface - element type
340 s2_elid : 2nd surface - element ID
341 s2_nmemb : 2nd surface - number of surface segments.
342
343 OUTPUT
344 int * nmember : number of surface segments
345 ----------------------------------------------------------------------------
346*/
347
348void delete_surface_(int * s1_nd1, int * s1_nd2, int * s1_nd3, int* s1_nd4,int * s1_eltyp,int * s1_elid,int * s1_nmemb,
349 int * s2_nd1, int * s2_nd2, int * s2_nd3, int* s2_nd4,int * s2_eltyp,int * s2_elid,int * s2_nmemb,
350 int * nmember )
351{
352 bool iterator;
353 int i1, i2;
354
355 iterator = true;
356 i1 = 0;
357 i2 = 0;
358
359 while (iterator == true ){
360
361 if (i1 == (*s1_nmemb) ) { // surface 1 is terminated - terminated
362 * nmember = surface.size();
363 return;
364 }
365
366 if (i2 == (*s2_nmemb) ) { // surface 2 is terminated - terminate with all surface 1 elements
367 for (int j=i1; j< * s1_nmemb; j++){
368 STUPL member = create_surface_member (s1_nd1[j],s1_nd2[j],s1_nd3[j],s1_nd4[j],s1_eltyp[j],s1_elid[j] );
369 surface.push_back(member);
370 }
371 * nmember = surface.size();
372 return;
373 }
374
375 STUPL member1 = create_surface_member (s1_nd1[i1],s1_nd2[i1],s1_nd3[i1],s1_nd4[i1],s1_eltyp[i1],s1_elid[i1] );
376 STUPL member2 = create_surface_member (s2_nd1[i2],s2_nd2[i2],s2_nd3[i2],s2_nd4[i2],s2_eltyp[i2],s2_elid[i2] );
377
378 int res = tupl_compare_surf( member1, member2 );
379 if (res == 1) { i2++ ; }
380 else if (res == -1) { surface.push_back(member1); i1++; }
381 else { i1++; i2++; } // Surfaces are identic - don't keep the surface
382
383 }
384
385}
386
387
388
389/* ----------------------------------------------------------------------------
390 intersect_surface : intersection between surface 1 & surface 2
391 this is dedicated for Fortran call
392 -> fills a global vector in C++,
393 other routine pass the values back to Fortran
394 ----------------------------------------------------------------------------
395 INPUT
396 s1_nd1 - s1_nd4 : 1st surface - 4 nodes
397 s1_eltyp : 1st surface - element type
398 s1_elid : 1st surface - element ID
399 s1_nmemb : 1st surface - number of surface segments.
400
401 s2_nd1 - s2_nd4 : 2nd surface - 4 nodes
402 s2_eltyp : 2nd surface - element type
403 s2_elid : 2nd surface - element ID
404 s2_nmemb : 2nd surface - number of surface segments.
405
406 OUTPUT
407 int * nmember : number of surface segments
408 ----------------------------------------------------------------------------
409*/
410
411void intersect_surface_(int * s1_nd1, int * s1_nd2, int * s1_nd3, int* s1_nd4,int * s1_eltyp,int * s1_elid,int * s1_nmemb,
412 int * s2_nd1, int * s2_nd2, int * s2_nd3, int* s2_nd4,int * s2_eltyp,int * s2_elid,int * s2_nmemb,
413 int * nmember )
414{
415 bool iterator;
416 int i1, i2;
417
418 iterator = true;
419 i1 = 0;
420 i2 = 0;
421
422 while (iterator == true ){
423
424 if (i1 == (*s1_nmemb) ) { // surface 1 is terminated - terminated
425 * nmember = surface.size();
426 return;
427 }
428
429 if (i2 == (*s2_nmemb) ) { // surface 2 is terminated - terminated
430 * nmember = surface.size();
431 return;
432 }
433
434 STUPL member1 = create_surface_member (s1_nd1[i1],s1_nd2[i1],s1_nd3[i1],s1_nd4[i1],s1_eltyp[i1],s1_elid[i1] );
435 STUPL member2 = create_surface_member (s2_nd1[i2],s2_nd2[i2],s2_nd3[i2],s2_nd4[i2],s2_eltyp[i2],s2_elid[i2] );
436
437 int res = tupl_compare_surf( member1, member2 );
438 if (res == 1) { i2++ ; }
439 else if (res == -1) { i1++ ; }
440 else { surface.push_back(member1); i1++; i2++; } // Surfaces are same - keep the surface
441
442 }
443
444}
445
446
447/* ----------------------------------------------------------------------------
448 surf_remove_duplicates : Remove duplicates in sorted lines
449 ----------------------------------------------------------------------------
450 INPUT/OUTPUT
451 s1_nd1 - s1_nd4 : surface - 4 nodes
452 s1_eltyp : surface - element type
453 s1_elid : surface - element ID
454 s1_nmemb : surface - number of surface segments.
455 ----------------------------------------------------------------------------
456*/
457 void surf_remove_duplicates_(int * s1_nd1, int * s1_nd2, int * s1_nd3, int* s1_nd4,int * s1_eltyp,int * s1_elid,int *size,int * new_size)
458{
459 int sz=1 ;
460 int i=1;
461
462 while (i< *size) {
463
464 STUPL member1 = create_surface_member (s1_nd1[i],s1_nd2[i],s1_nd3[i],s1_nd4[i],s1_eltyp[i],s1_elid[i] );
465 STUPL member2 = create_surface_member (s1_nd1[i-1],s1_nd2[i-1],s1_nd3[i-1],s1_nd4[i-1],s1_eltyp[i-1],s1_elid[i-1] );
466 int res = tupl_compare_surf( member1, member2 );
467 if ( res != 0) {
468 s1_nd1[sz] = s1_nd1[i];
469 s1_nd2[sz] = s1_nd2[i];
470 s1_nd3[sz] = s1_nd3[i];
471 s1_nd4[sz] = s1_nd4[i];
472 s1_eltyp[sz] = s1_eltyp[i];
473 s1_elid[sz] = s1_elid[i];
474 sz++;
475 }
476 i++;
477}
478
479 *new_size = sz;
480 return;
481
482}
483
484
485
486/* ----------------------------------------------------------------------------
487 union_line : union of 2 lines according to their 4 node IDs
488 this is dedicated for Fortran call
489 -> fills a global vector in C++,
490 other routine pass the values back to Fortran
491 ----------------------------------------------------------------------------
492 INPUT
493 s1_nd1 - s1_nd2 : 1st surface - 4 nodes
494 s1_eltyp : 1st surface - element type
495 s1_elid : 1st surface - element ID
496 s1_nmemb : 1st surface - number of surfzce segments.
497
498 s2_nd1 - s2_nd2 : 2nd surface - 4 nodes
499 s2_eltyp : 2nd surface - element type
500 s2_elid : 2nd surface - element ID
501 s2_nmemb : 2nd surface - number of surface segments.
502
503 OUTPUT
504 int * nmember : number of surface segments
505 ----------------------------------------------------------------------------
506*/
507void _FCALL union_line_(int * s1_nd1, int * s1_nd2, int * s1_eltyp,int * s1_elid,int * s1_nmemb,
508 int * s2_nd1, int * s2_nd2, int * s2_eltyp,int * s2_elid,int * s2_nmemb,
509 int * nmember )
510{
511 bool iterator;
512 int i1, i2;
513
514 iterator = true;
515 i1 = 0;
516 i2 = 0;
517
518 while (iterator == true ){
519 if (i1 == (*s1_nmemb) ) {
520 for (int j=i2; j< *s2_nmemb; j++){
521 LTUPL member = create_line_member (s2_nd1[j],s2_nd2[j],s2_eltyp[j],s2_elid[j] );
522 lines.push_back(member);
523 }
524 * nmember = lines.size();
525 return;
526 }
527
528 if (i2 == (*s2_nmemb) ) {
529 for (int j=i1; j< * s1_nmemb; j++){
530 LTUPL member = create_line_member (s1_nd1[j],s1_nd2[j],s1_eltyp[j],s1_elid[j] );
531 lines.push_back(member);
532 }
533 * nmember = lines.size();
534 return;
535 }
536
537 LTUPL member1 = create_line_member (s1_nd1[i1],s1_nd2[i1],s1_eltyp[i1],s1_elid[i1] );
538 LTUPL member2 = create_line_member (s2_nd1[i2],s2_nd2[i2],s2_eltyp[i2],s2_elid[i2] );
539
540 int res = ltupl_compare( member1, member2 );
541 if (res == 1) { lines.push_back(member2); i2++ ; }
542 else if (res == -1) { lines.push_back(member1); i1++; }
543 else { lines.push_back(member1); i1++; i2++; }
544
545 }
546
547}
548
549
550/* ----------------------------------------------------------------------------
551 delete_line : delete all elements from Surface 2 in Surface according to their 2 node IDs + ElementID
552 this is dedicated for Fortran call
553 -> fills a global vector in C++,
554 other routine pass the values back to Fortran
555 ----------------------------------------------------------------------------
556 INPUT
557 s1_nd1 - s1_nd2 : 1st line - 2 nodes
558 s1_eltyp : 1st line - element type
559 s1_elid : 1st line - element ID
560 s1_nmemb : 1st line - number of surfzce segments.
561
562 s2_nd1 - s2_nd2 : 2nd line - 2 nodes
563 s2_eltyp : 2nd line - element type
564 s2_elid : 2nd line - element ID
565 s2_nmemb : 2nd line - number of surface segments.
566
567 OUTPUT
568 int * nmember : number of surface segments
569 ----------------------------------------------------------------------------
570*/
571void _FCALL delete_line_(int * s1_nd1, int * s1_nd2, int * s1_eltyp,int * s1_elid,int * s1_nmemb,
572 int * s2_nd1, int * s2_nd2, int * s2_eltyp,int * s2_elid,int * s2_nmemb,
573 int * nmember )
574{
575 bool iterator;
576 int i1, i2;
577
578 iterator = true;
579 i1 = 0;
580 i2 = 0;
581
582 while (iterator == true ){
583 if (i1 == (*s1_nmemb) ) { // surface 1 is terminated - terminated
584 * nmember = lines.size();
585 return;
586 }
587
588 if (i2 == (*s2_nmemb) ) {
589 for (int j=i1; j< * s1_nmemb; j++){
590 LTUPL member = create_line_member (s1_nd1[j],s1_nd2[j],s1_eltyp[j],s1_elid[j] );
591 lines.push_back(member);
592 }
593 * nmember = lines.size();
594 return;
595 }
596
597 LTUPL member1 = create_line_member (s1_nd1[i1],s1_nd2[i1],s1_eltyp[i1],s1_elid[i1] );
598 LTUPL member2 = create_line_member (s2_nd1[i2],s2_nd2[i2],s2_eltyp[i2],s2_elid[i2] );
599
600 int res = ltupl_compare( member1, member2 );
601 if (res == 1) { i2++ ; }
602 else if (res == -1) { lines.push_back(member1); i1++; }
603 else { i1++; i2++; } // lines are same - don't keep the line
604
605 }
606
607}
608
609
610/* ----------------------------------------------------------------------------
611 intersect_line : line intersection between line1 and line2 according to their 2 node IDs + ElementID
612 this is dedicated for Fortran call
613 -> fills a global vector in C++,
614 other routine pass the values back to Fortran
615 ----------------------------------------------------------------------------
616 INPUT
617 s1_nd1 - s1_nd2 : 1st line - 2 nodes
618 s1_eltyp : 1st line - element type
619 s1_elid : 1st line - element ID
620 s1_nmemb : 1st line - number of surfzce segments.
621
622 s2_nd1 - s2_nd2 : 2nd line - 2 nodes
623 s2_eltyp : 2nd line - element type
624 s2_elid : 2nd line - element ID
625 s2_nmemb : 2nd line - number of surface segments.
626
627 OUTPUT
628 int * nmember : number of surface segments
629 ----------------------------------------------------------------------------
630*/
631void _FCALL intersect_line_(int * s1_nd1, int * s1_nd2, int * s1_eltyp,int * s1_elid,int * s1_nmemb,
632 int * s2_nd1, int * s2_nd2, int * s2_eltyp,int * s2_elid,int * s2_nmemb,
633 int * nmember )
634{
635 bool iterator;
636 int i1, i2;
637
638 iterator = true;
639 i1 = 0;
640 i2 = 0;
641
642 while (iterator == true ){
643 if (i1 == (*s1_nmemb) ) {
644 * nmember = lines.size();
645 return;
646 }
647
648 if (i2 == (*s2_nmemb) ) {
649 * nmember = lines.size();
650 return;
651 }
652
653 LTUPL member1 = create_line_member (s1_nd1[i1],s1_nd2[i1],s1_eltyp[i1],s1_elid[i1] );
654 LTUPL member2 = create_line_member (s2_nd1[i2],s2_nd2[i2],s2_eltyp[i2],s2_elid[i2] );
655
656 int res = ltupl_compare( member1, member2 );
657 if (res == 1) { i2++ ; }
658 else if (res == -1) { i1++; }
659 else { lines.push_back(member1); i1++; i2++; } // lines are same - keep member1
660
661 }
662
663}
664
665/* ----------------------------------------------------------------------------
666 surf_remove_duplicates : Remove duplicates in sorted lines
667 ----------------------------------------------------------------------------
668 INPUT/OUTPUT
669 s1_nd1 - s1_nd4 : surface - 4 nodes
670 s1_eltyp : surface - element type
671 s1_elid : surface - element ID
672 s1_nmemb : surface - number of surface segments.
673 ----------------------------------------------------------------------------
674*/
675 void line_remove_duplicates_(int * l1_nd1, int * l1_nd2,int * l1_eltyp,int * l1_elid,int *size,int * new_size)
676{
677 int sz=1 ;
678 int i=1;
679
680 while (i< *size) {
681
682 LTUPL member1 = create_line_member (l1_nd1[i],l1_nd2[i],l1_eltyp[i],l1_elid[i] );
683 LTUPL member2 = create_line_member (l1_nd1[i-1],l1_nd2[i-1],l1_eltyp[i-1],l1_elid[i-1] );
684 int res = ltupl_compare( member1, member2 );
685 if ( res != 0) {
686 l1_nd1[sz] = l1_nd1[i];
687 l1_nd2[sz] = l1_nd2[i];
688 l1_eltyp[sz] = l1_eltyp[i];
689 l1_elid[sz] = l1_elid[i];
690 sz++;
691 }
692 i++;
693}
694 *new_size = sz;
695 return;
696}
697
698
699/* ----------------------------------------------------------------------------
700 get_merged_surface_ : Pass the surface vector in Fortran & deletes the surface.
701 ----------------------------------------------------------------------------
702 OUTPUT
703 s_nd1 - s_nd4 : 1st surface - 2 nodes
704 s_eltyp : 1st surface - element type
705 s_elid : 1st surface - element ID
706 ---------------------------------------------------------------------------- */
707void _FCALL get_merged_surface_ ( int * s_nd1, int * s_nd2, int * s_nd3, int* s_nd4,int * s_eltyp,int * s_elid )
708{
709 int i=0;
710 for (auto mem = surface.begin(); mem != surface.end(); mem++){
711 STUPL member = *mem;
712 s_nd1[i] = get<0>(member);
713 s_nd2[i] = get<1>(member);
714 s_nd3[i] = get<2>(member);
715 s_nd4[i] = get<3>(member);
716 s_eltyp[i] = get<4>(member);
717 s_elid[i] = get<5>(member);
718 i++;
719 }
720 // erase the Surface after get back the results
721 std::vector<STUPL>().swap(surface);
722}
723
724/* ----------------------------------------------------------------------------
725 get_merged_lines_ : Pass the line vector in Fortran & deletes the surface.
726 ----------------------------------------------------------------------------
727 OUTPUT
728 s_nd1 - s_nd2 : 1st surface - 2 nodes
729 s_eltyp : 1st surface - element type
730 s_elid : 1st surface - element ID
731 ---------------------------------------------------------------------------- */
732void _FCALL get_merged_lines_ ( int * s_nd1, int * s_nd2,int * s_eltyp,int * s_elid )
733{
734 int i=0;
735 for (auto mem = lines.begin(); mem != lines.end(); mem++){
736 LTUPL member = *mem;
737 s_nd1[i] = get<0>(member);
738 s_nd2[i] = get<1>(member);
739 s_eltyp[i] = get<2>(member);
740 s_elid[i] = get<3>(member);
741 i++;
742 }
743 // erase the Surface after get back the results
744 std::vector<LTUPL>().swap(lines);
745}
746
747
748/* -----------------------------------------------------------------------------------------------------------
749 EXTERN C END
750 ----------------------------------------------------------------------------------------------------------- */
751}
752
753#ifdef MAIN
754int main()
755{
756 int nmember;
757 int s1_nd1[6]={3,3,4,4,7,7};
758 int s1_nd2[6]={5,5,1,1,8,8};
759 int s1_nd3[6]={4,6,2,4,1,4};
760 int s1_nd4[6]={1,2,1,5,2,5};
761 int s1_eltyp[6]={3,3,3,3,3,3};
762 int s1_elid[6]={1,2,3,4,5,6};
763 int s1_nmemb = 6;
764
765 int s2_nd1[4]={1,3,4,9};
766 int s2_nd2[4]={5,5,8,8};
767 int s2_nd3[4]={4,6,2,7};
768 int s2_nd4[4]={1,2,1,6};
769 int s2_eltyp[4]={3,3,3,3};
770 int s2_elid[4]={9,2,7,8};
771 int s2_nmemb = 4;
772
773 cout << "Union Surface \n";
774 cout << "------------- \n" << "\n";
775
776 union_surface_(s1_nd1, s1_nd2, s1_nd3, s1_nd4, s1_eltyp, s1_elid,&s1_nmemb,
777 s2_nd1, s2_nd2, s2_nd3, s2_nd4, s2_eltyp, s2_elid,&s2_nmemb,
778 &nmember );
779
781
782 int s_nd1[nmember];
783 int s_nd2[nmember];
784 int s_nd3[nmember];
785 int s_nd4[nmember];
786 int s_eltyp[nmember];
787 int s_elid[nmember];
788 get_merged_surface_ ( s_nd1, s_nd2, s_nd3, s_nd4,s_eltyp, s_elid );
789
790
791 cout << "\n\n";
792 cout << "Delete Surface \n";
793 cout << "-------------- \n" << "\n";
794
795 delete_surface_(s1_nd1, s1_nd2, s1_nd3, s1_nd4, s1_eltyp, s1_elid,&s1_nmemb,
796 s2_nd1, s2_nd2, s2_nd3, s2_nd4, s2_eltyp, s2_elid,&s2_nmemb,
797 &nmember );
798
800
801 int sd_nd1[nmember];
802 int sd_nd2[nmember];
803 int sd_nd3[nmember];
804 int sd_nd4[nmember];
805 int sd_eltyp[nmember];
806 int sd_elid[nmember];
807
808 get_merged_surface_ ( sd_nd1, sd_nd2, sd_nd3, sd_nd4,sd_eltyp, sd_elid );
809
810
811 cout << "\n\n";
812 cout << "Intersect Surface \n";
813 cout << "----------------- \n" << "\n";
814
815 intersect_surface_(s1_nd1, s1_nd2, s1_nd3, s1_nd4, s1_eltyp, s1_elid,&s1_nmemb,
816 s2_nd1, s2_nd2, s2_nd3, s2_nd4, s2_eltyp, s2_elid,&s2_nmemb,
817 &nmember );
818
820
821 int si_nd1[nmember];
822 int si_nd2[nmember];
823 int si_nd3[nmember];
824 int si_nd4[nmember];
825 int si_eltyp[nmember];
826 int si_elid[nmember];
827
828 get_merged_surface_ ( si_nd1, si_nd2, si_nd3, si_nd4,si_eltyp, si_elid );
829
830
831 cout << "\n\nLines"<< endl;;
832 cout << "----- \n\n";
833
834
835 int l1_nd1[6]={3,3,4,4,7,7};
836 int l1_nd2[6]={5,6,1,5,1,8};
837 int l1_eltyp[6]={3,3,3,3,3,3};
838 int l1_elid[6]={1,2,3,4,5,6};
839 int l1_nmemb = 6;
840
841 int l2_nd1[4]={1,3,4,9};
842 int l2_nd2[4]={5,6,8,8};
843 int l2_eltyp[4]={3,3,3,3};
844 int l2_elid[4]={9,2,7,8};
845 int l2_nmemb = 4;
846
847 cout << "Union Line \n";
848 cout << "---------- \n" << "\n";
849
850 union_line_(l1_nd1, l1_nd2, l1_eltyp, l1_elid, &l1_nmemb,
851 l2_nd1, l2_nd2, l2_eltyp, l2_elid, &l2_nmemb,
852 &nmember );
853
854 print_line();
855
856 int lu_nd1[nmember];
857 int lu_nd2[nmember];
858 int lu_eltyp[nmember];
859 int lu_elid[nmember];
860
861 get_merged_lines_ ( lu_nd1, lu_nd2,lu_eltyp, lu_elid );
862
863 cout << "\nDelete Line \n";
864 cout << "------------- \n" << "\n";
865
866 delete_line_(l1_nd1, l1_nd2, l1_eltyp, l1_elid, &l1_nmemb,
867 l2_nd1, l2_nd2, l2_eltyp, l2_elid, &l2_nmemb,
868 &nmember );
869
870 print_line();
871
872 int ld_nd1[nmember];
873 int ld_nd2[nmember];
874 int ld_eltyp[nmember];
875 int ld_elid[nmember];
876
877 get_merged_lines_ ( ld_nd1, ld_nd2,ld_eltyp, ld_elid );
878 get_merged_lines_ ( lu_nd1, lu_nd2,lu_eltyp, lu_elid );
879
880
881 cout << "\nIntsersect Line \n";
882 cout << "---------------- \n" << "\n";
883
884 intersect_line_(l1_nd1, l1_nd2, l1_eltyp, l1_elid, &l1_nmemb,
885 l2_nd1, l2_nd2, l2_eltyp, l2_elid, &l2_nmemb,
886 &nmember );
887
888 print_line();
889
890 int li_nd1[nmember];
891 int li_nd2[nmember];
892 int li_eltyp[nmember];
893 int li_elid[nmember];
894
895 get_merged_lines_ ( li_nd1, li_nd2,li_eltyp, li_elid );
896
897 cout << "\n\n";
898
899 int ns;
900 int l5_nd1[7]={3,3,4,4,4,7,7};
901 int l5_nd2[7]={5,6,1,1,5,1,8};
902 int l5_eltyp[7]={3,3,3,3,3,3,3};
903 int l5_elid[7]={1,2,3,3,4,5,6};
904 int l5_nmemb = 7;
905 line_remove_duplicates_(l5_nd1, l5_nd2,l5_eltyp,l5_elid,&l5_nmemb,&ns);
906
907 cout << "New Size :" << ns << "\n";
908 for (int i=0;i<ns;i++){
909 cout << i << " - " << l5_nd1[i] << " " << l5_nd2[i]<< " " << l5_eltyp[i]<< " " << l5_elid[i] << "\n";
910 }
911 return 0;
912}
913
914#endif
915
int main()
#define _FCALL
void _FCALL intersect_line_(int *s1_nd1, int *s1_nd2, int *s1_eltyp, int *s1_elid, int *s1_nmemb, int *s2_nd1, int *s2_nd2, int *s2_eltyp, int *s2_elid, int *s2_nmemb, int *nmember)
void print_surface()
void _FCALL union_line_(int *s1_nd1, int *s1_nd2, int *s1_eltyp, int *s1_elid, int *s1_nmemb, int *s2_nd1, int *s2_nd2, int *s2_eltyp, int *s2_elid, int *s2_nmemb, int *nmember)
void intersect_surface_(int *s1_nd1, int *s1_nd2, int *s1_nd3, int *s1_nd4, int *s1_eltyp, int *s1_elid, int *s1_nmemb, int *s2_nd1, int *s2_nd2, int *s2_nd3, int *s2_nd4, int *s2_eltyp, int *s2_elid, int *s2_nmemb, int *nmember)
void _FCALL get_merged_surface_(int *s_nd1, int *s_nd2, int *s_nd3, int *s_nd4, int *s_eltyp, int *s_elid)
int tupl_compare(STUPL lhs, STUPL rhs)
void surf_remove_duplicates_(int *s1_nd1, int *s1_nd2, int *s1_nd3, int *s1_nd4, int *s1_eltyp, int *s1_elid, int *size, int *new_size)
vector< LTUPL > lines
void _FCALL delete_line_(int *s1_nd1, int *s1_nd2, int *s1_eltyp, int *s1_elid, int *s1_nmemb, int *s2_nd1, int *s2_nd2, int *s2_eltyp, int *s2_elid, int *s2_nmemb, int *nmember)
void union_surface_(int *s1_nd1, int *s1_nd2, int *s1_nd3, int *s1_nd4, int *s1_eltyp, int *s1_elid, int *s1_nmemb, int *s2_nd1, int *s2_nd2, int *s2_nd3, int *s2_nd4, int *s2_eltyp, int *s2_elid, int *s2_nmemb, int *nmember)
STUPL create_surface_member(int n1, int n2, int n3, int n4, int eltype, int elid)
vector< STUPL > surface
int tupl_compare_surf(STUPL lhs, STUPL rhs)
#define STUPL
void _FCALL get_merged_lines_(int *s_nd1, int *s_nd2, int *s_eltyp, int *s_elid)
LTUPL create_line_member(int n1, int n2, int eltype, int elid)
#define LTUPL
void delete_surface_(int *s1_nd1, int *s1_nd2, int *s1_nd3, int *s1_nd4, int *s1_eltyp, int *s1_elid, int *s1_nmemb, int *s2_nd1, int *s2_nd2, int *s2_nd3, int *s2_nd4, int *s2_eltyp, int *s2_elid, int *s2_nmemb, int *nmember)
int ltupl_compare(LTUPL lhs, LTUPL rhs)
int comp(int a, int b)
void line_remove_duplicates_(int *l1_nd1, int *l1_nd2, int *l1_eltyp, int *l1_elid, int *size, int *new_size)
void print_line()