1.7.2.4. KaplanDuct¶
[1]:
import sys, time
import numpy as np
seed = 1435
np.random.seed(seed)
# import problem classes
import Exeter_CFD_Problems as TestProblems
verbose = False
sys.argv = sys.argv[:1]
print('Demonstration of the KaplanDuct test problem.')
# set up directories.
settings = {
'source_case': 'Exeter_CFD_Problems/data/KaplanDuct/case_fine/',
'case_path': 'Exeter_CFD_Problems/data/KaplanDuct/case_single/',
'boundary_files': ['Exeter_CFD_Problems/data/KaplanDuct/boundary_1stspline.csv', \
'Exeter_CFD_Problems/data/KaplanDuct/boundary_2ndspline.csv'],
'fixed_points_files': ['Exeter_CFD_Problems/data/KaplanDuct/fixed_1.csv',\
'Exeter_CFD_Problems/data/KaplanDuct/fixed_2.csv']
}
# instantiate the problem object
prob = TestProblems.KaplanDuct(settings)
# get the lower and upper bounds
lb, ub = prob.get_decision_boundary()
# generate random solutions satisfying the lower and upper bounds.
x = np.random.random((1000, lb.shape[0])) * (ub - lb) + lb
rand_x = []
for i in range(x.shape[0]):
if prob.constraint(x[i]): # check to see if the random solution is valid
rand_x.append(x[i])
# evaluate for a solution
print('Number of control points: ', prob.n_control)
print('Decision vector: ', rand_x[0])
print('Running simulation ...')
start = time.time()
res = prob.evaluate(rand_x[0], verbose=verbose)
print('Objective function value:', res)
print('Time taken:', time.time()-start, ' seconds.')
Demonstration of the KaplanDuct test problem.
/home/andrew/Dropbox/6_thevisualroom/33_machine_learning/optimiserTestProblemSuite/Exeter_CFD_Problems/data/SnappyHexOptimise.py:274: UserWarning: Warning: The CFD simulation may not have converged. If this is shown at problem instantiation, then you can safely ignore as no CFD simulation was performed.
warnings.warn("Warning: The CFD simulation may not have converged. If this is shown at problem instantiation, then you can safely ignore as no CFD simulation was performed.")
Number of control points: [1, 1]
Decision vector: [2166.43098447 -671.52102819 2377.3332863 -69.16966251]
Running simulation ...
Objective function value: 0.969045
Time taken: 5251.209176301956 seconds.
[2]:
! ls
Exeter_CFD_Problems LICENSE PlyParser_FoamFileParser_parsetab.py
figures log __pycache__
HeatExchanger.ipynb log2 README.md
KaplanDuct-Copy1.ipynb PitzDaily.ipynb sample_script.py
KaplanDuct.ipynb plotPitzDaily.py
[3]:
! postProcess -case Exeter_CFD_Problems/data/KaplanDuct/case_single -func sample > log 2>&1
[33]:
import plotKaplanDuct
import importlib
importlib.reload(plotKaplanDuct)
plotKaplanDuct.plot('Exeter_CFD_Problems/data/KaplanDuct/case_single/postProcessing/sample/0/U_nearWall.vtk')
[ ]: