diff options
author | 2019-10-01 14:35:53 -0700 | |
---|---|---|
committer | 2019-10-01 14:35:53 -0700 | |
commit | 81e4a0f3407af2aad99cacaaba483de80189d198 (patch) | |
tree | d24554d8a00525446c15a382dd5be875cbdd2fe5 /Source/Python | |
parent | ca5e5970269203f4fe2d3f56ae0eb3472f5340e4 (diff) | |
download | WarpX-81e4a0f3407af2aad99cacaaba483de80189d198.tar.gz WarpX-81e4a0f3407af2aad99cacaaba483de80189d198.tar.zst WarpX-81e4a0f3407af2aad99cacaaba483de80189d198.zip |
Allowed single precision in the Python interface
Diffstat (limited to 'Source/Python')
-rw-r--r-- | Source/Python/WarpXWrappers.cpp | 73 | ||||
-rw-r--r-- | Source/Python/WarpXWrappers.h | 50 |
2 files changed, 68 insertions, 55 deletions
diff --git a/Source/Python/WarpXWrappers.cpp b/Source/Python/WarpXWrappers.cpp index c6d7dfdb8..be9ec9519 100644 --- a/Source/Python/WarpXWrappers.cpp +++ b/Source/Python/WarpXWrappers.cpp @@ -1,7 +1,4 @@ -#include <AMReX.H> -#include <AMReX_BLProfiler.H> - #include <WarpXWrappers.h> #include <WarpXParticleContainer.H> #include <WarpX.H> @@ -10,7 +7,7 @@ namespace { - double** getMultiFabPointers(const amrex::MultiFab& mf, int *num_boxes, int *ncomps, int *ngrow, int **shapes) + amrex::Real** getMultiFabPointers(const amrex::MultiFab& mf, int *num_boxes, int *ncomps, int *ngrow, int **shapes) { *ncomps = mf.nComp(); *ngrow = mf.nGrow(); @@ -18,14 +15,14 @@ namespace int shapesize = AMREX_SPACEDIM; if (mf.nComp() > 1) shapesize += 1; *shapes = (int*) malloc(shapesize * (*num_boxes) * sizeof(int)); - double** data = (double**) malloc((*num_boxes) * sizeof(double*)); + amrex::Real** data = (amrex::Real**) malloc((*num_boxes) * sizeof(amrex::Real*)); #ifdef _OPENMP #pragma omp parallel #endif for ( amrex::MFIter mfi(mf, false); mfi.isValid(); ++mfi ) { int i = mfi.LocalIndex(); - data[i] = (double*) mf[mfi].dataPtr(); + data[i] = (amrex::Real*) mf[mfi].dataPtr(); for (int j = 0; j < AMREX_SPACEDIM; ++j) { (*shapes)[shapesize*i+j] = mf[mfi].box().length(j); } @@ -53,6 +50,16 @@ namespace extern "C" { + int warpx_Real_size() + { + return (int)sizeof(amrex::Real); + } + + int warpx_ParticleReal_size() + { + return (int)sizeof(amrex::ParticleReal); + } + int warpx_nSpecies() { auto & mypc = WarpX::GetInstance().GetPartContainer(); @@ -165,9 +172,9 @@ extern "C" } void warpx_addNParticles(int speciesnumber, int lenx, - double* x, double* y, double* z, - double* vx, double* vy, double* vz, - int nattr, double* attr, int uniqueparticles) + amrex::ParticleReal* x, amrex::ParticleReal* y, amrex::ParticleReal* z, + amrex::ParticleReal* vx, amrex::ParticleReal* vy, amrex::ParticleReal* vz, + int nattr, amrex::ParticleReal* attr, int uniqueparticles) { auto & mypc = WarpX::GetInstance().GetPartContainer(); auto & myspc = mypc.GetParticleContainer(speciesnumber); @@ -180,14 +187,14 @@ extern "C" ConvertLabParamsToBoost(); } - double warpx_getProbLo(int dir) + amrex::Real warpx_getProbLo(int dir) { WarpX& warpx = WarpX::GetInstance(); const amrex::Geometry& geom = warpx.Geom(0); return geom.ProbLo(dir); } - double warpx_getProbHi(int dir) + amrex::Real warpx_getProbHi(int dir) { WarpX& warpx = WarpX::GetInstance(); const amrex::Geometry& geom = warpx.Geom(0); @@ -200,7 +207,7 @@ extern "C" return myspc.TotalNumberOfParticles(); } - double** warpx_getEfield(int lev, int direction, + amrex::Real** warpx_getEfield(int lev, int direction, int *return_size, int *ncomps, int *ngrow, int **shapes) { auto & mf = WarpX::GetInstance().getEfield(lev, direction); return getMultiFabPointers(mf, return_size, ncomps, ngrow, shapes); @@ -212,7 +219,7 @@ extern "C" return getMultiFabLoVects(mf, return_size, ngrow); } - double** warpx_getEfieldCP(int lev, int direction, + amrex::Real** warpx_getEfieldCP(int lev, int direction, int *return_size, int *ncomps, int *ngrow, int **shapes) { auto & mf = WarpX::GetInstance().getEfield_cp(lev, direction); return getMultiFabPointers(mf, return_size, ncomps, ngrow, shapes); @@ -224,7 +231,7 @@ extern "C" return getMultiFabLoVects(mf, return_size, ngrow); } - double** warpx_getEfieldFP(int lev, int direction, + amrex::Real** warpx_getEfieldFP(int lev, int direction, int *return_size, int *ncomps, int *ngrow, int **shapes) { auto & mf = WarpX::GetInstance().getEfield_fp(lev, direction); return getMultiFabPointers(mf, return_size, ncomps, ngrow, shapes); @@ -236,7 +243,7 @@ extern "C" return getMultiFabLoVects(mf, return_size, ngrow); } - double** warpx_getBfield(int lev, int direction, + amrex::Real** warpx_getBfield(int lev, int direction, int *return_size, int *ncomps, int *ngrow, int **shapes) { auto & mf = WarpX::GetInstance().getBfield(lev, direction); return getMultiFabPointers(mf, return_size, ncomps, ngrow, shapes); @@ -248,7 +255,7 @@ extern "C" return getMultiFabLoVects(mf, return_size, ngrow); } - double** warpx_getBfieldCP(int lev, int direction, + amrex::Real** warpx_getBfieldCP(int lev, int direction, int *return_size, int *ncomps, int *ngrow, int **shapes) { auto & mf = WarpX::GetInstance().getBfield_cp(lev, direction); return getMultiFabPointers(mf, return_size, ncomps, ngrow, shapes); @@ -260,7 +267,7 @@ extern "C" return getMultiFabLoVects(mf, return_size, ngrow); } - double** warpx_getBfieldFP(int lev, int direction, + amrex::Real** warpx_getBfieldFP(int lev, int direction, int *return_size, int *ncomps, int *ngrow, int **shapes) { auto & mf = WarpX::GetInstance().getBfield_fp(lev, direction); return getMultiFabPointers(mf, return_size, ncomps, ngrow, shapes); @@ -272,7 +279,7 @@ extern "C" return getMultiFabLoVects(mf, return_size, ngrow); } - double** warpx_getCurrentDensity(int lev, int direction, + amrex::Real** warpx_getCurrentDensity(int lev, int direction, int *return_size, int *ncomps, int *ngrow, int **shapes) { auto & mf = WarpX::GetInstance().getcurrent(lev, direction); return getMultiFabPointers(mf, return_size, ncomps, ngrow, shapes); @@ -284,7 +291,7 @@ extern "C" return getMultiFabLoVects(mf, return_size, ngrow); } - double** warpx_getCurrentDensityCP(int lev, int direction, + amrex::Real** warpx_getCurrentDensityCP(int lev, int direction, int *return_size, int *ncomps, int *ngrow, int **shapes) { auto & mf = WarpX::GetInstance().getcurrent_cp(lev, direction); return getMultiFabPointers(mf, return_size, ncomps, ngrow, shapes); @@ -296,7 +303,7 @@ extern "C" return getMultiFabLoVects(mf, return_size, ngrow); } - double** warpx_getCurrentDensityFP(int lev, int direction, + amrex::Real** warpx_getCurrentDensityFP(int lev, int direction, int *return_size, int *ncomps, int *ngrow, int **shapes) { auto & mf = WarpX::GetInstance().getcurrent_fp(lev, direction); return getMultiFabPointers(mf, return_size, ncomps, ngrow, shapes); @@ -308,7 +315,7 @@ extern "C" return getMultiFabLoVects(mf, return_size, ngrow); } - double** warpx_getParticleStructs(int speciesnumber, int lev, + amrex::ParticleReal** warpx_getParticleStructs(int speciesnumber, int lev, int* num_tiles, int** particles_per_tile) { auto & mypc = WarpX::GetInstance().GetPartContainer(); auto & myspc = mypc.GetParticleContainer(speciesnumber); @@ -320,17 +327,17 @@ extern "C" *num_tiles = i; *particles_per_tile = (int*) malloc(*num_tiles*sizeof(int)); - double** data = (double**) malloc(*num_tiles*sizeof(typename WarpXParticleContainer::ParticleType*)); + amrex::ParticleReal** data = (amrex::ParticleReal**) malloc(*num_tiles*sizeof(typename WarpXParticleContainer::ParticleType*)); i = 0; for (WarpXParIter pti(myspc, lev); pti.isValid(); ++pti, ++i) { auto& aos = pti.GetArrayOfStructs(); - data[i] = (double*) aos.data(); + data[i] = (amrex::ParticleReal*) aos.data(); (*particles_per_tile)[i] = pti.numParticles(); } return data; } - double** warpx_getParticleArrays(int speciesnumber, int comp, int lev, + amrex::ParticleReal** warpx_getParticleArrays(int speciesnumber, int comp, int lev, int* num_tiles, int** particles_per_tile) { auto & mypc = WarpX::GetInstance().GetPartContainer(); auto & myspc = mypc.GetParticleContainer(speciesnumber); @@ -342,11 +349,11 @@ extern "C" *num_tiles = i; *particles_per_tile = (int*) malloc(*num_tiles*sizeof(int)); - double** data = (double**) malloc(*num_tiles*sizeof(double*)); + amrex::ParticleReal** data = (amrex::ParticleReal**) malloc(*num_tiles*sizeof(amrex::ParticleReal*)); i = 0; for (WarpXParIter pti(myspc, lev); pti.isValid(); ++pti, ++i) { auto& soa = pti.GetStructOfArrays(); - data[i] = (double*) soa.GetRealData(comp).dataPtr(); + data[i] = (amrex::ParticleReal*) soa.GetRealData(comp).dataPtr(); (*particles_per_tile)[i] = pti.numParticles(); } return data; @@ -361,11 +368,11 @@ extern "C" warpx.MoveWindow (true); } - void warpx_EvolveE (double dt) { + void warpx_EvolveE (amrex::Real dt) { WarpX& warpx = WarpX::GetInstance(); warpx.EvolveE (dt); } - void warpx_EvolveB (double dt) { + void warpx_EvolveB (amrex::Real dt) { WarpX& warpx = WarpX::GetInstance(); warpx.EvolveB (dt); } @@ -385,7 +392,7 @@ extern "C" WarpX& warpx = WarpX::GetInstance(); warpx.UpdateAuxilaryData (); } - void warpx_PushParticlesandDepose (double cur_time) { + void warpx_PushParticlesandDepose (amrex::Real cur_time) { WarpX& warpx = WarpX::GetInstance(); warpx.PushParticlesandDepose (cur_time); } @@ -398,15 +405,15 @@ extern "C" WarpX& warpx = WarpX::GetInstance(); warpx.setistep (lev, ii); } - double warpx_gett_new (int lev) { + amrex::Real warpx_gett_new (int lev) { WarpX& warpx = WarpX::GetInstance(); return warpx.gett_new (lev); } - void warpx_sett_new (int lev, double time) { + void warpx_sett_new (int lev, amrex::Real time) { WarpX& warpx = WarpX::GetInstance(); warpx.sett_new (lev, time); } - double warpx_getdt (int lev) { + amrex::Real warpx_getdt (int lev) { WarpX& warpx = WarpX::GetInstance(); return warpx.getdt (lev); } @@ -415,7 +422,7 @@ extern "C" WarpX& warpx = WarpX::GetInstance(); return warpx.maxStep (); } - double warpx_stopTime () { + amrex::Real warpx_stopTime () { WarpX& warpx = WarpX::GetInstance(); return warpx.stopTime (); } diff --git a/Source/Python/WarpXWrappers.h b/Source/Python/WarpXWrappers.h index 233a0b930..a272b9250 100644 --- a/Source/Python/WarpXWrappers.h +++ b/Source/Python/WarpXWrappers.h @@ -1,6 +1,9 @@ #ifndef WARPX_WRAPPERS_H_ #define WARPX_WRAPPERS_H_ +#include <AMReX.H> +#include <AMReX_BLProfiler.H> + #ifdef BL_USE_MPI #include <mpi.h> #endif @@ -9,6 +12,9 @@ extern "C" { #endif + int warpx_Real_size(); + int warpx_ParticleReal_size(); + int warpx_nSpecies(); bool warpx_use_fdtd_nci_corr(); @@ -49,61 +55,61 @@ extern "C" { void warpx_evolve (int numsteps); // -1 means the inputs parameter will be used. void warpx_addNParticles(int speciesnumber, int lenx, - double* x, double* y, double* z, - double* vx, double* vy, double* vz, - int nattr, double* attr, int uniqueparticles); + amrex::ParticleReal* x, amrex::ParticleReal* y, amrex::ParticleReal* z, + amrex::ParticleReal* vx, amrex::ParticleReal* vy, amrex::ParticleReal* vz, + int nattr, amrex::ParticleReal* attr, int uniqueparticles); void warpx_ConvertLabParamsToBoost(); - double warpx_getProbLo(int dir); + amrex::Real warpx_getProbLo(int dir); - double warpx_getProbHi(int dir); + amrex::Real warpx_getProbHi(int dir); long warpx_getNumParticles(int speciesnumber); - double** warpx_getEfield(int lev, int direction, - int *return_size, int* ncomps, int* ngrow, int **shapes); + amrex::Real** warpx_getEfield(int lev, int direction, + int *return_size, int* ncomps, int* ngrow, int **shapes); int* warpx_getEfieldLoVects(int lev, int direction, int *return_size, int* ngrow); - double** warpx_getBfield(int lev, int direction, - int *return_size, int* ncomps, int* ngrow, int **shapes); + amrex::Real** warpx_getBfield(int lev, int direction, + int *return_size, int* ncomps, int* ngrow, int **shapes); int* warpx_getBfieldLoVects(int lev, int direction, int *return_size, int* ngrow); - double** warpx_getCurrentDensity(int lev, int direction, - int *return_size, int* ncomps, int* ngrow, int **shapes); + amrex::Real** warpx_getCurrentDensity(int lev, int direction, + int *return_size, int* ncomps, int* ngrow, int **shapes); int* warpx_getCurrentDensityLoVects(int lev, int direction, int *return_size, int* ngrow); - double** warpx_getParticleStructs(int speciesnumber, int lev, - int* num_tiles, int** particles_per_tile); + amrex::ParticleReal** warpx_getParticleStructs(int speciesnumber, int lev, + int* num_tiles, int** particles_per_tile); - double** warpx_getParticleArrays(int speciesnumber, int comp, int lev, - int* num_tiles, int** particles_per_tile); + amrex::ParticleReal** warpx_getParticleArrays(int speciesnumber, int comp, int lev, + int* num_tiles, int** particles_per_tile); void warpx_ComputeDt (); void warpx_MoveWindow (); - void warpx_EvolveE (double dt); - void warpx_EvolveB (double dt); + void warpx_EvolveE (amrex::Real dt); + void warpx_EvolveB (amrex::Real dt); void warpx_FillBoundaryE (); void warpx_FillBoundaryB (); void warpx_SyncCurrent (); void warpx_UpdateAuxilaryData (); - void warpx_PushParticlesandDepose (double cur_time); + void warpx_PushParticlesandDepose (amrex::Real cur_time); int warpx_getistep (int lev); void warpx_setistep (int lev, int ii); - double warpx_gett_new (int lev); - void warpx_sett_new (int lev, double time); - double warpx_getdt (int lev); + amrex::Real warpx_gett_new (int lev); + void warpx_sett_new (int lev, amrex::Real time); + amrex::Real warpx_getdt (int lev); int warpx_maxStep (); - double warpx_stopTime (); + amrex::Real warpx_stopTime (); int warpx_checkInt (); int warpx_plotInt (); |