Skip to content

Commit

Permalink
finished wind tunnel + re-structured folders
Browse files Browse the repository at this point in the history
1. Moved all grasshopper libraries under gh folder.
2. Finished wind tunnel component. Still need to make sure all 0 folder
files are written correctly. One step from closing #24.
  • Loading branch information
mostaphaRoudsari committed Jul 4, 2016
1 parent f8535df commit 9a55eee
Show file tree
Hide file tree
Showing 16 changed files with 761 additions and 447 deletions.
4 changes: 2 additions & 2 deletions butterfly/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__all__ = ["boundarycondition", "core", "fields", "foamfile", "gh", "version"]
__all__ = ["boundarycondition", "core", "fields", "foamfile", "version"]

import boundarycondition, core, fields, foamfile, gh, version
import boundarycondition, core, fields, foamfile, version
6 changes: 3 additions & 3 deletions butterfly/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def __init__(self, values=None):
values=values)

@classmethod
def fromWindTunnel(cls, BFWindTunnel):
"""Init class from BFTunnel."""
return cls(values=BFWindTunnel.ABLConditionsDict)
def fromWindTunnel(cls, windTunnel):
"""Init class from wind tunnel."""
return cls(values=windTunnel.ABLConditionsDict)

@property
def flowDir(self):
Expand Down
49 changes: 29 additions & 20 deletions butterfly/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Butterfly core library."""
import os
from distutils.dir_util import copy_tree
from gh import loadOFMeshToRhino, loadOFPointsToRhino, loadOFVectorsToRhino
from version import Version
from helper import mkdir, wfile, runbatchfile
# constant folder objects
Expand Down Expand Up @@ -31,8 +30,9 @@ def __init__(self):
Exception.__init__(self, self._msg)


class Case(object):
class OpemFOAMCase(object):
"""Butterfly case."""

def __init__(self, projectName, BFSurfaces, blockMeshDict,
globalRefinementLevel=None, locationInMesh=None,
isSnappyHexMesh=False):
Expand Down Expand Up @@ -74,42 +74,43 @@ def __init__(self, projectName, BFSurfaces, blockMeshDict,
self._isInit = False
self._isSnappyHexMeshFoldersRenamed = False

@classmethod
def fromWindTunnel(cls, windTunnel):
"""Create case from wind tunnel."""
_blockMeshDict = windTunnel.blockMeshDict
_locationInMesh = _blockMeshDict.center

_case = cls(windTunnel.name, windTunnel.testGeomtries, _blockMeshDict,
globalRefinementLevel=windTunnel.globalRefLevel,
locationInMesh=_locationInMesh,
isSnappyHexMesh=True)

# edit files in 0 folder
_case.k.updateValues({'#include': '"initialConditions"',
'internalField': 'uniform $turbulentKE'})
return _case

@classmethod
def fromBlocks(cls, BFSurfaces, blocks, scale):
"""Create case from BFSurfaces and blocks.
This case will only be meshed using blockMesh
"""
raise NotImplementedError("Not implemented yet!")
raise NotImplementedError("Let us know if you in real need for this method!")
_blockMeshDict = BlockMeshDict(scale, BFSurfaces, blocks)
return cls(BFSurfaces, _blockMeshDict, isSnappyHexMesh=False)

def loadMesh(self):
"""Return OpenFOAM mesh as a Rhino mesh."""
return loadOFMeshToRhino(os.path.join(self.constantDir, "polyMesh"))
raise NotImplementedError()

def loadPoints(self):
"""Return OpenFOAM mesh as a Rhino mesh."""
return loadOFPointsToRhino(os.path.join(self.constantDir, "polyMesh"))
raise NotImplementedError()

def loadVelocity(self, timestep=None):
"""Return OpenFOAM mesh as a Rhino mesh."""
# find results folders
_folders = self.__getResultsSubfolders()

# if there is no timestep pick the last one
_folder = _folders[-1]

if timestep:
try:
# pick the one based on timestep
_folder = _folders[timestep + 1]
except IndexError:
pass

return loadOFVectorsToRhino(os.path.join(self.projectDir, str(_folder)),
variable='U')
raise NotImplementedError()

def createCaseFolders(self, workingDir=None):
"""Create project folders and subfolders.
Expand Down Expand Up @@ -346,6 +347,14 @@ def removeSnappyHexMeshFolders(self):

self._isSnappyHexMeshFoldersRenamed = False

def removeResultFolders(self):
pass

def purge(self, removePolyMeshFolder=True, removeSnappyHexMeshFolders=True,
removeResultFolders=False):
"""Purge case folder."""
pass

def ToString(self):
return self.__repr__()

Expand Down
2 changes: 1 addition & 1 deletion butterfly/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def valueDict(self):
"""Get fields as a dictionary."""
_d = OrderedDict()

if self.fromValues:
if not self.fromValues:
_d['#include'] = '"{}"'.format(self.ABLConditions.__class__.__name__)
if self.value:
_d['value'] = str(self.value)
Expand Down
6 changes: 3 additions & 3 deletions butterfly/foamfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ def body(self):
if value:
_values[key] = value

# convert python dictionary to c++ dictionary
# make python dictionary look like c++ dictionary!!
of = json.dumps(_values, indent=4, separators=(";", "\t\t")) \
.replace('"\n', ";\n").replace('"', '').replace('};', '}') \
.replace('\t\t{', '{')
.replace('\\"', "*").replace('"\n', ";\n").replace('"', '') \
.replace('};', '}').replace('\t\t{', '{').replace('*', '"')

# remove first and last {} and prettify[!] the file
l = (line[4:] if not line.endswith('{') else self._splitLine(line)
Expand Down
Loading

0 comments on commit 9a55eee

Please sign in to comment.