Package bs.bs2d.fea

Examples of bs.bs2d.fea.TriMesh2D


    public static final String WHITESPACE_DELIMITER = "\\s+";
   
    private static FileNameExtensionFilter fileFilter;
   
    public static TriMesh2D readMesh(File f) throws Exception{
        TriMesh2D mesh;
        if(f.getName().endsWith(".grd")){
            mesh = readGrdFile(f);
        } else if(f.getName().endsWith(".vol")){
            mesh = readVolFile(f);
        } else if(f.getName().endsWith(".msh")){
View Full Code Here


     * @param f file to read mesh data from
     * @return the mesh object described by the file
     */
    public static TriMesh2D readGrdFile(File f) throws Exception{
       
        TriMesh2D mesh = new TriMesh2D();
       
       
            List<String> lines;
            lines = FileUtils.readLines(f);
           
            int index = 0;
            while(lines.get(index).startsWith("#"))
                index++;

            String[] vals = lines.get(index).split(WHITESPACE_DELIMITER);
            index++;
           
            int nodes = Integer.parseInt(vals[0]);
            int elems = Integer.parseInt(vals[1]);
           
            // read nodes
            for(int i=0; i < nodes; i++){
                vals = lines.get(index+i).split(WHITESPACE_DELIMITER);
               
                int ni = Integer.parseInt(vals[0]);
                float x = Float.parseFloat(vals[1]);
                float y = Float.parseFloat(vals[2]);
               
                mesh.addNode(new Node2D(ni, x, y));
            }
            index += nodes;
           
            // read elements
            for(int i=0; i < elems; i++){
                vals = lines.get(index+i).split(WHITESPACE_DELIMITER);
               
                if(!vals[2].equals("tri"))
                    throw new Exception("Element type not supported: " + vals[2]);
               
                int ei = Integer.parseInt(vals[0]);
                int[] nodeIndex = new int[3];
                for(int j=0; j < 3; j++)
                    nodeIndex[j] = Integer.parseInt(vals[j+3]);
               
                mesh.addNewElement(ei, nodeIndex);
            }
           
            mesh.finalizeConstruction();
           
       
        return mesh;
    }
View Full Code Here

     * @param f file to read mesh data from
     * @return the mesh object described by the file
     */
    public static TriMesh2D readMshFile(File f) throws Exception{
       
        TriMesh2D mesh = new TriMesh2D();
       
       
            List<String> lines;
            lines = FileUtils.readLines(f);
           
            int index = lines.indexOf("$Nodes") + 1;
           
           
            String[] vals;
           
            // read nodes
            int nodes = Integer.parseInt(lines.get(index++));
            for(int i=0; i < nodes; i++){
                vals = lines.get(index+i).split(WHITESPACE_DELIMITER);
               
                int ni = Integer.parseInt(vals[0]);
                float x = Float.parseFloat(vals[1]);
                float y = Float.parseFloat(vals[2]);
               
                mesh.addNode(new Node2D(ni, x, y));
            }
            index += nodes;
            // done
           
           
            while(!lines.get(index).equals("$Elements"))
                index++;
            index++;
           
            // read elements
            int elems = Integer.parseInt(lines.get(index++));
            for(int i=0; i < elems; i++){
                vals = lines.get(index+i).split(WHITESPACE_DELIMITER);
               
                if(!vals[1].equals("2"))
                    continue;
               
                int ei = Integer.parseInt(vals[0]);
                int tags = Integer.parseInt(vals[2]);
                int[] nodeIndex = new int[3];
                for(int j=0; j < 3; j++)
                    nodeIndex[j] = Integer.parseInt(vals[3+tags+j]);
               
                mesh.addNewElement(ei, nodeIndex);
            }
           
            mesh.finalizeConstruction();
           
        return mesh;
    }
View Full Code Here

     * Netgen style .vol file.
     * @param f file to read mesh data from
     * @return the mesh object described by the file
     */
    public static TriMesh2D readVolFile(File f) throws Exception{
        TriMesh2D mesh = new TriMesh2D();
       
       
            List<String> lines;
            lines = FileUtils.readLines(f);
           
            int iElems = -1;
            int nElems = 0;
            int iNodes = -1;
            int nNodes = 0;
            for (int i = 0; i < lines.size(); i++) {
                String line = lines.get(i);
                if(line.equals("points")){
                    nNodes = Integer.parseInt(lines.get(++i));
                    iNodes = ++i;
                }
                if(line.equals("surfaceelementsuv")){
                    nElems = Integer.parseInt(lines.get(++i));
                    iElems = ++i;
                }
            }
            String[] vals;
           
            // read nodes
            for(int i=0; i < nNodes; i++){
                vals = lines.get(iNodes + i).split(WHITESPACE_DELIMITER);
               
                float x = Float.parseFloat(vals[1]);
                float y = Float.parseFloat(vals[2]);
               
                mesh.addNode(new Node2D(i+1, x, y));
            }
           
            // read elements
            for(int i=0; i < nElems; i++){
                vals = lines.get(iElems + i).split(WHITESPACE_DELIMITER);
               
                if(!vals[5].equals("3"))
                    throw new Exception("Element type not supported: " + vals[5]);
               
                int[] nodeIndex = new int[3];
                for(int j=0; j < 3; j++)
                    nodeIndex[j] = Integer.parseInt(vals[j+6]);
               
                mesh.addNewElement(i, nodeIndex);
            }
           
            mesh.finalizeConstruction();
       
        return mesh;
    }
View Full Code Here

    public void init(Object data) {
       
        if(data instanceof Object[]){
           
            Object[] o = (Object[]) data;
            TriMesh2D mesh = (TriMesh2D) o[0];
           
            if(mesh != null){
                List<BoundaryCondition> bcs = (List<BoundaryCondition>)o[1];
                runAnalysis(mesh, bcs);
                return;
            }
        }else if(data instanceof FEAResults){
            init((FEAResults)data);
            return;
        }
       
        // no valid data
        if(MainGUI.DEBUG_RESULTS){
            try {
                File msh = BSConstants.getTempFile("msh");
                TriMesh2D mesh = MeshReader.readMesh(msh);
                File out = BSConstants.getTempFile("dat");
                init(FEAResults.getResultsFromFile(mesh, out));
            } catch (Exception ex) {
                System.err.println("Couldn't load temp files from previous session.");
                ex.printStackTrace();
View Full Code Here

        // colleact params
        float[] scalar = results.getScalar(controls.getScalar());
        ColorMap.Style styleID = controls.getColorMapStyle();
        int res = controls.getResolution();
       
        TriMesh2D msh;
        if(deformed)
            msh = defMesh;
        else
            msh = results.getMesh();
       
View Full Code Here

                f = fc.getSelectedFile();
                BSConstants.workFile = f;

                // init mesh view with selected file
                try {
                    TriMesh2D mesh = MeshReader.readMesh(f);
                    views[0].init(mesh);// give mesh to mesh view (0)
                    changeView(1); //mesh will be passed on to loadcase view (1)
                } catch (Exception ex) {
                    UserMessage.showError("Error opening file!",
                                                ex.getMessage());
View Full Code Here

TOP

Related Classes of bs.bs2d.fea.TriMesh2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.