コード例 #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
void _PeriodicBoundariesManager_Build( void* periodicBCsManager, void* data ) {	
	PeriodicBoundariesManager* self = (PeriodicBoundariesManager*)periodicBCsManager;
	Dictionary_Entry_Value*    periodicBCsList = NULL;

	Stg_Component_Build( self->swarm, data, False );
	Stg_Component_Build( self->mesh, data, False );
	self->size = 4;
	self->boundaries = Memory_Alloc_Array( PeriodicBoundary, self->size, "PeriodicBoundariesManager->boundaries" );

	if ( self->dictionary ) {
		periodicBCsList = Dictionary_Get( self->dictionary, (Dictionary_Entry_Key)"PeriodicBoundaries" );
		
		/* Dictionary entry is optional - users may prefer to enter in code */
		if ( periodicBCsList ) {
			Index                   numPeriodicBCs = 0;
			Index                   periodicBC_I = 0;
			Dictionary_Entry_Value* periodicBC = NULL;
			char*                   perBCAxis = NULL;
			
			numPeriodicBCs = Dictionary_Entry_Value_GetCount( periodicBCsList );

			for ( periodicBC_I = 0; periodicBC_I < numPeriodicBCs; periodicBC_I++  ) {
				periodicBC = Dictionary_Entry_Value_GetElement( periodicBCsList, periodicBC_I );
				perBCAxis = Dictionary_Entry_Value_AsString( periodicBC );

				if ( 0 == strcmp( perBCAxis, "I_AXIS" ) ) {
					PeriodicBoundariesManager_AddPeriodicBoundary( self, I_AXIS );
				}
				else if ( 0 == strcmp( perBCAxis, "J_AXIS" ) ) {
					PeriodicBoundariesManager_AddPeriodicBoundary( self, J_AXIS );
				}
				else if ( 0 == strcmp( perBCAxis, "K_AXIS" ) ) {
					PeriodicBoundariesManager_AddPeriodicBoundary( self, K_AXIS );
				}
			}
		}
	}
	/* Test if mesh is periodic */
	else if ( Stg_Class_IsInstance( self->mesh->generator, CartesianGenerator_Type ) ) {
		CartesianGenerator* cartesianGenerator = (CartesianGenerator*) self->mesh->generator;
		Dimension_Index dim_I;

		for ( dim_I = 0 ; dim_I < self->swarm->dim ; dim_I++ ) {
			/* Add boundaries straight from mesh generator */
			if ( cartesianGenerator->periodic[ dim_I ] ) 
				PeriodicBoundariesManager_AddPeriodicBoundary( self, dim_I );
		}		
	}
}
コード例 #7
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);
}
コード例 #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
Dictionary_Entry_Value* Dictionary_Entry_Value_GetFirstElement( Dictionary_Entry_Value* self )
{
	return Dictionary_Entry_Value_GetElement( self, 0 );
}
コード例 #12
0
ファイル: FrictionVC.c プロジェクト: bmi-forum/bmi-pyre
void _FrictionVC_ReadDictionary( void* variableCondition, void* dictionary ) {
	FrictionVC*			self = (FrictionVC*)variableCondition;
	Dictionary_Entry_Value*	vcDictVal;
	Dictionary_Entry_Value	_vcDictVal;
	Dictionary_Entry_Value*	varsVal;
	FrictionVC_Entry_Index	entry_I;
	
	/* Find dictionary entry */
	if (self->_dictionaryEntryName)
		vcDictVal = Dictionary_Get(dictionary, self->_dictionaryEntryName);
	else
	{
		vcDictVal = &_vcDictVal;
		Dictionary_Entry_Value_InitFromStruct(vcDictVal, dictionary);
	}
	
	if (vcDictVal)
	{
		char*	wallStr;
		
		/* Obtain which wall */
		wallStr = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember(vcDictVal, "wall" ));
		if (!strcasecmp(wallStr, "back"))
			self->_wall = FrictionVC_Wall_Back;
		else if (!strcasecmp(wallStr, "left"))
			self->_wall = FrictionVC_Wall_Left;
		else if (!strcasecmp(wallStr, "bottom"))
			self->_wall = FrictionVC_Wall_Bottom;
		else if (!strcasecmp(wallStr, "right"))
			self->_wall = FrictionVC_Wall_Right;
		else if (!strcasecmp(wallStr, "top"))
			self->_wall = FrictionVC_Wall_Top;
		else if (!strcasecmp(wallStr, "front"))
			self->_wall = FrictionVC_Wall_Front;
		else {
			assert( 0 );
			self->_wall = FrictionVC_Wall_Size; /* invalid entry */
		}
		
		/* Obtain the variable entries */
		self->_entryCount = 0;
		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember(vcDictVal, "variables"));
		self->_entryTbl = Memory_Alloc_Array( FrictionVC_Entry, self->_entryCount, "FrictionVC->_entryTbl" );
		varsVal = Dictionary_Entry_Value_GetMember(vcDictVal, "variables");
		
		for (entry_I = 0; entry_I < self->_entryCount; entry_I++)
		{
			char*			valType;
			Dictionary_Entry_Value*	valueEntry;
			Dictionary_Entry_Value*	varDictListVal;
			
			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
			valueEntry = Dictionary_Entry_Value_GetMember(varDictListVal, "value");
			
			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString(
				Dictionary_Entry_Value_GetMember(varDictListVal, "name"));
				
			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember(varDictListVal, "type"));
			if (0 == strcasecmp(valType, "func"))
			{
				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
				Index	cfIndex;
				
				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
				if ( cfIndex == (unsigned)-1 ) {	
					Stream*	errorStr = Journal_Register( Error_Type, self->type );

					Journal_Printf( errorStr, "Error- in %s: While parsing "
						"definition of wallVC \"%s\" (applies to wall \"%s\"), the cond. func. applied to "
						"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
						__func__, self->_dictionaryEntryName, FrictionVC_WallEnumToStr[self->_wall],
						self->_entryTbl[entry_I].varName, funcName );
					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
					Journal_Printf( errorStr, ")\n");	
					assert(0);
				}	
				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
			}
			else if (0 == strcasecmp(valType, "array"))
			{
				Dictionary_Entry_Value*	valueElement;
				Index			i;

				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
					self->_entryTbl[entry_I].value.as.typeArray.size, "FrictionVC->_entryTbl[].value.as.typeArray.array" );
					
				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
				{
					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
						Dictionary_Entry_Value_AsDouble(valueElement);
				}
			}
			else if( 0 == strcasecmp( valType, "double" ) || 0 == strcasecmp( valType, "d" ) ||
				0 == strcasecmp( valType, "float" ) || 0 == strcasecmp( valType, "f" ) )
			{
				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
			}
			else if( 0 == strcasecmp( valType, "integer" ) || 0 == strcasecmp( valType, "int" ) || 0 == strcasecmp( valType, "i" ) ) {
				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
			}
			else if( 0 == strcasecmp( valType, "short" ) || 0 == strcasecmp( valType, "s" ) ) {
				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
			}
			else if( 0 == strcasecmp( valType, "char" ) || 0 == strcasecmp( valType, "c" ) ) {
				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
			}
			else if( 0 == strcasecmp( valType, "pointer" ) || 0 == strcasecmp( valType, "ptr" ) || 0 == strcasecmp( valType, "p" ) ) {
				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
				self->_entryTbl[entry_I].value.as.typePtr = (void*) ( (ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
			}
			else {
				/* Assume double */
				Journal_DPrintf( 
					Journal_Register( InfoStream_Type, "myStream" ), 
					"Type to variable on variable condition not given, assuming double\n" );
				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
			}
		}
コード例 #13
0
void _FieldVariable_AssignFromXML( void* fieldVariable, Stg_ComponentFactory* cf, void* data ) {
   FieldVariable*          self = (FieldVariable*)fieldVariable;
   FieldVariable_Register* fV_Register=NULL;
   Dimension_Index         dim;
   Index                   fieldComponentCount;
   Bool                    isCheckpointedAndReloaded, isCheckpointedAndReloaded2;
   Dictionary_Entry_Value* feVarsList = NULL;
   char*                   o_units = NULL;
   DomainContext*          context;
   Bool                    useCacheMaxMin;

   context = Stg_ComponentFactory_ConstructByKey(
      cf,
      self->name,
      (Dictionary_Entry_Key)"Context",
      DomainContext,
      False,
      data );

   if( !context )
      context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, False, data );
   
   if (context) {
      fV_Register = context->fieldVariable_Register;
      assert( fV_Register );
   }

   dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0 );
   /* allow this to be overwritten by the component dub dict */
   dim = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"dim", dim );

   fieldComponentCount = Stg_ComponentFactory_GetUnsignedInt(
      cf,
      self->name,
      (Dictionary_Entry_Key)"fieldComponentCount",
      0 );

   useCacheMaxMin = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"useCacheMaxMin", False );
   
   o_units = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"outputUnits", NULL );

   /* 
    * Decide whether this FieldVariable will be checkpointed & reloaded, based on the dictionary list 
    * "fieldVariableToCheckpoint". NB may want to put this in the XML component definintion of a
    * FieldVariable itself, but for now prefer list so it can be centrally set.
    * -- Pat, Jules, Kath - 29 November 2006 
    */

   isCheckpointedAndReloaded2 = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"isCheckpointedAndReloaded", False );

   /* Case insensitive search */
   feVarsList = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"fieldVariablesToCheckpoint" );
   if( NULL == feVarsList ) {
      feVarsList = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"FieldVariablesToCheckpoint" );
   }

   if( feVarsList != NULL ) {
      Index                   listLength = Dictionary_Entry_Value_GetCount( feVarsList );
      Index                   var_I = 0;
      Dictionary_Entry_Value* feVarDictValue = NULL;
      char*                   fieldVariableName;
   
      /* if the 'fieldVariablesToCheckpoint' list is empty (but exists)
       *    checkpoint every field
       * else selectively checkpoint based on list entries */
      if( listLength == 0 ) { 
         isCheckpointedAndReloaded = True; 
      }
      else {
         isCheckpointedAndReloaded = False;
         for ( var_I = 0; var_I < listLength; var_I++  ) {
            feVarDictValue = Dictionary_Entry_Value_GetElement( feVarsList, var_I );
            fieldVariableName = Dictionary_Entry_Value_AsString( feVarDictValue ); 
            if ( 0 == strcmp( self->name, fieldVariableName ) ) {
               isCheckpointedAndReloaded = True;
               break;
            }
         }
      }
   }
   else {
      /* If there's no special list, just checkpoint/reload everything. */
      isCheckpointedAndReloaded = True;
   }

   isCheckpointedAndReloaded = (isCheckpointedAndReloaded || isCheckpointedAndReloaded2 );

   feVarsList = NULL;
   /* also include check to see if this fevariable should be saved for analysis purposes */ 
   feVarsList = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"fieldVariablesToSave" );

   if( NULL == feVarsList ) {
      feVarsList = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"FieldVariablesToSave" );
   }
   if( feVarsList != NULL ) {
      Index                   listLength = Dictionary_Entry_Value_GetCount( feVarsList );
      Index                   var_I = 0;
      Dictionary_Entry_Value* feVarDictValue = NULL;
      char*                   fieldVariableName;
   
      for( var_I = 0; var_I < listLength; var_I++ ) {
         feVarDictValue = Dictionary_Entry_Value_GetElement( feVarsList, var_I );
         fieldVariableName = Dictionary_Entry_Value_AsString( feVarDictValue ); 

         if( 0 == strcmp( self->name, fieldVariableName ) ) {
            self->isSavedData = True;
            break;
         }
      }
   }
   _FieldVariable_Init(
      self,
      context,
      fieldComponentCount,
      dim,
      isCheckpointedAndReloaded,
      o_units,
      MPI_COMM_WORLD,
      fV_Register,
      useCacheMaxMin );

}
コード例 #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
ファイル: VariableAllVC.c プロジェクト: bmi-forum/bmi-pyre
void _VariableAllVC_ReadDictionary( void* variableCondition, void* dictionary ) {
	VariableAllVC*			self = (VariableAllVC*)variableCondition;
	Dictionary_Entry_Value*		vcDictVal;
	Dictionary_Entry_Value		_vcDictVal;
	Dictionary_Entry_Value*		varsVal;
	VariableAllVC_Entry_Index	entry_I;
	
	/* Find dictionary entry */
	if (self->_dictionaryEntryName)
		vcDictVal = Dictionary_Get( dictionary, self->_dictionaryEntryName );
	else
	{
		vcDictVal = &_vcDictVal;
		Dictionary_Entry_Value_InitFromStruct( vcDictVal, dictionary );
	}
	
	if (vcDictVal)
	{
		/* Obtain the variable entries */
		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember(vcDictVal, "variables"));
		self->_entryTbl = Memory_Alloc_Array( VariableAllVC_Entry, self->_entryCount, "VariableAllVC->_entryTbl" );
		varsVal = Dictionary_Entry_Value_GetMember(vcDictVal, "variables");
		
		for (entry_I = 0; entry_I < self->_entryCount; entry_I++)
		{
			char*			valType;
			Dictionary_Entry_Value*	valueEntry;
			Dictionary_Entry_Value*	varDictListVal;
			
			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
			valueEntry = Dictionary_Entry_Value_GetMember(varDictListVal, "value");
			
			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString(
				Dictionary_Entry_Value_GetMember(varDictListVal, "name"));
				
			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember(varDictListVal, "type"));
			if (!strcasecmp(valType, "func"))
			{
				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
				
				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
				self->_entryTbl[entry_I].value.as.typeCFIndex = ConditionFunction_Register_GetIndex(
					self->conFunc_Register, funcName);
			}
			else if (!strcasecmp(valType, "array"))
			{
				Dictionary_Entry_Value*	valueElement;
				Index			i;

				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
					self->_entryTbl[entry_I].value.as.typeArray.size,"VariableAllVC->_entryTbl[].value.as.typeArray.array" );
					
				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
				{
					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
						Dictionary_Entry_Value_AsDouble(valueElement);
				}
			}
			else if( !strcasecmp( valType, "double" ) || !strcasecmp( valType, "d" ) || !strcasecmp( valType, "float" ) || !strcasecmp( valType, "f" ) ) {
				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
			}
			else if( !strcasecmp( valType, "integer" ) || !strcasecmp( valType, "int" ) || !strcasecmp( valType, "i" ) ) {
				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
			}
			else if( !strcasecmp( valType, "short" ) || !strcasecmp( valType, "s" ) ) {
				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
			}
			else if( !strcasecmp( valType, "char" ) || !strcasecmp( valType, "c" ) ) {
				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
			}
			else if( !strcasecmp( valType, "pointer" ) || !strcasecmp( valType, "ptr" ) || !strcasecmp( valType, "p" ) ) {
				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
				self->_entryTbl[entry_I].value.as.typePtr = (void*) ( (ArithPointer) Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
			}
			else {
				/* Assume double */
				Journal_DPrintf( Journal_Register( InfoStream_Type, "myStream" ), "Type to variable on variable condition not given, assuming double\n" );
				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
			}
		}
