コード例 #1
0
void _RSGenerator_AssignFromXML( void* meshGenerator, Stg_ComponentFactory* cf, void* data )
{
   RSGenerator*			self 		= (RSGenerator*)meshGenerator;
   FiniteElementContext*	context 	= Stg_ComponentFactory_ConstructByName( cf, (Name)"context", FiniteElementContext, True, NULL  );
   Dictionary*			dict		= Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name ) );
   Dictionary_Entry_Value	*minList, *maxList, *tmp;
   char*			rootKey;
   unsigned			d_i;
   double 			maxVal;

   _CartesianGenerator_AssignFromXML( meshGenerator, cf, data );

   // mesh min/max coords are written to file from the mesh->min/maxGlobalCoord field. these differ from the min/max
   // coords as defined in the RSGenerator->min/maxCrd (these are in r-theta-phi, not x-y-z), so if we're restarting
   // we need to over-ride the coords from the hdf5 mesh file with those from the xml (assuming they don't differ
   // between runs...
   if( self->nDims > 2 ) {
      if( context->loadFromCheckPoint ) {
         minList = Dictionary_Get( dict, (Dictionary_Entry_Key)"minCoord" );
         maxList = Dictionary_Get( dict, (Dictionary_Entry_Key)"maxCoord" );
         if( minList && maxList ) {
                assert( Dictionary_Entry_Value_GetCount( minList ) >= self->nDims );
                assert( Dictionary_Entry_Value_GetCount( maxList ) >= self->nDims  );
                for( d_i = 0; d_i < self->nDims; d_i++ ) {
                   tmp = Dictionary_Entry_Value_GetElement( minList, d_i );
                   rootKey = Dictionary_Entry_Value_AsString( tmp );

                   if( !Stg_StringIsNumeric( (char*)rootKey ) )
                      tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
                   self->crdMin[d_i] = Dictionary_Entry_Value_AsDouble( tmp );

                   tmp = Dictionary_Entry_Value_GetElement( maxList, d_i );
                   rootKey = Dictionary_Entry_Value_AsString( tmp );

                   if( !Stg_StringIsNumeric( (char*)rootKey ) )
                      tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
                   self->crdMax[d_i] = Dictionary_Entry_Value_AsDouble( tmp );
                   /* test to ensure provided domain is valid */
                   maxVal = (abs(self->crdMax[d_i]) > abs(self->crdMin[d_i])) ? abs(self->crdMax[d_i]) : abs(self->crdMin[d_i]);
                   if( maxVal == 0 ) maxVal = 1;  /* if maxVal is zero, then both numbers must be zero, set to one as next test will fail */
                   Journal_Firewall( ( ( (self->crdMax[d_i] - self->crdMin[d_i])/maxVal) > 1E-10 || d_i==J_AXIS), global_error_stream,
                     "\n\nError in %s for %s '%s'\n\n"
                     "Dimension of domain (min = %f, max = %f) for component number %u is not valid.\n\n",
                     __func__, self->type, self->name, self->crdMin[d_i], self->crdMax[d_i], d_i );
                }
         }
      }
      // phi = (pi/2, pi)
      Journal_Firewall( !(fabs(self->crdMin[2] -self->crdMax[2])>=179.99 || self->crdMax[2] < self->crdMin[2]),
         global_error_stream, "\nError in %s: Phi definition is wrong. Ensure minZ < maxZ & abs(minZ-maxZ)<180\n", __func__);
   }
   Journal_Firewall( self->nDims==3, global_error_stream,
        "Error in %s: Must have 3 dimensions for component %s\n", __func__, self->name );
   // check domain size is valid
   Journal_Firewall( !(self->crdMin[0] <= 0 || self->crdMax[0] < self->crdMin[0]), global_error_stream,
        "Error in %s: Radius definition is wrong. Ensure maxX > minX & minX > 0\n", __func__ );

   Journal_Firewall(!( fabs(self->crdMin[1]-self->crdMax[1]) >= 179.99 || self->crdMax[1] < self->crdMin[1] ),
         global_error_stream, "Error in %s: Theta definition is wrong. Ensure minY < maxY && abs(minY-maxY) < 180\n", __func__ );
}
コード例 #2
0
void _Ppc_Switch_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
  Ppc_Switch* self = (Ppc_Switch*)_self;
  Dictionary*	theDictionary = NULL;
  Dictionary_Entry_Value* caseEntry = NULL;
  Dictionary_Entry_Value* tagList = NULL;
  Index case_I;
  char* ppcName;
  
  /* Construct parent */
  _Ppc_AssignFromXML( self, cf, data );
  
  /* The dictionary */ 
  theDictionary = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name ) );
  
  /* Read the properties list */	
  tagList = Dictionary_Get( theDictionary, (Dictionary_Entry_Key)"CaseList" );
  assert( tagList );
  self->caseCount = Dictionary_Entry_Value_GetCount( tagList );
  self->caseList = Memory_Alloc_Array( Ppc_Switch_Case, self->caseCount, "Ppc_Switch_caseList" );
  
  for( case_I = 0; case_I < self->caseCount; case_I++ ){
	 caseEntry = Dictionary_Entry_Value_GetElement( tagList, case_I );
	 /* get case value */
	 self->caseList[case_I].constant = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( caseEntry, (Dictionary_Entry_Key)"Case") );
	 /* get ppc associated with the case*/
	 ppcName = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetMember( caseEntry, (Dictionary_Entry_Key)"Value") );
	 self->caseList[case_I].valueTag = PpcManager_GetPpcByName( self->manager, cf, (Name)ppcName );
  }	
  
  /* Init */
  _Ppc_Switch_Init( 
     self,
	  Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"Interpolate", "" ),
	  PpcManager_GetPpcFromDict( self->manager, cf, self->name, (Dictionary_Entry_Key)"Field", "" ) );
}
コード例 #3
0
void _RefinedRegionsGeometry_Init( RefinedRegionsGeometry* self, IJK size ) {
    Dimension_Index		dim_I;
    Dictionary_Entry_Value*	regionsList = NULL;

    /* General and Virtual info should already be set */

    /* RefinedRegionsGeometry info */
    self->isConstructed = False;

    self->min[ I_AXIS ] = Dictionary_GetDouble_WithDefault( self->dictionary, "minX", 0.0f );
    self->min[ J_AXIS ] = Dictionary_GetDouble_WithDefault( self->dictionary, "minY", 0.0f );
    self->min[ K_AXIS ] = Dictionary_GetDouble_WithDefault( self->dictionary, "minZ", 0.0f );

    self->max[ I_AXIS ] = Dictionary_GetDouble_WithDefault( self->dictionary, "maxX", 1.0f );
    self->max[ J_AXIS ] = Dictionary_GetDouble_WithDefault( self->dictionary, "maxY", 1.0f );
    self->max[ K_AXIS ] = Dictionary_GetDouble_WithDefault( self->dictionary, "maxZ", 1.0f );

    if ( size ) {
        memcpy( self->countPerDim, size, sizeof(IJK) );
    }
    else {
        self->countPerDim[ I_AXIS ] = Dictionary_GetUnsignedInt_WithDefault( self->dictionary, "meshSizeI", 2 );
        self->countPerDim[ J_AXIS ] = Dictionary_GetUnsignedInt_WithDefault( self->dictionary, "meshSizeJ", 2 );
        self->countPerDim[ K_AXIS ] = Dictionary_GetUnsignedInt_WithDefault( self->dictionary, "meshSizeK", 2 );
    }

    for ( dim_I = 0; dim_I < 3; dim_I++ ) {
        self->refinedRegionDeltas[dim_I] = 4;
    }

    /* Now Read in the refined regions */
    regionsList = Dictionary_Get( self->dictionary, "RefinedRegions" );
    if ( regionsList ) {
        Index				entryCount = Dictionary_Entry_Value_GetCount( regionsList );
        Index				entry_I = 0;
        Dictionary_Entry_Value*		regionEntry;
        Dictionary*			regionDict;
        Dimension_Index			dim = 0;
        double				regionStart = 0;
        double				regionEnd = 0;
        unsigned int			refinementFactor = 1;

        for( entry_I = 0; entry_I < entryCount; entry_I++ ) {
            regionEntry = Dictionary_Entry_Value_GetElement( regionsList, entry_I );
            regionDict = Dictionary_Entry_Value_AsDictionary( regionEntry );
            dim = Dictionary_GetUnsignedInt_WithDefault( regionDict, "dim", 0 );
            regionStart = Dictionary_GetDouble_WithDefault( regionDict, "regionStart", 0.0 );
            regionEnd = Dictionary_GetDouble_WithDefault( regionDict, "regionEnd", 1.0 );
            refinementFactor = Dictionary_GetUnsignedInt_WithDefault( regionDict, "refinementFactor", 2 );
            _RefinedRegionsGeometry_AddRefinedRegion( self, dim, regionStart, regionEnd, refinementFactor );
        }
    }

    self->pointCount = self->countPerDim[I_AXIS] * self->countPerDim[J_AXIS] *
                       self->countPerDim[K_AXIS];

    assert( self->pointCount );

}
コード例 #4
0
Stg_Component* _Stg_ComponentFactory_PluginConstructByKey( 
   void*                  cf, 
   void*                  codelet, 
   Dictionary_Entry_Key   componentKey,
   Type                  type, 
   Bool                  isEssential,
   void*                  data ) 
{
   Stg_ComponentFactory*   self = (Stg_ComponentFactory*)cf;
   Stg_Component*            plugin = (Stg_Component*)codelet;
   Dictionary*               thisPluginDict = NULL;
   Dictionary*               pluginDict = (Dictionary*)Dictionary_Get( self->rootDict, "plugins" );
   Name                     componentName, redirect, pluginType;
   Dictionary_Entry_Value*   componentEntryVal;
   Index                     pluginIndex;
   Stream*                  errorStream = Journal_Register( Error_Type, self->type );

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

   /* Get this plugins Dictionary */
   for( pluginIndex = 0; pluginIndex < Dictionary_Entry_Value_GetCount( (Dictionary_Entry_Value*)pluginDict ); pluginIndex++ ) {
      thisPluginDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Entry_Value_GetElement( (Dictionary_Entry_Value*)pluginDict, pluginIndex ) );
      pluginType = StG_Strdup( Dictionary_GetString( thisPluginDict, "Type" ) );

      if( !strcmp( plugin->type, pluginType ) ){
         Memory_Free( pluginType );
         break;
      }
      Memory_Free( pluginType );
   }
   
   /* Get Dependency's Name */
   componentEntryVal = Dictionary_Get( thisPluginDict, componentKey );
   if ( componentEntryVal == NULL ) {
      Journal_Firewall( !isEssential, errorStream,
            "plugin '%s' cannot find essential component with key '%s'.\n", plugin->type, componentKey );
      Journal_PrintfL( self->infoStream, 2, "plugin '%s' cannot find non-essential component with key '%s'.\n", plugin->type, 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 );
}
コード例 #5
0
ファイル: SurfaceAdaptor.c プロジェクト: bmi-forum/bmi-pyre
void _SurfaceAdaptor_Construct( void* adaptor, Stg_ComponentFactory* cf, void* data ) {
	SurfaceAdaptor*	self = (SurfaceAdaptor*)adaptor;
	Dictionary*	dict;
	char*		surfaceType;

	assert( self );
	assert( cf );

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

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

	/* What kind of surface do we want? */
	surfaceType = Stg_ComponentFactory_GetString( cf, self->name, "surfaceType", "" );
	if( !strcmp( surfaceType, "wedge" ) ) {
		self->surfaceType = SurfaceAdaptor_SurfaceType_Wedge;
		self->info.wedge.offs = Stg_ComponentFactory_GetDouble( cf, self->name, "offset", 0.0 );
		self->info.wedge.grad = Stg_ComponentFactory_GetDouble( cf, self->name, "gradient", 0.5 );
	}
	else if( !strcmp( surfaceType, "sine" ) || !strcmp( surfaceType, "cosine" ) ) {
		Dictionary_Entry_Value*	originList;

		if( !strcmp( surfaceType, "sine" ) )
			self->surfaceType = SurfaceAdaptor_SurfaceType_Sine;
		else
			self->surfaceType = SurfaceAdaptor_SurfaceType_Cosine;

		originList = Dictionary_Get( dict, "origin" );
		if( originList ) {
			unsigned	nDims;
			unsigned	d_i;

			nDims = Dictionary_Entry_Value_GetCount( originList );
			for( d_i = 0; d_i < nDims; d_i++ ) {
				Dictionary_Entry_Value*	val;

				val = Dictionary_Entry_Value_GetElement( originList, d_i );
				self->info.trig.origin[d_i] = Dictionary_Entry_Value_AsDouble( val );
			}
		}
		else
			memset( self->info.trig.origin, 0, sizeof(double) * 2 );

		self->info.trig.amp = Stg_ComponentFactory_GetDouble( cf, self->name, "amplitude", 1.0 );
		self->info.trig.freq = Stg_ComponentFactory_GetDouble( cf, self->name, "frequency", 1.0 );
	}
	else
		_SurfaceAdaptor_Init( self );
}
コード例 #6
0
Dictionary_Entry_Value* _DictionaryUtils_GetRecursive( Dictionary* dict, char* str ){
   char* strPoint = strchr( str, '.' );
   if(strPoint){
      Dictionary_Entry_Value* entryVal=NULL;
      /* Create the struct and member strings from the source. */
      char* structString = StG_Strdup( str );
      char* strPointNew = strchr( structString, '.' );
      *strPointNew = 0;
      char* memberString = strPointNew + 1;
      Dictionary_Entry_Value* subDict = Dictionary_Get( dict, structString );
      if( subDict ) entryVal = _DictionaryUtils_GetRecursive( Dictionary_Entry_Value_AsDictionary(subDict), memberString );
      Memory_Free( structString );
      return entryVal;
   } else {
      return Dictionary_Get( dict, str );
   }
}
コード例 #7
0
void _Ppc_a_Vector_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
	Ppc_a_Vector* self = (Ppc_a_Vector*)_self;
	Dictionary*	theDictionary;

	/* Construct parent */
	_Ppc_AssignFromXML( self, cf, data );

	/* The dictionary */ 
	theDictionary = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name )  );

   _Ppc_a_Vector_Init( 
      self, 
      PpcManager_GetPpcFromDict( self->manager, cf, self->name, (Dictionary_Entry_Key)"Alpha", "" ), 
      PpcManager_GetPpcFromDict( self->manager, cf, self->name, (Dictionary_Entry_Key)"Vector", "" ), 
      Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"vi", 0.0 ),
      Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"vj", 1.0 ),
      Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"vk", 0.0 ) );
}
コード例 #8
0
Dictionary* Codelet_GetPluginDictionary( void* codelet, Dictionary* rootDict ) {
   Codelet*                self = (Codelet*)codelet;
   Dictionary_Entry_Value* pluginsDEV = Dictionary_Get( rootDict, "plugins" );
   Dictionary*             pluginDict;
   unsigned                pluginIndex;
   Name                    pluginType;
   
   for( pluginIndex = 0; pluginIndex < Dictionary_Entry_Value_GetCount( pluginsDEV ); pluginIndex++ ) {
      pluginDict = Dictionary_Entry_Value_AsDictionary(
         Dictionary_Entry_Value_GetElement( pluginsDEV, pluginIndex ) );

      pluginType = Dictionary_GetString( pluginDict, "Type" );

      if( !strcmp( self->type, pluginType ) )
         return pluginDict;   
   }

   return NULL;
}
コード例 #9
0
void _ManualParticleLayout_InitialiseParticle( 
		void* manualParticleLayout, 
		void* _swarm, 
		Particle_Index newParticle_I,
		void* _particle )
{
	ManualParticleLayout*       self                    = (ManualParticleLayout*)manualParticleLayout;
	Dictionary_Entry_Value*     manualParticlePositions = NULL;
	Dictionary_Entry_Value*     particlePositionEntry   = NULL;
	Dictionary*                 particlePositionDict    = NULL;
	GlobalParticle*             particle                = (GlobalParticle*)_particle;

	manualParticlePositions = Dictionary_Get( self->dictionary, (Dictionary_Entry_Key)"manualParticlePositions"  );
	particlePositionEntry = Dictionary_Entry_Value_GetElement( manualParticlePositions, newParticle_I );
	particlePositionDict = Dictionary_Entry_Value_AsDictionary( particlePositionEntry );
	particle->coord[I_AXIS] = Dictionary_GetDouble_WithDefault( particlePositionDict, (Dictionary_Entry_Key)"x", 0.0  );
	particle->coord[J_AXIS] = Dictionary_GetDouble_WithDefault( particlePositionDict, (Dictionary_Entry_Key)"y", 0.0  );
	particle->coord[K_AXIS] = Dictionary_GetDouble_WithDefault( particlePositionDict, (Dictionary_Entry_Key)"z", 0.0  );
}
コード例 #10
0
ファイル: MeshGenerator.c プロジェクト: bmi-forum/bmi-pyre
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 );
}
コード例 #11
0
void _MeshGenerator_AssignFromXML( void* meshGenerator, Stg_ComponentFactory* cf, void* data ) {
	MeshGenerator*		self = (MeshGenerator*)meshGenerator;
	Dictionary*		dict;
	unsigned		nDims;
	Dictionary_Entry_Value*	meshList;
	Dictionary_Entry_Value	*enabledDimsList, *enabledIncList;
	Mesh*			mesh;
	Bool                    partitioned;

	assert( self );
	assert( cf );

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

	/* Set the communicator to a default. */
	partitioned = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"partitioned", 1  );
	if( partitioned ) {
		MeshGenerator_SetMPIComm( self, MPI_COMM_WORLD );
	}
	else {
		MeshGenerator_SetMPIComm( self, MPI_COMM_SELF );
	}

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

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

	/* Read the mesh list, if it's there. */
	meshList = Dictionary_Get( dict, (Dictionary_Entry_Key)"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)name, Mesh, True, data  );
			MeshGenerator_AddMesh( self, mesh );
		}
	}

	/* Read dimensions and state. */
	nDims = Stg_ComponentFactory_GetUnsignedInt( cf, self->name,  (Dictionary_Entry_Key)"dim", 2 );
	nDims = Stg_ComponentFactory_GetUnsignedInt( cf, self->name,  (Dictionary_Entry_Key)"dims", nDims );
	MeshGenerator_SetDimSize( self, nDims );
	enabledDimsList = Dictionary_Get( dict, (Dictionary_Entry_Key)"enabledDims"  );
	enabledIncList = Dictionary_Get( dict, (Dictionary_Entry_Key)"enabledIncidence"  );

    /* Clear dims/incidence flags */
    unsigned    d_i;
    memset( self->enabledDims, 0, (nDims + 1) * sizeof(Bool) );
    for( d_i = 0; d_i <= nDims; d_i++ )
        memset( self->enabledInc[d_i], 0, (nDims + 1) * sizeof(Bool) );

    if( enabledDimsList ) {
        unsigned    dim;
        unsigned    nEnabledDims;
        nEnabledDims = Dictionary_Entry_Value_GetCount( enabledDimsList );
        for( d_i = 0; d_i < nEnabledDims; d_i++ ) {
            dim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledDimsList, d_i ) );
            if (dim > nDims)
                Journal_Printf(Mesh_Warning, "Warning - in %s: *** Skipping out of range dimension: %d\n", __func__, dim);
            else
                MeshGenerator_SetDimState( self, dim, True );
        }
    }
    else
    {
        /* Default to all dimensions enabled */
        for( d_i = 0; d_i < nDims + 1; d_i++ ) 
            MeshGenerator_SetDimState( self, d_i, True );
    }

    if( enabledIncList ) {
        unsigned    nEnabledInc;
        unsigned    fromDim, toDim;
        nEnabledInc = Dictionary_Entry_Value_GetCount( enabledIncList );
        assert( nEnabledInc % 2 == 0 );
        for( d_i = 0; d_i < nEnabledInc; d_i += 2 ) {
            fromDim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledIncList, d_i ) );
            toDim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledIncList, d_i + 1 ) );
            if (fromDim > nDims || toDim > nDims) 
                Journal_Printf( Mesh_Warning, "Warning - in %s: *** Skipping out of range incidence: %d to %d\n", 
                            __func__ , fromDim, toDim);
            else
                MeshGenerator_SetIncidenceState( self, fromDim, toDim, True );
        }
    }
    else
    {
        /* Default incidence setup 0->1,2,3  1->0,2  2->0,1  3->0,3 */
        MeshGenerator_SetIncidenceState( self, 0, 0, True );
        for( d_i = 1; d_i <= nDims; d_i ++ ) {
            MeshGenerator_SetIncidenceState( self, 0, d_i, True );
            MeshGenerator_SetIncidenceState( self, d_i, 0, True );
        }
        if (nDims == 2) {
            MeshGenerator_SetIncidenceState( self, 1, 2, True );
            MeshGenerator_SetIncidenceState( self, 2, 1, True );
            MeshGenerator_SetIncidenceState( self, 2, 2, True );
        }
        if( nDims == 3 )
           MeshGenerator_SetIncidenceState( self, 3, 3, True );
    }
}
コード例 #12
0
void _GALEDivergenceForce_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf, void* data ) {
	GALEDivergenceForce*          self             = (GALEDivergenceForce*)forceTerm;
	Dictionary*		dict;
        Stg_Shape* domainShape=NULL;
        FeMesh* geometryMesh=NULL;
        GALEStressBC_Entry force;
        char *type;

	/* Construct Parent */
	_ForceTerm_AssignFromXML( self, cf, data );

	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, self->name ) );
	domainShape =  Stg_ComponentFactory_ConstructByKey( cf, self->name, "DomainShape", Stg_Shape, True, data ) ;
        type = Stg_ComponentFactory_GetString( cf, self->name, "force_type", "" );

        if(!strcasecmp(type,"double") || !strcasecmp(type,"float"))
          {
            force.type = GALEStressBC_Double;
            force.DoubleValue = Stg_ComponentFactory_GetDouble( cf, self->name, "force_value", 0.0 );
          }
        else if(!strcasecmp(type,"func"))
          {
            char *funcName = Stg_ComponentFactory_GetString( cf, self->name, "force_value", "" );
            
            Index cfIndex;
            cfIndex = ConditionFunction_Register_GetIndex
              ( condFunc_Register, funcName);
            force.type = GALEStressBC_ConditionFunction;
            if ( cfIndex == (unsigned)-1 ) {	
              Stream*	errorStr = Journal_Register( Error_Type, self->type );
              
              Journal_Printf( errorStr, "Error- in %s: While parsing "
                              "definition of GALEDivergenceForce, the cond. func. "
                              " \"%s\" - wasn't found in the c.f. register.\n",
                              __func__, funcName );
              Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
              ConditionFunction_Register_PrintNameOfEachFunc
                ( condFunc_Register, errorStr );
              Journal_Printf( errorStr, ")\n");	
              assert(0);
            }
            force.CFIndex = cfIndex;
          }
        else if(strlen(type)==0)
          {
            Stream* errorStr = Journal_Register( Error_Type, self->type );
            Journal_Printf( errorStr, "Error- in %s: While parsing "
                            "definition of GALEDivergenceForce, force_type is not specified.\nSupported types are \"double\" and \"function\".\n",
                            __func__);
            assert(0);
          }
        else
          {
            Stream* errorStr = Journal_Register( Error_Type, self->type );
            Journal_Printf( errorStr, "Error- in %s: While parsing "
                            "definition of GALEDivergenceForce, the type of condition \"%s\"\nis not supported.  Supported types are \"double\" and \"function\".\n",
                            __func__, type );
            assert(0);
          }
        
        geometryMesh=Stg_ComponentFactory_ConstructByKey( cf, self->name, "GeometryMesh", FeMesh, True, data ) ;
        
	_GALEDivergenceForce_Init( self, domainShape, geometryMesh, force);
}
コード例 #13
0
void _Geothermal_FieldMaps_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
   Geothermal_FieldMaps*   self = (Geothermal_FieldMaps*)component;
   Dictionary*             dict = Codelet_GetPluginDictionary( component, cf->rootDict );
   Dictionary_Entry_Value* mapList;
   unsigned                map_i;
   Stream*                 errorStream = Journal_Register( ErrorStream_Type, Geothermal_FieldMaps_Type );
	
   Stream_SetPrintingRank( errorStream, 0 );


   /* Plugin-wide stuff */
   self->context = (AbstractContext*)Stg_ComponentFactory_ConstructByName(
      cf, "context", UnderworldContext, True, data ); 
   /*self->swarm = Stg_ComponentFactory_ConstructByName(
      cf, Dictionary_GetString( dict, "Swarm" ), Swarm, True, data );*/
   mapList = Dictionary_Get( dict, (Dictionary_Entry_Key)"maps" );
   if( mapList ) {
      self->numMaps = Dictionary_Entry_Value_GetCount( mapList );
      self->maps = malloc( self->numMaps * sizeof(Map*) );
   }
   else {
      self->numMaps = 0;
      self->maps = NULL;
   }

   /* Per map stuff */
   for( map_i = 0; map_i < self->numMaps; map_i++ ) {
      self->maps[map_i] = malloc( sizeof(Map) );
      Dictionary* mapEntryDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Entry_Value_GetElement( mapList, map_i ) );
      char* tmpStr;

      #define SDEK   Dictionary_Entry_Key
      #define SDGDWD Dictionary_GetDouble_WithDefault
      #define SDGSWD Dictionary_GetString_WithDefault
      #define SDGBWD Dictionary_GetBool_WithDefault
      #define SCFCBN Stg_ComponentFactory_ConstructByName
      strncpy( self->maps[map_i]->name, Dictionary_GetString( mapEntryDict, "name" ), FILENAME_MAX );
      strncpy( self->maps[map_i]->outputPath, SDGSWD( mapEntryDict, (SDEK)"outputPath", self->context->outputPath ), FILENAME_MAX);
      self->maps[map_i]->field = SCFCBN( cf, Dictionary_GetString( mapEntryDict, "Field" ), FeVariable, True, data );
      self->maps[map_i]->depth = SDGDWD( mapEntryDict, (SDEK)"depthFromSurface", 0.0 );

      /* Type of map */
      self->maps[map_i]->outputAllNodes = False;
      self->maps[map_i]->outputTopNodes = False;
      self->maps[map_i]->outputDepth = False;
      self->maps[map_i]->depth = 0.0;
      self->maps[map_i]->heightField = NULL;
      tmpStr = Dictionary_GetString( mapEntryDict, "of" );
      if( strcmp( "surface", tmpStr ) == 0 ) {
         self->maps[map_i]->outputTopNodes = True;
      }
      else if( strcmp( "volume", tmpStr ) == 0 ) {
         self->maps[map_i]->outputAllNodes = True;
      }
      else if( strcmp( "depth", tmpStr ) == 0 ) {
         self->maps[map_i]->outputDepth = True;
         self->maps[map_i]->depth = SDGDWD( mapEntryDict, (SDEK)"depthFromSurface", 0.0 );
/* TODO: firewall if depth not given!!!*/
      }
      else if( strcmp( "height", tmpStr ) == 0 ) {
         self->maps[map_i]->outputDepth = True;
         self->maps[map_i]->heightField = SCFCBN( cf, Dictionary_GetString( mapEntryDict, "HeightField" ), FieldVariable, True, data );
/* TODO: firewall if HeightField not given!!!*/
      }
      Journal_Firewall( 
         self->maps[map_i]->outputTopNodes || self->maps[map_i]->outputAllNodes || self->maps[map_i]->outputDepth, 
         errorStream, 
         "Error: On FieldMaps plugin entry %u (named: \"%s\"), the \"of\" parameter must be either \"surface\", \"volume\", " 
         "\"depth\", or \"height\" (\"%s\" was given).\n", 
         map_i, self->maps[map_i]->name, tmpStr );

      /* Formats */
      self->maps[map_i]->gocadOutput = SDGBWD( mapEntryDict, (SDEK)"GOCADOutput", True );
 
      self->maps[map_i]->nodeValues = 0;
      self->maps[map_i]->nodeCoords = 0;
      self->maps[map_i]->topNodesCount = 0;
   }

   ContextEP_Append( self->context, AbstractContext_EP_Dump, Geothermal_FieldMaps_Dump );
}
コード例 #14
0
Dictionary_Entry_Value* _Stg_ComponentFactory_PluginGetDictionaryValue( void* cf, void *codelet, Dictionary_Entry_Key key, Dictionary_Entry_Value* defaultVal ) {
   Stg_ComponentFactory*       self              = (Stg_ComponentFactory*) cf;
   Stg_Component*             plugin          = (Stg_Component*)codelet;
   Dictionary*                thisPluginDict = NULL;
   Dictionary*                pluginDict     = (Dictionary*)Dictionary_Get( self->rootDict, "plugins" );
   Name                      pluginType;
   Index      pluginIndex;
   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 );

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

   /* Get this plugins Dictionary */
   for( pluginIndex = 0; pluginIndex < Dictionary_Entry_Value_GetCount( (Dictionary_Entry_Value*)pluginDict ); pluginIndex++ ) {
      thisPluginDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Entry_Value_GetElement( (Dictionary_Entry_Value*)pluginDict, pluginIndex ) );
      pluginType = StG_Strdup( Dictionary_GetString( thisPluginDict, "Type" ) );
      if( !strcmp( plugin->type, pluginType ) ){
         Memory_Free( pluginType );
         break;
      }
                Memory_Free( pluginType );
   }

   /* Get this Stg_Component's Dictionary */
   Journal_Firewall( thisPluginDict != NULL, errorStream,
         "In func %s: Can't find sub-dictionary for component '%s'.\n", __func__, plugin->name );

   /* Get Value from dictionary */
   returnVal = Dictionary_Get( thisPluginDict, key );
   if ( !returnVal && defaultVal ) {
      returnVal = Dictionary_GetDefault( thisPluginDict, 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;
}
コード例 #15
0
void _SnacRemesher_ConstructExtensions( void* _context, void* data ) {
	Snac_Context*				context = (Snac_Context*)_context;
	SnacRemesher_Context*			contextExt = ExtensionManager_Get(
							context->extensionMgr,
							context,
							SnacRemesher_ContextHandle );
	Mesh*					mesh = context->mesh;
	SnacRemesher_Mesh*			meshExt = ExtensionManager_Get(
							context->meshExtensionMgr,
							mesh,
							SnacRemesher_MeshHandle );
	char*					conditionStr;
	Dictionary_Entry_Value*			conditionCriterion;
	Dictionary* 				meshDict;
	Stream*					error = Journal_Register( Error_Type, "Remesher" );
	char					tmpBuf[PATH_MAX];

	Journal_Printf( context->debug, "In: %s\n", __func__ );
	
	contextExt->debugIC = Journal_Register( Debug_Type, "Remesher-ICs" );
	contextExt->debugCoords = Journal_Register( Debug_Type, "Remesher-Coords" );
	contextExt->debugNodes = Journal_Register( Debug_Type, "Remesher-Nodes" );
	contextExt->debugElements = Journal_Register( Debug_Type, "Remesher-Elements" );
	contextExt->debugSync = Journal_Register( Debug_Type, "Remesher-Sync" );
	
	/* Additional tables required over the nodeElementTbl already required by core Snac */
	Mesh_ActivateNodeNeighbourTbl( mesh );
	Mesh_ActivateElementNeighbourTbl( mesh );
	
	/* Work out condition to remesh on */
	if( !Dictionary_Get( context->dictionary, CONDITION_STR ) ) {
		Journal_Printf( 
			error,
			"Warning: No \"%s\" entry in dictionary... will default to \"%s\"\n", 
			CONDITION_STR,
			OFF_STR );
	}
	
	conditionStr = Dictionary_Entry_Value_AsString( 
		Dictionary_GetDefault( context->dictionary, CONDITION_STR, Dictionary_Entry_Value_FromString( OFF_STR ) ) );
	
	contextExt->OnTimeStep = 0;
	contextExt->onMinLengthScale = 0;
	if( !strcmp( conditionStr, OFF_STR ) ) {
		contextExt->condition = SnacRemesher_Off;
		Journal_Printf( context->snacInfo, "Remesher is off\n" );
	}
	else if( !strcmp( conditionStr, ONTIMESTEP_STR ) ) {
		contextExt->condition = SnacRemesher_OnTimeStep;
		conditionCriterion = Dictionary_Get( context->dictionary, TIMESTEPCRITERION_STR );
		Journal_Printf( context->snacInfo, "Remesher is on... activated based on timeStep\n" );
		
		if( conditionCriterion ) {
			contextExt->OnTimeStep = Dictionary_Entry_Value_AsUnsignedInt( conditionCriterion );
		}
		else {
		}
		Journal_Printf( context->snacInfo, "Remeshing every %u timeSteps\n", contextExt->OnTimeStep );
	}
	else if( !strcmp( conditionStr, ONMINLENGTHSCALE_STR ) ) {
		contextExt->condition = SnacRemesher_OnMinLengthScale;
		conditionCriterion = Dictionary_Get( context->dictionary, LENGTHCRITERION_STR );
		Journal_Printf( context->snacInfo, "Remesher is on... activated by minLengthScale\n" );
		
		if( conditionCriterion ) {
			contextExt->onMinLengthScale = Dictionary_Entry_Value_AsDouble( conditionCriterion );
		}
		else {
		}
		Journal_Printf( context->snacInfo, "Remesh when minLengthScale < %g\n", contextExt->onMinLengthScale );
	}
	else if( !strcmp( conditionStr, ONBOTHTIMESTEPLENGTH_STR ) ) {
		contextExt->condition = SnacRemesher_OnBothTimeStepLength;
		conditionCriterion = Dictionary_Get( context->dictionary, TIMESTEPCRITERION_STR );
		Journal_Printf( context->snacInfo, "Remesher is on... activated by both timeStep and minLengthScale\n" );
		
		if( conditionCriterion ) {
			contextExt->OnTimeStep = Dictionary_Entry_Value_AsUnsignedInt( conditionCriterion );
			conditionCriterion = Dictionary_Get( context->dictionary, LENGTHCRITERION_STR );
			contextExt->onMinLengthScale = Dictionary_Entry_Value_AsDouble( conditionCriterion );
		}
		else {
		}
		Journal_Printf( context->snacInfo, "Remesh every %u timeSteps or wheen minLengthScale < %g\n", contextExt->OnTimeStep, contextExt->onMinLengthScale );
	}
	else {
		contextExt->condition = SnacRemesher_Off;
		Journal_Printf( context->snacInfo, "Remesher is defaulting to off\n" );
		Journal_Printf( error, "Provided remesh condition \"%s\" unrecognised\n", conditionStr );
	}
	
	
	/* Work out the mesh type */
	meshDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( context->dictionary, MESH_STR ) );
	if( meshDict ) {
		char* 					meshTypeStr;
		
		if( !Dictionary_Get( meshDict, MESHTYPE_STR ) ) {
			Journal_Printf( 
				error,
				"Warning: No \"%s\" entry in \"%s\"... will default to \"%s\"\n", 
				MESHTYPE_STR, 
				MESH_STR, 
				CARTESIAN_STR );
		}
		
		meshTypeStr = Dictionary_Entry_Value_AsString( 
			Dictionary_GetDefault( meshDict, MESHTYPE_STR, Dictionary_Entry_Value_FromString( CARTESIAN_STR ) ) );
		
		if( !strcmp( meshTypeStr, SPHERICAL_STR ) ) {
			meshExt->meshType = SnacRemesher_Spherical;
			Journal_Printf( context->snacInfo, "Remesher knows mesh as a spherical mesh\n" );
		}
		else if( !strcmp( meshTypeStr, CARTESIAN_STR ) ) {
			meshExt->meshType = SnacRemesher_Cartesian;
			Journal_Printf( context->snacInfo, "Remesher knows mesh as a cartesian mesh\n" );
		}
		else {
			meshExt->meshType = SnacRemesher_Cartesian;
			Journal_Printf( context->snacInfo, "Remesher assuming mesh as a cartesian mesh\n" );
			Journal_Printf( error, "Provided mesh type \"%s\" unrecognised!\n", meshTypeStr );
		}
	}
	else {
		meshExt->meshType = SnacRemesher_Cartesian;
		Journal_Printf( context->snacInfo, "Remesher assuming mesh as a cartesian mesh\n" );
		Journal_Printf( error, "No \"%s\" entry in dictionary!\n", MESH_STR );
	}
	/* Decide whether to restore the bottom surface */
	contextExt->bottomRestore = 0;
	if( !strcmp( Dictionary_Entry_Value_AsString( Dictionary_GetDefault( context->dictionary, "bottomRestore", Dictionary_Entry_Value_FromString( OFF_STR ) ) ), ON_STR) )
		contextExt->bottomRestore = 1;


	/* Register these functions for use in VCs */
	ConditionFunction_Register_Add(
		context->condFunc_Register,
		ConditionFunction_New( _SnacRemesher_TestCondFunc, "SnacRemesher_TestCondFunc" ) );
	
	/* Register these functions for use in VCs */
	ConditionFunction_Register_Add(
		context->condFunc_Register,
		ConditionFunction_New( _SnacRemesher_XFunc, "SnacRemesher_XFunc" ) );
	
	/* Register these functions for use in VCs */
	ConditionFunction_Register_Add(
		context->condFunc_Register,
		ConditionFunction_New( _SnacRemesher_YFunc, "SnacRemesher_YFunc" ) );
	
	/* Obtain the keys for the our new entry points... having the keys saves doing a string compare at run time */
	contextExt->recoverNodeK = EntryPoint_Register_GetHandle( 
		context->entryPoint_Register, 
		SnacRemesher_EP_RecoverNode );
	contextExt->interpolateNodeK = EntryPoint_Register_GetHandle( 
		context->entryPoint_Register, 
		SnacRemesher_EP_InterpolateNode );
	contextExt->interpolateElementK = EntryPoint_Register_GetHandle( 
		context->entryPoint_Register, 
		SnacRemesher_EP_InterpolateElement );

	/* Prepare the dump file */
	if( context->rank == 0) {
		sprintf( tmpBuf, "%s/remeshInfo.%u", context->outputPath, context->rank );
		if( (contextExt->remesherOut = fopen( tmpBuf, "w+" )) == NULL ) {
			assert( contextExt->remesherOut /* failed to open file for writing */ );
		}
	}
	/* initialize remeshing counter */
	contextExt->remeshingCount = 0;
}
コード例 #16
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" );
   }
}
コード例 #17
0
ファイル: main.c プロジェクト: AngelValverdePerez/underworld2
/* 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;
}
コード例 #18
0
void _SnacTemperature_ConstructExtensions( void* _context, void* data ) {
	Snac_Context*				context = (Snac_Context*)_context;
	SnacTemperature_Context*		contextExt = ExtensionManager_Get(
							context->extensionMgr,
							context,
							SnacTemperature_ContextHandle );
	Snac_Node				tmpNode;
	SnacTemperature_Node*			tmpNodeExt = ExtensionManager_Get(
							context->mesh->nodeExtensionMgr,
							&tmpNode,
							SnacTemperature_NodeHandle );
	Dictionary*				temperatureBCsDict;
	char					tmpBuf[PATH_MAX];
	
	/* Because temperature is not an array by itself, we must the "complex" constructor for Variable... the info needs to be
	 * wrapped this generic way... */
	Index					temperatureOffsetCount = 1;
	SizeT					temperatureOffsets[] = { /*GetOffsetOfMember( *tmpNodeExt, temperature ) };*/
		(SizeT)((char*)&tmpNodeExt->temperature - (char*)&tmpNode) };
	Variable_DataType			temperatureDataTypes[] = { Variable_DataType_Double };
	Index					temperatureDataTypeCounts[] = { 1 };
	
		
	#if DEBUG
		printf( "In %s()\n", __func__ );
	#endif

	/* Create the StGermain variable temperature, which is stored on a node extension */
	Variable_New( 
		"temperature", 
		temperatureOffsetCount, 
		temperatureOffsets, 
		temperatureDataTypes, 
		temperatureDataTypeCounts, 
		0, 
		&ExtensionManager_GetFinalSize( context->mesh->nodeExtensionMgr ),
		&context->mesh->layout->decomp->nodeDomainCount,
		(void**)&context->mesh->node,
		context->variable_Register );

	/* Register these functions for use in VCs */
	ConditionFunction_Register_Add(
		context->condFunc_Register,
		ConditionFunction_New( _SnacTemperature_Top2BottomSweep, "SnacTemperature_Top2BottomSweep" ) );
	ConditionFunction_Register_Add(
		context->condFunc_Register,
		ConditionFunction_New( _SnacTemperature_Top2BottomSweep_Spherical, "SnacTemperature_Top2BottomSweep_Spherical" ) );
	ConditionFunction_Register_Add(
		context->condFunc_Register,
		ConditionFunction_New( _SnacTemperature_Citcom_Compatible, "SnacTemperature_Citcom_Compatible" ) );

	/* Temperature variables */
	contextExt->topTemp = Dictionary_Entry_Value_AsDouble(
		Dictionary_GetDefault( context->dictionary, "topTemp", Dictionary_Entry_Value_FromDouble( 0.0f ) ) );

	contextExt->bottomTemp = Dictionary_Entry_Value_AsDouble(
		Dictionary_GetDefault( context->dictionary, "bottomTemp", Dictionary_Entry_Value_FromDouble( 1300.0f ) ) );

	/* Build the temperature IC and BC managers */
	temperatureBCsDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( context->dictionary, "temperatureBCs" ) );
	contextExt->temperatureBCs = CompositeVC_New("tempBC",
		context->variable_Register,
		context->condFunc_Register,
		temperatureBCsDict,
		context->mesh );

	/* Prepare the dump and checkpoint file */
	sprintf( tmpBuf, "%s/temperature.%u", context->outputPath, context->rank );
	if( (contextExt->temperatureOut = fopen( tmpBuf, "w+" )) == NULL ) {
		assert( contextExt->temperatureOut /* failed to open file for writing */ );
		abort();
	}
	sprintf( tmpBuf, "%s/temperatureCP.%u", context->outputPath, context->rank );
	if( (contextExt->temperatureCheckpoint = fopen( tmpBuf, "w+" )) == NULL ) {
		assert( contextExt->temperatureCheckpoint /* failed to open file for writing */ );
		abort();
	}
}