Plugins
diffusion_length.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2013: G-CSC, Goethe University Frankfurt
3  * Author: Josef Dubsky, Andreas Vogel, 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 
34 #ifndef __H__UG__PLUGINS__NAVIER_STOKES__INCOMPRESSIBLE__FV1__DIFFUSION_LENGTH__
35 #define __H__UG__PLUGINS__NAVIER_STOKES__INCOMPRESSIBLE__FV1__DIFFUSION_LENGTH__
36 
37 // other ug4 modules
38 #include "common/common.h"
39 
40 namespace ug{
41 namespace NavierStokes{
42 
48 template <typename TFVGeometry>
49 void NSDiffLengthFivePoint(number DiffLengthSqInv[], const TFVGeometry& geo)
50 {
51  // dimension of element
52  static const size_t dim = TFVGeometry::dim;
53 
54  // Check the SCVF - number of IPs (order of elements)
55  UG_ASSERT(geo.scvf(0).num_ip() == 1, "Only implemented for first order.");
56 
57  for(size_t i = 0; i < geo.num_scvf(); ++i)
58  {
59  // get SubControlVolumeFace
60  const typename TFVGeometry::SCVF& scvf = geo.scvf(i);
61 
62  // get associated SubControlVolumes
63  const typename TFVGeometry::SCV& scvFrom = geo.scv(scvf.from());
64  const typename TFVGeometry::SCV& scvTo = geo.scv(scvf.to());
65 
66  // Norm of Normal to SCVF squared
67  const number normNormalSq = VecTwoNormSq(scvf.normal());
68 
69  // average squared size of associated SCV
70  number areaSCVSq = 0.5 * (scvFrom.volume() + scvTo.volume());
71  areaSCVSq *= areaSCVSq;
72 
73  if(dim == 2)
74  {
75  DiffLengthSqInv[i] = 2.0 * normNormalSq/ areaSCVSq + 8.0 / normNormalSq;
76  }
77  else if (dim == 3)
78  {
79  // Distance between edge midpoint and center of element, that are part
80  // of the SCVF
81  const number distSq = VecDistanceSq(scvf.global_corner(0),
82  scvf.global_corner(2));
83 
84  DiffLengthSqInv[i] = 2.0 * normNormalSq/ areaSCVSq + 8.0 * distSq / normNormalSq;
85  }
86  else
87  UG_THROW("NSDiffLengthFivePoint not implemented for dimension "<<dim);
88  }
89 }
90 
91 template <typename TFVGeometry>
92 void NSDiffLengthRaw(number DiffLengthSqInv[], const TFVGeometry& geo)
93 {
94  // dimension of element
95  static const size_t dim = TFVGeometry::dim;
96 
97  // Check the SCVF - number of IPs (order of elements)
98  UG_ASSERT(geo.scvf(0).num_ip() == 1, "Only implemented for first order.");
99 
100 
101  for(size_t i = 0; i < geo.num_scvf(); ++i)
102  {
103  // get SubControlVolumeFace
104  const typename TFVGeometry::SCVF& scvf = geo.scvf(i);
105 
106  // get associated SubControlVolumes
107  const typename TFVGeometry::SCV& scvFrom = geo.scv(scvf.from());
108  const typename TFVGeometry::SCV& scvTo = geo.scv(scvf.to());
109 
110  // Norm of Normal to SCVF squared
111  const number normNormalSq = VecTwoNormSq(scvf.normal());
112 
113  // average squared size of associated SCV
114  number areaSCVSq = 0.5 * (scvFrom.volume() + scvTo.volume());
115  areaSCVSq *= areaSCVSq;
116 
117  if(dim == 2)
118  {
119  DiffLengthSqInv[i] = 1. / (0.5*areaSCVSq/normNormalSq + 3.0*normNormalSq/8.);
120  }
121  else if (dim == 3)
122  {
123  // Distance between edge midpoint and center of element, that are part
124  // of the SCVF
125  const number distSq = VecDistanceSq(scvf.global_corner(0),
126  scvf.global_corner(2));
127 
128  DiffLengthSqInv[i] = 1. / (0.5*areaSCVSq/normNormalSq + 3.0*distSq/8.);
129  }
130  else
131  UG_THROW("NSDiffLengthRaw not implemented for dimension "<<dim);
132  }
133 }
134 
135 template <typename TFVGeometry>
136 void NSDiffLengthCor(number DiffLengthSqInv[], const TFVGeometry& geo)
137 {
138  // dimension of element
139  static const size_t dim = TFVGeometry::dim;
140 
141  // Check the SCVF - number of IPs (order of elements)
142  UG_ASSERT(geo.scvf(0).num_ip() == 1, "Only implemented for first order.");
143 
144  // compute min, max and avg of ||n||^2
145  number minNormSq = std::numeric_limits<number>::max();
146  number minDistSq = std::numeric_limits<number>::max();
147  number avgNormSq = 0.0;
148  for(size_t i = 0; i < geo.num_scvf(); ++i)
149  {
150  // get SubControlVolumeFace
151  const typename TFVGeometry::SCVF& scvf = geo.scvf(i);
152 
153  // Norm of Normal to SCVF squared
154  const number normNormalSq = VecTwoNormSq(scvf.normal());
155 
156  // get min
157  if(normNormalSq < minNormSq) minNormSq = normNormalSq;
158 
159  // sum for average
160  avgNormSq += normNormalSq;
161 
162  // Distance between edge midpoint and center of element, that are part
163  // of the SCVF
164  if(dim == 3)
165  {
166  const number distSq = VecDistanceSq(scvf.global_corner(0),
167  scvf.global_corner(2));
168 
169  // get min
170  if(distSq < minDistSq) minDistSq = distSq;
171  }
172  }
173 
174  // devide by num scvf
175  avgNormSq /= geo.num_scvf();
176 
177  for(size_t i = 0; i < geo.num_scvf(); ++i)
178  {
179  // get associated SubControlVolumes
180  const typename TFVGeometry::SCVF& scvf = geo.scvf(i);
181  const typename TFVGeometry::SCV& scvFrom = geo.scv(scvf.from());
182  const typename TFVGeometry::SCV& scvTo = geo.scv(scvf.to());
183 
184  // average squared size of associated SCV
185  number areaSCVSq = 0.5 * (scvFrom.volume() + scvTo.volume());
186  areaSCVSq *= areaSCVSq;
187 
188  if(dim == 2)
189  {
190  DiffLengthSqInv[i] = 2.0 * minNormSq/ areaSCVSq + 8.0 / (3.0*avgNormSq);
191  }
192  else if (dim == 3)
193  {
194  DiffLengthSqInv[i] = 2.0 * minNormSq/ areaSCVSq + 8.0 * minDistSq / (3.0*avgNormSq);
195  }
196  else
197  UG_THROW("NSDiffLengthCor not implemented for dimension "<<dim);
198  }
199 }
200 
201 } // namespace NavierStokes
202 } // end namespace ug
203 
204 #endif /* __H__UG__PLUGINS__NAVIER_STOKES__INCOMPRESSIBLE__FV1__DIFFUSION_LENGTH__ */
function NavierStokes(fcts, subsets, discType)
static const int dim
#define UG_ASSERT(expr, msg)
#define UG_THROW(msg)
double number
vector_t::value_type VecTwoNormSq(const vector_t &v)
void NSDiffLengthRaw(number DiffLengthSqInv[], const TFVGeometry &geo)
Definition: diffusion_length.h:92
void NSDiffLengthCor(number DiffLengthSqInv[], const TFVGeometry &geo)
Definition: diffusion_length.h:136
void NSDiffLengthFivePoint(number DiffLengthSqInv[], const TFVGeometry &geo)
Definition: diffusion_length.h:49
TVector::value_type VecDistanceSq(const TVector &v1, const TVector &v2, const TMatrix &M)