1
+ #!/bin/env python
2
+ import numpy as np
3
+ import pyLOM
4
+
5
+
6
+ ## Parameters
7
+ OUTFILE = "./example_dataset.h5"
8
+
9
+
10
+ ## Synthetic data
11
+ #
12
+ # This is the data you want to perform ML on, i.e., the cooling function
13
+ # or the Cp on the airfoil example
14
+ K = np .array ([[[1 ,2 ,3 ,4 ],[5 , 6 , 7 , 8 ],[9 ,10 ,11 ,12 ]], [[13 , 14 , 15 , 16 ],[17 ,18 ,19 ,20 ],[21 ,22 ,23 ,24 ]]],np .float32 ).T
15
+ print ('K:' ,K .shape ) # (4, 3, 2)
16
+
17
+ # So the first dimension, 4, are the xyz positions
18
+ # then xyz must have length (4,3) or (4,2) in 2D
19
+ xyz = np .array ([[1 ,19 ,12 ],[1 ,20 ,12 ],[2 ,5 ,11 ],[3 ,6 ,11 ]],np .float32 )
20
+ print ('xyz:' ,xyz .shape ) # (4, 3)
21
+
22
+ # For the point order array we simply numerate our
23
+ # points consecutively
24
+ pointO = np .arange (xyz .shape [0 ])
25
+ print ('pointO:' ,pointO .shape ) # (4,)
26
+
27
+ # Now we are missing two variables of size (3,) and (2,)
28
+ # for this example we will call them `var1` and `var2`
29
+ var1 = np .array ([20 ,30 ,40 ],np .float32 )
30
+ print ('var1:' ,var1 .shape ) # (3,)
31
+ var2 = np .array ([200 ,300 ],np .float32 )
32
+ print ('var2:' ,var2 .shape ) # (2,)
33
+ print ()
34
+
35
+
36
+ ## Create a serial partition table
37
+ # The number of points is simply the first dimension
38
+ # of K and xyz
39
+ npoints = xyz .shape [0 ]
40
+ # Here we create a table with a single partition with the
41
+ # same number of points and elements (i.e., a cloud of points)
42
+ ptable = pyLOM .PartitionTable .new (1 ,npoints ,npoints )
43
+ print (ptable )
44
+
45
+
46
+ ## Create a pyLOM dataset
47
+ # Now we can arrange the dataset
48
+ # In this example, it is indiferent if we treat the data as
49
+ # points or cells. For simplicity we will assume the data to
50
+ # be points.
51
+ d = pyLOM .Dataset (xyz = xyz ,ptable = ptable ,order = pointO ,point = True ,
52
+ # Add the variables as a dictionary associated with
53
+ # their dimensions on the matrix K
54
+ vars = {
55
+ # We associate var1 to the first dimension of K, i.e.,
56
+ # idim = 0 as dimension 0 of K is always the number of
57
+ # points
58
+ 'var1' : {'idim' :0 ,'value' :var1 },
59
+ # We associate var2 to the second dimension of K, i.e.,
60
+ # idim = 1
61
+ 'var2' : {'idim' :1 ,'value' :var2 },
62
+ },
63
+ # Now we add the fields, i.e., the actual data to compute
64
+ # things. So K has ndim = 2 as there are two extra dimensions
65
+ # other than the number of points
66
+ K = {'ndim' :2 ,'value' :K }
67
+ )
68
+ print (d )
69
+
70
+ # Now we store the dataset
71
+ # we make sure to activate mode = 'w' to overwrite
72
+ # any possible early results
73
+ d .save (OUTFILE ,mode = 'w' )
74
+
75
+
76
+ pyLOM .cr_info ()
0 commit comments