Memosa-FVM  0.2
PhononInterface.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 _PHONONINTERFACE_H_
6 #define _PHONONINTERFACE_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 Mesh& otherMesh,
49  const GeomFields& geomFields,
50  const Xkspace& kspace,
51  const Xkspace& kspaceOther,
52  PhononModelOptions<X>& opts):
53 
54  _fg(fg),
55  _faces(fg.site),
56  _cells(mesh.getCells()),
57  _otherCells(otherMesh.getCells()),
58  _ibType(dynamic_cast<const IntArray&>(geomFields.ibType[_cells])),
59  _faceCells(mesh.getFaceCells(_faces)),
60  _areaMagField(geomFields.areaMag),
61  _faceAreaMag(dynamic_cast<const TArray&>(_areaMagField[_faces])),
62  _areaField(geomFields.area),
63  _faceArea(dynamic_cast<const VectorT3Array&>(_areaField[_faces])),
64  _options(opts),
65  _kspace(kspace),
66  _kspaceOther(kspaceOther),
67  _fg_id(fg.id),
68  _otherfg(otherMesh.getFaceGroup(fg.id)),
69  _otherFaces(_otherfg.site),
70  _otherFaceCells(otherMesh.getFaceCells(_otherFaces)),
71  _faceAreaMagOther(dynamic_cast<const TArray&>(_areaMagField[_otherFaces])),
72  _faceAreaOther(dynamic_cast<const VectorT3Array&>(_areaField[_otherFaces]))
73 
74  {}
75 
77 
78 
79  void applyInterfaceCondition(int f,const X refl, const X trans) const
80  {
81 
82  int c0 = _faceCells(f,0);
83  int c1 = _faceCells(f,1);
85  if (c1 < _cells.getSelfCount())
86  {
87  // c0 is ghost cell and c1 is boundry cell, so swap cell numbers
88  // so that c1p refers to the ghost cell in the following
89  int temp = c0;
90  c0 = c1;
91  c1 = temp;
92  sign *= -1.0;
93  }
94 
95 
96  X tot_in = 0.; //total incoming energy (to wall)
97  X tot_dk3 = 0.; //total weight of incoming energy
98 
99  if (_ibType[c0] != Mesh::IBTYPE_FLUID)
100  return;
101 
102  // current mesh
103  // sum up energy incoming to boundary (from domain)
104  int numK=_kspace.getlength();
105  for (int k=0;k<numK;k++)
106  {
107 
108  Xkvol& kv=_kspace.getkvol(k);
109  X dk3=kv.getdk3();
110  int numM=kv.getmodenum();
111 
112  for (int m=0;m<numM;m++) //mode loop beg
113  {
114 
115  Xmode& mode=kv.getmode(m);
116  Field& efield=mode.getfield();
117  VectorT3 vg = mode.getv(); // phonon group velocity
118  XArray& e_val = dynamic_cast< XArray&>(efield[_cells]); // e"
119  const VectorT3 en = sign*(_faceArea[f]/_faceAreaMag[f]); //outward normal unit vector to face
120  const VectorT3 sn = vg/sqrt(pow(vg[0],2)+pow(vg[1],2)+pow(vg[2],2));
121  const X sn_dot_en = sn[0]*en[0]+sn[1]*en[1]+sn[2]*en[2];
122  const X vg_dot_en = vg[0]*en[0]+vg[1]*en[1]+vg[2]*en[2];
123 
124  if (sn_dot_en > T_Scalar(0.0))
125  {
126  tot_in+=e_val[c0]*dk3*vg_dot_en;
127  tot_dk3+=vg_dot_en*dk3;
128  }
129  else
130  {
131  e_val[c1]=0.;
132  }
133 
134  } //mode loop end
135  }
136 
137  const X diff_refl = tot_in/tot_dk3; // value for e" leaving the wall
138 
139 
140  // other mesh
141  int c0other = _otherFaceCells(f,0);
142  int c1other = _otherFaceCells(f,1);
144  if (c1other < _otherCells.getSelfCount())
145  {
146  // c0 is ghost cell and c1 is boundry cell, so swap cell numbers
147  // so that c1p refers to the ghost cell in the following
148  int temp = c0other;
149  c0other = c1other;
150  c1other = temp;
151  sign2 *= -1.0;
152  }
153 
154 
155  X tot_in_other = 0.; //total incoming energy (to wall)
156  X tot_dk3_other = 0.; //total weight of incoming energy
157 
158 
159  // sum up energy incoming to boundary (from domain)
160  int numKOther=_kspaceOther.getlength();
161  for (int k=0;k<numKOther;k++)
162  {
163 
164  Xkvol& kv=_kspaceOther.getkvol(k);
165  X dk3=kv.getdk3();
166  int numM=kv.getmodenum();
167 
168  for (int m=0;m<numM;m++) //mode loop beg
169  {
170 
171  Xmode& mode=kv.getmode(m);
172  Field& efield=mode.getfield();
173  VectorT3 vg = mode.getv(); // phonon group velocity
174  XArray& e_val = dynamic_cast< XArray&>(efield[_otherCells]); // e"
175  const VectorT3 en = sign2*(_faceAreaOther[f]/_faceAreaMagOther[f]); //outward normal unit vector to face
176  const VectorT3 sn = vg/sqrt(pow(vg[0],2)+pow(vg[1],2)+pow(vg[2],2));
177  const X sn_dot_en = sn[0]*en[0]+sn[1]*en[1]+sn[2]*en[2];
178  const X vg_dot_en = vg[0]*en[0]+vg[1]*en[1]+vg[2]*en[2];
179 
180  if (sn_dot_en > T_Scalar(0.0))
181  {
182  tot_in_other+=e_val[c0other]*dk3*vg_dot_en;
183  tot_dk3_other+=vg_dot_en*dk3;
184  }
185  else
186  {
187  //e_val[c1]=0.;
188  }
189 
190  } //mode loop end
191  }
192 
193  const X diff_trans = tot_in_other/tot_dk3; // value for e" leaving the wall
194 
195 
196  // assign values for incoming (upwinded) and outgoing (reflected) to/from wall
197  for (int k=0;k<numK;k++)
198  {
199 
200  Xkvol& kv=_kspace.getkvol(k);
201  int numM=kv.getmodenum();
202 
203  for (int m=0;m<numM;m++) //mode loop beg
204  {
205 
206  Xmode& mode=kv.getmode(m);
207  Field& efield=mode.getfield();
208  VectorT3 vg = mode.getv(); // phonon group velocity
209  XArray& e_val = dynamic_cast<XArray&>(efield[_cells]); // e"
210  const VectorT3 en = sign*(_faceArea[f]/_faceAreaMag[f]); //normal unit vector to face
211  const X vg_dot_en = vg[0]*en[0]+vg[1]*en[1]+vg[2]*en[2];
212 
213  if (vg_dot_en > T_Scalar(0.0))
214  {
215 
216  /*Refl_pair& rpairs=mode.getReflpair(_fg_id);
217  X w1=rpairs.first.first;
218  X w2=rpairs.second.first;
219  int k1=rpairs.first.second;
220  int k2=rpairs.second.second;
221  Xmode& mode1=_kspace.getkvol(k1).getmode(m);
222  Xmode& mode2=_kspace.getkvol(k2).getmode(m);
223  Field& field1=mode1.getfield();
224  Field& field2=mode2.getfield();
225  XArray& e_val1=dynamic_cast<XArray&>(field1[_cells]);
226  XArray& e_val2=dynamic_cast<XArray&>(field2[_cells]);
227  e_val1[c1]+=refl*w1*e_val[c0];
228  e_val2[c1]+=refl*w2*e_val[c0];*/
229  e_val[c1]=e_val[c0]; // upwinded value
230  }
231  else
232  {
233  e_val[c1]+=refl*diff_refl; // diffusely reflected value
234  e_val[c1]+=trans*diff_trans; // diffusely transmitted value
235  }
236  } //mode loop end
237  }
238  }
239 
240  void applyInterfaceCondition(T_Scalar bRefl, T_Scalar bTrans) const
241  {
242  for (int i=0; i<_faces.getCount();i++)
243  applyInterfaceCondition(i,bRefl,bTrans);
244  }
245 
246 
247  protected:
248 
249  const FaceGroup& _fg;
260  const Xkspace& _kspace;
262  const int _fg_id;
268 
269 };
270 
271 #endif
pair< Reflection, Reflection > Refl_pair
Definition: pmode.h:29
Vector< X, 3 > VectorX3
int getSelfCount() const
Definition: StorageSite.h:40
PhononModelOptions< X > & _options
Tvec getv()
Definition: pmode.h:59
Definition: Kspace.h:28
const StorageSite & _faces
const Xkspace & _kspace
Definition: Mesh.h:28
Array< VectorT3 > VectorT3Array
Definition: Field.h:14
Tkvol & getkvol(int n) const
Definition: Kspace.h:390
Tmode & getmode(int n) const
Definition: kvol.h:44
int getlength() const
Definition: Kspace.h:391
const StorageSite & _otherFaces
PhononModelOptions< X > & getOptions()
Definition: Mesh.h:49
int getmodenum()
Definition: kvol.h:43
const Xkspace & _kspaceOther
Vector< T_Scalar, 3 > VectorT3
pmode< X > Xmode
const VectorT3Array & _faceAreaOther
const TArray & _faceAreaMagOther
const StorageSite & _cells
const Field & _areaMagField
const CRConnectivity & _otherFaceCells
Tangent sqrt(const Tangent &a)
Definition: Tangent.h:317
Array< X > XArray
Array< VectorX3 > VectorX3Array
Xmode::Refl_pair Refl_pair
NumTypeTraits< X >::T_Scalar T_Scalar
const Field & _areaField
Array< T_Scalar > TArray
const CRConnectivity & _faceCells
const TArray & _faceAreaMag
Field & getfield()
Definition: pmode.h:74
PhononInterface(const FaceGroup &fg, const Mesh &mesh, const Mesh &otherMesh, const GeomFields &geomFields, const Xkspace &kspace, const Xkspace &kspaceOther, PhononModelOptions< X > &opts)
Array< int > IntArray
int getCount() const
Definition: StorageSite.h:39
void applyInterfaceCondition(T_Scalar bRefl, T_Scalar bTrans) const
void applyInterfaceCondition(int f, const X refl, const X trans) const
Definition: pmode.h:18
const VectorT3Array & _faceArea
Definition: kvol.h:14
Kspace< X > Xkspace
const FaceGroup & _fg
const Array< int > & _ibType
T getdk3()
Definition: kvol.h:42
const FaceGroup & _otherfg
const StorageSite & _otherCells