ug4
Loading...
Searching...
No Matches
z_ray_tracer.hpp
Go to the documentation of this file.
1#include <vector>
2#include <string>
5#ifdef UG_PARALLEL
8#endif
9#include "common/common.h"
10
11namespace ug
12{
13
14template <typename TDomain>
16{
17
19 typedef TDomain domain_type;
20
22 static const int dim = domain_type::dim;
23
25 typedef typename domain_type::position_attachment_type position_attachment_type;
26
28 typedef typename grid_dim_traits<dim-1>::element_type side_t;
29
31
33
34public:
35
38 (
39 SmartPtr<domain_type> sp_domain,
40 const std::string & top_ss_names,
41 int grid_level,
42 bool useLocalTopFacesOnly = false
43 )
44 : m_sp_domain (sp_domain),
45 m_top_ss_grp (sp_domain->subset_handler (), TokenizeString (top_ss_names))
46 {
47 #ifndef UG_PARALLEL
48 useLocalTopFacesOnly = true;
49 #endif
50
51 typedef typename Grid::traits<side_t>::iterator SideIterator;
52
53 MultiGrid & mg = * m_sp_domain->grid ();
54 MGSubsetHandler & sh = * m_sp_domain->subset_handler ();
55 std::vector<side_t*> topSides;
56
57 // get all the elements to collect
58 if(useLocalTopFacesOnly){
59 m_top_tracer_tree.set_grid(*m_sp_domain->grid (), m_sp_domain->position_attachment ());
60 for (size_t i = 0; i < m_top_ss_grp.size (); i++)
61 {
62 int si = m_top_ss_grp [i];
63
64 if (grid_level >= 0){ // if the grid level for the top is specified
65 for (SideIterator it = sh.begin<side_t> (si, grid_level);
66 it != sh.end<side_t> (si, grid_level); ++it)
67 topSides.push_back (*it);
68 }
69 else{
70 for (int lvl = 0; lvl < (int) sh.num_levels(); lvl++){
71 for (SideIterator it = sh.begin<side_t> (si, lvl);
72 it != sh.end<side_t> (si, lvl); ++it)
73 {
74 side_t* t = *it;
75 if (! mg.has_children (t))
76 topSides.push_back (t);
77 }
78 }
79 }
80 }
81 }
82 else {
83 #ifdef UG_PARALLEL
84 m_top_tracer_tree.set_grid(m_top_grid, m_sp_domain->position_attachment ());
85
87
88 // select the Sides on the top
89 Selector sel (mg);
90 for (size_t i = 0; i < m_top_ss_grp.size (); i++)
91 {
92 int si = m_top_ss_grp [i];
93
94 if (grid_level >= 0) // if the grid level for the top is specified
95 for (SideIterator it = sh.begin<side_t> (si, grid_level);
96 it != sh.end<side_t> (si, grid_level); ++it)
97 sel.select (*it);
98 else
99 for (int lvl = 0; lvl < (int) sh.num_levels(); lvl++)
100 for (SideIterator it = sh.begin<side_t> (si, lvl);
101 it != sh.end<side_t> (si, lvl); ++it)
102 {
103 side_t* t = *it;
104 if (! (mg.has_children (t) || (dgm && dgm->is_ghost(t))))
105 sel.select (t);
106 }
107 }
108
109 // copy the top Sides into a new grid
111 serializer.add
113
114 GridDataSerializationHandler deserializer;
115 deserializer.add
117
118 AllGatherGrid (m_top_grid, sel, serializer, deserializer);
119
120 for (SideIterator it = m_top_grid.begin<side_t> (); it != m_top_grid.end<side_t> (); ++it)
121 topSides.push_back (*it);
122
123 // UG_LOG("DEBUG: SAVING allgathered m_top_grid to file in ls_init...\n");
124 // SaveGridToFile(m_top_grid, mkstr("top_grid_p" << pcl::ProcRank() << ".ugx").c_str(),
125 // m_sp_domain->position_attachment());
126 #endif
127 }
128 // compose the tree
129 m_top_tracer_tree.create_tree (topSides.begin (), topSides.end ());
130 }
131
134 (
135 const MathVector<dim> & over,
136 number tolerance,
137 number & z
138 )
139 {
140 // find all the intersections
141 MathVector<dim> up_dir;
142 up_dir = 0;
143 up_dir [dim - 1] = 1;
146
147 // check if there are intersections at all
148 if (m_top_intersection_records.size () == 0)
149 return false;
150
151 // find the lowest point
152 MathVector<dim> x = PointOnRay (over, up_dir, m_top_intersection_records[0].smin);
153 number z_min = x [dim - 1];
154 // UG_LOG("<dbg> x: " << x << std::endl);
155 for (size_t i = 1; i < m_top_intersection_records.size (); i++)
156 {
158 x = PointOnRay (over, up_dir, r.smin);
159 if (x [dim - 1] < z_min)
160 z_min = x [dim - 1];
161 }
162
163 z = z_min;
164 return true;
165 }
166
167private:
168
171
174
175# ifdef UG_PARALLEL
178# endif
181
183 std::vector<top_intersection_record_t> m_top_intersection_records;
184};
185
186}
Definition smart_pointer.h:108
manages the layouts and interfaces which are associated with a distributed grid.
Definition distributed_grid.h:88
bool is_ghost(TElem *elem) const
returns true if the element is a ghost
Definition distributed_grid_impl.hpp:67
Serialization callback for grid attachments.
Definition serialization.h:290
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
DistributedGridManager * distributed_grid_manager()
returns a pointer to the associated distributed grid manager.
Definition grid_impl.hpp:53
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
bool has_children(TElem *elem) const
Definition multi_grid.h:217
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
uint num_levels() const
returns the number of levels
Definition subset_handler_multi_grid.h:80
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
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 z_ray_tracer.hpp:16
bool get_min_at(const MathVector< dim > &over, number tolerance, number &z)
computes the minimum z-coordiate of the top (returns true if the top found, false otherwise)
Definition z_ray_tracer.hpp:134
domain_type::position_attachment_type position_attachment_type
type of the position accessor
Definition z_ray_tracer.hpp:25
ZRayTracer(SmartPtr< domain_type > sp_domain, const std::string &top_ss_names, int grid_level, bool useLocalTopFacesOnly=false)
class constructor
Definition z_ray_tracer.hpp:38
SmartPtr< domain_type > m_sp_domain
multigrid of the domain
Definition z_ray_tracer.hpp:170
lg_ntree< dim-1, dim, side_t > top_tracer_tree_t
Definition z_ray_tracer.hpp:30
std::vector< top_intersection_record_t > m_top_intersection_records
array to store all the intersections
Definition z_ray_tracer.hpp:183
grid_dim_traits< dim-1 >::element_type side_t
side type
Definition z_ray_tracer.hpp:28
SubsetGroup m_top_ss_grp
subset group of the top faces
Definition z_ray_tracer.hpp:173
Grid m_top_grid
auxiliary grid of the top faces
Definition z_ray_tracer.hpp:177
RayElemIntersectionRecord< side_t * > top_intersection_record_t
Definition z_ray_tracer.hpp:32
static const int dim
world dimension
Definition z_ray_tracer.hpp:22
top_tracer_tree_t m_top_tracer_tree
tracer tree of the top faces
Definition z_ray_tracer.hpp:180
TDomain domain_type
grid function type
Definition z_ray_tracer.hpp:19
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
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
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 AllGatherGrid(Grid &gridOut, Selector &sel, GridDataSerializationHandler &serializer, GridDataSerializationHandler &deserializer, const pcl::ProcessCommunicator &procCom)
AllGathers selected parts of a grid into 'gridOut'.
Definition gather_grid.cpp:83
geometry_traits< TElem >::iterator iterator
Definition grid.h:143
Definition ntree_traverser.h:310
Definition grid_dim_traits.h:53