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]
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 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_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)
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": []}
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)
afterload_times, endtime_times)) dtimes = np.diff(times) if rank == 0: logger.info(f"Simulation times: {times}") plt.plot(times, range(len(times)), marker="o") plt.savefig("simulation_times.pdf") W0sub1c = w0["displ"].function_space.sub(1).collapse() W0sub2c = w0["displ"].function_space.sub(2).collapse() displ_bc_y = Function(W0sub1c) displ_bc_z = Function(W0sub2c) displ_bc_top = Function(W0sub1c) dt = Constant(mesh, 0.0) t = Constant(mesh, 0.0) bottom = locate_entities_boundary(mesh, 2, lambda x: np.isclose(x[1], 0.0)) bottomW0 = locate_dofs_topological(w0["displ"].function_space, 2, bottom) top_dofsW0 = locate_dofs_topological( (w0["displ"].function_space.sub(1), W0sub1c), 2, top_load_facets) boundaryf = locate_entities_boundary(mesh, 2, lambda x: [True] * x.shape[1]) boundaryf_dofsW1 = locate_dofs_topological(w0["temp"].function_space, 2, boundaryf) boundaryf_dofsW2 = locate_dofs_topological(w0["phi"].function_space, 2, boundaryf) boundaryf_dofsW3 = locate_dofs_topological(w0["co2"].function_space, 2, boundaryf)
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)
times = t0 + np.logspace(np.log10(ta), np.log10(t1 - t0 - 0.1), args.steps) times_replaced = t1 + np.logspace(np.log10(ta), np.log10(t2 - t1), args.steps) times = np.hstack(((t0, ), times, (t1, ), times_replaced)) 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") W0sub1c = w0["displ"].function_space.sub(1).collapse() W0sub2c = w0["displ"].function_space.sub(2).collapse() displ_bc_y = Function(W0sub1c) displ_bc_z = Function(W0sub2c) dt = Constant(mesh, 0.0) t = Constant(mesh, 0.0) mesh.topology.create_connectivity_all() leftW0 = locate_dofs_topological(w0["displ"].function_space, 1, left_support_lines) rightW0sub1 = locate_dofs_topological(w0["displ"].function_space.sub(1), 1, right_support_lines) comm = MPI.COMM_WORLD filename = args.out with XDMFFile(comm, filename, "w") as ofile: ofile.write_mesh(mesh) force = Constant(mesh, 0.0)