Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Symmetry/Euler marker preprocessing logic with deforming markers #1933

Merged
merged 8 commits into from
Feb 21, 2023
26 changes: 19 additions & 7 deletions Common/include/CConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6559,26 +6559,38 @@ class CConfig {
* \brief Get the internal index for a moving boundary <i>val_marker</i>.
* \return Internal index for a moving boundary <i>val_marker</i>.
*/
unsigned short GetMarker_Moving(string val_marker) const;
unsigned short GetMarker_Moving(const string& val_marker) const;

/*!
* \brief Get bool if marker is moving. <i>val_marker</i>.
* \param[in] val_marker - String of the marker to test.
* \return Bool if the marker is a moving boundary <i>val_marker</i>.
* \brief Get a bool for whether a marker is moving. <i>val_marker</i>.
* \param[in] val_marker - Name of the marker to test.
* \return True if the marker is a moving boundary <i>val_marker</i>.
*/
bool GetMarker_Moving_Bool(string val_marker) const;
inline bool GetMarker_Moving_Bool(const string& val_marker) const {
return GetMarker_Moving(val_marker) < nMarker_Moving;
}

/*!
* \brief Get the internal index for a DEFORM_MESH boundary <i>val_marker</i>.
* \return Internal index for a DEFORM_MESH boundary <i>val_marker</i>.
*/
unsigned short GetMarker_Deform_Mesh(string val_marker) const;
unsigned short GetMarker_Deform_Mesh(const string& val_marker) const;

/*!
* \brief Get the internal index for a DEFORM_MESH_SYM_PLANE boundary <i>val_marker</i>.
* \return Internal index for a DEFORM_MESH_SYM_PLANE boundary <i>val_marker</i>.
*/
unsigned short GetMarker_Deform_Mesh_Sym_Plane(string val_marker) const;
unsigned short GetMarker_Deform_Mesh_Sym_Plane(const string& val_marker) const;

/*!
* \brief Get a bool for whether the marker is deformed. <i>val_marker</i>.
* \param[in] val_marker - Name of the marker to test.
* \return True if the marker is a deforming boundary <i>val_marker</i>.
*/
inline bool GetMarker_Deform_Mesh_Bool(const string& val_marker) const {
return GetMarker_Deform_Mesh(val_marker) < nMarker_Deform_Mesh ||
GetMarker_Deform_Mesh_Sym_Plane(val_marker) < nMarker_Deform_Mesh_Sym_Plane;
}

/*!
* \brief Get the internal index for a Fluid_Load boundary <i>val_marker</i>.
Expand Down
40 changes: 15 additions & 25 deletions Common/src/CConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8676,44 +8676,34 @@ bool CConfig::GetSurface_Movement(unsigned short kind_movement) const {
return false;
}

unsigned short CConfig::GetMarker_Moving(string val_marker) const {
unsigned short iMarker_Moving;
unsigned short CConfig::GetMarker_Moving(const string& val_marker) const {
unsigned short iMarker;

/*--- Find the marker for this moving boundary. ---*/
for (iMarker_Moving = 0; iMarker_Moving < nMarker_Moving; iMarker_Moving++)
if (Marker_Moving[iMarker_Moving] == val_marker) break;
for (iMarker = 0; iMarker < nMarker_Moving; iMarker++)
if (Marker_Moving[iMarker] == val_marker) break;

return iMarker_Moving;
return iMarker;
}

bool CConfig::GetMarker_Moving_Bool(string val_marker) const {
unsigned short iMarker_Moving;

/*--- Find the marker for this moving boundary, if it exists. ---*/
for (iMarker_Moving = 0; iMarker_Moving < nMarker_Moving; iMarker_Moving++)
if (Marker_Moving[iMarker_Moving] == val_marker) return true;

return false;
}

unsigned short CConfig::GetMarker_Deform_Mesh(string val_marker) const {
unsigned short iMarker_Deform_Mesh;
unsigned short CConfig::GetMarker_Deform_Mesh(const string& val_marker) const {
unsigned short iMarker;

/*--- Find the marker for this interface boundary. ---*/
for (iMarker_Deform_Mesh = 0; iMarker_Deform_Mesh < nMarker_Deform_Mesh; iMarker_Deform_Mesh++)
if (Marker_Deform_Mesh[iMarker_Deform_Mesh] == val_marker) break;
for (iMarker = 0; iMarker < nMarker_Deform_Mesh; iMarker++)
if (Marker_Deform_Mesh[iMarker] == val_marker) break;

return iMarker_Deform_Mesh;
return iMarker;
}

unsigned short CConfig::GetMarker_Deform_Mesh_Sym_Plane(string val_marker) const {
unsigned short iMarker_Deform_Mesh_Sym_Plane;
unsigned short CConfig::GetMarker_Deform_Mesh_Sym_Plane(const string& val_marker) const {
unsigned short iMarker;

/*--- Find the marker for this interface boundary. ---*/
for (iMarker_Deform_Mesh_Sym_Plane = 0; iMarker_Deform_Mesh_Sym_Plane < nMarker_Deform_Mesh_Sym_Plane; iMarker_Deform_Mesh_Sym_Plane++)
if (Marker_Deform_Mesh_Sym_Plane[iMarker_Deform_Mesh_Sym_Plane] == val_marker) break;
for (iMarker = 0; iMarker < nMarker_Deform_Mesh_Sym_Plane; iMarker++)
if (Marker_Deform_Mesh_Sym_Plane[iMarker] == val_marker) break;

return iMarker_Deform_Mesh_Sym_Plane;
return iMarker;
}

unsigned short CConfig::GetMarker_Fluid_Load(string val_marker) const {
Expand Down
3 changes: 2 additions & 1 deletion Common/src/geometry/CGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2592,7 +2592,8 @@ void CGeometry::ComputeSurf_Straightness(CConfig *config,
other GridMovements are rigid. ---*/
if ((config->GetMarker_All_KindBC(iMarker) == SYMMETRY_PLANE ||
config->GetMarker_All_KindBC(iMarker) == EULER_WALL) &&
!config->GetMarker_Moving_Bool(Local_TagBound)) {
!config->GetMarker_Moving_Bool(Local_TagBound) &&
!config->GetMarker_Deform_Mesh_Bool(Local_TagBound)) {

/*--- Loop over all global markers, and find the local-global pair via
matching unique string tags. ---*/
Expand Down
10 changes: 10 additions & 0 deletions TestCases/parallel_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,16 @@ def main():
pywrapper_rigidMotion.unsteady = True
test_list.append(pywrapper_rigidMotion)

# Deforming Bump in Channel
pywrapper_deformingBump = TestCase('pywrapper deforming bump in channel')
pywrapper_deformingBump.cfg_dir = "py_wrapper/deforming_bump_in_channel"
pywrapper_deformingBump.cfg_file = "config.cfg"
pywrapper_deformingBump.test_iter = 2
pywrapper_deformingBump.test_vals = [0.5, 0, -2.55436, -1.084594, -0.024882, 2.907803, 8.785498, -0.363585]
pcarruscag marked this conversation as resolved.
Show resolved Hide resolved
pywrapper_deformingBump.command = TestCase.Command("mpirun -np 2", "python", "run.py")
pywrapper_deformingBump.unsteady = True
test_list.append(pywrapper_deformingBump)

##############################################
### Method of Manufactured Solutions (MMS) ###
##############################################
Expand Down
72 changes: 72 additions & 0 deletions TestCases/py_wrapper/deforming_bump_in_channel/config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
% ------------------------------- SOLVER -------------------------------- %
%
SOLVER= EULER
%
% ----------------------------- FREESTREAM ------------------------------ %
%
MACH_NUMBER= 0.02
AOA= 0.0
FREESTREAM_OPTION= TEMPERATURE_FS
FREESTREAM_PRESSURE= 101325.0
FREESTREAM_TEMPERATURE= 288.15
%
% ------------------------- UNSTEADY SIMULATION ------------------------- %
%
TIME_DOMAIN= YES
TIME_MARCHING= DUAL_TIME_STEPPING-1ST_ORDER
% The time step is ~50x too large to obtain a quasi-steady solution for
% testing.
TIME_STEP= 0.5
MAX_TIME= 5.0
INNER_ITER= 500
TIME_ITER= 2
%
% ------------------------- BOUNDARY CONDITIONS ------------------------- %
%
MARKER_EULER= ( top, slip_bottom, bottom_front, interface, bottom_rear )
MARKER_INLET= ( inlet, 288.6, 101400.0, 1.0, 0.0, 0.0 )
MARKER_OUTLET= ( outlet, 101100.0 )
MARKER_PLOTTING= ( interface )
MARKER_MONITORING= ( interface )
%
% -------------------------- MESH DEFORMATION --------------------------- %
%
DEFORM_MESH= YES
MARKER_DEFORM_MESH = ( interface )
DEFORM_STIFFNESS_TYPE= INVERSE_VOLUME
DEFORM_LINEAR_SOLVER= CONJUGATE_GRADIENT
DEFORM_LINEAR_SOLVER_PREC= ILU
DEFORM_LINEAR_SOLVER_ITER= 200
DEFORM_LINEAR_SOLVER_ERROR= 1e-9
% DEFORM_CONSOLE_OUTPUT= YES
%
% ----------------------- SPATIAL DISCRETIZATION ------------------------ %
%
NUM_METHOD_GRAD= GREEN_GAUSS
CONV_NUM_METHOD_FLOW= ROE
MUSCL_FLOW= YES
SLOPE_LIMITER_FLOW= NONE
%
% ---------- PSEUDOTIME INTEGRATION / CONVERGENCE ACCELERATION ---------- %
%
TIME_DISCRE_FLOW= EULER_IMPLICIT
CFL_NUMBER= 500
MGLEVEL= 0
LINEAR_SOLVER= FGMRES
LINEAR_SOLVER_PREC= ILU
LINEAR_SOLVER_ERROR= 0.1
LINEAR_SOLVER_ITER= 10
%
% ------------------------ CONVERGENCE CRITERIA ------------------------- %
%
CONV_FIELD= RMS_DENSITY
CONV_RESIDUAL_MINVAL= -8
%
% --------------------------- INPUT / OUTPUT ---------------------------- %
%
RESTART_SOL= NO
SCREEN_OUTPUT= ( TIME_ITER, CUR_TIME, INNER_ITER, RMS_RES, LIFT, DRAG )
MESH_FILENAME= mesh.su2
MESH_FORMAT= SU2
OUTPUT_WRT_FREQ= (5)

108 changes: 108 additions & 0 deletions TestCases/py_wrapper/deforming_bump_in_channel/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env python

## \file run.py
# \brief Deforming bump in channel.
# \version 7.5.1 "Blackbird"
#
# SU2 Project Website: https://su2code.github.io
#
# The SU2 Project is maintained by the SU2 Foundation
# (http://su2foundation.org)
#
# Copyright 2012-2023, SU2 Contributors (cf. AUTHORS.md)
#
# SU2 is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# SU2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with SU2. If not, see <http://www.gnu.org/licenses/>.

import pysu2
from mpi4py import MPI
import numpy as np

def main():
comm = MPI.COMM_WORLD
rank = comm.Get_rank()

# Initialize the corresponding driver of SU2, this includes solver preprocessing.
try:
SU2Driver = pysu2.CSinglezoneDriver('config.cfg', 1, comm);
pcarruscag marked this conversation as resolved.
Show resolved Hide resolved
except TypeError as exception:
print('A TypeError occured in pysu2.CDriver : ', exception)
raise

# Get the ID of the marker we want to deform.
AllMarkerIDs = SU2Driver.GetMarkerIndices()
MarkerName = 'interface'
MarkerID = AllMarkerIDs[MarkerName] if MarkerName in AllMarkerIDs else -1

# Number of vertices on the specified marker (per rank).
nVertex = SU2Driver.GetNumberMarkerNodes(MarkerID) if MarkerID >= 0 else 0

# Retrieve some control parameters from the driver.
deltaT = SU2Driver.GetUnsteady_TimeStep()
TimeIter = SU2Driver.GetTime_Iter()
nTimeIter = SU2Driver.GetnTimeIter()
time = TimeIter * deltaT

# Extract the initial position of each node on the moving marker.
CoordX = np.zeros(nVertex)
CoordY = np.zeros(nVertex)
for iVertex in range(nVertex):
iPoint = SU2Driver.GetMarkerNode(MarkerID, iVertex)
CoordX[iVertex], CoordY[iVertex] = SU2Driver.GetInitialCoordinates(iPoint)

if rank == 0:
print("\n------------------------------ Begin Solver -----------------------------\n")

# The time loop is defined in Python so that we have acces to SU2 functionalities at each time step.
while (TimeIter < nTimeIter):
# Apply the surface deformation.
for iVertex in range(nVertex):
dy = np.real(DeformFunction(CoordX[iVertex] - 0.9, time))
SU2Driver.SetMarkerDisplacements(MarkerID, iVertex, (0.0, dy))

# Time iteration preprocessing.
SU2Driver.Preprocess(TimeIter)

# Run one time iteration (e.g. dual-time).
SU2Driver.Run()
SU2Driver.Postprocess()
SU2Driver.Update()

# Monitor the solver and output solution to file if required.
stopCalc = SU2Driver.Monitor(TimeIter)
SU2Driver.Output(TimeIter)

if (stopCalc == True):
break

# Update control parameters
TimeIter += 1
time += deltaT

# Postprocess the solver and exit cleanly
SU2Driver.Postprocessing()

if SU2Driver != None:
del SU2Driver
Fixed Show fixed Hide fixed
pcarruscag marked this conversation as resolved.
Show resolved Hide resolved

# Imposed deformation
def DeformFunction(x,t):
A1 = 0.016
L = 1.0
k1 = 4.730/L
return A1*(np.cosh(k1*x) - np.cos(k1*x) + ((np.cosh(k1*L)-np.cos(k1*L))*(np.sin(k1*x)-np.sinh(k1*x)))/(np.sinh(k1*L) - np.sin(k1*L)))*(np.exp(1j*t*2) + np.exp(-1j*t*2))


if __name__ == '__main__':
main()