Exemplo n.º 1
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 ) ) );
}
Exemplo n.º 2
0
Dictionary_Entry_Value* _Dictionary_GetDouble_WithScopeDefault(
   Dictionary*             dictionary,
   Dictionary_Entry_Key    key,
   Dictionary_Entry_Value* defaultVal )
{
   Dictionary_Entry_Value *returnVal=NULL;
   Bool                    usedDefault = False;
   Stream*                 stream = Journal_Register( Info_Type, "Dictionary" );

   returnVal = Dictionary_GetDefault( dictionary, key, defaultVal );

   if( returnVal && returnVal->type == Dictionary_Entry_Value_Type_String ) { 
      Dictionary_Entry_Key rootDictKey = Dictionary_Entry_Value_AsString( returnVal ); 
      Dictionary*          rootDict    = dictionary; 

      /* Check if the number really is a string or not */ 
      if( Stg_StringIsNumeric( rootDictKey ) ) 
         return returnVal; 

      Journal_PrintfL(
         stream,
         2,
         "Key '%s' points to key '%s' in the root dictionary: ",
         key,
         rootDictKey ); 

      /* Get Value from dictionary */ 
      returnVal = Dictionary_Get( rootDict, rootDictKey ); 
      if( !returnVal && defaultVal ) { 
         returnVal = Dictionary_GetDefault( rootDict, rootDictKey, 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;
}
void _TriGaussParticleLayout_AssignFromXML( void* triGaussParticleLayout, Stg_ComponentFactory* cf, void* data ){
	TriGaussParticleLayout *self = (TriGaussParticleLayout*)triGaussParticleLayout;
	unsigned int dim;
	unsigned int particlesPerCell;

   _PerCellParticleLayout_AssignFromXML( self, cf, data );
	dim = Dictionary_Entry_Value_AsUnsignedInt(
		Dictionary_GetDefault( cf->rootDict, "dim", Dictionary_Entry_Value_FromUnsignedInt( 3 ) ) );

	particlesPerCell = Dictionary_Entry_Value_AsUnsignedInt(
		Dictionary_GetDefault( cf->rootDict, "particlesPerCell", Dictionary_Entry_Value_FromUnsignedInt( 1 ) ) );

	_TriGaussParticleLayout_Init( self, dim, particlesPerCell );
}
Exemplo n.º 4
0
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. */

}
Exemplo n.º 5
0
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 ) ) );
}
Exemplo n.º 6
0
int Dictionary_GetInt_WithDefault(
   Dictionary*          dictionary,
   Dictionary_Entry_Key key,
   const int            defaultVal )
{
   return Dictionary_Entry_Value_AsInt( 
      Dictionary_GetDefault(
         dictionary, key, Dictionary_Entry_Value_FromInt( defaultVal ) ) );
}
Exemplo n.º 7
0
int Dictionary_GetUnsignedInt_WithDefault(
   Dictionary*          dictionary,
   Dictionary_Entry_Key key,
   const unsigned int   defaultVal )
{
   return Dictionary_Entry_Value_AsUnsignedInt( 
      Dictionary_GetDefault(
         dictionary, key, Dictionary_Entry_Value_FromUnsignedInt( defaultVal ) ) );
}
Exemplo n.º 8
0
char* Dictionary_GetString_WithDefault(
   Dictionary*          dictionary,
   Dictionary_Entry_Key key,
   const char* const    defaultVal )
{
   return Dictionary_Entry_Value_AsString( 
      Dictionary_GetDefault(
         dictionary, key, Dictionary_Entry_Value_FromString( defaultVal ) ) );
}
Exemplo n.º 9
0
Bool Dictionary_GetBool_WithDefault(
   Dictionary*          dictionary,
   Dictionary_Entry_Key key,
   const Bool           defaultVal )
{
   return Dictionary_Entry_Value_AsBool( 
      Dictionary_GetDefault(
         dictionary, key, Dictionary_Entry_Value_FromBool( defaultVal ) ) );
}
Exemplo n.º 10
0
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 ) ) );
}
Exemplo n.º 11
0
unsigned long Dictionary_GetUnsignedLong_WithDefault(
   Dictionary*          dictionary,
   Dictionary_Entry_Key key,
   const unsigned long  defaultVal )
{
   return Dictionary_Entry_Value_AsUnsignedLong( 
      Dictionary_GetDefault(
         dictionary, key, Dictionary_Entry_Value_FromUnsignedLong( defaultVal ) ) );
}
void _UnderworldContext_Init( UnderworldContext* self ) {
	self->isConstructed = True;

	/* always generate XDMF files when we generate HDF5 checkpoints */
#ifdef WRITE_HDF5
	if( Dictionary_Entry_Value_AsBool( Dictionary_GetDefault( self->dictionary, "generateXDMF", Dictionary_Entry_Value_FromBool( True ) ) ) ){
		ContextEP_Append( self, AbstractContext_EP_Save, XDMFGenerator_GenerateAll );
		ContextEP_Append( self, AbstractContext_EP_DataSave, XDMFGenerator_GenerateAll );

      if( Dictionary_Entry_Value_AsInt( Dictionary_GetDefault( self->dictionary, "checkpointEvery"    , Dictionary_Entry_Value_FromInt( 0 ) ) )  ||
          Dictionary_Entry_Value_AsInt( Dictionary_GetDefault( self->dictionary, "saveDataEvery"      , Dictionary_Entry_Value_FromInt( 0 ) ) )	 ||
          Dictionary_Entry_Value_AsInt( Dictionary_GetDefault( self->dictionary, "checkpointAtTimeInc", Dictionary_Entry_Value_FromInt( 0 ) ) )
            ){
            ContextEP_Append( self, AbstractContext_EP_Build, XDMFGenerator_GenerateTemporalTopLevel );
      }
	}
#endif
   
}
Exemplo n.º 13
0
Dictionary_Entry_Value* _Stg_ComponentFactory_PluginGetNumericalValue( void* cf, void *codelet, Dictionary_Entry_Key key, Dictionary_Entry_Value* defaultVal ) {
   Stg_ComponentFactory*    self           = (Stg_ComponentFactory*)cf;
   Dictionary_Entry_Value* returnVal;
   Bool                    usedDefault       = False;
   Stream*                 stream            = self->infoStream;
   Stream*         errorStream       = Journal_Register( Error_Type, self->type );

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

   returnVal = _Stg_ComponentFactory_PluginGetDictionaryValue( self, codelet, key, defaultVal );

   /* Check to see whether the type is a string -
    * if it is then assume that this is a dictionary key linking to the root dictionary */
   if ( returnVal ) {
      Dictionary_Entry_Key rootDictKey = Dictionary_Entry_Value_AsString( returnVal );
      Dictionary*          rootDict    = self->rootDict;

      /* Check if the number really is a string or not */
      if ( Stg_StringIsNumeric( rootDictKey ) )
         return returnVal;
      
      Journal_PrintfL( stream, 2, "Key '%s' points to key '%s' in the root dictionary: ", key, rootDictKey );

      Journal_Firewall( rootDict != NULL, errorStream, "Root Dictionary NULL in component factory.\n" );

      /* Get Value from dictionary */
      returnVal = Dictionary_Get( rootDict, rootDictKey );
      if ( !returnVal && defaultVal ) {
         returnVal = Dictionary_GetDefault( rootDict, rootDictKey, 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;
}
Exemplo n.º 14
0
Dictionary_Entry_Value* _Stg_ComponentFactory_GetDictionaryValue( void* cf, Name componentName, Dictionary_Entry_Key key, Dictionary_Entry_Value* defaultVal ) {
   Stg_ComponentFactory*       self              = (Stg_ComponentFactory*) cf;
   Dictionary*             componentDict     = NULL;
   Dictionary*             thisComponentDict = NULL;
   Dictionary_Entry_Value* returnVal;
   Bool                    usedDefault       = False;
   Stream*                 errorStream       = Journal_Register( Error_Type, Stg_Component_Type );
   Stream*                 stream            = self->infoStream;

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

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

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

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

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

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

   return returnVal;
}
Exemplo n.º 15
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;
}
Exemplo n.º 16
0
void stgGenerateFlattenedXML( Dictionary* dictionary, Dictionary* sources, char* timeStamp ) {
   XML_IO_Handler* ioHandler;
   char*           outputPath;
   char*           flatFilename;
   char*           flatFilenameStamped;
   char*           slimFilename;
   Stream*         s;
   Bool            isEnabled;
   Bool            ret;
   Bool            outputSlim;

   s = Journal_Register( Info_Type, (Name)XML_IO_Handler_Type );

   /* Avoid confusing messages from XML_IO_Handler. Turn it off temporarily. */
   isEnabled = Stream_IsEnable( s );
   Stream_EnableSelfOnly( s, False );

   ioHandler = XML_IO_Handler_New();
   if( sources == NULL )
      ioHandler->writeSources = False;
   outputPath = StG_Strdup( Dictionary_Entry_Value_AsString( Dictionary_GetDefault( dictionary,
      (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString( "./" ) ) ) );
   outputSlim = Dictionary_Entry_Value_AsBool( Dictionary_GetDefault( dictionary,
      (Dictionary_Entry_Key)"outputSlimmedXML", Dictionary_Entry_Value_FromBool( True ) ) );

   if( ! Stg_DirectoryExists( outputPath ) ) {
      if( Stg_FileExists( outputPath ) )
         Journal_Firewall( 0, s, "outputPath '%s' is a file an not a directory! Exiting...\n", outputPath );

      Journal_Printf( s, "outputPath '%s' does not exist, attempting to create...\n", outputPath );
      ret = Stg_CreateDirectory( outputPath );
      Journal_Firewall( ret, s, "Unable to create non-existing outputPath to '%s'\n", outputPath );
      Journal_Printf( s, "outputPath '%s' successfully created!\n", outputPath );
   }

   /* Set file names. */
   Stg_asprintf( &flatFilename, "%s/%s", outputPath, "input.xml" );

   IO_Handler_WriteAllToFile( ioHandler, flatFilename, dictionary, sources );

   /* Format; path/input-YYYY.MM.DD-HH.MM.SS.xml. */
   if (timeStamp) {
      Stg_asprintf( &flatFilenameStamped, "%s/%s-%s.%s",
                   outputPath, "input", timeStamp, "xml" );
      IO_Handler_WriteAllToFile( ioHandler, flatFilenameStamped, dictionary, sources );
      Memory_Free( flatFilenameStamped );
   }

   
   if( outputSlim && timeStamp ) {
      ioHandler->writeSources = False;
      Stg_asprintf( &slimFilename, "%s/%s-%s.%s",
         outputPath, "input-basic", timeStamp, "xml" );
      IO_Handler_WriteAllToFile( ioHandler, slimFilename, dictionary, NULL);
   }

   Stream_EnableSelfOnly( s, isEnabled );
   Stg_Class_Delete( ioHandler );

   Memory_Free( flatFilename );
}
Exemplo n.º 17
0
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 ); */

}
Exemplo n.º 18
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
	}
}
Exemplo n.º 19
0
void _SnacRemesher_ConstructExtensions( void* _context, void* data ) {
	Snac_Context*				context = (Snac_Context*)_context;
	SnacRemesher_Context*			contextExt = ExtensionManager_Get(
							context->extensionMgr,
							context,
							SnacRemesher_ContextHandle );
	Mesh*					mesh = context->mesh;
	SnacRemesher_Mesh*			meshExt = ExtensionManager_Get(
							context->meshExtensionMgr,
							mesh,
							SnacRemesher_MeshHandle );
	char*					conditionStr;
	Dictionary_Entry_Value*			conditionCriterion;
	Dictionary* 				meshDict;
	Stream*					error = Journal_Register( Error_Type, "Remesher" );
	char					tmpBuf[PATH_MAX];

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


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

	/* Prepare the dump file */
	if( context->rank == 0) {
		sprintf( tmpBuf, "%s/remeshInfo.%u", context->outputPath, context->rank );
		if( (contextExt->remesherOut = fopen( tmpBuf, "w+" )) == NULL ) {
			assert( contextExt->remesherOut /* failed to open file for writing */ );
		}
	}
	/* initialize remeshing counter */
	contextExt->remeshingCount = 0;
}
Exemplo n.º 20
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();
	}
}