예제 #1
0
파일: outputz.cpp 프로젝트: htimko/ArcPIC
// temporary for density
void out_tempn_2D( double n_el[], double n_ion[], int n_aver_e, int n_aver_ion, 
	       int nr, int nz, int NZ, double Vcell[], double Omega_pe, double qp, 
	       double dr, double dz, const char *dat_e, const char *dat_i ) {
  
  FILE *file_e, *file_i;
  double fi, fe;
  int j, k;  
  
  if (n_aver_e < 1)  n_aver_e = 1;
  if (n_aver_ion < 1)  n_aver_ion = 1;
  
  //fi = qp*SQU(1./Omega_pe)*TWOPI/(dz*n_aver_ion);   
  //fe = qp*SQU(1./Omega_pe)*TWOPI/(dz*n_aver_e); 
  fi = qp*SQU(1./Omega_pe)/n_aver_ion;   //CORR! 31.03.2010
  fe = qp*SQU(1./Omega_pe)/n_aver_e;   //CORR! 31.03.2010  

  file_e = fopen(dat_e, "w");
  file_i = fopen(dat_i, "w");

  for (j=0; j<nr; j++) {
    for (k=0; k<nz; k++) {
      fprintf(file_e, "% .5e % .5e % .5e \n", dr*j, dz*k, fe*n_el[j*NZ+k]/Vcell[j]); 
      fprintf(file_i, "% .5e % .5e % .5e \n", dr*j, dz*k, fi*n_ion[j*NZ+k]/Vcell[j]); 
    }
  }
  
  fclose(file_e);
  fclose(file_i);
  
}
예제 #2
0
boolean wildfire_score(population *pop, entity *entity)
  {
  int		i;		/* Map square. */
  int		s;		/* Loop over simulations. */
  int		map[WILDFIRE_X_DIMENSION*WILDFIRE_Y_DIMENSION];	/* Map. */
  int		count=0;	/* Number of cisterns. */
  double	fitness;	/* Solution's "fitness". */

  /* Decode chromsome, and count number of cisterns. */
  for(i=0; i<WILDFIRE_X_DIMENSION*WILDFIRE_Y_DIMENSION; i++)
    {
    map[i] = ((int *)entity->chromosome[0])[i];
    if (map[i]) count++;
    }

  /* Penalise an incorrect number of cisterns. */
  fitness = -0.01*SQU(WILDFIRE_CISTERNS-count);

  for(s=0; s<WILDFIRE_NUM_SIMULATIONS; s++)
    {
    fitness -= wildfire_simulation(map, FALSE);
    }

  /* See how the arrangement of cisterns does. */
  fitness /= WILDFIRE_NUM_SIMULATIONS;

  ga_entity_set_fitness(entity, fitness);

  fprintf(stderr, "#");
  
  return TRUE;
  }
