Ida Examples

download Ida Examples

of 26

Transcript of Ida Examples

  • 7/25/2019 Ida Examples

    1/26

    Example Programs for idav2.8.2

    Alan C. Hindmarsh, Radu Serban, and Aaron Collier

    Center for Applied Scientific Computing

    Lawrence Livermore National Laboratory

    July 29, 2015

    UCRL-SM-208113

  • 7/25/2019 Ida Examples

    2/26

    DISCLAIMER

    This document was prepared as an account of work sponsored by an agency of the UnitedStates government. Neither the United States government nor Lawrence Livermore NationalSecurity, LLC, nor any of their employees makes any warranty, expressed or implied, or as-sumes any legal liability or responsibility for the accuracy, completeness, or usefulness of anyinformation, apparatus, product, or process disclosed, or represents that its use would notinfringe privately owned rights. Reference herein to any specific commercial product, pro-cess, or service by trade name, trademark, manufacturer, or otherwise does not necessarily

    constitute or imply its endorsement, recommendation, or favoring by the United States gov-ernment or Lawrence Livermore National Security, LLC. The views and opinions of authorsexpressed herein do not necessarily state or reflect those of the United States government orLawrence Livermore National Security, LLC, and shall not be used for advertising or productendorsement purposes.

    This work was performed under the auspices of the U.S. Department of Energy by LawrenceLivermore National Laboratory under Contract DE-AC52-07NA27344.

    Approved for public release; further dissemination unlimited

  • 7/25/2019 Ida Examples

    3/26

    Contents

    1 Introduction 1

    2 Serial example problems 42.1 A dense example: idaRoberts dns . . . . . . . . . . . . . . . . . . . . . . . . . 42.2 A banded example: idaFoodWeb bnd . . . . . . . . . . . . . . . . . . . . . . . 62.3 A Krylov example: idaHeat2D kry . . . . . . . . . . . . . . . . . . . . . . . . 92.4 A sparse direct example: idaHeat2D klu . . . . . . . . . . . . . . . . . . . . . 11

    3 Parallel example problems 133.1 A user preconditioner example: idaHeat2D kry p . . . . . . . . . . . . . . . . 133.2 An IDABBDPRE preconditioner example: idaFoodWeb kry bbd p . . . . . . 14

    4 Fortran example problems 174.1 A serial example: fidaRoberts dns . . . . . . . . . . . . . . . . . . . . . . . . 17

    4.2 A parallel example: fidaHeat2D kry bbd p . . . . . . . . . . . . . . . . . . . . 18

    References 21

  • 7/25/2019 Ida Examples

    4/26

  • 7/25/2019 Ida Examples

    5/26

    1 Introduction

    This report is intended to serve as a companion document to the User Documentation ofida [2]. It provides details, with listings, on the example programs supplied with the ida

    distribution package.The ida distribution contains examples of four types: serial C examples, parallel C

    examples, and serial and parallel Fortran examples. With the exception of demo-typeexample files, the names of all the examples distributed with sundials are of the form[slv][PbName]_[ls]_[prec]_[p], where

    [slv] identifies the solver (for idaexamples this is ida, while for fidaexamples, this isfida);

    [PbName] identifies the problem;

    [ls] identifies the linear solver module used;

    [prec] indicates the idapreconditioner module used (if applicable for examples using a

    Krylov linear solver and the idabbdpremodule, this will be bbd);

    [p] indicates an example using the parallel vector module nvector parallel.

    The following lists summarize all examples distributed with ida.

    The idadistribution contains, in the srcdir/examples/ida/serial directory, the followingnine serial examples (using the nvector serialmodule):

    idaRoberts dns solves the Robertson chemical kinetics problem [3], which consists oftwo differential equations and one algebraic constraint. It also uses the rootfinding

    feature of ida.The problem is solved with the idadense linear solver using a user-supplied Jacobian.

    idaRoberts kluis the same as idaRoberts dns but uses the KLU sparse direct linearsolver.

    idaRoberts spsis the same as idaRoberts dnsbut uses the SuperLUMT sparse directlinear solver (with one thread).

    idaSlCrank dnssolves a system of index-2 DAEs, modeling a planar slider-crank mech-anism.

    The problem is obtained through a stabilized index reduction (Gear-Gupta-Leimkuhler)starting from the index-3 DAE equations of motion derived using three generalizedcoordinates and two algebraic position constraints.

    idaHeat2D bndsolves a 2-D heat equation, semidiscretized to a DAE on the unit square.

    This program solves the problem with the idaband linear solver and the defaultdifference-quotient Jacobian approximation. For purposes of illustration, IDACalcICis called to compute correct values at the boundary, given incorrect values as inputinitial guesses. The constraint u >0.0 is imposed for all components.

    1

  • 7/25/2019 Ida Examples

    6/26

    idaHeat2D krysolves the same 2-D heat equation problem asidaHeat2D bnd, with theKrylov linear solver idaspgmr. The preconditioner uses only the diagonal elements ofthe Jacobian.

    idaHeat2D klu solves the same 2-D heat equation problem as idaHeat2D bnd, withsparse linear solver idaklu.

    idaFoodWeb bndsolves a system of PDEs modelling a food web problem, with predator-prey interaction and diffusion, on the unit square in 2-D.

    The PDEs are discretized in space to a system of DAEs which are solved using theidaband linear solver with the default difference-quotient Jacobian approximation.

    idaKrylovDemo lssolves the same problem asidaHeat2D kry, with three Krylov linearsolvers idaspgmr, idaspbcg, and idasptfqmr. The preconditioner uses only thediagonal elements of the Jacobian.

    In the srcdir/examples/ida/parallel directory, the idadistribution contains the followingfour parallel examples (using the nvector parallelmodule):

    idaHeat2D kry p solves the same 2-D heat equation problem as idaHeat2D kry, withidaspgmr in parallel, and with a user-supplied diagonal preconditioner,

    idaHeat2D kry bbd p solves the same problem as idaHeat2D kry p.

    This program uses the Krylov linear solver idaspgmr in parallel, and the band-block-diagonal preconditioner idabbdpre with half-bandwidths equal to 1.

    idaFoodWeb kry p solves the same food web problem as idaFoodWeb bnd, but withidaspgmr and a user-supplied preconditioner.

    The preconditioner supplied to idaspgmr is the block-diagonal part of the Jacobianwith nsns blocks arising from the reaction terms only (ns = number of species).

    idaFoodWeb kry bbd p solves the same food web problem as idaFoodWeb kry p.

    This program solves the problem using idaspgmr in parallel and the idabbdprepre-conditioner.

    As part of the fida module, in the four subdirectories fcmix serial, fcmix parallel,fcmix openmp, and fcmix pthreads, within the directory srcdir/examples/ida, are the fol-lowing four examples for the Fortran-Cinterface:

    fidaRoberts dnsis a serial chemical kinetics example (dense) with rootfinding, equiv-alent to idaRoberts dns.

    fidaHeat2D kry bbd p is a parallel example (spgmr/idabbdpre) equivalent to theexample idaHeat2D kry bbd p.

    fidaRoberts dns openmp is the same as fidaRoberts dns but uses the NVECTORmodule NVECTOR OPENMP.

    fidaRoberts dns pthreads is the same as fidaRoberts dnsbut uses the NVECTORmodule NVECTOR PTHREADS.

    2

  • 7/25/2019 Ida Examples

    7/26

    In the following sections, we give detailed descriptions of some (but not all) of these examples.We also give our output files for each of these examples, but users should be cautioned thattheir results may differ slightly from these. Solution values may differ within tolerances, anddifferences in cumulative counters, such as numbers of steps or Newton iterations, may differ

    from one machine environment to another by as much as 10% to 20%.In the descriptions below, we make frequent references to the ida User Document [2]. All

    citations to specific sections (e.g. 4.2) are references to parts of that User Document, unlessexplicitly stated otherwise.

    Note. The examples in the ida distribution are written in such a way as to compile andrun for any combination of configuration options during the installation of sundials (seeAppendix ?? in the User Guide). As a consequence, they contain portions of code that willnot be typically present in a user program. For example, all example programs make use ofthe variablesSUNDIALS EXTENDED PRECISIONand SUNDIALS DOUBLE PRECISIONto test if thesolver libraries were built in extended or double precision, and use the appropriate conversion

    specifiers in printf functions. Similarly, the Fortran examples in fida are automaticallypre-processed to generate source code that corresponds to the manner in which the idalibraries were built (see 4in this document for more details).

    3

    http://-/?-http://-/?-
  • 7/25/2019 Ida Examples

    8/26

    2 Serial example problems

    2.1 A dense example: idaRoberts dns

    This example, due to Robertson [3], is a model of a three-species chemical kinetics system

    written in DAE form. Differential equations are given for species y1and y2while an algebraicequation determines y3. The equations for the species concentrations yi(t) are:

    y1

    =.04y1+ 104y2y3

    y2

    = +.04y1104y2y3310

    7y22

    0 =y1+y2+y31 .

    (1)

    The initial values are taken as y1 = 1, y2 = 0, and y3 = 0 This example computes the threeconcentration components on the interval from t = 0 through t = 41010. While integratingthe system, the program also use the rootfinding feature to find the points at which y1= 10

    4

    or at which y3 = 0.01.

    We give a rather detailed explanation of the parts of the program and their interactionwith ida.

    Following the initial comment block, this program has a number of#includelines, whichallow access to useful items in ida header files. The sundials types.h file provides thedefinition of the type realtype(see4.2in the user guide [2] for details). For now, it sufficesto read realtype as double. The ida.h file provides prototypes for the idafunctions to becalled (excluding the linear solver selection function), and also a number of constants thatare to be used in setting input arguments and testing the return value of IDASolve. Theida dense.h file provides the prototype for the IDADense function. The nvector serial.hfile is the header file for the serial implementation of the nvector module and includesdefinitions of theN Vectortype, a macro to access vector components, and prototypes for the

    serial implementation specific machine environment memory allocation and freeing functions.Finally, note that ida dense.h also includes the sundials dense.h file, which provides thedefinition of the dense matrix type DlsMat (type=1) and a macro for accessing matrixelements.

    This program includes the user-defined accessor macro IJth that is useful in writingthe problem functions in a form closely matching the mathematical description of the DAEsystem, i.e. with components numbered from 1 instead of from 0. The IJth macro is usedto access elements of a dense matrix of type DlsMat. It is defined using the denseaccessormacro DENSE ELEM which numbers matrix rows and columns starting with 0. The macroDENSE ELEM is fully described in 4.6.5.

    The program prologue ends with prototypes of the three user-supplied functions that are

    called by ida

    and the prototypes of five private functions. Of the latter, the fourPrint***functions perform printing operations, and check flag tests the return flag from the idauser-callable functions.

    After various declarations, the main program begins by allocating memory for the yy,yp, and avtol vectors using N VNew Serial with a length argument ofNEQ (= 3). The linesfollowing that load the initial values of the dependendent variable vectors into yy and yp, andset the relative tolerance rtol and absolute tolerance vector avtol. SerialN Vector valuesare set by first accessing the pointer to their underlying data using the macro NV DATA Sdefined by nvector serial in nvector serial.h.

    The calls toN VNew Serial, and also later calls to IDA***functions, make use of a private

    4

    http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/25/2019 Ida Examples

    9/26

    function, check flag, which examines the return value and prints a message if there was afailure. Thischeck flagfunction was written to be used for any serial sundialsapplication.

    The call to IDACreate creates the ida solver memory block. The return value of thisfunction is a pointer to the memory block for this problem. In the case of failure, the return

    value is NULL. This pointer must be passed in the remaining calls to idafunctions.The call to IDAInit allocates the solver memory block. Its arguments include the name

    of the C function resrob defining the residual function F(t ,y ,y), and the initial values oft, y, and y . The call to IDASVtolerancesspecifies a vector of absolute tolerances, and thiscall includes the relative tolerance rtol and the absolute tolerance vector avtol. See 4.5.1and 4.5.2 for full details of these calls. (The avtol vector is then freed, because idakeepsa separate copy of it.)

    The call to IDARootInit specifies that a rootfinding problem is to be solved along withthe integration of the DAE system, that the root functions are specified in the function grob,and that there are two such functions. Specifically, they are set to y1 0.0001 andy3 0.01,respectively. See 4.5.5for a detailed description of this call.

    The calls to IDADense (see 4.5.3) and IDADlsSetDenseJacFn (see 4.5.7.2) specify theidadense linear solver with an analytic Jacobian supplied by the user-supplied functionjacrob.

    The actual solution of the DAE initial value problem is accomplished in the loop overvalues of the output time tout. In each pass of the loop, the program calls IDASolve in theIDA NORMAL mode, meaning that the integrator is to take steps until it overshoots toutandthen interpolate tot =tout, putting the computed value ofy(tout) andy (tout) intoyy andyp, respectively, with tret = tout. The return value in this case is IDA SUCCESS. However,ifIDASolve finds a root before reaching the next value oftout, it returns IDA ROOT RETURNand stores the root location in tret and the solution there in yy and yp. In either case,the program prints t (= tret) and yy, and also the cumulative number of steps taken sofar, and the current method order and step size. In the case of a root, the program callsIDAGetRootInfo to get a length-2 arrayrootsfoundof bits showing which root function wasfound to have a root. If IDASolve returned any negative value (indicating a failure), theprogram breaks out of the loop. In the case of a IDA SUCCESS return, the value of tout isadvanced (multiplied by 10) and a counter (iout) is advanced, so that the loop can be endedwhen that counter reaches the preset number of output times, NOUT= 12. See 4.5.6for fulldetails of the call to IDASolve.

    Finally, the main program calls PrintFinalStats to extract and print several relevantstatistical quantities, such as the total number of steps, the number of residual and Jacobianevaluations, and the number of error test and convergence test failures. It then calls IDAFreeto free the idamemory block and N VDestroy Serial to free the vectors yy and yp.

    The function PrintFinalStats used here is actually suitable for general use in appli-

    cations of ida to any problem with a dense Jacobian. It calls various IDAGet*** andIDADenseGet*** functions to obtain the relevant counters, and then prints them. Specif-ically, these are: the cumulative number of steps (nst), the number of residual evaluations(nre) (excluding those for difference-quotient Jacobian evaluations), the number of residualevaluations for Jacobian evaluations (nreLS), the number of Jacobian evaluations (nje), thenumber of nonlinear (Newton) iterations (nni), the number of local error test failures (netf),the number of nonlinear convergence failures (ncfn), and the number ofgrob(root function)evaluations (nge). These optional outputs are described in 4.5.9.

    The functions resrob (of type IDAResFn) and jacrob (of type IDADenseJacFn) arestraightforward expressions of the DAE system (1) and its system Jacobian. The function

    5

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/25/2019 Ida Examples

    10/26

    jacrob makes use of the macro IJth discussed above. See4.6.1for detailed specificationsof IDAResFn. Similarly, the function grob defines the two functions, g0 and g1, whose rootsare to be found. See 4.6.4for a detailed description of the grob function.

    The output generated by idaRoberts dns is shown below. It shows the output values at

    the 12 preset values oftout. It also shows the two root locations found, first at a root ofg1,and then at a root ofg0.

    idaRoberts dns sample output

    i d aR o b er t s _d n s : R o be r ts o n k i ne t ic s D AE s e ri a l e x am p le p r ob l em f or I DA

    T h re e e q ua t io n c h em i ca l k i ne t ic s p r ob l em .

    L i n e ar s o l ve r : I D A DE N S E , w i th u se r - s u p p l i e d J a c o bi a n .

    T ol er an ce p ar am et er s : r to l = 0 . 00 01 a to l = 1 e -08 1 e -1 4 1 e- 06

    I ni ti al c on di ti on s y 0 = ( 1 0 0 )

    C o ns t ra i nt s a nd i d n ot u s ed .

    - - - - - - - - - - - - - -- - - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -t y1 y2 y3 | nst k h

    - - - - - - - - - - - - - -- - - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -

    2.6403 e-01 9.8997 e-01 3.4706 e-05 1.0000 e-02 | 85 2 6.4537 e-02

    rootsfound [] = 0 1

    4.0000 e-01 9.8517 e-01 3.3864 e-05 1.4796 e-02 | 88 2 6.4537 e-02

    4 .0 000 e +00 9 .05 50 e -01 2. 240 3e -05 9. 447 3e -02 | 102 4 4. 142 6e -01

    4 .0 000 e +01 7 .15 82 e -01 9. 185 1e -06 2. 841 7e -01 | 136 2 1. 342 2e +00

    4 .0 000 e +02 4 .50 49 e -01 3. 222 6e -06 5. 495 0e -01 | 190 4 3. 355 7e +01

    4 .0 000 e +03 1 .83 21 e -01 8. 942 9e -07 8. 167 9e -01 | 239 4 3. 453 3e +02

    4 .0 000 e +04 3 .89 84 e -02 1. 621 8e -07 9. 610 2e -01 | 287 5 2. 014 0e +03

    4 .0 000 e +05 4 .93 89 e -03 1. 985 2e -08 9. 950 6e -01 | 339 3 1. 678 8e +04

    4 .0 000 e +06 5 .16 83 e -04 2. 068 4e -09 9. 994 8e -01 | 444 4 2. 175 5e +05

    2 .0 793 e +07 1 .00 00 e -04 4. 000 4e -10 9. 999 0e -01 | 495 4 1. 014 6e +06

    rootsfound [] = -1 04 .0 000 e +07 5 .20 36 e -05 2. 081 6e -10 9. 999 5e -01 | 506 5 2. 550 3e +06

    4 .0 000 e +08 5 .21 03 e -06 2. 084 1e -11 9. 999 9e -01 | 541 4 2. 384 7e +07

    4 .0 000 e +09 5 .21 25 e -07 2. 085 0e -12 1. 000 0e -00 | 569 4 3. 935 1e +08

    4 .0 000 e +10 5 .10 91 e -08 2. 043 7e -13 1. 000 0e -00 | 589 2 6. 024 6e +09

    F i na l R un S t at i st i cs :

    Number of steps = 589

    N um ber of r es id ua l e va lu at io ns = 832

    N um ber of J ac ob ia n e va lu at io ns = 79

    N um ber of n on li ne ar it er at io ns = 832

    Number of error test failures = 14

    N u mb e r o f n o nl i ne a r c o nv . f a il u re s = 0

    N um ber of ro ot fn . e va lu at io ns = 624

    2.2 A banded example: idaFoodWeb bnd

    This example is a model of a multi-species food web [1], in which predator-prey relationshipswith diffusion in a 2-D spatial domain are simulated. Here we consider a model with s = 2pspecies: p predators and p prey. Species 1, . . . , p (the prey) satisfy rate equations, whilespecies p + 1, . . . , s(the predators) have infinitely fast reaction rates. The coupled PDEs for

    6

    http://-/?-http://-/?-http://-/?-http://-/?-
  • 7/25/2019 Ida Examples

    11/26

    the species concentrations ci(x,y,t) are:ci/t = Ri(x,y ,c) +di(c

    ixx+c

    iyy) i= 1, 2, . . . , p

    0 =Ri(x,y ,c) +di(cixx+c

    iyy) i= p+ 1, . . . , s ,

    (2)

    with

    Ri(x,y ,c) =ci

    bi+ s

    j=1

    aijcj

    .

    Here c denotes the vector {ci}. The interaction and diffusion coefficients (aij , bi, di) can befunctions of (x, y) in general. The choices made for this test problem are as follows:

    aij =

    1 i= j

    0.5106 i p, j > p

    104 i > p, j p

    0 all other (i, j) ,

    bi=bi(x, y) =

    (1 +xy+sin(4x) sin(4y)) i p

    (1 +xy+sin(4x)sin(4y)) i > p ,

    and

    di =

    1 i p

    0.5 i > p .

    The spatial domain is the unit square 0 x, y 1, and the time interval is 0 t 1. The boundary conditions are of homogeneous Neumann type (zero normal derivatives)everywhere. The coefficients are such that a unique stable equilibrium is guaranteed to existwhen = = 0 [1]. Empirically, a stable equilibrium appears to exist for (2) when and are positive, although it may not be unique. In this problem we take = 50 and= 1000. For the initial conditions, we set each prey concentration to a simple polynomialprofile satisfying the boundary conditions, while the predator concentrations are all set to aflat value:

    ci(x,y, 0) =

    10 +i[16x(1x)y(1y)]2 i p ,

    105 i > p .

    We discretize this PDE system (2) (plus boundary conditions) with central differencingon an LL mesh, so as to obtain a DAE system of size N =sL2. The dependent variablevector Cconsists of the values ci(xj , yk, t) grouped first by species index i, then by x, and

    lastly by y. At each spatial mesh point, the system has a block ofp ODEs followed by ablock of p algebraic equations, all coupled. For this example, we take p = 1, s = 2, andL= 20. The Jacobian is banded, with half-bandwidths mu = ml = sL = 40.

    TheidaFoodWeb bnd.cprogram includes the fileida band.hin order to use theidabandlinear solver. This file contains the prototype for the IDABand routine, the definition for theband matrix typeDlsMat (type=2), and theBAND COLandBAND COL ELEMmacros for access-ing matrix elements. See ??. The main idaheader file ida.his included for the prototypesof the solver user-callable functions and ida constants, while the file nvector serial.h isincluded for the definition of the serial N Vector type. The header file sundials dense.h isincluded for thenewDenseMatfunction used in allocating memory for the user data structure.

    7

  • 7/25/2019 Ida Examples

    12/26

    The include lines at the top of the file are followed by definitions of problem constantswhich include the x and y mesh dimensions, MX and MY, the number of equations NEQ, thescalar relative and absolute tolerances RTOL and ATOL, and various parameters for the food-web problem.

    Spatial discretization of the PDE naturally produces a DAE system in which equationsare numbered by mesh coordinates (i, j). The user-defined macro IJth Vptr isolates thetranslation for the mathematical two-dimensional index to the one-dimensional N Vectorindex and allows the user to write clean, readable code to access components of the dependentvariable. IJ Vptr(v,i,j) returns a pointer to the location in v corresponding to the specieswith index is = 0, x-index ix = i, and y-index jy = j .

    The typeUserDatais a pointer to a structure containing problem data used in the reswebfunction. This structure is allocated and initialized at the beginning ofmain. The pointer toit, called webdata, is then passed to IDASetUserData and as a result it will be passed backto the reswebfunction each time it is called.

    The main program is straightforward and very similar to that for idaRoberts dns. The

    differences come from the use of the idabandlinear solver and from the use of the consistentinitial conditions algorithm in idato correct the initial values. The call to IDABandincludesthe half-bandwidthsml and mu. IDACalcICis called with the option IDA YA YDP INIT, mean-ing that idais to compute the algebraic components ofy and differential components ofy,given the differential components of y. This option requires that the N Vector id be setthrough a call to IDASetId specifying the differential and algebraic components. In this ex-ample, id has components equal to 1 for the prey (indicating differential variables) and 0 forthe predators (algebraic variables).

    Next, the IDASolve function is called in a loop over the output times, and the solutionfor the species concentrations at the bottom-left and top-right corners is printed, along withthe cumulative number of time steps, current method order, and current step size.

    Finally, the main program calls PrintFinalStats to get and print all of the relevantstatistical quantities. It then calls N VDestroy Serialto free the vectors cc, cp, andid, andIDAFree to free the idamemory block.

    The function PrintFinalStats used here is actually suitable for general use in appli-cations of ida to any problem with a banded Jacobian. It calls various IDAGet*** andIDABandGet*** functions to obtain the relevant counters, and then prints them. Specifically,these are: the cumulative number of steps (nst), the number of residual evaluations (nre)(excluding those for difference-quotient Jacobian evaluations), the number of residual evalua-tions for Jacobian evaluations (nreLS), the number of Jacobian evaluations (nje), the numberof nonlinear (Newton) iterations (nni), the number of local error test failures (netf), andthe number of nonlinear convergence failures (ncfn). These optional outputs are describedin 4.5.9.

    The function reswebis a direct translation of the residual of (2). It first calls the privatefunction Fweb to initialize the residual vector with the right-hand side of (2) and then itloops over all grid points, setting residual values appropriately for differential or algebraiccomponents. The calculation of the interaction terms Ri is done in the function WebRates.

    Sample output from idaFoodWeb bndfollows.

    idaFoodWeb bnd sample output

    i d a F o o dW e b _ b n d : P r e da t o r - p r e y D A E s e r ia l e x a m pl e p r o b le m f o r I D A

    Number of species ns : 2 Mesh dimensions : 20 x 20 System size : 800

    8

    http://-/?-http://-/?-http://-/?-
  • 7/25/2019 Ida Examples

    13/26

    T ol er an ce p a ra me te rs : r to l = 1 e -0 5 a to l = 1 e -0 5

    L in ea r s ol ve r : I DA BA ND , B an d p ar am et er s m u = 4 0, m l = 4 0

    C a lc I C c a ll e d t o c o rr e ct i n it i al p r ed a to r c o n ce n tr a t io n s .

    - - - - - - - - - - - - - -- - - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -- -

    t bottom - left top - right | nst k h- - - - - - - - - - - - - -- - - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -- -

    0.00 e +00 1.0000 e+01 1.0000 e+05 | 0 0 1.6310 e -08

    1.0000 e+05 1.0000 e+05 |

    1.00 e -03 1.0318 e+01 1.0822 e+05 | 32 4 1.0823 e-04

    1.0319 e+05 1.0822 e+05 |

    1.00 e-02 1.6188 e+02 1.9734 e+06 | 127 4 1.4203 e-04

    1.6189 e+06 1.9734 e+06 |

    1.00 e-01 2.4019 e+02 2.7072 e+06 | 235 1 3.9160 e-02

    2.4019 e+06 2.7072 e+06 |

    4.00 e-01 2.4019 e+02 2.7072 e+06 | 238 1 3.1328 e-01

    2.4019 e+06 2.7072 e+06 |

    7.00 e-01 2.4019 e+02 2.7072 e+06 | 239 1 6.2657 e-01

    2.4019 e+06 2.7072 e+06 |

    1.00 e+00 2.4019 e+02 2.7072 e+06 | 239 1 6.2657 e-01

    2.4019 e+06 2.7072 e+06 |

    - - - - - - - - - - - - - -- - - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -- -

    F i na l r un s t at i st i cs :

    Number of steps = 239

    N um ber of r es id ua l e va lu at io ns = 33 39N um ber of J ac ob ia n e va lu at io ns = 36

    N um ber of n on li ne ar it er at io ns = 421

    Number of error test failures = 3

    N u mb e r o f n o nl i ne a r c o nv . f a il u re s = 0

    2.3 A Krylov example: idaHeat2D kry

    This example solves a discretized 2D heat PDE problem. The DAE system arises from theDirichlet boundary condition u = 0, along with the differential equations arising from thediscretization of the interior of the region.

    The domain is the unit square ={0 x, y 1} and the equations solved are:u/t= uxx+uyy (x, y)

    u= 0 (x, y) .(3)

    The time interval is 0 t 10.24, and the initial conditions are u= 16x(1x)y(1y).We discretize the PDE system (3) (plus boundary conditions) with central differencing

    on a 1010 mesh, so as to obtain a DAE system of size N= 100. The dependent variablevector u consists of the values u(xj, yk, t) grouped first by x, and then by y. Each discreteboundary condition becomes an algebraic equation within the DAE system.

    9

  • 7/25/2019 Ida Examples

    14/26

    In this case, ida spgmr.h is included for the definitions of constants and function proto-types associated with the spgmr method.

    After various initializations (including a vector of constraints with all components setto 1, imposing all solution components to be non-negative), the main program creates and

    initializes the ida memory block and then attaches the idaspgmr linear solver using thedefault MODIFIED GS Gram-Scmidt orthogonalization algorithm.

    The user-supplied preconditioner setup and solve functions, PsetupHeatandPsolveHeat,and the pointer to user data (data) are specified in a call to IDASpilsSetPreconditioner.In a loop over the desired output times, IDASolve is called in IDA NORMAL mode and themaximum solution norm is printed. Following this, three more counters are printed.

    The main program then re-initializes the idasolver and the idaspgmr linear solver andsolves the problem again, this time using the CLASSICAL GS Gramm-Schmidt orthogonal-ization algorithm. Finally, memory for the ida solver and for the various vectors used isdeallocated.

    The user-supplied residual function resHeat, of type IDAResFn, loads the DAE residual

    with the value of u on the boundary (representing the algebraic equations expressing theboundary conditions of (3)) and with the spatial discretization of the PDE (using centraldifferences) in the rest of the domain.

    The user-supplied functions PsetupHeatand PsolveHeattogether define the left precon-ditoner matrixP approximating the system Jacobian matrix J=F/u+F/u (wherethe DAE system is F(t,u,u) = 0), and solve the linear systems P z =r. Preconditioning isdone in this case by keeping only the diagonal elements of theJmatrix above, storing them asinverses in a vector pp, when computed inPsetupHeat, for subsequent use in PsolveHeat. Inthis instance, only cj = and data(the user data structure) are used from the PsetupHeatargument list.

    Sample output from idaHeat2D kry follows.

    idaHeat2D kry sample output

    i d aH e at 2 D _k r y : H e at e q ua t io n , s e ri a l e x am p le p r ob l em f or I DA

    D i sc r e ti z ed h e at e q ua t io n o n 2 D u ni t s q ua r e .

    Z e r o b o u n da r y c o n di t i on s , p o l y no m i a l i n i t ia l c o n d i ti o n s .

    Mesh dimensions : 10 x 10 Total system size : 100

    T ol er an ce p ar am et er s : r to l = 0 a to l = 0. 00 1

    C o ns t ra i nt s s et t o f o rc e a ll s o lu t io n c o mp o ne n ts > = 0 .

    L i n e ar s o l ve r : I D A SP G M R , p r e c o n d it i o n e r u s i ng d i a g o na l e l e m en t s .

    C as e 1 : g s yt p e = M O DI F I ED _ GS

    O u tp u t S u mm a ry ( u m ax = m ax - n o r m o f s o lu t io n )

    time umax k nst nni nje nre nreLS h npe nps

    - - - - - - - - - - - - - -- - - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - -

    0.01 8.24106 e -01 2 12 14 7 14 7 2.56 e -03 8 21

    0.02 6.88134 e -01 3 15 18 12 18 12 5.12 e -03 8 30

    0.04 4.70711 e -01 3 18 24 21 24 21 6.58 e -03 9 45

    0.08 2.16509 e -01 3 22 29 30 29 30 1.32 e -02 9 59

    0.16 4.57687 e -02 4 28 36 44 36 44 1.32 e -02 9 80

    0.32 2.09938 e -03 4 35 44 67 44 67 2.63 e -02 10 111

    0.64 0.00000 e +00 1 39 51 77 51 77 1.05 e -01 12 128

    1.28 0.00000 e +00 1 41 53 77 53 77 4.21 e -01 14 130

    10

  • 7/25/2019 Ida Examples

    15/26

    2.56 0.00000 e +00 1 43 55 77 55 77 1.69 e +00 16 132

    5.12 0.00000 e +00 1 44 56 77 56 77 3.37 e +00 17 133

    10.24 0.00000 e +00 1 45 57 77 57 77 6.74 e +00 18 134

    Error test failures = 1

    N o nl i ne a r c o nv e rg e nc e f a il u re s = 0L in ea r c on ve rg en ce f ai lu re s = 0

    C as e 2 : g s ty p e = C L A SS I CA L _ GS

    O u tp u t S u mm a ry ( u m ax = m ax - n o r m o f s o lu t io n )

    time umax k nst nni nje nre nreLS h npe nps

    - - - - - - - - - - - - - -- - - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - -

    0.01 8.24106 e -01 2 12 14 7 14 7 2.56 e -03 8 21

    0.02 6.88134 e -01 3 15 18 12 18 12 5.12 e -03 8 30

    0.04 4.70711 e -01 3 18 24 21 24 21 6.58 e -03 9 45

    0.08 2.16509 e -01 3 22 29 30 29 30 1.32 e -02 9 59

    0.16 4.57687 e -02 4 28 36 44 36 44 1.32 e -02 9 800.32 2.09938 e -03 4 35 44 67 44 67 2.63 e -02 10 111

    0.64 2.15648 e -20 1 39 51 77 51 77 1.05 e -01 12 128

    1.28 1.30250 e -20 1 41 53 77 53 77 4.21 e -01 14 130

    2.56 3.00951 e -20 1 43 55 77 55 77 1.69 e +00 16 132

    5.12 7.38674 e -20 1 44 56 77 56 77 3.37 e +00 17 133

    10.24 1.79685 e -19 1 45 57 77 57 77 6.74 e +00 18 134

    Error test failures = 1

    N o nl i ne a r c o nv e rg e nc e f a il u re s = 0

    L in ea r c on ve rg en ce f ai lu re s = 0

    2.4 A sparse direct example: idaHeat2D klu

    We provide an example of using ida with the KLU sparse direct solver module ida kluthat solves the same 2D heat PDE problem as idaHeat2D kry with the same zero Dirichletboundary conditions and central differencing but with no preconditioner. This example ismainly based off of the idaHeat2D bnd example program.

    Due to the nature of the Jacobian matrix of the 2D heat PDE problem in column majorformat, in order to store the Jacobian in compressed sparse column (CSC) format, it wasnecessary to have two separate user-supplied Jacobian functions. The function jacHeat3sets up the Jacobian in the special case that MGRID, the number of node points used in thecentral difference method, is 3. For MGRID 4, we use the function jacHeat.

    The main program is written in the same way it was written in idaHeat2D kry and

    idaHeat2D bnd but with a few exceptions. In order to use the IDAKLU solver, the user mustdetermine the number of non-zero (nnz) variables and there is a conditional statement tocheck the size ofMGRIDin order to determine which jacHeatfunction to use.

    The user-supplied function jacHeat3 specifies the values of the Jacobian matrix for theMGRID=3 case for each of the three datatypes needed for CSC format: column pointers(colptrs), actual data values (data), and row value of the data stored (rowvals).

    The user-supplied function jacHeat defines the structure of the Jacobian matrix for ageneral MGRID size greater than or equal to 4 in CSC format and fills in the three datatypesas needed. The system Jacobian matrix is defined as J=F/u + F/u with cj= asbefore. The column-based structure, which was determined heuristically, was generalized for

    11

  • 7/25/2019 Ida Examples

    16/26

    any size in the allowable range and to allow for the appropriate number of repeats within thestructure of the Jacobian matrix. The structures pattern was found by splitting the matrixinto MGRID blocks and determining the pattern within each block separately for each of thedatatypes.

    Theidapackage also includes support for SUPERLU MT, the parallel sparse direct solver.The idaHeat2D sps example has been included to demonstrate SUPERLU MT. It is verysimilar to idaHeat2D klu.

    Sample output from idaHeat2D klu follows.

    idaHeat2D klu sample output

    i d aH e at 2 D _k l u : H e at e q ua t io n , s e ri a l e x am p le p r ob l em f or I DA

    D i sc r et i ze d h ea t e q ua t io n o n 2 D u n it s q ua r e .

    Z e r o b o u n da r y c o n di t i on s , p o l y n om i a l i n i t ia l c o n d i ti o n s .

    Mesh dimensions : 10 x 10 Total system size : 100

    T ol er an ce p ar am et er s : r to l = 0 a to l = 1e -0 8

    C o ns t ra i nt s s et t o f o rc e a ll s o lu t io n c o mp o ne n ts > = 0 .L i n e ar s o l ve r : I D AK L U , s p a rs e d i r e ct s o l v er

    d i f f e re n c e q u o t ie n t J a c o b ia n

    I D AC a lc I C c a ll e d w i th i n pu t b o un d ar y v a lu e s = 0

    O u tp u t S u mm a ry ( u m ax = m ax - n o r m o f s o lu t io n )

    time umax k nst nni nje nre h

    . . . . . . . . . . . . . . . . . . .

    0.00 9.75461 e -01 0 0 0 2 2 5.15 e -10

    0.01 8.24056 e -01 5 53 63 23 65 5.55 e -04

    0.02 6.88097 e -01 5 69 81 24 83 9.99 e -04

    0.04 4.70961 e -01 5 90 106 27 108 1.91 e -03

    0.08 2.16312 e -01 5 113 130 27 132 1.72 e -03

    0.16 4.53210 e -02 5 137 155 28 157 3.43 e -030.32 1.98864 e -03 5 173 193 29 195 6.18 e -03

    0.64 3.83238 e -06 5 210 233 31 235 2.22 e -02

    1.28 0.00000 e +00 1 227 255 34 257 1.78 e -01

    2.56 0.00000 e +00 1 230 258 37 260 1.42 e +00

    5.12 0.00000 e +00 1 231 259 38 261 2.85 e +00

    10.24 0.00000 e +00 1 232 260 39 262 5.69 e +00

    netf = 2, ncfn = 0

    12

  • 7/25/2019 Ida Examples

    17/26

    3 Parallel example problems

    3.1 A user preconditioner example: idaHeat2D kry p

    As an example of using ida with the parallel MPI nvector parallel module and the

    Krylov linear solver idaspgmr with user-defined preconditioner, we provide the exampleidaHeat2D kry p which solves the same 2-D heat PDE problem as idaHeat2D kry.

    In the parallel setting, we can think of the processors as being laid out in a grid of sizeNPEX NPEY, with each processor computing a subset of the solution vector on a submeshof size MXSUB MYSUB. As a consequence, the computation of the residual vector requiresthat each processor exchange boundary information (namely the components at all interiorsubgrid boundaries) with its neighboring processors. The message-passing (implementedin the function rescomm) uses blocking sends, non-blocking receives, and receive-waiting,in routines BSend, BRecvPost, and BRecvWait, respectively. The data received from eachneighboring processor is then loaded into a work array, uext, which contains this ghost celldata along with the local portion of the solution.

    The local portion of the residual vector is then computed in the routine reslocal, whichassumes that all inter-processor communication of data needed to calculate rr has alreadybeen done. Components at interior subgrid boundaries are assumed to be in the work arrayuext. The local portion of the solution vectoruu is first copied intouext. The diffusion termsare evaluated in terms of the uext array, and the residuals are formed. The zero Dirichletboundary conditions are handled here by including the boundary components in the residual,giving algebraic equations for the discrete boundary conditions.

    The preconditioner (implemented in PsetupHeat and PsolveHeat) uses the diagonal el-ements of the Jacobian only and therefore involves only local calculations.

    The idaHeat2D kry p main program begins with MPI calls to initialize MPI and toset multi-processor environment parameters npes (number of processes) and thispe (local

    process index). Then the local and global vector lengths are set, the user-data structureUserdata is created and initialized, and N Vector variables are created and initialized forthe initial conditions (uuand up), for constraints, for the vectorid specifying the differentialand algebraic components of the solution vector, and for the preconditioner ( pp). As inidaHeat2D kry, constraints are passed to ida through the N Vector constraints and thefunction IDASetConstraints, with all components set to 1.0 to impose non-negativity oneach solution component. A temporary N Vector res is also created here, for use only inSetInitialProfiles. In addition, for illustration purposes, idaHeat2D kry p also excludesthe algebraic components of the solution (specified through the N Vector id) from the errortest by calling IDASetSuppressAlg with a flag TRUE.

    Sample output from idaHeat2D kry p follows.

    idaHeat2D kry p sample output

    i d a H e a t2 D _ k r y _p : H e a t e q ua t i on , p a r a ll e l e x a m pl e p r o b le m f o r I D A

    D i sc r et i z ed h ea t e q ua t io n o n 2 D u n it s q ua r e .

    Z e r o b o u n da r y c o n di t i on s , p o l y n om i a l i n i t ia l c o n d i ti o n s .

    Mesh dimensions : 10 x 10 Total system size : 100

    Subgrid dimensions : 5 x 5 Processor array : 2 x 2

    T ol er an ce p ar am et er s : r to l = 0 a to l = 0. 00 1

    C o ns t ra i nt s s et t o f o rc e a ll s o lu t io n c o mp o ne n ts > = 0 .

    S U PP R ES S AL G = T RU E t o s u pp r es s l o ca l e r ro r t e st i ng o n a ll b o un d ar y c o mp o ne n ts .

    L i ne a r s o lv e r : I D A S PG M R P r e co n d it i o ne r : d i ag o na l e l em e nt s o nl y .

    13

  • 7/25/2019 Ida Examples

    18/26

    O u tp u t S u mm a ry ( u m ax = m ax - n o r m o f s o lu t io n )

    time umax k nst nni nli nre nreLS h npe nps

    - - - - - - - - - - - - - -- - - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - -

    0.00 9.75461 e -01 0 0 0 0 0 0 0.00 e +00 0 00.01 8.24106 e -01 2 12 14 7 14 7 2.56 e -03 8 21

    0.02 6.88134 e -01 3 15 18 12 18 12 5.12 e -03 8 30

    0.04 4.70711 e -01 3 18 24 21 24 21 6.58 e -03 9 45

    0.08 2.16509 e -01 3 22 29 30 29 30 1.32 e -02 9 59

    0.16 4.57687 e -02 4 28 36 44 36 44 1.32 e -02 9 80

    0.32 2.09938 e -03 4 35 44 67 44 67 2.63 e -02 10 111

    0.64 5.54028 e -21 1 39 51 77 51 77 1.05 e -01 12 128

    1.28 3.85107 e -20 1 41 53 77 53 77 4.21 e -01 14 130

    2.56 5.00523 e -20 1 43 55 77 55 77 1.69 e +00 16 132

    5.12 1.50906 e -19 1 44 56 77 56 77 3.37 e +00 17 133

    10.24 4.63224 e -19 1 45 57 77 57 77 6.74 e +00 18 134

    Error test failures = 1

    N o nl i ne a r c o nv e rg e nc e f a il u re s = 0L in ea r c on ve rg en ce f ai lu re s = 0

    3.2 An IDABBDPRE preconditioner example: idaFoodWeb kry bbd p

    In this example, we solve the same food web problem as withidaFoodWeb bnd, but in paralleland with the idaspgmr linear solver and using the idabbdpremodule, which generates anduses a band-block-diagonal preconditioner.

    As withidaHeat2D kry p, we use a NPEX NPEYprocessor grid, with an MXSUB MYSUBsubmesh on each processor. Again, the residual evaluation begins with the communication ofghost data (in rescomm), followed by computation using an extended local array, cext, in the

    reslocal routine. The exterior Neumann boundary conditions are explicitly handled hereby copying data from the first interior mesh line to the ghost cell locations in cext. Thenthe reaction and diffusion terms are evaluated in terms of the cext array, and the residualsare formed.

    The Jacobian block on each processor is banded, and the half-bandwidths of that block areboth equal to NUM SPECIES MXSUB. This is the value supplied as mudqand mldqin the call toIDABBDPrecInit. But in order to reduce storage and computation costs for preconditioning,we supply the values mukeep = mlkeep = 2 (= NUM SPECIES) as the half-bandwidths of theretained band matrix blocks. This means that the Jacobian elements are computed with adifference quotient scheme using the true bandwidth of the block, but only a narrow bandmatrix (bandwidth 5) is kept as the preconditioner.

    The functionreslocalis also passed to the idabbdprepreconditioner as the Gresargu-ment, while aNULLpointer is passed for theGcommargument (since all required communicationfor the evaluation ofGres was already done for resweb).

    In theidaFoodWeb kry bbd pmain program, following MPI initializations and creation ofuser data block webdataand N Vectorvariables, the initial profiles are set, the idamemoryblock is created and allocated, the idabbdpre preconditioner is initialized, and the idaspgmrlinear solver is attached to the ida solver. The call to IDACalcIC corrects the initial valuesso that they are consistent with the DAE algebraic constraints.

    In a loop over the desired output times, the main solver function IDASolveis called, andselected solution components (at the bottom-left and top-right corners of the computational

    14

  • 7/25/2019 Ida Examples

    19/26

    domain) are collected on processor 0 and printed to stdout. The main program ends byprinting final solver statistics, freeing memory, and finalizing MPI.

    Sample output from idaFoodWeb kry bbd p follows.

    idaFoodWeb kry bbd p sample output

    i d a F o o d We b _ k r y _ b bd _ p : P r ed a t or - p r e y D A E p a r a ll e l e x a m pl e p r o b le m

    N um be r o f s pe ci es n s: 2

    Mesh dimensions : 20 x 20

    To ta l s ys tem siz e: 800

    S ub gr id d im en si on s : 10 x 10

    Processor array : 2 x 2

    T o l e r an c e p a r a m et e r s :

    r e la t iv e t o le r an c e = 1 e - 05

    a b so l ut e t o le r an c e = 1 e - 05

    L i ne a r s o lv e r : s c al e d p r ec o n di t io n e d G M RE S ( I D A SP G MR )

    ma x . Kry lov dim ension : ma xl = 16

    P r e c o n di t i o n e r : b a nd - b l oc k - d i a g o na l ( I D A B B D P RE )mud q = 20 , ml dq = 20 , muk eep = 2 , mlk eep = 2

    C a lc I C c a ll e d t o c o rr e ct i n it i al p r ed a to r c o n ce n tr a t io n s

    - - - - - - - - - - - - - -- - - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -- -

    t bottom - left top - right | nst k h

    - - - - - - - - - - - - - -- - - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -- -

    0.00 e +00 1.0000 e+01 1.0000 e+01 | 0 0 1.6310 e -08

    1.0000 e+05 1.0000 e+05 |

    1.00 e -03 1.0318 e+01 1.0827 e+01 | 33 4 9.7404 e-05

    1.0319 e+05 1.0822 e+05 |

    1.00 e-02 1.6189 e+02 1.9735 e+02 | 123 3 1.9481 e-041.6189 e+06 1.9735 e+06 |

    1.00 e-01 2.4019 e+02 2.7072 e+02 | 197 1 4.0396 e-02

    2.4019 e+06 2.7072 e+06 |

    4.00 e-01 2.4019 e+02 2.7072 e+02 | 200 1 3.2316 e-01

    2.4019 e+06 2.7072 e+06 |

    7.00 e-01 2.4019 e+02 2.7072 e+02 | 200 1 3.2316 e-01

    2.4019 e+06 2.7072 e+06 |

    1.00 e+00 2.4019 e+02 2.7072 e+02 | 201 1 6.4633 e-01

    2.4019 e+06 2.7072 e+06 |

    - - - - - - - - - - - - - -- - - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -- -

    F i n al s t a t i st i c s :

    Number of steps = 201

    N um ber of r es id ua l e va lu at io ns = 11 10

    N um ber of n on li ne ar it er at io ns = 245

    Number of error test failures = 0

    N u mb e r o f n o nl i ne a r c o nv . f a il u re s = 0

    Number of linear iterations = 863

    15

  • 7/25/2019 Ida Examples

    20/26

    N um ber of li ne ar c onv . fa il ur es = 0

    N um be r o f p re co nd it io ne r se tu ps = 26

    N um be r o f p re co nd it io ne r so lv es = 11 10

    N um be r o f l oc al r es id ua l ev al s . = 10 92

    16

  • 7/25/2019 Ida Examples

    21/26

    4 Fortran example problems

    The Fortran example problem programs supplied with the idapackage are all written instandardFortran77 and use double precision arithmetic. However, when theFortranex-

    amples are built, the source code is automatically modified according to the configure optionssupplied by the user and the system type. Integer variables are declared asINTEGER*n, wheren denotes the number of bytes in the corresponding C type (long intor int). Floating-point variable declarations remain unchanged if double precision is used, but are changedto REAL*n, where n denotes the number of bytes in the sundials type realtype, if usingsingle precision. Also, if using single precision, then declarations of floating-point constantsare appropriately modified; e.g. 0.5D-4is changed to 0.5E-4.

    4.1 A serial example: fidaRoberts dns

    The fidaRoberts dns example is a Fortran equivalent of the idaRoberts dns example.The main program begins with declarations and initializations. It calls the routines

    FNVINITS, FIDAMALLOC, FIDAROOTINIT, FIDADENSE, and FIDADENSESETJAC, to initialize thenvector serial module, the main solver memory, the rootfinding module, and the idadensemodule, and to specify user-supplied Jacobian routine, respectively. It calls FIDASOLVE in aloop over TOUT values, with printing of the solution values and performance data (currentorder and step count from the IOUTarray, and current step size from the ROUTarray). In thecase of a root return, an extra line is printed with the root information from FIDAROOTINFO.At the end, it prints a number of performance counters, and frees memory with calls toFIDAROOTFREE and FIDAFREE.

    In fidaRoberts dns.f, the FIDARESFUN routine is a straghtforward implementation ofEqns. (1). In FIDADJAC, the 3 3 system Jacobian is supplied. The FIDAROOTFN routinedefines the two root functions, which are set to determine the points at which y1 = 10

    4 or

    y3= .01. The final two routines are for printing a header and the final run statistics.The following is sample output from fidaRoberts dns. The performance offida here is

    similar to that of idaon the idaRoberts dns problem, with somewhat lower cost countersowing to the larger absolute error tolerances.

    fidaRoberts dns sample output

    f i da R o be r t s_ d ns : R o be r ts o n k i ne t ic s D AE s e ri a l e x a mp l e pr o bl e m f or I DA

    T h r ee e q u a t io n c h e m i c a lk i n e t i cs p r o b le m .

    T ol er an ce p a ra me te rs : r to l = 0 .1 0 E -0 3 a to l = 0 .1 0 E -0 5 0. 10 E - 09 0 .1 0 E -0 5

    I n it i al c o nd i ti o ns y 0 = ( 0 . 10 E + 0 1 0 .0 0 E + 00 0 . 00 E + 0 0)

    t y1 y2 y3 nst k h

    0.2640 E+00 0.9900 E+00 0.3471 E-04 0.1000 E-01 75 2 0.5716 E-01

    Above is a root , INFO () = 0 1

    0.4000 E+00 0.9852 E+00 0.3386 E-04 0.1480 E-01 77 3 0.1143 E+00

    0.4000 E+01 0.9055 E+00 0.2240 E-04 0.9447 E-01 91 4 0.3704 E+00

    0 .4 000 E +02 0 .71 58 E +00 0. 918 5E -05 0. 284 2E +00 127 4 0 .29 63 E +01

    0 .4 000 E +03 0 .45 05 E +00 0. 322 3E -05 0. 549 5E +00 177 3 0 .12 41 E +02

    0 .4 000 E +04 0 .18 32 E +00 0. 894 0E -06 0. 816 8E +00 228 3 0 .27 65 E +03

    0 .4 000 E +05 0 .38 99 E -01 0. 162 2E -06 0. 961 0E +00 278 5 0 .26 14 E +04

    0 .4 000 E +06 0 .49 39 E -02 0. 198 5E -07 0. 995 1E +00 324 5 0 .27 70 E +05

    0 .4 000 E +07 0 .51 76 E -03 0. 207 2E -08 0. 999 5E +00 355 4 0 .39 79 E +06

    0 .2 075 E +08 0 .10 00 E -03 0. 400 0E -09 0. 999 9E +00 374 4 0 .15 92 E +07

    17

  • 7/25/2019 Ida Examples

    22/26

    Above i s a root , I NFO () = -1 0

    0 .4 000 E +08 0 .51 91 E -04 0. 207 6E -09 0. 999 9E +00 380 3 0 .63 66 E +07

    0 .4 000 E +09 0 .58 82 E -05 0. 235 3E -10 0. 100 0E +01 394 1 0 .91 67 E +08

    0 .4 000 E +10 0 .70 54 E -06 0. 282 2E -11 0. 100 0E +01 402 1 0 .14 67 E +10

    0 .4 00 0E +1 1 - 0. 73 00 E -0 6 - 0. 29 20 E -1 1 0 .1 00 0 E+ 01 40 7 1 0 .2 34 7E +1 1

    F i na l R un S t at i st i cs :

    Number of steps = 407

    N um ber of r es id ua l e va lu at io ns = 557

    Number of Jacobian evaluations = 65

    N um ber of n on li ne ar it er at io ns = 557

    Number of error test failures = 6

    N um be r o f n on li ne ar c on v. f a il ur es = 0

    N um ber of ro ot fu nc ti on eval s. = 437

    4.2 A parallel example: fidaHeat2D kry bbd p

    This example, fidaHeat2D kry bbd p, is the Fortran equivalent ofidaHeat2D kry bbd p.The heat equation problem is described under the idaHeat2D kry example above, but hereit is solved in parallel, using the idabbdpre (band-block-diagonal) preconditioner mod-ule. The decomposition of the problem onto a processor array is identical to that in theidaHeat2D kry p example above.

    The problem is solved twice once with half-bandwidths of 5 in the difference-quotientbanded preconditioner blocks, and once with half-bandwidths of 1 (which results in lumpingof Jacobian values). In both cases, the retained banded blocks are tridiagonal, even thoughthe true Jacobian is not.

    The main program begins with initializations, includingMPI calls, a call to FNVINITPtoinitialize nvector parallel, and a call to SETINITPROFILEto initialize the UU, UP, ID, and

    CONSTR arrays (containing the solution vector, solution derivative vector, the differential/al-gebraic bit vector, and the contraint specification vector, respectively). A call to FIDASETIINand two calls toFIDASETVINare made to suppress error control on the algebraic variables, andto supply the ID array and constraints array (making the computed solution non-negative).The call to FIDAMALLOC initializes the fida main memory, and the calls to FIDASPGMR andFIDABBDINIT and initialize the fidabbd module.

    In the first loop over TOUTvalues, the main program calls FIDASOLVEand prints the max-norm of the solution and selected counters. When finished, it calls PRNTFINALSTATSto printa few more counters.

    The second solution is initialized by resetting mudqand mldq, followed by a second callto SETINITPROFILE, and by calls to FIDAREINIT and FIDABBDREINIT. After completing the

    second solution, the program frees memory and terminates MPI.The FIDARESFUN routine simply calls two other routines: FIDACOMMFN, to communicate

    needed boundary data from U to an extension of it called UEXT; and FIDAGLOCFN, to computethe residuals in terms ofUEXT and UP.

    The following is a sample output from fidaHeat2D kry bbd p, with a 1010 mesh andNPES = 4 processors. The performance is similar for the two solutions. The second caserequires more linear iterations, as expected, but their cost is offset by the much cheaperpreconditioner evaluations.

    18

  • 7/25/2019 Ida Examples

    23/26

    fidaHeat2D kry bbd p sample output

    f i d a H e a t2 D _ k r y _ b bd _ p : H e at e q u at i o n , p a r a ll e l e x a m pl e p r o b le m f o r F I D A

    D i sc r et i ze d h e at e q ua t io n o n 2 D u ni t s q ua r e .

    Z e r o b o u n da r y c o n di t i on s , p o l y n om i a l c o n d i ti o n s .Mesh dimensions : 10 x 10 Total system size : 100

    Subgrid dimensions : 5 x 5 Processor array : 2 x 2

    T ol er an ce p ar am et er s : r to l = 0 . 00 E + 00 a to l = 0 . 10 E - 02

    C o ns t ra i nt s s et t o f o rc e a ll s o lu t io n c o mp o ne n ts > = 0 .

    S U PP R ES S AL G = T RU E t o r e mo v e b o un d ar y c o mp o ne n ts f ro m t he e rr o r t es t .

    L i ne a r s o lv e r : S PG M R . P r e co n d it i o ne r : B B DP R E - B an de d - b lo ck - d i ag o na l .

    Case 1

    D i ff e re n ce q u ot i en t h al f - b a n d wi d th s = 5

    R e ta i ne d m a tr i x h al f - b a n dw i dt h s = 1

    O u t p ut S u m m ar yu m ax = m ax - n o r m o f s o lu t io n

    n re = n re + n re LS ( t ot al n um be r o f R ES e va ls . )

    time umax k nst nni nli nre nge h npe nps

    - - - - - - - - - - - - - -- - - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - - -- -

    0.1000 E -01 0.82411 E +00 2 12 14 7 14+ 7 96 0.26 E -02 8 21

    0.2000 E -01 0.68812 E +00 3 15 18 12 18+12 96 0.51 E -02 8 30

    0.4000 E -01 0.47075 E +00 3 18 24 22 24+22 108 0.66 E -02 9 46

    0.8000 E -01 0.21660 E +00 3 22 29 30 29+30 108 0.13 E -01 9 59

    0.1600 E +00 0.45659 E -01 4 28 37 43 37+43 120 0.26 E -01 10 80

    0.3200 E +00 0.21096 E -02 4 35 45 59 45+59 120 0.24 E -01 10 104

    0.6400 E +00 0.55368 E -04 1 40 54 71 54+71 156 0.19 E +00 13 125

    0.1280 E +01 0.15597 E -18 1 42 56 71 56+71 180 0.76 E +00 15 127

    0.2560 E +01 0.33865 E -20 1 43 57 71 57+71 192 0.15 E +01 16 1280.5120 E +01 0.86074 E -20 1 44 58 71 58+71 204 0.30 E +01 17 129

    0.1024 E +02 0.16630 E -19 1 45 59 71 59+71 216 0.61 E +01 18 130

    Error test failures = 1

    N on li ne ar c on ve rg en ce f ai lu re s = 0

    L in ear c on ve rg en ce f ai lu res = 0

    Case 2

    D i ff e re n ce q u ot i en t h al f - b a n d wi d th s = 1

    R e ta i ne d m a tr i x h al f - b a n dw i dt h s = 1

    O u t p ut S u m m ar y

    u m ax = m ax - n o r m o f s o lu t io nn re = n re + n re LS ( t ot al n um be r o f R ES e va ls . )

    time umax k nst nni nli nre nge h npe nps

    - - - - - - - - - - - - - -- - - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - -- - - - - - - - - - - - - - -- -

    0.1000 E -01 0.82411 E +00 2 12 14 7 14+ 7 32 0.26 E -02 8 21

    0.2000 E -01 0.68812 E +00 3 15 18 12 18+12 32 0.51 E -02 8 30

    0.4000 E -01 0.47093 E +00 3 19 23 20 23+20 36 0.10 E -01 9 43

    0.8000 E -01 0.21655 E +00 3 23 27 32 27+32 36 0.10 E -01 9 59

    0.1600 E +00 0.45225 E -01 4 27 33 44 33+44 40 0.20 E -01 10 77

    0.3200 E +00 0.21868 E -02 3 34 41 67 41+67 44 0.41 E -01 11 108

    0.6400 E +00 0.48847 E -18 1 39 49 86 49+86 52 0.16 E +00 13 135

    19

  • 7/25/2019 Ida Examples

    24/26

    0.1280 E +01 0.53982 E -18 1 41 51 86 51+86 60 0.66 E +00 15 137

    0.2560 E +01 0.74194 E -17 1 42 52 86 52+86 64 0.13 E +01 16 138

    0.5120 E +01 0.61081 E -16 1 43 53 86 53+86 68 0.26 E +01 17 139

    0.1024 E +02 0.40536 E -15 1 44 54 86 54+86 72 0.52 E +01 18 140

    Error test failures = 0N on li ne ar c on ve rg en ce f ai lu re s = 0

    L in ear c on ve rg en ce f ai lu res = 0

    20

  • 7/25/2019 Ida Examples

    25/26

    References

    [1] Peter N. Brown. Decay to uniform states in food webs. SIAM J. Appl. Math., 46:376392,1986.

    [2] A. C. Hindmarsh, R. Serban, and A. Collier. User Documentation for IDA v2.7.0. Tech-nical Report UCRL-SM-208112, LLNL, 2011.

    [3] H. H. Robertson. The solution of a set of reaction rate equations. In J. Walsh, editor,Numerical analysis: an introduction, pages 178182. Academ. Press, 1966.

    21

  • 7/25/2019 Ida Examples

    26/26