void _SPR_StrainRate_Execute( void* patch, void* data ) { /* * Fuction Description: is the driver of the main algorithm * All repFields associated with this component will be * are executed in the below functions */ PICelleratorContext* context = (PICelleratorContext*)data; SPR_StrainRate* self = (SPR_StrainRate*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)NameOfPatch ); double startTime; assert( self ); _OperatorFeVariable_SyncShadowValues( self->rawField ); MPI_Barrier(MPI_COMM_WORLD); startTime = MPI_Wtime( ); Journal_RPrintf( Journal_Register( Info_Type, (Name)"REP" ), "Start Recovery Method\n" ); /* Phases of the SPR_StrainRate in this code */ /* 1: Assemble A and b see eq. 14.31, REFERENCE and solve for [a] */ _SPR_StrainRate_AssembleSolveLocalPatchs( self ); /* 2: Communicate [a] */ FeVariable_SyncShadowValues( self ); /* 3: Calculate the Boundary values */ _BaseRecoveryFeVar_Boundaries( self ); /* 4: Perform a final sync for new proc boundary domain edge nodes */ FeVariable_SyncShadowValues( self ); Journal_RPrintf( Journal_Register( Info_Type, (Name)"REP" ), "Time Taken for Recovery Method %f\n", MPI_Wtime()-startTime); }
void TimeIntegrator_UpdateClass( void* timeIntegrator, void* data ) { TimeIntegrator* self = (TimeIntegrator*) timeIntegrator; double wallTime,tmin,tmax; wallTime = MPI_Wtime(); Journal_RPrintf(self->info,"Time Integration\n"); self->_execute( self, data ); wallTime = MPI_Wtime()-wallTime; MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD ); MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD ); Journal_RPrintf(self->info,"Time Integration - %.4g [min] / %.4g [max] (secs)\n", tmin,tmax); }
void _Module_Init( Module* self, Module_MangleNameFunction MangleName, Stg_ObjectList* directories ) { char* fileName = NULL; char* fullPathName = NULL; Stream* stream; Stream* debug; Stream* error; Bool found = False; #ifndef NOSHARED int fullPathLength = 0; int length; Index dir_i; #endif stream = Journal_Register( Info_Type, self->type ); debug = Journal_Register( Debug_Type, self->type ); error = Journal_Register( Error_Type, self->type ); self->MangleName = MangleName; Journal_Printf( debug, "Finding module: \"%s\"... ", self->name ); self->mangledName = self->MangleName( self->name ); #ifndef NOSHARED fileName = Memory_Alloc_Array( char, strlen(self->mangledName) + strlen(MODULE_SUFFIX) + strlen(MODULE_EXT) + 1, MODULE_FILENAME ); sprintf( fileName, "%s%s%s", self->mangledName, MODULE_SUFFIX, MODULE_EXT ); /* Look for the library from the directories. */ for( dir_i = 0; dir_i < directories->count; ++dir_i ) { length = strlen( (char*)Stg_ObjectList_ObjectAt( directories, dir_i ) ) + 1 + strlen( fileName ) + 1; if( fullPathLength < length ) { fullPathLength = length; fullPathName = Memory_Realloc_Array( fullPathName, char, fullPathLength ); } PathJoin( fullPathName, 2, Stg_ObjectList_ObjectAt( directories, dir_i ), fileName ); self->dllPtr = dlopen( fullPathName, RTLD_LAZY | RTLD_GLOBAL ); if( self->dllPtr ) { Journal_RPrintf( stream, "%s \"%s\" found using %s\n", self->type, self->name, fullPathName ); found = True; break; } else { Journal_RPrintf( stream, "\n%s \"%s\" NOT found using %s\n", self->type, self->name, fullPathName ); Journal_RPrintf( stream, " dlopen returned the error: %s\n\n", dlerror() ); } }
void Underworld_DensityChange_Check( UnderworldContext* context ) { /* Function runs each timestep to check if centroid is at certain height */ double volume; double centroid[3]; static int densityChangeIsDone = 0; /* test if this has already happened, if so leave function */ if ( densityChangeIsDone ) return; /* Get self (the plugin) */ Underworld_DensityChange* self = (Underworld_DensityChange*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)Underworld_DensityChange_Type ); /* get centroid coordinate */ volume = Material_Volume( self->material, (IntegrationPointsSwarm*)self->swarm, centroid ); /* test if centroid height (y-coord) is >= input height * Note following code is only run once */ if( centroid[1] >= self->height ) { self->bftExt->density = self->newDensity; densityChangeIsDone = 1; Journal_RPrintf( Journal_Register( Info_Type, (Name)"DensityChange" ), "************** Density Change for material %s, new density is %g**************\n", self->material->name, self->bftExt->density ); } }
void _TimeIntegrator_ExecuteRK4( void* timeIntegrator, void* data ) { TimeIntegrator* self = (TimeIntegrator*) timeIntegrator; Index integrand_I; Index integrandCount = TimeIntegrator_GetCount( self ); double dt = self->dt; TimeIntegrand* integrand; double wallTime,tmin,tmax; Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name ); /* Set Time */ double startTime = TimeIntegrator_GetTime( self ); TimeIntegrator_Setup( self ); for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) { integrand = TimeIntegrator_GetByIndex( self, integrand_I ); TimeIntegrator_SetTime( self, startTime ); wallTime = MPI_Wtime(); TimeIntegrand_FourthOrder( integrand, integrand->variable, dt ); wallTime = MPI_Wtime()-wallTime; MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD ); MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD ); Journal_RPrintf(self->info,"\t4th order: %35s - %9.4f [min] / %9.4f [max] (secs)\n", integrand->name, tmin, tmax); } TimeIntegrator_Finalise( self ); }
void PICellerator_Toolbox_Finalise( ToolboxesManager* toolboxesManager ) { PICellerator_Finalise(); Journal_RPrintf( Journal_Register( Info_Type, (Name)PICellerator_Toolbox_Type ), "Finalised: PICellerator (Particle-In-Cell Framework).\n" ); }
void _TimeIntegrator_Execute( void* timeIntegrator, void* data ) { TimeIntegrator* self = (TimeIntegrator*)timeIntegrator; double wallTime,tmin,tmax; Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name ); wallTime = MPI_Wtime(); /* Set function pointer */ switch (self->order) { case 1: self->_execute = _TimeIntegrator_ExecuteEuler; break; case 2: if (self->simultaneous) self->_execute = _TimeIntegrator_ExecuteRK2Simultaneous; else self->_execute = _TimeIntegrator_ExecuteRK2; break; case 4: if (self->simultaneous) self->_execute = _TimeIntegrator_ExecuteRK4Simultaneous; else self->_execute = _TimeIntegrator_ExecuteRK4; break; default: Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type ), "%s '%s' cannot handle order %u\n", self->type, self->name, self->order ); } /* Call real function */ Journal_RPrintf( self->info, "Time Integration\n" ); self->_execute( self, data ); wallTime = MPI_Wtime()-wallTime; MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD ); MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD ); Journal_RPrintf(self->info,"Time Integration - %.6g [min] / %.6g [max] (secs)\n", tmin, tmax); }
void _TimeIntegrator_ExecuteRK2Simultaneous( void* timeIntegrator, void* data ) { TimeIntegrator* self = (TimeIntegrator*)timeIntegrator; AbstractContext* context = (AbstractContext*) data; Index integrand_I; Index integrandCount = TimeIntegrator_GetCount( self ); double dt = self->dt; TimeIntegrand* integrand; Variable** originalVariableList; assert(0); /* this shit be broken */ Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name ); Journal_Firewall( False, Journal_MyStream( Error_Type, self ), "Error in %s '%s' - This function is temporarily unavailable \n" "Please only use non-simultaneous update or only first order update.\n", self->type, self->name ); /* Set Time */ TimeIntegrator_SetTime( self, context->currentTime ); originalVariableList = Memory_Alloc_Array( Variable*, integrandCount, "originalVariableList" ); TimeIntegrator_Setup( self ); for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) { integrand = TimeIntegrator_GetByIndex( self, integrand_I ); Journal_RPrintf(self->info,"\t2nd order (simultaneous): %s\n", integrand->name); /* Store Original */ originalVariableList[ integrand_I ] = Variable_NewFromOld( integrand->variable, "Original", True ); /* Predictor Step */ TimeIntegrand_FirstOrder( integrand, integrand->variable, 0.5 * dt ); } TimeIntegrator_Finalise( self ); /* Set Time */ TimeIntegrator_SetTime( self, context->currentTime + 0.5 * dt ); TimeIntegrator_Setup( self ); for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) { integrand = TimeIntegrator_GetByIndex( self, integrand_I ); /* Corrector Step */ TimeIntegrand_FirstOrder( integrand, originalVariableList[ integrand_I ], dt ); /* Free Original */ Stg_Class_Delete( originalVariableList[ integrand_I ] ); } TimeIntegrator_Finalise( self ); Memory_Free( originalVariableList ); }
void TimeIntegrator_Finalise( void* timeIntegrator ) { TimeIntegrator* self = (TimeIntegrator*)timeIntegrator; EntryPoint* entryPoint = self->finishEP; Hook_Index hookIndex; double wallTime,tmin,tmax; for( hookIndex = 0; hookIndex < entryPoint->hooks->count; hookIndex++ ) { wallTime = MPI_Wtime(); ((EntryPoint_2VoidPtr_Cast*)((Hook*)entryPoint->hooks->data[hookIndex])->funcPtr)( self, Stg_ObjectList_At( self->finishData, hookIndex ) ); wallTime = MPI_Wtime()-wallTime; MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD ); MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD ); Journal_RPrintf(self->info,"\t EP: %35s - %9.4f (secs)\n",(entryPoint->hooks->data[hookIndex])->name,tmin,tmax); } }
void TimeIntegrator_Setup( void* timeIntegrator ) { TimeIntegrator* self = (TimeIntegrator*)timeIntegrator; EntryPoint* entryPoint = self->setupEP; Hook_Index hookIndex; double wallTime,tmin,tmax; /* Shouldn't this be using a call to a run function of the entry point class ? */ for( hookIndex = 0; hookIndex < entryPoint->hooks->count; hookIndex++ ) { wallTime = MPI_Wtime(); ((EntryPoint_2VoidPtr_Cast*)((Hook*)entryPoint->hooks->data[hookIndex])->funcPtr)( self, Stg_ObjectList_At( self->setupData, hookIndex ) ); wallTime = MPI_Wtime()-wallTime; MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD ); MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD ); Journal_RPrintf(self->info,"\t EP: %35s - %9.4f [min] / %9.4f [max] (secs)\n",(entryPoint->hooks->data[hookIndex])->name,tmin,tmax); } }
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; }
void _TimeIntegrator_ExecuteRK4Simultaneous( void* timeIntegrator, void* data ) { TimeIntegrator* self = (TimeIntegrator*)timeIntegrator; AbstractContext* context = (AbstractContext*) data; Index integrand_I; Index integrandCount = TimeIntegrator_GetCount( self ); double dt = self->dt; TimeIntegrand* integrand; Variable** originalVariableList; Variable** timeDerivVariableList; assert(0); /* this shit be broken */ Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name ); /* Set Time */ TimeIntegrator_SetTime( self, context->currentTime ); originalVariableList = Memory_Alloc_Array( Variable*, integrandCount, "originalVariableList" ); timeDerivVariableList = Memory_Alloc_Array( Variable*, integrandCount, "timeDerivVariableList" ); /* First Step */ TimeIntegrator_Setup( self ); for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) { integrand = TimeIntegrator_GetByIndex( self, integrand_I ); Journal_RPrintf(self->info,"\t4nd order (simultaneous): %s\n", integrand->name); /* Store Original Position Variable */ originalVariableList[ integrand_I ] = Variable_NewFromOld( integrand->variable, "Original", True ); timeDerivVariableList[ integrand_I ] = Variable_NewFromOld( integrand->variable, "k1+2k2+2k3", False ); /* Store k1 */ TimeIntegrand_StoreTimeDeriv( integrand, timeDerivVariableList[ integrand_I ] ); /* 1st Step */ TimeIntegrand_FirstOrder( integrand, integrand->variable, 0.5 * dt ); } TimeIntegrator_Finalise( self ); /* Set Time */ TimeIntegrator_SetTime( self, context->currentTime + 0.5 * dt ); /* Second Step */ TimeIntegrator_Setup( self ); for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) { integrand = TimeIntegrator_GetByIndex( self, integrand_I ); /* Add k2 */ TimeIntegrand_Add2TimesTimeDeriv( integrand, timeDerivVariableList[ integrand_I ] ); TimeIntegrand_FirstOrder( integrand, originalVariableList[ integrand_I ], 0.5 * dt ); } TimeIntegrator_Finalise( self ); TimeIntegrator_Setup( self ); for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) { integrand = TimeIntegrator_GetByIndex( self, integrand_I ); /* Add k3 */ TimeIntegrand_Add2TimesTimeDeriv( integrand, timeDerivVariableList[ integrand_I ] ); /* 3rd Step */ TimeIntegrand_FirstOrder( integrand, originalVariableList[ integrand_I ], dt ); } TimeIntegrator_Finalise( self ); /* Set Time */ TimeIntegrator_SetTime( self, context->currentTime + dt ); TimeIntegrator_Setup( self ); for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) { integrand = TimeIntegrator_GetByIndex( self, integrand_I ); TimeIntegrand_FourthOrderFinalStep( integrand, originalVariableList[ integrand_I ], timeDerivVariableList[ integrand_I ], dt ); /* Free Original */ Stg_Class_Delete( timeDerivVariableList[ integrand_I ] ); Stg_Class_Delete( originalVariableList[ integrand_I ] ); } TimeIntegrator_Finalise( self ); Memory_Free( originalVariableList ); Memory_Free( timeDerivVariableList ); }
void ImportersToolbox_Toolbox_Finalise( PluginsManager* pluginsManager ) { ImportersToolbox_Finalise(); Journal_RPrintf( Journal_Register( Info_Type, (Name)ImportersToolbox_Toolbox_Type ), "Finalised: ImportersToolbox Toolbox.\n" ); }
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" ); } }