From bf250dc62d51c87176dbfd5ed37c10eef5f19c36 Mon Sep 17 00:00:00 2001 From: psauvan Date: Fri, 2 Aug 2024 17:14:28 +0200 Subject: [PATCH] fix bug with object surface --- .../GEOUNED/conversion/cell_definition.py | 14 ++- src/geouned/GEOUNED/utils/boolean_function.py | 2 +- testing/test.py | 92 +++++++++++-------- 3 files changed, 63 insertions(+), 45 deletions(-) diff --git a/src/geouned/GEOUNED/conversion/cell_definition.py b/src/geouned/GEOUNED/conversion/cell_definition.py index 44fcee9e..0a46da3d 100644 --- a/src/geouned/GEOUNED/conversion/cell_definition.py +++ b/src/geouned/GEOUNED/conversion/cell_definition.py @@ -746,11 +746,15 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances, numeric_forma orSeq.append(*extra) surf_piece.append(orSeq) - surf_piece_bool = BoolSequence(operator="AND") - for p in surf_piece: - surf_piece_bool.append(p.get_BoolSequence()) - surf_piece_bool.join_operators() - surf_piece_bool.simplify() + if surf_piece: + surf_piece_bool = BoolSequence(operator="AND") + for p in surf_piece: + surf_piece_bool.append(p.get_BoolSequence()) + surf_piece_bool.join_operators() + surf_piece_bool.simplify() + else: + del_list.append(isol) + continue # possible expresion for e # i1 diff --git a/src/geouned/GEOUNED/utils/boolean_function.py b/src/geouned/GEOUNED/utils/boolean_function.py index f7b8554e..6dae22c3 100644 --- a/src/geouned/GEOUNED/utils/boolean_function.py +++ b/src/geouned/GEOUNED/utils/boolean_function.py @@ -132,7 +132,7 @@ def get_BoolSequence(self, aux=False): if self.s2 is None: return self - seq = BoolSequence(self.op) + seq = BoolSequence(operator=self.op) seq.append(bsurface(self.s1, aux=aux)) if type(self.s2) is int: diff --git a/testing/test.py b/testing/test.py index 672bb63d..e58a34f7 100644 --- a/testing/test.py +++ b/testing/test.py @@ -4,12 +4,43 @@ from pathlib import Path sys.path.append(str(Path(__file__).parents[1] / "src")) +#sys.path.append("/opt/geouned/v1.2.0/src/") sys.path.append("/usr/lib64/freecad/lib64/") +import geouned from geouned import CadToCsg - -def setInput(inName, inpDir, outDir): +def setInputs(): + test_settings = geouned.Settings( + voidGen=True, + debug=False , + compSolids=False, + simplify="full", + minVoidSize=100.0, + ) + + test_options = geouned.Options( + forceCylinder=False, + newSplitPlane=True, + nPlaneReverse=0, + splitTolerance=0, + ) + + test_export = { + 'title' : 'Input Test', + 'outFormat' : ('mcnp',), + 'volSDEF' : True, + 'volCARD' : True, + 'dummyMat' : True, + 'cellSummaryFile' : False, + 'cellCommentFile' : False + } + + return test_settings, test_options, test_export + + + +def getNames(inName, inpDir, outDir): if inName.endswith(".step"): filename = inName[0:-5] @@ -23,37 +54,9 @@ def setInput(inName, inpDir, outDir): if outDir == "": outDir = "." - inName = f"{inpDir}/{inName}" - outName = f"{outDir}/{filename}" - - template = """[Files] -title = Input Test -stepFile = {} -geometryName = {} - -[Parameters] -compSolids = False -volCARD = False -volSDEF = True -voidGen = True -dummyMat = True -minVoidSize = 100 -cellSummaryFile = False -cellCommentFile = False -debug = False -simplify = full - -[Options] -forceCylinder = False -splitTolerance = 0 -newSplitPlane = True -nPlaneReverse = 0 -""".format( - inName, outName - ) - - with open(file="config.ini", mode="w", encoding="utf-8") as outfile: - outfile.write(template) + return f'{inpDir}/{inName}', f'{outDir}/{filename}' + + def getInputList(folder, ext=None): @@ -151,12 +154,23 @@ def printResults(f, res, lost): print(line) -def mkGEOInp(inpDir, outDir): - for f in getInputList(inpDir, ("stp", "step")): - setInput(f, inpDir, outDir) - GEO = CadToCsg() - GEO.set_configuration(inifile) - GEO.Start() +def mkGEOInp(inpDir, outDir, file=None): + sets, opts, exp = setInputs() + if file is None: + files = getInputList(inpDir, ("stp", "step")) + else: + files = (file,) + + for f in files: + inFile, outFile = getNames(f,inpDir,outDir) + exp['geometryName'] = outFile + + print('translate: ',inFile) + print('translate: ',outFile) + GEO = CadToCsg(settings = sets, options = opts) + GEO.load_step_file(inFile) + GEO.start() + GEO.export_csg(**exp) del GEO