Commit b2f3cd47 authored by Johannes Blaschke's avatar Johannes Blaschke
Browse files

continue cleaning up

parent 8cafab5d
......@@ -316,200 +316,247 @@ void collision (world_state * world, int last) {
}
// ***** STREAM: Debug functions ******************************************************
void stream_debug__momentum_conservation_preflight(world_state * world) {
if((config.boundaries[0] + config.boundaries[1] + config.boundaries[2] == 0) && config.debug)
if(!debug_check_total_momentum_conservation(get_particles(world), get_nparticles(world), get_squirmers(world), get_nsquirmers(world)))
if(cpu.rank == 0) printf("Momentum changed before stream \n");
debug_check_squirmer_number_conservation(get_squirmers(world), get_nsquirmers(world));
/********************************************************************************
* STEAM debug function *
*******************************************************************************/
void stream_debug__momentum_conservation_preflight (world_state * world) {
if((config__count_bcs() == 0) && config.debug)
if(!debug_check_total_momentum_conservation(get_particles(world), get_nparticles(world),
get_squirmers(world), get_nsquirmers(world)))
if(cpu.rank == 0) printf("Momentum changed before stream \n");
debug_check_squirmer_number_conservation(get_squirmers(world), get_nsquirmers(world));
}
void stream_debug__momentum_conservation_postflight(world_state * world) {
if((config.boundaries[0] + config.boundaries[1] + config.boundaries[2] == 0) && config.debug)
if(!debug_check_total_momentum_conservation(get_particles(world), get_nparticles(world),get_squirmers(world), get_nsquirmers(world)))
if(cpu.rank == 0) printf("Momentum changed during stream \n");
debug_check_squirmer_number_conservation(get_squirmers(world), get_nsquirmers(world));
void stream_debug__momentum_conservation_postflight (world_state * world) {
if((config__count_bcs() == 0) && config.debug)
if(!debug_check_total_momentum_conservation(get_particles(world), get_nparticles(world),
get_squirmers(world), get_nsquirmers(world)))
if(cpu.rank == 0) printf("Momentum changed during stream \n");
debug_check_squirmer_number_conservation(get_squirmers(world), get_nsquirmers(world));
}
// ***** STREAM ***********************************************************************
void stream(int timestep, int last, world_state * world)
{
// ***** GRID SHIFT *****************************************
initialize_gridshift(& cpu.gshift);
/********************************************************************************
* STEAM operator *
*******************************************************************************/
void stream(int timestep, int last, world_state * world) {
// ****** GRID SHIFT ********************************************************
initialize_gridshift(& cpu.gshift);
// ***** STREAM particles ***********************************
#ifdef DEBUG
// ****** STREAM particles **************************************************
#ifdef DEBUG
stream_debug__momentum_conservation_preflight(world);
#endif
#endif
if(config.trypanosome_on == 1) {
if(config.trypanosome_on == 1) {
int n_collision_check = 1;
obstacle_time_driven_md(world, n_collision_check, config.dt, last);
} else if(config.squirmeron == 1) { // ELSE to avoid incompatible streaming functions
} else if(config.squirmeron == 1) { // ELSE to avoid incompatible streaming functions
stream_with_squirmers(world, timestep, last);
} else {
stream_particles(world, config.dt, timestep, last);
}
} else {
stream_particles(world, config.dt, timestep, last);
}
#ifdef DEBUG
#ifdef DEBUG
stream_debug__momentum_conservation_postflight(world);
#endif
#endif
if(config.without_collision){
if(config.without_collision){
undo_gridshift(& cpu.gshift, world);
}
}
}
void free_memory(world_state * world) {
free(world->part.p);
free(world->part.inactivep);
free(cpu.lookuptabley);
free(cpu.lookuptablez);
free(world->cells);
free(localtemperature);
free(localtemp);
MPI_Type_free(&mpi_sendp);
MPI_Type_free(&mpi_vector3);
MPI_Type_free(&mpi_vector5);
MPI_Type_free(&mpi_vector16);
MPI_Type_free(&mpi_vector7);
MPI_Type_free(&mpi_vector11);
MPI_Type_free(&mpi_vector23);
MPI_Comm_free(&cartcomm);
void free_memory (world_state * world) {
free(world->part.p);
free(world->part.inactivep);
free(cpu.lookuptabley);
free(cpu.lookuptablez);
free(world->cells);
free(localtemperature);
free(localtemp);
MPI_Type_free(&mpi_sendp);
MPI_Type_free(&mpi_vector3);
MPI_Type_free(&mpi_vector5);
MPI_Type_free(&mpi_vector16);
MPI_Type_free(&mpi_vector7);
MPI_Type_free(&mpi_vector11);
MPI_Type_free(&mpi_vector23);
MPI_Comm_free(&cartcomm);
#ifdef DEBUG
if (config.debug) {
free(debug.tempcells);
free(debug.cells);
free(debug.cellsang);
free(debug.tempcellsang);
}
if (config.debug) {
free(debug.tempcells);
free(debug.cells);
free(debug.cellsang);
free(debug.tempcellsang);
}
#endif
if(config.squirmeron) {
free(world->squirmers.s);
free(world->squirmers.inactives);
free(world->osquirmers.s);
}
if(config.pflow) {
free(tempslices);
free(averageslicevelocity);
}
if(config.squirmeron) {
free(world->squirmers.s);
free(world->squirmers.inactives);
free(world->osquirmers.s);
}
if(config.pflow) {
free(tempslices);
free(averageslicevelocity);
}
if(config.trypanosome_on) {
if(config.trypanosome_on) {
free_trypanosome(world);
}
}
}
void run_support__timed_mpi_barrier(int n_barrier){
if(n_barrier == 1){
START(MPI_Barrier1);
MPI_Barrier(cartcomm);
STOP(MPI_Barrier1);
}else if(n_barrier == 2){
START(MPI_Barrier2);
MPI_Barrier(cartcomm);
STOP(MPI_Barrier2);
}
}
void run_support__print_status(int num_time_steps, int time_step){
if(cpu.rank == 0){
if(num_time_steps > 10){
if(time_step % (num_time_steps / 10) == 0)
printf("\n step: %d \n", time_step);
void run_support__timed_mpi_barrier (int n_barrier) {
if(n_barrier == 1){
START(MPI_Barrier1);
MPI_Barrier(cartcomm);
STOP(MPI_Barrier1);
}else if(n_barrier == 2){
START(MPI_Barrier2);
MPI_Barrier(cartcomm);
STOP(MPI_Barrier2);
}
else
printf("\n step: %d \n", time_step);
}
}
void run_n_timesteps(int n, world_state* world, int ext_control) {
// **************************** HOUSE Keeping *************************************************************************
// flag used for garbadge collection at the end of the simulation
// TODO: Improve garbadge collection system
int last = 0;
// **************************** PRINT Status: START *******************************************************************
// inform user the the time loop has started (include details about the time loop)
if(cpu.rank==0) printf("Beginning time loop, begin timestep = %d end timestep = %d \n", world->timestep, n);
//all_cpus_print_active_and_inactive_squirmers(get_squirmers(world), get_nsquirmers(world), "Squirmers[beginning]");
// **************************** MAIN LOOP: ****************************************************************************
// number of time steps that the main loop has to ittrate over
int num_time_steps = n - world->timestep;
for(; world->timestep<=n; world->timestep++){
// ************* PRINT Status updates **************************************************************
run_support__print_status(num_time_steps, world->timestep);
// ************* determine IF LAST step ************************************************************
// TODO: again, use a more sane gabadge collection mechanism
if( (world->timestep == n) && (ext_control == 0) ){
last = 1;
if(cpu.rank == 0) printf("Last timestep \n");
}
// ************* MPCD Algorithm: START *************************************************************
// streaming operator acting on:
// (1) particles and obstacles [world]
// (2) gshift [cpu] ** GLOBAL **
run_support__timed_mpi_barrier(1);
stream(world->timestep, 0, world);
// collision operator acting on:
// (1) particles and obstalces [world]
// (2) grid [world]
if(!config.without_collision){
run_support__timed_mpi_barrier(2);
collision(world, last); // if taken out, undo gridshift has to be done in stream
void run_support__print_status (int num_time_steps, int time_step) {
if(cpu.rank == 0){
if(num_time_steps > 10){
if(time_step % (num_time_steps / 10) == 0)
printf("\n step: %d \n", time_step);
}
else
printf("\n step: %d \n", time_step);
}
}
// ************* MPCD Algorithm: END ***************************************************************
// ************* PRINT RESULTS TO FILE *************************************************************
// this includes end data (in order to allow simulations to be resumed)
// TODO: move squirmer end data printing here (it's currently in a really awkward place)
void run_n_timesteps (int n, world_state* world, int ext_control) {
// system output house keeping
fflush(0);
// print trypanosome data
if((cpu.rank == 0) && (config.trypanosome_on == 1) && (world->timestep % config.naverage == 0)) {
tryp_FILE tryp_fp = tryp_support__access_fp("sim data");
print_trypanosome_to_file(world->trypanosome, tryp_fp, world->timestep);
}
// ****** HOUSE Keeping *****************************************************
// flag used for garbadge collection at the end of the simulation TODO:
// Improve garbadge collection system
int last = 0;
// print system enddata to file
if(world->timestep>0){
if((world->timestep % 500000 == 0 ) || last){
if(cpu.rank == 0) printf("\n Printing world state to file \n");
print_particle_enddata_to_file(get_particles(world), get_nparticles(world));
// ****** PRINT Status: START ***********************************************
// inform user the the time loop has started (include details about the time
// loop)
if(cpu.rank==0)
printf("Beginning time loop, begin timestep = %d end timestep = %d \n",
world->timestep, n);
//all_cpus_print_active_and_inactive_squirmers(get_squirmers(world), get_nsquirmers(world), "Squirmers[beginning]");
if(config.squirmeron == 1)
print_squirmer_enddata_to_file(get_squirmers(world), get_nsquirmers(world));
print_conserved_quantities_to_file(get_particles(world), get_nparticles(world), get_squirmers(world), get_nsquirmers(world), world->timestep);
// ****** MAIN LOOP: ********************************************************
// number of time steps that the main loop has to ittrate over
int num_time_steps = n - world->timestep;
if((cpu.rank == 0) && (config.trypanosome_on == 1)){
tryp_FILE tryp_fp = tryp_support__access_fp("end data");
print_trypanosome_to_file(world->trypanosome, tryp_fp, -1);
for(; world->timestep<=n; world->timestep++) {
// ****** PRINT Status updates ******************************************
run_support__print_status(num_time_steps, world->timestep);
// ****** determine IF LAST step ****************************************
// TODO: again, use a more sane gabadge collection mechanism
if( (world->timestep == n) && (ext_control == 0) ){
last = 1;
if(cpu.rank == 0) printf("Last timestep \n");
}
// ****** MPCD Algorithm: START *****************************************
// streaming operator acting on:
// (1) particles and obstacles [world]
// (2) gshift [cpu] ** GLOBAL **
run_support__timed_mpi_barrier(1);
stream(world->timestep, 0, world);
// collision operator acting on:
// (1) particles and obstalces [world]
// (2) grid [world]
if (!config.without_collision){
run_support__timed_mpi_barrier(2);
collision(world, last); // if taken out, undo gridshift has to be done in stream
}
// ****** MPCD Algorithm: END *******************************************
// ****** PRINT RESULTS TO FILE *****************************************
// this includes end data (in order to allow simulations to be resumed)
// TODO: move squirmer end data printing here (it's currently in a
// really awkward place)
// system output house keeping
fflush(0);
// print trypanosome data
if ((cpu.rank == 0) && (config.trypanosome_on == 1)
&& (world->timestep % config.naverage == 0)) {
tryp_FILE tryp_fp = tryp_support__access_fp("sim data");
print_trypanosome_to_file(world->trypanosome, tryp_fp, world->timestep);
}
// print system enddata to file
if (world->timestep>0){
if ((world->timestep % 500000 == 0 ) || last){
if (cpu.rank == 0) printf("\n Printing world state to file \n");
print_particle_enddata_to_file(get_particles(world),
get_nparticles(world));
if (config.squirmeron == 1)
print_squirmer_enddata_to_file(get_squirmers(world),
get_nsquirmers(world));
print_conserved_quantities_to_file(get_particles(world), get_nparticles(world),
get_squirmers(world), get_nsquirmers(world),
world->timestep);
if((cpu.rank == 0) && (config.trypanosome_on == 1)){
tryp_FILE tryp_fp = tryp_support__access_fp("end data");
print_trypanosome_to_file(world->trypanosome, tryp_fp, -1);
}
}
}
}
}
}
//all_cpus_print_active_and_inactive_squirmers(get_squirmers(world), get_nsquirmers(world), "Squirmers[end]");
//all_cpus_print_active_and_inactive_squirmers(get_squirmers(world), get_nsquirmers(world), "Squirmers[end]");
}
void main_support__print_core_domains(FILE * file_dest){
// Collects (MPI_Gather) core domains and prints them to FILE * file_dest
// MPI-lib, malloc, free
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment