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 _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 );

}
void _DruckerPrager_Extra_Init(
    DruckerPrager_Extra*                                     self,
    int                                                pressure_id,
    int                                                velocityGradients_id,
    double                                             minimumYieldStress,
    double                                             frictionCoefficient,
    double                                             frictionCoefficientAfterSoftening )
{
    MaterialPointsSwarm*      materialPointsSwarm;
    DruckerPrager_Extra_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_Extra_Type );

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

        particleExt = (DruckerPrager_Extra_Particle*)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)"DruckerPrager_ExtraTensileFailure", (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 );

        self->fullySoftened = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"FullySoftened", (ArithPointer) &particleExt->fullySoftened - (ArithPointer) &materialPoint, Variable_DataType_Int );
        LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->fullySoftened->variable );
        LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->fullySoftened );

        self->slipRate = Swarm_NewScalarVariable( materialPointsSwarm, (Name)"SlipRate", (ArithPointer) &particleExt->slipRate - (ArithPointer) &materialPoint, Variable_DataType_Double  );
        LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->slipRate->variable );
        LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->slipRate );

        /* slip vector gives the orientation of the failure plane */
        self->slip = Swarm_NewVectorVariable( materialPointsSwarm, (Name)"SlipVector", (ArithPointer) &particleExt->slip - (ArithPointer) &materialPoint,
                                              Variable_DataType_Double,
                                              dim,
                                              "SlipVectorX",
                                              "SlipVectorY",
                                              "SlipVectorZ" );
        LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->slip->variable );
        LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->slip );

        self->plasticStrainRate = Swarm_NewScalarVariable(
                                      materialPointsSwarm,
                                      (Name)"PlasticStrainRate",
                                      (ArithPointer) &particleExt->plasticStrainRate - (ArithPointer) &materialPoint,
                                      Variable_DataType_Double );
        LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->plasticStrainRate->variable );
        LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->plasticStrainRate );

        self->backgroundStrainRate = Swarm_NewScalarVariable(
                                         materialPointsSwarm,
                                         (Name)"BackgroundStrainRate",
                                         (ArithPointer) &particleExt->backgroundStrainRate - (ArithPointer) &materialPoint,
                                         Variable_DataType_Double );
        LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->backgroundStrainRate->variable );
        LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->backgroundStrainRate );


    } else {

        Name var_name = Stg_Object_AppendSuffix( materialPointsSwarm, (Name)"DruckerPrager_ExtraTensileFailure"  );
        self->tensileFailure = SwarmVariable_Register_GetByName( materialPointsSwarm->swarmVariable_Register, var_name );

        var_name = Stg_Object_AppendSuffix( materialPointsSwarm, (Name)"FullySoftened"  );
        self->fullySoftened = SwarmVariable_Register_GetByName( materialPointsSwarm->swarmVariable_Register, var_name );
        Memory_Free( var_name );
        assert( self->fullySoftened );

        var_name = Stg_Object_AppendSuffix( materialPointsSwarm, (Name)"SlipRate"  );
        self->slipRate = SwarmVariable_Register_GetByName( materialPointsSwarm->swarmVariable_Register, var_name );
        Memory_Free( var_name );
        assert( self->slipRate );

        var_name = Stg_Object_AppendSuffix( materialPointsSwarm, (Name)"SlipVector"  );
        self->slip = SwarmVariable_Register_GetByName( materialPointsSwarm->swarmVariable_Register, var_name );
        Memory_Free( var_name );
        assert( self->slip );

        var_name = Stg_Object_AppendSuffix( materialPointsSwarm, (Name)"PlasticStrainRate"  );
        self->plasticStrainRate = SwarmVariable_Register_GetByName( materialPointsSwarm->swarmVariable_Register, var_name );
        Memory_Free( var_name );
        assert( self->plasticStrainRate );

        var_name = Stg_Object_AppendSuffix( materialPointsSwarm, (Name)"BackgroundStrainRate"  );
        self->backgroundStrainRate = SwarmVariable_Register_GetByName( materialPointsSwarm->swarmVariable_Register, var_name );
        Memory_Free( var_name );
        assert( self->backgroundStrainRate );

    }

    self->curFrictionCoef = 0.0;

}
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 );
}