This class provides a 'as-simple-as' possible component, which just creates one source field, that is filled with random values in each timestep.
1
2
3
4
5
6
7from yac import (YAC, Reg2dGrid, Field, Location, TimeUnit)
8import numpy as np
9
10
11class NoiseGenerator:
12 def __init__(self, timestep, yac=None, collection_size=1):
13 self.yac = yac or YAC.default_instance
14 self.comp = self.yac.predef_comp("noisegenerator")
15 self.timestep = timestep
16 self.collection_size = collection_size
17
18 def setup(self):
19 global grid, noise_field
20 x = np.linspace(0, 2*np.pi, 360)
21 y = np.linspace(-0.5*np.pi, 0.5*np.pi, 180)
22 grid = Reg2dGrid("noise_grid", x, y)
23 points = grid.def_points(Location.CORNER, x, y)
24
25 noise_field = Field.create("noise", self.comp, points, self.collection_size,
26 self.timestep, TimeUnit.ISO_FORMAT)
27
28 def def_couples(self):
29 pass
30
31 def step(self):
32 print("NoiseGenerator: Lets make some noise!!!")
33 noise_field.put(np.random.rand(self.collection_size, grid.nbr_corners))
34 return noise_field.datetime