From 8e1296d9a3c42bfd794b312b5335029a93e7f6ef Mon Sep 17 00:00:00 2001 From: Boris Kaus Date: Sat, 30 Mar 2024 20:57:41 +0100 Subject: [PATCH] simplify initializing additional arrays --- Project.toml | 2 +- src/MTK_GMG.jl | 25 ++++++++++++++++++++++++- src/MTK_GMG_2D.jl | 8 ++------ src/MTK_GMG_3D.jl | 10 +--------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Project.toml b/Project.toml index 0fd1abb..f6aef38 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MagmaThermoKinematics" uuid = "e7fe3d1a-f102-40b5-a66b-64b14986c4c8" authors = ["Boris Kaus "] -version = "0.5.0" +version = "0.5.1" [deps] CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" diff --git a/src/MTK_GMG.jl b/src/MTK_GMG.jl index fe41456..d15c829 100644 --- a/src/MTK_GMG.jl +++ b/src/MTK_GMG.jl @@ -15,7 +15,7 @@ using MagmaThermoKinematics.Grid using MagmaThermoKinematics.Data import MagmaThermoKinematics: NumericalParameters, DikeParameters, TimeDependentProperties import MagmaThermoKinematics: update_Tvec!, Dike, InjectDike, km³, kyr, Myr, CreateDikePolygon -import MagmaThermoKinematics: PhasesFromTracers! +import MagmaThermoKinematics: PhasesFromTracers!, CreateArrays SecYear = 3600*24*365.25; using CUDA @@ -144,6 +144,29 @@ function MTK_initialize!(Arrays::NamedTuple, Grid::GridData, Num::NumericalParam return nothing end +""" + Ararys = MTK_initialize_arrays(Num::NumericalParameters) + +Initialize arrays used in the computations +""" +function MTK_initialize_arrays(Num::NumericalParameters) + + if Num.dim==2 + Arrays = CreateArrays(Dict( (Num.Nx, Num.Nz )=>(T=0,T_K=0, Tnew=0, T_init=0, T_it_old=0, Kc=1, Rho=1, Cp=1, Hr=0, Hl=0, ϕ=0, dϕdT=0,dϕdT_o=0, R=0, Z=0, P=0), + (Num.Nx-1,Num.Nz )=>(qx=0,Kx=0, Rc=0), + (Num.Nx ,Num.Nz-1)=>(qz=0,Kz=0 ) + )) + else + Arrays = CreateArrays(Dict( (Num.Nx, Num.Ny , Num.Nz )=>(T=0,T_K=0, Tnew=0, T_init=0, T_it_old=0, Kc=1, Rho=1, Cp=1, Hr=0, Hl=0, ϕ=0, dϕdT=0,dϕdT_o=0, R=0, X=0, Y=0, Z=0, P=0), + (Num.Nx-1,Num.Ny , Num.Nz )=>(qx=0,Kx=0), + (Num.Nx ,Num.Ny-1, Num.Nz )=>(qy=0,Ky=0), + (Num.Nx ,Num.Ny , Num.Nz-1)=>(qz=0,Kz=0 ) + )) + end + + return Arrays +end + """ MTK_initialize!(Arrays::NamedTuple, Grid::GridData, Num::NumericalParameters, Tracers::StructArray, Dikes::DikeParameters, CartData_input::CartData) diff --git a/src/MTK_GMG_2D.jl b/src/MTK_GMG_2D.jl index 416712c..7300252 100644 --- a/src/MTK_GMG_2D.jl +++ b/src/MTK_GMG_2D.jl @@ -58,13 +58,9 @@ There are a few functions that you can overwrite in your user code to customize Num = MTK_GMG.Setup_Model_CartData(CartData_input, Num, Mat_tup) end - - + # Array & grid initializations --------------- - Arrays = CreateArrays(Dict( (Num.Nx, Num.Nz )=>(T=0,T_K=0, Tnew=0, T_init=0, T_it_old=0, Kc=1, Rho=1, Cp=1, Hr=0, Hl=0, ϕ=0, dϕdT=0,dϕdT_o=0, R=0, Z=0, P=0), - (Num.Nx-1,Num.Nz )=>(qx=0,Kx=0, Rc=0), - (Num.Nx ,Num.Nz-1)=>(qz=0,Kz=0 ) - )) + Arrays = MTK_GMG.MTK_initialize_arrays(Num); # Set up model geometry & initial T structure if isnothing(CartData_input) diff --git a/src/MTK_GMG_3D.jl b/src/MTK_GMG_3D.jl index ad32ebd..af3288e 100644 --- a/src/MTK_GMG_3D.jl +++ b/src/MTK_GMG_3D.jl @@ -57,15 +57,7 @@ There are a few functions that you can overwrite in your user code to customize end # Array & grid initializations --------------- - if Num.dim==2 - error("This is the 3D routine - use MTK_GeoParams_2D instead") - else - Arrays = CreateArrays(Dict( (Num.Nx, Num.Ny , Num.Nz )=>(T=0,T_K=0, Tnew=0, T_init=0, T_it_old=0, Kc=1, Rho=1, Cp=1, Hr=0, Hl=0, ϕ=0, dϕdT=0,dϕdT_o=0, R=0, X=0, Y=0, Z=0, P=0), - (Num.Nx-1,Num.Ny , Num.Nz )=>(qx=0,Kx=0), - (Num.Nx ,Num.Ny-1, Num.Nz )=>(qy=0,Ky=0), - (Num.Nx ,Num.Ny , Num.Nz-1)=>(qz=0,Kz=0 ) - )) - end + Arrays = MTK_GMG.MTK_initialize_arrays(Num); # Set up model geometry & initial T structure if isnothing(CartData_input)