<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//NLM//DTD Journal Publishing DTD v2.3 20070202//EN" "journalpublishing.dtd">
<article article-type="research-article" dtd-version="2.3" xml:lang="EN" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">
<front>
<journal-meta>
<journal-id journal-id-type="publisher-id">Front. Nucl. Eng.</journal-id>
<journal-title>Frontiers in Nuclear Engineering</journal-title>
<abbrev-journal-title abbrev-type="pubmed">Front. Nucl. Eng.</abbrev-journal-title>
<issn pub-type="epub">2813-3412</issn>
<publisher>
<publisher-name>Frontiers Media S.A.</publisher-name>
</publisher>
</journal-meta>
<article-meta>
<article-id pub-id-type="publisher-id">1400482</article-id>
<article-id pub-id-type="doi">10.3389/fnuen.2024.1400482</article-id>
<article-categories>
<subj-group subj-group-type="heading">
<subject>Nuclear Engineering</subject>
<subj-group>
<subject>Original Research</subject>
</subj-group>
</subj-group>
</article-categories>
<title-group>
<article-title>New CAD modeling approach in Geant4 with half-space CSG</article-title>
<alt-title alt-title-type="left-running-head">Qiu</alt-title>
<alt-title alt-title-type="right-running-head">
<ext-link ext-link-type="uri" xlink:href="https://doi.org/10.3389/fnuen.2024.1400482">10.3389/fnuen.2024.1400482</ext-link>
</alt-title>
</title-group>
<contrib-group>
<contrib contrib-type="author" corresp="yes">
<name>
<surname>Qiu</surname>
<given-names>Y.</given-names>
</name>
<xref ref-type="corresp" rid="c001">&#x2a;</xref>
<uri xlink:href="https://loop.frontiersin.org/people/2273119/overview"/>
<role content-type="https://credit.niso.org/contributor-roles/conceptualization/"/>
<role content-type="https://credit.niso.org/contributor-roles/data-curation/"/>
<role content-type="https://credit.niso.org/contributor-roles/formal-analysis/"/>
<role content-type="https://credit.niso.org/contributor-roles/funding-acquisition/"/>
<role content-type="https://credit.niso.org/contributor-roles/investigation/"/>
<role content-type="https://credit.niso.org/contributor-roles/methodology/"/>
<role content-type="https://credit.niso.org/contributor-roles/project-administration/"/>
<role content-type="https://credit.niso.org/contributor-roles/resources/"/>
<role content-type="https://credit.niso.org/contributor-roles/software/"/>
<role content-type="https://credit.niso.org/contributor-roles/supervision/"/>
<role content-type="https://credit.niso.org/contributor-roles/validation/"/>
<role content-type="https://credit.niso.org/contributor-roles/visualization/"/>
<role content-type="https://credit.niso.org/contributor-roles/writing-original-draft/"/>
<role content-type="https://credit.niso.org/contributor-roles/Writing - review &#x26; editing/"/>
</contrib>
</contrib-group>
<aff>
<institution>Karlsruhe Institute of Technology</institution>, <addr-line>Karlsruhe</addr-line>, <country>Germany</country>
</aff>
<author-notes>
<fn fn-type="edited-by">
<p>
<bold>Edited by:</bold> <ext-link ext-link-type="uri" xlink:href="https://loop.frontiersin.org/people/1632983/overview">Wei Peng</ext-link>, Tsinghua University, China</p>
</fn>
<fn fn-type="edited-by">
<p>
<bold>Reviewed by:</bold> <ext-link ext-link-type="uri" xlink:href="https://loop.frontiersin.org/people/2738328/overview">Yuetong Luo</ext-link>, Hefei University of Technology, China</p>
<p>
<ext-link ext-link-type="uri" xlink:href="https://loop.frontiersin.org/people/2744657/overview">Stewart Boogert</ext-link>, The University of Manchester, United Kingdom</p>
</fn>
<corresp id="c001">&#x2a;Correspondence: Y. Qiu, <email>yuefeng.qiu@kit.edu</email>
</corresp>
</author-notes>
<pub-date pub-type="epub">
<day>14</day>
<month>08</month>
<year>2024</year>
</pub-date>
<pub-date pub-type="collection">
<year>2024</year>
</pub-date>
<volume>3</volume>
<elocation-id>1400482</elocation-id>
<history>
<date date-type="received">
<day>13</day>
<month>03</month>
<year>2024</year>
</date>
<date date-type="accepted">
<day>26</day>
<month>07</month>
<year>2024</year>
</date>
</history>
<permissions>
<copyright-statement>Copyright &#xa9; 2024 Qiu.</copyright-statement>
<copyright-year>2024</copyright-year>
<copyright-holder>Qiu</copyright-holder>
<license xlink:href="http://creativecommons.org/licenses/by/4.0/">
<p>This is an open-access article distributed under the terms of the Creative Commons Attribution License (CC BY). The use, distribution or reproduction in other forums is permitted, provided the original author(s) and the copyright owner(s) are credited and that the original publication in this journal is cited, in accordance with accepted academic practice. No use, distribution or reproduction is permitted which does not comply with these terms.</p>
</license>
</permissions>
<abstract>
<p>Geant4 offers constructive solid geometry (CSG) for modeling detector geometries, but representing intricate computer-aided design (CAD) structures can be cumbersome. This article presents a novel approach that overcomes this limitation. A new CSG solid type called &#x201c;half-space solid&#x201d; enables the equivalent representation of complex CAD solids within Geant4. An automatic program utilizes optimized decomposition algorithms to convert CAD solids into half-space solids. The geometry description markup language (GDML) has been extended to accommodate the half-space solid type alongside the development of interfaces for exporting converted geometries and their subsequent import into Geant4. These advancements establish a fully automated workflow for converting CAD geometries into CSG-based representations suitable for Geant4 simulations. The reliability of the half-space solid-based modeling approach has been verified through comparisons with established Geant4 solids for both simple shapes and a complex fusion reactor model. The excellent agreement obtained from these comparisons demonstrates the efficiency of this new approach.</p>
</abstract>
<kwd-group>
<kwd>CAD</kwd>
<kwd>CSG</kwd>
<kwd>GDML</kwd>
<kwd>GEANT4</kwd>
<kwd>half-space</kwd>
<kwd>McCad</kwd>
</kwd-group>
<contract-sponsor id="cn001">EUROfusion<named-content content-type="fundref-id">10.13039/100019784</named-content>
</contract-sponsor>
<custom-meta-wrap>
<custom-meta>
<meta-name>section-at-acceptance</meta-name>
<meta-value>Fission and Reactor Design</meta-value>
</custom-meta>
</custom-meta-wrap>
</article-meta>
</front>
<body>
<sec id="s1">
<title>1 Introduction</title>
<p>The design of the nuclear and accelerator systems relies heavily on CAD systems. CAD geometry, which is usually based on the boundary representation (BRep), is often the initial geometry source for high-fidelity nuclear analyses. The conversions of the CAD geometry to the constructive solid geometry (CSG) representation, which is used for geometry modeling in common Monte Carlo (MC) particle transport simulation codes, were studied in the last decade (<xref ref-type="bibr" rid="B13">Wu, 1987-1992</xref>; <xref ref-type="bibr" rid="B7">Lu et al., 2017</xref>). These approaches utilize the half-space type of CSG constructed by Boolean operations of semi-algebraic half-spaces. However, this approach is not directly usable for Geant4 (<xref ref-type="bibr" rid="B1">Allison et al., 2016</xref>) because primitive types of CSG (e.g., box, sphere, nd cylinder) are adopted. The conversion of CAD geometries to primitive CSG is not straightforward because the shapes of the primitive CSG are too constrained to build arbitrary CAD solids. To enable this CAD conversion process, half-space CSG solids are considered a good option and were recently explored in Tgeo (<xref ref-type="bibr" rid="B4">Brun and Rademakers, 1997</xref>) and Vecgeom (<xref ref-type="bibr" rid="B2">Apostolakis et al., 2015</xref>) to support plane-based half-space solids.</p>
<p>Attempts have also been made to directly use the BRep solids, with a significant amount of work dedicated to the implementation of <italic>G4BREPSolid</italic> (<xref ref-type="bibr" rid="B10">Sulkimo and Vuoskoski, 1996</xref>). This work has not been continued due to efficiencies in simulating complex CAD models, but it provides a good foundation for the relevant work with its underlying classes. A continuation in this direction is the Geant4 tessellated solid type <italic>G4TessellatedSolid</italic> (<xref ref-type="bibr" rid="B1">Allison et al., 2016</xref>). The tessellated solid can model CAD geometries through a faceting approximation process without constraints on solid shapes and surface types. A drawback of this approach is the unnecessary increased computational effort for simple CSG shapes; for example, a large number of facets are needed for modeling a sphere. An optimal solution for Geant4 is using CSG and tessellated solids together for both simple and complex shapes.</p>
<p>The modeling of CAD geometry using CSG has been achieved through a set of developments in this work. They include the development of a new Geant4 solid type called <italic>half-space solid</italic>, which is discussed in <xref ref-type="sec" rid="s2">Section 2</xref>, and the development of an automatic modeling approach presented in <xref ref-type="sec" rid="s3">Section 3</xref>. The tests and verifications performed for these developments are discussed in <xref ref-type="sec" rid="s4">Section 4</xref>.</p>
</sec>
<sec id="s2">
<title>2 Half-space solid</title>
<sec id="s2-1">
<title>2.1 Definition</title>
<p>A <italic>half-space</italic> is defined by a surface <inline-formula id="inf1">
<mml:math id="m1">
<mml:mrow>
<mml:mi>f</mml:mi>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x3d;</mml:mo>
<mml:mn>0</mml:mn>
</mml:mrow>
</mml:math>
</inline-formula>, and a sense <inline-formula id="inf2">
<mml:math id="m2">
<mml:mrow>
<mml:mi>&#x3f5;</mml:mi>
</mml:mrow>
</mml:math>
</inline-formula> indicating the side of the surface where the half-space is located. The <inline-formula id="inf3">
<mml:math id="m3">
<mml:mrow>
<mml:mi>&#x3f5;</mml:mi>
<mml:mo>&#x2208;</mml:mo>
<mml:mrow>
<mml:mfenced open="{" close="}" separators="|">
<mml:mrow>
<mml:mo>&#x2212;</mml:mo>
<mml:mn>1</mml:mn>
<mml:mo>,</mml:mo>
<mml:mn>1</mml:mn>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
</mml:mrow>
</mml:math>
</inline-formula> is either 1 or &#x2212;1 when the half-space is on the positive side (<inline-formula id="inf4">
<mml:math id="m4">
<mml:mrow>
<mml:mi>f</mml:mi>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x3e;</mml:mo>
<mml:mn>0</mml:mn>
</mml:mrow>
</mml:math>
</inline-formula>) or negative side (<inline-formula id="inf5">
<mml:math id="m5">
<mml:mrow>
<mml:mi>f</mml:mi>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x3c;</mml:mo>
<mml:mn>0</mml:mn>
</mml:mrow>
</mml:math>
</inline-formula>) of the surface.</p>
<p>Considering a half-space is created from a surface <inline-formula id="inf6">
<mml:math id="m6">
<mml:mrow>
<mml:mi>f</mml:mi>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x3d;</mml:mo>
<mml:mn>0</mml:mn>
</mml:mrow>
</mml:math>
</inline-formula>, the position of a point <inline-formula id="inf7">
<mml:math id="m7">
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
</mml:math>
</inline-formula> related to the half-space can be indicated by <xref ref-type="disp-formula" rid="e1">Equation 1</xref>
<disp-formula id="e1">
<mml:math id="m8">
<mml:mrow>
<mml:mi>S</mml:mi>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x3d;</mml:mo>
<mml:mi>&#x3f5;</mml:mi>
<mml:mo>&#x00B7;</mml:mo>
<mml:mi>f</mml:mi>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mrow>
<mml:mfenced open="{" close="" separators="|">
<mml:mrow>
<mml:mtable columnalign="left">
<mml:mtr>
<mml:mtd>
<mml:mrow>
<mml:mo>&#x3c;</mml:mo>
<mml:mn>0</mml:mn>
<mml:mo>,</mml:mo>
<mml:mtext>if&#x2009;outside</mml:mtext>
</mml:mrow>
</mml:mtd>
</mml:mtr>
<mml:mtr>
<mml:mtd>
<mml:mrow>
<mml:mo>&#x3d;</mml:mo>
<mml:mn>0</mml:mn>
<mml:mo>,</mml:mo>
<mml:mtext>if&#x2009;on&#x2009;the&#x2009;surface&#x2009;</mml:mtext>
</mml:mrow>
</mml:mtd>
</mml:mtr>
<mml:mtr>
<mml:mtd>
<mml:mrow>
<mml:mo>&#x3e;</mml:mo>
<mml:mn>0</mml:mn>
<mml:mo>,</mml:mo>
<mml:mtext>if&#x2009;inside&#x2009;</mml:mtext>
</mml:mrow>
</mml:mtd>
</mml:mtr>
</mml:mtable>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>.</mml:mo>
</mml:mrow>
</mml:math>
<label>(1)</label>
</disp-formula>
</p>
<p>A point is inside a half-space or on the surface only if it is within the semi-algebraic subset <inline-formula id="inf8">
<mml:math id="m9">
<mml:mrow>
<mml:mi>P</mml:mi>
<mml:mo>&#x2282;</mml:mo>
<mml:msup>
<mml:mi mathvariant="double-struck">R</mml:mi>
<mml:mn>3</mml:mn>
</mml:msup>
</mml:mrow>
</mml:math>
</inline-formula> (<xref ref-type="bibr" rid="B3">Bochnak et al., 2013</xref>), which P is defined in <xref ref-type="disp-formula" rid="e2">Equation 2</xref>:<disp-formula id="e2">
<mml:math id="m10">
<mml:mrow>
<mml:mi>P</mml:mi>
<mml:mo>&#x3d;</mml:mo>
<mml:mrow>
<mml:mfenced open="{" close="}" separators="|">
<mml:mrow>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x2208;</mml:mo>
<mml:msup>
<mml:mi mathvariant="double-struck">R</mml:mi>
<mml:mn>3</mml:mn>
</mml:msup>
<mml:mo>&#x7c;</mml:mo>
<mml:mi>S</mml:mi>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x2265;</mml:mo>
<mml:mn>0</mml:mn>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mtext>&#x2003;</mml:mtext>
<mml:mo>.</mml:mo>
</mml:mrow>
</mml:math>
<label>(2)</label>
</disp-formula>
</p>
<p>A <italic>half-space solid</italic> is bounded by a finite number of half-spaces using the Boolean intersection operation. Therefore, a point is inside or on the boundaries of a half-space solid only if it is inside the closed subset <inline-formula id="inf9">
<mml:math id="m11">
<mml:mrow>
<mml:mi>Q</mml:mi>
<mml:mo>&#x2282;</mml:mo>
<mml:msup>
<mml:mi mathvariant="double-struck">R</mml:mi>
<mml:mn>3</mml:mn>
</mml:msup>
</mml:mrow>
</mml:math>
</inline-formula>:<disp-formula id="e3">
<mml:math id="m12">
<mml:mrow>
<mml:mi>Q</mml:mi>
<mml:mo>&#x3d;</mml:mo>
<mml:msubsup>
<mml:mo>&#x22c2;</mml:mo>
<mml:mi>i</mml:mi>
<mml:mi>n</mml:mi>
</mml:msubsup>
<mml:msub>
<mml:mi>P</mml:mi>
<mml:mi>i</mml:mi>
</mml:msub>
<mml:mo>&#x3d;</mml:mo>
<mml:msubsup>
<mml:mo>&#x22c2;</mml:mo>
<mml:mi>i</mml:mi>
<mml:mi>n</mml:mi>
</mml:msubsup>
<mml:mrow>
<mml:mfenced open="{" close="}" separators="|">
<mml:mrow>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x2208;</mml:mo>
<mml:msup>
<mml:mi mathvariant="double-struck">R</mml:mi>
<mml:mn>3</mml:mn>
</mml:msup>
<mml:mo>&#x7c;</mml:mo>
<mml:msub>
<mml:mi>S</mml:mi>
<mml:mi>i</mml:mi>
</mml:msub>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x2265;</mml:mo>
<mml:mn>0</mml:mn>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>,</mml:mo>
</mml:mrow>
</mml:math>
<label>(3)</label>
</disp-formula>where <inline-formula id="inf10">
<mml:math id="m13">
<mml:mrow>
<mml:mi>n</mml:mi>
</mml:mrow>
</mml:math>
</inline-formula> denotes the number of half-spaces, and <inline-formula id="inf11">
<mml:math id="m14">
<mml:mrow>
<mml:mi>i</mml:mi>
<mml:mo>&#x3d;</mml:mo>
<mml:mn>1</mml:mn>
<mml:mo>,</mml:mo>
<mml:mn>2</mml:mn>
<mml:mo>,</mml:mo>
<mml:mn>3</mml:mn>
<mml:mo>,</mml:mo>
<mml:mo>&#x2026;</mml:mo>
<mml:mi>n</mml:mi>
</mml:mrow>
</mml:math>
</inline-formula> denotes the index of half-spaces.</p>
<p>Under a subsequence of decompositions, it is proved that a BRep CAD solid can be converted to a closed semi-algebraic subset <inline-formula id="inf12">
<mml:math id="m15">
<mml:mrow>
<mml:mi>R</mml:mi>
<mml:mo>&#x2282;</mml:mo>
<mml:msup>
<mml:mi mathvariant="double-struck">R</mml:mi>
<mml:mn>3</mml:mn>
</mml:msup>
</mml:mrow>
</mml:math>
</inline-formula> (<xref ref-type="bibr" rid="B11">Tsige-Tamirat, 2001</xref>):<disp-formula id="e4">
<mml:math id="m16">
<mml:mrow>
<mml:mi>R</mml:mi>
<mml:mo>&#x3d;</mml:mo>
<mml:msubsup>
<mml:mo>&#x22c3;</mml:mo>
<mml:mi>j</mml:mi>
<mml:mi>m</mml:mi>
</mml:msubsup>
<mml:msubsup>
<mml:mo>&#x22c2;</mml:mo>
<mml:mi>i</mml:mi>
<mml:mi>n</mml:mi>
</mml:msubsup>
<mml:mrow>
<mml:mfenced open="{" close="}" separators="|">
<mml:mrow>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x2208;</mml:mo>
<mml:msup>
<mml:mi mathvariant="double-struck">R</mml:mi>
<mml:mn>3</mml:mn>
</mml:msup>
<mml:mo>&#x7c;</mml:mo>
<mml:msub>
<mml:mi>S</mml:mi>
<mml:mrow>
<mml:mi>j</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>i</mml:mi>
</mml:mrow>
</mml:msub>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x2265;</mml:mo>
<mml:mn>0</mml:mn>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>,</mml:mo>
</mml:mrow>
</mml:math>
<label>(4)</label>
</disp-formula>where <inline-formula id="inf13">
<mml:math id="m17">
<mml:mrow>
<mml:msub>
<mml:mi>S</mml:mi>
<mml:mrow>
<mml:mi>j</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>i</mml:mi>
</mml:mrow>
</mml:msub>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
</mml:mrow>
</mml:math>
</inline-formula> is defined in (1), <inline-formula id="inf14">
<mml:math id="m18">
<mml:mrow>
<mml:mi>m</mml:mi>
</mml:mrow>
</mml:math>
</inline-formula> denotes the number of decomposed solids, and <inline-formula id="inf15">
<mml:math id="m19">
<mml:mrow>
<mml:mi>j</mml:mi>
<mml:mo>&#x3d;</mml:mo>
<mml:mn>1</mml:mn>
<mml:mo>,</mml:mo>
<mml:mn>2</mml:mn>
<mml:mo>,</mml:mo>
<mml:mn>3</mml:mn>
<mml:mo>,</mml:mo>
<mml:mo>&#x2026;</mml:mo>
<mml:mi>m</mml:mi>
</mml:mrow>
</mml:math>
</inline-formula>. Substituting <xref ref-type="disp-formula" rid="e3">(3)</xref> into <xref ref-type="disp-formula" rid="e4">(4)</xref> proves that a BRep solid can be represented by unions of finite numbers of half-space solids, R, defined in <xref ref-type="disp-formula" rid="e5">Equation 5</xref>:<disp-formula id="e5">
<mml:math id="m20">
<mml:mrow>
<mml:mi>R</mml:mi>
<mml:mo>&#x3d;</mml:mo>
<mml:msubsup>
<mml:mo>&#x22c3;</mml:mo>
<mml:mi>j</mml:mi>
<mml:mi>m</mml:mi>
</mml:msubsup>
<mml:msub>
<mml:mi>Q</mml:mi>
<mml:mi>j</mml:mi>
</mml:msub>
</mml:mrow>
</mml:math>
<label>(5)</label>
</disp-formula>
</p>
<p>The half-space solid is a specific type of half-space CSG, and it is the key to the conversion of CAD geometries to CSG. By implementing this new solid type in Geant4, the modeling of CAD geometry becomes feasible.</p>
</sec>
<sec id="s2-2">
<title>2.2 Implementation</title>
<p>The half-space solid type has been developed as a new Geant4 class called <italic>G4HalfSpaceSolid</italic> by inheriting from the base class <italic>G4VSolid</italic>. As shown in <xref ref-type="fig" rid="F1">Figure 1</xref>, it has a surface list containing the objects of the half-space class <italic>G4HalfSpaceSurface</italic> and is implemented with mandatory functions for geometry tracking. <italic>G4HalfSpaceSurface</italic> is a base class for the classes of specific surface types that restore surface parameters and implement the intersection calculation. Currently, six surface types are supported: plane, cylinder, sphere, cone, general quadric, and torus.</p>
<fig id="F1" position="float">
<label>FIGURE 1</label>
<caption>
<p>The diagram of classes that implement the half-space solid type. The new half-space solid type <italic>G4HalfSpaceSolid</italic> is based on the <italic>G4VSolid</italic> and consists of a collection of half-spaces defined as <italic>G4HalfSpaceSurface</italic>.</p>
</caption>
<graphic xlink:href="fnuen-03-1400482-g001.tif"/>
</fig>
<p>The <italic>G4HalfSpaceSolid</italic> implements the functions of the G4VSolid interface that are necessary for ray tracking and navigation. The function <italic>Inside</italic> checks the relative position of a point, that is, inside, outside, or on the boundaries, regarding the solid. The functions <italic>DistanceToIn</italic> and <italic>DistanceToOut</italic> compute the distance of a particle entering or exiting this solid along a given direction. The functions <italic>SafetyToIn</italic> and <italic>SafetyToOut</italic> estimate the safety (underestimated) distance from a point to enter or exit the solid in any direction.</p>
<p>In the implementation of the function <italic>Inside</italic>, the bounding box of the solid with a small margin on each side is adopted for a first check of the point position. A point is surely outside the half-space solid when it is outside the bounding box. The points inside the bounding box will be further confirmed by the half-spaces of the solid. Based on <xref ref-type="disp-formula" rid="e3">(3)</xref>, a point is outside the half-space solid when it is inside the complement of <inline-formula id="inf16">
<mml:math id="m21">
<mml:mrow>
<mml:mi>Q</mml:mi>
</mml:mrow>
</mml:math>
</inline-formula> defined in <xref ref-type="disp-formula" rid="e6">Equation 6</xref>:<disp-formula id="e6">
<mml:math id="m22">
<mml:mrow>
<mml:mover accent="true">
<mml:mi>Q</mml:mi>
<mml:mo>&#xaf;</mml:mo>
</mml:mover>
<mml:mo>&#x3d;</mml:mo>
<mml:msubsup>
<mml:mo>&#x22c3;</mml:mo>
<mml:mi>i</mml:mi>
<mml:mi>n</mml:mi>
</mml:msubsup>
<mml:msub>
<mml:mover accent="true">
<mml:mi>P</mml:mi>
<mml:mo>&#xaf;</mml:mo>
</mml:mover>
<mml:mi>i</mml:mi>
</mml:msub>
<mml:mtext>&#x2003;</mml:mtext>
<mml:mo>.</mml:mo>
</mml:mrow>
</mml:math>
<label>(6)</label>
</disp-formula>
</p>
<p>Therefore, if <inline-formula id="inf17">
<mml:math id="m23">
<mml:mrow>
<mml:msub>
<mml:mi>S</mml:mi>
<mml:mi>i</mml:mi>
</mml:msub>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x3c;</mml:mo>
<mml:mn>0</mml:mn>
</mml:mrow>
</mml:math>
</inline-formula> is true for one of the half-spaces <inline-formula id="inf18">
<mml:math id="m24">
<mml:mrow>
<mml:msub>
<mml:mi>P</mml:mi>
<mml:mi>i</mml:mi>
</mml:msub>
</mml:mrow>
</mml:math>
</inline-formula>, the point <inline-formula id="inf19">
<mml:math id="m25">
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
</mml:math>
</inline-formula> is outside the solid. If not, the point is on the boundary when one half-space has <inline-formula id="inf20">
<mml:math id="m26">
<mml:mrow>
<mml:msub>
<mml:mi>S</mml:mi>
<mml:mi>i</mml:mi>
</mml:msub>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x3d;</mml:mo>
<mml:mn>0</mml:mn>
</mml:mrow>
</mml:math>
</inline-formula>, or it is inside the solid when all half-spaces have <inline-formula id="inf21">
<mml:math id="m27">
<mml:mrow>
<mml:msub>
<mml:mi>S</mml:mi>
<mml:mi>i</mml:mi>
</mml:msub>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:mi>x</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>y</mml:mi>
<mml:mo>,</mml:mo>
<mml:mi>z</mml:mi>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x3e;</mml:mo>
<mml:mn>0</mml:mn>
</mml:mrow>
</mml:math>
</inline-formula>.</p>
<p>The key functions of <italic>G4HalfSpaceSolid</italic> are the particle-geometry intersection calculation in <italic>DistanceToIn</italic> and <italic>DistanceToOut</italic>. A neutral particle going in a straight trajectory is equivalent to a ray, which has a starting point and a direction vector. For charged particles, the curve trajectory is approximated by chords (<xref ref-type="bibr" rid="B1">Allison et al., 2016</xref>), and the intersection calculation method is hence similar to that of a straight trajectory. The intersections of a ray with all boundary surfaces of a half-space solid are performed, and the intersection points outside the solid are discarded because they are not valid. Normally, the distance of the ray to the nearest intersection point is the actual intersection distance. However, some exceptions require special caution. For example, in <xref ref-type="fig" rid="F2">Figure 2</xref>, ray <italic>a</italic> crosses exactly the intersection line of the cylinder and the plane at Point-1 and enters the solid at Point-2. Point-2 is the correct entry point, but Point-1 might be mistakenly taken because it is the nearest valid answer. To avoid this issue, a probe point with a tiny distance behind Point-1 must be calculated. If the particle is outside the solid after walking in this probe step, Point-2 is the correct answer instead of Point-1.</p>
<fig id="F2" position="float">
<label>FIGURE 2</label>
<caption>
<p>Illustrations of some exceptional cases in calculating the intersection distance of a ray entering and exiting a half-space solid. The gray area represents the solid region.</p>
</caption>
<graphic xlink:href="fnuen-03-1400482-g002.tif"/>
</fig>
<p>Another issue is caused by solution tolerance. For example, an intersection point <inline-formula id="inf22">
<mml:math id="m28">
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:msub>
<mml:mi>x</mml:mi>
<mml:mn>0</mml:mn>
</mml:msub>
<mml:mo>,</mml:mo>
<mml:msub>
<mml:mi>y</mml:mi>
<mml:mn>0</mml:mn>
</mml:msub>
<mml:mo>,</mml:mo>
<mml:msub>
<mml:mi>z</mml:mi>
<mml:mn>0</mml:mn>
</mml:msub>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
</mml:math>
</inline-formula> is supposed to have <inline-formula id="inf23">
<mml:math id="m29">
<mml:mrow>
<mml:mi>f</mml:mi>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:msub>
<mml:mi>x</mml:mi>
<mml:mn>0</mml:mn>
</mml:msub>
<mml:mo>,</mml:mo>
<mml:msub>
<mml:mi>y</mml:mi>
<mml:mn>0</mml:mn>
</mml:msub>
<mml:mo>,</mml:mo>
<mml:msub>
<mml:mi>z</mml:mi>
<mml:mn>0</mml:mn>
</mml:msub>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x3d;</mml:mo>
<mml:mn>0</mml:mn>
</mml:mrow>
</mml:math>
</inline-formula>, whereas <inline-formula id="inf24">
<mml:math id="m30">
<mml:mrow>
<mml:mi>f</mml:mi>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:msub>
<mml:mi>x</mml:mi>
<mml:mn>0</mml:mn>
</mml:msub>
<mml:mo>,</mml:mo>
<mml:msub>
<mml:mi>y</mml:mi>
<mml:mn>0</mml:mn>
</mml:msub>
<mml:mo>,</mml:mo>
<mml:msub>
<mml:mi>z</mml:mi>
<mml:mn>0</mml:mn>
</mml:msub>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
</mml:mrow>
</mml:math>
</inline-formula> might be very closed but not equal to 0. In <italic>G4HalfSpaceSolid</italic>, a tolerance <inline-formula id="inf25">
<mml:math id="m31">
<mml:mrow>
<mml:mi>&#x3b5;</mml:mi>
</mml:mrow>
</mml:math>
</inline-formula> (e.g., 10<sup>&#x2212;9</sup>) is adopted, and a point that satisfies <inline-formula id="inf26">
<mml:math id="m32">
<mml:mrow>
<mml:mrow>
<mml:mfenced open="|" close="|" separators="|">
<mml:mrow>
<mml:mi>f</mml:mi>
<mml:mrow>
<mml:mfenced open="(" close=")" separators="|">
<mml:mrow>
<mml:msub>
<mml:mi>x</mml:mi>
<mml:mn>0</mml:mn>
</mml:msub>
<mml:mo>,</mml:mo>
<mml:msub>
<mml:mi>y</mml:mi>
<mml:mn>0</mml:mn>
</mml:msub>
<mml:mo>,</mml:mo>
<mml:msub>
<mml:mi>z</mml:mi>
<mml:mn>0</mml:mn>
</mml:msub>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
</mml:mrow>
</mml:mfenced>
</mml:mrow>
<mml:mo>&#x3c;</mml:mo>
<mml:mi>&#x3b5;</mml:mi>
</mml:mrow>
</mml:math>
</inline-formula> is considered on the boundary surfaces. The direction of the particle is important for dealing with the precision problem. For example, in <xref ref-type="fig" rid="F2">Figure 2</xref>, ray <italic>b</italic> enters the gray solid at Point-3 from the adjacent solid, but it could be already inside the solid because of the precision problem. An invalid answer will be produced in the function <italic>DistanceToIn</italic>, and the particle will travel blindly through this solid. Therefore, special treatment is performed to handle this issue. Assuming the normal of the boundary surface is always pointing outward the solid, the cosine of the angle <inline-formula id="inf27">
<mml:math id="m33">
<mml:mrow>
<mml:mi>&#x3b8;</mml:mi>
</mml:mrow>
</mml:math>
</inline-formula> between the direction of the ray and the surface normal is computed. If <inline-formula id="inf28">
<mml:math id="m34">
<mml:mrow>
<mml:mi mathvariant="italic">cos</mml:mi>
<mml:mo>&#x2061;</mml:mo>
<mml:mi>&#x3b8;</mml:mi>
<mml:mo>&#x3c;</mml:mo>
<mml:mn>0</mml:mn>
</mml:mrow>
</mml:math>
</inline-formula>, Point-3 is accepted as the entering point of the ray <italic>b</italic>, even though it is not on the trajectory.</p>
<p>The safety distances computed by the functions <italic>SafetyToIn</italic> and <italic>SafetyToOut</italic> are used to accelerate the geometry tracking. If the distance of a particle to the next collision site is smaller than the safety distance, the collision simulation is invoked without knowing the exact intersection distance to solid boundaries. Therefore, the safety distance must be smaller than the actual intersection distance, and the computational effort of calculating the safety distance should be considerably smaller as well. In <italic>SafetyToIn</italic>, an underestimated distance from a particle to the bounding box is computed. In <italic>SafetyToOut</italic>, the minimum isotropic distance of the particle to the boundary surfaces of the half-space solid is calculated. However, calculating the isotropic distance is very computationally expensive for the general quadric and torus surfaces. In these cases, the safety distances are set to 0. This conservative estimation does not affect the correctness of the actual simulation because the intersection calculation will be invoked.</p>
<p>With all these implementations, the <italic>G4HalfSpaceSolid</italic> is intended to be a kind of generic-purpose solid type for use in neutral or charged particle simulation. To create a <italic>G4HalfSpaceSolid</italic> in Geant4, the attributes include the bounding box, volume size, and surface area. In addition, the polyhedron is computed and provided in the later modeling method so that all the solids can be visualized in the Geant4 native visualization system. Manually creating a half-space solid is not straightforward; thus, a modeling approach has been developed in this work to generate a half-space solid model automatically from CAD geometries.</p>
</sec>
</sec>
<sec id="s3">
<title>3 Half-space solid modeling</title>
<p>In this model approach, the GDML (<xref ref-type="bibr" rid="B5">Chytracek et al., 2006</xref>) format has been adopted for the persistence of the half-space solids. The GDML format has been extended to accommodate the half-space solid description. The conversion of CAD solids to half-space solids and an interface for exporting GDML files have been developed.</p>
<sec id="s3-1">
<title>3.1 GDML extensions</title>
<p>GDML is an application-independent geometry description format based on XML, and it is used as a general format in Geant4 for geometry persistence. It has self-consistent definitions of syntax that are specified in the GDML schema. Therefore, GDML can be extended to describe new solid types as long as the GDML schema is extended. In this work, the description of the half-space solid has been integrated into the GDML schema. As defined in the schema, a GDML file consists of five blocks&#x2014;<italic>Define</italic>, the <italic>Material</italic>, the <italic>Solids</italic>, the <italic>Structure</italic>, and the <italic>Setup</italic> blocks. Extensions have been implemented in the <italic>Define</italic> and <italic>Solids</italic> blocks, as shown in <xref ref-type="fig" rid="F3">Figure 3</xref>.</p>
<fig id="F3" position="float">
<label>FIGURE 3</label>
<caption>
<p>The extension of the GDML schema. The extended part is enclosed with the dotted line.</p>
</caption>
<graphic xlink:href="fnuen-03-1400482-g003.tif"/>
</fig>
<p>In the <italic>Define</italic> block, the <italic>Polyhedron</italic> is a polygon mesh used for visualizing the half-space solid. It is built by a list of nodes defined by three coordinates and a list of triangle facets consisting of three-node indices. In the <italic>Solids</italic> block, a <italic>half-space solid</italic> consists of a <italic>Surfaces</italic> list, which provides detailed definitions of half-spaces by the surfaces. It has a <italic>Boundary box</italic> defined by an upper and a lower point, a <italic>Volume</italic>, an <italic>Area</italic>, and a reference to the <italic>Polyhedron</italic>. The names of the solids and the polyhedrons must be uniquely given to be used as a reference for other blocks.</p>
<p>A <italic>Nested Boolean Solid</italic> type has been introduced in the GDML schema. Boolean operators like union, intersection, and subtraction can be used in a nested structure. The description of this solid will be interpreted into <italic>G4BooleanSolid</italic> in the extended Geant4 GDML parser. In the end, the Geant4 GDML parser has been extended to process the half-space solid information in the extended GDML file and construct a model from it.</p>
</sec>
<sec id="s3-2">
<title>3.2 CAD to half-space solid conversion</title>
<p>The conversion of CAD geometry half-space solid has been achieved using McCad (<xref ref-type="bibr" rid="B13">Wu, 1987-1992</xref>), which is an open-source MC geometry conversion program based on the Open CASCADE (OCC) library (<xref ref-type="bibr" rid="B8">Open CASCADE Technology, 2015</xref>). As the key to the conversion process, an automatic decomposition function that generates a set of splitting surfaces and decomposes the CAD solid using OCC Boolean operations has been implemented. Algorithms have been optimized to detect and sort splitting surfaces, as well as introduce new assistant splitting surfaces.</p>
<p>The conversion process starts with solids. A BRep CAD solid is composed of boundaries, which are also called <italic>Faces</italic>. The analytic representation of a face is called a <italic>Surface</italic>. All the surfaces of a solid must be checked in McCad to determine whether they are splitting surfaces. A novel algorithm has been developed in McCad to detect splitting surfaces. Using this algorithm, a BRep solid is meshed into triangle facets employing the OCC library function <italic>BRepMesh_ IncrementalMesh</italic>. A surface is a splitting surface if it has collisions with at least one facet of other faces or at least two facets of other faces located on different sides of this surface. Taking the two solids in <xref ref-type="fig" rid="F4">Figure 4</xref> for illustration, Surface-A collides with Facet-B of Face-B; thus, Surface-A is a splitting surface. Facet-E and Facet-F are located on different sides of Surface-C; hence, Surface-C is also a splitting surface.</p>
<fig id="F4" position="float">
<label>FIGURE 4</label>
<caption>
<p>Illustrations of detecting splitting surfaces. The pink triangles are facets, and the transparent planes are splitting surfaces.</p>
</caption>
<graphic xlink:href="fnuen-03-1400482-g004.tif"/>
</fig>
<p>In some special cases, the boundary surfaces are not suitable for splitting surfaces even if they pass the detection. For example, in <xref ref-type="fig" rid="F5">Figure 5A</xref>, the cylinder Surface-A is an invalid splitting surface. If cutting the solid by this cylinder, the resultant solid outside the cylinder is not a half-space solid, but a &#x201c;ghost&#x201d; solid. An algorithm is provided in McCad to introduce an additional splitting surface. The solid in <xref ref-type="fig" rid="F5">Figure 5A</xref> is cut with the assistant surface Surface-B and Surface-C, and the solid is split into three solids with regular shapes. In addition, optimizing the splitting order can significantly reduce the resultant solids. For example, in <xref ref-type="fig" rid="F5">Figure 5B</xref>, using Surface-C to cut the solid would produce fewer solids than Surface-D. Computational time is reduced in the conversion process by fewer cutting operations. Computational time is reduced in a particle transportation simulation due to fewer solids in the model. More detail about the implementations of these algorithms in McCad is given in (<xref ref-type="bibr" rid="B7">Lu et al., 2017</xref>).</p>
<fig id="F5" position="float">
<label>FIGURE 5</label>
<caption>
<p>Illustrations of introducing assistant splitting surface in <bold>(A)</bold> and optimization of the splitting sequence in <bold>(B)</bold>. The transparent planes are splitting surfaces, and the pink surface is an invalid splitting surface.</p>
</caption>
<graphic xlink:href="fnuen-03-1400482-g005.tif"/>
</fig>
<p>To make the creation of half-space solids possible for Geant4, a new GDML interface has been developed in McCad to export GDML files. Material compositions are defined by their names and densities and are assigned to a group of CAD solids as attributes. The linking information of a material and a solid is provided in the <italic>Structure</italic> block of a GDML file. The half-space solids generated from decomposing a CAD solid are exported in the <italic>Solids</italic> block, and they are united as one nested Boolean solid to represent the original CAD solid. The polyhedrons are produced from the CAD solids for visualization purposes. As a reference, the names of the polyhedrons, materials, and solids are presented uniquely in the GDML file.</p>
<p>As a Geant4 tessellated solid is produced from faceting the CAD solids, it is clear that they can be generated using the OCC function <italic>BRepMesh_IncrementalMesh</italic>. Therefore, McCad has been implemented with a conversion function for <italic>G4TessellatedSolid</italic> (<xref ref-type="bibr" rid="B9">Qiu et al., 2016</xref>) so that a hybrid model can be produced using together half-space solids and tessellated solids.</p>
</sec>
</sec>
<sec id="s4">
<title>4 Tests and verifications</title>
<p>Comparisons have been carried out with the well-validated Geant4 primitive solids and <italic>G4TessellatedSolid</italic> in modeling both simple and complex geometries to test the new half-space solid. The Geant4 version 10.02 was used for the implementation of <italic>G4HalfSpaceSolid</italic>, as well as for the test comparisons.</p>
<sec id="s4-1">
<title>4.1 Test comparisons with Geant4 primitives</title>
<p>As shown in <xref ref-type="fig" rid="F6">Figure 6</xref>, the test comparisons cover all the Geant4 primitive solids supported by the half-space solid. The volume size, the relative position, the safety distance, and the intersection distance are computed, and the results of the primitives are taken as references. Each function is evaluated by testing 10<sup>6</sup> samples. The points and rays are randomly sampled inside the bounding box with a margin of factor 0.5 in each direction.</p>
<fig id="F6" position="float">
<label>FIGURE 6</label>
<caption>
<p>The CSG shapes used to compare the half-space solids and the Geant4 primitive solids. Some of the dimensions are provided (R: radius; H: height; Unit: mm).</p>
</caption>
<graphic xlink:href="fnuen-03-1400482-g006.tif"/>
</fig>
<p>The test of the function <italic>Inside</italic> is considered passed if all the sample points yield consistent results from the two solids. The comparison results of safety and intersection distances are presented by the maximum absolute difference among all the samples. The results are shown in <xref ref-type="table" rid="T1">Table 1</xref>. Note that the methods for calculating the safety distance in some geometry shapes are different between half-space solids and Geant4 primitives. In this case, the comparisons are ignored, and the results are presented as N/A. The CPU time used for testing all the functions is summed and compared, and the value is presented in <xref ref-type="table" rid="T1">Table 1</xref> by ratios taking Geant4 primitives as references.</p>
<table-wrap id="T1" position="float">
<label>TABLE 1</label>
<caption>
<p>Comparison of geometry tracking calculation between half-space solids and Geant4 primitive solid<sc>s</sc>.</p>
</caption>
<table>
<thead valign="top">
<tr>
<th align="center"/>
<th align="center">
<italic>Inside</italic>
</th>
<th align="center">
<italic>DistanceToIn</italic> (mm)</th>
<th align="center">
<italic>DistanceToOut</italic> (mm)</th>
<th align="center">
<italic>SafetyToIn</italic> (mm)</th>
<th align="center">
<italic>SafetyToOut</italic> (mm)</th>
<th align="center">Ratio of CPU time<xref ref-type="table-fn" rid="Tfn1">
<sup>a</sup>
</xref>
</th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td align="center">Box</td>
<td align="center">Pass</td>
<td align="center">5.68 &#xd7; 10<sup>&#x2212;14</sup>
</td>
<td align="center">5.68 &#xd7; 10<sup>&#x2212;14</sup>
</td>
<td align="center">1.00 &#xd7; 10<sup>&#x2212;09</sup>
</td>
<td align="center">0</td>
<td align="center">5.5</td>
</tr>
<tr>
<td align="center">Sphere</td>
<td align="center">Pass</td>
<td align="center">2.64 &#xd7; 10<sup>&#x2212;12</sup>
</td>
<td align="center">2.47 &#xd7; 10<sup>&#x2212;13</sup>
</td>
<td align="center">N/A</td>
<td align="center">0</td>
<td align="center">2.6</td>
</tr>
<tr>
<td align="center">Cylinder</td>
<td align="center">Pass</td>
<td align="center">6.39 &#xd7; 10<sup>&#x2212;13</sup>
</td>
<td align="center">1.17 &#xd7; 10<sup>&#x2212;13</sup>
</td>
<td align="center">N/A</td>
<td align="center">0</td>
<td align="center">4.4</td>
</tr>
<tr>
<td align="center">Cone</td>
<td align="center">Pass</td>
<td align="center">8.33 &#xd7; 10<sup>&#x2212;12</sup>
</td>
<td align="center">1.69 &#xd7; 10<sup>&#x2212;11</sup>
</td>
<td align="center">N/A</td>
<td align="center">8.88 &#xd7; 10<sup>&#x2212;15</sup>
</td>
<td align="center">2.4</td>
</tr>
<tr>
<td align="center">Torus</td>
<td align="center">Pass</td>
<td align="center">6.17 &#xd7; 10<sup>&#x2212;09</sup>
</td>
<td align="center">1.20 &#xd7; 10<sup>&#x2212;10</sup>
</td>
<td align="center">N/A</td>
<td align="center">N/A</td>
<td align="center">0.9</td>
</tr>
<tr>
<td align="center">Trapezoid</td>
<td align="center">Pass</td>
<td align="center">3.12 &#xd7; 10<sup>&#x2212;08</sup>
</td>
<td align="center">1.32 &#xd7; 10<sup>&#x2212;07</sup>
</td>
<td align="center">N/A</td>
<td align="center">3.80 &#xd7; 10<sup>&#x2212;10</sup>
</td>
<td align="center">4.9</td>
</tr>
<tr>
<td align="center">Tube</td>
<td align="center">Pass</td>
<td align="center">1.90 &#xd7; 10<sup>&#x2212;12</sup>
</td>
<td align="center">3.48 &#xd7; 10<sup>&#x2212;13</sup>
</td>
<td align="center">N/A</td>
<td align="center">9.17 &#xd7; 10<sup>&#x2212;16</sup>
</td>
<td align="center">2.3</td>
</tr>
<tr>
<td align="center">Cut tube</td>
<td align="center">Pass</td>
<td align="center">1.48 &#xd7; 10<sup>&#x2212;12</sup>
</td>
<td align="center">1.85 &#xd7; 10<sup>&#x2212;12</sup>
</td>
<td align="center">N/A</td>
<td align="center">8.46 &#xd7; 10<sup>&#x2212;09</sup>
</td>
<td align="center">1.4</td>
</tr>
<tr>
<td align="center">Cone section</td>
<td align="center">Pass</td>
<td align="center">1.56 &#xd7; 10<sup>&#x2212;12</sup>
</td>
<td align="center">2.78 &#xd7; 10<sup>&#x2212;12</sup>
</td>
<td align="center">N/A</td>
<td align="center">7.33 &#xd7; 10<sup>&#x2212;15</sup>
</td>
<td align="center">1.4</td>
</tr>
<tr>
<td align="center">Ellipsoid</td>
<td align="center">Pass</td>
<td align="center">9.35 &#xd7; 10<sup>&#x2212;12</sup>
</td>
<td align="center">9.18 &#xd7; 10<sup>&#x2212;14</sup>
</td>
<td align="center">N/A</td>
<td align="center">N/A</td>
<td align="center">2.4</td>
</tr>
<tr>
<td align="center">Torus section</td>
<td align="center">Pass</td>
<td align="center">1.88 &#xd7; 10<sup>&#x2212;10</sup>
</td>
<td align="center">2.24 &#xd7; 10<sup>&#x2212;11</sup>
</td>
<td align="center">N/A</td>
<td align="center">N/A</td>
<td align="center">0.8</td>
</tr>
</tbody>
</table>
<table-wrap-foot>
<fn id="Tfn1">
<label>
<sup>a</sup>
</label>
<p>Ratio of CPU time: half-space solid to Geant4 primitive solid.</p>
</fn>
</table-wrap-foot>
</table-wrap>
<p>The tests of function <italic>Inside</italic> are passed in all the shapes. For the results of safety and intersection calculations, the differences between half-space solids and primitive solids are mostly below 10<sup>&#x2212;9</sup>&#xa0;mm, which is at the same level as the geometry tolerance. The only exceptional shape is the trapezoid. The reason could be that the trapezoid is defined as a Geant4 primitive <italic>G4Trd</italic> by the locations of its eight points, while it is defined as a half-space solid by the surface parameters. Due to the limit of the precision, the sloped plane of the trapezoid would not be identical between the two representations, which results in slight differences in the results. Nevertheless, the differences are negligibly small. In general, more CPU time is used for half-space solids than for the Geant4 primitives, which means further optimization of the codes and algorithms is needed for <italic>G4HalfSpaceSolid</italic>.</p>
</sec>
<sec id="s4-2">
<title>4.2 Verification of a complex model</title>
<p>The use of half-space solid type in the modeling of complex geometries is tested using the ITER Benchmark model (<xref ref-type="bibr" rid="B12">Wilson et al., 2008</xref>), which is a CAD model of the International Thermonuclear Experimental Reactor (ITER) facility. This CAD model has more than 900 solids, which consist of cylinder, cone, quadric, and torus surfaces. It is converted using McCad and exported to a GDML file. Approximately 3,000 half-space solids are produced in this step. In order to verify this model, a tessellated solid model has been generated using McCad from the same CAD model as half-space solids. Tessellated solids are generated one-to-one with the half-space solid on the same CAD solid so that direct comparison on each solid is allowed, for example, on volume. The precision of the tessellated solid is controlled by a parameter called <italic>deflection</italic>, which is the relative tolerance of an edge/facet to the original curve surface defined for the tessellation process. The deflection used in this tessellated model is 10<sup>&#x2212;3</sup>. These two models are shown in <xref ref-type="fig" rid="F7">Figure 7</xref>. A source has been set up on a sphere surface covering the entire model, and the <italic>Geantino</italic> particles are generated randomly on the surface. The direction of the particle is identical to the surface normal, pointing to the inside of the sphere. The <italic>Geantino</italic> particle is a virtual neutral particle that sees all solids as transparent and has no collision during particle transport. In total 1E7 event is simulated, and the track lengths are scored in all solids using the <italic>G4PSTrackLength</italic> scorer, and the CPU time has also been recorded.</p>
<fig id="F7" position="float">
<label>FIGURE 7</label>
<caption>
<p>Geometries of the half-space solid model (left) and the tessellated solid model (right). The sphere surface source shown on the left is used to simulate both models.</p>
</caption>
<graphic xlink:href="fnuen-03-1400482-g007.tif"/>
</fig>
<p>Due to the large number of solids, the number of facets in the tessellated solid model has exceeded the GDML limitation. To avoid this problem, the tessellated solid model was separated into two models by dividing the solids into two halves. Using the identical source definition, the total <italic>Geantino</italic> track length in the same spatial region must be identical, regardless of the geometry model. Therefore, this treatment does not affect the track lengths scored on the solids, assuming the tessellated solids are identically defined in the separated model as the full model. However, the simulation time summed up from the two separated models will be underestimated compared to the full model because fewer solids are involved in the particle navigation.</p>
<p>The computational time is shown in <xref ref-type="table" rid="T2">Table 2</xref>, using one 3.40&#xa0;GHz processor. The computational performance of the half-space solid model is at least 30% faster than that of the tessellated solid model. This performance could possibly be further improved, for example, by using the well-optimized <italic>G4MultiUnion</italic> to unite the half-space solids instead of using the nested Boolean solid. In addition, a certain number of particles are lost due to the geometry errors in the high-complexity model. The lost particles in 10<sup>7</sup> samples are given in <xref ref-type="table" rid="T2">Table 2</xref> as well, which shows that the half-space solid model has fewer geometry errors. Note that the lost particles reflect the qualities of the McCad-generated models on complex geometries using two different approaches and do not imply or reflect issues of the <italic>G4HalfSpaceSolid</italic> and <italic>G4TessellatedSolid</italic> implementations. The comparison of the track lengths is presented in <xref ref-type="fig" rid="F8">Figure 8</xref> as ratios, which take the results from the tessellated solid model as references. The ratios are, in general, within &#xb1;0.5%. A few solids have ratios of up to 2%. These larger variations are probably due to the geometry difference between the two representations because tessellated solids are facet approximations of CAD solids. The relative error of the half-space solid calculation is provided in <xref ref-type="fig" rid="F8">Figure 8</xref> as well, with a similar trend found in the calculation of the tessellated solid model. It should be noted that the relative error is higher than the ratio of the track lengths, which is unexpected. The reason why track lengths comparison shows a much lower deviation is likely because the same random number generator and seed are used for the simulation of two models, resulting in source particles generated in the same directions in the two runs.</p>
<table-wrap id="T2" position="float">
<label>TABLE 2</label>
<caption>
<p>Comparison of track length and computation time.</p>
</caption>
<table>
<thead valign="top">
<tr>
<th align="center"/>
<th align="center">CPU time (hour)</th>
<th align="center">Lost particles</th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td align="center">Half-space solid model</td>
<td align="center">4</td>
<td align="center">5</td>
</tr>
<tr>
<td align="center">Tessellated solid model</td>
<td align="center">6</td>
<td align="center">90</td>
</tr>
</tbody>
</table>
</table-wrap>
<fig id="F8" position="float">
<label>FIGURE 8</label>
<caption>
<p>The comparison of track length results in each solid between the half-space solid model and the tessellated solid model. The tessellated solid model has been taken as a reference to calculate the differences. The relative error (Rel. Err.) of the half-space solid calculation is provided.</p>
</caption>
<graphic xlink:href="fnuen-03-1400482-g008.tif"/>
</fig>
</sec>
</sec>
<sec sec-type="conclusion" id="s5">
<title>5 Conclusions</title>
<p>A new approach has been developed for Geant4 to model CAD geometry. In this approach, a new CSG solid type called a half-space solid has been developed to allow the conversion from CAD to CSG solids. It has been implemented as a new solid type in Geant4 version 10.02 code with the mandatory functions. In addition, an automatic conversion approach has been developed in McCad to decompose CAD solids into half-space solids with several optimized algorithms. The GDML format has been extended to accommodate the half-space solid type, with interfaces to export the solids from McCAD and then parse in Geant4 code. With all these developments, the automatic conversion of CAD geometries for Geant4 is fulfilled as a mature workflow.</p>
<p>For test verification, the half-space solid type has been tested by comparisons with Geant4 primitives, and very good agreements have been obtained in most of the solids. A complex CAD model of the ITER facility to compare a half-space solid model and a tessellated solid model. The ratios of results between the two models are, in general, within &#xb1;0.5%. Further optimizations are suggested in the future to improve the computation speed of the half-space solid type. This development has been released on <xref ref-type="bibr" rid="B6">Qiu (2024)</xref> and linked to Geant4 version 10.02. It is open-source and is available for the Geant4 community. It should be noted that the current developments are based on a previous version of Geant4 and thus need to be updated to the new Geant4 code base. The update and extension of the code will be collaborative work contributed by people interested in this development.</p>
</sec>
</body>
<back>
<sec sec-type="data-availability" id="s6">
<title>Data availability statement</title>
<p>The original contributions presented in the study are included in the article/Supplementary Material; further inquiries can be directed to the corresponding author.</p>
</sec>
<sec id="s7">
<title>Author contributions</title>
<p>YQ: conceptualization, data curation, formal analysis, funding acquisition, investigation, methodology, project administration, resources, software, supervision, validation, visualization, writing&#x2013;original draft, and writing&#x2013;review and editing.</p>
</sec>
<sec sec-type="funding-information" id="s8">
<title>Funding</title>
<p>The author(s) declare that financial support was received for the research, authorship, and/or publication of this article. Part of this work, supported by the European Communities under contracts of the Association between Euratom and the Karlsruhe Institute of Technology (KIT), was carried out within the framework of the EUROfusion Consortium, funded by the European Union via the Euratom Research and Training Program (Grant Agreement No 101052200&#x2014;EUROfusion).</p>
</sec>
<ack>
<p>Special acknowledgments to Dr. Ulrich Fischer and Dr. Lei Lu for providing valuable support during the code development and manuscript reviews. We acknowledge support by the KIT Publication Fund of the Karlsruhe Institute of Technology.</p>
</ack>
<sec sec-type="COI-statement" id="s9">
<title>Conflict of interest</title>
<p>The author declares that the research was conducted in the absence of any commercial or financial relationships that could be construed as a potential conflict of interest.</p>
</sec>
<sec sec-type="disclaimer" id="s10">
<title>Publisher&#x2019;s note</title>
<p>All claims expressed in this article are solely those of the authors and do not necessarily represent those of their affiliated organizations, or those of the publisher, the editors, and the reviewers. Any product that may be evaluated in this article, or claim that may be made by its manufacturer, is not guaranteed or endorsed by the publisher.</p>
</sec>
<sec sec-type="disclaimer" id="s11">
<title>Author disclaimer</title>
<p>Views and opinions expressed are those of the author(s) only and do not necessarily reflect those of the European Union or the European Commission. Neither the European Union nor the European Commission can be held responsible for them.</p>
</sec>
<ref-list>
<title>References</title>
<ref id="B1">
<citation citation-type="journal">
<person-group person-group-type="author">
<name>
<surname>Allison</surname>
<given-names>J.</given-names>
</name>
<name>
<surname>Amako</surname>
<given-names>K.</given-names>
</name>
<name>
<surname>Apostolakis</surname>
<given-names>J.</given-names>
</name>
<name>
<surname>Arce</surname>
<given-names>P.</given-names>
</name>
<name>
<surname>Asai</surname>
<given-names>M.</given-names>
</name>
<name>
<surname>Aso</surname>
<given-names>T.</given-names>
</name>
<etal/>
</person-group> (<year>2016</year>). <article-title>Recent developments in Geant4</article-title>. <source>NIM</source> <volume>A 835</volume>, <fpage>186</fpage>&#x2013;<lpage>225</lpage>. <pub-id pub-id-type="doi">10.1016/j.nima.2016.06.125</pub-id>
</citation>
</ref>
<ref id="B2">
<citation citation-type="journal">
<person-group person-group-type="author">
<name>
<surname>Apostolakis</surname>
<given-names>J.</given-names>
</name>
<name>
<surname>Bandieramonte</surname>
<given-names>M.</given-names>
</name>
<name>
<surname>Bitzes</surname>
<given-names>G.</given-names>
</name>
<name>
<surname>Brun</surname>
<given-names>R.</given-names>
</name>
<name>
<surname>Canal</surname>
<given-names>P.</given-names>
</name>
<name>
<surname>Carminati</surname>
<given-names>F.</given-names>
</name>
<etal/>
</person-group> (<year>2015</year>). <article-title>Towards a high performance geometry library for particle-detector simulations</article-title>. <source>J. Phys. Conf. Ser.</source> <volume>608</volume>, <fpage>012023</fpage>. <pub-id pub-id-type="doi">10.1088/1742-6596/608/1/012023</pub-id>
</citation>
</ref>
<ref id="B3">
<citation citation-type="book">
<person-group person-group-type="author">
<name>
<surname>Bochnak</surname>
<given-names>J.</given-names>
</name>
<name>
<surname>Coste</surname>
<given-names>M.</given-names>
</name>
<name>
<surname>Roy</surname>
<given-names>M.</given-names>
</name>
</person-group> (<year>2013</year>). <source>Real algebraic geometry</source>. <publisher-loc>Germany</publisher-loc>: <publisher-name>Springer</publisher-name>.</citation>
</ref>
<ref id="B4">
<citation citation-type="journal">
<person-group person-group-type="author">
<name>
<surname>Brun</surname>
<given-names>R.</given-names>
</name>
<name>
<surname>Rademakers</surname>
<given-names>F.</given-names>
</name>
</person-group> (<year>1997</year>). <article-title>ROOT &#x2014; an object oriented data analysis framework</article-title>. <source>Nucl. Instrum. Methods Phys. Res. Sect. A Accel. Spectrom. Detect. Assoc. Equip.</source> <volume>389</volume> (<issue>Issues 1&#x2013;2</issue>), <fpage>81</fpage>&#x2013;<lpage>86</lpage>. <comment>ISSN 0168-9002</comment>. <pub-id pub-id-type="doi">10.1016/S0168-9002(97)00048-X</pub-id>
</citation>
</ref>
<ref id="B5">
<citation citation-type="journal">
<person-group person-group-type="author">
<name>
<surname>Chytracek</surname>
<given-names>R.</given-names>
</name>
<name>
<surname>Mccormick</surname>
<given-names>J.</given-names>
</name>
<name>
<surname>Pokorski</surname>
<given-names>W.</given-names>
</name>
<name>
<surname>Santin</surname>
<given-names>G.</given-names>
</name>
</person-group> (<year>2006</year>). <article-title>Geometry description Markup Language for physics simulation and analysis applications</article-title>. <source>IEEE TNS</source> <volume>53</volume> (<issue>Issue</issue>), <fpage>2892</fpage>&#x2013;<lpage>2896</lpage>. <pub-id pub-id-type="doi">10.1109/tns.2006.881062</pub-id>
</citation>
</ref>
<ref id="B7">
<citation citation-type="journal">
<person-group person-group-type="author">
<name>
<surname>Lu</surname>
<given-names>L.</given-names>
</name>
<name>
<surname>Qiu</surname>
<given-names>Y.</given-names>
</name>
<name>
<surname>Fischer</surname>
<given-names>U.</given-names>
</name>
</person-group> (<year>2017</year>). <article-title>Improved solid decomposition algorithms for the CAD-to-MC conversion tool McCad</article-title>. <source>Fusion Eng. Des.</source> <volume>124</volume>, <fpage>1269</fpage>&#x2013;<lpage>1272</lpage>. <comment>ISSN 0920-3796</comment>. <pub-id pub-id-type="doi">10.1016/j.fusengdes.2017.02.040</pub-id>
</citation>
</ref>
<ref id="B8">
<citation citation-type="web">
<collab>Open CASCADE Technology</collab> (<year>2015</year>). <article-title>3D modeling and numerical simulation</article-title>. <comment>Available at: <ext-link ext-link-type="uri" xlink:href="http://www.opencascade.org">http://www.opencascade.org</ext-link>.</comment>
</citation>
</ref>
<ref id="B9">
<citation citation-type="confproc">
<person-group person-group-type="author">
<name>
<surname>Qiu</surname>
<given-names>Y.</given-names>
</name>
<name>
<surname>Fischer</surname>
<given-names>U.</given-names>
</name>
<name>
<surname>Lu</surname>
<given-names>L.</given-names>
</name>
</person-group> (<year>2016</year>). &#x201c;<article-title>A new Geant4 modeling solution based on CAD geometries</article-title>,&#x201d; in <conf-name>Presented at Annual Nuclear Science Symposium and Medical Imaging Conference</conf-name>, <conf-loc>Strasbourg, France</conf-loc>, <conf-date>Oct. 29 - Nov. 5, 2016</conf-date> (<publisher-name>NSS/MIC</publisher-name>).</citation>
</ref>
<ref id="B6">
<citation citation-type="web">
<person-group person-group-type="author">
<name>
<surname>Qiu</surname>
<given-names>Y.</given-names>
</name>
</person-group> (<year>2024</year>). <article-title>Geant4-Halfspace-solid [Computer software]</article-title>. <comment>GitHub</comment>. <comment>Available at: <ext-link ext-link-type="uri" xlink:href="https://github.com/Derek-yfqiu/Geant4-Halfspace-solid">https://github.com/Derek-yfqiu/Geant4-Halfspace-solid</ext-link>.</comment>
</citation>
</ref>
<ref id="B10">
<citation citation-type="journal">
<person-group person-group-type="author">
<name>
<surname>Sulkimo</surname>
<given-names>J.</given-names>
</name>
<name>
<surname>Vuoskoski</surname>
<given-names>J.</given-names>
</name>
</person-group> (<year>1996</year>). <article-title>Particle tracking in sophisticated CAD modelsfor simulation purposes</article-title>. <source>Nim. A</source> <volume>371</volume>, <fpage>434</fpage>&#x2013;<lpage>438</lpage>. <pub-id pub-id-type="doi">10.1016/0168-9002(95)01238-9</pub-id>
</citation>
</ref>
<ref id="B11">
<citation citation-type="book">
<person-group person-group-type="author">
<name>
<surname>Tsige-Tamirat</surname>
<given-names>H.</given-names>
</name>
</person-group> (<year>2001</year>). &#x201c;<article-title>On the use of cad geometry for Monte Carlo particle transport</article-title>,&#x201d; in <source>Advanced Monte Carlo for radiation physics, particle transport simulation and applications</source> (<publisher-loc>Germany</publisher-loc>: <publisher-name>Springer</publisher-name>), <fpage>511</fpage>&#x2013;<lpage>516</lpage>.</citation>
</ref>
<ref id="B12">
<citation citation-type="journal">
<person-group person-group-type="author">
<name>
<surname>Wilson</surname>
<given-names>P.</given-names>
</name>
<name>
<surname>Feder</surname>
<given-names>R.</given-names>
</name>
<name>
<surname>Fischer</surname>
<given-names>U.</given-names>
</name>
<name>
<surname>Loughlin</surname>
<given-names>M.</given-names>
</name>
<name>
<surname>Petrizzi</surname>
<given-names>L.</given-names>
</name>
<name>
<surname>Wu</surname>
<given-names>Y.</given-names>
</name>
<etal/>
</person-group> (<year>2008</year>). <article-title>State-of-the-art 3-d radiation transport methods for fusion energy systems</article-title>. <source>Fusion Eng. Des.</source> <volume>83</volume> (<issue>7&#x2013;9</issue>), <fpage>824</fpage>&#x2013;<lpage>833</lpage>. <pub-id pub-id-type="doi">10.1016/j.fusengdes.2008.05.038</pub-id>
</citation>
</ref>
<ref id="B13">
<citation citation-type="journal">
<person-group person-group-type="author">
<name>
<surname>Wu</surname>
<given-names>Y.</given-names>
</name>
</person-group> (<year>1987-19922009</year>). <article-title>CAD-based interface programs for fusion neutron transport simulation</article-title>. <source>Fusion Eng. Des.</source> <volume>84</volume> (<issue>7&#x2013;11</issue>), <fpage>1987</fpage>&#x2013;<lpage>1992</lpage>. <pub-id pub-id-type="doi">10.1016/j.fusengdes.2008.12.041</pub-id>
</citation>
</ref>
</ref-list>
</back>
</article>