-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtrixi_controller_data_store.c
More file actions
95 lines (71 loc) · 2.87 KB
/
Copy pathtrixi_controller_data_store.c
File metadata and controls
95 lines (71 loc) · 2.87 KB
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
#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] );
// Main loop
int steps = 0;
double* rho = NULL;
double* rho_tracer = NULL;
printf("\n*** Trixi controller *** Entering main loop\n");
while ( !trixi_is_finished( handle ) ) {
trixi_step( handle );
steps++;
if (steps % 100 == 0) {
// Get number of degrees of freedom
int ndofs = trixi_ndofsglobal( handle );
// Get a pointer to Trixi's internal simulation data
double * raw_data = trixi_get_conservative_vars_pointer(handle);
for (int i = 0; i < ndofs; ++i) {
// Density comes first
const double rho = raw_data[5*i];
// Tracer comes last
const double rho_tracer = raw_data[5*i + 4];
// Apply 10% damping to tracer (fraction of density)
const double tracer = 0.9 * (rho_tracer / rho);
raw_data[5*i + 4] = tracer * rho;
}
}
if (steps % 100 == 50) {
// Get number of degrees of freedom
int ndofs = trixi_ndofsglobal( handle );
// Allocate memory
rho = realloc( rho, sizeof(double) * ndofs );
rho_tracer = realloc( rho_tracer, sizeof(double) * ndofs );
// Get density and tracer
trixi_load_conservative_var(handle, 1, rho);
trixi_load_conservative_var(handle, 5, rho_tracer);
for (int i = 0; i < ndofs; ++i) {
// Apply 5% amplification to tracer (fraction of density)
const double tracer = 1.05 * (rho_tracer[i] / rho[i]);
rho_tracer[i] = tracer * rho[i];
}
// Write back tracer
trixi_store_conservative_var(handle, 5, rho_tracer);
}
}
// 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(rho);
free(rho_tracer);
return 0;
}