Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stable #197

Merged
merged 10 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMake/catch.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Captain! If catch2 alpine files do not exist, fetch content
if( NOT EXISTS "usr/include/catch2/" OR
NOT EXISTS "usr/lib/libCatch2Main.a" OR
NOT EXISTS "usr/lib/libCatch2.a" )
if( NOT EXISTS "/usr/include/catch2/" OR
NOT EXISTS "/usr/lib/libCatch2Main.a" OR
NOT EXISTS "/usr/lib/libCatch2.a" )

message( "Ahoy! Not found in system locations - installing from source..." )

Expand Down
2 changes: 1 addition & 1 deletion CMake/compile_time_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set( CMAKE_BUILD_TYPE "Release" )

# preprocessor definitions in source code are defined below:
set( description "(no description added yet)" )
set( GITR_USE_CUDA 1 CACHE STRING "${description}" FORCE )
set( GITR_USE_CUDA 0 CACHE STRING "${description}" FORCE )
set( GITR_USE_OPENMP 0 CACHE STRING "${description}" FORCE )
set( GITR_USE_MPI 0 CACHE STRING "${description}" FORCE )
set( GITR_USE_DOUBLE 1 CACHE STRING "${description}" FORCE )
Expand Down
7 changes: 7 additions & 0 deletions CMake/crosslink_components.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ target_link_libraries( interp2d thrust )

target_link_libraries( flags libconfig_cxx libconfig_c thrust )


