29#include "../../../Common/include/parallelization/omp_structure.hpp"
30#include "../../../Common/include/toolboxes/geometry_toolbox.hpp"
42 Smatrix[0][0] = (r12*r12+r22*r22)/detR2;
43 Smatrix[0][1] = -r11*r12/detR2;
44 Smatrix[1][1] = r11*r11/detR2;
61 Smatrix[0][0] = (z11*z11+z12*z12+z13*z13)/detR2;
62 Smatrix[0][1] = (z12*z22+z13*z23)/detR2;
63 Smatrix[0][2] = (z13*z33)/detR2;
64 Smatrix[1][1] = (z22*z22+z23*z23)/detR2;
65 Smatrix[1][2] = (z23*z33)/detR2;
66 Smatrix[2][2] = (z33*z33)/detR2;
75template<
size_t nDim,
bool periodic,
class GradientType,
class RMatrixType>
79 const RMatrixType& Rmatrix,
80 GradientType& gradient)
82 const auto eps =
pow(std::numeric_limits<passivedouble>::epsilon(),2);
96 su2double r13 = 0.0, r23 = 0.0, r33 = 1.0;
98 r11 =
sqrt(max(r11, eps));
100 r22 =
sqrt(max(r22 - r12*r12, eps));
110 r13 = Rmatrix(iPoint,0,2);
111 r33 = Rmatrix(iPoint,2,2);
112 const auto r23_a = Rmatrix(iPoint,1,2);
113 const auto r23_b = Rmatrix(iPoint,2,1);
116 r23 = r23_a/r22 - r23_b*r12/(r11*r22);
117 r33 =
sqrt(max(r33 - r23*r23 - r13*r13, eps));
136 for (
size_t iDim = 0; iDim < nDim; ++iDim)
137 for (
size_t jDim = iDim; jDim < nDim; ++jDim)
144 for (
size_t iVar = varBegin; iVar < varEnd; ++iVar)
148 for (
size_t iDim = 0; iDim < nDim; ++iDim)
149 for (
size_t jDim = 0; jDim < nDim; ++jDim)
150 Cvector[iDim] += Smatrix[min(iDim,jDim)][max(iDim,jDim)] * gradient(iPoint, iVar, jDim);
152 for (
size_t iDim = 0; iDim < nDim; ++iDim)
153 gradient(iPoint, iVar, iDim) = Cvector[iDim];
158 for (
size_t iVar = varBegin; iVar < varEnd; ++iVar)
159 for (
size_t iDim = 0; iDim < nDim; ++iDim)
183template<
size_t nDim,
class FieldType,
class GradientType,
class RMatrixType>
190 const FieldType& field,
191 const size_t varBegin,
194 GradientType& gradient,
195 RMatrixType& Rmatrix)
202 constexpr size_t OMP_MAX_CHUNK = 512;
211 for (
size_t iPoint = 0; iPoint < nPointDomain; ++iPoint)
213 auto nodes = geometry.
nodes;
214 const auto coord_i = nodes->
GetCoord(iPoint);
220 for (
size_t iVar = varBegin; iVar < varEnd; ++iVar)
225 for (
size_t iVar = varBegin; iVar < varEnd; ++iVar)
226 for (
size_t iDim = 0; iDim < nDim; ++iDim)
227 gradient(iPoint, iVar, iDim) = 0.0;
229 for (
size_t iDim = 0; iDim < nDim; ++iDim)
230 for (
size_t jDim = 0; jDim < nDim; ++jDim)
231 Rmatrix(iPoint, iDim, jDim) = 0.0;
234 for (
auto jPoint : nodes->GetPoints(iPoint))
255 weight = 1.0 / weight;
257 for (
size_t iDim = 0; iDim < nDim; ++iDim)
258 for (
size_t jDim = iDim; jDim < nDim; ++jDim)
259 Rmatrix(iPoint,iDim,jDim) += dist_ij[iDim]*dist_ij[jDim]*weight;
262 Rmatrix(iPoint,2,1) += dist_ij[0]*dist_ij[nDim-1]*weight;
266 for (
size_t iVar = varBegin; iVar < varEnd; ++iVar)
270 su2double delta_ij = weight * (field(jPoint,iVar) - field(iPoint,iVar));
272 for (
size_t iDim = 0; iDim < nDim; ++iDim)
273 gradient(iPoint, iVar, iDim) += dist_ij[iDim] * delta_ij;
282 for (
size_t iDim = 0; iDim < nDim; ++iDim)
283 for (
size_t jDim = 0; jDim < nDim; ++jDim)
286 for (
size_t iVar = varBegin; iVar < varEnd; ++iVar)
287 for (
size_t iDim = 0; iDim < nDim; ++iDim)
295 solveLeastSquares<nDim, false>(iPoint, varBegin, varEnd, Rmatrix, gradient);
313 for (
size_t iPoint = 0; iPoint < nPointDomain; ++iPoint)
314 solveLeastSquares<nDim, true>(iPoint, varBegin, varEnd, Rmatrix, gradient);
320 correctGradientsSymmetry<nDim>(geometry, config, varBegin, varEnd, idxVel, gradient);
324 if (solver !=
nullptr)
339template<
class FieldType,
class GradientType,
class RMatrixType>
346 const FieldType& field,
347 const size_t varBegin,
350 GradientType& gradient,
351 RMatrixType& Rmatrix) {
354 detail::computeGradientsLeastSquares<2>(solver, kindMpiComm, kindPeriodicComm, geometry, config,
355 weighted, field, varBegin, varEnd, idxVel, gradient, Rmatrix);
358 detail::computeGradientsLeastSquares<3>(solver, kindMpiComm, kindPeriodicComm, geometry, config,
359 weighted, field, varBegin, varEnd, idxVel, gradient, Rmatrix);
static void Error(const std::string &ErrorMsg, const std::string &FunctionName)
Definition mpi_structure.cpp:131
Main class for defining the problem; basically this class reads the configuration file,...
Definition CConfig.hpp:64
unsigned short GetnMarker_Periodic(void) const
Get the total number of periodic markers.
Definition CConfig.hpp:3309
Parent class for defining the geometry of the problem (complete geometry, multigrid agglomerated geom...
Definition CGeometry.hpp:75
CPoint * nodes
Node vector (dual grid information).
Definition CGeometry.hpp:253
unsigned long GetnPointDomain() const
Get number of real points (that belong to the domain).
Definition CGeometry.hpp:593
unsigned short GetnDim() const
Get number of coordinates.
Definition CGeometry.hpp:575
su2double GetCoord(unsigned long iPoint, unsigned long iDim) const
Get the coordinates dor the control volume.
Definition CPoint.hpp:158
Definition CSolver.hpp:71
void InitiatePeriodicComms(CGeometry *geometry, const CConfig *config, unsigned short val_periodic_index, unsigned short commType)
Routine to load a solver quantity into the data structures for MPI periodic communication and to laun...
Definition CSolver.cpp:368
void CompleteComms(CGeometry *geometry, const CConfig *config, MPI_QUANTITIES commType)
Routine to complete the set of non-blocking communications launched by InitiateComms() and unpacking ...
Definition CSolver.cpp:1724
void CompletePeriodicComms(CGeometry *geometry, const CConfig *config, unsigned short val_periodic_index, unsigned short commType)
Routine to complete the set of non-blocking periodic communications launched by InitiatePeriodicComms...
Definition CSolver.cpp:1113
void InitiateComms(CGeometry *geometry, const CConfig *config, MPI_QUANTITIES commType)
Routine to load a solver quantity into the data structures for MPI point-to-point communication and t...
Definition CSolver.cpp:1563
#define FORCEINLINE
Definition code_config.hpp:44
passivedouble su2double
Definition code_config.hpp:181
Implements the symmetry boundary conditions for the gradient computations.
void computeGradientsLeastSquares(CSolver *solver, MPI_QUANTITIES kindMpiComm, PERIODIC_QUANTITIES kindPeriodicComm, CGeometry &geometry, const CConfig &config, bool weighted, const FieldType &field, const size_t varBegin, const size_t varEnd, const int idxVel, GradientType &gradient, RMatrixType &Rmatrix)
Compute the gradient of a field using inverse-distance-weighted or unweighted Least-Squares approxima...
Definition computeGradientsLeastSquares.hpp:184
void solveLeastSquares(size_t iPoint, size_t varBegin, size_t varEnd, const RMatrixType &Rmatrix, GradientType &gradient)
Solve the least-squares problem for one point.
Definition computeGradientsLeastSquares.hpp:76
void computeSmatrix(su2double r11, su2double r12, su2double r13, su2double r22, su2double r23, su2double r33, su2double detR2, su2double Smatrix[][2])
Prepare Smatrix for 2D.
Definition computeGradientsLeastSquares.hpp:39
void computeGradientsLeastSquares(CSolver *solver, MPI_QUANTITIES kindMpiComm, PERIODIC_QUANTITIES kindPeriodicComm, CGeometry &geometry, const CConfig &config, bool weighted, const FieldType &field, const size_t varBegin, const size_t varEnd, const int idxVel, GradientType &gradient, RMatrixType &Rmatrix)
Instantiations for 2D and 3D.
Definition computeGradientsLeastSquares.hpp:340
FORCEINLINE ARRAY_T sqrt(const ARRAY_T &x)
Definition special_vectorization.hpp:116
FORCEINLINE ARRAY_T pow(const ARRAY_T &a, const ARRAY_T &b)
Definition special_vectorization.hpp:179
#define CURRENT_FUNCTION
Definition mpi_structure.hpp:59
void StartPreacc()
Starts a new preaccumulation section and sets the input variables.
Definition ad_structure.hpp:215
void EndPreacc()
Ends a preaccumulation section and computes the local Jacobi matrix of a code section using the varia...
Definition ad_structure.hpp:243
void SetPreaccOut(Ts &&... data)
Sets the scalar outputs of a preaccumulation section.
Definition ad_structure.hpp:222
void SetPreaccIn(Ts &&... data)
Sets the scalar inputs of a preaccumulation section.
Definition ad_structure.hpp:186
Definition computeGradientsGreenGauss.hpp:37
constexpr int omp_get_num_threads()
Number of threads in current team.
Definition omp_structure.hpp:75
#define END_SU2_OMP_FOR
Definition omp_structure.hpp:158
constexpr int omp_get_max_threads()
Maximum number of threads available.
Definition omp_structure.hpp:70
size_t computeStaticChunkSize(size_t totalWork, size_t numThreads, size_t maxChunkSize)
Compute a chunk size based on totalWork and number of threads such that all threads get the same numb...
Definition omp_structure.hpp:223
#define SU2_OMP_FOR_DYN(CHUNK)
Definition omp_structure.hpp:150
PERIODIC_QUANTITIES
Vertex-based quantities exchanged during periodic marker communications.
Definition option_structure.hpp:2843
MPI_QUANTITIES
Vertex-based quantities exchanged in MPI point-to-point communications.
Definition option_structure.hpp:2873