[84] | 1 | #include "elementBend.h" |
---|
| 2 | #include "mixedTools.h" |
---|
[124] | 3 | #include "mathematicalConstants.h" |
---|
[203] | 4 | #include "PhysicalConstants.h" |
---|
[287] | 5 | |
---|
| 6 | elementBend::elementBend() : abstractElement() |
---|
[84] | 7 | { |
---|
| 8 | setDefaultValues(); |
---|
| 9 | setDefaults(); |
---|
[153] | 10 | elementName_ = nomdElements("bend"); |
---|
[181] | 11 | nbParam_ = elementName_.getElementNbParameters(); |
---|
[84] | 12 | parametersString_ = new string[nbParam_+1]; |
---|
[418] | 13 | // registerAcceptableSoftware(nomDeLogiciel::transport, TBoolOk); |
---|
| 14 | // registerAcceptableSoftware(nomDeLogiciel::parmela, TBoolOk); |
---|
[84] | 15 | } |
---|
| 16 | |
---|
| 17 | void elementBend::setDefaultValues() |
---|
| 18 | { |
---|
[418] | 19 | defaultSpecificName_ = "bend"; |
---|
[84] | 20 | angleDegDef_ = 0.0; |
---|
| 21 | radiusDef_ = 1.0; |
---|
| 22 | beta1Def_ = 0.0; |
---|
| 23 | beta2Def_ = 0.0; |
---|
[202] | 24 | momentumDef_ = 0.0; |
---|
[84] | 25 | } |
---|
| 26 | |
---|
| 27 | void elementBend::setDefaults() |
---|
| 28 | { |
---|
[418] | 29 | specificName_ = defaultSpecificName_; |
---|
[84] | 30 | angleDeg_ = angleDegDef_; |
---|
| 31 | radius_ = radiusDef_; |
---|
| 32 | beta1_ = beta1Def_; |
---|
| 33 | beta2_ = beta2Def_; |
---|
[202] | 34 | momentum_ = momentumDef_; |
---|
[84] | 35 | } |
---|
| 36 | |
---|
| 37 | string* elementBend::getParametersString() const |
---|
| 38 | { |
---|
[225] | 39 | int compteur = -1; |
---|
| 40 | parametersString_[++compteur] = mixedTools::intToString(nbParam_); |
---|
[418] | 41 | parametersString_[++compteur] = specificName_; |
---|
[225] | 42 | parametersString_[++compteur] = mixedTools::doubleToString( angleDeg_); |
---|
| 43 | parametersString_[++compteur] = mixedTools::doubleToString(radius_); |
---|
| 44 | parametersString_[++compteur] = mixedTools::doubleToString(momentum_); |
---|
| 45 | parametersString_[++compteur] = mixedTools::doubleToString(aperture_); |
---|
| 46 | parametersString_[++compteur] = mixedTools::doubleToString(beta1_); |
---|
| 47 | parametersString_[++compteur] = mixedTools::doubleToString(beta2_); |
---|
| 48 | if ( compteur != nbParam_ ) { |
---|
| 49 | cerr << " elementBend::getParametersString() : ERROR nr pf parameters dosnt match " << endl; |
---|
| 50 | return NULL; |
---|
| 51 | } |
---|
[84] | 52 | return parametersString_; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | double elementBend::getLenghtOfElement() const |
---|
| 56 | { |
---|
| 57 | return 1.0e2 * radius_ * angleDeg_ * DEG_TO_RADIANS; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | void elementBend::setParametersString(string* param) |
---|
| 62 | { |
---|
| 63 | if ( param == NULL ) |
---|
| 64 | { |
---|
| 65 | cerr << " elementBend::setParametersString parameters empty parameter set"; |
---|
| 66 | return; |
---|
| 67 | } |
---|
[225] | 68 | |
---|
| 69 | int compteur = -1; |
---|
| 70 | int nbparam = atoi(param[++compteur].c_str()); |
---|
[84] | 71 | if ( nbparam != nbParam_ ) |
---|
| 72 | { |
---|
[202] | 73 | cerr << " elementBend::setParametersString parameters do not match for a BEND" << endl; |
---|
[84] | 74 | return; |
---|
| 75 | } |
---|
[418] | 76 | specificName_ = param[++compteur]; |
---|
[225] | 77 | angleDeg_ = atof(param[++compteur].c_str()); |
---|
| 78 | radius_ = atof(param[++compteur].c_str()); |
---|
| 79 | momentum_ = atof(param[++compteur].c_str()); |
---|
| 80 | aperture_ = atof(param[++compteur].c_str()); |
---|
| 81 | beta1_ = atof(param[++compteur].c_str()); |
---|
| 82 | beta2_ = atof(param[++compteur].c_str()); |
---|
[84] | 83 | // calcul de la longueur : rayon en m ; longueur en cm |
---|
| 84 | lenghtElem_ = getLenghtOfElement(); |
---|
[149] | 85 | cout << " elementBend::setParametersString calcule longueur = " << lenghtElem_ << endl; |
---|
[84] | 86 | } |
---|
| 87 | |
---|
[418] | 88 | // string elementBend::parmelaOutputFlow() const |
---|
| 89 | // { |
---|
| 90 | // ostringstream sortie; |
---|
| 91 | // // il faut entrer l'energie cinetique |
---|
| 92 | // double ecin = momentum_/EREST_MeV; |
---|
| 93 | // ecin = ecin*ecin + 1.; |
---|
| 94 | // ecin = EREST_MeV*(sqrt(ecin) - 1.0); |
---|
| 95 | // sortie << "BEND /l=" << lenghtElem_ << " / aper=" << aperture_ << " / iout=1 / wr=" << ecin << " /alpha=" << angleDeg_ << " / beta1=" << beta1_; |
---|
| 96 | // sortie << " / beta2=" << beta2_ << endl; |
---|
[387] | 97 | |
---|
[418] | 98 | // return sortie.str(); |
---|
| 99 | // } |
---|
[202] | 100 | |
---|
| 101 | |
---|
[418] | 102 | // string elementBend::transportOutputFlow() const |
---|
| 103 | // { |
---|
| 104 | // ostringstream sortie; |
---|
| 105 | // sortie << specificName_ << ":" << " SBEND, RADIUS=" << radius_ << ", ANGLE=" << angleDeg_ << ", E1=" << beta1_ << ", E2=" << beta2_ << ";" << endl; |
---|
| 106 | // return sortie.str(); |
---|
| 107 | // } |
---|
[84] | 108 | |
---|
[202] | 109 | |
---|
[84] | 110 | string elementBend::FileOutputFlow() const |
---|
| 111 | { |
---|
| 112 | ostringstream sortie; |
---|
[181] | 113 | // sortie << elementName_.getElementType() << endl; |
---|
[418] | 114 | sortie << elementName_.getGenericLabel() << endl; |
---|
| 115 | sortie << specificName_ << endl; |
---|
[84] | 116 | sortie << angleDeg_ << " " << radius_ << " " << aperture_ << endl; |
---|
[202] | 117 | sortie << beta1_ << " " << beta2_ << " " << momentum_ << endl; |
---|
[84] | 118 | return sortie.str(); |
---|
| 119 | } |
---|
| 120 | |
---|
[418] | 121 | vector< pair<string, vector<string> > > elementBend::parametersToSoftware () const{ |
---|
| 122 | vector< pair<string, vector<string> > > sortie; |
---|
| 123 | sortie.push_back( pair<string, vector<string> >("labelsGenericSpecific", vector<string>() ) ); |
---|
| 124 | sortie.back().second.push_back(elementName_.getGenericLabel()); |
---|
| 125 | sortie.back().second.push_back(specificName_); |
---|
| 126 | sortie.push_back( pair<string, vector<string> >("lenghtAperture", vector<string>() ) ); |
---|
| 127 | sortie.back().second.push_back(mixedTools::doubleToString( lenghtElem_)); |
---|
| 128 | sortie.back().second.push_back(mixedTools::doubleToString( aperture_)); |
---|
| 129 | sortie.push_back( pair<string, vector<string> >("angleDegre", vector<string>() ) ); |
---|
| 130 | sortie.back().second.push_back(mixedTools::doubleToString( angleDeg_)); |
---|
| 131 | sortie.push_back( pair<string, vector<string> >("radius", vector<string>() ) ); |
---|
| 132 | sortie.back().second.push_back(mixedTools::doubleToString( radius_)); |
---|
| 133 | sortie.push_back( pair<string, vector<string> >("rotatedFaces", vector<string>() ) ); |
---|
| 134 | sortie.back().second.push_back(mixedTools::doubleToString( beta1_)); |
---|
| 135 | sortie.back().second.push_back(mixedTools::doubleToString( beta2_)); |
---|
| 136 | sortie.push_back( pair<string, vector<string> >("momentum", vector<string>() ) ); |
---|
| 137 | sortie.back().second.push_back(mixedTools::doubleToString( momentum_)); |
---|
| 138 | return sortie; |
---|
| 139 | } |
---|
| 140 | |
---|
[84] | 141 | void elementBend::FileInput(ifstream& ifs) |
---|
| 142 | { |
---|
[418] | 143 | ifs >> specificName_; |
---|
[84] | 144 | ifs >> angleDeg_ >> radius_ >> aperture_; |
---|
[202] | 145 | ifs >> beta1_ >> beta2_ >> momentum_; |
---|
[149] | 146 | lenghtElem_ = getLenghtOfElement(); |
---|
| 147 | cout << " elementBend::FileInput calcule longueur = " << lenghtElem_ << endl; |
---|
[84] | 148 | } |
---|
[287] | 149 | |
---|
| 150 | |
---|
| 151 | string elementBend::print() { |
---|
| 152 | string txt = ""; |
---|
| 153 | |
---|
[418] | 154 | txt += specificName_; |
---|
[287] | 155 | txt += "\nangle (deg.) : "; |
---|
| 156 | txt += mixedTools::doubleToString(angleDeg_); |
---|
| 157 | txt += "\nradius (m) : "; |
---|
| 158 | txt += mixedTools::doubleToString(radius_); |
---|
| 159 | txt += "\nmomentum (MeV/c) : "; |
---|
| 160 | txt += mixedTools::doubleToString(momentum_); |
---|
| 161 | txt += "\nlength (cm) : "; |
---|
| 162 | txt += mixedTools::doubleToString(lenghtElem_); |
---|
| 163 | txt += "\naperture (cm) : "; |
---|
| 164 | txt += mixedTools::doubleToString(aperture_); |
---|
| 165 | txt += "\npole face rotations (deg.) entrance : "; |
---|
| 166 | txt += mixedTools::doubleToString(beta1_); |
---|
| 167 | txt += "\nexit : "; |
---|
| 168 | txt += mixedTools::doubleToString(beta2_); |
---|
| 169 | |
---|
| 170 | return txt; |
---|
| 171 | } |
---|