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__ );
}
void DictionarySuite_TestSet( DictionarySuiteData* data ) {
   Dictionary_Entry_Value* currValue;
   Dictionary_Entry_Value* listValue;
   double                  newVal1 = 34.3, newVal2 = 38.9;
   Index                   ii=0;

   DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD );

   listValue = Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_list" );
   /* getting dictionary out of a list */
   currValue = Dictionary_Entry_Value_GetFirstElement( listValue  );
   /* do something to this value */
   Dictionary_Entry_Value_SetFromDouble( currValue, newVal1 );
   currValue = currValue->next;
   /* do something to this value */
   Dictionary_Entry_Value_SetFromDouble( currValue, newVal2 );
   
   pcu_check_true( 5 == Dictionary_Entry_Value_GetCount( listValue ) );
   currValue = Dictionary_Entry_Value_GetFirstElement( listValue );
   pcu_check_le( fabs(newVal1 - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 );
   currValue = currValue->next;
   pcu_check_le( fabs(newVal2 - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 );
   currValue = currValue->next;
   for ( ii=2; ii<data->testDD->testListCount; ii++ ) {
      pcu_check_le( fabs(data->testDD->testList[ii]
         - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 );
      currValue = currValue->next;
   }
}
void Stg_ComponentFactory_GetRequiredDouble( void* cf, Name componentName, Dictionary_Entry_Key key, double* value ) {
   Dictionary_Entry_Value* dict_value = _Stg_ComponentFactory_GetNumericalValue( cf, componentName, key, NULL);
   if (!dict_value) {
      Journal_Firewall( NULL, NULL, "Input error for component '%s': Can't find the input key '%s'\n", componentName, key);
   }
   *value = Dictionary_Entry_Value_AsDouble(dict_value);
}
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", "" ) );
}
void _ConvexHull_AssignFromXML( void* convexHull, Stg_ComponentFactory* cf, void* data ) {
	ConvexHull*             self       = (ConvexHull*)convexHull;
	Index                   vertexCount;
	Index                   vertex_I;
	Coord_List              vertexList;
	double*                 coord;
	Dictionary_Entry_Value* optionSet;
	Dictionary_Entry_Value* optionsList;
	Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
	Stream*                 stream     = cf->infoStream;

	
	_Stg_Shape_AssignFromXML( self, cf, data );

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

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

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

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


	_ConvexHull_Init( self, vertexList, vertexCount);
}
void _SnacDikeInjection_ConstructExtensions( void* _context, void* data ) {
	Snac_Context*				context = (Snac_Context*)_context;
	SnacDikeInjection_Context*			contextExt = ExtensionManager_Get(
																		  context->extensionMgr,
																		  context,
																		  SnacDikeInjection_ContextHandle );
#ifdef DEBUG
	printf( "In %s()\n", __func__ );
#endif
	
	/* DikeInjection variables */
	contextExt->startX = Dictionary_Entry_Value_AsDouble(
			Dictionary_GetDefault( context->dictionary, "startX", 
								   Dictionary_Entry_Value_FromDouble( 29800.0f ) ) );
	//printf("startX is not the value %d", startX )
       contextExt->startZ = Dictionary_Entry_Value_AsDouble(
			Dictionary_GetDefault( context->dictionary, "startZ", 
								   Dictionary_Entry_Value_FromDouble( 0.0f ) ) );
	contextExt->endX = Dictionary_Entry_Value_AsDouble(
			Dictionary_GetDefault( context->dictionary, "endX", 
								   Dictionary_Entry_Value_FromDouble( 30200.0f ) ) );
	contextExt->endZ = Dictionary_Entry_Value_AsDouble(
			Dictionary_GetDefault( context->dictionary, "endZ", 
								   Dictionary_Entry_Value_FromDouble( 1000.0f ) ) );
	contextExt->dikeDepth = Dictionary_Entry_Value_AsDouble(
			Dictionary_GetDefault( context->dictionary, "dikeDepth", 
								   Dictionary_Entry_Value_FromDouble( 6000.0 ) ) );
	contextExt->dikeWidth = Dictionary_Entry_Value_AsDouble(
			Dictionary_GetDefault( context->dictionary, "dikeWidth", 
								   Dictionary_Entry_Value_FromDouble( 720 ) ) ); /* 1.8 * dx looks appropriate. */
	contextExt->injectionRate = Dictionary_Entry_Value_AsDouble(
			Dictionary_GetDefault( context->dictionary, "injectionRate", 
								   Dictionary_Entry_Value_FromDouble( 7.9e-10 ) ) ); /* a fraction of applied plate vel. */

}
double Dictionary_GetDouble_WithDefault(
   Dictionary*          dictionary,
   Dictionary_Entry_Key key,
   const double         defaultVal )
{
   return Dictionary_Entry_Value_AsDouble( 
      Dictionary_GetDefault(
         dictionary, key, Dictionary_Entry_Value_FromDouble( defaultVal ) ) );
}
float Dictionary_GetFloat_WithDefault(
   Dictionary*          dictionary,
   Dictionary_Entry_Key key,
   const float          defaultVal )
{
   return(float) Dictionary_Entry_Value_AsDouble( 
      Dictionary_GetDefault(
         dictionary, key, Dictionary_Entry_Value_FromDouble( (double)defaultVal ) ) );
}
void DictionarySuite_TestGet( DictionarySuiteData* data ) {
   Dictionary_Entry_Value* yValue;
   Dictionary_Entry_Value* testStruct;

   DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD );

   testStruct = Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_struct"  );
   yValue = Dictionary_Entry_Value_GetMember( Dictionary_Entry_Value_GetMember(testStruct, (Dictionary_Entry_Key)"geom" ), "starty");
   pcu_check_true( data->testDD->testStruct->geom.starty == Dictionary_Entry_Value_AsDouble( yValue ) );
}
void DictionarySuite_TestAddElement( DictionarySuiteData* data ) {
   Dictionary_Entry_Value* yValue;
   Dictionary_Entry_Value* testStruct;
   Dictionary_Entry_Value* currValue;
   double                  newVal = -45.0;

   DictionarySuite_PopulateDictWithTestValues( data->dict, data->testDD );

   /* turning the starty value into a list using add element */
   testStruct = Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_struct"  );
   yValue = Dictionary_Entry_Value_GetMember( Dictionary_Entry_Value_GetMember(testStruct, (Dictionary_Entry_Key)"geom" ), "starty");
   Dictionary_Entry_Value_AddElement( yValue, Dictionary_Entry_Value_FromDouble(newVal) );

   pcu_check_true( Dictionary_Entry_Value_Type_List == yValue->type );
   pcu_check_true( 2 == Dictionary_Entry_Value_GetCount( yValue ) );

   currValue = Dictionary_Entry_Value_GetFirstElement( yValue );
   pcu_check_le( fabs( data->testDD->testStruct->geom.starty - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 );
   currValue = currValue->next;
   pcu_check_le( fabs( newVal - Dictionary_Entry_Value_AsDouble( currValue )), 0.01 );
}
Beispiel #11
0
void _ShellGeometry_Init(
		ShellGeometry*					self )
{
	/* General and Virtual info should already be set */
	
	/* ShellGeometry info */
	self->isConstructed = True;
	self->size[0] = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_GetDefault( self->dictionary, "meshSizeI",
		Dictionary_Entry_Value_FromUnsignedInt( 2 ) ) );
	self->size[1] = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_GetDefault( self->dictionary, "meshSizeJ",
		Dictionary_Entry_Value_FromUnsignedInt( 2 ) ) );
	self->size[2] = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_GetDefault( self->dictionary, "meshSizeK",
		Dictionary_Entry_Value_FromUnsignedInt( 2 ) ) );
	self->pointCount = self->size[0] * self->size[1] * self->size[2];
	assert( self->pointCount );
	
	self->min[0] = Dictionary_Entry_Value_AsDouble( Dictionary_GetDefault( self->dictionary, "minTheta",
		Dictionary_Entry_Value_FromDouble( 2.0 * M_PI / 3.0 ) ) );
	self->min[1] = Dictionary_Entry_Value_AsDouble( Dictionary_GetDefault( self->dictionary, "minPhi",
		Dictionary_Entry_Value_FromDouble( 2.0 * M_PI / 3.0 ) ) );
	self->min[2] = Dictionary_Entry_Value_AsDouble( Dictionary_GetDefault( self->dictionary, "minR",
		Dictionary_Entry_Value_FromDouble( 0.5f ) ) );
	self->max[0] = Dictionary_Entry_Value_AsDouble( Dictionary_GetDefault( self->dictionary, "maxTheta",
		Dictionary_Entry_Value_FromDouble( M_PI / 3.0 ) ) );
	self->max[1] = Dictionary_Entry_Value_AsDouble( Dictionary_GetDefault( self->dictionary, "maxPhi",
		Dictionary_Entry_Value_FromDouble( M_PI / 3.0 ) ) );
	self->max[2] = Dictionary_Entry_Value_AsDouble( Dictionary_GetDefault( self->dictionary, "maxR",
		Dictionary_Entry_Value_FromDouble( 1.0f ) ) );
}
Beispiel #12
0
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 );
}
Dictionary_Entry_Value* Dictionary_Entry_Value_FromStringTo( char* string, char type ) {
	Dictionary_Entry_Value* retValue = Memory_Alloc( Dictionary_Entry_Value, "Return Value" );
	
	/* need to create the value temporarily so it can be converted if necessary */
	retValue->type = Dictionary_Entry_Value_Type_String;

	if ( string ) {
		retValue->as.typeString = ExpandEnvironmentVariables( string );
	}
	else {
		retValue->as.typeString = string;
	}
	
	switch (type) {
		case Dictionary_Entry_Value_Type_String:
			Dictionary_Entry_Value_InitFromString( retValue, retValue->as.typeString );
			break;
		case Dictionary_Entry_Value_Type_Double:
			Dictionary_Entry_Value_InitFromDouble( retValue, Dictionary_Entry_Value_AsDouble( retValue ) );
			break;
		case Dictionary_Entry_Value_Type_UnsignedInt:
			Dictionary_Entry_Value_InitFromUnsignedInt( retValue, Dictionary_Entry_Value_AsUnsignedInt( retValue ) );
			break;
		case Dictionary_Entry_Value_Type_Int:
			Dictionary_Entry_Value_InitFromInt( retValue, Dictionary_Entry_Value_AsInt( retValue ) );
			break;
		case Dictionary_Entry_Value_Type_UnsignedLong:
			Dictionary_Entry_Value_InitFromUnsignedLong( retValue, Dictionary_Entry_Value_AsUnsignedLong( retValue ) );
			break;
		case Dictionary_Entry_Value_Type_Bool:
			Dictionary_Entry_Value_InitFromBool( retValue, Dictionary_Entry_Value_AsBool( retValue ) );
			break;
		case Dictionary_Entry_Value_Type_Struct:
			Dictionary_Entry_Value_InitNewStruct( retValue );
			break;
		case Dictionary_Entry_Value_Type_List:
			Dictionary_Entry_Value_InitNewList( retValue );
			break;
		default: {
			Stream* errorStream = Journal_Register( Error_Type, "Dictionary_Entry_Value" );
			Journal_Firewall( False, errorStream, "In func %s: type '%d' is invalid.\n", __func__, type );
		}
	}		
	
	return retValue;
}
void Dictionary_Entry_Value_SetFromStringKeepCurrentType( Dictionary_Entry_Value* self, char* string ) {
	Dictionary_Entry_Value_Type currType = self->type;
	Dictionary_Entry_Value_DeleteContents( self );
	self->type = Dictionary_Entry_Value_Type_String;
	self->as.typeString = string;
	
	switch (currType) {
		case Dictionary_Entry_Value_Type_String:
			Dictionary_Entry_Value_SetValueString( self, string );
			break;
		case Dictionary_Entry_Value_Type_Double:
			Dictionary_Entry_Value_SetValueDouble( self, Dictionary_Entry_Value_AsDouble( self ) );
			break;
		case Dictionary_Entry_Value_Type_UnsignedInt:
			Dictionary_Entry_Value_SetValueUnsignedInt( self, Dictionary_Entry_Value_AsUnsignedInt( self ) );
			break;
		case Dictionary_Entry_Value_Type_Int:
			Dictionary_Entry_Value_SetValueInt( self, Dictionary_Entry_Value_AsInt( self ) );
			break;
		case Dictionary_Entry_Value_Type_UnsignedLong:
			Dictionary_Entry_Value_SetValueUnsignedLong( self, Dictionary_Entry_Value_AsUnsignedLong( self ) );
			break;
		case Dictionary_Entry_Value_Type_Bool:
			Dictionary_Entry_Value_SetValueBool( self, Dictionary_Entry_Value_AsBool( self ) );
			break;
		case Dictionary_Entry_Value_Type_Struct:
			Dictionary_Entry_Value_SetValueNewStruct( self );
			break;
		case Dictionary_Entry_Value_Type_List:
			Dictionary_Entry_Value_SetValueNewList( self );
			break;
		default: {
			Stream* errorStream = Journal_Register( Error_Type, "Dictionary_Entry_Value" );
			Journal_Firewall( False, errorStream, "In func %s: self->type '%d' is invalid.\n", __func__, self->type );
		}
	}
}
double Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value* self ) {
	if( !self ) {
		return 0.0f;
	}
	
	switch( self->type ) {
		case Dictionary_Entry_Value_Type_Struct:
			/* Do nothing (later will print a warning) */
			return 0;
		case Dictionary_Entry_Value_Type_List:
			/* returns the first element as an unsigned int */
			if (self->as.typeList->first) {
				return Dictionary_Entry_Value_AsDouble( self->as.typeList->first );
			} else {	
				return 0;
			}	
		case Dictionary_Entry_Value_Type_String:
			return strtod( self->as.typeString, 0 );
		case Dictionary_Entry_Value_Type_Double:
			return self->as.typeDouble;
		case Dictionary_Entry_Value_Type_UnsignedInt:
			return (double)self->as.typeUnsignedInt;
		case Dictionary_Entry_Value_Type_Int:
			return self->as.typeInt;
		case Dictionary_Entry_Value_Type_UnsignedLong:
			return self->as.typeUnsignedLong;
		case Dictionary_Entry_Value_Type_Bool:
			return (double)self->as.typeBool;
		default: {
			Stream* errorStream = Journal_Register( Error_Type, "Dictionary_Entry_Value" );
			Journal_Firewall( False, errorStream, "In func %s: self->type '%d' is invalid.\n", __func__, self->type );
		}
	}
	
	return 0.0f;
}
Beispiel #16
0
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 );
			}
		}
