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

Add scalar floor and refactor temperature and density floors #363

Merged
merged 59 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
3ecb87d
add function to apply a floor to any conserved variable and apply a d…
helenarichie Apr 28, 2023
3dd1d30
remove unnecessary macro
helenarichie Apr 28, 2023
198200b
Merge branch 'dev' into dev-scalar-floor
helenarichie Aug 14, 2023
2a6eb5f
save progress
helenarichie Aug 15, 2023
c793c79
Merge branch 'dev' into dev-scalar-floor
helenarichie Sep 22, 2023
4fda7e2
Merge branch 'dev-scalar-floor' of github.com:helenarichie/cholla int…
helenarichie Sep 22, 2023
9a245c3
Merge branch 'dev' into dev-scalar-floor
helenarichie Sep 22, 2023
b341db6
Merge branch 'dev-scalar-floor' of github.com:helenarichie/cholla int…
helenarichie Sep 22, 2023
8a58a85
Merge branch 'dev' into dev-scalar-floor
helenarichie Sep 22, 2023
25832d4
Merge branch 'dev' into dev-scalar-floor
helenarichie Sep 22, 2023
36a54e3
Merge branch 'dev-scalar-floor' of github.com:helenarichie/cholla int…
helenarichie Sep 22, 2023
77d6e1a
add test for scalar floor kernel
helenarichie Sep 25, 2023
639be11
run clang format
helenarichie Sep 25, 2023
25cdde9
Merge branch 'dev' into dev-scalar-floor
helenarichie Nov 3, 2023
0fd7f89
update branch
helenarichie Dec 6, 2023
098fe22
update initial conditions
helenarichie Dec 8, 2023
9b7e614
save simulation setup
helenarichie Dec 14, 2023
fed86f7
resolve merge conflict
helenarichie Dec 14, 2023
4077edd
resolve merge conflict
helenarichie Dec 14, 2023
3cd6b2e
update from cell averaging PR
helenarichie Dec 15, 2023
c1ccee3
update branch
Jan 3, 2024
ed40066
Merge branch 'dev' into dev-scalar-floor
Jan 3, 2024
5b85251
update build
Jan 4, 2024
f5dc360
hard-code cloud temp
helenarichie Jan 4, 2024
60b51a5
Merge branch 'dev-scalar-floor' of github.com:helenarichie/cholla int…
helenarichie Jan 4, 2024
e12b846
update build
helenarichie Jan 4, 2024
3fec978
update build
helenarichie Jan 6, 2024
328770b
clean up initial conditions
helenarichie Jan 13, 2024
2f3ef5f
reset to default settings
helenarichie Jan 13, 2024
094f1e9
get floor values from paramter file and remove density floor kernel
helenarichie Jan 13, 2024
d783bb7
run clang format
helenarichie Jan 13, 2024
399921b
remove reference to DENS_FLOOR macro
helenarichie Jan 23, 2024
fa7cfba
Merge branch 'dev' into dev-scalar-floor
helenarichie Jan 23, 2024
f276258
run clang format
helenarichie Jan 23, 2024
37ccafd
run clang format
helenarichie Jan 23, 2024
d737c4b
run clang format
helenarichie Jan 23, 2024
5f46029
Merge branch 'dev-scalar-floor' of github.com:helenarichie/cholla int…
helenarichie Jan 23, 2024
d292c46
undo accidental change
helenarichie Jan 23, 2024
da2d264
undo accidental removal of density floor in half-step
helenarichie Jan 23, 2024
8945bd4
Merge branch 'dev-scalar-floor' of github.com:helenarichie/cholla int…
helenarichie Jan 23, 2024
ef47030
fix undeclared variable
helenarichie Jan 23, 2024
2a5d7ed
remove debugging print statement
helenarichie Jan 24, 2024
db0f788
add host wrapper functions for temp and scalar floor kernels and move…
helenarichie Jan 24, 2024
71df115
run clang format'
helenarichie Jan 24, 2024
cfd9c0b
Merge branch 'dev' into dev-scalar-floor
helenarichie Jan 26, 2024
cb5e8f3
run clang format
helenarichie Jan 26, 2024
ddbd312
Update hydro build to use VL and PLMC
bcaddy Jan 18, 2024
29aa051
Switch MHD to using PLMC by default
bcaddy Jan 18, 2024
fafcf4f
Update other builds to PLMC and VL default
bcaddy Jan 18, 2024
2215b2f
Make sure cosmology builds use SIMPLE integrator
bcaddy Jan 22, 2024
ff09d5d
Fix clang-tidy warning
bcaddy Jan 23, 2024
b458962
Replace #warning with print to cerr
bcaddy Jan 23, 2024
35e327a
Merge branch 'dev' into dev-scalar-floor
helenarichie Feb 1, 2024
3e1c195
set default floor values in global.h and add warning
helenarichie Feb 1, 2024
8e2c742
Merge branch 'dev' into dev-scalar-floor
helenarichie Feb 1, 2024
8610f35
Merge branch 'dev' into dev-scalar-floor
helenarichie Feb 1, 2024
114f96b
change warning message and tweak how the default floors are set
helenarichie Feb 1, 2024
3eb2fb8
fix syntax errors
helenarichie Feb 1, 2024
cede7f3
run clang format
helenarichie Feb 1, 2024
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
26 changes: 13 additions & 13 deletions builds/make.type.dust
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@ DFLAGS += -DPRECISION=2
DFLAGS += -DPLMC
DFLAGS += -DHLLC

