Commit 191cf5fc authored by TOUZE Francois's avatar TOUZE Francois
Browse files

check for twiss & match actions with updated softwares

parent d054d610
......@@ -66,6 +66,9 @@ bool softwareElegant::createInputFile(particleBeam *beamBefore)
ofstream outfile;
string sfile= userDir_ + lattice;
outfile.open(sfile.c_str(),ios::out);
// the list of the parameters to be varied (filled in beamLine)
if( !vary_.empty() ) vary_.clear();
outfile << beamLine( firstIndex ) << endl;
outfile.close();
......@@ -80,7 +83,11 @@ bool softwareElegant::createInputFile(particleBeam *beamBefore)
if ( action == "twiss" ) {
outfile << run_setup( lattice );
outfile << twiss_output(amap,true,false,false);
outfile << "&twiss_output\n";
outfile << twiss_options( amap ) << endl;
// the Twiss parameters file => xxx-twiss.sdds
outfile << " filename = " << simulationId_+"-twiss.sdds" << endl;
outfile << "&end\n" << endl;
outfile << "&run_control &end\n" << endl;
}
......@@ -88,28 +95,33 @@ bool softwareElegant::createInputFile(particleBeam *beamBefore)
if ( action == "match" ) {
outfile << run_setup( lattice );
outfile << twiss_output(amap,false,false,false);
outfile << "&twiss_output\n";
outfile << " matched = 0\n";
outfile << twiss_initialValues( amap );
outfile << "&end\n" << endl;
outfile << "&run_control &end\n" << endl;
outfile << optimization( amap );
outfile << "&bunched_beam &end\n" << endl;
outfile << "&optimize &end\n" << endl;
// save the current beamLine => xxx-save_current.new
string save_current= simulationId_ + "-save_current.new";
outfile << "&save_lattice" << endl;
outfile << " filename = " << save_current << endl;
outfile << "&end\n" << endl;
outfile << run_setup( save_current );
outfile << twiss_output(amap,true,false,true );
outfile << "&twiss_output\n";
outfile << " matched = 0\n";
outfile << twiss_initialValues( amap );
outfile << " statistics = 1\n";
outfile << " filename = " << simulationId_+"-twiss.sdds" << endl;
outfile << "&end\n" << endl;
outfile << "&run_control &end" << endl;
}
outfile << "&bunched_beam &end\n" << endl;
outfile << "&track &end\n" << endl;
outfile << "&stop &end" << endl;
outfile.close();
dataManager_->consoleMessage("inputFile done for elegant\n");
return true;
......@@ -236,6 +248,7 @@ string softwareElegant::run_control()
return os.str();
}
/**
string softwareElegant::twiss_output(const std::vector<smap>& v,bool outfile,bool output_at_each_step,bool statistics)
{
if(debug > 0) cout << "softwareElegant::twiss_output()\n";
......@@ -289,6 +302,54 @@ string softwareElegant::twiss_output(const std::vector<smap>& v,bool outfile,boo
os << "&end\n" << endl;
return os.str();
}
*/
string softwareElegant::twiss_options(const std::vector<smap>& v)
{
ostringstream os;
string str= v[0].find("twiss_option")->second.at(0);
if ( str.find("option 1") != string::npos ) {
os << " matched = 0" << endl;
os << " beta_x = " << bunch_.find("beta_x")->second.at(0) << endl;
os << " beta_y = " << bunch_.find("beta_y")->second.at(0) << endl;
os << " alpha_x = " << bunch_.find("alfa_x")->second.at(0) << endl;
os << " alpha_y = " << bunch_.find("alfa_y")->second.at(0) << endl;
} else if ( str.find("option 2") != string::npos ) {
// calculations are performed in transport line mode starting from the given initial values of betax, alphax, etc..
os << " matched = 0" << endl;
os << twiss_initialValues( v ) << endl;
} else {
os << " matched = 1" << endl;
}
return os.str();
}
string softwareElegant::twiss_initialValues(const std::vector<smap>& v)
{
ostringstream os;
smap::const_iterator kt= v[1].find("beta_x");
if (kt != v[1].end()) os << " beta_x = " << kt->second.at(0) << endl;
kt= v[1].find("alpha_x");
if (kt != v[1].end()) os << " alpha_x = " << kt->second.at(0) << endl;
kt= v[1].find("dx");
if (kt != v[1].end()) os << " eta_x = " << kt->second.at(0) << endl;
kt= v[1].find("beta_y");
if (kt != v[1].end()) os << " beta_y = " << kt->second.at(0) << endl;
kt= v[1].find("alpha_y");
if (kt != v[1].end()) os << " alpha_y = " << kt->second.at(0) << endl;
kt= v[1].find("dpx");
if (kt != v[1].end()) os << " etap_x = " << kt->second.at(0) << endl;
return os.str();
}
string softwareElegant::nameOpticalFunction(string name)
{
......@@ -373,7 +434,7 @@ string softwareElegant::optimization(const std::vector<smap>& v)
os << "&optimization_setup" << endl;
if ( !os1.str().empty() ) os << " equation = " << os1.str() << endl;
os << " mode = " << v[ 6 ].find("mode")->second.at(0) << endl;
//recommended methods are “simplex” and “randomwalk”.
// recommended methods are “simplex” and “randomwalk”.
string s= v[ 6 ].find("method")->second.at(0);
if ( s.find("none") == string::npos )
os << " method = " << s << endl;
......@@ -409,10 +470,22 @@ string softwareElegant::optimization(const std::vector<smap>& v)
smap::const_iterator it;
for(it = v[ 4 ].begin(); it != v[ 4 ].end(); ++it)
{
string s( it->second.at(0) );
string::size_type nn= s.find(":");
string attribute(s.substr(0,nn));
os << "&optimization_variable" << endl;
string attribute;
smap::iterator where= vary_.find( it->first );
if( where == vary_.end() ) continue;
string key= where->second.at(0);
if (key == "mpole") {
attribute= "KNL";
} else if (key == "qpole") {
attribute= "K1";
} else if (key == "spole") {
attribute= "K2";
} else {
continue;
}
os << "&optimization_variable\n";
os << " name = " + it->first + ", item = " << attribute;
string low= it->second.at(2);
if( low.find("none") == string::npos )
......@@ -446,7 +519,7 @@ string softwareElegant::beamLine(unsigned firstIndex)
elPtr= getComputingBlock()->getElement( k );
string label= elPtr->getLabel();
if(find(lElts.begin(),lElts.end(),label) == lElts.end()) {
if (find(lElts.begin(),lElts.end(),label) == lElts.end()) {
vector<psvs> v= elPtr->parametersToSoftware();
os1 << elementsData( v );
......@@ -463,14 +536,15 @@ string softwareElegant::beamLine(unsigned firstIndex)
return os.str();
}
string softwareElegant::elementsData(const vector<psvs>& v) const
string softwareElegant::elementsData(const vector<psvs>& v)
{
if(debug > 0) cout << "softwareElegant::inputFormat()\n";
string keyword= v.at(0).second.at(0);
string label= v.at(0).second.at(1);
ostringstream os;
vary_[ label ].push_back( keyword );
ostringstream os;
if(keyword == "marker") {
os << label << ": marker\n";
......@@ -496,7 +570,7 @@ string softwareElegant::elementsData(const vector<psvs>& v) const
int order= atoi(v.at(1).second.at(0).c_str());
double knL= atof(v.at(1).second.at(1).c_str());
os << label << ":" << " mult, knl=" << knL << ", order= " << order << endl;
os << label << ":" << " mult, knl=" << knL << ", order= " << order << "\n";
} else if(keyword == "bend") {
......
......@@ -8,17 +8,22 @@
class softwareElegant : public abstractSoftware
{
smap bunch_;
smap vary_;
void beamData(const vector<psvs>&);
void fromParameters(const vector<psvs>&);
void fromDistribution(const vector<psvs>&);
void beamData(particleBeam*);
string beamLine(unsigned);
string elementsData(const vector<psvs>&) const;
string elementsData(const vector<psvs>&);
string run_setup(string);
string run_control();
string twiss_output(const std::vector<smap>&,bool,bool,bool);
//string twiss_output(const std::vector<smap>&,bool,bool,bool);
string twiss_initialValues(const std::vector<smap>&);
string twiss_options(const std::vector<smap>&);
string optimization(const vector<smap>&);
string nameOpticalFunction(string);
......
......@@ -264,8 +264,6 @@ string softwareMadx::twissStatement(const std::vector<smap>& v)
string opticalFunctions= "betx,alfx,mux,dx,dpx,bety,alfy,muy;";
os << "select, flag= twiss, column= name,s," + opticalFunctions << "\n";
// => os << "select, flag= twiss, column= name,s,betx,alfx,dx,bety,alfy" << ";\n";
ostringstream os3;
string str = v[0].find("twiss_option")->second.at(0);
if (str.find("option 1") != string::npos) {
......@@ -298,11 +296,7 @@ string softwareMadx::twissStatement(const std::vector<smap>& v)
}
// creates the TWISS table => xxx-twiss.txt
os << "twiss, save, file= " + getFileName("twiss",true) + os3.str() << ";\n";
// Plotting data
// => os << "plot, haxis=s, vaxis1=betx,bety, vaxis2=dx, colour=100, file= " + setPlotsFile() << ";\n";
os << "plot, haxis=s, vaxis1=betx,bety, colour=100, file= " + setPlotsFile() << ";\n";
os << "twiss, file= " + getFileName("twiss",true) + os3.str() << ";\n";
if (!v[ 2 ].empty()) {
......@@ -327,15 +321,10 @@ string softwareMadx::twissStatement(const std::vector<smap>& v)
os << endl;
os << os1.str() << endl;
os << "select, flag= twiss, clear;\n";
string derivedQuantities= "s,sigx,Hinvx,sigy;";
os << "select, flag= twiss, column= s," + derivedQuantities << "\n";
string derivedQuantities= "sigx,Hinvx,sigy;";
os << "select, flag= twiss, column= " + derivedQuantities << "\n";
// creates the SIGMA table => xxx-sigma.txt
os << "twiss, save, file= " + getFileName("sigma",true) << ";\n";
// Plotting data
os << "plot, haxis=s, vaxis=sigx,sigy, colour=100;\n";
os << "plot, haxis=s, vaxis=Hinvx, colour=100;\n";
os << "twiss, file= " + getFileName("sigma",true) + os3.str() << ";\n";
}
// chromatic functions
......@@ -343,13 +332,9 @@ string softwareMadx::twissStatement(const std::vector<smap>& v)
if (found != it->second.end()) {
os << "select, flag= twiss, clear;\n";
os << "select, flag= twiss, column= s,wx,wy,ddx;\n";
os << "select, flag= twiss, column= wx,wy,ddx;\n";
// creates the CHROM table => xxx-chrom.txt
os << "twiss, chrom, file= " + getFileName("chrom",true) << ";\n";
// Plotting data
os << "plot, table=twiss, haxis=s, vaxis1=wx,wy, vaxis2= ddx, colour=100;\n";
os << "twiss, chrom, file= " + getFileName("chrom",true) + os3.str() << ";\n";
}
}
......@@ -739,16 +724,16 @@ string softwareMadx::beamLine(unsigned firstIndex)
{
elPtr= getComputingBlock()->getElement(k);
string eType= elPtr->getGenericName();
//string eType= elPtr->getGenericName();
string label= elPtr->getLabel();
if(find(lElts.begin(),lElts.end(),label) == lElts.end()) {
if (find(lElts.begin(),lElts.end(),label) == lElts.end()) {
vector<psvs> v= elPtr->parametersToSoftware();
os1 << elementsData(v);
lElts.push_back(label);
os1 << elementsData( v );
lElts.push_back( label );
}
if(k < nElts-1) os2 << label << ",";
if (k < nElts-1) os2 << label << ",";
else os2 << label << ");" << endl;
}
......@@ -1314,9 +1299,8 @@ void softwareMadx::TSigma(json& j)
if ( buf.find("*") != string::npos ) break;
}
getline(ifs,buf); // skip formats
while (ifs >> buf) // s
while (ifs >> buf)
{
ifs >> buf;
vmap[ "sigx" ].push_back( buf );
ifs >> buf;
vmap[ "hinvx" ].push_back( buf );
......@@ -1362,9 +1346,8 @@ void softwareMadx::TChrom(json& j)
if ( buf.find("*") != string::npos ) break;
}
getline(ifs,buf); // skip formats
while (ifs >> buf) // s
while (ifs >> buf)
{
ifs >> buf;
vmap[ "wx" ].push_back( buf );
ifs >> buf;
vmap[ "wy" ].push_back( buf );
......
......@@ -24,8 +24,10 @@ void pspaplot::settings(string str)
//cout << "item choisi => " << item << endl;
json obj;
if (item == "phase-space") {
obj= phaseSpace( j );
if (item == "ellipse$START") {
obj= phaseSpace( j,"start" );
} else if (item == "ellipse$END") {
obj= phaseSpace( j,"end" );
} else {
obj= beamParameters( j );
}
......@@ -37,7 +39,7 @@ void pspaplot::settings(string str)
outfile.close();
}
json pspaplot::phaseSpace(json j)
json pspaplot::phaseSpace(json j, string opt)
{
auto ids= j.find( "plotSimulation" );
//std::cout << std::boolalpha;
......@@ -57,20 +59,24 @@ json pspaplot::phaseSpace(json j)
ifs >> obj;
ifs.close();
// displays the horizontal (xx') ellipse at the end of the beam line
vector<double> Xaxis;
vector<double> Yaxis;
double zcoor= obj.find( "zcoor" )->front();
double xrms= obj.find("xsigma")->front();
double alfa= obj.find("xalfa")->front();
double beta= obj.find("xbeta")->front();
//double zcoor= obj.find( "zcoor" )->back();
//double xrms= obj.find("xsigma")->back();
//double alfa= obj.find("xalfa")->back();
//double beta= obj.find("xbeta")->back();
// displays the horizontal (xx') ellipse at the beginning/end of the beam line
vector<double> Xaxis, Yaxis;
double zcoor, xrms, alfa, beta;
if (opt == "start") {
zcoor= obj.find( "zcoor" )->front();
xrms= obj.find("xsigma")->front();
alfa= obj.find("xalfa")->front();
beta= obj.find("xbeta")->front();
} else if (opt == "end") {
zcoor= obj.find( "zcoor" )->back();
xrms= obj.find("xsigma")->back();
alfa= obj.find("xalfa")->back();
beta= obj.find("xbeta")->back();
} else {
cout << "option error in the ellipse plot => " << opt << endl;
return json({});
}
int n= 50;
double h= 2.0*xrms/n;
......@@ -260,6 +266,11 @@ void pspaplot::submenu2(string key,json obj,map<string,vector<double> >& Ymaps)
if (key == "beta-functions") {
menu("xbeta",obj,Ymaps);
menu("ybeta",obj,Ymaps);
}
if (key == "beta&xeta") {
menu("xbeta",obj,Ymaps);
menu("ybeta",obj,Ymaps);
menu("xeta",obj,Ymaps);
}
......@@ -405,11 +416,13 @@ json pspaplot::lineplots(vector<double> Xaxis,map<string,vector<double> > Ymaps)
leftLabel += ",σy";
}
if (Ymaps.find("ybeta") != Ymaps.end()) {
if (Ymaps.find("xeta") != Ymaps.end()) {
x["label"]= "βy [m]";
it= Ymaps.find("ybeta");
addDataset= true;
leftLabel += ",βy";
}
}
if (Ymaps.find("yalfa") != Ymaps.end()) {
x["label"]= "αy [m]";
it= Ymaps.find("yalfa");
......@@ -447,11 +460,19 @@ json pspaplot::lineplots(vector<double> Xaxis,map<string,vector<double> > Ymaps)
string rightLabel;
addDataset= false;
if (Ymaps.find("ybeta") != Ymaps.end()) {
if (Ymaps.find("xeta") != Ymaps.end()) {
x["label"]= "ηₓ [m]";
it= Ymaps.find("xeta");
rightLabel= "ηₓ";
addDataset= true;
} else {
x["label"]= "βy [m]";
it= Ymaps.find("ybeta");
rightLabel += "βy";
addDataset= true;
}
}
if (Ymaps.find("xetap") != Ymaps.end()) {
x["label"]= "μ′ₓ [m]";
......
......@@ -13,7 +13,7 @@ class pspaplot
{
string userDir_;
json phaseSpace(json);
json phaseSpace(json,string);
json beamParameters(json);
void submenu1(string,json,vector<double>&,map<string,vector<double> >&);
void submenu2(string,json,map<string,vector<double> >&);
......
......@@ -33,8 +33,8 @@
<input type="radio" id="choice12" value="tunesVSdelta" v-on:click="say('tunesVSdelta')" v-model="picked">
<label for="choice12">tunes vs. Δp/p </label>
<input type="radio" id="choice15" value="phase-space" v-on:click="say('phase-space')" v-model="picked">
<label for="choice15">ellipse</label>
<input type="radio" id="choice15" value="ellipse$START" v-on:click="say('ellipse$START')" v-model="picked">
<label for="choice15">ellipse at START</label>
</div>
......@@ -51,8 +51,8 @@
<input type="radio" id="choice13" value="tunesVSx" v-on:click="say('tunesVSx')" v-model="picked">
<label for="choice12">tunes vs. x </label>
<input type="radio" id="choice16" value="ellipse$END" v-on:click="say('ellipse$END')" v-model="picked">
<label for="choice15">ellipse at END</label>
</div>
......@@ -69,8 +69,6 @@
<input type="radio" id="choice14" value="tunesVSy" v-on:click="say('tunesVSy')" v-model="picked">
<label for="choice14">tunes vs. y </label>
</div>
<div>
......@@ -80,7 +78,6 @@
<input type="radio" id="choice8" value="alfaVSdelta" v-on:click="say('alfaVSdelta')" v-model="picked">
<label for="choice8">alpha vs. Δp/p </label>
</div>
<!--span>Choisi => {{ picked }}</span-->
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment