Skip to content

Commit 4912896

Browse files
committed
apply runic formatting changes
1 parent 2d8c02c commit 4912896

File tree

3 files changed

+126
-130
lines changed

3 files changed

+126
-130
lines changed

src/LaMEM_io.jl

Lines changed: 88 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -550,24 +550,24 @@ function get_ind(x, xc, Nprocx)
550550
end
551551

552552
# Same as get_ind but without the need for the x vector
553-
function get_ind2(dx,xc,Nprocx)
553+
function get_ind2(dx, xc, Nprocx)
554554

555555
if Nprocx == 1
556-
xi = Int(round((xc[end] - xc[1]) / dx));
557-
ix_start = [1];
558-
ix_end = [xi];
556+
xi = Int(round((xc[end] - xc[1]) / dx))
557+
ix_start = [1]
558+
ix_end = [xi]
559559
else
560560
xi = zeros(Int64, Nprocx)
561-
for k = 1:Nprocx
562-
xi[k] = round((xc[k+1] - xc[k])/dx);
561+
for k in 1:Nprocx
562+
xi[k] = round((xc[k + 1] - xc[k]) / dx)
563563
end
564564

565565
ix_start = cumsum([0; xi[1:(end - 1)]]) .+ 1
566566
ix_end = cumsum(xi[1:end])
567567

568568
end
569569

570-
return xi,ix_start,ix_end
570+
return xi, ix_start, ix_end
571571

572572
end
573573

@@ -1112,11 +1112,7 @@ function Base.show(io::IO, d::LaMEM_partitioning_info)
11121112
end
11131113

11141114
function check_markers_directory(directory)
1115-
1116-
if !isdir(directory)
1117-
mkdir(directory)
1118-
end
1119-
1115+
return if !isdir(directory) mkdir(directory) end
11201116
end
11211117

11221118
function get_LaMEM_grid_info(file; args::Union{String, Nothing} = nothing)
@@ -1151,13 +1147,13 @@ function get_LaMEM_grid_info(file; args::Union{String, Nothing} = nothing)
11511147
Grid = LaMEM_grid(
11521148
nmark_x, nmark_y, nmark_z,
11531149
nump_x, nump_y, nump_z,
1154-
nel_x, nel_y, nel_z,
1150+
nel_x, nel_y, nel_z,
11551151
W, L, H,
11561152
parsed_x, parsed_y, parsed_z,
1157-
[],[],[],
1158-
[],[],[],
1159-
[],[],[],
1160-
[],[],[]
1153+
[], [], [],
1154+
[], [], [],
1155+
[], [], [],
1156+
[], [], []
11611157
)
11621158

11631159
return Grid
@@ -1172,28 +1168,28 @@ end
11721168
P: LaMEM_partitioning_info
11731169
Returns a LaMEM_partitioning_info object with the distribution of particles in the grid
11741170
"""
1175-
function get_particles_distribution(Grid,P)
1171+
function get_particles_distribution(Grid, P)
11761172

11771173
# get number of processors and processor coordnate bounds
1178-
nProcX = P.nProcX;
1179-
nProcY = P.nProcY;
1180-
nProcZ = P.nProcZ;
1181-
xc = P.xc;
1182-
yc = P.yc;
1183-
zc = P.zc;
1174+
nProcX = P.nProcX
1175+
nProcY = P.nProcY
1176+
nProcZ = P.nProcZ
1177+
xc = P.xc
1178+
yc = P.yc
1179+
zc = P.zc
11841180

1185-
(num, num_i, num_j, num_k) = get_numscheme(nProcX, nProcY, nProcZ);
1181+
(num, num_i, num_j, num_k) = get_numscheme(nProcX, nProcY, nProcZ)
11861182

1187-
dx = Grid.W/Grid.nump_x;
1188-
dy = Grid.L/Grid.nump_y;
1189-
dz = Grid.H/Grid.nump_z;
1183+
dx = Grid.W / Grid.nump_x
1184+
dy = Grid.L / Grid.nump_y
1185+
dz = Grid.H / Grid.nump_z
11901186

11911187
# % Get particles of respective procs
11921188
# % xi - amount of particles in x direction in each core
11931189
# % ix_start - indexes where they start for each core
1194-
(xi,ix_start,ix_end) = get_ind2(dx,xc,nProcX);
1195-
(yi,iy_start,iy_end) = get_ind2(dy,yc,nProcY);
1196-
(zi,iz_start,iz_end) = get_ind2(dz,zc,nProcZ);
1190+
(xi, ix_start, ix_end) = get_ind2(dx, xc, nProcX)
1191+
(yi, iy_start, iy_end) = get_ind2(dy, yc, nProcY)
1192+
(zi, iz_start, iz_end) = get_ind2(dz, zc, nProcZ)
11971193

11981194
x_start = ix_start[num_i[:]]
11991195
y_start = iy_start[num_j[:]]
@@ -1202,7 +1198,7 @@ function get_particles_distribution(Grid,P)
12021198
y_end = iy_end[num_j[:]]
12031199
z_end = iz_end[num_k[:]]
12041200

1205-
p_dist = particles_distribution(x_start,x_end,y_start,y_end,z_start,z_end);
1201+
p_dist = particles_distribution(x_start, x_end, y_start, y_end, z_start, z_end)
12061202

12071203
return p_dist
12081204

@@ -1218,23 +1214,23 @@ end
12181214
RandomNoise: add random noise to the grid (0/1)
12191215
Returns a LaMEM_grid object with the local grid for the current processor
12201216
"""
1221-
function get_proc_grid(Grid_info,p_dist,proc_bounds,proc_num,RandomNoise)
1217+
function get_proc_grid(Grid_info, p_dist, proc_bounds, proc_num, RandomNoise)
12221218

1223-
x_proc_bound = proc_bounds[1];
1224-
y_proc_bound = proc_bounds[2];
1225-
z_proc_bound = proc_bounds[3];
1219+
x_proc_bound = proc_bounds[1]
1220+
y_proc_bound = proc_bounds[2]
1221+
z_proc_bound = proc_bounds[3]
12261222

12271223
loc_nump_x = p_dist.x_end[proc_num] - p_dist.x_start[proc_num] + 1
12281224
loc_nump_y = p_dist.y_end[proc_num] - p_dist.y_start[proc_num] + 1
12291225
loc_nump_z = p_dist.z_end[proc_num] - p_dist.z_start[proc_num] + 1
1230-
1231-
loc_nel_x = loc_nump_x/Grid_info.nmark_x
1232-
loc_nel_y = loc_nump_y/Grid_info.nmark_y
1233-
loc_nel_z = loc_nump_z/Grid_info.nmark_z
12341226

1235-
x = range(x_proc_bound[1], x_proc_bound[2], length=loc_nump_x)
1236-
y = range(y_proc_bound[1], y_proc_bound[2], length=loc_nump_y)
1237-
z = range(z_proc_bound[1], z_proc_bound[2], length=loc_nump_z)
1227+
loc_nel_x = loc_nump_x / Grid_info.nmark_x
1228+
loc_nel_y = loc_nump_y / Grid_info.nmark_y
1229+
loc_nel_z = loc_nump_z / Grid_info.nmark_z
1230+
1231+
x = range(x_proc_bound[1], x_proc_bound[2], length = loc_nump_x)
1232+
y = range(y_proc_bound[1], y_proc_bound[2], length = loc_nump_y)
1233+
z = range(z_proc_bound[1], z_proc_bound[2], length = loc_nump_z)
12381234

12391235
# marker grid
12401236
X, Y, Z = GeophysicalModelGenerator.xyz_grid(x, y, z)
@@ -1244,27 +1240,27 @@ function get_proc_grid(Grid_info,p_dist,proc_bounds,proc_num,RandomNoise)
12441240
H = z_proc_bound[2] - z_proc_bound[1]
12451241

