Line data Source code
1 : /*
2 : * Copyright (c) 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 "registry/registry.h"
35 : #include "bridge/bridge.h"
36 : #include "bridge/util.h"
37 : #include "bridge/util_domain_dependent.h"
38 : #include "lib_grid/algorithms/space_partitioning/lg_ntree.h"
39 : #include "lib_grid/tools/subset_group.h"
40 :
41 : #include <lib_grid/algorithms/projections/overlying_subset_finder.hpp>
42 :
43 : using namespace std;
44 :
45 : namespace ug{
46 :
47 : /// TEMPORARY QUICK HACK! DON'T USE! WILL BE REPLACED SOON!
48 : class DomainRayTracer {
49 : public:
50 : typedef vector3 vector_t;
51 :
52 0 : DomainRayTracer(Domain3d& dom) :
53 0 : m_tree(*dom.grid(), dom.position_attachment()),
54 0 : m_small(SMALL),
55 0 : m_dom(&dom)
56 0 : {}
57 :
58 0 : void set_small(number small) {m_small = small;}
59 :
60 0 : void init (const std::vector<int>& subsetIndices)
61 : {
62 0 : MultiGrid& mg = *m_dom->grid();
63 0 : MGSubsetHandler& sh = *m_dom->subset_handler();
64 :
65 : std::vector<Triangle*> tris;
66 0 : for(size_t is = 0; is < subsetIndices.size(); ++is){
67 0 : int si = subsetIndices[is];
68 0 : for(int lvl = 0; lvl < (int)sh.num_levels(); ++lvl){
69 0 : for(TriangleIterator it = sh.begin<Triangle>(si, lvl);
70 0 : it != sh.end<Triangle>(si, lvl); ++it)
71 : {
72 0 : Triangle* t = *it;
73 : if(!mg.has_children(t))
74 0 : tris.push_back(t);
75 : }
76 : }
77 : }
78 :
79 0 : m_tree.create_tree(tris.begin(), tris.end());
80 0 : }
81 :
82 0 : void init (const char* subsetNames)
83 : {
84 0 : SubsetGroup ssGrp(m_dom->subset_handler());
85 0 : ssGrp.add(TokenizeString(subsetNames));
86 0 : init(ssGrp.index_vector());
87 0 : }
88 :
89 0 : size_t trace_ray(const vector_t& from, const vector_t& dir)
90 : {
91 : m_tracePoints.clear();
92 0 : RayElementIntersections(m_intersectionRecords, m_tree, from, dir, m_small);
93 0 : for_each_in_vec(intersection_record_t& r, m_intersectionRecords){
94 0 : m_tracePoints.push_back(PointOnRay(from, dir, r.smin));
95 : }end_for;
96 0 : return m_tracePoints.size();
97 : }
98 :
99 0 : size_t num_trace_points() const {return m_tracePoints.size();}
100 0 : const vector_t& trace_point(size_t i) const {return m_tracePoints[i];}
101 0 : number trace_point_x(size_t i) const {return m_tracePoints[i].x();}
102 0 : number trace_point_y(size_t i) const {return m_tracePoints[i].y();}
103 0 : number trace_point_z(size_t i) const {return m_tracePoints[i].z();}
104 :
105 : // size_t closest_point_index() const
106 : // {
107 : // if(m_tracePoints.empty())
108 : // return 0;
109 :
110 : // // todo: use local-ray-coord
111 : // size_t index = 0;
112 : // number minDistSq = VecDistanceSq(m_from, m_tracePoints[0]);
113 : // for(size_t i = 1; i < m_tracePoints.size(); ++i){
114 : // number distSq = VecDistanceSq(m_from, m_tracePoints[i]);
115 : // if(distSq < minDistSq){
116 : // minDistSq = distSq;
117 : // index = i;
118 : // }
119 : // }
120 :
121 : // return index;
122 : // }
123 :
124 : /// local coordinate regarding trace-ray
125 : // number local_trace_point_coordinate(size_t i) const;
126 :
127 : // int trace_point_subset_index(size_t i) const;
128 :
129 : private:
130 : typedef lg_ntree<3, 3, Triangle> tree_t;
131 : typedef RayElemIntersectionRecord<Triangle*> intersection_record_t;
132 :
133 : std::vector<vector_t> m_tracePoints;
134 : std::vector<intersection_record_t> m_intersectionRecords;
135 : tree_t m_tree;
136 : number m_small;
137 : Domain3d* m_dom;
138 : };
139 :
140 :
141 :
142 : namespace bridge {
143 : namespace domain_ray_tracing {
144 :
145 : struct Functionality {
146 :
147 1 : static void Common(Registry& reg, string grp)
148 : {
149 : typedef DomainRayTracer T;
150 :
151 3 : reg.add_class_<DomainRayTracer>("DomainRayTracer", grp)
152 2 : .add_constructor<void (*)(Domain3d&)> ()
153 2 : .add_method("set_small", &T::set_small, "", "small", "")
154 2 : .add_method("init", static_cast<void (T::*) (const std::vector<int>&)>(&T::init), "", "subsetIndices", "")
155 2 : .add_method("init", static_cast<void (T::*) (const char*)>(&T::init), "", "subsetNames", "")
156 2 : .add_method("trace_ray", &T::trace_ray, "", "rayFrom # rayTo", "")
157 2 : .add_method("num_trace_points", &T::num_trace_points, "numPoints", "", "")
158 2 : .add_method("trace_point", &T::trace_point, "point", "index", "")
159 2 : .add_method("trace_point_x", &T::trace_point_x, "xCoord", "index", "")
160 2 : .add_method("trace_point_y", &T::trace_point_y, "yCoord", "index", "")
161 2 : .add_method("trace_point_z", &T::trace_point_z, "zCoord", "index", "");
162 1 : }
163 :
164 :
165 :
166 : /**
167 : * Function called for the registration of Domain dependent parts.
168 : * All Functions and Classes depending on the Domain
169 : * are to be placed here when registering. The method is called for all
170 : * available Domain types, based on the current build options.
171 : *
172 : * @param reg registry
173 : * @param parentGroup group for sorting of functionality
174 : */
175 : template <typename TDomain>
176 2 : static void Domain(Registry& reg, string grp)
177 : {
178 : typedef TDomain domain_type;
179 :
180 : typedef OverlyingSubsetFinder<TDomain> T;
181 :
182 : string suffix = GetDomainSuffix<TDomain>();
183 : string tag = GetDomainTag<TDomain>();
184 :
185 :
186 2 : string name = string("OverlyingSubsetFinder").append(suffix);
187 :
188 6 : reg.add_class_<T>(name, grp)
189 4 : .template add_constructor<void (*)(SmartPtr<domain_type>, const std::string& subsets)> ()
190 4 : .add_method("findOverlyingSubset", &T::findOverlyingSubset, "", "point to search over", "")
191 2 : .set_construct_as_smart_pointer(true);
192 6 : reg.add_class_to_group(name, "OverlyingSubsetFinder", tag);
193 :
194 2 : }
195 :
196 : }; // end Functionality
197 :
198 : } // end of namespace domain_ray_tracing
199 :
200 1 : void RegisterBridge_DomainRayTracing(Registry& reg, string grp) {
201 1 : grp.append("/RayTracing");
202 :
203 : try {
204 2 : RegisterDomain2d3dDependent<domain_ray_tracing::Functionality>(reg, grp);
205 : #ifdef UG_DIM_3
206 1 : RegisterCommon<domain_ray_tracing::Functionality>(reg, grp);
207 : #endif
208 0 : } UG_REGISTRY_CATCH_THROW(grp);
209 1 : }
210 :
211 : } // end of namespace bridge
212 : }// end of namespace ug
|