Neko 1.99.2
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
cylinder.py
Go to the documentation of this file.
1import pyneko
2import json
3import ctypes
4
5# Initialise Neko
6pyneko.init()
7pyneko.job_info()
8
9
10cylinder_json = json.load(open('cylinder.case'))
11
12# Define initial conditions
13def initial(name, len):
14 scheme_name = ctypes.string_at(name, len).decode()
15
16 # In this case the check is redudnant, but if both fluid and scalar
17 # initial conditions should be defined, `scheme_name` can be used
18 # to identifiy which solver has called the callback
19 if (scheme_name == "fluid"):
20 # To retrive a dataclass representation of a field with a numpy array
21 # of the data in a field from Neko's field registry use field()
22 u = pyneko.field(b'u')
23 for i in range(0, u.dm.ntot):
24 u.x[i] = 1.0
25
26# Define inflow conditions
27def inflow(msk, msk_size, t, tstep):
28 bc_mask = pyneko.bc_mask(msk, msk_size)
29
30 # In this case this check is redudant, but if different user provied
31 # boundary conditions share the same callback, one could use the content
32 # of the callbacks field list to identify which condition should be applied,
33 # for example a velocity condition passes the fields (u, v, w)
34 if (pyneko.callback_field_name(1, b'u')): # Note: Fortran indices
35 u = pyneko.callback_field(b'u')
36 v = pyneko.callback_field(b'v')
37 w = pyneko.callback_field(b'w')
38 for i in range(0, msk_size):
39 idx = bc_mask[i] - 1 # Neko's mask is based on Fortran indices
40 u.x[idx] = 1.0
41 v.x[idx] = 0.0
42 w.x[idx] = 0.0
43
44# Create a Neko callback for the initial and inflow conditions
45cb_cylinder_ic = pyneko.initial_condition(initial)
46cb_cylinder_if = pyneko.dirichlet_condition(inflow)
47
48# Create a Neko case from a JSON file and provied (optional) callbacks
49cylinder_case = pyneko.case_init(cylinder_json,
50 cb_initial_condition = cb_cylinder_ic,
51 cb_dirichlet_condition = cb_cylinder_if)
52
53# To solve the entire case we can call solve()
54#pyneko.solve(cylinder_case)
55
56# To manually step forward in time, call step()
57while pyneko.time(cylinder_case) < pyneko.end_time(cylinder_case):
58 pyneko.step(cylinder_case)
59
60# Cleanup
61pyneko.case_free(cylinder_case)
62pyneko.finalize()
initial(name, len)
Definition cylinder.py:13
Defines inflow dirichlet conditions.
Definition inflow.f90:34