├── .gitignore ├── Makefile ├── README.rst ├── das.h ├── daskr ├── LICENSE ├── Makefile ├── README ├── examples │ ├── dheat.f │ ├── dheat.out │ ├── dheatilu.f │ ├── dheatilu.out │ ├── dkrdem.f │ ├── dkrdem.out │ ├── dweb.f │ ├── dweb.out │ ├── dwebilu.f │ ├── dwebilu.out │ ├── makeddem │ ├── makedh │ ├── makedhilu │ ├── makedw │ ├── makedwilu │ ├── makesdem │ ├── makesh │ ├── makeshilu │ ├── makesw │ ├── makeswilu │ ├── sheat.f │ ├── sheatilu.f │ ├── skrdem.f │ ├── sweb.f │ └── swebilu.f ├── preconds │ ├── dbanpre.f │ ├── dilupre.f │ ├── drbdpre.f │ ├── drbgpre.f │ ├── dsparsk.f │ ├── sbanpre.f │ ├── silupre.f │ ├── srbdpre.f │ ├── srbgpre.f │ └── ssparsk.f └── solver │ ├── daux.f │ ├── ddaskr.f │ ├── dlinpk.f │ ├── saux.f │ ├── sdaskr.f │ └── slinpk.f ├── daspk.h ├── daspk ├── Makefile ├── README ├── examples │ ├── dheat.f │ ├── dheat.out │ ├── dheatilu.f │ ├── dheatilu.out │ ├── dweb.f │ ├── dweb.out │ ├── dwebilu.f │ ├── dwebilu.out │ ├── makedh │ ├── makedhilu │ ├── makedw │ ├── makedwilu │ ├── makesh │ ├── makeshilu │ ├── makesw │ ├── makeswilu │ ├── sheat.f │ ├── sheatilu.f │ ├── sweb.f │ └── swebilu.f ├── preconds │ ├── dbanpre.f │ ├── dilupre.f │ ├── drbdpre.f │ ├── drbgpre.f │ ├── dsparsk.f │ ├── sbanpre.f │ ├── silupre.f │ ├── srbdpre.f │ ├── srbgpre.f │ └── ssparsk.f └── solver │ ├── daux.f │ ├── ddaspk.f │ ├── dlinpk.f │ ├── saux.f │ ├── sdaspk.f │ └── slinpk.f ├── daspk31 ├── Makefile └── README ├── dassl ├── Makefile ├── daux.f ├── ddassl.f └── dlinpk.f ├── documentation ├── Makefile ├── make.bat └── source │ ├── _static │ └── default.css │ ├── _templates │ ├── index.html │ ├── indexsidebar.html │ └── layout.html │ ├── conf.py │ ├── contents.rst │ ├── developers │ └── index.rst │ └── users │ ├── cython.rst │ ├── images │ ├── diffusionPlot.pdf │ ├── diffusionPlot.png │ ├── rxnSeriesPlot.pdf │ └── rxnSeriesPlot.png │ ├── index.rst │ ├── installation.rst │ ├── introduction.rst │ └── tutorial.rst ├── examples ├── diffusion │ ├── cython │ │ ├── Makefile │ │ ├── diffusion.py │ │ ├── model.pyx │ │ ├── pydas.pxd │ │ └── setup.py │ └── python │ │ ├── diffusion.py │ │ └── model.py └── rxnSeries │ └── rxnSeries.py ├── make.bat ├── make.inc.example ├── pydas.pxd ├── pydas.pyx ├── pydasTest.py ├── pydaspk.pxd ├── pydaspk.pyx ├── pydaspkTest.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # 3 | # Files for git to ignore 4 | # 5 | ################################################################################ 6 | 7 | # Compiled documentation 8 | documentation/build/* 9 | 10 | # Compiled libraries 11 | *.a 12 | *.so 13 | *.lib 14 | *.pyd 15 | 16 | # Temporary build files 17 | build/* 18 | *.o 19 | *.obj 20 | *.c 21 | 22 | # HTML files (particularly those generated by Cython) 23 | *.html 24 | 25 | # Python bytecode 26 | *.pyc 27 | 28 | # make.inc (this file may vary significantly from platform to platform) 29 | make.inc 30 | 31 | # Eclipse project files 32 | /.project 33 | /.pydevproject 34 | /.settings 35 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # 3 | # Makefile for PyDAS 4 | # 5 | ################################################################################ 6 | 7 | F77=gfortran 8 | 9 | CYTHON_FLAGS=--inplace 10 | 11 | -include make.inc 12 | 13 | .PHONY: DASSL DASPK DASPK31 DASKR cython clean 14 | 15 | all: DASSL DASPK DASKR cython 16 | 17 | daspk: DASPK31 cython-daspk 18 | 19 | cython-daspk: 20 | python setup.py build_ext daspk $(CYTHON_FLAGS) 21 | 22 | cython: DASSL DASPK DASKR pydas.pyx 23 | python setup.py build_ext $(CYTHON_FLAGS) 24 | 25 | install: DASSL DASPK DASKR cython 26 | python setup.py install 27 | 28 | DASSL: 29 | $(MAKE) -C dassl F77=$(F77) 30 | 31 | DASPK: 32 | $(MAKE) -C daspk F77=$(F77) 33 | 34 | DASPK31: 35 | $(MAKE) -C daspk31 F77=$(F77) 36 | 37 | DASKR: 38 | $(MAKE) -C daskr F77=$(F77) 39 | 40 | clean: clean-DASSL clean-DASPK clean-DASPK31 clean-DASKR clean-cython 41 | rm -rf build 42 | 43 | clean-DASSL: 44 | $(MAKE) -C dassl clean 45 | 46 | clean-DASPK: 47 | $(MAKE) -C daspk clean 48 | 49 | clean-DASPK31: 50 | $(MAKE) -C daspk31 clean 51 | 52 | clean-DASKR: 53 | $(MAKE) -C daskr clean 54 | 55 | clean-cython: 56 | python setup.py clean $(CLEAN_FLAGS) 57 | rm -f *.so *.pyc *.c 58 | 59 | help: 60 | @echo "" 61 | @echo "This makefile can be used to build PyDAS and its dependencies." 62 | @echo "" 63 | @echo "Typing \`make\` with no arguments will compile all three DAE solvers (DASSL," 64 | @echo "DASPK, and DASKR) to static libraries and compile the PyDAS Python modules" 65 | @echo "that provide the Python interface to these solvers." 66 | @echo "" 67 | @echo "Typing \`make daspk\` after typing \`make\` will then additionally compile 68 | @echo "the optional DASPK 3.1 solver as well as the cython module pydaspk associated with it." 69 | @echo "The DASPK 3.1 fortran source files must first be downloaded externally and placed" 70 | @echo "in the daspk31 folder." 71 | @echo "" 72 | @echo "Typing \`make clean\` will delete all of the intermediate build files," 73 | @echo "compiled libraries, and compiled Python modules for all three DAE solvers and" 74 | @echo "the PyDAS modules." 75 | @echo "" 76 | @echo "Individual dependencies can be specified using \`make \`, where" 77 | @echo " is one of:" 78 | @echo "" 79 | @echo " DASSL to compile the DASSL solver" 80 | @echo " DASPK to compile the DASPK solver" 81 | @echo " DASPK31 to compile the DASPK31 solver" 82 | @echo " DASKR to compile the DASKR solver" 83 | @echo " cython to compile the PyDAS Python wrapper module for DASSL" 84 | @echo " cython-daspk to compile the PyDAS Python wrapper module for both DASSL and DASPK3.1" 85 | @echo "" 86 | 87 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ************************************************************************* 2 | PyDAS - A Python wrapper to several differential algebraic system solvers 3 | ************************************************************************* 4 | 5 | Introduction 6 | ============ 7 | 8 | PyDAS provides a means for Python code to utilize several notable Fortran-based 9 | differential algebraic system solvers from Python code. The solvers made 10 | available -- DASSL, DASPK, and DASKR -- are all publicly-available from 11 | `Netlib `_, and are distributed with PyDAS. PyDAS 12 | provides a Python extension type for each solver, which in turn provides a 13 | Pythonic means of setting the solver options, providing residual and jacobian 14 | functions, and running the solver. 15 | 16 | The DASSL, DASPK, and DASKR solvers are all substantially more robust than 17 | VODE, the solver used within the ODE solver functionality provided by 18 | `SciPy `_. 19 | 20 | License 21 | ======= 22 | 23 | Copyright (c) 2010 by Joshua W. Allen (joshua.w.allen@gmail.com). 24 | 25 | Permission is hereby granted, free of charge, to any person obtaining a 26 | copy of this software and associated documentation files (the 'Software'), 27 | to deal in the Software without restriction, including without limitation 28 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 29 | and/or sell copies of the Software, and to permit persons to whom the 30 | Software is furnished to do so, subject to the following conditions: 31 | 32 | The above copyright notice and this permission notice shall be included in 33 | all copies or substantial portions of the Software. 34 | 35 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 36 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 38 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 40 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 41 | DEALINGS IN THE SOFTWARE. 42 | 43 | Dependencies 44 | ============ 45 | 46 | PyDAS has been tested on Python versions 2.5 and 2.6. It may or may not work 47 | for other Python versions. 48 | 49 | There are several Python dependencies that you must install before installing 50 | PyDAS: 51 | 52 | * `Python `_ (versions 2.5.x and 2.6.x are known to work) 53 | 54 | * `NumPy `_ (version 1.3.0 or later is recommended) 55 | 56 | * `Cython `_ (version 0.12.1 or later is recommended) 57 | 58 | In addition, you will also need a Fortran compiler and a C compiler that 59 | produce object files that can interoperate. The ``gfortran`` and ``gcc`` 60 | compiles from the GNU Compiler Collection are known to work. On Windows the 61 | `MinGW `_ compiler collection provides these compilers. 62 | 63 | The code for the differential algebraic system solvers DASSL, DASPK, and DASKR 64 | has been provided with the PyDAS package. The licenses for these solvers is 65 | different than that of the PyDAS wrapper code. **You are responsible for knowing 66 | and abiding by all licenses associated with each solver as well as with PyDAS 67 | as a whole.** 68 | 69 | Installation 70 | ============ 71 | 72 | .. note:: 73 | 74 | Currently only the DASSL solver has been wrapped. The installation 75 | scripts therefore only build and install the DASSL wrapper by default. 76 | 77 | Windows 78 | ------- 79 | 80 | The provided batch scripts will compile all of the solvers and the PyDAS 81 | wrapper code. These scripts presume that you have the 32-bit version of the 82 | MinGW C and Fortran compilers installed. Once you have run the batch script, 83 | you can install PyDAS into your Python packages if you desire by running the 84 | following command from the base package directory: 85 | 86 | > python setup.py install 87 | 88 | Linux 89 | ----- 90 | 91 | A Makefile has been provided that can be used to compile all of the solvers 92 | and the PyDAS wrapper code. To use, invoke the following command from the 93 | base package directory:: 94 | 95 | $ make 96 | 97 | This command will build PyDAS in-place, rather than installing it to your 98 | Python package directory. If you wish to formall install PyDAS, run the 99 | following command from the base package directory after the ``make`` command 100 | (you may need root privileges for this):: 101 | 102 | $ python setup.py install 103 | 104 | You may wish to write a file `make.inc` that sets certain variables used by 105 | the Makefiles (e.g. the Fortran compiler). An example of such a file, 106 | `make.inc.example`, has been provided. 107 | 108 | 109 | Mac OS X 110 | -------- 111 | 112 | Homebrew (http://brew.sh) is an easy way to get gfortran:: 113 | 114 | $ brew install gcc 115 | 116 | But your system may still not be able to find the correct `libgfortran.a` library file 117 | (see https://github.com/mxcl/homebrew/issues/8539 ). Also, there are some problems 118 | linking with `clang`, so you need to make it link with `gcc`. This one-liner should 119 | build and install, assuming you have NumPy, Cython, etc. all set up:: 120 | 121 | $ LIBRARY_PATH=/usr/local/lib/gcc LDSHARED='gcc -bundle -undefined dynamic_lookup -arch x86_64' make F77=gfortran install 122 | 123 | Or perhaps, with a newer version of Homebrew / Python / gfortran / NumPy / Cython, it will be a simple:: 124 | 125 | $ LIBRARY_PATH=/usr/local/Cellar/gfortran/4.8.0/gfortran/lib make F77=gfortran 126 | 127 | It seems to keep on changing. If you have difficulty, check the 128 | `issue tracker `_, and if you solve 129 | your difficulty, please share your successful approach. 130 | -------------------------------------------------------------------------------- /das.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ddassl.h 3 | * 4 | * Contains the function prototype for exposing the Fortran differential 5 | * equation solver DASSL to C/C++. 6 | */ 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /** 13 | * Typedef for residual functions. 14 | */ 15 | typedef void (*residual_function)(double* t, double* y, double* yprime, double* delta, int* ires, double* rpar, int* ipar); 16 | 17 | /** 18 | * Typedef for Jacobian functions. 19 | */ 20 | typedef void (*jacobian_function)(double* t, double* y, double* yprime, double* pd, double* cj, double* rpar, int* ipar); 21 | 22 | /** 23 | * Exposes the Fortran differential equation solver DASSL to C/C++. 24 | */ 25 | int ddassl_( 26 | residual_function res, /** The residual function that defines the ODE/DAE system */ 27 | int* neq, /** The number of equations to be solved */ 28 | double* t, /** The current value of the independent variable */ 29 | double* y, /** The current values of the dependent variables */ 30 | double* yprime, /** The current values of the first derivatives of the dependent variables */ 31 | double* tout, /** The value of the independent variable at which a solution is desired */ 32 | int* info, /** Parameters controlling how the integration is performed */ 33 | double* rtol, /** The relative error tolerance(s), either as a scalar or a vector */ 34 | double* atol, /** The absolute error tolerance(s), either as a scalar or a vector */ 35 | int* idid, /** Report of the solver actions, used to control subsequent calls */ 36 | double* rwork, /** Work space for double-precision values */ 37 | int* lrw, /** The length of the double-precision workspace */ 38 | int* iwork, /** Work space for integer values */ 39 | int* liw, /** The length of the integer workspace */ 40 | double* rpar, /** Double-precision parameters to pass to the residual and Jacobian functions */ 41 | int* ipar, /** Integer parameters to pass to the residual and Jacobian functions */ 42 | jacobian_function jac /** The Jacobian function */ 43 | ); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /daskr/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002, The Regents of the University of California. 2 | Produced at the Lawrence Livermore National Laboratory 3 | Written by A.C. Hindmarsh, P. N. Brown, and L. R. Petzold. 4 | DASKR: UCRL-CODE-2002-058 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the disclaimer below. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the disclaimer (as noted below) 16 | in the documentation and/or other materials provided with the 17 | distribution. 18 | 19 | 3. Neither the name of the UC/LLNL nor the names of its contributors 20 | may be used to endorse or promote products derived from this software 21 | without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 26 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 27 | REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY 28 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | Additional BSD Notice 37 | --------------------- 38 | 1. This notice is required to be provided under our contract with 39 | the U.S. Department of Energy (DOE). This work was produced at the 40 | University of California, Lawrence Livermore National Laboratory 41 | under Contract No. W-7405-ENG-48 with the DOE. 42 | 43 | 2. Neither the United States Government nor the University of 44 | California nor any of their employees, makes any warranty, express 45 | or implied, or assumes any liability or responsibility for the 46 | accuracy, completeness, or usefulness of any information, apparatus, 47 | product, or process disclosed, or represents that its use would not 48 | infringe privately-owned rights. 49 | 50 | 3. Also, reference herein to any specific commercial products, 51 | process, or services by trade name, trademark, manufacturer or 52 | otherwise does not necessarily constitute or imply its endorsement, 53 | recommendation, or favoring by the United States Government or the 54 | University of California. The views and opinions of authors expressed 55 | herein do not necessarily state or reflect those of the United States 56 | Government or the University of California, and shall not be used for 57 | advertising or product endorsement purposes. 58 | -------------------------------------------------------------------------------- /daskr/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # 3 | # Makefile for DASKR 4 | # 5 | ################################################################################ 6 | 7 | F77=gfortran 8 | 9 | CFLAGS=-fPIC -O3 10 | 11 | DOBJ=solver/daux.o solver/ddaskr.o solver/dlinpk.o preconds/dbanpre.o preconds/dilupre.o preconds/drbdpre.o preconds/drbgpre.o preconds/dsparsk.o 12 | 13 | SOBJ=solver/saux.o solver/sdaskr.o solver/slinpk.o preconds/sbanpre.o preconds/silupre.o preconds/srbdpre.o preconds/srbgpre.o preconds/ssparsk.o 14 | 15 | DLIB=libddaskr.a 16 | 17 | SLIB=libsdaskr.a 18 | 19 | all: $(DLIB) $(SLIB) 20 | 21 | $(DLIB): $(DOBJ) 22 | ar rcs $(DLIB) $(DOBJ) 23 | 24 | $(SLIB): $(SOBJ) 25 | ar rcs $(SLIB) $(SOBJ) 26 | 27 | %.o: %.f 28 | $(F77) $(CFLAGS) -c $< -o $@ 29 | 30 | clean: 31 | rm -f $(DLIB) $(DOBJ) $(SLIB) $(SOBJ) 32 | -------------------------------------------------------------------------------- /daskr/README: -------------------------------------------------------------------------------- 1 | DASKR Package: DAE Solver with Krylov Methods and Rootfinding 2 | Version of 3 October 2007 3 | 4 | P. N. Brown, A. C. Hindmarsh, and L. R. Petzold 5 | 6 | 7 | DASKR is a solver for systems of differential-algebraic equations (DAEs). 8 | It includes options for both direct and iterative (Krylov) methods for the 9 | solution of the linear systems arising at each (implicit) time step. 10 | DASKR is a variant of the DASPK package [1]. In addition to all the 11 | capabilities of DASPK, DASKR includes the ability to find the roots of a 12 | given set of functions while integrating the DAE system. 13 | 14 | In contrast to the older DASSL package, DASKR includes a procedure 15 | for calculating consistent initial conditions for a large class of 16 | problems (which includes semi-explicit index-1 systems) [2]. This 17 | procedure includes options for inequality constraints on selected 18 | components. The package also includes an option to omit the algebraic 19 | components from the local error control. 20 | 21 | Along with the solver itself, the DASKR package includes five example 22 | programs and a set of general-purpose preconditioner files. These are 23 | described in more detail below. The package includes separate single 24 | and double precision versions of all source files. 25 | 26 | 27 | Package Contents 28 | ---------------- 29 | 30 | 1. The DASKR package is being distributed in the form of a tar file, 31 | which expands to a directory, DASKR. The DASKR directory contains 32 | this README file and three subdirectories. 33 | 34 | 2. The subdirectory DASKR/solver contains the following source files: 35 | 36 | ddaskr.f = main solver source, double precision 37 | dlinpk.f = required LINPACK/BLAS routines, double precision 38 | daux.f = machine constant and error handler, double precision 39 | 40 | sdaskr.f = main solver source, single precision 41 | slinpk.f = required LINPACK/BLAS routines, single precision 42 | saux.f = machine constant and error handler, single precision 43 | 44 | The LINPACK/BLAS files are provided for the sake of completeness, but 45 | the target machine/system of interest may already have optimized versions 46 | of these routines, which should be used instead for the sake of efficiency. 47 | 48 | A complete usage document is included as the initial prologue of each 49 | source file ddaskr.f/sdaskr.f. 50 | 51 | 3. The subdirectory DASKR/examples contains the following files: 52 | 53 | dkrdem.f = small demonstration program, double precision, which 54 | solves two small problems with self-checking logic 55 | dheat.f = heat equation example program, double precision, using 56 | the Krylov option with banded preconditioner 57 | dheatilu.f = heat equation example program, double precision, using 58 | the Krylov option with sparse ILU preconditioner 59 | dweb.f = food web system example program, double precision, using 60 | the direct (band) option, and the Krylov option with a 61 | product preconditioner based on reaction-transport form 62 | dwebilu.f = food web system example program, double precision, using 63 | the Krylov option with sparse ILU preconditioner 64 | makeddem = Make-file to compile and load dkrdem program 65 | makedh = Make-file to compile and load dheat program 66 | makedhilu = Make-file to compile and load dheatilu program 67 | makedw = Make-file to compile and load dweb program 68 | makedwilu = Make-file to compile and load dwebilu program 69 | 70 | skrdem.f = small demonstration program, single precision, which 71 | solves two small problems with self-checking logic 72 | sheat.f = heat equation example program, single precision, using 73 | the Krylov option with banded preconditioner 74 | sheatilu.f = heat equation example program, single precision, using 75 | the Krylov option with sparse ILU preconditioner 76 | sweb.f = food web system example program, single precision, using 77 | the direct (band) option, and the Krylov option with a 78 | product preconditioner based on reaction-transport form 79 | swebilu.f = food web system example program, single precision, using 80 | the Krylov option with sparse ILU preconditioner 81 | makesdem = Make-file to compile and load skrdem program 82 | makesh = Make-file to compile and load sheat program 83 | makeshilu = Make-file to compile and load sheatilu program 84 | makesw = Make-file to compile and load sweb program 85 | makeswilu = Make-file to compile and load swebilu program 86 | 87 | dkrdem.out = output from dheat.f program 88 | dheat.out = output from dheat.f program 89 | dheatilu.out = output from dheatilu.f program 90 | dweb.out = output from dweb.f program 91 | dwebilu.out = output from dwebilu.f program 92 | 93 | Except for dkrdem/skrdem, all of these examples make use of preconditioner 94 | routines, provided in the files described below, when calling DASKR with 95 | the Krylov method option. All are heavily commented and intended for use 96 | as models for real user applications of DASKR. 97 | 98 | 4. The subdirectory DASKR/preconds contains the following source files: 99 | 100 | dbanpre.f = preconditioner for banded problems, double precision 101 | drbdpre.f = routines for a reaction-based block-diagonal precond- 102 | itioner for DAEs arising from a reaction-transport 103 | system, without block-grouping, double precision 104 | drbgpre.f = routines for a reaction-based block-diagonal precond- 105 | itioner for DAEs arising from a reaction-transport 106 | system, with block-grouping, double precision 107 | dilupre.f = preconditioner routines for sparse ILU preconditioning, 108 | double precision, intended for general DAE problems. 109 | dsparsk.f = routines from SPARSKIT, Y. Saad (Univ. of Minnesota), 110 | double precision, used by dilupre.f 111 | 112 | sbanpre.f = preconditioner for banded problems, single precision 113 | srbdpre.f = routines for a reaction-based block-diagonal precond- 114 | itioner for DAEs arising from a reaction-transport 115 | system, without block-grouping, single precision 116 | srbgpre.f = routines for a reaction-based block-diagonal precond- 117 | itioner for DAEs arising from a reaction-transport 118 | system, with block-grouping, single precision 119 | silupre.f = preconditioner routines for sparse ILU preconditioning, 120 | single precision, intended for general DAE problems. 121 | ssparsk.f = routines from SPARSKIT, Y. Saad (Univ. of Minnesota), 122 | single precision, used by silupre.f 123 | 124 | At the beginning of each of these source files is a prologue which documents 125 | the contents of the file and the usage of the routines in it. 126 | 127 | 128 | Installation and Usage Notes 129 | ---------------------------- 130 | 131 | 1. The single and double precision versions of the SPARSKIT subset, in 132 | the files ssparsk.f and dsparsk.f in DASKR/preconds, cannot be 133 | installed together as a single library, because of name duplications 134 | among the individual routines. If such a combined installation is 135 | desired, first change the names of all precision-dependent subroutines 136 | in either ssparsk.f or dsparsk.f, so as to have unique names across 137 | the two files. Then make the same name changes in the corresponding 138 | file silupre.f or dilupre.f which calls those SPARSKIT routines. 139 | 140 | 2. The five example problems can be compiled and loaded using the 141 | appropriate make-file in DASKR/examples. First check the compiler and 142 | flags in the make-file, however. Each make-file finds the required 143 | solver and preconditioner source or object files in ../solver and 144 | ../preconds. The output files for all five examples, as run in double 145 | precision on a Sun Sparc-10 Workstation, are provided in the files 146 | d*.out. The results on other systems may differ slightly. 147 | 148 | 3. The example programs that use ILU preconditioning, if altered to 149 | use the option JACOUT = 1, write an additional output file containing 150 | the initial Jacobian and residual vector in Boeing-Harwell format. A 151 | map of the Jacobian as a postscript file can then be generated using 152 | the SPARSKIT routines readmt and pspltm. 153 | 154 | 4. Users of DASKR with a sparse ILU preconditioner are encouraged to 155 | experiment with the many options available in the SPARSKIT package, 156 | as accessed through the dilupre.f/silupre.f modules provided. See the 157 | prologue in those files, and the two examples that use ILU. 158 | 159 | 5. Important Note: The use of single precision on a 32-bit machine is 160 | strongly discouraged. The amplification of roundoff errors by the 161 | integration and linear system solution algorithms is such that double 162 | precision is generally required on short-wordlength machines. In 163 | particular, the small demonstration program and the food web example 164 | programs provided here do not run on a 32-bit machine in single 165 | precision, with even the moderate tolerance values of 1.0e-5. 166 | 167 | 168 | References 169 | ---------- 170 | [1] P. N. Brown, A. C. Hindmarsh, and L. R. Petzold, Using Krylov 171 | Methods in the Solution of Large-Scale Differential-Algebraic 172 | Systems, SIAM J. Sci. Comp., 15 (1994), pp. 1467-1488. 173 | 174 | [2] P. N. Brown, A. C. Hindmarsh, and L. R. Petzold, Consistent 175 | Initial Condition Calculation for Differential-Algebraic 176 | Systems, SIAM J. Sci. Comp. 19 (1998), pp. 1495-1512. 177 | 178 | --------------------------------------------------------------------------- 179 | 180 | Work performed under the auspices of the U.S. Department of Energy by 181 | Lawrence Livermore National Laboratory under contract number W-7405-Eng-48. 182 | 183 | Copyright (c) 2002, The Regents of the University of California. 184 | UCRL-CODE-2002-058 185 | All rights reserved. 186 | This file is part of DASKR. 187 | For details, see DASKR/LICENSE 188 | -------------------------------------------------------------------------------- /daskr/examples/dheat.out: -------------------------------------------------------------------------------- 1 | DHEAT: Heat Equation Example Program for DDASKR 2 | 3 | M+2 by M+2 mesh, M = 10, System size NEQ = 144 4 | 5 | Root functions are: R1 = max(u) - 0.1 and R2 = max(u) - 0.01 6 | 7 | Linear solver method flag INFO(12) = 1 (0 = direct, 1 = Krylov) 8 | Preconditioner is a banded approximation with ML = 1 MU = 1 9 | 10 | Tolerances are RTOL = 0.0E+00 ATOL = 0.1E-04 11 | 12 | 13 | t UMAX NQ H STEPS NNI NLI 14 | 15 | 0.10000E-01 0.8314E+00 4 0.146E-02 27 40 25 16 | 0.20000E-01 0.6943E+00 5 0.146E-02 34 48 34 17 | 0.40000E-01 0.4746E+00 4 0.292E-02 43 59 48 18 | 0.80000E-01 0.2174E+00 4 0.526E-02 53 72 64 19 | 0.11962E+00 0.1000E+00 5 0.105E-01 59 80 77 20 | ***** Root found, JROOT = -1 0 21 | 0.16000E+00 0.4531E-01 5 0.105E-01 63 84 88 22 | 0.23707E+00 0.1000E-01 5 0.105E-01 70 91 106 23 | ***** Root found, JROOT = 0 -1 24 | 0.32000E+00 0.1967E-02 5 0.105E-01 78 99 123 25 | 0.64000E+00 0.4037E-05 2 0.421E-01 94 119 193 26 | 0.12800E+01 0.7500E-06 1 0.336E+00 98 126 221 27 | 0.25600E+01 0.6751E-06 1 0.135E+01 100 130 228 28 | 0.51200E+01 0.6832E-06 1 0.269E+01 101 131 231 29 | 0.10240E+02 0.5604E-06 1 0.538E+01 102 132 234 30 | 31 | 32 | Final statistics for this run.. 33 | RWORK size = 3373 IWORK size = 184 34 | Number of time steps ................ = 102 35 | Number of residual evaluations ...... = 438 36 | Number of root function evaluations . = 142 37 | Number of preconditioner evaluations = 24 38 | Number of preconditioner solves ..... = 366 39 | Number of nonlinear iterations ...... = 132 40 | Number of linear iterations ......... = 234 41 | Average Krylov subspace dimension = 1.7727 42 | 0 nonlinear conv. failures, 0 linear conv. failures 43 | -------------------------------------------------------------------------------- /daskr/examples/dheatilu.out: -------------------------------------------------------------------------------- 1 | DHEATILU: Heat Equation Example Program for DDASKR 2 | 3 | M+2 by M+2 mesh, M = 10, System size NEQ = 144 4 | Root functions are: R1 = max(u) - 0.1 and R2 = max(u) - 0.01 5 | 6 | Linear solver method flag INFO(12) = 1 (0 = direct, 1 = Krylov) 7 | Preconditioner is a sparse approximation with ML = 1 MU = 1 8 | Incomplete factorization option = 1 (1 = ILUT, 2 = ILUTP) 9 | Tolerances are RTOL = 0.0E+00 ATOL = 0.1E-04 10 | 11 | 12 | t UMAX NQ H STEPS NNI NLI 13 | 14 | 0.10000E-01 0.8314E+00 4 0.146E-02 27 40 25 15 | 0.20000E-01 0.6943E+00 5 0.146E-02 34 48 34 16 | 0.40000E-01 0.4746E+00 4 0.292E-02 43 59 48 17 | 0.80000E-01 0.2174E+00 4 0.526E-02 53 72 64 18 | 0.11962E+00 0.1000E+00 5 0.105E-01 59 80 77 19 | ***** Root found, JROOT = -1 0 20 | 0.16000E+00 0.4531E-01 5 0.105E-01 63 84 88 21 | 0.23707E+00 0.1000E-01 5 0.105E-01 70 91 106 22 | ***** Root found, JROOT = 0 -1 23 | 0.32000E+00 0.1967E-02 5 0.105E-01 78 99 123 24 | 0.64000E+00 0.4039E-05 2 0.421E-01 94 119 193 25 | 0.12800E+01 0.7758E-06 1 0.336E+00 98 126 220 26 | 0.25600E+01 0.4790E-06 1 0.135E+01 100 130 229 27 | 0.51200E+01 0.4433E-06 1 0.269E+01 101 132 237 28 | 0.10240E+02 0.6703E-06 1 0.538E+01 102 134 246 29 | 30 | 31 | Final statistics for this run.. 32 | RWORK size = 5293 IWORK size =4508 33 | Number of time steps ................ = 102 34 | Number of residual evaluations ...... = 380 35 | Number of res. evals. for precond. = 72 36 | Number of root function evaluations . = 142 37 | Number of preconditioner evaluations = 24 38 | Number of preconditioner solves ..... = 380 39 | Number of nonlinear iterations ...... = 134 40 | Number of linear iterations ......... = 246 41 | Average Krylov subspace dimension = 1.8358 42 | 0 nonlinear conv. failures, 0 linear conv. failures 43 | Minimum lengths for work arrays WP and IWP: 2448 4321 44 | -------------------------------------------------------------------------------- /daskr/examples/dkrdem.out: -------------------------------------------------------------------------------- 1 | DKRDEM: Demonstration Program for DDASKR 2 | 3 | 4 | Problem 1.. 5 | 6 | Problem is dY/dT = ((2*LOG(Y)+8)/T - 5)*Y, Y(1) = 1 7 | Solution is Y(T) = EXP(-T**2 + 5*T - 4) 8 | Root functions are.. 9 | R1 = dY/dT (root at T = 2.5) 10 | R2 = LOG(Y) - 2.2491 (roots at T = 2.47 and T = 2.53) 11 | RTOL = 0.0E+00 ATOL = 0.1E-05 JTYPE = 2 12 | 13 | At t = 0.2000000E+01 y = 0.7389087E+01 error = 0.3132E-04 14 | At t = 0.2469897E+01 y = 0.9479201E+01 error = 0.5856E-04 15 | 16 | Root found at t = 0.2469897E+01 JROOT = 0 1 17 | Error in t location of root is -0.1028E-03 18 | 19 | At t = 0.2500001E+01 y = 0.9487795E+01 error = 0.5940E-04 20 | 21 | Root found at t = 0.2500001E+01 JROOT = -1 0 22 | Error in t location of root is 0.1236E-05 23 | 24 | At t = 0.2530105E+01 y = 0.9479201E+01 error = 0.6011E-04 25 | 26 | Root found at t = 0.2530105E+01 JROOT = 0 -1 27 | Error in t location of root is 0.1055E-03 28 | 29 | At t = 0.3000000E+01 y = 0.7389114E+01 error = 0.5752E-04 30 | At t = 0.4000000E+01 y = 0.1000018E+01 error = 0.1799E-04 31 | At t = 0.5000000E+01 y = 0.1831521E-01 error = -0.4334E-06 32 | At t = 0.6000000E+01 y = 0.4593840E-04 error = 0.5385E-06 33 | 34 | Final statistics for this run.. 35 | number of steps = 156 36 | number of Gs = 234 37 | (excluding Js) = 216 38 | number of Js = 18 39 | number of Rs = 197 40 | error overrun = 0.60E+02 41 | 42 | -------------------------------------------------------------------------------- 43 | 44 | Problem 2.. Van Der Pol oscillator 45 | 46 | Problem is dY1/dT = Y2, dY2/dT = 100*(1-Y1**2)*Y2 - Y1 47 | Y1(0) = 2, Y2(0) = 0 48 | Root function is R(T,Y,YP) = Y1 49 | RTOL = 0.1E-05 ATOL = 0.1E-05 0.1E-03 50 | 51 | ................................................................................ 52 | 53 | Solution with JTYPE = 1 54 | 55 | At t = 0.2000000E+02 y1 = 0.1858214E+01 y2 = -0.7575149E-02 56 | At t = 0.4000000E+02 y1 = 0.1693220E+01 y2 = -0.9068522E-02 57 | At t = 0.6000000E+02 y1 = 0.1484599E+01 y2 = -0.1232676E-01 58 | At t = 0.8000000E+02 y1 = 0.1086207E+01 y2 = -0.5847012E-01 59 | At t = 0.8116351E+02 y1 = -0.3295063E-12 y2 = -0.6714100E+02 60 | 61 | Root found at t = 0.8116351E+02 JROOT = -1 62 | Error in t location of root is -0.8866E-02 63 | 64 | At t = 0.1000000E+03 y1 = -0.1868846E+01 y2 = 0.7497409E-02 65 | At t = 0.1200000E+03 y1 = -0.1705917E+01 y2 = 0.8930216E-02 66 | At t = 0.1400000E+03 y1 = -0.1501730E+01 y2 = 0.1196138E-01 67 | At t = 0.1600000E+03 y1 = -0.1148759E+01 y2 = 0.3569131E-01 68 | At t = 0.1625746E+03 y1 = 0.1296341E-09 y2 = 0.6714049E+02 69 | 70 | Root found at t = 0.1625746E+03 JROOT = 1 71 | Error in t location of root is -0.1631E-01 72 | 73 | At t = 0.1800000E+03 y1 = 0.1879373E+01 y2 = -0.7422161E-02 74 | At t = 0.2000000E+03 y1 = 0.1718428E+01 y2 = -0.8798316E-02 75 | 76 | Final statistics for this run.. 77 | number of steps = 619 78 | number of Gs = 1012 79 | (excluding Js) = 1012 80 | number of Js = 69 81 | number of Rs = 651 82 | 83 | ................................................................................ 84 | 85 | Solution with JTYPE = 2 86 | 87 | At t = 0.2000000E+02 y1 = 0.1858214E+01 y2 = -0.7575149E-02 88 | At t = 0.4000000E+02 y1 = 0.1693220E+01 y2 = -0.9068522E-02 89 | At t = 0.6000000E+02 y1 = 0.1484599E+01 y2 = -0.1232676E-01 90 | At t = 0.8000000E+02 y1 = 0.1086207E+01 y2 = -0.5847012E-01 91 | At t = 0.8116351E+02 y1 = -0.2332891E-12 y2 = -0.6714100E+02 92 | 93 | Root found at t = 0.8116351E+02 JROOT = -1 94 | Error in t location of root is -0.8866E-02 95 | 96 | At t = 0.1000000E+03 y1 = -0.1868846E+01 y2 = 0.7497409E-02 97 | At t = 0.1200000E+03 y1 = -0.1705917E+01 y2 = 0.8930216E-02 98 | At t = 0.1400000E+03 y1 = -0.1501730E+01 y2 = 0.1196138E-01 99 | At t = 0.1600000E+03 y1 = -0.1148759E+01 y2 = 0.3569131E-01 100 | At t = 0.1625746E+03 y1 = 0.1308139E-09 y2 = 0.6714049E+02 101 | 102 | Root found at t = 0.1625746E+03 JROOT = 1 103 | Error in t location of root is -0.1631E-01 104 | 105 | At t = 0.1800000E+03 y1 = 0.1879373E+01 y2 = -0.7422161E-02 106 | At t = 0.2000000E+03 y1 = 0.1718428E+01 y2 = -0.8798316E-02 107 | 108 | Final statistics for this run.. 109 | number of steps = 619 110 | number of Gs = 1288 111 | (excluding Js) = 1150 112 | number of Js = 69 113 | number of Rs = 651 114 | 115 | -------------------------------------------------------------------------------- 116 | 117 | Number of errors encountered = 0 118 | 119 | **********DDASKR passed all tests********** 120 | -------------------------------------------------------------------------------- /daskr/examples/makeddem: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the DDASKR example program dkrdem. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/ddaskr.o $(SOLVR)/daux.o $(SOLVR)/dlinpk.o \ 14 | $(PRECON)/dbanpre.o 15 | 16 | DEMO = dkrdem.o $(OBJS) 17 | 18 | DEMO : $(DEMO) 19 | $(COMP) $(FFLAGS) -o demo $(DEMO) -lm 20 | 21 | dkrdem.o: dkrdem.f 22 | $(COMP) $(FFLAGS) -c dkrdem.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daskr/examples/makedh: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the DDASKR example program dheat. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/ddaskr.o $(SOLVR)/daux.o $(SOLVR)/dlinpk.o \ 14 | $(PRECON)/dbanpre.o 15 | 16 | HEAT = dheat.o $(OBJS) 17 | 18 | HEAT : $(HEAT) 19 | $(COMP) $(FFLAGS) -o heat $(HEAT) -lm 20 | 21 | dheat.o: dheat.f 22 | $(COMP) $(FFLAGS) -c dheat.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daskr/examples/makedhilu: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the DDASKR example program dheatilu. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/ddaskr.o $(SOLVR)/daux.o $(SOLVR)/dlinpk.o \ 14 | $(PRECON)/dilupre.o $(PRECON)/dsparsk.o 15 | 16 | HEATILU = dheatilu.o $(OBJS) 17 | 18 | HEATILU : $(HEATILU) 19 | $(COMP) $(FFLAGS) -o heatilu $(HEATILU) -lm 20 | 21 | dheatilu.o: dheatilu.f 22 | $(COMP) $(FFLAGS) -c dheatilu.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daskr/examples/makedw: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the DDASKR example program dweb. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/ddaskr.o $(SOLVR)/daux.o $(SOLVR)/dlinpk.o \ 14 | $(PRECON)/drbdpre.o $(PRECON)/drbgpre.o 15 | 16 | WEB = dweb.o $(OBJS) 17 | 18 | WEB : $(WEB) 19 | $(COMP) $(FFLAGS) -o web $(WEB) -lm 20 | 21 | dweb.o: dweb.f 22 | $(COMP) $(FFLAGS) -c dweb.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daskr/examples/makedwilu: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the DDASKR example program dwebilu. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/ddaskr.o $(SOLVR)/daux.o $(SOLVR)/dlinpk.o \ 14 | $(PRECON)/dilupre.o $(PRECON)/dsparsk.o 15 | 16 | WEBILU = dwebilu.o $(OBJS) 17 | 18 | WEBILU : $(WEBILU) 19 | $(COMP) $(FFLAGS) -o webilu $(WEBILU) -lm 20 | 21 | dwebilu.o: dwebilu.f 22 | $(COMP) $(FFLAGS) -c dwebilu.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daskr/examples/makesdem: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the SDASKR example program skrdem. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/sdaskr.o $(SOLVR)/saux.o $(SOLVR)/slinpk.o \ 14 | $(PRECON)/sbanpre.o 15 | 16 | DEMO = skrdem.o $(OBJS) 17 | 18 | DEMO : $(DEMO) 19 | $(COMP) $(FFLAGS) -o demo $(DEMO) -lm 20 | 21 | skrdem.o: skrdem.f 22 | $(COMP) $(FFLAGS) -c skrdem.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daskr/examples/makesh: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the SDASKR example program sheat. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/sdaskr.o $(SOLVR)/saux.o $(SOLVR)/slinpk.o \ 14 | $(PRECON)/sbanpre.o 15 | 16 | HEAT = sheat.o $(OBJS) 17 | 18 | HEAT : $(HEAT) 19 | $(COMP) $(FFLAGS) -o heat $(HEAT) -lm 20 | 21 | sheat.o: sheat.f 22 | $(COMP) $(FFLAGS) -c sheat.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daskr/examples/makeshilu: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the SDASKR example program sheatilu. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/sdaskr.o $(SOLVR)/saux.o $(SOLVR)/slinpk.o \ 14 | $(PRECON)/silupre.o $(PRECON)/ssparsk.o 15 | 16 | HEATILU = sheatilu.o $(OBJS) 17 | 18 | HEATILU : $(HEATILU) 19 | $(COMP) $(FFLAGS) -o heatilu $(HEATILU) -lm 20 | 21 | sheatilu.o: sheatilu.f 22 | $(COMP) $(FFLAGS) -c sheatilu.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daskr/examples/makesw: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the DDASKR example program sweb. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/sdaskr.o $(SOLVR)/saux.o $(SOLVR)/slinpk.o \ 14 | $(PRECON)/srbdpre.o $(PRECON)/srbgpre.o 15 | 16 | WEB = sweb.o $(OBJS) 17 | 18 | WEB : $(WEB) 19 | $(COMP) $(FFLAGS) -o web $(WEB) -lm 20 | 21 | sweb.o: sweb.f 22 | $(COMP) $(FFLAGS) -c sweb.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daskr/examples/makeswilu: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the DDASKR example program swebilu. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/sdaskr.o $(SOLVR)/saux.o $(SOLVR)/slinpk.o \ 14 | $(PRECON)/silupre.o $(PRECON)/ssparsk.o 15 | 16 | WEBILU = swebilu.o $(OBJS) 17 | 18 | WEBILU : $(WEBILU) 19 | $(COMP) $(FFLAGS) -o webilu $(WEBILU) -lm 20 | 21 | swebilu.o: swebilu.f 22 | $(COMP) $(FFLAGS) -c swebilu.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daskr/preconds/dbanpre.f: -------------------------------------------------------------------------------- 1 | C----------------------------------------------------------------------- 2 | C 3 | C Preconditioner Routines for Banded Problems 4 | C 14 September 1995 5 | C 6 | C The following pair of subroutines -- DBANJA and DBANPS -- provides a 7 | C general-purpose banded preconditioner matrix for use with the DDASPK 8 | C solver, with the Krylov linear system method. When using DDASPK to 9 | C solve a problem G(t,y,y') = 0, whose iteration matrix (Jacobian) 10 | C J = dG/dy + c * dG/dy' (c = scalar) 11 | C is either banded or approximately equal to a banded matrix, these 12 | C routines can be used to generate a banded approximation to J as the 13 | C preconditioner and to solve the resulting banded linear system, in 14 | C conjunction with the Krylov method option (INFO(12) = 1) in DDASPK. 15 | C 16 | C Other than the user-supplied residual routine RES defining G(t,y,y'), 17 | C the only other inputs required by these routines are the 18 | C half-bandwidth parameters ML and MU of the approximate banded 19 | C Jacobian. If the system size is NEQ, the half-bandwidths are 20 | C defined as integers between 0 and NEQ - 1 such that only elements 21 | C with indices (i,j) satisfying 22 | C -ML .le. j - i .le. MU 23 | C are to be retained in the preconditioner. E.g., if ML = MU = 0, a 24 | C diagonal matrix will be generated as the preconditioner. The banded 25 | C preconditioner is obtained by difference quotient approximations. If 26 | C the true problem Jacobian is not banded but is approximately equal to 27 | C a matrix that is banded, the procedure used here will have the effect 28 | C of lumping the elements outside of the band onto the elements within 29 | C the band. 30 | C 31 | C To use these routines in conjunction with DDASPK, the user's calling 32 | C program should include the following, in addition to setting the other 33 | C DDASPK input parameters. 34 | C 35 | C (a) Dimension the array IPAR to have length at least 2, and load the 36 | C half-bandwidths into IPAR as 37 | C IPAR(1) = ML and IPAR(2) = MU 38 | C IPAR is used to communicate these parameters to DBANJA and DBANPS. 39 | C If the user program also uses IPAR for communication with RES, 40 | C that data should be located beyond the first 2 words of IPAR. 41 | C 42 | C (b) Include the names DBANJA and DBANPS in an EXTERNAL statement. 43 | C Set INFO(15) = 1 to indicate that a JAC routine exists. 44 | C Then in the call to DDASPK, pass the names DBANJA and DBANPS as 45 | C the arguments JAC and PSOL, respectively. 46 | C 47 | C (c) The DDASPK work arrays RWORK and IWORK must include segments WP 48 | C and IWP for use by DBANJA/DBANPS. The lengths of these depend on 49 | C the problem size and half-bandwidths, as follows: 50 | C LWP = length of RWORK segment WP = 51 | C (2*ML + MU + 1)*NEQ + 2*( (NEQ/(ML+MU+1)) + 1) 52 | C LIWP = length of IWORK segment IWP = NEQ 53 | C (Note the integer divide in LWP.) Load these lengths in IWORK as 54 | C IWORK(27) = LWP 55 | C IWORK(28) = LIWP 56 | C and include these values in the declared size of RWORK and IWORK. 57 | C 58 | C 59 | C The DBANJA and DBANPS routines generate and solve the banded 60 | C preconditioner matrix P within the preconditioned Krylov algorithm 61 | C used by DDASPK when INFO(12) = 1. P is generated and LU-factored 62 | C periodically during the integration, and the factors are used to 63 | C solve systems Px = b as needed. 64 | C----------------------------------------------------------------------- 65 | 66 | 67 | SUBROUTINE DBANJA (RES, IRES, NEQ, T, Y, YPRIME, REWT, SAVR, 68 | * WK, H, CJ, WP, IWP, IER, RPAR, IPAR) 69 | C 70 | C***BEGIN PROLOGUE DBANJA 71 | C***DATE WRITTEN 891204 (YYMMDD) 72 | C***REVISION DATE 900122 73 | C***REVISION DATE 920929 CJ in RES call sequence 74 | C***REVISION DATE 950914 Name change, minor revisions throughout 75 | C***AUTHORS L. R. Petzold, P. N. Brown, A. C. Hindmarsh, C. W. Ulrich 76 | C Numerical Mathematics Group 77 | C Lawrence Livermore National Laboratory 78 | C Livermore, CA 94551 79 | C 80 | C***DESCRIPTION 81 | C 82 | C Subroutine DBANJA generates a banded preconditioner matrix P that 83 | C approximates the DDASPK iteration matrix J = dG/dy + CJ*dG/dy', 84 | C where the DAE system is G(t,y,y') = 0. The band matrix P has 85 | C half-bandwidths ML and MU. It is computed by making (ML + MU + 1) 86 | C calls to the user's RES routine and forming difference quotients, 87 | C exactly as in the banded direct method option of DDASPK. 88 | C DBANJA calls the LINPACK routine DGBFA to do an LU factorization of 89 | C this matrix. 90 | C 91 | C The call sequence parameters have the following meanings. 92 | C 93 | C RES = External user-supplied subroutine to evaluate the 94 | C residuals. See RES description in DDASPK prologue. 95 | C IRES = Output flag set by RES. See RES description in DDASPK. 96 | C NEQ = Problem size. 97 | C T = Independent variable t. 98 | C Y = Array containing current dependent variables y. 99 | C YPRIME = Array containing current derivative y'. 100 | C REWT = Vector of reciprocal error weights, used here for 101 | C computing increments. 102 | C SAVR = Current residual evaluated at (T,Y,YPRIME). 103 | C WK = Real work space of length NEQ. 104 | C H = Current step size. 105 | C CJ = Scalar proportional to 1/H. 106 | C WP = Real work array for P etc. On output, it contains 107 | C the LU decomposition of the banded approximation P. 108 | C IWP = Integer work space for matrix pivot information. 109 | C IER = Output flag, > 0 if P is singular, and 0 otherwise. 110 | C RPAR,IPAR= Real and integer arrays used for communication between 111 | C the calling program and external user routines. 112 | C IPAR(1) and IPAR(2) must contain ML and MU, resp. 113 | C RPAR is not used here. 114 | C 115 | C***ROUTINES CALLED 116 | C D1MACH, DGBFA, RES 117 | C 118 | C***END PROLOGUE DBANJA 119 | C 120 | IMPLICIT DOUBLE PRECISION(A-H,O-Z) 121 | EXTERNAL RES 122 | DIMENSION Y(*), YPRIME(*), SAVR(*), REWT(*), WK(*) 123 | DIMENSION WP(*), IWP(*), RPAR(*), IPAR(*) 124 | C 125 | C Set band parameters. 126 | ML = IPAR(1) 127 | MU = IPAR(2) 128 | MBAND = ML + MU + 1 129 | MBA = MIN(MBAND, NEQ) 130 | MEBAND = MBAND + ML 131 | MEB1 = MEBAND - 1 132 | C 133 | C Set the machine unit roundoff UROUND and SQRT(UROUND), used to 134 | C set increments in the difference quotient procedure. 135 | UROUND = D1MACH(4) 136 | SQUR = SQRT(UROUND) 137 | C 138 | C Set pointers into WP. LENP is the length of the segment for P. 139 | C Following that are two segments of size (NEQ/MBAND), with offsets 140 | C ISAVE and IPSAVE, for temporary storage of Y and YPRIME elements. 141 | LENP = (2*ML+MU+1)*NEQ 142 | MSAVE = (NEQ/MBAND) + 1 143 | ISAVE = LENP 144 | IPSAVE = ISAVE + MSAVE 145 | C 146 | C Initialize error flags. 147 | IER = 0 148 | IRES = 0 149 | C 150 | C Generate the banded approximate iteration matrix P using 151 | C difference quotients on the results of calls to RES. 152 | C 153 | DO 40 J = 1,MBA 154 | DO 10 N = J,NEQ,MBAND 155 | K= (N-J)/MBAND + 1 156 | WP(ISAVE+K) = Y(N) 157 | WP(IPSAVE+K) = YPRIME(N) 158 | DEL = SQUR*MAX(ABS(Y(N)), ABS(H*YPRIME(N)), ABS(1.D0/REWT(N))) 159 | DEL = SIGN(DEL, H*YPRIME(N)) 160 | DEL = (Y(N) + DEL) - Y(N) 161 | Y(N) = Y(N) + DEL 162 | YPRIME(N) = YPRIME(N) + CJ*DEL 163 | 10 CONTINUE 164 | CALL RES (T, Y, YPRIME, CJ, WK, IRES, RPAR, IPAR) 165 | IF (IRES .LT. 0) RETURN 166 | DO 30 N = J,NEQ,MBAND 167 | K = (N-J)/MBAND + 1 168 | Y(N) = WP(ISAVE+K) 169 | YPRIME(N) = WP(IPSAVE+K) 170 | DEL = SQUR*MAX(ABS(Y(N)), ABS(H*YPRIME(N)), ABS(1.D0/REWT(N))) 171 | DEL = SIGN(DEL, H*YPRIME(N)) 172 | DEL = (Y(N) + DEL) - Y(N) 173 | DELINV = 1.0D0/DEL 174 | I1 = MAX(1, N-MU) 175 | I2 = MIN(NEQ, N+ML) 176 | II = N*MEB1 - ML 177 | DO 20 I = I1,I2 178 | 20 WP(II+I) = (WK(I) - SAVR(I))*DELINV 179 | 30 CONTINUE 180 | 40 CONTINUE 181 | C 182 | C Do LU decomposition of the band matrix P. 183 | C 184 | CALL DGBFA (WP, MEBAND, NEQ, ML, MU, IWP, IER) 185 | RETURN 186 | C 187 | C------------ End of Subroutine DBANJA ------------------------------- 188 | END 189 | 190 | SUBROUTINE DBANPS (NEQ, T, Y, YPRIME, SAVR, WK, CJ, WGHT, 191 | * WP, IWP, B, EPLIN, IER, RPAR, IPAR) 192 | C 193 | C***BEGIN PROLOGUE DBANPS 194 | C***DATE WRITTEN 891204 (YYMMDD) 195 | C***REVISION DATE 900110 (YYMMDD) 196 | C***REVISION DATE 950914 Name change, minor revisions throughout 197 | C***AUTHORS L. R. Petzold, P. N. Brown, A. C. Hindmarsh, C. W. Ulrich 198 | C Numerical Mathematics Group 199 | C Lawrence Livermore National Laboratory 200 | C Livermore, CA 94551 201 | C 202 | C***DESCRIPTION 203 | C 204 | C Subroutine DBANPS uses the factors produced by DBANJA to solve linear 205 | C systems P x = b for the banded preconditioner P and a given vector b. 206 | C It calls the LINPACK routine SGBSL for this. 207 | C 208 | C The call sequence parameters have the following meanings. 209 | C 210 | C NEQ = Problem size. 211 | C T = Independent variable t (not used). 212 | C Y = Array containing current dependent vars. (not used). 213 | C YPRIME = Array containing current derivative (not used). 214 | C SAVR = Current residual evaluated at (T,Y,YPRIME) (not used). 215 | C WK = Real work space of length NEQ (not used). 216 | C CJ = Scalar proportional to 1/H (H = step size) (not used). 217 | C WGHT = Vector of error weights for computing norms (not used). 218 | C WP = Real work array containing the LU decomposition of P. 219 | C IWP = Integer array containing matrix pivot information. 220 | C B = Right-hand side vector on input; solution on output. 221 | C EPLIN = tolerance on linear system solver (not used). 222 | C IER = Output error flag (not used; assumed 0 on input). 223 | C RPAR,IPAR= Real and integer arrays used for communication between 224 | C the calling program and external user routines. 225 | C IPAR(1) and IPAR(2) must contain ML and MU, resp. 226 | C RPAR is not used here. 227 | C 228 | C***ROUTINES CALLED 229 | C DGBSL 230 | C 231 | C***END PROLOGUE DBANPS 232 | C 233 | IMPLICIT DOUBLE PRECISION(A-H,O-Z) 234 | DIMENSION B(*),WP(*),IWP(*),RPAR(*),IPAR(*) 235 | C 236 | ML = IPAR(1) 237 | MU = IPAR(2) 238 | MEBAND = 2*ML + MU + 1 239 | CALL DGBSL (WP, MEBAND, NEQ, ML, MU, IWP, B, 0) 240 | RETURN 241 | C 242 | C------------ End of Subroutine DBANPS ------------------------------- 243 | END 244 | -------------------------------------------------------------------------------- /daskr/preconds/sbanpre.f: -------------------------------------------------------------------------------- 1 | C----------------------------------------------------------------------- 2 | C 3 | C Preconditioner Routines for Banded Problems 4 | C 14 September 1995 5 | C 6 | C The following pair of subroutines -- SBANJA and SBANPS -- provides a 7 | C general-purpose banded preconditioner matrix for use with the SDASPK 8 | C solver, with the Krylov linear system method. When using SDASPK to 9 | C solve a problem G(t,y,y') = 0, whose iteration matrix (Jacobian) 10 | C J = dG/dy + c * dG/dy' (c = scalar) 11 | C is either banded or approximately equal to a banded matrix, these 12 | C routines can be used to generate a banded approximation to J as the 13 | C preconditioner and to solve the resulting banded linear system, in 14 | C conjunction with the Krylov method option (INFO(12) = 1) in SDASPK. 15 | C 16 | C Other than the user-supplied residual routine RES defining G(t,y,y'), 17 | C the only other inputs required by these routines are the 18 | C half-bandwidth parameters ML and MU of the approximate banded 19 | C Jacobian. If the system size is NEQ, the half-bandwidths are 20 | C defined as integers between 0 and NEQ - 1 such that only elements 21 | C with indices (i,j) satisfying 22 | C -ML .le. j - i .le. MU 23 | C are to be retained in the preconditioner. E.g., if ML = MU = 0, a 24 | C diagonal matrix will be generated as the preconditioner. The banded 25 | C preconditioner is obtained by difference quotient approximations. If 26 | C the true problem Jacobian is not banded but is approximately equal to 27 | C a matrix that is banded, the procedure used here will have the effect 28 | C of lumping the elements outside of the band onto the elements within 29 | C the band. 30 | C 31 | C To use these routines in conjunction with SDASPK, the user's calling 32 | C program should include the following, in addition to setting the other 33 | C SDASPK input parameters. 34 | C 35 | C (a) Dimension the array IPAR to have length at least 2, and load the 36 | C half-bandwidths into IPAR as 37 | C IPAR(1) = ML and IPAR(2) = MU 38 | C IPAR is used to communicate these parameters to SBANJA and SBANPS. 39 | C If the user program also uses IPAR for communication with RES, 40 | C that data should be located beyond the first 2 words of IPAR. 41 | C 42 | C (b) Include the names SBANJA and SBANPS in an EXTERNAL statement. 43 | C Set INFO(15) = 1 to indicate that a JAC routine exists. 44 | C Then in the call to SDASPK, pass the names SBANJA and SBANPS as 45 | C the arguments JAC and PSOL, respectively. 46 | C 47 | C (c) The SDASPK work arrays RWORK and IWORK must include segments WP 48 | C and IWP for use by SBANJA/SBANPS. The lengths of these depend on 49 | C the problem size and half-bandwidths, as follows: 50 | C LWP = length of RWORK segment WP = 51 | C (2*ML + MU + 1)*NEQ + 2*( (NEQ/(ML+MU+1)) + 1) 52 | C LIWP = length of IWORK segment IWP = NEQ 53 | C (Note the integer divide in LWP.) Load these lengths in IWORK as 54 | C IWORK(27) = LWP 55 | C IWORK(28) = LIWP 56 | C and include these values in the declared size of RWORK and IWORK. 57 | C 58 | C 59 | C The SBANJA and SBANPS routines generate and solve the banded 60 | C preconditioner matrix P within the preconditioned Krylov algorithm 61 | C used by SDASPK when INFO(12) = 1. P is generated and LU-factored 62 | C periodically during the integration, and the factors are used to 63 | C solve systems Px = b as needed. 64 | C----------------------------------------------------------------------- 65 | 66 | 67 | SUBROUTINE SBANJA (RES, IRES, NEQ, T, Y, YPRIME, REWT, SAVR, 68 | * WK, H, CJ, WP, IWP, IER, RPAR, IPAR) 69 | C 70 | C***BEGIN PROLOGUE SBANJA 71 | C***DATE WRITTEN 891204 (YYMMDD) 72 | C***REVISION DATE 900122 73 | C***REVISION DATE 920929 CJ in RES call sequence 74 | C***REVISION DATE 950914 Name change, minor revisions throughout 75 | C***REVISION DATE 950918 Converted to single precision. 76 | C***AUTHORS L. R. Petzold, P. N. Brown, A. C. Hindmarsh, C. W. Ulrich 77 | C Numerical Mathematics Group 78 | C Lawrence Livermore National Laboratory 79 | C Livermore, CA 94551 80 | C 81 | C***DESCRIPTION 82 | C 83 | C Subroutine SBANJA generates a banded preconditioner matrix P that 84 | C approximates the SDASPK iteration matrix J = dG/dy + CJ*dG/dy', 85 | C where the DAE system is G(t,y,y') = 0. The band matrix P has 86 | C half-bandwidths ML and MU. It is computed by making (ML + MU + 1) 87 | C calls to the user's RES routine and forming difference quotients, 88 | C exactly as in the banded direct method option of SDASPK. 89 | C SBANJA calls the LINPACK routine SGBFA to do an LU factorization of 90 | C this matrix. 91 | C 92 | C The call sequence parameters have the following meanings. 93 | C 94 | C RES = External user-supplied subroutine to evaluate the 95 | C residuals. See RES description in SDASPK prologue. 96 | C IRES = Output flag set by RES. See RES description in SDASPK. 97 | C NEQ = Problem size. 98 | C T = Independent variable t. 99 | C Y = Array containing current dependent variables y. 100 | C YPRIME = Array containing current derivative y'. 101 | C REWT = Vector of reciprocal error weights, used here for 102 | C computing increments. 103 | C SAVR = Current residual evaluated at (T,Y,YPRIME). 104 | C WK = Real work space of length NEQ. 105 | C H = Current step size. 106 | C CJ = Scalar proportional to 1/H. 107 | C WP = Real work array for P etc. On output, it contains 108 | C the LU decomposition of the banded approximation P. 109 | C IWP = Integer work space for matrix pivot information. 110 | C IER = Output flag, > 0 if P is singular, and 0 otherwise. 111 | C RPAR,IPAR= Real and integer arrays used for communication between 112 | C the calling program and external user routines. 113 | C IPAR(1) and IPAR(2) must contain ML and MU, resp. 114 | C RPAR is not used here. 115 | C 116 | C***ROUTINES CALLED 117 | C R1MACH, SGBFA, RES 118 | C 119 | C***END PROLOGUE SBANJA 120 | C 121 | IMPLICIT REAL(A-H,O-Z) 122 | EXTERNAL RES 123 | DIMENSION Y(*), YPRIME(*), SAVR(*), REWT(*), WK(*) 124 | DIMENSION WP(*), IWP(*), RPAR(*), IPAR(*) 125 | C 126 | C Set band parameters. 127 | ML = IPAR(1) 128 | MU = IPAR(2) 129 | MBAND = ML + MU + 1 130 | MBA = MIN(MBAND, NEQ) 131 | MEBAND = MBAND + ML 132 | MEB1 = MEBAND - 1 133 | C 134 | C Set the machine unit roundoff UROUND and SQRT(UROUND), used to 135 | C set increments in the difference quotient procedure. 136 | UROUND = R1MACH(4) 137 | SQUR = SQRT(UROUND) 138 | C 139 | C Set pointers into WP. LENP is the length of the segment for P. 140 | C Following that are two segments of size (NEQ/MBAND), with offsets 141 | C ISAVE and IPSAVE, for temporary storage of Y and YPRIME elements. 142 | LENP = (2*ML+MU+1)*NEQ 143 | MSAVE = (NEQ/MBAND) + 1 144 | ISAVE = LENP 145 | IPSAVE = ISAVE + MSAVE 146 | C 147 | C Initialize error flags. 148 | IER = 0 149 | IRES = 0 150 | C 151 | C Generate the banded approximate iteration matrix P using 152 | C difference quotients on the results of calls to RES. 153 | C 154 | DO 40 J = 1,MBA 155 | DO 10 N = J,NEQ,MBAND 156 | K= (N-J)/MBAND + 1 157 | WP(ISAVE+K) = Y(N) 158 | WP(IPSAVE+K) = YPRIME(N) 159 | DEL = SQUR*MAX(ABS(Y(N)), ABS(H*YPRIME(N)), ABS(1.E0/REWT(N))) 160 | DEL = SIGN(DEL, H*YPRIME(N)) 161 | DEL = (Y(N) + DEL) - Y(N) 162 | Y(N) = Y(N) + DEL 163 | YPRIME(N) = YPRIME(N) + CJ*DEL 164 | 10 CONTINUE 165 | CALL RES (T, Y, YPRIME, CJ, WK, IRES, RPAR, IPAR) 166 | IF (IRES .LT. 0) RETURN 167 | DO 30 N = J,NEQ,MBAND 168 | K = (N-J)/MBAND + 1 169 | Y(N) = WP(ISAVE+K) 170 | YPRIME(N) = WP(IPSAVE+K) 171 | DEL = SQUR*MAX(ABS(Y(N)), ABS(H*YPRIME(N)), ABS(1.E0/REWT(N))) 172 | DEL = SIGN(DEL, H*YPRIME(N)) 173 | DEL = (Y(N) + DEL) - Y(N) 174 | DELINV = 1.0E0/DEL 175 | I1 = MAX(1, N-MU) 176 | I2 = MIN(NEQ, N+ML) 177 | II = N*MEB1 - ML 178 | DO 20 I = I1,I2 179 | 20 WP(II+I) = (WK(I) - SAVR(I))*DELINV 180 | 30 CONTINUE 181 | 40 CONTINUE 182 | C 183 | C Do LU decomposition of the band matrix P. 184 | C 185 | CALL SGBFA (WP, MEBAND, NEQ, ML, MU, IWP, IER) 186 | RETURN 187 | C 188 | C------------ End of Subroutine SBANJA ------------------------------- 189 | END 190 | 191 | SUBROUTINE SBANPS (NEQ, T, Y, YPRIME, SAVR, WK, CJ, WGHT, 192 | * WP, IWP, B, EPLIN, IER, RPAR, IPAR) 193 | C 194 | C***BEGIN PROLOGUE SBANPS 195 | C***DATE WRITTEN 891204 (YYMMDD) 196 | C***REVISION DATE 900110 (YYMMDD) 197 | C***REVISION DATE 950914 Name change, minor revisions throughout 198 | C***REVISION DATE 950918 Converted to single precision. 199 | C***AUTHORS L. R. Petzold, P. N. Brown, A. C. Hindmarsh, C. W. Ulrich 200 | C Numerical Mathematics Group 201 | C Lawrence Livermore National Laboratory 202 | C Livermore, CA 94551 203 | C 204 | C***DESCRIPTION 205 | C 206 | C Subroutine SBANPS uses the factors produced by SBANJA to solve linear 207 | C systems P x = b for the banded preconditioner P and a given vector b. 208 | C It calls the LINPACK routine SGBSL for this. 209 | C 210 | C The call sequence parameters have the following meanings. 211 | C 212 | C NEQ = Problem size. 213 | C T = Independent variable t (not used). 214 | C Y = Array containing current dependent vars. (not used). 215 | C YPRIME = Array containing current derivative (not used). 216 | C SAVR = Current residual evaluated at (T,Y,YPRIME) (not used). 217 | C WK = Real work space of length NEQ (not used). 218 | C CJ = Scalar proportional to 1/H (H = step size) (not used). 219 | C WGHT = Vector of error weights for computing norms (not used). 220 | C WP = Real work array containing the LU decomposition of P. 221 | C IWP = Integer array containing matrix pivot information. 222 | C B = Right-hand side vector on input; solution on output. 223 | C EPLIN = tolerance on linear system solver (not used). 224 | C IER = Output error flag (not used; assumed 0 on input). 225 | C RPAR,IPAR= Real and integer arrays used for communication between 226 | C the calling program and external user routines. 227 | C IPAR(1) and IPAR(2) must contain ML and MU, resp. 228 | C RPAR is not used here. 229 | C 230 | C***ROUTINES CALLED 231 | C SGBSL 232 | C 233 | C***END PROLOGUE SBANPS 234 | C 235 | IMPLICIT REAL(A-H,O-Z) 236 | DIMENSION B(*),WP(*),IWP(*),RPAR(*),IPAR(*) 237 | C 238 | ML = IPAR(1) 239 | MU = IPAR(2) 240 | MEBAND = 2*ML + MU + 1 241 | CALL SGBSL (WP, MEBAND, NEQ, ML, MU, IWP, B, 0) 242 | RETURN 243 | C 244 | C------------ End of Subroutine SBANPS ------------------------------- 245 | END 246 | -------------------------------------------------------------------------------- /daskr/solver/daux.f: -------------------------------------------------------------------------------- 1 | *DECK D1MACH 2 | DOUBLE PRECISION FUNCTION D1MACH (IDUMMY) 3 | C***BEGIN PROLOGUE D1MACH 4 | C***PURPOSE Compute the unit roundoff of the machine. 5 | C***CATEGORY R1 6 | C***TYPE DOUBLE PRECISION (R1MACH-S, D1MACH-D) 7 | C***KEYWORDS MACHINE CONSTANTS 8 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 9 | C***DESCRIPTION 10 | C *Usage: 11 | C DOUBLE PRECISION A, D1MACH 12 | C A = D1MACH(idummy) [The argument is ignored.] 13 | C 14 | C *Function Return Values: 15 | C A : the unit roundoff of the machine. 16 | C 17 | C *Description: 18 | C The unit roundoff is defined as the smallest positive machine 19 | C number u such that 1.0 + u .ne. 1.0. This is computed by D1MACH 20 | C in a machine-independent manner. 21 | C 22 | C***REFERENCES (NONE) 23 | C***ROUTINES CALLED DUMSUM 24 | C***REVISION HISTORY (YYYYMMDD) 25 | C 19930216 DATE WRITTEN 26 | C 19930818 Added SLATEC-format prologue. (FNF) 27 | C 20030707 Added DUMSUM to force normal storage of COMP. (ACH) 28 | C***END PROLOGUE D1MACH 29 | C 30 | INTEGER IDUMMY 31 | DOUBLE PRECISION U, COMP 32 | C***FIRST EXECUTABLE STATEMENT D1MACH 33 | U = 1.0D0 34 | 10 U = U*0.5D0 35 | CALL DUMSUM(1.0D0, U, COMP) 36 | IF (COMP .NE. 1.0D0) GO TO 10 37 | D1MACH = U*2.0D0 38 | RETURN 39 | C----------------------- End of Function D1MACH ------------------------ 40 | END 41 | SUBROUTINE DUMSUM(A,B,C) 42 | C Routine to force normal storing of A + B, for D1MACH. 43 | DOUBLE PRECISION A, B, C 44 | C = A + B 45 | RETURN 46 | END 47 | *DECK XERRWD 48 | SUBROUTINE XERRWD (MSG, NMES, NERR, LEVEL, NI, I1, I2, NR, R1, R2) 49 | C***BEGIN PROLOGUE XERRWD 50 | C***SUBSIDIARY 51 | C***PURPOSE Write error message with values. 52 | C***LIBRARY MATHLIB 53 | C***CATEGORY R3C 54 | C***TYPE DOUBLE PRECISION (XERRWV-S, XERRWD-D) 55 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 56 | C***DESCRIPTION 57 | C 58 | C Subroutines XERRWD, XSETF, XSETUN, and the function routine IXSAV, 59 | C as given here, constitute a simplified version of the SLATEC error 60 | C handling package. 61 | C 62 | C All arguments are input arguments. 63 | C 64 | C MSG = The message (character array). 65 | C NMES = The length of MSG (number of characters). 66 | C NERR = The error number (not used). 67 | C LEVEL = The error level.. 68 | C 0 or 1 means recoverable (control returns to caller). 69 | C 2 means fatal (run is aborted--see note below). 70 | C NI = Number of integers (0, 1, or 2) to be printed with message. 71 | C I1,I2 = Integers to be printed, depending on NI. 72 | C NR = Number of reals (0, 1, or 2) to be printed with message. 73 | C R1,R2 = Reals to be printed, depending on NR. 74 | C 75 | C Note.. this routine is machine-dependent and specialized for use 76 | C in limited context, in the following ways.. 77 | C 1. The argument MSG is assumed to be of type CHARACTER, and 78 | C the message is printed with a format of (1X,A). 79 | C 2. The message is assumed to take only one line. 80 | C Multi-line messages are generated by repeated calls. 81 | C 3. If LEVEL = 2, control passes to the statement STOP 82 | C to abort the run. This statement may be machine-dependent. 83 | C 4. R1 and R2 are assumed to be in double precision and are printed 84 | C in D21.13 format. 85 | C 86 | C***ROUTINES CALLED IXSAV 87 | C***REVISION HISTORY (YYMMDD) 88 | C 920831 DATE WRITTEN 89 | C 921118 Replaced MFLGSV/LUNSAV by IXSAV. (ACH) 90 | C 930329 Modified prologue to SLATEC format. (FNF) 91 | C 930407 Changed MSG from CHARACTER*1 array to variable. (FNF) 92 | C 930922 Minor cosmetic change. (FNF) 93 | C***END PROLOGUE XERRWD 94 | C 95 | C*Internal Notes: 96 | C 97 | C For a different default logical unit number, IXSAV (or a subsidiary 98 | C routine that it calls) will need to be modified. 99 | C For a different run-abort command, change the statement following 100 | C statement 100 at the end. 101 | C----------------------------------------------------------------------- 102 | C Subroutines called by XERRWD.. None 103 | C Function routine called by XERRWD.. IXSAV 104 | C----------------------------------------------------------------------- 105 | C**End 106 | C 107 | C Declare arguments. 108 | C 109 | DOUBLE PRECISION R1, R2 110 | INTEGER NMES, NERR, LEVEL, NI, I1, I2, NR 111 | CHARACTER*(*) MSG 112 | C 113 | C Declare local variables. 114 | C 115 | INTEGER LUNIT, IXSAV, MESFLG 116 | C 117 | C Get logical unit number and message print flag. 118 | C 119 | C***FIRST EXECUTABLE STATEMENT XERRWD 120 | LUNIT = IXSAV (1, 0, .FALSE.) 121 | MESFLG = IXSAV (2, 0, .FALSE.) 122 | IF (MESFLG .EQ. 0) GO TO 100 123 | C 124 | C Write the message. 125 | C 126 | WRITE (LUNIT,10) MSG 127 | 10 FORMAT(1X,A) 128 | IF (NI .EQ. 1) WRITE (LUNIT, 20) I1 129 | 20 FORMAT(6X,'In above message, I1 =',I10) 130 | IF (NI .EQ. 2) WRITE (LUNIT, 30) I1,I2 131 | 30 FORMAT(6X,'In above message, I1 =',I10,3X,'I2 =',I10) 132 | IF (NR .EQ. 1) WRITE (LUNIT, 40) R1 133 | 40 FORMAT(6X,'In above message, R1 =',D21.13) 134 | IF (NR .EQ. 2) WRITE (LUNIT, 50) R1,R2 135 | 50 FORMAT(6X,'In above, R1 =',D21.13,3X,'R2 =',D21.13) 136 | C 137 | C Abort the run if LEVEL = 2. 138 | C 139 | 100 IF (LEVEL .NE. 2) RETURN 140 | STOP 141 | C----------------------- End of Subroutine XERRWD ---------------------- 142 | END 143 | *DECK XSETF 144 | SUBROUTINE XSETF (MFLAG) 145 | C***BEGIN PROLOGUE XSETF 146 | C***PURPOSE Reset the error print control flag. 147 | C***LIBRARY MATHLIB 148 | C***CATEGORY R3A 149 | C***TYPE ALL (XSETF-A) 150 | C***KEYWORDS ERROR CONTROL 151 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 152 | C***DESCRIPTION 153 | C 154 | C XSETF sets the error print control flag to MFLAG: 155 | C MFLAG=1 means print all messages (the default). 156 | C MFLAG=0 means no printing. 157 | C 158 | C***SEE ALSO XERMSG, XERRWD, XERRWV 159 | C***REFERENCES (NONE) 160 | C***ROUTINES CALLED IXSAV 161 | C***REVISION HISTORY (YYMMDD) 162 | C 921118 DATE WRITTEN 163 | C 930329 Added SLATEC format prologue. (FNF) 164 | C 930407 Corrected SEE ALSO section. (FNF) 165 | C 930922 Made user-callable, and other cosmetic changes. (FNF) 166 | C***END PROLOGUE XSETF 167 | C 168 | C Subroutines called by XSETF.. None 169 | C Function routine called by XSETF.. IXSAV 170 | C----------------------------------------------------------------------- 171 | C**End 172 | INTEGER MFLAG, JUNK, IXSAV 173 | C 174 | C***FIRST EXECUTABLE STATEMENT XSETF 175 | IF (MFLAG .EQ. 0 .OR. MFLAG .EQ. 1) JUNK = IXSAV (2,MFLAG,.TRUE.) 176 | RETURN 177 | C----------------------- End of Subroutine XSETF ----------------------- 178 | END 179 | *DECK XSETUN 180 | SUBROUTINE XSETUN (LUN) 181 | C***BEGIN PROLOGUE XSETUN 182 | C***PURPOSE Reset the logical unit number for error messages. 183 | C***LIBRARY MATHLIB 184 | C***CATEGORY R3B 185 | C***TYPE ALL (XSETUN-A) 186 | C***KEYWORDS ERROR CONTROL 187 | C***DESCRIPTION 188 | C 189 | C XSETUN sets the logical unit number for error messages to LUN. 190 | C 191 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 192 | C***SEE ALSO XERMSG, XERRWD, XERRWV 193 | C***REFERENCES (NONE) 194 | C***ROUTINES CALLED IXSAV 195 | C***REVISION HISTORY (YYMMDD) 196 | C 921118 DATE WRITTEN 197 | C 930329 Added SLATEC format prologue. (FNF) 198 | C 930407 Corrected SEE ALSO section. (FNF) 199 | C 930922 Made user-callable, and other cosmetic changes. (FNF) 200 | C***END PROLOGUE XSETUN 201 | C 202 | C Subroutines called by XSETUN.. None 203 | C Function routine called by XSETUN.. IXSAV 204 | C----------------------------------------------------------------------- 205 | C**End 206 | INTEGER LUN, JUNK, IXSAV 207 | C 208 | C***FIRST EXECUTABLE STATEMENT XSETUN 209 | IF (LUN .GT. 0) JUNK = IXSAV (1,LUN,.TRUE.) 210 | RETURN 211 | C----------------------- End of Subroutine XSETUN ---------------------- 212 | END 213 | *DECK IXSAV 214 | INTEGER FUNCTION IXSAV (IPAR, IVALUE, ISET) 215 | C***BEGIN PROLOGUE IXSAV 216 | C***SUBSIDIARY 217 | C***PURPOSE Save and recall error message control parameters. 218 | C***LIBRARY MATHLIB 219 | C***CATEGORY R3C 220 | C***TYPE ALL (IXSAV-A) 221 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 222 | C***DESCRIPTION 223 | C 224 | C IXSAV saves and recalls one of two error message parameters: 225 | C LUNIT, the logical unit number to which messages are printed, and 226 | C MESFLG, the message print flag. 227 | C This is a modification of the SLATEC library routine J4SAVE. 228 | C 229 | C Saved local variables.. 230 | C LUNIT = Logical unit number for messages. 231 | C LUNDEF = Default logical unit number, data-loaded to 6 below 232 | C (may be machine-dependent). 233 | C MESFLG = Print control flag.. 234 | C 1 means print all messages (the default). 235 | C 0 means no printing. 236 | C 237 | C On input.. 238 | C IPAR = Parameter indicator (1 for LUNIT, 2 for MESFLG). 239 | C IVALUE = The value to be set for the parameter, if ISET = .TRUE. 240 | C ISET = Logical flag to indicate whether to read or write. 241 | C If ISET = .TRUE., the parameter will be given 242 | C the value IVALUE. If ISET = .FALSE., the parameter 243 | C will be unchanged, and IVALUE is a dummy argument. 244 | C 245 | C On return.. 246 | C IXSAV = The (old) value of the parameter. 247 | C 248 | C***SEE ALSO XERMSG, XERRWD, XERRWV 249 | C***ROUTINES CALLED NONE 250 | C***REVISION HISTORY (YYMMDD) 251 | C 921118 DATE WRITTEN 252 | C 930329 Modified prologue to SLATEC format. (FNF) 253 | C 941025 Minor modification re default unit number. (ACH) 254 | C***END PROLOGUE IXSAV 255 | C 256 | C**End 257 | LOGICAL ISET 258 | INTEGER IPAR, IVALUE 259 | C----------------------------------------------------------------------- 260 | INTEGER LUNIT, LUNDEF, MESFLG 261 | C----------------------------------------------------------------------- 262 | C The following Fortran-77 declaration is to cause the values of the 263 | C listed (local) variables to be saved between calls to this routine. 264 | C----------------------------------------------------------------------- 265 | SAVE LUNIT, LUNDEF, MESFLG 266 | DATA LUNIT/-1/, LUNDEF/6/, MESFLG/1/ 267 | C 268 | C***FIRST EXECUTABLE STATEMENT IXSAV 269 | IF (IPAR .EQ. 1) THEN 270 | IF (LUNIT .EQ. -1) LUNIT = LUNDEF 271 | IXSAV = LUNIT 272 | IF (ISET) LUNIT = IVALUE 273 | ENDIF 274 | C 275 | IF (IPAR .EQ. 2) THEN 276 | IXSAV = MESFLG 277 | IF (ISET) MESFLG = IVALUE 278 | ENDIF 279 | C 280 | RETURN 281 | C----------------------- End of Function IXSAV ------------------------- 282 | END 283 | -------------------------------------------------------------------------------- /daskr/solver/saux.f: -------------------------------------------------------------------------------- 1 | *DECK R1MACH 2 | REAL FUNCTION R1MACH (IDUMMY) 3 | C***BEGIN PROLOGUE R1MACH 4 | C***PURPOSE Compute the unit roundoff of the machine. 5 | C***CATEGORY R1 6 | C***TYPE SINGLE PRECISION (R1MACH-S, D1MACH-D) 7 | C***KEYWORDS MACHINE CONSTANTS 8 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 9 | C***DESCRIPTION 10 | C *Usage: 11 | C REAL A, R1MACH 12 | C A = R1MACH(idummy) [The argument is ignored.] 13 | C 14 | C *Function Return Values: 15 | C A : the unit roundoff of the machine. 16 | C 17 | C *Description: 18 | C The unit roundoff is defined as the smallest positive machine 19 | C number u such that 1.0 + u .ne. 1.0. This is computed by R1MACH 20 | C in a machine-independent manner. 21 | C 22 | C***REFERENCES (NONE) 23 | C***ROUTINES CALLED RUMSUM 24 | C***REVISION HISTORY (YYYYMMDD) 25 | C 19930216 DATE WRITTEN 26 | C 19930818 Added SLATEC-format prologue. (FNF) 27 | C 20030707 Added RUMSUM to force normal storage of COMP. (ACH) 28 | C***END PROLOGUE R1MACH 29 | C 30 | INTEGER IDUMMY 31 | REAL U, COMP 32 | C***FIRST EXECUTABLE STATEMENT R1MACH 33 | U = 1.0E0 34 | 10 U = U*0.5E0 35 | CALL RUMSUM(1.0E0, U, COMP) 36 | IF (COMP .NE. 1.0E0) GO TO 10 37 | R1MACH = U*2.0E0 38 | RETURN 39 | C----------------------- End of Function R1MACH ------------------------ 40 | END 41 | SUBROUTINE RUMSUM(A,B,C) 42 | C Routine to force normal storing of A + B, for R1MACH. 43 | REAL A, B, C 44 | C = A + B 45 | RETURN 46 | END 47 | *DECK XERRWV 48 | SUBROUTINE XERRWV (MSG, NMES, NERR, LEVEL, NI, I1, I2, NR, R1, R2) 49 | C***BEGIN PROLOGUE XERRWV 50 | C***SUBSIDIARY 51 | C***PURPOSE Write error message with values. 52 | C***LIBRARY MATHLIB 53 | C***CATEGORY R3C 54 | C***TYPE SINGLE PRECISION (XERRWV-S, XERRWD-D) 55 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 56 | C***DESCRIPTION 57 | C 58 | C Subroutines XERRWV, XSETF, XSETUN, and the function routine IXSAV, 59 | C as given here, constitute a simplified version of the SLATEC error 60 | C handling package. 61 | C 62 | C All arguments are input arguments. 63 | C 64 | C MSG = The message (character array). 65 | C NMES = The length of MSG (number of characters). 66 | C NERR = The error number (not used). 67 | C LEVEL = The error level.. 68 | C 0 or 1 means recoverable (control returns to caller). 69 | C 2 means fatal (run is aborted--see note below). 70 | C NI = Number of integers (0, 1, or 2) to be printed with message. 71 | C I1,I2 = Integers to be printed, depending on NI. 72 | C NR = Number of reals (0, 1, or 2) to be printed with message. 73 | C R1,R2 = Reals to be printed, depending on NR. 74 | C 75 | C Note.. this routine is machine-dependent and specialized for use 76 | C in limited context, in the following ways.. 77 | C 1. The argument MSG is assumed to be of type CHARACTER, and 78 | C the message is printed with a format of (1X,A). 79 | C 2. The message is assumed to take only one line. 80 | C Multi-line messages are generated by repeated calls. 81 | C 3. If LEVEL = 2, control passes to the statement STOP 82 | C to abort the run. This statement may be machine-dependent. 83 | C 4. R1 and R2 are assumed to be in single precision and are printed 84 | C in E21.13 format. 85 | C 86 | C***ROUTINES CALLED IXSAV 87 | C***REVISION HISTORY (YYMMDD) 88 | C 791129 DATE WRITTEN 89 | C 890413 Heavily revised, with Common eliminated. (ACH, PNB) 90 | C 921118 Replaced MFLGSV/LUNSAV by IXSAV. (ACH) 91 | C 930329 Modified prologue to SLATEC format. (FNF) 92 | C 930407 Changed MSG from CHARACTER*1 array to variable. (FNF) 93 | C 930922 Minor cosmetic change. (FNF) 94 | C***END PROLOGUE XERRWV 95 | C 96 | C*Internal Notes: 97 | C 98 | C For a different default logical unit number, IXSAV (or a subsidiary 99 | C routine that it calls) will need to be modified. 100 | C For a different run-abort command, change the statement following 101 | C statement 100 at the end. 102 | C----------------------------------------------------------------------- 103 | C Subroutines called by XERRWV.. None 104 | C Function routine called by XERRWV.. IXSAV 105 | C----------------------------------------------------------------------- 106 | C**End 107 | C 108 | C Declare arguments. 109 | C 110 | REAL R1, R2 111 | INTEGER NMES, NERR, LEVEL, NI, I1, I2, NR 112 | CHARACTER*(*) MSG 113 | C 114 | C Declare local variables. 115 | C 116 | INTEGER LUNIT, IXSAV, MESFLG 117 | C 118 | C Get logical unit number and message print flag. 119 | C 120 | C***FIRST EXECUTABLE STATEMENT XERRWV 121 | LUNIT = IXSAV (1, 0, .FALSE.) 122 | MESFLG = IXSAV (2, 0, .FALSE.) 123 | IF (MESFLG .EQ. 0) GO TO 100 124 | C 125 | C Write the message. 126 | C 127 | WRITE (LUNIT,10) MSG 128 | 10 FORMAT(1X,A) 129 | IF (NI .EQ. 1) WRITE (LUNIT, 20) I1 130 | 20 FORMAT(6X,'In above message, I1 =',I10) 131 | IF (NI .EQ. 2) WRITE (LUNIT, 30) I1,I2 132 | 30 FORMAT(6X,'In above message, I1 =',I10,3X,'I2 =',I10) 133 | IF (NR .EQ. 1) WRITE (LUNIT, 40) R1 134 | 40 FORMAT(6X,'In above message, R1 =',E21.13) 135 | IF (NR .EQ. 2) WRITE (LUNIT, 50) R1,R2 136 | 50 FORMAT(6X,'In above, R1 =',E21.13,3X,'R2 =',E21.13) 137 | C 138 | C Abort the run if LEVEL = 2. 139 | C 140 | 100 IF (LEVEL .NE. 2) RETURN 141 | STOP 142 | C----------------------- End of Subroutine XERRWV ---------------------- 143 | END 144 | *DECK XSETF 145 | SUBROUTINE XSETF (MFLAG) 146 | C***BEGIN PROLOGUE XSETF 147 | C***PURPOSE Reset the error print control flag. 148 | C***LIBRARY MATHLIB 149 | C***CATEGORY R3A 150 | C***TYPE ALL (XSETF-A) 151 | C***KEYWORDS ERROR CONTROL 152 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 153 | C***DESCRIPTION 154 | C 155 | C XSETF sets the error print control flag to MFLAG: 156 | C MFLAG=1 means print all messages (the default). 157 | C MFLAG=0 means no printing. 158 | C 159 | C***SEE ALSO XERMSG, XERRWD, XERRWV 160 | C***REFERENCES (NONE) 161 | C***ROUTINES CALLED IXSAV 162 | C***REVISION HISTORY (YYMMDD) 163 | C 921118 DATE WRITTEN 164 | C 930329 Added SLATEC format prologue. (FNF) 165 | C 930407 Corrected SEE ALSO section. (FNF) 166 | C 930922 Made user-callable, and other cosmetic changes. (FNF) 167 | C***END PROLOGUE XSETF 168 | C 169 | C Subroutines called by XSETF.. None 170 | C Function routine called by XSETF.. IXSAV 171 | C----------------------------------------------------------------------- 172 | C**End 173 | INTEGER MFLAG, JUNK, IXSAV 174 | C 175 | C***FIRST EXECUTABLE STATEMENT XSETF 176 | IF (MFLAG .EQ. 0 .OR. MFLAG .EQ. 1) JUNK = IXSAV (2,MFLAG,.TRUE.) 177 | RETURN 178 | C----------------------- End of Subroutine XSETF ----------------------- 179 | END 180 | *DECK XSETUN 181 | SUBROUTINE XSETUN (LUN) 182 | C***BEGIN PROLOGUE XSETUN 183 | C***PURPOSE Reset the logical unit number for error messages. 184 | C***LIBRARY MATHLIB 185 | C***CATEGORY R3B 186 | C***TYPE ALL (XSETUN-A) 187 | C***KEYWORDS ERROR CONTROL 188 | C***DESCRIPTION 189 | C 190 | C XSETUN sets the logical unit number for error messages to LUN. 191 | C 192 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 193 | C***SEE ALSO XERMSG, XERRWD, XERRWV 194 | C***REFERENCES (NONE) 195 | C***ROUTINES CALLED IXSAV 196 | C***REVISION HISTORY (YYMMDD) 197 | C 921118 DATE WRITTEN 198 | C 930329 Added SLATEC format prologue. (FNF) 199 | C 930407 Corrected SEE ALSO section. (FNF) 200 | C 930922 Made user-callable, and other cosmetic changes. (FNF) 201 | C***END PROLOGUE XSETUN 202 | C 203 | C Subroutines called by XSETUN.. None 204 | C Function routine called by XSETUN.. IXSAV 205 | C----------------------------------------------------------------------- 206 | C**End 207 | INTEGER LUN, JUNK, IXSAV 208 | C 209 | C***FIRST EXECUTABLE STATEMENT XSETUN 210 | IF (LUN .GT. 0) JUNK = IXSAV (1,LUN,.TRUE.) 211 | RETURN 212 | C----------------------- End of Subroutine XSETUN ---------------------- 213 | END 214 | *DECK IXSAV 215 | INTEGER FUNCTION IXSAV (IPAR, IVALUE, ISET) 216 | C***BEGIN PROLOGUE IXSAV 217 | C***SUBSIDIARY 218 | C***PURPOSE Save and recall error message control parameters. 219 | C***LIBRARY MATHLIB 220 | C***CATEGORY R3C 221 | C***TYPE ALL (IXSAV-A) 222 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 223 | C***DESCRIPTION 224 | C 225 | C IXSAV saves and recalls one of two error message parameters: 226 | C LUNIT, the logical unit number to which messages are printed, and 227 | C MESFLG, the message print flag. 228 | C This is a modification of the SLATEC library routine J4SAVE. 229 | C 230 | C Saved local variables.. 231 | C LUNIT = Logical unit number for messages. 232 | C LUNDEF = Default logical unit number, data-loaded to 6 below 233 | C (may be machine-dependent). 234 | C MESFLG = Print control flag.. 235 | C 1 means print all messages (the default). 236 | C 0 means no printing. 237 | C 238 | C On input.. 239 | C IPAR = Parameter indicator (1 for LUNIT, 2 for MESFLG). 240 | C IVALUE = The value to be set for the parameter, if ISET = .TRUE. 241 | C ISET = Logical flag to indicate whether to read or write. 242 | C If ISET = .TRUE., the parameter will be given 243 | C the value IVALUE. If ISET = .FALSE., the parameter 244 | C will be unchanged, and IVALUE is a dummy argument. 245 | C 246 | C On return.. 247 | C IXSAV = The (old) value of the parameter. 248 | C 249 | C***SEE ALSO XERMSG, XERRWD, XERRWV 250 | C***ROUTINES CALLED NONE 251 | C***REVISION HISTORY (YYMMDD) 252 | C 921118 DATE WRITTEN 253 | C 930329 Modified prologue to SLATEC format. (FNF) 254 | C 941025 Minor modification re default unit number. (ACH) 255 | C***END PROLOGUE IXSAV 256 | C 257 | C**End 258 | LOGICAL ISET 259 | INTEGER IPAR, IVALUE 260 | C----------------------------------------------------------------------- 261 | INTEGER LUNIT, LUNDEF, MESFLG 262 | C----------------------------------------------------------------------- 263 | C The following Fortran-77 declaration is to cause the values of the 264 | C listed (local) variables to be saved between calls to this routine. 265 | C----------------------------------------------------------------------- 266 | SAVE LUNIT, LUNDEF, MESFLG 267 | DATA LUNIT/-1/, LUNDEF/6/, MESFLG/1/ 268 | C 269 | C***FIRST EXECUTABLE STATEMENT IXSAV 270 | IF (IPAR .EQ. 1) THEN 271 | IF (LUNIT .EQ. -1) LUNIT = LUNDEF 272 | IXSAV = LUNIT 273 | IF (ISET) LUNIT = IVALUE 274 | ENDIF 275 | C 276 | IF (IPAR .EQ. 2) THEN 277 | IXSAV = MESFLG 278 | IF (ISET) MESFLG = IVALUE 279 | ENDIF 280 | C 281 | RETURN 282 | C----------------------- End of Function IXSAV ------------------------- 283 | END 284 | -------------------------------------------------------------------------------- /daspk.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file daspk.h 3 | * 4 | * Contains the function prototype for exposing the Fortran differential 5 | * equation solver DDASPK3.1 to C/C++. 6 | */ 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /** 13 | * Typedef for residual functions. 14 | */ 15 | typedef void (*residual_function)(double* t, double* y, double* yprime, double* cj, double* delta, int* ires, double* rpar, int* ipar, double* senpar); 16 | 17 | /** 18 | * Typedef for Jacobian functions. 19 | */ 20 | typedef void (*jacobian_function)(double* t, double* y, double* yprime, double* pd, double* cj, double* rpar, int* ipar, double* senpar, int* ijac); 21 | 22 | /** 23 | * Typedef for Psol functions. 24 | */ 25 | typedef void (*psol_function)(int* neq, double* wp, int* iwp, double* b, int* ier, double* rpar, int* ipar); 26 | 27 | 28 | /** 29 | * Typedef for G_res functions. 30 | */ 31 | typedef void (*g_res_function)(double* t, double* y, double* yprime, double* pd, double* cj, double* rpar, int* ipar, double* senpar, int* ijac); 32 | 33 | /** 34 | * Exposes the Fortran differential equation solver DASPK to C/C++. 35 | */ 36 | int ddaspk_( 37 | residual_function res, /** The residual function that defines the ODE/DAE system */ 38 | int* neq, /** The number of equations to be solved: including state variables and sensitivity variables */ 39 | double* t, /** The current value of the independent variable */ 40 | double* y, /** The current values of the dependent variables: solution (and sensitivity) components at T */ 41 | double* yprime, /** The current values of the first derivatives of the dependent variables */ 42 | double* tout, /** The value of the independent variable at which a solution is desired */ 43 | int* info, /** Parameters controlling how the integration is performed */ 44 | double* rtol, /** The relative error tolerance(s), either as a scalar or a vector of length NEQ */ 45 | double* atol, /** The absolute error tolerance(s), either as a scalar or a vector of length NEQ */ 46 | int* idid, /** Report of the solver actions, used to control subsequent calls */ 47 | double* rwork, /** Work space for double-precision values */ 48 | int* lrw, /** The length of the double-precision workspace */ 49 | int* iwork, /** Work space for integer values */ 50 | int* liw, /** The length of the integer workspace */ 51 | double* rpar, /** Double-precision parameters to pass to the residual and Jacobian functions */ 52 | int* ipar, /** Integer parameters to pass to the residual and Jacobian functions */ 53 | jacobian_function jac, /** The Jacobian function */ 54 | psol_function psol, /** Function for the preconditioner P for linear systems if Krylov method is selected */ 55 | double* senpar, /** Vector of sensitivity parameters that appear in res routine */ 56 | g_res_function g_res /** Optional adifor routine for evaluation of sensitivity equations */ 57 | ); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | -------------------------------------------------------------------------------- /daspk/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # 3 | # Makefile for DASPK 4 | # 5 | ################################################################################ 6 | 7 | F77=gfortran 8 | 9 | CFLAGS=-fPIC -O3 10 | 11 | DOBJ=solver/daux.o solver/ddaspk.o solver/dlinpk.o preconds/dbanpre.o preconds/dilupre.o preconds/drbdpre.o preconds/drbgpre.o preconds/dsparsk.o 12 | 13 | SOBJ=solver/saux.o solver/sdaspk.o solver/slinpk.o preconds/sbanpre.o preconds/silupre.o preconds/srbdpre.o preconds/srbgpre.o preconds/ssparsk.o 14 | 15 | DLIB=libddaspk.a 16 | 17 | SLIB=libsdaspk.a 18 | 19 | all: $(DLIB) $(SLIB) 20 | 21 | $(DLIB): $(DOBJ) 22 | ar rcs $(DLIB) $(DOBJ) 23 | 24 | $(SLIB): $(SOBJ) 25 | ar rcs $(SLIB) $(SOBJ) 26 | 27 | %.o: %.f 28 | $(F77) $(CFLAGS) -c $< -o $@ 29 | 30 | clean: 31 | rm -f $(DLIB) $(DOBJ) $(SLIB) $(SOBJ) 32 | -------------------------------------------------------------------------------- /daspk/README: -------------------------------------------------------------------------------- 1 | 2 | 3 | DASPK Package - 1995 Revision 4 | P. N. Brown 5 | A. C. Hindmarsh 6 | L. R. Petzold 7 | 8 | 9 | DASPK is a solver [1] for systems of differential-algebraic equations. 10 | It includes options for both direct and iterative (Krylov) methods for 11 | the solution of the linear systems arising at each (implicit) time step. 12 | 13 | The 1995 revision to DASPK includes a completely new procedure [2] for 14 | calculating consistent initial conditions for a large class of 15 | problems (which includes semi-explicit index-1 systems). This 16 | procedure includes options for inequality constraints on selected 17 | components. The package also includes a new option to omit the 18 | algebraic components from the local error control. 19 | 20 | Along with the solver itself, the DASPK package includes four example 21 | programs and a set of general-purpose preconditioner files. These are 22 | described in more detail below. The package includes separate single 23 | and double precision versions of all source files. 24 | 25 | 26 | Package Contents 27 | ---------------- 28 | 29 | 1. The DASPK package is being distributed in the form of a tar file, 30 | which expands to a directory, DASPK. The DASPK directory contains 31 | this README file and three subdirectories. 32 | 33 | 2. The subdirectory DASPK/solver contains the following source files: 34 | 35 | ddaspk.f = main solver source, double precision 36 | dlinpk.f = required LINPACK/BLAS routines, double precision 37 | daux.f = machine constant and error handler, double precision 38 | 39 | sdaspk.f = main solver source, single precision 40 | slinpk.f = required LINPACK/BLAS routines, single precision 41 | saux.f = machine constant and error handler, single precision 42 | 43 | The LINPACK/BLAS files are provided for the sake of completeness, but 44 | the target machine/system of interest may already have optimized 45 | versions of these routines, which should be used instead for the sake 46 | of efficiency. 47 | 48 | A complete usage document is included as the initial prologue of the 49 | source file *daspk.f. 50 | 51 | 3. The subdirectory DASPK/examples contains the following files: 52 | 53 | dheat.f = heat equation example program, double precision, using 54 | the Krylov option with banded preconditioner 55 | dheatilu.f = heat equation example program, double precision, using 56 | the Krylov option with sparse ILU preconditioner 57 | dweb.f = food web system example program, double precision, using 58 | the direct (band) option, and the Krylov option with a 59 | product preconditioner based on reaction-transport form 60 | dwebilu.f = food web system example program, double precision, using 61 | the Krylov option with sparse ILU preconditioner 62 | makedh = Make-file to compile and load dheat program 63 | makedhilu = Make-file to compile and load dheatilu program 64 | makedw = Make-file to compile and load dweb program 65 | makedwilu = Make-file to compile and load dwebilu program 66 | 67 | sheat.f = heat equation example program, single precision, using 68 | the Krylov option with banded preconditioner 69 | sheatilu.f = heat equation example program, single precision, using 70 | the Krylov option with sparse ILU preconditioner 71 | sweb.f = food web system example program, single precision, using 72 | the direct (band) option, and the Krylov option with a 73 | product preconditioner based on reaction-transport form 74 | swebilu.f = food web system example program, single precision, using 75 | the Krylov option with sparse ILU preconditioner 76 | makesh = Make-file to compile and load sheat program 77 | makeshilu = Make-file to compile and load sheatilu program 78 | makesw = Make-file to compile and load sweb program 79 | makeswilu = Make-file to compile and load swebilu program 80 | 81 | dheat.out = output from dheat.f program 82 | dheatilu.out = output from dheatilu.f program 83 | dweb.out = output from dweb.f program 84 | dwebilu.out = output from dwebilu.f program 85 | 86 | All of these examples make use of preconditioner routines, provided in 87 | the files described below, when calling DASPK with the Krylov method 88 | option. All are heavily commented and intended for use as models for 89 | real user applications of DASPK. 90 | 91 | 4. The subdirectory DASPK/preconds contains the following source files: 92 | 93 | dbanpre.f = preconditioner for banded problems, double precision 94 | drbdpre.f = routines for a reaction-based block-diagonal precond- 95 | itioner for DAEs arising from a reaction-transport 96 | system, without block-grouping, double precision 97 | drbgpre.f = routines for a reaction-based block-diagonal precond- 98 | itioner for DAEs arising from a reaction-transport 99 | system, with block-grouping, double precision 100 | dilupre.f = preconditioner routines for sparse ILU preconditioning, 101 | double precision, intended for general DAE problems. 102 | dsparsk.f = routines from SPARSKIT, Y. Saad (Univ. of Minnesota), 103 | double precision, used by dilupre.f 104 | 105 | sbanpre.f = preconditioner for banded problems, single precision 106 | srbdpre.f = routines for a reaction-based block-diagonal precond- 107 | itioner for DAEs arising from a reaction-transport 108 | system, without block-grouping, single precision 109 | srbgpre.f = routines for a reaction-based block-diagonal precond- 110 | itioner for DAEs arising from a reaction-transport 111 | system, with block-grouping, single precision 112 | silupre.f = preconditioner routines for sparse ILU preconditioning, 113 | single precision, intended for general DAE problems. 114 | ssparsk.f = routines from SPARSKIT, Y. Saad (Univ. of Minnesota), 115 | single precision, used by silupre.f 116 | 117 | At the beginning of each of these source files is a prologue which 118 | documents the contents of the file and the usage of the routines in it. 119 | 120 | 121 | Installation and Usage Notes 122 | ---------------------------- 123 | 124 | 1. The single and double precision versions of the SPARSKIT subset, in 125 | the files ssparsk.f and dsparsk.f in DASPK/preconds, cannot be 126 | installed together as a single library, because of name duplications 127 | among the individual routines. If such a combined installation is 128 | desired, first change the names of all precision-dependent subroutines 129 | in either ssparsk.f or dsparsk.f, so as to have unique names across 130 | the two files. Then make the same name changes in the corresponding 131 | file silupre.f or dilupre.f which calls those SPARSKIT routines. 132 | 133 | 2. The four example problems can be compiled and loaded using the 134 | appropriate make-file in DASPK/examples. First check the compiler and 135 | flags in the make-file, however. Each make-file finds the required 136 | solver and preconditioner source or object files in ../solver and 137 | ../preconds. The output files for all four examples, as run in double 138 | precision on a Sun Sparc-10 Workstation, are provided in the files 139 | d*.out. The results on other systems may differ slightly. 140 | 141 | 3. The example programs that use ILU preconditioning, if altered to 142 | use the option JACOUT = 1, write an additional output file containing 143 | the initial Jacobian and residual vector in Boeing-Harwell format. A 144 | map of the Jacobian as a postscript file can then be generated using 145 | the SPARSKIT routines readmt and pspltm. Details are available from 146 | the authors on request. 147 | 148 | 4. Users of DASPK with a sparse ILU preconditioner are encouraged to 149 | experiment with the many options available in the SPARSKIT package, 150 | as accessed through the dilupre.f/silupre.f modules provided. See the 151 | prologue in those files, and the two examples that use ILU. 152 | 153 | 5. Important Note: The use of single precision on a 32-bit machine is 154 | strongly discouraged. The amplification of roundoff errors by the 155 | integration and linear system solution algorithms is such that double 156 | precision is generally required on short-wordlength machines. In 157 | particular, the food web example programs provided here do not run on 158 | a 32-bit machine in single precision, with even the moderate tolerance 159 | values of 1.0e-5. 160 | 161 | 162 | References 163 | ---------- 164 | [1] P. N. Brown, A. C. Hindmarsh, and L. R. Petzold, Using Krylov 165 | Methods in the Solution of Large-Scale Differential-Algebraic 166 | Systems, SIAM J. Sci. Comp., 15 (1994), pp. 1467-1488. 167 | 168 | [2] P. N. Brown, A. C. Hindmarsh, and L. R. Petzold, Consistent 169 | Initial Condition Calculation for Differential-Algebraic 170 | Systems, SIAM J. Sci. Comp. 19 (1998), pp. 1495-1512. 171 | 172 | 173 | Last revised: 13 December 2000 174 | ------------------------------------------------------------------ 175 | Work performed under the auspices of the U.S. Department of Energy 176 | by Lawrence Livermore National Laboratory under contract number 177 | W-7405-Eng-48. 178 | -------------------------------------------------------------------------------- /daspk/examples/dheat.out: -------------------------------------------------------------------------------- 1 | Heat Equation Example Program for DDASPK 2 | 3 | M+2 by M+2 mesh, M = 10, System size NEQ = 144 4 | 5 | Linear solver method flag INFO(12) = 1 (0 = direct, 1 = Krylov) 6 | Preconditioner is a banded approximation with ML = 1 MU = 1 7 | 8 | Tolerances are RTOL = 0.0E+00 ATOL = 0.1E-02 9 | 10 | 11 | t UMAX NQ H STEPS NNI NLI 12 | 13 | 0.10000E-01 0.8320E+00 2 0.256E-02 12 20 16 14 | 0.20000E-01 0.6952E+00 2 0.461E-02 15 25 25 15 | 0.40000E-01 0.4749E+00 3 0.922E-02 18 29 32 16 | 0.80000E-01 0.2176E+00 4 0.922E-02 23 35 43 17 | 0.16000E+00 0.4506E-01 4 0.184E-01 28 41 59 18 | 0.32000E+00 0.1970E-02 4 0.369E-01 36 51 82 19 | 0.64000E+00 0.4749E-04 1 0.147E+00 41 60 107 20 | 0.12800E+01 0.6090E-04 1 0.590E+00 43 64 114 21 | 0.25600E+01 0.6385E-04 1 0.118E+01 44 65 116 22 | 0.51200E+01 0.6832E-04 1 0.472E+01 46 69 124 23 | 0.10240E+02 0.4698E-04 1 0.944E+01 47 70 128 24 | 25 | 26 | Final statistics for this run.. 27 | RWORK size = 3357 IWORK size = 184 28 | Number of time steps ................ = 47 29 | Number of residual evaluations ...... = 252 30 | Number of preconditioner evaluations = 18 31 | Number of preconditioner solves ..... = 198 32 | Number of nonlinear iterations ...... = 70 33 | Number of linear iterations ......... = 128 34 | Average Krylov subspace dimension = 1.8286 35 | 0 nonlinear conv. failures, 0 linear conv. failures 36 | -------------------------------------------------------------------------------- /daspk/examples/dheatilu.out: -------------------------------------------------------------------------------- 1 | Heat Equation Example Program for DDASPK 2 | 3 | M+2 by M+2 mesh, M = 10, System size NEQ = 144 4 | 5 | Linear solver method flag INFO(12) = 1 (0 = direct, 1 = Krylov) 6 | Preconditioner is a sparse approximation with ML = 1 MU = 1 7 | Incomplete factorization option = 1 (1 = ILUT, 2 = ILUTP) 8 | Tolerances are RTOL = 0.0E+00 ATOL = 0.1E-02 9 | 10 | 11 | t UMAX NQ H STEPS NNI NLI 12 | 13 | 0.10000E-01 0.8320E+00 2 0.256E-02 12 20 16 14 | 0.20000E-01 0.6952E+00 2 0.461E-02 15 25 25 15 | 0.40000E-01 0.4749E+00 3 0.922E-02 18 29 32 16 | 0.80000E-01 0.2176E+00 4 0.922E-02 23 35 43 17 | 0.16000E+00 0.4506E-01 4 0.184E-01 28 41 59 18 | 0.32000E+00 0.1970E-02 4 0.369E-01 36 51 82 19 | 0.64000E+00 0.4811E-04 1 0.147E+00 41 60 107 20 | 0.12800E+01 0.6191E-04 1 0.590E+00 43 63 113 21 | 0.25600E+01 0.8728E-04 1 0.118E+01 44 64 116 22 | 0.51200E+01 0.4619E-04 1 0.472E+01 46 67 124 23 | 0.10240E+02 0.2703E-04 1 0.944E+01 47 69 128 24 | 25 | 26 | Final statistics for this run.. 27 | RWORK size = 5277 IWORK size =4508 28 | Number of time steps ................ = 47 29 | Number of residual evaluations ...... = 197 30 | Number of res. evals. for precond. = 54 31 | Number of preconditioner evaluations = 18 32 | Number of preconditioner solves ..... = 197 33 | Number of nonlinear iterations ...... = 69 34 | Number of linear iterations ......... = 128 35 | Average Krylov subspace dimension = 1.8551 36 | 0 nonlinear conv. failures, 0 linear conv. failures 37 | Minimum lengths for work arrays WP and IWP: 2448 4321 38 | -------------------------------------------------------------------------------- /daspk/examples/makedh: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the DDASPK example program dheat. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/ddaspk.o $(SOLVR)/daux.o $(SOLVR)/dlinpk.o \ 14 | $(PRECON)/dbanpre.o 15 | 16 | HEAT = dheat.o $(OBJS) 17 | 18 | HEAT : $(HEAT) 19 | $(COMP) $(FFLAGS) -o heat $(HEAT) -lm 20 | 21 | dheat.o: dheat.f 22 | $(COMP) $(FFLAGS) -c dheat.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daspk/examples/makedhilu: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the DDASPK example program dheatilu. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/ddaspk.o $(SOLVR)/daux.o $(SOLVR)/dlinpk.o \ 14 | $(PRECON)/dilupre.o $(PRECON)/dsparsk.o 15 | 16 | HEATILU = dheatilu.o $(OBJS) 17 | 18 | HEATILU : $(HEATILU) 19 | $(COMP) $(FFLAGS) -o heatilu $(HEATILU) -lm 20 | 21 | dheatilu.o: dheatilu.f 22 | $(COMP) $(FFLAGS) -c dheatilu.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daspk/examples/makedw: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the DDASPK example program dweb. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/ddaspk.o $(SOLVR)/daux.o $(SOLVR)/dlinpk.o \ 14 | $(PRECON)/drbdpre.o $(PRECON)/drbgpre.o 15 | 16 | WEB = dweb.o $(OBJS) 17 | 18 | WEB : $(WEB) 19 | $(COMP) $(FFLAGS) -o web $(WEB) -lm 20 | 21 | dweb.o: dweb.f 22 | $(COMP) $(FFLAGS) -c dweb.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daspk/examples/makedwilu: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the DDASPK example program dwebilu. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/ddaspk.o $(SOLVR)/daux.o $(SOLVR)/dlinpk.o \ 14 | $(PRECON)/dilupre.o $(PRECON)/dsparsk.o 15 | 16 | WEBILU = dwebilu.o $(OBJS) 17 | 18 | WEBILU : $(WEBILU) 19 | $(COMP) $(FFLAGS) -o webilu $(WEBILU) -lm 20 | 21 | dwebilu.o: dwebilu.f 22 | $(COMP) $(FFLAGS) -c dwebilu.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daspk/examples/makesh: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the SDASPK example program sheat. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/sdaspk.o $(SOLVR)/saux.o $(SOLVR)/slinpk.o \ 14 | $(PRECON)/sbanpre.o 15 | 16 | HEAT = sheat.o $(OBJS) 17 | 18 | HEAT : $(HEAT) 19 | $(COMP) $(FFLAGS) -o heat $(HEAT) -lm 20 | 21 | sheat.o: sheat.f 22 | $(COMP) $(FFLAGS) -c sheat.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daspk/examples/makeshilu: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the SDASPK example program sheatilu. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/sdaspk.o $(SOLVR)/saux.o $(SOLVR)/slinpk.o \ 14 | $(PRECON)/silupre.o $(PRECON)/ssparsk.o 15 | 16 | HEATILU = sheatilu.o $(OBJS) 17 | 18 | HEATILU : $(HEATILU) 19 | $(COMP) $(FFLAGS) -o heatilu $(HEATILU) -lm 20 | 21 | sheatilu.o: sheatilu.f 22 | $(COMP) $(FFLAGS) -c sheatilu.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daspk/examples/makesw: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the DDASPK example program sweb. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/sdaspk.o $(SOLVR)/saux.o $(SOLVR)/slinpk.o \ 14 | $(PRECON)/srbdpre.o $(PRECON)/srbgpre.o 15 | 16 | WEB = sweb.o $(OBJS) 17 | 18 | WEB : $(WEB) 19 | $(COMP) $(FFLAGS) -o web $(WEB) -lm 20 | 21 | sweb.o: sweb.f 22 | $(COMP) $(FFLAGS) -c sweb.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daspk/examples/makeswilu: -------------------------------------------------------------------------------- 1 | # 2 | # This makefile compiles and loads the DDASPK example program swebilu. 3 | # If necessary, change the constants COMP and FFLAGS below for the 4 | # compiler to be used. 5 | 6 | COMP = f77 7 | FFLAGS = -O 8 | 9 | SOLVR = ../solver 10 | 11 | PRECON = ../preconds 12 | 13 | OBJS = $(SOLVR)/sdaspk.o $(SOLVR)/saux.o $(SOLVR)/slinpk.o \ 14 | $(PRECON)/silupre.o $(PRECON)/ssparsk.o 15 | 16 | WEBILU = swebilu.o $(OBJS) 17 | 18 | WEBILU : $(WEBILU) 19 | $(COMP) $(FFLAGS) -o webilu $(WEBILU) -lm 20 | 21 | swebilu.o: swebilu.f 22 | $(COMP) $(FFLAGS) -c swebilu.f 23 | 24 | 25 | # Rule for compiling a Fortran source file: 26 | .f.o: ; $(COMP) $(FFLAGS) -c $*.f -o $*.o 27 | -------------------------------------------------------------------------------- /daspk/preconds/dbanpre.f: -------------------------------------------------------------------------------- 1 | C----------------------------------------------------------------------- 2 | C 3 | C Preconditioner Routines for Banded Problems 4 | C 14 September 1995 5 | C 6 | C The following pair of subroutines -- DBANJA and DBANPS -- provides a 7 | C general-purpose banded preconditioner matrix for use with the DDASPK 8 | C solver, with the Krylov linear system method. When using DDASPK to 9 | C solve a problem G(t,y,y') = 0, whose iteration matrix (Jacobian) 10 | C J = dG/dy + c * dG/dy' (c = scalar) 11 | C is either banded or approximately equal to a banded matrix, these 12 | C routines can be used to generate a banded approximation to J as the 13 | C preconditioner and to solve the resulting banded linear system, in 14 | C conjunction with the Krylov method option (INFO(12) = 1) in DDASPK. 15 | C 16 | C Other than the user-supplied residual routine RES defining G(t,y,y'), 17 | C the only other inputs required by these routines are the 18 | C half-bandwidth parameters ML and MU of the approximate banded 19 | C Jacobian. If the system size is NEQ, the half-bandwidths are 20 | C defined as integers between 0 and NEQ - 1 such that only elements 21 | C with indices (i,j) satisfying 22 | C -ML .le. j - i .le. MU 23 | C are to be retained in the preconditioner. E.g., if ML = MU = 0, a 24 | C diagonal matrix will be generated as the preconditioner. The banded 25 | C preconditioner is obtained by difference quotient approximations. If 26 | C the true problem Jacobian is not banded but is approximately equal to 27 | C a matrix that is banded, the procedure used here will have the effect 28 | C of lumping the elements outside of the band onto the elements within 29 | C the band. 30 | C 31 | C To use these routines in conjunction with DDASPK, the user's calling 32 | C program should include the following, in addition to setting the other 33 | C DDASPK input parameters. 34 | C 35 | C (a) Dimension the array IPAR to have length at least 2, and load the 36 | C half-bandwidths into IPAR as 37 | C IPAR(1) = ML and IPAR(2) = MU 38 | C IPAR is used to communicate these parameters to DBANJA and DBANPS. 39 | C If the user program also uses IPAR for communication with RES, 40 | C that data should be located beyond the first 2 words of IPAR. 41 | C 42 | C (b) Include the names DBANJA and DBANPS in an EXTERNAL statement. 43 | C Set INFO(15) = 1 to indicate that a JAC routine exists. 44 | C Then in the call to DDASPK, pass the names DBANJA and DBANPS as 45 | C the arguments JAC and PSOL, respectively. 46 | C 47 | C (c) The DDASPK work arrays RWORK and IWORK must include segments WP 48 | C and IWP for use by DBANJA/DBANPS. The lengths of these depend on 49 | C the problem size and half-bandwidths, as follows: 50 | C LWP = length of RWORK segment WP = 51 | C (2*ML + MU + 1)*NEQ + 2*( (NEQ/(ML+MU+1)) + 1) 52 | C LIWP = length of IWORK segment IWP = NEQ 53 | C (Note the integer divide in LWP.) Load these lengths in IWORK as 54 | C IWORK(27) = LWP 55 | C IWORK(28) = LIWP 56 | C and include these values in the declared size of RWORK and IWORK. 57 | C 58 | C 59 | C The DBANJA and DBANPS routines generate and solve the banded 60 | C preconditioner matrix P within the preconditioned Krylov algorithm 61 | C used by DDASPK when INFO(12) = 1. P is generated and LU-factored 62 | C periodically during the integration, and the factors are used to 63 | C solve systems Px = b as needed. 64 | C----------------------------------------------------------------------- 65 | 66 | 67 | SUBROUTINE DBANJA (RES, IRES, NEQ, T, Y, YPRIME, REWT, SAVR, 68 | * WK, H, CJ, WP, IWP, IER, RPAR, IPAR) 69 | C 70 | C***BEGIN PROLOGUE DBANJA 71 | C***DATE WRITTEN 891204 (YYMMDD) 72 | C***REVISION DATE 900122 73 | C***REVISION DATE 920929 CJ in RES call sequence 74 | C***REVISION DATE 950914 Name change, minor revisions throughout 75 | C***AUTHORS L. R. Petzold, P. N. Brown, A. C. Hindmarsh, C. W. Ulrich 76 | C Numerical Mathematics Group 77 | C Lawrence Livermore National Laboratory 78 | C Livermore, CA 94551 79 | C 80 | C***DESCRIPTION 81 | C 82 | C Subroutine DBANJA generates a banded preconditioner matrix P that 83 | C approximates the DDASPK iteration matrix J = dG/dy + CJ*dG/dy', 84 | C where the DAE system is G(t,y,y') = 0. The band matrix P has 85 | C half-bandwidths ML and MU. It is computed by making (ML + MU + 1) 86 | C calls to the user's RES routine and forming difference quotients, 87 | C exactly as in the banded direct method option of DDASPK. 88 | C DBANJA calls the LINPACK routine DGBFA to do an LU factorization of 89 | C this matrix. 90 | C 91 | C The call sequence parameters have the following meanings. 92 | C 93 | C RES = External user-supplied subroutine to evaluate the 94 | C residuals. See RES description in DDASPK prologue. 95 | C IRES = Output flag set by RES. See RES description in DDASPK. 96 | C NEQ = Problem size. 97 | C T = Independent variable t. 98 | C Y = Array containing current dependent variables y. 99 | C YPRIME = Array containing current derivative y'. 100 | C REWT = Vector of reciprocal error weights, used here for 101 | C computing increments. 102 | C SAVR = Current residual evaluated at (T,Y,YPRIME). 103 | C WK = Real work space of length NEQ. 104 | C H = Current step size. 105 | C CJ = Scalar proportional to 1/H. 106 | C WP = Real work array for P etc. On output, it contains 107 | C the LU decomposition of the banded approximation P. 108 | C IWP = Integer work space for matrix pivot information. 109 | C IER = Output flag, > 0 if P is singular, and 0 otherwise. 110 | C RPAR,IPAR= Real and integer arrays used for communication between 111 | C the calling program and external user routines. 112 | C IPAR(1) and IPAR(2) must contain ML and MU, resp. 113 | C RPAR is not used here. 114 | C 115 | C***ROUTINES CALLED 116 | C D1MACH, DGBFA, RES 117 | C 118 | C***END PROLOGUE DBANJA 119 | C 120 | IMPLICIT DOUBLE PRECISION(A-H,O-Z) 121 | EXTERNAL RES 122 | DIMENSION Y(*), YPRIME(*), SAVR(*), REWT(*), WK(*) 123 | DIMENSION WP(*), IWP(*), RPAR(*), IPAR(*) 124 | C 125 | C Set band parameters. 126 | ML = IPAR(1) 127 | MU = IPAR(2) 128 | MBAND = ML + MU + 1 129 | MBA = MIN(MBAND, NEQ) 130 | MEBAND = MBAND + ML 131 | MEB1 = MEBAND - 1 132 | C 133 | C Set the machine unit roundoff UROUND and SQRT(UROUND), used to 134 | C set increments in the difference quotient procedure. 135 | UROUND = D1MACH(4) 136 | SQUR = SQRT(UROUND) 137 | C 138 | C Set pointers into WP. LENP is the length of the segment for P. 139 | C Following that are two segments of size (NEQ/MBAND), with offsets 140 | C ISAVE and IPSAVE, for temporary storage of Y and YPRIME elements. 141 | LENP = (2*ML+MU+1)*NEQ 142 | MSAVE = (NEQ/MBAND) + 1 143 | ISAVE = LENP 144 | IPSAVE = ISAVE + MSAVE 145 | C 146 | C Initialize error flags. 147 | IER = 0 148 | IRES = 0 149 | C 150 | C Generate the banded approximate iteration matrix P using 151 | C difference quotients on the results of calls to RES. 152 | C 153 | DO 40 J = 1,MBA 154 | DO 10 N = J,NEQ,MBAND 155 | K= (N-J)/MBAND + 1 156 | WP(ISAVE+K) = Y(N) 157 | WP(IPSAVE+K) = YPRIME(N) 158 | DEL = SQUR*MAX(ABS(Y(N)), ABS(H*YPRIME(N)), ABS(1.D0/REWT(N))) 159 | DEL = SIGN(DEL, H*YPRIME(N)) 160 | DEL = (Y(N) + DEL) - Y(N) 161 | Y(N) = Y(N) + DEL 162 | YPRIME(N) = YPRIME(N) + CJ*DEL 163 | 10 CONTINUE 164 | CALL RES (T, Y, YPRIME, CJ, WK, IRES, RPAR, IPAR) 165 | IF (IRES .LT. 0) RETURN 166 | DO 30 N = J,NEQ,MBAND 167 | K = (N-J)/MBAND + 1 168 | Y(N) = WP(ISAVE+K) 169 | YPRIME(N) = WP(IPSAVE+K) 170 | DEL = SQUR*MAX(ABS(Y(N)), ABS(H*YPRIME(N)), ABS(1.D0/REWT(N))) 171 | DEL = SIGN(DEL, H*YPRIME(N)) 172 | DEL = (Y(N) + DEL) - Y(N) 173 | DELINV = 1.0D0/DEL 174 | I1 = MAX(1, N-MU) 175 | I2 = MIN(NEQ, N+ML) 176 | II = N*MEB1 - ML 177 | DO 20 I = I1,I2 178 | 20 WP(II+I) = (WK(I) - SAVR(I))*DELINV 179 | 30 CONTINUE 180 | 40 CONTINUE 181 | C 182 | C Do LU decomposition of the band matrix P. 183 | C 184 | CALL DGBFA (WP, MEBAND, NEQ, ML, MU, IWP, IER) 185 | RETURN 186 | C 187 | C------------ End of Subroutine DBANJA ------------------------------- 188 | END 189 | 190 | SUBROUTINE DBANPS (NEQ, T, Y, YPRIME, SAVR, WK, CJ, WGHT, 191 | * WP, IWP, B, EPLIN, IER, RPAR, IPAR) 192 | C 193 | C***BEGIN PROLOGUE DBANPS 194 | C***DATE WRITTEN 891204 (YYMMDD) 195 | C***REVISION DATE 900110 (YYMMDD) 196 | C***REVISION DATE 950914 Name change, minor revisions throughout 197 | C***AUTHORS L. R. Petzold, P. N. Brown, A. C. Hindmarsh, C. W. Ulrich 198 | C Numerical Mathematics Group 199 | C Lawrence Livermore National Laboratory 200 | C Livermore, CA 94551 201 | C 202 | C***DESCRIPTION 203 | C 204 | C Subroutine DBANPS uses the factors produced by DBANJA to solve linear 205 | C systems P x = b for the banded preconditioner P and a given vector b. 206 | C It calls the LINPACK routine SGBSL for this. 207 | C 208 | C The call sequence parameters have the following meanings. 209 | C 210 | C NEQ = Problem size. 211 | C T = Independent variable t (not used). 212 | C Y = Array containing current dependent vars. (not used). 213 | C YPRIME = Array containing current derivative (not used). 214 | C SAVR = Current residual evaluated at (T,Y,YPRIME) (not used). 215 | C WK = Real work space of length NEQ (not used). 216 | C CJ = Scalar proportional to 1/H (H = step size) (not used). 217 | C WGHT = Vector of error weights for computing norms (not used). 218 | C WP = Real work array containing the LU decomposition of P. 219 | C IWP = Integer array containing matrix pivot information. 220 | C B = Right-hand side vector on input; solution on output. 221 | C EPLIN = tolerance on linear system solver (not used). 222 | C IER = Output error flag (not used; assumed 0 on input). 223 | C RPAR,IPAR= Real and integer arrays used for communication between 224 | C the calling program and external user routines. 225 | C IPAR(1) and IPAR(2) must contain ML and MU, resp. 226 | C RPAR is not used here. 227 | C 228 | C***ROUTINES CALLED 229 | C DGBSL 230 | C 231 | C***END PROLOGUE DBANPS 232 | C 233 | IMPLICIT DOUBLE PRECISION(A-H,O-Z) 234 | DIMENSION B(*),WP(*),IWP(*),RPAR(*),IPAR(*) 235 | C 236 | ML = IPAR(1) 237 | MU = IPAR(2) 238 | MEBAND = 2*ML + MU + 1 239 | CALL DGBSL (WP, MEBAND, NEQ, ML, MU, IWP, B, 0) 240 | RETURN 241 | C 242 | C------------ End of Subroutine DBANPS ------------------------------- 243 | END 244 | -------------------------------------------------------------------------------- /daspk/solver/daux.f: -------------------------------------------------------------------------------- 1 | *DECK D1MACH 2 | DOUBLE PRECISION FUNCTION D1MACH (IDUMMY) 3 | C***BEGIN PROLOGUE D1MACH 4 | C***PURPOSE Compute the unit roundoff of the machine. 5 | C***CATEGORY R1 6 | C***TYPE DOUBLE PRECISION (R1MACH-S, D1MACH-D) 7 | C***KEYWORDS MACHINE CONSTANTS 8 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 9 | C***DESCRIPTION 10 | C *Usage: 11 | C DOUBLE PRECISION A, D1MACH 12 | C A = D1MACH(idummy) [The argument is ignored.] 13 | C 14 | C *Function Return Values: 15 | C A : the unit roundoff of the machine. 16 | C 17 | C *Description: 18 | C The unit roundoff is defined as the smallest positive machine 19 | C number u such that 1.0 + u .ne. 1.0. This is computed by D1MACH 20 | C in a machine-independent manner. 21 | C 22 | C***REFERENCES (NONE) 23 | C***ROUTINES CALLED DUMSUM 24 | C***REVISION HISTORY (YYYYMMDD) 25 | C 19930216 DATE WRITTEN 26 | C 19930818 Added SLATEC-format prologue. (FNF) 27 | C 20030707 Added DUMSUM to force normal storage of COMP. (ACH) 28 | C***END PROLOGUE D1MACH 29 | C 30 | INTEGER IDUMMY 31 | DOUBLE PRECISION U, COMP 32 | C***FIRST EXECUTABLE STATEMENT D1MACH 33 | U = 1.0D0 34 | 10 U = U*0.5D0 35 | CALL DUMSUM(1.0D0, U, COMP) 36 | IF (COMP .NE. 1.0D0) GO TO 10 37 | D1MACH = U*2.0D0 38 | RETURN 39 | C----------------------- End of Function D1MACH ------------------------ 40 | END 41 | SUBROUTINE DUMSUM(A,B,C) 42 | C Routine to force normal storing of A + B, for D1MACH. 43 | DOUBLE PRECISION A, B, C 44 | C = A + B 45 | RETURN 46 | END 47 | *DECK XERRWD 48 | SUBROUTINE XERRWD (MSG, NMES, NERR, LEVEL, NI, I1, I2, NR, R1, R2) 49 | C***BEGIN PROLOGUE XERRWD 50 | C***SUBSIDIARY 51 | C***PURPOSE Write error message with values. 52 | C***LIBRARY MATHLIB 53 | C***CATEGORY R3C 54 | C***TYPE DOUBLE PRECISION (XERRWV-S, XERRWD-D) 55 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 56 | C***DESCRIPTION 57 | C 58 | C Subroutines XERRWD, XSETF, XSETUN, and the function routine IXSAV, 59 | C as given here, constitute a simplified version of the SLATEC error 60 | C handling package. 61 | C 62 | C All arguments are input arguments. 63 | C 64 | C MSG = The message (character array). 65 | C NMES = The length of MSG (number of characters). 66 | C NERR = The error number (not used). 67 | C LEVEL = The error level.. 68 | C 0 or 1 means recoverable (control returns to caller). 69 | C 2 means fatal (run is aborted--see note below). 70 | C NI = Number of integers (0, 1, or 2) to be printed with message. 71 | C I1,I2 = Integers to be printed, depending on NI. 72 | C NR = Number of reals (0, 1, or 2) to be printed with message. 73 | C R1,R2 = Reals to be printed, depending on NR. 74 | C 75 | C Note.. this routine is machine-dependent and specialized for use 76 | C in limited context, in the following ways.. 77 | C 1. The argument MSG is assumed to be of type CHARACTER, and 78 | C the message is printed with a format of (1X,A). 79 | C 2. The message is assumed to take only one line. 80 | C Multi-line messages are generated by repeated calls. 81 | C 3. If LEVEL = 2, control passes to the statement STOP 82 | C to abort the run. This statement may be machine-dependent. 83 | C 4. R1 and R2 are assumed to be in double precision and are printed 84 | C in D21.13 format. 85 | C 86 | C***ROUTINES CALLED IXSAV 87 | C***REVISION HISTORY (YYMMDD) 88 | C 920831 DATE WRITTEN 89 | C 921118 Replaced MFLGSV/LUNSAV by IXSAV. (ACH) 90 | C 930329 Modified prologue to SLATEC format. (FNF) 91 | C 930407 Changed MSG from CHARACTER*1 array to variable. (FNF) 92 | C 930922 Minor cosmetic change. (FNF) 93 | C***END PROLOGUE XERRWD 94 | C 95 | C*Internal Notes: 96 | C 97 | C For a different default logical unit number, IXSAV (or a subsidiary 98 | C routine that it calls) will need to be modified. 99 | C For a different run-abort command, change the statement following 100 | C statement 100 at the end. 101 | C----------------------------------------------------------------------- 102 | C Subroutines called by XERRWD.. None 103 | C Function routine called by XERRWD.. IXSAV 104 | C----------------------------------------------------------------------- 105 | C**End 106 | C 107 | C Declare arguments. 108 | C 109 | DOUBLE PRECISION R1, R2 110 | INTEGER NMES, NERR, LEVEL, NI, I1, I2, NR 111 | CHARACTER*(*) MSG 112 | C 113 | C Declare local variables. 114 | C 115 | INTEGER LUNIT, IXSAV, MESFLG 116 | C 117 | C Get logical unit number and message print flag. 118 | C 119 | C***FIRST EXECUTABLE STATEMENT XERRWD 120 | LUNIT = IXSAV (1, 0, .FALSE.) 121 | MESFLG = IXSAV (2, 0, .FALSE.) 122 | IF (MESFLG .EQ. 0) GO TO 100 123 | C 124 | C Write the message. 125 | C 126 | WRITE (LUNIT,10) MSG 127 | 10 FORMAT(1X,A) 128 | IF (NI .EQ. 1) WRITE (LUNIT, 20) I1 129 | 20 FORMAT(6X,'In above message, I1 =',I10) 130 | IF (NI .EQ. 2) WRITE (LUNIT, 30) I1,I2 131 | 30 FORMAT(6X,'In above message, I1 =',I10,3X,'I2 =',I10) 132 | IF (NR .EQ. 1) WRITE (LUNIT, 40) R1 133 | 40 FORMAT(6X,'In above message, R1 =',D21.13) 134 | IF (NR .EQ. 2) WRITE (LUNIT, 50) R1,R2 135 | 50 FORMAT(6X,'In above, R1 =',D21.13,3X,'R2 =',D21.13) 136 | C 137 | C Abort the run if LEVEL = 2. 138 | C 139 | 100 IF (LEVEL .NE. 2) RETURN 140 | STOP 141 | C----------------------- End of Subroutine XERRWD ---------------------- 142 | END 143 | *DECK XSETF 144 | SUBROUTINE XSETF (MFLAG) 145 | C***BEGIN PROLOGUE XSETF 146 | C***PURPOSE Reset the error print control flag. 147 | C***LIBRARY MATHLIB 148 | C***CATEGORY R3A 149 | C***TYPE ALL (XSETF-A) 150 | C***KEYWORDS ERROR CONTROL 151 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 152 | C***DESCRIPTION 153 | C 154 | C XSETF sets the error print control flag to MFLAG: 155 | C MFLAG=1 means print all messages (the default). 156 | C MFLAG=0 means no printing. 157 | C 158 | C***SEE ALSO XERMSG, XERRWD, XERRWV 159 | C***REFERENCES (NONE) 160 | C***ROUTINES CALLED IXSAV 161 | C***REVISION HISTORY (YYMMDD) 162 | C 921118 DATE WRITTEN 163 | C 930329 Added SLATEC format prologue. (FNF) 164 | C 930407 Corrected SEE ALSO section. (FNF) 165 | C 930922 Made user-callable, and other cosmetic changes. (FNF) 166 | C***END PROLOGUE XSETF 167 | C 168 | C Subroutines called by XSETF.. None 169 | C Function routine called by XSETF.. IXSAV 170 | C----------------------------------------------------------------------- 171 | C**End 172 | INTEGER MFLAG, JUNK, IXSAV 173 | C 174 | C***FIRST EXECUTABLE STATEMENT XSETF 175 | IF (MFLAG .EQ. 0 .OR. MFLAG .EQ. 1) JUNK = IXSAV (2,MFLAG,.TRUE.) 176 | RETURN 177 | C----------------------- End of Subroutine XSETF ----------------------- 178 | END 179 | *DECK XSETUN 180 | SUBROUTINE XSETUN (LUN) 181 | C***BEGIN PROLOGUE XSETUN 182 | C***PURPOSE Reset the logical unit number for error messages. 183 | C***LIBRARY MATHLIB 184 | C***CATEGORY R3B 185 | C***TYPE ALL (XSETUN-A) 186 | C***KEYWORDS ERROR CONTROL 187 | C***DESCRIPTION 188 | C 189 | C XSETUN sets the logical unit number for error messages to LUN. 190 | C 191 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 192 | C***SEE ALSO XERMSG, XERRWD, XERRWV 193 | C***REFERENCES (NONE) 194 | C***ROUTINES CALLED IXSAV 195 | C***REVISION HISTORY (YYMMDD) 196 | C 921118 DATE WRITTEN 197 | C 930329 Added SLATEC format prologue. (FNF) 198 | C 930407 Corrected SEE ALSO section. (FNF) 199 | C 930922 Made user-callable, and other cosmetic changes. (FNF) 200 | C***END PROLOGUE XSETUN 201 | C 202 | C Subroutines called by XSETUN.. None 203 | C Function routine called by XSETUN.. IXSAV 204 | C----------------------------------------------------------------------- 205 | C**End 206 | INTEGER LUN, JUNK, IXSAV 207 | C 208 | C***FIRST EXECUTABLE STATEMENT XSETUN 209 | IF (LUN .GT. 0) JUNK = IXSAV (1,LUN,.TRUE.) 210 | RETURN 211 | C----------------------- End of Subroutine XSETUN ---------------------- 212 | END 213 | *DECK IXSAV 214 | INTEGER FUNCTION IXSAV (IPAR, IVALUE, ISET) 215 | C***BEGIN PROLOGUE IXSAV 216 | C***SUBSIDIARY 217 | C***PURPOSE Save and recall error message control parameters. 218 | C***LIBRARY MATHLIB 219 | C***CATEGORY R3C 220 | C***TYPE ALL (IXSAV-A) 221 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 222 | C***DESCRIPTION 223 | C 224 | C IXSAV saves and recalls one of two error message parameters: 225 | C LUNIT, the logical unit number to which messages are printed, and 226 | C MESFLG, the message print flag. 227 | C This is a modification of the SLATEC library routine J4SAVE. 228 | C 229 | C Saved local variables.. 230 | C LUNIT = Logical unit number for messages. 231 | C LUNDEF = Default logical unit number, data-loaded to 6 below 232 | C (may be machine-dependent). 233 | C MESFLG = Print control flag.. 234 | C 1 means print all messages (the default). 235 | C 0 means no printing. 236 | C 237 | C On input.. 238 | C IPAR = Parameter indicator (1 for LUNIT, 2 for MESFLG). 239 | C IVALUE = The value to be set for the parameter, if ISET = .TRUE. 240 | C ISET = Logical flag to indicate whether to read or write. 241 | C If ISET = .TRUE., the parameter will be given 242 | C the value IVALUE. If ISET = .FALSE., the parameter 243 | C will be unchanged, and IVALUE is a dummy argument. 244 | C 245 | C On return.. 246 | C IXSAV = The (old) value of the parameter. 247 | C 248 | C***SEE ALSO XERMSG, XERRWD, XERRWV 249 | C***ROUTINES CALLED NONE 250 | C***REVISION HISTORY (YYMMDD) 251 | C 921118 DATE WRITTEN 252 | C 930329 Modified prologue to SLATEC format. (FNF) 253 | C 941025 Minor modification re default unit number. (ACH) 254 | C***END PROLOGUE IXSAV 255 | C 256 | C**End 257 | LOGICAL ISET 258 | INTEGER IPAR, IVALUE 259 | C----------------------------------------------------------------------- 260 | INTEGER LUNIT, LUNDEF, MESFLG 261 | C----------------------------------------------------------------------- 262 | C The following Fortran-77 declaration is to cause the values of the 263 | C listed (local) variables to be saved between calls to this routine. 264 | C----------------------------------------------------------------------- 265 | SAVE LUNIT, LUNDEF, MESFLG 266 | DATA LUNIT/-1/, LUNDEF/6/, MESFLG/1/ 267 | C 268 | C***FIRST EXECUTABLE STATEMENT IXSAV 269 | IF (IPAR .EQ. 1) THEN 270 | IF (LUNIT .EQ. -1) LUNIT = LUNDEF 271 | IXSAV = LUNIT 272 | IF (ISET) LUNIT = IVALUE 273 | ENDIF 274 | C 275 | IF (IPAR .EQ. 2) THEN 276 | IXSAV = MESFLG 277 | IF (ISET) MESFLG = IVALUE 278 | ENDIF 279 | C 280 | RETURN 281 | C----------------------- End of Function IXSAV ------------------------- 282 | END 283 | -------------------------------------------------------------------------------- /daspk/solver/saux.f: -------------------------------------------------------------------------------- 1 | *DECK R1MACH 2 | REAL FUNCTION R1MACH (IDUMMY) 3 | C***BEGIN PROLOGUE R1MACH 4 | C***PURPOSE Compute the unit roundoff of the machine. 5 | C***CATEGORY R1 6 | C***TYPE SINGLE PRECISION (R1MACH-S, D1MACH-D) 7 | C***KEYWORDS MACHINE CONSTANTS 8 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 9 | C***DESCRIPTION 10 | C *Usage: 11 | C REAL A, R1MACH 12 | C A = R1MACH(idummy) [The argument is ignored.] 13 | C 14 | C *Function Return Values: 15 | C A : the unit roundoff of the machine. 16 | C 17 | C *Description: 18 | C The unit roundoff is defined as the smallest positive machine 19 | C number u such that 1.0 + u .ne. 1.0. This is computed by R1MACH 20 | C in a machine-independent manner. 21 | C 22 | C***REFERENCES (NONE) 23 | C***ROUTINES CALLED RUMSUM 24 | C***REVISION HISTORY (YYYYMMDD) 25 | C 19930216 DATE WRITTEN 26 | C 19930818 Added SLATEC-format prologue. (FNF) 27 | C 20030707 Added RUMSUM to force normal storage of COMP. (ACH) 28 | C***END PROLOGUE R1MACH 29 | C 30 | INTEGER IDUMMY 31 | REAL U, COMP 32 | C***FIRST EXECUTABLE STATEMENT R1MACH 33 | U = 1.0E0 34 | 10 U = U*0.5E0 35 | CALL RUMSUM(1.0E0, U, COMP) 36 | IF (COMP .NE. 1.0E0) GO TO 10 37 | R1MACH = U*2.0E0 38 | RETURN 39 | C----------------------- End of Function R1MACH ------------------------ 40 | END 41 | SUBROUTINE RUMSUM(A,B,C) 42 | C Routine to force normal storing of A + B, for R1MACH. 43 | REAL A, B, C 44 | C = A + B 45 | RETURN 46 | END 47 | *DECK XERRWD 48 | SUBROUTINE XERRWD (MSG, NMES, NERR, LEVEL, NI, I1, I2, NR, R1, R2) 49 | C***BEGIN PROLOGUE XERRWD 50 | C***SUBSIDIARY 51 | C***PURPOSE Write error message with values. 52 | C***LIBRARY MATHLIB 53 | C***CATEGORY R3C 54 | C***TYPE DOUBLE PRECISION (XERRWV-S, XERRWD-D) 55 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 56 | C***DESCRIPTION 57 | C 58 | C Subroutines XERRWD, XSETF, XSETUN, and the function routine IXSAV, 59 | C as given here, constitute a simplified version of the SLATEC error 60 | C handling package. 61 | C 62 | C All arguments are input arguments. 63 | C 64 | C MSG = The message (character array). 65 | C NMES = The length of MSG (number of characters). 66 | C NERR = The error number (not used). 67 | C LEVEL = The error level.. 68 | C 0 or 1 means recoverable (control returns to caller). 69 | C 2 means fatal (run is aborted--see note below). 70 | C NI = Number of integers (0, 1, or 2) to be printed with message. 71 | C I1,I2 = Integers to be printed, depending on NI. 72 | C NR = Number of reals (0, 1, or 2) to be printed with message. 73 | C R1,R2 = Reals to be printed, depending on NR. 74 | C 75 | C Note.. this routine is machine-dependent and specialized for use 76 | C in limited context, in the following ways.. 77 | C 1. The argument MSG is assumed to be of type CHARACTER, and 78 | C the message is printed with a format of (1X,A). 79 | C 2. The message is assumed to take only one line. 80 | C Multi-line messages are generated by repeated calls. 81 | C 3. If LEVEL = 2, control passes to the statement STOP 82 | C to abort the run. This statement may be machine-dependent. 83 | C 4. R1 and R2 are assumed to be in double precision and are printed 84 | C in D21.13 format. 85 | C 86 | C***ROUTINES CALLED IXSAV 87 | C***REVISION HISTORY (YYMMDD) 88 | C 920831 DATE WRITTEN 89 | C 921118 Replaced MFLGSV/LUNSAV by IXSAV. (ACH) 90 | C 930329 Modified prologue to SLATEC format. (FNF) 91 | C 930407 Changed MSG from CHARACTER*1 array to variable. (FNF) 92 | C 930922 Minor cosmetic change. (FNF) 93 | C***END PROLOGUE XERRWD 94 | C 95 | C*Internal Notes: 96 | C 97 | C For a different default logical unit number, IXSAV (or a subsidiary 98 | C routine that it calls) will need to be modified. 99 | C For a different run-abort command, change the statement following 100 | C statement 100 at the end. 101 | C----------------------------------------------------------------------- 102 | C Subroutines called by XERRWD.. None 103 | C Function routine called by XERRWD.. IXSAV 104 | C----------------------------------------------------------------------- 105 | C**End 106 | C 107 | C Declare arguments. 108 | C 109 | DOUBLE PRECISION R1, R2 110 | INTEGER NMES, NERR, LEVEL, NI, I1, I2, NR 111 | CHARACTER*(*) MSG 112 | C 113 | C Declare local variables. 114 | C 115 | INTEGER LUNIT, IXSAV, MESFLG 116 | C 117 | C Get logical unit number and message print flag. 118 | C 119 | C***FIRST EXECUTABLE STATEMENT XERRWD 120 | LUNIT = IXSAV (1, 0, .FALSE.) 121 | MESFLG = IXSAV (2, 0, .FALSE.) 122 | IF (MESFLG .EQ. 0) GO TO 100 123 | C 124 | C Write the message. 125 | C 126 | WRITE (LUNIT,10) MSG 127 | 10 FORMAT(1X,A) 128 | IF (NI .EQ. 1) WRITE (LUNIT, 20) I1 129 | 20 FORMAT(6X,'In above message, I1 =',I10) 130 | IF (NI .EQ. 2) WRITE (LUNIT, 30) I1,I2 131 | 30 FORMAT(6X,'In above message, I1 =',I10,3X,'I2 =',I10) 132 | IF (NR .EQ. 1) WRITE (LUNIT, 40) R1 133 | 40 FORMAT(6X,'In above message, R1 =',D21.13) 134 | IF (NR .EQ. 2) WRITE (LUNIT, 50) R1,R2 135 | 50 FORMAT(6X,'In above, R1 =',D21.13,3X,'R2 =',D21.13) 136 | C 137 | C Abort the run if LEVEL = 2. 138 | C 139 | 100 IF (LEVEL .NE. 2) RETURN 140 | STOP 141 | C----------------------- End of Subroutine XERRWD ---------------------- 142 | END 143 | *DECK XSETF 144 | SUBROUTINE XSETF (MFLAG) 145 | C***BEGIN PROLOGUE XSETF 146 | C***PURPOSE Reset the error print control flag. 147 | C***LIBRARY MATHLIB 148 | C***CATEGORY R3A 149 | C***TYPE ALL (XSETF-A) 150 | C***KEYWORDS ERROR CONTROL 151 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 152 | C***DESCRIPTION 153 | C 154 | C XSETF sets the error print control flag to MFLAG: 155 | C MFLAG=1 means print all messages (the default). 156 | C MFLAG=0 means no printing. 157 | C 158 | C***SEE ALSO XERMSG, XERRWD, XERRWV 159 | C***REFERENCES (NONE) 160 | C***ROUTINES CALLED IXSAV 161 | C***REVISION HISTORY (YYMMDD) 162 | C 921118 DATE WRITTEN 163 | C 930329 Added SLATEC format prologue. (FNF) 164 | C 930407 Corrected SEE ALSO section. (FNF) 165 | C 930922 Made user-callable, and other cosmetic changes. (FNF) 166 | C***END PROLOGUE XSETF 167 | C 168 | C Subroutines called by XSETF.. None 169 | C Function routine called by XSETF.. IXSAV 170 | C----------------------------------------------------------------------- 171 | C**End 172 | INTEGER MFLAG, JUNK, IXSAV 173 | C 174 | C***FIRST EXECUTABLE STATEMENT XSETF 175 | IF (MFLAG .EQ. 0 .OR. MFLAG .EQ. 1) JUNK = IXSAV (2,MFLAG,.TRUE.) 176 | RETURN 177 | C----------------------- End of Subroutine XSETF ----------------------- 178 | END 179 | *DECK XSETUN 180 | SUBROUTINE XSETUN (LUN) 181 | C***BEGIN PROLOGUE XSETUN 182 | C***PURPOSE Reset the logical unit number for error messages. 183 | C***LIBRARY MATHLIB 184 | C***CATEGORY R3B 185 | C***TYPE ALL (XSETUN-A) 186 | C***KEYWORDS ERROR CONTROL 187 | C***DESCRIPTION 188 | C 189 | C XSETUN sets the logical unit number for error messages to LUN. 190 | C 191 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 192 | C***SEE ALSO XERMSG, XERRWD, XERRWV 193 | C***REFERENCES (NONE) 194 | C***ROUTINES CALLED IXSAV 195 | C***REVISION HISTORY (YYMMDD) 196 | C 921118 DATE WRITTEN 197 | C 930329 Added SLATEC format prologue. (FNF) 198 | C 930407 Corrected SEE ALSO section. (FNF) 199 | C 930922 Made user-callable, and other cosmetic changes. (FNF) 200 | C***END PROLOGUE XSETUN 201 | C 202 | C Subroutines called by XSETUN.. None 203 | C Function routine called by XSETUN.. IXSAV 204 | C----------------------------------------------------------------------- 205 | C**End 206 | INTEGER LUN, JUNK, IXSAV 207 | C 208 | C***FIRST EXECUTABLE STATEMENT XSETUN 209 | IF (LUN .GT. 0) JUNK = IXSAV (1,LUN,.TRUE.) 210 | RETURN 211 | C----------------------- End of Subroutine XSETUN ---------------------- 212 | END 213 | *DECK IXSAV 214 | INTEGER FUNCTION IXSAV (IPAR, IVALUE, ISET) 215 | C***BEGIN PROLOGUE IXSAV 216 | C***SUBSIDIARY 217 | C***PURPOSE Save and recall error message control parameters. 218 | C***LIBRARY MATHLIB 219 | C***CATEGORY R3C 220 | C***TYPE ALL (IXSAV-A) 221 | C***AUTHOR Hindmarsh, Alan C., (LLNL) 222 | C***DESCRIPTION 223 | C 224 | C IXSAV saves and recalls one of two error message parameters: 225 | C LUNIT, the logical unit number to which messages are printed, and 226 | C MESFLG, the message print flag. 227 | C This is a modification of the SLATEC library routine J4SAVE. 228 | C 229 | C Saved local variables.. 230 | C LUNIT = Logical unit number for messages. 231 | C LUNDEF = Default logical unit number, data-loaded to 6 below 232 | C (may be machine-dependent). 233 | C MESFLG = Print control flag.. 234 | C 1 means print all messages (the default). 235 | C 0 means no printing. 236 | C 237 | C On input.. 238 | C IPAR = Parameter indicator (1 for LUNIT, 2 for MESFLG). 239 | C IVALUE = The value to be set for the parameter, if ISET = .TRUE. 240 | C ISET = Logical flag to indicate whether to read or write. 241 | C If ISET = .TRUE., the parameter will be given 242 | C the value IVALUE. If ISET = .FALSE., the parameter 243 | C will be unchanged, and IVALUE is a dummy argument. 244 | C 245 | C On return.. 246 | C IXSAV = The (old) value of the parameter. 247 | C 248 | C***SEE ALSO XERMSG, XERRWD, XERRWV 249 | C***ROUTINES CALLED NONE 250 | C***REVISION HISTORY (YYMMDD) 251 | C 921118 DATE WRITTEN 252 | C 930329 Modified prologue to SLATEC format. (FNF) 253 | C 941025 Minor modification re default unit number. (ACH) 254 | C***END PROLOGUE IXSAV 255 | C 256 | C**End 257 | LOGICAL ISET 258 | INTEGER IPAR, IVALUE 259 | C----------------------------------------------------------------------- 260 | INTEGER LUNIT, LUNDEF, MESFLG 261 | C----------------------------------------------------------------------- 262 | C The following Fortran-77 declaration is to cause the values of the 263 | C listed (local) variables to be saved between calls to this routine. 264 | C----------------------------------------------------------------------- 265 | SAVE LUNIT, LUNDEF, MESFLG 266 | DATA LUNIT/-1/, LUNDEF/6/, MESFLG/1/ 267 | C 268 | C***FIRST EXECUTABLE STATEMENT IXSAV 269 | IF (IPAR .EQ. 1) THEN 270 | IF (LUNIT .EQ. -1) LUNIT = LUNDEF 271 | IXSAV = LUNIT 272 | IF (ISET) LUNIT = IVALUE 273 | ENDIF 274 | C 275 | IF (IPAR .EQ. 2) THEN 276 | IXSAV = MESFLG 277 | IF (ISET) MESFLG = IVALUE 278 | ENDIF 279 | C 280 | RETURN 281 | C----------------------- End of Function IXSAV ------------------------- 282 | END 283 | -------------------------------------------------------------------------------- /daspk31/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # 3 | # Makefile for DASPK3.1 4 | # 5 | ################################################################################ 6 | 7 | F77=gfortran 8 | 9 | CFLAGS=-fPIC -O3 10 | 11 | DOBJ=adf_dummy.o daux.o ddaskr.o ddaspk.o dlinpk.o dsensd.o mpi_dummy.o 12 | 13 | DLIB=libddaspk31.a 14 | 15 | all: $(DLIB) 16 | 17 | $(DLIB): $(DOBJ) 18 | ar rcs $(DLIB) $(DOBJ) 19 | 20 | %.o: %.f 21 | $(F77) $(CFLAGS) -c $< -o $@ 22 | 23 | clean: 24 | rm -f $(DLIB) $(DOBJ) 25 | -------------------------------------------------------------------------------- /daspk31/README: -------------------------------------------------------------------------------- 1 | DASPK 3.1 2 | Large Scale Differential Algebraic Equation Solver with Sensitivity Analysis 3 | 4 | Before using, dump the source files of the DASPK 3.1 solver folder into this folder. 5 | The fortran solver can be downloaded here: http://www.engineering.ucsb.edu/~cse/software.html 6 | The files present should be as follows: 7 | adf_dummy.f 8 | daux.f 9 | ddaskr.f 10 | ddaspk.f 11 | dlinpk.f 12 | dsensd.f 13 | mpi_dummy.f 14 | 15 | Making the PyDAS package will compile the fortran code as well as PyDAS wrappers. 16 | Use the 'make daspk31' command in the parent folder to compile the fortran code for 17 | daspk31 only. 18 | -------------------------------------------------------------------------------- /dassl/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # 3 | # Makefile for DASSL 4 | # 5 | ################################################################################ 6 | 7 | F77=gfortran 8 | 9 | CFLAGS=-fPIC -O3 10 | 11 | DOBJ=daux.o ddassl.o dlinpk.o 12 | 13 | DLIB=libddassl.a 14 | 15 | all: $(DLIB) 16 | 17 | $(DLIB): $(DOBJ) 18 | ar rcs $(DLIB) $(DOBJ) 19 | 20 | %.o: %.f 21 | $(F77) $(CFLAGS) -c $< -o $@ 22 | 23 | clean: 24 | rm -f $(DLIB) $(DOBJ) 25 | -------------------------------------------------------------------------------- /documentation/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 14 | 15 | .PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest 16 | 17 | help: 18 | @echo "Please use \`make ' where is one of" 19 | @echo " html to make standalone HTML files" 20 | @echo " dirhtml to make HTML files named index.html in directories" 21 | @echo " pickle to make pickle files" 22 | @echo " json to make JSON files" 23 | @echo " htmlhelp to make HTML files and a HTML help project" 24 | @echo " qthelp to make HTML files and a qthelp project" 25 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 26 | @echo " changes to make an overview of all changed/added/deprecated items" 27 | @echo " linkcheck to check all external links for integrity" 28 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 29 | 30 | clean: 31 | -rm -rf $(BUILDDIR)/* 32 | 33 | html: 34 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 35 | @echo 36 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 37 | 38 | dirhtml: 39 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 40 | @echo 41 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 42 | 43 | pickle: 44 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 45 | @echo 46 | @echo "Build finished; now you can process the pickle files." 47 | 48 | json: 49 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 50 | @echo 51 | @echo "Build finished; now you can process the JSON files." 52 | 53 | htmlhelp: 54 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 55 | @echo 56 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 57 | ".hhp project file in $(BUILDDIR)/htmlhelp." 58 | 59 | qthelp: 60 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 61 | @echo 62 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 63 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 64 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/PyDAS.qhcp" 65 | @echo "To view the help file:" 66 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/PyDAS.qhc" 67 | 68 | latex: 69 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 70 | @echo 71 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 72 | @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \ 73 | "run these through (pdf)latex." 74 | 75 | changes: 76 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 77 | @echo 78 | @echo "The overview file is in $(BUILDDIR)/changes." 79 | 80 | linkcheck: 81 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 82 | @echo 83 | @echo "Link check complete; look for any errors in the above output " \ 84 | "or in $(BUILDDIR)/linkcheck/output.txt." 85 | 86 | doctest: 87 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 88 | @echo "Testing of doctests in the sources finished, look at the " \ 89 | "results in $(BUILDDIR)/doctest/output.txt." 90 | -------------------------------------------------------------------------------- /documentation/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | set SPHINXBUILD=sphinx-build 6 | set BUILDDIR=build 7 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source 8 | if NOT "%PAPER%" == "" ( 9 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 10 | ) 11 | 12 | if "%1" == "" goto help 13 | 14 | if "%1" == "help" ( 15 | :help 16 | echo.Please use `make ^` where ^ is one of 17 | echo. html to make standalone HTML files 18 | echo. dirhtml to make HTML files named index.html in directories 19 | echo. pickle to make pickle files 20 | echo. json to make JSON files 21 | echo. htmlhelp to make HTML files and a HTML help project 22 | echo. qthelp to make HTML files and a qthelp project 23 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 24 | echo. changes to make an overview over all changed/added/deprecated items 25 | echo. linkcheck to check all external links for integrity 26 | echo. doctest to run all doctests embedded in the documentation if enabled 27 | goto end 28 | ) 29 | 30 | if "%1" == "clean" ( 31 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 32 | del /q /s %BUILDDIR%\* 33 | goto end 34 | ) 35 | 36 | if "%1" == "html" ( 37 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 38 | echo. 39 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 40 | goto end 41 | ) 42 | 43 | if "%1" == "dirhtml" ( 44 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 45 | echo. 46 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 47 | goto end 48 | ) 49 | 50 | if "%1" == "pickle" ( 51 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 52 | echo. 53 | echo.Build finished; now you can process the pickle files. 54 | goto end 55 | ) 56 | 57 | if "%1" == "json" ( 58 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 59 | echo. 60 | echo.Build finished; now you can process the JSON files. 61 | goto end 62 | ) 63 | 64 | if "%1" == "htmlhelp" ( 65 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 66 | echo. 67 | echo.Build finished; now you can run HTML Help Workshop with the ^ 68 | .hhp project file in %BUILDDIR%/htmlhelp. 69 | goto end 70 | ) 71 | 72 | if "%1" == "qthelp" ( 73 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 74 | echo. 75 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 76 | .qhcp project file in %BUILDDIR%/qthelp, like this: 77 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\PyDAS.qhcp 78 | echo.To view the help file: 79 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\PyDAS.ghc 80 | goto end 81 | ) 82 | 83 | if "%1" == "latex" ( 84 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 85 | echo. 86 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 87 | goto end 88 | ) 89 | 90 | if "%1" == "changes" ( 91 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 92 | echo. 93 | echo.The overview file is in %BUILDDIR%/changes. 94 | goto end 95 | ) 96 | 97 | if "%1" == "linkcheck" ( 98 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 99 | echo. 100 | echo.Link check complete; look for any errors in the above output ^ 101 | or in %BUILDDIR%/linkcheck/output.txt. 102 | goto end 103 | ) 104 | 105 | if "%1" == "doctest" ( 106 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 107 | echo. 108 | echo.Testing of doctests in the sources finished, look at the ^ 109 | results in %BUILDDIR%/doctest/output.txt. 110 | goto end 111 | ) 112 | 113 | :end 114 | -------------------------------------------------------------------------------- /documentation/source/_templates/index.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | {% set title = 'Overview' %} 3 | {% block body %} 4 | 5 |

