FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
hecmw_io_get_mesh.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "hecmw_struct.h"
9 #include "hecmw_util.h"
10 #include "hecmw_io_get_mesh.h"
11 #include "hecmw_io_mesh.h"
12 #include "hecmw_io_hec.h"
13 #include "hecmw_io_geofem.h"
14 #include "hecmw_io_abaqus.h"
15 #include "hecmw_io_dist.h"
16 #include "hecmw_dist_refine.h"
17 #include "hecmw_dist_free.h"
18 
19 static struct hecmwST_local_mesh *get_entire_mesh(
20  struct hecmw_ctrl_meshfiles *files) {
21  int i;
22  struct hecmwST_local_mesh *mesh;
23 
24  if (HECMW_io_init()) return NULL;
25  HECMW_log(HECMW_LOG_DEBUG, "io_init done");
26 
27  if (HECMW_io_pre_process()) return NULL;
28  HECMW_log(HECMW_LOG_DEBUG, "io_pre_process done");
29 
30  for (i = 0; i < files->n_mesh; i++) {
31  struct hecmw_ctrl_meshfile *file = &files->meshfiles[i];
32 
33  switch (file->type) {
35  if (HECMW_read_entire_mesh(file->filename)) return NULL;
36  break;
38  if (HECMW_read_geofem_mesh(file->filename)) return NULL;
39  break;
41  if (HECMW_read_abaqus_mesh(file->filename)) return NULL;
42  break;
43  default:
44  HECMW_assert(0);
45  }
46  }
47  HECMW_log(HECMW_LOG_DEBUG, "reading mesh done\n");
48 
49  if (HECMW_io_post_process()) return NULL;
50  HECMW_log(HECMW_LOG_DEBUG, "post_process done\n");
51 
53  if (mesh == NULL) return NULL;
54  HECMW_log(HECMW_LOG_DEBUG, "converting mesh done\n");
55 
56  if (HECMW_io_finalize()) return NULL;
57  HECMW_log(HECMW_LOG_DEBUG, "io_finalize done\n");
58 
59  return mesh;
60 }
61 
62 struct hecmwST_local_mesh *HECMW_get_mesh(char *name_ID) {
63  struct hecmw_ctrl_meshfiles *files;
64  struct hecmwST_local_mesh *mesh;
65  char filename[HECMW_FILENAME_LEN + 1];
66  char *cad_filename;
67  FILE *fp;
68 
70  if (files == NULL) return NULL;
71 
72  if (files->n_mesh == 1 &&
73  files->meshfiles[0].type == HECMW_CTRL_FTYPE_HECMW_DIST) {
74  strcpy(filename, files->meshfiles[0].filename);
75  mesh = HECMW_get_dist_mesh(filename);
76  } else {
77  mesh = get_entire_mesh(files);
78  }
79 
80  strcpy(filename, files->meshfiles[0].filename);
81  strtok(filename, ".");
82  strcat(filename, ".rnf");
83  if ((fp = fopen(filename, "r")) == NULL) {
84  cad_filename = NULL;
85  } else {
86  fclose(fp);
87  cad_filename = filename;
88  }
89 
90  if (HECMW_dist_refine(&mesh, files->meshfiles[0].refine, cad_filename,
91  NULL) != HECMW_SUCCESS) {
93  return NULL;
94  }
95 
97 
98  return mesh;
99 }
HECMW_CTRL_FTYPE_GEOFEM
#define HECMW_CTRL_FTYPE_GEOFEM
Definition: hecmw_control.h:18
HECMW_read_abaqus_mesh
int HECMW_read_abaqus_mesh(const char *filename)
Definition: hecmw_io_abaqus.c:4281
HECMW_dist_free
void HECMW_dist_free(struct hecmwST_local_mesh *mesh)
Definition: hecmw_dist_free.c:218
HECMW_LOG_DEBUG
#define HECMW_LOG_DEBUG
Definition: hecmw_log.h:21
HECMW_log
int HECMW_log(int loglv, const char *fmt,...)
Definition: hecmw_log.c:260
mesh
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
hecmw_io_abaqus.h
HECMW_io_post_process
int HECMW_io_post_process(void)
Definition: hecmw_io_mesh.c:4040
hecmwST_local_mesh
Definition: hecmw_struct.h:139
HECMW_CTRL_FTYPE_HECMW_ENTIRE
#define HECMW_CTRL_FTYPE_HECMW_ENTIRE
Definition: hecmw_control.h:16
HECMW_io_init
int HECMW_io_init(void)
Definition: hecmw_io_mesh.c:4010
hecmw_dist_free.h
hecmw_io_geofem.h
hecmw_struct.h
HECMW_CTRL_FTYPE_ABAQUS
#define HECMW_CTRL_FTYPE_ABAQUS
Definition: hecmw_control.h:20
hecmw_io_dist.h
HECMW_io_finalize
int HECMW_io_finalize(void)
Definition: hecmw_io_mesh.c:4024
HECMW_CTRL_FTYPE_HECMW_DIST
#define HECMW_CTRL_FTYPE_HECMW_DIST
Definition: hecmw_control.h:14
hecmw_ctrl_meshfile
Definition: hecmw_control.h:11
HECMW_ctrl_free_meshfiles
void HECMW_ctrl_free_meshfiles(struct hecmw_ctrl_meshfiles *meshfiles)
Definition: hecmw_control.c:2066
hecmw_ctrl_meshfile::type
int type
Definition: hecmw_control.h:12
hecmw_io_get_mesh.h
HECMW_read_entire_mesh
int HECMW_read_entire_mesh(const char *filename)
Definition: hecmw_io_hec.c:4436
hecmw_dist_refine.h
HECMW_get_mesh
struct hecmwST_local_mesh * HECMW_get_mesh(char *name_ID)
Definition: hecmw_io_get_mesh.c:62
HECMW_ctrl_get_meshfiles
struct hecmw_ctrl_meshfiles * HECMW_ctrl_get_meshfiles(char *name_ID)
Definition: hecmw_control.c:2205
HECMW_SUCCESS
#define HECMW_SUCCESS
Definition: hecmw_config.h:64
hecmw_ctrl_meshfiles
Definition: hecmw_control.h:39
hecmw_io_mesh.h
hecmw_ctrl_meshfile::filename
char * filename
Definition: hecmw_control.h:34
HECMW_get_dist_mesh
struct hecmwST_local_mesh * HECMW_get_dist_mesh(char *fname)
Definition: hecmw_io_dist.c:1662
HECMW_io_make_local_mesh
struct hecmwST_local_mesh * HECMW_io_make_local_mesh(void)
Definition: hecmw_io_mesh.c:4068
HECMW_read_geofem_mesh
int HECMW_read_geofem_mesh(const char *filename)
Definition: hecmw_io_geofem.c:667
hecmw_ctrl_meshfiles::meshfiles
struct hecmw_ctrl_meshfile * meshfiles
Definition: hecmw_control.h:42
hecmwST_local_mesh::files
char ** files
Definition: hecmw_struct.h:156
NULL
#define NULL
Definition: hecmw_io_nastran.c:30
hecmw_io_hec.h
HECMW_assert
#define HECMW_assert(cond)
Definition: hecmw_util.h:40
HECMW_FILENAME_LEN
#define HECMW_FILENAME_LEN
Definition: hecmw_config.h:72
hecmw_util.h
HECMW_io_pre_process
int HECMW_io_pre_process(void)
Definition: hecmw_io_mesh.c:4038
HECMW_dist_refine
int HECMW_dist_refine(struct hecmwST_local_mesh **mesh, int refine, const char *cad_filename, const char *part_filename)
Definition: hecmw_dist_refine.c:4530