示例#1
0
void _Geothermal_DepthMap_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
   Geothermal_DepthMap* self = (Geothermal_DepthMap*)component;
   Dictionary*          dictionary = Codelet_GetPluginDictionary( component, cf->rootDict );
   Stream*              errorStream = Journal_Register( ErrorStream_Type, Geothermal_DepthMap_Type );
	
   Stream_SetPrintingRank( errorStream, 0 );
   Journal_Printf( errorStream, "WARNING: \"DepthMap\" plugin is depricated, use \"FieldMap\" plugin instead" );

   self->swarm = Stg_ComponentFactory_ConstructByName(
      cf, Dictionary_GetString( dictionary, "Swarm" ), Swarm, True, data );

   self->context = (AbstractContext*)Stg_ComponentFactory_ConstructByName(
      cf, "context", UnderworldContext, True, data ); 

   self->depth = Dictionary_GetDouble_WithDefault( dictionary, (Dictionary_Entry_Key)"DepthFromSurface", 0.0 );
   self->outputPath = Dictionary_GetString_WithDefault( dictionary, (Dictionary_Entry_Key)"outputPath", "./output" );
   self->outputAllNodes = Dictionary_GetBool_WithDefault( dictionary, (Dictionary_Entry_Key)"OutputAllNodes", False );
   self->outputTopNodes = Dictionary_GetBool_WithDefault( dictionary, (Dictionary_Entry_Key)"OutputTopNodes", False );
   self->gocadOutput = Dictionary_GetBool_WithDefault( dictionary, (Dictionary_Entry_Key)"GOCADOutput", True );
   self->outputPath = Dictionary_Entry_Value_AsString( Dictionary_Get( dictionary, "outputPath" ) );

   self->field = Stg_ComponentFactory_ConstructByName(
      cf, Dictionary_GetString( dictionary, "Field" ), FeVariable, True, data );

   ContextEP_Append( self->context, AbstractContext_EP_Dump, Geothermal_DepthMap_Dump );
}
char* _Stg_ComponentFactory_GetRootDictString( void* cf, Dictionary_Entry_Key key, const char* const defaultVal ) {
   Stg_ComponentFactory*    self              = (Stg_ComponentFactory*)cf;

   Journal_PrintfL( self->infoStream, 2, "Getting string from root dictionary with key '%s' and default value '%s'\n",
         key, defaultVal );

   assert( self->rootDict );
   return Dictionary_GetString_WithDefault( self->rootDict, key, defaultVal );
}
void DictionarySuite_TestShortcuts( DictionarySuiteData* data ) {

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

   /* Testing GetString_WithDefault. If an entry with that key already exists, then
    *  the value of the existing key should be returned, and the default passed in
    *  ignored. However if the given key _doesn't_ exist, the default should be 
    *  returned, and a new entry with the given key added to the dict. */
   pcu_check_streq( data->testDD->testString, Dictionary_GetString_WithDefault( data->dict, "test_cstring", "heya" ) );
   pcu_check_streq( "heya", Dictionary_GetString_WithDefault( data->dict, "test_cstring2", "heya" ) );
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_cstring2" )  );
	data->testDD->testDouble = Dictionary_GetDouble_WithDefault( data->dict, (Dictionary_Entry_Key)"test_double", 2.8 );
   pcu_check_true( data->testDD->testDouble );
   pcu_check_true( 2.8 == Dictionary_GetDouble_WithDefault( data->dict, (Dictionary_Entry_Key)"test_double2", 2.8 )  );

   /* test_placeholder refers to test_double which equals 45.567 */
   pcu_check_true( 45.567 == Dictionary_GetDouble_WithScopeDefault( data->dict, (Dictionary_Entry_Key)"test_placeholder", -1 )  );
   
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_double2" )  );
   data->testDD->testUint = Dictionary_GetUnsignedInt_WithDefault( data->dict, "test_uint", 33 );
	pcu_check_true( data->testDD->testUint );
   pcu_check_true( 33 == Dictionary_GetUnsignedInt_WithDefault( data->dict, "test_uint2", 33 ) );
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_uint2" )  );
   data->testDD->testInt = Dictionary_GetInt_WithDefault( data->dict, (Dictionary_Entry_Key)"test_int", -24 );
	pcu_check_true( data->testDD->testInt );
   pcu_check_true( -24 == Dictionary_GetInt_WithDefault( data->dict, (Dictionary_Entry_Key)"test_int2", -24 )  );
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_int2" )  );
   data->testDD->testUnsignedlong = Dictionary_GetUnsignedLong_WithDefault( data->dict, "test_unsignedlong", 32433 );
	pcu_check_true( data->testDD->testUnsignedlong );
   pcu_check_true( 32433 == Dictionary_GetUnsignedLong_WithDefault( data->dict, "test_unsignedlong2", 32433 ) );
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_unsignedlong2" )  );
   data->testDD->testBool = Dictionary_GetBool_WithDefault( data->dict, (Dictionary_Entry_Key)"test_bool", False );
	pcu_check_true( data->testDD->testBool );
   pcu_check_true( False == Dictionary_GetBool_WithDefault( data->dict, (Dictionary_Entry_Key)"test_bool2", False )  );
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_bool2" )  );

   pcu_check_streq( data->testDD->testString, Dictionary_GetString_WithPrintfDefault( data->dict, "test_cstring", "heya%s%u", "hey", 3 ) );
   pcu_check_streq( "heyahey3", Dictionary_GetString_WithPrintfDefault( data->dict, "test_cstring3", "heya%s%u", "hey", 3 ) );
   pcu_check_true( NULL != Dictionary_Get( data->dict, (Dictionary_Entry_Key)"test_cstring3" ) );
}
Stg_Component* _Stg_ComponentFactory_ConstructByName( void* cf, Name componentName, Type type, Bool isEssential, void* data ) {
   Stg_ComponentFactory*   self              = (Stg_ComponentFactory*)cf;
   Stg_Component*      component;
   Stream*         stream            = self->infoStream;

   Journal_PrintfL( stream, 2, "Looking for %sessential component '%s': ", (isEssential ? "" : "non-"), componentName );

   component = LiveComponentRegister_Get( self->LCRegister, componentName );

   /* Checking */
   if (component) {
      Journal_PrintfL( stream, 2, "Found.\n" );

      if ( !component->isConstructed ) {
         /* Journal_Printf( stream, "%s has not been constructed yet. Constructing now.\n", componentName ); */
         Stream_Indent( stream );
         Stg_Component_AssignFromXML( component, self, data, True );
         Stream_UnIndent( stream );
      }

      Stg_Class_CheckType( component, type );

   }
   else {
      Name         redirect;

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

      Journal_PrintfL( stream, 2, "Not found.\n" );

      if ( isEssential ) {
         Stream* errorStream = Journal_Register( Error_Type, self->type );

         Journal_Printf( errorStream, "In func %s: Cannot find essential component '%s'.\n", __func__, componentName );

         Journal_Printf( errorStream, "Could you have meant one of these?\n" );

         Stream_Indent( errorStream );
         LiveComponentRegister_PrintSimilar( self->LCRegister, componentName, errorStream, 5 );
         Journal_Firewall( 0, errorStream, "" );
      }
   }
   
   return component;
}
Stg_Component* _Stg_ComponentFactory_PluginConstructByKey( 
   void*                  cf, 
   void*                  codelet, 
   Dictionary_Entry_Key   componentKey,
   Type                  type, 
   Bool                  isEssential,
   void*                  data ) 
{
   Stg_ComponentFactory*   self = (Stg_ComponentFactory*)cf;
   Stg_Component*            plugin = (Stg_Component*)codelet;
   Dictionary*               thisPluginDict = NULL;
   Dictionary*               pluginDict = (Dictionary*)Dictionary_Get( self->rootDict, "plugins" );
   Name                     componentName, redirect, pluginType;
   Dictionary_Entry_Value*   componentEntryVal;
   Index                     pluginIndex;
   Stream*                  errorStream = Journal_Register( Error_Type, self->type );

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

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

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

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

   return self->constructByName( self, componentName, type, isEssential, data );
}
Stg_Component* _Stg_ComponentFactory_ConstructByKey( 
      void*         cf, 
      Name         parentComponentName, 
      Dictionary_Entry_Key   componentKey,
      Type         type, 
      Bool          isEssential,
      void*          data ) 
{
   Stg_ComponentFactory*   self              = (Stg_ComponentFactory*)cf;
   Dictionary*      thisComponentDict = NULL;
   Dictionary*      componentDict     = NULL;
   Name         componentName, redirect;
   Dictionary_Entry_Value*   componentEntryVal;
   Stream*         errorStream       = Journal_Register( Error_Type, self->type );

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

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

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

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

   return self->constructByName( self, componentName, type, isEssential, data );
}
char* Dictionary_GetString_WithPrintfDefault(
   Dictionary*          dictionary,
   Dictionary_Entry_Key key,
   char*                format,
   ... )
{
   char*   returnString;
   char*   defaultVal;
   va_list ap;
   
   va_start( ap, format );

   /* Create Default String from format arguments */
   Stg_vasprintf( &defaultVal, format, ap );

   /* Read Dictionary */
   returnString = Dictionary_GetString_WithDefault( dictionary, key, defaultVal );

   /* Clean up */
   Memory_Free( defaultVal );
   va_end( ap );

   return returnString;
}
void Experimental_NodeTempProfile( PICelleratorContext* context ) {
#if 0
	static FeVariable*          temperatureFe;
	FiniteElement_Mesh*         mesh;
	double*                     nodeCoord;
	double                      lmaxTemp, nodeTemp;
	Index                       lNode_I, newNodeID;
	int                         startProfileNodeID; 
	static Bool                 beenHere              = False;
	Stream*                     stream                = Journal_Register( Info_Type, (Name)"TempNodeHeight"  );
	char*                       filename;
	double*                     maxTempList = Memory_Alloc_Array( double, context->nproc, "Hold the max temperature of each array");
	unsigned                    rootProc;
	
	rootProc = 0;
	if (!beenHere) {
		Name                 tempFeName;
		tempFeName = Dictionary_GetString_WithDefault( context->dictionary, "TemperatureField", "TemperatureField" );
		
		/* Get TemperatureField FeVariable */
		temperatureFe = (FeVariable*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)tempFeName );
		assert( temperatureFe  );
	
		/* Set up stream */
		Stg_asprintf( &filename, "CylinderNodeProfiling.%dof%d.dat", context->rank, context->nproc );
		Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, filename );
		Memory_Free( filename );
		Stream_SetAutoFlush( stream, True );

		/* Print header to stream */
		Journal_Printf( stream, "Timestep\tCentralPosition\t\tNodeTemperature\n" );
		beenHere = True;
	}
	mesh = temperatureFe->feMesh;
	
	for( lNode_I = 0; lNode_I < temperatureFe->feMesh->nodeLocalCount ; lNode_I++ ) {
		nodeTemp = FeVariable_GetScalarAtNode( temperatureFe , lNode_I );
		if( lNode_I == 0 ) {
			lmaxTemp = nodeTemp;
			startProfileNodeID = lNode_I;
		}
		if ( nodeTemp > lmaxTemp ) {
			lmaxTemp = nodeTemp;
			startProfileNodeID = lNode_I;
		}
	}
	MPI_Gather( &lmaxTemp, 1, MPI_DOUBLE, maxTempList, 1, MPI_DOUBLE, rootProc, context->communicator );

	Journal_Printf( stream, "%.6g   ******************************\n", (double)context->timeStep );
	nodeCoord = Mesh_CoordAt( mesh , startProfileNodeID );
	nodeTemp  = FeVariable_GetScalarAtNode( temperatureFe, startProfileNodeID );
	Journal_Printf( stream, "\t\tNode Profile in Y direction, starting at (%.6g, %.6g, %.6g)\tat temperature = %g\n",
				nodeCoord[0], nodeCoord[1], nodeCoord[2], nodeTemp );

	newNodeID = mesh->nodeNeighbourTbl[ startProfileNodeID ][ 1 ]; /* 1 = +y direction, 2 = +z direction */
	if( newNodeID >= mesh->nodeLocalCount ) { /* is node NOT a local, thus stop profiling */
		Journal_Printf( stream, "\t\tProfiling has reached the boundary of the local processor\n");
	} else {  /* continue profiling */
		nodeTemp = FeVariable_GetScalarAtNode( temperatureFe, newNodeID );
		while( nodeTemp > 0.0 ) {
			nodeCoord = Mesh_CoordAt( mesh, newNodeID );
			Journal_Printf( stream, "\t\t (%.6g, %.6g, %.6g)\tat temperature = %g\n", nodeCoord[0], nodeCoord[1], nodeCoord[2], nodeTemp );
			newNodeID = mesh->nodeNeighbourTbl[ newNodeID ][ 1 ];
			if( newNodeID >= mesh->nodeLocalCount ) {
                          /* is node not a local i.e. not on processor, tus stop profiling	 */
				Journal_Printf( stream, "\t\tProfiling has reached the boundary of the local processor\n");
				break;
			}
			nodeTemp = FeVariable_GetScalarAtNode( temperatureFe, newNodeID );
		}
	}
	Memory_Free( maxTempList );
	MPI_Barrier( context->communicator );
