From 64e6fa659f678867a0c371435b5903160d8f184e Mon Sep 17 00:00:00 2001 From: Gopal Yalla Date: Mon, 15 Jul 2024 09:35:12 -0600 Subject: [PATCH] Correcting formatting and generalize collective actuator point searching name --- include/aero/actuator/ActuatorBulk.h | 6 +- include/aero/actuator/ActuatorBulkFAST.h | 12 ++- include/aero/actuator/ActuatorFunctors.h | 1 - include/aero/actuator/ActuatorFunctorsFAST.h | 2 +- .../actuator/ActuatorGenericSearchFunctor.h | 24 ++--- src/aero/actuator/ActuatorBulk.C | 10 ++- src/aero/actuator/ActuatorBulkFAST.C | 88 ++++++++++--------- src/aero/actuator/ActuatorExecutorsFASTNgp.C | 16 ++-- src/aero/actuator/ActuatorFunctors.C | 8 +- src/aero/actuator/ActuatorModel.C | 4 +- 10 files changed, 86 insertions(+), 85 deletions(-) diff --git a/include/aero/actuator/ActuatorBulk.h b/include/aero/actuator/ActuatorBulk.h index 3e3353017..1d812cccb 100644 --- a/include/aero/actuator/ActuatorBulk.h +++ b/include/aero/actuator/ActuatorBulk.h @@ -66,7 +66,9 @@ struct ActuatorBulk virtual ~ActuatorBulk() {} virtual void stk_search( - const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk, bool onlyFine = false); + const ActuatorMeta& actMeta, + stk::mesh::BulkData& stkBulk, + bool onlyFine = false); void stk_search_act_pnts( const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk); @@ -102,7 +104,7 @@ struct ActuatorBulk ActFixElemIds elemContainingPoint_; const int localTurbineId_; - bool singlePointCoarseSearch_ = false; + bool singlePointCoarseSearch_ = false; }; } // namespace nalu diff --git a/include/aero/actuator/ActuatorBulkFAST.h b/include/aero/actuator/ActuatorBulkFAST.h index bd849e9d1..525735125 100644 --- a/include/aero/actuator/ActuatorBulkFAST.h +++ b/include/aero/actuator/ActuatorBulkFAST.h @@ -56,11 +56,15 @@ struct ActuatorBulkFAST : public ActuatorBulk bool is_tstep_ratio_admissable( const double fastTimeStep, const double naluTimeStep); - void stk_turbine_search ( - const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk,bool onlyFine = false); + void stk_search_collective_act_pnts( + const ActuatorMeta& actMeta, + stk::mesh::BulkData& stkBulk, + bool onlyFine = false); void stk_search( - const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk, bool onlyFine = false) override; + const ActuatorMeta& actMeta, + stk::mesh::BulkData& stkBulk, + bool onlyFine = false) override; virtual ~ActuatorBulkFAST(); @@ -68,7 +72,7 @@ struct ActuatorBulkFAST : public ActuatorBulk ActFixVectorDbl turbineTorque_; ActFixVectorDbl hubLocations_; ActFixVectorDbl hubOrientation_; - ActFixScalarDbl turbineSearchRadius_; //need vector for turbine search...this will be a different size than searchRadius_ in Actuatorbulk.h + ActFixScalarDbl turbineSearchRadius_; ActTensorDblDv orientationTensor_; diff --git a/include/aero/actuator/ActuatorFunctors.h b/include/aero/actuator/ActuatorFunctors.h index 42b6a8b86..918441dac 100644 --- a/include/aero/actuator/ActuatorFunctors.h +++ b/include/aero/actuator/ActuatorFunctors.h @@ -10,7 +10,6 @@ #ifndef ACTUATORFUNCTORS_H_ #define ACTUATORFUNCTORS_H_ -#include #include #include #include diff --git a/include/aero/actuator/ActuatorFunctorsFAST.h b/include/aero/actuator/ActuatorFunctorsFAST.h index fd926dc1a..101f2ff18 100644 --- a/include/aero/actuator/ActuatorFunctorsFAST.h +++ b/include/aero/actuator/ActuatorFunctorsFAST.h @@ -38,7 +38,7 @@ inline void RunActFastUpdatePoints(ActuatorBulkFAST& actBulk) { Kokkos::deep_copy(actBulk.pointCentroid_.view_host(), 0.0); - actBulk.pointCentroid_.modify_host(); //actuator point locations in space + actBulk.pointCentroid_.modify_host(); Kokkos::parallel_for( "ActFastUpdatePoints", actBulk.local_range_policy(), ActFastUpdatePoints(actBulk)); diff --git a/include/aero/actuator/ActuatorGenericSearchFunctor.h b/include/aero/actuator/ActuatorGenericSearchFunctor.h index 64a5098c6..8af9793ad 100644 --- a/include/aero/actuator/ActuatorGenericSearchFunctor.h +++ b/include/aero/actuator/ActuatorGenericSearchFunctor.h @@ -26,7 +26,6 @@ namespace sierra { namespace nalu { template - //coarse search actuatorbulk.c L96 struct GenericLoopOverCoarseSearchResults { using execution_space = ActuatorFixedExecutionSpace; @@ -47,7 +46,6 @@ struct GenericLoopOverCoarseSearchResults actBulk_.coarseSearchElemIds_.sync_host(); actBulk_.coarseSearchPointIds_.sync_host(); innerLoopFunctor_.preloop(); - //innerLoopExtent_ = actBulk_.singlePointCoarseSearch ? 1 : actBulk_.pointCentroid_.extent(0) } // ctor for functor constructor taking multiple args @@ -68,7 +66,6 @@ struct GenericLoopOverCoarseSearchResults actBulk_.coarseSearchElemIds_.sync_host(); actBulk_.coarseSearchPointIds_.sync_host(); innerLoopFunctor_.preloop(); - //innerLoopExtent_ = actBulk_.singlePointCoarseSearch ? 1 : actBulk_.pointCentroid_.extent(0) } // see ActuatorExecutorFASTSngp.C line 58 @@ -78,7 +75,7 @@ struct GenericLoopOverCoarseSearchResults auto pointId = actBulk_.coarseSearchPointIds_.h_view(index); auto elemId = actBulk_.coarseSearchElemIds_.h_view(index); - // get element topology + // get element topology const stk::mesh::Entity elem = stkBulk_.get_entity(stk::topology::ELEMENT_RANK, elemId); const stk::topology& elemTopo = stkBulk_.bucket(elem).topology(); @@ -125,20 +122,16 @@ struct GenericLoopOverCoarseSearchResults // anything else that is required should be stashed on the functor // during functor construction i.e. ActuatorBulk, flags, ActuatorMeta, // etc. - // - // - // for (int actPtInd = 0; actPtInd < innerLoopExtent_; actPtInd ++){ - // innerLoopFunctor_(actPtInd, nodeCoords, sourceTerm, dual_vol, scvIp[nIp]); - // } - // - if (actBulk_.singlePointCoarseSearch_) { - innerLoopFunctor_(pointId, nodeCoords, sourceTerm, dual_vol, scvIp[nIp]); + if (actBulk_.singlePointCoarseSearch_) { + innerLoopFunctor_( + pointId, nodeCoords, sourceTerm, dual_vol, scvIp[nIp]); } else { - for (int actPtInd = 0; actPtInd < actBulk_.pointCentroid_.extent(0); actPtInd ++){ - innerLoopFunctor_(actPtInd, nodeCoords, sourceTerm, dual_vol, scvIp[nIp]); + for (int actPtInd = 0; actPtInd < actBulk_.pointCentroid_.extent(0); + actPtInd++) { + innerLoopFunctor_( + actPtInd, nodeCoords, sourceTerm, dual_vol, scvIp[nIp]); } } - } } @@ -148,7 +141,6 @@ struct GenericLoopOverCoarseSearchResults VectorFieldType* actuatorSource_; ScalarFieldType* dualNodalVolume_; functor innerLoopFunctor_; - //const size_t innerLoopExtent_; }; } // namespace nalu diff --git a/src/aero/actuator/ActuatorBulk.C b/src/aero/actuator/ActuatorBulk.C index 746fc1f60..1babfd594 100644 --- a/src/aero/actuator/ActuatorBulk.C +++ b/src/aero/actuator/ActuatorBulk.C @@ -105,13 +105,15 @@ ActuatorBulk::stk_search_act_pnts( actuator_utils::reduce_view_on_host(localParallelRedundancy_); } -void ActuatorBulk::stk_search( - const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk,bool onlyFine /*= false*/) +void +ActuatorBulk::stk_search( + const ActuatorMeta& actMeta, + stk::mesh::BulkData& stkBulk, + bool onlyFine /*= false*/) { - stk_search_act_pnts(actMeta, stkBulk); + stk_search_act_pnts(actMeta, 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 356f58c9e..aeb03f91f 100644 --- a/src/aero/actuator/ActuatorBulkFAST.C +++ b/src/aero/actuator/ActuatorBulkFAST.C @@ -43,8 +43,6 @@ ActuatorMetaFAST::is_disk() return actuatorType_ == ActuatorType::ActDiskFASTNGP; } - - ActuatorBulkFAST::ActuatorBulkFAST( const ActuatorMetaFAST& actMeta, double naluTimeStep) : ActuatorBulk(actMeta), @@ -247,61 +245,65 @@ ActuatorBulkFAST::init_epsilon(const ActuatorMetaFAST& actMeta) void ActuatorBulkFAST::stk_search( - const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk, bool onlyFine /* = false */) + const ActuatorMeta& actMeta, + stk::mesh::BulkData& stkBulk, + bool onlyFine /* = false */) { - if (singlePointCoarseSearch_){ - //TODO: Does it make sense for actuator point search to have onlyFine option? - stk_search_act_pnts(actMeta, stkBulk); - } - else{ - // perform turbine level search and cache to the bulk data - stk_turbine_search(actMeta, stkBulk,onlyFine); - } + if (singlePointCoarseSearch_) { + // TODO: Does it make sense for actuator point search to have onlyFine + // option? + stk_search_act_pnts(actMeta, stkBulk); + } else { + // perform turbine level search and cache to the bulk data + stk_search_collective_act_pnts(actMeta, stkBulk, onlyFine); + } } - void -ActuatorBulkFAST::stk_turbine_search( - const ActuatorMeta& actMeta, stk::mesh::BulkData& stkBulk, bool onlyFine /* = false */) +ActuatorBulkFAST::stk_search_collective_act_pnts( + const ActuatorMeta& actMeta, + stk::mesh::BulkData& stkBulk, + bool onlyFine /* = false */) { auto points = hubLocations_; if (!onlyFine) { - // Loop over all turbines to initialize the search radius - for (int iTurb = 0; iTurb < openFast_.get_nTurbinesGlob(); ++iTurb) { - // if my process contains the turbine - if (NaluEnv::self().parallel_rank() == openFast_.get_procNo(iTurb)) { - auto hubLoc = Kokkos::subview(hubLocations_, iTurb, Kokkos::ALL); - double turbineRadius = 0.0; - // Approximate turbine radius to define search radius - // - /* 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: Is z 1 or 2? - turbineSearchRadius_(iTurb) = 1.25 * turbineRadius * std::sqrt(2); //TODO: Could switch to bounding boxes here instead - + // Loop over all turbines to initialize the search radius + for (int iTurb = 0; iTurb < openFast_.get_nTurbinesGlob(); ++iTurb) { + // if my process contains the turbine + if (NaluEnv::self().parallel_rank() == openFast_.get_procNo(iTurb)) { + auto hubLoc = Kokkos::subview(hubLocations_, iTurb, Kokkos::ALL); + double turbineRadius = 0.0; + // Approximate turbine radius to define search radius + // + /* 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: Is z 1 or 2? + turbineSearchRadius_(iTurb) = + 1.25 * turbineRadius * + std::sqrt(2); // TODO: Could switch to bounding boxes here instead + } } - } - //actuator_utils::reduce_view_on_host(turbineSearchRadius_.view_host()); - //turbineSearchRadius_.sync_host(); - auto radius = turbineSearchRadius_; - auto boundSpheres = CreateBoundingSpheres(points,radius); - auto elemBoxes = CreateElementBoxes(stkBulk, actMeta.searchTargetNames_); - - // the coarse search now associates element boxes with turbines - ExecuteCoarseSearch( - boundSpheres, elemBoxes, coarseSearchPointIds_, coarseSearchElemIds_, - actMeta.searchMethod_); + // actuator_utils::reduce_view_on_host(turbineSearchRadius_.view_host()); + // turbineSearchRadius_.sync_host(); + auto radius = turbineSearchRadius_; + auto boundSpheres = CreateBoundingSpheres(points, radius); + auto elemBoxes = CreateElementBoxes(stkBulk, actMeta.searchTargetNames_); + + // the coarse search now associates element boxes with turbines + ExecuteCoarseSearch( + boundSpheres, elemBoxes, coarseSearchPointIds_, coarseSearchElemIds_, + actMeta.searchMethod_); } ExecuteFineSearch( stkBulk, coarseSearchPointIds_, coarseSearchElemIds_, points, elemContainingPoint_, localCoords_, pointIsLocal_, localParallelRedundancy_); - } Kokkos::RangePolicy diff --git a/src/aero/actuator/ActuatorExecutorsFASTNgp.C b/src/aero/actuator/ActuatorExecutorsFASTNgp.C index f82c43657..d6fbb50e4 100644 --- a/src/aero/actuator/ActuatorExecutorsFASTNgp.C +++ b/src/aero/actuator/ActuatorExecutorsFASTNgp.C @@ -25,16 +25,16 @@ ActuatorLineFastNGP::ActuatorLineFastNGP( void ActuatorLineFastNGP::operator()() { - //Zero the (body-force) actuator source term + // Zero the (body-force) actuator source term actBulk_.zero_source_terms(stkBulk_); //set range policy to only operating over points owned by local fast turbine auto fastRangePolicy = actBulk_.local_range_policy(); - //Interpolate velocity to actuator points. + // Interpolate velocity to actuator points. RunInterpActuatorVel(actBulk_, stkBulk_); - // Add FLLC correction to velocity field. + // Add FLLC correction to velocity field. apply_fllc(actBulk_); Kokkos::parallel_for( @@ -44,17 +44,17 @@ ActuatorLineFastNGP::operator()() // get relative velocity from openFAST ActFastCacheRelativeVelocities(actBulk_); - // Compute filtered lifting line correction + // Compute filtered lifting line correction compute_fllc(); // Send interpolated velocities at actuator points to openFAST actBulk_.interpolate_velocities_to_fast(); - // Get actuator point centroids + // Get actuator point centroids RunActFastUpdatePoints(actBulk_); - // Execute fine and coarse search given point centroids - actBulk_.stk_search(actMeta_, stkBulk_); + // Execute fine and coarse search given point centroids + actBulk_.stk_search(actMeta_, stkBulk_); // call openfast and step actBulk_.step_fast(); @@ -124,7 +124,7 @@ ActuatorDiskFastNGP::operator()() actBulk_.update_ADM_points(actMeta_); - actBulk_.stk_search(actMeta_, stkBulk_,true); + actBulk_.stk_search(actMeta_, stkBulk_, true); } actBulk_.step_fast(); diff --git a/src/aero/actuator/ActuatorFunctors.C b/src/aero/actuator/ActuatorFunctors.C index 7065a34d9..e5a31463c 100644 --- a/src/aero/actuator/ActuatorFunctors.C +++ b/src/aero/actuator/ActuatorFunctors.C @@ -91,11 +91,11 @@ SpreadForceInnerLoop::operator()( actuator_utils::compute_distance( 3, nodeCoords, pointCoords.data(), &distance[0]); - //Check distance between actuator point and element centroid. Only needed if singlePointCoarseSearch_==False - //auto epsilonRadius = - // Kokkos::subview(actBulk_.searchRadius_.view_host(), pointId, Kokkos::ALL); auto epsilonRadius = actBulk_.searchRadius_.h_view(pointId); - if (std::sqrt(distance[0]*distance[0] + distance[1]*distance[1] + distance[2]*distance[2]) < epsilonRadius) { + if ( + std::sqrt( + distance[0] * distance[0] + distance[1] * distance[1] + + distance[2] * distance[2]) < epsilonRadius) { const double gauss = actuator_utils::Gaussian_projection(3, &distance[0], epsilon.data()); diff --git a/src/aero/actuator/ActuatorModel.C b/src/aero/actuator/ActuatorModel.C index b3cd965c9..1ec926739 100644 --- a/src/aero/actuator/ActuatorModel.C +++ b/src/aero/actuator/ActuatorModel.C @@ -145,8 +145,8 @@ ActuatorModel::init(stk::mesh::BulkData& stkBulk) break; #endif #else - //perform stk_search (coarse + fine search) - actBulk_->stk_search(*actMeta_.get(), stkBulk); + // perform stk_search (coarse + fine search) + actBulk_->stk_search(*actMeta_.get(), stkBulk); break; #endif }