OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
Connectivity.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 <vector>
25#include <algorithm>
26
27#define _FCALL
28
29using namespace std;
30
31struct tab3_t {
32 int n1, n2, n3;
33};
34
35struct edge_t {
36 edge_t(const int& nn1, const int& nn2, const int& eelem) {
37 n1 = nn1;
38 n2 = nn2;
39 elem_list.push_back(eelem);
40 nb_con = 0;
41 }
42 int n1, n2;
43 vector<int> elem_list;
44 int nb_con;
45};
46
47typedef vector<edge_t> edge_list_t;
48typedef vector<int> tab1_t;
49
50extern "C"
51{
52 void edge_sort_(edge_list_t**, int*, int*, int*, int*);
54 void edge_get_connect_(edge_list_t**, int*);
56 void tab1_init_(tab1_t**);
57 void tab1_append_(tab1_t**, int*);
58 void tab1_append_tab_(tab1_t**, int*, int*);
59 void tab1_get_size_(tab1_t**, int*);
60 void tab1_get_(tab1_t**, int*);
62 void _FCALL EDGE_SORT(edge_list_t** edge_ptr, int* n1, int* n2, int* elem, int* nedge) {
63 edge_sort_(edge_ptr, n1, n2, elem, nedge);
64 }
65 void _FCALL EDGE_GET_NB_CONNECT(edge_list_t** edge_ptr, int* nb_conn) {
66 edge_get_nb_connect_(edge_ptr, nb_conn);
67 }
68 void _FCALL EDGE_GET_CONNECT(edge_list_t** edge_ptr, int* elem) {
69 edge_get_connect_(edge_ptr, elem);
70 }
72 edge_free_memory_(edge_ptr);
73 }
74 void _FCALL TAB1_INIT(tab1_t** tab1_ptr) {
75 tab1_init_(tab1_ptr);
76 }
77 void _FCALL TAB1_APPEND(tab1_t** tab1_ptr, int* ii) {
78 tab1_append_(tab1_ptr, ii);
79 }
80 void _FCALL TAB1_APPEND_TAB(tab1_t** tab1_ptr, int* n, int* tab) {
81 tab1_append_tab_(tab1_ptr, n, tab);
82 }
83 void _FCALL TAB1_GET_SIZE(tab1_t** tab1_ptr, int* ii) {
84 tab1_get_size_(tab1_ptr, ii);
85 }
86 void _FCALL TAB1_GET(tab1_t** tab1_ptr, int* ii) {
87 tab1_get_(tab1_ptr, ii);
88 }
89 void _FCALL TAB1_FREE_MEMORY(tab1_t** tab1_ptr, int* ii) {
90 tab1_free_memory_(tab1_ptr);
91 }
92}
93
94// toot
95void edge_sort_(edge_list_t** edge_ptr, int* n1, int* n2, int* elem, int* nedge)
96{
97 int nn = *nedge;
98 std::vector<tab3_t> tab(nn);
99 for (int i(0) ; i < nn ; ++i) {
100 tab.at(i).n1 = n1[i];
101 tab.at(i).n2 = n2[i];
102 tab.at(i).n3 = elem[i];
103 }
104 std::sort(tab.begin(), tab.end(), [] (tab3_t ielem1, tab3_t ielem2)
105 {return (ielem1.n1 < ielem2.n1);});
106 int i = 0;
107 while (i < tab.size()) {
108 int j = i;
109 for ( ; (j < tab.size()) && (tab.at(i).n1 == tab.at(j).n1) ; j++) {}
110 if (j != i) {
111 std::vector<tab3_t>::iterator iter1 = tab.begin() + i;
112 std::vector<tab3_t>::iterator iter2 = tab.begin() + j;
113 std::sort(iter1, iter2, [] (tab3_t ielem1, tab3_t ielem2) {return (ielem1.n2 < ielem2.n2);});
114 i = j;
115 }
116 }
117
118
119 *edge_ptr = new edge_list_t;
120 edge_list_t* edge_list = *edge_ptr;
121
122 edge_list->push_back(edge_t(tab.at(0).n1, tab.at(0).n2, tab.at(0).n3));
123 for (int i(1) ; i < nn ; ++i) {
124 if (tab.at(i).n1 != (*(edge_list->end()-1)).n1 || tab.at(i).n2 != (*(edge_list->end()-1)).n2) {
125 edge_list->push_back(edge_t(tab.at(i).n1, tab.at(i).n2, tab.at(i).n3));
126 } else {
127 (*(edge_list->end()-1)).elem_list.push_back(tab.at(i).n3);
128 }
129 }
130
131 for (int i(0) ; i < edge_list->size() ; ++i) {
132 edge_list->at(i).nb_con = edge_list->at(i).elem_list.size();
133 }
134
135 *nedge = edge_list->size();
136 nn = *nedge;
137 // Copy back
138 for (int i(0) ; i < nn ; ++i) {
139 n1[i] = edge_list->at(i).n1;
140 n2[i] = edge_list->at(i).n2;
141 }
142}
143
144void edge_get_nb_connect_(edge_list_t** edge_ptr, int* nb_conn)
145{
146 edge_list_t const * edge_list = *edge_ptr;
147 int nn = edge_list->size();
148 for (int i(0) ; i < nn ; ++i) {
149 nb_conn[i] = edge_list->at(i).nb_con;
150 }
151}
152
153void edge_get_connect_(edge_list_t** edge_ptr, int* elem)
154{
155 edge_list_t const * edge_list = *edge_ptr;
156 int nn = edge_list->size();
157 int cpt = 0;
158 for (int i(0) ; i < nn ; ++i) {
159 for (int j(0) ; j < edge_list->at(i).elem_list.size(); ++j) {
160 elem[cpt] = edge_list->at(i).elem_list.at(j);
161 cpt++;
162 }
163 }
164}
165
167{
168 if (*edge_ptr != nullptr) {
169 delete (*edge_ptr);
170 *edge_ptr = nullptr;
171 }
172}
173
174void tab1_init_(tab1_t** tab_ptr)
175{
176 (*tab_ptr) = new tab1_t;
177}
178void tab1_append_(tab1_t** tab_ptr, int* ii)
179{
180 (*tab_ptr)->push_back(*ii);
181}
182void tab1_append_tab_(tab1_t** tab_ptr, int* n, int* tab)
183{
184 for (int i(0) ; i < *n ; ++i) {
185 (*tab_ptr)->push_back(tab[i]);
186 }
187}
188void tab1_get_size_(tab1_t** tab_ptr, int* ss)
189{
190 *ss = (*tab_ptr)->size();
191}
192void tab1_get_(tab1_t** tab_ptr, int* out)
193{
194 int ss = (*tab_ptr)->size();
195 for (int i(0) ; i < ss ; ++i) {
196 out[i] = (*tab_ptr)->at(i);
197 }
198}
200{
201 if ((*tab_ptr) != nullptr) {
202 delete (*tab_ptr);
203 (*tab_ptr) = nullptr;
204 }
205}
void _FCALL TAB1_GET_SIZE(tab1_t **tab1_ptr, int *ii)
void edge_get_nb_connect_(edge_list_t **, int *)
void _FCALL TAB1_FREE_MEMORY(tab1_t **tab1_ptr, int *ii)
void _FCALL TAB1_INIT(tab1_t **tab1_ptr)
void tab1_free_memory_(tab1_t **)
void edge_free_memory_(edge_list_t **)
vector< edge_t > edge_list_t
void _FCALL TAB1_APPEND_TAB(tab1_t **tab1_ptr, int *n, int *tab)
void _FCALL EDGE_GET_NB_CONNECT(edge_list_t **edge_ptr, int *nb_conn)
vector< int > tab1_t
void _FCALL EDGE_GET_CONNECT(edge_list_t **edge_ptr, int *elem)
void edge_sort_(edge_list_t **, int *, int *, int *, int *)
void _FCALL EDGE_FREE_MEMORY(edge_list_t **edge_ptr)
void tab1_init_(tab1_t **)
void tab1_get_(tab1_t **, int *)
void _FCALL TAB1_GET(tab1_t **tab1_ptr, int *ii)
void tab1_get_size_(tab1_t **, int *)
void tab1_append_(tab1_t **, int *)
void _FCALL EDGE_SORT(edge_list_t **edge_ptr, int *n1, int *n2, int *elem, int *nedge)
void tab1_append_tab_(tab1_t **, int *, int *)
void edge_get_connect_(edge_list_t **, int *)
void _FCALL TAB1_APPEND(tab1_t **tab1_ptr, int *ii)
#define _FCALL
n
edge_t(const int &nn1, const int &nn2, const int &eelem)
vector< int > elem_list