Neko 1.99.2
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
cylinder.jl
Go to the documentation of this file.
1using Neko
2using JSON
3
4Neko.init()
5Neko.job_info()
6
7cylinder_json = JSON.parsefile("cylinder.case")
8
9# Define initial conditions
10function initial_condition(scheme_name::Ptr{Cchar}, len::Cint)::Cvoid
11
12 # In this case the check is redudnant, but if both fluid and scalar
13 # initial conditions should be defined, `scheme_name` can be used
14 # to identifiy which solver has called the callback
15 if (unsafe_string(scheme_name) == "fluid")
16 # To retrive a Julia struct, with wrapped arrays of the data in a field
17 # from Neko's field registry use field()
18 u = Neko.field("u")
19 nelm = Neko.field_nelements("u")
20 lx = u.Xh.lx
21
22 for e in 1:nelm
23 for k in 1:lx
24 for j in 1:lx
25 for i in 1:lx
26 u.x[i,j,k,e] = 1.0
27 end
28 end
29 end
30 end
31 end
32
33 return nothing
34end;
35
36# Define inflow conditions
37function inflow(msk::Ptr{Cint}, msk_size::Cint,
38 t::Cdouble, tstep::Cint)::Cvoid
39
40 bc_msk = Neko.bc_mask(msk, msk_size)
41
42 # In this case this check is redudant, but if different user provied
43 # boundary conditions share the same callback, one could use the content
44 # of the callbacks field list to identify which condition should be applied,
45 # for example a velocity condition passes the fields (u, v, w)
46 if (Neko.callback_field_name(1, "u"))
47 u = Neko.callback_field("u")
48 v = Neko.callback_field("v")
49 w = Neko.callback_field("w")
50 lx = u.Xh.lx
51
52 for i in 1:msk_size
53 # Compute the (i,j,k,e) index given the linear index in bc_msk
54 idx = Neko.nonlinear_index(bc_msk[i], lx, lx, lx)
55 u.x[idx] = 1.0
56 v.x[idx] = 0.0
57 w.x[idx] = 0.0
58 end
59 end
60
61 return nothing
62end;
63
64# Create a Neko callback for the initial and inflow conditions
65const cb_initial = @Neko.initial_condition(initial_condition)
66const cb_inflow = @Neko.dirichlet_condition(inflow)
67
68# Create a Neko case from a JSON file and provied (optional) callbacks
69cylinder_case = Neko.case_init(cylinder_json,
70 cb_initial_condition = cb_initial,
71 cb_dirichlet_condition = cb_inflow)
72
73# To solve the entire case we can call solve()
74#Neko.solve(cylinder_case)
75
76# To manually step forward in time, call step()
77while Neko.time(cylinder_case) < Neko.end_time(cylinder_case)
78 Neko.step(cylinder_case)
79end
80
81# Cleanup
82Neko.case_free(cylinder_case)
83Neko.finalize()