#include "ISolenoidField.hxx" #include "IFieldManager.hxx" #include "ISolenoidFieldDescription.hxx" #include #include #include #include OA_EXCEPTION(SolenoidField,COMET::EoaCore); OA_EXCEPTION(BadCoilRadii,SolenoidField); COMET::ISolenoidField::ISolenoidField( double current, double coilInnerRadius, double coilOuterRadius, double coilFullLength, const TVector3* translation, const TRotation* rotation, int verbose , double maxR , double maxZ , int nSheets , double tolerance): COMET::IElementField(translation,rotation), fCoil(NULL),fCurrent(current) { if (coilInnerRadius > coilOuterRadius || coilInnerRadius<=0){ COMETError( "COMET::ISolenoidField: Inner radius of coil is less than zero or smaller than the outer radius"); throw BadCoilRadii(); } // Form the coil name: std::stringstream sstream; sstream<GetLength() != coilFullLength || fCoil->GetInnerRadius() != coilInnerRadius || fCoil->GetOuterRadius() != coilOuterRadius) { COMETLog("COMET::ISolenoidField: Existing Coil size does not match field volume." " Deleting old coil and creating new one."); delete fCoil; createCoil=true; } else { createCoil=false; } } if (createCoil) { fCoil=new IBLCoil(coilName, coilInnerRadius, coilOuterRadius, coilFullLength, nSheets, tolerance, maxR, maxZ, 0, 0, 0, 0, coilName+"Cache.dat"); COMET::IBLCoil::registerCoil(fCoil); fCoil->generateFieldMap(); } // Set the bounding box for this element: fBoundingBox.MinX=-fCoil->GetMaxR(); fBoundingBox.MaxX= fCoil->GetMaxR(); fBoundingBox.MinY=-fCoil->GetMaxR(); fBoundingBox.MaxY= fCoil->GetMaxR(); fBoundingBox.MinZ=-fCoil->GetMaxZ(); fBoundingBox.MaxZ= fCoil->GetMaxZ(); if(verbose>0) { fCoil->printCoil(); } } COMET::ISolenoidField::~ISolenoidField() { delete fCoil; } void COMET::ISolenoidField::getFieldValue(const double LocalPoint[4], double LocalField[6]) const { fCoil->addField(LocalPoint,LocalField,fCurrent); } const COMET::IElementFieldDescription* COMET::ISolenoidField::MakeDescription(){ return new ISolenoidFieldDescription( fCurrent, fCoil->GetInnerRadius(), fCoil->GetOuterRadius(), fCoil->GetLength(), GetTranslation(),GetRotation() ); } COMET::ISolenoidField* COMET::ISolenoidField::Recreate(const IElementFieldDescription& description){ const ISolenoidFieldDescription& solenoid=*static_cast(&description); const TVector3* pos = solenoid.Translation(); const TRotation* rot = solenoid.Rotation(); return new ISolenoidField( solenoid.Current(), solenoid.InnerR(), solenoid.OuterR(), solenoid.FullLength(), pos,rot); } std::string COMET::ISolenoidField::GetCacheDirectory()const{ std::string output; // Check for the following variables: std::vector possibleCacheDirectories; possibleCacheDirectories.push_back("ICEDUST_COILMAP_CACHE"); possibleCacheDirectories.push_back("ICEDUST_CACHE"); for (std::vector::const_iterator i_test=possibleCacheDirectories.begin(); i_test!=possibleCacheDirectories.end();++i_test){ const char* value=getenv(i_test->c_str()); if(value){ output=value; break; } } if(output.empty()) output="."; return output; }