void LiveComponentRegister_DeleteAll( void* liveComponentRegister ) {
   LiveComponentRegister* self = (LiveComponentRegister*)liveComponentRegister;
   Stg_Component*         component;

   while (LiveComponentRegister_GetCount( self ) > 0){
      /* delete from back of list forward */
      component = LiveComponentRegister_At( self, LiveComponentRegister_GetCount( self ) - 1 );
      LiveComponentRegister_RemoveOneComponentsEntry( self, component->name );
      Stg_Class_Delete( component );
   }
}
Пример #2
0
void Stg_ComponentFactory_DestroyComponents( Stg_ComponentFactory* self, void* data ) {
   Stg_Component*                         component                    = NULL;
   Index                                  component_I;
   Stream*                                stream;
   
   assert( self );
   
   stream = self->infoStream;

   if( self->componentDict ){
      Journal_Printf( stream, "\nDestroying Stg_Components from the live-component register\n\n" );
      Stream_Indent( stream );
   
      for( component_I = 0; component_I < LiveComponentRegister_GetCount( self->LCRegister ); component_I++ ){
         /* Grab component from register */
         component = LiveComponentRegister_At( self->LCRegister, component_I );
         if( component && !component->isDestroyed ){
            Stg_Component_Destroy( component, data, True );
         }
      }
      Stream_UnIndent( stream );
   }
   else{
      Journal_Printf( stream, "No Stg_ComponentList found..!\n" );
   }
}
Пример #3
0
void _DomainContext_AssignFromXML( void* context, Stg_ComponentFactory* cf, void* data ) {
   DomainContext* self = (DomainContext*)context;
   Dictionary     *contextDict = NULL;

   _AbstractContext_AssignFromXML( context, cf, data );

   self->dim          = Dictionary_GetUnsignedInt_WithDefault( self->dictionary, "dim", 2 );
   self->verticalAxis = Dictionary_GetUnsignedInt_WithDefault( self->dictionary, "VerticalAxis", 1 );

   /* try grab the scaling component and put it on the context 
    * check for the contextDict first as ConstructByKey NEEDS the conextDict 
    * and in units tests the contextDict sometime doesn't exist */
   contextDict = Dictionary_GetDictionary( cf->componentDict, self->name );
   if( contextDict ) {
      self->scaling = Stg_ComponentFactory_ConstructByKey(
         cf,
         self->name, 
         (Dictionary_Entry_Key)"Scaling",
         Scaling,
         False,
         data );
   }
   if( !self->scaling ) {
      self->scaling = Stg_ComponentFactory_ConstructByName(
         cf,
         (Name)"default_scaling", 
         Scaling, False, data ); 
   }

       /* The following is for backward compatiblity with old (GALE) xml files. */
   {
      /* Post change 1d3dc4e00549 in this repositroy, the old style of DofLayout 
       * XML definition was illegal. This change allows for the old style.
       *
       * Here we build all 'MeshVariable' components first.
       *
       * This is a hack, selective construction of general component over other is
       * a weakness to the object model and should be avoided. This section should
       * be removed in future and xml files updated in accordance with change 1d3dc4e00549  
       */

      Stg_Component *component=NULL;
      Index         component_I;
      for( component_I = 0; component_I < LiveComponentRegister_GetCount( cf->LCRegister ); component_I++ ){
         /* Grab component from register */
         component = LiveComponentRegister_At( cf->LCRegister, component_I ); 
         /* if not a "MeshVariable" do nothing */
         if( strcmp( component->type, MeshVariable_Type ) ) continue;

         if( component && !component->isConstructed ){
            Journal_Printf( cf->infoStream, "Constructing %s as %s\n", component->type, component->name );
            Stg_Component_AssignFromXML( component, cf, data, True );
         }

      }
   }

   _DomainContext_Init( self );
}
void LiveComponentRegister_InitialiseAll( void* liveComponentRegister, void* data ) {
   LiveComponentRegister* self = (LiveComponentRegister*)liveComponentRegister;
   Stg_Component*         component;
   Index                  index;
   Index                  count = LiveComponentRegister_GetCount( self );
   
   for( index = 0; index < count; index++ ) {
      component = LiveComponentRegister_At( self, index );
      Stg_Component_Initialise( component, data, False );
   }
}
void LiveComponentRegister_DestroyAll( void* lcReg ) {
   LiveComponentRegister* self = (LiveComponentRegister*)lcReg;
   Stg_Component*         component;
   unsigned               index;
   
   /* 
    * Note, if a Component is already Destroyed the, isDestroyed flag should protect the
    * code from running the _Destroy function again.
    */
   for( index = 0; index < LiveComponentRegister_GetCount( self ); index++ ) {
      component = LiveComponentRegister_At( self, index );
      Stg_Component_Destroy( component, NULL, False );
   }
}
Пример #6
0
void stgMainLoop( Stg_ComponentFactory* cf ) {
   /* Run (Solve) phase. */

   /* 
    * Do this by running the contexts, 
    * which manage the entry points which call the _Execute() funcs for the other components.
    */
   unsigned component_i;
   Stg_Component* component;
   AbstractContext* context;
   
   for( component_i = 0; component_i < LiveComponentRegister_GetCount( cf->LCRegister ); component_i++ ) {
      component = LiveComponentRegister_At( cf->LCRegister, component_i );
      if( Stg_CompareType( component, AbstractContext ) ) { 
         context = (AbstractContext*)component;
         Stg_Component_Execute( context, 0, True );
      }
   }
}
Пример #7
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;
}