Commit 7e9704b0 authored by Cianciosa, Mark's avatar Cianciosa, Mark
Browse files

Allow the arguments of piecewise constants to be deferred. This fixed a bug...

Allow the arguments of piecewise constants to be deferred. This fixed a bug where the EFIT test case was not reflecting off the O-Mode cutoff since the spline arguments were not correct.
parent e467dab8
Loading
Loading
Loading
Loading
+19 −12
Original line number Diff line number Diff line
@@ -35,14 +35,16 @@ int main(int argc, const char * argv[]) {

    std::mutex sync;

    //typedef float base;
    typedef double base;
    typedef float base;
    //typedef double base;
    //typedef std::complex<float> base;
    //typedef std::complex<double> base;

    const timeing::measure_diagnostic total("Total Time");

    const size_t num_times = 50000;
    const size_t num_times = 10000;
    const size_t sub_steps = 1;
    const size_t num_steps = num_times/sub_steps;
    const size_t num_rays = 1000000;

    std::vector<std::thread> threads(0);
@@ -104,21 +106,24 @@ int main(int argc, const char * argv[]) {
            kz->set(static_cast<base> (0.0));


            auto eq = equilibrium::make_efit<base> (NC_FILE, x, y, z, sync);
            auto eq = equilibrium::make_efit<base> (NC_FILE, sync);
            //auto eq = equilibrium::make_slab_density<base> ();
            //auto eq = equilibrium::make_no_magnetic_field<base> ();

            //const base endtime = static_cast<base> (60.0);
            const base endtime = static_cast<base> (3.0);
            //const base endtime = static_cast<base> (4.0);
            const base endtime = static_cast<base> (1.0);
            const base dt = endtime/static_cast<base> (num_times);

            //auto dt_var = graph::variable(num_rays, static_cast<base> (dt), "dt");

            //solver::split_simplextic<dispersion::bohm_gross<base>>
            //solver::rk4<dispersion::bohm_gross<base>>
            //solver::adaptive_rk4<dispersion::bohm_gross<base>>
            //solver::rk4<dispersion::simple<base>>
            //solver::rk4<dispersion::ordinary_wave<base>>
            solver::rk4<dispersion::ordinary_wave<base>>
            //solver::rk4<dispersion::extra_ordinary_wave<base>>
            solver::rk4<dispersion::cold_plasma<base>>
            //solver::adaptive_rk4<dispersion::ordinary_wave<base>>
                solve(omega, kx, ky, kz, x, y, z, t, dt, eq);
                //solve(omega, kx, ky, kz, x, y, z, t, dt_var, eq);
            solve.init(kx);
            solve.compile();
            if (thread_number == 0 && false) {
@@ -143,12 +148,14 @@ int main(int argc, const char * argv[]) {
                std::cout << "Omega " << omega->evaluate().at(sample) << std::endl;
            }

            for (size_t j = 0; j < num_times; j++) {
            for (size_t j = 0; j < num_steps; j++) {
                if (thread_number == 0) {
                    solve.print(sample);
                }
                for(size_t k = 0; k < sub_steps; k++) {
                    solve.step();
                }
            }

            if (thread_number == 0) {
                solve.print(sample);
+13 −10
Original line number Diff line number Diff line
@@ -14,8 +14,6 @@
		C73BBE8229F820810027BB7F /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C71342682947F36100672AD4 /* Metal.framework */; };
		C79141B622DAAD0C00E0BA0D /* xrays.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C79141B522DAAD0C00E0BA0D /* xrays.cpp */; };
		C7D371132A0595A40074676E /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C71342682947F36100672AD4 /* Metal.framework */; };
		C7D371202A05B74E0074676E /* efit_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C7D3711F2A05B74E0074676E /* efit_test.cpp */; };
		C7D371212A05D8450074676E /* efit_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C7D3711F2A05B74E0074676E /* efit_test.cpp */; };
		C7D371222A05D84F0074676E /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C71342682947F36100672AD4 /* Metal.framework */; };
		C7E5644528A2A1AA000F31A2 /* backend_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C7931E7328074F540033B488 /* backend_test.cpp */; };
		C7E5645128A2A1DD000F31A2 /* dispersion_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C7931E6B28073BCA0033B488 /* dispersion_test.cpp */; };
