Skip to content

Commit 92a8b09

Browse files
authored
Merge pull request #214 from ReactionMechanismGenerator/save_sol
Add function to save the solution
2 parents 7052a02 + a165085 commit 92a8b09

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

Project.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ version = "0.4.0"
77
Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
88
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
99
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
10+
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
11+
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
1012
DiffEqSensitivity = "41bf760c-e81c-5289-8e54-58b1f1f8abe2"
1113
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
1214
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
@@ -43,7 +45,9 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
4345
Calculus = "0.4,0.5"
4446
Colors = "0.11,0.12"
4547
Conda = "1"
46-
DiffEqSensitivity = "^6"
48+
CSV = "0"
49+
DataFrames = "1"
50+
DiffEqSensitivity = "6"
4751
ForwardDiff = "0.10"
4852
Images = "0.24"
4953
IncompleteLU = "0.2"

src/Simulation.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,3 +764,28 @@ function rates(ssys::Q; ts::X=Array{Float64,1}()) where {Q<:SystemSimulation,X<:
764764
end
765765

766766
export rates
767+
768+
"""
769+
Save the simulation profile to a .csv file
770+
"""
771+
function save(sim::T, save_name::String) where {T<:Simulation}
772+
df = DataFrame(sim.sol)
773+
rename!(df, names(df)[sim.domain.indexes[1]:sim.domain.indexes[2]] .=> sim.names)
774+
for (thermovariable, index) in sim.domain.thermovariabledict
775+
rename!(df, names(df)[index] => thermovariable)
776+
end
777+
CSV.write(save_name, df)
778+
end
779+
780+
function save(syss::T, save_name::String) where {T<:SystemSimulation}
781+
df = DataFrame(syss.sol)
782+
for sim in syss.sims
783+
rename!(df, names(df)[sim.domain.indexes[1]:sim.domain.indexes[2]] .=> sim.names .* "($(sim.domain.phase.name))")
784+
for (thermovariable, index) in sim.domain.thermovariabledict
785+
rename!(df, names(df)[index] => thermovariable)
786+
end
787+
end
788+
CSV.write(save_name, df)
789+
end
790+
export save
791+

src/TestReactors.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Test
22
using SciMLBase
33
using Sundials
4+
using CSV
5+
using DataFrames
46

57
@testset "Test Reactors" begin
68

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

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

0 commit comments

Comments
 (0)