Line data Source code
1 : /*
2 : * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Andreas Vogel
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__LIB_DISC__FUNCTION_SPACE__ADAPTION_SURFACE_GRID_FUNCTION_IMPL__
34 : #define __H__UG__LIB_DISC__FUNCTION_SPACE__ADAPTION_SURFACE_GRID_FUNCTION_IMPL__
35 :
36 : #include "adaption_surface_grid_function.h"
37 : #include "common/profiler/profiler.h"
38 : #include "lib_grid/algorithms/debug_util.h"
39 :
40 : #define GFUNCADAPT_PROFILE_FUNC() PROFILE_FUNC_GROUP("gfunc-adapt")
41 :
42 :
43 : namespace ug{
44 :
45 : template <typename TDomain>
46 : template <typename TElem, typename TAlgebra>
47 0 : void AdaptionSurfaceGridFunction<TDomain>::
48 : copy_from_surface(const GridFunction<TDomain,TAlgebra>& rSurfaceFct, TElem* elem)
49 : {
50 : std::vector<DoFIndex> vInd;
51 : const size_t numFct = m_spDDInfo->num_fct();
52 :
53 : std::vector<std::vector<number> >& vvVal = m_aaValue[elem];
54 0 : vvVal.resize(numFct);
55 :
56 0 : for(size_t fct = 0; fct < numFct; ++fct){
57 :
58 : std::vector<number>& vVal = vvVal[fct];
59 :
60 : rSurfaceFct.inner_dof_indices(elem, fct, vInd);
61 0 : vVal.resize(vInd.size());
62 0 : for(size_t i = 0; i < vInd.size(); ++i)
63 0 : vVal[i] = DoFRef(rSurfaceFct, vInd[i]);
64 : }
65 0 : }
66 :
67 : template <typename TDomain>
68 : template <typename TElem, typename TAlgebra>
69 0 : void AdaptionSurfaceGridFunction<TDomain>::
70 : copy_from_surface(const GridFunction<TDomain,TAlgebra>& rSurfaceFct)
71 : {
72 0 : ConstSmartPtr<SurfaceView> spSurfView = rSurfaceFct.approx_space()->surface_view();
73 0 : ConstSmartPtr<MultiGrid> spGrid = m_spDomain->grid();
74 : typedef typename GridFunction<TDomain,TAlgebra>::template traits<TElem>::const_iterator iter_type;
75 : iter_type iter = rSurfaceFct.template begin<TElem>(SurfaceView::ALL);
76 : iter_type iterEnd = rSurfaceFct.template end<TElem>(SurfaceView::ALL);
77 :
78 0 : for( ; iter != iterEnd; ++iter){
79 :
80 : // get surface element
81 : TElem* elem = *iter;
82 :
83 : // copy indices to attachment
84 0 : copy_from_surface(rSurfaceFct, elem);
85 : }
86 0 : }
87 :
88 : template <typename TDomain>
89 : template <typename TAlgebra>
90 0 : void AdaptionSurfaceGridFunction<TDomain>::
91 : copy_from_surface(const GridFunction<TDomain,TAlgebra>& rSurfaceFct)
92 : {
93 : GFUNCADAPT_PROFILE_FUNC();
94 0 : attach_entries(rSurfaceFct.dof_distribution()->dof_distribution_info());
95 :
96 0 : if(rSurfaceFct.max_dofs(VERTEX))copy_from_surface<Vertex,TAlgebra>(rSurfaceFct);
97 0 : if(rSurfaceFct.max_dofs(EDGE)) copy_from_surface<Edge,TAlgebra>(rSurfaceFct);
98 0 : if(rSurfaceFct.max_dofs(FACE)) copy_from_surface<Face,TAlgebra>(rSurfaceFct);
99 0 : if(rSurfaceFct.max_dofs(VOLUME))copy_from_surface<Volume,TAlgebra>(rSurfaceFct);
100 :
101 : #ifdef UG_PARALLEL
102 : m_ParallelStorageType = rSurfaceFct.get_storage_mask();
103 : #endif
104 :
105 : // \todo: At this point the vert. slaves are not provided with the correct values
106 : // Thus, the vert. masters should sent their values there.
107 0 : }
108 :
109 :
110 : template <typename TDomain>
111 : template <typename TElem, typename TAlgebra>
112 0 : void AdaptionSurfaceGridFunction<TDomain>::
113 : copy_to_surface(GridFunction<TDomain,TAlgebra>& rSurfaceFct, TElem* elem)
114 : {
115 : std::vector<DoFIndex> vInd;
116 : const std::vector<std::vector<number> >& vvVal = m_aaValue[elem];
117 :
118 : UG_ASSERT(vvVal.size() == m_spDDInfo->num_fct(), "Array says numFct: "<<
119 : vvVal.size()<<", but should be "<<m_spDDInfo->num_fct()<<" on "
120 : << ElementDebugInfo(*m_spDomain->grid(), elem));
121 :
122 0 : for(size_t fct = 0; fct < vvVal.size(); ++fct){
123 :
124 : const std::vector<number>& vVal = vvVal[fct];
125 : rSurfaceFct.inner_dof_indices(elem, fct, vInd);
126 :
127 : UG_ASSERT(vVal.size() == vInd.size(), "Stored dofs are "<<vVal.size()<<
128 : ", but fct "<<fct<<" has "<<vInd.size()<<" dofs on "<<
129 : elem->reference_object_id())
130 :
131 0 : for(size_t i = 0; i < vInd.size(); ++i){
132 : UG_ASSERT(vInd[i][0] != size_t(-1),
133 : "Bad dof-index encountered on: "
134 : << ElementDebugInfo(*rSurfaceFct.domain()->grid(), elem));
135 0 : DoFRef(rSurfaceFct, vInd[i]) = vVal[i];
136 : }
137 : }
138 0 : }
139 :
140 : template <typename TDomain>
141 : template <typename TElem, typename TAlgebra>
142 0 : void AdaptionSurfaceGridFunction<TDomain>::
143 : copy_to_surface(GridFunction<TDomain,TAlgebra>& rSurfaceFct)
144 : {
145 0 : ConstSmartPtr<SurfaceView> spSurfView = rSurfaceFct.approx_space()->surface_view();
146 0 : ConstSmartPtr<MultiGrid> spGrid = m_spDomain->grid();
147 :
148 : typedef typename GridFunction<TDomain,TAlgebra>::template traits<TElem>::const_iterator iter_type;
149 : iter_type iter = rSurfaceFct.template begin<TElem>(SurfaceView::ALL);
150 : iter_type iterEnd = rSurfaceFct.template end<TElem>(SurfaceView::ALL);
151 :
152 0 : for( ; iter != iterEnd; ++iter)
153 : {
154 : TElem* elem = *iter;
155 :
156 0 : copy_to_surface(rSurfaceFct, elem);
157 : }
158 0 : }
159 :
160 : template <typename TDomain>
161 : template <typename TAlgebra>
162 0 : void AdaptionSurfaceGridFunction<TDomain>::
163 : copy_to_surface(GridFunction<TDomain,TAlgebra>& rSurfaceFct)
164 : {
165 : GFUNCADAPT_PROFILE_FUNC();
166 0 : if(rSurfaceFct.max_dofs(VERTEX))copy_to_surface<Vertex,TAlgebra>(rSurfaceFct);
167 0 : if(rSurfaceFct.max_dofs(EDGE)) copy_to_surface<Edge,TAlgebra>(rSurfaceFct);
168 0 : if(rSurfaceFct.max_dofs(FACE)) copy_to_surface<Face,TAlgebra>(rSurfaceFct);
169 0 : if(rSurfaceFct.max_dofs(VOLUME))copy_to_surface<Volume,TAlgebra>(rSurfaceFct);
170 :
171 : #ifdef UG_PARALLEL
172 : rSurfaceFct.set_storage_type(m_ParallelStorageType);
173 : #endif
174 :
175 0 : detach_entries();
176 0 : }
177 :
178 :
179 : template <typename TDomain>
180 : template <typename TBaseElem>
181 0 : inline void AdaptionSurfaceGridFunction<TDomain>::obj_created(TBaseElem* elem){
182 :
183 : // get value attachment
184 : std::vector<std::vector<number> >& vvVal = m_aaValue[elem];
185 :
186 : // resize to number of functions
187 0 : vvVal.resize(m_spDDInfo->num_fct());
188 :
189 : // get geom obj infos
190 0 : const ReferenceObjectID roid = elem->reference_object_id();
191 0 : const int si = m_spDomain->subset_handler()->get_subset_index(elem);
192 :
193 : // for each fct cmp resize to number of dofs associated with elem
194 0 : for(size_t fct = 0; fct < vvVal.size(); ++fct){
195 0 : vvVal[fct].resize(m_spDDInfo->num_fct_dofs(fct, roid, si));
196 : }
197 0 : }
198 :
199 : } // end namespace ug
200 :
201 : #endif /* __H__UG__LIB_DISC__FUNCTION_SPACE__ADAPTION_SURFACE_GRID_FUNCTION_IMPL__ */
|