33 #ifndef __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__STD_TRANSFER_IMPL__
34 #define __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__STD_TRANSFER_IMPL__
45 template <
typename TDomain,
typename TAlgebra>
53 for(
size_t fct = 0; fct < fineDD.
num_fct(); ++fct)
56 UG_THROW(
"AssembleStdProlongationForP1Lagrange:"
57 "Interpolation only implemented for Lagrange P1 functions.");
65 const_iterator iter, iterBegin, iterEnd;
68 std::vector<size_t> vParentIndex, vChildIndex;
69 std::vector<DoFIndex> vParentDoF, vChildDoF;
72 iterBegin = fineDD.template begin<Vertex>(si);
73 iterEnd = fineDD.template end<Vertex>(si);
76 for(iter = iterBegin; iter != iterEnd; ++iter)
92 UG_ASSERT(vParentIndex.size() == vChildIndex.size(),
"Size mismatch");
95 for(
size_t i = 0; i < vParentIndex.size(); ++i)
96 P(vChildIndex[i], vParentIndex[i]) = 1.0;
104 if(!parent)
continue;
107 UG_THROW(
"StdTransfer: Parent element \n"
109 "is not contained in coarse-dd nor the child element\n"
111 " in the coarse-dd. This should not happen.")
119 for(
size_t fct = 0; fct < fineDD.
num_fct(); fct++)
134 DoFRef(P, vChildDoF[0], vParentDoF[0]) = 1.0;
138 for(
int i = 0; i < 2; ++i)
140 Edge* edge =
dynamic_cast<Edge*
>(parent);
142 DoFRef(P, vChildDoF[0], vParentDoF[0]) = 0.5;
146 for(
int i = 0; i < 4; ++i)
148 Face* face =
dynamic_cast<Face*
>(parent);
150 DoFRef(P, vChildDoF[0], vParentDoF[0]) = 0.25;
154 for(
int i = 0; i < 8; ++i)
158 DoFRef(P, vChildDoF[0], vParentDoF[0]) = 0.125;
161 default:
UG_THROW(
"AssembleStdProlongationForP1Lagrange: Element father"
162 " is of unsupported type "<< roid <<
" for "
214 template <
typename TDomain,
typename TAlgebra>
215 template <
typename TChild>
227 const_iterator iter, iterBegin, iterEnd;
230 std::vector<DoFIndex> vParentDoF, vChildDoF;
231 std::vector<size_t> vParentIndex, vChildIndex;
234 iterBegin = fineDD.template begin<TChild>(si);
235 iterEnd = fineDD.template end<TChild>(si);
238 std::vector<LFEID> vLFEID;
239 std::vector<size_t> vFct;
240 for(
size_t fct = 0; fct < fineDD.
num_fct(); ++fct){
243 vLFEID.push_back(fineDD.
lfeid(fct));
245 if(vFct.empty())
continue;
248 for(iter = iterBegin; iter != iterEnd; ++iter)
251 TChild* child = *iter;
264 UG_ASSERT(vParentIndex.size() == vChildIndex.size(),
"Size mismatch");
267 for(
size_t i = 0; i < vParentIndex.size(); ++i)
268 P(vChildIndex[i], vParentIndex[i]) = 1.0;
277 if(!parent)
continue;
280 UG_THROW(
"StdTransfer: A parent element is not contained in "
281 " coarse-dd nor the child element in the coarse-dd. "
282 "This should not happen.")
287 for(
size_t f = 0; f < vFct.size(); f++)
290 const size_t fct = vFct[f];
291 const LFEID& lfeID = vLFEID[f];
302 UG_ASSERT(vChildDoF.size() == 1,
"Must be one.");
303 UG_ASSERT(vParentDoF.size() == 1,
"Must be one.");
305 DoFRef(P, vChildDoF[0], vParentDoF[0]) = 1.0;
313 std::vector<GridObject*> vParent;
316 if(parentDim == lfeID.
dim()){
318 vParent.push_back(parent);
319 }
else if(parentDim == lfeID.
dim() - 1){
321 typedef typename TChild::sideof TElem;
322 std::vector<TElem*> vElem;
324 for(
size_t p = 0;
p < vElem.size(); ++
p)
325 vParent.push_back(vElem[
p]);
328 UG_THROW(
"StdTransfer: For CR parent must be full-dim "
329 "elem or a side (dim-1). But has dim: "<<parentDim);
334 std::vector<MathVector<TDomain::dim> > vDoFPos;
338 for(
size_t i = 0; i < vParent.size(); ++i)
344 std::vector<std::vector<number> > vvShape;
348 for(
size_t ip = 0; ip < vvShape.size(); ++ip)
349 for(
size_t sh = 0; sh < vvShape[ip].size(); ++sh)
350 DoFRef(P, vChildDoF[ip], vParentDoF[sh]) +=
351 (1./vParent.size()) * vvShape[ip][sh];
362 std::vector<MathVector<TDomain::dim> > vDoFPos;
369 std::vector<std::vector<number> > vvShape;
373 for(
size_t ip = 0; ip < vvShape.size(); ++ip)
374 for(
size_t sh = 0; sh < vvShape[ip].size(); ++sh)
375 DoFRef(P, vChildDoF[ip], vParentDoF[sh]) = vvShape[ip][sh];
380 UG_THROW(
"StdTransfer: Local-Finite-Element: "<<lfeID<<
381 " is not supported by this Transfer.")
389 template <
typename TDomain,
typename TAlgebra>
400 if(fineDD.
max_dofs(
VERTEX)) assemble_prolongation<Vertex>(P, fineDD, coarseDD, spDomain);
401 if(fineDD.
max_dofs(
EDGE)) assemble_prolongation<Edge>(P, fineDD, coarseDD, spDomain);
402 if(fineDD.
max_dofs(
FACE)) assemble_prolongation<Face>(P, fineDD, coarseDD, spDomain);
403 if(fineDD.
max_dofs(
VOLUME)) assemble_prolongation<Volume>(P, fineDD, coarseDD, spDomain);
407 template <
typename TDomain,
typename TAlgebra>
408 template <
typename TChild>
420 const_iterator iter, iterBegin, iterEnd;
423 std::vector<DoFIndex> vParentDoF, vChildDoF;
424 std::vector<size_t> vParentIndex, vChildIndex;
427 iterBegin = fineDD.template begin<TChild>(si);
428 iterEnd = fineDD.template end<TChild>(si);
431 std::vector<LFEID> vLFEID;
432 std::vector<size_t> vFct;
433 for(
size_t fct = 0; fct < fineDD.
num_fct(); ++fct){
436 vLFEID.push_back(fineDD.
lfeid(fct));
438 if(vFct.empty())
continue;
441 for(iter = iterBegin; iter != iterEnd; ++iter)
444 TChild* child = *iter;
457 UG_ASSERT(vParentIndex.size() == vChildIndex.size(),
"Size mismatch");
460 for(
size_t i = 0; i < vParentIndex.size(); ++i)
461 R(vParentIndex[i], vChildIndex[i]) = 1.0;
470 if(!parent)
continue;
473 UG_THROW(
"StdTransfer: A parent element is not contained in "
474 " coarse-dd nor the child element in the coarse-dd. "
475 "This should not happen.")
480 for(
size_t f = 0; f < vFct.size(); f++)
483 const size_t fct = vFct[f];
484 const LFEID& lfeID = vLFEID[f];
495 UG_ASSERT(vChildDoF.size() == 1,
"Must be one.");
496 UG_ASSERT(vParentDoF.size() == 1,
"Must be one.");
498 DoFRef(R, vParentDoF[0], vChildDoF[0]) = 1.0;
506 std::vector<GridObject*> vParent;
509 if(parentDim == lfeID.
dim()){
511 vParent.push_back(parent);
512 }
else if(parentDim == lfeID.
dim() - 1){
514 typedef typename TChild::sideof TElem;
515 std::vector<TElem*> vElem;
517 for(
size_t p = 0;
p < vElem.size(); ++
p){
522 vParent.push_back(vElem[
p]);
526 UG_THROW(
"StdTransfer: For CR parent must be full-dim "
527 "elem or a side (dim-1). But has dim: "<<parentDim);
532 std::vector<MathVector<TDomain::dim> > vDoFPos;
536 for(
size_t i = 0; i < vParent.size(); ++i)
542 std::vector<std::vector<number> > vvShape;
546 for(
size_t ip = 0; ip < vvShape.size(); ++ip)
547 for(
size_t sh = 0; sh < vvShape[ip].size(); ++sh)
548 DoFRef(R, vParentDoF[sh], vChildDoF[ip]) +=
549 (1./vParent.size()) * vvShape[ip][sh];
560 std::vector<MathVector<TDomain::dim> > vDoFPos;
564 std::vector<std::vector<number> > vvShape;
568 for(
size_t ip = 0; ip < vvShape.size(); ++ip)
569 for(
size_t sh = 0; sh < vvShape[ip].size(); ++sh)
570 DoFRef(R, vParentDoF[sh], vChildDoF[ip]) = vvShape[ip][sh];
575 UG_THROW(
"StdTransfer: Local-Finite-Element: "<<lfeID<<
576 " is not supported by this Transfer.")
584 template <
typename TDomain,
typename TAlgebra>
595 if(fineDD.
max_dofs(
VERTEX)) assemble_restriction<Vertex>(R, coarseDD, fineDD, spDomain);
596 if(fineDD.
max_dofs(
EDGE)) assemble_restriction<Edge>(R, coarseDD, fineDD, spDomain);
597 if(fineDD.
max_dofs(
FACE)) assemble_restriction<Face>(R, coarseDD, fineDD, spDomain);
598 if(fineDD.
max_dofs(
VOLUME)) assemble_restriction<Volume>(R, coarseDD, fineDD, spDomain);
602 template <
typename TDomain,
typename TAlgebra>
609 UG_THROW(
"StdTransfer: Can only project between successive level, "
610 "but fine = "<<fineGL<<
", coarse = "<<coarseGL);
612 if(fineGL.
type() != coarseGL.
type())
613 UG_THROW(
"StdTransfer: Can only project between dof distributions of "
614 "same type, but fine = "<<fineGL<<
", coarse = "<<coarseGL);
617 remove_outdated(m_mProlongation, spApproxSpace->revision());
620 TransferKey key(coarseGL, fineGL, spApproxSpace->revision());
623 if(m_mProlongation.find(key) == m_mProlongation.end())
631 bool P1LagrangeOnly =
false;
632 if(m_p1LagrangeOptimizationEnabled){
633 P1LagrangeOnly =
true;
634 for(
size_t fct = 0; fct < spApproxSpace->num_fct(); ++fct)
636 spApproxSpace->lfeid(fct).order() != 1)
637 P1LagrangeOnly =
false;
641 assemble_prolongation_p1(*P, *spFineDD, *spCoarseDD);
643 assemble_prolongation(*P, *spFineDD, *spCoarseDD, spApproxSpace->domain());
646 for (
int type = 1; type <
CT_ALL; type = type << 1)
648 for (
size_t i = 0; i < m_vConstraint.size(); ++i)
650 if (m_vConstraint[i]->type() & type)
651 m_vConstraint[i]->adjust_prolongation(*P, spFineDD, spCoarseDD, type);
659 write_debug(*P,
"P", fineGL, coarseGL);
662 return m_mProlongation[key];
665 template <
typename TDomain,
typename TAlgebra>
672 UG_THROW(
"StdTransfer: Can only project between successive level, "
673 "but fine = "<<fineGL<<
", coarse = "<<coarseGL);
675 if(fineGL.
type() != coarseGL.
type())
676 UG_THROW(
"StdTransfer: Can only project between dof distributions of "
677 "same type, but fine = "<<fineGL<<
", coarse = "<<coarseGL);
680 remove_outdated(m_mRestriction, spApproxSpace->revision());
683 TransferKey key(coarseGL, fineGL, spApproxSpace->revision());
686 if(m_mRestriction.find(key) == m_mRestriction.end())
695 R->set_as_transpose_of(*prolongation(fineGL, coarseGL, spApproxSpace));
697 assemble_restriction(*R, *spCoarseDD, *spFineDD, spApproxSpace->domain());
704 for (
int type = 1; type <
CT_ALL; type = type << 1)
706 for (
size_t i = 0; i < m_vConstraint.size(); ++i)
708 if (m_vConstraint[i]->type() & type)
709 m_vConstraint[i]->adjust_restriction(*R, spCoarseDD, spFineDD, type);
713 write_debug(*R,
"R", coarseGL, fineGL);
716 return m_mRestriction[key];
719 template <
typename TDomain,
typename TAlgebra>
726 UG_THROW(
"StdTransfer: currently only cached implemented.");
732 UG_THROW(
"StdTransfer: cannot prolongate between grid functions from "
733 "different approximation spaces.");
738 MatMultDirect(uFine, m_dampProl, *prolongation(fineGL, coarseGL, spApproxSpace), uCoarse);
740 prolongation(fineGL, coarseGL, spApproxSpace)->axpy(uFine, 0.0, uFine, m_dampProl, uCoarse);
744 for (
int type = 1; type <
CT_ALL; type = type << 1)
746 for (
size_t i = 0; i < m_vConstraint.size(); ++i)
748 if (m_vConstraint[i]->type() & type)
749 m_vConstraint[i]->adjust_prolongation(uFine, fineGL, uCoarse, coarseGL, type);
754 UG_CATCH_THROW(
"StdTransfer:prolongation: Failed for fine = "<<fineGL<<
" and "
755 " coarse = "<<coarseGL);
760 for(
size_t fct = 0; fct < spApproxSpace->num_fct(); ++fct)
769 &uFine.layouts()->comm());
774 template <
typename TDomain,
typename TAlgebra>
781 UG_THROW(
"StdTransfer: currently only cached implemented.");
787 UG_THROW(
"StdTransfer: cannot prolongate between grid functions from "
788 "different approximation spaces.");
791 restriction(coarseGL, fineGL, spApproxSpace)->
792 apply_ignore_zero_rows(uCoarse, m_dampRes, uFine);
795 for (
int type = 1; type <
CT_ALL; type = type << 1)
797 for (
size_t i = 0; i < m_vConstraint.size(); ++i)
799 if (m_vConstraint[i]->type() & type)
800 m_vConstraint[i]->adjust_restriction(uCoarse, coarseGL, uFine, fineGL, type);
804 }
UG_CATCH_THROW(
"StdTransfer:do_restrict: Failed for fine = "<<fineGL<<
" and "
805 " coarse = "<<coarseGL);
808 template <
typename TDomain,
typename TAlgebra>
813 for(
size_t i = 0; i < m_vConstraint.size(); ++i)
814 op->add_constraint(m_vConstraint[i]);
815 op->set_restriction_damping(m_dampRes);
816 op->set_prolongation_damping(m_dampProl);
817 op->set_debug(m_spDebugWriter);
818 op->enable_p1_lagrange_optimization(p1_lagrange_optimization_enabled());
819 op->set_use_transposed(m_bUseTransposed);
823 template <
typename TDomain,
typename TAlgebra>
830 if(m_spDebugWriter.invalid())
return;
834 m_spDebugWriter.template cast_dynamic<GridFunctionDebugWriter<TDomain, TAlgebra> >();
837 if(dbgWriter.
invalid())
return;
845 GridLevel gridLev = dbgWriter->grid_level();
846 dbgWriter->set_grid_levels(glFrom, glTo);
847 dbgWriter->write_matrix(mat,
name.c_str());
848 dbgWriter->set_grid_level(gridLev);
location name
Definition: checkpoint_util.lua:128
Definition: smart_pointer.h:108
T * get()
returns encapsulated pointer
Definition: smart_pointer.h:197
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition: smart_pointer.h:212
base class for approximation spaces without type of algebra or dof distribution
Definition: approximation_space.h:279
Definition: dof_distribution.h:51
size_t dof_indices(GridObject *elem, size_t fct, std::vector< DoFIndex > &ind, bool bHang=false, bool bClear=true) const
extracts all multiindices for a function (sorted)
Definition: dof_distribution.cpp:1227
void collect_associated(std::vector< TBaseElem * > &vAssElem, TElem *elem, bool clearContainer=true) const
returns the adjacent elements
Definition: dof_distribution.h:176
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 inner_dof_indices(GridObject *elem, size_t fct, std::vector< DoFIndex > &ind, bool bClear=true) const
extracts all multiindices of a function in the inner (sorted)
Definition: dof_distribution.cpp:1243
size_t num_indices() const
return the number of dofs distributed
Definition: dof_distribution.h:218
bool is_contained(TGeomObj *obj) const
returns if the grid object is part of the dof distribution
Definition: dof_distribution.h:208
SmartPtr< MultiGrid > multi_grid()
Definition: dof_distribution.h:69
int num_subsets() const
returns number of subsets
Definition: dof_distribution_info.h:192
bool is_def_in_subset(size_t fct, int si) const
returns if a function is defined on a subset
Definition: dof_distribution_info.h:217
size_t max_fct_dofs(const size_t fct, int dim) const
returns the maximal number of dofs on a dimension for a function component
Definition: dof_distribution_info.h:250
const LFEID & lfeid(size_t fct) const
Definition: dof_distribution_info.h:226
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
size_t num_fct() const
number of discrete functions on subset si
Definition: dof_distribution_info.h:176
Base-class for edges.
Definition: grid_base_objects.h:397
virtual Vertex * vertex(size_t index) const
Definition: grid_base_objects.h:366
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
virtual Vertex * vertex(size_t index) const
Definition: grid_base_objects.h:486
represents numerical solutions on a grid using an algebraic vector
Definition: grid_function.h:121
SmartPtr< ApproximationSpace< TDomain > > approx_space()
returns approx space
Definition: grid_function.h:348
const GridLevel & grid_level() const
returns the grid level
Definition: grid_function.h:247
Definition: grid_level.h:42
ViewType type() const
returns the type
Definition: grid_level.h:77
int level() const
returns the level
Definition: grid_level.h:74
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
virtual int base_object_id() const =0
virtual ReferenceObjectID reference_object_id() const =0
Identifier for Local Finite Elements.
Definition: local_finite_element_id.h:98
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
int dim() const
returns the space dimension of the local finite element
Definition: local_finite_element_id.h:129
@ CROUZEIX_RAVIART
Definition: local_finite_element_id.h:105
@ PIECEWISE_CONSTANT
Definition: local_finite_element_id.h:106
@ LAGRANGE
Definition: local_finite_element_id.h:104
Definition: multi_grid.h:72
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
void set_storage_type(uint type)
sets the storage type
Definition: parallel_matrix.h:101
Standard Prolongation Operator.
Definition: std_transfer.h:59
void assemble_restriction(matrix_type &mat, const DoFDistribution &coarseDD, const DoFDistribution &fineDD, ConstSmartPtr< TDomain > spDomain)
Definition: std_transfer_impl.h:410
void assemble_prolongation_p1(matrix_type &mat, const DoFDistribution &fineDD, const DoFDistribution &coarseDD)
Definition: std_transfer_impl.h:47
virtual SmartPtr< matrix_type > restriction(const GridLevel &coarseGL, const GridLevel &fineGL, ConstSmartPtr< ApproximationSpace< TDomain > > spApproxSpace)
returns restriction as a matrix
Definition: std_transfer_impl.h:668
TAlgebra::matrix_type matrix_type
Type of Matrix.
Definition: std_transfer.h:71
virtual void do_restrict(vector_type &uCoarse, const vector_type &uFine)
apply transposed Operator, restrict function
Definition: std_transfer.h:138
virtual SmartPtr< matrix_type > prolongation(const GridLevel &fineGL, const GridLevel &coarseGL, ConstSmartPtr< ApproximationSpace< TDomain > > spApproxSpace)
returns prolongation as a matrix
Definition: std_transfer_impl.h:605
virtual void prolongate(vector_type &uFine, const vector_type &uCoarse)
apply Operator, interpolate function
Definition: std_transfer.h:128
virtual SmartPtr< ITransferOperator< TDomain, TAlgebra > > clone()
returns new instance with same setting
Definition: std_transfer_impl.h:810
void write_debug(const matrix_type &mat, std::string name, const GridLevel &glTo, const GridLevel &glFrom)
debug writing of matrix
Definition: std_transfer_impl.h:825
void assemble_prolongation(matrix_type &mat, const DoFDistribution &fineDD, const DoFDistribution &coarseDD, ConstSmartPtr< TDomain > spDomain)
Definition: std_transfer_impl.h:217
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
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
virtual Vertex * vertex(size_t index) const
Definition: grid_base_objects.h:727
void ScaleLayoutValues(TVector *pVec, const IndexLayout &layout, number scale)
scales the values of a vector by a given number only on the layout indices
Definition: parallelization_util.h:350
void AdditiveToConsistent(TVector *pVec, const IndexLayout &masterLayout, const IndexLayout &slaveLayout, pcl::InterfaceCommunicator< IndexLayout > *pCom=NULL)
changes parallel storage type from additive to consistent
Definition: parallelization_util.h:160
@ PST_CONSISTENT
Definition: parallel_storage_type.h:68
std::string ElementDebugInfo(const Grid &grid, GridObject *e)
Returns a string containing information on the given element.
Definition: debug_util.cpp:991
std::string ToString(const T &t)
Convert a object supporting 'std::cout << obj' to a string.
Definition: string_util.h:362
#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
@ CT_ALL
Definition: ass_tuner.h:60
ReferenceObjectID
these ids are used to identify the shape of a geometric object.
Definition: grid_base_objects.h:74
@ ROID_QUADRILATERAL
Definition: grid_base_objects.h:79
@ ROID_EDGE
Definition: grid_base_objects.h:77
@ ROID_HEXAHEDRON
Definition: grid_base_objects.h:81
@ ROID_VERTEX
Definition: grid_base_objects.h:76
number & DoFRef(TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
Definition: multi_index.h:276
void ShapesAtGlobalPosition(std::vector< std::vector< number > > &vvShape, const std::vector< MathVector< dim > > &vGlobPos, const ReferenceObjectID roid, const std::vector< MathVector< dim > > &vCornerCoord, const LFEID &lfeID)
Definition: dof_position_util.cpp:285
bool MatMultDirect(ParallelVector< vector_type > &dest, const number &beta1, const ParallelMatrix< matrix_type > &A1, const ParallelVector< vector_type > &w1)
Definition: parallel_matrix_impl.h:224
@ 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
bool InnerDoFPosition(std::vector< MathVector< dim > > &vPos, const ReferenceObjectID roid, const std::vector< MathVector< dim > > &vCornerCoord, const LFEID &lfeID)
�
Definition: dof_position_util.cpp:112
#define PROFILE_FUNC_GROUP(groups)
Definition: profiler.h:258
struct to distinguish already assembled operators
Definition: std_transfer.h:195