Пример #1
0
def test_l2projection_bounded_3D(polynomial_order, lb, ub):
    xmin, ymin, zmin = 0., 0., 0.
    xmax, ymax, zmax = 1., 1., 1.
    nx = 10

    interpolate_expression = Ball(0.15, [0.5, 0.5, 0.5],
                                  degree=3,
                                  lb=lb,
                                  ub=ub)

    property_idx = 1
    mesh = BoxMesh(Point(xmin, ymin, zmin), Point(xmax, ymax, zmax), nx, nx,
                   nx)

    V = FunctionSpace(mesh, "DG", polynomial_order)

    x = RegularBox(Point(0., 0., 0.), Point(1., 1.,
                                            1.)).generate([100, 100, 100])
    s = assign_particle_values(x, interpolate_expression)

    # Just make a complicated particle, possibly with scalars and vectors mixed
    p = particles(x, [s], mesh)

    vh = Function(V)
    lstsq_rho = l2projection(p, V, property_idx)
    lstsq_rho.project(vh.cpp_object(), lb, ub)

    # Assert if it stays within bounds
    assert np.any(vh.vector().get_local() < ub + 1e-12)
    assert np.any(vh.vector().get_local() > lb - 1e-12)
Пример #2
0
class BoxGrid(object):
	def __init__(self, x0, x1, y0, y1, z0, z1, n, unstructured=False):
		class Left(SubDomain):
			def inside(self, x, on_boundary):
				return near(x[0], x0)
		class Right(SubDomain):
			def inside(self, x, on_boundary):
				return near(x[0], x1)
		class Back(SubDomain):
			def inside(self, x, on_boundary):
				return near(x[1], y0)
		class Front(SubDomain):
			def inside(self, x, on_boundary):
				return near(x[1], y1)
		class Bottom(SubDomain):
			def inside(self, x, on_boundary):
				return near(x[2], z0)
		class Top(SubDomain):
			def inside(self, x, on_boundary):
				return near(x[2], z1)
		if unstructured:
			self.geometry = Box(Point(x0, y0, z0), Point(x1, y1, z1))
			self.mesh = generate_mesh(self.geometry, n)
		else:
			nx = int(round(n**(1./3.)*(x1 - x0)))
			ny = int(round(n**(1./3.)*(y1 - y0)))
			nz = int(round(n**(1./3.)*(z1 - z0)))
			self.mesh = BoxMesh(Point(x0, y0, z0), Point(x1, y1, z1), nx, ny, nz)
		self.domains = MeshFunction("size_t", self.mesh, self.mesh.topology().dim())
		self.domains.set_all(0)
		self.dx = Measure('dx', domain=self.mesh, subdomain_data=self.domains)
		self.boundaries = MeshFunction("size_t", self.mesh, self.mesh.topology().dim()-1)
		self.boundaries.set_all(0)
		self.left = Left()
		self.left.mark(self.boundaries, 1)
		self.right = Right()
		self.right.mark(self.boundaries, 2)
		self.front = Front()
		self.front.mark(self.boundaries, 3)
		self.back = Back()
		self.back.mark(self.boundaries, 4)
		self.bottom = Bottom()
		self.bottom.mark(self.boundaries, 5)
		self.top = Top()
		self.top.mark(self.boundaries, 6)
		self.ds = Measure('ds', domain=self.mesh, subdomain_data=self.boundaries)
		self.dS = Measure('dS', domain=self.mesh, subdomain_data=self.boundaries)