12461242
if RandomNoise == 1
1247-
dx = x[2] - x[1]
1248-
dy = y[2] - y[1]
1249-
dz = z[2] - z[1]
1250-
dXNoise = zeros(size(X)) + dx;
1251-
dYNoise = zeros(size(Y)) + dy;
1252-
dZNoise = zeros(size(Z)) + dz;
1253-
1254-
dXNoise = dXNoise.*(rand(size(dXNoise))-0.5);
1255-
dYNoise = dYNoise.*(rand(size(dYNoise))-0.5);
1256-
dZNoise = dZNoise.*(rand(size(dZNoise))-0.5);
1257-
1258-
Xpart = X + dXNoise;
1259-
Ypart = Y + dYNoise;
1260-
Zpart = Z + dZNoise;
1261-
1262-
X = Xpart;
1263-
Y = Ypart;
1264-
Z = Zpart;
1265-
x = X(1,:,1);
1266-
y = Y(:,1,1);
1267-
z = Z(1,1,:);
1243+
dx = x[2] - x[1]
1244+
dy = y[2] - y[1]
1245+
dz = z[2] - z[1]
1246+
dXNoise = zeros(size(X)) + dx
1247+
dYNoise = zeros(size(Y)) + dy
1248+
dZNoise = zeros(size(Z)) + dz
1249+
1250+
dXNoise = dXNoise .* (rand(size(dXNoise)) - 0.5)
1251+
dYNoise = dYNoise .* (rand(size(dYNoise)) - 0.5)
1252+
dZNoise = dZNoise .* (rand(size(dZNoise)) - 0.5)
1253+
1254+
Xpart = X + dXNoise
1255+
Ypart = Y + dYNoise
1256+
Zpart = Z + dZNoise
1257+
1258+
X = Xpart
1259+
Y = Ypart
1260+
Z = Zpart
1261+
x = X(1, :, 1)
1262+
y = Y(:, 1, 1)
1263+
z = Z(1, 1, :)
12681264

12691265
end
12701266

