From 3542285d64c9e9e2d657343b57ad9db494610658 Mon Sep 17 00:00:00 2001 From: Gopal Yalla Date: Thu, 13 Jun 2024 08:14:37 -0600 Subject: [PATCH] (Work in progress) Fixing compiling errors with turbine level coarse search. --- include/aero/actuator/ActuatorBulk.h | 10 ++++++ include/aero/actuator/ActuatorBulkFAST.h | 4 +-- src/aero/actuator/ActuatorBulk.C | 22 +++++++++++- src/aero/actuator/ActuatorBulkFAST.C | 38 ++++++++++---------- src/aero/actuator/ActuatorExecutorsFASTNgp.C | 7 ++-- src/aero/actuator/ActuatorModel.C | 12 ++----- 6 files changed, 56 insertions(+), 37 deletions(-) diff --git a/include/aero/actuator/ActuatorBulk.h b/include/aero/actuator/ActuatorBulk.h index 8e566d292..63628781b 100644 --- a/include/aero/actuator/ActuatorBulk.h +++ b/include/aero/actuator/ActuatorBulk.h @@ -68,6 +68,16 @@ struct ActuatorBulk void stk_search_act_pnts( const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk); + + //Generic stk search + void stk_search( + const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk, bool onlyFine = false); + + //do I need this to be virtual function so the generic stk_search can call it, even though + //the turbine search only makes sense in the ActuatorBulkFast context as implemented? + virtual void stk_turbine_search( + const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk, bool onlyFine = false); + void zero_source_terms(stk::mesh::BulkData& stkBulk); void parallel_sum_source_term(stk::mesh::BulkData& stkBulk); void compute_offsets(const ActuatorMeta& actMeta); diff --git a/include/aero/actuator/ActuatorBulkFAST.h b/include/aero/actuator/ActuatorBulkFAST.h index 8b88ce1ba..d85a63294 100644 --- a/include/aero/actuator/ActuatorBulkFAST.h +++ b/include/aero/actuator/ActuatorBulkFAST.h @@ -57,8 +57,8 @@ struct ActuatorBulkFAST : public ActuatorBulk const double fastTimeStep, const double naluTimeStep); // This is placed in ActuatorBulkFAST instead of ActuatorBulk because hublocations are needed - void stk_turbine_search( - const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk); + void stk_turbine_search ( + const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk,bool onlyFine = false) override; virtual ~ActuatorBulkFAST(); diff --git a/src/aero/actuator/ActuatorBulk.C b/src/aero/actuator/ActuatorBulk.C index 2d3a99d47..642133659 100644 --- a/src/aero/actuator/ActuatorBulk.C +++ b/src/aero/actuator/ActuatorBulk.C @@ -88,8 +88,8 @@ ActuatorBulk::stk_search_act_pnts( const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk) { auto points = pointCentroid_.template view(); - auto radius = searchRadius_.template view(); + auto radius = searchRadius_.template view(); auto boundSpheres = CreateBoundingSpheres(points, radius); auto elemBoxes = CreateElementBoxes(stkBulk, actMeta.searchTargetNames_); @@ -105,6 +105,26 @@ ActuatorBulk::stk_search_act_pnts( actuator_utils::reduce_view_on_host(localParallelRedundancy_); } +void stk_turbine_search( + const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk, bool onlyFine /*= false*/) +{ + STK_ThrowErrorMsg("Turbine Search Requires ActuatorBulkFAST data"); +} + +void +ActuatorBulk::stk_search( + const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk,bool onlyFine /*= false*/) +{ + if (actMeta.turbineLevelSearch_){ + // perform turbine level search and cache to the bulk data + stk_turbine_search(actMeta.get(), stkBulk,onlyFine); + } + else{ + //TODO: Does it make sense for actuator point search to have onlyFine option? + stk_search_act_pnts(actMeta.get(), stkBulk); + } +} + void ActuatorBulk::zero_source_terms(stk::mesh::BulkData& stkBulk) diff --git a/src/aero/actuator/ActuatorBulkFAST.C b/src/aero/actuator/ActuatorBulkFAST.C index 808e5267c..a2c034bf4 100644 --- a/src/aero/actuator/ActuatorBulkFAST.C +++ b/src/aero/actuator/ActuatorBulkFAST.C @@ -247,50 +247,50 @@ ActuatorBulkFAST::init_epsilon(const ActuatorMetaFAST& actMeta) void ActuatorBulkFAST::stk_turbine_search( - const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk, bool onlyFineSearch=False) + const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk, bool onlyFine /* = false */) { //It seems point_centroids includes all actuator points across all turbines. TODO: Is that right? //If so, we need to build a similar list here that will be of size numberofActuators //that includes all hublocations. The search radius also needs to be of the same size + // create bounding sphere and element boxes based on turbine location and search radius + auto points = hubLocations_.template view(); + + if (!onlyFine) { // Loop over all turbines to initialize the search radius turbineSearchRadius_.modify_host(); for (int iTurb = 0; iTurb < openFast_.get_nTurbinesGlob(); ++iTurb) { - // if my process contains the turbine? + // if my process contains the turbine if (NaluEnv::self().parallel_rank() == openFast_.get_procNo(iTurb)) { - const int nbfp = openFast_.get_numForcePtsBlade(iTurb); + auto hubLoc = Kokkos::subview(actBulk_.hubLocations_, iTurb, Kokkos::ALL); + double turbineRadius = 0.0; // Approximate turbine radius to define search radius // - // TODO: is there an easier way to get this information. Is nbfp actually at the blade tip? - Point bladeTip = actuator_utils::get_fast_point(openFast_, iTurb, fast::BLADE, nbfp, 0); - double turbineRadius = 0.0; - for (int i = 0; i < 3; ++i) { - turbineRadius += std::pow(bladeTip[i] - hubLoc[i], 2.0); - } - turbineRadius = std::sqrt(turbineRadius); - searchRadius_.h_view(iTurb) = 1.25 * turbineRadius * std::sqrt(2); + /* const int nbfp = openFast_.get_numForcePtsBlade(iTurb); */ + /* Point bladeTip = actuator_utils::get_fast_point(openFast_, iTurb, fast::BLADE, nbfp, 0); */ + /* for (int i = 0; i < 3; ++i) { */ + /* turbineRadius += std::pow(bladeTip[i] - hubLoc[i], 2.0); */ + /* } */ + //use the hub height as a surrogate for turbineRadius + turbineRadius = hubLoc[2] //TODO: 1 or 2? + turbineSearchRadius_.h_view(iTurb) = 1.25 * turbineRadius * std::sqrt(2); //TODO: Could switch to bounding boxes here instead } } - //TODO: Are we interacting with Kokkos views correctly? - actuator_utils::reduce_view_on_host(searchTurbineRadius_.view_host()); - searchTurbineRadius_.sync_host(); + actuator_utils::reduce_view_on_host(turbineSearchRadius_.view_host()); + turbineSearchRadius_.sync_host(); - // create bounding sphere and element boxes based on turbine location and search radius - auto points = hubLocations_.template view(); auto radius = turbineSearchRadius_.template view(); auto boundSpheres = CreateBoundingSpheres(points,radius); auto elemBoxes = CreateElementBoxes(stkBulk, actMeta.searchTargetNames_); - // need conditional behavior for executing coarse or fine search - // - // the coarse search now associates element boxes with turbines ExecuteCoarseSearch( boundSpheres, elemBoxes, coarseSearchPointIds_, coarseSearchElemIds_, actMeta.searchMethod_); + } // The fine search may be slower now because the number of element boxes are much larger than needed. // However, we don't need to do another fine search. If it's too slow, we could do a smaller fine search diff --git a/src/aero/actuator/ActuatorExecutorsFASTNgp.C b/src/aero/actuator/ActuatorExecutorsFASTNgp.C index 73ea33bc4..674cfdfe1 100644 --- a/src/aero/actuator/ActuatorExecutorsFASTNgp.C +++ b/src/aero/actuator/ActuatorExecutorsFASTNgp.C @@ -55,10 +55,7 @@ ActuatorLineFastNGP::operator()() RunActFastUpdatePoints(actBulk_); // Execute fine and coarse search given point centroids (see next slides) - // Do not need to update fine and coarse search when performing turbine level search - if !(actMeta_->turbineLevelSearch_) { - actBulk_.stk_search_act_pnts(actMeta_, stkBulk_); // this is the fine and coarse searching. - } + actBulk_.stk_search(actMeta_, stkBulk_); // this is the fine and coarse searching. // call openfast and step actBulk_.step_fast(); @@ -130,7 +127,7 @@ ActuatorDiskFastNGP::operator()() actBulk_.update_ADM_points(actMeta_); - actBulk_.stk_search_act_pnts(actMeta_, stkBulk_); + actBulk_.stk_search(actMeta_, stkBulk_,true); } actBulk_.step_fast(); diff --git a/src/aero/actuator/ActuatorModel.C b/src/aero/actuator/ActuatorModel.C index cf63c254f..b3cd965c9 100644 --- a/src/aero/actuator/ActuatorModel.C +++ b/src/aero/actuator/ActuatorModel.C @@ -145,16 +145,8 @@ ActuatorModel::init(stk::mesh::BulkData& stkBulk) break; #endif #else - - if (actMeta_->turbineLevelSearch_){ - // perform turbine level search and cache to the bulk data - actBulk_->stk_turbine_search(*actMeta_.get(), stkBulk); - } - else{ - // perform search for actline and actdisk - actBulk_->stk_search_act_pnts(*actMeta_.get(), stkBulk); - } - + //perform stk_search (coarse + fine search) + actBulk_->stk_search(*actMeta_.get(), stkBulk); break; #endif }