Skip to content

Commit

Permalink
clean up of ElectroMagnBC2D_SM.cpp and fix for Francesco email adress
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesprouveur committed Nov 5, 2023
1 parent 6b9be13 commit f742eeb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 120 deletions.
2 changes: 1 addition & 1 deletion doc/Sphinx/Overview/partners.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Partners
| | * `Julien Dérouillat <[email protected]>`_ |
| | * `Haithem Kallala <[email protected]>`_ |
| | * `Mathieu Lobet <[email protected]>`_ |
| | * `Francesco Massimo <francesco.massimo@cea.fr>`_ |
| | * `Francesco Massimo <francesco.massimo@universite-paris-saclay.fr>`_ |
| | * `Charles Prouveur <[email protected]>`_ |
| | |
+------------+---------------------------------------------------------------------------------------------------------+
Expand Down
136 changes: 17 additions & 119 deletions src/ElectroMagnBC/ElectroMagnBC2D_SM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ ElectroMagnBC2D_SM::ElectroMagnBC2D_SM( Params &params, Patch *patch, unsigned i
// Calculate axes indices
axis0_ = i_boundary_ / 2; // axis normal to border
axis1_ = axis0_ == 0 ? 1 : 0; // other axis (tangent to border)
//axis2_ = axis0_ == 2 ? 1 : 2; // other axis (tangent to border)
sign_ = (double) (i_boundary_ % 2) *2 - 1.; // -1 or 1 for min or max

// Index where to set the field along axis 0
Expand All @@ -44,7 +43,6 @@ ElectroMagnBC2D_SM::ElectroMagnBC2D_SM( Params &params, Patch *patch, unsigned i
B_val[axis1_].resize( n_p[axis1_], 0. ); // primal in the other direction
B_val[2 ].resize( n_d[axis1_], 0. ); // dual in the other direction

// allocation on te device
smilei::tools::gpu::HostDeviceMemoryManagement::DeviceAllocate( B_val[0].data(), B_val[0].size() );
smilei::tools::gpu::HostDeviceMemoryManagement::DeviceAllocate( B_val[1].data(), B_val[1].size() );
smilei::tools::gpu::HostDeviceMemoryManagement::DeviceAllocate( B_val[2].data(), B_val[2].size() );
Expand Down Expand Up @@ -72,21 +70,10 @@ ElectroMagnBC2D_SM::~ElectroMagnBC2D_SM()
{
for (int i=0 ; i<B_val.size() ; ++i){
smilei::tools::gpu::HostDeviceMemoryManagement::DeviceFree( B_val[i].data(), B_val[i].size() );
//delete B_val[i];
//delete[] B_val[i];
}
//B_val.swap(std::vector<std::vector<double> > ());
/*if( B_val[1] ) {
smilei::tools::gpu::HostDeviceMemoryManagement::DeviceFree( B_val[1].data(), B_val[1].size() );
delete B_val[1];
}
if( B_val[2] ) {
smilei::tools::gpu::HostDeviceMemoryManagement::DeviceFree( B_val[2].data(), B_val[2].size() );
delete B_val[2];
}*/
}



void ElectroMagnBC2D_SM::save_fields( Field *my_field, Patch *patch )
{
Field2D *field2D=static_cast<Field2D *>( my_field );
Expand Down Expand Up @@ -126,55 +113,40 @@ void ElectroMagnBC2D_SM::disableExternalFields()
B_val[2].resize( 0 );
}



// ---------------------------------------------------------------------------------------------------------------------
// Apply Boundary Conditions
// ---------------------------------------------------------------------------------------------------------------------
void ElectroMagnBC2D_SM::apply( ElectroMagn *EMfields, double time_dual, Patch *patch )
{
if( patch->isBoundary( i_boundary_ ) ) {

// Static cast of the fields
/*std::vector<Field2D*> E( 3 );
E[0] = static_cast<Field2D *>( EMfields->Ex_ );
E[1] = static_cast<Field2D *>( EMfields->Ey_ );
E[2] = static_cast<Field2D *>( EMfields->Ez_ );
std::vector<Field2D*> B( 3 );
B[0] = static_cast<Field2D *>( EMfields->Bx_ );
B[1] = static_cast<Field2D *>( EMfields->By_ );
B[2] = static_cast<Field2D *>( EMfields->Bz_ );//*/


const Field *E[3]{ EMfields->Ex_, EMfields->Ey_, EMfields->Ez_ };
const Field *B[3]{ EMfields->Bx_, EMfields->By_, EMfields->Bz_ };


const double *const __restrict__ E0 = E[0]->data_;//E[axis0_]->data_;
const double *const __restrict__ E1 = E[1]->data_;//E[axis1_]->data_;
const double *const __restrict__ E0 = E[0]->data_;
const double *const __restrict__ E1 = E[1]->data_;
const double *const __restrict__ E2 = E[2]->data_;
double *const __restrict__ B0 = B[0]->data_;//B[axis0_]->data_;
double *const __restrict__ B1 = B[1]->data_;//B[axis1_]->data_;
double *const __restrict__ B0 = B[0]->data_;
double *const __restrict__ B1 = B[1]->data_;
double *const __restrict__ B2 = B[2]->data_;

const double *const __restrict__ B_ext0 = B_val[0].data();//B_val[axis0_].data();
const double *const __restrict__ B_ext1 = B_val[1].data();//B_val[axis1_].data();
const double *const __restrict__ B_ext0 = B_val[0].data();
const double *const __restrict__ B_ext1 = B_val[1].data();
const double *const __restrict__ B_ext2 = B_val[2].data();

#ifdef SMILEI_OPENACC_MODE
const int sizeofE0 = E[0]->number_of_points_;//E[axis0_]->number_of_points_;
const int sizeofE1 = E[1]->number_of_points_;//E[axis1_]->number_of_points_;
const int sizeofE0 = E[0]->number_of_points_;
const int sizeofE1 = E[1]->number_of_points_;
const int sizeofE2 = E[2]->number_of_points_;
const int sizeofB0 = B[0]->number_of_points_;//B[axis0_]->number_of_points_;
const int sizeofB1 = B[1]->number_of_points_;//[axis1_]->number_of_points_;
const int sizeofB0 = B[0]->number_of_points_;
const int sizeofB1 = B[1]->number_of_points_;
const int sizeofB2 = B[2]->number_of_points_;

const int B_ext_size0 = B_val[0].size();//B_val[axis0_].size();
const int B_ext_size1 = B_val[1].size();//B_val[axis1_].size();
const int B_ext_size2 = B_val[2].size();//*/
const int B_ext_size0 = B_val[0].size();
const int B_ext_size1 = B_val[1].size();
const int B_ext_size2 = B_val[2].size();
#endif


const int isBoundary1min = patch->isBoundary( axis1_, 0 );
const int isBoundary1max = patch->isBoundary( axis1_, 1 );

Expand Down Expand Up @@ -216,41 +188,13 @@ void ElectroMagnBC2D_SM::apply( ElectroMagn *EMfields, double time_dual, Patch *
#pragma omp teams distribute parallel for
#endif
for( unsigned int j=isBoundary1min; j<n1p-isBoundary1max ; j++ ) {
/*( *B[1] )( iB_[1], j )
= Alpha_ * ( *E[2] )( iB_[0] , j )
+ Beta_ * ( ( *B[1] )( iB_[1]-sign_, j )-B_val[1][j] )
+ Gamma_ * db1[j]
+ Delta_ * ( ( *B[0] )( iB_[0], j+1 )-B_val[0][j+1] )
+ Epsilon_* ( ( *B[0] )( iB_[0], j )-B_val[0][j ] )
+ B_val[1][j];//*/
/*B1[ iB1*n1p + j ]
= Alpha_ * E2[ iB0*n1p + j ]
+ Beta_ * ( B1[p1*n1p + j] - B_ext1[j] )
+ Gamma_ * db1[j]
+ Delta_ * ( B0[iB0*n1p + j+1 ] - B_ext0[j+1] )
+ Epsilon_* ( B0[iB0*n1p + j ] - B_ext0[j ] )
+ B_ext1[j];//*/
/*B1[ iB1*nyp + j ]
= Alpha_ * E2[ iB0*nyp + j ]
+ Beta_ * ( B1[p1*nyp + j] - B_ext1[j] )
+ Gamma_ * db1[j]
+ Delta_ * ( B0[iB0*nyd + j+1 ] - B_ext0[j+1] )
+ Epsilon_* ( B0[iB0*nyd + j ] - B_ext0[j ] )
+ B_ext1[j]; //*/
/*B1[ iB1*nyd + j ]
= Alpha_ * E2[ iB0*nyp + j ]
+ Beta_ * ( B1[p1*nyd + j] - B_ext1[j] )
+ Gamma_ * db1[j]
+ Delta_ * ( B0[iB0*nyp + j+1 ] - B_ext0[j+1] )
+ Epsilon_* ( B0[iB0*nyp + j ] - B_ext0[j ] )
+ B_ext1[j];//*/
B1[ iB1*nyp + j ]
= Alpha_ * E2[ iB0*nyp + j ]
+ Beta_ * ( B1[p1*nyp + j] - B_ext1[j] )
+ Gamma_ * db1[j]
+ Delta_ * ( B0[iB0*nyd + j+1 ] - B_ext0[j+1] )
+ Epsilon_* ( B0[iB0*nyd + j ] - B_ext0[j ] )
+ B_ext1[j]; //*/
+ B_ext1[j];
}
} else { // for Bx^(p,d)
#ifdef SMILEI_OPENACC_MODE
Expand All @@ -261,46 +205,15 @@ void ElectroMagnBC2D_SM::apply( ElectroMagn *EMfields, double time_dual, Patch *
#pragma omp teams distribute parallel for
#endif
for( unsigned int j=isBoundary1min; j<n1p-isBoundary1max ; j++ ) {
/*( *B[0] )( j, iB_[0] )
= -Alpha_ * ( *E[2] )( j, iB_[1] )
+ Beta_ * ( ( *B[0] )( j, iB_[0]-sign_ )-B_ext0[j] )
+ Gamma_ * db1[j]
+ Delta_ * ( ( *B[1] )( j+1, iB_[1] )-B_ext1[j+1] )
+ Epsilon_* ( ( *B[1] )( j , iB_[1] )-B_ext1[j] )
+ B_ext0[j];//*/
/*B0[ iB0 + n0d * j ]
= -Alpha_ * E2[iB1+n0d * j]
+ Beta_ * ( B0[p0+n0d * j ] - B_ext0[j] )
+ Gamma_ * db1[j]
+ Delta_ * ( B1[iB1+n0d * (j+1) ] - B_ext1[j+1] )
+ Epsilon_* ( B1[iB1+n0d * j ] - B_ext1[j ] )
+ B_ext0[j];//*/
/*B1[ j*nyp + iB1 ]
= -Alpha_ * E2[iB1+j*nyp]
+ Beta_ * ( B1[p1+j*nyp ] - B_ext1[j] )
+ Gamma_ * db1[j]
+ Delta_ * ( B0[iB0+(j+1)*nyd ] - B_ext0[j+1] )
+ Epsilon_* ( B0[iB0+j*nyd ] - B_ext0[j ] )
+ B_ext1[j];//*/
/*B0[ iB0 + nyd * j ]
= -Alpha_ * E2[iB1+nyp * j]
+ Beta_ * ( B0[p0+nyd * j ] - B_ext0[j] )
+ Gamma_ * db1[j]
+ Delta_ * ( B1[iB1+nyp * (j+1) ] - B_ext1[j+1] )
+ Epsilon_* ( B1[iB1+nyp * j ] - B_ext1[j ] )
+ B_ext0[j];*/
B0[ iB0 + nyd * j ]
= -Alpha_ * E2[iB1+nyp * j]
+ Beta_ * ( B0[p0+nyd * j ] - B_ext0[j] )
+ Gamma_ * db1[j]
+ Delta_ * ( B1[iB1+nyp * (j+1) ] - B_ext1[j+1] )
+ Epsilon_* ( B1[iB1+nyp * j ] - B_ext1[j ] )
+ B_ext0[j];//*/


+ B_ext0[j];
}
}

smilei::tools::gpu::HostDeviceMemoryManagement::DeviceFree( db1, b1_size );

// Lasers polarized along axis 2
Expand All @@ -315,7 +228,6 @@ void ElectroMagnBC2D_SM::apply( ElectroMagn *EMfields, double time_dual, Patch *
}
}
}

smilei::tools::gpu::HostDeviceMemoryManagement::DeviceAllocateAndCopyHostToDevice( db2, b2_size );

// for Bz^(d,d)
Expand All @@ -328,13 +240,6 @@ void ElectroMagnBC2D_SM::apply( ElectroMagn *EMfields, double time_dual, Patch *
#pragma omp teams distribute parallel for
#endif
for( unsigned int j=isBoundary1min; j<n1d-isBoundary1max ; j++ ) {
/*( *B[2] )( iB_[2], j )
= -Alpha_ * ( *E[1] )( iB_[0] , j )
+ Beta_ * ( ( *B[2] )( iB_[2]-sign_, j )- B_ext2[j] )
+ Gamma_ * db2[j]
+ B_ext2[j];//*/
//B2[ iB2*n1p + j ] = -Alpha_ * E1[iB0*n1p + j] + Beta_ * (B2[ p2*n1p + j] - B_ext2[j])
//B2[ iB2*nyd + j ] = -Alpha_ * E1[iB0*nyd + j] + Beta_ * (B2[ p2*nyd + j] - B_ext2[j])
B2[ iB2*nyd + j ] = -Alpha_ * E1[iB0*nyd + j] + Beta_ * (B2[ p2*nyd + j] - B_ext2[j])
+ Gamma_ * db2[j] + B_ext2[j];

Expand All @@ -348,17 +253,10 @@ void ElectroMagnBC2D_SM::apply( ElectroMagn *EMfields, double time_dual, Patch *
#pragma omp teams distribute parallel for
#endif
for( unsigned int j=isBoundary1min; j<n1d-isBoundary1max ; j++ ) {
/*( *B[2] )( j, iB_[2] )
= Alpha_ * ( *E[0] )( j, iB_[1] )
+ Beta_ * ( ( *B[2] )( j, iB_[2]-sign_ )- B_ext2[j] )
+ Gamma_ * db2[j]
+ B_ext2[j];//*/
//B2[ j*n0d + iB2 ] = Alpha_ * E0[j*n0d + iB1] + Beta_ * (B2[j*n0d + p2] - B_ext2[j])
B2[ j*nyd + iB2 ] = Alpha_ * E0[j*nyp + iB1] + Beta_ * (B2[j*nyd + p2] - B_ext2[j])
+ Gamma_ * db2[j] + B_ext2[j];//*/
+ Gamma_ * db2[j] + B_ext2[j];
}
}

smilei::tools::gpu::HostDeviceMemoryManagement::DeviceFree( db2, b2_size );
}
}

0 comments on commit f742eeb

Please sign in to comment.