target_link_libraries( utils
libconfig_cxx
libconfig_c
Expand All @@ -17,6 +18,10 @@ target_link_libraries( utils
netcdf_cxx
netcdf_c )

target_link_libraries( config_interface
netcdf_cxx
netcdf_c )

target_link_libraries( boris_data_broker
boris
flags
Expand Down Expand Up @@ -163,6 +168,8 @@ target_link_libraries( file_io_tests
Catch2::Catch2WithMain
)

target_link_libraries( interpolator_tests Catch2::Catch2WithMain )

if( GITR_USE_MPI )
target_link_libraries( GITR mpi )
target_link_libraries( coulomb_tests mpi )
Expand Down
14 changes: 14 additions & 0 deletions CMake/define_test_components.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ enable_testing()

add_test(NAME sample_test COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/examples/sft_a/test.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/examples/sft_a )

set( cpu_test_targets
interpolator_tests
)

# gpu test targets first
set( gpu_test_targets
boris_tests
Expand All @@ -14,6 +18,16 @@ set( gpu_test_targets
file_io_tests
)

foreach( component IN LISTS cpu_test_targets )

add_executable( ${component} test_src/${component}.cpp )

add_test( NAME ${component} COMMAND ${component} )

target_include_directories( ${component} PUBLIC include test_include )

endforeach()

# compile with nvcc
if( GITR_USE_CUDA )

Expand Down
8 changes: 4 additions & 4 deletions CMake/filepaths_default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,30 @@ else()
set( NETCDF_C_HEADERS_DIR ${NETCDF_C_HEADERS_DIR} CACHE STRING "${description}" )
endif()

if( NOT DEFINED ${LIBCONFIG_CXX_LIB_DIR})
if( NOT DEFINED LIBCONFIG_CXX_LIB_DIR)
set( LIBCONFIG_CXX_LIB_DIR "/usr/lib/x86_64-linux-gnu" "/usr/lib"
CACHE STRING "${description}" )
else()
set( LIBCONFIG_CXX_LIB_DIR ${LIBCONFIG_CXX_LIB_DIR}
CACHE STRING "${description}" )
endif()

if( NOT DEFINED ${LIBCONFIG_C_LIB_DIR} )
if( NOT DEFINED LIBCONFIG_C_LIB_DIR )
set( LIBCONFIG_C_LIB_DIR "/usr/lib/x86_64-linux-gnu" "/usr/lib"
CACHE STRING "${description}" )
else()
set( LIBCONFIG_C_LIB_DIR ${LIBCONFIG_C_LIB_DIR}
CACHE STRING "${description}" )
endif()

if( NOT DEFINED ${LIBCONFIG_CXX_HEADERS_DIR} )
if( NOT DEFINED LIBCONFIG_CXX_HEADERS_DIR )
set( LIBCONFIG_CXX_HEADERS_DIR "/usr/lib/x86_64-linux-gnu" "/usr/lib"
CACHE STRING "${description}" )
else()
set( LIBCONFIG_CXX_HEADERS_DIR ${LIBCONFIG_CXX_HEADERS_DIR}
CACHE STRING "${description}" )
endif()
if( NOT DEFINED ${LIBCONFIG_C_HEADERS_DIR} )
if( NOT DEFINED LIBCONFIG_C_HEADERS_DIR )
set( LIBCONFIG_C_HEADERS_DIR "/usr/lib/x86_64-linux-gnu" "/usr/lib"
CACHE STRING "${description}" )
else()
Expand Down
2 changes: 2 additions & 0 deletions containers/Dockerfile_alpine
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ run apk add --update netcdf-dev
run apk add --update netcdf-cxx4-dev
run apk add --update catch2-3 --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing
run apk add --update libconfig-dev
run apk add --update gdb
run apk add --update ninja
#cli11
#I think that's it... and we need GITR itself too... should we just install it now...

Expand Down
2 changes: 1 addition & 1 deletion containers/build_alpine.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#DOCKER_BUILDKIT=1 \
docker build \
--file GITR/containers/Dockerfile_alpine \
--file containers/Dockerfile_alpine \
--tag alpine_interactive_image .
3 changes: 3 additions & 0 deletions examples/sft_a/generate_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@ def generate():
Ti =np.zeros(nZ);
Ti = TD0+dT_ds*z;
Ti2D = np.matlib.repmat(Ti,nR,1);


vz2D = np.transpose(vz2D)
Ti2D = np.transpose(Ti2D)

# Captain! Ti2D is nZ rows and nR columns

# Write 2D plasma profiles to netcdf
rootgrp = netCDF4.Dataset("input/profiles.nc", "w", format="NETCDF4")
Expand Down
3 changes: 2 additions & 1 deletion examples/sft_a/input/gitrInput.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ backgroundPlasmaProfiles =
timeStep =
{
dt = 1E-8;
nT = 4000000;
# Captain! Changed from 4e6 to 4e4 for a faster test
nT = 40000;
}

surfaces =
Expand Down
Binary file modified examples/sft_a/input/particleSource.nc
Binary file not shown.
Binary file modified examples/sft_a/input/profiles.nc
Binary file not shown.
103 changes: 103 additions & 0 deletions include/background_plasma.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#pragma once
#include "config_interface.h"
#include "array.h"
#include <cstdlib>

class temperature_grid_type
{
public:

temperature_grid_type( libconfig_string_query const &query_metadata,
std::string parent_module_name )
:
full_module_path( parent_module_name + "." + module_name + "." )
{
// metadata keys (put in a namespace later?)
std::string raw_input_file_key = "fileString";

// meta keys have values that serve as keys to a final value
std::string r_grid_size_meta_key = "gridNrString";
std::string y_grid_size_meta_key = "gridNyString";
std::string z_grid_size_meta_key = "gridNzString";

std::string r_grid_meta_key = "gridRString";
std::string y_grid_meta_key = "gridYString";
std::string z_grid_meta_key = "gridZString";

std::string ion_temp_data_meta_key = "IonTempString";
std::string electron_temp_data_meta_key = "ElectronTempString";
std::string ion_temp_data_key;
std::string electron_temp_data_key;

// create netcdf file reader object:
std::string raw_input_file_path;

query_metadata( full_module_path + raw_input_file_key, raw_input_file_path );

// step 0: meta_key --> key
std::string r_grid_size_key;
std::string z_grid_size_key;
query_metadata( full_module_path + r_grid_size_meta_key, r_grid_size_key );
query_metadata( full_module_path + z_grid_size_meta_key, z_grid_size_key );

query_metadata( full_module_path + ion_temp_data_meta_key, ion_temp_data_key );
query_metadata( full_module_path + electron_temp_data_meta_key, electron_temp_data_key );

// query query_raw_input using the keys and values above
netcdf_string_query const query_raw_input( "input/" + raw_input_file_path );

int r_grid_size = -1;
int z_grid_size = -1;
query_raw_input( r_grid_size_key, r_grid_size );
query_raw_input( z_grid_size_key, z_grid_size );

// check grid sizes here:
if( r_grid_size == -1 ) std::cout << "error: r_grid_size is -1";
if( z_grid_size == -1 ) std::cout << "error: z_grid_size is -1";

ti.resize( r_grid_size * z_grid_size );
te.resize( r_grid_size * z_grid_size );

query_raw_input( ion_temp_data_key, ti.data() );
query_raw_input( electron_temp_data_key, te.data() );
}

// members:
sim::Array< double > ti;
sim::Array< double > te;

// include these as sim::array initially and then pass to tensor class
// ti data
// te data

/*
Temperature =
{
#ti = 10.0;
#te = 10.0;
fileString = "profiles.nc";
gridNrString = "nR";
gridNzString = "nZ";
gridRString = "gridR";
gridZString = "gridZ";
IonTempString = "ti";
ElectronTempString = "te";
}
*/
std::string const module_name = "Temperature";
std::string const full_module_path;
};

class background_plasma
{
public:

std::string const module_name = "backgroundPlasmaProfiles";

temperature_grid_type temperature_grid;

background_plasma( libconfig_string_query const &query_metadata )
:
temperature_grid( query_metadata, module_name )
{ }
};
63 changes: 59 additions & 4 deletions include/config_interface.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#include <iostream>
#include <string>
#include <memory>
Expand All @@ -7,9 +8,59 @@
#include <cassert>
#include <typeinfo>

#include "config_interface_exceptions.h"
#include "netcdf.h"
#include "ncFile.h"
#include "ncVar.h"
#include "ncDim.h"
#include "libconfig.h++"

class netcdf_string_query
{
public:

netcdf_string_query( std::string netcdf_file_init = "" );

~netcdf_string_query();

template< typename T >
void operator()( std::string const &query_key, T &query_value ) const;

template< typename T >
void operator()( std::string const &query_key, T* query_value ) const;

std::string netcdf_file_name = "empty";

netCDF::NcFile nc;
};

template< typename T >
void netcdf_string_query::operator()( std::string const &query_key, T* query_value ) const
{
std::cout << "Ahoy, Captain! Correct overload called for " << query_key << std::endl;

netCDF::NcVar ncvar;

ncvar = nc.getVar( query_key );

if( ncvar.isNull() )
{
std::cout << "error: could not find " << query_key << std::endl;
}

else ncvar.getVar( query_value );
}

template< typename T >
void netcdf_string_query::operator()( std::string const &query_key, T &query_value ) const
{
netCDF::NcDim nc_nx(nc.getDim(query_key));

int n_x = nc_nx.getSize();

query_value = n_x;
}


/* This class wraps the libconfig object and inserts
a key-string mapping in between. This creates an
internal separation between the internal representation
Expand Down Expand Up @@ -42,7 +93,7 @@ void libconfig_string_query::operator()( std::string const query_key,

if( cfg.exists( query_key.c_str() ) == false )
{
throw invalid_key( query_key );
throw 0;
}

auto const &setting = cfg.getRoot().lookup( query_key );
Expand Down Expand Up @@ -76,7 +127,9 @@ void libconfig_string_query::operator()( std::string const query_key, T &query_v
{
if( cfg.exists( query_key.c_str() ) == false )
{
throw invalid_key( query_key );
//throw invalid_key( query_key );
std::cout << "libconfig could not find" << query_key << std::endl;
throw 0;
}

auto const &setting = cfg.getRoot().lookup( query_key );
Expand All @@ -94,7 +147,9 @@ void libconfig_string_query::operator()( std::string const query_key, T &query_v

if( success == false )
{
throw lookup_failed( query_key );
//throw lookup_failed( query_key );
std::cout << "libconfig " << query_key << " lookup failed!" << std::endl;
throw 0;
}
}
}
Expand Down
Loading
Loading