-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturbineStreamTube.py
117 lines (85 loc) · 4.02 KB
/
turbineStreamTube.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python3
import logging
LEVEL = logging.INFO
logger = logging.getLogger(__name__)
import sys
import argparse
import paraview
paraview.compatibility.major = 5
paraview.compatibility.minor = 13
import paraview.simple as pv
pv._DisableFirstRenderCameraReset() # disable automatic camera reset on 'Show'
import utils
import constants as const
################################################################################
def turbineStreamTube(casename):
"""Created by Jeffrey Johnston for sowfatools. October 2024.
Use paraview to generate turbine streamtubes.
"""
directory = const.PARAVIEW_DIRECTORY/casename
if not directory.is_dir():
logger.warning(f'No directory found for case {casename}')
return
logger.info(f'Processing case {casename}')
utils.create_directory(directory/'streamtube')
# Load case data
datafilepath = directory/f'{casename}_transform&calculate.vtu'
data = pv.XMLUnstructuredGridReader(registrationName='data.vtu',
FileName=[str(datafilepath)])
data.CellArrayStatus = ['UAvg']
data.TimeArray = 'None'
pointdata = pv.CellDatatoPointData(registrationName='pointdata', Input=data)
logger.debug(f'Loading {datafilepath.name}')
pv.UpdatePipeline(time=0.0, proxy=pointdata)
# Create ellipse for streamtube seeding
rotor_untilted = pv.Ellipse(registrationName='rotor_untilted')
rotor_untilted.Normal = [1,0,0]
rotor_untilted.MajorRadiusVector = [0, const.TURBINE_RADIUS, 0]
rotor_untilted.Resolution = 1000
rotor_tilted = pv.Transform(registrationName='rotor_tilted',
Input=rotor_untilted)
rotor_tilted.Transform = 'RotateAroundOriginTransform'
# Generate streamtubes for upstream and downstream turbines
for turbine in ['upstream','downstream']:
outputfile = directory/'streamtube'/f'{casename}_streamtube_{turbine}Turbine_forwardBackward.vtp'
rotor_center = 0 if turbine == 'upstream' else const.TURBINE_SPACING_m
rotor_untilted.Center = [rotor_center,0,0]
rotor_tilted.Transform.Originofrotation = [rotor_center,0,0]
if casename in ['t007','t009'] and turbine == 'upstream':
tilt_angle = -30
else:
tilt_angle = 5
rotor_tilted.Transform.Rotate = [0,tilt_angle,0]
pv.UpdatePipeline(time=0.0, proxy=rotor_tilted)
streamtubes = pv.StreamTracerWithCustomSource(registrationName='streamtubes',
Input=pointdata,
SeedSource=rotor_tilted)
streamtubes.ComputeVorticity = 0
logger.debug(f'Generating streamtubes for {turbine} turbine')
pv.UpdatePipeline(time=0.0, proxy=streamtubes)
logger.info(f'Saving {outputfile.name}')
pv.SaveData(str(outputfile),proxy=streamtubes,
ChooseArraysToWrite=1,PointDataArrays=[],CellDataArrays=[],
CompressorType='ZLib')
pv.Delete(streamtubes)
del streamtubes
pv.Delete(data)
pv.Delete(rotor_tilted)
pv.Delete(rotor_untilted)
pv.Delete(pointdata)
pv.Delete(data)
del rotor_tilted, rotor_untilted, pointdata, data
################################################################################
if __name__ == '__main__':
utils.configure_root_logger(level=LEVEL)
logger.debug(f'Python version: {sys.version}')
logger.debug(f'Python executable location: {sys.executable}')
description = """Use paraview to generate turbine streamtubes"""
parser = argparse.ArgumentParser(description=description)
parser.add_argument('cases',
help='List of turbine cases',
nargs='+')
args = parser.parse_args()
logger.debug(f'Parsed Command Line Arguments: {args}')
for casename in args.cases:
turbineStreamTube(casename)