Exemplo n.º 1
0
void _GeneralSwarm_Init(
   void*                                 swarm,
   EscapedRoutine*                       escapedRoutine )
{
   GeneralSwarm*    self = (GeneralSwarm*)swarm;
   GlobalParticle          globalParticle;

   self->swarmAdvector      = NULL;		/* If we're using a SwarmAdvector, it will 'attach' itself later on. */
   self->escapedRoutine     = escapedRoutine;

   self->particleCoordVariable = Swarm_NewVectorVariable( self, (Name)"Position", GetOffsetOfMember( globalParticle, coord ),
                                 Variable_DataType_Double,
                                 self->dim,
                                 "PositionX",
                                 "PositionY",
                                 "PositionZ" );
   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->particleCoordVariable->variable );
   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->particleCoordVariable );

   /* init members */
   self->previousIntSwarmMap = NULL;
   /* lets init this guy with one spot for convenience */
   self->intSwarmMapList = List_New("intSwarmMapList");
   List_SetItemSize(self->intSwarmMapList, sizeof(SwarmMap*));

}
void _IntegrationPointsSwarm_Init( 
   void*                   swarm,
   FeMesh*                 mesh )
{
   IntegrationPointsSwarm* self = (IntegrationPointsSwarm*)swarm;
   LocalParticle           localParticle;
   IntegrationPoint        particle;

   self->mesh               = mesh;

   self->weightVariable = Swarm_NewScalarVariable( self, (Name)"Weight", GetOffsetOfMember( particle , weight ), 
      Variable_DataType_Double );

   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->weightVariable );
   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->weightVariable->variable );

   self->localCoordVariable = Swarm_NewVectorVariable( self, (Name)"LocalElCoord", GetOffsetOfMember( localParticle , xi ),
      Variable_DataType_Double, self->dim, "Xi", "Eta", "Zeta" );

   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->localCoordVariable );
   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->localCoordVariable->variable );
   
   /* _Construct calls _Swarm_Init */

   /* Lock down the extension manager.
    * It doesn't make sense for the IntegrationPointsSwarm to allow IntegrationPoints to be extended
    * This means attempts to extend integration points are firewalled to pickup errors.
    * -- Alan 20060506
    */
   ExtensionManager_SetLockDown( self->particleExtensionMgr, True );

   self->swarmsMappedTo = List_New("swarmsMappedTo");
   List_SetItemSize(self->swarmsMappedTo, sizeof(SwarmMap*));

}
void _DruckerPrager_Init(
		DruckerPrager*                                     self,
		int                                                pressure_id,
		int                                                velocityGradients_id,
		double                                             minimumYieldStress,
		double                                             frictionCoefficient,
		double                                             frictionCoefficientAfterSoftening )
{
   MaterialPointsSwarm*      materialPointsSwarm;
	DruckerPrager_Particle*   particleExt;
	StandardParticle          materialPoint;
	Dimension_Index          dim = 0;
	
	/* Assign Pointers */
	self->frictionCoefficient = frictionCoefficient;
	self->minimumYieldStress  = minimumYieldStress;
	
	self->pressureTag         = pressure_id;
	self->velocityGradientsTag = velocityGradients_id;
   materialPointsSwarm = self->mgr->materialSwarm;
   dim = materialPointsSwarm->dim;	
    /* Strain softening of Friction - (linear weakening is assumed ) */
	/* needs a softening factor between +0 and 1 and a reference strain > 0 */
	self->frictionCoefficientAfterSoftening = frictionCoefficientAfterSoftening;

   /* get the particle extension */
   self->particleExtHandle = ExtensionManager_GetHandle( materialPointsSwarm->particleExtensionMgr, (Name)DruckerPrager_Type );

   if( self->particleExtHandle == (unsigned)-1 ) {
      /* if no particles extension add it and add Update hook */
      self->particleExtHandle = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)DruckerPrager_Type, sizeof(DruckerPrager_Particle) );

      particleExt = (double*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &materialPoint, self->particleExtHandle );
      
      /* The tensileFailure variable allows to check whether a materialPoint has failed in tensile mode or not */
      self->tensileFailure = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"DruckerPragerTensileFailure", (ArithPointer) &particleExt->tensileFailure - (ArithPointer) &materialPoint, Variable_DataType_Char );
      LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->tensileFailure->variable );
      LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->tensileFailure );
	   
   } else {
      /* get references to all swarm variables */
      Name var_name = Stg_Object_AppendSuffix( materialPointsSwarm, (Name)"DruckerPragerTensileFailure"  );
      self->tensileFailure = SwarmVariable_Register_GetByName( materialPointsSwarm->swarmVariable_Register, var_name );
      Memory_Free( var_name );
	   
   }

   self->curFrictionCoef = 0.0;

}
PpcFeVariable* PpcFeVariable_New( Name name, 
      DomainContext *context, 
      FeMesh *mesh,
      IntegrationPointsSwarm *swarm,
      Bool accumulate,
      PpcManager *ppcMan,
      int tag ) {

   PpcFeVariable     *self = NULL;
   int               componentsCount=1;

   /* painfully define a new ParticleFeVariable, methods first */
   self = _PpcFeVariable_DefaultNew( name );

   /** define basics in data structures */
   self->isConstructed = True;
	_FieldVariable_Init( (FieldVariable*)self, context, componentsCount, context->dim, True, NULL, context->communicator, context->fieldVariable_Register, False );
   _FeVariable_Init( (FeVariable* )self, mesh, NULL, NULL, False, NULL, NULL, NULL, False, False );
	_ParticleFeVariable_Init( (ParticleFeVariable*)self, swarm, accumulate );
	_PpcFeVariable_Init( self, ppcMan, tag );

   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*) self );

   return self;

}
Index LiveComponentRegister_IfRegThenAdd( Stg_Component *component ) {
   if( LiveComponentRegister_GetLiveComponentRegister() ) {
      LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), component );
      return 1;
   }
   else
      return 0;
}
void _MaterialPointsSwarm_Init( 
		void*                                 swarm,
		Material*                             material,
		Materials_Register*                   materials_Register )
{
	MaterialPointsSwarm*    self = (MaterialPointsSwarm*)swarm;
	MaterialPoint           particle;
	GlobalParticle          globalParticle;

	self->material           = material;
	self->materials_Register = materials_Register;
	
	self->materialIndexVariable = Swarm_NewScalarVariable( self, (Name)"MaterialIndex", GetOffsetOfMember( particle , materialIndex  ), Variable_DataType_Int ); /* Should be unsigned int */
   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->materialIndexVariable->variable );
   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->materialIndexVariable );

}
void _RateFieldTimeIntegrator_Build( void* rateFieldTimeIntegrator, void* data ) {
   RateFieldTimeIntegrator*  self = (RateFieldTimeIntegrator*) rateFieldTimeIntegrator;
   ExtensionInfo_Index   handle;

   Stg_Component_Build( self->swarm, data, False );
   Stg_Component_Build( self->rateField, data, False );

   handle = ExtensionManager_GetHandle( self->swarm->particleExtensionMgr, (Name)self->name );

   if ( handle == (ExtensionInfo_Index) -1 ) {
      ArithPointer offset;
      handle = ExtensionManager_Add( self->swarm->particleExtensionMgr, (Name)RateFieldTimeIntegrator_Type, self->rateField->fieldComponentCount*sizeof(double)  );

      /* Adding required increment variable */
      offset = (ArithPointer ) ExtensionManager_Get( self->swarm->particleExtensionMgr, NULL, handle );

      /* Add variables for vizualization / analysis purposes */
      self->particleTimeIntegral = Swarm_NewVectorVariable( self->swarm, self->name, offset, Variable_DataType_Double, self->rateField->fieldComponentCount, "STG_AUTONAME"  );
      LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->particleTimeIntegral->variable );
      LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->particleTimeIntegral );

      /* The RateFieldTimeIntegrator class inherits from the TimeIntegrand class - this class needs a 'Variable' to
       * integrate through time. */
      self->variable = self->particleTimeIntegral->variable;
   } else
      Journal_Firewall(False, Journal_Register( Error_Type, (Name)"RateFieldTimeIntegrator"  ),
                       "\n\nError in '%s' - Extension with name %s should not already exists.\n"
                       "An error has occurred.  Please contact developers.", __func__, self->name);


   /* Build parent.  Note that this needs to go last because it assumes that a variable has been set, which only just happens above */
   /* Another example where the build/init/etc phases don't work */

   _TimeIntegrand_Build( self, data );
   Stg_Component_Build( self->particleTimeIntegral, data, False );

}
Exemplo n.º 8
0
void _MeshGenerator_Construct( void* meshGenerator, Stg_ComponentFactory* cf, void* data ) {
	MeshGenerator*		self = (MeshGenerator*)meshGenerator;
	Dictionary*		dict;
	Dictionary_Entry_Value*	meshList;
	Mesh*			mesh;

	assert( self );
	assert( cf );

	/* Rip out the components structure as a dictionary. */
	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, self->name ) );

	/* Set the communicator to a default. */
	MeshGenerator_SetComm( self, MPI_COMM_WORLD );

	/* Read the individual mesh if specified. */
	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, "mesh", Mesh, False, data );
	if( mesh )
		MeshGenerator_AddMesh( self, mesh );

	/* Read the mesh list, if it's there. */
	meshList = Dictionary_Get( dict, "meshes" );
	if( meshList ) {
		unsigned	nMeshes;
		char*		name;
		unsigned	m_i;

		nMeshes = Dictionary_Entry_Value_GetCount( meshList );
		for( m_i = 0; m_i < nMeshes; m_i++ ) {
			Mesh*	mesh;

			name = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( meshList, m_i ) );
			mesh = Stg_ComponentFactory_ConstructByName( cf, name, Mesh, True, data );
			MeshGenerator_AddMesh( self, mesh );
		}
	}

	/* Add to live component register. */
	LiveComponentRegister_Add( cf->LCRegister, (Stg_Component*)self );
}
Exemplo n.º 9
0
void Stg_ComponentFactory_CreateComponents( Stg_ComponentFactory *self ) {
   Dictionary_Entry*                      componentDictEntry           = NULL;
   Dictionary*                            currComponentDict            = NULL;
   Type                                   componentType                = NULL;
   Name                                   componentName                = NULL;
   Stg_Component_DefaultConstructorFunction*  componentConstructorFunction;
   Index                                  component_I;
   Stream*                                stream;
   
   assert( self );
   
   stream = self->infoStream;
   if( self->componentDict ){
      Stream_Indent( stream );

      /* add the contexts to the live component register first (so these get constructed/built/initialised first) */   
      for( component_I = 0; component_I < Dictionary_GetCount( self->componentDict ) ; component_I++ ){
         componentDictEntry = self->componentDict->entryPtr[ component_I ];

         currComponentDict  = Dictionary_Entry_Value_AsDictionary( componentDictEntry->value );
         componentType      = Dictionary_GetString( currComponentDict, "Type" );
         componentName      = componentDictEntry->key;

         if( strcmp( componentType, "DomainContext" ) && 
             strcmp( componentType, "FiniteElementContext" ) &&
             strcmp( componentType, "PICelleratorContext" ) )
            continue;

         if( LiveComponentRegister_Get( self->LCRegister, componentName ) != NULL ) {
            Journal_RPrintf( Journal_Register( Error_Type, self->type ),
               "Error in func %s: Trying to instantiate two components with the name of '%s'\n"
               "Each component's name must be unique.\n",
               __func__, componentName );
            exit(EXIT_FAILURE);
         }

         /* Print Message */
         /* Journal_Printf( stream, "Instantiating %s as %s\n", componentType, componentName ); */
         
         /* Get Default Constructor for this type */
         componentConstructorFunction = Stg_ComponentRegister_AssertGet( 
               Stg_ComponentRegister_Get_ComponentRegister(), componentType, "0" );

         /* Add to register */
         LiveComponentRegister_Add( self->LCRegister, (Stg_Component*)componentConstructorFunction( componentName ) );
      }

      /* now add the rest of the components */   
      for( component_I = 0; component_I < Dictionary_GetCount( self->componentDict ) ; component_I++ ){
         componentDictEntry = self->componentDict->entryPtr[ component_I ];

         currComponentDict  = Dictionary_Entry_Value_AsDictionary( componentDictEntry->value );
         componentType      = Dictionary_GetString( currComponentDict, "Type" );
         componentName      = componentDictEntry->key;

         if( !strcmp( componentType, "DomainContext" ) ||
             !strcmp( componentType, "FiniteElementContext" ) ||
             !strcmp( componentType, "PICelleratorContext" ) )
            continue;

         if( LiveComponentRegister_Get( self->LCRegister, componentName ) != NULL ) {
            Journal_RPrintf( Journal_Register( Error_Type, self->type ),
               "Error in func %s: Trying to instantiate two components with the name of '%s'\n"
               "Each component's name must be unique.\n",
               __func__, componentName );
            exit(EXIT_FAILURE);
         }
         
         Journal_Firewall( strcmp( componentType, "" ), NULL, "In func %s: Component with name '%s' does not have a 'Type' specified.\n"
                                                                              "This is sometimes caused by incorrect or missing 'mergeType' resulting in clobbered input file components.\n"
                                                                              "You may need to add 'mergeType=\"merge\"' to this component. Please check your input file.", __func__, componentName);

         /* Print Message */
         /* Journal_Printf( stream, "Instantiating %s as %s\n", componentType, componentName ); */
         
         /* Get Default Constructor for this type */
         componentConstructorFunction = Stg_ComponentRegister_AssertGet( 
               Stg_ComponentRegister_Get_ComponentRegister(), componentType, "0" );

         /* Add to register */
         LiveComponentRegister_Add( self->LCRegister, (Stg_Component*)componentConstructorFunction( componentName ) );
      }

      Stream_UnIndent( stream );
   }
   else{
      Journal_Printf( stream, "No Stg_Component List found..!\n" );
   }
}
void LiveComponentRegisterSuite_TestGet( LiveComponentRegisterSuiteData* data ) {
   typedef float Triple[3];

   float* array;
   Triple* structArray;

   StgVariable* var;
   StgVariable* vec;
   StgVariable* vecVar[3];
   StgVariable* tempVar = NULL;
   Index length = 10;

   Variable_Register* reg;

   array = Memory_Alloc_Array( float, length, "test" );
   structArray = Memory_Alloc_Array( Triple, length, "test" );

   reg = Variable_Register_New();

   var = StgVariable_NewScalar(
      "Scalar",
		NULL,
      StgVariable_DataType_Float,
      &length,
      NULL,
      (void**)&array,
      reg );

   vec = StgVariable_NewVector(
      "Three",
		NULL,
      StgVariable_DataType_Float,
      3,
      &length,
      NULL,
      (void**)&structArray,
      reg,
      "a",
      "b",
      "c" );

   vecVar[0] = Variable_Register_GetByName( reg, "a" );
   vecVar[1] = Variable_Register_GetByName( reg, "b" );
   vecVar[2] = Variable_Register_GetByName( reg, "c" );

   Variable_Register_BuildAll( reg );

   LiveComponentRegister_Add( data->lcRegister, (Stg_Component*) var );
   pcu_check_true( LiveComponentRegister_IfRegThenAdd( (Stg_Component*) vec ) );
   LiveComponentRegister_Add( data->lcRegister, (Stg_Component*) vecVar[0] );
   LiveComponentRegister_Add( data->lcRegister, (Stg_Component*) vecVar[1] );
   LiveComponentRegister_Add( data->lcRegister, (Stg_Component*) vecVar[2] );

   tempVar = (StgVariable*) LiveComponentRegister_Get( data->lcRegister, (Name)"Scalar" );
   pcu_check_true( tempVar == var );

   tempVar = (StgVariable* ) LiveComponentRegister_Get( LiveComponentRegister_GetLiveComponentRegister(), (Name)"Three" );
   pcu_check_true( tempVar == vec );

   tempVar = (StgVariable* ) LiveComponentRegister_Get( data->lcRegister, (Name)"a" );
   pcu_check_true( tempVar == vecVar[0] );

   tempVar = (StgVariable* ) LiveComponentRegister_Get( data->lcRegister, (Name)"b" );
   pcu_check_true( tempVar == vecVar[1] );

   tempVar = (StgVariable* ) LiveComponentRegister_Get( data->lcRegister, (Name)"c" );
   pcu_check_true( tempVar == vecVar[2] );
}
Exemplo n.º 11
0
/* TODO: Need to find a way to add different communicators for different contexts. */
Stg_ComponentFactory* stgMainConstruct( Dictionary* dictionary, Dictionary* sources, MPI_Comm communicator, void* _context ) {
   Stg_ComponentFactory* cf;
   Dictionary*           componentDict;
   Stg_Component*        component;
   AbstractContext*      context=NULL;
   unsigned              component_I;
   char*                 timeStamp;
   time_t                currTime;
   struct tm*            timeInfo;
   int                   adjustedYear;
   int                   adjustedMonth;
   unsigned              rank;

   MPI_Comm_rank( communicator, &rank );

   currTime = time( NULL );
   timeInfo = localtime( &currTime );

   /* See man localtime() for why to adjust these. */
   adjustedYear = 1900 + timeInfo->tm_year;
   adjustedMonth = 1 + timeInfo->tm_mon;

   Stg_asprintf( &timeStamp, "%.4d.%.2d.%.2d-%.2d.%.2d.%.2d",
      adjustedYear, adjustedMonth, timeInfo->tm_mday,
      timeInfo->tm_hour, timeInfo->tm_min, timeInfo->tm_sec );

   if( ( componentDict = Dictionary_Entry_Value_AsDictionary(
      Dictionary_Get( dictionary, (Dictionary_Entry_Key)"components" ) ) ) == NULL )
      componentDict = Dictionary_New();
   
   CheckDictionaryKeys( componentDict, "Component dictionary must have unique names\n" );
   /* lets go right ahead and delete the component register. */
   /* this is mainly required for the pcu tests which pass through here a number of times
      without calling StGermain_Finalise */
   LiveComponentRegister_Delete();
   cf = Stg_ComponentFactory_New( dictionary, componentDict );

   if( _context ) {
      context = (AbstractContext*)_context;
      context->CF = cf;
      context->dictionary = dictionary;
      context->communicator = communicator;
      context->timeStamp = timeStamp;
      LiveComponentRegister_Add( cf->LCRegister, (Stg_Component*)context );
   }

   /* Instantion phase. */
   Stg_ComponentFactory_CreateComponents( cf );

   /* 
    * Assign the dictionary, componentFactory & the communicator for the contexts.
    * TODO: if different contexts require different communicators, 
    * then StG. components will be required for these, and they should be passed in from the XML 
    * Also, this is a little hacky, as nothing is known about the other 
    * layers of StG or their associated contexts here.
    */
   for( component_I = 0; component_I < LiveComponentRegister_GetCount( cf->LCRegister ); component_I++ ) {
      component = LiveComponentRegister_At( cf->LCRegister, component_I );

      if( Stg_CompareType( component, AbstractContext ) ) { 
         Journal_Firewall(
            dictionary->count,
            Journal_Register( Error_Type, "Error Stream" ), 
            "Error in %s: The dictionary is empty, "
            "meaning no input parameters have been feed into your program. "
            "Perhaps you've forgot to pass any input files ( or command-line arguments ) in.\n",
            __func__ );

         context = (AbstractContext*)component;
         context->dictionary = dictionary;
         context->CF = cf;
         context->timeStamp = timeStamp;
         //context->communicator = communicator;
      }
   }

   /* generate the Flattened xml file last once Scaling has occured */
   if( rank==0 ) stgGenerateFlattenedXML( dictionary, sources, timeStamp );
   
   /* Construction phase. */
   Stg_ComponentFactory_ConstructComponents( cf, NULL );
   
   return cf;
}
void _IntegrationPointsSwarm_Init( 
   void*                   swarm,
   FeMesh*                 mesh, 
   TimeIntegrator*         timeIntegrator,
   WeightsCalculator*      weights,
   IntegrationPointMapper* mapper,
   Materials_Register*     materials_Register,
   Bool                    recalculateWeights )
{
   IntegrationPointsSwarm* self = (IntegrationPointsSwarm*)swarm;
   LocalParticle           localParticle;
   IntegrationPoint        particle;

   self->mesh               = mesh;
   self->timeIntegrator     = timeIntegrator;
   self->weights            = weights;
   self->mapper             = mapper;
   self->materials_Register = materials_Register;

   self->recalculateWeights = recalculateWeights;

   /* Disable checkpointing and reloading of IP swarms - currently they can't be reloaded if the particles
   don't have a global coord. We assume there is no history info on them which means we're happy to re-create
   them from scratch given the position the material points were in when the checkpoint was made as input
   -- PatrickSunter 12 June 2006 */
   self->isSwarmTypeToCheckPointAndReload = False;

   self->weightVariable = Swarm_NewScalarVariable( self, (Name)"Weight", GetOffsetOfMember( particle , weight ), 
      Variable_DataType_Double );

   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->weightVariable );
   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->weightVariable->variable );

   self->localCoordVariable = Swarm_NewVectorVariable( self, (Name)"LocalElCoord", GetOffsetOfMember( localParticle , xi ),
      Variable_DataType_Double, self->dim, "Xi", "Eta", "Zeta" );

   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->localCoordVariable );
   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->localCoordVariable->variable );

   if ( timeIntegrator ) {
      /* Assuming this is called from _IntegrationPointsSwarm_AssignFromXML, it would have always called construct
       * on the mapper which in turn would have constructed any MaterialPointsSwarms with it.
       * The MaterialPointsSwarms would have already appended their update routines to the EP, and hence this
       * ensures that the _IntegrationPointsSwarm_UpdateHook will always be called last */
      TimeIntegrator_InsertAfterFinishEP(
         timeIntegrator,
         (Name) "MaterialPointsSwarm_Update", /* Needs to be after a the material update */
         (Name) "IntegrationPointsSwarm_Update",
         _IntegrationPointsSwarm_UpdateHook,
         self->name,
         self );
   }
   
   /* _Construct calls _Swarm_Init */

   /* Lock down the extension manager.
    * It doesn't make sense for the IntegrationPointsSwarm to allow IntegrationPoints to be extended
    * This means attempts to extend integration points are firewalled to pickup errors.
    * -- Alan 20060506
    */
   ExtensionManager_SetLockDown( self->particleExtensionMgr, True );
}