Ejemplo n.º 1
0
static void boundary_node2 (GtsGNode * n, GtsGraphBisection * bg)
{
  GSList * i = GTS_SLIST_CONTAINER (n)->items;

  while (i) {
    GtsGNode * n1 = GTS_GNODE_NEIGHBOR (n, i->data);
    if (gts_containee_is_contained (GTS_CONTAINEE (n1), 
				    GTS_CONTAINER (bg->g1))) {
      g_hash_table_insert (bg->bg2, n, n1);
      return;
    }
    i = i->next;
  }
}
Ejemplo n.º 2
0
/* Same as in source.c used here to obtain viscosity (make it more general?) */
static GfsSourceDiffusion * source_diffusion_viscosity (GfsVariable * v)
{
  if (v->sources) {
    GSList * i = GTS_SLIST_CONTAINER (v->sources)->items;

    while (i) {
      GtsObject * o = i->data;

      if (GFS_IS_SOURCE_DIFFUSION (o))
        return GFS_SOURCE_DIFFUSION (o);
      i = i->next;
    }
  }
  return NULL;
}
Ejemplo n.º 3
0
static void gfs_source_darcy_read (GtsObject ** o, GtsFile * fp)
{
    (* GTS_OBJECT_CLASS (gfs_source_darcy_class ())->parent_class->read) (o, fp);
  if (fp->type == GTS_ERROR)
    return;
  
  printf("\ntesting1\n");
  /*Check if source darcy has already been added or not*/
  FttComponent c;
  for (c = 0; c < FTT_DIMENSION; c++) {
    GfsVariable * v = GFS_SOURCE_VELOCITY (*o)->v[c];

    if (v->sources) {
      GSList * i = GTS_SLIST_CONTAINER (v->sources)->items;
      
      while (i) {
	if (i->data != *o && GFS_IS_SOURCE_DARCY (i->data)) {
	  gts_file_error (fp, "variable '%s' cannot have multiple Darcy source terms", v->name);
	  return;
	}
	i = i->next;
      }
    }
  }

  printf("\ntesting2\n");
  GfsDomain * domain = GFS_DOMAIN (gfs_object_simulation (*o));
  GfsSourceDarcy * s = GFS_SOURCE_DARCY (*o);
  printf("\ntesting3\n");
  s->darcycoeff = gfs_function_new (gfs_function_class (), 0.);
  gfs_function_read (s->darcycoeff, gfs_object_simulation (s), fp);
  printf("\ntesting4\n");
  
  if (fp->type != '\n') {
    s->forchhicoeff = gfs_function_new (gfs_function_class (), 0.);
    gfs_function_read (s->forchhicoeff, gfs_object_simulation (s), fp);
  }

  if (s->beta < 1.)
    for (c = 0; c <  FTT_DIMENSION; c++)
      s->u[c] = gfs_temporary_variable (domain);
  else {
    GFS_SOURCE_GENERIC (s)->centered_value = NULL;
    GFS_SOURCE_GENERIC (s)->mac_value = NULL;
  }
  printf("\ntesting5\n");
}
Ejemplo n.º 4
0
GfsSourceDarcy * gfs_has_source_darcy (GfsDomain * domain)
{
  GfsVariable * v;

  g_return_val_if_fail (domain != NULL, NULL);

  v = gfs_variable_from_name (domain->variables, "U");
  g_return_val_if_fail (v != NULL, NULL);

  if (v->sources) {
    GSList * i = GTS_SLIST_CONTAINER (v->sources)->items;

    while (i) {
      if (GFS_IS_SOURCE_DARCY (i->data))
	return i->data;
      i = i->next;
    }
  }
  return NULL;
}
Ejemplo n.º 5
0
static void update_neighbors (GtsGNode * n, GtsGraphBisection * bg,
			      GtsEHeap * h1, GtsEHeap * h2)
{
  GSList * i;

  i = GTS_SLIST_CONTAINER (n)->items;
  while (i) {
    GtsGNode * n1 = GTS_GNODE_NEIGHBOR (n, i->data);
    if (gts_containee_is_contained (GTS_CONTAINEE (n1), 
				    GTS_CONTAINER (bg->g))) {
      GtsEHeap * h;
      GtsGraph * g1, * g2;
      GHashTable * bg1;

      if (gts_containee_is_contained (GTS_CONTAINEE (n1),
				      GTS_CONTAINER (bg->g1))) {
	h = h1;
	g1 = bg->g1;
	g2 = bg->g2;
	bg1 = bg->bg1;
      }
      else {
	h = h2;
	g1 = bg->g2;
	g2 = bg->g1;
	bg1 = bg->bg2;
      }
      g_hash_table_remove (bg1, n1);
      if (h && GTS_OBJECT (n1)->reserved && GTS_OBJECT (n1)->reserved != n1) {
	gts_eheap_remove (h, GTS_OBJECT (n1)->reserved);
	GTS_OBJECT (n1)->reserved = NULL;
      }
      if (gts_gnode_degree (n1, g2)) {
	g_hash_table_insert (bg1, n1, n1);
	if (h && GTS_OBJECT (n1)->reserved != n1)
	  GTS_OBJECT (n1)->reserved = gts_eheap_insert (h, n1);
      }
    }
    i = i->next;
  }  
}
Ejemplo n.º 6
0
static gdouble node_cost (GtsGNode * n, gpointer * data)
{
  GtsGraph * g = data[0];
  GtsGraph * g1 = data[1];
  GSList * i = GTS_SLIST_CONTAINER (n)->items;
  gdouble cost = 0.;

  while (i) {
    GtsGEdge * e = i->data;
    GtsGNode * n1 = GTS_GNODE_NEIGHBOR (n, e);

    if (gts_containee_is_contained (GTS_CONTAINEE (n1), GTS_CONTAINER (g))) {
      if (gts_containee_is_contained (GTS_CONTAINEE (n1), GTS_CONTAINER (g1)))
	cost -= gts_gedge_weight (e);
      else 
	cost += gts_gedge_weight (e);
    }
    i = i->next;
  }

  return cost;
}
Ejemplo n.º 7
0
/**
 * gts_graph_bisection_kl_refine:
 * @bg: a #GtsGraphBisection.
 * @mmax: the maximum number of unsuccessful successive moves.
 *
 * An implementation of the simplified Kernighan-Lin algorithm for
 * graph bisection refinement as described in Karypis and Kumar
 * (1997).
 *
 * The algorithm stops if @mmax consecutive modes do not lead to a
 * decrease in the number of edges cut. This last @mmax moves are
 * undone.
 *
 * Returns: the decrease in the weight of the edges cut by the bisection.  
 */
