IAP GITLAB
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
corsika
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
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
Pranav Sampathkumar
corsika
Commits
e367193c
Commit
e367193c
authored
2 years ago
by
Maximilian Reininghaus
Browse files
Options
Downloads
Patches
Plain Diff
const-correctness, changed a few names, renamed file
parent
fd4f9baf
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/environment.cpp
+77
-0
77 additions, 0 deletions
examples/environment.cpp
with
77 additions
and
0 deletions
examples/environment
_example
.cpp
→
examples/environment.cpp
+
77
−
0
View file @
e367193c
...
...
@@ -16,56 +16,62 @@ using namespace corsika;
// Example to show how to construct an environment in CORSIKA
// Medium
Typ
e is constructed via "mixin inheritance"
//
My
Medium
Interfac
e is constructed via "mixin inheritance"
// Here, we construct our base class with IMediumModel and IMediumPropertyModel:
// the former allow us define a density profile and nuclear composite,
// the later is used to determine energy losses parameters.
using
I
Medium
Typ
e
=
IMediumPropertyModel
<
IMediumModel
>
;
using
My
Medium
Interfac
e
=
IMediumPropertyModel
<
IMediumModel
>
;
using
EnvType
=
Environment
<
I
Medium
Typ
e
>
;
using
My
EnvType
=
Environment
<
My
Medium
Interfac
e
>
;
int
main
()
{
// define the environment and universe
EnvType
env
;
VolumeTreeNode
<
IMediumType
>*
universe
=
env
.
getUniverse
().
get
();
// create environment and universe, empty so far
MyEnvType
env
;
// create a geometry object: a sphere with radius of 1000m
// create a geometry object: a sphere with radius of 1000
m
CoordinateSystemPtr
const
&
rootCS
=
env
.
getCoordinateSystem
();
Point
const
center
{
rootCS
,
0
_m
,
0
_m
,
0
_m
};
LengthType
radius
=
1000
_m
;
LengthType
const
radius
=
1000
_m
;
auto
sphere
=
std
::
make_unique
<
Sphere
>
(
center
,
radius
);
// create node from geometry object
auto
node
=
std
::
make_unique
<
VolumeTreeNode
<
I
Medium
Typ
e
>>
(
std
::
move
(
sphere
));
auto
node
=
std
::
make_unique
<
VolumeTreeNode
<
My
Medium
Interfac
e
>>
(
std
::
move
(
sphere
));
// set medium properties to our node, say it is water
auto
nuc_comp
=
NuclearComposition
({{
Code
::
Hydrogen
,
Code
::
Oxygen
},
{
0.11
,
0.89
}});
MassDensityType
density
=
1
_g
/
(
1
_cm
*
1
_cm
*
1
_cm
);
auto
medium
=
std
::
make_shared
<
MediumPropertyModel
<
HomogeneousMedium
<
IMediumType
>>>
(
Medium
::
WaterLiquid
,
density
,
nuc_comp
);
NuclearComposition
const
nucl_comp
{{
Code
::
Hydrogen
,
Code
::
Oxygen
},
{
0.11
,
0.89
}};
MassDensityType
const
density
=
1
_g
/
(
1
_cm
*
1
_cm
*
1
_cm
);
// create concrete implementation of MyMediumInterface by combining parts that
// implement the corresponding interfaces. HomogeneousMedium implements IMediumModel,
// MediumPropertyModel implements IMediumPropertyModel.
auto
const
medium
=
std
::
make_shared
<
MediumPropertyModel
<
HomogeneousMedium
<
MyMediumInterface
>>>
(
Medium
::
WaterLiquid
,
density
,
nucl_comp
);
node
->
setModelProperties
(
medium
);
// put our node into universe
// node: this has to be down after setting node model properties, since
// std::move will make our previous defined node, which is a unique pointer
// un-referencable in the context
VolumeTreeNode
<
MyMediumInterface
>*
const
universe
=
env
.
getUniverse
().
get
();
universe
->
addChild
(
std
::
move
(
node
));
// example to explore the media properties of the node
for
(
LengthType
h
=
0
_m
;
h
<
radius
;
h
+=
100
_m
)
{
for
(
auto
h
=
0
_m
;
h
<
radius
;
h
+=
100
_m
)
{
Point
const
ptest
{
rootCS
,
0
_m
,
0
_m
,
h
};
I
Medium
Typ
e
const
&
media_prop
_
=
My
Medium
Interfac
e
const
&
media_prop
=
env
.
getUniverse
()
->
getContainingNode
(
ptest
)
->
getModelProperties
();
MassDensityType
rho
_
=
media_prop
_
.
getMassDensity
(
ptest
);
NuclearComposition
nuc_comp
_
=
media_prop
_
.
getNuclearComposition
();
std
::
vector
<
Code
>
nucs_
=
nuc_comp
_
.
getComponents
();
std
::
vector
<
double
>
fracs_
=
nuc_comp
_
.
getFractions
();
MassDensityType
const
rho
=
media_prop
.
getMassDensity
(
ptest
);
NuclearComposition
const
&
nuc_comp
=
media_prop
.
getNuclearComposition
();
std
::
vector
<
Code
>
const
&
nuclei
=
nuc_comp
.
getComponents
();
std
::
vector
<
double
>
const
&
fractions
=
nuc_comp
.
getFractions
();
CORSIKA_LOG_INFO
(
"radius: {:.2f} m, density: {:.2f} g/cm^3, nucs: ({:d}, {:d}), fracs: ({:.2f}, "
"radius: {:.2f} m, density: {:.2f} g/cm^3, nuclei: ({:d}, {:d}), fractions: "
"({:.2f}, "
"{:.2f})"
,
h
/
1
_m
,
rho
_
/
1
_g
*
(
1
_cm
*
1
_cm
*
1
_cm
),
get_PDG
(
nuc
s_
[
0
]),
get_PDG
(
nucs_
[
1
]
),
fracs_
[
0
],
fracs_
[
1
]
);
h
/
1
_m
,
rho
/
(
1
_g
/
static_pow
<
3
>
(
1
_cm
)
)
,
get_PDG
(
nuc
lei
.
at
(
0
)
),
get_PDG
(
nuclei
.
at
(
1
)),
fractions
.
at
(
0
),
fractions
.
at
(
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