Skip to content

Commit

Permalink
Re-introduced sequential ox output (ox_seq) (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnende authored Jul 22, 2020
1 parent 64380d6 commit aa37cd8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/running_simulations.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ QDYN offers various optional simulation features. Set the following parameters t

| Parameter | Description | Default value |
| :----------: | ------------------------------------------------------------ | :-----------: |
| `OX_SEQ` | Type of snapshot outputs:<br />`0` = All snapshots in a single output file (`output_ox`)<br />`1` = One output file per snapshot (`output_ox_1`, `output_ox_2`, ...) | `0` |
| `NWOUT` | Spatial interval for snapshot output (in number of elements along-dip) | `1` |
| `NXOUT` | Spatial interval for snapshot output (in number of elements along-strike) | `1` |
| `NTOUT` | Temporal interval (in number of time steps) for snapshot output | `1` |
Expand Down
2 changes: 1 addition & 1 deletion src/input.f90
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ subroutine read_main(pb)
endif
read(15,*) pb%features%stress_coupling, pb%features%tp, pb%features%localisation
read(15,*) pb%ot%ntout, pb%ox%ntout, pb%ot%ic, pb%ox%nxout, pb%ox%nwout, &
pb%ox%nxout_dyn, pb%ox%nwout_dyn, pb%ox%i_ox_dyn
pb%ox%nxout_dyn, pb%ox%nwout_dyn, pb%ox%i_ox_seq, pb%ox%i_ox_dyn
read(15,*) pb%beta, pb%smu, pb%lam, pb%D, pb%H, pb%ot%v_th
read(15,*) pb%Tper, pb%Aper
read(15,*) pb%dt_try, pb%dt_max,pb%tmax, pb%acc
Expand Down
30 changes: 22 additions & 8 deletions src/output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ subroutine ox_init(pb)

type (problem_type), intent(inout) :: pb

integer :: n, count_w, count_x
integer :: count_w, count_x, n

! Number of mesh elements
n = pb%mesh%nn
Expand All @@ -413,6 +413,8 @@ subroutine ox_init(pb)
pb%ox%count = count_w * count_x
! Initial potency
pb%ox%pot_pre = 0.d0
! Initial snapshot count
pb%ox%seq_count = 0

! ---------------------------------------------------------------------------
! Prepare data structure and headers for ox, ox_dyn, and dyn output
Expand Down Expand Up @@ -441,9 +443,11 @@ subroutine ox_init(pb)

endif

! Create ox file
open(FID_OX, file=FILE_OX, status="replace")
close(FID_OX)
! Create ox file (if not split over multiple files)
if (pb%ox%i_ox_seq == 0) then
open(FID_OX, file=FILE_OX, status="replace")
close(FID_OX)
endif

! Define headers
pb%ox%header = '# t x y z v theta tau tau_dot slip sigma'
Expand Down Expand Up @@ -594,7 +598,8 @@ subroutine ox_write(pb)

integer :: iw, ix, n, nwout_dyn, nxout_dyn, unit
logical :: call_gather, close_unit, dynamic, falling_edge, last_call, &
MPI_master, skip, rising_edge, write_ox, write_ox_dyn, write_QSB
MPI_master, skip, rising_edge, write_ox, write_ox_dyn, &
write_ox_seq, write_QSB
double precision, dimension(pb%mesh%nnglob) :: tau, v
character(len=100) :: tmp
character(len=100), allocatable :: file_name
Expand Down Expand Up @@ -630,6 +635,7 @@ subroutine ox_write(pb)
write_ox = (mod(pb%it, pb%ox%ntout) == 0 .or. last_call) .and. MPI_master
write_ox_dyn = ((pb%ox%i_ox_dyn == 1) .and. dynamic) .and. &
MPI_master .and. .not. skip
write_ox_seq = write_ox .and. (pb%ox%i_ox_seq == 1) .and. MPI_master
write_QSB = ((pb%DYN_FLAG == 1) .and. dynamic) .and. &
MPI_master .and. .not. skip

Expand Down Expand Up @@ -660,8 +666,18 @@ subroutine ox_write(pb)

if (write_ox) then

pb%ox%seq_count = pb%ox%seq_count + 1

! Check if data needs to be written to separate file
if (write_ox_seq) then
write(tmp, "(a, a, i0)") FILE_OX, "_", pb%ox%seq_count
file_name = trim(tmp)
open(FID_OX, file=file_name, status="replace")
else
open(FID_OX, file=FILE_OX, status="old", position="append")
endif

! Write ox data
open(FID_OX, file=FILE_OX, status="old", position="append")
call write_ox_lines(FID_OX, pb%ox%fmt, pb%objects_glob, &
pb%ox%nxout, pb%ox%nwout, pb)
close(FID_OX)
Expand Down Expand Up @@ -694,7 +710,6 @@ subroutine ox_write(pb)
write(tmp, "(a, i0)") FILE_OX_DYN_PRE, pb%ox%dyn_count
file_name = trim(tmp)
open(unit, file=file_name, status="replace")
write(unit, "(a)") pb%ox%header
call write_ox_lines(unit, pb%ox%fmt, pb%objects_glob, &
pb%ox%nxout_dyn, pb%ox%nwout_dyn, pb)
! Close output unit
Expand All @@ -712,7 +727,6 @@ subroutine ox_write(pb)
file_name = trim(tmp)
! Write ox data
open(unit, file=file_name, status="replace")
write(unit, "(a)") pb%ox%header
call write_ox_lines(unit, pb%ox%fmt, pb%objects_glob, &
pb%ox%nxout_dyn, pb%ox%nwout_dyn, pb)
! Close output unit
Expand Down
2 changes: 1 addition & 1 deletion src/problem_class.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module problem_class
! snapshot outputs: at every fault point, but only at few selected times
type ox_type
integer :: ntout=0, nrup=-1
integer :: count, dyn_count, dyn_stat, i_ox_dyn
integer :: count, dyn_count, dyn_stat, i_ox_dyn, i_ox_seq, seq_count
integer :: nwout, nwout_dyn, nxout, nxout_dyn
double precision :: pot_pre
character(len=256) :: header
Expand Down
9 changes: 2 additions & 7 deletions src/pyqdyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def __init__(self):
set_dict["NTOUT"] = 1 # Temporal interval (number of time steps) for snapshot output
set_dict["NXOUT"] = 1 # Spatial interval (number of elements in x-direction) for snapshot output
set_dict["NWOUT"] = 1 # Spatial interval (number of elements in y-direction) for snapshot output
set_dict["OX_SEQ"] = 0 # Type of snapshot outputs (0: all snapshots in single file, 1: one file per snapshot) - DEPRECATED
set_dict["OX_SEQ"] = 0 # Type of snapshot outputs (0: all snapshots in single file, 1: one file per snapshot)
set_dict["OX_DYN"] = 0 # Output specific snapshots of dynamic events defined by thresholds on peak slip velocity DYN_TH_ON and DYN_TH_OFF
set_dict["NXOUT_DYN"] = 1 # Spatial interval (number of elements in x-direction) for dynamic snapshot outputs
set_dict["NWOUT_DYN"] = 1 # Spatial interval (number of elements in y-direction) for dynamic snapshot outputs
Expand Down Expand Up @@ -322,11 +322,6 @@ def write_input(self):
print("The mesh has not yet been rendered!")
exit()

if self.set_dict["OX_SEQ"] == 1:
print("Warning: OX_SEQ = 1 is no longer supported by the snapshot output module.")
print("All snapshots are combined into a single output file (default).")
print("This legacy code will be removed in a future release.")

# Optionally, output can be created to an external working directory
# This is still experimental...
if self.work_dir != "":
Expand Down Expand Up @@ -395,7 +390,7 @@ def write_input(self):
exit()
input_str += "%u%s N_creep\n" % (N_creep, delimiter)
input_str += "%u %u %u%s stress_coupling, thermal press., localisation\n" % (settings["FEAT_STRESS_COUPL"], settings["FEAT_TP"], settings["FEAT_LOCALISATION"], delimiter)
input_str += "%u %u %u %u %u %u %u %u%s ntout_ot, ntout_ox, nt_coord, nxout, nwout, nxout_DYN, nwout_DYN, ox_DYN\n" % (settings["NTOUT_OT"], settings["NTOUT"], settings["IC"]+1, settings["NXOUT"], settings["NWOUT"], settings["NXOUT_DYN"], settings["NWOUT_DYN"], settings["OX_DYN"], delimiter)
input_str += "%u %u %u %u %u %u %u %u %u%s ntout_ot, ntout_ox, nt_coord, nxout, nwout, nxout_DYN, nwout_DYN, ox_seq, ox_DYN\n" % (settings["NTOUT_OT"], settings["NTOUT"], settings["IC"]+1, settings["NXOUT"], settings["NWOUT"], settings["NXOUT_DYN"], settings["NWOUT_DYN"], settings["OX_SEQ"], settings["OX_DYN"], delimiter)
input_str += "%.15g %.15g %.15g %.15g %.15g %.15g%s beta, smu, lambda, v_th\n" % (settings["VS"], settings["MU"], settings["LAM"], settings["D"], settings["HD"], settings["V_TH"], delimiter)
input_str += "%.15g %.15g%s Tper, Aper\n" % (settings["TPER"], settings["APER"], delimiter)
input_str += "%.15g %.15g %.15g %.15g%s dt_try, dtmax, tmax, accuracy\n" % (settings["DTTRY"] ,settings["DTMAX"] ,settings["TMAX"] ,settings["ACC"] , delimiter)
Expand Down
4 changes: 2 additions & 2 deletions src/qdyn.m
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ function export_main_input()
fprintf(fid,'%u i_rns_law\n', RNS_LAW);
fprintf(fid,'%u i_sigma_cpl\n', SIGMA_CPL);
fprintf(fid,'0 0 0 stress_coupling, thermal press., localisation\n');
fprintf(fid,'%u %u %u %u %u %u %u ntout_ot, ntout, nt_coord, nxout, nwout, nxout_DYN, nwout_DYN, ox_DYN\n', ...
NTOUT_OT, NTOUT,IC,NXOUT,NWOUT,NXOUT_DYN,NWOUT_DYN,OX_DYN);
fprintf(fid,'%u %u %u %u %u %u %u ntout_ot, ntout, nt_coord, nxout, nwout, nxout_DYN, nwout_DYN, ox_seq ox_DYN\n', ...
NTOUT_OT, NTOUT,IC,NXOUT,NWOUT,NXOUT_DYN,NWOUT_DYN,OX_SEQ,OX_DYN);
fprintf(fid,'%.15g %.15g %.15g %.15g %.15g %.15g beta, smu, lambda, D, H, v_th\n', ...
VS, MU, LAM, D, H, V_TH);
fprintf(fid,'%.15g %.15g Tper, Aper\n',TPER,APER);
Expand Down

0 comments on commit aa37cd8

Please sign in to comment.