FrontISTR  6.0.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_inp.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_inp_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 
52  if (HECMW_io_create_dummy_nodes()) return NULL;
53  HECMW_log(HECMW_LOG_DEBUG, "creating rotational dummy nodes done\n");
54 
56  if (mesh == NULL) return NULL;
57  HECMW_log(HECMW_LOG_DEBUG, "converting mesh done\n");
58 
59  if (HECMW_io_finalize()) return NULL;
60  HECMW_log(HECMW_LOG_DEBUG, "io_finalize done\n");
61 
62  return mesh;
63 }
64 
65 struct hecmwST_local_mesh *HECMW_get_mesh(char *name_ID) {
66  struct hecmw_ctrl_meshfiles *files;
67  struct hecmwST_local_mesh *mesh;
68  char filename[HECMW_FILENAME_LEN + 1];
69  char *cad_filename;
70  FILE *fp;
71 
73  if (files == NULL) return NULL;
74 
75  if (files->n_mesh == 1 &&
76  files->meshfiles[0].type == HECMW_CTRL_FTYPE_HECMW_DIST) {
77  snprintf(filename, sizeof(filename), "%s", files->meshfiles[0].filename);
78  mesh = HECMW_get_dist_mesh(filename);
79  } else {
80  mesh = get_entire_mesh(files);
81  }
82 
83  char *dot;
84  snprintf(filename, sizeof(filename), "%s", files->meshfiles[0].filename);
85  dot = strchr(filename, '.');
86  if (dot != NULL) *dot = '\0';
87  strncat(filename, ".rnf", sizeof(filename) - strlen(filename) - 1);
88  if ((fp = fopen(filename, "r")) == NULL) {
89  cad_filename = NULL;
90  } else {
91  fclose(fp);
92  cad_filename = filename;
93  }
94 
95  if (HECMW_dist_refine(&mesh, files->meshfiles[0].refine, cad_filename,
96  NULL) != HECMW_SUCCESS) {
98  return NULL;
99  }
100 
102 
103  return mesh;
104 }
#define HECMW_FILENAME_LEN
Definition: hecmw_config.h:87
#define HECMW_SUCCESS
Definition: hecmw_config.h:79
void HECMW_ctrl_free_meshfiles(struct hecmw_ctrl_meshfiles *meshfiles)
struct hecmw_ctrl_meshfiles * HECMW_ctrl_get_meshfiles(char *name_ID)
#define HECMW_CTRL_FTYPE_HECMW_DIST
Definition: hecmw_control.h:14
#define HECMW_CTRL_FTYPE_HECMW_ENTIRE
Definition: hecmw_control.h:16
#define HECMW_CTRL_FTYPE_INP
Definition: hecmw_control.h:20
#define HECMW_CTRL_FTYPE_GEOFEM
Definition: hecmw_control.h:18
void HECMW_dist_free(struct hecmwST_local_mesh *mesh)
int HECMW_dist_refine(struct hecmwST_local_mesh **mesh, int refine, const char *cad_filename, const char *part_filename)
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
struct hecmwST_local_mesh * HECMW_get_dist_mesh(char *fname)
int HECMW_read_geofem_mesh(const char *filename)
struct hecmwST_local_mesh * HECMW_get_mesh(char *name_ID)
int HECMW_read_entire_mesh(const char *filename)
int HECMW_read_inp_mesh(const char *filename)
int HECMW_io_create_dummy_nodes(void)
struct hecmwST_local_mesh * HECMW_io_make_local_mesh(void)
int HECMW_io_init(void)
int HECMW_io_pre_process(void)
int HECMW_io_post_process(void)
int HECMW_io_finalize(void)
#define NULL
int HECMW_log(int loglv, const char *fmt,...)
Definition: hecmw_log.c:260
#define HECMW_LOG_DEBUG
Definition: hecmw_log.h:21
#define HECMW_assert(cond)
Definition: hecmw_util.h:40
struct hecmw_ctrl_meshfile * meshfiles
Definition: hecmw_control.h:42