Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <Exporter.hpp> // The SpEC Exporter 7 : #include <memory> 8 : 9 : #include "Options/String.hpp" 10 : #include "PointwiseFunctions/AnalyticData/AnalyticData.hpp" 11 : #include "PointwiseFunctions/AnalyticData/GeneralRelativity/AnalyticData.hpp" 12 : #include "PointwiseFunctions/GeneralRelativity/Tags.hpp" 13 : #include "PointwiseFunctions/InitialDataUtilities/InitialData.hpp" 14 : #include "Utilities/Serialization/CharmPupable.hpp" 15 : #include "Utilities/TMPL.hpp" 16 : #include "Utilities/TaggedTuple.hpp" 17 : 18 : /// \cond 19 : namespace PUP { 20 : class er; 21 : } // namespace PUP 22 : /// \endcond 23 : 24 : namespace gr::AnalyticData { 25 : 26 : /*! 27 : * \brief Vacuum initial data generated by SpEC. 28 : * 29 : * This class loads numerical data written out by the SpEC initial data solver. 30 : * It uses the `spec::Exporter` linked in from SpEC to interpolate to arbitrary 31 : * grid points. The coordinates are assumed to be in SpEC's "grid" frame. 32 : * We interpolate the following quantities: 33 : * 34 : * - "Nid_g": spatial metric 35 : * - "Nid_K": (lower) extrinsic curvature 36 : * - "Nid_N": lapse 37 : * - "Nid_Shift": (upper) shift 38 : */ 39 1 : class SpecInitialData : public evolution::initial_data::InitialData, 40 : public MarkAsAnalyticData, 41 : public AnalyticDataBase<3> { 42 : public: 43 : template <typename DataType> 44 0 : using tags = 45 : tmpl::list<gr::Tags::SpatialMetric<DataType, 3>, 46 : gr::Tags::ExtrinsicCurvature<DataType, 3>, 47 : gr::Tags::Lapse<DataType>, 48 : gr::Tags::Shift<DataType, 3>>; 49 : 50 0 : struct DataDirectory { 51 0 : using type = std::string; 52 0 : static constexpr Options::String help = { 53 : "Path to a directory of data produced by SpEC. The directory is " 54 : "expected to contain 'GrDomain.input' and 'Vars*.h5' files for all the " 55 : "subdomains in GrDomain.input."}; 56 : }; 57 : 58 0 : using options = tmpl::list<DataDirectory>; 59 : 60 0 : static constexpr Options::String help = {"Initial data generated by SpEC"}; 61 : 62 0 : SpecInitialData() = default; 63 0 : SpecInitialData(const SpecInitialData& rhs); 64 0 : SpecInitialData& operator=(const SpecInitialData& rhs); 65 0 : SpecInitialData(SpecInitialData&& /*rhs*/) = default; 66 0 : SpecInitialData& operator=(SpecInitialData&& /*rhs*/) = default; 67 0 : ~SpecInitialData() = default; 68 : 69 0 : SpecInitialData(std::string data_directory); 70 : 71 0 : auto get_clone() const 72 : -> std::unique_ptr<evolution::initial_data::InitialData> override; 73 : 74 : /// \cond 75 : explicit SpecInitialData(CkMigrateMessage* msg); 76 : using PUP::able::register_constructor; 77 : WRAPPED_PUPable_decl_template(SpecInitialData); 78 : /// \endcond 79 : 80 : template <typename DataType, typename... Tags> 81 0 : tuples::TaggedTuple<Tags...> variables(const tnsr::I<DataType, 3>& x, 82 : tmpl::list<Tags...> /*meta*/) const { 83 : auto interpolated_vars = interpolate_from_spec(x); 84 : return {std::move(get<Tags>(interpolated_vars))...}; 85 : } 86 : 87 : // NOLINTNEXTLINE(google-runtime-references) 88 0 : void pup(PUP::er& /*p*/) override; 89 : 90 : private: 91 : /// These quantities are supported for interpolation from SpEC 92 : template <typename DataType> 93 1 : using interpolated_tags = 94 : tmpl::list<gr::Tags::SpatialMetric<DataType, 3>, 95 : gr::Tags::ExtrinsicCurvature<DataType, 3>, 96 : gr::Tags::Lapse<DataType>, 97 : gr::Tags::Shift<DataType, 3>>; 98 : 99 : /// These are the names in SpEC datasets corresponding to the quantities above 100 1 : static const inline std::vector<std::string> vars_to_interpolate_{ 101 : "Nid_g", "Nid_K", "Nid_N", "Nid_Shift"}; 102 : 103 : template <typename DataType> 104 : tuples::tagged_tuple_from_typelist<interpolated_tags<DataType>> 105 0 : interpolate_from_spec(const tnsr::I<DataType, 3>& x) const; 106 : 107 0 : std::string data_directory_{}; 108 : 109 0 : std::unique_ptr<spec::Exporter> spec_exporter_{nullptr}; 110 : }; 111 : 112 : } // namespace gr::AnalyticData