|
| 1 | +#ifndef AMREX_OPENBC_H_ |
| 2 | +#define AMREX_OPENBC_H_ |
| 3 | +#include <AMReX_Config.H> |
| 4 | + |
| 5 | +#include <AMReX_MLMG.H> |
| 6 | +#include <AMReX_MLPoisson.H> |
| 7 | + |
| 8 | +namespace amrex |
| 9 | +{ |
| 10 | + |
| 11 | +namespace openbc { |
| 12 | + |
| 13 | + static constexpr int M = 7; // highest order of moments |
| 14 | + static constexpr int P = 3; |
| 15 | + |
| 16 | + struct Moments |
| 17 | + { |
| 18 | + typedef GpuArray<Real,(M+2)*(M+1)/2> array_type; |
| 19 | + array_type mom; |
| 20 | + Real x, y, z; |
| 21 | + Orientation face; |
| 22 | + }; |
| 23 | + |
| 24 | + struct MomTag |
| 25 | + { |
| 26 | + Array4<Real const> gp; |
| 27 | + Box b2d; |
| 28 | + Orientation face; |
| 29 | + int offset; |
| 30 | + }; |
| 31 | + |
| 32 | + std::ostream& operator<< (std::ostream& os, Moments const& mom); |
| 33 | +} |
| 34 | + |
| 35 | +#if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP) |
| 36 | +template<> |
| 37 | +struct Gpu::SharedMemory<openbc::Moments::array_type> |
| 38 | +{ |
| 39 | + AMREX_GPU_DEVICE openbc::Moments::array_type* dataPtr () noexcept { |
| 40 | + AMREX_HIP_OR_CUDA(HIP_DYNAMIC_SHARED(openbc::Moments::array_type,amrex_openbc_momarray);, |
| 41 | + extern __shared__ openbc::Moments::array_type amrex_openbc_momarray[];) |
| 42 | + return amrex_openbc_momarray; |
| 43 | + } |
| 44 | +}; |
| 45 | +#endif |
| 46 | + |
| 47 | +/** |
| 48 | + * \brief Open Boundary Poisson Solver |
| 49 | + * |
| 50 | + * References: |
| 51 | + * (1) The Solution of Poisson's Equation for Isolated Source |
| 52 | + * Distributions, R. A. James, 1977, JCP 25, 71 |
| 53 | + * (2) A Local Corrections Algorithm for Solving Poisson's Equation in Three |
| 54 | + * Dimensions, P. McCorquodale, P. Colella, G. T. Balls, & S. B. Baden, |
| 55 | + * 2007, Communications in Applied Mathematics and Computational Science, |
| 56 | + * 2, 1, 57-81 |
| 57 | + */ |
| 58 | +class OpenBCSolver |
| 59 | +{ |
| 60 | +public: |
| 61 | + OpenBCSolver (); |
| 62 | + |
| 63 | + OpenBCSolver (const Vector<Geometry>& a_geom, |
| 64 | + const Vector<BoxArray>& a_grids, |
| 65 | + const Vector<DistributionMapping>& a_dmap, |
| 66 | + const LPInfo& a_info = LPInfo()); |
| 67 | + |
| 68 | + ~OpenBCSolver (); |
| 69 | + |
| 70 | + OpenBCSolver (const OpenBCSolver&) = delete; |
| 71 | + OpenBCSolver (OpenBCSolver&&) = delete; |
| 72 | + OpenBCSolver& operator= (const OpenBCSolver&) = delete; |
| 73 | + OpenBCSolver& operator= (OpenBCSolver&&) = delete; |
| 74 | + |
| 75 | + void define (const Vector<Geometry>& a_geom, |
| 76 | + const Vector<BoxArray>& a_grids, |
| 77 | + const Vector<DistributionMapping>& a_dmap, |
| 78 | + const LPInfo& a_info = LPInfo()); |
| 79 | + |
| 80 | + void setVerbose (int v) noexcept; |
| 81 | + |
| 82 | + Real solve (const Vector<MultiFab*>& a_sol, const Vector<MultiFab const*>& a_rhs, |
| 83 | + Real a_tol_rel, Real a_tol_abs); |
| 84 | + |
| 85 | +public: // public for cuda |
| 86 | + |
| 87 | + void compute_moments (Gpu::DeviceVector<openbc::Moments>& moments); |
| 88 | + void compute_potential (Gpu::DeviceVector<openbc::Moments> const& moments); |
| 89 | + void interpolate_potential (MultiFab& solg); |
| 90 | + |
| 91 | +private: |
| 92 | + |
| 93 | +#ifdef AMREX_USE_MPI |
| 94 | + void bcast_moments (Gpu::DeviceVector<openbc::Moments>& moments); |
| 95 | +#endif |
| 96 | + |
| 97 | + int m_verbose = 0; |
| 98 | + Vector<Geometry> m_geom; |
| 99 | + Vector<BoxArray> m_grids; |
| 100 | + Vector<DistributionMapping> m_dmap; |
| 101 | + LPInfo m_info; |
| 102 | + std::unique_ptr<MLPoisson> m_poisson_1; |
| 103 | + std::unique_ptr<MLPoisson> m_poisson_2; |
| 104 | + std::unique_ptr<MLMG> m_mlmg_1; |
| 105 | + std::unique_ptr<MLMG> m_mlmg_2; |
| 106 | + |
| 107 | + int m_coarsen_ratio = 0; |
| 108 | + Array<MultiFab,AMREX_SPACEDIM> m_dpdn; |
| 109 | + Gpu::PinnedVector<openbc::MomTag> m_momtags_h; |
| 110 | +#ifdef AMREX_USE_GPU |
| 111 | + Gpu::DeviceVector<openbc::MomTag> m_momtags_d; |
| 112 | + Gpu::PinnedVector<int> m_ngpublocks_h; |
| 113 | + Gpu::DeviceVector<int> m_ngpublocks_d; |
| 114 | + int m_nthreads_momtag; |
| 115 | +#endif |
| 116 | + |
| 117 | + int m_nblocks_local = 0; |
| 118 | + int m_nblocks = 0; |
| 119 | +#ifdef AMREX_USE_MPI |
| 120 | + Vector<int> m_countvec; |
| 121 | + Vector<int> m_offset; |
| 122 | +#endif |
| 123 | + |
| 124 | + IntVect m_ngrowdomain; |
| 125 | + MultiFab m_crse_grown_faces_phi; |
| 126 | + MultiFab m_phind; |
| 127 | + BoxArray m_bag; |
| 128 | + |
| 129 | + BoxArray m_ba_all; |
| 130 | + DistributionMapping m_dm_all; |
| 131 | + Geometry m_geom_all; |
| 132 | +}; |
| 133 | + |
| 134 | +} |
| 135 | + |
| 136 | +#endif |
0 commit comments