示例#1
0
文件: main.c 项目: amarthwen/trunk
int main(void)
{
    PWM_init();
    
	CF_init(&alpha, &beta);
	
	PID_init(&pid_x, &pid_y);
	
	Flags_init();
    
	Timer1_init();
	
	Twi_init();
	
	Usart_init();

    deviceInit_adc();

    deviceInit_rc();
	
    if(!deviceInit() || !Flags_getBit(flags_deviceAdcInitialised) || !Flags_getBit(flags_deviceRcInitialised))
	{
		_exit();
	}
	
	// todo: workaround for slave initialization
	deviceInitialize(deviceID_slave, _true);

    // todo: workaround for gps initialization
    deviceInitialize(deviceID_gps, _true);
	
	//enable interrupts
	_enableInterrupts();

    while(1);
}	
示例#2
0
/* get confinement from SCM
 * in SCM, confinement is given by one of these:
 * for spherical confinement,
 *  (define confinement '(
 *    10.0 ;; LJ parameter epsilon in kT (so this is dimensionless value)
 *    1.0  ;; LJ parameter r0 in "length" (so this is dimensionless value)
 *    "sphere"
 *    10.0 ;; radius of the cavity at (0, 0, 0)
 *  ))
 * for spherical confinement with a hole,
 *  (define confinement '(
 *    10.0 ;; LJ parameter epsilon in kT (so this is dimensionless value)
 *    1.0  ;; LJ parameter r0 in "length" (so this is dimensionless value)
 *    "sphere+hole"
 *    10.0 ;; radius of the cavity at (0, 0, 0)
 *    1.0  ;; radius of the hole at (0, 0, 1) direction
 *  ))
 * for cylindrical confinement,
 *  (define confinement '(
 *    10.0 ;; LJ parameter epsilon in kT (so this is dimensionless value)
 *    1.0  ;; LJ parameter r0 in "length" (so this is dimensionless value)
 *    "cylinder"    ;; the cylinder center goes through (0, 0, 0) and (x, y, z).
 *    10.0          ;; radius of the cylinder
 *    1.0  0.0  0.0 ;; direction vector (x, y, z) of the cylinder
 *  ))
 * for dumbbell confinement,
 *  (define confinement '(
 *    10.0 ;; LJ parameter epsilon in kT (so this is dimensionless value)
 *    1.0  ;; LJ parameter r0 in "length" (so this is dimensionless value)
 *    "dumbbell" ;; the origin is at the center of the cylinder
 *    10.0       ;; left cavity radius centered at (center1, 0, 0)
 *    10.0       ;; right cavity radius centered at (center2, 0, 0)
 *    2.0        ;; length of the cylinder
 *    1.0        ;; cylinder radius
 *  ))
 * for 2D hexagonal confinement with cylinder pipe,
 *  (define confinement '(
 *    10.0 ;; LJ parameter epsilon in kT (so this is dimensionless value)
 *    1.0  ;; LJ parameter r0 in "length" (so this is dimensionless value)
 *    "hex2d"
 *    10.0    ;; cavity radius
 *    1.0     ;; cylinder radius
 *    12.0    ;; lattice spacing
 *  ))
 * for porous media (outside of the 3D hexagonal particle array)
 *  (define confinement '(
 *    10.0 ;; LJ parameter epsilon in kT (so this is dimensionless value)
 *    1.0  ;; LJ parameter r0 in "length" (so this is dimensionless value)
 *    "porous"
 *    10.0    ;; particle radius
 *    20.0    ;; lattice spacing in x (2R for touching case)
 *  ))
 * INPUT
 *  var : name of the variable.
 *        in the above example, set "confinement".
 * OUTPUT
 *  returned value : struct confinement
 *                   if NULL is returned, it failed (not defined)
 */
struct confinement *
CF_guile_get (const char *var)
{
  if (guile_check_symbol (var) == 0)
    {
      fprintf (stderr, "CF_guile_get: %s is not defined\n", var);
      return (NULL);
    }

  SCM scm_symbol
    = scm_c_lookup (var);

  SCM scm_confinement
    = scm_variable_ref (scm_symbol);

  if (!SCM_NFALSEP (scm_list_p (scm_confinement)))
    {
      fprintf (stderr, "CF_guile_get: %s is not a list\n", var);
      return (NULL);
    }


  struct confinement *cf = NULL;

  unsigned long len
    = scm_num2ulong (scm_length (scm_confinement),
		     0, "CF_guile_get");
  if (len == 0)
    {
      // no confinement
      return (cf);
    }
  else if (len < 4)
    {
      fprintf (stderr, "CF_guile_get: %s is too short\n", var);
      return (NULL);
    }

  double epsilon
    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (0)),
		   "CF_guile_get");
  double r0
    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (1)),
		   "CF_guile_get");

  // get the string
  char *str_cf = NULL;
  SCM scm_conf = scm_list_ref (scm_confinement, scm_int2num (2));
#ifdef GUILE16
  size_t str_len;
  if (gh_string_p (scm_conf))
    {
      str_cf = gh_scm2newstr (scm_conf, &str_len);
    }
#else // !GUILE16
  if (scm_is_string (scm_conf))
    {
      str_cf = scm_to_locale_string (scm_conf);
    }
