Esempio n. 1
0
PTCar Car_Get(int i) {
	CarListInit();
	PTListItem pli = List_GetItem(CarList, i);
	if (pli != NULL) {
		return (PTCar) pli->item;
	}
	return NULL;
}
Esempio n. 2
0
PTAxle Car_GetAxles(PTCar car, int i) {
	if (car != NULL) {
		PTListItem pli = List_GetItem(car->axles, i);
		if (pli != NULL) {
			return ((PTAxle) pli->item);
		}
	}
	return NULL;
}
void IntegrationPointsSwarm_ClearSwarmMaps( void* integrationPoints ) {
    IntegrationPointsSwarm* self = (IntegrationPointsSwarm*)integrationPoints;
    SwarmMap* map = NULL;

    int ii;
    for (ii=0; ii<List_GetSize(self->swarmsMappedTo); ii++) {
        map = *(SwarmMap**)List_GetItem(self->swarmsMappedTo, ii);
        SwarmMap_Clear(map);
    }
}
void GeneralSwarm_ClearSwarmMaps( void* swarm ) {
	GeneralSwarm* self = (GeneralSwarm*) swarm;
    SwarmMap* map = NULL;

    int ii;
    for (ii=0; ii<List_GetSize(self->intSwarmMapList); ii++) {
        map = *(SwarmMap**)List_GetItem(self->intSwarmMapList, ii);
        SwarmMap_Clear(map);
    }

}
void ListSuite_TestInsert( ListSuiteData* data ) {
   Index idx;

   /* Initially, insert at the end */
   for( idx = 0; idx < NUM_ITEMS/2; idx++ ) {
      List_Insert( data->list, idx, &data->arrayData[idx] );
   }
   /* Then insert the rest from the half-way point */
   for( idx = NUM_ITEMS/2; idx < NUM_ITEMS; idx++ ) {
      List_Insert( data->list, NUM_ITEMS/2, &data->arrayData[idx] );
   }

   pcu_check_true( data->list->nItems == NUM_ITEMS );

   for( idx = 0; idx < NUM_ITEMS/2; idx++ ) {
      pcu_check_true( *(int*)List_GetItem( data->list, idx ) == idx );
   }
   for( idx = NUM_ITEMS/2; idx < NUM_ITEMS; idx++ ) {
      pcu_check_true( *(int*)List_GetItem( data->list, idx ) == ((NUM_ITEMS-1) - (idx - NUM_ITEMS/2)) );
   }
}
void ListSuite_TestPrepend( ListSuiteData* data ) {
   Index idx;

   for( idx = 0; idx < NUM_ITEMS; idx++ ) {
      List_Prepend( data->list, &data->arrayData[idx] );
   }

   pcu_check_true( data->list->nItems == NUM_ITEMS );
   for( idx = 0; idx < NUM_ITEMS; idx++ ) {
      pcu_check_true( *(int*)List_GetItem( data->list, idx ) == ((NUM_ITEMS-1) - idx) );
   }
}
Esempio n. 7
0
PTAxle Car_SetAxles(PTCar car, int i) {
	
	PTListItem pli = List_GetItem(car->axles, i);
	
	if (pli == NULL && i == Car_GetAxlesNum(car)) {
	
		return Axle_Add(car);
	} else {
	
		return (PTAxle) pli->item;
	}
	
	return NULL;
}
Esempio n. 8
0
PTCar Car_Set(int i) {
	
	CarListInit();
	PTListItem pli = List_GetItem(CarList, i);
	
	if (pli == NULL && i == Car_GetNum()) {
	
		return Car_Add();
	} else {
	
		return (PTCar) pli->item;
	}
	
	return NULL;
}
void _GeneralSwarm_Delete( void* swarm )
{
   GeneralSwarm* self = (GeneralSwarm*)swarm;
   SwarmMap* map;
   int ii;
   
   self->previousIntSwarmMap=NULL;
   if(self->intSwarmMapList){
       for (ii=0; ii<List_GetSize(self->intSwarmMapList); ii++) {
          map = *(SwarmMap**)List_GetItem(self->intSwarmMapList, ii);
          Stg_Class_Delete(map);
       }
   }
   Stg_Class_Delete(self->intSwarmMapList);
   
   self->intSwarmMapList = NULL;

   _Swarm_Delete( self );
}
void ListSuite_TestRemove( ListSuiteData* data ) {
   Index idx;
   Index listIndex=0;

   for( idx = 0; idx < NUM_ITEMS; idx++ ) {
      List_Append( data->list, &data->arrayData[idx] );
   }
   for( idx = 0; idx < NUM_ITEMS; idx++ ) {
      if ( idx % 2 == 0 ) {
         List_Remove( data->list, &data->arrayData[idx] );
      }
   }

   pcu_check_true( data->list->nItems == NUM_ITEMS/2 );
   listIndex=0;
   for( idx = 0; idx < NUM_ITEMS; idx++ ) {
      if ( idx % 2 == 1 ) {
         pcu_check_true( *(int*)List_GetItem( data->list, listIndex ) == idx );
         listIndex++;
      }
   }
}
unsigned GeneralSwarm_IntegrationPointMap( void* _self, void* _intSwarm, unsigned elementId, unsigned intPtCellId ){
    GeneralSwarm* self  = (GeneralSwarm*)_self;
    IntegrationPointsSwarm*	intSwarm = (IntegrationPointsSwarm*)_intSwarm;
    Mesh*	                intMesh  = (Mesh*)intSwarm->mesh;
    SwarmMap* map = NULL;

    // first, lets check if the int swarm is mirroring a general swarm
    if (intSwarm->mirroredSwarm == (Swarm*)self)
    {
        // ok, it is a mirrored swarm
        return Swarm_ParticleCellIDtoLocalID(
                                        self,
                                        CellLayout_MapElementIdToCellId( self->cellLayout, elementId ),
                                        intPtCellId );
    } else if ( self->previousIntSwarmMap && self->previousIntSwarmMap->swarm==intSwarm ) { /* next check if previous swarmmap */
        map = self->previousIntSwarmMap;
    } else {
        /* ok, previous is not our guy, check other existing: */
        int ii;
        for (ii=0; ii<List_GetSize(self->intSwarmMapList); ii++) {
            map = *(SwarmMap**)List_GetItem(self->intSwarmMapList, ii);
            if ( map->swarm==intSwarm ){
                self->previousIntSwarmMap = map;
                break;
            }
        }
        // if we've gotten to this point, there is no corresponding map.. let's create one */
        map = SwarmMap_New( intSwarm );
        // add to list
        List_Append( self->intSwarmMapList, (void*)&map );
        self->previousIntSwarmMap = map;
        // also add to int swarm incase it moves
        List_Append( intSwarm->swarmsMappedTo, (void*)&map );

    }
    
    unsigned matPointLocalIndex;
    if ( SwarmMap_Map(map,elementId,intPtCellId,&matPointLocalIndex) ) {
        /* ok, map found, return value */
        return matPointLocalIndex;
    } else {
        /* not found... damn.. lets go ahead and find nearest neighbour */
        
        /* lets check some things */
        Journal_Firewall(
            Stg_Class_IsInstance( self->cellLayout, ElementCellLayout_Type ),
            NULL,
            "Error In func %s: %s expects a materialSwarm with cellLayout of type ElementCellLayout.",
            __func__, self->type
        );

        Journal_Firewall(
            intSwarm->mesh==(FeMesh*)((ElementCellLayout*)self->cellLayout)->mesh,
            Journal_Register( Error_Type, (Name)self->type  ),
            "Error - in %s(): Mapper requires both the MaterialSwarm and\n"
            "the IntegrationSwarm to live on the same mesh.\n"
            "Here the MaterialSwarm %s lives in the mesh %s\n"
            "and the IntegrationSwarm %s lives in the mesh %s.",
            self->name, ((ElementCellLayout*)self->cellLayout)->mesh->name,
            intSwarm->name, intSwarm->mesh->name
        );
        
        Cell_Index cell_I = CellLayout_MapElementIdToCellId( intSwarm->cellLayout, elementId );
        Cell_Index cell_M = CellLayout_MapElementIdToCellId(     self->cellLayout, elementId );

        IntegrationPoint* integrationPoint = (IntegrationPoint*)Swarm_ParticleInCellAt( intSwarm, cell_I, intPtCellId );
        
        /* Convert integration point local to global coordinates */
        Coord global;
        FeMesh_CoordLocalToGlobal( intMesh, elementId, integrationPoint->xi, (double*) &global );

        /* now lets sweep material points to find our closest friend */
        double         distance2_min = DBL_MAX;
        double         distance2;
        Particle_Index particle_M;
        unsigned cellPartCount = self->cellParticleCountTbl[ cell_M ];
        
        Journal_Firewall( cellPartCount,
            Journal_Register( Error_Type, (Name)self->type  ),
            "Error - in %s(): There doesn't appear to be any particles\n"
            "within the current cell (%u).\n",
            self->name, cell_M );

        for ( particle_M = 0; particle_M < cellPartCount; particle_M++ ) {
            GlobalParticle* materialPoint = (GlobalParticle*)Swarm_ParticleInCellAt( self, cell_M, particle_M );
            distance2 = pow( global[0] - materialPoint->coord[0], 2 ) + pow( global[1] - materialPoint->coord[1], 2 );
            if( self->dim == 3 )
                distance2 += pow( global[2] - materialPoint->coord[2], 2 );
            if ( distance2 < distance2_min ){
                distance2_min = distance2;
                matPointLocalIndex = Swarm_ParticleCellIDtoLocalID( self, cell_M, particle_M );
            }
        }
        
        /* ok, we've found our nearest friend. record to mapping */
        SwarmMap_Insert(map,elementId,intPtCellId,matPointLocalIndex);

    }
    
    return matPointLocalIndex;
}