OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
c_h3d_open_file.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#include "h3d_values.h"
60
61#ifdef MYREAL4
62#define my_real float
63#endif
64
65#ifdef MYREAL8
66#define my_real double
67#endif
68
69 H3DFileInfo* h3d_file;
70 bool rc;
71 H3D_ID subcase_id;
72
73 unsigned int model_count;
75 H3D_TRIBOOL model_adaptive ;
76 H3D_ID model_id;
77
79
80
81 unsigned int assm_count;
82 H3D_ID assm_id;
84
85 H3D_ID assm_parent; // assm_parent = 1
86
90
91 unsigned int comp_count;
92 H3D_ID comp_id;
93 H3D_ID comp_parent_id; // comp_parent_id = assm 1
94
95 H3D_SIM_IDX sim_idx;
122
123 char edata_type[50];
124 H3D_ID dt_id;
125 unsigned int pool_count;
126 unsigned int layer_count;
128 H3D_TENSOR_TYPE tensor_type; // unused
129 float poisson; // default & unused
130 unsigned int dt_count;
132
133#define _FCALL
134extern "C"
135/*=================================================================*/
136{
137
138
139/*=================================================================*/
140/* REPORTERRORMESSAGE */
141/*=================================================================*/
142
143void ReportErrorMsg(H3DFileInfo* h3d_file, const char* error)
144{
145 FILE* errorFile = (FILE*)h3d_file->client_data1;
146 if( !errorFile ) {
147#ifdef _WIN64
148 fopen_s(&errorFile,"export_error_messages", "a");
149#else
150 errorFile = fopen("export_error_messages", "a");
151#endif
152 h3d_file->client_data1 = (void*)errorFile;
153 }
154
155 fprintf(errorFile, "%s\n", error);
156
157}
158/*=================================================================*/
159/* OPEN_H3D_FILE */
160/*=================================================================*/
161void c_h3d_open_file_(char *name, int *size, my_real *percentage_error, int *comp_level, char *RADVERS, int *LEN_RADVERS,
162 my_real *FAC_M, my_real *FAC_L, my_real *FAC_T)
163{
164
165 rc = true;
166 subcase_id = 1;
167
168 model_count = 1;
169 model_tabular = false;
170 model_adaptive = H3D_BOOL_FALSE;
171 model_id = 1;
172
173 assm_poolname_id = H3D_NULL_ID;
174
175
176 assm_count = 2;
177 assm_id = 1;
178 model_as_parent = H3D_NULL_ID;
179
180 assm_parent = 0; // assm_parent = 1
181
182 comp_poolname_id = H3D_NULL_ID;
183 node_poolname_id = H3D_NULL_ID;
184 sphnode_poolname_id = H3D_NULL_ID;
185
186 comp_count = 1;
187 comp_id = 1;
188 comp_parent_id = 1; // comp_parent_id = assm 1
189
190 rbody_poolname_id = H3D_NULL_ID;
191 rbe2_poolname_id = H3D_NULL_ID;
192 rbe3_poolname_id = H3D_NULL_ID;
193 rwall_poolname_id = H3D_NULL_ID;
194 spring_poolname_id = H3D_NULL_ID;
195 beam_poolname_id = H3D_NULL_ID;
196 truss_poolname_id = H3D_NULL_ID;
197 elem1D_poolname_id = H3D_NULL_ID;
198 elem2D_poolname_id = H3D_NULL_ID;
199 sh4n_poolname_id = H3D_NULL_ID;
200 sh3n_poolname_id = H3D_NULL_ID;
201 shell_poolname_id = H3D_NULL_ID;
202 quad_poolname_id = H3D_NULL_ID;
203 skin_poolname_id = H3D_NULL_ID;
204 solid4n_poolname_id = H3D_NULL_ID;
205 solid10n_poolname_id = H3D_NULL_ID;
206 solid5n_poolname_id = H3D_NULL_ID;
207 solid6n_poolname_id = H3D_NULL_ID;
208 solid8n_poolname_id = H3D_NULL_ID;
209 solid16n_poolname_id = H3D_NULL_ID;
210 solid20n_poolname_id = H3D_NULL_ID;
211 rigid_poolname_id = H3D_NULL_ID;
212 solid_poolname_id = H3D_NULL_ID;
213 onedelem_poolname_id = H3D_NULL_ID;
214 sph_poolname_id = H3D_NULL_ID;
215 sphcell_poolname_id = H3D_NULL_ID;
216
217 dt_id = 1;
218 pool_count = 0;
219 layer_count = 0;
220 has_corners = false;
221 poisson = 0.3f; // default & unused
222 dt_count = 2;
223
224 char *cname;
225 int cname_len;
226 int i;
227
228 cname_len = *size + 1;
229 cname=(char*) malloc(sizeof(char)*cname_len);
230 for(i=0;i<*size;i++) cname[i] = name[i];
231 cname[*size]='\0';
232//
233// open h3d file
234//
235 h3d_file = Hyper3DExportOpen(cname, H3D_SINGLEFILE, NULL, ReportErrorMsg);
236
237 h3d_file -> quantize_error = *percentage_error / 100.f ;
238 h3d_file -> compression_level = *comp_level ;
239
240 // define pool names that will be used
241 char* creating_application;
242 creating_application=(char*) malloc(sizeof(char)*(*LEN_RADVERS+1));
243#ifdef _WIN64
244 strncpy_s(creating_application, *LEN_RADVERS+1, RADVERS, *LEN_RADVERS);
245#else
246 strncpy(creating_application, RADVERS, *LEN_RADVERS);
247#endif
248 creating_application[*LEN_RADVERS] = '\0';
249//
250 char* solver_name;
251 solver_name=(char*) malloc(sizeof(char)*(*LEN_RADVERS+1));
252#ifdef _WIN64
253 strncpy_s(solver_name, *LEN_RADVERS+1 , RADVERS, *LEN_RADVERS);
254#else
255 strncpy(solver_name, RADVERS, *LEN_RADVERS);
256#endif
257 solver_name[*LEN_RADVERS] = '\0';
258//
259 char file_creation_date[] = __DATE__;
260 char original_data_file[] = " ";
261 char original_result_file[] = " ";
262
263 char file_comment[100];
264 sprintf(file_comment, "UNIT MASS=%g LENGTH=%g TIME=%g", *FAC_M,*FAC_L,*FAC_T);
265
266 try {
267
268
269 // create Model block
271 if( !rc ) throw rc;
272
273
274
275
278 if( !rc ) throw rc;
279
280
281
283 if( !rc ) throw rc;
284
285
286
287 // SetModel must be called!
289 if( !rc ) throw rc;
290
291 // create File Info block
292 rc = Hyper3DFileInfoBegin(h3d_file, creating_application, file_creation_date, solver_name);
293 if( !rc ) throw rc;
294// rc = Hyper3DFileInfoAddModelFile(h3d_file, original_data_file);
295// if( !rc ) throw rc;
296// rc = Hyper3DFileInfoAddResultFile(h3d_file, original_result_file);
297// if( !rc ) throw rc;
298 rc = Hyper3DFileInfoAddComment(h3d_file, file_comment);
299 if( !rc ) throw rc;
301 if( !rc ) throw rc;
302
303
304
305 } // end of try
306
307 catch(...) {
309 }
310
311}
312
313void _FCALL C_H3D_OPEN_FILE(char *name, int *size, my_real *percentage_error, int *comp_level, char *RADVERS, int *LEN_RADVERS,
314 my_real *FAC_M, my_real *FAC_L, my_real *FAC_T)
315{c_h3d_open_file_ (name,size,percentage_error,comp_level,RADVERS,LEN_RADVERS,FAC_M,FAC_L,FAC_T);}
316
317void c_h3d_open_file__ (char *name, int *size, my_real *percentage_error, int *comp_level, char *RADVERS, int *LEN_RADVERS,
318 my_real *FAC_M, my_real *FAC_L, my_real *FAC_T)
319{c_h3d_open_file_ (name,size,percentage_error,comp_level,RADVERS,LEN_RADVERS,FAC_M,FAC_L,FAC_T);}
320
321void c_h3d_open_file (char *name, int *size, my_real *percentage_error, int *comp_level, char *RADVERS, int *LEN_RADVERS,
322 my_real *FAC_M, my_real *FAC_L, my_real *FAC_T)
323{c_h3d_open_file_ (name,size,percentage_error,comp_level,RADVERS,LEN_RADVERS,FAC_M,FAC_L,FAC_T);}
324
325
326/*=================================================================*/
327/* REOPEN_H3D_FILE */
328/*=================================================================*/
329void c_h3d_reopen_file_(char *name, int *size, my_real *percentage_error, int *comp_level)
330{
331
332 rc = true;
333 subcase_id = 1;
334
335 model_count = 1;
336 model_tabular = false;
337 model_adaptive = H3D_BOOL_FALSE;
338 model_id = 1;
339
340 assm_poolname_id = H3D_NULL_ID;
341
342
343 assm_count = 2;
344 assm_id = 1;
345 model_as_parent = H3D_NULL_ID;
346
347 assm_parent = 0; // assm_parent = 1
348
349 comp_poolname_id = H3D_NULL_ID;
350 node_poolname_id = H3D_NULL_ID;
351
352 comp_count = 1;
353 comp_id = 1;
354 comp_parent_id = 1; // comp_parent_id = assm 1
355
356 rbody_poolname_id = H3D_NULL_ID;
357 rbe2_poolname_id = H3D_NULL_ID;
358 rbe3_poolname_id = H3D_NULL_ID;
359 rwall_poolname_id = H3D_NULL_ID;
360 spring_poolname_id = H3D_NULL_ID;
361 beam_poolname_id = H3D_NULL_ID;
362 truss_poolname_id= H3D_NULL_ID;
363 elem1D_poolname_id = H3D_NULL_ID;
364 elem2D_poolname_id = H3D_NULL_ID;
365 sh4n_poolname_id = H3D_NULL_ID;
366 sh3n_poolname_id = H3D_NULL_ID;
367 shell_poolname_id = H3D_NULL_ID;
368 quad_poolname_id = H3D_NULL_ID;
369 skin_poolname_id = H3D_NULL_ID;
370 solid4n_poolname_id = H3D_NULL_ID;
371 solid10n_poolname_id = H3D_NULL_ID;
372 solid5n_poolname_id = H3D_NULL_ID;
373 solid6n_poolname_id = H3D_NULL_ID;
374 solid8n_poolname_id = H3D_NULL_ID;
375 solid16n_poolname_id = H3D_NULL_ID;
376 solid20n_poolname_id = H3D_NULL_ID;
377 rigid_poolname_id = H3D_NULL_ID;
378 solid_poolname_id = H3D_NULL_ID;
379 onedelem_poolname_id = H3D_NULL_ID;
380 sph_poolname_id = H3D_NULL_ID;
381 sphcell_poolname_id = H3D_NULL_ID;
382 sphnode_poolname_id = H3D_NULL_ID;
383
384 dt_id = 2;
385 pool_count = 0;
386 layer_count = 0;
387 has_corners = false;
388 poisson = 0.3f; // default & unused
389 dt_count = 2;
390
391 char *cname;
392 int cname_len;
393 int i;
394 cname_len = *size + 1;
395 cname=(char*) malloc(sizeof(char)*cname_len);
396 for(i=0;i<*size;i++) cname[i] = name[i];
397 cname[*size]='\0';
398//
399//
400// open h3d file
401//
402 h3d_file = Hyper3DExportOpen(cname,H3D_SINGLEFILE|H3D_APPEND, NULL, ReportErrorMsg);
403
404 try {
405 // SetModel must be called!
407 if( !rc ) throw rc;
408
409
410 rc = Hyper3DAddString(h3d_file, H3D_DEFAULT_COMPPOOL, &comp_poolname_id);
411 if( !rc ) throw rc;
412
413 rc = Hyper3DAddString(h3d_file, H3D_DEFAULT_NODEPOOL, &node_poolname_id);
414 if( !rc ) throw rc;
415
416 rc = Hyper3DAddString(h3d_file, H3D_DEFAULT_ELEMPOOL1D, &elem1D_poolname_id);
417 if( !rc ) throw rc;
418
419 char SHELLPOOL[] = "Shell";
421 if( !rc ) throw rc;
422
423 char SOLIDPOOL[] = "Solid";
425 if( !rc ) throw rc;
426
427 char QUADPOOL[] = "QUAD";
429 if( !rc ) throw rc;
430
431 char SKINPOOL[] = "SKIN";
433 if( !rc ) throw rc;
434
435 char ONEDELEMPOOL[] = "1D";
437 if( !rc ) throw rc;
438
439 char RIGIDPOOL[] = "Rigid";
441 if( !rc ) throw rc;
442
443 char SPHCELLPOOL[] = "SPHCELL";
445 if( !rc ) throw rc;
446
447 char SPHNODEPOOL[] = "SPHNodes";
449 if( !rc ) throw rc;
450
451 char SH3NPOOL[] = "SH3N";
453 if( !rc ) throw rc;
454
455 char SH4NPOOL[] = "SHELL";
457 if( !rc ) throw rc;
458
459 char SPRINGPOOL[] = "SPRING";
461 if( !rc ) throw rc;
462
463 char TRUSSPOOL[] = "TRUSS";
465 if( !rc ) throw rc;
466
467 char BEAMPOOL[] = "BEAM";
469 if( !rc ) throw rc;
470
471 char SOLID4NPOOL[] = "TETRA4";
473 if( !rc ) throw rc;
474
475 char SOLID10NPOOL[] = "TETRA10";
477 if( !rc ) throw rc;
478
479 char SOLID5NPOOL[] = "PENTA5";
481 if( !rc ) throw rc;
482
483 char SOLID6NPOOL[] = "PENTA6";
485 if( !rc ) throw rc;
486
487 char SOLID8NPOOL[] = "BRICK";
489 if( !rc ) throw rc;
490
491 char SOLID16NPOOL[] = "BRICK16";
493 if( !rc ) throw rc;
494
495 char SOLID20NPOOL[] = "BRICK20";
497 if( !rc ) throw rc;
498
499 char SPHPOOL[] = "Sph";
501 if( !rc ) throw rc;
502
503 char RBODYPOOL[] = "Rbody";
505 if( !rc ) throw rc;
506
507 char RBE2POOL[] = "Rbe2";
509 if( !rc ) throw rc;
510
511 char RBE3POOL[] = "Rbe3";
513 if( !rc ) throw rc;
514
515 char RWALLPOOL[] = "Rwall";
517 if( !rc ) throw rc;
518
519
520
521 } // end of try
522
523 catch(...) {
525 }
526
527}
528
529void _FCALL C_H3D_REOPEN_FILE(char *name, int *size, my_real *percentage_error, int *comp_level)
530{c_h3d_reopen_file_ (name,size,percentage_error,comp_level);}
531
532void c_h3d_reopen_file__ (char *name, int *size, my_real *percentage_error, int *comp_level)
533{c_h3d_reopen_file_ (name,size,percentage_error,comp_level);}
534
535void c_h3d_reopen_file (char *name, int *size, my_real *percentage_error, int *comp_level)
536{c_h3d_reopen_file_ (name,size,percentage_error,comp_level);}
537
538
539
540/*=================================================================*/
541/* H3D_WRITE_TOC */
542/*=================================================================*/
543
545{
546 try {
547 bool rc2 = Hyper3DWriteTOC(h3d_file);
548 if( !rc ) throw rc;
549
550 } // end of try
551
552 catch(...) {
554 }
555}
556
559
562
565
566
567/*=================================================================*/
568}
569/*=================================================================*/
570/* TRACE BACK end */
571/*=================================================================*/
572
H3D_ID shell_poolname_id
H3D_ID solid4n_poolname_id
void c_h3d_write_toc_()
H3D_ID onedelem_poolname_id
H3D_ID solid16n_poolname_id
H3DFileInfo * h3d_file
unsigned int comp_count
unsigned int model_count
H3D_ID elem1D_poolname_id
H3D_ID sph_poolname_id
H3D_TRIBOOL model_adaptive
unsigned int pool_count
H3D_ID assm_parent
H3D_ID model_id
H3D_ID rigid_poolname_id
unsigned int dt_count
bool has_corners
void h3d_write_toc()
H3D_ID model_as_parent
void h3d_write_toc__()
H3D_ID node_poolname_id
bool rc
H3D_ID solid5n_poolname_id
H3D_ID rbe3_poolname_id
H3D_ID spring_poolname_id
H3D_ID assm_poolname_id
void _FCALL C_H3D_REOPEN_FILE(char *name, int *size, my_real *percentage_error, int *comp_level)
float poisson
H3D_ID sh4n_poolname_id
H3D_ID comp_parent_id
H3D_ID beam_poolname_id
unsigned int assm_count
bool model_tabular
H3D_ID sh3n_poolname_id
H3D_ID sphnode_poolname_id
H3D_ID comp_id
H3D_ID solid6n_poolname_id
H3D_ID * layername_ids
void c_h3d_open_file(char *name, int *size, my_real *percentage_error, int *comp_level, char *RADVERS, int *LEN_RADVERS, my_real *FAC_M, my_real *FAC_L, my_real *FAC_T)
unsigned int layer_count
void c_h3d_reopen_file_(char *name, int *size, my_real *percentage_error, int *comp_level)
H3D_ID rwall_poolname_id
H3D_ID solid_poolname_id
H3D_ID rbody_poolname_id
H3D_SIM_IDX sim_idx
H3D_ID subcase_id
H3D_ID sphcell_poolname_id
H3D_ID skin_poolname_id
void c_h3d_open_file__(char *name, int *size, my_real *percentage_error, int *comp_level, char *RADVERS, int *LEN_RADVERS, my_real *FAC_M, my_real *FAC_L, my_real *FAC_T)
H3D_ID solid8n_poolname_id
void _FCALL C_H3D_WRITE_TOC()
H3D_ID truss_poolname_id
void c_h3d_reopen_file__(char *name, int *size, my_real *percentage_error, int *comp_level)
H3D_ID dt_id
H3D_ID elem2D_poolname_id
H3D_ID quad_poolname_id
char edata_type[50]
void c_h3d_reopen_file(char *name, int *size, my_real *percentage_error, int *comp_level)
H3D_ID solid20n_poolname_id
void c_h3d_open_file_(char *name, int *size, my_real *percentage_error, int *comp_level, char *RADVERS, int *LEN_RADVERS, my_real *FAC_M, my_real *FAC_L, my_real *FAC_T)
void _FCALL C_H3D_OPEN_FILE(char *name, int *size, my_real *percentage_error, int *comp_level, char *RADVERS, int *LEN_RADVERS, my_real *FAC_M, my_real *FAC_L, my_real *FAC_T)
H3D_TENSOR_TYPE tensor_type
H3D_ID rbe2_poolname_id
void ReportErrorMsg(H3DFileInfo *h3d_file, const char *error)
H3D_ID comp_poolname_id
H3D_ID solid10n_poolname_id
H3D_ID assm_id
#define my_real
Definition cppsort.cpp:32
bool Hyper3DModelBegin(H3DFileInfo *h3d_file, unsigned int count)
Definition h3d_dl.c:1006
bool Hyper3DFileInfoEnd(H3DFileInfo *h3d_file)
Definition h3d_dl.c:996
bool Hyper3DFileInfoAddComment(H3DFileInfo *h3d_file, const char *comment)
Definition h3d_dl.c:989
bool Hyper3DAddString(H3DFileInfo *h3d_file, const char *const string, H3D_ID *const str_id)
Definition h3d_dl.c:955
bool Hyper3DWriteTOC(H3DFileInfo *h3d_file)
Definition h3d_dl.c:934
bool Hyper3DExportClearError(H3DFileInfo *h3d_file)
Definition h3d_dl.c:939
bool Hyper3DFileInfoBegin(H3DFileInfo *h3d_file, const char *creating_appl, const char *creation_date, const char *solver_name)
Definition h3d_dl.c:966
bool Hyper3DModelEnd(H3DFileInfo *h3d_file)
Definition h3d_dl.c:1020
bool Hyper3DModelWrite(H3DFileInfo *h3d_file, const char *label, H3D_ID id, bool tabular, H3D_TRIBOOL adaptive)
Definition h3d_dl.c:1013
H3DFileInfo * Hyper3DExportOpen(const char *filename, H3D_FileMode mode, H3DMessageFunctionType mFunc, H3DErrorFunctionType eFunc)
Definition h3d_dl.c:926
bool Hyper3DSetModelToWrite(H3DFileInfo *h3d_file, H3D_ID id, bool tabular)
Definition h3d_dl.c:1027
#define _FCALL