Beispiel #1
0
Datei: us.c Projekt: gonzus/us
static void mark_cell(US* us, const Cell* cell)
{
    if (!cell) {
        return;
    }
    if (arena_is_cell_used(us->arena, cell)) {
        LOG(DEBUG, ("=== MARKING cell already marked"));
        return;
    }
    LOG(DEBUG, ("=== MARKING cell"));
    arena_mark_cell_used(us->arena, cell);
    switch (cell->tag) {
        case CELL_CONS:
            LOG(DEBUG, ("=== MARKING cell cons"));
            mark_cell(us, cell->cons.car);
            mark_cell(us, cell->cons.cdr);
            break;
        case CELL_PROC:
            LOG(DEBUG, ("=== MARKING cell proc"));
            mark_cell(us, cell->pval.params);
            mark_cell(us, cell->pval.body);
            mark_env(us, cell->pval.env);
            break;
    }
}
Beispiel #2
0
Datei: us.c Projekt: gonzus/us
static void mark_env(US* us, Env* env)
{
    if (!env) {
        return;
    }
    if (arena_is_env_used(us->arena, env)) {
        LOG(DEBUG, ("=== MARKING env already marked"));
        return;
    }
    LOG(DEBUG, ("=== MARKING env"));
    arena_mark_env_used(us->arena, env);
    for (int j = 0; j < env->size; ++j) {
        for (Symbol* sym = env->table[j]; sym; sym = sym->next) {
            mark_cell(us, sym->value);
        }
    }
    mark_env(us, env->parent);
}
Beispiel #3
0
///////////////////////////////////////////////////////////////////////////////
///\brief Main program
///
/// Initialize the simualtion and read input data from SCI,run the simulations, 
/// and write the results
///
///
///\return void No return needed
///////////////////////////////////////////////////////////////////////////////
int main() { 
  para.geom = &geom;
  para.outp = &outp1;
  para.prob = &prob;
  para.mytime = &mytime;
  para.bc     = &bc;
  para.solv   = &solv;

  initial(&para);

  if(!read_max(&para, var)) {
    printf("no file"); exit(1);
  }

  if(!allocate_data( ))    exit ( 1 );

  clear_data(&para,  var,BINDEX);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
  if(!read_input(&para, var,BINDEX)) {
    printf("no file"); exit(1);
  }

  init_data(&para,  var,BINDEX);

  mark_cell(&para, var,BINDEX);

  if(para.solv->read_file==1) read_data(&para,var);
  
  FFD_solver(&para, var,BINDEX);
  write_SCI(&para,  var, "output");
  free_data(var);
  free_index(BINDEX);
  
  //getchar();  
  exit ( 0 );
} // End of main( )
void
bar_2 (int * interp, Pcc_cell *c)
{
  c->bla += 2;
  mark_cell(interp, c);
}
void
bar_1 (int * interp, Pcc_cell *c)
{
  c->bla += 1;
  mark_cell(interp, c);
}
static void
foo(int * interp, Pcc_cell *c)
{
  mark_cell(interp, c);
}
///////////////////////////////////////////////////////////////////////////////
/// Set default initial values for simulation variables 
///
///\param para Pointer to FFD parameters
///\param var Pointer to FFD simulation variables
///\param BINDEX Pointer to boundary index
///
///\return 0 if no error occurred
///////////////////////////////////////////////////////////////////////////////
int set_initial_data(PARA_DATA *para, REAL **var, int **BINDEX) {
  int i, j; 
  int size = (para->geom->imax+2)*(para->geom->jmax+2)*(para->geom->kmax+2);
  int flag = 0;
  
  para->mytime->t = 0.0;
  para->mytime->step_current = 0;
  para->outp->cal_mean = 0;

  /****************************************************************************
  | Set inital value for FFD variables
  ****************************************************************************/
  for(i=0; i<size; i++) {
    var[GX][i]      = 0.0;
    var[GY][i]      = 0.0;
    var[GZ][i]      = 0.0;
    var[VX][i]      = para->init->u;
    var[VY][i]      = para->init->v;
    var[VZ][i]      = para->init->w;
    var[VXM][i]     = 0.0;
    var[VYM][i]     = 0.0;
    var[VZM][i]     = 0.0;
    var[VXS][i]     = 0.0;
    var[VYS][i]     = 0.0;
    var[VZS][i]     = 0.0;
    var[TEMP][i]    = para->init->T;
    var[TEMPM][i]   = 0.0; 
    var[TEMPS][i]   = 0.0;  // Source of temperature
    var[IP][i]      = 0.0;
    var[AP][i]      = 0.0;
    var[AW][i]      = 0.0;
    var[AE][i]      = 0.0;
    var[AS][i]      = 0.0;
    var[AN][i]      = 0.0;
    var[AB][i]      = 0.0;
    var[AF][i]      = 0.0;
    var[B][i]       = 0.0;
    var[AP0][i]     = 0.0;
    var[TMP1][i]    = 0.0;
    var[TMP2][i]    = 0.0;
    var[TMP3][i]    = 0.0;
    var[PP][i]      = 0.0;
    var[FLAGP][i]   = -1.0;
    var[FLAGU][i]   = -1.0;
    var[FLAGV][i]   = -1.0;
    var[FLAGW][i]   = -1.0;
    var[VXBC][i]    = 0.0;
    var[VYBC][i]    = 0.0;
    var[VZBC][i]    = 0.0;
    var[TEMPBC][i]  = 0.0;;
    var[QFLUXBC][i] = 0.0;
    var[QFLUX][i]   = 0.0;
    var[Xi1][i]     = 0.0;
    var[Xi2][i]     = 0.0;
    var[Xi1S][i]    = 0.0;
    var[Xi2S][i]    = 0.0;
    var[Xi1BC][i]   = 0.0;
    var[Xi2BC][i]   = 0.0;
    var[C1][i]      = 0.0;
    var[C2][i]      = 0.0;
    var[C1S][i]     = 0.0;
    var[C2S][i]     = 0.0;
    var[C1BC][i]    = 0.0;
    var[C2BC][i]    = 0.0;
  }

  // Calculate the thermal diffusivity
  para->prob->alpha = para->prob->cond / (para->prob->rho*para->prob->Cp);

  /****************************************************************************
  | Read the configurations defined by SCI 
  ****************************************************************************/
  if(para->inpu->parameter_file_format == SCI) {
    flag = read_sci_input(para, var, BINDEX);
    if(flag != 0) {
      sprintf(msg, "set_inital_data(): Could not read file %s", 
              para->inpu->parameter_file_name);
      ffd_log(msg, FFD_ERROR);
      return flag; 
    }
    flag = read_sci_zeroone(para, var, BINDEX);
    if(flag != 0) {
      ffd_log("set_inital_data(): Could not read block information file", 
               FFD_ERROR);
      return flag; 
    }
    mark_cell(para, var);
  }

  /****************************************************************************
  | Allocate memory for sensor data if there is at least one sensor
  ****************************************************************************/
  if(para->sens->nb_sensor>0) {
    para->sens->senVal = (REAL *) malloc(para->sens->nb_sensor*sizeof(REAL));
    if(para->sens->senVal==NULL) {
      ffd_log("set_initial_data(): Could not allocate memory for "
        "para->sens->senVal", FFD_ERROR);
      return -1;
    }
    para->sens->senValMean = (REAL *) malloc(para->sens->nb_sensor*sizeof(REAL));
    if(para->sens->senValMean==NULL) {
      ffd_log("set_initial_data(): Could not allocate memory for "
        "para->sens->senValMean", FFD_ERROR);
      return 1;
    }
  }

  /****************************************************************************
  | Allocate memory for Species
  ****************************************************************************/
  if(para->bc->nb_port>0&&para->bc->nb_Xi>0) {
    para->bc->XiPort = (REAL **) malloc(sizeof(REAL*)*para->bc->nb_port);
    para->bc->XiPortAve = (REAL **) malloc(sizeof(REAL*)*para->bc->nb_port);
    para->bc->XiPortMean = (REAL **) malloc(sizeof(REAL*)*para->bc->nb_port);
    if(para->bc->XiPort==NULL || 
       para->bc->XiPortAve==NULL ||
       para->bc->XiPortMean==NULL) {
      ffd_log("set_initial_data(): Could not allocate memory for XiPort.",
              FFD_ERROR);
      return 1;
    }

    for(i=0; i<para->bc->nb_port; i++) {
      para->bc->XiPort[i] = (REAL *) malloc(sizeof(REAL)*para->bc->nb_Xi);
      para->bc->XiPortAve[i] = (REAL *) malloc(sizeof(REAL)*para->bc->nb_Xi);
      para->bc->XiPortMean[i] = (REAL *) malloc(sizeof(REAL)*para->bc->nb_Xi);
      if(para->bc->XiPort[i]==NULL || 
         para->bc->XiPortAve[i]==NULL || 
         para->bc->XiPortMean[i]==NULL) {
        sprintf(msg, "set_initial_data(): Could not allocate memory for "
                "Xi at Port[%d].", i);
        ffd_log(msg, FFD_ERROR);
        return 1;
      }

      for(j=0; j<para->bc->nb_Xi; j++) {
        para->bc->XiPort[i][j] = 0.0;
        para->bc->XiPortAve[i][j] = 0.0;
        para->bc->XiPortMean[i][j] = 0.0;
      }
    }
    if(para->outp->version==DEBUG) {
      ffd_log("Allocated memory for Xi", FFD_NORMAL);
    }
  }
  else  if(para->outp->version==DEBUG) {
      ffd_log("No Xi in the simulation", FFD_NORMAL);
  }

  /****************************************************************************
  | Allocate memory for Substances
  ****************************************************************************/
  if(para->bc->nb_port>0&&para->bc->nb_C>0) {
    para->bc->CPort = (REAL **) malloc(sizeof(REAL *)*para->bc->nb_port);
    para->bc->CPortAve = (REAL **) malloc(sizeof(REAL *)*para->bc->nb_port);
    para->bc->CPortMean = (REAL **) malloc(sizeof(REAL *)*para->bc->nb_port);
    if(para->bc->CPort==NULL || para->bc->CPortAve==NULL 
       || para->bc->CPortMean) {
      ffd_log("set_initial_data(): Could not allocate memory for CPort.",
              FFD_ERROR);
      return 1;
    }
    
    for(i=0; i<para->bc->nb_port; i++) {
      para->bc->CPort[i] = (REAL *) malloc(sizeof(REAL)*para->bc->nb_C);
      para->bc->CPortAve[i] = (REAL *) malloc(sizeof(REAL)*para->bc->nb_C);
      para->bc->CPortMean[i] = (REAL *) malloc(sizeof(REAL)*para->bc->nb_C);
      if(para->bc->CPort[i]==NULL || para->bc->CPortAve[i]==NULL 
         || para->bc->CPortMean[i]) {
        ffd_log("set_initial_data(): "
                "Could not allocate memory for C at Port[i].",
                FFD_ERROR);
        return 1;
      }

      for(j=0; j<para->bc->nb_C; j++) {
        para->bc->CPort[i][j] = 0.0;
        para->bc->CPortAve[i][j] = 0.0;
        para->bc->CPortMean[i][j] = 0.0;
      }
    }
    if(para->outp->version==DEBUG) {
      ffd_log("Allocated memory for C", FFD_NORMAL);
    }
  }
  else if(para->outp->version==DEBUG) {
      ffd_log("No C in the simulation", FFD_NORMAL);
  }

  /****************************************************************************
  | Pre-calculate data needed but not change in the simulation
  ****************************************************************************/
  para->geom->volFlu = fluid_volume(para, var);
  para->geom->pindex     = (int) para->geom->jmax/2;

  /****************************************************************************
  | Set all the averaged data to 0
  ****************************************************************************/
  flag = reset_time_averaged_data(para, var);
  if(flag != 0) {
    ffd_log("FFD_solver(): Could not reset averaged data.",
      FFD_ERROR);
    return flag;
  }

  /****************************************************************************
  | Conduct the data exchange at the inital state of cosimulation 
  ****************************************************************************/
  if(para->solv->cosimulation==1) {
    /*------------------------------------------------------------------------
    | Calculate the area of boundary
    ------------------------------------------------------------------------*/
    flag = bounary_area(para, var, BINDEX);
    if(flag != 0) {
      ffd_log("set_initial_data(): Could not get the boundary area.",
              FFD_ERROR);
      return flag;
    }
    /*------------------------------------------------------------------------
    | Read the cosimulation parameter data (Only need once)
    ------------------------------------------------------------------------*/
    flag = read_cosim_parameter(para, var, BINDEX);
    if(flag != 0) {
      ffd_log("set_initial_data(): Could not read cosimulation parameters.",
              FFD_ERROR);
      return 1;
    }
    /*------------------------------------------------------------------------
    | Read the cosimulation data
    ------------------------------------------------------------------------*/
    flag = read_cosim_data(para, var, BINDEX);
    if(flag != 0) {
      ffd_log("set_initial_data(): Could not read initial data for "
               "cosimulaiton.", FFD_ERROR);
      return flag;
    }
    
    /*------------------------------------------------------------------------
    | Perform the simulation for one step to update the FFD initial condition
    ------------------------------------------------------------------------*/
    flag = vel_step(para, var, BINDEX);
    if(flag != 0) {
      ffd_log("FFD_solver(): Could not solve velocity.", FFD_ERROR);
      return flag;
    }
    else if(para->outp->version==DEBUG)
      ffd_log("FFD_solver(): solved velocity step.", FFD_NORMAL);

    flag = temp_step(para, var, BINDEX);
    if(flag != 0) {
      ffd_log("FFD_solver(): Could not solve temperature.", FFD_ERROR);
      return flag;
    }
    else if(para->outp->version==DEBUG)
      ffd_log("FFD_solver(): solved temperature step.", FFD_NORMAL);

    flag = den_step(para, var, BINDEX);
    if(flag != 0) {
      ffd_log("FFD_solver(): Could not solve trace substance.", FFD_ERROR);
      return flag;
    }
    else if(para->outp->version==DEBUG)
      ffd_log("FFD_solver(): solved density step.", FFD_NORMAL);
    
    // Integrate the data on the boundary surface
    flag = surface_integrate(para, var, BINDEX);
    if(flag != 0) {
      ffd_log("FFD_solver(): "
        "Could not average the data on boundary.",
        FFD_ERROR);
      return flag;
    }
    else if (para->outp->version==DEBUG)
      ffd_log("FFD_solver(): completed surface integration", 
              FFD_NORMAL);

    flag = add_time_averaged_data(para, var);
    if(flag != 0) {
      ffd_log("FFD_solver(): "
        "Could not add the averaged data.",
        FFD_ERROR);
      return flag;
    }
    else if (para->outp->version==DEBUG)
      ffd_log("FFD_solver(): completed time average", 
              FFD_NORMAL);

    // Average the FFD simulation data
    flag = average_time(para, var);
    if(flag != 0) {
      ffd_log("FFD_solver(): Could not average the data over time.",
        FFD_ERROR);
      return flag;
    }

    /*------------------------------------------------------------------------
    | Write the cosimulation data
    ------------------------------------------------------------------------*/
    flag = write_cosim_data(para, var);
    if(flag != 0) {
      ffd_log("set_initial_data(): Could not write initial data for "
              "cosimulaiton.", FFD_ERROR);
      return flag;
    }
  }

  return flag;
} // set_initial_data()