From 964440fad09419d226f78930e07cae027de3733e Mon Sep 17 00:00:00 2001 From: qualand <34353104+qualand@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:57:09 -0600 Subject: [PATCH] fixing process flux function for cavity --- solarpilot/Ambient.cpp | 4 +-- solarpilot/Receiver.cpp | 9 +++++++ solarpilot/Receiver.h | 1 + solarpilot/STObject.cpp | 2 +- solarpilot/interop.cpp | 47 +++++++++++++++++++++------------ solarpilot/interop.h | 2 +- ssc/cmod_csp_tower_particle.cpp | 4 +-- 7 files changed, 46 insertions(+), 23 deletions(-) diff --git a/solarpilot/Ambient.cpp b/solarpilot/Ambient.cpp index b6a18304e..045a1ed87 100644 --- a/solarpilot/Ambient.cpp +++ b/solarpilot/Ambient.cpp @@ -212,7 +212,7 @@ void Ambient::calcSunPosition(double lat, double lon, double timezone, double ts long retcode = 0; //Initialize with no errors - retcode = S_solpos(pdat); //Call the solar posotion algorithm + retcode = S_solpos(pdat); //Call the solar position algorithm S_decode(retcode, pdat); //Check the return code //set the calculated values @@ -243,7 +243,7 @@ void Ambient::calcDaytimeHours(double hrs[2], double lat, double lon, double tim long retcode = 0; //Initialize with no errors - retcode = S_solpos(pdat); //Call the solar posotion algorithm + retcode = S_solpos(pdat); //Call the solar position algorithm //srss( pdat ); S_decode(retcode, pdat); //Check the return code hrs[0] = pdat->sretr/60.; diff --git a/solarpilot/Receiver.cpp b/solarpilot/Receiver.cpp index 66b687602..b53af1bef 100644 --- a/solarpilot/Receiver.cpp +++ b/solarpilot/Receiver.cpp @@ -478,6 +478,15 @@ void FluxSurface::Normalize(){ } +void FluxSurface::Scale(double flux_mult /*-*/) { + + for (int i = 0; i < _nflux_x; i++) { + for (int j = 0; j < _nflux_y; j++) { + _flux_grid.at(i).at(j).flux *= flux_mult; + } + } +} + //-----------------Receiver---------------- void Receiver::Create(var_receiver &V, double tht) diff --git a/solarpilot/Receiver.h b/solarpilot/Receiver.h index ee83f3792..94aba7ca2 100644 --- a/solarpilot/Receiver.h +++ b/solarpilot/Receiver.h @@ -144,6 +144,7 @@ class FluxSurface : public mod_base //Declare the scripts void DefineFluxPoints(var_receiver &V, int rec_geom, int nx=-1, int ny=-1); void Normalize(); + void Scale(double flux_mult /*-*/); void ClearFluxGrid(); void ClearFluxGridResetMaxFlux(); }; diff --git a/solarpilot/STObject.cpp b/solarpilot/STObject.cpp index 753139653..42c1098d1 100644 --- a/solarpilot/STObject.cpp +++ b/solarpilot/STObject.cpp @@ -1006,7 +1006,7 @@ bool ST_System::CreateSTSystem(SolarField &SF, Hvector &helios, Vect &sunvect){ } /*--- Create a virtual stage ---*/ - /*--- Set the receiever stages ---*/ + /*--- Set the receiver stages ---*/ StageList.push_back(new ST_Stage()); ST_Stage *r_stage = StageList.back(); //Global origin diff --git a/solarpilot/interop.cpp b/solarpilot/interop.cpp index d4bfac1ab..46a11caa8 100644 --- a/solarpilot/interop.cpp +++ b/solarpilot/interop.cpp @@ -168,15 +168,12 @@ void interop::GenerateSimulationWeatherData(var_map &V, int design_method, Array switch (design_method) { case var_solarfield::DES_SIM_DETAIL::SUBSET_OF_DAYSHOURS: - //case LAYOUT_DETAIL::SUBSET_HOURS: - { //Subset of days/hours //Need to add this still V.amb.sim_time_step.Setval(0.); throw spexception("Simulation with a user-specified list of days/hours is not currently supported. Please use another option."); //break; } - //case LAYOUT_DETAIL::SINGLE_POINT: case var_solarfield::DES_SIM_DETAIL::SINGLE_SIMULATION_POINT: { //2) Single design point=1; V.amb.sim_time_step.Setval(0.); @@ -201,14 +198,12 @@ void interop::GenerateSimulationWeatherData(var_map &V, int design_method, Array wdatvar->setStep(0, dom, hour, month, P.dni, P.Tamb, P.Patm, P.Vwind, P.Simweight); break; } - //case LAYOUT_DETAIL::NO_FILTER: case var_solarfield::DES_SIM_DETAIL::DO_NOT_FILTER_HELIOSTATS: { //3) Do not filter heliostats=0; wdatvar->clear(); V.amb.sim_time_step.Setval(0.); break; } - //case LAYOUT_DETAIL::FULL_ANNUAL: case var_solarfield::DES_SIM_DETAIL::ANNUAL_SIMULATION: { //4) Annual simulation=3; *wdatvar = WeatherData(V.amb.wf_data.val); //vset["ambient"][0]["wf_data"].value; @@ -217,7 +212,6 @@ void interop::GenerateSimulationWeatherData(var_map &V, int design_method, Array V.amb.sim_time_step.Setval(3600.); break; } - //case LAYOUT_DETAIL::MAP_TO_ANNUAL: case var_solarfield::DES_SIM_DETAIL::EFFICIENCY_MAP__ANNUAL: { //Efficiency map + annual simulation V.amb.sim_time_step.Setval(3600.); @@ -253,8 +247,6 @@ void interop::GenerateSimulationWeatherData(var_map &V, int design_method, Array break; } - //case LAYOUT_DETAIL::LIMITED_ANNUAL: - //case LAYOUT_DETAIL::AVG_PROFILES: case var_solarfield::DES_SIM_DETAIL::LIMITED_ANNUAL_SIMULATION: case var_solarfield::DES_SIM_DETAIL::REPRESENTATIVE_PROFILES: case -1: //for optimization @@ -2413,22 +2405,43 @@ void sim_result::process_raytrace_simulation(SolarField& SF, sim_params& P, int } #endif -void sim_result::process_flux(SolarField *SF, bool normalize){ +void sim_result::process_flux(SolarField* SF, bool normalize) { flux_surfaces.clear(); receiver_names.clear(); int nr = (int)SF->getReceivers()->size(); - Receiver *rec; - for(int i=0; igetReceivers()->at(i); - if(! rec->isReceiverEnabled() ) continue; - flux_surfaces.push_back( *rec->getFluxSurfaces() ); - if(normalize){ - for(unsigned int j=0; jgetFluxSurfaces()->size(); j++){ - flux_surfaces.back().at(j).Normalize(); + if (!rec->isReceiverEnabled()) continue; + int n_surfaces = rec->getFluxSurfaces()->size(); + flux_surfaces.push_back(*rec->getFluxSurfaces()); + if (normalize) { + if (n_surfaces == 1) { + for (unsigned int j = 0; j < rec->getFluxSurfaces()->size(); j++) { + flux_surfaces.back().at(j).Normalize(); + } + } + else { + // For aperture (j = 0), use normalize, because we don't want it to count towards total flux + flux_surfaces.back().at(0).Normalize(); + + // Sum flux on all receiver panels + double flux_tot = 0.0; + for (unsigned int j = 1; j < rec->getFluxSurfaces()->size(); j++) { + flux_tot += flux_surfaces.back().at(j).getTotalFlux(); + } + + for (unsigned int j = 1; j < rec->getFluxSurfaces()->size(); j++) { + flux_surfaces.back().at(j).Scale(1.0 / flux_tot); + } } } - receiver_names.push_back( SF->getReceivers()->at(i)->getVarMap()->rec_name.val ); + receiver_names.push_back( + //*SF->getReceivers()->at(i)->getReceiverName() + SF->getReceivers()->at(i)->getVarMap()->rec_name.val + ); } + } //------parametric------------------------ diff --git a/solarpilot/interop.h b/solarpilot/interop.h index 86077962a..1c4609ed5 100644 --- a/solarpilot/interop.h +++ b/solarpilot/interop.h @@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "mod_base.h" #include "heliodata.h" #include "definitions.h" -#ifdef SP_USE_THREADS +#ifdef SP_USE_SOLTRACE #include "stapi.h" #endif diff --git a/ssc/cmod_csp_tower_particle.cpp b/ssc/cmod_csp_tower_particle.cpp index 15b4c7e26..15bbf2419 100644 --- a/ssc/cmod_csp_tower_particle.cpp +++ b/ssc/cmod_csp_tower_particle.cpp @@ -782,7 +782,7 @@ class cm_csp_tower_particle : public compute_module // Receiver model // ********************************************************* - // Using cmod inputs as initial guesses for receiver + // Initializing receivers with cmod inputs - these are initial guesses when SolarPILOT optimization is used double THT = as_double("h_tower"); // [m] tower height std::vector rec_height = as_vector_double("rec_height"); // [m] receiver height std::vector rec_width = as_vector_double("rec_width"); // [m] receiver width @@ -878,7 +878,7 @@ class cm_csp_tower_particle : public compute_module else { // Throw error if not running optimization std::string msg; msg = util::format("Receiver (%d) failed to converge at design condition. " - "Aperture size is too large.", i); + "Aperture size is most likely too large or receiver parameters are unrealistic.", i); throw exec_error("csp_tower_particle", msg); } }