Memosa-FVM  0.2
PhononBoundary.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifndef _PHONONBOUNDARY_H_
6 #define _PHONONBOUNDARY_H_
7 
8 #include "Mesh.h"
9 #include <math.h>
10 #include "NumType.h"
11 #include "Array.h"
12 #include "Vector.h"
13 #include "Field.h"
14 #include "StorageSite.h"
15 #include "CRConnectivity.h"
16 #include "MultiFieldMatrix.h"
17 #include "CRMatrix.h"
18 #include "FluxJacobianMatrix.h"
19 #include "DiagonalMatrix.h"
20 #include "GeomFields.h"
21 #include "pmode.h"
22 #include "Kspace.h"
23 #include "kvol.h"
24 
25 template<class X>
27 {
28  public :
29 
31 
33 
37 
38  typedef Array<X> XArray;
39  typedef Vector<X,3> VectorX3; //also needed for phonons
41  typedef Kspace<X> Xkspace;
42  typedef kvol<X> Xkvol;
43  typedef pmode<X> Xmode;
44  typedef typename Xmode::Refl_pair Refl_pair;
45 
47  const Mesh& mesh,
48  const GeomFields& geomFields,
49  const Xkspace& kspace,
51  const int fg_id):
52 
53  _faces(faces),
54  _cells(mesh.getCells()),
55  _ibType(dynamic_cast<const IntArray&>(geomFields.ibType[_cells])),
56  _faceCells(mesh.getFaceCells(_faces)),
57  _areaMagField(geomFields.areaMag),
58  _faceAreaMag(dynamic_cast<const TArray&>(_areaMagField[_faces])),
59  _areaField(geomFields.area),
60  _faceArea(dynamic_cast<const VectorT3Array&>(_areaField[_faces])),
61  _options(opts),
62  _kspace(kspace),
63  _fg_id(fg_id)
64  {}
65 
67 
68  void applyReflectingWall(int f,const X refl) const
69  {
70 
71  const int c0 = _faceCells(f,0);
72  const int c1 = _faceCells(f,1);
73  X tot_in = 0.; //total incoming energy (to wall)
74  X tot_dk3 = 0.; //total weight of incoming energy
75 
76  if (_ibType[c0] != Mesh::IBTYPE_FLUID)
77  return;
78 
79  // sum up energy incoming to boundary (from domain)
80  int numK=_kspace.getlength();
81  for (int k=0;k<numK;k++)
82  {
83 
84  Xkvol& kv=_kspace.getkvol(k);
85  X dk3=kv.getdk3();
86  int numM=kv.getmodenum();
87 
88  for (int m=0;m<numM;m++) //mode loop beg
89  {
90 
91  Xmode& mode=kv.getmode(m);
92  Field& efield=mode.getfield();
93  VectorT3 vg = mode.getv(); // phonon group velocity
94  XArray& e_val = dynamic_cast< XArray&>(efield[_cells]); // e"
95  const VectorT3 en = _faceArea[f]/_faceAreaMag[f]; //normal unit vector to face
96  const VectorT3 sn = vg/sqrt(pow(vg[0],2)+pow(vg[1],2)+pow(vg[2],2));
97  const X sn_dot_en = sn[0]*en[0]+sn[1]*en[1]+sn[2]*en[2];
98  const X vg_dot_en = vg[0]*en[0]+vg[1]*en[1]+vg[2]*en[2];
99 
100  if (sn_dot_en > T_Scalar(0.0))
101  {
102  tot_in+=e_val[c0]*dk3*vg_dot_en;
103  tot_dk3+=vg_dot_en*dk3;
104  }
105  else
106  {
107  e_val[c1]=0.;
108  }
109 
110  } //mode loop end
111  }
112 
113  const X diff_refl = tot_in/tot_dk3; // value for e" leaving the wall
114 
115  // assign values for incoming (upwinded) and outgoing (reflected) to/from wall
116  for (int k=0;k<numK;k++)
117  {
118 
119  Xkvol& kv=_kspace.getkvol(k);
120  int numM=kv.getmodenum();
121 
122  for (int m=0;m<numM;m++) //mode loop beg
123  {
124 
125  Xmode& mode=kv.getmode(m);
126  Field& efield=mode.getfield();
127  VectorT3 vg = mode.getv(); // phonon group velocity
128  XArray& e_val = dynamic_cast<XArray&>(efield[_cells]); // e"
129  const VectorT3 en = _faceArea[f]/_faceAreaMag[f]; //normal unit vector to face
130  const X vg_dot_en = vg[0]*en[0]+vg[1]*en[1]+vg[2]*en[2];
131 
132  if (vg_dot_en > T_Scalar(0.0))
133  {
134 
135  Refl_pair& rpairs=mode.getReflpair(_fg_id);
136  //X w1=rpairs.first.first;
137  //X w2=rpairs.second.first;
138  int k1=rpairs.first.second;
139  //int k2=rpairs.second.second;
140  Xmode& mode1=_kspace.getkvol(k1).getmode(m);
141  //Xmode& mode2=_kspace.getkvol(k2).getmode(m);
142  Field& field1=mode1.getfield();
143  //Field& field2=mode2.getfield();
144  XArray& e_val1=dynamic_cast<XArray&>(field1[_cells]);
145  //XArray& e_val2=dynamic_cast<XArray&>(field2[_cells]);
146  e_val1[c1]+=refl*e_val[c0];
147  //e_val2[c1]+=refl*w2*e_val[c0];
148  e_val[c1]=e_val[c0]; // upwinded value
149  }
150  else
151  {
152  e_val[c1]+=(1-refl)*diff_refl; // diffusely reflected value
153  }
154  } //mode loop end
155  }
156  }
157 
159  {
160  for (int i=0; i<_faces.getCount();i++)
161  applyReflectingWall(i,bRefl[i]);
162  }
163 
164 
165  void applyTemperatureWall(int f,const X Twall) const
166  {
167 
168  const int c0 = _faceCells(f,0);
169  const int c1 = _faceCells(f,1);
170 
171  if (_ibType[c0] != Mesh::IBTYPE_FLUID)
172  return;
173 
174  // sum up energy incoming to boundary (from domain)
175  int numK=_kspace.getlength();
176 
177  for (int k=0;k<numK;k++)
178  {
179  Xkvol& kv=_kspace.getkvol(k);
180  int numM=kv.getmodenum();
181 
182  for (int m=0;m<numM;m++) //mode loop beg
183  {
184  Xmode& mode=kv.getmode(m);
185  Field& efield=mode.getfield();
186  VectorX3 vg = mode.getv();
187  XArray& e_val = dynamic_cast< XArray&>(efield[_cells]); // e"
188  const VectorX3 en = _faceArea[f]/_faceAreaMag[f]; //normal unit vector to face
189  const X vg_dot_en = vg[0]*en[0]+vg[1]*en[1]+vg[2]*en[2];
190 
191  if (vg_dot_en > T_Scalar(0.0))
192  {
193  e_val[c1]=e_val[c0];
194  }
195  else
196  {
197  e_val[c1]=mode.calce0(Twall);
198  }
199 
200  } //mode loop end
201  }
202  }
203 
205  {
206  for (int j=0; j<_faces.getCount();j++)
207  {
208  applyTemperatureWall(j,bTemp[j]);
209  }
210  }
211 
212 
213  /*
214 
215 
216  void applyInterfaceCondition(int f,const X refl, const X trans) const
217  {
218 
219  const int c0 = _faceCells(f,0);
220  const int c1 = _faceCells(f,1);
221  T_Scalar sign(NumTypeTraits<T_Scalar>::getUnity());
222  if (c1 < _cells.getSelfCount())
223  {
224  // c0 is ghost cell and c1 is boundry cell, so swap cell numbers
225  // so that c1p refers to the ghost cell in the following
226  int temp = c0;
227  c0 = c1;
228  c1 = temp;
229  sign *= -1.0;
230  }
231 
232 
233  X tot_in = 0.; //total incoming energy (to wall)
234  X tot_dk3 = 0.; //total weight of incoming energy
235 
236  if (_ibType[c0] != Mesh::IBTYPE_FLUID)
237  return;
238 
239  // sum up energy incoming to boundary (from domain)
240  int numK=_kspace.getlength();
241  for (int k=0;k<numK;k++)
242  {
243 
244  Xkvol& kv=_kspace.getkvol(k);
245  X dk3=kv.getdk3();
246  int numM=kv.getmodenum();
247 
248  for (int m=0;m<numM;m++) //mode loop beg
249  {
250 
251  Xmode& mode=kv.getmode(m);
252  Field& efield=mode.getfield();
253  VectorT3 vg = mode.getv(); // phonon group velocity
254  XArray& e_val = dynamic_cast< XArray&>(efield[_cells]); // e"
255  const VectorT3 en = sign*(_faceArea[f]/_faceAreaMag[f]); //outward normal unit vector to face
256  const VectorT3 sn = vg/sqrt(pow(vg[0],2)+pow(vg[1],2)+pow(vg[2],2));
257  const X sn_dot_en = sn[0]*en[0]+sn[1]*en[1]+sn[2]*en[2];
258  const X vg_dot_en = vg[0]*en[0]+vg[1]*en[1]+vg[2]*en[2];
259 
260  if (sn_dot_en > T_Scalar(0.0))
261  {
262  tot_in+=e_val[c0]*dk3*vg_dot_en;
263  tot_dk3+=vg_dot_en*dk3;
264  }
265  else
266  {
267  //e_val[c1]=0.;
268  }
269 
270  } //mode loop end
271  }
272 
273  const X diff_refl = tot_in/tot_dk3; // value for e" leaving the wall
274 
275  // assign values for incoming (upwinded) and outgoing (reflected) to/from wall
276  for (int k=0;k<numK;k++)
277  {
278 
279  Xkvol& kv=_kspace.getkvol(k);
280  int numM=kv.getmodenum();
281 
282  for (int m=0;m<numM;m++) //mode loop beg
283  {
284 
285  Xmode& mode=kv.getmode(m);
286  Field& efield=mode.getfield();
287  VectorT3 vg = mode.getv(); // phonon group velocity
288  XArray& e_val = dynamic_cast<XArray&>(efield[_cells]); // e"
289  const VectorT3 en = sign*(_faceArea[f]/_faceAreaMag[f]); //normal unit vector to face
290  const X vg_dot_en = vg[0]*en[0]+vg[1]*en[1]+vg[2]*en[2];
291 
292  if (vg_dot_en > T_Scalar(0.0))
293  {
294 
295  Refl_pair& rpairs=mode.getReflpair(_fg_id);
296  X w1=rpairs.first.first;
297  X w2=rpairs.second.first;
298  int k1=rpairs.first.second;
299  int k2=rpairs.second.second;
300  Xmode& mode1=_kspace.getkvol(k1).getmode(m);
301  Xmode& mode2=_kspace.getkvol(k2).getmode(m);
302  Field& field1=mode1.getfield();
303  Field& field2=mode2.getfield();
304  XArray& e_val1=dynamic_cast<XArray&>(field1[_cells]);
305  XArray& e_val2=dynamic_cast<XArray&>(field2[_cells]);
306  e_val1[c1]+=refl*w1*e_val[c0];
307  e_val2[c1]+=refl*w2*e_val[c0];
308  e_val[c1]=e_val[c0]; // upwinded value
309  }
310  else
311  {
312  e_val[c1]=refl*diff_refl; // diffusely reflected value
313  }
314  } //mode loop end
315  }
316  }
317 
318  void applyInterfaceCondition(FloatValEvaluator<X>& bRefl, FloatValEvaluator<X>& bTrans) const
319  {
320  for (int i=0; i<_faces.getCount();i++)
321  applyInterfaceCondition(i,bRefl[i],bTrans[i]);
322  }
323 */
324  /*
325 
326  void applyZeroGradientBC(int f) const
327  {
328  const int c0 = _faceCells(f,0);
329  const int c1 = _faceCells(f,1);
330 
331  if (_ibType[c0] != Mesh::IBTYPE_FLUID)
332  return;
333 
334  const int numDirections = _quadrature.getDirCount();
335 
336  for (int j=0; j<numDirections; j++)
337  {
338  Field& fnd = *_dsfPtr.dsf[j];
339  XArray& dsf = dynamic_cast< XArray&>(fnd[_cells]);
340  dsf[c1]=dsf[c0];
341  }
342  }
343  void applyZeroGradientBC() const
344  {
345  for (int i=0; i<_faces.getCount();i++)
346  applyZeroGradientBC(i);
347  }
348  */
349 
350 
351  protected:
352 
362  const Xkspace& _kspace;
363  const int _fg_id;
364 };
365 
366 #endif
pair< Reflection, Reflection > Refl_pair
Definition: pmode.h:29
Refl_pair & getReflpair(int i)
Definition: pmode.h:71
const Field & _areaMagField
Array< int > IntArray
Array< T_Scalar > TArray
Tvec getv()
Definition: pmode.h:59
Definition: Kspace.h:28
Array< X > XArray
T calce0(T Tl)
Definition: pmode.h:88
Definition: Field.h:14
Tkvol & getkvol(int n) const
Definition: Kspace.h:390
void applyReflectingWall(int f, const X refl) const
Tmode & getmode(int n) const
Definition: kvol.h:44
int getlength() const
Definition: Kspace.h:391
void applyReflectingWall(FloatValEvaluator< X > &bRefl) const
Definition: Mesh.h:49
int getmodenum()
Definition: kvol.h:43
Tangent sqrt(const Tangent &a)
Definition: Tangent.h:317
const Xkspace & _kspace
PhononModelOptions< X > & _options
Kspace< X > Xkspace
void applyTemperatureWall(FloatValEvaluator< X > &bTemp) const
PhononBoundary(const StorageSite &faces, const Mesh &mesh, const GeomFields &geomFields, const Xkspace &kspace, PhononModelOptions< X > &opts, const int fg_id)
const StorageSite & _faces
const CRConnectivity & _faceCells
Array< VectorT3 > VectorT3Array
const VectorT3Array & _faceArea
Vector< T_Scalar, 3 > VectorT3
Field & getfield()
Definition: pmode.h:74
const int _fg_id
const Array< int > & _ibType
pmode< X > Xmode
Array< VectorX3 > VectorX3Array
const TArray & _faceAreaMag
int getCount() const
Definition: StorageSite.h:39
Xmode::Refl_pair Refl_pair
const StorageSite & _cells
const Field & _areaField
NumTypeTraits< X >::T_Scalar T_Scalar
PhononModelOptions< X > & getOptions()
Vector< X, 3 > VectorX3
Definition: pmode.h:18
void applyTemperatureWall(int f, const X Twall) const
Definition: kvol.h:14
kvol< X > Xkvol
T getdk3()
Definition: kvol.h:42