Exemple #1
0
def create_forest(comm, depth, htarget):
    """
    Create an initial forest for analysis and optimization.

    This code loads in the model, sets names, meshes the geometry and creates
    an OctForest from the mesh. The forest is populated with octrees with
    the specified depth.

    Args:
        comm (MPI_Comm): MPI communicator
        depth (int): Depth of the initial trees
        htarget (float): Target global element mesh size

    Returns:
        OctForest: Initial forest for topology optimization
    """
    # Load the geometry model
    geo = TMR.LoadModel('../cantilever/cantilever.stp')

    # Mark the boundary condition faces
    verts = geo.getVertices()
    edges = geo.getEdges()
    faces = geo.getFaces()
    volumes = geo.getVolumes()

    faces[3].setName('fixed')
    faces[4].setSource(volumes[0], faces[5])
    verts[4].setName('pt1')
    verts[3].setName('pt2')

    # Set the boundary conditions for the problem
    bcs = TMR.BoundaryConditions()
    bcs.addBoundaryCondition('fixed')

    # Create the mesh
    mesh = TMR.Mesh(comm, geo)

    # Set the meshing options
    opts = TMR.MeshOptions()

    # Create the surface mesh
    mesh.mesh(args.htarget, opts)

    # Create a model from the mesh
    model = mesh.createModelFromMesh()

    # Create the corresponding mesh topology from the mesh-model
    topo = TMR.Topology(comm, model)

    # Create the quad forest and set the topology of the forest
    forest = TMR.OctForest(comm)
    forest.setTopology(topo)

    # Create the trees
    forest.createTrees(depth)

    return forest
Exemple #2
0
htarget = 10.0
mesh.mesh(htarget, opts=opts)
mesh.writeToVTK('surface-mesh.vtk')

# Create a model from the mesh
model = mesh.createModelFromMesh()

# Create the corresponding mesh topology from the mesh-model
topo = TMR.Topology(comm, model)

# Create the quad forest and set the topology of the forest
forest = TMR.QuadForest(comm)
forest.setTopology(topo)

# Make the creator class
bcs = TMR.BoundaryConditions()
bcs.addBoundaryCondition('x+')
bcs.addBoundaryCondition('x-')
bcs.addBoundaryCondition('y+')
bcs.addBoundaryCondition('y-')

# Allocate the creator class
creator = CreateMe(bcs)

# Create the initial forest
nlevels = 2
forest.createTrees(nlevels - 1)

# Target relative error
target_rel_err = 1e-5