Line data Source code
1 : /*
2 : * Copyright (c) 2015: G-CSC, Goethe University Frankfurt
3 : * Author: Andreas Vogel
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 "subset_dim_util.h"
34 : #include "lib_grid/lg_base.h"
35 :
36 : namespace ug{
37 :
38 : /// returns if a subset is a regular grid
39 0 : bool SubsetIsRegularGrid(const SubsetHandler& sh, int si)
40 : {
41 : // check for constraining/constrained elements
42 0 : if(sh.num<ConstrainedVertex>(si) > 0) return false;
43 0 : if(sh.num<ConstrainedEdge>(si) > 0) return false;
44 0 : if(sh.num<ConstrainingEdge>(si) > 0) return false;
45 0 : if(sh.num<ConstrainedTriangle>(si) > 0) return false;
46 0 : if(sh.num<ConstrainingTriangle>(si) > 0) return false;
47 0 : if(sh.num<ConstrainedQuadrilateral>(si) > 0) return false;
48 0 : if(sh.num<ConstrainingQuadrilateral>(si) > 0) return false;
49 :
50 : // if not found, subset describes a regular grid
51 : return true;
52 : }
53 :
54 : /// returns if a subset is a regular grid
55 0 : bool SubsetIsRegularGrid(const MGSubsetHandler& sh, int si)
56 : {
57 : // check for constraining/constrained elements
58 0 : if(sh.num<ConstrainedVertex>(si) > 0) return false;
59 0 : if(sh.num<ConstrainedEdge>(si) > 0) return false;
60 0 : if(sh.num<ConstrainingEdge>(si) > 0) return false;
61 0 : if(sh.num<ConstrainedTriangle>(si) > 0) return false;
62 0 : if(sh.num<ConstrainingTriangle>(si) > 0) return false;
63 0 : if(sh.num<ConstrainedQuadrilateral>(si) > 0) return false;
64 0 : if(sh.num<ConstrainingQuadrilateral>(si) > 0) return false;
65 :
66 : // if not found, subset describes a regular grid
67 : return true;
68 : }
69 :
70 : /// returns if a subset is a regular grid
71 0 : bool SubsetIsRegularGrid(const ISubsetHandler& ish, int si)
72 : {
73 : // test SubsetHandler
74 0 : const SubsetHandler* sh = dynamic_cast<const SubsetHandler*>(&ish);
75 0 : if(sh != NULL)
76 0 : return SubsetIsRegularGrid(*sh, si);
77 :
78 : // test MGSubsetHandler
79 0 : const MGSubsetHandler* mgsh = dynamic_cast<const MGSubsetHandler*>(&ish);
80 0 : if(mgsh != NULL)
81 0 : return SubsetIsRegularGrid(*mgsh, si);
82 :
83 : // unknown type of subset handler
84 0 : UG_THROW("Unknown SubsetHandler type.");
85 : return false;
86 : }
87 :
88 : /// returns the current dimension of the subset
89 0 : int DimensionOfSubset(const ISubsetHandler& sh, int si)
90 : {
91 : try{
92 0 : return sh.subset_info(si).get_property("dim").to_int();
93 : }
94 0 : UG_CATCH_THROW("Make sure to properly set the dim-property of each subset "
95 : "before calling DimensionOfSubset! Use e.g. "
96 : "Domain::update_local_subset_dim_property, "
97 : "Domain::update_global_subset_dim_property, "
98 : "UpdateMaxDimensionOfSubset or UpdateGlobalMaxDimensionOfSubset.");
99 : }
100 :
101 0 : int DimensionOfSubsets(const ISubsetHandler& sh)
102 : {
103 : // dimension to be computed
104 : int dim = DIM_SUBSET_EMPTY_GRID;
105 :
106 : // loop subsets
107 0 : for(int si = 0; si < sh.num_subsets(); ++si)
108 : {
109 : // get dimension of subset
110 0 : int siDim = DimensionOfSubset(sh, si);
111 :
112 : // if empty grid given, skip
113 0 : if(siDim == DIM_SUBSET_EMPTY_GRID) continue;
114 :
115 : // check if dimension is higher than already checked subsets
116 0 : if(dim < siDim)
117 : dim = siDim;
118 : }
119 :
120 : // return computed domain
121 0 : return dim;
122 : }
123 :
124 : } // end namespace ug
|