1% Testing divand in 2 dimensions in a cyclic domain.
2
3% grid of background field
4n = 30;
5
6[xi,yi] = ndgrid(0:n-1);
7
8x = xi(2,15);
9y = yi(2,15);
10f = 1;
11
12mask = ones(size(xi));
13pm = ones(size(xi)) / (xi(2,1)-xi(1,1));
14pn = ones(size(xi)) / (yi(1,2)-yi(1,1));
15
16
17
18fi = divand(mask,{pm,pn},{xi,yi},{x,y},f,5,200,'moddim',[n 0]);
19rms_diff = [];
20
21rms_diff(end+1) = divand_rms(fi(end,:),fi(4,:));
22
23
24x = xi(2,2);
25y = yi(2,2);
26
27fi = divand(mask,{pm,pn},{xi,yi},{x,y},f,5,200,'moddim',[n n]);
28
29rms_diff(end+1) = abs(fi(4,4) - fi(end,end));
30
31
32fi2 = divand(mask,{pm,pn},{xi,yi},{x,y},f,5,200,'moddim',[n 0],'fracindex',[0.5; 15.]);
33fi3 = divand(mask,{pm,pn},{xi,yi},{x,y},f,5,200,'moddim',[n 0],'fracindex',[30.5; 15.]);
34rms_diff(end+1) = divand_rms(fi2,fi3);
35
36
37
38fi3 = divand(mask,{pm,pn},{xi,yi},{x,y},f,5,200,'moddim',[n 0],'fracindex',[10.5; 15.]);
39fi4 = cat(1,fi3(11:end,:),fi3(1:10,:));
40
41rms_diff(end+1) = divand_rms(fi2,fi4);
42
43
44
45
46
47% test with mask
48mask(11,4) = 0;
49mask(3:15,20) = 0;
50
51fi3 = divand(mask,{pm,pn},{xi,yi},{x,y},f,5,200,'moddim',[n 0],'fracindex',[10.5; 15.]);
52fi4 = cat(1,fi3(11:end,:),fi3(1:10,:));
53
54mask = cat(1,mask(11:end,:),mask(1:10,:));
55
56fi2 = divand(mask,{pm,pn},{xi,yi},{x,y},f,5,200,'moddim',[n 0],'fracindex',[0.5; 15.]);
57
58
59rms_diff(end+1) = divand_rms(fi2,fi4);
60rms_diff(end+1) = divand_rms(isnan(fi2),isnan(fi4));
61
62% advection
63
64a = 5;
65u = a*cos(2*pi*yi/n);
66v = a*cos(2*pi*xi/n);
67
68mask = ones(size(xi));
69fi = divand(mask,{pm,pn},{xi,yi},{x,y},f,5,200,'moddim',[n 0],'fracindex',[10.5; 15.],'velocity',{u,v});
70fi2 = cat(1,fi(11:end,:),fi(1:10,:));
71
72ut = cat(1,u(11:end,:),u(1:10,:));
73vt = cat(1,v(11:end,:),v(1:10,:));
74fi3 = divand(mask,{pm,pn},{xi,yi},{x,y},f,5,200,'moddim',[n 0],'fracindex',[0.5; 15.],'velocity',{ut,vt});
75
76rms_diff(end+1) = divand_rms(fi2,fi3);
77
78if any(rms_diff > 1e-10) || any(isnan(rms_diff))
79  error('unexpected large difference');
80end
81
82fprintf('(max rms=%g) ',max(rms_diff));
83
84% Copyright (C) 2014 Alexander Barth <a.barth@ulg.ac.be>
85%
86% This program is free software; you can redistribute it and/or modify it under
87% the terms of the GNU General Public License as published by the Free Software
88% Foundation; either version 2 of the License, or (at your option) any later
89% version.
90%
91% This program is distributed in the hope that it will be useful, but WITHOUT
92% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
94% details.
95%
96% You should have received a copy of the GNU General Public License along with
97% this program; if not, see <http://www.gnu.org/licenses/>.
98