Example #1
0
# Create a generated mesh
generatedMesh = iron.GeneratedMesh()
generatedMesh.CreateStart(generatedMeshUserNumber, region)
generatedMesh.type = iron.GeneratedMeshTypes.REGULAR
generatedMesh.basis = [basis]
generatedMesh.extent = [width, height, length]
generatedMesh.numberOfElements = [
    numberGlobalXElements, numberGlobalYElements, numberGlobalZElements
]

mesh1 = iron.Mesh()
generatedMesh.CreateFinish(mesh1UserNumber, mesh1)

# Find the total number of nodes and elements from the generated mesh
meshNodes = iron.MeshNodes()
mesh1.NodesGet(mesh_component_number, meshNodes)
total_number_of_nodes = meshNodes.NumberOfNodesGet()

total_number_of_elements = mesh1.NumberOfElementsGet()

# Start the creation of a second manually generated mesh
mesh2 = iron.Mesh()
mesh2.CreateStart(mesh2UserNumber, region, number_of_dimensions)
mesh2.NumberOfComponentsSet(1)

# Define which elements are included in the new mesh, and the total number of elements
original_elements_list = range(1, total_number_of_elements + 1)
removed_elements = (numpy.array([1, 750]) -
                    1).tolist()  # list of elements to be removed from mesh
new_elements_list = numpy.delete(original_elements_list,
Example #2
0
def OpenCMISS_to_morphic(c_mesh,
                         geometric_field,
                         element_nums,
                         node_nums,
                         dimension=2,
                         interpolation='linear'):
    """Convert an OpenCMISS mesh to a morphic mesh.

    Only Linear lagrange elements supported.

    Keyword arguments:
    morphicMesh -- morphic mesh
    dimension -- dimension of mesh to read in
    """

    from opencmiss.iron import iron
    mesh_nodes = iron.MeshNodes()
    mesh_elements = iron.MeshElements()
    c_mesh.NodesGet(1, mesh_nodes)
    c_mesh.ElementsGet(1, mesh_elements)
    # Create morphic mesh
    mesh = morphic.Mesh()

    # Add nodes
    if interpolation in ['linear', 'quadratic', 'cubic']:
        derivatives = [1]
    elif interpolation == 'hermite':
        derivatives = range(1, 9)
    for node_num in node_nums:
        coordinates = []
        for c_idx, c in enumerate([1, 2, 3]):  # Component
            componentValues = []
            for derivative_idx, derivative in enumerate(derivatives):
                componentValues.append(
                    geometric_field.ParameterSetGetNodeDP(
                        iron.FieldVariableTypes.U,
                        iron.FieldParameterSetTypes.VALUES, 1, derivative,
                        int(node_num), c))
            coordinates.append(componentValues)

        mesh.add_stdnode(node_num, coordinates, group='_default')
        #print('Morphic node added', node_num, coordinates)

    if dimension == 2:
        if interpolation == 'linear':
            element_interpolation = ['L1', 'L1']
            num_elem_nodes = 4
        if interpolation == 'quadratic':
            element_interpolation = ['L2', 'L2']
            num_elem_nodes = 16
    elif dimension == 3:
        if interpolation == 'linear':
            element_interpolation = ['L1', 'L1', 'L1']
            num_elem_nodes = 8
        if interpolation == 'quadratic':
            element_interpolation = ['L2', 'L2', 'L2']
            num_elem_nodes = 27
        if interpolation == 'cubic':
            element_interpolation = ['L3', 'L3', 'L3']
            num_elem_nodes = 64
        if interpolation == 'hermite':
            element_interpolation = ['H3', 'H3', 'H3']
            num_elem_nodes = 8

    # Add elements
    for elem in element_nums:
        elem_nodes = mesh_elements.NodesGet(int(elem), num_elem_nodes)
        mesh.add_element(elem, element_interpolation, elem_nodes)
        #print('Morphic element added', elem.number)

    # Generate the mesh
    mesh.generate(True)

    return mesh
def num_nodes_get(mesh, mesh_component=1):
    nodes = iron.MeshNodes()
    mesh.NodesGet(mesh_component, nodes)
    return nodes.NumberOfNodesGet()