ug4
obstacle_constraint_interface.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3  * Author: Raphael Prohl
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_ALGEBRA__OPERATOR__PRECONDITIONER__PROJECTED_GAUSS_SEIDEL__OBSTACLE_CONSTRAINT_INTERFACE__
34 #define __H__UG__LIB_ALGEBRA__OPERATOR__PRECONDITIONER__PROJECTED_GAUSS_SEIDEL__OBSTACLE_CONSTRAINT_INTERFACE__
35 
39 
41 
42 using namespace std;
43 
44 namespace ug{
45 
47 
67 template <typename TDomain, typename TAlgebra>
69  public IDomainConstraint<TDomain, TAlgebra>
70  // TODO: think about, restructuring the IConstraint-Interface in order to distinguish between
71  // a constraint having an effect on the assembling process and a constraint, which is considered in the
72  // solver (e.g. by means of 'adjust_restriction') only!
73 {
74  public:
77 
79  typedef TAlgebra algebra_type;
80 
82  typedef typename algebra_type::matrix_type matrix_type;
83 
85  typedef typename algebra_type::vector_type vector_type;
86 
89 
91  typedef TDomain domain_type;
92 
94  static const int dim = domain_type::dim;
95 
97  typedef typename domain_type::position_type position_type;
98 
99  public:
102  {
103  clear();
104 
105  m_spDD = u.dof_distribution();
106  m_spDomain = u.domain();
107  };
108 
111  //clear();
112  UG_THROW("In 'IObstacleConstraint()': A constructor with a GridFunction as parameter"
113  "is needed here!");
114  };
115 
117  #ifdef UG_FOR_LUA
118  void add(const char* name, const char* function);
119  void add(const char* name, const char* function, const char* subsets);
120  #endif
121 
123  void add(SmartPtr<UserData<number, dim, bool> > func, const char* function);
124  void add(SmartPtr<UserData<number, dim, bool> > func, const char* function, const char* subsets);
125 
127  void add(SmartPtr<UserData<number, dim> > func, const char* function);
128  void add(SmartPtr<UserData<number, dim> > func, const char* function, const char* subsets);
129 
131  void add(number value, const char* function);
132  void add(number value, const char* function, const char* subsets);
133 
135  void add(SmartPtr<UserData<MathVector<dim>, dim> > func, const char* functions);
136  void add(SmartPtr<UserData<MathVector<dim>, dim> > func, const char* functions, const char* subsets);
137 
138 
141  void init();
142 
144  bool is_obs_dof(const DoFIndex& dof);
145 
147  void reset_active_dofs(){m_vActiveDofs.resize(0);}
148 
150  void active_dofs(vector<DoFIndex>& vActiveDoFs)
151  {vActiveDoFs = m_vActiveDofs;}
152 
153 
157  virtual void preprocess(){};
158 
160  virtual void adjust_sol_and_cor(value_type& sol_i, value_type& c_i, bool& dofIsAdmissible,
161  const DoFIndex& dof) = 0;
162 
165 
166 
168  virtual void restrict_obs_values() = 0;
169 
170 
172  virtual ~IObstacleConstraint(){};
173 
174  public:
176  // Implement Interface
178 
181  ConstSmartPtr<DoFDistribution> dd, int type, number time = 0.0,
183  const number s_a0 = 1.0){
184  UG_LOG("IObstacleConstraint::adjust_jacobian() \n");
185  };
186 
189  ConstSmartPtr<DoFDistribution> dd, int type, number time = 0.0,
191  const std::vector<number>* vScaleMass = NULL,
192  const std::vector<number>* vScaleStiff = NULL){
193  UG_LOG("IObstacleConstraint::adjust_defect() \n");
194  };
195 
198  ConstSmartPtr<DoFDistribution> dd, int type, number time = 0.0){
199  UG_LOG("IObstacleConstraint::adjust_solution() \n");
200  };
201 
204  ConstSmartPtr<DoFDistribution> dd, int type, number time = 0.0){
205  UG_LOG("IObstacleConstraint::adjust_linear() \n");
206  };
207 
209  void adjust_rhs(vector_type& b, const vector_type& u,
210  ConstSmartPtr<DoFDistribution> dd, int type, number time = 0.0){
211  UG_LOG("IObstacleConstraint::adjust_rhs() \n");
212  };
213 
218  int type,
219  number time = 0.0){
220  UG_LOG("IObstacleConstraint::adjust_prolongationP() \n");
221  };
222 
224  virtual void adjust_restriction(matrix_type& R,
227  int type,
228  number time = 0.0);
229 
231  //TODO: does another type make more sense?
232  virtual int type() const {return CT_CONSTRAINTS;}
233 
234  private:
236  void extract_data();
237 
238  template <typename TUserData, typename TScheduledUserData>
239  void extract_data(std::map<int, std::vector<TUserData*> >& mvUserDataObsSegment,
240  std::vector<TScheduledUserData>& vUserData);
241 
243  void clear();
244 
245  void check_functions_and_subsets(FunctionGroup& functionGroup, SubsetGroup& subsetGroup,
246  size_t numFct) const;
247 
249  void init_obstacle_dofs_with_values(number time);
250 
251  template <typename TUserData>
252  void init_obstacle_dofs_with_values(const std::map<int, std::vector<TUserData*> >& mvUserData, number time);
253 
254  template <typename TBaseElem, typename TUserData>
255  void init_obstacle_dofs_with_values(const std::vector<TUserData*>& vUserData, int si, number time);
256 
257  protected:
259  map<DoFIndex, number> m_mObstacleValues;
260 
262  vector<int> m_vObsSubsets;
263 
265  vector<DoFIndex> m_vActiveDofs;
266 
267  private:
270 
273 
275  struct NumberData
276  {
277  const static bool isConditional = false;
278  const static size_t numFct = 1;
281  std::string fctName_)
282  : spFunctor(functor_), fctName(fctName_), bWholeDomain(true)
283  {}
285  std::string fctName_, std::string ssName_)
286  : spFunctor(functor_), fctName(fctName_), ssName(ssName_),
287  bWholeDomain(false)
288  {}
290  number time, int si) const
291  {
292  (*spFunctor)(val[0], x, time, si); return true;
293  }
294 
296  std::string fctName;
297  std::string ssName;
298  size_t fct[numFct];
301  };
302 
305  {
306  const static bool isConditional = true;
307  const static size_t numFct = 1;
310  std::string fctName_)
311  : spFunctor(functor_), fctName(fctName_), bWholeDomain(true)
312  {}
314  std::string fctName_, std::string ssName_)
315  : spFunctor(functor_), fctName(fctName_), ssName(ssName_),
316  bWholeDomain(true)
317  {}
319  number time, int si) const
320  {
321  return (*spFunctor)(val[0], x, time, si);
322  }
323 
325  std::string fctName;
326  std::string ssName;
327  size_t fct[numFct];
330  };
331 
334  {
335  const static bool isConditional = false;
336  const static size_t numFct = 1;
339  std::string fctName_)
340  : functor(value_), fctName(fctName_), bWholeDomain(true)
341  {}
343  std::string fctName_, std::string ssName_)
344  : functor(value_), fctName(fctName_), ssName(ssName_),
345  bWholeDomain(false)
346  {}
347  inline bool operator()(MathVector<1>& val, const MathVector<dim> x,
348  number time, int si) const
349  {
350  val[0] = functor; return true;
351  }
352 
354  std::string fctName;
355  std::string ssName;
356  size_t fct[numFct];
359  };
360 
362  struct VectorData
363  {
364  const static bool isConditional = false;
365  const static size_t numFct = dim;
368  std::string fctName_)
369  : spFunctor(value_), fctName(fctName_), bWholeDomain(true)
370  {}
372  std::string fctName_, std::string ssName_)
373  : spFunctor(value_), fctName(fctName_), ssName(ssName_),
374  bWholeDomain(false)
375  {}
377  number time, int si) const
378  {
379  (*spFunctor)(val, x, time, si); return true;
380  }
381 
383  std::string fctName;
384  std::string ssName;
385  size_t fct[numFct];
388  };
389 
390  std::vector<CondNumberData> m_vCondNumberData;
391  std::vector<NumberData> m_vNumberData;
392  std::vector<ConstNumberData> m_vConstNumberData;
393 
394  std::vector<VectorData> m_vVectorData;
395 
397  std::map<int, std::vector<NumberData*> > m_mNumberObsSegment;
398 
400  std::map<int, std::vector<ConstNumberData*> > m_mConstNumberObsSegment;
401 
403  std::map<int, std::vector<CondNumberData*> > m_mCondNumberObsSegment;
404 
406  std::map<int, std::vector<VectorData*> > m_mVectorObsSegment;
407 };
408 
409 
410 } // end namespace ug
411 
412 // include implementation
414 
415 #endif /* __H__UG__LIB_ALGEBRA__OPERATOR__PRECONDITIONER__PROJECTED_GAUSS_SEIDEL__OBSTACLE_CONSTRAINT_INTERFACE__ */
416 
location name
Definition: checkpoint_util.lua:128
Definition: smart_pointer.h:296
Definition: smart_pointer.h:108
Definition: function_group.h:52
represents numerical solutions on a grid using an algebraic vector
Definition: grid_function.h:121
SmartPtr< TDomain > domain()
returns domain
Definition: grid_function.h:342
SmartPtr< DoFDistribution > dof_distribution()
Definition: grid_function.h:236
Definition: constraint_interface.h:162
Interface for Obstacle Constraints.
Definition: obstacle_constraint_interface.h:73
virtual void adjust_prolongation(matrix_type &P, ConstSmartPtr< DoFDistribution > ddFine, ConstSmartPtr< DoFDistribution > ddCoarse, int type, number time=0.0)
sets constraints in prolongation
Definition: obstacle_constraint_interface.h:215
IObstacleConstraint()
constructor
Definition: obstacle_constraint_interface.h:110
virtual void preprocess()
Definition: obstacle_constraint_interface.h:157
IObstacleConstraint(const GridFunction< TDomain, TAlgebra > &u)
constructor for an obstacle defined on some subset(s)
Definition: obstacle_constraint_interface.h:101
std::map< int, std::vector< VectorData * > > m_mVectorObsSegment
non-conditional obstacle values for all subsets
Definition: obstacle_constraint_interface.h:406
ConstSmartPtr< DoFDistribution > m_spDD
pointer to the DofDistribution on the whole domain
Definition: obstacle_constraint_interface.h:272
std::map< int, std::vector< ConstNumberData * > > m_mConstNumberObsSegment
constant obstacle values for all subsets
Definition: obstacle_constraint_interface.h:400
vector_type::value_type value_type
Value type.
Definition: obstacle_constraint_interface.h:88
ConstSmartPtr< TDomain > m_spDomain
pointer to the domain
Definition: obstacle_constraint_interface.h:269
TDomain domain_type
Type of domain.
Definition: obstacle_constraint_interface.h:91
TAlgebra algebra_type
Algebra type.
Definition: obstacle_constraint_interface.h:79
map< DoFIndex, number > m_mObstacleValues
map to store obstacle values with its corresponding DoFs
Definition: obstacle_constraint_interface.h:259
vector< int > m_vObsSubsets
stores the subset-indices of the obstacle subsets
Definition: obstacle_constraint_interface.h:262
virtual void adjust_sol_and_cor(value_type &sol_i, value_type &c_i, bool &dofIsAdmissible, const DoFIndex &dof)=0
projects the i-th index of the solution onto the admissible set and adjusts the correction
void adjust_defect(vector_type &d, const vector_type &u, ConstSmartPtr< DoFDistribution > dd, int type, number time=0.0, ConstSmartPtr< VectorTimeSeries< vector_type > > vSol=NULL, const std::vector< number > *vScaleMass=NULL, const std::vector< number > *vScaleStiff=NULL)
sets a zero value in the defect for all dirichlet indices
Definition: obstacle_constraint_interface.h:188
virtual void restrict_obs_values()=0
restricts the obstacle values to a coarser grid in a multigrid hierarchy
std::vector< NumberData > m_vNumberData
Definition: obstacle_constraint_interface.h:391
std::vector< CondNumberData > m_vCondNumberData
Definition: obstacle_constraint_interface.h:390
void adjust_jacobian(matrix_type &J, const vector_type &u, ConstSmartPtr< DoFDistribution > dd, int type, number time=0.0, ConstSmartPtr< VectorTimeSeries< vector_type > > vSol=NULL, const number s_a0=1.0)
sets a unity row for all dirichlet indices
Definition: obstacle_constraint_interface.h:180
virtual int type() const
returns the type of the constraints
Definition: obstacle_constraint_interface.h:232
std::map< int, std::vector< CondNumberData * > > m_mCondNumberObsSegment
conditional obstacle values for all subsets
Definition: obstacle_constraint_interface.h:403
void adjust_solution(vector_type &u, ConstSmartPtr< DoFDistribution > dd, int type, number time=0.0)
sets the dirichlet value in the solution for all dirichlet indices
Definition: obstacle_constraint_interface.h:197
virtual ~IObstacleConstraint()
Destructor.
Definition: obstacle_constraint_interface.h:172
vector< DoFIndex > m_vActiveDofs
stores the dofs, which satisfy the constraints with equality
Definition: obstacle_constraint_interface.h:265
IDomainConstraint< TDomain, TAlgebra > base_type
Base Type.
Definition: obstacle_constraint_interface.h:76
std::vector< VectorData > m_vVectorData
Definition: obstacle_constraint_interface.h:394
void adjust_rhs(vector_type &b, const vector_type &u, ConstSmartPtr< DoFDistribution > dd, int type, number time=0.0)
sets the dirichlet value in the right-hand side
Definition: obstacle_constraint_interface.h:209
std::map< int, std::vector< NumberData * > > m_mNumberObsSegment
non-conditional obstacle values for all subsets
Definition: obstacle_constraint_interface.h:397
virtual void adjust_defect_to_constraint(vector_type &d)=0
the defect needs to be adjusted for the active indices (those indices, which are in contact)
std::vector< ConstNumberData > m_vConstNumberData
Definition: obstacle_constraint_interface.h:392
void active_dofs(vector< DoFIndex > &vActiveDoFs)
returns the vector storing the active dofs
Definition: obstacle_constraint_interface.h:150
algebra_type::matrix_type matrix_type
Matrix type.
Definition: obstacle_constraint_interface.h:82
domain_type::position_type position_type
Type of position coordinates (e.g. position_type)
Definition: obstacle_constraint_interface.h:97
algebra_type::vector_type vector_type
Vector type.
Definition: obstacle_constraint_interface.h:85
void reset_active_dofs()
resets the vector storing the active dofs
Definition: obstacle_constraint_interface.h:147
void adjust_linear(matrix_type &A, vector_type &b, ConstSmartPtr< DoFDistribution > dd, int type, number time=0.0)
sets unity rows in A and dirichlet values in right-hand side b
Definition: obstacle_constraint_interface.h:203
Definition: multi_index.h:50
Wrapper for sequential matrices to handle them in parallel.
Definition: parallel_matrix.h:65
Group of subsets.
Definition: subset_group.h:51
time series of solutions and corresponding time point
Definition: solution_time_series.h:59
static const int dim
virtual void init()
#define UG_THROW(msg)
Definition: error.h:57
#define UG_LOG(msg)
Definition: log.h:367
double number
Definition: types.h:124
Definition: smart_pointer.h:814
the ug namespace
@ CT_CONSTRAINTS
Definition: ass_tuner.h:58
function func(x, y, z, t, si)
T value_type
Definition: sparsematrix_interface.h:2
grouping for subset and conditional data
Definition: obstacle_constraint_interface.h:305
CondNumberData(SmartPtr< UserData< number, dim, bool > > functor_, std::string fctName_)
Definition: obstacle_constraint_interface.h:309
SmartPtr< UserData< number, dim, bool > > spFunctor
Definition: obstacle_constraint_interface.h:324
SubsetGroup ssGrp
Definition: obstacle_constraint_interface.h:328
std::string ssName
Definition: obstacle_constraint_interface.h:326
bool bWholeDomain
Definition: obstacle_constraint_interface.h:329
CondNumberData(SmartPtr< UserData< number, dim, bool > > functor_, std::string fctName_, std::string ssName_)
Definition: obstacle_constraint_interface.h:313
bool operator()(MathVector< 1 > &val, const MathVector< dim > x, number time, int si) const
Definition: obstacle_constraint_interface.h:318
std::string fctName
Definition: obstacle_constraint_interface.h:325
MathVector< 1 > value_type
Definition: obstacle_constraint_interface.h:308
grouping for subset and conditional data
Definition: obstacle_constraint_interface.h:334
bool bWholeDomain
Definition: obstacle_constraint_interface.h:358
ConstNumberData(number value_, std::string fctName_, std::string ssName_)
Definition: obstacle_constraint_interface.h:342
std::string fctName
Definition: obstacle_constraint_interface.h:354
MathVector< 1 > value_type
Definition: obstacle_constraint_interface.h:337
ConstNumberData(number value_, std::string fctName_)
Definition: obstacle_constraint_interface.h:338
SubsetGroup ssGrp
Definition: obstacle_constraint_interface.h:357
bool operator()(MathVector< 1 > &val, const MathVector< dim > x, number time, int si) const
Definition: obstacle_constraint_interface.h:347
std::string ssName
Definition: obstacle_constraint_interface.h:355
number functor
Definition: obstacle_constraint_interface.h:353
grouping for subset and non-conditional data
Definition: obstacle_constraint_interface.h:276
MathVector< 1 > value_type
Definition: obstacle_constraint_interface.h:279
bool operator()(MathVector< 1 > &val, const MathVector< dim > x, number time, int si) const
Definition: obstacle_constraint_interface.h:289
SubsetGroup ssGrp
Definition: obstacle_constraint_interface.h:299
bool bWholeDomain
Definition: obstacle_constraint_interface.h:300
NumberData(SmartPtr< UserData< number, dim > > functor_, std::string fctName_)
Definition: obstacle_constraint_interface.h:280
NumberData(SmartPtr< UserData< number, dim > > functor_, std::string fctName_, std::string ssName_)
Definition: obstacle_constraint_interface.h:284
std::string fctName
Definition: obstacle_constraint_interface.h:296
std::string ssName
Definition: obstacle_constraint_interface.h:297
SmartPtr< UserData< number, dim > > spFunctor
Definition: obstacle_constraint_interface.h:295
grouping for subset and non-conditional data
Definition: obstacle_constraint_interface.h:363
bool operator()(MathVector< dim > &val, const MathVector< dim > x, number time, int si) const
Definition: obstacle_constraint_interface.h:376
VectorData(SmartPtr< UserData< MathVector< dim >, dim > > value_, std::string fctName_, std::string ssName_)
Definition: obstacle_constraint_interface.h:371
std::string fctName
Definition: obstacle_constraint_interface.h:383
MathVector< dim > value_type
Definition: obstacle_constraint_interface.h:366
SmartPtr< UserData< MathVector< dim >, dim > > spFunctor
Definition: obstacle_constraint_interface.h:382
std::string ssName
Definition: obstacle_constraint_interface.h:384
bool bWholeDomain
Definition: obstacle_constraint_interface.h:387
VectorData(SmartPtr< UserData< MathVector< dim >, dim > > value_, std::string fctName_)
Definition: obstacle_constraint_interface.h:367
SubsetGroup ssGrp
Definition: obstacle_constraint_interface.h:386