Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change order of parse options function #112

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ PetscErrorCode sp_write_surface_vec(PetscInt i);
PetscErrorCode sp_destroy();
PetscErrorCode rescalePrecipitation(double tempo);
PetscErrorCode parse_options(int rank);
PetscErrorCode load_topo_var(int rank);


int main(int argc,char **args)
{
Expand Down Expand Up @@ -93,11 +95,36 @@ int main(int argc,char **args)

seed = rank;

// Parse command line options
parse_options(rank);

// Read ASCII files
reader(rank, "param.txt");

// Parse command line options
parse_options(rank);
// Check if the number of interfaces in "param.txt" is higher than then number read from command line
if (seed_layer_size > n_interfaces) {
PetscPrintf(PETSC_COMM_WORLD, "Error: The number of layers specified in command line \"-seed\" command is higher than the number in \"param.txt\".\n");
}

PetscPrintf(PETSC_COMM_WORLD, "Number of seed layers: %d\n", seed_layer_size);
for (int k = 0; k < seed_layer_size; k++) {
PetscPrintf(PETSC_COMM_WORLD, "seed layer: %d - strain: %lf\n", seed_layer[k], strain_seed_layer[k]);
}
PetscPrintf(PETSC_COMM_WORLD, "\n");

if (sp_surface_processes && sp_surface_tracking && sp_mode == 1) {
load_topo_var(rank);
}

if (sp_mode == 2 && PETSC_FALSE == set_sp_d_c) {
ierr = PetscPrintf(PETSC_COMM_WORLD, "-sp_mode 2 (diffusion) using default value: sp_d_c %e\n", sp_d_c); CHKERRQ(ierr);
} else if (sp_mode == 2) {
ierr = PetscPrintf(PETSC_COMM_WORLD, "-sp_mode 2 (diffusion) using custom value: sp_d_c %e\n", sp_d_c); CHKERRQ(ierr);
} else if (sp_mode == 3) {
ierr = PetscPrintf(PETSC_COMM_WORLD, "-sp_mode 3 (fluvial erosion) using K_fluvial: %e and sea_level %e\n", K_fluvial, sea_level); CHKERRQ(ierr);
} else if (sp_mode == 4) {
ierr = PetscPrintf(PETSC_COMM_WORLD, "-sp_mode 4 (fluvial erosion mode 2) using K_fluvial: %e and sea_level %e\n", K_fluvial, sea_level); CHKERRQ(ierr);
}

// Update elements aux constants
if (dimensions == 3) {
Expand Down
96 changes: 36 additions & 60 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@ extern PetscInt strain_seed_layer_size;
extern PetscBool strain_seed_layer_set;
extern PetscBool strain_seed_constant;
extern PetscBool strain_seed_constant_set;
extern double h_air;;
extern PetscInt pressure_in_rheol;
extern PetscBool sp_surface_processes;
extern PetscBool sp_surface_tracking;
extern PetscInt sp_mode;
extern PetscBool set_sp_d_c;
extern PetscScalar sp_d_c;
extern PetscScalar K_fluvial;
extern PetscScalar sea_level;
extern double h_air;


PetscErrorCode load_topo_var(int rank);
PetscInt *seed_layer_aux;
PetscReal *strain_seed_layer_aux;


PetscErrorCode parse_options(int rank)
Expand All @@ -34,64 +26,48 @@ PetscErrorCode parse_options(int rank)
ierr = PetscOptionsGetInt(NULL , NULL, "-Px", &Px, NULL); CHKERRQ(ierr);
ierr = PetscOptionsGetInt(NULL , NULL, "-Pz", &Pz, NULL); CHKERRQ(ierr);

if (n_interfaces > 0 && interfaces_from_ascii == 1) {
ierr = PetscCalloc1(n_interfaces, &seed_layer); CHKERRQ(ierr);
seed_layer_size = n_interfaces + 1;
ierr = PetscOptionsGetIntArray(NULL, NULL, "-seed", seed_layer, &seed_layer_size, &seed_layer_set); CHKERRQ(ierr);
ierr = PetscCalloc1(100000, &seed_layer_aux); CHKERRQ(ierr);
seed_layer_size = 100000;
ierr = PetscOptionsGetIntArray(NULL, NULL, "-seed", seed_layer_aux, &seed_layer_size, &seed_layer_set); CHKERRQ(ierr);

ierr = PetscCalloc1(n_interfaces, &strain_seed_layer); CHKERRQ(ierr);
strain_seed_layer_size = n_interfaces + 1;
ierr = PetscOptionsGetRealArray(NULL, NULL, "-strain_seed", strain_seed_layer, &strain_seed_layer_size, &strain_seed_layer_set); CHKERRQ(ierr);
if (strain_seed_layer_set == PETSC_TRUE && seed_layer_set == PETSC_FALSE) {
PetscPrintf(PETSC_COMM_WORLD, "Specify the seed layer with the flag -seed (required by -strain_seed)\n");
exit(1);
}
if (strain_seed_layer_set == PETSC_TRUE && seed_layer_set == PETSC_TRUE && seed_layer_size != strain_seed_layer_size) {
PetscPrintf(PETSC_COMM_WORLD, "Specify the same number of values in the list for flags -seed and -strain_seed\n");
exit(1);
}
if (strain_seed_layer_set == PETSC_FALSE && seed_layer_set == PETSC_TRUE) {
PetscPrintf(PETSC_COMM_WORLD, "Using default value '0.5' for -strain_seed (for all seed layers)\n");
for (int k = 0; k < seed_layer_size; k++) {
strain_seed_layer[k] = 0.5;
}
}
PetscPrintf(PETSC_COMM_WORLD, "Number of seed layers: %d\n", seed_layer_size);
for (int k = 0; k < seed_layer_size; k++) {
PetscPrintf(PETSC_COMM_WORLD, "seed layer: %d - strain: %lf\n", seed_layer[k], strain_seed_layer[k]);
}
PetscPrintf(PETSC_COMM_WORLD, "\n");
ierr = PetscCalloc1(100000, &strain_seed_layer_aux); CHKERRQ(ierr);
strain_seed_layer_size = 100000;
ierr = PetscOptionsGetRealArray(NULL, NULL, "-strain_seed", strain_seed_layer_aux, &strain_seed_layer_size, &strain_seed_layer_set); CHKERRQ(ierr);

ierr = PetscOptionsGetBool(NULL, NULL, "-strain_seed_constant", &strain_seed_constant, &strain_seed_constant_set); CHKERRQ(ierr);
if (strain_seed_constant_set == PETSC_TRUE && seed_layer_set == PETSC_FALSE) {
PetscPrintf(PETSC_COMM_WORLD, "Specify the seed layer with the flags -seed and -strain_seed (required by -strain_seed_constant)\n");
exit(1);
}
ierr = PetscCalloc1(seed_layer_size, &seed_layer); CHKERRQ(ierr);
ierr = PetscCalloc1(strain_seed_layer_size, &strain_seed_layer); CHKERRQ(ierr);

for (int k = 0; k < seed_layer_size; k++) {
seed_layer[k] = seed_layer_aux[k];
strain_seed_layer[k] = strain_seed_layer_aux[k];
}

h_air = -1.0;
ierr = PetscOptionsGetReal(NULL, NULL, "-h_air", &h_air, NULL); CHKERRQ(ierr);
if (pressure_in_rheol == 0 && h_air < 0.0) {
PetscPrintf(PETSC_COMM_WORLD, "Specify the thickness of the air layer with the flag -h_air\n");
PetscPrintf(PETSC_COMM_WORLD, "(you adopted depth dependent rheology: pressure_in_rheol = 0)\n");
PetscFree(seed_layer_aux);
PetscFree(strain_seed_layer_aux);

if (strain_seed_layer_set == PETSC_TRUE && seed_layer_set == PETSC_FALSE) {
PetscPrintf(PETSC_COMM_WORLD, "Specify the seed layer with the flag -seed (required by -strain_seed)\n");
exit(1);
} else {
h_air = 0.0;
}

if (sp_surface_processes && sp_surface_tracking && sp_mode == 1) {
load_topo_var(rank);
if (strain_seed_layer_set == PETSC_TRUE && seed_layer_set == PETSC_TRUE && seed_layer_size != strain_seed_layer_size) {
PetscPrintf(PETSC_COMM_WORLD, "Specify the same number of values in the list for flags -seed and -strain_seed\n");
exit(1);
}
if (strain_seed_layer_set == PETSC_FALSE && seed_layer_set == PETSC_TRUE) {
PetscPrintf(PETSC_COMM_WORLD, "Using default value '0.5' for -strain_seed (for all seed layers)\n");
for (int k = 0; k < seed_layer_size; k++) {
strain_seed_layer[k] = 0.5;
}
}

if (sp_mode == 2 && PETSC_FALSE == set_sp_d_c) {
ierr = PetscPrintf(PETSC_COMM_WORLD, "-sp_mode 2 (diffusion) using default value: sp_d_c %e\n", sp_d_c); CHKERRQ(ierr);
} else if (sp_mode == 2) {
ierr = PetscPrintf(PETSC_COMM_WORLD, "-sp_mode 2 (diffusion) using custom value: sp_d_c %e\n", sp_d_c); CHKERRQ(ierr);
} else if (sp_mode == 3) {
ierr = PetscPrintf(PETSC_COMM_WORLD, "-sp_mode 3 (fluvial erosion) using K_fluvial: %e and sea_level %e\n", K_fluvial, sea_level); CHKERRQ(ierr);
} else if (sp_mode == 4) {
ierr = PetscPrintf(PETSC_COMM_WORLD, "-sp_mode 4 (fluvial erosion mode 2) using K_fluvial: %e and sea_level %e\n", K_fluvial, sea_level); CHKERRQ(ierr);
ierr = PetscOptionsGetBool(NULL, NULL, "-strain_seed_constant", &strain_seed_constant, &strain_seed_constant_set); CHKERRQ(ierr);
if (strain_seed_constant_set == PETSC_TRUE && seed_layer_set == PETSC_FALSE) {
PetscPrintf(PETSC_COMM_WORLD, "Specify the seed layer with the flags -seed and -strain_seed (required by -strain_seed_constant)\n");
exit(1);
}

h_air = -1.0;
ierr = PetscOptionsGetReal(NULL, NULL, "-h_air", &h_air, NULL); CHKERRQ(ierr);

PetscFunctionReturn(0);
}
12 changes: 10 additions & 2 deletions src/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ PetscErrorCode reader(int rank, const char fName[]){

else if (strcmp(tkn_w, "diffusivity0_scaled") == 0) {kappa0_scaled = atof(tkn_v);}
else if (strcmp(tkn_w, "temperature0_scaled") == 0) {temperature0_scaled = atof(tkn_v);}*/



// Else
Expand Down Expand Up @@ -447,6 +447,14 @@ PetscErrorCode reader(int rank, const char fName[]){

MPI_Bcast(&non_dim,1,MPI_INT,0,PETSC_COMM_WORLD);

if (pressure_in_rheol == 0 && h_air < 0.0) {
PetscPrintf(PETSC_COMM_WORLD, "Specify the thickness of the air layer with the flag -h_air\n");
PetscPrintf(PETSC_COMM_WORLD, "(you adopted depth dependent rheology: pressure_in_rheol = 0)\n");
exit(1);
} else if (pressure_in_rheol == 1) {
h_air = 0.0;
}

if (non_dim==1){
h0_scaled = depth;
depth /= h0_scaled;
Expand Down Expand Up @@ -501,7 +509,7 @@ PetscErrorCode reader(int rank, const char fName[]){
adiabatic_scaled = time0_scaled*g0_scaled*veloc0_scaled;



air_threshold_density = 100.0/rho0_scaled;


Expand Down