Exemple #1
0
static void gfs_source_darcy_class_init (GfsSourceGenericClass * klass)
{
  /* define new methods and overload inherited methods here */

  GFS_EVENT_CLASS (klass)->event = gfs_source_darcy_event;
  printf("\ndarcy init\n");
  GTS_OBJECT_CLASS (klass)->read = gfs_source_darcy_read;
  printf("\ndarcy read\n");
  GTS_OBJECT_CLASS (klass)->write = gfs_source_darcy_write;
  printf("\ndarcy written\n");
  GTS_OBJECT_CLASS (klass)->destroy = gfs_source_darcy_destroy;
}
Exemple #2
0
static void gfs_init_wave_write (GtsObject * o, FILE * fp)
{
  (* GTS_OBJECT_CLASS (gfs_init_wave_class ())->parent_class->write) (o, fp);

  gfs_function_write (GFS_INIT_WAVE (o)->d, fp);
  gfs_function_write (GFS_INIT_WAVE (o)->hs, fp);
}
Exemple #3
0
static void wave_read (GtsObject ** o, GtsFile * fp)
{
  (* GTS_OBJECT_CLASS (gfs_wave_class ())->parent_class->read) (o, fp);
  if (fp->type == GTS_ERROR)
    return;

  GfsWave * wave = GFS_WAVE (*o);
  if (fp->type == '{') {
    GtsFileVariable var[] = {
      {GTS_UINT,   "nk",      TRUE, &wave->nk},
      {GTS_UINT,   "ntheta",  TRUE, &wave->ntheta},
      {GTS_DOUBLE, "alpha_s", TRUE, &wave->alpha_s},
      {GTS_NONE}
    };
    gts_file_assign_variables (fp, var);
    if (fp->type == GTS_ERROR)
      return;
  }

  GfsDomain * domain = GFS_DOMAIN (wave);
  guint ik, ith;
  wave->F = gfs_matrix_new (wave->nk, wave->ntheta, sizeof (GfsVariable *));
  for (ik = 0; ik < wave->nk; ik++)
    for (ith = 0; ith < wave->ntheta; ith++) {
      gchar * name = g_strdup_printf ("F%d_%d", ik, ith);
      gchar * description = g_strdup_printf ("Action density for f = %g Hz and theta = %g degrees",
					     frequency (ik), theta (ith, wave->ntheta)*180./M_PI);
      wave->F[ik][ith] = gfs_domain_get_or_add_variable (domain, name, description);
      g_assert (wave->F[ik][ith]);
      g_free (name);
      g_free (description);
    }
}
Exemple #4
0
static void refine_solid_destroy (GtsObject * object)
{
  gfs_domain_remove_derived_variable (GFS_DOMAIN (gfs_object_simulation (object)), 
				      "SolidCurvature");

  (* GTS_OBJECT_CLASS (gfs_refine_solid_class ())->parent_class->destroy) (object);
}
Exemple #5
0
/**
 * gts_object_class_check_cast:
 * @klass: a #GtsObjectClass.
 * @from: a #GtsObjectClass.
 *
 * Returns: @klass while emitting warnings if @klass is not derived from
 * @from.
 */
gpointer gts_object_class_check_cast (gpointer klass, 
				      gpointer from)
{
  if (!klass) {
    g_warning ("invalid cast from (NULL) pointer to `%s'",
	       GTS_OBJECT_CLASS (from)->info.name);
    return klass;
  }
  if (!gts_object_class_is_from_class (klass, from)) {
    g_warning ("invalid cast from `%s' to `%s'",
	       GTS_OBJECT_CLASS (klass)->info.name,
	       GTS_OBJECT_CLASS (from)->info.name);
    return klass;
  }
  return klass;
}
Exemple #6
0
static void gfs_map_projection_write (GtsObject * o, FILE * fp)
{
  (* GTS_OBJECT_CLASS (gfs_map_projection_class ())->parent_class->write) (o, fp);
  GfsMapProjection * map = GFS_MAP_PROJECTION (o);
  fprintf (fp, " { lon = %.8g lat = %.8g angle = %g }",
	   map->lon, map->lat, map->angle);
}
Exemple #7
0
static void edge_clone (GtsObject * clone, GtsObject * object)
{
    (* GTS_OBJECT_CLASS (gts_edge_class ())->parent_class->clone) (clone,
            object);
    GTS_SEGMENT (clone)->v1 = GTS_SEGMENT (clone)->v2 = NULL;
    GTS_EDGE (clone)->triangles = NULL;
}
Exemple #8
0
static void output_spectra_destroy ( GtsObject * o )
{
  if (GFS_OUTPUT_SPECTRA (o)->cgd)
    gts_object_destroy (GTS_OBJECT (GFS_OUTPUT_SPECTRA (o)->cgd));

  (* GTS_OBJECT_CLASS (gfs_output_spectra_class ())->parent_class->destroy) (o);
}
Exemple #9
0
GtsVertexClass*
pygts_parent_vertex_class(void)
{
  static GtsVertexClass *klass = NULL;
  GtsObjectClass *super = NULL;

  if (klass == NULL) {

    super = GTS_OBJECT_CLASS(gts_vertex_class());

    GtsObjectClassInfo pygts_parent_vertex_info = {
      "PygtsParentVertex",
      sizeof(PygtsParentVertex),
      sizeof(GtsVertexClass),
      (GtsObjectClassInitFunc)(super->info.class_init_func),
      (GtsObjectInitFunc)(super->info.object_init_func),
      (GtsArgSetFunc) NULL,
      (GtsArgGetFunc) NULL
    };
    klass = (GtsVertexClass*)gts_object_class_new(gts_object_class(),
				 &pygts_parent_vertex_info);
  }

  return klass;
}
Exemple #10
0
static void gfs_init_wave_destroy (GtsObject * object)
{
  gts_object_destroy (GTS_OBJECT (GFS_INIT_WAVE (object)->d));
  gts_object_destroy (GTS_OBJECT (GFS_INIT_WAVE (object)->hs));

  (* GTS_OBJECT_CLASS (gfs_init_wave_class ())->parent_class->destroy) (object);
}
Exemple #11
0
static void output_spectra_write (GtsObject * o, FILE * fp)
{
  (* GTS_OBJECT_CLASS (gfs_output_spectra_class ())->parent_class->write) (o, fp); 
  
  GfsOutputSpectra * v = GFS_OUTPUT_SPECTRA (o);
  fprintf (fp, " %s { x = %g y = %g z = %g Lx = %g Ly = %g Lz = %g } %d",
	   v->v->name, v->pos.x, v->pos.y, v->pos.z, v->L.x, v->L.y, v->L.z, v->level);
}
Exemple #12
0
GfsRefine * gfs_refine_new (GfsRefineClass * klass)
{
  GfsRefine * object;

  object = GFS_REFINE (gts_object_new (GTS_OBJECT_CLASS (klass)));

  return object;
}
Exemple #13
0
static void refine_surface_destroy (GtsObject * object)
{
  GfsRefineSurface * d = GFS_REFINE_SURFACE (object);

  gts_object_destroy (GTS_OBJECT (d->surface));

  (* GTS_OBJECT_CLASS (gfs_refine_surface_class ())->parent_class->destroy) (object);
}
Exemple #14
0
static void refine_surface_read (GtsObject ** o, GtsFile * fp)
{
  (* GTS_OBJECT_CLASS (gfs_refine_surface_class ())->parent_class->read) (o, fp);
  if (fp->type == GTS_ERROR)
    return;

  gfs_generic_surface_read (GFS_REFINE_SURFACE (*o)->surface, gfs_object_simulation (*o), fp);
}
Exemple #15
0
static void exception_destroy (GtsObject * object)
{
  GtsException * e = GTS_EXCEPTION (object);

  g_free (e->message); e->message = NULL;

  (* GTS_OBJECT_CLASS (gts_exception_class ())->parent_class->destroy) (object);
}
Exemple #16
0
/**
 * gts_bb_tree_triangle_distance:
 * @tree: a bounding box tree.
 * @t: a #GtsTriangle.
 * @distance: a #GtsBBoxDistFunc.
 * @delta: spatial scale of the sampling to be used.
 * @range: a #GtsRange to be filled with the results.
 * 
 * Given a triangle @t, points are sampled regularly on its surface
 * using @delta as increment. The distance from each of these points
 * to the closest object of @tree is computed using @distance and the
 * gts_bb_tree_point_distance() function. The fields of @range are
 * filled with the number of points sampled, the minimum, average and
 * maximum value and the standard deviation.  
 */
void gts_bb_tree_triangle_distance (GNode * tree,
				    GtsTriangle * t,
				    GtsBBoxDistFunc distance,
				    gdouble delta,
				    GtsRange * range)
{
  GtsPoint * p1, * p2, * p3, * p;
  GtsVector p1p2, p1p3;
  gdouble l1, t1, dt1;
  guint i, n1;

  g_return_if_fail (tree != NULL);
  g_return_if_fail (t != NULL);
  g_return_if_fail (distance != NULL);
  g_return_if_fail (delta > 0.);
  g_return_if_fail (range != NULL);

  gts_triangle_vertices (t, 
			 (GtsVertex **) &p1, 
			 (GtsVertex **) &p2, 
			 (GtsVertex **) &p3);

  gts_vector_init (p1p2, p1, p2);
  gts_vector_init (p1p3, p1, p3);
  gts_range_init (range);
  p = GTS_POINT (gts_object_new (GTS_OBJECT_CLASS (gts_point_class ())));

  l1 = sqrt (gts_vector_scalar (p1p2, p1p2));
  n1 = l1/delta + 1;
  dt1 = 1.0/(gdouble) n1;
  t1 = 0.0;
  for (i = 0; i <= n1; i++, t1 += dt1) {
    gdouble t2 = 1. - t1;
    gdouble x = t2*p1p3[0];
    gdouble y = t2*p1p3[1];
    gdouble z = t2*p1p3[2];
    gdouble l2 = sqrt (x*x + y*y + z*z);
    guint j, n2 = (guint) (l2/delta + 1);
    gdouble dt2 = t2/(gdouble) n2;

    x = t2*p1->x + t1*p2->x;
    y = t2*p1->y + t1*p2->y;
    z = t2*p1->z + t1*p2->z;
    
    t2 = 0.0;
    for (j = 0; j <= n2; j++, t2 += dt2) {
      p->x = x + t2*p1p3[0];
      p->y = y + t2*p1p3[1];
      p->z = z + t2*p1p3[2];

      gts_range_add_value (range,
		    gts_bb_tree_point_distance (tree, p, distance, NULL));
    }
  }

  gts_object_destroy (GTS_OBJECT (p));
  gts_range_update (range);
}
Exemple #17
0
static gboolean output_spectra_event (GfsEvent * event, 
				      GfsSimulation * sim) 
{
  if ((* GFS_EVENT_CLASS (GTS_OBJECT_CLASS (gfs_output_spectra_class ())->parent_class)->event)
      (event, sim)) {
    GfsDomain * domain = GFS_DOMAIN (sim);
    GfsOutputSpectra * v = GFS_OUTPUT_SPECTRA (event);
    fftw_plan p;
    Datawrite data;

    data.fp  = GFS_OUTPUT (event)->file->fp;
    data.L   = v->L;
    data.kmax = init_kmax(v->L);
    data.dir1 = v->dir[0];
    data.dir2 = v->dir[1];

    fill_cartesian_matrix( v->cgd, v->v, domain);
    switch (v->Ndim) {
      case 1: {
	data.n1 = ( v->cgd->n[v->dir[0]] / 2 ) + 1;
	data.out = fftw_malloc( sizeof(fftw_complex)*data.n1 );
	p = fftw_plan_dft_r2c_1d( v->cgd->n[v->dir[0]], v->cgd->v, data.out, FFTW_ESTIMATE);
	fftw_execute(p);
	write_spectra_1D ( &data );
	break;
      }
      case 2: {
	data.n1 = v->cgd->n[v->dir[0]];
	data.n2 = ( v->cgd->n[v->dir[1]] / 2 ) + 1;
	data.out = fftw_malloc( sizeof(fftw_complex)*v->cgd->n[v->dir[0]]*data.n2 );
	p = fftw_plan_dft_r2c_2d( v->cgd->n[v->dir[0]], v->cgd->n[v->dir[1]], 
				  v->cgd->v, data.out, FFTW_ESTIMATE);
	fftw_execute(p); 
	write_spectra_2D ( &data );
	break;
      }
    case 3: {
      data.n1 = v->cgd->n[0];
      data.n2 = v->cgd->n[1];
      data.n3 = ( v->cgd->n[2] / 2 ) + 1;
      data.out = fftw_malloc( sizeof(fftw_complex)*v->cgd->n[0]*v->cgd->n[1]*data.n3 );
      p = fftw_plan_dft_r2c_3d( v->cgd->n[0], v->cgd->n[1], v->cgd->n[2], 
				v->cgd->v, data.out, FFTW_ESTIMATE);
      fftw_execute(p); 
      write_spectra_3D ( &data );
      break;
    }
    default:
      g_assert_not_reached ();
    }
    
    fftw_destroy_plan(p);
    fftw_free ( data.out );

    return TRUE;
  }
  return FALSE;
}
Exemple #18
0
static void gfs_source_darcy_write (GtsObject * o, FILE * fp)
{
  GfsSourceDarcy * s = GFS_SOURCE_DARCY (o);

  (* GTS_OBJECT_CLASS (gfs_source_darcy_class ())->parent_class->write) (o, fp);
  gfs_function_write (s->darcycoeff, fp);
  if (s->forchhicoeff)
    gfs_function_write (s->forchhicoeff, fp);
}
Exemple #19
0
static gboolean gfs_init_stokes_wave_event (GfsEvent * event, GfsSimulation * sim)
{
  if ((* GFS_EVENT_CLASS (GTS_OBJECT_CLASS (gfs_init_stokes_wave_class ())->parent_class)->event) 
      (event, sim)) {
    GfsVariable ** velocity = gfs_domain_velocity (GFS_DOMAIN (sim));
    GfsVariable * t = gfs_variable_from_name (GFS_DOMAIN (sim)->variables, "T");
    g_assert (velocity);
    g_assert (t);
    gfs_domain_cell_traverse (GFS_DOMAIN (sim), FTT_PRE_ORDER, FTT_TRAVERSE_LEAFS, -1,
			      (FttCellTraverseFunc) init_velocity, velocity);
    GfsSurface * surface = GFS_SURFACE (gts_object_new (GTS_OBJECT_CLASS (gfs_surface_class ())));
    surface->f = gfs_function_spatial_new (gfs_function_spatial_class (), stokes_height);
    gfs_object_simulation_set (surface->f, sim);
    gfs_domain_init_fraction (GFS_DOMAIN (sim), GFS_GENERIC_SURFACE (surface), t);
    gts_object_destroy (GTS_OBJECT (surface));
    return TRUE;
  }
  return FALSE;
}
Exemple #20
0
static void refine_distance_destroy (GtsObject * object)
{
  GfsRefineDistance * d = GFS_REFINE_DISTANCE (object);

  if (d->stree)
    gts_bb_tree_destroy (d->stree, TRUE);
  gfs_domain_remove_derived_variable (GFS_DOMAIN (gfs_object_simulation (object)), "Distance");

  (* GTS_OBJECT_CLASS (gfs_refine_distance_class ())->parent_class->destroy) (object);
}
Exemple #21
0
static void list_face_destroy (GtsObject * object)
{
  ListFace * f = LIST_FACE (object);

  if (f->heap) {
    gts_eheap_remove (f->heap, f->pair);
    f->heap = NULL;
  }

  (* GTS_OBJECT_CLASS (list_face_class ())->parent_class->destroy) 
    (object);
}
Exemple #22
0
/**
 * gts_triangle_new:
 * @klass: a #GtsTriangleClass.
 * @e1: a #GtsEdge.
 * @e2: another #GtsEdge touching @e1.
 * @e3: another #GtsEdge touching both @e1 and @e2.
 *
 * Returns: a new #GtsTriangle having @e1, @e2 and @e3 as edges.
 */
