Skip to content

Commit

Permalink
Correcting formatting and generalize collective actuator point search…
Browse files Browse the repository at this point in the history
…ing name
  • Loading branch information
gyalla committed Jul 15, 2024
1 parent f38cfca commit 64e6fa6
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 85 deletions.
6 changes: 4 additions & 2 deletions include/aero/actuator/ActuatorBulk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -102,7 +104,7 @@ struct ActuatorBulk
ActFixElemIds elemContainingPoint_;

const int localTurbineId_;
bool singlePointCoarseSearch_ = false;
bool singlePointCoarseSearch_ = false;
};

} // namespace nalu
Expand Down
12 changes: 8 additions & 4 deletions include/aero/actuator/ActuatorBulkFAST.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,23 @@ 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();

ActFixVectorDbl turbineThrust_;
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_;

Expand Down
1 change: 0 additions & 1 deletion include/aero/actuator/ActuatorFunctors.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#ifndef ACTUATORFUNCTORS_H_
#define ACTUATORFUNCTORS_H_

#include <aero/actuator/ActuatorGenericTurbineSearchFunctor.h>
#include <aero/actuator/ActuatorGenericSearchFunctor.h>
#include <aero/actuator/ActuatorBulk.h>
#include <FieldTypeDef.h>
Expand Down
2 changes: 1 addition & 1 deletion include/aero/actuator/ActuatorFunctorsFAST.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
24 changes: 8 additions & 16 deletions include/aero/actuator/ActuatorGenericSearchFunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace sierra {
namespace nalu {

template <typename ActuatorBulk, typename functor>
//coarse search actuatorbulk.c L96
struct GenericLoopOverCoarseSearchResults
{
using execution_space = ActuatorFixedExecutionSpace;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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]);
}
}

}
}

Expand All @@ -148,7 +141,6 @@ struct GenericLoopOverCoarseSearchResults
VectorFieldType* actuatorSource_;
ScalarFieldType* dualNodalVolume_;
functor innerLoopFunctor_;
//const size_t innerLoopExtent_;
};

} // namespace nalu
Expand Down
10 changes: 6 additions & 4 deletions src/aero/actuator/ActuatorBulk.C
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
88 changes: 45 additions & 43 deletions src/aero/actuator/ActuatorBulkFAST.C
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ ActuatorMetaFAST::is_disk()
return actuatorType_ == ActuatorType::ActDiskFASTNGP;
}



ActuatorBulkFAST::ActuatorBulkFAST(
const ActuatorMetaFAST& actMeta, double naluTimeStep)
: ActuatorBulk(actMeta),
Expand Down Expand Up @@ -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<ActuatorFixedExecutionSpace>
Expand Down
16 changes: 8 additions & 8 deletions src/aero/actuator/ActuatorExecutorsFASTNgp.C
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/aero/actuator/ActuatorFunctors.C
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
4 changes: 2 additions & 2 deletions src/aero/actuator/ActuatorModel.C
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 64e6fa6

Please sign in to comment.