Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
toolbox
WindEnergyToolbox
Commits
c1cddc59
Commit
c1cddc59
authored
6 years ago
by
David Verelst
Committed by
David Verelst
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
hawc2.StFile: add method to save st file (plus test)
parent
a6ba4dae
No related branches found
No related tags found
1 merge request
!95
Save st
Pipeline
#6954
passed
6 years ago
Stage: test
Stage: deploy
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
wetb/hawc2/st_file.py
+32
-8
32 additions, 8 deletions
wetb/hawc2/st_file.py
wetb/hawc2/tests/test_st_file.py
+20
-3
20 additions, 3 deletions
wetb/hawc2/tests/test_st_file.py
with
52 additions
and
11 deletions
wetb/hawc2/st_file.py
+
32
−
8
View file @
c1cddc59
...
@@ -15,6 +15,10 @@ standard_library.install_aliases()
...
@@ -15,6 +15,10 @@ standard_library.install_aliases()
import
numpy
as
np
import
numpy
as
np
stcols
=
"
r m x_cg y_cg ri_x ri_y x_sh y_sh E G I_x I_y I_p k_x k_y A pitch x_e y_e
"
class
StFile
(
object
):
class
StFile
(
object
):
"""
Read HAWC2 St (beam element structural data) file
"""
Read HAWC2 St (beam element structural data) file
...
@@ -69,7 +73,7 @@ class StFile(object):
...
@@ -69,7 +73,7 @@ class StFile(object):
with
open
(
filename
)
as
fid
:
with
open
(
filename
)
as
fid
:
txt
=
fid
.
read
()
txt
=
fid
.
read
()
# Some files starts with first set ("#1...") with out specifying number of sets
# Some files starts with first set ("#1...") with out specifying number of sets
# no_maindata_sets = int(txt.strip()[0])
# no_maindata_sets = int(txt.strip()[0])
# assert no_maindata_sets == txt.count("#")
# assert no_maindata_sets == txt.count("#")
self
.
main_data_sets
=
{}
self
.
main_data_sets
=
{}
for
mset
in
txt
.
split
(
"
#
"
)[
1
:]:
for
mset
in
txt
.
split
(
"
#
"
)[
1
:]:
...
@@ -83,8 +87,9 @@ class StFile(object):
...
@@ -83,8 +87,9 @@ class StFile(object):
set_data_dict
[
set_nr
]
=
np
.
array
([
set_lines
[
i
].
split
()
for
i
in
range
(
1
,
no_rows
+
1
)],
dtype
=
np
.
float
)
set_data_dict
[
set_nr
]
=
np
.
array
([
set_lines
[
i
].
split
()
for
i
in
range
(
1
,
no_rows
+
1
)],
dtype
=
np
.
float
)
self
.
main_data_sets
[
mset_nr
]
=
set_data_dict
self
.
main_data_sets
[
mset_nr
]
=
set_data_dict
for
i
,
name
in
enumerate
(
"
r m x_cg y_cg ri_x ri_y x_sh y_sh E G I_x I_y I_p k_x k_y A pitch x_e y_e
"
.
split
()):
for
i
,
name
in
enumerate
(
stcols
.
split
()):
setattr
(
self
,
name
,
lambda
radius
=
None
,
mset
=
1
,
set
=
1
,
column
=
i
:
self
.
_value
(
radius
,
column
,
mset
,
set
))
setattr
(
self
,
name
,
lambda
radius
=
None
,
mset
=
1
,
set
=
1
,
column
=
i
:
self
.
_value
(
radius
,
column
,
mset
,
set
))
def
_value
(
self
,
radius
,
column
,
mset_nr
=
1
,
set_nr
=
1
):
def
_value
(
self
,
radius
,
column
,
mset_nr
=
1
,
set_nr
=
1
):
st_data
=
self
.
main_data_sets
[
mset_nr
][
set_nr
]
st_data
=
self
.
main_data_sets
[
mset_nr
][
set_nr
]
...
@@ -98,14 +103,35 @@ class StFile(object):
...
@@ -98,14 +103,35 @@ class StFile(object):
return
r
return
r
return
r
[
np
.
argmin
(
np
.
abs
(
r
-
radius
))]
return
r
[
np
.
argmin
(
np
.
abs
(
r
-
radius
))]
def
to_str
(
self
,
mset
=
1
,
set
=
1
):
def
to_str
(
self
,
mset
=
1
,
set
=
1
,
precision
=
'
%12.5e
'
):
d
=
self
.
main_data_sets
[
mset
][
set
]
d
=
self
.
main_data_sets
[
mset
][
set
]
return
"
\n
"
.
join
([(
"
%12.5e
"
*
d
.
shape
[
1
])
%
tuple
(
row
)
for
row
in
d
])
return
'
\n
'
.
join
([(
precision
*
d
.
shape
[
1
])
%
tuple
(
row
)
for
row
in
d
])
def
save
(
self
,
filename
,
precision
=
'
%15.07e
'
,
encoding
=
'
utf-8
'
):
"""
Save all data defined in main_data_sets to st file.
"""
colwidth
=
len
(
precision
%
1
)
sep
=
'
=
'
*
colwidth
*
len
(
stcols
)
+
'
\n
'
colhead
=
''
.
join
([
k
.
center
(
colwidth
)
for
k
in
stcols
.
split
()])
+
'
\n
'
nsets
=
len
(
self
.
main_data_sets
)
with
open
(
filename
,
'
w
'
,
encoding
=
encoding
)
as
fid
:
fid
.
write
(
'
%i ; number of sets, Nset
\n
'
%
nsets
)
for
mset
,
set_data_dict
in
self
.
main_data_sets
.
items
():
fid
.
write
(
'
#%i ; set number
\n
'
%
mset
)
for
set
,
set_array
in
set_data_dict
.
items
():
dstr
=
self
.
to_str
(
mset
=
mset
,
set
=
set
,
precision
=
precision
)
npoints
=
self
.
main_data_sets
[
mset
][
set
].
shape
[
0
]
fid
.
write
(
sep
+
colhead
+
sep
)
fid
.
write
(
'
$%i %i
\n
'
%
(
set
,
npoints
))
fid
.
write
(
dstr
+
'
\n
'
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
import
os
import
os
st
=
StFile
(
os
.
path
.
dirname
(
__file__
)
+
r
"
/tests/test_files/DTU_10MW_RWT_Blade_st.dat
"
)
cwd
=
os
.
path
.
dirname
(
__file__
)
st
=
StFile
(
os
.
path
.
join
(
cwd
,
r
'
tests/test_files/DTU_10MW_RWT_Blade_st.dat
'
))
print
(
st
.
m
())
print
(
st
.
m
())
print
(
st
.
E
(
radius
=
36
,
mset
=
1
,
set
=
1
))
# Elastic blade
print
(
st
.
E
(
radius
=
36
,
mset
=
1
,
set
=
1
))
# Elastic blade
print
(
st
.
E
(
radius
=
36
,
mset
=
1
,
set
=
2
))
# stiff blade
print
(
st
.
E
(
radius
=
36
,
mset
=
1
,
set
=
2
))
# stiff blade
...
@@ -122,7 +148,5 @@ if __name__ == "__main__":
...
@@ -122,7 +148,5 @@ if __name__ == "__main__":
print
(
st
.
pitch
(
67.8883
-
0.01687
))
print
(
st
.
pitch
(
67.8883
-
0.01687
))
print
(
st
.
pitch
(
23.2446
))
print
(
st
.
pitch
(
23.2446
))
#print (st.)
#print (st.)
#print (st.)
#print (st.)
This diff is collapsed.
Click to expand it.
wetb/hawc2/tests/test_st_file.py
+
20
−
3
View file @
c1cddc59
...
@@ -10,15 +10,19 @@ from __future__ import absolute_import
...
@@ -10,15 +10,19 @@ from __future__ import absolute_import
from
future
import
standard_library
from
future
import
standard_library
standard_library
.
install_aliases
()
standard_library
.
install_aliases
()
import
unittest
import
unittest
from
wetb.hawc2.st_file
import
StFile
import
os
import
os
from
numpy
import
testing
from
wetb.hawc2.st_file
import
StFile
testfilepath
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
test_files/
'
)
# test file path
testfilepath
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
test_files/
'
)
# test file path
class
TestStFile
(
unittest
.
TestCase
):
class
TestStFile
(
unittest
.
TestCase
):
def
test_stfile
(
self
):
def
test_stfile
(
self
):
st
=
StFile
(
testfilepath
+
"
DTU_10MW_RWT_Blade_st.dat
"
)
st
=
StFile
(
testfilepath
+
'
DTU_10MW_RWT_Blade_st.dat
'
)
self
.
assertEqual
(
st
.
radius_st
()[
2
],
3.74238
)
self
.
assertEqual
(
st
.
radius_st
()[
2
],
3.74238
)
self
.
assertEqual
(
st
.
radius_st
(
3
),
3.74238
)
self
.
assertEqual
(
st
.
radius_st
(
3
),
3.74238
)
self
.
assertEqual
(
st
.
x_e
(
67.7351
),
4.4320990737400E-01
)
self
.
assertEqual
(
st
.
x_e
(
67.7351
),
4.4320990737400E-01
)
...
@@ -27,10 +31,23 @@ class TestStFile(unittest.TestCase):
...
@@ -27,10 +31,23 @@ class TestStFile(unittest.TestCase):
def
test_stfile_interpolate
(
self
):
def
test_stfile_interpolate
(
self
):
st
=
StFile
(
testfilepath
+
"
DTU_10MW_RWT_Blade_st.dat
"
)
st
=
StFile
(
testfilepath
+
'
DTU_10MW_RWT_Blade_st.dat
'
)
self
.
assertAlmostEqual
(
st
.
x_e
(
72.2261
),
0.381148048
)
self
.
assertAlmostEqual
(
st
.
x_e
(
72.2261
),
0.381148048
)
self
.
assertAlmostEqual
(
st
.
y_e
(
72.2261
),
0.016692967
)
self
.
assertAlmostEqual
(
st
.
y_e
(
72.2261
),
0.016692967
)
def
test_save
(
self
):
fname
=
os
.
path
.
join
(
testfilepath
,
'
DTU_10MW_RWT_Blade_st.dat
'
)
fname2
=
os
.
path
.
join
(
testfilepath
,
'
DTU_10MW_RWT_Blade_st2.dat
'
)
st
=
StFile
(
fname
)
st
.
save
(
fname2
,
encoding
=
'
utf-8
'
,
precision
=
'
%20.12e
'
)
st2
=
StFile
(
fname2
)
self
.
assertEqual
(
len
(
st
.
main_data_sets
),
len
(
st2
.
main_data_sets
))
self
.
assertEqual
(
len
(
st
.
main_data_sets
[
1
]),
len
(
st2
.
main_data_sets
[
1
]))
for
k
in
st
.
main_data_sets
[
1
]:
testing
.
assert_almost_equal
(
st
.
main_data_sets
[
1
][
k
],
st2
.
main_data_sets
[
1
][
k
],
decimal
=
12
)
os
.
remove
(
fname2
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
#import sys;sys.argv = ['', 'Test.testName']
#import sys;sys.argv = ['', 'Test.testName']
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment