diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index a090484..b7bd803 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -4,6 +4,7 @@ "name": "MOOSE-Linux", "includePath": [ "${workspaceFolder}", + "${workspaceFolder}/ascot5/include", "${workspaceFolder}/build/header_symlinks", "${workspaceFolder}/unit/build/header_symlinks", "${MOOSE_DIR}/framework/build/header_symlinks", @@ -24,6 +25,7 @@ "browse": { "path": [ "${workspaceFolder}", + "${workspaceFolder}/ascot5/include", "${workspaceFolder}/build/header_symlinks", "${workspaceFolder}/unit/build/header_symlinks", "${MOOSE_DIR}/framework/build/header_symlinks", diff --git a/.vscode/launch.json b/.vscode/launch.json index 4027a39..d4969ab 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -38,14 +38,14 @@ } }, { - "name": "(lldb) Unit Test Launch", + "name": "(gdb) Unit Test Launch", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/unit/phaethon-unit-dbg", + "program": "${workspaceFolder}/unit/phaethon-unit-devel", "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": true, + "cwd": "${workspaceFolder}/unit", + "environment": [{"name": "ASAN_OPTIONS", "value": "alloc_dealloc_mismatch=0"}], + "externalConsole": false, "MIMode": "gdb", "logging": { "trace": true, diff --git a/.vscode/settings.json b/.vscode/settings.json index b260d93..ec6436c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,10 +14,70 @@ "sstream": "cpp", "streambuf": "cpp", "vector": "cpp", - "*.csv": "cpp" + "*.csv": "cpp", + "array": "cpp", + "atomic": "cpp", + "strstream": "cpp", + "bit": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "codecvt": "cpp", + "complex": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "regex": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iostream": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "thread": "cpp", + "cfenv": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp", + "valarray": "cpp", + "nonlinearoptimization": "cpp", + "tensor": "cpp" }, "python.linting.flake8Enabled": true, "python.linting.enabled": true, "restructuredtext.languageServer.disabled": true, - "python.pythonPath": "/usr/bin/python" + "python.pythonPath": "/usr/bin/python", + "esbonio.server.enabled": false, + "esbonio.sphinx.buildDir": "/home/mbluteau/work/projects/moose_fi_app/code/phaethon/build" } \ No newline at end of file diff --git a/Makefile b/Makefile index 9d0764a..dda9cf9 100644 --- a/Makefile +++ b/Makefile @@ -49,10 +49,6 @@ XFEM := no include $(MOOSE_DIR)/modules/modules.mk ############################################################################### -# Additional libraries for HDF5 support -ADDITIONAL_INCLUDES := -I/usr/include/hdf5/serial -ADDITIONAL_LIBS := -lhdf5_hl_cpp -lhdf5_cpp -lhdf5_serial_hl -lhdf5_serial - # dep apps APPLICATION_DIR := $(CURDIR) APPLICATION_NAME := phaethon diff --git a/ascot5 b/ascot5 index a19f8ef..641a57c 160000 --- a/ascot5 +++ b/ascot5 @@ -1 +1 @@ -Subproject commit a19f8ef1669502d34f3f0a50ee0e243d991fd039 +Subproject commit 641a57c7d4a5b9d9700d843a793433232746eb54 diff --git a/doc/content/releases.md b/doc/content/releases.md index 7af7ff9..13d1102 100644 --- a/doc/content/releases.md +++ b/doc/content/releases.md @@ -2,13 +2,12 @@ 1. Choose a version number. Look at previous releases and use [semantic versioning](https://semver.org/) to determine what the next number should be. 2. Update the `CHANGELOG` at the top level of the repository for this version, summarising any major changes made since the last release. Use **Fixed**, **Added**, and **Changed** sections. -3. Commit CHANGELOG. -3. Make sure you are on the main branch and there are no uncommitted changes. -4. Mark release with an empty git commit: `git commit --allow-empty -m "REL: vX.Y.Z"` +3. Make sure you are on the main branch and there are no other uncommitted changes. +4. Commit the changelog and mark as a release: `git commit -m "REL: vX.Y.Z"` 5. Tag the commit: `git tag -a vX.Y.Z` and then enter brief description. 6. Push the tag and commit to remote: `git push origin main && git push origin vX.Y.Z` 7. Build the Docker image: `docker build --file Dockerfile --target phaethon --tag phaethon:vX.Y.Z .` -8. Save the Docker image to a compressed tar archive: `docker save phaethon:vX.Y.Z | gzip > phaethon_vX.Y.Z.tar.gz` +8. Save the Docker image to a compressed tar archive: `docker save phaethon:vX.Y.Z | gzip > phaethon-ubuntu-vX_Y_Z.tar.gz` 9. Upload tar archive to [STEP OneDrive](https://ukaeauk.sharepoint.com/:f:/s/STEP_DigitalEnablers_B_3_2/Ei608KfIoLBNlSjtyUf1XMEB-V8nUKx0iFX5p07Z7VE9xw?e=eNWutU) TODO step 4 onwards could be automated by a script or Makefile with the version number as the input \ No newline at end of file diff --git a/docker/Dockerfile-phaethon b/docker/Dockerfile-phaethon index e6dbce9..f6edb3d 100644 --- a/docker/Dockerfile-phaethon +++ b/docker/Dockerfile-phaethon @@ -4,11 +4,11 @@ # TODO should probably move away from using submodules. It means the version # information of dependencies is scattered, and it would be better to centralise # it here. -ARG MOOSE_BASE=moose-ubuntu-dev MOOSE_VER=2021-09-15 +ARG MOOSE_BASE=moose-ubuntu-dev MOOSE_VER=2021-09-15 USER=dev FROM ${MOOSE_BASE}:${MOOSE_VER} AS ascot5-moose-ubuntu # Basic environment -ARG USER=dev +ARG USER WORKDIR $HOME # Set path to shared library for Python interface to use and other environment ENV LD_LIBRARY_PATH=$HOME/ascot5 EDITOR=vim PATH="${HOME}/.local/bin:${PATH}" @@ -42,7 +42,7 @@ RUN python -m pip install --upgrade meshio[all] click FROM phaethon-deps as phaethon-dev # Some development utilities, including git-lfs -RUN sudo apt-get -y install clang-format curl hdf5-tools +RUN sudo apt-get -y install clang-format curl hdf5-tools gdb RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash && \ sudo apt-get -y install git-lfs && \ git lfs install @@ -55,7 +55,10 @@ RUN python -m pip install --upgrade flake8 jupyter ############################## FROM phaethon-deps as phaethon -WORKDIR /home/phaethon +ARG USER +WORKDIR $HOME/phaethon COPY ./ ./ -RUN git clean -dfx && make -j4 && make -C unit/ -j4 -RUN cd unit && ./run_tests + +RUN sudo chown -R ${USER}:${USER} . && git clean -dfx \ + && make -j4 && make -C unit/ -j4 +RUN ./run_tests && cd unit && ./run_tests diff --git a/include/problems/AscotProblem.h b/include/problems/AscotProblem.h index d31e76e..9d994f2 100644 --- a/include/problems/AscotProblem.h +++ b/include/problems/AscotProblem.h @@ -60,6 +60,79 @@ class AscotProblem : public ExternalProblem */ static H5::Group getActiveEndstate(const H5::H5File & hdf5_file); + /** + * @brief Get the Marker Group object + * + * @param hdf5_file the ASCOT5 HDF5 file with input and output data. + * @return H5::Group the HDF5 file group object for the markers + */ + static H5::Group getAscotH5Group(const H5::H5File & hdf5_file, const std::string & group_name); + + /** + * @brief Get an Ascot HDF5 Data object + * + * @tparam T type of the data object + * @param endstate_group the group in which the data object sits + * @param field_name the name of the data object in the HDF5 file + * @return std::vector the data object values + */ + template + static std::vector getAscotH5DataField(H5::Group & endstate_group, + const std::string & field_name); + + /** + * @brief Set an Ascot HDF5 Data object + * + * @tparam T type of the data object + * @param endstate_group the group to which the data object will be written + * @param field_name the name of the data object in the HDF5 file + */ + template + static void setAscotH5DataField(H5::Group & endstate_group, const std::string & field_name); + + /** + * @brief Create and write a dataset to an HDF5 group + * + * @tparam T the type of data + * @param data the data to write to the HDF5 DataSet + * @param name the name of the data field in the HDF5 file + * @param data_space the HDF5 DataSpace for the DataSet + * @param group the HDF5 Group in which the DataSet will be created + */ + template + static void createAndWriteDataset(const std::vector & data, + const std::string & name, + const H5::DataSpace & data_space, + const H5::Group & group); + + /** + * @brief Copy the ASCOT5 endstate data members to the marker group in the HDF5 file + * + * @param marker_group the marker group in the HDF5 file to which the endstate + * is to be copied + */ + void copyEndstate2MarkerGroup(const H5::H5File & hdf5_file); + + /** + * @brief Get the Double type Ascot Endstate Variables from HDF5 File + * + * @param endstate_group the HDF5 file group where the endstate lives + * @return std::unordered_map> the variables of type double_t + * in the endstate + */ + static std::unordered_map> + getAscotH5EndstateDouble(H5::Group & endstate_group); + + /** + * @brief Get the Integer type Ascot Endstate Variables from HDF5 File + * + * @param endstate_group the HDF5 file group where the endstate lives + * @return std::unordered_map> the variables of type int64_t in + * the endstate + */ + static std::unordered_map> + getAscotH5EndstateInt(H5::Group & endstate_group); + /** * @brief Get the indices of wall tiles that each particle has collided with * @@ -110,12 +183,21 @@ class AscotProblem : public ExternalProblem std::vector energies, std::vector weights); + // Endstate variables required for restarting ASCOT5 + std::unordered_map> endstate_data_double; + std::unordered_map> endstate_data_int; + private: /// The name of the AuxVariable to transfer to const VariableName & _sync_to_var_name; /// The Auxiliary system in which the heat flux values will be stored AuxiliarySystem & _problem_system; /// The HDF5 file that is both the ASCOT5 input and output - const H5std_string _ascot5_file_name; + const FileName & _ascot5_file_name; H5::H5File _ascot5_file; + /// Mapping for top-level group name to sub-group prefix for ASCOT5 HDF5 file + static const std::unordered_map hdf5_group_prefix; + // The HDF5 dataset names that constitute the required endstate variables to restart ASCOT5 + static const std::vector endstate_fields_double; + static const std::vector endstate_fields_int; }; diff --git a/phaethon.mk b/phaethon.mk new file mode 100644 index 0000000..8f83bf5 --- /dev/null +++ b/phaethon.mk @@ -0,0 +1,21 @@ +## Some build configurations specific to Phaethon +# This file is automatically included by $(FRAMEWORK_DIR)/app.mk so it doesn't +# need to be included in this project's Makefile + +# Additional libraries for HDF5 support +ifdef CONDA_DEFAULT_ENV +ADDITIONAL_LIBS += -lhdf5_hl_cpp -lhdf5_cpp -lhdf5_hl -lhdf5 +else +ADDITIONAL_INCLUDES += -I/usr/include/hdf5/serial +ADDITIONAL_LIBS += -lhdf5_hl_cpp -lhdf5_cpp -lhdf5_serial_hl -lhdf5_serial +endif + +# ASCOT5 +ASCOT5_DIR := $(APPLICATION_DIR)/ascot5 +ADDITIONAL_DEPEND_LIBS += libascot_main +ADDITIONAL_LIBS += -Wl,-rpath=$(ASCOT5_DIR) -L$(ASCOT5_DIR) -lascot_main +ADDITIONAL_INCLUDES += -I$(ASCOT5_DIR)/include +ASCOT5_OPT := NOGIT=true CC=h5cc MPI=0 FLAGS=-foffload=disable + +libascot_main: + $(MAKE) $(ASCOT5_OPT) -C $(ASCOT5_DIR) libascot_main diff --git a/src/problems/AscotProblem.C b/src/problems/AscotProblem.C index ed56c25..17894bf 100644 --- a/src/problems/AscotProblem.C +++ b/src/problems/AscotProblem.C @@ -11,6 +11,11 @@ #include "AscotProblem.h" #include "AuxiliarySystem.h" #include +#include +namespace ascot5 +{ +#include "ascot5_main.h" +} using namespace H5; registerMooseObject("PhaethonApp", AscotProblem); @@ -38,6 +43,15 @@ AscotProblem::AscotProblem(const InputParameters & parameters) AscotProblem::~AscotProblem() {} +const std::unordered_map AscotProblem::hdf5_group_prefix = { + {"marker", "prt"}, {"options", "opt"}, {"results", "run"}}; + +const std::vector AscotProblem::endstate_fields_double = { + "mass", "rprt", "phiprt", "zprt", "vr", "vphi", "vz", "weight", "time"}; + +const std::vector AscotProblem::endstate_fields_int = { + "id", "charge", "anum", "znum", "endcond"}; + bool AscotProblem::converged() { @@ -47,8 +61,20 @@ AscotProblem::converged() void AscotProblem::externalSolve() { - // TODO call ASCOT5 - return; + // Compose the input arguments to ASCOT5 + int argc = 2; + size_t lastindex = _ascot5_file_name.find("."); + std::string ascot5_input = "--in=" + _ascot5_file_name.substr(0, lastindex); + const char * argv[2] = {"ascot5", ascot5_input.c_str()}; + try + { + ascot5::ascot5_main(argc, (char **)argv); + } + catch (const std::exception & e) + { + std::cerr << e.what() << '\n'; + throw MooseException(e.what()); + } } void @@ -73,6 +99,32 @@ AscotProblem::syncSolutions(Direction direction) "elemental and order 0 (i.e. CONSTANT)."); } + // Send input for current time step to ASCOT5 + if (direction == Direction::TO_EXTERNAL_APP) + { + // Open ASCOT5 file and relevant groups for writing + H5File ascot5_file(_ascot5_file_name, H5F_ACC_RDWR); + Group ascot5_options = getAscotH5Group(ascot5_file, "options"); + + // Catch any exceptions related to writing to HDF5 file + try + { + // Write the end time condition to the options group + DataSet endcond_max_simtime = ascot5_options.openDataSet("ENDCOND_MAX_SIMTIME"); + double_t data[1] = {time() + dt()}; + endcond_max_simtime.write(data, PredType::NATIVE_DOUBLE); + // Copy the endstate to the marker group + if (_t_step > 1) + { + copyEndstate2MarkerGroup(ascot5_file); + } + } + catch (DataSetIException error) + { + error.printErrorStack(); + } + } + // Get solution from ASCOT5 run if (direction == Direction::FROM_EXTERNAL_APP) { @@ -80,6 +132,10 @@ AscotProblem::syncSolutions(Direction direction) H5File ascot5_file(_ascot5_file_name, H5F_ACC_RDONLY); Group ascot5_active_endstate = getActiveEndstate(ascot5_file); + // Read relevant endstate variables for restarting ASCOT5 + endstate_data_double = getAscotH5EndstateDouble(ascot5_active_endstate); + endstate_data_int = getAscotH5EndstateInt(ascot5_active_endstate); + // Get particle information std::vector walltile = getWallTileHits(ascot5_active_endstate); std::vector energies = getParticleEnergies(ascot5_active_endstate); @@ -99,10 +155,10 @@ AscotProblem::syncSolutions(Direction direction) { dof_i = el->dof_number(sync_to_var.sys().number(), sync_to_var.number(), 0); // TODO make this heading coloured - _console << "Heat flux mapping from ASCOT5 HDF5" << std::endl; - _console << "==================================" << std::endl; - _console << "el_dof: " << dof_i << ", el_id: " << el->id() - << ", flux: " << heat_fluxes[el->id()] << std::endl; + //_console << "Heat flux mapping from ASCOT5 HDF5" << std::endl; + //_console << "==================================" << std::endl; + //_console << "el_dof: " << dof_i << ", el_id: " << el->id() + // << ", flux: " << heat_fluxes[el->id()] << std::endl; sync_to_var.sys().solution().set(dof_i, heat_fluxes[el->id()]); } @@ -114,23 +170,34 @@ AscotProblem::syncSolutions(Direction direction) Group AscotProblem::getActiveEndstate(const H5File & hdf5_file) { - // Open the results group - Group results_group = hdf5_file.openGroup("results"); + return getAscotH5Group(hdf5_file, "results"); +} + +Group +AscotProblem::getAscotH5Group(const H5File & hdf5_file, const std::string & group_name) +{ + // Open the top-level group + Group top_group = hdf5_file.openGroup(group_name); // Check if the attribute 'active' is present - if (results_group.attrExists("active")) + if (top_group.attrExists("active")) { // Open the attribute - H5::Attribute results_active_attr = results_group.openAttribute("active"); + H5::Attribute active_attr = top_group.openAttribute("active"); // Get its string type - StrType stype = results_active_attr.getStrType(); + StrType stype = active_attr.getStrType(); // Read the active run number into a string buffer - std::string active_result_num; - results_active_attr.read(stype, active_result_num); - // Open the active run group - std::string endstate_name = "run_" + active_result_num + "/endstate"; - Group endstate_group = results_group.openGroup(endstate_name); - return endstate_group; + std::string active_num; + active_attr.read(stype, active_num); + // Get the name for the group + std::string subgroup_name = AscotProblem::hdf5_group_prefix.at(group_name) + "_" + active_num; + if (group_name == "results") + { + subgroup_name.append("/endstate"); + } + // Open the group + Group active_group = top_group.openGroup(subgroup_name); + return active_group; } else { @@ -138,46 +205,72 @@ AscotProblem::getActiveEndstate(const H5File & hdf5_file) } } -std::vector -AscotProblem::getWallTileHits(Group & endstate_group) +template +std::vector +AscotProblem::getAscotH5DataField(H5::Group & endstate_group, const std::string & field_name) { - // Open the walltile dataset - DataSet walltile_dataset = endstate_group.openDataSet("walltile"); - // Get the walltile dataset's data space - DataSpace walltile_dataspace = walltile_dataset.getSpace(); - // check we only have 1 dim - if (walltile_dataspace.getSimpleExtentNdims() == 1) + + // Open the datasets to check the number of ions/markers + DataSet dataset = endstate_group.openDataSet(field_name); + DataSpace dataspace = dataset.getSpace(); + // Check we only have 1 dim + if (dataspace.getSimpleExtentNdims() == 1) { - hssize_t n_markers = walltile_dataspace.getSimpleExtentNpoints(); - std::vector walltile(n_markers); - walltile_dataset.read(walltile.data(), PredType::NATIVE_INT64); - return walltile; + const hsize_t n_markers = dataspace.getSimpleExtentNpoints(); + std::vector marker_data(n_markers); + // Map the C++ type to what is expected by HDF5 routines + if (typeid(T) == typeid(double_t)) + { + dataset.read(marker_data.data(), PredType::NATIVE_DOUBLE); + } + else if (typeid(T) == typeid(int64_t)) + { + dataset.read(marker_data.data(), PredType::NATIVE_INT64); + } + else + { + throw MooseException("Unrecognised data type requested from HDF5 file"); + } + return marker_data; } else { - throw MooseException("ASCOT5 HDF5 File walltile dataset of incorrect dim."); + throw MooseException("ASCOT5 HDF5 File weight dataset is of incorrect dim."); } } -std::vector -AscotProblem::getMarkerWeights(Group & endstate_group) +std::unordered_map> +AscotProblem::getAscotH5EndstateDouble(H5::Group & endstate_group) { - - // Open the datasets to check the number of ions/markers - DataSet weight_dataset = endstate_group.openDataSet("weight"); - DataSpace weight_dataspace = weight_dataset.getSpace(); - // Check we only have 1 dim - if (weight_dataspace.getSimpleExtentNdims() == 1) + std::unordered_map> endstate_data; + for (auto && field : endstate_fields_double) { - const hsize_t n_markers = weight_dataspace.getSimpleExtentNpoints(); - std::vector marker_weights(n_markers); - weight_dataset.read(marker_weights.data(), PredType::NATIVE_DOUBLE); - return marker_weights; + endstate_data[field] = getAscotH5DataField(endstate_group, field); } - else + return endstate_data; +} + +std::unordered_map> +AscotProblem::getAscotH5EndstateInt(H5::Group & endstate_group) +{ + std::unordered_map> endstate_data; + for (auto && field : endstate_fields_int) { - throw MooseException("ASCOT5 HDF5 File weight dataset is of incorrect dim."); + endstate_data[field] = getAscotH5DataField(endstate_group, field); } + return endstate_data; +} + +std::vector +AscotProblem::getWallTileHits(Group & endstate_group) +{ + return getAscotH5DataField(endstate_group, "walltile"); +} + +std::vector +AscotProblem::getMarkerWeights(Group & endstate_group) +{ + return getAscotH5DataField(endstate_group, "weight"); } std::vector @@ -259,4 +352,99 @@ AscotProblem::calculateHeatFluxes(std::vector walltile, } return heat_fluxes; +} + +void +AscotProblem::copyEndstate2MarkerGroup(const H5File & hdf5_file) +{ + // create a new marker group for the next time step + std::string step_num = std::to_string(_t_step); + if (step_num.length() < 10) + step_num.insert(step_num.front() == '-' ? 1 : 0, 10 - step_num.length(), '0'); + Group new_marker = hdf5_file.createGroup("marker/prt_" + step_num); + // adjust the 'active' attribute on the top level marker group + Group marker = hdf5_file.openGroup("marker"); + H5::Attribute active = marker.openAttribute("active"); + StrType stype = active.getStrType(); + active.write(stype, step_num); + // get the number of markers still active + std::vector valid_indices; + // TODO this could undoubtedly be optimised. Performance will be quite poor if + // endcond vector is large. + for (size_t i = 0; i != endstate_data_int.at("endcond").size(); i++) + { + // An endcondition of 1 indicates the marker reached the end of the + // simulation time. All other endconditions indicate that the marker has + // terminated and should no longer be simulated. + if (endstate_data_int.at("endcond")[i] == 1) + { + valid_indices.push_back(i); + } + } + std::vector nmarkers = {(int64_t)valid_indices.size()}; + // write the number of markers to the new group + const int64_t rank = 2; + hsize_t dims[rank] = {1, 1}; + DataSpace data_space(rank, dims); + createAndWriteDataset(nmarkers, "n", data_space, new_marker); + // set the DataSpace for all other arrays based on the number of markers + dims[0] = (hsize_t)nmarkers[0]; + data_space = DataSpace(rank, dims); + // Write double data + for (auto && field : endstate_fields_double) + { + std::vector data; + // filter the data + for (auto && j : valid_indices) + { + data.push_back(endstate_data_double.at(field)[j]); + } + createAndWriteDataset(data, field, data_space, new_marker); + } + // Write integer data + for (auto && field : endstate_fields_int) + { + std::vector data; + if (field == "endcond") + { + continue; + } + // filter the data + for (auto && j : valid_indices) + { + data.push_back(endstate_data_int.at(field)[j]); + } + createAndWriteDataset(data, field, data_space, new_marker); + } +} + +template +void +AscotProblem::createAndWriteDataset(const std::vector & data, + const std::string & name, + const DataSpace & data_space, + const Group & group) +{ + const PredType * type = nullptr; + if (typeid(T) == typeid(double_t)) + { + type = &PredType::NATIVE_DOUBLE; + } + else if (typeid(T) == typeid(int64_t)) + { + type = &PredType::NATIVE_INT64; + } + else + { + throw MooseException("Unrecognised data type requested from HDF5 file"); + } + // remove the 'prt' substring from some of the field names + std::string name_local(name); + size_t start = name_local.find("prt"); + if (start != std::string::npos) + { + name_local.erase(start, 3); + } + DataSet dataset = group.createDataSet(name_local, *type, data_space); + dataset.write(data.data(), *type); } \ No newline at end of file diff --git a/supplementary/ascot5/create_simple_run_endstate2markers.py b/supplementary/ascot5/create_simple_run_endstate2markers.py new file mode 100644 index 0000000..3b78364 --- /dev/null +++ b/supplementary/ascot5/create_simple_run_endstate2markers.py @@ -0,0 +1,177 @@ +#!/usr/bin/env python +# coding: utf-8 + +import shutil +import sys +import subprocess +import numpy as np +import h5py +import scipy.constants as constants +import a5py.ascot5io.ascot5 as ascot5 +import a5py.ascot5io.mrk_prt as mrk_prt +import a5py.ascot5io.mrk_gc as mrk_gc +import a5py.ascot5io.mrk_fl as mrk_fl + + +def main(base_file='simple_run.h5', h5file='simple_run_endstate2markers.h5'): + # Copy the base HDF5 file + shutil.copy(base_file, h5file) + + # Copy the endstate to markers group + # We only want the markers that have reached the end of the valid + # simulation time, which corresponds to endcond=1. All other end + # conditions correspond to particles that should no longer be simulated. + # You can find the definition of the endconditions in the C source: + # `ascot5/endcond.h` + new_marker = state2markers(fn=h5file, markertype='fo', state='endstate', + endcond=1) + + # Trim down h5file so that it takes less space, and copy the group created + # above into the existing marker group so that we can use `h5diff` for + # tests + with h5py.File(h5file, mode='r+') as file: + del file['results'] + marker_group = file['marker'] + active_marker = 'prt_' + marker_group.attrs['active'].decode('UTF-8') + for key in marker_group[new_marker].keys(): + del marker_group[active_marker][key] + marker_group[active_marker][key] = marker_group[new_marker][key] + + # Now repack it so that it actually takes less space + tempfile = 'temp' + subprocess.call(args=['h5repack', h5file, tempfile]) + shutil.move(tempfile, h5file) + + +# Redefining this from `a5py/postprocessing/state2markers.py` because that has +# an error where fn is not used to open the HDF5 file. In the future, once this +# is fixed one should use that routine instead of this one. +def state2markers(fn, markertype, state, endcond, ids=np.array([0]), + idx=np.array([0])): + """ + Convert ASCOT5 state to markers for rerun. + + The new markers are written in the same HDF5 file as from + which the state is read so make a copy first! + + Parameters + ---------- + + h5fn : str + Full path to HDF5 file. + + markertype : str + Type of markers to be generated: + - 'fo' Particles + - 'gc' Guiding centers + - 'ml' Magnetic field lines + + state : str + State from where particles are picked + + endcond : int + Initializes new markers from the old markers that have + this endstate. + + ids : str, optional + Array of marker ids to be rerun. Overrides endcond. + + idx : str, optional + Array of marker indexes to be rerun. Overrides ids. + + Notes + ----- + + If both "endcond" and "ids" are given, then the latter overrides former. + """ + + AMU2KG = 1.66053904e-27 + J2EV = 1.0/constants.elementary_charge + + # Read endstate and find indexes of valid markers + if state == "endstate": + a5 = ascot5.Ascot(fn).active.endstate.read() + elif state == "inistate": + a5 = ascot5.Ascot(fn).active.inistate.read() + else: + raise ValueError('Unknown state type.') + + if (idx == 0).all() and (ids == 0).all(): + idx = a5["endcond"] == endcond + elif (idx == 0).all(): + print("TODO Not implemted") + + N = np.sum(idx) + if(N == 0): + print("Error: No valid markers.") + return + + # Convert endstate to... + + # ..particles + if markertype == 'fo': + ids = a5["id"][idx] + mass = a5["mass"][idx] + charge = a5["charge"][idx] + R = a5["rprt"][idx] + phi = a5["phiprt"][idx] + z = a5["zprt"][idx] + vR = a5["vr"][idx] + vphi = a5["vphi"][idx] + vz = a5["vz"][idx] + anum = a5["anum"][idx] + znum = a5["znum"][idx] + weight = a5["weight"][idx] + time = a5["time"][idx] + return mrk_prt.write_hdf5(fn, N, ids, mass, charge, + R, phi, z, vR, vphi, vz, + anum, znum, weight, time) + + # ..guiding centers + if markertype == 'gc': + ids = a5["id"][idx] + mass = a5["mass"][idx] + charge = a5["charge"][idx] + R = a5["r"][idx] + phi = a5["phi"][idx] + z = a5["z"][idx] + mu = a5["mu"][idx] + vpar = a5["vpar"][idx] + theta = a5["theta"][idx] + anum = a5["anum"][idx] + znum = a5["znum"][idx] + weight = a5["weight"][idx] + time = a5["time"][idx] + B = np.sqrt( np.power(a5["br"][idx],2) + + np.power(a5["bphi"][idx],2) + + np.power(a5["bz"][idx],2) ) + + energy = mu * B + (0.5 * mass * vpar * vpar) * (AMU2KG * J2EV) + v = np.sqrt( 2 * ( energy / J2EV ) / (mass * AMU2KG) ) + pitch = vpar / v + return mrk_gc.write_hdf5(fn, N, ids, mass, charge, + R, phi, z, energy, pitch, theta, + anum, znum, weight, time) + + # ..magnetic field lines + if markertype == 'ml': + ids = a5["id"][idx] + R = a5["r"][idx] + phi = a5["phi"][idx] + z = a5["z"][idx] + weight = a5["weight"][idx] + time = a5["time"][idx] + vpar = a5["vpar"][idx] + v = np.sqrt( np.power(a5["vr"][idx],2) + + np.power(a5["vphi"][idx],2) + + np.power(a5["vz"][idx],2) ) + pitch = vpar / v + return mrk_fl.write_hdf5(fn, N, ids, R, phi, z, pitch, + weight, time) + + +if __name__ == '__main__': + if len(sys.argv[1:]) == 0: + main() + else: + main(sys.argv[1:]) diff --git a/supplementary/ascot5/extract_simple_run_quick_endstate.py b/supplementary/ascot5/extract_simple_run_quick_endstate.py new file mode 100644 index 0000000..6dd0700 --- /dev/null +++ b/supplementary/ascot5/extract_simple_run_quick_endstate.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# coding: utf-8 + +import a5py.ascot5io.ascot5 as ascot5 +import sys + + +def main(h5file='simple_run.h5'): + # Get the endstate results from the HDF5 file + hdf5 = ascot5.Ascot(h5file) + endstate = hdf5.active.endstate + + # Double/floating-point data for endstate + fp_data = ('mass', 'rprt', 'phiprt', 'zprt', 'vr', 'vphi', 'vz', 'weight', + 'time') + + # Integer data for endstate + integer_data = ('id', 'charge', 'anum', 'znum', 'endcond') + + basename = h5file.split('.')[0] + # Write the fp data to file as a C++ unordered map + with open(basename + '_endstate_fp.txt', 'w') as fp_file: + for field in fp_data: + data_string = ', '.join([f'{x:.18f}' for x in + endstate.get(field, SI=False)]) + dataline = f'{{"{field}", {{{data_string}}}}},\n' + fp_file.write(dataline) + + # Write the fp data to file as a C++ unordered map + with open(basename + '_endstate_int.txt', 'w') as int_file: + for field in integer_data: + endstate_data = endstate.get(field, SI=False) + # for some reason, endcond is bit shifted by 2 leftwards in the + # python reading routines ¯\_(ツ)_/¯ + if field == 'endcond': + endstate_data = endstate_data >> 2 + data_string = ', '.join([f'{int(x)}' for x in endstate_data]) + dataline = f'{{"{field}", {{{data_string}}}}},\n' + int_file.write(dataline) + + +if __name__ == '__main__': + main(sys.argv[1]) diff --git a/supplementary/ascot5/extract_simple_run_quick_results.py b/supplementary/ascot5/extract_simple_run_quick_results.py new file mode 100644 index 0000000..91a4dc9 --- /dev/null +++ b/supplementary/ascot5/extract_simple_run_quick_results.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# coding: utf-8 + +import a5py.ascot5io.ascot5 as ascot5 +import numpy as np + +# Get the endstate results from the HDF5 file +hdf5 = ascot5.Ascot('simple_run_quick.h5') +endstate = hdf5.active.endstate + +# Save a variety of the arrays to csv files for validating unit test runs +np.savetxt('weight_quick.csv', endstate.get('weight'), newline=', ') +np.savetxt('walltile_quick.csv', endstate.get('walltile'), newline=', ', fmt='%1d') +for vel in ('vr', 'vphi', 'vz'): + np.savetxt(vel + '_quick.csv', endstate.get(vel), newline=', ') diff --git a/supplementary/ascot5/generate_test_data.sh b/supplementary/ascot5/generate_test_data.sh index 2342eed..7da7057 100755 --- a/supplementary/ascot5/generate_test_data.sh +++ b/supplementary/ascot5/generate_test_data.sh @@ -1,20 +1,38 @@ #!/bin/bash # coding: utf-8 -# Generate test data from ASCOT5 'simplerun' - -python ../../ascot5-python/a5py/a5py/preprocessing/simpleruns.py -mv helloworld.h5 simple_run.h5 - -# Run ascot5 on input data - -ascot5_main --in simple_run - -# Generate dummy mesh for use in MOOSE app - -./a5wall_convert.py simple_run.h5 - -# Create other unit test data - -python calculate_simple_run_particle_energies.py -python calculate_simple_run_heat_fluxes.py +# Generate test data from ASCOT5 'simplerun' and a quick version + +OPTION=$1 +export OMP_NUM_THREADS=1 + +case $OPTION in + + simplerun) + # Generate input file + python ../../ascot5-python/a5py/a5py/preprocessing/simpleruns.py + mv helloworld.h5 simple_run.h5 + # Run ascot5 on input data + ascot5_main --in simple_run + # Generate dummy mesh for use in MOOSE app + ./a5wall_convert.py simple_run.h5 + # Create other unit test data + python calculate_simple_run_particle_energies.py + python calculate_simple_run_heat_fluxes.py + python extract_simple_run_quick_endstate.py simple_run.h5 + python create_simple_run_endstate2markers.py + ;; + + simplerun_quick) + # Generate input file + python simple_run_quick.py + cp simple_run_quick.h5 simple_run_quick_input.h5 + # Run ascot5 on input data + ascot5_main --in simple_run_quick + # Create other unit test data + python extract_simple_run_quick_results.py + python extract_simple_run_quick_endstate.py simple_run_quick.h5 + # Tidy up + rm simple_run_quick.h5 + ;; +esac diff --git a/supplementary/ascot5/simple_run_endstate2markers.h5 b/supplementary/ascot5/simple_run_endstate2markers.h5 new file mode 100644 index 0000000..da448e7 --- /dev/null +++ b/supplementary/ascot5/simple_run_endstate2markers.h5 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7a4c58f0aaeff1a708fc4178f689a138557a64b94a49035ab36e399e7d240ff1 +size 91472 diff --git a/supplementary/ascot5/simple_run_endstate_fp.txt b/supplementary/ascot5/simple_run_endstate_fp.txt new file mode 100644 index 0000000..c16bdbd --- /dev/null +++ b/supplementary/ascot5/simple_run_endstate_fp.txt @@ -0,0 +1,9 @@ +{"mass", {4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000, 4.000000000000000000}}, +{"rprt", {8.185539710180593787, 8.027547547627923663, 4.061436867642658655, 5.192215405400155248, 3.904017366218724749, 5.131987134704800724, 3.905211552599474167, 8.022966804587747802, 7.989025907782687064, 8.067661674712542919, 7.989017555674028159, 8.163763846649835898, 8.053388484013792592, 3.972438018949568939, 8.060176843756668319, 8.047306855636856326, 5.353427175619172473, 7.505722511743087466, 8.154674440914879696, 5.182956311255655812, 5.264164613378509827, 5.258875150475630811, 5.029703321332402055, 8.023696565068233255, 8.120829580546139681, 5.197382732607924716, 8.074172762536143466, 4.004104262546157145, 7.601490506506466183, 7.989306711361350288, 3.935524428865546653, 3.940058952513056045, 6.710905805906112853, 5.334547033429604568, 5.261253175845084229, 5.106647664530219011, 7.565692449566814304, 8.005952285914643696, 5.246983692054847381, 3.932388636317786457, 8.019226988795105981, 5.286132260338373356, 3.900562295232468557, 8.173904499993517092, 8.073754106472140535, 3.957498841100007159, 7.989158409341824196, 5.488012096468718681, 8.034326044774177333, 5.305781460348946155, 3.917547322159044665, 3.950773166367754996, 7.191122075538321390, 4.040710832126302776, 3.905959907354045857, 5.506308319742251101, 8.177595480144949747, 5.160531827826321027, 3.967006515577389258, 8.046888045958322522, 8.092792574604501965, 8.056627575169750699, 3.918706155675216962, 3.890652949193889043, 8.040355005993305326, 5.212986119624602566, 5.304912682399053558, 8.151371178792313543, 3.900142659604967310, 7.266767493692347202, 8.031180160402460189, 6.123210100056502014, 5.343920250343220602, 7.990731320691858208, 7.998357172070275745, 8.035730707889692681, 5.192769241859356733, 8.079000955392070082, 5.683780823329850129, 8.037537682727865729, 3.948128516341344429, 7.993350785326345687, 5.512500215463330910, 8.115388089819470352, 3.923643249538976807, 3.963201763089872376, 8.047450268855191879, 3.907778315464214725, 3.905251122925538443, 8.159726975518630354, 3.933871221108394156, 8.059242218644778077, 3.927408896562187390, 8.058955562387914995, 3.932511493057204266, 3.944461020902781279, 5.488842011056836334, 3.907326735944709029, 6.713925771814742482, 5.279192681953250421}}, +{"phiprt", {-329.451781184425101401, -372.740207308653737073, 34.580028519185361802, 144.456745336433215243, 56.784741362045949131, 269.874356923728498714, -123.694287964736432173, -337.090892504960322640, 835938.064900690806098282, -118.054094537261519804, 954882.085362685378640890, -294.429336276642118264, -226.753286680655577356, -79.163156215457306075, -226.728438665004318864, -227.177450275538916458, 306.379055519760811421, 696.857863525287370976, -294.813391035480492519, 234.412669871222902884, 115.791840114810824502, 330.537503089998324413, 1309380.203243896365165710, -156.730556027969043953, -259.785030275666144917, 144.590457722936264418, -153.951791707004417731, 112.725041970644355160, 444.525623771235018467, 1275786.414380696369335055, 406.964178575549908601, 513.774764354422700308, 343.464825119805936993, 428.968328881162221933, 85.931946628505272656, 281.905702407320802649, 611.689148729771204671, -158.681206727199196393, 176.359813092331222606, 133.322767622916103392, -265.448413377381086775, 197.974370590470726938, -18.410962600389751742, -77.954988284294103096, -9.807954137147579132, 223.770088372085155015, 764621.911085142754018307, 11.320198005957756493, -263.932269913321476906, 109.478634122803015316, 23.257667152178562731, 224.927874747057330751, 428.598677798728829202, 69.053953085929293820, 338.936089437190446461, 336.182464508737382403, 180210.324989393673604354, 197.023581327849029776, 64.424409306926577301, 803.252053594148492266, 549.098408523338207488, -298.880013113088750742, 552.486659879230501247, 159.713114882956205065, -47.527459704713407973, 204.488423967569929118, 114.605372929277635308, -294.730274676957151314, 161.419093273906810282, 703.086084272373227577, -12.280644010349480055, 1236042.125488302670419216, -1086806.310115632833912969, -233.745065408407981522, 1118792.715752209071069956, -84.086755365606535406, 179.821259355931488244, 637262.530054847244173288, 413.334999071051811370, 624.163924949555394051, -9.431122974612975440, -124.828174520767234412, 58.873688926343184846, -152.243645857224578322, 299.717126494320268648, 548.256093070823681046, 516192.851426972541958094, 446.512753016746160029, 519.111601194645686519, -114.530008951256974115, 442.444464575360314029, -82.536332106558845112, 96.769135967542922572, 658.463414718882404486, 47.302674456462632691, 297.653278376074354128, 256.173376418134239429, 554.700921595340901149, 345.082057142904716329, 102.963666858057749209}}, +{"zprt", {0.975299327779328928, 0.960014873007974390, 0.014683321650052705, 0.001711608422618379, 0.287720100631914388, 0.001539020417658187, 0.886894625891117561, 1.211229470242312312, 0.010969118946132981, 0.827566127290806142, 0.004673722017880761, 0.615985869834606570, -0.149561088511479617, 1.314372149334158690, 0.324609223799033120, 0.407275707873850590, 0.001786336012106617, -0.818753642852698582, 0.881309873886099382, 0.001850820270739978, 0.000718079692843701, 0.000706841565074311, -1.049941116953318154, 0.510716250610728451, 0.359880535049948991, 0.001136243246866726, 0.620516907165503007, 0.054228137607195984, -0.663848500876909053, -0.063708772075981954, -1.115865842350000969, -0.637887867184333435, -1.350478833982030835, -0.780377310840922656, 0.001607125222500900, 0.001657584235767412, -0.727472429428213774, 0.719695367983763989, 0.001196840162502765, 0.993310264178008606, 0.657810055709907915, -0.699769023140883739, 1.165078582827886233, 0.881490766368632883, 0.281062685564863912, 0.076616977290344682, -0.045064063402766467, 0.001442855973291163, 0.776205207639695582, 0.001270718854945505, 1.194494249294180133, -0.078141239446340313, -1.133693252497454784, 0.017243819554009193, -0.864822631754817217, 0.001539672475979089, 0.580676644317092649, 0.000070496280562394, 1.210886258772397195, -0.315003631408671603, -0.037005161212667004, 0.147970750535579509, -0.739138738767259329, 0.057142254918028372, 0.787961008200881552, 0.000985003130513676, 0.001866788995591823, 0.675736371374723754, -0.800068875873258478, -1.074679287046443221, 0.316762195731797036, 1.537910549558935580, -1.057412044248941863, 0.657373619283165733, 0.180843997318612809, -0.080457411557162267, 0.001662287031277603, -0.085865417429419832, -1.146274374625525061, 0.103716673395784845, 1.029721714753642159, 0.189641989801194316, 0.001818904581329112, 0.968427357971188396, -1.163796560291074256, -1.068853755555138063, -0.003177323134794201, -0.875408457200515300, -0.627623095453660351, 0.475451693985760593, -1.142433660474765356, 0.517855250109586329, 1.266709889968644864, -0.428250174462763089, 0.001058759359158317, -1.144265927345455180, 0.001149728557644690, -0.982667906975634886, -1.350163401804976626, 0.001821616950066440}}, +{"vr", {6726950.876166521571576595, 6245914.225225844420492649, -7035044.454640137962996960, 11032318.190904302522540092, 4023164.604898532386869192, 9625418.538657888770103455, 3836299.733669225126504898, 9649721.835221888497471809, -117440.877923620515502989, 7662949.996123213320970535, 510023.029020441230386496, 9877025.584487810730934143, 3279030.841255275532603264, 2492944.355537967290729284, 7244569.659570151939988136, 6777551.309738075360655785, 11848700.584055539220571518, -3647450.732717351987957954, 9717580.496944313868880272, 11869366.696552272886037827, 4525829.318946493789553642, 4751484.603072462603449821, 427887.709753627888858318, 4854287.410819835960865021, 6376184.441882430575788021, 7426338.944255332462489605, 9389601.121968118473887444, -9052603.967206429690122604, -2153026.903225770220160484, 123125.493903175694867969, 6734880.326913392171263695, 4363917.214193511754274368, -8908023.873535908758640289, -6183534.152212052606046200, 10341159.450700430199503899, 10330864.488689539954066277, -3947251.106124070938676596, 3919075.036951433867216110, 7624803.073282956145703793, 9738094.757367633283138275, 3934529.194068036973476410, -2701424.963987945578992367, 3989482.740146532654762268, 9682229.556740837171673775, 318745.004492134088650346, -6308638.565211365930736065, 231500.221878469455987215, 9699988.006544148549437523, 5982925.577521393075585365, 8208044.843904850073158741, 3794407.239994526375085115, 3388508.571512086316943169, -5386618.292474089190363884, 4879194.910046128556132317, 941710.688788758590817451, 10402661.532238677144050598, 6102347.302598842419683933, 292790.045834385324269533, 912647.538709406275302172, 6410018.823490441776812077, 7399395.509230405092239380, 7671474.743540313094854355, -1110365.324742922093719244, -11310274.933254022151231766, 6878740.382913371548056602, 6198507.230994142591953278, 12184282.318197194486856461, 3700309.568884396925568581, 3605329.432206659112125635, -6634756.507224347442388535, 8921413.998517626896500587, -1035343.320392728084698319, -301668.376659147557802498, 6005873.413850078359246254, 706938.508223629905842245, 2995505.572570440825074911, 10726828.883183585479855537, 1628260.567791967652738094, -6197175.445988361723721027, 6867758.021055217832326889, 6385076.745810758322477341, 2477796.010814280249178410, 12401131.847398912534117699, 10305110.199006319046020508, -193790.713482855819165707, 5318593.340561756864190102, 1900662.083015298703685403, 3970067.761343114543706179, 710831.293527439003810287, 5459308.728863675147294998, 3533076.773661450482904911, 7984007.238862473517656326, 7096780.893044016323983669, 414554.306808479130268097, 4847071.399671746417880058, 2155932.469230305403470993, 7695827.400337519124150276, 688048.184865279938094318, -9600127.251460582017898560, 11810527.478189386427402496}}, +{"vphi", {-9727805.122332844883203506, -10468733.773152057081460953, 10404306.301869988441467285, -5926062.952644253149628639, -2375554.258702238090336323, 8150024.086000205017626286, -6163131.070164355449378490, -8319592.725379040464758873, 1971079.036326905712485313, -10434074.332666108384728432, 2938616.924883494619280100, -8397487.208542581647634506, -12564292.388034068048000336, -2854470.809889525175094604, -9081752.581790247932076454, -10575164.268553324043750763, -3923297.905163770075887442, 12266273.167272653430700302, -8393471.450353443622589111, -3736690.291706236079335213, 12083222.285028269514441490, -11999014.937878312543034554, 620290.800213903654366732, -11772490.128618435934185982, -11218992.792913123965263367, -10403646.438532065600156784, -8886708.909724345430731773, -9136212.193168058991432190, 12430935.602968757972121239, 3010713.134868826717138290, 9797834.744836065918207169, 3669248.274904221761971712, 9396142.793245000764727592, 4933714.346292823553085327, 7160738.588408041745424271, 7129580.174802044406533241, 11876531.938774337992072105, -11955728.395857155323028564, 10231399.515634408220648766, -8143815.649165145121514797, -12374307.050780946388840675, 10011575.585305389016866684, -3191519.392342586535960436, -8587314.351546201854944229, -9968717.536790747195482254, -11249798.573581391945481300, 1498064.514892244478687644, 8132190.551775041036307812, -9884532.111982638016343117, 9732292.103941414505243301, -2162642.094526012893766165, 11467891.224293306469917297, 11694805.875752005726099014, -6024390.171409367583692074, 12750089.393952406942844391, 7130889.125164113007485867, -6996277.075932976789772511, 12978504.444441692903637886, -8927205.197743533179163933, 11167669.646036561578512192, 9966142.638722630217671394, -10267891.134640054777264595, 4170779.545815343502908945, 2081837.361486763460561633, -10923094.872835671529173851, 11235835.066798986867070198, 2480089.413608309347182512, -12059565.062397537752985954, 11665386.568701328709721565, 10190334.699592692777514458, -8495765.785230081528425217, 644583.826549300341866910, 61324.664411703575751744, -11399815.549109525978565216, -1426467.142854757606983185, -12383740.179632443934679031, -6514066.662548831664025784, -2419113.410070822108536959, 10344136.988583220168948174, 7878540.620379981584846973, -4262118.109313962049782276, -11237933.683516725897789001, -1236369.422709343954920769, -7882964.073981502093374729, 12724683.238925702869892120, 6004473.061498328112065792, -2987365.589625715278089046, 10457287.581271832808852196, 4030636.642281397711485624, -11419837.352874293923377991, 12148464.896494254469871521, -9664511.203469706699252129, -2534034.511871613562107086, 11776225.529838073998689651, 11856236.854577589780092239, 8027130.230189319700002670, 10199686.608938150107860565, 4850231.620479302480816841, 8707938.420967577025294304, 3973273.007143257651478052}}, +{"vz", {5355264.460228838957846165, 4450699.238567685708403587, -3287384.815607718657702208, 3423226.486529649235308170, 12112771.258206935599446297, 3078006.088894226588308811, 10763222.509696174412965775, 2491440.642908376175910234, 3257106.765120402444154024, 903379.470138734439387918, 2764633.044104462489485741, -573800.107975804014131427, -95779.945571406584349461, 12417147.976225703954696655, 5774328.596462568268179893, 3303120.011866965796798468, 3572556.343925199471414089, -2156417.154293753672391176, -1918047.215999919455498457, 3701670.765236451756209135, 1436131.001757658785209060, 1413759.027794740162789822, -202289.632913792971521616, 2507445.337323077954351902, 1419582.963990278774872422, 2272434.792241929098963737, 1138574.216854310827329755, -1768707.777476805495098233, -3057865.352432534098625183, 2172571.363869205582886934, 5214610.275260088033974171, 11663669.348565435037016869, -894601.043737424653954804, 10282676.012577468529343605, 3214322.967402660287916660, 3315174.312848625704646111, -3453920.877362706232815981, 3185116.076121560297906399, 2393578.661439311224967241, 2719580.150822759140282869, -9225.517233743403266999, 7814126.005254469811916351, 11935098.259427366778254509, 1013418.736906326841562986, 8320834.175289545208215714, -1480354.867980694165453315, 1968308.121191160054877400, 2885734.597578225657343864, 5910129.202631282620131969, 2541388.359954296145588160, 12225947.484588345512747765, 5055078.590521623380482197, -1655692.452139262808486819, 10413861.873492814600467682, 2257596.166862438898533583, 3079364.989123668521642685, 3159247.061662542633712292, 141003.129904717236058787, 9381919.891752747818827629, 1620960.207609127741307020, 3791923.998090940061956644, 2037788.243117127567529678, 12244183.347764384001493454, -6024281.962383901700377464, 1336675.656630586599931121, 1970116.704290696652606130, 3733565.491071761585772038, -3058286.940074034966528416, 4412334.406618952751159668, -4527823.184637383557856083, 4067592.481335339136421680, -190809.477198530628811568, 41429.649591782195784617, 1623308.362481739837676287, 1009907.841562960646115243, -2460064.337428821716457605, 3324473.577664065640419722, 1426321.437892681686207652, 4798011.768490541726350784, 7696021.956044267863035202, 10469645.801085064187645912, 6016862.966363416053354740, 3637529.108320854604244232, 84504.332036333536962047, 2567726.748737524729222059, 10208193.138813024386763573, 1880665.773785111261531711, 6590298.736834933981299400, 12320593.579770898446440697, 2878404.625254092738032341, -2912131.212336590047925711, 3381122.847369084600359201, 10571788.357539935037493706, 5441963.303133215755224228, 2117518.718316648621112108, 9973237.913712253794074059, 2299351.938423836138099432, 12022902.392972188070416451, -641827.854945812141522765, 3643434.039527322631329298}}, +{"weight", {1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000, 1.000000000000000000}}, +{"time", {0.000009856000000000, 0.000004418000000000, 0.000000025000000000, 0.000000001000000000, 0.000000746000000000, 0.000000001000000000, 0.000001330000000000, 0.000010040000000000, 0.016698172996393850, 0.000003897000000000, 0.015862671996833621, 0.000006496999999999, 0.000003240000000000, 0.000005926999999999, 0.000008253999999999, 0.000004153000000000, 0.000000001000000000, 0.000003208000000000, 0.000005757000000000, 0.000000001000000000, 0.000000001000000000, 0.000000001000000000, 0.027000000990971423, 0.000003361000000000, 0.000003742000000000, 0.000000001000000000, 0.000005442000000000, 0.000000009000000000, 0.000003256000000000, 0.019071376995144700, 0.000001617000000000, 0.000006370999999999, 0.000004497000000000, 0.000004504000000000, 0.000000001000000000, 0.000000001000000000, 0.000003566000000000, 0.000003315000000000, 0.000000001000000000, 0.000001255000000000, 0.000002970000000000, 0.000001048000000000, 0.000003594000000000, 0.000007491999999999, 0.000007455999999999, 0.000000041000000000, 0.022603092993285761, 0.000000001000000000, 0.000005446000000000, 0.000000001000000000, 0.000008863999999999, 0.000000097000000000, 0.000003189000000000, 0.000000003000000000, 0.000000909000000000, 0.000000001000000000, 0.004444871999922495, 0.000000001000000000, 0.000001390000000000, 0.000004194000000000, 0.000005198000000000, 0.000004399000000000, 0.000007944999999999, 0.000000009000000000, 0.000003620000000000, 0.000000001000000000, 0.000000001000000000, 0.000003082000000000, 0.000000926000000000, 0.000004827000000000, 0.000009466000000000, 0.027000000990971423, 0.026901979991023017, 0.000003342000000000, 0.025333068991848822, 0.000003099000000000, 0.000000001000000000, 0.018887883995241283, 0.000001837000000000, 0.000008228999999999, 0.000002189000000000, 0.000004069000000000, 0.000000001000000000, 0.000013314000000002, 0.000001297000000000, 0.000003438000000000, 0.016638606996425203, 0.000001177000000000, 0.000004796000000000, 0.000003883000000000, 0.000001245000000000, 0.000004989000000000, 0.000006636999999999, 0.000003519000000000, 0.000000001000000000, 0.000002415000000000, 0.000000001000000000, 0.000009117000000000, 0.000006256999999999, 0.000000001000000000}}, diff --git a/supplementary/ascot5/simple_run_endstate_int.txt b/supplementary/ascot5/simple_run_endstate_int.txt new file mode 100644 index 0000000..1581f76 --- /dev/null +++ b/supplementary/ascot5/simple_run_endstate_int.txt @@ -0,0 +1,5 @@ +{"id", {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100}}, +{"charge", {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}}, +{"anum", {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}}, +{"znum", {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}}, +{"endcond", {8, 8, 8, 16, 8, 16, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 8, 16, 16, 16, 1, 8, 8, 16, 8, 8, 16, 8, 8, 8, 16, 16, 16, 16, 16, 8, 16, 8, 8, 16, 8, 8, 8, 8, 8, 16, 8, 16, 8, 8, 16, 8, 8, 16, 8, 16, 8, 8, 8, 8, 8, 8, 8, 16, 16, 8, 8, 16, 8, 1, 4, 8, 8, 8, 16, 8, 16, 8, 8, 8, 16, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 16, 8, 16, 16}}, diff --git a/supplementary/ascot5/simple_run_quick.py b/supplementary/ascot5/simple_run_quick.py new file mode 100644 index 0000000..27ae56a --- /dev/null +++ b/supplementary/ascot5/simple_run_quick.py @@ -0,0 +1,285 @@ +""" +Module for generating simple runs from analytical inputs. + +File: simpleruns.py +""" +import numpy as np + +import a5py.ascot5io.B_GS as B_GS +import a5py.ascot5io.E_TC as E_TC +import a5py.ascot5io.plasma_1D as plasma_1D +import a5py.ascot5io.wall_2D as wall_2D +import a5py.ascot5io.N0_3D as N0_3D +import a5py.ascot5io.options as options +import a5py.ascot5io.mrk_prt as mrk_prt +import a5py.ascot5io.mrk_gc as mrk_gc + +from numpy.random import random as rand +from scipy.constants import physical_constants as const + +def make_ascot5_hello_world(): + settings = {} + + # Magnetic field input, choose whether you want + # - Analytical or spline interpolated + # - Axisymmetric or 3D + settings["bfield_use_splines"] = False + settings["bfield_make_3D"] = False + + # How many markers you want + settings["markers"] = 100 + + # Do you want 2D or 3D wall model + settings["wall_make_3D"] = True + + # Simulate guiding centers (GC) (if false, simulate gyro-orbits (GO)) + settings["sim_gc_mode"] = False + + # If this is a guiding center simulation, do we use adaptive step? + settings["sim_use_adaptivestep"] = False + + # Try out the hybrid model for wall collision checks + settings["sim_use_hybrid"] = False + + # Record GC position even if the simulation is GO simulation + settings["sim_recordGCasGO"] = False + + make_ascot5_slowingdownrun("simple_run_quick.h5", settings) + +def make_ascot5_regression_test(): + print("implement me") + +def make_ascot5_slowingdownrun(fn, settings): + """ + Create test case base with uniform EM fields and plasma. + """ + # ITER like but circular magnetic field paramters + psi_coeff = np.array([2.21808016e-02, -1.28841781e-01, -4.17718173e-02, + -6.22680280e-02, 6.20083978e-03, -1.20524711e-03, + -3.70147050e-05, 0.00000000e+00, 0.00000000e+00, + 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, + -0.155]) + R0 = 6.2 + z0 = 0 + B_phi0 = 5.3 + psi_mult = 200 + N_TFcoils = 18 + minor_radius = 2 + ripple_penetration = 0.2 + ripple_strength = 0.5 + + # Magnetic field grid if splines are used + Rmin = 4; Rmax = 8.5; nR = 120 + pmin = 0; pmax = 360; nph = 360 + zmin = -4; zmax = 4; nz = 200 + + # Generate input of type that was requested + if not settings["bfield_use_splines"]: + if not settings["bfield_make_3D"]: + # Analytic 2D equilibrium + B_GS.write_hdf5(fn, R0, z0, B_phi0, psi_mult, psi_coeff) + else : + # Analytic 2D equilibrium and analytic ripple + B_GS.write_hdf5(fn, R0, z0, B_phi0, psi_mult, psi_coeff, + nripple=N_TFcoils, a0=minor_radius, + alpha0=ripple_penetration, delta0=ripple_strength) + else: + if not settings["bfield_make_3D"]: + # Analytic equilibrium represented with 2D splines + B_GS.write_hdf5_B_2DS(fn, R0, z0, B_phi0, psi_mult, psi_coeff, + Rmin, Rmax, nR, zmin, zmax, nz) + else : + # Analytic equilibrium represented with 3D splines + B_GS.write_hdf5_B_3DS(fn, R0, z0, B_phi0, psi_mult, psi_coeff, + N_TFcoils, minor_radius, + ripple_penetration, ripple_strength, + Rmin, Rmax, nR, zmin, + zmax, nz, pmin, pmax, nph) + + # Electric field that is zero everywhere + Exyz = np.array([0, 0, 0]) + E_TC.write_hdf5(fn, Exyz) + + # Plasma data: uniform density through 0 to 1 and exponential decay after + dens = 1e20 + temp = 1e3 + Nrho = 100 + Nion = 1 + anum = np.array([1]) + znum = np.array([1]) + mass = np.array([1]) + charge = np.array([1]) + rho = np.transpose(np.linspace(0,2,num=Nrho)) + plasmaprofile = np.ones((len(rho),1)) + edens = dens*plasmaprofile + etemp = temp*plasmaprofile + idens = dens*plasmaprofile + itemp = temp*plasmaprofile + + edens[rho>1] = 1 + idens[rho>1] = 1 + plasma_1D.write_hdf5(fn, Nrho, Nion, anum, znum, mass, charge, rho, edens, + etemp, idens, itemp) + + # Square wall around the plasma + wall_nseg = 20 + wall_R = np.concatenate( (np.linspace(4.1, 8.4, 6)[1:], + np.linspace(8.4, 8.4, 6)[1:], + np.linspace(8.4, 4.1, 6)[1:], + np.linspace(4.1, 4.1, 6)[1:]) ) + wall_z = np.concatenate( (np.linspace(-3.9, -3.9, 6)[1:], + np.linspace(-3.9, 3.9, 6)[1:], + np.linspace(3.9, 3.9, 6)[1:], + np.linspace(3.9, -3.9, 6)[1:]) ) + wall_nphi = 10 + + # If requested, make it 3D by wrapping 2D wall around torus + if not settings["wall_make_3D"]: + wall_2D.write_hdf5(fn, wall_nseg, wall_R, wall_z) + else : + wall_2D.write_hdf5_3D(fn, wall_nseg, wall_R, wall_z, wall_nphi) + + # Dummy neutral data + N0_3D.write_hdf5_dummy(fn) + + # Particle input + Nmrk = settings["markers"] + ids = np.linspace(1,Nmrk,Nmrk) + mass = 4*np.ones(ids.shape) + charge = 2*np.ones(ids.shape) + anum = 4*np.ones(ids.shape) + znum = 2*np.ones(ids.shape) + R = 3.5 + 2*rand(ids.shape) + phi = 360*rand(ids.shape) + z = 0*np.ones(ids.shape) + weight = 1*np.ones(ids.shape) + time = 0*np.ones(ids.shape) + energy = 3.5e6*np.ones(ids.shape) + pitch = 0.999-1.999*rand(ids.shape) + theta = 2*np.pi*rand(ids.shape) + + gamma = 1 + energy * const["elementary charge"][0] \ + / ( const["alpha particle mass"][0] \ + * np.power(const["speed of light in vacuum"][0],2) ) + v = np.sqrt(1-1/(gamma*gamma))*const["speed of light in vacuum"][0] + vR = np.sqrt(1-pitch*pitch)*v + vphi = pitch*v + vz = 0*v + mrk_prt.write_hdf5(fn, Nmrk, ids, mass, charge, R, phi, z, vR, vphi, vz, + anum, znum, weight, time) + + # Set options to null state + o = options.generateopt() + o = flagsToZero(o,"ENABLE") + o = flagsToZero(o,"ENDCOND") + o["RECORD_MODE"] = np.array([0],dtype='i4') + + # Set slowing-down simulation options + + o["SIM_MODE"] = 1 + o["FIXEDSTEP_USERDEFINED"] = 1.0e-9 + if settings["sim_gc_mode"]: + o["SIM_MODE"] = 2 + o["FIXEDSTEP_USERDEFINED"] = 5.0e-8 + + if settings["sim_use_hybrid"]: + o["SIM_MODE"] = 3 + o["FIXEDSTEP_USERDEFINED"] = 5.0e-8 + + if settings["sim_use_adaptivestep"]: + o["ENABLE_ADAPTIVE"] = 1 + + if settings["sim_recordGCasGO"]: + o["RECORD_MODE"] = 1 + + o["FIXEDSTEP_USE_USERDEFINED"] = 1 + o["ADAPTIVE_TOL_ORBIT"] = 1.0e-8 + o["ADAPTIVE_TOL_CCOL"] = 1.0e-2 + o["ADAPTIVE_MAX_DRHO"] = 1.0 + o["ADAPTIVE_MAX_DPHI"] = 1.0 + + o["ENDCOND_SIMTIMELIM"] = 1 + o["ENDCOND_CPUTIMELIM"] = 1 + o["ENDCOND_RHOLIM"] = 1 + o["ENDCOND_ENERGYLIM"] = 1 + o["ENDCOND_WALLHIT"] = 1 + + o["ENDCOND_MAX_SIMTIME"] = 1.0e-4 + o["ENDCOND_MAX_CPUTIME"] = 1.0e3 + o["ENDCOND_MAX_RHO"] = 10.0 + o["ENDCOND_MIN_RHO"] = 0.7 + o["ENDCOND_MIN_ENERGY"] = 1.99e3 + o["ENDCOND_MIN_THERMAL"] = 2.0 + + o["ENABLE_ORBIT_FOLLOWING"] = 1 + o["ENABLE_COULOMB_COLLISIONS"] = 1 + + # All distributions on + o["ENABLE_DIST_5D"] = 1 + o["ENABLE_DIST_6D"] = 1 + o["ENABLE_DIST_RHO5D"] = 1 + o["ENABLE_DIST_RHO6D"] = 1 + + o["DIST_MIN_R"] = 3.5 + o["DIST_MAX_R"] = 8.5 + o["DIST_NBIN_R"] = 12 + + o["DIST_MIN_PHI"] = 0 + o["DIST_MAX_PHI"] = 360 + o["DIST_NBIN_PHI"] = 20 + + o["DIST_MIN_Z"] = -2.45 + o["DIST_MAX_Z"] = 2.45 + o["DIST_NBIN_Z"] = 24 + + o["DIST_MIN_RHO"] = 0 + o["DIST_MAX_RHO"] = 1 + o["DIST_NBIN_RHO"] = 11 + + o["DIST_MIN_THETA"] = 0 + o["DIST_MAX_THETA"] = 360 + o["DIST_NBIN_THETA"] = 13 + + o["DIST_MIN_VPA"] = -1.5e7 + o["DIST_MAX_VPA"] = 1.5e7 + o["DIST_NBIN_VPA"] = 36 + + o["DIST_MIN_VPE"] = 0 + o["DIST_MAX_VPE"] = 1.5e7 + o["DIST_NBIN_VPE"] = 18 + + o["DIST_MIN_VR"] = -1.5e7 + o["DIST_MAX_VR"] = 1.5e7 + o["DIST_NBIN_VR"] = 14 + + o["DIST_MIN_VPHI"] = -1.5e7 + o["DIST_MAX_VPHI"] = 1.5e7 + o["DIST_NBIN_VPHI"] = 15 + + o["DIST_MIN_VZ"] = -1.5e7 + o["DIST_MAX_VZ"] = 1.5e7 + o["DIST_NBIN_VZ"] = 16 + + o["DIST_MIN_TIME"] = 0 + o["DIST_MAX_TIME"] = 3e-2 + o["DIST_NBIN_TIME"] = 2 + + o["DIST_MIN_CHARGE"] = -100 + o["DIST_MAX_CHARGE"] = 100 + o["DIST_NBIN_CHARGE"] = 1 + + o["ENABLE_ORBITWRITE"] = 1 + o["ORBITWRITE_MODE"] = 1 + o["ORBITWRITE_NPOINT"] = 100 + o["ORBITWRITE_INTERVAL"] = 0 + + options.write_hdf5(fn, o) + +def flagsToZero(options,flags): + for i in options: + if i.startswith(flags): + options[i] = np.array([0],dtype='i4') + return options + +if __name__ == '__main__': + make_ascot5_hello_world() diff --git a/supplementary/ascot5/simple_run_quick_endstate_fp.txt b/supplementary/ascot5/simple_run_quick_endstate_fp.txt new file mode 100644 index 0000000..87d5b6e --- /dev/null +++ b/supplementary/ascot5/simple_run_quick_endstate_fp.txt @@ -0,0 +1,9 @@ +{"mass", {6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27, 6.642156e-27}}, +{"rprt", {3.902164e+00, 8.021377e+00, 6.404512e+00, 7.990867e+00, 8.186851e+00, 4.001307e+00, 3.959174e+00, 3.985467e+00, 3.900034e+00, 5.122297e+00, 7.989679e+00, 5.413621e+00, 8.097417e+00, 8.132724e+00, 8.003062e+00, 3.907641e+00, 3.904191e+00, 7.996854e+00, 3.951107e+00, 6.715157e+00, 5.815808e+00, 6.575163e+00, 3.907416e+00, 8.150620e+00, 4.837630e+00, 8.164708e+00, 4.050672e+00, 3.935496e+00, 3.965542e+00, 6.018980e+00, 5.321379e+00, 6.656532e+00, 7.991811e+00, 5.480018e+00, 5.343051e+00, 8.039152e+00, 8.137743e+00, 7.996635e+00, 5.318960e+00, 4.087417e+00, 3.934678e+00, 5.360352e+00, 8.052443e+00, 3.979714e+00, 3.894790e+00, 3.902419e+00, 3.941018e+00, 3.923506e+00, 3.900362e+00, 3.914586e+00, 3.906154e+00, 5.482039e+00, 8.046085e+00, 7.991720e+00, 3.918165e+00, 5.261661e+00, 5.223607e+00, 5.300778e+00, 6.861763e+00, 4.933140e+00, 5.581725e+00, 3.928581e+00, 5.377336e+00, 5.290808e+00, 4.085004e+00, 3.899808e+00, 4.066303e+00, 4.042630e+00, 5.219525e+00, 8.059913e+00, 3.934908e+00, 7.110895e+00, 8.098300e+00, 3.940767e+00, 5.324719e+00, 3.949488e+00, 5.446883e+00, 5.341386e+00, 8.004781e+00, 5.251300e+00, 3.938475e+00, 3.935650e+00, 7.992954e+00, 7.993912e+00, 3.903207e+00, 8.158305e+00, 5.456803e+00, 7.993085e+00, 8.086808e+00, 7.990519e+00, 3.904623e+00, 7.999211e+00, 7.993083e+00, 6.253236e+00, 5.368194e+00, 4.004139e+00, 5.426111e+00, 5.216689e+00, 6.074238e+00, 5.280000e+00}}, +{"phiprt", {4.495596e+02, -3.373434e+02, 2.897119e+02, 4.489168e+02, -4.172490e+01, 1.387769e+02, 3.684054e+02, 7.785627e+01, 1.617487e+02, 3.147730e+02, 6.296804e+02, 1.242763e+04, 1.791387e+03, -3.313687e+02, -3.028892e+02, 3.449303e+02, 1.289864e+02, -3.081716e+02, 5.489679e+02, 3.994132e+02, 8.035516e+03, 1.032466e+04, 1.644654e+02, -1.149293e+02, 1.121475e+04, -1.861926e+02, 2.902660e+02, 5.143681e+02, 3.676279e+02, 5.472664e+02, 3.261566e+02, 1.074836e+04, -2.704258e+02, 1.939242e+02, 7.673123e+01, -1.560156e+02, -2.231777e+02, -8.773298e+01, 3.441296e+02, 5.107891e-01, 6.239617e+01, 1.587557e+02, 6.228171e+02, 4.250406e+01, 8.863122e+01, 3.024020e+02, 1.171284e+02, 1.197311e+02, 4.848726e+02, 4.091610e+02, 3.402375e+02, 1.226165e+02, -1.554574e+02, 7.728803e+02, 9.488820e+01, 4.368090e+01, 2.663672e+02, 3.368171e+02, 1.033626e+04, 1.193794e+04, 8.883304e+03, 1.687811e+02, 5.060716e+01, 3.985129e+01, 1.083675e+02, 1.259498e+02, 3.227281e+02, 1.052513e+02, 2.830838e+02, -8.242628e+01, 8.226872e+01, 5.500049e+02, -1.888230e+02, 5.499634e+02, 3.166996e+02, 5.129983e+02, 7.722384e+01, 2.787068e+02, 6.625052e+02, 8.550445e+00, 4.780068e+02, 1.903198e+02, 3.328530e+03, 5.924086e+02, 4.481316e+02, -3.304535e+02, 6.292887e+03, 6.648455e+02, 5.491008e+02, -5.634352e+03, -8.783988e+01, -1.235109e+02, -1.260702e+02, 5.198865e+02, 4.594111e+01, 3.552445e+02, 1.259689e+04, 4.633144e+01, 5.585872e+02, 1.636512e+01}}, +{"zprt", {-6.622955e-01, 8.293220e-01, -1.383118e+00, -3.013420e-01, 5.020397e-01, 5.360830e-03, -5.770364e-02, 1.290780e-01, -3.124895e-02, 7.708910e-04, 1.319082e-01, 1.211779e+00, 9.141281e-01, 2.225575e-01, 1.051600e+00, 2.430099e-02, 2.173327e-02, 4.051253e-01, -1.083164e+00, -1.350772e+00, -1.632315e+00, 1.542439e+00, 2.912459e-01, 6.357337e-01, -8.352473e-01, 2.238729e-01, 1.514381e-01, -1.190813e+00, -1.094082e+00, -1.315527e+00, 1.476436e-03, -1.681814e+00, 3.981842e-01, 1.310498e-03, 1.410406e-03, 6.082555e-01, 8.528356e-01, 1.200913e+00, 1.875629e-03, 4.947001e-01, 8.944814e-03, 1.814850e-03, -1.312205e-01, -6.664728e-02, 4.801758e-02, 5.554539e-02, 1.057075e-01, 9.144501e-03, -7.725157e-01, -8.068196e-01, -8.466689e-01, 1.204015e-03, 1.305686e-01, -6.370157e-01, 1.022033e+00, 1.668544e-03, 1.894358e-03, 1.206089e-03, -1.487244e+00, -5.538926e-01, 1.443421e+00, 8.906385e-01, 1.667202e-03, 1.901983e-03, 1.676426e-01, 5.873105e-01, 3.510515e-02, 3.139815e-02, 1.384130e-03, 8.993597e-01, 6.962096e-02, -1.187425e+00, 1.264784e-01, -1.133734e+00, 1.726726e-03, -9.877786e-01, 1.563097e-03, 1.327506e-03, 5.231427e-02, 1.250224e-03, -8.729392e-01, -5.893878e-01, -2.369763e-01, -2.090754e-01, -5.649003e-01, 2.414972e-01, -1.393588e+00, 1.457191e-01, -3.310524e-01, 3.459254e-03, 1.303124e+00, 6.473437e-01, 6.381654e-01, -1.371796e+00, 1.674693e-03, -7.209530e-02, 1.503115e+00, 8.867704e-04, -1.332240e+00, 1.858041e-03}}, +{"vr", {4.188986e+05, 5.914381e+06, -7.603723e+06, 1.017052e+05, 9.293130e+06, 4.732280e+06, 2.880471e+06, -6.543649e+06, -1.574978e+05, 4.717791e+06, 2.277408e+06, -3.298558e+05, -1.060332e+06, 6.822169e+06, 3.823862e+06, 5.231983e+06, 1.202757e+06, 3.267541e+06, 5.057643e+06, -4.473109e+06, 1.046568e+07, -8.484541e+06, 4.175367e+06, 1.010807e+07, -1.832521e+06, 3.903343e+06, -2.703677e+06, 3.849705e+06, 2.276507e+06, -1.012141e+07, 9.599980e+06, 8.291369e+06, 5.804997e+06, 8.779398e+06, 9.202344e+06, 7.112640e+06, 7.211636e+06, 1.012561e+07, 1.232588e+07, -3.275824e+06, -5.315533e+06, 1.196392e+07, 5.909110e+06, 9.366935e+06, -8.068261e+06, -9.559925e+06, -3.890834e+06, 8.727990e+06, 2.099796e+06, 4.788927e+06, 5.352300e+06, 8.055495e+06, 6.705878e+06, 3.578800e+06, 2.620947e+06, 1.074787e+07, 1.216454e+07, 7.773182e+06, 7.984636e+06, -1.512115e+05, 3.180831e+06, 5.022454e+06, 1.099744e+07, 1.240393e+07, -7.719958e+06, 2.103518e+06, -8.180598e+06, 5.190899e+05, 9.029168e+06, 5.388741e+06, 2.553449e+06, -7.517883e+06, 4.508898e+06, 1.193021e+06, 1.140825e+07, 9.472235e+06, 1.059653e+07, 8.647104e+06, 6.561819e+06, 8.229223e+06, -1.468578e+06, 5.436796e+06, 2.879513e+06, 5.714339e+06, 3.257427e+06, 6.388061e+06, 7.118904e+05, 2.293180e+06, 2.180816e+06, 1.656478e+06, 1.706796e+06, 5.058937e+06, 6.609182e+06, -1.573747e+05, 1.102769e+07, -1.324540e+06, -3.444044e+06, 5.567893e+06, -7.222827e+06, 1.206029e+07}}, +{"vphi", {6.492701e+06, -9.918921e+06, 1.045167e+07, 8.469659e+06, -8.790811e+06, 1.097135e+07, 7.658743e+06, -1.113678e+07, 8.365966e+06, 1.199639e+07, 6.953469e+06, 1.285163e+07, -1.036620e+07, -9.953040e+06, -1.131821e+07, -9.661565e+06, 4.064235e+06, -9.478428e+06, 1.120315e+07, 1.218459e+07, 7.011652e+06, 9.706135e+06, -6.615922e+06, -8.113111e+06, 1.012158e+07, -1.026697e+07, -6.971768e+06, 9.740383e+06, 1.104313e+07, 6.917506e+06, 8.226241e+06, 9.807570e+06, -9.062124e+06, 9.197994e+06, 8.712606e+06, -1.076189e+07, -1.062792e+07, -8.095242e+06, -1.596742e+06, -2.281296e+06, 7.714739e+06, 3.498438e+06, 9.012219e+06, 8.818532e+06, 2.566635e+06, -8.200930e+06, -1.145127e+07, -3.873433e+06, 9.650108e+06, 4.734156e+06, 8.580877e+06, 9.892254e+06, -1.001990e+07, 1.188400e+07, -2.617117e+06, 6.472920e+06, 2.493999e+06, 1.011483e+07, 9.553074e+06, 1.241818e+07, 8.876657e+06, -1.178448e+07, 6.040509e+06, 4.691484e+05, -9.297016e+06, -8.696943e+06, 4.078046e+06, -2.761511e+06, -8.908431e+06, -1.147520e+07, -7.293691e+06, 9.536742e+06, -9.820692e+06, 1.061929e+07, -5.145472e+06, 8.356575e+06, -6.818337e+06, 9.312912e+06, 8.037920e+06, -9.724868e+06, 4.654825e+06, 5.393641e+06, 8.114669e+06, 9.828096e+06, 4.258374e+06, -1.123892e+07, 6.991374e+06, 8.284049e+06, 1.019223e+07, -1.062173e+07, -1.243435e+07, -1.194178e+07, -8.891088e+06, 1.292241e+07, 5.976454e+06, 5.402319e+05, 1.233780e+07, 1.159306e+07, 1.029739e+07, 3.047657e+06}}, +{"vz", {1.123466e+07, 5.925965e+06, 1.220900e+06, 9.840866e+06, 2.183103e+06, 5.077722e+06, 1.007943e+07, -1.304263e+06, 9.926436e+06, 1.541703e+06, 1.071919e+07, 6.344958e+05, 7.602807e+06, 4.772400e+06, -5.074703e+06, 6.915840e+06, -1.227126e+07, 8.237707e+06, 4.178272e+06, 1.628399e+05, -2.672034e+06, -6.286453e+05, 1.036071e+07, 5.701477e+05, -7.798990e+06, 6.917583e+06, -1.061287e+07, 7.671574e+06, 6.435458e+06, 4.244067e+06, 2.952895e+06, 1.238691e+06, 7.227942e+06, 2.620720e+06, 2.820873e+06, 1.443403e+06, -1.905059e+06, -6.981855e+05, 3.751206e+06, -1.235366e+07, -8.987561e+06, 3.629764e+06, 7.236692e+06, 1.744236e+06, -9.841945e+06, -3.146573e+06, -4.719980e+06, 8.795854e+06, 8.427017e+06, 1.109965e+07, 8.140625e+06, 2.407959e+06, 4.800601e+06, 3.794769e+06, 1.244306e+07, 3.337059e+06, 3.788657e+06, 2.411986e+06, 3.479863e+06, 3.462855e+06, -8.791608e+06, 2.109367e+06, 3.334356e+06, 3.804058e+06, -4.745111e+06, 9.406739e+06, -9.219311e+06, 1.267489e+07, 2.768253e+06, -2.763510e+06, -1.043218e+07, -4.574269e+06, 7.170350e+06, 7.372635e+06, 3.453240e+06, 2.998793e+06, 3.126206e+06, 2.654801e+06, 7.786431e+06, 2.500420e+06, 1.203014e+07, 1.048324e+07, 9.676025e+06, 6.273086e+06, 1.182386e+07, 1.181365e+06, 1.084374e+07, 9.721418e+06, 7.735533e+06, 7.163149e+06, 3.319952e+06, 6.076971e+05, 6.763234e+06, 1.248964e+06, 3.349353e+06, -1.290357e+07, 1.491232e+06, 1.773556e+06, 3.205848e+06, 3.716102e+06}}, +{"weight", {1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00}}, +{"time", {1.767000e-06, 5.357000e-06, 2.909000e-06, 4.985000e-06, 8.337000e-06, 2.000000e-09, 1.450000e-07, 8.900000e-08, 9.700000e-08, 1.000000e-09, 9.526000e-06, 1.000000e-04, 7.431700e-05, 5.743000e-06, 3.079000e-06, 1.800000e-08, 1.200000e-08, 7.577000e-06, 1.332000e-06, 2.466000e-06, 1.000000e-04, 1.000000e-04, 3.750000e-07, 1.049700e-05, 1.000000e-04, 6.583000e-06, 1.910000e-07, 1.862000e-06, 1.423000e-06, 1.371000e-05, 1.000000e-09, 1.000000e-04, 8.245000e-06, 1.000000e-09, 1.000000e-09, 3.714000e-06, 3.668000e-06, 6.070000e-06, 1.000000e-09, 5.058000e-06, 4.200000e-08, 1.000000e-09, 5.111000e-06, 9.600000e-08, 1.000000e-08, 9.000000e-09, 7.400000e-08, 2.000000e-09, 1.168000e-06, 3.884000e-06, 1.449000e-06, 1.000000e-09, 5.164000e-06, 3.453000e-06, 3.465000e-06, 1.000000e-09, 1.000000e-09, 1.000000e-09, 1.000000e-04, 1.000000e-04, 1.000000e-04, 7.930000e-07, 1.000000e-09, 1.000000e-09, 1.410000e-07, 6.320000e-07, 4.300000e-08, 4.000000e-09, 1.000000e-09, 3.150000e-06, 7.600000e-08, 5.779000e-06, 7.227000e-06, 1.598000e-06, 1.000000e-09, 1.602000e-06, 1.000000e-09, 1.000000e-09, 6.804000e-06, 1.000000e-09, 7.293000e-06, 1.898000e-06, 3.797900e-05, 4.338000e-06, 3.056000e-06, 3.849000e-06, 1.000000e-04, 5.471000e-06, 4.073000e-06, 8.286300e-05, 1.169000e-06, 3.097000e-06, 1.069000e-05, 1.787000e-06, 1.000000e-09, 1.110000e-06, 1.000000e-04, 1.000000e-09, 2.476000e-06, 1.000000e-09}}, diff --git a/supplementary/ascot5/simple_run_quick_endstate_int.txt b/supplementary/ascot5/simple_run_quick_endstate_int.txt new file mode 100644 index 0000000..539a9e4 --- /dev/null +++ b/supplementary/ascot5/simple_run_quick_endstate_int.txt @@ -0,0 +1,4 @@ +{"id", {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100}}, +{"charge", {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, +{"anum", {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}}, +{"znum", {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}}, diff --git a/supplementary/ascot5/simple_run_quick_input.h5 b/supplementary/ascot5/simple_run_quick_input.h5 new file mode 100644 index 0000000..0b6613a --- /dev/null +++ b/supplementary/ascot5/simple_run_quick_input.h5 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd37fcfbc77f04d495693fa377df6841e4bc5ca181edbc112ec590f85caa422d +size 123620 diff --git a/supplementary/ascot5/vphi_quick.csv b/supplementary/ascot5/vphi_quick.csv new file mode 100644 index 0000000..f76ea8b --- /dev/null +++ b/supplementary/ascot5/vphi_quick.csv @@ -0,0 +1 @@ +6.492701298772452399e+06, -9.640107071652561426e+06, 1.045213257266329974e+07, 8.440662719975093380e+06, -8.776201507522625849e+06, 1.097135352794579044e+07, 7.658743491348427720e+06, -1.113678098877682537e+07, 8.365966423919799738e+06, 1.199633549350807630e+07, 6.921172106592651457e+06, 1.274506990568034165e+07, 4.560538023208796047e+06, -9.335972135420329869e+06, -1.131592861805500649e+07, -9.661565330170780420e+06, 4.064235046175145544e+06, -9.481000327863404527e+06, 1.120315243975296058e+07, 1.218194059096620604e+07, 7.192106077908927575e+06, 1.028182595505019464e+07, -6.615922467050546780e+06, -7.941487940930943005e+06, 1.125562071812202036e+07, -9.622890920915467665e+06, -6.971768213647169061e+06, 9.740382806529304013e+06, 1.104313104227859341e+07, 6.902494778245725669e+06, 8.226189268856520765e+06, 1.152452399187667295e+07, -9.571463589921087027e+06, 9.197938116985902190e+06, 8.712615314250528812e+06, -1.082211399865413457e+07, -1.068007893655811809e+07, -8.095242382568120025e+06, -1.596760058239639504e+06, -2.281295617563875392e+06, 7.714738923846660182e+06, 3.498515345716753975e+06, 8.974889210696520284e+06, 8.818532185480454937e+06, 2.566634564876860008e+06, -8.200930176945962012e+06, -1.145126806873370335e+07, -3.873432536667405162e+06, 9.650108236681655049e+06, 4.734155857336253859e+06, 8.580876691941855475e+06, 9.892220694500656798e+06, -1.001083139609322324e+07, 1.187695410552902892e+07, -2.617116656140115112e+06, 6.472536163444899023e+06, 2.493905688112113159e+06, 1.011482287009207904e+07, 9.531161563372233883e+06, 1.180110549872102961e+07, 9.257315691126961261e+06, -1.178447552824107744e+07, 6.040401460769318044e+06, 4.693738503073072061e+05, -9.297015927133072168e+06, -8.696943052120957524e+06, 4.078045695531179663e+06, -2.761510796381428838e+06, -8.908263241535628214e+06, -1.151660008814521506e+07, -7.293691008885084651e+06, 9.522310831569222733e+06, -9.584664838673224673e+06, 1.061928902978692204e+07, -5.145267039061734453e+06, 8.356574550118450075e+06, -6.818311917363377288e+06, 9.312950120104465634e+06, 8.005205204979187809e+06, -9.724902810687497258e+06, 4.654824939649670385e+06, 5.393640730981994420e+06, 8.096073930669086054e+06, 9.797613356599196792e+06, 4.258374167384886183e+06, -1.125009206605644524e+07, 5.329292349472776055e+06, 8.379065227682460099e+06, 1.017566176418238878e+07, -1.062570208889432810e+07, -1.243435177785620280e+07, -1.189229933999574929e+07, -9.173770392378721386e+06, 1.292219045630387031e+07, 5.976525511617368087e+06, 5.402318623721542535e+05, 1.211236220531049930e+07, 1.159297874875888042e+07, 1.028298980194181018e+07, 3.047659801476442255e+06, \ No newline at end of file diff --git a/supplementary/ascot5/vr_quick.csv b/supplementary/ascot5/vr_quick.csv new file mode 100644 index 0000000..9e44023 --- /dev/null +++ b/supplementary/ascot5/vr_quick.csv @@ -0,0 +1 @@ +4.188985535533562652e+05, 7.070502815087599680e+06, -7.636158614852994680e+06, 1.145267300727042602e+06, 9.312965712451353669e+06, 4.732280287894872949e+06, 2.880470661408778280e+06, -6.543649260857601650e+06, -1.574977585837645456e+05, 4.717674151588845998e+06, 2.064750296283769887e+06, -2.211860956069839187e+06, -7.185892228322144598e+06, 8.777494836691305041e+06, 3.782804405138372909e+06, 5.231982993984293193e+06, 1.202756660482098348e+06, 3.087379732898131944e+06, 5.057643177964685485e+06, -4.469662429872955196e+06, 9.518764679730977863e+06, -1.987782798220453318e+06, 4.175367385570073500e+06, 1.025066908438956365e+07, -1.955385632754161023e+06, 7.537513877284852788e+06, -2.703676758189930115e+06, 3.849705151896625757e+06, 2.276506538845914416e+06, -1.003887143344253488e+07, 9.599978019321970642e+06, -2.794430892380543053e+06, 7.475365268374780426e+05, 8.779274887615341693e+06, 9.202347677265232429e+06, 6.950039712018099613e+06, 7.188622929724885151e+06, 1.012560747655091248e+07, 1.232584618791977316e+07, -3.275824344736191444e+06, -5.315532576391742565e+06, 1.196396665265876241e+07, 5.694649667255659588e+06, 9.366934961101077497e+06, -8.068261268228993751e+06, -9.559924761070623994e+06, -3.890834115765157156e+06, 8.727989771420661360e+06, 2.099795714975048322e+06, 4.788927306389690377e+06, 5.352300496623408049e+06, 8.055657695068452507e+06, 6.708460828568927944e+06, 3.561288939942188561e+06, 2.620946505429810844e+06, 1.074796611870339327e+07, 1.216446576742294431e+07, 7.773051689314278774e+06, 8.612152200743988156e+06, -2.640013831739779562e+06, -1.303158503374516731e+06, 5.022454087618279271e+06, 1.099736350380812585e+07, 1.240395359374840185e+07, -7.719958316751128063e+06, 2.103517892418867908e+06, -8.180597748746608384e+06, 5.190899383286888478e+05, 9.029280185300452635e+06, 5.409389512664784677e+06, 2.553448669233762193e+06, -7.752391633505460806e+06, 6.259800619823458605e+06, 1.193020683579144999e+06, 1.140823642667769641e+07, 9.472235239569708705e+06, 1.059640709422574006e+07, 8.646847709620555863e+06, 6.402261447794737294e+06, 8.229495646997016855e+06, -1.468578429521424463e+06, 5.436795974235650152e+06, 1.827426106305611786e+06, 5.585803304279394448e+06, 3.257427496556041297e+06, 6.344345564422544092e+06, 1.117804784600507654e+07, 3.362439298913687002e+06, 9.306020918415240012e+05, 1.719822842951549217e+06, 1.706795754868683638e+06, 5.189488483581449836e+06, 4.884286136288893409e+06, -1.722047163628228009e+05, 1.102772966151208431e+07, -1.324539543774374062e+06, -4.394476213969391771e+06, 5.568189248315598816e+06, -7.288752429302556440e+06, 1.206022801214471459e+07, \ No newline at end of file diff --git a/supplementary/ascot5/vz_quick.csv b/supplementary/ascot5/vz_quick.csv new file mode 100644 index 0000000..f56f9ea --- /dev/null +++ b/supplementary/ascot5/vz_quick.csv @@ -0,0 +1 @@ +1.123466478692467324e+07, 5.054411228650572710e+06, 9.585671562615525909e+05, 9.802935396305443719e+06, 2.201547048272352200e+06, 5.077722330869821832e+06, 1.007942835334776342e+07, -1.304263235194377368e+06, 9.926436383600633591e+06, 1.541824976739645936e+06, 1.077904418341665156e+07, -2.560108164234674769e+05, -9.643525432811131701e+06, 2.048754911437833449e+06, -5.113551288432821631e+06, 6.915840393566162325e+06, -1.227125539351577312e+07, 8.302530610613210127e+06, 4.178272361137263477e+06, 3.395462947596778977e+05, 4.984667425329016522e+06, 7.558149746017783880e+06, 1.036070538782346807e+07, -1.588129848276356352e+05, 6.028024896105947904e+06, 4.356674849545905367e+06, -1.061286572939588316e+07, 7.671574287819704041e+06, 6.435457543132803403e+06, 4.455163395825868472e+06, 2.952720351896135602e+06, -5.082006879394599237e+06, 8.729075037983844057e+06, 2.621026200543973129e+06, 2.821115716030993965e+06, 1.731229250624551205e+06, -1.671378537490043323e+06, -6.981855241541009163e+05, 3.751324256584329065e+06, -1.235366359407554381e+07, -8.987561170528156683e+06, 3.629487711314712185e+06, 7.448470337805340067e+06, 1.744235808579851873e+06, -9.841945241960944608e+06, -3.146573028440066148e+06, -4.719979717051813379e+06, 8.795854362234743312e+06, 8.427016554125437513e+06, 1.109965236394236609e+07, 8.140624891207260080e+06, 2.408065492947618011e+06, 4.807618538352963515e+06, 3.835328626619687770e+06, 1.244305745593252406e+07, 3.336940959277781658e+06, 3.788845596713943873e+06, 2.412287558852328453e+06, 1.095085632897977717e+06, -4.436544741683461703e+06, 8.873319955016942695e+06, 2.109367319804533850e+06, 3.334456600228022318e+06, 3.803884404077354353e+06, -4.745110901342683472e+06, 9.406738704366739839e+06, -9.219311406289627776e+06, 1.267489419226745516e+07, 2.768196995001063216e+06, -2.541300546748413239e+06, -1.043217668505865335e+07, -4.207400967844647355e+06, 6.110067467075658962e+06, 7.372634615808091126e+06, 3.453389021125979722e+06, 2.998793154314230662e+06, 3.126386234355444554e+06, 2.654969853105944581e+06, 7.955086047155376524e+06, 2.500516790253384039e+06, 1.203013803767061420e+07, 1.048323558007913083e+07, 9.936282008856477216e+06, 6.418101720629937015e+06, 1.182386377556186542e+07, 1.227350287257928634e+06, -3.681540619521673769e+06, 9.324974473841901869e+06, 7.999791659189752303e+06, 7.159164526675233617e+06, 3.319952280301799998e+06, 3.806666975496117375e+05, 7.767395255187734030e+06, 1.232491859846372623e+06, 3.349358887794710696e+06, -1.290356863660833426e+07, -8.237131591163150733e+05, 1.773820833597316639e+06, 3.108581371024414897e+06, 3.715994435546023306e+06, \ No newline at end of file diff --git a/supplementary/ascot5/walltile_quick.csv b/supplementary/ascot5/walltile_quick.csv new file mode 100644 index 0000000..89a0b19 --- /dev/null +++ b/supplementary/ascot5/walltile_quick.csv @@ -0,0 +1 @@ +113, 16, 0, 94, 333, 153, 34, 114, 193, 0, 293, 0, 0, 13, 56, 393, 153, 53, 236, 0, 0, 0, 194, 253, 0, 173, 354, 196, 36, 0, 0, 0, 93, 0, 0, 213, 136, 296, 0, 34, 73, 0, 294, 74, 114, 354, 154, 154, 153, 76, 396, 0, 213, 54, 111, 0, 0, 0, 0, 0, 0, 191, 0, 0, 154, 154, 353, 113, 0, 296, 114, 0, 173, 236, 0, 196, 0, 0, 334, 0, 156, 233, 94, 254, 113, 13, 0, 333, 214, 94, 311, 253, 253, 0, 0, 393, 0, 0, 0, 0, \ No newline at end of file diff --git a/supplementary/ascot5/weight_quick.csv b/supplementary/ascot5/weight_quick.csv new file mode 100644 index 0000000..0b65ab2 --- /dev/null +++ b/supplementary/ascot5/weight_quick.csv @@ -0,0 +1 @@ +1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, 1.000000000000000000e+00, \ No newline at end of file diff --git a/test/tests/problems/read_ascot5_heat_fluxes/read_ascot5_heat_fluxes.i b/test/tests/problems/ascotproblem_multi_timestep/ascotproblem_multi_timestep.i similarity index 82% rename from test/tests/problems/read_ascot5_heat_fluxes/read_ascot5_heat_fluxes.i rename to test/tests/problems/ascotproblem_multi_timestep/ascotproblem_multi_timestep.i index 6f3a613..0f40e30 100644 --- a/test/tests/problems/read_ascot5_heat_fluxes/read_ascot5_heat_fluxes.i +++ b/test/tests/problems/ascotproblem_multi_timestep/ascotproblem_multi_timestep.i @@ -7,7 +7,7 @@ [Problem] type = AscotProblem sync_variable = fi_heat_flux - ascot5_file = 'simple_run.h5' + ascot5_file = 'simple_run_test.h5' [] [AuxVariables] @@ -19,7 +19,8 @@ [Executioner] type = Transient - num_steps = 1 + dt = 1e-6 + num_steps = 5 [] [Outputs] diff --git a/test/tests/problems/ascotproblem_multi_timestep/gold/ascotproblem_multi_timestep_out.e b/test/tests/problems/ascotproblem_multi_timestep/gold/ascotproblem_multi_timestep_out.e new file mode 100644 index 0000000..002c1bd Binary files /dev/null and b/test/tests/problems/ascotproblem_multi_timestep/gold/ascotproblem_multi_timestep_out.e differ diff --git a/test/tests/problems/read_ascot5_heat_fluxes/simple_run.inp b/test/tests/problems/ascotproblem_multi_timestep/simple_run.inp similarity index 100% rename from test/tests/problems/read_ascot5_heat_fluxes/simple_run.inp rename to test/tests/problems/ascotproblem_multi_timestep/simple_run.inp diff --git a/test/tests/problems/ascotproblem_multi_timestep/simple_run_quick_input.h5 b/test/tests/problems/ascotproblem_multi_timestep/simple_run_quick_input.h5 new file mode 120000 index 0000000..09833ed --- /dev/null +++ b/test/tests/problems/ascotproblem_multi_timestep/simple_run_quick_input.h5 @@ -0,0 +1 @@ +../../../../supplementary/ascot5/simple_run_quick_input.h5 \ No newline at end of file diff --git a/test/tests/problems/ascotproblem_multi_timestep/tests b/test/tests/problems/ascotproblem_multi_timestep/tests new file mode 100644 index 0000000..0c32cd6 --- /dev/null +++ b/test/tests/problems/ascotproblem_multi_timestep/tests @@ -0,0 +1,17 @@ +[Tests] + [./setup] + type = RunCommand + command = "cp simple_run_quick_input.h5 simple_run_test.h5" + [../] + [./ascotproblem_multi_timestep] + type = 'Exodiff' + input = 'ascotproblem_multi_timestep.i' + exodiff = 'ascotproblem_multi_timestep_out.e' + prereq = setup + [../] + [./teardown] + type = RunCommand + command = "rm simple_run_test.h5" + prereq = ascotproblem_multi_timestep + [../] +[] diff --git a/test/tests/problems/read_ascot5_heat_fluxes/gold/read_ascot5_heat_fluxes_out.e b/test/tests/problems/read_ascot5_heat_fluxes/gold/read_ascot5_heat_fluxes_out.e deleted file mode 100644 index eae5908..0000000 Binary files a/test/tests/problems/read_ascot5_heat_fluxes/gold/read_ascot5_heat_fluxes_out.e and /dev/null differ diff --git a/test/tests/problems/read_ascot5_heat_fluxes/simple_run.h5 b/test/tests/problems/read_ascot5_heat_fluxes/simple_run.h5 deleted file mode 120000 index 6a0f403..0000000 --- a/test/tests/problems/read_ascot5_heat_fluxes/simple_run.h5 +++ /dev/null @@ -1 +0,0 @@ -../../../../supplementary/ascot5/simple_run.h5 \ No newline at end of file diff --git a/test/tests/problems/read_ascot5_heat_fluxes/tests b/test/tests/problems/read_ascot5_heat_fluxes/tests deleted file mode 100644 index c6f074c..0000000 --- a/test/tests/problems/read_ascot5_heat_fluxes/tests +++ /dev/null @@ -1,7 +0,0 @@ -[Tests] - [read_heat_fluxes_main_app] - type = 'Exodiff' - input = 'read_ascot5_heat_fluxes.i' - exodiff = 'read_ascot5_heat_fluxes_out.e' - [] -[] diff --git a/unit/Makefile b/unit/Makefile index 5cc23f0..f8e14f3 100644 --- a/unit/Makefile +++ b/unit/Makefile @@ -44,9 +44,9 @@ LEVEL_SET := no include $(MOOSE_DIR)/modules/modules.mk ############################################################################### -# Extra stuff for GTEST and HDF5 -ADDITIONAL_INCLUDES := -I$(FRAMEWORK_DIR)/contrib/gtest -I/usr/include/hdf5/serial -ADDITIONAL_LIBS := $(FRAMEWORK_DIR)/contrib/gtest/libgtest.la -lhdf5_hl_cpp -lhdf5_cpp -lhdf5_serial_hl -lhdf5_serial +# Extra stuff for GTEST +ADDITIONAL_INCLUDES := -I$(FRAMEWORK_DIR)/contrib/gtest +ADDITIONAL_LIBS := $(FRAMEWORK_DIR)/contrib/gtest/libgtest.la # dep apps CURRENT_DIR := $(shell pwd) diff --git a/unit/include/AscotProblemTest.h b/unit/include/AscotProblemTest.h index 7ae8bb5..215f58f 100644 --- a/unit/include/AscotProblemTest.h +++ b/unit/include/AscotProblemTest.h @@ -2,8 +2,10 @@ #include "PhaethonAppTest.h" #include "Executioner.h" +#include "Transient.h" #include "FEProblemBase.h" #include "AscotProblem.h" +#include // Fixture to test the Ascot External Problem class AscotProblemTest : public PhaethonAppInputTest @@ -37,6 +39,47 @@ class AscotProblemTest : public PhaethonAppInputTest AscotProblem * problemPtr = nullptr; }; +// Fixture to test the time stepping of the Ascot External Problem +// TODO unfortunately, it isn't possible to inherit from AscotProblemTest because downcasting of the +// . So, some duplicate code here. +class AscotProblemTimeTest : public PhaethonAppInputTest +{ +protected: + AscotProblemTimeTest(std::string inputfile) : PhaethonAppInputTest(inputfile){}; + + virtual void SetUp() override + { + + // Call the base class method + ASSERT_NO_THROW(PhaethonAppInputTest::SetUp()); + + ASSERT_FALSE(appIsNull); + ASSERT_NO_THROW(app->setupOptions()); + ASSERT_NO_THROW(app->runInputFile()); + + // Get the executioner + executionerPtr = dynamic_cast(app->getExecutioner()); + ASSERT_NE(executionerPtr, nullptr); + // This is the bit that throws a seg fault in subclasses. + ASSERT_NO_THROW(executionerPtr->init()); + // Simulate taking a time step + ASSERT_NO_THROW(executionerPtr->preExecute()); + ASSERT_NO_THROW(executionerPtr->incrementStepOrReject()); + ASSERT_NO_THROW(executionerPtr->preStep()); + ASSERT_NO_THROW(executionerPtr->computeDT()); + + // Get the FE problem + problemPtr = dynamic_cast(&(executionerPtr->feProblem())); + ASSERT_NE(problemPtr, nullptr); + + // Check type (i.e. make sure this is an AscotProblem) + ASSERT_EQ(problemPtr->type(), "AscotProblem"); + } + + Transient * executionerPtr = nullptr; + AscotProblem * problemPtr = nullptr; +}; + class AscotProblemHDF5Test : public AscotProblemTest { protected: @@ -55,3 +98,38 @@ class AscotProblemHDF5Test : public AscotProblemTest H5::H5File hdf5_file; }; + +class AscotProblemHDF5WriteTest : public AscotProblemTest +{ +protected: + AscotProblemHDF5WriteTest() : AscotProblemTest("ascot_hdf5.i") + { + // Copy the simple_run.h5 HDF5 file. The copy will be written to and then + // compared against simple_run_endstate2markers.h5 + std::filesystem::copy_file(reference_hdf5, hdf5_file_name); + }; + + ~AscotProblemHDF5WriteTest() { std::filesystem::remove(hdf5_file_name); }; + + const std::string hdf5_file_name = "inputs/simple_run_endstate2markers_test.h5"; + const std::string reference_hdf5 = "inputs/simple_run.h5"; +}; + +class AscotProblemSimpleRunTest : public AscotProblemTimeTest +{ +protected: + AscotProblemSimpleRunTest() : AscotProblemTimeTest("ascot_simple_run.i") + { + // Copy the simple_run HDF5 file that will be used a temp file for this run + std::filesystem::copy_file("inputs/simple_run_quick_input.h5", hdf5_file_name); + setenv("OMP_NUM_THREADS", "1", 1); + }; + + ~AscotProblemSimpleRunTest() + { + std::filesystem::remove(hdf5_file_name); + unsetenv("OMP_NUM_THREADS"); + }; + + const std::string hdf5_file_name = "inputs/simple_run_quick_test.h5"; +}; diff --git a/unit/inputs/ascot_hdf5.i b/unit/inputs/ascot_hdf5.i index 60ee64c..3850cdd 100644 --- a/unit/inputs/ascot_hdf5.i +++ b/unit/inputs/ascot_hdf5.i @@ -7,7 +7,7 @@ [Problem] type = AscotProblem sync_variable = fi_heat_flux - ascot5_file = './simple_run.h5' + ascot5_file = 'simple_run.h5' [] [AuxVariables] diff --git a/unit/inputs/ascot_simple_run.i b/unit/inputs/ascot_simple_run.i new file mode 100644 index 0000000..8c51290 --- /dev/null +++ b/unit/inputs/ascot_simple_run.i @@ -0,0 +1,28 @@ +[Mesh] + type = FileMesh + file = 'simple_run.inp' + allow_renumbering = false +[] + +[Problem] + type = AscotProblem + sync_variable = fi_heat_flux + ascot5_file = 'simple_run_quick_test.h5' +[] + +[AuxVariables] + [fi_heat_flux] + family = MONOMIAL + order = CONSTANT + [] +[] + +[Executioner] + type = Transient + dt = 1e-5 + num_steps = 1 +[] + +[Outputs] + console = false +[] diff --git a/unit/inputs/simple_run_endstate2markers.h5 b/unit/inputs/simple_run_endstate2markers.h5 new file mode 120000 index 0000000..c3dc815 --- /dev/null +++ b/unit/inputs/simple_run_endstate2markers.h5 @@ -0,0 +1 @@ +../../supplementary/ascot5/simple_run_endstate2markers.h5 \ No newline at end of file diff --git a/unit/inputs/simple_run_quick_input.h5 b/unit/inputs/simple_run_quick_input.h5 new file mode 120000 index 0000000..e9aff65 --- /dev/null +++ b/unit/inputs/simple_run_quick_input.h5 @@ -0,0 +1 @@ +../../supplementary/ascot5/simple_run_quick_input.h5 \ No newline at end of file diff --git a/unit/src/AscotProblemTest.C b/unit/src/AscotProblemTest.C index 956d4ed..7f3e4a1 100644 --- a/unit/src/AscotProblemTest.C +++ b/unit/src/AscotProblemTest.C @@ -18,18 +18,45 @@ using namespace H5; std::vector simple_run_walltile{ #include "../../../supplementary/ascot5/walltile.csv" }; +std::vector simple_run_quick_walltile{ +#include "../../../supplementary/ascot5/walltile_quick.csv" +}; std::vector simple_run_energy{ #include "../../../supplementary/ascot5/simple_run_energies.csv" }; std::vector simple_run_weight{ #include "../../../supplementary/ascot5/weight.csv" }; +std::vector simple_run_quick_weight{ +#include "../../../supplementary/ascot5/weight_quick.csv" +}; std::vector simple_run_hfluxes{ #include "../../../supplementary/ascot5/simple_run_heat_fluxes.csv" }; +std::vector simple_run_quick_vr{ +#include "../../../supplementary/ascot5/vr_quick.csv" +}; +std::vector simple_run_quick_vphi{ +#include "../../../supplementary/ascot5/vphi_quick.csv" +}; +std::vector simple_run_quick_vz{ +#include "../../../supplementary/ascot5/vz_quick.csv" +}; +std::unordered_map> simple_run_endstate_fp = { +#include "../../../supplementary/ascot5/simple_run_endstate_fp.txt" +}; +std::unordered_map> simple_run_endstate_int = { +#include "../../../supplementary/ascot5/simple_run_endstate_int.txt" +}; // Tests -TEST_F(AscotProblemHDF5Test, check_hdf5) +TEST(CheckMap, CheckMap) +{ + ASSERT_FLOAT_EQ(simple_run_endstate_fp["mass"][0], 4.0); + ASSERT_EQ(simple_run_endstate_int["anum"][3], 4); +} + +TEST_F(AscotProblemHDF5Test, CheckHDF5) { ASSERT_FALSE(appIsNull); @@ -52,7 +79,48 @@ TEST_F(AscotProblemHDF5Test, check_hdf5) ASSERT_EQ(active_result_num, "0069271660"); } -TEST_F(AscotProblemHDF5Test, read_walltile) +TEST_F(AscotProblemHDF5Test, getAscotH5Group) +{ + + ASSERT_FALSE(appIsNull); + const std::string group_name("options"); + // Check that the options group is present, then open it + ASSERT_TRUE(hdf5_file.nameExists(group_name)); + Group options_group = problemPtr->getAscotH5Group(hdf5_file, group_name); + + // Check that the group location is as expected + ASSERT_EQ(options_group.getObjName(), "/options/opt_3012694174"); + ASSERT_EQ(options_group.getNumObjs(), (long long unsigned int)79); +} + +TEST_F(AscotProblemHDF5Test, ReadEndstateInt) +{ + Group endstate_group = problemPtr->getActiveEndstate(hdf5_file); + std::unordered_map> endstate_data; + endstate_data = problemPtr->getAscotH5EndstateInt(endstate_group); + + for (auto && field : simple_run_endstate_int) + { + ASSERT_EQ(endstate_data[field.first], field.second); + } +} + +TEST_F(AscotProblemHDF5Test, ReadEndstateDouble) +{ + Group endstate_group = problemPtr->getActiveEndstate(hdf5_file); + std::unordered_map> endstate_data; + endstate_data = problemPtr->getAscotH5EndstateDouble(endstate_group); + + for (auto && field : simple_run_endstate_fp) + { + for (size_t i = 0; i < field.second.size(); i++) + { + ASSERT_FLOAT_EQ(endstate_data[field.first][i], field.second[i]); + } + } +} + +TEST_F(AscotProblemHDF5Test, ReadWalltile) { ASSERT_FALSE(appIsNull); @@ -61,7 +129,7 @@ TEST_F(AscotProblemHDF5Test, read_walltile) ASSERT_EQ(problemPtr->getWallTileHits(endstate_group), simple_run_walltile); } -TEST_F(AscotProblemHDF5Test, read_weights) +TEST_F(AscotProblemHDF5Test, ReadWeights) { ASSERT_FALSE(appIsNull); @@ -75,7 +143,7 @@ TEST_F(AscotProblemHDF5Test, read_weights) } } -TEST_F(AscotProblemHDF5Test, read_energy) +TEST_F(AscotProblemHDF5Test, ReadEnergy) { ASSERT_FALSE(appIsNull); @@ -89,7 +157,7 @@ TEST_F(AscotProblemHDF5Test, read_energy) } } -TEST_F(AscotProblemHDF5Test, calculate_relativistic_energy) +TEST_F(AscotProblemHDF5Test, CalculateRelativisticEnergy) { // velocity components (r, phi, z) in m/s std::vector velocity{6726950.87616652, -9727805.12233284, 5355264.46022884}; @@ -99,7 +167,7 @@ TEST_F(AscotProblemHDF5Test, calculate_relativistic_energy) ASSERT_DOUBLE_EQ(problemPtr->calculateRelativisticEnergy(mass, velocity), 5.605926430766929e-13); } -TEST_F(AscotProblemHDF5Test, calculate_heat_fluxes) +TEST_F(AscotProblemHDF5Test, CalculateHeatFluxes) { ASSERT_FALSE(appIsNull); @@ -107,7 +175,6 @@ TEST_F(AscotProblemHDF5Test, calculate_heat_fluxes) // check that the mesh is the expected size ASSERT_EQ(problemPtr->mesh().nElem(), (unsigned long int)400); - Group endstate_group = problemPtr->getActiveEndstate(hdf5_file); std::vector heat_fluxes = problemPtr->calculateHeatFluxes(simple_run_walltile, simple_run_energy, simple_run_weight); @@ -120,18 +187,7 @@ TEST_F(AscotProblemHDF5Test, calculate_heat_fluxes) } } -/* -TEST_F(AscotProblemHDF5Test, check_auxvariable) -{ - // It looks like I need to think more about the distributed nature of the - // AuxVariable and mesh. I need to sum over all of the threads and probably - // processes? - ASSERT_EQ(problemPtr->getAuxiliarySystem()., (unsigned int)400); -} -*/ - -// TODO need to get this test passing -TEST_F(AscotProblemHDF5Test, check_solution_sync) +TEST_F(AscotProblemHDF5Test, CheckSolutionSync) { ASSERT_FALSE(appIsNull); problemPtr->syncSolutions(ExternalProblem::Direction::FROM_EXTERNAL_APP); @@ -148,4 +204,84 @@ TEST_F(AscotProblemHDF5Test, check_solution_sync) dof_i = el->dof_number(auxvar_heat_fluxes.sys().number(), auxvar_heat_fluxes.number(), 0); ASSERT_NEAR(auxvar_heat_fluxes.sys().solution().el(dof_i), simple_run_hfluxes[id], tol); } -} \ No newline at end of file +} + +TEST_F(AscotProblemHDF5WriteTest, Endstate2Marker) +{ + + H5::H5File hdf5_file(hdf5_file_name, H5F_ACC_RDWR); + // set the test data in the class + problemPtr->endstate_data_double = simple_run_endstate_fp; + problemPtr->endstate_data_int = simple_run_endstate_int; + + // write the test data to the marker group + problemPtr->copyEndstate2MarkerGroup(hdf5_file); + hdf5_file.close(); + + // check newly written marker group against reference with `h5diff` + // TODO update h5diff arguments + int h5diff_result = + std::system(("h5diff -cvv " + hdf5_file_name + + " inputs/simple_run_endstate2markers.h5 marker/prt_1 marker/prt_0033994144") + .c_str()); + ASSERT_TRUE(h5diff_result); +} + +TEST_F(AscotProblemSimpleRunTest, ExectuteSimpleRun) +{ + ASSERT_NO_THROW(problemPtr->externalSolve()); +} + +TEST_F(AscotProblemSimpleRunTest, VerifySimpleRun) +{ + ASSERT_NO_THROW(problemPtr->externalSolve()); + + // Open open output file and relevant group + H5File ascot5_file(hdf5_file_name, H5F_ACC_RDONLY); + Group ascot5_active_endstate = problemPtr->getActiveEndstate(ascot5_file); + + // Get relevant output data for verification + std::vector walltile = problemPtr->getWallTileHits(ascot5_active_endstate); + std::vector weights = problemPtr->getMarkerWeights(ascot5_active_endstate); + + for (size_t i = 0; i < walltile.size(); i++) + { + ASSERT_EQ(walltile[i], simple_run_quick_walltile[i]); + ASSERT_DOUBLE_EQ(weights[i], simple_run_quick_weight[i]); + } + + // The velocities don't have their own read routine, so do some repetition of code here + // TODO this should be put into a class method of AscotProblem or a separate HDF5 wrapper class + std::unordered_map> velocities; + std::unordered_map> simple_quick_vel = { + {"vr", simple_run_quick_vr}, {"vphi", simple_run_quick_vphi}, {"vz", simple_run_quick_vz}}; + std::vector velocity_names{"vr", "vphi", "vz"}; + double_t tol; + + for (auto && name : velocity_names) + { + velocities[name].resize(100); + DataSet v_dataset = ascot5_active_endstate.openDataSet(name); + v_dataset.read(velocities[name].data(), PredType::NATIVE_DOUBLE); + + for (size_t i = 0; i < velocities[name].size(); i++) + { + tol = abs(simple_quick_vel[name][i] * 0.001); + ASSERT_NEAR(velocities[name][i], simple_quick_vel[name][i], tol); + } + } +} + +TEST_F(AscotProblemSimpleRunTest, CheckTimeStep) { ASSERT_FLOAT_EQ(1e-5, problemPtr->dt()); } + +TEST_F(AscotProblemSimpleRunTest, CheckTimeOptionSet) +{ + problemPtr->syncSolutions(ExternalProblem::Direction::TO_EXTERNAL_APP); + + H5File ascot5_file(hdf5_file_name, H5F_ACC_RDONLY); + Group options = problemPtr->getAscotH5Group(ascot5_file, "options"); + DataSet endcond_max_simtime = options.openDataSet("ENDCOND_MAX_SIMTIME"); + double_t set_time[1]; + endcond_max_simtime.read(set_time, PredType::NATIVE_DOUBLE); + ASSERT_FLOAT_EQ(set_time[0], 1e-5); +}