Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relativistic field initialization (solve poisson) in transverse direction #318

Closed
ycaophysics opened this issue Oct 20, 2020 · 24 comments
Closed
Labels
feature-request something that could be added to the code needs-user-input the issue cannot be resolved without additional information

Comments

@ycaophysics
Copy link

The problem and the context

My problem involves a longitudinal Bx field and an electron species moving in the y direction. However, the current solve_poisson only works in x (longitudinal direction). To initialize a relativistic species moving in transverse direction, I hope to modify the (relativistic) poisson solver to work in y/transverse direction. Thanks

@ycaophysics ycaophysics added the feature-request something that could be added to the code label Oct 20, 2020
@Z10Frank
Copy link
Contributor

Before the explanation for the modifications, some recommendations:

  • As you see in the doc, the underlying hypothesis is negligible energy spread, so your modified solver will not work if the energy spread is too large.
  • Your species should be initialized far from the borders or almost any Poisson solver will give you strange effects on the borders.

As can you see from the documentation https://smileipic.github.io/Smilei/relativistic_fields_initialization.html, the difference between a relativistic Poisson solver for a species moving along x or y is the presence of an average gamma squared in the operations associated to the desired direction.

For a motion along x, this gamma squared is below the x derivatives in Eq. 62:
Screenshot 2020-10-20 at 11 47 12
and in the final equations to find E and B from Phi:
Screenshot 2020-10-20 at 11 47 49

Thus, to modify the solver to take into account instead a motion along y, that gamma squared must be moved from the x derivatives to the y derivatives in those equations, and change the unit vector x in the final vector product, from x to y.

Eq. 62, or relativistic Poisson's equation, is solved with a conjugate gradient method (look at the section "The resulting algorithm" in https://en.wikipedia.org/wiki/Conjugate_gradient_method). The term Ap of that scheme is computed ElectroMagn2D::compute_Ap_relativistic_Poisson in ElectroMagn2D.cpp. There, you'll have to move the terms involving gamma squared from the derivatives along x to the derivatives along y.

In the same file, you can find the mentioned calculation of E from Phi in ElectroMagn2D::initE_relativistic_Poisson.

Finally, in the same file you can find the calculation of B from E in ElectroMagn2D::initB_relativistic_Poisson. The mentioned vector product should be changed to have the unit vector y instead of x.

To start, try to make these modifications, do not hesitate to contact us here if you have questions, I hope the explanation was clear. You may have to change the boundary conditions in the Poisson solver in compute_Ap_relativistic_Poisson, but better make first the other modifications.

@ycaophysics
Copy link
Author

