Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
z_ray_tracer.hpp
Go to the documentation of this file.
1#include <vector>
2#include <string>
7#include "common/common.h"
8
9namespace ug
10{
11
12template <typename TDomain>
14{
15
17 typedef TDomain domain_type;
18
20 static const int dim = domain_type::dim;
21
23 typedef typename domain_type::position_attachment_type position_attachment_type;
24
26 typedef typename grid_dim_traits<dim-1>::element_type side_t;
27
29
31
32public:
33
36 (
37 SmartPtr<domain_type> sp_domain,
38 const std::string & top_ss_names,
39 int grid_level,
40 bool useLocalTopFacesOnly = false
41 )
42 : m_sp_domain (sp_domain),
43 m_top_ss_grp (sp_domain->subset_handler (), TokenizeString (top_ss_names))
44 {
45 #ifndef UG_PARALLEL
46 useLocalTopFacesOnly = true;
47 #endif
48
49 typedef typename Grid::traits<side_t>::iterator SideIterator;
50
51 MultiGrid & mg = * m_sp_domain->grid ();
52 MGSubsetHandler & sh = * m_sp_domain->subset_handler ();
53 std::vector<side_t*> topSides;
54
55 // get all the elements to collect
56 if(useLocalTopFacesOnly){
57 m_top_tracer_tree.set_grid(*m_sp_domain->grid (), m_sp_domain->position_attachment ());
58 for (size_t i = 0; i < m_top_ss_grp.size (); i++)
59 {
60 int si = m_top_ss_grp [i];
61
62 if (grid_level >= 0){ // if the grid level for the top is specified
63 for (SideIterator it = sh.begin<side_t> (si, grid_level);
64 it != sh.end<side_t> (si, grid_level); ++it)
65 topSides.push_back (*it);
66 }
67 else{
68 for (int lvl = 0; lvl < (int) sh.num_levels(); lvl++){
69 for (SideIterator it = sh.begin<side_t> (si, lvl);
70 it != sh.end<side_t> (si, lvl); ++it)
71 {
72 side_t* t = *it;
73 if (! mg.has_children (t))
74 topSides.push_back (t);
75 }
76 }
77 }
78 }
79 }
80 else {
81 #ifdef UG_PARALLEL
82 m_top_tracer_tree.set_grid(m_top_grid, m_sp_domain->position_attachment ());
83
85
86 // select the Sides on the top
87 Selector sel (mg);
88 for (size_t i = 0; i < m_top_ss_grp.size (); i++)
89 {
90 int si = m_top_ss_grp [i];
91
92 if (grid_level >= 0) // if the grid level for the top is specified
93 for (SideIterator it = sh.begin<side_t> (si, grid_level);
94 it != sh.end<side_t> (si, grid_level); ++it)
95 sel.select (*it);
96 else
97 for (int lvl = 0; lvl < (int) sh.num_levels(); lvl++)
98 for (SideIterator it = sh.begin<side_t> (si, lvl);
99 it != sh.end<side_t> (si, lvl); ++it)
100 {
101 side_t* t = *it;
102 if (! (mg.has_children (t) || (dgm && dgm->is_ghost(t))))
103 sel.select (t);
104 }
105 }
106
107 // copy the top Sides into a new grid
109 serializer.add
111
112 GridDataSerializationHandler deserializer;
113 deserializer.add
115
116 AllGatherGrid (m_top_grid, sel, serializer, deserializer);
117
118 for (SideIterator it = m_top_grid.begin<side_t> (); it != m_top_grid.end<side_t> (); ++it)
119 topSides.push_back (*it);
120
121 // UG_LOG("DEBUG: SAVING allgathered m_top_grid to file in ls_init...\n");
122 // SaveGridToFile(m_top_grid, mkstr("top_grid_p" << pcl::ProcRank() << ".ugx").c_str(),
123 // m_sp_domain->position_attachment());
124 #endif
125 }
126 // compose the tree
127 m_top_tracer_tree.create_tree (topSides.begin (), topSides.end ());
128 }
129
132 (
133 const MathVector<dim> & over,
134 number tolerance,
135 number & z
136 )
137 {
138 // find all the intersections
139 MathVector<dim> up_dir;
140 up_dir = 0;
141 up_dir [dim - 1] = 1;
144
145 // check if there are intersections at all
146 if (m_top_intersection_records.size () == 0)
147 return false;
148
149 // find the lowest point
150 MathVector<dim> x = PointOnRay (over, up_dir, m_top_intersection_records[0].smin);
151 number z_min = x [dim - 1];
152 // UG_LOG("<dbg> x: " << x << std::endl);
153 for (size_t i = 1; i < m_top_intersection_records.size (); i++)
154 {
156 x = PointOnRay (over, up_dir, r.smin);
157 if (x [dim - 1] < z_min)
158 z_min = x [dim - 1];
159 }
160
161 z = z_min;
162 return true;
163 }
164
165private:
166
169
172
173# ifdef UG_PARALLEL
176# endif
179
181 std::vector<top_intersection_record_t> m_top_intersection_records;
182};
183
184}
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:14
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:132
domain_type::position_attachment_type position_attachment_type
type of the position accessor
Definition z_ray_tracer.hpp:23
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:36
SmartPtr< domain_type > m_sp_domain
multigrid of the domain
Definition z_ray_tracer.hpp:168
lg_ntree< dim-1, dim, side_t > top_tracer_tree_t
Definition z_ray_tracer.hpp:28
std::vector< top_intersection_record_t > m_top_intersection_records
array to store all the intersections
Definition z_ray_tracer.hpp:181
grid_dim_traits< dim-1 >::element_type side_t
side type
Definition z_ray_tracer.hpp:26
SubsetGroup m_top_ss_grp
subset group of the top faces
Definition z_ray_tracer.hpp:171
Grid m_top_grid
auxiliary grid of the top faces
Definition z_ray_tracer.hpp:175
RayElemIntersectionRecord< side_t * > top_intersection_record_t
Definition z_ray_tracer.hpp:30
static const int dim
world dimension
Definition z_ray_tracer.hpp:20
top_tracer_tree_t m_top_tracer_tree
tracer tree of the top faces
Definition z_ray_tracer.hpp:178
TDomain domain_type
grid function type
Definition z_ray_tracer.hpp:17
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