39 #include <gsl/gsl_rng.h>
40 #include <gsl/gsl_histogram.h>
41 #include <gsl/gsl_cdf.h>
42 #include <gsl/gsl_randist.h>
43 #include <gsl/gsl_sf_erf.h>
44 #include <gsl/gsl_qrng.h>
46 #include <boost/format.hpp>
56 interpolationCacheSet_m(false)
84 for (
unsigned int i = 0; i <
Dimension; i++)
85 nr_m[i] = domain[i].length();
87 for (
int i = 0; i < 3; i++)
155 double scaleFactor = 1;
161 double tmp2 = 1 /
hr_m[0] * 1 /
hr_m[1] * 1 /
hr_m[2] / (scaleFactor * scaleFactor * scaleFactor) / gammaz;
167 hr_scaled[2] *= gammaz;
171 imagePotential =
rho_m;
176 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
188 eg_m *=
Vector_t(gammaz / (scaleFactor), gammaz / (scaleFactor), 1.0 / (scaleFactor * gammaz));
194 int mx = (int)
nr_m[0];
195 int mx2 = (int)
nr_m[0] / 2;
196 int my = (int)
nr_m[1];
197 int my2 = (int)
nr_m[1] / 2;
198 int mz = (int)
nr_m[2];
199 int mz2 = (int)
nr_m[2] / 2;
201 for (
int i=0; i<mx; i++ )
202 *
gmsg <<
"Bin " << binNumber
203 <<
", Self Field along x axis E = " <<
eg_m[i][my2][mz2]
204 <<
", Pot = " <<
rho_m[i][my2][mz2] <<
endl;
206 for (
int i=0; i<my; i++ )
207 *
gmsg <<
"Bin " << binNumber
208 <<
", Self Field along y axis E = " <<
eg_m[mx2][i][mz2]
209 <<
", Pot = " <<
rho_m[mx2][i][mz2] <<
endl;
211 for (
int i=0; i<mz; i++ )
212 *
gmsg <<
"Bin " << binNumber
213 <<
", Self Field along z axis E = " <<
eg_m[mx2][my2][i]
214 <<
", Pot = " <<
rho_m[mx2][my2][i] <<
endl;
245 double zshift = -(2 * origin(2) + (domain[2].first() + domain[2].last() + 1) * hz) * gammaz * scaleFactor;
252 imagePotential *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
258 const int dumpFreq = 100;
259 #ifdef DBG_SCALARFIELD
273 boost::format phi_fn(
"data/%1%-phi_scalar-%|2$05|.dat");
276 std::ofstream fstr2(phi_fn.str());
288 << (rmin(0) - origin(0)) / spacing(0) <<
"\t"
289 << (rmin(1) - origin(1)) / spacing(1) <<
"\t"
290 << (rmin(2) - origin(2)) / spacing(2) <<
"\t"
292 for (
int x = myidx[0].first(); x <= myidx[0].last(); x++) {
293 for (
int y = myidx[1].first(); y <= myidx[1].last(); y++) {
294 for (
int z = myidx[2].first(); z <= myidx[2].last(); z++) {
295 fstr2 << std::setw(5) << x + 1
296 << std::setw(5) << y + 1
297 << std::setw(5) << z + 1
298 << std::setw(17) << origin(2) + z * spacing(2)
299 << std::setw(17) <<
rho_m[x][y][z].get()
300 << std::setw(17) << imagePotential[x][y][z].get() <<
std::endl;
316 eg_m *=
Vector_t(gammaz / (scaleFactor), gammaz / (scaleFactor), 1.0 / (scaleFactor * gammaz));
329 for (
int i=0; i<mx; i++ )
330 *
gmsg <<
"Bin " << binNumber
331 <<
", Image Field along x axis E = " <<
eg_m[i][my2][mz2]
332 <<
", Pot = " <<
rho_m[i][my2][mz2] <<
endl;
334 for (
int i=0; i<my; i++ )
335 *
gmsg <<
"Bin " << binNumber
336 <<
", Image Field along y axis E = " <<
eg_m[mx2][i][mz2]
337 <<
", Pot = " <<
rho_m[mx2][i][mz2] <<
endl;
339 for (
int i=0; i<mz; i++ )
340 *
gmsg <<
"Bin " << binNumber
341 <<
", Image Field along z axis E = " <<
eg_m[mx2][my2][i]
342 <<
", Pot = " <<
rho_m[mx2][my2][i] <<
endl;
345 #ifdef DBG_SCALARFIELD
353 boost::format phi_fn(
"data/%1%-e_field-%|2$05|.dat");
356 std::ofstream fstr2(phi_fn.str());
365 for (
int x = myidxx[0].first(); x <= myidxx[0].last(); x++) {
366 for (
int y = myidxx[1].first(); y <= myidxx[1].last(); y++) {
367 for (
int z = myidxx[2].first(); z <= myidxx[2].last(); z++) {
368 Vector_t ef =
eg_m[x][y][z].get() + tmp_eg[x][y][z].get();
369 fstr2 << std::setw(5) << x + 1
370 << std::setw(5) << y + 1
371 << std::setw(5) << z + 1
372 << std::setw(17) << origin(2) + z * spacing(2)
373 << std::setw(17) << ef(0)
374 << std::setw(17) << ef(1)
426 if(
R[
n](0) < xmin ||
R[
n](0) > xmax ||
427 R[
n](1) < ymin ||
R[
n](1) > ymax) {
440 Vector_t mymin =
Vector_t(xmin, ymin , zmin);
441 Vector_t mymax =
Vector_t(xmax, ymax , zmax);
443 for (
int i = 0; i < 3; i++)
444 hr_m[i] = (mymax[i] - mymin[i])/
nr_m[i];
482 gammaz =
sqrt(gammaz + 1.0);
483 double scaleFactor = 1;
487 hr_scaled[2] *= gammaz;
490 double tmp2 = 1 / hr_scaled[0] * 1 / hr_scaled[1] * 1 / hr_scaled[2];
494 #ifdef DBG_SCALARFIELD
495 INFOMSG(
"*** START DUMPING SCALAR FIELD ***" <<
endl);
501 std::string rho_fn = std::string(
"data/") + SfileName + std::string(
"-rho_scalar-") + std::to_string(
fieldDBGStep_m);
502 fstr1.open(rho_fn.c_str(), std::ios::out);
504 for (
int x = myidx1[0].first(); x <= myidx1[0].last(); x++) {
505 for (
int y = myidx1[1].first(); y <= myidx1[1].last(); y++) {
506 for (
int z = myidx1[2].first(); z <= myidx1[2].last(); z++) {
507 fstr1 << x + 1 <<
" " << y + 1 <<
" " << z + 1 <<
" " <<
rho_m[x][y][z].get() <<
std::endl;
512 INFOMSG(
"*** FINISHED DUMPING SCALAR FIELD ***" <<
endl);
523 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
531 #ifdef DBG_SCALARFIELD
532 INFOMSG(
"*** START DUMPING SCALAR FIELD ***" <<
endl);
537 std::string phi_fn = std::string(
"data/") + SfileName + std::string(
"-phi_scalar-") + std::to_string(
fieldDBGStep_m);
538 fstr2.open(phi_fn.c_str(), std::ios::out);
540 for (
int x = myidx[0].first(); x <= myidx[0].last(); x++) {
541 for (
int y = myidx[1].first(); y <= myidx[1].last(); y++) {
542 for (
int z = myidx[2].first(); z <= myidx[2].last(); z++) {
543 fstr2 << x + 1 <<
" " << y + 1 <<
" " << z + 1 <<
" " <<
rho_m[x][y][z].get() <<
std::endl;
549 INFOMSG(
"*** FINISHED DUMPING SCALAR FIELD ***" <<
endl);
556 eg_m *=
Vector_t(gammaz / (scaleFactor), gammaz / (scaleFactor), 1.0 / (scaleFactor * gammaz));
562 int mx = (int)
nr_m[0];
563 int mx2 = (int)
nr_m[0] / 2;
564 int my = (int)
nr_m[1];
565 int my2 = (int)
nr_m[1] / 2;
566 int mz = (int)
nr_m[2];
567 int mz2 = (int)
nr_m[2] / 2;
569 for (
int i=0; i<mx; i++ )
570 *
gmsg <<
"Field along x axis Ex = " <<
eg_m[i][my2][mz2] <<
" Pot = " <<
rho_m[i][my2][mz2] <<
endl;
572 for (
int i=0; i<my; i++ )
573 *
gmsg <<
"Field along y axis Ey = " <<
eg_m[mx2][i][mz2] <<
" Pot = " <<
rho_m[mx2][i][mz2] <<
endl;
575 for (
int i=0; i<mz; i++ )
576 *
gmsg <<
"Field along z axis Ez = " <<
eg_m[mx2][my2][i] <<
" Pot = " <<
rho_m[mx2][my2][i] <<
endl;
579 #ifdef DBG_SCALARFIELD
589 std::string e_field = std::string(
"data/") + SfileName + std::string(
"-e_field-") + std::to_string(
fieldDBGStep_m);
590 fstr.open(e_field.c_str(), std::ios::out);
592 for (
int x = myidxx[0].first(); x <= myidxx[0].last(); x++) {
593 for (
int y = myidxx[1].first(); y <= myidxx[1].last(); y++) {
594 for (
int z = myidxx[2].first(); z <= myidxx[2].last(); z++) {
595 fstr << x + 1 <<
" " << y + 1 <<
" " << z + 1 <<
" " <<
eg_m[x][y][z].get() <<
std::endl;
606 INFOMSG(
"*** FINISHED DUMPING E FIELD ***" <<
endl);
624 Bf(0) =
Bf(0) - betaC *
Ef(1);
625 Bf(1) =
Bf(1) + betaC *
Ef(0);
663 Vector_t hr_scaled =
hr_m ;
664 hr_scaled[1] *= gamma;
667 double tmp2 = 1.0 / (hr_scaled[0] * hr_scaled[1] * hr_scaled[2]);
671 #ifdef DBG_SCALARFIELD
672 INFOMSG(
"*** START DUMPING SCALAR FIELD ***" <<
endl);
676 std::ostringstream istr;
681 std::string rho_fn = std::string(
"data/") + SfileName + std::string(
"-rho_scalar-") + std::string(istr.str());
682 fstr1.open(rho_fn.c_str(), std::ios::out);
684 for (
int x = myidx1[0].first(); x <= myidx1[0].last(); x++) {
685 for (
int y = myidx1[1].first(); y <= myidx1[1].last(); y++) {
686 for (
int z = myidx1[2].first(); z <= myidx1[2].last(); z++) {
687 fstr1 << x + 1 <<
" " << y + 1 <<
" " << z + 1 <<
" " <<
rho_m[x][y][z].get() <<
std::endl;
692 INFOMSG(
"*** FINISHED DUMPING SCALAR FIELD ***" <<
endl);
704 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
710 #ifdef DBG_SCALARFIELD
711 INFOMSG(
"*** START DUMPING SCALAR FIELD ***" <<
endl);
716 std::string phi_fn = std::string(
"data/") + SfileName + std::string(
"-phi_scalar-") + std::string(istr.str());
717 fstr2.open(phi_fn.c_str(), std::ios::out);
719 for (
int x = myidx[0].first(); x <= myidx[0].last(); x++) {
720 for (
int y = myidx[1].first(); y <= myidx[1].last(); y++) {
721 for (
int z = myidx[2].first(); z <= myidx[2].last(); z++) {
722 fstr2 << x + 1 <<
" " << y + 1 <<
" " << z + 1 <<
" " <<
rho_m[x][y][z].get() <<
std::endl;
728 INFOMSG(
"*** FINISHED DUMPING SCALAR FIELD ***" <<
endl);
743 int mx = (int)
nr_m[0];
744 int mx2 = (int)
nr_m[0] / 2;
745 int my = (int)
nr_m[1];
746 int my2 = (int)
nr_m[1] / 2;
747 int mz = (int)
nr_m[2];
748 int mz2 = (int)
nr_m[2] / 2;
750 for (
int i=0; i<mx; i++ )
751 *
gmsg <<
"Field along x axis Ex = " <<
eg_m[i][my2][mz2] <<
" Pot = " <<
rho_m[i][my2][mz2] <<
endl;
753 for (
int i=0; i<my; i++ )
754 *
gmsg <<
"Field along y axis Ey = " <<
eg_m[mx2][i][mz2] <<
" Pot = " <<
rho_m[mx2][i][mz2] <<
endl;
756 for (
int i=0; i<mz; i++ )
757 *
gmsg <<
"Field along z axis Ez = " <<
eg_m[mx2][my2][i] <<
" Pot = " <<
rho_m[mx2][my2][i] <<
endl;
760 #ifdef DBG_SCALARFIELD
771 std::string e_field = std::string(
"data/") + SfileName + std::string(
"-e_field-") + std::string(istr.str());
772 fstr.open(e_field.c_str(), std::ios::out);
774 for (
int x = myidxx[0].first(); x <= myidxx[0].last(); x++) {
775 for (
int y = myidxx[1].first(); y <= myidxx[1].last(); y++) {
776 for (
int z = myidxx[2].first(); z <= myidxx[2].last(); z++) {
777 fstr << x + 1 <<
" " << y + 1 <<
" " << z + 1 <<
" " <<
eg_m[x][y][z].get() <<
std::endl;
788 INFOMSG(
"*** FINISHED DUMPING E FIELD ***" <<
endl);
801 Bf(0) = betaC *
Ef(2);
802 Bf(2) = -betaC *
Ef(0);
855 Vector_t hr_scaled =
hr_m ;
856 hr_scaled[1] *= gamma;
859 double tmp2 = 1.0 / (hr_scaled[0] * hr_scaled[1] * hr_scaled[2]);
863 #ifdef DBG_SCALARFIELD
864 INFOMSG(
"*** START DUMPING SCALAR FIELD ***" <<
endl);
868 std::ostringstream istr;
873 std::string rho_fn = std::string(
"data/") + SfileName + std::string(
"-rho_scalar-") + std::string(istr.str());
874 fstr1.open(rho_fn.c_str(), std::ios::out);
876 for (
int x = myidx1[0].first(); x <= myidx1[0].last(); x++) {
877 for (
int y = myidx1[1].first(); y <= myidx1[1].last(); y++) {
878 for (
int z = myidx1[2].first(); z <= myidx1[2].last(); z++) {
879 fstr1 << x + 1 <<
" " << y + 1 <<
" " << z + 1 <<
" " <<
rho_m[x][y][z].get() <<
std::endl;
884 INFOMSG(
"*** FINISHED DUMPING SCALAR FIELD ***" <<
endl);
894 rho_m *= hr_scaled[0] * hr_scaled[1] * hr_scaled[2];
900 #ifdef DBG_SCALARFIELD
901 INFOMSG(
"*** START DUMPING SCALAR FIELD ***" <<
endl);
906 std::string phi_fn = std::string(
"data/") + SfileName + std::string(
"-phi_scalar-") + std::string(istr.str());
907 fstr2.open(phi_fn.c_str(), std::ios::out);
909 for (
int x = myidx[0].first(); x <= myidx[0].last(); x++) {
910 for (
int y = myidx[1].first(); y <= myidx[1].last(); y++) {
911 for (
int z = myidx[2].first(); z <= myidx[2].last(); z++) {
912 fstr2 << x + 1 <<
" " << y + 1 <<
" " << z + 1 <<
" " <<
rho_m[x][y][z].get() <<
std::endl;
918 INFOMSG(
"*** FINISHED DUMPING SCALAR FIELD ***" <<
endl);
933 int mx = (int)
nr_m[0];
934 int mx2 = (int)
nr_m[0] / 2;
935 int my = (int)
nr_m[1];
936 int my2 = (int)
nr_m[1] / 2;
937 int mz = (int)
nr_m[2];
938 int mz2 = (int)
nr_m[2] / 2;
940 for (
int i=0; i<mx; i++ )
941 *
gmsg <<
"Bin " << bin
942 <<
", Field along x axis Ex = " <<
eg_m[i][my2][mz2]
943 <<
", Pot = " <<
rho_m[i][my2][mz2] <<
endl;
945 for (
int i=0; i<my; i++ )
946 *
gmsg <<
"Bin " << bin
947 <<
", Field along y axis Ey = " <<
eg_m[mx2][i][mz2]
948 <<
", Pot = " <<
rho_m[mx2][i][mz2] <<
endl;
950 for (
int i=0; i<mz; i++ )
951 *
gmsg <<
"Bin " << bin
952 <<
", Field along z axis Ez = " <<
eg_m[mx2][my2][i]
953 <<
", Pot = " <<
rho_m[mx2][my2][i] <<
endl;
957 #ifdef DBG_SCALARFIELD
967 std::string e_field = std::string(
"data/") + SfileName + std::string(
"-e_field-") + std::string(istr.str());
968 fstr.open(e_field.c_str(), std::ios::out);
970 for (
int x = myidxx[0].first(); x <= myidxx[0].last(); x++) {
971 for (
int y = myidxx[1].first(); y <= myidxx[1].last(); y++) {
972 for (
int z = myidxx[2].first(); z <= myidxx[2].last(); z++) {
973 fstr << x + 1 <<
" " << y + 1 <<
" " << z + 1 <<
" " <<
eg_m[x][y][z].get() <<
std::endl;
984 INFOMSG(
"*** FINISHED DUMPING E FIELD ***" <<
endl);
1032 for (
int i = 0; i < 2 * 3; ++i) {
1051 for (
int i = 0; i < 2 * 3; ++i) {
1061 for (
int i = 0; i < 2 * 3; ++ i) {
1085 for (
unsigned int i = 0; i <
Dimension; i++)
1086 grid[i] = domain[i].length();
1140 const Vector_t maxE =
max(
eg_m);
1142 const Vector_t minE =
min(
eg_m);
virtual void swap(unsigned int i, unsigned int j)
Vector_t rmin_m
minimal extend of particles
ParticleAttrib< Vector_t > P
IpplTimings::TimerRef selfFieldTimer_m
timer for selfField calculation
void changeDomain(FieldLayout< Dim > &)
void destroy(size_t M, size_t I, bool doNow=false)
ParticleAttrib< Vector_t > Ef
ParticleAttrib< Vector_t > Eftmp
T ParticlePeriodicBCond(const T t, const T minval, const T maxval)
virtual void create(size_t)
RegionLayout< T, Dim, Mesh > & getLayout()
void scatter(Field< T, Dim, M, C > &f, const ParticleAttrib< Vektor< PT, Dim > > &pp, const IntOp &intop) const
virtual double getXRangeMin(unsigned short level=0)=0
virtual double getXRangeMax(unsigned short level=0)=0
T::PETE_Expr_t::PETE_Return_t max(const PETE_Expr< T > &expr, NDIndex< D > &loc)
ParticleAttrib< double > Q
virtual double getZRangeMax(unsigned short level=0)=0
Vektor< int, 3 > nr_m
meshsize of cartesian mesh
void swap(unsigned int i, unsigned int j)
Inform & print(Inform &os)
double getCouplingConstant() const
ParticleLayout< double, 3 > & getLayout()
std::string getFieldSolverType()
T ParticleNoBCond(const T t, const T, const T)
ParticleAttrib< CacheDataCIC< double, 3U > > interpolationCache_m
T::PETE_Expr_t::PETE_Return_t sum(const PETE_Expr< T > &expr)
size_t getTotalNum() const
Field< Vektor< T, 1U >, 1U, Cartesian< 1U, MFLOAT >, Cell > & Grad(Field< T, 1U, Cartesian< 1U, MFLOAT >, Vert > &x, Field< Vektor< T, 1U >, 1U, Cartesian< 1U, MFLOAT >, Cell > &r)
BConds< Vector_t, 3, Mesh_t, Center_t > vbc_m
Inform & level2(Inform &inf)
static OpalData * getInstance()
std::shared_ptr< AbstractParticle< double, Dim > > pbase
std::pair< Vector_t, Vector_t > VectorPair_t
Field_t rho_m
scalar potential
void BinaryRepartition(FieldLayout< Dim > &layout, BareField< double, Dim > &weights)
PoissonSolver * solver_m
the actual solver, should be a base object
void updateDomainLength(Vektor< int, 3 > &grid)
constexpr double c
The velocity of light in m/s.
bool interpolationCacheSet_m
static void startTimer(TimerRef t)
Vector_t rmax_m
maximal extend of particles
Vektor< double, 3 > Vector_t
void set_origin(const Vektor< MFLOAT, Dim > &o)
virtual void computePotential(Field_t &rho, Vector_t hr)=0
VectorPair_t getEExtrema()
FieldSolver * fs_m
stores the used field solver
size_t getLocalNum() const
virtual void destroy(size_t M, size_t I, bool optDestroy=true)
Inform & print(Inform &os)
virtual double getYRangeMin(unsigned short level=0)=0
Tps< T > sqrt(const Tps< T > &x)
Square root.
ParticleAttrib< double > dt
void initialize(FieldLayout_t *fLayout)
virtual double getYRangeMax(unsigned short level=0)=0
VField_t eg_m
vector field on the grid
Vector_t hr_m
meshspacing of cartesian mesh
const Mesh_t & getMesh() const
static const unsigned Dimension
double getBinGamma(int bin)
Get gamma of one bin.
virtual double getZRangeMin(unsigned short level=0)=0
FieldLayout< Dim > & getFieldLayout()
void resizeMesh()
resize mesh to geometry specified
ParticleAttrib< Vector_t > Bf
void initialize(Layout_t &)
void updateFields(const Vector_t &hr, const Vector_t &origin)
Inform & level3(Inform &inf)
void set_meshSpacing(MFLOAT *const del)
void resetInterpolationCache(bool clearCache=false)
Mesh_t & get_mesh() const
void get_bounds(Vector_t &rmin, Vector_t &rmax)
ParticleBConds< Position_t, Dimension > & getBConds()
static void stopTimer(TimerRef t)
std::string getInputBasename()
get input file name without extension
BConds< double, 3, Mesh_t, Center_t > bc_m
for defining the boundary conditions
Inform & level1(Inform &inf)
NDIndex< Dim > getLocalNDIndex()
T::PETE_Expr_t::PETE_Return_t min(const PETE_Expr< T > &expr, NDIndex< D > &loc)
const NDIndex< Dim > & getDomain() const
virtual void test(PartBunchBase< double, 3 > *bunch)=0
Inform & endl(Inform &inf)
void computeSelfFields_cycl(double gamma)
Calculates the self electric field from the charge density distribution for use in cyclotrons...
FieldLayout_t & getFieldLayout()