示例#1
0
 def get_laplace(q, phi):
     h = fd.avg(fd.CellVolume(mesh)) / fd.FacetArea(mesh)
     mu = eta / h
     n = fd.FacetNormal(mesh)
     ad = (-fd.inner(2 * fd.avg(phi * n), fd.avg(fd.grad(q))) -
           fd.inner(fd.avg(fd.grad(phi)), 2 * fd.avg(q * n)) + mu *
           fd.inner(2 * fd.avg(phi * n), 2 * fd.avg(q * n))) * fd.dS
     ad += fd.inner(fd.grad(q), fd.grad(phi)) * fd.dx
     return ad
示例#2
0
def min_mesh_size(mesh):
    """Calculate minimum cell diameter in mesh

    Args:
        mesh ([type]): [description]

    Returns:
        float: [description]
    """
    DG0 = fd.FunctionSpace(mesh, "DG", 0)
    h_sizes = fd.assemble(
        fd.CellDiameter(mesh) / fd.CellVolume(mesh) * fd.TestFunction(DG0) *
        fd.dx).dat.data_ro
    local_min_size = np.max(h_sizes)
    min_size = mesh.comm.allreduce(local_min_size, op=MPI.MAX)
    return min_size
wh, vh, mu_h = fd.TestFunctions(W)

# 3.2) Set initial conditions
# ---- previous solution
# concentrations
c0 = fd.Function(DG1, name="c0")
c0.assign(0.0)

# ----------------------
# 3.4) Variational Form
# ----------------------
# coefficients
dt = np.sqrt(tol)
dtc = fd.Constant(dt)
n = fd.FacetNormal(mesh)
h = fd.sqrt(2) * fd.CellVolume(mesh) / fd.CellDiameter(mesh)

# advective velocity
velocity = fd.Function(vDG1)
velocity.interpolate(v_inlet)
vnorm = fd.sqrt(fd.dot(velocity, velocity))

# upwind term
vn = 0.5 * (fd.dot(velocity, n) + abs(fd.dot(velocity, n)))
cupw = fd.conditional(fd.dot(velocity, n) > 0, ch, lmbd_h)

# Diffusion tensor
Diff = fd.Identity(mesh.geometric_dimension()) * Dm
# Diff = fd.Identity(mesh.geometric_dimension())*(Dm + d_t*vnorm) + \
#     fd.Constant(d_l-d_t)*fd.outer(velocity, velocity)/vnorm