void StGermain_SingleAttractor_UpdatePositions( DomainContext* context ) { Cell_LocalIndex lCell_I; Particle_InCellIndex cParticle_I; Particle* currParticle; Index dim_I; Swarm* swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm" ); Coord attractorPoint; Mesh* mesh; Stream* stream = Journal_Register( Info_Type, (Name)"particleUpdate" ); unsigned int movementSpeedDivisor = 0; int movementSign = 1; unsigned int explosionPeriod = 20; double minCrd[3], maxCrd[3]; Stream_SetPrintingRank( stream, Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) ); movementSpeedDivisor = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"movementSpeedDivisor", 10 ); mesh = (Mesh* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"mesh-linear" ); Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd ); for ( dim_I=0; dim_I < 3; dim_I++ ) { attractorPoint[dim_I] = (maxCrd[dim_I] - minCrd[dim_I]) / 3; } Journal_Printf( stream, "Calculated attractor point is at (%f,%f,%f):\n", attractorPoint[0], attractorPoint[1], attractorPoint[2] ); /* Now decide if we are attracting or repelling */ if ( ( ( (context->timeStep - 1) / explosionPeriod ) % 2 ) == 0 ) { Journal_Printf( stream, "Timestep %d - Implosive mode\n", context->timeStep ); movementSign = 1; } else { Journal_Printf( stream, "Timestep %d - Explosive mode\n", context->timeStep ); movementSign = -1; } for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++ ) { Journal_Printf( stream, "\tUpdating Particles positions in local cell %d:\n", lCell_I ); for ( cParticle_I=0; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) { Coord movementVector = {0,0,0}; Coord newParticleCoord = {0,0,0}; Coord* oldCoord; currParticle = (Particle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I ); oldCoord = &currParticle->coord; Journal_Printf( stream, "\t\tUpdating particleInCell %d:\n", cParticle_I ); for ( dim_I=0; dim_I < 3; dim_I++ ) { movementVector[dim_I] = ( attractorPoint[dim_I] - (*oldCoord)[dim_I] ) / movementSpeedDivisor; movementVector[dim_I] *= movementSign; if ( movementSign == -1 ) { movementVector[dim_I] *= (float)movementSpeedDivisor / (movementSpeedDivisor-1); } newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I]; } memcpy( currParticle->velocity, movementVector, 3*sizeof(double) ); Journal_Printf( stream, "\t\tChanging its coords from (%f,%f,%f) to (%f,%f,%f):\n", (*oldCoord)[0], (*oldCoord)[1], (*oldCoord)[2], newParticleCoord[0], newParticleCoord[1], newParticleCoord[2] ); for ( dim_I=0; dim_I < 3; dim_I++ ) { currParticle->coord[dim_I] = newParticleCoord[dim_I]; } } } Swarm_UpdateAllParticleOwners( swarm ); }
void _VariableCondition_Print(void* variableCondition) { VariableCondition* self = (VariableCondition*)variableCondition; VariableCondition_VariableIndex vcVar_I; VariableCondition_ValueIndex val_I; Index i; /* Set the Journal for printing informations */ Stream* variableConditionStream = Journal_Register( InfoStream_Type, "VariableConditionStream"); /* General info */ Journal_Printf( variableConditionStream, "VariableCondition (ptr): %p\n", self); /* Print parent */ _Stg_Component_Print( self, variableConditionStream ); /* Virtual info */ Journal_Printf( variableConditionStream, "\t_getSet (func ptr): %p\n", self->_getSet); Journal_Printf( variableConditionStream, "\t_getVariableCount (func ptr): %p\n", self->_getVariableCount); Journal_Printf( variableConditionStream, "\t_getVariableIndex (func ptr): %p\n", self->_getVariableIndex); Journal_Printf( variableConditionStream, "\t_getValueIndex (func ptr): %p\n", self->_getValueIndex); Journal_Printf( variableConditionStream, "\t_getValueCount (func ptr): %p\n", self->_getValueCount); Journal_Printf( variableConditionStream, "\t_getValue (func ptr): %p\n", self->_getValue); /* Stg_Class info */ Journal_Printf( variableConditionStream, "\tvariable_Register (ptr): %p\n", self->variable_Register); Journal_Printf( variableConditionStream, "\tconFunc_Register (ptr): %p\n", self->conFunc_Register); Journal_Printf( variableConditionStream, "\t_set (ptr): %p\n", self->_set); Journal_Printf( variableConditionStream, "\tindexCount: %u\n", self->indexCount); Journal_Printf( variableConditionStream, "\tindexTbl (ptr): %p\n", self->indexTbl); if (self->indexTbl) for (i = 0; i < self->indexCount; i++) Journal_Printf( variableConditionStream, "\t\tindexTbl[%u]: %u\n", i, self->indexTbl[i]); Journal_Printf( variableConditionStream, "\tvcVarCountTbl (ptr): %p\n", self->vcVarCountTbl); if (self->vcVarCountTbl) for (i = 0; i < self->indexCount; i++) Journal_Printf( variableConditionStream, "\t\tvcVarCountTbl[%u]: %u\n", i, self->vcVarCountTbl[i]); Journal_Printf( variableConditionStream, "\tvcTbl (ptr): %p\n", self->vcTbl); if (self->vcTbl) for (i = 0; i < self->indexCount; i++) for (vcVar_I = 0; vcVar_I < self->vcVarCountTbl[i]; vcVar_I++) { Journal_Printf( variableConditionStream, "\t\tvcTbl[%u][%u]:\n", i, vcVar_I); Journal_Printf( variableConditionStream, "\t\t\tvarIndex: %u\n", self->vcTbl[i][vcVar_I].varIndex); Journal_Printf( variableConditionStream, "\t\t\tvalIndex: %u\n", self->vcTbl[i][vcVar_I].valIndex); } Journal_Printf( variableConditionStream, "\tvalueCount: %u\n", self->valueCount); Journal_Printf( variableConditionStream, "\tvalueTbl (ptr): %p\n", self->valueTbl); if( self->valueTbl ) { for (val_I = 0; val_I < self->valueCount; val_I++) { Journal_Printf( variableConditionStream, "\t\tvalueTbl[%u]:\n", val_I); switch (self->valueTbl[val_I].type) { case VC_ValueType_Double: Journal_Printf( variableConditionStream, "\t\t\ttype: VC_ValueType_Double\n" ); Journal_Printf( variableConditionStream, "\t\t\tasDouble: %g\n", self->valueTbl[val_I].as.typeDouble ); break; case VC_ValueType_Int: Journal_Printf( variableConditionStream, "\t\t\ttype: VC_ValueType_Int\n" ); Journal_Printf( variableConditionStream, "\t\t\tasInt: %i\n", self->valueTbl[val_I].as.typeInt ); break; case VC_ValueType_Short: Journal_Printf( variableConditionStream, "\t\t\ttype: VC_ValueType_Short\n" ); Journal_Printf( variableConditionStream, "\t\t\tasShort: %i\n", self->valueTbl[val_I].as.typeShort ); break; case VC_ValueType_Char: Journal_Printf( variableConditionStream, "\t\t\ttype: VC_ValueType_Char\n"); Journal_Printf( variableConditionStream, "\t\t\tasChar: %c\n", self->valueTbl[val_I].as.typeChar ); break; case VC_ValueType_Ptr: Journal_Printf( variableConditionStream, "\t\t\ttype: VC_ValueType_Ptr\n"); Journal_Printf( variableConditionStream, "\t\t\tasPtr: %g\n", self->valueTbl[val_I].as.typePtr ); break; case VC_ValueType_DoubleArray: Journal_Printf( variableConditionStream, "\t\t\ttype: VC_ValueType_DoubleArray\n"); Journal_Printf( variableConditionStream, "\t\t\tarraySize: %u\n", self->valueTbl[val_I].as.typeArray.size); Journal_Printf( variableConditionStream, "\t\t\tasDoubleArray (ptr): %p\n", self->valueTbl[val_I].as.typeArray.array); if (self->valueTbl[val_I].as.typeArray.array) for (i = 0; i < self->valueTbl[val_I].as.typeArray.size; i++) Journal_Printf( variableConditionStream, "\t\t\t\tasDoubleArray[%u]: %g\n", i, self->valueTbl[val_I].as.typeArray.array[i]); break; case VC_ValueType_CFIndex: Journal_Printf( variableConditionStream, "\t\t\ttype: VC_ValueType_CFIndex\n"); Journal_Printf( variableConditionStream, "\t\t\tasCFIndex: %u\n", self->valueTbl[val_I].as.typeCFIndex); break; } } } }
void stgGenerateFlattenedXML( Dictionary* dictionary, Dictionary* sources, char* timeStamp ) { XML_IO_Handler* ioHandler; char* outputPath; char* flatFilename; char* flatFilenameStamped; char* slimFilename; Stream* s; Bool isEnabled; Bool ret; Bool outputSlim; s = Journal_Register( Info_Type, (Name)XML_IO_Handler_Type ); /* Avoid confusing messages from XML_IO_Handler. Turn it off temporarily. */ isEnabled = Stream_IsEnable( s ); Stream_EnableSelfOnly( s, False ); ioHandler = XML_IO_Handler_New(); if( sources == NULL ) ioHandler->writeSources = False; outputPath = StG_Strdup( Dictionary_Entry_Value_AsString( Dictionary_GetDefault( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString( "./" ) ) ) ); outputSlim = Dictionary_Entry_Value_AsBool( Dictionary_GetDefault( dictionary, (Dictionary_Entry_Key)"outputSlimmedXML", Dictionary_Entry_Value_FromBool( True ) ) ); if( ! Stg_DirectoryExists( outputPath ) ) { if( Stg_FileExists( outputPath ) ) Journal_Firewall( 0, s, "outputPath '%s' is a file an not a directory! Exiting...\n", outputPath ); Journal_Printf( s, "outputPath '%s' does not exist, attempting to create...\n", outputPath ); ret = Stg_CreateDirectory( outputPath ); Journal_Firewall( ret, s, "Unable to create non-existing outputPath to '%s'\n", outputPath ); Journal_Printf( s, "outputPath '%s' successfully created!\n", outputPath ); } /* Set file names. */ Stg_asprintf( &flatFilename, "%s/%s", outputPath, "input.xml" ); IO_Handler_WriteAllToFile( ioHandler, flatFilename, dictionary, sources ); /* Format; path/input-YYYY.MM.DD-HH.MM.SS.xml. */ if (timeStamp) { Stg_asprintf( &flatFilenameStamped, "%s/%s-%s.%s", outputPath, "input", timeStamp, "xml" ); IO_Handler_WriteAllToFile( ioHandler, flatFilenameStamped, dictionary, sources ); Memory_Free( flatFilenameStamped ); } if( outputSlim && timeStamp ) { ioHandler->writeSources = False; Stg_asprintf( &slimFilename, "%s/%s-%s.%s", outputPath, "input-basic", timeStamp, "xml" ); IO_Handler_WriteAllToFile( ioHandler, slimFilename, dictionary, NULL); } Stream_EnableSelfOnly( s, isEnabled ); Stg_Class_Delete( ioHandler ); Memory_Free( flatFilename ); }
Bool DiscretisationGeometry_Finalise( void ) { Journal_Printf( Journal_Register( DebugStream_Type, "Context" ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */ return True; }
void SobolGeneratorSuite_TestSobolGenerator( SobolGeneratorSuiteData* data ) { int procToWatch; Stream* stream; SobolGenerator* sobolGenerator; Index index; Index sobol_I; int bit_I; double result; char output_file[PCU_PATH_MAX]; char rightmostBit_file[PCU_PATH_MAX]; char expected_name[PCU_PATH_MAX]; char expected_file[PCU_PATH_MAX]; procToWatch = data->nProcs >=2 ? 1 : 0; if( data->rank == procToWatch ) { stream = Journal_Register( Info_Type, (Name)"SobolGeneratorStream" ); Stream_RedirectFile( stream, "testSobolGeneratorRightmostBit.dat" ); Journal_Printf( stream, " *********************** Testing _SobolGenerator_FindRightmostZeroBit *******************\n" ); for ( index = 0 ; index < 30 ; index++ ) { for ( bit_I = sizeof( Index ) * 4 - 1 ; bit_I >= 0 ; bit_I-- ) Journal_Printf( stream, "%u", index & 1 << bit_I ? 1 : 0 ); Journal_Printf( stream, " number %u: %u\n", index, _SobolGenerator_FindRightmostZeroBit( index ) ); } /* constructor */ for ( sobol_I = 0 ; sobol_I < 100 ; sobol_I++ ) { sprintf( output_file, "testSobolGenerator.%03u.dat", sobol_I ); Stream_RedirectFile( stream, output_file ); sobolGenerator = SobolGenerator_NewFromTable( output_file ); Journal_Printf( stream," ****************** Testing SobolGenerator_GetDirectionalNumber ***************\n" ); for ( index = 0 ; index < 30 ; index++ ) SobolGenerator_GetDirectionalNumber( sobolGenerator, index ); /* Checking up to 200000 numbers - this number is arbitary - * it's only limited because we don't want file size to be huge * This number is intentionally over 25535 = 2^16 - 1 because there was a time when numbers repeated after this */ for ( index = 0 ; index < 200000 ; index++ ) { result = SobolGenerator_GetNextNumber(sobolGenerator); assert( fabs( result - SobolGenerator_GetNumberByIndex(sobolGenerator, index)) < 1e-8 ); /* Only dump subset of data - this output criterion is completely arbitary */ if ( index % 773 == 3 ) Journal_Printf( stream, "%.4g\n", result ); } sprintf( expected_name, "testSobolGeneratorOutput.%03u-%03u.expected", sobolGenerator->polynomialDegree, sobolGenerator->polynomialCoefficient ); pcu_filename_expected( "testSobolGeneratorRightmostBitOutput.expected", rightmostBit_file ); pcu_check_fileEq( "testSobolGeneratorRightmostBit.dat", rightmostBit_file ); pcu_filename_expected( expected_name, expected_file ); pcu_check_fileEq( output_file, expected_file ); remove( output_file ); Stg_Class_Delete( sobolGenerator ); } remove( "testSobolGeneratorRightmostBit.dat" ); } }
void _SnacRemesher_Remesh( void* _context, void* data ) { Snac_Context* context = (Snac_Context*)_context; SnacRemesher_Context* contextExt = ExtensionManager_Get( context->extensionMgr, context, SnacRemesher_ContextHandle ); Bool remesh; Journal_DPrintf( context->debug, "In: %s\n", __func__ ); switch( contextExt->condition ) { case SnacRemesher_OnTimeStep: /* Remeshing on multiples of "OnTimeStep", but don't remesh on loop 0. */ Journal_Firewall( contextExt->OnTimeStep, context->snacError, "Invalid remesh timestep criterion." ); remesh = (context->timeStep <= 1 || context->timeStep==context->restartTimestep) ? False : (context->timeStep % contextExt->OnTimeStep == 0) ? True : False; break; case SnacRemesher_OnMinLengthScale: remesh = (context->minLengthScale/context->initMinLengthScale < contextExt->onMinLengthScale) ? True : False; break; case SnacRemesher_OnBothTimeStepLength: Journal_Firewall( contextExt->OnTimeStep, context->snacError, "Invalid remesh timestep criterion." ); remesh = (context->timeStep <= 1) ? False : (context->timeStep % contextExt->OnTimeStep == 0) ? True : False; remesh = remesh ? True : (context->minLengthScale/context->initMinLengthScale < contextExt->onMinLengthScale) ? True : False; break; case SnacRemesher_Off: default: remesh = False; break; } if( remesh ) { Mesh* mesh = context->mesh; SnacRemesher_Mesh* meshExt = ExtensionManager_Get( context->meshExtensionMgr, mesh, SnacRemesher_MeshHandle ); Node_LocalIndex newNode_i; /* Element_LocalIndex newElement_i; */ Journal_Printf( context->snacInfo, "Remeshing!\n" ); /* ** If spherical coordinates are being used, ** then we'll need to convert the current mesh's cartesian coordinates ** to spherical coordinates first. */ if( meshExt->meshType == SnacRemesher_Spherical ) { Node_LocalIndex lNode_i; for( lNode_i = 0; lNode_i < mesh->nodeLocalCount; lNode_i++ ) { double x = mesh->nodeCoord[lNode_i][0]; double y = mesh->nodeCoord[lNode_i][1]; double z = mesh->nodeCoord[lNode_i][2]; mesh->nodeCoord[lNode_i][0] = SnacArcTan( y, x ); mesh->nodeCoord[lNode_i][1] = sqrt( x * x + y * y + z * z ); mesh->nodeCoord[lNode_i][2] = acos( z / meshExt->newNodeCoords[lNode_i][1] ); } } /* Sync the mesh. */ if( mesh->layout->decomp->procsInUse > 1 ) { Mesh_Sync( mesh ); } /* Remesh the coordinates. */ _SnacRemesher_NewCoords( context ); /* Interpolate current nodal values onto new coordinates. */ meshExt->newNodes = (Snac_Node*)ExtensionManager_Malloc( mesh->nodeExtensionMgr, mesh->nodeLocalCount ); _SnacRemesher_InterpolateNodes( context ); /* Don't forget the residualFr/Ft: This simple copy works because bottoms nodes are always bottom and remeshing doesn't change the node number. */ for( newNode_i = 0; newNode_i < mesh->nodeLocalCount; newNode_i++ ) { Snac_Node* dstNode = (Snac_Node*)ExtensionManager_At( context->mesh->nodeExtensionMgr, meshExt->newNodes, newNode_i ); Snac_Node* srcNode = Snac_Node_At( context, newNode_i ); dstNode->residualFr = srcNode->residualFr; dstNode->residualFt = srcNode->residualFt; } /* Interpolate current elemental values onto new coordinates. */ /* Barycentric coordinates of the old domain hex element set. */ meshExt->oldBarycenters = Memory_Alloc_Array( Coord, mesh->elementDomainCount, "OldBarycenters" ); /* Barycentric coordinates of the new local hex element set. */ meshExt->newBarycenters = Memory_Alloc_Array( Coord, mesh->elementLocalCount, "NewBarycenters" ); /* Coefficients for evaluating interpolation weight - function of old barycenters only. */ meshExt->barcoef = Memory_Alloc_Array( SnacRemesher_ElementBarcoef, mesh->elementDomainCount, "BarCoef" ); meshExt->barcord = Memory_Alloc_Array( SnacRemesher_ElementBarcord, mesh->elementLocalCount, "BarCord" ); /* Since ghost elements are numbered after local elements, a mapping from domain id to an ordered id listis constructed for straightforward interpolation: i.e. orderedToDomain: ordered ID -> domainID. */ meshExt->orderedToDomain = Memory_Alloc_Array( Element_DomainIndex, mesh->elementDomainCount, "OrderedToDomain" ); meshExt->newElements = Memory_Alloc_Array( SnacRemesher_Element, mesh->elementLocalCount, "NewElements" ); //memcpy( meshExt->newElements, mesh->element, mesh->elementExtensionMgr->finalSize * mesh->elementDomainCount ); /* Do the linear interpolation between grids of barycenters. */ _SnacRemesher_InterpolateElements( context ); /* Copy accross the new coord, node & element information to the current arrays. */ memcpy( mesh->nodeCoord, meshExt->newNodeCoords, mesh->nodeLocalCount * sizeof(Coord) ); memcpy( mesh->node, meshExt->newNodes, mesh->nodeExtensionMgr->finalSize * mesh->nodeLocalCount ); /* don't need to copy here because it's now donw in _SnacRemesher_InterpolateElements. */ //memcpy( mesh->element, meshExt->newElements, mesh->elementExtensionMgr->finalSize * mesh->elementLocalCount ); /* for( newElement_i = 0; newElement_i < mesh->elementLocalCount; newElement_i++ ) { */ /* Snac_Element* srcElement = */ /* (Snac_Element*)ExtensionManager_At( context->mesh->elementExtensionMgr, */ /* meshExt->newElements, */ /* newElement_i ); */ /* Snac_Element* dstElement = Snac_Element_At( context, newElement_i ); */ /* memcpy( dstElement, srcElement, sizeof(Snac_Element)/2 ); */ /* } */ /* Update element attributes based on the new coordinates and the transferred variables. */ _SnacRemesher_UpdateElements( context ); /* Free some space, as it won't be needed until the next remesh. */ Memory_Free( meshExt->oldBarycenters ); Memory_Free( meshExt->newBarycenters ); Memory_Free( meshExt->barcoef ); Memory_Free( meshExt->barcord ); Memory_Free( meshExt->orderedToDomain ); Memory_Free( meshExt->newElements ); ExtensionManager_Free( mesh->nodeExtensionMgr, meshExt->newNodes ); //ExtensionManager_Free( mesh->elementExtensionMgr, meshExt->newElements ); meshExt->newNodes = NULL; //meshExt->newElements = NULL; /* ** If in spherical mode, convert back to cartesian coordinates. */ if( meshExt->meshType == SnacRemesher_Spherical ) { unsigned lNode_i; for( lNode_i = 0; lNode_i < mesh->nodeLocalCount; lNode_i++ ) { double theta = mesh->nodeCoord[lNode_i][0]; double r = mesh->nodeCoord[lNode_i][1]; double phi = mesh->nodeCoord[lNode_i][2]; mesh->nodeCoord[lNode_i][0] = r * sin( phi ) * cos( theta ); mesh->nodeCoord[lNode_i][1] = r * sin( phi ) * sin( theta ); mesh->nodeCoord[lNode_i][2] = r * cos( phi ); } } /* Sync the mesh. */ if( mesh->layout->decomp->procsInUse > 1 ) { Mesh_Sync( mesh ); } /* dump info such as remeshing frequency, criterion, and the current time step */ contextExt->remeshingCount++; _SnacRemesher_DumpInfo( context ); } }
double ReturnZero( Stream* stream ) { Journal_Printf( stream, "In func %s\n", __func__ ); return 0.0; }
void _GALEDivergenceForce_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf, void* data ) { GALEDivergenceForce* self = (GALEDivergenceForce*)forceTerm; Dictionary* dict; Stg_Shape* domainShape=NULL; FeMesh* geometryMesh=NULL; GALEStressBC_Entry force; char *type; /* Construct Parent */ _ForceTerm_AssignFromXML( self, cf, data ); dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, self->name ) ); domainShape = Stg_ComponentFactory_ConstructByKey( cf, self->name, "DomainShape", Stg_Shape, True, data ) ; type = Stg_ComponentFactory_GetString( cf, self->name, "force_type", "" ); if(!strcasecmp(type,"double") || !strcasecmp(type,"float")) { force.type = GALEStressBC_Double; force.DoubleValue = Stg_ComponentFactory_GetDouble( cf, self->name, "force_value", 0.0 ); } else if(!strcasecmp(type,"func")) { char *funcName = Stg_ComponentFactory_GetString( cf, self->name, "force_value", "" ); Index cfIndex; cfIndex = ConditionFunction_Register_GetIndex ( condFunc_Register, funcName); force.type = GALEStressBC_ConditionFunction; if ( cfIndex == (unsigned)-1 ) { Stream* errorStr = Journal_Register( Error_Type, self->type ); Journal_Printf( errorStr, "Error- in %s: While parsing " "definition of GALEDivergenceForce, the cond. func. " " \"%s\" - wasn't found in the c.f. register.\n", __func__, funcName ); Journal_Printf( errorStr, "(Available functions in the C.F. register are: "); ConditionFunction_Register_PrintNameOfEachFunc ( condFunc_Register, errorStr ); Journal_Printf( errorStr, ")\n"); assert(0); } force.CFIndex = cfIndex; } else if(strlen(type)==0) { Stream* errorStr = Journal_Register( Error_Type, self->type ); Journal_Printf( errorStr, "Error- in %s: While parsing " "definition of GALEDivergenceForce, force_type is not specified.\nSupported types are \"double\" and \"function\".\n", __func__); assert(0); } else { Stream* errorStr = Journal_Register( Error_Type, self->type ); Journal_Printf( errorStr, "Error- in %s: While parsing " "definition of GALEDivergenceForce, the type of condition \"%s\"\nis not supported. Supported types are \"double\" and \"function\".\n", __func__, type ); assert(0); } geometryMesh=Stg_ComponentFactory_ConstructByKey( cf, self->name, "GeometryMesh", FeMesh, True, data ) ; _GALEDivergenceForce_Init( self, domainShape, geometryMesh, force); }
Bool StgDomainUtils_Finalise( void ) { Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context" ), "In: %s\n", __func__ ); return True; }
int main( int argc, char* argv[] ) { MPI_Comm CommWorld; int rank; int numProcessors; int procToWatch; Stream* stream; double** complex2d; Index x1 = 5; Index y1[] = { 1, 2, 3, 4, 5 }; Index i, j; /* 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 ); stream = Journal_Register ( "info", "MyInfo" ); if( argc >= 2 ) { procToWatch = atoi( argv[1] ); } else { procToWatch = 0; } if( rank == procToWatch ) { Journal_Printf( stream, "Watching rank: %i\n", rank ); } Journal_Printf( stream, "2D Complex\n" ); complex2d = Memory_Alloc_2DComplex_Unnamed( double, x1, y1 ); /* write */ for (i = 0; i < x1; ++i) { for (j = 0; j < y1[i]; ++j) { complex2d[i][j] = i + (double)(j / 10.0); } } /* read */ for (i = 0; i < x1; ++i) { for (j = 0; j < y1[i]; ++j) { Journal_Printf( stream, "%lf ", complex2d[i][j] ); } Journal_Printf( stream, "\n" ); } Memory_Free( complex2d ); BaseFoundation_Finalise(); /* Close off MPI */ MPI_Finalize(); return 0; /* success */ }
void Snac_Material_Print( void* material, Stream* stream ) { Snac_Material* self = (Snac_Material*)material; unsigned int i; Journal_Printf( stream, "Snac_Material:\n" ); Journal_Printf( stream, "\trheology: " ); if( self->rheology & Snac_Material_Elastic ) Journal_Printf( stream, "Elastic " ); if( self->rheology & Snac_Material_Plastic ) Journal_Printf( stream, "Plastic " ); if( self->rheology & Snac_Material_Maxwell ) Journal_Printf( stream, "Maxwell " ); if( self->rheology & Snac_Material_ViscoPlastic ) Journal_Printf( stream, "ViscoPlastic " ); Journal_Printf( stream, "\n" ); /* Elastic */ Journal_Printf( stream, "\tlambda: %g\n", self->lambda ); Journal_Printf( stream, "\tmu: %g\n", self->mu ); /* Maxwell */ Journal_Printf( stream, "\t viscosity: %g\n", self->viscosity ); Journal_Printf( stream, "\t reference strain-rate: %g\n", self->refsrate ); Journal_Printf( stream, "\t reference temperature: %g\n", self->reftemp ); Journal_Printf( stream, "\t activation energy: %g\n", self->activationE ); Journal_Printf( stream, "\t exponent of strain-rate: %g\n", self->srexponent ); /* Plastic */ Journal_Printf( stream, "\tnsegments: %u\n", self->nsegments ); Journal_Printf( stream, "\tplstrain: " ); for( i = 0; i < self->nsegments; i++ ) { Journal_Printf( stream, "%g, ", self->plstrain[i] ); } Journal_Printf( stream, "\n" ); Journal_Printf( stream, "\tfrictionAngle: " ); for( i = 0; i < self->nsegments; i++ ) { Journal_Printf( stream, "%g, ", self->frictionAngle[i] ); } Journal_Printf( stream, "\n" ); Journal_Printf( stream, "\tdilationAngle: " ); for( i = 0; i < self->nsegments; i++ ) { Journal_Printf( stream, "%g, ", self->dilationAngle[i] ); } Journal_Printf( stream, "\n" ); Journal_Printf( stream, "\tcohesion: " ); for( i = 0; i < self->nsegments; i++ ) { Journal_Printf( stream, "%g, ", self->cohesion[i] ); } Journal_Printf( stream, "\n" ); Journal_Printf( stream, "\tten_off: %g\n", self->ten_off ); }
void ModulesManager_Load( void* modulesManager, void* _dictionary, Name contextName ) { ModulesManager* self = (ModulesManager*)modulesManager; Dictionary* dictionary = (Dictionary*)_dictionary; unsigned int entryCount; unsigned int entry_I; Dictionary_Entry_Value* modulesVal; /* * First add the directory list onto LD_LIBRARY_PATH so that it can potentially * resolve the unknown symbols */ #ifndef NOSHARED char* curEnvPath; char* newEnvPath; Index newEnvPathLength; Index dir_I; Index i, count; char* dir; newEnvPathLength = 0; if( dictionary ) { Dictionary_Entry_Value* localLibDirList = Dictionary_Get( dictionary, "LD_LIBRARY_PATH" ); if( localLibDirList ) { count = Dictionary_Entry_Value_GetCount( localLibDirList ); for( i = 0; i < count; ++i ) { dir = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( localLibDirList, i ) ); ModulesManager_AddDirectory( "FromDictionary", dir ); } } } for( dir_I = 0; dir_I < moduleDirectories->count; ++dir_I ) { newEnvPathLength += strlen( (char*)Stg_ObjectList_ObjectAt( moduleDirectories, dir_I ) ); /* Add one make space for the ':' inbetween the directories */ newEnvPathLength += 1; } curEnvPath = getenv("LD_LIBRARY_PATH"); if( curEnvPath ) { newEnvPathLength += strlen( curEnvPath ); } if( newEnvPathLength > 0 ) { /* Add one to make space for the Null Terminator '\0' */ newEnvPathLength += 1; newEnvPath = Memory_Alloc_Array( char, newEnvPathLength, "LD_LIBRARY_PATH" ); newEnvPath[0] = '\0'; for( dir_I = 0; dir_I < moduleDirectories->count; ++dir_I ) { strcat( newEnvPath, (char*)Stg_ObjectList_ObjectAt( moduleDirectories, dir_I ) ); strcat( newEnvPath, ":" ); } if( curEnvPath ) { strcat( newEnvPath, curEnvPath ); } setenv( "LD_LIBRARY_PATH", newEnvPath, 1 ); Journal_Printf( Journal_Register( Debug_Type, self->type ), "Using LD_LIBRARY_PATH=%s\n", newEnvPath ); Memory_Free( newEnvPath ); }
void AllNodesVCSuite_TestAllNodesVC( AllNodesVCSuiteData* data ) { unsigned nDomains; unsigned nDims = 3; unsigned meshSize[3] = {3, 3, 3}; int procToWatch; double minCrds[3] = {0.0, 0.0, 0.0}; double maxCrds[3] = {1.0, 1.0, 1.0}; double* array[7]; char* vcKey = "AllNodesVC"; char* varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"}; char input_file[PCU_PATH_MAX]; char expected_file[PCU_PATH_MAX]; Mesh* mesh; Variable_Register* variable_Register; ConditionFunction* quadCF; ConditionFunction_Register* conFunc_Register; ExtensionManager_Register* extensionMgr_Register; Dictionary* dictionary; Dictionary* sources; Stream* stream; XML_IO_Handler* io_handler; Variable* var[7]; VariableCondition* vc; Index i, j, k; procToWatch = data->nProcs >=2 ? 1 : 0; io_handler = XML_IO_Handler_New(); stream = Journal_Register( Info_Type, (Name)"AllNodesVCStream" ); Stream_RedirectFile( stream, "testAllNodesVC.dat" ); dictionary = Dictionary_New(); sources = Dictionary_New(); Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") ); /* Input file */ pcu_filename_input( "allVC.xml", input_file ); IO_Handler_ReadAllFromFile( io_handler, input_file, dictionary, sources ); fflush( stdout ); extensionMgr_Register = ExtensionManager_Register_New(); /* Create a mesh. */ mesh = (Mesh*) AllNodesVCSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register ); nDomains = Mesh_GetDomainSize( mesh, MT_VERTEX ); /* Create CF stuff */ quadCF = ConditionFunction_New( AllNodesVCSuite_quadratic, (Name)"quadratic", NULL); conFunc_Register = ConditionFunction_Register_New( ); ConditionFunction_Register_Add(conFunc_Register, quadCF); /* Create variable register */ variable_Register = Variable_Register_New(); /* Create variables */ for (i = 0; i < 6; i++) { array[i] = Memory_Alloc_Array( double, nDomains, "array[i]" ); var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&nDomains, NULL, (void**)&array[i], 0 ); Variable_Register_Add(variable_Register, var[i]); } array[6] = Memory_Alloc_Array( double, nDomains*5, "array[6]" ); var[6] = Variable_NewVector( varName[6], NULL, Variable_DataType_Double, 5, &nDomains, NULL, (void**)&array[6], 0 ); Variable_Register_Add(variable_Register, var[6]); Variable_Register_BuildAll(variable_Register); /* Create AllVC */ vc = (VariableCondition*)AllNodesVC_New( "AllNodesVC", NULL, vcKey, variable_Register, conFunc_Register, dictionary, mesh ); Stg_Component_Build( vc, 0, False ); for (j = 0; j < 6; j++) memset(array[j], 0, sizeof(double)*nDomains); memset(array[6], 0, sizeof(double)*nDomains*5); VariableCondition_Apply(vc, NULL); if (data->rank == procToWatch) { Journal_Printf( stream,"Testing for %s\n", vcKey); for (j = 0; j < 6; j++) { Journal_Printf( stream, "\nvar[%u]: %.2lf", j, array[j][0]) ; for (k = 1; k < nDomains; k++) Journal_Printf( stream, ", %.2lf", array[j][k] ); } Journal_Printf( stream, "\nvar[6]: %.2lf", array[6][0] ); for (j = 1; j < nDomains*5; j++) Journal_Printf( stream, ", %.2lf", array[6][j] ); Journal_Printf( stream, "\n\n" ); for (j = 0; j < 7; j++) { for (k = 0; k < nDomains; k++) Journal_Printf( stream, "%s ", VariableCondition_IsCondition(vc, k, j) ? "True " : "False" ); Journal_Printf( stream, "\n" ); } Journal_Printf( stream, "\n" ); for (j = 0; j < 7; j++) { for (k = 0; k < nDomains; k++) { VariableCondition_ValueIndex valIndex; valIndex = VariableCondition_GetValueIndex(vc, k, j); if (valIndex != (unsigned)-1) Journal_Printf( stream, "%03u ", valIndex); else Journal_Printf( stream, "XXX "); } Journal_Printf( stream, "\n" ); } Journal_Printf( stream, "\n" ); pcu_filename_expected( "testAllNodesVC.expected", expected_file ); pcu_check_fileEq( "testAllNodesVC.dat", expected_file ); remove( "testAllNodesVC.dat" ); } Stg_Class_Delete(vc); Stg_Class_Delete(variable_Register); for (i = 0; i < 7; i++) { Stg_Class_Delete(var[i]); if (array[i]) Memory_Free(array[i]); } Stg_Class_Delete(extensionMgr_Register); Stg_Class_Delete(io_handler); Stg_Class_Delete(conFunc_Register); Stg_Class_Delete(dictionary); Stg_Class_Delete(sources); FreeObject( mesh ); }
double Stg_TimeMonitor_End( Stg_TimeMonitor* tm ) { double dt; double maxdt; double mindt; double sumdt; double avedt; double maxt; int rank; int size; tm->t2 = MPI_Wtime(); dt = tm->t2 - tm->t1; MPI_Comm_size( tm->comm, &size ); /* MPI_Reduce( &dt, &maxdt, 1, MPI_DOUBLE, MPI_MAX, 0, tm->comm ); MPI_Reduce( &dt, &mindt, 1, MPI_DOUBLE, MPI_MIN, 0, tm->comm ); MPI_Allreduce( &dt, &sumdt, 1, MPI_DOUBLE, MPI_SUM, tm->comm ); MPI_Reduce( &tm->t2, &maxt, 1, MPI_DOUBLE, MPI_MAX, 0, tm->comm ); avedt = sumdt / size; */ /* Note: Above is commented out because cannot use MPI_Reduce functions unless we are sure * that ALL procs will call end(). This is currently not the case with Stg_Component_Initialise() * phase as some procs will have more/less variables to call Initialise() on via Variable_Condition * due to decomposition and Wall boundary conditions */ maxdt = dt; mindt = dt; sumdt = dt * size; avedt = (double)dt; maxt = tm->t2; /* Note: maybe Stg_Components should store rank and comm??? how do the find their comm? */ MPI_Comm_rank( tm->comm, &rank ); if( rank == 0 && tm->print ) { if( !tm->criteria || maxdt > Stg_TimerWatchCriteria * (maxt - Stg_TimeMonitor_t0) ) { if( size == 1 ) { Journal_Printf( Journal_Register( Info_Type, Stg_TimeMonitor_InfoStreamName ), "\t%s(%s): ts: %.2g (secs), dt(%.2g%%): %.2gs\n", Stg_TimeMonitor_InfoStreamName, tm->tag, maxt - Stg_TimeMonitor_t0, (avedt) / (maxt - Stg_TimeMonitor_t0) * 100.0, avedt ); } else { Journal_Printf( Journal_Register( Info_Type, Stg_TimeMonitor_InfoStreamName ), "\t%s(%s): ts: %.2g (secs), dt(%.g%%): %.2g/%.2g/%.2gs\n", Stg_TimeMonitor_InfoStreamName, tm->tag, maxt - Stg_TimeMonitor_t0, (avedt) / (maxt - Stg_TimeMonitor_t0) * 100.0, maxdt, mindt, avedt ); } } } return avedt; }
Bool BaseContainer_Init( int* argc, char** argv[] ) { Journal_Printf( Journal_Register( DebugStream_Type, "Context" ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */ return True; }
/* Print implementation */ void _Stg_ObjectList_Print( void* objectList, struct Stream* stream ) { Stg_ObjectList* self = (Stg_ObjectList*) objectList; /* General info */ Journal_Printf( stream, "Stg_ObjectList (ptr):%p\n", (void*)self ); Stream_Indent( stream ); /* Print parent class */ _Stg_Class_Print( self, stream ); /* Virtual info */ Journal_Printf( stream, "_append(func ptr): %p\n", (void*)self->_append ); Journal_Printf( stream, "_prepend(func ptr): %p\n", (void*)self->_prepend ); Journal_Printf( stream, "_replaceAll(func ptr): %p\n", (void*)self->_replaceAll ); Journal_Printf( stream, "_replace(func ptr): %p\n", (void*)self->_replace ); Journal_Printf( stream, "_insertBefore(func ptr): %p\n", (void*)self->_insertBefore ); Journal_Printf( stream, "_insertAfter(func ptr): %p\n", (void*)self->_insertAfter ); Journal_Printf( stream, "_remove(func ptr): %p\n", (void*)self->_remove ); Journal_Printf( stream, "_getIndex(func ptr): %p\n", (void*)self->_getIndex ); Journal_Printf( stream, "_get(func ptr): %p\n", (void*)self->_get ); Journal_Printf( stream, "_allocMoreMemory(func ptr): %p\n", (void*)self->_allocMoreMemory ); Journal_Printf( stream, "_insertAtIndex(func ptr): %p\n", (void*)self->_insertAtIndex ); Journal_Printf( stream, "_removeByIndex(func ptr): %p\n", (void*)self->_removeByIndex ); Journal_Printf( stream, "_deleteAllObjects(func ptr): %p\n", (void*)self->_deleteAllObjects ); /* Stg_ObjectList */ Journal_Printf( stream, "_size: %u\n", self->_size ); Journal_Printf( stream, "_delta: %u\n", self->_delta ); Journal_Printf( stream, "_noJournalingInCopy: %u\n", self->_noJournalingInCopy ); Journal_Printf( stream, "count: %u\n", self->count ); Journal_Printf( stream, "data[0-%d]:\n", self->count ); Stg_ObjectList_PrintAllObjects( self, stream ); Stream_UnIndent( stream ); }
void _SnacRemesher_Construct( void* component, Stg_ComponentFactory* cf, void* data ) { Snac_Context* context; /* Retrieve context. */ context = (Snac_Context*)Stg_ComponentFactory_ConstructByName( cf, "context", Snac_Context, True, data ); Journal_Printf( context->debug, "In: %s\n", __func__ ); /* Add extensions to nodes, elements and the context */ SnacRemesher_ContextHandle = ExtensionManager_Add( context->extensionMgr, SnacRemesher_Type, sizeof(SnacRemesher_Context) ); SnacRemesher_MeshHandle = ExtensionManager_Add( context->meshExtensionMgr, SnacRemesher_Type, sizeof(SnacRemesher_Mesh) ); Journal_Printf( context->debug, "\tcontext extension handle: %u\n", SnacRemesher_ContextHandle ); Journal_Printf( context->debug, "\tmesh extension handle: %u\n", SnacRemesher_MeshHandle ); /* Register new entry points to the context (which manages them) */ Context_AddEntryPoint( context, SnacRemesher_EntryPoint_New( SnacRemesher_EP_InterpolateNode, SnacRemesher_InterpolateNode_CastType ) ); Context_AddEntryPoint( context, SnacRemesher_EntryPoint_New( SnacRemesher_EP_InterpolateElement, SnacRemesher_InterpolateElement_CastType ) ); Context_AddEntryPoint( context, SnacRemesher_EntryPoint_New( SnacRemesher_EP_CopyElement, SnacRemesher_CopyElement_CastType ) ); /* Add extensions to the entry points */ EntryPoint_Append( Context_GetEntryPoint( context, AbstractContext_EP_Build ), SnacRemesher_Type, _SnacRemesher_Build, SnacRemesher_Type ); EntryPoint_Append( Context_GetEntryPoint( context, AbstractContext_EP_Initialise ), SnacRemesher_Type, _SnacRemesher_InitialConditions, SnacRemesher_Type ); EntryPoint_Append( Context_GetEntryPoint( context, AbstractContext_EP_Sync ), SnacRemesher_Type, _SnacRemesher_Remesh, SnacRemesher_Type ); EntryPoint_Append( Context_GetEntryPoint( context, SnacRemesher_EP_InterpolateNode ), SnacRemesher_Type, _SnacRemesher_InterpolateNode, SnacRemesher_Type ); EntryPoint_Append( Context_GetEntryPoint( context, SnacRemesher_EP_InterpolateElement ), SnacRemesher_Type, _SnacRemesher_InterpolateElement, SnacRemesher_Type ); EntryPoint_Append( Context_GetEntryPoint( context, SnacRemesher_EP_CopyElement ), SnacRemesher_Type, _SnacRemesher_CopyElement, SnacRemesher_Type ); EntryPoint_Append( Context_GetEntryPoint( context, AbstractContext_EP_DestroyExtensions ), SnacRemesher_Type, _SnacRemesher_DeleteExtensions, SnacRemesher_Type ); /* Construct. */ _SnacRemesher_ConstructExtensions( context, data ); }
static void GlobalPrint( void* ptr, struct Stream* stream ) { Journal_Printf( stream, "(ptr): %p\n", ptr ); }
double ReturnNeg43( Stream* stream ) { Journal_Printf( stream, "In func %s\n", __func__ ); return -43; }
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; EntryPoint* entryPoint; Stream* stream; double result; /* 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 ); if( argc >= 2 ) { procToWatch = atoi( argv[1] ); } else { procToWatch = 0; } /* creating a stream */ stream = Journal_Register( InfoStream_Type, "myStream" ); Stream_SetPrintingRank( stream, procToWatch ); Journal_Printf( stream, "Watching rank: %i\n", rank ); /* Get Maximum of Values */ entryPoint = EntryPoint_New( testEpName, EntryPoint_Maximum_VoidPtr_CastType ); EP_Append( entryPoint, Return1 ); EP_Append( entryPoint, Return89 ); EP_Append( entryPoint, ReturnNeg43 ); EP_Append( entryPoint, ReturnZero ); result = ((EntryPoint_Maximum_VoidPtr_CallCast*) entryPoint->run)( entryPoint, stream ); Journal_PrintDouble( stream, result ); Stg_Class_Delete( entryPoint ); /* Get Minimum of Values */ entryPoint = EntryPoint_New( testEpName, EntryPoint_Minimum_VoidPtr_CastType ); EP_Append( entryPoint, Return1 ); EP_Append( entryPoint, Return89 ); EP_Append( entryPoint, ReturnNeg43 ); EP_Append( entryPoint, ReturnZero ); result = ((EntryPoint_Minimum_VoidPtr_CallCast*) entryPoint->run)( entryPoint, stream ); Journal_PrintDouble( stream, result ); Stg_Class_Delete( entryPoint ); BaseExtensibility_Finalise(); BaseAutomation_Finalise(); BaseContainer_Finalise(); BaseIO_Finalise(); BaseFoundation_Finalise(); /* Close off MPI */ MPI_Finalize(); return 0; /* success */ }
Bool StGermainUtils_Init( int* argc, char** argv[] ) { Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context" ), "In: %s\n", __func__ ); return True; }
/* Main */ int main( int argc, char* argv[] ) { MPI_Comm CommWorld; int rank; int numProcessors; int procToWatch; Dictionary* dictionary; Dictionary* componentDict; XML_IO_Handler* ioHandler; char* filename; Snac_Context* snacContext; int tmp; /* 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 ); if( argc >= 3 ) { procToWatch = atoi( argv[2] ); } else { procToWatch = 0; } if( rank == procToWatch ) printf( "Watching rank: %i\n", rank ); if (!Snac_Init( &argc, &argv )) { fprintf(stderr, "Error initialising StGermain, exiting.\n" ); exit(EXIT_FAILURE); } /* Snac's init message */ tmp = Stream_GetPrintingRank( Journal_Register( InfoStream_Type, "Context" ) ); Stream_SetPrintingRank( Journal_Register( InfoStream_Type, "Context" ), 0 ); Journal_Printf( /* DO NOT CHANGE OR REMOVE */ Journal_Register( InfoStream_Type, "Context" ), "Snac. Copyright (C) 2003-2005 Caltech, VPAC & University of Texas.\n" ); Stream_Flush( Journal_Register( InfoStream_Type, "Context" ) ); Stream_SetPrintingRank( Journal_Register( InfoStream_Type, "Context" ), tmp ); MPI_Barrier( CommWorld ); /* Ensures copyright info always come first in output */ /* Create the dictionary, and some fixed values */ dictionary = Dictionary_New(); Dictionary_Add( dictionary, "rank", Dictionary_Entry_Value_FromUnsignedInt( rank ) ); Dictionary_Add( dictionary, "numProcessors", Dictionary_Entry_Value_FromUnsignedInt( numProcessors ) ); /* Read input */ ioHandler = XML_IO_Handler_New(); if( argc >= 2 ) { filename = strdup( argv[1] ); } else { filename = strdup( "input.xml" ); } if ( False == IO_Handler_ReadAllFromFile( ioHandler, filename, dictionary ) ) { fprintf( stderr, "Error: Snac couldn't find specified input file %s. Exiting.\n", filename ); exit( EXIT_FAILURE ); } Journal_ReadFromDictionary( dictionary ); snacContext = Snac_Context_New( 0.0f, 0.0f, sizeof(Snac_Node), sizeof(Snac_Element), CommWorld, dictionary ); if( rank == procToWatch ) Dictionary_PrintConcise( dictionary, snacContext->verbose ); /* Construction phase -----------------------------------------------------------------------------------------------*/ Stg_Component_Construct( snacContext, 0 /* dummy */, &snacContext, True ); /* Building phase ---------------------------------------------------------------------------------------------------*/ Stg_Component_Build( snacContext, 0 /* dummy */, False ); /* Initialisaton phase ----------------------------------------------------------------------------------------------*/ Stg_Component_Initialise( snacContext, 0 /* dummy */, False ); if( rank == procToWatch ) Context_PrintConcise( snacContext, snacContext->verbose ); /* Step the context solver */ Stg_Component_Execute( snacContext, 0 /* dummy */, False ); /* Stg_Class_Delete stuff */ Stg_Component_Destroy( snacContext, 0 /* dummy */, False ); Stg_Class_Delete( snacContext ); free( filename ); Stg_Class_Delete( ioHandler ); Stg_Class_Delete( dictionary ); /* Close off frameworks */ Snac_Finalise(); MPI_Finalize(); return 0; /* success */ }
void _Codelet_Print( void* codelet, Stream* stream ) { Codelet* self = (Codelet*)codelet; Journal_Printf( stream, "Codelet: %s, Type %s\n", self->name, self->type ); _Stg_Component_Print( self, stream ); }
Bool _VariableCondition_IsCondition( void* variableCondition, Index localIndex, Index inputVarIndex ) { VariableCondition* self = (VariableCondition*)variableCondition; VariableCondition_VariableIndex vcVar_I; Index i; Variable_Index varIndexToTryMatch = 0; Variable_Index subVarIndexToTryMatch = 0; Variable* variableToTryMatch = NULL; Variable* subVariableToTryMatch = NULL; Variable_Index subVariable_I = 0; /* if the set isn't initialised, this is a NULL BC : False */ if ( !self->_set ) { return False; } /* first check if the index they've given us is actually in the list this VC applies to */ /* quick check, since we have the set available */ if ( localIndex >= self->_set->size ) { Stream* warning = Journal_Register( ErrorStream_Type, self->type ); Journal_Printf( warning, "Error- In %s: Tried to check an index %d larger than the size of " "the set (%d).\n", __func__, localIndex, self->_set->size ); assert(0); return False; } if(!UIntMap_Map( self->mapping, localIndex, &i )) return False; /* if ( !IndexSet_IsMember( self->_set, localIndex ) ) { return False; } for (i = 0; i < self->indexCount; i++) if (self->indexTbl[i] == localIndex) break; if (i == self->indexCount) return False; */ /* now check if the Variable they've given us is actually in the list to apply at the given index */ for (vcVar_I = 0; vcVar_I < self->vcVarCountTbl[i]; vcVar_I++) { varIndexToTryMatch = self->vcTbl[i][vcVar_I].varIndex; variableToTryMatch = self->variable_Register->_variable[varIndexToTryMatch]; if ( varIndexToTryMatch == inputVarIndex) { return True; } else if ( variableToTryMatch->subVariablesCount >= 1 ) { /* 2nd chance draw is that if this Var has sub-components, we should test if the input argument is * actually one of those - in which case we should consider it has a condition applied to it. */ for ( subVariable_I = 0; subVariable_I < variableToTryMatch->subVariablesCount; subVariable_I++ ) { /* TODO: next few lines bit slow! Maybe need to cache subvar indices on variable */ subVariableToTryMatch = variableToTryMatch->components[subVariable_I]; if ( subVariableToTryMatch == NULL ) continue; subVarIndexToTryMatch = Variable_Register_GetIndex( self->variable_Register, subVariableToTryMatch->name ); if ( subVarIndexToTryMatch == inputVarIndex) { return True; } } } } return False; }
int main( int argc, char* argv[] ) { MPI_Comm CommWorld; int rank; int numProcessors; int procToWatch; /* 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 ); if( argc >= 2 ) { procToWatch = atoi( argv[1] ); } else { procToWatch = 0; } if( rank == procToWatch ) { Stream* infoTest1; Stream* infoTest2; Stream* debugTest1; Stream* debugTest2; Stream* dumpTest1; Stream* dumpTest2; Stream* newTest1; Stream* newTest2; Stream* fileTest1; Stream* fileTest2; Stream* propTest1; Stream* propTest2; Dictionary* dictionary = Dictionary_New(); XML_IO_Handler* io_handler = XML_IO_Handler_New(); infoTest1 = Journal_Register( Info_Type, "test1" ); infoTest2 = Journal_Register( Info_Type, "test2" ); debugTest1 = Journal_Register( Debug_Type, "test1" ); debugTest2 = Journal_Register( Debug_Type, "test2" ); dumpTest1 = Journal_Register( Dump_Type, "test1" ); dumpTest2 = Journal_Register( Dump_Type, "test2" ); IO_Handler_ReadAllFromFile( io_handler, "data/journal.xml", dictionary ); Journal_ReadFromDictionary( dictionary ); newTest1 = Journal_Register( Info_Type, "test1.new1" ); newTest2 = Journal_Register( Info_Type, "test1.new2" ); Journal_Printf( infoTest1, "infoTest1\n" ); Journal_Printf( infoTest2, "infoTest2\n" ); Journal_Printf( debugTest1, "debugTest1\n" ); Journal_Printf( debugTest2, "debugTest2\n" ); Journal_Printf( dumpTest1, "dumpTest1\n" ); Journal_Printf( dumpTest2, "dumpTest2\n" ); Journal_PrintfL( newTest1, 3, "newTest1\n" ); Journal_PrintfL( newTest1, 4, "newTest1\n" ); Journal_Printf( newTest2, "newTest2\n" ); fileTest1 = Journal_Register( "newtype", "hello" ); fileTest2 = Journal_Register( "newtype", "other" ); Journal_Printf( fileTest1, "yay!" ); Journal_Printf( fileTest2, "double yay!" ); propTest1 = Journal_Register( Info_Type, "propertiestest1" ); propTest2 = Journal_Register( Info_Type, "propertiestest2" ); Print( propTest1, infoTest1 ); Print( propTest2, infoTest1 ); Stg_Class_Delete( io_handler ); Stg_Class_Delete( dictionary ); } BaseIO_Finalise(); BaseFoundation_Finalise(); /* Close off MPI */ MPI_Finalize(); return EXIT_SUCCESS; }
Bool PICellerator_MaterialPoints_Finalise( void ) { Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context" ), "In: %s\n", __func__ ); return True; }
void _SnacRemesher_ConstructExtensions( void* _context, void* data ) { Snac_Context* context = (Snac_Context*)_context; SnacRemesher_Context* contextExt = ExtensionManager_Get( context->extensionMgr, context, SnacRemesher_ContextHandle ); Mesh* mesh = context->mesh; SnacRemesher_Mesh* meshExt = ExtensionManager_Get( context->meshExtensionMgr, mesh, SnacRemesher_MeshHandle ); char* conditionStr; Dictionary_Entry_Value* conditionCriterion; Dictionary* meshDict; Stream* error = Journal_Register( Error_Type, "Remesher" ); char tmpBuf[PATH_MAX]; Journal_Printf( context->debug, "In: %s\n", __func__ ); contextExt->debugIC = Journal_Register( Debug_Type, "Remesher-ICs" ); contextExt->debugCoords = Journal_Register( Debug_Type, "Remesher-Coords" ); contextExt->debugNodes = Journal_Register( Debug_Type, "Remesher-Nodes" ); contextExt->debugElements = Journal_Register( Debug_Type, "Remesher-Elements" ); contextExt->debugSync = Journal_Register( Debug_Type, "Remesher-Sync" ); /* Additional tables required over the nodeElementTbl already required by core Snac */ Mesh_ActivateNodeNeighbourTbl( mesh ); Mesh_ActivateElementNeighbourTbl( mesh ); /* Work out condition to remesh on */ if( !Dictionary_Get( context->dictionary, CONDITION_STR ) ) { Journal_Printf( error, "Warning: No \"%s\" entry in dictionary... will default to \"%s\"\n", CONDITION_STR, OFF_STR ); } conditionStr = Dictionary_Entry_Value_AsString( Dictionary_GetDefault( context->dictionary, CONDITION_STR, Dictionary_Entry_Value_FromString( OFF_STR ) ) ); contextExt->OnTimeStep = 0; contextExt->onMinLengthScale = 0; if( !strcmp( conditionStr, OFF_STR ) ) { contextExt->condition = SnacRemesher_Off; Journal_Printf( context->snacInfo, "Remesher is off\n" ); } else if( !strcmp( conditionStr, ONTIMESTEP_STR ) ) { contextExt->condition = SnacRemesher_OnTimeStep; conditionCriterion = Dictionary_Get( context->dictionary, TIMESTEPCRITERION_STR ); Journal_Printf( context->snacInfo, "Remesher is on... activated based on timeStep\n" ); if( conditionCriterion ) { contextExt->OnTimeStep = Dictionary_Entry_Value_AsUnsignedInt( conditionCriterion ); } else { } Journal_Printf( context->snacInfo, "Remeshing every %u timeSteps\n", contextExt->OnTimeStep ); } else if( !strcmp( conditionStr, ONMINLENGTHSCALE_STR ) ) { contextExt->condition = SnacRemesher_OnMinLengthScale; conditionCriterion = Dictionary_Get( context->dictionary, LENGTHCRITERION_STR ); Journal_Printf( context->snacInfo, "Remesher is on... activated by minLengthScale\n" ); if( conditionCriterion ) { contextExt->onMinLengthScale = Dictionary_Entry_Value_AsDouble( conditionCriterion ); } else { } Journal_Printf( context->snacInfo, "Remesh when minLengthScale < %g\n", contextExt->onMinLengthScale ); } else if( !strcmp( conditionStr, ONBOTHTIMESTEPLENGTH_STR ) ) { contextExt->condition = SnacRemesher_OnBothTimeStepLength; conditionCriterion = Dictionary_Get( context->dictionary, TIMESTEPCRITERION_STR ); Journal_Printf( context->snacInfo, "Remesher is on... activated by both timeStep and minLengthScale\n" ); if( conditionCriterion ) { contextExt->OnTimeStep = Dictionary_Entry_Value_AsUnsignedInt( conditionCriterion ); conditionCriterion = Dictionary_Get( context->dictionary, LENGTHCRITERION_STR ); contextExt->onMinLengthScale = Dictionary_Entry_Value_AsDouble( conditionCriterion ); } else { } Journal_Printf( context->snacInfo, "Remesh every %u timeSteps or wheen minLengthScale < %g\n", contextExt->OnTimeStep, contextExt->onMinLengthScale ); } else { contextExt->condition = SnacRemesher_Off; Journal_Printf( context->snacInfo, "Remesher is defaulting to off\n" ); Journal_Printf( error, "Provided remesh condition \"%s\" unrecognised\n", conditionStr ); } /* Work out the mesh type */ meshDict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( context->dictionary, MESH_STR ) ); if( meshDict ) { char* meshTypeStr; if( !Dictionary_Get( meshDict, MESHTYPE_STR ) ) { Journal_Printf( error, "Warning: No \"%s\" entry in \"%s\"... will default to \"%s\"\n", MESHTYPE_STR, MESH_STR, CARTESIAN_STR ); } meshTypeStr = Dictionary_Entry_Value_AsString( Dictionary_GetDefault( meshDict, MESHTYPE_STR, Dictionary_Entry_Value_FromString( CARTESIAN_STR ) ) ); if( !strcmp( meshTypeStr, SPHERICAL_STR ) ) { meshExt->meshType = SnacRemesher_Spherical; Journal_Printf( context->snacInfo, "Remesher knows mesh as a spherical mesh\n" ); } else if( !strcmp( meshTypeStr, CARTESIAN_STR ) ) { meshExt->meshType = SnacRemesher_Cartesian; Journal_Printf( context->snacInfo, "Remesher knows mesh as a cartesian mesh\n" ); } else { meshExt->meshType = SnacRemesher_Cartesian; Journal_Printf( context->snacInfo, "Remesher assuming mesh as a cartesian mesh\n" ); Journal_Printf( error, "Provided mesh type \"%s\" unrecognised!\n", meshTypeStr ); } } else { meshExt->meshType = SnacRemesher_Cartesian; Journal_Printf( context->snacInfo, "Remesher assuming mesh as a cartesian mesh\n" ); Journal_Printf( error, "No \"%s\" entry in dictionary!\n", MESH_STR ); } /* Decide whether to restore the bottom surface */ contextExt->bottomRestore = 0; if( !strcmp( Dictionary_Entry_Value_AsString( Dictionary_GetDefault( context->dictionary, "bottomRestore", Dictionary_Entry_Value_FromString( OFF_STR ) ) ), ON_STR) ) contextExt->bottomRestore = 1; /* Register these functions for use in VCs */ ConditionFunction_Register_Add( context->condFunc_Register, ConditionFunction_New( _SnacRemesher_TestCondFunc, "SnacRemesher_TestCondFunc" ) ); /* Register these functions for use in VCs */ ConditionFunction_Register_Add( context->condFunc_Register, ConditionFunction_New( _SnacRemesher_XFunc, "SnacRemesher_XFunc" ) ); /* Register these functions for use in VCs */ ConditionFunction_Register_Add( context->condFunc_Register, ConditionFunction_New( _SnacRemesher_YFunc, "SnacRemesher_YFunc" ) ); /* Obtain the keys for the our new entry points... having the keys saves doing a string compare at run time */ contextExt->recoverNodeK = EntryPoint_Register_GetHandle( context->entryPoint_Register, SnacRemesher_EP_RecoverNode ); contextExt->interpolateNodeK = EntryPoint_Register_GetHandle( context->entryPoint_Register, SnacRemesher_EP_InterpolateNode ); contextExt->interpolateElementK = EntryPoint_Register_GetHandle( context->entryPoint_Register, SnacRemesher_EP_InterpolateElement ); /* Prepare the dump file */ if( context->rank == 0) { sprintf( tmpBuf, "%s/remeshInfo.%u", context->outputPath, context->rank ); if( (contextExt->remesherOut = fopen( tmpBuf, "w+" )) == NULL ) { assert( contextExt->remesherOut /* failed to open file for writing */ ); } } /* initialize remeshing counter */ contextExt->remeshingCount = 0; }
void _MeshGenerator_AssignFromXML( void* meshGenerator, Stg_ComponentFactory* cf, void* data ) { MeshGenerator* self = (MeshGenerator*)meshGenerator; Dictionary* dict; unsigned nDims; Dictionary_Entry_Value* meshList; Dictionary_Entry_Value *enabledDimsList, *enabledIncList; Mesh* mesh; Bool partitioned; assert( self ); assert( cf ); /* Rip out the components structure as a dictionary. */ dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name ) ); /* Set the communicator to a default. */ partitioned = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"partitioned", 1 ); if( partitioned ) { MeshGenerator_SetMPIComm( self, MPI_COMM_WORLD ); } else { MeshGenerator_SetMPIComm( self, MPI_COMM_SELF ); } self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data ); if( !self->context ) self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, False, data ); /* Read the individual mesh if specified. */ mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, False, data ); if( mesh ) MeshGenerator_AddMesh( self, mesh ); /* Read the mesh list, if it's there. */ meshList = Dictionary_Get( dict, (Dictionary_Entry_Key)"meshes" ); if( meshList ) { unsigned nMeshes; char* name; unsigned m_i; nMeshes = Dictionary_Entry_Value_GetCount( meshList ); for( m_i = 0; m_i < nMeshes; m_i++ ) { Mesh* mesh; name = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( meshList, m_i ) ); mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)name, Mesh, True, data ); MeshGenerator_AddMesh( self, mesh ); } } /* Read dimensions and state. */ nDims = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"dim", 2 ); nDims = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"dims", nDims ); MeshGenerator_SetDimSize( self, nDims ); enabledDimsList = Dictionary_Get( dict, (Dictionary_Entry_Key)"enabledDims" ); enabledIncList = Dictionary_Get( dict, (Dictionary_Entry_Key)"enabledIncidence" ); /* Clear dims/incidence flags */ unsigned d_i; memset( self->enabledDims, 0, (nDims + 1) * sizeof(Bool) ); for( d_i = 0; d_i <= nDims; d_i++ ) memset( self->enabledInc[d_i], 0, (nDims + 1) * sizeof(Bool) ); if( enabledDimsList ) { unsigned dim; unsigned nEnabledDims; nEnabledDims = Dictionary_Entry_Value_GetCount( enabledDimsList ); for( d_i = 0; d_i < nEnabledDims; d_i++ ) { dim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledDimsList, d_i ) ); if (dim > nDims) Journal_Printf(Mesh_Warning, "Warning - in %s: *** Skipping out of range dimension: %d\n", __func__, dim); else MeshGenerator_SetDimState( self, dim, True ); } } else { /* Default to all dimensions enabled */ for( d_i = 0; d_i < nDims + 1; d_i++ ) MeshGenerator_SetDimState( self, d_i, True ); } if( enabledIncList ) { unsigned nEnabledInc; unsigned fromDim, toDim; nEnabledInc = Dictionary_Entry_Value_GetCount( enabledIncList ); assert( nEnabledInc % 2 == 0 ); for( d_i = 0; d_i < nEnabledInc; d_i += 2 ) { fromDim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledIncList, d_i ) ); toDim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledIncList, d_i + 1 ) ); if (fromDim > nDims || toDim > nDims) Journal_Printf( Mesh_Warning, "Warning - in %s: *** Skipping out of range incidence: %d to %d\n", __func__ , fromDim, toDim); else MeshGenerator_SetIncidenceState( self, fromDim, toDim, True ); } } else { /* Default incidence setup 0->1,2,3 1->0,2 2->0,1 3->0,3 */ MeshGenerator_SetIncidenceState( self, 0, 0, True ); for( d_i = 1; d_i <= nDims; d_i ++ ) { MeshGenerator_SetIncidenceState( self, 0, d_i, True ); MeshGenerator_SetIncidenceState( self, d_i, 0, True ); } if (nDims == 2) { MeshGenerator_SetIncidenceState( self, 1, 2, True ); MeshGenerator_SetIncidenceState( self, 2, 1, True ); MeshGenerator_SetIncidenceState( self, 2, 2, True ); } if( nDims == 3 ) MeshGenerator_SetIncidenceState( self, 3, 3, True ); } }
void _SnacHillSlope_InitialConditions( void* _context, void* data ) { Snac_Context *context = (Snac_Context*)_context; SnacHillSlope_Context *contextExt = ExtensionManager_Get(context->extensionMgr, context, SnacHillSlope_ContextHandle ); Mesh *mesh = context->mesh; MeshLayout *layout = (MeshLayout*)mesh->layout; HexaMD *decomp = (HexaMD*)layout->decomp; BlockGeometry *geometry = (BlockGeometry*)layout->elementLayout->geometry; Node_GlobalIndex node_g, node_gI, node_gJ; const int full_I_node_range=decomp->nodeGlobal3DCounts[0]; const int full_J_node_range=decomp->nodeGlobal3DCounts[1]; double new_x[full_I_node_range], new_y[full_J_node_range]; double reg_dx, reg_dy, new_xMax, new_xMin, new_xHalf, midOffset, old_yMax, new_yMax, new_yMin; double slopeAngle = contextExt->slopeAngle * M_PI/180.0; double resolveHeight = geometry->max[1]-contextExt->resolveDepth; double xLeftFlatRamp = (contextExt->leftFlatFraction<0.0 ? 0.0 : (contextExt->leftFlatFraction>1.0 ? 1.0 : contextExt->leftFlatFraction)); double xRightRampFlat = (contextExt->rightFlatFraction<0.0 ? 1.0-contextExt->leftFlatFraction : (contextExt->rightFlatFraction>1.0 ? 1.0 : contextExt->rightFlatFraction)); const double smoothFactor = contextExt->rampFlatSmoothFactor; int restart = FALSE; Dictionary_Entry_Value *pluginsList, *plugin; #ifdef DEBUG int imax=0; #endif pluginsList = PluginsManager_GetPluginsList( context->dictionary ); if (pluginsList) { plugin = Dictionary_Entry_Value_GetFirstElement(pluginsList); while ( plugin ) { if ( 0 == strcmp( Dictionary_Entry_Value_AsString( plugin ), "SnacRestart" ) ) { restart = TRUE; break; } plugin = plugin->next; } } /* if(context->restartTimestep > 0) { restart = TRUE; } */ if( restart ) { fprintf(stderr, "Restarting: thus bailing from hillSlope/InitialConditions.c to avoid overwriting the mesh geometry\n"); return; } #ifdef DEBUG printf( "In: %s\n", __func__ ); #endif // fprintf(stderr, "Slope angle = %g degrees\n", slopeAngle/(M_PI/180.0)); /* Report HillSlope plugin variables picked up (?) from xml parameter file */ Journal_Printf( context->snacInfo, "\nSlope angle = %g degrees\n", slopeAngle/(M_PI/180.0) ); reg_dx = (geometry->max[0]-geometry->min[0])/(double)(full_I_node_range-1); reg_dy = (geometry->max[1]-geometry->min[1])/(double)(full_J_node_range-1); /* * Decide at what height (prior to shearing) to switch from rombhoid to parallelopiped geometry, * i.e., at what depth to resolve using "regular" elements parallel to the surface * versus "irregular" elements deformed to fit to a horizontal bottom * If contextExt->resolveDepth is negative, resolveHeight is set to zero and the whole domain is "regular" */ if(contextExt->resolveDepth<0.0 || resolveHeight<0.0) { resolveHeight = 0.0; } else if(resolveHeight>geometry->max[1]) { resolveHeight = geometry->max[1]; } for( node_gI = 0; node_gI < full_I_node_range; node_gI++ ) new_x[node_gI] = geometry->min[0] + node_gI*reg_dx; for( node_gJ = 0; node_gJ <= (full_J_node_range-1); node_gJ++ ) new_y[node_gJ] = geometry->min[1] + node_gJ*reg_dy; /* if((full_J_node_range-1)<4) { */ /* for( node_gJ = 0; node_gJ <= (full_J_node_range-1); node_gJ++ ) */ /* new_y[node_gJ] = geometry->min[1] + node_gJ*reg_dy; */ /* } else { */ /* for( node_gJ = 0; node_gJ <= (full_J_node_range-1)/4; node_gJ++ ) */ /* new_y[node_gJ] = geometry->min[1] + node_gJ*reg_dy*(stretchFactor/(1.0+stretchFactor)); */ /* for( ; node_gJ <= (full_J_node_range-1); node_gJ++ ) */ /* new_y[node_gJ] = geometry->min[1] + ((full_J_node_range-1)/4)*reg_dy*(stretchFactor/(1.0+stretchFactor)) */ /* + (node_gJ-((full_J_node_range-1)/4))*reg_dy*(1.0/(1.0+stretchFactor)); */ /* } */ /* * Assume highest point in x,y is at the last mesh node */ new_xMin = new_x[0]; new_xMax = new_x[full_I_node_range-1]; new_xHalf = new_xMin+(new_xMax-new_xMin)/2.0; new_yMin = new_y[0]; old_yMax = new_yMax = new_y[full_J_node_range-1]; /*+ tan(mesh_slope)*geometry->max[0]; */ xLeftFlatRamp=new_xMin+(new_xMax-new_xMin)*xLeftFlatRamp; xRightRampFlat=new_xMin+(new_xMax-new_xMin)*xRightRampFlat; fprintf(stderr, "Left flat <= %g -> %g\n", contextExt->leftFlatFraction, xLeftFlatRamp); fprintf(stderr, "Right flat >= %g -> %g\n", contextExt->rightFlatFraction, xRightRampFlat); fprintf(stderr, "Ramp-flat smoothness = %g\n", smoothFactor); fprintf(stderr, "Flat/ramp/flat ranges: %g <-> %g <-> %g <-> %g\n", new_xMin, xLeftFlatRamp, xRightRampFlat, new_xMax); /* * Loop across all nodes in mesh * - total of x*y*z nodes is given by context->mesh->nodeGlobalCount+1 */ for( node_g = 0; node_g < context->mesh->nodeGlobalCount; node_g++ ) { Node_LocalIndex node_l = Mesh_NodeMapGlobalToLocal( mesh, node_g ); Index i_g; Index j_g; Index k_g; Coord* coord = 0; Coord tmpCoord; /* * If a local node, directly change the node coordinates else use a temporary location */ if( node_l < context->mesh->nodeLocalCount ) { /* a local node */ coord = Snac_NodeCoord_P( context, node_l ); } else { /* * If the node is running on another CPU, use dummy ptr * - wouldn't it be better to just skip (continue) to next node? */ coord = &tmpCoord; } /* * Convert 1d mesh node index to 3d i,j,k mesh node position */ RegularMeshUtils_Node_1DTo3D( decomp, node_g, &i_g, &j_g, &k_g ); /* * Do nothing to x coordinate */ (*coord)[0] = new_x[i_g]; /*exp(-smoothFactor*(xRightRampFlat-new_x[i_g])/old_yMax) * Transform y coordinates by shearing mesh parallel to vertical axis */ (*coord)[1] = new_y[j_g]; midOffset=( (xRightRampFlat-(xRightRampFlat-new_xHalf)*( 1.0-exp(-smoothFactor*(xRightRampFlat-new_xHalf)/old_yMax) )) - (new_xHalf-xLeftFlatRamp)*( 1.0-exp(-smoothFactor*(new_xHalf-xLeftFlatRamp)/old_yMax) ) )*tan(slopeAngle); if(new_x[i_g]<=new_xHalf) { /* LHS */ (*coord)[1] += ( (new_x[i_g]<xLeftFlatRamp ? 0 : (new_x[i_g]-xLeftFlatRamp)*( 1.0-exp(-smoothFactor*(new_x[i_g]-xLeftFlatRamp)/old_yMax) )*tan(slopeAngle) ) *(new_y[j_g]>=resolveHeight ? 1.0 : new_y[j_g]/resolveHeight) ); } else { /* RHS */ (*coord)[1] += ( (new_x[i_g]>=xRightRampFlat ? xRightRampFlat*tan(slopeAngle)-midOffset : (xRightRampFlat-(xRightRampFlat-new_x[i_g])*( 1.0-exp(-smoothFactor*(xRightRampFlat-new_x[i_g])/old_yMax) ))*tan(slopeAngle) - midOffset) *(new_y[j_g]>=resolveHeight ? 1.0 : new_y[j_g]/resolveHeight) ); } /* * Track maximum y as mesh deforms */ if((*coord)[1]>new_yMax) new_yMax=(*coord)[1]; #ifdef DEBUG fprintf( stderr, "\tnode_l: %2u, node_g: %2u, i: %2u, j: %2u, k: %2u, ", node_l, node_g, i_g, j_g, k_g ); fprintf( stderr, "x: %12g, y: %12g, z: %12g\n", (*coord)[0], (*coord)[1], (*coord)[2] ); #endif } /* * Reset vertical max */ geometry->max[1] = new_yMax; }