33 #ifndef __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__STD_INJECTION_IMPL__
34 #define __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__STD_INJECTION_IMPL__
49 template <
typename TAlgebra>
56 for(
size_t fct = 0; fct < fineDD.
num_fct(); ++fct)
59 UG_THROW(
"AssembleInjectionForP1Lagrange: "
60 "Interpolation only implemented for Lagrange P1 functions.");
67 const size_t numCoarseDoFs = coarseDD.
num_indices();
70 mat.resize_and_clear(numCoarseDoFs, numFineDoFs);
72 std::vector<size_t> coarseInd, fineInd;
76 const_iterator iter, iterBegin, iterEnd;
78 iterBegin = fineDD.template begin<RegularVertex>();
79 iterEnd = fineDD.template end<RegularVertex>();
82 for(iter = iterBegin; iter != iterEnd; ++iter)
99 for(
size_t i = 0; i < coarseInd.size(); ++i)
100 mat(coarseInd[i], fineInd[i]) = 1.0;
104 template <
int dim,
typename TAlgebra>
113 std::vector<size_t> coarseInd, fineInd;
118 const_iterator iter, iterBegin, iterEnd;
120 iterBegin = coarseDD.template begin<Element>();
121 iterEnd = coarseDD.template end<Element>();
124 for(iter = iterBegin; iter != iterEnd; ++iter)
127 Element* coarseElem = *iter;
130 const size_t numChild = grid.
num_children<Element, Element>(coarseElem);
131 if(numChild == 0)
continue;
136 for(
size_t c = 0; c < numChild; ++c)
138 Element* child = grid.
get_child<Element, Element>(coarseElem, c);
142 for(
size_t i = 0; i < coarseInd.size(); ++i)
143 mat(coarseInd[i], fineInd[i]) = 1.0/(numChild);
148 template <
typename TAlgebra>
155 const size_t numCoarseDoFs = coarseDD.
num_indices();
158 mat.resize_and_clear(numCoarseDoFs, numFineDoFs);
160 if(coarseDD.
max_dofs(
VERTEX)) AssembleInjectionByAverageOfChildren<0, TAlgebra>(mat, coarseDD, fineDD);
161 if(coarseDD.
max_dofs(
EDGE)) AssembleInjectionByAverageOfChildren<1, TAlgebra>(mat, coarseDD, fineDD);
162 if(coarseDD.
max_dofs(
FACE)) AssembleInjectionByAverageOfChildren<2, TAlgebra>(mat, coarseDD, fineDD);
163 if(coarseDD.
max_dofs(
VOLUME)) AssembleInjectionByAverageOfChildren<3, TAlgebra>(mat, coarseDD, fineDD);
166 template <
typename TDomain,
typename TAlgebra>
167 template <
typename TElem>
174 std::vector<size_t> vCoarseIndex, vFineIndex;
179 const_iterator iter, iterBegin, iterEnd;
184 iterBegin = coarseDD.template begin<TElem>(si);
185 iterEnd = coarseDD.template end<TElem>(si);
188 for(iter = iterBegin; iter != iterEnd; ++iter)
191 TElem* coarseElem = *iter;
193 const size_t numChild = mg.
num_children<TElem, TElem>(coarseElem);
194 if(numChild != 0)
continue;
199 UG_ASSERT(vCoarseIndex.size() == vFineIndex.size(),
"Size mismatch");
202 for(
size_t i = 0; i < vCoarseIndex.size(); ++i)
203 mat(vCoarseIndex[i], vFineIndex[i]) = 1.0;
208 template <
typename TDomain,
typename TAlgebra>
213 if(coarseDD.
max_dofs(
VERTEX)) set_identity_on_pure_surface<Vertex>(mat, coarseDD, fineDD);
214 if(coarseDD.
max_dofs(
EDGE)) set_identity_on_pure_surface<Edge>(mat, coarseDD, fineDD);
215 if(coarseDD.
max_dofs(
FACE)) set_identity_on_pure_surface<Face>(mat, coarseDD, fineDD);
216 if(coarseDD.
max_dofs(
VOLUME)) set_identity_on_pure_surface<Volume>(mat, coarseDD, fineDD);
226 template <
typename TDomain,
typename TAlgebra>
230 m_spApproxSpace = approxSpace;
233 template <
typename TDomain,
typename TAlgebra>
237 m_fineLevel = fineLevel;
238 m_coarseLevel = coarseLevel;
240 if(m_fineLevel.level() - m_coarseLevel.level() != 1)
241 UG_THROW(
"StdInjection::set_levels:"
242 " Can only project between successive level.");
245 template <
typename TDomain,
typename TAlgebra>
249 if(!m_spApproxSpace.valid())
251 "Approximation Space not set. Cannot init Projection.");
254 bool P1LagrangeOnly =
true;
255 for(
size_t fct = 0; fct < m_spApproxSpace->num_fct(); ++fct)
256 if(m_spApproxSpace->local_finite_element_id(fct).type() !=
LFEID::LAGRANGE ||
257 m_spApproxSpace->local_finite_element_id(fct).order() != 1)
258 P1LagrangeOnly =
false;
263 AssembleInjectionForP1Lagrange<TAlgebra>
265 *m_spApproxSpace->dof_distribution(m_coarseLevel),
266 *m_spApproxSpace->dof_distribution(m_fineLevel));
270 AssembleInjectionByAverageOfChildren<TAlgebra>
272 *m_spApproxSpace->dof_distribution(m_coarseLevel),
273 *m_spApproxSpace->dof_distribution(m_fineLevel));
277 " Cannot assemble interpolation matrix.");
279 if(m_coarseLevel.is_surface()){
280 set_identity_on_pure_surface(m_matrix, *m_spApproxSpace->dof_distribution(m_coarseLevel), *m_spApproxSpace->dof_distribution(m_fineLevel));
290 template <
typename TDomain,
typename TAlgebra>
298 " Operator not initialized.");
301 UG_ASSERT(uFine.size() >= m_matrix.num_rows(),
302 "Vector [size= " << uFine.size() <<
"] and Rows [size= "
303 << m_matrix.num_rows() <<
"] sizes have to match!");
304 UG_ASSERT(uCoarse.size() >= m_matrix.num_cols(),
"Vector [size= "
305 << uCoarse.size() <<
"] and Cols [size= " <<
306 m_matrix.num_cols() <<
"] sizes have to match!");
309 if(!m_matrix.apply_transposed(uFine, uCoarse))
310 UG_THROW(
"StdInjection::apply: Cannot apply matrix.");
313 template <
typename TDomain,
typename TAlgebra>
320 UG_THROW(
"StdInjection::apply_transposed:"
321 "Operator not initialized.");
324 UG_ASSERT(uFine.size() >= m_matrix.num_cols(),
325 "Vector [size= " << uFine.size() <<
"] and Cols [size= "
326 << m_matrix.num_cols() <<
"] sizes have to match!");
327 UG_ASSERT(uCoarse.size() >= m_matrix.num_rows(),
"Vector [size= "
328 << uCoarse.size() <<
"] and Rows [size= " <<
329 m_matrix.num_rows() <<
"] sizes have to match!");
333 m_matrix.apply_ignore_zero_rows(uCoarse, 1.0, uFine);
336 " Cannot apply transposed matrix.");
340 template <
typename TDomain,
typename TAlgebra>
345 op->set_approximation_space(m_spApproxSpace);
Definition: smart_pointer.h:108
base class for approximation spaces without type of algebra or dof distribution
Definition: approximation_space.h:279
Definition: dof_distribution.h:51
size_t inner_algebra_indices(GridObject *elem, std::vector< size_t > &ind, bool bClear=true) const
extracts all algebra indices in the inner of the element (not sorted)
Definition: dof_distribution.cpp:1276
size_t num_indices() const
return the number of dofs distributed
Definition: dof_distribution.h:218
SmartPtr< MultiGrid > multi_grid()
Definition: dof_distribution.h:69
int num_subsets() const
returns number of subsets
Definition: dof_distribution_info.h:192
size_t max_dofs(const int dim) const
returns the maximum number of dofs on grid objects in a dimension
Definition: dof_distribution_info.h:231
const LFEID & local_finite_element_id(size_t fct) const
Definition: dof_distribution_info.h:225
size_t num_fct() const
number of discrete functions on subset si
Definition: dof_distribution_info.h:176
Definition: grid_level.h:42
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
SpaceType type() const
returns the type of the local finite element
Definition: local_finite_element_id.h:132
int order() const
returns the order of the local finite element
Definition: local_finite_element_id.h:126
@ LAGRANGE
Definition: local_finite_element_id.h:104
Definition: multi_grid.h:72
TChild * get_child(TElem *elem, size_t ind) const
returns the i-th child of the given child-type
Definition: multi_grid.h:268
GridObject * get_parent(GridObject *parent) const
Definition: multi_grid.cpp:180
size_t num_children(TElem *elem) const
returns the number of children of the given child-type
Definition: multi_grid.h:225
Definition: std_injection.h:61
virtual SmartPtr< ITransferOperator< TDomain, TAlgebra > > clone()
clones the operator
Definition: std_injection_impl.h:342
void set_identity_on_pure_surface(matrix_type &mat, const DoFDistribution &coarseDD, const DoFDistribution &fineDD)
Definition: std_injection_impl.h:169
virtual void prolongate(vector_type &uFine, const vector_type &uCoarse)
Project uFine to uCoarse; uCoarse = P(uFine);.
Definition: std_injection_impl.h:292
virtual void init()
Init operator.
Definition: std_injection_impl.h:246
virtual void do_restrict(vector_type &uCoarse, const vector_type &uFine)
Apply Transposed Operator u = L^T*f.
Definition: std_injection_impl.h:315
TAlgebra::vector_type vector_type
Type of Vector.
Definition: std_injection.h:70
void set_approximation_space(SmartPtr< ApproximationSpace< TDomain > > approxSpace)
Set Approximation Space.
Definition: std_injection_impl.h:228
TAlgebra::matrix_type matrix_type
Type of Vector.
Definition: std_injection.h:73
void set_levels(GridLevel coarseLevel, GridLevel fineLevel)
Set approximation level.
Definition: std_injection_impl.h:235
Const iterator to traverse the surface of a multi-grid hierarchy.
Definition: surface_view.h:237
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
@ PST_CONSISTENT
Definition: parallel_storage_type.h:68
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_CATCH_THROW(msg)
Definition: error.h:64
#define UG_THROW(msg)
Definition: error.h:57
void AssembleInjectionForP1Lagrange(typename TAlgebra::matrix_type &mat, const DoFDistribution &coarseDD, const DoFDistribution &fineDD)
Definition: std_injection_impl.h:50
@ VOLUME
Definition: grid_base_objects.h:63
@ VERTEX
Definition: grid_base_objects.h:60
@ EDGE
Definition: grid_base_objects.h:61
@ FACE
Definition: grid_base_objects.h:62
void AssembleInjectionByAverageOfChildren(typename TAlgebra::matrix_type &mat, const DoFDistribution &coarseDD, const DoFDistribution &fineDD)
Definition: std_injection_impl.h:105
#define PROFILE_FUNC_GROUP(groups)
Definition: profiler.h:258
domain_traits< dim >::grid_base_object grid_base_object
Definition: dof_distribution.h:88