%===================================================================================
\section{Fortran example problems}\label{s:ex_fortran}
%===================================================================================

The {\F} example problem programs supplied with the {\ida}
package are all written in standard {\F}77 and use double precision
arithmetic.  Before running any of these examples, the user should
make sure that the {\F} data types for real and integer variables
appropriately match the {\CC} types.  See \S\ref{ss:fcdata} in the
{\ida} User Document for details.

\subsection{A serial example: fidaRoberts\_dns}\label{ss:fidaRoberts}

The \id{fidaRoberts\_dns} example is a {\F} equivalent of the
\id{idaRoberts\_dns} example.

The main program begins with declarations and initializations.  
It calls the routines \id{FNVINITS}, \id{FIDAMALLOC}, \id{FIDAROOTINIT}, 
\id{FSUNDENSEMATINIT}, \id{FSUNDENSELINSOLINIT}, \id{FIDALSINIT}, and
\id{FIDADENSESETJAC}, to initialize the {\nvecs} module, the main
solver memory, the rootfinding module, the {\sunmatdense} module, the
{\sunlinsoldense} module, attach these to {\ida}, and to specify
user-supplied Jacobian routine, respectively. 
It calls \id{FIDASOLVE} in a loop over \id{TOUT} values, with printing of
the solution values and performance data (current order and step count
from the \id{IOUT} array, and current step size from the \id{ROUT} array).
In the case of a root return, an extra line is printed with the root
information from \id{FIDAROOTINFO}.  At the end, it prints a number of
performance counters, and frees memory with calls to \id{FIDAROOTFREE}
and \id{FIDAFREE}.

In \id{fidaRoberts\_dns.f}, the \id{FIDARESFUN} routine is a straghtforward
implementation of Eqns. (\ref{e:idaRoberts_DAE}).  In \id{FIDADJAC}, the 
$3 \times 3$ system Jacobian is supplied.  The \id{FIDAROOTFN} routine
defines the two root functions, which are set to determine the points at which
$y_1 = 10^{-4}$ or $y_3 = .01$.  The final two routines are for
printing a header and the final run statistics.

The following is sample output from \id{fidaRoberts\_dns}.
The performance of {\fida} here is similar to that of {\ida} on
the \id{idaRoberts\_dns} problem, with somewhat lower cost counters owing to
the larger absolute error tolerances.

%%
\includeOutput{fidaRoberts\_dns}{../../examples/ida/fcmix_serial/fidaRoberts_dns.out}
%%

%-----------------------------------------------------------------------------------

\subsection{A parallel example: fidaHeat2D\_kry\_bbd\_p}\label{ss:fidaHeat2D_bbd_p}

This example, \id{fidaHeat2D\_kry\_bbd\_p}, is the {\F} equivalent of
\id{idaHeat2D\_kry\_bbd\_p}.  The heat equation problem is described
under the \id{idaHeat2D\_kry} example above, but here it is solved in
parallel, using the {\idabbdpre} (band-block-diagonal) preconditioner
module.  The decomposition of the problem onto a processor array is
identical to that in the \id{idaHeat2D\_kry\_p} example above.

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

The main program begins with initializations, including {\mpi} calls,
a call to \id{FNVINITP} to initialize {\nvecp}, and a call to
\id{SETINITPROFILE} to initialize the \id{UU}, \id{UP}, \id{ID}, and
\id{CONSTR} arrays (containing the solution vector, solution derivative vector,
the differential/algebraic bit vector, and the contraint specification
vector, respectively).  A call to \id{FIDASETIIN} and two calls to
\id{FIDASETVIN} are made to suppress error control on the algebraic
variables, and to supply the \id{ID} array and constraints array (making
the computed solution non-negative).  The call to \id{FIDAMALLOC}
initializes the {\fida} main memory.  The calls to
\id{FSUNSPGMRINIT}, \id{FSUNSPGMRSETMAXRS}, \id{FIDALSINIT} and
\id{FIDABBDINIT} create and initialize the {\spgmr} solver and {\fidabbd} module.

In the first loop over \id{TOUT} values, the main program calls \id{FIDASOLVE}
and prints the max-norm of the solution and selected counters.  When finished,
it calls \id{PRNTFINALSTATS} to print a few more counters.

The second solution is initialized by resetting \id{mudq} and \id{mldq},
followed by a second call to \id{SETINITPROFILE}, and by calls to \id{FIDAREINIT} 
and \id{FIDABBDREINIT}.  After completing the second solution, the
program frees memory and terminates MPI.

The \id{FIDARESFUN} routine simply calls two other routines: \id{FIDACOMMFN},
to communicate needed boundary data from \id{U} to an extension of it called
\id{UEXT}; and \id{FIDAGLOCFN}, to compute the residuals in terms of
\id{UEXT} and \id{UP}.

The following is a sample output from \id{fidaHeat2D\_kry\_bbd\_p}, with a $10 \times 10$
mesh and \id{NPES} = 4 processors.  The performance is similar for the two
solutions.  The second case requires more linear iterations, as expected, 
but their cost is offset by the much cheaper preconditioner evaluations.

%%
\includeOutput{fidaHeat2D\_kry\_bbd\_p}{../../examples/ida/fcmix_parallel/fidaHeat2D_kry_bbd_p.out}
%%

%-----------------------------------------------------------------------------------