I changed the first two parts to this (haven't changed the boundary condition though):

void ElectroMagn2D::compute_Ap_relativistic_Poisson( Patch *patch, double gamma_mean )
{
// gamma_mean is the average Lorentz factor of the species whose fields will be computed
// See for example https://doi.org/10.1016/j.nima.2016.02.043 for more details
// Modified to y direction

double one_ov_dy_sq_ov_gamma_sq       = 1.0/( dy*dy )/( gamma_mean*gamma_mean );
double one_ov_dx_sq                   = 1.0/( dx*dx );
double two_ov_dygam2dx2               = 2.0*( 1.0/( dy*dy )/( gamma_mean*gamma_mean )+1.0/( dx*dx ) );

// vector product Ap = A*p
for( unsigned int i=1; i<ny_p-1; i++ ) {
    for( unsigned int j=1; j<nx_p-1; j++ ) {
        ( *Ap_ )( i, j ) = one_ov_dy_sq_ov_gamma_sq*( ( *p_ )( i-1, j )+( *p_ )( i+1, j ) )
                           + one_ov_dx_sq*( ( *p_ )( i, j-1 )+( *p_ )( i, j+1 ) )
                           - two_ov_dygam2dx2*( *p_ )( i, j );
    }//j
}//i

void ElectroMagn2D::initE_relativistic_Poisson( Patch *patch, double gamma_mean )
{
// gamma_mean is the average Lorentz factor of the species whose fields will be computed
// See for example https://doi.org/10.1016/j.nima.2016.02.043 for more details

Field2D *Ex2D  = static_cast<Field2D *>( Ex_rel_ );
Field2D *Ey2D  = static_cast<Field2D *>( Ey_rel_ );
Field2D *rho2D = static_cast<Field2D *>( rho_ );

// ------------------------------------------
// Compute the fields Ex and Ey
// ------------------------------------------



// Ey
MESSAGE( 1, "Computing Ey from scalar potential, relativistic Poisson problem" );
for( unsigned int i=1; i<ny_p-1; i++ ) {
    for( unsigned int j=0; j<nx_p; j++ ) {
        ( *Ey2D )( i, j ) = ( ( *phi_ )( i-1, j )-( *phi_ )( i, j ) )/dy/gamma_mean/gamma_mean;
    }
}
MESSAGE( 1, "Ey: done" );
// Ex
MESSAGE( 1, "Computing Ex from scalar potential, relativistic Poisson problem" );
for( unsigned int i=0; i<ny_p; i++ ) {
    for( unsigned int j=1; j<nx_p-1; j++ ) {
        ( *Ex2D )( i, j ) = ( ( *phi_ )( i, j-1 )-( *phi_ )( i, j ) )/dx;
    }
}

However, I don't know what to do with B field initialization. In the original script there doesn't seem to be a By field (which should exist by beta0*(x cross E), which I'm not sure why.

Also I realized whether it's possible to let the laser propagate in the y direction and the electron will then flow in the X direction (then it would be a 90 degree rotation of my problem). This way I don't really need the modification anymore. Thanks

@Z10Frank
Copy link
Contributor

Your modifications seem ok.

With a solver for a motion along x, the vector product B = beta0 x E gives Bx=0, By = -betaEz, Bz = betaEy, that's why Bx does not exist. However, Ez = - \partial_z Phi, which in 2D is not defined (there are no variations along z), so also By=0.

For a solver for a motion along y, you would have Bx = betaEz, By=0, Bx = -betaEx. In this case, since Ez = - \partial_z Phi = 0 as before, so also Bx = 0.

Anyway, as you say if your laser propagates along y you can make the electrons flow along X and you don't need a modified solver. I'll close the issue then, feel free to reopen it if in the future you will need again a modified solver.

@ycaophysics
Copy link
Author

This is what I have for B field. However, I'm not really sure about the initial field 2D, and I'm not sure whether the Bz loop i<nx_p, j<ny_d indices needs change for beta0*Ex.
Also, does boundary condition initialization matter a lot in the simulation? Could using a large transverse y size avoid unphysical phenomenon from boundaries? Thanks

void ElectroMagn2D::initB_relativistic_Poisson( Patch *patch, double gamma_mean )
{
// gamma_mean is the average Lorentz factor of the species whose fields will be computed
// See for example https://doi.org/10.1016/j.nima.2016.02.043 for more details

Field2D *Ex2D  = static_cast<Field2D *>( Ex_rel_ );
Field2D *Bz2D  = static_cast<Field2D *>( Bz_rel_ );
// By is zero everywhere
Field2D *By2D  = static_cast<Field2D *>( By_rel_ );
// ------------------------------------------
// Compute the field Bz; Bx and By are identically zero
// ------------------------------------------

double beta_mean = sqrt( 1.-1./gamma_mean/gamma_mean );
MESSAGE( 0, "In relativistic Poisson solver, gamma_mean = " << gamma_mean );

// By^(p,d) is identically zero
// (hypothesis of negligible J transverse with respect to Jx)
MESSAGE( 1, "Computing By, relativistic Poisson problem" );
for( unsigned int i=0; i<nx_p; i++ ) {
    for( unsigned int j=0; j<ny_d; j++ ) {
        ( *By2D )( i, j ) = 0.;
    }
}
MESSAGE( 1, "Bx: done" );

// Bz^(d,d) from Ex^(p,d)
MESSAGE( 1, "Computing Bz from scalar potential, relativistic Poisson problem" );
for( unsigned int i=0; i<nx_p; i++ ) {
    for( unsigned int j=0; j<ny_d; j++ ) {
        ( *Bz2D )( i, j ) = -beta_mean*( *Ex2D )( i, j );
    }
}
MESSAGE( 1, "Bz: done" );

} // initB_relativistic_Poisson

@Z10Frank Z10Frank reopened this Oct 22, 2020
@Z10Frank
Copy link
Contributor

I see your Bx = 0, By = 0, Bz = -betaEx as it should be.

Now, remember the entering of these fields in the Yee scheme to solve the electromagnetic fields: Ex is dual, primal (d,p), while Bz is dual, dual (d,d). This means that the indices in the loop must go from 0 to nx_d for i, and from 0 to ny_p, to follow the entering of the Ex field that you are putting inside Bz.

Afterwards, in center_fields_from_relativistic_Poisson there is the centering of the B fields. Your Bz is now centered as Ex (d,p). To center is as (d,d), you will need to use an interpolation: Bz(i,j) = 0.5*( ( *Bz2Drel )( i, j ) + ( *Bz2Drel )( i, j-1 ) ), the same for Bz2D0.

Sure, for the first tests you can try to use a very large simulation box to avoid border effects and see if it is ok for your simulations.

@ycaophysics
Copy link
Author

Do you mean by changing this section (other sections remain the same) in "center_fields_from_relativistic_Poisson"? That's all that is required for poisson solver right? Thanks

// Bz (d,d) - remember that Bzrel is centered as Eyrel (p,d)
// now Exrel(d,p) by modification
for( unsigned int i=1; i<nx_d-1; i++ ) {
for( unsigned int j=0; j<ny_d; j++ ) {
( Bz2D )( i, j ) = 0.5( ( *Bz2Drel )( i, j ) + ( *Bz2Drel )( i, j-1 ) );
( Bz2D0 )( i, j )= 0.5( ( *Bz2Drel )( i, j ) + ( *Bz2Drel )( i, j-1 ) );
}

@Z10Frank
Copy link
Contributor

Yes, for a solver with an x motion you had Bz = betaEy, but for a y motion Bz = -betaEx, so that comment in the code you reported does not apply, it should be instead
// Bz (d,d) - remember that Bzrel is centered as Exrel (d,p)

Your modifications should be correct.

@ycaophysics
Copy link
Author

The compile fails when linking smilei due to multiple definition. (I think I could also try to modify the boundary condition first and then compile, since the compilation process could be long and problematic)
Anyway this is the error message. Thanks

Linking smilei
build/src/ElectroMagn/ElectroMagn2D.o: In function bool std::operator==<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*)': /usr/include/c++/4.8.5/bits/basic_string.h:249: multiple definition of ElectroMagn2D::ElectroMagn2D(Params&, DomainDecomposition*, std::vector<Species*, std::allocator<Species*> >&, Patch*)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/usr/include/c++/4.8.5/bits/basic_string.h:249: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function _INTERNAL4ddedea8::__gnu_cxx::__exchange_and_add(int volatile*, int)': /usr/include/c++/4.8.5/ext/atomicity.h:49: multiple definition of ElectroMagn2D::initElectroMagn2DQuantities(Params&, Patch*)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/usr/include/c++/4.8.5/ext/atomicity.h:49: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function std::string::_Rep::_M_dispose(std::allocator<char> const&)': /usr/include/c++/4.8.5/bits/basic_string.h:249: multiple definition of ElectroMagn2D::ElectroMagn2D(Params&, DomainDecomposition*, std::vector<Species*, std::allocator<Species*> >&, Patch*)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/usr/include/c++/4.8.5/bits/basic_string.h:249: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function std::string::_Rep::_M_dispose(std::allocator<char> const&)': /usr/include/c++/4.8.5/bits/basic_string.h:249: multiple definition of ElectroMagn2D::ElectroMagn2D(ElectroMagn2D*, Params&, Patch*)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/usr/include/c++/4.8.5/bits/basic_string.h:249: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::ElectroMagn2D(ElectroMagn2D*, Params&, Patch*)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:62: multiple definition of ElectroMagn2D::ElectroMagn2D(ElectroMagn2D*, Params&, Patch*)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:62: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::ElectroMagn2D(ElectroMagn2D*, Params&, Patch*)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:62: multiple definition of ElectroMagn2D::~ElectroMagn2D()'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:62: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::~ElectroMagn2D()': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:249: multiple definition of ElectroMagn2D::~ElectroMagn2D()'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:249: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::~ElectroMagn2D()': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:250: multiple definition of ElectroMagn2D::~ElectroMagn2D()'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:250: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::~ElectroMagn2D()': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:249: multiple definition of ElectroMagn2D::compute_r()'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:249: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::compute_r()': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:312: multiple definition of ElectroMagn2D::compute_Ap(Patch*)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:312: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function Field::operator()(unsigned int, unsigned int)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/Field/Field.h:157: multiple definition of ElectroMagn2D::compute_Ap_relativistic_Poisson(Patch*, double)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/Field/Field.h:157: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function Field::operator()(unsigned int, unsigned int)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/Field/Field.h:157: multiple definition of ElectroMagn2D::compute_pAp()'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/Field/Field.h:157: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::compute_pAp()': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:454: multiple definition of ElectroMagn2D::update_pand_r(double, double)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:454: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::update_pand_r(double, double)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:460: multiple definition of ElectroMagn2D::update_p(double, double)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:460: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::update_p(double, double)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:472: multiple definition of ElectroMagn2D::center_fields_from_relativistic_Poisson(Patch*)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:472: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::center_fields_from_relativistic_Poisson(Patch*)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:662: multiple definition of ElectroMagn2D::sum_rel_fields_to_em_fields(Patch*)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:662: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::sum_rel_fields_to_em_fields(Patch*)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:815: multiple definition of ElectroMagn2D::centeringE(std::vector<double, std::allocator >)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:815: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::centeringE(std::vector<double, std::allocator<double> >)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:841: multiple definition of ElectroMagn2D::centeringErel(std::vector<double, std::allocator >)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:841: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::centeringErel(std::vector<double, std::allocator<double> >)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:859: multiple definition of ElectroMagn2D::saveMagneticFields(bool)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:859: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::saveMagneticFields(bool)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:919: multiple definition of ElectroMagn2D::centerMagneticFields()'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:919: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::centerMagneticFields()': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:1217: multiple definition of ElectroMagn2D::binomialCurrentFilter(unsigned int, std::vector<unsigned int, std::allocator >)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:1217: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::binomialCurrentFilter(unsigned int, std::vector<unsigned int, std::allocator<unsigned int> >)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:940: multiple definition of ElectroMagn2D::customFIRCurrentFilter(unsigned int, std::vector<unsigned int, std::allocator >, std::vector<double, std::allocator >)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:940: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function Field::copyFrom(Field*)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/Field/Field.h:233: multiple definition of ElectroMagn2D::createField(std::string, Params&)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/Field/Field.h:233: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function std::string::_Rep::_M_dispose(std::allocator<char> const&)': /usr/include/c++/4.8.5/bits/basic_string.h:249: multiple definition of ElectroMagn2D::computeTotalRhoJ()'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/usr/include/c++/4.8.5/bits/basic_string.h:249: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::computeTotalRhoJ()': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:1277: multiple definition of ElectroMagn2D::computeTotalEnvChi()'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:1277: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::computeTotalEnvChi()': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:1322: multiple definition of ElectroMagn2D::computePoynting()'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:1322: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::computePoynting()': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:1452: multiple definition of ElectroMagn2D::applyExternalField(Field*, Profile*, Patch*)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:1452: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::applyExternalField(Field*, Profile*, Patch*)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:1459: multiple definition of ElectroMagn2D::applyPrescribedField(Field*, Profile*, Patch*, double)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:1459: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function std::string::_Rep::_M_dispose(std::allocator<char> const&)': /usr/include/c++/4.8.5/bits/basic_string.h:249: multiple definition of ElectroMagn2D::initAntennas(Patch*, Params&)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/usr/include/c++/4.8.5/bits/basic_string.h:249: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function std::string::_Rep::_M_dispose(std::allocator<char> const&)': /usr/include/c++/4.8.5/bits/basic_string.h:249: multiple definition of ElectroMagn2D::initRelativisticPoissonFields(Patch*)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/usr/include/c++/4.8.5/bits/basic_string.h:249: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function std::string::_Rep::_M_dispose(std::allocator<char> const&)': /usr/include/c++/4.8.5/bits/basic_string.h:249: multiple definition of ElectroMagn2D::initB_relativistic_Poisson(Patch*, double)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/usr/include/c++/4.8.5/bits/basic_string.h:249: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::initB_relativistic_Poisson(Patch*, double)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:618: multiple definition of ElectroMagn2D::initE_relativistic_Poisson(Patch*, double)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:618: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::initE_relativistic_Poisson(Patch*, double)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:564: multiple definition of ElectroMagn2D::initE(Patch*)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:564: first defined here
build/src/ElectroMagn/ElectroMagn2D.o: In function ElectroMagn2D::initE(Patch*)': /rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/ElectroMagn2D.cpp:492: multiple definition of ElectroMagn2D::initPoisson(Patch*)'
build/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.o:/rds/general/user/yc15818/home/Smilei_conda_mod/Smilei/src/ElectroMagn/.ipynb_checkpoints/ElectroMagn2D-checkpoint.cpp:492: first defined here

@Z10Frank
Copy link
Contributor

Z10Frank commented Oct 27, 2020

Each time you modified a method used by the Poisson solver, you created a new method with the same name of the old one? This could cause the multiple definition error.

PS as it was written in the link I sent you on Element, for compiling issues normally please provide us details of your environment, i.e. the result of the commands below.

git describe --all --long
make env
echo $LD_LIBRARY_PATH 
python -m sysconfig
ldd smilei

In this case, maybe it's just a problem of creating a homonym method.

@ycaophysics
Copy link
Author

Do you mean changing the name of the modified function could avoid this problem? (I'm not very sure about what creating a homonym method means) The compilation is fine until linking smilei. Thanks

@Z10Frank
Copy link
Contributor

Creating a homonym method means that you created two functions with the same name and input arguments, so the compiler cannot know which one is the "true" one.

First, try to download smilei in another folder, without modifying it and see if it compiles and runs correctly. If it doesn't, please provide us details on your system configuration, as stated in my previous answer, and these compilation problems should be addressed before modifying the solver.

If without modifications the code compiles and runs correctly, I see two recommended steps:

  1. simple, quick step, suggested for testing but not too elegant:
    overwrite the old functions you have modified (those with the solver for the x direction) with your functions for your solver for the y direction (keep a backup of the old functions or use git to keep track of the modifications and in case revert them, do not lose your work). This way, there should be only one function for the solver and the compilation should work. If the code compiled without modifications, and now it doesn't, then there is some error in your implementation.

  2. more elegant implementation, to do after solution 1) works:
    Starting from the github version of the code, through branches "if" you can make the solver work for the x or y direction depending on a flag in input. This will need to read in input which solver to use and needs some more modifications.

@ycaophysics
Copy link
Author

The compilation was fine without modification. I did replace the old function with the new one (like method 1) but the compilation for the new one shows the multiple definition error. I wonder if I need to change other files too to make the modification.

@Z10Frank
Copy link
Contributor

Z10Frank commented Nov 5, 2020

So if without modification it compiles, there's something to fix in your implementation.

I suggest to take the original code without modifications, the version that compiles. Starting from there, gradually put your modifications in the place of the corresponding original parts of the solver, by small steps (like few lines of code, or just one block each time, like a for loop). Alternatively, comment everything in the old solver methods and then put your modifications gradually, by small steps.

Each time you put a small modification, try to compile. Add the next modification only if it compiles. If at a certain point errors arise, you found a part that is giving errors to the compiler. Then fix the errors of that part, and so on until you have put in place all your modified solver.

@ycaophysics
Copy link
Author

I was a little confused. I modified the code and compiled, the code shows the multiple definition error. I tried modifying one function and leaving others unchanged, it shows the same thing. However, when I changed the that single file back to where it begins (when the compilation was okay), the multiple definition error shows again when linking Smilei (I did "make clean" everytime). I don't know what's wrong here.
Maybe the code wouldn't compile twice in one folder? Or I mistakenly use another version of the code file? (I'm kind of sure it's the same code, just copied and pasted from Jupterlab)
Thanks

@Z10Frank
Copy link
Contributor

Z10Frank commented Nov 7, 2020

Yes, I had understood the problem from your previous message, in my previous answer there was a strategy to find the error. The code can perfectly compile multiple times in the same folder if the C++ synthax rules are respected. If you obtain an error probably something should be fixed in your modifications.

Again, please try to take the code version that compiles without modifications, then try to do your modifications through small incremental steps and at each little step try to compile. If it does not compile, there is an error in the little step you have made and should be corrected to make the code compile.

@ycaophysics
Copy link
Author

Okay I finally got the problem (and it's kind of stupid). The modification is okay. But when I modified the code, the system automatically creates a hidden backup folder that contains the original file, and therefore creating a homonym when compiling. I fixed it right now and it compiles okay with modification. Sorry for the trouble. Thanks

@Z10Frank
Copy link
Contributor

Z10Frank commented Nov 7, 2020

Very good, now it's time to test your new solver.
I'll close the issue for the moment, feel free to reopen it if further related help is needed.

@Z10Frank Z10Frank closed this as completed Nov 7, 2020
@iltommi
Copy link
Contributor

iltommi commented Nov 7, 2020

When you posted the error log I noticed the weird path containing .ipynb_checkpoints but didn't pay attention.

Could you please tell us which editor/IDE does this?
I'm worried that someone could get again in trouble and maybe we can prevent this behavior.

@ycaophysics
Copy link
Author

It's jupyterlab or jupyter notebook that could create these errors (the editor automatically creates backup files).

@ycaophysics
Copy link
Author

ycaophysics commented Nov 9, 2020

The simulation result with y direction relativistic solver doesn't seem so good compared to situation without solve-relativistic-poisson. I'm now thinking about two possible problems. 1. Does "solve relativistic poisson" only applies to the plasma species inside the first simulation window? Since my window is moving, it might be the case that the species initialized after some time do not received the correction? (The density profile seems to get a discontinuity in density) The total number of iterations is about 4000, which should work under the 50000 default "relativistic_poisson_max_iteration" value. 2. Does the "gamma_mean" variable in the functions you mentioned only applies to the x longitudinal direction? Since in the explanation text it says "A relativistic mean velocity in the x direction and a negligible energy spread are assumed in the hypotheses of this procedure".
Thanks
(I can't attach the movie of the weird density evolution here, so I'll probably send that to the chat room?)

@Z10Frank Z10Frank reopened this Nov 9, 2020
@Z10Frank
Copy link
Contributor

Z10Frank commented Nov 9, 2020

  1. In the doc and in Smilei.cpp you'll see that the solver is applied to a species with a flag relativistic_field_initialization.
    If the species is frozen, the solver will be used on that species when the species stops to be frozen. If your species is not in the window and it is not frozen, the solver will not act on it, maybe this is the problem.

  2. gamma_mean is the Lorentz relativistic factor, it is independent of the motion direction

I cannot see your movie, the link did not work. Can I see the input namelist?

@ycaophysics
Copy link
Author

After I added the relativistic_field_initialization, the error message shows this (I'm not so good at C++ programming and not sure if that's something wrong with the modification):

Stack trace (most recent call last):
#6 Object "[0xffffffffffffffff]", at 0xffffffffffffffff, in
#5 Object "./smilei", at 0x5f0fa3, in
smilei: malloc.c:4048: _int_malloc: Assertion `(unsigned long) (size) >= (unsigned long) (nb)' failed.

(I'm attaching the modified cpp script and the job script here)

smilei_script.py.txt
ElectroMagn2D.cpp.txt

@Z10Frank
Copy link
Contributor

This happens with the non-modified solver? If not, the problem lies in the modification.

@Z10Frank Z10Frank added the needs-user-input the issue cannot be resolved without additional information label Mar 8, 2021
@Z10Frank
Copy link
Contributor

Z10Frank commented Mar 8, 2021

Closing the issue, feel free to reopen it if you have news.

@Z10Frank Z10Frank closed this as completed Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request something that could be added to the code needs-user-input the issue cannot be resolved without additional information
Projects
None yet
Development

No branches or pull requests

3 participants