gdouble gts_graph_bisection_kl_refine (GtsGraphBisection * bg,
				       guint mmax)
{
  GtsEHeap * h1, * h2;
  GtsGNode * n;
  guint nm = 0, i;
  GtsGNode ** moves;
  gdouble bestcost = 0., totalcost = 0., best_balance;

  g_return_val_if_fail (bg != NULL, 0.);
  g_return_val_if_fail (mmax > 0, 0.);

  h1 = gts_eheap_new ((GtsKeyFunc) node_move_cost1, bg);
  gts_eheap_freeze (h1);
  gts_container_foreach (GTS_CONTAINER (bg->g1), (GtsFunc) build_heap, h1);
  gts_eheap_thaw (h1);

  h2 = gts_eheap_new ((GtsKeyFunc) node_move_cost2, bg);
  gts_eheap_freeze (h2);
  gts_container_foreach (GTS_CONTAINER (bg->g2), (GtsFunc) build_heap, h2);
  gts_eheap_thaw (h2);

  moves = g_malloc (sizeof (GtsGNode *)*mmax);
  best_balance = fabs (gts_graph_weight (bg->g1) - gts_graph_weight (bg->g2));

  do {
    GtsGraph * g1, * g2;
    gdouble cost;

    if (gts_graph_weight (bg->g1) > gts_graph_weight (bg->g2)) {
      n = gts_eheap_remove_top (h1, &cost);
      g1 = bg->g1;
      g2 = bg->g2;
    }
    else {
      n = gts_eheap_remove_top (h2, &cost);
      g1 = bg->g2;
      g2 = bg->g1;
    }
    if (n) {
      GSList * i;

      GTS_OBJECT (n)->reserved = NULL;
      gts_container_add (GTS_CONTAINER (g2), GTS_CONTAINEE (n));
      gts_container_remove (GTS_CONTAINER (g1), GTS_CONTAINEE (n));

      totalcost += cost;
      if (totalcost < bestcost) {
	bestcost = totalcost;
	nm = 0;
      }
      else if (totalcost == bestcost) {
	gdouble balance = fabs (gts_graph_weight (g1) - gts_graph_weight (g2));

	if (balance < best_balance) {
	  best_balance = balance;
	  nm = 0;
	}
      }	       
      else
	moves[nm++] = n;

      i = GTS_SLIST_CONTAINER (n)->items;
      while (i) {
	GtsGNode * n1 = GTS_GNODE_NEIGHBOR (n, i->data);
	if (GTS_OBJECT (n1)->reserved && 
	    gts_containee_is_contained (GTS_CONTAINEE (n1), 
					GTS_CONTAINER (bg->g))) {
	  GtsEHeap * h = 
	    gts_containee_is_contained (GTS_CONTAINEE (n1), 
					GTS_CONTAINER (bg->g1)) ? h1 : h2;
	  gts_eheap_remove (h, GTS_OBJECT (n1)->reserved);
	  GTS_OBJECT (n1)->reserved = gts_eheap_insert (h, n1);
	}
	i = i->next;
      }
    }
  } while (n && nm < mmax);

  gts_eheap_foreach (h1, (GFunc) gts_object_reset_reserved, NULL);
  gts_eheap_foreach (h2, (GFunc) gts_object_reset_reserved, NULL);
  gts_eheap_destroy (h1);
  gts_eheap_destroy (h2);

  /* undo last nm moves */
  for (i = 0; i < nm; i++) {
    GtsGNode * n = moves[i];
    GtsGraph * g1 = 
      gts_containee_is_contained (GTS_CONTAINEE (n),
				  GTS_CONTAINER (bg->g1)) ? bg->g1 : bg->g2;
    GtsGraph * g2 = g1 == bg->g1 ? bg->g2 : bg->g1;
    
    gts_container_add (GTS_CONTAINER (g2), GTS_CONTAINEE (n));
    gts_container_remove (GTS_CONTAINER (g1), GTS_CONTAINEE (n));
  }
  g_free (moves);

  return bestcost;
}