Exemplo n.º 1
0
def form_fluid(
    displacement_fluid,
    velocity_fluid,
    phi_fluid,
    psi_fluid,
    fluid: Space,
    param: Parameters,
):

    return (
        param.NU * dot(grad(velocity_fluid), grad(phi_fluid)) * fluid.dx
        + dot(param.BETA, grad(velocity_fluid)) * phi_fluid * fluid.dx
        + dot(grad(displacement_fluid), grad(psi_fluid)) * fluid.dx
        - dot(grad(displacement_fluid), fluid.normal_vector)
        * psi_fluid
        * fluid.ds(1)
        - param.NU
        * dot(grad(velocity_fluid), fluid.normal_vector)
        * phi_fluid
        * fluid.ds(1)
        + param.GAMMA
        / fluid.cell_size
        * displacement_fluid
        * psi_fluid
        * fluid.ds(1)
        + param.GAMMA
        / fluid.cell_size
        * velocity_fluid
        * phi_fluid
        * fluid.ds(1)
    )
Exemplo n.º 2
0
def form_fluid_adjoint(
    displacement_fluid_adjoint,
    velocity_fluid_adjoint,
    xi_fluid,
    eta_fluid,
    fluid: Space,
    param: Parameters,
):

    return (
        param.NU
        * dot(grad(eta_fluid), grad(displacement_fluid_adjoint))
        * fluid.dx
        + dot(param.BETA, grad(eta_fluid))
        * displacement_fluid_adjoint
        * fluid.dx
        + dot(grad(xi_fluid), grad(velocity_fluid_adjoint)) * fluid.dx
        - dot(grad(xi_fluid), fluid.normal_vector)
        * velocity_fluid_adjoint
        * fluid.ds(1)
        - param.NU
        * dot(grad(eta_fluid), fluid.normal_vector)
        * displacement_fluid_adjoint
        * fluid.ds(1)
        + param.GAMMA
        / fluid.cell_size
        * xi_fluid
        * velocity_fluid_adjoint
        * fluid.ds(1)
        + param.GAMMA
        / fluid.cell_size
        * eta_fluid
        * displacement_fluid_adjoint
        * fluid.ds(1)
    )
Exemplo n.º 3
0
def functional_fluid(
    displacement_fluid_old,
    velocity_fluid_old,
    displacement_fluid_interface,
    velocity_fluid_interface,
    displacement_fluid_old_interface,
    velocity_fluid_old_interface,
    phi_fluid,
    psi_fluid,
    fluid: Space,
    param: Parameters,
    time,
    time_step,
):

    return (
        velocity_fluid_old * phi_fluid * fluid.dx
        - 0.5
        * time_step
        * form_fluid(
            displacement_fluid_old,
            velocity_fluid_old,
            phi_fluid,
            psi_fluid,
            fluid,
            param,
        )
        + 0.5
        * time_step
        * param.GAMMA
        / fluid.cell_size
        * displacement_fluid_interface
        * psi_fluid
        * fluid.ds(1)
        + 0.5
        * time_step
        * param.GAMMA
        / fluid.cell_size
        * velocity_fluid_interface
        * phi_fluid
        * fluid.ds(1)
        + 0.5
        * time_step
        * param.GAMMA
        / fluid.cell_size
        * displacement_fluid_old_interface
        * psi_fluid
        * fluid.ds(1)
        + 0.5
        * time_step
        * param.GAMMA
        / fluid.cell_size
        * velocity_fluid_old_interface
        * phi_fluid
        * fluid.ds(1)
        + time_step * external_force(time) * phi_fluid * fluid.dx
    )
Exemplo n.º 4
0
def nodesquare():
    space = Space()
    space.add_dimension("x")
    space.add_dimension("y")
    nodelist = []
    for i in range(-1, 2):
        for j in range(-1, 2):
            nodelist.append(space.nodegen([i, j]))
    for i in [0, 1, 2, 3, 4, 5, 6, 7, 8]:
        nodelist[4].link(nodelist[i])
    return nodelist
