Skip to content
Snippets Groups Projects
Commit a40b1960 authored by mads's avatar mads
Browse files

bug fixes, docs etc

parent 55f5fa54
No related branches found
No related tags found
No related merge requests found
......@@ -5,4 +5,5 @@ Created on 29/01/2016
'''
import pytest
import os
pytest.main(os.path.dirname(__file__) + "./../")
p = os.path.abspath(os.path.join(os.path.dirname(__file__) + "./../")).replace("\\", "/")
pytest.main(p)
......@@ -149,7 +149,10 @@ class DLCHighLevel(object):
start, step, stop = [float(eval(v, globals(), self.__dict__)) for v in values.lower().split(":")]
values = np.arange(start, stop + step, step)
else:
values = [(eval(v, globals(), self.__dict__)) for v in str(values).lower().replace("/", ",").split(",")]
try:
values = [(eval(v, globals(), self.__dict__)) for v in str(values).lower().replace("/", ",").split(",")]
except SyntaxError:
values = [(eval(v.lstrip('0'), globals(), self.__dict__)) for v in str(values).lower().replace("/", ",").split(",")]
dist = self.dlc_df[dist_key][row]
if str(dist).lower() == "weibull" or str(dist).lower() == "rayleigh":
......@@ -287,10 +290,10 @@ class DLCHighLevel(object):
if __name__ == "__main__":
dlc_hl = DLCHighLevel(r'X:\NREL5MW\dlc.xlsx')
dlc_hl = DLCHighLevel(r'X:\DTU10MW\Q0010\DLC_post_betas1.xlsx')
#print (DLCHighLevelInputFile(r'C:\mmpe\Projects\DLC.xlsx').sensor_info(0, 0, 1)['Name'])
#print (dlc_dict()['64'])
#print (dlc_hl.fatigue_distribution()['64'])
print (dlc_hl.file_hour_lst(r"X:\NREL5MW/C0008/res/"))
print (dlc_hl.file_hour_lst(r"X:\DTU10MW/Q0010/res/"))
......@@ -155,6 +155,8 @@ class HTCLine(HTCContents):
values = None
comments = ""
def __init__(self, name, values, comments):
if "__" in name:
name = name[:name.index("__")]
self.name_ = name
self.values = values
self.comments = comments
......
......@@ -13,6 +13,7 @@ from __future__ import absolute_import
from io import open
from builtins import str
from future import standard_library
from wetb.utils.process_exec import pexec
standard_library.install_aliases()
from collections import OrderedDict
......@@ -39,6 +40,7 @@ class HTCFile(HTCContents, HTCDefaults):
self.lines = self.empty_htc.split("\n")
else:
self.filename = filename
self.modelpath = os.path.realpath(os.path.join(os.path.dirname(self.filename), modelpath))
self.lines = self.readlines(filename)
# with open(filename) as fid:
# self.lines = fid.readlines()
......@@ -55,7 +57,7 @@ class HTCFile(HTCContents, HTCDefaults):
self._add_contents(line)
if line.name_ == "exit":
break
assert 'simulation' in self.contents, "%s could not be loaded. 'simulation' section missing" % filename
#assert 'simulation' in self.contents, "%s could not be loaded. 'simulation' section missing" % filename
def readlines(self, filename):
self.htc_inputfiles.append(filename)
......@@ -65,7 +67,7 @@ class HTCFile(HTCContents, HTCDefaults):
for l in lines:
if l.lower().lstrip().startswith('continue_in_file'):
filename = l.lstrip().split(";")[0][len("continue_in_file"):].strip()
filename = os.path.join(os.path.dirname(self.filename), self.modelpath, filename)
filename = os.path.join(self.modelpath, filename)
for line in self.readlines(filename):
if line.lstrip().lower().startswith('exit'):
......@@ -95,7 +97,10 @@ class HTCFile(HTCContents, HTCDefaults):
def set_name(self, name, folder="htc"):
self.filename = os.path.join(self.modelpath, folder, "%s.htc" % name).replace("\\", "/")
self.simulation.logfile = "./log/%s.log" % name
if 'simulation' in self and 'logfile' in self.simulation:
self.simulation.logfile = "./log/%s.log" % name
elif 'test_structure' in self and 'logfile' in self.test_structure:
self.test_structure.logfile = "./log/%s.log" % name
self.output.filename = "./res/%s" % name
def input_files(self):
......@@ -172,14 +177,22 @@ class HTCFile(HTCContents, HTCDefaults):
return []
dataformat = self.output.get('data_format', 'hawc_ascii')
res_filename = self.output.filename[0]
if dataformat == "gtsdf" or dataformat == "gtsdf64":
if dataformat[0] == "gtsdf" or dataformat[0] == "gtsdf64":
return [res_filename + ".hdf5"]
elif dataformat == "flex_int":
elif dataformat[0] == "flex_int":
return [res_filename + ".int", os.path.join(os.path.dirname(res_filename), 'sensor')]
else:
return [res_filename + ".sel", res_filename + ".dat"]
def simulate(self, exe):
self.save()
htcfile = os.path.relpath(self.filename, self.modelpath)
hawc2exe = exe
errorcode, stdout, stderr, cmd = pexec([hawc2exe, htcfile], self.modelpath)
if errorcode or 'Elapsed time' not in stderr:
raise Exception (str(stdout) + str(stderr))
if "__main__" == __name__:
f = HTCFile(r"C:\mmpe\HAWC2\Hawc2_model\htc\NREL_5MW_reference_wind_turbine_launcher_test.htc")
......
......@@ -76,12 +76,43 @@ class PCFile(AEFile):
return Cx0 + (Cx1 - Cx0) * (thickness - th0) / (th1 - th0)
def CL(self, radius, alpha, ae_set_nr=1):
"""Lift coefficient
Parameters
---------
radius : float
radius [m]
alpha : float
Angle of attack [deg]
ae_set_nr : int optional
Aerdynamic set number, default is 1
Returns
-------
Lift coefficient : float
"""
return self._Cxxx(radius, alpha, 1, ae_set_nr)
def CD(self, radius, alpha, ae_set_nr=1):
"""Drag coefficient
Parameters
---------
radius : float
radius [m]
alpha : float
Angle of attack [deg]
ae_set_nr : int optional
Aerdynamic set number, default is 1
Returns
-------
Drag coefficient : float
"""
return self._Cxxx(radius, alpha, 2, ae_set_nr)
def CM(self, radius, alpha, ae_set_nr=1):
return self._Cxxx(radius, alpha, 3, ae_set_nr)
if __name__ == "__main__":
......
......@@ -297,7 +297,7 @@ class SimulationThread(Thread):
htcfile = os.path.relpath(self.sim.htcFile.filename, self.sim.modelpath)
hawc2exe = self.sim.hawc2exe
stdout = self.sim.stdout_filename
self.process = subprocess.Popen("%s %s 1> %s 2>&1" % (hawc2exe, htcfile, stdout), stdout=None, stderr=None, shell=True, cwd=modelpath, creationflags=CREATE_NO_WINDOW)
self.process = subprocess.Popen('"%s" %s 1> %s 2>&1' % (hawc2exe, htcfile, stdout), stdout=None, stderr=None, shell=True, cwd=modelpath, creationflags=CREATE_NO_WINDOW)
Thread.start(self)
......
......@@ -381,7 +381,10 @@ def py2pyx(pylines):
indent = l[:len(l) - len(l.lstrip())]
cdef = l[l.index("#c") + 1:]
l = indent + cdef
pyxlines.append(l)
if "__future__" in l:
pyxlines.insert(0, l) # from __future__ import ... must be first
else:
pyxlines.append(l)
return pyxlines
......
......@@ -168,11 +168,11 @@ def abvrel2xyz(alpha, beta, vrel):
Parameters
----------
alpha : array_like
Pitot tube angle of attack
Pitot tube angle of attack. Zero: Parallel to pitot tube. Positive: Flow from wind side (pressure side)
beta : array_like
Pitot tube side slip angle
Pitot tube side slip angle. Zero: Parallel to pitot tube. Positive: Flow from root side
vrel : array_like
Pitot tube relative velocity
Pitot tube relative velocity. Positive: flow towards pitot tube
Returns
-------
......@@ -181,13 +181,13 @@ def abvrel2xyz(alpha, beta, vrel):
y : array_like
Wind component in alpha plane (positive for positive alpha)
z : array_like
Wind component in beta plane (positive for positive beta)
Wind component in beta plane (positive for negative beta)
"""
alpha = np.array(alpha, dtype=np.float)
beta = np.array(beta, dtype=np.float)
vrel = np.array(vrel, dtype=np.float)
sign_vsx = -((np.abs(beta) > np.pi / 2) * 2 - 1) # +1 for |beta| <= 90, -1 for |beta|>90
sign_vsx = -((np.abs(beta) > np.pi / 2) * 2 - 1) # +1 for |beta| < 90, -1 for |beta|>90
sign_vsy = np.sign(alpha) #+ for alpha > 0
sign_vsz = -np.sign(beta) #- for beta>0
......@@ -196,10 +196,10 @@ def abvrel2xyz(alpha, beta, vrel):
m = alpha != 0
y = np.zeros_like(alpha)
y[m] = sign_vsy * np.sqrt(vrel[m] ** 2 / ((1 / np.tan(alpha[m])) ** 2 + 1 + (np.tan(beta[m]) / np.tan(alpha[m])) ** 2))
y[m] = sign_vsy[m] * np.sqrt(vrel[m] ** 2 / ((1 / np.tan(alpha[m])) ** 2 + 1 + (np.tan(beta[m]) / np.tan(alpha[m])) ** 2))
m = beta != 0
z = np.zeros_like(alpha)
z[m] = sign_vsz * np.sqrt(vrel[m] ** 2 / ((1 / np.tan(beta[m])) ** 2 + 1 + (np.tan(alpha[m]) / np.tan(beta[m])) ** 2))
z[m] = sign_vsz[m] * np.sqrt(vrel[m] ** 2 / ((1 / np.tan(beta[m])) ** 2 + 1 + (np.tan(alpha[m]) / np.tan(beta[m])) ** 2))
return x, y, z
......@@ -169,7 +169,7 @@ def fit_log_shear(z_u_lst, include_R=False):
Example
--------
>>> fit_log_shear([(85, 8.88131), (21, 4.41832)], 87.13333)
>>> fit_log_shear([(85, 8.88131), (21, 4.41832)])
[ 0.49938238 8.99192568]
"""
# def shear_error(x, z_u_lst):
......
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