Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Common/include/containers/C2DContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ enum SizeType : size_t {DynamicSize=0};

/*--- Namespace to "hide" helper classes and
functions used by the container class. ---*/
namespace container_helpers
namespace container_details
{
/*!
* \class AccessorImpl
Expand Down Expand Up @@ -147,7 +147,9 @@ class AccessorImpl
bool empty() const noexcept {return size()==0;} \
Scalar_t* data() noexcept {return m_data;} \
const Scalar_t* data() const noexcept {return m_data;} \
Scalar_t* begin() noexcept {return data();} \
const Scalar_t* begin() const noexcept {return data();} \
Scalar_t* end() noexcept {return data()+size();} \
const Scalar_t* end() const noexcept {return data()+size();}

/*!
Expand Down Expand Up @@ -383,12 +385,12 @@ class AccessorImpl<Index_t,Scalar_t,StorageType::RowMajor,AlignSize,1,DynamicSiz
*/
template<typename Index_t, class Scalar_t, StorageType Store, size_t AlignSize, size_t StaticRows, size_t StaticCols>
class C2DContainer :
public container_helpers::AccessorImpl<Index_t,Scalar_t,Store,AlignSize,StaticRows,StaticCols>
public container_details::AccessorImpl<Index_t,Scalar_t,Store,AlignSize,StaticRows,StaticCols>
{
static_assert(std::is_integral<Index_t>::value,"");

private:
using Base = container_helpers::AccessorImpl<Index_t,Scalar_t,Store,AlignSize,StaticRows,StaticCols>;
using Base = container_details::AccessorImpl<Index_t,Scalar_t,Store,AlignSize,StaticRows,StaticCols>;
using Base::m_data;
using Base::m_allocate;
using Base::m_destroy;
Expand Down
57 changes: 57 additions & 0 deletions Common/include/containers/container_decorators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,60 @@ struct C3DDummyMiddleView
return data(i,k);
}
};

/*--- Helper functions to allocate containers of containers. ---*/

/*!
* \brief Allocate a vector of varying-size vectors and initialize with some value.
* \param[in] M - the first index is >=0 and < M
* \param[in] N - the second index is >=0 and < N[first index]
* \param[in,out] X - the vector of vectors
* \param[in] val - the value for initialization, default is 0
* \tparam IndexVector - type of N
* \tparam VectorOfVector - type of X
*/
template<class IndexVector, class VectorOfVector, class Scalar = int>
inline void AllocVectorOfVectors(size_t M, const IndexVector& N, VectorOfVector& X, Scalar val = 0) {
X.resize(M);
for(size_t i = 0; i < M; ++i){
X[i].resize(N[i]);
for (auto& x : X[i]) x = val;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it a bit to try to make it compatible with more types. If I broke anything I'll fix it.
Thanks for all the cleanup.

}
}

/*!
* \overload Deduce outer size from index vector.
*/
template<class IndexVector, class VectorOfVector, class Scalar = int>
inline void AllocVectorOfVectors(const IndexVector& N, VectorOfVector& X, Scalar val = 0) {
auto M = N.size();
AllocVectorOfVectors(M, N, X, val);
Comment on lines +234 to +235

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea with the overload 👍

}

/*!
* \brief Allocate a vector of matrices with varying row count, and initialize with some value.
* \param[in] M - the first index is >=0 and < M
* \param[in] N - the second index is >=0 and < N[first index]
* \param[in] P - the third index is >=0 and < P
* \param[in,out] X - the vector of matrices
* \param[in] val - the value for initialization, default is 0
* \tparam IndexVector - type of N
* \tparam VectorOfMatrix - type of X
*/
template<class IndexVector, class VectorOfMatrix, class Scalar = int>
inline void AllocVectorOfMatrices(size_t M, const IndexVector& N, size_t P, VectorOfMatrix& X, Scalar val=0) {
X.resize(M);
for(size_t i = 0; i < M; ++i){
X[i].resize(N[i],P);
for (auto& x : X[i]) x = val;
}
}

