Skip to content
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

Moving decompose logic out of CadToCsg.start to its own method #189

Closed
153 changes: 79 additions & 74 deletions src/geouned/GEOUNED/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(
# define later when running the code
self.geometry_bounding_box = None
self.meta_list = []
self.cone_info = {}

@property
def stepFile(self):
Expand Down Expand Up @@ -565,80 +566,15 @@ def start(self):

self.Surfaces = UF.SurfacesDict(offset=self.settings.startSurf - 1)

warnSolids = []
warnEnclosures = []
coneInfo = dict()
tempTime0 = datetime.now()
if not self.options.Facets:

# decompose all solids in elementary solids (convex ones)
warningSolidList = self._decompose_solids(meta=True)

# decompose Enclosure solids
if self.settings.voidGen and self.enclosure_list:
warningEnclosureList = self._decompose_solids(meta=False)

logger.info("End of decomposition phase")

# start Building CGS cells phase

for j, m in enumerate(tqdm(self.meta_list, desc="Translating solid cells")):
if m.IsEnclosure:
continue
logger.info(f"Building cell: {j+1}")
cones = Conv.cellDef(
m,
self.Surfaces,
self.geometry_bounding_box,
self.options,
self.tolerances,
self.numeric_format,
)
if cones:
coneInfo[m.__id__] = cones
if j in warningSolidList:
warnSolids.append(m)
if not m.Solids:
logger.info(f"none {j}, {m.__id__}")
logger.info(m.Definition)

if self.options.forceNoOverlap:
Conv.no_overlapping_cell(self.meta_list, self.Surfaces, self.options)

else:
translate(
self.meta_list,
self.Surfaces,
self.geometry_bounding_box,
self.settings,
self.options,
self.tolerances,
)
# decompose Enclosure solids
if self.settings.voidGen and self.enclosure_list:
warningEnclosureList = self._decompose_solids(meta=False)
self._decompose_geometry()

tempstr2 = str(datetime.now() - tempTime)
logger.info(tempstr2)

# building enclosure solids

if self.settings.voidGen and self.enclosure_list:
for j, m in enumerate(self.enclosure_list):
logger.info(f"Building Enclosure Cell: {j + 1}")
cones = Conv.cellDef(
m,
self.Surfaces,
self.geometry_bounding_box,
self.options,
self.tolerances,
self.numeric_format,
)
if cones:
coneInfo[m.__id__] = cones
if j in warningEnclosureList:
warnEnclosures.append(m)

tempTime1 = datetime.now()

# void generation phase
Expand Down Expand Up @@ -735,12 +671,10 @@ def start(self):

self.meta_list.extend(meta_void)

print_warning_solids(warnSolids, warnEnclosures)

# add plane definition to cone
# add plane definition to cone, currently needs to be done at the end of the process
process_cones(
self.meta_list,
coneInfo,
self.cone_info,
self.Surfaces,
self.geometry_bounding_box,
self.options,
Expand All @@ -754,6 +688,77 @@ def start(self):
logger.info(f"Translation time of solid cells {tempTime1} - {tempTime0}")
logger.info(f"Translation time of void cells {tempTime2} - {tempTime1}")

def _decompose_geometry(self):
Copy link
Member

@psauvan psauvan May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method must be split in 3 methods:

  • 1st : from line 698 to 704 (decomposition of standard solids, and enclosures)
  • 2nd: from line 702 to 742 (processing of geometry with solids made of facets and enclosures decomposition)
  • 3rd: from line 708 to 726 (conversion to solids bool definition) and 744 to 758 (conversion to enclosure bool definition)

the 3rd method must have a flag to tell if standard or facets geometry is processed.

  • if standard geometry execute:
    * conversion to solids bool definition
    * forceNoOverlapping (lines 728 and 729)
    * conversion to enclosure bool

  • if facet geometry execute:
    * conversion to enclosure bool

In the start method the sequence of execution should be:
if facet geometry :
execute 2nd method (processing of geometry with solids made of facets and enclosures decomposition)
else
execute 1st method (decomposition of standard solids, and enclosures)

execute 3rd method (conversion of solids and enclosure). If flag is facet execute only conversion of enclosure

The geometry made of facets doesn't need decomposition and conversion process. The steps equivalent to these two processes are carried out in the function translate

Copy link
Collaborator Author

@shimwell shimwell May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite understanding this as there are overlaps in those line numbers so I guess there will be repetition in the 3 methods.

"""Decomposes the geometry of the current object."""

warnSolids = []
warnEnclosures = []
if not self.options.Facets:
# decompose all solids in elementary solids (convex ones)
warningSolidList = self._decompose_solids(meta=True)

# decompose Enclosure solids
if self.settings.voidGen and self.enclosure_list:
warningEnclosureList = self._decompose_solids(meta=False)

logger.info("End of decomposition phase")

# start Building CGS cells phase

for j, m in enumerate(tqdm(self.meta_list, desc="Translating solid cells")):
if m.IsEnclosure:
continue
logger.info(f"Building cell: {j+1}")
cones = Conv.cellDef(
m,
self.Surfaces,
self.geometry_bounding_box,
self.options,
self.tolerances,
self.numeric_format,
)
if cones:
self.cone_info[m.__id__] = cones
if j in warningSolidList:
warnSolids.append(m)
if not m.Solids:
logger.info(f"none {j}, {m.__id__}")
logger.info(m.Definition)

if self.options.forceNoOverlap:
Conv.no_overlapping_cell(self.meta_list, self.Surfaces, self.options)

else:
translate(
self.meta_list,
self.Surfaces,
self.geometry_bounding_box,
self.settings,
self.options,
self.tolerances,
)
# decompose Enclosure solids
if self.settings.voidGen and self.enclosure_list:
warningEnclosureList = self._decompose_solids(meta=False)

if self.settings.voidGen and self.enclosure_list:
for j, m in enumerate(self.enclosure_list):
logger.info(f"Building Enclosure Cell: {j + 1}")
cones = Conv.cellDef(
m,
self.Surfaces,
self.geometry_bounding_box,
self.options,
self.tolerances,
self.numeric_format,
)
if cones:
self.cone_info[m.__id__] = cones
if j in warningEnclosureList:
warnEnclosures.append(m)

print_warning_solids(warnSolids, warnEnclosures)

def _decompose_solids(self, meta: bool):

if meta:
Expand Down Expand Up @@ -832,8 +837,8 @@ def update_comment(meta, idLabel):
meta.set_comments(void.void_comment_line((meta.__commentInfo__[0], newLabel)))


def process_cones(MetaList, coneInfo, Surfaces, UniverseBox, options, tolerances, numeric_format):
cellId = tuple(coneInfo.keys())
def process_cones(MetaList, cone_info, Surfaces, UniverseBox, options, tolerances, numeric_format):
cellId = tuple(cone_info.keys())
for m in MetaList:
if m.__id__ not in cellId and not m.Void:
continue
Expand All @@ -844,7 +849,7 @@ def process_cones(MetaList, coneInfo, Surfaces, UniverseBox, options, tolerances
cones = set()
for Id in m.__commentInfo__[1]:
if Id in cellId:
cones.update(-x for x in coneInfo[Id])
cones.update(-x for x in cone_info[Id])
Conv.add_cone_plane(
m.Definition,
cones,
Expand All @@ -857,7 +862,7 @@ def process_cones(MetaList, coneInfo, Surfaces, UniverseBox, options, tolerances
elif not m.Void:
Conv.add_cone_plane(
m.Definition,
coneInfo[m.__id__],
cone_info[m.__id__],
Surfaces,
UniverseBox,
options,
Expand Down