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
167 changes: 86 additions & 81 deletions src/geouned/GEOUNED/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,80 +565,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,6 +670,82 @@ def start(self):

self.meta_list.extend(meta_void)

logger.info("Process finished")
logger.info(datetime.now() - startTime)

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 = []
coneInfo = dict()
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)

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)

print_warning_solids(warnSolids, warnEnclosures)

# add plane definition to cone
Expand All @@ -748,12 +759,6 @@ def start(self):
self.numeric_format,
)

logger.info("Process finished")
logger.info(datetime.now() - startTime)

logger.info(f"Translation time of solid cells {tempTime1} - {tempTime0}")
logger.info(f"Translation time of void cells {tempTime2} - {tempTime1}")

def _decompose_solids(self, meta: bool):

if meta:
Expand Down Expand Up @@ -823,15 +828,6 @@ def _decompose_solids(self, meta: bool):
return warningSolids


def update_comment(meta, idLabel):
if meta.__commentInfo__ is None:
return
if meta.__commentInfo__[1] is None:
return
newLabel = (idLabel[i] for i in meta.__commentInfo__[1])
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())
for m in MetaList:
Expand Down Expand Up @@ -866,6 +862,15 @@ def process_cones(MetaList, coneInfo, Surfaces, UniverseBox, options, tolerances
)


def update_comment(meta, idLabel):
if meta.__commentInfo__ is None:
return
if meta.__commentInfo__[1] is None:
return
newLabel = (idLabel[i] for i in meta.__commentInfo__[1])
meta.set_comments(void.void_comment_line((meta.__commentInfo__[0], newLabel)))


def print_warning_solids(warnSolids, warnEnclosures):

solids_logger = logging.getLogger("solids_logger")
Expand Down