Skip to content

Commit 3c9f9bb

Browse files
committed
Add Myles' fix to WA interface
1 parent 0ab83dd commit 3c9f9bb

2 files changed

Lines changed: 154 additions & 11 deletions

File tree

Common/include/interface_interpolation/CSlidingMesh.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*!
1+
/*!
22
* \file CSlidingMesh.hpp
33
* \brief Sliding mesh interpolation.
44
* \author H. Kline
@@ -67,6 +67,21 @@ class CSlidingMesh final : public CInterpolator {
6767
const unsigned long* nNeighbor, const su2double *coord,
6868
unsigned long centralNode, su2double** element);
6969

70+
/*!
71+
* \brief For 3-Dimensional grids, build the dual surface element
72+
* \param[in] map - array containing the index of the boundary points connected to the node
73+
* \param[in] startIndex - for each vertex specifies the corresponding index in the global
74+
* array containing the indexes of all its neighbouring vertexes
75+
* \param[in] nNeighbour - for each vertex specifies the number of its neighbouring vertexes (on the boundary)
76+
* \param[in] coord - array containing the coordinates of all the boundary vertexes
77+
* \param[in] centralNode - label of the vertex around which the dual surface element is built
78+
* \param[out] element - double array where element node coordinates will be stored
79+
* \return Number of points included in the element.
80+
*/
81+
static int Build_DualElement(const unsigned long *map, const unsigned long *startIndex,
82+
const unsigned long* nNeighbor, const su2double *coord,
83+
unsigned long centralNode, su2double** element);
84+
7085
/*!
7186
* \brief For 2-Dimensional grids, compute intersection length of two segments projected along a given direction
7287
* \param[in] nDim - Number of dimensions

Common/src/interface_interpolation/CSlidingMesh.cpp

Lines changed: 138 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,15 @@ void CSlidingMesh::SetTransferCoeff(const CConfig* const* config) {
469469

470470
nEdges_target = Target_nLinkedNodes[target_iPoint];
471471

472-
nNode_target = 2*(nEdges_target + 1);
473-
474-
target_element = new su2double*[nNode_target];
475-
for (ii = 0; ii < nNode_target; ii++)
472+
target_element = new su2double*[ 2*nEdges_target + 2 ];
473+
for (ii = 0; ii < 2*nEdges_target + 2; ii++)
476474
target_element[ii] = new su2double[nDim];
477475

478-
nNode_target = Build_3D_surface_element(Target_LinkedNodes, Target_StartLinkedNodes, Target_nLinkedNodes,
479-
TargetPoint_Coord, target_iPoint, target_element);
476+
// nNode_target = Build_3D_surface_element(Target_LinkedNodes, Target_StartLinkedNodes, Target_nLinkedNodes,
477+
// TargetPoint_Coord, target_iPoint, target_element);
478+
479+
nNode_target = Build_DualElement(Target_LinkedNodes, Target_StartLinkedNodes, Target_nLinkedNodes,
480+
TargetPoint_Coord, target_iPoint, target_element);
480481

481482
/*--- Brute force to find the closest donor_node ---*/
482483

