Skip to content

Commit

Permalink
Adding formatter to CI to keep code in PEP8 (#104)
Browse files Browse the repository at this point in the history
* added format checker

* run black . locally
  • Loading branch information
shimwell authored Apr 30, 2024
1 parent 8e2fd7f commit bb0365d
Show file tree
Hide file tree
Showing 12 changed files with 195 additions and 151 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
24 changes: 11 additions & 13 deletions scripts/geounedClassCall.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@
# only if modules are not in the PYTHONPATH or directly installed in the python distribution used
import sys

geo_path="C:\\Users\\Patrick\\Documents\\GitHub\\GEOUNED\\src"
geo_path = "C:\\Users\\Patrick\\Documents\\GitHub\\GEOUNED\\src"
sys.path.append(geo_path)
sys.path.append('C:\\Program Files\\FreeCAD 0.19\\bin...')
sys.path.append("C:\\Program Files\\FreeCAD 0.19\\bin...")

from geouned import CadToCsg

stepFileName = 'placa.stp'
stepFileName = "placa.stp"

GEO = CadToCsg('Conversion Example')
GEO = CadToCsg("Conversion Example")

GEO.set('stepFile', stepFileName)
GEO.set('geometryName','Placa')
GEO.set('outFormat', ('mcnp', 'openMC_XML'))
GEO.set('planeDistance', 0.05)
GEO.set('quadricPY', True)
GEO.set('P_abc', '12f')
GEO.set('P_d', '12f')
GEO.set("stepFile", stepFileName)
GEO.set("geometryName", "Placa")
GEO.set("outFormat", ("mcnp", "openMC_XML"))
GEO.set("planeDistance", 0.05)
GEO.set("quadricPY", True)
GEO.set("P_abc", "12f")
GEO.set("P_d", "12f")
GEO.Start()


1 change: 1 addition & 0 deletions src/geouned/GEOReverse/Modules/MCNPinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def __getTransList__(self):
trl[c.name] = getTransMatrix(trValues, c.unit)
return trl


# fmt: off
def getTransMatrix(trsf, unit="", scale=10.0):

Expand Down
8 changes: 6 additions & 2 deletions src/geouned/GEOUNED/Conversion/CellDefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,9 @@ def cellDef(meta_obj, surfaces, universe_box):

elif surf_type == "Cylinder":
cyl = GeounedSurface(
("Cylinder", surf_params), universe_box, Face="Build"
("Cylinder", surf_params),
universe_box,
Face="Build",
)
id2, exist = surfaces.addCylinder(cyl)

Expand Down Expand Up @@ -1185,7 +1187,9 @@ def addConePlane(definition, cones_list, surfaces, universe_box):
continue

plane = GeounedSurface(
("Plane", (cone.Surf.Apex, cone.Surf.Axis, 1, 1)), universe_box, Face="Build"
("Plane", (cone.Surf.Apex, cone.Surf.Axis, 1, 1)),
universe_box,
Face="Build",
)
pid, exist = surfaces.addPlane(plane)

Expand Down
9 changes: 9 additions & 0 deletions src/geouned/GEOUNED/Utils/Geometry_GU.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
from .BasicFunctions_part1 import isSameValue
from .BasicFunctions_part2 import isSameTorus


# SURFACES
class SurfacesGu(object):
"""GEOUNED surface class"""

def __init__(self, face):
self.face = face
self.Surface = self.face.Surface
Expand All @@ -28,6 +30,7 @@ def __str__(self):

class PlaneGu(SurfacesGu):
"""GEOUNED Plane Class"""

def __init__(self, face, plane3Pts=False):
SurfacesGu.__init__(self, face)
self.Axis = face.Surface.Axis
Expand All @@ -47,6 +50,7 @@ def __init__(self, face, plane3Pts=False):

class CylinderGu(SurfacesGu):
"""GEOUNED Cylinder Class"""

def __init__(self, face):
SurfacesGu.__init__(self, face)
self.Axis = face.Surface.Axis
Expand All @@ -57,6 +61,7 @@ def __init__(self, face):

class ConeGu(SurfacesGu):
"""GEOUNED Cone Class"""

def __init__(self, face):
SurfacesGu.__init__(self, face)
self.Axis = face.Surface.Axis
Expand All @@ -69,6 +74,7 @@ def __init__(self, face):

class SphereGu(SurfacesGu):
"""GEOUNED Sphere Class"""

def __init__(self, face):
SurfacesGu.__init__(self, face)
self.type = self.type[0:6]
Expand All @@ -78,6 +84,7 @@ def __init__(self, face):

class TorusGu(SurfacesGu):
"""GEOUNED Torus Class"""

def __init__(self, face):
SurfacesGu.__init__(self, face)
self.Center = face.Surface.Center
Expand All @@ -88,6 +95,7 @@ def __init__(self, face):

class SolidGu:
"""GEOUNED Solid Class"""

def __init__(self, solid, plane3Pts=False):
self.solid = solid
faces = DefineListFace_GU(solid.Faces, plane3Pts)
Expand Down Expand Up @@ -221,6 +229,7 @@ def __mergePeriodicUV__(self, parameter, faceList):
# FACES
class FaceGu(object):
"""GEOUNED Face Class"""

def __init__(self, face, Plane3Pts=False):
# GEOUNED based atributes
self.__face__ = face
Expand Down
22 changes: 12 additions & 10 deletions src/geouned/GEOUNED/Utils/Options/Classes.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
class Options:
from .optionsDefault import defaultValues, typeDict

@classmethod
def setDefaultAttribute(cls):
for key,value in cls.defaultValues.items():
setattr(cls, key, value)
for key, value in cls.defaultValues.items():
setattr(cls, key, value)

@classmethod
def setAttribute(cls,key,value):
@classmethod
def setAttribute(cls, key, value):
if key in cls.defaultValues.keys():
setattr(cls, key, value)


class Tolerances:
from .tolerancesDefault import defaultValues, typeDict, KwrdEquiv

@classmethod
def setDefaultAttribute(cls):
for key,value in cls.defaultValues.items():
for key, value in cls.defaultValues.items():
setattr(cls, key, value)

@classmethod
def setAttribute(cls,key,value):
def setAttribute(cls, key, value):
if key in cls.defaultValues.keys():
setattr(cls, key, value)

Expand All @@ -29,10 +31,10 @@ class McnpNumericFormat:

@classmethod
def setDefaultAttribute(cls):
for key,value in cls.defaultValues.items():
setattr(cls, key, value)
for key, value in cls.defaultValues.items():
setattr(cls, key, value)

@classmethod
def setAttribute(cls,key,value):
def setAttribute(cls, key, value):
if key in cls.defaultValues.keys():
setattr(cls, key, value)
26 changes: 13 additions & 13 deletions src/geouned/GEOUNED/Utils/Options/mcnpNumericDefault.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
defaultValues = {
"P_abc": "14.7e", # Plane general a,b,c params
"P_d": "14.7e", # Plane general d params
"P_xyz": "14.7e", # PX/PY/PZ params
"S_r": "14.7e", # SO/SX/SY/SZ/S radius
"S_xyz": "14.7e", # SO/SX/SY/SZ/S center
"C_r": "12f", # Cylinder radius
"C_xyz": "12f", # Cylinder center
"K_xyz": "13.6e", # Cone apex
"K_tan2": "12f", # Cone tan^2 value
"T_r": "14.7e", # Torus radii
"T_xyz": "14.7e", # Torus center
"P_abc": "14.7e", # Plane general a,b,c params
"P_d": "14.7e", # Plane general d params
"P_xyz": "14.7e", # PX/PY/PZ params
"S_r": "14.7e", # SO/SX/SY/SZ/S radius
"S_xyz": "14.7e", # SO/SX/SY/SZ/S center
"C_r": "12f", # Cylinder radius
"C_xyz": "12f", # Cylinder center
"K_xyz": "13.6e", # Cone apex
"K_tan2": "12f", # Cone tan^2 value
"T_r": "14.7e", # Torus radii
"T_xyz": "14.7e", # Torus center
"GQ_1to6": "18.15f", # GQ 1 to 6 coefficients (order 2 x2,y2,z2,xy,...)
"GQ_7to9": "18.15f", # GQ 7 to 9 coefficients (order 1 x,y,z)
"GQ_10": "18.15f", # GQ 10 coefficient (order 0)
}
"GQ_10": "18.15f", # GQ 10 coefficient (order 0)
}
50 changes: 25 additions & 25 deletions src/geouned/GEOUNED/Utils/Options/optionsDefault.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# default options values
defaultValues = {
"forceCylinder" : False, # Force using cylinders instead cones for auxillary surfaces of torus surface definition
"newSplitPlane" : True, # Use new module for planes splitting in decomposition module
"delLastNumber" : False, # Deleting the last word in the comment if it is a number
"verbose" : False, # Display information during conversion process
"enlargeBox" : 2, # Enlarge box Boundary when evaluating Ctable (dimension in mm)
"nPlaneReverse" : 0, # numbers of plane thresold whether cut of parallel planes are made fisrt with lowest or highest number
"splitTolerance" : 0, # First try for fuzzy tolerance used in BOPTOOL Split function. If BOPTSplit crash try lower value for tolerance
"scaleUp" : True, # Scale up Fuzzy tolerance once get below 1e-12
"quadricPY" : False, # use quadric form of cones and cylinder not aligned with X,Y,Z axis when write openMC script file
"Facets" : False, # use alternative conversion module when geometry is defined by cells compound by only triangular plane faces
"prnt3PPlane" : False, # print 3 point plane definition in MCNP output as 3 points coordinates
"forceNoOverlap" : False, # force no overlaping cell definition. Adjacent cell definition are rested from current cell definition
"forceCylinder": False, # Force using cylinders instead cones for auxillary surfaces of torus surface definition
"newSplitPlane": True, # Use new module for planes splitting in decomposition module
"delLastNumber": False, # Deleting the last word in the comment if it is a number
"verbose": False, # Display information during conversion process
"enlargeBox": 2, # Enlarge box Boundary when evaluating Ctable (dimension in mm)
"nPlaneReverse": 0, # numbers of plane thresold whether cut of parallel planes are made fisrt with lowest or highest number
"splitTolerance": 0, # First try for fuzzy tolerance used in BOPTOOL Split function. If BOPTSplit crash try lower value for tolerance
"scaleUp": True, # Scale up Fuzzy tolerance once get below 1e-12
"quadricPY": False, # use quadric form of cones and cylinder not aligned with X,Y,Z axis when write openMC script file
"Facets": False, # use alternative conversion module when geometry is defined by cells compound by only triangular plane faces
"prnt3PPlane": False, # print 3 point plane definition in MCNP output as 3 points coordinates
"forceNoOverlap": False, # force no overlaping cell definition. Adjacent cell definition are rested from current cell definition
}