Beispiel #17
0
void _SnacCylinderQuad_InitialConditions( void* _context, void* data ) {
	Snac_Context*			context = (Snac_Context*)_context;
	Mesh*				mesh = context->mesh;
	MeshLayout*			layout = (MeshLayout*)mesh->layout;
	HexaMD*				decomp = (HexaMD*)layout->decomp;
	BlockGeometry*			geometry = (BlockGeometry*)layout->elementLayout->geometry;
	Node_GlobalIndex		node_gI;
	double				ri,ro,ztop,zbot;
	double				alpha,d;
#ifdef DEBUG
	printf( "In: %s\n", __func__ );
#endif

	ri = Dictionary_Entry_Value_AsDouble(Dictionary_GetDefault( context->dictionary, "cylinder_ri", Dictionary_Entry_Value_FromDouble( 3.0f ) ) );
	ro = Dictionary_Entry_Value_AsDouble(Dictionary_GetDefault( context->dictionary, "cylinder_ro", Dictionary_Entry_Value_FromDouble( 10.0f ) ) );
	zbot = Dictionary_Entry_Value_AsDouble(Dictionary_GetDefault( context->dictionary, "cylinder_zbot", Dictionary_Entry_Value_FromDouble( 0.0f ) ) );
	ztop = Dictionary_Entry_Value_AsDouble(Dictionary_GetDefault( context->dictionary, "cylinder_ztop", Dictionary_Entry_Value_FromDouble( 1.0f ) ) );
	alpha = Dictionary_Entry_Value_AsDouble(Dictionary_GetDefault( context->dictionary, "cylinder_alpha", Dictionary_Entry_Value_FromDouble( 1.1f ) ) );

	d = (ro - ri)*(alpha-1.0)/(pow(alpha,decomp->nodeGlobal3DCounts[2]-1)-1.0);
	/* apply the cylindrical initial mesh */
	for( node_gI = 0; node_gI < context->mesh->nodeGlobalCount; node_gI++ ) {
		Node_LocalIndex			node_lI = _MeshDecomp_Node_GlobalToLocal1D( decomp, node_gI );
		Index				i_gI;
		Index				j_gI;
		Index				k_gI;
		Coord*				coord = 0;
		Coord				initialRTZ,tmpCoord;
		double				rsum = 0.0f;

		/* If a local node, directly change the node coordinates and initial tpr, else use a temporary location */
		if( node_lI < context->mesh->nodeLocalCount ) { /* a local node */
			coord = Snac_NodeCoord_P( context, node_lI );
		}
		else { /* Not a local node */
			coord = &tmpCoord;
		}

		RegularMeshUtils_Node_1DTo3D( decomp, node_gI, &i_gI, &j_gI, &k_gI );

		/*               -----                   */
		/*         right |    \ front            */
		/*     z ^       --\   \                 */
		/*       |     back  |_ |                */
		/*       -->x       left                 */
		initialRTZ[0] = ri; // radius
		if(k_gI>0) rsum = (pow(alpha,k_gI)-1.0)/(alpha-1.0)*d;
		initialRTZ[0] += rsum;
		initialRTZ[1] = (90.0f/(decomp->nodeGlobal3DCounts[0]-1)*i_gI)*PI/180.0f; // theta
		initialRTZ[2] = ztop - (ztop-zbot)/(decomp->nodeGlobal3DCounts[1]-1)*j_gI; // Z

		(*coord)[0] = initialRTZ[0]*cos(initialRTZ[1]);
		(*coord)[1] = initialRTZ[2];
		(*coord)[2] = initialRTZ[0]*sin(initialRTZ[1]);

		if( node_gI == 0 ) {
			geometry->min[0] = geometry->max[0] = (*coord)[0];
			geometry->min[1] = geometry->max[1] = (*coord)[1];
			geometry->min[2] = geometry->max[2] = (*coord)[2];
		}
		else {
			if( geometry->min[0] > (*coord)[0] ) geometry->min[0] = (*coord)[0];
			if( geometry->min[1] > (*coord)[1] ) geometry->min[1] = (*coord)[1];
			if( geometry->min[2] > (*coord)[2] ) geometry->min[2] = (*coord)[2];
			if( geometry->max[0] < (*coord)[0] ) geometry->max[0] = (*coord)[0];
			if( geometry->max[1] < (*coord)[1] ) geometry->max[1] = (*coord)[1];
			if( geometry->max[2] < (*coord)[2] ) geometry->max[2] = (*coord)[2];
		}

		#ifdef DEBUG
			printf( "\tnode_lI: %2u, node_gI: %2u, i: %2u, j: %2u, k: %2u, r: %8g, theta: %8g, z: %8g,",
				node_lI,
				node_gI,
				i_gI,
				j_gI,
				k_gI,
				initialRTZ[0],
				initialRTZ[1],
				initialRTZ[2] );
			printf( "x: %12g, y: %12g, z: %12g\n", (*coord)[0], (*coord)[1], (*coord)[2] );
		#endif
	}
}
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;
}
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();
	}
}
double Stg_ComponentFactory_PluginGetDouble( void* cf, void *codelet, Dictionary_Entry_Key key, double defaultVal ) {
   return Dictionary_Entry_Value_AsDouble( 
                _Stg_ComponentFactory_PluginGetNumericalValue( cf, codelet, key, 
                                                               Dictionary_Entry_Value_FromDouble( defaultVal )));
}
Beispiel #21
0
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 );
			}
		}
