Plugins
damage.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019: Ruhr University Bochum
3  * Authors: 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 __SMALL_STRAIN_MECHANICS__DAMAGE_H_
34 #define __SMALL_STRAIN_MECHANICS__DAMAGE_H_
35 
40 
41 namespace ug{
42 namespace SmallStrainMechanics{
43 
44 
45 
47 // Helper traits for constraints
49 
50 template <int dim> struct contrained_dim_traits;
51 template <> struct contrained_dim_traits<2>
52 {
55 };
56 template <> struct contrained_dim_traits<3>
57 {
60 };
61 
62 
63 template <int dim>
64 void AveragePositions( MathVector<dim>& vCenter,
65  const std::vector<MathVector<dim> >& vCornerCoords);
66 
67 
68 template <typename TDomain>
70  SmartPtr<GridFunction<TDomain, CPUAlgebra> > spF, // some dummy function
72  std::vector< typename grid_dim_traits<TDomain::dim>::element_type* >& vNeighbors);
73 
74 template <typename TDomain>
76 (
77  std::vector< typename grid_dim_traits<TDomain::dim>::element_type* >& vElem,
78  std::vector<size_t>& vIndex,
79  std::vector< MathVector<TDomain::dim> >& vDistance,
81  typename TDomain::grid_type& grid,
82  typename TDomain::position_accessor_type& aaPos,
83  SmartPtr<GridFunction<TDomain, CPUAlgebra> > spF, bool fillElemSizeIntoVector = false
84 );
85 
86 template <typename TDomain>
89  std::vector< std::vector< number > >& vStencil,
90  std::vector< std::vector<size_t> >& vIndex, bool fillElemSizeIntoVector = false);
91 
92 template <typename TDomain>
95  std::vector< std::vector< number > >& vStencil,
96  std::vector< std::vector<size_t> >& vIndex, bool fillElemSizeIntoVector = false);
97 
98 template <typename TDomain>
101  std::vector< std::vector< number > >& vStencil,
102  std::vector< std::vector<size_t> >& vIndex,
103  int quadRuleType, bool fillElemSizeIntoVector = false);
104 
105 
107 // Damage updater
109 
110 template <typename TDomain>
112 {
113  public:
114  static const int dim = TDomain::dim;
115  typedef typename TDomain::grid_type TGrid;
121 
123  // Setup and Solve
125  public:
127 
128  void set_disc_type(const std::string& type);
129 
130  void set_quad_rule(int quadRuleType) {m_quadRuleType = quadRuleType;}
131 
134  const number beta, const number r,
135  const number eps, const int maxIter, const number dampNewton);
136 
137  int last_num_iterations() const {return m_lastNumIters;}
138 
139  protected:
142  int m_quadRuleType; // 1 = Midpoint, 2 = Simpson
144 
145  RevisionCounter m_ApproxSpaceRevision; // approximation space revision of cached values
146 
148  // Implementation
150  protected:
151  number DLambda(size_t i) {return m_vStencil[i][0];}
153  {
154  number res = 0.0;
155  for (size_t j = 0; j < m_vIndex[i].size(); ++j)
156  res += m_vStencil[i][j] * (*spF)[ m_vIndex[i][j] ];
157  return res;
158  }
159 
160  std::vector< std::vector< number > > m_vStencil;
161  std::vector< std::vector<size_t> > m_vIndex;
162 
163  public:
165 
166  protected:
168  void write_debug(SmartPtr<GridFunction<TDomain, CPUAlgebra> > spGF, std::string name, int call, int iter);
169  void write_stencil_matrix_debug(SmartPtr<GridFunction<TDomain, CPUAlgebra> > spGF, std::string name, int call);
170 };
171 
172 
174 // RelativeDensityUpdater
176 
177 
178 template <typename TDomain>
180 {
181  public:
182  static const int dim = TDomain::dim;
183  typedef typename TDomain::grid_type TGrid;
188 
190 
192 
193  public:
194  std::vector<number> solve( SmartPtr<GridFunction<TDomain, CPUAlgebra> > spChi,
196  const number betaStar, const number etaChiStar,
197  const number chiMin, const number dt, const int p,
198  const number rho_target, const number MassTol);
199 
200  void set_disc_type(const std::string& type);
202 
203  void set_quad_rule(int quadRuleType) {m_quadRuleType = quadRuleType;}
204 
205  protected:
208  int m_quadRuleType; // 1 = Midpoint, 2 = Simpson
210  RevisionCounter m_ApproxSpaceRevision; // approximation space revision of cached values
211 
213  // Implementation
215  protected:
216  number DLambda(size_t i) {return m_vStencil[i][0];}
218  {
219  number res = 0.0;
220  for (size_t j = 0; j < m_vIndex[i].size(); ++j)
221  res += m_vStencil[i][j] * (*spF)[ m_vIndex[i][j] ];
222  return res;
223  }
224  std::vector< std::vector< number > > m_vStencil;
225  std::vector< std::vector<size_t> > m_vIndex;
226 
227 
228  protected:
232 
233  public:
235 
236  protected:
238  void write_debug(SmartPtr<GridFunction<TDomain, CPUAlgebra> > spGF, std::string name, int call, int iter);
239  void write_stencil_matrix_debug(SmartPtr<GridFunction<TDomain, CPUAlgebra> > spGF, std::string name, int call);
240 };
241 
242 
244 // Damage marking
246 
247 
248 template<typename TDomain>
251  IRefiner& refiner,
252  number minValueToRefine, number maxValueToCoarsen,
253  int maxLevel,
254  const std::vector<MathVector<TDomain::dim,number>* >& vCenter,
255  const std::vector<number>& vRadius);
256 
257 
258 template<typename TDomain>
261 
262 
263 template<typename TDomain>
267 
268 
269 } // end namespace SmallStrainMechanics
270 }// namespace ug
271 
272 #include "damage_impl.h"
273 
274 #endif /* __SMALL_STRAIN_MECHANICS__DAMAGE_H_ */
parameterString p
Definition: Biogas.lua:1
void write_debug(SmartPtr< GridFunction< TDomain, CPUAlgebra > > spGF, std::string name, int call, int iter)
Definition: damage_impl.h:1774
int last_num_iterations() const
Definition: damage.h:137
std::vector< std::vector< size_t > > m_vIndex
Definition: damage.h:161
static const int dim
Definition: damage.h:114
int m_quadRuleType
Definition: damage.h:142
void set_debug(SmartPtr< GridFunctionDebugWriter< TDomain, CPUAlgebra > > spDebugWriter)
Definition: damage_impl.h:1767
number Lambda(size_t i, SmartPtr< GridFunction< TDomain, CPUAlgebra > > spF)
Definition: damage.h:152
DamageFunctionUpdater()
Definition: damage.h:126
bool solve(SmartPtr< GridFunction< TDomain, CPUAlgebra > > spF, SmartPtr< GridFunction< TDomain, CPUAlgebra > > spPsi0, const number beta, const number r, const number eps, const int maxIter, const number dampNewton)
Definition: damage_impl.h:1597
TDomain::grid_type TGrid
Definition: damage.h:115
void set_quad_rule(int quadRuleType)
Definition: damage.h:130
grid_dim_traits< dim >::side_type TSide
Definition: damage.h:117
@ _PARTIAL_INTEGRATION_
Definition: damage.h:140
TDomain::position_accessor_type TPositionAccessor
Definition: damage.h:120
grid_dim_traits< dim >::element_type TElem
Definition: damage.h:116
void set_disc_type(const std::string &type)
Definition: damage_impl.h:1580
void write_stencil_matrix_debug(SmartPtr< GridFunction< TDomain, CPUAlgebra > > spGF, std::string name, int call)
Definition: damage_impl.h:1794
std::vector< std::vector< number > > m_vStencil
Definition: damage.h:160
int m_lastNumIters
Definition: damage.h:143
contrained_dim_traits< dim >::contraining_side_type TContrainingSide
Definition: damage.h:119
SmartPtr< GridFunctionDebugWriter< TDomain, CPUAlgebra > > m_spDebugWriter
Definition: damage.h:167
RevisionCounter m_ApproxSpaceRevision
Definition: damage.h:145
contrained_dim_traits< dim >::contrained_side_type TContrainedSide
Definition: damage.h:118
number DLambda(size_t i)
Definition: damage.h:151
void set_enforce_local_required_beta(bool bEnforce)
Definition: damage.h:201
SmartPtr< GridFunction< TDomain, CPUAlgebra > > m_spLaplaceChi
Definition: damage.h:230
void write_debug(SmartPtr< GridFunction< TDomain, CPUAlgebra > > spGF, std::string name, int call, int iter)
Definition: damage_impl.h:2094
SmartPtr< GridFunction< TDomain, CPUAlgebra > > m_spElemSize
Definition: damage.h:229
void write_stencil_matrix_debug(SmartPtr< GridFunction< TDomain, CPUAlgebra > > spGF, std::string name, int call)
Definition: damage_impl.h:2114
number Lambda(size_t i, SmartPtr< GridFunction< TDomain, CPUAlgebra > > spF)
Definition: damage.h:217
std::vector< number > solve(SmartPtr< GridFunction< TDomain, CPUAlgebra > > spChi, SmartPtr< GridFunction< TDomain, CPUAlgebra > > spDrivingForce, const number betaStar, const number etaChiStar, const number chiMin, const number dt, const int p, const number rho_target, const number MassTol)
Definition: damage_impl.h:1858
TDomain::grid_type TGrid
Definition: damage.h:183
TDomain::position_accessor_type TPositionAccessor
Definition: damage.h:189
RevisionCounter m_ApproxSpaceRevision
Definition: damage.h:210
SmartPtr< GridFunctionDebugWriter< TDomain, CPUAlgebra > > m_spDebugWriter
Definition: damage.h:237
grid_dim_traits< dim >::element_type TElem
Definition: damage.h:184
contrained_dim_traits< dim >::contrained_side_type TContrainedSide
Definition: damage.h:186
static const int dim
Definition: damage.h:182
std::vector< std::vector< size_t > > m_vIndex
Definition: damage.h:225
void set_debug(SmartPtr< GridFunctionDebugWriter< TDomain, CPUAlgebra > > spDebugWriter)
Definition: damage_impl.h:2087
std::vector< std::vector< number > > m_vStencil
Definition: damage.h:224
SmartPtr< GridFunction< TDomain, CPUAlgebra > > m_spChiTrial
Definition: damage.h:231
bool m_bEnforceLocalRequiredBeta
Definition: damage.h:209
number DLambda(size_t i)
Definition: damage.h:216
contrained_dim_traits< dim >::contraining_side_type TContrainingSide
Definition: damage.h:187
void set_quad_rule(int quadRuleType)
Definition: damage.h:203
void set_disc_type(const std::string &type)
Definition: damage_impl.h:1840
grid_dim_traits< dim >::side_type TSide
Definition: damage.h:185
RelativeDensityUpdater()
Definition: damage.h:191
Grid::VertexAttachmentAccessor< position_attachment_type > position_accessor_type
SmartPtr< TGrid > grid()
static const int dim
TGrid grid_type
Variant::Type type()
double number
void InitLaplacian_PartialIntegration(SmartPtr< GridFunction< TDomain, CPUAlgebra > > spF, std::vector< std::vector< number > > &vStencil, std::vector< std::vector< size_t > > &vIndex, int quadRuleType, bool fillElemSizeIntoVector=false)
Definition: damage_impl.h:621
void MarkDamage(SmartPtr< GridFunction< TDomain, CPUAlgebra > > spF, SmartPtr< GridFunction< TDomain, CPUAlgebra > > spPsi0, IRefiner &refiner, number minValueToRefine, number maxValueToCoarsen, int maxLevel, const std::vector< MathVector< TDomain::dim, number > * > &vCenter, const std::vector< number > &vRadius)
Definition: damage_impl.h:2293
void AveragePositions(MathVector< dim > &vCenter, const std::vector< MathVector< dim > > &vCornerCoords)
Definition: damage_impl.h:44
void InitLaplacian_LeastSquares(SmartPtr< GridFunction< TDomain, CPUAlgebra > > spF, std::vector< std::vector< number > > &vStencil, std::vector< std::vector< size_t > > &vIndex, bool fillElemSizeIntoVector=false)
Definition: damage_impl.h:1242
void HadamardProd(SmartPtr< GridFunction< TDomain, CPUAlgebra > > spFPsi0, ConstSmartPtr< GridFunction< TDomain, CPUAlgebra > > spF, ConstSmartPtr< GridFunction< TDomain, CPUAlgebra > > spPsi0)
Definition: damage_impl.h:2602
void CollectStencilNeighbors_NeumannZeroBND_IndexAndDistance(std::vector< typename grid_dim_traits< TDomain::dim >::element_type * > &vElem, std::vector< size_t > &vIndex, std::vector< MathVector< TDomain::dim > > &vDistance, typename grid_dim_traits< TDomain::dim >::element_type *elem, typename TDomain::grid_type &grid, typename TDomain::position_accessor_type &aaPos, SmartPtr< GridFunction< TDomain, CPUAlgebra > > spF, bool fillElemSizeIntoVector=false)
Definition: damage_impl.h:297
void CollectSurfaceNeighbors(SmartPtr< GridFunction< TDomain, CPUAlgebra > > spF, typename grid_dim_traits< TDomain::dim >::element_type *elem, std::vector< typename grid_dim_traits< TDomain::dim >::element_type * > &vNeighbors)
Definition: damage_impl.h:62
void InitLaplacian_TaylorExpansion(SmartPtr< GridFunction< TDomain, CPUAlgebra > > spF, std::vector< std::vector< number > > &vStencil, std::vector< std::vector< size_t > > &vIndex, bool fillElemSizeIntoVector=false)
Definition: damage_impl.h:1035
std::vector< number > DamageStatistic(SmartPtr< GridFunction< TDomain, CPUAlgebra > > spF, SmartPtr< GridFunction< TDomain, CPUAlgebra > > spPsi0)
Definition: damage_impl.h:2519
ConstrainedEdge contrained_side_type
Definition: damage.h:53
ConstrainingEdge contraining_side_type
Definition: damage.h:54
ConstrainingFace contraining_side_type
Definition: damage.h:59
ConstrainedFace contrained_side_type
Definition: damage.h:58