Skip to content

Commit

Permalink
Used new reg_test_files and added rhoPimple test. (#609)
Browse files Browse the repository at this point in the history
* Switched the reg_test input to a repo.

* Added the DARhoPimple test.

* Fixed an issue in the make file for rhopimple.

* Added the missing make file for rhopimple.
  • Loading branch information
friedenhe authored Mar 21, 2024
1 parent 5f2cc15 commit fb3380a
Show file tree
Hide file tree
Showing 49 changed files with 228 additions and 55 deletions.
5 changes: 4 additions & 1 deletion src/adjoint/Make/files_Compressible
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ DARegression/DARegression.C
DAStateInfo/DAStateInfo.C
DAStateInfo/DAStateInfoRhoSimpleFoam.C
DAStateInfo/DAStateInfoRhoSimpleCFoam.C
DAStateInfo/DAStateInfoRhoPimpleFoam.C
DAStateInfo/DAStateInfoTurboFoam.C

DAIndex/DAIndex.C
Expand Down Expand Up @@ -60,6 +61,7 @@ DAFvSource/DAFvSourceActuatorDisk.C
DAResidual/DAResidual.C
DAResidual/DAResidualDummy.C
DAResidual/DAResidualRhoSimpleFoam.C
DAResidual/DAResidualRhoPimpleFoam.C
DAResidual/DAResidualRhoSimpleCFoam.C
DAResidual/DAResidualTurboFoam.C

Expand Down Expand Up @@ -89,6 +91,7 @@ DALinearEqn/DALinearEqn.C
DASolver/DASolver.C
DASolver/DARhoSimpleFoam/DARhoSimpleFoam.C
DASolver/DARhoSimpleCFoam/DARhoSimpleCFoam.C
DASolver/DARhoPimpleFoam/DARhoPimpleFoam.C
DASolver/DATurboFoam/DATurboFoam.C

boundaryConditions/homTemp/homTempFvPatchScalarField.C
Expand All @@ -101,7 +104,7 @@ models/SpalartAllmarasFv3/makeSpalartAllmarasFv3Compressible.C
models/SpalartAllmarasFv3FieldInversion/makeSpalartAllmarasFv3FieldInversionCompressible.C
models/kOmegaSSTFieldInversion/makekOmegaSSTFieldInversionCompressible.C
models/kOmegaFieldInversionOmega/makekOmegaFieldInversionOmegaCompressible.C

models/pimpleControlDF/pimpleControlDF.C

models/MRFDF/MRFZoneDF.C
models/MRFDF/MRFZoneListDF.C
Expand Down
2 changes: 1 addition & 1 deletion tests/Allclean
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ if [ -z "$WM_PROJECT" ]; then
exit 1
fi

rm -rf input __pycache__
rm -rf reg_test_files-main __pycache__
20 changes: 11 additions & 9 deletions tests/Allrun
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ if [ -z "$WM_PROJECT" ]; then
exit 1
fi

# check if we need to download input.tar.gz
if [ -f "input.tar.gz" ]; then
echo "input.tar.gz already exists."
# check if we need to download reg_test_files-main.tar.gz
if [ -f "reg_test_files-main.tar.gz" ]; then
echo "reg_test_files-main.tar.gz already exists."
else
echo "Downloading input.tar.gz"
wget https://github.com/dafoam/files/releases/download/v1.0.0/input.tar.gz --no-check-certificate
echo "Downloading reg_test_files-main.tar.gz"
wget https://github.com/DAFoam/reg_test_files/archive/refs/heads/main.tar.gz -O reg_test_files-main.tar.gz --no-check-certificate
fi

if [ -z "$1" ]; then
Expand All @@ -22,8 +22,8 @@ fi

function runTests()
{
rm -rf input DAFoam_Test_${1}.txt
tar -zxf input.tar.gz
rm -rf reg_test_files-main DAFoam_Test_${1}.txt
tar -zxf reg_test_files-main.tar.gz
if [ -z "$DF_CHECK_COVERAGE" ]; then
mpirun --oversubscribe -np 4 python runTests_${1}.py $@ | tee DAFoam_Test_${1}.txt
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
Expand Down Expand Up @@ -55,8 +55,8 @@ function runTests()

function runTestsSerial()
{
rm -rf input DAFoam_Test_${1}.txt
tar -zxf input.tar.gz
rm -rf reg_test_files-main DAFoam_Test_${1}.txt
tar -zxf reg_test_files-main.tar.gz
if [ -z "$DF_CHECK_COVERAGE" ]; then
python runTests_${1}.py $@ | tee DAFoam_Test_${1}.txt
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
Expand Down Expand Up @@ -119,6 +119,7 @@ case $argm in
runTests DARhoSimpleFoam
runTests DARhoSimpleFoamUBend
runTests DARhoSimpleCFoam
runTests DARhoPimpleFoam
if [ -f "$DAFOAM_ROOT_PATH/OpenFOAM/sharedLibs/libDAFoamCompressibleADR.so" ]; then
runTests DARhoSimpleFoamMRFAD
runTests DARhoSimpleFoamAD
Expand Down Expand Up @@ -185,6 +186,7 @@ case $argm in
runTests DARhoSimpleFoam
runTests DARhoSimpleFoamUBend
runTests DARhoSimpleCFoam
runTests DARhoPimpleFoam
if [ -f "$DAFOAM_ROOT_PATH/OpenFOAM/sharedLibs/libDAFoamCompressibleADR.so" ]; then
runTests DARhoSimpleFoamMRFAD
runTests DARhoSimpleFoamAD
Expand Down
14 changes: 14 additions & 0 deletions tests/refs/DAFoam_Test_DARhoPimpleFoamRef.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Dictionary Key: CD
@value 0.2304630624535831 1e-08 1e-10
Dictionary Key: CL
@value 6.3056661425586 1e-08 1e-10
Dictionary Key: fail
@value 0 1e-08 1e-10
Dictionary Key: CD
Dictionary Key: twist
@value -0.1045060854662659 0.0001 1e-06
Dictionary Key: CL
Dictionary Key: twist
@value -0.2190748076682245 0.0001 1e-06
Dictionary Key: fail
@value 0 0.0001 1e-06
2 changes: 1 addition & 1 deletion tests/runTests_DAHeatTransferFoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

gcomm = MPI.COMM_WORLD

os.chdir("./input/ChannelConjugateHeat/thermal")
os.chdir("./reg_test_files-main/ChannelConjugateHeat/thermal")

aeroOptions = {
"designSurfaces": ["channel_outer", "channel_inner", "channel_sides"],
Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DALaplacianFoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

gcomm = MPI.COMM_WORLD

os.chdir("./input/flange")
os.chdir("./reg_test_files-main/flange")

# test incompressible solvers
aeroOptions = {
Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DAPimpleDyMFoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
from testFuncs import *

os.chdir("./input/NACA0012DynamicMesh")
os.chdir("./reg_test_files-main/NACA0012DynamicMesh")

replace_text_in_file("system/controlDict", "endTime 0.01;", "endTime 0.001;")

Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DAPimpleFoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

gcomm = MPI.COMM_WORLD

os.chdir("./input/NACA0012Unsteady")
os.chdir("./reg_test_files-main/NACA0012Unsteady")

if gcomm.rank == 0:
os.system("rm -rf processor*")
Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DAPimpleFoamField.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

gcomm = MPI.COMM_WORLD

os.chdir("./input/NACA0012Unsteady")
os.chdir("./reg_test_files-main/NACA0012Unsteady")

if gcomm.rank == 0:
os.system("rm -rf processor*")
Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DAPimpleFoamTurbModels.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

gcomm = MPI.COMM_WORLD

os.chdir("./input/NACA0012Unsteady")
os.chdir("./reg_test_files-main/NACA0012Unsteady")

funcs = {}

Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DAPisoFoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

gcomm = MPI.COMM_WORLD

os.chdir("./input/CurvedCubeHexMesh")
os.chdir("./reg_test_files-main/CurvedCubeHexMesh")

if gcomm.rank == 0:
os.system("rm -rf 0 processor*")
Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DAPisoFoamACTL.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

gcomm = MPI.COMM_WORLD

os.chdir("./input/CurvedCubeHexMesh")
os.chdir("./reg_test_files-main/CurvedCubeHexMesh")

if gcomm.rank == 0:
os.system("rm -rf 0 processor*")
Expand Down
154 changes: 154 additions & 0 deletions tests/runTests_DARhoPimpleFoam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#!/usr/bin/env python
"""
Run Python tests for DARhoPimpleFoam
"""

from mpi4py import MPI
from dafoam import PYDAFOAM, optFuncs
import sys
import os
from pygeo import *
from pyspline import *
from idwarp import *
import numpy as np
from testFuncs import *

calcFDSens = 0
if len(sys.argv) != 1:
if sys.argv[1] == "calcFDSens":
calcFDSens = 1

gcomm = MPI.COMM_WORLD

os.chdir("./reg_test_files-main/NACA0012UnsteadyComp")

if gcomm.rank == 0:
os.system("rm -rf processor*")

twist0 = 0
U0 = 100
T0 = 300.0
p0 = 101325.0
rho0 = p0 / 287.0 / T0
A0 = 0.1
nuTilda0 = 1e-4

# test incompressible solvers
daOptions = {
"designSurfaces": ["wing"],
"solverName": "DARhoPimpleFoam",
"primalBC": {"useWallFunction": True},
"unsteadyAdjoint": {
"mode": "timeAccurate",
"PCMatPrecomputeInterval": 20,
"PCMatUpdateInterval": 1,
"objFuncTimeOperator": "average",
},
"printIntervalUnsteady": 1,
"objFunc": {
"CD": {
"part1": {
"type": "force",
"source": "patchToFace",
"patches": ["wing"],
"directionMode": "fixedDirection",
"direction": [1.0, 0.0, 0.0],
"scale": 1.0 / (0.5 * U0 * U0 * A0 * rho0),
"addToAdjoint": True,
}
},
"CL": {
"part1": {
"type": "force",
"source": "patchToFace",
"patches": ["wing"],
"directionMode": "fixedDirection",
"direction": [0.0, 1.0, 0.0],
"scale": 1.0 / (0.5 * U0 * U0 * A0 * rho0),
"addToAdjoint": True,
}
},
},
"adjStateOrdering": "cell",
"adjEqnOption": {
"gmresRelTol": 1.0e-8,
"pcFillLevel": 1,
"jacMatReOrdering": "natural",
"useNonZeroInitGuess": True,
},
"normalizeStates": {
"U": U0,
"p": p0,
"T": T0,
"nuTilda": 1e-3,
"phi": 1.0,
},
"designVar": {
"twist": {"designVarType": "FFD"},
},
}

# mesh warping parameters, users need to manually specify the symmetry plane
meshOptions = {
"gridFile": os.getcwd(),
"fileType": "OpenFOAM",
# point and normal for the symmetry plane
"symmetryPlanes": [[[0.0, 0.0, 0.0], [0.0, 0.0, 1.0]], [[0.0, 0.0, 0.1], [0.0, 0.0, 1.0]]],
}

# =============================================================================
# Design variable setup
# =============================================================================
DVGeo = DVGeometry("./FFD/FFD.xyz")
DVGeo.addRefAxis("bodyAxis", xFraction=0.25, alignIndex="k")


def twist(val, geo):
for i in range(2):
geo.rot_z["bodyAxis"].coef[i] = val[0]


DVGeo.addGlobalDV("twist", [twist0], twist, lower=-100.0, upper=100.0, scale=1.0)


# =============================================================================
# DAFoam initialization
# =============================================================================
DASolver = PYDAFOAM(options=daOptions, comm=gcomm)
DASolver.setDVGeo(DVGeo)
mesh = USMesh(options=meshOptions, comm=gcomm)
DASolver.printFamilyList()
DASolver.setMesh(mesh)
evalFuncs = []
DASolver.setEvalFuncs(evalFuncs)

# =============================================================================
# Constraint setup
# =============================================================================
DVCon = DVConstraints()
DVCon.setDVGeo(DVGeo)
DVCon.setSurface(DASolver.getTriangulatedMeshSurface(groupName=DASolver.designSurfacesGroup))

# =============================================================================
# Initialize optFuncs for optimization
# =============================================================================
optFuncs.DASolver = DASolver
optFuncs.DVGeo = DVGeo
optFuncs.DVCon = DVCon
optFuncs.evalFuncs = evalFuncs
optFuncs.gcomm = gcomm

# Run
if calcFDSens == 1:
optFuncs.calcFDSens()
else:
DASolver.runColoring()
xDV = DVGeo.getValues()
funcs = {}
funcs, fail = optFuncs.calcObjFuncValues(xDV)
funcsSens = {}
funcsSens, fail = optFuncs.calcObjFuncSens(xDV, funcs)

if gcomm.rank == 0:
reg_write_dict(funcs, 1e-8, 1e-10)
reg_write_dict(funcsSens, 1e-4, 1e-6)
2 changes: 1 addition & 1 deletion tests/runTests_DARhoSimpleCFoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

gcomm = MPI.COMM_WORLD

os.chdir("./input/NACA0012")
os.chdir("./reg_test_files-main/NACA0012")

if gcomm.rank == 0:
os.system("rm -rf 0 processor*")
Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DARhoSimpleCFoamAD.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

gcomm = MPI.COMM_WORLD

os.chdir("./input/NACA0012")
os.chdir("./reg_test_files-main/NACA0012")

if gcomm.rank == 0:
os.system("rm -rf 0 processor*")
Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DARhoSimpleFoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

gcomm = MPI.COMM_WORLD

os.chdir("./input/CurvedCubeSnappyHexMesh")
os.chdir("./reg_test_files-main/CurvedCubeSnappyHexMesh")

if gcomm.rank == 0:
os.system("rm -rf 0 processor*")
Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DARhoSimpleFoamAD.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

gcomm = MPI.COMM_WORLD

os.chdir("./input/CurvedCubeSnappyHexMesh")
os.chdir("./reg_test_files-main/CurvedCubeSnappyHexMesh")

if gcomm.rank == 0:
os.system("rm -rf 0 processor*")
Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DARhoSimpleFoamFIML.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

gcomm = MPI.COMM_WORLD

os.chdir("./input/CurvedCubeSnappyHexMesh")
os.chdir("./reg_test_files-main/CurvedCubeSnappyHexMesh")

if gcomm.rank == 0:
os.system("rm -rf 0 processor*")
Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DARhoSimpleFoamMRFAD.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

gcomm = MPI.COMM_WORLD

os.chdir("./input/CompressorFluid")
os.chdir("./reg_test_files-main/CompressorFluid")

if gcomm.rank == 0:
os.system("rm -rf 0 processor*")
Expand Down
Loading

0 comments on commit fb3380a

Please sign in to comment.