From 05e2d2a7b1455bd6e5870f75fdd3d5533fa3c524 Mon Sep 17 00:00:00 2001 From: Fan <fan_hu@pku.edu.cn> Date: Sat, 5 Mar 2022 14:40:36 +0800 Subject: [PATCH] format and update --- examples/environment_example.cpp | 49 ++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/examples/environment_example.cpp b/examples/environment_example.cpp index 77c7b307e..20a10101d 100644 --- a/examples/environment_example.cpp +++ b/examples/environment_example.cpp @@ -19,37 +19,44 @@ using EnvType = Environment<IMediumType>; int main() { // define the environment and universe EnvType env; - auto *universe = env.getUniverse().get(); - auto const &rootCS = env.getCoordinateSystem(); + VolumeTreeNode<IMediumType>* universe = env.getUniverse().get(); - // create a geometry object + // create a geometry object: a sphere with radius of 1000m + CoordinateSystemPtr const& rootCS = env.getCoordinateSystem(); Point const center{rootCS, 0_m, 0_m, 0_m}; - auto radius = 1000_m; + LengthType radius = 1000_m; auto sphere = std::make_unique<Sphere>(center, radius); - // create node from geometry object and put it into universe + // create node from geometry object auto node = std::make_unique<VolumeTreeNode<IMediumType>>(std::move(sphere)); - universe->addChild(std::move(node)); - - // set media properties to our node, say it is water - auto nuc_comp = - NuclearComposition({{Code::Carbon, Code::Oxygen}, {0.11, 0.89}}); - auto density = 1_g / (1_cm * 1_cm * 1_cm); - auto medium = - std::make_shared<MediumPropertyModel<HomogeneousMedium<IMediumType>>>( - Medium::WaterLiquid, density, nuc_comp); + // 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); node->setModelProperties(medium); - // example to explore the node + // 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 + universe->addChild(std::move(node)); + + // example to explore the media properties of the node for (LengthType h = 0_m; h < radius; h += 100_m) { Point const ptest{rootCS, 0_m, 0_m, h}; - auto rho = env.getUniverse() - ->getContainingNode(ptest) - ->getModelProperties() - .getMassDensity(ptest); - CORSIKA_LOG_INFO("radius: {:.2f} m, density: {:.2f} g/cm^3, ", h / 1_m, - rho / 1_g * (1_cm * 1_cm * 1_cm)); + IMediumType 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(); + CORSIKA_LOG_INFO( + "radius: {:.2f} m, density: {:.2f} g/cm^3, nucs: ({:d}, {:d}), fracs: ({:.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]); } return 0; -- GitLab