next up previous contents
Next: Python Up: Wrappers Previous: Wrappers

C

First, let's look at a very simple code test-stokes written in C, where a resistance problem for 8 particles in the simple cubic lattice configuration in the cubic periodic cell with the size of $ 10$ is solved for the constant velocity $ \bm{U} = (1,1,1)$ by the solver solve_res_3f().
/* test code for libstokes
 * Copyright (C) 2006-2007 Kengo Ichiki <kichiki@users.sourceforge.net>
 * $Id: manual.tex,v 1.5 2008/10/12 20:16:53 kichiki Exp $
*/

int
main (int argc, char** argv)
{
  struct stokes *sys = stokes_init ();

  int np, nm;
  np = 8;
  nm = 8;
  stokes_set_np (sys, np, nm);

  sys->periodic = 1; // periodic boundary condition
  double lx, ly, lz;
  lx = 10.0;
  ly = 10.0;
  lz = 10.0;
  stokes_set_l (sys, lx, ly, lz);

  double ewald_tr = 60.25;
  double xi = xi_by_tratio (sys, ewald_tr);

  double ewald_eps = 1.0e-12;
  stokes_set_xi (sys, xi, ewald_eps);

  fprintf (stdout, "xi = %f\n", xi);

  //sys->lubmin = 2.0000000001;
  sys->lubmin2 = 4.0000000001;
  sys->lubmax = 4.0;
  stokes_set_iter (sys, "gmres", 2000, 20, 1.0e-6, 1, stdout);

  int i;
  double * pos;
  double * u;
  double * f;
  pos = (double *)calloc (np * 3, sizeof (double));
  u   = (double *)calloc (np * 3, sizeof (double));
  f   = (double *)calloc (np * 3, sizeof (double));

  pos[ 0] = 0.0; // x component
  pos[ 1] = 0.0; // y component
  pos[ 2] = 0.0; // z component
  pos[ 3] = 5.0; pos[ 4] = 0.0; pos[ 5] = 0.0;
  pos[ 6] = 0.0; pos[ 7] = 5.0; pos[ 8] = 0.0;
  pos[ 9] = 0.0; pos[10] = 0.0; pos[11] = 5.0;
  pos[12] = 5.0; pos[13] = 5.0; pos[14] = 0.0;
  pos[15] = 0.0; pos[16] = 5.0; pos[17] = 5.0;
  pos[18] = 5.0; pos[19] = 0.0; pos[20] = 5.0;
  pos[21] = 5.0; pos[22] = 5.0; pos[23] = 5.0;

  for (i = 0; i < np * 3; i ++)
    {
      u[i] = 1.0;
    }

  fprintf (stdout, "pos:\n");
  for (i = 0; i < np; i ++)
    {
      fprintf (stdout, "%d %f %f %f\n",
	       i,
	       pos[i*3 + 0],
	       pos[i*3 + 1],
	       pos[i*3 + 2]);
    }

  fprintf (stdout, "u:\n");
  for (i = 0; i < np; i ++)
    {
      fprintf (stdout, "%d %f %f %f\n",
	       i,
	       u[i*3 + 0],
	       u[i*3 + 1],
	       u[i*3 + 2]);
    }

  stokes_set_pos (sys, pos);

  solve_res_3f (sys, u, f);

  fprintf (stdout, "f:\n");
  for (i = 0; i < np; i ++)
    {
      fprintf (stdout, "%d %f %f %f\n",
	       i,
	       f[i*3 + 0],
	       f[i*3 + 1],
	       f[i*3 + 2]);
    }

  return 0;
}



Kengo Ichiki 2008-10-12