Skip to content

Commit

Permalink
Merge pull request #263 from brown-ccv/dev-to-master
Browse files Browse the repository at this point in the history
Dev to master
  • Loading branch information
CallieHsu authored Sep 20, 2023
2 parents edd2e9c + 51a8a73 commit 5d564f3
Show file tree
Hide file tree
Showing 9 changed files with 443 additions and 434 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Chamber"
uuid = "4ddda095-17ec-41dd-95c9-ce16dd2a2f48"
authors = ["CallieHsu <[email protected]> and contributors"]
version = "0.1.1"
version = "0.2.0"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ A `DataFrame` containing the solution with columns:
- `total_mass`: Total mass of magma chamber (kg).
- `total_mass_H2O`: Total mass of water in the magma (kg).
- `total_mass_CO2`: Total mass of CO₂ in the magma (kg).
- `eps_x`: Crystal volume fraction.

### Outputs
A directory named after `output_dirname` or the default value, containing the following files:
Expand Down
4 changes: 3 additions & 1 deletion scripts/runcode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ A `DataFrame` containing the solution with columns:
- `total_mass`: Total mass of magma chamber in kg.
- `total_mass_H2O`: Total mass of water in the magma in kg.
- `total_mass_CO2`: Total mass of CO₂ in the magma in kg.
- `eps_x`: Crystal volume fraction.
## Outputs
A directory named after `output_dirname` or the default value, containing the following files:
Expand Down Expand Up @@ -265,7 +266,7 @@ julia> chamber(composition, end_time, log_volume_km3, InitialConc_H2O, InitialCo
print_timer_log(io, to)
close(io)
df = DataFrame(sol)
write_csv(df, erupt_saved, path)
write_csv(df, erupt_saved, path, composition)
if plotfig
plot_figs(df, path)
end
Expand Down Expand Up @@ -305,6 +306,7 @@ A `DataFrame` containing the solution with columns:
- `total_mass`: Total mass of magma chamber in kg.
- `total_mass_H2O`: Total mass of water in the magma in kg.
- `total_mass_CO2`: Total mass of CO₂ in the magma in kg.
- `eps_x`: Crystal volume fraction.
## Outputs
A directory named after `output_dirname` or the default value, containing the following files:
Expand Down
2 changes: 1 addition & 1 deletion src/ic_finder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function IC_Finder(
end
end

if eps_g0 <= 0 || X_co20 < 0
if eps_g0 <= 0 || X_co20 < 0 || any(isnan, [X_co20, eps_g0])
X_co20 = 0.0
eps_g0 = 0.0
mco2_diss = m_co2_melt
Expand Down
9 changes: 3 additions & 6 deletions src/runcode-func.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,9 @@ function affect!(
erupt_saved::EruptSaved{Float64},
)
composition = param.composition
storeTime = param_saved_var.storeTime
storeTemp = param_saved_var.storeTemp
storeTemp = storeTemp[storeTime .< int.t]
storeTime = storeTime[storeTime .< int.t]
param_saved_var.storeTime = storeTime
param_saved_var.storeTemp = storeTemp
IsStoreTimeLTt = param_saved_var.storeTime .< int.t
param_saved_var.storeTemp = param_saved_var.storeTemp[IsStoreTimeLTt]
param_saved_var.storeTime = param_saved_var.storeTime[IsStoreTimeLTt]

if param.dP_lit_dt_0 == 0
temp_P_lit = 0.0
Expand Down
23 changes: 16 additions & 7 deletions src/write_csv.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
function write_csv(df::DataFrame, erupt_saved::EruptSaved{Float64}, path::String)::Nothing
function extend_with_nan(arr::Vector{T}, n::Int64)::Vector{T} where {T<:Float64}
return [arr; fill(NaN, n - length(arr))]
end

function write_csv(df::DataFrame, erupt_saved::EruptSaved{Float64}, path::String, composition::Union{Silicic,Mafic})::Nothing
number_of_data = size(df, 1)
println("number_of_data: $number_of_data")
names = [
Expand All @@ -14,13 +18,18 @@ function write_csv(df::DataFrame, erupt_saved::EruptSaved{Float64}, path::String
"total_mass_CO2",
]
rename!(df, ["timestamp" => "time"])
rename!(df, ["value$i" => names[i] for i in 1:10])
rename!(df, ["value$i" => name for (i, name) in enumerate(names)])
# add eps_x column
m_h2o = df[:, "total_mass_H2O"] ./ df[:, "total_mass"]
m_co2 = df[:, "total_mass_CO2"] ./ df[:, "total_mass"]
df[!, "eps_x"] = crystal_fraction_eps_x.(repeat([composition], number_of_data), df[:, "T"], df[:, "P+dP"], m_h2o, m_co2)

n = length(erupt_saved.time)
df_erupt = DataFrame(
reduce(
hcat,
[erupt_saved.time, erupt_saved.duration, erupt_saved.mass, erupt_saved.volume],
),
["time_of_eruption", "duration_of_eruption", "mass_erupted", "volume_erupted"],
time_of_eruption = erupt_saved.time,
duration_of_eruption = extend_with_nan(erupt_saved.duration, n),
mass_erupted = extend_with_nan(erupt_saved.mass, n),
volume_erupted = extend_with_nan(erupt_saved.volume, n)
)
CSV.write("$path/out.csv", df)
CSV.write("$path/eruptions.csv", df_erupt)
Expand Down
282 changes: 141 additions & 141 deletions test/out.csv

Large diffs are not rendered by default.

278 changes: 139 additions & 139 deletions test/out_co2_1e-3.csv

Large diffs are not rendered by default.

276 changes: 138 additions & 138 deletions test/out_co2_2e-3.csv

Large diffs are not rendered by default.

0 comments on commit 5d564f3

Please sign in to comment.