GtsTriangle * gts_triangle_new (GtsTriangleClass * klass,
                                GtsEdge * e1,
                                GtsEdge * e2,
                                GtsEdge * e3)
{
    GtsTriangle * t;

    t = GTS_TRIANGLE (gts_object_new (GTS_OBJECT_CLASS (klass)));
    gts_triangle_set (t, e1, e2, e3);

    return t;
}
Exemple #23
0
/**
 * gts_hsplit_new:
 * @klass: a #GtsHSplitClass.
 * @vs: a #GtsSplit.
 *
 * Returns: a new #GtsHSplit, hierarchical extension of @vs.
 */
GtsHSplit * gts_hsplit_new (GtsHSplitClass * klass, GtsSplit * vs)
{
  GtsHSplit * hs;

  g_return_val_if_fail (vs != NULL, NULL);

  hs = GTS_HSPLIT (gts_object_new (GTS_OBJECT_CLASS (klass)));
  memcpy (hs, vs, sizeof (GtsSplit));
  GTS_OBJECT (hs)->reserved = NULL;

  return hs;
}
Exemple #24
0
/**
 * gts_object_check_cast:
 * @object: a #GtsObject.
 * @klass: a #GtsObjectClass.
 *
 * Returns: @object while emitting warnings if @object is not of class @klass.
 */
