├── eos ├── helmholtz │ ├── helm_implno.dek │ ├── helm_wrap.h │ ├── helm_const.dek │ └── helm_table_storage.dek ├── eos.h └── eos_interface.c ├── scripts ├── indent.sh ├── gizmo_documentation_ims │ ├── gizmo_demo_c.jpeg │ ├── gizmo_smaller.png │ ├── method_demo.jpeg │ ├── gizmo_hydro_demo.jpeg │ ├── gizmo_different_meshes.jpeg │ ├── scaling_strong_med_hr.jpeg │ ├── scaling_weak_res_med_hr.jpeg │ └── scaling_weak_size_med_hr.jpeg ├── visit │ ├── make_visit_index.sh │ ├── GIZMO.xml │ ├── README │ ├── GIZMOMDServerPluginInfo.C │ ├── GIZMOEnginePluginInfo.C │ ├── GIZMOCommonPluginInfo.C │ ├── GIZMOPluginInfo.h │ └── avtGIZMOFileFormat.h ├── diffcheck.sh ├── test_problems │ ├── rotor.params │ ├── mhd_blast.params │ ├── field_loop.params │ ├── orszag_tang.params │ ├── mhd_wave.params │ ├── toth.params │ ├── square.params │ ├── briowu.params │ ├── noh.params │ ├── soundwave.params │ ├── blob.params │ ├── shocktube.params │ ├── currentsheet.params │ ├── interactblast.params │ ├── mri.params │ ├── kh_wengen.params │ ├── dustyboxwave.params │ ├── sedov.params │ ├── evrard.params │ ├── rt.params │ ├── gresho.params │ ├── keplerian.params │ ├── ring_collision.params │ ├── zeldovich.params │ ├── kh_mcnally_2d.params │ ├── zeldovich_mhd.params │ ├── sbcluster.params │ └── core.params ├── pipelines │ └── bitbucket-pipelines.yml ├── compress_gizmosnap.py └── compress_cleanup_sim.sh ├── config-makefile ├── system ├── code_block_xchange_perform_ops_demalloc.h ├── code_block_xchange_perform_ops_malloc.h ├── ngb_codeblock_before_condition.h ├── code_block_secondary_loop_evaluation.h ├── myqsort.h ├── code_block_xchange_finalize.h ├── code_block_primary_loop_evaluation.h ├── code_block_xchange_initialize.h ├── pinning.c ├── allocate.c ├── vector.h ├── ngb_codeblock_checknode.h ├── ngb_codeblock_after_condition_unthreaded.h ├── parallel_sort_special.c ├── ngb_codeblock_after_condition_threaded.h └── bracketed_rootfind.h ├── sidm ├── cbe_integrator_flux_computation.h ├── cbe_integrator.c ├── sidm_core_flux_computation.h ├── sidm_core.c └── dm_fuzzy_flux_computation.h ├── structure ├── subfind │ ├── subfind_vars.c │ └── subfind_potential.c └── fof.h ├── gravity ├── myfftw3.h └── forcetree.h ├── prepare-config.perl ├── Makefile.systype ├── domain.h ├── cooling ├── chimes │ ├── params_chimes.txt │ └── chimes_vars.h └── cooling.h ├── radiation └── rt_direct_ray_transport.h ├── tags.h ├── README.md ├── main.c ├── galaxy_sf └── blackholes │ └── blackhole.h ├── turb ├── turbulent_diffusion.h └── chimes_turbulent_ion_diffusion.h └── hydro └── conduction.h /eos/helmholtz/helm_implno.dek: -------------------------------------------------------------------------------- 1 | ! implicit declarations 2 | implicit none 3 | -------------------------------------------------------------------------------- /scripts/indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | indent -gnu -npsl -npcs -nbs -nsaf -nsai -nsaw -nprs -bap -pmt -l110 $@ 4 | -------------------------------------------------------------------------------- /scripts/gizmo_documentation_ims/gizmo_demo_c.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pfhopkins/gizmo-public/HEAD/scripts/gizmo_documentation_ims/gizmo_demo_c.jpeg -------------------------------------------------------------------------------- /scripts/gizmo_documentation_ims/gizmo_smaller.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pfhopkins/gizmo-public/HEAD/scripts/gizmo_documentation_ims/gizmo_smaller.png -------------------------------------------------------------------------------- /scripts/gizmo_documentation_ims/method_demo.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pfhopkins/gizmo-public/HEAD/scripts/gizmo_documentation_ims/method_demo.jpeg -------------------------------------------------------------------------------- /scripts/gizmo_documentation_ims/gizmo_hydro_demo.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pfhopkins/gizmo-public/HEAD/scripts/gizmo_documentation_ims/gizmo_hydro_demo.jpeg -------------------------------------------------------------------------------- /config-makefile: -------------------------------------------------------------------------------- 1 | GIZMO_config.h: $(CONFIG) 2 | $(PERL) prepare-config.perl $(CONFIG) 3 | 4 | compile_time_info.c: $(CONFIG) 5 | $(PERL) prepare-config.perl $(CONFIG) 6 | -------------------------------------------------------------------------------- /scripts/gizmo_documentation_ims/gizmo_different_meshes.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pfhopkins/gizmo-public/HEAD/scripts/gizmo_documentation_ims/gizmo_different_meshes.jpeg -------------------------------------------------------------------------------- /scripts/gizmo_documentation_ims/scaling_strong_med_hr.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pfhopkins/gizmo-public/HEAD/scripts/gizmo_documentation_ims/scaling_strong_med_hr.jpeg -------------------------------------------------------------------------------- /scripts/gizmo_documentation_ims/scaling_weak_res_med_hr.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pfhopkins/gizmo-public/HEAD/scripts/gizmo_documentation_ims/scaling_weak_res_med_hr.jpeg -------------------------------------------------------------------------------- /scripts/gizmo_documentation_ims/scaling_weak_size_med_hr.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pfhopkins/gizmo-public/HEAD/scripts/gizmo_documentation_ims/scaling_weak_size_med_hr.jpeg -------------------------------------------------------------------------------- /system/code_block_xchange_perform_ops_demalloc.h: -------------------------------------------------------------------------------- 1 | /*! just de-allocate buffers from code_block_xchange_perform_ops_malloc in reverse order they were malloc'd */ 2 | myfree(DataNodeList); myfree(DataIndexTable); myfree(Ngblist); 3 | -------------------------------------------------------------------------------- /sidm/cbe_integrator_flux_computation.h: -------------------------------------------------------------------------------- 1 | /* --------------------------------------------------------------------------------- 2 | this is the kernel where the core of the CBE flux computation is performed, 3 | to calculate the relevant fluxes between faces of partciels, within the gravity routine 4 | --------------------------------------------------------------------------------- */ 5 | -------------------------------------------------------------------------------- /scripts/visit/make_visit_index.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function print_help() { 4 | echo "Usage: $1 [nchunks] [file list]" 5 | } 6 | 7 | if [ -z "$1" ]; then 8 | print_help $0 9 | exit 1 10 | fi 11 | 12 | if ! [[ $1 =~ [0-9]+$ ]]; then 13 | print_help $0 14 | exit 1 15 | fi 16 | 17 | echo "!NBLOCKS $1" 18 | shift 19 | for f in $*; do 20 | echo $f 21 | done 22 | -------------------------------------------------------------------------------- /sidm/cbe_integrator.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "../allvars.h" 8 | #include "../proto.h" 9 | #include "../kernel.h" 10 | 11 | 12 | /*! \file cbe_integrator.c 13 | * \brief routines needed for CBE integrator implementation 14 | * This file was written by Phil Hopkins (phopkins@caltech.edu) for GIZMO. 15 | */ 16 | 17 | -------------------------------------------------------------------------------- /scripts/diffcheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ## This file was written by Phil Hopkins (phopkins@caltech.edu) for GIZMO ## 3 | for i in $(find * -maxdepth 0 -type f); do echo $i; diff $i $1/$i; done 4 | for i in $(find */* -maxdepth 0 -type f); do echo $i; diff $i $1/$i; done 5 | for i in $(find */*/* -maxdepth 0 -type f); do echo $i; diff $i $1/$i; done 6 | for i in $(find */*/*/* -maxdepth 0 -type f); do echo $i; diff $i $1/$i; done 7 | for i in $(find */*/*/*/* -maxdepth 0 -type f); do echo $i; diff $i $1/$i; done 8 | 9 | -------------------------------------------------------------------------------- /scripts/test_problems/rotor.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % BOX_SPATIAL_DIMENSION=2 8 | % EOS_GAMMA=(1.4000) 9 | % MAGNETIC 10 | % SELFGRAVITY_OFF 11 | % 12 | InitCondFile rotor_ics 13 | OutputDir output 14 | TimeMax 0.15 15 | TimeBetSnapshot 0.05 16 | BoxSize 1 17 | DesNumNgb 20 18 | -------------------------------------------------------------------------------- /scripts/test_problems/mhd_blast.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % BOX_PERIODIC 6 | % BOX_SPATIAL_DIMENSION=2 7 | % HYDRO_MESHLESS_FINITE_MASS 8 | % EOS_GAMMA=(5.0/3.0) 9 | % MAGNETIC 10 | % SELFGRAVITY_OFF 11 | % 12 | InitCondFile mhd_blast_ics 13 | OutputDir output 14 | TimeMax 1 15 | BoxSize 1 16 | TimeBetSnapshot 0.1 17 | DesNumNgb 20 18 | -------------------------------------------------------------------------------- /scripts/test_problems/field_loop.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % BOX_PERIODIC 6 | % BOX_SPATIAL_DIMENSION=2 7 | % MAGNETIC 8 | % SELFGRAVITY_OFF 9 | % 10 | InitCondFile field_loop_ics 11 | OutputDir output 12 | TimeMax 20 13 | BoxSize 1 14 | TimeOfFirstSnapshot 0.01 15 | TimeBetSnapshot 1 16 | MaxSizeTimestep 0.1 17 | DesNumNgb 20 18 | -------------------------------------------------------------------------------- /scripts/test_problems/orszag_tang.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % BOX_PERIODIC 6 | % BOX_SPATIAL_DIMENSION=2 7 | % HYDRO_MESHLESS_FINITE_MASS 8 | % MAGNETIC 9 | % SELFGRAVITY_OFF 10 | % 11 | InitCondFile orszag_tang_ics 12 | OutputDir output 13 | TimeMax 0.5 14 | BoxSize 1 15 | TimeBetSnapshot 0.1 16 | MaxSizeTimestep 0.1 17 | DesNumNgb 20 18 | -------------------------------------------------------------------------------- /scripts/test_problems/mhd_wave.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % BOX_SPATIAL_DIMENSION=1 8 | % EOS_GAMMA=(5.0/3.0) 9 | % MAGNETIC 10 | % SELFGRAVITY_OFF 11 | % 12 | InitCondFile mhd_wave_ics 13 | OutputDir output 14 | TimeMax 0.5 15 | BoxSize 1 16 | TimeBetSnapshot 0.05 17 | MaxSizeTimestep 0.1 18 | DesNumNgb 4 19 | -------------------------------------------------------------------------------- /scripts/visit/GIZMO.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ${HDF5_INCLUDE_DIR} 5 | 6 | 7 | ${HDF5_LIBRARY_DIR} 8 | 9 | 10 | ${HDF5_LIB} 11 | 12 | 13 | *.hdf5 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /scripts/test_problems/toth.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % BOX_LONG_X=16 8 | % BOX_LONG_Y=1 9 | % BOX_LONG_Z=1 10 | % BOX_SPATIAL_DIMENSION=2 11 | % EOS_GAMMA=(5.0/3.0) 12 | % MAGNETIC 13 | % SELFGRAVITY_OFF 14 | % 15 | InitCondFile toth_ics 16 | OutputDir output 17 | TimeMax 0.08 18 | BoxSize 0.25 19 | TimeBetSnapshot 0.04 20 | DesNumNgb 20 21 | -------------------------------------------------------------------------------- /scripts/test_problems/square.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_SPATIAL_DIMENSION=2 7 | % BOX_PERIODIC 8 | % SELFGRAVITY_OFF 9 | % EOS_GAMMA=(1.4) 10 | % 11 | InitCondFile square_ics 12 | OutputDir output 13 | TimeMax 10 14 | BoxSize 1 15 | TimeBetSnapshot 0.5 16 | DesNumNgb 12 17 | % -- optional numerical parameters (requires additional Config flags) 18 | CourantFac 0.1 19 | -------------------------------------------------------------------------------- /scripts/test_problems/briowu.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % BOX_LONG_X=16 8 | % BOX_LONG_Y=1 9 | % BOX_LONG_Z=1 10 | % BOX_SPATIAL_DIMENSION=2 11 | % EOS_GAMMA=(2.0) 12 | % MAGNETIC 13 | % SELFGRAVITY_OFF 14 | % 15 | InitCondFile briowu_ics 16 | OutputDir output 17 | TimeMax 0.2 18 | BoxSize 0.25 19 | TimeBetSnapshot 0.1 20 | MaxSizeTimestep 0.04 21 | DesNumNgb 20 22 | -------------------------------------------------------------------------------- /scripts/test_problems/noh.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % SELFGRAVITY_OFF 8 | % EOS_GAMMA=(5.0/3.0) 9 | % 10 | InitCondFile noh_ics 11 | OutputDir output 12 | TimeMax 2 13 | BoxSize 6 14 | TimeBetSnapshot 0.1 15 | DesNumNgb 60 16 | % -- optional numerical parameters (requires additional Config flags) 17 | CourantFac 0.1 18 | % -- optional parameter - speed up the test with bigger steps, but maybe bigger errors 19 | MaxSizeTimestep 0.001 20 | 21 | -------------------------------------------------------------------------------- /structure/subfind/subfind_vars.c: -------------------------------------------------------------------------------- 1 | #include "../../allvars.h" 2 | /* 3 | * This file was originally part of the GADGET3 code developed by Volker Springel. 4 | * It has been updated significantly by PFH for basic compatibility with GIZMO, 5 | * as well as code cleanups, and accommodating new GIZMO functionality for various 6 | * other operations. See notes in subfind.c and GIZMO User Guide for details. 7 | */ 8 | 9 | #ifdef SUBFIND 10 | 11 | #include "subfind.h" 12 | #include "../fof.h" 13 | 14 | int Ncollective; 15 | int MaxNsubgroups; 16 | int Nsubgroups; 17 | int TotNsubgroups; 18 | struct subgroup_properties *SubGroup; 19 | struct nearest_r2_data *R2Loc; 20 | struct nearest_ngb_data *NgbLoc; 21 | struct r2data *R2list; 22 | //struct nearest_ngb_data *NgbLoc; 23 | //struct nearest_r2_data *R2Loc; 24 | double *Dist2list; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /scripts/test_problems/soundwave.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_SPATIAL_DIMENSION=1 7 | % BOX_PERIODIC 8 | % SELFGRAVITY_OFF 9 | % EOS_GAMMA=(5.0/3.0) 10 | % 11 | InitCondFile soundwave_ics 12 | OutputDir output 13 | TimeMax 1.5 14 | BoxSize 1 15 | TimeBetSnapshot 0.1 16 | DesNumNgb 4 17 | % -- optional numerical parameters (requires additional Config flags) 18 | ErrTolIntAccuracy 0.01 19 | CourantFac 0.05 20 | MaxRMSDisplacementFac 0.1 21 | ErrTolForceAcc 0.001 22 | TimeBetStatistics 0.5 23 | 24 | -------------------------------------------------------------------------------- /system/code_block_xchange_perform_ops_malloc.h: -------------------------------------------------------------------------------- 1 | /*! allocate buffers to arrange communication */ 2 | long long NTaskTimesNumPart = maxThreads * NumPart; size_t MyBufferSize = All.BufferSize; int loop_iteration = 0; 3 | All.BunchSize = (long) ((MyBufferSize * 1024 * 1024) / (sizeof(struct data_index) + sizeof(struct data_nodelist) + sizeof(struct INPUT_STRUCT_NAME) + sizeof(struct OUTPUT_STRUCT_NAME) + sizemax(sizeof(struct INPUT_STRUCT_NAME),sizeof(struct OUTPUT_STRUCT_NAME)))); 4 | Ngblist = (int *) mymalloc("Ngblist", NTaskTimesNumPart * sizeof(int)); 5 | DataIndexTable = (struct data_index *) mymalloc("DataIndexTable", All.BunchSize * sizeof(struct data_index)); 6 | DataNodeList = (struct data_nodelist *) mymalloc("DataNodeList", All.BunchSize * sizeof(struct data_nodelist)); 7 | double timeall=0, timecomp=0, timecomm=0, timewait=0, t0; CPU_Step[CPU_MISC] += measure_time(); t0 = my_second(); /*! for timing information */ 8 | 9 | -------------------------------------------------------------------------------- /scripts/test_problems/blob.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % BOX_LONG_X=1 8 | % BOX_LONG_Y=1 9 | % BOX_LONG_Z=3 10 | % SELFGRAVITY_OFF 11 | % EOS_GAMMA=(5.0/3.0) 12 | % 13 | InitCondFile blob_ics 14 | OutputDir output 15 | TimeMax 8 16 | BoxSize 2000 17 | TimeBetSnapshot 0.1 18 | DesNumNgb 32 19 | UnitLength_in_cm 3.085678e+21 20 | UnitMass_in_g 1.989e+43 21 | UnitVelocity_in_cm_per_s 100000 22 | % -- optional parameter - speed up the test with bigger steps, but maybe bigger errors 23 | MaxSizeTimestep 0.02 24 | -------------------------------------------------------------------------------- /gravity/myfftw3.h: -------------------------------------------------------------------------------- 1 | #ifndef __MY_FFTW3_H__ 2 | #define __MY_FFTW3_H__ 3 | 4 | #include 5 | 6 | #define cmplx_re(c) ((c)[0]) 7 | #define cmplx_im(c) ((c)[1]) 8 | 9 | #ifdef DOUBLEPRECISION_FFTW 10 | #define fftw_real double 11 | #define MPI_TYPE_FFTW MPI_DOUBLE 12 | #else 13 | #define fftw_real float 14 | #define MPI_TYPE_FFTW MPI_FLOAT 15 | #define fftw_complex fftwf_complex 16 | #define fftw_mpi_local_size_3d_transposed fftwf_mpi_local_size_3d_transposed 17 | #define fftw_mpi_init fftwf_mpi_init 18 | #define fftw_plan fftwf_plan 19 | #define fftw_mpi_local_size_3d fftwf_mpi_local_size_3d 20 | #define fftw_mpi_plan_dft_r2c_3d fftwf_mpi_plan_dft_r2c_3d 21 | #define fftw_mpi_plan_dft_c2r_3d fftwf_mpi_plan_dft_c2r_3d 22 | #define fftw_execute fftwf_execute 23 | #define fftw_destroy_plan fftwf_destroy_plan 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /scripts/test_problems/shocktube.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_SPATIAL_DIMENSION=1 7 | % BOX_PERIODIC 8 | % SELFGRAVITY_OFF 9 | % EOS_GAMMA=(1.4) 10 | % 11 | InitCondFile shocktube_ics_emass % or 'shocktube_ics_diffmass' 12 | OutputDir output 13 | TimeMax 5 14 | BoxSize 80 15 | TimeBetSnapshot 0.5 16 | MaxSizeTimestep 0.001 17 | DesNumNgb 4 18 | % -- optional numerical parameters (requires additional Config flags) 19 | ErrTolIntAccuracy 0.0025 20 | CourantFac 0.05 21 | MaxRMSDisplacementFac 0.125 22 | TimeBetStatistics 0.5 23 | 24 | -------------------------------------------------------------------------------- /scripts/test_problems/currentsheet.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % BOX_SPATIAL_DIMENSION=2 8 | % MAGNETIC 9 | % SELFGRAVITY_OFF 10 | % 11 | % Note this problem has a few different ICs, as described in the user guide: 12 | % currentsheet_A0pt1_b0pt1_ics, currentsheet_A0pt1_b1em12_ics, 13 | % and currentsheet_A1e4_b0pt1_ics 14 | % 15 | InitCondFile currentsheet_A0pt1_b0pt1_ics % choose 16 | OutputDir output 17 | TimeMax 0.1 18 | BoxSize 1 19 | TimeBetSnapshot 1 20 | MaxSizeTimestep 1e-05 21 | DesNumNgb 16 22 | % -- optional numerical parameters (requires additional Config flags) 23 | CourantFac 0.1 24 | -------------------------------------------------------------------------------- /scripts/test_problems/interactblast.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_BND_PARTICLES 7 | % BOX_SPATIAL_DIMENSION=1 8 | % BOX_REFLECT_X 9 | % SELFGRAVITY_OFF 10 | % EOS_GAMMA=(1.4) 11 | % 12 | InitCondFile interactblast_ics 13 | OutputDir output 14 | TimeMax 0.038 15 | BoxSize 1 16 | TimeBetSnapshot 0.0038 17 | MaxSizeTimestep 2e-07 18 | MinSizeTimestep 2e-07 19 | DesNumNgb 4 20 | % -- optional numerical parameters (requires additional Config flags) 21 | ErrTolIntAccuracy 0.002 22 | CourantFac 0.01 23 | MaxRMSDisplacementFac 0.05 24 | ErrTolForceAcc 0.001 25 | -------------------------------------------------------------------------------- /scripts/test_problems/mri.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % BOX_SHEARING=1 8 | % BOX_SHEARING_Q=(3./2.) 9 | % BOX_SPATIAL_DIMENSION=2 10 | % EOS_GAMMA=(1.000001) 11 | % MAGNETIC 12 | % MULTIPLEDOMAINS=64 13 | % SELFGRAVITY_OFF 14 | % 15 | % You may want to experiment with flags such as MHD_CONSTRAINED_GRADIENT, as well 16 | % 17 | InitCondFile mri_ics 18 | OutputDir output 19 | TimeMax 100 20 | BoxSize 1 21 | TimeBetSnapshot 1 22 | DesNumNgb 20 23 | GravityConstantInternal 1 24 | SofteningGas 0.05 25 | % -- optional parameter - speed up the test with bigger steps, but maybe bigger errors 26 | MaxSizeTimestep 0.1 27 | -------------------------------------------------------------------------------- /system/ngb_codeblock_before_condition.h: -------------------------------------------------------------------------------- 1 | /* 2 | this defines a code-block to be inserted in the neighbor search routines after the conditions for neighbor-validity are applied 3 | (valid particle types checked) 4 | */ 5 | int numngb, no, p, task; 6 | struct NODE *current; 7 | // cache some global vars locally for improved compiler alias analysis 8 | int maxPart = All.MaxPart; 9 | int maxNodes = MaxNodes; 10 | long bunchSize = All.BunchSize; 11 | integertime ti_Current = All.Ti_Current; 12 | MyDouble dx, dy, dz, dist, xtmp; xtmp=0; 13 | 14 | #ifdef REDUCE_TREEWALK_BRANCHING 15 | t_vector box, hbox, vcenter; 16 | #ifdef BOX_PERIODIC 17 | INIT_VECTOR3(boxSize_X, boxSize_Y, boxSize_Z, &box); 18 | INIT_VECTOR3(searchcenter[0], searchcenter[1], searchcenter[2], &vcenter); 19 | SCALE_VECTOR3(0.5, &box, &hbox); 20 | #endif 21 | #endif 22 | 23 | numngb = 0; 24 | no = *startnode; 25 | 26 | while(no >= 0) 27 | { 28 | if(no < maxPart) /* single particle */ 29 | { 30 | p = no; 31 | no = Nextnode[no]; 32 | -------------------------------------------------------------------------------- /system/code_block_secondary_loop_evaluation.h: -------------------------------------------------------------------------------- 1 | /* This is a generic code block designed for simple neighbor loops, so that they don't have to 2 | be copy-pasted and can be generically optimized in a single place. specifically this is for 3 | the secondary loop of particles on a remote processor (after the primary has been passed) 4 | 5 | EVALUATION_CALL is the actual call, and needs to be defined appropriately, or this will crash 6 | */ 7 | #if !defined(EVALUATION_CALL) 8 | printf("Cannot compile the secondary sub-loop without EVALUATION_CALL defined. Exiting. \n"); fflush(stdout); exit(995534); 9 | #endif 10 | int j, dummy, *ngblist, thread_id = *(int *) p; 11 | ngblist = Ngblist + thread_id * NumPart; 12 | while(1) 13 | { 14 | LOCK_NEXPORT; 15 | #ifdef _OPENMP 16 | #pragma omp critical(_nextlistsecblox_) 17 | #endif 18 | { 19 | j = NextJ; 20 | NextJ++; 21 | } 22 | UNLOCK_NEXPORT; 23 | if(j >= Nimport) {break;} 24 | EVALUATION_CALL 25 | } 26 | /* loop completed successfully */ 27 | return NULL; 28 | -------------------------------------------------------------------------------- /scripts/pipelines/bitbucket-pipelines.yml: -------------------------------------------------------------------------------- 1 | # Template C++ Application 2 | 3 | # This template allows you to validate your C++ application. 4 | 5 | # The workflow allows running tests and code linting on the default branch. 6 | 7 | image: ubuntu:20.04 8 | 9 | pipelines: 10 | 11 | default: 12 | 13 | - parallel: 14 | 15 | - step: 16 | 17 | name: Build and Run 18 | 19 | script: 20 | 21 | # Install deps 22 | 23 | - apt-get update && DEBIAN_FRONTEND="noninteractive" TZ="America/New_York" apt-get install -y --no-install-recommends gosu wget ca-certificates git build-essential libopenmpi-dev libgsl-dev libhdf5-dev hdf5-tools 24 | 25 | - id -u build &>/dev/null || useradd --user-group --create-home --shell /bin/false build 26 | 27 | # Build and run 28 | 29 | - gosu build sh scripts/pipelines/run_isodisk_testprob.sh 30 | 31 | # Compare with reference solution 32 | 33 | - gosu build sh scripts/pipelines/compare_isodisk_output.sh 34 | -------------------------------------------------------------------------------- /system/myqsort.h: -------------------------------------------------------------------------------- 1 | /* must define macros QSORT, KEY_TYPE, STRUCT_TYPE, KEY_COPY, GET_KEYVAL */ 2 | /* 3 | * This file was originally part of the GADGET3 code by Volker Springel. 4 | */ 5 | static void QSORT(KEY_TYPE *a,int n) 6 | { 7 | #pragma alloca 8 | KEY_TYPE *b = (KEY_TYPE *)alloca(sizeof(KEY_TYPE)*n); 9 | 10 | if (n > 1) { 11 | int i,j1,j2; 12 | double avg = 0.0; 13 | KEY_BASE_TYPE kavg; 14 | 15 | /* compute average key value and use as pivot point */ 16 | 17 | for(i=0;i < n;i++) 18 | avg += KEY_GETVAL(&a[i]); 19 | 20 | kavg = (KEY_BASE_TYPE) (avg / (double)n); 21 | 22 | j1 = 0; 23 | j2 = n; 24 | 25 | for (i = 0;i < n;i++) 26 | if (KEY_GETVAL(&a[i]) <= kavg) { 27 | KEY_COPY(&a[i],&b[j1]); 28 | j1++; 29 | } 30 | else { 31 | --j2; 32 | KEY_COPY(&a[i],&b[j2]); 33 | } 34 | 35 | if (j1 > 0 && j2 < n) { 36 | 37 | if (j1 > 0) QSORT(b,j1); 38 | if (j2 < n) QSORT(&b[j1],n-j1); 39 | 40 | memcpy(a,b,sizeof(KEY_TYPE)*n); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /scripts/test_problems/kh_wengen.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % BOX_LONG_X=32 8 | % BOX_LONG_Y=32 9 | % BOX_LONG_Z=2 10 | % SELFGRAVITY_OFF 11 | % EOS_GAMMA=(5.0/3.0) 12 | % 13 | InitCondFile kh_wengen_ics 14 | OutputDir output 15 | TimeMax 32 16 | BoxSize 8 17 | TimeBetSnapshot 0.05 18 | MaxSizeTimestep 0.02 19 | DesNumNgb 45 20 | UnitLength_in_cm 3.085678e+21 21 | UnitMass_in_g 1.989e+43 22 | UnitVelocity_in_cm_per_s 100000 23 | % -- optional numerical parameters (requires additional Config flags) 24 | CourantFac 0.1 25 | ErrTolForceAcc 0.005 26 | ArtCondConstant 0.25 27 | ViscosityAMin 0.025 28 | ViscosityAMax 2 29 | -------------------------------------------------------------------------------- /scripts/test_problems/dustyboxwave.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % 3 | % BOX_PERIODIC 4 | % BOX_SPATIAL_DIMENSION=1 5 | % EOS_GAMMA=(5./3.) 6 | % EOS_ENFORCE_ADIABAT=(3./5.) 7 | % SELFGRAVITY_OFF 8 | % GRAIN_FLUID 9 | % GRAIN_BACKREACTION 10 | % 11 | InitCondFile dustywave_ics % (or try dustybox_ics) 12 | OutputDir output 13 | TimeMax 2.5 14 | BoxSize 1 15 | TimeBetSnapshot 0.01 16 | DesNumNgb 4 17 | % -- grain physics parameters 18 | Grain_Internal_Density 1 19 | Grain_Size_Min 1.23608 20 | Grain_Size_Max 1.23608 21 | Grain_Size_Spectrum_Powerlaw 0.5 22 | % -- if the code is having trouble starting up on an iteration towards kernel sizes, prompt with 23 | %Softening_Type0 0.01 % gas 24 | %Softening_Type3 0.001 % grains 25 | % -- optional parameter - speed up the test with bigger steps, but maybe bigger errors 26 | MaxSizeTimestep 0.0001 27 | -------------------------------------------------------------------------------- /prepare-config.perl: -------------------------------------------------------------------------------- 1 | 2 | # This file processes the configurations options in Config.sh, producing 3 | # two files: 4 | # 5 | # GIZMO_config.h to be included in each source file (via allvars.h) 6 | # compile_time_info.c code to be compiled in, which will print the configuration 7 | # 8 | # This file was originally part of GADGET3 by Volker Springel. 9 | # 10 | 11 | if(@ARGV[0]) 12 | { 13 | open(FILE, @ARGV[0]); 14 | } 15 | else 16 | { 17 | open(FILE, "Config.sh"); 18 | } 19 | open(OUTFILE, ">GIZMO_config.h"); 20 | open(COUTF, ">compile_time_info.c"); 21 | 22 | print COUTF "#include \n"; 23 | print COUTF "void output_compile_time_options(void)\n\{\n"; 24 | print COUTF "printf(\n"; 25 | 26 | while($line=) 27 | { 28 | chop $line; 29 | 30 | @fields = split ' ' , $line; 31 | 32 | if(substr($fields[0], 0, 1) ne "#") 33 | { 34 | if(length($fields[0]) > 0) 35 | { 36 | @subfields = split '=', $fields[0]; 37 | 38 | print OUTFILE "#define $subfields[0] $subfields[1]\n"; 39 | print COUTF "\" $fields[0]\\n\"\n"; 40 | } 41 | } 42 | } 43 | 44 | print COUTF "\"\\n\");\n"; 45 | print COUTF "\}\n"; 46 | -------------------------------------------------------------------------------- /scripts/test_problems/sedov.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % SELFGRAVITY_OFF 8 | % EOS_GAMMA=(5.0/3.0) 9 | % 10 | InitCondFile sedov_ics 11 | OutputDir output 12 | TimeMax 0.03 13 | BoxSize 6 14 | TimeBetSnapshot 0.003 15 | DesNumNgb 32 16 | UnitLength_in_cm 3.085678e+21 17 | UnitMass_in_g 1.989e+43 18 | UnitVelocity_in_cm_per_s 100000 19 | MinGasTemp 10 20 | % -- optional numerical parameters (requires additional Config flags) 21 | ErrTolIntAccuracy 0.002 22 | CourantFac 0.05 23 | MaxRMSDisplacementFac 0.1 24 | ErrTolForceAcc 0.0015 25 | TimeBetStatistics 0.001 26 | % -- optional parameter - speed up the test with bigger steps, but maybe bigger errors 27 | MaxSizeTimestep 0.0001 28 | -------------------------------------------------------------------------------- /scripts/test_problems/evrard.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % EOS_GAMMA=(5.0/3.0) 7 | % 8 | % recommended, but not required: 9 | % 10 | % MULTIPLEDOMAINS=16 11 | % ADAPTIVE_GRAVSOFT_FORGAS 12 | % 13 | InitCondFile evrard_ics 14 | OutputDir output 15 | PartAllocFactor 5 16 | TimeMax 0.8 17 | TimeBetSnapshot 0.1 18 | MaxSizeTimestep 0.001 19 | DesNumNgb 40 20 | GravityConstantInternal 1 21 | MaxHsml 2000 22 | SofteningGas 0.0001 % set me larger if not using adaptive softenings! 23 | SofteningHalo 0.07 24 | Softening_Type2 0.003 25 | Softening_Type3 0.003 26 | Softening_Type4 0.003 27 | Softening_Type5 0.003 28 | % -- optional numerical parameters (requires additional Config flags) 29 | CourantFac 0.1 30 | -------------------------------------------------------------------------------- /scripts/test_problems/rt.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % BOX_BND_PARTICLES 8 | % BOX_LONG_X=1 9 | % BOX_LONG_Y=2 10 | % BOX_SPATIAL_DIMENSION=2 11 | % EOS_GAMMA=(1.4) 12 | % SELFGRAVITY_OFF 13 | % GRAVITY_ANALYTIC 14 | % 15 | % remember to go into gravity/analytic_gravity.c and un-comment 16 | % the call to GravAccel_RayleighTaylorTest() in add_analytic_gravitational_forces() 17 | % before compiling the source code 18 | % 19 | % 20 | % For the MHD version of the problem, additionally enable: 21 | % 22 | % MAGNETIC 23 | % MHD_B_SET_IN_PARAMS 24 | % 25 | InitCondFile rt_ics.ic 26 | OutputDir output 27 | TimeMax 20 28 | BoxSize 0.5 29 | TimeBetSnapshot 1 30 | MaxSizeTimestep 0.1 31 | DesNumNgb 20 32 | GravityConstantInternal 1 33 | % - optional physics parameters (B-field strength) 34 | BiniX 0.07 35 | BiniY 0 36 | BiniZ 0 37 | -------------------------------------------------------------------------------- /Makefile.systype: -------------------------------------------------------------------------------- 1 | # Select Target Computer 2 | # 3 | # Please copy this file to Makefile.systype and uncomment your 4 | # system. Don't commit changes to this file unless you add support for 5 | # a new system. 6 | # 7 | ############# 8 | 9 | SYSTYPE="Frontera" 10 | #SYSTYPE="Stampede2" 11 | #SYSTYPE="Bridges2" 12 | #SYSTYPE="Anvil" 13 | #SYSTYPE="Wheeler" 14 | #SYSTYPE="CaltechHPC" 15 | #SYSTYPE="MacBookPro" 16 | #SYSTYPE="MacBookCellar" 17 | #SYSTYPE="Quest" 18 | #SYSTYPE="Quest-intel" 19 | #SYSTYPE="TSCC" 20 | #SYSTYPE="Expanse" 21 | #SYSTYPE="Iron" 22 | #SYSTYPE="RUSTY" 23 | #SYSTYPE="Darter" 24 | #SYSTYPE="Comet" 25 | #SYSTYPE="Gordon" 26 | #SYSTYPE="odyssey" 27 | #SYSTYPE="antares" 28 | #SYSTYPE="Pleiades" 29 | #SYSTYPE="Mira" 30 | #SYSTYPE="Titan" 31 | #SYSTYPE="Edison" 32 | #SYSTYPE="SciNet" 33 | #SYSTYPE="Ranger_intel" 34 | #SYSTYPE="Ranger_pgi" 35 | #SYSTYPE="Darwin" 36 | #SYSTYPE="Magny" 37 | #SYSTYPE="Magny-Intel" 38 | #SYSTYPE="OpenSuse" 39 | #SYSTYPE="OpenSuse64" 40 | #SYSTYPE="HLRB2" 41 | #SYSTYPE="MPA" 42 | #SYSTYPE="VIP" 43 | #SYSTYPE="Ubuntu" 44 | #SYSTYPE="MBM" 45 | #SYSTYPE="OpteronMPA-Gnu" 46 | #SYSTYPE="OpteronMPA-Intel" 47 | #SYSTYPE="Centos5-intel" 48 | #SYSTYPE="Kolob" 49 | #SYSTYPE="Centos5-Gnu" 50 | #SYSTYPE="OPA-Cluster64-Intel" 51 | #SYSTYPE="Stampede" 52 | #SYSTYPE="Zwicky" 53 | #SYSTYPE="BlueWaters" 54 | #SYSTYPE="PopOS" -------------------------------------------------------------------------------- /system/code_block_xchange_finalize.h: -------------------------------------------------------------------------------- 1 | /* This is a code block which must be inserted at the END of the code_block_xchange...(any).h 2 | subroutines. This de-allocates everything to prevent memory leaks and errors, and includes 3 | a couple of the key subroutines (which have been defined already but can be detailed here) */ 4 | 5 | 6 | static inline void *PRIMARY_SUBFUN_NAME(void *p, int loop_iteration) 7 | { 8 | #define CONDITION_FOR_EVALUATION CONDITIONFUNCTION_FOR_EVALUATION 9 | #define EVALUATION_CALL CORE_FUNCTION_NAME(i, 0, exportflag, exportnodecount, exportindex, ngblist, loop_iteration) 10 | #include "../system/code_block_primary_loop_evaluation.h" 11 | #undef CONDITION_FOR_EVALUATION 12 | #undef EVALUATION_CALL 13 | } 14 | 15 | static inline void *SECONDARY_SUBFUN_NAME(void *p, int loop_iteration) 16 | { 17 | #define EVALUATION_CALL CORE_FUNCTION_NAME(j, 1, &dummy, &dummy, &dummy, ngblist, loop_iteration); 18 | #include "../system/code_block_secondary_loop_evaluation.h" 19 | #undef EVALUATION_CALL 20 | } 21 | 22 | #undef CONDITIONFUNCTION_FOR_EVALUATION 23 | #undef SECONDARY_SUBFUN_NAME 24 | #undef PRIMARY_SUBFUN_NAME 25 | #undef OUTPUTFUNCTION_NAME 26 | #undef DATARESULT_NAME 27 | #undef DATAOUT_NAME 28 | #undef OUTPUT_STRUCT_NAME 29 | #undef INPUTFUNCTION_NAME 30 | #undef DATAGET_NAME 31 | #undef DATAIN_NAME 32 | #undef INPUT_STRUCT_NAME 33 | #undef CORE_FUNCTION_NAME 34 | -------------------------------------------------------------------------------- /scripts/test_problems/gresho.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % BOX_SPATIAL_DIMENSION=2 8 | % SELFGRAVITY_OFF 9 | % EOS_GAMMA=(1.4) 10 | % 11 | % You may want to experiment with the neighbor number and the AGGRESSIVE_SLOPE_LIMITERS or 12 | % SLOPE_LIMITER_TOLERANCE and KERNEL_FUNCTION (try =5 or 7 instead of 3) settings, 13 | % to see how the numerical diffusivity is affected on this problem (you have significant 14 | % room to trade stability/noise versus diffusivity, and the problem in any code is, at this 15 | % relatively low resolution, strongly influenced by the slope-limiter) 16 | % 17 | InitCondFile gresho_ics 18 | OutputDir output 19 | TimeMax 3 20 | BoxSize 1 21 | TimeBetSnapshot 0.5 22 | DesNumNgb 20 23 | % -- optional numerical parameters (requires additional Config flags) 24 | ErrTolIntAccuracy 0.001 25 | CourantFac 0.025 26 | MaxRMSDisplacementFac 0.125 27 | MaxSizeTimestep 5.0e-4 28 | ArtCondConstant 0.25 29 | ViscosityAMin 0.025 30 | ViscosityAMax 2 31 | 32 | -------------------------------------------------------------------------------- /scripts/test_problems/keplerian.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_SPATIAL_DIMENSION=2 7 | % SELFGRAVITY_OFF 8 | % GRAVITY_ANALYTIC 9 | % EOS_GAMMA=(7.0/5.0) 10 | % ENERGY_ENTROPY_SWITCH_IS_ACTIVE 11 | % 12 | % Make sure you go into the file gravity/analytic_gravity.h and un-comment the line: 13 | % 14 | % //GravAccel_KeplerianTestProblem(); // keplerian disk with boundaries for test problem 15 | % 16 | % within the routine “add_analytic_gravitational_forces”. Otherwise the code won’t know 17 | % what to use for the analytic gravitational forces. 18 | % 19 | % 20 | InitCondFile keplerian_ics 21 | OutputDir output 22 | TimeMax 10 23 | BoxSize 8 24 | TimeBetSnapshot 2.5 25 | MaxSizeTimestep 0.1 26 | DesNumNgb 20 27 | % -- optional numerical parameters (requires additional Config flags) 28 | ErrTolIntAccuracy 0.002 29 | CourantFac 0.025 30 | MaxRMSDisplacementFac 0.125 31 | ResubmitOn 0 32 | ResubmitCommand dummy 33 | TimeBetStatistics 1e10 34 | ErrTolTheta 0.5 35 | ErrTolForceAcc 0.001 36 | MaxNumNgbDeviation 0.01 37 | -------------------------------------------------------------------------------- /scripts/test_problems/ring_collision.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % 3 | % BOX_SPATIAL_DIMENSION=2 4 | % SELFGRAVITY_OFF 5 | % EOS_TILLOTSON 6 | % EOS_ELASTIC 7 | % KERNEL_FUNCTION=6 8 | % 9 | % (The choice of KERNEL_FUNCTION=6 is optional here. Experiment with different kernels. 10 | % But be sure to set DesNumNgb accordingly; for e.g. KERNEL_FUNCTION=5 or 7, use 40, =3, use 20, =4 or 6 use 32) 11 | % 12 | % Experiment with both HYDRO_MESHLESS_FINITE_MASS and HYDRO_DENSITY_SPH. On some elastic problems, SPH can 13 | % give improved problems, though if you have fluid phases, MFM tends to give better behavior. 14 | % 15 | InitCondFile ring_collision_ics % choose IC and resolution 16 | OutputDir output 17 | TimeMax 300 18 | TimeBetSnapshot 5 19 | MaxSizeTimestep 0.1 20 | DesNumNgb 32 % make sure to set appropriate for kernel 21 | %--- parameters here make EOS: P=cs*cs*(rho-rho_0), where cs=rho_0=1 in code units ---% 22 | Tillotson_EOS_params_a 0 23 | Tillotson_EOS_params_b 0 24 | Tillotson_EOS_params_u_0 1e+20 25 | Tillotson_EOS_params_rho_0 1 26 | Tillotson_EOS_params_A 1 27 | Tillotson_EOS_params_B 0 28 | Tillotson_EOS_params_u_s 1e+20 29 | Tillotson_EOS_params_u_s_prime 1e+20 30 | Tillotson_EOS_params_alpha 0 31 | Tillotson_EOS_params_beta 0 32 | Tillotson_EOS_params_mu 0.22 33 | Tillotson_EOS_params_Y0 1e+20 34 | %-- optional [if having trouble on initial iteration to correct kernel sizes], can prompt with 35 | %Softening_Type0 0.001 % this is our elastic material 36 | -------------------------------------------------------------------------------- /eos/eos.h: -------------------------------------------------------------------------------- 1 | #ifndef EOS_INTERFACE_H 2 | #define EOS_INTERFACE_H 3 | 4 | #include "../GIZMO_config.h" 5 | 6 | 7 | #if (defined(EOS_TILLOTSON) || defined(EOS_ELASTIC) || defined(EOS_HELMHOLTZ) || defined(COSMIC_RAY_FLUID) || defined(RT_RADPRESSURE_IN_HYDRO) || defined(EOS_TRUELOVE_PRESSURE) || defined(TRUELOVE_CRITERION_PRESSURE) || defined(EOS_GMC_BAROTROPIC) || defined(COSMIC_RAY_SUBGRID_LEBRON)) && !defined(EOS_GENERAL) 8 | #define EOS_GENERAL 9 | #endif 10 | 11 | #ifdef EOS_HELMHOLTZ 12 | #define EOS_TABULATED 13 | #define EOS_USES_CGS 14 | #define EOS_CARRIES_YE 15 | #define EOS_CARRIES_ABAR 16 | #define EOS_CARRIES_TEMPERATURE 17 | #define EOS_PROVIDES_ENTROPY 18 | #define EOS_PROVIDES_CV 19 | #endif 20 | 21 | struct eos_input 22 | { 23 | double rho; /* Density */ 24 | double eps; /* Specific internal energy */ 25 | #ifdef EOS_CARRIES_YE 26 | double Ye; /* Electron fraction */ 27 | #endif 28 | #ifdef EOS_CARRIES_ABAR 29 | double Abar; /* Mean atomic weight (in atomic mass units) */ 30 | #endif 31 | #ifdef EOS_CARRIES_TEMPERATURE 32 | double temp; /* Temperature initial guess */ 33 | #endif 34 | }; 35 | 36 | struct eos_output 37 | { 38 | double press; /* Pressure */ 39 | double csound; /* Sound speed */ 40 | #ifdef EOS_CARRIES_TEMPERATURE 41 | double temp; /* Temperature (in Kelvin) */ 42 | #endif 43 | #ifdef EOS_PROVIDES_ENTROPY 44 | double entropy; /* Entropy (in CGS) */ 45 | #endif 46 | #ifdef EOS_PROVIDES_CV 47 | double cv; /* Specific heat at constant volume (in CGS) */ 48 | #endif 49 | }; 50 | 51 | #ifdef EOS_TABULATED 52 | int eos_init(char const * eos_table_fname); 53 | int eos_cleanup(); 54 | #endif 55 | 56 | int eos_compute(struct eos_input const * in, struct eos_output * out); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /eos/helmholtz/helm_wrap.h: -------------------------------------------------------------------------------- 1 | /* wrappers for the Timmes EOS Fortran code. 2 | written by David Radice 3 | WARNING: because of the memory layout used by the original Fortran code 4 | which was not thread safe, the Helmholtz wrapper might perform poorly or 5 | throw an exception if a large number of OpenMP threads is used. 6 | Eventually, someone will have to make a thread safe version of the 7 | Helmholtz EOS if you want to run on things like the new KNL on Stampede2 8 | */ 9 | 10 | #ifdef EOS_HELMHOLTZ // top-level flag [needs to be here to prevent compiler breaking when this is not active] // 11 | 12 | #ifndef EOS_HELM_WRAP_H 13 | #define EOS_HELM_WRAP_H 14 | 15 | void helm_read_table_c( 16 | char const * tab_file_name); 17 | 18 | void helm_range_rho_ye_c( 19 | double * rho_ye_min, 20 | double * rho_ye_max); 21 | void helm_range_temp_c( 22 | double * temp_min, 23 | double * temp_max); 24 | 25 | void helm_range_eps_c( 26 | int const * rank, 27 | double const * rho, 28 | double const * abar, 29 | double const * ye, 30 | double * eps_min, 31 | double * eps_max, 32 | int * eosfail); 33 | 34 | void helm_eos_t_c( 35 | int const * rank, 36 | double const * rho, 37 | double const * temp, 38 | double const * abar, 39 | double const * ye, 40 | double * press, 41 | double * eps, 42 | double * entropy, 43 | double * csound, 44 | double * dedt, 45 | int * eosfail); 46 | 47 | void helm_eos_e_c( 48 | int const * rank, 49 | double const * rho, 50 | double const * eps, 51 | double const * abar, 52 | double const * ye, 53 | double * temp, 54 | double * press, 55 | double * entropy, 56 | double * csound, 57 | double * dedt, 58 | int * eosfail); 59 | 60 | #endif 61 | 62 | #endif // top-level flag 63 | -------------------------------------------------------------------------------- /domain.h: -------------------------------------------------------------------------------- 1 | #ifndef ALLVARS_H 2 | #include "allvars.h" 3 | #endif 4 | 5 | /* 6 | * This file was originally part of the GADGET3 code developed by 7 | * Volker Springel. The code has been modified 8 | * slightly by Phil Hopkins (phopkins@caltech.edu) for GIZMO. 9 | */ 10 | 11 | double domain_particle_cost_multiplier(int i); 12 | void domain_findSplit_work_balanced(int ncpu, int ndomain); 13 | void domain_findSplit_load_balanced(int ncpu, int ndomain); 14 | int domain_sort_loadorigin(const void *a, const void *b); 15 | int domain_sort_segments(const void *a, const void *b); 16 | void domain_assign_load_or_work_balanced(int mode, int multipledomains); 17 | void domain_allocate(void); 18 | int domain_check_memory_bound(int multipledomains); 19 | int domain_compare_key(const void *a, const void *b); 20 | int domain_compare_key(const void *a, const void *b); 21 | int domain_compare_toplist(const void *a, const void *b); 22 | double domain_particle_costfactor(int i); 23 | int domain_countToGo(size_t nlimit); 24 | void domain_Decomposition(int UseAllTimeBins, int SaveKeys, int do_particle_mergesplit_key); 25 | int domain_decompose(void); 26 | int domain_determineTopTree(void); 27 | void domain_findExtent(void); 28 | void domain_exchange(void); 29 | void domain_findSplit(int cpustart, int ncpu, int first, int last); 30 | void domain_findSplit_balanced(int cpustart, int ncpu, int first, int last); 31 | void domain_free(void); 32 | void domain_shiftSplit(void); 33 | void domain_sumCost(void); 34 | int domain_topsplit(int node, peanokey startkey); 35 | int domain_topsplit_local(int node, peanokey startkey, int mode); 36 | int domain_topsplit_special(void); 37 | int domain_compare_key(const void *a, const void *b); 38 | int domain_check_for_local_refine(int i, double countlimit, double costlimit); 39 | void domain_free_trick(void); 40 | void domain_allocate_trick(void); 41 | int domain_recursively_combine_topTree(int start, int ncpu); 42 | void domain_walktoptree(int no); 43 | void mysort_domain(void *b, size_t n, size_t s); 44 | -------------------------------------------------------------------------------- /sidm/sidm_core_flux_computation.h: -------------------------------------------------------------------------------- 1 | /* here is where we call the core of the SIDM calculation for DM particle-particle interactions */ 2 | #ifdef DM_SIDM 3 | { 4 | /* check if target+neighbor are an SIDM candidate, and against self-interaction */ 5 | double Pj_dtime = GET_PARTICLE_TIMESTEP_IN_PHYSICAL(j); 6 | if( ((1 << local.Type) & (DM_SIDM)) && ((1 << P[j].Type) & (DM_SIDM)) && (local.ID != P[j].ID) && (local.dtime <= Pj_dtime)) 7 | { 8 | if((local.dtime==Pj_dtime) && (local.ID > P[j].ID)) continue; // ensures interaction will only be calculated once for each pair // 9 | double h_si = 0.5*(kernel.h_i + kernel.h_j), m_si = 0.5*(local.Mass + P[j].Mass); 10 | #ifdef GRAIN_COLLISIONS 11 | double prob = prob_of_grain_interaction(local.Grain_CrossSection_PerUnitMass , local.Mass, kernel.r, h_si, kernel.dv, local.dtime, j); 12 | #else 13 | double prob = prob_of_interaction(m_si, kernel.r, h_si, kernel.dv, local.dtime); 14 | #endif 15 | if(prob > 0.2) {out.dtime_sidm = DMIN(out.dtime_sidm , local.dtime*(0.2/prob));} // timestep condition not being met as desired, warn code to lower timestep next turn // 16 | if (gsl_rng_uniform(random_generator) < prob) 17 | { 18 | #ifdef WAKEUP 19 | if(!(TimeBinActive[P[j].TimeBin])) {if(WAKEUP*local.dtime < Pj_dtime) { 20 | #pragma omp atomic write 21 | PPPZ[j].wakeup=1; 22 | #pragma omp atomic write 23 | NeedToWakeupParticles_local = 1; 24 | }} 25 | #endif 26 | double kick[3]; calculate_interact_kick(kernel.dv, kick, m_si); 27 | int k; for(k=0;k<3;k++) { 28 | out.sidm_kick[k] -= (P[j].Mass/m_si)*kick[k]; 29 | #pragma omp atomic 30 | P[j].Vel[k] += (local.Mass/m_si)*kick[k]; // this variable is modified here so need to do this carefully here to ensure we don't multiply-write at the same time 31 | } 32 | out.si_count++; 33 | #pragma omp atomic 34 | P[j].NInteractions++; 35 | } 36 | } // if((1 << ptype) & (DM_SIDM)) 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /scripts/test_problems/zeldovich.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % EOS_GAMMA=(5.0/3.0) 8 | % 9 | % Also the parameters below are usually recommended (but not necessary) 10 | % 11 | % PMGRID=256 12 | % MULTIPLEDOMAINS=16 13 | % ADAPTIVE_GRAVSOFT_FORGAS 14 | % 15 | InitCondFile zeldovich_ics 16 | OutputDir output 17 | TimeBegin 0.00990099 18 | TimeMax 1 19 | ComovingIntegrationOn 1 20 | Omega_Matter 1 21 | Omega_Lambda 0 22 | Omega_Baryon 1 23 | HubbleParam 1 24 | BoxSize 64000 25 | TimeOfFirstSnapshot 0.00990099 26 | ScaleFac_Between_Snapshots 1.05 27 | MaxSizeTimestep 0.01 28 | DesNumNgb 32 29 | UnitLength_in_cm 3.085678e+21 30 | UnitMass_in_g 1.989e+43 31 | UnitVelocity_in_cm_per_s 100000 32 | SofteningGas 100 % adjust me depending on adaptive softenings! 33 | Softening_Type1 0 % no DM (OmegaBaryon=1); otherwise set this! 34 | Softening_Type2 0 % no type-2 particles 35 | Softening_Type3 0 % no type-3 particles 36 | Softening_Type4 0 % no type-4 particles 37 | Softening_Type5 0 % no type-5 particles 38 | SofteningGasMaxPhys 100 % adjust me depending on adaptive softenings! 39 | Softening_Type1_MaxPhysLimit 0 40 | Softening_Type2_MaxPhysLimit 0 41 | Softening_Type3_MaxPhysLimit 0 42 | Softening_Type4_MaxPhysLimit 0 43 | Softening_Type5_MaxPhysLimit 0 44 | MinGasTemp 0.001 45 | % -- optional numerical parameters (requires additional Config flags) 46 | CourantFac 0.2 47 | ArtCondConstant 0.25 48 | ViscosityAMin 0.025 49 | ViscosityAMax 2 50 | MinGasHsmlFractional 1 51 | 52 | -------------------------------------------------------------------------------- /scripts/visit/README: -------------------------------------------------------------------------------- 1 | GIZMO HDF5 VisIt Plugin 2 | ----------------------- 3 | 4 | This is a VisIt plugin for importing GIZMO HDF5 snapshot files into VisIt. 5 | 6 | 7 | - DEPENDENCIES - 8 | 9 | This plugin was created/tested using 10 | 11 | * cmake 2.8.8 works for me 12 | * HDF5 1.8.11 works for me 13 | * VisIt 2.7.1 works for me 14 | 15 | Other versions might work as well. 16 | 17 | 18 | 19 | - INSTALL - 20 | 21 | To install, first create a CMakeLists.txt file using the xml2cmake utility 22 | bundled with VisIt 23 | 24 | $ xml2cmake -clobber ZelmaniTracers.xml 25 | 26 | Create a build folder for cmake, i.e., from the visit plugin directory: 27 | 28 | $ mkdir build 29 | 30 | Change into the build directory 31 | 32 | $ cd build 33 | 34 | Run cmake 35 | 36 | $ cmake .. 37 | 38 | If successful this should have generated a Makefile. To compile/install do: 39 | 40 | $ make 41 | 42 | This will install the plugin to 43 | 44 | ${HOME}/.visit/${VISIT_VERSION}/${VISIT_ARCH}/plugins 45 | 46 | 47 | 48 | - INDEX FILE - 49 | 50 | This is a STSD (Single Time Single Domain) plugin. This means that the plugin, 51 | by itself, is only able to read a single snapshot file. To deal with chunked 52 | output and/or with multiple times, you need to create a VisIt index file. This 53 | should be an ASCII file with extension ``.visit'' having the following format 54 | (with no indentation): 55 | 56 | !NBLOCKS 2 57 | snapshot.000.0.hdf5 58 | snapshot.000.1.hdf5 59 | snapshot.001.0.hdf5 60 | snapshot.001.1.hdf5 61 | ... 62 | 63 | The ``NBLOCKS'' field specifies the number of chunks of the data (number of 64 | files for each iteration). This is followed by the list of all of the files for 65 | the first iteration, followed by the ones for the second iteration and so on 66 | and so forth. VisIt is able to read this file and figure out how to combine the 67 | different HDF5 files. 68 | 69 | You can create an index file using the script ``make_visit_index.sh'' contained 70 | in this directory, as follows 71 | 72 | $ /bin/bash ./make_visit_index.sh ${nchunks} ${list_of_snapshots} 73 | 74 | For example, to create an index file for an unchunked run out of all of the 75 | HDF5 files, one can do 76 | 77 | $ /bin/bash ./make_visit_index.sh 1 *.hdf5 > snapshot.visit 78 | 79 | 80 | 81 | - CURRENT STATUS - 82 | 83 | This plugin is still EXPERIMENTAL. I would not be surprised if it fails to read 84 | your data. 85 | -------------------------------------------------------------------------------- /system/code_block_primary_loop_evaluation.h: -------------------------------------------------------------------------------- 1 | /* This is a generic code block designed for simple neighbor loops, so that they don't have to 2 | be copy-pasted and can be generically optimized in a single place. specifically this is for 3 | the initial loop of particles on the local processor (and determination of which need passing) 4 | 5 | Two blocks need to be defined or this will crash: 6 | CONDITION_FOR_EVALUATION inserts the clause that actually determines 7 | whether or not to pass a particle to the main evaluation routine 8 | EVALUATION_CALL is the actual call, and needs to be written appropriately 9 | */ 10 | #if !defined(CONDITION_FOR_EVALUATION) || !defined(EVALUATION_CALL) 11 | printf("Cannot compile the primary sub-loop without both CONDITION_FOR_EVALUATION and EVALUATION_CALL defined. Exiting. \n"); fflush(stdout); exit(995533); 12 | #endif 13 | /* variable assignment */ 14 | int i, j, *exportflag, *exportnodecount, *exportindex, *ngblist, thread_id = *(int *) p; 15 | /* define the pointers needed for each thread to speak back regarding what needs processing */ 16 | ngblist = Ngblist + thread_id * NumPart; 17 | exportflag = Exportflag + thread_id * NTask; 18 | exportnodecount = Exportnodecount + thread_id * NTask; 19 | exportindex = Exportindex + thread_id * NTask; 20 | /* Note: exportflag is local to each thread */ 21 | for(j = 0; j < NTask; j++) {exportflag[j] = -1;} 22 | #ifdef _OPENMP 23 | if(BufferCollisionFlag && thread_id) {return NULL;} /* force to serial for this subloop if threads simultaneously cross the Nexport bunchsize threshold */ 24 | #endif 25 | /* now begin the actual loop */ 26 | while(1) 27 | { 28 | int exitFlag = 0; 29 | LOCK_NEXPORT; 30 | #ifdef _OPENMP 31 | #pragma omp critical(_nextlistprimblox_) 32 | #endif 33 | { 34 | if(BufferFullFlag != 0 || NextParticle < 0) 35 | { 36 | exitFlag = 1; 37 | } 38 | else 39 | { 40 | i = NextParticle; 41 | NextParticle = NextActiveParticle[NextParticle]; 42 | } 43 | } 44 | UNLOCK_NEXPORT; 45 | if(exitFlag) {break;} 46 | if(ProcessedFlag[i]) {continue;} 47 | CONDITION_FOR_EVALUATION 48 | { 49 | if(EVALUATION_CALL < 0) {break;} // export buffer has filled up // 50 | } 51 | ProcessedFlag[i] = 1; /* particle successfully finished */ 52 | } 53 | /* loop completed successfully */ 54 | return NULL; 55 | -------------------------------------------------------------------------------- /scripts/test_problems/kh_mcnally_2d.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % BOX_SPATIAL_DIMENSION=2 8 | % SELFGRAVITY_OFF 9 | % EOS_GAMMA=(5.0/3.0) 10 | % KERNEL_FUNCTION=5 11 | % 12 | % (The choice of KERNEL_FUNCTION is optional here. Experiment with different kernels. 13 | % But be sure to set DesNumNgb accordingly; for e.g. KERNEL_FUNCTION=5 or 7, use 40-50, =3 or 4, use 20-32) 14 | % 15 | % the parameters above are required for the hydro version of this problem. 16 | % (modulo, of course, the choice of hydro method). For the MHD version of the 17 | % problem, additionally enable: 18 | % 19 | % MAGNETIC 20 | % MHD_B_SET_IN_PARAMS 21 | % 22 | % and then set the relevant BiniX, BiniY, BiniZ parameters below 23 | % 24 | % note that the default setup of this problem is inviscid, so the small-scale structure is always 25 | % 'seeded' by grid noise, and there is no "converged" solution in the non-linear structure (the structure 26 | % should appear at infinitely small scales, at infinite resolution). Following 27 | % Lecoanet et al. 2016 (MNRAS, 455, 4274), to actually obtain define-ably converged solutions, 28 | % need to make the system have a finite Reynolds number. To do this, add finite viscosity. So experiment 29 | % with the flags: 30 | % 31 | % CONDUCTION 32 | % VISCOSITY 33 | % 34 | % which are controlled by the flags 'ShearViscosityCoeff', 'BulkViscosityCoeff', 'ConductionCoeff' (see below) 35 | % 36 | InitCondFile kh_mcnally_2d_ics % or try 'kh_mcnally_2dgrid_ics' 37 | OutputDir output 38 | TimeMax 10 39 | BoxSize 1 40 | TimeBetSnapshot 0.1 41 | MaxSizeTimestep 0.02 42 | DesNumNgb 40 43 | % -- optional physics parameters 44 | BiniX 0.07 45 | BiniY 1.0e0 46 | BiniZ 1.0e0 47 | ConductionCoeff 0.0002 48 | ShearViscosityCoeff 0.0002 49 | BulkViscosityCoeff 0.0 50 | % -- optional numerical parameters (requires additional Config flags) 51 | CourantFac 0.1 52 | 53 | -------------------------------------------------------------------------------- /scripts/test_problems/zeldovich_mhd.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % MAGNETIC 8 | % MHD_B_SET_IN_PARAMS 9 | % 10 | % Also the parameters below are usually recommended (but not necessary) 11 | % 12 | % PMGRID=128 13 | % MULTIPLEDOMAINS=16 14 | % ADAPTIVE_GRAVSOFT_FORGAS 15 | % 16 | % The methods paper includes two versions of this test, with 'weak' and 'strong' 17 | % initial fields. This corresponds to setting BiniY=0.05517 or BiniY=3.395, 18 | % respectively. So change the example value below to reproduce both limits. 19 | % 20 | InitCondFile zeldovich_mhd_ics 21 | OutputDir output 22 | TimeBegin 0.047619 23 | TimeMax 1 24 | ComovingIntegrationOn 1 25 | Omega_Matter 1 26 | Omega_Lambda 0 27 | Omega_Baryon 1 28 | HubbleParam 1 29 | BoxSize 1 30 | TimeOfFirstSnapshot 0.047619 31 | ScaleFac_Between_Snapshots 1.15 32 | MaxSizeTimestep 0.01 33 | DesNumNgb 32 34 | BiniX 0 35 | BiniY 3.395 36 | BiniZ 0 37 | UnitLength_in_cm 1.97483e+26 38 | UnitMass_in_g 1.44759e+50 39 | UnitVelocity_in_cm_per_s 3.6e+09 40 | UnitMagneticField_in_gauss 5.53268e-05 41 | SofteningGas 0.00015 42 | Softening_Type1 0 % no DM (OmegaBaryon=1); otherwise set this! 43 | Softening_Type2 0 % no type-2 particles 44 | Softening_Type3 0 % no type-3 particles 45 | Softening_Type4 0 % no type-4 (newly-formed star) particles 46 | Softening_Type5 0 % no type-5 (blackhole) particles 47 | SofteningGasMaxPhys 0.00015 48 | Softening_Type1_MaxPhysLimit 0 49 | Softening_Type2_MaxPhysLimit 0 50 | Softening_Type3_MaxPhysLimit 0 51 | Softening_Type4_MaxPhysLimit 0 52 | Softening_Type5_MaxPhysLimit 0 53 | MinGasTemp 1e-20 54 | MinGasHsmlFractional 1 55 | -------------------------------------------------------------------------------- /eos/helmholtz/helm_const.dek: -------------------------------------------------------------------------------- 1 | ! 2 | ! mathematical and physical constants (in cgs,except e0 which is in ev) 3 | ! 4 | ! the 2006 codta recommended valeus of the physical constants 5 | ! by coehn & taylor 6 | 7 | 8 | ! declare 9 | double precision pi,a2rad,rad2a,eulercon 10 | double precision g,h,hbar,qe,avo,clight,kerg,kev,amu,mn,mp,me, & 11 | rbohr,fine,hion,ev2erg,ssol,asol,weinfre,weinlam, & 12 | rhonuc 13 | double precision msol,rsol,lsol,mearth,rearth,ly,pc,au, & 14 | secyer 15 | 16 | ! math constants 17 | parameter (pi = 3.1415926535897932384d0, & 18 | eulercon = 0.577215664901532861d0, & 19 | a2rad = pi/180.0d0, rad2a = 180.0d0/pi) 20 | 21 | ! physical constants 22 | parameter (g = 6.6742867d-8, & 23 | h = 6.6260689633d-27, & 24 | hbar = 0.5d0 * h/pi, & 25 | qe = 4.8032042712d-10, & 26 | avo = 6.0221417930d23, & 27 | clight = 2.99792458d10, & 28 | kerg = 1.380650424d-16, & 29 | ev2erg = 1.60217648740d-12, & 30 | kev = kerg/ev2erg, & 31 | amu = 1.66053878283d-24, & 32 | mn = 1.67492721184d-24, & 33 | mp = 1.67262163783d-24, & 34 | me = 9.1093821545d-28, & 35 | rbohr = hbar*hbar/(me * qe * qe), & 36 | fine = qe*qe/(hbar*clight), & 37 | hion = 13.605698140d0) 38 | 39 | parameter (ssol = 5.67051d-5, & 40 | asol = 4.0d0 * ssol / clight, & 41 | weinlam = h*clight/(kerg * 4.965114232d0), & 42 | weinfre = 2.821439372d0*kerg/h, & 43 | rhonuc = 2.342d14) 44 | 45 | 46 | ! astronomical constants 47 | parameter (msol = 1.9892d33, & 48 | rsol = 6.95997d10, & 49 | lsol = 3.8268d33, & 50 | mearth = 5.9764d27, & 51 | rearth = 6.37d8, & 52 | ly = 9.460528d17, & 53 | pc = 3.261633d0 * ly, & 54 | au = 1.495978921d13, & 55 | secyer = 3.1558149984d7) 56 | -------------------------------------------------------------------------------- /cooling/chimes/params_chimes.txt: -------------------------------------------------------------------------------- 1 | %------------------------------------------------------------------------- 2 | %---- This is an example parameter file like the included "params.txt" 3 | % for GIZMO, showing an example set of CHIMES parameters added. 4 | % (all the other parameters need to be added too -- this is just 5 | % an example of the CHIMES-specific 'block') 6 | % See the CHIMES-specific readme for more details of the additions 7 | %------------------------------------------------------------------------- 8 | Chimes_data_path /path/reaction_network/chimes-data 9 | PhotoIonTable FG20_cross_sections/z0.000_cross_sections.hdf5 10 | Thermal_Evolution_On 1 % 0=evolve chemistry only; 1=evolve temperature and chemistry. 11 | Chemistry_eqm 0 % 0=NonEq; 1=eqm tables; 2=solve eqm from rate eqns. 12 | StaticMolCooling 0 % 0=incl Div(velocity); 1=thermal line broadening only. 13 | CellSelfShielding_On 2 % 0=optically thin; 1=update column densities within chemistry solver; 2=only update column densities at start of hydro step. 14 | Shielding_length_factor 0.5 % Multiplicative factor for the shielding length. 15 | Grain_Temperature 10 % dust temperature in K 16 | CR_rate 1.8e-16 % HI ionisation rate from cosmic rays, s^-1 17 | max_mol_temperature 1.0e5 % K; above this temperature, molecules are excluded. 18 | rad_field_norm_factor 1.0 % Multiplicative factor to scale the UV field given by the PhotoIonTable 19 | relativeTolerance 1.0e-4 % Controls accuracy of thermo-chemistry integration. 20 | absoluteTolerance 1.0e-10 % Controls accuracy of chemistry integration. 21 | explicitTolerance 0.1 % Controls accuracy of chemistry integration. 22 | scale_metal_tolerances 0 % 0=fixed, 1=scaled 23 | IncludeCarbon 1 % 0=exclude carbon from chemistry network; 1=include it. 24 | IncludeNitrogen 1 % NOTE: These IncludeXXX parameters also require 25 | IncludeOxygen 1 % the METALS and COOL_METAL_LINES_BY_SPECIES Config flags, 26 | IncludeNeon 1 % otherwise the metal abundances will be set to zero. 27 | IncludeMagnesium 1 28 | IncludeSilicon 1 29 | IncludeSulphur 1 30 | IncludeCalcium 1 31 | IncludeIron 1 32 | chimes_debug 0 % Controls debug statements from CHIMES. 33 | N_chimes_full_output_freq 10 % How often all abundances are written to snapshot (req. CHIMES_REDUCED_OUTPUT). 34 | Chimes_f_esc_ion 0.05 % minimum enforced ionizing photon escape fraction from local attenuation 35 | Chimes_f_esc_G0 0.1 % minimum enforced FUV (photoelectric) photon escape from local attenuation 36 | -------------------------------------------------------------------------------- /scripts/test_problems/sbcluster.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % 8 | % The following parameters are recommended, but not strictly necessary: 9 | % 10 | % PMGRID=32 11 | % PM_HIRES_REGION_CLIPPING=1000 12 | % MULTIPLEDOMAINS=16 13 | % ADAPTIVE_GRAVSOFT_FORGAS 14 | % 15 | % For the MHD version of the problem, be sure to enable: 16 | % 17 | % MAGNETIC 18 | % MHD_B_SET_IN_PARAMS 19 | % 20 | % 21 | InitCondFile sbcluster_ics 22 | OutputDir output 23 | PartAllocFactor 5 24 | TimeBegin 0.02 25 | TimeMax 1 26 | ComovingIntegrationOn 1 27 | BoxSize 1 28 | Omega_Matter 1 29 | Omega_Lambda 0 30 | Omega_Baryon 0.1 31 | HubbleParam 0.5 32 | TimeOfFirstSnapshot 0.02 33 | ScaleFac_Between_Snapshots 2 34 | MaxSizeTimestep 0.01 35 | DesNumNgb 32 36 | UnitLength_in_cm 9.87417e+25 37 | UnitMass_in_g 1.80886e+49 38 | UnitVelocity_in_cm_per_s 1.10567e+08 39 | UnitMagneticField_in_gauss 1 40 | MinGasHsmlFractional 1 41 | % set softenings in code units. note the default setup here has only gas and DM 42 | % which are types 0 and 1, respectively. values for other types wont matter 43 | % unless added physics (e.g. star formation) is enabled 44 | SofteningGas 0.0001 % alt. 'Softening_Type0' 45 | SofteningHalo 0.0005 % alt. 'Softening_Type1' 46 | Softening_Type2 0 47 | Softening_Type3 0 48 | Softening_Type4 0 49 | Softening_Type5 0 50 | SofteningGasMaxPhys 0.0001 % alt. 'Softening_Type0_MaxPhysLimit' 51 | SofteningHaloMaxPhys 0.0005 % alt. 'Softening_Type1_MaxPhysLimit' 52 | Softening_Type2_MaxPhysLimit 0 53 | Softening_Type3_MaxPhysLimit 0 54 | Softening_Type4_MaxPhysLimit 0 55 | Softening_Type5_MaxPhysLimit 0 56 | InitGasTemp 100 57 | MinGasTemp 10 58 | % -- optional physics parameters (B-field) 59 | BiniX 0 60 | BiniY 0 61 | BiniZ 1e-08 62 | -------------------------------------------------------------------------------- /scripts/compress_gizmosnap.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import h5py 4 | import argparse 5 | import functools 6 | import tempfile 7 | 8 | ## this is the core compression subroutine 9 | def copy_level0(fs, fd, name, node): 10 | if isinstance(node, h5py.Dataset): 11 | # create the new dataset, defaulting to gzip level 4 compression, 12 | # including chunking/shuffle options, which work well. 13 | dnew = fd.create_dataset(name, data=node, dtype=node.dtype, chunks=True, 14 | shuffle=True, compression="gzip", compression_opts=4, fletcher32=True); 15 | print(' ..dataset {} ({}) compressed'.format(name,node.dtype)); 16 | elif isinstance(node, h5py.Group) and name == 'Header': 17 | # header entries don't get compressed, but are negligible for storage 18 | fs.copy(name, fd, name=name); 19 | print(' Header copied'); 20 | else: 21 | print(' Group {}'.format(name)); 22 | 23 | ## this is the main loop, called by parser, which does all the os-level operations 24 | def main(filename): 25 | print('Losslessly compressing snapshot {}'.format(filename)); # start 26 | fs = h5py.File(filename, 'r'); # open file 27 | # check that the file has not already been compressed, in which case, exit 28 | if('CompactLevel' in fs['Header'].attrs): 29 | print(' .. this snapshot has already been compressed, done'); 30 | fs.close(); 31 | return; 32 | # create a temporary working file for intermediate steps 33 | tmpfilename = filename+'__tmp__'; 34 | fd = h5py.File(tmpfilename, 'w'); 35 | # recursively do the work here on the entries (call and compress) 36 | copy_datasets = functools.partial(copy_level0, fs, fd); 37 | fs.visititems(copy_datasets); 38 | # encode that the file is compressed, so it can be skipped in future 39 | fd['Header'].attrs['CompactLevel'] = 0; 40 | # close and rename temp file to replace original file 41 | fd.close(); fs.close(); os.rename(tmpfilename,filename); 42 | print(' Completed'); 43 | return; 44 | 45 | ## this is the parser, meant to be called from the command-line 46 | if __name__ == '__main__': 47 | parser = argparse.ArgumentParser( 48 | description='Losslessly compress GIZMO hdf5 snapshots.' 49 | '(c) R. Feldmann 2017, modified by PFH 2020') 50 | parser.add_argument('filename', help='hdf5 file to be compactified ' 51 | '(file will be over-written)') 52 | 53 | if len(sys.argv[1:]) == 0: 54 | print('Error: {} requires more parameters'.format(__file__)); 55 | parser.print_help(); 56 | parser.exit(); 57 | 58 | args = parser.parse_args(); 59 | main(args.filename) 60 | -------------------------------------------------------------------------------- /cooling/cooling.h: -------------------------------------------------------------------------------- 1 | #ifndef INLINE_FUNC 2 | #ifdef INLINE 3 | #define INLINE_FUNC inline 4 | #else 5 | #define INLINE_FUNC 6 | #endif 7 | #endif 8 | 9 | /* 10 | * This file contains the definitions for the cooling.c routines 11 | * 12 | * This file was originally part of the GADGET3 code developed by 13 | * Volker Springel. The code has been modified by Phil Hopkins (phopkins@caltech.edu) for GIZMO. 14 | */ 15 | 16 | double ThermalProperties(double u, double rho, int target, double *mu_guess, double *ne_guess, double *nH0_guess, double *nHp_guess, double *nHe0_guess, double *nHep_guess, double *nHepp_guess); 17 | double return_uvb_shieldfac(int target, double gamma_12, double nHcgs, double logT); 18 | double return_local_gammamultiplier(int target); 19 | double evaluate_Compton_heating_cooling_rate(int target, double T, double nHcgs, double n_elec, double shielding_factor_for_exgalbg); 20 | double get_background_radiation_temperature_for_emission_corrections(int target); 21 | void InitCool(void); 22 | #ifndef CHIMES 23 | void InitCoolMemory(void); 24 | void IonizeParams(void); 25 | void IonizeParamsFunction(void); 26 | void IonizeParamsTable(void); 27 | //double INLINE_FUNC LogTemp(double u, double ne); 28 | void MakeCoolingTable(void); 29 | void ReadIonizeParams(char *fname); 30 | void SetZeroIonization(void); 31 | #endif 32 | void TestCool(void); 33 | 34 | #ifndef CHIMES 35 | double find_abundances_and_rates(double logT, double rho, int target, double shieldfac, int return_cooling_mode, 36 | double *ne_guess, double *nH0_guess, double *nHp_guess, double *nHe0_guess, double *nHep_guess, double *nHepp_guess, double *mu_guess, 37 | double *LambdaExc_return, double *LambdaIon_return, double *LambdaRec_return, double *LambdaFF_return); 38 | double convert_u_to_temp(double u, double rho, int target, double *ne_guess, double *nH0_guess, double *nHp_guess, double *nHe0_guess, double *nHep_guess, double *nHepp_guess, double *mu_guess); 39 | double CoolingRate(double logT, double rho, double n_elec_guess, double *n_elec_eval, int target); 40 | double CoolingRateFromU(double u, double rho, double ne_guess, double *ne_eval, int target); 41 | #endif 42 | double DoCooling(double u_old, double rho, double dt, double ne_guess, double *ne_eval, int target); 43 | #ifndef CHIMES 44 | double GetCoolingTime(double u_old, double rho, double ne_guess, double *ne_eval, int target); 45 | double DoInstabilityCooling(double m_old, double u, double rho, double dt, double fac, double ne_guess, double *ne_eval, int target); 46 | #endif 47 | 48 | #ifdef COOL_GRACKLE 49 | void InitGrackle(void); 50 | double CallGrackle(double u_old, double rho, double dt, double ne_guess, int target, int mode); 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /structure/fof.h: -------------------------------------------------------------------------------- 1 | #ifndef FOF_H 2 | #define FOF_H 3 | #include "../allvars.h" 4 | 5 | /* variables for fof.c code */ 6 | /* 7 | * This file was originally part of the GADGET3 code developed by Volker Springel. 8 | * It has been updated significantly by PFH for basic compatibility with GIZMO, 9 | * as well as code cleanups, and accommodating new GIZMO functionality for various 10 | * other operations. 11 | */ 12 | 13 | void fof_exchange_group_data(void); 14 | int fof_compare_FOF_PList_MinID(const void *a, const void *b); 15 | int fof_compare_FOF_GList_MinID(const void *a, const void *b); 16 | int fof_compare_FOF_GList_MinIDTask(const void *a, const void *b); 17 | int fof_compare_FOF_GList_MinIDTask_MinID(const void *a, const void *b); 18 | int fof_compare_FOF_GList_LocCountTaskDiffMinID(const void *a, const void *b); 19 | int fof_compare_FOF_GList_ExtCountMinID(const void *a, const void *b); 20 | int fof_compare_Group_GrNr(const void *a, const void *b); 21 | int fof_compare_Group_MinIDTask(const void *a, const void *b); 22 | int fof_compare_Group_MinID(const void *a, const void *b); 23 | int fof_compare_ID_list_GrNrID(const void *a, const void *b); 24 | int fof_compare_Group_MinIDTask_MinID(const void *a, const void *b); 25 | int fof_compare_Group_Len(const void *a, const void *b); 26 | void fof_finish_group_properties(void); 27 | int compare_group_mass_ID(const void *a, const void *b); 28 | void fof_assign_HostHaloMass(void); 29 | extern int Ngroups, TotNgroups; 30 | extern long long TotNids; 31 | 32 | 33 | 34 | 35 | typedef struct 36 | { 37 | MyIDType MinID; 38 | MyIDType MinIDTask; 39 | int LocCount; 40 | int ExtCount; 41 | #ifdef FOF_DENSITY_SPLIT_TYPES 42 | int LocDMCount; 43 | int ExtDMCount; 44 | #endif 45 | int GrNr; 46 | } fof_group_list; 47 | 48 | typedef struct 49 | { 50 | int Len; 51 | unsigned int Offset; 52 | MyIDType MinID; 53 | MyIDType MinIDTask; 54 | int GrNr; 55 | int LenType[6]; 56 | MyOutputFloat MassType[6]; 57 | MyOutputFloat Mass; 58 | MyOutputFloat CM[3]; 59 | MyOutputFloat Vel[3]; 60 | MyDouble FirstPos[3]; 61 | #ifdef GALSF 62 | double Sfr; 63 | #endif 64 | #ifdef BLACK_HOLES 65 | MyOutputFloat BH_Mass; 66 | MyOutputFloat BH_Mdot; 67 | #ifdef BH_SEED_FROM_FOF 68 | MyOutputFloat MinPot; 69 | int index_maxdens, task_maxdens; 70 | #endif 71 | #endif 72 | 73 | #ifdef SUBFIND 74 | int Nsubs; 75 | int FirstSub; 76 | MyDouble Pos[3]; 77 | int ContaminationLen; 78 | MyOutputFloat ContaminationMass; 79 | struct Subfind_DensityOtherPropsEval_data_out SubHaloProps_vsDelta[SUBFIND_ADDIO_NUMOVERDEN]; 80 | #endif 81 | 82 | } group_properties; 83 | extern group_properties *Group; 84 | 85 | typedef struct 86 | { 87 | MyIDType ID; 88 | unsigned int GrNr; 89 | } fof_id_list; 90 | 91 | #endif // FOF_H 92 | -------------------------------------------------------------------------------- /system/code_block_xchange_initialize.h: -------------------------------------------------------------------------------- 1 | /* this is a 'pre-amble' block which must be included before 2 | the code in 'code_block_xchange...(any of the other routines).h' is called. 3 | It sets a number of variable and function names based on the user-specified 4 | parent routine name (which should of course itself be unique!). It also sets 5 | up some definitions for the multi-threading, and pre-defines some of the 6 | subroutines which will be referenced. */ 7 | 8 | /* initialize some thread information */ 9 | #ifdef PTHREADS_NUM_THREADS 10 | #include 11 | #endif 12 | #ifdef PTHREADS_NUM_THREADS 13 | extern pthread_mutex_t mutex_nexport; 14 | extern pthread_mutex_t mutex_partnodedrift; 15 | #define LOCK_NEXPORT pthread_mutex_lock(&mutex_nexport); 16 | #define UNLOCK_NEXPORT pthread_mutex_unlock(&mutex_nexport); 17 | #else 18 | #define LOCK_NEXPORT 19 | #define UNLOCK_NEXPORT 20 | #endif 21 | 22 | /* initialize macro and variable names: these define structures/variables with names following the value of CORE_FUNCTION_NAME with the '_data_in' and other terms appended -- this should be unique within the file defined! */ 23 | #define INPUT_STRUCT_NAME MACRO_NAME_CONCATENATE(CORE_FUNCTION_NAME, _data_in_) 24 | #define DATAIN_NAME MACRO_NAME_CONCATENATE(CORE_FUNCTION_NAME, _DataIn_) 25 | #define DATAGET_NAME MACRO_NAME_CONCATENATE(CORE_FUNCTION_NAME, _DataGet_) 26 | #define OUTPUT_STRUCT_NAME MACRO_NAME_CONCATENATE(CORE_FUNCTION_NAME, _data_out_) 27 | #define DATAOUT_NAME MACRO_NAME_CONCATENATE(CORE_FUNCTION_NAME, _DataOut_) 28 | #define DATARESULT_NAME MACRO_NAME_CONCATENATE(CORE_FUNCTION_NAME, _DataResult_) 29 | #define PRIMARY_SUBFUN_NAME MACRO_NAME_CONCATENATE(CORE_FUNCTION_NAME, _subfun_primary_) 30 | #define SECONDARY_SUBFUN_NAME MACRO_NAME_CONCATENATE(CORE_FUNCTION_NAME, _subfun_secondary_) 31 | #ifndef INPUTFUNCTION_NAME /* assign a default name if one is not user-specified */ 32 | #define INPUTFUNCTION_NAME MACRO_NAME_CONCATENATE(CORE_FUNCTION_NAME, _particle2in_) 33 | #endif 34 | #ifndef OUTPUTFUNCTION_NAME /* assign a default name if one is not user-specified */ 35 | #define OUTPUTFUNCTION_NAME MACRO_NAME_CONCATENATE(CORE_FUNCTION_NAME, _out2particle_) 36 | #endif 37 | 38 | 39 | /* define generic forms of functions used below */ 40 | int CORE_FUNCTION_NAME(int target, int mode, int *exportflag, int *exportnodecount, int *exportindex, int *ngblist, int loop_iteration); 41 | //static inline void INPUTFUNCTION_NAME(struct INPUT_STRUCT_NAME *in, int i, int loop_iteration); 42 | //static inline void OUTPUTFUNCTION_NAME(struct OUTPUT_STRUCT_NAME *out, int i, int mode, int loop_iteration); 43 | static inline void *PRIMARY_SUBFUN_NAME(void *p, int loop_iteration); 44 | static inline void *SECONDARY_SUBFUN_NAME(void *p, int loop_iteration); 45 | 46 | -------------------------------------------------------------------------------- /scripts/test_problems/core.params: -------------------------------------------------------------------------------- 1 | % Example compile-time options: 2 | % (HYDRO_MESHLESS_FINITE_MASS is optional, replace with your 3 | % choice of hydro/mhd options) 4 | % 5 | % HYDRO_MESHLESS_FINITE_MASS 6 | % BOX_PERIODIC 7 | % EOS_GAMMA=(5.0/3.0) 8 | % EOS_ENFORCE_ADIABAT=(1.0) 9 | % GRAVITY_NOT_PERIODIC 10 | % MAGNETIC 11 | % MHD_B_SET_IN_PARAMS 12 | % 13 | % strongly recommended, but not strictly required: 14 | % 15 | % MULTIPLEDOMAINS=16 16 | % ADAPTIVE_GRAVSOFT_FORGAS 17 | % 18 | % the initial field value is set by BiniZ below. For the default 19 | % value given, this corresponds to the mu=10 simulations 20 | % in the methods paper. These runs use ~64^3 total particles, with 21 | % ~50^3 in the initial spherical region which will collapse (the rest 22 | % are effectively 'boundary zone' particles) 23 | % 24 | % The test problems in the paper require a special (non-standard) equation 25 | % of state, which is not simply set by a code flag. To enable this for a 26 | % proper comparison, you must change one line of the source code before 27 | % compilation. In the file "eos.c", find the lines: 28 | % 29 | % #ifdef EOS_ENFORCE_ADIABAT 30 | % press = EOS_ENFORCE_ADIABAT * pow(SphP[i].Density, GAMMA); 31 | % #endif 32 | % 33 | % Obviously, this line enforces a typical adiabatic equation of state. 34 | % We just need to replace this particular press = .... line with the following: 35 | % 36 | % #ifdef EOS_ENFORCE_ADIABAT 37 | % press = 0.04*SphP[i].Density*sqrt(1.+pow(SphP[i].Density/1.47705e8 ,4./3.)); 38 | % #endif 39 | % 40 | % This will use the specific barytropic equation of state from the paper, instead. 41 | % Note that this is hard-coded to a certain assumed set of units (corresponding 42 | % to the example choices below). 43 | % 44 | % 45 | InitCondFile core_ics 46 | OutputDir output 47 | TimeMax 0.25 48 | BoxSize 0.15 49 | TimeBetSnapshot 0.001 50 | DesNumNgb 32 51 | BiniX 0 52 | BiniY 0 53 | BiniZ 6.1019e-05 % initial field strength 54 | UnitLength_in_cm 3.085678e+18 55 | UnitMass_in_g 1.9891e+33 56 | UnitVelocity_in_cm_per_s 100000 57 | UnitMagneticField_in_gauss 1 58 | SofteningGas 5e-6 59 | Softening_Type1 5e-6 60 | Softening_Type2 5e-6 61 | Softening_Type3 5e-6 62 | Softening_Type4 5e-6 63 | Softening_Type5 5e-6 64 | % -- optional parameters - speed up the test with bigger steps, but maybe bigger errors 65 | MaxSizeTimestep 5e-05 66 | MaxHsml 100 67 | -------------------------------------------------------------------------------- /radiation/rt_direct_ray_transport.h: -------------------------------------------------------------------------------- 1 | /* --------------------------------------------------------------------------------- */ 2 | /* ... explicit radiation transport evaluation along rays (for Jiang et al. module) ... 3 | * 4 | * Solve the explicit transport problem for intensity along rays on the ray-grid 5 | * carried by elements, following Jiang et al. 2014's method. 6 | * Currently a piecewise-constant reconstruction (adding higher-order shortly, 7 | * this is temporary but being used for testing before doing so) 8 | * 9 | * This file was written by Phil Hopkins (phopkins@caltech.edu) for GIZMO. 10 | */ 11 | /* --------------------------------------------------------------------------------- */ 12 | 13 | #if defined(RT_EVOLVE_INTENSITIES) 14 | if(local.Mass>0 && P[j].Mass>0 && dt_hydrostep>0 && Face_Area_Norm>0) 15 | { 16 | double c_light_eff=C_LIGHT_CODE_REDUCED, rsol_fac=c_light_eff/C_LIGHT_CODE, V_i_invphys=All.cf_a3inv/V_i, V_j_invphys=All.cf_a3inv/V_j, vfluid_minus_vface_dotA=0, cminusv_n_dotA[N_RT_INTENSITY_BINS]={0}, sigma_j=Particle_Size_j*(SphP[j].Density*All.cf_a3inv); int k_freq, k_angle; 17 | #if defined(HYDRO_MESHLESS_FINITE_VOLUME) && (HYDRO_FIX_MESH_MOTION<5) 18 | double v_frame[3]={0}; for(k=0;k<3;k++) {vfluid_minus_vface_dotA+=0.5*((ParticleVel_j[k]+local.ParticleVel[k])-(local.Vel[k]+VelPred_j[k]))/All.cf_atime * Face_Area_Vec[k];} // frame velocity, not fluid velocity, is what appears here. physical units 19 | #endif 20 | for(k_angle=0; k_angle3.5) {a_tau=1./q_tau;} else {if(q_tau<0.1) {a_tau=1.-0.25*q_tau*q_tau;} else {a_tau=sqrt(1.-exp(-q_tau*q_tau))/q_tau;}} 27 | 28 | for(k_angle=0; k_angle 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /* 10 | * This file was originally part of the GADGET3 code by Volker Springel. 11 | */ 12 | 13 | #ifdef IMPOSE_PINNING 14 | 15 | #define __USE_GNU 16 | 17 | #include 18 | 19 | #include "../allvars.h" 20 | #include "../proto.h" 21 | 22 | #ifndef SOCKETS 23 | #define SOCKETS 4 /* Setting for our 4 x AMD Magny-Cours nodes */ 24 | #define MAX_CORES 48 /* Setting for our 4 x AMD Magny-Cours nodes */ 25 | #endif 26 | 27 | /* SOCKETS = 12 for 2 x Intel 6-core nodes with hypethreading */ 28 | /* MAX_CORES = 24 for 2 x Intel 6-core nodes with hypethreading */ 29 | 30 | static cpu_set_t cpuset; 31 | 32 | 33 | void get_core_set(void) 34 | { 35 | CPU_ZERO(&cpuset); 36 | sched_getaffinity(getpid(), sizeof(cpuset), &cpuset); 37 | } 38 | 39 | 40 | void pin_to_core_set(void) 41 | { 42 | int core, task, num_threads; 43 | static cpu_set_t cpuset_new; 44 | 45 | char *p = getenv("OMP_NUM_THREADS"); 46 | if(p) 47 | num_threads = atoi(p); 48 | else 49 | num_threads = 1; 50 | 51 | #ifdef PTHREADS_NUM_THREADS 52 | if(num_threads != PTHREADS_NUM_THREADS) 53 | { 54 | terminate("You have activated PTHREADS_NUM_THREADS, but the value of the environment variable OMP_NUM_THREADS is not equal to PTHREADS_NUM_THREADS!"); 55 | } 56 | #endif 57 | 58 | 59 | CPU_ZERO(&cpuset_new); 60 | 61 | int corestart = 0; 62 | 63 | for(task=0, core= corestart; task < NTask * num_threads; task++) 64 | { 65 | while(!CPU_ISSET(core, &cpuset)) 66 | { 67 | core += SOCKETS; 68 | if(core >= MAX_CORES) 69 | { 70 | corestart++; 71 | if(corestart >= SOCKETS) 72 | corestart = 0; 73 | 74 | core = corestart; 75 | } 76 | } 77 | 78 | if((task / num_threads) == ThisTask) 79 | CPU_SET(core, &cpuset_new); 80 | 81 | core += SOCKETS; 82 | if(core >= MAX_CORES) 83 | { 84 | corestart++; 85 | if(corestart >= SOCKETS) 86 | corestart = 0; 87 | 88 | core = corestart; 89 | } 90 | } 91 | 92 | sched_setaffinity (getpid(), sizeof(cpuset_new), &cpuset_new); 93 | } 94 | 95 | 96 | void report_pinning(void) 97 | { 98 | cpu_set_t cpuset; 99 | int i; 100 | char buf[MAX_CORES+1]; 101 | 102 | CPU_ZERO (&cpuset); 103 | sched_getaffinity (getpid(), sizeof(cpuset), &cpuset); 104 | 105 | for(i=0;i 40 | 41 | // **************************************************************************** 42 | // Function: GetMDServerInfo 43 | // 44 | // Purpose: 45 | // Return a new MDServerPluginInfo for the GIZMO database. 46 | // 47 | // Programmer: generated by xml2info 48 | // Creation: omitted 49 | // 50 | // **************************************************************************** 51 | extern "C" DBP_EXPORT MDServerDatabasePluginInfo* GIZMO_GetMDServerInfo() 52 | { 53 | return new GIZMOMDServerPluginInfo; 54 | } 55 | 56 | // this makes compilers happy... remove if we ever have functions here 57 | void GIZMOMDServerPluginInfo::dummy() 58 | { 59 | } 60 | 61 | -------------------------------------------------------------------------------- /scripts/visit/GIZMOEnginePluginInfo.C: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * 3 | * Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC 4 | * Produced at the Lawrence Livermore National Laboratory 5 | * LLNL-CODE-442911 6 | * All rights reserved. 7 | * 8 | * This file is part of VisIt. For details, see https://visit.llnl.gov/. The 9 | * full copyright notice is contained in the file COPYRIGHT located at the root 10 | * of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * - Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the disclaimer below. 17 | * - Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the disclaimer (as noted below) in the 19 | * documentation and/or other materials provided with the distribution. 20 | * - Neither the name of the LLNS/LLNL nor the names of its contributors may 21 | * be used to endorse or promote products derived from this software without 22 | * specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | * ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, 28 | * LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY 29 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 35 | * DAMAGE. 36 | * 37 | *****************************************************************************/ 38 | 39 | #include 40 | 41 | // **************************************************************************** 42 | // Function: GetEngineInfo 43 | // 44 | // Purpose: 45 | // Return a new EnginePluginInfo for the GIZMO database. 46 | // 47 | // Programmer: generated by xml2info 48 | // Creation: omitted 49 | // 50 | // **************************************************************************** 51 | extern "C" DBP_EXPORT EngineDatabasePluginInfo* GIZMO_GetEngineInfo() 52 | { 53 | return new GIZMOEnginePluginInfo; 54 | } 55 | 56 | // **************************************************************************** 57 | // Method: GIZMOEnginePluginInfo::GetWriter 58 | // 59 | // Purpose: 60 | // Sets up a GIZMO writer. 61 | // 62 | // Returns: A GIZMO writer. 63 | // 64 | // Programmer: generated by xml2info 65 | // Creation: omitted 66 | // 67 | // **************************************************************************** 68 | avtDatabaseWriter * 69 | GIZMOEnginePluginInfo::GetWriter(void) 70 | { 71 | return NULL; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /system/allocate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "../allvars.h" 7 | #include "../proto.h" 8 | 9 | 10 | /* This routine allocates memory for particle storage, both the collisionless and the fluid particles. 11 | * The memory for the ordered binary tree of the timeline is also allocated. 12 | */ 13 | /* 14 | * This file was originally part of the GADGET3 code developed by 15 | * Volker Springel. The code has been modified 16 | * in part (cleaned up a bit, dealt with some newer memory 17 | * structures and allocation strategies) by Phil Hopkins 18 | * (phopkins@caltech.edu) for GIZMO. 19 | */ 20 | 21 | void allocate_memory(void) 22 | { 23 | size_t bytes; 24 | 25 | double bytes_tot = 0; 26 | 27 | int NTaskTimesThreads; 28 | 29 | NTaskTimesThreads = maxThreads * NTask; 30 | 31 | Exportflag = (int *) mymalloc("Exportflag", NTaskTimesThreads * sizeof(int)); 32 | Exportindex = (int *) mymalloc("Exportindex", NTaskTimesThreads * sizeof(int)); 33 | Exportnodecount = (int *) mymalloc("Exportnodecount", NTaskTimesThreads * sizeof(int)); 34 | 35 | Send_count = (int *) mymalloc("Send_count", sizeof(int) * NTask); 36 | Send_offset = (int *) mymalloc("Send_offset", sizeof(int) * NTask); 37 | Recv_count = (int *) mymalloc("Recv_count", sizeof(int) * NTask); 38 | Recv_offset = (int *) mymalloc("Recv_offset", sizeof(int) * NTask); 39 | 40 | ProcessedFlag = (unsigned char *) mymalloc("ProcessedFlag", bytes = All.MaxPart * sizeof(unsigned char)); 41 | bytes_tot += bytes; 42 | 43 | NextActiveParticle = (int *) mymalloc("NextActiveParticle", bytes = All.MaxPart * sizeof(int)); 44 | bytes_tot += bytes; 45 | 46 | NextInTimeBin = (int *) mymalloc("NextInTimeBin", bytes = All.MaxPart * sizeof(int)); 47 | bytes_tot += bytes; 48 | 49 | PrevInTimeBin = (int *) mymalloc("PrevInTimeBin", bytes = All.MaxPart * sizeof(int)); 50 | bytes_tot += bytes; 51 | 52 | 53 | if(All.MaxPart > 0) 54 | { 55 | if(!(P = (struct particle_data *) mymalloc("ParticleData_P", bytes = All.MaxPart * sizeof(struct particle_data)))) 56 | { 57 | printf("failed to allocate memory for particle data storage structure `P' (%g MB).\n", bytes / (1024.0 * 1024.0)); 58 | endrun(1); 59 | } 60 | bytes_tot += bytes; 61 | 62 | if(ThisTask == 0) {printf("Allocated %g MByte for particle data storage.\n", bytes_tot / (1024.0 * 1024.0));} 63 | } 64 | 65 | if(All.MaxPartGas > 0) 66 | { 67 | bytes_tot = 0; 68 | 69 | if(!(SphP = (struct gas_cell_data *) mymalloc("GasCellData_P", bytes = All.MaxPartGas * sizeof(struct gas_cell_data)))) 70 | { 71 | printf("failed to allocate memory for gas cell data storage structure (%g MB).\n", bytes / (1024.0 * 1024.0)); 72 | endrun(1); 73 | } 74 | bytes_tot += bytes; 75 | 76 | if(ThisTask == 0) {printf("Allocated %g MByte for storage of hydro data.\n", bytes_tot / (1024.0 * 1024.0));} 77 | 78 | #ifdef CHIMES 79 | if (!(ChimesGasVars = (struct gasVariables *) mymalloc("gasVars", bytes = All.MaxPartGas * sizeof(struct gasVariables)))) 80 | { 81 | printf("failed to allocate memory for 'ChimesGasVars' (%g MB).\n", bytes / (1024.0 * 1024.0)); 82 | endrun(1); 83 | } 84 | bytes_tot += bytes; 85 | 86 | if(ThisTask == 0) 87 | printf("Allocated %g MByte for storage of ChimesGasVars data.\n", bytes_tot / (1024.0 * 1024.0)); 88 | #endif 89 | } 90 | 91 | 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /tags.h: -------------------------------------------------------------------------------- 1 | /* defines tag names for labeling MPI messages to prevent collisions */ 2 | 3 | /* 4 | * This file was originally part of the GADGET3 code developed by 5 | * Volker Springel. The code has been modified 6 | * in part by Phil Hopkins (phopkins@caltech.edu) for GIZMO (new variables, 7 | * and different naming conventions for some old variables) 8 | */ 9 | 10 | 11 | #define TAG_N 10 /*!< Various tags used for labeling MPI messages */ 12 | #define TAG_HEADER 11 13 | #define TAG_PDATA 12 14 | #define TAG_GASDATA 13 15 | #define TAG_KEY 14 16 | #define TAG_DMOM 15 17 | #define TAG_NODELEN 16 18 | #define TAG_HMAX 17 19 | #define TAG_GRAV_A 18 20 | #define TAG_GRAV_B 19 21 | #define TAG_DIRECT_A 20 22 | #define TAG_DIRECT_B 21 23 | #define TAG_HYDRO_A 22 24 | #define TAG_HYDRO_B 23 25 | #define TAG_NFORTHISTASK 24 26 | #define TAG_PERIODIC_A 25 27 | #define TAG_PERIODIC_B 26 28 | #define TAG_PERIODIC_C 27 29 | #define TAG_PERIODIC_D 28 30 | #define TAG_NONPERIOD_A 29 31 | #define TAG_NONPERIOD_B 30 32 | #define TAG_NONPERIOD_C 31 33 | #define TAG_NONPERIOD_D 32 34 | #define TAG_POTENTIAL_A 33 35 | #define TAG_POTENTIAL_B 34 36 | #define TAG_DENS_A 35 37 | #define TAG_DENS_B 36 38 | #define TAG_LOCALN 37 39 | 40 | #define TAG_BH_A 38 41 | #define TAG_BH_B 39 42 | #define TAG_BH_C 40 43 | #define TAG_BH_D 41 44 | #define TAG_BH_E 42 45 | #define TAG_BH_F 43 46 | #define TAG_BH_G 44 47 | #define TAG_BH_H 45 48 | #define TAG_BH_I 46 49 | 50 | #define TAG_FOF_A 47 51 | #define TAG_FOF_B 48 52 | #define TAG_FOF_C 49 53 | #define TAG_FOF_D 50 54 | #define TAG_FOF_E 51 55 | #define TAG_FOF_F 52 56 | #define TAG_FOF_G 53 57 | #define TAG_FOF_H 54 58 | #define TAG_FOF_I 55 59 | #define TAG_FOF_J 56 60 | 61 | #define TAG_SWAP 57 62 | #define TAG_PM_FOLD 58 63 | 64 | #define TAG_AGS_DENS_A 59 65 | #define TAG_AGS_DENS_B 60 66 | 67 | #define TAG_GRDENS_A 61 68 | #define TAG_GRDENS_B 62 69 | 70 | #define TAG_DMDENS_A 63 71 | #define TAG_DMDENS_B 64 72 | 73 | #define TAG_PSRT_A 65 74 | #define TAG_PDATA_GAS 66 75 | #define TAG_KEY_GAS 67 76 | 77 | #define TAG_RT_A 72 78 | #define TAG_RT_B 73 79 | #define TAG_RT_C 74 80 | #define TAG_RT_D 75 81 | 82 | #define TAG_FBLOOP_1A 80 83 | #define TAG_FBLOOP_1B 81 84 | #define TAG_FBLOOP_2A 82 85 | #define TAG_FBLOOP_2B 83 86 | #define TAG_FBLOOP_3A 84 87 | #define TAG_FBLOOP_3B 85 88 | #define TAG_FBLOOP_4A 86 89 | #define TAG_FBLOOP_4B 87 90 | #define TAG_FBLOOP_5A 88 91 | #define TAG_FBLOOP_5B 89 92 | 93 | #define TAG_GRADLOOP_A 90 94 | #define TAG_GRADLOOP_B 91 95 | #define TAG_GRADLOOP_C 92 96 | 97 | #define TAG_PDATA_STARS 93 98 | #define TAG_KEY_STARS 94 99 | #define TAG_PDATA_BHS 95 100 | #define TAG_KEY_BHS 96 101 | #define TAG_BHDATA 97 102 | 103 | #define TAG_DYNSMAGLOOP_A 98 104 | #define TAG_DYNSMAGLOOP_B 99 105 | #define TAG_DYNSMAGLOOP_C 100 106 | 107 | #ifdef CHIMES 108 | #define TAG_CHIMESDATA 101 109 | #define TAG_ABUNDATA 102 110 | #endif 111 | 112 | #define TAG_MPI_GENERIC_COM_BUFFER_A 103 113 | #define TAG_MPI_GENERIC_COM_BUFFER_B 104 114 | 115 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Welcome! 2 | 3 | This is **GIZMO**: a flexible, multi-method multi-physics code. The code solves the fluid using Lagrangian mesh-free finite-volume Godunov methods (or SPH, or fixed-grid Eulerian methods), and self-gravity with fast hybrid PM-Tree methods and fully-adaptive resolution. Other physics include: magnetic fields (ideal and non-ideal), radiation-hydrodynamics, anisotropic conduction and viscosity, sub-grid turbulent diffusion, radiative cooling, cosmological integration, sink particles, dust-gas mixtures, cosmic rays, degenerate equations of state, galaxy/star/black hole formation and feedback, self-interacting and scalar-field dark matter, on-the-fly structure finding, and more. 4 | 5 | See the [User Guide](http://www.tapir.caltech.edu/~phopkins/Site/GIZMO_files/gizmo_documentation.html) for an up-to-date physics list, or [the original code website](http://www.tapir.caltech.edu/~phopkins/Site/GIZMO.html) for examples demonstrating the advantages of the new methods, different types of **GIZMO** simulations, and its massively-parallel scalings. 6 | 7 | The code is descended from P-SPH, itself descended from GADGET-3 (so a huge debt owes to the work of Volker Springel), and many of the GADGET conventions remain (for compatibility with GADGET outputs and codes). See the source code for appropriate attribution of the code elements. 8 | 9 | Both the [public code](https://github.com/pfhopkins/gizmo-public) ([alternative repo here](https://bitbucket.org/phopkins/gizmo-public)) and the [development (private) code](https://bitbucket.org/phopkins/gizmo) are hosted on git version-controlled repositories. For code issues, feature requests, or bugs, please post Discussion and Issues interface at the [public code github repository](https://github.com/pfhopkins/gizmo-public). The previous GIZMO Google Group had to be de-activated owing to security and spam concerns. 10 | 11 | Basic Rules: 12 | 13 | 1. The reference for code methods, setup, use and citation policy is the User Guide, available as `gizmo_documentation.html` in the `scripts` folder as part of this repository, or via download [here](http://www.tapir.caltech.edu/~phopkins/Site/GIZMO_files/gizmo_documentation.html). Read it! The code is extensively documented. Important things you need to know before running are there. Most questions are already answered. 14 | 15 | 2. Access to the development (private) code does **not** imply permission to use any modules identified as proprietary either in the User Guide or `Template_Config.sh` file (or elsewhere). The development code can only be used or distributed with explicit permission from the code authors. Many of the non-public modules are proprietary and developed by students for on-going research; it is not acceptable to use or share these routines without first obtaining the explicit permission of both the lead code author and author(s) of the relevant routines. If in doubt, ask. Anyone violating these terms will have code access immediately revoked. 16 | 17 | The public version of the code is free software, distributed under the [GNU General Public License](http://www.gnu.org/copyleft/gpl.html). You may freely distribute and copy the public code. You may also modify it as you wish, and distribute these modified versions as long as you indicate prominently any changes you made in the original code, and as long as you leave the copyright notices, and the no-warranty notice intact. Please read the General Public License for more details. Note that the authors retain their copyright on the code. 18 | 19 | If you use any version of the code, please reference the code paper, [Hopkins 2015, MNRAS, 450, 53](http://arxiv.org/abs/1409.7395); you should also reference Volker Springel's GADGET paper (Springel, 2005, MNRAS, 364, 1105) for the domain decomposition and N-body algorithms. Appropriate citations for specific modules are described in the Users Guide. 20 | -------------------------------------------------------------------------------- /system/vector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was originally part of the GADGET3 code by Volker Springel. 3 | */ 4 | 5 | #ifndef _VECTOR_H_ 6 | #define _VECTOR_H_ 7 | 8 | #if defined(VECTOR_SSE) 9 | #include "vector_sse2.h" 10 | #elif defined(VECTOR_AVX) 11 | #include "vector_avx.h" 12 | #elif defined(VECTOR_VSX) 13 | #include "vector_vsx.h" 14 | #elif defined(VECTOR_QPX) 15 | #include "vector_qpx.h" 16 | #else 17 | 18 | // generic scalar code 19 | 20 | #ifdef DOUBLEPRECISION 21 | 22 | typedef ALIGN(32) union { 23 | unsigned long long i[4]; 24 | double d[4]; 25 | } t_vector; 26 | 27 | #else 28 | 29 | typedef ALIGN(16) union { 30 | unsigned int i[4]; 31 | float d[4]; 32 | } t_vector; 33 | 34 | #endif 35 | 36 | // read the first 3 components of a vector, 4th component is undefined 37 | static inline void LOAD_VECTOR3(MyFloat * src,t_vector * v) 38 | { 39 | v->d[0] = src[0]; 40 | v->d[1] = src[1]; 41 | v->d[2] = src[2]; 42 | } 43 | 44 | // read all 4 components of a vector 45 | static inline void LOAD_VECTOR4(MyFloat * src,t_vector * v) 46 | { 47 | v->d[0] = src[0]; 48 | v->d[1] = src[1]; 49 | v->d[2] = src[2]; 50 | v->d[3] = src[3]; 51 | } 52 | 53 | // stores only the first 3 components of a vector (avoid, because it's slow) 54 | static inline void STORE_VECTOR3(MyFloat * dst,t_vector * v) 55 | { 56 | dst[0] = v->d[0]; 57 | dst[1] = v->d[1]; 58 | dst[2] = v->d[2]; 59 | } 60 | 61 | // stores all 4 components of a vector (fast) 62 | static inline void STORE_VECTOR4(MyFloat * dst,t_vector * v) 63 | { 64 | dst[0] = v->d[0]; 65 | dst[1] = v->d[1]; 66 | dst[2] = v->d[2]; 67 | dst[3] = v->d[3]; 68 | } 69 | 70 | // initializes first 3 components of a vector (4th component becomes undefined) 71 | static inline void SET_VECTOR3(MyFloat a,t_vector * v) 72 | { 73 | v->d[0] = a; 74 | v->d[1] = a; 75 | v->d[2] = a; 76 | } 77 | 78 | // initializes all 4 components of a vector with the same scalar value 79 | static inline void SET_VECTOR4(MyFloat a,t_vector * v) 80 | { 81 | v->d[0] = a; 82 | v->d[1] = a; 83 | v->d[2] = a; 84 | v->d[3] = a; 85 | } 86 | 87 | // initializes first 3 components of a vector (4th component becomes undefined) 88 | static inline void INIT_VECTOR3(MyFloat a0,MyFloat a1,MyFloat a2,t_vector * v) 89 | { 90 | v->d[0] = a0; 91 | v->d[1] = a1; 92 | v->d[2] = a2; 93 | } 94 | 95 | // adds the first 3 components of 2 vectors (4th component undefined) 96 | static inline void ADD_VECTOR3(t_vector * a,t_vector * b,t_vector * result) 97 | { 98 | result->d[0] = a->d[0]+b->d[0]; 99 | result->d[1] = a->d[1]+b->d[1]; 100 | result->d[2] = a->d[2]+b->d[2]; 101 | } 102 | 103 | // multiplies the first 3 components of 2 vectors (4th component undefined) 104 | static inline void MUL_VECTOR3(t_vector * a,t_vector * b,t_vector * result) 105 | { 106 | result->d[0] = a->d[0] * b->d[0]; 107 | result->d[1] = a->d[1] * b->d[1]; 108 | result->d[2] = a->d[2] * b->d[2]; 109 | } 110 | 111 | // multiplies the first 3 components of 2 vectors (4th component undefined) 112 | static inline void SCALE_VECTOR3(MyFloat a,t_vector * b,t_vector * v) 113 | { 114 | v->d[0] = a * b->d[0]; 115 | v->d[1] = a * b->d[1]; 116 | v->d[2] = a * b->d[2]; 117 | } 118 | 119 | // returns a value >0, if a(i) < b(i) for any i=1..3 120 | static inline int ANY_COMP_LT_VECTOR3(t_vector * a,t_vector * b,int mask) 121 | { 122 | return (a->d[0] < b->d[0]) | (a->d[1] < b->d[1]) | (a->d[2] < b->d[2]); 123 | } 124 | 125 | // returns 0, if a(i) < b(i) for any i=1..3 126 | static inline int ALL_COMP_LT_VECTOR3(t_vector * a,t_vector * b,int mask) 127 | { 128 | return (a->d[0] < b->d[0]) & (a->d[1] < b->d[1]) & (a->d[2] < b->d[2]); 129 | } 130 | 131 | // returns the L2 norm of the first 3 components of a vector 132 | static inline MyDouble L2NORM_VECTOR3(t_vector * v) 133 | { 134 | return v->d[0] * v->d[0] + v->d[1] * v->d[1] + v->d[2] * v->d[2]; 135 | } 136 | 137 | #endif 138 | 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "allvars.h" 12 | #include "proto.h" 13 | 14 | 15 | 16 | /*! \file main.c 17 | * \brief start of the program 18 | */ 19 | /* 20 | * This file was originally part of the GADGET3 code developed by 21 | * Volker Springel. The code has been modified 22 | * in part by Phil Hopkins (phopkins@caltech.edu) for GIZMO. 23 | */ 24 | 25 | /*! 26 | * This function initializes the MPI communication packages, and sets 27 | * cpu-time counters to 0. Then begrun() is called, which sets up 28 | * the simulation either from IC's or from restart files. Finally, 29 | * run() is started, the main simulation loop, which iterates over 30 | * the timesteps. 31 | */ 32 | int main(int argc, char **argv) 33 | { 34 | int i; 35 | 36 | #ifdef IMPOSE_PINNING 37 | get_core_set(); 38 | #endif 39 | 40 | MPI_Init(&argc, &argv); 41 | MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask); 42 | MPI_Comm_size(MPI_COMM_WORLD, &NTask); 43 | 44 | #ifdef IMPOSE_PINNING 45 | pin_to_core_set(); 46 | #endif 47 | 48 | double safe_memorypertask = mpi_report_comittable_memory(0,1); 49 | MPI_Barrier(MPI_COMM_WORLD); 50 | 51 | /* initialize OpenMP thread pool and bind (implicitly though OpenMP runtime) */ 52 | if(ThisTask == 0) 53 | { 54 | char *username = getenv("USER"); 55 | char hostname[201]; hostname[200] = '\0'; 56 | int have_hn = gethostname(hostname,200); 57 | time_t rawtime; 58 | struct tm * timeinfo; 59 | time ( &rawtime ); 60 | timeinfo = localtime ( &rawtime ); 61 | 62 | printf("\nSystem time: %s", asctime(timeinfo) ); 63 | printf("This is GIZMO, version %d, running on %s as %s.\n", 64 | GIZMO_VERSION, 65 | have_hn == 0 ? hostname : "?", 66 | username ? username : "?" 67 | ); 68 | #ifdef BUILDINFO 69 | printf(BUILDINFO", " __DATE__ " " __TIME__ "\n"); 70 | #endif 71 | printf("\nCode was compiled with settings:\n\n"); 72 | output_compile_time_options(); 73 | } 74 | 75 | #ifdef _OPENMP 76 | #pragma omp parallel 77 | { 78 | #pragma omp master 79 | { 80 | maxThreads = omp_get_num_threads(); 81 | } 82 | } 83 | #elif defined(PTHREADS_NUM_THREADS) 84 | if(ThisTask == 0) {printf("Using %d POSIX threads\n", maxThreads);} 85 | #endif 86 | 87 | for(PTask = 0; NTask > (1 << PTask); PTask++); 88 | 89 | if(argc < 2) 90 | { 91 | if(ThisTask == 0) 92 | { 93 | printf("Parameters are missing.\n"); 94 | printf("Call with [] []\n"); 95 | printf("\n"); 96 | printf(" RestartFlag Action\n"); 97 | printf(" 0 Read initial conditions and start simulation\n"); 98 | printf(" 1 Read restart files and resume simulation\n"); 99 | printf(" 2 Restart from specified snapshot dump and continue simulation\n"); 100 | printf(" 3 Run FOF and optionally SUBFIND if enabled\n"); 101 | printf(" 4 Convert snapshot file to different format\n"); 102 | printf(" 5 Calculate power spectrum and two-point function\n"); 103 | printf(" 6 Calculate velocity power spectrum for the gas particles\n"); 104 | printf("\n"); 105 | } 106 | endrun(0); 107 | } 108 | 109 | strcpy(ParameterFile, argv[1]); 110 | 111 | if(argc >= 3) 112 | RestartFlag = atoi(argv[2]); 113 | else 114 | RestartFlag = 0; 115 | 116 | if(argc >= 4) 117 | RestartSnapNum = atoi(argv[3]); 118 | else 119 | RestartSnapNum = -1; 120 | 121 | /* initialize CPU-time/Wallclock-time measurement */ 122 | for(i = 0; i < CPU_PARTS; i++) {All.CPU_Sum[i] = CPU_Step[i] = 0;} 123 | 124 | CPUThisRun = 0; 125 | WallclockTime = my_second(); 126 | 127 | begrun(); /* set-up run */ 128 | 129 | run(); /* main simulation loop */ 130 | 131 | MPI_Finalize(); /* clean up & finalize MPI */ 132 | 133 | return 0; 134 | } 135 | -------------------------------------------------------------------------------- /system/ngb_codeblock_checknode.h: -------------------------------------------------------------------------------- 1 | #ifdef NGB_ONLY_OPEN_NODES_CONTAINING_GAS /* additional skip criterion */ 2 | if(All.Time > All.TimeBegin) {if(hmax <= 0) {continue;}} 3 | #endif 4 | 5 | #if (BOX_SHEARING > 1) 6 | /* in this case, we have a shearing box with the '1' coordinate being phi, so there is a periodic extra wrap; 7 | this requires some extra care, because we can have the situation where the -node- center is wrapped, but 8 | the actual particle[s] of interest are not wrapped */ 9 | 10 | // start with the 'normal' periodic components: always pays to check these first because next is more expensive // 11 | // (since there is no extra wrapping in these directions, the normal validation criteria apply) 12 | MyDouble dx0 = current->center[0]-searchcenter[0]; 13 | dx = NGB_PERIODIC_BOX_LONG_X(dx0,current->center[1]-searchcenter[1],current->center[2]-searchcenter[2],-1); 14 | if(dx > dist) continue; 15 | dz = NGB_PERIODIC_BOX_LONG_Z(dx0,current->center[1]-searchcenter[1],current->center[2]-searchcenter[2],-1); 16 | if(dz > dist) continue; 17 | // ok we've made it this far, now we need to test the y-axis wrapping // 18 | MyDouble dx_abs = fabs(dx0); 19 | MyDouble dx_node = 0.5 * current->len; 20 | if((dx_abs + dx_node < boxHalf_X) || (dx_abs - dx_node > boxHalf_X)) 21 | { 22 | // entire node box should be either wrapped or unwrapped: no ambiguity here, use the 'normal' distance evaluation 23 | dy = NGB_PERIODIC_BOX_LONG_Y(dx0,current->center[1]-searchcenter[1],current->center[2]-searchcenter[2],-1); 24 | if(dy > dist) continue; 25 | } else { 26 | // ok this is the messy case: some of the node is wrapped, some is unwrapped. consider both cases 27 | MyDouble dy0 = current->center[1]-searchcenter[1]; 28 | MyDouble dy_m = NGB_PERIODIC_BOX_LONG_Y(dx0-dx_node,dy0,current->center[2]-searchcenter[2],-1); // one edge of x-side of box 29 | MyDouble dy_p = NGB_PERIODIC_BOX_LONG_Y(dx0+dx_node,dy0,current->center[2]-searchcenter[2],-1); // other edge, should bracket possible wrapping 30 | dy = DMIN(dy_m, dy_p); // need to include all possible neighbors, which means using minimum of either distance 31 | if(dy > dist) continue; 32 | } 33 | // now test against the minimal sphere enclosing everything // 34 | dist += FACT1 * current->len; 35 | if(dx * dx + dy * dy + dz * dz > dist * dist) continue; 36 | 37 | #else 38 | /* this is the 'normal' operation mode */ 39 | 40 | #ifdef REDUCE_TREEWALK_BRANCHING 41 | // On the Power platform it is more efficient to compute all conditions first and then perform a single branch (on current Intel processors this is equally fast) 42 | MyDouble dist2 = dist + FACT1*current->len; 43 | dx = NGB_PERIODIC_BOX_LONG_X(current->center[0] - vcenter.d[0], current->center[1] - vcenter.d[1], current->center[2] - vcenter.d[2],-1); 44 | dy = NGB_PERIODIC_BOX_LONG_Y(current->center[0] - vcenter.d[0], current->center[1] - vcenter.d[1], current->center[2] - vcenter.d[2],-1); 45 | dz = NGB_PERIODIC_BOX_LONG_Z(current->center[0] - vcenter.d[0], current->center[1] - vcenter.d[1], current->center[2] - vcenter.d[2],-1); 46 | // now test against the minimal sphere enclosing everything 47 | if ((dx > dist) || (dy > dist) || (dz > dist) || (dx * dx + dy * dy + dz * dz > dist2 * dist2)) continue; // ok, we need to open the node 48 | #else 49 | // On older Intel and AMD processors it seems better to avoid the computations and branch early 50 | dx = NGB_PERIODIC_BOX_LONG_X(current->center[0]-searchcenter[0],current->center[1]-searchcenter[1],current->center[2]-searchcenter[2],-1); 51 | if(dx > dist) continue; 52 | dy = NGB_PERIODIC_BOX_LONG_Y(current->center[0]-searchcenter[0],current->center[1]-searchcenter[1],current->center[2]-searchcenter[2],-1); 53 | if(dy > dist) continue; 54 | dz = NGB_PERIODIC_BOX_LONG_Z(current->center[0]-searchcenter[0],current->center[1]-searchcenter[1],current->center[2]-searchcenter[2],-1); 55 | if(dz > dist) continue; 56 | // now test against the minimal sphere enclosing everything // 57 | dist += FACT1 * current->len; 58 | if(dx * dx + dy * dy + dz * dz > dist * dist) continue; 59 | #endif 60 | #endif 61 | -------------------------------------------------------------------------------- /scripts/visit/GIZMOCommonPluginInfo.C: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * 3 | * Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC 4 | * Produced at the Lawrence Livermore National Laboratory 5 | * LLNL-CODE-442911 6 | * All rights reserved. 7 | * 8 | * This file is part of VisIt. For details, see https://visit.llnl.gov/. The 9 | * full copyright notice is contained in the file COPYRIGHT located at the root 10 | * of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * - Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the disclaimer below. 17 | * - Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the disclaimer (as noted below) in the 19 | * documentation and/or other materials provided with the distribution. 20 | * - Neither the name of the LLNS/LLNL nor the names of its contributors may 21 | * be used to endorse or promote products derived from this software without 22 | * specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | * ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, 28 | * LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY 29 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 35 | * DAMAGE. 36 | * 37 | *****************************************************************************/ 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | // **************************************************************************** 45 | // Method: GIZMOCommonPluginInfo::GetDatabaseType 46 | // 47 | // Purpose: 48 | // Returns the type of a GIZMO database. 49 | // 50 | // Programmer: generated by xml2info 51 | // Creation: omitted 52 | // 53 | // **************************************************************************** 54 | DatabaseType 55 | GIZMOCommonPluginInfo::GetDatabaseType() 56 | { 57 | return DB_TYPE_STSD; 58 | } 59 | 60 | // **************************************************************************** 61 | // Method: GIZMOCommonPluginInfo::SetupDatabase 62 | // 63 | // Purpose: 64 | // Sets up a GIZMO database. 65 | // 66 | // Arguments: 67 | // list A list of file names. 68 | // nList The number of timesteps in list. 69 | // nBlocks The number of blocks in the list. 70 | // 71 | // Returns: A GIZMO database from list. 72 | // 73 | // Programmer: generated by xml2info 74 | // Creation: omitted 75 | // 76 | // **************************************************************************** 77 | avtDatabase * 78 | GIZMOCommonPluginInfo::SetupDatabase(const char *const *list, 79 | int nList, int nBlock) 80 | { 81 | integertime nTimestep = nList / nBlock; 82 | avtSTSDFileFormat ***ffl = new avtSTSDFileFormat**[nTimestep]; 83 | for (integertime i = 0 ; i < nTimestep ; i++) 84 | { 85 | ffl[i] = new avtSTSDFileFormat*[nBlock]; 86 | for (int j = 0 ; j < nBlock ; j++) 87 | { 88 | ffl[i][j] = new avtGIZMOFileFormat(list[i*nBlock + j]); 89 | } 90 | } 91 | avtSTSDFileFormatInterface *inter 92 | = new avtSTSDFileFormatInterface(ffl, nTimestep, nBlock); 93 | return new avtGenericDatabase(inter); 94 | } 95 | -------------------------------------------------------------------------------- /system/ngb_codeblock_after_condition_unthreaded.h: -------------------------------------------------------------------------------- 1 | if(P[p].Ti_current != ti_Current) 2 | drift_particle(p, ti_Current); 3 | 4 | #ifndef REDUCE_TREEWALK_BRANCHING 5 | #if (SEARCHBOTHWAYS==1) 6 | dist = DMAX(PPP[p].Hsml, hsml); 7 | #else 8 | dist = hsml; 9 | #endif 10 | dx = NGB_PERIODIC_BOX_LONG_X(P[p].Pos[0] - searchcenter[0], P[p].Pos[1] - searchcenter[1], P[p].Pos[2] - searchcenter[2],-1); 11 | if(dx > dist) continue; 12 | dy = NGB_PERIODIC_BOX_LONG_Y(P[p].Pos[0] - searchcenter[0], P[p].Pos[1] - searchcenter[1], P[p].Pos[2] - searchcenter[2],-1); 13 | if(dy > dist) continue; 14 | dz = NGB_PERIODIC_BOX_LONG_Z(P[p].Pos[0] - searchcenter[0], P[p].Pos[1] - searchcenter[1], P[p].Pos[2] - searchcenter[2],-1); 15 | if(dz > dist) continue; 16 | if(dx * dx + dy * dy + dz * dz > dist * dist) continue; 17 | #endif 18 | 19 | Ngblist[numngb++] = p; 20 | } 21 | else 22 | { 23 | if(no >= maxPart + maxNodes) /* pseudo particle */ 24 | { 25 | if(mode == 1) {endrun(123129);} 26 | if(target >= 0) /* if no target is given, export will not occur */ 27 | { 28 | if(Exportflag[task = DomainTask[no - (maxPart + maxNodes)]] != target) 29 | { 30 | Exportflag[task] = target; 31 | Exportnodecount[task] = NODELISTLENGTH; 32 | } 33 | 34 | if(Exportnodecount[task] == NODELISTLENGTH) 35 | { 36 | if(*nexport >= bunchSize) 37 | { 38 | *nexport = nexport_save; 39 | if(nexport_save == 0) {endrun(13004);} /* in this case, the buffer is too small to process even a single particle */ 40 | for(task = 0; task < NTask; task++) {nsend_local[task] = 0;} 41 | for(no = 0; no < nexport_save; no++) {nsend_local[DataIndexTable[no].Task]++;} 42 | return -1; /* buffer has filled -- important that only this and other buffer-full conditions return the negative condition for the routine */ 43 | } 44 | Exportnodecount[task] = 0; 45 | Exportindex[task] = *nexport; 46 | DataIndexTable[*nexport].Task = task; 47 | DataIndexTable[*nexport].Index = target; 48 | DataIndexTable[*nexport].IndexGet = *nexport; 49 | *nexport = *nexport + 1; 50 | nsend_local[task]++; 51 | } 52 | 53 | DataNodeList[Exportindex[task]].NodeList[Exportnodecount[task]++] = DomainNodeIndex[no - (maxPart + maxNodes)]; 54 | if(Exportnodecount[task] < NODELISTLENGTH) {DataNodeList[Exportindex[task]].NodeList[Exportnodecount[task]] = -1;} 55 | } 56 | no = Nextnode[no - maxNodes]; 57 | continue; 58 | } 59 | 60 | current = &Nodes[no]; 61 | 62 | if(mode == 1) 63 | { 64 | if(current->u.d.bitflags & (1 << BITFLAG_TOPLEVEL)) /* we reached a top-level node again, which means that we are done with the branch */ 65 | { 66 | *startnode = -1; 67 | #ifndef REDUCE_TREEWALK_BRANCHING 68 | return numngb; 69 | #else 70 | return ngb_filter_variables(numngb, Ngblist, &vcenter, &box, &hbox, hsml, SEARCHBOTHWAYS); 71 | #endif 72 | } 73 | } 74 | 75 | if(current->Ti_current != ti_Current) {force_drift_node(no, ti_Current);} 76 | 77 | if(!(current->u.d.bitflags & (1 << BITFLAG_MULTIPLEPARTICLES))) 78 | { 79 | if(current->u.d.mass) /* open cell */ 80 | { 81 | no = current->u.d.nextnode; 82 | continue; 83 | } 84 | } 85 | 86 | double hmax = Extnodes[no].hmax; 87 | #if (SEARCHBOTHWAYS==1) 88 | dist = DMAX(hmax, hsml) + 0.5 * current->len; 89 | #else 90 | dist = hsml + 0.5 * current->len; 91 | #endif 92 | no = current->u.d.sibling; // in case the node can be discarded // 93 | #include "ngb_codeblock_checknode.h" 94 | no = current->u.d.nextnode; // ok, we need to open the node // 95 | } 96 | } 97 | 98 | *startnode = -1; 99 | #ifndef REDUCE_TREEWALK_BRANCHING 100 | return numngb; 101 | #else 102 | return ngb_filter_variables(numngb, Ngblist, &vcenter, &box, &hbox, hsml, SEARCHBOTHWAYS); 103 | #endif 104 | 105 | -------------------------------------------------------------------------------- /system/parallel_sort_special.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "../allvars.h" 13 | #include "../proto.h" 14 | 15 | 16 | /* 17 | * This file was originally part of the GADGET3 code by Volker Springel. 18 | */ 19 | 20 | #if defined(IO_SUBFIND_READFOF_FROMIC) 21 | 22 | static struct aux_data 23 | { 24 | MyIDType ID; 25 | MyIDType GrNr; 26 | int OriginTask; 27 | int OriginIndex; 28 | int FinalTask; 29 | } 30 | *Aux; 31 | 32 | 33 | static int compare_Aux_GrNr_ID(const void *a, const void *b) 34 | { 35 | if(((struct aux_data *) a)->GrNr < (((struct aux_data *) b)->GrNr)) {return -1;} 36 | if(((struct aux_data *) a)->GrNr > (((struct aux_data *) b)->GrNr)) {return +1;} 37 | if(((struct aux_data *) a)->ID < (((struct aux_data *) b)->ID)) {return -1;} 38 | if(((struct aux_data *) a)->ID > (((struct aux_data *) b)->ID)) {return +1;} 39 | return 0; 40 | } 41 | 42 | static int compare_Aux_OriginTask_OriginIndex(const void *a, const void *b) 43 | { 44 | if(((struct aux_data *) a)->OriginTask < (((struct aux_data *) b)->OriginTask)) {return -1;} 45 | if(((struct aux_data *) a)->OriginTask > (((struct aux_data *) b)->OriginTask)) {return +1;} 46 | if(((struct aux_data *) a)->OriginIndex < (((struct aux_data *) b)->OriginIndex)) {return -1;} 47 | if(((struct aux_data *) a)->OriginIndex > (((struct aux_data *) b)->OriginIndex)) {return +1;} 48 | return 0; 49 | } 50 | 51 | 52 | 53 | /* The following function should do the same thing as a call of 54 | 55 | parallel_sort(P, NumPart, sizeof(struct particle_data), io_compare_P_GrNr_ID) 56 | 57 | but reducing the peak memory consumption through use of an auxiliary array. 58 | 59 | */ 60 | 61 | 62 | void parallel_sort_special_P_GrNr_ID(void) 63 | { 64 | int i, j, Nimport, ngrp, sendTask, recvTask; 65 | 66 | Aux = mymalloc("Aux", NumPart * sizeof(struct aux_data)); 67 | 68 | for(i = 0; i < NumPart; i++) 69 | { 70 | Aux[i].GrNr = P[i].GrNr; 71 | Aux[i].ID = P[i].ID; 72 | Aux[i].OriginTask = ThisTask; 73 | Aux[i].OriginIndex = i; 74 | } 75 | 76 | parallel_sort(Aux, NumPart, sizeof(struct aux_data), compare_Aux_GrNr_ID); 77 | 78 | for(i = 0; i < NumPart; i++) 79 | Aux[i].FinalTask = ThisTask; 80 | 81 | parallel_sort(Aux, NumPart, sizeof(struct aux_data), compare_Aux_OriginTask_OriginIndex); 82 | 83 | 84 | for(i = 0; i < NTask; i++) 85 | Send_count[i] = 0; 86 | 87 | for(i = 0; i < NumPart; i++) 88 | Send_count[Aux[i].FinalTask]++; 89 | 90 | 91 | MPI_Alltoall(Send_count, 1, MPI_INT, Recv_count, 1, MPI_INT, MPI_COMM_WORLD); 92 | 93 | for(j = 0, Nimport = 0, Recv_offset[0] = 0, Send_offset[0] = 0; j < NTask; j++) 94 | { 95 | Nimport += Recv_count[j]; 96 | 97 | if(j > 0) 98 | { 99 | Send_offset[j] = Send_offset[j - 1] + Send_count[j - 1]; 100 | Recv_offset[j] = Recv_offset[j - 1] + Recv_count[j - 1]; 101 | } 102 | } 103 | 104 | if(Nimport != NumPart) 105 | terminate("Nimport != NumPart"); 106 | 107 | 108 | struct particle_data *pbuf; 109 | 110 | pbuf = mymalloc("pbuf", NumPart * sizeof(struct particle_data)); 111 | 112 | for(i = 0; i < NTask; i++) 113 | Send_count[i] = 0; 114 | 115 | for(i = 0; i < NumPart; i++) 116 | pbuf[Send_offset[Aux[i].FinalTask] + Send_count[Aux[i].FinalTask]++] = P[i]; 117 | 118 | 119 | memcpy(&P[Recv_offset[ThisTask]], &pbuf[Send_offset[ThisTask]], 120 | Send_count[ThisTask] * sizeof(struct particle_data)); 121 | 122 | for(ngrp = 1; ngrp < (1 << PTask); ngrp++) 123 | { 124 | sendTask = ThisTask; 125 | recvTask = ThisTask ^ ngrp; 126 | 127 | if(recvTask < NTask) 128 | { 129 | if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) 130 | { 131 | /* get the particles */ 132 | MPI_Sendrecv(&pbuf[Send_offset[recvTask]], 133 | Send_count[recvTask] * sizeof(struct particle_data), MPI_BYTE, 134 | recvTask, TAG_PSRT_A, 135 | &P[Recv_offset[recvTask]], 136 | Recv_count[recvTask] * sizeof(struct particle_data), MPI_BYTE, 137 | recvTask, TAG_PSRT_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); 138 | } 139 | } 140 | } 141 | 142 | myfree(pbuf); 143 | 144 | 145 | qsort(P, NumPart, sizeof(struct particle_data), io_compare_P_GrNr_ID); 146 | 147 | 148 | myfree(Aux); 149 | } 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /scripts/visit/GIZMOPluginInfo.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * 3 | * Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC 4 | * Produced at the Lawrence Livermore National Laboratory 5 | * LLNL-CODE-442911 6 | * All rights reserved. 7 | * 8 | * This file is part of VisIt. For details, see https://visit.llnl.gov/. The 9 | * full copyright notice is contained in the file COPYRIGHT located at the root 10 | * of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * - Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the disclaimer below. 17 | * - Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the disclaimer (as noted below) in the 19 | * documentation and/or other materials provided with the distribution. 20 | * - Neither the name of the LLNS/LLNL nor the names of its contributors may 21 | * be used to endorse or promote products derived from this software without 22 | * specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | * ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, 28 | * LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY 29 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 35 | * DAMAGE. 36 | * 37 | *****************************************************************************/ 38 | 39 | // **************************************************************************** 40 | // GIZMOPluginInfo.h 41 | // **************************************************************************** 42 | 43 | #ifndef GIZMO_PLUGIN_INFO_H 44 | #define GIZMO_PLUGIN_INFO_H 45 | #include 46 | #include 47 | 48 | class avtDatabase; 49 | class avtDatabaseWriter; 50 | 51 | // **************************************************************************** 52 | // Class: GIZMODatabasePluginInfo 53 | // 54 | // Purpose: 55 | // Classes that provide all the information about the GIZMO plugin. 56 | // Portions are separated into pieces relevant to the appropriate 57 | // components of VisIt. 58 | // 59 | // Programmer: generated by xml2info 60 | // Creation: omitted 61 | // 62 | // Modifications: 63 | // 64 | // **************************************************************************** 65 | 66 | class GIZMOGeneralPluginInfo : public virtual GeneralDatabasePluginInfo 67 | { 68 | public: 69 | virtual const char *GetName() const; 70 | virtual const char *GetVersion() const; 71 | virtual const char *GetID() const; 72 | virtual bool EnabledByDefault() const; 73 | virtual bool HasWriter() const; 74 | virtual std::vector GetDefaultFilePatterns() const; 75 | virtual bool AreDefaultFilePatternsStrict() const; 76 | virtual bool OpensWholeDirectory() const; 77 | }; 78 | 79 | class GIZMOCommonPluginInfo : public virtual CommonDatabasePluginInfo, public virtual GIZMOGeneralPluginInfo 80 | { 81 | public: 82 | virtual DatabaseType GetDatabaseType(); 83 | virtual avtDatabase *SetupDatabase(const char * const *list, 84 | int nList, int nBlock); 85 | }; 86 | 87 | class GIZMOMDServerPluginInfo : public virtual MDServerDatabasePluginInfo, public virtual GIZMOCommonPluginInfo 88 | { 89 | public: 90 | // this makes compilers happy... remove if we ever have functions here 91 | virtual void dummy(); 92 | }; 93 | 94 | class GIZMOEnginePluginInfo : public virtual EngineDatabasePluginInfo, public virtual GIZMOCommonPluginInfo 95 | { 96 | public: 97 | virtual avtDatabaseWriter *GetWriter(void); 98 | }; 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /eos/helmholtz/helm_table_storage.dek: -------------------------------------------------------------------------------- 1 | ! sizes of the tables 2 | ! normal table, big table, bigger table, denser bigger table 3 | 4 | integer imax,jmax 5 | 6 | ! original 7 | ! parameter (imax = 211, jmax = 71) 8 | 9 | ! standard 10 | parameter (imax = 271, jmax = 101) 11 | 12 | ! twice as dense 13 | ! parameter (imax = 541, jmax = 201) 14 | 15 | ! half as dense 16 | ! parameter (imax = 136, jmax = 51) 17 | 18 | 19 | 20 | ! for the electrons 21 | ! density and temperature 22 | double precision tlo,thi,tstp,tstpi,dlo,dhi,dstp,dstpi 23 | double precision d(imax),t(jmax) 24 | common /dttabc1/ d,t, & 25 | tlo,thi,tstp,tstpi,dlo,dhi,dstp,dstpi 26 | 27 | ! for the helmholtz free energy tables 28 | double precision f(imax,jmax),fd(imax,jmax), & 29 | ft(imax,jmax),fdd(imax,jmax),ftt(imax,jmax), & 30 | fdt(imax,jmax),fddt(imax,jmax),fdtt(imax,jmax), & 31 | fddtt(imax,jmax) 32 | 33 | common /frtabc1/ f,fd, & 34 | ft,fdd,ftt, & 35 | fdt,fddt,fdtt, & 36 | fddtt 37 | 38 | ! for the pressure derivative with density tables 39 | double precision dpdf(imax,jmax),dpdfd(imax,jmax), & 40 | dpdft(imax,jmax),dpdfdt(imax,jmax) 41 | 42 | common /dpdtab1/ dpdf,dpdfd, & 43 | dpdft,dpdfdt 44 | 45 | 46 | ! for chemical potential tables 47 | double precision ef(imax,jmax),efd(imax,jmax), & 48 | eft(imax,jmax),efdt(imax,jmax) 49 | 50 | common /eftabc1/ ef,efd, & 51 | eft,efdt 52 | 53 | 54 | ! for the number density tables 55 | double precision xf(imax,jmax),xfd(imax,jmax), & 56 | xft(imax,jmax),xfdt(imax,jmax) 57 | 58 | common /xftabc1/ xf,xfd, & 59 | xft,xfdt 60 | 61 | 62 | ! for storing the differences 63 | double precision dt_sav(jmax),dt2_sav(jmax), & 64 | dti_sav(jmax),dt2i_sav(jmax),dt3i_sav(jmax), & 65 | dd_sav(imax),dd2_sav(imax), & 66 | ddi_sav(imax),dd2i_sav(imax),dd3i_sav(imax) 67 | 68 | common /diftabc1/dt_sav,dt2_sav, & 69 | dti_sav,dt2i_sav,dt3i_sav, & 70 | dd_sav,dd2_sav, & 71 | ddi_sav,dd2i_sav,dd3i_sav 72 | 73 | 74 | 75 | 76 | ! for the ions 77 | ! density and temperature 78 | double precision tion_lo,tion_hi,tion_stp,tion_stpi, & 79 | dion_lo,dion_hi,dion_stp,dion_stpi 80 | double precision dion(imax),tion(jmax) 81 | common /dttabc2/ dion,tion, & 82 | tion_lo,tion_hi,tion_stp,tion_stpi, & 83 | dion_lo,dion_hi,dion_stp,dion_stpi 84 | 85 | ! for the helmholtz free energy tables 86 | double precision fion(imax,jmax),fiond(imax,jmax), & 87 | fiont(imax,jmax),fiondd(imax,jmax), & 88 | fiontt(imax,jmax),fiondt(imax,jmax), & 89 | fionddt(imax,jmax),fiondtt(imax,jmax), & 90 | fionddtt(imax,jmax) 91 | 92 | common /frtabc2/ fion,fiond, & 93 | fiont,fiondd,fiontt, & 94 | fiondt,fionddt,fiondtt, & 95 | fionddtt 96 | 97 | ! for the pressure derivative with density tables 98 | double precision dpiondf(imax,jmax),dpiondfd(imax,jmax), & 99 | dpiondft(imax,jmax),dpiondfdt(imax,jmax) 100 | 101 | common /dpdtab2/ dpiondf,dpiondfd, & 102 | dpiondft,dpiondfdt 103 | 104 | 105 | ! for chemical potential tables 106 | double precision efion(imax,jmax),efiond(imax,jmax), & 107 | efiont(imax,jmax),efiondt(imax,jmax) 108 | 109 | common /eftabc2/ efion,efiond, & 110 | efiont,efiondt 111 | 112 | 113 | ! for the number density tables 114 | double precision xfion(imax,jmax),xfiond(imax,jmax), & 115 | xfiont(imax,jmax),xfiondt(imax,jmax) 116 | 117 | common /xftabc2/ xfion,xfiond, & 118 | xfiont,xfiondt 119 | 120 | 121 | ! for storing the differences 122 | double precision dt_sav_ion(jmax),dt2_sav_ion(jmax), & 123 | dti_sav_ion(jmax),dt2i_sav_ion(jmax), & 124 | dt3i_sav_ion(jmax),dd_sav_ion(imax), & 125 | dd2_sav_ion(imax),ddi_sav_ion(imax), & 126 | dd2i_sav_ion(imax),dd3i_sav_ion(imax) 127 | 128 | common /diftabc2/dt_sav_ion,dt2_sav_ion, & 129 | dti_sav_ion,dt2i_sav_ion, & 130 | dt3i_sav_ion,dd_sav_ion, & 131 | dd2_sav_ion,ddi_sav_ion, & 132 | dd2i_sav_ion,dd3i_sav_ion 133 | -------------------------------------------------------------------------------- /gravity/forcetree.h: -------------------------------------------------------------------------------- 1 | #ifndef FORCETREE_H 2 | #define FORCETREE_H 3 | 4 | #ifndef INLINE_FUNC 5 | #ifdef INLINE 6 | #define INLINE_FUNC inline 7 | #else 8 | #define INLINE_FUNC 9 | #endif 10 | #endif 11 | 12 | /* 13 | * This file was originally part of the GADGET3 code developed by 14 | * Volker Springel. The code has been modified 15 | * substantially (condensed, new feedback routines added, 16 | * some optimizatins, and new variable/memory conventions added) 17 | * by Phil Hopkins (phopkins@caltech.edu) for GIZMO. 18 | */ 19 | 20 | 21 | #define BITFLAG_TOPLEVEL 0 22 | #define BITFLAG_DEPENDS_ON_LOCAL_MASS 1 23 | #define BITFLAG_MAX_SOFTENING_TYPE 2 /* bits 2-4; this is a relic of the old code which used bitflags instead of variables to deal with different softenings (tons of complexity for not much gain, no longer used) */ 24 | #define BITFLAG_MIXED_SOFTENINGS_IN_NODE 5 /* this is a relic of the old code which used bitflags instead of variables to deal with different softenings (tons of complexity for not much gain, no longer used) */ 25 | #define BITFLAG_INTERNAL_TOPLEVEL 6 26 | #define BITFLAG_MULTIPLEPARTICLES 7 27 | #define BITFLAG_NODEHASBEENKICKED 8 28 | #define BITFLAG_INSIDE_LINKINGLENGTH 9 29 | #define BITFLAG_MASK ((1 << BITFLAG_MULTIPLEPARTICLES)) 30 | 31 | void force_update_tree(void); 32 | 33 | 34 | void force_flag_localnodes(void); 35 | 36 | void *gravity_primary_loop(void *p); 37 | void *gravity_secondary_loop(void *p); 38 | 39 | int force_treeevaluate(int target, int mode, int *exportflag, int *exportnodecount, int *exportindex); 40 | int force_treeevaluate_ewald_correction(int target, int mode, int *exportflag, int *exportnodecount, int *exportindex); 41 | int force_treeevaluate_potential(int target, int type, int *nexport, int *nsend_local); 42 | 43 | void force_drift_node(int no, integertime time1); 44 | 45 | void force_tree_discardpartials(void); 46 | void force_treeupdate_pseudos(int); 47 | void force_update_pseudoparticles(void); 48 | 49 | void force_kick_node(int i, MyDouble *dv); 50 | 51 | void force_dynamic_update(void); 52 | void force_dynamic_update_node(int no, int mode, MyFloat *minbound, MyFloat *maxbound); 53 | 54 | void force_update_hmax(void); 55 | void force_update_hmax_of_node(int no, int mode); 56 | 57 | void force_finish_kick_nodes(void); 58 | 59 | void force_create_empty_nodes(int no, int topnode, int bits, int x, int y, int z, int *nodecount, int *nextfree); 60 | 61 | void force_exchange_pseudodata(void); 62 | 63 | void force_insert_pseudo_particles(void); 64 | 65 | void force_add_star_to_tree(int igas, int istar); 66 | 67 | void force_costevaluate(void); 68 | int force_getcost_single(void); 69 | int force_getcost_quadru(void); 70 | void force_resetcost(void); 71 | void force_setupnonrecursive(int no); 72 | void force_treeallocate(int maxnodes, int maxpart); 73 | int force_treebuild(int npart, struct unbind_data *mp); 74 | int force_treebuild_single(int npart, struct unbind_data *mp); 75 | 76 | int force_treeevaluate_direct(int target, int mode); 77 | 78 | void force_treefree(void); 79 | void force_update_node(int no, int flag); 80 | void force_update_node_recursive(int no, int sib, int father); 81 | void force_update_size_of_parent_node(int no); 82 | 83 | void dump_particles(void); 84 | 85 | MyFloat INLINE_FUNC ngb_periodic(MyFloat x); 86 | MyFloat INLINE_FUNC ngb_periodic_longbox(MyFloat x); 87 | MyFloat ngb_select_closest(int k, int n, MyFloat *arr, int *ind); 88 | void ngb_treeallocate(int npart); 89 | void ngb_treebuild(void); 90 | 91 | 92 | void ngb_treefree(void); 93 | void ngb_treesearch(int); 94 | void ngb_treesearch_pairs(int); 95 | void ngb_update_nodes(void); 96 | void ngb_treesearch_notsee(int no); 97 | 98 | int ngb_treefind_fof_primary(MyDouble searchcenter[3], MyFloat hsml, int target, int *startnode, int mode, 99 | int *nexport, int *nsend_local, int MyFOF_PRIMARY_LINK_TYPES); 100 | int ngb_clear_buf(MyDouble searchcenter[3], MyFloat hguess, int numngb); 101 | void ngb_treefind_flagexport(MyDouble searchcenter[3], MyFloat hguess); 102 | 103 | 104 | int ngb_treefind_pairs_threads(MyDouble searchcenter[3], MyFloat hsml, int target, int *startnode, 105 | int mode, int *exportflag, int *exportnodecount, int *exportindex, int *ngblist); 106 | int ngb_treefind_variable_targeted(MyDouble searchcenter[3], MyFloat hsml, int target, int *startnode, int mode, 107 | int *nexport, int *nsend_local, int TARGET_BITMASK); 108 | int ngb_treefind_pairs_targeted(MyDouble searchcenter[3], MyFloat hsml, int target, int *startnode, int mode, 109 | int *nexport, int *nsend_local, int TARGET_BITMASK); 110 | int ngb_treefind_variable_threads(MyDouble searchcenter[3], MyFloat hsml, int target, int *startnode, int mode, 111 | int *exportflag, int *exportnodecount, int *exportindex, int *ngblist); 112 | 113 | #endif 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /galaxy_sf/blackholes/blackhole.h: -------------------------------------------------------------------------------- 1 | /*! \file blackhole.h 2 | * \brief routine declarations for gas accretion onto black holes, and black hole mergers 3 | */ 4 | /* 5 | * This file is largely written by Phil Hopkins (phopkins@caltech.edu) for GIZMO. 6 | * see notes in blackhole.c for details on code history. 7 | */ 8 | 9 | #ifdef BLACK_HOLES // top-level flag [needs to be here to prevent compiler breaking when this is not active] // 10 | 11 | 12 | #define BHPOTVALUEINIT 1.0e30 13 | extern int N_active_loc_BHs; /*!< number of active black holes on the LOCAL processor */ 14 | 15 | extern struct blackhole_temp_particle_data // blackholedata_topass 16 | { 17 | MyIDType index; 18 | MyFloat BH_InternalEnergy; 19 | MyFloat Mgas_in_Kernel; 20 | MyFloat Mstar_in_Kernel; 21 | MyFloat Malt_in_Kernel; 22 | MyFloat Jgas_in_Kernel[3]; 23 | MyFloat Jstar_in_Kernel[3]; 24 | MyFloat Jalt_in_Kernel[3]; // mass/angular momentum for GAS/STAR/TOTAL components computed always now 25 | MyLongDouble accreted_Mass; 26 | MyLongDouble accreted_BH_Mass; 27 | MyLongDouble accreted_BH_Mass_alphadisk; 28 | #if defined(BH_SWALLOWGAS) && !defined(BH_GRAVCAPTURE_GAS) 29 | MyLongDouble BH_AccretionDeficit; 30 | #endif 31 | #ifdef GRAIN_FLUID 32 | MyFloat accreted_dust_Mass; 33 | #endif 34 | #ifdef RT_REINJECT_ACCRETED_PHOTONS 35 | MyFloat accreted_photon_energy; 36 | #endif 37 | #ifdef BH_ALPHADISK_ACCRETION 38 | MyFloat mdot_alphadisk; /*!< gives mdot of mass going into alpha disk */ 39 | #endif 40 | #if defined(BH_OUTPUT_MOREINFO) 41 | MyFloat Sfr_in_Kernel; 42 | #endif 43 | #if defined(BH_GRAVACCRETION) && (BH_GRAVACCRETION == 0) 44 | MyFloat MgasBulge_in_Kernel; 45 | MyFloat MstarBulge_in_Kernel; 46 | #endif 47 | #ifdef BH_CALC_LOCAL_ANGLEWEIGHTS 48 | MyFloat BH_angle_weighted_kernel_sum; 49 | #endif 50 | #ifdef BH_DYNFRICTION 51 | MyFloat DF_rms_vel, DF_mean_vel[3], DF_mmax_particles; 52 | #endif 53 | #if defined(BH_BONDI) || defined(BH_DRAG) || (BH_GRAVACCRETION >= 5) || defined(SINGLE_STAR_SINK_DYNAMICS) || defined(SINGLE_STAR_TIMESTEPPING) 54 | MyFloat BH_SurroundingGasVel[3]; 55 | #endif 56 | #ifdef JET_DIRECTION_FROM_KERNEL_AND_SINK 57 | MyFloat BH_SurroundingGasCOM[3]; 58 | #endif 59 | #if (BH_GRAVACCRETION == 8) 60 | MyFloat hubber_mdot_vr_estimator, hubber_mdot_disk_estimator, hubber_mdot_bondi_limiter; 61 | #endif 62 | #if defined(BH_FOLLOW_ACCRETED_MOMENTUM) 63 | MyLongDouble accreted_momentum[3]; /*!< accreted linear momentum */ 64 | #endif 65 | #if defined(BH_RETURN_BFLUX) 66 | MyLongDouble accreted_B[3]; 67 | #endif 68 | #if defined(BH_FOLLOW_ACCRETED_COM) 69 | MyLongDouble accreted_centerofmass[3]; /*!< accreted center-of-mass */ 70 | #endif 71 | #if defined(BH_FOLLOW_ACCRETED_ANGMOM) 72 | MyLongDouble accreted_J[3]; /*!< accreted angular momentum */ 73 | #endif 74 | #if defined(BH_GRAVCAPTURE_GAS) 75 | MyFloat mass_to_swallow_edd; /*!< gives the mass we want to swallow that contributes to eddington */ 76 | #endif 77 | #if defined(BH_RETURN_ANGMOM_TO_GAS) 78 | MyFloat angmom_prepass_sum_for_passback[3]; /*!< Normalization term for angular momentum feedback kicks, see denominator of Eq 22 of Hubber 2013 */ 79 | MyFloat angmom_norm_topass_in_swallowloop; /*!< corresponding scalar normalization calculated from the vector above */ 80 | #endif 81 | #if defined(BH_RETURN_BFLUX) 82 | MyFloat kernel_norm_topass_in_swallowloop; 83 | #endif 84 | } 85 | *BlackholeTempInfo; 86 | 87 | 88 | /* blackhole_utils.c */ 89 | void blackhole_start(void); 90 | void blackhole_end(void); 91 | void blackhole_properties_loop(void); 92 | double bh_eddington_mdot(double bh_mass); 93 | double bh_lum_bol(double mdot, double mass, long pindex); 94 | double evaluate_blackhole_radiative_efficiency(double mdot, double mass, long pindex); 95 | double evaluate_blackhole_cosmicray_efficiency(double mdot, double mass, long pindex); 96 | 97 | /* blackholes.c */ 98 | void blackhole_final_operations(void); 99 | int bhsink_isactive(int i); 100 | 101 | /* blackhole_environment.c */ 102 | void blackhole_environment_loop(void); 103 | #ifdef BH_GRAVACCRETION 104 | void blackhole_environment_second_loop(void); 105 | #endif 106 | 107 | /* blackhole_swallow_and_kick.c */ 108 | void blackhole_swallow_and_kick_loop(void); 109 | double target_mass_for_wind_spawning(int i); 110 | 111 | /* blackhole_feed.c */ 112 | void blackhole_feed_loop(void); 113 | 114 | //void check_for_bh_merger(int j, MyIDType id); 115 | int bh_check_boundedness(int j, double vrel, double vesc, double dr_code, double sink_radius); 116 | double bh_vesc(int j, double mass, double r_code, double bh_softening); 117 | void set_blackhole_mdot(int i, int n, double dt); 118 | void set_blackhole_new_mass(int i, int n, double dt); 119 | #if defined(BH_DRAG) || defined(BH_DYNFRICTION) 120 | void set_blackhole_drag(int i, int n, double dt); 121 | #endif 122 | void set_blackhole_long_range_rp(int i, int n); 123 | 124 | 125 | 126 | #endif // top-level flag 127 | -------------------------------------------------------------------------------- /turb/turbulent_diffusion.h: -------------------------------------------------------------------------------- 1 | /* --------------------------------------------------------------------------------- */ 2 | /* ... turbulent diffusion (sub-grid) models ... 3 | * 4 | * The basic equations here follow the Smagorinky eddy diffusion model. For SPH, the 5 | * discretization comes from Wadsley 2008 & Shen 2010. However, some caution is needed, 6 | * for SPH, this relys on the (noisy and zeroth-order inconsistent) SPH second-derivative 7 | * operator. So a large kernel is especially useful to minimize the systematic errors. 8 | * For MFM/MFV methods, the consistent finite-volume formulation is used, which 9 | * greatly minimizes artificial (numerical) diffusion. 10 | * In either case, since we solve the diffusion equations explicitly, a stronger timestep 11 | * restriction is necessary (since the equations are parabolic); this is in timestep.c. 12 | * This is very important (many implementations of these equations in the literature 13 | * do not include the appropriate timestep and flux-limiters; that makes the equations 14 | * numerically unstable (you can get an answer, but it might be wrong, independent of resolution) 15 | * 16 | * This file was written by Phil Hopkins (phopkins@caltech.edu) for GIZMO. 17 | */ 18 | /* --------------------------------------------------------------------------------- */ 19 | { 20 | #ifdef TURB_DIFF_METALS // turbulent diffusion of metals (passive scalar mixing) // 21 | 22 | if((local.Mass>0)&&(P[j].Mass>0)&&((local.TD_DiffCoeff>MIN_REAL_NUMBER)||(SphP[j].TD_DiffCoeff>MIN_REAL_NUMBER))) 23 | { 24 | double wt_i=0.5, wt_j=0.5, cmag, d_scalar; 25 | double diffusion_wt = wt_i*local.TD_DiffCoeff + wt_j*SphP[j].TD_DiffCoeff; // physical 26 | #ifdef HYDRO_SPH 27 | diffusion_wt *= 0.5*(local.Density + SphP[j].Density)*All.cf_a3inv; // physical 28 | #else 29 | diffusion_wt *= Riemann_out.Face_Density; // physical 30 | #endif 31 | /* calculate implied mass flux 'across the boundary' to prevent excessively large coefficients */ 32 | double massflux = fabs( Face_Area_Norm * diffusion_wt / (DMIN(kernel.h_i,kernel.h_j)*All.cf_atime) * dt_hydrostep / (DMIN(local.Mass,P[j].Mass)) ); 33 | if(massflux > 0.25) {diffusion_wt *= 0.25/massflux;} 34 | 35 | int k_species; 36 | double rho_i = local.Density*All.cf_a3inv, rho_j = SphP[j].Density*All.cf_a3inv, rho_ij = 0.5*(rho_i+rho_j); // physical 37 | for(k_species=0;k_species= NUM_METAL_SPECIES) {Z_j = return_ismdustchem_species_of_interest_for_diffusion_and_yields(j,k_species);} 43 | #endif 44 | d_scalar = local.Metallicity[k_species]-Z_j; // physical 45 | for(k=0;k<3;k++) 46 | { 47 | double grad_direct = d_scalar * kernel.dp[k] * rinv*rinv; // 1/code length 48 | double grad_ij = grad_direct; 49 | #if !defined(TURB_DIFF_METALS_LOWORDER) 50 | if(k_species < NUM_METAL_SPECIES) {grad_ij = wt_i*local.Gradients.Metallicity[k_species][k] + wt_j*SphP[j].Gradients.Metallicity[k_species][k];} // 1/code length 51 | #endif 52 | grad_dot_x_ij += grad_ij * kernel.dp[k]; // physical 53 | grad_ij = MINMOD(grad_ij , grad_direct); 54 | cmag += Face_Area_Vec[k] * grad_ij; // 1/code length 55 | } 56 | cmag /= All.cf_atime; // cmag has units of 1/r -- convert to physical 57 | 58 | double d_scalar_tmp = d_scalar - grad_dot_x_ij; // physical 59 | double d_scalar_hll = MINMOD(d_scalar , d_scalar_tmp); 60 | double hll_corr = rho_ij * HLL_correction(d_scalar_hll, 0, rho_ij, diffusion_wt) / (-diffusion_wt); // physical 61 | double cmag_corr = cmag + hll_corr; 62 | cmag = MINMOD(1.5*cmag, cmag_corr); 63 | double f_direct = Face_Area_Norm*d_scalar*rinv/All.cf_atime; // physical 64 | if((f_direct*cmag < 0) && (fabs(f_direct) > HLL_DIFFUSION_OVERSHOOT_FACTOR*fabs(cmag))) {cmag = 0;} 65 | 66 | cmag *= -diffusion_wt * dt_hydrostep; // physical 67 | if(fabs(cmag) > 0) 68 | { 69 | double zlim = 0.25 * DMIN( DMIN(local.Mass,P[j].Mass)*fabs(d_scalar) , DMAX(local.Mass*local.Metallicity[k_species] , P[j].Mass*Z_j) ); 70 | if(fabs(cmag)>zlim) {cmag*=zlim/fabs(cmag);} 71 | #ifndef HYDRO_SPH 72 | double dmet = (Z_j-local.Metallicity[k_species]) * fabs(mdot_estimated) * dt_hydrostep; 73 | cmag = MINMOD(dmet,cmag); // limiter based on mass exchange from MFV HLLC solver // 74 | #endif 75 | out.Dyield[k_species] += FluxCorrectionFactor_to_i * cmag; 76 | if(j_is_active_for_fluxes) {SphP[j].Dyield[k_species] -= FluxCorrectionFactor_to_j * cmag;} 77 | } 78 | } 79 | } 80 | #endif 81 | } 82 | -------------------------------------------------------------------------------- /hydro/conduction.h: -------------------------------------------------------------------------------- 1 | /* --------------------------------------------------------------------------------- */ 2 | /* ... real conduction evaluation ... 3 | * 4 | * For SPH, this relys on the (noisy and zeroth-order inconsistent) SPH second-derivative 5 | * operator. So a large kernel is especially useful to minimize the systematic errors. 6 | * For MFM/MFV methods, the consistent finite-volume formulation is used. 7 | * In either case, since we solve the conduction equations explicitly, a stronger timestep 8 | * restriction is necessary (since the equations are parabolic); this is in timestep.c 9 | * 10 | * This file was written by Phil Hopkins (phopkins@caltech.edu) for GIZMO. 11 | */ 12 | /* --------------------------------------------------------------------------------- */ 13 | { 14 | double scalar_i = local.InternalEnergyPred; // physical units 15 | double scalar_j = SphP[j].InternalEnergyPred; // physical units 16 | double kappa_i = local.Kappa_Conduction; // physical units 17 | double kappa_j = SphP[j].Kappa_Conduction; // physical units 18 | 19 | if((kappa_i>MIN_REAL_NUMBER)&&(kappa_j>MIN_REAL_NUMBER)&&(local.Mass>0)&&(P[j].Mass>0)) 20 | { 21 | double d_scalar = scalar_i - scalar_j; 22 | double rho_i, rho_j, rho_ij; 23 | rho_i = local.Density*All.cf_a3inv; rho_j = SphP[j].Density*All.cf_a3inv; rho_ij = 0.5*(rho_i+rho_j); // physical units 24 | 25 | // NOT SPH: Now we use the more accurate finite-volume formulation, with the effective faces we have already calculated // 26 | double *grad_i = local.Gradients.InternalEnergy; // physical u / code length 27 | double *grad_j = SphP[j].Gradients.InternalEnergy; 28 | 29 | double flux_wt = rho_ij; 30 | double diffusion_wt = 0.5*(kappa_i+kappa_j); 31 | #ifdef COOLING 32 | diffusion_wt = kappa_i*kappa_j/diffusion_wt; 33 | #endif 34 | int do_isotropic = 1; 35 | double b_hll=1, cmag=0, wt_i=0.5, wt_j=0.5, grad_dot_x_ij = 0; 36 | double grad_ij[3]; 37 | for(k=0;k<3;k++) 38 | { 39 | double q_grad = wt_i*grad_i[k] + wt_j*grad_j[k]; 40 | double q_direct = d_scalar * kernel.dp[k] * rinv*rinv; // physical u / code length 41 | grad_dot_x_ij += q_grad * kernel.dp[k]; // physical u 42 | #ifdef MAGNETIC 43 | grad_ij[k] = MINMOD_G(q_grad , q_direct); 44 | if(q_grad*q_direct < 0) {if(fabs(q_direct) > 5.*fabs(q_grad)) {grad_ij[k] = 0.0;}} 45 | #else 46 | grad_ij[k] = MINMOD(q_grad , q_direct); 47 | #endif 48 | } 49 | #ifdef MAGNETIC 50 | if(bhat_mag > 0) 51 | { 52 | do_isotropic = 0; 53 | double B_interface_dot_grad_T = 0.0, grad_mag = 0.0; 54 | for(k=0;k<3;k++) 55 | { 56 | B_interface_dot_grad_T += bhat[k] * grad_ij[k]; 57 | grad_mag += grad_ij[k]*grad_ij[k]; 58 | } 59 | for(k=0;k<3;k++) {cmag += bhat[k] * Face_Area_Vec[k];} // physical 60 | cmag *= B_interface_dot_grad_T; // physical / code length 61 | if(grad_mag > 0) {grad_mag = sqrt(grad_mag);} else {grad_mag=1;} 62 | b_hll = B_interface_dot_grad_T / grad_mag; // physical 63 | b_hll *= b_hll; // physical 64 | } 65 | #endif 66 | if(do_isotropic) {for(k=0;k<3;k++) {cmag += Face_Area_Vec[k] * grad_ij[k];}} 67 | cmag /= All.cf_atime; // cmag has units of u/r -- convert to physical 68 | 69 | /* obtain HLL correction terms for Reimann problem solution */ 70 | double d_scalar_tmp = d_scalar - grad_dot_x_ij; // physical 71 | double d_scalar_hll = MINMOD(d_scalar , d_scalar_tmp); 72 | double hll_corr = b_hll * flux_wt * HLL_correction(d_scalar_hll, 0, flux_wt, diffusion_wt) / (-diffusion_wt); // physical 73 | double cmag_corr = cmag + hll_corr; 74 | cmag = MINMOD(HLL_DIFFUSION_COMPROMISE_FACTOR*cmag, cmag_corr); 75 | /* slope-limiter to ensure heat always flows from hot to cold */ 76 | double d_scalar_b = b_hll * d_scalar; // physical 77 | double f_direct = Face_Area_Norm*d_scalar_b*rinv/All.cf_atime; // physical 78 | double check_for_stability_sign = f_direct*cmag; // physical 79 | if((check_for_stability_sign < 0) && (fabs(f_direct) > HLL_DIFFUSION_OVERSHOOT_FACTOR*fabs(cmag))) {cmag = 0;} 80 | cmag *= -diffusion_wt; /* multiply through coefficient to get flux (physical units) */ 81 | 82 | 83 | /* follow that with a flux limiter as well */ 84 | diffusion_wt = dt_hydrostep * cmag; // all in physical units // 85 | if(fabs(diffusion_wt) > 0) 86 | { 87 | // enforce a flux limiter for stability (to prevent overshoot) // 88 | //double du_ij_cond = 1.0*DMIN(local.Mass*scalar_i, P[j].Mass*scalar_j); 89 | double du_ij_cond = DMIN( 0.25*fabs(local.Mass*scalar_i-P[j].Mass*scalar_j) , DMAX(local.Mass*scalar_i , P[j].Mass*scalar_j)); 90 | if(check_for_stability_sign<0) {du_ij_cond *= 1.e-2;} 91 | if(fabs(diffusion_wt)>du_ij_cond) {diffusion_wt *= du_ij_cond/fabs(diffusion_wt);} 92 | Fluxes.p += diffusion_wt / dt_hydrostep; 93 | } // if(diffusion_wt > 0) 94 | 95 | } // close check that kappa and particle masses are positive 96 | } 97 | -------------------------------------------------------------------------------- /system/ngb_codeblock_after_condition_threaded.h: -------------------------------------------------------------------------------- 1 | /* 2 | this defines a code-block to be inserted in the neighbor search routines after the conditions for neighbor-validity are applied 3 | (valid particle types checked) 4 | */ 5 | if(P[p].Ti_current != ti_Current) 6 | { 7 | LOCK_PARTNODEDRIFT; 8 | #ifdef _OPENMP 9 | #pragma omp critical(_partdriftngb_) 10 | #endif 11 | drift_particle(p, ti_Current); 12 | UNLOCK_PARTNODEDRIFT; 13 | } 14 | 15 | #ifndef REDUCE_TREEWALK_BRANCHING 16 | #if (SEARCHBOTHWAYS==1) 17 | dist = DMAX(PPP[p].Hsml, hsml); 18 | #else 19 | dist = hsml; 20 | #endif 21 | dx = NGB_PERIODIC_BOX_LONG_X(P[p].Pos[0] - searchcenter[0], P[p].Pos[1] - searchcenter[1], P[p].Pos[2] - searchcenter[2],-1); 22 | if(dx > dist) continue; 23 | dy = NGB_PERIODIC_BOX_LONG_Y(P[p].Pos[0] - searchcenter[0], P[p].Pos[1] - searchcenter[1], P[p].Pos[2] - searchcenter[2],-1); 24 | if(dy > dist) continue; 25 | dz = NGB_PERIODIC_BOX_LONG_Z(P[p].Pos[0] - searchcenter[0], P[p].Pos[1] - searchcenter[1], P[p].Pos[2] - searchcenter[2],-1); 26 | if(dz > dist) continue; 27 | if(dx * dx + dy * dy + dz * dz > dist * dist) continue; 28 | #endif 29 | ngblist[numngb++] = p; /* Note: unlike in previous versions of the code, the buffer can hold up to all particles. note also the threaded-vs-unthreaded use of n vs N in ngblist */ 30 | } 31 | else 32 | { 33 | if(no >= maxPart + maxNodes) /* pseudo particle */ 34 | { 35 | #ifdef DONOTUSENODELIST 36 | if(mode == 1) 37 | { 38 | no = Nextnode[no - maxNodes]; 39 | continue; 40 | } 41 | #endif 42 | if(mode == 1) {endrun(123128);} 43 | 44 | if(target >= 0) /* if no target is given, export will not occur */ 45 | { 46 | if(exportflag[task = DomainTask[no - (maxPart + maxNodes)]] != target) 47 | { 48 | exportflag[task] = target; 49 | exportnodecount[task] = NODELISTLENGTH; 50 | } 51 | 52 | if(exportnodecount[task] == NODELISTLENGTH) 53 | { 54 | int exitFlag = 0, nexp; 55 | LOCK_NEXPORT; 56 | #ifdef _OPENMP 57 | #pragma omp critical(_nexportngb_) 58 | #endif 59 | { 60 | if(Nexport >= bunchSize) 61 | { 62 | /* out of buffer space. Need to discard work for this particle and interrupt */ 63 | BufferFullFlag = 1; 64 | exitFlag = 1; 65 | } 66 | else 67 | { 68 | nexp = Nexport; 69 | Nexport++; 70 | } 71 | } 72 | UNLOCK_NEXPORT; 73 | if(exitFlag) {return -1;} /* buffer has filled -- important that only this and other buffer-full conditions return the negative condition for the routine */ 74 | 75 | exportnodecount[task] = 0; 76 | exportindex[task] = nexp; 77 | DataIndexTable[nexp].Task = task; 78 | DataIndexTable[nexp].Index = target; 79 | DataIndexTable[nexp].IndexGet = nexp; 80 | } 81 | #ifndef DONOTUSENODELIST 82 | DataNodeList[exportindex[task]].NodeList[exportnodecount[task]++] = DomainNodeIndex[no - (maxPart + maxNodes)]; 83 | if(exportnodecount[task] < NODELISTLENGTH) 84 | DataNodeList[exportindex[task]].NodeList[exportnodecount[task]] = -1; 85 | #endif 86 | } 87 | 88 | no = Nextnode[no - maxNodes]; 89 | continue; 90 | } 91 | 92 | current = &Nodes[no]; 93 | 94 | #ifndef DONOTUSENODELIST 95 | if(mode == 1) 96 | { 97 | if(current->u.d.bitflags & (1 << BITFLAG_TOPLEVEL)) /* we reached a top-level node again, which means that we are done with the branch */ 98 | { 99 | *startnode = -1; 100 | #ifndef REDUCE_TREEWALK_BRANCHING 101 | return numngb; 102 | #else 103 | return ngb_filter_variables(numngb, ngblist, &vcenter, &box, &hbox, hsml, SEARCHBOTHWAYS); 104 | #endif 105 | } 106 | } 107 | #endif 108 | 109 | if(current->Ti_current != ti_Current) 110 | { 111 | LOCK_PARTNODEDRIFT; 112 | #ifdef _OPENMP 113 | #pragma omp critical(_nodedriftngb_) 114 | #endif 115 | force_drift_node(no, ti_Current); 116 | UNLOCK_PARTNODEDRIFT; 117 | } 118 | 119 | if(!(current->u.d.bitflags & (1 << BITFLAG_MULTIPLEPARTICLES))) 120 | { 121 | if(current->u.d.mass) /* open cell */ 122 | { 123 | no = current->u.d.nextnode; 124 | continue; 125 | } 126 | } 127 | 128 | double hmax = Extnodes[no].hmax; 129 | #if (SEARCHBOTHWAYS==1) 130 | dist = DMAX(hmax, hsml) + 0.5 * current->len; 131 | #else 132 | dist = hsml + 0.5 * current->len; 133 | #endif 134 | no = current->u.d.sibling; /* in case the node can be discarded */ 135 | #include "ngb_codeblock_checknode.h" 136 | no = current->u.d.nextnode; // ok, we need to open the node // 137 | } 138 | } 139 | 140 | *startnode = -1; 141 | #ifndef REDUCE_TREEWALK_BRANCHING 142 | return numngb; 143 | #else 144 | return ngb_filter_variables(numngb, ngblist, &vcenter, &box, &hbox, hsml, SEARCHBOTHWAYS); 145 | #endif 146 | -------------------------------------------------------------------------------- /scripts/visit/avtGIZMOFileFormat.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * 3 | * Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC 4 | * Produced at the Lawrence Livermore National Laboratory 5 | * LLNL-CODE-442911 6 | * All rights reserved. 7 | * 8 | * This file is part of VisIt. For details, see https://visit.llnl.gov/. The 9 | * full copyright notice is contained in the file COPYRIGHT located at the root 10 | * of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html. 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following conditions are met: 14 | * 15 | * - Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the disclaimer below. 17 | * - Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the disclaimer (as noted below) in the 19 | * documentation and/or other materials provided with the distribution. 20 | * - Neither the name of the LLNS/LLNL nor the names of its contributors may 21 | * be used to endorse or promote products derived from this software without 22 | * specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | * ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, 28 | * LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY 29 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 35 | * DAMAGE. 36 | * 37 | *****************************************************************************/ 38 | 39 | 40 | // ************************************************************************* // 41 | // avtGIZMOFileFormat.h // 42 | // ************************************************************************* // 43 | 44 | #ifndef AVT_GIZMO_FILE_FORMAT_H 45 | #define AVT_GIZMO_FILE_FORMAT_H 46 | 47 | #include 48 | 49 | #include 50 | 51 | #ifndef GIZMO_N_PTYPE 52 | #define GIZMO_N_PTYPE 6 53 | #endif 54 | 55 | 56 | // **************************************************************************** 57 | // Class: avtGIZMOFileFormat 58 | // 59 | // Purpose: 60 | // Reads in GIZMO files as a plugin to VisIt. 61 | // 62 | // Programmer: davide -- generated by xml2avt 63 | // Creation: Fri Aug 1 09:27:55 PDT 2014 64 | // 65 | // **************************************************************************** 66 | 67 | class avtGIZMOFileFormat : public avtSTSDFileFormat 68 | { 69 | public: 70 | avtGIZMOFileFormat(const char *filename); 71 | virtual ~avtGIZMOFileFormat() {;}; 72 | 73 | void Initialize(); 74 | void ReadHeader(); 75 | void ReadMetadata(); 76 | 77 | // 78 | // This is used to return unconvention data -- ranging from material 79 | // information to information about block connectivity. 80 | // 81 | // virtual void *GetAuxiliaryData(const char *var, const char *type, 82 | // void *args, DestructorFunction &); 83 | // 84 | 85 | virtual bool ReturnsValidTime() const { return true; }; 86 | virtual double GetTime(void); 87 | 88 | virtual const char *GetType(void) { return "GIZMO"; }; 89 | virtual void FreeUpResources(void); 90 | 91 | virtual vtkDataSet *GetMesh(const char *); 92 | virtual vtkDataArray *GetVar(const char *); 93 | virtual vtkDataArray *GetVectorVar(const char *); 94 | 95 | struct Header { 96 | double box_size; 97 | int flag_cooling; 98 | int flag_double_precision; 99 | int flag_feedback; 100 | int flag_ic_info; 101 | int flag_metals; 102 | int flag_sfr; 103 | int flag_stellar_age; 104 | double hubble_param; 105 | double mass_table[GIZMO_N_PTYPE]; 106 | int num_files_per_snapshot; 107 | int num_part_this_file[GIZMO_N_PTYPE]; 108 | unsigned int num_part_total[GIZMO_N_PTYPE]; 109 | unsigned int num_part_total_high_word[GIZMO_N_PTYPE]; 110 | double Omega_Matter; 111 | double Omega_Lambda; 112 | double redshift; 113 | double time; 114 | }; 115 | 116 | struct Field { 117 | std::string name; 118 | int rank; 119 | }; 120 | 121 | protected: 122 | bool initialized; 123 | std::string filename; 124 | Header header; 125 | std::list fields[GIZMO_N_PTYPE]; 126 | 127 | virtual void PopulateDatabaseMetaData(avtDatabaseMetaData *); 128 | }; 129 | 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /sidm/sidm_core.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "../allvars.h" 11 | #include "../proto.h" 12 | #include "../kernel.h" 13 | 14 | #define GSLWORKSIZE 100000 15 | 16 | /*! \file sidm_routines.c 17 | * \brief Fuctions and routines needed for the calculations of dark matter self interactions 18 | * 19 | * This file contains the functions and routines necesary for the computation of 20 | * the self-interaction probabilities and the velocity kicks due to the interactios. 21 | * Originally written by Miguel Rocha, rocham@uci.edu. Oct 2010. Updated on 2014 & re-written by PFH March 2018 22 | */ 23 | 24 | /*! This function calculates the interaction probability between two particles. 25 | * It checks if comoving integration is on and does the necesary change of 26 | * variables and units. 27 | */ 28 | 29 | #ifdef DM_SIDM 30 | 31 | 32 | double prob_of_interaction(double mass, double r, double h_si, double dV[3], double dt) 33 | { 34 | double dVmag = sqrt(dV[0]*dV[0]+dV[1]*dV[1]+dV[2]*dV[2]) / All.cf_atime; // velocity in physical 35 | double rho_eff = mass / (h_si*h_si*h_si) * All.cf_a3inv; // density in physical 36 | double cx_eff = All.DM_InteractionCrossSection * g_geo(r/h_si); // effective cross section (physical) scaled to cgs 37 | double units = UNIT_SURFDEN_IN_CGS; // needed to convert everything to cgs 38 | if(All.DM_InteractionVelocityScale>0) {double x=dVmag/All.DM_InteractionVelocityScale; cx_eff/=1+x*x*x*x;} // take velocity dependence 39 | return rho_eff * cx_eff * dVmag * dt * units; // dimensionless probability 40 | } 41 | 42 | /*! This routine sets the kicks for each particle after it has been decided that they will 43 | * interact. It uses an algorithm tha conserves energy and momentum but picks a random direction so it does not conserves angular momentum. */ 44 | #if !defined(GRAIN_COLLISIONS) /* if using the 'grain collisions' module, these functions will be defined elsewhere [in the grains subroutines] */ 45 | void calculate_interact_kick(double dV[3], double kick[3], double m) 46 | { 47 | double dVmag = (1-All.DM_DissipationFactor)*sqrt(dV[0]*dV[0]+dV[1]*dV[1]+dV[2]*dV[2]); 48 | if(dVmag<0) {dVmag=0;} 49 | if(All.DM_KickPerCollision>0) {double v0=All.DM_KickPerCollision; dVmag=sqrt(dVmag*dVmag+v0*v0);} 50 | double cos_theta = 2.0*gsl_rng_uniform(random_generator)-1.0, sin_theta = sqrt(1.-cos_theta*cos_theta), phi = gsl_rng_uniform(random_generator)*2.0*M_PI; 51 | kick[0] = 0.5*(dV[0] + dVmag*sin_theta*cos(phi)); 52 | kick[1] = 0.5*(dV[1] + dVmag*sin_theta*sin(phi)); 53 | kick[2] = 0.5*(dV[2] + dVmag*cos_theta); 54 | } 55 | #endif 56 | 57 | 58 | /*! This function returns the value of the geometrical factor needed for the calculation of the interaction probability. */ 59 | double g_geo(double r) 60 | { 61 | double f, u; int i; u = r / 2.0 * GEOFACTOR_TABLE_LENGTH; i = (int) u; 62 | if(i >= GEOFACTOR_TABLE_LENGTH) {i = GEOFACTOR_TABLE_LENGTH - 1;} 63 | if(i <= 1) {f = 0.992318 + (GeoFactorTable[0] - 0.992318)*u;} else {f = GeoFactorTable[i - 1] + (GeoFactorTable[i] - GeoFactorTable[i - 1]) * (u - i);} 64 | return f; 65 | } 66 | 67 | /*! This routine initializes the table that will be used to get the geometrical factor 68 | * as a function of the two particle separations. It populates a table with the results of the numerical integration */ 69 | void init_geofactor_table(void) 70 | { 71 | int i; double result, abserr,r; 72 | gsl_function F; gsl_integration_workspace *workspace; workspace = gsl_integration_workspace_alloc(GSLWORKSIZE); 73 | for(i = 0; i < GEOFACTOR_TABLE_LENGTH; i++) 74 | { 75 | r = 2.0/GEOFACTOR_TABLE_LENGTH * (i + 1); 76 | F.function = &geofactor_integ; 77 | F.params = &r; 78 | gsl_integration_qag(&F, 0.0, 1.0, 0, 1.0e-8, GSLWORKSIZE, GSL_INTEG_GAUSS41,workspace, &result, &abserr); 79 | GeoFactorTable[i] = 2*M_PI*result; 80 | } 81 | gsl_integration_workspace_free(workspace); 82 | } 83 | 84 | /*! This function returns the integrand of the numerical integration done on init_geofactor_table(). */ 85 | double geofactor_integ(double x, void * params) 86 | { 87 | double result, abserr, r, newparams[2]; 88 | r = *(double *) params; newparams[0] = r; newparams[1] = x; 89 | gsl_function F; gsl_integration_workspace *workspace; workspace = gsl_integration_workspace_alloc(GSLWORKSIZE); 90 | F.function = &geofactor_angle_integ; F.params = newparams; 91 | 92 | gsl_integration_qag(&F, -1.0, 1.0, 0, 1.0e-8, GSLWORKSIZE, GSL_INTEG_GAUSS41,workspace, &result, &abserr); 93 | gsl_integration_workspace_free(workspace); 94 | 95 | /*! This function returns the value W(x). The values of the density kernel as a funtion of x=r/h */ 96 | double wk=0; if(x<1) kernel_main(x, 1, 1, &wk, &wk, -1); 97 | return x*x*wk*result; 98 | } 99 | 100 | /*! This function returns the integrand of the angular part of the integral done on init_geofactor_table(). */ 101 | double geofactor_angle_integ(double u, void * params) 102 | { 103 | double x,r,f; 104 | r = *(double *) params; 105 | x = *(double *) (params + sizeof(double)); 106 | f = sqrt(x*x + r*r + 2*x*r*u); 107 | double wk=0; if(f<1) kernel_main(f, 1, 1, &wk, &wk, -1); /*! This function returns the value W(x). The values of the density kernel as a funtion of x=r/h */ 108 | return wk; 109 | } 110 | 111 | /*! This function simply initializes some variables to prevent memory errors */ 112 | void init_self_interactions() {int i; for(i = 0; i < NumPart; i++) {P[i].dtime_sidm = 0; P[i].NInteractions = 0;}} 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /turb/chimes_turbulent_ion_diffusion.h: -------------------------------------------------------------------------------- 1 | /* --------------------------------------------------------------------------------- */ 2 | /* ... turbulent diffusion (sub-grid) models ... 3 | * 4 | * The basic equations here follow the Smagorinky eddy diffusion model. For SPH, the 5 | * discretization comes from Wadsley 2008 & Shen 2010. However, some caution is needed, 6 | * for SPH, this relys on the (noisy and zeroth-order inconsistent) SPH second-derivative 7 | * operator. So a large kernel is especially useful to minimize the systematic errors. 8 | * For MFM/MFV methods, the consistent finite-volume formulation is used, which 9 | * greatly minimizes artificial (numerical) diffusion. 10 | * In either case, since we solve the diffusion equations explicitly, a stronger timestep 11 | * restriction is necessary (since the equations are parabolic); this is in timestep.c. 12 | * This is very important (many implementations of these equations in the literature 13 | * do not include the appropriate timestep and flux-limiters; that makes the equations 14 | * numerically unstable (you can get an answer, but it might be wrong, independent of resolution) 15 | * 16 | * This file was taken almost entirely from the turbulent_diffusion.h file, which was written by 17 | * Phil Hopkins (phopkins@caltech.edu) for GIZMO. It has been modified by Alex Richings to apply 18 | * those same methods to the diffusion of ions and molecules in the CHIMES module. 19 | */ 20 | /* --------------------------------------------------------------------------------- */ 21 | { 22 | #ifdef CHIMES_TURB_DIFF_IONS // turbulent diffusion of CHIMES ions and molecules (passive scalar mixing) // 23 | 24 | if((local.Mass>0)&&(P[j].Mass>0)&&((local.TD_DiffCoeff>MIN_REAL_NUMBER)||(SphP[j].TD_DiffCoeff>MIN_REAL_NUMBER))) 25 | { 26 | double wt_i=0.5, wt_j=0.5, cmag, d_scalar; 27 | double diffusion_wt = wt_i*local.TD_DiffCoeff + wt_j*SphP[j].TD_DiffCoeff; // physical 28 | #ifdef HYDRO_SPH 29 | diffusion_wt *= 0.5*(local.Density + SphP[j].Density)*All.cf_a3inv; // physical 30 | #else 31 | diffusion_wt *= Riemann_out.Face_Density; // physical 32 | #endif 33 | /* calculate implied mass flux 'across the boundary' to prevent excessively large coefficients */ 34 | double massflux = fabs( Face_Area_Norm * diffusion_wt / (DMIN(kernel.h_i,kernel.h_j)*All.cf_atime) * dt_hydrostep / (DMIN(local.Mass,P[j].Mass)) ); 35 | if(massflux > 0.25) {diffusion_wt *= 0.25/massflux;} 36 | 37 | int k_species; 38 | double rho_i = local.Density*All.cf_a3inv, rho_j = SphP[j].Density*All.cf_a3inv, rho_ij = 0.5*(rho_i+rho_j); // physical 39 | 40 | // Loop through all CHIMES species to compute the change in 41 | // the total number of ions/molecules of that species. 42 | for(k_species = 0; k_species < ChimesGlobalVars.totalNumberOfSpecies; k_species++) 43 | { 44 | cmag = 0.0; 45 | double grad_dot_x_ij = 0.0; 46 | 47 | // For d_scalar, we want the difference in the number of ions per unit mass. 48 | // This is analogous to turbulent_diffusion.h, which uses the difference in 49 | // Metallicity (i.e. metal mass over total mass) here. 50 | 51 | double local_abundance_times_mass = local.ChimesNIons[k_species], external_abundance_times_mass; // values we will need 52 | #pragma omp atomic read 53 | external_abundance_times_mass = SphP[j].ChimesNIons[k_species]; // this variable can be reset owing to how we code this, needs to be carefully read for thread safety here. 54 | double external_abundance_times_mass_0 = external_abundance_times_mass; // save initial value for below 55 | 56 | d_scalar = (local_abundance_times_mass / local.Mass) - (external_abundance_times_mass / P[j].Mass); // physical 57 | for(k = 0; k < 3; k++) 58 | { 59 | double grad_direct = d_scalar * kernel.dp[k] * rinv * rinv; // 1/code length 60 | 61 | // NOTE: For CHIMES, we ONLY do this with the LOWORDER method 62 | double grad_ij = grad_direct; 63 | grad_dot_x_ij += grad_ij * kernel.dp[k]; // physical 64 | cmag += Face_Area_Vec[k] * grad_ij; // 1/code length 65 | } 66 | cmag /= All.cf_atime; // cmag has units of 1/r -- convert to physical 67 | 68 | double d_scalar_tmp = d_scalar - grad_dot_x_ij; // physical 69 | double d_scalar_hll = MINMOD(d_scalar , d_scalar_tmp); 70 | double hll_corr = rho_ij * HLL_correction(d_scalar_hll, 0, rho_ij, diffusion_wt) / (-diffusion_wt); // physical 71 | double cmag_corr = cmag + hll_corr; 72 | cmag = MINMOD(1.5 * cmag, cmag_corr); 73 | double f_direct = Face_Area_Norm * d_scalar * rinv / All.cf_atime; // physical 74 | if((f_direct * cmag < 0) && (fabs(f_direct) > HLL_DIFFUSION_OVERSHOOT_FACTOR * fabs(cmag))) {cmag = 0;} 75 | 76 | cmag *= -diffusion_wt * dt_hydrostep; // physical 77 | if(fabs(cmag) > 0) 78 | { 79 | double zlim = 0.25 * DMIN( DMIN(local.Mass, P[j].Mass) * fabs(d_scalar) , DMAX(local_abundance_times_mass , external_abundance_times_mass) ); 80 | if(fabs(cmag) > zlim) {cmag *= zlim / fabs(cmag);} 81 | #ifndef HYDRO_SPH 82 | double dmet = ((external_abundance_times_mass / P[j].Mass) - (local_abundance_times_mass / local.Mass)) * fabs(mdot_estimated) * dt_hydrostep; 83 | cmag = MINMOD(dmet,cmag); // limiter based on mass exchange from MFV HLLC solver // 84 | #endif 85 | out.ChimesIonsYield[k_species] += cmag; 86 | external_abundance_times_mass -= cmag; // that metal mass must come out of the neighbor element 87 | #pragma omp atomic 88 | SphP[j].ChimesNIons[k_species] += external_abundance_times_mass - external_abundance_times_mass_0; // here we enforce machine-accurate conservation by swapping right here. that means we need to be very careful to do this in a thread-safe manner 89 | } 90 | } 91 | } 92 | #endif // CHIMES_TURB_DIFF_IONS 93 | } 94 | -------------------------------------------------------------------------------- /scripts/compress_cleanup_sim.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ## 3 | ## This is a script designed to 'clean up' GIZMO simulation directories after the 4 | ## simulation is complete, for purposes of archiving and analyzing the simulations. 5 | ## It assumes certain directory and filename conventions, so you'll need to modify 6 | ## it to match your conventions. But I (PFH) am including it in the GIZMO repo 7 | ## because the notes below contain some useful information about what you can delete 8 | ## or compress after simulations are completed. 9 | ## 10 | ## Begin by checking for a dummy empty file called 'clean_me' which is required for 11 | ## a directory to be cleaned. this is to prevent accidentally working on active dirs 12 | done=0 13 | if [ -f "clean_me" ] 14 | then 15 | done=1 16 | fi 17 | ## Now clean up the directory. Assumes the source code is a folder named 'code' 18 | ## in your run-time directory, the snapshots are written to a sub-folder named 19 | ## 'output', and the stdout/stderr files (named gizmo.out/gizmo.err) are written 20 | ## into that same run-time directory. This is all good code practice so that all 21 | ## the information from your run is in one place, completely recoverable 22 | if [ $done -eq 1 ] 23 | then 24 | ## delete stdout/stderr, log files. these are very large and only useful while running 25 | rm gizmo.* 26 | rm *.err 27 | rm *.log 28 | rm *.out 29 | ## ewald tables are only used in-run, they can be removed 30 | rm ewald* 31 | ## by default, I never copy the full spcool_tables directory into a run-folder, but 32 | ## use symlinks to a common directory, to save space. but if you did copy them, 33 | ## they take a lot of space for identical files. 34 | rm -r spcool_tables 35 | ## check if the source code directory is already tarballed and zipped. if not, 36 | ## go into it and 'make clean' then tar and zip the source code directory. 37 | ## this is really important for archival purposes (e.g. backing up simulations). 38 | ## you always want to save the source code, of course. but because of the 39 | ## git/version-control system, even if the source code it small, it can easily 40 | ## contain thousands of tiny hidden files from version control. this plays 41 | ## havok with disk systems if you have a lot of them and will get you into trouble. 42 | if [ ! -f ./code.tgz ]; then 43 | if [ -d "code" ]; then 44 | cd code 45 | make clean 46 | cd .. 47 | tar -czvf code.tgz code 48 | rm -r code 49 | fi 50 | fi 51 | fi 52 | ## Remove any file labeled 'core' in the run or output directory. These are core-dumps 53 | ## from certain types of errors on certain machines, only used for debugging. 54 | rm core* 55 | rm output/core* 56 | ## Touch the files to update their access times appropriately 57 | #touch -a * 58 | #touch -a */* 59 | #touch -a */*/* 60 | ## Check that the folder 'output' exists, which this script assumes is where all 61 | ## the simulation outputs are being written (should be set in the parameter file) 62 | if [ -d "output" ] 63 | then 64 | cd output 65 | if [ $done -eq 1 ] 66 | then 67 | ## remove the 'timing' files in output. especially if you are running with extended 68 | ## outputs, these files can be enormous (they are ascii, so poorly-compressed), 69 | ## and written every timestep in some cases. and they contain only information 70 | ## about optimization and timing and code checks, used in-run but not to archive 71 | rm timebin.txt 72 | rm timings.txt 73 | rm balance.txt 74 | rm cpu.txt 75 | rm energy.txt 76 | rm info.txt 77 | ## remove the restartfiles. since this is a complete flash of system memory 78 | ## (with a backup), it can easily be huge (bigger than all the snapshots), 79 | ## but is useless once runs are completed (and cannot be transferred between 80 | ## systems or even slightly different compiled versions of the code. 81 | rm -r restartfiles 82 | ## some of the output files are useful, but can get incredibly large 83 | ## (depending on the details of the simulation), because they are written 84 | ## as ascii with a lot of repeating numbers. this includes all of the 'baryonic' 85 | ## diagnostic files like sfr.txt, HIIheating.txt, blackhole information, etc. 86 | ## (especially the blackhole_details files). these can be zipped to compress 87 | ## them by typical factors of ~100, so we do that here if they exist. 88 | if [ -f "sfr.txt" ] 89 | then 90 | tar -czvf sfr.tgz sfr.txt 91 | rm sfr.txt 92 | fi 93 | if [ -f "HIIheating.txt" ] 94 | then 95 | tar -czvf HIIheating.tgz HIIheating.txt 96 | rm HIIheating.txt 97 | fi 98 | if [ -f "blackholes.txt" ] 99 | then 100 | tar -czvf blackholes.tgz blackholes.txt 101 | rm blackholes.txt 102 | fi 103 | if [ -d "blackhole_details" ] 104 | then 105 | tar -czvf blackhole_details.tgz blackhole_details 106 | rm -r blackhole_details 107 | fi 108 | fi 109 | ## Now we compress the snapshots themselves. This calls a python script, also 110 | ## included in the GIZMO source, which losslessly compresses the hdf5 files 111 | ## for snapshots. This assumes you are writing in hdf5, and assumes that 112 | ## your default output/snapshot name prefix is "snapshot" (and if its is 113 | ## writing multi-component snapshots, the directory prefix for them is 114 | ## "snapdir"). Change those if needed. Make sure the python code is linked 115 | ## and working properly. Again the compression is lossless, this is akin to 116 | ## gzipping the files, but allows you to continue using them like a 'normal' 117 | ## hdf5 file, so its ideal, and typically gives a factor of ~2 compression 118 | ## (though it can be much higher if the data is highly regular). Make sure 119 | ## if you use this that you link the correct location of "compress_gizmosnap", 120 | ## here just assumed to be ${HOME} 121 | #touch -a */*/* 122 | for snapshotname in ./snapshot_*.hdf5 123 | do 124 | python3 ${HOME}/compress_gizmosnap.py $snapshotname 125 | done 126 | for snapshotname in ./snapdir_*/snapshot_*.hdf5 127 | do 128 | python3 ${HOME}/compress_gizmosnap.py $snapshotname 129 | done 130 | cd .. 131 | fi 132 | ## All done! 133 | -------------------------------------------------------------------------------- /structure/subfind/subfind_potential.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "../../allvars.h" 7 | #include "../../proto.h" 8 | #include "../../kernel.h" 9 | /* 10 | * This file was originally part of the GADGET3 code developed by Volker Springel. 11 | * It has been updated significantly by PFH for basic compatibility with GIZMO, 12 | * as well as code cleanups, and accommodating new GIZMO functionality for various 13 | * other operations. See notes in subfind.c and GIZMO User Guide for details. 14 | */ 15 | 16 | #ifdef SUBFIND 17 | 18 | #include "../fof.h" 19 | #include "subfind.h" 20 | 21 | void subfind_potential_compute(int num, struct unbind_data *d, int phase, double weakly_bound_limit) 22 | { 23 | int i, j, k, recvTask, ndone, ndone_flag, dummy, ngrp, place, nexport, nimport; /* allocate buffers to arrange communication */ 24 | All.BunchSize = (long) ((All.BufferSize * 1024 * 1024) / (sizeof(struct data_index) + sizeof(struct data_nodelist) + sizeof(struct gravdata_in) + 25 | sizeof(struct potdata_out) + sizemax(sizeof(struct gravdata_in), sizeof(struct potdata_out)))); 26 | DataIndexTable = (struct data_index *) mymalloc("DataIndexTable", All.BunchSize * sizeof(struct data_index)); 27 | DataNodeList = (struct data_nodelist *) mymalloc("DataNodeList", All.BunchSize * sizeof(struct data_nodelist)); 28 | 29 | i = 0; /* begin with this index */ 30 | do 31 | { 32 | for(j = 0; j < NTask; j++) {Send_count[j] = 0; Exportflag[j] = -1;} 33 | /* do local particles and prepare export list */ 34 | for(nexport = 0; i < num; i++) 35 | { 36 | if(phase == 1) {if(P[d[i].index].v.DM_BindingEnergy <= weakly_bound_limit) {continue;}} 37 | if(subfind_force_treeevaluate_potential(d[i].index, 0, &nexport, Send_count) < 0) {break;} 38 | } 39 | qsort(DataIndexTable, nexport, sizeof(struct data_index), data_index_compare); 40 | MPI_Alltoall(Send_count, 1, MPI_INT, Recv_count, 1, MPI_INT, MPI_COMM_WORLD); 41 | for(j = 0, nimport = 0, Recv_offset[0] = 0, Send_offset[0] = 0; j < NTask; j++) 42 | { 43 | nimport += Recv_count[j]; 44 | if(j > 0) 45 | { 46 | Send_offset[j] = Send_offset[j - 1] + Send_count[j - 1]; 47 | Recv_offset[j] = Recv_offset[j - 1] + Recv_count[j - 1]; 48 | } 49 | } 50 | GravDataGet = (struct gravdata_in *) mymalloc("GravDataGet", nimport * sizeof(struct gravdata_in)); 51 | GravDataIn = (struct gravdata_in *) mymalloc("GravDataIn", nexport * sizeof(struct gravdata_in)); 52 | 53 | /* prepare particle data for export */ 54 | for(j = 0; j < nexport; j++) 55 | { 56 | place = DataIndexTable[j].Index; 57 | for(k = 0; k < 3; k++) {GravDataIn[j].Pos[k] = P[place].Pos[k];} 58 | for(k = 0; k < NODELISTLENGTH; k++) {GravDataIn[j].NodeList[k] = DataNodeList[DataIndexTable[j].IndexGet].NodeList[k];} 59 | } 60 | /* exchange particle data */ 61 | for(ngrp = 1; ngrp < (1 << PTask); ngrp++) 62 | { 63 | recvTask = ThisTask ^ ngrp; 64 | if(recvTask < NTask) 65 | { 66 | if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) 67 | { /* get the particles */ 68 | MPI_Sendrecv(&GravDataIn[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct gravdata_in), MPI_BYTE, recvTask, TAG_POTENTIAL_A, 69 | &GravDataGet[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct gravdata_in), MPI_BYTE, recvTask, TAG_POTENTIAL_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); 70 | } 71 | } 72 | } 73 | myfree(GravDataIn); 74 | PotDataResult = (struct potdata_out *) mymalloc("PotDataResult", nimport * sizeof(struct potdata_out)); 75 | PotDataOut = (struct potdata_out *) mymalloc("PotDataOut", nexport * sizeof(struct potdata_out)); 76 | 77 | /* now do the particles that were sent to us */ 78 | for(j = 0; j < nimport; j++) {subfind_force_treeevaluate_potential(j, 1, &dummy, &dummy);} 79 | if(i >= num) {ndone_flag = 1;} else {ndone_flag = 0;} 80 | MPI_Allreduce(&ndone_flag, &ndone, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); 81 | /* get the result */ 82 | for(ngrp = 1; ngrp < (1 << PTask); ngrp++) 83 | { 84 | recvTask = ThisTask ^ ngrp; 85 | if(recvTask < NTask) 86 | { 87 | if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) 88 | { /* send the results */ 89 | MPI_Sendrecv(&PotDataResult[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct potdata_out), MPI_BYTE, recvTask, TAG_POTENTIAL_B, 90 | &PotDataOut[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct potdata_out), MPI_BYTE, recvTask, TAG_POTENTIAL_B, MPI_COMM_WORLD, MPI_STATUS_IGNORE); 91 | } 92 | } 93 | 94 | } 95 | /* add the results to the local particles */ 96 | for(j = 0; j < nexport; j++) 97 | { 98 | place = DataIndexTable[j].Index; 99 | P[place].u.DM_Potential += PotDataOut[j].Potential; 100 | } 101 | myfree(PotDataOut); 102 | myfree(PotDataResult); 103 | myfree(GravDataGet); 104 | } 105 | while(ndone < NTask); 106 | 107 | for(i = 0; i < num; i++) 108 | { 109 | if(phase == 1) {if(P[d[i].index].v.DM_BindingEnergy <= weakly_bound_limit) {continue;}} 110 | int p = d[i].index; double h_grav = ForceSoftening_KernelRadius(p); 111 | P[p].u.DM_Potential -= P[p].Mass / h_grav * kernel_gravity(0,1,1,-1); // subtract self-contribution here 112 | P[p].u.DM_Potential *= All.G / All.cf_atime; 113 | if(All.TotN_gas > 0 && (FOF_SECONDARY_LINK_TYPES & 1) == 0 && (FOF_PRIMARY_LINK_TYPES & 1) == 0 && All.OmegaBaryon > 0) {P[p].u.DM_Potential *= All.OmegaMatter / (All.OmegaMatter - All.OmegaBaryon);} 114 | } 115 | myfree(DataNodeList); 116 | myfree(DataIndexTable); 117 | } 118 | 119 | #endif 120 | 121 | -------------------------------------------------------------------------------- /cooling/chimes/chimes_vars.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * This file is part of CHIMES. 3 | * Copyright (c) 2020 Alexander Richings (alexander.j.richings@durham.ac.uk) 4 | * 5 | * CHIMES is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published 7 | * by the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***************************************************************************/ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "chimes_interpol.h" 26 | 27 | 28 | #ifdef CHIMES 29 | 30 | 31 | /* Define CHIMES-specific maths operations, depending 32 | * on whether we are using single or double precision. 33 | * Also, the chimes_exp10() function may use the 34 | * exp10() or exp10f() function if the GNU extensions 35 | * are enabled, otherwise we will need to use our 36 | * own definition. */ 37 | #ifdef CHIMES_USE_DOUBLE_PRECISION 38 | #define CHIMES_FLT_MIN DBL_MIN 39 | 40 | #ifdef CHIMES_ENABLE_GNU_SOURCE 41 | __attribute__((always_inline, const)) inline static double chimes_exp10(const double x) 42 | { 43 | return exp10(x); 44 | } 45 | #else // CHIMES_ENABLE_GNU_SOURCE 46 | __attribute__((always_inline, const)) inline static double chimes_exp10(const double x) 47 | { 48 | return exp(x * M_LN10); 49 | } 50 | #endif // CHIMES_ENABLE_GNU_SOURCE 51 | 52 | __attribute__((always_inline, const)) inline static double chimes_exp(const double x) 53 | { 54 | return exp(x); 55 | } 56 | 57 | __attribute__((always_inline, const)) inline static double chimes_pow(const double x, const double y) 58 | { 59 | return pow(x, y); 60 | } 61 | 62 | __attribute__((always_inline, const)) inline static double chimes_log10(const double x) 63 | { 64 | return log10(x); 65 | } 66 | 67 | __attribute__((always_inline, const)) inline static double chimes_log(const double x) 68 | { 69 | return log(x); 70 | } 71 | 72 | __attribute__((always_inline, const)) inline static double chimes_sqrt(const double x) 73 | { 74 | return sqrt(x); 75 | } 76 | #else // CHIMES_USE_DOUBLE_PRECISION 77 | #define CHIMES_FLT_MIN FLT_MIN 78 | 79 | #ifdef CHIMES_ENABLE_GNU_SOURCE 80 | __attribute__((always_inline, const)) inline static float chimes_exp10(const float x) 81 | { 82 | return exp10f(x); 83 | } 84 | #else // CHIMES_ENABLE_GNU_SOURCE 85 | __attribute__((always_inline, const)) inline static float chimes_exp10(const float x) 86 | { 87 | return expf(x * (float) M_LN10); 88 | } 89 | #endif // CHIMES_ENABLE_GNU_SOURCE 90 | 91 | __attribute__((always_inline, const)) inline static float chimes_exp(const float x) 92 | { 93 | return expf(x); 94 | } 95 | 96 | __attribute__((always_inline, const)) inline static float chimes_pow(const float x, const float y) 97 | { 98 | return powf(x, y); 99 | } 100 | 101 | __attribute__((always_inline, const)) inline static float chimes_log10(const float x) 102 | { 103 | return log10f(x); 104 | } 105 | 106 | __attribute__((always_inline, const)) inline static float chimes_log(const float x) 107 | { 108 | return logf(x); 109 | } 110 | 111 | __attribute__((always_inline, const)) inline static float chimes_sqrt(const float x) 112 | { 113 | return sqrtf(x); 114 | } 115 | #endif // CHIMES_USE_DOUBLE_PRECISION 116 | 117 | /* In some cases, we need an exp10() function 118 | * that is always in double precision, even 119 | * when we are running the rest of CHIMES 120 | * in single precision. This is used in the 121 | * photoheating shielding functions. */ 122 | #ifdef CHIMES_ENABLE_GNU_SOURCE 123 | __attribute__((always_inline, const)) inline static double chimes_exp10_dbl(const double x) 124 | { 125 | return exp10(x); 126 | } 127 | #else 128 | __attribute__((always_inline, const)) inline static double chimes_exp10_dbl(const double x) 129 | { 130 | return exp(x * M_LN10); 131 | } 132 | #endif 133 | 134 | /*!< Electron mass. Units: g. */ 135 | #define ELECTRON_MASS 9.10938356e-28f 136 | 137 | /*!< Proton mass. Units: g. */ 138 | #define PROTON_MASS 1.672621898e-24f 139 | 140 | /*!< Pi. */ 141 | #define PI 3.1415927f 142 | 143 | /*!< Euler's constant. */ 144 | #define EULERS_CONST 2.718281828459f 145 | 146 | /*!< Speed of light. Units: cm / s. */ 147 | #define LIGHTSPEED 2.99792458e10f 148 | 149 | /*!< Boltzmann constant. Units: erg / K. */ 150 | #define BOLTZMANNCGS 1.38064852e-16f 151 | 152 | /*!< Boltzmann constant. Units: eV / K. */ 153 | #define BOLTZMANN_EVK 8.61733105e-5f 154 | 155 | /*!< For dust processes involving G0, e.g. photoelectric heating, we attenuate G0 by exp(- G0_gamma * Av). */ 156 | #define G0_GAMMA 2.77f 157 | 158 | /*!< Effective dust absorption and scattering cross section, to calculate Av from N_Htot. Units: cm^2 / H atom. */ 159 | #define DUSTEFFSIZE 4.0e-22f 160 | 161 | /*!< Dust surface area for H2 formation. Units: cm^2 / H atom. */ 162 | #define DUST_CROSS_SECTION 1.0e-21f 163 | 164 | /*!< All reaction and cooling rates are limited to this maximum temperature. */ 165 | #define MAX_TEMPERATURE_FOR_RATES 2.0e9f 166 | 167 | /*!< Exclude species when their corresponding element abundance is below this threshold. */ 168 | #define METALS_MINIMUM_THRESHOLD 1.0e-30f 169 | 170 | /*!< The maximum number of steps in the CVODE solver. */ 171 | #define MAXSTEPS 1e5 172 | 173 | /** 174 | * Structure containing information 175 | * about each non-equilibrium species 176 | */ 177 | struct Species_Structure 178 | { 179 | int include_species; /*!< Flag indicating whether the species is included in the network. */ 180 | ChimesFloat element_abundance; /*!< Abundance of the corresponding element. */ 181 | ChimesFloat creation_rate; /*!< Sum of the rates of all reactions that create this species. */ 182 | ChimesFloat destruction_rate; /*!< Sum of the rates of all reactions that destroy this species. */ 183 | }; 184 | 185 | 186 | 187 | #endif 188 | 189 | -------------------------------------------------------------------------------- /system/bracketed_rootfind.h: -------------------------------------------------------------------------------- 1 | /* 2 | Code block containing a Brent 1973 rootfind routine, guaranteed to find the root 3 | provided upper and lower bounds for a continuous function 4 | 5 | Required initializations outside this block: 6 | ROOTFIND_FUNCTION(x) - #define'd macro that evaluates a function of a single 7 | variable whose root we wish to find 8 | ROOTFIND_X_a, ROOTFIND_X_b - Arguments to ROOTFIND_FUNCTION that are known 9 | to bracket the root. 10 | ROOTFUNC_a, ROOTFUNC_b - values of the function evaluated at the bracket 11 | points ROOTFIND_REL_X_tol - Tolerance for desired relative error in the root; 12 | stop iterating when this is achieved ROOTFIND_ABS_X_tol - Tolerance for desired 13 | absolute error in the root; stop iterating when this is achieved 14 | */ 15 | 16 | // if doing nested rootfinds, need to def a different inner function because 17 | // ROOTFIND_FUNCTION has not yet been undef'd 18 | #ifdef ROOTFIND_FUNCTION_INNER 19 | #define ROOTFUNC ROOTFIND_FUNCTION_INNER 20 | #else 21 | #define ROOTFUNC ROOTFIND_FUNCTION 22 | #endif 23 | 24 | if (ROOTFUNC_a * ROOTFUNC_b > 0) { 25 | PRINT_WARNING("ERROR: Bounds supplied to bracketed_roofind.h block do not bracket " 26 | "the root. x_a=%g x_b=%g f_a=%g f_b=%g Expanding region...", 27 | ROOTFIND_X_a, ROOTFIND_X_b, ROOTFUNC_a, ROOTFUNC_b); 28 | double bracket_fac = 1.1; 29 | int bracket_iter = 0; 30 | do { 31 | double tmp = ROOTFIND_X_a; // let a be the lower value 32 | ROOTFIND_X_a = DMIN(ROOTFIND_X_a, ROOTFIND_X_b) / bracket_fac; 33 | ROOTFIND_X_b = DMAX(tmp, ROOTFIND_X_b) * bracket_fac; 34 | ROOTFUNC_a = ROOTFUNC(ROOTFIND_X_a); 35 | ROOTFUNC_b = ROOTFUNC(ROOTFIND_X_b); 36 | bracket_iter++; 37 | } while (ROOTFUNC_a * ROOTFUNC_b > 0 && bracket_iter < MAXITER); 38 | if ((bracket_iter == MAXITER) || isnan(ROOTFUNC_a) || isnan(ROOTFUNC_b)) { 39 | PRINT_WARNING("ERROR: Could not bracket root. x_a=%g x_b=%g f_a=%g f_b=%g\n", ROOTFIND_X_a, ROOTFIND_X_b, ROOTFUNC_a, ROOTFUNC_b); 40 | endrun(234528); 41 | } 42 | } 43 | 44 | if (fabs(ROOTFUNC_a) < fabs(ROOTFUNC_b)) { // in our convention 'a' represents 45 | // the bracket with the larger 46 | // residual 47 | double tmp = ROOTFUNC_a; 48 | ROOTFUNC_a = ROOTFUNC_b; 49 | ROOTFUNC_b = tmp; 50 | tmp = ROOTFIND_X_a; 51 | ROOTFIND_X_a = ROOTFIND_X_b; 52 | ROOTFIND_X_b = tmp; 53 | } 54 | 55 | double ROOTFIND_X_c = ROOTFIND_X_a, ROOTFUNC_c = ROOTFUNC_a; 56 | int USED_BISECTION = 1, DO_BISECTION = 0, ROOTFIND_ITER = 0; 57 | double ROOTFIND_X_c_old = ROOTFIND_X_c, ROOTFIND_X_new, ROOTFUNC_new = ROOTFUNC_c, ROOTFIND_X_error = 1e100, DELTA_TOL = 0.; 58 | 59 | /* now we do a Brent 1973 method root-find */ 60 | do { 61 | ROOTFIND_X_new = 0; 62 | if ((ROOTFUNC_a != ROOTFUNC_c) && (ROOTFUNC_b != ROOTFUNC_c)) { // inverse quadratic interpolation 63 | ROOTFIND_X_new += ROOTFIND_X_a * ROOTFUNC_c * ROOTFUNC_b / (ROOTFUNC_a - ROOTFUNC_b) / (ROOTFUNC_a - ROOTFUNC_c); 64 | ROOTFIND_X_new += ROOTFIND_X_b * ROOTFUNC_c * ROOTFUNC_a / (ROOTFUNC_b - ROOTFUNC_a) / (ROOTFUNC_b - ROOTFUNC_c); 65 | ROOTFIND_X_new += ROOTFIND_X_c * ROOTFUNC_a * ROOTFUNC_b / (ROOTFUNC_c - ROOTFUNC_a) / (ROOTFUNC_c - ROOTFUNC_b); 66 | } else { // secant method 67 | ROOTFIND_X_new = (ROOTFIND_X_a * ROOTFUNC_b - ROOTFIND_X_b * ROOTFUNC_a) / (ROOTFUNC_b - ROOTFUNC_a); 68 | } 69 | DELTA_TOL = DMAX(fabs(ROOTFIND_ABS_X_tol), ROOTFIND_REL_X_tol * fabs(ROOTFIND_X_new)); // new absolute tolerance, incorporating relative tolerance 70 | 71 | DO_BISECTION = 0; 72 | double ROOTFIND_X_midpoint_a = 0.25 * (3 * ROOTFIND_X_a + ROOTFIND_X_b); 73 | if ((ROOTFIND_X_new < DMIN(ROOTFIND_X_midpoint_a, ROOTFIND_X_b)) || (ROOTFIND_X_new > DMAX(ROOTFIND_X_midpoint_a, ROOTFIND_X_b))) { 74 | DO_BISECTION = 1; 75 | } else { // accept the interpolation and bug out if it looks converged 76 | if (fabs(ROOTFIND_X_new - ROOTFIND_X_b) < DELTA_TOL) { 77 | break; 78 | } 79 | } 80 | if (USED_BISECTION) { 81 | if (fabs(ROOTFIND_X_new - ROOTFIND_X_b) >= 0.5 * fabs(ROOTFIND_X_c - ROOTFIND_X_b)) { 82 | DO_BISECTION = 1; 83 | } 84 | if (ROOTFIND_X_b != ROOTFIND_X_c) { 85 | if (fabs(ROOTFIND_X_b - ROOTFIND_X_c) < DELTA_TOL) { 86 | DO_BISECTION = 1; 87 | } 88 | } 89 | } else { 90 | if (fabs(ROOTFIND_X_new - ROOTFIND_X_b) >= 0.5 * fabs(ROOTFIND_X_c_old - ROOTFIND_X_c)) { 91 | DO_BISECTION = 1; 92 | } 93 | if (ROOTFIND_X_c_old != ROOTFIND_X_c) { 94 | if (fabs(ROOTFIND_X_c_old - ROOTFIND_X_c) < DELTA_TOL) { 95 | DO_BISECTION = 1; 96 | } 97 | } 98 | } 99 | if (DO_BISECTION) { 100 | // bisection in log space can help convergence for typical use cases; do 101 | // this if possible 102 | if ((ROOTFIND_X_b > 0) && (ROOTFIND_X_a > 0)) { 103 | ROOTFIND_X_new = sqrt(ROOTFIND_X_b * ROOTFIND_X_a); 104 | } else { 105 | ROOTFIND_X_new = 0.5 * (ROOTFIND_X_b + ROOTFIND_X_a); 106 | } 107 | USED_BISECTION = 1; 108 | } // bisection 109 | else { 110 | USED_BISECTION = 0; 111 | } 112 | ROOTFUNC_new = ROOTFUNC(ROOTFIND_X_new); 113 | if (ROOTFUNC_new == 0) { 114 | break; 115 | } 116 | 117 | ROOTFIND_X_c_old = ROOTFIND_X_c; 118 | ROOTFIND_X_c = ROOTFIND_X_b; 119 | ROOTFUNC_c = ROOTFUNC_b; 120 | if (ROOTFUNC_a * ROOTFUNC_new < 0) { 121 | ROOTFIND_X_b = ROOTFIND_X_new; 122 | ROOTFUNC_b = ROOTFUNC_new; 123 | } else { 124 | ROOTFIND_X_a = ROOTFIND_X_new; 125 | ROOTFUNC_a = ROOTFUNC_new; 126 | } 127 | 128 | if (fabs(ROOTFUNC_a) < fabs(ROOTFUNC_b)) { 129 | double tmp = ROOTFUNC_a; 130 | ROOTFUNC_a = ROOTFUNC_b; 131 | ROOTFUNC_b = tmp; 132 | tmp = ROOTFIND_X_a; 133 | ROOTFIND_X_a = ROOTFIND_X_b; 134 | ROOTFIND_X_b = tmp; 135 | } 136 | ROOTFIND_X_error = fabs(ROOTFIND_X_b - ROOTFIND_X_a); 137 | ROOTFIND_ITER++; 138 | if (ROOTFIND_ITER > MAXITER) { 139 | break; 140 | } 141 | } while (ROOTFIND_X_error > DELTA_TOL); 142 | 143 | #undef ROOTFUNC 144 | 145 | #ifdef ROOTFIND_FUNCTION_INNER 146 | #undef ROOTFIND_FUNCTION_INNER 147 | #else 148 | #undef ROOTFIND_FUNCTION 149 | #endif 150 | -------------------------------------------------------------------------------- /sidm/dm_fuzzy_flux_computation.h: -------------------------------------------------------------------------------- 1 | /* quantum pressure-tensor computation to calculate the relevant fluxes between faces of particles, within the gravity routine */ 2 | #ifdef DM_FUZZY 3 | 4 | #define DM_FUZZY_USE_SIMPLER_HLL_SOLVER 0 /* determines which solver will be used for DM_FUZZY=0; =1 is the newer, simpler, but more diffusive solver */ 5 | 6 | 7 | if((local.Type==1) && (P[j].Type==1)) // only acts between DM particles of type 1 (can easily change if desired) 8 | { 9 | /* since this isn't a super-expensive calculation, and we need to walk the gravity tree for both 'sides' anyways, we will effectively do this twice each timestep */ 10 | double V_i=local.V_i, V_j=get_particle_volume_ags(j), wt_i=V_i, wt_j=V_j, Face_Area_Vec[3], Face_Area_Norm=0, vface_i_minus_j=0, dv[3]; // calculate densities (in physical units) 11 | // calculate effective faces and face velocity between elements // 12 | if((fabs(V_i-V_j)/DMIN(V_i,V_j))/NUMDIMS > 1.25) {wt_i=wt_j=2.*V_i*V_j/(V_i+V_j);} else {wt_i=V_i; wt_j=V_j;} // limiter to prevent faces from going geometrically crazy in disparate limits 13 | for(k=0;k<3;k++) 14 | { 15 | Face_Area_Vec[k] = (kernel.wk_i*wt_i * (local.NV_T[k][0]*kernel.dp[0] + local.NV_T[k][1]*kernel.dp[1] + local.NV_T[k][2]*kernel.dp[2]) + 16 | kernel.wk_j*wt_j * (P[j].NV_T[k][0]*kernel.dp[0] + P[j].NV_T[k][1]*kernel.dp[1] + P[j].NV_T[k][2]*kernel.dp[2])) * All.cf_atime*All.cf_atime; // physical units 17 | Face_Area_Norm += Face_Area_Vec[k]*Face_Area_Vec[k]; // physical units 18 | dv[k] = kernel.dv[k] / All.cf_atime; // physical units: dp and dv = local - j = R - L, always // 19 | vface_i_minus_j += dv[k] * Face_Area_Vec[k]; // physical units 20 | } 21 | Face_Area_Norm = sqrt(Face_Area_Norm); vface_i_minus_j /= Face_Area_Norm; 22 | // convert everything needed below into physical units // 23 | double igrad[3], jgrad[3], i2grad[3][3], j2grad[3][3], fac_g = All.cf_a3inv/All.cf_atime, fac_g2 = All.cf_a3inv*All.cf_a2inv, dp[3]; int m; 24 | for(k=0;k<3;k++) 25 | { 26 | dp[k] = kernel.dp[k] * All.cf_atime; 27 | igrad[k] = fac_g * local.AGS_Gradients_Density[k]; 28 | jgrad[k] = fac_g * P[j].AGS_Gradients_Density[k]; 29 | for(m=0;m<3;m++) 30 | { 31 | i2grad[k][m] = fac_g2 * local.AGS_Gradients2_Density[k][m]; 32 | j2grad[k][m] = fac_g2 * P[j].AGS_Gradients2_Density[k][m]; 33 | } 34 | } 35 | 36 | #if (DM_FUZZY == 0) 37 | double prev_acc = All.G*All.cf_a2inv * P[j].Mass * P[j].OldAcc, flux[3]={0}, dt_egy_Numerical_QuantumPotential=0, m_mean = 0.5*(local.Mass+P[j].Mass), rho_i=local.Mass/V_i*All.cf_a3inv, rho_j=P[j].Mass/V_j*All.cf_a3inv, dt = local.dtime, AGS_Numerical_QuantumPotential = 0.5*(local.AGS_Numerical_QuantumPotential/V_i + P[j].AGS_Numerical_QuantumPotential/V_j)*All.cf_a3inv; 38 | double HLLwt = (0.5*(kernel.wk_i/kernel.hinv3_i + kernel.wk_j/kernel.hinv3_j)) * (0.5*(kernel.h_i+kernel.h_j)/kernel.r); HLLwt = 10.*HLLwt*HLLwt; // strong dissipation terms allowed for very-close particles, where second-derivative diverges, otherwise weak (no diffusion) // 39 | // actually compute the fluxes now, this is the key routine, below // 40 | 41 | #if (DM_FUZZY_USE_SIMPLER_HLL_SOLVER == 0) 42 | do_dm_fuzzy_flux_computation_old(HLLwt, dt, m_mean, prev_acc, dp, dv, jgrad, igrad, j2grad, i2grad, rho_j, rho_i, vface_i_minus_j, Face_Area_Vec, flux, AGS_Numerical_QuantumPotential, &dt_egy_Numerical_QuantumPotential); 43 | #else 44 | do_dm_fuzzy_flux_computation(HLLwt, dt, prev_acc, dv, jgrad, igrad, j2grad, i2grad, rho_j, rho_i, vface_i_minus_j, Face_Area_Vec, flux, P[j].AGS_Numerical_QuantumPotential/V_j*All.cf_a3inv, local.AGS_Numerical_QuantumPotential/V_i*All.cf_a3inv, &dt_egy_Numerical_QuantumPotential); 45 | #endif 46 | out.AGS_Dt_Numerical_QuantumPotential += dt_egy_Numerical_QuantumPotential; for(k=0;k<3;k++) {out.acc[k] += flux[k] / (local.Mass * All.cf_a2inv);} // assign back to particles 47 | 48 | #else 49 | 50 | double h_2m = 0.5*All.ScalarField_hbar_over_mass; 51 | double Psi_Re_R, Psi_Re_L, d_Psi_Re_R[3], d_Psi_Re_L[3], v_face[3], 52 | Psi_Im_R, Psi_Im_L, d_Psi_Im_R[3], d_Psi_Im_L[3], Flux_Re=0, Flux_Im=0, Flux_M=0; 53 | 54 | for(k=0;k<3;k++) {v_face[k] = 0.5*(local.Vel[k]+P[j].Vel[k]) / All.cf_atime;} 55 | 56 | dm_fuzzy_reconstruct_and_slopelimit(&Psi_Re_R, d_Psi_Re_R, &Psi_Re_L, d_Psi_Re_L, 57 | local.AGS_Psi_Re, local.AGS_Gradients_Psi_Re, local.AGS_Gradients2_Psi_Re, 58 | P[j].AGS_Psi_Re_Pred * P[j].AGS_Density / P[j].Mass, 59 | P[j].AGS_Gradients_Psi_Re, P[j].AGS_Gradients2_Psi_Re, dp); 60 | 61 | dm_fuzzy_reconstruct_and_slopelimit(&Psi_Im_R, d_Psi_Im_R, &Psi_Im_L, d_Psi_Im_L, 62 | local.AGS_Psi_Im, local.AGS_Gradients_Psi_Im, local.AGS_Gradients2_Psi_Im, 63 | P[j].AGS_Psi_Im_Pred * P[j].AGS_Density / P[j].Mass, 64 | P[j].AGS_Gradients_Psi_Im, P[j].AGS_Gradients2_Psi_Im, dp); 65 | 66 | double psi2_L = Psi_Re_L*Psi_Re_L + Psi_Im_L*Psi_Im_L, psi2_R = Psi_Re_R*Psi_Re_R + Psi_Im_R*Psi_Im_R; 67 | /* 68 | double Adotv = 0; for(k=0;k<3;k++) {Adotv += Face_Area_Vec[k]*v_face[k];} 69 | double AdotDp_Re_R=0; for(k=0;k<3;k++) {AdotDp_Re_R += Face_Area_Vec[k]*d_Psi_Re_R[k];} 70 | double AdotDp_Re_L=0; for(k=0;k<3;k++) {AdotDp_Re_L += Face_Area_Vec[k]*d_Psi_Re_L[k];} 71 | double AdotDp_Im_R=0; for(k=0;k<3;k++) {AdotDp_Im_R += Face_Area_Vec[k]*d_Psi_Im_R[k];} 72 | double AdotDp_Im_L=0; for(k=0;k<3;k++) {AdotDp_Im_L += Face_Area_Vec[k]*d_Psi_Im_L[k];} 73 | */ 74 | 75 | for(k=0;k<3;k++) 76 | { 77 | Flux_Re += 0.5 * Face_Area_Vec[k] * ( -h_2m*(d_Psi_Im_R[k]+d_Psi_Im_L[k]) + v_face[k]*(Psi_Re_R+Psi_Re_L) ); 78 | Flux_Im += 0.5 * Face_Area_Vec[k] * ( h_2m*(d_Psi_Re_R[k]+d_Psi_Re_L[k]) + v_face[k]*(Psi_Im_R+Psi_Im_L) ); 79 | Flux_M += 0.5 * Face_Area_Vec[k] * ( 2.*h_2m * (Psi_Im_R * d_Psi_Re_R[k] - Psi_Re_R * d_Psi_Im_R[k] + 80 | Psi_Im_L * d_Psi_Re_L[k] - Psi_Re_L * d_Psi_Im_L[k]) 81 | + v_face[k]*(psi2_L + psi2_R) ); 82 | } 83 | double k_eff = 0.3 / kernel.r, cs_eff = 0.5 * h_2m * k_eff, prefac = 0.5 * Face_Area_Norm * cs_eff; 84 | Flux_Re += prefac * (Psi_Re_R-Psi_Re_L); 85 | Flux_Im += prefac * (Psi_Im_R-Psi_Im_L); 86 | Flux_M += prefac * (psi2_R - psi2_L); 87 | 88 | 89 | out.AGS_Dt_Psi_Re += Flux_Re; 90 | out.AGS_Dt_Psi_Im += Flux_Im; 91 | out.AGS_Dt_Psi_Mass += Flux_M; 92 | #endif 93 | 94 | } // total bracket (for variable protection) 95 | #endif 96 | 97 | 98 | -------------------------------------------------------------------------------- /eos/eos_interface.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef _OPENMP 9 | #include 10 | #endif 11 | 12 | #include "eos.h" 13 | #include "../allvars.h" 14 | 15 | #ifdef EOS_HELMHOLTZ 16 | #include "helmholtz/helm_wrap.h" 17 | #endif 18 | 19 | #define BITMASK_SET_FLAG(BITMASK,FLAG) (BITMASK) |= (FLAG) 20 | #define BITMASK_SET_ALL_FLAGS(BITMASK) (BITMASK = ~(0)) 21 | #define BITMASK_UNSET_FLAG(BITMASK,FLAG) (BITMASK) &= ~(FLAG) 22 | #define BITMASK_UNSET_ALL_FLAGS(BITMASK) (BITMASK) = 0 23 | #define BITMASK_CHECK_FLAG(BITMASK,FLAG) (((BITMASK) & (FLAG)) == (FLAG)) 24 | 25 | #define EOS_ERR_VALID 0 26 | #define EOS_ERR_RHO_LT_RHOMIN 1 27 | #define EOS_ERR_RHO_GT_RHOMAX 2 28 | #define EOS_ERR_EPS_LT_EPSMIN 4 29 | #define EOS_ERR_EPS_GT_EPSMAX 8 30 | #define EOS_ERR_COMPOSITION 16 31 | 32 | static int eos_input_to_cgs(struct eos_input * vars); 33 | static int eos_output_from_cgs(struct eos_output * vars); 34 | 35 | static int eos_validate(struct eos_input const * vars, struct eos_input * vars_adj, int * bitmask); 36 | static int eos_compute_from_valid(struct eos_input const * in, struct eos_output * out); 37 | 38 | #ifdef EOS_TABULATED 39 | int eos_init(char const * eos_table_fname) 40 | { 41 | if(access(eos_table_fname, R_OK) != 0) 42 | { 43 | fprintf(stderr, "Could not read \"%s\"\n", eos_table_fname); 44 | return 1; 45 | } 46 | #ifdef EOS_HELMHOLTZ 47 | helm_read_table_c(eos_table_fname); 48 | #endif 49 | return 0; 50 | } 51 | 52 | int eos_cleanup() 53 | { 54 | return 0; 55 | } 56 | #endif 57 | 58 | int eos_compute(struct eos_input const * in_, struct eos_output * out_) 59 | { 60 | struct eos_input in, in_adj; 61 | memcpy(&in, in_, sizeof(in)); 62 | #ifdef EOS_USES_CGS 63 | eos_input_to_cgs(&in); 64 | #endif 65 | 66 | int bitmask = 0; 67 | int ierr = eos_validate(&in, &in_adj, &bitmask); 68 | assert(!ierr); 69 | if(bitmask != EOS_ERR_VALID) 70 | { 71 | fprintf(stderr, "EOS ERROR:"); 72 | if(BITMASK_CHECK_FLAG(bitmask, EOS_ERR_COMPOSITION)) 73 | fprintf(stderr, "/invalid composition"); 74 | if(BITMASK_CHECK_FLAG(bitmask, EOS_ERR_RHO_LT_RHOMIN)) 75 | fprintf(stderr, "/density too low"); 76 | if(BITMASK_CHECK_FLAG(bitmask, EOS_ERR_RHO_GT_RHOMAX)) 77 | fprintf(stderr, "/density too large"); 78 | if(BITMASK_CHECK_FLAG(bitmask, EOS_ERR_EPS_LT_EPSMIN)) 79 | fprintf(stderr, "/temperature too low"); 80 | if(BITMASK_CHECK_FLAG(bitmask, EOS_ERR_EPS_GT_EPSMAX)) 81 | fprintf(stderr, "/temperature too high"); 82 | fprintf(stderr, "\n"); 83 | 84 | #ifdef EOS_USES_CGS 85 | char const * unit_dens = "g/cm^3"; 86 | char const * unit_ene = "erg/g"; 87 | #else 88 | char const * unit_dens = ""; 89 | char const * unit_ene = ""; 90 | #endif 91 | 92 | fprintf(stderr, " rho = %.19e %s\n", in.rho, unit_dens); 93 | fprintf(stderr, " eps = %.19e %s\n", in.eps, unit_ene); 94 | #ifdef EOS_CARRIES_YE 95 | fprintf(stderr, " Ye = %.19e\n", in.Ye); 96 | #endif 97 | #ifdef EOS_CARRIES_ABAR 98 | fprintf(stderr, " Abar = %.19e\n", in.Abar); 99 | #endif 100 | fprintf(stderr, "Using 0th order extrapolation\n"); 101 | memcpy(&in, &in_adj, sizeof(in)); 102 | } 103 | struct eos_output out; 104 | ierr = eos_compute_from_valid(&in, &out); 105 | assert(!ierr); 106 | #ifdef EOS_USES_CGS 107 | ierr = eos_output_from_cgs(&out); 108 | assert(!ierr); 109 | #endif 110 | memcpy(out_, &out, sizeof(out)); 111 | 112 | return 0; 113 | } 114 | 115 | static int eos_input_to_cgs(struct eos_input * vars) 116 | { 117 | vars->rho *= UNIT_DENSITY_IN_CGS; 118 | vars->eps *= UNIT_SPECEGY_IN_CGS; 119 | return 0; 120 | } 121 | 122 | static int eos_output_from_cgs(struct eos_output * vars) 123 | { 124 | vars->press /= UNIT_PRESSURE_IN_CGS; 125 | vars->csound /= UNIT_VEL_IN_CGS; 126 | return 0; 127 | } 128 | 129 | static int eos_validate(struct eos_input const * vars, struct eos_input * vars_adj, int * bitmask) 130 | { 131 | *bitmask = EOS_ERR_VALID; 132 | memcpy(vars_adj, vars, sizeof(*vars)); 133 | 134 | #ifdef EOS_HELMHOLTZ 135 | if(vars->Ye < 0) 136 | { 137 | BITMASK_SET_FLAG(*bitmask, EOS_ERR_COMPOSITION); 138 | vars_adj->Ye = 0; 139 | } 140 | if(vars->Ye > 1) 141 | { 142 | BITMASK_SET_FLAG(*bitmask, EOS_ERR_COMPOSITION); 143 | vars_adj->Ye = 1; 144 | } 145 | if(vars->Abar < 1) 146 | { 147 | BITMASK_SET_FLAG(*bitmask, EOS_ERR_COMPOSITION); 148 | vars_adj->Abar = 1; 149 | } 150 | 151 | double rho_ye_min, rho_ye_max; 152 | helm_range_rho_ye_c(&rho_ye_min, &rho_ye_max); 153 | if(vars->rho * vars_adj->Ye < rho_ye_min) 154 | { 155 | BITMASK_SET_FLAG(*bitmask, EOS_ERR_RHO_LT_RHOMIN); 156 | vars_adj->rho = rho_ye_min / vars_adj->Ye; 157 | } 158 | if(vars->rho * vars_adj->Ye > rho_ye_max) 159 | { 160 | BITMASK_SET_FLAG(*bitmask, EOS_ERR_RHO_GT_RHOMAX); 161 | vars_adj->rho = rho_ye_max / vars_adj->Ye; 162 | } 163 | 164 | #ifdef _OPENMP 165 | int rank = omp_get_thread_num(); 166 | #else 167 | int rank = 0; 168 | #endif 169 | int fail; 170 | double eps_min, eps_max; 171 | helm_range_eps_c(&rank, &vars_adj->rho, &vars_adj->Abar, &vars_adj->Ye, &eps_min, 172 | &eps_max, &fail); 173 | if(fail) 174 | { 175 | fprintf(stderr, "%s:%d unexpected EOS failure!\n", __FILE__, __LINE__); 176 | return 1; 177 | } 178 | if(vars->eps < eps_min) 179 | { 180 | BITMASK_SET_FLAG(*bitmask, EOS_ERR_EPS_LT_EPSMIN); 181 | vars_adj->eps = eps_min; 182 | } 183 | if(vars->eps > eps_max) 184 | { 185 | BITMASK_SET_FLAG(*bitmask, EOS_ERR_EPS_GT_EPSMAX); 186 | vars_adj->eps = eps_max; 187 | } 188 | #endif 189 | 190 | return 0; 191 | } 192 | 193 | static int eos_compute_from_valid(struct eos_input const * in, struct eos_output * out) 194 | { 195 | #ifdef EOS_HELMHOLTZ 196 | out->temp = in->temp; 197 | double temp_min, temp_max; 198 | helm_range_temp_c(&temp_min, &temp_max); 199 | if(in->temp < temp_min || in->temp > temp_max) 200 | { 201 | /* Initial guess from gamma = 5/3, electron gas EOS */ 202 | out->temp = 2.0/3.0 * in->Abar * in->eps * GSL_CONST_CGSM_MASS_ELECTRON/GSL_CONST_CGSM_BOLTZMANN; 203 | } 204 | 205 | #ifdef _OPENMP 206 | int rank = omp_get_thread_num(); 207 | #else 208 | int rank = 0; 209 | #endif 210 | int fail; 211 | helm_eos_e_c(&rank, &in->rho, &in->eps, &in->Abar, &in->Ye, &out->temp, 212 | &out->press, &out->entropy, &out->csound, &out->cv, &fail); 213 | if(fail) 214 | { 215 | fprintf(stderr, "%s:%d unexpected EOS failure!\n", __FILE__, __LINE__); 216 | return 1; 217 | } 218 | #endif 219 | 220 | return 0; 221 | } 222 | 223 | 224 | --------------------------------------------------------------------------------