/* Filename: ex2.c
 *
 *   Prometheus library C interface  example
 *
 */
#undef __FUNC__
#define __FUNC__ "main"
int main( int argc, char **args )
{

    int ierr, flag, ii, memlev=0, nstep=1, niter=0, exe_number = 2, minc=4;
    int numnd, numel, nena, nen1a, nndf, *edges=0, *eq_id=0, *pepimethues;
    int npLoc, npGst,* proc_gnode=0,*ghost_gnode=0, *ghost_proc=0;
    Mat A;
    Vec x,b;
    Scalar energy, *coord=0;
    void *epimetheus = 0;

    ierr = PetscInitialize( &argc, &args, 0, 0 );                                                  CHKERRA(ierr);
    ierr = promCreate( &epimetheus );                                                            CHKERRA(ierr);
    ierr = promInitParameters( epimetheus );                                                            CHKERRA(ierr);
    /* construct data ...  (eg, "coord", "edges", etc. as specified in the users guide)  */

    /*  local data   */
    ierr = promInitLocal( epimetheus, coord, numnd, nndf, edges, numel, nena, nen1a,  ioffset, minc, eq_id);
    CHKERRA(ierr); // global data

    ierr = promInitGlobal( epimetheus, npLoc, npGst, proc_gnode, ghost_gnode, ghost_proc );
    CHKERRA(ierr);

    /*  init data is temporary -  free ...   */

    /*  get objects   */
    ierr = promGetA( epimetheus, &A );                                                CHKERRA(ierr);
    ierr = promGetb( epimetheus, &b );                                                  CHKERRA(ierr);

    /*  assemble data into objects ...   */

     /*  two exta levels   */
    ii = 0;
    ierr = promNewLevel( epimetheus, &ii );                                        CHKERRA(ierr);
    ii = 0;
    ierr = promNewLevel( epimetheus, &ii );                                         CHKERRA(ierr);

    /*  get ready for solves   */
    ierr = promFinalize( &epimetheus);                                                  CHKERRA(ierr);

    /*  solve   */
    ierr = PromPreSolv( epimetheus, nstep, niter );                                CHKERRA(ierr);
    ierr = promSolve( epimetheus, niter, &energy );                               CHKERRA(ierr);

    /*  look at ans ...   */
    ierr = PromGetx( epimetheus, &x );                                                  CHKERRA(ierr);

    /* clean up   */
    ierr = promDestroy( epimetheus );                                                    CHKERRA(ierr);
    ierr = PetscFinalize();                                                                        CHKERRA(ierr);
    return 0;
}