From 5fd428aa0898717f224ddbf4abaa95f52bac7a96 Mon Sep 17 00:00:00 2001 From: Yuto Horikawa Date: Sun, 10 Dec 2023 20:17:40 +0900 Subject: [PATCH] Replace `temp` with `temperature` (#112) * replace `temp` with `temperature` * rename `surf_temperature` to `surface_temperature` etc. * format * enable `always_for_in` * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .JuliaFormetter.toml | 1 + src/TPM.jl | 49 +++++++++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/.JuliaFormetter.toml b/.JuliaFormetter.toml index 323237ba..31258a19 100644 --- a/.JuliaFormetter.toml +++ b/.JuliaFormetter.toml @@ -1 +1,2 @@ style = "blue" +always_for_in = true diff --git a/src/TPM.jl b/src/TPM.jl index 1e2e0d15..7effbb5a 100644 --- a/src/TPM.jl +++ b/src/TPM.jl @@ -238,10 +238,10 @@ Output data format for `SingleTPM` ## Saved only at the time steps desired by the user - `times_to_save` : Timesteps to save temperature [s] - `depth_nodes` : Depths of the calculation nodes for 1-D heat conduction [m], a vector of size `Nz` -- `surf_temp` : Surface temperature [K], a matrix in size of `(Ns, Nt)`. +- `surface_temperature` : Surface temperature [K], a matrix in size of `(Ns, Nt)`. - `Ns` : Number of faces - `Nt` : Number of time steps to save surface temperature -- `face_temp` : Temperature [K] as a function of depth [m] and time [s], `Dict` with face ID as key and a matrix `(Nz, Nt)` as an entry. +- `subsurface_temperature` : Temperature [K] as a function of depth [m] and time [s], `Dict` with face ID as key and a matrix `(Nz, Nt)` as an entry. - `Nz` : The number of the depth nodes - `Nt` : The number of time steps to save temperature """ @@ -255,8 +255,8 @@ struct SingleTPMResult times_to_save ::Vector{Float64} depth_nodes ::Vector{Float64} - surf_temp ::Matrix{Float64} - face_temp ::Dict{Int, Matrix{Float64}} + surface_temperature ::Matrix{Float64} + subsurface_temperature ::Dict{Int, Matrix{Float64}} end @@ -280,12 +280,23 @@ function SingleTPMResult(stpm::SingleTPM, ephem, times_to_save::Vector{Float64}, torque = zeros(SVector{3, Float64}, nsteps) depth_nodes = stpm.thermo_params.Δz * (0:stpm.thermo_params.Nz-1) - surf_temp = zeros(length(stpm.shape.faces), nsteps_to_save) - face_temp = Dict{Int, Matrix{Float64}}( + surface_temperature = zeros(length(stpm.shape.faces), nsteps_to_save) + subsurface_temperature = Dict{Int,Matrix{Float64}}( nₛ => zeros(stpm.thermo_params.Nz, nsteps_to_save) for nₛ in face_ID ) - return SingleTPMResult(ephem.time, E_in, E_out, E_cons, force, torque, times_to_save, depth_nodes, surf_temp, face_temp) + return SingleTPMResult( + ephem.time, + E_in, + E_out, + E_cons, + force, + torque, + times_to_save, + depth_nodes, + surface_temperature, + subsurface_temperature, + ) end @@ -354,10 +365,10 @@ function update_TPM_result!(result::SingleTPMResult, stpm::SingleTPM, nₜ::Inte if t in result.times_to_save # In the step of saving temperature nₜ_save = findfirst(isequal(t), result.times_to_save) - result.surf_temp[:, nₜ_save] .= surface_temperature(stpm) + result.surface_temperature[:, nₜ_save] .= surface_temperature(stpm) - for (nₛ, temp) in result.face_temp - temp[:, nₜ_save] .= stpm.temperature[:, nₛ] + for (nₛ, temperature) in result.subsurface_temperature + temperature[:, nₜ_save] .= stpm.temperature[:, nₛ] end end end @@ -408,8 +419,11 @@ function export_TPM_results(dirpath, result::SingleTPMResult) ##= Surface temperature =## filepath = joinpath(dirpath, "surface_temperature.csv") df = hcat( - DataFrame(time=result.times_to_save), - DataFrame(result.surf_temp', ["face_$(i)" for i in 1:size(result.surf_temp, 1)]), + DataFrame(time = result.times_to_save), + DataFrame( + result.surface_temperature', + ["face_$(i)" for i in 1:size(result.surface_temperature, 1)] + ), ) CSV.write(filepath, df) @@ -424,8 +438,9 @@ function export_TPM_results(dirpath, result::SingleTPMResult) ) # Add a column for each face - for (nₛ, face_temp) in collect(result.face_temp) - df[:, "face_$(nₛ)"] = reshape(face_temp, length(face_temp)) + for (nₛ, subsurface_temperature) in collect(result.subsurface_temperature) + df[:, "face_$(nₛ)"] = + reshape(subsurface_temperature, length(subsurface_temperature)) end # Sort the columns by the face ID @@ -517,11 +532,11 @@ end # function run_TPM!(shape::ShapeModel, orbit::OrbitalElements, spin::SpinParams, thermo_params::AbstractThermoParams, savepath="tmp.jld2") # @unpack P, Δt, t_begin, t_end = thermo_params -# init_temps_zero!(shape, thermo_params) +# init_temperatures_zero!(shape, thermo_params) # ts = (t_begin:Δt:t_end) * P # timestamp = prep_timestamp(ts) -# # surf_temp_table = zeros(length(shape.faces), Int(1/thermo_params.Δt)-1) +# # surface_temperature_table = zeros(length(shape.faces), Int(1/thermo_params.Δt)-1) # for (i, t) in enumerate(ts) # update_orbit!(orbit, t) @@ -547,7 +562,7 @@ end # save_timestamp!(timestamp, i, orbit.u, orbit.ν, spin.ϕ, f..., τ..., E_in, E_out, E_cons) -# update_temps!(shape, thermo_params) +# update_temperatures!(shape, thermo_params) # end # mean_energy_cons_frac!(timestamp, spin) # jldsave(savepath; shape, orbit, spin, thermo_params, timestamp)