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
b16457ab
Commit
b16457ab
authored
7 years ago
by
Mads M. Pedersen
Browse files
Options
Downloads
Patches
Plain Diff
closes
#35
parent
0169ebda
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
wetb/hawc2/htc_contents.py
+10
-0
10 additions, 0 deletions
wetb/hawc2/htc_contents.py
wetb/hawc2/htc_file.py
+31
-21
31 additions, 21 deletions
wetb/hawc2/htc_file.py
wetb/hawc2/tests/test_htc_file.py
+9
-3
9 additions, 3 deletions
wetb/hawc2/tests/test_htc_file.py
with
50 additions
and
24 deletions
wetb/hawc2/htc_contents.py
+
10
−
0
View file @
b16457ab
...
@@ -175,6 +175,16 @@ class HTCSection(HTCContents):
...
@@ -175,6 +175,16 @@ class HTCSection(HTCContents):
s
+=
""
.
join
([
c
.
__str__
(
level
+
1
)
for
c
in
self
])
s
+=
""
.
join
([
c
.
__str__
(
level
+
1
)
for
c
in
self
])
s
+=
"
%send %s;%s
\n
"
%
(
"
"
*
level
,
self
.
name_
,
((
""
,
"
\t
"
+
self
.
end_comments
)[
self
.
end_comments
.
strip
()
!=
""
]).
replace
(
"
\t\n
"
,
"
\n
"
))
s
+=
"
%send %s;%s
\n
"
%
(
"
"
*
level
,
self
.
name_
,
((
""
,
"
\t
"
+
self
.
end_comments
)[
self
.
end_comments
.
strip
()
!=
""
]).
replace
(
"
\t\n
"
,
"
\n
"
))
return
s
return
s
def
get_subsection_by_name
(
self
,
name
):
lst
=
[
s
for
s
in
self
if
'
name
'
in
s
and
s
.
name
[
0
]
==
name
]
if
len
(
lst
)
==
1
:
return
lst
[
0
]
else
:
if
len
(
lst
)
==
0
:
raise
ValueError
(
"
subsection
'
%s
'
not found
"
%
name
)
else
:
raise
NotImplementedError
()
class
HTCLine
(
HTCContents
):
class
HTCLine
(
HTCContents
):
values
=
None
values
=
None
...
...
This diff is collapsed.
Click to expand it.
wetb/hawc2/htc_file.py
+
31
−
21
View file @
b16457ab
...
@@ -197,21 +197,21 @@ class HTCFile(HTCContents, HTCDefaults):
...
@@ -197,21 +197,21 @@ class HTCFile(HTCContents, HTCDefaults):
with
open
(
filename
,
'
w
'
,
encoding
=
'
cp1252
'
)
as
fid
:
with
open
(
filename
,
'
w
'
,
encoding
=
'
cp1252
'
)
as
fid
:
fid
.
write
(
str
(
self
))
fid
.
write
(
str
(
self
))
def
set_name
(
self
,
name
,
htc_folder
=
"
htc
"
,
log_folder
=
"
log
"
,
res_folder
=
"
res
"
,
animation_folder
=
'
animation
'
,
visualization_folder
=
"
visualization
"
):
def
set_name
(
self
,
name
,
subfolder
=
''
):
#if os.path.isabs(folder) is False and os.path.relpath(folder).startswith("htc" + os.path.sep):
#if os.path.isabs(folder) is False and os.path.relpath(folder).startswith("htc" + os.path.sep):
self
.
contents
#load if not loaded
self
.
contents
#load if not loaded
fmt_folder
=
lambda
folder
:
"
./
"
+
os
.
path
.
relpath
(
folder
).
replace
(
"
\\
"
,
"
/
"
)
fmt_folder
=
lambda
folder
,
subfolder
:
"
./
"
+
os
.
path
.
relpath
(
os
.
path
.
join
(
folder
,
subfolder
)
).
replace
(
"
\\
"
,
"
/
"
)
self
.
filename
=
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
modelpath
,
fmt_folder
(
htc
_
folder
),
"
%s.htc
"
%
name
)).
replace
(
"
\\
"
,
"
/
"
)
self
.
filename
=
os
.
path
.
abspath
(
os
.
path
.
join
(
self
.
modelpath
,
fmt_folder
(
'
htc
'
,
sub
folder
),
"
%s.htc
"
%
name
)).
replace
(
"
\\
"
,
"
/
"
)
if
'
simulation
'
in
self
and
'
logfile
'
in
self
.
simulation
:
if
'
simulation
'
in
self
and
'
logfile
'
in
self
.
simulation
:
self
.
simulation
.
logfile
=
os
.
path
.
join
(
fmt_folder
(
log_folder
),
"
%s.log
"
%
name
).
replace
(
"
\\
"
,
"
/
"
)
self
.
simulation
.
logfile
=
os
.
path
.
join
(
fmt_folder
(
'
log
'
,
subfolder
),
"
%s.log
"
%
name
).
replace
(
"
\\
"
,
"
/
"
)
if
'
animation
'
in
self
.
simulation
:
self
.
simulation
.
animation
=
os
.
path
.
join
(
fmt_folder
(
'
animation
'
,
subfolder
),
"
%s.dat
"
%
name
).
replace
(
"
\\
"
,
"
/
"
)
if
'
visualization
'
in
self
.
simulation
:
self
.
simulation
.
visualization
=
os
.
path
.
join
(
fmt_folder
(
'
visualization
'
,
subfolder
),
"
%s.hdf5
"
%
name
).
replace
(
"
\\
"
,
"
/
"
)
elif
'
test_structure
'
in
self
and
'
logfile
'
in
self
.
test_structure
:
# hawc2aero
elif
'
test_structure
'
in
self
and
'
logfile
'
in
self
.
test_structure
:
# hawc2aero
self
.
test_structure
.
logfile
=
os
.
path
.
join
(
fmt_folder
(
log_folder
),
"
%s.log
"
%
name
).
replace
(
"
\\
"
,
"
/
"
)
self
.
test_structure
.
logfile
=
os
.
path
.
join
(
fmt_folder
(
'
log
'
,
subfolder
),
"
%s.log
"
%
name
).
replace
(
"
\\
"
,
"
/
"
)
if
'
simulation
'
in
self
and
'
animation
'
in
self
.
simulation
:
self
.
output
.
filename
=
os
.
path
.
join
(
fmt_folder
(
'
res
'
,
subfolder
),
"
%s
"
%
name
).
replace
(
"
\\
"
,
"
/
"
)
self
.
simulation
.
animation
=
os
.
path
.
join
(
fmt_folder
(
animation_folder
),
"
%s.dat
"
%
name
).
replace
(
"
\\
"
,
"
/
"
)
if
'
simulation
'
in
self
and
'
visualization
'
in
self
.
simulation
:
self
.
simulation
.
visualization
=
os
.
path
.
join
(
fmt_folder
(
visualization_folder
),
"
%s.hdf5
"
%
name
).
replace
(
"
\\
"
,
"
/
"
)
self
.
output
.
filename
=
os
.
path
.
join
(
fmt_folder
(
res_folder
),
"
%s
"
%
name
).
replace
(
"
\\
"
,
"
/
"
)
def
set_time
(
self
,
start
=
None
,
stop
=
None
,
step
=
None
):
def
set_time
(
self
,
start
=
None
,
stop
=
None
,
step
=
None
):
self
.
contents
# load if not loaded
self
.
contents
# load if not loaded
...
@@ -262,6 +262,14 @@ class HTCFile(HTCContents, HTCDefaults):
...
@@ -262,6 +262,14 @@ class HTCFile(HTCContents, HTCDefaults):
if
'
soil
'
in
self
:
if
'
soil
'
in
self
:
if
'
soil_element
'
in
self
.
soil
:
if
'
soil_element
'
in
self
.
soil
:
files
.
append
(
self
.
soil
.
soil_element
.
get
(
'
datafile
'
,
[
None
])[
0
])
files
.
append
(
self
.
soil
.
soil_element
.
get
(
'
datafile
'
,
[
None
])[
0
])
try
:
dtu_we_controller
=
self
.
dll
.
get_subsection_by_name
(
'
dtu_we_controller
'
)
theta_min
=
dtu_we_controller
.
init
.
constant__5
[
1
]
files
.
append
(
os
.
path
.
join
(
os
.
path
.
dirname
(
dtu_we_controller
.
filename
[
0
]),
"
wpdata.%d
"
%
theta_min
).
replace
(
"
\\
"
,
"
/
"
))
except
:
pass
try
:
try
:
files
.
append
(
self
.
force
.
dll
.
dll
[
0
])
files
.
append
(
self
.
force
.
dll
.
dll
[
0
])
except
:
except
:
...
@@ -362,16 +370,18 @@ class HTCFile(HTCContents, HTCDefaults):
...
@@ -362,16 +370,18 @@ class HTCFile(HTCContents, HTCDefaults):
def
deltat
(
self
):
def
deltat
(
self
):
return
self
.
simulation
.
newmark
.
deltat
[
0
]
return
self
.
simulation
.
newmark
.
deltat
[
0
]
def
get_body
(
self
,
name
):
lst
=
[
b
for
b
in
self
.
new_htc_structure
if
b
.
name_
==
"
main_body
"
and
b
.
name
[
0
]
==
name
]
#
if
len
(
lst
)
==
1
:
# def get_body(self, name):
return
lst
[
0
]
# lst = [b for b in self.new_htc_structure if b.name_=="main_body" and b.name[0]==name]
else
:
# if len(lst)==1:
if
len
(
lst
)
==
0
:
# return lst[0]
raise
ValueError
(
"
Body
'
%s
'
not found
"
%
name
)
# else:
else
:
# if len(lst)==0:
raise
NotImplementedError
()
# raise ValueError("Body '%s' not found"%name)
# else:
# raise NotImplementedError()
#
class
H2aeroHTCFile
(
HTCFile
):
class
H2aeroHTCFile
(
HTCFile
):
def
__init__
(
self
,
filename
=
None
,
modelpath
=
None
):
def
__init__
(
self
,
filename
=
None
,
modelpath
=
None
):
...
...
This diff is collapsed.
Click to expand it.
wetb/hawc2/tests/test_htc_file.py
+
9
−
3
View file @
b16457ab
...
@@ -107,12 +107,15 @@ class TestHtcFile(unittest.TestCase):
...
@@ -107,12 +107,15 @@ class TestHtcFile(unittest.TestCase):
def
test_htcfile_setname
(
self
):
def
test_htcfile_setname
(
self
):
htcfile
=
HTCFile
(
self
.
testfilepath
+
"
test.htc
"
)
htcfile
=
HTCFile
(
self
.
testfilepath
+
"
test.htc
"
)
htcfile
.
set_name
(
"
mytest
"
,
htc_folder
=
"
htcfiles
"
)
htcfile
.
set_name
(
"
mytest
"
)
self
.
assertEqual
(
os
.
path
.
relpath
(
htcfile
.
filename
,
self
.
testfilepath
),
r
'
mytest.htc
'
)
self
.
assertEqual
(
os
.
path
.
relpath
(
htcfile
.
filename
,
self
.
testfilepath
),
r
'
..\htc\
mytest.htc
'
)
self
.
assertEqual
(
htcfile
.
simulation
.
logfile
[
0
],
'
./log/mytest.log
'
)
self
.
assertEqual
(
htcfile
.
simulation
.
logfile
[
0
],
'
./log/mytest.log
'
)
self
.
assertEqual
(
htcfile
.
output
.
filename
[
0
],
'
./res/mytest
'
)
self
.
assertEqual
(
htcfile
.
output
.
filename
[
0
],
'
./res/mytest
'
)
htcfile
.
set_name
(
"
mytest
"
,
'
subfolder
'
)
self
.
assertEqual
(
os
.
path
.
relpath
(
htcfile
.
filename
,
self
.
testfilepath
),
r
'
..\htc\subfolder\mytest.htc
'
)
self
.
assertEqual
(
htcfile
.
simulation
.
logfile
[
0
],
'
./log/subfolder/mytest.log
'
)
self
.
assertEqual
(
htcfile
.
output
.
filename
[
0
],
'
./res/subfolder/mytest
'
)
def
test_set_time
(
self
):
def
test_set_time
(
self
):
htcfile
=
HTCFile
(
self
.
testfilepath
+
"
test.htc
"
)
htcfile
=
HTCFile
(
self
.
testfilepath
+
"
test.htc
"
)
...
@@ -248,6 +251,9 @@ end turb_export;"""
...
@@ -248,6 +251,9 @@ end turb_export;"""
except
ValueError
:
except
ValueError
:
raise
ValueError
(
f
+
"
is not in list
"
)
raise
ValueError
(
f
+
"
is not in list
"
)
self
.
assertFalse
(
input_files
)
self
.
assertFalse
(
input_files
)
htcfile
=
HTCFile
(
self
.
testfilepath
+
"
DTU_10MW_RWT.htc
"
)
self
.
assertTrue
(
'
./control/wpdata.100
'
in
htcfile
.
input_files
())
def
test_input_files2
(
self
):
def
test_input_files2
(
self
):
htcfile
=
HTCFile
(
self
.
testfilepath
+
"
ansi.htc
"
,
'
../
'
)
htcfile
=
HTCFile
(
self
.
testfilepath
+
"
ansi.htc
"
,
'
../
'
)
...
...
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