[82] | 1 | #include "elementSoleno.h" |
---|
| 2 | #include "mixedTools.h" |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | elementSoleno::elementSoleno() : abstractElement() |
---|
| 6 | { |
---|
[424] | 7 | setDefaultValues(); |
---|
| 8 | setDefaults(); |
---|
| 9 | elementName_ = nomdElements("soleno"); |
---|
| 10 | nbParam_ = elementName_.getElementNbParameters(); |
---|
| 11 | parametersString_ = new string[nbParam_+1]; |
---|
| 12 | // registerAcceptableSoftware(nomDeLogiciel::transport, TBoolOk); |
---|
| 13 | // registerAcceptableSoftware(nomDeLogiciel::parmela, TBoolOk); |
---|
[82] | 14 | } |
---|
| 15 | |
---|
[424] | 16 | void elementSoleno::setDefaultValues() |
---|
| 17 | { |
---|
| 18 | defaultSpecificName_ = "solnd"; |
---|
| 19 | B0Def_ = 0.0; |
---|
| 20 | varyB0Def_ = false; |
---|
| 21 | } |
---|
[82] | 22 | |
---|
[424] | 23 | void elementSoleno::setDefaults() |
---|
| 24 | { |
---|
| 25 | specificName_ = defaultSpecificName_; |
---|
| 26 | B0_ = B0Def_; |
---|
| 27 | varyB0_ = varyB0Def_; |
---|
| 28 | } |
---|
[82] | 29 | |
---|
[424] | 30 | string* elementSoleno::getParametersString() const |
---|
| 31 | { |
---|
| 32 | cout << " passage elementSoleno::getParametersString() B0_= " << B0_ << endl; |
---|
| 33 | int compteur = -1; |
---|
| 34 | parametersString_[++compteur] = mixedTools::intToString(nbParam_); |
---|
| 35 | parametersString_[++compteur] = specificName_; |
---|
| 36 | parametersString_[++compteur] = mixedTools::doubleToString(lenghtElem_); |
---|
| 37 | parametersString_[++compteur] = mixedTools::doubleToString(aperture_); |
---|
| 38 | parametersString_[++compteur] = mixedTools::doubleToString(B0_); |
---|
| 39 | parametersString_[++compteur] = mixedTools::intToString(varyB0_); |
---|
| 40 | if ( compteur != nbParam_ ) { |
---|
| 41 | cerr << " elementSoleno::getParametersString() : ERROR nr pf parameters dosnt match " << endl; |
---|
| 42 | return NULL; |
---|
[82] | 43 | } |
---|
[424] | 44 | return parametersString_; |
---|
| 45 | } |
---|
[82] | 46 | |
---|
[424] | 47 | void elementSoleno::setParametersString(string* param) |
---|
[82] | 48 | { |
---|
[424] | 49 | if ( param == NULL ) { |
---|
| 50 | cerr << " elementSoleno::setParametersString parameters empty parameter set"; |
---|
| 51 | return; |
---|
[225] | 52 | } |
---|
| 53 | int compteur = -1; |
---|
| 54 | int nbparam = atoi(param[++compteur].c_str()); |
---|
[424] | 55 | if ( nbparam != nbParam_ ) { |
---|
| 56 | cerr << " elementSoleno::setParametersString parameters do not match for a SOLENOID"; |
---|
| 57 | return; |
---|
| 58 | } |
---|
| 59 | specificName_ = param[++compteur]; |
---|
| 60 | lenghtElem_ = atof(param[++compteur].c_str()); |
---|
| 61 | aperture_ = atof(param[++compteur].c_str()); |
---|
| 62 | B0_ = atof(param[++compteur].c_str()); |
---|
| 63 | varyB0_ = atoi(param[++compteur].c_str()); |
---|
[82] | 64 | } |
---|
| 65 | |
---|
[418] | 66 | // string elementSoleno::parmelaOutputFlow() const |
---|
| 67 | // { |
---|
| 68 | // ostringstream sortie; |
---|
| 69 | // // on passe l'induction magnetique en Gauss |
---|
| 70 | // sortie << "SOLENOID /l=" << lenghtElem_ << " /aper=" << aperture_ << " /iout=1 /h=" << 1000.*B0_ << endl; |
---|
| 71 | // return sortie.str(); |
---|
| 72 | // } |
---|
[82] | 73 | |
---|
[418] | 74 | // string elementSoleno::transportOutputFlow() const |
---|
| 75 | // { |
---|
| 76 | // ostringstream sortie; |
---|
| 77 | // // on passe la longueur en metres |
---|
| 78 | // sortie << specificName_ << ":" << " SOLENOID, L=" << 0.01*lenghtElem_ << ", B=" << B0_ << ";" << endl; |
---|
| 79 | // if ( varyB0_ ) { |
---|
| 80 | // sortie << " VARY, " << specificName_+"[B]" << ";" << endl; |
---|
| 81 | // } |
---|
| 82 | // return sortie.str(); |
---|
| 83 | // } |
---|
[82] | 84 | |
---|
[488] | 85 | // string elementSoleno::FileOutputFlow() const |
---|
| 86 | // { |
---|
| 87 | // ostringstream sortie; |
---|
| 88 | // // sortie << elementName_.getElementType() << endl; |
---|
| 89 | // sortie << elementName_.getGenericLabel() << endl; |
---|
| 90 | // sortie << specificName_ << endl; |
---|
| 91 | // sortie << lenghtElem_ << " " << aperture_<< " " << B0_ << " " << varyB0_ << endl; |
---|
| 92 | // return sortie.str(); |
---|
| 93 | // } |
---|
[82] | 94 | |
---|
[418] | 95 | |
---|
| 96 | vector< pair<string, vector<string> > > elementSoleno::parametersToSoftware () const { |
---|
| 97 | vector< pair<string, vector<string> > > sortie; |
---|
| 98 | sortie.push_back( pair<string, vector<string> >("labelsGenericSpecific", vector<string>() ) ); |
---|
| 99 | sortie.back().second.push_back(elementName_.getGenericLabel()); |
---|
| 100 | sortie.back().second.push_back(specificName_); |
---|
| 101 | sortie.push_back( pair<string, vector<string> >("lenghtAperture", vector<string>() ) ); |
---|
| 102 | sortie.back().second.push_back(mixedTools::doubleToString(lenghtElem_)); |
---|
| 103 | sortie.back().second.push_back(mixedTools::doubleToString(aperture_)); |
---|
| 104 | sortie.push_back( pair<string, vector<string> >("field", vector<string>() ) ); |
---|
| 105 | sortie.back().second.push_back(mixedTools::doubleToString(B0_)); |
---|
| 106 | sortie.push_back( pair<string, vector<string> >("isBvariable", vector<string>() ) ); |
---|
| 107 | sortie.back().second.push_back(mixedTools::intToString(varyB0_)); |
---|
| 108 | return sortie; |
---|
| 109 | } |
---|
| 110 | |
---|
[488] | 111 | // void elementSoleno::FileInput(ifstream& ifs) |
---|
| 112 | // { |
---|
| 113 | // ifs >> specificName_; |
---|
| 114 | // ifs >> lenghtElem_ >> aperture_ >> B0_ >> varyB0_ ; |
---|
| 115 | // } |
---|
[287] | 116 | |
---|
[424] | 117 | string elementSoleno::print() |
---|
| 118 | { |
---|
| 119 | string txt = ""; |
---|
| 120 | txt += specificName_; |
---|
| 121 | txt += "\nlength (cm) : "; |
---|
| 122 | txt += mixedTools::doubleToString(lenghtElem_); |
---|
| 123 | txt += "\naperture (cm) : "; |
---|
| 124 | txt += mixedTools::doubleToString(aperture_); |
---|
| 125 | txt += "\nfield (kG) : "; |
---|
| 126 | txt += mixedTools::doubleToString(B0_); |
---|
| 127 | txt += "\n : may vary ? "; |
---|
| 128 | txt += mixedTools::boolToString(varyB0_); |
---|
| 129 | return txt; |
---|
| 130 | } |
---|
[287] | 131 | |
---|
[424] | 132 | void elementSoleno::InputRep(UAPNode* root) |
---|
| 133 | { |
---|
[488] | 134 | // UAPNode* ele = root->addChild("element"); |
---|
| 135 | // ele->addAttribute("name",specificName_); |
---|
| 136 | UAPNode* ele = setAMLelementHeader(root); |
---|
[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 | } |
---|
[488] | 160 | |
---|
| 161 | void elementSoleno::FileAMLInput(UAPNode* entree) |
---|
| 162 | { |
---|
| 163 | if ( !checkAMLelementGenericName(entree) ) return; |
---|
| 164 | AMLtools::readAMLParameterAttribut(entree, "length", "design", lenghtElem_); |
---|
| 165 | |
---|
| 166 | UAPNode* ouverture = entree->getChildByName("aperture"); |
---|
| 167 | if ( !ouverture ) { |
---|
| 168 | cout << " elementSoleno::FileAMLInput ERREUR pas de noeud AML <aperture> " << endl; |
---|
| 169 | return; |
---|
| 170 | } |
---|
| 171 | AMLtools::readAMLParameterAttribut(ouverture, "xy_limit", "design", aperture_); |
---|
| 172 | UAPNode* solenoide = entree->getChildByName("solenoid"); |
---|
| 173 | if ( !solenoide ) { |
---|
| 174 | cout << " elementSoleno::FileAMLInput ERREUR pas de noeud AML <solenoide> " << endl; |
---|
| 175 | return; |
---|
| 176 | } |
---|
| 177 | AMLtools::readAMLParameterAttribut(solenoide, "ksol", "design", B0_); |
---|
| 178 | string vrai; |
---|
| 179 | AMLtools::readAMLParameterAttribut(solenoide, "vary", "is_on", vrai); |
---|
| 180 | if ( vrai == string("true")) varyB0_ = true; |
---|
| 181 | else varyB0_ = false; |
---|
| 182 | } |
---|