diff --git a/examples/EAGLE_6/eagle_6.yml b/examples/EAGLE_6/eagle_6.yml index 05d34ff6359327268c1754c342f87cbae1e043bd..92323a77ce08d7c3b67ec0bd243ae4bec263af16 100644 --- a/examples/EAGLE_6/eagle_6.yml +++ b/examples/EAGLE_6/eagle_6.yml @@ -6,6 +6,14 @@ InternalUnitSystem: UnitCurrent_in_cgs: 1 # Amperes UnitTemp_in_cgs: 1 # Kelvin +# Structure finding on the fly options +StructureFinding: + config_file_name: stf_input.cfg + output_file_name: stf_output.out + output_time_format: 0 + output_times: 100 + + # Define the system of units to use int VELOCIraptor. VelociraptorUnitSystem: UnitMass_in_cgs: 1.989e33 # M_sun in grams diff --git a/src/velociraptor_interface.c b/src/velociraptor_interface.c index 5e0e59176ec53fe65cb8ab4692a45e6f7a37edde..dda8f884ed18ed9054bfddb07f7178595e74476e 100644 --- a/src/velociraptor_interface.c +++ b/src/velociraptor_interface.c @@ -25,6 +25,10 @@ /* Config parameters. */ #include "../config.h" +#include <errno.h> +#include <libgen.h> +#include <unistd.h> + /* This object's header. */ #include "velociraptor_interface.h" @@ -106,44 +110,16 @@ void velociraptor_init(struct engine *e) { s->nr_cells * sizeof(struct cell_loc)) != 0) error("Failed to allocate top-level cell locations for VELOCIraptor."); - - //double cell_loc_min[3] = {sim_info.spacedimension[0] - sim_info.cellwidth[0], - // sim_info.spacedimension[1] - sim_info.cellwidth[1], - // sim_info.spacedimension[2] - sim_info.cellwidth[2]}; - //double cell_loc_max[3] = {0.0, 0.0, 0.0}; - for(int i=0; i<s->nr_cells; i++) { sim_info.cellloc[i].loc[0] = unit_info.lengthtokpc * s->cells_top[i].loc[0]; sim_info.cellloc[i].loc[1] = unit_info.lengthtokpc * s->cells_top[i].loc[1]; sim_info.cellloc[i].loc[2] = unit_info.lengthtokpc * s->cells_top[i].loc[2]; - - //for(int k=0; k<3; k++) { - // cell_loc_min[k] = min(cell_loc_min[k], sim_info.cellloc[i].loc[k]); - // cell_loc_max[k] = max(cell_loc_max[k], sim_info.cellloc[i].loc[k] + sim_info.cellwidth[k]); - //} } - //FILE *file = NULL; - - ///* Name of output file. */ - //char fname[200]; - //sprintf(fname, "cell_locs_rank_%d.dat", e->nodeID); - //file = fopen(fname, "w"); - - ///* Header. */ - //fprintf(file, "# %6s %6s %6s %6s %6s %6s %6s\n", "x", "y", "z", "xw", "yw", - // "zw", "rank"); - - ///* Output */ - //for (int i = 0; i < s->nr_cells; i++) { - // struct cell *c = &s->cells_top[i]; - // fprintf(file, " %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6d\n", sim_info.cellloc[i].loc[0] / unit_info.lengthtokpc, - // sim_info.cellloc[i].loc[1]/ unit_info.lengthtokpc, sim_info.cellloc[i].loc[2]/ unit_info.lengthtokpc, sim_info.cellwidth[0]/ unit_info.lengthtokpc, sim_info.cellwidth[1]/ unit_info.lengthtokpc, sim_info.cellwidth[2]/ unit_info.lengthtokpc, - // c->nodeID); - //} - - //fclose(file); - + char configfilename[PARSER_MAX_LINE_SIZE]; + parser_get_param_string(e->parameter_file, "StructureFinding:config_file_name", configfilename); + + message("Config file name: %s", configfilename); message("Period: %e", sim_info.period); message("Zoom high res mass: %e", sim_info.zoomhigresolutionmass); message("Inter-particle spacing: %e", sim_info.interparticlespacing); @@ -153,7 +129,7 @@ void velociraptor_init(struct engine *e) { //message("Local top-level cell locations range: (%e,%e,%e) -> (%e,%e,%e)", cell_loc_min[0], cell_loc_min[1], cell_loc_min[2], cell_loc_max[0], cell_loc_max[1], cell_loc_max[2]); message("Top-level cell locations range: (%e,%e,%e) -> (%e,%e,%e)", sim_info.cellloc[0].loc[0], sim_info.cellloc[0].loc[1], sim_info.cellloc[0].loc[2], sim_info.cellloc[sim_info.numcells - 1].loc[0], sim_info.cellloc[sim_info.numcells - 1].loc[1], sim_info.cellloc[sim_info.numcells - 1].loc[2]); - InitVelociraptor("stf_input.cfg", "stf_output.out", cosmo_info, unit_info, sim_info); + InitVelociraptor(configfilename, cosmo_info, unit_info, sim_info); /* Free cell locations after VELOCIraptor has copied them. */ //free(sim_info.cellloc); @@ -185,8 +161,19 @@ void velociraptor_invoke(struct engine *e) { //for(int i=0; i<nr_gparts; i++) message("Potential: %f", gparts[i].potential); - InvokeVelociraptor(nr_gparts, gparts, cell_node_ids); + /* Check that we can write the snapshots by testing if the output + * directory exists and is searchable and writable. */ + char outputfilename[PARSER_MAX_LINE_SIZE]; + parser_get_param_string(e->parameter_file, "StructureFinding:output_file_name", outputfilename); + const char *dirp = dirname(outputfilename); + if (access(dirp, W_OK | X_OK) != 0) { + error("Cannot write snapshots in directory %s (%s)", dirp, strerror(errno)); + } + + message("Output file name: %s", outputfilename); + + InvokeVelociraptor(nr_gparts, gparts, cell_node_ids, outputfilename); /* Free cell node ids after VELOCIraptor has copied them. */ - //free(cell_node_ids); + free(cell_node_ids); } diff --git a/src/velociraptor_interface.h b/src/velociraptor_interface.h index 90f98857efc6b67d806a034fb5875ecd284568c6..71366dfe5d24ed4dac4bc27e7d1cae37002ab385 100644 --- a/src/velociraptor_interface.h +++ b/src/velociraptor_interface.h @@ -68,8 +68,8 @@ struct siminfo { }; /* VELOCIraptor interface. */ -void InitVelociraptor(char* config_name, char* output_name, struct cosmoinfo cosmo_info, struct unitinfo unit_info, struct siminfo sim_info); -void InvokeVelociraptor(const int num_gravity_parts, struct gpart *gravity_parts, const int *cell_node_ids); +void InitVelociraptor(char* config_name, struct cosmoinfo cosmo_info, struct unitinfo unit_info, struct siminfo sim_info); +void InvokeVelociraptor(const int num_gravity_parts, struct gpart *gravity_parts, const int *cell_node_ids, char* output_name); /* VELOCIraptor wrapper functions. */ void velociraptor_init(struct engine *e);