def test_vector_constant():
    mesh = UnitCubeMesh(MPI.COMM_WORLD, 2, 2, 2)
    c0 = Constant(mesh, [1.0, 2.0])
    c1 = Constant(mesh, np.array([1.0, 2.0]))
    assert (c0.value.all() == c1.value.all())
    c0.value += 1.0
    assert c0.value.all() == np.array([2.0, 3.0]).all()
    c0.value -= [1.0, 2.0]
    assert c0.value[0] == c0.value[1]
Exemple #2
0
def assemble_div_vector(k, offset):
    mesh = create_quad_mesh(offset)
    V = FunctionSpace(mesh, ("RTCF", k + 1))
    v = ufl.TestFunction(V)
    form = ufl.inner(Constant(mesh, 1), ufl.div(v)) * ufl.dx
    L = fem.assemble_vector(form)
    return L[:]
def test_tensor_constant():
    mesh = UnitCubeMesh(MPI.COMM_WORLD, 2, 2, 2)
    data = [[1.0, 2.0, 1.0], [1.0, 2.0, 1.0], [1.0, 2.0, 1.0]]
    c0 = Constant(mesh, data)
    assert c0.value.shape == (3, 3)
    assert c0.value.all() == np.asarray(data).all()
    c0.value *= 2.0
    assert c0.value.all() == (2.0 * np.asarray(data)).all()
def test_scalar_constant():
    mesh = UnitCubeMesh(MPI.COMM_WORLD, 2, 2, 2)
    c = Constant(mesh, 1.0)
    assert c.value.shape == ()
    assert c.value == 1.0
    c.value += 1.0
    assert c.value == 2.0
    c.value = 3.0
    assert c.value == 3.0
def test_wrong_dim():
    mesh = UnitCubeMesh(MPI.COMM_WORLD, 2, 2, 2)
    c = Constant(mesh, [1.0, 2.0])
    assert c.value.shape == (2, )
    with pytest.raises(ValueError):
        c.value = [1.0, 2.0, 3.0]
def test_reshape():
    mesh = UnitCubeMesh(MPI.COMM_WORLD, 2, 2, 2)
    c = Constant(mesh, 1.0)
    with pytest.raises(ValueError):
        c.value.resize(100)
Exemple #7
0
with w1["phi"].vector.localForm() as local:
    local.set(0.95)

displ_bc2 = Function(w0["displ"].function_space.sub(2).collapse())

t = 0.1
tp = args.tp

inital_times = numpy.linspace(t, tp, 5)
afterload_times = tp + numpy.logspace(numpy.log10(fecoda.mps.t_begin),
                                      numpy.log10(tp + args.end), args.steps)

times = numpy.hstack((inital_times, afterload_times))
dtimes = numpy.diff(times)

dt = Constant(mesh, 0.0)
t = Constant(mesh, 0.0)

bottom_facets = mt_facet.indices[numpy.where(mt_facet.values == 1)[0]]
bottom_dofs = locate_dofs_topological(
    (w0["displ"].function_space.sub(2), displ_bc2.function_space), 2,
    bottom_facets)

comm = MPI.COMM_WORLD
filename = f"{meshname}_{args.out}"
with XDMFFile(comm, f"{filename}.xdmf", "w") as ofile:
    ofile.write_mesh(mesh)

ksp = [None] * 4
log = {"compl": [], "times": []}
Exemple #8
0
phi_bc = Function(w0["phi"].function_space)
displ_bc = Function(w0["displ"].function_space)
temp_bc = Function(w0["temp"].function_space)

times = t0 + np.logspace(np.log10(fecoda.mps.t_begin), np.log10(t1 - t0), 50)
times = np.hstack(([
    t0,
], times))
dtimes = np.diff(times)

if rank == 0:
    logger.info("Simulation times: {}".format(times))
    plt.plot(times, range(len(times)), marker="o")
    plt.savefig("simulation_times.pdf")

dt = Constant(mesh, 0.0)
t = Constant(mesh, 0.0)

mesh.topology.create_connectivity_all()

leftW0 = locate_dofs_topological(w0["displ"].function_space, 2,
                                 left_side_facets)

comm = MPI.COMM_WORLD
filename = "cantilever"
with XDMFFile(comm, f"{filename}.xdmf", "w") as ofile:
    ofile.write_mesh(mesh)

force = Constant(mesh, 0.0)
dforce = Constant(mesh, 0.0)
Exemple #9
0
    local.set(fecoda.misc.room_temp)
with w1["temp"].vector.localForm() as local:
    local.set(fecoda.misc.room_temp)

with w0["phi"].vector.localForm() as local:
    local.set(0.95)
with w1["phi"].vector.localForm() as local:
    local.set(0.95)

inital_times = np.linspace(t, tp, 5, endpoint=False)
loading_times = np.linspace(tp, tp + 1.0, args.steps)

times = np.hstack((inital_times, loading_times))
dtimes = np.diff(times)

dt = Constant(mesh, 0.0)
t = Constant(mesh, 0.0)

bottom_left_lines = mt_line.indices[np.where(mt_line.values == 3)[0]]
bottom_left_dofs = locate_dofs_topological(w0["displ"].function_space, 1,
                                           bottom_left_lines)

bottom_right_lines = mt_line.indices[np.where(mt_line.values == 2)[0]]
bottom_right_dofs = locate_dofs_topological(
    (w0["displ"].function_space.sub(2),
     w0["displ"].function_space.sub(2).collapse()), 1, bottom_right_lines)

top_load_dofs = locate_dofs_topological(
    (w0["displ"].function_space.sub(2),
     w0["displ"].function_space.sub(2).collapse()), 1, top_load_facets)