Exemplo n.º 5
0
def functional_fluid_adjoint_initial(
    displacement_fluid_adjoint_old,
    velocity_fluid_adjoint_old,
    displacement_fluid_adjoint_interface,
    velocity_fluid_adjoint_interface,
    displacement_fluid_adjoint_old_interface,
    velocity_fluid_adjoint_old_interface,
    xi_fluid,
    eta_fluid,
    fluid: Space,
    param: Parameters,
    time,
    time_step,
    microtimestep_before: MicroTimeStep,
    microtimestep: MicroTimeStep,
):

    return (
        0.5
        * time_step
        * param.NU
        * dot(grad(eta_fluid), fluid.normal_vector)
        * displacement_fluid_adjoint_interface
        * fluid.ds(1)
        + 2.0 * param.NU
        * characteristic_function_fluid(param)
        * dot(
            goal_functional(
                microtimestep_before, microtimestep, "primal_velocity"
            )[1],
            grad(eta_fluid),
        )
        * fluid.dx
    )
Exemplo n.º 6
0
def functional_solid_adjoint_initial(
    displacement_solid_adjoint_old,
    velocity_solid_adjoint_old,
    displacement_solid_adjoint_interface,
    velocity_solid_adjoint_interface,
    displacement_solid_adjoint_old_interface,
    velocity_solid_adjoint_old_interface,
    xi_solid,
    eta_solid,
    solid: Space,
    param: Parameters,
    time,
    time_step,
    microtimestep_before: MicroTimeStep,
    microtimestep: MicroTimeStep,
):

    return (
        0.5
        * time_step
        * param.GAMMA
        / solid.cell_size
        * xi_solid
        * velocity_solid_adjoint_interface
        * solid.ds(1)
        + 0.5
        * time_step
        * param.GAMMA
        / solid.cell_size
        * eta_solid
        * displacement_solid_adjoint_interface
        * solid.ds(1)
        + 2.0 * param.ZETA
        * characteristic_function_solid(param)
        * dot(
            goal_functional(
                microtimestep_before, microtimestep, "primal_displacement"
            )[1],
            grad(xi_solid),
        )
        * solid.dx
    )
Exemplo n.º 7
0
def functional_solid(
    displacement_solid_old,
    velocity_solid_old,
    displacement_solid_interface,
    velocity_solid_interface,
    displacement_solid_old_interface,
    velocity_solid_old_interface,
    phi_solid,
    psi_solid,
    solid: Space,
    param: Parameters,
    time,
    time_step,
):

    return (
        velocity_solid_old * phi_solid * solid.dx
        + displacement_solid_old * psi_solid * solid.dx
        - 0.5
        * time_step
        * form_solid(
            displacement_solid_old,
            velocity_solid_old,
            phi_solid,
            psi_solid,
            solid,
            param,
        )
        - 0.5
        * time_step
        * param.NU
        * dot(grad(velocity_solid_interface), solid.normal_vector)
        * phi_solid
        * solid.ds(1)
        - 0.5
        * time_step
        * param.NU
        * dot(grad(velocity_solid_old_interface), solid.normal_vector)
        * phi_solid
        * solid.ds(1)
    )
Exemplo n.º 8
0
def form_solid(
    displacement_solid,
    velocity_solid,
    phi_solid,
    psi_solid,
    solid: Space,
    param: Parameters,
):

    return (
        param.ZETA * dot(grad(displacement_solid), grad(phi_solid)) * solid.dx
        + param.DELTA * dot(grad(velocity_solid), grad(phi_solid)) * solid.dx
        - velocity_solid * psi_solid * solid.dx
        - param.DELTA
        * dot(grad(velocity_solid), solid.normal_vector)
        * phi_solid
        * solid.ds(1)
    )
Exemplo n.º 9
0
def form_solid_adjoint(
    displacement_solid_adjoint,
    velocity_solid_adjoint,
    xi_solid,
    eta_solid,
    solid: Space,
    param: Parameters,
):

    return (
        param.ZETA
        * dot(grad(xi_solid), grad(displacement_solid_adjoint))
        * solid.dx
        + param.DELTA
        * dot(grad(eta_solid), grad(displacement_solid_adjoint))
        * solid.dx
        - eta_solid * velocity_solid_adjoint * solid.dx
        - param.DELTA
        * dot(grad(eta_solid), solid.normal_vector)
        * displacement_solid_adjoint
        * solid.ds(1)
    )
