bool InIsoscelesTriangle(const GG::Pt& pt, const GG::Pt& ul, const GG::Pt& lr, ShapeOrientation orientation) { double x1_, y1_, x2_, y2_, x3_, y3_; FindIsoscelesTriangleVertices(ul, lr, orientation, x1_, y1_, x2_, y2_, x3_, y3_); return InTriangle(pt, x1_, y1_, x2_, y2_, x3_, y3_); }
BOOL CbelaviewDoc::GetPointValues(double x, double y, CPointVals &u) { int k; k=InTriangle(x,y); if (k<0) return FALSE; GetPointValues(x,y,k,u); return TRUE; }
bool IncrementalBlueNoise::GlobalInsertNode(Node2d * target_node) { #ifdef _Debug_Demo flip_records.clear(); split_records.clear(); #endif //Locate the triangle list<Edge*>::const_iterator it; int mode = -1; for (it = leadingEdges_.begin(); it != leadingEdges_.end(); ++it) { Edge* edge = *it; bool inTri = InTriangle(edge, target_node, mode); if (inTri) { if (mode == 0) { splitTriangle(*edge, *target_node); return true; } else if (mode == 1) { splitOnEdge(*edge, *target_node); return true; } else if (mode == 2) { edge = edge->getNextEdgeInFace(); splitOnEdge(*edge, *target_node); return true; } else if (mode == 3) { edge = edge->getNextEdgeInFace(); edge = edge->getNextEdgeInFace(); splitOnEdge(*edge, *target_node); return true; } } } return false; }
// Algorithm Insert(DT(a,b,c,v1,v2,...,vi-1), vi) // 1.find the triangle vavbvc which contains vi // FindTriangle() // 2.if (vi located at the interior of vavbvc) // 3. then add triangle vavbvi, vbvcvi and vcvavi into DT // UpdateDT() // FlipTest(DT, va, vb, vi) // FlipTest(DT, vb, vc, vi) // FlipTest(DT, vc, va, vi) // 4.else if (vi located at one edge (E.g. edge vavb) of vavbvc) // 5. then add triangle vavivc, vivbvc, vavdvi and vivdvb into DT (here, d is the third vertex of triangle which contains edge vavb) // UpdateDT() // FlipTest(DT, va, vd, vi) // FlipTest(DT, vc, va, vi) // FlipTest(DT, vd, vb, vi) // FlipTest(DT, vb, vc, vi) // 6.return DT(a,b,c,v1,v2,...,vi) void Insert(MESH * pMesh, int ver_index) { VERTEX2D * pVer = (VERTEX2D *)(pMesh->pVerArr+ver_index); TRIANGLE * pTargetTri = NULL; TRIANGLE * pEqualTri1 = NULL; TRIANGLE * pEqualTri2 = NULL; int j = 0; TRIANGLE * pTri = pMesh->pTriArr; while (pTri != NULL) { REAL r = InTriangle(pMesh, pVer, pTri); if(r > 0) // should be in triangle { pTargetTri = pTri; } else if (r == 0) // should be on edge { if(j == 0) { pEqualTri1 = pTri; j++; } else { pEqualTri2 = pTri; } } pTri = pTri->pNext; } if (pEqualTri1 != NULL && pEqualTri2 != NULL) { InsertOnEdge(pMesh, pEqualTri1, ver_index); InsertOnEdge(pMesh, pEqualTri2, ver_index); } else { InsertInTriangle(pMesh, pTargetTri, ver_index); } }
BOOL CbelaviewDoc::OnOpenDocument(LPCTSTR lpszPathName) { if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE; FILE *fp; int i, j, k, t; char s[1024], q[1024]; char *v; double b; BOOL flag = FALSE; CPointProp PProp; CBoundaryProp BProp; CMaterialProp MProp; CCircuit CProp; CNode node; CSegment segm; CArcSegment asegm; CElement elm; CBlockLabel blk; CMeshNode mnode; CPoint mline; // make sure old document is cleared out... if (NumList != NULL) { for (i = 0; i < meshnode.GetSize(); i++) { if (ConList[i] != NULL) free(ConList[i]); } free(ConList); ConList = NULL; free(NumList); NumList = NULL; } nodelist.RemoveAll(); linelist.RemoveAll(); blocklist.RemoveAll(); arclist.RemoveAll(); nodeproplist.RemoveAll(); lineproplist.RemoveAll(); blockproplist.RemoveAll(); circproplist.RemoveAll(); meshnode.RemoveAll(); meshelem.RemoveAll(); contour.RemoveAll(); if ((fp = fopen(lpszPathName, "rt")) == NULL) { MsgBox("Couldn't read from specified .poly file"); return FALSE; } // define some defaults ProblemType = 0; Coords = 0; ProblemNote = ""; bHasMask = FALSE; Depth = -1; // parse the file while (flag == FALSE) { fgets(s, 1024, fp); sscanf(s, "%s", q); // Deal with flag for file format version if (_strnicmp(q, "[format]", 8) == 0) { double vers; v = StripKey(s); sscanf(v, "%lf", &vers); if (((int)vers) != 1) MsgBox("File is from a different version of Bela\nTrying to read anyhow..."); q[0] = NULL; } // Depth in the into-the-page direction if (_strnicmp(q, "[depth]", 7) == 0) { v = StripKey(s); sscanf(v, "%lf", &Depth); q[0] = NULL; } // Units of length used by the problem if (_strnicmp(q, "[lengthunits]", 13) == 0) { v = StripKey(s); sscanf(v, "%s", q); if (_strnicmp(q, "inches", 6) == 0) LengthUnits = 0; else if (_strnicmp(q, "millimeters", 11) == 0) LengthUnits = 1; else if (_strnicmp(q, "centimeters", 1) == 0) LengthUnits = 2; else if (_strnicmp(q, "mils", 4) == 0) LengthUnits = 4; else if (_strnicmp(q, "microns", 6) == 0) LengthUnits = 5; else if (_strnicmp(q, "meters", 6) == 0) LengthUnits = 3; q[0] = NULL; } // Problem Type (planar or axisymmetric) if (_strnicmp(q, "[problemtype]", 13) == 0) { v = StripKey(s); sscanf(v, "%s", q); if (_strnicmp(q, "planar", 6) == 0) ProblemType = 0; if (_strnicmp(q, "axisymmetric", 3) == 0) ProblemType = 1; q[0] = NULL; } // Coordinates (cartesian or polar) if (_strnicmp(q, "[coordinates]", 13) == 0) { v = StripKey(s); sscanf(v, "%s", q); if (_strnicmp(q, "cartesian", 4) == 0) Coords = 0; if (_strnicmp(q, "polar", 5) == 0) Coords = 1; q[0] = NULL; } // Comments if (_strnicmp(q, "[comment]", 9) == 0) { v = StripKey(s); // put in carriage returns; k = (int)strlen(v); for (i = 0; i < k; i++) { if ((v[i] == '\\') && (v[i + 1] == 'n')) { v[i] = 13; v[i + 1] = 10; } } for (i = 0; i < k; i++) { if (v[i] == '\"') { v = v + i + 1; i = k; } } k = (int)strlen(v); if (k > 0) { for (i = k - 1; i >= 0; i--) { if (v[i] == '\"') { v[i] = 0; i = -1; } } } ProblemNote = v; q[0] = NULL; } // properties for axisymmetric external region if (_strnicmp(q, "[extzo]", 7) == 0) { v = StripKey(s); sscanf(v, "%lf", &extZo); q[0] = NULL; } if (_strnicmp(q, "[extro]", 7) == 0) { v = StripKey(s); sscanf(v, "%lf", &extRo); q[0] = NULL; } if (_strnicmp(q, "[extri]", 7) == 0) { v = StripKey(s); sscanf(v, "%lf", &extRi); q[0] = NULL; } // Point Properties if (_strnicmp(q, "<beginpoint>", 11) == 0) { PProp.PointName = "New Point Property"; PProp.V = PProp.qp = 0; q[0] = NULL; } if (_strnicmp(q, "<pointname>", 11) == 0) { v = StripKey(s); k = (int)strlen(v); for (i = 0; i < k; i++) { if (v[i] == '\"') { v = v + i + 1; i = k; } } k = (int)strlen(v); if (k > 0) { for (i = k - 1; i >= 0; i--) { if (v[i] == '\"') { v[i] = 0; i = -1; } } } PProp.PointName = v; q[0] = NULL; } if (_strnicmp(q, "<vp>", 4) == 0) { v = StripKey(s); sscanf(v, "%lf", &PProp.V); q[0] = NULL; } if (_strnicmp(q, "<qp>", 4) == 0) { v = StripKey(s); sscanf(v, "%lf", &PProp.qp); q[0] = NULL; } if (_strnicmp(q, "<endpoint>", 9) == 0) { nodeproplist.Add(PProp); q[0] = NULL; } // Boundary Properties; if (_strnicmp(q, "<beginbdry>", 11) == 0) { BProp.BdryName = "New Boundary"; BProp.BdryFormat = 0; BProp.V = BProp.qs = 0; BProp.c0 = BProp.c1 = 0; q[0] = NULL; } if (_strnicmp(q, "<bdryname>", 10) == 0) { v = StripKey(s); k = (int)strlen(v); for (i = 0; i < k; i++) { if (v[i] == '\"') { v = v + i + 1; i = k; } } k = (int)strlen(v); if (k > 0) { for (i = k - 1; i >= 0; i--) { if (v[i] == '\"') { v[i] = 0; i = -1; } } } BProp.BdryName = v; q[0] = NULL; } if (_strnicmp(q, "<bdrytype>", 10) == 0) { v = StripKey(s); sscanf(v, "%i", &BProp.BdryFormat); q[0] = NULL; } if (_strnicmp(q, "<vs>", 4) == 0) { v = StripKey(s); sscanf(v, "%lf", &BProp.V); q[0] = NULL; } if (_strnicmp(q, "<qs>", 4) == 0) { v = StripKey(s); sscanf(v, "%lf", &BProp.qs); q[0] = NULL; } if (_strnicmp(q, "<c0>", 4) == 0) { v = StripKey(s); sscanf(v, "%lf", &BProp.c0); q[0] = NULL; } if (_strnicmp(q, "<c1>", 4) == 0) { v = StripKey(s); sscanf(v, "%lf", &BProp.c1); q[0] = NULL; } if (_strnicmp(q, "<endbdry>", 9) == 0) { lineproplist.Add(BProp); q[0] = NULL; } // Block Properties; if (_strnicmp(q, "<beginblock>", 12) == 0) { MProp.BlockName = "New Material"; MProp.ex = 1.; MProp.ey = 1.; MProp.qv = 0.; q[0] = NULL; } if (_strnicmp(q, "<blockname>", 10) == 0) { v = StripKey(s); k = (int)strlen(v); for (i = 0; i < k; i++) { if (v[i] == '\"') { v = v + i + 1; i = k; } } k = (int)strlen(v); if (k > 0) { for (i = k - 1; i >= 0; i--) { if (v[i] == '\"') { v[i] = 0; i = -1; } } } MProp.BlockName = v; q[0] = NULL; } if (_strnicmp(q, "<ex>", 4) == 0) { v = StripKey(s); sscanf(v, "%lf", &MProp.ex); q[0] = NULL; } if (_strnicmp(q, "<ey>", 4) == 0) { v = StripKey(s); sscanf(v, "%lf", &MProp.ey); q[0] = NULL; } if (_strnicmp(q, "<qv>", 4) == 0) { v = StripKey(s); sscanf(v, "%lf", &MProp.qv); q[0] = NULL; } if (_strnicmp(q, "<endblock>", 9) == 0) { blockproplist.Add(MProp); q[0] = NULL; } // Circuit Properties if (_strnicmp(q, "<beginconductor>", 16) == 0) { CProp.CircName = "New Circuit"; CProp.V = CProp.q = 0; CProp.CircType = 0; q[0] = NULL; } if (_strnicmp(q, "<conductorname>", 15) == 0) { v = StripKey(s); k = (int)strlen(v); for (i = 0; i < k; i++) { if (v[i] == '\"') { v = v + i + 1; i = k; } } k = (int)strlen(v); if (k > 0) { for (i = k - 1; i >= 0; i--) { if (v[i] == '\"') { v[i] = 0; i = -1; } } } CProp.CircName = v; q[0] = NULL; } if (_strnicmp(q, "<vc>", 4) == 0) { v = StripKey(s); sscanf(v, "%lf", &CProp.V); q[0] = NULL; } if (_strnicmp(q, "<qc>", 4) == 0) { v = StripKey(s); sscanf(v, "%lf", &CProp.q); q[0] = NULL; } if (_strnicmp(q, "<conductortype>", 15) == 0) { v = StripKey(s); sscanf(v, "%i", &CProp.CircType); q[0] = NULL; } if (_strnicmp(q, "<endconductor>", 14) == 0) { circproplist.Add(CProp); q[0] = NULL; } // Points list; if (_strnicmp(q, "[numpoints]", 11) == 0) { v = StripKey(s); sscanf(v, "%i", &k); for (i = 0; i < k; i++) { fgets(s, 1024, fp); sscanf(s, "%lf %lf %i %i %i\n", &node.x, &node.y, &t, &node.InGroup, &node.InConductor); node.BoundaryMarker = t - 1; node.InConductor--; nodelist.Add(node); } q[0] = NULL; } // read in segment list if (_strnicmp(q, "[numsegments]", 13) == 0) { v = StripKey(s); sscanf(v, "%i", &k); for (i = 0; i < k; i++) { fgets(s, 1024, fp); sscanf(s, "%i %i %lf %i %i %i %i\n", &segm.n0, &segm.n1, &segm.MaxSideLength, &t, &segm.Hidden, &segm.InGroup, &segm.InConductor); segm.BoundaryMarker = t - 1; segm.InConductor--; linelist.Add(segm); } q[0] = NULL; } // read in arc segment list if (_strnicmp(q, "[numarcsegments]", 13) == 0) { v = StripKey(s); sscanf(v, "%i", &k); for (i = 0; i < k; i++) { fgets(s, 1024, fp); sscanf(s, "%i %i %lf %lf %i %i %i %i\n", &asegm.n0, &asegm.n1, &asegm.ArcLength, &asegm.MaxSideLength, &t, &asegm.Hidden, &asegm.InGroup, &asegm.InConductor); asegm.BoundaryMarker = t - 1; asegm.InConductor--; arclist.Add(asegm); } q[0] = NULL; } // read in list of holes; if (_strnicmp(q, "[numholes]", 13) == 0) { v = StripKey(s); sscanf(v, "%i", &k); if (k > 0) { blk.BlockType = -1; blk.MaxArea = 0; for (i = 0; i < k; i++) { fgets(s, 1024, fp); sscanf(s, "%lf %lf\n", &blk.x, &blk.y); // blocklist.Add(blk); // don't add holes to the list // of block labels because it messes up the // number of block labels. } } q[0] = NULL; } // read in regional attributes if (_strnicmp(q, "[numblocklabels]", 13) == 0) { v = StripKey(s); sscanf(v, "%i", &k); for (i = 0; i < k; i++) { fgets(s, 1024, fp); sscanf(s, "%lf %lf %i %lf %i %i\n", &blk.x, &blk.y, &blk.BlockType, &blk.MaxArea, &blk.InGroup, &blk.IsExternal); blk.IsDefault = blk.IsExternal & 2; blk.IsExternal = blk.IsExternal & 1; if (blk.MaxArea < 0) blk.MaxArea = 0; else blk.MaxArea = PI*blk.MaxArea*blk.MaxArea / 4.; blk.BlockType -= 1; blocklist.Add(blk); } q[0] = NULL; } if (_strnicmp(q, "[solution]", 10) == 0) { flag = TRUE; q[0] = NULL; } } // read in meshnodes; fscanf(fp, "%i\n", &k); meshnode.SetSize(k); for (i = 0; i < k; i++) { fgets(s, 1024, fp); sscanf(s, "%lf %lf %lf %i", &mnode.x, &mnode.y, &mnode.V, &mnode.Q); meshnode.SetAt(i, mnode); } // read in elements; fscanf(fp, "%i\n", &k); meshelem.SetSize(k); for (i = 0; i < k; i++) { fgets(s, 1024, fp); sscanf(s, "%i %i %i %i", &elm.p[0], &elm.p[1], &elm.p[2], &elm.lbl); elm.blk = blocklist[elm.lbl].BlockType; meshelem.SetAt(i, elm); } // read in circuit data; fscanf(fp, "%i\n", &k); for (i = 0; i < k; i++) { fgets(s, 1024, fp); sscanf(s, "%lf %lf", &circproplist[i].V, &circproplist[i].q); } fclose(fp); // scale depth to meters for internal computations; if (Depth == -1) Depth = 1; else Depth *= LengthConv[LengthUnits]; // element centroids and radii; for (i = 0; i < meshelem.GetSize(); i++) { meshelem[i].ctr = Ctr(i); for (j = 0, meshelem[i].rsqr = 0; j < 3; j++) { b = sqr(meshnode[meshelem[i].p[j]].x - meshelem[i].ctr.re) + sqr(meshnode[meshelem[i].p[j]].y - meshelem[i].ctr.im); if (b > meshelem[i].rsqr) meshelem[i].rsqr = b; } } // Find flux density in each element; for (i = 0; i < meshelem.GetSize(); i++) GetElementD(i); // Find extreme values of A; A_Low = meshnode[0].V; A_High = meshnode[0].V; for (i = 1; i<meshnode.GetSize(); i++) { if (meshnode[i].V>A_High) A_High = meshnode[i].V; if (meshnode[i].V < A_Low) A_Low = meshnode[i].V; } // save default values for extremes of A A_lb = A_Low; A_ub = A_High; // build list of elements connected to each node; // allocate connections list; NumList = (int *)calloc(meshnode.GetSize(), sizeof(int)); ConList = (int **)calloc(meshnode.GetSize(), sizeof(int *)); // find out number of connections to each node; for (i = 0; i < meshelem.GetSize(); i++) { for (j = 0; j < 3; j++) NumList[meshelem[i].p[j]]++; } // allocate space for connections lists; for (i = 0; i < meshnode.GetSize(); i++) ConList[i] = (int *)calloc(NumList[i], sizeof(int)); // build list; for (i = 0; i < meshnode.GetSize(); i++) NumList[i] = 0; for (i = 0; i < meshelem.GetSize(); i++) { for (j = 0; j < 3; j++) { k = meshelem[i].p[j]; ConList[k][NumList[k]] = i; NumList[k]++; } } // sort each connection list so that the elements are // arranged in a counter-clockwise order CComplex u0, u1; int swa; BOOL flg; for (i = 0; i < meshnode.GetSize(); i++) { for (j = 0; j < NumList[i]; j++) { for (k = 0, flg = FALSE; k < NumList[i] - j - 1; k++) { u0 = meshelem[ConList[i][k]].ctr - meshnode[i].CC(); u1 = meshelem[ConList[i][k + 1]].ctr - meshnode[i].CC(); if (arg(u0) > arg(u1)) { swa = ConList[i][k]; ConList[i][k] = ConList[i][k + 1]; ConList[i][k + 1] = swa; flg = TRUE; } } if (!flg) j = NumList[i]; } } // Find extreme values of potential d_PlotBounds[0][0] = A_Low; d_PlotBounds[0][1] = A_High; PlotBounds[0][0] = d_PlotBounds[0][0]; PlotBounds[0][1] = d_PlotBounds[0][1]; for (i = 0; i < meshelem.GetSize(); i++) GetNodalD(meshelem[i].d, i); // Find extreme values of D and E; i = 0; while (blocklist[meshelem[i].lbl].IsExternal) i++; d_PlotBounds[1][0] = abs(D(i)); d_PlotBounds[1][1] = d_PlotBounds[1][0]; d_PlotBounds[2][0] = abs(E(0)); d_PlotBounds[2][1] = d_PlotBounds[2][0]; for (i = 0; i < meshelem.GetSize(); i++) { if (!blocklist[meshelem[i].lbl].IsExternal) { b = abs(D(i)); if (b > d_PlotBounds[1][1]) d_PlotBounds[1][1] = b; if (b < d_PlotBounds[1][0]) d_PlotBounds[1][0] = b; b = abs(E(i)); if (b > d_PlotBounds[2][1]) d_PlotBounds[2][1] = b; if (b < d_PlotBounds[2][0]) d_PlotBounds[2][0] = b; } } PlotBounds[1][0] = d_PlotBounds[1][0]; PlotBounds[1][1] = d_PlotBounds[1][1]; PlotBounds[2][0] = d_PlotBounds[2][0]; PlotBounds[2][1] = d_PlotBounds[2][1]; // Choose bounds based on the type of contour plot // currently in play POSITION pos = GetFirstViewPosition(); CbelaviewView *theView = (CbelaviewView *)GetNextView(pos); // Build adjacency information for each element. FindBoundaryEdges(); // Check to see if any regions are multiply defined // (i.e. tagged by more than one block label). If so, // display an error message and mark the problem blocks. for (k = 0, bMultiplyDefinedLabels = FALSE; k < blocklist.GetSize(); k++) { if ((i = InTriangle(blocklist[k].x, blocklist[k].y)) >= 0) { if (meshelem[i].lbl != k) { blocklist[meshelem[i].lbl].IsSelected = TRUE; if (!bMultiplyDefinedLabels) { CString msg; msg = "Some regions in the problem have been defined\n"; msg += "by more than one block label. These potentially\n"; msg += "problematic regions will appear as selected in\n"; msg += "the initial view."; MsgBox(msg); bMultiplyDefinedLabels = TRUE; } } } } FirstDraw = TRUE; return TRUE; }
void CbelaviewDoc::LineIntegral(int inttype, double *z) { // inttype Integral // 0 E.t // 1 D.n // 2 Contour length // 3 Stress Tensor Force // 4 Stress Tensor Torque // inttype==0 => E.t if(inttype==0){ CPointVals u; int k; k=(int) contour.GetSize(); GetPointValues(contour[0].re,contour[0].im, u); z[0] = u.V; GetPointValues(contour[k-1].re,contour[k-1].im,u); z[0]-= u.V; } // inttype==1 => D.n if(inttype==1){ CComplex n,t,pt; CPointVals v; double dz,u,d,Dn; int i,j,k,m,elm; int NumPlotPoints=d_LineIntegralPoints; BOOL flag; z[0]=0; z[1]=0; for(k=1;k<contour.GetSize();k++) { dz=abs(contour[k]-contour[k-1])/((double) NumPlotPoints); for(i=0,elm=-1;i<NumPlotPoints;i++) { u=(((double) i)+0.5)/((double) NumPlotPoints); pt=contour[k-1] + u*(contour[k] - contour[k-1]); t=contour[k]-contour[k-1]; t/=abs(t); n=I*t; pt+=n*1.e-06; if (elm<0) elm=InTriangle(pt.re,pt.im); else if (InTriangleTest(pt.re,pt.im,elm)==FALSE) { flag=FALSE; for(j=0;j<3;j++) for(m=0;m<NumList[meshelem[elm].p[j]];m++) { elm=ConList[meshelem[elm].p[j]][m]; if (InTriangleTest(pt.re,pt.im,elm)==TRUE) { flag=TRUE; m=100; j=3; } } if (flag==FALSE) elm=InTriangle(pt.re,pt.im); } if(elm>=0) flag=GetPointValues(pt.re,pt.im,elm,v); else flag=FALSE; if(flag==TRUE){ Dn = Re(v.D/n); if (ProblemType==AXISYMMETRIC) d=2.*PI*pt.re*sq(LengthConv[LengthUnits]); else d=Depth*LengthConv[LengthUnits]; z[0]+=(Dn*dz*d); z[1]+=dz*d; } } } z[1]=z[0]/z[1]; // Average D.n over the surface; } // inttype==2 => Contour Length if(inttype==2){ int i,k; k=(int) contour.GetSize(); for(i=0,z[0]=0;i<k-1;i++) z[0]+=abs(contour[i+1]-contour[i]); z[0]*=LengthConv[LengthUnits]; if(ProblemType==1){ for(i=0,z[1]=0;i<k-1;i++) z[1]+=(PI*(contour[i].re+contour[i+1].re)* abs(contour[i+1]-contour[i])); z[1]*=pow(LengthConv[LengthUnits],2.); } else{ z[1]=z[0]*Depth; } } // inttype==3 => Stress Tensor Force if(inttype==3){ CComplex n,t,pt; double Hn,Bn,BH,dF1,dF2; CPointVals v; double dz,dza,u; int i,j,k,m,elm; int NumPlotPoints=d_LineIntegralPoints; BOOL flag; for(i=0;i<4;i++) z[i]=0; for(k=1;k<contour.GetSize();k++) { dz=abs(contour[k]-contour[k-1])/((double) NumPlotPoints); for(i=0,elm=-1;i<NumPlotPoints;i++) { u=(((double) i)+0.5)/((double) NumPlotPoints); pt=contour[k-1] + u*(contour[k] - contour[k-1]); t=contour[k]-contour[k-1]; t/=abs(t); n=I*t; pt+=n*1.e-06; if (elm<0) elm=InTriangle(pt.re,pt.im); else if (InTriangleTest(pt.re,pt.im,elm)==FALSE) { flag=FALSE; for(j=0;j<3;j++) for(m=0;m<NumList[meshelem[elm].p[j]];m++) { elm=ConList[meshelem[elm].p[j]][m]; if (InTriangleTest(pt.re,pt.im,elm)==TRUE) { flag=TRUE; m=100; j=3; } } if (flag==FALSE) elm=InTriangle(pt.re,pt.im); } if(elm>=0) flag=GetPointValues(pt.re,pt.im,elm,v); else flag=FALSE; if(flag==TRUE) { Hn= Re(v.E/n); Bn= Re(v.D/n); BH= Re(v.D*conj(v.E)); dF1=v.E.re*Bn + v.D.re*Hn - n.re*BH; dF2=v.E.im*Bn + v.D.im*Hn - n.im*BH; dza=dz*LengthConv[LengthUnits]; if(ProblemType==1){ dza*=2.*PI*pt.re*LengthConv[LengthUnits]; dF1=0; } else dza*=Depth; z[0]+=(dF1*dza/2.); z[1]+=(dF2*dza/2.); } } } } // inttype==4 => Stress Tensor Torque if(inttype==4){ CComplex n,t,pt; double Hn,Bn,BH,dF1,dF2,dT; CPointVals v; double dz,dza,u; int i,j,k,m,elm; int NumPlotPoints=d_LineIntegralPoints; BOOL flag; z[0]=z[1]=0; for(k=1;k<contour.GetSize();k++) { dz=abs(contour[k]-contour[k-1])/((double) NumPlotPoints); for(i=0,elm=-1;i<NumPlotPoints;i++) { u=(((double) i)+0.5)/((double) NumPlotPoints); pt=contour[k-1]+ u*(contour[k] - contour[k-1]); t=contour[k]-contour[k-1]; t/=abs(t); n=I*t; pt+=n*1.e-6; if (elm<0) elm=InTriangle(pt.re,pt.im); else if (InTriangleTest(pt.re,pt.im,elm)==FALSE) { flag=FALSE; for(j=0;j<3;j++) for(m=0;m<NumList[meshelem[elm].p[j]];m++) { elm=ConList[meshelem[elm].p[j]][m]; if (InTriangleTest(pt.re,pt.im,elm)==TRUE) { flag=TRUE; m=100; j=3; } } if (flag==FALSE) elm=InTriangle(pt.re,pt.im); } if(elm>=0) flag=GetPointValues(pt.re,pt.im,elm,v); else flag=FALSE; if(flag==TRUE) { Hn= Re(v.E/n); Bn= Re(v.D/n); BH= Re(v.D*conj(v.E)); dF1=v.E.re*Bn + v.D.re*Hn - n.re*BH; dF2=v.E.im*Bn + v.D.im*Hn - n.im*BH; dT= pt.re*dF2 - dF1*pt.im; dza=dz*LengthConv[LengthUnits]*LengthConv[LengthUnits]; z[0]+=(dT*dza*Depth/2.); } } } } return; }
void CbelaviewDoc::GetLineValues(CXYPlot &p,int PlotType,int NumPlotPoints) { double *q,z,u,dz; CComplex pt,n,t; int i,j,k,m,elm; CPointVals v; BOOL flag; q=(double *)calloc(contour.GetSize(),sizeof(double)); for(i=1,z=0.;i<contour.GetSize();i++) { z+=abs(contour[i]-contour[i-1]); q[i]=z; } dz=z/(NumPlotPoints-1); /* m_XYPlotType.AddString("Potential"); m_XYPlotType.AddString("|B| (Magnitude of flux density)"); m_XYPlotType.AddString("B . n (Normal flux density)"); m_XYPlotType.AddString("B . t (Tangential flux density)"); m_XYPlotType.AddString("|H| (Magnitude of field intensity)"); m_XYPlotType.AddString("H . n (Normal field intensity)"); m_XYPlotType.AddString("H . t (Tangential field intensity)"); m_XYPlotType.AddString("J_eddy */ switch (PlotType) { case 0: p.Create(NumPlotPoints,2); strcpy(p.lbls[1],"Potential, Volts"); break; case 1: p.Create(NumPlotPoints,2); strcpy(p.lbls[1],"|D|, C/m^2"); break; case 2: p.Create(NumPlotPoints,2); strcpy(p.lbls[1],"D.n, C/m^2"); break; case 3: p.Create(NumPlotPoints,2); strcpy(p.lbls[1],"D.t, C/m^2"); break; case 4: p.Create(NumPlotPoints,2); strcpy(p.lbls[1],"|E|, V/m"); break; case 5: p.Create(NumPlotPoints,2); strcpy(p.lbls[1],"E.n, V/m"); break; case 6: p.Create(NumPlotPoints,2); strcpy(p.lbls[1],"E.t, V/m"); break; default: p.Create(NumPlotPoints,2); break; } switch(LengthUnits){ case 1: strcpy(p.lbls[0],"Length, mm"); break; case 2: strcpy(p.lbls[0],"Length, cm"); break; case 3: strcpy(p.lbls[0],"Length, m"); break; case 4: strcpy(p.lbls[0],"Length, mils"); break; case 5: strcpy(p.lbls[0],"Length, um"); break; default: strcpy(p.lbls[0],"Length, inches"); break; } for(i=0,k=1,z=0,elm=-1;i<NumPlotPoints;i++,z+=dz) { while((z>q[k]) && (k<(contour.GetSize()-1))) k++; u=(z-q[k-1])/(q[k]-q[k-1]); pt=contour[k-1]+u*(contour[k]-contour[k-1]); t=contour[k]-contour[k-1]; t/=abs(t); n = I*t; pt+=(n*1.e-06); if (elm<0) elm=InTriangle(pt.re,pt.im); else if (InTriangleTest(pt.re,pt.im,elm)==FALSE) { flag=FALSE; for(j=0;j<3;j++) for(m=0;m<NumList[meshelem[elm].p[j]];m++) { elm=ConList[meshelem[elm].p[j]][m]; if (InTriangleTest(pt.re,pt.im,elm)==TRUE) { flag=TRUE; m=100; j=3; } } if (flag==FALSE) elm=InTriangle(pt.re,pt.im); } if(elm>=0) flag=GetPointValues(pt.re,pt.im,elm,v); else flag=FALSE; p.M[i][0]=z; if(flag!=FALSE) { switch (PlotType) { case 0: p.M[i][1]=v.V; break; case 1: p.M[i][1]=abs(v.D); break; case 2: p.M[i][1]=Re(v.D/n); break; case 3: p.M[i][1]=Re(v.D/t); break; case 4: p.M[i][1]=abs(v.E); break; case 5: p.M[i][1]=Re(v.E/n); break; case 6: p.M[i][1]=Re(v.E/t); break; default: p.M[i][1]=0; break; } } } free(q); }