#endif
}
示例#9
0
void _MeshDecomp_Init(
		MeshDecomp*					self,
		MPI_Comm					communicator,
		ElementLayout*					elementLayout,
		NodeLayout*					nodeLayout,
		Stg_ObjectList*             pointer_Register )
{
	/* General and Virtual info should already be set */
	
	/* MeshDecomp info */
	char*   storageStr;
	
	self->isConstructed = True;
	self->communicator = communicator;
	
	MPI_Comm_rank( self->communicator, (int*)&self->rank );
	MPI_Comm_size( self->communicator, (int*)&self->nproc );
	self->procsInUse = 0;
	
	self->allowUnusedCPUs = Dictionary_GetBool_WithDefault( self->dictionary, "allowUnusedCPUs", False ) ;
	self->allowPartitionOnNode = Dictionary_GetBool_WithDefault( self->dictionary, "allowPartitionOnNode", True );
	self->allowPartitionOnElement = Dictionary_GetBool_WithDefault( self->dictionary, "allowPartitionOnElement", False );

	assert( self->allowPartitionOnNode || self->allowPartitionOnElement );

	self->allowUnbalancing = Dictionary_GetBool_WithDefault( self->dictionary, "allowUnbalancing", False );

	self->procTopology = NULL;
	
	/* Determine IndexSet storage type */
	storageStr = Dictionary_GetString_WithDefault( self->dictionary, "selfStorage", "storeNeighbours" );
	if( !strcmp( storageStr, "storeAll" ) ) {
		self->storage = StoreAll;
	}
	else if( !strcmp( storageStr, "storeSelf" ) ) {
		self->storage = StoreSelf;
	}
	else { /* !strcmp( storageStr, "storeNeighbours" ) */
		self->storage = StoreNeighbours;
	}
	
	self->elementLayout = elementLayout;
	self->nodeLayout = nodeLayout;
	self->localElementSets = NULL;
	self->shadowElementSets = NULL;
	self->localNodeSets = NULL;
	self->shadowNodeSets = NULL;
	
	self->nodeGlobalCount = 0;
	self->nodeLocalCount = 0;
	self->nodeShadowCount = 0;
	self->nodeDomainCount = 0;
	
	self->elementGlobalCount = 0;
	self->elementLocalCount = 0;
	self->elementShadowCount = 0;
	self->elementDomainCount = 0;

	/* TODO - Hack: Registering pointer to node domain count */
	if (pointer_Register) {
		Name nodeDomainCountName;

		Stg_asprintf( &nodeDomainCountName, "%s-nodeDomainCount", self->name );  /* Need to free memory somewhere! */
		Stg_ObjectList_GlobalPointerAppend( pointer_Register, &self->nodeDomainCount, nodeDomainCountName );
	}
}