Ejemplo n.º 1
0
void _RefinedRegionsGeometry_Construct( void* refinedRegionsGeometry, Stg_ComponentFactory *cf, void* data ) {
    RefinedRegionsGeometry*  self   = (RefinedRegionsGeometry*)refinedRegionsGeometry;
    IJK             size;
    int             shift;
    Dimension_Index dim;
    Dimension_Index dim_I;

    self->dictionary =  Dictionary_GetDictionary( cf->componentDict, self->name );

    /* Get Size from Dictionary */
    dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, "dim", 0 );

    size[ I_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, "sizeI", 1 );
    size[ J_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, "sizeJ", 1 );
    size[ K_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, "sizeK", 1 );
    if ( dim == 2 )
        size[ K_AXIS ] = 1;

    /* Shift the size if nessesary */
    shift = Stg_ComponentFactory_GetInt( cf, self->name, "sizeShift", 0 );
    for ( dim_I = I_AXIS ; dim_I < dim ; dim_I++ )
        size[ dim_I ] += shift;

    _Geometry_Init( (Geometry*)self );
    _RefinedRegionsGeometry_Init( self, size );
}
void _AnalyticFeVariable_AssignFromXML( void* analyticFeVariable, Stg_ComponentFactory* cf, void* data ) {
   AnalyticFeVariable* self = (AnalyticFeVariable*)analyticFeVariable;
   Dictionary*         dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
   Name                numericFieldName;
   Name                functionName;
   FeVariable*         numericField = NULL;

   /* 
    * NOTE:
    * This component is a special case where it calls its ancestor's *_AssignFromXML
    * instead of its immediate parent's. This is because we don't want to re-declare 
    * the required FeVariable parameters in this component's XML block.
    */
   _FieldVariable_AssignFromXML( self, cf, data );

   numericFieldName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"NumericField" );
   numericField = (FeVariable*)LiveComponentRegister_Get( cf->LCRegister, numericFieldName );

   if( !numericField ) 
      numericField = Stg_ComponentFactory_ConstructByName( cf, (Name)numericFieldName,
         FeVariable, True, data );

   functionName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"Function" );

   /* 
    * NOTE:
    * The parent's *_Init function needs to be called to initialise
    * FeVariable-specific attributes.
    */
   _FeVariable_Init( (FeVariable*)self, numericField->feMesh, NULL,
      NULL, False, NULL, NULL, NULL, True, False );

   _AnalyticFeVariable_Init( self, functionName, numericField );
}
Ejemplo 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 _ManualParticleLayout_AssignFromXML( void* manualParticleLayout, Stg_ComponentFactory *cf, void* data ) {
	ManualParticleLayout*      self       = (ManualParticleLayout*) manualParticleLayout;
	Dictionary*                dictionary;
	
   _GlobalParticleLayout_AssignFromXML( self, cf, data );

   dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );

   _ManualParticleLayout_Init( self, dictionary );
}
Ejemplo n.º 5
0
Dictionary_Entry_Value* _Stg_ComponentFactory_GetDictionaryValue( void* cf, Name componentName, Dictionary_Entry_Key key, Dictionary_Entry_Value* defaultVal ) {
   Stg_ComponentFactory*       self              = (Stg_ComponentFactory*) cf;
   Dictionary*             componentDict     = NULL;
   Dictionary*             thisComponentDict = NULL;
   Dictionary_Entry_Value* returnVal;
   Bool                    usedDefault       = False;
   Stream*                 errorStream       = Journal_Register( Error_Type, Stg_Component_Type );
   Stream*                 stream            = self->infoStream;

   Journal_Firewall( self != NULL, errorStream, "In func %s: Stg_ComponentFactory is NULL.\n", __func__ );

   Journal_PrintfL( stream, 2, "Getting parameter '%s': ", key );

   /* Get this Stg_Component's Dictionary */
   componentDict = self->componentDict;
   Journal_Firewall( componentDict != NULL, errorStream, 
         "In func %s: Stg_Component Factory's dictionary is NULL.\n", __func__ );
   thisComponentDict = Dictionary_GetDictionary( componentDict, componentName );
   if( thisComponentDict == NULL )
      return defaultVal;

   /* Get Value from dictionary */
   returnVal = Dictionary_Get( thisComponentDict, key );
   if ( !returnVal && defaultVal ) {
      returnVal = Dictionary_GetDefault( thisComponentDict, key, defaultVal );
      usedDefault = True;
   }

   /* Print Stuff */
   if ( usedDefault ) {
      Journal_PrintfL( stream, 2, "Using default value = " );
      if ( Stream_IsPrintableLevel( stream, 2 ) ) 
         Dictionary_Entry_Value_Print( returnVal, stream );
      Journal_PrintfL( stream, 2, "\n" );

      return returnVal;
   }
   else if ( returnVal ) {
      Journal_PrintfL( stream, 2, "Found - Value = " );
      if ( Stream_IsPrintableLevel( stream, 2 ) ) 
         Dictionary_Entry_Value_Print( returnVal, stream );
      Journal_PrintfL( stream, 2, "\n" );
   }
   else 
      Journal_PrintfL( stream, 2, "Not found.\n" );

   return returnVal;
}
Ejemplo n.º 6
0
void _ConvexHull_AssignFromXML( void* convexHull, Stg_ComponentFactory* cf, void* data ) {
	ConvexHull*             self       = (ConvexHull*)convexHull;
	Index                   vertexCount;
	Index                   vertex_I;
	Coord_List              vertexList;
	double*                 coord;
	Dictionary_Entry_Value* optionSet;
	Dictionary_Entry_Value* optionsList;
	Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
	Stream*                 stream     = cf->infoStream;

	
	_Stg_Shape_AssignFromXML( self, cf, data );

	optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"vertices"  );
	Journal_Firewall( optionsList != NULL, 
		Journal_Register( Error_Type, (Name)self->type  ),
		"In func %s: The list 'vertices' specifying the convexHull is NULL.\n", __func__);

	vertexCount = Dictionary_Entry_Value_GetCount(optionsList);
	Journal_Firewall( ( self->dim == 2 && vertexCount < 4 ) || ( self->dim == 3 && vertexCount < 5 ),
		Journal_Register( Error_Type, (Name)self->type  ),
		"In func %s: Sorry, but we got lazy, you can only specify 3 (2D) or 4 (3D) points. " 
		"Please feel free to hassle developers for this feature.\n", __func__);

	/* Allocate space */
	vertexList = Memory_Alloc_Array( Coord , vertexCount, "Vertex Array" );
	memset( vertexList, 0, vertexCount * sizeof(Coord) );
	
	Stream_Indent( stream );
	for ( vertex_I = 0 ; vertex_I < vertexCount ; vertex_I++) { 
		optionSet = Dictionary_Entry_Value_GetElement(optionsList, vertex_I );
		coord = vertexList[vertex_I];

		/* Read Vertex */
		coord[ I_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"x") );
		coord[ J_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"y") );
		
		coord[ K_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"z"));
		optionSet = optionSet->next;
	}
	Stream_UnIndent( stream  );


	_ConvexHull_Init( self, vertexList, vertexCount);
}
void _PeriodicBoundariesManager_AssignFromXML( void* periodicBCsManager, Stg_ComponentFactory* cf, void* data ) {
	PeriodicBoundariesManager*	self = (PeriodicBoundariesManager*)periodicBCsManager;
	Dictionary*						dictionary = NULL;
	Mesh*								mesh = NULL;
	Swarm*							swarm = NULL;
	PICelleratorContext*			context;

	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", PICelleratorContext, False, data );
	if( !context  ) 
		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", PICelleratorContext, True, data  );

	dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
	swarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", Swarm, True, data  );

	_PeriodicBoundariesManager_Init( self, context, mesh, swarm, dictionary );
}
void _LinkedDofInfo_AssignFromXML( void* linkedDofInfo, Stg_ComponentFactory *cf, void* data ){
	LinkedDofInfo*	self = (LinkedDofInfo*)linkedDofInfo;
	Dictionary*		dictionary;
	Mesh*				mesh = NULL;
	DofLayout*		dofLayout = NULL;
	DomainContext*	context;

	dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
	
	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", DomainContext, False, data );
	if( !context  ) 
		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );

	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Mesh", Mesh, True, data  );
	dofLayout = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)DofLayout_Type, DofLayout, True, data  );

	_LinkedDofInfo_Init( self, context, mesh, dofLayout, dictionary ); 
}
Ejemplo n.º 9
0
Stg_Component* _Stg_ComponentFactory_ConstructByKey( 
      void*         cf, 
      Name         parentComponentName, 
      Dictionary_Entry_Key   componentKey,
      Type         type, 
      Bool          isEssential,
      void*          data ) 
{
   Stg_ComponentFactory*   self              = (Stg_ComponentFactory*)cf;
   Dictionary*      thisComponentDict = NULL;
   Dictionary*      componentDict     = NULL;
   Name         componentName, redirect;
   Dictionary_Entry_Value*   componentEntryVal;
   Stream*         errorStream       = Journal_Register( Error_Type, self->type );

   Journal_Firewall( self != NULL, errorStream, "In func %s: Stg_Component is NULL.\n", __func__ );

   /* Get this Stg_Component's Dictionary */
   componentDict = self->componentDict;
   Journal_Firewall( componentDict != NULL, errorStream, 
         "In func %s: Stg_Component Factory's dictionary is NULL.\n", __func__ );
   thisComponentDict = Dictionary_GetDictionary( componentDict, parentComponentName );

   /* Get Dependency's Name */
   componentEntryVal = Dictionary_Get( thisComponentDict, componentKey );
   if ( componentEntryVal == NULL ) {
      Journal_Firewall( !isEssential, errorStream,
            "Stg_Component '%s' cannot find essential component with key '%s'.\n", parentComponentName, componentKey );
      Journal_PrintfL( self->infoStream, 2, "Stg_Component '%s' cannot find non-essential component with key '%s'.\n", parentComponentName, componentKey );
      return NULL;
   }
      
   componentName = Dictionary_Entry_Value_AsString( componentEntryVal );

   /* If we can find the component's name in the root dictionary, use that value instead. */
   if( self->rootDict ) {
      redirect = Dictionary_GetString_WithDefault( self->rootDict, componentName, "" );
      if( strcmp( redirect, "" ) )
         componentName = redirect;
   }

   return self->constructByName( self, componentName, type, isEssential, data );
}
void SwarmOutputSuite_TestSwarmOutput( SwarmOutputSuiteData* data ) {
   int procToWatch = data->nProcs > 1 ? 1 : 0;

   if( data->rank == procToWatch ) {
      Dictionary*                dictionary;
      Dictionary*                componentDict;
      Stg_ComponentFactory*      cf;
      DomainContext*             context;
      char                       input_file[PCU_PATH_MAX];
      Swarm*                     swarm;
      SwarmOutput*               swarmOutput;
      SpaceFillerParticleLayout* particleLayout;

      pcu_filename_input( "testSwarmOutput.xml", input_file );
      cf = stgMainInitFromXML( input_file, data->comm, NULL );
      context = (DomainContext*) LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
      dictionary = context->dictionary;

      Journal_ReadFromDictionary( dictionary );
      stgMainBuildAndInitialise( cf  );

      ContextEP_Append( context, AbstractContext_EP_Dt, SwarmOutputSuite_Dt );
      ContextEP_Append( context, AbstractContext_EP_Step, SwarmOutputSuite_MoveParticles );

      componentDict = Dictionary_GetDictionary( dictionary, "components" );
      assert( componentDict );

      AbstractContext_Dump( context );
      Stg_Component_Execute( context, 0, False );

      particleLayout = (SpaceFillerParticleLayout*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"particleLayout" );
      swarmOutput = (SwarmOutput* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarmOutput" );
      swarm = (Swarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm" );

      pcu_check_true( particleLayout->isConstructed && particleLayout->isBuilt && particleLayout->isInitialised );
      pcu_check_true( swarmOutput->isConstructed && swarmOutput->isBuilt && swarmOutput->isInitialised );
      pcu_check_true( swarm->isConstructed && swarm->isBuilt && swarm->isInitialised  );

      pcu_check_streq( swarm->name, swarmOutput->swarm->name );

      stgMainDestroy( cf );
   }
}
Ejemplo n.º 11
0
void _ShapedMaterial_AssignFromXML( void* shapedMaterial, Stg_ComponentFactory* cf, void* data ) {
	ShapedMaterial*				self = (ShapedMaterial*) shapedMaterial;
	Materials_Register*	Materials_Register;
	PICelleratorContext*	context;
	FieldVariable*       materialIndexField;
	Dictionary*				materialDictionary;

	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", PICelleratorContext, False, data );
	if( !context  ) 
		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", PICelleratorContext, True, data  );

	materialDictionary = Dictionary_GetDictionary( cf->componentDict, self->name );

	/** user must provide a field which represents the shapes, with field values corresponding to current material index */
	/** (this field should be initialised later, so no circular dependency should result)                                */
	materialIndexField =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialIndexField", FieldVariable, True, data   ) ;
	Materials_Register = context->materials_Register;

	_ShapedMaterial_Init( self, context, materialIndexField, materialDictionary, Materials_Register );
}
/*----------------------------------------------------------------------------------------------------------
** Virtual functions
*/
void _LinearSpaceAdaptor_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
  LinearSpaceAdaptor* self = (LinearSpaceAdaptor*)_self;
  Dictionary* dictionary  = Dictionary_GetDictionary( cf->componentDict, self->name );
  Dictionary_Entry_Value* optionsList = NULL;
  Dictionary_Entry_Value* optionSet = NULL;
  linearSpaceAdaptor_Segment* seg = NULL;
  Index segmentCount;
  Index segment_I;
  AbstractContext* context;

  assert( self );
  assert( cf );

  /* Call parent construct. */
  _MeshAdaptor_AssignFromXML( self, cf, data );

  context = (AbstractContext*)Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
  if( !context  )
	 context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data );

  self->loadFromCheckPoint = context->loadFromCheckPoint;

  if( self->loadFromCheckPoint  )
	 return;

  self->minX = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"minX" ) );
  self->maxX = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"maxX" ) );
  self->minY = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"minY" ) );
  self->maxY = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"maxY" ) );
  self->minZ = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"minZ" ) );
  self->maxZ = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"maxZ" ) );

  /* Read mapping functions - X axis*/
  optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"mappingFunctionX" );

  if( optionsList ) {
	 segmentCount = Dictionary_Entry_Value_GetCount(optionsList );
	 self->nSegmentsx = segmentCount;

	 self->tablex = Memory_Alloc_Array( linearSpaceAdaptor_Segment , segmentCount, "mapping table x" );
	 memset( self->tablex, 0, segmentCount * sizeof(linearSpaceAdaptor_Segment) );

	 for ( segment_I = 0 ; segment_I < segmentCount ; segment_I++) { 
		optionSet = Dictionary_Entry_Value_GetElement(optionsList, segment_I );
		seg = &(self->tablex[segment_I]);
		seg->x = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"point" ) );
		seg->y = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"mappedTo" ) );
	 }
  } else {
	 self->nSegmentsx = 0;
  }

  /* Read mapping functions - Y axis*/
  optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"mappingFunctionY" );
	
  if( optionsList ) {
	 segmentCount = Dictionary_Entry_Value_GetCount(optionsList );
	 self->nSegmentsy = segmentCount;

	 self->tabley = Memory_Alloc_Array( linearSpaceAdaptor_Segment , segmentCount, "mapping table y" );
	 memset( self->tabley, 0, segmentCount * sizeof(linearSpaceAdaptor_Segment) );

	 for ( segment_I = 0; segment_I < segmentCount; segment_I++) { 
		optionSet = Dictionary_Entry_Value_GetElement(optionsList, segment_I );
		seg = &(self->tabley[segment_I]);
		seg->x = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"point" ) );
		seg->y = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"mappedTo" ) );
	 }
  } else {
	 self->nSegmentsy = 0;
  }

  /* Read mapping functions - Z axis*/
  optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"mappingFunctionZ" );
	
  if( optionsList && ((DomainContext*)context)->dim==3 ) {
	 segmentCount = Dictionary_Entry_Value_GetCount(optionsList );
	 self->nSegmentsz = segmentCount;

	 self->tablez = Memory_Alloc_Array( linearSpaceAdaptor_Segment , segmentCount, "mapping table z" );
	 memset( self->tablez, 0, segmentCount * sizeof(linearSpaceAdaptor_Segment) );

	 for ( segment_I = 0 ; segment_I < segmentCount ; segment_I++) { 
		optionSet = Dictionary_Entry_Value_GetElement(optionsList, segment_I );
		seg = &(self->tablez[segment_I]);
		seg->x = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"point" ) );
		seg->y = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"mappedTo" ) );
	 }
  } else {
	 self->nSegmentsz = 0;
  }

  _LinearSpaceAdaptor_Init( self );
}
Ejemplo n.º 13
0
int main( int argc, char *argv[] ) {
	int		rank;
	int		procCount;
	int		procToWatch;
	Stream*		stream;
	
	/* Initialise MPI, get world info */
	MPI_Init( &argc, &argv );
	MPI_Comm_size( MPI_COMM_WORLD, &procCount );
	MPI_Comm_rank( MPI_COMM_WORLD, &rank );
	
	BaseFoundation_Init( &argc, &argv );

	RegressionTest_Init( "Base/Automation/Stg_Component" );
	
	BaseIO_Init( &argc, &argv );
	BaseContainer_Init( &argc, &argv );
	BaseAutomation_Init( &argc, &argv );

	stream = Journal_Register( Info_Type, __FILE__ );
	
	if( argc >= 2 ) {
		procToWatch = atoi( argv[1] );
	}
	else {
		procToWatch = 0;
	}
	if( rank == procToWatch ) {
		Stg_ComponentMeta* metaTest;

		XML_IO_Handler* io;
		Dictionary* allDict;
		Dictionary* compDict;

		CompositeVC* vc;
		
		Journal_Printf( stream, "%s\n", Stg_Component_GetMetadata() );

		metaTest = Stg_Component_CreateMeta( "blah", Variable_Type );
		Stg_Class_Print( metaTest, stream );
		Stg_Class_Delete( metaTest );

		allDict = Dictionary_New();
		io = XML_IO_Handler_New();
		IO_Handler_ReadAllFromFile( io, "data/metatest.xml", allDict );
		compDict = Dictionary_GetDictionary( allDict, "components" );
		vc = CompositeVC_DefaultNew( "vc" );	
		
		metaTest = Stg_Component_Validate( vc, CompositeVC_Type, compDict );
		Stg_Class_Print( metaTest, stream );
		Stg_Class_Delete( metaTest );

		Stg_Class_Delete( io );
		Stg_Class_Delete( compDict );
	}

	
	BaseAutomation_Finalise();
	BaseContainer_Finalise();
	BaseIO_Finalise();

	RegressionTest_Finalise();
	
	BaseFoundation_Finalise();

	
	/* Close off MPI */
	MPI_Finalize();
	
	return 0; /* success */
}
Ejemplo n.º 14
0
void _MeshVariable_AssignFromXML( void* meshVariable, Stg_ComponentFactory* cf, void* data ) {
	MeshVariable*		self = (MeshVariable*)meshVariable;
	SizeT					dataOffsets[] = { 0 };
	StgVariable_DataType	dataTypes[] = { 0 };		/* Init value later */
	Index					dataTypeCounts[] = { 1 };
	Dictionary*			componentDict = NULL;
	Dictionary*			thisComponentDict = NULL;
	Name					dataTypeName = NULL;
	Name					rankName = NULL;
	void*					variableRegister = NULL;
	Name*					names = NULL;
	Stream*				error = Journal_Register( Error_Type, (Name)self->type );
	Mesh*					mesh;
	AbstractContext*	context;
	
	assert( self );

	componentDict = cf->componentDict;
	assert( componentDict  );
	thisComponentDict = Dictionary_GetDictionary( componentDict, self->name );
	assert( thisComponentDict );

	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
	if( !context  )
		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, False, data );
	
	/* Grab Registers */
    if(context)
        variableRegister = context->variable_Register;

	/* Construct the mesh. */
	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
	MeshVariable_SetMesh( self, mesh );

	/* Get the topological element we're intereseted in. */
	self->topoDim = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"topologicalDim", 0  );
			
	/* Get Type of Variable */
	dataTypeName = Dictionary_GetString( thisComponentDict, (Dictionary_Entry_Key)"DataType"  );
	if ( !strcasecmp( dataTypeName, "Double" ) )
		dataTypes[0] = StgVariable_DataType_Double;
	else if ( !strcasecmp( dataTypeName, "Float" ) )
		dataTypes[0] = StgVariable_DataType_Float;
	else if ( !strcasecmp( dataTypeName, "Int" ) )
		dataTypes[0] = StgVariable_DataType_Int;
	else if ( !strcasecmp( dataTypeName, "Char" ) )
		dataTypes[0] = StgVariable_DataType_Char;
	else if ( !strcasecmp( dataTypeName, "Short" ) )
		dataTypes[0] = StgVariable_DataType_Short;
	else 
		Journal_Firewall( False, error, "Variable '%s' cannot understand data type '%s'\n", self->name, dataTypeName );

	/* Get Rank of Variable - i.e. Scalar or Vector */
	rankName = Dictionary_GetString( thisComponentDict, (Dictionary_Entry_Key)"Rank"  );
	if( !strcasecmp( rankName, "Scalar" ) ){
		dataTypeCounts[0] = 1;
	}
	else if ( !strcasecmp( rankName, "Vector" ) ){
		Dictionary_Entry_Value* list;
		Index                   nameCount = 0;

		dataTypeCounts[0] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"VectorComponentCount", nameCount  );

		/* Get Names from list */
		if (( list = Dictionary_Get( thisComponentDict, (Dictionary_Entry_Key)"names" ) )) {
			Index entry_I;

			nameCount = Dictionary_Entry_Value_GetCount( list  );
			names = Memory_Alloc_Array( Name, nameCount, "Variable Names" );

			for ( entry_I = 0 ; entry_I < nameCount ; entry_I++ )
				names[ entry_I ] = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement(list, entry_I ) );

            Journal_Firewall( nameCount >= dataTypeCounts[0], error, "Variable '%s' has too few names in list for %d vector components.\n", self->name, dataTypeCounts[0] );
		}

	}
	else
		Journal_Firewall( False, error, "Variable '%s' cannot understand rank '%s'\n", self->name, rankName );

	_StgVariable_Init(
                  (StgVariable*)self,
                           context,
                                 1,
                       dataOffsets,
                         dataTypes,
                    dataTypeCounts,
                             names,
                                 0,
                              NULL,
    _MeshVariable_GetMeshArraySize,
           (void**)&self->arrayPtr,
                              True,
                  variableRegister );

	/* Clean Up */
	if (names)
		Memory_Free(names);
}