Skip to content

Commit f461dee

Browse files
authored
Merge pull request #68 from bergolho/master
New conic domain function and more general format for the benchmark domain function
2 parents 4e33523 + 2691a9c commit f461dee

File tree

3 files changed

+123
-29
lines changed

3 files changed

+123
-29
lines changed

src/domains_library/domain.c

+61-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ SET_SPATIAL_DOMAIN(initialize_grid_with_rabbit_mesh) {
127127
return num_loaded > 0;
128128
}
129129

130+
/**
131+
* Sets the current domain as a domain described in the N-version benchmark
132+
* (http://rsta.royalsocietypublishing.org/content/369/1954/4331)
133+
*/
130134
SET_SPATIAL_DOMAIN(initialize_grid_with_benchmark_mesh) {
131135

132136
real_cpu side_length;
@@ -137,6 +141,15 @@ SET_SPATIAL_DOMAIN(initialize_grid_with_benchmark_mesh) {
137141
real_cpu max_h = start_h;
138142
GET_PARAMETER_NUMERIC_VALUE_OR_USE_DEFAULT(real_cpu, max_h, config, "maximum_discretization");
139143

144+
real_cpu side_length_x = 20000.0;
145+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, side_length_x, config, "side_length_x");
146+
147+
real_cpu side_length_y = 7000.0;
148+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, side_length_y, config, "side_length_y");
149+
150+
real_cpu side_length_z = 3000.0;
151+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, side_length_z, config, "side_length_z");
152+
140153
log_info("Loading N-Version benchmark mesh using dx %lf um, dy %lf um, dz %lf um\n", start_h, start_h, start_h);
141154

142155
side_length = start_h;
@@ -150,7 +163,7 @@ SET_SPATIAL_DOMAIN(initialize_grid_with_benchmark_mesh) {
150163
int num_steps = get_num_refinement_steps_to_discretization(side_length, start_h);
151164

152165
refine_grid(the_grid, num_steps);
153-
set_benchmark_domain(the_grid);
166+
set_benchmark_domain(the_grid, side_length_x, side_length_y, side_length_z);
154167

155168
log_info("Cleaning grid\n");
156169
int i;
@@ -401,5 +414,52 @@ SET_SPATIAL_DOMAIN(initialize_grid_with_square_mesh_and_source_sink_fibrotic_reg
401414

402415
set_plain_fibrosis_source_sink_region(the_grid, phi, seed, min_x, max_x, min_y, max_y, min_z, max_z, source_sink_min_x, source_sink_max_x, side_length);
403416

417+
return 1;
418+
}
419+
420+
SET_SPATIAL_DOMAIN(initialize_grid_with_cuboid_and_sphere_fibrotic_mesh_with_conic_path){
421+
real_cpu side_length_x = 0.0;
422+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, side_length_x, config, "side_length_x");
423+
424+
real_cpu side_length_y = 0.0;
425+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, side_length_y, config, "side_length_y");
426+
427+
real_cpu side_length_z = 0.0;
428+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, side_length_z, config, "side_length_z");
429+
430+
real_cpu start_dx = 0.0;
431+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, start_dx, config, "start_dx");
432+
433+
real_cpu start_dy = 0.0;
434+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, start_dy, config, "start_dy");
435+
436+
real_cpu start_dz = 0.0;
437+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, start_dz, config, "start_dz");
438+
439+
real_cpu phi = 0.0;
440+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, phi, config, "phi");
441+
442+
real_cpu plain_center = 0.0;
443+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, plain_center, config, "plain_center");
444+
445+
real_cpu sphere_radius = 0.0;
446+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, sphere_radius, config, "sphere_radius");
447+
448+
real_cpu border_zone_size = 0.0;
449+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, border_zone_size, config, "border_zone_size");
450+
451+
real_cpu border_zone_radius = 0.0;
452+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, border_zone_radius, config, "border_zone_radius");
453+
454+
real_cpu conic_slope = 0.0;
455+
GET_PARAMETER_NUMERIC_VALUE_OR_REPORT_ERROR(real_cpu, conic_slope, config, "conic_slope");
456+
457+
unsigned seed = 0;
458+
GET_PARAMETER_NUMERIC_VALUE_OR_USE_DEFAULT(unsigned, seed, config, "seed");
459+
460+
//set_square_mesh(config, the_grid);
461+
set_cuboid_domain_mesh(the_grid, start_dx, start_dy, start_dz, side_length_x, side_length_y, side_length_z);
462+
set_cuboid_sphere_fibrosis_with_conic_path(the_grid, phi, plain_center, sphere_radius, border_zone_size, border_zone_radius, seed, conic_slope);
463+
404464
return 1;
405465
}

