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 <vector>
34 : #include <string>
35 : #include <sstream>
36 :
37 : // include bridge
38 : #include "bridge/bridge.h"
39 : #include "bridge/util.h"
40 : #include "bridge/util_domain_dependent.h"
41 :
42 : #include "lib_disc/domain.h"
43 : #include "lib_grid/lib_grid.h"
44 :
45 : using namespace std;
46 :
47 : namespace ug{
48 :
49 : /**
50 : * \defgroup selection_bridge Selection Bridge
51 : * \ingroup domain_bridge
52 : * \{
53 : */
54 :
55 : ////////////////////////////////////////////////////////////////////////////////
56 : /// Selects / Deselects all elements
57 0 : void SelectDomainElements(ISelector& sel, bool bSelect, bool selectVrts,
58 : bool selectEdges, bool selectFaces, bool selectVolumes)
59 : {
60 : Grid* g = sel.grid();
61 :
62 0 : if(!g)
63 : return;
64 :
65 0 : ISelector::status_t status = bSelect ? ISelector::SELECTED
66 : : ISelector::DESELECTED;
67 :
68 0 : if(selectVrts)
69 0 : sel.select(g->begin<Vertex>(), g->end<Vertex>(), status);
70 0 : if(selectEdges)
71 0 : sel.select(g->begin<Edge>(), g->end<Edge>(), status);
72 0 : if(selectFaces)
73 0 : sel.select(g->begin<Face>(), g->end<Face>(), status);
74 0 : if(selectVolumes)
75 0 : sel.select(g->begin<Volume>(), g->end<Volume>(), status);
76 : }
77 :
78 : ////////////////////////////////////////////////////////////////////////////////
79 : /// Selects / Deselects associated (low dimensional) elements.
80 0 : void SelectAssociatedElements(ISelector& sel, bool bSelect, bool selectVrts,
81 : bool selectEdges, bool selectFaces)
82 : {
83 0 : ISelector::status_t status = bSelect ? ISelector::SELECTED
84 : : ISelector::DESELECTED;
85 :
86 :
87 0 : GridObjectCollection goc = sel.get_grid_objects();
88 :
89 0 : for(size_t lvl = 0; lvl < goc.num_levels(); ++lvl){
90 0 : if(selectVrts){
91 0 : SelectAssociated<Vertex>(sel, goc.begin<Edge>(lvl),
92 0 : goc.end<Edge>(lvl), status);
93 0 : SelectAssociated<Vertex>(sel, goc.begin<Face>(lvl),
94 0 : goc.end<Face>(lvl), status);
95 0 : SelectAssociated<Vertex>(sel, goc.begin<Volume>(lvl),
96 0 : goc.end<Volume>(lvl), status);
97 : }
98 0 : if(selectEdges){
99 0 : SelectAssociated<Edge>(sel, goc.begin<Face>(lvl),
100 0 : goc.end<Face>(lvl), status);
101 0 : SelectAssociated<Edge>(sel, goc.begin<Volume>(lvl),
102 0 : goc.end<Volume>(lvl), status);
103 : }
104 :
105 0 : if(selectFaces){
106 0 : SelectAssociated<Face>(sel, goc.begin<Volume>(lvl),
107 0 : goc.end<Volume>(lvl), status);
108 : }
109 : }
110 0 : }
111 :
112 : ////////////////////////////////////////////////////////////////////////////////
113 : /// Selects / Deselects elements in the given subset of the given domain
114 : template <class TDomain>
115 0 : void SelectDomainSubset(ISelector& sel, TDomain& dom, int subsetIndex,
116 : bool bSelect, bool selectVrts, bool selectEdges,
117 : bool selectFaces, bool selectVolumes)
118 : {
119 0 : ISubsetHandler& sh = *dom.subset_handler();
120 :
121 0 : ISelector::status_t status = bSelect ? ISelector::SELECTED
122 : : ISelector::DESELECTED;
123 :
124 0 : if(selectVrts)
125 0 : SelectSubsetElements<Vertex>(sel, sh, subsetIndex, status);
126 0 : if(selectEdges)
127 0 : SelectSubsetElements<Edge>(sel, sh, subsetIndex, status);
128 0 : if(selectFaces)
129 0 : SelectSubsetElements<Face>(sel, sh, subsetIndex, status);
130 0 : if(selectVolumes)
131 0 : SelectSubsetElements<Volume>(sel, sh, subsetIndex, status);
132 0 : }
133 :
134 : // end group selection_bridge
135 : /// \}
136 :
137 : ////////////////////////////////////////////////////////////////////////////////
138 : ////////////////////////////////////////////////////////////////////////////////
139 : namespace bridge{
140 : namespace Selection{
141 :
142 : /// \addtogroup selection_bridge
143 : /// \{
144 :
145 : /**
146 : * Class exporting the functionality. All functionality that is to
147 : * be used in scripts or visualization must be registered here.
148 : */
149 : struct Functionality
150 : {
151 :
152 : /**
153 : * Function called for the registration of Domain and Algebra independent parts.
154 : * All Functions and Classes not depending on Domain and Algebra
155 : * are to be placed here when registering.
156 : *
157 : * @param reg registry
158 : * @param parentGroup group for sorting of functionality
159 : */
160 1 : static void Common(Registry& reg, string grp)
161 : {
162 : // register domain independent mark methods
163 3 : reg.add_function("SelectDomainElements", &SelectDomainElements, grp, "", "sel#bSelect#selectVrts#selectEdges#selectFaces#selectVolumes");
164 3 : reg.add_function("SelectAssociatedElements", &SelectAssociatedElements, grp, "", "sel#bSelect#selectVrts#selectEdges#selectFaces");
165 1 : }
166 :
167 : /**
168 : * Function called for the registration of Domain dependent parts.
169 : * All Functions and Classes depending on the Domain
170 : * are to be placed here when registering. The method is called for all
171 : * available Domain types, based on the current build options.
172 : *
173 : * @param reg registry
174 : * @param parentGroup group for sorting of functionality
175 : */
176 : template <typename TDomain>
177 3 : static void Domain(Registry& reg, string grp)
178 : {
179 : typedef TDomain domain_type;
180 :
181 9 : reg.add_function("SelectDomainSubset",
182 : &SelectDomainSubset<domain_type>, grp,
183 : "", "sel#dom#subsetIndex#bSelect#selectVrts#selectEdges#selectFaces#selectVolumes");
184 3 : }
185 :
186 : }; // end Functionality
187 :
188 : // end group selection_bridge
189 : /// \}
190 :
191 : }// end Refinement
192 :
193 : /// \addtogroup selection_bridge
194 1 : void RegisterBridge_Selection(Registry& reg, string grp)
195 : {
196 1 : grp.append("/Selection");
197 : typedef Selection::Functionality Functionality;
198 :
199 : try{
200 2 : RegisterCommon<Functionality>(reg, grp);
201 1 : RegisterDomainDependent<Functionality>(reg, grp);
202 : }
203 0 : UG_REGISTRY_CATCH_THROW(grp);
204 1 : }
205 :
206 : }// end of namespace bridge
207 : }// end of namespace ug
|