Skip to content

Commit

Permalink
Reduce memory usage of the samplers again (#1209)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchdf authored Aug 22, 2024
1 parent 89eacad commit f336699
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 12 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 @@ -60,7 +60,7 @@ public:
/** Determine how the subsampling will be done
*
*/
void update_sampling_locations() override;
bool update_sampling_locations() override;

void post_sample_actions() override {};

Expand Down
4 changes: 3 additions & 1 deletion amr-wind/utilities/sampling/DTUSpinnerSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void DTUSpinnerSampler::get_turbine_data(const std::string& turbine_label)
}
#endif // AMR_WIND_USE_OPENFAST

void DTUSpinnerSampler::update_sampling_locations()
bool DTUSpinnerSampler::update_sampling_locations()
{
BL_PROFILE(
"amr-wind::Sampling::DTUSpinnerSampler::update_sampling_locations");
Expand Down Expand Up @@ -435,6 +435,8 @@ void DTUSpinnerSampler::update_sampling_locations()
m_last_lidar_center = m_lidar_center;

m_update_count = m_update_count + 1;

return true;
}

#ifdef AMR_WIND_USE_NETCDF
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/utilities/sampling/FreeSurfaceSampler.H
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public:
}

//! Find heights associated with 2D sample locations
void update_sampling_locations() override;
bool update_sampling_locations() override;

//! Redo some of the initialization work when the grid changes
void post_regrid_actions() override;
Expand Down
4 changes: 3 additions & 1 deletion amr-wind/utilities/sampling/FreeSurfaceSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void FreeSurfaceSampler::sampling_locations(SampleLocType& locs) const
}
}

void FreeSurfaceSampler::update_sampling_locations()
bool FreeSurfaceSampler::update_sampling_locations()
{

BL_PROFILE("amr-wind::FreeSurfaceSampler::update_sampling_locations");
Expand Down Expand Up @@ -525,6 +525,8 @@ void FreeSurfaceSampler::update_sampling_locations()
dout_ptr[n] = plo0[coorddir];
});
}

return true;
}

void FreeSurfaceSampler::post_regrid_actions()
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/utilities/sampling/LidarSampler.H
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public:
*
*
*/
void update_sampling_locations() override;
bool update_sampling_locations() override;

void post_sample_actions() override {};

Expand Down
4 changes: 3 additions & 1 deletion amr-wind/utilities/sampling/LidarSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void LidarSampler::initialize(const std::string& key)
check_bounds();
}

void LidarSampler::update_sampling_locations()
bool LidarSampler::update_sampling_locations()
{

amrex::Real time = m_sim.time().current_time();
Expand All @@ -84,6 +84,8 @@ void LidarSampler::update_sampling_locations()
m_end[1] = m_start[1] + m_length * std::sin(current_azimuth) *
std::sin(current_elevation);
m_end[2] = m_start[2] + m_length * std::cos(current_elevation);

return true;
}

#ifdef AMR_WIND_USE_NETCDF
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/utilities/sampling/RadarSampler.H
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public:

//! Populate and return a vector of probe locations to be sampled
void sampling_locations(SampleLocType& /*locs*/) const override;
void update_sampling_locations() override;
bool update_sampling_locations() override;
void cone_axis_locations(SampleLocType& /*locs*/) const;
void output_locations(SampleLocType& locs) const override
{
Expand Down
4 changes: 3 additions & 1 deletion amr-wind/utilities/sampling/RadarSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ double RadarSampler::determine_current_sweep_angle() const
}
}

void RadarSampler::update_sampling_locations()
bool RadarSampler::update_sampling_locations()
{
amrex::Real time = m_sim.time().current_time();
amrex::Real start_time = m_sim.time().start_time();
Expand Down Expand Up @@ -306,6 +306,8 @@ void RadarSampler::update_sampling_locations()
}

m_radar_iter++;

return true;
}

void RadarSampler::new_cone()
Expand Down
2 changes: 1 addition & 1 deletion amr-wind/utilities/sampling/SamplerBase.H
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public:
virtual void output_locations(SampleLocType&) const = 0;

//! Update the sampling locations
virtual void update_sampling_locations() {}
virtual bool update_sampling_locations() { return false; }

//! Run actions after sample (useful in interpolated subsampling)
virtual void post_sample_actions() {}
Expand Down
10 changes: 8 additions & 2 deletions amr-wind/utilities/sampling/Sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,17 @@ void Sampling::update_sampling_locations()
{
BL_PROFILE("amr-wind::Sampling::update_sampling_locations");

amrex::Vector<bool> updated_position;
for (const auto& obj : m_samplers) {
obj->update_sampling_locations();
const bool updated_pos = obj->update_sampling_locations();
updated_position.push_back(updated_pos);
}

update_container();
if (std::any_of(
updated_position.begin(), updated_position.end(),
[](const auto& v) { return v; })) {
update_container();
}
}

void Sampling::post_advance_work()
Expand Down
2 changes: 1 addition & 1 deletion test/test_files/dam_break_godunov/dam_break_godunov.inp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ time.plot_interval = 10 # Steps between plot files
time.checkpoint_interval = -100 # Steps between checkpoint files

incflo.post_processing = sampling
sampling.output_frequency = 30
sampling.output_frequency = 10
sampling.output_format = native
sampling.labels = fs
sampling.fields = velocity
Expand Down

0 comments on commit f336699

Please sign in to comment.