@@ -1310,36 +1306,36 @@ p_dist_example = get_particles_distribution(Grid_example,P_example)
13101306
proc_bounds = get_proc_bound(Grid_example,p_dist_example,2)
13111307
```
13121308
"""
1313-
function get_proc_bound(Grid,p_dist,proc_num)
1309+
function get_proc_bound(Grid, p_dist, proc_num)
13141310

1315-
dx = Grid.W/Grid.nump_x;
1316-
dy = Grid.L/Grid.nump_y;
1317-
dz = Grid.H/Grid.nump_z;
1311+
dx = Grid.W / Grid.nump_x
1312+
dy = Grid.L / Grid.nump_y
1313+
dz = Grid.H / Grid.nump_z
13181314

1319-
parsed_x = Grid.coord_x
1320-
parsed_y = Grid.coord_y
1321-
parsed_z = Grid.coord_z
1315+
parsed_x = Grid.coord_x
1316+
parsed_y = Grid.coord_y
1317+
parsed_z = Grid.coord_z
13221318

1323-
model_x = [ parsed_x[1] + dx/2, parsed_x[end] - dx/2 ]
1324-
model_y = [ parsed_y[1] + dy/2, parsed_y[end] - dy/2 ]
1325-
model_z = [ parsed_z[1] + dz/2, parsed_z[end] - dz/2 ]
1319+
model_x = [parsed_x[1] + dx / 2, parsed_x[end] - dx / 2]
1320+
model_y = [parsed_y[1] + dy / 2, parsed_y[end] - dy / 2]
1321+
model_z = [parsed_z[1] + dz / 2, parsed_z[end] - dz / 2]
13261322

1327-
x_left = model_x[1];
1328-
y_front = model_y[1];
1329-
z_bot = model_z[1];
1323+
x_left = model_x[1]
1324+
y_front = model_y[1]
1325+
z_bot = model_z[1]
13301326

1331-
x_start = p_dist.x_start;
1332-
x_end = p_dist.x_end;
1333-
y_start = p_dist.y_start;
1334-
y_end = p_dist.y_end;
1335-
z_start = p_dist.z_start;
1336-
z_end = p_dist.z_end;
1327+
x_start = p_dist.x_start
1328+
x_end = p_dist.x_end
1329+
y_start = p_dist.y_start
1330+
y_end = p_dist.y_end
1331+
z_start = p_dist.z_start
1332+
z_end = p_dist.z_end
13371333

1338-
x_proc_bound = [ x_left + dx*( x_start[proc_num] - 1 ), x_left + dx*( x_end[proc_num] - 1 ) ];
1339-
y_proc_bound = [ y_front + dy*( y_start[proc_num] - 1 ), y_front + dy*( y_end[proc_num] - 1 ) ];
1340-
z_proc_bound = [ z_bot + dz*( z_start[proc_num] - 1 ), z_bot + dz*( z_end[proc_num] - 1 ) ];
1334+
x_proc_bound = [x_left + dx * (x_start[proc_num] - 1), x_left + dx * (x_end[proc_num] - 1)]
1335+
y_proc_bound = [y_front + dy * (y_start[proc_num] - 1), y_front + dy * (y_end[proc_num] - 1)]
1336+
z_proc_bound = [z_bot + dz * (z_start[proc_num] - 1), z_bot + dz * (z_end[proc_num] - 1)]
13411337

1342-
return [ x_proc_bound, y_proc_bound, z_proc_bound ]
1338+
return [x_proc_bound, y_proc_bound, z_proc_bound]
13431339

13441340
end
13451341

@@ -1354,7 +1350,7 @@ end
13541350
function crop_bounds(uncropped_bounds, proc_bounds, x, y, z)
13551351

13561352
# Crop boundaries from the whole model to only the extent of the current processor
1357-
vecs = [x, y, z]
1353+
vecs = [x, y, z]
13581354
new_bounds = [zeros(size(vecs[i])) for i in eachindex(vecs)]
13591355
for i in eachindex(vecs)
13601356
vec = vecs[i]
@@ -1394,7 +1390,7 @@ function crop_bounds(uncropped_bounds, proc_bounds, x, y, z)
13941390
end
13951391

13961392
function closest_val(val, vec)
1397-
return vec[argmin(abs.(vec .- val))]
1393+
return vec[argmin(abs.(vec .- val))]
13981394
end
13991395

14001396
"""
@@ -1555,9 +1551,9 @@ function setup_model_domain(coord_x::AbstractVector{<:Real},
15551551
xcoor[ix], ycoor[iy],zcoor[iz]
15561552
)
15571553

1558-
xcoor=[]
1559-
ycoor=[]
1560-
zcoor=[]
1554+
xcoor = []
1555+
ycoor = []
1556+
zcoor = []
15611557

15621558
return P
15631559

test/test_lamem.jl

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ zcoords_ans=[-6.4, 6.4];
5454
nProcX_ans = 4; nProcY_ans = 2; nProcZ_ans = 1;
5555
nNodeX_ans = 129; nNodeY_ans = 65; nNodeZ_ans = 33;
5656
P = setup_model_domain([extrema(xcoords_ans)...], [extrema(ycoords_ans)...], [extrema(zcoords_ans)...], nx, ny, nz, n_ranks)
57-
@test isapprox(nProcX_ans, P.nProcX; atol=1e-8)
58-
@test isapprox(nProcY_ans, P.nProcY; atol=1e-8)
59-
@test isapprox(nProcZ_ans, P.nProcZ; atol=1e-8)
60-
@test isapprox(xcoords_ans, P.xc; atol=1e-8)
61-
@test isapprox(ycoords_ans, P.yc; atol=1e-8)
62-
@test isapprox(zcoords_ans, P.zc; atol=1e-8)
63-
@test isapprox(nNodeX_ans, P.nNodeX; atol=1e-8)
64-
@test isapprox(nNodeY_ans, P.nNodeY; atol=1e-8)
65-
@test isapprox(nNodeZ_ans, P.nNodeZ; atol=1e-8)
57+
@test isapprox(nProcX_ans, P.nProcX; atol=1.0e-8)
58+
@test isapprox(nProcY_ans, P.nProcY; atol=1.0e-8)
59+
@test isapprox(nProcZ_ans, P.nProcZ; atol=1.0e-8)
60+
@test isapprox(xcoords_ans, P.xc; atol=1.0e-8)
61+
@test isapprox(ycoords_ans, P.yc; atol=1.0e-8)
62+
@test isapprox(zcoords_ans, P.zc; atol=1.0e-8)
63+
@test isapprox(nNodeX_ans, P.nNodeX; atol=1.0e-8)
64+
@test isapprox(nNodeY_ans, P.nNodeY; atol=1.0e-8)
65+
@test isapprox(nNodeZ_ans, P.nNodeZ; atol=1.0e-8)
6666

6767
n_ranks = 128; nx=256; ny=1; nz=128;
6868
xcoords_ans=[-35.35034129014803, -31.479617703551735, -27.608894116955444, -23.73817053035915, -19.867446943762857, -15.996723357166562, -12.125999770570267, -8.255276183973974, -4.384552597377681, -0.5138290107813872, 3.3568945758149065, 7.227618162411201, 11.098341749007494, 14.969065335603787, 18.839788922200082, 22.710512508796374, 26.58123609539267];
@@ -71,15 +71,15 @@ zcoords_ans=[-6.4, -4.8, -3.2, -1.6, 0.0, 1.6, 3.2, 4.8, 6.4];
7171
nProcX_ans = 16; nProcY_ans = 1; nProcZ_ans = 8;
7272
nNodeX_ans = 257; nNodeY_ans = 2; nNodeZ_ans = 129;
7373
P = setup_model_domain([extrema(xcoords_ans)...], [extrema(ycoords_ans)...], [extrema(zcoords_ans)...], nx, ny, nz, n_ranks)
74-
@test isapprox(nProcX_ans, P.nProcX; atol=1e-8)
75-
@test isapprox(nProcY_ans, P.nProcY; atol=1e-8)
76-
@test isapprox(nProcZ_ans, P.nProcZ; atol=1e-8)
77-
@test isapprox(xcoords_ans, P.xc; atol=1e-8)
78-
@test isapprox(ycoords_ans, P.yc; atol=1e-8)
79-
@test isapprox(zcoords_ans, P.zc; atol=1e-8)
80-
@test isapprox(nNodeX_ans, P.nNodeX; atol=1e-8)
81-
@test isapprox(nNodeY_ans, P.nNodeY; atol=1e-8)
82-
@test isapprox(nNodeZ_ans, P.nNodeZ; atol=1e-8)
74+
@test isapprox(nProcX_ans, P.nProcX; atol=1.0e-8)
75+
@test isapprox(nProcY_ans, P.nProcY; atol=1.0e-8)
76+
@test isapprox(nProcZ_ans, P.nProcZ; atol=1.0e-8)
77+
@test isapprox(xcoords_ans, P.xc; atol=1.0e-8)
78+
@test isapprox(ycoords_ans, P.yc; atol=1.0e-8)
79+
@test isapprox(zcoords_ans, P.zc; atol=1.0e-8)
80+
@test isapprox(nNodeX_ans, P.nNodeX; atol=1.0e-8)
81+
@test isapprox(nNodeY_ans, P.nNodeY; atol=1.0e-8)
82+
@test isapprox(nNodeZ_ans, P.nNodeZ; atol=1.0e-8)
8383

8484
n_ranks = 2048; nx=512; ny=2048; nz=512;
8585
xcoords_ans=[-35.35034129014803, -27.60889411695544, -19.867446943762857, -12.12599977057027, -4.3845525973776835, 3.356894575814903, 11.098341749007488, 18.839788922200068, 26.58123609539267 ];
@@ -88,15 +88,15 @@ zcoords_ans=[-6.4, -4.800000000000001, -3.2, -1.6, 0.0, 1.6, 3.2, 4.800000000000
8888
nProcX_ans = 8; nProcY_ans = 32; nProcZ_ans = 8;
8989
nNodeX_ans = 513; nNodeY_ans = 2049; nNodeZ_ans = 513;
9090
P = setup_model_domain([-35.35034129014803,26.58123609539267], [-24.510578171895816,34.75629047035891], [-6.4,6.4], nx, ny, nz, n_ranks)
91-
@test isapprox(nProcX_ans, P.nProcX; atol=1e-8)
92-
@test isapprox(nProcY_ans, P.nProcY; atol=1e-8)
93-
@test isapprox(nProcZ_ans, P.nProcZ; atol=1e-8)
94-
@test isapprox(xcoords_ans, P.xc; atol=1e-8)
95-
@test isapprox(ycoords_ans, P.yc[1:10]; atol=1e-8)
96-
@test isapprox(zcoords_ans, P.zc; atol=1e-8)
97-
@test isapprox(nNodeX_ans, P.nNodeX; atol=1e-8)
98-
@test isapprox(nNodeY_ans, P.nNodeY; atol=1e-8)
99-
@test isapprox(nNodeZ_ans, P.nNodeZ; atol=1e-8)
91+
@test isapprox(nProcX_ans, P.nProcX; atol=1.0e-8)
92+
@test isapprox(nProcY_ans, P.nProcY; atol=1.0e-8)
93+
@test isapprox(nProcZ_ans, P.nProcZ; atol=1.0e-8)
94+
@test isapprox(xcoords_ans, P.xc; atol=1.0e-8)
95+
@test isapprox(ycoords_ans, P.yc[1:10]; atol=1.0e-8)
96+
@test isapprox(zcoords_ans, P.zc; atol=1.0e-8)
97+
@test isapprox(nNodeX_ans, P.nNodeX; atol=1.0e-8)
98+
@test isapprox(nNodeY_ans, P.nNodeY; atol=1.0e-8)
99+
@test isapprox(nNodeZ_ans, P.nNodeZ; atol=1.0e-8)
100100

101101
n_ranks = 32768; nx=2048; ny=512; nz=1024;
102102
xcoords_ans=[-35.35034129014803, -34.38266039349895, -33.41497949684988, -32.4472986002008, -31.47961770355173, -30.511936806902664, -29.54425591025359, -28.576575013604515, -27.60889411695544, -26.64121322030637 ];
@@ -105,15 +105,15 @@ zcoords_ans=[-6.4, -6.0, -5.6000000000000005, -5.2, -4.800000000000001, -4.4, -4
105105
nProcX_ans = 64; nProcY_ans = 16; nProcZ_ans = 32;
106106
nNodeX_ans = 2049; nNodeY_ans = 513; nNodeZ_ans = 1025;
107107
P = setup_model_domain([-35.35034129014803,26.58123609539267], [-24.510578171895816,34.75629047035891], [-6.4,6.4], nx, ny, nz, n_ranks)
108-
@test isapprox(nProcX_ans, P.nProcX; atol=1e-8)
109-
@test isapprox(nProcY_ans, P.nProcY; atol=1e-8)
110-
@test isapprox(nProcZ_ans, P.nProcZ; atol=1e-8)
111-
@test isapprox(xcoords_ans, P.xc[1:10]; atol=1e-8)
112-
@test isapprox(ycoords_ans, P.yc[1:10]; atol=1e-8)
113-
@test isapprox(zcoords_ans, P.zc[1:10]; atol=1e-8)
114-
@test isapprox(nNodeX_ans, P.nNodeX; atol=1e-8)
115-
@test isapprox(nNodeY_ans, P.nNodeY; atol=1e-8)
116-
@test isapprox(nNodeZ_ans, P.nNodeZ; atol=1e-8)
108+
@test isapprox(nProcX_ans, P.nProcX; atol=1.0e-8)
109+
@test isapprox(nProcY_ans, P.nProcY; atol=1.0e-8)
110+
@test isapprox(nProcZ_ans, P.nProcZ; atol=1.0e-8)
111+
@test isapprox(xcoords_ans, P.xc[1:10]; atol=1.0e-8)
112+
@test isapprox(ycoords_ans, P.yc[1:10]; atol=1.0e-8)
113+
@test isapprox(zcoords_ans, P.zc[1:10]; atol=1.0e-8)
114+
@test isapprox(nNodeX_ans, P.nNodeX; atol=1.0e-8)
115+
@test isapprox(nNodeY_ans, P.nNodeY; atol=1.0e-8)
116+
@test isapprox(nNodeZ_ans, P.nNodeZ; atol=1.0e-8)
117117

118118
# Test creating model setups
119119
Grid = read_LaMEM_inputfile("test_files/Subduction2D_FreeSlip_Particles_Linear_DirectSolver.dat")

0 commit comments

Comments
 (0)