YlmSpherepackHelper.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <cstddef>
8 #include <vector>
9 
10 #include "Utilities/Gsl.hpp"
11 
12 namespace YlmSpherepack_detail {
13 
14 /// Holds the various 'work' arrays for YlmSpherepack.
15 struct Storage {
16  std::vector<double> work_phys_to_spec;
17  std::vector<double> work_scalar_spec_to_phys;
18  std::vector<double> work_vector_spec_to_phys;
19  std::vector<double> theta, phi, sin_theta, cos_theta;
20  std::vector<double> cos_phi, sin_phi, cosec_theta, cot_theta;
22  std::vector<double> work_interp_alpha;
23  std::vector<double> work_interp_beta;
24  std::vector<double> work_interp_pmm;
25  std::vector<size_t> work_interp_index;
26 };
27 
28 /// This is a quick way of providing temporary space that is
29 /// re-utilized many times without the expense of mallocs. This
30 /// turned out to be important for optimizing SpEC (because
31 /// YlmSpherepack is used for the basis functions in the most
32 /// expensive subdomains) but may or may not be important for SpECTRE.
33 class MemoryPool {
34  public:
35  MemoryPool() = default;
36  std::vector<double>& get(size_t n_pts) noexcept;
37  void free(const std::vector<double>& to_be_freed) noexcept;
38  void free(gsl::not_null<double*> to_be_freed) noexcept;
39 
40  private:
41  struct StorageAndAvailability {
42  std::vector<double> storage;
43  bool currently_in_use{false};
44  };
45  // It turns out that the maximum number of temporaries needed in a
46  // single YlmSpherepack calculation is 9.
47  static const constexpr size_t num_temps_ = 9;
49 };
50 } // namespace YlmSpherepack_detail
T free(T... args)
Definition: YlmSpherepackHelper.cpp:9
tnsr::iaa< DataType, SpatialDim, Frame > phi(const Scalar< DataType > &lapse, const tnsr::i< DataType, SpatialDim, Frame > &deriv_lapse, const tnsr::I< DataType, SpatialDim, Frame > &shift, const tnsr::iJ< DataType, SpatialDim, Frame > &deriv_shift, const tnsr::ii< DataType, SpatialDim, Frame > &spatial_metric, const tnsr::ijj< DataType, SpatialDim, Frame > &deriv_spatial_metric) noexcept
Computes the auxiliary variable used by the generalized harmonic formulation of Einstein&#39;s equations...
Definition: ComputeGhQuantities.cpp:22
Defines functions and classes from the GSL.
const DataVector & quadrature_weights(const Mesh< 1 > &mesh) noexcept
Quadrature weights for a one-dimensional mesh.
Require a pointer to not be a nullptr
Definition: ConservativeFromPrimitive.hpp:12