Newer
Older
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 3 19:53:59 2014
@author: dave
"""
from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals
from __future__ import absolute_import
from builtins import dict
from io import open as opent
from builtins import range
from builtins import str
from builtins import int
from future import standard_library
standard_library.install_aliases()
from builtins import object
__author__ = 'David Verelst'
__license__ = 'GPL'
__version__ = '0.5'
import os
import copy
import struct
import math
from time import time
import codecs
from itertools import chain
import scipy as sp
import scipy.integrate as integrate
import pandas as pd
# misc is part of prepost, which is available on the dtu wind gitlab server:
# https://gitlab.windenergy.dtu.dk/dave/prepost
from wetb.prepost import misc
# wind energy python toolbox, available on the dtu wind redmine server:
# http://vind-redmine.win.dtu.dk/projects/pythontoolbox/repository/show/fatigue_tools
from wetb.fatigue_tools.fatigue import (eq_load, cycle_matrix2)
class LogFile(object):
"""Check a HAWC2 log file for errors.
"""
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# the total message list log:
self.MsgListLog = []
# a smaller version, just indication if there are errors:
self.MsgListLog2 = dict()
# specify which message to look for. The number track's the order.
# this makes it easier to view afterwards in spreadsheet:
# every error will have its own column
# error messages that appear during initialisation
self.err_init = {}
self.err_init[' *** ERROR *** Error in com'] = len(self.err_init)
self.err_init[' *** ERROR *** in command '] = len(self.err_init)
# *** WARNING *** A comma "," is written within the command line
self.err_init[' *** WARNING *** A comma ",'] = len(self.err_init)
# *** ERROR *** Not correct number of parameters
self.err_init[' *** ERROR *** Not correct '] = len(self.err_init)
# *** INFO *** End of file reached
self.err_init[' *** INFO *** End of file r'] = len(self.err_init)
# *** ERROR *** No line termination in command line
self.err_init[' *** ERROR *** No line term'] = len(self.err_init)
# *** ERROR *** MATRIX IS NOT DEFINITE
self.err_init[' *** ERROR *** MATRIX IS NO'] = len(self.err_init)
# *** ERROR *** There are unused relative
self.err_init[' *** ERROR *** There are un'] = len(self.err_init)
# *** ERROR *** Error finding body based
self.err_init[' *** ERROR *** Error findin'] = len(self.err_init)
# *** ERROR *** In body actions
self.err_init[' *** ERROR *** In body acti'] = len(self.err_init)
# *** ERROR *** Command unknown and ignored
self.err_init[' *** ERROR *** Command unkn'] = len(self.err_init)
# *** ERROR *** ERROR - More bodies than elements on main_body: tower
self.err_init[' *** ERROR *** ERROR - More'] = len(self.err_init)
# *** ERROR *** The program will stop
self.err_init[' *** ERROR *** The program '] = len(self.err_init)
# *** ERROR *** Unknown begin command in topologi.
self.err_init[' *** ERROR *** Unknown begi'] = len(self.err_init)
# *** ERROR *** Not all needed topologi main body commands present
self.err_init[' *** ERROR *** Not all need'] = len(self.err_init)
# *** ERROR *** opening timoschenko data file
self.err_init[' *** ERROR *** opening tim'] = len(self.err_init)
# *** ERROR *** Error opening AE data file
self.err_init[' *** ERROR *** Error openin'] = len(self.err_init)
# *** ERROR *** Requested blade _ae set number not found in _ae file
self.err_init[' *** ERROR *** Requested bl'] = len(self.err_init)
# Error opening PC data file
self.err_init[' Error opening PC data file'] = len(self.err_init)
# *** ERROR *** error reading mann turbulence
self.err_init[' *** ERROR *** error readin'] = len(self.err_init)
# # *** INFO *** The DLL subroutine
# self.err_init[' *** INFO *** The DLL subro'] = len(self.err_init)
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# ** WARNING: FROM ESYS ELASTICBAR: No keyword
self.err_init[' ** WARNING: FROM ESYS ELAS'] = len(self.err_init)
# *** ERROR *** DLL ./control/killtrans.dll could not be loaded - error!
self.err_init[' *** ERROR *** DLL'] = len(self.err_init)
# *** ERROR *** The DLL subroutine
self.err_init[' *** ERROR *** The DLL subr'] = len(self.err_init)
# *** ERROR *** Mann turbulence length scale must be larger than zero!
# *** ERROR *** Mann turbulence alpha eps value must be larger than zero!
# *** ERROR *** Mann turbulence gamma value must be larger than zero!
self.err_init[' *** ERROR *** Mann turbule'] = len(self.err_init)
# *** WARNING *** Shear center x location not in elastic center, set to zero
self.err_init[' *** WARNING *** Shear cent'] = len(self.err_init)
# Turbulence file ./xyz.bin does not exist
self.err_init[' Turbulence file '] = len(self.err_init)
self.err_init[' *** WARNING ***'] = len(self.err_init)
self.err_init[' *** ERROR ***'] = len(self.err_init)
self.err_init[' WARNING'] = len(self.err_init)
self.err_init[' ERROR'] = len(self.err_init)
# error messages that appear during simulation
self.err_sim = {}
# *** ERROR *** Wind speed requested inside
self.err_sim[' *** ERROR *** Wind speed r'] = len(self.err_sim)
# Maximum iterations exceeded at time step:
self.err_sim[' Maximum iterations exceede'] = len(self.err_sim)
# Solver seems not to converge:
self.err_sim[' Solver seems not to conver'] = len(self.err_sim)
# *** ERROR *** Out of x bounds:
self.err_sim[' *** ERROR *** Out of x bou'] = len(self.err_sim)
# *** ERROR *** Out of limits in user defined shear field - limit value used
self.err_sim[' *** ERROR *** Out of limit'] = len(self.err_sim)
# TODO: error message from a non existing channel output/input
# add more messages if required...
self.init_cols = len(self.err_init)
self.sim_cols = len(self.err_sim)
self.header = None
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def readlog(self, fname, case=None, save_iter=False):
"""
"""
# open the current log file
with open(fname, 'r') as f:
lines = f.readlines()
# keep track of the messages allready found in this file
tempLog = []
tempLog.append(fname)
exit_correct, found_error = False, False
subcols_sim = 4
subcols_init = 2
# create empty list item for the different messages and line
# number. Include one column for non identified messages
for j in range(self.init_cols):
# 2 sub-columns per message: nr, msg
for k in range(subcols_init):
tempLog.append('')
for j in range(self.sim_cols):
# 4 sub-columns per message: first, last, nr, msg
for k in range(subcols_sim):
tempLog.append('')
# and two more columns at the end for messages of unknown origin
tempLog.append('')
tempLog.append('')
# if there is a cases object, see how many time steps we expect
if case is not None:
dt = float(case['[dt_sim]'])
time_steps = int(float(case['[time_stop]']) / dt)
iterations = np.ndarray( (time_steps+1,3), dtype=np.float32 )
else:
iterations = np.ndarray( (len(lines),3), dtype=np.float32 )
dt = False
iterations[:,0:2] = np.nan
iterations[:,2] = 0
# keep track of the time_step number
time_step, init_block = 0, True
# check for messages in the current line
# for speed: delete from message watch list if message is found
for j, line in enumerate(lines):
# all id's of errors are 27 characters long
msg = line[:27]
# remove the line terminator, this seems to take 2 characters
# on PY2, but only one in PY3
line = line.replace('\n', '')
# keep track of the number of iterations
if line[:12] == ' Global time':
iterations[time_step,0] = float(line[14:40])
# for PY2, new line is 2 characters, for PY3 it is one char
iterations[time_step,1] = int(line[-6:])
# time step is the first time stamp
if not dt:
dt = float(line[15:40])
Loading
Loading full blame...