예제 #1
0
def test_spectral_nabla2(parameters):
    p = parameters
    x = np.linspace(0, p.lx, p.nx, endpoint=False)
    z = np.linspace(0, p.lz, p.nz, endpoint=False)
    X, Z = np.meshgrid(x, z, indexing="ij")

    array_factory = ArrayFactory(p, np)
    spatial_diff = SpatialDifferentiator(p, np, array_factory=array_factory)
    basis_fns = [BasisFunctions.COMPLEX_EXP, BasisFunctions.COMPLEX_EXP]

    var = Variable(
        p,
        np,
        sd=spatial_diff,
        array_factory=array_factory,
        basis_functions=basis_fns,
    )
    var[:] = 1

    nabla2 = var.snabla2()

    n, m = array_factory.make_mode_number_matrices()
    true_nabla2 = -((2 * np.pi / p.lx * n)**2) - (2 * np.pi / p.lz * m)**2

    assert_array_almost_equal(nabla2, true_nabla2)
예제 #2
0
def test_fully_spectral_array_production(parameters):
    array_factory = ArrayFactory(parameters, np)

    spectral = array_factory.make_spectral()
    physical = array_factory.make_physical()

    assert spectral.shape == (2 * parameters.nn + 1, parameters.nm)
    assert physical.shape == (parameters.nx, parameters.nz)
예제 #3
0
def test_fdm_array_production(fdm_parameters):
    array_factory = ArrayFactory(fdm_parameters, np)

    spectral = array_factory.make_spectral()
    physical = array_factory.make_physical()

    assert spectral.shape == (fdm_parameters.nn, fdm_parameters.nz)
    assert physical.shape == (fdm_parameters.nx, fdm_parameters.nz)
예제 #4
0
    def __init__(self, params, xp):
        self._params = params
        self._xp = xp

        # Algorithms
        self._data_trans = DataTransferer(xp)
        self._integrator = Integrator(params, xp)
        self._array_factory = ArrayFactory(params, xp)
        self._spatial_diff = SpatialDifferentiator(params, xp,
                                                   self._array_factory)
        self._spectral_trans = SpectralTransformer(params, xp,
                                                   self._array_factory)

        self._t = 0
        self._loop_counter = 0

        self._dump_vars = []
        self._dump_dvars = []
        self._dump_idx = 0

        self._save_vars = []

        self._tickers = []

        self._timer = Timer()
        self._wallclock_remaining = 0.0
        self._wallclock_ticker = Ticker(100,
                                        self.calc_time_remaining,
                                        is_loop_counter=True)
        self.register_ticker(self._wallclock_ticker)
예제 #5
0
def test_fdm_nabla2(fdm_parameters):
    p = fdm_parameters
    x = np.linspace(0, p.lx, p.nx, endpoint=False)
    z = np.linspace(0, p.lz, p.nz, endpoint=False)
    X, Z = np.meshgrid(x, z, indexing="ij")

    array_factory = ArrayFactory(p, np)
    spatial_diff = SpatialDifferentiator(p, np, array_factory=array_factory)
    basis_fns = [BasisFunctions.COMPLEX_EXP, BasisFunctions.COMPLEX_EXP]

    var = Variable(
        p,
        np,
        sd=spatial_diff,
        array_factory=array_factory,
        basis_functions=basis_fns,
    )
    var[1] = 0.5 * z**2

    nabla2 = var.snabla2()

    true_nabla2 = np.zeros_like(nabla2)
    true_nabla2[1] = -((2 * np.pi)**2) * var[1] + 1

    assert_array_almost_equal(nabla2[1, 1:-1], true_nabla2[1, 1:-1])
예제 #6
0
def test_transform_periodic_x_fdm_z(fdm_parameters):
    p = fdm_parameters
    array_factory = ArrayFactory(fdm_parameters, np)
    st = SpectralTransformer(fdm_parameters, np, array_factory=array_factory)

    spectral = array_factory.make_spectral()
    physical = array_factory.make_physical()

    x = np.linspace(0, 1.0, p.nx, endpoint=False)
    z = np.linspace(0, 1.0, p.nz)
    X, Z = np.meshgrid(x, z, indexing="ij")

    true_physical = (
        3.0 + np.cos(2 * np.pi * X) + 2.0 * np.cos(2 * 2 * np.pi * X)
    )

    st.to_spectral(
        true_physical,
        spectral,
        basis_functions=[BasisFunctions.COMPLEX_EXP, BasisFunctions.FDM],
    )

    true_spectral = np.zeros_like(spectral)
    true_spectral[0, :] = 3.0
    true_spectral[1, :] = 1.0 / 2
    true_spectral[2, :] = 2.0 / 2

    assert_array_almost_equal(spectral, true_spectral)

    st.to_physical(
        spectral,
        physical,
        basis_functions=[BasisFunctions.COMPLEX_EXP, BasisFunctions.FDM],
    )

    assert_array_almost_equal(physical, true_physical)
예제 #7
0
def test_fdm_laplacian_solver(fdm_parameters):
    p = fdm_parameters
    array_factory = ArrayFactory(p, np)

    basis_fns = [BasisFunctions.COMPLEX_EXP, BasisFunctions.COMPLEX_EXP]

    psi = Variable(p,
                   np,
                   array_factory=array_factory,
                   basis_functions=basis_fns)

    laplacian_solver = LaplacianSolver(p, np, psi, array_factory=array_factory)

    true_soln = array_factory.make_spectral()
    rhs = array_factory.make_spectral()

    true_soln[:, :] = 1.0

    for n in range(p.nn):
        rhs[n, :] = laplacian_solver.laps[n] @ true_soln[n, :]

    soln = laplacian_solver.solve(rhs)

    assert_array_almost_equal(soln, true_soln)
예제 #8
0
def array_factory(parameters):
    return ArrayFactory(parameters, np)