#endif // GUILE16
  if (strcmp (str_cf, "sphere") == 0)
    {
      if (len != 4)
	{
	  fprintf (stderr, "CF_guile_get:"
		   " for sphere, number of parameter must be 1\n");
	}
      else
	{
	  double R
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (3)),
			   "CF_guile_get");
	  cf = CF_init (0, // sphere
			R,
			0.0, // r
			0.0, 0.0, 0.0, // x, y, z
			0.0, // R2
			0.0, // L
			0, // flag_LJ
			epsilon,
			r0);
	  CHECK_MALLOC (cf, "CF_guile_get");
	}
    }
  else if (strcmp (str_cf, "sphere+hole") == 0)
    {
      if (len != 5)
	{
	  fprintf (stderr, "CF_guile_get:"
		   " for sphere+hole, number of parameter must be 2\n");
	}
      else
	{
	  double R
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (3)),
			   "CF_guile_get");
	  double r
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (4)),
			   "CF_guile_get");
	  cf = CF_init (1, // sphere+hole
			R,
			r,
			0.0, 0.0, 0.0, // x, y, z
			0.0, // R2
			0.0, // L
			0, // flag_LJ
			epsilon,
			r0);
	  CHECK_MALLOC (cf, "CF_guile_get");
	}
    }
  else if (strcmp (str_cf, "cylinder") == 0)
    {
      if (len != 7)
	{
	  fprintf (stderr, "CF_guile_get:"
		   " for cylinder, number of parameter must be 4\n");
	}
      else
	{
	  double r
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (3)),
			   "CF_guile_get");
	  double x
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (4)),
			   "CF_guile_get");
	  double y
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (5)),
			   "CF_guile_get");
	  double z
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (6)),
			   "CF_guile_get");
	  cf = CF_init (2, // cylinder
			0.0, // R,
			r,
			x, y, z,
			0.0, // R2
			0.0, // L
			0, // flag_LJ
			epsilon,
			r0);
	  CHECK_MALLOC (cf, "CF_guile_get");
	}
    }
  else if (strcmp (str_cf, "dumbbell") == 0)
    {
      if (len != 7)
	{
	  fprintf (stderr, "CF_guile_get:"
		   " for dumbbell, number of parameter must be 4\n");
	}
      else
	{
	  double R
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (3)),
			   "CF_guile_get");
	  double R2
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (4)),
			   "CF_guile_get");
	  double L
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (5)),
			   "CF_guile_get");
	  double r
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (6)),
			   "CF_guile_get");
	  cf = CF_init (3, // dumbbell
			R,
			r,
			0.0, 0.0, 0.0, // x, y, z
			R2,
			L,
			0, // flag_LJ
			epsilon,
			r0);
	  CHECK_MALLOC (cf, "CF_guile_get");
	}
    }
  else if (strcmp (str_cf, "hex2d") == 0)
    {
      if (len != 6)
	{
	  fprintf (stderr, "CF_guile_get:"
		   " for hex2d, number of parameter must be 3\n");
	}
      else
	{
	  double R
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (3)),
			   "CF_guile_get");
	  double r
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (4)),
			   "CF_guile_get");
	  double L
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (5)),
			   "CF_guile_get");
	  cf = CF_init (4, // hex2d
			R,
			r,
			0.0, 0.0, 0.0, // x, y, z
			0.0, // R2
			L,
			0, // flag_LJ
			epsilon,
			r0);
	  CHECK_MALLOC (cf, "CF_guile_get");
	}
    }
  else if (strcmp (str_cf, "porous") == 0)
    {
      if (len != 5)
	{
	  fprintf (stderr, "CF_guile_get:"
		   " for hex2d, number of parameter must be 2\n");
	}
      else
	{
	  double R
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (3)),
			   "CF_guile_get");
	  double L
	    = scm_num2dbl (scm_list_ref (scm_confinement, scm_int2num (4)),
			   "CF_guile_get");
	  cf = CF_init (5, // porous
			R,
			0.0,
			0.0, 0.0, 0.0, // x, y, z
			0.0, // R2
			L,
			0, // flag_LJ
			epsilon,
			r0);
	  CHECK_MALLOC (cf, "CF_guile_get");
	}
    }
  else
    {
      fprintf (stderr, "CF_guile_get: invalid confinement %s\n",
	       str_cf);
    }
  free (str_cf);

  return (cf); // success
}
示例#3
0
int
check_CF_sphere_calc_force (double R,
			    int verbose, double tiny)
{
  if (verbose != 0)
    {
      fprintf (stdout,
	       "==================================================\n"
	       "check_CF_sphere_calc_force (R=%f) : start\n", R);
    }

  int check = 0;
  double max = 0.0;

  struct confinement *cf
    = CF_init (0, // sphere
	       R,
	       0.0, // r,
	       0.0, // x,
	       0.0, // y,
	       0.0, // z,
	       0.0, // R2,
	       0.0, // L,
	       1, // flag_LJ
	       10.0, // e
	       R + 2.0); // r0
  // note now r is in [0, 2R) and a = 1, so it is to prevent overflow.
  CHECK_MALLOC (cf, "check_CF_sphere_calc_force");

  // set struct stokes *sys
  int np = 1;
  double *f = (double *)malloc (sizeof (double) * np * 3);
  CHECK_MALLOC (f, "check_CF_sphere_calc_force");

  struct stokes *sys = stokes_init ();
  CHECK_MALLOC (sys, "check_CF_sphere_calc_force");
  stokes_set_np (sys, np, np);

  char label[80];
  int i;
  for (i = 0; i < 100; i ++)
    {
      double r = (double)i / 100.0 * 2.0 * R;
      int j;
      for (j = 0; j < 10; j ++)
	{
	  double theta = M_PI * (double)j / 10.0;
	  int k;
	  for (k = 0; k < 20; k ++)
	    {
	      double phi = 2.0 * M_PI * (double) k / 20.0;
	      sys->pos[0] = r * sin(theta) * cos(phi);
	      sys->pos[1] = r * sin(theta) * sin(phi);
	      sys->pos[2] = r * cos(theta);

	      CF_sphere_calc_force (cf, sys, f, 0 /* zero-clear */);

	      if (r <= (R-1.0))
		{
		  sprintf (label, " sphere (%f,%5.1f,%5.1f) fx",
			   r, 180.0/M_PI*theta, 180.0/M_PI*phi);
		  check += compare_max (f[0], 0.0, label, verbose, tiny, &max);

		  sprintf (label, " sphere (%f,%5.1f,%5.1f) fy",
			   r, 180.0/M_PI*theta, 180.0/M_PI*phi);
		  check += compare_max (f[1], 0.0, label, verbose, tiny, &max);

		  sprintf (label, " sphere (%f,%5.1f,%5.1f) fz",
			   r, 180.0/M_PI*theta, 180.0/M_PI*phi);
		  check += compare_max (f[2], 0.0, label, verbose, tiny, &max);
		}
	      else
		{
		  double x = r - (R-1.0); // depth of overlap
		  double LJ_r = cf->r0 - x;
		  double fr = 12.0 * cf->e * pow (cf->r0 / LJ_r, 7.0)
		    * (pow (cf->r0 / LJ_r, 6.0) - 1.0);
		  double fx = -fr * sin(theta) * cos(phi);
		  double fy = -fr * sin(theta) * sin(phi);
		  double fz = -fr * cos(theta);

		  sprintf (label, " sphere (%f,%5.1f,%5.1f) fx",
			   r, 180.0/M_PI*theta, 180.0/M_PI*phi);
		  check += compare_max (f[0], fx, label, verbose, tiny, &max);

		  sprintf (label, " sphere (%f,%5.1f,%5.1f) fy",
			   r, 180.0/M_PI*theta, 180.0/M_PI*phi);
		  check += compare_max (f[1], fy, label, verbose, tiny, &max);

		  sprintf (label, " sphere (%f,%5.1f,%5.1f) fz",
			   r, 180.0/M_PI*theta, 180.0/M_PI*phi);
		  check += compare_max (f[2], fz, label, verbose, tiny, &max);
		}
	    }
	}
    }

  CF_free (cf);

  if (verbose != 0)
    {
      fprintf (stdout, " max error = %e vs tiny = %e\n", max, tiny);
      if (check == 0) fprintf (stdout, " => PASSED\n\n");
      else            fprintf (stdout, " => FAILED\n\n");
    }

  return (check);
}
示例#4
0
int
check_CF_init (int verbose, double tiny)
{
  if (verbose != 0)
    {
      fprintf (stdout,
	       "==================================================\n"
	       "check_CF_init : start\n");
    }

  int check = 0;
  double max = 0.0;

  struct confinement *cf;
  int type;
  double R;
  double r;
  double x, y, z;
  double R2;
  double L;
  int flag_LJ;
  double e;
  double r0;

  double theta;
  double theta2;
  double center1; // x component of the center of left cavity
  double center2; // x component of the center of right cavity
  double Lx;
  double Ly;
  double Lz;

  // type == 0 : sphere
  type = 0;
  R  = 10.0;
  r  = 0.0;
  x  = 0.0;
  y  = 0.0;
  z  = 0.0;
  R2 = 0.0;
  L  = 0.0;
  flag_LJ = 0;
  e  = 10.0;
  r0 = 0.8;
  cf = CF_init (type, R, r, x, y, z, R2, L, flag_LJ, e, r0);
  CHECK_MALLOC (cf, "check_CF_init");

  check += compare_max (cf->R, R, " sphere R", verbose, tiny, &max);
  check += compare_max (cf->r, r, " sphere r", verbose, tiny, &max);
  check += compare_max (cf->x, x, " sphere x", verbose, tiny, &max);
  check += compare_max (cf->y, y, " sphere y", verbose, tiny, &max);
  check += compare_max (cf->z, z, " sphere z", verbose, tiny, &max);
  check += compare_max (cf->R2, R2, " sphere R2", verbose, tiny, &max);
  check += compare_max (cf->L, L, " sphere L", verbose, tiny, &max);
  check += compare_max ((double)cf->flag_LJ, (double)flag_LJ, " sphere LJ", verbose, tiny, &max);
  check += compare_max (cf->e, e, " sphere LJ-e", verbose, tiny, &max);
  check += compare_max (cf->r0, r0, " sphere LJ-r0", verbose, tiny, &max);

  theta = asin (r / R);
  check += compare_max (cf->theta, theta, " sphere theta", verbose, tiny, &max);
  check += compare_max (cf->theta2, 0.0, " sphere theta2", verbose, tiny, &max);
  check += compare_max (cf->center1, 0.0, " sphere center1", verbose, tiny, &max);
  check += compare_max (cf->center2, 0.0, " sphere center2", verbose, tiny, &max);
  check += compare_max (cf->Lx, 0.0, " sphere Lx", verbose, tiny, &max);
  check += compare_max (cf->Ly, 0.0, " sphere Ly", verbose, tiny, &max);
  check += compare_max (cf->Lz, 0.0, " sphere Lz", verbose, tiny, &max);

  CF_free (cf);


  // type == 1 : sphere + hole
  type = 1;
  R  = 5.0;
  r  = 1.25;
  x  = 0.0;
  y  = 0.0;
  z  = 0.0;
  R2 = 0.0;
  L  = 0.0;
  flag_LJ = 1;
  e  = 9.0;
  r0 = 0.7;
  cf = CF_init (type, R, r, x, y, z, R2, L, flag_LJ, e, r0);
  CHECK_MALLOC (cf, "check_CF_init");

  check += compare_max (cf->R, R, " sph+hole R", verbose, tiny, &max);
  check += compare_max (cf->r, r, " sph+hole r", verbose, tiny, &max);
  check += compare_max (cf->x, x, " sph+hole x", verbose, tiny, &max);
  check += compare_max (cf->y, y, " sph+hole y", verbose, tiny, &max);
  check += compare_max (cf->z, z, " sph+hole z", verbose, tiny, &max);
  check += compare_max (cf->R2, R2, " sph+hole R2", verbose, tiny, &max);
  check += compare_max (cf->L, L, " sph+hole L", verbose, tiny, &max);
  check += compare_max ((double)cf->flag_LJ, (double)flag_LJ, " sph+hole LJ", verbose, tiny, &max);
  check += compare_max (cf->e, e, " sph+hole LJ-e", verbose, tiny, &max);
  check += compare_max (cf->r0, r0, " sph+hole LJ-r0", verbose, tiny, &max);

  theta = asin (r / R);
  check += compare_max (cf->theta, theta, " sph+hole theta", verbose, tiny, &max);
  check += compare_max (cf->theta2, 0.0, " sph+hole theta2", verbose, tiny, &max);
  check += compare_max (cf->center1, 0.0, " sph+hole center1", verbose, tiny, &max);
  check += compare_max (cf->center2, 0.0, " sph+hole center2", verbose, tiny, &max);
  check += compare_max (cf->Lx, 0.0, " sph+hole Lx", verbose, tiny, &max);
  check += compare_max (cf->Ly, 0.0, " sph+hole Ly", verbose, tiny, &max);
  check += compare_max (cf->Lz, 0.0, " sph+hole Lz", verbose, tiny, &max);

  CF_free (cf);


  // type == 2 : cylinder
  type = 2;
  R  = 0.0;
  r  = 2.5;
  x  = 0.5;
  y  = 0.6;
  z  = 0.7;
  R2 = 0.0;
  L  = 0.0;
  flag_LJ = 0;
  e  = 11.0;
  r0 = 1.1;
  cf = CF_init (type, R, r, x, y, z, R2, L, flag_LJ, e, r0);
  CHECK_MALLOC (cf, "check_CF_init");

  check += compare_max (cf->R, R, " cylinder R", verbose, tiny, &max);
  check += compare_max (cf->r, r, " cylinder r", verbose, tiny, &max);
  check += compare_max (cf->x, x, " cylinder x", verbose, tiny, &max);
  check += compare_max (cf->y, y, " cylinder y", verbose, tiny, &max);
  check += compare_max (cf->z, z, " cylinder z", verbose, tiny, &max);
  check += compare_max (cf->R2, R2, " cylinder R2", verbose, tiny, &max);
  check += compare_max (cf->L, L, " cylinder L", verbose, tiny, &max);
  check += compare_max ((double)cf->flag_LJ, (double)flag_LJ, " cylinder LJ", verbose, tiny, &max);
  check += compare_max (cf->e, e, " cylinder LJ-e", verbose, tiny, &max);
  check += compare_max (cf->r0, r0, " cylinder LJ-r0", verbose, tiny, &max);

  //theta = asin (r / R);
  theta = 0.0; // because R = 0 here
  check += compare_max (cf->theta, theta, " cylinder theta", verbose, tiny, &max);
  check += compare_max (cf->theta2, 0.0, " cylinder theta2", verbose, tiny, &max);
  check += compare_max (cf->center1, 0.0, " cylinder center1", verbose, tiny, &max);
  check += compare_max (cf->center2, 0.0, " cylinder center2", verbose, tiny, &max);
  check += compare_max (cf->Lx, 0.0, " cylinder Lx", verbose, tiny, &max);
  check += compare_max (cf->Ly, 0.0, " cylinder Ly", verbose, tiny, &max);
  check += compare_max (cf->Lz, 0.0, " cylinder Lz", verbose, tiny, &max);

  CF_free (cf);


  // type == 3 : dumbbell
  type = 3;
  R  = 5.0;
  r  = 1.3;
  x  = 0.0;
  y  = 0.0;
  z  = 0.0;
  R2 = 10.0;
  L  = 2.0;
  flag_LJ = 1;
  e  = 15.0;
  r0 = 0.5;
  cf = CF_init (type, R, r, x, y, z, R2, L, flag_LJ, e, r0);
  CHECK_MALLOC (cf, "check_CF_init");

  check += compare_max (cf->R, R, " dumbbell R", verbose, tiny, &max);
  check += compare_max (cf->r, r, " dumbbell r", verbose, tiny, &max);
  check += compare_max (cf->x, x, " dumbbell x", verbose, tiny, &max);
  check += compare_max (cf->y, y, " dumbbell y", verbose, tiny, &max);
  check += compare_max (cf->z, z, " dumbbell z", verbose, tiny, &max);
  check += compare_max (cf->R2, R2, " dumbbell R2", verbose, tiny, &max);
  check += compare_max (cf->L, L, " dumbbell L", verbose, tiny, &max);
  check += compare_max ((double)cf->flag_LJ, (double)flag_LJ, " dumbbell LJ", verbose, tiny, &max);
  check += compare_max (cf->e, e, " dumbbell LJ-e", verbose, tiny, &max);
  check += compare_max (cf->r0, r0, " dumbbell LJ-r0", verbose, tiny, &max);

  theta = asin (r / R);
  check += compare_max (cf->theta, theta, " dumbbell theta", verbose, tiny, &max);
  theta2 = asin (r / R2);
  check += compare_max (cf->theta2, theta2, " dumbbell theta2", verbose, tiny, &max);
  center1 = -(0.5 * L + R * cos (theta));
  center2 = +(0.5 * L + R2* cos (theta2));
  check += compare_max (cf->center1, center1, " dumbbell center1", verbose, tiny, &max);
  check += compare_max (cf->center2, center2, " dumbbell center2", verbose, tiny, &max);
  check += compare_max (cf->Lx, 0.0, " dumbbell Lx", verbose, tiny, &max);
  check += compare_max (cf->Ly, 0.0, " dumbbell Ly", verbose, tiny, &max);
  check += compare_max (cf->Lz, 0.0, " dumbbell Lz", verbose, tiny, &max);

  CF_free (cf);


  // type == 4 : hex2d
  type = 4;
  R  = 5.0;
  r  = 1.3;
  x  = 0.0;
  y  = 0.0;
  z  = 0.0;
  R2 = 0.0;
  L  = 5.5;
  flag_LJ = 0;
  e  = 11.1;
  r0 = 0.81;
  cf = CF_init (type, R, r, x, y, z, R2, L, flag_LJ, e, r0);
  CHECK_MALLOC (cf, "check_CF_init");

  check += compare_max (cf->R, R, " hex2d R", verbose, tiny, &max);
  check += compare_max (cf->r, r, " hex2d r", verbose, tiny, &max);
  check += compare_max (cf->x, x, " hex2d x", verbose, tiny, &max);
  check += compare_max (cf->y, y, " hex2d y", verbose, tiny, &max);
  check += compare_max (cf->z, z, " hex2d z", verbose, tiny, &max);
  check += compare_max (cf->R2, R2, " hex2d R2", verbose, tiny, &max);
  check += compare_max (cf->L, L, " hex2d L", verbose, tiny, &max);
  check += compare_max ((double)cf->flag_LJ, (double)flag_LJ, " hex2d LJ", verbose, tiny, &max);
  check += compare_max (cf->e, e, " hex2d LJ-e", verbose, tiny, &max);
  check += compare_max (cf->r0, r0, " hex2d LJ-r0", verbose, tiny, &max);

  theta = asin (r / R);
  check += compare_max (cf->theta, theta, " hex2d theta", verbose, tiny, &max);
  check += compare_max (cf->theta2, 0.0, " hex2d theta2", verbose, tiny, &max);
  check += compare_max (cf->center1, 0.0, " hex2d center1", verbose, tiny, &max);
  check += compare_max (cf->center2, 0.0, " hex2d center2", verbose, tiny, &max);
  Lx = 0.5 * L;
  Ly = sqrt (3.0) * 0.5 * L;
  check += compare_max (cf->Lx, Lx, " hex2d Lx", verbose, tiny, &max);
  check += compare_max (cf->Ly, Ly, " hex2d Ly", verbose, tiny, &max);
  check += compare_max (cf->Lz, 0.0, " hex2d Lz", verbose, tiny, &max);

  CF_free (cf);

  // type == 5 : porous
  type = 5;
  R  = 5.0;
  r  = 0.0;
  x  = 0.0;
  y  = 0.0;
  z  = 0.0;
  R2 = 0.0;
  L  = 10.0;
  flag_LJ = 0;
  e  = 12.3;
  r0 = 0.76;
  cf = CF_init (type, R, r, x, y, z, R2, L, flag_LJ, e, r0);
  CHECK_MALLOC (cf, "check_CF_init");

  check += compare_max (cf->R, R, " porous R", verbose, tiny, &max);
  check += compare_max (cf->r, r, " porous r", verbose, tiny, &max);
  check += compare_max (cf->x, x, " porous x", verbose, tiny, &max);
  check += compare_max (cf->y, y, " porous y", verbose, tiny, &max);
  check += compare_max (cf->z, z, " porous z", verbose, tiny, &max);
  check += compare_max (cf->R2, R2, " porous R2", verbose, tiny, &max);
  check += compare_max (cf->L, L, " porous L", verbose, tiny, &max);
  check += compare_max ((double)cf->flag_LJ, (double)flag_LJ, " porous LJ", verbose, tiny, &max);
  check += compare_max (cf->e, e, " porous LJ-e", verbose, tiny, &max);
  check += compare_max (cf->r0, r0, " porous LJ-r0", verbose, tiny, &max);

  check += compare_max (cf->theta, 0.0, " porous theta", verbose, tiny, &max);
  check += compare_max (cf->theta2, 0.0, " porous theta2", verbose, tiny, &max);
  check += compare_max (cf->center1, 0.0, " porous center1", verbose, tiny, &max);
  check += compare_max (cf->center2, 0.0, " porous center2", verbose, tiny, &max);
  Lx = L;
  Ly = L * sqrt (3.0);
  Lz = L * sqrt (6.0) * 2.0 / 3.0;
  check += compare_max (cf->Lx, Lx, " porous Lx", verbose, tiny, &max);
  check += compare_max (cf->Ly, Ly, " porous Ly", verbose, tiny, &max);
  check += compare_max (cf->Lz, Lz, " porous Lz", verbose, tiny, &max);

  CF_free (cf);

  if (verbose != 0)
    {
      fprintf (stdout, " max error = %e vs tiny = %e\n", max, tiny);
      if (check == 0) fprintf (stdout, " => PASSED\n\n");
      else            fprintf (stdout, " => FAILED\n\n");
    }

  return (check);
}