Пример #1
0
static void check (const gchar *log,
                   AranSphericalSeriesd *ass, gdouble radius,
		   VsgVector3d *center,
		   gcomplex128 (*f) (VsgVector3d *x))
{
  guint i, j, k;
  gdouble t, p;
  gcomplex128 yres, yref, err;
  gdouble r, cost, sint, cosp, sinp;

  for (i=0; i<N ; i ++)
    {
      p = 2.*G_PI * i/(N-1.);
      cosp = cos (p);
      sinp = sin (p);

      for (j=0; j<N; j ++)
	{
	  t = G_PI * j/(N-1.);
	  cost = cos (t);
	  sint = sin (t);

	  for (k=0; k<N; k ++)
	    {
	      VsgVector3d vec;
	      r = radius + radius * k/(N-1.);

	      yres = aran_spherical_seriesd_evaluate_internal (ass, r,
							       cost, sint,
							       cosp, sinp);

	      vsg_vector3d_from_spherical_internal (&vec, r,
						    cost, sint,
						    cosp, sinp);
	      vsg_vector3d_add (&vec, center, &vec);

	      yref = f (&vec);

	      err = yref-yres;

	      if (yref != 0.) err /= yref;

	      if (cabs (err) > epsilon && cabs(yref) > epsilon)
		{
		  g_printerr ("Error %s (%f,%f,%f) : " \
                              "(%e+%ej), (%e+%ej) -> %e\n",
                              log,
			      r, t, p,
			      creal (yref), cimag (yref),
			      creal (yres), cimag (yres),
			      cabs (err));
		}
	    }
	}
    }
}
Пример #2
0
static void check (const gchar *log,
                   AranSphericalSeriesd *ass, gdouble radius,
		   VsgVector3d *center,
		   void (*f) (VsgVector3d *x, VsgVector3d *grad))
{
  guint i, j, k;
  gdouble t, p;
  gdouble err;
  gdouble r, cost, sint, cosp, sinp;
  gcomplex128 dr, dt, dp;

  for (i=0; i<N ; i ++)
    {
      p = 2.*G_PI * i/(N-1.);
      cosp = cos (p);
      sinp = sin (p);

      for (j=0; j<N; j ++)
	{
	  t = G_PI * j/(N-1.);
	  cost = cos (t);
	  sint = sin (t);

	  for (k=0; k<N; k ++)
	    {
	      VsgVector3d vec;
	      VsgVector3d vref;
	      VsgVector3d vres;
	      VsgVector3d verr;

	      r = radius * k/(N-1.);

	      vsg_vector3d_from_spherical_internal (&vec, r,
						    cost, sint,
						    cosp, sinp);

/*               aran_spherical_seriesd_gradient_evaluate (ass, &vec, */
/*                                                               &vres); */

              aran_spherical_seriesd_gradient_evaluate_internal (ass,
                                                                 r,
                                                                 cost, sint,
                                                                 cosp, sinp,
                                                                 &dr, &dt, &dp);
              local_to_cartesian (r, cost, sint, cosp, sinp,
                                  creal (dr), creal (dt), creal (dp),
                                  &vres);

              
              vsg_vector3d_scalp (&vres, -1., &vres);

	      vsg_vector3d_add (&vec, center, &vec);

	      f (&vec, &vref);

	      vsg_vector3d_sub (&vref, &vres, &verr);

              err = vsg_vector3d_norm (&verr) / vsg_vector3d_norm (&vref);

	      if (fabs (err) > epsilon || !finite (err))
		{
		  g_printerr ("Error %s (%f,%f,%f) : " \
                              "(%f,%f,%f) != (%f,%f,%f) -> %e\n",
                              log,
			      r, t, p,
/* 			      vec.x, vec.y, vec.z, */
			      vref.x, vref.y, vref.z,
			      vres.x, vres.y, vres.z,
			      fabs (err));
		}
	    }
	}
    }
}