public static double FaceWeightFactor(Element main, Element e,Face face) { double wf = 0; Vector2 dcf = face.centroid - main.centroid; Vector2 dff = e.centroid - face.centroid; wf = (dcf * face.normal) / ((dcf +dff) * face.normal); return wf; }
/* public void SetBoundary(int side, BoundaryType boundarytype, double value, double hcoeff = 0) { faces[side].SetBoundary(boundarytype, value, hcoeff); } */ public int FaceLocalId(Face face) { for (int n = 0; n < faces.Length; n++) { if (faces[n] == face) return n; } return -1; }
public bool Create(string filename_) { double[,] points=null ; double[,] polys = null; double[,] bound = null; Dictionary<string, Face> facedic = new Dictionary<string, Face>(); if (!LoadFromFile(filename_, ref points, ref polys, ref bound)) return false; count = 0; SetParameters(); elementcount = polys.GetLength(1); int vertexcount = polys.GetLength(0)-1; elements = new Element[elementcount]; int faceid = 0; int e = 0; for (e = 0; e < elementcount; e++) { Element elem; elements[e] = new Element(vertexcount); elem = elements[e]; elem.id = e; elem.k = 1; Vector2[] vertex = new Vector2[vertexcount]; for (int v = 0; v < vertexcount; v++) { int pointindex = (int)polys[v, e]; vertex[v] = new Vector2(points[0, pointindex], points[1, pointindex]); int p1index = pointindex; int p2index = 0; if (v < vertexcount - 1) p2index = (int)polys[v + 1, e]; else p2index = (int)polys[0, e]; int p1 = p1index; int p2 = p2index; string facestr =Face.GetFaceStrId(p1index,p2index); if (!facedic.ContainsKey(facestr)) { Face face = new Face(new Vector2(points[0, p1], points[1, p1]), new Vector2(points[0, p2], points[1, p2])); face.id = faceid; face.pointid1=p1; face.pointid2=p2; face.owner = elem; faceid++; facedic.Add(facestr, face); elem.faces[v] = face; } else { Face face = facedic[facestr]; face.nbelem = elem; elem.faces[v] = face; Element owner = face.owner; elem.nbs[v] = owner; owner.nbs[owner.FaceLocalId(face)] = elem; } } elem.SetPolygon(vertex); elem.PreCalc(); } faces = new Face[facedic.Count]; bndfaces = new Face[bound.GetLength(1)]; foreach (var pair in facedic) { Face face = pair.Value; faces[face.id] = face; } for (e = 0; e < elementcount; e++) elements[e].Calc(); int f; for (f = 0; f < bound.GetLength(1); f++) { string facestr = Face.GetFaceStrId((int)bound[0, f], (int)bound[1, f]); Face face = facedic[facestr]; face.bnddomain = (int)bound[5, f]; face.bndgroup = (int)bound[4, f]; face.isboundary = true; bndfaces[f]=face; } SetInitialBoundary(); // for (e = 0; e < elementcount; e++) // elements[e].CalcFluxes(); return true; }
public static double FaceWeightFactorSimple(Element main, Element e, Face face) { double wf = main.volume / (main.volume + e.volume); return wf; }
// only one face between two nodes, first node is face owner void CreateFaces() { int nf = 0; for (nf = 0; nf < vertex.Length; nf++) { if (faces[nf] == null) { if(nf==vertex.Length-1) faces[nf] = new Face(vertex[nf], vertex[0]); else faces[nf] = new Face(vertex[nf], vertex[nf+1]); faces[nf].owner = this; if (nbs[nf] != null) faces[nf].nbelem = nbs[nf]; } } }
// -------------------- COMPUTE --------------------------------- // -------------------- COMPUTE --------------------------------- public void Calc() { double bc, ac; double flux; double sumflux; double[] aa = new double[3]; double[] bb = new double[3]; int e; int iter = 0; for (iter = 0; iter < 225; iter++) { for (e = 0; e < elementcount; e++) { Element elem = elements[e]; int nf; bc = 0; ac = 0; sumflux = 0; flux = 0; aa[0] = 0; aa[1] = 0; aa[2] = 0; bb[0] = 0; bb[1] = 0; bb[2] = 0; for (nf = 0; nf < Element.FACEMAX; nf++) { Face face = elem.faces[nf]; Element nb = elem.nbs[nf]; // int nw = elem.facenormals[FaceType.WEST]; // int ne = elem.facenormals[FaceType.EAST]; // fluxV = 0; if (face.isboundary) { if (face.boundaryType == BoundaryType.BND_CONST) { flux = face.k * (face.area / elem.nodedistances[nf]); ac += flux; bc += flux * face.bndu; bb[nf] = flux; } else if (face.boundaryType == BoundaryType.BND_FLUX) { double sf = face.area; flux = face.bndflux * sf; bc += flux; bb[nf] = flux; } } else { flux = -face.k * (face.area / elem.nodedistances[nf]); sumflux += flux * nb.u; ac += -flux; aa[nf] = -flux; } } for (int ii = 0; ii < 3; ii++) { aa[ii] = aa[ii] / Math.Sqrt(3); bb[ii] = bb[ii] / Math.Sqrt(3); } double acc = ac / Math.Sqrt(3); double bcc = bc / Math.Sqrt(3); elem.u = (bc - sumflux) / ac; } } }