Plugins
Loading...
Searching...
No Matches
ls_init_impl.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015: G-CSC, Goethe University Frankfurt
3 * Authors: Christian Wehner, Dmitry Logashenko
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/*
34 * Initialization of the level-set function: implementation
35 */
36
37// FOR DEBUGGING ONLY
38// #include "lib_grid/file_io/file_io.h"
39
40#ifdef UG_PARALLEL
43#endif
44
45namespace ug{
46namespace LevelSet{
47
52template <typename TGridFunc>
54(
56)
57{
58 // UG_LOG("<dbg> Interplate to called!\n");
59 position_accessor_type aaPos = spLSF->domain()->position_accessor ();
60 std::vector<DoFIndex> ind (1);
61
62// top tracer tree
64 if (m_bRelative)
65 {
66 // UG_LOG("<dbg> relative\n");
68 (
69 new z_ray_tracer_t (spLSF->domain (), m_top_ss_names)
70 );
71 sp_top_z->init (m_rt_gl, m_localTopFacesOnly);
72 }
73
74// interpolate the values
75 for (VertexConstIterator iter = spLSF->template begin<Vertex> ();
76 iter != spLSF->template end<Vertex> (); ++iter)
77 {
78 Vertex * vrt = *iter;
79
80 // interpolate the raster
81 MathVector<dim> coord = aaPos [vrt];
82 typename raster_t::Coordinate rc;
83 for (int i = 0; i < dim - 1; ++i)
84 rc[i] = coord[i];
85 number raster_val = m_raster.interpolate(rc, 1);
86
87 // correct the raster if relative
88 if (sp_top_z.valid ())
89 {
90 number top_z;
91 if (sp_top_z->get_min_at (coord, m_rt_tol, top_z))
92 raster_val += top_z;
93 else if (m_bDefaultTop)
94 raster_val += m_rt_default;
95 else
96 UG_THROW ("LSFbyRaster: Point " << coord << " is not covered by the top subset.");
97 }
98
99 // get indices of the dofs and set the value
100 spLSF->inner_dof_indices (vrt, 0, ind);
101 DoFRef (*spLSF, ind[0]) = coord [dim - 1] - raster_val;
102 }
103
104 // adjust parallel storage state
105#ifdef UG_PARALLEL
106 spLSF->set_storage_type(PST_CONSISTENT);
107#endif
108}
109
113template <typename TGridFunc>
115(
116 int grid_level
117)
118{
119 init(grid_level, false);
120}
121
122template <typename TGridFunc>
124(
125 int grid_level,
126 bool localTopSidesOnly
127)
128{
129 #ifndef UG_PARALLEL
130 localTopSidesOnly = true;
131 #endif
132
133 typedef typename Grid::traits<side_t>::iterator SideIterator;
134
135 MultiGrid & mg = * m_sp_domain->grid ();
136 MGSubsetHandler & sh = * m_sp_domain->subset_handler ();
137 std::vector<side_t*> topSides;
138
139// get all the elements to collect
140 if(localTopSidesOnly){
141 m_top_tracer_tree.set_grid(*m_sp_domain->grid (), m_sp_domain->position_attachment ());
142 for (size_t i = 0; i < m_top_ss_grp.size (); i++)
143 {
144 int si = m_top_ss_grp [i];
145
146 if (grid_level >= 0){ // if the grid level for the top is specified
147 for (SideIterator it = sh.begin<side_t> (si, grid_level);
148 it != sh.end<side_t> (si, grid_level); ++it)
149 topSides.push_back (*it);
150 }
151 else{
152 for (int lvl = 0; lvl < (int) sh.num_levels(); lvl++){
153 for (SideIterator it = sh.begin<side_t> (si, lvl);
154 it != sh.end<side_t> (si, lvl); ++it)
155 {
156 side_t* t = *it;
157 if (! mg.has_children (t))
158 topSides.push_back (t);
159 }
160 }
161 }
162 }
163 }
164 else {
165 #ifdef UG_PARALLEL
166 m_top_tracer_tree.set_grid(m_top_grid, m_sp_domain->position_attachment ());
167
169
170 // select the Sides on the top
171 Selector sel (mg);
172 for (size_t i = 0; i < m_top_ss_grp.size (); i++)
173 {
174 int si = m_top_ss_grp [i];
175
176 if (grid_level >= 0) // if the grid level for the top is specified
177 for (SideIterator it = sh.begin<side_t> (si, grid_level);
178 it != sh.end<side_t> (si, grid_level); ++it)
179 sel.select (*it);
180 else
181 for (int lvl = 0; lvl < (int) sh.num_levels(); lvl++)
182 for (SideIterator it = sh.begin<side_t> (si, lvl);
183 it != sh.end<side_t> (si, lvl); ++it)
184 {
185 side_t* t = *it;
186 if (! (mg.has_children (t) || (dgm && dgm->is_ghost(t))))
187 sel.select (t);
188 }
189 }
190
191 // copy the top Sides into a new grid
193 serializer.add
194 (GeomObjAttachmentSerializer<Vertex, position_attachment_type>::create (mg, m_sp_domain->position_attachment ()));
195
196 GridDataSerializationHandler deserializer;
197 deserializer.add
198 (GeomObjAttachmentSerializer<Vertex, position_attachment_type>::create (m_top_grid, m_sp_domain->position_attachment ()));
199
200 AllGatherGrid (m_top_grid, sel, serializer, deserializer);
201
202 for (SideIterator it = m_top_grid.begin<side_t> (); it != m_top_grid.end<side_t> (); ++it)
203 topSides.push_back (*it);
204
205 // UG_LOG("DEBUG: SAVING allgathered m_top_grid to file in ls_init...\n");
206 // SaveGridToFile(m_top_grid, mkstr("top_grid_p" << pcl::ProcRank() << ".ugx").c_str(),
207 // m_sp_domain->position_attachment());
208 #endif
209 }
210
211// compose the tree
212 m_top_tracer_tree.create_tree (topSides.begin (), topSides.end ());
213}
214
218template <typename TGridFunc>
220(
221 const MathVector<dim> & over,
222 number tolerance,
223 number & z
224)
225{
226// find all the intersections
227 MathVector<dim> up_dir;
228 up_dir = 0;
229 up_dir [dim - 1] = 1;
230 m_top_intersection_records.clear ();
231 RayElementIntersections (m_top_intersection_records, m_top_tracer_tree, over, up_dir, tolerance);
232
233 // UG_LOG("<dbg> over: " << over << ", up_dir: " << up_dir << std::endl);
234 // UG_LOG("<dbg> num intersections: " << m_top_intersection_records.size () << std::endl);
235
236// check if there are intersections at all
237 if (m_top_intersection_records.size () == 0)
238 return false;
239
240// find the lowest point
241 MathVector<dim> x = PointOnRay (over, up_dir, m_top_intersection_records[0].smin);
242 number z_min = x [dim - 1];
243 // UG_LOG("<dbg> x: " << x << std::endl);
244 for (size_t i = 1; i < m_top_intersection_records.size (); i++)
245 {
246 top_intersection_record_t & r = m_top_intersection_records [i];
247 x = PointOnRay (over, up_dir, r.smin);
248 if (x [dim - 1] < z_min)
249 z_min = x [dim - 1];
250 }
251
252 z = z_min;
253 return true;
254}
255
256} // end namespace LevelSet
257} // end namespace ug
258
259/* End of File */
bool valid() const
bool is_ghost(TElem *elem) const
void add(SPVertexDataSerializer cb)
DistributedGridManager * distributed_grid_manager()
void select(GridObject *elem, byte status)
void set_grid(Grid *grid)
an auxiliary class for the computation of the relative height
Definition ls_init.h:192
void init(int grid_level)
initializer: creates the tree
Definition ls_init_impl.h:115
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 ls_init_impl.h:220
domain_type::position_accessor_type position_accessor_type
type of the position accessor
Definition ls_init.h:81
static const int dim
world dimension
Definition ls_init.h:84
void interpolate_to(SmartPtr< TGridFunc > spLSF)
computes the level-set function
Definition ls_init_impl.h:54
TGridFunc::template traits< Vertex >::const_iterator VertexConstIterator
vertex base iterator
Definition ls_init.h:87
grid_dim_traits< dim-1 >::element_type side_t
side type
Definition ls_init.h:93
bool has_children(TElem *elem) const
geometry_traits< TElem >::iterator end(int subsetIndex, int level)
geometry_traits< TElem >::iterator begin(int subsetIndex, int level)
PST_CONSISTENT
#define UG_THROW(msg)
double number
vector_t PointOnRay(const vector_t &from, const vector_t &dir, number s)
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)
const number & DoFRef(const TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
void AllGatherGrid(Grid &gridOut, Selector &sel, GridDataSerializationHandler &serializer, GridDataSerializationHandler &deserializer, const pcl::ProcessCommunicator &procCom=pcl::ProcessCommunicator())
geometry_traits< TElem >::iterator iterator