@@ -508,8 +509,11 @@ void CSlidingMesh::SetTransferCoeff(const CConfig* const* config) {
508509
for (ii = 0; ii < 2*nEdges_donor + 2; ii++)
509510
donor_element[ii] = new su2double[nDim];
510511

511-
nNode_donor = Build_3D_surface_element(Donor_LinkedNodes, Donor_StartLinkedNodes, Donor_nLinkedNodes,
512-
DonorPoint_Coord, donor_iPoint, donor_element);
512+
// nNode_donor = Build_3D_surface_element(Donor_LinkedNodes, Donor_StartLinkedNodes, Donor_nLinkedNodes,
513+
// DonorPoint_Coord, donor_iPoint, donor_element);
514+
515+
nNode_donor = Build_DualElement(Donor_LinkedNodes, Donor_StartLinkedNodes, Donor_nLinkedNodes,
516+
DonorPoint_Coord, donor_iPoint, donor_element);
513517

514518
Area = 0;
515519
for (ii = 1; ii < nNode_target-1; ii++){
@@ -609,8 +613,11 @@ void CSlidingMesh::SetTransferCoeff(const CConfig* const* config) {
609613
for (ii = 0; ii < 2*nEdges_donor + 2; ii++)
610614
donor_element[ii] = new su2double[nDim];
611615

612-
nNode_donor = Build_3D_surface_element(Donor_LinkedNodes, Donor_StartLinkedNodes, Donor_nLinkedNodes,
613-
DonorPoint_Coord, donor_iPoint, donor_element);
616+
// nNode_donor = Build_3D_surface_element(Donor_LinkedNodes, Donor_StartLinkedNodes, Donor_nLinkedNodes,
617+
// DonorPoint_Coord, donor_iPoint, donor_element);
618+
619+
nNode_donor = Build_DualElement(Donor_LinkedNodes, Donor_StartLinkedNodes, Donor_nLinkedNodes,
620+
DonorPoint_Coord, donor_iPoint, donor_element);
614621

615622
tmp_Area = 0;
616623
for (ii = 1; ii < nNode_target-1; ii++)
@@ -839,6 +846,127 @@ int CSlidingMesh::Build_3D_surface_element(const unsigned long *map, const unsig
839846

840847
}
841848

849+
int CSlidingMesh::Build_DualElement(const unsigned long *map, const unsigned long *startIndex,
850+
const unsigned long* nNeighbor, const su2double *coord,
851+
unsigned long centralNode, su2double** element){
852+
853+
/*--- Given a node "centralNode", this routines reconstruct the vertex centered surface quadrilateral element around the node and stores it into "element" ---*/
854+
/*--- Returns the number of points included in the element ---*/
855+
856+
unsigned long iNode, jNode, kNode, ElementIndex, iPoint, jPoint, kPoint, nOuterNodes, nTriNodes;
857+
unsigned short nDim = 3, iDim, nTmp;
858+
const unsigned long *OuterNodes, *ptr;
859+
int NodeIndex;
860+
unsigned long **DualElement;
861+
862+
nTriNodes = 3;
863+
864+
/* --- Store central node as element first point --- */
865+
for (iDim = 0; iDim < nDim; iDim++) {
866+
element[0][iDim] = coord[centralNode * nDim + iDim];
867+
}
868+
869+
/* --- Get the number of nodes directly connected to the central node --- */
870+
nOuterNodes = nNeighbor[centralNode];
871+
872+
/* --- Array containing the points connected to the central node --- */
873+
OuterNodes = &map[startIndex[centralNode]];
874+
875+
/* --- Allocate auxiliary structure, vectors are longer than needed but this avoid further re-allocations due to length variation --- */
876+
DualElement = new unsigned long*[nOuterNodes];
877+
for ( int i = 0; i < nOuterNodes; i++ ) {
878+
DualElement[i] = new unsigned long[nTriNodes];
879+
}
880+
881+
/*--- Initialise dual elements ---*/
882+
for ( int i = 0; i < nOuterNodes; i++ ){
883+
for (int j = 0; j < nTriNodes; j++) {
884+
DualElement[i][j] = -1;
885+
}
886+
}
887+
888+
NodeIndex = 0;
889+
890+
/* --- Build and order tri segments of a hexa dual element --- */
891+
while ((nOuterNodes - NodeIndex) > 0) {
892+
893+
for (iNode = 0; iNode < nOuterNodes && ((nOuterNodes - NodeIndex) > 0); iNode++) {
894+
iPoint = OuterNodes[iNode];
895+
ptr = &map[startIndex[iPoint]];
896+
nTmp = nNeighbor[iPoint];
897+
898+
for (jNode = 0; jNode < nTmp && ((nOuterNodes - NodeIndex) > 0); jNode++) {
899+
jPoint = ptr[jNode];
900+
901+
for (kNode = 0; kNode < nOuterNodes && ((nOuterNodes - NodeIndex) > 0); kNode++) {
902+
kPoint = OuterNodes[kNode];
903+
904+
/*--- Find the shared outer nodes in order ---*/
905+
if (jPoint == kPoint) {
906+
907+
if (NodeIndex == 0) {
908+
DualElement[NodeIndex][0] = centralNode;
909+
DualElement[NodeIndex][1] = iPoint;
910+
DualElement[NodeIndex][2] = jPoint;
911+
NodeIndex++;
912+
break;
913+
}
914+
915+
if (iPoint == DualElement[NodeIndex - 1][2] && jPoint != DualElement[NodeIndex - 1][1]) {
916+
DualElement[NodeIndex][0] = centralNode;
917+
DualElement[NodeIndex][1] = iPoint;
918+
DualElement[NodeIndex][2] = jPoint;
919+
NodeIndex++;
920+
break;
921+
}
922+
923+
}
924+
}
925+
}
926+
}
927+
}
928+
929+
NodeIndex = 0;
930+
ElementIndex = 1;
931+
932+
/* --- Build array containing the quad dual element by finding the mid point of each edge and the baricenter of each face.
933+
* Each quad is split through its diagonal connecting the central node, baricenter and 4th node. --- */
934+
while ((nOuterNodes - NodeIndex) > 0) {
935+
for (iDim = 0; iDim < nDim; iDim++) {
936+
element[ElementIndex][iDim] = (element[0][iDim] + coord[DualElement[NodeIndex][1] * nDim + iDim]) / 2;
937+
}
938+
ElementIndex++;
939+
940+
for (iDim = 0; iDim < nDim; iDim++) {
941+
element[ElementIndex][iDim] = (element[0][iDim] + coord[DualElement[NodeIndex][1] * nDim + iDim] + coord[DualElement[NodeIndex][2] * nDim + iDim]) / 3;
942+
}
943+
ElementIndex++;
944+
NodeIndex++;
945+
}
946+
947+
// This is a closed element, so add again element 1 to the end of the structure, useful later
948+
if(DualElement[NodeIndex - 1][2] == DualElement[0][1]){
949+
950+
for (iDim = 0; iDim < nDim; iDim++) {
951+
element[ElementIndex][iDim] = element[1][iDim];
952+
}
953+
ElementIndex++;
954+
}
955+
else {
956+
for (iDim = 0; iDim < nDim; iDim++) {
957+
element[ElementIndex][iDim] = (element[0][iDim] + coord[DualElement[NodeIndex - 1][2] * nDim + iDim]) / 2;
958+
}
959+
ElementIndex++;
960+
}
961+
962+
for ( int i = 0; i < nOuterNodes; i++ ) {
963+
delete[] DualElement[i];
964+
}
965+
delete [] DualElement;
966+
967+
return (int)ElementIndex;
968+
}
969+
842970
su2double CSlidingMesh::ComputeLineIntersectionLength(unsigned short nDim, const su2double* A1, const su2double* A2,
843971
const su2double* B1, const su2double* B2, const su2double* Direction) {
844972

0 commit comments

Comments
 (0)