17from dataclasses
import dataclass
21initial_condition = CFUNCTYPE(
None, POINTER(c_char_p), c_int)
23preprocess = CFUNCTYPE(
None, c_double, c_int)
25compute = CFUNCTYPE(
None, c_double, c_int)
27dirichlet_condition = CFUNCTYPE(
None, POINTER(c_int), c_int, c_double, c_int)
29material_properties = CFUNCTYPE(
None, POINTER(c_char_p), c_int, c_double, c_int)
31source_term = CFUNCTYPE(
None, POINTER(c_char_p), c_int, c_double, c_int)
33libneko = CDLL(util.find_library(
"neko"))
35libneko.neko_init.resType =
None
36libneko.neko_finalize.resType =
None
37libneko.neko_job_info.resType =
None
39libneko.neko_device_init.restype =
None
40libneko.neko_device_finalize.restype =
None
42libneko.neko_registry_init.restype =
None
43libneko.neko_registry_free.restype =
None
46libneko.neko_case_allocate.argtypes = [POINTER(c_int)]
47libneko.neko_case_allocate.restype =
None
49libneko.neko_case_init.argtypes = [POINTER(c_char_p), c_int, POINTER(c_int)]
50libneko.neko_case_init.restype = c_int
52libneko.neko_case_free.argtypes = [POINTER(c_int)]
53libneko.neko_case_free.restype =
None
55libneko.neko_case_time.argtypes = [POINTER(c_int)]
56libneko.neko_case_time.restype = c_double
58libneko.neko_case_end_time.argtypes = [POINTER(c_int)]
59libneko.neko_case_end_time.restype = c_double
61libneko.neko_case_tstep.argtypes = [POINTER(c_int)]
62libneko.neko_case_tstep.restype = c_int
64libneko.neko_case_is_done.argtypes = [POINTER(c_int)]
65libneko.neko_case_is_done.restype = c_int
67libneko.neko_solve.argtypes = [POINTER(c_int)]
68libneko.neko_solve.restype =
None
70libneko.neko_step.argtypes = [POINTER(c_int)]
71libneko.neko_step.restype =
None
73libneko.neko_field.argtypes = [c_char_p]
74libneko.neko_field.restype = POINTER(c_double)
76libneko.neko_field_order.argtypes = [c_char_p]
77libneko.neko_field_order.restype = c_int
79libneko.neko_field_nelements.argtypes = [c_char_p]
80libneko.neko_field_nelements.restype = c_int
82libneko.neko_field_size.argtypes = [c_char_p]
83libneko.neko_field_size.restype = c_int
85libneko.neko_field_dofmap.argtypes = [c_char_p,
86 POINTER(POINTER(c_longlong)),
87 POINTER(POINTER(c_double)),
88 POINTER(POINTER(c_double)),
89 POINTER(POINTER(c_double))]
90libneko.neko_field_dofmap.restype =
None
92libneko.neko_case_fluid_dofmap.argtypes = [POINTER(c_int),
93 POINTER(POINTER(c_longlong)),
94 POINTER(POINTER(c_double)),
95 POINTER(POINTER(c_double)),
96 POINTER(POINTER(c_double)),
98libneko.neko_case_fluid_dofmap.restype =
None
100libneko.neko_field_space.argtypes = [c_char_p,
102 POINTER(POINTER(c_double)),
103 POINTER(POINTER(c_double)),
104 POINTER(POINTER(c_double)),
105 POINTER(POINTER(c_double)),
106 POINTER(POINTER(c_double)),
107 POINTER(POINTER(c_double)),
108 POINTER(POINTER(c_double)),
109 POINTER(POINTER(c_double)),
110 POINTER(POINTER(c_double)),
111 POINTER(POINTER(c_double))]
112libneko.neko_field_space.restype =
None
114libneko.neko_case_fluid_space.argtypes = [POINTER(c_int),
116 POINTER(POINTER(c_double)),
117 POINTER(POINTER(c_double)),
118 POINTER(POINTER(c_double)),
119 POINTER(POINTER(c_double)),
120 POINTER(POINTER(c_double)),
121 POINTER(POINTER(c_double)),
122 POINTER(POINTER(c_double)),
123 POINTER(POINTER(c_double)),
124 POINTER(POINTER(c_double)),
125 POINTER(POINTER(c_double))]
126libneko.neko_case_fluid_space.restype =
None
128libneko.neko_case_fluid_coef.argtypes = [POINTER(c_int),
129 POINTER(POINTER(c_double)),
130 POINTER(POINTER(c_double)),
131 POINTER(POINTER(c_double)),
132 POINTER(POINTER(c_double)),
133 POINTER(POINTER(c_double)),
134 POINTER(POINTER(c_double)),
135 POINTER(POINTER(c_double)),
136 POINTER(POINTER(c_double)),
137 POINTER(POINTER(c_double)),
138 POINTER(POINTER(c_double)),
139 POINTER(POINTER(c_double)),
140 POINTER(POINTER(c_double)),
141 POINTER(POINTER(c_double)),
142 POINTER(POINTER(c_double)),
143 POINTER(POINTER(c_double)),
144 POINTER(POINTER(c_double)),
145 POINTER(POINTER(c_double)),
146 POINTER(POINTER(c_double)),
147 POINTER(POINTER(c_double)),
148 POINTER(POINTER(c_double)),
149 POINTER(POINTER(c_double)),
150 POINTER(POINTER(c_double)),
151 POINTER(POINTER(c_double)),
152 POINTER(POINTER(c_double)),
153 POINTER(POINTER(c_double)),
154 POINTER(POINTER(c_double)),
155 POINTER(POINTER(c_double)),
156 POINTER(POINTER(c_double)),
157 POINTER(POINTER(c_double)),
158 POINTER(POINTER(c_double)),
159 POINTER(POINTER(c_double))]
160libneko.neko_case_fluid_coef.restype =
None
162libneko.neko_output_ctrl_execute.argtypes = [POINTER(c_int), c_bool]
164libneko.neko_user_setup.argtypes = [POINTER(c_int),
171libneko.neko_user_setup.restype =
None
173libneko.neko_cb_field_by_name.argtypes = [c_char_p]
174libneko.neko_cb_field_by_name.restype = POINTER(c_double)
176libneko.neko_cb_field_name_at_index.argtypes = [POINTER(c_int), c_char_p]
177libneko.neko_cb_field_name_at_index.restype = c_int
183 """ Defines a Neko mapping of the degrees of freedom """
192 """ Defines a Neko space. """
207 """ Defines a Neko field. """
214 """ Defines Neko coefficients. """
248 """ Initialise Neko. """
252 """ Finalize Neko. """
253 libneko.neko_finalize()
256 """ Initialise Neko device layer. """
257 libneko.neko_device_init()
260 """ Finalize Neko device lyaer. """
261 libneko.neko_device_finalize()
264 """ Display job information. """
265 libneko.neko_job_info()
268 """ Initialise a neko registry. """
269 libneko.neko_registry_init()
272 """ Destroy a neko registry. """
273 libneko.neko_registry_free()
276 cb_initial_condition = initial_condition(0),
282 """Initialise a Neko case
284 A case is created based on a JSON file and a couple of (optional)
298 libneko.neko_case_allocate(byref(case_descr))
299 user_setup(case_descr, cb_initial_condition, cb_preprocess,
300 cb_compute, cb_dirichlet_condition, cb_material_properties,
303 libneko.neko_case_init(byref(cp), len(json.dumps(case_json)),
308 """ Destroy a Neko case. """
309 libneko.neko_case_free(byref(case_descr))
312 """ Retrive the current time of a case. """
313 time = libneko.neko_case_time(byref(case_descr))
317 """ Retrive the end time of a case. """
318 end_time = libneko.neko_case_end_time(byref(case_descr))
322 """ Retrive the current time-step of a case. """
323 tstep = libneko.neko_case_tstep(byref(case_descr))
327 """ Check if a case has reached its end time. """
328 is_done = libneko.neko_case_is_done(byref(case_descr))
332 """ Solve a Neko case. """
333 libneko.neko_solve(byref(case_descr))
336 """ Compute a time-step for a Neko case. """
337 libneko.neko_step(byref(case_descr))
340 """ Retrive a Neko field as a `neko_field_t`. """
342 np.frombuffer((c_double *
343 libneko.neko_field_size(name)).from_address(
344 addressof(libneko.neko_field(name).contents)),
345 dtype=np.dtype(c_double)),
352 """ Retrive the order of a Neko field. """
353 order = libneko.neko_field_order(name)
357 """ Retrive the number of elements in a Neko field. """
358 nelements = libneko.neko_field_nelements(name)
362 """ Retrive the total number of degrees of freedom of a Neko field. """
363 size = libneko.neko_field_size(name)
367 """ Retrive a dofmap of a Neko field as a `neko_dofmap_t`. """
368 size = libneko.neko_field_size(name)
369 dof_ptr = POINTER(c_longlong)()
370 x_ptr = POINTER(c_double)()
371 y_ptr = POINTER(c_double)()
372 z_ptr = POINTER(c_double)()
373 libneko.neko_field_dofmap(name, byref(dof_ptr),
374 byref(x_ptr), byref(y_ptr), byref(z_ptr))
376 dofmap =
wrap_dofmap(dof_ptr, x_ptr, y_ptr, z_ptr, size)
381 """ Retrive a dofmap of a Neko case's fluid solver as a `neko_dofmap_t`. """
383 dof_ptr = POINTER(c_longlong)()
384 x_ptr = POINTER(c_double)()
385 y_ptr = POINTER(c_double)()
386 z_ptr = POINTER(c_double)()
387 libneko.neko_case_fluid_dofmap(byref(case_descr), byref(dof_ptr),
388 byref(x_ptr), byref(y_ptr), byref(z_ptr),
391 dofmap =
wrap_dofmap(dof_ptr, x_ptr, y_ptr, z_ptr, size.value)
397 np.frombuffer((c_longlong * size).from_address(
398 addressof(dof_ptr.contents)), dtype=np.dtype(int)),
399 np.frombuffer((c_double * size).from_address(
400 addressof(x_ptr.contents)), dtype=np.dtype(c_double)),
401 np.frombuffer((c_double * size).from_address(
402 addressof(y_ptr.contents)), dtype=np.dtype(c_double)),
403 np.frombuffer((c_double * size).from_address(
404 addressof(z_ptr.contents)), dtype=np.dtype(c_double)),
410 """ Retrive a space of a Neko field as a `neko_space_t`. """
412 zg = POINTER(c_double)()
413 dr_inv = POINTER(c_double)()
414 ds_inv = POINTER(c_double)()
415 dt_inv = POINTER(c_double)()
416 wx = POINTER(c_double)()
417 wy = POINTER(c_double)()
418 wz = POINTER(c_double)()
419 dx = POINTER(c_double)()
420 dy = POINTER(c_double)()
421 dz = POINTER(c_double)()
422 libneko.neko_field_space(name, byref(lx), byref(zg),
423 byref(dr_inv), byref(ds_inv), byref(dt_inv),
424 byref(wx), byref(wy), byref(wz),
425 byref(dx), byref(dy), byref(dz))
428 dr_inv, ds_inv, dt_inv,
429 wx, wy, wz, dx, dy, dz)
434 """ Retrive a space of a Neko case's fluid solver as a `neko_space_t`. """
436 zg = POINTER(c_double)()
437 dr_inv = POINTER(c_double)()
438 ds_inv = POINTER(c_double)()
439 dt_inv = POINTER(c_double)()
440 wx = POINTER(c_double)()
441 wy = POINTER(c_double)()
442 wz = POINTER(c_double)()
443 dx = POINTER(c_double)()
444 dy = POINTER(c_double)()
445 dz = POINTER(c_double)()
446 libneko.neko_case_fluid_space(byref(case_descr), byref(lx), byref(zg),
447 byref(dr_inv), byref(ds_inv), byref(dt_inv),
448 byref(wx), byref(wy), byref(wz),
449 byref(dx), byref(dy), byref(dz))
452 dr_inv, ds_inv, dt_inv,
453 wx, wy, wz, dx, dy, dz)
457def wrap_space(lx, zg, dr_inv, ds_inv, dt_inv, wx, wy, wz, dx, dy, dz):
460 np.frombuffer((c_double * lx * 3).from_address(
461 addressof(zg.contents))),
462 np.frombuffer((c_double * lx).from_address(
463 addressof(dr_inv.contents))),
464 np.frombuffer((c_double * lx).from_address(
465 addressof(ds_inv.contents))),
466 np.frombuffer((c_double * lx).from_address(
467 addressof(dt_inv.contents))),
468 np.frombuffer((c_double * lx).from_address(
469 addressof(wx.contents))),
470 np.frombuffer((c_double * lx).from_address(
471 addressof(wy.contents))),
472 np.frombuffer((c_double * lx).from_address(
473 addressof(wz.contents))),
474 np.frombuffer((c_double * lx * lx).from_address(
475 addressof(dx.contents))),
476 np.frombuffer((c_double * lx * lx).from_address(
477 addressof(dy.contents))),
478 np.frombuffer((c_double * lx * lx).from_address(
479 addressof(dz.contents)))
485 """ Retrive coefficients of a Neko case's fluid solver as a `neko_coef_t`. """
486 G11_ptr = POINTER(c_double)()
487 G22_ptr = POINTER(c_double)()
488 G33_ptr = POINTER(c_double)()
489 G12_ptr = POINTER(c_double)()
490 G13_ptr = POINTER(c_double)()
491 G23_ptr = POINTER(c_double)()
492 mult_ptr = POINTER(c_double)()
493 dxdr_ptr = POINTER(c_double)()
494 dydr_ptr = POINTER(c_double)()
495 dzdr_ptr = POINTER(c_double)()
496 dxds_ptr = POINTER(c_double)()
497 dyds_ptr = POINTER(c_double)()
498 dzds_ptr = POINTER(c_double)()
499 dxdt_ptr = POINTER(c_double)()
500 dydt_ptr = POINTER(c_double)()
501 dzdt_ptr = POINTER(c_double)()
502 drdx_ptr = POINTER(c_double)()
503 drdy_ptr = POINTER(c_double)()
504 drdz_ptr = POINTER(c_double)()
505 dsdx_ptr = POINTER(c_double)()
506 dsdy_ptr = POINTER(c_double)()
507 dsdz_ptr = POINTER(c_double)()
508 dtdx_ptr = POINTER(c_double)()
509 dtdy_ptr = POINTER(c_double)()
510 dtdz_ptr = POINTER(c_double)()
511 jac_ptr = POINTER(c_double)()
512 B_ptr = POINTER(c_double)()
513 area_ptr = POINTER(c_double)()
514 nx_ptr = POINTER(c_double)()
515 ny_ptr = POINTER(c_double)()
516 nz_ptr = POINTER(c_double)()
518 libneko.neko_case_fluid_coef(byref(case_descr),
554 np.frombuffer((c_double * dm.ntot).from_address(
555 addressof(G11_ptr.contents))),
556 np.frombuffer((c_double * dm.ntot).from_address(
557 addressof(G22_ptr.contents))),
558 np.frombuffer((c_double * dm.ntot).from_address(
559 addressof(G33_ptr.contents))),
560 np.frombuffer((c_double * dm.ntot).from_address(
561 addressof(G12_ptr.contents))),
562 np.frombuffer((c_double * dm.ntot).from_address(
563 addressof(G13_ptr.contents))),
564 np.frombuffer((c_double * dm.ntot).from_address(
565 addressof(G23_ptr.contents))),
566 np.frombuffer((c_double * dm.ntot).from_address(
567 addressof(mult_ptr.contents))),
568 np.frombuffer((c_double * dm.ntot).from_address(
569 addressof(dxdr_ptr.contents))),
570 np.frombuffer((c_double * dm.ntot).from_address(
571 addressof(dydr_ptr.contents))),
572 np.frombuffer((c_double * dm.ntot).from_address(
573 addressof(dzdr_ptr.contents))),
574 np.frombuffer((c_double * dm.ntot).from_address(
575 addressof(dxds_ptr.contents))),
576 np.frombuffer((c_double * dm.ntot).from_address(
577 addressof(dyds_ptr.contents))),
578 np.frombuffer((c_double * dm.ntot).from_address(
579 addressof(dzds_ptr.contents))),
580 np.frombuffer((c_double * dm.ntot).from_address(
581 addressof(dxdt_ptr.contents))),
582 np.frombuffer((c_double * dm.ntot).from_address(
583 addressof(dydt_ptr.contents))),
584 np.frombuffer((c_double * dm.ntot).from_address(
585 addressof(dzdt_ptr.contents))),
586 np.frombuffer((c_double * dm.ntot).from_address(
587 addressof(drdx_ptr.contents))),
588 np.frombuffer((c_double * dm.ntot).from_address(
589 addressof(drdy_ptr.contents))),
590 np.frombuffer((c_double * dm.ntot).from_address(
591 addressof(drdz_ptr.contents))),
592 np.frombuffer((c_double * dm.ntot).from_address(
593 addressof(dsdx_ptr.contents))),
594 np.frombuffer((c_double * dm.ntot).from_address(
595 addressof(dsdy_ptr.contents))),
596 np.frombuffer((c_double * dm.ntot).from_address(
597 addressof(dsdz_ptr.contents))),
598 np.frombuffer((c_double * dm.ntot).from_address(
599 addressof(dtdx_ptr.contents))),
600 np.frombuffer((c_double * dm.ntot).from_address(
601 addressof(dtdy_ptr.contents))),
602 np.frombuffer((c_double * dm.ntot).from_address(
603 addressof(dtdz_ptr.contents))),
604 np.frombuffer((c_double * dm.ntot).from_address(
605 addressof(jac_ptr.contents))),
606 np.frombuffer((c_double * dm.ntot).from_address(
607 addressof(B_ptr.contents))),
608 np.frombuffer((c_double * dm.ntot).from_address(
609 addressof(area_ptr.contents))),
610 np.frombuffer((c_double * dm.ntot).from_address(
611 addressof(nx_ptr.contents))),
612 np.frombuffer((c_double * dm.ntot).from_address(
613 addressof(ny_ptr.contents))),
614 np.frombuffer((c_double * dm.ntot).from_address(
615 addressof(nz_ptr.contents)))
620def user_setup(case_descr, cb_initial_condition, cb_preprocess, cb_compute,
621 cb_dirichlet_condition, cb_material_properties, cb_source_term):
622 """ Setup user-provided callbacks. """
623 libneko.neko_user_setup(byref(case_descr),
624 cb_initial_condition,
627 cb_dirichlet_condition,
628 cb_material_properties,
632 libneko.neko_output_ctrl_execute(byref(case_descr), force)
635 """ Retrive a callback's Neko field as a `neko_field_t`. """
637 np.frombuffer((c_double *
638 libneko.neko_field_size(name)).from_address(
639 addressof(libneko.neko_cb_field_by_name(name).contents)),
640 dtype=np.dtype(c_double)),
647 """ Check the name of a field at a certain index in the callback's field list. """
648 field_index = c_int(index)
649 same_field = libneko.neko_cb_field_name_at_index(byref(field_index), name)
650 return same_field > 0
653 mask = np.frombuffer((c_int * msk_size).from_address(
654 addressof(msk.contents)), dtype=np.dtype(np.int32))
662 return cast(create_string_buffer(s.encode()),c_char_p)
user_setup(case_descr, cb_initial_condition, cb_preprocess, cb_compute, cb_dirichlet_condition, cb_material_properties, cb_source_term)
case_fluid_space(case_descr)
case_fluid_coef(case_descr)
case_init(case_json, cb_initial_condition=initial_condition(0), cb_preprocess=preprocess(0), cb_compute=compute(0), cb_dirichlet_condition=dirichlet_condition(0), cb_material_properties=material_properties(0), cb_source_term=source_term(0))
wrap_dofmap(dof_ptr, x_ptr, y_ptr, z_ptr, size)
callback_field_name(index, name)
wrap_space(lx, zg, dr_inv, ds_inv, dt_inv, wx, wy, wz, dx, dy, dz)
python_dict_to_fortran(d)
case_fluid_dofmap(case_descr)
Implements the source_term_t type and a wrapper source_term_wrapper_t.