Skip to content

Commit

Permalink
Merge pull request #214 from ReactionMechanismGenerator/save_sol
Browse files Browse the repository at this point in the history
Add function to save the solution
  • Loading branch information
mjohnson541 authored Nov 14, 2023
2 parents 7052a02 + a165085 commit 92a8b09
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ version = "0.4.0"
Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DiffEqSensitivity = "41bf760c-e81c-5289-8e54-58b1f1f8abe2"
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Expand Down Expand Up @@ -43,7 +45,9 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
Calculus = "0.4,0.5"
Colors = "0.11,0.12"
Conda = "1"
DiffEqSensitivity = "^6"
CSV = "0"
DataFrames = "1"
DiffEqSensitivity = "6"
ForwardDiff = "0.10"
Images = "0.24"
IncompleteLU = "0.2"
Expand Down
25 changes: 25 additions & 0 deletions src/Simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -764,3 +764,28 @@ function rates(ssys::Q; ts::X=Array{Float64,1}()) where {Q<:SystemSimulation,X<:
end

export rates

"""
Save the simulation profile to a .csv file
"""
function save(sim::T, save_name::String) where {T<:Simulation}
df = DataFrame(sim.sol)
rename!(df, names(df)[sim.domain.indexes[1]:sim.domain.indexes[2]] .=> sim.names)
for (thermovariable, index) in sim.domain.thermovariabledict
rename!(df, names(df)[index] => thermovariable)
end
CSV.write(save_name, df)
end

function save(syss::T, save_name::String) where {T<:SystemSimulation}
df = DataFrame(syss.sol)
for sim in syss.sims
rename!(df, names(df)[sim.domain.indexes[1]:sim.domain.indexes[2]] .=> sim.names .* "($(sim.domain.phase.name))")
for (thermovariable, index) in sim.domain.thermovariabledict
rename!(df, names(df)[index] => thermovariable)
end
end
CSV.write(save_name, df)
end
export save

4 changes: 4 additions & 0 deletions src/TestReactors.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Test
using SciMLBase
using Sundials
using CSV
using DataFrames

@testset "Test Reactors" begin

Expand Down Expand Up @@ -193,6 +195,8 @@ domain,y0,p = ConstantTPDomain(phase=ig,initialconds=initialconds) #Define the d
react = Reactor(domain,y0,(0.0,150.11094);p=p) #Create the reactor object
sol = solve(react.ode,CVODE_BDF(),abstol=1e-20,reltol=1e-12); #solve the ode associated with the reactor
sim = Simulation(sol,domain);
save(sim, "test.csv")
@test isfile("test.csv")

spcnames = getfield.(ig.species,:name)
h2ind = findfirst(isequal("H2"),spcnames)
Expand Down

0 comments on commit 92a8b09

Please sign in to comment.