ug4
std_transfer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-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__OPERATOR__LINEAR_OPERATOR__STD_TRANSFER__
34 #define __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__STD_TRANSFER__
35 
36 // extern headers
37 #include <iostream>
38 
39 // other ug4 modules
40 #include "common/common.h"
41 #include "transfer_interface.h"
43 
44 #ifdef UG_PARALLEL
46 #endif
47 
48 namespace ug{
49 
51 
56 template <typename TDomain, typename TAlgebra>
57 class StdTransfer :
58  virtual public ITransferOperator<TDomain, TAlgebra>
59 {
60  public:
63 
65  typedef TAlgebra algebra_type;
66 
68  typedef typename TAlgebra::vector_type vector_type;
69 
71  typedef typename TAlgebra::matrix_type matrix_type;
72 
74  typedef TDomain domain_type;
75 
78 
79  public:
81  StdTransfer() : ITransferOperator<TDomain, TAlgebra>(),
83  m_dampRes(1.0), m_dampProl(1.0),
84  bCached(true), m_bUseTransposed(true),
85  m_spDebugWriter(NULL)
86  {};
87 
89  virtual ~StdTransfer(){};
90 
93 
96 
98  void set_debug(SmartPtr<IDebugWriter<TAlgebra> > spDebugWriter) {
99  m_spDebugWriter = spDebugWriter;
100  }
101 
103 
113 
115  void set_use_transposed(bool bTransposed) {m_bUseTransposed = bTransposed;}
116 
117  public:
119  virtual void set_levels(GridLevel coarseLevel, GridLevel fineLevel) {}
120 
122  virtual void init() {}
123 
126 
128  virtual void prolongate(vector_type& uFine, const vector_type& uCoarse){
129  GF* pFine = dynamic_cast<GF*>(&uFine);
130  const GF* pCoarse = dynamic_cast<const GF*>(&uCoarse);
131  if(!pFine || !pCoarse)
132  UG_THROW("StdTransfer: fine and coarse vectors expected to be "
133  "a grid function.");
134  prolongate(*pFine, *pCoarse);
135  }
136 
138  virtual void do_restrict(vector_type& uCoarse, const vector_type& uFine){
139  const GF* pFine = dynamic_cast<const GF*>(&uFine);
140  GF* pCoarse = dynamic_cast<GF*>(&uCoarse);
141  if(!pFine || !pCoarse)
142  UG_THROW("StdTransfer: fine and coarse vectors expected to be "
143  "a grid function.");
144  do_restrict(*pCoarse, *pFine);
145  }
146 
147  public:
149  virtual SmartPtr<matrix_type>
150  prolongation(const GridLevel& fineGL, const GridLevel& coarseGL,
152 
154  virtual SmartPtr<matrix_type>
155  restriction(const GridLevel& coarseGL, const GridLevel& fineGL,
157 
159  void prolongate(GF& uFine, const GF& uCoarse);
160 
162  void do_restrict(GF& uCoarse, const GF& uFine);
163 
164  protected:
166  void write_debug(const matrix_type& mat, std::string name,
167  const GridLevel& glTo, const GridLevel& glFrom);
168 
169  template <typename TChild>
171  const DoFDistribution& coarseDD,
172  const DoFDistribution& fineDD,
173  ConstSmartPtr<TDomain> spDomain);
175  const DoFDistribution& coarseDD,
176  const DoFDistribution& fineDD,
177  ConstSmartPtr<TDomain> spDomain);
178 
179  template <typename TChild>
181  const DoFDistribution& fineDD,
182  const DoFDistribution& coarseDD,
183  ConstSmartPtr<TDomain> spDomain);
185  const DoFDistribution& fineDD,
186  const DoFDistribution& coarseDD,
187  ConstSmartPtr<TDomain> spDomain);
188 
190  const DoFDistribution& fineDD,
191  const DoFDistribution& coarseDD);
192 
193  protected:
195  struct TransferKey{
196  TransferKey(const GridLevel& toGL_, const GridLevel& fromGL_,
197  const RevisionCounter& revCnt_)
198  : toGL(toGL_), fromGL(fromGL_), revCnt(revCnt_) {}
201 
202  bool operator<(const TransferKey& other) const {
203  if(revCnt != other.revCnt) return revCnt < other.revCnt;
204  if(toGL != other.toGL) return toGL < other.toGL;
205  return fromGL < other.fromGL;
206  }
207  };
208 
209  typedef std::map<TransferKey, SmartPtr<matrix_type> > TransferMap;
212 
213  void remove_outdated(TransferMap& map, const RevisionCounter& revCnt) {
214  typedef typename TransferMap::iterator iterator;
215  for(iterator iter = map.begin(); iter != map.end();)
216  {
217  const RevisionCounter& cnt = iter->first.revCnt;
218  if((cnt.obj() == revCnt.obj()) && (cnt != revCnt)){
219  map.erase(iter++);
220  } else {
221  ++iter;
222  }
223  }
224  }
225 
226  protected:
229 
232 
236 
238  bool bCached;
239 
242 
245 };
246 
247 } // end namespace ug
248 
249 #include "std_transfer_impl.h"
250 
251 #endif /* __H__UG__LIB_DISC__OPERATOR__LINEAR_OPERATOR__STD_TRANSFER__ */
location name
Definition: checkpoint_util.lua:128
Definition: smart_pointer.h:296
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
represents numerical solutions on a grid using an algebraic vector
Definition: grid_function.h:121
Definition: grid_level.h:42
base class for all debug writer
Definition: debug_writer.h:244
interface for transfer routines
Definition: transfer_interface.h:50
std::vector< SmartPtr< IConstraint< TAlgebra > > > m_vConstraint
list of post processes
Definition: transfer_interface.h:117
Wrapper for sequential matrices to handle them in parallel.
Definition: parallel_matrix.h:65
Class used to identify a state of adaption of a grid, approx-space, ...
Definition: revision_counter.h:56
const void * obj() const
returns the associated object
Definition: revision_counter.h:123
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
TransferMap m_mRestriction
Definition: std_transfer.h:210
TAlgebra::matrix_type matrix_type
Type of Matrix.
Definition: std_transfer.h:71
void remove_outdated(TransferMap &map, const RevisionCounter &revCnt)
Definition: std_transfer.h:213
TAlgebra::vector_type vector_type
Type of Vector.
Definition: std_transfer.h:68
GridFunction< TDomain, TAlgebra > GF
Type of GridFunction.
Definition: std_transfer.h:77
StdTransfer()
Default constructor.
Definition: std_transfer.h:81
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
ITransferOperator< TDomain, TAlgebra > base_type
Type of base class.
Definition: std_transfer.h:62
bool m_bUseTransposed
flag if transposed is used
Definition: std_transfer.h:241
SmartPtr< IDebugWriter< TAlgebra > > m_spDebugWriter
debug writer
Definition: std_transfer.h:244
virtual void set_levels(GridLevel coarseLevel, GridLevel fineLevel)
Set levels.
Definition: std_transfer.h:119
virtual void init()
initialize the operator
Definition: std_transfer.h:122
void set_restriction_damping(number damp)
set restriction damping (only applied on vector operation, not (!!) in assembled matrices)
Definition: std_transfer.h:92
std::map< TransferKey, SmartPtr< matrix_type > > TransferMap
Definition: std_transfer.h:209
TDomain domain_type
Type of Domain.
Definition: std_transfer.h:74
void enable_p1_lagrange_optimization(bool enable)
enables/disables an assembling optimization for p1-lagrange elements
Definition: std_transfer.h:111
number m_dampProl
Definition: std_transfer.h:235
void set_use_transposed(bool bTransposed)
sets if restriction and prolongation are transposed
Definition: std_transfer.h:115
virtual void prolongate(vector_type &uFine, const vector_type &uCoarse)
apply Operator, interpolate function
Definition: std_transfer.h:128
bool p1_lagrange_optimization_enabled() const
Definition: std_transfer.h:112
number m_dampRes
damping parameter
Definition: std_transfer.h:234
TAlgebra algebra_type
Type of Algebra.
Definition: std_transfer.h:65
TransferMap m_mProlongation
Definition: std_transfer.h:211
bool m_p1LagrangeOptimizationEnabled
flag for p1-lagrange-optimization
Definition: std_transfer.h:231
void set_prolongation_damping(number damp)
set prolongation damping (only applied on vector operation, not (!!) in assembled matrices)
Definition: std_transfer.h:95
virtual SmartPtr< ITransferOperator< TDomain, TAlgebra > > clone()
returns new instance with same setting
Definition: std_transfer_impl.h:810
void set_debug(SmartPtr< IDebugWriter< TAlgebra > > spDebugWriter)
set debug writer
Definition: std_transfer.h:98
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
virtual ~StdTransfer()
virtual destructor
Definition: std_transfer.h:89
bool bCached
flag if cached (matrix) transfer used
Definition: std_transfer.h:238
#define UG_THROW(msg)
Definition: error.h:57
double number
Definition: types.h:124
the ug namespace
struct to distinguish already assembled operators
Definition: std_transfer.h:195
GridLevel toGL
Definition: std_transfer.h:199
bool operator<(const TransferKey &other) const
Definition: std_transfer.h:202
TransferKey(const GridLevel &toGL_, const GridLevel &fromGL_, const RevisionCounter &revCnt_)
Definition: std_transfer.h:196
RevisionCounter revCnt
Definition: std_transfer.h:200
GridLevel fromGL
Definition: std_transfer.h:199