public static void readData(FeScanner RD) { readDataFile(RD); FeScanner fes = new FeScanner(meshFile); fem = new FeModel(fes, null); Element.fem = fem; fem.readData(); if (resultFile != null) { displ = new double[fem.nNod * fem.nDf]; FeStress stress = new FeStress(fem); stress.readResults(resultFile, displ); if (deformScale > 0) { showDeformShape = true; } drawContours = VisData.parm != VisData.parms.none; } }
public CSFEM() { UTIL.printDate(PR); FeModel fem = new FeModel(RD, PR); Element.fem = fem; fem.readData(); //Console.WriteLine(fem.nEl); PR.Write(Environment.NewLine + "Number of elements nEl = {0,9}" + Environment.NewLine + "Number of nodes nNod = {1,9}" + Environment.NewLine + "Number of dimensions nDim = {2,9}" + Environment.NewLine, fem.nEl, fem.nNod, fem.nDim); long t0 = Environment.TickCount; Solver solver = Solver.newSolver(fem); solver.assembleGSM(); PR.WriteLine("Memory for global matrix: {0,9:0.00} MB" + Environment.NewLine, Solver.lengthOfGSM * 8.0e-6); FeLoad load = new FeLoad(fem); Element.load = load; FeStress stress = new FeStress(fem); // Load step loop while (load.readData()) { load.assembleRHS(); int iter = 0; // Equilibrium iterations do { iter++; int its = solver.solve(FeLoad.RHS); if (its > 0) { PR.Write(Environment.NewLine + "Solver: {0} iterations" + Environment.NewLine, its); } stress.computeIncrement(); } while (!stress.equilibrium(iter)); stress.accumulate(); stress.writeResults(); PR.WriteLine("Loadstep {0}", FeLoad.loadStepName); if (iter > 1) { PR.WriteLine("{0,5} iterations, " + "Relative residual norm = {1,9:E6}", iter, FeStress.relResidNorm); } PR.Write(Environment.NewLine); } PR.Write(Environment.NewLine + "Solution time = {0:0.00} s" + Environment.NewLine, (Environment.TickCount - t0) * 0.001); }
public static void CsfeaToVtk_Main(String[] args) { Console.Clear(); Console.WriteLine(); Console.WriteLine("***************************************************"); Console.WriteLine("* C# Finite Element Analysis - Post-Processor *"); Console.WriteLine("* ------------------------------------------- *"); Console.WriteLine("* Copyright © Ravinder Singh, 2017. *"); Console.WriteLine("* License: Apache v2.0 License. *"); Console.WriteLine("* For further information on this software *"); Console.WriteLine("* email : [email protected]. *"); Console.WriteLine("***************************************************"); Console.WriteLine(); string[] w; switch (args.Length) { case 1: w = args[0].Split('.'); meshFile = args[0]; outFile = w[0] + "_msh" + ".vtk"; break; case 2: w = args[1].Split('.'); meshFile = args[0]; resultFile = args[1]; outFile = w[0] + "_" + w[1] + ".vtk"; break; default: break; } fes = new FeScanner(meshFile); fem = new FeModel(fes, null); Element.fem = fem; fem.readData(); WR = new FePrintWriter().getPrinter(outFile); WR.WriteLine("# vtk DataFile Version 3.1"); WR.WriteLine(outFile); WR.WriteLine("ASCII\nDATASET UNSTRUCTURED_GRID"); WR.WriteLine("POINTS {0} DOUBLE", fem.nNod); int ElemConnectNodeCount = 0; for (int iel = 0; iel < fem.nEl; iel++) { if (fem.elems[iel].name.Equals("hex20") || fem.elems[iel].name.Equals("hex20r")) { ElemConnectNodeCount += 21; } if (fem.elems[iel].name.Equals("hex8") || fem.elems[iel].name.Equals("hex8r")) { ElemConnectNodeCount += 9; } if (fem.elems[iel].name.Equals("quad8") || fem.elems[iel].name.Equals("quad8r")) { ElemConnectNodeCount += 9; } if (fem.elems[iel].name.Equals("quad4") || fem.elems[iel].name.Equals("quad4r")) { ElemConnectNodeCount += 5; } if (fem.elems[iel].name.Equals("truss22") || fem.elems[iel].name.Equals("truss32")) { ElemConnectNodeCount += 3; } } for (int i = 0; i < fem.nNod; i++) { for (int j = 0; j < fem.nDim; j++) { WR.Write("{0,20:0.000000000}", fem.getNodeCoord(i, j)); } if (fem.nDim < 3) { WR.Write("{0,20:0.000000000}", 0.0); } if (fem.nDim < 2) { WR.Write("{0,20:0.000000000}", 0.0); } WR.WriteLine(); } WR.WriteLine(); WR.Write("\nCELLS {0} ", fem.nEl); WR.Write("{0} \n", ElemConnectNodeCount); for (int iel = 0; iel < fem.nEl; iel++) { if (fem.elems[iel].name.Equals("hex20") || fem.elems[iel].name.Equals("hex20r")) { WR.Write("20 "); int nind = fem.elems[iel].ind.Length; for (int i = 0; i < vtkArrInd_hex20.Length; i++) { WR.Write("{0,6}", fem.elems[iel].ind[vtkArrInd_hex20[i]] - 1); } } if (fem.elems[iel].name.Equals("hex8") || fem.elems[iel].name.Equals("hex8r")) { WR.Write("8 "); int nind = fem.elems[iel].ind.Length; for (int i = 0; i < vtkArrInd_hex8.Length; i++) { WR.Write("{0,6}", fem.elems[iel].ind[vtkArrInd_hex8[i]] - 1); } } if (fem.elems[iel].name.Equals("quad8") || fem.elems[iel].name.Equals("quad8r")) { WR.Write("8 "); int nind = fem.elems[iel].ind.Length; for (int i = 0; i < vtkArrInd_quad8.Length; i++) { WR.Write("{0,6}", fem.elems[iel].ind[vtkArrInd_quad8[i]] - 1); } } if (fem.elems[iel].name.Equals("quad4") || fem.elems[iel].name.Equals("quad4r")) { WR.Write("4 "); int nind = fem.elems[iel].ind.Length; for (int i = 0; i < vtkArrInd_quad4.Length; i++) { WR.Write("{0,6}", fem.elems[iel].ind[vtkArrInd_quad4[i]] - 1); } } if (fem.elems[iel].name.Equals("truss22") || fem.elems[iel].name.Equals("truss32")) { WR.Write("2 "); int nind = fem.elems[iel].ind.Length; for (int i = 0; i < vtkArrInd_truss2.Length; i++) { WR.Write("{0,6}", fem.elems[iel].ind[vtkArrInd_truss2[i]] - 1); } } WR.WriteLine(); } WR.WriteLine("\nCELL_TYPES {0}", fem.nEl); for (int i = 0; i < fem.nEl; i++) { if (fem.elems[i].name.Equals("hex20") || fem.elems[i].name.Equals("hex20r")) { WR.Write("{0,3}", 25); } if (fem.elems[i].name.Equals("hex8") || fem.elems[i].name.Equals("hex8r")) { WR.Write("{0,3}", 12); } if (fem.elems[i].name.Equals("quad8") || fem.elems[i].name.Equals("quad8r")) { WR.Write("{0,3}", 23); } if (fem.elems[i].name.Equals("quad4") || fem.elems[i].name.Equals("quad4r")) { WR.Write("{0,3}", 9); } if (fem.elems[i].name.Equals("truss22") || fem.elems[i].name.Equals("truss32")) { WR.Write("{0,3}", 3); } } WR.WriteLine("\n"); if (resultFile != null) { displ = new double[fem.nNod * fem.nDf]; stress = new FeStress(fem); stress.readResults(resultFile, displ); resAtNod = new ResultAtNodes(fem); WR.Write("POINT_DATA {0}", fem.nNod); writeScalars("Si"); writeScalars("Sx"); writeScalars("Sy"); writeScalars("Sz"); writeScalars("Sxy"); if (fem.nDim == 3) { writeScalars("Syz"); writeScalars("Szx"); } //writeScalars("S1"); //writeScalars("S2"); //if (fem.nDim == 3) //{ // writeScalars("S3"); // writeScalars("S13"); //} writeScalars("Ux"); writeScalars("Uy"); if (fem.nDim == 3) { writeScalars("Uz"); } } WR.Flush(); WR.Close(); }