def create_square_element(mesh: Mesh, finite_element_field: Field, node_coordinate_set): """ Create a single square 2-D finite element using the supplied finite element field and sequence of 4 n-D node coordinates. :param mesh: The Zinc Mesh to create elements in. :param finite_element_field: Zinc FieldFiniteElement to interpolate on element. :param node_coordinate_set: Sequence of 4 coordinates each with as many components as finite element field. :return: None """ assert mesh.getDimension() == 2 assert finite_element_field.castFiniteElement().isValid() assert len(node_coordinate_set) == 4 fieldmodule = finite_element_field.getFieldmodule() nodeset = fieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES) node_template = nodeset.createNodetemplate() node_template.defineField(finite_element_field) element_template = mesh.createElementtemplate() element_template.setElementShapeType(Element.SHAPE_TYPE_SQUARE) linear_basis = fieldmodule.createElementbasis( 2, Elementbasis.FUNCTION_TYPE_LINEAR_LAGRANGE) eft = mesh.createElementfieldtemplate(linear_basis) element_template.defineField(finite_element_field, -1, eft) field_cache = fieldmodule.createFieldcache() with ChangeManager(fieldmodule): node_identifiers = [] for node_coordinate in node_coordinate_set: node = nodeset.createNode(-1, node_template) node_identifiers.append(node.getIdentifier()) field_cache.setNode(node) finite_element_field.assignReal(field_cache, node_coordinate) element = mesh.createElement(-1, element_template) element.setNodesByIdentifier(eft, node_identifiers) fieldmodule.defineAllFaces()
def create_triangle_elements(mesh: Mesh, finite_element_field: Field, element_node_set): """ Create a linear triangular element for every set of 3 local nodes in element_node_set. :param mesh: The Zinc Mesh to create elements in. :param finite_element_field: Zinc FieldFiniteElement to interpolate from nodes. :param element_node_set: Sequence of 3 node identifiers for each element. :return: None """ assert mesh.getDimension() == 2 assert finite_element_field.castFiniteElement().isValid() fieldmodule = finite_element_field.getFieldmodule() element_template = mesh.createElementtemplate() element_template.setElementShapeType(Element.SHAPE_TYPE_TRIANGLE) linear_basis = fieldmodule.createElementbasis( 2, Elementbasis.FUNCTION_TYPE_LINEAR_SIMPLEX) eft = mesh.createElementfieldtemplate(linear_basis) element_template.defineField(finite_element_field, -1, eft) with ChangeManager(fieldmodule): for element_nodes in element_node_set: element = mesh.createElement(-1, element_template) element.setNodesByIdentifier(eft, element_nodes) fieldmodule.defineAllFaces()