Ejemplo n.º 1
0
  public void run() {
    // 1.Read in a triangle mesh from an input file with
    //  format ASCII UCD generated by Gridgen
    MeshReader reader = new MeshReader("triangle.grd");
    Mesh mesh = reader.read2DMesh();
    // Compute geometry relationship of nodes and elements
    mesh.computeNodeBelongsToElements();

    // 2.Mark border types
    HashMap<NodeType, Function> mapNTF = new HashMap<NodeType, Function>();
    mapNTF.put(NodeType.Dirichlet, null);
    mesh.markBorderNode(mapNTF);

    // 3.Use element library to assign degrees of
    //  freedom (DOF) to element
    ElementList eList = mesh.getElementList();
    FELinearTriangle feLT = new FELinearTriangle();
    for (int i = 1; i <= eList.size(); i++) feLT.assignTo(eList.at(i));

    // 4.Weak form
    WeakFormLaplace2D weakForm = new WeakFormLaplace2D();
    // Right hand side(RHS): f = -2*(x^2+y^2)+36
    weakForm.setF(X.M(X).A(Y.M(Y)).M(-2.0).A(36.0));

    // 5.Assembly process
    AssemblerScalar assembler = new AssemblerScalar(mesh, weakForm);
    assembler.assemble();
    Matrix stiff = assembler.getStiffnessMatrix();
    Vector load = assembler.getLoadVector();
    // Boundary condition
    assembler.imposeDirichletCondition(C0);

    // 6.Solve linear system
    SolverJBLAS solver = new SolverJBLAS();
    Vector u = solver.solveDGESV(stiff, load);
    System.out.println("u=");
    for (int i = 1; i <= u.getDim(); i++) System.out.println(String.format("%.3f", u.get(i)));

    // 7.Output results to an Techplot format file
    MeshWriter writer = new MeshWriter(mesh);
    writer.writeTechplot("./tutorial/Laplace2D.dat", u);

    this.mesh = mesh;
    this.u = u;
  }
Ejemplo n.º 2
0
  public void readMesh() {
    MeshReader reader = new MeshReader("lagrangian.grd");
    mesh = reader.read2DMesh();
    mesh.computeNodeBelongsToElements();

    // 2.Mark border types
    HashMap<NodeType, Function> mapNTF = new HashMap<NodeType, Function>();
    mapNTF.put(NodeType.Dirichlet, null);
    mesh.markBorderNode(mapNTF);
    ElementList eList = mesh.getElementList();
    //        for(int i=1;i<=eList.size();i++) {
    //        	System.out.println(eList.at(i));
    //        }

    // 3.Use element library to assign degrees of
    //  freedom (DOF) to element
    FELinearTriangle feLT = new FELinearTriangle();
    for (int i = 1; i <= eList.size(); i++) feLT.assignTo(eList.at(i));
  }