Plugins
adaptive_util_impl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 ADAPTIVE_UTIL_IMPL_H_
34 #define ADAPTIVE_UTIL_IMPL_H_
35 
37 #include "adaptive_util.h"
38 
39 namespace ug{
40 namespace SmallStrainMechanics{
41 
42 template<typename TDomain, typename TElem>
43 void plastic_ip_elem(bool& bPlasticIPs, TElem* elem,
44  const LocalVector& locU, SmartPtr<TDomain> dom,
46 {
47  static const int dim = TDomain::dim;
48 
49  // get vertices and extract corner coordinates
51  position_accessor_type& aaPos = dom->position_accessor();
53  const size_t numVertices = elem->num_vertices();
54  for (size_t i = 0; i < numVertices; ++i) {
55  coCoord[i] = aaPos[elem->vertex(i)];
56  };
57 
58  int quadOrder = elemDisc.get_quad_order();
59 
60  // update the geometry for the Element elem
62  try{
63  geo.update(elem, &(coCoord[0]),
64  LFEID(LFEID::LAGRANGE, dim, 1), quadOrder);
65  }
66  UG_CATCH_THROW("plastic_ip_elem:"
67  " Cannot update Finite Element Geometry.");
68 
69  // get the material law
70  if (elemDisc.get_material_law().invalid())
71  UG_THROW("No material law set in plastic_ip_elem \n");
72 
73  SmartPtr<IMaterialLaw<TDomain> > spMatLaw = elemDisc.get_material_law();
74 
75  // pointer to internal variable of current elem
76  spMatLaw->internal_vars(elem);
77 
79  for (size_t ip = 0; ip < geo.num_ip(); ++ip)
80  {
81  // get displacementGradient (GradU)
82  spMatLaw->template DisplacementGradient<DimFEGeometry<dim> >(GradU, ip, geo, locU);
83 
84  number gamma = spMatLaw->plastic_multiplier(ip, GradU);
85  if (gamma > 0.0)
86  {
87  bPlasticIPs = true; return;
88  }
89  if (gamma == 0.0)
90  {
91  bPlasticIPs = false;
92  }
93  if (gamma < 0.0)
94  UG_THROW("gamma: " << gamma << "in plastIP_elem \n");
95  }
96 }
97 
98 template <typename TDomain, typename TAlgebra>
102 {
103 // types
104  typedef GridFunction<TDomain, TAlgebra> TFunction;
105  typedef typename TFunction::element_type element_type;
106  typedef typename DoFDistribution::traits<element_type>::const_iterator const_iterator;
107 
109 
110  int numMarkedRefine = 0;
111  bool bPlasticIPs = false;
112  const_iterator iter = dd->template begin<element_type>();
113  const_iterator iterEnd = dd->template end<element_type>();
114 
115  // local indices and local algebra
116  LocalIndices ind; LocalVector locU;
117 
118 // loop elements for marking
119  for(; iter != iterEnd; ++iter)
120  {
121  element_type* elem = *iter;
122 
123  // get global indices
124  u.indices(elem, ind);
125 
126  // adapt local algebra
127  locU.resize(ind);
128 
129  // local vector extract -> locU
130  GetLocalVector(locU, u);
131 
132  // reset boolean
133  bPlasticIPs = false;
134 
135  // check, if plastic yielding occurs
136  // at one integration point in the element
137  plastic_ip_elem<TDomain, element_type> (bPlasticIPs, elem, locU,
138  u.domain(), elemDisc);
139 
140  // marks for refinement
141  if(bPlasticIPs)
142  {
143  refiner.mark(elem, RM_REFINE);
144  numMarkedRefine++;
145  }
146  }
147 
148 #ifdef UG_PARALLEL
149  if(pcl::NumProcs() > 1)
150  {
151  UG_LOG(" +++ Marked for refinement on Proc "<<pcl::ProcRank()<<": " << numMarkedRefine << " Elements.\n");
153  int numMarkedRefineLocal = numMarkedRefine;
154  numMarkedRefine = com.allreduce(numMarkedRefineLocal, PCL_RO_SUM);
155  }
156 #endif
157 
158 UG_LOG(" +++ Marked for refinement: " << numMarkedRefine << " Elements.\n");
159 
160 }
161 
162 
163 
164 } //end of namespace SmallStrainMechanics
165 } //end of namespace ug
166 
167 #endif /* ADAPTIVE_UTIL_IMPL_H_ */
size_t allreduce(const size_t &t, pcl::ReduceOperation op) const
void update(GridObject *pElem, const MathVector< worldDim > *vCorner)
size_t num_ip() const
SmartPtr< TDomain > domain()
void indices(TElem *elem, LocalIndices &ind, bool bHang=false) const
SmartPtr< DoFDistribution > dof_distribution()
void mark(const TIterator &iterBegin, const TIterator &iterEnd, RefinementMark refMark=RM_REFINE)
void resize(const LocalIndices &ind)
SmartPtr< IMaterialLaw< TDomain > > get_material_law()
gets the material law
Definition: small_strain_mech.h:135
int get_quad_order()
gets the quad order
Definition: small_strain_mech.h:184
Grid::VertexAttachmentAccessor< position_attachment_type > position_accessor_type
int element_type() const
static const int dim
RM_REFINE
#define PCL_RO_SUM
int ProcRank()
int NumProcs()
#define UG_CATCH_THROW(msg)
#define UG_THROW(msg)
#define UG_LOG(msg)
double number
void MarkForAdaption_PlasticElem(IRefiner &refiner, GridFunction< TDomain, TAlgebra > &u, SmallStrainMechanicsElemDisc< TDomain > &elemDisc)
Definition: adaptive_util_impl.h:99
void plastic_ip_elem(bool &bPlasticIPs, TElem *elem, const LocalVector &locU, SmartPtr< TDomain > dom, SmallStrainMechanicsElemDisc< TDomain > &elemDisc)
Definition: adaptive_util_impl.h:43
void GetLocalVector(LocalVector &lvec, const TVector &vec)
SurfaceView::traits< TElem >::const_iterator const_iterator