Quellcode zum Kopieren der Geometrie in die AVS - Struktur:
#include <stdio.h>
#include <string.h>
#include <avs/avs.h>
#include <avs/port.h>
#include <avs/geom.h>
#include <avs/ucd_defs.h>
#include <avs/field.h>
#include <math.h>
/* Socket includes */
#include <portal/sockets.h>
#include <portal/datasock.h>
#include <portal/AVSinit.h>
#include "AVSinterface.h"
#define NUM_CELL_TYPES 8
extern char *AVSstatic;
/*-----------------------------------------------------*
* *
* **** add_cell **** *
* *
*-----------------------------------------------------*/
/* Einfuegen eines Elementes in die Struktur*/
add_cell(model, cell, ucd_cell_type, n, rnode_list, mat_id)
int cell, ucd_cell_type, n, *rnode_list, mat_id;
UCD_structure **model;
{
static char *cell_type[] = {"pt", "line", "tri", "quad", "tet",
"pyr", "prism", "hex"};
int i, j, num_me_nodes, num_nodes, cell_found, me_flag,
node_list[40];
if (ucd_cell_type < NUM_CELL_TYPES) {
me_flag = 0;
num_nodes = UCD_num_nodes[ucd_cell_type];
for (i = 0; i < num_nodes; i++)
node_list[i] = rnode_list[i] - 1;
if (n != num_nodes) {
for (i = num_nodes, num_me_nodes = 0; i < n; i++)
if (rnode_list[i] != 0) {
node_list[num_nodes + num_me_nodes] =
rnode_list[i] - 1;
me_flag = me_flag | (0x1 <<
(i - num_nodes));
num_me_nodes++;
}
}
UCDcell_set_information(*model, cell, cell + 1,
cell_type[ucd_cell_type], mat_id - 1, ucd_cell_type,
me_flag, node_list);
}
}
/*-----------------------------------------------------*
* *
* **** copy_DS_UCD_data **** *
* *
*-----------------------------------------------------*/
/* Kopieren der Geometrie in die Struktur */
int
copy_DS_UCD_data(UCD_structure ** output, void *from, long int type, int size,
int secondtime)
{
/* Definition der Strukturen */
typedef struct _ctype_struct {
int id, mat, n, cell_type;
} Ctype;
typedef struct _ntype_struct {
int n, node_list[20];
} Ntype;
typedef struct _model_stats {
char node_data_labels[100], cell_data_labels[100],
model_data_labels[100], node_data_units[100],
cell_data_units[100], model_data_units[100];
int num_nodes, num_cells, num_node_data,
num_cell_data, num_model_data, node_active_list[20],
cell_active_list[20], model_active_list[20],
num_node_comp, node_comp_list[20],
num_cell_comp, cell_comp_list[20], num_model_comp,
model_comp_list[20], num_nlist_nodes;
} Mtype;
typedef struct _ucd_stats {
int size;
} Ucd_Stats_Type;
/* Variablendeklaration */
char string[40], tmp_str[80], file_name[80], model_name[20];
DS_UCD *temp = (DS_UCD *) from;
int i, num_nodes, num_cells, num_node_data, num_cell_data,
num_model_data, cell_tsize, node_csize, ucd_flags,
node, cell, util_flag;
float x, y, z, *data, xmin = 0.0, xmax = 0.0, ymin = 0.0,
ymax = 0.0, zmin = 0.0, zmax = 0.0, min_extent[3],
max_extent[3];
float *xc, *yc, *zc, *node_data, *cell_data, *model_data,
*max_node_data, *min_cell_data, *max_cell_data,
*min_model_data, *max_model_data, *min_node_data;
Ntype *cell_nlists;
Ctype *cells;
static char *cell_type[] = {"pt", "line", "tri", "quad", "tet",
"pyr", "prism", "hex"};
Mtype model_stats;
float *data_real;
Ucd_Stats_Type *ucd_stats;
static int clist[] = {1, 2, 3, 4};
cell_nlists = NULL;
if (AVSstatic == NULL) {
ucd_stats = (Ucd_Stats_Type *) malloc(sizeof(Ucd_Stats_Type));
AVSstatic = (char *) ucd_stats;
} else
ucd_stats = (Ucd_Stats_Type *) AVSstatic;
/* Allgemeine Beschreibung */
model_stats.num_nodes = temp->num_nodes;
model_stats.num_cells = temp->num_cells;
model_stats.num_node_data = temp->num_node_data;
model_stats.num_cell_data = temp->num_cell_data;
model_stats.num_model_data = temp->num_model_data;
/* alloc der Felder fuer Koordinaten (xc,yc,zc) und der Elemente
(cells, cell_nlists) */
cells = (Ctype *) malloc(sizeof(Ctype) * model_stats.num_cells);
cell_nlists = (Ntype *) malloc(sizeof(Ntype) * model_stats.num_cells);
xc = (float *) malloc(sizeof(float) * model_stats.num_nodes);
yc = (float *) malloc(sizeof(float) * model_stats.num_nodes);
zc = (float *) malloc(sizeof(float) * model_stats.num_nodes);
/* Lesen der Knotenkoordinaten aus temp->data_ptr */
data_real = (float *) (temp->data_ptr);
for (i = 0; i < model_stats.num_nodes; i++)
xc[i] = *data_real++;
xmin = *data_real++;
xmax = *data_real++;
for (i = 0; i < model_stats.num_nodes; i++)
yc[i] = *data_real++;
ymin = *data_real++;
ymax = *data_real++;
for (i = 0; i < model_stats.num_nodes; i++)
zc[i] = *data_real++;
zmin = *data_real++;
zmax = *data_real++;
/* Lesen der Elementdaten (nur Elemente vom Typ tri) aus
temp->data_ptr */
model_stats.num_nlist_nodes = 0;
for (i = 0; i < model_stats.num_cells; i++) {
cells[i].cell_type = 2;
cells[i].id = 1;
cells[i].mat = 1;
cell_nlists[i].node_list[0] = (int) *data_real++;
cell_nlists[i].node_list[1] = (int) *data_real++;
cell_nlists[i].node_list[2] = (int) *data_real++;
cell_nlists[i].n = 3;
cells[i].n = 3;
model_stats.num_nlist_nodes = model_stats.
num_nlist_nodes + 3;
}
/* Lesen der Knotenwerte aus temp->data_ptr */
model_stats.node_active_list[0] = 1;
strcpy(model_stats.node_data_labels, "hoehen");
strcpy(model_stats.node_data_units, "lb/in**2");
strcpy(string, "hoehen, lb/in**2");
model_stats.node_comp_list[0] = 1;
model_stats.node_comp_list[1] = 0;
model_stats.num_node_comp = 1;
for (i = 1; i < model_stats.num_node_comp; i++)
model_stats.node_active_list[i] = 0;
node_data = (float *) malloc(sizeof(float) *
model_stats.num_nodes * model_stats.num_node_data);
min_node_data = (float *) malloc(sizeof(float) *
model_stats.num_node_data);
max_node_data = (float *) malloc(sizeof(float) *
model_stats.num_node_data);
for (i = 0; i < model_stats.num_nodes; i++) {
node_data[i] = *data_real++;
}
xmin = xmax = node_data[0];
for (i = 1; i < model_stats.num_nodes; i++) {
min_node_data[0] = (node_data[i] < min_node_data[0]
? node_data[i] : min_node_data[0]),
max_node_data[0] = (node_data[i] > max_node_data[0]
? node_data[i] : max_node_data[0]);
}
for (i = 1; i < model_stats.num_node_comp; i++)
model_stats.node_active_list[i] = 0;
/* Kopieren der Daten nach AVS */
util_flag = 0;
num_nodes = model_stats.num_nodes;
num_cells = model_stats.num_cells;
num_node_data = model_stats.num_node_data;
num_cell_data = model_stats.num_cell_data;
num_model_data = model_stats.num_model_data;
cell_tsize = node_csize = model_stats.num_nlist_nodes;
ucd_stats->size = cell_tsize;
ucd_flags = UCD_INT | UCD_MATERIAL_IDS | UCD_NODE_NAMES |
UCD_CELL_NAMES | UCD_CELL_TYPES | UCD_MID_EDGES;
strcpy(model_name, "ucd_bild");
if (secondtime == 0)
*output = (UCD_structure *) UCDstructure_alloc
(model_name, num_model_data, ucd_flags,
num_cells, cell_tsize,num_cell_data,
num_nodes, node_csize, num_node_data,
util_flag);
/* Knotenwerte */
for (node = 0; node < num_nodes; node++) {
x = xc[node], y = yc[node], z = zc[node];
if (node) {
xmin = (x < xmin ? x : xmin),
xmax = (x > xmax ? x : xmax);
ymin = (y < ymin ? y : ymin),
ymax = (y > ymax ? y : ymax);
zmin = (z < zmin ? z : zmin),
zmax = (z > zmax ? z : zmax);
} else {
xmin = xmax = x;
ymin = ymax = y;
zmin = zmax = z;
}
if (!UCDnode_set_information(*output, node,
node + 1, 0, clist)) {
AVSerror("Error in read_ucd:
can't set node %d info.\n", node);
return (0);
}
}
UCDstructure_set_node_positions(*output, xc, yc, zc);
/* Extremalwerte */
min_extent[0] = xmin, min_extent[1] = ymin,
min_extent[2] = zmin;
max_extent[0] = xmax, max_extent[1] = ymax,
max_extent[2] = zmax;
UCDstructure_set_extent(*output, min_extent, max_extent);
/* Elemente */
for (cell = 0; cell < num_cells; cell++) {
add_cell(output, cell, cells[cell].cell_type,
cell_nlists[cell].n, cell_nlists[cell].node_list,
cells[cell].mat);
}
/* Ergebnisdaten fuer Knoten, Elemente, Geometrie */
if (num_node_data) {
UCDstructure_set_node_components(*output,
model_stats.node_comp_list, model_stats.num_node_comp);
UCDstructure_set_node_active(*output,
model_stats.node_active_list);
UCDstructure_set_node_labels(*output,
model_stats.node_data_labels, ".");
UCDstructure_set_node_units(*output,
model_stats.node_data_units, ".");
if (model_stats.num_node_comp > 1) {
for (i = 0; model_stats.node_data_labels[i] != '.'; i++)
string[i] = model_stats.node_data_labels[i];
string[i] = '\0';
} else
strcpy(string, model_stats.node_data_labels);
UCDstructure_set_node_minmax(*output, min_node_data, max_node_data);
if (!UCDstructure_set_node_data(*output, node_data)) {
AVSerror("Error in read_ucd: can't set node data.\n");
return (0);
}
}
free(xc);
free(yc);
free(zc);
if (num_node_data) {
free(node_data);
free(min_node_data);
free(max_node_data);
}
if (num_cell_data) {
free(cell_data);
free(min_cell_data);
free(max_cell_data);
}
if (num_model_data) {
free(model_data);
free(min_model_data);
free(max_model_data);
}
free(cells);
if (cell_nlists)
free(cell_nlists);
free(ucd_stats);
}