29 typedef shared_ptr<VectorT3Array>
VT3Ptr;
56 typedef shared_ptr<StorageSite>
SSPtr;
57 typedef shared_ptr<CRConnectivity>
CRPtr;
70 typedef pair<const StorageSite*, const StorageSite*>
SSPair;
72 typedef map<const StorageSite*, StorageSite*>
SiteMap;
88 const int numMeshes =
_meshes.size();
91 _rank=MPI::COMM_WORLD.Get_rank();
94 for (
int n=0; n<numMeshes; n++)
99 const int faceCount=faces.
getCount();
100 const int cellCount=cells.
getCount();
132 const int numMeshes=
_meshes.size();
133 const T Tinit=
_options[
"initialTemperature"];
135 for (
int n=0;n<numMeshes;n++)
139 throw CException(
"Have not set the Kspace for this Mesh!!");
146 const int numcells=cells.
getCount();
151 shared_ptr<TArray> eArray(
new TArray(numcells*kcount));
152 shared_ptr<TArray> e0Array(
new TArray(numcells*kcount));
153 shared_ptr<TArray> ResidArray(
new TArray(numcells*kcount));
154 shared_ptr<TArray> tauArray(
new TArray(numcells*kcount));
162 shared_ptr<TArray> SrcArray(
new TArray(numcells*kcount));
167 shared_ptr<TArray> TLcell(
new TArray(numcells));
168 shared_ptr<TArray> deltaTcell(
new TArray(numcells));
169 shared_ptr<VectorT3Array> lamArray(
new VectorT3Array(numcells));
181 shared_ptr<IntArray> f2c(
new IntArray(numcells));
188 for(
int mode=0;mode<modeCount;mode++)
190 shared_ptr<Field> modeField(
new Field(
"mode"));
191 shared_ptr<TArray> modeTemp(
new TArray(numcells));
193 modeField->addArray(cells,modeTemp);
194 FieldVecPtr->push_back(modeField);
201 for(
int c=0;c<numcells;c++)
204 for (
int k=0;k<numK;k++)
210 for (
int m=0;m<numM;m++)
214 const T einit=mode.
calce0(Tinit);
220 (*eArray)[cellIndex]=einit;
221 (*e0Array)[cellIndex]=einit;
222 (*ResidArray)[cellIndex]=0.;
223 (*tauArray)[cellIndex]=tau;
231 shared_ptr<TArray> TlResidCell(
new TArray(numcells));
245 const int faceCount=faces.
getCount();
248 for(
int i=offSet;i<offSet+faceCount;i++)
258 if(
_bcMap[fg.
id]->bcType ==
"reflecting")
262 const int faceCount=faces.
getCount();
264 const bool Imp=(*(
_bcMap[fg.
id]))[
"FullyImplicit"];
265 const T ref=(*(
_bcMap[fg.
id]))[
"specifiedReflection"];
268 dynamic_cast<const TArray&
>(AreaMagField[faces]);
273 const VectorT3 norm=AreaDir[0]/AreaMag[0];
277 for (
int k=0;k<numK;k++)
282 for (
int m=0;m<numM;m++)
287 const T vmag=
sqrt(pow(vg[0],2)+pow(vg[1],2)+pow(vg[2],2));
290 const T sidotn=si[0]*norm[0]+si[1]*norm[1]+si[2]*norm[2];
295 so=si-2.*(si[0]*norm[0]+si[1]*norm[1]+si[2]*norm[2])*norm;
296 T soMag=
sqrt(pow(so[0],2)+pow(so[1],2)+pow(so[2],2));
303 const int k1=refls.first.second;
306 reflsFrom.first.second=-1;
307 reflsFrom.second.second=k;
308 rmap2[fg.
id]=reflsFrom;
316 for(
int i=offSet;i<offSet+faceCount;i++)
321 for(
int i=offSet;i<offSet+faceCount;i++)
327 for(
int i=0;i<faceCount;i++)
329 int cell1=BfaceCells(i,0);
330 if(BCArray[cell1]==0)
332 else if(BCArray[cell1]==2)
338 for(
int i=0;i<faceCount;i++)
340 int cell1=BfaceCells(i,0);
341 if(BCArray[cell1]==0)
343 else if (BCArray[cell1]==1)
348 else if(
_bcMap[fg.
id]->bcType ==
"temperature")
351 const int faceCount=faces.
getCount();
354 for(
int i=offSet;i<offSet+faceCount;i++)
357 else if(
_bcMap[fg.
id]->bcType ==
"Interface")
361 const int faceCount=faces0.
getCount();
364 for(
int i=offSet;i<offSet+faceCount;i++)
367 int cell0=BfaceCells(i-offSet,0);
368 int cell1=BfaceCells(i-offSet,1);
373 bool doneAlready=
false;
383 bool foundMatch=
false;
387 int otherFgID,otherMid;
388 for(
int otherMeshID=n+1;otherMeshID<numMeshes;otherMeshID++)
396 otherFgID=otherfgPtr->id;
397 otherMid=otherMeshID;
398 faces1Ptr=&(otherfgPtr->site);
419 else if(!doneAlready && !foundMatch)
421 cout<<
"Face Group: "<<fg.
id<<
" MeshID: "<<mesh.
getID()<<endl;
422 throw CException(
"Could not find a matching face group!");
447 for(
int i=0;i<numMeshes;i++)
455 const int listSize=
_IClist.size();
456 for(
int ic=0;ic<listSize;ic++)
467 for(
int ic=0;ic<listSize;ic++)
487 cout<<
"Creating Coarse Levels on rank "<<
_rank<<
"..."<<endl;
488 cout<<
"Level: 0, rank: "<<
_rank<<endl<<endl;
496 cout<<
"Coarse Levels Completed on rank "<<
_rank<<
"."<<endl;
501 const int numMeshes=
_meshes.size();
503 for (
int n=0;n<numMeshes;n++)
518 if(
_bcMap[fg.
id]->bcType ==
"reflecting")
522 const int faceCount=faces.
getCount();
524 const bool Imp=(*(
_bcMap[fg.
id]))[
"FullyImplicit"];
528 for(
int i=offSet;i<offSet+faceCount;i++)
533 for(
int i=offSet;i<offSet+faceCount;i++)
539 for(
int i=0;i<faceCount;i++)
541 int cell1=BfaceCells(i,0);
542 if(BCArray[cell1]==0)
544 else if(BCArray[cell1]==2)
550 for(
int i=0;i<faceCount;i++)
552 int cell1=BfaceCells(i,0);
553 if(BCArray[cell1]==0)
555 else if (BCArray[cell1]==1)
560 else if(
_bcMap[fg.
id]->bcType ==
"temperature")
563 const int faceCount=faces.
getCount();
566 for(
int i=offSet;i<offSet+faceCount;i++)
569 else if(
_bcMap[fg.
id]->bcType ==
"Interface")
573 const int faceCount=faces0.
getCount();
576 for(
int i=offSet;i<offSet+faceCount;i++)
579 int cell0=BfaceCells(i-offSet,0);
580 int cell1=BfaceCells(i-offSet,1);
585 bool doneAlready=
false;
595 bool foundMatch=
false;
599 int otherFgID,otherMid;
600 for(
int otherMeshID=n+1;otherMeshID<numMeshes;otherMeshID++)
608 otherFgID=otherfgPtr->id;
609 otherMid=otherMeshID;
610 faces1Ptr=&(otherfgPtr->site);
625 if(
_bcMap[fg.
id]->InterfaceModel!=
"DMM")
630 else if(!doneAlready && !foundMatch)
632 cout<<
"Face Group: "<<fg.
id<<
" MeshID: "<<mesh.
getID()<<endl;
633 throw CException(
"Could not find a matching face group!");
652 for(
int i=0;i<numMeshes;i++)
659 const int listSize=
_IClist.size();
660 for(
int ic=0;ic<listSize;ic++)
671 for(
int ic=0;ic<listSize;ic++)
687 const int numMeshes=
_meshes.size();
688 const T Tinit=
_options[
"initialTemperature"];
690 for (
int n=0;n<numMeshes;n++)
696 const int numcells=cells.
getCount();
699 shared_ptr<TArray> eArray(
new TArray(numcells*kcount));
700 shared_ptr<TArray> e0Array(
new TArray(numcells*kcount));
701 shared_ptr<TArray> ResidArray(
new TArray(numcells*kcount));
702 shared_ptr<TArray> InjArray(
new TArray(numcells*kcount));
703 shared_ptr<TArray> FASArray(
new TArray(numcells*kcount));
704 shared_ptr<TArray> tauArray(
new TArray(numcells*kcount));
714 shared_ptr<TArray> SrcArray(
new TArray(numcells*kcount));
719 shared_ptr<TArray> TLcell(
new TArray(numcells));
720 shared_ptr<TArray> deltaTcell(
new TArray(numcells));
726 shared_ptr<IntArray> f2c(
new IntArray(numcells));
730 for(
int c=0;c<numcells;c++)
733 for (
int k=0;k<numK;k++)
738 for (
int m=0;m<numM;m++)
741 const T einit=mode.
calce0(Tinit);
743 (*eArray)[cellIndex]=einit;
744 (*e0Array)[cellIndex]=einit;
745 (*ResidArray)[cellIndex]=0.;
746 (*InjArray)[cellIndex]=0.;
747 (*FASArray)[cellIndex]=0.;
748 (*tauArray)[cellIndex]=tau;
765 const int faceCount=faces.
getCount();
768 for(
int i=offSet;i<offSet+faceCount;i++)
777 if(
_bcMap[fg.
id]->bcType ==
"reflecting")
781 const int faceCount=faces.
getCount();
783 const bool Imp=(*(
_bcMap[fg.
id]))[
"FullyImplicit"];
787 for(
int i=offSet;i<offSet+faceCount;i++)
792 for(
int i=offSet;i<offSet+faceCount;i++)
798 for(
int i=0;i<faceCount;i++)
800 int cell1=BfaceCells(i,0);
801 if(BCArray[cell1]==0)
803 else if(BCArray[cell1]==2)
809 for(
int i=0;i<faceCount;i++)
811 int cell1=BfaceCells(i,0);
812 if(BCArray[cell1]==0)
814 else if (BCArray[cell1]==1)
819 else if(
_bcMap[fg.
id]->bcType ==
"temperature")
822 const int faceCount=faces.
getCount();
825 for(
int i=offSet;i<offSet+faceCount;i++)
828 else if(
_bcMap[fg.
id]->bcType ==
"Interface")
832 const int faceCount=faces0.
getCount();
835 for(
int i=offSet;i<offSet+faceCount;i++)
838 int cell0=BfaceCells(i-offSet,0);
955 const int listSize=
_IClist.size();
956 for(
int i=0;i<listSize;i++)
961 const int fgid0=ic.
FgID0;
962 const int fgid1=ic.
FgID1;
997 for(
int i=0;i<faces0.
getCount();i++)
999 const int f01=common01[i];
1000 const int c01=faceCells1(f01,1);
1001 const int c10=faceCells0(i,1);
1002 (*scatter01)[i]=c01;
1003 (*scatter10)[f01]=c10;
1013 const int numMeshes=
_meshes.size();
1015 for(
int n=0;n<numMeshes;n++)
1029 if(bc.
bcType==
"temperature")
1032 bTemperature(bc.
getVal(
"specifiedTemperature"),faces);
1047 const int numMeshes=
_meshes.size();
1049 for(
int n=0;n<numMeshes;n++)
1063 if(bc.
bcType==
"temperature")
1066 bTemperature(bc.
getVal(
"specifiedTemperature"),faces);
1071 if(
_options.Convection==
"SecondOrder")
1083 if(
_options.AgglomerationMethod==
"FaceArea")
1085 int maxLevs=finerModel->
getOptions().maxLevels;
1086 int thisLevel=(finerModel->
getLevel())+1;
1088 if(thisLevel<maxLevs)
1098 map<const StorageSite*, IntArray*> PreFacePairMap;
1102 *newMeshesPtr, CoarseCounts, PreFacePairMap, CoarseGhost, siteMap);
1110 *newMeshesPtr, coarseScatterMaps, coarseGatherMaps, CoarseCounts,
1117 *newMeshesPtr, CoarseCounts, PreFacePairMap, CoarseGhost);
1121 *newKspacesPtr,*newMacroPtr);
1123 newModelPtr->setFinerLevel(finerModel);
1125 newModelPtr->getOptions()=finerModel->
getOptions();
1126 newModelPtr->getBCs()=finerModel->
getBCs();
1127 newModelPtr->getMKMap()=finerModel->
getMKMap();
1128 newModelPtr->getIClist()=finerModel->
getIClist();
1129 newModelPtr->getMeshICmap()=finerModel->
getMeshICmap();
1132 newModelPtr->initCoarse();
1136 cout<<
"Level: "<<newModelPtr->getLevel()<<endl<<endl;
1137 newModelPtr->calcDomainStats();
1142 newModelPtr->MakeCoarseModel(newModelPtr);
1144 _options.maxLevels=newModelPtr->getLevel();
1147 else if(
_options.AgglomerationMethod==
"AMG")
1148 throw CException(
"Have not implemented AMG agglomeration method.");
1150 throw CException(
"Unknown agglomeration method.");
1162 const int len=inList.size();
1163 for(
int i=0;i<len;i++)
1167 inList[i]->setCoarseKspace(newKspacePtr);
1168 outList.push_back(newKspacePtr);
1171 for(
int i=0;i<len;i++)
1172 inList[i]->giveTransmissions();
1178 map<const StorageSite*, IntArray*>& PreFacePairMap,
IntArray& CoarseGhost,
1182 const int numMeshes=inMeshes.size();
1194 for(
int m=0;m<numMeshes;m++)
1196 const Mesh& mesh=*inMeshes[m];
1199 outMeshes.push_back(newMeshPtr);
1200 newMeshPtr->
setID(m);
1202 int coarseCount=
coarsenInterior(m, mesh, inGeomFields, CoarseCounts[m]);
1210 const int Fid0=ic.
FgID0;
1211 const int Fid1=ic.
FgID1;
1212 const Mesh& mesh0=*inMeshes[Mid0];
1213 const Mesh& mesh1=*inMeshes[Mid1];
1217 const IntArray& common01=*(ComMap.find(&faces1)->second);
1230 const int faceCount=faces0.
getCount();
1233 const int cCount0=CoarseCounts[Mid0];
1236 const CRPtr cellsIntGhost0Ptr=cellFaces0.
multiply(faceCells0,
true);
1241 dynamic_cast<const VectorT3Array&
>(FaceAreaField[allFaces0]);
1244 *FaceFine2CoarsePtr0=-1;
1245 IntArray& FaceFine2Coarse0=*FaceFine2CoarsePtr0;
1249 *FaceFine2CoarsePtr1=-1;
1250 IntArray& FaceFine2Coarse1=*FaceFine2CoarsePtr1;
1257 preCoarseToFineCells0->initCount();
1260 preCoarseToFineCells0->addCount(FineToCoarse0[c],1);
1262 preCoarseToFineCells0->finishCount();
1265 preCoarseToFineCells0->add(FineToCoarse0[c],c);
1267 preCoarseToFineCells0->finishAdd();
1271 for(
int f=0;f<faceCount;f++)
1274 if(FaceFine2Coarse0[f]==-1)
1276 const int c00=faceCells0(f,0);
1277 const int f01=common01[f];
1278 const int c01=faceCells1(f01,0);
1279 const int coarseC00=FineToCoarse0[c00];
1280 const int coarseC01=FineToCoarse1[c01];
1282 const int cC00fineCnt=preCoarseToFineCells0->getCount(coarseC00);
1283 for(
int cC00fine=0;cC00fine<cC00fineCnt;cC00fine++)
1285 const int fineCell=(*preCoarseToFineCells0)(coarseC00,cC00fine);
1288 const int fineGhostCount=cellsIntGhost0.
getCount(fineCell);
1289 for(
int fineGhostNum=0;fineGhostNum<fineGhostCount;fineGhostNum++)
1291 const int fineGhost=cellsIntGhost0(fineCell,fineGhostNum);
1292 const int f10=cellFaces0(fineGhost,0);
1293 const int f11=common01[f10];
1294 const int c11=faceCells1(f11,0);
1296 if(FineToCoarse1[c11]==coarseC01)
1298 if(FaceFine2Coarse0[f10]==-1 && FaceFine2Coarse0[f]==-1)
1300 FaceFine2Coarse0[f10]=coarseFace;
1301 FaceFine2Coarse0[f]=coarseFace;
1302 FaceFine2Coarse1[f11]=coarseFace;
1303 FaceFine2Coarse1[f01]=coarseFace;
1306 else if(FaceFine2Coarse0[f10]==-1 && FaceFine2Coarse0[f]!=-1)
1308 FaceFine2Coarse0[f10]=FaceFine2Coarse0[f];
1309 FaceFine2Coarse1[f11]=FaceFine2Coarse0[f01];
1311 else if(FaceFine2Coarse0[f10]!=-1 && FaceFine2Coarse0[f]==-1)
1313 FaceFine2Coarse0[f]=FaceFine2Coarse0[f10];
1314 FaceFine2Coarse1[f01]=FaceFine2Coarse1[f11];
1322 if(FaceFine2Coarse0[f]==-1)
1324 FaceFine2Coarse0[f]=coarseFace;
1325 FaceFine2Coarse1[f01]=coarseFace;
1343 for(
int f=0;f<faceCount;f++)
1346 summedArea[FaceFine2Coarse0[f]]+=FArea0[f+offset];
1349 for(
int f=0;f<faceCount;f++)
1351 const int f01=common01[f];
1353 VectorT3& sumVec=summedArea[FaceFine2Coarse0[f]];
1354 const VectorT3& partVec=FArea0[f+offset];
1355 T sumMag=
sqrt(sumVec[0]*sumVec[0]+sumVec[1]*sumVec[1]+
1356 sumVec[2]*sumVec[2]);
1357 T partMag=
sqrt(partVec[0]*partVec[0]+partVec[1]*partVec[1]+
1358 partVec[2]*partVec[2]);
1361 if(sumMag/partMag<1.0)
1364 FaceFine2Coarse0[f]=coarseFace;
1365 FaceFine2Coarse1[f01]=coarseFace;
1371 PreFacePairMap[&faces0]=FaceFine2CoarsePtr0;
1372 PreFacePairMap[&faces1]=FaceFine2CoarsePtr1;
1376 for(
int n=0;n<numMeshes;n++)
1383 CoarseCounts[n], PreFacePairMap);
1389 CoarseGhost[n]=CoarseCounts[n];
1400 if(
_bcMap[fg.
id]->bcType ==
"Interface")
1405 for(
int i=0;i<faceCount;i++)
1407 const int cghost=faceCells(i,1);
1408 FineToCoarse[cghost]=FaceFine2Coarse[i]+CoarseGhost[n];
1409 if(FaceFine2Coarse[i]>coarseFaces)
1410 coarseFaces=FaceFine2Coarse[i];
1412 CoarseGhost[n]+=coarseFaces+1;
1413 outGhost+=coarseFaces+1;
1415 else if(
_bcMap[fg.
id]->bcType ==
"temperature" ||
1416 _bcMap[fg.
id]->bcType ==
"reflecting" )
1418 for(
int i=0;i<faceCount;i++)
1420 const int cghost=faceCells(i,1);
1421 FineToCoarse[cghost]=CoarseGhost[n];
1439 const int numMeshes=inMeshes.size();
1440 for(
int n=0;n<numMeshes;n++)
1442 const Mesh& mesh=*inMeshes[n];
1453 tempIndex[c]=coarseIndex[c];
1464 typedef map<const StorageSite*, vector<const Array<int>* > > IndicesMap;
1465 IndicesMap toIndicesMap;
1468 foreach(
const StorageSite::GatherMap::value_type pos, gatherMap)
1475 toIndicesMap[&oSite].push_back(&toIndices);
1516 foreach(IndicesMap::value_type pos, toIndicesMap)
1519 const vector<const Array<int>* > toIndicesArrays = pos.second;
1522 map<int,int> otherToMyMapping;
1525 foreach(
const Array<int>* toIndicesPtr, toIndicesArrays)
1528 const int nGhostRows = toIndices.
getLength();
1529 for(
int ng=0; ng<nGhostRows; ng++)
1531 const int fineIndex = toIndices[ng];
1532 const int coarseOtherIndex = coarseIndex[fineIndex];
1534 if (coarseOtherIndex < 0)
1537 if (otherToMyMapping.find(coarseOtherIndex) !=
1538 otherToMyMapping.end())
1540 coarseIndex[fineIndex] = otherToMyMapping[coarseOtherIndex];
1544 coarseIndex[fineIndex] = CoarseGhost[n];
1545 otherToMyMapping[coarseOtherIndex] = coarseIndex[fineIndex];
1546 gatherSet.
insert( coarseIndex[fineIndex] );
1554 const int coarseMappersSize = otherToMyMapping.size();
1556 shared_ptr<Array<int> > coarseToIndices(
new Array<int>(coarseMappersSize));
1558 for(
int n = 0; n < gatherSet.
size(); n++)
1559 (*coarseToIndices)[n] = gatherSet.
getData().at(n);
1561 SSPair sskey(&site,&oSite);
1562 coarseGathMaps [sskey] = coarseToIndices;
1568 IndicesMap fromIndicesMap;
1570 foreach(
const StorageSite::GatherMap::value_type pos, scatterMap)
1575 fromIndicesMap[&oSite].push_back(&fromIndices);
1578 foreach(IndicesMap::value_type pos, fromIndicesMap)
1581 const vector<const Array<int>* > fromIndicesArrays = pos.second;
1585 foreach(
const Array<int>* fromIndicesPtr, fromIndicesArrays)
1587 const Array<int>& fromIndices = *fromIndicesPtr;
1588 const int nGhostRows = fromIndices.
getLength();
1589 for(
int ng=0; ng<nGhostRows; ng++)
1591 const int fineIndex = fromIndices[ng];
1592 const int coarseOtherIndex = coarseIndex[fineIndex];
1593 if (coarseOtherIndex >= 0)
1594 scatterSet.
insert( coarseOtherIndex );
1599 const int coarseMappersSize = scatterSet.
size();
1601 shared_ptr<Array<int> > coarseFromIndices(
new Array<int>(coarseMappersSize));
1603 for(
int n = 0; n < scatterSet.
size(); n++ )
1604 (*coarseFromIndices)[n] = scatterSet.
getData().at(n);
1606 SSPair sskey(&site,&oSite);
1607 coarseScatMaps[sskey] = coarseFromIndices;
1617 const int numMeshes =
_meshes.size();
1618 for (
int n=0; n<numMeshes; n++)
1626 foreach(
const StorageSite::ScatterMap::value_type& pos, fineScatterMap)
1632 if (siteMap.find(&fineOSite) == siteMap.end())
1638 siteMap[&fineOSite]=ghostSite;
1643 SSPair sskey(&fineSite,&fineOSite);
1644 coarseScatterMap[coarseOSite] = coarseScatMaps[sskey];
1651 foreach(
const StorageSite::GatherMap::value_type& pos, fineGatherMap)
1655 SSPair sskey(&fineSite,&fineOSite);
1657 coarseGatherMap[&coarseOSite] = coarseGathMaps[sskey];
1665 map<const StorageSite*, IntArray*>& PreFacePairMap,
1669 const int numMeshes=inMeshes.size();
1671 int smallestMesh=-1;
1673 for(
int n=0;n<numMeshes;n++)
1675 const Mesh& mesh=*inMeshes[n];
1676 Mesh* newMeshPtr=outMeshes[n];
1683 const int inCellTotal=inCells.
getCount();
1684 const int inFaceCount=inFaces.
getCount();
1688 const TArray& areaMagArray=
1689 dynamic_cast<const TArray&
>(areaMagField[inFaces]);
1696 outCells.
setCount(CoarseCounts[n],coarseGhost[n]-CoarseCounts[n]);
1698 CoarseToFineCells->initCount();
1700 for(
int c=0;c<inCellTotal;c++)
1701 CoarseToFineCells->addCount(FineToCoarse[c],1);
1703 CoarseToFineCells->finishCount();
1705 for(
int c=0;c<inCellTotal;c++)
1706 CoarseToFineCells->add(FineToCoarse[c],c);
1708 CoarseToFineCells->finishAdd();
1714 FineFacesCoarseCells->initCount();
1717 for(
int f=0;f<inFaceCount;f++)
1719 int coarse0=FineToCoarse[inFaceinCells(f,0)];
1720 int coarse1=FineToCoarse[inFaceinCells(f,1)];
1721 if(coarse0!=coarse1)
1722 FineFacesCoarseCells->addCount(f,2);
1725 FineFacesCoarseCells->finishCount();
1728 for(
int f=0;f<inFaceCount;f++)
1730 int fc0=inFaceinCells(f,0);
1731 int fc1=inFaceinCells(f,1);
1732 int cc0=FineToCoarse[fc0];
1733 int cc1=FineToCoarse[fc1];
1736 FineFacesCoarseCells->add(f,cc0);
1737 FineFacesCoarseCells->add(f,cc1);
1741 FineFacesCoarseCells->finishAdd();
1743 CRPtr CoarseCellsFineFaces=FineFacesCoarseCells->getTranspose();
1744 CRPtr CellCellCoarse=CoarseCellsFineFaces->multiply(*FineFacesCoarseCells,
true);
1749 for(
int c=0;c<outCells.
getCount();c++)
1752 const int neibs=CellCellCoarse->getCount(c);
1754 for(
int n=0;n<neibs;n++)
1756 const int c1=(*CellCellCoarse)(c,n);
1785 CoarseCellCoarseFace->initCount();
1788 for(
int c=0;c<outCells.
getCount();c++)
1790 const int neibs=CellCellCoarse->getCount(c);
1791 CoarseCellCoarseFace->addCount(c,neibs);
1795 CoarseCellCoarseFace->addCount(c,neibs);
1800 CoarseCellCoarseFace->finishCount();
1808 const int neibs=CellCellCoarse->getCount(c);
1809 for(
int n=0;n<neibs;n++)
1811 const int c1=(*CellCellCoarse)(c,n);
1816 CoarseCellCoarseFace->add(c,counter);
1817 CoarseCellCoarseFace->add(c1,counter);
1825 CoarseCellCoarseFace->add(c,counter);
1826 CoarseCellCoarseFace->add(c1,counter);
1831 CoarseCellCoarseFace->add(c,counter);
1832 CoarseCellCoarseFace->add(c1,counter);
1834 CoarseCellCoarseFace->add(c,counter);
1835 CoarseCellCoarseFace->add(c1,counter);
1842 const int coarseInteriorCount=counter;
1854 if(
_bcMap[fg.
id]->bcType ==
"Interface")
1859 if(FaceFine2Coarse[i]>coarseFaces)
1860 coarseFaces=FaceFine2Coarse[i];
1861 faceCount=coarseFaces+1;
1863 BArray countedFaces(faceCount);
1867 const int coarseFace=FaceFine2Coarse[i];
1868 if(!countedFaces[coarseFace])
1871 const int cc1=(*FineFacesCoarseCells)(globFace,0);
1872 const int cc2=(*FineFacesCoarseCells)(globFace,1);
1873 CoarseCellCoarseFace->add(cc1,counter);
1874 CoarseCellCoarseFace->add(cc2,counter);
1876 countedFaces[coarseFace]=
true;
1884 for(
int i=0;i<faceCount;i++)
1886 const int c1=inBfaceCells(i,1);
1887 const int cc1=FineToCoarse[c1];
1888 const int cc2=(*CellCellCoarse)(cc1,0);
1889 CoarseCellCoarseFace->add(cc1,counter);
1890 CoarseCellCoarseFace->add(cc2,counter);
1899 foreach(
const StorageSite::GatherMap::value_type pos, outCells.
getGatherMap())
1905 if ( to_where != -1 )
1907 const int fgCount=toIndices.
getLength();
1909 for(
int i=0;i<fgCount;i++)
1911 const int c1=toIndices[i];
1912 const int c1neibs=CellCellCoarse->getCount(c1);
1913 for(
int j=0;j<c1neibs;j++)
1915 const int c2=(*CellCellCoarse)(toIndices[i],j);
1916 CoarseCellCoarseFace->add(c2,counter);
1917 CoarseCellCoarseFace->add(toIndices[i],counter);
1924 CoarseCellCoarseFace->finishAdd();
1926 CRPtr CoarseFaceCoarseCell=CoarseCellCoarseFace->getTranspose();
1932 CoarseFacesFineFaces->initCount();
1937 for(
int f=0;f<inFaceCount;f++)
1939 int fc0=inFaceinCells(f,0);
1940 int fc1=inFaceinCells(f,1);
1941 const int cc0=FineToCoarse[fc0];
1942 const int cc1=FineToCoarse[fc1];
1944 int cc0neibs=CellCellCoarse->getCount(cc0);
1945 int cc1neibs=CellCellCoarse->getCount(cc1);
1954 const int cfaces=CoarseCellCoarseFace->getCount(cc0);
1956 for(
int cf=0;cf<cfaces;cf++)
1958 const int face=(*CoarseCellCoarseFace)(cc0,cf);
1959 const int tempc0=(*CoarseFaceCoarseCell)(face,0);
1960 const int tempc1=(*CoarseFaceCoarseCell)(face,1);
1962 if(((cc0==tempc0)&&(cc1==tempc1))||((cc1==tempc0)&&(cc0==tempc1)))
1969 areaSum[face]+=inFA[f]*sign;
1971 if(cc1neibs>1 && cc0neibs>1)
1973 CoarseFacesFineFaces->addCount(face,1);
1978 T sumMag=
sqrt(areaSum[face][0]*areaSum[face][0]+
1979 areaSum[face][1]*areaSum[face][1]+
1980 areaSum[face][2]*areaSum[face][2]);
1982 T partMag=
sqrt(inFA[f][0]*inFA[f][0]+
1983 inFA[f][1]*inFA[f][1]+
1984 inFA[f][2]*inFA[f][2]);
1986 if(sumMag/partMag>.75)
1988 CoarseFacesFineFaces->addCount(face,1);
1992 areaSum[face]-=inFA[f]*sign;
2000 CoarseFacesFineFaces->finishCount();
2004 for(
int f=0;f<inFaceCount;f++)
2006 int fc0=inFaceinCells(f,0);
2007 int fc1=inFaceinCells(f,1);
2008 const int cc0=FineToCoarse[fc0];
2009 const int cc1=FineToCoarse[fc1];
2011 int cc0neibs=CellCellCoarse->getCount(cc0);
2012 int cc1neibs=CellCellCoarse->getCount(cc1);
2021 const int cfaces=CoarseCellCoarseFace->getCount(cc0);
2023 for(
int cf=0;cf<cfaces;cf++)
2025 const int face=(*CoarseCellCoarseFace)(cc0,cf);
2026 const int tempc0=(*CoarseFaceCoarseCell)(face,0);
2027 const int tempc1=(*CoarseFaceCoarseCell)(face,1);
2029 if(((cc0==tempc0)&&(cc1==tempc1))||((cc1==tempc0)&&(cc0==tempc1)))
2036 areaSum[face]+=inFA[f]*sign;
2038 if(cc1neibs>1 && cc0neibs>1)
2040 CoarseFacesFineFaces->add(face,f);
2045 T sumMag=
sqrt(areaSum[face][0]*areaSum[face][0]+
2046 areaSum[face][1]*areaSum[face][1]+
2047 areaSum[face][2]*areaSum[face][2]);
2049 T partMag=
sqrt(inFA[f][0]*inFA[f][0]+
2050 inFA[f][1]*inFA[f][1]+
2051 inFA[f][2]*inFA[f][2]);
2053 if(sumMag/partMag>.75)
2055 CoarseFacesFineFaces->add(face,f);
2059 areaSum[face]-=inFA[f]*sign;
2066 CoarseFacesFineFaces->finishAdd();
2071 int inOffset=coarseInteriorCount;
2078 if(
_bcMap[fg.
id]->bcType ==
"Interface")
2082 for(
int i=0;i<faceCount;i++)
2083 if(FaceFine2Coarse[i]>coarseFaces)
2084 coarseFaces=FaceFine2Coarse[i];
2090 inOffset+=coarseFaces;
2099 (*newFgCoordsPtr)=oldFgCoords;
2110 foreach(
const StorageSite::GatherMap::value_type pos, coarseGatherMap)
2116 if ( to_where != -1 )
2118 const int cellCount=toIndices.
getLength();
2121 for(
int i=0;i<cellCount;i++)
2123 const int c1=toIndices[i];
2124 faceCount+=CellCellCoarse->getCount(c1);
2129 inOffset+=faceCount;
2135 const int outCellsTotCount=outCells.
getCount();
2138 TArray& outCV=*outCellVolumePtr;
2143 const TArray& inCV=
dynamic_cast<const TArray&
>(VolumeField[inCells]);
2146 for(
int c=0;c<outCellsCount;c++)
2148 const int fineCount=CoarseToFineCells->getCount(c);
2153 for(
int i=0;i<fineCount;i++)
2155 int fc=(*CoarseToFineCells)(c,i);
2157 newCoord+=inCoords[fc]*inCV[fc];
2159 outCoords[c]=newCoord/outCV[c];
2162 for(
int c=outCellsCount;c<outCellsTotCount;c++)
2164 const int fineCount=CoarseToFineCells->getCount(c);
2169 for(
int i=0;i<fineCount;i++)
2171 int fc=(*CoarseToFineCells)(c,i);
2172 newCoord+=inCoords[fc];
2174 outCoords[c]=newCoord;
2177 VolumeField.
addArray(outCells,outCellVolumePtr);
2180 const int outFacesCount=outFaces.
getCount();
2184 TArray& outFAMag=*outFaceAreaMagPtr;
2193 for(
int f=0;f<outFacesCount;f++)
2195 const int fineCount=CoarseFacesFineFaces->getCount(f);
2196 const int cCell0=(*CoarseFaceCoarseCell)(f,0);
2197 for(
int i=0;i<fineCount;i++)
2199 const int fFace=(*CoarseFacesFineFaces)(f,i);
2200 const int fCell0=inFaceinCells(fFace,0);
2201 const int CCell0=FineToCoarse[fCell0];
2206 outFA[f]+=inFA[fFace];
2208 outFA[f]-=inFA[fFace];
2209 outFAMag[f]+=areaMagArray[fFace];
2213 FaceAreaField.
addArray(outFaces,outFaceAreaPtr);
2214 areaMagField.
addArray(outFaces,outFaceAreaMagPtr);
2246 return smallestMesh;
2258 const TArray& areaMagArray=
dynamic_cast<const TArray&
>(areaMagField[inFaces]);
2265 for(
int c=0;c<inCellCount;c++)
2267 if(FineToCoarse[c]<0)
2270 const int neibCount=inCellinFaces.
getCount(c);
2274 for(
int neib=0;neib<neibCount;neib++)
2276 const int f=inCellinFaces(c,neib);
2278 if(inBCfArray[f]==0)
2280 if(c==inFaceinCells(f,1))
2281 c2=inFaceinCells(f,0);
2283 c2=inFaceinCells(f,1);
2285 if(FineToCoarse[c2]==-1)
2287 if(areaMagArray[f]>maxArea)
2290 maxArea=areaMagArray[f];
2299 FineToCoarse[c]=coarseCount;
2300 FineToCoarse[pairWith]=coarseCount;
2307 for(
int c=0;c<inCellCount;c++)
2309 if(FineToCoarse[c]==-1)
2311 const int neibCount=inCellinFaces.
getCount(c);
2316 for(
int neib=0;neib<neibCount;neib++)
2318 const int f=inCellinFaces(c,neib);
2320 if(inBCfArray[f]==0)
2322 if(c==inFaceinCells(f,1))
2323 c2=inFaceinCells(f,0);
2325 c2=inFaceinCells(f,1);
2327 if(areaMagArray[f]>maxArea)
2329 pairWith=FineToCoarse[c2];
2331 maxArea=areaMagArray[f];
2338 FineToCoarse[c]=coarseCount;
2343 if(FineToCoarse[c2perm]==-1)
2345 FineToCoarse[c]=coarseCount;
2346 FineToCoarse[c2perm]=coarseCount;
2350 FineToCoarse[c]=FineToCoarse[c2perm];
2359 map<const StorageSite*, IntArray*> PreFacePairMap)
2363 const int inCellTotal=inCells.
getCount();
2365 const int inFaceCount=inFaces.
getCount();
2371 FineToCoarse=FineToCoarseConst;
2373 int coarseGhost=coarseCount;
2384 if(
_bcMap[fg.
id]->bcType ==
"Interface")
2389 for(
int i=0;i<faceCount;i++)
2391 const int cghost=faceCells(i,1);
2392 FineToCoarse[cghost]=FaceFine2Coarse[i]+coarseGhost;
2393 if(FaceFine2Coarse[i]>coarseFaces)
2394 coarseFaces=FaceFine2Coarse[i];
2396 coarseGhost+=coarseFaces+1;
2397 outGhost+=coarseFaces+1;
2399 else if(
_bcMap[fg.
id]->bcType ==
"temperature" ||
2400 _bcMap[fg.
id]->bcType ==
"reflecting" )
2402 for(
int i=0;i<faceCount;i++)
2404 const int cghost=faceCells(i,1);
2405 FineToCoarse[cghost]=coarseGhost;
2420 for(
int i=0;i<faceCount;i++)
2422 const int cghost=faceCells(i,1);
2423 FineToCoarse[cghost]=coarseGhost;
2432 CoarseToFineCells->initCount();
2434 for(
int c=0;c<inCellTotal;c++)
2435 CoarseToFineCells->addCount(FineToCoarse[c],1);
2437 CoarseToFineCells->finishCount();
2439 for(
int c=0;c<inCellTotal;c++)
2440 CoarseToFineCells->add(FineToCoarse[c],c);
2442 CoarseToFineCells->finishAdd();
2445 FineFacesCoarseCells->initCount();
2448 int survivingFaces=0;
2449 int coarse0, coarse1;
2450 for(
int f=0;f<inFaceCount;f++)
2452 coarse0=FineToCoarse[inFaceinCells(f,0)];
2453 coarse1=FineToCoarse[inFaceinCells(f,1)];
2454 if(coarse0!=coarse1)
2457 FineFacesCoarseCells->addCount(f,2);
2461 FineFacesCoarseCells->finishCount();
2464 for(
int f=0;f<inFaceCount;f++)
2466 int fc0=inFaceinCells(f,0);
2467 int fc1=inFaceinCells(f,1);
2468 int cc0=FineToCoarse[fc0];
2469 int cc1=FineToCoarse[fc1];
2472 FineFacesCoarseCells->add(f,cc0);
2473 FineFacesCoarseCells->add(f,cc1);
2477 FineFacesCoarseCells->finishAdd();
2479 CRPtr CoarseCellsFineFaces=FineFacesCoarseCells->getTranspose();
2480 CRPtr CellCellCoarse=CoarseCellsFineFaces->multiply(*FineFacesCoarseCells,
true);
2485 if(CellCellCoarse->getCount(c)<2)
2499 const int removal=(*CoarseToFineCells)(c,0);
2500 FineToCoarse[removal]=coarseCount;
2514 const int Fid0=ic.
FgID0;
2515 const int Fid1=ic.
FgID1;
2516 const Mesh& mesh0=*inMeshes[Mid0];
2517 const Mesh& mesh1=*inMeshes[Mid1];
2524 const IntArray& common01=*(ComMap.find(&faces1)->second);
2531 const int inFaceCount=faces0.
getCount();
2533 const TArray& areaMagArray0=
dynamic_cast<const TArray&
>(areaMagField[globFaces0]);
2538 const CRPtr cellsIntGhost0Ptr=cellFaces0.
multiply(faceCells0,
true);
2542 CoarseFineCount.
zero();
2546 int& count0=coarseCounts[Mid0];
2547 int& count1=coarseCounts[Mid1];
2557 for(
int f=0;f<inFaceCount;f++)
2559 const int c=faceCells0(f,0);
2560 const int cCoarse=CoarseFineCount[c];
2561 if(f2c0[c]<0 || cCoarse<4)
2564 const int neibCount=cellCells0.
getCount(c);
2568 for(
int neib=0;neib<neibCount;neib++)
2570 const int fglob=globCellFaces0(c,neib);
2572 if(inBCfArray0[fglob]==0)
2574 if(c==globFaceCells0(fglob,1))
2575 c2=globFaceCells0(fglob,0);
2577 c2=globFaceCells0(fglob,1);
2579 int c2Coarse=f2c0[c2];
2585 if(areaMagArray0[fglob]>maxArea)
2588 maxArea=areaMagArray0[fglob];
2598 if(areaMagArray0[fglob]>maxArea)
2601 maxArea=areaMagArray0[fglob];
2613 int c2Coarse=f2c0[pairWith];
2614 if(c2Coarse==-1 && f2c0[c]==-1)
2616 f2c0[pairWith]=count0;
2618 CoarseFineCount[count0]++;
2621 else if(f2c0[c]==-1 && c2Coarse>=0)
2632 for(
int f=0;f<inFaceCount;f++)
2634 const int c=faceCells0(f,0);
2638 const int neibCount=cellCells0.
getCount(c);
2642 for(
int neib=0;neib<neibCount;neib++)
2644 const int fglob=globCellFaces0(c,neib);
2646 if(inBCfArray0[fglob]==0)
2648 if(c==globFaceCells0(fglob,1))
2649 c2=globFaceCells0(fglob,0);
2651 c2=globFaceCells0(fglob,1);
2655 if(areaMagArray0[fglob]>maxArea)
2658 maxArea=areaMagArray0[fglob];
2667 f2c0[pairWith]=count0;
2677 preCoarseToFineCells0->initCount();
2681 preCoarseToFineCells0->addCount(f2c0[c],1);
2684 preCoarseToFineCells0->finishCount();
2688 preCoarseToFineCells0->add(f2c0[c],c);
2690 preCoarseToFineCells0->finishAdd();
2693 for(
int f=0;f<inFaceCount;f++)
2695 const int f1=common01[f];
2697 const int c01=faceCells1(f1,0);
2698 const int c00=faceCells0(f,0);
2702 const int coarseC00=f2c0[c00];
2703 const int cC00fineCnt=preCoarseToFineCells0->getCount(coarseC00);
2705 for(
int cC00fine=0;cC00fine<cC00fineCnt;cC00fine++)
2708 const int fineCell=(*preCoarseToFineCells0)(coarseC00,cC00fine);
2711 const int c10gNeibs=cellsIntGhost0.
getCount(fineCell);
2712 for(
int c10ghost=0;c10ghost<c10gNeibs;c10ghost++)
2714 const int c10g=cellsIntGhost0(fineCell,c10ghost);
2715 const int f10=cellFaces0(c10g,0);
2716 const int f11=common01[f10];
2718 const int c11=faceCells1(f11,0);
2719 const int neibCount1=cellCells1.
getCount(c01);
2721 for(
int c01neibs=0;c01neibs<neibCount1;c01neibs++)
2723 if(cellCells1(c01,c01neibs)==c11)
2732 if(f2c1[c11]>-1 && f2c1[c01]<0)
2733 f2c1[c01]=f2c1[c11];
2734 else if(f2c1[c01]>-1 && f2c1[c11]<0)
2735 f2c1[c11]=f2c1[c01];
2736 else if(f2c1[c11]<0 && f2c1[c01]<0)
2745 const int c11neibCnt=cellCells1.
getCount(c11);
2747 for(
int c11nb=0;c11nb<c11neibCnt;c11nb++)
2749 const int c11neib=cellCells1(c11,c11nb);
2750 for(
int c01neibs=0;c01neibs<neibCount1;c01neibs++)
2752 if(cellCells1(c01,c01neibs)==c11neib)
2761 if(f2c1[middleMan]==-1)
2763 if(f2c1[c11]<0 && f2c1[c01]<0)
2767 f2c1[middleMan]=count1;
2770 else if(f2c1[c11]>-1 && f2c1[c01]<0)
2772 f2c1[c01]=f2c1[c11];
2773 f2c1[middleMan]=f2c1[c11];
2775 else if(f2c1[c01]>-1 && f2c1[c11]<0)
2777 f2c1[c11]=f2c1[c01];
2778 f2c1[middleMan]=f2c1[c01];
2802 for(
int sweepNo=0;sweepNo<sweeps;sweepNo++)
2813 const int numMeshes=
_meshes.size();
2822 for(
int msh=start;((msh<numMeshes)&&(msh>-1));msh+=dir)
2832 for(
int i=0;i<totIC;i++)
2887 for(
int i=0;i<totIC;i++)
2900 const int numMeshes=
_meshes.size();
2904 const int listSize=
_IClist.size();
2905 for(
int ic=0;ic<listSize;ic++)
2920 for(
int msh=0;msh<numMeshes;msh++)
2950 highResid=currentResid;
2952 if(currentResid>highResid)
2953 highResid=currentResid;
2961 const int numMeshes=
_meshes.size();
2962 for(
int msh=0;msh<numMeshes;msh++)
2990 const int numMeshes =
_meshes.size();
2992 for (
int n=0; n<numMeshes; n++)
3013 const int cellTotCount=coarserCells.
getCount();
3017 for(
int c=0;c<cellCount;c++)
3019 const int fineCount=CoarserToFiner.
getCount(c);
3022 for(
int fc=0;fc<fineCount;fc++)
3024 const int cell=CoarserToFiner(c,fc);
3029 for(
int k=0;k<klen;k++)
3033 for(
int m=0;m<numModes;m++)
3035 coarserVar[coarserCellIndex]+=finerVar[finerCellIndex]*finerVol[cell];
3036 coarserFAS[coarserCellIndex]+=finerRes[finerCellIndex];
3046 for(
int k=0;k<klen;k++)
3051 for(
int m=0;m<numModes;m++)
3053 coarserVar[coarserCellIndex]/=coarserVol[c];
3054 coarserInj[coarserCellIndex]=coarserVar[coarserCellIndex];
3060 for(
int c=cellCount;c<cellTotCount;c++)
3062 const int cell=CoarserToFiner(c,0);
3066 for(
int k=0;k<klen;k++)
3070 for(
int m=0;m<numModes;m++)
3072 coarserVar[coarserCellIndex]=0.;
3073 coarserFAS[coarserCellIndex]=0.;
3074 coarserVar[coarserCellIndex]+=finerVar[finerCellIndex];
3075 coarserFAS[coarserCellIndex]+=finerRes[finerCellIndex];
3076 coarserInj[coarserCellIndex]=coarserVar[coarserCellIndex];
3089 for(
int c=0;c<cellCount;c++)
3091 const int fineCount=CoarserToFiner.
getCount(c);
3095 for(
int fc=0;fc<fineCount;fc++)
3097 const int cell=CoarserToFiner(c,fc);
3098 coarserVarM[c]+=finerVarM[cell]*finerVol[cell];
3099 coarserFASM[c]+=finerResM[cell];
3101 coarserVarM[c]/=coarserVol[c];
3102 coarserInjM[c]=coarserVarM[c];
3111 const int numMeshes =
_meshes.size();
3112 for (
int n=0; n<numMeshes; n++)
3127 const int numMeshes =
_meshes.size();
3128 for (
int n=0; n<numMeshes; n++)
3138 for(
int c=0;c<cellCount;c++)
3142 for(
int k=0;k<klen;k++)
3146 for(
int m=0;m<numModes;m++)
3149 e0Array[cellIndex]=mode.
calce0(Tlat);
3160 const int numMeshes =
_meshes.size();
3162 for (
int n=0; n<numMeshes; n++)
3181 const int cellTotCount=coarserCells.
getCount();
3183 for(
int c=0;c<cellCount;c++)
3185 const int fineCount=CoarserToFiner.
getCount(c);
3186 for(
int fc=0;fc<fineCount;fc++)
3189 const int finerCell=CoarserToFiner(c,fc);
3192 for(
int k=0;k<klen;k++)
3196 for(
int m=0;m<numModes;m++)
3198 const T correction=coarserArray[coarserCellIndex]-injArray[coarserCellIndex];
3199 finerArray[finerCellIndex]+=correction;
3207 for(
int c=cellCount;c<cellTotCount;c++)
3209 const int f=coarseCellFaces(c,0);
3212 const int fineCount=CoarserToFiner.
getCount(c);
3213 for(
int fc=0;fc<fineCount;fc++)
3215 const int finerCell=CoarserToFiner(c,fc);
3220 for(
int k=0;k<klen;k++)
3224 for(
int m=0;m<numModes;m++)
3226 const T correction=coarserArray[coarserCellIndex]-injArray[coarserCellIndex];
3227 finerArray[finerCellIndex]+=correction;
3241 for(
int c=0;c<cellCount;c++)
3243 const int fineCount=CoarserToFiner.
getCount(c);
3244 const T correction=coarserArrayM[c]-injArrayM[c];
3246 for(
int fc=0;fc<fineCount;fc++)
3247 finerArrayM[CoarserToFiner(c,fc)]+=correction;
3254 const int numMeshes=
_meshes.size();
3255 for(
int n=0;n<numMeshes;n++)
3260 const int numcells = cells.
getCount();
3265 for(
int c=0;c<numcells;c++)
3274 const T absTol=
_options.absTolerance;
3275 const int show=
_options.showResidual;
3277 while((niters<iters) && (
_residual>absTol))
3283 cout<<
"Iteration:"<<niters<<
" Residual:"<<
_residual<<endl;
3295 const int n=mesh.
getID();
3298 const T DK3=kspace.
getDK3();
3300 const T hbar=6.582119e-16;
3305 if (fg.
id == faceGroupId)
3308 const int nFaces = faces.
getCount();
3314 for(
int f=0; f<nFaces; f++)
3317 const int c1=faceCells(f,1);
3323 for(
int m=0;m<modenum;m++)
3328 const T vgdotAn=An[0]*vg[0]+An[1]*vg[1]+An[2]*vg[2];
3329 r += eArray[cellIndex]*vgdotAn*(dk3/DK3);
3342 MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &tempR, one, MPI::DOUBLE, MPI::SUM);
3347 throw CException(
"getHeatFluxIntegral: invalid faceGroupID");
3355 const int n=mesh.
getID();
3358 const T DK3=kspace.
getDK3();
3360 const T hbar=6.582119e-16;
3374 const int c1=faceCells(f,1);
3375 const int c0=faceCells(f,0);
3382 for(
int m=0;m<modenum;m++)
3387 const T vgdotAn=An[0]*vg[0]+An[1]*vg[1]+An[2]*vg[2];
3389 r += eArray[cellIndex0]*vgdotAn*(dk3/DK3);
3391 r += eArray[cellIndex]*vgdotAn*(dk3/DK3);
3403 const int n=mesh.
getID();
3418 if (fg.
id == faceGroupId)
3421 const int nFaces = faces.
getCount();
3427 for(
int f=0; f<nFaces; f++)
3430 const int c1=faceCells(f,1);
3432 for(
int binIndx=0;binIndx<binNos;binIndx++)
3443 T vgdotAn=vg[0]*An[0]+vg[1]*An[1]+vg[2]*An[2];
3446 q[binIndx]+= eArray[cellIndex]*vgdotAn*dk3;
3456 throw CException(
"getHeatFluxIntegral: invalid faceGroupID");
3463 const int n=mesh.
getID();
3471 const T hbar=6.582119e-16;
3476 if (fg.
id == faceGroupId)
3479 const int nFaces = faces.
getCount();
3485 for(
int f=0; f<nFaces; f++)
3488 const int c1=faceCells(f,1);
3494 for(
int m=0;m<modenum;m++)
3500 const T vgdotAn=An[0]*vg[0]+An[1]*vg[1]+An[2]*vg[2];
3501 q[index]+= eArray[cellIndex]*vgdotAn*dk3;
3520 if (fg.
id == faceGroupId)
3523 const int nFaces = faces.
getCount();
3525 const TArray& faceArea=
dynamic_cast<const TArray&
>(areaMagField[faces]);
3527 for(
int f=0; f<nFaces; f++)
3536 throw CException(
"getwallArea: invalid faceGroupID");
3548 if (fg.
id == faceGroupId)
3551 const int nFaces = faces.
getCount();
3554 for(
int f=0; f<nFaces; f++)
3565 MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &tempR, one, MPI::DOUBLE, MPI::SUM);
3568 MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &tempR, one, MPI::DOUBLE, MPI::SUM);
3571 MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &tempR, one, MPI::DOUBLE, MPI::SUM);
3576 throw CException(
"getwallArea: invalid faceGroupID");
3583 const int n=mesh.
getID();
3590 for(
int k=0;k<len;k++)
3594 for(
int m=0;m<modes;m++)
3598 const TArray& eArray=
dynamic_cast<const TArray&
>(eField[cells]);
3599 (*vals)[count]=eArray[cell];
3608 const int numMeshes =
_meshes.size();
3609 for (
int n=0; n<numMeshes; n++)
3614 const int numcells=cells.
getCount();
3618 for(
int k=0;k<len;k++)
3622 for(
int m=0;m<modes;m++)
3627 for(
int c=0;c<numcells;c++)
3628 eArray[c]=mode.
calce0(Tl[c]);
3643 const int numMeshes =
_meshes.size();
3648 for (
int n=0; n<numMeshes; n++)
3652 const int numcells=cells.
getCount();
3655 for(
int c=0;c<numcells;c++)
3666 for (
int n=0; n<numMeshes; n++)
3675 for(
int c=0;c<selfcells;c++)
3677 T factor=(coords[c][0]-xmin)/(xmax-xmin);
3678 Tl[c]=T1+factor*(T2-T1);
3687 const int numMeshes=
_meshes.size();
3688 for (
int n=0;n<numMeshes;n++)
3692 throw CException(
"Have not set the Kspace for this Mesh!!");
3696 const int numcells=cells.
getCount();
3698 const int modeCount=FieldVec.size();
3702 for(
int m=0;m<modeCount;m++)
3705 Field& modeField=*FieldVec[m];
3706 TArray& modeTemp=
dynamic_cast<TArray&
>(modeField[cells]);
3707 for(
int c=0;c<numcells;c++)
3709 for(
int k=0;k<numK;k++)
3714 eSum[c]+=kspace.
gete(c,index)*dk3;
3717 for(
int c=0;c<numcells;c++)
3726 const int numMeshes=
_meshes.size();
3727 for (
int n=0;n<numMeshes;n++)
3731 throw CException(
"Have not set the Kspace for this Mesh!!");
3736 const int numcells=cells.
getCount();
3742 for(
int b=0;b<bandCount;b++)
3745 shared_ptr<Field> bandField(
new Field(
"bandTemp"));
3747 bandField->addArray(cells,Tptr);
3748 FieldVecPtr->push_back(bandField);
3753 for(
int c=0;c<numcells;c++)
3757 const int k=kpts[i];
3758 const int m=mpts[i];
3762 eSum[c]+=kspace.
gete(c,index)*dk3;
3765 for(
int c=0;c<numcells;c++)
3766 bandTemp[c]=kspace.
calcBandTemp(TL[c],eSum[c],kpts,mpts);
3774 const int numMeshes=
_meshes.size();
3775 for (
int n=0;n<numMeshes;n++)
3779 throw CException(
"Have not set the Kspace for this Mesh!!");
3781 const T DK3=kspace.
getDK3();
3784 const int numcells=cells.
getCount();
3792 for(
int c=0;c<numcells;c++)
3795 for(
int k=0;k<numK;k++)
3800 for(
int m=0;m<numM;m++)
3802 eSum[c]+=kspace.
gete(c,index)*(dk3/DK3);
3808 for(
int b=0;b<bandCount;b++)
3810 shared_ptr<Field> bandField(
new Field(
"bandRelEnergy"));
3812 bandField->addArray(cells,Tptr);
3813 FieldVecPtr->push_back(bandField);
3818 for(
int c=0;c<numcells;c++)
3823 const int k=kpts[i];
3824 const int m=mpts[i];
3828 cellSum+=kspace.
gete(c,index)*(dk3/DK3);
3830 bandEn[c]=cellSum/eSum[c];
3839 const int numMeshes=
_meshes.size();
3840 const T eVtoJoule=1.60217646e-19;
3841 for (
int n=0;n<numMeshes;n++)
3845 throw CException(
"Have not set the Kspace for this Mesh!!");
3849 const int numcells=cells.
getCount();
3851 const T DK3=kspace.
getDK3();
3857 for(
int m=0;m<modeCount;m++)
3859 shared_ptr<Field> modeField(
new Field(
"mode"));
3863 modeField->addArray(cells,qptr);
3864 FieldVecPtr->push_back(modeField);
3866 for(
int c=0;c<numcells;c++)
3868 for(
int k=0;k<numK;k++)
3873 q[c]+=mode.
getv()*(dk3/DK3)*kspace.
gete(c,index)*eVtoJoule;
3874 Q[c]+=mode.
getv()*(dk3/DK3)*kspace.
gete(c,index)*eVtoJoule;
3888 const int numMeshes=
_meshes.size();
3889 const T eVtoJoule=1.60217646e-19;
3890 for (
int n=0;n<numMeshes;n++)
3894 throw CException(
"Have not set the Kspace for this Mesh!!");
3898 const int numcells=cells.
getCount();
3900 const T DK3=kspace.
getDK3();
3906 for(
int b=0;b<bandCount;b++)
3908 shared_ptr<Field> bandField(
new Field(
"BandFlux"));
3912 bandField->addArray(cells,qptr);
3913 FieldVecPtr->push_back(bandField);
3916 for(
int c=0;c<numcells;c++)
3920 const int k=kpts[i];
3921 const int m=mpts[i];
3925 q[c]+=mode.
getv()*(dk3/DK3)*kspace.
gete(c,index)*eVtoJoule;
3937 const int numMeshes=
_meshes.size();
3938 TArray meshVols(numMeshes);
3941 T interfaceArea(0.);
3942 T interfaceAreaX(0.);
3943 T interfaceAreaY(0.);
3944 T interfaceAreaZ(0.);
3945 int interfaceFaces(0);
3947 for (
int n=0;n<numMeshes;n++)
3954 meshVols[n]+=vol[c];
3956 totalVol+=meshVols[n];
3963 if(
_bcMap[fg.
id]->bcType ==
"Interface")
3966 const int numFaces=faces.
getCount();
3969 dynamic_cast<const TArray&
>(AreaMagField[faces]);
3973 interfaceFaces+=numFaces;
3975 for(
int f=0;f<numFaces;f++)
3977 interfaceArea+=AreaMag[f];
3978 interfaceAreaX+=
fabs(AreaDir[f][0]);
3979 interfaceAreaY+=
fabs(AreaDir[f][1]);
3980 interfaceAreaZ+=
fabs(AreaDir[f][2]);
3994 for (
int n=0;n<numMeshes;n++)
3999 cout<<
"Mesh: "<<n<<endl;
4002 cout<<
"Mesh Volume: "<<meshVols[n]<<endl;
4006 cout<<
"Total Volume: "<<totalVol<<endl;
4007 cout<<
"Interface Area: "<<interfaceArea<<endl;
4008 cout<<
"Interface Area (X): "<<interfaceAreaX<<endl;
4009 cout<<
"Interface Area (Y): "<<interfaceAreaY<<endl;
4010 cout<<
"Interface Area (Z): "<<interfaceAreaZ<<endl;
4011 cout<<
"Area/Volume: "<<interfaceArea/totalVol<<endl;
4012 cout<<
"Volume/Area: "<<totalVol/interfaceArea<<endl;
4013 cout<<
"Interface Face Count: "<<interfaceFaces<<endl;
4014 return interfaceArea/totalVol;
4023 const int numMeshes = meshes.size();
4024 shared_ptr<Field> colorFieldPtr(
new Field(
"Colors"));
4026 Field& colorField=*colorFieldPtr;
4027 for (
int n=0; n<numMeshes; n++)
4029 const Mesh& mesh=*meshes[n];
4032 const int cellTotCount=cells.
getCount();
4036 colorField.
addArray(cells, colorPtr);
4037 TArray& colorArray=(*colorPtr);
4040 for(
int c=0;c<cellCount;c++)
4043 const int neibs=cellCells.
getCount(c);
4045 while(colorArray[c]==-1)
4050 for(
int j=0;j<neibs;j++)
4052 if(color==colorArray[cellCells(c,j)])
4062 colorArray[c]=color;
4081 shared_ptr<Field> field0ptr(
new Field(
"plotColor"));
4083 Field& field0=*field0ptr;
4086 const int numMeshes =
_meshes.size();
4087 for (
int n=0; n<numMeshes; n++)
4092 const int cellTotCount=cells.
getCount();
4094 TArray& colorArray=
dynamic_cast<TArray&
>(colorField[cells]);
4097 (*colorPtr)=colorArray;
4105 shared_ptr<Field> fieldptr(
new Field(
"plotColor"));
4107 Field& field=*fieldptr;
4113 const int numMeshes =
_meshes.size();
4114 for(
int n=0;n<numMeshes;n++)
4117 const Mesh& coarseMesh=*coarseMeshes[n];
4120 const int finestCellTotCount=finestCells.
getCount();
4125 TArray& plotColorArray=*plotColorPtr;
4126 field.
addArray(finestCells, plotColorPtr);
4128 TArray& colorArray=
dynamic_cast<TArray&
>(colorField[coarseCells]);
4130 for(
int c=0;c<finestCellCount;c++)
4131 plotColorArray[c]=colorArray[finestToCoarse(c,0)];
4141 const int numMeshes =
_meshes.size();
4142 for (
int n=0; n<numMeshes; n++)
4155 for(
int lvl=2;lvl<
_options.maxLevels;lvl++)
4165 FineToCoarseNew=FineToCoarseOld->multiply(*FineToCoarseNew,
true);
4167 FineToCoarseOld=FineToCoarseNew;
4188 const int fin=off+cnt;
4190 if(f0<fin && f0>=off)
4191 if(f1<fin && f1>=off)
4199 const int numMeshes =
_meshes.size();
4202 for (
int n=0; n<numMeshes; n++)
4209 for(
int c=0;c<numcells;c++)
4220 const int numMeshes =
_meshes.size();
4221 for (
int n=0; n<numMeshes; n++)
4232 for(
int c=0;c<numcells;c++)
4253 MPI::COMM_WORLD.Allreduce(MPI::IN_PLACE, &tempResid, one, MPI::DOUBLE, MPI::SUM);
ArrayBase * modewiseHeatFluxIntegral(const Mesh &mesh, const int faceGroupId)
KSConnectivity< T > TKConnectivity
Tkspace & getKspace(const int i)
shared_ptr< Reflection > Reflptr
const FaceGroupList & getBoundaryFaceGroups() const
pair< Reflection, Reflection > Refl_pair
int getCount(const int i) const
const FaceGroup & getInteriorFaceGroup() const
ArrayBase & getLatticeTemp(const Mesh &mesh)
void setFASArray(TArrPtr FASPtr)
void NewtonSolve(T &guess, const T e_sum)
shared_ptr< FaceGroup > FaceGroupPtr
T updateResid(const bool addFAS)
void syncLocal(const StorageSite &site)
vector< IntArrPtr > MeshICmap
ArrayBase * binwiseHeatFluxIntegral(const Mesh &mesh, const int faceGroupId)
const CRConnectivity & getConnectivity(const StorageSite &from, const StorageSite &to) const
int FinishCoarseMesh(const MeshList &inMeshes, GeomFields &inGeomFields, MeshList &outMeshes, IntArray &CoarseCounts, map< const StorageSite *, IntArray * > &PreFacePairMap, IntArray &coarseGhost)
void findSpecs(const Tvec n, const int m, const int k, Refl_pair &refls)
shared_ptr< TCOMET > TCOMETPtr
shared_ptr< BCcellArray > BCellPtr
void COMETSolveFull(const int dir, const int level)
COMETModel(const MeshList &meshes, const int level, GeomFields &geomFields, MacroFields ¯oFields, Quadrature< T > &quad, const int ibm=0, GeomFields *finestGeomFields=NULL, const MeshList *finestMeshes=NULL, MacroFields *finestMacroFields=NULL)
std::map< int, COMETBC< T > * > COMETBCMap
void updateTau(const int c, const T Tl)
void coarsenInterfaceCells(COMETIC< T > &ic, IntArray &coarseCounts, GeomFields &inGeomFields, const MeshList &inMeshes)
shared_ptr< TArray > TArrptr
void makeCellColors(const int level)
void setScatterProcID(int proc_id)
T getAverageTemperature()
bool COMETfindCommonFaces(StorageSite &faces, StorageSite &otherFaces, const GeomFields &geomFields)
shared_ptr< MeshList > MshLstPtr
NumTypeTraits< T >::T_Scalar T_Scalar
GeomFields & getGeomFields()
void setTauArray(TArrPtr TauPtr)
void makeCoarseCoeffs(const IClist &fineList, IClist &coarseList, MeshList &coarseMeshes)
Tkvol & getkvol(int n) const
pair< const StorageSite *, const StorageSite * > SSPair
Tmode & getmode(int n) const
void seteArray(TArrPtr ePtr)
const StorageSite & createInteriorFaceGroup(const int size)
map< const StorageSite *, StorageSite * > SiteMap
VectorT3 getWallAreaVector(const Mesh &mesh, const int faceGroupId)
shared_ptr< pmode< T > > Mode_ptr
void MakeNewKspaces(TkspList &inList, TkspList &outList)
const FaceGroup & getFaceGroup(const int fgId) const
int correctSingleNeighbor(const int m, const Mesh &mesh, GeomFields &inGeomFields, int coarseCount, map< const StorageSite *, IntArray * > PreFacePairMap)
vector< BCellPtr > BCcellList
T calcLatTemp(const int c)
void MakeInteriorCoarseMesh(const MeshList &inMeshes, GeomFields &inGeomFields, MeshList &outMeshes, IntArray &CoarseCounts, map< const StorageSite *, IntArray * > &PreFacePairMap, IntArray &CoarseGhost, SiteMap &siteMap)
const CommonMap & getCommonMap() const
T HeatFluxIntegralFace(const Mesh &mesh, const int f)
vector< shared_ptr< Field > > FieldVector
COMETModelOptions< T > _options
MeshKspaceMap & getMKMap()
void setCount(const int selfCount, const int nGhost=0)
void doSweeps(const int sweeps)
void setBCMap(COMETBCMap *bcMap)
void setConnectivity(const StorageSite &rowSite, const StorageSite &colSite, shared_ptr< CRConnectivity > conn)
void setLocalScatterMaps(const Mesh &mesh0, StorageSite &faces0, const Mesh &mesh1, StorageSite &faces1)
Array< int > * FineToCoarse1
T & gete(const int cell, const int count)
COMETModelOptions< T > TCModOpts
MeshICmap & getMeshICmap()
const StorageSite & createBoundaryFaceGroup(const int size, const int offset, const int id, const string &boundaryType)
void applyTemperatureWallFine(FloatValEvaluator< T > &bTemp) const
map< int, Refl_pair > Refl_Map
map< const StorageSite *, StorageSite * > SiteMap
shared_ptr< BCfaceArray > BfacePtr
FloatVal< T > getVal(const string varName) const
void setFinerLevel(TCOMET *fl)
TCOMET * getModelPointer(const int level)
void updateResid(const COMETIC< T > &ic, const bool plusFAS)
ArrayBase * getValueArray(const Mesh &mesh, const int cell)
shared_ptr< GeomFields > GeoFldsPtr
void syncGhostCoarsening(const MeshList &inMeshes, GeomFields &inGeomFields, MeshList &outMeshes, ScatGathMaps &coarseScatMaps, ScatGathMaps &coarseGathMaps, IntArray &coarseSizes, IntArray &CoarseGhost)
Tangent sqrt(const Tangent &a)
const CRConnectivity & getAllFaceCells() const
void syncGhostCoarsening(const MeshList &inMeshes, GeomFields &inGeomFields, MeshList &outMeshes)
const CRConnectivity & getCellFaces() const
int getSelfFaceID(const int mesh)
void makeDMMcoeffs(COMETIC< T > &ic)
map< int, int > MeshKspaceMap
void applyTemperatureBoundaries()
void setResArray(TArrPtr ResPtr)
Tmode::Reflection Reflection
COMETModelOptions< T > & getOptions()
void applyTemperatureWallCoarse(FloatValEvaluator< T > &bTemp) const
Array< VectorT3 > VectorT3Array
int getGlobalIndex(const int cell, const int count)
const StorageSite & createInterfaceGroup(const int size, const int offset, const int id)
vector< BfacePtr > BCfaceList
int getScatterProcID() const
int getGatherProcID() const
void updateOtherGhost(const COMETIC< T > &ic, const int Mid0, const bool plusFAS)
map< int, TKClist > FgTKClistMap
void setStraightLine(const T T1, const T T2)
shared_ptr< StorageSite > SSPtr
shared_ptr< IntArray > IntArrPtr
void setFinestLevel(TCOMET *finest)
map< const StorageSite *, shared_ptr< Array< int > > > CommonMap
IntArray & getMIndices(const int fBin)
T calcModeTemp(T guess, const T e_sum, const T m)
const StorageSite & getFaces() const
const CRConnectivity & getCellCells() const
const StorageSite & getCells() const
MeshKspaceMap _MeshKspaceMap
void makeCoarseScatGath(const MeshList &inMeshes, SiteMap &siteMap, ScatGathMaps &coarseScatMaps, ScatGathMaps &coarseGathMaps)
FieldVectorMap BandRelEnergy
void makeNoInterfaceCoeffs(COMETIC< T > &ic)
int getCountLevel1() const
void makeFinestToCoarseConn()
vector< COMETIC< T > * > IClist
shared_ptr< CRConnectivity > CRPtr
void setCoarserLevel(TCOMET *cl)
const ScatterMap & getScatterMap() const
const MeshList & getMeshList()
void addArray(const StorageSite &, shared_ptr< ArrayBase > a)
const CRConnectivity & getFaceCells(const StorageSite &site) const
map< const StorageSite *, shared_ptr< Array< int > > > ScatterMap
const vector< int > & getData() const
void COMETSolveFine(const int dir, const int level)
DensityOfStates< T > * getDOSptr()
shared_ptr< VectorT3Array > VT3Ptr
Tangent fabs(const Tangent &a)
void setGatherProcID(int proc_id)
shared_ptr< CRConnectivity > multiply(const CRConnectivity &b, const bool implicitDiagonal) const
void CopyKspace(Tkspace ©FromKspace)
COMETModel(const MeshList &meshes, const int level, GeomFields &geomFields, TkspList &kspaces, PhononMacro ¯o)
const GatherMap & getGatherMap() const
void COMETSolveCoarse(const int dir, const int level)
FieldVector plottingCellColors
FieldVectorMap BandTemperatures
shared_ptr< CRConnectivity > getTranspose() const
vector< Tkspace * > TkspList
Vector< T_Scalar, 3 > VectorT3
pair< T, int > Reflection
Array< int > * FineToCoarse0
void initializeTemperatureBoundaries()
FieldVectorMap BranchFlux
IntArray & getKIndices(const int fBin)
FieldVectorMap BranchTemperatures
map< const StorageSite *, shared_ptr< Array< int > > > GatherMap
const FaceGroupList & getInterfaceGroups() const
NumTypeTraits< T >::T_Scalar T_Scalar
int coarsenInterior(const int m, const Mesh &mesh, GeomFields &inGeomFields, int &coarseCount)
map< int, COMETBC< T > * > COMETBCMap
void smooth(const int num, const StorageSite &solidFaces)
Field & getColorField(int level)
T calcBandTemp(const T guess, const T eSum, const IntArray &kpts, const IntArray &mpts)
void setSourceArray(TArrPtr SPtr)
Tmode::Refl_pair Refl_pair
map< SSPair, shared_ptr< Array< int > > > ScatGathMaps
T HeatFluxIntegral(const Mesh &mesh, const int faceGroupId)
shared_ptr< Tkspace > KspPtr
void sete0Array(TArrPtr e0Ptr)
T getWallArea(const Mesh &mesh, const int faceGroupId)
shared_ptr< Mesh > MeshPtr
shared_ptr< PhononMacro > PMacroPtr
void advance(const int iters)
void makePlotColors(const int level)
void MakeCoarseModel(TCOMET *finerModel)
void doSweeps(const int sweeps, const int num)
vector< Mesh * > MeshList
void setInjArray(TArrPtr InjPtr)
bool sameFaceGroup(const Mesh &mesh, const int f0, const int f1)
const TKClist & getKConnectivity(const int fgid) const
void findResidCoarse(const bool plusFAS)