Skip to content
Snippets Groups Projects
Commit f424096a authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

Added more tests

parent b2af0e41
No related branches found
No related tags found
1 merge request!94Handle disabled mpi
wrf_HRI 173 183 0 0.0004 <coordinates>7.83191,55.48940,0.0</coordinates>
1 1 12
0.000 0.030 0.100 0.400 1.500
70.0
3.597152 3.948682 5.167395 7.000154 8.364547 6.43485 8.643194 11.77051 15.15757 14.73792 10.01205 5.165975
9.176929 9.782334 9.531809 9.909545 10.04269 9.593921 9.584007 10.51499 11.39895 11.68746 11.63732 10.08803
2.392578 2.447266 2.412109 2.591797 2.755859 2.595703 2.583984 2.548828 2.470703 2.607422 2.626953 2.326172
\ No newline at end of file
......@@ -5,10 +5,14 @@ Created on 25. apr. 2018
'''
import os
import unittest
from topfarm.cost_models.fuga.lib_reader import read_lib
import mock
import numpy as np
from topfarm.cost_models.fuga import py_fuga
from tests.test_files import testfilepath
from topfarm.cost_models.fuga import py_fuga, lib_reader
from topfarm.cost_models.fuga.lib_reader import read_lib
import importlib
class Test(unittest.TestCase):
......@@ -22,6 +26,11 @@ class Test(unittest.TestCase):
np.testing.assert_array_almost_equal(k, [2.392578, 2.447266, 2.412109, 2.591797, 2.755859, 2.595703,
2.583984, 2.548828, 2.470703, 2.607422, 2.626953, 2.326172])
def test_main(self):
with mock.patch.object(lib_reader, "__name__", "__main__"):
lib_reader.try_me()
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.test_lib_reader']
......
"""Tests for TOPFARM
"""
import warnings
import numpy as np
import os
from topfarm.topfarm import TopFarm
from topfarm.cost_models.dummy import DummyCost
import unittest
import warnings
import pytest
import numpy as np
from topfarm.cost_models.dummy import DummyCost, DummyCostPlotComp
class Test(unittest.TestCase): # unittest version
......@@ -40,6 +44,18 @@ class Test(unittest.TestCase): # unittest version
self.assertLess(tb_pos[1][0], 6 + tol) # check within border
np.testing.assert_array_almost_equal(tb_pos, optimal, dec_prec)
def testDummyCostPlotComp(self):
if os.name == 'posix' and "DISPLAY" not in os.environ:
pytest.xfail("No display")
desired = [[3, -3], [7, -7], [4, -3], [3, -7]]
tf = TopFarm(turbines=[[6, 0], [6, -8], [1, 1], [-1, -8]],
cost_comp=DummyCost(desired),
min_spacing=2,
boundary=[(0, 0), (6, 0), (6, -10), (0, -10)],
plot_comp = DummyCostPlotComp(desired))
tf.evaluate()
if __name__ == "__main__":
unittest.main()
......@@ -35,7 +35,7 @@ class BoundaryComp(ExplicitComponent):
r = range_ / 2
vertices = np.array([(x_c - r[0], y_c - r[1]), (x_c + r[0], y_c - r[1]), (x_c + r[0], y_c + r[1]), (x_c - r[0], y_c + r[1])])
else:
raise NotImplementedError
raise NotImplementedError("Boundary type '%s' is not implemented"%boundary_type)
# get the real number of vertices
nVertices = vertices.shape[0]
......
......@@ -2,7 +2,6 @@ from openmdao.core.explicitcomponent import ExplicitComponent
import numpy as np
class CostModelComponent(ExplicitComponent):
def __init__(self, n_wt, cost_function, cost_gradient_function=None):
super().__init__()
......@@ -21,7 +20,6 @@ class CostModelComponent(ExplicitComponent):
self.declare_partials('cost', '*')
else:
self.declare_partials('cost', '*', method='fd')
def compute(self, inputs, outputs):
x = inputs['turbineX']
......
......@@ -21,13 +21,13 @@ class DummyCost(ExplicitComponent):
def cost(self, x, y):
"""Evaluate cost function"""
def setup(self):
self.add_input('turbineX', val=np.zeros(self.N), units='m')
self.add_input('turbineY', val=np.zeros(self.N), units='m')
self.add_output('cost', val=0.0)
self.declare_partials('cost', '*')
def compute(self, inputs, outputs):
"""
f(x,y) = SUM(x_i - optx_i)^2 + SUM(y_i + opty_i)^2
......@@ -48,7 +48,6 @@ class DummyCostPlotComp(PlotComp):
def __init__(self, optimal, memory=10, delay=0.001):
super().__init__(memory, delay)
self.optimal = optimal
def init_plot(self, boundary):
PlotComp.init_plot(self, boundary)
......@@ -57,18 +56,23 @@ class DummyCostPlotComp(PlotComp):
plt.plot(optx, opty, 'o', color=c, ms=8)
if __name__ == '__main__':
n_wt = 4
random_offset = 5
optimal = [(3, -3), (7, -7), (4, -3), (3, -7), (-3, -3), (-7, -7), (-4, -3), (-3, -7)][:n_wt]
rotorDiameter = 1.0
minSpacing = 2.0
def try_me():
if __name__ == '__main__':
n_wt = 4
random_offset = 5
optimal = [(3, -3), (7, -7), (4, -3), (3, -7), (-3, -3), (-7, -7), (-4, -3), (-3, -7)][:n_wt]
rotorDiameter = 1.0
minSpacing = 2.0
turbines = np.array(optimal) + np.random.randint(-random_offset, random_offset, (n_wt, 2))
plot_comp = DummyCostPlotComp(optimal)
boundary = [(0, 0), (6, 0), (6, -10), (0, -10)]
tf = TopFarm(turbines, DummyCost(optimal), minSpacing * rotorDiameter, boundary=boundary, plot_comp=plot_comp)
# tf.check()
tf.optimize()
# plot_comp.show()
turbines = np.array(optimal) + np.random.randint(-random_offset, random_offset, (n_wt, 2))
plot_comp = DummyCostPlotComp(optimal)
boundary = [(0, 0), (6, 0), (6, -10), (0, -10)]
tf = TopFarm(turbines, DummyCost(optimal), minSpacing * rotorDiameter, boundary=boundary, plot_comp=plot_comp)
# tf.check()
tf.optimize()
plot_comp.show()
try_me()
......@@ -5,6 +5,8 @@ Created on 25. apr. 2018
'''
import os
import numpy as np
from tests.test_files import tfp
def read_lib(filename):
with open(filename) as fid:
......@@ -13,7 +15,7 @@ def read_lib(filename):
descriptor = lines[0]
nRoughnessClasses, nHeights, nSectorslib = map(int, lines[2].split())
z0ref_lst = list(map(float, lines[4].split()))
# TODO: Implement for specified z0 and height
#
......@@ -38,9 +40,13 @@ def read_lib(filename):
# readln(fil);
# end;
# end;
f,A,k = [np.array(lines[i].split()[:nSectorslib], dtype=np.float) for i in [8, 10, 12]]
return f/100,A,k
f, A, k = [np.array(lines[i].split()[:nSectorslib], dtype=np.float) for i in [8, 10, 12]]
return f / 100, A, k
def try_me():
if __name__ == '__main__':
print(read_lib(tfp + "fuga_files/hornsrev2.lib"))
if __name__ == '__main__':
print(read_lib(os.path.dirname(__file__) + "/Colonel/LUT/Farms/Horns Rev 1/hornsrev2.lib"))
try_me()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment