initial import
This commit is contained in:
parent
936840ef72
commit
5277428179
4 changed files with 253 additions and 0 deletions
9
Cantera/fortran/f77demos/README.txt
Normal file
9
Cantera/fortran/f77demos/README.txt
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
This directory contains examples of Fortran 77 programs that use
|
||||
Cantera. The programs are:
|
||||
|
||||
ctlib An example showing how to write subroutines that emulate those
|
||||
of the Chemkin CKLIB library.
|
||||
|
||||
isentropic Mach number vs. area ratio for isentropic flow.
|
||||
|
||||
95
Cantera/fortran/f77demos/ctlib.f
Normal file
95
Cantera/fortran/f77demos/ctlib.f
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
c
|
||||
c This example shows how to implement subroutines that emulate those
|
||||
c of the Chemkin CKLIB library. This may be useful to port an
|
||||
c existing Chemkin-based application to Cantera. As shown here, the
|
||||
c subroutine names begin with 'ct' instead of 'ck', so that Cantera
|
||||
c and CKLIB subroutines can be both used in an application, if
|
||||
c desired. It is also possible to rename these subroutines with the
|
||||
c 'ck' prefix if the application is not linked to the Chemkin CKLIB
|
||||
c library. In this case, application programs do not need to be
|
||||
c modified or recompiled - they only need to be relinked.
|
||||
c
|
||||
c Only a few subroutines are implemented here, but the same idea can
|
||||
c be applied to create Cantera-based versions of any other
|
||||
c subroutines in the CKLIB library.
|
||||
c
|
||||
|
||||
c-----------------------------------------------------------------------
|
||||
c example driver program
|
||||
|
||||
program ctck
|
||||
implicit double precision (a-h,o-z)
|
||||
double precision rckwrk(1)
|
||||
integer ickwrk(1)
|
||||
parameter (MAXSP = 100)
|
||||
double precision y(MAXSP), wdot(MAXSP)
|
||||
|
||||
c Read in the reaction mechanism. Since this is done differently
|
||||
c than in Chemkin, this function does not correspond to any CKLIB
|
||||
c subroutine.
|
||||
call newIdealGasMix('gri30.cti','gri30','')
|
||||
|
||||
c get the number of elements, species, and reactions
|
||||
call ctindx(ickwrk, rckwrk, mm, kk, ii)
|
||||
|
||||
do k = 1, kk
|
||||
y(k) = 1.0/kk
|
||||
end do
|
||||
|
||||
c compute the net production rates in cgs units
|
||||
p = 1.0d6
|
||||
t = 2500.0d0
|
||||
|
||||
call ctwyp(p, t, y, ickwrk, rckwrk, wdot)
|
||||
do k = 1, kk
|
||||
write(*,*) k, y(k), wdot(k)
|
||||
end do
|
||||
|
||||
stop
|
||||
end
|
||||
|
||||
c----------------------------------------------------------------------
|
||||
c
|
||||
c The subroutines below emulate ones in the Chemkin CKLIB
|
||||
c library. They are implemented in terms of the procedures in
|
||||
c demo_ftnlib. It would also be possible to rewrite demo_ftnlib to
|
||||
c implement a Chemkin-like interface directly. Note that the arrays
|
||||
c ickwrk and rckwrk are passed in for consistency with the Chemkin
|
||||
c interface specification, but the are not used. These may simply be
|
||||
c dummy arrays, as in the main program above.
|
||||
c
|
||||
|
||||
c CTINDX: get the number of elements, species, and reactions
|
||||
|
||||
subroutine ctindx(ickwrk, rckwrk, mm, kk, ii)
|
||||
implicit double precision (a-h,o-z)
|
||||
mm = nElements()
|
||||
kk = nSpecies()
|
||||
ii = nReactions()
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
c CTWYP: get the net molar production rates, given the pressure,
|
||||
c temperature, and array of mass fractions.
|
||||
|
||||
subroutine ctwyp(p,t,y,ickwrk,rckwrk,wdot)
|
||||
implicit double precision (a-h,o-z)
|
||||
double precision y(*), rckwrk(*), wdot(*)
|
||||
integer ickwrk(*)
|
||||
|
||||
c set the state
|
||||
psi = 0.1*p
|
||||
call setState_TPY(t, psi, y)
|
||||
|
||||
c get the net production rates
|
||||
call getNetProductionRates(wdot)
|
||||
|
||||
c convert SI -> cgs
|
||||
nsp = nSpecies()
|
||||
do k = 1, nsp
|
||||
wdot(k) = 1.0d3*wdot(k)
|
||||
end do
|
||||
return
|
||||
end
|
||||
|
||||
86
Cantera/fortran/f77demos/f77demos.mak.in
Normal file
86
Cantera/fortran/f77demos/f77demos.mak.in
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#!/bin/sh
|
||||
|
||||
|
||||
# the name of the executable program to be created
|
||||
PROG_NAME = demo
|
||||
|
||||
# the object files to be linked together.
|
||||
OBJS = demo.o demo_ftnlib.o
|
||||
|
||||
# additional flags to be passed to the linker. If your program
|
||||
# requires other external libraries, put them here
|
||||
LINK_OPTIONS =
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# You probably don't need to edit anything below.
|
||||
|
||||
|
||||
# the Fortran compiler
|
||||
FORT = @F77@
|
||||
|
||||
# Fortran compile flags
|
||||
FORT_FLAGS = @FFLAGS@
|
||||
|
||||
# Fortran libraries
|
||||
FORT_LIBS = @FLIBS@
|
||||
|
||||
# the C++ compiler
|
||||
CXX = @CXX@
|
||||
|
||||
# C++ compile flags
|
||||
CXX_FLAGS = @CXXFLAGS@
|
||||
|
||||
# external libraries
|
||||
EXT_LIBS = @LOCAL_LIBS@ -lctcxx
|
||||
|
||||
# the directory where the Cantera libraries are located
|
||||
CANTERA_LIBDIR=@CANTERA_LIBDIR@
|
||||
|
||||
# the directory where Cantera include files may be found.
|
||||
CANTERA_INCDIR=@CANTERA_INCDIR@
|
||||
|
||||
# flags passed to the C++ compiler/linker for the linking step
|
||||
LCXX_FLAGS = -L$(CANTERA_LIBDIR) @CXXFLAGS@
|
||||
|
||||
# how to compile C++ source files to object files
|
||||
.@CXX_EXT@.@OBJ_EXT@:
|
||||
$(CXX) -c $< -I$(CANTERA_INCDIR) $(CXX_FLAGS)
|
||||
|
||||
# how to compile Fortran source files to object files
|
||||
.@F77_EXT@.@OBJ_EXT@:
|
||||
$(FORT) -c $< $(FORT_FLAGS)
|
||||
|
||||
PROGRAM = $(PROG_NAME)$(EXE_EXT)
|
||||
|
||||
DEPENDS = $(OBJS:.o=.d)
|
||||
|
||||
all: isentropic ctlib
|
||||
|
||||
isentropic: isentropic.o demo_ftnlib.o
|
||||
$(CXX) -o isentropic isentropic.o demo_ftnlib.o $(LCXX_FLAGS) $(CANTERA_LIBS) $(LINK_OPTIONS) $(EXT_LIBS) @LIBS@ $(FORT_LIBS)
|
||||
|
||||
ctlib: ctlib.o demo_ftnlib.o
|
||||
$(CXX) -o ctlib ctlib.o demo_ftnlib.o $(LCXX_FLAGS) $(CANTERA_LIBS) $(LINK_OPTIONS) $(EXT_LIBS) @LIBS@ $(FORT_LIBS)
|
||||
|
||||
%.d:
|
||||
g++ -MM $*.cpp > $*.d
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS) $(PROGRAM)
|
||||
|
||||
depends: $(DEPENDS)
|
||||
cat *.d > .depends
|
||||
$(RM) $(DEPENDS)
|
||||
|
||||
TAGS:
|
||||
etags *.h *.cpp
|
||||
|
||||
ifeq ($(wildcard .depends), .depends)
|
||||
include .depends
|
||||
endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
63
Cantera/fortran/f77demos/isentropic.f
Normal file
63
Cantera/fortran/f77demos/isentropic.f
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
c
|
||||
c Mach number vs. area for an isentropic flow. See also the Python
|
||||
c version of this problem in the Python demos.
|
||||
c
|
||||
program isentropic
|
||||
implicit double precision (a-h,o-z)
|
||||
parameter (oneatm = 1.01325d5, NPTS = 200)
|
||||
double precision a(NPTS), dmach(NPTS), t(NPTS),
|
||||
$ ratio(NPTS)
|
||||
|
||||
call newIdealGasMix('gri30.cti','gri30','')
|
||||
temp = 1200.d0
|
||||
pres = 10.d0*oneatm
|
||||
call setState_TPX_String(temp, pres,'H2:1, N2:0.1')
|
||||
|
||||
c stagnation state properties
|
||||
s0 = entropy_mass()
|
||||
h0 = enthalpy_mass()
|
||||
p0 = pressure()
|
||||
|
||||
dmdot = 1.0d0
|
||||
amin = 1.0d14
|
||||
|
||||
do n = 1, NPTS
|
||||
p = p0*n/(NPTS+1)
|
||||
call setState_SP(s0,p)
|
||||
h = enthalpy_mass()
|
||||
rho = density()
|
||||
|
||||
v2 = 2.0*(h0 - h)
|
||||
v = sqrt(v2)
|
||||
area = dmdot/(rho*v)
|
||||
if (area .lt. amin) then
|
||||
amin = area
|
||||
end if
|
||||
|
||||
a(n) = area
|
||||
dmach(n) = v/soundspeed()
|
||||
t(n) = temperature()
|
||||
ratio(n) = p/p0
|
||||
end do
|
||||
|
||||
do n = 1, NPTS
|
||||
a(n) = a(n)/amin
|
||||
write(*,30) a(n), dmach(n), t(n), ratio(n)
|
||||
30 format(4e16.5)
|
||||
end do
|
||||
stop
|
||||
end
|
||||
|
||||
|
||||
double precision function soundspeed()
|
||||
implicit double precision (a-h,o-z)
|
||||
double precision meanMolarMass
|
||||
parameter (R = 8314.3d0)
|
||||
gamma = cp_mass()/cv_mass()
|
||||
soundspeed = sqrt(gamma * R * temperature()
|
||||
$ / meanMolarMass())
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Reference in a new issue