7 #include <boost/numeric/ublas/io.hpp>
9 #include <flame/constants.h>
10 #include <flame/base.h>
11 #include <flame/moment.h>
12 #include <flame/chg_stripper.h>
13 #include <flame/state/vector.h>
14 #include <flame/state/matrix.h>
16 #include <flame/moment_sup.h>
20 typedef state_t::vector_t value_vec;
21 typedef state_t::matrix_t value_mat;
23 extern int glps_debug;
27 void PrtVec(
const MomentState::vector_t &a)
29 for (
size_t k = 0; k < a.size(); k++)
30 std::cout << std::scientific << std::setprecision(10)
31 << std::setw(18) << a[k];
36 void PrtMat(
const value_mat &M)
38 for (
size_t j = 0; j < M.size1(); j++) {
39 for (
size_t k = 0; k < M.size2(); k++)
40 std::cout << std::scientific << std::setprecision(10)
41 << std::setw(18) << M(j, k);
46 void PrtState(
const state_t& ST)
48 MomentState::vector_t CenofChg, BeamRMS;
51 for (
size_t k = 0; k < ST.
size(); k++) {
52 std::cout <<
"\nState: "<<k<<
" s = "<<std::fixed << std::setprecision(5) << ST.
pos <<
"\n"
54 <<
"\n Real: "<<ST.real[k]
56 PrtVec(ST.moment0[k]);
57 std::cout <<
" moment1\n";
58 PrtMat(ST.moment1[k]);
61 std::cout<<
"\nCenter: "<< std::scientific << std::setprecision(10)
62 << std::setw(18)<<ST.moment0_env<<
"\n";
63 std::cout<<
"RMS Beam Size: "<< std::scientific << std::setprecision(10)
64 << std::setw(18)<<ST.moment0_rms<<
"\n";
65 PrtMat(ST.moment1_env);
69 void prt_initial_cond(
Machine &sim,
77 void PrtOut(std::ofstream &outf1, std::ofstream &outf2, std::ofstream &outf3,
const state_t& ST)
79 outf1 << std::scientific << std::setprecision(14) << std::setw(22) << ST.
pos;
80 for (
size_t j = 0; j < ST.
size(); j++)
81 for (
int k = 0; k < 6; k++)
82 outf1 << std::scientific << std::setprecision(14) << std::setw(22) << ST.moment0[j][k];
83 for (
int k = 0; k < 6; k++)
84 outf1 << std::scientific << std::setprecision(14) << std::setw(22) << ST.moment0_env[k];
87 outf2 << std::scientific << std::setprecision(14) << std::setw(22) << ST.
pos;
88 for (
size_t j = 0; j < ST.
size(); j++)
89 for (
int k = 0; k < 6; k++)
90 outf2 << std::scientific << std::setprecision(14) << std::setw(22) << sqrt(ST.moment1[j](k, k));
91 for (
int k = 0; k < 6; k++)
92 outf2 << std::scientific << std::setprecision(14) << std::setw(22) << sqrt(ST.moment1_env(k, k));
95 outf3 << std::scientific << std::setprecision(14)
96 << std::setw(22) << ST.
pos << std::setw(22) << ST.ref.
phis << std::setw(22) << ST.ref.
IonEk <<
"\n";
100 void propagate(
const Config &conf)
104 std::auto_ptr<StateBase> state(sim.
allocState());
106 std::ofstream outf1, outf2, outf3;
108 if(!StatePtr)
throw std::runtime_error(
"Only sim_type MomentMatrix is supported");
110 outf1.open(
"moment0.txt", std::ios::out);
111 outf2.open(
"moment1.txt", std::ios::out);
112 outf3.open(
"ref_orbit.txt", std::ios::out);
114 prt_initial_cond(sim, *StatePtr);
120 prt_initial_cond(sim, *StatePtr);
123 while (it != sim.
end()) {
142 std::cout << std::fixed << std::setprecision(5)
143 <<
"\npropagate: " << double(tStamp[1]-tStamp[0])/CLOCKS_PER_SEC <<
" sec" <<
"\n";
147 int main(
int argc,
char *argv[])
150 std::auto_ptr<Config> conf;
158 conf.reset(P.
parse_file(argc>1 ? argv[1] : NULL));
159 fprintf(stderr,
"Parsing succeeds\n");
160 }
catch(std::exception& e) {
161 fprintf(stderr,
"Parse error: %s\n", e.what());
174 }
catch(std::exception& e) {
175 std::cerr <<
"Main exception: " << e.what() <<
"\n";
void propagate(StateBase *S, size_t start=0, size_t max=-1) const
Pass the given bunch State through this Machine.
p_elements_t::iterator iterator
Beamline element iterator.
Base class for all simulated elements.
StateBase * allocState(const Config &c) const
Allocate (with "operator new") an appropriate State object.
The core simulate Machine engine.
Interface to lattice file parser.
double IonEk
Kinetic energy.
virtual void advance(StateBase &s)=0
Propogate the given State through this Element.
double phis
Absolute synchrotron phase [rad].
iterator begin()
Points to the first element.
Associative configuration container.
static void registeryCleanup()
Discard all registered State and Element type information.
double pos
absolute longitudinal position at end of Element
Config * parse_file(const char *fname)
Open and parse a file.
iterator end()
Points just after the last element.
size_t size() const
of charge states