mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
Initial revision
This commit is contained in:
commit
1e8d3822ff
3
.cvsignore
Normal file
3
.cvsignore
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Makefile
|
||||||
|
configure.sol
|
||||||
|
configure.linux
|
1
Cantera/.cvsignore
Normal file
1
Cantera/.cvsignore
Normal file
@ -0,0 +1 @@
|
|||||||
|
Makefile
|
51
Cantera/Makefile.in
Executable file
51
Cantera/Makefile.in
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
#/bin/sh
|
||||||
|
###############################################################
|
||||||
|
# $Author$
|
||||||
|
# $Date$
|
||||||
|
# $Revision$
|
||||||
|
#
|
||||||
|
# Copyright 2001 California Institute of Technology
|
||||||
|
# See file License.txt for licensing information
|
||||||
|
#
|
||||||
|
# $Log$
|
||||||
|
# Revision 1.1 2003-04-14 17:57:49 dggoodwin
|
||||||
|
# Initial revision
|
||||||
|
#
|
||||||
|
# Revision 1.6 2002/12/16 13:25:57 dgg
|
||||||
|
# *** empty log message ***
|
||||||
|
#
|
||||||
|
# Revision 1.5 2002/08/24 23:25:06 dgg
|
||||||
|
# *** empty log message ***
|
||||||
|
#
|
||||||
|
# Revision 1.4 2002/08/14 07:37:42 dgg
|
||||||
|
# *** empty log message ***
|
||||||
|
#
|
||||||
|
# Revision 1.3 2002/01/12 06:43:42 dgg
|
||||||
|
# *** empty log message ***
|
||||||
|
#
|
||||||
|
###############################################################
|
||||||
|
|
||||||
|
build_f90=@BUILD_F90@
|
||||||
|
build_python=@BUILD_PYTHON@
|
||||||
|
|
||||||
|
all:
|
||||||
|
cd src; @MAKE@
|
||||||
|
ifeq ($(build_f90),1)
|
||||||
|
cd fortran; @MAKE@
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) ../lib/libcantera.a
|
||||||
|
cd src; @MAKE@ clean
|
||||||
|
cd clib/src; @MAKE@ clean
|
||||||
|
cd python; @MAKE@ clean
|
||||||
|
|
||||||
|
depends:
|
||||||
|
cd src; @MAKE@ depends
|
||||||
|
cd clib/src; @MAKE@ depends
|
||||||
|
|
||||||
|
# end of file
|
||||||
|
|
||||||
|
|
||||||
|
|
2
Cantera/clib/src/.cvsignore
Normal file
2
Cantera/clib/src/.cvsignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Makefile
|
||||||
|
.depends
|
188
Cantera/clib/src/Cabinet.h
Executable file
188
Cantera/clib/src/Cabinet.h
Executable file
@ -0,0 +1,188 @@
|
|||||||
|
/**
|
||||||
|
* @file Cabinet.h
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CT_CABINET_H
|
||||||
|
#define CT_CABINET_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template for classes to hold pointers to objects. The Cabinet<M>
|
||||||
|
* class maintains a list of pointers to objects of class M (or of
|
||||||
|
* subclasses of M). These classes are used by the 'clib' interface
|
||||||
|
* library functions that provide access to Cantera C++ objects from
|
||||||
|
* outside C++. To refer to an existing object, the library functions
|
||||||
|
* take an integer argument that specifies the location in the pointer
|
||||||
|
* list maintained by the appropriate Cabinet<M> instance. The pointer
|
||||||
|
* is retrieved from the list by the interface function, the desired
|
||||||
|
* method is invoked, and the result returned to the non-C++ calling
|
||||||
|
* procedure. By storing the pointers in a 'cabinet', there is no need
|
||||||
|
* to encode them in a string or integer and pass them out to the
|
||||||
|
* non-C++ calling routine, as some other interfacing schemes do.
|
||||||
|
*
|
||||||
|
* The Cabinet<M> class can be used to store pointers to any class
|
||||||
|
* that is default-constructible (i.e., has a constructor that takes
|
||||||
|
* no arguments). The requirement that the class be
|
||||||
|
* default-constructible arises since the Cabinet constructor always
|
||||||
|
* creates an instance of M by invoking 'new M', and stores a pointer
|
||||||
|
* to it as the first entry in the list. In most cases, class M is a
|
||||||
|
* base class with virtual methods, and the base class versions of the
|
||||||
|
* methods throw CanteraError exceptions. The subclasses overload
|
||||||
|
* these methods to implement the desired functionality. Class
|
||||||
|
* Cabinet<M> stores only the base-class pointers, but since the
|
||||||
|
* methods are virtual, the method of the appropriate subclass will be
|
||||||
|
* invoked.
|
||||||
|
*
|
||||||
|
* The Cabinet<M> class is set up to allow deleting objects in a safe
|
||||||
|
* manner, *provided* that method 'delete' is used, and the destructor
|
||||||
|
* for the object is not called directly. Method 'delete' does the
|
||||||
|
* following. If called with n = 0, it does nothing, since the first
|
||||||
|
* object in the list (the default-constructed base class instance) is
|
||||||
|
* never destroyed. If called with n > 0, it deletes the object, and
|
||||||
|
* replaces the pointer to where the object had been (but is no more)
|
||||||
|
* with a pointer to the first object. In this way, if it is deleted
|
||||||
|
* again inadvertently nothing happens, and if an attempt is made to
|
||||||
|
* reference the object by its index number, the base-class object
|
||||||
|
* will be referenced instead, which will throw an exception. If
|
||||||
|
* instead the pointer were stored in the refering code, there would
|
||||||
|
* always be the chance that
|
||||||
|
*
|
||||||
|
* The Cabinet<M> class is implemented as a singlet. The constructor
|
||||||
|
* is never explicitly called; instead, static function
|
||||||
|
* Cabinet<M>::cabinet() is called to obtain a pointer to the
|
||||||
|
* instance. This function calls the constructor on the first call and
|
||||||
|
* stores the pointer to this instance. Subsequent calls simply return
|
||||||
|
* the already-created pointer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<class M>
|
||||||
|
class Cabinet {
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor. Delete all objects in the list.
|
||||||
|
*/
|
||||||
|
virtual ~Cabinet() {clear();}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static function that returns a pointer to the one Cabinet<M>
|
||||||
|
* instance. All access to the Cabinet<M> instance should go
|
||||||
|
* through this function.
|
||||||
|
*/
|
||||||
|
static Cabinet<M>* cabinet() {
|
||||||
|
if (__storage == 0) {
|
||||||
|
__storage = new Cabinet<M>;
|
||||||
|
}
|
||||||
|
return __storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new object. The index of the object is returned.
|
||||||
|
*/
|
||||||
|
int add(M* ptr) {
|
||||||
|
//try {
|
||||||
|
__table.push_back(ptr);
|
||||||
|
return __table.size() - 1;
|
||||||
|
//}
|
||||||
|
//catch (CanteraError) {return -1;}
|
||||||
|
//catch (...) {return -999;}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a new copy of an existing object. The index of the new
|
||||||
|
* object is returned.
|
||||||
|
*/
|
||||||
|
int newCopy(int i) {
|
||||||
|
try {
|
||||||
|
M* old = __table[i];
|
||||||
|
__table.push_back(new M(*old));
|
||||||
|
return __table.size() - 1;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
catch (...) {return -999;}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assign one object (index j) to another (index i). This method
|
||||||
|
* is not used currently, and may be removed from the class in the
|
||||||
|
* future.
|
||||||
|
*/
|
||||||
|
int assign(int i, int j) {
|
||||||
|
try {
|
||||||
|
M* src = __table[j];
|
||||||
|
M* dest = __table[i];
|
||||||
|
*dest = *src;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
catch (...) {return -999;}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all objects.
|
||||||
|
*/
|
||||||
|
int clear() {
|
||||||
|
int i, n;
|
||||||
|
n = __table.size();
|
||||||
|
for (i = 1; i < n; i++) {del(i);}
|
||||||
|
delete __table[0];
|
||||||
|
__table = vector<M*>();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the nth object. After the object is deleted, the pointer
|
||||||
|
* to it in the list is replaced by a pointer to the first element
|
||||||
|
* in the list.
|
||||||
|
*/
|
||||||
|
void del(int n) {
|
||||||
|
if (n == 0) return;
|
||||||
|
if (__table[n] != __table[0]) {
|
||||||
|
delete __table[n];
|
||||||
|
__table[n] = __table[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw CanteraError("Cabinet<M>::del",
|
||||||
|
"Attempt made to delete an already-deleted object.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a pointer to object n.
|
||||||
|
*/
|
||||||
|
M* item(int n) {
|
||||||
|
if (n >= 0 && n < int(__table.size()))
|
||||||
|
return __table[n];
|
||||||
|
else {
|
||||||
|
throw CanteraError("item","index out of range"+int2str(n));
|
||||||
|
return __table[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
Cabinet() { add(new M); }
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pointer to the single instance of this class.
|
||||||
|
*/
|
||||||
|
static Cabinet<M>* __storage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vector to hold pointers to objects.
|
||||||
|
*/
|
||||||
|
std::vector<M*> __table;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
85
Cantera/clib/src/Makefile.in
Executable file
85
Cantera/clib/src/Makefile.in
Executable file
@ -0,0 +1,85 @@
|
|||||||
|
#/bin/sh
|
||||||
|
###############################################################
|
||||||
|
# $Author$
|
||||||
|
# $Date$
|
||||||
|
# $Revision$
|
||||||
|
#
|
||||||
|
# Copyright 2001 California Institute of Technology
|
||||||
|
#
|
||||||
|
###############################################################
|
||||||
|
|
||||||
|
|
||||||
|
SUFFIXES=
|
||||||
|
SUFFIXES= .cpp .d .o
|
||||||
|
|
||||||
|
CXX_FLAGS = @CXXFLAGS@ $(CXX_OPT)
|
||||||
|
|
||||||
|
OBJS = ct.o Storage.o ctstagn.o ctsurf.o ctrpath.o ctbdry.o ctreactor.o ctfunc.o ctxml.o
|
||||||
|
|
||||||
|
DEPENDS = $(OBJS:.o=.d)
|
||||||
|
|
||||||
|
|
||||||
|
# Fortran libraries
|
||||||
|
FORT_LIBS = @FLIBS@
|
||||||
|
|
||||||
|
shared_ctlib = @SHARED_CTLIB@
|
||||||
|
|
||||||
|
# the C++ compiler
|
||||||
|
CXX = @CXX@
|
||||||
|
|
||||||
|
# external libraries
|
||||||
|
EXT_LIBS = -lzeroD -loneD @LOCAL_LIBS@
|
||||||
|
|
||||||
|
# the directory where the Cantera libraries are located
|
||||||
|
CANTERA_LIBDIR=../../../lib
|
||||||
|
LIB_DEPS = $(CANTERA_LIBDIR)/libcantera.a $(CANTERA_LIBDIR)/libzeroD.a \
|
||||||
|
$(CANTERA_LIBDIR)/liboneD.a $(CANTERA_LIBDIR)/libconverters.a
|
||||||
|
|
||||||
|
# the directory where Cantera include files may be found.
|
||||||
|
CANTERA_INCDIR=../../src
|
||||||
|
|
||||||
|
CXX_INCLUDES = -I$(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 $< $(CXX_INCLUDES) $(CXX_FLAGS) @PIC@
|
||||||
|
|
||||||
|
LIB_NAME=lib@CT_SHARED_LIB@
|
||||||
|
|
||||||
|
ifeq ($(shared_ctlib),1)
|
||||||
|
CTLIB = ./$(LIB_NAME)@SO@
|
||||||
|
else
|
||||||
|
CTLIB = ./$(LIB_NAME).a
|
||||||
|
endif
|
||||||
|
|
||||||
|
lib: $(OBJS) $(LIB_DEPS)
|
||||||
|
$(RM) $(CTLIB)
|
||||||
|
ifeq ($(shared_ctlib),1)
|
||||||
|
$(CXX) -o $(CTLIB) $(OBJS) $(LCXX_FLAGS) @SHARED@ $(LINK_OPTIONS) $(EXT_LIBS) @LIBS@ $(FORT_LIBS)
|
||||||
|
cp $(CTLIB) ../../../lib
|
||||||
|
else
|
||||||
|
@ARCHIVE@ $(CTLIB) $(OBJS)
|
||||||
|
cp $(CTLIB) ../../../lib
|
||||||
|
ranlib ../../../lib/$(CTLIB)
|
||||||
|
endif
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(OBJS) $(CTLIB)
|
||||||
|
|
||||||
|
install:
|
||||||
|
@INSTALL@ $(CTLIB) @prefix@/lib/cantera
|
||||||
|
|
||||||
|
|
||||||
|
%.d:
|
||||||
|
g++ -MM $(CXX_INCLUDES) $*.cpp > $*.d
|
||||||
|
|
||||||
|
depends: $(DEPENDS)
|
||||||
|
cat *.d > .depends
|
||||||
|
$(RM) $(DEPENDS)
|
||||||
|
|
||||||
|
ifeq ($(wildcard .depends), .depends)
|
||||||
|
include .depends
|
||||||
|
endif
|
115
Cantera/clib/src/Storage.cpp
Executable file
115
Cantera/clib/src/Storage.cpp
Executable file
@ -0,0 +1,115 @@
|
|||||||
|
|
||||||
|
// Build as a DLL under Windows
|
||||||
|
#ifdef WIN32
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#pragma warning(disable:4503)
|
||||||
|
#else
|
||||||
|
#define DLL_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Cantera includes
|
||||||
|
#include "Kinetics.h"
|
||||||
|
#include "transport/TransportFactory.h"
|
||||||
|
|
||||||
|
#include "clib_defs.h"
|
||||||
|
#include "Storage.h"
|
||||||
|
|
||||||
|
|
||||||
|
Storage::Storage() {
|
||||||
|
addThermo(new ThermoPhase);
|
||||||
|
addKinetics(new Kinetics);
|
||||||
|
addTransport(newTransportMgr());
|
||||||
|
}
|
||||||
|
|
||||||
|
Storage::~Storage() { clear(); }
|
||||||
|
|
||||||
|
int Storage::addThermo(thermo_t* th) {
|
||||||
|
if (th->index() >= 0)
|
||||||
|
return th->index();
|
||||||
|
__thtable.push_back(th);
|
||||||
|
int n = __thtable.size() - 1;
|
||||||
|
th->setIndex(n);
|
||||||
|
__thmap[th->id()] = n;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Storage::nThermo() { return __thtable.size(); }
|
||||||
|
|
||||||
|
int Storage::addKinetics(Kinetics* kin) {
|
||||||
|
if (kin->index() >= 0)
|
||||||
|
return kin->index();
|
||||||
|
__ktable.push_back(kin);
|
||||||
|
int n = __ktable.size() - 1;
|
||||||
|
kin->setIndex(n);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Storage::addTransport(Transport* tr) {
|
||||||
|
if (tr->index() >= 0)
|
||||||
|
return tr->index();
|
||||||
|
__trtable.push_back(tr);
|
||||||
|
int n = __trtable.size() - 1;
|
||||||
|
tr->setIndex(n);
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
// int Storage::addNewTransport(int model, char* dbase, int th,
|
||||||
|
// int loglevel) {
|
||||||
|
// try {
|
||||||
|
// ThermoPhase* thrm = __thtable[th];
|
||||||
|
// Transport* tr = newTransportMgr(model,
|
||||||
|
// string(dbase), thrm, loglevel);
|
||||||
|
// __trtable.push_back(tr);
|
||||||
|
// return __trtable.size() - 1;
|
||||||
|
// }
|
||||||
|
// catch (CanteraError) {return -1;}
|
||||||
|
// catch (...) {return ERR;}
|
||||||
|
// }
|
||||||
|
|
||||||
|
int Storage::clear() {
|
||||||
|
int i, n;
|
||||||
|
n = __thtable.size();
|
||||||
|
for (i = 1; i < n; i++) {
|
||||||
|
if (__thtable[i] != __thtable[0])
|
||||||
|
delete __thtable[i];
|
||||||
|
__thtable[i] = __thtable[0];
|
||||||
|
}
|
||||||
|
n = __ktable.size();
|
||||||
|
for (i = 1; i < n; i++) {
|
||||||
|
if (__ktable[i] != __ktable[0])
|
||||||
|
delete __ktable[i];
|
||||||
|
__ktable[i] = __ktable[0];
|
||||||
|
}
|
||||||
|
n = __trtable.size();
|
||||||
|
for (i = 1; i < n; i++) {
|
||||||
|
if (__trtable[i] != __trtable[0])
|
||||||
|
delete __trtable[i];
|
||||||
|
__trtable[i] = __trtable[0];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Storage::deleteKinetics(int n) {
|
||||||
|
if (n == 0) return;
|
||||||
|
if (__ktable[n] != __ktable[0])
|
||||||
|
delete __ktable[n];
|
||||||
|
__ktable[n] = __ktable[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Storage::deleteThermo(int n) {
|
||||||
|
if (n == 0) return;
|
||||||
|
if (n < 0 || n >= (int) __thtable.size())
|
||||||
|
throw CanteraError("deleteThermo","illegal index");
|
||||||
|
__thtable[n] = __thtable[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Storage::deleteTransport(int n) {
|
||||||
|
if (n == 0) return;
|
||||||
|
if (__trtable[n] != __trtable[0])
|
||||||
|
delete __trtable[n];
|
||||||
|
__trtable[n] = __trtable[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
Storage* Storage::__storage = 0;
|
||||||
|
|
68
Cantera/clib/src/Storage.h
Executable file
68
Cantera/clib/src/Storage.h
Executable file
@ -0,0 +1,68 @@
|
|||||||
|
#ifndef CTC_STORAGE_H
|
||||||
|
#define CTC_STORAGE_H
|
||||||
|
|
||||||
|
// Cantera includes
|
||||||
|
#include "Kinetics.h"
|
||||||
|
#include "transport/TransportBase.h"
|
||||||
|
|
||||||
|
#include "Cabinet.h"
|
||||||
|
#include "clib_defs.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to hold pointers to Cantera objects. Only one instance of
|
||||||
|
* this class is needed.
|
||||||
|
*/
|
||||||
|
class Storage {
|
||||||
|
public:
|
||||||
|
Storage();
|
||||||
|
virtual ~Storage();
|
||||||
|
|
||||||
|
// vectors to hold pointers to objects
|
||||||
|
vector<Kinetics*> __ktable;
|
||||||
|
vector<thermo_t*> __thtable;
|
||||||
|
vector<Transport*> __trtable;
|
||||||
|
|
||||||
|
map<string, int> __thmap;
|
||||||
|
|
||||||
|
static Storage* storage() {
|
||||||
|
if (__storage == 0) {
|
||||||
|
__storage = new Storage;
|
||||||
|
}
|
||||||
|
return __storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int addThermo(ThermoPhase* th);
|
||||||
|
int addKinetics(Kinetics* kin);
|
||||||
|
int addTransport(Transport* tr);
|
||||||
|
// int addNewTransport(int model, char* dbase, int th, int loglevel);
|
||||||
|
int clear();
|
||||||
|
void deleteKinetics(int n);
|
||||||
|
void deleteThermo(int n);
|
||||||
|
void deleteTransport(int n);
|
||||||
|
int nThermo();
|
||||||
|
static Storage* __storage;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline ThermoPhase* ph(int n) {
|
||||||
|
return Storage::__storage->__thtable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Kinetics* kin(int n) {
|
||||||
|
return Storage::__storage->__ktable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ThermoPhase* th(int n) {
|
||||||
|
return Storage::__storage->__thtable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int thermo_index(string id) {
|
||||||
|
return Storage::__storage->__thmap[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Transport* trans(int n) {
|
||||||
|
return Storage::__storage->__trtable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
19
Cantera/clib/src/clib_defs.h
Executable file
19
Cantera/clib/src/clib_defs.h
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef CTC_DEFS_H
|
||||||
|
#define CTC_DEFS_H
|
||||||
|
|
||||||
|
// Build as a DLL under Windows
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DLL_IMPORT __declspec(dllimport)
|
||||||
|
#define DLL_EXPORT __declspec(dllexport)
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#pragma warning(disable:4503)
|
||||||
|
#else
|
||||||
|
#define DLL_EXPORT
|
||||||
|
#define DLL_IMPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Values returned for error conditions
|
||||||
|
#define ERR -999
|
||||||
|
#define DERR -999.999
|
||||||
|
|
||||||
|
#endif
|
863
Cantera/clib/src/ct.cpp
Executable file
863
Cantera/clib/src/ct.cpp
Executable file
@ -0,0 +1,863 @@
|
|||||||
|
/**
|
||||||
|
* Cantera interface library. This library of functions is designed
|
||||||
|
* to encapsulate Cantera functionality and make it available for
|
||||||
|
* use in languages and applications other than C++. A set of
|
||||||
|
* library functions is provided that are declared "extern C". All
|
||||||
|
* Cantera objects are stored and referenced by integers - no
|
||||||
|
* pointers are passed to or from the calling application.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// turn off warnings under Windows
|
||||||
|
#ifdef WIN32
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#pragma warning(disable:4503)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Cantera includes
|
||||||
|
#include "ChemEquil.h"
|
||||||
|
#include "KineticsFactory.h"
|
||||||
|
#include "transport/TransportFactory.h"
|
||||||
|
#include "ctml.h"
|
||||||
|
#include "importCTML.h"
|
||||||
|
#include "converters/ck2ctml.h"
|
||||||
|
#include "Storage.h"
|
||||||
|
#include "Cabinet.h"
|
||||||
|
|
||||||
|
#include "clib_defs.h"
|
||||||
|
|
||||||
|
inline XML_Node* _xml(int i) {
|
||||||
|
return Cabinet<XML_Node>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int nThermo() {
|
||||||
|
return Storage::storage()->nThermo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exported functions.
|
||||||
|
*/
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
//--------------- Phase ---------------------//
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_nElements(int n) {
|
||||||
|
return ph(n)->nElements();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_nSpecies(int n) {
|
||||||
|
return ph(n)->nSpecies();
|
||||||
|
}
|
||||||
|
|
||||||
|
doublereal DLL_EXPORT phase_temperature(int n) {
|
||||||
|
return ph(n)->temperature();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_setTemperature(int n, double t) {
|
||||||
|
ph(n)->setTemperature(t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
doublereal DLL_EXPORT phase_density(int n) {
|
||||||
|
return ph(n)->density();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_setDensity(int n, double rho) {
|
||||||
|
if (rho < 0.0) throw CanteraError("phase_setDensity",
|
||||||
|
"density cannot be negative");
|
||||||
|
ph(n)->setDensity(rho);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
doublereal DLL_EXPORT phase_molarDensity(int n) {
|
||||||
|
return ph(n)->molarDensity();
|
||||||
|
}
|
||||||
|
|
||||||
|
doublereal DLL_EXPORT phase_meanMolecularWeight(int n) {
|
||||||
|
return ph(n)->meanMolecularWeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_elementIndex(int n, char* nm) {
|
||||||
|
string elnm = string(nm);
|
||||||
|
return ph(n)->elementIndex(elnm);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_speciesIndex(int n, char* nm) {
|
||||||
|
string spnm = string(nm);
|
||||||
|
return ph(n)->speciesIndex(spnm);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_getMoleFractions(int n, int lenx, double* x) {
|
||||||
|
ThermoPhase* p = ph(n);
|
||||||
|
if (lenx >= p->nSpecies()) {
|
||||||
|
p->getMoleFractions(x);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
doublereal DLL_EXPORT phase_moleFraction(int n, int k) {
|
||||||
|
ThermoPhase* p = ph(n);
|
||||||
|
return p->moleFraction(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_getMassFractions(int n, int leny, double* y) {
|
||||||
|
ThermoPhase* p = ph(n);
|
||||||
|
if (leny >= p->nSpecies()) {
|
||||||
|
p->getMassFractions(leny, y);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
doublereal DLL_EXPORT phase_massFraction(int n, int k) {
|
||||||
|
ThermoPhase* p = ph(n);
|
||||||
|
return p->massFraction(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_setMoleFractions(int n, int lenx, double* x, int norm) {
|
||||||
|
ThermoPhase* p = ph(n);
|
||||||
|
if (lenx >= p->nSpecies()) {
|
||||||
|
if (norm) p->setMoleFractions(x);
|
||||||
|
else p->setMoleFractions_NoNorm(x);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_setMoleFractionsByName(int n, char* x) {
|
||||||
|
try {
|
||||||
|
ThermoPhase* p = ph(n);
|
||||||
|
compositionMap xx;
|
||||||
|
int nsp = p->nSpecies();
|
||||||
|
for (int n = 0; n < nsp; n++) {
|
||||||
|
xx[p->speciesName(n)] = -1;
|
||||||
|
}
|
||||||
|
parseCompString(string(x), xx);
|
||||||
|
p->setMoleFractionsByName(xx);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
//catch (...) {return ERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_setMassFractions(int n, int leny,
|
||||||
|
double* y, int norm) {
|
||||||
|
ThermoPhase* p = ph(n);
|
||||||
|
if (leny >= p->nSpecies()) {
|
||||||
|
if (norm) p->setMassFractions(y);
|
||||||
|
else p->setMassFractions_NoNorm(y);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -10;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_setMassFractionsByName(int n, char* y) {
|
||||||
|
try {
|
||||||
|
ThermoPhase* p = ph(n);
|
||||||
|
compositionMap yy;
|
||||||
|
int nsp = p->nSpecies();
|
||||||
|
for (int n = 0; n < nsp; n++) {
|
||||||
|
yy[p->speciesName(n)] = -1;
|
||||||
|
}
|
||||||
|
parseCompString(string(y), yy);
|
||||||
|
p->setMassFractionsByName(yy);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_getAtomicWeights(int n,
|
||||||
|
int lenm, double* atw) {
|
||||||
|
ThermoPhase* p = ph(n);
|
||||||
|
if (lenm >= p->nElements()) {
|
||||||
|
const vector_fp& wt = p->atomicWeights();
|
||||||
|
copy(wt.begin(), wt.end(), atw);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -10;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_getMolecularWeights(int n,
|
||||||
|
int lenm, double* mw) {
|
||||||
|
ThermoPhase* p = ph(n);
|
||||||
|
if (lenm >= p->nSpecies()) {
|
||||||
|
const vector_fp& wt = p->molecularWeights();
|
||||||
|
copy(wt.begin(), wt.end(), mw);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -10;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_getSpeciesName(int n, int k, int lennm, char* nm) {
|
||||||
|
try {
|
||||||
|
string spnm = ph(n)->speciesName(k);
|
||||||
|
int lout = min(lennm,spnm.size());
|
||||||
|
copy(spnm.c_str(), spnm.c_str() + lout, nm);
|
||||||
|
nm[lout] = '\0';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
//catch (...) {return ERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_getElementName(int n, int m, int lennm, char* nm) {
|
||||||
|
try {
|
||||||
|
string elnm = ph(n)->elementName(m);
|
||||||
|
int lout = min(lennm,elnm.size());
|
||||||
|
copy(elnm.c_str(), elnm.c_str() + lout, nm);
|
||||||
|
nm[lout] = '\0';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
doublereal DLL_EXPORT phase_nAtoms(int n, int k, int m) {
|
||||||
|
try {
|
||||||
|
return ph(n)->nAtoms(k,m);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_addElement(int n, char* name, doublereal weight) {
|
||||||
|
try {
|
||||||
|
ph(n)->addElement(string(name),weight);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// int DLL_EXPORT phase_addSpecies(int n, char* name, int phase,
|
||||||
|
// int ncomp, doublereal* comp, int thermoType, int ncoeffs,
|
||||||
|
// double* coeffs, double minTemp, double maxTemp, double refPressure,
|
||||||
|
// doublereal charge, doublereal weight) {
|
||||||
|
// try {
|
||||||
|
// vector_fp cmp(ncomp);
|
||||||
|
// copy(comp, comp + ncomp, cmp.begin());
|
||||||
|
// vector_fp c(ncoeffs);
|
||||||
|
// copy(coeffs, coeffs + ncoeffs, c.begin());
|
||||||
|
// ph(n)->addSpecies(string(name), phase, cmp,
|
||||||
|
// thermoType, c, minTemp, maxTemp, refPressure,
|
||||||
|
// charge, weight);
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// catch (CanteraError) { return -1; }
|
||||||
|
// catch (...) {return ERR;}
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-------------- Thermo --------------------//
|
||||||
|
|
||||||
|
// int DLL_EXPORT newThermo(int eos, int ph, int sptherm) {
|
||||||
|
// return Storage::storage()->addNewThermo(eos, ph, sptherm);
|
||||||
|
// }
|
||||||
|
|
||||||
|
int DLL_EXPORT th_thermoIndex(char* id) {
|
||||||
|
return thermo_index(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// int DLL_EXPORT newThermo(char* model) {
|
||||||
|
// try {
|
||||||
|
// string m = string(model);
|
||||||
|
// thermo_t* th = newThermoPhase(m);
|
||||||
|
// return Storage::storage()->addThermo(th);
|
||||||
|
// }
|
||||||
|
// catch (CanteraError) { return -1; }
|
||||||
|
// }
|
||||||
|
|
||||||
|
int DLL_EXPORT newThermoFromXML(int mxml) {
|
||||||
|
try {
|
||||||
|
XML_Node* x = _xml(mxml);
|
||||||
|
thermo_t* th = newPhase(*x);
|
||||||
|
return Storage::storage()->addThermo(th);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
//int DLL_EXPORT th_phase(int n) {
|
||||||
|
// return th(n)->phase().index();
|
||||||
|
// }
|
||||||
|
|
||||||
|
int DLL_EXPORT th_nSpecies(int n) {
|
||||||
|
return th(n)->nSpecies();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT th_eosType(int n) {
|
||||||
|
return th(n)->eosType();
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT th_enthalpy_mole(int n) {
|
||||||
|
try {return th(n)->enthalpy_mole();}
|
||||||
|
catch (CanteraError) {return DERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT th_intEnergy_mole(int n) {
|
||||||
|
try {return th(n)->intEnergy_mole();}
|
||||||
|
catch (CanteraError) {return DERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT th_entropy_mole(int n) {
|
||||||
|
try {return th(n)->entropy_mole();}
|
||||||
|
catch (CanteraError) {return DERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT th_gibbs_mole(int n) {
|
||||||
|
try {return th(n)->gibbs_mole();}
|
||||||
|
catch (CanteraError) {return DERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT th_cp_mole(int n) {
|
||||||
|
try {return th(n)->cp_mole();}
|
||||||
|
catch (CanteraError) {return DERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT th_cv_mole(int n) {
|
||||||
|
try {return th(n)->cv_mole();}
|
||||||
|
catch (CanteraError) {return DERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT th_pressure(int n) {
|
||||||
|
try {return th(n)->pressure();}
|
||||||
|
catch (CanteraError) {return DERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT th_enthalpy_mass(int n) {
|
||||||
|
try {return th(n)->enthalpy_mass();}
|
||||||
|
catch (CanteraError) {return DERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT th_intEnergy_mass(int n) {
|
||||||
|
try {return th(n)->intEnergy_mass();}
|
||||||
|
catch (CanteraError) {return DERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT th_entropy_mass(int n) {
|
||||||
|
try {return th(n)->entropy_mass();}
|
||||||
|
catch (CanteraError) {return DERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT th_gibbs_mass(int n) {
|
||||||
|
try {return th(n)->gibbs_mass();}
|
||||||
|
catch (CanteraError) {return DERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT th_cp_mass(int n) {
|
||||||
|
try {return th(n)->cp_mass();}
|
||||||
|
catch (CanteraError) {return DERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT th_cv_mass(int n) {
|
||||||
|
try {return th(n)->cv_mass();}
|
||||||
|
catch (CanteraError) {return DERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT th_chemPotentials(int n, int lenm, double* murt) {
|
||||||
|
thermo_t* thrm = th(n);
|
||||||
|
int nsp = thrm->nSpecies();
|
||||||
|
if (lenm >= nsp) {
|
||||||
|
thrm->getChemPotentials(murt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -10;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT th_setPressure(int n, double p) {
|
||||||
|
try {
|
||||||
|
if (p < 0.0) throw CanteraError("th_setPressure",
|
||||||
|
"pressure cannot be negative");
|
||||||
|
th(n)->setPressure(p);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT th_set_HP(int n, double* vals) {
|
||||||
|
try {
|
||||||
|
if (vals[1] < 0.0)
|
||||||
|
throw CanteraError("th_set_HP",
|
||||||
|
"pressure cannot be negative");
|
||||||
|
th(n)->setState_HP(vals[0],vals[1]);
|
||||||
|
if (th(n)->temperature() < 0.0)
|
||||||
|
throw CanteraError("th_set_HP",
|
||||||
|
"temperature cannot be negative");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT th_set_UV(int n, double* vals) {
|
||||||
|
try {
|
||||||
|
if (vals[1] < 0.0)
|
||||||
|
throw CanteraError("th_set_UV",
|
||||||
|
"specific volume cannot be negative");
|
||||||
|
th(n)->setState_UV(vals[0],vals[1]);
|
||||||
|
if (th(n)->temperature() < 0.0)
|
||||||
|
throw CanteraError("th_set_UV",
|
||||||
|
"temperature cannot be negative");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT th_set_SV(int n, double* vals) {
|
||||||
|
try { th(n)->setState_SV(vals[0],vals[1]);
|
||||||
|
return 0; }
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
catch (...) {return ERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT th_set_SP(int n, double* vals) {
|
||||||
|
try {
|
||||||
|
th(n)->setState_SP(vals[0],vals[1]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT th_equil(int n, int XY) {
|
||||||
|
try {
|
||||||
|
equilibrate(*th(n), XY); return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
doublereal DLL_EXPORT th_refPressure(int n) {
|
||||||
|
return th(n)->refPressure();
|
||||||
|
}
|
||||||
|
|
||||||
|
doublereal DLL_EXPORT th_minTemp(int n, int k) {
|
||||||
|
return th(n)->minTemp(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
doublereal DLL_EXPORT th_maxTemp(int n, int k) {
|
||||||
|
return th(n)->maxTemp(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int DLL_EXPORT th_getEnthalpies_RT(int n, int lenm, double* h_rt) {
|
||||||
|
thermo_t* thrm = th(n);
|
||||||
|
int nsp = thrm->nSpecies();
|
||||||
|
if (lenm >= nsp) {
|
||||||
|
thrm->getEnthalpy_RT(h_rt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -10;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT th_getEntropies_R(int n, int lenm, double* s_r) {
|
||||||
|
thermo_t* thrm = th(n);
|
||||||
|
int nsp = thrm->nSpecies();
|
||||||
|
if (lenm >= nsp) {
|
||||||
|
thrm->getEntropy_R(s_r);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -10;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT th_getCp_R(int n, int lenm, double* cp_r) {
|
||||||
|
thermo_t* thrm = th(n);
|
||||||
|
int nsp = thrm->nSpecies();
|
||||||
|
if (lenm >= nsp) {
|
||||||
|
thrm->getCp_R(cp_r);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -10;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------- Kinetics ------------------//
|
||||||
|
|
||||||
|
int DLL_EXPORT newKineticsFromXML(int mxml, int iphase,
|
||||||
|
int neighbor1, int neighbor2) {
|
||||||
|
try {
|
||||||
|
XML_Node* x = _xml(mxml);
|
||||||
|
vector<thermo_t*> phases;
|
||||||
|
phases.push_back(th(iphase));
|
||||||
|
if (neighbor1 >= 0) {
|
||||||
|
phases.push_back(th(neighbor1));
|
||||||
|
if (neighbor2 >= 0) {
|
||||||
|
phases.push_back(th(neighbor2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Kinetics* kin = newKineticsMgr(*x, phases);
|
||||||
|
return Storage::storage()->addKinetics(kin);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT installRxnArrays(int pxml, int ikin,
|
||||||
|
char* default_phase) {
|
||||||
|
try {
|
||||||
|
XML_Node* p = _xml(pxml);
|
||||||
|
kinetics_t* k = kin(ikin);
|
||||||
|
string defphase = string(default_phase);
|
||||||
|
installReactionArrays(*p, *k, defphase);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------
|
||||||
|
int DLL_EXPORT kin_type(int n) {
|
||||||
|
return kin(n)->type();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_start(int n, int p) {
|
||||||
|
return kin(n)->start(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_speciesIndex(int n, const char* nm, const char* ph) {
|
||||||
|
return kin(n)->kineticsSpeciesIndex(string(nm), string(ph));
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_nSpecies(int n) {
|
||||||
|
return kin(n)->nTotalSpecies();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_nReactions(int n) {
|
||||||
|
return kin(n)->nReactions();
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT kin_reactantStoichCoeff(int n, int k, int i) {
|
||||||
|
return kin(n)->reactantStoichCoeff(k,i);
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT kin_productStoichCoeff(int n, int k, int i) {
|
||||||
|
return kin(n)->productStoichCoeff(k,i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_reactionType(int n, int i) {
|
||||||
|
return kin(n)->reactionType(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_getFwdRatesOfProgress(int n, int len, double* fwdROP) {
|
||||||
|
Kinetics* k = kin(n);
|
||||||
|
try {
|
||||||
|
if (len >= k->nReactions()) {
|
||||||
|
k->getFwdRatesOfProgress(fwdROP);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_getRevRatesOfProgress(int n, int len, double* revROP) {
|
||||||
|
Kinetics* k = kin(n);
|
||||||
|
try {
|
||||||
|
if (len >= k->nReactions()) {
|
||||||
|
k->getRevRatesOfProgress(revROP);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_isReversible(int n, int i) {
|
||||||
|
return (int)kin(n)->isReversible(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_getNetRatesOfProgress(int n, int len, double* netROP) {
|
||||||
|
try {
|
||||||
|
Kinetics* k = kin(n);
|
||||||
|
if (len >= k->nReactions()) {
|
||||||
|
k->getNetRatesOfProgress(netROP);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_getCreationRates(int n, int len, double* cdot) {
|
||||||
|
try {
|
||||||
|
Kinetics* k = kin(n);
|
||||||
|
if (len >= k->nTotalSpecies()) {
|
||||||
|
k->getCreationRates(cdot);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_getDestructionRates(int n, int len, double* ddot) {
|
||||||
|
try {
|
||||||
|
Kinetics* k = kin(n);
|
||||||
|
if (len >= k->nTotalSpecies()) {
|
||||||
|
k->getDestructionRates(ddot);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
//catch (...) {return ERR;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_getNetProductionRates(int n, int len, double* wdot) {
|
||||||
|
try {
|
||||||
|
Kinetics* k = kin(n);
|
||||||
|
if (len >= k->nTotalSpecies()) {
|
||||||
|
k->getNetProductionRates(wdot);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_getSourceTerms(int n, int len, double* ydot) {
|
||||||
|
try {
|
||||||
|
Kinetics* k = kin(n);
|
||||||
|
ThermoPhase* p = &k->thermo();
|
||||||
|
const vector_fp& mw = p->molecularWeights();
|
||||||
|
int nsp = mw.size();
|
||||||
|
double rrho = 1.0/p->density();
|
||||||
|
if (len >= nsp) {
|
||||||
|
k->getNetProductionRates(ydot);
|
||||||
|
multiply_each(ydot, ydot + nsp, mw.begin());
|
||||||
|
scale(ydot, ydot + nsp, ydot, rrho);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT kin_multiplier(int n, int i) {
|
||||||
|
return kin(n)->multiplier(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_getEquilibriumConstants(int n, int len, double* kc) {
|
||||||
|
try {
|
||||||
|
Kinetics* k = kin(n);
|
||||||
|
if (len >= k->nReactions()) {
|
||||||
|
k->getEquilibriumConstants(kc);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return ERR;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_getReactionString(int n, int i, int len, char* buf) {
|
||||||
|
try {
|
||||||
|
Kinetics* k = kin(n);
|
||||||
|
string r = k->reactionString(i);
|
||||||
|
int lout = min(len,r.size());
|
||||||
|
copy(r.c_str(), r.c_str() + lout, buf);
|
||||||
|
buf[lout] = '\0';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT kin_setMultiplier(int n, int i, double v) {
|
||||||
|
try {
|
||||||
|
if (v >= 0.0) {
|
||||||
|
kin(n)->setMultiplier(i,v);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else return ERR;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//------------------- Transport ---------------------------
|
||||||
|
|
||||||
|
int DLL_EXPORT newTransport(char* model,
|
||||||
|
int ith, int loglevel) {
|
||||||
|
string mstr = string(model);
|
||||||
|
thermo_t* t = th(ith);
|
||||||
|
try {
|
||||||
|
Transport* tr = newTransportMgr(mstr,t, loglevel);
|
||||||
|
return Storage::storage()->addTransport(tr);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT trans_viscosity(int n) {
|
||||||
|
try {return trans(n)->viscosity();}
|
||||||
|
catch (CanteraError) { return -1.0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT trans_thermalConductivity(int n) {
|
||||||
|
try {return trans(n)->thermalConductivity();}
|
||||||
|
catch (CanteraError) { return -1.0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT trans_getThermalDiffCoeffs(int n, int ldt, double* dt) {
|
||||||
|
try { trans(n)->getThermalDiffCoeffs(dt); return 0; }
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT trans_getMixDiffCoeffs(int n, int ld, double* d) {
|
||||||
|
try { trans(n)->getMixDiffCoeffs(d); return 0;}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT trans_getBinDiffCoeffs(int n, int ld, double* d) {
|
||||||
|
try { trans(n)->getBinaryDiffCoeffs(ld,d); return 0;}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT trans_getMultiDiffCoeffs(int n, int ld, double* d) {
|
||||||
|
try { trans(n)->getMultiDiffCoeffs(ld,d); return 0;}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------- Functions ---------------------------
|
||||||
|
|
||||||
|
int DLL_EXPORT import_phase(int nth, int nxml, char* id) {
|
||||||
|
thermo_t* thrm = th(nth);
|
||||||
|
XML_Node* node = _xml(nxml);
|
||||||
|
string idstr = string(id);
|
||||||
|
try {
|
||||||
|
importPhase(*node, thrm);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT import_kinetics(int nxml, char* id,
|
||||||
|
int nphases, integer* ith, int nkin) {
|
||||||
|
vector<thermo_t*> phases;
|
||||||
|
for (int i = 0; i < nphases; i++) {
|
||||||
|
phases.push_back(th(ith[i]));
|
||||||
|
}
|
||||||
|
XML_Node* node = _xml(nxml);
|
||||||
|
Kinetics* k = kin(nkin);
|
||||||
|
string idstr = string(id);
|
||||||
|
try {
|
||||||
|
importKinetics(*node, phases, k);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int DLL_EXPORT phase_report(int nth,
|
||||||
|
int ibuf, char* buf, int show_thermo) {
|
||||||
|
try {
|
||||||
|
bool stherm = (show_thermo != 0);
|
||||||
|
string s = report(*th(nth), stherm);
|
||||||
|
if (int(s.size()) > ibuf - 1) {
|
||||||
|
return -(s.size() + 1);
|
||||||
|
}
|
||||||
|
copy(s.begin(), s.end(), buf);
|
||||||
|
buf[s.size() - 1] = '\0';
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT getCanteraError(int buflen, char* buf) {
|
||||||
|
string e; // = "<no error>";
|
||||||
|
//if (nErrors() > 0)
|
||||||
|
e = lastErrorMessage();
|
||||||
|
int n = min(e.size(), buflen-1);
|
||||||
|
copy(e.begin(), e.begin() + n, buf);
|
||||||
|
buf[min(n, buflen-1)] = '\0';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT addCanteraDirectory(int buflen, char* buf) {
|
||||||
|
addDirectory(string(buf));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT readlog(int n, char* buf) {
|
||||||
|
string s;
|
||||||
|
getlog(s);
|
||||||
|
int nlog = s.size();
|
||||||
|
if (n < 0) return nlog;
|
||||||
|
int nn = min(n-1, nlog);
|
||||||
|
copy(s.begin(), s.begin() + nn,
|
||||||
|
buf);
|
||||||
|
buf[min(nlog, n-1)] = '\0';
|
||||||
|
clearlog();
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
int DLL_EXPORT clearStorage() {
|
||||||
|
Storage::__storage->clear();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT delThermo(int n) {
|
||||||
|
try {
|
||||||
|
Storage::__storage->deleteThermo(n);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT delKinetics(int n) {
|
||||||
|
Storage::__storage->deleteKinetics(n);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT delTransport(int n) {
|
||||||
|
Storage::__storage->deleteTransport(n);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT buildSolutionFromXML(char* src, int ixml, char* id,
|
||||||
|
int ith, int ikin) {
|
||||||
|
|
||||||
|
XML_Node* root = 0;
|
||||||
|
if (ixml > 0) root = _xml(ixml);
|
||||||
|
|
||||||
|
thermo_t* t = th(ith);
|
||||||
|
kinetics_t* k = kin(ikin);
|
||||||
|
|
||||||
|
Kinetics& kin = *k;
|
||||||
|
XML_Node *x, *r=0;
|
||||||
|
if (root) r = &root->root();
|
||||||
|
x = find_XML(string(src), r, string(id), "", "phase");
|
||||||
|
if (!x) return false;
|
||||||
|
importPhase(*x, t);
|
||||||
|
kin.addPhase(*t);
|
||||||
|
kin.init();
|
||||||
|
installReactionArrays(*x, kin, x->id());
|
||||||
|
t->setState_TP(300.0, OneAtm);
|
||||||
|
if (r) {
|
||||||
|
if (&x->root() != &r->root()) delete &x->root();
|
||||||
|
}
|
||||||
|
else delete &x->root();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int DLL_EXPORT ck_to_ctml(char* in_file, char* db_file,
|
||||||
|
char* tr_file, char* out_file, char* id_tag) {
|
||||||
|
return convert_ck(in_file, db_file, tr_file, out_file, id_tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
132
Cantera/clib/src/ct.h
Executable file
132
Cantera/clib/src/ct.h
Executable file
@ -0,0 +1,132 @@
|
|||||||
|
#ifndef CTC_CT_H
|
||||||
|
#define CTC_CT_H
|
||||||
|
|
||||||
|
#include "clib_defs.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
int DLL_IMPORT phase_nElements(int n);
|
||||||
|
int DLL_IMPORT phase_nSpecies(int n);
|
||||||
|
double DLL_IMPORT phase_temperature(int n);
|
||||||
|
int DLL_IMPORT phase_setTemperature(int n, double t);
|
||||||
|
double DLL_IMPORT phase_density(int n);
|
||||||
|
int DLL_IMPORT phase_setDensity(int n, double rho);
|
||||||
|
double DLL_IMPORT phase_molarDensity(int n);
|
||||||
|
double DLL_IMPORT phase_meanMolecularWeight(int n);
|
||||||
|
double DLL_IMPORT phase_moleFraction(int n, int k);
|
||||||
|
double DLL_IMPORT phase_massFraction(int n, int k);
|
||||||
|
int DLL_IMPORT phase_getMoleFractions(int n, int lenx, double* x);
|
||||||
|
int DLL_IMPORT phase_getMassFractions(int n, int leny, double* y);
|
||||||
|
int DLL_IMPORT phase_setMoleFractions(int n, int lenx,
|
||||||
|
double* x, int norm);
|
||||||
|
int DLL_IMPORT phase_setMassFractions(int n, int leny,
|
||||||
|
double* y, int norm);
|
||||||
|
int DLL_IMPORT phase_setMoleFractionsByName(int n, char* x);
|
||||||
|
int DLL_IMPORT phase_setMassFractionsByName(int n, char* y);
|
||||||
|
int DLL_IMPORT phase_getAtomicWeights(int n, int lenm, double* atw);
|
||||||
|
int DLL_IMPORT phase_getMolecularWeights(int n, int lenm, double* mw);
|
||||||
|
int DLL_IMPORT phase_getElementName(int n, int k, int lennm, char* nm);
|
||||||
|
int DLL_IMPORT phase_getSpeciesName(int n, int m, int lennm, char* nm);
|
||||||
|
int DLL_IMPORT phase_elementIndex(int n, char* nm);
|
||||||
|
int DLL_IMPORT phase_speciesIndex(int n, char* nm);
|
||||||
|
int DLL_IMPORT phase_report(int nth,
|
||||||
|
int ibuf, char* buf, int show_thermo);
|
||||||
|
double DLL_IMPORT phase_nAtoms(int n, int k, int m);
|
||||||
|
|
||||||
|
int DLL_IMPORT phase_addElement(int n, char* name, double weight);
|
||||||
|
int DLL_IMPORT phase_addSpecies(int n, char* name, int phase,
|
||||||
|
int ncomp, double* comp, int thermoType, int ncoeffs,
|
||||||
|
double* coeffs, double minTemp, double maxTemp, double refPressure,
|
||||||
|
double charge, double weight);
|
||||||
|
|
||||||
|
//int DLL_IMPORT newThermo(char* model);
|
||||||
|
int DLL_IMPORT newThermoFromXML(int mxml);
|
||||||
|
int DLL_IMPORT th_thermoIndex(char* id);
|
||||||
|
int DLL_IMPORT th_phase(int n);
|
||||||
|
int DLL_IMPORT th_nSpecies(int n);
|
||||||
|
int DLL_IMPORT th_eosType(int n);
|
||||||
|
double DLL_IMPORT th_refPressure(int n);
|
||||||
|
double DLL_IMPORT th_minTemp(int n, int k=-1);
|
||||||
|
double DLL_IMPORT th_maxTemp(int n, int k=-1);
|
||||||
|
double DLL_IMPORT th_enthalpy_mole(int n);
|
||||||
|
double DLL_IMPORT th_intEnergy_mole(int n);
|
||||||
|
double DLL_IMPORT th_entropy_mole(int n);
|
||||||
|
double DLL_IMPORT th_gibbs_mole(int n);
|
||||||
|
double DLL_IMPORT th_cp_mole(int n);
|
||||||
|
double DLL_IMPORT th_cv_mole(int n);
|
||||||
|
double DLL_IMPORT th_pressure(int n);
|
||||||
|
int DLL_IMPORT th_setPressure(int n, double p);
|
||||||
|
double DLL_IMPORT th_enthalpy_mass(int n);
|
||||||
|
double DLL_IMPORT th_intEnergy_mass(int n);
|
||||||
|
double DLL_IMPORT th_entropy_mass(int n);
|
||||||
|
double DLL_IMPORT th_gibbs_mass(int n);
|
||||||
|
double DLL_IMPORT th_cp_mass(int n);
|
||||||
|
double DLL_IMPORT th_cv_mass(int n);
|
||||||
|
int DLL_IMPORT th_chemPotentials(int n, int lenm, double* murt);
|
||||||
|
int DLL_IMPORT th_getEnthalpies_RT(int n, int lenm, double* h_rt);
|
||||||
|
int DLL_IMPORT th_getEntropies_R(int n, int lenm, double* s_r);
|
||||||
|
int DLL_IMPORT th_getCp_R(int n, int lenm, double* cp_r);
|
||||||
|
int DLL_IMPORT get_eos(char* fname, char* phase_id);
|
||||||
|
|
||||||
|
int DLL_IMPORT th_set_HP(int n, double* vals);
|
||||||
|
int DLL_IMPORT th_set_UV(int n, double* vals);
|
||||||
|
int DLL_IMPORT th_set_SV(int n, double* vals);
|
||||||
|
int DLL_IMPORT th_set_SP(int n, double* vals);
|
||||||
|
int DLL_IMPORT th_equil(int n, int XY);
|
||||||
|
|
||||||
|
int DLL_IMPORT newKineticsFromXML(int mxml, int iphase,
|
||||||
|
int neighbor1=-1, int neighbor2=-1);
|
||||||
|
int DLL_IMPORT installRxnArrays(int pxml, int ikin,
|
||||||
|
char* default_phase);
|
||||||
|
int DLL_IMPORT kin_nSpecies(int n);
|
||||||
|
int DLL_IMPORT kin_nReactions(int n);
|
||||||
|
double DLL_IMPORT kin_reactantStoichCoeff(int n, int i, int k);
|
||||||
|
double DLL_IMPORT kin_productStoichCoeff(int n, int i, int k);
|
||||||
|
int DLL_IMPORT kin_reactionType(int n, int i);
|
||||||
|
int DLL_IMPORT kin_getFwdRatesOfProgress(int n, int len, double* fwdROP);
|
||||||
|
int DLL_IMPORT kin_getRevRatesOfProgress(int n, int len, double* revROP);
|
||||||
|
int DLL_IMPORT kin_getNetRatesOfProgress(int n, int len, double* netROP);
|
||||||
|
int DLL_IMPORT kin_getEquilibriumConstants(int n, int len, double* kc);
|
||||||
|
int DLL_IMPORT kin_getCreationRates(int n, int len, double* cdot);
|
||||||
|
int DLL_IMPORT kin_getDestructionRates(int n, int len, double* ddot);
|
||||||
|
int DLL_IMPORT kin_getNetProductionRates(int n, int len, double* wdot);
|
||||||
|
int DLL_IMPORT kin_getSourceTerms(int n, int len, double* ydot);
|
||||||
|
double DLL_IMPORT kin_multiplier(int n, int i);
|
||||||
|
int DLL_IMPORT kin_getReactionString(int n, int i, int len, char* buf);
|
||||||
|
int DLL_IMPORT kin_setMultiplier(int n, int i, double v);
|
||||||
|
|
||||||
|
int DLL_IMPORT kin_isReversible(int n, int i);
|
||||||
|
int DLL_IMPORT kin_type(int n);
|
||||||
|
int DLL_IMPORT kin_start(int n, int p);
|
||||||
|
int DLL_IMPORT kin_speciesIndex(int n, const char* nm, const char* ph);
|
||||||
|
|
||||||
|
int DLL_IMPORT newTransport(char* model,
|
||||||
|
int th, int loglevel);
|
||||||
|
double DLL_IMPORT trans_viscosity(int n);
|
||||||
|
double DLL_IMPORT trans_thermalConductivity(int n);
|
||||||
|
int DLL_IMPORT trans_getThermalDiffCoeffs(int n, int ldt, double* dt);
|
||||||
|
int DLL_IMPORT trans_getMixDiffCoeffs(int n, int ld, double* d);
|
||||||
|
int DLL_IMPORT trans_getBinDiffCoeffs(int n, int ld, double* d);
|
||||||
|
int DLL_IMPORT trans_getMultiDiffCoeffs(int n, int ld, double* d);
|
||||||
|
|
||||||
|
int DLL_IMPORT import_phase(int nth, int nxml, char* id);
|
||||||
|
int DLL_IMPORT import_kinetics(int nxml, char* id,
|
||||||
|
int nphases, int* ith, int nkin);
|
||||||
|
int DLL_IMPORT import_from_file(int nth, int nkin, char* fname, char* db,
|
||||||
|
char* id, int validate, double threshold);
|
||||||
|
int DLL_IMPORT getCanteraError(int buflen, char* buf);
|
||||||
|
int DLL_IMPORT addCanteraDirectory(int buflen, char* buf);
|
||||||
|
int DLL_IMPORT clearStorage();
|
||||||
|
int DLL_IMPORT delPhase(int n);
|
||||||
|
int DLL_IMPORT delThermo(int n);
|
||||||
|
int DLL_IMPORT delKinetics(int n);
|
||||||
|
int DLL_IMPORT delTransport(int n);
|
||||||
|
int DLL_IMPORT readlog(int n, char* buf);
|
||||||
|
int DLL_IMPORT buildSolutionFromXML(char* src, int ixml, char* id,
|
||||||
|
int ith, int ikin);
|
||||||
|
|
||||||
|
int DLL_IMPORT ck_to_ctml(char* in_file, char* db_file,
|
||||||
|
char* tr_file, char* out_file, char* id_tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
92
Cantera/clib/src/ctbdry.cpp
Executable file
92
Cantera/clib/src/ctbdry.cpp
Executable file
@ -0,0 +1,92 @@
|
|||||||
|
|
||||||
|
// Build as a DLL under Windows
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DLL_EXPORT __declspec(dllexport)
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#pragma warning(disable:4503)
|
||||||
|
#else
|
||||||
|
#define DLL_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Cantera includes
|
||||||
|
#include "oneD/OneDim.h"
|
||||||
|
#include "oneD/Inlet1D.h"
|
||||||
|
|
||||||
|
#include "Cabinet.h"
|
||||||
|
#include "Storage.h"
|
||||||
|
|
||||||
|
// Values returned for error conditions
|
||||||
|
#define ERR -999
|
||||||
|
#define DERR -999.999
|
||||||
|
|
||||||
|
Cabinet<Bdry1D>* Cabinet<Bdry1D>::__storage = 0;
|
||||||
|
|
||||||
|
inline Bdry1D* _bndry(int i) {
|
||||||
|
return Cabinet<Bdry1D>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//inline Phase* _phase(int n) {
|
||||||
|
// return Storage::__storage->__phasetable[n];
|
||||||
|
//}
|
||||||
|
|
||||||
|
inline ThermoPhase* _thermo(int n) {
|
||||||
|
return Storage::__storage->__thtable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
int DLL_EXPORT bndry_new(int itype) {
|
||||||
|
Bdry1D* s;
|
||||||
|
switch (itype) {
|
||||||
|
case 1:
|
||||||
|
s = new Inlet1D(); break;
|
||||||
|
case 2:
|
||||||
|
s = new Symm1D(); break;
|
||||||
|
case 3:
|
||||||
|
s = new Surf1D(); break;
|
||||||
|
default:
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
int i = Cabinet<Bdry1D>::cabinet()->add(s);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bndry_del(int i) {
|
||||||
|
Cabinet<Bdry1D>::cabinet()->del(i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT bndry_temperature(int i) {
|
||||||
|
return _bndry(i)->temperature();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bndry_settemperature(int i, double t) {
|
||||||
|
_bndry(i)->setTemperature(t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bndry_setmdot(int i, double mdot) {
|
||||||
|
try {
|
||||||
|
_bndry(i)->setMdot(mdot);
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double DLL_EXPORT bndry_mdot(int i) {
|
||||||
|
return _bndry(i)->mdot();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bndry_setxin(int i, double* xin) {
|
||||||
|
_bndry(i)->setMoleFractions(xin);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bndry_setxinbyname(int i, char* xin) {
|
||||||
|
_bndry(i)->setMoleFractions(string(xin));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
17
Cantera/clib/src/ctbdry.h
Executable file
17
Cantera/clib/src/ctbdry.h
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef CTC_BDRY_H
|
||||||
|
#define CTC_BDRY_H
|
||||||
|
|
||||||
|
#include "clib_defs.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
int DLL_IMPORT bndry_new(int itype);
|
||||||
|
int DLL_IMPORT bndry_del(int i);
|
||||||
|
double DLL_IMPORT bndry_temperature(int i);
|
||||||
|
int DLL_IMPORT bndry_settemperature(int i, double t);
|
||||||
|
int DLL_IMPORT bndry_setmdot(int i, double mdot);
|
||||||
|
double DLL_IMPORT bndry_mdot(int i);
|
||||||
|
int DLL_IMPORT bndry_setxin(int i, double* xin);
|
||||||
|
int DLL_IMPORT bndry_setxinbyname(int i, char* xin);
|
||||||
|
}
|
||||||
|
#endif
|
90
Cantera/clib/src/ctfunc.cpp
Executable file
90
Cantera/clib/src/ctfunc.cpp
Executable file
@ -0,0 +1,90 @@
|
|||||||
|
|
||||||
|
#include "Func1.h"
|
||||||
|
#include "ctexceptions.h"
|
||||||
|
using namespace Cantera;
|
||||||
|
|
||||||
|
#include "Cabinet.h"
|
||||||
|
|
||||||
|
// Build as a DLL under Windows
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DLL_EXPORT __declspec(dllexport)
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#pragma warning(disable:4503)
|
||||||
|
#else
|
||||||
|
#define DLL_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Values returned for error conditions
|
||||||
|
#define ERR -999
|
||||||
|
#define DERR -999.999
|
||||||
|
|
||||||
|
typedef Func1 func_t;
|
||||||
|
|
||||||
|
Cabinet<func_t>* Cabinet<func_t>::__storage = 0;
|
||||||
|
|
||||||
|
inline func_t* _func(int i) {
|
||||||
|
return Cabinet<func_t>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
// functions
|
||||||
|
|
||||||
|
int DLL_EXPORT func_new(int type, int n, int lenp, double* params) {
|
||||||
|
func_t* r=0;
|
||||||
|
int m = lenp;
|
||||||
|
try {
|
||||||
|
if (type == FourierFuncType) {
|
||||||
|
if (lenp < 2*n + 2)
|
||||||
|
throw CanteraError("func_new",
|
||||||
|
"not enough Fourier coefficients");
|
||||||
|
r = new Fourier1(n, params[n+1], params[0], params + 1,
|
||||||
|
params + n + 2);
|
||||||
|
}
|
||||||
|
else if (type == PolyFuncType) {
|
||||||
|
if (lenp < n + 1)
|
||||||
|
throw CanteraError("func_new",
|
||||||
|
"not enough polynomial coefficients");
|
||||||
|
r = new Poly1(n, params);
|
||||||
|
}
|
||||||
|
else if (type == ArrheniusFuncType) {
|
||||||
|
if (lenp < 3*n)
|
||||||
|
throw CanteraError("func_new",
|
||||||
|
"not enough Arrhenius coefficients");
|
||||||
|
r = new Arrhenius1(n, params);
|
||||||
|
}
|
||||||
|
else if (type == SumFuncType) {
|
||||||
|
r = new Func1Sum(*_func(n), *_func(m));
|
||||||
|
}
|
||||||
|
else if (type == ProdFuncType) {
|
||||||
|
r = new Func1Product(*_func(n), *_func(m));
|
||||||
|
}
|
||||||
|
else if (type == RatioFuncType) {
|
||||||
|
r = new Func1Ratio(*_func(n), *_func(m));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
r = new Func1();
|
||||||
|
return Cabinet<func_t>::cabinet()->add(r);
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int DLL_EXPORT func_del(int i) {
|
||||||
|
Cabinet<func_t>::cabinet()->del(i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT func_copy(int i) {
|
||||||
|
return Cabinet<func_t>::cabinet()->newCopy(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT func_assign(int i, int j) {
|
||||||
|
return Cabinet<func_t>::cabinet()->assign(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT func_value(int i, double t) {
|
||||||
|
return _func(i)->eval(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
Cantera/clib/src/ctfunc.h
Executable file
14
Cantera/clib/src/ctfunc.h
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef CTC_FUNC1_H
|
||||||
|
#define CTC_FUNC1_H
|
||||||
|
|
||||||
|
#include "clib_defs.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
int DLL_IMPORT func_new(int type, int n, int lenp, double* p);
|
||||||
|
int DLL_IMPORT func_del(int i);
|
||||||
|
int DLL_IMPORT func_copy(int i);
|
||||||
|
int DLL_IMPORT func_assign(int i, int j);
|
||||||
|
double DLL_IMPORT func_value(int i, double t);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
179
Cantera/clib/src/ctnum.cpp
Executable file
179
Cantera/clib/src/ctnum.cpp
Executable file
@ -0,0 +1,179 @@
|
|||||||
|
|
||||||
|
// Cantera includes
|
||||||
|
#include "numerics.h"
|
||||||
|
#include "Cabinet.h"
|
||||||
|
inline DenseMatrix* _matrix(int i) {
|
||||||
|
return Cabinet<DenseMatrix>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline BandMatrix* _bmatrix(int i) {
|
||||||
|
return Cabinet<BandMatrix>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build as a DLL under Windows
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DLL_EXPORT __declspec(dllexport)
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#pragma warning(disable:4503)
|
||||||
|
#else
|
||||||
|
#define DLL_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Values returned for error conditions
|
||||||
|
#define ERR -999
|
||||||
|
#define DERR -999.999
|
||||||
|
|
||||||
|
Cabinet<DenseMatrix>* Cabinet<DenseMatrix>::__storage = 0;
|
||||||
|
Cabinet<BandMatrix>* Cabinet<BandMatrix>::__storage = 0;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
|
||||||
|
///// Matrix //////
|
||||||
|
|
||||||
|
int DLL_EXPORT newMatrix(int m, int n) {
|
||||||
|
DenseMatrix* x = new DenseMatrix(m,n);
|
||||||
|
return Cabinet<DenseMatrix>::cabinet()->add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT delMatrix(int i) {
|
||||||
|
Cabinet<DenseMatrix>::cabinet()->del(i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT matrix_copy(int i) {
|
||||||
|
return Cabinet<DenseMatrix>::cabinet()->newCopy(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT matrix_assign(int i, int j) {
|
||||||
|
return Cabinet<DenseMatrix>::cabinet()->assign(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT matrix_nRows(int i) {
|
||||||
|
return _matrix(i)->nRows();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT matrix_nColumns(int i) {
|
||||||
|
return _matrix(i)->nColumns();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT matrix_resize(int i, int m, int n, double v) {
|
||||||
|
_matrix(i)->resize(m,n,v);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT matrix_appendColumn(int i, double* c) {
|
||||||
|
_matrix(i)->appendColumn(c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT matrix_value(int i, int m, int n) {
|
||||||
|
return _matrix(i)->value(m,n);
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT matrix_setvalue(int i, int m, int n, double v) {
|
||||||
|
_matrix(i)->value(m,n) = v;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT matrix_solve(int i1, int i2) {
|
||||||
|
try {
|
||||||
|
int info = solve(*_matrix(i1), *_matrix(i2));
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
catch (...) { return ERR; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT matrix_multiply(int ma, int mb, int mp) {
|
||||||
|
try {
|
||||||
|
DenseMatrix* a = _matrix(ma);
|
||||||
|
DenseMatrix* b = _matrix(mb);
|
||||||
|
DenseMatrix* p = _matrix(mp);
|
||||||
|
multiply(*a, b->begin(), p->begin());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
catch (...) { return ERR; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT matrix_invert(int ma) {
|
||||||
|
try {
|
||||||
|
invert(*_matrix(ma));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
catch (...) { return ERR; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////// BandMatrix //////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
int DLL_EXPORT bmatrix_new(int n, int kl, int ku) {
|
||||||
|
BandMatrix* x = new BandMatrix(n, kl, ku);
|
||||||
|
return Cabinet<BandMatrix>::cabinet()->add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bmatrix_del(int i) {
|
||||||
|
Cabinet<BandMatrix>::cabinet()->del(i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bmatrix_copy(int i) {
|
||||||
|
return Cabinet<BandMatrix>::cabinet()->newCopy(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bmatrix_assign(int i, int j) {
|
||||||
|
return Cabinet<BandMatrix>::cabinet()->assign(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bmatrix_nRows(int i) {
|
||||||
|
return _bmatrix(i)->rows();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bmatrix_nColumns(int i) {
|
||||||
|
return _bmatrix(i)->columns();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bmatrix_resize(int i, int m, int n, double v) {
|
||||||
|
_bmatrix(i)->resize(m,n,v);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT bmatrix_value(int i, int m, int n) {
|
||||||
|
return _bmatrix(i)->value(m,n);
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT bmatrix_setvalue(int i, int m, int n, double v) {
|
||||||
|
try {
|
||||||
|
_bmatrix(i)->value(m,n) = v;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
catch (...) { return ERR; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bmatrix_solve(int ma, int mb) {
|
||||||
|
try {
|
||||||
|
int n = _bmatrix(ma)->nColumns();
|
||||||
|
_bmatrix(ma)->solve(n,
|
||||||
|
_matrix(mb)->begin());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
catch (...) { return ERR; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bmatrix_multiply(int ma, int mb, int mp) {
|
||||||
|
try {
|
||||||
|
BandMatrix* a = _bmatrix(ma);
|
||||||
|
DenseMatrix* b = _matrix(mb);
|
||||||
|
DenseMatrix* p = _matrix(mp);
|
||||||
|
a->mult(b->begin(), p->begin());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
catch (...) { return ERR; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
Cantera/clib/src/ctnum.h
Executable file
37
Cantera/clib/src/ctnum.h
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef CTC_CTNUM_H
|
||||||
|
#define CTC_CTNUM_H
|
||||||
|
|
||||||
|
#include "clib_defs.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
int DLL_IMPORT newMatrix(int m, int n);
|
||||||
|
int DLL_IMPORT delMatrix(int i);
|
||||||
|
int DLL_IMPORT matrix_copy(int i);
|
||||||
|
int DLL_IMPORT matrix_assign(int i, int j);
|
||||||
|
int DLL_IMPORT matrix_nRows(int i);
|
||||||
|
int DLL_IMPORT matrix_nColumns(int i);
|
||||||
|
int DLL_IMPORT matrix_resize(int i, int m, int n, double v);
|
||||||
|
int DLL_IMPORT matrix_appendColumn(int i, double* c);
|
||||||
|
double DLL_IMPORT matrix_value(int i, int m, int n);
|
||||||
|
double DLL_IMPORT matrix_setvalue(int i, int m, int n, double v);
|
||||||
|
int DLL_IMPORT matrix_solve(int i1, int i2);
|
||||||
|
int DLL_IMPORT matrix_multiply(int ma, int mb, int mp);
|
||||||
|
int DLL_IMPORT matrix_invert(int ma);
|
||||||
|
|
||||||
|
int DLL_IMPORT bmatrix_new(int n, int kl, int ku);
|
||||||
|
int DLL_IMPORT bmatrix_del(int i);
|
||||||
|
int DLL_IMPORT bmatrix_copy(int i);
|
||||||
|
int DLL_IMPORT bmatrix_assign(int i, int j);
|
||||||
|
int DLL_IMPORT bmatrix_nRows(int i);
|
||||||
|
int DLL_IMPORT bmatrix_nColumns(int i);
|
||||||
|
int DLL_IMPORT bmatrix_resize(int i, int m, int n, double v);
|
||||||
|
double DLL_IMPORT bmatrix_value(int i, int m, int n);
|
||||||
|
double DLL_IMPORT bmatrix_setvalue(int i, int m, int n, double v);
|
||||||
|
int DLL_IMPORT bmatrix_solve(int ma, int mb);
|
||||||
|
int DLL_IMPORT bmatrix_multiply(int ma, int mb, int mp);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
367
Cantera/clib/src/ctreactor.cpp
Executable file
367
Cantera/clib/src/ctreactor.cpp
Executable file
@ -0,0 +1,367 @@
|
|||||||
|
|
||||||
|
// Cantera includes
|
||||||
|
#include "zeroD/Reactor.h"
|
||||||
|
#include "zeroD/Reservoir.h"
|
||||||
|
#include "zeroD/Wall.h"
|
||||||
|
#include "zeroD/flowControllers.h"
|
||||||
|
|
||||||
|
#include "Cabinet.h"
|
||||||
|
#include "Storage.h"
|
||||||
|
|
||||||
|
// Build as a DLL under Windows
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DLL_EXPORT __declspec(dllexport)
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#pragma warning(disable:4503)
|
||||||
|
#else
|
||||||
|
#define DLL_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Values returned for error conditions
|
||||||
|
#define ERR -999
|
||||||
|
#define DERR -999.999
|
||||||
|
|
||||||
|
typedef ReactorBase reactor_t;
|
||||||
|
typedef FlowDevice flowdev_t;
|
||||||
|
typedef Wall wall_t;
|
||||||
|
|
||||||
|
Cabinet<reactor_t>* Cabinet<reactor_t>::__storage = 0;
|
||||||
|
Cabinet<flowdev_t>* Cabinet<flowdev_t>::__storage = 0;
|
||||||
|
Cabinet<wall_t>* Cabinet<wall_t>::__storage = 0;
|
||||||
|
|
||||||
|
inline reactor_t* _reactor(int i) {
|
||||||
|
return Cabinet<reactor_t>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline flowdev_t* _flowdev(int i) {
|
||||||
|
return Cabinet<flowdev_t>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline wall_t* _wall(int i) {
|
||||||
|
return Cabinet<wall_t>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Kinetics* _kin(int n) {
|
||||||
|
return Storage::__storage->__ktable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ThermoPhase* _th(int n) {
|
||||||
|
return Storage::__storage->__thtable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Func1* _func(int i) {
|
||||||
|
return Cabinet<Func1>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
|
||||||
|
// reactor
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_new(int type) {
|
||||||
|
reactor_t* r=0;
|
||||||
|
if (type == ReactorType)
|
||||||
|
r = new Reactor();
|
||||||
|
else if (type == ReservoirType)
|
||||||
|
r = new Reservoir();
|
||||||
|
else
|
||||||
|
r = new ReactorBase();
|
||||||
|
return Cabinet<reactor_t>::cabinet()->add(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_del(int i) {
|
||||||
|
Cabinet<reactor_t>::cabinet()->del(i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_copy(int i) {
|
||||||
|
return Cabinet<reactor_t>::cabinet()->newCopy(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_assign(int i, int j) {
|
||||||
|
return Cabinet<reactor_t>::cabinet()->assign(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_setInitialVolume(int i, double v) {
|
||||||
|
_reactor(i)->setInitialVolume(v);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_setInitialTime(int i, double t) {
|
||||||
|
_reactor(i)->setInitialTime(t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_setThermoMgr(int i, int n) {
|
||||||
|
_reactor(i)->setThermoMgr(*_th(n));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_setKineticsMgr(int i, int n) {
|
||||||
|
reactor_t* r = _reactor(i);
|
||||||
|
if (r->type() == ReactorType)
|
||||||
|
((Reactor*)r)->setKineticsMgr(*_kin(n));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_advance(int i, double t) {
|
||||||
|
try {
|
||||||
|
_reactor(i)->advance(t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) {return -1;}
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT reactor_step(int i, double t) {
|
||||||
|
return _reactor(i)->step(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT reactor_time(int i) {
|
||||||
|
return _reactor(i)->time();
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT reactor_mass(int i) {
|
||||||
|
return _reactor(i)->mass();
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT reactor_volume(int i) {
|
||||||
|
return _reactor(i)->volume();
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT reactor_density(int i) {
|
||||||
|
return _reactor(i)->density();
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT reactor_temperature(int i) {
|
||||||
|
return _reactor(i)->temperature();
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT reactor_enthalpy_mass(int i) {
|
||||||
|
return _reactor(i)->enthalpy_mass();
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT reactor_intEnergy_mass(int i) {
|
||||||
|
return _reactor(i)->intEnergy_mass();
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT reactor_pressure(int i) {
|
||||||
|
return _reactor(i)->pressure();
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT reactor_massFraction(int i, int k) {
|
||||||
|
return _reactor(i)->massFraction(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_setEnergy(int i, int eflag) {
|
||||||
|
reactor_t* r = _reactor(i);
|
||||||
|
if (r->type() == ReactorType) ((Reactor*)r)->setEnergy(eflag);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_setArea(int i, double a) {
|
||||||
|
reactor_t* r = _reactor(i);
|
||||||
|
if (r->type() == ReactorType) ((Reactor*)r)->setArea(a);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_setExtTemp(int i, double t) {
|
||||||
|
reactor_t* r = _reactor(i);
|
||||||
|
if (r->type() == ReactorType) ((Reactor*)r)->setExtTemp(t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_setExtRadTemp(int i, double t) {
|
||||||
|
reactor_t* r = _reactor(i);
|
||||||
|
if (r->type() == ReactorType) ((Reactor*)r)->setExtRadTemp(t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_setVDotCoeff(int i, double v) {
|
||||||
|
reactor_t* r = _reactor(i);
|
||||||
|
if (r->type() == ReactorType) ((Reactor*)r)->setVDotCoeff(v);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_setHeatTransferCoeff(int i, double h) {
|
||||||
|
reactor_t* r = _reactor(i);
|
||||||
|
if (r->type() == ReactorType) ((Reactor*)r)->setHeatTransferCoeff(h);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_setEmissivity(int i, double eps) {
|
||||||
|
reactor_t* r = _reactor(i);
|
||||||
|
if (r->type() == ReactorType) ((Reactor*)r)->setEmissivity(eps);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT reactor_setExtPressure(int i, double p) {
|
||||||
|
reactor_t* r = _reactor(i);
|
||||||
|
if (r->type() == ReactorType) ((Reactor*)r)->setExtPressure(p);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// flow devices
|
||||||
|
|
||||||
|
int DLL_EXPORT flowdev_new(int type) {
|
||||||
|
flowdev_t* r;
|
||||||
|
switch (type) {
|
||||||
|
case MFC_Type:
|
||||||
|
r = new MassFlowController(); break;
|
||||||
|
case PressureReg_Type:
|
||||||
|
r = new PressureRegulator(); break;
|
||||||
|
case Valve_Type:
|
||||||
|
r = new Valve(); break;
|
||||||
|
default:
|
||||||
|
r = new FlowDevice();
|
||||||
|
}
|
||||||
|
return Cabinet<flowdev_t>::cabinet()->add(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flowdev_del(int i) {
|
||||||
|
Cabinet<flowdev_t>::cabinet()->del(i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flowdev_copy(int i) {
|
||||||
|
return Cabinet<flowdev_t>::cabinet()->newCopy(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flowdev_assign(int i, int j) {
|
||||||
|
return Cabinet<flowdev_t>::cabinet()->assign(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flowdev_install(int i, int n, int m) {
|
||||||
|
_flowdev(i)->install(*_reactor(n), *_reactor(m) );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT flowdev_massFlowRate(int i) {
|
||||||
|
return _flowdev(i)->massFlowRate();
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT flowdev_setpoint(int i) {
|
||||||
|
return _flowdev(i)->setpoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flowdev_setSetpoint(int i, double v) {
|
||||||
|
_flowdev(i)->setSetpoint(v);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flowdev_setGains(int i, int n, double* gains) {
|
||||||
|
_flowdev(i)->setGains(n, gains);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flowdev_getGains(int i, int n, double* gains) {
|
||||||
|
_flowdev(i)->getGains(n, gains);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flowdev_setParameters(int i, int n, double* v) {
|
||||||
|
_flowdev(i)->setParameters(n, v);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flowdev_setFunction(int i, int n) {
|
||||||
|
_flowdev(i)->setFunction(_func(n));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flowdev_reset(int i) {
|
||||||
|
_flowdev(i)->reset();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flowdev_update(int i) {
|
||||||
|
_flowdev(i)->update();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT flowdev_maxError(int i) {
|
||||||
|
return _flowdev(i)->maxError();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flowdev_ready(int i) {
|
||||||
|
bool ok = _flowdev(i)->ready();
|
||||||
|
if (ok) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////// Walls ///////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
int DLL_EXPORT wall_new(int type) {
|
||||||
|
wall_t* r;
|
||||||
|
r = new Wall();
|
||||||
|
return Cabinet<wall_t>::cabinet()->add(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT wall_del(int i) {
|
||||||
|
Cabinet<wall_t>::cabinet()->del(i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT wall_copy(int i) {
|
||||||
|
return Cabinet<wall_t>::cabinet()->newCopy(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT wall_assign(int i, int j) {
|
||||||
|
return Cabinet<wall_t>::cabinet()->assign(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT wall_install(int i, int n, int m) {
|
||||||
|
_wall(i)->install(*_reactor(n), *_reactor(m) );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT wall_vdot(int i, double t) {
|
||||||
|
return _wall(i)->vdot(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT wall_Q(int i, double t) {
|
||||||
|
return _wall(i)->Q(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT wall_area(int i) {
|
||||||
|
return _wall(i)->area();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT wall_setArea(int i, double v) {
|
||||||
|
_wall(i)->setArea(v);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT wall_setThermalResistance(int i, double rth) {
|
||||||
|
_wall(i)->setThermalResistance(rth);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT wall_setHeatTransferCoeff(int i, double u) {
|
||||||
|
_wall(i)->setHeatTransferCoeff(u);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT wall_setHeatFlux(int i, int n) {
|
||||||
|
_wall(i)->setHeatFlux(_func(n));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT wall_setExpansionRateCoeff(int i, double k) {
|
||||||
|
_wall(i)->setExpansionRateCoeff(k);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT wall_setExpansionRate(int i, int n) {
|
||||||
|
_wall(i)->setExpansionRate(_func(n));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT wall_ready(int i) {
|
||||||
|
if (_wall(i)->ready()) return 1;
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
73
Cantera/clib/src/ctreactor.h
Executable file
73
Cantera/clib/src/ctreactor.h
Executable file
@ -0,0 +1,73 @@
|
|||||||
|
#ifndef CTC_REACTOR_H
|
||||||
|
#define CTC_REACTOR_H
|
||||||
|
|
||||||
|
#include "clib_defs.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
int DLL_IMPORT reactor_new(int type);
|
||||||
|
int DLL_IMPORT reactor_del(int i);
|
||||||
|
int DLL_IMPORT reactor_copy(int i);
|
||||||
|
int DLL_IMPORT reactor_assign(int i, int j);
|
||||||
|
int DLL_IMPORT reactor_setInitialVolume(int i, double v);
|
||||||
|
int DLL_IMPORT reactor_setInitialTime(int i, double t);
|
||||||
|
int DLL_IMPORT reactor_setEnergy(int i, int eflag);
|
||||||
|
int DLL_IMPORT reactor_setThermoMgr(int i, int n);
|
||||||
|
int DLL_IMPORT reactor_setKineticsMgr(int i, int n);
|
||||||
|
int DLL_IMPORT reactor_advance(int i, double t);
|
||||||
|
double DLL_IMPORT reactor_step(int i, double t);
|
||||||
|
double DLL_IMPORT reactor_time(int i);
|
||||||
|
double DLL_IMPORT reactor_mass(int i);
|
||||||
|
double DLL_IMPORT reactor_volume(int i);
|
||||||
|
double DLL_IMPORT reactor_density(int i);
|
||||||
|
double DLL_IMPORT reactor_temperature(int i);
|
||||||
|
double DLL_IMPORT reactor_enthalpy_mass(int i);
|
||||||
|
double DLL_IMPORT reactor_intEnergy_mass(int i);
|
||||||
|
double DLL_IMPORT reactor_pressure(int i);
|
||||||
|
double DLL_IMPORT reactor_massFraction(int i, int k);
|
||||||
|
|
||||||
|
//int DLL_IMPORT reactor_setArea(int i, double a);
|
||||||
|
//int DLL_IMPORT reactor_setExtTemp(int i, double t);
|
||||||
|
//int DLL_IMPORT reactor_setExtRadTemp(int i, double t);
|
||||||
|
//int DLL_IMPORT reactor_setVDotCoeff(int i, double v);
|
||||||
|
//int DLL_IMPORT reactor_setHeatTransferCoeff(int i, double h);
|
||||||
|
//int DLL_IMPORT reactor_setEmissivity(int i, double eps);
|
||||||
|
//int DLL_IMPORT reactor_setExtPressure(int i, double p);
|
||||||
|
//int DLL_IMPORT reactor_setEnergy(int i, int eflag);
|
||||||
|
|
||||||
|
int DLL_IMPORT flowdev_new(int type);
|
||||||
|
int DLL_IMPORT flowdev_del(int i);
|
||||||
|
//int DLL_IMPORT flowdev_copy(int i);
|
||||||
|
//int DLL_IMPORT flowdev_assign(int i, int j);
|
||||||
|
int DLL_IMPORT flowdev_install(int i, int n, int m);
|
||||||
|
double DLL_IMPORT flowdev_massFlowRate(int i);
|
||||||
|
double DLL_IMPORT flowdev_setpoint(int i);
|
||||||
|
int DLL_IMPORT flowdev_setSetpoint(int i, double v);
|
||||||
|
//int DLL_IMPORT flowdev_setGains(int i, int n, double* gains);
|
||||||
|
//int DLL_IMPORT flowdev_getGains(int i, int n, double* gains);
|
||||||
|
int DLL_IMPORT flowdev_setParameters(int i, int n, double* v);
|
||||||
|
int DLL_IMPORT flowdev_setFunction(int i, int n);
|
||||||
|
//int DLL_IMPORT flowdev_reset(int i);
|
||||||
|
//int DLL_IMPORT flowdev_update(int i);
|
||||||
|
//double DLL_IMPORT flowdev_maxError(int i);
|
||||||
|
int DLL_IMPORT flowdev_ready(int i);
|
||||||
|
|
||||||
|
int DLL_IMPORT wall_new(int type);
|
||||||
|
int DLL_IMPORT wall_del(int i);
|
||||||
|
int DLL_IMPORT wall_copy(int i);
|
||||||
|
int DLL_IMPORT wall_assign(int i, int j);
|
||||||
|
int DLL_IMPORT wall_install(int i, int n, int m);
|
||||||
|
double DLL_IMPORT wall_vdot(int i, double t);
|
||||||
|
double DLL_IMPORT wall_Q(int i, double t);
|
||||||
|
double DLL_IMPORT wall_area(int i);
|
||||||
|
int DLL_IMPORT wall_setArea(int i, double v);
|
||||||
|
int DLL_IMPORT wall_setThermalResistance(int i, double rth);
|
||||||
|
int DLL_IMPORT wall_setHeatTransferCoeff(int i, double u);
|
||||||
|
int DLL_IMPORT wall_setHeatFlux(int i, int n);
|
||||||
|
int DLL_IMPORT wall_setExpansionRateCoeff(int i, double k);
|
||||||
|
int DLL_IMPORT wall_setExpansionRate(int i, int n);
|
||||||
|
int DLL_IMPORT wall_ready(int i);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
189
Cantera/clib/src/ctrpath.cpp
Executable file
189
Cantera/clib/src/ctrpath.cpp
Executable file
@ -0,0 +1,189 @@
|
|||||||
|
|
||||||
|
// Build as a DLL under Windows
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DLL_EXPORT __declspec(dllexport)
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#pragma warning(disable:4503)
|
||||||
|
#else
|
||||||
|
#define DLL_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Cantera includes
|
||||||
|
#include "ReactionPath.h"
|
||||||
|
|
||||||
|
#include "Cabinet.h"
|
||||||
|
#include "Storage.h"
|
||||||
|
|
||||||
|
// Values returned for error conditions
|
||||||
|
#define ERR -999
|
||||||
|
#define DERR -999.999
|
||||||
|
|
||||||
|
typedef ReactionPathDiagram diag_t;
|
||||||
|
typedef ReactionPathBuilder builder_t;
|
||||||
|
|
||||||
|
Cabinet<ReactionPathDiagram>* Cabinet<ReactionPathDiagram>::__storage = 0;
|
||||||
|
Cabinet<builder_t>* Cabinet<builder_t>::__storage = 0;
|
||||||
|
|
||||||
|
inline ReactionPathDiagram* _diag(int i) {
|
||||||
|
return Cabinet<ReactionPathDiagram>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline builder_t* _builder(int i) {
|
||||||
|
return Cabinet<builder_t>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Kinetics* _kin(int n) {
|
||||||
|
return Storage::__storage->__ktable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_new() {
|
||||||
|
diag_t* d = new ReactionPathDiagram();
|
||||||
|
return Cabinet<diag_t>::cabinet()->add(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_del(int i) {
|
||||||
|
Cabinet<diag_t>::cabinet()->del(i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_copy(int i) {
|
||||||
|
return Cabinet<diag_t>::cabinet()->newCopy(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_assign(int i, int j) {
|
||||||
|
return Cabinet<diag_t>::cabinet()->assign(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_detailed(int i) {
|
||||||
|
_diag(i)->show_details = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_brief(int i) {
|
||||||
|
_diag(i)->show_details = false;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_setThreshold(int i, double v) {
|
||||||
|
_diag(i)->threshold = v;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_setBoldColor(int i, char* color) {
|
||||||
|
_diag(i)->bold_color = string(color);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_setNormalColor(int i, char* color) {
|
||||||
|
_diag(i)->normal_color = string(color);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_setDashedColor(int i, char* color) {
|
||||||
|
_diag(i)->dashed_color = string(color);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_setDotOptions(int i, char* opt) {
|
||||||
|
_diag(i)->dot_options = string(opt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_setFont(int i, char* font) {
|
||||||
|
_diag(i)->setFont(string(font));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_setBoldThreshold(int i, double v) {
|
||||||
|
_diag(i)->bold_min = v;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_setNormalThreshold(int i, double v) {
|
||||||
|
_diag(i)->dashed_max = v;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_setLabelThreshold(int i, double v) {
|
||||||
|
_diag(i)->label_min = v;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_setScale(int i, double v) {
|
||||||
|
_diag(i)->scale = v;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_setFlowType(int i, int iflow) {
|
||||||
|
if (iflow == 0)
|
||||||
|
_diag(i)->flow_type = OneWayFlow;
|
||||||
|
else
|
||||||
|
_diag(i)->flow_type = NetFlow;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_setArrowWidth(int i, double v) {
|
||||||
|
_diag(i)->arrow_width = v;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_setTitle(int i, char* title) {
|
||||||
|
_diag(i)->title = string(title);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_add(int i, int n) {
|
||||||
|
_diag(i)->add(*_diag(n));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_findMajor(int i, double threshold,
|
||||||
|
int lda, double* a) {
|
||||||
|
_diag(i)->findMajorPaths(threshold, lda, a);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_write(int i, int fmt, char* fname) {
|
||||||
|
ofstream f(fname);
|
||||||
|
if (fmt == 0)
|
||||||
|
_diag(i)->exportToDot(f);
|
||||||
|
else
|
||||||
|
_diag(i)->writeData(f);
|
||||||
|
f.close();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rdiag_displayOnly(int i, int k) {
|
||||||
|
_diag(i)->displayOnly(k);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rbuild_new() {
|
||||||
|
builder_t* d = new ReactionPathBuilder();
|
||||||
|
return Cabinet<builder_t>::cabinet()->add(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rbuild_del(int i) {
|
||||||
|
Cabinet<builder_t>::cabinet()->del(i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rbuild_init(int i, char* logfile, int k) {
|
||||||
|
ofstream flog(logfile);
|
||||||
|
_builder(i)->init(flog, *_kin(k));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT rbuild_build(int i, int k, char* el, char* dotfile,
|
||||||
|
int idiag, int iquiet) {
|
||||||
|
ofstream fdot(dotfile);
|
||||||
|
bool quiet = false;
|
||||||
|
if (iquiet > 0) quiet = true;
|
||||||
|
_builder(i)->build(*_kin(k), string(el), fdot, *_diag(idiag), quiet);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
Cantera/clib/src/ctrpath.h
Executable file
37
Cantera/clib/src/ctrpath.h
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef CTC_RXNPATH_H
|
||||||
|
#define CTC_RXNPATH_H
|
||||||
|
|
||||||
|
#include "clib_defs.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
int DLL_IMPORT rdiag_new();
|
||||||
|
int DLL_IMPORT rdiag_del(int i);
|
||||||
|
int DLL_IMPORT rdiag_detailed(int i);
|
||||||
|
int DLL_IMPORT rdiag_brief(int i);
|
||||||
|
int DLL_IMPORT rdiag_setThreshold(int i, double v);
|
||||||
|
int DLL_IMPORT rdiag_setBoldColor(int i, char* color);
|
||||||
|
int DLL_IMPORT rdiag_setNormalColor(int i, char* color);
|
||||||
|
int DLL_IMPORT rdiag_setDashedColor(int i, char* color);
|
||||||
|
int DLL_IMPORT rdiag_setDotOptions(int i, char* opt);
|
||||||
|
int DLL_IMPORT rdiag_setBoldThreshold(int i, double v);
|
||||||
|
int DLL_IMPORT rdiag_setNormalThreshold(int i, double v);
|
||||||
|
int DLL_IMPORT rdiag_setLabelThreshold(int i, double v);
|
||||||
|
int DLL_IMPORT rdiag_setScale(int i, double v);
|
||||||
|
int DLL_IMPORT rdiag_setFlowType(int i, int iflow);
|
||||||
|
int DLL_IMPORT rdiag_setArrowWidth(int i, double v);
|
||||||
|
int DLL_IMPORT rdiag_setTitle(int i, char* title);
|
||||||
|
int DLL_IMPORT rdiag_write(int i, int fmt, char* fname);
|
||||||
|
int DLL_IMPORT rdiag_add(int i, int n);
|
||||||
|
int DLL_IMPORT rdiag_findMajor(int i, double threshold, int lda, double* a);
|
||||||
|
int DLL_IMPORT rdiag_setFont(int i, char* font);
|
||||||
|
int DLL_IMPORT rdiag_displayOnly(int i, int k);
|
||||||
|
|
||||||
|
int DLL_IMPORT rbuild_new();
|
||||||
|
int DLL_IMPORT rbuild_del(int i);
|
||||||
|
int DLL_IMPORT rbuild_init(int i, char* logfile, int k);
|
||||||
|
int DLL_IMPORT rbuild_build(int i, int k, char* el, char* dotfile,
|
||||||
|
int idiag, int iquiet);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
452
Cantera/clib/src/ctstagn.cpp
Executable file
452
Cantera/clib/src/ctstagn.cpp
Executable file
@ -0,0 +1,452 @@
|
|||||||
|
|
||||||
|
// Cantera includes
|
||||||
|
#include "oneD/OneDim.h"
|
||||||
|
#include "oneD/StFlow.h"
|
||||||
|
#include "oneD/Inlet1D.h"
|
||||||
|
#include "oneD/MultiNewton.h"
|
||||||
|
#include "DenseMatrix.h"
|
||||||
|
#include "Cabinet.h"
|
||||||
|
#include "Storage.h"
|
||||||
|
|
||||||
|
// Build as a DLL under Windows
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DLL_EXPORT __declspec(dllexport)
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#pragma warning(disable:4503)
|
||||||
|
#else
|
||||||
|
#define DLL_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Values returned for error conditions
|
||||||
|
#define ERR -999
|
||||||
|
#define DERR -999.999
|
||||||
|
|
||||||
|
using namespace FlowBdry;
|
||||||
|
|
||||||
|
Cabinet<OneDim>* Cabinet<OneDim>::__storage = 0;
|
||||||
|
Cabinet<StFlow>* Cabinet<StFlow>::__storage = 0;
|
||||||
|
Cabinet<Boundary>* Cabinet<Boundary>::__storage = 0;
|
||||||
|
//Cabinet<Surf1D>* Cabinet<Surf1D>::__storage = 0;
|
||||||
|
|
||||||
|
inline OneDim* _onedim(int i) {
|
||||||
|
return Cabinet<OneDim>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline StFlow* _flow(int i) {
|
||||||
|
return Cabinet<StFlow>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Boundary* _boundary(int i) {
|
||||||
|
return Cabinet<Boundary>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Bdry1D* _bndry(int i) {
|
||||||
|
return Cabinet<Bdry1D>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//inline SurfKinetics* _surfkin(int i) {
|
||||||
|
// return Cabinet<SurfKinetics>::cabinet()->item(i);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//inline Surf1D* _surface(int i) {
|
||||||
|
// return Cabinet<Surf1D>::cabinet()->item(i);
|
||||||
|
//}
|
||||||
|
|
||||||
|
inline DenseMatrix* _matrix(int i) {
|
||||||
|
return Cabinet<DenseMatrix>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ThermoPhase* _phase(int n) {
|
||||||
|
return Storage::__storage->__thtable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Kinetics* _kinetics(int n) {
|
||||||
|
return Storage::__storage->__ktable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ThermoPhase* _thermo(int n) {
|
||||||
|
return Storage::__storage->__thtable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Transport* _transport(int n) {
|
||||||
|
return Storage::__storage->__trtable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_new(int type, int iph, int np) {
|
||||||
|
IdealGasPhase* ph = (IdealGasPhase*)_thermo(iph);
|
||||||
|
StFlow* x;
|
||||||
|
try {
|
||||||
|
switch (type) {
|
||||||
|
case 0:
|
||||||
|
x = new AxiStagnFlow(ph, ph->nSpecies(), np); break;
|
||||||
|
case 1:
|
||||||
|
x = new OneDFlow(ph, ph->nSpecies(), np); break;
|
||||||
|
default:
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
return Cabinet<StFlow>::cabinet()->add(x);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_del(int i) {
|
||||||
|
Cabinet<StFlow>::cabinet()->del(i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_copy(int i) {
|
||||||
|
return Cabinet<StFlow>::cabinet()->newCopy(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_assign(int i, int j) {
|
||||||
|
return Cabinet<StFlow>::cabinet()->assign(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
// int DLL_EXPORT flow_readinputs(int i, char* infile) {
|
||||||
|
// try {
|
||||||
|
// ifstream f(infile);
|
||||||
|
// if (!f) throw CanteraError("flow_readinputs",
|
||||||
|
// "error opening input file");
|
||||||
|
// // _flow(i)->readInputs(f);
|
||||||
|
// f.close();
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// catch (CanteraError) { return -1; }
|
||||||
|
// catch (...) { return ERR; }
|
||||||
|
// }
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_setupgrid(int i, int npts, double* grid) {
|
||||||
|
try {
|
||||||
|
_flow(i)->setupGrid(npts, grid);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
//catch (...) { return ERR; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_setthermo(int i, int k) {
|
||||||
|
IdealGasPhase* th = (IdealGasPhase*)_thermo(k);
|
||||||
|
_flow(i)->setThermo(*th);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_setkinetics(int i, int k) {
|
||||||
|
Kinetics* kin = _kinetics(k);
|
||||||
|
_flow(i)->setKinetics(*kin);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_settransport(int i, int k, int soret) {
|
||||||
|
try {
|
||||||
|
Transport* tr = _transport(k);
|
||||||
|
bool withSoret = (soret == 1);
|
||||||
|
_flow(i)->setTransport(*tr, withSoret);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_settemperature(int i, int j, double t) {
|
||||||
|
_flow(i)->setTemperature(j, t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_setmassfraction(int i, int j, int k, double t) {
|
||||||
|
_flow(i)->setMassFraction(j, k, t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_setpressure(int i, double p) {
|
||||||
|
_flow(i)->setPressure(p);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_showsolution(int i, char* fname, double* soln) {
|
||||||
|
string fn = string(fname);
|
||||||
|
if (fn == "-")
|
||||||
|
_flow(i)->showSolution(cout, soln);
|
||||||
|
else {
|
||||||
|
ofstream fout(fname);
|
||||||
|
_flow(i)->showSolution(fout, soln);
|
||||||
|
fout.close();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_outputtec(int i, doublereal* x,
|
||||||
|
char* fname, char* title, int zone) {
|
||||||
|
ofstream f(fname);
|
||||||
|
//DenseMatrix* mat = _matrix(m);
|
||||||
|
_flow(i)->outputTEC(f, x, string(title), zone);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// solve / fix
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_solveenergyeqn(int i, int j) {
|
||||||
|
_flow(i)->solveEnergyEqn(j);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_fixtemperature(int i, int j) {
|
||||||
|
_flow(i)->fixTemperature(j);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_setenergyfactor(int i, double e) {
|
||||||
|
_flow(i)->setEnergyFactor(e);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_fixspecies(int i, int j) {
|
||||||
|
_flow(i)->fixSpecies(j);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_solvespecies(int i, int j) {
|
||||||
|
_flow(i)->solveSpecies(j);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_resize(int i, int points) {
|
||||||
|
_flow(i)->resize(points);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// int DLL_EXPORT flow_integratechem(int i, doublereal* x, double dt) {
|
||||||
|
// try{
|
||||||
|
// _flow(i)->integrateChem(x, dt);
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// catch (CanteraError) { return -1; }
|
||||||
|
// }
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_settolerances(int i, int nr,
|
||||||
|
doublereal* rtol, int na, doublereal* atol) {
|
||||||
|
try {
|
||||||
|
_flow(i)->setTolerances(nr, rtol, na, atol);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
//catch (...) { return ERR; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_eval(int i, int j, doublereal* x, doublereal* r, integer* m) {
|
||||||
|
try {
|
||||||
|
_flow(i)->eval(j, x, r, m);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_restore(int i, int job, char* fname, char* id,
|
||||||
|
int& size_z, doublereal* z, int& size_soln, doublereal* soln) {
|
||||||
|
try {
|
||||||
|
_flow(i)->restore(job, fname, string(id), size_z, z,
|
||||||
|
size_soln, soln);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
catch (...) { return ERR; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_setfixedpoint(int i, int j0, doublereal t0) {
|
||||||
|
_flow(i)->setFixedPoint(j0, t0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int DLL_EXPORT flow_setboundaries(int i, int nleft, int nright) {
|
||||||
|
Boundary *left=0, *right=0;
|
||||||
|
if (nleft > 0) left = _boundary(nleft);
|
||||||
|
if (nright > 0) right = _boundary(nright);
|
||||||
|
_flow(i)->setBoundaries(left, right);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//==========================================================
|
||||||
|
|
||||||
|
int DLL_EXPORT bdry_new(int type, int iph, int kin) {
|
||||||
|
Boundary* x=0;
|
||||||
|
//const doublereal* wt = _phase(iph)->molecularWeights().begin();
|
||||||
|
int nsp = _phase(iph)->nSpecies();
|
||||||
|
switch (type) {
|
||||||
|
case 0:
|
||||||
|
x = new Inlet(nsp); break;
|
||||||
|
case 1:
|
||||||
|
x = new Outlet(nsp); break;
|
||||||
|
//case 2:
|
||||||
|
//if (kin > 0)
|
||||||
|
// x = new Surface(nsp, _surfkin(kin));
|
||||||
|
//else
|
||||||
|
// x = new Surface(nsp, 0);
|
||||||
|
//break;
|
||||||
|
case 3:
|
||||||
|
x = new SymmPlane(nsp); break;
|
||||||
|
default:
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
return Cabinet<Boundary>::cabinet()->add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int DLL_EXPORT bdry_del(int i) {
|
||||||
|
Cabinet<Boundary>::cabinet()->del(i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bdry_copy(int i) {
|
||||||
|
return Cabinet<Boundary>::cabinet()->newCopy(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bdry_assign(int i, int j) {
|
||||||
|
return Cabinet<Boundary>::cabinet()->assign(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT bdry_set(int i, int n, doublereal* v) {
|
||||||
|
switch (n) {
|
||||||
|
case 1:
|
||||||
|
_boundary(i)->set_mdot(*v); break;
|
||||||
|
case 2:
|
||||||
|
_boundary(i)->set_V(*v); break;
|
||||||
|
case 3:
|
||||||
|
_boundary(i)->set_T(*v); break;
|
||||||
|
case 4:
|
||||||
|
_boundary(i)->set_Y(v); break;
|
||||||
|
default:
|
||||||
|
throw CanteraError("bdry_set","unknown option");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//=========================================================
|
||||||
|
|
||||||
|
|
||||||
|
int DLL_EXPORT onedim_new(int nd, int* domains, int* types) {
|
||||||
|
int i;
|
||||||
|
vector<Resid1D*> doms;
|
||||||
|
for (i = 0; i < nd; i++) {
|
||||||
|
switch (types[i]) {
|
||||||
|
case 0:
|
||||||
|
doms.push_back(_flow(domains[i])); break;
|
||||||
|
//case 1:
|
||||||
|
//doms.push_back(_surface(domains[i])); break;
|
||||||
|
case 2:
|
||||||
|
doms.push_back(_bndry(domains[i])); break;
|
||||||
|
default:
|
||||||
|
throw CanteraError("onedim_new", "unknown domain type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
OneDim* x = new OneDim(doms);
|
||||||
|
return Cabinet<OneDim>::cabinet()->add(x);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int DLL_EXPORT onedim_del(int i) {
|
||||||
|
Cabinet<OneDim>::cabinet()->del(i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT onedim_addFlow(int i, int n) {
|
||||||
|
try {
|
||||||
|
_onedim(i)->addDomain(_flow(n));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
// catch (...) { return ERR; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// int DLL_EXPORT onedim_addSurf(int i, int n) {
|
||||||
|
// try {
|
||||||
|
// _onedim(i)->addDomain(_surface(n));
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// catch (CanteraError) { return -1; }
|
||||||
|
// }
|
||||||
|
|
||||||
|
int DLL_EXPORT onedim_eval(int i, doublereal* x0, doublereal* r) {
|
||||||
|
try {
|
||||||
|
_onedim(i)->eval(-1, x0, r, 0.0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
// catch (...) { return ERR; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT onedim_solve(int i, doublereal* x0, doublereal* x1,
|
||||||
|
int loglevel) {
|
||||||
|
try {
|
||||||
|
int m = _onedim(i)->solve(x0, x1, loglevel);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
//catch (...) { return ERR; }
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT onedim_ssnorm(int i, doublereal* x0, doublereal* x1) {
|
||||||
|
return _onedim(i)->ssnorm(x0, x1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT onedim_setsteadymode(int i) {
|
||||||
|
if (_onedim(i)->transient()) {
|
||||||
|
_onedim(i)->setSteadyMode();
|
||||||
|
//_onedim(i)->jacobian().setAge(10000);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT onedim_settransientmode(int i, doublereal dt, doublereal* x) {
|
||||||
|
_onedim(i)->initTimeInteg(dt, x);
|
||||||
|
double rr = fabs(_onedim(i)->rdt()*dt - 1.0);
|
||||||
|
if ((rr > 1.e-5) || _onedim(i)->steady()) {
|
||||||
|
//_onedim(i)->jacobian().setAge(10000);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT onedim_setnewtonoptions(int i, int maxage) {
|
||||||
|
_onedim(i)->newton().setOptions(maxage);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT onedim_resize(int i) {
|
||||||
|
_onedim(i)->resize();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT onedim_writeStats(int i) {
|
||||||
|
_onedim(i)->writeStats();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT onedim_timestep(int i, int nsteps, doublereal dt,
|
||||||
|
doublereal* x, doublereal* xnew, int loglevel) {
|
||||||
|
try {
|
||||||
|
return _onedim(i)->timeStep(nsteps, dt, x, xnew, loglevel);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1.0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT onedim_save(int i, char* fname, char* id,
|
||||||
|
char* desc, doublereal* soln) {
|
||||||
|
try {
|
||||||
|
_onedim(i)->save(string(fname), string(id), string(desc), soln);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
//catch (...) { return ERR; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
71
Cantera/clib/src/ctstagn.h
Executable file
71
Cantera/clib/src/ctstagn.h
Executable file
@ -0,0 +1,71 @@
|
|||||||
|
#ifndef CTC_STAGN_H
|
||||||
|
#define CTC_STAGN_H
|
||||||
|
|
||||||
|
// Cantera includes
|
||||||
|
//#include "stagn.h"
|
||||||
|
|
||||||
|
//#include "Cabinet.h"
|
||||||
|
//#include "Storage.h"
|
||||||
|
#include "clib_defs.h"
|
||||||
|
|
||||||
|
//inline StFlow* _flow(int i) {
|
||||||
|
// return Cabinet<StFlow>::cabinet()->item(i);
|
||||||
|
//}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
int DLL_IMPORT flow_new(int type, int iph, int np);
|
||||||
|
int DLL_IMPORT flow_del(int i);
|
||||||
|
int DLL_IMPORT flow_copy(int i);
|
||||||
|
int DLL_IMPORT flow_assign(int i, int j);
|
||||||
|
int DLL_IMPORT flow_setupgrid(int i, int npts, double* grid);
|
||||||
|
int DLL_EXPORT flow_setthermo(int i, int k);
|
||||||
|
int DLL_IMPORT flow_setkinetics(int i, int k);
|
||||||
|
int DLL_IMPORT flow_settransport(int i, int k, int soret);
|
||||||
|
int DLL_IMPORT flow_solveenergyeqn(int i, int j);
|
||||||
|
int DLL_IMPORT flow_fixtemperature(int i, int j);
|
||||||
|
int DLL_IMPORT flow_setenergyfactor(int i, double e);
|
||||||
|
int DLL_IMPORT flow_fixspecies(int i, int j);
|
||||||
|
int DLL_IMPORT flow_solvespecies(int i, int j);
|
||||||
|
// int DLL_IMPORT flow_integratechem(int i, double* x, double dt);
|
||||||
|
int DLL_IMPORT flow_settemperature(int i, int j, double t);
|
||||||
|
int DLL_IMPORT flow_setpressure(int i, double p);
|
||||||
|
int DLL_IMPORT flow_setmassfraction(int i, int j, int k, double t);
|
||||||
|
int DLL_IMPORT flow_outputtec(int i, double* x, char* fname,
|
||||||
|
char* title, int zone);
|
||||||
|
int DLL_IMPORT flow_showsolution(int i, char* fname, double* x);
|
||||||
|
int DLL_IMPORT flow_settolerances(int i, int nr,
|
||||||
|
double* rtol, int na, double* atol);
|
||||||
|
int DLL_IMPORT flow_resize(int i, int points);
|
||||||
|
int DLL_IMPORT flow_setsteadymode(int i);
|
||||||
|
int DLL_IMPORT flow_settransientmode(int i, double dt, double* x);
|
||||||
|
|
||||||
|
int DLL_IMPORT flow_restore(int i, int job, char* fname, char* id,
|
||||||
|
int& size_z, double* z, int& size_soln, double* soln);
|
||||||
|
int DLL_IMPORT flow_setfixedpoint(int i, int j0, double t0);
|
||||||
|
int DLL_IMPORT flow_setboundaries(int i, int nleft, int nright);
|
||||||
|
int DLL_IMPORT bdry_new(int type, int iph, int kin);
|
||||||
|
int DLL_IMPORT bdry_del(int i);
|
||||||
|
int DLL_IMPORT bdry_copy(int i);
|
||||||
|
int DLL_IMPORT bdry_assign(int i, int j);
|
||||||
|
int DLL_IMPORT bdry_set(int i, int n, double* v);
|
||||||
|
|
||||||
|
int DLL_IMPORT onedim_new(int nd, int* domains, int* types);
|
||||||
|
int DLL_IMPORT onedim_del(int i);
|
||||||
|
int DLL_IMPORT onedim_addFlow(int i, int n);
|
||||||
|
//int DLL_IMPORT onedim_addSurf(int i, int n);
|
||||||
|
int DLL_EXPORT onedim_eval(int i, double* x0, double* r);
|
||||||
|
int DLL_IMPORT onedim_solve(int i, double* x0, double* x1, int loglevel);
|
||||||
|
double DLL_IMPORT onedim_ssnorm(int i, double* x0, double* x1);
|
||||||
|
int DLL_IMPORT onedim_setsteadymode(int i);
|
||||||
|
int DLL_IMPORT onedim_settransientmode(int i, double dt, double* x);
|
||||||
|
int DLL_IMPORT onedim_setnewtonoptions(int i, int maxage);
|
||||||
|
int DLL_IMPORT onedim_resize(int i);
|
||||||
|
int DLL_IMPORT onedim_writeStats(int i);
|
||||||
|
double DLL_IMPORT onedim_timestep(int i, int nsteps, double dt,
|
||||||
|
double* x, double* xnew, int loglevel);
|
||||||
|
int DLL_IMPORT onedim_save(int i, char* fname, char* id, char* desc, double* soln);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
86
Cantera/clib/src/ctsurf.cpp
Executable file
86
Cantera/clib/src/ctsurf.cpp
Executable file
@ -0,0 +1,86 @@
|
|||||||
|
|
||||||
|
// Cantera includes
|
||||||
|
#include "SurfPhase.h"
|
||||||
|
#include "InterfaceKinetics.h"
|
||||||
|
|
||||||
|
#include "Cabinet.h"
|
||||||
|
#include "Storage.h"
|
||||||
|
|
||||||
|
// Build as a DLL under Windows
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DLL_EXPORT __declspec(dllexport)
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#pragma warning(disable:4503)
|
||||||
|
#else
|
||||||
|
#define DLL_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Values returned for error conditions
|
||||||
|
#define ERR -999
|
||||||
|
#define DERR -999.999
|
||||||
|
|
||||||
|
|
||||||
|
//Cabinet<Surf1D>* Cabinet<Surf1D>::__storage = 0;
|
||||||
|
|
||||||
|
//inline Surf1D* _surface(int i) {
|
||||||
|
// return Cabinet<Surf1D>::cabinet()->item(i);
|
||||||
|
//}
|
||||||
|
|
||||||
|
inline SurfPhase* _surfphase(int n) {
|
||||||
|
return (SurfPhase*)Storage::__storage->__thtable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline InterfaceKinetics* _surfkin(int n) {
|
||||||
|
return (InterfaceKinetics*)Storage::__storage->__ktable[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
// int DLL_EXPORT surface_new(int ikin) {
|
||||||
|
// InterfaceKinetics* sk = 0;
|
||||||
|
// if (ikin > 0) sk = _surfkin(ikin);
|
||||||
|
// Surf1D* s = new Surf1D(sk);
|
||||||
|
// return Cabinet<Surf1D>::cabinet()->add(s);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// int DLL_EXPORT surface_del(int i) {
|
||||||
|
// Cabinet<Surf1D>::cabinet()->del(i);
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
int DLL_EXPORT surf_setsitedensity(int i, double s0) {
|
||||||
|
_surfphase(i)->setSiteDensity(s0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double DLL_EXPORT surf_sitedensity(int i) {
|
||||||
|
return _surfphase(i)->siteDensity();
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT surf_setcoverages(int i, double* c) {
|
||||||
|
_surfphase(i)->setCoverages(c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT surf_getcoverages(int i, double* c) {
|
||||||
|
_surfphase(i)->getCoverages(c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT surf_setconcentrations(int i, double* c) {
|
||||||
|
_surfphase(i)->setConcentrations(c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT surf_getconcentrations(int i, double* c) {
|
||||||
|
_surfphase(i)->getConcentrations(c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// int DLL_EXPORT surface_setcoverages(int i, double* c) {
|
||||||
|
// _surface(i)->setCoverages(c);
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
}
|
54
Cantera/clib/src/ctsurf.h
Executable file
54
Cantera/clib/src/ctsurf.h
Executable file
@ -0,0 +1,54 @@
|
|||||||
|
#ifndef CTC_SURF_H
|
||||||
|
#define CTC_SURF_H
|
||||||
|
|
||||||
|
// Cantera includes
|
||||||
|
//#include "surface.h"
|
||||||
|
|
||||||
|
//#include "Cabinet.h"
|
||||||
|
//#include "Storage.h"
|
||||||
|
#include "clib_defs.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
int DLL_IMPORT surface_new(int ikin);
|
||||||
|
int DLL_IMPORT surface_del(int i);
|
||||||
|
|
||||||
|
int DLL_IMPORT surfphase_new();
|
||||||
|
int DLL_IMPORT surf_del(int i);
|
||||||
|
int DLL_IMPORT surf_copy(int i);
|
||||||
|
int DLL_IMPORT surf_assign(int i, int j);
|
||||||
|
int DLL_IMPORT surf_addspecies(int i, char* nm, double sz);
|
||||||
|
int DLL_IMPORT surf_nspecies(int i);
|
||||||
|
int DLL_IMPORT surf_freezespecies(int i);
|
||||||
|
int DLL_IMPORT surf_setcoverages(int i, double* c);
|
||||||
|
int DLL_IMPORT surf_getcoverages(int i, double* c);
|
||||||
|
int DLL_IMPORT surf_setconcentrations(int i, double* c);
|
||||||
|
int DLL_IMPORT surf_getconcentrations(int i, double* c);
|
||||||
|
int DLL_IMPORT surf_setsitedensity(int i, double s0);
|
||||||
|
double DLL_IMPORT surf_sitedensity(int i);
|
||||||
|
int DLL_IMPORT surf_doc(int i, char* key, char* value);
|
||||||
|
|
||||||
|
int DLL_IMPORT surfkin_new(int iph, int ith1, int ith2);
|
||||||
|
int DLL_IMPORT surfkin_del(int i);
|
||||||
|
int DLL_IMPORT surfkin_addreaction(int i, int nr, int* r,
|
||||||
|
int* rst, int* ro, int np, int* p, int* pst,
|
||||||
|
int nrate, double* rateParams);
|
||||||
|
int DLL_IMPORT surfkin_nreactions(int i);
|
||||||
|
int DLL_IMPORT surfkin_getratesofprogress(int i, double* rop);
|
||||||
|
int DLL_IMPORT surfkin_getnetproductionrates(int i, double* sdot);
|
||||||
|
int DLL_IMPORT surfkin_integrate(int i, double dt);
|
||||||
|
int DLL_IMPORT surfkin_save(int i, char* fname, char* id, char* comment);
|
||||||
|
|
||||||
|
int DLL_IMPORT surface_settolerances(int i, int nr,
|
||||||
|
double* rtol, int na, double* atol);
|
||||||
|
int DLL_IMPORT surface_fixspecies(int i, int k, double c=-1.0);
|
||||||
|
int DLL_IMPORT surface_solvespecies(int i, int k);
|
||||||
|
int DLL_IMPORT surface_setmultiplier(int i, int k, double f);
|
||||||
|
double DLL_IMPORT surface_multiplier(int i, int k);
|
||||||
|
double DLL_IMPORT surface_temperature(int i);
|
||||||
|
int DLL_IMPORT surface_settemperature(int i, double t);
|
||||||
|
int DLL_IMPORT surface_setcoverages(int i, double* c);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
235
Cantera/clib/src/ctxml.cpp
Normal file
235
Cantera/clib/src/ctxml.cpp
Normal file
@ -0,0 +1,235 @@
|
|||||||
|
|
||||||
|
// Cantera includes
|
||||||
|
#include "ctml.h"
|
||||||
|
|
||||||
|
#include "Cabinet.h"
|
||||||
|
#include "Storage.h"
|
||||||
|
|
||||||
|
// Build as a DLL under Windows
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DLL_EXPORT __declspec(dllexport)
|
||||||
|
#pragma warning(disable:4786)
|
||||||
|
#pragma warning(disable:4503)
|
||||||
|
#else
|
||||||
|
#define DLL_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Values returned for error conditions
|
||||||
|
#define ERR -999
|
||||||
|
#define DERR -999.999
|
||||||
|
|
||||||
|
Cabinet<XML_Node>* Cabinet<XML_Node>::__storage = 0;
|
||||||
|
|
||||||
|
inline XML_Node* _xml(int i) {
|
||||||
|
return Cabinet<XML_Node>::cabinet()->item(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_new(const char* name = 0) {
|
||||||
|
XML_Node* x;
|
||||||
|
if (!name) x = new XML_Node;
|
||||||
|
else x = new XML_Node(string(name));
|
||||||
|
return Cabinet<XML_Node>::cabinet()->add(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_del(int i) {
|
||||||
|
Cabinet<XML_Node>::cabinet()->del(i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_removeChild(int i, int j) {
|
||||||
|
_xml(i)->removeChild(_xml(j));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_copy(int i) {
|
||||||
|
return Cabinet<XML_Node>::cabinet()->newCopy(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_assign(int i, int j) {
|
||||||
|
return Cabinet<XML_Node>::cabinet()->assign(i,j);
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_build(int i, const char* file) {
|
||||||
|
try {
|
||||||
|
string path = findInputFile(string(file));
|
||||||
|
ifstream f(path.c_str());
|
||||||
|
if (!f) {
|
||||||
|
throw CanteraError("xml_build",
|
||||||
|
"file "+string(file)+" not found.");
|
||||||
|
}
|
||||||
|
_xml(i)->build(f);
|
||||||
|
f.close();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_attrib(int i, const char* key, char* value) {
|
||||||
|
try {
|
||||||
|
string ky = string(key);
|
||||||
|
XML_Node& node = *_xml(i);
|
||||||
|
if (node.hasAttrib(ky)) {
|
||||||
|
string v = node[ky];
|
||||||
|
strncpy(value, v.c_str(), 80);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw CanteraError("xml_attrib","node "
|
||||||
|
" has no attribute '"+ky+"'");
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_addAttrib(int i, const char* key, const char* value) {
|
||||||
|
try {
|
||||||
|
string ky = string(key);
|
||||||
|
string val = string(value);
|
||||||
|
XML_Node& node = *_xml(i);
|
||||||
|
node.addAttribute(ky, val);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_tag(int i, char* tag) {
|
||||||
|
try {
|
||||||
|
XML_Node& node = *_xml(i);
|
||||||
|
const string v = node.name();
|
||||||
|
strncpy(tag, v.c_str(), 80);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_value(int i, char* value) {
|
||||||
|
try {
|
||||||
|
XML_Node& node = *_xml(i);
|
||||||
|
const string v = node.value();
|
||||||
|
strncpy(value, v.c_str(), 80);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_child(int i, const char* loc) {
|
||||||
|
try {
|
||||||
|
XML_Node& node = *_xml(i);
|
||||||
|
XML_Node& c = node.child(string(loc));
|
||||||
|
return Cabinet<XML_Node>::cabinet()->add(&c);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_child_bynumber(int i, int m) {
|
||||||
|
try {
|
||||||
|
XML_Node& node = *_xml(i);
|
||||||
|
XML_Node& c = node.child(m);
|
||||||
|
return Cabinet<XML_Node>::cabinet()->add(&c);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_findID(int i, const char* id) {
|
||||||
|
try {
|
||||||
|
XML_Node& node = *_xml(i);
|
||||||
|
XML_Node* c = node.findID(string(id));
|
||||||
|
if (c) {
|
||||||
|
return Cabinet<XML_Node>::cabinet()->add(c);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw CanteraError("xml_find_id","id not found: "+string(id));
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_findByName(int i, const char* nm) {
|
||||||
|
try {
|
||||||
|
XML_Node& node = *_xml(i);
|
||||||
|
XML_Node* c = node.findByName(string(nm));
|
||||||
|
if (c) {
|
||||||
|
return Cabinet<XML_Node>::cabinet()->add(c);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw CanteraError("xml_findByName","name "+string(nm)
|
||||||
|
+" not found");
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_nChildren(int i) {
|
||||||
|
try {
|
||||||
|
XML_Node& node = *_xml(i);
|
||||||
|
return node.nChildren();
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_addChild(int i, const char* name, const char* value) {
|
||||||
|
try {
|
||||||
|
XML_Node& node = *_xml(i);
|
||||||
|
XML_Node& c = node.addChild(string(name),string(value));
|
||||||
|
return Cabinet<XML_Node>::cabinet()->add(&c);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { showErrors(cout); return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_addChildNode(int i, int j) {
|
||||||
|
try {
|
||||||
|
XML_Node& node = *_xml(i);
|
||||||
|
XML_Node& chld = *_xml(j);
|
||||||
|
XML_Node& c = node.addChild(chld);
|
||||||
|
return Cabinet<XML_Node>::cabinet()->add(&c);
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT xml_write(int i, const char* file) {
|
||||||
|
try {
|
||||||
|
ofstream f(file);
|
||||||
|
if (f) {
|
||||||
|
XML_Node& node = *_xml(i);
|
||||||
|
node.write(f);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw CanteraError("xml_write",
|
||||||
|
"file "+string(file)+" not found.");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DLL_EXPORT ctml_getFloatArray(int i, int n, doublereal* data, int iconvert) {
|
||||||
|
try {
|
||||||
|
XML_Node& node = *_xml(i);
|
||||||
|
vector_fp v;
|
||||||
|
bool conv = false;
|
||||||
|
if (iconvert > 0) conv = true;
|
||||||
|
getFloatArray(node, v, conv);
|
||||||
|
int nv = v.size();
|
||||||
|
|
||||||
|
// array not big enough
|
||||||
|
if (n < nv) {
|
||||||
|
throw CanteraError("ctml_getFloatArray",
|
||||||
|
"array must be dimensioned at least "+int2str(nv));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < nv; i++) {
|
||||||
|
data[i] = v[i];
|
||||||
|
}
|
||||||
|
n = nv;
|
||||||
|
}
|
||||||
|
catch (CanteraError) { return -1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
30
Cantera/clib/src/ctxml.h
Normal file
30
Cantera/clib/src/ctxml.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef CTC_XML_H
|
||||||
|
#define CTC_XML_H
|
||||||
|
|
||||||
|
#include "clib_defs.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
int DLL_IMPORT xml_new(const char* name);
|
||||||
|
int DLL_IMPORT xml_del(int i);
|
||||||
|
int DLL_IMPORT xml_copy(int i);
|
||||||
|
int DLL_IMPORT xml_assign(int i, int j);
|
||||||
|
int DLL_IMPORT xml_build(int i, const char* file);
|
||||||
|
int DLL_IMPORT xml_attrib(int i, const char* key, char* value);
|
||||||
|
int DLL_IMPORT xml_addAttrib(int i, const char* key, const char* value);
|
||||||
|
int DLL_IMPORT xml_value(int i, char* value);
|
||||||
|
int DLL_IMPORT xml_tag(int i, char* tag);
|
||||||
|
int DLL_IMPORT xml_child(int i, const char* loc);
|
||||||
|
int DLL_IMPORT xml_child_bynumber(int i, int m);
|
||||||
|
int DLL_IMPORT xml_findID(int i, const char* id);
|
||||||
|
int DLL_IMPORT xml_findByName(int i, const char* nm);
|
||||||
|
int DLL_IMPORT xml_nChildren(int i);
|
||||||
|
int DLL_IMPORT xml_addChild(int i, const char* name, const char* value);
|
||||||
|
int DLL_IMPORT xml_addChildNode(int i, int j);
|
||||||
|
int DLL_IMPORT xml_write(int i, const char* file);
|
||||||
|
int DLL_IMPORT xml_removeChild(int i, int j);
|
||||||
|
int DLL_IMPORT ctml_getFloatArray(int i, int n, double* data, int iconvert=0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
3
Cantera/cxx/README
Normal file
3
Cantera/cxx/README
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
This directory contains files that are part of the C++ user
|
||||||
|
interface. For the kernel C++ files, see directory ../src.
|
||||||
|
|
3
Cantera/lib/README
Executable file
3
Cantera/lib/README
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
Library files.
|
||||||
|
|
85
Cantera/matlab/Makefile.in
Normal file
85
Cantera/matlab/Makefile.in
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#/bin/sh
|
||||||
|
###############################################################
|
||||||
|
# $Author$
|
||||||
|
# $Date$
|
||||||
|
# $Revision$
|
||||||
|
#
|
||||||
|
# Copyright 2001 California Institute of Technology
|
||||||
|
# See file License.txt for licensing information
|
||||||
|
#
|
||||||
|
###############################################################
|
||||||
|
|
||||||
|
LIBS = @LOCAL_LIBS@ @LIBS@ @FLIBS@
|
||||||
|
SRCS = cantera/private/ctmethods.cpp \
|
||||||
|
cantera/private/ctfunctions.cpp \
|
||||||
|
cantera/private/xmlmethods.cpp \
|
||||||
|
cantera/private/phasemethods.cpp \
|
||||||
|
cantera/private/thermomethods.cpp \
|
||||||
|
cantera/private/kineticsmethods.cpp \
|
||||||
|
cantera/private/transportmethods.cpp \
|
||||||
|
cantera/private/reactormethods.cpp \
|
||||||
|
cantera/private/wallmethods.cpp \
|
||||||
|
cantera/private/flowdevicemethods.cpp
|
||||||
|
|
||||||
|
all: ctmethods.mexmac
|
||||||
|
|
||||||
|
ctmethods.mexmac: $(SRCS)
|
||||||
|
@PYTHON_CMD@ setup_matlab.py @ctroot@/lib @CT_SHARED_LIB@ '$(LIBS)'
|
||||||
|
(@MATLAB_CMD@ -nodesktop -nojvm -nosplash -r setup)
|
||||||
|
rm -f setup.m
|
||||||
|
|
||||||
|
install:
|
||||||
|
@INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera
|
||||||
|
@INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera-demos
|
||||||
|
@INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera/private
|
||||||
|
@INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera/@ThermoPhase/private
|
||||||
|
@INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera/@Kinetics/private
|
||||||
|
@INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera/@Transport/private
|
||||||
|
@INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera/@Solution
|
||||||
|
@INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera/@XML_Node/private
|
||||||
|
@INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera/@Reactor/private
|
||||||
|
@INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera/@Wall/private
|
||||||
|
@INSTALL@ -d @prefix@/matlab/toolbox/cantera/cantera/@FlowDevice/private
|
||||||
|
cd cantera; @INSTALL@ *.m *.@mex_ext@ @prefix@/matlab/toolbox/cantera/cantera
|
||||||
|
cd cantera/private; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/private
|
||||||
|
cd cantera/examples; @INSTALL@ *.m @prefix@/matlab/toolbox/cantera/cantera-demos
|
||||||
|
cd cantera/@ThermoPhase; @INSTALL@ \
|
||||||
|
*.m @prefix@/matlab/toolbox/cantera/cantera/@ThermoPhase
|
||||||
|
cd cantera/@ThermoPhase/private; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/@ThermoPhase/private
|
||||||
|
cd cantera/@Kinetics; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/@Kinetics
|
||||||
|
cd cantera/@Kinetics/private; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/@Kinetics/private
|
||||||
|
cd cantera/@Solution; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/@Solution
|
||||||
|
cd cantera/@Transport; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/@Transport
|
||||||
|
cd cantera/@Transport/private; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/@Transport/private
|
||||||
|
cd cantera/@XML_Node; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/@XML_Node
|
||||||
|
cd cantera/@Reactor; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/@Reactor
|
||||||
|
cd cantera/@Reactor/private; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/@Reactor/private
|
||||||
|
cd cantera/@Wall; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/@Wall
|
||||||
|
cd cantera/@Wall/private; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/@Wall/private
|
||||||
|
cd cantera/@FlowDevice; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/@FlowDevice
|
||||||
|
cd cantera/@FlowDevice/private; @INSTALL@ *.m \
|
||||||
|
@prefix@/matlab/toolbox/cantera/cantera/@FlowDevice/private
|
||||||
|
|
||||||
|
clean:
|
||||||
|
echo '-'
|
||||||
|
|
||||||
|
depends:
|
||||||
|
echo '-'
|
||||||
|
|
||||||
|
# end of file
|
||||||
|
|
||||||
|
|
||||||
|
|
15
Cantera/matlab/cantera/@FlowDevice/FlowDevice.m
Normal file
15
Cantera/matlab/cantera/@FlowDevice/FlowDevice.m
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
function x = FlowDevice(typ)
|
||||||
|
%
|
||||||
|
if nargin == 0
|
||||||
|
typ = 1;
|
||||||
|
end
|
||||||
|
x.index = flowdevicemethods(0,typ);
|
||||||
|
if x.index < 0
|
||||||
|
error(geterr);
|
||||||
|
end
|
||||||
|
x.type = typ;
|
||||||
|
x.upstream = -1;
|
||||||
|
x.downstream = -1;
|
||||||
|
x = class(x,'FlowDevice');
|
||||||
|
|
||||||
|
|
4
Cantera/matlab/cantera/@FlowDevice/clear.m
Normal file
4
Cantera/matlab/cantera/@FlowDevice/clear.m
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
function clear(f)
|
||||||
|
% CLEAR -
|
||||||
|
%
|
||||||
|
flowdevicemethods(1, f.index)
|
16
Cantera/matlab/cantera/@FlowDevice/install.m
Normal file
16
Cantera/matlab/cantera/@FlowDevice/install.m
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
function install(f, upstream, downstream)
|
||||||
|
|
||||||
|
if nargin == 3
|
||||||
|
if ~isa(upstream,'Reactor') | ~isa(downstream,'Reactor')
|
||||||
|
error(['Flow devices can only be installed between reactors or' ...
|
||||||
|
' reservoirs'])
|
||||||
|
end
|
||||||
|
i = hndl(upstream);
|
||||||
|
j = hndl(downstream);
|
||||||
|
ok = flowdevicemethods(2, f.index, i, j);
|
||||||
|
if ok < 0
|
||||||
|
error(geterr)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
error('install requires 3 arguments')
|
||||||
|
end
|
5
Cantera/matlab/cantera/@FlowDevice/massFlowRate.m
Normal file
5
Cantera/matlab/cantera/@FlowDevice/massFlowRate.m
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function mdot = massFlowRate(f)
|
||||||
|
% MASSFLOWRATE - mass flow rate in kg/s
|
||||||
|
%
|
||||||
|
mdot = flowdevicemethods(21, f.index)
|
||||||
|
|
@ -0,0 +1,13 @@
|
|||||||
|
function v = flowdevicemethods(n, job, a, b, c, d)
|
||||||
|
%
|
||||||
|
if nargin == 2
|
||||||
|
v = ctmethods(80, n, job);
|
||||||
|
elseif nargin == 3
|
||||||
|
v = ctmethods(80, n, job, a);
|
||||||
|
elseif nargin == 4
|
||||||
|
v = ctmethods(80, n, job, a, b);
|
||||||
|
elseif nargin == 5
|
||||||
|
v = ctmethods(80, n, job, a, b, c);
|
||||||
|
elseif nargin == 6
|
||||||
|
v = ctmethods(80, n, job, a, b, c, d);
|
||||||
|
end
|
12
Cantera/matlab/cantera/@FlowDevice/setMassFlowRate.m
Normal file
12
Cantera/matlab/cantera/@FlowDevice/setMassFlowRate.m
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
function setMassFlowRate(f, mdot)
|
||||||
|
% SETMASSFLOWRATE -
|
||||||
|
%
|
||||||
|
if f.type == 1
|
||||||
|
k = flowdevicemethods(3, f.index, mdot);
|
||||||
|
if k < 0
|
||||||
|
error(geterr);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
error('Mass flow rate can only be set for mass flow controllers')
|
||||||
|
end
|
||||||
|
|
10
Cantera/matlab/cantera/@FlowDevice/setValveCoeff.m
Normal file
10
Cantera/matlab/cantera/@FlowDevice/setValveCoeff.m
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
function setValveCoeff(f, k)
|
||||||
|
% SETVALVECOEFF - set valve coefficient
|
||||||
|
%
|
||||||
|
if f.type ~= 3
|
||||||
|
error('Valve coefficient can only be set for valves')
|
||||||
|
end
|
||||||
|
ok = flowdevicemethods(4, f.index, k);
|
||||||
|
if ok < 0
|
||||||
|
error(geterr);
|
||||||
|
end
|
33
Cantera/matlab/cantera/@Kinetics/Kinetics.m
Executable file
33
Cantera/matlab/cantera/@Kinetics/Kinetics.m
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
function k = Kinetics(r, ph, neighbor1, neighbor2)
|
||||||
|
% KINETICS - Kinetics class constructor.
|
||||||
|
%
|
||||||
|
% Class Kinetics represents kinetics managers, which are classes
|
||||||
|
% that manage reaction mechanisms. The reaction mechanism
|
||||||
|
% attributes are specified in a CTML file.
|
||||||
|
%
|
||||||
|
%
|
||||||
|
if nargin == 1
|
||||||
|
if isa(r,'Kinetics')
|
||||||
|
% create a copy
|
||||||
|
k = r;
|
||||||
|
return
|
||||||
|
end
|
||||||
|
elseif nargin == 2
|
||||||
|
if isa(r,'XML_Node')
|
||||||
|
k.owner = 1;
|
||||||
|
i = hndl(r);
|
||||||
|
iph = hndl(ph);
|
||||||
|
ineighbor1 = -1;
|
||||||
|
ineighbor2 = -1;
|
||||||
|
k.id = kinetics_get(i,0,iph,ineighbor1,ineighbor2);
|
||||||
|
if k.id < 0
|
||||||
|
error(geterr);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
k.owner = 0;
|
||||||
|
k.id = r;
|
||||||
|
end
|
||||||
|
k = class(k,'Kinetics');
|
||||||
|
else
|
||||||
|
error('wrong number of arguments');
|
||||||
|
end
|
5
Cantera/matlab/cantera/@Kinetics/clear.m
Normal file
5
Cantera/matlab/cantera/@Kinetics/clear.m
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function clear(k)
|
||||||
|
% CLEAR - delete the Kinetics instance.
|
||||||
|
%
|
||||||
|
kinetics_set(k.id,3);
|
||||||
|
|
23
Cantera/matlab/cantera/@Kinetics/creationRates.m
Executable file
23
Cantera/matlab/cantera/@Kinetics/creationRates.m
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
function cdot = creationRates(a)
|
||||||
|
% CREATIONRATES Chemical creation rates (kmol/m^3/s).
|
||||||
|
%
|
||||||
|
% cdot = creationRates(K)
|
||||||
|
%
|
||||||
|
% Returns a column vector of the creation rates of all
|
||||||
|
% species. If the output is not assigned to a variable, a
|
||||||
|
% bar graph is produced.
|
||||||
|
%
|
||||||
|
% See also: destructionRates, netProdRates.
|
||||||
|
%
|
||||||
|
cdot = kinetics_get(a.id,21,0);
|
||||||
|
if nargout == 0
|
||||||
|
figure
|
||||||
|
set(gcf,'Name','Creation Rates')
|
||||||
|
bar(cdot)
|
||||||
|
xlabel('Species Number')
|
||||||
|
ylabel('Creation Rate (kmol/m^3-s)')
|
||||||
|
title('Species Chemical Creation Rates')
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
23
Cantera/matlab/cantera/@Kinetics/destructionRates.m
Executable file
23
Cantera/matlab/cantera/@Kinetics/destructionRates.m
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
function ddot = destructionRates(a)
|
||||||
|
% destructionRates Chemical destruction rates (kmol/m^3/s).
|
||||||
|
%
|
||||||
|
% cdot = destructionRates(a)
|
||||||
|
%
|
||||||
|
% Returns a column vector of the destruction rates of all
|
||||||
|
% species. If the output is not assigned to a variable, a
|
||||||
|
% bar graph is produced.
|
||||||
|
%
|
||||||
|
% See also: creationRates, netProdRates.
|
||||||
|
%
|
||||||
|
ddot = kinetics_get(a.id,22,0);
|
||||||
|
if nargout == 0
|
||||||
|
figure
|
||||||
|
set(gcf,'Name','Destruction Rates')
|
||||||
|
bar(ddot)
|
||||||
|
xlabel('Species Number')
|
||||||
|
ylabel('Destruction Rate (kmol/m^3/s)')
|
||||||
|
title('Species Chemical Destruction Rates')
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
20
Cantera/matlab/cantera/@Kinetics/destruction_rates.m
Executable file
20
Cantera/matlab/cantera/@Kinetics/destruction_rates.m
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
function q = destruction_rates(a)
|
||||||
|
% destruction_rates Chemical destruction rates for all species.
|
||||||
|
%
|
||||||
|
% q = destruction_rates(a)
|
||||||
|
%
|
||||||
|
% Returns a column vector of the destruction rates of all species.
|
||||||
|
%
|
||||||
|
% See also: creation_rates, net_production_rates.
|
||||||
|
%
|
||||||
|
q = production(a.id,nSpecies(a.ph),1);
|
||||||
|
if nargout == 0
|
||||||
|
figure
|
||||||
|
set(gcf,'Name','Destruction Rates')
|
||||||
|
bar(q)
|
||||||
|
xlabel('Species Number')
|
||||||
|
ylabel('Destruction Rate (kmol/m^3/s)')
|
||||||
|
title('Species Chemical Destruction Rates')
|
||||||
|
end
|
||||||
|
|
||||||
|
|
22
Cantera/matlab/cantera/@Kinetics/equil_Kc.m
Executable file
22
Cantera/matlab/cantera/@Kinetics/equil_Kc.m
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
function kc = equil_Kc(a)
|
||||||
|
% equil_Kc(a) equilibrium constants for all reactions
|
||||||
|
%
|
||||||
|
% q = equil_Kc(a)
|
||||||
|
%
|
||||||
|
% Returns a column vector of the equilibrium constants
|
||||||
|
% for all reactions. The vector has an entry for every
|
||||||
|
% reaction, whether reversible or not, but non-zero values
|
||||||
|
% occur only for the reversible reactions.
|
||||||
|
%
|
||||||
|
%
|
||||||
|
kc = kinetics_get(a.id,14,0);
|
||||||
|
if nargout == 0
|
||||||
|
figure
|
||||||
|
set(gcf,'Name','Equilibrium Constants')
|
||||||
|
bar(log10(kc))
|
||||||
|
xlabel('Reaction Number')
|
||||||
|
ylabel('log_1_0 Kc [kmol, m, s]')
|
||||||
|
title('Equilibrium Constants Kc')
|
||||||
|
end
|
||||||
|
|
||||||
|
|
2
Cantera/matlab/cantera/@Kinetics/hndl.m
Executable file
2
Cantera/matlab/cantera/@Kinetics/hndl.m
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
function i = hndl(k)
|
||||||
|
i = k.id;
|
14
Cantera/matlab/cantera/@Kinetics/isReversible.m
Executable file
14
Cantera/matlab/cantera/@Kinetics/isReversible.m
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
function yn = isReversible(a, i)
|
||||||
|
% ISREVERSIBLE - Reversible reaction flag.
|
||||||
|
%
|
||||||
|
% A reversible reaction is one that runs in both the forward
|
||||||
|
% direction (reactants -> products) and in the reverse direction
|
||||||
|
% (products -> reactants). The reverse rate for reversible
|
||||||
|
% reactions is computed from thermochemistry, so that the
|
||||||
|
% reaction satisfies detailed balance, and the net rate of
|
||||||
|
% progress is zero in states of chemical equilibrium.
|
||||||
|
%
|
||||||
|
% ISREVERSIBLE(K, IRXN) returns 1 if reaction number IRXN is
|
||||||
|
% reversible, and 0 if it is irreversible.
|
||||||
|
%
|
||||||
|
yn = kinetics_get(a.id,4,i);
|
6
Cantera/matlab/cantera/@Kinetics/kinetics_hndl.m
Normal file
6
Cantera/matlab/cantera/@Kinetics/kinetics_hndl.m
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
function i = kinetics_hndl(k)
|
||||||
|
% KINETICS_HNDL - integer used to access kernel object
|
||||||
|
%
|
||||||
|
i = k.id;
|
||||||
|
|
||||||
|
|
14
Cantera/matlab/cantera/@Kinetics/multiplier.m
Executable file
14
Cantera/matlab/cantera/@Kinetics/multiplier.m
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
function n = multiplier(a,irxn)
|
||||||
|
% MULTIPLIER Multiplier for reaction rate of progress.
|
||||||
|
%
|
||||||
|
% The multiplier multiplies the reaction rate of progress. It may
|
||||||
|
% be used to implement sensitivity analysis, or to selectively
|
||||||
|
% disable reactions. For reversible reactions, it multiplies both
|
||||||
|
% the forward and reverse rates. By default, the multiplier value
|
||||||
|
% is 1.0, but it may be set to any other value by calling method
|
||||||
|
% setMultiplier.
|
||||||
|
%
|
||||||
|
% MULTIPLIER(K, IRXN) Multiplier for reaction number IRXN
|
||||||
|
%
|
||||||
|
n = kinetics_get(a.id,2,irxn);
|
||||||
|
|
5
Cantera/matlab/cantera/@Kinetics/nReactions.m
Executable file
5
Cantera/matlab/cantera/@Kinetics/nReactions.m
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
function n = nReactions(a)
|
||||||
|
% NREACTIONS - Number of reactions.
|
||||||
|
%
|
||||||
|
n = kinetics_get(a.id,1,0);
|
||||||
|
|
5
Cantera/matlab/cantera/@Kinetics/nTotalSpecies.m
Normal file
5
Cantera/matlab/cantera/@Kinetics/nTotalSpecies.m
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function nsp = nTotalSpecies(a)
|
||||||
|
% NTOTALSPECIES - The total number of species, summed over all
|
||||||
|
% participating phases.
|
||||||
|
%
|
||||||
|
nsp = kinetics_get(a.id, 3, 0);
|
22
Cantera/matlab/cantera/@Kinetics/netProdRates.m
Executable file
22
Cantera/matlab/cantera/@Kinetics/netProdRates.m
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
function wdot = netProdRates(a)
|
||||||
|
% NETPRODRATES Net chemical production rates for all species.
|
||||||
|
%
|
||||||
|
% wdot = netProdRates(a)
|
||||||
|
%
|
||||||
|
% Returns a column vector of the net production (creation -
|
||||||
|
% destruction) rates of all species. If the output is not
|
||||||
|
% assigned to a variable, a bar plot is produced.
|
||||||
|
%
|
||||||
|
% See also: creationRates, destructionRates
|
||||||
|
%
|
||||||
|
wdot = kinetics_get(a.id,23,0);
|
||||||
|
if nargout == 0
|
||||||
|
figure
|
||||||
|
set(gcf,'Name','Production Rates')
|
||||||
|
bar(wdot)
|
||||||
|
xlabel('Species Number')
|
||||||
|
ylabel('Net Production Rate (kmol/m^3/s)')
|
||||||
|
title('Species Net Chemical Production Rates')
|
||||||
|
end
|
||||||
|
|
||||||
|
|
22
Cantera/matlab/cantera/@Kinetics/private/delkinetics.cpp
Normal file
22
Cantera/matlab/cantera/@Kinetics/private/delkinetics.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
#include "mex.h"
|
||||||
|
#include "../../../../clib/src/ct.h"
|
||||||
|
#include "../../private/ctmatutils.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a Cantera 'Kinetics' object
|
||||||
|
*/
|
||||||
|
void mexFunction( int nlhs, mxArray *plhs[],
|
||||||
|
int nrhs, const mxArray *prhs[] )
|
||||||
|
{
|
||||||
|
int k = getInt(prhs[0]);
|
||||||
|
int ok = delKinetics(k);
|
||||||
|
|
||||||
|
// Create matrix for the return argument.
|
||||||
|
plhs[0] = mxCreateDoubleMatrix(1,1, mxREAL);
|
||||||
|
double* x = mxGetPr(plhs[0]);
|
||||||
|
*x = ok;
|
||||||
|
}
|
||||||
|
}
|
19
Cantera/matlab/cantera/@Kinetics/private/isrev.cpp
Executable file
19
Cantera/matlab/cantera/@Kinetics/private/isrev.cpp
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
#include "mex.h"
|
||||||
|
#include "../../../../clib/src/ct.h"
|
||||||
|
#include "../../private/ctmatutils.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
void mexFunction( int nlhs, mxArray *plhs[],
|
||||||
|
int nrhs, const mxArray *prhs[] )
|
||||||
|
{
|
||||||
|
double vv;
|
||||||
|
int kin = getInt(prhs[0]);
|
||||||
|
int irxn = getInt(prhs[1]);
|
||||||
|
vv = kin_isReversible(kin,irxn-1);
|
||||||
|
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
|
||||||
|
double *h = mxGetPr(plhs[0]);
|
||||||
|
*h = vv;
|
||||||
|
}
|
||||||
|
}
|
35
Cantera/matlab/cantera/@Kinetics/private/kin_get.cpp
Executable file
35
Cantera/matlab/cantera/@Kinetics/private/kin_get.cpp
Executable file
@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
#include "mex.h"
|
||||||
|
#include "../../../../clib/src/ct.h"
|
||||||
|
#include "../../private/ctmatutils.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
void mexFunction( int nlhs, mxArray *plhs[],
|
||||||
|
int nrhs, const mxArray *prhs[] )
|
||||||
|
{
|
||||||
|
double vv;
|
||||||
|
int kin = getInt(prhs[0]);
|
||||||
|
int job = getInt(prhs[1]);
|
||||||
|
int irxn = getInt(prhs[2]);
|
||||||
|
|
||||||
|
bool ok = true;
|
||||||
|
switch (job) {
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
vv = kin_nReactions(kin); break;
|
||||||
|
case 2:
|
||||||
|
vv = kin_multiplier(kin, irxn-1); break;
|
||||||
|
case 3:
|
||||||
|
vv = kin_nSpecies(kin); break;
|
||||||
|
default:
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
|
||||||
|
double *h = mxGetPr(plhs[0]);
|
||||||
|
*h = vv;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
Cantera/matlab/cantera/@Kinetics/private/kin_set.cpp
Executable file
47
Cantera/matlab/cantera/@Kinetics/private/kin_set.cpp
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
#include "mex.h"
|
||||||
|
#include "../../private/ctmatutils.h"
|
||||||
|
#include "../../../../clib/src/ct.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
void reportError() {
|
||||||
|
int buflen = 300;
|
||||||
|
char* output_buf = (char*)mxCalloc(buflen, sizeof(char));
|
||||||
|
getCanteraError(buflen, output_buf);
|
||||||
|
mexErrMsgTxt(output_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mexFunction( int nlhs, mxArray *plhs[],
|
||||||
|
int nrhs, const mxArray *prhs[] ) {
|
||||||
|
// try {
|
||||||
|
double vv;
|
||||||
|
int kin = getInt(prhs[0]);
|
||||||
|
int job = getInt(prhs[1]);
|
||||||
|
int irxn = getInt(prhs[2]);
|
||||||
|
double* ptr = mxGetPr(prhs[3]);
|
||||||
|
int m = mxGetM(prhs[3]);
|
||||||
|
int n = mxGetN(prhs[3]);
|
||||||
|
|
||||||
|
// set scalar attributes
|
||||||
|
int iok = -1;
|
||||||
|
if (job < 10) {
|
||||||
|
if (m != 1 || n != 1)
|
||||||
|
mexErrMsgTxt("value must be scalar.");
|
||||||
|
|
||||||
|
switch (job) {
|
||||||
|
case 1:
|
||||||
|
iok = kin_setMultiplier(kin,irxn-1,*ptr); break;
|
||||||
|
default:
|
||||||
|
iok = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (iok < 0) mexErrMsgTxt("error in kin_set.");
|
||||||
|
// }
|
||||||
|
//catch (...) {
|
||||||
|
// reportError();
|
||||||
|
// mexErrMsgTxt("exception in kin_set.");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
14
Cantera/matlab/cantera/@Kinetics/private/kinetics_get.m
Normal file
14
Cantera/matlab/cantera/@Kinetics/private/kinetics_get.m
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
function v = kinetics_get(n, job, a, b, c, d)
|
||||||
|
% KINETICS_GET - get kinetics attributes
|
||||||
|
%
|
||||||
|
if nargin == 2
|
||||||
|
v = ctmethods(40, n, job);
|
||||||
|
elseif nargin == 3
|
||||||
|
v = ctmethods(40, n, job, a);
|
||||||
|
elseif nargin == 4
|
||||||
|
v = ctmethods(40, n, job, a, b);
|
||||||
|
elseif nargin == 5
|
||||||
|
v = ctmethods(40, n, job, a, b, c);
|
||||||
|
elseif nargin == 6
|
||||||
|
v = ctmethods(40, n, job, a, b, c, d);
|
||||||
|
end
|
6
Cantera/matlab/cantera/@Kinetics/private/kinetics_set.m
Normal file
6
Cantera/matlab/cantera/@Kinetics/private/kinetics_set.m
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
function kinetics_set(n, job, a, b)
|
||||||
|
% KINETICS_SET - get kinetics attributes
|
||||||
|
%
|
||||||
|
ctmethods(40, n, -job, a, b)
|
||||||
|
|
||||||
|
|
33
Cantera/matlab/cantera/@Kinetics/private/newkinetics.cpp
Executable file
33
Cantera/matlab/cantera/@Kinetics/private/newkinetics.cpp
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
#include "mex.h"
|
||||||
|
#include "../../../../clib/src/ct.h"
|
||||||
|
#include "../../private/ctmatutils.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a Cantera 'Kinetics' object
|
||||||
|
*/
|
||||||
|
void mexFunction( int nlhs, mxArray *plhs[],
|
||||||
|
int nrhs, const mxArray *prhs[] )
|
||||||
|
{
|
||||||
|
// Check for proper number of arguments
|
||||||
|
if(nrhs != 4) {
|
||||||
|
mexErrMsgTxt("Four inputs required.");
|
||||||
|
}
|
||||||
|
else if(nlhs > 1) {
|
||||||
|
mexErrMsgTxt("Too many output arguments");
|
||||||
|
}
|
||||||
|
|
||||||
|
int root = getInt(prhs[0]);
|
||||||
|
int iph = getInt(prhs[1]);
|
||||||
|
int in1 = getInt(prhs[2]);
|
||||||
|
int in2 = getInt(prhs[3]);
|
||||||
|
int n = newKineticsFromXML(root, iph, in1, in2);
|
||||||
|
|
||||||
|
// Create matrix for the return argument.
|
||||||
|
plhs[0] = mxCreateDoubleMatrix(1,1, mxREAL);
|
||||||
|
double* x = mxGetPr(plhs[0]);
|
||||||
|
*x = n;
|
||||||
|
}
|
||||||
|
}
|
32
Cantera/matlab/cantera/@Kinetics/private/production.cpp
Executable file
32
Cantera/matlab/cantera/@Kinetics/private/production.cpp
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
#include "mex.h"
|
||||||
|
#include "../../../../clib/src/ct.h"
|
||||||
|
#include "../../private/ctmatutils.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
void mexFunction( int nlhs, mxArray *plhs[],
|
||||||
|
int nrhs, const mxArray *prhs[] )
|
||||||
|
{
|
||||||
|
int kin = getInt(prhs[0]);
|
||||||
|
int nsp = getInt(prhs[1]);
|
||||||
|
int job = getInt(prhs[2]);
|
||||||
|
plhs[0] = mxCreateNumericMatrix(nsp,1,mxDOUBLE_CLASS,mxREAL);
|
||||||
|
double *h = mxGetPr(plhs[0]);
|
||||||
|
int ok = -10;
|
||||||
|
switch (job) {
|
||||||
|
case 0:
|
||||||
|
ok = kin_getCreationRates(kin,nsp,h); break;
|
||||||
|
case 1:
|
||||||
|
ok = kin_getDestructionRates(kin,nsp,h); break;
|
||||||
|
case 2:
|
||||||
|
ok = kin_getNetProductionRates(kin,nsp,h); break;
|
||||||
|
case 3:
|
||||||
|
ok = kin_getSourceTerms(kin, nsp, h); break;
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
if (ok < 0)
|
||||||
|
mexErrMsgTxt("error computing production rates");
|
||||||
|
}
|
||||||
|
}
|
20
Cantera/matlab/cantera/@Kinetics/private/pstoich.cpp
Executable file
20
Cantera/matlab/cantera/@Kinetics/private/pstoich.cpp
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
#include "mex.h"
|
||||||
|
#include "../../../../clib/src/ct.h"
|
||||||
|
#include "../../private/ctmatutils.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
void mexFunction( int nlhs, mxArray *plhs[],
|
||||||
|
int nrhs, const mxArray *prhs[] )
|
||||||
|
{
|
||||||
|
double vv;
|
||||||
|
int kin = getInt(prhs[0]);
|
||||||
|
int isp = getInt(prhs[1]);
|
||||||
|
int irxn = getInt(prhs[2]);
|
||||||
|
vv = kin_productStoichCoeff(kin,irxn-1,isp-1);
|
||||||
|
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
|
||||||
|
double *h = mxGetPr(plhs[0]);
|
||||||
|
*h = vv;
|
||||||
|
}
|
||||||
|
}
|
32
Cantera/matlab/cantera/@Kinetics/private/rop.cpp
Executable file
32
Cantera/matlab/cantera/@Kinetics/private/rop.cpp
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
#include "mex.h"
|
||||||
|
#include "../../../../clib/src/ct.h"
|
||||||
|
#include "../../private/ctmatutils.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
void mexFunction( int nlhs, mxArray *plhs[],
|
||||||
|
int nrhs, const mxArray *prhs[] )
|
||||||
|
{
|
||||||
|
int kin = getInt(prhs[0]);
|
||||||
|
int job = getInt(prhs[1]);
|
||||||
|
int nr = kin_nReactions(kin);
|
||||||
|
plhs[0] = mxCreateNumericMatrix(nr,1,mxDOUBLE_CLASS,mxREAL);
|
||||||
|
double *h = mxGetPr(plhs[0]);
|
||||||
|
int ok = -10;
|
||||||
|
switch (job) {
|
||||||
|
case 0:
|
||||||
|
ok = kin_getFwdRatesOfProgress(kin,nr,h); break;
|
||||||
|
case 1:
|
||||||
|
ok = kin_getRevRatesOfProgress(kin,nr,h); break;
|
||||||
|
case 2:
|
||||||
|
ok = kin_getNetRatesOfProgress(kin,nr,h); break;
|
||||||
|
case 3:
|
||||||
|
ok = kin_getEquilibriumConstants(kin,nr,h); break;
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
if (ok < 0)
|
||||||
|
mexErrMsgTxt("error computing rates of progress");
|
||||||
|
}
|
||||||
|
}
|
20
Cantera/matlab/cantera/@Kinetics/private/rstoich.cpp
Executable file
20
Cantera/matlab/cantera/@Kinetics/private/rstoich.cpp
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
#include "mex.h"
|
||||||
|
#include "../../../../clib/src/ct.h"
|
||||||
|
#include "../../private/ctmatutils.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
void mexFunction( int nlhs, mxArray *plhs[],
|
||||||
|
int nrhs, const mxArray *prhs[] )
|
||||||
|
{
|
||||||
|
double vv;
|
||||||
|
int kin = getInt(prhs[0]);
|
||||||
|
int isp = getInt(prhs[1]);
|
||||||
|
int irxn = getInt(prhs[2]);
|
||||||
|
vv = kin_reactantStoichCoeff(kin,irxn-1,isp-1);
|
||||||
|
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
|
||||||
|
double *h = mxGetPr(plhs[0]);
|
||||||
|
*h = vv;
|
||||||
|
}
|
||||||
|
}
|
25
Cantera/matlab/cantera/@Kinetics/private/rxnstring.cpp
Executable file
25
Cantera/matlab/cantera/@Kinetics/private/rxnstring.cpp
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
#include "mex.h"
|
||||||
|
#include "../../../../clib/src/ct.h"
|
||||||
|
#include "../../private/ctmatutils.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
void mexFunction( int nlhs, mxArray *plhs[],
|
||||||
|
int nrhs, const mxArray *prhs[] )
|
||||||
|
{
|
||||||
|
int kin = getInt(prhs[0]);
|
||||||
|
int irxn = getInt(prhs[1]);
|
||||||
|
char* buf;
|
||||||
|
int buflen = 80;
|
||||||
|
buf = (char*)mxCalloc(buflen, sizeof(char));
|
||||||
|
int iok = kin_getReactionString(kin, irxn-1, buflen, buf);
|
||||||
|
if (iok >= 0) {
|
||||||
|
plhs[0] = mxCreateString(buf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mexErrMsgTxt("error getting reaction string");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
Cantera/matlab/cantera/@Kinetics/reactionEqn.m
Executable file
29
Cantera/matlab/cantera/@Kinetics/reactionEqn.m
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
function e = reactionEqn(a, irxn)
|
||||||
|
% reactionEqn Reaction equation of reaction irxn.
|
||||||
|
%
|
||||||
|
if nargin == 1
|
||||||
|
m = nReactions(a);
|
||||||
|
n = 1;
|
||||||
|
irxn = [1:m]';
|
||||||
|
elseif nargin == 2
|
||||||
|
if isa(irxn,'double')
|
||||||
|
[m, n] = size(irxn);
|
||||||
|
else
|
||||||
|
error('reaction number(s) must be numeric');
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if m == 1 & n == 1
|
||||||
|
e = kinetics_get(a.id, 31, irxn); % rxnstring(a.id, irxn);
|
||||||
|
else
|
||||||
|
e = {};
|
||||||
|
for i = 1:m
|
||||||
|
for j = 1:n
|
||||||
|
e{i,j} = kinetics_get(a.id, 31, irxn(i,j)); % rxnstring(a.id, irxn(i,j));
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
20
Cantera/matlab/cantera/@Kinetics/rop.m
Normal file
20
Cantera/matlab/cantera/@Kinetics/rop.m
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
function rop = rop(k)
|
||||||
|
% ROP - Forward and reverse rates of progress.
|
||||||
|
%
|
||||||
|
% ROP(K) returns an M x 2 array of reaction rates of
|
||||||
|
% progress. The first column contains the forward rates of progress,
|
||||||
|
% and the second column the reverse rates. If this function
|
||||||
|
% is called with no output argument, a bar graph is produced.
|
||||||
|
%
|
||||||
|
f = rop_f(k)
|
||||||
|
r = rop_r(k)
|
||||||
|
rop = [f r]
|
||||||
|
if nargout == 0
|
||||||
|
figure
|
||||||
|
set(gcf,'Name','Rates of Progress');
|
||||||
|
bar(rop);
|
||||||
|
xlabel('Reaction Number');
|
||||||
|
ylabel('Rate of Progress [kmol/m^3-s]');
|
||||||
|
title('Rates of Progress');
|
||||||
|
legend('Forward', 'Reverse');
|
||||||
|
end
|
20
Cantera/matlab/cantera/@Kinetics/rop_f.m
Executable file
20
Cantera/matlab/cantera/@Kinetics/rop_f.m
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
function q = rop_f(a)
|
||||||
|
% ROP_F Forward rates of progress for all reactions.
|
||||||
|
%
|
||||||
|
% Q = ROP_F(K)
|
||||||
|
%
|
||||||
|
% Returns a column vector of the forward rates of progress
|
||||||
|
% for all reactions.
|
||||||
|
%
|
||||||
|
% See also: rop_r, rop_net.
|
||||||
|
%
|
||||||
|
q = kinetics_get(a.id,11,0);
|
||||||
|
if nargout == 0
|
||||||
|
figure
|
||||||
|
set(gcf,'Name','Rates of Progress')
|
||||||
|
bar(q)
|
||||||
|
xlabel('Reaction Number')
|
||||||
|
ylabel('Forward Rate of Progress [kmol/m^3]')
|
||||||
|
title('Forward Rates of Progress')
|
||||||
|
end
|
||||||
|
|
20
Cantera/matlab/cantera/@Kinetics/rop_net.m
Executable file
20
Cantera/matlab/cantera/@Kinetics/rop_net.m
Executable file
@ -0,0 +1,20 @@
|
|||||||
|
function q = rop_net(a)
|
||||||
|
% ROP_F Forward rates of progress for all reactions.
|
||||||
|
%
|
||||||
|
% Q = ROP_F(K)
|
||||||
|
%
|
||||||
|
% Returns a column vector of the forward rates of progress
|
||||||
|
% for all reactions.
|
||||||
|
%
|
||||||
|
% See also: rop_r, rop_net.
|
||||||
|
%
|
||||||
|
q = kinetics_get(a.id,13,0);
|
||||||
|
if nargout == 0
|
||||||
|
figure
|
||||||
|
set(gcf,'Name','Rates of Progress')
|
||||||
|
bar(q)
|
||||||
|
xlabel('Reaction Number')
|
||||||
|
ylabel('Net Rate of Progress [kmol/m^3]')
|
||||||
|
title('Net Rates of Progress')
|
||||||
|
end
|
||||||
|
|
13
Cantera/matlab/cantera/@Kinetics/rop_r.m
Executable file
13
Cantera/matlab/cantera/@Kinetics/rop_r.m
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
function q = rop_r(a)
|
||||||
|
% ROP_R Reverse rates of progress for all reactions.
|
||||||
|
%
|
||||||
|
% Q = ROP_R(K)
|
||||||
|
%
|
||||||
|
% Returns a column vector of the reverse rates of progress
|
||||||
|
% for all reactions. The value is zero for irreversible
|
||||||
|
% reactions.
|
||||||
|
%
|
||||||
|
% See also: rop_r, rop_net.
|
||||||
|
%
|
||||||
|
q = kinetics_get(a.id,12,0);
|
||||||
|
|
29
Cantera/matlab/cantera/@Kinetics/rxnEqs.m
Executable file
29
Cantera/matlab/cantera/@Kinetics/rxnEqs.m
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
function e = rxnEqs(a, irxn)
|
||||||
|
% rxnEqs
|
||||||
|
%
|
||||||
|
if nargin == 1
|
||||||
|
m = nReactions(a);
|
||||||
|
n = 1;
|
||||||
|
irxn = [1:m]'
|
||||||
|
elseif nargin == 2
|
||||||
|
if isa(irxn,'double')
|
||||||
|
[m, n] = size(irxn);
|
||||||
|
else
|
||||||
|
error('reaction number(s) must be numeric');
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if m == 1 & n == 1
|
||||||
|
e = rxnstring(a.id, irxn);
|
||||||
|
else
|
||||||
|
e = {};
|
||||||
|
for i = 1:m
|
||||||
|
for j = 1:n
|
||||||
|
e{i,j} = rxnstring(a.id, irxn(i,j));
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
10
Cantera/matlab/cantera/@Kinetics/setMultiplier.m
Executable file
10
Cantera/matlab/cantera/@Kinetics/setMultiplier.m
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
function setMultiplier(a,i,v)
|
||||||
|
% SETMULTIPLIER Set the rate of progress multiplier.
|
||||||
|
%
|
||||||
|
% SETMULTIPLIER(K, IRXN, V) sets the multipler for reaction IRXN
|
||||||
|
% to value V.
|
||||||
|
%
|
||||||
|
% see also: MULTIPLIER
|
||||||
|
%
|
||||||
|
kinetics_set(a.id,1,i,v);
|
||||||
|
|
30
Cantera/matlab/cantera/@Kinetics/stoich_net.m
Executable file
30
Cantera/matlab/cantera/@Kinetics/stoich_net.m
Executable file
@ -0,0 +1,30 @@
|
|||||||
|
function nu = stoich_net(a,species,rxns)
|
||||||
|
% stoich_net Net stoichiometric coefficients.
|
||||||
|
%
|
||||||
|
% nu = stoich_net(a)
|
||||||
|
%
|
||||||
|
% Returns a sparse matrix of all net (product - reactant)
|
||||||
|
% stoichiometric coefficients. The matrix element nu(k,i) is the
|
||||||
|
% net stoichiometric coefficient of species k in reaction i.
|
||||||
|
%
|
||||||
|
% nu = stoich_net(a, species, rxns)
|
||||||
|
%
|
||||||
|
% Returns a sparse matrix the same size as above, but
|
||||||
|
% containing only entries for the specified species and
|
||||||
|
% reactions. For example, stoich_net(a,3,[1 3 5 7]) returns a
|
||||||
|
% sparse matrix containing only the coefficients for species 3
|
||||||
|
% in reactions 1, 3, 5, and 7.
|
||||||
|
%
|
||||||
|
% Note that the net stoichiometric coefficients may be negative,
|
||||||
|
% unlike the reactant or product stoichiometric coefficients.
|
||||||
|
%
|
||||||
|
% See also: stoich_r, stoich_p.
|
||||||
|
%
|
||||||
|
if nargin == 1
|
||||||
|
nu = stoich_p(a) - stoich_r(a)
|
||||||
|
elseif nargin == 3
|
||||||
|
nu = stoich_p(a,species,rxns) - stoich_r(a,species,rxns);
|
||||||
|
else
|
||||||
|
error(['syntax error. Type ''help stoich_net'' for more' ...
|
||||||
|
' information.'])
|
||||||
|
end
|
43
Cantera/matlab/cantera/@Kinetics/stoich_p.m
Executable file
43
Cantera/matlab/cantera/@Kinetics/stoich_p.m
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
function nu_p = stoich_p(a,species,rxns)
|
||||||
|
% stoich_p Product stoichiometric coefficients.
|
||||||
|
%
|
||||||
|
% nu = stoich_p(a)
|
||||||
|
%
|
||||||
|
% Returns a sparse matrix of all product stoichiometric
|
||||||
|
% coefficients. The matrix element nu(k,i) is the
|
||||||
|
% stoichiometric coefficient of species k as a product in
|
||||||
|
% reaction i.
|
||||||
|
%
|
||||||
|
% nu = stoich_p(a, species, rxns)
|
||||||
|
%
|
||||||
|
% Returns a sparse matrix the same size as above, but
|
||||||
|
% containing only entries for the specified species and
|
||||||
|
% reactions. For example, stoich_p(a,3,[1 3 5 7]) returns a
|
||||||
|
% sparse matrix containing only the coefficients for species 3
|
||||||
|
% in reactions 1, 3, 5, and 7.
|
||||||
|
%
|
||||||
|
% See also: stoich_r, stoich_net.
|
||||||
|
%
|
||||||
|
nsp = nTotalSpecies(a);
|
||||||
|
nr =nReactions(a);
|
||||||
|
b = sparse(nsp,nr);
|
||||||
|
f = @kinetics_get;
|
||||||
|
if nargin == 1
|
||||||
|
kvals = 1:nsp;
|
||||||
|
ivals = 1:nr;
|
||||||
|
elseif nargin == 3
|
||||||
|
kvals = species;
|
||||||
|
ivals = rxns;
|
||||||
|
else
|
||||||
|
error('Syntax error. type ''help stoich_r'' for more information.')
|
||||||
|
end
|
||||||
|
|
||||||
|
for k = kvals
|
||||||
|
for i = ivals
|
||||||
|
nu = feval(f,a.id,6,i,k);
|
||||||
|
if nu ~= 0.0
|
||||||
|
b(k,i) = nu;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
nu_p = b;
|
43
Cantera/matlab/cantera/@Kinetics/stoich_r.m
Executable file
43
Cantera/matlab/cantera/@Kinetics/stoich_r.m
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
function nu_r = stoich_r(a,species,rxns)
|
||||||
|
% stoich_r Reactant stoichiometric coefficients.
|
||||||
|
%
|
||||||
|
% nu = stoich_r(a)
|
||||||
|
%
|
||||||
|
% Returns a sparse matrix of all reactant stoichiometric
|
||||||
|
% coefficients. The matrix element nu(k,i) is the
|
||||||
|
% stoichiometric coefficient of species k as a reactant in
|
||||||
|
% reaction i.
|
||||||
|
%
|
||||||
|
% nu = stoich_r(a, species, rxns)
|
||||||
|
%
|
||||||
|
% Returns a sparse matrix the same size as above, but
|
||||||
|
% containing only entries for the specified species and
|
||||||
|
% reactions. For example, stoich_r(a,3,[1 3 5 7]) returns a
|
||||||
|
% sparse matrix containing only the coefficients for species 3
|
||||||
|
% in reactions 1, 3, 5, and 7.
|
||||||
|
%
|
||||||
|
% See also: stoich_p, stoich_net.
|
||||||
|
%
|
||||||
|
nsp = nTotalSpecies(a);
|
||||||
|
nr =nReactions(a);
|
||||||
|
b = sparse(nsp,nr);
|
||||||
|
f = @kinetics_get;
|
||||||
|
if nargin == 1
|
||||||
|
kvals = 1:nsp;
|
||||||
|
ivals = 1:nr;
|
||||||
|
elseif nargin == 3
|
||||||
|
kvals = species;
|
||||||
|
ivals = rxns;
|
||||||
|
else
|
||||||
|
error('Syntax error. type ''help stoich_r'' for more information.')
|
||||||
|
end
|
||||||
|
|
||||||
|
for k = kvals
|
||||||
|
for i = ivals
|
||||||
|
nu = feval(f,a.id,5,i,k);
|
||||||
|
if nu ~= 0.0
|
||||||
|
b(k,i) = nu;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
nu_r = b;
|
4
Cantera/matlab/cantera/@Kinetics/ydot.m
Executable file
4
Cantera/matlab/cantera/@Kinetics/ydot.m
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
function v = ydot(a)
|
||||||
|
% YDOT - Evaluates wdot_k M_k / (density)
|
||||||
|
%
|
||||||
|
v = kinetics_get(a.id,24,0);
|
35
Cantera/matlab/cantera/@Reactor/Reactor.m
Normal file
35
Cantera/matlab/cantera/@Reactor/Reactor.m
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
function x = Reactor(contents, typ)
|
||||||
|
% REACTOR - Create a Reactor object.
|
||||||
|
%
|
||||||
|
% A Reactor object simulates a perfectly-stirred reactor. It has
|
||||||
|
% a time-dependent state, and may be coupled to other reactors
|
||||||
|
% through flow lines or through walls that may expand or
|
||||||
|
% contract and/or conduct heat.
|
||||||
|
%
|
||||||
|
% r1 = Reactor % an empty reactor
|
||||||
|
% r2 = Reactor(gas) % a reactor containing a gas
|
||||||
|
%
|
||||||
|
% See also: Reservoir
|
||||||
|
%
|
||||||
|
if nargin == 0
|
||||||
|
contents = 0;
|
||||||
|
typ = 1;
|
||||||
|
elseif nargin == 1
|
||||||
|
typ = 1;
|
||||||
|
elseif nargin > 2
|
||||||
|
error('too many arguments');
|
||||||
|
end
|
||||||
|
|
||||||
|
x.index = reactormethods(0,typ);
|
||||||
|
if x.index < 0
|
||||||
|
error(geterr);
|
||||||
|
end
|
||||||
|
x.contents = contents;
|
||||||
|
x = class(x,'Reactor');
|
||||||
|
|
||||||
|
if isa(contents,'Solution')
|
||||||
|
insert(x, contents);
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
22
Cantera/matlab/cantera/@Reactor/advance.m
Normal file
22
Cantera/matlab/cantera/@Reactor/advance.m
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
function advance(r, tout)
|
||||||
|
% ADVANCE - Advance the state of the reactor in time.
|
||||||
|
%
|
||||||
|
% Method advance integrates the system of ordinary differential
|
||||||
|
% equations that determine the rate of change of the reactor
|
||||||
|
% volume, the mass of each species, and the total energy. The
|
||||||
|
% integration is carried out from the current reactor time to time
|
||||||
|
% 'tout.' (Note 'tout' is an absolute time, not a time interval.) The
|
||||||
|
% integrator may take many internal time steps before reaching
|
||||||
|
% tout.
|
||||||
|
%
|
||||||
|
% for i in 1:10
|
||||||
|
% tout = 0.1*i
|
||||||
|
% advance(r, tout)
|
||||||
|
% ...
|
||||||
|
% <add output commands here>
|
||||||
|
% ...
|
||||||
|
% end
|
||||||
|
%
|
||||||
|
% See also: Reactor/step
|
||||||
|
%
|
||||||
|
reactormethods(8, reactor_hndl(r), tout);
|
5
Cantera/matlab/cantera/@Reactor/clear.m
Normal file
5
Cantera/matlab/cantera/@Reactor/clear.m
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function clear(r)
|
||||||
|
% CLEAR -
|
||||||
|
%
|
||||||
|
reactormethods(2, reactor_hndl(r));
|
||||||
|
|
4
Cantera/matlab/cantera/@Reactor/density.m
Normal file
4
Cantera/matlab/cantera/@Reactor/density.m
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
function rho = density(r)
|
||||||
|
% DENSITY - density
|
||||||
|
%
|
||||||
|
rho = reactormethods(25, reactor_hndl(r));
|
12
Cantera/matlab/cantera/@Reactor/enthalpy_mass.m
Normal file
12
Cantera/matlab/cantera/@Reactor/enthalpy_mass.m
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
function h = enthalpy_mass(r)
|
||||||
|
% ENTHALPY_MASS - the specific enthalpy [J/kg].
|
||||||
|
%
|
||||||
|
% h = enthalpy_mass(r)
|
||||||
|
%
|
||||||
|
% returns the specific enthalpy of the reactor contents at the
|
||||||
|
% end of the last call to 'advance' or 'step.'
|
||||||
|
%
|
||||||
|
% See also: Reactor/intEnergy_mass, Reactor/entropy_mass,
|
||||||
|
% Reactor/enthalpy_mole
|
||||||
|
%
|
||||||
|
h = reactormethods(27, reactor_hndl(r));
|
2
Cantera/matlab/cantera/@Reactor/hndl.m
Normal file
2
Cantera/matlab/cantera/@Reactor/hndl.m
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
function i = hndl(r)
|
||||||
|
i = r.index;
|
8
Cantera/matlab/cantera/@Reactor/insert.m
Normal file
8
Cantera/matlab/cantera/@Reactor/insert.m
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
function insert(r, gas)
|
||||||
|
% INSERT - insert a mixture into the reactor
|
||||||
|
%
|
||||||
|
r.contents = gas;
|
||||||
|
setThermoMgr(r, gas);
|
||||||
|
setKineticsMgr(r, gas);
|
||||||
|
|
||||||
|
|
12
Cantera/matlab/cantera/@Reactor/intEnergy_mass.m
Normal file
12
Cantera/matlab/cantera/@Reactor/intEnergy_mass.m
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
function u = intEnergy_mass(r)
|
||||||
|
% INTENERGY_MASS - the specific internal energy [J/kg].
|
||||||
|
%
|
||||||
|
% u = intEnergy_mass(r)
|
||||||
|
%
|
||||||
|
% returns the specific internal energy of the reactor contents at
|
||||||
|
% the end of the last call to 'advance' or 'step.'
|
||||||
|
%
|
||||||
|
% See also: Reactor/enthalpy_mass, Reactor/entropy_mass,
|
||||||
|
% Reactor/enthalpy_mole
|
||||||
|
%
|
||||||
|
u = reactormethods(28, reactor_hndl(r));
|
5
Cantera/matlab/cantera/@Reactor/mass.m
Normal file
5
Cantera/matlab/cantera/@Reactor/mass.m
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function m = mass(r)
|
||||||
|
% MASS -
|
||||||
|
%
|
||||||
|
reactormethods(23, reactor_hndl(r));
|
||||||
|
|
5
Cantera/matlab/cantera/@Reactor/massFraction.m
Normal file
5
Cantera/matlab/cantera/@Reactor/massFraction.m
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function y = massFraction(r, species)
|
||||||
|
% MASSFRACTION - Mass fraction of species with name 'species'.
|
||||||
|
%
|
||||||
|
k = speciesIndex(r.contents, species) - 1;
|
||||||
|
y = reactormethods(30, reactor_hndl(r), k);
|
11
Cantera/matlab/cantera/@Reactor/massFractions.m
Normal file
11
Cantera/matlab/cantera/@Reactor/massFractions.m
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
function y = massFractions(r)
|
||||||
|
% MASSFRACTION - Mass fractions of reactor contents after last call
|
||||||
|
% to 'advance' or 'step'.
|
||||||
|
%
|
||||||
|
nsp = nSpecies(r.contents)
|
||||||
|
ir = reactor_hndl(r)
|
||||||
|
for k = 1:nsp
|
||||||
|
yy(k) = reactormethods(30, ir, k-1);
|
||||||
|
end
|
||||||
|
y = yy
|
||||||
|
|
4
Cantera/matlab/cantera/@Reactor/pressure.m
Normal file
4
Cantera/matlab/cantera/@Reactor/pressure.m
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
function p = pressure(r)
|
||||||
|
% PRESSURE - pressure
|
||||||
|
%
|
||||||
|
p = reactormethods(29, reactor_hndl(r));
|
130
Cantera/matlab/cantera/@Reactor/private/reactormethods.cpp
Normal file
130
Cantera/matlab/cantera/@Reactor/private/reactormethods.cpp
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
|
||||||
|
#include "mex.h"
|
||||||
|
#include "../../../../clib/src/ctreactor.h"
|
||||||
|
#include "../../../../clib/src/ct.h"
|
||||||
|
#include "../../private/ctmatutils.h"
|
||||||
|
|
||||||
|
const double Undef = -999.123;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
|
||||||
|
void reportError() {
|
||||||
|
int buflen = 300;
|
||||||
|
char* output_buf = (char*)mxCalloc(buflen, sizeof(char));
|
||||||
|
getCanteraError(buflen, output_buf);
|
||||||
|
mexErrMsgTxt(output_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void mexFunction( int nlhs, mxArray *plhs[],
|
||||||
|
int nrhs, const mxArray *prhs[] )
|
||||||
|
{
|
||||||
|
int j, m, iok, n;
|
||||||
|
char *file, *key, *val;
|
||||||
|
|
||||||
|
int job = getInt(prhs[0]);
|
||||||
|
int i = getInt(prhs[1]);
|
||||||
|
|
||||||
|
double r = Undef;
|
||||||
|
double v = Undef;
|
||||||
|
if (nrhs > 2) v = getDouble(prhs[2]);
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
if (job == 0) {
|
||||||
|
n = reactor_new(i);
|
||||||
|
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
|
||||||
|
double *h = mxGetPr(plhs[0]);
|
||||||
|
*h = double(n);
|
||||||
|
if (n < 0) reportError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// options that do not return a value
|
||||||
|
|
||||||
|
if (job < 20) {
|
||||||
|
switch (job) {
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
iok = reactor_del(i);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
iok = reactor_copy(i);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
iok = reactor_assign(i,int(v));
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
iok = reactor_setInitialVolume(i, v);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
iok = reactor_setInitialTime(i, v);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
iok = reactor_setThermoMgr(i, int(v));
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
iok = reactor_setKineticsMgr(i, int(v));
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
iok = reactor_advance(i, v);
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
iok = reactor_setEnergy(i, int(v));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mexErrMsgTxt("unknown job parameter");
|
||||||
|
}
|
||||||
|
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
|
||||||
|
double *h = mxGetPr(plhs[0]);
|
||||||
|
*h = double(iok);
|
||||||
|
if (iok < 0) reportError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// options that return a value of type 'double'
|
||||||
|
|
||||||
|
else if (job < 40) {
|
||||||
|
switch (job) {
|
||||||
|
case 21:
|
||||||
|
r = reactor_step(i, v);
|
||||||
|
break;
|
||||||
|
case 22:
|
||||||
|
r = reactor_time(i);
|
||||||
|
break;
|
||||||
|
case 23:
|
||||||
|
r = reactor_mass(i);
|
||||||
|
break;
|
||||||
|
case 24:
|
||||||
|
r = reactor_volume(i);
|
||||||
|
break;
|
||||||
|
case 25:
|
||||||
|
r = reactor_density(i);
|
||||||
|
break;
|
||||||
|
case 26:
|
||||||
|
r = reactor_temperature(i);
|
||||||
|
break;
|
||||||
|
case 27:
|
||||||
|
r = reactor_enthalpy_mass(i);
|
||||||
|
break;
|
||||||
|
case 28:
|
||||||
|
r = reactor_intEnergy_mass(i);
|
||||||
|
break;
|
||||||
|
case 29:
|
||||||
|
r = reactor_pressure(i);
|
||||||
|
break;
|
||||||
|
case 30:
|
||||||
|
r = reactor_massFraction(i, int(v));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mexErrMsgTxt("unknown job parameter");
|
||||||
|
}
|
||||||
|
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
|
||||||
|
double *h = mxGetPr(plhs[0]);
|
||||||
|
*h = r;
|
||||||
|
if (r == Undef) reportError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
Cantera/matlab/cantera/@Reactor/private/reactormethods.m
Normal file
13
Cantera/matlab/cantera/@Reactor/private/reactormethods.m
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
function v = reactormethods(n, job, a, b, c, d)
|
||||||
|
%
|
||||||
|
if nargin == 2
|
||||||
|
v = ctmethods(60, n, job);
|
||||||
|
elseif nargin == 3
|
||||||
|
v = ctmethods(60, n, job, a);
|
||||||
|
elseif nargin == 4
|
||||||
|
v = ctmethods(60, n, job, a, b);
|
||||||
|
elseif nargin == 5
|
||||||
|
v = ctmethods(60, n, job, a, b, c);
|
||||||
|
elseif nargin == 6
|
||||||
|
v = ctmethods(60, n, job, a, b, c, d);
|
||||||
|
end
|
2
Cantera/matlab/cantera/@Reactor/reactor_hndl.m
Normal file
2
Cantera/matlab/cantera/@Reactor/reactor_hndl.m
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
function i = reactor_hndl(r)
|
||||||
|
i = r.index;
|
8
Cantera/matlab/cantera/@Reactor/setEnergy.m
Normal file
8
Cantera/matlab/cantera/@Reactor/setEnergy.m
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
function setEnergy(f, flag)
|
||||||
|
% SETENERGY -
|
||||||
|
%
|
||||||
|
iflag = 0
|
||||||
|
if flag = 'on'
|
||||||
|
iflag = 1
|
||||||
|
end
|
||||||
|
reactormethods(9, f.index, iflag)
|
5
Cantera/matlab/cantera/@Reactor/setInitialTime.m
Normal file
5
Cantera/matlab/cantera/@Reactor/setInitialTime.m
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function setInitialTime(r, t0)
|
||||||
|
% SETINITIALTIME -
|
||||||
|
%
|
||||||
|
reactormethods(5, reactor_hndl(r), t0);
|
||||||
|
|
5
Cantera/matlab/cantera/@Reactor/setInitialVolume.m
Normal file
5
Cantera/matlab/cantera/@Reactor/setInitialVolume.m
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function setInitialVolume(r, t0)
|
||||||
|
% SETINITIALVOLUME -
|
||||||
|
%
|
||||||
|
reactormethods(4, reactor_hndl(r), t0);
|
||||||
|
|
9
Cantera/matlab/cantera/@Reactor/setKineticsMgr.m
Normal file
9
Cantera/matlab/cantera/@Reactor/setKineticsMgr.m
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
function setKineticsMgr(r, k)
|
||||||
|
% SETKINETICSMGR - set the kinetics manager
|
||||||
|
%
|
||||||
|
if ~isa(k,'Kinetics')
|
||||||
|
error('wrong object type');
|
||||||
|
end
|
||||||
|
|
||||||
|
reactormethods(7, reactor_hndl(r), kinetics_hndl(k));
|
||||||
|
|
9
Cantera/matlab/cantera/@Reactor/setThermoMgr.m
Normal file
9
Cantera/matlab/cantera/@Reactor/setThermoMgr.m
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
function setThermoMgr(r, t)
|
||||||
|
% SETTHERMOMGR - set the thermo manager
|
||||||
|
%
|
||||||
|
if ~isa(t,'ThermoPhase')
|
||||||
|
error('wrong object type');
|
||||||
|
end
|
||||||
|
|
||||||
|
reactormethods(6, reactor_hndl(r), thermo_hndl(t));
|
||||||
|
|
28
Cantera/matlab/cantera/@Reactor/step.m
Normal file
28
Cantera/matlab/cantera/@Reactor/step.m
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
function t = step(r, tout)
|
||||||
|
% STEP - Take one internal time step toward tout.
|
||||||
|
%
|
||||||
|
% The integrator used to integrate the ODEs (CVODE) takes
|
||||||
|
% variable-size steps, chosen so that a specified error
|
||||||
|
% tolerance is maintained. At times when the solution is rapidly
|
||||||
|
% changing, the time step becomes smaller to resolve the
|
||||||
|
% solution.
|
||||||
|
%
|
||||||
|
% Method 'step' takes one internal time step and returns. This
|
||||||
|
% can be useful when it is desired to resolve a rapidly-changing
|
||||||
|
% solution in the output file.
|
||||||
|
%
|
||||||
|
% This method can be used as follows:
|
||||||
|
%
|
||||||
|
% t = 0.0
|
||||||
|
% tout = 0.1
|
||||||
|
% while t < tout
|
||||||
|
% t = step(r, tout)
|
||||||
|
% ,,,
|
||||||
|
% <commands to save desired variables>
|
||||||
|
% ...
|
||||||
|
% end
|
||||||
|
%
|
||||||
|
% See also: Reactor/advance
|
||||||
|
%
|
||||||
|
t = reactormethods(21, reactor_hndl(r), tend);
|
||||||
|
|
5
Cantera/matlab/cantera/@Reactor/temperature.m
Normal file
5
Cantera/matlab/cantera/@Reactor/temperature.m
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function t = temperature(r)
|
||||||
|
% TEMPERATURE - temperature
|
||||||
|
%
|
||||||
|
t = reactormethods(26, reactor_hndl(r));
|
||||||
|
|
4
Cantera/matlab/cantera/@Reactor/time.m
Normal file
4
Cantera/matlab/cantera/@Reactor/time.m
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
function t = time(r)
|
||||||
|
% TIME - time
|
||||||
|
%
|
||||||
|
t = reactormethods(22, reactor_hndl(r));
|
4
Cantera/matlab/cantera/@Reactor/volume.m
Normal file
4
Cantera/matlab/cantera/@Reactor/volume.m
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
function v = volume(r)
|
||||||
|
% VOLUME - volume
|
||||||
|
%
|
||||||
|
v = reactormethods(24, reactor_hndl(r));
|
54
Cantera/matlab/cantera/@Solution/Solution.m
Executable file
54
Cantera/matlab/cantera/@Solution/Solution.m
Executable file
@ -0,0 +1,54 @@
|
|||||||
|
function s = Solution(x, r)
|
||||||
|
% SOLUTION - class Solution constructor.
|
||||||
|
%
|
||||||
|
% Class Solution represents solutions of multiple species. A
|
||||||
|
% solution is defined as a mixture of two or more constituents
|
||||||
|
% (species) that are completely mixed on molecular length
|
||||||
|
% scales. The macroscopic intensive thermodynamic state of a
|
||||||
|
% solution is specified by two thermodynamic properties (for
|
||||||
|
% example, the temperature and pressure), and the relative amounts
|
||||||
|
% of each species, which may be given as mole fractions or mass
|
||||||
|
% fractions.
|
||||||
|
|
||||||
|
% s = Solution('input.xml', <transport-model>)
|
||||||
|
%
|
||||||
|
% constructs a Solution object from a specification contained in
|
||||||
|
% file input.xml, and using a specified transport property
|
||||||
|
% model. If the transport model is omitted, it defaults to
|
||||||
|
% 'None', which disables transport property evaluation.
|
||||||
|
|
||||||
|
% Class Solution derives from three more basic classes, and most of
|
||||||
|
% its methods are inherited from these classes. These are:
|
||||||
|
%
|
||||||
|
% class ThermoPhase - composition information and
|
||||||
|
% thermodynamic properties
|
||||||
|
% class Kinetics - homogeneous kinetics
|
||||||
|
% class Transport - transport properties
|
||||||
|
%
|
||||||
|
% See also: ThermoPhase, Kinetics, Transport
|
||||||
|
%
|
||||||
|
if nargin == 1
|
||||||
|
trmodel = 'None';
|
||||||
|
elseif nargin == 2
|
||||||
|
trmodel = r;
|
||||||
|
else
|
||||||
|
error('wrong number of arguments');
|
||||||
|
end
|
||||||
|
|
||||||
|
if isa(x,'Solution')
|
||||||
|
s = x;
|
||||||
|
return
|
||||||
|
elseif isa(x,'XML_Node')
|
||||||
|
xp = x;
|
||||||
|
else
|
||||||
|
doc = XML_Node('doc', x);
|
||||||
|
xp = child(doc,'ctml/phase');
|
||||||
|
end
|
||||||
|
t = ThermoPhase(xp);
|
||||||
|
k = Kinetics(xp,t);
|
||||||
|
s.kin = k;
|
||||||
|
s.th = t;
|
||||||
|
tr = Transport(trmodel,t,4);
|
||||||
|
s.tr = tr;
|
||||||
|
s = class(s,'Solution',t,k,tr);
|
||||||
|
|
9
Cantera/matlab/cantera/@Solution/clear.m
Normal file
9
Cantera/matlab/cantera/@Solution/clear.m
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
function clear(s)
|
||||||
|
% CLEAR - Delete the kernel object.
|
||||||
|
%
|
||||||
|
clear(s.th);
|
||||||
|
clear(s.kin);
|
||||||
|
disp('Solution.clear: skipping clearing the transport object... check this!')
|
||||||
|
%clear(s.tr);
|
||||||
|
|
||||||
|
|
22
Cantera/matlab/cantera/@Solution/display.m
Executable file
22
Cantera/matlab/cantera/@Solution/display.m
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
function display(a)
|
||||||
|
|
||||||
|
s = [sprintf('\n temperature %12.6g K\n', temperature(a)) ...
|
||||||
|
sprintf(' pressure %12.6g Pa\n', pressure(a)) ...
|
||||||
|
sprintf(' density %12.6g kg/m^3\n', density(a)) ...
|
||||||
|
sprintf(' mean mol. weight %12.6g amu', ...
|
||||||
|
meanMolecularWeight(a))];
|
||||||
|
disp(s);
|
||||||
|
|
||||||
|
nsp = nSpecies(a);
|
||||||
|
x = moleFractions(a);
|
||||||
|
y = massFractions(a);
|
||||||
|
|
||||||
|
s = [...
|
||||||
|
sprintf('\n X Y \n') ...
|
||||||
|
sprintf(' ------------- ------------ ')];
|
||||||
|
disp(s);
|
||||||
|
|
||||||
|
for k = 1:nsp
|
||||||
|
disp(sprintf('%18s %12.6e %12.6e', char(speciesName(a,k)), x(k), y(k)));
|
||||||
|
end
|
||||||
|
disp(' ');
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user