-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrixi_controller_data.c
72 lines (54 loc) · 2.05 KB
/
trixi_controller_data.c
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
#include <stdio.h>
#include <stdlib.h>
#include <trixi.h>
int main ( int argc, char *argv[] ) {
if ( argc < 2 ) {
fprintf(stderr, "ERROR: missing arguments: PROJECT_DIR LIBELIXIR_PATH\n\n");
fprintf(stderr, "usage: %s PROJECT_DIR LIBELIXIR_PATH\n", argv[0]);
return 2;
} else if ( argc < 3 ) {
fprintf(stderr, "ERROR: missing argument: LIBELIXIR_PATH\n\n");
fprintf(stderr, "usage: %s PROJECT_DIR LIBELIXIR_PATH\n", argv[0]);
return 2;
}
// Initialize Trixi
printf("\n*** Trixi controller *** Initialize Trixi\n");
trixi_initialize( argv[1], NULL );
// Set up the Trixi simulation
// We get a handle to use subsequently
printf("\n*** Trixi controller *** Set up Trixi simulation\n");
int handle = trixi_initialize_simulation( argv[2] );
// Get number of variables
int nvariables = trixi_nvariables( handle );
printf("\n*** Trixi controller *** nvariables %d\n", nvariables);
// Main loop
int steps = 0;
int nelements = 0;
double* data = NULL;
printf("\n*** Trixi controller *** Entering main loop\n");
while ( !trixi_is_finished( handle ) ) {
trixi_step( handle );
steps++;
if (steps % 10 == 0) {
// Get number of elements
nelements = trixi_nelements( handle );
printf("\n*** Trixi controller *** nelements %d\n", nelements);
// Allocate memory
data = realloc( data, sizeof(double) * nelements );
// Get element averaged values for first variable
trixi_load_element_averaged_primitive_vars(handle, 1, data);
}
}
// Print first variable
for (int i = 0; i < nelements; ++i) {
printf("u[element %3d] = %f\n", i, data[i]);
}
// Finalize Trixi simulation
printf("\n*** Trixi controller *** Finalize Trixi simulation\n");
trixi_finalize_simulation( handle );
// Finalize Trixi
printf("\n*** Trixi controller *** Finalize Trixi\n");
trixi_finalize();
free(data);
return 0;
}