diff options
author | Oliver Schinagl <oliver@schinagl.nl> | 2008-01-09 13:02:54 (GMT) |
---|---|---|
committer | Oliver Schinagl <oliver@schinagl.nl> | 2008-01-09 13:02:54 (GMT) |
commit | 29e82f50f6f23b1a344b486f377d918425e37188 (patch) | |
tree | 6d5ff663d8ef89898d5584eab9f63f45126b145a /Smoke/fluids.c | |
parent | 4f8eda57dc837193ea25737b28d3514b3858639f (diff) | |
download | 2iv35-29e82f50f6f23b1a344b486f377d918425e37188.zip 2iv35-29e82f50f6f23b1a344b486f377d918425e37188.tar.gz 2iv35-29e82f50f6f23b1a344b486f377d918425e37188.tar.bz2 |
simulation reset added; colormap autoscaling moved to fluids main loop
Diffstat (limited to 'Smoke/fluids.c')
-rw-r--r-- | Smoke/fluids.c | 94 |
1 files changed, 57 insertions, 37 deletions
diff --git a/Smoke/fluids.c b/Smoke/fluids.c index d1fc279..51ee23e 100644 --- a/Smoke/fluids.c +++ b/Smoke/fluids.c @@ -55,15 +55,13 @@ static int DIM; //size of simulation grid //init_simulation: Initialize simulation data structures as a function of the grid size 'n'. // Although the simulation takes place on a 2D grid, we allocate all data structures as 1D arrays, // for compatibility with the FFTW numerical library. -fftw_real *init_simulation(int n, struct vis_data_arrays *vis_data) +void fluids_init_simulation(int n, struct vis_data_arrays *vis_data) { int i; size_t dim1, dim2; - fftw_real *return_value; DIM = n; dim1 = n * 2*(n/2+1)*sizeof(fftw_real); //Allocate data structures - return_value = (fftw_real *)malloc(dim1); vx = (fftw_real*) malloc(dim1); vy = (fftw_real*) malloc(dim1); vx0 = (fftw_real*) malloc(dim1); @@ -86,7 +84,7 @@ fftw_real *init_simulation(int n, struct vis_data_arrays *vis_data) } for (i = 0; i < n * n; i++) //Initialize data structures to 0 - { vx[i] = vy[i] = vx0[i] = vy0[i] = fx[i] = fy[i] = rho[i] = rho0[i] = height_array[i] = 0.0f; } + { vx[i] = vy[i] = vx0[i] = vy0[i] = fx[i] = fy[i] = rho[i] = rho0[i] = 0.0f; } vis_data->rho = rho; vis_data->force = (fftw_real *)malloc(dim2); @@ -95,8 +93,13 @@ fftw_real *init_simulation(int n, struct vis_data_arrays *vis_data) vis_data->div_vel = (fftw_real *)malloc(dim1); vis_data->height = (fftw_real *)malloc(dim2); vis_data->normals = (struct point *)malloc(dim2 *sizeof(struct point *)); +} - return return_value; +void fluids_reset_simulation(void) { + int i; + + for (i = 0; i < DIM * DIM; i++) //Initialize data structures to 0 + { vx[i] = vy[i] = vx0[i] = vy0[i] = fx[i] = fy[i] = rho[i] = rho0[i] = 0.0f; } } int rescale_to_winwidth(float value) @@ -363,23 +366,62 @@ fftw_real calculate_height_plot(int dataset, int index) return return_value; } + void copy_frames(fftw_real *dataset) { memcpy(smoke_get_frame(), dataset, DIM * 2 * (DIM / 2 + 1) * sizeof(fftw_real)); } + float par_der(float xy1, float xy2, fftw_real cell) { return (xy1 - (xy2/ cell)); } + +fftw_real *get_frame(struct vis_data_arrays *vis_data, int dataset) +{ + fftw_real *return_value; + + switch(dataset) + { + default: + case DATASET_RHO: + return_value = vis_data->rho; + break; + case DATASET_VEL: + return_value = vis_data->vel; + break; + case DATASET_FORCE: + return_value = vis_data->force; + break; + case DATASET_DIVV: + return_value = vis_data->div_vel; + break; + case DATASET_DIVF: + return_value = vis_data->div_force; + break; + case DATASET_HIST: + return_value = vis_data->history[0]; + } + + return return_value; +} + + void populate_arrays(struct vis_data_arrays *vis_data) { int idx, i, j; + float scale_min, scale_max; + fftw_real *frame; + fftw_real wn = (fftw_real)winWidth / (fftw_real)(DIM + 1); // Grid cell width fftw_real hn = (fftw_real)winHeight / (fftw_real)(DIM + 1); // Grid cell height - + + frame = get_frame(vis_data, smoke_get_dataset()); + scale_min = scale_max = frame[0]; + for (j = 0; j < DIM; j++) { for (i = 0; i < DIM; i++) @@ -401,37 +443,15 @@ void populate_arrays(struct vis_data_arrays *vis_data) // printf("n: %lf; old: %lf\n", // vis_data->normals[idx].z, normal_array[idx].z); // } - } - } -} -fftw_real *get_frame(struct vis_data_arrays *vis_data, int dataset) -{ - fftw_real *return_value; - switch(dataset) - { - default: - case DATASET_RHO: - return_value = vis_data->rho; - break; - case DATASET_VEL: - return_value = vis_data->vel; - break; - case DATASET_FORCE: - return_value = vis_data->force; - break; - case DATASET_DIVV: - return_value = vis_data->div_vel; - break; - case DATASET_DIVF: - return_value = vis_data->div_force; - break; - case DATASET_HIST: - return_value = vis_data->history[0]; - } - - return return_value; + + if (colormap_get_autoscaling()) { + if (scale_min > frame[idx]) { colormap_set_scale_min(frame[idx]); } + if (scale_max < frame[idx]) { colormap_set_scale_max(frame[idx]); } + } + } + } } //do_one_simulation_step: Do one complete cycle of the simulation: @@ -441,7 +461,7 @@ fftw_real *get_frame(struct vis_data_arrays *vis_data, int dataset) // - gluPostRedisplay: draw a new visualization frame -void calculate_one_simulation_step(struct vis_data_arrays *vis_data) +void fluids_calculate_one_simulation_step(struct vis_data_arrays *vis_data) { int dataset; fftw_real *frame; @@ -452,7 +472,6 @@ void calculate_one_simulation_step(struct vis_data_arrays *vis_data) diffuse_matter(DIM, vx, vy, rho, rho0, dt); calculate_height_plots(); calculate_normal_vectors(); - colormap_autoscale(); } populate_arrays(vis_data); @@ -466,6 +485,7 @@ void calculate_one_simulation_step(struct vis_data_arrays *vis_data) heightplots_set_frame(vis_data->height); normals_set_frame(vis_data->normals); +// streamlines_set_frame(vis_data->history); } //------ VISUALIZATION CODE STARTS HERE ----------------------------------------------------------------- |