Skip to content

Commit 055b4b3

Browse files
authored
add new surface processes implementation (#125)
The current implementation uses a dm swarm to track the surface. In this version, the only surface process available is a simple diffusion process. Additionally, some parameters are no longer supported: `sp_dt`, `precipitation_profile_from_ascii`, and `climate_change_from_ascii`. The output file for the surface level has been renamed to `surface_*.txt`.
1 parent 6089f97 commit 055b4b3

15 files changed

Lines changed: 1687 additions & 1627 deletions

File tree

src/header.h

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PetscInt particles_per_ele = 81;
99
PetscReal theta_FSSA = 0.5;
1010
PetscReal sub_division_time_step = 1.0;
1111
PetscReal particles_perturb_factor = 0.5;
12-
PetscInt sp_mode = 1;
12+
PetscInt sp_mode = 0;
1313
PetscReal Xi_min = 1.0E-14;
1414
PetscReal random_initial_strain = 0;
1515
PetscReal pressure_const = -1.0;
@@ -22,7 +22,6 @@ PetscScalar K_fluvial = 2.0E-7;
2222
PetscScalar m_fluvial = 1.0;
2323
PetscScalar sea_level = 0.0;
2424
PetscScalar basal_heat = -1.0;
25-
PetscReal sp_dt = 0.0;
2625
PetscScalar sp_d_c = 0.0;
2726
// Parameter file boolean variables
2827
PetscInt WITH_NON_LINEAR = 0; // 1=True, 0=False
@@ -43,8 +42,6 @@ PetscInt bcv_extern = 0; // 1=True, 0=False
4342
PetscInt binary_output = 0; // 1=True, 0=False
4443
PetscInt sticky_blanket_air = 0; // 1=True, 0=False
4544
PetscInt multi_velocity = 0; // 1=True, 0=False
46-
PetscInt precipitation_profile = 0; // 1=True, 0=False
47-
PetscInt climate_change = 0; // 1=True, 0=False
4845
PetscInt free_surface_stab = 1; // 1=True, 0=False
4946
PetscInt print_step_files = 1; // 1=True, 0=False
5047
PetscInt RK4 = 0; // 0=Euler, 1=Runge-Kutta (not working yet!)
@@ -55,7 +52,6 @@ PetscInt high_kappa_in_asthenosphere = 0; // 1=True, 0=False
5552
// Will be added to param.txt
5653
PetscBool sp_surface_tracking = PETSC_FALSE; // PETSC_TRUE/PETSC_FALSE
5754
PetscBool sp_surface_processes = PETSC_FALSE; // PETSC_TRUE/PETSC_FALSE
58-
PetscBool set_sp_dt = PETSC_FALSE; // PETSC_TRUE/PETSC_FALSE
5955
PetscBool set_sp_d_c = PETSC_FALSE; // PETSC_TRUE/PETSC_FALSE
6056
PetscBool plot_sediment = PETSC_FALSE; // PETSC_TRUE/PETSC_FALSE
6157
PetscBool a2l = PETSC_TRUE; // PETSC_TRUE/PETSC_FALSE
@@ -359,34 +355,6 @@ PetscInt cont_mv=0;
359355

360356
PetscInt print_step_aux;
361357

362-
Vec sp_surface_global;
363-
Vec sp_surface_global_n;
364-
Vec sp_surface_coords_global;
365-
Vec sp_top_surface_global;
366-
Vec sp_bot_surface_global;
367-
Vec sp_mean_surface_global;
368-
Vec sp_top_surface_global_n;
369-
Vec sp_bot_surface_global_n;
370-
PetscReal sp_eval_time;
371-
PetscReal sp_last_eval_time;
372-
373-
long sp_n_profiles;
374-
PetscScalar *topo_var_time;
375-
PetscScalar *topo_var_rate;
376-
377-
Vec sp_surface_global_aux;
378-
379-
PetscScalar *global_surface_array_helper;
380-
PetscScalar *global_surface_array_helper_aux;
381-
382-
PetscScalar prec_factor=1.0;
383-
384-
PetscScalar *var_climate_time;
385-
PetscScalar *var_climate_scale;
386-
PetscInt n_var_climate;
387-
PetscInt cont_var_climate=0;
388-
389-
390358
//Rescaled variables for non-dimensional scenarios
391359
//(necessary to calculate the effective viscosity using
392360
//dimensional pressure, temperature, strain rate and cummulative strain)
@@ -412,3 +380,12 @@ PetscReal pressure0_scaled;
412380
PetscReal air_threshold_density;
413381

414382
PetscBool export_kappa = PETSC_FALSE;
383+
384+
// surface processes
385+
DM dmcell_s;
386+
DM dms_s;
387+
PetscInt dms_s_ppe = 2; // dm swarm surface number of particles per element
388+
PetscInt buffer_s;
389+
390+
// sp_mode
391+
// 1 - diffusion

src/main.cpp

Lines changed: 48 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ PetscErrorCode calc_drho();
5050
PetscErrorCode veloc_total(int dimensions);
5151
PetscErrorCode rescaleVeloc(Vec Veloc_fut, double tempo);
5252
PetscErrorCode multi_veloc_change(Vec Veloc_fut,double tempo);
53-
PetscErrorCode sp_create_surface_vec();
54-
PetscErrorCode sp_interpolate_surface_particles_to_vec();
55-
PetscErrorCode evaluate_surface_processes();
56-
PetscErrorCode sp_write_surface_vec(PetscInt i);
57-
PetscErrorCode sp_destroy();
58-
PetscErrorCode rescalePrecipitation(double tempo);
5953
PetscErrorCode parse_options(int rank);
60-
PetscErrorCode load_topo_var(int rank);
6154

55+
PetscErrorCode sp_create_surface_swarm_2d();
56+
PetscErrorCode sp_move_surface_swarm(PetscInt dimensions, PetscReal dt);
57+
PetscErrorCode sp_surface_swarm_interpolation();
58+
PetscErrorCode sp_evaluate_surface_processes(PetscInt dimensions, PetscReal dt);
59+
PetscErrorCode sp_update_surface_swarm_particles_properties();
60+
PetscErrorCode sp_destroy();
61+
PetscErrorCode sp_view_2d(DM dm, const char prefix[]);
6262

6363
int main(int argc,char **args)
6464
{
@@ -96,34 +96,35 @@ int main(int argc,char **args)
9696
seed = rank;
9797

9898
// Parse command line options
99-
parse_options(rank);
99+
ierr = parse_options(rank); CHKERRQ(ierr);
100100

101101
// Read ASCII files
102-
reader(rank, "param.txt");
102+
ierr = reader(rank, "param.txt"); CHKERRQ(ierr);
103103

104104
// Check if the number of interfaces in "param.txt" is higher than then number read from command line
105105
if (seed_layer_set && seed_layer_size > (n_interfaces + 1)) {
106106
PetscPrintf(PETSC_COMM_WORLD, "Error: The number of layers specified in command line \"-seed\" command is higher than the number in \"param.txt\".\n");
107107
}
108108

109+
// Check surface processes configuration
110+
if (sp_surface_processes == PETSC_TRUE && (sp_mode != 1)) {
111+
PetscPrintf(PETSC_COMM_WORLD, "Error: Invalid \"sp_mode\" in \"param.txt\".\n");
112+
exit(1);
113+
}
114+
109115
PetscPrintf(PETSC_COMM_WORLD, "Number of seed layers: %d\n", seed_layer_size);
110116
for (int k = 0; k < seed_layer_size; k++) {
111117
PetscPrintf(PETSC_COMM_WORLD, "seed layer: %d - strain: %lf\n", seed_layer[k], strain_seed_layer[k]);
112118
}
113119
PetscPrintf(PETSC_COMM_WORLD, "\n");
114120

115-
if (sp_surface_processes && sp_surface_tracking && sp_mode == 1) {
116-
load_topo_var(rank);
117-
}
118-
119-
if (sp_mode == 2 && PETSC_FALSE == set_sp_d_c) {
120-
ierr = PetscPrintf(PETSC_COMM_WORLD, "-sp_mode 2 (diffusion) using default value: sp_d_c %e\n", sp_d_c); CHKERRQ(ierr);
121-
} else if (sp_mode == 2) {
122-
ierr = PetscPrintf(PETSC_COMM_WORLD, "-sp_mode 2 (diffusion) using custom value: sp_d_c %e\n", sp_d_c); CHKERRQ(ierr);
123-
} else if (sp_mode == 3) {
124-
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);
125-
} else if (sp_mode == 4) {
126-
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);
121+
// surface processes
122+
if (sp_surface_processes == PETSC_TRUE && sp_mode == 1) {
123+
if (set_sp_d_c == PETSC_FALSE) {
124+
ierr = PetscPrintf(PETSC_COMM_WORLD, "'sp_mode=1' (diffusion) using default value: sp_d_c %e\n", sp_d_c); CHKERRQ(ierr);
125+
} else {
126+
ierr = PetscPrintf(PETSC_COMM_WORLD, "'sp_mode=1' (diffusion) using custom value: sp_d_c %e\n", sp_d_c); CHKERRQ(ierr);
127+
}
127128
}
128129

129130
// Update elements aux constants
@@ -164,17 +165,17 @@ int main(int argc,char **args)
164165
PetscPrintf(PETSC_COMM_WORLD,"Swarm: done\n");
165166
}
166167

