Skip to content

Commit

Permalink
joinpath in runtest, change in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vinodjanardhanan committed Sep 23, 2022
1 parent e8dd994 commit a6b4350
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
5 changes: 5 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ The meaning of different tags is specified below.
- <surface_mech> : name of the surface reaction mechanism
- <gas_mech> : name of the gasphase reaction mechanism


## Input file download
The xml input file and the *lib* directory containig other required input files may be downloaded from [here](https://github.com/vinodjanardhanan/BatchReactor.jl/tree/main/test).


## Output
The code generates two output files in the same directory where the input file **`batch.xml`** is present.
The file **`gas_profile.dat`** contains the mole fraction of the gas phase species as a function of time.
Expand Down
32 changes: 24 additions & 8 deletions src/BatchReactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ This is the calling function for executing the batch reactor with user defined r
batch_reactor(input_file::AbstractString, lib_dir::AbstractString, user_defined::Function; sens= false)
- input_file: the xml input file for batch reactor
- lib_dir: the direcrtory in which the data files are present. It must be the relative path
- user_defined : a function that calculates the species source terms. Must be supplied by the user
- sens : Boolean to be set as true when used along with the sensitivity code
"""
function batch_reactor(input_file::AbstractString, lib_dir::AbstractString, user_defined::Function; sens= false)
chem = Chemistry(false, false, true, user_defined)
Expand All @@ -56,14 +58,28 @@ This is the calling function for executing the batch reactor with chemistry inpu
batch_reactor(input_file::AbstractString, lib_dir::AbstractString; sens= false, surfchem=false, gaschem=false)
- input_file: the xml input file for batch reactor
- lib_dir: the direcrtory in which the data files are present. It must be the relative path
- sens : Boolean to be set as true when used along with the sensitivity code
- surfchem : Boolean to specify the calculation of surface reaction rates
- gaschem : Boolean to specify the calculation of gasphase reaction rates
"""
function batch_reactor(input_file::AbstractString, lib_dir::AbstractString; sens= false, surfchem=false, gaschem=false)
chem = Chemistry(surfchem, gaschem, false, f->())
batch_reactor(input_file, lib_dir, sens, chem)
end



"""
A function for call from other packages, mainly intended for reactor network modeling
# Usage
batch_reactor(inlet_comp, T, p, time; Asv=1.0, chem, thermo_obj, md)
- inlet_comp : A dictionary of species and its mole fractions at the reactor inlet
- T : operating temperature (K)
- p : operating pressure (Pa)
- time : integration time (s)
- Asv : Surface area to volume ratio (important in the case of surface reactions. 1 in the case of gasphase chemistry)
- thermo_obj : Species thermo object (Please refer IdealGas package documentation)
- md : MechanismDefinition (Please refer to ReactionCommons documentation)
"""
function batch_reactor(inlet_comp, T, p, time; Asv=1.0, chem, thermo_obj, md)

Expand Down Expand Up @@ -192,10 +208,10 @@ function batch_reactor(input_file::AbstractString, lib_dir::AbstractString, sens
end


"""
#=
Function for creating the solition vector.
The solution vector contains mass density of the species ie. ρ × Y_k
"""
=#
function get_solution_vector(id::InputData, chem)
soln = zeros(length(id.gasphase))
molefrac_to_massfrac!(soln,id.mole_fracs,id.thermo_obj.molwt)
Expand All @@ -207,9 +223,9 @@ function get_solution_vector(id::InputData, chem)
end


"""
#=
Function for reading the common input parameters
"""
=#
function input_data(xmlroot::XMLElement, lib_dir::AbstractString, chem)


Expand Down Expand Up @@ -279,9 +295,9 @@ function input_data(xmlroot::XMLElement, lib_dir::AbstractString, chem)
end


"""
#=
Residual function definition for the batch reactor
"""
=#
function residual!(du,u,p,t)
state = 1
thermo_obj = 2
Expand Down Expand Up @@ -328,9 +344,9 @@ end



"""
#=
Function to save the variables into output file
"""
=#
function save_data(u,t,integrator)
state = 1
g_stream, s_stream = o_streams
Expand Down
12 changes: 8 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ using IdealGas, RxnHelperUtils, SurfaceReactions, GasphaseReactions, ReactionCom
end

@testset "Testing surface chemistry" begin
retcode = batch_reactor("batch_surf/batch.xml", lib_dir, surfchem=true)
input_file = joinpath("batch_surf", "batch.xml")
retcode = batch_reactor(input_file, lib_dir, surfchem=true)
@test retcode == Symbol("Success")
end

@testset "Testing gas chemistry of h2 + o2" begin
retcode = batch_reactor("batch_h2o2/batch.xml", lib_dir, gaschem=true)
input_file = joinpath("batch_h2o2", "batch.xml")
retcode = batch_reactor(input_file, lib_dir, gaschem=true)
@test retcode == Symbol("Success")
end

@testset "Testing gas chemistry using grimech" begin
retcode = batch_reactor("batch_ch4/batch.xml", lib_dir, gaschem=true)
input_file = joinpath("batch_ch4", "batch.xml")
retcode = batch_reactor(input_file, lib_dir, gaschem=true)
@test retcode == Symbol("Success")
end

Expand Down Expand Up @@ -62,7 +65,8 @@ using IdealGas, RxnHelperUtils, SurfaceReactions, GasphaseReactions, ReactionCom
function udf(state)
state.source[1:end] .= 0.0
end
retcode = batch_reactor("batch_udf/batch.xml", lib_dir, udf)
input_file = joinpath("batch_udf", "batch.xml")
retcode = batch_reactor(input_file, lib_dir, udf)
@test retcode == Symbol("Success")
end
end

0 comments on commit a6b4350

Please sign in to comment.