typeDict = {
"forceCylinder" : bool, # Force using cylinders instead cones for auxillary surfaces of torus surface definition
"newSplitPlane" : bool, # Use new module for planes splitting in decomposition module
"delLastNumber" : bool, # Deleting the last word in the comment if it is a number
"verbose" : bool, # Display information during conversion process
"enlargeBox" : float, # Enlarge box Boundary when evaluating Ctable (dimension in mm)
"nPlaneReverse" : int, # numbers of plane thresold whether cut of parallel planes are made fisrt with lowest or highest number
"splitTolerance" : int, # First try for fuzzy tolerance used in BOPTOOL Split function. If BOPTSplit crash try lower value for tolerance
"scaleUp" : bool, # Scale up Fuzzy tolerance once get below 1e-12
"quadricPY" : bool, # use quadric form of cones and cylinder not aligned with X,Y,Z axis when write openMC script file
"Facets" : bool, # use alternative conversion module when geometry is defined by cells compound by only triangular plane faces
"prnt3PPlane" : bool, # print 3 point plane definition in MCNP output as 3 points coordinates
"forceNoOverlap" : bool, # force no overlaping cell definition. Adjacent cell definition are rested from current cell definition
}
"forceCylinder": bool, # Force using cylinders instead cones for auxillary surfaces of torus surface definition
"newSplitPlane": bool, # Use new module for planes splitting in decomposition module
"delLastNumber": bool, # Deleting the last word in the comment if it is a number
"verbose": bool, # Display information during conversion process
"enlargeBox": float, # Enlarge box Boundary when evaluating Ctable (dimension in mm)
"nPlaneReverse": int, # numbers of plane thresold whether cut of parallel planes are made fisrt with lowest or highest number
"splitTolerance": int, # First try for fuzzy tolerance used in BOPTOOL Split function. If BOPTSplit crash try lower value for tolerance
"scaleUp": bool, # Scale up Fuzzy tolerance once get below 1e-12
"quadricPY": bool, # use quadric form of cones and cylinder not aligned with X,Y,Z axis when write openMC script file
"Facets": bool, # use alternative conversion module when geometry is defined by cells compound by only triangular plane faces
"prnt3PPlane": bool, # print 3 point plane definition in MCNP output as 3 points coordinates
"forceNoOverlap": bool, # force no overlaping cell definition. Adjacent cell definition are rested from current cell definition
}
58 changes: 29 additions & 29 deletions src/geouned/GEOUNED/Utils/Options/tolerancesDefault.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
defaultValues = {
"relativeTol": False,
"relativePrecision": 1.0e-6, # relative precision
"value": 1.0e-6, # Tolerance in single value comparison
"distance": 1.0e-4, # General Distance Tolerance
"angle": 1.0e-4, # General Angle Tolerance
"pln_distance": 1.0e-4, # distance between planes equal planes if distance between parallel planes < 1e-4 cm
"pln_angle": 1.0e-4, # angle between axis. 1e-4 : planes separate each other 0.1mm each 1m
"cyl_distance": 1.0e-4, # distance between radius/center
"cyl_angle": 1.0e-4, # angle between axis
"sph_distance": 1.0e-4, # distance between radius/center
"kne_distance": 1.0e-4, # distance between apex
"kne_angle": 1.0e-4, # angle between semiangles/axis
"tor_distance": 1.0e-4, # distance between Major/Minor radii/center
"tor_angle": 1.0e-4, # angle between axis
"min_area": 1.0e-2, # minimun face area to consider in cell definition
}
"value": 1.0e-6, # Tolerance in single value comparison
"distance": 1.0e-4, # General Distance Tolerance
"angle": 1.0e-4, # General Angle Tolerance
"pln_distance": 1.0e-4, # distance between planes equal planes if distance between parallel planes < 1e-4 cm
"pln_angle": 1.0e-4, # angle between axis. 1e-4 : planes separate each other 0.1mm each 1m
"cyl_distance": 1.0e-4, # distance between radius/center
"cyl_angle": 1.0e-4, # angle between axis
"sph_distance": 1.0e-4, # distance between radius/center
"kne_distance": 1.0e-4, # distance between apex
"kne_angle": 1.0e-4, # angle between semiangles/axis
"tor_distance": 1.0e-4, # distance between Major/Minor radii/center
"tor_angle": 1.0e-4, # angle between axis
"min_area": 1.0e-2, # minimun face area to consider in cell definition
}