Exemplo n.º 10
0
def adjoint_residual_solid(
    displacement_solid,
    velocity_solid,
    displacement_solid_adjoint,
    velocity_solid_adjoint,
    displacement_fluid_adjoint,
    velocity_fluid_adjoint,
    solid: Space,
    solid_timeline: TimeLine,
    param: Parameters,
):
    residuals = []
    left = True
    macrotimestep = solid_timeline.head
    glocal_size = solid_timeline.size
    m = 1
    for n in range(glocal_size):

        microtimestep = macrotimestep.head.after
        local_size = macrotimestep.size - 1
        for k in range(local_size):

            print(f"Current contribution: {m}")
            lhs = 0.0
            rhs = 0.0
            time_step = microtimestep.before.dt
            gauss_1, gauss_2 = gauss(microtimestep)
            if left:

                l = m
                microtimestep_adjust = microtimestep
                left = False

            else:

                l = m - 1
                if microtimestep.before.before is None:

                    microtimestep_adjust = (
                        macrotimestep.microtimestep_before.after)

                else:

                    microtimestep_adjust = microtimestep.before
                left = True

            lhs += (0.5 * time_step * (
                (primal_derivative(velocity_solid, l, gauss_1,
                                   microtimestep_adjust) -
                 (velocity_solid[m] - velocity_solid[m - 1]) / time_step) *
                displacement_solid_adjoint[m]) * solid.dx)
            lhs += (0.5 * time_step * (
                (primal_derivative(velocity_solid, l, gauss_2,
                                   microtimestep_adjust) -
                 (velocity_solid[m] - velocity_solid[m - 1]) / time_step) *
                displacement_solid_adjoint[m]) * solid.dx)
            lhs += (0.5 * time_step *
                    ((primal_derivative(
                        displacement_solid,
                        l,
                        gauss_1,
                        microtimestep_adjust,
                    ) - (displacement_solid[m] - displacement_solid[m - 1]) /
                      time_step) * velocity_solid_adjoint[m]) * solid.dx)
            lhs += (0.5 * time_step *
                    ((primal_derivative(
                        displacement_solid,
                        l,
                        gauss_2,
                        microtimestep_adjust,
                    ) - (displacement_solid[m] - displacement_solid[m - 1]) /
                      time_step) * velocity_solid_adjoint[m]) * solid.dx)
            lhs += (0.5 * time_step * form_solid_adjoint(
                displacement_solid_adjoint[m],
                velocity_solid_adjoint[m],
                primal_reconstruction(displacement_solid, l, gauss_1,
                                      microtimestep_adjust) -
                linear_extrapolation(displacement_solid, m, gauss_1,
                                     microtimestep),
                primal_reconstruction(velocity_solid, l, gauss_1,
                                      microtimestep_adjust) -
                linear_extrapolation(velocity_solid, m, gauss_1,
                                     microtimestep),
                solid,
                param,
            ))
            lhs += (0.5 * time_step * form_solid_adjoint(
                displacement_solid_adjoint[m],
                velocity_solid_adjoint[m],
                primal_reconstruction(displacement_solid, l, gauss_2,
                                      microtimestep_adjust) -
                linear_extrapolation(displacement_solid, m, gauss_2,
                                     microtimestep),
                primal_reconstruction(velocity_solid, l, gauss_2,
                                      microtimestep_adjust) -
                linear_extrapolation(velocity_solid, m, gauss_2,
                                     microtimestep),
                solid,
                param,
            ))
            lhs -= (0.5 * time_step * param.GAMMA / solid.cell_size *
                    (primal_reconstruction(displacement_solid, l, gauss_1,
                                           microtimestep_adjust) -
                     linear_extrapolation(displacement_solid, m, gauss_1,
                                          microtimestep)) *
                    velocity_fluid_adjoint[m] * solid.ds(1))
            lhs -= (0.5 * time_step * param.GAMMA / solid.cell_size *
                    (primal_reconstruction(displacement_solid, l, gauss_2,
                                           microtimestep_adjust) -
                     linear_extrapolation(displacement_solid, m, gauss_2,
                                          microtimestep)) *
                    velocity_fluid_adjoint[m] * solid.ds(1))
            lhs -= (0.5 * time_step * param.GAMMA / solid.cell_size *
                    (primal_reconstruction(velocity_solid, l, gauss_1,
                                           microtimestep_adjust) -
                     linear_extrapolation(velocity_solid, m, gauss_1,
                                          microtimestep)) *
                    displacement_fluid_adjoint[m] * solid.ds(1))
            lhs -= (0.5 * time_step * param.GAMMA / solid.cell_size *
                    (primal_reconstruction(velocity_solid, l, gauss_2,
                                           microtimestep_adjust) -
                     linear_extrapolation(velocity_solid, m, gauss_2,
                                          microtimestep)) *
                    displacement_fluid_adjoint[m] * solid.ds(1))
            rhs += (0.5 * time_step * 2.0 * param.ZETA *
                    characteristic_function_solid(param) * dot(
                        grad(
                            linear_extrapolation(displacement_solid, m,
                                                 gauss_1, microtimestep)),
                        grad(
                            primal_reconstruction(
                                displacement_solid,
                                l,
                                gauss_1,
                                microtimestep_adjust,
                            ) - linear_extrapolation(displacement_solid, m,
                                                     gauss_1, microtimestep)),
                    ) * solid.dx)
            rhs += (0.5 * time_step * 2.0 * param.ZETA *
                    characteristic_function_solid(param) * dot(
                        grad(
                            linear_extrapolation(displacement_solid, m,
                                                 gauss_2, microtimestep)),
                        grad(
                            primal_reconstruction(
                                displacement_solid,
                                l,
                                gauss_2,
                                microtimestep_adjust,
                            ) - linear_extrapolation(displacement_solid, m,
                                                     gauss_2, microtimestep)),
                    ) * solid.dx)

            m += 1
            microtimestep = microtimestep.after
            residuals.append(assemble(0.5 * rhs - 0.5 * lhs))

        macrotimestep = macrotimestep.after

    return residuals