/*!
* \overload Deduce outer size from index vector.
*/
template<class IndexVector, class VectorOfMatrix, class Scalar = int>
inline void AllocVectorOfMatrices(const IndexVector& N, size_t P, VectorOfMatrix& X, Scalar val=0) {
auto M = N.size();
AllocVectorOfMatrices(M, N, P, X, val);
}
1 change: 1 addition & 0 deletions Common/src/CConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7481,6 +7481,7 @@ CConfig::~CConfig(void) {
delete[] Marker_Analyze;
delete[] Marker_WallFunctions;
delete[] Marker_ZoneInterface;
delete[] Marker_CHTInterface;
delete [] Marker_PyCustom;
delete[] Marker_All_SendRecv;

Expand Down
59 changes: 19 additions & 40 deletions SU2_CFD/include/solvers/CFVMFlowSolverBase.inl
Original file line number Diff line number Diff line change
Expand Up @@ -108,40 +108,26 @@ void CFVMFlowSolverBase<V, R>::Allocate(const CConfig& config) {
/*--- LinSysSol will always be init to 0. ---*/
System.SetxIsZero(true);

/*--- Allocates a 2D array with variable "outer" sizes and init to 0. ---*/

auto Alloc2D = [](unsigned long M, const vector<unsigned long>& N, vector<vector<su2double> >& X) {
X.resize(M);
for (unsigned long i = 0; i < M; ++i) X[i].resize(N[i],0.0);
};

/*--- Allocates a 3D array with variable "middle" sizes and init to 0. ---*/

auto Alloc3D = [](unsigned long M, const vector<unsigned long>& N, unsigned long P, vector<su2activematrix>& X) {
X.resize(M);
for (unsigned long i = 0; i < M; ++i) X[i].resize(N[i],P) = su2double(0.0);
};

/*--- Store the value of the characteristic primitive variables at the boundaries ---*/

Alloc3D(nMarker, nVertex, nPrimVar, CharacPrimVar);
AllocVectorOfMatrices(nVertex, nPrimVar, CharacPrimVar);

/*--- Store the value of the Total Pressure at the inlet BC ---*/

Alloc2D(nMarker, nVertex, Inlet_Ttotal);
AllocVectorOfVectors(nVertex, Inlet_Ttotal);

/*--- Store the value of the Total Temperature at the inlet BC ---*/

Alloc2D(nMarker, nVertex, Inlet_Ptotal);
AllocVectorOfVectors(nVertex, Inlet_Ptotal);

/*--- Store the value of the Flow direction at the inlet BC ---*/

Alloc3D(nMarker, nVertex, nDim, Inlet_FlowDir);
AllocVectorOfMatrices(nVertex, nDim, Inlet_FlowDir);

/*--- Force definition and coefficient arrays for all of the markers ---*/

Alloc2D(nMarker, nVertex, CPressure);
Alloc2D(nMarker, nVertex, CPressureTarget);
AllocVectorOfVectors(nVertex, CPressure);
AllocVectorOfVectors(nVertex, CPressureTarget);

/*--- Non dimensional aerodynamic coefficients ---*/

Expand Down Expand Up @@ -179,42 +165,35 @@ void CFVMFlowSolverBase<V, R>::Allocate(const CConfig& config) {

/*--- Heat flux in all the markers ---*/

Alloc2D(nMarker, nVertex, HeatFlux);
Alloc2D(nMarker, nVertex, HeatFluxTarget);
AllocVectorOfVectors(nVertex, HeatFlux);
AllocVectorOfVectors(nVertex, HeatFluxTarget);

/*--- Y plus in all the markers ---*/

Alloc2D(nMarker, nVertex, YPlus);
AllocVectorOfVectors(nVertex, YPlus);

/*--- Skin friction in all the markers ---*/

Alloc3D(nMarker, nVertex, nDim, CSkinFriction);
AllocVectorOfMatrices(nVertex, nDim, CSkinFriction);

/*--- Wall Shear Stress in all the markers ---*/

Alloc2D(nMarker, nVertex, WallShearStress);
AllocVectorOfVectors(nVertex, WallShearStress);

/*--- Store the values of the temperature and the heat flux density at the boundaries,
used for coupling with a solid donor cell ---*/
constexpr auto nHeatConjugateVar = 4u;

Alloc3D(nMarker, nVertex, nHeatConjugateVar, HeatConjugateVar);
for (auto& x : HeatConjugateVar) x = config.GetTemperature_FreeStreamND();
AllocVectorOfMatrices(nVertex, nHeatConjugateVar, HeatConjugateVar, config.GetTemperature_FreeStreamND());

if (MGLevel == MESH_0) {
VertexTraction.resize(nMarker);
for (unsigned long iMarker = 0; iMarker < nMarker; iMarker++) {
if (config.GetSolid_Wall(iMarker))
VertexTraction[iMarker].resize(nVertex[iMarker], nDim) = su2double(0.0);
}
auto nSolidVertex = nVertex;
for (unsigned long iMarker = 0; iMarker < nMarker; iMarker++)
if (!config.GetSolid_Wall(iMarker))
nSolidVertex[iMarker] = 0;

if (config.GetDiscrete_Adjoint()) {
VertexTractionAdjoint.resize(nMarker);
for (unsigned long iMarker = 0; iMarker < nMarker; iMarker++) {
if (config.GetSolid_Wall(iMarker))
VertexTractionAdjoint[iMarker].resize(nVertex[iMarker], nDim) = su2double(0.0);
}
}
AllocVectorOfMatrices(nSolidVertex, nDim, VertexTraction);

if (config.GetDiscrete_Adjoint()) AllocVectorOfMatrices(nSolidVertex, nDim, VertexTractionAdjoint);
}

/*--- Initialize the BGS residuals in FSI problems. ---*/
Expand Down
21 changes: 16 additions & 5 deletions SU2_CFD/include/solvers/CHeatSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,23 @@
*/
class CHeatSolver final : public CSolver {
protected:
static constexpr size_t MAXNDIM = 3; /*!< \brief Max number of space dimensions, used in some static arrays. */
static constexpr size_t MAXNVAR = 1; /*!< \brief Max number of variables, for static arrays. */

unsigned short nVarFlow, nMarker, CurrentMesh;
su2double **HeatFlux, *HeatFlux_per_Marker, *Surface_HF, Total_HeatFlux, AllBound_HeatFlux,
*AverageT_per_Marker, Total_AverageT, AllBound_AverageT,
*Primitive, *Primitive_Flow_i, *Primitive_Flow_j,
*Surface_Areas, Total_HeatFlux_Areas, Total_HeatFlux_Areas_Monitor;
su2double ***ConjugateVar, ***InterfaceVar;
vector<vector<su2double> > HeatFlux;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe someone could add /*!< \brief comments */.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yes I can do that, I already worked on the output of the heatsolver ... but I put that on the long bench. I am not sure if all those containers are necessary.
I'll add a commit tomorrow 👍

vector<su2double> HeatFlux_per_Marker;
su2double Total_HeatFlux;
su2double AllBound_HeatFlux;
vector<su2double> AverageT_per_Marker;
su2double Total_AverageT;
su2double AllBound_AverageT;
vector<su2double> Primitive_Flow_i;
vector<su2double> Primitive_Flow_j;
vector<su2double> Surface_Areas;
su2double Total_HeatFlux_Areas;
su2double Total_HeatFlux_Areas_Monitor;
vector<su2activematrix> ConjugateVar;

CHeatVariable* nodes = nullptr; /*!< \brief The highest level in the variable hierarchy this solver can safely use. */

Expand Down
28 changes: 7 additions & 21 deletions SU2_CFD/src/solvers/CEulerSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,10 @@ CEulerSolver::CEulerSolver(CGeometry *geometry, CConfig *config,
cout << "Explicit scheme. No Jacobian structure (" << description << "). MG level: " << iMesh <<"." << endl;
}

/*--- Allocates a 2D array with variable "outer" sizes and init to 0. ---*/

auto Alloc2D = [](unsigned long M, const vector<unsigned long>& N, vector<vector<su2double> >& X) {
X.resize(M);
for(unsigned long i = 0; i < M; ++i) X[i].resize(N[i], 0.0);
};

/*--- Allocates a 3D array with variable "middle" sizes and init to 0. ---*/

auto Alloc3D = [](unsigned long M, const vector<unsigned long>& N, unsigned long P, vector<su2activematrix>& X) {
X.resize(M);
for(unsigned long i = 0; i < M; ++i) X[i].resize(N[i],P) = su2double(0.0);
};

/*--- Store the value of the primitive variables + 2 turb variables at the boundaries,
used for IO with a donor cell ---*/

Alloc3D(nMarker, nVertex, (rans? nPrimVar+2 : nPrimVar), DonorPrimVar);
AllocVectorOfMatrices(nVertex, (rans? nPrimVar+2 : nPrimVar), DonorPrimVar);

/*--- Store the value of the characteristic primitive variables index at the boundaries ---*/

Expand All @@ -208,18 +194,18 @@ CEulerSolver::CEulerSolver(CGeometry *geometry, CConfig *config,
ActDisk_Axis.resize(nMarker, MAXNDIM);

/*--- Actuator Disk Fa, Fx, Fy and Fz allocations ---*/
Alloc2D(nMarker, nVertex, ActDisk_Fa);
Alloc2D(nMarker, nVertex, ActDisk_Fx);
Alloc2D(nMarker, nVertex, ActDisk_Fy);
Alloc2D(nMarker, nVertex, ActDisk_Fz);
AllocVectorOfVectors(nVertex, ActDisk_Fa);
AllocVectorOfVectors(nVertex, ActDisk_Fx);
AllocVectorOfVectors(nVertex, ActDisk_Fy);
AllocVectorOfVectors(nVertex, ActDisk_Fz);

/*--- Store the value of the Delta P at the Actuator Disk ---*/

Alloc2D(nMarker, nVertex, ActDisk_DeltaP);
AllocVectorOfVectors(nVertex, ActDisk_DeltaP);

/*--- Store the value of the Delta T at the Actuator Disk ---*/

Alloc2D(nMarker, nVertex, ActDisk_DeltaT);
AllocVectorOfVectors(nVertex, ActDisk_DeltaT);

/*--- Supersonic coefficients ---*/

Expand Down
Loading