Skip to content

Commit

Permalink
add new smearing setup
Browse files Browse the repository at this point in the history
  • Loading branch information
tduretz committed Jun 10, 2024
1 parent 6c70638 commit 14a1e0d
Show file tree
Hide file tree
Showing 5 changed files with 390 additions and 10 deletions.
35 changes: 27 additions & 8 deletions JuliaVisualisation/Main_Visualisation_Makie_MD7.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function AddCountourQuivers!(PlotOnTop, ax1, xc, xv, zc, V, T, σ1, Fab, height,
arrows!(ax1, xc./Lc, zc./Lc, Fab.x, Fab.z, arrowsize = 0, lengthscale=Δ/1.5)
end
if PlotOnTop.σ1_axis
arrows!(ax1, xc./Lc, zc./Lc, σ1.x, σ1.z, arrowsize = 0, lengthscale=Δ/1.5)
arrows!(ax1, xc./Lc, zc./Lc, σ1.x, σ1.z, arrowsize = 0, lengthscale=Δ/1.5, color=:white)
end
if PlotOnTop.vel_vec
arrows!(ax1, xc./Lc, zc./Lc, V.x*cm_y, V.z*cm_y, arrowsize = V.arrow, lengthscale = V.scale)
Expand Down Expand Up @@ -57,14 +57,14 @@ function main()

# File numbers
file_start = 00
file_step = 50
file_end = 200
file_step = 10
file_end = 1500

# Select field to visualise
# field = :Phases
field = :Phases
# field = :Cohesion
# field = :Density
field = :Viscosity
# field = :Viscosity
# field = :PlasticStrainrate
# field = :Stress
# field = :StrainRate
Expand All @@ -79,6 +79,8 @@ function main()
# field = :TimeSeries
# field = :AnisotropyFactor
# field = :MeltFraction
# field = :TimeSeries
field = :EffectiveFrictionTime

# Switches
printfig = false # print figures to disk
Expand Down Expand Up @@ -109,6 +111,7 @@ function main()
tc = My
Vc = 1.0

probe = (ϕeff = Float64.([]), t = Float64.([]))
cm_yr = 100.0*3600.0*24.0*365.25

# Time loop
Expand All @@ -128,8 +131,10 @@ function main()
zvx = ExtractData( filename, "/Model/zvx_coord")
xv_hr = ExtractData( filename, "/VizGrid/xviz_hr")
zv_hr = ExtractData( filename, "/VizGrid/zviz_hr")
# τxz_t = ExtractData( filename, "TimeSeries/sxz_mean_time")
# t_t = ExtractData( filename, "TimeSeries/Time_time")
τzz_t = ExtractData( filename, "TimeSeries/szzd_mean_time")
P_t = ExtractData( filename, "TimeSeries/P_mean_time")
τxz_t = ExtractData( filename, "TimeSeries/sxz_mean_time")
t_t = ExtractData( filename, "TimeSeries/Time_time")

xc_hr = 0.5.*(xv_hr[1:end-1] .+ xv_hr[2:end])
zc_hr = 0.5.*(zv_hr[1:end-1] .+ zv_hr[2:end])
Expand Down Expand Up @@ -174,6 +179,7 @@ function main()
ε̇xz = Float64.(reshape(ExtractData( filename, "/Vertices/exz"), nvx, nvz))
τII = sqrt.( 0.5*(τxx.^2 .+ τyy.^2 .+ τzz.^2 .+ 0.5*(τxz[1:end-1,1:end-1].^2 .+ τxz[2:end,1:end-1].^2 .+ τxz[1:end-1,2:end].^2 .+ τxz[2:end,2:end].^2 ) ) ); τII[mask_air] .= NaN
ε̇II = sqrt.( 0.5*(ε̇xx.^2 .+ ε̇yy.^2 .+ ε̇zz.^2 .+ 0.5*(ε̇xz[1:end-1,1:end-1].^2 .+ ε̇xz[2:end,1:end-1].^2 .+ ε̇xz[1:end-1,2:end].^2 .+ ε̇xz[2:end,2:end].^2 ) ) ); ε̇II[mask_air] .= NaN
τxzc = 0.25*(τxz[1:end-1,1:end-1] .+ τxz[2:end,1:end-1] .+ τxz[1:end-1,2:end] .+ τxz[2:end,2:end])
C = Float64.(reshape(ExtractData( filename, "/Centers/cohesion"), ncx, ncz))
ϕ = ExtractField(filename, "/Centers/phi", centroids, false, 0)
divu = ExtractField(filename, "/Centers/divu", centroids, false, 0)
Expand Down Expand Up @@ -425,7 +431,20 @@ function main()

if field==:TimeSeries
ax1 = Axis(f[1, 1], title = L"$τ_{xz}$", xlabel = L"$t$", ylabel = L"$\tau_{xz}$")
lines!(ax1, t_t, τxz_t)
τxz_t[1] = 0.
@show .-τxz_t
lines!(ax1, t_t, .-τxz_t./(.-P_t.+τzz_t))
end

if field==:EffectiveFrictionTime
ϕ_eff = -mean(τxzc[:,end] ./ (τzz[:,end] .- P[:,end]) )
if istep==0 ϕ_eff = 0. end
push!(probe.ϕeff, ϕ_eff)
push!(probe.t, t)
@show Float64.(probe.t)
ax1 = Axis(f[1, 1], title = L"$ϕ_eff$", xlabel = L"$t$", ylabel = L"$ϕ_eff$")
lines!(ax1, Float64.(probe.t), Float64.(probe.ϕeff))

end

DataInspector(f)
Expand Down
4 changes: 4 additions & 0 deletions MDLIB/InputOutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,10 @@ Input ReadInputFile( char *fileName ) {
materials.psi[k] = ReadMatProps( fin, "psi", k, 0.0 ) * M_PI/ 180.0;
if (materials.psi[k]>0.0 && model.compressible==0) { printf("Set compressible=1 to activate dilation\n"); exit(1); }
materials.Slim[k] = ReadMatProps( fin, "Slim" ,k, 1.0e90 ) / scaling.S;
if (materials.Slim[k]<materials.C[k]) {
printf("Upper stress limiter of phase %d is lower than cohesion: it makes no sense, please correct!\n", k);
exit(1);
}
// Viscoplasticity
materials.n_vp[k] = ReadMatProps( fin, "n_vp", k, 1.0 ) ;
materials.eta_vp[k] = ReadMatProps( fin, "eta_vp", k, 0.0 ) / scaling.S / pow(scaling.t, 1.0/materials.n_vp[k]);
Expand Down
5 changes: 3 additions & 2 deletions MDLIB/RheologyDensity.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ double ViscosityConcise( int phase, double G, double T, double P, double d, doub
*Pcorr = P;

//------------------------------------------------------------------------//
// printf("%d\n", materials->cstv[phase]);

// Activate deformation mechanisms
if ( materials->cstv[phase] !=0 ) constant = 1;
Expand Down Expand Up @@ -628,7 +629,7 @@ double ViscosityConcise( int phase, double G, double T, double P, double d, doub
// Check yield stress
F_trial = Tii - Tyield;

// if (F_trial>0) printf("%2.2e %2.2e %2.2e %2.2e %2.2e\n", F_trial*scaling->S, C*scaling->S, cos_fric, P*scaling->S, sin_fric);
// if (F_trial>0) printf("F=%2.2e C=%2.2e cos_fric=%2.2e P=%2.2e sin_fric=%2.2e\n", F_trial*scaling->S, C*scaling->S, cos_fric, P*scaling->S, sin_fric);

double Tiic;
double Pc_chk;
Expand Down Expand Up @@ -775,7 +776,7 @@ double ViscosityConcise( int phase, double G, double T, double P, double d, doub
if (is_pl == 1) inv_eta_diss += (1.0/eta_pl );
eta = 1.0/(inv_eta_diss);
// if (T*scaling->T<673.0) {
// printf("constant = %d %2.2e %2.2e %2.2e %2.2e\n", constant, eta*scaling->eta, eta_pwl*scaling->eta, eta_pl*scaling->eta, eta_cst*scaling->eta);
// printf("constant = %d eta = %2.2e eta_pl = %2.2e %2.2e %2.2e %2.2e\n", constant, eta*scaling->eta, eta_pl*scaling->eta, eta_pwl*scaling->eta, eta_pl*scaling->eta, eta_cst*scaling->eta);
// }

// Viscoplastic overstress
Expand Down
186 changes: 186 additions & 0 deletions SETS/FaultSmearing.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#include "math.h"
#include "mdoodz.h"
#include "stdio.h"
#include "stdlib.h"

int SetDualPhase(MdoodzInput *input, Coordinates coordinate, int phase) {

int dual_phase = phase;
double Lx = input->model.xmax - input->model.xmin;
double Lz = input->model.zmax - input->model.zmin;
double Ax, Az;

// Set checkerboard for phase 0
Ax = cos( 10.0*2.0*M_PI*coordinate.x / Lx );
Az = cos( 10.0*2.0*M_PI*coordinate.z / Lz );
if ( ( (Az<0.0 && Ax<0.0) || (Az>0.0 && Ax>0.0) ) && dual_phase==0 ) {
dual_phase += input->model.Nb_phases;
}

// // Set checkerboard for phase 2
// Ax = cos( 10.0*2.0*M_PI*coordinate.x / Lx );
// Az = cos( 10.0*2.0*M_PI*coordinate.z / Lz );
// if ( ( (Az<0.0 && Ax<0.0) || (Az>0.0 && Ax>0.0) ) && dual_phase==2 ) {
// dual_phase += input->model.Nb_phases;
// }

return dual_phase;
}

char *ReadGeometryFile(char *inputFile, int nb_elems) {
char *ph_hr = malloc((nb_elems) * sizeof(char));
FILE *fid = fopen(inputFile, "rb");
if (!fid) {
fprintf(stderr, "\nUnable to open file %s. I will exit here ... \n", inputFile);
exit(2);
}
fread(ph_hr, sizeof(char), nb_elems, fid);
fclose(fid);
return ph_hr;
}

void MutateInput(MdoodzInput *input) {
if (input->model.user0 == 0) {
printf("Phase map to be drawn in a SetParticles\n");
return;
} else if (input->model.user0 == 1) {
char *fileName = input->model.import_file;
char inputFilePath[255];
sprintf(inputFilePath, "%s/%s", input->model.import_files_dir, input->model.import_file);
printf("Phase map will be built based on %s\n", fileName);
const int nx = (int) (input->model.user7);
const int nz = nx;
const int nb_elems = nx * nz;
input->geometry = malloc(sizeof(Geometry));
input->geometry[0] = (Geometry){
.nx = nx,
.nz = nz,
.nb_elems = nb_elems,
.ph_hr = ReadGeometryFile(inputFilePath, nb_elems),
};
}
}

int SetPhase(MdoodzInput *input, Coordinates coordinates) {
if (input->geometry) {
const int nx = input->geometry->nx+1;
const int nz = input->geometry->nz+1;
// ------------------------- //
// Locate markers in the image files
// Find index of minimum/west temperature node
double dx_hr = (input->model.xmax - input->model.xmin) / (nx-1);
double dz_hr = (input->model.zmax - input->model.zmin) / (nz-1);
double dstx = (coordinates.x - input->model.xmin);
int ix = (int) ceil(dstx / dx_hr) - 1;
// Find index of minimum/west pressure node
double dstz = (coordinates.z - input->model.zmin);
int iz = (int) ceil(dstz / dz_hr) - 1;
// Attribute phase
if (ix < 0) {
printf("sauceisse!!!\n");
exit(1);
}
if (iz < 0) {
printf("puréee!!!\n");
exit(1);
}
if (ix + iz * (nx-1) > input->geometry->nb_elems) {
printf("puréee!!!\n");
exit(1);
}
// Default: phase from input file
int phase = input->geometry->ph_hr[ix + iz * (nx-1)];
// Add seed
const double radius = input->model.user1 / input->scaling.L;
const double theta = -0.0 * M_PI / 180.0;
const double Xn = coordinates.x * cos(theta) - coordinates.z * sin(theta);
const double Zn = coordinates.x * sin(theta) + coordinates.z * cos(theta);
if ( (pow(Xn / radius / 1.0, 2) + pow(Zn / radius / 1.0, 2) - 1.0) < 0) {
phase = 1;
}
return phase;
}
else {
// Simple setup with only one seed
const double radius = input->model.user1 / input->scaling.L;
const double theta = -0.0 * M_PI / 180.0;
const double Xn = coordinates.x * cos(theta) - coordinates.z * sin(theta);
const double Zn = coordinates.x * sin(theta) + coordinates.z * cos(theta);
if ( (pow(Xn / radius / 1.0, 2) + pow(Zn / radius / 1.0, 2) - 1.0) < 0) {
return 1;
} else {
return 0;
}
}
}

double SetNoise(MdoodzInput *input, Coordinates coordinates, int phase) {
// srand(69);
return ((double) rand() / (double) RAND_MAX) - 0.5;
}

double SetPressure(MdoodzInput *input, Coordinates coordinates, int phase) {
return input->model.bkg_pressure;
}

// SetBC SetBCVx(MdoodzInput *instance, POSITION position, Coordinates coordinates) {
// SetBC bc;
// const double x = coordinates.x;

// // Assign BC values
// if (position == N || position == S || position == NW || position == SW || position == NE || position == SE) {
// bc.value = 0;
// bc.type = 13;
// } else if (position == W || position == E) {
// bc.value = -x * (instance->model.bkg_strain_rate - instance->model.bkg_div_rate/3.0);
// bc.type = 0;
// } else {
// bc.value = 0.0;
// bc.type = -1;
// }
// return bc;
// }

// SetBC SetBCVz(MdoodzInput *instance, POSITION position, Coordinates coordinates) {
// SetBC bc;
// const double z = coordinates.z;

// // Set boundary nodes types and values
// if (position == W || position == SW || position == NW || position == E || position == SE || position == NE ) {
// bc.value = 0.0;
// bc.type = 13;
// } else if (position == S || position == N) {
// bc.value = z * (instance->model.bkg_strain_rate + instance->model.bkg_div_rate/3.0);
// bc.type = 0;
// } else {
// bc.value = 0;
// bc.type = -1;
// }
// return bc;
// }

int main(int nargs, char *args[]) {
// Input file name
char *input_file;
if ( nargs < 2 ) {
asprintf(&input_file, "FaultSmearing.txt"); // Default
}
else {
asprintf(&input_file, "%s", args[1]); // Custom
}
printf("Running MDoodz7.0 using %s\n", input_file);
MdoodzSetup setup = {
.SetParticles = &(SetParticles_ff){
.SetPhase = SetPhase,
.SetNoise = SetNoise,
.SetPressure = SetPressure,
.SetDualPhase = SetDualPhase,
},
.SetBCs = &(SetBCs_ff){
.SetBCVx = SetPureOrSimpleShearBCVx,
.SetBCVz = SetPureOrSimpleShearBCVz,
},
.MutateInput = MutateInput,
};
RunMDOODZ(input_file, &setup);
}
Loading

0 comments on commit 14a1e0d

Please sign in to comment.