Skip to content
Snippets Groups Projects
Commit c8364ca3 authored by Johannes Junggeburth's avatar Johannes Junggeburth :dog2:
Browse files

Extend poly edges

parent 412b99cf
No related branches found
No related tags found
1 merge request!391Extend poly edges
Pipeline #9857927 passed
...@@ -28,6 +28,10 @@ ...@@ -28,6 +28,10 @@
#include <vector> #include <vector>
namespace{
constexpr unsigned tubeApproxEdges = 8;
}
std::pair<const GeoShape* , const GeoShape*> getOps(const GeoShape* composed) { std::pair<const GeoShape* , const GeoShape*> getOps(const GeoShape* composed) {
if (composed->typeID() == GeoShapeUnion::getClassTypeID()) { if (composed->typeID() == GeoShapeUnion::getClassTypeID()) {
const GeoShapeUnion* unionShape = dynamic_cast<const GeoShapeUnion*>(composed); const GeoShapeUnion* unionShape = dynamic_cast<const GeoShapeUnion*>(composed);
...@@ -48,7 +52,7 @@ std::pair<const GeoShape* , const GeoShape*> getOps(const GeoShape* composed) { ...@@ -48,7 +52,7 @@ std::pair<const GeoShape* , const GeoShape*> getOps(const GeoShape* composed) {
unsigned int countComposedShapes(const GeoShape* shape) { unsigned int countComposedShapes(const GeoShape* shape) {
std::pair<const GeoShape*, const GeoShape*> ops = getOps(shape); std::pair<const GeoShape*, const GeoShape*> ops = getOps(shape);
return 1 + (ops.first ? countComposedShapes(ops.first) : 0) + return 1 + (ops.first ? countComposedShapes(ops.first) : 0) +
(ops.second ? countComposedShapes(ops.second) : 0); (ops.second ? countComposedShapes(ops.second) : 0);
} }
GeoIntrusivePtr<const GeoShape> compressShift(const GeoShape* shift) { GeoIntrusivePtr<const GeoShape> compressShift(const GeoShape* shift) {
...@@ -229,6 +233,46 @@ std::vector<GeoTrf::Vector3D> getPolyShapeEdges(const GeoShape* shape, ...@@ -229,6 +233,46 @@ std::vector<GeoTrf::Vector3D> getPolyShapeEdges(const GeoShape* shape,
} }
} }
} else if (shape->typeID() == GeoTube::getClassTypeID()) {
constexpr double stepLength = 2.*M_PI / tubeApproxEdges;
const GeoTube* tube = static_cast<const GeoTube*>(shape);
for (const double z :{-1., 1.}){
for (unsigned int e = 0; e < tubeApproxEdges; ++e) {
edgePoints.emplace_back(tube->getRMax()*std::cos(stepLength*e),
tube->getRMax()*std::sin(stepLength*e),
z*tube->getZHalfLength());
}
}
} else if (shape->typeID() == GeoTubs::getClassTypeID()) {
const GeoTubs* tubs = static_cast<const GeoTubs*>(shape);
const double stepSize = tubs->getDPhi() / tubeApproxEdges;
for (const double z : {-1., 1.}) {
for (unsigned e = 0; e <= tubeApproxEdges; ++e) {
edgePoints.emplace_back(tubs->getRMax()*std::cos(tubs->getSPhi() + stepSize*e),
tubs->getRMax()*std::sin(tubs->getSPhi() + stepSize*e),
z*tubs->getZHalfLength());
}
}
} else if (shape->typeID() == GeoEllipticalTube::getClassTypeID()) {
const GeoEllipticalTube* tube = static_cast<const GeoEllipticalTube*>(shape);
constexpr double stepSize = 2.*M_PI / tubeApproxEdges;
for (const double z : {-1.,1.}) {
for (unsigned e = 0; e<tubeApproxEdges; ++e){
edgePoints.emplace_back(tube->getXHalfLength()*std::cos(stepSize*e),
tube->getYHalfLength()*std::sin(stepSize*e),
z* tube->getZHalfLength());
}
}
} else if (shape->typeID() == GeoTorus::getClassTypeID()) {
constexpr double stepSize = 2.*M_PI / tubeApproxEdges;
const GeoTorus* torus = static_cast<const GeoTorus*>(shape);
for (unsigned int donut =0; donut < tubeApproxEdges; ++donut) {
for (unsigned int slice =0; slice < tubeApproxEdges; ++slice) {
edgePoints.emplace_back((torus->getRTor() + torus->getRMax()* std::cos(slice *stepSize))*std::cos(donut*stepSize),
(torus->getRTor() + torus->getRMax()* std::cos(slice *stepSize))*std::sin(donut*stepSize),
torus->getRMax()* std::sin(slice*stepSize));
}
}
} else { } else {
THROW_EXCEPTION("The shape "<<shape->type()<<" is not supported. Please add it to the list"); THROW_EXCEPTION("The shape "<<shape->type()<<" is not supported. Please add it to the list");
} }
......
...@@ -33,15 +33,14 @@ namespace { ...@@ -33,15 +33,14 @@ namespace {
const GeoMaterial* MaterialManager::MaterialFactory::get() const { return m_material; } const GeoMaterial* MaterialManager::MaterialFactory::get() const { return m_material; }
MaterialManager::MaterialFactory::~MaterialFactory() { MaterialManager::MaterialFactory::~MaterialFactory() {
if (!m_material) return; if (!m_material) return;
// std::cout<<"MaterialFactory() -- finalize " <<m_material->getName()<<std::endl;
if (m_components.empty()) { if (m_components.empty()) {
m_material->lock(); m_material->lock();
return; return;
} }
const double inv_totalFraction = 1. / m_totFraction; const double inv_totalFraction = 1. / m_totFraction;
for(const auto& [element, fraction] : m_components) { for(const auto& [element, fraction] : m_components) {
m_material->add(element, m_material->add(element, fraction * element->getA() * inv_totalFraction);
fraction * element->getA() * inv_totalFraction);
} }
m_material->lock(); m_material->lock();
} }
...@@ -56,8 +55,7 @@ void MaterialManager::MaterialFactory::addComponent(const ConstMaterialPtr& mat, ...@@ -56,8 +55,7 @@ void MaterialManager::MaterialFactory::addComponent(const ConstMaterialPtr& mat,
addComponent(elePtr, mat->getFraction(ele) * fraction); addComponent(elePtr, mat->getFraction(ele) * fraction);
} }
} }
void MaterialManager::MaterialFactory::addComponent(const ConstElementPtr& ele, void MaterialManager::MaterialFactory::addComponent(const ConstElementPtr& ele, double fraction) {
double fraction) {
m_components.emplace_back(std::make_pair(ele, fraction)); m_components.emplace_back(std::make_pair(ele, fraction));
m_totFraction += fraction; m_totFraction += fraction;
} }
...@@ -135,7 +133,7 @@ void MaterialManager::printAll() const { ...@@ -135,7 +133,7 @@ void MaterialManager::printAll() const {
} }
void MaterialManager::addElement(const std::string &name, const std::string &symbol, double z, double a) { void MaterialManager::addElement(const std::string &name, const std::string &symbol, double z, double a) {
GeoIntrusivePtr<GeoElement> newElement{new GeoElement(name,symbol,z,a*atomicDensity)}; GeoIntrusivePtr<GeoElement> newElement{make_intrusive<GeoElement>(name,symbol,z,a*atomicDensity)};
addElement(newElement); addElement(newElement);
} }
...@@ -158,7 +156,7 @@ void MaterialManager::setMaterialNamespace(const std::string &name) { ...@@ -158,7 +156,7 @@ void MaterialManager::setMaterialNamespace(const std::string &name) {
void MaterialManager::lockMaterial() { m_factory.reset(); } void MaterialManager::lockMaterial() { m_factory.reset(); }
void MaterialManager::addMaterial(const std::string &name, double density) { void MaterialManager::addMaterial(const std::string &name, double density) {
MaterialPtr newMat{new GeoMaterial(name, density * volDensity)}; MaterialPtr newMat{make_intrusive<GeoMaterial>(name, density * volDensity)};
addMaterial(newMat); addMaterial(newMat);
} }
...@@ -200,14 +198,14 @@ void MaterialManager::addMatComponent(const std::string &name, double fraction) ...@@ -200,14 +198,14 @@ void MaterialManager::addMatComponent(const std::string &name, double fraction)
} }
void MaterialManager::buildSpecialMaterials() { void MaterialManager::buildSpecialMaterials() {
// Ether // Ether
GeoIntrusivePtr<GeoElement> ethElement{new GeoElement("Ether","ET",500.0,0.0)}; GeoIntrusivePtr<GeoElement> ethElement{make_intrusive<GeoElement>("Ether","ET",500.0,0.0)};
m_elements.insert(std::make_pair("Ether",ethElement)); m_elements.insert(std::make_pair("Ether",ethElement));
GeoIntrusivePtr<GeoMaterial> ether{new GeoMaterial("special::Ether",0.0)}; GeoIntrusivePtr<GeoMaterial> ether{make_intrusive<GeoMaterial>("special::Ether",0.0)};
ether->add(ethElement,1.); ether->add(ethElement,1.);
ether->lock(); ether->lock();
m_materials.insert(std::make_pair("special::Ether", ether)); m_materials.insert(std::make_pair("special::Ether", ether));
// HyperUranium // HyperUranium
GeoIntrusivePtr<GeoMaterial> hu{new GeoMaterial("special::HyperUranium",0.0)}; GeoIntrusivePtr<GeoMaterial> hu{make_intrusive<GeoMaterial>("special::HyperUranium",0.0)};
hu->add(ethElement,1.); hu->add(ethElement,1.);
hu->lock(); hu->lock();
m_materials.insert(std::make_pair("special::HyperUranium", hu)); m_materials.insert(std::make_pair("special::HyperUranium", hu));
......
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