Пример #3
0
def test_mesh_generator_3d():
    """Basic functionality test."""
    mesh = BoxMesh(Point(0.0, 0.0, 0.0), Point(1.0, 1.0, 1.0), 5, 5, 5)
    for x in mesh.coordinates():
        x[0] += 0.5 * x[1] + 0.2 * x[2]

    w = RandomCell(mesh)
    pts = w.generate(3)
    assert len(pts) == mesh.num_cells() * 3

    interpolate_expression = Expression("x[0] + x[1] + x[2]", degree=1)
    s = assign_particle_values(pts, interpolate_expression, on_root=False)

    assert np.linalg.norm(np.sum(pts, axis=1) - s) <= 1e-15

    p = particles(pts, [s], mesh)
    assert pts.shape == p.positions().shape

    for i in range(10000):
        s, t, u, v = w._random_bary(4)
        assert s >= 0 and s <= 1
        assert t >= 0 and t <= 1
        assert u >= 0 and u <= 1
        assert v >= 0 and v <= 1
Пример #4
0
def gen_mesh(n_gridpoints, dim):
    if dim == 2:
        #if(dolfin.__version__[2] <= 4):
        #  mesh = RectangleMesh(0,0,1,1,n_gridpoints,n_gridpoints,"left");
        #else:
        p0 = Point(0, 0)
        p1 = Point(1, 1)
        mesh = RectangleMesh(p0, p1, n_gridpoints, n_gridpoints, "left")

    else:
        p0 = Point(0, 0, 0)
        p1 = Point(1, 1, 0)
        mesh = BoxMesh(p0, p1, n_gridpoints, n_gridpoints, n_gridpoints)

    return mesh
Пример #5
0
def test_l2_projection_3D(polynomial_order, in_expression):
    xmin, ymin, zmin = 0.0, 0.0, 0.0
    xmax, ymax, zmax = 1.0, 1.0, 1.0
    nx = 25

    property_idx = 1
    mesh = BoxMesh(Point(xmin, ymin, zmin), Point(xmax, ymax, zmax), nx, nx,
                   nx)

    interpolate_expression = Expression(in_expression, degree=3)

    if len(interpolate_expression.ufl_shape) == 0:
        V = FunctionSpace(mesh, "DG", polynomial_order)
    elif len(interpolate_expression.ufl_shape) == 1:
        V = VectorFunctionSpace(mesh, "DG", polynomial_order)

    v_exact = Function(V)
    v_exact.assign(interpolate_expression)

    x = RandomBox(Point(0.0, 0.0, 0.0), Point(1.0, 1.0,
                                              1.0)).generate([4, 4, 4])
    s = assign_particle_values(x, interpolate_expression)

    # Just make a complicated particle, possibly with scalars and vectors mixed
    p = particles(x, [s], mesh)

    # Do AddDelete sweep
    AD = AddDelete(p, 13, 15, [v_exact])
    AD.do_sweep()

    vh = Function(V)
    lstsq_vh = l2projection(p, V, property_idx)
    lstsq_vh.project(vh.cpp_object())

    error_sq = abs(assemble(dot(v_exact - vh, v_exact - vh) * dx))
    if comm.Get_rank() == 0:
        assert error_sq < 1e-13
Пример #6
0
    def initMesh(self, n):

        self.mesh = BoxMesh(Point(0., 0., 0.), Point(1., 1., 1.), n, n, n)
Пример #7
0
nx, ny, nz = 20, 20, 20


# Initial composition field
class StepFunction(UserExpression):

    def eval_cell(self, values, x, cell):
        c = Cell(mesh, cell.index)
        if c.midpoint()[1] > db + 0.02*np.cos(np.pi*x[0]/float(lmbdax))*np.cos(np.pi*x[2]/float(lmbdaz)):
            values[0] = 1.0
        else:
            values[0] = 0.0


mesh = BoxMesh.create(
    comm, [Point(0.0, 0.0, 0.0), Point(float(lmbdax), 1.0, float(lmbdaz))],
    [nx, ny, nz], CellType.Type.tetrahedron)

# Shift the mesh to line up with the initial step function condition
scale = db * (1.0 - db)
shift = Expression(("0.0", "x[1]*(H - x[1])/S*A*cos(pi/Lx*x[0])*cos(pi/Lz*x[2])", "0.0"),
                   A=0.02, Lx=lmbdax, Lz=lmbdaz, H=1.0, S=scale, degree=4)

V = VectorFunctionSpace(mesh, "CG", 1)
displacement = interpolate(shift, V)
ALE.move(mesh, displacement)

# Entrainment functional measures
de = 1
cf = MeshFunction("size_t", mesh, mesh.topology().dim(), 0)
CompiledSubDomain("x[1] > db - DOLFIN_EPS", db=db).mark(cf, de)
Пример #8
0
def run_with_params(Tb, mu_value, k_s, path):
    run_time_init = clock()

    mesh = BoxMesh(Point(0.0, 0.0, 0.0),
                   Point(mesh_width, mesh_width, mesh_height), nx, ny, nz)

    pbc = PeriodicBoundary()

    WE = VectorElement('CG', mesh.ufl_cell(), 2)
    SE = FiniteElement('CG', mesh.ufl_cell(), 1)
    WSSS = FunctionSpace(mesh,
                         MixedElement(WE, SE, SE, SE),
                         constrained_domain=pbc)
    # W = FunctionSpace(mesh, WE, constrained_domain=pbc)
    # S = FunctionSpace(mesh, SE, constrained_domain=pbc)
    W = WSSS.sub(0).collapse()
    S = WSSS.sub(1).collapse()

    temperature_vals = [27.0 + 273, Tb + 273, 1300.0 + 273, 1305.0 + 273]
    temp_prof = TemperatureProfile(temperature_vals, element=S.ufl_element())

    mu_a = mu_value  # this was taken from the Blankenbach paper, can change

    Ep = b / temp_prof.delta

    mu_bot = exp(-Ep *
                 (temp_prof.bottom * temp_prof.delta - 1573.0) + cc) * mu_a

    # TODO: verify exponentiation
    Ra = rho_0 * alpha * g * temp_prof.delta * h**3 / (kappa_0 * mu_a)
    w0 = rho_0 * alpha * g * temp_prof.delta * h**2 / mu_a
    tau = h / w0
    p0 = mu_a * w0 / h

    log(mu_a, mu_bot, Ra, w0, p0)

    slip_vx = 1.6E-09 / w0  # Non-dimensional
    slip_velocity = Constant((slip_vx, 0.0, 0.0))
    zero_slip = Constant((0.0, 0.0, 0.0))

    time_step = 3.0E11 / tau * 2

    dt = Constant(time_step)
    t_end = 3.0E15 / tau / 5.0  # Non-dimensional times

    u = Function(WSSS)

    # Instead of TrialFunctions, we use split(u) for our non-linear problem
    v, p, T, Tf = split(u)
    v_t, p_t, T_t, Tf_t = TestFunctions(WSSS)

    T0 = interpolate(temp_prof, S)

    mu_exp = Expression(
        'exp(-Ep * (T_val * dTemp - 1573.0) + cc * x[2] / mesh_height)',
        Ep=Ep,
        dTemp=temp_prof.delta,
        cc=cc,
        mesh_height=mesh_height,
        T_val=T0,
        element=S.ufl_element())

    Tf0 = interpolate(temp_prof, S)

    mu = Function(S)
    v0 = Function(W)

    v_theta = (1.0 - theta) * v0 + theta * v

    T_theta = (1.0 - theta) * T0 + theta * T

    Tf_theta = (1.0 - theta) * Tf0 + theta * Tf

    # TODO: Verify forms

    r_v = (inner(sym(grad(v_t)), 2.0 * mu * sym(grad(v))) - div(v_t) * p -
           T * v_t[2]) * dx

    r_p = p_t * div(v) * dx

    heat_transfer = Constant(k_s) * (Tf_theta - T_theta) * dt

    r_T = (
        T_t *
        ((T - T0) + dt * inner(v_theta, grad(T_theta)))  # TODO: Inner vs dot
        +
        (dt / Ra) * inner(grad(T_t), grad(T_theta)) - T_t * heat_transfer) * dx

    v_melt = Function(W)
    z_hat = Constant((0.0, 0.0, 1.0))

    # TODO: inner -> dot, take out Tf_t
    r_Tf = (Tf_t * ((Tf - Tf0) + dt * inner(v_melt, grad(Tf_theta))) +
            Tf_t * heat_transfer) * dx

    r = r_v + r_p + r_T + r_Tf

    bcv0 = DirichletBC(WSSS.sub(0), zero_slip, top)
    bcv1 = DirichletBC(WSSS.sub(0), slip_velocity, bottom)
    bcv2 = DirichletBC(WSSS.sub(0).sub(1), Constant(0.0), back)
    bcv3 = DirichletBC(WSSS.sub(0).sub(1), Constant(0.0), front)

    bcp0 = DirichletBC(WSSS.sub(1), Constant(0.0), bottom)
    bct0 = DirichletBC(WSSS.sub(2), Constant(temp_prof.surface), top)
    bct1 = DirichletBC(WSSS.sub(2), Constant(temp_prof.bottom), bottom)
    bctf1 = DirichletBC(WSSS.sub(3), Constant(temp_prof.bottom), bottom)

    bcs = [bcv0, bcv1, bcv2, bcv3, bcp0, bct0, bct1, bctf1]

    t = 0
    count = 0
    files = DefaultDictByKey(partial(create_xdmf, path))

    while t < t_end:
        mu.interpolate(mu_exp)
        rhosolid = rho_0 * (1.0 - alpha * (T0 * temp_prof.delta - 1573.0))
        deltarho = rhosolid - rho_melt
        # TODO: project (accuracy) vs interpolate
        assign(
            v_melt,
            project(
                v0 - darcy * (grad(p) * p0 / h - deltarho * z_hat * g) / w0,
                W))
        # TODO: Written out one step later?
        # v_melt.assign(v0 - darcy * (grad(p) * p0 / h - deltarho * yvec * g) / w0)
        # TODO: use nP after to avoid projection?

        solve(r == 0, u, bcs)
        nV, nP, nT, nTf = u.split()  # TODO: write with Tf, ... etc

        if count % output_every == 0:
            time_left(count, t_end / time_step,
                      run_time_init)  # TODO: timestep vs dt

            # TODO: Make sure all writes are to the same function for each time step
            files['T_fluid'].write(nTf, t)
            files['p'].write(nP, t)
            files['v_solid'].write(nV, t)
            files['T_solid'].write(nT, t)
            files['mu'].write(mu, t)
            files['v_melt'].write(v_melt, t)
            files['gradp'].write(project(grad(nP), W), t)
            files['rho'].write(project(rhosolid, S), t)
            files['Tf_grad'].write(project(grad(Tf), W), t)
            files['advect'].write(project(dt * dot(v_melt, grad(nTf))), t)
            files['ht'].write(project(heat_transfer, S), t)

        assign(T0, nT)
        assign(v0, nV)
        assign(Tf0, nTf)

        t += time_step
        count += 1

    log('Case mu={}, Tb={}, k={} complete. Run time = {:.2f} minutes'.format(
        mu_a, Tb, k_s, (clock() - run_time_init) / 60.0))