# DFLAGS += -DDE
DFLAGS += -DDE
DFLAGS += -DAVERAGE_SLOW_CELLS
DFLAGS += -DTEMPERATURE_FLOOR
DFLAGS += -DDENSITY_FLOOR

ifeq ($(findstring cosmology,$(TYPE)),cosmology)
DFLAGS += -DSIMPLE
else
DFLAGS += -DVL
# DFLAGS += -DSIMPLE
endif

# Evolve additional scalars
DFLAGS += -DSCALAR
DFLAGS += -DSCALAR
DFLAGS += -DSCALAR_FLOOR

# Define dust macro
DFLAGS += -DDUST
DFLAGS += -DDUST

# Apply the cooling in the GPU from precomputed tables
DFLAGS += -DCOOLING_GPU
DFLAGS += -DCOOLING_GPU
DFLAGS += -DCLOUDY_COOLING

#Measure the Timing of the different stages
#DFLAGS += -DCPU_TIME
#DFLAGS += -DCPU_TIME

DFLAGS += -DSLICES
DFLAGS += -DPROJECTION
DFLAGS += -DSLICES
DFLAGS += -DPROJECTION

DFLAGS += $(OUTPUT)

DFLAGS += -DOUTPUT_ALWAYS

#Select if the Hydro Conserved data will reside in the GPU
#and the MPI transfers are done from the GPU
#If not specified, MPI_GPU is off by default
#This is set in the system make.host file
DFLAGS += $(MPI_GPU)
DFLAGS += $(MPI_GPU)
4 changes: 1 addition & 3 deletions src/dust/dust_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ __global__ void Dust_Kernel(Real *dev_conserved, int nx, int ny, int nz, int n_g
Real const temperature = hydro_utilities::Calc_Temp_Conserved(energy, density_gas, momentum_x, momentum_y,
momentum_z, gamma, number_density);
#endif // MHD

#endif // DE
#endif // DE

Real tau_sp = Calc_Sputtering_Timescale(number_density, temperature, grain_radius) /
TIME_UNIT; // sputtering timescale, kyr (sim units)
Expand Down Expand Up @@ -126,7 +125,6 @@ __device__ __host__ Real Calc_Sputtering_Timescale(Real number_density, Real tem
number_density /= (6e-4); // gas number density in units of 10^-27 g/cm^3

// sputtering timescale, s
printf("%e\n", grain_radius);
Real tau_sp = A * (a / number_density) * (pow(temperature_0 / temperature, omega) + 1);

return tau_sp;
Expand Down
6 changes: 2 additions & 4 deletions src/dust/dust_cuda_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

#ifdef DUST

TEST(tDUSTTestSputteringTimescale,
CorrectInputExpectCorrectOutput) // test suite name, test name
TEST(tDUSTTestSputteringTimescale, CorrectInputExpectCorrectOutput)
{
// Parameters
Real YR_IN_S = 3.154e7;
Expand All @@ -47,8 +46,7 @@ TEST(tDUSTTestSputteringTimescale,
<< "The ULP difference is: " << ulps_diff << std::endl;
}

TEST(tDUSTTestSputteringGrowthRate,
CorrectInputExpectCorrectOutput) // test suite name, test name
TEST(tDUSTTestSputteringGrowthRate, CorrectInputExpectCorrectOutput)
{
// Parameters
Real YR_IN_S = 3.154e7;
Expand Down
21 changes: 21 additions & 0 deletions src/global/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,27 @@ void Parse_Param(char *name, char *value, struct Parameters *parms)
} else if (strcmp(name, "UVB_rates_file") == 0) {
strncpy(parms->UVB_rates_file, value, MAXLEN);
#endif
#ifdef TEMPERATURE_FLOOR
} else if (strcmp(name, "temperature_floor") == 0) {
parms->temperature_floor = atof(value);
if (parms->temperature_floor == 0) {
chprintf("WARNING: temperature floor is set to its default value (zero)! It can be set to a different value in the input parameter file.\n");
}
#endif
#ifdef DENSITY_FLOOR
} else if (strcmp(name, "density_floor") == 0) {
parms->density_floor = atof(value);
if (parms->density_floor == 0) {
chprintf("WARNING: density floor is set to its default value (zero)! It can be set to a different value in the input parameter file.\n");
}
#endif
#ifdef SCALAR_FLOOR
} else if (strcmp(name, "scalar_floor") == 0) {
parms->scalar_floor = atof(value);
if (parms->scalar_floor == 0) {
chprintf("WARNING: scalar floor is set to its default value (zero)! It can be set to a different value in the input parameter file.\n");
}
#endif
#ifdef ANALYSIS
} else if (strcmp(name, "analysis_scale_outputs_file") == 0) {
strncpy(parms->analysis_scale_outputs_file, value, MAXLEN);
Expand Down
7 changes: 3 additions & 4 deletions src/global/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ typedef double Real;

#define LOG_FILE_NAME "run_output.log"

// Conserved Floor Values
#define TEMP_FLOOR 1e-3
#define DENS_FLOOR 1e-5 // in code units

// Parameters for Enzo dual Energy Condition
// - Prior to GH PR #356, DE_ETA_1 nominally had a value of 0.001 in all
// simulations (in practice, the value of DE_ETA_1 had minimal significance
Expand Down Expand Up @@ -326,6 +322,9 @@ struct Parameters {
char UVB_rates_file[MAXLEN]; // File for the UVB photoheating and
// photoionization rates of HI, HeI and HeII
#endif
Real temperature_floor = 0;
Real density_floor = 0;
Real scalar_floor = 0;
#ifdef ANALYSIS
char analysis_scale_outputs_file[MAXLEN]; // File for the scale_factor output
// values for cosmological
Expand Down
57 changes: 33 additions & 24 deletions src/grid/grid3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,17 @@ void Grid3D::Initialize(struct Parameters *P)
#endif /*ROTATED_PROJECTION*/

// Values for lower limit for density and temperature
#ifdef TEMPERATURE_FLOOR
H.temperature_floor = P->temperature_floor;
#else

#ifdef DENSITY_FLOOR
H.density_floor = DENS_FLOOR;
H.density_floor = P->density_floor;
#else
H.density_floor = 0.0;
#endif

#ifdef TEMPERATURE_FLOOR
H.temperature_floor = TEMP_FLOOR;
#ifdef SCALAR_FLOOR
H.scalar_floor = P->scalar_floor;
#else
H.temperature_floor = 0.0;
#endif

#ifdef COSMOLOGY
H.OUTPUT_SCALE_FACOR = not(P->scale_outputs_file[0] == '\0');
Expand Down Expand Up @@ -424,16 +424,6 @@ void Grid3D::Execute_Hydro_Integrator(void)
z_off = nz_local_start;
#endif

// Set the lower limit for density and temperature (Internal Energy)
Real U_floor, density_floor;
density_floor = H.density_floor;
// Minimum of internal energy from minumum of temperature
U_floor = H.temperature_floor * KB / (gama - 1) / MP / SP_ENERGY_UNIT;
#ifdef COSMOLOGY
U_floor = H.temperature_floor / (gama - 1) / MP * KB * 1e-10; // ( km/s )^2
U_floor /= Cosmo.v_0_gas * Cosmo.v_0_gas / Cosmo.current_a / Cosmo.current_a;
#endif

#ifdef CPU_TIME
Timer.Hydro_Integrator.Start();
#endif // CPU_TIME
Expand Down Expand Up @@ -461,14 +451,14 @@ void Grid3D::Execute_Hydro_Integrator(void)
{
#ifdef VL
VL_Algorithm_3D_CUDA(C.device, C.d_Grav_potential, H.nx, H.ny, H.nz, x_off, y_off, z_off, H.n_ghost, H.dx, H.dy,
H.dz, H.xbound, H.ybound, H.zbound, H.dt, H.n_fields, H.custom_grav, density_floor, U_floor,
H.dz, H.xbound, H.ybound, H.zbound, H.dt, H.n_fields, H.custom_grav, H.density_floor,
C.Grav_potential);
#endif // VL
#ifdef SIMPLE
Simple_Algorithm_3D_CUDA(C.device, C.d_Grav_potential, H.nx, H.ny, H.nz, x_off, y_off, z_off, H.n_ghost, H.dx, H.dy,
H.dz, H.xbound, H.ybound, H.zbound, H.dt, H.n_fields, H.custom_grav, density_floor,
U_floor, C.Grav_potential);
#endif // SIMPLE
H.dz, H.xbound, H.ybound, H.zbound, H.dt, H.n_fields, H.custom_grav, H.density_floor,
C.Grav_potential);
#endif // SIMPLE
} else {
chprintf("Error: Grid dimensions nx: %d ny: %d nz: %d not supported.\n", H.nx, H.ny, H.nz);
chexit(-1);
Expand Down Expand Up @@ -500,10 +490,29 @@ Real Grid3D::Update_Hydro_Grid()

Execute_Hydro_Integrator();

// == Perform chemistry/cooling (there are a few different cases) ==
#ifdef CUDA

#ifdef COOLING_GPU
#ifdef CPU_TIME
#ifdef TEMPERATURE_FLOOR
// Set the lower limit temperature (Internal Energy)
Real U_floor;
// Minimum of internal energy from minumum of temperature
U_floor = H.temperature_floor * KB / (gama - 1) / MP / SP_ENERGY_UNIT;
#ifdef COSMOLOGY
U_floor = H.temperature_floor / (gama - 1) / MP * KB * 1e-10; // ( km/s )^2
U_floor /= Cosmo.v_0_gas * Cosmo.v_0_gas / Cosmo.current_a / Cosmo.current_a;
#endif
Apply_Temperature_Floor(C.device, H.nx, H.ny, H.nz, H.n_ghost, H.n_fields, U_floor);
#endif // TEMPERATURE_FLOOR

#ifdef SCALAR_FLOOR
#ifdef DUST
Apply_Scalar_Floor(C.device, H.nx, H.ny, H.nz, H.n_ghost, grid_enum::dust_density, H.scalar_floor);
#endif
#endif // SCALAR_FLOOR

// == Perform chemistry/cooling (there are a few different cases) ==
#ifdef COOLING_GPU
#ifdef CPU_TIME
Timer.Cooling_GPU.Start();
#endif
// ==Apply Cooling from cooling/cooling_cuda.h==
Expand Down
3 changes: 2 additions & 1 deletion src/grid/grid3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ struct Header {
int custom_grav;

// Values for lower limit for density and temperature
Real density_floor;
Real temperature_floor;
Real density_floor;
Real scalar_floor;

Real Ekin_avrg;

Expand Down
3 changes: 1 addition & 2 deletions src/grid/initial_conditions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,12 +1414,11 @@ void Grid3D::Clouds()
#ifdef DE
C.GasEnergy[id] = p_cl / (gama - 1.0);
#endif // DE

#ifdef SCALAR
#ifdef DUST
C.host[id + H.n_cells * grid_enum::dust_density] = rho_cl * 1e-2;
#endif // DUST
#endif
#endif // SCALAR
}
}
}
Expand Down
61 changes: 57 additions & 4 deletions src/hydro/hydro_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1100,9 +1100,22 @@ __global__ void Sync_Energies_3D(Real *dev_conserved, int nx, int ny, int nz, in

#endif // DE

#ifdef TEMPERATURE_FLOOR
__global__ void Apply_Temperature_Floor(Real *dev_conserved, int nx, int ny, int nz, int n_ghost, int n_fields,
Real U_floor)
void Apply_Temperature_Floor(Real *dev_conserved, int nx, int ny, int nz, int n_ghost, int n_fields, Real U_floor)
{
// set values for GPU kernels
int n_cells = nx * ny * nz;
int ngrid = (n_cells + TPB - 1) / TPB;
// number of blocks per 1D grid
dim3 dim1dGrid(ngrid, 1, 1);
// number of threads per 1D block
dim3 dim1dBlock(TPB, 1, 1);

hipLaunchKernelGGL(Temperature_Floor_Kernel, dim1dGrid, dim1dBlock, 0, 0, dev_conserved, nx, ny, nz, n_ghost,
n_fields, U_floor);
}

__global__ void Temperature_Floor_Kernel(Real *dev_conserved, int nx, int ny, int nz, int n_ghost, int n_fields,
Real U_floor)
{
int id, xid, yid, zid, n_cells;
Real d, d_inv, vx, vy, vz, E, Ekin, U;
Expand Down Expand Up @@ -1138,7 +1151,6 @@ __global__ void Apply_Temperature_Floor(Real *dev_conserved, int nx, int ny, int
#endif
}
}
#endif // TEMPERATURE_FLOOR

__device__ Real Average_Cell_Single_Field(int field_indx, int i, int j, int k, int nx, int ny, int nz, int ncells,
Real *conserved)
Expand Down Expand Up @@ -1254,3 +1266,44 @@ __device__ void Average_Cell_All_Fields(int i, int j, int k, int nx, int ny, int

printf("%3d %3d %3d FC: d: %e E:%e P:%e vx:%e vy:%e vz:%e\n", i, j, k, d, E, P, vx_av, vy_av, vz_av);
}

void Apply_Scalar_Floor(Real *dev_conserved, int nx, int ny, int nz, int n_ghost, int field_num, Real scalar_floor)
{
// set values for GPU kernels
int n_cells = nx * ny * nz;
int ngrid = (n_cells + TPB - 1) / TPB;
// number of blocks per 1D grid
dim3 dim1dGrid(ngrid, 1, 1);
// number of threads per 1D block
dim3 dim1dBlock(TPB, 1, 1);

hipLaunchKernelGGL(Scalar_Floor_Kernel, dim1dGrid, dim1dBlock, 0, 0, dev_conserved, nx, ny, nz, n_ghost, field_num,
scalar_floor);
}

__global__ void Scalar_Floor_Kernel(Real *dev_conserved, int nx, int ny, int nz, int n_ghost, int field_num,
Real scalar_floor)
{
int id, xid, yid, zid, n_cells;
Real scalar; // variable to store the value of the scalar before a floor is applied
n_cells = nx * ny * nz;

// get a global thread ID
id = threadIdx.x + blockIdx.x * blockDim.x;
zid = id / (nx * ny);
yid = (id - zid * nx * ny) / nx;
xid = id - zid * nx * ny - yid * nx;

// threads corresponding to real cells do the calculation
if (xid > n_ghost - 1 && xid < nx - n_ghost && yid > n_ghost - 1 && yid < ny - n_ghost && zid > n_ghost - 1 &&
zid < nz - n_ghost) {
scalar = dev_conserved[id + n_cells * field_num];

if (scalar < scalar_floor) {
// printf("###Thread scalar change %f -> %f \n", scalar, scalar_floor);
dev_conserved[id + n_cells * field_num] = scalar_floor;
}
}
}

#endif // CUDA
13 changes: 9 additions & 4 deletions src/hydro/hydro_cuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ __global__ void Average_Slow_Cells_3D(Real *dev_conserved, int nx, int ny, int n
Real dy, Real dz, Real gamma, Real max_dti_slow);
#endif

#ifdef TEMPERATURE_FLOOR
__global__ void Apply_Temperature_Floor(Real *dev_conserved, int nx, int ny, int nz, int n_ghost, int n_fields,
Real U_floor);
#endif
void Apply_Temperature_Floor(Real *dev_conserved, int nx, int ny, int nz, int n_ghost, int n_fields, Real U_floor);

__global__ void Temperature_Floor_Kernel(Real *dev_conserved, int nx, int ny, int nz, int n_ghost, int n_fields,
Real U_floor);

void Apply_Scalar_Floor(Real *dev_conserved, int nx, int ny, int nz, int n_ghost, int field_num, Real scalar_floor);

__global__ void Scalar_Floor_Kernel(Real *dev_conserved, int nx, int ny, int nz, int n_ghost, int field_num,
Real scalar_floor);

__global__ void Partial_Update_Advected_Internal_Energy_1D(Real *dev_conserved, Real *Q_Lx, Real *Q_Rx, int nx,
int n_ghost, Real dx, Real dt, Real gamma, int n_fields);
Expand Down
Loading
Loading