Line data Source code
1 : /*
2 : * Copyright (c) 2012-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Sebastian Reiter
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 :
33 : #include "check_associated_elements.h"
34 : #include "lib_grid/grid/grid_util.h"
35 :
36 : namespace ug{
37 : namespace grid_unit_tests{
38 :
39 0 : void CheckAssociatedEdgesOfVolumes(Grid& g)
40 : {
41 : // VOLOPT_STORE_ASSOCIATED_EDGES has to be enabled, so that this method makes sense...
42 0 : if(!g.option_is_enabled(VOLOPT_STORE_ASSOCIATED_EDGES)){
43 : UG_LOG("WARNING: Autoenabling VOLOPT_STORE_ASSOCIATED_EDGES in CheckAssociatedEdgesOfVolumes.\n");
44 0 : g.enable_options(VOLOPT_STORE_ASSOCIATED_EDGES);
45 : }
46 :
47 0 : g.begin_marking();
48 :
49 : // iterate over all volumes
50 0 : for(VolumeIterator iter = g.volumes_begin(); iter != g.volumes_end(); ++iter){
51 : Volume* vol = *iter;
52 0 : g.clear_marks();
53 :
54 : // get all associated edges
55 : std::vector<Edge*> edges;
56 : CollectAssociated(edges, g, vol);
57 :
58 : // iterate over them and mark them. Make sure none is marked twice.
59 0 : for(size_t i = 0; i < edges.size(); ++i){
60 0 : if(g.is_marked(edges[i])){
61 0 : UG_THROW("Edge is contained in associated edges of volume twice!");
62 : }
63 : g.mark(edges[i]);
64 : }
65 :
66 : // make sure that the elements have the right order, if VOLOPT_AUTOGENERATE_EDGES
67 : // or GRIDOPT_AUTOGENERATE_SIDES is active
68 0 : if(g.option_is_enabled(VOLOPT_AUTOGENERATE_EDGES) ||
69 0 : g.option_is_enabled(GRIDOPT_AUTOGENERATE_SIDES))
70 : {
71 : // edges should be sorted...
72 : // also check get_edge(vol, i)...
73 0 : EdgeDescriptor ed;
74 0 : for(size_t i_ed = 0; i_ed < vol->num_edges(); ++i_ed){
75 0 : vol->edge_desc(i_ed, ed);
76 0 : Edge* e = g.get_edge(ed);
77 :
78 0 : if(e != g.get_edge(vol, i_ed)){
79 0 : UG_THROW("Grid::get_edge(vol, i) does not return the i-th edge of vol!");
80 : }
81 :
82 0 : if(e != edges[i_ed]){
83 0 : UG_THROW("AssociatedEdges should contain edges in the correct order when autogeneration is active!");
84 : }
85 : }
86 : }
87 :
88 : // now iterate over associated edges of all corner vertices of vol
89 : // and make sure that each is marked
90 0 : Volume::ConstVertexArray vrts = vol->vertices();
91 0 : for(size_t i_vrt = 0; i_vrt < vol->num_vertices(); ++i_vrt){
92 0 : CollectAssociated(edges, g, vrts[i_vrt]);
93 0 : for(size_t i_edge = 0; i_edge < edges.size(); ++i_edge){
94 0 : if(VolumeContains(vol, edges[i_edge])){
95 0 : if(!g.is_marked(edges[i_edge])){
96 0 : UG_THROW("Edge is contained in volume but not in volume's associated-edge-container!");
97 : }
98 : }
99 : }
100 : }
101 0 : }
102 :
103 0 : g.end_marking();
104 0 : }
105 :
106 0 : void CheckAssociatedVolumesOfEdges(Grid& g)
107 : {
108 : // VOLOPT_STORE_ASSOCIATED_EDGES has to be enabled, so that this method makes sense...
109 0 : if(!g.option_is_enabled(EDGEOPT_STORE_ASSOCIATED_VOLUMES)){
110 : UG_LOG("WARNING: Autoenabling EDGEOPT_STORE_ASSOCIATED_VOLUMES in CheckAssociatedVolumesOfEdges.\n");
111 0 : g.enable_options(EDGEOPT_STORE_ASSOCIATED_VOLUMES);
112 : }
113 :
114 0 : g.begin_marking();
115 :
116 : // iterate over all volumes
117 0 : for(EdgeIterator iter = g.edges_begin(); iter != g.edges_end(); ++iter){
118 : Edge* e = *iter;
119 0 : g.clear_marks();
120 :
121 : // get all associated volumes
122 : std::vector<Volume*> vols;
123 : CollectAssociated(vols, g, e);
124 :
125 : // iterate over them and mark them. Make sure none is marked twice.
126 0 : for(size_t i = 0; i < vols.size(); ++i){
127 0 : if(g.is_marked(vols[i])){
128 0 : UG_THROW("Volume is contained in associated volumes of edge twice!");
129 : }
130 : g.mark(vols[i]);
131 : }
132 :
133 : // now iterate over associated volumes of all corner vertices of e
134 : // and make sure that each is marked
135 0 : Edge::ConstVertexArray vrts = e->vertices();
136 0 : for(size_t i_vrt = 0; i_vrt < e->num_vertices(); ++i_vrt){
137 0 : CollectAssociated(vols, g, vrts[i_vrt]);
138 0 : for(size_t i_vol = 0; i_vol < vols.size(); ++i_vol){
139 0 : if(VolumeContains(vols[i_vol], e)){
140 0 : if(!g.is_marked(vols[i_vol])){
141 0 : UG_THROW("Volume is contained in edge but not in edge's associated-volume-container!");
142 : }
143 : }
144 : }
145 : }
146 0 : }
147 :
148 0 : g.end_marking();
149 0 : }
150 :
151 : }// end of namespace
152 : }// end of namespace
|