Exodus 7.22

/test/testwt-oned.c
/*
* Copyright (c) 2005-2017 National Technology & Engineering Solutions
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
* NTESS, the U.S. Government retains certain rights in this software.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of NTESS nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "exodusII.h"
#define EXCHECK(funcall) \
do { \
if ((error = (funcall)) != NC_NOERR) { \
fprintf(stderr, "ERROR Calling " #funcall ", error = %d\n", error); \
ex_close(exoid); \
exit(-1); \
} \
} while (0)
int main(int argc, char **argv)
{
int error;
int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
int num_elem_in_block[10], num_nodes_per_elem[10];
int num_nodes_in_nset[10];
int num_node_sets, num_side_sets;
int i, j, k, m, *elem_map, *connect;
int node_list[100];
int ebids[10], nsids[10];
int num_qa_rec, num_info;
int num_nod_vars, num_ele_vars, num_nset_vars;
int *truth_tab;
int whole_time_step, num_time_steps;
int CPU_word_size, IO_word_size;
int prop_array[2];
int elem_list[1], side_list[1];
float *nodal_var_vals, *elem_var_vals;
float *nset_var_vals;
float time_value;
float x[100];
float attrib[10], dist_fact[100];
char * coord_names[3], *qa_record[2][4], *info[3], *var_names[3];
char * block_names[10], *set_names[10];
char * prop_names[2], *attrib_names[2];
char * title = "This is a test";
ex_opts(EX_VERBOSE | EX_ABORT);
/* Specify compute and i/o word size */
CPU_word_size = 0; /* sizeof(float) */
IO_word_size = 4; /* (4 bytes) */
/* create EXODUS file */
exoid = ex_create("test.exo", /* filename path */
EX_CLOBBER, /* create mode */
&CPU_word_size, /* CPU float word size in bytes */
&IO_word_size); /* I/O float word size in bytes */
printf("after ex_create for oned.e, exoid = %d\n", exoid);
printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);
EXCHECK(ex_set_max_name_length(exoid, 40));
/* initialize file with parameters */
num_dim = 1;
num_nodes = 10;
num_elem = 10; /* 9 lines plus a point */
num_elem_blk = 3;
num_node_sets = 2;
num_side_sets = 2;
EXCHECK(ex_put_init(exoid, title, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets,
num_side_sets));
for (i = 0; i < num_nodes; i++) {
x[i] = exp((float)i / 10.0f);
}
EXCHECK(ex_put_coord(exoid, x, NULL, NULL));
coord_names[0] = "xcoor";
EXCHECK(ex_put_coord_names(exoid, coord_names));
/* Add nodal attributes */
EXCHECK(ex_put_attr_param(exoid, EX_NODAL, 0, 1));
EXCHECK(ex_put_one_attr(exoid, EX_NODAL, 0, 1, x));
attrib_names[0] = "Node_attr_1";
EXCHECK(ex_put_attr_names(exoid, EX_NODAL, 0, attrib_names));
/* write element order map */
elem_map = (int *)calloc(num_elem, sizeof(int));
for (i = 1; i <= num_elem; i++) {
elem_map[i - 1] = 10 * i;
}
EXCHECK(ex_put_map(exoid, elem_map));
free(elem_map);
/* write element block parameters */
block_names[0] = "left_side";
block_names[1] = "right_side";
block_names[2] = "center";
num_elem_in_block[0] = 4;
num_elem_in_block[1] = 5;
num_elem_in_block[2] = 1;
num_nodes_per_elem[0] = 2;
num_nodes_per_elem[1] = 2;
num_nodes_per_elem[2] = 1;
ebids[0] = 10;
ebids[1] = 20;
ebids[2] = 30;
EXCHECK(ex_put_block(exoid, EX_ELEM_BLOCK, ebids[0], "bar", num_elem_in_block[0],
num_nodes_per_elem[0], 0, 0, 1));
EXCHECK(ex_put_block(exoid, EX_ELEM_BLOCK, ebids[1], "bar", num_elem_in_block[1],
num_nodes_per_elem[1], 0, 0, 1));
EXCHECK(ex_put_block(exoid, EX_ELEM_BLOCK, ebids[2], "point", num_elem_in_block[2],
num_nodes_per_elem[2], 0, 0, 0));
/* Write element block names */
EXCHECK(ex_put_names(exoid, EX_ELEM_BLOCK, block_names));
/* write element block properties */
prop_names[0] = "DENSITY";
EXCHECK(ex_put_prop_names(exoid, EX_ELEM_BLOCK, 1, prop_names));
EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], prop_names[0], 1));
EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], prop_names[0], 10));
EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], prop_names[0], 34));
/* write element connectivity */
connect = (int *)calloc(20, sizeof(int));
for (i = 0; i < num_elem * 2; i += 2) {
connect[i] = i / 2 + 1;
connect[i + 1] = i / 2 + 2;
}
EXCHECK(ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL));
EXCHECK(ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[1], connect + 8, NULL, NULL));
/* Circle */
connect[0] = 5;
EXCHECK(ex_put_conn(exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL));
free(connect);
/* write element block attributes */
for (i = 0; i < num_elem; i++) {
attrib[i] = 3.14159 * i;
}
EXCHECK(ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[0], attrib));
EXCHECK(ex_put_attr(exoid, EX_ELEM_BLOCK, ebids[1], attrib + num_elem_in_block[0]));
attrib_names[0] = "THICKNESS";
EXCHECK(ex_put_attr_names(exoid, EX_ELEM_BLOCK, ebids[0], attrib_names));
attrib_names[0] = "WIDTH";
EXCHECK(ex_put_attr_names(exoid, EX_ELEM_BLOCK, ebids[1], attrib_names));
/* write individual node sets */
num_nodes_in_nset[0] = 5;
num_nodes_in_nset[1] = 3;
nsids[0] = 20;
nsids[1] = 21;
EXCHECK(ex_put_set_param(exoid, EX_NODE_SET, nsids[0], 5, 5));
node_list[0] = 1;
node_list[1] = 3;
node_list[2] = 5;
node_list[3] = 7;
node_list[4] = 9;
dist_fact[0] = 1.0;
dist_fact[1] = 2.0;
dist_fact[2] = 3.0;
dist_fact[3] = 4.0;
dist_fact[4] = 5.0;
EXCHECK(ex_put_set(exoid, EX_NODE_SET, nsids[0], node_list, NULL));
EXCHECK(ex_put_set_dist_fact(exoid, EX_NODE_SET, nsids[0], dist_fact));
EXCHECK(ex_put_set_param(exoid, EX_NODE_SET, nsids[1], 3, 3));
node_list[0] = 2;
node_list[1] = 4;
node_list[2] = 6;
dist_fact[0] = 1.0;
dist_fact[1] = 2.0;
dist_fact[2] = 3.0;
EXCHECK(ex_put_set(exoid, EX_NODE_SET, nsids[1], node_list, NULL));
EXCHECK(ex_put_set_dist_fact(exoid, EX_NODE_SET, nsids[1], dist_fact));
/* Write node set names */
set_names[0] = "all_odd_nodes";
set_names[1] = "some_even_nodes";
EXCHECK(ex_put_names(exoid, EX_NODE_SET, set_names));
EXCHECK(ex_put_prop(exoid, EX_NODE_SET, nsids[0], "FACE", 4));
EXCHECK(ex_put_prop(exoid, EX_NODE_SET, nsids[1], "FACE", 5));
prop_array[0] = 1000;
prop_array[1] = 2000;
EXCHECK(ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array));
/* Add nodeset attributes */
EXCHECK(ex_put_attr_param(exoid, EX_NODE_SET, nsids[0], 1));
EXCHECK(ex_put_attr(exoid, EX_NODE_SET, nsids[0], x));
attrib_names[0] = "Nodeset_attribute";
EXCHECK(ex_put_attr_names(exoid, EX_NODE_SET, nsids[0], attrib_names));
EXCHECK(ex_put_set_param(exoid, EX_SIDE_SET, 1, 1, 1));
EXCHECK(ex_put_set_param(exoid, EX_SIDE_SET, 2, 1, 1));
elem_list[0] = 1;
side_list[0] = 1;
dist_fact[0] = 2.0;
EXCHECK(ex_put_set(exoid, EX_SIDE_SET, 1, elem_list, side_list));
EXCHECK(ex_put_set_dist_fact(exoid, EX_SIDE_SET, 1, dist_fact));
elem_list[0] = 9;
side_list[0] = 2;
dist_fact[0] = 3.0;
EXCHECK(ex_put_set(exoid, EX_SIDE_SET, 2, elem_list, side_list));
EXCHECK(ex_put_set_dist_fact(exoid, EX_SIDE_SET, 2, dist_fact));
/* Write side set names */
set_names[0] = "left_boundary";
set_names[1] = "right_boundary";
EXCHECK(ex_put_names(exoid, EX_SIDE_SET, set_names));
/* write QA records; test empty and just blank-filled records */
num_qa_rec = 2;
qa_record[0][0] = "TESTWT";
qa_record[0][1] = "testwt";
qa_record[0][2] = "07/07/93";
qa_record[0][3] = "15:41:33";
qa_record[1][0] = "";
qa_record[1][1] = " ";
qa_record[1][2] = "";
qa_record[1][3] = " ";
EXCHECK(ex_put_qa(exoid, num_qa_rec, qa_record));
/* write information records; test empty and just blank-filled records */
num_info = 3;
info[0] = "This is the first information record.";
info[1] = "";
info[2] = " ";
EXCHECK(ex_put_info(exoid, num_info, info));
/* write results variables parameters and names */
num_nod_vars = 2;
/* 12345678901234567890123456789012 */
var_names[0] = "node_variable_a_very_long_name_0";
var_names[1] = "nod_var1";
EXCHECK(ex_put_variable_param(exoid, EX_NODAL, num_nod_vars));
EXCHECK(ex_put_variable_names(exoid, EX_NODAL, num_nod_vars, var_names));
num_ele_vars = 3;
/* 0 1 2 3 */
/* 12345678901234567890123456789012 */
var_names[0] = "this_variable_name_is_short";
var_names[1] = "this_variable_name_is_just_right";
var_names[2] = "this_variable_name_is_tooooo_long";
EXCHECK(ex_put_variable_param(exoid, EX_ELEM_BLOCK, num_ele_vars));
EXCHECK(ex_put_variable_names(exoid, EX_ELEM_BLOCK, num_ele_vars, var_names));
num_nset_vars = 3;
var_names[0] = "ns_var0";
var_names[1] = "ns_var1";
var_names[2] = "ns_var2";
EXCHECK(ex_put_variable_param(exoid, EX_NODE_SET, num_nset_vars));
EXCHECK(ex_put_variable_names(exoid, EX_NODE_SET, num_nset_vars, var_names));
/* write element variable truth table */
truth_tab = (int *)calloc((num_elem_blk * num_ele_vars), sizeof(int));
k = 0;
for (i = 0; i < num_elem_blk; i++) {
for (j = 0; j < num_ele_vars; j++) {
truth_tab[k++] = 1;
}
}
EXCHECK(ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab));
free(truth_tab);
/* for each time step, write the analysis results;
* the code below fills the arrays glob_var_vals,
* nodal_var_vals, and elem_var_vals with values for debugging purposes;
*/
whole_time_step = 1;
num_time_steps = 10;
nodal_var_vals = (float *)calloc(num_nodes, CPU_word_size);
elem_var_vals = (float *)calloc(num_elem, CPU_word_size);
nset_var_vals = (float *)calloc(10, CPU_word_size);
for (i = 0; i < num_time_steps; i++) {
time_value = (float)(i + 1) / 100.0f;
/* write time value */
EXCHECK(ex_put_time(exoid, whole_time_step, &time_value));
/* write nodal variables */
for (k = 1; k <= num_nod_vars; k++) {
for (j = 0; j < num_nodes; j++) {
nodal_var_vals[j] = (float)k + ((float)(j + 1) * time_value);
}
EXCHECK(ex_put_var(exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals));
}
/* write element variables */
for (k = 1; k <= num_ele_vars; k++) {
for (j = 0; j < num_elem_blk; j++) {
for (m = 0; m < num_elem_in_block[j]; m++) {
elem_var_vals[m] = (float)(k + 1) + (float)(j + 2) + ((float)(m + 1) * time_value);
}
EXCHECK(ex_put_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j], num_elem_in_block[j],
elem_var_vals));
}
}
/* write nodeset variables */
for (k = 1; k <= num_nset_vars; k++) {
for (j = 0; j < num_node_sets; j++) {
for (m = 0; m < num_nodes_in_nset[j]; m++) {
nset_var_vals[m] = (float)(k + 3) + (float)(j + 4) + ((float)(m + 1) * time_value);
}
EXCHECK(ex_put_var(exoid, whole_time_step, EX_NODE_SET, k, nsids[j], num_nodes_in_nset[j],
nset_var_vals));
}
}
whole_time_step++;
/* update the data file; this should be done at the end of every time step
* to ensure that no data is lost if the analysis dies
*/
EXCHECK(ex_update(exoid));
}
free(nodal_var_vals);
free(elem_var_vals);
free(nset_var_vals);
/* close the EXODUS files */
EXCHECK(ex_close(exoid));
return 0;
}
ex_put_block
int ex_put_block(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, const char *entry_descrip, int64_t num_entries_this_blk, int64_t num_nodes_per_entry, int64_t num_edges_per_entry, int64_t num_faces_per_entry, int64_t num_attr_per_entry)
Definition: ex_put_block.c:73
EX_NODE_SET
Definition: exodusII.h:256
ex_put_names
int ex_put_names(int exoid, ex_entity_type obj_type, char *names[])
Definition: ex_put_names.c:63
truth_tab
truth_tab
Definition: ex_put_elem_var_tab.c:108
ex_put_truth_table
int ex_put_truth_table(int exoid, ex_entity_type obj_type, int num_blk, int num_var, int *var_tab)
Definition: ex_put_truth_table.c:93
ex_put_qa
int ex_put_qa(int exoid, int num_qa_records, char *qa_record[][4])
Definition: ex_put_qa.c:90
ex_opts
int ex_opts(int options)
Definition: ex_opts.c:83
error
error
Definition: ex_put_elem_var_tab.c:115
ex_put_prop_array
int ex_put_prop_array(int exoid, ex_entity_type obj_type, const char *prop_name, const void_int *values)
Definition: ex_put_prop_array.c:98
ex_put_set_dist_fact
int ex_put_set_dist_fact(int exoid, ex_entity_type set_type, ex_entity_id set_id, const void *set_dist_fact)
Definition: ex_put_set_dist_fact.c:63
ex_put_prop_names
int ex_put_prop_names(int exoid, ex_entity_type obj_type, int num_props, char **prop_names)
Definition: ex_put_prop_names.c:124
ex_put_variable_param
int ex_put_variable_param(int exoid, ex_entity_type obj_type, int num_vars)
Definition: ex_put_variable_param.c:152
ex_put_time
int ex_put_time(int exoid, int time_step, const void *time_value)
Definition: ex_put_time.c:78
ex_put_attr_names
int ex_put_attr_names(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, char **names)
ex_put_set_param
int ex_put_set_param(int exoid, ex_entity_type set_type, ex_entity_id set_id, int64_t num_entries_in_set, int64_t num_dist_fact_in_set)
Definition: ex_put_set_param.c:65
ex_put_prop
int ex_put_prop(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, const char *prop_name, ex_entity_id value)
Definition: ex_put_prop.c:103
EX_SIDE_SET
Definition: exodusII.h:264
ex_create
#define ex_create(path, mode, comp_ws, io_ws)
Definition: exodusII.h:444
ex_close
int ex_close(int exoid)
Definition: ex_close.c:73
ex_put_coord_names
int ex_put_coord_names(int exoid, char *coord_names[])
Definition: ex_put_coord_names.c:73
ex_put_set
int ex_put_set(int exoid, ex_entity_type set_type, ex_entity_id set_id, const void_int *set_entry_list, const void_int *set_extra_list)
Definition: ex_put_set.c:67
EX_ABORT
Definition: exodusII.h:284
ex_put_variable_names
int ex_put_variable_names(int exoid, ex_entity_type obj_type, int num_vars, char *var_names[])
Definition: ex_put_variable_names.c:151
ex_put_attr_param
int ex_put_attr_param(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, int num_attrs)
Definition: ex_put_attr_param.c:61
EX_CLOBBER
#define EX_CLOBBER
Definition: exodusII.h:114
EX_NODAL
Definition: exodusII.h:254
ex_put_info
int ex_put_info(int exoid, int num_info, char *info[])
Definition: ex_put_info.c:102
ex_set_max_name_length
int ex_set_max_name_length(int exoid, int length)
Definition: ex_utils.c:213
ex_put_conn
int ex_put_conn(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, const void_int *node_conn, const void_int *elem_edge_conn, const void_int *elem_face_conn)
Definition: ex_put_conn.c:71
EXCHECK
#define EXCHECK(funcall)
Definition: ex_copy.c:42
ex_put_map
int ex_put_map(int exoid, const void_int *elem_map)
Definition: ex_put_map.c:85
exodusII.h
ex_update
int ex_update(int exoid)
Definition: ex_update.c:56
ex_put_attr
int ex_put_attr(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, const void *attrib)
Definition: ex_put_attr.c:63
ex_put_init
int ex_put_init(int exoid, const char *title, int64_t num_dim, int64_t num_nodes, int64_t num_elem, int64_t num_elem_blk, int64_t num_node_sets, int64_t num_side_sets)
Definition: ex_put_init.c:80
ex_put_coord
int ex_put_coord(int exoid, const void *x_coor, const void *y_coor, const void *z_coor)
Definition: ex_put_coord.c:113
EX_ELEM_BLOCK
Definition: exodusII.h:261
EX_VERBOSE
Definition: exodusII.h:282
ex_put_one_attr
int ex_put_one_attr(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, int attrib_index, const void *attrib)
Definition: ex_put_one_attr.c:63
ex_put_var
int ex_put_var(int exoid, int time_step, ex_entity_type var_type, int var_index, ex_entity_id obj_id, int64_t num_entries_this_obj, const void *var_vals)
Definition: ex_put_var.c:238