Пример #1
0
 def initial_conditions(self):
     ic1 = fd.project(fd.Expression([0., 0., 0.]), self.V)
     ic2 = fd.project(
         fd.Expression(["0.1*(1-cos(pi*x[2]/Lz/2.))", 0., 0.], Lz=self.Lz),
         self.V)
     #        ic3 = fd.project( fd.Expression(["0.1*x[2]/Lz_B", 0., 0.], Lz_B=self.Lz), self.V )
     self.X.assign(ic2)
     #        self.static_solver()
     self.U.assign(ic1)
Пример #2
0
def initial_values(sim):

    print("Solving steady heat driven cavity to obtain initial values")

    Ra = 2.518084e6

    Pr = 6.99

    sim.grashof_number = sim.grashof_number.assign(Ra / Pr)

    sim.prandtl_number = sim.prandtl_number.assign(Pr)

    dim = sim.mesh.geometric_dimension()

    T_c = sim.cold_wall_temperature.__float__()

    w = fe.interpolate(
        fe.Expression((0., ) + (0., ) * dim + (T_c, ), element=sim.element),
        sim.function_space)

    F = heat_driven_cavity_variational_form_residual(
        sim=sim, solution=w) * fe.dx(degree=sim.quadrature_degree)

    T_h = sim.hot_wall_temperature.__float__()

    problem = fe.NonlinearVariationalProblem(
        F=F,
        u=w,
        bcs=dirichlet_boundary_conditions(sim),
        J=fe.derivative(F, w))

    solver = fe.NonlinearVariationalSolver(problem=problem,
                                           solver_parameters={
                                               "snes_type": "newtonls",
                                               "snes_monitor": True,
                                               "ksp_type": "preonly",
                                               "pc_type": "lu",
                                               "mat_type": "aij",
                                               "pc_factor_mat_solver_type":
                                               "mumps"
                                           })

    def solve():

        solver.solve()

        return w

    w, _ = \
        sapphire.continuation.solve_with_bounded_regularization_sequence(
            solve = solve,
            solution = w,
            backup_solution = fe.Function(w),
            regularization_parameter = sim.grashof_number,
            initial_regularization_sequence = (
                0., sim.grashof_number.__float__()))

    return w
Пример #3
0
    def initialize_solvers(self):
        # Kinematics                # Right Cauchy-Green tensor
        if self.nonlin:
            d = self.X.geometric_dimension()
            I = fd.Identity(d)  # Identity tensor
            F = I + fd.grad(self.X)  # Deformation gradient
            C = F.T * F
            E = (C - I) / 2.  # Green-Lagrangian strain
#            E = 1./2.*( fd.grad(self.X).T + fd.grad(self.X) + fd.grad(self.X).T * fd.grad(self.X) ) # alternative equivalent definition
        else:
            E = 1. / 2. * (fd.grad(self.X).T + fd.grad(self.X)
                           )  # linear strain

        self.W = (self.lam / 2.) * (fd.tr(E))**2 + self.mu * fd.tr(E * E)
        #        f = fd.Constant((0, 0, -self.g)) # body force / rho
        #        T = self.surface_force()

        # Total potential energy
        Pi = self.W * fd.dx
        # Compute first variation of Pi (directional derivative about X in the direction of v)
        F_expr = fd.derivative(Pi, self.X, self.v)

        self.DBC = fd.DirichletBC(self.V, fd.Expression([0., 0., 0.]),
                                  self.bottom_id)
        #        delX = fd.nabla_grad(self.X)
        #        delv_B = fd.nabla_grad(self.v)
        #        T_x_dv = self.lam * fd.div(self.X) * fd.div(self.v) \
        #                + self.mu * ( fd.inner( delX, delv_B + fd.transpose(delv_B) ) )

        self.a_U = fd.dot(self.trial, self.v) * fd.dx
        #        self.L_U = ( fd.dot( self.U, self.v ) - self.dt/2./self.rho * T_x_dv ) * fd.dx
        self.L_U = fd.dot(
            self.U, self.v) * fd.dx - self.dt / 2. / self.rho * F_expr  #\
        #                  + self.dt/2./self.rho*fd.dot(T,self.v)*fd.ds(1) # surface force at x==0 plane
        # + self.dt/2.*fd.dot(f,self.v)*fd.dx # body force
        self.a_X = fd.dot(self.trial, self.v) * fd.dx
        #        self.L_interface = fd.dot(self.phi_vect, self.v) * fd.ds(self.interface_id)
        self.L_X = fd.dot((self.X + self.dt * self.U), self.v) * fd.dx  #\
        #                    - self.dt/self.rho * self.L_interface

        self.LVP_U = fd.LinearVariationalProblem(self.a_U,
                                                 self.L_U,
                                                 self.U,
                                                 bcs=[self.DBC])
        self.LVS_U = fd.LinearVariationalSolver(self.LVP_U)
        self.LVP_X = fd.LinearVariationalProblem(self.a_X,
                                                 self.L_X,
                                                 self.X,
                                                 bcs=[self.DBC])
        self.LVS_X = fd.LinearVariationalSolver(self.LVP_X)
Пример #4
0
    def static_solver(self):
        def epsilon(u):
            return 0.5 * (fd.nabla_grad(u) + fd.nabla_grad(u).T)
            #return sym(nabla_grad(u))

        def sigma(u):
            d = u.geometric_dimension()  # space dimension
            return self.lam * fd.nabla_div(u) * fd.Identity(
                d) + 2 * self.mu * epsilon(u)

        # Define variational problem
        u = fd.TrialFunction(self.V)
        v = fd.TestFunction(self.V)
        #        f = fd.Constant((0, 0, -self.g)) # body force / rho
        f = fd.Constant((0, 0, 0))  # body force / rho
        T = self.surface_force()

        a = fd.inner(sigma(u), epsilon(v)) * fd.dx
        L = fd.dot(f, v) * fd.dx + fd.dot(T, v) * fd.ds(1)
        # Compute solution
        self.DBC = fd.DirichletBC(self.V, fd.Expression([0., 0., 0.]),
                                  self.bottom_id)
        fd.solve(a == L, self.X, bcs=self.DBC)
Пример #5
0
def initial_values(sim):

    return fe.interpolate(
        fe.Expression((0., 0., 0., sim.cold_wall_temperature.__float__()),
                      element=sim.element), sim.function_space)