#include "elementCell.h" #include #include "mathematicalTools.h" #include "mixedTools.h" elementCell::elementCell() : abstractElement() { setDefaultValues(); setDefaults(); elementName_ = nomdElements("cell"); nbParam_ = elementName_.getElementNbParameters(); parametersString_ = new string[nbParam_+1]; // registerAcceptableSoftware(nomDeLogiciel::parmela, TBoolOk); } void elementCell::setDefaultValues() { defaultSpecificName_ = "cell"; initialPhaseDef_ = 0.0; acceleratingFieldDef_ = 1.0; acceleratingShapeFileDef_ = "xxxxxxx"; focusingMagFileDef_ = "xxxxxx"; offsetMagDef_ = 0.0; scaleFactorDef_ = 1.0; } void elementCell::setDefaults() { specificName_ = defaultSpecificName_; initialPhase_ = initialPhaseDef_; acceleratingField_ = acceleratingFieldDef_; acceleratingShapeFile_ = acceleratingShapeFileDef_; focusingMagFile_ = focusingMagFileDef_; offsetMag_ = offsetMagDef_; scaleFactor_ = scaleFactorDef_; } string* elementCell::getParametersString() const { int compteur = -1; parametersString_[++compteur] = mixedTools::intToString(nbParam_); parametersString_[++compteur] = specificName_; parametersString_[++compteur] = mixedTools::doubleToString(lenghtElem_); parametersString_[++compteur] = mixedTools::doubleToString(aperture_); parametersString_[++compteur] = mixedTools::doubleToString(initialPhase_); parametersString_[++compteur] = mixedTools::doubleToString( phaseStepMax_); parametersString_[++compteur] = mixedTools::doubleToString(acceleratingField_); parametersString_[++compteur] = acceleratingShapeFile_; parametersString_[++compteur] = focusingMagFile_; parametersString_[++compteur] = mixedTools::doubleToString(offsetMag_); parametersString_[++compteur] = mixedTools::doubleToString(scaleFactor_); if ( compteur != nbParam_ ) { cerr << " elementCell::getParametersString() : ERROR nr pf parameters dosnt match " << endl; return NULL; } return parametersString_; } void elementCell::setParametersString(string* param) { if ( param == NULL ) { cerr << " elementCell::setParametersString parameters empty parameter set"; return; } int compteur = -1; int nbparam = atoi(param[++compteur].c_str()); if ( nbparam != nbParam_ ) { cerr << " elementCell::setParametersString parameters do not match for a CELL"; return; } specificName_ = param[++compteur]; lenghtElem_ = atof(param[++compteur].c_str()); aperture_ = atof(param[++compteur].c_str()); initialPhase_ = atof(param[++compteur].c_str()); phaseStepMax_ = atof(param[++compteur].c_str()); acceleratingField_ = atof(param[++compteur].c_str()); acceleratingShapeFile_ = param[++compteur]; focusingMagFile_ = param[++compteur]; offsetMag_ = atof(param[++compteur].c_str()); scaleFactor_ = atof(param[++compteur].c_str()); } // string elementCell::parmelaOutputFlow() const // { // ostringstream sortie; // sortie << "CELL /l=" << lenghtElem_ << " /aper=" << aperture_ << endl; // sortie << " /iout=1 /phi0=" << initialPhase_ << " /E0=" << acceleratingField_ << endl; // sortie << " /nc=1 /dwtmax=" << phaseStepMax_ << " /sym=-1" << endl; // sortie << "CFIELD 1" << endl; // sortie << acceleratingShapeFile_ << endl; // if ( focusingMagFile_ != "") { // sortie << "POISSON /zoff=" << offsetMag_ << " /rmult=" << scaleFactor_ << endl; // sortie << focusingMagFile_ << endl; // } // return sortie.str(); // } string elementCell::FileOutputFlow() const { ostringstream sortie; // sortie << elementName_.getElementType() << endl; sortie << elementName_.getGenericLabel() << endl; sortie << specificName_ << endl; sortie << lenghtElem_ << " " << aperture_ << endl; sortie << initialPhase_ << " " << acceleratingField_ << endl; sortie << phaseStepMax_ << endl; sortie << acceleratingShapeFile_ << endl; sortie << focusingMagFile_ << endl; sortie << offsetMag_ << " " << scaleFactor_ << endl; return sortie.str(); } vector< pair > > elementCell::parametersToSoftware () const { vector< pair > > sortie; sortie.push_back( pair >("labelsGenericSpecific", vector() ) ); sortie.back().second.push_back(elementName_.getGenericLabel()); sortie.back().second.push_back(specificName_); sortie.push_back( pair >("lenghtAperture", vector() ) ); sortie.back().second.push_back(mixedTools::doubleToString(lenghtElem_)); sortie.back().second.push_back(mixedTools::doubleToString( aperture_)); sortie.push_back( pair >("phaseInitialStepmax", vector() ) ); sortie.back().second.push_back(mixedTools::doubleToString( initialPhase_)); sortie.back().second.push_back(mixedTools::doubleToString( phaseStepMax_)); sortie.push_back( pair >("fieldValueFile", vector() ) ); sortie.back().second.push_back(mixedTools::doubleToString( acceleratingField_)); sortie.back().second.push_back(acceleratingShapeFile_); sortie.push_back( pair >("MagFocusingFileOffsetScale", vector() ) ); sortie.back().second.push_back(focusingMagFile_); sortie.back().second.push_back(mixedTools::doubleToString( offsetMag_)); sortie.back().second.push_back(mixedTools::doubleToString( scaleFactor_)); return sortie; } void elementCell::FileInput(ifstream& ifs) { ifs >> specificName_; ifs >> lenghtElem_ >> aperture_; ifs >> initialPhase_ >> acceleratingField_; ifs >> phaseStepMax_; ifs >> acceleratingShapeFile_; ifs >> focusingMagFile_; ifs >> offsetMag_ >> scaleFactor_; } string elementCell::print() { string txt = ""; txt += specificName_; txt += "\nlength (cm) : "; txt += mixedTools::doubleToString(lenghtElem_); txt += "\naperture (cm) : "; txt += mixedTools::doubleToString(aperture_); txt += "\ninitial phase (deg.) : "; txt += mixedTools::doubleToString(initialPhase_); txt += "\nmax phase step (deg.) : "; txt += mixedTools::doubleToString(phaseStepMax_); txt += "\nmax accelerating field (MV/m) : "; txt += mixedTools::doubleToString(acceleratingField_); txt += "\nname of file for field shape : "; txt += acceleratingShapeFile_; txt += "\nname of file for focusing mag. field : "; txt += focusingMagFile_; txt += "\n z-offset for mag. field : "; txt += mixedTools::doubleToString(offsetMag_); txt += "\n scaling factor for mag. field : "; txt += mixedTools::doubleToString(scaleFactor_); return txt; } void elementCell::InputRep(UAPNode* root) { UAPNode* ele = root->addChild("element"); ele->addAttribute("name",specificName_); UAPNode* node = ele->addChild("methods"); node->addChild("tracking")->addAttribute("value","parmela"); string txt = ""; txt = mixedTools::doubleToString(lenghtElem_); ele->addChild("length")->addAttribute("design",txt); node = ele->addChild("aperture"); node->addAttribute("at","ENTRANCE"); node->addAttribute("shape","CIRCLE"); txt = mixedTools::doubleToString(aperture_); node->addChild("xy_limit")->addAttribute("design",txt); node = ele->addChild("linac_cavity"); txt = mixedTools::doubleToString(initialPhase_); node->addChild("phase0")->addAttribute("design",txt); txt = mixedTools::doubleToString(acceleratingField_); node->addChild("gradient")->addAttribute("design",txt); // données propres à Parmela ele->addChild("comment")->addAttribute("text","data specific to Parmela"); txt = mixedTools::doubleToString(phaseStepMax_); ele->addChild("phaseStepMax")->addAttribute("value",txt); txt = acceleratingShapeFile_; ele->addChild("acceleratingShapeField")->addAttribute("name",txt); if ( focusingMagFile_ != "") { txt = focusingMagFile_; ele->addChild("focusingMagneticField")->addAttribute("name",txt); txt = mixedTools::doubleToString(offsetMag_); ele->addChild("z_offset")->addAttribute("value",txt); txt = mixedTools::doubleToString(scaleFactor_); ele->addChild("scaling_factor")->addAttribute("value",txt); } }