Пример #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 );
}
void _AnalyticFeVariable_AssignFromXML( void* analyticFeVariable, Stg_ComponentFactory* cf, void* data ) {
   AnalyticFeVariable* self = (AnalyticFeVariable*)analyticFeVariable;
   Dictionary*         dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
   Name                numericFieldName;
   Name                functionName;
   FeVariable*         numericField = NULL;

   /* 
    * NOTE:
    * This component is a special case where it calls its ancestor's *_AssignFromXML
    * instead of its immediate parent's. This is because we don't want to re-declare 
    * the required FeVariable parameters in this component's XML block.
    */
   _FieldVariable_AssignFromXML( self, cf, data );

   numericFieldName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"NumericField" );
   numericField = (FeVariable*)LiveComponentRegister_Get( cf->LCRegister, numericFieldName );

   if( !numericField ) 
      numericField = Stg_ComponentFactory_ConstructByName( cf, (Name)numericFieldName,
         FeVariable, True, data );

   functionName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"Function" );

   /* 
    * NOTE:
    * The parent's *_Init function needs to be called to initialise
    * FeVariable-specific attributes.
    */
   _FeVariable_Init( (FeVariable*)self, numericField->feMesh, NULL,
      NULL, False, NULL, NULL, NULL, True, False );

   _AnalyticFeVariable_Init( self, functionName, numericField );
}
Пример #3
0
void _StgFEM_Document_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
   Codelet*           self = (Codelet*)component;
   AbstractContext*   context;
   ConditionFunction* condFunc;
   Dictionary*        pluginDict = Codelet_GetPluginDictionary( component, cf->rootDict );
   DocumentationComponentFactory* dcf;
   Stream* componentListStream;

   context = (AbstractContext*)Stg_ComponentFactory_ConstructByName(
      cf,
      Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"Context" ),
      AbstractContext,
      True,
      data );


   /* Print list of all components */
   componentListStream = Journal_Register( Info_Type, (Name)"componentList"  );
   Stream_RedirectFile_WithPrependedPath( componentListStream, context->outputPath, "ComponentList.txt" );
   Stg_ComponentRegister_PrintAllTypes( Stg_ComponentRegister_Get_ComponentRegister(), componentListStream );

   /* Print info for one component */
   dcf = DocumentationComponentFactory_New( );
   Stream_RedirectFile_WithPrependedPath( dcf->infoStream, context->outputPath, "Documentation.txt" );
   DocumentationComponentFactory_DocumentType( dcf, Dictionary_GetString( context->dictionary, (Dictionary_Entry_Key)"documentType" ) );

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

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

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

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

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

   return self->constructByName( self, componentName, type, isEssential, data );
}
Пример #5
0
Dictionary* Codelet_GetPluginDictionary( void* codelet, Dictionary* rootDict ) {
   Codelet*                self = (Codelet*)codelet;
   Dictionary_Entry_Value* pluginsDEV = Dictionary_Get( rootDict, "plugins" );
   Dictionary*             pluginDict;
   unsigned                pluginIndex;
   Name                    pluginType;
   
   for( pluginIndex = 0; pluginIndex < Dictionary_Entry_Value_GetCount( pluginsDEV ); pluginIndex++ ) {
      pluginDict = Dictionary_Entry_Value_AsDictionary(
         Dictionary_Entry_Value_GetElement( pluginsDEV, pluginIndex ) );

      pluginType = Dictionary_GetString( pluginDict, "Type" );

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

   return NULL;
}
void Underworld_DensityChange_Setup( UnderworldContext* context ) {
		/* Function pulls and checks user input from the xml file */
	BuoyancyForceTerm*  bft = NULL;
	BuoyancyForceTerm_MaterialExt* materialExt = NULL;;
	Stream* stream = Journal_Register( Info_Type, (Name)"cows" );
	Name   materialName = NULL;
	int materialIndex;

	/* Get self (the plugin) */
	Underworld_DensityChange* self = (Underworld_DensityChange* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_DensityChange_Type  ); 

	/* Initialise plugin data */
	self->bftExt = NULL;
	self->swarm = NULL;
	self->material = NULL;
	self->height = 0;
	self->newDensity = 0;

	/* Need buoyancy force term, to get density infomation from bft extension + the integration swarm */
	bft = Stg_ComponentFactory_ConstructByName( context->CF, (Name)"buoyancyForceTerm", BuoyancyForceTerm, True, NULL  );

	/* Read in input from root xml dictionary */
	self->height = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"materialDensityChangeHeight", 0.5  );
	self->newDensity = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"materialDensityNewDensity", 0.3 );
	self->swarm = (IntegrationPointsSwarm* )bft->integrationSwarm;
	materialName = Dictionary_GetString( context->dictionary, (Dictionary_Entry_Key)"materialDensityToChange"  );
	self->material = Materials_Register_GetByName( self->swarm->materials_Register, materialName );

	/* check if material index exists */
	if( self->material==NULL ) {
		printf("Error\nCounld find the material with index %d\n", materialIndex ); exit(0);
	}
	materialExt = (BuoyancyForceTerm_MaterialExt*)ExtensionManager_Get( self->material->extensionMgr, self->material, bft->materialExtHandle );
	Journal_RPrintf( stream, "Will change %s's density at height %g from %g to %g\n", 
			self->material->name, self->height, materialExt->density, self->newDensity );

	self->bftExt = materialExt;
}
Пример #7
0
void _lecode_tools_Isostasy_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data )
{
   lecode_tools_Isostasy* self = (lecode_tools_Isostasy*)component;
   ConditionFunction *cond_func;
   Dictionary* pluginDict = Codelet_GetPluginDictionary( component, cf->rootDict );

   lecode_tools_Isostasy_self = self;

   self->context = (AbstractContext*)Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"Context"  ), UnderworldContext, True, data );
   self->ctx = self->context;
   self->mesh = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"mesh"  ), FeMesh, True, data );
   self->swarm = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"swarm"  ), IntegrationPointsSwarm, True, data );
   /*
     self->heightField = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"HeightField"  ), FeVariable, True, data );
   */
   self->surfaceIdx = Stg_ComponentFactory_PluginGetInt( cf, self, "SurfaceIndex", -1 );
   self->vertAxis = Stg_ComponentFactory_PluginGetInt( cf, self, "VerticalAxis", 1 );
   if( self->vertAxis == 1 )
      self->zontalAxis = 2;
   else if( self->vertAxis == 2 )
      self->zontalAxis = 1;
   else
      Journal_Firewall( NULL,
       Journal_MyStream( Error_Type, self ),
       "\n\nError in %s for %s - Isostasy plugin requires 'VerticalAxis' to be '1' (standard UW) or '2'.",
       __func__,
       self->type );

   self->avg = Stg_ComponentFactory_PluginGetBool( cf, self, "UseAverage", True );
   self->vel_field = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"velocityField"  ), FeVariable, True, data );
   self->buoyancy = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"buoyancy"  ), BuoyancyForceTerm, False, data );
   self->rho_zero_mat = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"rhoZeroMaterial"  ), Material, True, data );
   self->sle = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"sle"  ), SystemLinearEquations, True, data );
   self->thermalSLE = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"thermalSLE"  ), SystemLinearEquations, False, data );
   if (self->thermalSLE)
   {
      self->tempField = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"temperatureField"  ), FeVariable, True, data );
      self->tempDotField = Stg_ComponentFactory_ConstructByName( cf, Dictionary_GetString( pluginDict, (Dictionary_Entry_Key)"temperatureDotField"  ), FeVariable, True, data );
   }
   self->maxIts = Stg_ComponentFactory_PluginGetInt( cf, self, "MaxIterations", -1 );

   SystemLinearEquations_SetToNonLinear(self->sle);
   SystemLinearEquations_AddNonLinearEP(self->sle, lecode_tools_Isostasy_Type, lecode_tools_Isostasy_NonLinearEP);

   cond_func = ConditionFunction_New( (ConditionFunction_ApplyFunc*)lecode_tools_Isostasy_SetBC, (Name)"lecode_tools_Isostasy", NULL );
   ConditionFunction_Register_Add( condFunc_Register, cond_func);

   /** check if PPCing */
   if(!self->buoyancy){
      self->ppcManager = NULL;
      self->ppcManager = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"Manager", PpcManager, False, data );
      if( !self->ppcManager  )
         self->ppcManager = Stg_ComponentFactory_ConstructByName( cf, (Name)"default_ppcManager", PpcManager, False, data  );
         if( !self->ppcManager )
            Journal_Firewall( NULL,
                 Journal_MyStream( Error_Type, self ),
                 "\n\nError in %s for %s - Neither a BuoyancyForceTerm or Ppc manager was found .\nIsostasy plugin requires one OR the other to operate.\n\n\n",
                 __func__,
                 self->type );
         if( self->thermalSLE )
            Journal_Firewall( NULL,
                 Journal_MyStream( Error_Type, self ),
                 "\n\nError in %s for %s - Ppc not compatible with thermalSLE option.\n\n\n",
                 __func__,
                 self->type );

      self->densityID = PpcManager_GetPpcFromDict( self->ppcManager, cf, self->name, (Dictionary_Entry_Key)"DensityLabel", "DensityLabel" );

   }

}
Пример #8
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;
}
Пример #9
0
void Stg_ComponentFactory_CreateComponents( Stg_ComponentFactory *self ) {
   Dictionary_Entry*                      componentDictEntry           = NULL;
   Dictionary*                            currComponentDict            = NULL;
   Type                                   componentType                = NULL;
   Name                                   componentName                = NULL;
   Stg_Component_DefaultConstructorFunction*  componentConstructorFunction;
   Index                                  component_I;
   Stream*                                stream;
   
   assert( self );
   
   stream = self->infoStream;
   if( self->componentDict ){
      Stream_Indent( stream );

      /* add the contexts to the live component register first (so these get constructed/built/initialised first) */   
      for( component_I = 0; component_I < Dictionary_GetCount( self->componentDict ) ; component_I++ ){
         componentDictEntry = self->componentDict->entryPtr[ component_I ];

         currComponentDict  = Dictionary_Entry_Value_AsDictionary( componentDictEntry->value );
         componentType      = Dictionary_GetString( currComponentDict, "Type" );
         componentName      = componentDictEntry->key;

         if( strcmp( componentType, "DomainContext" ) && 
             strcmp( componentType, "FiniteElementContext" ) &&
             strcmp( componentType, "PICelleratorContext" ) )
            continue;

         if( LiveComponentRegister_Get( self->LCRegister, componentName ) != NULL ) {
            Journal_RPrintf( Journal_Register( Error_Type, self->type ),
               "Error in func %s: Trying to instantiate two components with the name of '%s'\n"
               "Each component's name must be unique.\n",
               __func__, componentName );
            exit(EXIT_FAILURE);
         }

         /* Print Message */
         /* Journal_Printf( stream, "Instantiating %s as %s\n", componentType, componentName ); */
         
         /* Get Default Constructor for this type */
         componentConstructorFunction = Stg_ComponentRegister_AssertGet( 
               Stg_ComponentRegister_Get_ComponentRegister(), componentType, "0" );

         /* Add to register */
         LiveComponentRegister_Add( self->LCRegister, (Stg_Component*)componentConstructorFunction( componentName ) );
      }

      /* now add the rest of the components */   
      for( component_I = 0; component_I < Dictionary_GetCount( self->componentDict ) ; component_I++ ){
         componentDictEntry = self->componentDict->entryPtr[ component_I ];

         currComponentDict  = Dictionary_Entry_Value_AsDictionary( componentDictEntry->value );
         componentType      = Dictionary_GetString( currComponentDict, "Type" );
         componentName      = componentDictEntry->key;

         if( !strcmp( componentType, "DomainContext" ) ||
             !strcmp( componentType, "FiniteElementContext" ) ||
             !strcmp( componentType, "PICelleratorContext" ) )
            continue;

         if( LiveComponentRegister_Get( self->LCRegister, componentName ) != NULL ) {
            Journal_RPrintf( Journal_Register( Error_Type, self->type ),
               "Error in func %s: Trying to instantiate two components with the name of '%s'\n"
               "Each component's name must be unique.\n",
               __func__, componentName );
            exit(EXIT_FAILURE);
         }
         
         Journal_Firewall( strcmp( componentType, "" ), NULL, "In func %s: Component with name '%s' does not have a 'Type' specified.\n"
                                                                              "This is sometimes caused by incorrect or missing 'mergeType' resulting in clobbered input file components.\n"
                                                                              "You may need to add 'mergeType=\"merge\"' to this component. Please check your input file.", __func__, componentName);

         /* Print Message */
         /* Journal_Printf( stream, "Instantiating %s as %s\n", componentType, componentName ); */
         
         /* Get Default Constructor for this type */
         componentConstructorFunction = Stg_ComponentRegister_AssertGet( 
               Stg_ComponentRegister_Get_ComponentRegister(), componentType, "0" );

         /* Add to register */
         LiveComponentRegister_Add( self->LCRegister, (Stg_Component*)componentConstructorFunction( componentName ) );
      }

      Stream_UnIndent( stream );
   }
   else{
      Journal_Printf( stream, "No Stg_Component List found..!\n" );
   }
}
Пример #10
0
void _MeshVariable_AssignFromXML( void* meshVariable, Stg_ComponentFactory* cf, void* data ) {
	MeshVariable*		self = (MeshVariable*)meshVariable;
	SizeT					dataOffsets[] = { 0 };
	StgVariable_DataType	dataTypes[] = { 0 };		/* Init value later */
	Index					dataTypeCounts[] = { 1 };
	Dictionary*			componentDict = NULL;
	Dictionary*			thisComponentDict = NULL;
	Name					dataTypeName = NULL;
	Name					rankName = NULL;
	void*					variableRegister = NULL;
	Name*					names = NULL;
	Stream*				error = Journal_Register( Error_Type, (Name)self->type );
	Mesh*					mesh;
	AbstractContext*	context;
	
	assert( self );

	componentDict = cf->componentDict;
	assert( componentDict  );
	thisComponentDict = Dictionary_GetDictionary( componentDict, self->name );
	assert( thisComponentDict );

	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
	if( !context  )
		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, False, data );
	
	/* Grab Registers */
    if(context)
        variableRegister = context->variable_Register;

	/* Construct the mesh. */
	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
	MeshVariable_SetMesh( self, mesh );

	/* Get the topological element we're intereseted in. */
	self->topoDim = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"topologicalDim", 0  );
			
	/* Get Type of Variable */
	dataTypeName = Dictionary_GetString( thisComponentDict, (Dictionary_Entry_Key)"DataType"  );
	if ( !strcasecmp( dataTypeName, "Double" ) )
		dataTypes[0] = StgVariable_DataType_Double;
	else if ( !strcasecmp( dataTypeName, "Float" ) )
		dataTypes[0] = StgVariable_DataType_Float;
	else if ( !strcasecmp( dataTypeName, "Int" ) )
		dataTypes[0] = StgVariable_DataType_Int;
	else if ( !strcasecmp( dataTypeName, "Char" ) )
		dataTypes[0] = StgVariable_DataType_Char;
	else if ( !strcasecmp( dataTypeName, "Short" ) )
		dataTypes[0] = StgVariable_DataType_Short;
	else 
		Journal_Firewall( False, error, "Variable '%s' cannot understand data type '%s'\n", self->name, dataTypeName );

	/* Get Rank of Variable - i.e. Scalar or Vector */
	rankName = Dictionary_GetString( thisComponentDict, (Dictionary_Entry_Key)"Rank"  );
	if( !strcasecmp( rankName, "Scalar" ) ){
		dataTypeCounts[0] = 1;
	}
	else if ( !strcasecmp( rankName, "Vector" ) ){
		Dictionary_Entry_Value* list;
		Index                   nameCount = 0;

		dataTypeCounts[0] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"VectorComponentCount", nameCount  );

		/* Get Names from list */
		if (( list = Dictionary_Get( thisComponentDict, (Dictionary_Entry_Key)"names" ) )) {
			Index entry_I;

			nameCount = Dictionary_Entry_Value_GetCount( list  );
			names = Memory_Alloc_Array( Name, nameCount, "Variable Names" );

			for ( entry_I = 0 ; entry_I < nameCount ; entry_I++ )
				names[ entry_I ] = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement(list, entry_I ) );

            Journal_Firewall( nameCount >= dataTypeCounts[0], error, "Variable '%s' has too few names in list for %d vector components.\n", self->name, dataTypeCounts[0] );
		}

	}
	else
		Journal_Firewall( False, error, "Variable '%s' cannot understand rank '%s'\n", self->name, rankName );

	_StgVariable_Init(
                  (StgVariable*)self,
                           context,
                                 1,
                       dataOffsets,
                         dataTypes,
                    dataTypeCounts,
                             names,
                                 0,
                              NULL,
    _MeshVariable_GetMeshArraySize,
           (void**)&self->arrayPtr,
                              True,
                  variableRegister );

	/* Clean Up */
	if (names)
		Memory_Free(names);
}
Пример #11
0
void _Geothermal_FieldMaps_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
   Geothermal_FieldMaps*   self = (Geothermal_FieldMaps*)component;
   Dictionary*             dict = Codelet_GetPluginDictionary( component, cf->rootDict );
   Dictionary_Entry_Value* mapList;
   unsigned                map_i;
   Stream*                 errorStream = Journal_Register( ErrorStream_Type, Geothermal_FieldMaps_Type );
	
   Stream_SetPrintingRank( errorStream, 0 );


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

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

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

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

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

   ContextEP_Append( self->context, AbstractContext_EP_Dump, Geothermal_FieldMaps_Dump );
}
void TimeIntegrationSuite_TestDriver( TimeIntegrationSuiteData* data, char *_name, char *_DerivName0, char *_DerivName1, int _order ) {
   Stg_ComponentFactory* cf;
   Stream*               stream;
   Dictionary*           dictionary;
   TimeIntegrator*       timeIntegrator;
   TimeIntegrand*        timeIntegrand;
   TimeIntegrand*        timeIntegrandList[2];
   DomainContext*        context;
   Variable*             variable;
   Variable*             variableList[2];
   double*               array;
   double*               array2;
   Index                 size0 = 11;
   Index                 size1 = 7;
   Index                 array_I;
   Index                 timestep = 0;
   Index                 maxTimesteps = 10;
   Bool                  simultaneous;
   unsigned              order;
   double                error = 0.0;
   Name                  derivName;
   double                tolerance = 0.001;
   Index                 integrand_I;
   Index                 integrandCount = 2;
   char                  expected_file[PCU_PATH_MAX];

   dictionary = Dictionary_New();
   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );
   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"DerivName0", Dictionary_Entry_Value_FromString(_DerivName0) );
   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"DerivName1", Dictionary_Entry_Value_FromString(_DerivName1) );

   context = DomainContext_New( "context", 0, 0, MPI_COMM_WORLD, NULL );
   cf = stgMainConstruct( dictionary, NULL, data->comm, context );
   stgMainBuildAndInitialise( cf );
      
   ContextEP_Append( context, AbstractContext_EP_Dt, TimeIntegrationSuite_GetDt );

   /* Create Stuff */
   order = _order;
   simultaneous = False;
   variableList[0] = Variable_NewVector( "testVariable", (AbstractContext*)context, Variable_DataType_Double, 2, &size0, NULL, (void**)&array, NULL );
   variableList[1] = Variable_NewVector( "testVariable2", (AbstractContext*)context, Variable_DataType_Double, 2, &size1, NULL, (void**)&array2, NULL );
   timeIntegrator = TimeIntegrator_New( "testTimeIntegrator", order, simultaneous, NULL, NULL );
   timeIntegrator->context = context;
   timeIntegrandList[0] = TimeIntegrand_New( "testTimeIntegrand0", context, timeIntegrator, variableList[0], 0, NULL, True );
   timeIntegrandList[1] = TimeIntegrand_New( "testTimeIntegrand1", context, timeIntegrator, variableList[1], 0, NULL, True );

   Journal_Enable_AllTypedStream( True );
   stream = Journal_Register( Info_Type, (Name)"EulerStream"  );
   Stream_RedirectFile( stream, _name );

   Stream_Enable( timeIntegrator->info, False );
   derivName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"DerivName0" );
   timeIntegrandList[0]->_calculateTimeDeriv = TimeIntegrationSuite_GetFunctionPtr( derivName  );
   Journal_Printf( stream, "DerivName0 - %s\n", derivName );
   derivName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"DerivName1" );
   timeIntegrandList[1]->_calculateTimeDeriv = TimeIntegrationSuite_GetFunctionPtr( derivName  );
   Journal_Printf( stream, "DerivName1 - %s\n", derivName );

   /* Print Stuff to file */
   Journal_PrintValue( stream, order );
   Journal_PrintBool( stream, simultaneous );

   /* Add stuff to EPs */
   TimeIntegrator_AppendSetupEP( timeIntegrator, "start1", TimeIntegrationSuite_TestContextType, CURR_MODULE_NAME, context );
   TimeIntegrator_AppendFinishEP( timeIntegrator, "finish1", TimeIntegrationSuite_TestVariableType, CURR_MODULE_NAME, variableList[0] );
   TimeIntegrator_PrependSetupEP( timeIntegrator, "start0", TimeIntegrationSuite_TestVariableType, CURR_MODULE_NAME, variableList[0] );
   TimeIntegrator_PrependFinishEP( timeIntegrator, "finish0", TimeIntegrationSuite_TestContextType, CURR_MODULE_NAME, context );

   /* Build */
   Stg_Component_Build( variableList[0], context, False );
   Stg_Component_Build( variableList[1], context, False );
   Stg_Component_Build( timeIntegrator, context, False );
   Stg_Component_Build( timeIntegrandList[0], context, False );
   Stg_Component_Build( timeIntegrandList[1], context, False );
   array = Memory_Alloc_Array( double, 2 * size0, "name" );
   array2 = Memory_Alloc_Array( double, 2 * size1, "name" );

   /* Initialise */
   memset( array, 0, sizeof(double) * 2 * size0 );
   memset( array2, 0, sizeof(double) * 2 * size1 );
   Stg_Component_Initialise( timeIntegrator, context, False );
   Stg_Component_Initialise( variableList[0], context, False );
   Stg_Component_Initialise( variableList[1], context, False );
   Stg_Component_Initialise( timeIntegrandList[0], context, False );
   Stg_Component_Initialise( timeIntegrandList[1], context, False );

   for ( timestep = 0.0 ; timestep < maxTimesteps ; timestep ++ ) {
      Journal_Printf( stream, "Step %u - Time = %.3g\n", timestep, context->currentTime );

      Stg_Component_Execute( timeIntegrator, context, True );
      context->currentTime += AbstractContext_Dt( context );

      for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
         timeIntegrand   = timeIntegrandList[ integrand_I ];
         variable         = variableList[ integrand_I ];
         for ( array_I = 0 ; array_I < variable->arraySize ; array_I++ ) {
            if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv ) {
               error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) - 2.0 * array_I * context->currentTime );
               error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) + array_I * context->currentTime );
            }
            else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv2 ) {
               error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) + 0.5 * array_I * context->currentTime );
               error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) - 3 * array_I * context->currentTime );
            }
            else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv ) {
               error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) - array_I * context->currentTime * context->currentTime );
               error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) + 0.5 * array_I * context->currentTime * context->currentTime );
            }
            else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv2 ) {
               error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) + 0.25 * array_I * context->currentTime * context->currentTime );
               error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) - 1.5 * array_I * context->currentTime * context->currentTime );
            }
            else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv ) {
               error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) - 2.0 * array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0)/3.0));
               error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) + array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0 )/3.0));
            }
            else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv2 ) {
               error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) + 0.5 * array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0)/3.0));
               error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) - 3.0 * array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0 )/3.0));
            }
            else
               Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)CURR_MODULE_NAME  ), "Don't understand _calculateTimeDeriv = %p\n", timeIntegrand->_calculateTimeDeriv );
         }
      }
   }
   pcu_check_lt( error, tolerance );

   if ( error < tolerance )
      Journal_Printf( stream, "Passed\n" );
   else
      Journal_Printf( stream, "Failed - Error = %lf\n", error );
   
   Journal_Enable_AllTypedStream( False );

   if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv
      || timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv2 ) {
      pcu_filename_expected( "testTimeIntegrationEulerOutput.expected", expected_file );
   }
   else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv
      || timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv2 ) {
      pcu_filename_expected( "testTimeIntegrationRK2Output.expected", expected_file );
   }
   else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv
      || timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv2 ) {
      pcu_filename_expected( "testTimeIntegrationRK4Output.expected", expected_file );
   }

   pcu_check_fileEq( _name, expected_file );

   /* Destroy stuff */
   Stream_CloseAndFreeFile( stream );
   Memory_Free( array );
   Memory_Free( array2 );
   Stg_Class_Delete( variable );
   _Stg_Component_Delete( timeIntegrator );
   _Stg_Component_Delete( timeIntegrandList[0] );
   _Stg_Component_Delete( timeIntegrandList[1] );
   remove( _name );
}
void IsoviscousStiffness2D( IsoviscousStiffnessData* data ) {
   StiffnessMatrix*      stiffnessMatrix;
   Dictionary*           dictionary;
   FiniteElementContext* context;
   Stg_ComponentFactory* cf;
   PetscViewer           expViewer;
   PetscReal             matrixNorm, errorNorm, test;
   Mat                   expected;
   char                  expected_file[PCU_PATH_MAX];
   char                  *filename, *matrixName;
   double                tolerance;
   char                  xml_input[PCU_PATH_MAX];
   Stream*               infoStream = Journal_Register( Info_Type, (Name)CURR_MODULE_NAME );
   char                  rFile[PCU_PATH_MAX];
   int                   err;

   pcu_docstring( "This test compares a Stiffness matrix against a previously generated stiffness matrix"
      "The stiffness matrix is generated from a 2D FEM model for an isoviscous fluid flow." 
      "See testIsoviscous.xml for the actual xml used" );

   /* read in the xml input file */
   pcu_filename_input( "IsoviscousStiffnessMatrix.xml", xml_input );
   cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
   context = (FiniteElementContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
   data->context = context;
   dictionary = context->dictionary;

   stgMainBuildAndInitialise( cf );

   /* Test is to check the relative error between an
       1 ) expected stiffness matrix, (made years ago)
       2) the current stiffness matrix.

       both matricies are built using only an Arrhenius rheology 
    */

   /* get the tolerance */
   tolerance = Dictionary_GetDouble( dictionary, "StiffnessMatrixCompareTolerance" );

   /* Get Matrix */
   matrixName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"CompareStiffnessMatrix"  );
   Journal_Printf( infoStream, "Comparing stiffness matrix '%s'\n", matrixName );
   stiffnessMatrix = (StiffnessMatrix*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)matrixName );
   assert( stiffnessMatrix  );

   StiffnessMatrix_Assemble( stiffnessMatrix, False, NULL, context );

   /* Get Stored Matrix from file */
   filename = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"StiffnessMatrixCompareFilename"  );
   Journal_Printf( infoStream, "Checking with file '%s'\n", filename );

   pcu_filename_expected( filename, expected_file );
   PetscViewerBinaryOpen( context->communicator, expected_file, FILE_MODE_READ, &expViewer );

   Stg_MatLoad( expViewer, MATAIJ, &expected );

   MatNorm( expected, NORM_FROBENIUS, &matrixNorm );
   assert( matrixNorm != 0 );

   MatAXPY( expected, -1, (stiffnessMatrix->matrix) , DIFFERENT_NONZERO_PATTERN );
   MatNorm( expected, NORM_FROBENIUS, &errorNorm );
   test = errorNorm / matrixNorm;

   pcu_check_lt( test, tolerance );

   /* Check tolerance */
   /*
   stream = Journal_Register( Info_Type, (Name)"StiffnessMatrixComparison"  );
   Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, "StiffnessMatrixCompare.dat" );
   Journal_PrintValue( infoStream, tolerance );
   Journal_Printf( stream, "Comparison between stiffness matrix '%s' %s with tolerance %4g.\n", 
         matrixName, 
         ( errorNorm/matrixNorm < tolerance ? "passed" : "failed" ),
         tolerance );
         */

   /* 
   Stream_CloseFile( stream );
       To view the expected and computed matricies uncomment this
   PetscViewerASCIIOpen(context->communicator, "numerical.dat",&currViewer);
   PetscViewerASCIIOpen(context->communicator, "expected.dat",&parallelViewer);
   MatView( stiffnessMatrix->matrix, currViewer ); //PETSC_VIEWER_STDOUT_WORLD );
   MatView( expected, parallelViewer ); //PETSC_VIEWER_STDOUT_WORLD );
   Stg_PetscViewerDestroy(&currViewer);
   Stg_PetscViewerDestroy(&parallelViewer);
   */
   if( data->context->rank == 0 ) {
      /* Now clean output path */
      sprintf(rFile, "%s/input.xml", data->context->outputPath );
      err = remove( rFile );
      if( err == -1 ) printf("Error in %s, can't delete the input.xml\n", __func__);
   }
   stgMainDestroy( cf );
}