示例#1
0
文件: ilsol0.cpp 项目: keesvp/OpenIL
static void ulsolop( int solop, genpar *pars, int blend, evalcontext* ecntxt )
{
  solidtyp sol, sol0, sol1;

  sol = newsol( ecntxt );
  sol0 = *(solidtyp*)pars[0].parp;
  sol1 = *(solidtyp*)pars[1].parp;
/*
  if ( blend && !( check_valid_blend( sol0 ) && check_valid_blend( sol1 ) ) )
    switch ( solop )
    {
      case blendsub:
	solop = solsub;
	break;
      case blendmul:
	solop = solsec;
	break;
      default:
	solop = solgrp;
	break;
    }
*/
  sol->prop = solop;
  sol->tpart.node.lnode = sol0;
  sol->tpart.node.rnode = sol1;
  ecntxt->stacks->pushand( ULsol, &sol );
}
示例#2
0
SolutionInstance TubeLF::Integrate(d dt) {
  // Integrate using Lax-Friedrich method
  d t=sol.getTime();
  d newt = t + dt;

  // Define new solutioninstance
  SolutionInstance newsol(gp);
  newsol.setTime(newt);

  const vd& oldrho=sol.rho();
  const vd& oldm=sol.m();
  const vd& oldrhoE=sol.rhoE();

  vd& rho=newsol.rho_ref();
  vd& m=newsol.m_ref();
  vd& rhoE=newsol.rhoE_ref();

  // Fluxes from previous solution
  vd Cflux=sol.Cflux();
  vd Mflux=sol.Mflux();
  vd Eflux=sol.Eflux();

  {  // Left boundary
    d la = dt/dx;
    rho(0) = oldrho(0);
    rho(0)+=-la*(Cflux(1)-Cflux(0));
    d oldu0=oldm(0)/oldrho(0);
    // std::cout << "oldu:"<< oldu0 << std::endl;
    d momfluxl = pow(oldm(0), 2)/oldrho(0) + pleft(t);
    m(0) = oldm(0);
    m(0)+=-la*(Mflux(1)-momfluxl);
    rhoE(0) = oldrhoE(0);
    rhoE(0)+=-la*(Eflux(1)-Eflux(0));
  } //  End left boundary

  {				// Inner nodes
    d lambda = dt/(2*dx);
    rho.subvec(1,gp-2)=0.5*(oldrho.head(gp-2) + oldrho.tail(gp-2));
    rho.subvec(1,gp-2)+=-lambda*(Cflux.tail(gp-2) -Cflux.head(gp-2));
  
    m.subvec(1,gp-2)=0.5*(oldm.head(gp-2) + oldm.tail(gp-2));
    m.subvec(1,gp-2)+=-lambda*(Mflux.tail(gp-2) -Mflux.head(gp-2));

    rhoE.subvec(1,gp-2)=0.5*(oldrhoE.head(gp-2) + oldrhoE.tail(gp-2));
    rhoE.subvec(1,gp-2)+=-lambda*(Eflux.tail(gp-2) -Eflux.head(gp-2));
  } // End inner nodes

  {				// Right boundary
    int i = gp - 1;
    d la = dt/dx;
    rho(i) = oldrho(i);
    rho(i)+=-la*(0-Cflux(i-1));
    m(i) = 0;
    rhoE(i) = oldrhoE(i);
    rhoE(i)+=-la*(0-Eflux(i-1));
  } // End right boundary

  return newsol;
}
示例#3
0
文件: ilsol0.cpp 项目: keesvp/OpenIL
static solidtyp solcp( solidtyp sol, int deep, int pass, evalcontext* ecntxt )
{
  int i;
  solidtyp nsol;
  void *pp;

  if ( !sol )
    return NULL;
  nsol = newsol( ecntxt );
  if ( ecntxt->cycles->error )
    return NULL;
  *nsol = *sol;
  nsol->refcnt = 1;
  if ( sol->ttyp == ULmap )
    if ( deep )
    {
//      nsol->trf.trfi = *(maptyp*)cpyitem( ULmap, &sol->trf.trfi, 1, pass );
      cpyitem( ULmap, &pp, &sol->trf.trfi, 1, pass, ecntxt );
      nsol->trf.trfi = *(maptyp*)pp;
    }
    else
      refitem( ULmap, &sol->trf.trfi );
  if ( deep )
    for ( i = 0; i < nrnatr; i++ )
    {
//      nsol->natrb[i] = *(listtyp*)cpyitem( ULlist, &sol->natrb[i], 1, 0 );
      cpyitem( ULlist, &pp, &sol->natrb[i], 1, pass, ecntxt );
      nsol->natrb[i] = *(listtyp*)pp;
    }
  else
    for ( i = 0; i < nrnatr; i++ )
      refitem( ULlist, &sol->natrb[i] );
  if ( sol->isleaf )
  {
  /*
    if ( sol->tpart.leaf.isop )
      nsol->tpart.leaf.isop = copy_iso_data( sol->tpart.leaf.isop );
  */
    if ( deep )
      for ( i = 0; i < nrlatr; i++ )
      {
//        nsol->tpart.leaf.latrb[i] = *(listtyp*)cpyitem( ULlist, &sol->tpart.leaf.latrb[i], 1, 0 );
        cpyitem( ULlist, &pp, &sol->tpart.leaf.latrb[i], 1, pass, ecntxt );
        nsol->tpart.leaf.latrb[i] = *(listtyp*)pp;
      }
    else
      for ( i = 0; i < nrlatr; i++ )
	refitem( ULlist, &sol->tpart.leaf.latrb[i] );
  }
  else
  {
    nsol->tpart.node.lnode = solcp( sol->tpart.node.lnode, deep, pass, ecntxt );
    nsol->tpart.node.rnode = solcp( sol->tpart.node.rnode, deep, pass, ecntxt );
  }
  return nsol;
}
示例#4
0
文件: ilsol0.cpp 项目: keesvp/OpenIL
static void ullvl( int parcnt, genpar *pars, void *d0, void *d1, mapevalenviron* mapenv, evalcontext* ecntxt )
{
  solidtyp sol;

  sol = newsol( ecntxt );
  sol->prop = solgrp;
  sol->tpart.node.lnode = *(solidtyp*)pars[0].parp;
  sol->tpart.node.rnode = 0;
  ecntxt->stacks->pushand( ULsol, &sol );
}
示例#5
0
文件: ilsol0.cpp 项目: keesvp/OpenIL
static solidtyp solprim( int prim, evalcontext* ecntxt )
{
  solidtyp sol;

  sol = newsol( ecntxt );
  if ( ecntxt->cycles->error )
    return NULL;
  sol->isleaf = 1;
  sol->prop = prim;
  return sol;
}
/** calls user callback after a new solution was found, that is better than the current incumbent;
 *  the callback decides, whether this solution should be accepted as new incumbent, and whether the solution process
 *  should be stopped
 */
