1 /*
2 * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package nbodygl;
26
27 import hat.Accelerator;
28 import optkl.ifacemapper.BoundSchema;
29 import optkl.ifacemapper.Buffer;
30 import hat.types.Float4;
31 import optkl.ifacemapper.Schema;
32
33 public interface Universe extends Buffer {
34 int length();
35 default Float4[] posArrView(){
36 return null;
37 }
38 default Float4[] velArrView(){
39 return null;
40 }
41 interface Body extends Struct {
42 float x();
43
44 float y();
45
46 float z();
47
48 float vx();
49
50 float vy();
51
52 float vz();
53
54 void x(float x);
55
56 void y(float y);
57
58 void z(float z);
59
60 void vx(float vx);
61
62 void vy(float vy);
63
64 void vz(float vz);
65 }
66
67 Body body(long idx);
68
69 /*
70 typedef struct Body_s{
71 float x;
72 float y;
73 float y;
74 float vx;
75 float vy;
76 float y;
77 } Body_t;
78
79 typedef struct Universe_s{
80 int length;
81 Body_t body[1];
82 }Universe_t;
83
84 */
85 Schema<Universe> schema = Schema.of(Universe.class, resultTable -> resultTable
86
87 .arrayLen("length").array("body", array -> array
88 .fields("x", "y", "z", "vx", "vy", "vz")
89 )
90 );
91
92 static Universe create(Accelerator accelerator, int length) {
93 return BoundSchema.of(accelerator ,schema, length).allocate();
94 }
95
96 }