Skip to content

Commit

Permalink
Added tests for ReLU and RBF.
Browse files Browse the repository at this point in the history
  • Loading branch information
friedenhe committed Apr 10, 2024
1 parent db61360 commit 67cee48
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 42 deletions.
10 changes: 7 additions & 3 deletions tests/refs/DAFoam_Test_DARhoSimpleFoamFIMLRef.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
ictionary Key: VAR
@value 19.99003057275109 1e-08 1e-10
Dictionary Key: VAR
@value 19.99003057276491 1e-08 1e-10
Dictionary Key: VAR_RBF
@value 19.98999618847408 1e-08 1e-10
Dictionary Key: VAR_ReLU
@value 19.99092771148178 1e-08 1e-10
Dictionary Key: fail
@value 0 1e-08 1e-10
Dictionary Key: VAR
Dictionary Key: parameter
@value 0.002477420841907976 0.0001 1e-06
@value 0.002477420841879514 0.0001 1e-06
Dictionary Key: fail
@value 0 0.0001 1e-06
82 changes: 43 additions & 39 deletions tests/runTests_DARhoSimpleFoamFIML.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,50 +138,54 @@ def regModel(val, DASolver):
funcsSens["VAR"]["parameter"] = norm

# test RBF regression
DASolver.setOption(
"regressionModel",
{
"active": True,
"modelType": "radialBasisFunction",
"inputNames": ["KoU2", "ReWall", "CoP", "TauoK"],
"outputName": "betaFIOmega",
"nRBFs": 20,
"inputShift": [0.0, 0.0, 0.0, 0.0],
"inputScale": [1.0, 1.0, 0.0001, 1.0],
"outputShift": 1.0,
"outputScale": 1.0,
"printInputInfo": True,
"defaultOutputValue": 1.0,
"writeFeatures": True,
},
)
DASolver.updateDAOption()
aeroOptions["regressionModel"] = {
"active": True,
"modelType": "radialBasisFunction",
"inputNames": ["KoU2", "ReWall", "CoP", "TauoK"],
"outputName": "betaFIOmega",
"nRBFs": 20,
"inputShift": [0.0, 0.0, 0.0, 0.0],
"inputScale": [1.0, 1.0, 0.0001, 1.0],
"outputShift": 1.0,
"outputScale": 1.0,
"printInputInfo": True,
"defaultOutputValue": 1.0,
"writeFeatures": True,
}

DASolver = PYDAFOAM(options=aeroOptions, comm=gcomm)
nParameters = DASolver.solver.getNRegressionParameters()
parameter0 = np.ones(nParameters) * 0.03
DASolver.addInternalDV("parameter", parameter0, regModel, lower=-10, upper=10, scale=100.0)
DASolver()
funcs1 = {}
funcs1, fail = optFuncs.calcObjFuncValues(iDV)
DASolver.evalFunctions(funcs1, evalFuncs=["VAR"])
funcs["VAR_RBF"] = funcs1["VAR"]

# test ReLU
DASolver.setOption(
"regressionModel",
{
"active": True,
"modelType": "neuralNetwork",
"inputNames": ["KoU2", "ReWall", "CoP", "TauoK"],
"outputName": "betaFIOmega",
"hiddenLayerNeurons": [10, 10],
"inputShift": [0.0, 0.0, 0.0, 0.0],
"inputScale": [1.0, 1.0, 0.0001, 1.0],
"outputShift": 1.0,
"outputScale": 1.0,
"activationFunction": "ReLU",
"leakyCoeff": 0.1,
"printInputInfo": False,
"defaultOutputValue": 1.0,
},
)
DASolver.updateDAOption()
aeroOptions["regressionModel"] = {
"active": True,
"modelType": "neuralNetwork",
"inputNames": ["KoU2", "ReWall", "CoP", "TauoK"],
"outputName": "betaFIOmega",
"hiddenLayerNeurons": [10, 10],
"inputShift": [0.0, 0.0, 0.0, 0.0],
"inputScale": [1.0, 1.0, 0.0001, 1.0],
"outputShift": 1.0,
"outputScale": 1.0,
"activationFunction": "ReLU",
"leakyCoeff": 0.1,
"printInputInfo": False,
"defaultOutputValue": 1.0,
}

DASolver = PYDAFOAM(options=aeroOptions, comm=gcomm)
nParameters = DASolver.solver.getNRegressionParameters()
parameter0 = np.ones(nParameters) * 0.05
DASolver.addInternalDV("parameter", parameter0, regModel, lower=-10, upper=10, scale=100.0)
DASolver()
funcs2 = {}
funcs2, fail = optFuncs.calcObjFuncValues(iDV)
DASolver.evalFunctions(funcs2, evalFuncs=["VAR"])
funcs["VAR_ReLU"] = funcs2["VAR"]

if gcomm.rank == 0:
Expand Down

0 comments on commit 67cee48

Please sign in to comment.