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));
            }
        }
Exemplo n.º 2
0
        // 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);
            }
        }
        // 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 : { }
                }
            }
        }
        void createSurForceList(FeScanner es)
        {
            int list_count = es.readInt();

            for (int j = 0; j < list_count; j++)
            {
                readSurForces(es);
            }
        }
        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));
                    }
                }
            }
        }
        // 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();
        }
        public readmesh()
        {
            String modelName = CSMGEN.RD.next();
            String fileName  = CSMGEN.RD.next();

            CSMGEN.PR.WriteLine("ReadMesh:  {0}    {1}\n", modelName, fileName);
            FeScanner RD = new FeScanner(fileName);
            FeModel   m  = new FeModel(RD, CSMGEN.PR);

            m.readData();
            CSMGEN.blocks.Add(modelName, m);
            CSMGEN.PR.WriteLine("Mesh " + modelName + ": nEl = {0,9}  nNod = {1,9}\n", m.nEl, m.nNod);
        }
Exemplo n.º 8
0
        // Read data for specified constrained displacements
        private void readConstrDisplacements(FeScanner es)
        {
            String s   = es.next().ToLower();
            int    idf = UTIL.direction(s);

            if (idf == -1)
            {
                UTIL.errorMsg("constrDispl direction should be x/y/z. Specified:" + s);
            }
            if (!es.hasNextDouble())
            {
                UTIL.errorMsg("constrDispl value is not a double: " + es.next());
            }
            double vd = es.nextDouble();

            defDs = es.readNumberList(defDs, idf, nDim, vd);
        }
        // Read data for specified nodal forces
        private void readNodalForces(FeScanner es)
        {
            String s   = es.next().ToLower();
            int    idf = UTIL.direction(s);

            if (idf == -1)
            {
                UTIL.errorMsg("nodForce direction should be x/y/z. Specified:" + s);
            }

            if (!es.hasNextDouble())
            {
                UTIL.errorMsg("nodForce value is not a double: " + es.next());
            }
            double vd = es.nextDouble();

            nodForces = es.readNumberList(nodForces, idf, fem.nDim, vd);
        }
Exemplo n.º 10
0
        public static void CSFEM_Main(String[] args)
        {
            Console.Clear();
            Console.WriteLine();
            Console.WriteLine("***************************************************");
            Console.WriteLine("*   C# Finite Element Analysis - Pre-Processor    *");
            Console.WriteLine("*                              & Linear Solver    *");
            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("***************************************************");


            FE.main = FE.FEM;

            RD = new FeScanner(args[0]);
            string[] file = args[0].Split('.');
            //fileOut = (args.Length == 1) ? file[0] + "_fem" : args[1];
            fileOut = file[0] + "_fem";
            PR      = new FePrintWriter().getPrinter(fileOut);


            PR.WriteLine();
            PR.WriteLine("***************************************************");
            PR.WriteLine("*   C# Finite Element Analysis - Pre-Processor    *");
            PR.WriteLine("*                              & Linear Solver    *");
            PR.WriteLine("*   -------------------------------------------   *");
            PR.WriteLine("*   Copyright © Ravinder Singh, 2017.             *");
            PR.WriteLine("*   License: Apache v2.0 License.                 *");
            PR.WriteLine("*   For further information on this software      *");
            PR.WriteLine("*   email : [email protected].               *");
            PR.WriteLine("***************************************************");

            PR.WriteLine();
            PR.WriteLine("FEA Model & Solver. Data file: " + args[0]);
            Console.WriteLine("\nFEA Model & Solver. Data file: " + args[0]);

            new CSFEM();
            PR.Close();
        }
Exemplo n.º 11
0
        public static void CSMGEN_Main(String[] args)
        {
            Console.Clear();
            Console.WriteLine();
            Console.WriteLine("***************************************************");
            Console.WriteLine("*   C# Finite Element Analysis - Mesh Generator   *");
            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("***************************************************");


            FE.main = FE.MGEN;

            RD = new FeScanner(args[0]);
            string[] file = args[0].Split('.');
            //fileOut = (args.Length == 1) ? file[0] + "_fem" : args[1];
            fileOut = file[0] + "_gen";
            PR      = new FePrintWriter().getPrinter(fileOut);

            PR.WriteLine();
            PR.WriteLine("***************************************************");
            PR.WriteLine("*   C# Finite Element Analysis - Mesh Generator   *");
            PR.WriteLine("*   -------------------------------------------   *");
            PR.WriteLine("*   Copyright © Ravinder Singh, 2017.             *");
            PR.WriteLine("*   License: Apache v2.0 License.                 *");
            PR.WriteLine("*   For further information on this software      *");
            PR.WriteLine("*   email : [email protected].               *");
            PR.WriteLine("***************************************************");
            PR.WriteLine();

            PR.WriteLine("Mesh Generator. Data file: " + args[0]);
            PR.WriteLine();
            Console.WriteLine("\nMesh generator. Data file: " + args[0]);
            Console.WriteLine();

            new CSMGEN();
        }
Exemplo n.º 12
0
        // 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));
        }
Exemplo n.º 13
0
        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;
            }
        }
Exemplo n.º 14
0
        // 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 : { }
            }
        }
Exemplo n.º 15
0
        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;
                }
            }
        }
Exemplo n.º 16
0
        // 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);
        }
Exemplo n.º 17
0
 // Construct finite element model.
 // RD - data scanner, PR - print writer.
 public FeModel(FeScanner RD, StreamWriter PR)
 {
     FeModelData.RD = RD;
     FeModelData.PR = PR;
 }
Exemplo n.º 18
0
        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();
        }
Exemplo n.º 19
0
        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;
                }
            }
        }