src/domains_library/domain_helpers.c

+58-27
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,13 @@ int calculate_cuboid_side_lengths(real_cpu start_dx, real_cpu start_dy, real_cpu
445445
* (http://rsta.royalsocietypublishing.org/content/369/1954/4331)
446446
*
447447
*/
448-
void set_benchmark_domain(struct grid *the_grid) {
448+
void set_benchmark_domain(struct grid *the_grid, real_cpu sx, real_cpu sy, real_cpu sz) {
449449
struct cell_node *grid_cell = the_grid->first_cell;
450450

451-
real_cpu sx, sy, sz;
452-
sx = 20000;
453-
sy = 7000;
454-
sz = 3000;
451+
//real_cpu sx, sy, sz;
452+
//sx = 20000;
453+
//sy = 7000;
454+
//sz = 3000;
455455

456456
while(grid_cell != 0) {
457457
grid_cell->active = (grid_cell->center.x < sx) && (grid_cell->center.y < sy) && (grid_cell->center.z < sz);
@@ -1010,12 +1010,10 @@ int calc_num_refs(real_cpu start_h, real_cpu desired_h) {
10101010
return num_refs;
10111011
}
10121012

1013-
void set_plain_fibrosis_source_sink_region (struct grid *the_grid, real_cpu phi, unsigned fib_seed, const double min_x, const double max_x, const double min_y,
1014-
const double max_y, const double min_z, const double max_z,
1015-
real_cpu source_sink_min_x, real_cpu source_sink_max_x, real_cpu side_length) {
1016-
log_info("Making %.2lf %% of cells inside the region inactive\n", phi * 100.0);
1013+
void set_cuboid_sphere_fibrosis_with_conic_path(struct grid *the_grid, real_cpu phi, real_cpu plain_center, real_cpu sphere_radius, real_cpu bz_size, real_cpu bz_radius,
1014+
unsigned fib_seed, real_cpu cone_slope) {
10171015

1018-
struct cell_node *grid_cell;
1016+
log_info("Making %.2lf %% of cells inactive\n", phi * 100.0f);
10191017

10201018
if(fib_seed == 0)
10211019
fib_seed = (unsigned)time(NULL) + getpid();
@@ -1024,30 +1022,63 @@ void set_plain_fibrosis_source_sink_region (struct grid *the_grid, real_cpu phi,
10241022

10251023
log_info("Using %u as seed\n", fib_seed);
10261024

1027-
real_cpu a1 = (2.0*side_length) / (side_length - 2*source_sink_min_x);
1028-
real_cpu b1 = -source_sink_min_x*a1;
1029-
real_cpu a2 = (2.0*side_length) / (side_length - 2*source_sink_max_x);
1030-
real_cpu b2 = -source_sink_max_x*a2;
1025+
real_cpu bz_radius_2 = pow(bz_radius, 2.0);
1026+
real_cpu sphere_radius_2 = pow(sphere_radius, 2.0);
1027+
struct cell_node *grid_cell;
10311028

10321029
grid_cell = the_grid->first_cell;
10331030
while(grid_cell != 0) {
1034-
real center_x = grid_cell->center.x;
1035-
real center_y = grid_cell->center.y;
1036-
real center_z = grid_cell->center.z;
1031+
//Calcula distância da célula para o centro da malha
1032+
real_cpu distance = pow(grid_cell->center.x - plain_center, 2.0) + pow(grid_cell->center.y - plain_center, 2.0);
1033+
real_cpu h_distance = abs(grid_cell->center.x - plain_center);
1034+
1035+
if(grid_cell->active) {
10371036

1038-
if(center_x >= min_x && center_x <= max_x && center_y >= min_y && center_y <= max_y && center_z >= min_z && center_z <= max_z
1039-
&& (center_y > a1*center_x + b1 || center_y > a2*center_x + b2)) {
1040-
if(grid_cell->active) {
1041-
real_cpu p = (real_cpu)(rand()) / (RAND_MAX);
1042-
if(p < phi) {
1043-
grid_cell->active = false;
1044-
}
1037+
INITIALIZE_FIBROTIC_INFO(grid_cell);
10451038

1046-
INITIALIZE_FIBROTIC_INFO(grid_cell);
1047-
FIBROTIC(grid_cell) = true;
1039+
if(distance <= bz_radius_2) {
1040+
//Dentro da border zone
1041+
if(distance <= sphere_radius_2) {
1042+
//dentro da "esfera"
1043+
if(h_distance < cone_slope*grid_cell->center.y*plain_center) //abs(cone_slope*grid_cell->center.y)
1044+
{
1045+
FIBROTIC(grid_cell) = true;
1046+
1047+
//Dentro do cone
1048+
}
1049+
else{
1050+
grid_cell->active = false;
1051+
grid_cell->can_change = false;
1052+
FIBROTIC(grid_cell) = true;
1053+
}
1054+
} else {
1055+
BORDER_ZONE(grid_cell) = true;
1056+
}
10481057
}
10491058
}
1059+
grid_cell = grid_cell->next;
1060+
}
1061+
1062+
grid_cell = the_grid->first_cell;
10501063

1064+
while(grid_cell != 0) {
1065+
if(grid_cell->active) {
1066+
if(FIBROTIC(grid_cell)) {
1067+
real_cpu p = (real_cpu)(rand()) / (RAND_MAX);
1068+
if(p < phi)
1069+
grid_cell->active = false;
1070+
grid_cell->can_change = false;
1071+
} else if(BORDER_ZONE(grid_cell)) {
1072+
real_cpu distance_from_center = sqrt((grid_cell->center.x - plain_center) * (grid_cell->center.x - plain_center) +
1073+
(grid_cell->center.y - plain_center) * (grid_cell->center.y - plain_center));
1074+
distance_from_center = (distance_from_center - sphere_radius) / bz_size;
1075+
real_cpu phi_local = phi - phi * distance_from_center;
1076+
real_cpu p = (real_cpu)(rand()) / (RAND_MAX);
1077+
if(p < phi_local)
1078+
grid_cell->active = false;
1079+
grid_cell->can_change = false;
1080+
}
1081+
}
10511082
grid_cell = grid_cell->next;
10521083
}
1053-
}
1084+
}

src/domains_library/domain_helpers.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int set_cuboid_domain_mesh(struct grid *the_grid, real_cpu start_dx, real_cpu st
1717
real_cpu side_length_z);
1818
int set_square_mesh(struct config *config, struct grid *the_grid);
1919

20-
void set_benchmark_domain(struct grid *the_grid);
20+
void set_benchmark_domain(struct grid *the_grid, real_cpu sx, real_cpu sy, real_cpu sz);
2121
void set_cuboid_domain(struct grid *the_grid, real_cpu sizeX, real_cpu sizeY, real_cpu sizeZ);
2222

2323
void set_custom_mesh(struct grid *the_grid, const char *file_name, size_t size, char *read_format);
@@ -56,6 +56,9 @@ uint32_t set_custom_mesh_from_file(struct grid *the_grid, const char *mesh_file,
5656

5757
void set_cube_sphere_fibrosis(struct grid *the_grid, real_cpu phi, real_cpu sphere_center[3], real_cpu sphere_radius, unsigned fib_seed);
5858

59+
void set_cuboid_sphere_fibrosis_with_conic_path (struct grid *the_grid, real_cpu phi, real_cpu plain_center, real_cpu sphere_radius, real_cpu bz_size, real_cpu bz_radius,
60+
unsigned fib_seed, real_cpu cone_slope);
61+
5962
int calc_num_refs(real_cpu start_h, real_cpu desired_h);
6063

6164
#endif // MONOALG3D_DOMAIN_HELPERS_H

0 commit comments

Comments
 (0)