コード例 #16
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 );
    }
}
コード例 #17
0
ファイル: MeshVariable.c プロジェクト: dansand/underworld2
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);
}
コード例 #18
0
void ModulesManager_Load( void* modulesManager, void* _dictionary, Name contextName ) {
   ModulesManager*         self = (ModulesManager*)modulesManager;
   Dictionary*             dictionary = (Dictionary*)_dictionary;
   unsigned int            entryCount;
   unsigned int            entry_I;
   Dictionary_Entry_Value* modulesVal;

   /* 
    * First add the directory list onto LD_LIBRARY_PATH so that it can potentially
    * resolve the unknown symbols */
   #ifndef NOSHARED
   char* curEnvPath;
   char* newEnvPath;
   Index newEnvPathLength;
   Index dir_I;
   Index i, count;
   char* dir;

   newEnvPathLength = 0;

   if( dictionary ) {
      Dictionary_Entry_Value* localLibDirList = Dictionary_Get( dictionary, "LD_LIBRARY_PATH" );

      if( localLibDirList ) {
         count = Dictionary_Entry_Value_GetCount( localLibDirList );
         for( i = 0; i < count; ++i ) {
            dir = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( localLibDirList, i ) );
            ModulesManager_AddDirectory( "FromDictionary", dir );
         }
      }
   }
   
   for( dir_I = 0; dir_I < moduleDirectories->count; ++dir_I ) {
      newEnvPathLength += strlen( (char*)Stg_ObjectList_ObjectAt( moduleDirectories, dir_I ) );
      /* Add one make space for the ':' inbetween the directories */
      newEnvPathLength += 1; 
   }
   curEnvPath = getenv("LD_LIBRARY_PATH");
   if( curEnvPath ) {
      newEnvPathLength += strlen( curEnvPath );
   }

   if( newEnvPathLength > 0 ) {
      /* Add one to make space for the Null Terminator '\0' */
      newEnvPathLength += 1;
      
      newEnvPath = Memory_Alloc_Array( char, newEnvPathLength, "LD_LIBRARY_PATH" );
      newEnvPath[0] = '\0';
      for( dir_I = 0; dir_I < moduleDirectories->count; ++dir_I ) {
         strcat( newEnvPath, (char*)Stg_ObjectList_ObjectAt( moduleDirectories, dir_I ) );
         strcat( newEnvPath, ":" );
      }
      if( curEnvPath ) {
         strcat( newEnvPath, curEnvPath );
      }
      setenv( "LD_LIBRARY_PATH", newEnvPath, 1 );

      Journal_Printf(
         Journal_Register( Debug_Type, self->type ),
         "Using LD_LIBRARY_PATH=%s\n",
         newEnvPath );
      Memory_Free( newEnvPath );
   }
コード例 #19
0
Name _ToolboxesManager_GetModuleName( void* toolboxesManager, Dictionary_Entry_Value* moduleVal, unsigned int entry_I ) {
    return Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( moduleVal, entry_I ) );
}
コード例 #20
0
/*----------------------------------------------------------------------------------------------------------
** 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 );
}
コード例 #21
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 );
}