Beispiel #1
0
def create_fields_displacement_gradients(coordinates: Field,
                                         reference_coordinates: Field,
                                         mesh: Mesh):
    """
    :return: 1st and 2nd displacement gradients of (coordinates - referenceCoordinates) w.r.t. referenceCoordinates.
    """
    assert (coordinates.getNumberOfComponents()
            == 3) and (reference_coordinates.getNumberOfComponents() == 3)
    fieldmodule = mesh.getFieldmodule()
    dimension = mesh.getDimension()
    with ChangeManager(fieldmodule):
        if dimension == 3:
            u = coordinates - reference_coordinates
            displacement_gradient = fieldmodule.createFieldGradient(
                u, reference_coordinates)
            displacement_gradient2 = fieldmodule.createFieldGradient(
                displacement_gradient, reference_coordinates)
        elif dimension == 2:
            # Note this needs improvement as missing cross terms
            # assume xi directions are approximately normal;
            # effect is to penalise elements where this is not so, which is also desired
            dX_dxi1 = fieldmodule.createFieldDerivative(
                reference_coordinates, 1)
            dX_dxi2 = fieldmodule.createFieldDerivative(
                reference_coordinates, 2)
            dx_dxi1 = fieldmodule.createFieldDerivative(coordinates, 1)
            dx_dxi2 = fieldmodule.createFieldDerivative(coordinates, 2)
            dS1_dxi1 = fieldmodule.createFieldMagnitude(dX_dxi1)
            dS2_dxi2 = fieldmodule.createFieldMagnitude(dX_dxi2)
            du_dS1 = (dx_dxi1 - dX_dxi1) / dS1_dxi1
            du_dS2 = (dx_dxi2 - dX_dxi2) / dS2_dxi2
            displacement_gradient = fieldmodule.createFieldConcatenate(
                [du_dS1, du_dS2])
            # curvature:
            d2u_dSdxi1 = fieldmodule.createFieldDerivative(
                displacement_gradient, 1)
            d2u_dSdxi2 = fieldmodule.createFieldDerivative(
                displacement_gradient, 2)
            displacement_gradient2 = fieldmodule.createFieldConcatenate(
                [d2u_dSdxi1 / dS1_dxi1, d2u_dSdxi2 / dS2_dxi2])
        else:  # dimension == 1
            dX_dxi1 = fieldmodule.createFieldDerivative(
                reference_coordinates, 1)
            dx_dxi1 = fieldmodule.createFieldDerivative(coordinates, 1)
            dS1_dxi1 = fieldmodule.createFieldMagnitude(dX_dxi1)
            displacement_gradient = (dx_dxi1 - dX_dxi1) / dS1_dxi1
            # curvature:
            displacement_gradient2 = fieldmodule.createFieldDerivative(
                displacement_gradient, 1) / dS1_dxi1
    return displacement_gradient, displacement_gradient2
Beispiel #2
0
def evaluate_field_mesh_integral(field: Field, coordinates: Field, mesh: Mesh, number_of_points=4):
    """
    Integrate value of a field over mesh using Gaussian Quadrature.
    :param field: Field to integrate over mesh.
    :param coordinates: Field giving spatial coordinates to integrate over.
    :param mesh: The mesh or mesh group to integrate over.
    :param number_of_points: Number of integration points in each dimension.
    :return: Integral value.
    """
    fieldmodule = mesh.getFieldmodule()
    components_count = field.getNumberOfComponents()
    with ChangeManager(fieldmodule):
        integral = fieldmodule.createFieldMeshIntegral(field, coordinates, mesh)
        integral.setNumbersOfPoints(number_of_points)
        fieldcache = fieldmodule.createFieldcache()
        result, value = integral.evaluateReal(fieldcache, components_count)
        del integral
        del fieldcache
    assert result == RESULT_OK
    return value