gpointer gts_object_check_cast (gpointer object, 
				gpointer klass)
{
  if (!object) {
    g_warning ("invalid cast from (NULL) pointer to `%s'",
	       GTS_OBJECT_CLASS (klass)->info.name);
    return object;
  }
  if (!((GtsObject *) object)->klass) {
    g_warning ("invalid unclassed pointer in cast to `%s'",
	       GTS_OBJECT_CLASS (klass)->info.name);
    return object;
  }
  if (!gts_object_is_from_class (object, klass)) {
    g_warning ("invalid cast from `%s' to `%s'",
	       ((GtsObject *) object)->klass->info.name,
	       GTS_OBJECT_CLASS (klass)->info.name);
    return object;
  }
  return object;
}
Exemple #25
0
static void wave_write (GtsObject * o, FILE * fp)
{
  (* GTS_OBJECT_CLASS (gfs_wave_class ())->parent_class->write) (o, fp);

  GfsWave * wave = GFS_WAVE (o);
  fprintf (fp, " {\n"
	   "  nk = %d\n"
	   "  ntheta = %d\n"
	   "  alpha_s = %g\n"
	   "}",
	   wave->nk, wave->ntheta, wave->alpha_s);
}
Exemple #26
0
/**
 * gts_bbox_new:
 * @klass: a #GtsBBoxClass.
 * @bounded: the object to be bounded.
 * @x1: x-coordinate of the lower left corner.
 * @y1: y-coordinate of the lower left corner.
 * @z1: z-coordinate of the lower left corner.
 * @x2: x-coordinate of the upper right corner.
 * @y2: y-coordinate of the upper right corner.
 * @z2: z-coordinate of the upper right corner.
 *
 * Returns: a new #GtsBBox.
 */
GtsBBox * gts_bbox_new (GtsBBoxClass * klass,
			gpointer bounded,
			gdouble x1, gdouble y1, gdouble z1,
			gdouble x2, gdouble y2, gdouble z2)
{
  GtsBBox * bbox;

  g_return_val_if_fail (klass != NULL, NULL);

  bbox = GTS_BBOX (gts_object_new (GTS_OBJECT_CLASS (klass)));
  gts_bbox_set (bbox, bounded, x1, y1, z1, x2, y2, z2);
  return bbox;
}
Exemple #27
0
static void refine_solid_read (GtsObject ** o, GtsFile * fp)
{
  GfsRefineSolid * refine = GFS_REFINE_SOLID (*o);
  GfsDerivedVariableInfo v = { "SolidCurvature", "curvature of the solid boundary",
			       solid_curvature };
  refine->v = gfs_domain_add_derived_variable (GFS_DOMAIN (gfs_object_simulation (*o)), v);
  if (!refine->v) {
    gts_file_error (fp, "derived variable `SolidCurvature' already defined");
    return;
  }

  (* GTS_OBJECT_CLASS (gfs_refine_solid_class ())->parent_class->read) (o, fp);
}
Exemple #28
0
static void gfs_porous_write (GtsObject * o, FILE * fp)
{
  /* call write method of parent */
    (* GTS_OBJECT_CLASS (gfs_porous_class ())->parent_class->write)(o, fp);
  /* do object specific write here */
  GfsPorous * por = GFS_POROUS (o);
  
  fputs (" {\n"
	 "  porosity =", fp);
  gfs_function_write (por->porosity, fp);
  fputs ("\n  K =", fp);
  gfs_function_write (por->K, fp);
  fputs("}\n ", fp);
}
Exemple #29
0
static void edge_destroy (GtsObject * object)
{
    GtsEdge * edge = GTS_EDGE (object);
    GSList * i;

    i = edge->triangles;
    while (i) {
        GSList * next = i->next;
        gts_object_destroy (i->data);
        i = next;
    }
    g_assert (edge->triangles == NULL);

    (* GTS_OBJECT_CLASS (gts_edge_class ())->parent_class->destroy) (object);
}
Exemple #30
0
static void gfs_skew_symmetric_read (GtsObject ** o, GtsFile * fp)
{
  (* GTS_OBJECT_CLASS (gfs_skew_symmetric_class ())->parent_class->read) (o, fp);
  if (fp->type == GTS_ERROR)
    return;

  if (fp->type != '{') 
    return;

  GtsFileVariable var[] = {
    {GTS_DOUBLE, "beta", TRUE, &GFS_SKEW_SYMMETRIC (*o)->beta},
    {GTS_NONE}
  };
  gts_file_assign_variables (fp, var);
}