Skip to content

Commit

Permalink
We have to finish Human mesh implementation!
Browse files Browse the repository at this point in the history
  • Loading branch information
rsachetto committed Oct 19, 2017
1 parent a71391b commit 21bacc6
Show file tree
Hide file tree
Showing 12 changed files with 505,532 additions and 30 deletions.
7,481 changes: 7,481 additions & 0 deletions meshes/big_scart.pts

Large diffs are not rendered by default.

494,114 changes: 494,114 additions & 0 deletions meshes/human_800_scars_tagged.alg

Large diffs are not rendered by default.

3,585 changes: 3,585 additions & 0 deletions meshes/small_scart.pts

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions scripts/tag_scars.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BEGIN{}
{

#SMALL SCAR
if( ($1 > 36800) && ($1 < 66400) && ($2>72800) && ($2<92000) && ($3>16800) && ($3<36000) && (($5 == 1) || ( $5==2 ))) {
printf("%s,s\n", $0);
}
#BIG SCAR
else if ( ($1 > 80800) && ($1 < 108800) && ($2>68800) && ($2<96000) && ($3>24000) && ($3<60800) && (($5 == 1) || ( $5==2 ))) {
printf("%s,b\n", $0);
}
else printf("%s,n\n", $0);
}
END{}
7 changes: 3 additions & 4 deletions src/alg/cell/cell_refinement.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// Created by sachetto on 30/09/17.
//

#include <assert.h>
#include "cell.h"

