IAP GITLAB

Skip to content
Snippets Groups Projects
Commit e367193c authored by Maximilian Reininghaus's avatar Maximilian Reininghaus :vulcan:
Browse files

const-correctness, changed a few names, renamed file

parent fd4f9baf
No related branches found
No related tags found
No related merge requests found
......@@ -16,56 +16,62 @@ using namespace corsika;
// Example to show how to construct an environment in CORSIKA
// MediumType is constructed via "mixin inheritance"
// MyMediumInterface 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 IMediumType = IMediumPropertyModel<IMediumModel>;
using MyMediumInterface = IMediumPropertyModel<IMediumModel>;
using EnvType = Environment<IMediumType>;
using MyEnvType = Environment<MyMediumInterface>;
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<IMediumType>>(std::move(sphere));
auto node = std::make_unique<VolumeTreeNode<MyMediumInterface>>(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};
IMediumType const& media_prop_ =
MyMediumInterface 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(nucs_[0]), get_PDG(nucs_[1]),
fracs_[0], fracs_[1]);
h / 1_m, rho / (1_g / static_pow<3>(1_cm)), get_PDG(nuclei.at(0)),
get_PDG(nuclei.at(1)), fractions.at(0), fractions.at(1));
}
return 0;
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment