Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GeoModel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GeoModelDev
GeoModel
Commits
14782434
Commit
14782434
authored
2 months ago
by
Johannes Junggeburth
Browse files
Options
Downloads
Patches
Plain Diff
Introduce GeoMaterial sorter helper struct
parent
f6aa8bbb
No related branches found
No related tags found
1 merge request
!412
Query is nothing else than a std::optional but just came earlier
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GeoModelCore/GeoModelHelpers/GeoModelHelpers/GeoMaterialSorter.h
+33
-0
33 additions, 0 deletions
...lCore/GeoModelHelpers/GeoModelHelpers/GeoMaterialSorter.h
GeoModelCore/GeoModelHelpers/src/GeoMaterialSorter.cxx
+56
-0
56 additions, 0 deletions
GeoModelCore/GeoModelHelpers/src/GeoMaterialSorter.cxx
with
89 additions
and
0 deletions
GeoModelCore/GeoModelHelpers/GeoModelHelpers/GeoMaterialSorter.h
0 → 100644
+
33
−
0
View file @
14782434
/*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/
#ifndef GeoModelHelpers_GeoMaterialSorter_H
#define GeoModelHelpers_GeoMaterialSorter_H
#include
"GeoModelKernel/GeoMaterial.h"
#include
"GeoModelKernel/GeoElement.h"
#include
"GeoModelKernel/GeoIntrusivePtr.h"
#include
<set>
/// @brief Helper struct to deuplicate equivalent materials with different naming
struct
GeoMaterialSorter
{
/** @brief Comparison operator returing whether Material A is smaller than Material B */
bool
operator
()(
const
GeoMaterial
*
a
,
const
GeoMaterial
*
b
)
const
;
/** @brief Comparison operator returing whether the Element A is smaller than Element B */
bool
operator
()(
const
GeoElement
*
a
,
const
GeoElement
*
b
)
const
;
/// @brief Compares 2 GeoMaterials
/// @param a : Pointer to material A
/// @param b : Pointer to material B
/// @return Returns 0 if no defining material property could be found that differs
/// Returns -1 if the first defining & differing property of A is smaller
/// Returns 1 otherwise
int
compare
(
const
GeoMaterial
*
a
,
const
GeoMaterial
*
b
)
const
;
int
compare
(
const
GeoElement
*
a
,
const
GeoElement
*
b
)
const
;
};
/// @brief
/// @tparam ShapeType
using
GeoMaterialSet
=
std
::
set
<
GeoIntrusivePtr
<
const
GeoMaterial
>
,
GeoMaterialSorter
>
;
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
GeoModelCore/GeoModelHelpers/src/GeoMaterialSorter.cxx
0 → 100644
+
56
−
0
View file @
14782434
/*
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
*/
#include
"GeoModelHelpers/GeoMaterialSorter.h"
namespace
{
// Tolerance in density to treat both material equally
constexpr
double
equivTol
=
1.e-6
;
}
bool
GeoMaterialSorter
::
operator
()(
const
GeoMaterial
*
a
,
const
GeoMaterial
*
b
)
const
{
return
compare
(
a
,
b
)
<
0
;
}
bool
GeoMaterialSorter
::
operator
()(
const
GeoElement
*
a
,
const
GeoElement
*
b
)
const
{
return
compare
(
a
,
b
)
<
0
;
}
int
GeoMaterialSorter
::
compare
(
const
GeoMaterial
*
a
,
const
GeoMaterial
*
b
)
const
{
if
(
a
==
b
)
{
return
0
;
}
if
(
a
->
getNumElements
()
!=
b
->
getNumElements
())
{
return
a
->
getNumElements
()
<
b
->
getNumElements
();
}
const
double
densityCmp
=
a
->
getDensity
()
-
b
->
getDensity
();
if
(
std
::
abs
(
densityCmp
)
>
equivTol
)
{
return
densityCmp
<
0.
?
-
1
:
1
;
}
/// Assume sorting of elements by fraction
for
(
unsigned
e
=
0
;
e
<
a
->
getNumElements
();
++
e
)
{
const
double
fracComp
=
a
->
getFraction
(
e
)
-
b
->
getFraction
(
e
);
if
(
std
::
abs
(
fracComp
)
>
equivTol
)
{
return
fracComp
<
0.
?
-
1
:
1
;
}
const
int
eleCmp
=
compare
(
a
->
getElement
(
e
),
b
->
getElement
(
e
));
if
(
eleCmp
)
{
return
eleCmp
;
}
}
return
0
;
}
int
GeoMaterialSorter
::
compare
(
const
GeoElement
*
a
,
const
GeoElement
*
b
)
const
{
if
(
a
==
b
)
{
return
0
;
}
if
(
a
->
getZ
()
!=
b
->
getZ
())
{
return
a
->
getZ
()
<
b
->
getZ
()
?
-
1
:
1
;
}
if
(
a
->
getA
()
!=
b
->
getA
())
{
return
a
->
getA
()
<
b
->
getA
()
?
-
1
:
1
;
}
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment