-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_get_value.cxx
122 lines (92 loc) · 2.4 KB
/
test_get_value.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <heat.hxx>
#include <bmi.hxx>
#include <bmi_heat.hxx>
void print_var_values(BmiHeat model, const char *var_name);
void print_var_column(BmiHeat model, const char *var_name, int colno);
int
main (void)
{
int i;
const int n_steps = 10;
BmiHeat model;
int size;
std::string name;
int rank;
model.Initialize("");
name = model.GetComponentName();
std::cout << name << std::endl;
for (i = 0; i<n_steps; i++)
{
fprintf (stdout, "Values at time %d\n", i);
fprintf (stdout, "==============\n");
print_var_values(model, "plate_surface__temperature");
model.UpdateUntil(i);
}
fprintf(stdout, "Values at time %d\n", i);
fprintf(stdout, "==============\n");
print_var_values(model, "plate_surface__temperature");
model.Finalize();
return EXIT_SUCCESS;
}
void
print_var_column(BmiHeat model, const char *name, int colno)
{
int grid;
int * shape;
int rank;
grid = model.GetVarGrid(name);
rank = model.GetGridRank(grid);
shape = new int[rank];
model.GetGridShape(grid, shape);
{
int * inds = (int*)malloc(sizeof(int)*shape[0]);
double * col = NULL;
inds[0] = colno;
for (int i=1; i<shape[0]; i++)
inds[i] = inds[i-1] + shape[1];
col = new double[shape[0]];
model.GetValueAtIndices(name, col, inds, shape[0]);
fprintf (stdout, "Column %d: ", colno);
for (int i=0; i<shape[0]; i++)
fprintf (stdout, "%f ", col[i]);
fprintf (stdout, "\n");
free(col);
free(inds);
}
delete shape;
return;
}
void
print_var_values(BmiHeat model, const char *var_name)
{
double *var = NULL;
int i, j;
int grid;
int * shape;
int rank;
int size;
grid = model.GetVarGrid(var_name);
rank = model.GetGridRank(grid);
size = model.GetGridSize(grid);
shape = new int[rank];
model.GetGridShape(grid, shape);
var = new double[size];
model.GetValue(var_name, var);
fprintf (stdout, "Variable: %s\n", var_name);
fprintf (stdout, "Number of dimension: %d\n", rank);
fprintf (stdout, "Shape: %d x %d\n", shape[0], shape[1]);
fprintf (stdout, "================\n");
for (i=0; i<shape[0]; i++) {
for (j=0; j<shape[1]; j++)
fprintf (stdout, "%f ", var[i * shape[1] + j]);
fprintf (stdout, "\n");
}
print_var_column(model, var_name, 1);
print_var_column(model, var_name, shape[1] - 2);
delete shape;
return;
}