From c99cba2405f6748c0934551f064b8dac8053384b Mon Sep 17 00:00:00 2001 From: Marc Henry de Frahan Date: Fri, 20 Sep 2024 11:40:11 -0600 Subject: [PATCH] new class method for boxes, use it --- amr-wind/utilities/sampling/FreeSurfaceSampler.H | 6 ++++++ amr-wind/utilities/sampling/FreeSurfaceSampler.cpp | 14 +++++++++++++- amr-wind/utilities/sampling/LineSampler.H | 5 +++++ amr-wind/utilities/sampling/LineSampler.cpp | 14 ++++++++++++-- amr-wind/utilities/sampling/PlaneSampler.H | 5 +++++ amr-wind/utilities/sampling/PlaneSampler.cpp | 14 ++++++++++++-- amr-wind/utilities/sampling/ProbeSampler.H | 6 ++++++ amr-wind/utilities/sampling/ProbeSampler.cpp | 14 +++++++++++++- amr-wind/utilities/sampling/RadarSampler.H | 6 ++++++ amr-wind/utilities/sampling/RadarSampler.cpp | 13 ++++++++++++- amr-wind/utilities/sampling/SamplerBase.H | 5 +++++ amr-wind/utilities/sampling/VolumeSampler.H | 5 +++++ amr-wind/utilities/sampling/VolumeSampler.cpp | 13 ++++++++++++- 13 files changed, 112 insertions(+), 8 deletions(-) diff --git a/amr-wind/utilities/sampling/FreeSurfaceSampler.H b/amr-wind/utilities/sampling/FreeSurfaceSampler.H index c300727a1e..003df63b03 100644 --- a/amr-wind/utilities/sampling/FreeSurfaceSampler.H +++ b/amr-wind/utilities/sampling/FreeSurfaceSampler.H @@ -24,6 +24,12 @@ public: //! Populate and return a vector of probe locations to be sampled void sampling_locations(SampleLocType& /*sample_locs**/) const override; + + //! Populate the vector with coordinates of the sampling locations inside + //! boxes + void sampling_locations( + SampleLocType&, const amrex::Vector&) const override; + void output_locations(SampleLocType& sample_locs) const override { return sampling_locations(sample_locs); diff --git a/amr-wind/utilities/sampling/FreeSurfaceSampler.cpp b/amr-wind/utilities/sampling/FreeSurfaceSampler.cpp index 45dd2465ae..5699a91c68 100644 --- a/amr-wind/utilities/sampling/FreeSurfaceSampler.cpp +++ b/amr-wind/utilities/sampling/FreeSurfaceSampler.cpp @@ -368,6 +368,19 @@ void FreeSurfaceSampler::check_bounds() void FreeSurfaceSampler::sampling_locations(SampleLocType& sample_locs) const { AMREX_ALWAYS_ASSERT(sample_locs.locations().empty()); + + const int lev = 0; + const auto domain = m_sim.mesh().Geom(lev).Domain(); + sampling_locations(sample_locs, {domain}); + + AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points()); +} + +void FreeSurfaceSampler::sampling_locations( + SampleLocType& sample_locs, const amrex::Vector& boxes) const +{ + AMREX_ALWAYS_ASSERT(sample_locs.locations().empty()); + int idx = 0; for (int j = 0; j < m_npts_dir[1]; ++j) { for (int i = 0; i < m_npts_dir[0]; ++i) { @@ -381,7 +394,6 @@ void FreeSurfaceSampler::sampling_locations(SampleLocType& sample_locs) const ++idx; } } - AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points()); } bool FreeSurfaceSampler::update_sampling_locations() diff --git a/amr-wind/utilities/sampling/LineSampler.H b/amr-wind/utilities/sampling/LineSampler.H index 6995e8c959..e0ad2c5cb2 100644 --- a/amr-wind/utilities/sampling/LineSampler.H +++ b/amr-wind/utilities/sampling/LineSampler.H @@ -33,6 +33,11 @@ public: //! Populate and return a vector of probe locations to be sampled void sampling_locations(SampleLocType& /*sample_locs**/) const override; + //! Populate the vector with coordinates of the sampling locations inside + //! boxes + void sampling_locations( + SampleLocType&, const amrex::Vector&) const override; + void output_locations(SampleLocType& sample_locs) const override { return sampling_locations(sample_locs); diff --git a/amr-wind/utilities/sampling/LineSampler.cpp b/amr-wind/utilities/sampling/LineSampler.cpp index a134c9fc2b..9af12a2384 100644 --- a/amr-wind/utilities/sampling/LineSampler.cpp +++ b/amr-wind/utilities/sampling/LineSampler.cpp @@ -57,6 +57,18 @@ void LineSampler::sampling_locations(SampleLocType& sample_locs) const { AMREX_ALWAYS_ASSERT(sample_locs.locations().empty()); + const int lev = 0; + const auto domain = m_sim.mesh().Geom(lev).Domain(); + sampling_locations(sample_locs, {domain}); + + AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points()); +} + +void LineSampler::sampling_locations( + SampleLocType& sample_locs, const amrex::Vector& boxes) const +{ + AMREX_ALWAYS_ASSERT(sample_locs.locations().empty()); + const amrex::Real ndiv = amrex::max(m_npts - 1, 1); amrex::Array dx; @@ -70,8 +82,6 @@ void LineSampler::sampling_locations(SampleLocType& sample_locs) const m_start[2] + i * dx[2])}; sample_locs.push_back(loc, i); } - - AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points()); } #ifdef AMR_WIND_USE_NETCDF diff --git a/amr-wind/utilities/sampling/PlaneSampler.H b/amr-wind/utilities/sampling/PlaneSampler.H index f723c3d09a..9d1b9aa63d 100644 --- a/amr-wind/utilities/sampling/PlaneSampler.H +++ b/amr-wind/utilities/sampling/PlaneSampler.H @@ -44,6 +44,11 @@ public: //! Populate and return a vector of probe locations to be sampled void sampling_locations(SampleLocType& /*sample_locs**/) const override; + //! Populate the vector with coordinates of the sampling locations inside + //! boxes + void sampling_locations( + SampleLocType&, const amrex::Vector&) const override; + void output_locations(SampleLocType& sample_locs) const override { return sampling_locations(sample_locs); diff --git a/amr-wind/utilities/sampling/PlaneSampler.cpp b/amr-wind/utilities/sampling/PlaneSampler.cpp index 1d86a51b30..a3444bd2bf 100644 --- a/amr-wind/utilities/sampling/PlaneSampler.cpp +++ b/amr-wind/utilities/sampling/PlaneSampler.cpp @@ -79,6 +79,18 @@ void PlaneSampler::sampling_locations(SampleLocType& sample_locs) const { AMREX_ALWAYS_ASSERT(sample_locs.locations().empty()); + const int lev = 0; + const auto domain = m_sim.mesh().Geom(lev).Domain(); + sampling_locations(sample_locs, {domain}); + + AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points()); +} + +void PlaneSampler::sampling_locations( + SampleLocType& sample_locs, const amrex::Vector& boxes) const +{ + AMREX_ALWAYS_ASSERT(sample_locs.locations().empty()); + amrex::Array dx; amrex::Array dy; @@ -102,8 +114,6 @@ void PlaneSampler::sampling_locations(SampleLocType& sample_locs) const } } } - - AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points()); } #ifdef AMR_WIND_USE_NETCDF diff --git a/amr-wind/utilities/sampling/ProbeSampler.H b/amr-wind/utilities/sampling/ProbeSampler.H index 9ca78f60a7..5854c24ea3 100644 --- a/amr-wind/utilities/sampling/ProbeSampler.H +++ b/amr-wind/utilities/sampling/ProbeSampler.H @@ -28,8 +28,14 @@ public: //! Check and fix the bounds of the sampler so the probes are in the domain void check_bounds() override; + //! Populate the vector with coordinates of the sampling locations void sampling_locations(SampleLocType& /*sample_locs**/) const override; + //! Populate the vector with coordinates of the sampling locations inside + //! boxes + void sampling_locations( + SampleLocType&, const amrex::Vector&) const override; + void output_locations(SampleLocType& sample_locs) const override { return sampling_locations(sample_locs); diff --git a/amr-wind/utilities/sampling/ProbeSampler.cpp b/amr-wind/utilities/sampling/ProbeSampler.cpp index 3bf30d5883..8513c596c3 100644 --- a/amr-wind/utilities/sampling/ProbeSampler.cpp +++ b/amr-wind/utilities/sampling/ProbeSampler.cpp @@ -60,6 +60,19 @@ void ProbeSampler::check_bounds() void ProbeSampler::sampling_locations(SampleLocType& sample_locs) const { AMREX_ALWAYS_ASSERT(sample_locs.locations().empty()); + + const int lev = 0; + const auto domain = m_sim.mesh().Geom(lev).Domain(); + sampling_locations(sample_locs, {domain}); + + AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points()); +} + +void ProbeSampler::sampling_locations( + SampleLocType& sample_locs, const amrex::Vector& boxes) const +{ + AMREX_ALWAYS_ASSERT(sample_locs.locations().empty()); + const auto& probe_locs = m_probes.locations(); for (int i = 0; i < m_npts; ++i) { for (int d = 0; d < AMREX_SPACEDIM; ++d) { @@ -68,7 +81,6 @@ void ProbeSampler::sampling_locations(SampleLocType& sample_locs) const sample_locs.push_back(loc, i); } } - AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points()); } #ifdef AMR_WIND_USE_NETCDF diff --git a/amr-wind/utilities/sampling/RadarSampler.H b/amr-wind/utilities/sampling/RadarSampler.H index ab92664aaf..bd9f5d418d 100644 --- a/amr-wind/utilities/sampling/RadarSampler.H +++ b/amr-wind/utilities/sampling/RadarSampler.H @@ -48,6 +48,12 @@ public: //! Populate and return a vector of probe locations to be sampled void sampling_locations(SampleLocType& /*sample_locs**/) const override; + + //! Populate the vector with coordinates of the sampling locations inside + //! boxes + void sampling_locations( + SampleLocType&, const amrex::Vector&) const override; + bool update_sampling_locations() override; void cone_axis_locations(SampleLocType& /*sample_locs**/) const; void output_locations(SampleLocType& sample_locs) const override diff --git a/amr-wind/utilities/sampling/RadarSampler.cpp b/amr-wind/utilities/sampling/RadarSampler.cpp index ada2dfd9d1..b7962f13d1 100644 --- a/amr-wind/utilities/sampling/RadarSampler.cpp +++ b/amr-wind/utilities/sampling/RadarSampler.cpp @@ -464,6 +464,18 @@ void RadarSampler::sampling_locations(SampleLocType& sample_locs) const { AMREX_ALWAYS_ASSERT(sample_locs.locations().empty()); + const int lev = 0; + const auto domain = m_sim.mesh().Geom(lev).Domain(); + sampling_locations(sample_locs, {domain}); + + AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points()); +} + +void RadarSampler::sampling_locations( + SampleLocType& sample_locs, const amrex::Vector& boxes) const +{ + AMREX_ALWAYS_ASSERT(sample_locs.locations().empty()); + for (int i = 0; i < num_points_scan(); ++i) { const amrex::Array loc = {AMREX_D_DECL( (m_radar_iter > 0) ? m_prior_cones[i][0] : m_fill_val, @@ -479,7 +491,6 @@ void RadarSampler::sampling_locations(SampleLocType& sample_locs) const m_current_cones[i][2])}; sample_locs.push_back(loc, ioff); } - AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points()); } // TODO: Create test for this calculation diff --git a/amr-wind/utilities/sampling/SamplerBase.H b/amr-wind/utilities/sampling/SamplerBase.H index 4ad465b2d7..26747dbf08 100644 --- a/amr-wind/utilities/sampling/SamplerBase.H +++ b/amr-wind/utilities/sampling/SamplerBase.H @@ -87,6 +87,11 @@ public: //! Populate the vector with coordinates of the sampling locations virtual void sampling_locations(SampleLocType&) const = 0; + //! Populate the vector with coordinates of the sampling locations inside + //! boxes + virtual void sampling_locations( + SampleLocType&, const amrex::Vector&) const = 0; + //! Check and fix the bounds of the sampler so the probes are in the domain virtual void check_bounds() = 0; diff --git a/amr-wind/utilities/sampling/VolumeSampler.H b/amr-wind/utilities/sampling/VolumeSampler.H index 18438510a1..d1974dba75 100644 --- a/amr-wind/utilities/sampling/VolumeSampler.H +++ b/amr-wind/utilities/sampling/VolumeSampler.H @@ -34,6 +34,11 @@ public: //! Populate and return a vector of probe locations to be sampled void sampling_locations(SampleLocType& /*sample_locs**/) const override; + //! Populate the vector with coordinates of the sampling locations inside + //! boxes + void sampling_locations( + SampleLocType&, const amrex::Vector&) const override; + void output_locations(SampleLocType& sample_locs) const override { return sampling_locations(sample_locs); diff --git a/amr-wind/utilities/sampling/VolumeSampler.cpp b/amr-wind/utilities/sampling/VolumeSampler.cpp index 50f1fff17b..fea863aa33 100644 --- a/amr-wind/utilities/sampling/VolumeSampler.cpp +++ b/amr-wind/utilities/sampling/VolumeSampler.cpp @@ -70,6 +70,18 @@ void VolumeSampler::sampling_locations(SampleLocType& sample_locs) const { AMREX_ALWAYS_ASSERT(sample_locs.locations().empty()); + const int lev = 0; + const auto domain = m_sim.mesh().Geom(lev).Domain(); + sampling_locations(sample_locs, {domain}); + + AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points()); +} + +void VolumeSampler::sampling_locations( + SampleLocType& sample_locs, const amrex::Vector& boxes) const +{ + AMREX_ALWAYS_ASSERT(sample_locs.locations().empty()); + const amrex::Array dx = { (m_hi[0] - m_lo[0]) / m_npts_dir[0], (m_hi[1] - m_lo[1]) / m_npts_dir[1], @@ -88,7 +100,6 @@ void VolumeSampler::sampling_locations(SampleLocType& sample_locs) const } } } - AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points()); } #ifdef AMR_WIND_USE_NETCDF