rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
check_consistency.m
1 function res = check_consistency(grid)
2 %function res = check_consistency(grid)
3 %
4 % function checking the consistency of a cubegrid, i.e. checking, whether
5 % - all elements have axis parallel edges
6 % - the volume of the leaf-elements corresponds to the level-0 elements
7 %
8 % Return values:
9 % res: This is 1 if OK, 0 if error
10 %
11 % @note The check is slow, as all edges for all elements are determined in
12 % loops and multiply
13 
14 % perhaps later further extensions
15 
16 % Bernard Haasdonk 27.3.2007
17 
18 % for all elements check that all edges are axis-parallel
19 
20  res = 1;
21 
22  for gid = 1:grid.nelements;
23  [p0,p1] = get_edges(grid,gid);
24  diff = p0-p1;
25  % only one entry may relevantly differ from zero
26  nonzeros = sum(abs(diff)>1e-10);
27  if (min(nonzeros)<1) || (max(nonzeros)>1)
28  disp('edge not axis parallel, please check!');
29  res = 0;
30  end;
31  end;
32 
33  % check the volume of the leaf-elements corresponds to the level-0 elements
34 
35  macrogids = find(grid.level==0);
36  leafgids = get_leafgids(grid);
37 
38  macrovol = get_volume(grid,macrogids);
39  leafvol = get_volume(grid,leafgids);
40 
41  ratio = abs(sum(macrovol)-sum(leafvol))/sum(macrovol);
42  if (ratio>1e-5)
43  disp('volume ratio of leaf and macrogrid differing, please check!');
44  res = 0;
45  end;
46 
47 end
48 
A hierarchical cubegrid of arbitrary dimension.
Definition: cubegrid.m:17
Definition: leaf.m:17