static
void newSolution(
   TCLIQUE_SELECTADJNODES((*selectadjnodes)), /**< user function to select adjacent edges */
   TCLIQUE_GRAPH*   tcliquegraph,       /**< pointer to graph data structure */
   TCLIQUE_NEWSOL   ((*newsol)),        /**< user function to call on every new solution */
   TCLIQUE_DATA*    tcliquedata,        /**< user data to pass to user callback function */
   CLIQUEHASH*      cliquehash,         /**< clique hash table */
   int*             buffer,             /**< buffer of size nnodes */
   int*             Vzero,              /**< zero weighted nodes */
   int              nVzero,             /**< number of zero weighted nodes */
   int              maxnzeroextensions, /**< maximal number of zero-valued variables extending the clique */
   int*             curcliquenodes,     /**< nodes of the new clique */
   int              ncurcliquenodes,    /**< number of nodes in the new clique */
   TCLIQUE_WEIGHT   curcliqueweight,    /**< weight of the new clique */
   int*             maxcliquenodes,     /**< pointer to store nodes of the maximum weight clique */
   int*             nmaxcliquenodes,    /**< pointer to store number of nodes in the maximum weight clique */
   TCLIQUE_WEIGHT*  maxcliqueweight,    /**< pointer to store weight of the maximum weight clique */
   TCLIQUE_Bool*    stopsolving         /**< pointer to store whether the solving should be stopped */
   )
{
   CLIQUE* clique;
   int insertpos;
   TCLIQUE_Bool acceptsol;

   assert(curcliquenodes != NULL);
   assert(maxcliquenodes != NULL);
   assert(nmaxcliquenodes != NULL);
   assert(maxcliqueweight != NULL);
   assert(curcliqueweight > *maxcliqueweight);
   assert(stopsolving != NULL);
   assert(newsol == NULL || cliquehash != NULL);

   acceptsol = TRUE;
   *stopsolving = FALSE;
   clique = NULL;
   insertpos = 0;

   if( newsol != NULL )
   {
      /* check whether the clique is already stored in the table */
      if( cliquehash->ncliques > 0 )
      {
         createClique(&clique, curcliquenodes, ncurcliquenodes);
         acceptsol = !inCliquehash(cliquehash, clique, &insertpos);
      }
   }

   /* check, if this is a new clique */
   if( acceptsol )
   {
      /* extend the clique with the zero-weighted nodes */
      extendCliqueZeroWeight(selectadjnodes, tcliquegraph, buffer, Vzero, nVzero, maxnzeroextensions,
         curcliquenodes, &ncurcliquenodes);

      if( newsol != NULL )
      {
         /* call user callback method */
         newsol(tcliquedata, curcliquenodes, ncurcliquenodes, curcliqueweight, maxcliqueweight, &acceptsol, stopsolving);

         /* if clique was accepted, clear the clique hash table; otherwise, insert it into the clique hash table, such that
          * the same or a weaker clique is not presented to the user again
          */
         if( acceptsol )
            clearCliquehash(cliquehash);
         else
         {
            /* if the clique was not yet created, do it now */
            if( clique == NULL )
            {
               assert(insertpos == 0);
               assert(cliquehash->ncliques == 0);
               createClique(&clique, curcliquenodes, ncurcliquenodes);
            }

            /* insert clique into clique hash table */
            insertClique(cliquehash, clique, insertpos);
            clique = NULL; /* the clique now belongs to the table */
         }
      }
   }

   /* free the clique, if it was created and not put into the clique hash table */
   if( clique != NULL )
      freeClique(&clique);

   if( acceptsol )
   {
      /* copy the solution to the incumbent */
      BMScopyMemoryArray(maxcliquenodes, curcliquenodes, ncurcliquenodes);
      *nmaxcliquenodes = ncurcliquenodes;
      if( curcliqueweight > *maxcliqueweight )
         *maxcliqueweight = curcliqueweight;
   }

#ifdef TCLIQUE_DEBUG
   debugMessage(" -> clique %s (weight %d):", acceptsol ? "accepted" : "rejected", curcliqueweight);
   {
      int i;
      for( i = 0; i < ncurcliquenodes; ++i )
         debugPrintf(" %d", curcliquenodes[i]);
      debugPrintf("\n");
   }
#endif
}