Exemplo n.º 1
0
Bool File_Read( void* file, const char* const fileName ) {
	File* self = (File*)file;
	Bool result;
	
	if( !(result = self->_read( self, fileName )) ) {
		/* If the file failed to read, try prepending the search paths (if its not an absolute path) */
		if( strlen(fileName) >= 1 && fileName[0] != '/' ) {
			int i;

			for( i = 0; i < Stg_ObjectList_Count( _stgFilePaths ); i++ ) {
				char* path = (char*)Stg_ObjectAdaptor_Object( (Stg_ObjectAdaptor*)Stg_ObjectList_At( _stgFilePaths, i ) );
				char newFileName[FILENAME_MAX];

				strncpy( newFileName, path, FILENAME_MAX-1 );
				strncat( newFileName, "/", FILENAME_MAX-1 - 1 );
				strncat( newFileName, fileName, FILENAME_MAX-1 - 1 - strlen(path) );
				if( (result = self->_read( self, newFileName )) ) {
					break;
				}
			}
		}
	}
	
	if( result ) {
		/* File opened, set the name. */
		Stg_Object_SetName( self, (char*)fileName );
		self->_opened = True;
		self->_lastOpenedAs = 1;
	}
	
	return result;
}
Exemplo n.º 2
0
void _ToolboxesManager_Print( void* toolboxesManager, Stream* stream ) {
    ToolboxesManager* self = (ToolboxesManager*)toolboxesManager;

    /* General info */
    Journal_Printf( (void*) stream, "Toolboxes (ptr): %p\n", self );

    if( Stg_ObjectList_Count(self->initTB) > 0 ) {
        Index i;

        Journal_Printf( stream, "Initialised Modules:\n" );
        Stream_Indent( stream );
        for( i = 0; i < Stg_ObjectList_Count(self->initTB) ; ++i ) {
            Journal_Printf( stream, "%s\n", self->initTB->data[i]->name );
        }
        Stream_UnIndent( stream );
    }

    /* Print parent */
    _ModulesManager_Print( self, stream );
}
Exemplo n.º 3
0
void _GeneralSwarm_Build( void* swarm, void* data )
{
   GeneralSwarm*	self = (GeneralSwarm*) swarm;
   int			commHandler_I;
   Bool                    movementCommHandlerFound = False;
   Stream*                 errorStream = Journal_Register( Error_Type, (Name)self->type  );
   int var_I;

   _Swarm_Build( self, data );

   if( self->escapedRoutine != NULL) Stg_Component_Build( self->escapedRoutine, data , False );

   /* Since this swarm is being set up to advect a PICellerator material, it should make sure
    * at least one ParticleMovementHandler-type ParticleCommHandler has been added to the base
    * Swarm. */
   for( commHandler_I=0; commHandler_I < self->commHandlerList->count; commHandler_I++ )
   {
      ParticleCommHandler *pComm = NULL;

      pComm = (ParticleCommHandler*)(Stg_ObjectList_At( self->commHandlerList, commHandler_I ));
      if( pComm->type == ParticleMovementHandler_Type )
      {
         movementCommHandlerFound = True;
         break;
      }
   }

   Journal_Firewall( (Stg_ObjectList_Count(self->commHandlerList) >= 1) && (movementCommHandlerFound == True),
                     errorStream, "Error: for GeneralSwarm Swarms, at least one ParticleMovementHandler"
                     " commHandler must be registered. Please rectify this in your XML / code.\n" );

   for( var_I = 0 ; var_I < self->nSwarmVars ; var_I++ )
   {
      Stg_Component_Build( self->swarmVars[var_I], data , False );
   }
}
void ForceVector_GlobalAssembly_General( void* forceVector ) {
	ForceVector*            self                 = (ForceVector*) forceVector;
	FeVariable*             feVar                = self->feVariable;
	Element_LocalIndex      element_lI;
	Element_LocalIndex      elementLocalCount;
	Node_ElementLocalIndex  nodeCountCurrElement = 0;
	Element_Nodes           nodeIdsInCurrElement = 0;
	Dof_Index               totalDofsThisElement = 0;
	Dof_Index               totalDofsPrevElement = 0;
	Dof_Index               dofCountLastNode     = 0;
	Dof_EquationNumber**    elementLM            = NULL;
	double*                 elForceVecToAdd      = NULL;
	/* For output printing */
	double                  outputPercentage=10;	/* Controls how often to give a status update of assembly progress */
	int                     outputInterval;

	Journal_DPrintf( self->debug, "In %s - for vector \"%s\"\n", __func__, self->name );
	
	Stream_IndentBranch( StgFEM_Debug );
	
	if ( Stg_ObjectList_Count( self->forceTermList ) > 0 ) {
		elementLocalCount = FeMesh_GetElementLocalSize( feVar->feMesh );

		/* Initialise Vector */
		outputInterval = (int)( (outputPercentage/100.0)*(double)(elementLocalCount) );
		if( outputInterval == 0 ) { outputInterval = elementLocalCount; }
	
		for( element_lI = 0; element_lI < elementLocalCount; element_lI++ ) {  
			unsigned	nInc, *inc;
		
			FeMesh_GetElementNodes( feVar->feMesh, element_lI, self->inc );
			nInc = IArray_GetSize( self->inc );
			inc = IArray_GetPtr( self->inc );
			nodeCountCurrElement = nInc;
			/* Get the local node ids */
			nodeIdsInCurrElement = inc;

			/* Set value of elementLM: will automatically just index into global LM table if built */
			elementLM = FeEquationNumber_BuildOneElementLocationMatrix( feVar->eqNum, element_lI );

			/* work out number of dofs at the node, using LM */
			/* Since: Number of entries in LM table for this element = (by defn.) Number of dofs this element */
			dofCountLastNode = feVar->dofLayout->dofCounts[nodeIdsInCurrElement[nodeCountCurrElement-1]]; 
			totalDofsThisElement = &elementLM[nodeCountCurrElement-1][dofCountLastNode-1] - &elementLM[0][0] + 1;

			if ( totalDofsThisElement > totalDofsPrevElement ) {
				if (elForceVecToAdd) Memory_Free( elForceVecToAdd );
				Journal_DPrintfL( self->debug, 2, "Reallocating elForceVecToAdd to size %d\n", totalDofsThisElement );
				elForceVecToAdd = Memory_Alloc_Array( double, totalDofsThisElement, "elForceVecToAdd" );
			}

			/* Initialise Values to Zero */
			memset( elForceVecToAdd, 0, totalDofsThisElement * sizeof(double) );
		
			/* Assemble this element's element force vector: going through each force term in list */
			ForceVector_AssembleElement( self, element_lI, elForceVecToAdd );


	        /* When keeping BCs in we come across a bit of a problem in parallel. We're not
	           allowed to add entries to the force vector here and then clobber it later with
	           an insert in order to set the BC. So, what we'll do is just add zero here, that
	           way later we can add the BC and it will be the same as inserting it.
	           --- Luke, 20 May 2008 */
	        if( !self->feVariable->eqNum->removeBCs ) {
	           DofLayout* dofs;
	           int nDofs, curInd;
	           int ii, jj;

	           dofs = self->feVariable->dofLayout; /* shortcut to the dof layout */
	           curInd = 0; /* need a counter to track where we are in the element force vector */
	           for( ii = 0; ii < nodeCountCurrElement; ii++ ) {
	              nDofs = dofs->dofCounts[inc[ii]]; /* number of dofs on this node */
	              for( jj = 0; jj < nDofs; jj++ ) {
	                 if( !FeVariable_IsBC( self->feVariable, inc[ii], jj ) ) {
	                    curInd++;
	                    continue; /* only need to clear it if it's a bc */
	                 }
	                 elForceVecToAdd[curInd] = 0.0;
	                 curInd++;
	              }
	           }
	        }

			/* Ok, assemble into global matrix */
			//Vector_AddEntries( self->vector, totalDofsThisElement, (Index*)(elementLM[0]), elForceVecToAdd );
			VecSetValues( self->vector, totalDofsThisElement, (PetscInt*)elementLM[0], elForceVecToAdd, ADD_VALUES );

#if DEBUG
			if( element_lI % outputInterval == 0 ) {
				Journal_DPrintfL( self->debug, 2, "done %d percent of global force vector assembly (general) \n",
						  (int)(100.0*((double)element_lI/(double)elementLocalCount)) );
			}
#endif

			/* Cleanup: If we haven't built the big LM for all elements, free the temporary one */
			if ( False == feVar->eqNum->locationMatrixBuilt ) {
				Memory_Free( elementLM );
			}
			totalDofsPrevElement = totalDofsThisElement;
		}

		Memory_Free( elForceVecToAdd );
	}