@@ -156,7 +154,6 @@
		C71342652947D57900672AD4 /* metal_context.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = metal_context.hpp; sourceTree = "<group>"; };
		C71342682947F36100672AD4 /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; };
		C717CB8D2A02E361008FBDD8 /* FindNetCDF.cmake */ = {isa = PBXFileReference; lastKnownFileType = text; path = FindNetCDF.cmake; sourceTree = "<group>"; };
		C717CB8E2A02EB5C008FBDD8 /* cublic_splines.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = cublic_splines.hpp; sourceTree = "<group>"; };
		C71C1FF527F5379D006997C2 /* dispersion.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = dispersion.hpp; sourceTree = "<group>"; };
		C71C1FF627F5F5A8006997C2 /* solver.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = solver.hpp; sourceTree = "<group>"; };
		C71C1FF727F61DFA006997C2 /* math.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = math.hpp; sourceTree = "<group>"; };
@@ -190,7 +187,6 @@
		C7CEA0042948D02A00F61D09 /* timing.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = timing.hpp; sourceTree = "<group>"; };
		C7CEA0052948EB0F00F61D09 /* cuda_context.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = cuda_context.hpp; sourceTree = "<group>"; };
		C7D371182A05B7230074676E /* efit_test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = efit_test; sourceTree = BUILT_PRODUCTS_DIR; };
		C7D3711F2A05B74E0074676E /* efit_test.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; path = efit_test.cpp; sourceTree = "<group>"; };
		C7E5643E28A2A16F000F31A2 /* backend_test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = backend_test; sourceTree = BUILT_PRODUCTS_DIR; };
		C7E5644A28A2A1C5000F31A2 /* dispersion_test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = dispersion_test; sourceTree = BUILT_PRODUCTS_DIR; };
		C7E5645628A2A204000F31A2 /* solver_test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = solver_test; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -200,7 +196,6 @@
		C7E5648628A2A324000F31A2 /* vector_test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = vector_test; sourceTree = BUILT_PRODUCTS_DIR; };
		C7E5649228A2A34A000F31A2 /* physics_test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = physics_test; sourceTree = BUILT_PRODUCTS_DIR; };
		C7E7D02F283565A200E09896 /* vector_test.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; path = vector_test.cpp; sourceTree = "<group>"; };
		C7E8AA0829FDF5CC00302595 /* coordinates.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = coordinates.hpp; sourceTree = "<group>"; };
		C7FA0DFD29590B7400A31E4D /* jit_test.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = jit_test.cpp; sourceTree = "<group>"; };
		C7FA0E0329590EF300A31E4D /* jit_test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = jit_test; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
@@ -384,8 +379,6 @@
				C7CEA0052948EB0F00F61D09 /* cuda_context.hpp */,
				C7CEA0042948D02A00F61D09 /* timing.hpp */,
				C73BBE9629F8669F0027BB7F /* newton.hpp */,
				C7E8AA0829FDF5CC00302595 /* coordinates.hpp */,
				C717CB8E2A02EB5C008FBDD8 /* cublic_splines.hpp */,
			);
			path = graph_framework;
			sourceTree = "<group>";
@@ -414,7 +407,6 @@
				C7FA0DFD29590B7400A31E4D /* jit_test.cpp */,
				C73BBE6929F7117E0027BB7F /* trigonometry_test.cpp */,
				C73BBE7D29F816E60027BB7F /* piecewise_test.cpp */,
				C7D3711F2A05B74E0074676E /* efit_test.cpp */,
			);
			path = graph_tests;
			sourceTree = SOURCE_ROOT;
