Commit 4ac0cfc3 authored by TOUZE Francois's avatar TOUZE Francois
Browse files

rendre possible plusieurs calculs de Tunes en fonction de differents parametres

parent 9b98eaac
...@@ -179,6 +179,42 @@ void computingBlock::emittAMLInput() ...@@ -179,6 +179,42 @@ void computingBlock::emittAMLInput()
return; return;
} }
std::vector<smap> computingBlock::tunesAMLInput( UAPNode* up )
{
if(debug > 0) cout << "computingBlock::tunesAMLInput()\n";
std::vector<smap> v;
if( !up ) return v;
smap amap;
NodeVec jnode= up->getChildrenByName("scan");
int jkey= 0;
for(unsigned k = 0; k < jnode.size(); ++k)
{
string key= mixedTools::intToString( jkey );
UAPNode* child= jnode[k];
amap[ key ].push_back( child->getAttributeString("option") );
amap[ key ].push_back( child->getAttributeString("range") );
amap[ key ].push_back( child->getAttributeString("start") );
amap[ key ].push_back( child->getAttributeString("points") );
jkey++;
}
v.push_back( amap); // v[0]
if( !amap.empty() ) amap.clear();
string str= "0";
AMLtools::readAMLParameterAttribut(up,"INTQx","design",str);
amap["INTQx"].push_back( str );
str= "0";
AMLtools::readAMLParameterAttribut(up,"INTQy","design",str);
amap["INTQy"].push_back( str );
v.push_back( amap); // v[1]
return v;
}
/* ****************************************
std::vector<smap> computingBlock::tunesAMLInput( UAPNode* up ) std::vector<smap> computingBlock::tunesAMLInput( UAPNode* up )
{ {
if(debug > 0) cout << "computingBlock::tunesAMLInput()\n"; if(debug > 0) cout << "computingBlock::tunesAMLInput()\n";
...@@ -212,6 +248,7 @@ std::vector<smap> computingBlock::tunesAMLInput( UAPNode* up ) ...@@ -212,6 +248,7 @@ std::vector<smap> computingBlock::tunesAMLInput( UAPNode* up )
return v; return v;
} }
******************************** */
std::vector<smap> computingBlock::twissAMLInput( UAPNode* nde ) std::vector<smap> computingBlock::twissAMLInput( UAPNode* nde )
{ {
...@@ -872,6 +909,25 @@ void computingBlock::toJSON(json& j) ...@@ -872,6 +909,25 @@ void computingBlock::toJSON(json& j)
if( action == "track" ) jtrackOutput( j["parameters"],v ); if( action == "track" ) jtrackOutput( j["parameters"],v );
if( action == "match" ) jmatchOutput( j["parameters"],v ); if( action == "match" ) jmatchOutput( j["parameters"],v );
if( action == "tunes" ) jtunesOutput( j["parameters"],v ); if( action == "tunes" ) jtunesOutput( j["parameters"],v );
// cout << j["parameters"].dump(4) << endl;
// auto it_z1= j.find( "parameters" );
// std::cout << std::boolalpha;
// std::cout << "\"parameters\" was found: " << (it_z1 != j.end()) << '\n';
// auto it_z2= it_z1->find( "tunesOption" );
// std::cout << "\"tunesOption\" was found: " << (it_z2 != it_z1->end()) << '\n';
// for (json::iterator it = it_z2->begin(); it != it_z2->end(); ++it) {
// std::cout << *it << '\n';
// }
// for (auto& key : *it_z1->find( "tunesOption" )) {
// std::cout << key << '\n';
// if (key == "tuneBetasAlfas") {
// auto it = it_z1->find("scan1");
// string range = it->find( "range" ).value();
// std::cout << range << '\n';
// }
// }
} }
void computingBlock::jtwissOutput(json& j,const vector<smap>& v) void computingBlock::jtwissOutput(json& j,const vector<smap>& v)
...@@ -1032,6 +1088,52 @@ void computingBlock::jtrackOutput(json& j,const vector<smap>& v) ...@@ -1032,6 +1088,52 @@ void computingBlock::jtrackOutput(json& j,const vector<smap>& v)
} }
} }
void computingBlock::jtunesOutput(json& j,const vector<smap>& v)
{
if (debug > 0) cout << "computingBlock::jtunesOutput()\n";
cout << "computingBlock::jtunesOutput()\n";
if( !v[ 0 ].empty() ) {
for(int k = 0; k < v[ 0 ].size(); ++k)
{
smap::const_iterator it= v[ 0 ].find( mixedTools::intToString(k) );
if( it == v[ 0 ].end() ) continue;
string key= it->second.at(0);
// **** TUNES, BETAS AND ALFAS @ SS CENTRE Vs ENERGY DEVIATION
if( key.find("1") != string::npos ) {
j["tunesOption"].push_back( "tuneBetasAlfas" );
j["scan1"]["range"] = it->second.at(1);
j["scan1"]["start"] = it->second.at(2);
j["scan1"]["points"]= it->second.at(3);
}
// **** TUNES Vs X POSITIONS ****
if( key.find("2") != string::npos ) {
j["tunesOption"].push_back( "tunesXPositions" );
j["scan2"]["range"] = it->second.at(1);
j["scan2"]["start"] = it->second.at(2);
j["scan2"]["points"]= it->second.at(3);
}
// **** TUNES Vs Y POSITIONS ****
if( key.find("3") != string::npos ) {
j["tunesOption"].push_back( "tunesYPositions" );
j["scan3"]["range"] = it->second.at(1);
j["scan3"]["start"] = it->second.at(2);
j["scan3"]["points"]= it->second.at(3);
}
}
}
if( !v[ 1 ].empty() ) {
j["shift"]["inqX"]= v[ 1 ].find("INTQx")->second.at(0);
j["shift"]["inqY"]= v[ 1 ].find("INTQy")->second.at(0);
}
}
/* *******************************************
void computingBlock::jtunesOutput(json& j,const vector<smap>& v) void computingBlock::jtunesOutput(json& j,const vector<smap>& v)
{ {
string str= v[0].find("tunes_option")->second.at(0); string str= v[0].find("tunes_option")->second.at(0);
...@@ -1079,6 +1181,7 @@ void computingBlock::jtunesOutput(json& j,const vector<smap>& v) ...@@ -1079,6 +1181,7 @@ void computingBlock::jtunesOutput(json& j,const vector<smap>& v)
j["scan"]["inqY"]= nullptr; j["scan"]["inqY"]= nullptr;
} }
} }
************************* */
void computingBlock::jmatchOutput(json& j,const vector<smap>& v) void computingBlock::jmatchOutput(json& j,const vector<smap>& v)
{ {
...@@ -1544,6 +1647,66 @@ std::vector<smap> computingBlock::jtwissInput(json j) ...@@ -1544,6 +1647,66 @@ std::vector<smap> computingBlock::jtwissInput(json j)
return v; return v;
} }
std::vector<smap> computingBlock::jtunesInput(json j)
{
if (debug > 0) cout << "computingBlock::jtunesInput()\n";
auto up= j.find( "parameters" );
if (debug > 0) cout << up->dump(4) << endl;
smap amap;
for (auto& key : *up->find( "tunesOption" ))
{
json::iterator z;
if (key == "tuneBetasAlfas") z= up->find("scan1");
if (key == "tunesXPositions") z= up->find("scan2");
if (key == "tunesYPositions") z= up->find("scan3");
json::iterator it= z->find("range");
if (it->is_null()) continue;
string s1= it.value();
json::iterator jt= z->find("start");
if (jt->is_null()) continue;
string s2= jt.value();
json::iterator kt= z->find("points");
if (kt->is_null()) continue;
string s3= kt.value();
if (!s1.length() || !s2.length() || !s3.length()) continue;
amap[ key ].push_back( it.value() );
amap[ key ].push_back( jt.value() );
amap[ key ].push_back( kt.value() );
}
std::vector<smap> v;
v.push_back( amap );
if( !amap.empty() ) amap.clear();
auto z= up->find( "shift" );
json::iterator it= z->find( "inqX" );
if (it->is_null()) {
amap[ "INTQx" ].push_back( "0.0" );
} else {
string s1= it.value();
if (!s1.length()) amap[ "INTQx" ].push_back( "0.0" );
else amap[ "INTQx" ].push_back( s1 );
}
json::iterator jt= z->find( "inqY" );
if (jt->is_null()) {
amap[ "INTQy" ].push_back( "0.0" );
} else {
string s2= jt.value();
if (!s2.length()) amap[ "INTQy" ].push_back( "0.0" );
else amap[ "INTQy" ].push_back( s2 );
}
v.push_back( amap );
return v;
}
/* *****************************************************
std::vector<smap> computingBlock::jtunesInput(json j) std::vector<smap> computingBlock::jtunesInput(json j)
{ {
if (debug > 0) cout << "computingBlock::jtunesInput()\n"; if (debug > 0) cout << "computingBlock::jtunesInput()\n";
...@@ -1583,6 +1746,7 @@ std::vector<smap> computingBlock::jtunesInput(json j) ...@@ -1583,6 +1746,7 @@ std::vector<smap> computingBlock::jtunesInput(json j)
return v; return v;
} }
********************** */
std::vector<smap> computingBlock::jmatchInput(json j) std::vector<smap> computingBlock::jmatchInput(json j)
{ {
......
...@@ -140,42 +140,54 @@ string softwareMadx::tunesStatement(const std::vector<smap>& v) ...@@ -140,42 +140,54 @@ string softwareMadx::tunesStatement(const std::vector<smap>& v)
if(debug > 0) cout << "last element = " << label << endl; if(debug > 0) cout << "last element = " << label << endl;
ostringstream os; ostringstream os;
os << "u0= " << v[1].find("start")->second.at(0) << ";\n"; os << "\n";
os << "KMax= " << v[1].find("points")->second.at(0) << ";\n"; string s1= v[ 1 ].find("INTQx")->second.at(0);
os << "du= " << v[1].find("range")->second.at(0) << "/KMax;\n"; if (s1.empty()) os << "INTQx= 0.0" << ";\n";
os << "INTQx= " << v[2].find("INTQx")->second.at(0) << ";\n"; else os << "INTQx= " << s1 << ";\n";
os << "INTQy= " << v[2].find("INTQy")->second.at(0) << ";\n"; string s2= v[ 1 ].find("INTQy")->second.at(0);
if (s2.empty()) os << "INTQy= 0.0" << ";\n";
string key= v[0].find("tunes_option")->second.at(0); else os << "INTQy= " << s2<< ";\n";
if (key.find("option 1") != string::npos) { os << "\n";
smap::const_iterator kt;
kt= v[ 0 ].find("tuneBetasAlfas");
if (kt != v[ 0 ].end()) {
os << "create,table=T1,column= dp,Qx,Qy,bx,by,ax,ay;\n"; os << "create,table=T1,column= dp,Qx,Qy,bx,by,ax,ay;\n";
// Qx/Qy = horizontal/vertical tune versus DELTAP // Qx/Qy = horizontal/vertical tune versus DELTAP
os << "Qx:= table(summ,Q1) - INTQx;\n"; os << "Qx:= table(summ,Q1) - INTQx;\n";
os << "Qy:= table(summ,Q2) - INTQy;\n"; os << "Qy:= table(summ,Q2) - INTQy;\n";
// bx/by = amplitude functions beta versus DELTAP // bx/by = amplitude functions beta versus DELTAP
os << "bx:= table(twiss," << label << ",betx);\n"; os << "bx:= table(twiss," << label << ",betx);\n";
os << "by:= table(twiss," << label << ",bety);\n"; os << "by:= table(twiss," << label << ",bety);\n";
// ax/ay = correlation function alpha versus DELTAP // ax/ay = correlation function alpha versus DELTAP
os << "ax:= table(twiss," << label << ",alfx);\n"; os << "ax:= table(twiss," << label << ",alfx);\n";
os << "ay:= table(twiss," << label << ",alfy);\n\n"; os << "ay:= table(twiss," << label << ",alfy);\n\n";
os << "k= 0;\n";
os << "while (k <= KMAX)\n";
os << "{\n";
os << " dp= u0 + k*du;\n";
os << " twiss, deltap= dp;\n";
os << " fill,table= T1;\n";
os << " k= k+1;\n";
os << "}\n";
// creates the table => xxx-Etunes.txt
os << "write,table=T1,file=" + getFileName("Etunes",true) << ";\n";
} else if (key.find("option 2") != string::npos ) {
os << "u0= " << kt->second.at(1) << ";\n";
os << "KMax= " << kt->second.at(2) << ";\n";
os << "du= " << kt->second.at(0) << "/KMax;\n";
os << "k= 0;\n";
os << "while (k <= KMAX)\n";
os << "{\n";
os << " dp= u0 + k*du;\n";
os << " twiss, deltap= dp;\n";
os << " fill,table= T1;\n";
os << " k= k+1;\n";
os << "}\n";
// creates the table => xxx-Etunes.txt
os << "write,table=T1,file=" + getFileName("Etunes",true) << ";\n\n";
}
kt= v[ 0 ].find("tunesXPositions");
if (kt != v[ 0 ].end()) {
os << "create,table=T2,column= uk,Qx,Qy;\n"; os << "create,table=T2,column= uk,Qx,Qy;\n";
// tunes versus x position // tunes versus x position
os << "Qx:= table(summ,Q1) - INTQx;\n"; os << "Qx:= table(summ,Q1) - INTQx;\n";
os << "Qy:= table(summ,Q2) - INTQy;\n"; os << "Qy:= table(summ,Q2) - INTQy;\n\n";
os << "u0= " << kt->second.at(1) << ";\n";
os << "KMax= " << kt->second.at(2) << ";\n";
os << "du= " << kt->second.at(0) << "/KMax;\n";
os << "k= 0;\n"; os << "k= 0;\n";
os << "while (k <= KMAX)\n"; os << "while (k <= KMAX)\n";
os << "{\n"; os << "{\n";
...@@ -186,13 +198,18 @@ string softwareMadx::tunesStatement(const std::vector<smap>& v) ...@@ -186,13 +198,18 @@ string softwareMadx::tunesStatement(const std::vector<smap>& v)
os << "}\n"; os << "}\n";
// creates the table => xxx-Xtunes.txt // creates the table => xxx-Xtunes.txt
os << "write,table=T2,file=" + getFileName("Xtunes",true) << ";\n"; os << "write,table=T2,file=" + getFileName("Xtunes",true) << ";\n";
}
} else if (key.find("option 3") != string::npos ) {
kt= v[ 0 ].find("tunesYPositions");
if (kt != v[ 0 ].end()) {
os << "create,table=T3,column= uk,Qx,Qy;\n"; os << "create,table=T3,column= uk,Qx,Qy;\n";
// tunes versus y position // tunes versus y position
os << "Qx:= table(summ,Q1) - INTQx;\n"; os << "Qx:= table(summ,Q1) - INTQx;\n";
os << "Qy:= table(summ,Q2) - INTQy;\n"; os << "Qy:= table(summ,Q2) - INTQy;\n\n";
os << "u0= " << kt->second.at(1) << ";\n";
os << "KMax= " << kt->second.at(2) << ";\n";
os << "du= " << kt->second.at(0) << "/KMax;\n";
os << "k= 0;\n"; os << "k= 0;\n";
os << "while (k <= KMAX)\n"; os << "while (k <= KMAX)\n";
os << "{\n"; os << "{\n";
...@@ -203,143 +220,11 @@ string softwareMadx::tunesStatement(const std::vector<smap>& v) ...@@ -203,143 +220,11 @@ string softwareMadx::tunesStatement(const std::vector<smap>& v)
os << "}\n"; os << "}\n";
// creates the table => xxx-Ytunes.txt // creates the table => xxx-Ytunes.txt
os << "write,table=T3,file=" + getFileName("Ytunes",true) << ";\n"; os << "write,table=T3,file=" + getFileName("Ytunes",true) << ";\n";
} else {
cout << "ERROR in softwareMadx::tunesStatements option= " << key << " not defined\n";
return string();
} }
return os.str(); return os.str();
} }
/**
string softwareMadx::tunesStatement(const std::vector<smap>& v)
{
if(debug > 0) cout << "softwareMadx::tunesStatement()\n";
ostringstream os;
// accesses value for last element
abstractElement* elPtr;
elPtr= getComputingBlock()->getLastElement();
string label= elPtr->getLabel();
if(debug > 0) cout << "last element = " << label << endl;
string str= v[0].find("tunes_option")->second.at(0);
if( str.find("option 1") != string::npos ) {
// optical functions versus DELTAP at the end of the beam line expanded by USE
// Qx/Qy = horizontal/vertical tune
// bx/by = amplitude functions beta
// ax/ay = correlation function alpha
os<< "create, table=Etunes, column= z,Qx,Qy,bx,by,ax,ay;\n";
} else if( str.find("option 2") != string::npos ) {
// tunes versus x position at the end of the beam line expanded by USE
os<< "create, table=Xtunes, column= z,Qx,Qy;\n";
} else if( str.find("option 3") != string::npos ) {
// tunes versus y position at the end of the beam line expanded by USE
os<< "create, table=Ytunes, column= z,Qx,Qy;\n";
} else {
cout << "ERROR in softwareMadx::tunesStatements option= " << str << " not defined\n";
return string();
}
string tx= v[2].find("INTQx")->second.at(0);
os << "INTQx:= " << tx << ";\n";
tx= v[2].find("INTQy")->second.at(0);
os << "INTQy:= " << tx << ";\n";
os<< "u0 = " << v[1].find("start")->second.at(0) << ";\n";
os<< "KMax = " << v[1].find("points")->second.at(0) << ";\n";
os<< "du = " << v[1].find("range")->second.at(0) << "/KMax;\n";
os<< "k= 0;\n";
os<< "while (k <= KMAX)\n";
os<< "{\n";
os<< " uk = u0 + k*du;\n";
// **** TUNES, BETAS AND ALFAS @ SS CENTRE Vs ENERGY DEVIATION
if( str.find("option 1") != string::npos ) {
os<< " twiss, deltap= uk;\n";
os<< " z = 100*uk;\n";
os<< " Qx = table(twiss," << label << ",mux) - INTQx;\n";
os<< " Qy = table(twiss," << label << ",muy) - INTQy;\n";
os<< " bx = table(twiss," << label << ",betx);\n";
os<< " by = table(twiss," << label << ",bety);\n";
os<< " ax = table(twiss," << label << ",alfx);\n";
os<< " ay = table(twiss," << label << ",alfy);\n";
os<< " if (bx > 1e-100 && by > 1e-100) {\n";
os<< " fill,table = Etunes;\n";
os<< " }\n";
}
// **** TUNES Vs X POSITIONS ****
if( str.find("option 2") != string::npos ) {
os<< " twiss, x= uk;\n";
os<< " z = 1000*uk;\n";
os<< " Qx = table(twiss," << label << ",mux) - INTQx;\n";
os<< " Qy = table(twiss," << label << ",muy) - INTQy;\n";
os<< " if (Qx < 1 && Qy < 1) {\n";
os<< " fill,table = Xtunes;\n";
os<< " }\n";
}
// **** TUNES Vs Y POSITIONS ****
if( str.find("option 3") != string::npos ) {
os<< " twiss, y= uk;\n";
os<< " z = 1000*uk;\n";
os<< " Qx = table(twiss," << label << ",mux) - INTQx;\n";
os<< " Qy = table(twiss," << label << ",muy) - INTQy;\n";
os<< " if (Qx < 1 && Qy < 1) {\n";
os<< " fill,table = Ytunes;\n";
os<< " }\n";
}
os<< " k = k+1;\n";
os<< "};\n";
// plots
char ch1= '"';
string str1= string(&ch1,1);
if( str.find("option 1") != string::npos ) {
// creates the TUNES table => xxx-Etunes.txt
os << "write, table=Etunes, file= " + getFileName("Etunes",true) << ";\n";
os << "plot, table=Etunes, haxis=z, vaxis1=Qx, vaxis2=Qy, style=100, symbol=4, title=" << str1+"Tunes Vs Dp/p [%]"+str1 << ", noversion,file= " + setPlotsFile() << ";\n";
os << "plot, table=Etunes, haxis=z, vaxis1=bx, vaxis2=by, style=100, symbol=4, title=" << str1+"Beta Vs Dp/p [%], SS centre"+str1 << ", noversion;\n";
os << "plot, table=Etunes, haxis=z, vaxis1=ax, vaxis2=ay, style=100, symbol=4, title=" << str1+"Alfa Vs Dp/p [%], SS centre"+str1 << ", noversion;\n";
}
if( str.find("option 2") != string::npos ) {
// creates the XTUNES table => xxx-Xtunes.txt
os << "write, table=Xtunes, file= "+getFileName("Xtunes",true) << ";\n";
os << "plot, table=Xtunes, haxis=z, vaxis1=Qx, vaxis2=Qy, style=100, symbol=4, title=" << str1+"Tunes Vs X position [mm]"+str1 << ", noversion, file= " + setPlotsFile() << ";\n";
}
if( str.find("option 3") != string::npos ) {
// creates the YTUNES table => xxx-Ytunes.txt
os << "write, table=Ytunes, file= "+getFileName("Ytunes",true) << ";\n";
os << "plot, table=Ytunes, haxis=z, vaxis1=Qx, vaxis2=Qy, style=100, symbol=4, title=" << str1+"Tunes Vs Y position [mm]"+str1 << ", noversion, file= " + setPlotsFile() << ";\n";
}
return os.str();
}
*/
string softwareMadx::twissStatement(const std::vector<smap>& v) string softwareMadx::twissStatement(const std::vector<smap>& v)
......
...@@ -4,8 +4,9 @@ ...@@ -4,8 +4,9 @@
<div id="computing-menu" class="border-bottom border-light d-flex flex-row justify-content-between"> <div id="computing-menu" class="border-bottom border-light d-flex flex-row justify-content-between">
<div id="computing-title"> <div id="computing-title">
<h2 @click="showConfig">Settings</h2> <h2 @click="showConfig">Plots</h2>
<span class="ml-3" @click="showPlots">Plots</span> <!--span class="ml-3" @click="showPlots">Plots</span-->
</div> </div>
</div> </div>
...@@ -88,11 +89,13 @@ ...@@ -88,11 +89,13 @@
</div> </div>
<div class="d-flex flex-row justify-content-between mb-3"> <div class="d-flex flex-row justify-content-between mb-3">
<button size="md" type="button" class="white-button ml-4"> <button size="md" type="button" class="white-button ml-4">
<router-link to="/Simulate">Back to simulate</router-link> <router-link to="/Simulate">Back to simulate</router-link>
</button> </button>
<button size="md" type="button" id="start-simulation" class="btn new-sector border border-success text-white bg-success mr-4" @click="showPlots" v-if="isDraw">Draw
</button> <button size="md" type="button" id="start-simulation" class="btn new-sector border border-success text-white bg-success mr-4" @click="showPlots" v-if="isDraw">Draw</button>
<!--<b-button size="md"w type="button" id="start-simulation" class="btn new-sector border border-success text-white bg-success mr-4" v-on:click="showConsole" v-if="isSimulationSucceed">Analyze outputs</b-button>--> <!--<b-button size="md"w type="button" id="start-simulation" class="btn new-sector border border-success text-white bg-success mr-4" v-on:click="showConsole" v-if="isSimulationSucceed">Analyze outputs</b-button>-->
</div> </div>
</div> </div>
...@@ -249,8 +252,8 @@ label { ...@@ -249,8 +252,8 @@ label {
line-height: 50px; line-height: 50px;
} }
button {
width: 200px;
}
</style> </style>
...@@ -354,22 +354,34 @@ export default { ...@@ -354,22 +354,34 @@ export default {
] ]
}; };
}, },
methods: { methods: {
getParametersKeyOfElement: function(elementId) { getParametersKeyOfElement: function(elementId) {
const element = this.selectedElements.filter((element) => element.id === elementId)[0]; const element = this.selectedElements.filter((element) => element.id === elementId)[0];
return Object.keys(element.parameters); return Object.keys(element.parameters);
}, },
isParameterChecked: function(parameter) { isParameterChecked: function(parameter) {
if (!this.actionParameters.matchingCommands) return false;
console.log(' isParameterChecked => ', parameter);
if (!this.actionParameters.matchingCommands) return false;
return this.actionParameters.matchingCommands.includes(parameter);