Skip to content

Commit 18fde7e

Browse files
committed
simplify
1 parent 65e4167 commit 18fde7e

File tree

2 files changed

+25
-40
lines changed

2 files changed

+25
-40
lines changed

Common/include/containers/container_decorators.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ class C3DContainerDecorator {
115115
Index rows() const noexcept { return m_storage.cols() / m_innerSz; }
116116
Index cols() const noexcept { return m_innerSz; }
117117

118+
/*!
119+
* \brief Raw data.
120+
*/
121+
Scalar* data() noexcept { return m_storage.data(); }
122+
const Scalar* data() const noexcept { return m_storage.data(); }
123+
118124
/*!
119125
* \brief Element-wise access.
120126
*/

Common/src/geometry/CGeometry.cpp

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4085,51 +4085,30 @@ void CGeometry::ComputeWallDistance(const CConfig* const* config_container, CGeo
40854085
}
40864086
/*--- Otherwise, set wall roughnesses. ---*/
40874087
if (!allEmpty) {
4088-
/*--- Store all marker wall roughnesses in a common data structure. ---*/
4089-
std::vector<unsigned short> wall_rough_zone, wall_rough_marker;
4090-
std::vector<su2double> wall_rough_val;
4088+
/*--- Store all marker wall roughnesses in a common data structure (rank, zone, marker) -> value. ---*/
4089+
unsigned short nMarkerMax = 0;
4090+
for (auto iZone = 0u; iZone < nZone; ++iZone) {
4091+
nMarkerMax = std::max(nMarkerMax, geometry_container[iZone][iInst][MESH_0]->GetnMarker());
4092+
}
4093+
const auto tmp = nMarkerMax;
4094+
SU2_MPI::Allreduce(&tmp, &nMarkerMax, 1, MPI_UNSIGNED_SHORT, MPI_MAX, SU2_MPI::GetComm());
4095+
4096+
su2activematrix wall_roughness(nZone, nMarkerMax);
40914097
for (auto iZone = 0u; iZone < nZone; ++iZone) {
40924098
const CConfig* config = config_container[iZone];
40934099
for (auto iMarker = 0u; iMarker < geometry_container[iZone][iInst][MESH_0]->GetnMarker(); ++iMarker) {
4094-
wall_rough_zone.push_back(iZone);
4095-
wall_rough_marker.push_back(iMarker);
4096-
wall_rough_val.push_back(config->GetWallRoughnessProperties(config->GetMarker_All_TagBound(iMarker)).second);
4100+
wall_roughness(iZone, iMarker) =
4101+
config->GetWallRoughnessProperties(config->GetMarker_All_TagBound(iMarker)).second;
40974102
}
40984103
}
4099-
/*--- Communicate. ---*/
4100-
const int wall_rough_size = wall_rough_val.size();
4101-
const int mpi_size = SU2_MPI::GetSize();
4102-
std::vector<int> counts(mpi_size);
4103-
SU2_MPI::Allgather(&wall_rough_size, 1, MPI_INT, counts.data(), 1, MPI_INT, SU2_MPI::GetComm());
4104-
std::vector<int> displs(mpi_size + 1, 0);
4105-
for (int i = 1; i <= mpi_size; ++i) displs[i] = displs[i - 1] + counts[i - 1];
4106-
const auto total_size = displs.back();
4107-
4108-
std::vector<unsigned short> all_wall_rough_zone(total_size), all_wall_rough_marker(total_size);
4109-
std::vector<su2double> all_wall_rough_val(total_size);
4110-
4111-
SU2_MPI::Allgatherv(wall_rough_zone.data(), wall_rough_size, MPI_UNSIGNED_SHORT, all_wall_rough_zone.data(),
4112-
counts.data(), displs.data(), MPI_UNSIGNED_SHORT, SU2_MPI::GetComm());
4113-
SU2_MPI::Allgatherv(wall_rough_marker.data(), wall_rough_size, MPI_UNSIGNED_SHORT, all_wall_rough_marker.data(),
4114-
counts.data(), displs.data(), MPI_UNSIGNED_SHORT, SU2_MPI::GetComm());
4115-
SU2_MPI::Allgatherv(wall_rough_val.data(), wall_rough_size, MPI_DOUBLE, all_wall_rough_val.data(),
4116-
counts.data(), displs.data(), MPI_DOUBLE, SU2_MPI::GetComm());
4117-
4118-
/*--- f(iRank, iZone, iMarker) -> roughness value ---*/
4119-
auto wall_rough_func = [&](int iRank, unsigned short iZone, unsigned short iMarker) {
4120-
/*--- Jump based on rank, then linear search for (iZone, iMarker). ---*/
4121-
for (auto k = displs[iRank]; k < displs[iRank + 1]; ++k) {
4122-
if (all_wall_rough_zone[k] == iZone && all_wall_rough_marker[k] == iMarker) {
4123-
return all_wall_rough_val[k];
4124-
}
4125-
}
4126-
SU2_MPI::Error("Failed to find wall roughness value", CURRENT_FUNCTION);
4127-
return su2double{};
4128-
};
4129-
4130-
for(auto jZone=0u; jZone<nZone; jZone++) {
4131-
if (wallDistanceNeeded[jZone] && config_container[jZone]->GetnRoughWall() > 0) {
4132-
geometry_container[jZone][iInst][MESH_0]->nodes->SetWallRoughness(wall_rough_func);
4104+
const auto nRank = SU2_MPI::GetSize();
4105+
C3DDoubleMatrix all_wall_roughness(nRank, nZone, nMarkerMax);
4106+
SU2_MPI::Allgather(wall_roughness.data(), wall_roughness.size(), MPI_DOUBLE, all_wall_roughness.data(),
4107+
wall_roughness.size(), MPI_DOUBLE, SU2_MPI::GetComm());
4108+
4109+
for(auto iZone = 0u; iZone < nZone; ++iZone) {
4110+
if (wallDistanceNeeded[iZone] && config_container[iZone]->GetnRoughWall() > 0) {
4111+
geometry_container[iZone][iInst][MESH_0]->nodes->SetWallRoughness(all_wall_roughness);
41334112
}
41344113
}
41354114
}

0 commit comments

Comments
 (0)