Пример #9
0
def box():
    return BoxMesh(MPI.comm_world, [numpy.array([0, 0, 0]),
                                    numpy.array([2, 2, 2])], [2, 2, 5], CellType.tetrahedron,
                   cpp.mesh.GhostMode.none)
Пример #10
0
def create_mesh():
    N = 20
    x0, y0, z0 = -1.5, -1.5, -0.25
    x1, y1, z1 = 1.5, 1.5, 0.25

    # mesh = UnitCubeMesh.create(N, N, N//2, CellType.Type.hexahedron)
    mesh = BoxMesh(Point(x0, y0, z0), Point(x1, y1, z1), N, N, N//2)
    # mesh = UnitCubeMesh(N, N, N)

    # mesh size is smaller near x=y=0
    # mesh.coordinates()[:, :2] = mesh.coordinates()[:, :2]**2
    # mesh size is smaller near z=0 and mapped to a [-1;0] domain along z
    # mesh.coordinates()[:, 2] = -mesh.coordinates()[:, 2]**2
    # left =  CompiledSubDomain("near(x[0], side) && on_boundary", side = 0.0)
    # right = CompiledSubDomain("near(x[0], side) && on_boundary", side = 1.0)
    class Top(SubDomain):
        def inside(self, x, on_boundary):
            return near(x[2], z1) and on_boundary

    class Bottom(SubDomain):
        def inside(self, x, on_boundary):
            return near(x[2], z0) and on_boundary

    class Left(SubDomain):
        def inside(self, x, on_boundary):
            return near(x[0], x0) and on_boundary

    class Right(SubDomain):
        def inside(self, x, on_boundary):
            return near(x[0], x1) and on_boundary

    class Front(SubDomain):
        def inside(self, x, on_boundary):
            return near(x[1], y0) and on_boundary

    class Back(SubDomain):
        def inside(self, x, on_boundary):
            return near(x[1], y1) and on_boundary

    class Symmetry_x(SubDomain):
        def inside(self, x, on_boundary):
            return near(x[0], 0) and on_boundary

    class Symmetry_y(SubDomain):
        def inside(self, x, on_boundary):
            return near(x[1], 0) and on_boundary



    # exterior facets MeshFunction
    boundaries = MeshFunction("size_t", mesh, mesh.topology().dim()-1)
    boundaries.set_all(0)
    Top().mark(boundaries, 1)
    Bottom().mark(boundaries, 2)
    Left().mark(boundaries, 3)
    Right().mark(boundaries, 4)
    Front().mark(boundaries, 5)
    Back().mark(boundaries, 6)
    # Symmetry_x().mark(boundaries, 2)
    # Symmetry_y().mark(boundaries, 3)


    subdomains = MeshFunction("size_t", mesh, mesh.topology().dim())
    subdomains.set_all(0)
    File("hyperelastic_cube.xml") << mesh
    File("hyperelastic_cube_physical_region.xml") << subdomains
    File("hyperelastic_cube_facet_region.xml") << boundaries

    return (mesh, subdomains, boundaries)
Пример #11
0
#

U_exact = (
    " U*sin(mode*pi*(x[0])) * cos(mode*pi*(x[1])) * cos(mode*pi*(x[2]))",
    "-U*cos(mode*pi*(x[0])) * sin(mode*pi*(x[1])) * cos(mode*pi*(x[2]))",
    " 0.",
)
u_exact = Expression(U_exact, degree=7, U=float(1.0), nu=float(nu), mode=mode)

f = Constant((0.0, 0.0, 0.0))

# Create mesh
xmin, ymin, zmin = geometry["xmin"], geometry["ymin"], geometry["zmin"]
xmax, ymax, zmax = geometry["xmax"], geometry["ymax"], geometry["zmax"]

mesh = BoxMesh(MPI.comm_world, Point(xmin, ymin, zmin),
               Point(xmax, ymax, zmax), nx, ny, nz)
pbc = PeriodicBoundary(geometry)

# xdmf output
xdmf_u = XDMFFile(mesh.mpi_comm(), outdir_base + "u.xdmf")
xdmf_p = XDMFFile(mesh.mpi_comm(), outdir_base + "p.xdmf")
xdmf_curl = XDMFFile(mesh.mpi_comm(), outdir_base + "curl.xdmf")

# Required elements
W_E_2 = VectorElement("DG", mesh.ufl_cell(), k)
T_E_2 = VectorElement("DG", mesh.ufl_cell(), 0)
Wbar_E_2 = VectorElement("DGT", mesh.ufl_cell(), kbar)
Wbar_E_2_H12 = VectorElement("CG", mesh.ufl_cell(), kbar)["facet"]

Q_E = FiniteElement("DG", mesh.ufl_cell(), k - 1)
Qbar_E = FiniteElement("DGT", mesh.ufl_cell(), k)
Пример #12
0
    basis = VectorSpaceBasis(nullspace_basis)
    basis.orthonormalize()

    _x = [basis[i] for i in range(6)]
    nsp = PETSc.NullSpace()
    nsp.create(_x)
    return nsp


# Load mesh from file
# mesh = Mesh(MPI.comm_world)
# XDMFFile(MPI.comm_world, "../pulley.xdmf").read(mesh)

# mesh = UnitCubeMesh(2, 2, 2)
mesh = BoxMesh.create(
    MPI.comm_world, [Point(0, 0, 0)._cpp_object,
                     Point(2, 1, 1)._cpp_object], [12, 12, 12],
    CellType.Type.tetrahedron, dolfin.cpp.mesh.GhostMode.none)
cmap = dolfin.fem.create_coordinate_map(mesh.ufl_domain())
mesh.geometry.coord_mapping = cmap

# Function to mark inner surface of pulley
# def inner_surface(x, on_boundary):
#    r = 3.75 - x[2]*0.17
#    return (x[0]*x[0] + x[1]*x[1]) < r*r and on_boundary


def boundary(x, on_boundary):
    return np.logical_or(x[:, 0] < np.finfo(float).eps,
                         x[:, 0] > 1.0 - np.finfo(float).eps)

Пример #13
0
    basis = VectorSpaceBasis(nullspace_basis)
    basis.orthonormalize()

    _x = [basis[i] for i in range(6)]
    nsp = PETSc.NullSpace()
    nsp.create(_x)
    return nsp


# Load mesh from file
# mesh = Mesh(MPI.comm_world)
# XDMFFile(MPI.comm_world, "../pulley.xdmf").read(mesh)

# mesh = UnitCubeMesh(2, 2, 2)
mesh = BoxMesh(MPI.comm_world,
               [Point(0, 0, 0)._cpp_object,
                Point(2, 1, 1)._cpp_object], [12, 12, 12],
               CellType.Type.tetrahedron, dolfin.cpp.mesh.GhostMode.none)
cmap = dolfin.fem.create_coordinate_map(mesh.ufl_domain())
mesh.geometry.coord_mapping = cmap

# Function to mark inner surface of pulley
# def inner_surface(x, on_boundary):
#    r = 3.75 - x[2]*0.17
#    return (x[0]*x[0] + x[1]*x[1]) < r*r and on_boundary


def boundary(x, on_boundary):
    return np.logical_or(x[:, 0] < 10.0 * np.finfo(float).eps,
                         x[:, 0] > 1.0 - 10.0 * np.finfo(float).eps)

Пример #14
0
def run_with_params(Tb, mu_value, k_s, path):
    run_time_init = clock()

    mesh = BoxMesh(Point(0.0, 0.0, 0.0), Point(mesh_width, mesh_width, mesh_height), nx, ny, nz)

    pbc = PeriodicBoundary()

    WE = VectorElement('CG', mesh.ufl_cell(), 2)
    SE = FiniteElement('CG', mesh.ufl_cell(), 1)
    WSSS = FunctionSpace(mesh, MixedElement(WE, SE, SE, SE), constrained_domain=pbc)
    # W = FunctionSpace(mesh, WE, constrained_domain=pbc)
    # S = FunctionSpace(mesh, SE, constrained_domain=pbc)
    W = WSSS.sub(0).collapse()
    S = WSSS.sub(1).collapse()

    temperature_vals = [27.0 + 273, Tb + 273, 1300.0 + 273, 1305.0 + 273]
    temp_prof = TemperatureProfile(temperature_vals, element=S.ufl_element())

    mu_a = mu_value  # this was taken from the Blankenbach paper, can change

    Ep = b / temp_prof.delta

    mu_bot = exp(-Ep * (temp_prof.bottom * temp_prof.delta - 1573.0) + cc) * mu_a

    # TODO: verify exponentiation
    Ra = rho_0 * alpha * g * temp_prof.delta * h ** 3 / (kappa_0 * mu_a)
    w0 = rho_0 * alpha * g * temp_prof.delta * h ** 2 / mu_a
    tau = h / w0
    p0 = mu_a * w0 / h

    log(mu_a, mu_bot, Ra, w0, p0)

    slip_vx = 1.6E-09 / w0  # Non-dimensional
    slip_velocity = Constant((slip_vx, 0.0, 0.0))
    zero_slip = Constant((0.0, 0.0, 0.0))

    time_step = 3.0E11 / tau * 2

    dt = Constant(time_step)
    t_end = 3.0E15 / tau / 5.0  # Non-dimensional times

    u = Function(WSSS)

    # Instead of TrialFunctions, we use split(u) for our non-linear problem
    v, p, T, Tf = split(u)
    v_t, p_t, T_t, Tf_t = TestFunctions(WSSS)

    T0 = interpolate(temp_prof, S)

    mu_exp = Expression('exp(-Ep * (T_val * dTemp - 1573.0) + cc * x[2] / mesh_height)',
                       Ep=Ep, dTemp=temp_prof.delta, cc=cc, mesh_height=mesh_height, T_val=T0,
                       element=S.ufl_element())

    Tf0 = interpolate(temp_prof, S)

    mu = Function(S)
    v0 = Function(W)

    v_theta = (1.0 - theta) * v0 + theta * v

    T_theta = (1.0 - theta) * T0 + theta * T

    Tf_theta = (1.0 - theta) * Tf0 + theta * Tf

    # TODO: Verify forms

    r_v = (inner(sym(grad(v_t)), 2.0 * mu * sym(grad(v)))
           - div(v_t) * p
           - T * v_t[2]) * dx

    r_p = p_t * div(v) * dx

    heat_transfer = Constant(k_s) * (Tf_theta - T_theta) * dt

    r_T = (T_t * ((T - T0) + dt * inner(v_theta, grad(T_theta)))  # TODO: Inner vs dot
           + (dt / Ra) * inner(grad(T_t), grad(T_theta))
           - T_t * heat_transfer) * dx

    v_melt = Function(W)
    z_hat = Constant((0.0, 0.0, 1.0))

    # TODO: inner -> dot, take out Tf_t
    r_Tf = (Tf_t * ((Tf - Tf0) + dt * inner(v_melt, grad(Tf_theta)))
            + Tf_t * heat_transfer) * dx

    r = r_v + r_p + r_T + r_Tf

    bcv0 = DirichletBC(WSSS.sub(0), zero_slip, top)
    bcv1 = DirichletBC(WSSS.sub(0), slip_velocity, bottom)
    bcv2 = DirichletBC(WSSS.sub(0).sub(1), Constant(0.0), back)
    bcv3 = DirichletBC(WSSS.sub(0).sub(1), Constant(0.0), front)

    bcp0 = DirichletBC(WSSS.sub(1), Constant(0.0), bottom)
    bct0 = DirichletBC(WSSS.sub(2), Constant(temp_prof.surface), top)
    bct1 = DirichletBC(WSSS.sub(2), Constant(temp_prof.bottom), bottom)
    bctf1 = DirichletBC(WSSS.sub(3), Constant(temp_prof.bottom), bottom)

    bcs = [bcv0, bcv1, bcv2, bcv3, bcp0, bct0, bct1, bctf1]

    t = 0
    count = 0
    files = DefaultDictByKey(partial(create_xdmf, path))

    while t < t_end:
        mu.interpolate(mu_exp)
        rhosolid = rho_0 * (1.0 - alpha * (T0 * temp_prof.delta - 1573.0))
        deltarho = rhosolid - rho_melt
        # TODO: project (accuracy) vs interpolate
        assign(v_melt, project(v0 - darcy * (grad(p) * p0 / h - deltarho * z_hat * g) / w0, W))
        # TODO: Written out one step later?
        # v_melt.assign(v0 - darcy * (grad(p) * p0 / h - deltarho * yvec * g) / w0)
        # TODO: use nP after to avoid projection?

        solve(r == 0, u, bcs)
        nV, nP, nT, nTf = u.split()  # TODO: write with Tf, ... etc

        if count % output_every == 0:
            time_left(count, t_end / time_step, run_time_init)  # TODO: timestep vs dt

            # TODO: Make sure all writes are to the same function for each time step
            files['T_fluid'].write(nTf, t)
            files['p'].write(nP, t)
            files['v_solid'].write(nV, t)
            files['T_solid'].write(nT, t)
            files['mu'].write(mu, t)
            files['v_melt'].write(v_melt, t)
            files['gradp'].write(project(grad(nP), W), t)
            files['rho'].write(project(rhosolid, S), t)
            files['Tf_grad'].write(project(grad(Tf), W), t)
            files['advect'].write(project(dt * dot(v_melt, grad(nTf))), t)
            files['ht'].write(project(heat_transfer, S), t)

        assign(T0, nT)
        assign(v0, nV)
        assign(Tf0, nTf)

        t += time_step
        count += 1

    log('Case mu={}, Tb={}, k={} complete. Run time = {:.2f} minutes'.format(mu_a, Tb, k_s, (clock() - run_time_init) / 60.0))
Пример #15
0
 def get(self):
     """Built-in mesh."""
     x = self.pad(self.values)
     return BoxMesh(Point(-x[0] / 2.0, -x[1] / 2.0, -x[2] / 2.0),
                    Point(x[0] / 2.0, x[1] / 2.0, x[2] / 2.0), x[3], x[4],
                    x[5])
Пример #16
0
def box():
    return BoxMesh.create(
        MPI.comm_world,
        [Point(0, 0, 0)._cpp_object,
         Point(2, 2, 2)._cpp_object], [2, 2, 5], CellType.Type.tetrahedron,
        cpp.mesh.GhostMode.none)
Пример #17
0
    basis = VectorSpaceBasis(nullspace_basis)
    basis.orthonormalize()

    _x = [basis[i] for i in range(6)]
    nsp = PETSc.NullSpace()
    nsp.create(_x)
    return nsp


# Load mesh from file
# mesh = Mesh(MPI.comm_world)
# XDMFFile(MPI.comm_world, "../pulley.xdmf").read(mesh)

# mesh = UnitCubeMesh(2, 2, 2)
mesh = BoxMesh(MPI.comm_world,
               [np.array([0.0, 0.0, 0.0]),
                np.array([2.0, 1.0, 1.0])], [12, 12, 12], CellType.tetrahedron,
               dolfin.cpp.mesh.GhostMode.none)
cmap = dolfin.fem.create_coordinate_map(mesh.ufl_domain())
mesh.geometry.coord_mapping = cmap

# Function to mark inner surface of pulley
# def inner_surface(x, on_boundary):
#    r = 3.75 - x[2]*0.17
#    return (x[0]*x[0] + x[1]*x[1]) < r*r and on_boundary


def boundary(x):
    return np.logical_or(x[:, 0] < 10.0 * np.finfo(float).eps,
                         x[:, 0] > 1.0 - 10.0 * np.finfo(float).eps)

Пример #18
0
def mesh(N=20, **params):
    m = BoxMesh(Point(0, 0, 0), Point(L, 1, 1), N, N, N)
    return m