Neko 1.99.7
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
cylinder.c
Go to the documentation of this file.
1#include <string.h>
2#include <jansson.h>
3#include <neko.h>
4
5/*
6 * Helper to compare a callback's scheme name, which is not null-terminated
7 */
8static int scheme_name_is(const char *scheme_name, int scheme_name_len,
9 const char *name) {
10 return ((scheme_name_len == (int) strlen(name)) &&
11 (strncmp(scheme_name, name, scheme_name_len) == 0));
12}
13
14/* Define initial conditions */
15static void initial(const char *scheme_name, int scheme_name_len) {
16
17 /*
18 * In this case the check is redundant, but if both fluid and scalar
19 * initial conditions should be defined, `scheme_name` can be used
20 * to identify which solver has called the callback
21 */
22 if (scheme_name_is(scheme_name, scheme_name_len, "fluid")) {
23
24 /*
25 * To retrive a pointer to the data in a field from Neko's field
26 * registry use neko_field()
27 */
28 neko_real *u = neko_field("u");
29 int n = neko_field_size("u");
30
31 for (int i = 0; i < n; i++) {
32 u[i] = 1.0;
33 }
34 }
35}
36
37/* Define inflow conditions */
38static void inflow(int *msk, int msk_size, neko_real t, int tstep) {
39 int idx = 1; /* Note: Fortran indices */
40
41 /*
42 * In this case this check is redundant, but if different user provided
43 * boundary conditions share the same callback, one could use the content
44 * of the callback's field list to identify which condition should be
45 * applied, for example a velocity condition passes the fields (u, v, w)
46 */
47 if (neko_cb_field_name_at_index(&idx, "u")) {
48
49 /*
50 * Inside a callback, the fields passed to it are retrived with
51 * neko_cb_field_by_name() rather than from the field registry
52 */
56
57 for (int i = 0; i < msk_size; i++) {
58 int j = msk[i] - 1; /* Neko's mask is based on Fortran indices */
59 u[j] = 1.0;
60 v[j] = 0.0;
61 w[j] = 0.0;
62 }
63 }
64}
65
66int main(int argc, char **argv) {
67
68 /* Initialise Neko */
69 neko_init();
71
72 /* Create a Neko case from a JSON file */
73 json_error_t json_error;
74 const char *case_json = json_dumps(json_load_file("cylinder.case", 0,
75 &json_error), JSON_COMPACT);
76 int *neko_case = NULL;
77
78 /*
79 * To provide user callbacks, the case must be allocated before it is
80 * initialised, such that the callbacks are registered before the case
81 * resolves the "user" entries in the JSON object. Unused callbacks are
82 * left undefined by passing a null pointer.
83 */
84 neko_case_allocate(&neko_case);
85 neko_user_setup(&neko_case, initial, NULL, NULL, inflow, NULL, NULL);
86
87 neko_case_init(&case_json, strlen(case_json), &neko_case);
88
89 /* To solve the entire case we can call neko_solve() */
90 /* neko_solve(&neko_case); */
91
92 /* To manually step forward in time, call neko_step() */
93 while (neko_case_time(&neko_case) < neko_case_end_time(&neko_case)) {
94 neko_step(&neko_case);
95 }
96
97 /*
98 * To retrive a pointer to the data in a field from Neko's field
99 * registry use neko_field()
100 */
101 neko_real *u = neko_field("u");
102
103 /* Cleanup */
104 neko_case_free(&neko_case);
106}
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w
const int i
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ u
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
const int j
static void initial(const char *scheme_name, int scheme_name_len)
Definition cylinder.c:15
int main(int argc, char **argv)
Definition cylinder.c:66
static int scheme_name_is(const char *scheme_name, int scheme_name_len, const char *name)
Definition cylinder.c:8
Defines inflow dirichlet conditions.
Definition inflow.f90:34
void neko_step(int **case_iptr)
double neko_real
Definition neko.h:10
void neko_finalize()
void neko_case_init(const char **case_json, int case_len, int **case_iptr)
void neko_case_allocate(int **case_iptr)
void neko_init()
void neko_job_info()
int neko_field_size(char *field_name)
void neko_case_free(int **case_iptr)
neko_real * neko_field(char *field_name)
double neko_case_end_time(int **case_iptr)
double neko_case_time(int **case_iptr)
neko_real * neko_cb_field_by_name(char *field_name)
int neko_cb_field_name_at_index(int *field_idx, char *field_name)
void neko_user_setup(int **case_iptr, neko_initial_condition_cb initial_cb, neko_preprocess_cb preprocess_cb, neko_compute_cb compute_cb, neko_dirichlet_condition_cb dirichlet_cb, neko_material_properties_cb material_cb, neko_source_term_cb source_cb)