-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6284 from knelli2/strahlkorper_coords_txt_file
Add executable to write CCE worldtube coords to a file
- Loading branch information
Showing
29 changed files
with
496 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Executables/WriteCceWorldtubeCoordsToFile/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
79 changes: 79 additions & 0 deletions
79
src/Executables/WriteCceWorldtubeCoordsToFile/WriteCceWorldtubeCoordsToFile.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Distributed under the MIT License. | ||
// See LICENSE.txt for details. | ||
|
||
#include <array> | ||
#include <boost/program_options.hpp> | ||
#include <boost/program_options/value_semantic.hpp> | ||
#include <cstddef> | ||
#include <exception> | ||
#include <string> | ||
|
||
#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<double>()->required(), | ||
"Radius of the worltube.")( | ||
"lmax,L", boost::program_options::value<size_t>()->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<std::string>()->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<double>(); | ||
const size_t l_max = vars["lmax"].as<size_t>(); | ||
const std::array<double, 3> center{0.0, 0.0, 0.0}; | ||
const std::string output_file = vars["output_file"].as<std::string>(); | ||
const bool overwrite = vars["force"].as<bool>(); | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/NumericalAlgorithms/SphericalHarmonics/IO/StrahlkorperCoordsToTextFile.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Distributed under the MIT License. | ||
// See LICENSE.txt for details. | ||
|
||
#include "NumericalAlgorithms/SphericalHarmonics/IO/StrahlkorperCoordsToTextFile.hpp" | ||
|
||
#include <fstream> | ||
#include <iomanip> | ||
#include <limits> | ||
#include <ostream> | ||
#include <string> | ||
|
||
#include "DataStructures/DataVector.hpp" | ||
#include "DataStructures/Tensor/Tensor.hpp" | ||
#include "DataStructures/Transpose.hpp" | ||
#include "NumericalAlgorithms/SphericalHarmonics/AngularOrdering.hpp" | ||
#include "NumericalAlgorithms/SphericalHarmonics/Strahlkorper.hpp" | ||
#include "NumericalAlgorithms/SphericalHarmonics/StrahlkorperFunctions.hpp" | ||
#include "Utilities/ErrorHandling/Error.hpp" | ||
#include "Utilities/FileSystem.hpp" | ||
#include "Utilities/GenerateInstantiations.hpp" | ||
|
||
namespace Frame { | ||
struct Inertial; | ||
struct Distorted; | ||
struct Grid; | ||
} // namespace Frame | ||
|
||
namespace ylm { | ||
template <typename Frame> | ||
void write_strahlkorper_coords_to_text_file( | ||
const Strahlkorper<Frame>& strahlkorper, | ||
const std::string& output_file_name, const AngularOrdering ordering, | ||
const bool overwrite_file) { | ||
if (not overwrite_file and | ||
file_system::check_if_file_exists(output_file_name)) { | ||
ERROR_NO_TRACE("The output file " << output_file_name | ||
<< " already exists."); | ||
} | ||
|
||
tnsr::I<DataVector, 3, Frame> cartesian_coords = | ||
ylm::cartesian_coords(strahlkorper); | ||
|
||
// Cce expects coordinates in a different order than a typical Strahlkorper | ||
if (ordering == AngularOrdering::Cce) { | ||
const auto physical_extents = | ||
strahlkorper.ylm_spherepack().physical_extents(); | ||
auto transposed_coords = | ||
tnsr::I<DataVector, 3, Frame>(get<0>(cartesian_coords).size()); | ||
for (size_t i = 0; i < 3; ++i) { | ||
transpose(make_not_null(&transposed_coords.get(i)), | ||
cartesian_coords.get(i), physical_extents[0], | ||
physical_extents[1]); | ||
} | ||
|
||
cartesian_coords = std::move(transposed_coords); | ||
} | ||
|
||
std::ofstream output_file(output_file_name); | ||
output_file << std::fixed | ||
<< std::setprecision(std::numeric_limits<double>::digits10 + 4) | ||
<< std::scientific; | ||
|
||
const size_t num_points = get<0>(cartesian_coords).size(); | ||
for (size_t i = 0; i < num_points; i++) { | ||
output_file << get<0>(cartesian_coords)[i] << " " | ||
<< get<1>(cartesian_coords)[i] << " " | ||
<< get<2>(cartesian_coords)[i] << std::endl; | ||
} | ||
} | ||
|
||
void write_strahlkorper_coords_to_text_file(const double radius, | ||
const size_t l_max, | ||
const std::array<double, 3>& center, | ||
const std::string& output_file_name, | ||
const AngularOrdering ordering, | ||
const bool overwrite_file) { | ||
const Strahlkorper<Frame::Inertial> strahlkorper{l_max, radius, center}; | ||
write_strahlkorper_coords_to_text_file(strahlkorper, output_file_name, | ||
ordering, overwrite_file); | ||
} | ||
|
||
#define FRAME(data) BOOST_PP_TUPLE_ELEM(0, data) | ||
|
||
#define INSTANTIATE(_, data) \ | ||
template void write_strahlkorper_coords_to_text_file( \ | ||
const Strahlkorper<FRAME(data)>& strahlkorper, \ | ||
const std::string& output_file_name, const AngularOrdering ordering, \ | ||
const bool overwrite_file); | ||
|
||
GENERATE_INSTANTIATIONS(INSTANTIATE, | ||
(Frame::Grid, Frame::Distorted, Frame::Inertial)) | ||
|
||
#undef INSTANTIATE | ||
#undef FRAME | ||
} // namespace ylm |
49 changes: 49 additions & 0 deletions
49
src/NumericalAlgorithms/SphericalHarmonics/IO/StrahlkorperCoordsToTextFile.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Distributed under the MIT License. | ||
// See LICENSE.txt for details. | ||
|
||
#pragma once | ||
|
||
#include <array> | ||
#include <cstddef> | ||
#include <string> | ||
|
||
#include "NumericalAlgorithms/SphericalHarmonics/AngularOrdering.hpp" | ||
#include "NumericalAlgorithms/SphericalHarmonics/Strahlkorper.hpp" | ||
|
||
namespace ylm { | ||
/// @{ | ||
/*! | ||
* \brief Writes the collocation points of a `ylm::Strahlkorper` to an output | ||
* text file. | ||
* | ||
* \details The ordering of the points can be either the typical | ||
* `ylm::Spherepack` ordering or CCE ordering that works with libsharp. Also, an | ||
* error will occur if the output file already exists, but the output file can | ||
* be overwritten with the \p overwrite_file option. | ||
* | ||
* The second overload will construct a spherical `ylm::Strahlkorper` with the | ||
* given \p radius, \p l_max, and \p center. | ||
* | ||
* The output file format will be as follows with no comment or header lines, | ||
* a space as the delimiter, and decimals written in scientific notation: | ||
* | ||
* ``` | ||
* x0 y0 z0 | ||
* x1 y1 z1 | ||
* x2 y2 z2 | ||
* ... | ||
* ``` | ||
*/ | ||
template <typename Frame> | ||
void write_strahlkorper_coords_to_text_file( | ||
const Strahlkorper<Frame>& strahlkorper, | ||
const std::string& output_file_name, AngularOrdering ordering, | ||
bool overwrite_file = false); | ||
|
||
void write_strahlkorper_coords_to_text_file(double radius, size_t l_max, | ||
const std::array<double, 3>& center, | ||
const std::string& output_file_name, | ||
AngularOrdering ordering, | ||
bool overwrite_file = false); | ||
/// @} | ||
} // namespace ylm |
Oops, something went wrong.