void _MeshParticleLayout_Init( void* meshParticleLayout, Mesh* mesh, Particle_InCellIndex cellParticleCount, unsigned int seed, unsigned int filltype ) {
	MeshParticleLayout* self = (MeshParticleLayout*)meshParticleLayout;

	self->mesh = mesh;
	self->isConstructed     = True;
	self->cellParticleCount = cellParticleCount;
	self->seed              = seed;
    self->filltype          = filltype;
	
	Swarm_Random_Seed( self->seed );
}
Esempio n. 2
0
void _MeshParticleLayout_Init( void* meshParticleLayout, Particle_InCellIndex cellParticleCount, unsigned int seed ) {
	MeshParticleLayout* self = (MeshParticleLayout*)meshParticleLayout;

	self->mesh = NULL;
	self->isConstructed     = True;
	self->cellParticleCount = cellParticleCount;
	self->seed              = seed;
	
	Swarm_Random_Seed( self->seed );

	_PerCellParticleLayout_Init( meshParticleLayout, GlobalCoordSystem, False );
}
void PCDVCSuite_TestExponentialInterface( PCDVCSuiteData* data ) {
   Swarm*             integrationSwarm = (Swarm*)LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"integrationSwarm" );
   Swarm*             materialSwarm    = (Swarm*)LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"materialPoints" );
   FeMesh*            mesh             = (FeMesh*)LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"linearMesh" );
   //WeightsCalculator* weights          = (WeightsCalculator*)LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"weights" );
   FeVariable*        feVariable;
   Element_LocalIndex lElement_I       = 0;
   double             analyticValue    = 0.0;
   double             integral         = 0.0;
   double             error;
   double             errorSquaredSum  = 0.0;
   double             errorSum         = 0.0;
   Index              loop_I;
   Index              count            = Dictionary_GetUnsignedInt_WithDefault( data->context->dictionary, "SampleSize", 5000 );
   void*              generic          = NULL;
   double             mean;
   double             standardDeviation;

   /* Create FeVariable */
   feVariable = FeVariable_New_Full(
      "feVariable",
      (DomainContext*)data->context,
      mesh,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL, 
      1,
      data->context->dim,
      False,
      False,
      False,
      MPI_COMM_WORLD,
      data->context->fieldVariable_Register );

   feVariable->_interpolateWithinElement = ExponentialInterface;
   analyticValue = 0.05 * (exp(2) - exp(-2)) + 2.0;

   for ( loop_I = 0 ; loop_I < count ; loop_I++ ) {
      /* Layout Particles */
      Swarm_Random_Seed( (long)loop_I );
      _Swarm_InitialiseParticles( materialSwarm, generic );

      _IntegrationPointsSwarm_UpdateHook( NULL, integrationSwarm );
      /* The following function should not be called here as it is already called ultimately via the above function */
      /* calling this function again causes a first iteration in Lloyd's algorithm for the Voronoi cells which we don't want here */
      //WeightsCalculator_CalculateCell( weights, integrationSwarm, lElement_I );

      /* Evaluate Integral */
      integral = FeVariable_IntegrateElement( feVariable, integrationSwarm, lElement_I );

      /* Calculate Error */
      error = fabs( integral - analyticValue )/fabs( analyticValue );
      errorSum += error;
      errorSquaredSum += error*error;
   }

   /* Calculate Mean and Standard Deviation */
   mean = errorSum / (double)count;
   standardDeviation = sqrt( errorSquaredSum / (double)count - mean * mean );
   printf("In %s: Mean %lf SD %lf Sol %lf\n", __func__, mean, standardDeviation, analyticValue);
   Stg_Component_Destroy( feVariable, NULL, True );

   compareAgainstReferenceSolution( data->context, data->stream, mean, standardDeviation, "testPCDVC_ExponentialInterface.expected" );
}
void WeightsSuite_TestElementIntegral(
   PICelleratorContext* context,
   Name                 funcName,
   Index                count,   // was SampleSize - defaults to 5000
   double               meanTolerance,
   double               stdDevTolerance,
   double               expectedMean,
   double               expectedStdDev ) 
{
   Swarm*             integrationSwarm = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"integrationSwarm" );
   Swarm*             materialSwarm    = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPoints" );
   FeMesh*            mesh             = (FeMesh*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"linearMesh" );
   WeightsCalculator* weights          = (WeightsCalculator*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"weights"  );
   FeVariable*        feVariable;
   Element_LocalIndex lElement_I       = 0;
   double             analyticValue    = 0.0;
   double             integral         = 0.0;
   double             error;
   double             errorSquaredSum  = 0.0;
   double             errorSum         = 0.0;
   double             mean;
   double             standardDeviation;
   Index              loop_I;
   void*              data;
   double             differenceMean, differenceStdDev;   

   /* Create FeVariable */
   feVariable = FeVariable_New_Full(
      "feVariable", 
      (DomainContext*)context,
      mesh,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL, 
      1,
      context->dim,
      False,
      False,
      False,
      MPI_COMM_WORLD,
      context->fieldVariable_Register );

   Journal_Firewall( (funcName!=NULL), Journal_Register( Error_Type, (Name)"ConstantWeightsSuite"  ),
      "Error, function name input to %s is NULL", __func__ );

   if ( strcasecmp( funcName, "ShapeFunction" ) == 0 ) {
      feVariable->_interpolateWithinElement = shapeFunction;
      analyticValue = 4.0;
   }
   else if ( strcasecmp( funcName, "ConstantFunction" ) == 0 ) {
      feVariable->_interpolateWithinElement = constantFunction;
      analyticValue = -12.0;
   }
   else if ( strcasecmp( funcName, "LinearFunction" ) == 0 ) {
      feVariable->_interpolateWithinElement = linearFunction;
      analyticValue = 8.0;
   }
   else if ( strcasecmp( funcName, "QuadraticFunction" ) == 0 ) {
      feVariable->_interpolateWithinElement = quadraticFunction;
      analyticValue = 16.0/3.0;
   }
   else if ( strcasecmp( funcName, "PolynomialFunction" ) == 0 ) {
      feVariable->_interpolateWithinElement = polynomialFunction;
      analyticValue = 148.0/3.0;
   }
   else if ( strcasecmp( funcName, "ExponentialFunction" ) == 0 ) {
      feVariable->_interpolateWithinElement = exponentialFunction;
      analyticValue = 0.0 /*TODO*/;
      abort();
   }
   else if ( strcasecmp( funcName, "ExponentialInterface" ) == 0 ) {
      feVariable->_interpolateWithinElement = exponentialInterface;
      analyticValue = 0.05 * (exp(2) - exp(-2)) + 2.0;
   }
   else if ( strcasecmp( funcName, "CircleInterface" ) == 0 ) {
      feVariable->_interpolateWithinElement = circleInterface;
      analyticValue = M_PI;
   }
   else 
      Journal_Firewall( False,
         Journal_Register( Error_Type, (Name)"ConstantWeightsSuite"  ),
         "Cannot understand function name '%s'\n", funcName );

   for ( loop_I = 0 ; loop_I < count ; loop_I++ ) {
      Swarm_Random_Seed( (long)loop_I );
      /* Layout Particles */
      _Swarm_InitialiseParticles( materialSwarm, data );

      _IntegrationPointsSwarm_UpdateHook( NULL, integrationSwarm );
      
      WeightsCalculator_CalculateCell( weights, integrationSwarm, lElement_I );

      /* Evaluate Integral */
      integral = FeVariable_IntegrateElement( feVariable, integrationSwarm, lElement_I );

      /* Calculate Error */
      error = fabs( integral - analyticValue )/fabs( analyticValue );
      errorSum += error;
      errorSquaredSum += error*error;
   }

   /* Calculate Mean and Standard Deviation */
   mean = errorSum / (double)count;
   standardDeviation = sqrt( errorSquaredSum / (double)count - mean * mean );

   //printf( "Func: %s - Mean = %g; SD = %g\n", funcName, mean, standardDeviation );

   /* compare the mean and standard deviation */
   differenceMean = fabs(mean - expectedMean);
   differenceStdDev = fabs(standardDeviation - expectedStdDev);
   pcu_check_le( differenceMean, meanTolerance );
   pcu_check_le( differenceStdDev, stdDevTolerance );
}