@@ -777,7 +769,6 @@
			buildActionMask = 2147483647;
			files = (
				C73BBE6A29F7117E0027BB7F /* trigonometry_test.cpp in Sources */,
				C7D371202A05B74E0074676E /* efit_test.cpp in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
@@ -793,7 +784,6 @@
			isa = PBXSourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
				C7D371212A05D8450074676E /* efit_test.cpp in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
@@ -1342,6 +1332,13 @@
				CODE_SIGN_IDENTITY = "-";
				CODE_SIGN_STYLE = Automatic;
				DEAD_CODE_STRIPPING = YES;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"NC_FILE=\\\"/Users/m4c/Projects/graph_framework/graph_tests/efit.nc\\\"",
					USE_METAL,
					"CXX=\\\"c++\\\"",
					"DEBUG=1",
					"$(inherited)",
				);
				MACOSX_DEPLOYMENT_TARGET = 12.3;
				PRODUCT_NAME = "$(TARGET_NAME)";
			};
@@ -1354,6 +1351,12 @@
				CODE_SIGN_IDENTITY = "-";
				CODE_SIGN_STYLE = Automatic;
				DEAD_CODE_STRIPPING = YES;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"NC_FILE=\\\"/Users/m4c/Projects/graph_framework/graph_tests/efit.nc\\\"",
					USE_METAL,
					"CXX=\\\"c++\\\"",
					"$(inherited)",
				);
				MACOSX_DEPLOYMENT_TARGET = 12.3;
				PRODUCT_NAME = "$(TARGET_NAME)";
			};
+0 −1
Original line number Diff line number Diff line
@@ -9,4 +9,3 @@ add_test_target (physics_test)
add_test_target (jit_test)
add_test_target (trigonometry_test)
add_test_target (piecewise_test)
add_test_target (efit_test)
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ template<typename DISPERSION>
void test_solve(const typename DISPERSION::base tolarance,
                const typename DISPERSION::base omega,
                const typename DISPERSION::base k_guess,
                equilibrium::unique_equilibrium<typename DISPERSION::base> &eq) {
                equilibrium::shared<typename DISPERSION::base> &eq) {
    auto w = graph::variable<typename DISPERSION::base> (1, omega, "\\omega");
    auto kx = graph::variable<typename DISPERSION::base> (1, 0.25, "k_{x}");
    auto ky = graph::variable<typename DISPERSION::base> (1, 0.25, "k_{y}");

graph_tests/efit_test.cpp

deleted100644 → 0
+0 −117
Original line number Diff line number Diff line
//------------------------------------------------------------------------------
///  @file backend_test.cpp
///  @brief Tests for the buffer backend.
//------------------------------------------------------------------------------

//  Turn on asserts even in release builds.
#ifdef NDEBUG
#undef NDEBUG
#endif

#include <cassert>
#include <complex>

#include "../graph_framework/solver.hpp"

//------------------------------------------------------------------------------
///  @brief Efit tests
//------------------------------------------------------------------------------
template<typename T>
void test_efit() {
    std::mutex sync;

    const size_t num_r = 200;
    const size_t num_z = 400;
    const size_t total = num_r*num_z;

    auto omega = graph::variable<T> (total, "\\omega");
    auto kx = graph::variable<T> (total, "k_{x}");
    auto ky = graph::variable<T> (total, "k_{y}");
    auto kz = graph::variable<T> (total, "k_{z}");
    auto x = graph::variable<T> (total, "x");
    auto y = graph::variable<T> (total, "y");
    auto z = graph::variable<T> (total, "z");
    auto t = graph::variable<T> (total, "t");

    t->set(static_cast<T> (0.0));
    omega->set(static_cast<T> (590.0));
    y->set(static_cast<T> (0.0));
    kx->set(static_cast<T> (0.0));
    ky->set(static_cast<T> (0.0));
    kz->set(static_cast<T> (0.0));

    auto eq = equilibrium::make_efit<T> (NC_FILE, x, y, z, sync);

    dispersion::dispersion_interface<dispersion::ordinary_wave<T>> D(omega, kx, ky, kz, x, y, z, t, eq);

    auto ne = eq->get_electron_density(x, y, z);
    auto b = eq->get_magnetic_field(x, y, z);

    std::vector<T> r_buffer(0);
    std::vector<T> z_buffer(0);

    const T dr = 1.7/(num_r - 1);
    const T dz = 3.2/(num_z - 1);

    for (size_t i = 0; i < num_r; i++) {
        for (size_t j = 0; j < num_z; j++) {
            r_buffer.push_back(i*dr + 0.84);
            z_buffer.push_back(j*dz - 1.6);
        }
    }

    auto q = graph::constant(static_cast<T> (1.602176634E-19));
    auto epsion0 = graph::constant(static_cast<T> (8.8541878138E-12));
    auto mu0 = graph::constant(static_cast<T> (M_PI*4.0E-7));
    auto me = graph::constant(static_cast<T> (9.1093837015E-31));
    auto c = graph::one<T> ()/graph::sqrt(epsion0*mu0);
    auto wpe = dispersion::build_plasma_fequency(ne, q, me, c, epsion0);

    x->set(r_buffer);
    z->set(z_buffer);

    graph::input_nodes<T> inputs = {
        graph::variable_cast<T> (omega),
        graph::variable_cast<T> (kx),
        graph::variable_cast<T> (ky),
        graph::variable_cast<T> (kz),
        graph::variable_cast<T> (x),
        graph::variable_cast<T> (y),
        graph::variable_cast<T> (z),
        graph::variable_cast<T> (t)
    };
    graph::output_nodes<T> outputs = {
        D.get_d(),
        ne,
        b->get_x(),
        b->get_y(),
        b->get_z(),
        wpe
    };

    jit::context<T> context;
    context.add_kernel("residule", inputs, outputs, {});
    context.compile();
    auto kernel = context.create_kernel_call("residule", inputs, outputs, total);

    kernel();

    for (size_t i = 0; i < total; i++) {
        context.print(i);
    }
}

//------------------------------------------------------------------------------
///  @brief Main program of the test.
///
///  @params[in] argc Number of commandline arguments.
///  @params[in] argv Array of commandline arguments.
//------------------------------------------------------------------------------
int main(int argc, const char * argv[]) {
    START_GPU
    //test_efit<float> ();
    test_efit<double> ();
    //test_efit<std::complex<float>> ();
    //test_efit<std::complex<double>> ();
    END_GPU
}
Loading