YetAnotherCoupler 3.2.0_a
Loading...
Searching...
No Matches
noisegenerator.py

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#!/usr/bin/env python3
2
3# Copyright (c) 2024 The YAC Authors
4#
5# SPDX-License-Identifier: BSD-3-Clause
6
7from yac import *
8import numpy as np
9
10class NoiseGenerator:
11 def __init__(self, timestep, yac = None):
12 self.yac = yac or YAC.default_instance
13 self.comp = self.yac.predef_comp("noisegenerator")
14 self.timestep = timestep
15
16 def setup(self):
17 global grid, noise_field
18 x = np.linspace(0,2*np.pi,360)
19 y = np.linspace(-0.5*np.pi,0.5*np.pi,180)
20 grid = Reg2dGrid(f"noise_grid", x, y)
21 points = grid.def_points(Location.CORNER, x, y)
22
23 noise_field = Field.create("noise", self.comp, points, 1,
24 self.timestep, TimeUnit.ISO_FORMAT)
25
26 def def_couples(self):
27 pass
28
29 def step(self):
30 print(f"NoiseGenerator: Lets make some noise!!!")
31 noise_field.put(np.random.rand(grid.nbr_corners, 1))
32 return noise_field.datetime