Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
overlying_subset_finder.hpp
Go to the documentation of this file.
4#ifdef UG_PARALLEL
8#endif
10
11namespace ug {
12
13 template <typename TDomain>
15 {
16 static const int dim = TDomain::dim;
17 typedef TDomain domain_type;
18
19 typedef typename grid_dim_traits<dim-1>::element_type side_t;
20
22
24
25 typedef typename domain_type::position_attachment_type position_attachment_type;
26 typedef typename domain_type::position_accessor_type position_accessor_type;
27
29
30 public:
31
33 SmartPtr<TDomain> sp_domain,
34 const std::string & top_ss_names)
35 : m_sp_domain (sp_domain),
36 m_top_ss_grp (sp_domain->subset_handler (), TokenizeString (top_ss_names))
37 {
38
39 MultiGrid & mg = * m_sp_domain->grid ();
40 MGSubsetHandler & sh = * m_sp_domain->subset_handler ();
41 std::vector<side_t*> topSides;
42
43 m_top_tracer_tree.set_grid(m_top_grid, m_sp_domain->position_attachment ());
44
47
49 subset_index_accessor.access(mg, subset_index_attachment);
50
51 // select the Sides on the top
52 Selector sel (mg);
53 for (size_t i = 0; i < m_top_ss_grp.size (); i++)
54 {
55 int si = m_top_ss_grp [i];
56
57 for (SideIterator it = sh.begin<side_t> (si, 0); it != sh.end<side_t> (si, 0); ++it)
58 {
59 sel.select (*it);
60 subset_index_accessor[*it] = si;
61 }
62 }
63
65 accessor.access(mg, m_sp_domain->position_attachment());
66
67
68 //UG_LOG_ALL_PROCS("Total count of Edges on this node before distributing: " << sel.num<side_t>() << std::endl);
69
70 // for (SideIterator it = sel.begin<side_t>(); it != sel.end<side_t>(); ++it)
71 // {
72 // UG_LOG_ALL_PROCS(subset_index_accessor[(*it)] << ": " << accessor[(*it)->vertex(0)] << "-" << accessor[(*it)->vertex(1)] << std::endl);
73 // }
74
75 // copy the top Sides into a new grid
76
77 #ifdef UG_PARALLEL
78
80 serializer.add
82 serializer.add
84
86 deserializer.add
88 deserializer.add
90
91 BroadcastGrid (m_top_grid, sel, serializer, deserializer, 0);
92
93 #endif
94
95 for (SideIterator it = m_top_grid.begin<side_t> (); it != m_top_grid.end<side_t> (); ++it)
96 topSides.push_back (*it);
97
98 m_top_tracer_tree.create_tree (topSides.begin (), topSides.end ());
99
100 // debug();
101
102 // SaveGridToFile(m_top_grid, mkstr("top_grid_p" << pcl::ProcRank() << ".ugx").c_str(),
103 // m_sp_domain->position_attachment());
104 }
105
106 std::string findOverlyingSubset(const std::vector<number> & point)
107 {
108
109 if (point.size () != dim)
110 UG_THROW ("OverlyingSubsetFinder::findOverlyingSubset: Exactly " << dim << " coordinates have to be specified!");
111
112 MathVector<dim> measure_point;
113
114 for(size_t d = 0; d < dim; d++)
115 {
116 measure_point[d] = point[d];
117 }
118
119 // find all the intersections
120 MathVector<dim> up_dir;
121 up_dir = 0;
122 up_dir [dim - 1] = 1;
125
126 // check if there are intersections at all
127 if (m_top_intersection_records.size () == 0)
128 return "";
129
131 subset_index_accessor.access(m_top_grid, subset_index_attachment);
132
133 //debug();
134
135 // find the lowest point
136 MathVector<dim> x = PointOnRay (measure_point, up_dir, m_top_intersection_records[0].smin);
137 number z_min = x [dim - 1];
138 int si = subset_index_accessor[m_top_intersection_records[0].elem];
139
140 // UG_LOG("<dbg> x: " << x << std::endl);
141 for (size_t i = 1; i < m_top_intersection_records.size (); i++)
142 {
144 x = PointOnRay (measure_point, up_dir, r.smin);
145 if (x [dim - 1] < z_min)
146 {
147 z_min = x [dim - 1];
148 si = subset_index_accessor[r.elem];
149 }
150 }
151
152 return m_sp_domain->subset_handler ()->get_subset_name(si);
153 }
154
155 void debug()
156 {
157 position_accessor_type accessor;
158 accessor.access(m_top_grid, m_sp_domain->position_attachment());
159
161 subset_index_accessor.access(m_top_grid, subset_index_attachment);
162
163 UG_LOG_ALL_PROCS("Total count of Edges: " << m_top_grid.num<side_t>() << std::endl);
164
165 for (SideIterator it = m_top_grid.begin<side_t>(); it != m_top_grid.end<side_t>(); ++it)
166 {
167 UG_LOG_ALL_PROCS(subset_index_accessor[(*it)] << ": ");
168 for (size_t i = 0; i < dim; i++)
169 {
170 UG_LOG_ALL_PROCS(accessor[(*it)->vertex(i)] << "-");
171 }
172 UG_LOG_ALL_PROCS(std::endl);
173 }
174
175 }
176
177 private:
179
183
185
187 std::vector<top_intersection_record_t> m_top_intersection_records;
188
189 };
190
191}
Definition smart_pointer.h:108
A generic specialization of IAttachment.
Definition attachment_pipe.h:263
Serialization callback for grid attachments.
Definition serialization.h:290
the generic attachment-accessor for access to grids attachment pipes.
Definition grid.h:182
bool access(Grid &grid, TAttachment &a)
Definition grid.h:189
Serialization of data associated with grid elements.
Definition serialization.h:186
void add(SPVertexDataSerializer cb)
Adds a callback class for serialization and deserialization.
Definition serialization.cpp:69
Manages the elements of a grid and their interconnection.
Definition grid.h:132
size_t num() const
Definition grid_impl.hpp:230
void attach_to(IAttachment &attachment, bool passOnValues)
attach with custom pass-on-behaviour and unspecified default value.
Definition grid_impl.hpp:296
geometry_traits< TGeomObj >::iterator begin()
Definition grid_impl.hpp:164
geometry_traits< TGeomObj >::iterator end()
Definition grid_impl.hpp:175
void select(GridObject *elem, byte status)
selects an element
Definition selector_interface_impl.hpp:56
a mathematical Vector with N entries.
Definition math_vector.h:97
Definition multi_grid.h:72
Handles subsets on a per level basis.
Definition subset_handler_multi_grid.h:60
geometry_traits< TElem >::iterator end(int subsetIndex, int level)
returns the end-iterator for the elements of type TElem in the given subset.
Definition subset_handler_multi_grid_impl.hpp:64
geometry_traits< TElem >::iterator begin(int subsetIndex, int level)
returns the begin-iterator for the elements of type TElem in the given subset.
Definition subset_handler_multi_grid_impl.hpp:44
Definition overlying_subset_finder.hpp:15
OverlyingSubsetFinder(SmartPtr< TDomain > sp_domain, const std::string &top_ss_names)
Definition overlying_subset_finder.hpp:32
Attachment< int > subset_index_attachment
Definition overlying_subset_finder.hpp:182
SmartPtr< domain_type > m_sp_domain
Definition overlying_subset_finder.hpp:178
void debug()
Definition overlying_subset_finder.hpp:155
grid_dim_traits< dim-1 >::element_type side_t
Definition overlying_subset_finder.hpp:19
SubsetGroup m_top_ss_grp
Definition overlying_subset_finder.hpp:180
domain_type::position_accessor_type position_accessor_type
Definition overlying_subset_finder.hpp:26
static const int dim
Definition overlying_subset_finder.hpp:16
Grid::traits< side_t >::iterator SideIterator
Definition overlying_subset_finder.hpp:28
lg_ntree< dim-1, dim, side_t > top_tracer_tree_t
Definition overlying_subset_finder.hpp:21
top_tracer_tree_t m_top_tracer_tree
Definition overlying_subset_finder.hpp:184
RayElemIntersectionRecord< side_t * > top_intersection_record_t
Definition overlying_subset_finder.hpp:23
std::vector< top_intersection_record_t > m_top_intersection_records
array to store all the intersections
Definition overlying_subset_finder.hpp:187
domain_type::position_attachment_type position_attachment_type
Definition overlying_subset_finder.hpp:25
std::string findOverlyingSubset(const std::vector< number > &point)
Definition overlying_subset_finder.hpp:106
TDomain domain_type
Definition overlying_subset_finder.hpp:17
Grid m_top_grid
Definition overlying_subset_finder.hpp:181
specialization of ISelector for a grid of class Grid.
Definition selector_grid.h:96
Group of subsets.
Definition subset_group.h:51
size_t size() const
number of subsets in this group
Definition subset_group.h:122
Definition lg_ntree.h:338
void set_grid(Grid &grid, position_attachment_t aPos)
Definition lg_ntree.h:350
void create_tree(TIterator elemsBegin, TIterator elemsEnd)
Definition lg_ntree.h:356
#define UG_LOG_ALL_PROCS(msg)
Definition log.h:371
#define UG_THROW(msg)
Definition error.h:57
double number
Definition types.h:124
vector_t PointOnRay(const vector_t &from, const vector_t &dir, number s)
returns the point described by a relative ray coordinate
Definition math_util_impl.hpp:150
function util LuaCallbackHelper create(func)
the ug namespace
bool RayElementIntersections(std::vector< RayElemIntersectionRecord< typename tree_t::elem_t > > &intersectionsOut, const tree_t &tree, const typename tree_t::vector_t &rayFrom, const typename tree_t::vector_t &rayDir, const number small=1.e-12)
Definition ntree_traverser.h:386
void TokenizeString(const string &str, vector< string > &vToken, const char delimiter)
Definition string_util.cpp:56
void BroadcastGrid(Grid &gridOut, Selector &sel, GridDataSerializationHandler &serializer, GridDataSerializationHandler &deserializer, int root, const pcl::ProcessCommunicator &procCom)
Broadcasts the specified Selection from 'root' to all processes in procCom.
Definition broadcast.cpp:38
geometry_traits< TElem >::iterator iterator
Definition grid.h:143
Definition ntree_traverser.h:310
Definition grid_dim_traits.h:53