/*
 * file:   ssman1d.c
 * author: Hinke Osinga and Reza Rokni --- University of Exeter
 * date:   April 2001
 */


/*
 * ssman1d_instal(void)
 * ssman1d_reset(void)
 * mans_clear(void)
 */


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <constants.h>
#include <defaults.h>

#include "utilities.h"
#include "math_utils.h"
#include "pm.h"
#include "ssman1d.h"


static char *SSMAN_OBJ_NAME = "SSMan1D";

static char *SSMAN[] = {
  "SSMan1D.Side",
  "SSMan1D.Ini_Step",
  "SSMan1D.Stab_ARC",
  "SSMan1D.Unstab_ARC",
  "SSMan1D.Tot_Steps",
  "SSMan1D.Curve",
  "SSMan1D.alpha_min",
  "SSMan1D.alpha_max",
  "SSMan1D.Delta_alpha_min",
  "SSMan1D.Delta_alpha_max",
  "SSMan1D.Delta_min",
  "SSMan1D.compute_ssman1d",
  "SSMan1D.compute_suman1d",
  "SSMan1D.clear_mans",
  "SSMan1D.Reset"
};

typedef enum{SIDE, INI_STEP, STAB_ARC, UNSTAB_ARC, TOT_STEPS, CURVE,
	       ALPHA_MIN, ALPHA_MAX, DELTA_ALPHA_MIN,  
	       DELTA_ALPHA_MAX, DELTA_MIN, 
               COMPUTE_SSMAN, COMPUTE_SUMAN,  
	       CLEAR_MANS,RESET} SSMAN_t;


void ssman1d_install()
{
  void mans_clear(), ssman1d_compute_init();
  void suman1d_compute_init(), ssman1d_reset();

  /* create elements for window values in the Postmaster */
  pm(CREATE_OBJ, SSMAN_OBJ_NAME,
    CREATE_ELEM, SSMAN[SIDE], INT,
     CREATE_ELEM, SSMAN[INI_STEP], DBL,
     CREATE_ELEM, SSMAN[STAB_ARC], DBL,
     CREATE_ELEM, SSMAN[UNSTAB_ARC], DBL,
     CREATE_ELEM, SSMAN[TOT_STEPS], INT,
     CREATE_ELEM, SSMAN[CURVE], INT,
     CREATE_ELEM, SSMAN[ALPHA_MIN], DBL,
     CREATE_ELEM, SSMAN[ALPHA_MAX], DBL,
     CREATE_ELEM, SSMAN[DELTA_ALPHA_MIN], DBL,
     CREATE_ELEM, SSMAN[DELTA_ALPHA_MAX], DBL,
     CREATE_ELEM, SSMAN[DELTA_MIN], DBL,
     CREATE_ELEM, SSMAN[COMPUTE_SSMAN], FNCT,
     CREATE_ELEM, SSMAN[COMPUTE_SUMAN], FNCT,
     CREATE_ELEM, SSMAN[CLEAR_MANS], FNCT,
     CREATE_ELEM, SSMAN[RESET], FNCT,
     NULL);

  /* initialize the function pointers in the Postmaster */
  pm(INIT, SSMAN[COMPUTE_SSMAN],
     PUT, SSMAN[COMPUTE_SSMAN], ssman1d_compute_init,
     INIT, SSMAN[COMPUTE_SUMAN],
     PUT, SSMAN[COMPUTE_SUMAN], suman1d_compute_init,
     INIT, SSMAN[CLEAR_MANS],
     PUT, SSMAN[CLEAR_MANS], mans_clear,
     INIT, SSMAN[RESET],
     PUT, SSMAN[RESET], ssman1d_reset,
     NULL);
}

void ssman1d_reset()
{
  pm(PUT, SSMAN[SIDE], 0, NULL);
  pm(PUT, SSMAN[INI_STEP], 1.0e-06, NULL);
  pm(PUT, SSMAN[STAB_ARC], 10.0, NULL);
  pm(PUT, SSMAN[UNSTAB_ARC], 10.0, NULL);
  pm(PUT, SSMAN[TOT_STEPS], 2000000, NULL);
  pm(PUT, SSMAN[CURVE], 0, NULL);
  pm(PUT, SSMAN[ALPHA_MIN], 0.2 , NULL);
  pm(PUT, SSMAN[ALPHA_MAX], 0.3 , NULL);
  pm(PUT, SSMAN[DELTA_ALPHA_MIN], 1e-5 , NULL);
  pm(PUT, SSMAN[DELTA_ALPHA_MAX], 0.0001 , NULL);
  pm(PUT, SSMAN[DELTA_MIN], 1e-5 , NULL);
}

void mans_clear(void)
{
  memory  m;
  int     manifold_test();

  m = (memory) pm(GET, "Memory.Fixed", NULL);
  memory_clear_selected_flows(m, manifold_test);
  pm(EXEC, "Memory.Count", NULL);
}