double _Stg_ComponentFactory_GetDouble( void* cf, Name componentName, Dictionary_Entry_Key key, double defaultVal ) {
   return Dictionary_Entry_Value_AsDouble( 
         _Stg_ComponentFactory_GetNumericalValue( cf, componentName, key, 
            Dictionary_Entry_Value_FromDouble( defaultVal )));
}
Bool Dictionary_Entry_Value_CompareFull( Dictionary_Entry_Value* self, Dictionary_Entry_Value* dev, Bool strictTypeCheck ) {
	Bool         retValue = True; 
	Stream*      errorStream = Journal_Register( Error_Type, "Dictionary_Entry_Value" );

	if ( strictTypeCheck ) {
		if ( self->type != dev->type ) {
			return False;
		}
	}

	switch( self->type ) {
		case Dictionary_Entry_Value_Type_String: {
			/* Comparing as strings is tricky. When both are strings it's fine. If the dev to compare to is stored
			 * natively as a number, we should convert the first to a number also for comparison. Otherwise, you
			 * can get false Negatives when the entries are numerically the same, but use different notation
			 * (e.g. scientific vs decimal) */ 	
			switch( dev->type ) {
				case Dictionary_Entry_Value_Type_String:
					if ( 0 != strcmp( self->as.typeString, dev->as.typeString ) ) 
						retValue = False;
					break;
				case Dictionary_Entry_Value_Type_Double:
					if ( dev->as.typeDouble != Dictionary_Entry_Value_AsDouble( self ) )
						retValue = False;
					break;
				case Dictionary_Entry_Value_Type_UnsignedInt:
					if ( dev->as.typeUnsignedInt != Dictionary_Entry_Value_AsUnsignedInt( self ) )
						retValue = False;
					break;
				case Dictionary_Entry_Value_Type_Int:
					if ( dev->as.typeInt != Dictionary_Entry_Value_AsInt( self ) )
						retValue = False;
					break;
				case Dictionary_Entry_Value_Type_UnsignedLong:
					if ( dev->as.typeUnsignedLong != Dictionary_Entry_Value_AsUnsignedLong( self ) )
						retValue = False;
					break;
				case Dictionary_Entry_Value_Type_Bool:
					if ( dev->as.typeBool != Dictionary_Entry_Value_AsBool( self ) )
				case Dictionary_Entry_Value_Type_Struct:
				case Dictionary_Entry_Value_Type_List:
					retValue = False;
					break;
				default:
					Journal_Firewall( False, errorStream, "In func %s: dev->type '%d' is invalid.\n", __func__, dev->type );
			}
			break;
		}
		case Dictionary_Entry_Value_Type_Double:
			if ( self->as.typeDouble != Dictionary_Entry_Value_AsDouble( dev ) )
				retValue = False;
			break;
		case Dictionary_Entry_Value_Type_UnsignedInt:
			if ( self->as.typeUnsignedInt != Dictionary_Entry_Value_AsUnsignedInt( dev ) )
				retValue = False;
			break;
		case Dictionary_Entry_Value_Type_Int:
			if ( self->as.typeInt != Dictionary_Entry_Value_AsInt( dev ) )
				retValue = False;
			break;
		case Dictionary_Entry_Value_Type_UnsignedLong:
			if ( self->as.typeUnsignedLong != Dictionary_Entry_Value_AsUnsignedLong( dev ) )
				retValue = False;
			break;
		case Dictionary_Entry_Value_Type_Bool:
			if ( self->as.typeBool != Dictionary_Entry_Value_AsBool( dev ) )
				retValue = False;
			break;
		case Dictionary_Entry_Value_Type_Struct:
			if ( dev->type != Dictionary_Entry_Value_Type_Struct ) {
				retValue = False;
				break;
			}
			retValue = Dictionary_CompareAllEntriesFull( self->as.typeStruct, dev->as.typeStruct, strictTypeCheck );
			break;
		case Dictionary_Entry_Value_Type_List: {
			Dictionary_Entry_Value* cur1 = NULL;
			Dictionary_Entry_Value* cur2 = NULL;

			if ( dev->type != Dictionary_Entry_Value_Type_List ) {
				retValue = False;
				break;
			}
			if ( self->as.typeList->count != dev->as.typeList->count ) {
				retValue = False;
				break;
			}
			cur1 = self->as.typeList->first;
			cur2 = dev->as.typeList->first;
			while ( cur1 ) {
				retValue = Dictionary_Entry_Value_CompareFull( cur1, cur2, strictTypeCheck );
				if ( retValue == False ) break;
				cur1 = cur1->next;
				cur2 = cur2->next;
			}	
			break;
		}
		default:
			Journal_Firewall( False, errorStream, "In func %s: self->type '%d' is invalid.\n", __func__, self->type );
	};

	return retValue;
}
/*----------------------------------------------------------------------------------------------------------
** 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 );
}
Bool Stg_ComponentFactory_TryDouble( void* cf, Name componentName, Dictionary_Entry_Key key, double* value ) {
   Dictionary_Entry_Value* dict_value = _Stg_ComponentFactory_GetNumericalValue( cf, componentName, key, NULL);
   if (!dict_value) return False;
   *value = Dictionary_Entry_Value_AsDouble(dict_value);
   return True;
}
void _SnacHillSlope_ConstructExtensions( void* _context, void* data ) {
	Snac_Context*				context = (Snac_Context*)_context;
	SnacHillSlope_Context*			contextExt = ExtensionManager_Get(
								context->extensionMgr,
								context,
								SnacHillSlope_ContextHandle );
/* 	Dictionary*				hillSlopeBCsDict; */
/* 	char					tmpBuf[PATH_MAX]; */

	/* Because hillSlope is not an array by itself, we must the "complex" constructor for Variable... the info needs to be
	 * wrapped this generic way... */
