-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generalized Tecplot ASCII and Binary Readers/Writers #95
Open
lamkina
wants to merge
26
commits into
mdolab:main
Choose a base branch
from
lamkina:file_io
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,871
−93
Open
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
6c8fc28
Implemented tecplot ascii and binary readers and writers for n-dimens…
lamkina 16191ce
Fixing black
lamkina 3718d06
Adding docs for tecplot module
lamkina b277258
Bumped the minor version
lamkina 0f35428
Fixed exception in external io test to catch all errors
lamkina b03bcac
Adding zone input validation, better use of enums, refactoring, and b…
lamkina 9ebce66
Fixing regex for zone name matching
lamkina 0288bee
Added terminating comma to regex pattern for zone header
lamkina d8fdc99
Fixed regex for zone name matching
lamkina 660609b
Updating tecplot writers in the weight problem
lamkina f88c903
Fixing if checks for types
lamkina 47903db
Updating tecplot writers in the aero solver
lamkina 75f59ea
Fixing strand ID and solution time bugs in ASCII writer
lamkina 80196c6
Fixed random data in ordered zones and added stress testing
lamkina 63169ee
Added block format writer and reader to adhere to line width constraints
lamkina a503e8c
Added line length test for ASCII files
lamkina fc5c1c2
Improved the ascii data reader to use multiple separators and ignore …
lamkina 066a6bd
Added full reader and writer separator support with tests
lamkina 449c9b9
Cleaning up documentation, imports, and api
lamkina c2baf7c
Added tri connectivity property for FE zones with tests
lamkina fc5fbe8
Flake 8 is always watching
lamkina 1e44f71
Added unique indices and nodes to fe zones
lamkina b9b83aa
New connectivity handling for FE zones with unique data and connectiv…
lamkina b30741e
Fixed remap connectivity bug
lamkina 99e04c7
Switched remap connectivity to numpy for sppeeeed
lamkina 7fc9a08
Updgraded the zone name matching to be more robust
lamkina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
__version__ = "1.8.0" | ||
__version__ = "1.9.0" | ||
|
||
from .problems import ( | ||
AeroProblem, | ||
TransiProblem, | ||
StructProblem, | ||
AeroStructProblem, | ||
EngineProblem, | ||
FieldPerformanceProblem, | ||
FluidProperties, | ||
FuelCase, | ||
ICAOAtmosphere, | ||
LGProblem, | ||
MissionProblem, | ||
MissionProfile, | ||
MissionSegment, | ||
StructProblem, | ||
TransiProblem, | ||
WeightProblem, | ||
FuelCase, | ||
FluidProperties, | ||
ICAOAtmosphere, | ||
EngineProblem, | ||
FieldPerformanceProblem, | ||
LGProblem, | ||
) | ||
|
||
from .solvers import BaseSolver, AeroSolver | ||
|
||
from .utils import getPy3SafeString | ||
|
||
from .solvers import AeroSolver, BaseSolver | ||
from .testing import BaseRegTest, getTol | ||
from .utils import getPy3SafeString, tecplotIO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,13 @@ | |
Holds the weightProblem class for weightandbalance solvers. | ||
""" | ||
|
||
import numpy as np | ||
import copy | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
|
||
from ..utils import TecplotFEZone, TecplotOrderedZone, writeTecplot | ||
from ..utils.tecplotIO import ZoneType | ||
|
||
try: | ||
from pygeo import geo_utils | ||
|
@@ -68,9 +73,9 @@ | |
""" | ||
|
||
# Check if components is of type Component or list, otherwise raise Error | ||
if type(components) == list: | ||
if isinstance(components, list): | ||
pass | ||
elif type(components) == object: | ||
elif isinstance(components, object): | ||
components = [components] | ||
else: | ||
raise Error("addComponents() takes in either a list of or a single component") | ||
|
@@ -132,7 +137,7 @@ | |
|
||
""" | ||
|
||
if type(surf) == list: | ||
if isinstance(surf, list): | ||
self.p0 = np.array(surf[0]) | ||
self.v1 = np.array(surf[1]) | ||
self.v2 = np.array(surf[2]) | ||
|
@@ -194,24 +199,28 @@ | |
File name for tecplot file. Should have a .dat extension. | ||
|
||
""" | ||
f = open(fileName, "w") | ||
f.write('TITLE = "weight_problem Surface Mesh"\n') | ||
f.write('VARIABLES = "CoordinateX" "CoordinateY" "CoordinateZ"\n') | ||
f.write("Zone T=%s\n" % ("surf")) | ||
f.write("Nodes = %d, Elements = %d ZONETYPE=FETRIANGLE\n" % (len(self.p0) * 3, len(self.p0))) | ||
f.write("DATAPACKING=POINT\n") | ||
for i in range(len(self.p0)): | ||
points = [] | ||
points.append(self.p0[i]) | ||
points.append(self.p0[i] + self.v1[i]) | ||
points.append(self.p0[i] + self.v2[i]) | ||
for i in range(len(points)): | ||
f.write(f"{points[i][0]:f} {points[i][1]:f} {points[i][2]:f}\n") | ||
# Build the FETriangle data array | ||
dataArrays = np.zeros((len(self.p0) * 3, 3), dtype=float) | ||
dataArrays[::3] = self.p0 | ||
dataArrays[1::3] = self.p0 + self.v1 | ||
dataArrays[2::3] = self.p0 + self.v2 | ||
data = {"CoordinateX": dataArrays[:, 0], "CoordinateY": dataArrays[:, 1], "CoordinateZ": dataArrays[:, 2]} | ||
|
||
# Create the connectivity | ||
conn = np.zeros((len(self.p0), 3), dtype=int) | ||
for i in range(len(self.p0)): | ||
f.write("%d %d %d\n" % (3 * i + 1, 3 * i + 2, 3 * i + 3)) | ||
conn[i, :] = [3 * i + 1, 3 * i + 2, 3 * i + 3] | ||
|
||
f.close() | ||
# Create the single zone | ||
zones = [TecplotFEZone("surf", data, conn, zoneType=ZoneType.FETRIANGLE)] | ||
|
||
writeTecplot( | ||
fileName, | ||
title="weight_problem Surface Mesh", | ||
zones=zones, | ||
datapacking="POINT", | ||
precision="SINGLE", | ||
) | ||
|
||
def writeTecplot(self, fileName): | ||
""" | ||
|
@@ -362,9 +371,9 @@ | |
""" | ||
|
||
# Check if case is a single entry or a list, otherwise raise Error | ||
if type(cases) == list: | ||
if isinstance(cases, list): | ||
pass | ||
elif type(cases) == object: | ||
elif isinstance(cases, object): | ||
cases = [cases] | ||
else: | ||
raise Error("addFuelCases() takes in either a list of or a single fuelcase") | ||
|
@@ -447,7 +456,7 @@ | |
|
||
if includeType is not None: | ||
# Specified a list of component types to include | ||
if type(includeType) == str: | ||
if isinstance(includeType, str): | ||
includeType = [includeType] | ||
weightKeysTmp = set() | ||
for key in weightKeys: | ||
|
@@ -457,21 +466,21 @@ | |
|
||
if include is not None: | ||
# Specified a list of compoents to include | ||
if type(include) == str: | ||
if isinstance(include, str): | ||
include = [include] | ||
include = set(include) | ||
weightKeys.intersection_update(include) | ||
|
||
if exclude is not None: | ||
# Specified a list of components to exclude | ||
if type(exclude) == str: | ||
if isinstance(exclude, str): | ||
exclude = [exclude] | ||
exclude = set(exclude) | ||
weightKeys.difference_update(exclude) | ||
|
||
if excludeType is not None: | ||
# Specified a list of compoent types to exclude | ||
if type(excludeType) == str: | ||
if isinstance(excludeType, str): | ||
excludeType = [excludeType] | ||
weightKeysTmp = copy.copy(weightKeys) | ||
for key in weightKeys: | ||
|
@@ -490,48 +499,42 @@ | |
|
||
filename: str | ||
filename for writing the masses. This string will have the | ||
.dat suffix appended to it. | ||
# .dat suffix appended to it if it does not already have it. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
""" | ||
|
||
fileHandle = filename + ".dat" | ||
f = open(fileHandle, "w") | ||
nMasses = len(self.nameList) | ||
f.write('TITLE = "%s: Mass Data"\n' % self.name) | ||
f.write('VARIABLES = "X", "Y", "Z", "Mass"\n') | ||
locList = ["current", "fwd", "aft"] | ||
|
||
zones = [] | ||
for loc in locList: | ||
f.write('ZONE T="%s", I=%d, J=1, K=1, DATAPACKING=POINT\n' % (loc, nMasses)) | ||
|
||
for key in self.components.keys(): | ||
dataArray = np.zeros((nMasses, 4), dtype=float) | ||
for i, key in enumerate(self.components.keys()): | ||
CG = self.components[key].getCG(loc) | ||
mass = self.components[key].getMass() | ||
x = np.real(CG[0]) | ||
y = np.real(CG[1]) | ||
z = np.real(CG[2]) | ||
m = np.real(mass) | ||
|
||
f.write(f"{x:f} {y:f} {z:f} {m:f}\n") | ||
|
||
# end | ||
f.write("\n") | ||
# end | ||
|
||
# textOffset = 0.5 | ||
# for loc in locList: | ||
# for name in self.nameList: | ||
# x= np.real(self.componentDict[name].CG[loc][0]) | ||
# y= np.real(self.componentDict[name].CG[loc][1]) | ||
# z= np.real(self.componentDict[name].CG[loc][2])+textOffset | ||
# m= np.real(self.componentDict[name].W) | ||
|
||
# f.write('TEXT CS=GRID3D, HU=POINT, X=%f, Y=%f, Z=%f, H=12, T="%s"\n'%(x,y,z,name+' '+loc)) | ||
# # end | ||
|
||
# # end | ||
|
||
f.close() | ||
return | ||
dataArray[i, 0] = CG[0] | ||
dataArray[i, 1] = CG[1] | ||
dataArray[i, 2] = CG[2] | ||
dataArray[i, 3] = mass | ||
|
||
data = { | ||
"CoordinateX": dataArray[:, 0], | ||
"CoordinateY": dataArray[:, 1], | ||
"CoordinateZ": dataArray[:, 2], | ||
"Mass": dataArray[:, 3], | ||
} | ||
|
||
zones.append(TecplotOrderedZone(loc, data)) | ||
|
||
# Create the path with the .dat extension | ||
filePath = Path(filename).with_suffix(".dat") | ||
|
||
writeTecplot( | ||
filePath, | ||
title=f"{self.name}: Mass Data", | ||
zones=zones, | ||
datapacking="POINT", | ||
precision="SINGLE", | ||
) | ||
|
||
def writeProblemData(self, fileName): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking here, but why use this large array? Makes it more readable to just use
x
etc. If there is no need to keep the data together, I would favor readability. This appears in other classes as well.