46 #include <Xyce_config.h>
77 #include <N_ERH_ErrorMgr.h>
101 meshScaledFlag (false),
116 iRecentCellLookup(0),
119 meshFileName (
"internal"),
120 externalMeshFlag (false),
129 adjInfoAllocFlag(false),
130 sgplotLevel(sgplotLevel1),
131 useDefaultLabels(true)
146 meshFileName (right.meshFileName),
147 externalMeshFlag (right.externalMeshFlag),
154 xRatio (right.xRatio),
155 yRatio (right.yRatio),
157 meshScaledFlag (right.meshScaledFlag),
159 invVol (right.invVol),
160 surfArea (right.surfArea),
161 circum (right.circum),
162 invCircum (right.invCircum),
164 numNodes (right.numNodes),
165 numEdges (right.numEdges),
166 numCells (right.numCells),
167 numLabels (right.numLabels),
168 numRegLabels (right.numRegLabels),
169 numBndryNodes (right.numBndryNodes),
170 maxNodeNN (right.maxNodeNN),
171 iRecentCellLookup(right.iRecentCellLookup),
172 cylGeom (right.cylGeom),
173 dopingSet (right.dopingSet),
174 mNodeVector (right.mNodeVector),
175 mEdgeVector (right.mEdgeVector),
176 mCellVector (right.mCellVector),
177 mLabelVector (right.mLabelVector),
178 dopingVector (right.dopingVector),
179 xVector (right.xVector),
180 yVector (right.yVector),
181 visitCellFlagVec (right.visitCellFlagVec),
182 mLabelMap (right.mLabelMap),
185 devOptions_ (right.devOptions_),
186 afVisitedVec (right.afVisitedVec),
187 adjInfoAllocFlag (right.adjInfoAllocFlag),
188 sgplotLevel (right.sgplotLevel),
201 for (i=0;i<
ixMax+10;++i)
205 for (j=0;j<
iyMax+10;++j)
219 for (j=0;j<numNodes+10;++j)
229 for (i=0;i<
ixMax+10;++i)
232 for (j=0;j<
iyMax+10;++j)
314 for (i=0;i<
ixMax+10;++i)
318 for (j=0;j<
iyMax+10;++j)
332 for (j=0;j<numNodes+10;++j)
342 for (i=0;i<
ixMax+10;++i)
345 for (j=0;j<
iyMax+10;++j)
378 for (i=0;i<
ixMax+10;++i)
396 for (i=0;i<
ixMax+10;++i)
428 bool bsuccess =
true;
442 bsuccess = bsuccess && tmpBool;
450 bsuccess = bsuccess && tmpBool;
454 #ifdef Xyce_DEBUG_DEVICE
479 FILE *nFile = fopen(meshFileName_tmp.c_str(),
"r");
483 std::string msg(
"PDE_2DMesh::readSGFMeshFile - ");
484 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg + meshFileName_tmp +
489 fread(&meshhead,
sizeof(
MESHHEAD),1,nFile);
493 fseek(nFile, lOffset, SEEK_CUR);
497 fread(&cLabel,
sizeof(UINT),1,nFile);
502 #ifdef Xyce_DEBUG_DEVICE
504 Xyce::dout() <<
"About to read label lists: cLabel = " << cLabel << std::endl;
507 for(i = 0; i < cLabel; ++i)
512 fread(&xlatlabel,
sizeof(
XLATLABEL),1,nFile);
518 #ifdef Xyce_DEBUG_DEVICE
521 Xyce::dout() <<
"i = " << i ;
522 Xyce::dout() <<
" iIndex = " << xLabel.
iIndex;
523 Xyce::dout() <<
" uType = " << xLabel.
uType;
524 Xyce::dout() <<
" cNode = " << xLabel.
cNode;
525 Xyce::dout() <<
" label name = " << xLabel.
name << std::endl;
531 for (j=0;j<xlatlabel.
cNode; ++j)
534 fread(&au,
sizeof(UINT),1,nFile);
540 ExtendedString tmpName = xLabel.
name;
557 fread(&cArray,
sizeof(UINT),1,nFile);
558 #ifdef Xyce_DEBUG_DEVICE
560 Xyce::dout() <<
"About to read in the arrays. cArray = " << cArray << std::endl;
565 for(i = 0; i < 2; ++i)
569 ExtendedString tmpName(szArrayName);
571 #ifdef Xyce_DEBUG_DEVICE
572 Xyce::dout() <<
"i=" <<i<<
" name = " << tmpName << std::endl;
578 for (j=0;j<meshhead.
cNode; ++j)
580 fread(&xtmp,
sizeof(
double),1,nFile);
584 else if (tmpName ==
"Y")
587 for (j=0;j<meshhead.
cNode; ++j)
589 fread(&xtmp,
sizeof(
double),1,nFile);
595 #ifdef Xyce_DEBUG_DEVICE
598 Xyce::dout() <<
"Done reading x and y arrays.";
599 Xyce::dout() <<
" Reading the others, if they exist." << std::endl;
606 #ifdef Xyce_DEBUG_DEVICE
608 Xyce::dout() <<
"reading extra arrays..." << std::endl;
610 for(i = 2; i < meshhead.
cArray; ++i)
614 ExtendedString tmpName(szArrayName);
619 for (j=0;j<meshhead.
cNode; ++j)
621 fread(&xtmp,
sizeof(
double),1,nFile);
628 for (j=0;j<meshhead.
cNode; ++j)
629 fread(&xtmp,
sizeof(
double),1,nFile);
636 fread(&cNodes,
sizeof(UINT),1,nFile);
643 #ifdef Xyce_DEBUG_DEVICE
645 Xyce::dout() <<
"About to read the nodes. cNodes = " << cNodes << std::endl;
648 for (i=0;i<cNodes;++i)
651 fread(&sgfNode,
sizeof(
NODE),1,nFile);
661 fread(&cEdge,
sizeof(UINT),1,nFile);
665 #ifdef Xyce_DEBUG_DEVICE
667 Xyce::dout() <<
"About to read the edges. cEdge = " << cEdge << std::endl;
670 for (i=0; i< cEdge; ++i)
673 fread(&sgfEdge,
sizeof(
EDGE),1,nFile);
675 int inode1 = sgfEdge.
inodeA;
676 int inode2 = sgfEdge.
inodeB;
695 fread(&cTriangle,
sizeof(UINT),1,nFile);
699 #ifdef Xyce_DEBUG_DEVICE
701 Xyce::dout() <<
"About to read the cells. numCells = " <<
numCells << std::endl;
703 for (i=0;i<cTriangle;++i)
706 fread(&Tri,
sizeof(
TRI),1,nFile);
726 fread(&cAdj,
sizeof(UINT),1,nFile);
729 #ifdef Xyce_DEBUG_DEVICE
731 Xyce::dout() <<
"About to read the adjacency info. cAdj = " << cAdj << std::endl;
734 double rDistScale = 1.0;
735 double X0_1 = rDistScale;
736 double X0_2 = rDistScale * X0_1;
737 double X0_3 = rDistScale * X0_2;
739 double ScaleILEN, ScaleAREA, ScaleELEN = X0_1;
742 #ifdef Xyce_DEBUG_DEVICE
745 if (meshhead.
fCylGeom) Xyce::dout() <<
"Cylindrical Geometry\n\n";
746 else Xyce::dout() <<
"Cartesian Geometry\n\n";
773 for(i = 0; i < cAdj; ++i)
776 fread(&inode,
sizeof(
int),1,nFile);
780 nodeInfo.
Area /= ScaleAREA;
789 for (j=0;j<cNeighbor;++j)
791 fread( &EdgeInfo,
sizeof(
EDGEINFO),1,nFile);
792 mNodeVector[inode].edgeInfoVector.push_back(EdgeInfo);
795 for(j = 0; j < cNeighbor; ++j)
800 mNodeVector[inode].edgeInfoVector[j].ilen /= ScaleILEN;
801 mNodeVector[inode].edgeInfoVector[j].elen /= ScaleELEN;
802 mNodeVector[inode].edgeInfoVector[j].Area1 /= ScaleAREA;
803 mNodeVector[inode].edgeInfoVector[j].Area2 /= ScaleAREA;
805 int iedge =
mNodeVector[inode].edgeInfoVector[j].iedge;
838 FILE *nFile = fopen(meshFileName_tmp.c_str(),
"w");
840 strcpy(meshhead.
szLogo,
"SGFramework Mesh File Version 1.0\n\x1a");
841 strcpy(meshhead.
szSign,
"@~!__MESH__!~@");
857 fwrite( &meshhead,
sizeof(
MESHHEAD), 1, nFile);
861 fwrite( &meshhead.
cConstant,
sizeof(UINT), 1, nFile);
864 fwrite( &meshhead.
cLabel,
sizeof(UINT), 1, nFile);
865 for (i=0;i<meshhead.
cLabel;++i)
873 fwrite(&xlabel,
sizeof(
XLATLABEL) ,1,nFile);
877 for (j=0;j<xlabel.
cNode;++j)
880 fwrite(&istuf,
sizeof(UINT), 1, nFile);
891 fwrite( &cArray,
sizeof(UINT),1,nFile);
893 strcpy(szCoord1,
"X");
894 fwrite( szCoord1, (
LEN_IDENT+1), 1, nFile);
898 fwrite( &(
xVector[i]),
sizeof(
double), 1, nFile);
902 strcpy(szCoord2,
"Y");
903 fwrite( szCoord2, (
LEN_IDENT+1), 1, nFile);
906 fwrite( &(
yVector[i]),
sizeof(
double), 1, nFile);
912 fwrite( &meshhead.
cNode,
sizeof(UINT), 1, nFile);
913 for (i=0;i<meshhead.
cNode;++i)
917 fwrite(&n1,
sizeof(
NODE), 1, nFile);
921 fwrite( &meshhead.
cEdge,
sizeof(UINT), 1, nFile);
922 for (i=0;i<meshhead.
cEdge;++i)
928 fwrite( &e1,
sizeof(
EDGE), 1, nFile);
932 fwrite(&meshhead.
cTriangle,
sizeof(UINT),1,nFile);
942 if (tmp < 0) t1.
uLabel = -1u;
943 else t1.
uLabel =
static_cast<unsigned int>(tmp);
955 fwrite(&t1,
sizeof(
TRI), 1, nFile);
961 fwrite(&numNodes,
sizeof(UINT), 1, nFile);
965 fwrite(&inode,
sizeof(UINT),1,nFile);
977 fwrite(&edgeinfo,
sizeof(
EDGEINFO),1,nFile);
1007 std::string & outputMeshFileName,
1008 std::map<std::string,PDE_2DElectrode*> & elMap,
1011 bool bsuccess =
true;
1012 bool tmpBool =
true;
1016 externalMeshFlag =
false;
1018 meshFileName = outputMeshFileName;
1020 bsuccess = setupInternalMesh (nx,ny,xlength,ylength);
1025 if ( !(elMap.empty()) )
1027 tmpBool = errorCheckElectrodes (numElectrodes, elMap);
1028 bsuccess = bsuccess && tmpBool;
1031 if ( useDefaultLabels )
1033 tmpBool = setupDefaultLabels(numElectrodes);
1034 bsuccess = bsuccess && tmpBool;
1038 tmpBool = setupInternalLabels(numElectrodes, elMap);
1039 bsuccess = bsuccess && tmpBool;
1045 tmpBool = cellNodes();
1046 bsuccess = bsuccess && tmpBool;
1051 tmpBool = setupGeometry ();
1052 bsuccess = bsuccess && tmpBool;
1054 visitCellFlagVec.resize(numCells,0);
1056 #ifdef Xyce_DEBUG_DEVICE
1057 if (devOptions_->debugLevel > 1)
1063 if (sgplotLevel > 0)
1065 tmpBool = writeSGFMeshFile (outputMeshFileName);
1066 bsuccess = bsuccess && tmpBool;
1091 #ifdef Xyce_DEBUG_DEVICE
1094 Xyce::dout() <<
"In PDE_2DMesh:resizeMesh." << std::endl;
1101 xRatio = xlength/(old_xlength);
1102 yRatio = ylength/(old_ylength);
1105 xMax = xMin + xlength;
1106 yMax = yMin + ylength;
1108 #ifdef Xyce_DEBUG_DEVICE
1111 Xyce::dout() <<
" xMax = " <<
xMax << std::endl;
1112 Xyce::dout() <<
" yMax = " <<
yMax << std::endl;
1131 #ifdef Xyce_DEBUG_DEVICE
1134 Xyce::dout() <<
"\txVec["<<i<<
"] = " <<
xVector[i];
1135 Xyce::dout() <<
"\tyVec["<<i<<
"] = " <<
yVector[i] << std::endl;
1143 #ifdef Xyce_DEBUG_DEVICE
1146 Xyce::dout() <<
"Done with PDE_2DMesh:resizeMesh." << std::endl;
1173 int nx,
int ny,
double xlength,
double ylength)
1183 #ifdef Xyce_DEBUG_DEVICE
1185 Xyce::dout() <<
"In setupInternalMesh"<<std::endl;
1192 dy =
yMax/(
static_cast<double>(iyMax-1));
1196 for (i=0;i<
ixMax+10;++i)
1200 for (j=0;j<iyMax+10;++j)
1210 for (i=0;i<
ixMax;++i)
1212 for (j=0;j<
iyMax;++j)
1215 n1.
x =
dx*(
static_cast<double>(i));
1216 n1.
y =
dy*(
static_cast<double>(j));
1221 if (i==0 || j==0 || i==ixMax-1 || j==iyMax-1)
1234 #ifdef Xyce_DEBUG_DEVICE
1237 Xyce::dout() <<
"\nDone with Node vector" << std::endl;
1246 for (j=0;j<numNodes+10;++j)
1255 for (i=0;i<
ixMax;++i)
1257 for (j=0;j<
iyMax;++j)
1283 #ifdef Xyce_DEBUG_DEVICE
1284 Xyce::dout() <<
" edge1.inodeA = " << edge1.
inodeA;
1285 Xyce::dout() <<
" edge1.inodeB = " << edge1.
inodeB <<std::endl;
1321 #ifdef Xyce_DEBUG_DEVICE
1322 Xyce::dout() <<
" edge2.inodeA = " << edge2.
inodeA;
1323 Xyce::dout() <<
" edge2.inodeB = " << edge2.
inodeB <<std::endl;
1338 #ifdef Xyce_DEBUG_DEVICE
1341 Xyce::dout() <<
"Done with Edge vector" << std::endl;
1348 for (i=0;i<ixMax+10;++i)
1351 for (j=0;j<iyMax+10;++j)
1355 for (i=1; i<
ixMax; ++i)
1357 for (j=1;j<
iyMax;++j)
1371 int inodeA, inodeB, inodeC, inodeD;
1399 #ifdef Xyce_DEBUG_DEVICE
1402 Xyce::dout() <<
"Done with Cell vector" << std::endl;
1409 for (i=1; i<
ixMax; ++i)
1411 for (j=1;j<
iyMax;++j)
1420 #ifdef Xyce_DEBUG_DEVICE
1423 Xyce::dout() <<
"Done with Cell neighbors." << std::endl;
1448 #ifdef Xyce_DEBUG_DEVICE
1451 Xyce::dout() <<
"Done with setupInternalMesh\n";
1477 #ifdef Xyce_DEBUG_DEVICE
1478 Xyce::dout() <<
"In PDE_2DMesh::setupInternalAdjacencyInfo." << std::endl;
1485 int inodeA = edgeTmp.
inodeA;
1486 int inodeB = edgeTmp.
inodeB;
1505 edgeTmp.
ilen *= 0.5;
1509 edgeTmp.
Area2 = 0.0;
1515 #ifdef Xyce_DEBUG_DEVICE
1516 Xyce::dout() <<
"About to do the edgeinfo:" << std::endl;
1519 for (i=0;i<
ixMax;++i)
1521 for (j=0;j<
iyMax;++j)
1528 if (i==0 || i==ixMax-1)
1533 if (j==0 || j==iyMax-1)
1547 eiTmp.
inode = nnTmp;
1548 eiTmp.
iedge = edgeTmp;
1551 mNodeVector[node].edgeInfoVector.push_back(eiTmp);
1559 eiTmp.
inode = nnTmp;
1560 eiTmp.
iedge = edgeTmp;
1563 mNodeVector[node].edgeInfoVector.push_back(eiTmp);
1571 eiTmp.
inode = nnTmp;
1572 eiTmp.
iedge = edgeTmp;
1575 mNodeVector[node].edgeInfoVector.push_back(eiTmp);
1583 eiTmp.
inode = nnTmp;
1584 eiTmp.
iedge = edgeTmp;
1587 mNodeVector[node].edgeInfoVector.push_back(eiTmp);
1594 #ifdef Xyce_DEBUG_DEVICE
1595 Xyce::dout() <<
"Done doing the edgeinfo:" << std::endl;
1614 (
int numElectrodes, std::map<std::string,PDE_2DElectrode*> & elMap)
1616 bool bsuccess =
true;
1619 if (numElectrodes != elMap.size())
1622 std::string msg(
"Number of electrodes and number of nodes are not equal.\n");
1623 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
1634 bool allNotSet =
true;
1635 useDefaultLabels =
false;
1637 std::map<std::string, PDE_2DElectrode*>::iterator mapIter;
1638 std::map<std::string, PDE_2DElectrode*>::iterator mapStart = elMap.begin();
1639 std::map<std::string, PDE_2DElectrode*>::iterator mapEnd = elMap.end();
1641 for ( mapIter = mapStart; mapIter != mapEnd; ++mapIter )
1645 allSet = allSet && (el.
given(
"START") && el.
given(
"END") && el.
given(
"SIDE"));
1646 allNotSet = allNotSet &&
1650 if (!allSet && !allNotSet)
1653 std::string msg(
"Some electrodes have start, end and side specified,\nsome don't. ");
1654 msg +=
"Either specify start, end and side for\nall electrodes, or none.\n";
1655 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
1662 useDefaultLabels =
true;
1695 ExtendedString tmpName =
"SI";
1707 for (i=1;i<
ixMax-1;++i)
1709 for (j=1;j<iyMax-1;++j)
1717 tmpName = xLabel.
name;
1726 if (numberElectrodes==2)
1732 xLabel.
name =
"ANODE";
1741 for (i=0;i<
ixMax;++i)
1748 tmpName = xLabel.
name;
1753 #ifdef Xyce_DEBUG_DEVICE
1756 Xyce::dout() <<
"Right before pushing back the ANODE label." << std::endl;
1759 cout <<
"Node: " << i <<
" = " << xLabel.
mNodeVector[i];
1769 xLabel.
name =
"CATHODE";
1778 for (i=0;i<
ixMax;++i)
1785 tmpName = xLabel.
name;
1790 #ifdef Xyce_DEBUG_DEVICE
1793 Xyce::dout() <<
"Right before pushing back the CATHODE label." << std::endl;
1796 cout <<
"Node: " << i <<
" = " << xLabel.
mNodeVector[i];
1807 xLabel.
name =
"NOFLUX";
1810 xLabel.
cNode = 2*iyMax-2;
1816 for (j=1;j<iyMax-1;++j)
1823 for (j=1;j<iyMax-1;++j)
1830 tmpName = xLabel.
name;
1835 #ifdef Xyce_DEBUG_DEVICE
1838 Xyce::dout() <<
"Right before pushing back the NOFLUX label." << std::endl;
1841 Xyce::dout() <<
"Node: " << i <<
" = " << xLabel.
mNodeVector[i];
1842 Xyce::dout() << std::endl;
1855 for (i=1;i<
ixMax;++i)
1866 for (i=1;i<
ixMax;++i)
1877 for (j=1;j<
iyMax;++j)
1888 for (j=1;j<
iyMax;++j)
1898 else if (numberElectrodes==3)
1925 int iB =
static_cast<int> (0.101 *
static_cast<double>(ixMax-1));
1926 int iC =
static_cast<int> (0.301 *
static_cast<double>(ixMax-1));
1927 int iD =
static_cast<int> (0.401 *
static_cast<double>(ixMax-1));
1928 int iE =
static_cast<int> (0.701 *
static_cast<double>(ixMax-1));
1929 int iF =
static_cast<int> (0.801 *
static_cast<double>(ixMax-1));
1936 xLabel.
name =
"EMITTER";
1939 xLabel.
cNode = iB-iA+1;
1945 for (i=iA;i<iB+1;++i)
1952 tmpName = xLabel.
name;
1960 xLabel.
name =
"BASE";
1963 xLabel.
cNode = iD-iC+1;
1969 for (i=iC;i<iD+1;++i)
1976 tmpName = xLabel.
name;
1984 xLabel.
name =
"COLLECTOR";
1987 xLabel.
cNode = iF-iE+1;
1993 for (i=iE;i<iF+1;++i)
2000 tmpName = xLabel.
name;
2015 xLabel.
name =
"NOFLUX";
2024 for (i=iB+1;i<iC;++i)
2031 for (i=iD+1;i<iE;++i)
2038 for (i=iF+1;i<iG;++i)
2046 for (j=0;j<iyMax-1;++j)
2054 for (j=0;j<iyMax-2;++j)
2062 for (i=0;i<ixMax-1;++i)
2071 tmpName = xLabel.
name;
2084 for (i=iA+1;i<iB+1;++i)
2095 for (i=iC+1;i<iD+1;++i)
2106 for (i=iE+1;i<iF+1;++i)
2118 for (i=iB+1;i<iC+1;++i)
2129 for (i=iD+1;i<iE+1;++i)
2140 for (i=iF+1;i<iG+1;++i)
2151 for (i=1;i<
ixMax;++i)
2162 for (j=1;j<
iyMax;++j)
2173 for (j=1;j<
iyMax;++j)
2184 else if (numberElectrodes==4)
2219 int iB =
static_cast<int> (0.101 *
static_cast<double>(ixMax-1));
2220 int iC =
static_cast<int> (0.151 *
static_cast<double>(ixMax-1));
2221 int iD =
static_cast<int> (0.851 *
static_cast<double>(ixMax-1));
2222 int iE =
static_cast<int> (0.901 *
static_cast<double>(ixMax-1));
2227 #ifdef Xyce_DEBUG_DEVICE
2228 Xyce::dout() <<
"iA = "<< iA << std::endl;
2229 Xyce::dout() <<
"iB = "<< iB << std::endl;
2230 Xyce::dout() <<
"iC = "<< iC << std::endl;
2231 Xyce::dout() <<
"iD = "<< iD << std::endl;
2232 Xyce::dout() <<
"iE = "<< iE << std::endl;
2233 Xyce::dout() <<
"iF = "<< iF << std::endl;
2238 xLabel.
name =
"SOURCE";
2241 xLabel.
cNode = iB-iA+1;
2247 for (i=iA;i<iB+1;++i)
2254 tmpName = xLabel.
name;
2262 xLabel.
name =
"GATE";
2265 xLabel.
cNode = iD-iC+1;
2271 for (i=iC;i<iD+1;++i)
2278 tmpName = xLabel.
name;
2286 xLabel.
name =
"DRAIN";
2289 xLabel.
cNode = iF-iE+1;
2295 for (i=iE;i<iF+1;++i)
2302 tmpName = xLabel.
name;
2311 xLabel.
name =
"SUB";
2314 xLabel.
cNode = iF-iA+1;
2320 for (i=iA;i<iF+1;++i)
2327 tmpName = xLabel.
name;
2338 xLabel.
name =
"NOFLUX";
2341 xLabel.
cNode = (iC-iB-1)+(iE-iD-1)+(iyMax-1)+(iyMax-1);
2347 for (i=iB+1;i<iC;++i)
2354 for (i=iD+1;i<iE;++i)
2362 for (j=1;j<iyMax-1;++j)
2370 for (j=1;j<iyMax-1;++j)
2377 tmpName = xLabel.
name;
2389 for (i=iA+1;i<iB+1;++i)
2400 for (i=iC+1;i<iD+1;++i)
2411 for (i=iE+1;i<iF+1;++i)
2422 for (i=iA+1;i<iF+1;++i)
2433 for (i=iB+1;i<iC+1;++i)
2444 for (i=iD+1;i<iE+1;++i)
2455 for (j=1;j<
iyMax;++j)
2466 for (j=1;j<
iyMax;++j)
2478 #ifdef Xyce_DEBUG_DEVICE
2479 Xyce::dout() <<
"Sorry, the internal mesh generator can't";
2480 Xyce::dout() <<
" handle anything greater than 4 electrodes." << std::endl;
2502 std::map<std::string,PDE_2DElectrode*> & elMap)
2509 ExtendedString tmpName =
"SI";
2521 for (i=1;i<
ixMax-1;++i)
2523 for (j=1;j<iyMax-1;++j)
2531 tmpName = xLabel.
name;
2539 std::vector<int> done;
2542 std::map<std::string, PDE_2DElectrode*>::iterator mapIter;
2543 std::map<std::string, PDE_2DElectrode*>::iterator mapStart =
2545 std::map<std::string, PDE_2DElectrode*>::iterator mapEnd =
2552 for ( mapIter = mapStart; mapIter != mapEnd; ++mapIter )
2558 if (el.
side ==
"top" || el.
side ==
"bottom")
2585 el.
iA =
static_cast<int> (start *
static_cast<double>(ixMax-1));
2586 el.
iB =
static_cast<int> (end *
static_cast<double>(ixMax-1));
2588 if (el.
iA < 0) el.
iA = 0;
2589 if (el.
iA > ixMax-1) el.
iA = ixMax-1;
2590 if (el.
iB < 0) el.
iB = 0;
2591 if (el.
iB > ixMax-1) el.
iB = ixMax-1;
2595 ExtendedString tmpName = el.
name;
2600 xLabel.
name = tmpName;
2601 xLabel.
iIndex = labelIndex; ++labelIndex;
2610 if (el.
side ==
"top")
2614 else if (el.
side ==
"bottom")
2619 for (i=el.
iA;i<el.
iB+1;++i)
2627 tmpName = xLabel.
name;
2633 else if (el.
side ==
"right" || el.
side ==
"left")
2660 el.
iA =
static_cast<int> (start *
static_cast<double>(iyMax-1));
2661 el.
iB =
static_cast<int> (end *
static_cast<double>(iyMax-1));
2663 if (el.
iA < 0) el.
iA = 0;
2664 if (el.
iA > iyMax-1) el.
iA = iyMax-1;
2665 if (el.
iB < 0) el.
iB = 0;
2666 if (el.
iB > iyMax-1) el.
iB = iyMax-1;
2670 ExtendedString tmpName = el.
name;
2675 xLabel.
name = tmpName;
2676 xLabel.
iIndex = labelIndex; ++labelIndex;
2685 if (el.
side ==
"right")
2689 else if (el.
side ==
"left")
2694 for (j=el.
iA;j<el.
iB+1;++j)
2702 tmpName = xLabel.
name;
2710 std::string msg(
"electrode side specification not recognized.\n");
2711 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
2720 xLabel.
name =
"NOFLUX";
2721 xLabel.
iIndex = labelIndex; ++labelIndex;
2725 int NOFLUXIndex = xLabel.
iIndex;
2729 for (j=0;j<
iyMax;++j)
2741 for (j=0;j<
iyMax;++j)
2753 for (i=0;i<
ixMax;++i)
2765 for (i=0;i<
ixMax;++i)
2778 #ifdef Xyce_DEBUG_DEVICE
2781 Xyce::dout() <<
"NOFLUX nodes:" << std::endl;
2782 for (
int nodeIndex=0;nodeIndex<xLabel.
mNodeVector.size();++nodeIndex)
2785 Xyce::dout() <<
"node="<<iNode<<
" x=" <<
xVector[iNode];
2786 Xyce::dout() <<
" y="<<
yVector[iNode] <<std::endl;
2791 tmpName = xLabel.
name;
2801 std::vector<int> edgeDone;
2804 for ( mapIter = mapStart; mapIter != mapEnd; ++mapIter )
2811 for (i=el.
iA+1;i<el.
iB+1;++i)
2822 else if (el.
side==
"bottom")
2825 for (i=el.
iA+1;i<el.
iB+1;++i)
2836 else if (el.
side==
"left")
2839 for (j=el.
iA+1;j<el.
iB+1;++j)
2850 else if (el.
side==
"right")
2853 for (j=el.
iA+1;j<el.
iB+1;++j)
2866 std::string msg(
"electrode side specification not recognized.\n");
2867 N_ERH_ErrorMgr::report(N_ERH_ErrorMgr::DEV_FATAL_0, msg);
2873 for (j=1;j<
iyMax;++j)
2879 if (edgeDone[e1]!=1)
2887 for (j=1;j<
iyMax;++j)
2893 if (edgeDone[e1]!=1)
2901 for (i=1;i<
ixMax;++i)
2907 if (edgeDone[e1]!=1)
2915 for (i=1;i<
ixMax;++i)
2921 if (edgeDone[e1]!=1)
2928 #ifdef Xyce_DEBUG_DEVICE
2931 Xyce::dout() <<
"EDGEs:"<<std::endl;
2933 for (i=1;i<
ixMax;++i)
2939 Xyce::dout() <<
"edge: " << e1;
2941 Xyce::dout() <<
" y(A)="<<
yVector[mEdgeVector[e1].inodeA];
2942 Xyce::dout() <<
" x(B)="<<
xVector[mEdgeVector[e1].inodeB];
2943 Xyce::dout() <<
" y(B)="<<
yVector[mEdgeVector[e1].inodeB];
2944 Xyce::dout() <<
" label = " << mEdgeVector[e1].uLabel;
2945 Xyce::dout() << std::endl;
2947 Xyce::dout() << std::endl;
2950 for (i=1;i<
ixMax;++i)
2956 Xyce::dout() <<
"edge: " << e1;
2958 Xyce::dout() <<
" y(A)="<<
yVector[mEdgeVector[e1].inodeA];
2959 Xyce::dout() <<
" x(B)="<<
xVector[mEdgeVector[e1].inodeB];
2960 Xyce::dout() <<
" y(B)="<<
yVector[mEdgeVector[e1].inodeB];
2961 Xyce::dout() <<
" label = " << mEdgeVector[e1].uLabel;
2962 Xyce::dout() << std::endl;
2964 Xyce::dout() << std::endl;
2967 for (j=1;j<
iyMax;++j)
2973 Xyce::dout() <<
"edge: " << e1;
2975 Xyce::dout() <<
" y(A)="<<
yVector[mEdgeVector[e1].inodeA];
2976 Xyce::dout() <<
" x(B)="<<
xVector[mEdgeVector[e1].inodeB];
2977 Xyce::dout() <<
" y(B)="<<
yVector[mEdgeVector[e1].inodeB];
2978 Xyce::dout() <<
" label = " << mEdgeVector[e1].uLabel;
2979 Xyce::dout() << std::endl;
2981 Xyce::dout() << std::endl;
2984 for (j=1;j<
iyMax;++j)
2990 Xyce::dout() <<
"edge: " << e1;
2992 Xyce::dout() <<
" y(A)="<<
yVector[mEdgeVector[e1].inodeA];
2993 Xyce::dout() <<
" x(B)="<<
xVector[mEdgeVector[e1].inodeB];
2994 Xyce::dout() <<
" y(B)="<<
yVector[mEdgeVector[e1].inodeB];
2995 Xyce::dout() <<
" label = " << mEdgeVector[e1].uLabel;
2996 Xyce::dout() << std::endl;
2998 Xyce::dout() << std::endl;
3026 std::vector<mNode>::iterator first =
mNodeVector.begin ();
3027 std::vector<mNode>::iterator last =
mNodeVector.end ();
3028 std::vector<mNode>::iterator iter;
3033 for (iter=first;iter!=last;++iter)
3035 if (maxNodeNN < iter->cnode)
maxNodeNN = iter->cnode;
3047 std::map<std::string, mLabel>::iterator firstL =
mLabelMap.begin ();
3048 std::map<std::string, mLabel>::iterator lastL =
mLabelMap.end ();
3049 std::map<std::string, mLabel>::iterator iterL;
3051 for (iterL=firstL; iterL!=lastL; ++iterL)
3053 if (iterL->second.uType ==
TYPE_EDGE)
continue;
3055 std::vector<int>::iterator firstN = iterL->second.mNodeVector.begin ();
3056 std::vector<int>::iterator lastN = iterL->second.mNodeVector.end ();
3057 std::vector<int>::iterator iterN;
3059 iterL->second.vol = 0.0;
3061 for (iterN=firstN; iterN!=lastN; ++iterN)
3070 for (iter=first;iter!=last;++iter)
3072 if (xMax < iter->x)
xMax = iter->x;
3073 if (yMax < iter->y)
yMax = iter->y;
3074 if (
xMin > iter->x)
xMin = iter->x;
3075 if (
yMin > iter->y)
yMin = iter->y;
3094 FILE *file = fopen(dbFileName.c_str(),
"wt");
3096 fprintf(file,
"CELLS\n");
3097 fprintf(file,
" | | EDGES CELLS \n");
3098 fprintf(file,
" i | u | AB BC AC/CD AD AB BC AC/CD AD \n");
3099 fprintf(file,
"----- | --- | ----- ----- ----- ----- ----- ----- ----- -----\n");
3105 fprintf(file,
"%5u | ", i);
3106 if (c1.
uLabel != -1 ) fprintf(file,
"%3u | ", c1.
uLabel);
3107 else fprintf(file,
" | ");
3110 else fprintf(file,
" ");
3113 else fprintf(file,
" ");
3116 else fprintf(file,
" ");
3119 else fprintf(file,
" n/a ");
3123 else fprintf(file,
" ");
3126 else fprintf(file,
" ");
3129 else fprintf(file,
" ");
3132 else fprintf(file,
" n/a");
3134 fprintf(file,
"\n");
3136 fprintf(file,
"----- | --- | ----- ----- ----- ----- ----- ----- ----- -----\n");
3138 fprintf(file,
"\nEDGES\n");
3139 fprintf(file,
" | | NODES | | | | |\n");
3140 fprintf(file,
" i | u | A B | ilen | elen | Area1 | Area2 |\n");
3141 fprintf(file,
"----- | --- | ----- ----- | ------------ | ------------ | ------------ | ------------ |\n");
3146 fprintf(file,
"%5u | ", i);
3147 if (e1.
uLabel != -1 ) fprintf(file,
"%3u | ", e1.
uLabel);
3148 else fprintf(file,
" | ");
3149 fprintf(file,
"%5u %5u | %12.4e | %12.4e | %12.4e | %12.4e |\n",
3153 fprintf(file,
"\nNODES\n");
3154 fprintf(file,
" | | |\n");
3155 fprintf(file,
" i | x y | Area |\n");
3156 fprintf(file,
"----- | ------------ ------------ | ------------ |\n");
3161 fprintf(file,
"%5u | ", i);
3162 fprintf(file,
"%12.4e %12.4e | %12.4e |\n", n1.
x, n1.
y, n1.
area);
3165 fprintf(file,
"\nNodeEdgeInfo\n");
3168 fprintf(file,
"------\n");
3169 fprintf(file,
" node index = %d\n", i);
3172 fprintf(file,
" local edge index = %d\n", j);
3174 fprintf(file,
" global edge index = %d\n",
3177 fprintf(file,
" neighbor node = %d\n",
3180 fprintf(file,
" elen = %12.4e\n",
3183 fprintf(file,
" ilen = %12.4e\n",
3186 fprintf(file,
"------\n");
3206 std::map<std::string,mLabel>::iterator first =
mLabelMap.begin ();
3207 std::map<std::string,mLabel>::iterator last =
mLabelMap.end ();
3208 std::map<std::string,mLabel>::iterator iter =
mLabelMap.end ();
3210 Xyce::dout() << std::endl;
3211 Xyce::dout() <<
"Mesh Labels:" <<std::endl;
3212 Xyce::dout() <<
" Index # nodes Type Label";
3213 Xyce::dout() << std::endl;
3214 for (i=0, iter=first; iter!=last; ++iter, ++i)
3216 Xyce::dout().width(8);
3217 Xyce::dout() << iter->second.iIndex;
3218 Xyce::dout().width(10);
3219 Xyce::dout() << iter->second.cNode;
3221 if (iter->second.uType ==
TYPE_EDGE) Xyce::dout() <<
" Edge ";
3222 else Xyce::dout() <<
" Region ";
3224 Xyce::dout() <<
" ";
3225 Xyce::dout().width(15);
3226 Xyce::dout() << iter->second.name << std::endl;
3228 Xyce::dout() << std::endl;
3256 (
double &x,
double &y,
int inodeA,
int inodeB,
int inodeC)
3259 mNode nA = mNodeVector[inodeA];
3260 mNode nB = mNodeVector[inodeB];
3261 mNode nC = mNodeVector[inodeC];
3263 double x1 = nA.
x;
double y1 = nA.
y;
3264 double x2 = nB.
x;
double y2 = nB.
y;
3265 double x3 = nC.
x;
double y3 = nC.
y;
3267 double dx12 = x1 - x2;
3268 double dx23 = x2 - x3;
3269 double dx13 = x1 - x3;
3271 double m12 = (dx12) ? (y1 - y2) / dx12 : 0.0;
3272 double m23 = (dx23) ? (y2 - y3) / dx23 : 0.0;
3273 double m13 = (dx13) ? (y1 - y3) / dx13 : 0.0;
3274 double x12 = (x1 + x2) / 2.0;
double y12 = (y1 + y2) / 2.0;
3275 double x23 = (x2 + x3) / 2.0;
double y23 = (y2 + y3) / 2.0;
3276 double x13 = (x1 + x3) / 2.0;
double y13 = (y1 + y3) / 2.0;
3279 if (fabs(dx12) < fabs(dx23))
3281 iSmallest = (fabs(dx12) < fabs(dx13)) ?
TAG12 :
TAG13;
3285 iSmallest = (fabs(dx23) < fabs(dx13)) ?
TAG23 :
TAG13;
3291 x = (m13 * m23 * (y13 - y23) + m23 * x13 - m13 * x23) / (m23 - m13);
3295 x = (m13 * m12 * (y13 - y12) + m12 * x13 - m13 * x12) / (m12 - m13);
3299 x = (m12 * m23 * (y12 - y23) + m23 * x12 - m12 * x23) / (m23 - m12);
3304 if (fabs(m12) > fabs(m23))
3306 iLargest = (fabs(m12) > fabs(m13)) ?
TAG12 :
TAG13;
3310 iLargest = (fabs(m23) > fabs(m13)) ?
TAG23 :
TAG13;
3316 y = (x12 - x) / m12 + y12;
3320 y = (x23 - x) / m23 + y23;
3324 y = (x13 - x) / m13 + y13;
3328 #ifdef Xyce_DEBUG_DEVICE
3329 if (devOptions_->debugLevel > 1)
3331 Xyce::dout() <<
"In computeIntPB:\n";
3332 Xyce::dout() <<
" inodeA = " << inodeA;
3333 Xyce::dout() <<
" inodeB = " << inodeB;
3334 Xyce::dout() <<
" inodeC = " << inodeC << std::endl;
3335 Xyce::dout() <<
" x1 = " << x1;
3336 Xyce::dout() <<
" y1 = " << y1 <<std::endl;
3338 Xyce::dout() <<
" x2 = " << x2;
3339 Xyce::dout() <<
" y2 = " << y2 <<std::endl;
3341 Xyce::dout() <<
" x3 = " << x3;
3342 Xyce::dout() <<
" y3 = " << y3 <<std::endl;
3344 Xyce::dout() <<
" iSmallest = " << iSmallest << std::endl;
3345 Xyce::dout() <<
" iLargest = " << iLargest << std::endl;
3347 Xyce::dout() <<
" m12 = " << m12 << std::endl;
3348 Xyce::dout() <<
" m23 = " << m23 << std::endl;
3349 Xyce::dout() <<
" m13 = " << m13 << std::endl;
3351 Xyce::dout() <<
" x = " << x << std::endl;
3352 Xyce::dout() <<
" y = " << y << std::endl;
3377 (
double x1,
double y1,
double x2,
double y2)
3379 double dx1 = x2 - x1;
3380 double dy1 = y2 - y1;
3381 double h = sqrt(dx1 * dx1 + dy1 * dy1);
3383 double A = pi * (x1 + x2) * h;
3403 (
double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
3407 if (x1 > x2) { xT = x1; yT = y1; x1 = x2; y1 = y2; x2 = xT; y2 = yT; }
3408 if (x2 > x3) { xT = x2; yT = y2; x2 = x3; y2 = y3; x3 = xT; y3 = yT; }
3409 if (x1 > x2) { xT = x1; yT = y1; x1 = x2; y1 = y2; x2 = xT; y2 = yT; }
3412 double m13 = (y1 - y3) / (x1 - x3);
3415 double x2_2 = x2 * x2;
3416 double x2_3 = x2 * x2_2;
3420 if (fabs(x1-x2) > 1.0e-14)
3422 double m12 = (y1 - y2) / (x1 - x2);
3423 double x1_2 = x1 * x1;
3424 double x1_3 = x1 * x1_2;
3425 V12 = (m12 - m13) * ((x2_3 - x1_3) / 3.0 - x1 * (x2_2 - x1_2) / 2.0);
3430 if (fabs(x2-x3) > 1.0e-14)
3432 double m23 = (y2 - y3) / (x2 - x3);
3433 double x3_2 = x3 * x3;
3434 double x3_3 = x3 * x3_2;
3435 V23 = (m23 - m13) * ((x3_3 - x2_3) / 3.0 - x3 * (x3_2 - x2_2) / 2.0);
3440 double V = 2.0 * pi * (fabs(V12) + fabs(V23));
3459 double xl = n1.
x - n2.
x;
3460 double xr = n3.
x - n2.
x;
3461 double yl = n1.
y - n2.
y;
3462 double yr = n3.
y - n2.
y;
3464 double r = (xl*xr+yl*yr)/(sqrt(
sq(xl)+
sq(yl))*sqrt(
sq(xr)+
sq(yr)));
3465 if (r > 1.0) r = 1.0;
3466 else if (r < -1.0) r = -1.0;
3468 double angle = acos(r);
3486 std::vector<mCell>::iterator first =
mCellVector.begin();
3487 std::vector<mCell>::iterator last =
mCellVector.end ();
3488 std::vector<mCell>::iterator iter;
3491 for (i=0,iter=first; iter!=last ; ++i, ++iter)
3493 mCell & cellObj = *iter;
3495 int iedgeDA = cellObj.
iedgeDA;
3504 inode[0] = edgeAB.
inodeA;
3505 inode[1] = edgeAB.
inodeB;
3506 inode[2] = edgeBC.
inodeA;
3507 inode[3] = edgeBC.
inodeB;
3508 inode[4] = edgeCD.
inodeA;
3509 inode[5] = edgeCD.
inodeB;
3514 if (inode[0] == inode[2])
3519 cellObj.
inodeA = inode[1];
3520 cellObj.
inodeB = inode[0];
3521 cellObj.
inodeC = inode[3];
3523 else if (inode[0] == inode[3])
3528 cellObj.
inodeA = inode[1];
3529 cellObj.
inodeB = inode[0];
3530 cellObj.
inodeC = inode[2];
3532 else if (inode[1] == inode[2])
3537 cellObj.
inodeA = inode[0];
3538 cellObj.
inodeB = inode[1];
3539 cellObj.
inodeC = inode[3];
3546 cellObj.
inodeA = inode[0];
3547 cellObj.
inodeB = inode[1];
3548 cellObj.
inodeC = inode[2];
3558 inode[6] = edgeDA.
inodeA;
3559 inode[7] = edgeDA.
inodeB;
3561 if ((inode[0] == inode[2]) || (inode[0] == inode[3]))
3565 cellObj.
inodeA = inode[1];
3566 cellObj.
inodeB = inode[0];
3572 cellObj.
inodeA = inode[0];
3573 cellObj.
inodeB = inode[1];
3575 if ((inode[4] == inode[2]) || (inode[4] == inode[3]))
3579 cellObj.
inodeC = inode[4];
3580 cellObj.
inodeD = inode[5];
3586 cellObj.
inodeC = inode[5];
3587 cellObj.
inodeD = inode[4];
3610 double x1 = node1.
x;
3611 double y1 = node1.
y;
3612 double x2 = node2.
x;
3613 double y2 = node2.
y;
3614 double x3 = node3.
x;
3615 double y3 = node3.
y;
3617 double x12 = x2 - x1;
3618 double y12 = y2 - y1;
3619 double x13 = x3 - x1;
3620 double y13 = y3 - y1;
3622 double d12 = sqrt(x12*x12 + y12*y12);
3623 double d13 = sqrt(x13*x13 + y13*y13);
3625 double arg12 = x12/d12;
3626 double arg13 = x13/d13;
3628 if (arg12 < -1.0) arg12 = 1.0;
else if (arg12 > 1.0) arg12 = 1.0;
3629 if (arg13 < -1.0) arg13 = 1.0;
else if (arg13 > 1.0) arg13 = 1.0;
3631 double a12 = acos(arg12);
3632 double a13 = acos(arg13);
3636 if (y12 < 0) a12 = 2*pi - a12;
3637 if (y13 < 0) a13 = 2*pi - a13;
3639 return (a13 > a12) ?
true :
false;
3664 if (inode1 == inode3)
3670 else if (inode1 == inode4)
3676 else if (inode2 == inode3)
3696 if ((inode1 == inode3) || (inode1 == inode4))
3707 if ((inode5 == inode3) || (inode5 == inode4))
3732 (
int itri,
int *ainode,
int *aiedge,
int *aitri,
int *auLabel)
3734 elementNodes(itri,ainode);
3736 int iedgeAB, iedgeBC, iedgeCD, iedgeDA;
3738 iedgeAB = aiedge[0] = mCellVector[itri].iedgeAB;
3739 iedgeBC = aiedge[1] = mCellVector[itri].iedgeBC;
3740 iedgeCD = aiedge[2] = mCellVector[itri].iedgeCD;
3741 iedgeDA = aiedge[3] = mCellVector[itri].iedgeDA;
3743 aitri[0] = mCellVector[itri].icellAB;
3744 aitri[1] = mCellVector[itri].icellBC;
3745 aitri[2] = mCellVector[itri].icellCD;
3746 aitri[3] = mCellVector[itri].icellDA;
3748 auLabel[0] = mEdgeVector[iedgeAB].uLabel;
3749 auLabel[1] = mEdgeVector[iedgeBC].uLabel;
3750 auLabel[2] = mEdgeVector[iedgeCD].uLabel;
3751 auLabel[3] = (iedgeDA != -1) ? mEdgeVector[iedgeDA].uLabel : -1;
3764 (
NADJ &nadj,
int itri,
int iVertex,
int uIntLabel,
bool fCW)
3773 int aauVertices2Edge[4][4] =
3782 getElementInfo(itri, ainode, aiedge, aitri, auLabel);
3783 int cVertices = (ainode[
VERTEX_D] != -1) ? 4 : 3;
3786 nadj.
inode = ainode[iVertex];
3793 int nNextVertex = (fCCW == fCW) ? 1 : -1;
3794 int i = (iVertex + nNextVertex + cVertices) % cVertices;
3795 int i1 = aauVertices2Edge[iVertex][i];
3796 nadj.
ainode[0] = inode = ainode[i];
3797 nadj.
aiedge[0] = aiedge[i1];
3799 bool fBndry = (auLabel[i1] != uIntLabel);
3803 {
for(i = 0; i < cVertices; ++i)
3804 {
if (ainode[i] == nadj.
inode) iVertex = i;
3805 if (ainode[i] == inode) i1 = i;
3807 UINT iA = (iVertex + 1) % cVertices;
3808 UINT iB = (iVertex + cVertices - 1) % cVertices;
3809 UINT iV = (i1 == iA) ? iB : iA;
3810 UINT iE = aauVertices2Edge[iVertex][iV];
3812 nadj.
auLabel[cnode] = mCellVector[itri].uLabel;
3814 nadj.
ainode[cnode] = inode = ainode[iV];
3815 nadj.
aiedge[cnode] = aiedge[iE];
3816 nadj.
aielem[cnode] = aitri[iE];
3817 fBndry = fBndry || (auLabel[iE] != uIntLabel);
3825 if (itri == -1)
break;
3827 getElementInfo(itri, ainode, aiedge, aitri, auLabel);
3828 cVertices = (ainode[
VERTEX_D] != -1) ? 4 : 3;
3858 #ifdef Xyce_DEBUG_DEVICE
3861 Xyce::dout() <<
"In PDE_2DMesh::calcAdjacencyInfo" << std::endl;
3887 int *pinode = ainode;
3890 for(j = 0; j < 4; ++j, ++pinode)
3907 int c = nadjT.
cnode - 2;
3908 for(k = nadj.
cnode - 1; k != -1; --k)
3914 for(k = 0; k < c; ++k)
3940 for(k = 0; k < c-1; ++k)
3959 UINT cTriangle = (nadj.
fGotAll) ? c : c-1;
3962 nodeinfo.
Area = 0.0;
3963 for(k = 0; k < c; ++k)
3967 double elen = sqrt(
sq(xA-xB)+
sq(yA-yB));
3972 area =
areaAdjust(xA,yA,x[k],y[k],x[k+1],y[k+1]);
3976 ilen = sqrt(
sq(x[k]-x[k+1])+
sq(y[k]-y[k+1]));
3977 area = ilen * elen * 0.25;
3982 aedgeinfo[k].
ilen = ilen;
3983 aedgeinfo[k].
elen = elen;
3984 aedgeinfo[k].
Area1 = area;
3985 aedgeinfo[k].
Area2 = 0.0;
3986 nodeinfo.
Area += area;
3989 for(k = 0; k < cTriangle; ++k)
3997 double xAB = (xA+xB)/2.0;
3998 double yAB = (yA+yB)/2.0;
3999 double xAC = (xA+xC)/2.0;
4000 double yAC = (yA+yC)/2.0;
4010 (sqrt(
sq(xAB-xA)+
sq(yAB-yA))*sqrt(
sq(xAB-xo)+
sq(yAB-yo))+
4011 sqrt(
sq(xAC-xA)+
sq(yAC-yA))*sqrt(
sq(xAC-xo)+
sq(yAC-yo)));
4013 aedgeinfo[k].
Area2 = area;
4018 write(nFile, &nadj.
inode,
sizeof(INODE));
4020 write(nFile, aedgeinfo, c *
sizeof(
EDGEINFO));
4032 mNodeVector[*pinode].edgeInfoVector[k] = aedgeinfo[k];
4062 for(k = 0; k < cRegion; ++k, ++piBegin, ++piEnd)
4064 *piBegin = *piEnd = -1;
4070 for(k = 0; k < c; ++k, ++puLabel)
4072 int uLabel = *puLabel;
4076 aiEnd[uLabel] = k + 1;
4078 else if (
aiEnd[uLabel] == k) ++
aiEnd[uLabel];
4081 puLabel = nadj.
auLabel + c - 1;
4082 for(k = c; *puLabel == uLabel; --k, --puLabel);
4088 for(k = 0; k < cRegion; ++k, ++piBegin, ++piEnd)
4090 int iBegin = *piBegin;
4095 cEdge = (iEnd > iBegin) ? iEnd - iBegin : (c + iEnd) - iBegin;
4099 int cTEdge = (cEdge) ? cEdge - 1 : 0;
4102 nodeinfo.
Area = 0.0;
4103 for(l = 0; l < cEdge; ++l)
4105 int m = (iBegin + l) % nadj.
cnode;
4108 double xmdpt = (xA + xB) / 2.0;
4109 double ymdpt = (yA + yB) / 2.0;
4110 double elen = sqrt(
sq(xA-xB)+
sq(yA-yB));
4111 double ilen, area, x1, y1, x2, y2;
4113 { x1 = xmdpt; x2 = x[m+1];
4114 y1 = ymdpt; y2 = y[m+1];
4117 { x1 = x[m]; x2 = xmdpt;
4118 y1 = y[m]; y2 = ymdpt;
4121 { x1 = x[m]; x2 = x[m+1];
4122 y1 = y[m]; y2 = y[m+1];
4129 { ilen = sqrt(
sq(x1-x2)+
sq(y1-y2));
4130 area = ilen * elen / 4.0;
4135 aedgeinfo[l].
ilen = ilen;
4136 aedgeinfo[l].
elen = elen;
4137 aedgeinfo[l].
Area1 = area;
4138 aedgeinfo[l].
Area2 = 0.0;
4139 nodeinfo.
Area += area;
4142 for(l = 0; l < cTEdge; ++l)
4143 {
int m = (iBegin + l) % nadj.
cnode;
4144 int n = (m + 1) % nadj.
cnode;
4153 double xAB = (xA+xB)/2.0;
4154 double yAB = (yA+yB)/2.0;
4155 double xAC = (xA+xC)/2.0;
4156 double yAC = (yA+yC)/2.0;
4164 (sqrt(
sq(xAB-xA)+
sq(yAB-yA))*sqrt(
sq(xAB-xo)+
sq(yAB-yo))+
4165 sqrt(
sq(xAC-xA)+
sq(yAC-yA))*sqrt(
sq(xAC-xo)+
sq(yAC-yo)));
4167 aedgeinfo[l].
Area2 = area;
4171 int inode = numNodes + nadj.
inode * cRegion + k;
4173 write(nFile, &inode,
sizeof(INODE));
4175 write(nFile, aedgeinfo, cEdge *
sizeof(
EDGEINFO));
4188 mNodeVector[inode].edgeInfoVector[k] = aedgeinfo[k];
4205 #ifdef Xyce_DEBUG_DEVICE
4208 Xyce::dout() <<
"Done with PDE_2DMesh::calcAdjacencyInfo" << std::endl;
4225 bool bsuccess =
false;
4227 ExtendedString tmpName = labelName;
4246 ExtendedString tmpName = labelName;
4283 xvec_tmp.resize(
xVector.size(), 0.0);
4298 yvec_tmp.resize(
yVector.size(), 0.0);
4314 ExtendedString tmpName = labelName;
4351 double X0_1 = xScale;
4352 double X0_2 = xScale * X0_1;
4353 double X0_3 = xScale * X0_2;
4355 double scaleILEN, scaleArea;
4356 double scaleELEN = X0_1;
4358 if (
cylGeom) { scaleILEN = X0_2; scaleArea = X0_3; }
4359 else { scaleILEN = X0_1; scaleArea = X0_2; }
4361 #ifdef Xyce_DEBUG_DEVICE
4364 Xyce::dout() << section_divider << std::endl;
4365 Xyce::dout() <<
" In PDE_2DMesh::scaleMesh"<<std::endl;
4366 Xyce::dout() <<
" scaleELEN = " << scaleELEN <<std::endl;
4367 Xyce::dout() <<
" scaleILEN = " << scaleILEN <<std::endl;
4368 Xyce::dout() <<
" scaleArea = " << scaleArea <<std::endl;
4369 Xyce::dout() << section_divider << std::endl;
4374 scaleELEN = 1.0/scaleELEN;
4375 scaleILEN = 1.0/scaleILEN;
4376 scaleArea = 1.0/scaleArea;
4383 std::vector<EDGEINFO>::iterator firstEI =
mNodeVector[i].edgeInfoVector.begin ();
4384 std::vector<EDGEINFO>::iterator lastEI =
mNodeVector[i].edgeInfoVector.end ();
4385 std::vector<EDGEINFO>::iterator iterEI;
4386 for (iterEI=firstEI;iterEI!=lastEI;++iterEI)
4388 iterEI->ilen *= scaleILEN;
4389 iterEI->elen *= scaleELEN;
4390 iterEI->Area1 *= scaleArea;
4391 iterEI->Area2 *= scaleArea;
4409 std::map<std::string, mLabel>::iterator firstL =
mLabelMap.begin ();
4410 std::map<std::string, mLabel>::iterator lastL =
mLabelMap.end ();
4411 std::map<std::string, mLabel>::iterator iterL;
4413 for (iterL=firstL; iterL!=lastL; ++iterL)
4415 iterL->second.vol *= scaleArea;
4416 iterL->second.surfArea *= scaleILEN;
4445 int iNodeA,iNodeB,iNodeC,iNodeD;
4458 if (istatus == 2)
return F[inode];
4459 if (istatus == -1)
return 0.0;
4474 intAHelp.
f0 = F[iNodeA];
4475 intAHelp.
f1 = F[iNodeB];
4476 intAHelp.
f2 = F[iNodeC];
4484 intAHelp.
f0 = F[iNodeA];
4485 intAHelp.
f2 = F[iNodeC];
4491 double f1 = F[iNodeB];
4492 double f2 = F[iNodeD];
4494 if( pow((r1-r),2.0)+pow((z1-z),2.0) <
4495 pow((r2-r),2.0)+pow((z2-z),2.0)
4539 int iEdgeAB, iEdgeBC, iEdgeCD, iEdgeDA;
4541 double ABx, ABy, ABangle, ABFx, ABFy;
4542 double BCx, BCy, BCangle, BCFx, BCFy;
4543 double CDx, CDy, CDangle, CDFx, CDFy;
4544 double DAx, DAy, DAangle, DAFx, DAFy;
4545 double xA, xB, yA, yB;
4548 #ifdef Xyce_DEBUG_DEVICE
4583 if (triFlag) iEdgeDA = -1;
4592 ABangle =
compAngle(xB,yB, xA,yA, (xA+0.1), yA);
4596 ABFx = F[iEdgeAB] * cos(ABangle);
4597 ABFy = F[iEdgeAB] * sin(ABangle);
4604 BCangle =
compAngle(xB,yB, xA,yA, (xA+0.1), yA);
4608 BCFx = F[iEdgeBC] * cos(BCangle);
4609 BCFy = F[iEdgeBC] * sin(BCangle);
4616 CDangle =
compAngle(xB,yB, xA,yA, (xA+0.1), yA);
4620 CDFx = F[iEdgeCD] * cos(CDangle);
4621 CDFy = F[iEdgeCD] * sin(CDangle);
4630 DAangle =
compAngle(xB,yB, xA,yA, (xA+0.1), yA);
4634 DAFx = F[iEdgeDA] * cos(DAangle);
4635 DAFy = F[iEdgeDA] * sin(DAangle);
4646 #ifdef Xyce_DEBUG_DEVICE
4647 bool madeIt =
false;
4672 #ifdef Xyce_DEBUG_DEVICE
4687 alpha = ((ABy < CDy)?1.0:0.0) * (z-ABy)/(CDy-ABy) +
4688 ((ABy >= CDy)?1.0:0.0) * (ABy-z)/(ABy-CDy);
4689 xvec = (1.0-alpha)*ABFx + alpha*CDFx;
4691 alpha = ((BCx < DAx)?1.0:0.0) * (r-BCx)/(DAx-BCx) +
4692 ((BCx >= DAx)?1.0:0.0) * (BCx-r)/(BCx-DAx);
4693 yvec = (1.0-alpha)*BCFy + alpha*DAFy;
4695 #ifdef Xyce_DEBUG_DEVICE
4701 alpha = ((BCy < DAy)?1.0:0.0) * (z-BCy)/(DAy-BCy) +
4702 ((BCy >= DAy)?1.0:0.0) * (BCy-z)/(BCy-DAy);
4703 xvec = (1.0-alpha)*BCFx + alpha*DAFx;
4705 alpha = ((ABx < CDx)?1.0:0.0) * (r-ABx)/(CDx-ABx) +
4706 ((ABx >= CDx)?1.0:0.0) * (ABx-r)/(ABx-CDx);
4707 yvec = (1.0-alpha)*ABFy + alpha*CDFy;
4709 #ifdef Xyce_DEBUG_DEVICE
4719 #ifdef Xyce_DEBUG_DEVICE
4721 double rtest = ((2.1e-3)/209.0) * 22.0;
4722 double rtol = fabs(rtest/1000.0);
4723 double ztest = -9.0e-5;
4724 double ztol = fabs(ztest/1000.0);
4727 (xvec != 0.0 && !(xvec > 0.0) && !(xvec < 0.0)) ||
4728 (yvec != 0.0 && !(yvec > 0.0) && !(yvec < 0.0))
4729 || (r >= (rtest-rtol) && r <= (rtest+rtol) &&
4730 z >= (ztest-ztol) && z <= (ztest+ztol))
4733 Xyce::dout() << Xyce::section_divider << std::endl;
4734 Xyce::dout() <<
"Vector Interpolation failed!" << std::endl;
4735 Xyce::dout() << std::endl;
4736 Xyce::dout() <<
" iCell = " << iCell << std::endl;
4737 Xyce::dout() <<
" alpha = " << alpha << std::endl;
4738 Xyce::dout() <<
" number of cells on mesh: " <<
numCells << std::endl;
4739 Xyce::dout() <<
" r = " << r << std::endl;
4740 Xyce::dout() <<
" z = " << z << std::endl;
4741 Xyce::dout() << std::endl;
4742 Xyce::dout() <<
" xvec = " << xvec << std::endl;
4743 Xyce::dout() <<
" yvec = " << yvec << std::endl;
4745 Xyce::dout() <<
" inodeA = " << iA << std::endl;
4746 Xyce::dout() <<
" inodeB = " << iB << std::endl;
4747 Xyce::dout() <<
" inodeC = " << iC << std::endl;
4748 Xyce::dout() <<
" inodeD = " << iD << std::endl;
4757 Xyce::dout() <<
" ABangle = " << ABangle <<
" = " <<(ABangle/pi)<<
" * PI" << std::endl;
4758 Xyce::dout() <<
" BCangle = " << BCangle <<
" = " <<(BCangle/pi)<<
" * PI" << std::endl;
4759 Xyce::dout() <<
" CDangle = " << CDangle <<
" = " <<(CDangle/pi)<<
" * PI" << std::endl;
4761 Xyce::dout() <<
" DAangle = " << DAangle <<
" = " <<(DAangle/pi)<<
" * PI" << std::endl;
4763 Xyce::dout() <<
" ABFx = " << ABFx << std::endl;
4764 Xyce::dout() <<
" ABFy = " << ABFy << std::endl;
4765 Xyce::dout() <<
" BCFx = " << BCFx << std::endl;
4766 Xyce::dout() <<
" BCFy = " << BCFy << std::endl;
4767 Xyce::dout() <<
" CDFx = " << CDFx << std::endl;
4768 Xyce::dout() <<
" CDFy = " << CDFy << std::endl;
4769 Xyce::dout() <<
" DAFx = " << DAFx << std::endl;
4770 Xyce::dout() <<
" DAFy = " << DAFy << std::endl;
4772 Xyce::dout() <<
" F[iEdgeAB] = " << F[iEdgeAB] <<std::endl;
4773 Xyce::dout() <<
" F[iEdgeBC] = " << F[iEdgeBC] <<std::endl;
4774 Xyce::dout() <<
" F[iEdgeCD] = " << F[iEdgeCD] <<std::endl;
4776 Xyce::dout() <<
" F[iEdgeDA] = " << F[iEdgeDA] <<std::endl;
4777 Xyce::dout() << Xyce::section_divider << std::endl;
4832 int iEdgeAB,iEdgeBC,iEdgeCD,iEdgeDA;
4833 int iNodeA,iNodeB,iNodeC,iNodeD;
4834 bool doneFlag =
false;
4838 int ixhi,ixlo,iyhi,iylo;
4861 if(r==
xVector[iNodeA] && z==
yVector[iNodeA]){inode=iNodeA; istatus=2;}
4862 if(r==
xVector[iNodeB] && z==
yVector[iNodeB]){inode=iNodeB; istatus=2;}
4863 if(r==
xVector[iNodeC] && z==
yVector[iNodeC]){inode=iNodeC; istatus=2;}
4865 if(r==
xVector[iNodeD] && z==
yVector[iNodeD]){inode=iNodeD; istatus=2;}
4867 if (istatus == 2)
return;
4875 intEHelp.
xB =
xVector[mEdgeVector[iEdgeAB].inodeB];
4876 intEHelp.
yA =
yVector[mEdgeVector[iEdgeAB].inodeA];
4877 intEHelp.
yB =
yVector[mEdgeVector[iEdgeAB].inodeB];
4885 intEHelp.
xA =
xVector[mEdgeVector[iEdgeBC].inodeA];
4886 intEHelp.
xB =
xVector[mEdgeVector[iEdgeBC].inodeB];
4887 intEHelp.
yA =
yVector[mEdgeVector[iEdgeBC].inodeA];
4888 intEHelp.
yB =
yVector[mEdgeVector[iEdgeBC].inodeB];
4896 intEHelp.
xA =
xVector[mEdgeVector[iEdgeCD].inodeA];
4897 intEHelp.
xB =
xVector[mEdgeVector[iEdgeCD].inodeB];
4898 intEHelp.
yA =
yVector[mEdgeVector[iEdgeCD].inodeA];
4899 intEHelp.
yB =
yVector[mEdgeVector[iEdgeCD].inodeB];
4909 intEHelp.
xA =
xVector[mEdgeVector[iEdgeDA].inodeA];
4910 intEHelp.
xB =
xVector[mEdgeVector[iEdgeDA].inodeB];
4911 intEHelp.
yA =
yVector[mEdgeVector[iEdgeDA].inodeA];
4912 intEHelp.
yB =
yVector[mEdgeVector[iEdgeDA].inodeB];
4922 if((ixhi >= 1) && (ixlo >= 1) && (iyhi >= 1) && (iylo >= 1))
4936 double minimum = +1.0e+99;
4950 if (ABmin <= minimum) { minimum = ABmin; iC = AB_iC; }
4962 if (BCmin <= minimum) { minimum = BCmin; iC = BC_iC; }
4974 if (CDmin <= minimum) { minimum = CDmin; iC = CD_iC; }
4986 if (DAmin < minimum) { minimum = DAmin; iC = DA_iC; }
5000 #ifdef Xyce_DEBUG_DEVICE
5003 Xyce::dout() << std::endl;
5004 Xyce::dout() <<
"iCell = " << iCell << std::endl;
5005 Xyce::dout() <<
"r = " << r <<
" z = " << z << std::endl;
5006 Xyce::dout() <<
"curr_min = " << curr_min << std::endl;
5007 Xyce::dout() << std::endl;
5011 Xyce::dout() <<
"AB_iC = " << AB_iC;
5012 Xyce::dout() <<
" ABmin = " << ABmin;
5018 Xyce::dout() <<
"BC_iC = " << BC_iC;
5019 Xyce::dout() <<
" BCmin = " << BCmin;
5025 Xyce::dout() <<
"CD_iC = " << CD_iC;
5026 Xyce::dout() <<
" CDmin = " << CDmin;
5032 Xyce::dout() <<
"DA_iC = " << DA_iC;
5033 Xyce::dout() <<
" DAmin = " << DAmin;
5061 double minDist = +1.0e99;
5063 double rdist,zdist,dist;
5070 rdist = r-x1; zdist = z-y1;
5071 dist = sqrt (rdist*rdist + zdist*zdist);
5072 if (dist < minDist) { minDist = dist; }
5080 rdist = r-x1; zdist = z-y1;
5081 dist = sqrt (rdist*rdist + zdist*zdist);
5082 if (dist < minDist) { minDist = dist; }
5090 rdist = r-x1; zdist = z-y1;
5091 dist = sqrt (rdist*rdist + zdist*zdist);
5092 if (dist < minDist) { minDist = dist; }
5100 rdist = r-x1; zdist = z-y1;
5101 dist = sqrt (rdist*rdist + zdist*zdist);
5102 if (dist < minDist) { minDist = dist; }
5120 double x1,
double y1,
5121 double x2,
double y2,
5122 double x3,
double y3)
5129 xl = x1 - x2; yl = y1 - y2;
5130 xr = x3 - x2; yr = y3 - y2;
5132 r = (xl*xr+yl*yr)/(sqrt(
sq(xl)+
sq(yl))*sqrt(
sq(xr)+
sq(yr)));
5133 if (r > 1.0) r = 1.0;
5134 else if (r < -1.0) r = -1.0;
5136 if (xl*yr-xr*yl > 0) angle = 2*
M_PI-angle;
5165 aiNodeVector.reserve (32);
5166 aiEdgeVector.reserve (32);
5167 aiCellVector.reserve (32);
5168 auLabelVector.reserve (32);
5171 for (
int i=0;i<32;++i)
5173 aiNodeVector[i] = -1;
5174 aiEdgeVector[i] = -1;
5175 aiCellVector[i] = -1;
5176 auLabelVector[i] = -1;
5217 iedgeAB (-1), iedgeBC (-1), iedgeCD (-1), iedgeDA (-1),
5218 icellAB (-1), icellBC (-1), icellCD (-1), icellDA (-1)
5285 double f =
aa*r +
bb*z +
cc;
5302 if( (y1-
y0)*(x2-x1)- (y2-y1)*(x1-
x0) != 0.0)
5305 ((y1-
y0)*(x2-
x1) - (y2-y1)*(x1-
x0));
5380 if( (yA <= z && yB >= z) || (yB <= z && yA >= z) )
5406 if((xA <= r && xB >= r)||(xB <= r && xA >= r))
5411 if((yA <= z && yB >= z)||(yB <= z && yA >= z))