/* 	Index					hillSlopeOffsetCount = 1; */
/*  	SizeT					hillSlopeOffsets[] = { (SizeT)((char*)&tmpNodeExt->hillSlope - (char*)&tmpNode) };  */
/* 	Variable_DataType			hillSlopeDataTypes[] = { Variable_DataType_Double }; */
/* 	Index					hillSlopeDataTypeCounts[] = { 1 }; */
	#ifdef DEBUG
		printf( "In %s()\n", __func__ );
	#endif


	/* Create the StGermain variable hillSlope, which is stored on a node extension */
/* 	Variable_New(  */
/* 		"hillSlope",  */
/* 		hillSlopeOffsetCount,  */
/* 		hillSlopeOffsets,  */
/* 		hillSlopeDataTypes,  */
/* 		hillSlopeDataTypeCounts,  */
/* 		0,  */
/* 		&ExtensionManager_GetFinalSize( context->mesh->nodeExtensionMgr ), */
/* 		&context->mesh->layout->decomp->nodeDomainCount, */
/* 		(void**)&context->mesh->node, */
/* 		context->variable_Register ); */



	/* HillSlope variables */
	contextExt->slopeAngle = Dictionary_Entry_Value_AsDouble(
		Dictionary_GetDefault( context->dictionary, "slopeAngle", Dictionary_Entry_Value_FromDouble( 30.0f ) ) );

/* 	contextExt->rngSeed = Dictionary_Entry_Value_AsUnsignedInt( */
/* 		Dictionary_GetDefault( context->dictionary, "rngSeed", Dictionary_Entry_Value_FromUnsignedInt( 1 ) ) ); */

/* 	contextExt->fractionPlasticSeeds = Dictionary_Entry_Value_AsDouble( */
/* 		Dictionary_GetDefault( context->dictionary, "fractionPlasticSeeds", Dictionary_Entry_Value_FromDouble( 0.02f ) ) ); */




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


/* 	#ifdef DEBUG */
/* 		fprintf( stderr, "In %s()\n", __func__ ); */
/* 	#endif */

/* 	Journal_Printf( context->debug, "slopeAngle:  %g\n", contextExt->slopeAngle ); */

}