Ejemplo n.º 1
0
/* write fracture state */
static void fracture_state_write (DOM *dom)
{
  char path [1024];
  double R[3], r, (*disp) [3];
  int i, n, dofs;
  MESH *msh;
  SET *item;
  BODY *bod;
  CON *con;

#if HDF5
  int numbod;
  PBF *f;

  snprintf (path, 1024, "%s/fracture", dom->solfec->outpath);
  ASSERT (f = PBF_Write (path, PBF_ON, PBF_ON), ERR_FILE_OPEN);

  PBF_Time (f, &dom->time);

  for (numbod = 0, bod = dom->bod; bod; bod = bod->next)
  {
    if (bod->fracture)
    {
      msh = bod->shape->data;
      dofs = 3 * msh->nodes_count;
      ERRMEM (disp = malloc (msh->nodes_count * sizeof (double [3])));
      for (i = 0; i < msh->nodes_count; i ++)
      {
        SUB (msh->cur_nodes [i], msh->ref_nodes [i], disp [i]);
      }

      PBF_Uint (f, &bod->id, 1);
      PBF_Int (f, &dofs, 1);
      PBF_Double (f, (double*)disp, dofs);

      n = SET_Size (bod->con);
      PBF_Int (f, &n, 1);
      for (item = SET_First (bod->con); item; item = SET_Next (item))
      {
	con = item->data;
	r = sqrt (con->area/ALG_PI);
	PBF_Double (f, &r, 1);

	if (bod == con->master)
	{
	  PBF_Double (f, con->mpnt, 3);
	}
	else
	{
	  PBF_Double (f, con->spnt, 3);
	}

        NVMUL (con->base, con->R, R);
	PBF_Double (f, R, 3);
      }

      bod->fracture = 0;

      free (disp);
      numbod ++;
    }

    PBF_Int2 (f, "numbod", &numbod, 1);
  }

  PBF_Close (f);
#else
  FILE *f;
  XDR x;

#if MPI
  snprintf (path, 1024, "%s/fracture%d.dat", dom->solfec->outpath, dom->rank);
#else
  snprintf (path, 1024, "%s/fracture.dat", dom->solfec->outpath);
#endif
  ASSERT (f = fopen (path, "a"), ERR_FILE_OPEN);
  xdrstdio_create (&x, f, XDR_ENCODE);

  for (bod = dom->bod; bod; bod = bod->next)
  {
    if (bod->fracture)
    {
      msh = bod->shape->data;
      dofs = 3 * msh->nodes_count;
      ERRMEM (disp = malloc (msh->nodes_count * sizeof (double [3])));
      for (i = 0; i < msh->nodes_count; i ++)
      {
        SUB (msh->cur_nodes [i], msh->ref_nodes [i], disp [i]);
      }

      ASSERT (xdr_u_int (&x, &bod->id), ERR_FILE_WRITE);
      ASSERT (xdr_int (&x, &dofs), ERR_FILE_WRITE);
      ASSERT (xdr_vector (&x, (char*)disp, dofs, sizeof (double), (xdrproc_t)xdr_double), ERR_FILE_WRITE);
      n = SET_Size (bod->con);
      ASSERT (xdr_int (&x, &n), ERR_FILE_WRITE);
      for (item = SET_First (bod->con); item; item = SET_Next (item))
      {
	con = item->data;
	r = sqrt (con->area/ALG_PI);
	ASSERT (xdr_double (&x, &r), ERR_FILE_WRITE);

	if (bod == con->master)
	{
          ASSERT (xdr_vector (&x, (char*)con->mpnt, 3, sizeof (double), (xdrproc_t)xdr_double), ERR_FILE_WRITE);
	}
	else
	{
          ASSERT (xdr_vector (&x, (char*)con->spnt, 3, sizeof (double), (xdrproc_t)xdr_double), ERR_FILE_WRITE);
	}

        NVMUL (con->base, con->R, R);
        ASSERT (xdr_vector (&x, (char*)R, 3, sizeof (double), (xdrproc_t)xdr_double), ERR_FILE_WRITE);
      }

      bod->fracture = 0;

      free (disp);
    }
  }

  xdr_destroy (&x);
  fclose (f);
#endif
}
Ejemplo n.º 2
0
int main (int argc, char **argv)
{
  char *s, str [512];
  int n, nmax;
  double d;
  PBF *bf;

  if (argc == 1)
  {
    printf ("pbftest [NUMBER OF SAMPLES] [COMPRESSION FLAG]\n");
    return 0;
  }

  if (argc >= 2 && isdigit (argv [1][0]))
    nmax = atoi (argv [1]);
  else nmax = 10;

  bf = PBF_Write ("pbftest.state");

  if (argc >= 3)
  {
    if (atoi (argv [2]) == 1)
    {
      bf->compression = PBF_ON; /* enable compression */
    }
  }

  for (n = 1; n <= nmax; n ++) write (bf, n);
  PBF_Close (bf);

  bf = PBF_Read ("pbftest.state");
  for (n = 1; n <= nmax; n ++) 
  {
    if (!read (bf, n))
    {
      fprintf (stderr, "FAILED (reading all)\n");
      return 1;
    }
    PBF_Forward (bf, 1);
  }

  /* read every third double */
  PBF_Seek (bf, 0);
  for (n = 1; n <= nmax; n += 3)
  {
    PBF_Label (bf, "DOUBLE");
    PBF_Double (bf, &d, 1);
    if (d != (double) n)
    {
      fprintf (stderr, "FAILED (forward reading every 3rd labeled double)\n");
      return 1;
    }
    PBF_Forward (bf, 3);
  }

  /* read every fifth string */
  PBF_Seek (bf, 0);
  for (n = 1; n <= nmax; n += 5)
  {
    PBF_Label (bf, "STRING");
    s = NULL;
    PBF_String (bf, &s);
    sprintf (str, "CURRENT NUMBER IS %d", n);
    if (strcmp (s, str) != 0)
    {
      fprintf (stderr, "FAILED (forward reading every 5th labeled string)\n");
      return 1;
    }
    PBF_Forward (bf, 5);
    free (s);
  }

  /* do the same backwards */
  PBF_Seek (bf, nmax);
  for (n = nmax; n >= 1; n -= 3)
  {
    PBF_Label (bf, "DOUBLE");
    PBF_Double (bf, &d, 1);
    if (d != (double) n)
    {
      fprintf (stderr, "FAILED (backward reading every 3rd labeled double)\n");
      return 1;
    }
    PBF_Backward (bf, 3);
  }
  PBF_Seek (bf, nmax);
  for (n = nmax; n >= 1; n -= 5)
  {
    PBF_Label (bf, "STRING");
    s = NULL;
    PBF_String (bf, &s);
    sprintf (str, "CURRENT NUMBER IS %d", n);
    if (strcmp (s, str) != 0)
    {
      fprintf (stderr, "FAILED (forward reading every 5th labeled string)\n");
      return 1;
    }
    PBF_Backward (bf, 5);
    free (s);
  }
 
  PBF_Close (bf);

  printf ("PASSED\n");
  return 0;
}