void refine_cell( struct cell_node *cell, uint32_vector *free_sv_positions, uint32_vector *refined_this_step) {
if( cell == NULL ) {
fprintf(stderr, "refine_cell(): Parameter cell is NULL. Exiting");
exit(10);
}

assert(cell);

struct transition_node *east_transition_node,
*north_transition_node,
Expand Down
5 changes: 5 additions & 0 deletions src/alg/grid/grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ void set_grid_flux(struct grid *the_grid);
bool refine_grid_with_bound(struct grid* the_grid, double refinement_bound, double min_h);
void refine_grid(struct grid* the_grid, int num_steps);
void refine_grid_cell_at(struct grid *the_grid, uint32_t cell_number);
void refine_fibrotic_cells(struct grid *the_grid);
void refine_border_zone_cells(struct grid *the_grid);

bool derefine_grid_with_bound(struct grid *the_grid, double derefinement_bound, double max_h);
void derefine_all_grid (struct grid* the_grid);
Expand All @@ -56,4 +58,7 @@ void print_grid_vector(struct grid* the_grid, FILE *output_file, char name);
double * grid_vector_to_array(struct grid *the_grid, char name, uint32_t *num_lines);

void save_grid_domain (struct grid * the_grid, const char *file_name);



#endif //MONOALG3D_GRID_H
49 changes: 46 additions & 3 deletions src/alg/grid/grid_refinement.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Created by sachetto on 30/09/17.
//

#include <assert.h>
#include "grid.h"

/**
Expand Down Expand Up @@ -108,7 +109,7 @@ void set_grid_flux(struct grid *the_grid) {
struct cell_node **ac = the_grid->active_cells;


#pragma omp parallel for
#pragma omp parallel for
for (int i = 0; i < active_cells; i++) {
ac[i]->north_flux = 0.0;
ac[i]->south_flux = 0.0;
Expand All @@ -119,7 +120,7 @@ void set_grid_flux(struct grid *the_grid) {
}


#pragma omp parallel for
#pragma omp parallel for
for (int i = 0; i < active_cells; i++) {
set_cell_flux(ac[i], 's' ); // Computes south flux.
set_cell_flux(ac[i], 'n' ); // Computes north flux.
Expand All @@ -129,4 +130,46 @@ void set_grid_flux(struct grid *the_grid) {
set_cell_flux(ac[i], 'b' ); // Computes back flux.
}

}
}

void refine_fibrotic_cells(struct grid *the_grid) {


assert(the_grid);

struct cell_node *grid_cell, *auxiliar_grid_cell;

grid_cell = the_grid->first_cell;
while ( grid_cell != 0 ) {
if(grid_cell->active && grid_cell->fibrotic) {
auxiliar_grid_cell = grid_cell;
grid_cell = grid_cell->next;
refine_cell( auxiliar_grid_cell, NULL, NULL);
the_grid->number_of_cells += 7;
}
else {
grid_cell = grid_cell->next;
}
}
}

void refine_border_zone_cells(struct grid *the_grid) {

assert(the_grid);

struct cell_node *grid_cell, *auxiliar_grid_cell;

grid_cell = the_grid->first_cell;
while ( grid_cell != 0 ) {
if(grid_cell->active && grid_cell->border_zone) {
auxiliar_grid_cell = grid_cell;
grid_cell = grid_cell->next;
refine_cell( auxiliar_grid_cell, NULL, NULL);
the_grid->number_of_cells += 7;
}
else {
grid_cell = grid_cell->next;
}
}
}

147 changes: 141 additions & 6 deletions src/domains_library/domain_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void set_plain_domain (struct grid *the_grid, double sizeX, double sizeY, double
}
}

void set_custom_mesh (struct grid *the_grid, const char *file_name, int size) {
void set_custom_mesh(struct grid *the_grid, const char *file_name, int size, bool read_fibrosis) {
struct cell_node *grid_cell = the_grid->first_cell;
FILE *file = fopen (file_name, "r");

Expand Down Expand Up @@ -79,7 +79,12 @@ void set_custom_mesh (struct grid *the_grid, const char *file_name, int size) {
struct point_3d point3d;

while (i < size) {
fscanf (file, "%lf,%lf,%lf,%lf,%d\n", &a[i][0], &a[i][1], &a[i][2], &b, &fibrosis);
if (read_fibrosis) {
fscanf(file, "%lf,%lf,%lf,%lf,%d\n", &a[i][0], &a[i][1], &a[i][2], &b, &fibrosis);
}
else {
fscanf(file, "%lf,%lf,%lf,%lf\n", &a[i][0], &a[i][1], &a[i][2], &b);
}
if (a[i][1] > maxy)
maxy = a[i][1];
if (a[i][2] > maxz)
Expand All @@ -93,7 +98,9 @@ void set_custom_mesh (struct grid *the_grid, const char *file_name, int size) {
point3d.y = a[i][1];
point3d.z = a[i][2];

point_hash_insert (p_hash, point3d, fibrosis);
if(read_fibrosis) {
point_hash_insert(p_hash, point3d, fibrosis);
}

i++;
}
Expand All @@ -112,8 +119,10 @@ void set_custom_mesh (struct grid *the_grid, const char *file_name, int size) {
point3d.y = y;
point3d.z = z;

grid_cell->fibrotic = (point_hash_search (p_hash, point3d) == 1);
grid_cell->border_zone = (point_hash_search (p_hash, point3d) == 2);
if(read_fibrosis) {
grid_cell->fibrotic = (point_hash_search(p_hash, point3d) == 1);
grid_cell->border_zone = (point_hash_search(p_hash, point3d) == 2);
}

if (x > maxx || y > maxy || z > maxz || x < minx || y < miny || z < minz) {

Expand All @@ -136,7 +145,7 @@ void set_custom_mesh (struct grid *the_grid, const char *file_name, int size) {

void set_custom_mesh_with_bounds (struct grid *the_grid, const char *file_name, int size,
double minx, double maxx, double miny, double maxy, double minz,
double maxz) {
double maxz, bool read_fibrosis) {
struct cell_node *grid_cell = the_grid->first_cell;
FILE *file = fopen (file_name, "r");

Expand Down Expand Up @@ -382,3 +391,129 @@ void set_plain_sphere_fibrosis(struct grid* the_grid, double phi, double plain_


}

void set_human_mesh_fibrosis(struct grid * grid, double phi, const char *scar_file, unsigned seed, double scar_center_x, double scar_center_y, double scar_center_z) {

if(seed == 0)
seed = (unsigned)time(NULL)+getpid();

srand(seed);

print_to_stdout_and_file("Using %u as seed\n", seed);

double bz_size = 0;
double dist;

print_to_stdout_and_file("Calculating fibrosis using phi: %lf\n", phi);
struct cell_node *gridCell = grid->first_cell;

while( gridCell != NULL ) {

if(gridCell->active) {
if(gridCell->fibrotic) {
gridCell->can_change = false;
double p = (double) (rand()) / (RAND_MAX);
if (p < phi) gridCell->active = false;
}
else if(gridCell->border_zone) {
double centerX = gridCell->center_x;
double centerY = gridCell->center_y;
double centerZ = gridCell->center_z;
dist = sqrt((centerX - scar_center_x)*(centerX - scar_center_x) + (centerY - scar_center_y)*(centerY - scar_center_y) + (centerZ - scar_center_z)*(centerZ - scar_center_z) );
if(dist > bz_size) {
bz_size = dist;
}
}

}
gridCell = gridCell->next;
}


gridCell = grid->first_cell;
while( gridCell != NULL ) {

if(gridCell->active) {
if(gridCell->border_zone) {
double centerX = gridCell->center_x;
double centerY = gridCell->center_y;
double centerZ = gridCell->center_z;
dist = sqrt((centerX - scar_center_x)*(centerX - scar_center_x) + (centerY - scar_center_y)*(centerY - scar_center_y) + (centerZ - scar_center_z)*(centerZ - scar_center_z) );
dist = dist/bz_size;
double phi_local = phi - phi*dist;
double p = (double) (rand()) / (RAND_MAX);
if (p < phi_local) gridCell->active = false;
gridCell->can_change = false;

}
}
gridCell = gridCell->next;
}

if(scar_file) {

int minx = 79100;
int maxx = 121000;
int miny = 66700;
int maxy = 106000;
int minz = 11200;
int maxz = 61400;

FILE *file = fopen("scar.pts","r");

if(!file) {
printf("Error opening mesh described in V_t_0!!\n");
exit(0);
}

int size = 2172089;

double **a = (double**) malloc(sizeof(double*)*size);
for(int i=0; i< size; i++){
a[i] = (double*) malloc(sizeof(double) * 3);
if(a[i] == NULL) {
printf("Failed to allocate memory\n");
exit(0);
}
}
double b;

int d;

int i = 0;

while ( !feof(file) ) {
fscanf(file, "%lf,%lf,%lf,%d,%lf\n",&a[i][0],&a[i][1],&a[i][2],&d,&b);
i++;
}
sort_vector(a, size);


gridCell = grid->first_cell;
while( gridCell != 0 ) {

double centerX = gridCell->center_x;
double centerY = gridCell->center_y;
double centerZ = gridCell->center_z;

//inside big scar
if( centerX < maxx && centerY < maxy && centerZ < maxz && centerX > minx && centerY > miny && centerZ > minz ) {
int index = inside_mesh(a, centerX, centerY, centerZ, 0, size - 1);
bool a = gridCell->active;
gridCell->active = index != -1;
}

gridCell = gridCell->next;
}


fclose(file);
for(int j=0; j < size; j++){
free(a[j]);
}

free(a);
}


}
6 changes: 4 additions & 2 deletions src/domains_library/domain_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ int get_num_refinement_steps_to_discretization (double side_len, double h);
void set_benchmark_domain (struct grid *the_grid);
void set_plain_domain (struct grid *the_grid, double sizeX, double sizeY, double sizeZ);

void set_custom_mesh (struct grid *the_grid, const char *file_name, int size);
void set_custom_mesh(struct grid *the_grid, const char *file_name, int size, bool read_fibrosis);

void set_custom_mesh_with_bounds (struct grid *the_grid, const char *file_name, int size, double minx, double maxx,
double miny, double maxy, double minz, double maxz);
double miny, double maxy, double minz, double maxz, bool read_fibrosis);

void set_cell_not_changeable (struct cell_node *c, double initialDiscretization);

Expand All @@ -24,4 +24,6 @@ void set_plain_fibrosis (struct grid *the_grid, double phi, unsigned fib_seed);
void set_plain_sphere_fibrosis (struct grid *the_grid, double phi, double plain_center, double sphere_radius,
double bz_size, double bz_radius, unsigned fib_seed);

void set_human_mesh_fibrosis(struct grid * grid, double phi, const char *scar_file, unsigned seed, double scar_center_x, double scar_center_y, double scar_center_z);

#endif // MONOALG3D_DOMAIN_HELPERS_H
Loading

0 comments on commit 21bacc6

Please sign in to comment.