5 #ifndef _COMETDISCRETIZER_H_
6 #define _COMETDISCRETIZER_H_
101 TArray Bvec(totalmodes+1);
102 TArray Resid(totalmodes+1);
103 TArrow AMat(totalmodes+1);
110 for(
int c=start;((c<cellcount)&&(c>-1));c+=dir)
118 while((dt>newTol && NewtonIters<maxNew) || NewtonIters<minNew)
142 dt=
fabs(Bvec[totalmodes]);
149 while((dt>newTol && NewtonIters<maxNew) || NewtonIters<minNew)
169 dt=
fabs(Bvec[totalmodes]);
179 while((dt>newTol && NewtonIters<maxNew) || NewtonIters<minNew)
200 dt=
fabs(Bvec[totalmodes]);
213 while((dt>newTol && NewtonIters<maxNew) || NewtonIters<minNew)
234 dt=
fabs(Bvec[totalmodes]);
238 throw CException(
"Unexpected value for boundary cell map.");
254 TArray Bvec(totalmodes+1);
255 TArray Resid(totalmodes+1);
256 TArrow AMat(totalmodes+1);
262 for(
int c=start;((c<cellcount)&&(c>-1));c+=dir)
271 while((dt>newTol && NewtonIters<maxNew) || NewtonIters<minNew)
298 dt=0.5*
fabs(Bvec[totalmodes]/Tl[c])+rscaled*0.5;
306 while((dt>newTol && NewtonIters<maxNew) || NewtonIters<minNew)
326 dt=
fabs(Bvec[totalmodes]);
336 while((dt>newTol && NewtonIters<maxNew) || NewtonIters<minNew)
359 dt=0.5*
fabs(Bvec[totalmodes]/Tl[c])+0.5*rscaled;
372 while((dt>newTol && NewtonIters<maxNew) || NewtonIters<minNew)
393 dt=
fabs(Bvec[totalmodes]);
397 throw CException(
"Unexpected value for boundary cell map.");
413 TArray Bvec(totalmodes+1);
414 TArray Resid(totalmodes+1);
417 TArrow AMat(totalmodes+1);
422 for(
int c=start;((c<cellcount)&&(c>-1));c+=dir)
430 for(
int srcIts=0;srcIts<1;srcIts++)
436 while((dt>newTol && NewtonIters<maxNew) || NewtonIters<minNew)
462 dt=
fabs(Bvec[totalmodes]);
473 while((dt>newTol && NewtonIters<maxNew) || NewtonIters<minNew)
493 dt=
fabs(Bvec[totalmodes]);
502 for(
int srcIts=0;srcIts<1;srcIts++)
507 while((dt>newTol && NewtonIters<maxNew) || NewtonIters<minNew)
531 dt=
fabs(Bvec[totalmodes]);
548 while((dt>newTol && NewtonIters<maxNew) || NewtonIters<minNew)
569 dt=
fabs(Bvec[totalmodes]);
573 throw CException(
"Unexpected value for boundary cell map.");
604 for(
int j=0;j<neibcount;j++)
619 T& curMax=pointMax[k];
620 T& curMin=pointMin[k];
621 Grads[k].accumulate(Gcoeff, e1-e0);
639 for(
int j=0;j<neibcount;j++)
652 const T minVal=pointMin[k];
653 const T maxVal=pointMax[k];
654 const T de0(Grads[k]*dr0);
661 for(
int j=0;j<neibcount;j++)
684 for(
int nj=0;nj<neibcount1;nj++)
700 T& curMax=neibMax[k];
701 T& curMin=neibMin[k];
702 NeibGrads[k].accumulate(Gcoeff,e11-e1);
721 for(
int nj=0;nj<neibcount1;nj++)
734 const T minVal=neibMin[k];
735 const T maxVal=neibMax[k];
736 const T de1(NeibGrads[k]*dr1);
748 for(
int k=0;k<klen;k++)
752 for(
int m=0;m<numModes;m++)
758 flux=vg[0]*Af[0]+vg[1]*Af[1]+vg[2]*Af[2];
763 const GradType& grad=Grads[count-1];
764 const GradType& neibGrad=NeibGrads[count-1];
770 const VectorT3 fVec=faceCoords[f]-_cellCoords[cell0];
773 T SOU=(fVec[0]*grad[0]+fVec[1]*grad[1]+
774 fVec[2]*grad[2])*pointLim[count-1];
776 BVec[count-1]-=flux*
_eArray[c0ind]-flux*SOU;
781 const VectorT3 fVec=faceCoords[f]-_cellCoords[cell1];
784 T SOU=(fVec[0]*neibGrad[0]+fVec[1]*neibGrad[1]+
785 fVec[2]*neibGrad[2])*neibLim[count-1];
786 BVec[count-1]-=flux*
_eArray[c1ind]-flux*SOU;
796 for(
int k=0;k<klen;k++)
801 for(
int m=0;m<numModes;m++)
806 flux=vg[0]*Af[0]+vg[1]*Af[1]+vg[2]*Af[2];
828 for(
int j=0;j<neibcount;j++)
842 for(
int k=0;k<klen;k++)
847 for(
int m=0;m<numModes;m++)
852 flux=vg[0]*Af[0]+vg[1]*Af[1]+vg[2]*Af[2];
871 for(
int j=0;j<neibcount;j++)
889 T refl=(*(
_bcMap[Fgid]))[
"specifiedReflection"];
890 T oneMinusRefl=1.-refl;
894 for(
int k=0;k<klen;k++)
899 for(
int m=0;m<numModes;m++)
906 flux=vg[0]*Af[0]+vg[1]*Af[1]+vg[2]*Af[2];
909 Amat(count,count)-=flux;
910 BVec[count-1]-=flux*eArray[cell];
916 const int kk=rpairs.second.second;
921 Amat(count,ccount)-=flux*refl;
922 BVec[count-1]-=eeArray[cell]*refl*flux;
927 T inverseSumVdotA=1./sumVdotA;
930 for(
int k=0;k<klen;k++)
934 for(
int m=0;m<numModes;m++)
938 flux=vg[0]*Af[0]+vg[1]*Af[1]+vg[2]*Af[2];
941 for(
int kk=0;kk<klen;kk++)
946 for(
int mm=0;mm<numMODES;mm++)
949 T VdotA=vvg[0]*Af[0]+vvg[1]*Af[1]+vvg[2]*Af[2];
955 Amat(count,ccount)-=flux*VdotA*ddk3*oneMinusRefl*inverseSumVdotA;
956 BVec[count-1]-=flux*VdotA*ddk3
957 *eeArray[cell]*inverseSumVdotA*oneMinusRefl;
969 for(
int k=0;k<klen;k++)
973 for(
int m=0;m<numModes;m++)
980 flux=vg[0]*Af[0]+vg[1]*Af[1]+vg[2]*Af[2];
983 Amat(count,count)-=flux;
984 BVec[count-1]-=flux*eArray[cell];
987 BVec[count-1]-=flux*eArray[cell2];
1000 const int order=totalmodes+1;
1005 for(
int k=0;k<klen;k++)
1009 for(
int m=0;m<numModes;m++)
1018 BVec[count-1]-=coeff*
_eArray[cellIndex];
1019 BVec[count-1]+=coeff*
_e0Array[cellIndex];
1030 const int order=totalmodes+1;
1036 const T hbar=6.582119e-16;
1038 for(
int k=0;k<klen;k++)
1041 const T dk3=kvol.
getdk3();
1043 for(
int m=0;m<numModes;m++)
1049 coeff=(dk3/DK3)/tau;
1051 BVec[totalmodes]+=coeff*
_eArray[cellIndex];
1052 BVec[totalmodes]-=coeff*
_e0Array[cellIndex];
1076 for(
int k=0;k<klen;k++)
1081 for(
int m=0;m<numModes;m++)
1091 BVec[count-1]*=relFac;
1111 for(
int j=0;j<neibcount;j++)
1124 for(
int k=0;k<klen;k++)
1129 for(
int m=0;m<numModes;m++)
1134 flux=vg[0]*Af[0]+vg[1]*Af[1]+vg[2]*Af[2];
1157 const int order=totalmodes+1;
1162 for(
int k=0;k<klen;k++)
1166 for(
int m=0;m<numModes;m++)
1178 BVec[count-1]-=coeff*eArray[cell];
1179 BVec[count-1]+=coeff*eShifted[cell];
1180 BVec[totalmodes]+=coeff*eArray[cell]/tauTot;
1181 BVec[totalmodes]-=coeff*eShifted[cell]/tauTot;
1193 for(
int k=0;k<klen;k++)
1197 for(
int m=0;m<numModes;m++)
1201 _eArray[cellIndex]+=BVec[count];
1208 TlArray[cell]+=BVec[totalmodes];
1210 deltaTArray[cell]=BVec[totalmodes];
1212 TlResArray[cell]=-Rvec[totalmodes];
1219 TArray ResidSum(totalmodes+1);
1220 TArray Bsum(totalmodes+1);
1223 TArray Bvec(totalmodes+1);
1224 TArray Resid(totalmodes+1);
1225 TArray Dummy(totalmodes+1);
1226 TArrow AMat(totalmodes+1);
1233 for(
int c=0;c<cellcount;c++)
1293 throw CException(
"Unexpected value for boundary cell map.");
1297 for(
int o=0;o<totalmodes+1;o++)
1299 ResidScalar+=ResidSum[o];
1303 ResidScalar/=traceSum;
1318 TArray ResidSum(totalmodes+1);
1319 TArray Bsum(totalmodes+1);
1322 TArray Bvec(totalmodes+1);
1323 TArray Resid(totalmodes+1);
1324 TArray Dummy(totalmodes+1);
1325 TArrow AMat(totalmodes+1);
1330 for(
int c=0;c<cellcount;c++)
1396 throw CException(
"Unexpected value for boundary cell map.");
1400 for(
int o=0;o<totalmodes+1;o++)
1402 ResidScalar+=ResidSum[o];
1406 ResidScalar/=traceSum;
1421 TArray ResidSum(totalmodes+1);
1422 TArray Bsum(totalmodes+1);
1425 TArray Bvec(totalmodes+1);
1426 TArray Resid(totalmodes+1);
1427 TArray Dummy(totalmodes+1);
1430 TArrow AMat(totalmodes+1);
1435 for(
int c=0;c<cellcount;c++)
1499 throw CException(
"Unexpected value for boundary cell map.");
1503 for(
int o=0;o<totalmodes+1;o++)
1505 ResidScalar+=ResidSum[o];
1509 ResidScalar/=traceSum;
1524 const int order=totalmodes+1;
1528 for(
int k=0;k<klen;k++)
1532 for(
int m=0;m<numModes;m++)
1538 rArray[count]=resArray[c];
1565 FaceToFg::iterator id;
1568 if(id->second[0]<=faceIndex && id->second[1]>faceIndex)
1571 cout<<
"Face index: "<<faceIndex<<endl;
1572 throw CException(
"Didn't find matching FaceGroup!");
1579 for(
int i=0;i<length;i++)
1588 for(
int k=0;k<klen;k++)
1592 for(
int m=0;m<numModes;m++)
1609 bVec[totmodes]-=fasArray[c];
1618 for(
int c=0;c<cellCount;c++)
1621 for(
int k=0;k<klen;k++)
1625 for(
int m=0;m<numModes;m++)
1641 for(
int k=0;k<klen;k++)
1645 for(
int m=0;m<numModes;m++)
1680 for(
int j=0;j<neibcount;j++)
1695 T& curMax=pointMax[k];
1696 T& curMin=pointMin[k];
1697 Grads[k].accumulate(Gcoeff, e1-e0);
1715 for(
int j=0;j<neibcount;j++)
1728 const T minVal=pointMin[k];
1729 const T maxVal=pointMax[k];
1730 const T de0(Grads[k]*dr0);
1738 for(
int j=0;j<neibcount;j++)
1759 for(
int k=0;k<klen;k++)
1764 for(
int m=0;m<numModes;m++)
1768 const T VdotA=Af[0]*vg[0]+Af[1]*vg[1]+Af[2]*vg[2];
1776 const VectorT3 rVec=_cellCoords[cell2]-_cellCoords[cell];
1779 T SOU=(fVec[0]*grad[0]+fVec[1]*grad[1]+
1780 fVec[2]*grad[2])*pointLim[count-1];
1792 const T refl=(*(
_bcMap[Fgid]))[
"specifiedReflection"];
1809 for(
int k=0;k<klen;k++)
1814 for(
int m=0;m<numModes;m++)
1818 const T VdotA=Af[0]*vg[0]+Af[1]*vg[1]+Af[2]*vg[2];
1826 VectorT3 fVec=faceCoords[f]-_cellCoords[cell];
1828 T SOU=(grad[0]*fVec[0]+grad[1]*fVec[1]+grad[2]*fVec[2])*pointLim[count-1];
1840 for(
int k=0;k<klen;k++)
1845 for(
int m=0;m<numModes;m++)
1849 const T VdotA=Af[0]*vg[0]+Af[1]*vg[1]+Af[2]*vg[2];
1855 const int kk=rpairs.second.second;
1858 const int rIndex=cell2start+refMode.
getIndex()-1;
1939 for(
int j=0;j<neibcount;j++)
1947 const T refl=(*(
_bcMap[Fgid]))[
"specifiedReflection"];
1962 for(
int k=0;k<klen;k++)
1967 for(
int m=0;m<numModes;m++)
1971 const T VdotA=Af[0]*vg[0]+Af[1]*vg[1]+Af[2]*vg[2];
1976 SumEVdotA+=
_eArray[cellIndex]*VdotA*(dk3/DK3);
1983 const int kk=rpairs.second.second;
1986 const int rIndex=cellstart+refMode.
getIndex()-1;
2001 T wallTemp=Tl[cell2];
2002 T esum=SumEVdotA*DK3;
2007 for(
int k=0;k<klen;k++)
2011 for(
int m=0;m<numModes;m++)
2018 const T oneMinusRefl=1.-refl;
2036 TArray Correction(klen+1);
2039 for(
int j=0;j<neibcount;j++)
2066 for(
int c=0;c<cellcount;c++)
2075 for(
int k=0;k<klen;k++)
2079 for(
int m=0;m<numModes;m++)
2084 TpreFactor+=mode.calcTensorPrefactor(Tl[c]);
2085 VpreFactor+=mode.calcVectorPrefactor(Tl[c],eArray[c]);
2092 for(
int k=0;k<klen;k++)
2099 TensorSum+=TempTensor*dk3*TpreFactor;
2100 VectorSum+=Kvec*dk3*VpreFactor;
2103 lambda=
inverse(TensorSum)*VectorSum;
2106 for(
int k=0;k<klen;k++)
2110 T shift=Kvec[0]*lambda[0]+Kvec[1]*lambda[1]+Kvec[2]*lambda[2];
2112 for(
int m=0;m<numModes;m++)
2117 eShifted[c]=mode.calcShifted(Tl[c],shift);
2126 for(
int i=0;i<3;i++)
2127 for(
int j=0;j<3;j++)
2128 out(i,j)=v1[i]*v2[j];
void multiply(const TArray &x, TArray &b)
const FaceGroupList & getBoundaryFaceGroups() const
pair< Reflection, Reflection > Refl_pair
int getCount(const int i) const
Refl_pair & getReflpair(int i)
const VectorT3Array & _cellCoords
shared_ptr< FaceGroup > FaceGroupPtr
void makeValueArray(const int c, TArray &o)
void COMETConvection(const int cell, TSquare &Amat, TArray &BVec)
ArrowHeadMatrix< T > TArrow
const CRConnectivity & _faceCells
void COMETSolveFull(const int dir, const int level)
void updateTau(const int c, const T Tl)
const IntArray & _BCArray
T getde0taudT(const int c, T Tl)
Tkvol & getkvol(int n) const
void COMETConvectionFine(const int cell0, TArrow &Amat, TArray &BVec, const GradMatrix &gMat)
Tmode & getmode(int n) const
void ScatterPhonons(const int cell0)
KSConnectivity< T > TKConnectivity
void Distribute(const int cell, TArray &BVec, TArray &Rvec)
const StorageSite & _faces
NumTypeTraits< T >::T_Scalar T_Scalar
const FaceGroup & getFaceGroup(const int fgId) const
void COMETSource(const int cell, TArray &BVec)
TArray gatherResid(const int c)
SquareTensor< T, 3 > T3Tensor
Coord & getCoeff(const int i, const int j)
void COMETFullScatt(const int cell, TArray &s, TArray &BVec)
T scaledResid(const TArray &de, const int c)
virtual T & getElement(const int i, const int j)=0
void calcTemp(T &guess, const T e_sum, const Tvec An)
void COMETCollision(const int cell, TMatrix *Amat, TArray &BVec)
map< int, COMETBC< T > * > COMETBCMap
Array< GradType > GradArray
Tmode::Refl_pair Refl_pair
void addFAS(const int c, TArray &Bvec)
void multiply(const XArray &x, XArray &b)
int getGlobalIndex(const int cell, const int count)
T_Scalar & getElement(const int i, const int j)
const IntArray & _BCfArray
void outerProduct(const VectorT3 &v1, const VectorT3 &v2, T3Tensor &out)
Vector< T_Scalar, 3 > VectorT3
const TArray & _cellVolume
void addFAS(const int c, TArray &bVec)
void updatee0(const int c)
COMETDiscretizer(const Mesh &mesh, const GeomFields &geomfields, PhononMacro ¯o, Tkspace &kspace, COMETBCMap &bcMap, const IntArray &BCArray, const IntArray &BCfArray, COpts &options, const FgTKClistMap &FgToKsc)
COMETModelOptions< T > COpts
SquareMatrix< T > TSquare
const T getTau(const int index)
const CRConnectivity & _cellFaces
void computeLimitCoeff2(T &lc, const T x, const T &dx, const T &min, const T &max, const LimitFunc &f)
void correctInterface(const int cell0, TArray &Bvec)
const TArray & _faceAreaMag
static GradMatrixType & getGradientMatrix(const Mesh &mesh, const GeomFields &geomFields)
void COMETSolveFine(const int dir, const int level)
void COMETEquilibrium(const int cell, TMatrix *Amat, TArray &BVec)
SquareMatrix< T, 2 > inverse(SquareMatrix< T, 2 > &a)
Tangent fabs(const Tangent &a)
void COMETConvectionCoarse(const int cell0, TArrow &Amat, TArray &BVec)
GradientModel< T > GradModelType
const GeomFields & _geomFields
void ScatterPhonons(const int c, const int totIts, TArray &C, TArray &B, const TArray &V, TArray &newE, const T cv)
void COMETSolveCoarse(const int dir, const int level)
void addSource(const int c, TArray &BVec, const T cv)
const VectorT3Array & _faceArea
map< int, TKClist > FgTKClistMap
void updateGhostFine(const int cell, const GradMatrix &gMat)
void multiplySelf(const TArray &x, TArray &b, const T scale) const
const StorageSite & _cells
void getSourceTerm(const int c, TArray &s, TArray &ds)
Array< VectorT3 > VectorT3Array
GradModelType::GradMatrixType GradMatrix
map< int, VecInt2 > FaceToFg
void updateGhostCoarse(const int cell)
void COMETShifted(const int cell, TMatrix *Amat, TArray &BVec)
const FgTKClistMap & _FaceToKSC
void findResidCoarse(const bool plusFAS)
int findFgId(const int faceIndex)