예제 #1
0
def test_initialize_fneq(Case, dtype_device):
    dtype, device = dtype_device
    lattice = Lattice(D2Q9, device, dtype)
    if Case == TaylorGreenVortex3D:
        lattice = Lattice(D3Q27, dtype=dtype, device=device)
    flow = Case(resolution=16, reynolds_number=1000, mach_number=0.01, lattice=lattice)
    collision = BGKCollision(lattice, tau=flow.units.relaxation_parameter_lu)
    streaming = StandardStreaming(lattice)
    simulation_neq = Simulation(flow=flow, lattice=lattice, collision=collision, streaming=streaming)

    pre_rho = lattice.rho(simulation_neq.f)
    pre_u = lattice.u(simulation_neq.f)

    simulation_neq.initialize_f_neq()

    post_rho = lattice.rho(simulation_neq.f)
    post_u = lattice.u(simulation_neq.f)
    assert(torch.allclose(pre_rho,post_rho,1e-6))
    assert(torch.allclose(pre_u,post_u))

    if Case == TaylorGreenVortex2D:
        error_reporter_neq = ErrorReporter(lattice, flow, interval=1, out=None)
        error_reporter_eq = ErrorReporter(lattice, flow, interval=1, out=None)
        simulation_eq = Simulation(flow=flow, lattice=lattice, collision=collision, streaming=streaming)
        simulation_neq.reporters.append(error_reporter_neq)
        simulation_eq.reporters.append(error_reporter_eq)

        simulation_neq.step(10)
        simulation_eq.step(10)
        error_u, error_p = np.mean(np.abs(error_reporter_neq.out), axis=0).tolist()
        error_u_eq, error_p_eq = np.mean(np.abs(error_reporter_eq.out), axis=0).tolist()

        assert(error_u < error_u_eq)
예제 #2
0
def convergence(ctx, init_f_neq):
    """Use Taylor Green 2D for convergence test in diffusive scaling."""
    device, dtype = ctx.obj['device'], ctx.obj['dtype']
    lattice = Lattice(D2Q9, device, dtype)
    error_u_old = None
    error_p_old = None
    print(("{:>15} " * 5).format("resolution", "error (u)", "order (u)",
                                 "error (p)", "order (p)"))

    for i in range(4, 9):
        resolution = 2**i
        mach_number = 8 / resolution

        # Simulation
        flow = TaylorGreenVortex2D(resolution=resolution,
                                   reynolds_number=10000,
                                   mach_number=mach_number,
                                   lattice=lattice)
        collision = BGKCollision(lattice,
                                 tau=flow.units.relaxation_parameter_lu)
        streaming = StandardStreaming(lattice)
        simulation = Simulation(flow=flow,
                                lattice=lattice,
                                collision=collision,
                                streaming=streaming)
        if (init_f_neq):
            simulation.initialize_f_neq()
        error_reporter = ErrorReporter(lattice, flow, interval=1, out=None)
        simulation.reporters.append(error_reporter)
        for _ in range(10 * resolution):
            simulation.step(1)
        error_u, error_p = np.mean(np.abs(error_reporter.out), axis=0).tolist()
        factor_u = 0 if error_u_old is None else error_u_old / error_u
        factor_p = 0 if error_p_old is None else error_p_old / error_p
        error_u_old = error_u
        error_p_old = error_p
        print("{:15} {:15.2e} {:15.1f} {:15.2e} {:15.1f}".format(
            resolution, error_u, factor_u / 2, error_p, factor_p / 2))
    if factor_u / 2 < 1.9:
        print("Velocity convergence order < 2.")
    if factor_p / 2 < 0.9:
        print("Velocity convergence order < 1.")
    if factor_u / 2 < 1.9 or factor_p / 2 < 0.9:
        sys.exit(1)
    else:
        return 0
예제 #3
0
                                 interval=postplotinterval * 2,
                                 out=None)
energy_f = ObservableReporter(IncompressibleKineticEnergy(lattice, flow_fine),
                              interval=postplotinterval * 2,
                              out=None)
spectrum_f = ObservableReporter(EnergySpectrum(lattice, flow_fine),
                                interval=postplotinterval * 2,
                                out=None)
f_reporter = FReporter(2 * data_interval)
simulation.reporters.append(f_reporter)
simulation.reporters.append(enstrophy_f)
simulation.reporters.append(energy_f)
simulation.reporters.append(spectrum_f)

simulation.initialize_pressure()
simulation.initialize_f_neq()
_ = simulation.step(2 * n_steps)

########################################################################################################################
##### Make Data Pairs
########################################################################################################################
print('Make Data Pairs and shuffle training data')
data = torch.stack(f_reporter.fs).cpu()
f_reporter.fs = []

inputs = data[0:-1]
outputs = data[1:]

f_init = inputs[nr_init].clone()
f_output = outputs[-1].clone()