예제 #3
0
boolean fitting_score(population *pop, entity *entity)
{
	int			i;		/* Loop variable over training points. */
	double		score=0.0;	/* Mean of squared deviations. */
	char *		params;
	double		params_d[4];	/* Fitting parameters. */
	fitting_data_t	*data;		/* Training data. */
	double E,R,L,C;

	entity->fitness = 0;

	data = (fitting_data_t *)pop->data;
	params = (char *)entity->chromosome[0];

	chromo_translator(params, params_d);
	E = params_d[0];
	R = params_d[1];
	L = params_d[2];
	C = params_d[3];

	for (i=0; i<data->size; i++)
	{
		if(score > 10000000) 
		{
			score = 10000000;
			break;
		}
		score += SQU(data->y[i]-(target_function(data->x[i], params_d)));
	}

	entity->fitness = -sqrt(score / data->size);
	return TRUE;
}
예제 #4
0
파일: outputz.cpp 프로젝트: htimko/ArcPIC
void out_temps_2D( Moments  mom[], double u0, double fnorm, int nr, int nz, int NZ, 
		   double dr, double dz, const char *dat1, const char *dat2, const char *dat3 ) {

  FILE *file1, *file2, *file3;
  int j, k;
  
  for (j=0; j<nr; j++) {
    for (k=0; k<nz; k++) {
      
      if( mom[j*NZ+k].n > 1 ) {
	mom[j*NZ+k].tz = ( mom[j*NZ+k].tz/(u0*u0*mom[j*NZ+k].n) - SQU(mom[j*NZ+k].uz) )*fnorm;
	mom[j*NZ+k].tr = ( mom[j*NZ+k].tr/(u0*u0*mom[j*NZ+k].n) - SQU(mom[j*NZ+k].ur) )*fnorm;
	mom[j*NZ+k].tt = ( mom[j*NZ+k].tt/(u0*u0*mom[j*NZ+k].n) - SQU(mom[j*NZ+k].ut) )*fnorm;
      }
      else {
	mom[j*NZ+k].tz = mom[j*NZ+k].tr = mom[j*NZ+k].tt = 0.;
      }
      
    }
  }

  file1 = fopen(dat1, "w");
  file2 = fopen(dat2, "w");
  file3 = fopen(dat3, "w");


  for (j=0; j<nr; j++) {
    for (k=0; k<nz; k++) {  
      fprintf(file1, "% .5e % .5e % .5e \n", dr*j, dz*k, mom[j*NZ+k].tz); 
      fprintf(file2, "% .5e % .5e % .5e \n", dr*j, dz*k, mom[j*NZ+k].tr);  
      fprintf(file3, "% .5e % .5e % .5e \n", dr*j, dz*k, mom[j*NZ+k].tt); 
    }
  }
  
  fclose(file1);
  fclose(file2);
  fclose(file3);

}
예제 #5
0
파일: test_simplex.c 프로젝트: aaasz/SHP
boolean test_score(population *pop, entity *entity)
  {
  double		A, B, C, D;	/* Parameters. */

  A = ((double *)entity->chromosome[0])[0];
  B = ((double *)entity->chromosome[0])[1];
  C = ((double *)entity->chromosome[0])[2];
  D = ((double *)entity->chromosome[0])[3];

  entity->fitness = -(fabs(0.75-A)+SQU(0.95-B)+fabs(CUBE(0.23-C))+FOURTH_POW(0.71-D));

  return TRUE;
  }