typeDict = {
"relativeTol": bool,
"relativePrecision": float, # relative precision
"value": float, # Tolerance in single value comparison
"distance": float, # General Distance Tolerance
"angle": float, # General Angle Tolerance
"pln_distance": float, # distance between planes equal planes if distance between parallel planes < 1e-4 cm
"pln_angle": float, # angle between axis. 1e-4 : planes separate each other 0.1mm each 1m
"cyl_distance": float, # distance between radius/center
"cyl_angle": float, # angle between axis
"sph_distance": float, # distance between radius/center
"kne_distance": float, # distance between apex
"kne_angle": float, # angle between semiangles/axis
"tor_distance": float, # distance between Major/Minor radii/center
"tor_angle": float, # angle between axis
"min_area": float, # minimun face area to consider in cell definition
}
"value": float, # Tolerance in single value comparison
"distance": float, # General Distance Tolerance
"angle": float, # General Angle Tolerance
"pln_distance": float, # distance between planes equal planes if distance between parallel planes < 1e-4 cm
"pln_angle": float, # angle between axis. 1e-4 : planes separate each other 0.1mm each 1m
"cyl_distance": float, # distance between radius/center
"cyl_angle": float, # angle between axis
"sph_distance": float, # distance between radius/center
"kne_distance": float, # distance between apex
"kne_angle": float, # angle between semiangles/axis
"tor_distance": float, # distance between Major/Minor radii/center
"tor_angle": float, # angle between axis
"min_area": float, # minimun face area to consider in cell definition
}

KwrdEquiv = {
"relativeTolerance": "relativeTol",
Expand All @@ -50,4 +50,4 @@
"torusDistance": "tor_distance",
"torusAngle": "tor_angle",
"minArea": "min_area",
}
}
Loading

0 comments on commit bb0365d

Please sign in to comment.