167-
// PetscPrintf(PETSC_COMM_SELF,"********** <rank:%d> <particles_per_ele:%d>\n", rank, particles_per_ele); -> conversar com Victor sobre
168-
// PetscPrintf(PETSC_COMM_SELF,"********** <rank:%d> <layers:%d>\n", rank, layers); -> conversar com Victor sobre
168+
if (dimensions == 2 && (sp_surface_tracking)) {
169+
PetscPrintf(PETSC_COMM_WORLD,"\nSurface Processes Swarm (creating)\n");
170+
171+
sp_create_surface_swarm_2d();
169172

170-
// Surface Processes Swarm
171-
if (dimensions == 2 && geoq_on && sp_surface_tracking && n_interfaces>0 && interfaces_from_ascii==1) {
172-
PetscPrintf(PETSC_COMM_WORLD, "\nSP Swarm (creating)\n");
173-
ierr = sp_create_surface_vec(); CHKERRQ(ierr);
174-
PetscPrintf(PETSC_COMM_WORLD, "SP Swarm: done\n");
175-
ierr = sp_interpolate_surface_particles_to_vec(); CHKERRQ(ierr);
173+
PetscPrintf(PETSC_COMM_WORLD,"Surface Processes Swarm: done\n");
176174
}
177175

176+
// PetscPrintf(PETSC_COMM_SELF,"********** <rank:%d> <particles_per_ele:%d>\n", rank, particles_per_ele); -> conversar com Victor sobre
177+
// PetscPrintf(PETSC_COMM_SELF,"********** <rank:%d> <layers:%d>\n", rank, layers); -> conversar com Victor sobre
178+
178179
if (dimensions == 3) {
179180
calc_drho(); // CHECK: does need this call here?
180181
}
@@ -228,8 +229,9 @@ int main(int argc,char **args)
228229
ierr = write_geoq_(tcont,binary_output);
229230
ierr = write_tempo(tcont);
230231

231-
if (dimensions == 2 && sp_surface_tracking && geoq_on && n_interfaces>0 && interfaces_from_ascii==1) {
232-
sp_write_surface_vec(tcont);
232+
if (dimensions == 2 && sp_surface_tracking) {
233+
ierr = PetscSNPrintf(prefix, PETSC_MAX_PATH_LEN-1,"surface_%d", tcont); CHKERRQ(ierr);
234+
ierr = sp_view_2d(dms_s, prefix); CHKERRQ(ierr);
233235
}
234236

235237
VecCopy(Veloc_fut,Veloc);
@@ -242,14 +244,6 @@ int main(int argc,char **args)
242244
PetscPrintf(PETSC_COMM_WORLD, "\n\n*** Using custom initial print_step = %d until %.3g Myr\n\n", print_step, initial_print_max_time);
243245
}
244246

245-
if (dimensions == 2 && sp_surface_processes && PETSC_FALSE == set_sp_dt) {
246-
sp_dt = 10.0 * dt_calor;
247-
PetscPrintf(PETSC_COMM_WORLD, "\n\n*** Using default sp_dt\n\n");
248-
}
249-
250-
sp_eval_time = sp_dt;
251-
sp_last_eval_time = 0.0;
252-
253247
for (tempo = dt_calor,tcont=1;tempo<=timeMAX && tcont<=stepMAX;tempo+=dt_calor, tcont++){
254248
if ((tempo > initial_print_max_time || fabs(tempo-initial_print_max_time) < 0.0001) && initial_print_step > 0) {
255249
initial_print_step = 0;
@@ -277,17 +271,6 @@ int main(int argc,char **args)
277271

278272
ierr = veloc_total(dimensions); CHKERRQ(ierr);
279273

280-
if (dimensions == 2 && sp_surface_processes && geoq_on && n_interfaces>0 && interfaces_from_ascii==1 && (tempo > sp_eval_time || fabs(tempo-sp_eval_time) < 0.0001)) {
281-
PetscPrintf(PETSC_COMM_WORLD,"\nEvaluating sp...\n");
282-
283-
ierr = rescalePrecipitation(tempo);
284-
285-
evaluate_surface_processes();
286-
287-
sp_eval_time += sp_dt;
288-
sp_last_eval_time = tempo;
289-
}
290-
291274
if (geoq_on){
292275
if (RK4==1){
293276
VecCopy(Veloc_fut,Veloc_weight);
@@ -302,6 +285,10 @@ int main(int argc,char **args)
302285
// y a b x
303286
VecAXPBY(Veloc_weight, fac, (1.0-fac),Veloc_fut); //y = a*x + b*y
304287
ierr = moveSwarm(dimensions, dt_calor_sec/max_cont);
288+
289+
if (dimensions == 2 && sp_surface_tracking) {
290+
ierr = sp_move_surface_swarm(dimensions, dt_calor_sec/max_cont); CHKERRQ(ierr);
291+
}
305292
}
306293
}
307294

@@ -312,8 +299,13 @@ int main(int argc,char **args)
312299
}
313300
}
314301

315-
if (dimensions == 2 && sp_surface_tracking && geoq_on && n_interfaces>0 && interfaces_from_ascii==1) {
316-
ierr = sp_interpolate_surface_particles_to_vec(); CHKERRQ(ierr);
302+
if (dimensions == 2 && sp_surface_tracking) {
303+
ierr = sp_surface_swarm_interpolation(); CHKERRQ(ierr);
304+
305+
if (sp_surface_processes) {
306+
ierr = sp_evaluate_surface_processes(dimensions, dt_calor_sec); CHKERRQ(ierr);
307+
ierr = sp_update_surface_swarm_particles_properties(); CHKERRQ(ierr);
308+
}
317309
}
318310

319311
if (tcont%print_step==0){
@@ -334,8 +326,9 @@ int main(int argc,char **args)
334326
}
335327
}
336328

337-
if (dimensions == 2 && sp_surface_tracking && n_interfaces>0 && interfaces_from_ascii==1) {
338-
ierr = sp_write_surface_vec(tcont); CHKERRQ(ierr);
329+
if (dimensions == 2 && sp_surface_tracking) {
330+
ierr = PetscSNPrintf(prefix, PETSC_MAX_PATH_LEN-1,"surface_%d", tcont); CHKERRQ(ierr);
331+
ierr = sp_view_2d(dms_s, prefix); CHKERRQ(ierr);
339332
}
340333
}
341334
}
@@ -351,8 +344,7 @@ int main(int argc,char **args)
351344

352345
destroy_veloc();
353346

354-
355-
if (sp_surface_processes && geoq_on && n_interfaces>0 && interfaces_from_ascii==1) {
347+
if (dimensions == 2 && sp_surface_tracking) {
356348
sp_destroy();
357349
}
358350

@@ -516,17 +508,3 @@ PetscErrorCode multi_veloc_change(Vec Veloc_fut,double tempo){
516508
}
517509
PetscFunctionReturn(0);
518510
}
519-
520-
521-
PetscErrorCode rescalePrecipitation(double tempo)
522-
{
523-
//PetscErrorCode ierr;
524-
if (cont_var_climate<n_var_climate){
525-
if (tempo>1.0E6*var_climate_time[cont_var_climate]){
526-
prec_factor=var_climate_scale[cont_var_climate];
527-
cont_var_climate++;
528-
}
529-
}
530-
531-
PetscFunctionReturn(0);
532-
}

0 commit comments

Comments
 (0)