예제 #6
0
파일: outputz.cpp 프로젝트: htimko/ArcPIC
void out_phi_2D( double phi[], int n_aver, int nr, int nz, int NZ, 
		 double Omega_pe, double dr, double dz, const char *dat1 ) {

  FILE *file1;
  double f1;
  int j, k;
  
  if( n_aver < 1 )  n_aver = 1;
  
  f1 = SQU(dz/Omega_pe)/n_aver;   

  file1 = fopen(dat1, "w");
  for (j=0; j<=nr; j++) {
    for (k=0; k<=nz; k++) {
      fprintf(file1, "% .5e % .5e % .5e \n", dr*j, dz*k, f1*phi[j*NZ+k]); 
    }
  }
  fclose(file1); 
  
}
예제 #7
0
파일: outputz.cpp 프로젝트: htimko/ArcPIC
void out_dens_2D( double dens_av[], int n_aver, double sign, int nr, int nz, int NZ, double Omega_pe,  
		  double dr, double dz, const char *dat_p ) {
  FILE *file_p;
  double fp;
  int j, k;  
  
  if (n_aver < 1)  n_aver = 1;

  fp = sign*SQU(1./Omega_pe)/n_aver;  

  file_p = fopen(dat_p, "w");

  for (j=0; j<=nr; j++) {
    for (k=0; k<=nz; k++) {
      fprintf(file_p, "% .5e % .5e % .5e \n", dr*j, dz*k, fp*dens_av[j*NZ+k]); 
    }
  }
  
  fclose(file_p);
  
}
예제 #8
0
static void TransfiniteSph(Vertex S, Vertex center, Vertex *T)
{
  double r = sqrt(SQU(S.Pos.X - center.Pos.X) + SQU(S.Pos.Y - center.Pos.Y)
                  + SQU(S.Pos.Z - center.Pos.Z));

  double s = sqrt(SQU(T->Pos.X - center.Pos.X) + SQU(T->Pos.Y - center.Pos.Y)
                  + SQU(T->Pos.Z - center.Pos.Z));

  double dirx = (T->Pos.X - center.Pos.X) / s;
  double diry = (T->Pos.Y - center.Pos.Y) / s;
  double dirz = (T->Pos.Z - center.Pos.Z) / s;

  T->Pos.X = center.Pos.X + r * dirx;
  T->Pos.Y = center.Pos.Y + r * diry;
  T->Pos.Z = center.Pos.Z + r * dirz;
}
예제 #9
0
/*check two molecules for equivalence */
gint checkequivalence2Molecules(MolSymAtom* a,MolSymAtom* b,gint n)
{
	MolSymAtom* atomList;
	gint i,j;
	gdouble eps = 1e-3;

	eps = a->eps;


	for (i=0;i<n;i++)
	{
		atomList = b;
		for (j=0;j<n;j++)
	 	{
			if ((a->type == atomList->type) &&
			 (SQU(a->position[0] - atomList->position[0],a->position[1] - atomList->position[1],
			a->position[2] - atomList->position[2]) < eps*eps)) break;
			atomList++;;
		}
		if (j==n) return 0;
		a++;
	}
	return 1;
}
예제 #10
0
파일: outputz.cpp 프로젝트: htimko/ArcPIC
void out_efield_2D( double efield_z[], double efield_r[], int n_aver, int nr, int nz, int NZ, 
		    double Omega_pe, double dr, double dz, const char *dat1, const char *dat2 ) {

  FILE *file1, *file2;
  double f1;
  int j, k;
  
  if( n_aver < 1 )  n_aver = 1;
  
  f1 = 2*dz/SQU(Omega_pe)/n_aver;   

  file1 = fopen(dat1, "w");
  file2 = fopen(dat2, "w");

  for (j=0; j<=nr; j++) {
    for (k=0; k<=nz; k++) {
      fprintf(file1, "% .5e % .5e % .5e \n", dr*j, dz*k, f1*efield_z[j*NZ+k]); 
      fprintf(file2, "% .5e % .5e % .5e \n", dr*j, dz*k, f1*efield_r[j*NZ+k]); 
    }
  }
  fclose(file1); 
  fclose(file2);
  
}
예제 #11
0
boolean pingpong_score(population *pop, entity *entity)
  {
  int		i;	/* Team member. */
  double	score=0.0, lossscore=0.0, badscore=0.0;
  int		badloss=0, loss=0;

  entity->fitness = 0;

  for (i=0; i<25; i++)
    {
    score = (((int *)entity->chromosome[0])[i] - i)*4 + 2;
    if (score > 0)
      {
      loss++;
      lossscore += score;
      if (score > 10)
        {
        badloss++;
        badscore += score;
        }
      }
    }
  lossscore /= loss;

/* In no case should a player lose by > 10 points. */
/*  entity->fitness -= badloss * 3.0;*/
  entity->fitness -= badscore * 2.0;

/* Average loss should be as close to 6 as possible. */
  entity->fitness -= SQU(6 - lossscore) * 3.0;

/* Team should win majority of the games. */
  if (loss>12) entity->fitness -= loss;
  
  return TRUE;
  }
