Skip to content

Commit

Permalink
Remove sampling spike
Browse files Browse the repository at this point in the history
  • Loading branch information
marchdf committed Sep 20, 2024
1 parent 79332cd commit 5a54ba1
Show file tree
Hide file tree
Showing 23 changed files with 361 additions and 179 deletions.
2 changes: 1 addition & 1 deletion amr-wind/utilities/sampling/DTUSpinnerSampler.H
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public:
*
*
*/
void sampling_locations(SampleLocType& /*locs*/) const override;
void sampling_locations(SampleLocType& /*sample_locs**/) const override;

static vs::Vector generate_lidar_pattern(
PrismParameters InnerPrism, PrismParameters OuterPrism, double time);
Expand Down
30 changes: 12 additions & 18 deletions amr-wind/utilities/sampling/DTUSpinnerSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,12 @@ vs::Vector DTUSpinnerSampler::generate_lidar_pattern(
reflection_2, sampling_utils::reflect(reflection_1, axis));
}

//

void DTUSpinnerSampler::sampling_locations(SampleLocType& locs) const
void DTUSpinnerSampler::sampling_locations(SampleLocType& sample_locs) const
{

// The total number of points at this time step
long n_samples = m_beam_points * m_ntotal;

// Resize to number of points in line times number of sampling times
if (locs.size() < n_samples) {
locs.resize(n_samples);
}
AMREX_ALWAYS_ASSERT(sample_locs.locations().empty());

const amrex::Real ndiv = amrex::max(m_beam_points - 1, 1);
amrex::Array<amrex::Real, AMREX_SPACEDIM> dx;

// Loop per subsampling
for (int k = 0; k < m_ntotal; ++k) {

Expand All @@ -159,12 +149,15 @@ void DTUSpinnerSampler::sampling_locations(SampleLocType& locs) const
}

for (int i = 0; i < m_beam_points; ++i) {
for (int d = 0; d < AMREX_SPACEDIM; ++d) {
locs[i + k * m_beam_points][d] =
m_start[d + offset] + i * dx[d];
}
const amrex::Array<amrex::Real, AMREX_SPACEDIM> loc = {AMREX_D_DECL(
m_start[0 + offset] + i * dx[0],
m_start[1 + offset] + i * dx[1],
m_start[2 + offset] + i * dx[2])};
sample_locs.push_back(loc, i + k * m_beam_points);
}
}

AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points());
}

#ifdef AMR_WIND_USE_OPENFAST
Expand Down Expand Up @@ -512,8 +505,8 @@ void DTUSpinnerSampler::output_netcdf_data(
std::vector<size_t> count{1, 0, AMREX_SPACEDIM};
std::vector<size_t> starti{nt, 0};
std::vector<size_t> counti{1, 0};
SamplerBase::SampleLocType locs;
sampling_locations(locs);
SampleLocType sample_locs;
sampling_locations(sample_locs);

auto xyz = grp.var("points");
auto xp = grp.var("points_x");
Expand All @@ -522,6 +515,7 @@ void DTUSpinnerSampler::output_netcdf_data(
count[1] = num_points();
counti[1] = num_points();

const auto& locs = sample_locs.locations();
xyz.put(locs[0].data(), start, count);

auto n_samples = m_beam_points * m_ntotal;
Expand Down
6 changes: 3 additions & 3 deletions amr-wind/utilities/sampling/FreeSurfaceSampler.H
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public:
void check_bounds() override;

//! Populate and return a vector of probe locations to be sampled
void sampling_locations(SampleLocType& /*locs*/) const override;
void output_locations(SampleLocType& locs) const override
void sampling_locations(SampleLocType& /*sample_locs**/) const override;
void output_locations(SampleLocType& sample_locs) const override
{
return sampling_locations(locs);
return sampling_locations(sample_locs);
}

//! Find heights associated with 2D sample locations
Expand Down
24 changes: 11 additions & 13 deletions amr-wind/utilities/sampling/FreeSurfaceSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,26 +365,23 @@ void FreeSurfaceSampler::check_bounds()
}
}

void FreeSurfaceSampler::sampling_locations(SampleLocType& locs) const
void FreeSurfaceSampler::sampling_locations(SampleLocType& sample_locs) const
{
locs.resize(num_output_points());

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) {
// Initialize output values to 0.0
for (int ni = 0; ni < m_ninst; ++ni) {
// Grid direction 1
locs[idx * m_ninst + ni][m_gc0] = m_grid_locs[idx][0];
// Grid direction 2
locs[idx * m_ninst + ni][m_gc1] = m_grid_locs[idx][1];
// Output direction
locs[idx * m_ninst + ni][m_coorddir] =
m_out[idx * m_ninst + ni];
amrex::Array<amrex::Real, AMREX_SPACEDIM> loc;
loc[m_gc0] = m_grid_locs[idx][0];
loc[m_gc1] = m_grid_locs[idx][1];
loc[m_coorddir] = m_out[idx * m_ninst + ni];
sample_locs.push_back(loc, idx * m_ninst + ni);
}
++idx;
}
}
AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points());
}

