| 1 |
/* |
| 2 |
* Copyright(C) 1999-2020, 2023 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
/***************************************************************************** |
| 9 |
EXPERIMENTAL -- DO NOT USE THIS CAPABILITY/CONCEPT FOR PRODUCTION WORK |
| 10 |
|
| 11 |
This is a test of an experimental capability to output only the transient |
| 12 |
data to an exodus file. Eventually there will be a link between the |
| 13 |
transient file and the file containing the mesh data. For now, we are |
| 14 |
only writing the transient data and verifying that the file has sufficient |
| 15 |
data to be understood by some of the seacas utilities. |
| 16 |
|
| 17 |
One of the ultimate goals is to make per-timestep output of results |
| 18 |
data faster since do not need the mesh definition bulk data |
| 19 |
(coordinates, connectivity, ...) for each step |
| 20 |
|
| 21 |
EXPERIMENTAL -- DO NOT USE THIS CAPABILITY/CONCEPT FOR PRODUCTION WORK |
| 22 |
*****************************************************************************/ |
| 23 |
|
| 24 |
#include <stdio.h> |
| 25 |
#include <stdlib.h> |
| 26 |
#include <string.h> |
| 27 |
|
| 28 |
#include "exodusII.h" |
| 29 |
|
| 30 |
int main(int argc, char **argv) |
| 31 |
{ |
| 32 |
int exoid, num_dim, num_nodes, num_elem, num_elem_blk; |
| 33 |
int num_node_sets, num_side_sets, error; |
| 34 |
int i, j, k, m; |
| 35 |
int num_glo_vars, num_nod_vars, num_ele_vars; |
| 36 |
int *truth_tab; |
| 37 |
int whole_time_step, num_time_steps; |
| 38 |
int CPU_word_size, IO_word_size; |
| 39 |
|
| 40 |
float *glob_var_vals, *nodal_var_vals, *elem_var_vals; |
| 41 |
float time_value; |
| 42 |
char *var_names[3]; |
| 43 |
char *title = "This is a test"; |
| 44 |
|
| 45 |
struct ex_block blocks[10]; |
| 46 |
|
| 47 |
ex_opts(EX_VERBOSE); |
| 48 |
|
| 49 |
/* Specify compute and i/o word size */ |
| 50 |
|
| 51 |
CPU_word_size = 0; /* sizeof(float) */ |
| 52 |
IO_word_size = 4; /* (4 bytes) */ |
| 53 |
|
| 54 |
/* create EXODUS II file */ |
| 55 |
exoid = ex_create("test-results.exo", /* filename path */ |
| 56 |
EX_CLOBBER, /* create mode */ |
| 57 |
&CPU_word_size, /* CPU float word size in bytes */ |
| 58 |
&IO_word_size); /* I/O float word size in bytes */ |
| 59 |
printf("after ex_create for test.exo, exoid = %d\n", exoid); |
| 60 |
printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size); |
| 61 |
|
| 62 |
num_dim = 0; |
| 63 |
num_nodes = 33; |
| 64 |
num_elem = 7; |
| 65 |
num_elem_blk = 7; |
| 66 |
num_node_sets = 0; |
| 67 |
num_side_sets = 0; |
| 68 |
|
| 69 |
ex_put_init(exoid, title, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, |
| 70 |
num_side_sets); |
| 71 |
|
| 72 |
/* write element block parameters */ |
| 73 |
for (i = 0; i < 10; i++) { |
| 74 |
blocks[i].type = EX_ELEM_BLOCK; |
| 75 |
blocks[i].id = i + 10; |
| 76 |
blocks[i].num_entry = 1; |
| 77 |
blocks[i].num_nodes_per_entry = 0; |
| 78 |
blocks[i].num_edges_per_entry = 0; |
| 79 |
blocks[i].num_faces_per_entry = 0; |
| 80 |
blocks[i].num_attribute = 0; |
| 81 |
} |
| 82 |
|
| 83 |
ex_put_block_params(exoid, num_elem_blk, blocks); |
| 84 |
|
| 85 |
/* write results variables parameters and names */ |
| 86 |
num_glo_vars = 1; |
| 87 |
|
| 88 |
var_names[0] = "glo_vars"; |
| 89 |
|
| 90 |
error = ex_put_variable_param(exoid, EX_GLOBAL, num_glo_vars); |
| 91 |
printf("after ex_put_variable_param, error = %d\n", error); |
| 92 |
if (error) { |
| 93 |
ex_close(exoid); |
| 94 |
exit(-1); |
| 95 |
} |
| 96 |
|
| 97 |
error = ex_put_variable_names(exoid, EX_GLOBAL, num_glo_vars, var_names); |
| 98 |
printf("after ex_put_variable_names, error = %d\n", error); |
| 99 |
if (error) { |
| 100 |
ex_close(exoid); |
| 101 |
exit(-1); |
| 102 |
} |
| 103 |
|
| 104 |
num_nod_vars = 2; |
| 105 |
/* 12345678901234567890123456789012 */ |
| 106 |
var_names[0] = "node_variable_a_very_long_name_0"; |
| 107 |
var_names[1] = "nod_var1"; |
| 108 |
|
| 109 |
error = ex_put_variable_param(exoid, EX_NODAL, num_nod_vars); |
| 110 |
printf("after ex_put_variable_param, error = %d\n", error); |
| 111 |
if (error) { |
| 112 |
ex_close(exoid); |
| 113 |
exit(-1); |
| 114 |
} |
| 115 |
|
| 116 |
error = ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, var_names); |
| 117 |
printf("after ex_put_variable_names, error = %d\n", error); |
| 118 |
if (error) { |
| 119 |
ex_close(exoid); |
| 120 |
exit(-1); |
| 121 |
} |
| 122 |
|
| 123 |
num_ele_vars = 3; |
| 124 |
/* 0 1 2 3 */ |
| 125 |
/* 12345678901234567890123456789012 */ |
| 126 |
var_names[0] = "this_variable_name_is_short"; |
| 127 |
var_names[1] = "this_variable_name_is_just_right"; |
| 128 |
var_names[2] = "this_variable_name_is_tooooo_long"; |
| 129 |
|
| 130 |
error = ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_ele_vars); |
| 131 |
printf("after ex_put_variable_param, error = %d\n", error); |
| 132 |
if (error) { |
| 133 |
ex_close(exoid); |
| 134 |
exit(-1); |
| 135 |
} |
| 136 |
|
| 137 |
error = ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names); |
| 138 |
printf("after ex_put_variable_names, error = %d\n", error); |
| 139 |
if (error) { |
| 140 |
ex_close(exoid); |
| 141 |
exit(-1); |
| 142 |
} |
| 143 |
|
| 144 |
/* write element variable truth table */ |
| 145 |
truth_tab = (int *)calloc((num_elem_blk * num_ele_vars), sizeof(int)); |
| 146 |
|
| 147 |
k = 0; |
| 148 |
for (i = 0; i < num_elem_blk; i++) { |
| 149 |
for (j = 0; j < num_ele_vars; j++) { |
| 150 |
truth_tab[k++] = 1; |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
error = ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab); |
| 155 |
printf("after ex_put_elem_var_tab, error = %d\n", error); |
| 156 |
|
| 157 |
if (error) { |
| 158 |
ex_close(exoid); |
| 159 |
exit(-1); |
| 160 |
} |
| 161 |
|
| 162 |
free(truth_tab); |
| 163 |
|
| 164 |
/* for each time step, write the analysis results; |
| 165 |
* the code below fills the arrays glob_var_vals, |
| 166 |
* nodal_var_vals, and elem_var_vals with values for debugging purposes; |
| 167 |
* obviously the analysis code will populate these arrays |
| 168 |
*/ |
| 169 |
|
| 170 |
whole_time_step = 1; |
| 171 |
num_time_steps = 10; |
| 172 |
|
| 173 |
glob_var_vals = (float *)calloc(num_glo_vars, CPU_word_size); |
| 174 |
nodal_var_vals = (float *)calloc(num_nodes, CPU_word_size); |
| 175 |
elem_var_vals = (float *)calloc(4, CPU_word_size); |
| 176 |
|
| 177 |
for (i = 0; i < num_time_steps; i++) { |
| 178 |
time_value = (float)(i + 1) / 100.0f; |
| 179 |
|
| 180 |
/* write time value */ |
| 181 |
|
| 182 |
error = ex_put_time(exoid, whole_time_step, &time_value); |
| 183 |
printf("after ex_put_time, error = %d\n", error); |
| 184 |
|
| 185 |
if (error) { |
| 186 |
ex_close(exoid); |
| 187 |
exit(-1); |
| 188 |
} |
| 189 |
|
| 190 |
/* write global variables */ |
| 191 |
|
| 192 |
for (j = 0; j < num_glo_vars; j++) { |
| 193 |
glob_var_vals[j] = (float)(j + 2) * time_value; |
| 194 |
} |
| 195 |
|
| 196 |
error = ex_put_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, num_glo_vars, glob_var_vals); |
| 197 |
printf("after ex_put_glob_vars, error = %d\n", error); |
| 198 |
|
| 199 |
if (error) { |
| 200 |
ex_close(exoid); |
| 201 |
exit(-1); |
| 202 |
} |
| 203 |
|
| 204 |
/* write nodal variables */ |
| 205 |
|
| 206 |
for (k = 1; k <= num_nod_vars; k++) { |
| 207 |
for (j = 0; j < num_nodes; j++) { |
| 208 |
nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value); |
| 209 |
} |
| 210 |
|
| 211 |
error = ex_put_var(exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals); |
| 212 |
printf("after ex_put_nodal_var, error = %d\n", error); |
| 213 |
if (error) { |
| 214 |
ex_close(exoid); |
| 215 |
exit(-1); |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
/* write element variables */ |
| 220 |
|
| 221 |
for (k = 1; k <= num_ele_vars; k++) { |
| 222 |
for (j = 0; j < num_elem_blk; j++) { |
| 223 |
for (m = 0; m < blocks[j].num_entry; m++) { |
| 224 |
elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value); |
| 225 |
/* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */ |
| 226 |
} |
| 227 |
error = ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, blocks[j].id, |
| 228 |
blocks[j].num_entry, elem_var_vals); |
| 229 |
printf("after ex_put_elem_var, error = %d\n", error); |
| 230 |
if (error) { |
| 231 |
ex_close(exoid); |
| 232 |
exit(-1); |
| 233 |
} |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
whole_time_step++; |
| 238 |
|
| 239 |
/* update the data file; this should be done at the end of every time step |
| 240 |
* to ensure that no data is lost if the analysis dies |
| 241 |
*/ |
| 242 |
error = ex_update(exoid); |
| 243 |
printf("after ex_update, error = %d\n", error); |
| 244 |
if (error) { |
| 245 |
ex_close(exoid); |
| 246 |
exit(-1); |
| 247 |
} |
| 248 |
} |
| 249 |
free(glob_var_vals); |
| 250 |
free(nodal_var_vals); |
| 251 |
free(elem_var_vals); |
| 252 |
|
| 253 |
/* close the EXODUS files |
| 254 |
*/ |
| 255 |
error = ex_close(exoid); |
| 256 |
printf("after ex_close, error = %d\n", error); |
| 257 |
if (error) { |
| 258 |
ex_close(exoid); |
| 259 |
exit(-1); |
| 260 |
} |
| 261 |
return 0; |
| 262 |
} |