void _Underworld_Mobility_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) { UnderworldContext* context; context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); Underworld_Mobility_PrintHeaderToFile( context ); ContextEP_Append( context, AbstractContext_EP_AssignFromXMLExtensions, Underworld_Mobility_Setup ); ContextEP_Append( context, AbstractContext_EP_FrequentOutput , Underworld_Mobility_Dump ); }
void _Underworld_DensityChange_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) { UnderworldContext* context; context = (UnderworldContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); /* Add functions to entry points */ ContextEP_Append( context, AbstractContext_EP_Initialise, Underworld_DensityChange_Setup ); ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_DensityChange_Check ); }
void _Viscoelastic_ViscoelasticCantileverBeam_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) { UnderworldContext* context = Stg_ComponentFactory_ConstructByName( cf, "context", UnderworldContext, True, data ); ContextEP_Append( context, AbstractContext_EP_FrequentOutput, CalcDeflectionAndCheckGravity ); StgFEM_FrequentOutput_PrintString( context, "Deflection" ); }
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 _Experimental_CylinderNodeProfiling_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) { AbstractContext* context; FeVariable* temperatureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"TemperatureField", FeVariable, True, data ); FeMesh* mesh = temperatureField->feMesh; context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data ); ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Experimental_NodeTempProfile ); }
void SwarmOutputSuite_TestSwarmOutput( SwarmOutputSuiteData* data ) { int procToWatch = data->nProcs > 1 ? 1 : 0; if( data->rank == procToWatch ) { Dictionary* dictionary; Dictionary* componentDict; Stg_ComponentFactory* cf; DomainContext* context; char input_file[PCU_PATH_MAX]; Swarm* swarm; SwarmOutput* swarmOutput; SpaceFillerParticleLayout* particleLayout; pcu_filename_input( "testSwarmOutput.xml", input_file ); cf = stgMainInitFromXML( input_file, data->comm, NULL ); context = (DomainContext*) LiveComponentRegister_Get( cf->LCRegister, (Name)"context" ); dictionary = context->dictionary; Journal_ReadFromDictionary( dictionary ); stgMainBuildAndInitialise( cf ); ContextEP_Append( context, AbstractContext_EP_Dt, SwarmOutputSuite_Dt ); ContextEP_Append( context, AbstractContext_EP_Step, SwarmOutputSuite_MoveParticles ); componentDict = Dictionary_GetDictionary( dictionary, "components" ); assert( componentDict ); AbstractContext_Dump( context ); Stg_Component_Execute( context, 0, False ); particleLayout = (SpaceFillerParticleLayout*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"particleLayout" ); swarmOutput = (SwarmOutput* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarmOutput" ); swarm = (Swarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm" ); pcu_check_true( particleLayout->isConstructed && particleLayout->isBuilt && particleLayout->isInitialised ); pcu_check_true( swarmOutput->isConstructed && swarmOutput->isBuilt && swarmOutput->isInitialised ); pcu_check_true( swarm->isConstructed && swarm->isBuilt && swarm->isInitialised ); pcu_check_streq( swarm->name, swarmOutput->swarm->name ); stgMainDestroy( cf ); } }
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 }
void _Underworld_MaxVelocity_AssignFromXML( void* plugin, Stg_ComponentFactory* cf, void* data ) { /** * \Purpose * This function is called on the 'Construct phase' as defined by the * Codelet_New(.....) above. The construct phase is called at the beginning of the * code. * In this function all data structures (objects or components) that this * plugin needs should be collected. To be more specific, the objects that * are defined in the inputfile (and thus are static) should be collected here. * * Also the user functionily (as opposed to non StGermain functionality) * should be defined in here. * So users defined functions should be attached to EntryPoints. These user * defined functions are called Hooks. So StGermain executes entry points, which * kick off user defined Hooks. * * \Inputs * Inputs are all automatic. * 1st args is the plugin pointer itself. (Not used here) * 2nd is the component factory. Will be used to collect components from * the inputfile. * 3rd Ask Steve. * * \Interactions * The context is generally gathered first from the ComponentFactory in * every plugin's construction phase. This allows the plugin we're constructing * to have access to a wide range of data. (Note this is not the behaviour of components; * they only access the data structures they need). * Once the context has been gathered we append a hook to the EP called * AbstractContext_EP_FrequentOutput. A list of StGermain entry points can * be found in StGermain/Base/Context/src/AbstractContext.c * * */ UnderworldContext* context; /* Gather context from the ComponentFactory here */ context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", UnderworldContext, True, data ); /* Simple user defined function which belong to no EntryPoint */ Underworld_MaxVelocity_PrintHeaderToFile( context ); /* Append user defined function, Underworld_MaxVelocity_Output, onto the EntryPoint * AbstractContext_EP_FrequentOutput */ ContextEP_Append( context, AbstractContext_EP_FrequentOutput, Underworld_MaxVelocity_Output ); }
void SemiLagrangianIntegratorSuite_Test( SemiLagrangianIntegratorSuiteData* data ) { Stg_ComponentFactory* cf; ConditionFunction* condFunc; //char xml_input[PCU_PATH_MAX]; double l2Error; FeVariable* phiField; FeVariable* phiOldField; Swarm* gaussSwarm; double phi[3]; unsigned node_i; AbstractContext* context; //pcu_filename_input( "testSemiLagrangianIntegrator.xml", xml_input ); cf = stgMainInitFromXML( "StgFEM/Utils/input/testSemiLagrangianIntegrator.xml", MPI_COMM_WORLD, NULL ); context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, NULL ); condFunc = ConditionFunction_New( SemiLagrangianIntegratorSuite_Line, (Name)"Line", NULL ); ConditionFunction_Register_Add( condFunc_Register, condFunc ); condFunc = ConditionFunction_New( SemiLagrangianIntegratorSuite_ShearCellX, (Name)"ShearCellX", NULL ); ConditionFunction_Register_Add( condFunc_Register, condFunc ); condFunc = ConditionFunction_New( SemiLagrangianIntegratorSuite_ShearCellY, (Name)"ShearCellY", NULL ); ConditionFunction_Register_Add( condFunc_Register, condFunc ); /* manually set the timestep */ ContextEP_ReplaceAll( context, AbstractContext_EP_Dt, Dt ); ContextEP_Append( context, AbstractContext_EP_UpdateClass, SemiLagrangianIntegratorSuite_UpdatePositions ); stgMainBuildAndInitialise( cf ); phiField = (FeVariable*)LiveComponentRegister_Get( cf->LCRegister, (Name)"PhiField" ); phiOldField = (FeVariable* )LiveComponentRegister_Get( cf->LCRegister, (Name)"PhiFieldInitial" ); gaussSwarm = (Swarm* )LiveComponentRegister_Get( cf->LCRegister, (Name)"gaussSwarm" ); for( node_i = 0; node_i < Mesh_GetLocalSize( phiField->feMesh, MT_VERTEX ); node_i++ ) { FeVariable_GetValueAtNode( phiField, node_i, phi ); FeVariable_SetValueAtNode( phiOldField, node_i, phi ); } stgMainLoop( cf ); l2Error = SemiLagrangianIntegratorSuite_EvaluateError( phiField, phiOldField, gaussSwarm ); pcu_check_true( l2Error < TOLERANCE ); stgMainDestroy( cf ); }
void _Underworld_Vrms_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) { Underworld_Vrms* self = (Underworld_Vrms*)component; self->context = (AbstractContext*)Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"Context", UnderworldContext, True, data ); self->gaussSwarm = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"GaussSwarm", Swarm, True, data ); self->velocityField = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"VelocityField", FeVariable, True, data ); /* Create new Field Variable */ self->velocitySquaredField = OperatorFeVariable_NewUnary( "VelocitySquaredField", (DomainContext*)self->context, self->velocityField, "VectorSquare" ); self->velocitySquaredField->context = (DomainContext*)self->context; Underworld_Vrms_PrintHeaderToFile( self->context ); ContextEP_Append( self->context, AbstractContext_EP_FrequentOutput, Underworld_Vrms_Dump ); }
int main( int argc, char* argv[] ) { MPI_Comm CommWorld; int rank; int numProcessors; int procToWatch; Dictionary* dictionary; AbstractContext* abstractContext; /* Initialise MPI, get world info */ MPI_Init( &argc, &argv ); MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld ); MPI_Comm_size( CommWorld, &numProcessors ); MPI_Comm_rank( CommWorld, &rank ); BaseFoundation_Init( &argc, &argv ); BaseIO_Init( &argc, &argv ); BaseContainer_Init( &argc, &argv ); BaseAutomation_Init( &argc, &argv ); BaseExtensibility_Init( &argc, &argv ); BaseContext_Init( &argc, &argv ); stream = Journal_Register (Info_Type, "myStream"); /* Redirect the error stream to stdout, so we can check warnings appear correctly */ Stream_SetFileBranch( Journal_GetTypedStream( ErrorStream_Type ), stJournal->stdOut ); if( argc >= 2 ) { procToWatch = atoi( argv[1] ); } else { procToWatch = 0; } if( rank == procToWatch ) Journal_Printf( (void*) stream, "Watching rank: %i\n", rank ); /* Read input */ dictionary = Dictionary_New(); dictionary->add( dictionary, "rank", Dictionary_Entry_Value_FromUnsignedInt( rank ) ); dictionary->add( dictionary, "numProcessors", Dictionary_Entry_Value_FromUnsignedInt( numProcessors ) ); /* Build the context */ abstractContext = _AbstractContext_New( sizeof(AbstractContext), "TestContext", MyDelete, MyPrint, NULL, NULL, NULL, _AbstractContext_Build, _AbstractContext_Initialise, _AbstractContext_Execute, _AbstractContext_Destroy, "context", True, MySetDt, 0, 10, CommWorld, dictionary ); /* add hooks to existing entry points */ ContextEP_Append( abstractContext, AbstractContext_EP_Dt, MyDt ); if( rank == procToWatch ) { Stream* stream = Journal_Register( InfoStream_Type, AbstractContext_Type ); Stg_Component_Build( abstractContext, 0 /* dummy */, False ); Stg_Component_Initialise( abstractContext, 0 /* dummy */, False ); Context_PrintConcise( abstractContext, stream ); Stg_Component_Execute( abstractContext, 0 /* dummy */, False ); Stg_Component_Destroy( abstractContext, 0 /* dummy */, False ); } /* Stg_Class_Delete stuff */ Stg_Class_Delete( abstractContext ); Stg_Class_Delete( dictionary ); BaseContext_Finalise(); BaseExtensibility_Finalise(); BaseAutomation_Finalise(); BaseContainer_Finalise(); BaseIO_Finalise(); BaseFoundation_Finalise(); /* Close off MPI */ MPI_Finalize(); return 0; /* success */ }
void _Spherical_CubedSphereNusselt_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) { Spherical_CubedSphereNusselt* self = (Spherical_CubedSphereNusselt*)component; UnderworldContext* context; FieldVariable_Register* fV_Register; FeVariable* temperatureGradientsField; FeVariable* velocityField; FeVariable* temperatureField; self->context = (AbstractContext*)Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"Context", UnderworldContext, True, data ); self->gaussSwarm = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"GaussSwarm", Swarm, True, data ); /* The PpcManager */ self->mgr = Stg_ComponentFactory_PluginConstructByKey( cf, self, (Dictionary_Entry_Key)"Manager", PpcManager, False, data ); if( !self->mgr ) self->mgr = Stg_ComponentFactory_ConstructByName( cf, (Name)"default_ppcManager", PpcManager, True, data ); // initialise as unfound ppc self->volAvgVD = self->volAvgW = self->volAvgT = self->vol = NULL; self->volAvgVD = Stg_ComponentFactory_PluginConstructByKey( cf, self, "volume_averaged_viscous_dissipation",PpcIntegral, False, data); self->volAvgW = Stg_ComponentFactory_PluginConstructByKey( cf, self, "volume_averaged_work_done",PpcIntegral, False, data); self->volAvgT = Stg_ComponentFactory_PluginConstructByKey( cf, self, "volume_averaged_temperature",PpcIntegral, True, data); self->vol = Stg_ComponentFactory_PluginConstructByKey( cf, self, "volume",PpcIntegral, True, data); self->Ra = Stg_ComponentFactory_PluginGetDouble( cf, self, (Dictionary_Entry_Key)"Ra", -2 ); assert( self->Ra > -1 ); StgFEM_FrequentOutput_PrintString( self->context, "<T'>" ); StgFEM_FrequentOutput_PrintString( self->context, "NuU_av" ); StgFEM_FrequentOutput_PrintString( self->context, "NuB_av" ); StgFEM_FrequentOutput_PrintString( self->context, "out_max_VelMag" ); StgFEM_FrequentOutput_PrintString( self->context, "in_max_VelMag" ); // if ppcs found then add to FrequentOutput file if( self->vol ) { if( self->volAvgVD ) StgFEM_FrequentOutput_PrintString( self->context, "volAvgVD" ); if( self->volAvgW ) StgFEM_FrequentOutput_PrintString( self->context, "volAvgW" ); } context = (UnderworldContext*)self->context; fV_Register = context->fieldVariable_Register; /* Create Some FeVariables to calculate nusselt number */ temperatureField = self->temperatureField = (FeVariable*)FieldVariable_Register_GetByName( fV_Register, "TemperatureField" ); velocityField = self->velocityField = (FeVariable*)FieldVariable_Register_GetByName( fV_Register, "VelocityField" ); temperatureGradientsField = self->temperatureGradientsField = (FeVariable*)FieldVariable_Register_GetByName( fV_Register, "TemperatureGradientsField" ); self->mesh = ((FeVariable*)temperatureField)->feMesh; self->advectiveHeatFluxField = OperatorFeVariable_NewBinary( "AdvectiveHeatFluxField", (DomainContext*)context, temperatureField, velocityField, "VectorScale" ); self->temperatureTotalDerivField = OperatorFeVariable_NewBinary( "TemperatureTotalDerivField", (DomainContext*)context, self->advectiveHeatFluxField, temperatureGradientsField, "Subtraction" ); /* Add functions to entry points */ ContextEP_Append( self->context, AbstractContext_EP_FrequentOutput, Spherical_CubedSphereNusselt_Output ); ContextEP_Append( self->context, AbstractContext_EP_FrequentOutput, Spherical_MaxVel_Output ); // if the definition for the vd and adiabatic work exist add another hook if( self->vol && self->volAvgVD && self->volAvgW ) ContextEP_Append( self->context, AbstractContext_EP_FrequentOutput, Spherical_Work_Output ); }
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 ); }
int main( int argc, char* argv[] ) { MPI_Comm CommWorld; int rank; int numProcessors; int procToWatch; Dictionary* dictionary; AbstractContext* abstractContext; /* Initialise MPI, get world info */ MPI_Init( &argc, &argv ); MPI_Comm_dup( MPI_COMM_WORLD, &CommWorld ); MPI_Comm_size( CommWorld, &numProcessors ); MPI_Comm_rank( CommWorld, &rank ); BaseFoundation_Init( &argc, &argv ); BaseIO_Init( &argc, &argv ); BaseContainer_Init( &argc, &argv ); BaseAutomation_Init( &argc, &argv ); BaseExtensibility_Init( &argc, &argv ); BaseContext_Init( &argc, &argv ); stream = Journal_Register( InfoStream_Type, "myStream" ); if( argc >= 2 ) { procToWatch = atoi( argv[1] ); } else { procToWatch = 0; } if( rank == procToWatch ) Journal_Printf( (void*) stream, "Watching rank: %i\n", rank ); /* Read input */ dictionary = Dictionary_New(); /* Build the context */ abstractContext = _AbstractContext_New( sizeof(AbstractContext), "TestContext", MyDelete, MyPrint, NULL, NULL, NULL, _AbstractContext_Build, _AbstractContext_Initialise, _AbstractContext_Execute, _AbstractContext_Destroy, "context", True, MySetDt, 0, 10, CommWorld, dictionary ); /* add hooks to existing entry points */ ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Build, MyBuild ); ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Initialise, MyInitialConditions ); ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Solve, MySolve ); ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Dt, MyDt ); if( rank == procToWatch ) { Journal_Printf( (void*)stream, "abstractContext->entryPointList->_size: %lu\n", abstractContext->entryPoint_Register->_size ); Journal_Printf( (void*)stream, "abstractContext->entryPointList->count: %u\n", abstractContext->entryPoint_Register->count ); } ContextEP_Append( abstractContext, AbstractContext_EP_Solve, MySolve2 ); ContextEP_ReplaceAll( abstractContext, AbstractContext_EP_Initialise, MyInitialConditions2 ); if( rank == procToWatch ) { stream = Journal_Register( InfoStream_Type, AbstractContext_Type ); AbstractContext_PrintConcise( abstractContext, stream ); Journal_Printf( (void*)stream, "abstractContext->entryPointList->_size: %lu\n", abstractContext->entryPoint_Register->_size ); Journal_Printf( (void*)stream, "abstractContext->entryPointList->count: %u\n", abstractContext->entryPoint_Register->count ); } /* Run the context */ if( rank == procToWatch ) { Stg_Component_Build( abstractContext, 0 /* dummy */, False ); Stg_Component_Initialise( abstractContext, 0 /* dummy */, False ); Stg_Component_Execute( abstractContext, 0 /* dummy */, False ); Stg_Component_Destroy( abstractContext, 0 /* dummy */, False ); } /* Stg_Class_Delete stuff */ Stg_Class_Delete( abstractContext ); Stg_Class_Delete( dictionary ); BaseContext_Finalise(); BaseExtensibility_Finalise(); BaseAutomation_Finalise(); BaseContainer_Finalise(); BaseIO_Finalise(); BaseFoundation_Finalise(); /* Close off MPI */ MPI_Finalize(); return 0; /* success */ }