OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
c_h3d_create_rbodies.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//
24#include <stdio.h>
25#include <string.h>
26#include <stdlib.h>
27#include <math.h>
28#include <fcntl.h>
29
30
31
32#ifdef _WIN32
33/* Windows includes */
34#include <windows.h>
35#include <process.h>
36#include <io.h>
37#include <sys\types.h>
38#include <sys/stat.h>
39
40
41#elif 1
42
43/* Linux includes */
44#include <sys/resource.h>
45#include <sys/types.h>
46#include <time.h>
47#include <sys/stat.h>
48#include <unistd.h>
49#include <dlfcn.h>
50#define _FCALL
51#include <math.h>
52#include <stdbool.h>
53
54#endif
55
56#include "h3dpublic_defs.h"
57#include "h3dpublic_export.h"
58
59#define _FCALL
60
61#include "h3d_values.h"
62
63extern "C"
64/*=================================================================*/
65{
66/*=================================================================*/
67/* C_H3D_CREATE_RBODIES */
68/*=================================================================*/
69void c_h3d_create_rbodies_(int *ITAB, int *NUMNOD, int *NPBY, int *NNPBY, int *LPBY, int *NRBODY, int *COMPID_RBODIES)
70{
71 try {
72
73
74 // create Elements
75 H3D_ID elem_id ;
76 H3D_ID RigidElem ;
77 int i,j,nsn;
78
79 char RBODYPOOL[] = "Rbody";
81 if( !rc ) throw rc;
82
83 char RIGIDPOOL[] = "Rigid";
85 if( !rc ) throw rc;
86
87 unsigned int elem_count = 1;
88 unsigned int *conn;
89 double *coef;
90 int *dof;
91
92 if(*COMPID_RBODIES != 0 && *NRBODY != 0)
93 {
95 H3D_ELEM_CONFIG_RIGIDLINK, *COMPID_RBODIES,
97 for(i=0;i<*NRBODY;i++)
98 {
99 elem_id = NPBY[*NNPBY * i + 5];
100 nsn = NPBY[*NNPBY * i + 1];
101 comp_id = 1;
102
103 conn =(unsigned int *)malloc(nsn*sizeof(unsigned int));
104 coef =(double *)malloc(nsn*sizeof(double));
105 for(int n=0; n < nsn ; n++){coef[n] = 0.0;}
106
107 dof =(int *)malloc(nsn*sizeof(int));
108
109 for(j=0;j<nsn;j++)
110 {
111 conn[j] = ITAB[LPBY[NPBY[*NNPBY * i + 10] + j ] - 1 ];
112 dof[j] = 0;
113 }
114
115 RigidElem = NPBY[*NNPBY * i + 5] ;
116
117 unsigned int conn1[1];
118 double coef1[1] = {1.0};
119 int dof1[1] = {6};
120 conn1[0] = ITAB[NPBY[*NNPBY * i]-1];
121
122
123 if( !rc ) throw rc;
124 rc = Hyper3DElement2Write(h3d_file, elem_id, conn1, dof1 , coef1 , 1 ,conn, dof, coef, nsn);
125 if( !rc ) throw rc;
126
127 free(conn);
128 free(coef);
129 free(dof);
130
131 }
133 if( !rc ) throw rc;
134 }
135 else
136 {
137 for(i=0;i<*NRBODY;i++)
138 {
139 elem_id = NPBY[*NNPBY * i + 5];
140 nsn = NPBY[*NNPBY * i + 1];
141 comp_id = 1;
142
143 conn =(unsigned int *)malloc(nsn*sizeof(unsigned int));
144 coef =(double *)malloc(nsn*sizeof(double));
145 for(int n=0; n < nsn ; n++){coef[n] = 0.0;}
146
147 dof =(int *)malloc(nsn*sizeof(int));
148
149 for(j=0;j<nsn;j++)
150 {
151 conn[j] = ITAB[LPBY[NPBY[*NNPBY * i + 10] + j ] - 1 ];
152 dof[j] = 0;
153 }
154
155 RigidElem = NPBY[*NNPBY * i + 5] ;
156
157 unsigned int conn1[1];
158 double coef1[1] = {1.0};
159 int dof1[1] = {6};
160 conn1[0] = ITAB[NPBY[*NNPBY * i]-1];
161
162
164 H3D_ELEM_CONFIG_RIGIDLINK, RigidElem,
166 if( !rc ) throw rc;
167 rc = Hyper3DElement2Write(h3d_file, elem_id, conn1, dof1 , coef1 , 1 ,conn, dof, coef, nsn);
168 if( !rc ) throw rc;
170 if( !rc ) throw rc;
171
172 free(conn);
173 free(coef);
174 free(dof);
175
176 }
177 }
178
179
180 } // end of try
181
182 catch(...) {
184 }
185
186}
187
188void _FCALL C_H3D_CREATE_RBODIES(int *ITAB, int *NUMNOD, int *NPBY, int *NNPBY, int *LPBY, int *NRBODY, int *COMPID_RBODIES)
189{c_h3d_create_rbodies_ (ITAB, NUMNOD, NPBY, NNPBY, LPBY, NRBODY, COMPID_RBODIES);}
190
191void c_h3d_create_rbodies__ (int *ITAB, int *NUMNOD, int *NPBY, int *NNPBY, int *LPBY, int *NRBODY, int *COMPID_RBODIES)
192{c_h3d_create_rbodies_ (ITAB, NUMNOD, NPBY, NNPBY, LPBY, NRBODY, COMPID_RBODIES);}
193
194void c_h3d_create_rbodies (int *ITAB, int *NUMNOD, int *NPBY, int *NNPBY, int *LPBY, int *NRBODY, int *COMPID_RBODIES)
195{c_h3d_create_rbodies_ (ITAB, NUMNOD, NPBY, NNPBY, LPBY, NRBODY, COMPID_RBODIES);}
196
197
198/*=================================================================*/
199/* C_H3D_CREATE_RBODIES */
200/*=================================================================*/
201void c_h3d_create_rbodies_impi_(int *ITAB, int *NRBYKIN, int *MASTERND, int *ID_RBY, int *PTRPO, int *PTRPOO, int *PORBY, int *NSPMD, int *COMPID_RBODIES)
202{
203
204 int * PTRPO_TMP = new int [*NSPMD + 1];
205 try {
206
207
208 // create Elements
209 H3D_ID elem_id ;
210 H3D_ID RigidElem ;
211 int i,j,n,p,nsn,nsn_loc,ptr;
212 //int PTRPO_TMP[*NSPMD + 1];
213
214 char RBODYPOOL[] = "Rbody";
216 if( !rc ) throw rc;
217
218 char RIGIDPOOL[] = "Rigid";
220 if( !rc ) throw rc;
221
222 unsigned int *conn;
223 double *coef;
224 int *dof;
225 unsigned int elem_count = 1;
226
227 for(i=0;i<*NSPMD + 1;i++)
228 {
229 PTRPO_TMP[i] = PTRPO[i];
230 }
231
232 if(*COMPID_RBODIES != 0 && *NRBYKIN != 0)
233 {
235 H3D_ELEM_CONFIG_RIGIDLINK, *COMPID_RBODIES,
237 for(i=0;i<*NRBYKIN;i++)
238 {
239 elem_id = ID_RBY[i];
240 RigidElem = MASTERND[i] + 1 ;
241 nsn = 0;
242
243 for(p=0;p<*NSPMD;p++)
244 {
245 ptr = PTRPO_TMP[p];
246 if(ptr < PTRPOO[p+1])
247 {
248 if(PORBY[ptr-1] == i+1)
249 {
250 nsn = nsn + PORBY[ptr];
251 ptr = ptr + 2 ;
252 PTRPO_TMP[p]=PTRPO_TMP[p] + nsn + 2;
253 }
254 }
255 }
256
257 conn =(unsigned int *)malloc(nsn*sizeof(unsigned int));
258 coef =(double *)malloc(nsn*sizeof(double));
259 dof =(int *)malloc(nsn*sizeof(int));
260
261 for(n=0; n < nsn ; n++){coef[n] = 0.0; dof[n]=0; conn[n]=0;}
262 unsigned int conn1[1];
263 //double coef[nsn];
264 double coef1[1] = {1.0};
265 //int dof[nsn];
266 int dof1[1] = {6};
267 conn1[0] = RigidElem;
268 j = 0;
269
270 for(p=0;p<*NSPMD;p++)
271 {
272 ptr = PTRPO[p];
273 if(ptr < PTRPOO[p+1])
274 {
275 if(PORBY[ptr - 1] == i+1)
276 {
277 nsn_loc = PORBY[ptr];
278 ptr = ptr + 2 ;
279 for(n=0;n<nsn_loc;n++)
280 {
281 conn[j] = PORBY[ptr+n-1] + 1;
282
283 j++;
284 }
285 PTRPO[p]=PTRPO[p] + nsn + 2;
286 }
287 }
288
289 }
290
291 if( !rc ) throw rc;
292 rc = Hyper3DElement2Write(h3d_file, elem_id, conn1, dof1 , coef1 , 1 ,conn, dof, coef, nsn);
293 if( !rc ) throw rc;
294
295 free(conn);
296 free(coef);
297 free(dof);
298
299 }
301 if( !rc ) throw rc;
302 }
303 else
304 {
305
306 for(i=0;i<*NRBYKIN;i++)
307 {
308 elem_id = ID_RBY[i];
309 RigidElem = MASTERND[i] + 1 ;
310 nsn = 0;
311
312 for(p=0;p<*NSPMD;p++)
313 {
314 ptr = PTRPO_TMP[p];
315 if(ptr < PTRPOO[p+1])
316 {
317 if(PORBY[ptr-1] == i+1)
318 {
319 nsn = nsn + PORBY[ptr];
320 ptr = ptr + 2 ;
321 PTRPO_TMP[p]=PTRPO_TMP[p] + nsn + 2;
322 }
323 }
324
325 }
326
327
328 conn =(unsigned int *)malloc(nsn*sizeof(unsigned int));
329 coef =(double *)malloc(nsn*sizeof(double));
330 dof =(int *)malloc(nsn*sizeof(int));
331
332 for(n=0; n < nsn ; n++){coef[n] = 0.0; dof[n]=0; conn[n]=0;}
333 unsigned int conn1[1];
334 //double coef[nsn];
335 double coef1[1] = {1.0};
336 //int dof[nsn];
337 int dof1[1] = {6};
338 conn1[0] = RigidElem;
339 j = 0;
340
341 for(p=0;p<*NSPMD;p++)
342 {
343 ptr = PTRPO[p];
344 if(ptr < PTRPOO[p+1])
345 {
346 if(PORBY[ptr - 1] == i+1)
347 {
348 nsn_loc = PORBY[ptr];
349 ptr = ptr + 2 ;
350 for(n=0;n<nsn_loc;n++)
351 {
352 conn[j] = PORBY[ptr+n-1] + 1;
353
354 j++;
355 }
356 PTRPO[p]=PTRPO[p] + nsn + 2;
357 }
358 }
359
360 }
361
362
363
365 H3D_ELEM_CONFIG_RIGIDLINK, elem_id,
367 if( !rc ) throw rc;
368 rc = Hyper3DElement2Write(h3d_file, elem_id, conn1, dof1 , coef1 , 1 ,conn, dof, coef, nsn);
369 if( !rc ) throw rc;
371 if( !rc ) throw rc;
372
373 free(conn);
374 free(coef);
375 free(dof);
376
377 }
378 }
379
380 } // end of try
381
382 catch(...) {
384 }
385 delete [] PTRPO_TMP;
386
387}
388
389void _FCALL C_H3D_CREATE_RBODIES_IMPI(int *ITAB ,int *NRBYKIN, int *MASTERND, int *ID_RBY, int *PTRPO, int *PTRPOO, int *PORBY, int *NSPMD, int *COMPID_RBODIES)
390{c_h3d_create_rbodies_impi_ (ITAB,NRBYKIN, MASTERND, ID_RBY, PTRPO, PTRPOO, PORBY,NSPMD,COMPID_RBODIES);}
391
392void c_h3d_create_rbodies_impi__ (int *ITAB ,int *NRBYKIN, int *MASTERND, int *ID_RBY, int *PTRPO, int *PTRPOO, int *PORBY, int *NSPMD, int *COMPID_RBODIES)
393{c_h3d_create_rbodies_impi_ (ITAB,NRBYKIN, MASTERND, ID_RBY, PTRPO, PTRPOO, PORBY,NSPMD,COMPID_RBODIES);}
394
395void c_h3d_create_rbodies_impi (int *ITAB, int *NRBYKIN, int *MASTERND, int *ID_RBY, int *PTRPO, int *PTRPOO, int *PORBY, int *NSPMD, int *COMPID_RBODIES)
396{c_h3d_create_rbodies_impi_ (ITAB,NRBYKIN, MASTERND, ID_RBY, PTRPO, PTRPOO, PORBY,NSPMD,COMPID_RBODIES);}
397
398
399}
void _FCALL C_H3D_CREATE_RBODIES_IMPI(int *ITAB, int *NRBYKIN, int *MASTERND, int *ID_RBY, int *PTRPO, int *PTRPOO, int *PORBY, int *NSPMD, int *COMPID_RBODIES)
void _FCALL C_H3D_CREATE_RBODIES(int *ITAB, int *NUMNOD, int *NPBY, int *NNPBY, int *LPBY, int *NRBODY, int *COMPID_RBODIES)
void c_h3d_create_rbodies__(int *ITAB, int *NUMNOD, int *NPBY, int *NNPBY, int *LPBY, int *NRBODY, int *COMPID_RBODIES)
void c_h3d_create_rbodies_impi(int *ITAB, int *NRBYKIN, int *MASTERND, int *ID_RBY, int *PTRPO, int *PTRPOO, int *PORBY, int *NSPMD, int *COMPID_RBODIES)
void c_h3d_create_rbodies(int *ITAB, int *NUMNOD, int *NPBY, int *NNPBY, int *LPBY, int *NRBODY, int *COMPID_RBODIES)
void c_h3d_create_rbodies_(int *ITAB, int *NUMNOD, int *NPBY, int *NNPBY, int *LPBY, int *NRBODY, int *COMPID_RBODIES)
void c_h3d_create_rbodies_impi_(int *ITAB, int *NRBYKIN, int *MASTERND, int *ID_RBY, int *PTRPO, int *PTRPOO, int *PORBY, int *NSPMD, int *COMPID_RBODIES)
void c_h3d_create_rbodies_impi__(int *ITAB, int *NRBYKIN, int *MASTERND, int *ID_RBY, int *PTRPO, int *PTRPOO, int *PORBY, int *NSPMD, int *COMPID_RBODIES)
H3DFileInfo * h3d_file
H3D_ID rigid_poolname_id
H3D_ID node_poolname_id
bool rc
H3D_ID comp_id
H3D_ID rbody_poolname_id
bool Hyper3DElement2Write(H3DFileInfo *h3d_file, H3D_ID id, unsigned int *inode, int *idof, double *icoeff, unsigned int num_inodes, unsigned int *dnode, int *ddof, double *dcoeff, unsigned int num_dnodes)
Definition h3d_dl.c:1170
bool Hyper3DAddString(H3DFileInfo *h3d_file, const char *const string, H3D_ID *const str_id)
Definition h3d_dl.c:955
bool Hyper3DExportClearError(H3DFileInfo *h3d_file)
Definition h3d_dl.c:939
bool Hyper3DElement2End(H3DFileInfo *h3d_file)
Definition h3d_dl.c:1181
bool Hyper3DElement2Begin(H3DFileInfo *h3d_file, unsigned int count, H3D_ID poolname_id, H3D_ElementConfig config, H3D_ID parent_id, H3D_ID parent_poolname_id, H3D_ID node_poolname_id)
Definition h3d_dl.c:1160
#define _FCALL
n