forked from csdms/bmi-example-cxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_set_value.cxx
82 lines (59 loc) · 1.65 KB
/
test_set_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
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <heat.hxx>
#include <bmi.hxx>
#include <bmi_heat.hxx>
void print_matrix (double *m, int n_dims, int * shape);
int
main (void)
{
int i;
const int n_steps = 10;
BmiHeat model;
double *new_vals = NULL;
int *shape = NULL;
int size;
std::string name;
int rank;
int grid;
model.Initialize("config.txt");
name = model.GetComponentName();
std::cout << name << std::endl;
grid = model.GetVarGrid("plate_surface__temperature");
rank = model.GetGridRank(grid);
shape = new int[rank];
model.GetGridShape(grid, shape);
new_vals = (double *)model.GetValuePtr("plate_surface__temperature");
fprintf (stdout, "Values before set\n");
fprintf (stdout, "=================\n");
print_matrix (new_vals, rank, shape);
new_vals[0] = -1;
size = model.GetGridSize(grid);
new_vals = new double[size];
model.GetValue("plate_surface__temperature", new_vals);
print_matrix (new_vals, rank, shape);
new_vals[0] = 1.;
model.SetValue("plate_surface__temperature", new_vals);
fprintf (stdout, "Values after set\n");
fprintf (stdout, "================\n");
print_matrix (new_vals, rank, shape);
delete shape;
delete new_vals;
model.Finalize ();
return EXIT_SUCCESS;
}
void
print_matrix (double *m, int n_dims, int * shape)
{
int i, j;
fprintf (stdout, "Number of dimension: %d\n", n_dims);
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 ", m[i*shape[1]+j]);
fprintf (stdout, "\n");
}
}