[82] | 1 | #include "elementSoleno.h" |
---|
| 2 | #include "mixedTools.h" |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | elementSoleno::elementSoleno() : abstractElement() |
---|
| 6 | { |
---|
[424] | 7 | cout << " passage constructeur elementSoleno " << endl; |
---|
| 8 | setDefaultValues(); |
---|
| 9 | setDefaults(); |
---|
| 10 | elementName_ = nomdElements("soleno"); |
---|
| 11 | nbParam_ = elementName_.getElementNbParameters(); |
---|
| 12 | parametersString_ = new string[nbParam_+1]; |
---|
| 13 | // registerAcceptableSoftware(nomDeLogiciel::transport, TBoolOk); |
---|
| 14 | // registerAcceptableSoftware(nomDeLogiciel::parmela, TBoolOk); |
---|
[82] | 15 | } |
---|
| 16 | |
---|
[424] | 17 | void elementSoleno::setDefaultValues() |
---|
| 18 | { |
---|
| 19 | defaultSpecificName_ = "solnd"; |
---|
| 20 | B0Def_ = 0.0; |
---|
| 21 | varyB0Def_ = false; |
---|
| 22 | } |
---|
[82] | 23 | |
---|
[424] | 24 | void elementSoleno::setDefaults() |
---|
| 25 | { |
---|
| 26 | specificName_ = defaultSpecificName_; |
---|
| 27 | B0_ = B0Def_; |
---|
| 28 | varyB0_ = varyB0Def_; |
---|
| 29 | } |
---|
[82] | 30 | |
---|
[424] | 31 | string* elementSoleno::getParametersString() const |
---|
| 32 | { |
---|
| 33 | cout << " passage elementSoleno::getParametersString() B0_= " << B0_ << endl; |
---|
| 34 | int compteur = -1; |
---|
| 35 | parametersString_[++compteur] = mixedTools::intToString(nbParam_); |
---|
| 36 | parametersString_[++compteur] = specificName_; |
---|
| 37 | parametersString_[++compteur] = mixedTools::doubleToString(lenghtElem_); |
---|
| 38 | parametersString_[++compteur] = mixedTools::doubleToString(aperture_); |
---|
| 39 | parametersString_[++compteur] = mixedTools::doubleToString(B0_); |
---|
| 40 | parametersString_[++compteur] = mixedTools::intToString(varyB0_); |
---|
| 41 | if ( compteur != nbParam_ ) { |
---|
| 42 | cerr << " elementSoleno::getParametersString() : ERROR nr pf parameters dosnt match " << endl; |
---|
| 43 | return NULL; |
---|
[82] | 44 | } |
---|
[424] | 45 | return parametersString_; |
---|
| 46 | } |
---|
[82] | 47 | |
---|
[424] | 48 | void elementSoleno::setParametersString(string* param) |
---|
[82] | 49 | { |
---|
[424] | 50 | if ( param == NULL ) { |
---|
| 51 | cerr << " elementSoleno::setParametersString parameters empty parameter set"; |
---|
| 52 | return; |
---|
[225] | 53 | } |
---|
| 54 | int compteur = -1; |
---|
| 55 | int nbparam = atoi(param[++compteur].c_str()); |
---|
[424] | 56 | if ( nbparam != nbParam_ ) { |
---|
| 57 | cerr << " elementSoleno::setParametersString parameters do not match for a SOLENOID"; |
---|
| 58 | return; |
---|
| 59 | } |
---|
| 60 | specificName_ = param[++compteur]; |
---|
| 61 | lenghtElem_ = atof(param[++compteur].c_str()); |
---|
| 62 | aperture_ = atof(param[++compteur].c_str()); |
---|
| 63 | B0_ = atof(param[++compteur].c_str()); |
---|
| 64 | varyB0_ = atoi(param[++compteur].c_str()); |
---|
[82] | 65 | } |
---|
| 66 | |
---|
[418] | 67 | // string elementSoleno::parmelaOutputFlow() const |
---|
| 68 | // { |
---|
| 69 | // ostringstream sortie; |
---|
| 70 | // // on passe l'induction magnetique en Gauss |
---|
| 71 | // sortie << "SOLENOID /l=" << lenghtElem_ << " /aper=" << aperture_ << " /iout=1 /h=" << 1000.*B0_ << endl; |
---|
| 72 | // return sortie.str(); |
---|
| 73 | // } |
---|
[82] | 74 | |
---|
[418] | 75 | // string elementSoleno::transportOutputFlow() const |
---|
| 76 | // { |
---|
| 77 | // ostringstream sortie; |
---|
| 78 | // // on passe la longueur en metres |
---|
| 79 | // sortie << specificName_ << ":" << " SOLENOID, L=" << 0.01*lenghtElem_ << ", B=" << B0_ << ";" << endl; |
---|
| 80 | // if ( varyB0_ ) { |
---|
| 81 | // sortie << " VARY, " << specificName_+"[B]" << ";" << endl; |
---|
| 82 | // } |
---|
| 83 | // return sortie.str(); |
---|
| 84 | // } |
---|
[82] | 85 | |
---|
| 86 | string elementSoleno::FileOutputFlow() const |
---|
[424] | 87 | { |
---|
| 88 | ostringstream sortie; |
---|
| 89 | // sortie << elementName_.getElementType() << endl; |
---|
| 90 | sortie << elementName_.getGenericLabel() << endl; |
---|
| 91 | sortie << specificName_ << endl; |
---|
| 92 | sortie << lenghtElem_ << " " << aperture_<< " " << B0_ << " " << varyB0_ << endl; |
---|
| 93 | return sortie.str(); |
---|
| 94 | } |
---|
[82] | 95 | |
---|
[418] | 96 | |
---|
| 97 | vector< pair<string, vector<string> > > elementSoleno::parametersToSoftware () const { |
---|
| 98 | vector< pair<string, vector<string> > > sortie; |
---|
| 99 | sortie.push_back( pair<string, vector<string> >("labelsGenericSpecific", vector<string>() ) ); |
---|
| 100 | sortie.back().second.push_back(elementName_.getGenericLabel()); |
---|
| 101 | sortie.back().second.push_back(specificName_); |
---|
| 102 | sortie.push_back( pair<string, vector<string> >("lenghtAperture", vector<string>() ) ); |
---|
| 103 | sortie.back().second.push_back(mixedTools::doubleToString(lenghtElem_)); |
---|
| 104 | sortie.back().second.push_back(mixedTools::doubleToString(aperture_)); |
---|
| 105 | sortie.push_back( pair<string, vector<string> >("field", vector<string>() ) ); |
---|
| 106 | sortie.back().second.push_back(mixedTools::doubleToString(B0_)); |
---|
| 107 | sortie.push_back( pair<string, vector<string> >("isBvariable", vector<string>() ) ); |
---|
| 108 | sortie.back().second.push_back(mixedTools::intToString(varyB0_)); |
---|
| 109 | return sortie; |
---|
| 110 | } |
---|
| 111 | |
---|
[82] | 112 | void elementSoleno::FileInput(ifstream& ifs) |
---|
| 113 | { |
---|
[418] | 114 | ifs >> specificName_; |
---|
[229] | 115 | ifs >> lenghtElem_ >> aperture_ >> B0_ >> varyB0_ ; |
---|
[82] | 116 | } |
---|
[287] | 117 | |
---|
[424] | 118 | string elementSoleno::print() |
---|
| 119 | { |
---|
| 120 | string txt = ""; |
---|
| 121 | txt += specificName_; |
---|
| 122 | txt += "\nlength (cm) : "; |
---|
| 123 | txt += mixedTools::doubleToString(lenghtElem_); |
---|
| 124 | txt += "\naperture (cm) : "; |
---|
| 125 | txt += mixedTools::doubleToString(aperture_); |
---|
| 126 | txt += "\nfield (kG) : "; |
---|
| 127 | txt += mixedTools::doubleToString(B0_); |
---|
| 128 | txt += "\n : may vary ? "; |
---|
| 129 | txt += mixedTools::boolToString(varyB0_); |
---|
| 130 | return txt; |
---|
| 131 | } |
---|
[287] | 132 | |
---|
[424] | 133 | void elementSoleno::InputRep(UAPNode* root) |
---|
| 134 | { |
---|
| 135 | UAPNode* ele = root->addChild("element"); |
---|
| 136 | ele->addAttribute("name",specificName_); |
---|
[287] | 137 | |
---|
[424] | 138 | string txt = ""; |
---|
| 139 | txt = mixedTools::doubleToString(lenghtElem_); |
---|
| 140 | ele->addChild("length")->addAttribute("design",txt); |
---|
| 141 | |
---|
| 142 | // pour Parmela /aper : radius of aperture at exit (gap) |
---|
| 143 | UAPNode* node = ele->addChild("aperture"); |
---|
| 144 | node->addAttribute("at","EXIT"); |
---|
| 145 | node->addAttribute("shape","CIRCLE"); |
---|
| 146 | txt = mixedTools::doubleToString(aperture_); |
---|
| 147 | node->addChild("xy_limit")->addAttribute("design",txt); |
---|
| 148 | |
---|
| 149 | node = ele->addChild("solenoid"); |
---|
| 150 | txt = mixedTools::doubleToString(B0_); |
---|
| 151 | node->addChild("ksol")->addAttribute("design",txt); |
---|
| 152 | |
---|
| 153 | // faire varier ou pas l'induction pour l'ajuster |
---|
| 154 | if ( varyB0_ ) { |
---|
| 155 | node->addChild("vary")->addAttribute("is_on","true"); |
---|
| 156 | } else { |
---|
| 157 | node->addChild("vary")->addAttribute("is_on","false"); |
---|
| 158 | } |
---|
[287] | 159 | } |
---|