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

Making static gravity more user friendly with custom gravity field flags #340

Merged
merged 16 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
format
  • Loading branch information
evazlimen committed Sep 22, 2023
commit dbbb64d014011f78efd79aa92ddea583534b0511
2 changes: 1 addition & 1 deletion src/analysis/feedback_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void FeedbackAnalysis::Compute_Gas_Velocity_Dispersion(Grid3D& G)
#ifdef MPI_CHOLLA
MPI_Allreduce(&partial_mass, &total_mass, 1, MPI_CHREAL, MPI_SUM, world);
#else
total_mass = partial_mass;
total_mass = partial_mass;
#endif

for (k = G.H.n_ghost; k < G.H.nz - G.H.n_ghost; k++) {
Expand Down
2 changes: 1 addition & 1 deletion src/chemistry_gpu/chemistry_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void Grid3D::Update_Chemistry()
#ifdef COSMOLOGY
Chem.H.current_z = Cosmo.current_z;
#else
Chem.H.current_z = 0;
Chem.H.current_z = 0;
#endif

Do_Chemistry_Update(C.device, H.nx, H.ny, H.nz, H.n_ghost, H.n_fields, H.dt, Chem.H);
Expand Down
2 changes: 1 addition & 1 deletion src/cooling_grackle/cool_grackle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void Cool_GK::Initialize(struct parameters *P, Cosmology &Cosmo)
data->metal_cooling = 1; // metal cooling off
#else
chprintf("WARNING: Metal Cooling is Off. \n");
data->metal_cooling = 0; // metal cooling off
data->metal_cooling = 0; // metal cooling off
#endif

#ifdef PARALLEL_OMP
Expand Down
8 changes: 4 additions & 4 deletions src/gravity/gravity_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void Grid3D::set_dt_Gravity()
dt_particles = Calc_Particles_dt();
dt_particles = fmin(dt_particles, Particles.max_dt);
#ifdef ONLY_PARTICLES
dt_min = dt_particles;
dt_min = dt_particles;
chprintf(" dt_particles: %f \n", dt_particles);
#else
chprintf(" dt_hydro: %f dt_particles: %f \n", dt_hydro, dt_particles);
Expand Down Expand Up @@ -211,7 +211,7 @@ Real Grav3D::Get_Average_Density()
#ifdef MPI_CHOLLA
dens_avrg_all = ReduceRealAvg(dens_mean);
#else
dens_avrg_all = dens_mean;
dens_avrg_all = dens_mean;
#endif

dens_avrg = dens_avrg_all;
Expand Down Expand Up @@ -530,8 +530,8 @@ void Grid3D::Compute_Gravitational_Potential(struct parameters *P)
input_density = Grav.F.density_d;
output_potential = Grav.F.potential_d;
#else
input_density = Grav.F.density_h;
output_potential = Grav.F.potential_h;
input_density = Grav.F.density_h;
output_potential = Grav.F.potential_h;
#endif

#ifdef SOR
Expand Down
4 changes: 2 additions & 2 deletions src/gravity/gravity_functions_gpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void Grid3D::Copy_Hydro_Density_to_Gravity_GPU()
#ifdef COSMOLOGY
cosmo_rho_0_gas = Cosmo.rho_0_gas;
#else
cosmo_rho_0_gas = 1.0;
cosmo_rho_0_gas = 1.0;
#endif

// Copy the density from the device array to the Poisson input density array
Expand Down Expand Up @@ -261,7 +261,7 @@ void Grid3D::Extrapolate_Grav_Potential_GPU()
#ifdef COSMOLOGY
cosmo_factor = Cosmo.current_a * Cosmo.current_a / Cosmo.phi_0_gas;
#else
cosmo_factor = 1.0;
cosmo_factor = 1.0;
#endif

// set values for GPU kernels
Expand Down
44 changes: 22 additions & 22 deletions src/gravity/static_grav.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ inline __device__ void calc_g_1D(int xid, int x_off, int n_ghost, int custom_gra
{
Real x_pos, r_disk, r_halo;
x_pos = (x_off + xid - n_ghost + 0.5) * dx + xbound;
//set gravity field according to parameter file input
// set gravity field according to parameter file input
switch (custom_grav) {
case 1:
//1D NFW halo & Miyamoto-Nagai disk
// for disk components, calculate polar r
// r_disk = 0.220970869121;
// r_disk = 6.85009694274;
case 1:
// 1D NFW halo & Miyamoto-Nagai disk
// for disk components, calculate polar r
// r_disk = 0.220970869121;
// r_disk = 6.85009694274;
r_disk = 13.9211647546;
// r_disk = 20.9922325665;
// for halo, calculate spherical r
Expand Down Expand Up @@ -85,7 +85,7 @@ inline __device__ void calc_g_2D(int xid, int yid, int x_off, int y_off, int n_g
}
break;
case 2:
//Rayleigh-Taylor instability
// Rayleigh-Taylor instability
*gx = 0;
*gy = -1;
break;
Expand All @@ -96,7 +96,7 @@ inline __device__ void calc_g_2D(int xid, int yid, int x_off, int y_off, int n_g
*gx = -cos(phi) * GN * M / (r * r);
*gy = -sin(phi) * GN * M / (r * r);
break;
case 4:
case 4:
// set gravitational acceleration for Kuzmin disk + NFW halo
Real a_d, a_h, a, M_vir, M_d, R_vir, R_d, R_s, M_h, c_vir, x;
M_vir = 1.0e12; // viral mass of MW in M_sun
Expand Down Expand Up @@ -145,14 +145,14 @@ inline __device__ void calc_g_3D(int xid, int yid, int zid, int x_off, int y_off
case 1:
// Milky way disk model
// set properties of halo and disk (these must match initial conditions)

M_vir = 1.0e12; // viral mass of in M_sun
M_d = 6.5e10; // viral mass of in M_sun
R_d = 3.5; // disk scale length in kpc
z_d = 3.5 / 5.0; // disk scale height in kpc
R_vir = 261.; // virial radius in kpc
c_vir = 20.0; // halo concentration

M_h = M_vir - M_d; // halo mass in M_sun
R_h = R_vir / c_vir; // halo scale length in kpc
phi_0_h = GN * M_h / (log(1.0 + c_vir) - c_vir / (1.0 + c_vir));
Expand All @@ -172,18 +172,18 @@ inline __device__ void calc_g_3D(int xid, int yid, int zid, int x_off, int y_off
*gy = (y_pos / r_disk) * (a_disk_r + a_halo_r);
*gz = a_disk_z + a_halo_z;
break;
case 2:
// M82 model
// set properties of halo and disk (these must match initial conditions)

M_vir = 5.0e10; // viral mass of in M_sun
M_d = 1.0e10; // mass of disk in M_sun
R_d = 0.8; // disk scale length in kpc
z_d = 0.15; // disk scale height in kpc
R_vir = R_d/0.015; // viral radius in kpc
c_vir = 10.0; // halo concentration

M_h = M_vir - M_d; // halo mass in M_sun
case 2:
// M82 model
// set properties of halo and disk (these must match initial conditions)

M_vir = 5.0e10; // viral mass of in M_sun
M_d = 1.0e10; // mass of disk in M_sun
R_d = 0.8; // disk scale length in kpc
z_d = 0.15; // disk scale height in kpc
R_vir = R_d / 0.015; // viral radius in kpc
c_vir = 10.0; // halo concentration

M_h = M_vir - M_d; // halo mass in M_sun
R_h = R_vir / c_vir; // halo scale length in kpc
phi_0_h = GN * M_h / (log(1.0 + c_vir) - c_vir / (1.0 + c_vir));
x = r_halo / R_h;
Expand Down
6 changes: 3 additions & 3 deletions src/grid/grid3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void Grid3D::Initialize(struct parameters *P)
#ifdef DENSITY_FLOOR
H.density_floor = DENS_FLOOR;
#else
H.density_floor = 0.0;
H.density_floor = 0.0;
#endif

#ifdef TEMPERATURE_FLOOR
Expand Down Expand Up @@ -340,8 +340,8 @@ void Grid3D::AllocateMemory(void)
CudaSafeCall(cudaHostAlloc(&C.Grav_potential, H.n_cells * sizeof(Real), cudaHostAllocDefault));
CudaSafeCall(cudaMalloc((void **)&C.d_Grav_potential, H.n_cells * sizeof(Real)));
#else
C.Grav_potential = NULL;
C.d_Grav_potential = NULL;
C.Grav_potential = NULL;
C.d_Grav_potential = NULL;
#endif

#ifdef CHEMISTRY_GPU
Expand Down
20 changes: 10 additions & 10 deletions src/grid/initial_conditions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1481,18 +1481,18 @@ void Grid3D::Zeldovich_Pancake(struct parameters P)
Real H0, h, Omega_M, rho_0, G, z_zeldovich, z_init, x_center, T_init, k_x;

chprintf("Setting Zeldovich Pancake initial conditions...\n");
H0 = P.H0;
h = H0 / 100;
H0 = P.H0;
h = H0 / 100;
Omega_M = P.Omega_M;

chprintf(" h = %f \n", h);
chprintf(" Omega_M = %f \n", Omega_M);

H0 /= 1000; //[km/s / kpc]
G = G_COSMO;
rho_0 = 3 * H0 * H0 / (8 * M_PI * G) * Omega_M / h / h;
G = G_COSMO;
rho_0 = 3 * H0 * H0 / (8 * M_PI * G) * Omega_M / h / h;
z_zeldovich = 1;
z_init = P.Init_redshift;
z_init = P.Init_redshift;
chprintf(" rho_0 = %f \n", rho_0);
chprintf(" z_init = %f \n", z_init);
chprintf(" z_zeldovich = %f \n", z_zeldovich);
Expand Down Expand Up @@ -1552,17 +1552,17 @@ void Grid3D::Zeldovich_Pancake(struct parameters P)
index = (int(x_pos / H.dx) + 0) % 256;
// index = ( index + 16 ) % 256;
dens = ics_values[0 * nPoints + index];
vel = ics_values[1 * nPoints + index];
E = ics_values[2 * nPoints + index];
U = ics_values[3 * nPoints + index];
vel = ics_values[1 * nPoints + index];
E = ics_values[2 * nPoints + index];
U = ics_values[3 * nPoints + index];
// //

// chprintf( "%f \n", vel );
C.density[id] = dens;
C.density[id] = dens;
C.momentum_x[id] = dens * vel;
C.momentum_y[id] = 0;
C.momentum_z[id] = 0;
C.Energy[id] = E;
C.Energy[id] = E;

#ifdef DE
C.GasEnergy[id] = U;
Expand Down
5 changes: 3 additions & 2 deletions src/integrators/VL_3D_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ __global__ void Update_Conserved_Variables_3D_half(Real *dev_conserved, Real *de

void VL_Algorithm_3D_CUDA(Real *d_conserved, Real *d_grav_potential, int nx, int ny, int nz, int x_off, int y_off,
int z_off, int n_ghost, Real dx, Real dy, Real dz, Real xbound, Real ybound, Real zbound,
Real dt, int n_fields, int custom_grav, Real density_floor, Real U_floor, Real *host_grav_potential)
Real dt, int n_fields, int custom_grav, Real density_floor, Real U_floor,
Real *host_grav_potential)
{
// Here, *dev_conserved contains the entire
// set of conserved variables on the grid
Expand Down Expand Up @@ -122,7 +123,7 @@ void VL_Algorithm_3D_CUDA(Real *d_conserved, Real *d_grav_potential, int nx, int
#if defined(GRAVITY)
dev_grav_potential = d_grav_potential;
#else // not GRAVITY
dev_grav_potential = NULL;
dev_grav_potential = NULL;
#endif // GRAVITY

// If memory is single allocated: memory_allocated becomes true and
Expand Down
3 changes: 2 additions & 1 deletion src/integrators/VL_3D_cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

void VL_Algorithm_3D_CUDA(Real *d_conserved, Real *d_grav_potential, int nx, int ny, int nz, int x_off, int y_off,
int z_off, int n_ghost, Real dx, Real dy, Real dz, Real xbound, Real ybound, Real zbound,
Real dt, int n_fields, int custom_grav, Real density_floor, Real U_floor, Real *host_grav_potential);
Real dt, int n_fields, int custom_grav, Real density_floor, Real U_floor,
Real *host_grav_potential);

void Free_Memory_VL_3D();

Expand Down
4 changes: 2 additions & 2 deletions src/io/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,12 +1394,12 @@ void Grid3D::Write_Grid_HDF5(hid_t file_id)
#ifdef OUTPUT_METALS
output_metals = true;
#else // not OUTPUT_METALS
output_metals = false;
output_metals = false;
#endif // OUTPUT_METALS
#ifdef OUTPUT_ELECTRONS
output_electrons = true;
#else // not OUTPUT_ELECTRONS
output_electrons = false;
output_electrons = false;
#endif // OUTPUT_ELECTRONS
#ifdef OUTPUT_FULL_IONIZATION
output_full_ionization = true;
Expand Down
14 changes: 7 additions & 7 deletions src/particles/io_particles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,12 @@ void Particles_3D::Load_Particles_Data_HDF5(hid_t file_id, int nfile, struct par
Real vy_max_g = vy_max;
Real vz_max_g = vz_max;

Real px_min_g = px_min;
Real py_min_g = py_min;
Real pz_min_g = pz_min;
Real vx_min_g = vx_min;
Real vy_min_g = vy_min;
Real vz_min_g = vz_min;
Real px_min_g = px_min;
Real py_min_g = py_min;
Real pz_min_g = pz_min;
Real vx_min_g = vx_min;
Real vy_min_g = vy_min;
Real vz_min_g = vz_min;
#endif // MPI_CHOLLA

// Print initial Statistics
Expand Down Expand Up @@ -569,7 +569,7 @@ void Grid3D::Write_Particles_Data_HDF5(hid_t file_id)
#ifdef MPI_CHOLLA
N_particles_total = ReducePartIntSum(Particles.n_local);
#else
N_particles_total = Particles.n_local;
N_particles_total = Particles.n_local;
#endif

// Print the total particles when saving the particles data
Expand Down
14 changes: 7 additions & 7 deletions src/particles/particles_3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ void Particles_3D::Initialize(struct parameters *P, Grav3D &Grav, Real xbound, R
G.boundary_type_z0 = P->zlg_bcnd;
G.boundary_type_z1 = P->zug_bcnd;
#else
G.boundary_type_x0 = P->xl_bcnd;
G.boundary_type_x1 = P->xu_bcnd;
G.boundary_type_y0 = P->yl_bcnd;
G.boundary_type_y1 = P->yu_bcnd;
G.boundary_type_z0 = P->zl_bcnd;
G.boundary_type_z1 = P->zu_bcnd;
G.boundary_type_x0 = P->xl_bcnd;
G.boundary_type_x1 = P->xu_bcnd;
G.boundary_type_y0 = P->yl_bcnd;
G.boundary_type_y1 = P->yu_bcnd;
G.boundary_type_z0 = P->zl_bcnd;
G.boundary_type_z1 = P->zu_bcnd;
#endif

#ifdef PARTICLES_GPU
Expand Down Expand Up @@ -211,7 +211,7 @@ void Particles_3D::Initialize(struct parameters *P, Grav3D &Grav, Real xbound, R
#ifdef MPI_CHOLLA
n_total_initial = ReducePartIntSum(n_local);
#else
n_total_initial = n_local;
n_total_initial = n_local;
#endif

chprintf("Particles Initialized: \n n_local: %lu \n", n_local);
Expand Down
4 changes: 2 additions & 2 deletions src/particles/particles_boundaries_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,13 @@ void Particles_3D::Unload_Particles_from_Buffer_CPU(int direction, int side, Rea
offset_extra += 1;
pId = recv_buffer[offset_extra];
#else
pId = 0;
pId = 0;
#endif
#ifdef PARTICLE_AGE
offset_extra += 1;
pAge = recv_buffer[offset_extra];
#else
pAge = 0.0;
pAge = 0.0;
#endif

offset_buff += N_DATA_PER_PARTICLE_TRANSFER;
Expand Down
2 changes: 1 addition & 1 deletion src/reconstruction/plmp_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ __global__ void PLMP_cuda(Real *dev_conserved, Real *dev_bounds_L, Real *dev_bou
dge = dev_conserved[(n_fields - 1) * n_cells + id];
p_i = hydro_utilities::Get_Pressure_From_DE(E, E - E_kin, dge, gamma);
#else
p_i = (dev_conserved[4 * n_cells + id] - 0.5 * d_i * (vx_i * vx_i + vy_i * vy_i + vz_i * vz_i)) * (gamma - 1.0);
p_i = (dev_conserved[4 * n_cells + id] - 0.5 * d_i * (vx_i * vx_i + vy_i * vy_i + vz_i * vz_i)) * (gamma - 1.0);
#endif // PRESSURE_DE
p_i = fmax(p_i, (Real)TINY_NUMBER);
#ifdef SCALAR
Expand Down
2 changes: 1 addition & 1 deletion src/reconstruction/ppmc_cuda_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ TEST(tALLPpmcVLReconstructor, CorrectInputExpectCorrectOutput)
#ifdef MHD
size_t const n_fields = 8;
#else // not MHD
size_t const n_fields = 5;
size_t const n_fields = 5;
#endif // MHD

// Setup host grid. Fill host grid with random values and randomly assign maximum value
Expand Down
2 changes: 1 addition & 1 deletion src/reconstruction/ppmp_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ __global__ void PPMP_cuda(Real *dev_conserved, Real *dev_bounds_L, Real *dev_bou
dge = dev_conserved[(n_fields - 1) * n_cells + id];
p_i = hydro_utilities::Get_Pressure_From_DE(E, E - E_kin, dge, gamma);
#else
p_i = (dev_conserved[4 * n_cells + id] - 0.5 * d_i * (vx_i * vx_i + vy_i * vy_i + vz_i * vz_i)) * (gamma - 1.0);
p_i = (dev_conserved[4 * n_cells + id] - 0.5 * d_i * (vx_i * vx_i + vy_i * vy_i + vz_i * vz_i)) * (gamma - 1.0);
#endif // PRESSURE_DE
p_i = fmax(p_i, (Real)TINY_NUMBER);
#ifdef DE
Expand Down
8 changes: 2 additions & 6 deletions src/reconstruction/reconstruction_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -576,13 +576,9 @@ TEST(tALLReconstructionWriteData, CorrectInputExpectCorrectOutput)
{
// Set up test and mock up grid
#ifdef MHD
reconstruction::Primitive interface {
1, 2, 3, 4, 5, 6, 7, 8
};
reconstruction::Primitive interface{1, 2, 3, 4, 5, 6, 7, 8};
#else // MHD
reconstruction::Primitive interface {
6, 7, 8, 9, 10
};
reconstruction::Primitive interface{6, 7, 8, 9, 10};
#endif // MHD
size_t const nx = 3, ny = 3, nz = 3;
size_t const n_cells = nx * ny * nz;
Expand Down
4 changes: 2 additions & 2 deletions src/system_tests/hydro_system_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ class tHYDROtMHDSYSTEMLinearWavesParameterizedMpi : public ::testing::TestWithPa
double const allowedL1Error = 4E-7; // Based on results in Gardiner & Stone 2008
double const allowedError = 4E-7;
#elif defined(PLMC)
double const allowedL1Error = 1E-7; // Based on results in Gardiner & Stone 2008
double const allowedError = 1E-7;
double const allowedL1Error = 1E-7; // Based on results in Gardiner & Stone 2008
double const allowedError = 1E-7;
#elif defined(PPMC)
double const allowedL1Error = 2.7E-8; // Based on results in Gardiner & Stone 2008
double const allowedError = 2.7E-8;
Expand Down
Loading