Skip to content

Commit

Permalink
FEM: code formating, max line length < 100, fem in out modules
Browse files Browse the repository at this point in the history
  • Loading branch information
berndhahnebach committed May 27, 2019
1 parent f2bbb89 commit 5d69805
Show file tree
Hide file tree
Showing 11 changed files with 545 additions and 183 deletions.
77 changes: 63 additions & 14 deletions src/Mod/Fem/feminout/convert2TetGen.py
Expand Up @@ -46,12 +46,19 @@ def exportMeshToTetGenPoly(meshToExport, filePath, beVerbose=1):
f = open(filePath, 'w')
f.write("# This file was generated from FreeCAD geometry\n")
f.write("# Part 1 - node list\n")
'''
f.write("%(TotalNumOfPoints)i %(NumOfDimensions)i %(NumOfProperties)i %(BoundaryMarkerExists)i\n" % {
'TotalNumOfPoints': len(allVertices),
'NumOfDimensions': 3,
'NumOfProperties': 0,
'BoundaryMarkerExists': 0
})
'''
f.write(
"TotalNumOfPoints: {}, NumOfDimensions; {}, "
"NumOfProperties: {}, BoundaryMarkerExists: {}\n"
.format(len(allVertices), 3, 0, 0)
)
for PointIndex in range(len(allVertices)):
f.write("%(PointIndex)5i %(x) e %(y) e %(z) e\n" % {
'PointIndex': PointIndex,
Expand Down Expand Up @@ -93,10 +100,13 @@ def exportMeshToTetGenPoly(meshToExport, filePath, beVerbose=1):
EdgeKeys = EdgeFacets.keys()
# disconnectedEdges = len(EdgeKeys)
if beVerbose == 1:
FreeCAD.Console.PrintMessage('\nBoundaryMarker:' + repr(BoundaryMarker) + ' ' + repr(len(EdgeFacets)))
FreeCAD.Console.PrintMessage(
'\nBoundaryMarker:' + repr(BoundaryMarker) + ' ' + repr(len(EdgeFacets))
)
searchForPair = 1

# Main loop: first search for all complementary facets, then fill one branch and repeat while edges are available
# Main loop: first search for all complementary facets
# then fill one branch and repeat while edges are available
while len(EdgeFacets) > 0:
removeEdge = 0
for EdgeIndex in EdgeKeys:
Expand Down Expand Up @@ -142,7 +152,9 @@ def exportMeshToTetGenPoly(meshToExport, filePath, beVerbose=1):
searchForPair = 0
# End of main loop
if beVerbose == 1:
FreeCAD.Console.PrintMessage('\nNew BoundaryMarker:' + repr(BoundaryMarker) + ' ' + repr(len(EdgeFacets)))
FreeCAD.Console.PrintMessage(
'\nNew BoundaryMarker:' + repr(BoundaryMarker) + ' ' + repr(len(EdgeFacets))
)

## Part 2 - write all facets to *.poly file
f.write("# Part 2 - facet list\n")
Expand Down Expand Up @@ -194,7 +206,8 @@ def createMesh():
# Init objects
if beVerbose == 1:
FreeCAD.Console.PrintMessage("\nInit Objects...")
# App.closeDocument(App.ActiveDocument.Label) #closeDocument after restart of macro. Needs any ActiveDocument.
# closeDocument after restart of macro. Needs any ActiveDocument.
# App.closeDocument(App.ActiveDocument.Label)
AppPyDoc = App.newDocument(PyDocumentName)
NSideBox = AppPyDoc.addObject("Part::Box", NSideBoxName)
PSideBox = AppPyDoc.addObject("Part::Box", PSideBoxName)
Expand All @@ -204,17 +217,33 @@ def createMesh():
AdsorbtionBox = AppPyDoc.addObject("Part::Box", AdsorbtionBoxName)
pnMesh = AppPyDoc.addObject("Mesh::Feature", pnMeshName)

BoxList = [NSideBox, DepletionBox, PSideBox, OxideBox, AdsorbtionBox, SurfDepletionBox]
BoxList = [
NSideBox,
DepletionBox,
PSideBox,
OxideBox,
AdsorbtionBox,
SurfDepletionBox
]
NSideBoxMesh = Mesh.Mesh()
PSideBoxMesh = Mesh.Mesh()
DepletionBoxMesh = Mesh.Mesh()
SurfDepletionBoxMesh = Mesh.Mesh()
OxideBoxMesh = Mesh.Mesh()
AdsorbtionBoxMesh = Mesh.Mesh()
BoxMeshList = [NSideBoxMesh, DepletionBoxMesh, PSideBoxMesh, OxideBoxMesh, AdsorbtionBoxMesh, SurfDepletionBoxMesh]
BoxMeshList = [
NSideBoxMesh,
DepletionBoxMesh,
PSideBoxMesh,
OxideBoxMesh,
AdsorbtionBoxMesh,
SurfDepletionBoxMesh
]
if beVerbose == 1:
if len(BoxList) != len(BoxMeshList):
FreeCAD.Console.PrintMessage("\n ERROR! Input len() of BoxList and BoxMeshList is not the same! ")
FreeCAD.Console.PrintMessage(
"\n ERROR! Input len() of BoxList and BoxMeshList is not the same! "
)

## Set sizes in nanometers
if beVerbose == 1:
Expand Down Expand Up @@ -253,12 +282,30 @@ def createMesh():

# Object placement
Rot = App.Rotation(0, 0, 0, 1)
NSideBox.Placement = App.Placement(App.Vector(0, 0, -BulkHeight), Rot)
PSideBox.Placement = App.Placement(App.Vector(DepletionSize * 2 + BulkLength, 0, -BulkHeight), Rot)
DepletionBox.Placement = App.Placement(App.Vector(BulkLength, 0, -BulkHeight), Rot)
SurfDepletionBox.Placement = App.Placement(App.Vector(0, 0, 0), Rot)
OxideBox.Placement = App.Placement(App.Vector(0, 0, DepletionSize), Rot)
AdsorbtionBox.Placement = App.Placement(App.Vector(0, 0, DepletionSize + OxideThickness), Rot)
NSideBox.Placement = App.Placement(
App.Vector(0, 0, -BulkHeight),
Rot
)
PSideBox.Placement = App.Placement(
App.Vector(DepletionSize * 2 + BulkLength, 0, -BulkHeight),
Rot
)
DepletionBox.Placement = App.Placement(
App.Vector(BulkLength, 0, -BulkHeight),
Rot
)
SurfDepletionBox.Placement = App.Placement(
App.Vector(0, 0, 0),
Rot
)
OxideBox.Placement = App.Placement(
App.Vector(0, 0, DepletionSize),
Rot
)
AdsorbtionBox.Placement = App.Placement(
App.Vector(0, 0, DepletionSize + OxideThickness),
Rot
)

## Unite
if beVerbose == 1:
Expand All @@ -271,7 +318,9 @@ def createMesh():

# for index in range(len(BoxList)):
for index in range(len(BoxList) - 1): # Manual hack
BoxMeshList[index].addFacets(BoxList[index].Shape.tessellate(tessellationTollerance))
BoxMeshList[index].addFacets(
BoxList[index].Shape.tessellate(tessellationTollerance)
)
nmesh.addMesh(BoxMeshList[index])

nmesh.removeDuplicatedPoints()
Expand Down
18 changes: 14 additions & 4 deletions src/Mod/Fem/feminout/importCcxDatResults.py
Expand Up @@ -44,13 +44,18 @@
pyopen = open


def open(filename):
def open(
filename
):
"called when freecad opens a file"
docname = os.path.splitext(os.path.basename(filename))[0]
insert(filename, docname)


def insert(filename, docname):
def insert(
filename,
docname
):
"called when freecad wants to import a file"
try:
doc = FreeCAD.getDocument(docname)
Expand All @@ -61,14 +66,19 @@ def insert(filename, docname):


# ********* module specific methods *********
def import_dat(filename, Analysis=None):
def import_dat(
filename,
Analysis=None
):
r = readResult(filename)
# print("Results {}".format(r))
return r


# read a calculix result file and extract the data
def readResult(dat_input):
def readResult(
dat_input
):
FreeCAD.Console.PrintMessage('Read ccx results from dat file: {}\n'.format(dat_input))
dat_file = pyopen(dat_input, "r")
eigenvalue_output_section_found = False
Expand Down

0 comments on commit 5d69805

Please sign in to comment.