Exemplo n.º 11
0
def primal_residual_solid(
    displacement_solid_array,
    velocity_solid_array,
    displacement_fluid_array,
    velocity_fluid_array,
    displacement_solid_adjoint_array,
    velocity_solid_adjoint_array,
    solid: Space,
    solid_timeline: TimeLine,
    param: Parameters,
):

    residuals = []
    macrotimestep = solid_timeline.head
    global_size = solid_timeline.size
    m = 1
    for n in range(global_size):

        microtimestep = macrotimestep.head.after
        local_size = macrotimestep.size - 1
        for k in range(local_size):

            print(f"Current contribution: {m}")
            lhs = 0.0
            rhs = 0.0
            time_step = microtimestep.before.dt
            gauss_1, gauss_2 = gauss(microtimestep)
            lhs += (0.5 * time_step *
                    ((velocity_solid_array[m] - velocity_solid_array[m - 1]) /
                     time_step * (adjoint_reconstruction(
                         displacement_solid_adjoint_array,
                         m,
                         gauss_1,
                         microtimestep,
                         macrotimestep,
                     ) - displacement_solid_adjoint_array[m])) * solid.dx)
            lhs += (0.5 * time_step *
                    ((velocity_solid_array[m] - velocity_solid_array[m - 1]) /
                     time_step * (adjoint_reconstruction(
                         displacement_solid_adjoint_array,
                         m,
                         gauss_2,
                         microtimestep,
                         macrotimestep,
                     ) - displacement_solid_adjoint_array[m])) * solid.dx)
            lhs += (0.5 * time_step *
                    ((displacement_solid_array[m] -
                      displacement_solid_array[m - 1]) / time_step *
                     (adjoint_reconstruction(
                         velocity_solid_adjoint_array,
                         m,
                         gauss_1,
                         microtimestep,
                         macrotimestep,
                     ) - velocity_solid_adjoint_array[m])) * solid.dx)
            lhs += (0.5 * time_step *
                    ((displacement_solid_array[m] -
                      displacement_solid_array[m - 1]) / time_step *
                     (adjoint_reconstruction(
                         velocity_solid_adjoint_array,
                         m,
                         gauss_2,
                         microtimestep,
                         macrotimestep,
                     ) - velocity_solid_adjoint_array[m])) * solid.dx)
            lhs += (0.5 * time_step * form_solid(
                linear_extrapolation(displacement_solid_array, m, gauss_1,
                                     microtimestep),
                linear_extrapolation(velocity_solid_array, m, gauss_1,
                                     microtimestep),
                adjoint_reconstruction(
                    displacement_solid_adjoint_array,
                    m,
                    gauss_1,
                    microtimestep,
                    macrotimestep,
                ) - displacement_solid_adjoint_array[m],
                adjoint_reconstruction(
                    velocity_solid_adjoint_array,
                    m,
                    gauss_1,
                    microtimestep,
                    macrotimestep,
                ) - velocity_solid_adjoint_array[m],
                solid,
                param,
            ))
            lhs += (0.5 * time_step * form_solid(
                linear_extrapolation(displacement_solid_array, m, gauss_2,
                                     microtimestep),
                linear_extrapolation(velocity_solid_array, m, gauss_2,
                                     microtimestep),
                adjoint_reconstruction(
                    displacement_solid_adjoint_array,
                    m,
                    gauss_2,
                    microtimestep,
                    macrotimestep,
                ) - displacement_solid_adjoint_array[m],
                adjoint_reconstruction(
                    velocity_solid_adjoint_array,
                    m,
                    gauss_2,
                    microtimestep,
                    macrotimestep,
                ) - velocity_solid_adjoint_array[m],
                solid,
                param,
            ))
            lhs += (0.5 * time_step * param.NU * dot(
                grad(
                    linear_extrapolation(velocity_fluid_array, m, gauss_1,
                                         microtimestep)),
                solid.normal_vector,
            ) * (adjoint_reconstruction(
                displacement_solid_adjoint_array,
                m,
                gauss_1,
                microtimestep,
                macrotimestep,
            ) - displacement_solid_adjoint_array[m]) * solid.ds(1))
            lhs += (0.5 * time_step * param.NU * dot(
                grad(
                    linear_extrapolation(velocity_fluid_array, m, gauss_2,
                                         microtimestep)),
                solid.normal_vector,
            ) * (adjoint_reconstruction(
                displacement_solid_adjoint_array,
                m,
                gauss_2,
                microtimestep,
                macrotimestep,
            ) - displacement_solid_adjoint_array[m]) * solid.ds(1))

            m += 1
            microtimestep = microtimestep.after
            residuals.append(assemble(0.5 * rhs - 0.5 * lhs))

        macrotimestep = macrotimestep.after

    return residuals
Exemplo n.º 12
0
    param.NUMBER_ELEMENTS_VERTICAL,
    diagonal="right",
)
mesh_s = RectangleMesh(
    Point(0.0, -1.0),
    Point(4.0, 0.0),
    param.NUMBER_ELEMENTS_HORIZONTAL,
    param.NUMBER_ELEMENTS_VERTICAL,
    diagonal="left",
)
boundary_mesh = BoundaryMesh(mesh_f, "exterior")
inner_boundary = Inner_boundary()
mesh_i = SubMesh(boundary_mesh, inner_boundary)

# Create function spaces
fluid = Space(mesh_f, param.LOCAL_MESH_SIZE_FLUID)
solid = Space(mesh_s, param.LOCAL_MESH_SIZE_SOLID)
interface = Space(mesh_i)

# Create time interval structures
fluid_timeline = TimeLine()
fluid_timeline.unify(
    param.TIME_STEP, param.LOCAL_MESH_SIZE_FLUID, param.GLOBAL_MESH_SIZE
)
solid_timeline = TimeLine()
solid_timeline.unify(
    param.TIME_STEP, param.LOCAL_MESH_SIZE_SOLID, param.GLOBAL_MESH_SIZE
)

# Set deoupling method
if param.RELAXATION: