From 0ac06e363399dfde2bab8ebac1a6aa18693bcef7 Mon Sep 17 00:00:00 2001 From: minsoo Date: Mon, 21 Sep 2026 15:42:16 -0500 Subject: [PATCH] Add missing lookup_winds functions from ramtares_main --- .../DRWP_atmos/include/lookup_winds.hh | 7 ++ .../DRWP_atmos/src/lookup_winds.cc | 69 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/models/environment/atmos/atmosphere_models/DRWP_atmos/include/lookup_winds.hh b/models/environment/atmos/atmosphere_models/DRWP_atmos/include/lookup_winds.hh index 3f6ceba7..369472d4 100644 --- a/models/environment/atmos/atmosphere_models/DRWP_atmos/include/lookup_winds.hh +++ b/models/environment/atmos/atmosphere_models/DRWP_atmos/include/lookup_winds.hh @@ -205,6 +205,9 @@ public: void compute_average_wind( size_t table_index, double min_alt, double max_alt); + void compute_average_wind_interp( double min_altitude, + double max_altitude, + double altitude_incr); // Legacy capability, deprecated. void test_for_reinitialize(); @@ -216,6 +219,10 @@ protected: bool full_domain, double min_alt=0, double max_alt=0); + void compute_average_wind_interp( size_t table_index, + double min_altitude=0, + double max_altitude=0, + double altitude_incr=0); void calculate_speed_of_sound(); void calculate_wind_mag_dir(); void stream_error(int line, const std::string& drwpFileName_); diff --git a/models/environment/atmos/atmosphere_models/DRWP_atmos/src/lookup_winds.cc b/models/environment/atmos/atmosphere_models/DRWP_atmos/src/lookup_winds.cc index 177e8cd2..bdd6474d 100644 --- a/models/environment/atmos/atmosphere_models/DRWP_atmos/src/lookup_winds.cc +++ b/models/environment/atmos/atmosphere_models/DRWP_atmos/src/lookup_winds.cc @@ -655,6 +655,18 @@ LookupAtmosWinds::compute_average_wind( { compute_average_wind( table_index, false, min_alt, max_alt); } + +/****************************************************************************/ +void +LookupAtmosWinds::compute_average_wind_interp( + double min_alt, + double max_alt, + double step_alt) +{ + size_t target_index = (active)? current_index : 0; + compute_average_wind_interp( target_index, min_alt, max_alt, step_alt); +} + /****************************************************************************/ void LookupAtmosWinds::compute_average_wind( @@ -727,6 +739,63 @@ LookupAtmosWinds::compute_average_wind( } } +/****************************************************************************/ +void +LookupAtmosWinds::compute_average_wind_interp( + size_t table_index, + double min_alt, + double max_alt, + double step_alt) +{ + if (table_index >= number_of_datasets) { + CMLMessage::error( __FILE__,__LINE__, + "Error computing average wind velocity for profile at index ", + table_index, ".\nThis index has not been populated with data.\n" + "Aborting computation.\n"); + return; + } + + double original_altitude = altitude; + jeod::Vector3::initialize(average_wind); + DRWPTableLookup & table_ = TableLookup_array[table_index]; + + // Table logic to maintain bounds of operated on + // altitude array within available domain + double table_end1 = table_.independent->data.front(); + double table_end2 = table_.independent->data.back(); + double table_min = std::min(table_end1, table_end2); + double table_max = std::max(table_end1, table_end2); + double min_alt_ = std::max(table_min, min_alt); + double max_alt_ = std::min(table_max, max_alt); + + if (min_alt_ > max_alt_) { + CMLMessage::error( __FILE__,__LINE__, + "Error computing average wind velocity within specified bounds\n", + "No altitude data found in between 'min_alt' (", min_alt, + ")\nand 'max_alt' (", max_alt, ") for given DRWP Binary file."); + // Leave average at zero-vector + return; + } + size_t num_alts = (max_alt_ - min_alt_) / step_alt + 1; + for (size_t alt = 0; alt < num_alts; ++alt) { + altitude = min_alt_ + static_cast(alt) * step_alt; + table_.update(); + calculate_wind_mag_dir(); + jeod::Vector3::incr( wind_velocity_tc, + average_wind); + } + + jeod::Vector3::scale( (1.0/num_alts), + average_wind); + // We just populated the model's output data with values from an altitude + // that is not the current altitude. If the model is currently active, that + // might cause some problems with data logging. + // Reset model outputs to current table and altitude. + if (active) { + update(original_altitude); + } +} + /************************************************************************* calculate_speed_of_sound Purpose: (computes SOS based on pressure and density at a given altitude)