1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// ! ## rs_isl
// ! Implementation of Iterative Stencil Loops
// !
// ! Runs a simulation over a 2-dimensional array
// ! specified by the given parameters.
// !
// ! ## Features:
// ! - generic array elements
// ! - parallelization using threads
// ! - custom definition of neighbouring elements
// !
// ! For further information on ISLs see: https://wikipedia.org/wiki/Iterative_Stencil_Loops
// !
// ! ## Usage
// !
// ! An example which creates a wave-like motion from left to right through the grid.
// !
// ! ```rust, no_run
// ! use core::f64;
// ! use std::{cmp::max, path::PathBuf};
// !
// ! use rs_isl::*;
// !
// !
// ! fn main() {
// ! // create a domain with a size of 200 by 100
// ! let dim = (200, 100)
// ! // we only access the left neighbour of every cell
// ! let neighbours = vec![(-1, 0)];
// !
// ! // take neighbours value, if there is no neighbour decrease by 3
// ! let op = |num: &f32, nb: Vec<Option<&f32>>| {
// ! if nb.first().unwrap().is_some() {
// ! let f = *nb[0].unwrap();
// ! return f;
// ! }
// ! return max(*num as i32 - 3, 0) as f32;
// ! };
// !
// ! // creates a sine shape at the left boundary of the domain
// ! let init = |x: usize, _y: usize| {
// ! if x < DIM.0 / 10 {
// ! let fac = x as f64 / (DIM.0 / 10) as f64 * f64::consts::FRAC_PI_2;
// ! return (250.0 - 250.0 * fac.sin()) as f32;
// ! }
// ! 0.0
// ! };
// !
// ! // create the simulation parameters
// ! let params = IslParams::new(
// ! dim,
// ! op,
// ! // number of threads for simulation, the domain size must be divisible by this number
// ! 10,
// ! init,
// ! // number of simulation steps
// ! 200,
// ! // number of output steps
// ! 100,
// ! neighbours,
// ! // path for writing vtk files
// ! PathBuf::from("raw"),
// ! );
// !
// ! // run the simulation
// ! run_isl(params).unwrap();
// ! }
// ! ```
use ;
use PathBuf;
use WithCall;
/// Trait for defining the output of every cell.
///
/// Implement for your Data Type to write your data into the output file
///
/// # Example
/// ```rust, no_run
///
/// use rs_isl::*;
///
/// struct Point {
/// x: u32,
/// y: u32,
/// }
///
/// impl VtkOutput for Point {
/// fn value_names() -> Vec<String> {
/// vec!["x_coord".into(), "y_coord".into()]
/// }
/// fn cellvalue(&self) -> Vec<f32> {
/// vec![self.x as f32, self.y as f32]
/// }
/// }
/// ```
+ Clone + Send + Copy,
H: Fn ,
/// Runs the ISL and returns the output data
///
/// For more information see crate level documentation and [IslParams::new]
///
/// # Errors
///
/// If the given array size (x*y) is not divisible by the number of runners, an error will be returned.