bool FreeSurfaceSampler::update_sampling_locations()
Expand Down Expand Up @@ -727,10 +724,11 @@ void FreeSurfaceSampler::output_netcdf_data(
// Write the coordinates every time
std::vector<size_t> start{nt, 0, 0};
std::vector<size_t> count{1, 0, AMREX_SPACEDIM};
SamplerBase::SampleLocType locs;
sampling_locations(locs);
SampleLocType sample_locs;
sampling_locations(sample_locs);
auto xyz = grp.var("points");
count[1] = num_output_points();
const auto& locs = sample_locs.locations();
xyz.put(locs[0].data(), start, count);
}
#else
Expand Down
5 changes: 3 additions & 2 deletions amr-wind/utilities/sampling/LidarSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ void LidarSampler::output_netcdf_data(
// Write the coordinates every time
std::vector<size_t> start{nt, 0, 0};
std::vector<size_t> count{1, 0, AMREX_SPACEDIM};
SamplerBase::SampleLocType locs;
sampling_locations(locs);
SampleLocType sample_locs;
sampling_locations(sample_locs);
auto xyz = grp.var("points");
count[1] = num_points();
const auto& locs = sample_locs.locations();
xyz.put(locs[0].data(), start, count);
}
#else
Expand Down
6 changes: 3 additions & 3 deletions amr-wind/utilities/sampling/LineSampler.H
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public:
void check_bounds() override;

//! Populate and return a vector of probe locations to be sampled
void sampling_locations(SampleLocType& /*locs*/) const override;
void sampling_locations(SampleLocType& /*sample_locs**/) const override;

void output_locations(SampleLocType& locs) const override
void output_locations(SampleLocType& sample_locs) const override
{
return sampling_locations(locs);
return sampling_locations(sample_locs);
}

void
Expand Down
13 changes: 8 additions & 5 deletions amr-wind/utilities/sampling/LineSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ void LineSampler::check_bounds()
}
}

void LineSampler::sampling_locations(SampleLocType& locs) const
void LineSampler::sampling_locations(SampleLocType& sample_locs) const
{
locs.resize(m_npts);
AMREX_ALWAYS_ASSERT(sample_locs.locations().empty());

const amrex::Real ndiv = amrex::max(m_npts - 1, 1);
amrex::Array<amrex::Real, AMREX_SPACEDIM> dx;
Expand All @@ -65,10 +65,13 @@ void LineSampler::sampling_locations(SampleLocType& locs) const
}

for (int i = 0; i < m_npts; ++i) {
for (int d = 0; d < AMREX_SPACEDIM; ++d) {
locs[i][d] = m_start[d] + i * dx[d];
}
const amrex::Array<amrex::Real, AMREX_SPACEDIM> loc = {AMREX_D_DECL(
m_start[0] + i * dx[0], m_start[1] + i * dx[1],
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
Expand Down
6 changes: 3 additions & 3 deletions amr-wind/utilities/sampling/PlaneSampler.H
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public:
void check_bounds() override;

//! Populate and return a vector of probe locations to be sampled
void sampling_locations(SampleLocType& /*locs*/) const override;
void sampling_locations(SampleLocType& /*sample_locs**/) const override;

void output_locations(SampleLocType& locs) const override
void output_locations(SampleLocType& sample_locs) const override
{
return sampling_locations(locs);
return sampling_locations(sample_locs);
}

void
Expand Down
12 changes: 8 additions & 4 deletions amr-wind/utilities/sampling/PlaneSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ void PlaneSampler::check_bounds()
}
}

void PlaneSampler::sampling_locations(SampleLocType& locs) const
void PlaneSampler::sampling_locations(SampleLocType& sample_locs) const
{
locs.resize(m_npts);
AMREX_ALWAYS_ASSERT(sample_locs.locations().empty());

amrex::Array<amrex::Real, AMREX_SPACEDIM> dx;
amrex::Array<amrex::Real, AMREX_SPACEDIM> dy;
Expand All @@ -92,14 +92,18 @@ void PlaneSampler::sampling_locations(SampleLocType& locs) const
for (int k = 0; k < nplanes; ++k) {
for (int j = 0; j < m_npts_dir[1]; ++j) {
for (int i = 0; i < m_npts_dir[0]; ++i) {
amrex::Array<amrex::Real, AMREX_SPACEDIM> loc;
for (int d = 0; d < AMREX_SPACEDIM; ++d) {
locs[idx][d] = m_origin[d] + dx[d] * i + dy[d] * j +
m_poffsets[k] * m_offset_vector[d];
loc[d] = m_origin[d] + dx[d] * i + dy[d] * j +
m_poffsets[k] * m_offset_vector[d];
}
sample_locs.push_back(loc, idx);
++idx;
}
}
}

AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points());
}

#ifdef AMR_WIND_USE_NETCDF
Expand Down
6 changes: 3 additions & 3 deletions amr-wind/utilities/sampling/ProbeSampler.H
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public:
//! Check and fix the bounds of the sampler so the probes are in the domain
void check_bounds() override;

void sampling_locations(SampleLocType& /*locs*/) const override;
void sampling_locations(SampleLocType& /*sample_locs**/) const override;

void output_locations(SampleLocType& locs) const override
void output_locations(SampleLocType& sample_locs) const override
{
return sampling_locations(locs);
return sampling_locations(sample_locs);
}

void
Expand Down
24 changes: 15 additions & 9 deletions amr-wind/utilities/sampling/ProbeSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ void ProbeSampler::initialize(const std::string& key)

ifh >> m_npts;
ifh.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
m_probes.resize(m_npts);
for (int i = 0; i < m_npts; ++i) {
ifh >> m_probes[i][0] >> m_probes[i][1] >> m_probes[i][2];
amrex::Array<amrex::Real, AMREX_SPACEDIM> loc;
ifh >> loc[0] >> loc[1] >> loc[2];
ifh.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
m_probes.push_back(loc, i);
}
check_bounds();
}
Expand All @@ -35,16 +36,17 @@ void ProbeSampler::check_bounds()
const int lev = 0;
const auto* prob_lo = m_sim.mesh().Geom(lev).ProbLo();
const auto* prob_hi = m_sim.mesh().Geom(lev).ProbHi();
auto& probe_locs = m_probes.locations();
bool all_ok = true;
for (int i = 0; i < m_npts; ++i) {
for (int d = 0; d < AMREX_SPACEDIM; ++d) {
if (m_probes[i][d] < prob_lo[d]) {
if (probe_locs[i][d] < prob_lo[d]) {
all_ok = false;
m_probes[i][d] = prob_lo[d];
probe_locs[i][d] = prob_lo[d];
}
if (m_probes[i][d] > prob_hi[d]) {
if (probe_locs[i][d] > prob_hi[d]) {
all_ok = false;
m_probes[i][d] = prob_hi[d];
probe_locs[i][d] = prob_hi[d];
}
}
}
Expand All @@ -55,14 +57,18 @@ void ProbeSampler::check_bounds()
}
}

void ProbeSampler::sampling_locations(SampleLocType& locs) const
void ProbeSampler::sampling_locations(SampleLocType& sample_locs) const
{
locs.resize(m_npts);
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) {
locs[i][d] = m_probes[i][d];
const amrex::Array<amrex::Real, AMREX_SPACEDIM> loc = {AMREX_D_DECL(
probe_locs[i][0], probe_locs[i][1], probe_locs[i][2])};
sample_locs.push_back(loc, i);
}
}
AMREX_ALWAYS_ASSERT(sample_locs.locations().size() == num_points());
}

#ifdef AMR_WIND_USE_NETCDF
Expand Down
16 changes: 8 additions & 8 deletions amr-wind/utilities/sampling/RadarSampler.H
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public:
double determine_current_sweep_angle() const;

//! Populate and return a vector of probe locations to be sampled
void sampling_locations(SampleLocType& /*locs*/) const override;
void sampling_locations(SampleLocType& /*sample_locs**/) const override;
bool update_sampling_locations() override;
void cone_axis_locations(SampleLocType& /*locs*/) const;
void output_locations(SampleLocType& locs) const override
void cone_axis_locations(SampleLocType& /*sample_locs**/) const;
void output_locations(SampleLocType& sample_locs) const override
{
return cone_axis_locations(locs);
return cone_axis_locations(sample_locs);
}

void post_sample_actions() override;
Expand Down Expand Up @@ -140,10 +140,10 @@ protected:
amrex::Vector<amrex::Real> m_start;
amrex::Vector<amrex::Real> m_end;

SamplerBase::SampleLocType m_initial_cone;
SamplerBase::SampleLocType m_current_cones;
SamplerBase::SampleLocType m_prior_cones;
SamplerBase::SampleLocType m_sample_cones;
SampleLocType::LocType m_initial_cone;
SampleLocType::LocType m_current_cones;
SampleLocType::LocType m_prior_cones;
SampleLocType::LocType m_sample_cones;

LosRotType m_los_proj;
LosUnitType m_los_unit;
Expand Down
Loading

0 comments on commit 5a54ba1

Please sign in to comment.