Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
grid_util.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017: 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#ifndef __H__UG_grid_util
34#define __H__UG_grid_util
35
36#include "../grid/grid.h"
37#include "../tools/selector_grid.h"
38
39namespace ug{
40
45template <class TElem>
46inline void CopySelectedElements(Selector& srcSel, Grid& destGrid, AVertex aNewVrt)
47{
48 Grid& srcGrid = *srcSel.grid();
49
50 Grid::VertexAttachmentAccessor<AVertex> aaNewVrt(srcGrid, aNewVrt);
51
53 typedef typename Grid::traits<TElem>::iterator iter_t;
54
55 for(iter_t eiter = srcSel.begin<TElem>();
56 eiter != srcSel.end<TElem>(); ++eiter)
57 {
58 TElem* e = *eiter;
59 vrts.resize(e->num_vertices());
60 for(size_t iv = 0; iv < e->num_vertices(); ++iv)
61 vrts.set_vertex(iv, aaNewVrt[e->vertex(iv)]);
62
63 destGrid.create_by_cloning(e, vrts);
64 }
65}
66
67template <class TAAPosSrc, class TAAPosDest>
68inline void CopySelection(Selector& srcSel, Grid& destGrid,
69 TAAPosSrc aaPosSrc, TAAPosDest aaPosDest)
70{
71 UG_COND_THROW(!srcSel.grid(), "The specified selector has to operate on a grid.");
72
73 Grid& srcGrid = *srcSel.grid();
74
75 AVertex aNewVrt;
76 srcGrid.attach_to_vertices(aNewVrt);
77 Grid::VertexAttachmentAccessor<AVertex> aaNewVrt(srcGrid, aNewVrt);
78
80
81// create new vertices in destGrid
82 for(VertexIterator viter = srcSel.begin<Vertex>();
83 viter != srcSel.end<Vertex>(); ++viter)
84 {
85 Vertex* v = *viter;
86 Vertex* nv = *destGrid.create_by_cloning(v);
87 aaNewVrt[v] = nv;
88 aaPosDest[nv] = aaPosSrc[v];
89 }
90
91 CopySelectedElements<Edge>(srcSel, destGrid, aNewVrt);
92 CopySelectedElements<Face>(srcSel, destGrid, aNewVrt);
93 CopySelectedElements<Volume>(srcSel, destGrid, aNewVrt);
94
95 srcGrid.detach_from_vertices(aNewVrt);
96}
97
98}// end of namespace
99
100#endif //__H__UG_grid_util
this class can be used if one wants to create a custom element from a set of vertices.
Definition grid_base_objects.h:336
void set_vertex(size_t index, Vertex *vrt)
Definition grid_base_objects.h:350
void resize(size_t newSize)
Definition grid_base_objects.h:347
Manages the elements of a grid and their interconnection.
Definition grid.h:132
VertexIterator create_by_cloning(Vertex *pCloneMe, GridObject *pParent=NULL)
this method creates a new vertex, which has the same type as pCloneMe.
Definition grid.cpp:419
void detach_from_vertices(IAttachment &attachment)
Definition grid.h:787
void attach_to_vertices(IAttachment &attachment, bool passOnValues)
Definition grid.h:728
Grid * grid() const
Definition selector_interface.h:218
specialization of ISelector for a grid of class Grid.
Definition selector_grid.h:96
geometry_traits< TElem >::iterator end()
Definition selector_grid_impl.hpp:134
geometry_traits< TElem >::iterator begin()
Definition selector_grid_impl.hpp:106
Base-class for all vertex-types.
Definition grid_base_objects.h:231
void SelectAssociatedGridObjects(TSelector &sel, ISelector::status_t status)
selects associated geometric objects of selected ones on each level.
Definition selection_util.cpp:221
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition error.h:61
the ug namespace
ElementStorage< Vertex >::SectionContainer::iterator VertexIterator
This Iterator will be used as base-class for iterators of specialized geometric objects.
Definition grid_base_object_traits.h:73
void CopySelectedElements(SmartPtr< TDomain > destDom, SmartPtr< TDomain > srcDom, Selector &sel, AVertex &aNewVrt)
Definition vtk_export_ho.h:77
void CopySelection(Selector &srcSel, Grid &destGrid, TAAPosSrc aaPosSrc, TAAPosDest aaPosDest)
Definition grid_util.h:68
geometry_traits< TElem >::iterator iterator
Definition grid.h:143