PageRenderTime 102ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/contrib/exodusii/5.22b/exodus/cbind/test/testwt_clb.c

https://bitbucket.org/vijaysm/libmesh
C | 999 lines | 684 code | 214 blank | 101 comment | 88 complexity | a54d6173729383fb826619f574b3c4c7 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-3.0, MPL-2.0-no-copyleft-exception, GPL-2.0
  1. /*
  2. * Copyright (c) 2005 Sandia Corporation. Under the terms of Contract
  3. * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Governement
  4. * retains certain rights in this software.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. *
  13. * * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following
  15. * disclaimer in the documentation and/or other materials provided
  16. * with the distribution.
  17. *
  18. * * Neither the name of Sandia Corporation nor the names of its
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. */
  35. /*****************************************************************************
  36. *
  37. * testwt - test write an ExodusII database file
  38. *
  39. * author - Sandia National Laboratories
  40. * Larry A. Schoof - Original
  41. * Vic Yarberry - Added headers and error logging
  42. * 7/7/93 Modified for use with Exodus 2.00
  43. *
  44. *
  45. * environment - UNIX
  46. *
  47. * entry conditions -
  48. *
  49. * exit conditions -
  50. *
  51. * revision history -
  52. *
  53. * This is a test program for the C binding of the EXODUS II
  54. * database write routines.
  55. *
  56. *****************************************************************************/
  57. #include <stdlib.h>
  58. #include <stdio.h>
  59. #include "exodusII.h"
  60. int main (int argc, char **argv)
  61. {
  62. int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
  63. int num_elem_in_block[10], num_nodes_per_elem[10];
  64. int num_node_sets, num_side_sets, error;
  65. int i, j, k, kk, m, *elem_map, *connect;
  66. int node_list[100],elem_list[100],side_list[100];
  67. int ebids[10], ssids[10], nsids[10], nattr[10];
  68. int num_nodes_per_set[10], num_elem_per_set[10];
  69. int num_df_per_set[10];
  70. int num_qa_rec, num_info;
  71. int num_glo_vars, num_nod_vars, num_ele_vars, num_nset_vars, num_sset_vars;
  72. int *truth_tab, *nset_tab, *sset_tab;
  73. int whole_time_step, num_time_steps;
  74. int CPU_word_size,IO_word_size;
  75. int prop_array[2];
  76. float *glob_var_vals, *nodal_var_vals, *elem_var_vals, *nset_var_vals, *sset_var_vals;
  77. float time_value;
  78. float x[100], y[100], z[100];
  79. float attrib[1], dist_fact[100];
  80. char *coord_names[3], *qa_record[2][4], *info[3], *var_names[7];
  81. char *prop_names[2];
  82. char *eb_type[10];
  83. ex_opts (EX_VERBOSE|EX_ABORT);
  84. /* Specify compute and i/o word size */
  85. CPU_word_size = 0; /* sizeof(float) */
  86. IO_word_size = 4; /* (4 bytes) */
  87. /* create EXODUS II file */
  88. exoid = ex_create ("test.exo", /* filename path */
  89. EX_CLOBBER, /* create mode */
  90. &CPU_word_size, /* CPU float word size in bytes */
  91. &IO_word_size); /* I/O float word size in bytes */
  92. printf ("after ex_create for test.exo, exoid = %d\n", exoid);
  93. printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size);
  94. /* ncopts = NC_VERBOSE; */
  95. /* initialize file with parameters */
  96. num_dim = 3;
  97. num_nodes = 33;
  98. num_elem = 7;
  99. num_elem_blk = 7;
  100. num_node_sets = 2;
  101. num_side_sets = 5;
  102. error = ex_put_init (exoid, "This is a test", num_dim, num_nodes, num_elem,
  103. num_elem_blk, num_node_sets, num_side_sets);
  104. printf ("after ex_put_init, error = %d\n", error);
  105. if (error) {
  106. ex_close (exoid);
  107. exit(-1);
  108. }
  109. /* write nodal coordinates values and names to database */
  110. /* Quad #1 */
  111. x[0] = 0.0; y[0] = 0.0; z[0] = 0.0;
  112. x[1] = 1.0; y[1] = 0.0; z[1] = 0.0;
  113. x[2] = 1.0; y[2] = 1.0; z[2] = 0.0;
  114. x[3] = 0.0; y[3] = 1.0; z[3] = 0.0;
  115. /* Quad #2 */
  116. x[4] = 1.0; y[4] = 0.0; z[4] = 0.0;
  117. x[5] = 2.0; y[5] = 0.0; z[5] = 0.0;
  118. x[6] = 2.0; y[6] = 1.0; z[6] = 0.0;
  119. x[7] = 1.0; y[7] = 1.0; z[7] = 0.0;
  120. /* Hex #1 */
  121. x[8] = 0.0; y[8] = 0.0; z[8] = 0.0;
  122. x[9] = 10.0; y[9] = 0.0; z[9] = 0.0;
  123. x[10] = 10.0; y[10] = 0.0; z[10] =-10.0;
  124. x[11] = 1.0; y[11] = 0.0; z[11] =-10.0;
  125. x[12] = 1.0; y[12] = 10.0; z[12] = 0.0;
  126. x[13] = 10.0; y[13] = 10.0; z[13] = 0.0;
  127. x[14] = 10.0; y[14] = 10.0; z[14] =-10.0;
  128. x[15] = 1.0; y[15] = 10.0; z[15] =-10.0;
  129. /* Tetra #1 */
  130. x[16] = 0.0; y[16] = 0.0; z[16] = 0.0;
  131. x[17] = 1.0; y[17] = 0.0; z[17] = 5.0;
  132. x[18] = 10.0; y[18] = 0.0; z[18] = 2.0;
  133. x[19] = 7.0; y[19] = 5.0; z[19] = 3.0;
  134. /* Wedge #1 */
  135. x[20] = 3.0; y[20] = 0.0; z[20] = 6.0;
  136. x[21] = 6.0; y[21] = 0.0; z[21] = 0.0;
  137. x[22] = 0.0; y[22] = 0.0; z[22] = 0.0;
  138. x[23] = 3.0; y[23] = 2.0; z[23] = 6.0;
  139. x[24] = 6.0; y[24] = 2.0; z[24] = 2.0;
  140. x[25] = 0.0; y[25] = 2.0; z[25] = 0.0;
  141. /* Tetra #2 */
  142. x[26] = 2.7; y[26] = 1.7; z[26] = 2.7;
  143. x[27] = 6.0; y[27] = 1.7; z[27] = 3.3;
  144. x[28] = 5.7; y[28] = 1.7; z[28] = 1.7;
  145. x[29] = 3.7; y[29] = 0.0; z[29] = 2.3;
  146. /* 3d Tri */
  147. x[30] = 0.0; y[30] = 0.0; z[30] = 0.0;
  148. x[31] = 10.0; y[31] = 0.0; z[31] = 0.0;
  149. x[32] = 10.0; y[32] = 10.0; z[32] = 10.0;
  150. error = ex_put_coord (exoid, x, y, z);
  151. printf ("after ex_put_coord, error = %d\n", error);
  152. if (error) {
  153. ex_close (exoid);
  154. exit(-1);
  155. }
  156. coord_names[0] = "xcoor";
  157. coord_names[1] = "ycoor";
  158. coord_names[2] = "zcoor";
  159. error = ex_put_coord_names (exoid, coord_names);
  160. printf ("after ex_put_coord_names, error = %d\n", error);
  161. if (error) {
  162. ex_close (exoid);
  163. exit(-1);
  164. }
  165. /* write element order map */
  166. elem_map = (int *) calloc(num_elem, sizeof(int));
  167. for (i=1; i<=num_elem; i++)
  168. {
  169. elem_map[i-1] = i;
  170. }
  171. error = ex_put_map (exoid, elem_map);
  172. printf ("after ex_put_map, error = %d\n", error);
  173. if (error) {
  174. ex_close (exoid);
  175. exit(-1);
  176. }
  177. free (elem_map);
  178. /* write element block parameters */
  179. num_elem_in_block[0] = 1;
  180. num_elem_in_block[1] = 1;
  181. num_elem_in_block[2] = 1;
  182. num_elem_in_block[3] = 1;
  183. num_elem_in_block[4] = 1;
  184. num_elem_in_block[5] = 1;
  185. num_elem_in_block[6] = 1;
  186. num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads */
  187. num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads */
  188. num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes */
  189. num_nodes_per_elem[3] = 4; /* elements in block #4 are 4-node tetras */
  190. num_nodes_per_elem[4] = 6; /* elements in block #5 are 6-node wedges */
  191. num_nodes_per_elem[5] = 8; /* elements in block #6 are 8-node tetras */
  192. num_nodes_per_elem[6] = 3; /* elements in block #7 are 3-node tris */
  193. ebids[0] = 10;
  194. ebids[1] = 11;
  195. ebids[2] = 12;
  196. ebids[3] = 13;
  197. ebids[4] = 14;
  198. ebids[5] = 15;
  199. ebids[6] = 16;
  200. nattr[0] = nattr[1] = nattr[2] = nattr[3] = 1;
  201. nattr[4] = nattr[5] = nattr[6] = 1;
  202. eb_type[0] = "quad";
  203. eb_type[1] = "quad";
  204. eb_type[2] = "hex";
  205. eb_type[3] = "tetra";
  206. eb_type[4] = "wedge";
  207. eb_type[5] = "tetra";
  208. eb_type[6] = "tri";
  209. error = ex_put_concat_elem_block (exoid, ebids, eb_type,
  210. num_elem_in_block, num_nodes_per_elem,
  211. nattr, 0);
  212. printf ("after ex_put_concat_elem_block, error = %d\n", error);
  213. if (error) {
  214. ex_close (exoid);
  215. exit(-1);
  216. }
  217. /* write element block properties */
  218. prop_names[0] = "MATL";
  219. prop_names[1] = "DENSITY";
  220. error = ex_put_prop_names(exoid,EX_ELEM_BLOCK,2,prop_names);
  221. printf ("after ex_put_prop_names, error = %d\n", error);
  222. if (error) {
  223. ex_close (exoid);
  224. exit(-1);
  225. }
  226. error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10);
  227. printf ("after ex_put_prop, error = %d\n", error);
  228. if (error) {
  229. ex_close (exoid);
  230. exit(-1);
  231. }
  232. error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20);
  233. printf ("after ex_put_prop, error = %d\n", error);
  234. if (error) {
  235. ex_close (exoid);
  236. exit(-1);
  237. }
  238. error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30);
  239. printf ("after ex_put_prop, error = %d\n", error);
  240. if (error) {
  241. ex_close (exoid);
  242. exit(-1);
  243. }
  244. error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40);
  245. printf ("after ex_put_prop, error = %d\n", error);
  246. if (error) {
  247. ex_close (exoid);
  248. exit(-1);
  249. }
  250. error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50);
  251. printf ("after ex_put_prop, error = %d\n", error);
  252. if (error) {
  253. ex_close (exoid);
  254. exit(-1);
  255. }
  256. error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[5], "MATL", 60);
  257. printf ("after ex_put_prop, error = %d\n", error);
  258. if (error) {
  259. ex_close (exoid);
  260. exit(-1);
  261. }
  262. error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[6], "MATL", 70);
  263. printf ("after ex_put_prop, error = %d\n", error);
  264. if (error) {
  265. ex_close (exoid);
  266. exit(-1);
  267. }
  268. /* write element connectivity */
  269. connect = (int *) calloc(8, sizeof(int));
  270. connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4;
  271. error = ex_put_elem_conn (exoid, ebids[0], connect);
  272. printf ("after ex_put_elem_conn, error = %d\n", error);
  273. if (error) {
  274. ex_close (exoid);
  275. exit(-1);
  276. }
  277. connect[0] = 5; connect[1] = 6; connect[2] = 7; connect[3] = 8;
  278. error = ex_put_elem_conn (exoid, ebids[1], connect);
  279. printf ("after ex_put_elem_conn, error = %d\n", error);
  280. if (error) {
  281. ex_close (exoid);
  282. exit(-1);
  283. }
  284. connect[0] = 9; connect[1] = 10; connect[2] = 11; connect[3] = 12;
  285. connect[4] = 13; connect[5] = 14; connect[6] = 15; connect[7] = 16;
  286. error = ex_put_elem_conn (exoid, ebids[2], connect);
  287. printf ("after ex_put_elem_conn, error = %d\n", error);
  288. if (error) {
  289. ex_close (exoid);
  290. exit(-1);
  291. }
  292. connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;
  293. error = ex_put_elem_conn (exoid, ebids[3], connect);
  294. printf ("after ex_put_elem_conn, error = %d\n", error);
  295. if (error) {
  296. ex_close (exoid);
  297. exit(-1);
  298. }
  299. connect[0] = 21; connect[1] = 22; connect[2] = 23;
  300. connect[3] = 24; connect[4] = 25; connect[5] = 26;
  301. error = ex_put_elem_conn (exoid, ebids[4], connect);
  302. printf ("after ex_put_elem_conn, error = %d\n", error);
  303. if (error) {
  304. ex_close (exoid);
  305. exit(-1);
  306. }
  307. connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20;
  308. connect[4] = 27; connect[5] = 28; connect[6] = 30; connect[7] = 29;
  309. error = ex_put_elem_conn (exoid, ebids[5], connect);
  310. printf ("after ex_put_elem_conn, error = %d\n", error);
  311. if (error) {
  312. ex_close (exoid);
  313. exit(-1);
  314. }
  315. connect[0] = 31; connect[1] = 32; connect[2] = 33;
  316. error = ex_put_elem_conn (exoid, ebids[6], connect);
  317. printf ("after ex_put_elem_conn, error = %d\n", error);
  318. if (error) {
  319. ex_close (exoid);
  320. exit(-1);
  321. }
  322. free (connect);
  323. /* write element block attributes */
  324. attrib[0] = 3.14159;
  325. error = ex_put_elem_attr (exoid, ebids[0], attrib);
  326. printf ("after ex_put_elem_attr, error = %d\n", error);
  327. if (error) {
  328. ex_close (exoid);
  329. exit(-1);
  330. }
  331. attrib[0] = 6.14159;
  332. error = ex_put_elem_attr (exoid, ebids[1], attrib);
  333. printf ("after ex_put_elem_attr, error = %d\n", error);
  334. if (error) {
  335. ex_close (exoid);
  336. exit(-1);
  337. }
  338. error = ex_put_elem_attr (exoid, ebids[2], attrib);
  339. printf ("after ex_put_elem_attr, error = %d\n", error);
  340. if (error) {
  341. ex_close (exoid);
  342. exit(-1);
  343. }
  344. error = ex_put_elem_attr (exoid, ebids[3], attrib);
  345. printf ("after ex_put_elem_attr, error = %d\n", error);
  346. if (error) {
  347. ex_close (exoid);
  348. exit(-1);
  349. }
  350. error = ex_put_elem_attr (exoid, ebids[4], attrib);
  351. printf ("after ex_put_elem_attr, error = %d\n", error);
  352. if (error) {
  353. ex_close (exoid);
  354. exit(-1);
  355. }
  356. error = ex_put_elem_attr (exoid, ebids[5], attrib);
  357. printf ("after ex_put_elem_attr, error = %d\n", error);
  358. if (error) {
  359. ex_close (exoid);
  360. exit(-1);
  361. }
  362. error = ex_put_elem_attr (exoid, ebids[6], attrib);
  363. printf ("after ex_put_elem_attr, error = %d\n", error);
  364. if (error) {
  365. ex_close (exoid);
  366. exit(-1);
  367. }
  368. /* write individual node sets */
  369. nsids[0] = 20; nsids[1] = 21;
  370. num_nodes_per_set[0] = 5; num_nodes_per_set[1] = 3;
  371. num_df_per_set[0] = 5; num_df_per_set[1] = 3;
  372. error = ex_put_concat_node_sets (exoid, nsids, num_nodes_per_set,
  373. num_df_per_set, 0, 0, 0, 0);
  374. printf ("after ex_put_concat_node_sets, error = %d\n", error);
  375. if (error) {
  376. ex_close (exoid);
  377. exit(-1);
  378. }
  379. node_list[0] = 10; node_list[1] = 11; node_list[2] = 12;
  380. node_list[3] = 13; node_list[4] = 14;
  381. dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0;
  382. dist_fact[3] = 4.0; dist_fact[4] = 5.0;
  383. error = ex_put_node_set (exoid, 20, node_list);
  384. printf ("after ex_put_node_set, error = %d\n", error);
  385. if (error) {
  386. ex_close (exoid);
  387. exit(-1);
  388. }
  389. error = ex_put_node_set_dist_fact (exoid, 20, dist_fact);
  390. printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
  391. if (error) {
  392. ex_close (exoid);
  393. exit(-1);
  394. }
  395. node_list[0] = 20; node_list[1] = 21; node_list[2] = 22;
  396. dist_fact[0] = 1.1; dist_fact[1] = 2.1; dist_fact[2] = 3.1;
  397. error = ex_put_node_set (exoid, 21, node_list);
  398. printf ("after ex_put_node_set, error = %d\n", error);
  399. if (error) {
  400. ex_close (exoid);
  401. exit(-1);
  402. }
  403. error = ex_put_node_set_dist_fact (exoid, 21, dist_fact);
  404. printf ("after ex_put_node_set_dist_fact, error = %d\n", error);
  405. if (error) {
  406. ex_close (exoid);
  407. exit(-1);
  408. }
  409. error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4);
  410. printf ("after ex_put_prop, error = %d\n", error);
  411. if (error) {
  412. ex_close (exoid);
  413. exit(-1);
  414. }
  415. error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5);
  416. printf ("after ex_put_prop, error = %d\n", error);
  417. if (error) {
  418. ex_close (exoid);
  419. exit(-1);
  420. }
  421. prop_array[0] = 1000;
  422. prop_array[1] = 2000;
  423. error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array);
  424. printf ("after ex_put_prop_array, error = %d\n", error);
  425. if (error) {
  426. ex_close (exoid);
  427. exit(-1);
  428. }
  429. /* Define the sideset params at one time, then write individually */
  430. ssids[0] = 30;
  431. ssids[1] = 31;
  432. ssids[2] = 32;
  433. ssids[3] = 33;
  434. ssids[4] = 34;
  435. num_elem_per_set[0] = 2;
  436. num_elem_per_set[1] = 2;
  437. num_elem_per_set[2] = 7;
  438. num_elem_per_set[3] = 8;
  439. num_elem_per_set[4] = 10;
  440. num_df_per_set[0] = 4;
  441. num_df_per_set[1] = 4;
  442. num_df_per_set[2] = 0;
  443. num_df_per_set[3] = 0;
  444. num_df_per_set[4] = 0;
  445. error = ex_put_concat_side_sets (exoid, ssids, num_elem_per_set,
  446. num_df_per_set, 0, 0, 0, 0, 0);
  447. printf ("after ex_put_concat_side_sets, error = %d\n", error);
  448. /* write individual side sets */
  449. /* side set #1 - quad */
  450. elem_list[0] = 2; elem_list[1] = 2;
  451. side_list[0] = 4; side_list[1] = 2;
  452. dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2;
  453. dist_fact[3] = 30.3;
  454. error = ex_put_side_set (exoid, 30, elem_list, side_list);
  455. printf ("after ex_put_side_set, error = %d\n", error);
  456. if (error) {
  457. ex_close (exoid);
  458. exit(-1);
  459. }
  460. error = ex_put_side_set_dist_fact (exoid, 30, dist_fact);
  461. printf ("after ex_put_side_set_dist_fact, error = %d\n", error);
  462. if (error) {
  463. ex_close (exoid);
  464. exit(-1);
  465. }
  466. /* side set #2 - quad, spanning 2 elements */
  467. elem_list[0] = 1; elem_list[1] = 2;
  468. side_list[0] = 2; side_list[1] = 3;
  469. dist_fact[0] = 31.0; dist_fact[1] = 31.1; dist_fact[2] = 31.2;
  470. dist_fact[3] = 31.3;
  471. error = ex_put_side_set (exoid, 31, elem_list, side_list);
  472. printf ("after ex_put_side_set, error = %d\n", error);
  473. if (error) {
  474. ex_close (exoid);
  475. exit(-1);
  476. }
  477. error = ex_put_side_set_dist_fact (exoid, 31, dist_fact);
  478. printf ("after ex_put_side_set_dist_fact, error = %d\n", error);
  479. if (error) {
  480. ex_close (exoid);
  481. exit(-1);
  482. }
  483. /* side set #3 - hex */
  484. elem_list[0] = 3; elem_list[1] = 3;
  485. elem_list[2] = 3; elem_list[3] = 3;
  486. elem_list[4] = 3; elem_list[5] = 3;
  487. elem_list[6] = 3;
  488. side_list[0] = 5; side_list[1] = 3;
  489. side_list[2] = 3; side_list[3] = 2;
  490. side_list[4] = 4; side_list[5] = 1;
  491. side_list[6] = 6;
  492. error = ex_put_side_set (exoid, 32, elem_list, side_list);
  493. printf ("after ex_put_side_set, error = %d\n", error);
  494. if (error) {
  495. ex_close (exoid);
  496. exit(-1);
  497. }
  498. /* side set #4 - tetras */
  499. elem_list[0] = 4; elem_list[1] = 4;
  500. elem_list[2] = 4; elem_list[3] = 4;
  501. elem_list[4] = 6; elem_list[5] = 6;
  502. elem_list[6] = 6; elem_list[7] = 6;
  503. side_list[0] = 1; side_list[1] = 2;
  504. side_list[2] = 3; side_list[3] = 4;
  505. side_list[4] = 1; side_list[5] = 2;
  506. side_list[6] = 3; side_list[7] = 4;
  507. error = ex_put_side_set (exoid, 33, elem_list, side_list);
  508. printf ("after ex_put_side_set, error = %d\n", error);
  509. if (error) {
  510. ex_close (exoid);
  511. exit(-1);
  512. }
  513. /* side set #5 - wedges and tris */
  514. elem_list[0] = 5; elem_list[1] = 5;
  515. elem_list[2] = 5; elem_list[3] = 5;
  516. elem_list[4] = 5; elem_list[5] = 7;
  517. elem_list[6] = 7; elem_list[7] = 7;
  518. elem_list[8] = 7; elem_list[9] = 7;
  519. side_list[0] = 1; side_list[1] = 2;
  520. side_list[2] = 3; side_list[3] = 4;
  521. side_list[4] = 5; side_list[5] = 1;
  522. side_list[6] = 2; side_list[7] = 3;
  523. side_list[8] = 4; side_list[9] = 5;
  524. error = ex_put_side_set (exoid, 34, elem_list, side_list);
  525. printf ("after ex_put_side_set, error = %d\n", error);
  526. if (error) {
  527. ex_close (exoid);
  528. exit(-1);
  529. }
  530. error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100);
  531. printf ("after ex_put_prop, error = %d\n", error);
  532. if (error) {
  533. ex_close (exoid);
  534. exit(-1);
  535. }
  536. error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101);
  537. printf ("after ex_put_prop, error = %d\n", error);
  538. if (error) {
  539. ex_close (exoid);
  540. exit(-1);
  541. }
  542. /* write QA records; test empty and just blank-filled records */
  543. num_qa_rec = 2;
  544. qa_record[0][0] = "TESTWT";
  545. qa_record[0][1] = "testwt";
  546. qa_record[0][2] = "07/07/93";
  547. qa_record[0][3] = "15:41:33";
  548. qa_record[1][0] = "";
  549. qa_record[1][1] = " ";
  550. qa_record[1][2] = "";
  551. qa_record[1][3] = " ";
  552. error = ex_put_qa (exoid, num_qa_rec, qa_record);
  553. printf ("after ex_put_qa, error = %d\n", error);
  554. if (error) {
  555. ex_close (exoid);
  556. exit(-1);
  557. }
  558. /* write information records; test empty and just blank-filled records */
  559. num_info = 3;
  560. info[0] = "This is the first information record.";
  561. info[1] = "";
  562. info[2] = " ";
  563. error = ex_put_info (exoid, num_info, info);
  564. printf ("after ex_put_info, error = %d\n", error);
  565. if (error) {
  566. ex_close (exoid);
  567. exit(-1);
  568. }
  569. /* write results variables parameters and names */
  570. num_glo_vars = 1;
  571. num_nod_vars = 2;
  572. num_ele_vars = 3;
  573. num_nset_vars = 4;
  574. num_sset_vars = 7;
  575. truth_tab = (int *) calloc ((num_elem_blk * num_ele_vars), sizeof(int));
  576. nset_tab = (int *) calloc ((num_node_sets * num_nset_vars), sizeof(int));
  577. sset_tab = (int *) calloc ((num_side_sets * num_sset_vars), sizeof(int));
  578. k = 0;
  579. for (i=0; i<num_elem_blk; i++) {
  580. for (j=0; j<num_ele_vars; j++) {
  581. truth_tab[k++] = 1;
  582. }
  583. }
  584. k = 0;
  585. for (i=0; i<num_node_sets; i++) {
  586. for (j=0; j<num_nset_vars; j++) {
  587. if (k%2 == 0)
  588. nset_tab[k++] = 1;
  589. else
  590. nset_tab[k++] = 0;
  591. }
  592. }
  593. k = 0;
  594. for (i=0; i<num_side_sets; i++) {
  595. for (j=0; j<num_sset_vars; j++) {
  596. if (k%2 == 0)
  597. sset_tab[k++] = 0;
  598. else
  599. sset_tab[k++] = 1;
  600. }
  601. }
  602. ex_put_all_var_param(exoid, num_glo_vars, num_nod_vars, num_ele_vars, truth_tab,
  603. num_nset_vars, nset_tab, num_sset_vars, sset_tab);
  604. printf ("after ex_put_all_var_param, error = %d\n", error);
  605. if (error) {
  606. ex_close (exoid);
  607. exit(-1);
  608. }
  609. free (truth_tab);
  610. free (nset_tab);
  611. free (sset_tab);
  612. var_names[0] = "glo_vars";
  613. error = ex_put_var_names (exoid, "g", num_glo_vars, var_names);
  614. printf ("after ex_put_var_names, error = %d\n", error);
  615. if (error) {
  616. ex_close (exoid);
  617. exit(-1);
  618. }
  619. /* 12345678901234567890123456789012 */
  620. var_names[0] = "node_variable_a_very_long_name_0";
  621. var_names[1] = "nod_var1";
  622. error = ex_put_var_names (exoid, "n", num_nod_vars, var_names);
  623. printf ("after ex_put_var_names, error = %d\n", error);
  624. if (error) {
  625. ex_close (exoid);
  626. exit(-1);
  627. }
  628. var_names[0] = "ele_var0";
  629. var_names[1] = "ele_var1";
  630. var_names[2] = "ele_var2";
  631. error = ex_put_var_names (exoid, "e", num_ele_vars, var_names);
  632. printf ("after ex_put_var_names, error = %d\n", error);
  633. if (error) {
  634. ex_close (exoid);
  635. exit(-1);
  636. }
  637. var_names[0] = "nset_var0";
  638. var_names[1] = "nset_var1";
  639. var_names[2] = "nset_var2";
  640. var_names[3] = "nset_var3";
  641. error = ex_put_var_names (exoid, "m", num_nset_vars, var_names);
  642. printf ("after ex_put_var_names, error = %d\n", error);
  643. if (error) {
  644. ex_close (exoid);
  645. exit(-1);
  646. }
  647. var_names[0] = "sset_var0";
  648. var_names[1] = "sset_var1";
  649. var_names[2] = "sset_var2";
  650. var_names[3] = "sset_var3";
  651. var_names[4] = "sset_var4";
  652. var_names[5] = "sset_var5";
  653. var_names[6] = "sset_var6";
  654. error = ex_put_var_names (exoid, "s", num_sset_vars, var_names);
  655. printf ("after ex_put_var_names, error = %d\n", error);
  656. if (error) {
  657. ex_close (exoid);
  658. exit(-1);
  659. }
  660. /* for each time step, write the analysis results;
  661. * the code below fills the arrays glob_var_vals,
  662. * nodal_var_vals, and elem_var_vals with values for debugging purposes;
  663. * obviously the analysis code will populate these arrays
  664. */
  665. whole_time_step = 1;
  666. num_time_steps = 10;
  667. glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size);
  668. nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size);
  669. elem_var_vals = (float *) calloc (4, CPU_word_size);
  670. nset_var_vals = (float *) calloc (5, CPU_word_size);
  671. sset_var_vals = (float *) calloc (10, CPU_word_size);
  672. for (i=0; i<num_time_steps; i++)
  673. {
  674. time_value = (float)(i+1)/100.;
  675. /* write time value */
  676. error = ex_put_time (exoid, whole_time_step, &time_value);
  677. printf ("after ex_put_time, error = %d\n", error);
  678. if (error) {
  679. ex_close (exoid);
  680. exit(-1);
  681. }
  682. /* write global variables */
  683. for (j=0; j<num_glo_vars; j++) {
  684. glob_var_vals[j] = (float)(j+2) * time_value;
  685. }
  686. error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars,
  687. glob_var_vals);
  688. printf ("after ex_put_glob_vars, error = %d\n", error);
  689. if (error) {
  690. ex_close (exoid);
  691. exit(-1);
  692. }
  693. /* write nodal variables */
  694. for (k=1; k<=num_nod_vars; k++) {
  695. for (j=0; j<num_nodes; j++) {
  696. nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value);
  697. }
  698. error = ex_put_nodal_var (exoid, whole_time_step, k, num_nodes,
  699. nodal_var_vals);
  700. printf ("after ex_put_nodal_var, error = %d\n", error);
  701. if (error) {
  702. ex_close (exoid);
  703. exit(-1);
  704. }
  705. }
  706. /* write element variables */
  707. for (k=1; k<=num_ele_vars; k++) {
  708. for (j=0; j<num_elem_blk; j++) {
  709. for (m=0; m<num_elem_in_block[j]; m++) {
  710. elem_var_vals[m] = (float)(k+1) + (float)(j+2) +
  711. ((float)(m+1)*time_value);
  712. }
  713. error = ex_put_elem_var (exoid, whole_time_step, k, ebids[j],
  714. num_elem_in_block[j], elem_var_vals);
  715. printf ("after ex_put_elem_var, error = %d\n", error);
  716. if (error) {
  717. ex_close (exoid);
  718. exit(-1);
  719. }
  720. }
  721. }
  722. /* write nodeset variables */
  723. kk = 0;
  724. for (j=0; j<num_node_sets; j++) {
  725. for (k=0; k<num_nset_vars; k++) {
  726. if (kk++ % 2 == 0) {
  727. for (m=0; m<num_nodes_per_set[j]; m++) {
  728. nset_var_vals[m] = (float)(k+1) + (float)(j+2) +
  729. ((float)(m+1)*time_value);
  730. }
  731. error = ex_put_nset_var (exoid, whole_time_step, k+1, nsids[j],
  732. num_nodes_per_set[j], nset_var_vals);
  733. printf ("after ex_put_nset_var, error = %d\n", error);
  734. if (error) {
  735. ex_close (exoid);
  736. exit(-1);
  737. }
  738. }
  739. }
  740. }
  741. /* write sideset variables */
  742. kk = 0;
  743. for (j=0; j<num_side_sets; j++) {
  744. for (k=0; k<num_sset_vars; k++) {
  745. if (kk++ % 2 != 0) {
  746. for (m=0; m<num_elem_per_set[j]; m++) {
  747. sset_var_vals[m] = (float)(k+1) + (float)(j+2) +
  748. ((float)(m+1)*time_value);
  749. }
  750. error = ex_put_sset_var (exoid, whole_time_step, k+1, ssids[j],
  751. num_elem_per_set[j], sset_var_vals);
  752. printf ("after ex_put_sset_var, error = %d\n", error);
  753. if (error) {
  754. ex_close (exoid);
  755. exit(-1);
  756. }
  757. }
  758. }
  759. }
  760. whole_time_step++;
  761. /* update the data file; this should be done at the end of every time step
  762. * to ensure that no data is lost if the analysis dies
  763. */
  764. error = ex_update (exoid);
  765. printf ("after ex_update, error = %d\n", error);
  766. if (error) {
  767. ex_close (exoid);
  768. exit(-1);
  769. }
  770. }
  771. free(glob_var_vals);
  772. free(nodal_var_vals);
  773. free(elem_var_vals);
  774. free(nset_var_vals);
  775. free(sset_var_vals);
  776. /* close the EXODUS files
  777. */
  778. error = ex_close (exoid);
  779. printf ("after ex_close, error = %d\n", error);
  780. if (error) {
  781. ex_close (exoid);
  782. exit(-1);
  783. }
  784. return 0;
  785. }