Skip to content

Commit 139040f

Browse files
committed
cleanup
1 parent 279148d commit 139040f

5 files changed

Lines changed: 64 additions & 42 deletions

File tree

Common/include/ad_structure.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ namespace AD{
250250
inline void Push_TapePosition() {}
251251

252252
#else
253-
typedef codi::DataStore CheckpointHandler;
253+
using CheckpointHandler = codi::DataStore;
254254

255-
typedef su2double::TapeType Tape;
255+
using Tape = su2double::TapeType;
256256

257-
typedef codi::ExternalFunctionHelper<su2double> ExtFuncHelper;
257+
using ExtFuncHelper = codi::ExternalFunctionHelper<su2double>;
258258

259259
extern ExtFuncHelper* FuncHelper;
260260

Common/include/datatype_structure.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ namespace SU2_TYPE {
183183
* \param[in] data - The non-primitive datatype.
184184
* \return - The primary value casted to int.
185185
*/
186-
FORCEINLINE int Int(const su2double& data) {return int(SU2_TYPE::GetValue(data));}
186+
FORCEINLINE int Int(const su2double& data) {return static_cast<int>(SU2_TYPE::GetValue(data));}
187187

188188
/*!
189189
* \brief Casts the primitive value to short (uses GetValue, already implemented for each type).
190190
* \param[in] data - The non-primitive datatype.
191191
* \return - The primary value casted to short.
192192
*/
193-
FORCEINLINE short Short(const su2double& data) {return short(SU2_TYPE::GetValue(data));}
193+
FORCEINLINE short Short(const su2double& data) {return static_cast<short>(SU2_TYPE::GetValue(data));}
194194

195195
/*--- Special handling of the sprintf routine for non-primitive types. ---*/
196196
/*--- Pass-through for built-in types. ---*/

Common/include/grid_movement_structure.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,13 +947,18 @@ class CVolumetricMovement : public CGridMovement {
947947
unsigned short nDim; /*!< \brief Number of dimensions. */
948948
unsigned short nVar; /*!< \brief Number of variables. */
949949

950-
unsigned long nPoint; /*!< \brief Number of points. */
950+
unsigned long nPoint; /*!< \brief Number of points. */
951951
unsigned long nPointDomain; /*!< \brief Number of points in the domain. */
952952

953953
unsigned long nIterMesh; /*!< \brief Number of iterations in the mesh update. +*/
954954

955+
#ifndef CODI_FORWARD_TYPE
956+
CSysMatrix<su2mixedfloat> StiffMatrix; /*!< \brief Stiffness matrix of the elasticity problem. */
957+
CSysSolve<su2mixedfloat> System; /*!< \brief Linear solver/smoother. */
958+
#else
959+
CSysMatrix<su2double> StiffMatrix;
955960
CSysSolve<su2double> System;
956-
CSysMatrix<su2double> StiffMatrix; /*!< \brief Matrix to store the point-to-point stiffness. */
961+
#endif
957962
CSysVector<su2double> LinSysSol;
958963
CSysVector<su2double> LinSysRes;
959964

Common/include/linear_algebra/CSysMatrix.hpp

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ class CSysMatrix {
432432
}
433433

434434
/*!
435-
* \brief Set the value of a block in the sparse matrix with scaling.
435+
* \brief Set the value of a block (in flat format) in the sparse matrix with scaling.
436+
* \note If the template param Overwrite is false we add to the block (bij += alpha*b).
436437
* \param[in] block_i - Row index.
437438
* \param[in] block_j - Column index.
438439
* \param[in] val_block - Block to set to A(i, j).
@@ -451,7 +452,7 @@ class CSysMatrix {
451452
}
452453

453454
/*!
454-
* \brief Add a scaled block (in flat format) to the sparse matrix.
455+
* \brief Add a scaled block (in flat format) to the sparse matrix (see SetBlock).
455456
* \param[in] block_i - Row index.
456457
* \param[in] block_j - Column index.
457458
* \param[in] val_block - Block to set to A(i, j).
@@ -460,55 +461,61 @@ class CSysMatrix {
460461
template<class OtherType,
461462
typename enable_if<!is_pointer<OtherType>::value,bool>::type = 0>
462463
inline void AddBlock(unsigned long block_i, unsigned long block_j,
463-
OtherType alpha, const OtherType *val_block) {
464+
const OtherType *val_block, OtherType alpha = 1.0) {
464465
SetBlock<OtherType,false>(block_i, block_j, val_block, alpha);
465466
}
466467

467468
/*!
468-
* \brief Set the value of a block in the sparse matrix.
469+
* \brief Set the value of a scaled block in the sparse matrix.
470+
* \note If the template param Overwrite is false we add to the block (bij += alpha*b).
469471
* \param[in] block_i - Row index.
470472
* \param[in] block_j - Column index.
471473
* \param[in] val_block - Block to set to A(i, j).
474+
* \param[in] alpha - Scale factor.
472475
*/
473-
template<class OtherType, int Sign = 1, bool Overwrite = true>
474-
inline void SetBlock(unsigned long block_i, unsigned long block_j, const OtherType* const* val_block) {
476+
template<class OtherType, bool Overwrite = true>
477+
inline void SetBlock(unsigned long block_i, unsigned long block_j,
478+
const OtherType* const* val_block, OtherType alpha = 1.0) {
475479

476480
auto mat_ij = GetBlock(block_i, block_j);
477481
if (!mat_ij) return;
478482
for (auto iVar = 0ul; iVar < nVar; ++iVar) {
479483
for (auto jVar = 0ul; jVar < nEqn; ++jVar) {
480-
*mat_ij = (Overwrite? ScalarType(0) : *mat_ij) + Sign * PassiveAssign(val_block[iVar][jVar]);
484+
*mat_ij = (Overwrite? ScalarType(0) : *mat_ij) + PassiveAssign(alpha * val_block[iVar][jVar]);
481485
++mat_ij;
482486
}
483487
}
484488
}
485489

486490
/*!
487-
* \brief Adds the specified block to the sparse matrix.
491+
* \brief Adds a scaled block to the sparse matrix (see SetBlock).
488492
* \param[in] block_i - Row index.
489493
* \param[in] block_j - Column index.
490494
* \param[in] val_block - Block to add to A(i, j).
495+
* \param[in] alpha - Scale factor.
491496
*/
492497
template<class OtherType>
493-
inline void AddBlock(unsigned long block_i, unsigned long block_j, const OtherType* const* val_block) {
494-
SetBlock<OtherType,1,false>(block_i, block_j, val_block);
498+
inline void AddBlock(unsigned long block_i, unsigned long block_j,
499+
const OtherType* const* val_block, OtherType alpha = 1.0) {
500+
SetBlock<OtherType,false>(block_i, block_j, val_block, alpha);
495501
}
496502

497503
/*!
498-
* \brief Subtracts the specified block to the sparse matrix.
504+
* \brief Subtracts the specified block to the sparse matrix (see AddBlock).
499505
* \param[in] block_i - Row index.
500506
* \param[in] block_j - Column index.
501507
* \param[in] val_block - Block to subtract to A(i, j).
502508
*/
503509
template<class OtherType>
504510
inline void SubtractBlock(unsigned long block_i, unsigned long block_j, const OtherType* const* val_block) {
505-
SetBlock<OtherType,-1,false>(block_i, block_j, val_block);
511+
AddBlock(block_i, block_j, val_block, OtherType(-1));
506512
}
507513

508514
/*!
509515
* \brief Update 4 blocks ii, ij, ji, jj (add to i* sub from j*).
510516
* \note The template parameter Sign, can be used create a "subtractive"
511517
* update i.e. subtract from row i and add to row j instead.
518+
* This method assumes an FVM-type sparse pattern.
512519
* \param[in] edge - Index of edge that connects iPoint and jPoint.
513520
* \param[in] iPoint - Row to which we add the blocks.
514521
* \param[in] jPoint - Row from which we subtract the blocks.
@@ -547,17 +554,18 @@ class CSysMatrix {
547554
}
548555

549556
/*!
550-
* \brief Update 2 blocks ij and ji (add to i* sub from j*).
557+
* \brief Sets 2 blocks ij and ji (add to i* sub from j*) associated with
558+
* one edge of an FVM-type sparse pattern.
551559
* \note The template parameter Sign, can be used create a "subtractive"
552560
* update i.e. subtract from row i and add to row j instead.
553561
* The parameter Overwrite allows completely writing over the
554-
* current values held by the matrix.
562+
* current values held by the matrix (true), or updating them (false).
555563
* \param[in] edge - Index of edge that connects iPoint and jPoint.
556564
* \param[in] block_i - Subs from ji.
557565
* \param[in] block_j - Adds to ij.
558566
*/
559-
template<class OtherType, int Sign = 1, bool Overwrite = false>
560-
inline void UpdateBlocks(unsigned long iEdge, const OtherType* const* block_i, const OtherType* const* block_j) {
567+
template<class OtherType, int Sign = 1, bool Overwrite = true>
568+
inline void SetBlocks(unsigned long iEdge, const OtherType* const* block_i, const OtherType* const* block_j) {
561569

562570
ScalarType *bij = &matrix[edge_ptr(iEdge,0)*nVar*nEqn];
563571
ScalarType *bji = &matrix[edge_ptr(iEdge,1)*nVar*nEqn];
@@ -574,46 +582,55 @@ class CSysMatrix {
574582
}
575583

576584
/*!
577-
* \brief Short-hand for the "subtractive" version (sub from i* add to j*) of UpdateBlocks.
585+
* \brief Short-hand for the "additive overwrite" version of SetBlocks.
578586
*/
579587
template<class OtherType>
580-
inline void UpdateBlocksSub(unsigned long iEdge, const OtherType* const* block_i, const OtherType* const* block_j) {
581-
UpdateBlocks<OtherType,-1>(iEdge, block_i, block_j);
588+
inline void UpdateBlocks(unsigned long iEdge, const OtherType* const* block_i, const OtherType* const* block_j) {
589+
SetBlocks<OtherType,1,false>(iEdge, block_i, block_j);
582590
}
583591

584592
/*!
585-
* \brief Short-hand for the "additive overwrite" version of UpdateBlocks.
593+
* \brief Short-hand for the "subtractive" version (sub from i* add to j*) of SetBlocks.
586594
*/
587595
template<class OtherType>
588-
inline void SetBlocks(unsigned long iEdge, const OtherType* const* block_i, const OtherType* const* block_j) {
589-
UpdateBlocks<OtherType,1,true>(iEdge, block_i, block_j);
596+
inline void UpdateBlocksSub(unsigned long iEdge, const OtherType* const* block_i, const OtherType* const* block_j) {
597+
SetBlocks<OtherType,-1,false>(iEdge, block_i, block_j);
590598
}
591599

592600
/*!
593-
* \brief Adds the specified block to the (i, i) subblock of the matrix-by-blocks structure.
601+
* \brief Sets the specified block to the (i, i) subblock of the sparse matrix.
602+
* Scales the input block by factor alpha. If the Overwrite parameter is
603+
* false we update instead (bii += alpha*b).
594604
* \param[in] block_i - Diagonal index.
595605
* \param[in] val_block - Block to add to the diagonal of the matrix.
606+
* \param[in] alpha - Scale factor.
596607
*/
597-
template<class OtherType, int Sign = 1>
598-
inline void AddBlock2Diag(unsigned long block_i, const OtherType* const* val_block) {
608+
template<class OtherType, bool Overwrite = true>
609+
inline void SetBlock2Diag(unsigned long block_i, const OtherType* const* val_block, OtherType alpha = 1.0) {
599610

600-
ScalarType *bii = &matrix[dia_ptr[block_i]*nVar*nEqn];
611+
auto mat_ii = &matrix[dia_ptr[block_i]*nVar*nEqn];
601612

602-
unsigned long iVar, jVar, offset = 0;
613+
for (auto iVar = 0ul; iVar < nVar; iVar++)
614+
for (auto jVar = 0ul; jVar < nEqn; jVar++) {
615+
*mat_ii = (Overwrite? ScalarType(0) : *mat_ii) + PassiveAssign(alpha * val_block[iVar][jVar]);
616+
++mat_ii;
617+
}
618+
}
603619

604-
for (iVar = 0; iVar < nVar; iVar++)
605-
for (jVar = 0; jVar < nEqn; jVar++)
606-
bii[offset++] += Sign * PassiveAssign(val_block[iVar][jVar]);
620+
/*!
621+
* \brief Non overwrite version of SetBlock2Diag, also with scaling.
622+
*/
623+
template<class OtherType>
624+
inline void AddBlock2Diag(unsigned long block_i, const OtherType* const* val_block, OtherType alpha = 1.0) {
625+
SetBlock2Diag<OtherType,false>(block_i, val_block, alpha);
607626
}
608627

609628
/*!
610-
* \brief Subtracts the specified block from the (i, i) subblock of the matrix-by-blocks structure.
611-
* \param[in] block_i - Diagonal index.
612-
* \param[in] val_block - Block to subtract from the diagonal of the matrix.
629+
* \brief Short-hand to AddBlock2Diag with alpha = -1, i.e. subtracts from the current diagonal.
613630
*/
614631
template<class OtherType>
615632
inline void SubtractBlock2Diag(unsigned long block_i, const OtherType* const* val_block) {
616-
AddBlock2Diag<OtherType,-1>(block_i, val_block);
633+
AddBlock2Diag(block_i, val_block, OtherType(-1));
617634
}
618635

619636
/*!

SU2_CFD/src/solvers/CFEASolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ void CFEASolver::Compute_StiffMatrix(CGeometry *geometry, CNumerics **numerics,
921921

922922
for (jNode = 0; jNode < nNodes; jNode++) {
923923
auto Kab = element->Get_Kab(iNode, jNode);
924-
Jacobian.AddBlock(indexNode[iNode], indexNode[jNode], simp_penalty, Kab);
924+
Jacobian.AddBlock(indexNode[iNode], indexNode[jNode], Kab, simp_penalty);
925925
}
926926

927927
if (LockStrategy) omp_unset_lock(&UpdateLocks[indexNode[iNode]]);

0 commit comments

Comments
 (0)