6 | PyDAS is a free Python 7 | wrapper to the DASSL differential algebraic equation solver. 8 |

9 | 10 |

Features

11 | 12 |

Get PyDAS

13 | 14 |

Documentation

15 | 16 | 31 |
17 | 19 | 21 | 23 | 24 | 26 | 28 | 30 |
32 | 33 | {% endblock %} 34 | -------------------------------------------------------------------------------- /documentation/source/_templates/indexsidebar.html: -------------------------------------------------------------------------------- 1 |

Download

2 | 5 | 6 |

Use

7 | 11 | 12 |

Develop

13 | 17 | 18 |

Contact

19 | 22 | -------------------------------------------------------------------------------- /documentation/source/_templates/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "!layout.html" %} 2 | 3 | {#%- set sourcename = False %} {#Remove the "view this page's source" link #} 4 | 5 | {% block rootrellink %} 6 |
  • Home
  • 7 |
  • Documentation »
  • 8 | {% endblock %} 9 | 10 | {%- block header %} 11 |
    12 | PyDAS 13 |
    14 | {%- endblock %} 15 | 16 | {%- block footer %} 17 | 31 | {%- endblock %} 32 | 33 | -------------------------------------------------------------------------------- /documentation/source/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # PyDAS documentation build configuration file, created by 4 | # sphinx-quickstart on Sat Jun 5 18:14:06 2010. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | sys.path.append(os.path.abspath('../..')) 20 | 21 | # -- General configuration ----------------------------------------------------- 22 | 23 | # Add any Sphinx extension module names here, as strings. They can be extensions 24 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 25 | extensions = ['sphinx.ext.autodoc', 'sphinx.ext.pngmath'] 26 | 27 | # Add any paths that contain templates here, relative to this directory. 28 | templates_path = ['_templates'] 29 | 30 | # The suffix of source filenames. 31 | source_suffix = '.rst' 32 | 33 | # The encoding of source files. 34 | #source_encoding = 'utf-8' 35 | 36 | # The master toctree document. 37 | master_doc = 'contents' 38 | 39 | # General information about the project. 40 | project = u'PyDAS' 41 | copyright = u'2010, Joshua W. Allen' 42 | 43 | # The version info for the project you're documenting, acts as replacement for 44 | # |version| and |release|, also used in various other places throughout the 45 | # built documents. 46 | # 47 | # The short X.Y version. 48 | version = '0.1' 49 | # The full version, including alpha/beta/rc tags. 50 | release = '0.1.0' 51 | 52 | # The language for content autogenerated by Sphinx. Refer to documentation 53 | # for a list of supported languages. 54 | #language = None 55 | 56 | # There are two options for replacing |today|: either, you set today to some 57 | # non-false value, then it is used: 58 | #today = '' 59 | # Else, today_fmt is used as the format for a strftime call. 60 | #today_fmt = '%B %d, %Y' 61 | 62 | # List of documents that shouldn't be included in the build. 63 | #unused_docs = [] 64 | 65 | # List of directories, relative to source directory, that shouldn't be searched 66 | # for source files. 67 | exclude_trees = [] 68 | 69 | # The reST default role (used for this markup: `text`) to use for all documents. 70 | #default_role = None 71 | 72 | # If true, '()' will be appended to :func: etc. cross-reference text. 73 | #add_function_parentheses = True 74 | 75 | # If true, the current module name will be prepended to all description 76 | # unit titles (such as .. function::). 77 | #add_module_names = True 78 | 79 | # If true, sectionauthor and moduleauthor directives will be shown in the 80 | # output. They are ignored by default. 81 | #show_authors = False 82 | 83 | # The name of the Pygments (syntax highlighting) style to use. 84 | pygments_style = 'sphinx' 85 | 86 | # A list of ignored prefixes for module index sorting. 87 | #modindex_common_prefix = [] 88 | 89 | 90 | # -- Options for HTML output --------------------------------------------------- 91 | 92 | # The theme to use for HTML and HTML Help pages. Major themes that come with 93 | # Sphinx are currently 'default' and 'sphinxdoc'. 94 | html_theme = 'default' 95 | 96 | # Theme options are theme-specific and customize the look and feel of a theme 97 | # further. For a list of options available for each theme, see the 98 | # documentation. 99 | #html_theme_options = {} 100 | 101 | # Add any paths that contain custom themes here, relative to this directory. 102 | #html_theme_path = [] 103 | 104 | # The name for this set of Sphinx documents. If None, it defaults to 105 | # " v documentation". 106 | #html_title = None 107 | 108 | # A shorter title for the navigation bar. Default is the same as html_title. 109 | #html_short_title = None 110 | 111 | # The name of an image file (relative to this directory) to place at the top 112 | # of the sidebar. 113 | #html_logo = None 114 | 115 | # The name of an image file (within the static path) to use as favicon of the 116 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 117 | # pixels large. 118 | #html_favicon = None 119 | 120 | # Add any paths that contain custom static files (such as style sheets) here, 121 | # relative to this directory. They are copied after the builtin static files, 122 | # so a file named "default.css" will overwrite the builtin "default.css". 123 | html_static_path = ['_static'] 124 | 125 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 126 | # using the given strftime format. 127 | #html_last_updated_fmt = '%b %d, %Y' 128 | 129 | # If true, SmartyPants will be used to convert quotes and dashes to 130 | # typographically correct entities. 131 | #html_use_smartypants = True 132 | 133 | # Custom sidebar templates, maps document names to template names. 134 | html_index = 'index.html' 135 | html_sidebars = {'index': 'indexsidebar.html'} 136 | 137 | # Additional templates that should be rendered to pages, maps page names to 138 | # template names. 139 | html_additional_pages = {'index': 'index.html'} 140 | 141 | # If false, no module index is generated. 142 | #html_use_modindex = True 143 | 144 | # If false, no index is generated. 145 | #html_use_index = True 146 | 147 | # If true, the index is split into individual pages for each letter. 148 | #html_split_index = False 149 | 150 | # If true, links to the reST sources are added to the pages. 151 | #html_show_sourcelink = True 152 | 153 | # If true, an OpenSearch description file will be output, and all pages will 154 | # contain a tag referring to it. The value of this option must be the 155 | # base URL from which the finished HTML is served. 156 | #html_use_opensearch = '' 157 | 158 | # If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). 159 | #html_file_suffix = '' 160 | 161 | # Output file base name for HTML help builder. 162 | htmlhelp_basename = 'PyDASdoc' 163 | 164 | 165 | # -- Options for LaTeX output -------------------------------------------------- 166 | 167 | # The paper size ('letter' or 'a4'). 168 | #latex_paper_size = 'letter' 169 | 170 | # The font size ('10pt', '11pt' or '12pt'). 171 | #latex_font_size = '10pt' 172 | 173 | # Grouping the document tree into LaTeX files. List of tuples 174 | # (source start file, target name, title, author, documentclass [howto/manual]). 175 | latex_documents = [ 176 | ('developers/index', 'developers.tex', u"PyDAS Developers' Guide", u'Joshua W. Allen', 'manual'), 177 | ('users/index', 'users.tex', u"PyDAS Users' Guide", u'Joshua W. Allen', 'manual'), 178 | ] 179 | 180 | # The name of an image file (relative to this directory) to place at the top of 181 | # the title page. 182 | #latex_logo = None 183 | 184 | # For "manual" documents, if this is true, then toplevel headings are parts, 185 | # not chapters. 186 | #latex_use_parts = False 187 | 188 | # Additional stuff for the LaTeX preamble. 189 | latex_preamble = """ 190 | \usepackage[version=3]{mhchem} 191 | 192 | \\renewcommand{\\vector}[1]{\\ensuremath{\\boldsymbol{\\mathbf{#1}}}} 193 | \\renewcommand{\\matrix}[1]{\\ensuremath{\\boldsymbol{\\mathbf{#1}}}} 194 | """ 195 | pngmath_latex_preamble = latex_preamble 196 | 197 | # Documents to append as an appendix to all manuals. 198 | #latex_appendices = [] 199 | 200 | # If false, no module index is generated. 201 | #latex_use_modindex = True 202 | -------------------------------------------------------------------------------- /documentation/source/contents.rst: -------------------------------------------------------------------------------- 1 | ******************************** 2 | PyDAS v\ |release| documentation 3 | ******************************** 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | 8 | users/index 9 | developers/index 10 | 11 | * :ref:`genindex` 12 | * :ref:`modindex` 13 | * :ref:`search` 14 | 15 | -------------------------------------------------------------------------------- /documentation/source/developers/index.rst: -------------------------------------------------------------------------------- 1 | *********************** 2 | PyDAS Developers' Guide 3 | *********************** 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | :numbered: 8 | 9 | -------------------------------------------------------------------------------- /documentation/source/users/images/diffusionPlot.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwallen/PyDAS/4da00e27ffaf82bec30277917fa9ed35007306d8/documentation/source/users/images/diffusionPlot.pdf -------------------------------------------------------------------------------- /documentation/source/users/images/diffusionPlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwallen/PyDAS/4da00e27ffaf82bec30277917fa9ed35007306d8/documentation/source/users/images/diffusionPlot.png -------------------------------------------------------------------------------- /documentation/source/users/images/rxnSeriesPlot.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwallen/PyDAS/4da00e27ffaf82bec30277917fa9ed35007306d8/documentation/source/users/images/rxnSeriesPlot.pdf -------------------------------------------------------------------------------- /documentation/source/users/images/rxnSeriesPlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwallen/PyDAS/4da00e27ffaf82bec30277917fa9ed35007306d8/documentation/source/users/images/rxnSeriesPlot.png -------------------------------------------------------------------------------- /documentation/source/users/index.rst: -------------------------------------------------------------------------------- 1 | ****************** 2 | PyDAS Users' Guide 3 | ****************** 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | :numbered: 8 | 9 | introduction 10 | installation 11 | tutorial 12 | cython 13 | 14 | -------------------------------------------------------------------------------- /documentation/source/users/installation.rst: -------------------------------------------------------------------------------- 1 | ************ 2 | Installation 3 | ************ 4 | 5 | Prerequisites 6 | ============= 7 | 8 | PyDAS is currently available for the `Python `_ 2.x 9 | series. In particular, Python 2.5 and later are known to work. In addition to 10 | the packages in the Python standard library, PyDAS depends on the following 11 | packages: 12 | 13 | * `NumPy `_ version 1.3.0 or later 14 | 15 | * `Cython `_ version 0.12.1 or later 16 | 17 | In addition, you will also need a Fortran compiler and a C compiler that 18 | produce object files that can interoperate [#f1]_. The ``gfortran`` and ``gcc`` 19 | compilers from the `GNU Compiler Collection `_ are known 20 | to work, and are probably your best bet no matter what operating system you 21 | are using. On Windows the `MinGW `_ compiler collection 22 | provides these compilers. 23 | 24 | The DASSL, DASPK, and DASKR solvers are provided with the PyDAS package; you 25 | do not need to download them separately. 26 | 27 | .. [#f1] The Fortran interfaces are exposed to Python via C, so the installer 28 | needs to be able to link object files from Fortran and C for this to work. 29 | 30 | Installing PyDAS 31 | ================ 32 | 33 | If you are running an operating system other than Windows, refer to the 34 | section directly below. Windows users get their own special installation 35 | procedure, described subsequently. 36 | 37 | Unix-like Systems 38 | ----------------- 39 | 40 | A Makefile has been provided that can be used to compile all of the solvers 41 | -- DASSL, DASPK, and DASKR -- and the PyDAS wrapper code. To use, invoke the 42 | following command from the root package directory:: 43 | 44 | $ make 45 | 46 | This command will build PyDAS in-place, rather than installing it to your 47 | Python package directory. At this point you can optionally run the unit test 48 | script ``test.py`` and/or any of the provided examples to confirm that PyDAS 49 | was compiled successfully. 50 | 51 | If you wish to formally install PyDAS, run the following command from the root 52 | package directory after the ``make`` command (you may need root privileges for 53 | this):: 54 | 55 | $ python setup.py install 56 | 57 | You may wish to write a file `make.inc` that sets certain variables used by 58 | the Makefiles (e.g. the Fortran compiler). An example of such a file, 59 | `make.inc.example`, has been provided. 60 | 61 | Windows 62 | ------- 63 | 64 | .. warning:: 65 | 66 | A regression in Cython 0.14 has resulted in it being unusable for PyDAS 67 | in Windows. Cython 0.13 is known to work, and more recent released of 68 | Cython should also correct for this regression. See 69 | `this thread `_ 70 | from the ``cython-dev`` mailing list for more information. 71 | 72 | A batch script ``make.bat`` has been provided in the root package directory. 73 | Double-clicking this script will cause all of the solvers -- DASSL, DASPK, and 74 | DASKR -- to be compiled into static libraries and the PyDAS wrapper code to be 75 | compiled. 76 | 77 | .. note:: 78 | 79 | The batch script presumes that you have the 32-bit version of the MinGW 80 | C and Fortran compilers installed. You may need to add the location of 81 | the MinGW ``bin`` directory to the ``PATH`` environment variable if this 82 | has not already been done. 83 | 84 | At this point you can optionally run the unit test script ``test.py`` and/or 85 | any of the provided examples to confirm that PyDAS was compiled successfully. 86 | 87 | .. warning:: 88 | 89 | When using MinGW with Cython on Windows, you may encounter the error 90 | "Unable to find vcvarsall.bat". A workaround for this issue is available 91 | from the Cython FAQ at 92 | `this page `_. 93 | In particular the ``pydistutils.cfg`` file approach should work. 94 | 95 | If you wish to formally install PyDAS, run the following command from the root 96 | package directory after the batch script completes successfully (you may need 97 | administrator privileges for this):: 98 | 99 | > python setup.py install 100 | 101 | -------------------------------------------------------------------------------- /documentation/source/users/introduction.rst: -------------------------------------------------------------------------------- 1 | ************ 2 | Introduction 3 | ************ 4 | 5 | Differential equations are frequently encountered in a variety of technical 6 | fields. For example, scientists and engineers often express mathematical models 7 | of physical phenomena as a set of differential (and possibly some algebraic) 8 | equations. These models can quickly become complicated enough that direct 9 | analytical solutions are difficult or impossible to obtain. In these cases, 10 | computers can be used to numerically generate approximate solutions. 11 | 12 | A system of differential algebraic equations (DAEs for short) is a set of 13 | equations that implicitly relate an independent variable :math:`t`, a set of 14 | dependent variables :math:`\vector{y}`, and the set of first derivatives 15 | :math:`d\vector{y}/dt`. (Throughout this documentation, we use boldface to 16 | indicate a vector quantity.) The general form is 17 | 18 | .. math:: \vector{g} \left( t, \vector{y}, \frac{d\vector{y}}{dt} \right) = \vector{0} 19 | 20 | Most DAE systems can be expressed in the above form using the appropriate 21 | transformations (e.g. finite differencing). 22 | 23 | In 1982 the first version of DASSL, a Fortran code for efficient solving of DAE 24 | systems of the above form, was released by Petzold [Petzold1982]_. In 1989 and 25 | 2002 the first versions of DASPK and DASKR, descendants of the DASSL code with 26 | a number of advanced features, were released by Brown, Hindmarsh, Petzold, and 27 | Ulrich. 28 | 29 | .. [Petzold1982] L. R. Petzold. "A Description of DASSL: A 30 | Differential/Algebraic System Solver." Sandia National Laboratories report 31 | SAND82-8637 (1982). 32 | 33 | Why PyDAS? 34 | ========== 35 | 36 | DASSL, DASPK, and DASKR are written in Fortran 77, which is not much fun to 37 | code in, especially for novice programmers. Even after the vast improvements 38 | in the language in Fortran 90/95, the task can seem daunting. (In particular, 39 | getting data into and out of a Fortran program via file input and output is 40 | still quite difficult and awkward.) However, the strength of Fortran is that 41 | it produces code that is very efficient to execute, which is often important 42 | when solving DAEs. 43 | 44 | Meanwhile, the Python programming language is much easier to program in. In 45 | particular, Python comes with a large library of free, open source packages 46 | that provide a wide range of functionality, limiting the amount of work the 47 | programmer needs to do from scratch. A number of packages, including 48 | `NumPy `_, `SciPy `_, and 49 | `matplotlib `_, replace much of the 50 | functionality of numerical computing environments such as MATLAB. However, 51 | the differential equation functionality within SciPy is insufficient for 52 | many complex DAE systems. 53 | 54 | PyDAS provides Python programmers with access to a much more robust DAE 55 | solver by providing an interface to the DASSL code from Python. 56 | 57 | Should I Use PyDAS? 58 | =================== 59 | 60 | If you have a small set of differential equations, you should consider trying 61 | the differential equation solver contained within SciPy first, as it may be 62 | suitable for your task. However, if you have a large set of differential (and 63 | algebraic) equations and/or know that you need a more robust solver, then PyDAS 64 | may be just the tool for you. 65 | 66 | Read on to learn how to install and use PyDAS, and tips for getting the most 67 | out of PyDAS. 68 | 69 | -------------------------------------------------------------------------------- /documentation/source/users/tutorial.rst: -------------------------------------------------------------------------------- 1 | ******** 2 | Tutorial 3 | ******** 4 | 5 | In this section we will develop code to solve a very simple DAE system using 6 | DASSL. 7 | 8 | The physical process we are modeling is a pair of first-order chemical 9 | reactions in series occurring in an ideal batch reactor: 10 | 11 | .. math:: \ce{A ->[k_1] B ->[k_2] C} 12 | 13 | The governing equations for this process are the system of first-order 14 | ordinary differential equations 15 | 16 | .. math:: 17 | 18 | \frac{dA}{dt} &= -k_1 A \\ 19 | \frac{dB}{dt} &= k_1 A - k_2 B \\ 20 | \frac{dC}{dt} &= k_2 B 21 | 22 | where :math:`t` is time, :math:`A`, :math:`B`, and :math:`C` represent the 23 | concentration of each species, and :math:`k_1` and :math:`k_2` are rate 24 | coefficients for each chemical reaction. The initial condition is pure A, i.e. 25 | 26 | .. math:: 27 | 28 | A(0) = 1 \hspace{30pt} B(0) = 0 \hspace{30pt} C(0) = 0 29 | 30 | For the purposes of this example we are not interested in units. 31 | 32 | #. **Rewrite your DAE system in general form.** The general form of a DAE 33 | system is :math:`\vector{g}( t, \vector{y}, d\vector{y}/dt) = \vector{0}`. 34 | Since our governing equations are explicit first-order ODEs, this is very easy: 35 | 36 | .. math:: 37 | 38 | -k_1 A - \frac{dA}{dt} &= 0 \\ 39 | k_1 A - k_2 B - \frac{dB}{dt} &= 0 \\ 40 | k_2 B - \frac{dC}{dt} &= 0 41 | 42 | Most DAE systems should be expressible in general form, though some 43 | manual transformations may be required. 44 | 45 | #. **Import the solver class from the** :mod:`pydas` **module.** This is done with 46 | a single import statement:: 47 | 48 | from pydas import DASSL 49 | 50 | #. **Create a new class that derives from the chosen solver class.** The use of 51 | a class for this purpose enables you to store variables needed by the 52 | residual and/or Jacobian functions as attributes of the class. In this 53 | example we will need to store the rate coefficients :math:`k_1` and 54 | :math:`k_2`. Here we provide an :meth:`__init__` method to easily set these 55 | values. A docstring describing the purpose of the class is always a good 56 | idea. :: 57 | 58 | class Model(DASSL): 59 | """ 60 | A model of first-order irreversible reactions in series 61 | 62 | A -> B -> C 63 | 64 | occurring in a batch reactor. In such a system the concentration 65 | of the intermediate B has a maximum that depends on the relative 66 | rate constants `k1` and `k2`. These are stored as data members of 67 | the class so that they are available to the residual function. 68 | """ 69 | 70 | def __init__(self, k1=0.0, k2=0.0): 71 | self.k1 = k1 72 | self.k2 = k2 73 | 74 | #. **Write the residual method for that class.** The :meth:`residual` method is 75 | automatically called by the solver, and is used to compute the value of. 76 | 77 | .. math:: 78 | \vector{g} \left( t, \vector{y}, \frac{d\vector{y}}{dt} \right) = \vector{0} 79 | 80 | The method provides three parameters in 81 | addition to the ``self`` object: the independent variable `t`, a float; the 82 | vector of dependent variables `y`, a numpy array of floats; and the first 83 | derivatives `dydt`, a numpy array of floats. The method expects two return 84 | variables: a numpy array of floats containing the value of 85 | :math:`\vector{g}( t, \vector{y}, d\vector{y}/dt)` corresponding to the 86 | input parameters, and a integer status flag, having a value of 0 if okay or 87 | -2 to terminate the simulation. Our :meth:`residual` method reflects the 88 | general form of the DAE system:: 89 | 90 | def residual(self, t, y, dydt): 91 | delta = numpy.zeros(y.shape[0], numpy.float64) 92 | delta[0] = -self.k1 * y[0] - dydt[0] 93 | delta[1] = self.k1 * y[0] - self.k2 * y[1] - dydt[1] 94 | delta[2] = self.k2 * y[1] - dydt[2] 95 | return delta, 0 96 | 97 | Note that you need an ``import numpy`` statement in your module for the 98 | above to run. 99 | 100 | #. **(Optional) Write the jacobian method for that class.** The 101 | :meth:`jacobian` method is used to specify the analytical Jacobian 102 | corresponding to the residual function. The Jacobian is the matrix of 103 | partial derivatives with elements given by 104 | 105 | .. math:: 106 | J_{mn} = \frac{\partial g_m}{\partial y_n} + C_J \frac{\partial g_m}{\partial (dy_n/dt)} 107 | 108 | In addition to the same `t`, 109 | `y`, and `dydt` parameters as the :meth:`residual` method, the 110 | :meth:`jacobian` method also has a fourth parameter: a float `cj` to be used 111 | to scale the derivative components in the Jacobian matrix. For our system 112 | the Jacobian is not too difficult to generate:: 113 | 114 | def jacobian(self, t, y, dydt, cj): 115 | pd = -cj * numpy.identity(y.shape[0], numpy.float64) 116 | pd[0,0] += -self.k1 117 | pd[1,0] += self.k1 118 | pd[1,1] += -self.k2 119 | pd[2,1] += self.k2 120 | return pd 121 | 122 | If not specified, the solver will evaluate an approximate Jacobian 123 | numerically. For many problems this is enough, which is good because it 124 | can be time-consuming to generate an analytical Jacobian. The use of 125 | analytical or numerical Jacobian is detected and configured automatically 126 | by PyDAS; all you need to do is to provide or omit the :meth:`jacobian` 127 | method. 128 | 129 | #. **Create an object of your derived class.** Since we designed our 130 | :meth:`__init__` method to accept the rate coefficients, we can easily 131 | set them to the values we want. For this tutorial we will use 132 | :math:`k_1 = 1.0` and :math:`k_2 = 0.25`. :: 133 | 134 | model = Model(k1=1.0, k2=0.25) 135 | 136 | #. **Initialize the model with the initial conditions and solver options.** 137 | The initial conditions follow directly from the equation above:: 138 | 139 | t0 = 0.0; y0 = numpy.array([1.0, 0.0, 0.0], numpy.float64) 140 | 141 | Since we are using a DAE solver, we also need initial values for the 142 | first derivatives :math:`d\vector{y}/dt`. These initial values must be 143 | *consistent* with those of :math:`t` and :math:`\vector{y}`. It is best if 144 | you can determine the initial values of :math:`d\vector{y}/dt` manually, 145 | as we can in this example:: 146 | 147 | dydt0 = - model.residual(t0, y0, numpy.zeros(3, numpy.float64))[0] 148 | model.initialize(t0, y0, dydt0) 149 | 150 | If you cannot do this manually (or simply have no idea how), you can simply 151 | omit it; DASSL will then try to estimate it for you. Note that this is not 152 | always successful. :: 153 | 154 | model.initialize(t0, y0) 155 | 156 | You can also use the :meth:`initialize` method to specify absolute and 157 | relative tolerances for the solver to use, either as scalars or numpy arrays. 158 | Below we use scalars:: 159 | 160 | model.initialize(t0, y0, dydt0, atol=1e-16, rtol=1e-8) 161 | 162 | Default values will be used if not specified. 163 | 164 | The :meth:`initialize` method of the solver class must always be called 165 | before attempting to integrate. 166 | 167 | #. **Integrate forward using advance or step.** After initialization, the 168 | current values of :math:`t` and :math:`\vector{y}(t)` are available from 169 | the `t` and `y` attributes of the solver object. In order to conduct the 170 | integration, call the :meth:`advance` or :meth:`step` methods of the solver 171 | object. The :meth:`advance` method integrates forward until the time 172 | specified as the parameter is reached; the `t` and `y` attributes then will 173 | contain the solution at that time. The :meth:`step` method integrates such 174 | that one automatically-determined step is taken towards the specified 175 | parameter, which is usually the end time of the simulation; when finished, 176 | the `t` and `y` attributes will contain the solution at the end time of that 177 | step. Here we will use the :meth:`step` method:: 178 | 179 | # Initialize solution vectors 180 | t = [] 181 | y = [] 182 | 183 | # Set maximum simulation time and maximum number of simulation steps to allow 184 | tmax = 16 185 | maxiter = 1000 186 | 187 | # Generate the solution by stepping until tmax is reached 188 | # This will give you the solution at time points automatically selected 189 | # by the solver 190 | iter = 0 191 | while iter < maxiter and model.t < tmax: 192 | model.step(tmax) 193 | t.append(model.t) 194 | # You must make a copy of y because it is overwritten by DASSL at 195 | # each call to step() 196 | y.append(model.y.copy()) 197 | 198 | # Convert the solution vectors to numpy arrays 199 | t = numpy.array(t, numpy.float64) 200 | y = numpy.array(y, numpy.float64) 201 | 202 | Note that we must keep track of the solution ourselves, as each call to 203 | :meth:`advance` or :meth:`step` causes the the `t` and `y` attributes to be 204 | overwritten. (In particular, we must copy `y` because it is a numpy array.) 205 | We must also provide the test that the end time of the simulation is reached, 206 | as this is not done for you. Finally, we convert the solution data to numpy 207 | arrays for easier postprocessing. 208 | 209 | The complete code for this tutorial can be found in the ``rxnSeries`` DASSL 210 | example. Running this code should produce the following plot (assuming you have 211 | matplotlib installed): 212 | 213 | .. figure:: images/rxnSeriesPlot.* 214 | :height: 3in 215 | 216 | 217 | -------------------------------------------------------------------------------- /examples/diffusion/cython/Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # 3 | # Makefile to build PyDAS benard example 4 | # 5 | ################################################################################ 6 | 7 | all: 8 | python setup.py build_ext --inplace 9 | 10 | clean: 11 | python setup.py clean 12 | rm -rf *.so *.c *.html build 13 | -------------------------------------------------------------------------------- /examples/diffusion/cython/diffusion.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 6 | """ 7 | 8 | import numpy 9 | from model import DiffusionModel 10 | 11 | if __name__ == '__main__': 12 | 13 | # The times at which to obtain the solution 14 | tlist = numpy.array([10**i for i in range(-6, 1)], numpy.float64) 15 | # The number of grid points to use to discretize the spatial dimension 16 | N = 501 17 | 18 | # Set initial conditions 19 | t0 = 0.0 20 | y0 = numpy.zeros((N), numpy.float64) 21 | y0[0] = 1 22 | 23 | # Initialize the model 24 | model = DiffusionModel(N=N) 25 | dydt0 = - model.residual(t0, y0, numpy.zeros((N), numpy.float64))[0] 26 | model.initialize(t0, y0, dydt0) 27 | 28 | # Integrate to get the solution at each time point 29 | t = []; y = [] 30 | for t1 in tlist: 31 | model.advance(t1) 32 | t.append(model.t) 33 | # You must make a copy of y because it is overwritten by DASSL at 34 | # each call to advance() 35 | y.append(model.y.copy()) 36 | 37 | # Convert the solution vectors to numpy arrays 38 | t = numpy.array(t, numpy.float64) 39 | y = numpy.array(y, numpy.float64) 40 | 41 | x = numpy.linspace(0, 1, N) 42 | 43 | # Generate plot of solutions 44 | import pylab 45 | pylab.figure(figsize=(7,5)) 46 | pylab.plot(x, y.T) 47 | pylab.xlim((0,1)) 48 | pylab.ylim((0,1)) 49 | pylab.xlabel('Membrane position $x$') 50 | pylab.ylabel('Concentration $\\theta$') 51 | pylab.legend([ 52 | 't = $\\mathdefault{10^{-6}}$', 53 | 't = $\\mathdefault{10^{-5}}$', 54 | 't = $\\mathdefault{10^{-4}}$', 55 | 't = $\\mathdefault{10^{-3}}$', 56 | 't = $\\mathdefault{10^{-2}}$', 57 | 't = $\\mathdefault{10^{-1}}$', 58 | 't = $\\mathdefault{10^{0}}$'], loc=1) 59 | pylab.show() 60 | -------------------------------------------------------------------------------- /examples/diffusion/cython/model.pyx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 6 | """ 7 | 8 | import numpy 9 | cimport numpy 10 | 11 | from pydas cimport DASSL 12 | 13 | cdef class DiffusionModel(DASSL): 14 | """ 15 | An extension type for solving the diffusion equation in a 1D thin membrane. 16 | The attribute `N` is the number of grid points to use to discretize the 17 | spatial direction. 18 | """ 19 | 20 | cdef public int N 21 | 22 | def __init__(self, N=10): 23 | self.N = N 24 | 25 | def residual(self, double t, numpy.ndarray[numpy.float64_t, ndim=1] y, numpy.ndarray[numpy.float64_t, ndim=1] dydt): 26 | 27 | cdef Py_ssize_t i 28 | cdef double dx 29 | cdef numpy.ndarray[numpy.float64_t, ndim=1] delta 30 | 31 | dx = 1.0 / (self.N - 1) 32 | 33 | delta = numpy.zeros(y.shape[0], numpy.float64) 34 | # Internal nodes 35 | for i in range(1, self.N-1): 36 | delta[i] = (y[i+1] - 2 * y[i] + y[i-1]) / (dx * dx) - dydt[i] 37 | # Left boundary (x = 0) 38 | i = 0 39 | delta[i] = y[i] - 1.0 40 | # Right boundary (x = 1) 41 | i = self.N - 1 42 | delta[i] = y[i] 43 | 44 | return delta, 0 45 | -------------------------------------------------------------------------------- /examples/diffusion/cython/pydas.pxd: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | ################################################################################ 4 | # 5 | # PyDAS - A Python wrapper for several differential algebraic system solvers 6 | # 7 | # Copyright (c) 2010 by Joshua W. Allen (jwallen@mit.edu) 8 | # 9 | # Permission is hereby granted, free of charge, to any person obtaining a 10 | # copy of this software and associated documentation files (the 'Software'), 11 | # to deal in the Software without restriction, including without limitation 12 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | # and/or sell copies of the Software, and to permit persons to whom the 14 | # Software is furnished to do so, subject to the following conditions: 15 | # 16 | # The above copyright notice and this permission notice shall be included in 17 | # all copies or substantial portions of the Software. 18 | # 19 | # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | # DEALINGS IN THE SOFTWARE. 26 | # 27 | ################################################################################ 28 | 29 | import numpy 30 | cimport numpy 31 | 32 | cdef class DASSL: 33 | 34 | cdef public int maxOrder 35 | cdef public object tstop 36 | cdef public double initialStep 37 | cdef public double maximumStep 38 | cdef public object bandwidths 39 | cdef public bint nonnegative 40 | 41 | cdef public double t 42 | cdef public numpy.ndarray y 43 | cdef public numpy.ndarray dydt 44 | 45 | cdef numpy.ndarray info 46 | cdef numpy.ndarray atol 47 | cdef numpy.ndarray rtol 48 | cdef numpy.ndarray rwork 49 | cdef numpy.ndarray iwork 50 | cdef numpy.ndarray rpar 51 | cdef numpy.ndarray ipar 52 | cdef int idid 53 | 54 | cpdef initialize(self, double t0, y0, dydt0=?, atol=?, rtol=?) 55 | 56 | cpdef advance(self, double tout) 57 | 58 | cpdef step(self, double tout) 59 | 60 | cdef solve(self, double tout) 61 | -------------------------------------------------------------------------------- /examples/diffusion/cython/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | ################################################################################ 5 | # 6 | # RMG - Reaction Mechanism Generator 7 | # 8 | # Copyright (c) 2010 by Joshua W. Allen (jwallen@mit.edu) 9 | # 10 | # Permission is hereby granted, free of charge, to any person obtaining a 11 | # copy of this software and associated documentation files (the 'Software'), 12 | # to deal in the Software without restriction, including without limitation 13 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 14 | # and/or sell copies of the Software, and to permit persons to whom the 15 | # Software is furnished to do so, subject to the following conditions: 16 | # 17 | # The above copyright notice and this permission notice shall be included in 18 | # all copies or substantial portions of the Software. 19 | # 20 | # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | # DEALINGS IN THE SOFTWARE. 27 | # 28 | ################################################################################ 29 | 30 | import numpy 31 | 32 | if __name__ == '__main__': 33 | 34 | from distutils.core import setup 35 | from distutils.extension import Extension 36 | from Cython.Distutils import build_ext 37 | 38 | # Turn on HTML annotation file generation (useful for 39 | import Cython.Compiler.Options 40 | Cython.Compiler.Options.annotate = True 41 | 42 | # Turn on profiling capacity for all Cython modules 43 | Cython.Compiler.Options.directive_defaults['profile'] = True 44 | 45 | # The Cython modules to setup 46 | ext_modules = [ 47 | Extension('model', ['model.pyx'], include_dirs=[numpy.get_include()]), 48 | ] 49 | 50 | # Run the setup command 51 | setup( 52 | cmdclass = {'build_ext': build_ext}, 53 | ext_modules = ext_modules 54 | ) 55 | -------------------------------------------------------------------------------- /examples/diffusion/python/diffusion.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 6 | """ 7 | 8 | import numpy 9 | from model import DiffusionModel 10 | 11 | if __name__ == '__main__': 12 | 13 | # The times at which to obtain the solution 14 | tlist = numpy.array([10**i for i in range(-6, 1)], numpy.float64) 15 | # The number of grid points to use to discretize the spatial dimension 16 | N = 501 17 | 18 | # Set initial conditions 19 | t0 = 0.0 20 | y0 = numpy.zeros((N), numpy.float64) 21 | y0[0] = 1 22 | 23 | # Initialize the model 24 | model = DiffusionModel(N=N) 25 | dydt0 = - model.residual(t0, y0, numpy.zeros((N), numpy.float64))[0] 26 | model.initialize(t0, y0, dydt0) 27 | 28 | # Integrate to get the solution at each time point 29 | t = []; y = [] 30 | for t1 in tlist: 31 | model.advance(t1) 32 | t.append(model.t) 33 | # You must make a copy of y because it is overwritten by DASSL at 34 | # each call to advance() 35 | y.append(model.y.copy()) 36 | 37 | # Convert the solution vectors to numpy arrays 38 | t = numpy.array(t, numpy.float64) 39 | y = numpy.array(y, numpy.float64) 40 | 41 | x = numpy.linspace(0, 1, N) 42 | 43 | # Generate plot of solutions 44 | import pylab 45 | pylab.figure(figsize=(7,5)) 46 | pylab.plot(x, y.T) 47 | pylab.xlim((0,1)) 48 | pylab.ylim((0,1)) 49 | pylab.xlabel('Membrane position $x$') 50 | pylab.ylabel('Concentration $\\theta$') 51 | pylab.legend([ 52 | 't = $\\mathdefault{10^{-6}}$', 53 | 't = $\\mathdefault{10^{-5}}$', 54 | 't = $\\mathdefault{10^{-4}}$', 55 | 't = $\\mathdefault{10^{-3}}$', 56 | 't = $\\mathdefault{10^{-2}}$', 57 | 't = $\\mathdefault{10^{-1}}$', 58 | 't = $\\mathdefault{10^{0}}$'], loc=1) 59 | pylab.show() 60 | -------------------------------------------------------------------------------- /examples/diffusion/python/model.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 6 | """ 7 | 8 | import numpy 9 | 10 | from pydas import DASSL 11 | 12 | class DiffusionModel(DASSL): 13 | """ 14 | A class for solving the diffusion equation in a 1D thin membrane. The 15 | attribute `N` is the number of grid points to use to discretize the 16 | spatial direction. 17 | """ 18 | 19 | def __init__(self, N=10): 20 | self.N = N 21 | 22 | def residual(self, t, y, dydt): 23 | delta = numpy.zeros(y.shape[0], numpy.float64) 24 | # The grid point spacing 25 | dx = 1.0 / (self.N - 1) 26 | # Internal nodes 27 | for i in range(1, self.N-1): 28 | delta[i] = (y[i+1] - 2 * y[i] + y[i-1]) / (dx * dx) - dydt[i] 29 | # Left boundary (x = 0) 30 | i = 0 31 | delta[i] = y[i] - 1.0 32 | # Right boundary (x = 1) 33 | i = self.N - 1 34 | delta[i] = y[i] 35 | 36 | return delta, 0 37 | -------------------------------------------------------------------------------- /examples/rxnSeries/rxnSeries.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | This file uses DASSL to solve a model of a set of irreversible first-order 6 | reactions in series occurring in a well-mixed batch reactor: 7 | 8 | A -> B -> C 9 | 10 | The governing equations are 11 | 12 | d[A]/dt = -k1*[A] 13 | d[B]/dt = k1*[A] - k2*[B] 14 | d[C]/dt = k2*[B] 15 | 16 | with initial conditions 17 | 18 | [A](0) = 1.0 [B](0) = 0.0 [C] = 0.0 19 | 20 | and k1 = 1.0 and k2 = 0.25. 21 | """ 22 | 23 | import sys 24 | sys.path.append('.') 25 | 26 | from pydas import DASSL 27 | import numpy 28 | 29 | class Model(DASSL): 30 | """ 31 | A model of first-order irreversible reactions in series 32 | 33 | A -> B -> C 34 | 35 | occurring in a batch reactor. In such a system the concentration 36 | of the intermediate B has a maximum that depends on the relative 37 | rate constants `k1` and `k2`. These are stored as data members of 38 | the class so that they are available to the residual function. 39 | """ 40 | 41 | def __init__(self, k1=0.0, k2=0.0): 42 | self.k1 = k1 43 | self.k2 = k2 44 | 45 | def residual(self, t, y, dydt): 46 | delta = numpy.zeros(y.shape[0], numpy.float64) 47 | delta[0] = -self.k1 * y[0] - dydt[0] 48 | delta[1] = self.k1 * y[0] - self.k2 * y[1] - dydt[1] 49 | delta[2] = self.k2 * y[1] - dydt[2] 50 | return delta, 0 51 | 52 | #def jacobian(self, t, y, dydt, cj): 53 | #pd = -cj * numpy.identity(y.shape[0], numpy.float64) 54 | #pd[0,0] += -self.k1 55 | #pd[1,0] += self.k1 56 | #pd[1,1] += -self.k2 57 | #pd[2,1] += self.k2 58 | #return pd 59 | 60 | ################################################################################ 61 | 62 | if __name__ == '__main__': 63 | 64 | # Initialize solution vectors 65 | t = [] 66 | y = [] 67 | 68 | # Set maximum simulation time and maximum number of simulation steps to allow 69 | tmax = 16 70 | maxiter = 1000 71 | 72 | # Initialize the model 73 | model = Model(k1=1.0, k2=0.25) 74 | t0 = 0.0; y0 = numpy.array([1.0, 0.0, 0.0], numpy.float64) 75 | # Since the model is explicit -- dy/dt = f(t, y) -- it is easy to 76 | # evaluate dydt0; doing this is recommended because it lets DASSL 77 | # choose a proper initial time step 78 | dydt0 = - model.residual(t0, y0, numpy.zeros(3, numpy.float64))[0] 79 | model.initialize(t0, y0, dydt0) 80 | 81 | # Generate the solution by stepping until tmax is reached 82 | # This will give you the solution at time points automatically selected 83 | # by the solver 84 | iter = 0 85 | while iter < maxiter and model.t < tmax: 86 | model.step(tmax) 87 | t.append(model.t) 88 | # You must make a copy of y because it is overwritten by DASSL at 89 | # each call to step() 90 | y.append(model.y.copy()) 91 | 92 | # Convert the solution vectors to numpy arrays 93 | t = numpy.array(t, numpy.float64) 94 | y = numpy.array(y, numpy.float64) 95 | 96 | # If matplotlib is installed, show a plot of the results 97 | # Otherwise do nothing 98 | try: 99 | import pylab 100 | pylab.plot(t, y) 101 | pylab.legend(['A', 'B', 'C'], loc=1) 102 | pylab.xlabel('Time') 103 | pylab.ylabel('Concentration') 104 | pylab.show() 105 | except ImportError: 106 | pass 107 | 108 | -------------------------------------------------------------------------------- /make.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :: Set the Fortran compiler and compiler flags 4 | set f77=gfortran 5 | set cflags=-O3 6 | 7 | echo Compiling DASSL... 8 | CALL %f77% %cflags% -c dassl/daux.f -o dassl/daux.o 9 | CALL %f77% %cflags% -c dassl/ddassl.f -o dassl/ddassl.o 10 | CALL %f77% %cflags% -c dassl/dlinpk.f -o dassl/dlinpk.o 11 | CALL ar rcs dassl/libddassl.a dassl/daux.o dassl/ddassl.o dassl/dlinpk.o 12 | 13 | echo Compiling PyDAS... 14 | CALL python setup.py build_ext --compiler=mingw32 --inplace 15 | 16 | :end 17 | pause 18 | -------------------------------------------------------------------------------- /make.inc.example: -------------------------------------------------------------------------------- 1 | F77=gfortran 2 | 3 | CYTHON_FLAGS=--inplace 4 | -------------------------------------------------------------------------------- /pydas.pxd: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | cimport numpy as np 3 | 4 | cimport cython 5 | 6 | cdef class DASSL: 7 | 8 | cdef public int maxOrder 9 | cdef public object tstop 10 | cdef public double initialStep 11 | cdef public double maximumStep 12 | cdef public object bandwidths 13 | cdef public bint nonnegative 14 | cdef public bint sensitivity 15 | cdef public int sensmethod 16 | 17 | cdef public double t 18 | cdef public np.ndarray y 19 | cdef public np.ndarray dydt 20 | cdef public np.ndarray senpar 21 | 22 | cdef np.ndarray info 23 | cdef np.ndarray atol 24 | cdef np.ndarray rtol 25 | cdef np.ndarray rwork 26 | cdef np.ndarray iwork 27 | cdef np.ndarray rpar 28 | cdef np.ndarray ipar 29 | cdef int idid 30 | 31 | cpdef initialize(self, double t0, np.ndarray y0, np.ndarray dydt0=?, np.ndarray senpar=?, atol=?, rtol=?) 32 | 33 | cpdef advance(self, double tout) 34 | 35 | cpdef step(self, double tout) 36 | 37 | cdef solve(self, double tout) -------------------------------------------------------------------------------- /pydasTest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | This file contains unit tests for PyDAS. 6 | """ 7 | 8 | import unittest 9 | 10 | from pydas import DASSL 11 | import math 12 | import numpy 13 | 14 | ################################################################################ 15 | 16 | 17 | class SimpleModel(DASSL): 18 | """ 19 | A model of first-order irreversible reactions in series 20 | 21 | A -> B -> C 22 | 23 | occurring in a batch reactor. In such a system the concentration 24 | of the intermediate B has a maximum that depends on the relative 25 | rate constants `k1` and `k2`. These are stored as data members of 26 | the class so that they are available to the residual function. 27 | """ 28 | 29 | def __init__(self, k1=0.0, k2=0.0): 30 | self.k1 = k1 31 | self.k2 = k2 32 | 33 | def residual(self, t, y, dydt, senpar): 34 | delta = numpy.zeros(y.shape[0], numpy.float64) 35 | delta[0] = -self.k1 * y[0] - dydt[0] 36 | delta[1] = self.k1 * y[0] - self.k2 * y[1] - dydt[1] 37 | delta[2] = self.k2 * y[1] - dydt[2] 38 | return delta, 0 39 | 40 | def jacobian(self, t, y, dydt, cj, senpar): 41 | pd = -cj * numpy.identity(y.shape[0], numpy.float64) 42 | pd[0,0] += -self.k1 43 | pd[1,0] += self.k1 44 | pd[1,1] += -self.k2 45 | pd[2,1] += self.k2 46 | return pd 47 | 48 | ################################################################################# 49 | 50 | class DASSLCheck(unittest.TestCase): 51 | """ 52 | Contains unit tests of the DASSL wrapper. 53 | """ 54 | 55 | def testSimple(self): 56 | """ 57 | This test solves a simple set of ODEs numerically using DASSL and 58 | compares the result to a known analytical solution. The physical 59 | system this problem represents is two first-order chemical reactions 60 | in series in a homogeneous batch reactor. 61 | 62 | The governing equations are 63 | 64 | dA/dt = -k1*A 65 | dB/dt = k1*A - k2*B 66 | dC/dt = k2*B 67 | 68 | with initial conditions 69 | 70 | A(0) = 1.0 B(0) = 0.0 C(0) = 0.0 71 | 72 | and k1 = 1.0 and k2 = 0.25. The analytical solution is 73 | 74 | A(t) = exp(-k1*t) 75 | B(t) = k1/(k2-k1) * (exp(-k1*t) - exp(-k2*t)) 76 | C(t) = (1 - k2/(k2-k1) * exp(-k1*t) - k1/(k2-k1) * exp(-k2*t) 77 | 78 | Note that C(t) = A(0) - A(t) - B(t) since the governing equations are 79 | conservative. 80 | """ 81 | 82 | k1 = 1.0; k2 = 0.25 83 | model = SimpleModel(k1, k2) 84 | t0 = 0.0; y0 = numpy.array([1.0, 0.0, 0.0], numpy.float64) 85 | dydt0 = model.residual(t0, y0, numpy.zeros(3, numpy.float64),numpy.zeros(3, numpy.float64))[0] 86 | model.initialize(t0, y0, dydt0, atol=1e-16, rtol=1e-8) 87 | 88 | tmax = 100; iter = 0; maxiter = 1000 89 | while iter < 1000 and model.t < 16: 90 | model.step(tmax) 91 | t = model.t 92 | A, B, C = model.y 93 | 94 | Atrue = math.exp(-k1*t) 95 | Btrue = k1 / (k2 - k1) * (math.exp(-k1*t) - math.exp(-k2*t)) 96 | Ctrue = 1.0 - Atrue - Btrue 97 | if Atrue > 1e-8: 98 | self.assertAlmostEqual(A / Atrue, 1.0, 6) 99 | if Btrue > 1e-8: 100 | self.assertAlmostEqual(B / Btrue, 1.0, 6, 'At t = %g: B = %g, but Btrue = %g' % (t, B, Btrue)) 101 | if Ctrue > 1e-8: 102 | self.assertAlmostEqual(C / Ctrue, 1.0, 6, 'At t = %g: C = %g, but Ctrue = %g' % (t, C, Ctrue)) 103 | 104 | ################################################################################ 105 | 106 | if __name__ == '__main__': 107 | unittest.main( testRunner = unittest.TextTestRunner(verbosity=2) ) 108 | -------------------------------------------------------------------------------- /pydaspk.pxd: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | cimport numpy as np 3 | 4 | cimport cython 5 | 6 | cdef class DASPK: 7 | 8 | cdef public int maxOrder 9 | cdef public object tstop 10 | cdef public double initialStep 11 | cdef public double maximumStep 12 | cdef public object bandwidths 13 | cdef public bint nonnegative 14 | cdef public bint sensitivity 15 | cdef public int sensmethod 16 | 17 | cdef public double t 18 | cdef public np.ndarray y 19 | cdef public np.ndarray dydt 20 | cdef public np.ndarray senpar 21 | 22 | cdef np.ndarray info 23 | cdef np.ndarray atol 24 | cdef np.ndarray rtol 25 | cdef np.ndarray rwork 26 | cdef np.ndarray iwork 27 | cdef np.ndarray rpar 28 | cdef np.ndarray ipar 29 | cdef int idid 30 | 31 | cpdef initialize(self, double t0, np.ndarray y0, np.ndarray dydt0=?, np.ndarray senpar=?, atol=?, rtol=?) 32 | 33 | cpdef advance(self, double tout) 34 | 35 | cpdef step(self, double tout) 36 | 37 | cdef solve(self, double tout) -------------------------------------------------------------------------------- /pydaspkTest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | This file contains unit tests for PyDASPK. 6 | """ 7 | 8 | import unittest 9 | 10 | from pydaspk import DASPK 11 | import math 12 | import numpy 13 | import matplotlib.pyplot as plt 14 | ################################################################################ 15 | 16 | class DASPKSimpleModel(DASPK): 17 | """ 18 | A model of first-order irreversible reactions in series 19 | 20 | A -> B -> C 21 | 22 | occurring in a batch reactor. In such a system the concentration 23 | of the intermediate B has a maximum that depends on the relative 24 | rate constants `k1` and `k2`. These are stored as data members of 25 | the class so that they are available to the residual function. 26 | """ 27 | 28 | def __init__(self, k1=0.0, k2=0.0): 29 | self.k1 = k1 30 | self.k2 = k2 31 | 32 | def residual(self, t, y, dydt, senpar): 33 | delta = numpy.zeros(y.shape[0], numpy.float64) 34 | delta[0] = -self.k1 * y[0] - dydt[0] 35 | delta[1] = self.k1 * y[0] - self.k2 * y[1] - dydt[1] 36 | delta[2] = self.k2 * y[1] - dydt[2] 37 | return delta, 0 38 | 39 | def jacobian(self, t, y, dydt, cj, senpar): 40 | pd = -cj * numpy.identity(y.shape[0], numpy.float64) 41 | pd[0,0] += -self.k1 42 | pd[1,0] += self.k1 43 | pd[1,1] += -self.k2 44 | pd[2,1] += self.k2 45 | return pd 46 | 47 | ################################################################################ 48 | 49 | class DASPKSensitivityModel(DASPK): 50 | """ 51 | A model of first-order irreversible reactions in series 52 | 53 | A -> B -> C 54 | 55 | occurring in a batch reactor. In such a system the concentration 56 | of the intermediate B has a maximum that depends on the relative 57 | rate constants `k1` and `k2`. These are stored as data members of 58 | the class so that they are available to the residual function. 59 | """ 60 | 61 | def __init__(self, sensitivity, sensmethod): 62 | self.sensitivity = sensitivity 63 | self.sensmethod = sensmethod 64 | 65 | def residual(self, t, y, dydt, senpar): 66 | delta = numpy.zeros(9, numpy.float64) 67 | delta[0] = -senpar[0]* y[0] 68 | delta[1] = senpar[0]* y[0] - senpar[1] * y[1] 69 | delta[2] = senpar[1] * y[1] 70 | numReactions = 2 71 | numState = 3 72 | for j in range(numReactions): 73 | for i in range(numState): 74 | for k in range(numState): 75 | delta[(j+1)*numState + i] += self.jacobian(t,y,dydt,0,senpar)[i,k]*y[(j+1)*numState + k] 76 | delta[(j+1)*numState + i] += self.dgdk(y)[i,j] 77 | 78 | 79 | for i in range(9): 80 | delta[i] -= dydt[i] 81 | return delta, 1 82 | 83 | def jacobian(self, t, y, dydt, cj, senpar): 84 | pd = -cj * numpy.identity(3, numpy.float64) 85 | pd[0,0] += -senpar[0] 86 | pd[1,0] += senpar[0] 87 | pd[1,1] += -senpar[1] 88 | pd[2,1] += senpar[1] 89 | return pd 90 | 91 | def dgdk(self,y): 92 | deriv = numpy.zeros((3,2),numpy.float64) 93 | deriv[0,0] = -y[0] 94 | deriv[1,0] = y[0] 95 | deriv[1,1] = -y[1] 96 | deriv[2,1] = y[1] 97 | return deriv 98 | 99 | ################################################################################ 100 | 101 | class DASPKCheck(unittest.TestCase): 102 | """ 103 | Contains unit tests of the DASSL wrapper. 104 | """ 105 | 106 | def testSimple(self): 107 | """ 108 | This test solves a simple set of ODEs numerically using DASSL and 109 | compares the result to a known analytical solution. The physical 110 | system this problem represents is two first-order chemical reactions 111 | in series in a homogeneous batch reactor. 112 | 113 | The governing equations are 114 | 115 | dA/dt = -k1*A 116 | dB/dt = k1*A - k2*B 117 | dC/dt = k2*B 118 | 119 | with initial conditions 120 | A(0) = 1.0 B(0) = 0.0 C(0) = 0.0 121 | 122 | and k1 = 1.0 and k2 = 0.25. The analytical solution is 123 | 124 | A(t) = exp(-k1*t) 125 | B(t) = k1/(k2-k1) * (exp(-k1*t) - exp(-k2*t)) 126 | C(t) = (1 - k2/(k2-k1) * exp(-k1*t) - k1/(k2-k1) * exp(-k2*t) 127 | 128 | Note that C(t) = A(0) - A(t) - B(t) since the governing equations are 129 | conservative. 130 | """ 131 | 132 | k1 = 1.0; k2 = 0.25 133 | model = DASPKSimpleModel(k1, k2) 134 | t0 = 0.0; y0 = numpy.array([1.0, 0.0, 0.0], numpy.float64) 135 | dydt0 = model.residual(t0, y0, numpy.zeros(3, numpy.float64),numpy.zeros(3, numpy.float64))[0] 136 | senpar = numpy.array([0.0,0.0,0.0], numpy.float64) 137 | 138 | model.initialize(t0, y0, dydt0, senpar, atol=1e-16, rtol=1e-8) 139 | 140 | tmax = 100; iter = 0; maxiter = 1000 141 | tvec = [] 142 | Avec = [] 143 | Bvec = [] 144 | Cvec = [] 145 | while iter < 1000 and model.t < 16: 146 | model.step(tmax) 147 | t = model.t 148 | tvec.append(t) 149 | A, B, C = model.y 150 | Avec.append(A) 151 | Bvec.append(B) 152 | Cvec.append(C) 153 | Atrue = math.exp(-k1*t) 154 | Btrue = k1 / (k2 - k1) * (math.exp(-k1*t) - math.exp(-k2*t)) 155 | Ctrue = 1.0 - Atrue - Btrue 156 | if Atrue > 1e-8: 157 | self.assertAlmostEqual(A / Atrue, 1.0, 6) 158 | if Btrue > 1e-8: 159 | self.assertAlmostEqual(B / Btrue, 1.0, 6, 'At t = %g: B = %g, but Btrue = %g' % (t, B, Btrue)) 160 | if Ctrue > 1e-8: 161 | self.assertAlmostEqual(C / Ctrue, 1.0, 6, 'At t = %g: C = %g, but Ctrue = %g' % (t, C, Ctrue)) 162 | 163 | plt.plot(tvec,Avec,tvec,Bvec,tvec,Cvec) 164 | plt.show() 165 | 166 | def testSensitivity(self): 167 | """ 168 | This test solves a simple set of ODEs numerically using DASSL and 169 | compares the result to a known analytical solution. The physical 170 | system this problem represents is two first-order chemical reactions 171 | in series in a homogeneous batch reactor. 172 | 173 | The governing equations are 174 | 175 | dA/dt = -k1*A 176 | dB/dt = k1*A - k2*B 177 | dC/dt = k2*B 178 | 179 | with initial conditions 180 | A(0) = 1.0 B(0) = 0.0 C(0) = 0.0 181 | 182 | and k1 = 1.0 and k2 = 0.25. The analytical solution is 183 | 184 | A(t) = exp(-k1*t) 185 | B(t) = k1/(k2-k1) * (exp(-k1*t) - exp(-k2*t)) 186 | C(t) = (1 - k2/(k2-k1) * exp(-k1*t) - k1/(k2-k1) * exp(-k2*t) 187 | 188 | Note that C(t) = A(0) - A(t) - B(t) since the governing equations are 189 | conservative. 190 | 191 | This tests whether finite difference sensitivities work in daspik 192 | """ 193 | 194 | k1 = 1.0; k2 = 0.25 195 | model = DASPKSensitivityModel(True, 1) 196 | t0 = 0.0 197 | n0 = numpy.array([1.0, 0.0, 0.0], numpy.float64) #state variables 198 | senpar = numpy.array([k1,k2], numpy.float64) 199 | neq = len(n0)*(len(senpar)+1) 200 | y0 = numpy.zeros(neq, numpy.float64) 201 | atol = numpy.ones(neq,numpy.float64)*1e-10 202 | rtol = numpy.ones(neq,numpy.float64)*1e-8 203 | for i in range(len(n0)): 204 | y0[i] = n0[i] 205 | atol[i] = 1e-16 206 | rtol[i] = 1e-8 207 | dydt0 = numpy.zeros(neq, numpy.float64) 208 | res = model.residual(t0, y0, numpy.zeros(neq, numpy.float64),senpar)[0] 209 | dydt0[:len(res)] = res 210 | model.initialize(t0, y0, dydt0, senpar, atol=atol, rtol=rtol) 211 | 212 | tmax = 100; iter = 0; maxiter = 1000 213 | tvec = [] 214 | dAdk1vec = [] 215 | dBdk1vec = [] 216 | dCdk1vec = [] 217 | dAdk2vec = [] 218 | dBdk2vec = [] 219 | dCdk2vec = [] 220 | 221 | Avec = [] 222 | Bvec = [] 223 | Cvec = [] 224 | while iter < 1000 and model.t < 16: 225 | model.step(tmax) 226 | t = model.t 227 | A, B, C = model.y[:3] 228 | tvec.append(model.t) 229 | dAdk1vec.append(model.y[3]*k1/A) 230 | dBdk1vec.append(model.y[4]*k1/B) 231 | dCdk1vec.append(model.y[5]*k1/C) 232 | dAdk2vec.append(model.y[6]*k2/A) 233 | dBdk2vec.append(model.y[7]*k2/B) 234 | dCdk2vec.append(model.y[8]*k2/C) 235 | 236 | Avec.append(A) 237 | Bvec.append(B) 238 | Cvec.append(C) 239 | Atrue = math.exp(-k1*t) 240 | Btrue = k1 / (k2 - k1) * (math.exp(-k1*t) - math.exp(-k2*t)) 241 | 242 | Ctrue = 1.0 - Atrue - Btrue 243 | if Atrue > 1e-8: 244 | self.assertAlmostEqual(A / Atrue, 1.0, 6) 245 | if Btrue > 1e-8: 246 | self.assertAlmostEqual(B / Btrue, 1.0, 6, 'At t = %g: B = %g, but Btrue = %g' % (t, B, Btrue)) 247 | if Ctrue > 1e-8: 248 | self.assertAlmostEqual(C / Ctrue, 1.0, 6, 'At t = %g: C = %g, but Ctrue = %g' % (t, C, Ctrue)) 249 | 250 | print "At 16 seconds after simulation..." 251 | print "dA/dk1 = %f" % dAdk1vec[-1] 252 | print "dB/dk1 = %f" % dBdk1vec[-1] 253 | print "dC/dk1 = %f" % dCdk1vec[-1] 254 | print "dA/dk2 = %f" % dAdk2vec[-1] 255 | print "dB/dk2 = %f" % dBdk2vec[-1] 256 | print "dC/dk2 = %f" % dCdk2vec[-1] 257 | plt.figure(1) 258 | plt.plot(tvec, Avec, label='A') 259 | plt.plot(tvec, Bvec, label='B') 260 | plt.plot(tvec, Cvec, label='C') 261 | plt.figure(2) 262 | plt.plot(tvec,dAdk1vec,label='dA/dk1') 263 | plt.plot(tvec,dAdk2vec,label='dA/dk2') 264 | plt.plot(tvec,dBdk1vec,label='dB/dk1') 265 | plt.plot(tvec,dBdk2vec,label='dB/dk2') 266 | plt.plot(tvec,dCdk1vec,label='dC/dk1') 267 | plt.plot(tvec,dCdk2vec,label='dC/dk2') 268 | 269 | plt.legend() 270 | plt.show() 271 | 272 | ################################################################################ 273 | 274 | if __name__ == '__main__': 275 | unittest.main( testRunner = unittest.TextTestRunner(verbosity=2) ) 276 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | ################################################################################ 5 | # 6 | # PyDAS - A Python wrapper to several differential algebraic system solvers 7 | # 8 | # Copyright (c) 2010-2014 by Joshua W. Allen (joshua.w.allen@gmail.com) 9 | # extended by Connie W. Gao (connieg@mit.edu) 10 | # 11 | # Permission is hereby granted, free of charge, to any person obtaining a 12 | # copy of this software and associated documentation files (the 'Software'), 13 | # to deal in the Software without restriction, including without limitation 14 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 15 | # and/or sell copies of the Software, and to permit persons to whom the 16 | # Software is furnished to do so, subject to the following conditions: 17 | # 18 | # The above copyright notice and this permission notice shall be included in 19 | # all copies or substantial portions of the Software. 20 | # 21 | # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | # DEALINGS IN THE SOFTWARE. 28 | # 29 | ################################################################################ 30 | 31 | import numpy 32 | import sys 33 | 34 | if __name__ == '__main__': 35 | 36 | # Use setuptools by default (requires Python>=2.6) if available 37 | # If not available, fall back to distutils 38 | # Using setuptools enables support for compiling wheels 39 | try: 40 | from setuptools import setup, Extension 41 | except ImportError: 42 | from distutils.core import setup 43 | from distutils.extension import Extension 44 | 45 | from Cython.Distutils import build_ext 46 | 47 | # Turn on HTML annotation file generation 48 | import Cython.Compiler.Options 49 | Cython.Compiler.Options.annotate = True 50 | 51 | # The Cython extension modules to compile 52 | pydas_ext = Extension( 53 | 'pydas', 54 | ['pydas.pyx'], 55 | include_dirs=['.', numpy.get_include()], 56 | libraries=['gfortran'], 57 | extra_objects=['dassl/daux.o','dassl/ddassl.o','dassl/dlinpk.o'], 58 | ) 59 | pydaspk_ext = Extension( 60 | 'pydaspk', 61 | ['pydaspk.pyx'], 62 | include_dirs=['.', numpy.get_include()], 63 | libraries=['gfortran'], 64 | extra_objects=['daspk31/adf_dummy.o','daspk31/daux.o','daspk31/ddaspk.o','daspk31/dlinpk.o','daspk31/dsensd.o','daspk31/mpi_dummy.o'], 65 | ) 66 | 67 | 68 | modules = ['pydas'] 69 | extensions = [pydas_ext] 70 | 71 | if 'daspk' in sys.argv: 72 | # Optionally compile and make pydaspk if the user requests it 73 | sys.argv.remove('daspk') 74 | modules.append('pydaspk') 75 | extensions.append(pydaspk_ext) 76 | 77 | # Run the setup command 78 | setup(name='PyDAS', 79 | version='0.1.0', 80 | description='A Python wrapper to several differential algebraic system solvers', 81 | author='Joshua W. Allen', 82 | author_email='joshua.w.allen@gmail.com', 83 | url='http://github.com/jwallen/PyDAS', 84 | py_modules= modules, 85 | cmdclass = {'build_ext': build_ext}, 86 | ext_modules = extensions 87 | ) 88 | --------------------------------------------------------------------------------