From 49a39c567ae834d3a99ba93a55f564ce4c2b4af5 Mon Sep 17 00:00:00 2001 From: Kyle Nelli Date: Wed, 11 Sep 2024 16:37:28 -0700 Subject: [PATCH] Add executable to write CCE worldtube coords to a file --- src/Executables/CMakeLists.txt | 1 + .../CMakeLists.txt | 24 ++++++ .../WriteCceWorldtubeCoordsToFile.cpp | 79 +++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 src/Executables/WriteCceWorldtubeCoordsToFile/CMakeLists.txt create mode 100644 src/Executables/WriteCceWorldtubeCoordsToFile/WriteCceWorldtubeCoordsToFile.cpp diff --git a/src/Executables/CMakeLists.txt b/src/Executables/CMakeLists.txt index c9595dfc0839..d7cfdbdfd98c 100644 --- a/src/Executables/CMakeLists.txt +++ b/src/Executables/CMakeLists.txt @@ -10,3 +10,4 @@ add_subdirectory(ExportCoordinates) add_subdirectory(ParallelInfo) add_subdirectory(ReduceCceWorldtube) add_subdirectory(TimeStepperSummary) +add_subdirectory(WriteCceWorldtubeCoordsToFile) diff --git a/src/Executables/WriteCceWorldtubeCoordsToFile/CMakeLists.txt b/src/Executables/WriteCceWorldtubeCoordsToFile/CMakeLists.txt new file mode 100644 index 000000000000..33c49662dcc2 --- /dev/null +++ b/src/Executables/WriteCceWorldtubeCoordsToFile/CMakeLists.txt @@ -0,0 +1,24 @@ +# Distributed under the MIT License. +# See LICENSE.txt for details. + +set(EXECUTABLE WriteCceWorldtubeCoordsToFile) + +add_spectre_executable( + ${EXECUTABLE} + EXCLUDE_FROM_ALL + WriteCceWorldtubeCoordsToFile.cpp + ) + +target_link_libraries( + ${EXECUTABLE} + PRIVATE + Boost::boost + Boost::program_options + Printf + SphericalHarmonics + SphericalHarmonicsIO + ) + +if(BUILD_TESTING) + add_dependencies(test-executables ${EXECUTABLE}) +endif() diff --git a/src/Executables/WriteCceWorldtubeCoordsToFile/WriteCceWorldtubeCoordsToFile.cpp b/src/Executables/WriteCceWorldtubeCoordsToFile/WriteCceWorldtubeCoordsToFile.cpp new file mode 100644 index 000000000000..3cd327f3193f --- /dev/null +++ b/src/Executables/WriteCceWorldtubeCoordsToFile/WriteCceWorldtubeCoordsToFile.cpp @@ -0,0 +1,79 @@ +// Distributed under the MIT License. +// See LICENSE.txt for details. + +#include +#include +#include +#include +#include +#include + +#include "NumericalAlgorithms/SphericalHarmonics/AngularOrdering.hpp" +#include "NumericalAlgorithms/SphericalHarmonics/IO/StrahlkorperCoordsToTextFile.hpp" +#include "Parallel/Printf/Printf.hpp" + +// Charm looks for this function but since we build without a main function or +// main module we just have it be empty +extern "C" void CkRegisterMainModule(void) {} + +/* + * This executable is used for writing the collocation points of a CCE + * Strahlkorper to a text file. This is useful for other NR codes so they can + * write data to certain points and we do the necessary transformations. + */ +int main(int argc, char** argv) { + boost::program_options::options_description desc( + "Program for writing the collocation points (coordinates) of a worldtube " + "sphere that SpECTRE CCE is able to read and interpret to a " + "file.\nDetails about the output file:\n" + " * There are no header or comment lines\n" + " * Each point is written to a new line of the output file\n" + " * The delimiter for the x, y, z components of each point is a space\n" + " * The points are written in scientific notation\n" + " * The sphere is centered on the origin (0, 0, 0)"); + desc.add_options()("help,h", "show this help message")( + "radius,r", boost::program_options::value()->required(), + "Radius of the worltube.")( + "lmax,L", boost::program_options::value()->required(), + "The spherical harmonic L of the surface. The surface will have (L + 1) " + "* (2L + 1) total points")( + "output_file,o", boost::program_options::value()->required(), + "Output filename for the points. No extension will be added.")( + "force,f", boost::program_options::bool_switch(), + "Overwrite the output file if it already exists"); + + boost::program_options::variables_map vars; + + boost::program_options::store( + boost::program_options::command_line_parser(argc, argv) + .options(desc) + .run(), + vars); + + if (vars.contains("help")) { + Parallel::printf("%s\n", desc); + return 0; + } + + for (const auto& option : {"radius", "lmax", "output_file"}) { + if (not vars.contains(option)) { + Parallel::printf("Missing option: %s\n\n%s", option, desc); + return 1; + } + } + + const double radius = vars["radius"].as(); + const size_t l_max = vars["lmax"].as(); + const std::array center{0.0, 0.0, 0.0}; + const std::string output_file = vars["output_file"].as(); + const bool overwrite = vars["force"].as(); + + try { + ylm::write_strahlkorper_coords_to_text_file( + radius, l_max, center, output_file, ylm::AngularOrdering::Cce, + overwrite); + } catch (const std::exception& exception) { + Parallel::printf("%s\n", exception.what()); + return 1; + } +}