예제 #12
0
GAULFUNC boolean random_test(void)
  {
  unsigned int	i, j, k;		/* Loop variables. */
  double	r;			/* Pseudo-random number. */
  long		bins[NUM_BINS];		/* Bin. */
  double	sum=0,sumsq=0;		/* Stats. */
  int		numtrue=0, numfalse=0;	/* Count booleans. */
  unsigned int	rchi=100;		/* Number of bins in chisq test. */
  unsigned int	nchi=1000;		/* Number of samples in chisq test. */
  double	chisq;			/* Chisq error. */
  double	elimit = 2*sqrt((double)rchi);	/* Chisq error limit. */
  double	nchi_rchi = (double)nchi / (double)rchi;	/* Speed calculation. */
  FILE		*rfile=NULL;		/* Handle for file of random integers. */

  random_init();

  printf("Testing random numbers.\n");

/*
 * Uniform Distribution.
 */
  printf("Uniform distribution.  Mean should be about 0.5.\n");

  for (i=0;i<NUM_BINS;i++) bins[i] = 0;

  for (i=0;i<NUM_SAMPLES;i++)
    {
    r = random_unit_uniform();
    if (r >= 0.0 && r < 1.0)
      {
      bins[(int)(r*NUM_BINS)]++;
      sum += r;
      sumsq += SQU(r);
      }
    else
      {
      printf("Number generated out of range 0.0<=r<1.0.\n");
      }
    }
  printf("Mean = %f\n", sum / NUM_SAMPLES);
  printf("Standard deviation = %f\n", (sumsq - sum*sum/NUM_SAMPLES)/NUM_SAMPLES);

  for (i=0;i<NUM_BINS;i++)
    printf("%5.3f %ld\n", i/(double)NUM_BINS, bins[i]);

/*
 * Gaussian Distribution.
 */
  printf("Gaussian distribution.  Mean should be about 0.45.  Standard deviation should be about 0.05.\n");

  sum=0;
  sumsq=0;

  for (i=0;i<NUM_BINS;i++) bins[i] = 0;

  for (i=0;i<NUM_SAMPLES;i++)
    {
    r = random_gaussian(0.45,0.05);
    if (r >= 0.0 && r < 1.0)
      {
      bins[(int)(r*NUM_BINS)]++;
      sum += r;
      sumsq += SQU(r);
      }
    else
      {
      printf("Number generated out of range 0.0<=r<1.0.\n");
      }
    }
  printf("Mean = %f\n", sum / NUM_SAMPLES);
  printf("Standard deviation = %f\n", (sumsq - sum*sum/NUM_SAMPLES)/NUM_SAMPLES);

  for (i=0;i<NUM_BINS;i++)
    printf("%5.3f %ld\n", i/(double)NUM_BINS, bins[i]);

/*
 * Unit Gaussian Distribution.
 */
  printf("Gaussian distribution.  Mean should be about 0.0.  Standard deviation should be about 1.0.\n");

  sum=0;
  sumsq=0;

  for (i=0;i<NUM_BINS;i++) bins[i] = 0;

  for (i=0;i<NUM_SAMPLES;i++)
    {
    r = random_unit_gaussian();
    if (r >= -5.0 && r < 5.0)
      {
      bins[(int)((r+5.0)*NUM_BINS)/10]++;
      sum += r;
      sumsq += SQU(r);
      }
    else
      {
      printf("Number generated out of range -5.0<=r<5.0.\n");
      }
    }
  printf("Mean = %f\n", sum / NUM_SAMPLES);
  printf("Standard deviation = %f\n", (sumsq - sum*sum/NUM_SAMPLES)/NUM_SAMPLES);

  for (i=0;i<NUM_BINS;i++)
    printf("%5.3f %ld\n", -5.0+10*i/(double)NUM_BINS, bins[i]);

/*
 * Random Boolean.
 */
  printf("Random Booleans.  Two counts should be approximately equal.\n");

  for (i=0;i<NUM_SAMPLES;i++)
    {
    if ( random_boolean() )
      numtrue++;
    else
      numfalse++;
    }
  printf("TRUE/FALSE = %d/%d\n", numtrue, numfalse);

/*
 * Random int.
 */
  printf("Random Integers.  The distribution should be approximately uniform.\n");

  for (i=0;i<NUM_BINS;i++) bins[i] = 0;

  for (i=0;i<NUM_SAMPLES;i++)
    bins[random_int(NUM_BINS)]++;

  for (i=0;i<NUM_BINS;i++)
    printf("%u %ld\n", i, bins[i]);

/*
 * Chi squared test.  This is the standard basic test for randomness of a PRNG.
 * We would expect any moethod to fail about about one out of ten runs.
 * The error is r*t/N - N and should be within 2*sqrt(r) of r.
 */

  printf("Chi Squared Test of Random Integers.  We would expect a couple of failures.\n");

  if (rchi>NUM_BINS) die("Internal error: too few bins.");

  for (j=0;j<NUM_CHISQ;j++)
    {
    printf("Run %u. chisq should be within %f of %u.\n", j, elimit, rchi);
    for(k=0; k<10; k++)
      {
      memset(bins, 0, rchi*sizeof(long));
      chisq = 0.0;

      for(i=0; i<nchi; i++)
        bins[random_int(rchi)]++;

      for(i=0; i<rchi; i++)
        chisq += SQU((double)bins[i] - nchi_rchi);

      chisq /= nchi_rchi;

      printf("chisq = %f - %s\n", chisq, fabs(chisq - rchi)>elimit?"FAILED":"PASSED");
      }
    }

  printf("Creating file (\"randtest.dat\") of 5000 random integer numbers for external analysis.\n");

  rfile = fopen("randtest.dat", "w");

  for (i=0; i<5000; i++)
    {
    r = (double) random_rand();
    fprintf(rfile, "%f %f\n",
            /*i, r,*/
            (double)i/(double)5000, r/(double)RANDOM_RAND_MAX);
    }

  fclose(rfile);

  return TRUE;
  }
