1 |
|
# This file is part of ff3d - http://www.freefem.org/ff3d |
2 |
|
|
3 |
|
# This program is free software; you can redistribute it and/or modify |
4 |
|
# it under the terms of the GNU General Public License as published by |
5 |
|
# the Free Software Foundation; either version 2, or (at your option) |
6 |
|
# any later version. |
7 |
|
|
8 |
|
# This program is distributed in the hope that it will be useful, |
9 |
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 |
|
# GNU General Public License for more details. |
12 |
|
|
13 |
|
# You should have received a copy of the GNU General Public License |
14 |
|
# along with this program; if not, write to the Free Software Foundation, |
15 |
|
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
16 |
|
|
17 |
|
# $Id$ |
18 |
|
|
19 |
# Tools for the FreeFEM3D checking procedure |
# Tools for the FreeFEM3D checking procedure |
|
# $Id$ |
|
20 |
|
|
21 |
# Error count |
# Error count |
22 |
$errors = 0; |
$errors = 0; |
137 |
|
|
138 |
Run($script); |
Run($script); |
139 |
|
|
140 |
# Tests all lines in the signature separately, just to make error |
# Tests each line in the signature separately, just to make error |
141 |
# reports more precise. |
# reports more precise. |
142 |
|
|
143 |
|
my @sig = split /\n/,$signature; |
144 |
|
foreach my $line (@sig){ |
145 |
|
LineCheck('^'.$line.'$'); |
146 |
|
} |
147 |
|
} |
148 |
|
|
149 |
|
# Povray scene for domain tests |
150 |
|
sub WriteDomainPovrayScene{ |
151 |
|
WriteFile('test.pov',<< 'EOF'); |
152 |
|
|
153 |
|
/* One big sphere */ |
154 |
|
sphere{ |
155 |
|
<0,0,0>,1.1 |
156 |
|
pigment{color rgb <1,0,0>} |
157 |
|
} |
158 |
|
|
159 |
|
/* One smaller sphere, centered on a test point and intersecting the |
160 |
|
first sphere. A test point is contained in the intersection*/ |
161 |
|
|
162 |
|
sphere{ |
163 |
|
<1,0,0>,0.5 |
164 |
|
pigment{color rgb <0,1,0>} |
165 |
|
} |
166 |
|
|
167 |
|
/* One smaller sphere, centered on a test point which is not reached |
168 |
|
by the first sphere. */ |
169 |
|
|
170 |
|
sphere{ |
171 |
|
<1,1,1>,0.5 |
172 |
|
pigment{color rgb <0,0,1>} |
173 |
|
} |
174 |
|
EOF |
175 |
|
} |
176 |
|
|
177 |
|
# Builds a domain with the given domain operations, reads it in ff3d |
178 |
|
# and checks wether the given signature is ok. |
179 |
|
|
180 |
|
sub DomainCheck{ |
181 |
|
my ($domainop,$signature) =@_; |
182 |
|
|
183 |
|
# The list of useful povray objects, written to one povray file |
184 |
|
# and used as necessary in the following FF3D script. |
185 |
|
WriteDomainPovrayScene(); |
186 |
|
|
187 |
|
# Builds a ff3d script that loads the scene in and checks its |
188 |
|
# indicator function on points spread evenly on a unit cube (from |
189 |
|
# (-1,-1,-1) to (1,1,1)). |
190 |
|
|
191 |
|
my $script = "scene S = pov(\"test.pov\");\n" |
192 |
|
."domain O = domain(S,$domainop);\n"; |
193 |
|
for(my $x = -1;$x <= 1;$x++){ |
194 |
|
for(my $y = -1;$y <= 1;$y++){ |
195 |
|
for(my $z = -1;$z <= 1;$z++){ |
196 |
|
$script .= "cout << $x << \",\" << $y << \",\" << $z;\n" |
197 |
|
."cout << \":\" << one(O)($x,$y,$z) << \"\\n\";\n\n"; |
198 |
|
} |
199 |
|
} |
200 |
|
} |
201 |
|
|
202 |
|
Run($script); |
203 |
|
|
204 |
|
# Tests each line in the signature separately, just to make error |
205 |
|
# reports more precise. |
206 |
|
|
207 |
|
my @sig = split /\n/,$signature; |
208 |
|
foreach my $line (@sig){ |
209 |
|
LineCheck('^'.$line.'$'); |
210 |
|
} |
211 |
|
} |
212 |
|
|
213 |
|
# Builds a domain, then runs a simple differential equation resolution |
214 |
|
# to differentiate inside points and outside points. |
215 |
|
|
216 |
|
sub DomainMeshCheck{ |
217 |
|
|
218 |
|
# $domainop = required domain operation |
219 |
|
# $signature = expected result |
220 |
|
|
221 |
|
my ($domainop,$signature) = @_; |
222 |
|
|
223 |
|
# The list of useful povray objects, written to one povray file |
224 |
|
# and used as necessary in the following FF3D script. |
225 |
|
WriteDomainPovrayScene(); |
226 |
|
|
227 |
|
# The FF3D script, using the above povray objects and the domain |
228 |
|
# composed as described in the perl script. The problem to solve |
229 |
|
# is chosen so that the inside of the domain will converge to the |
230 |
|
# numerical value 1, and the outside to a value smaller than one. |
231 |
|
|
232 |
|
my $script = "scene S = pov(\"test.pov\");\n"; |
233 |
|
$script .= "domain O = domain(S,$domainop);\n"; |
234 |
|
$script .= << 'EOF'; |
235 |
|
|
236 |
|
vertex a = (-2,-2,-2); |
237 |
|
vertex b = (2,2,2); |
238 |
|
vector n = (10,10,10); |
239 |
|
mesh M = structured(n,a,b); |
240 |
|
|
241 |
|
solve (u) in O by M{ |
242 |
|
pde(u) |
243 |
|
-div(grad(u)) = 0; |
244 |
|
|
245 |
|
// Defines a Dirichlet boundary condition on the domain frontier. |
246 |
|
|
247 |
|
u = 1 on <1,0,0>; |
248 |
|
u = 1 on <0,1,0>; |
249 |
|
u = 0 on M; |
250 |
|
} |
251 |
|
EOF |
252 |
|
|
253 |
|
# Final trace output, aimed at testing point values scattered |
254 |
|
# around the domain. |
255 |
|
|
256 |
|
for(my $x = -1;$x <= 1;$x++){ |
257 |
|
for(my $y = -1;$y <= 1;$y++){ |
258 |
|
for(my $z = -1;$z <= 1;$z++){ |
259 |
|
|
260 |
|
# Coordinates display |
261 |
|
|
262 |
|
$script .= "cout << $x << \",\" << $y << \",\" << $z" |
263 |
|
." << \":\";\n"; |
264 |
|
|
265 |
|
# Value of u. Values are rounded to one or zero |
266 |
|
# because we are only interested in checking if the |
267 |
|
# point belongs to the defined domain or not. |
268 |
|
|
269 |
|
$script .= "if(u($x,$y,$z) > 0.9) cout << \"1\\n\";\n" |
270 |
|
. "else cout << \"0\\n\";\n"; |
271 |
|
} |
272 |
|
} |
273 |
|
} |
274 |
|
|
275 |
|
# Runs FF3D script |
276 |
|
|
277 |
|
Run($script); |
278 |
|
|
279 |
|
# Tests each line in the signature separately, just to make error |
280 |
|
# reports more precise. |
281 |
|
|
282 |
my @sig = split /\n/,$signature; |
my @sig = split /\n/,$signature; |
283 |
foreach my $line (@sig){ |
foreach my $line (@sig){ |
284 |
LineCheck('^'.$line.'$'); |
LineCheck('^'.$line.'$'); |