From 2ee9eb8a080a2016f866c459423bbbd8ae37d14b Mon Sep 17 00:00:00 2001 From: Kyle Nelli Date: Thu, 27 Jun 2024 16:08:47 -0700 Subject: [PATCH] Add FromVolumeFile to ShapeMapOptions --- .../TimeDependentOptions/ShapeMap.cpp | 9 +++ .../TimeDependentOptions/ShapeMap.hpp | 7 ++- .../TimeDependentOptions/Test_ShapeMap.cpp | 62 +++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/Domain/Creators/TimeDependentOptions/ShapeMap.cpp b/src/Domain/Creators/TimeDependentOptions/ShapeMap.cpp index 7d1a7f7884c59..c2d684463ce78 100644 --- a/src/Domain/Creators/TimeDependentOptions/ShapeMap.cpp +++ b/src/Domain/Creators/TimeDependentOptions/ShapeMap.cpp @@ -16,6 +16,7 @@ #include "DataStructures/ModalVector.hpp" #include "DataStructures/Tensor/Tensor.hpp" #include "Domain/Structure/ObjectLabel.hpp" +#include "FromVolumeFile.hpp" #include "NumericalAlgorithms/SphericalHarmonics/Spherepack.hpp" #include "NumericalAlgorithms/SphericalHarmonics/SpherepackIterator.hpp" #include "NumericalAlgorithms/SphericalHarmonics/Strahlkorper.hpp" @@ -186,6 +187,14 @@ initial_shape_and_size_funcs( shape_funcs[0][iter.set(1_st, m)()] = 0.0; } } + } else if (std::holds_alternative>>( + shape_options.initial_values.value())) { + const auto& volume_file_options = + std::get>>( + shape_options.initial_values.value()); + + shape_funcs = volume_file_options.shape_values; + size_funcs = volume_file_options.size_values; } } diff --git a/src/Domain/Creators/TimeDependentOptions/ShapeMap.hpp b/src/Domain/Creators/TimeDependentOptions/ShapeMap.hpp index 53786f07e38f0..be155014ff8b4 100644 --- a/src/Domain/Creators/TimeDependentOptions/ShapeMap.hpp +++ b/src/Domain/Creators/TimeDependentOptions/ShapeMap.hpp @@ -11,6 +11,7 @@ #include #include "DataStructures/DataVector.hpp" +#include "Domain/Creators/TimeDependentOptions/FromVolumeFile.hpp" #include "Domain/Structure/ObjectLabel.hpp" #include "NumericalAlgorithms/SphericalHarmonics/IO/ReadSurfaceYlm.hpp" #include "NumericalAlgorithms/SphericalHarmonics/Strahlkorper.hpp" @@ -191,7 +192,8 @@ struct ShapeMapOptions { struct InitialValues { using type = Options::Auto< - std::variant, + std::variant>>, Spherical>; static constexpr Options::String help = { "Initial Ylm coefficients for the shape map. Specify 'Spherical' for " @@ -223,7 +225,8 @@ struct ShapeMapOptions { size_t l_max{}; std::optional< - std::variant> + std::variant>>> initial_values{}; std::optional> initial_size_values{}; bool transition_ends_at_cube{false}; diff --git a/tests/Unit/Domain/Creators/TimeDependentOptions/Test_ShapeMap.cpp b/tests/Unit/Domain/Creators/TimeDependentOptions/Test_ShapeMap.cpp index fa883cd8fe81f..613f12e219e26 100644 --- a/tests/Unit/Domain/Creators/TimeDependentOptions/Test_ShapeMap.cpp +++ b/tests/Unit/Domain/Creators/TimeDependentOptions/Test_ShapeMap.cpp @@ -8,11 +8,16 @@ #include #include #include +#include #include #include +#include #include #include "Domain/Creators/TimeDependentOptions/ShapeMap.hpp" +#include "Domain/FunctionsOfTime/FunctionOfTime.hpp" +#include "Domain/FunctionsOfTime/PiecewisePolynomial.hpp" +#include "Domain/FunctionsOfTime/RegisterDerivedWithCharm.hpp" #include "Domain/Structure/ObjectLabel.hpp" #include "Framework/TestCreation.hpp" #include "Framework/TestHelpers.hpp" @@ -20,6 +25,8 @@ #include "IO/H5/AccessType.hpp" #include "IO/H5/Dat.hpp" #include "IO/H5/File.hpp" +#include "IO/H5/TensorData.hpp" +#include "IO/H5/VolumeData.hpp" #include "NumericalAlgorithms/SphericalHarmonics/IO/FillYlmLegendAndData.hpp" #include "NumericalAlgorithms/SphericalHarmonics/Spherepack.hpp" #include "NumericalAlgorithms/SphericalHarmonics/SpherepackIterator.hpp" @@ -206,6 +213,7 @@ void test_funcs(const gsl::not_null generator) { file_system::rm(test_filename, true); } const std::vector subfile_names{"Ylm_coefs", "dt_Ylm_coefs"}; + const std::string volume_subfile_name{"VolumeData"}; const double time = 1.7; // Purposefully larger than the LMax in the options so that the // Strahlkorpers will be restricted @@ -245,6 +253,12 @@ void test_funcs(const gsl::not_null generator) { } } + // Take advantage of the funcs and write those to the volume file + const std::string shape_name{"ShapeB"}; + const std::string size_name{"SizeB"}; + std::unordered_map> + functions_of_time{}; { const auto shape_map_options = TestHelpers::test_creation< domain::creators::time_dependent_options::ShapeMapOptions< @@ -288,6 +302,53 @@ void test_funcs(const gsl::not_null generator) { } CHECK(size_funcs == std::array{DataVector{1.1}, DataVector{2.2}, DataVector{3.3}, DataVector{0.0}}); + + functions_of_time[shape_name] = + std::make_unique>( + time, shape_funcs, 100.0); + functions_of_time[size_name] = + std::make_unique>( + time, size_funcs, 100.0); + { + h5::H5File test_file(test_filename, true); + auto& vol_file = test_file.insert(volume_subfile_name); + + // We don't care about the volume data here, just the functions of time + vol_file.write_volume_data( + 0, 0.0, + {ElementVolumeData{ + "blah", + {TensorComponent{"RandomTensor", DataVector{3, 0.0}}}, + {3}, + {Spectral::Basis::Legendre}, + {Spectral::Quadrature::GaussLobatto}}}, + std::nullopt, serialize(functions_of_time)); + } + } + + { + const auto shape_map_options = TestHelpers::test_creation< + domain::creators::time_dependent_options::ShapeMapOptions< + false, domain::ObjectLabel::B>>( + "LMax: 8\n" + "InitialValues:\n" + " H5Filename: TotalEclipseOfTheHeart.h5\n" + " SubfileName: VolumeData\n" + " Time: 1.7\n" + "SizeInitialValues: Auto"); + + const auto [shape_funcs, size_funcs] = + domain::creators::time_dependent_options:: + initial_shape_and_size_funcs(shape_map_options, inner_radius); + + CHECK(shape_funcs == + functions_of_time.at(shape_name)->func_and_2_derivs(time)); + auto all_size_funcs = + functions_of_time.at(size_name)->func_and_all_derivs(time); + CHECK(all_size_funcs.size() == size_funcs.size()); + for (size_t i = 0; i < size_funcs.size(); i++) { + CHECK(all_size_funcs[i] == gsl::at(size_funcs, i)); + } } // Already checked that shape funcs are correct. Here just check that size @@ -443,6 +504,7 @@ void test_funcs(const gsl::not_null generator) { SPECTRE_TEST_CASE("Unit.Domain.Creators.TimeDependentOptions.ShapeMap", "[Domain][Unit]") { + domain::FunctionsOfTime::register_derived_with_charm(); MAKE_GENERATOR(generator); test_kerr_schild_boyer_lindquist(); test_ylms_from_file();