void createAngleSurForce(FeScanner es) { // int nFaceNodes = es.readInt(); int[] fnode = new int[nFaceNodes]; for (int i = 0; i < nFaceNodes; i++) { fnode[i] = es.readInt(); } double angle = es.readDouble(); String s = es.next().ToLower(); int dir = UTIL.direction(s); if (dir == -1) { UTIL.errorMsg("surForce direction should be x/y/z/n. Specified:" + s); } double force = es.readDouble(); sg.getSurfacebyAngle(fnode, angle); IEnumerator <int> iase = sg.anglSurfaceElems.GetEnumerator(); IEnumerator <int[]> iasf = sg.angleSurface.GetEnumerator(); //Console.WriteLine(sg.angleSurface.Count); for (int i = 0; i < sg.angleSurface.Count; i++) { iase.MoveNext(); iasf.MoveNext(); //Console.WriteLine(iase.Current + " : " + iasf.Current[0] + " " + iasf.Current[1] + " " + iasf.Current[2] + " " + iasf.Current[3] + " "); surForces.Add(new ElemFaceLoad(iase.Current, iasf.Current.Length, dir, iasf.Current, force)); } }
// Read element type, material and connectivities // for all elements private void readElemData(FeScanner es) { if (nEl == 0) { UTIL.errorMsg("nEl should be defined before elCon"); } elems = new Element[nEl]; for (int iel = 0; iel < nEl; iel++) { // Element type String s = es.next().ToLower(); elems[iel] = Element.newElement(s); // Element material String elMat = es.next(); elems[iel].setElemMaterial(elMat); //Element Area or Thickness if Truss or Plane 2D or Shell if (s.Equals(Element.elements.truss22.ToString()) || s.Equals(Element.elements.truss32.ToString())) { elems[iel].A = es.readDouble(); } else if (s.Equals(Element.elements.quad4.ToString()) || s.Equals(Element.elements.quad8r.ToString())) { elems[iel].t = es.readDouble(); } // Element connectivities int nind = elems[iel].ind.Length; for (int i = 0; i < nind; i++) { elCon[i] = es.readInt(); } elems[iel].setElemConnectivities(elCon, nind); } }
void createElemAngleSurForce(FeScanner es) { String s = es.next().ToLower(); int dir = UTIL.direction(s); if (dir == -1) { UTIL.errorMsg("surForce direction should be x/y/z/n. Specified:" + s); } double force = es.readDouble(); double angle = es.readDouble(); int nFaceNodes = es.readInt(); int[] f = new int[nFaceNodes]; for (int i = 0; i < nFaceNodes; i++) { f[i] = es.readInt(); } int nElem = es.readInt(); int[] e = new int[nElem]; for (int i = 0; i < nElem; i++) { e[i] = es.readInt() - 1; } sg.getSurfacebyAngle(f, angle); IEnumerator <int> iase = sg.anglSurfaceElems.GetEnumerator(); IEnumerator <int[]> iasf = sg.angleSurface.GetEnumerator(); //foreach(int[] fss in sg.angleSurface) //{ // iase.MoveNext(); // Console.Write(iase.Current + " : "); // for (int k = 0; k < fss.Length; k++) // Console.Write("{0,6}", fss[k]); // Console.WriteLine(); //} foreach (int el in sg.anglSurfaceElems) { iasf.MoveNext(); for (int j = 0; j < e.Length; j++) { if (el == e[j]) { surForces.Add(new ElemFaceLoad(el, iasf.Current.Length, dir, iasf.Current, force)); } } } }
// Create data for distributed surface load // specified inside a box private void createBoxSurForces(FeScanner es) { int[][] faces; String s = es.next().ToLower(); int dir = UTIL.direction(s); if (dir == -1) { UTIL.errorMsg("boxSurForce direction should be x/y/z/n. Specified:" + s); } if (!es.hasNextDouble()) { UTIL.errorMsg("boxSurForce value is not a double: " + es.next()); } double force = es.nextDouble(); for (int i = 0; i < 2; i++) { for (int j = 0; j < fem.nDim; j++) { box[i][j] = es.readDouble(); } } for (int iel = 0; iel < fem.nEl; iel++) { Element el = fem.elems[iel]; faces = el.getElemFaces(); //FACE: foreach (int[] face in faces) { int nNodes = face.Length; for (int inod = 0; inod < nNodes; inod++) { iw[inod] = 0; } for (int inod = 0; inod < nNodes; inod++) { int iGl = el.ind[face[inod]]; if (iGl > 0) { for (int j = 0; j < fem.nDim; j++) { double x = fem.getNodeCoord(iGl - 1, j); if (x < box[0][j] || x > box[1][j]) { goto FACE; } } iw[inod] = iGl; } } surForces.Add(new ElemFaceLoad(iel, nNodes, dir, iw, force)); FACE : { } } } }
// Read results from a file. // displ - displacements for the finite element model (out) public void readResults(String resultFile, double[] displ) { if (resultFile == null) { return; } FeScanner RD = new FeScanner(resultFile); // Read displacements RD.moveAfterLineWithWord("node"); for (int i = 0; i < fem.nNod; i++) { RD.readInt(); for (int j = 0; j < fem.nDim; j++) { displ[fem.nDim * i + j] = RD.readDouble(); } } // Read stresses for (int iel = 0; iel < fem.nEl; iel++) { RD.moveAfterLineWithWord("el"); foreach (StressContainer aStr in fem.elems[iel].str) { for (int i = 0; i < 2 * fem.nDim; i++) { if (fem.nDim == 3) { aStr.sStress[i] = RD.readDouble(); } else { if (i == 2) { aStr.sStress[i + 1] = RD.readDouble(); } else if (i == 3) { aStr.sStress[i - 1] = RD.readDouble(); } else { aStr.sStress[i] = RD.readDouble(); } } } aStr.sEpi = RD.readDouble(); } } RD.close(); }
// Read data for surface forces (element face loading): // direction, iel, nFaceNodes, faceNodes, forcesAtNodes. private void readSurForces(FeScanner es) { String s = es.next().ToLower(); int dir = UTIL.direction(s); if (dir == -1) { UTIL.errorMsg("surForce direction should be x/y/z/n. Specified:" + s); } int iel = es.readInt(); int nFaceNodes = es.readInt(); for (int i = 0; i < nFaceNodes; i++) { iw[i] = es.readInt(); } for (int i = 0; i < nFaceNodes; i++) { dw[i] = es.readDouble(); } surForces.Add(new ElemFaceLoad(iel - 1, nFaceNodes, dir, iw, dw)); }
// Create data for constrained displacements // specified inside a box private void createBoxConstrDisplacements(FeScanner es) { String s = es.next().ToLower(); int idf = UTIL.direction(s); if (idf == -1) { UTIL.errorMsg("boxConstrDispl direction should be x/y/z. Specified:" + s); } if (!es.hasNextDouble()) { UTIL.errorMsg("boxConstrDispl value is not a double: " + es.next()); } double vd = es.nextDouble(); for (int i = 0; i < 2; i++) { for (int j = 0; j < nDim; j++) { box[i][j] = es.readDouble(); } } //NODE: for (int i = 0; i < nNod; i++) { for (int j = 0; j < nDim; j++) { double x = getNodeCoord(i, j); if (x < box[0][j] || x > box[1][j]) { goto NODE; } } defDs.Add(new Dof(nDim * i + idf, vd)); NODE : { } } }
private void readDataFile(FeScanner es) { vars name = vars.NONE; String s; Material mat; it = defDs.GetEnumerator(); while (es.hasNext()) { varName = es.next(); String varname = varName.ToLower(); if (varname.Equals("#")) { es.nextLine(); continue; } try { name = (vars)System.Enum.Parse(typeof(vars), varname);//vars.valueOf(varname); //Console.WriteLine("hmm"); } catch (Exception E) { UTIL.errorMsg("Variable name is not found: " + varName); } switch (name) { case vars.nel: nEl = es.readInt(); //Console.WriteLine("FEMODEL: "+nEl.ToString()); break; case vars.nnod: nNod = es.readInt(); //Console.WriteLine("FEMODEL: " + nNod.ToString()); break; case vars.ndim: nDim = es.readInt(); nDf = nDim; //Console.WriteLine("FEMODEL: " + nDf.ToString()); break; case vars.stressstate: s = es.next().ToLower(); try { stressState = (StrStates)System.Enum.Parse(typeof(StrStates), s); //StrStates.valueOf(s); } catch (Exception E) { UTIL.errorMsg("stressState has forbidden value: " + s); } if (stressState != StrStates.threed) { nDim = nDf = 2; } else { nDim = nDf = 3; } //Console.WriteLine("FEMODEL: " + stressState.ToString()); break; case vars.physlaw: s = es.next().ToLower(); try { physLaw = (PhysLaws)System.Enum.Parse(typeof(PhysLaws), s); //PhysLaws.valueOf(s); } catch (Exception E) { UTIL.errorMsg("physLaw has forbidden value: " + s); } //Console.WriteLine("FEMODEL: " + s.ToString()); break; case vars.solver: s = es.next().ToLower(); try { Solver.solver = (Solver.solvers)System.Enum.Parse(typeof(Solver.solvers), s); //Solver.solvers.valueOf(s); } catch (Exception E) { UTIL.errorMsg("solver has forbidden value: " + s); } //Console.WriteLine("FEMODEL: " + s.ToString()); break; case vars.elcon: readElemData(es); break; case vars.nodcoord: if (nNod == 0 || nDim == 0) { UTIL.errorMsg("nNod and nDim should be specified before nodCoord"); } nEq = nNod * nDim; // Nodal coordinates newCoordArray(); for (int i = 0; i < nNod; i++) { for (int j = 0; j < nDim; j++) { setNodeCoord(i, j, es.readDouble()); } } break; case vars.material: String matname = es.next(); mat = Material.newMaterial(physLaw.ToString(), stressState.ToString()); double e = es.readDouble(); double nu = es.readDouble(); double alpha = es.readDouble(); mat.setElasticProp(e, nu, alpha); if (physLaw == PhysLaws.elplastic) { double sY = es.readDouble(); double km = es.readDouble(); double mm = es.readDouble(); mat.setPlasticProp(sY, km, mm); } materials.Add(matname, mat); //Console.WriteLine("FEMODEL: " + matname); break; case vars.constrdispl: readConstrDisplacements(es); break; case vars.boxconstrdispl: createBoxConstrDisplacements(es); break; case vars.thermalloading: s = es.next(); if (s.ToLower().Equals("y")) { thermalLoading = true; } else if (s.ToLower().Equals("n")) { thermalLoading = false; } else { UTIL.errorMsg("thermalLoading should be y/n. Specified: " + s); } break; case vars.includefile: s = es.next(); FeScanner R = new FeScanner(s); readDataFile(R); break; case vars.trussarea: readTrussArea(es); break; case vars.end: return; } } }
static void readDataFile(FeScanner RD) { vars name = vars.none; while (RD.hasNext()) { String varName = RD.next(); String varNameLower = varName.ToLower(); if (varName.Equals("#")) { RD.nextLine(); continue; } try { name = (vars)System.Enum.Parse(typeof(vars), varNameLower); } catch (Exception e) { UTIL.errorMsg("Variable name is not found: " + varName); } switch (name) { case vars.meshfile: meshFile = RD.next(); break; case vars.resultfile: resultFile = RD.next(); break; case vars.parm: try { varName = RD.next(); parm = (parms)System.Enum.Parse(typeof(parms), varName.ToLower()); } catch (Exception e) { UTIL.errorMsg("No such result parameter: " + varName); } break; case vars.showedges: showEdges = RD.next().Equals("y"); break; case vars.shownodes: showNodes = RD.next().Equals("y"); break; case vars.ndivmin: nDivMin = RD.readInt(); break; case vars.ndivmax: nDivMax = RD.readInt(); break; case vars.fmin: fMin = RD.readDouble(); break; case vars.fmax: fMax = RD.readDouble(); break; case vars.ncontours: nContours = RD.readInt(); break; case vars.deformscale: deformScale = RD.readDouble(); break; case vars.end: return; default: return; } } }
// Read data fragment for load increment. // newLoad = true - beginning of new load, // = false - continuation of load. // returns true if load data has been read private bool readDataFile(FeScanner es, bool newLoad) { if (newLoad) { scaleLoad = 0; nodForces = new List <Dof>(); itnf = nodForces.GetEnumerator(); surForces = new List <ElemFaceLoad>(); itsf = surForces.GetEnumerator(); if (fem.thermalLoading) { for (int i = 0; i < dtemp.Length; i++) { dtemp[i] = 0.0; } } for (int i = 0; i < dDispl.Length; i++) { dDispl[i] = 0.0; } } if (!es.hasNext()) { return(false); // No load data } vars name = vars.NONE; String s; while (es.hasNext()) { String varName = es.next(); String varNameLower = varName.ToLower(); if (varName.Equals("#")) { es.nextLine(); continue; } try { name = (vars)System.Enum.Parse(typeof(vars), varNameLower); //vars.valueOf(varNameLower); } catch (Exception E) { UTIL.errorMsg("Variable name is not found: " + varName); } switch (name) { case vars.loadstep: loadStepName = es.next(); //Console.WriteLine("FELOAD " + loadStepName.ToString()); break; case vars.scaleload: scaleLoad = es.readDouble(); //Console.WriteLine("FELOAD " + scaleLoad.ToString()); break; case vars.residtolerance: residTolerance = es.readDouble(); //Console.WriteLine("FELOAD " + residTolerance.ToString()); break; case vars.maxiternumber: maxIterNumber = es.readInt(); //Console.WriteLine("FELOAD " + maxIterNumber.ToString()); break; case vars.nodforce: readNodalForces(es); break; case vars.surforce: readSurForces(es); break; case vars.boxsurforce: createBoxSurForces(es); break; case vars.nodtemp: dtemp = new double[fem.nNod]; for (int i = 0; i < fem.nNod; i++) { dtemp[i] = es.readDouble(); } break; case vars.includefile: s = es.next().ToLower(); FeScanner R = new FeScanner(s); readDataFile(R, false); break; case vars.anglesurforce: createAngleSurForce(es); break; case vars.surforcelist: createSurForceList(es); break; case vars.elemanglesurforce: createElemAngleSurForce(es); break; case vars.end: return(true); } } return(true); }