예제 #13
0
파일: weno.c 프로젝트: fmaymi/ctf
double __weno5(const double *v, const double c[3][3], const double d[3])
// -----------------------------------------------------------------------------
//
// 
//
// Improvement of the WENO scheme smoothness estimator, Shen & Zha (2010)
// -----------------------------------------------------------------------------
{
  double eps = 1e-6;
  double eps_prime = 1e-6;

  const double vs[3] = {
    c[0][0]*v[+0] + c[0][1]*v[+1] + c[0][2]*v[2],
    c[1][0]*v[-1] + c[1][1]*v[+0] + c[1][2]*v[1],
    c[2][0]*v[-2] + c[2][1]*v[-1] + c[2][2]*v[0],
  };
  double B[3] = { // smoothness indicators
    (13./12.)*SQU(1*v[+0] - 2*v[+1] + 1*v[+2]) +
    ( 1./ 4.)*SQU(3*v[+0] - 4*v[+1] + 1*v[+2]),
    (13./12.)*SQU(1*v[-1] - 2*v[+0] + 1*v[+1]) +
    ( 1./ 4.)*SQU(1*v[-1] - 0*v[+0] - 1*v[+1]),
    (13./12.)*SQU(1*v[-2] - 2*v[-1] + 1*v[+0]) +
    ( 1./ 4.)*SQU(1*v[-2] - 4*v[-1] + 3*v[+0])
  };

  double w[3];
  if (IS_mode == ImprovedBorges08) {
    eps = eps_prime = 1e-14; // Borges uses 1e-40, but has Matlab
    const double tau5 = fabs(B[0] - B[2]);

    // Calculate my weights with new smoothness indicators accoding to Borges
    w[0] = d[0] * (1.0 + (tau5 / (B[0] + eps)));
    w[1] = d[1] * (1.0 + (tau5 / (B[1] + eps)));
    w[2] = d[2] * (1.0 + (tau5 / (B[2] + eps)));
  }
  else if (IS_mode == ImprovedShenZha10) {
    eps = 1e-6;
    eps_prime = 1e-10;
    const double A = shenzha10_A; // [0 (less aggressive) -> ~100 (more aggressive)]
    const double minB = min3(B), maxB = max3(B);
    const double R0 = minB / (maxB + eps_prime);
    B[0] = R0*A*minB + B[0];
    B[1] = R0*A*minB + B[1];
    B[2] = R0*A*minB + B[2];
    w[0] = d[0] / SQU(eps_prime + B[0]);
    w[1] = d[1] / SQU(eps_prime + B[1]);
    w[2] = d[2] / SQU(eps_prime + B[2]);
  }
  else { // Use OriginalJiangShu96
    eps = eps_prime = 1e-6; // recommended value by Jiang and Shu
    w[0] = d[0] / SQU(eps_prime + B[0]);
    w[1] = d[1] / SQU(eps_prime + B[1]);
    w[2] = d[2] / SQU(eps_prime + B[2]);
  }

  const double wtot = w[0] + w[1] + w[2];
  return (w[0]*vs[0] + w[1]*vs[1] + w[2]*vs[2])/wtot;
}
예제 #14
0
파일: outputz.cpp 프로젝트: htimko/ArcPIC
void diagn_av_stability( const double dens[], double diag_Te[], double diag_ne[], int n_av,
			 double sign, double u0, int nr, int nz, int NR, int NZ, double Omega_pe,  
			 double dr, double dz, int steps, int *check, const char *dat_err ) {

  double ne_max = 0., ne_max_old = 0.;
  double ne_av = 0., ne_av_old = 0.; // average over all k's
  int ne_max_j(-1), ne_max_k(-1), ne_av_j(-1);

  // ne/Te ratios
  double noT_max = 0., noT_max_old = 0.;
  double noT_av = 0., noT_av_old = 0.; // average over all k's
  int noT_max_j(-1), noT_max_k(-1), noT_av_j(-1);

  if (n_av < 0) n_av = 1;
  double fne = SQU(1./Omega_pe)/n_av;  


  FILE *file;

  // Check ne, ne/Te 
  for (int j=0; j<NR; j++) {
    for (int k=0; k<NZ; k++) {
      ne_av_old += sign*dens[j*NZ+k];
      ne_max_old = sign*dens[j*NZ+k];
      
      if ( ne_max < ne_max_old ) {
	ne_max = ne_max_old;
	ne_max_j = j;
	ne_max_k = k;
      }
    }
    if ( ne_av < ne_av_old ) {
      ne_av = ne_av_old;
      ne_av_j = j;
    }
    ne_av_old = 0.;
  }
  ne_av *= fne/NZ; // in units of n_ref
  ne_max *= fne; // in units of n_ref
  
  for (int j=0; j<nr; j++) {
    for (int k=0; k<nz; k++) {
      diag_Te[j*NZ+k] /= diag_ne[j*NZ+k]; // don't extract main velocity
      diag_Te[j*NZ+k] /= SQU(u0);
      
      if ( diag_Te[j*NZ+k] > 1e-20 ) {
	noT_av_old += sign*dens[j*NZ+k]/diag_Te[j*NZ+k];
	noT_max_old = sign*dens[j*NZ+k]/diag_Te[j*NZ+k];
      }
      
      if ( noT_max < noT_max_old ) {
	noT_max = noT_max_old;
	noT_max_j = j;
	noT_max_k = k;
      }
    }
    if ( noT_av < noT_av_old ) {
      noT_av = noT_av_old;
      noT_av_j = j;
    }
    noT_av_old = 0.;
  }
  noT_av  *= fne/nz; // in units of n_ref/T_ref
  noT_max *= fne;    // in units of n_ref/T_ref

  // Write to error file if needed
  file = fopen(dat_err, "a");

  // IF ERROR => put check == 1 => stop.
  if ( ne_av > 5. ) {
    fprintf(file, "***ERROR*** GLOBAL(%d steps): <ne>/n_ref= %.5e along j= %d \n", steps, ne_av, ne_av_j); 
    *check = 1;
  }
  if ( noT_av > 2. ) {
    fprintf(file, "***ERROR*** GLOBAL(%d steps): <ne/Te>/(n_ref/T_ref)= %.5e along j= %d \n", steps, noT_av, noT_av_j);      
    *check = 1;
  }

  // WARNINGS
  if ( ne_av > 1. ) {
    fprintf(file, "***WARNING*** GLOBAL(%d steps): <ne>/n_ref= %.5e along j= %d \n", steps, ne_av, ne_av_j); 
  }
  if ( ne_max > 5. ) {
    fprintf(file, "***WARNING*** LOCAL(%d steps): [ne]max/n_ref= %.5e at j= %d k= %d \n", steps, ne_max, ne_max_j, ne_max_k); 
  }
  if ( noT_av > 1. ) {
    fprintf(file, "***WARNING*** GLOBAL(%d steps): <ne/Te>/(n_ref/T_ref)= %.5e along j= %d \n", steps, noT_av, noT_av_j); 
  }
  if ( noT_max > 2. ) {
    fprintf(file, "***WARNING*** LOCAL(%d steps): [ne/Te]max/(n_ref/T_ref)= %.5e at j= %d k= %d \n", steps, noT_max, noT_max_j, noT_max_k); 
  }
  
  fclose(file);
  
}
예제 #15
0
파일: outputz.cpp 프로젝트: htimko/ArcPIC
void diagn_stability_2D( const double dens[], Particle pa[], double diag_Te[], double diag_ve[], double diag_ne[], 
			 double sign, int np, double u0, int nr, int nz, int NR, int NZ, double Omega_pe,  
			 double dr, double dz, int steps, int& check, const char *dat_err ) {

  double ne_max = 0., ne_max_old = 0.;
  double ne_av = 0., ne_av_old = 0.; // average over all k's
  int ne_max_j(-1), ne_max_k(-1), ne_av_j(-1);

  // ne/Te ratios
  double noT_max = 0., noT_max_old = 0.;
  double noT_av = 0., noT_av_old = 0.; // average over all k's
  int noT_max_j(-1), noT_max_k(-1), noT_av_j(-1);

  double fne;
  fne = SQU(1./Omega_pe);  

  double vz, vr, vt, vz2, vr2, vt2;

  FILE *file;

  // Check ne, ne/Te 
  for (int j=0; j<NR; j++) {
    for (int k=0; k<NZ; k++) {
      ne_av_old += sign*dens[j*NZ+k];
      ne_max_old = sign*dens[j*NZ+k];
      
      if ( ne_max < ne_max_old ) {
	ne_max = ne_max_old;
	ne_max_j = j;
	ne_max_k = k;
      }
    }
    if ( ne_av < ne_av_old ) {
      ne_av = ne_av_old;
      ne_av_j = j;
    }
    ne_av_old = 0.;
  }
  ne_av  *= fne/NZ; // in units of n_ref
  ne_max *= fne;    // in units of n_ref
  
  for (int j=0; j<NR; j++) {
    for (int k=0; k<NZ; k++) {
      diag_Te[j*NZ+k]=0.;
      diag_ve[j*NZ+k]=0.;
      diag_ne[j*NZ+k]=0.;
    }
  }

  for (int n=0; n<np; n++) {
    int j = (int)pa[n].p.r;
    int k = (int)pa[n].p.z;
    
    vz = pa[n].p.vz;
    vr = pa[n].p.vr;
    vt = pa[n].p.vt;
    diag_ve[j*NZ+k] += vz + vr + vt;
    
    vz2 = SQU(vz);
    vr2 = SQU(vr);
    vt2 = SQU(vt);
    diag_Te[j*NZ+k] += vz2 + vr2 + vt2;
    
    diag_ne[j*NZ+k]++;
  }
  
  for (int j=0; j<nr; j++) {
    for (int k=0; k<nz; k++) {
      diag_Te[j*NZ+k] /= diag_ne[j*NZ+k];
      //diag_Te[j*NZ+k] -= SQU(diag_ve[j*NZ+k]/diag_ne[j*NZ+k]); // don't extract main velocity
      diag_Te[j*NZ+k] /= SQU(u0);
      
      diag_ne[j*NZ+k] = sign*dens[j*NZ+k];
      
      noT_av_old += diag_ne[j*NZ+k]/diag_Te[j*NZ+k];
      noT_max_old = diag_ne[j*NZ+k]/diag_Te[j*NZ+k];
      
      if ( noT_max < noT_max_old ) {
	noT_max = noT_max_old;
	noT_max_j = j;
	noT_max_k = k;
      }
    }
    if ( noT_av < noT_av_old ) {
      noT_av = noT_av_old;
      noT_av_j = j;
    }
    noT_av_old = 0.;
  }
  noT_av  *= fne/nz; // in units of n_ref/T_ref
  noT_max *= fne;    // in units of n_ref/T_ref
  
  // Write to error file if needed
  file = fopen(dat_err, "a");
  // If error => put check == 1 => stop.
  if ( ne_av > 5. ) {
    fprintf(file, "***ERROR*** GLOBAL(%d steps): <ne>/n_ref= %.5e along j= %d \n", steps, ne_av, ne_av_j); 
    check = 1;
  }
  if ( noT_av > 2. ) {
    fprintf(file, "***ERROR*** GLOBAL(%d steps): <ne/Te>/(n_ref/T_ref)= %.5e along j= %d \n", steps, noT_av, noT_av_j);      
    check = 1;
  }
  
  // WARNINGS
  if ( ne_av > 1. ) {
    fprintf(file, "***WARNING*** GLOBAL(%d steps): <ne>/n_ref= %.5e along j= %d \n", steps, ne_av, ne_av_j); 
  }
  if ( ne_max > 5. ) {
    fprintf(file, "***WARNING*** LOCAL(%d steps): [ne]max/n_ref= %.5e at j= %d k= %d \n", steps, ne_max, ne_max_j, ne_max_k); 
  }
  if ( noT_av > 1. ) {
    fprintf(file, "***WARNING*** GLOBAL(%d steps): <ne/Te>/(n_ref/T_ref)= %.5e along j= %d \n", steps, noT_av, noT_av_j); 
  }
  if ( noT_max > 2. ) {
    fprintf(file, "***WARNING*** LOCAL(%d steps): [ne/Te]max/(n_ref/T_ref)= %.5e at j= %d k= %d \n", steps, noT_max, noT_max_j, noT_max_k); 
  }
  
  fclose(file);
}
예제 #16
0
static double F_Transfinite(GEdge *ge, double t_)
{
  double length = ge->length();
  if(length == 0.0){
    Msg::Error("Zero-length curve %d in transfinite mesh", ge->tag());
    return 1.;
  }

  SVector3 der = ge->firstDer(t_) ;
  double d = norm(der);
  double coef = ge->meshAttributes.coeffTransfinite;
  int type = ge->meshAttributes.typeTransfinite;
  int nbpt = ge->meshAttributes.nbPointsTransfinite;

  if(CTX::instance()->mesh.flexibleTransfinite && CTX::instance()->mesh.lcFactor)
    nbpt /= CTX::instance()->mesh.lcFactor;

  Range<double> bounds = ge->parBounds(0);
  double t_begin = bounds.low();
  double t_end = bounds.high();
  double t = (t_ - t_begin)/(t_end-t_begin);

  double val;

  if(coef <= 0.0 || coef == 1.0) {
    // coef < 0 should never happen
    val = d * coef / ge->length();
  }
  else {
    switch (std::abs(type)) {

    case 1: // Geometric progression ar^i; Sum of n terms = length = a (r^n-1)/(r-1)
      {
        double r = (sign(type) >= 0) ? coef : 1. / coef;
        double a = length * (r - 1.) / (pow(r, nbpt - 1.) - 1.);
        int i = (int)(log(t * length / a * (r - 1.) + 1.) / log(r));
        val = d / (a * pow(r, (double)i));
      }
      break;

    case 2: // Bump
      {
        double a;
        if(coef > 1.0) {
          a = -4. * sqrt(coef - 1.) * atan2(1., sqrt(coef - 1.)) /
            ((double)nbpt *  length);
        }
        else {
          a = 2. * sqrt(1. - coef) * log(fabs((1. + 1. / sqrt(1. - coef)) /
                                              (1. - 1. / sqrt(1. - coef))))
            / ((double)nbpt * length);
        }
        double b = -a * length * length / (4. * (coef - 1.));
        val = d / (-a * SQU(t * length - (length) * 0.5) + b);
      }
      break;

    default:
      Msg::Warning("Unknown case in Transfinite Line mesh");
      val = 1.;
      break;
    }
  }
  return val;
}
예제 #17
0
int MQuadrangle9::getNumFacesRep(bool curved){
  return curved ? 2*SQU(CTX::instance()->mesh.numSubEdges) : 2;
}