void compareElements( TrafficIPC::Disturbances& newElems,
                      TrafficIPC::Disturbances& expectedElems ) {
   sort( newElems.begin(), newElems.end(), SortElements() );
   sort( expectedElems.begin(), expectedElems.end(), SortElements() );
   MC2_TEST_REQUIRED( newElems.size() == expectedElems.size() );
   for ( DisturbanceElements::size_type i = 0; i < newElems.size(); ++i ) {
      MC2_TEST_CHECK_EXT( *newElems[ i ] == *expectedElems[ i ], i );
   }
}
示例#2
0
void SequenceElements::MoveElement(int index,int destinationIndex)
{
    IncrementChangeCount(nullptr);
    if(index<destinationIndex)
    {
        mAllViews[mCurrentView][index]->Index() = destinationIndex;
        for(int i=index+1;i<destinationIndex;i++)
        {
            mAllViews[mCurrentView][i]->Index() = i-1;
        }
    }
    else
    {
        mAllViews[mCurrentView][index]->Index() = destinationIndex;
        for(int i=destinationIndex;i<index;i++)
        {
            mAllViews[mCurrentView][i]->Index() = i+1;
        }
    }
    SortElements();
}
示例#3
0
int FEASolver::Cuthill()
{

    FILE *fp;
    int i,n0,n1,n;
    long int j,k;
    int newwide,*newnum,**ocon;
    int  *numcon,*nxtnum;
    char infile[256];

    // read in connectivity from nodefile
    sprintf(infile,"%s.edge",PathName.c_str());
    if((fp=fopen(infile,"rt"))==NULL)
    {
        //MsgBox("Couldn't open %s",infile);
        printf("Couldn't open %s",infile);
        return FALSE;
    }
    fscanf(fp,"%li",&k);	// read in number of lines
    fscanf(fp,"%li",&j);	// read in boundarymarker flag;

    // allocate storage for numbering
    nxtnum=(int *)calloc(NumNodes,sizeof(int));
    newnum=(int *)calloc(NumNodes,sizeof(int));
    numcon=(int *)calloc(NumNodes,sizeof(int));
    ocon=(int **)calloc(NumNodes,sizeof(int *));

    // initialize node array;
    for(i=0; i<NumNodes; i++)
    {
        newnum[i] = -1;
    }

    // allocate space for connections;
    ocon[0]=(int *)calloc(2*k,sizeof(int));

    // with first pass, figure out how many connections
    // there are for each node;
    for(i=0; i<k; i++)
    {
        fscanf(fp,"%li",&j);
        fscanf(fp,"%i",&n0);
        fscanf(fp,"%i",&n1);
        fscanf(fp,"%li",&j);

        numcon[n0]++;
        numcon[n1]++;
    }

    // mete out connection storage space;
    for(i=1,n=0; i<NumNodes; i++)
    {
        n+=numcon[i-1];
        ocon[i]=ocon[0]+n;
    }

    // on second pass through file, store connections;
    rewind(fp);
    fscanf(fp,"%li",&k);	// read in number of lines
    fscanf(fp,"%li",&j);	// read in boundarymarker flag;
    for(i=0; i<k; i++)
    {
        fscanf(fp,"%li",&j);
        fscanf(fp,"%i",&n0);
        fscanf(fp,"%i",&n1);
        fscanf(fp,"%li",&j);

        ocon[n0][nxtnum[n0]]=n1;
        nxtnum[n0]++;
        ocon[n1][nxtnum[n1]]=n0;
        nxtnum[n1]++;
    }
    fclose(fp);
    remove(infile);

    // sort connections in order of increasing connectivity;
    // I'm lazy, so I'm doing a bubble sort;
    for(n0=0; n0<NumNodes; n0++)
    {
        for(i=1; i<numcon[n0]; i++)
            for(j=1; j<numcon[n0]; j++)
                if(numcon[ocon[n0][j]]<numcon[ocon[n0][j-1]])
                {
                    n1=ocon[n0][j];
                    ocon[n0][j]=ocon[n0][j-1];
                    ocon[n0][j-1]=n1;
                }
    }


    // search for a node to start with;
    j=numcon[0];
    n0=0;
    for(i=1; i<NumNodes; i++)
    {
        if(numcon[i]<j)
        {
            j=numcon[i];
            n0=i;
        }
        if(j==2) i=k;	// break out if j==2,
        // because this is the best we can do
    }

    // do renumbering algorithm;
    for(i=0; i<NumNodes; i++) nxtnum[i]=-1;
    newnum[n0]=0;
    n=1;
    nxtnum[0]=n0;

    do
    {
        // renumber in order of increasing number of connections;

        for(i=0; i<numcon[n0]; i++)
        {
            if (newnum[ocon[n0][i]]<0)
            {
                newnum[ocon[n0][i]]=n;
                nxtnum[n]=ocon[n0][i];
                n++;
            }
        }

        // need to catch case in which problem is multiply
        // connected and still renumber right.
        if(nxtnum[newnum[n0]+1]<0)
        {
            //	WarnMessage("Multiply Connected!");
            //	exit(0);

            // first, get a node that hasn't been visited yet;
            for(i=0; i<NumNodes; i++)
                if(newnum[i]<0)
                {
                    j=numcon[i];
                    n0=i;
                    i=NumNodes;
                }


            // now, get a new starting node;
            for(i=0; i<NumNodes; i++)
            {
                if((newnum[i]<0) && (numcon[i]<j))
                {
                    j=numcon[i];
                    n0=i;
                }
                if(j==2) i=NumNodes;	// break out if j==2,
                // because this is the
                // best we can do
            }

            // now, set things to restart;
            newnum[n0]=n;
            nxtnum[n]=n0;
            n++;
        }
        else n0=nxtnum[newnum[n0]+1];


    }
    while(n<NumNodes);

    // remap connectivities;
    for(i=0; i<NumNodes; i++)
        for(j=0; j<numcon[i]; j++)
            ocon[i][j]=newnum[ocon[i][j]];

    // remap (anti)periodic boundary points
    for(i=0; i<NumPBCs; i++)
    {
        pbclist[i].x=newnum[pbclist[i].x];
        pbclist[i].y=newnum[pbclist[i].y];
    }

    // find new bandwidth;

    // PBCs f**k up the banding, som could have to do
    // something like:
    // if(NumPBCs!=0) BandWidth=0;
    // else{
    // but if we apply the PCBs the last thing before the
    // solver is called, we can take advantage of banding
    // speed optimizations without messing things up.
    for(n0=0,newwide=0; n0<NumNodes; n0++)
    {
        for(i=0; i<numcon[n0]; i++)
            if(abs(newnum[n0]-ocon[n0][i])>newwide)
            {
                newwide=abs(newnum[n0]-ocon[n0][i]);
            }
    }

    BandWidth=newwide+1;
    // }

    // free up the variables that we needed during the routine....
    free(numcon);
    free(nxtnum);
    free(ocon[0]);
    free(ocon);

    // new mapping remains in newnum;
    // apply this mapping to elements first.
    for(i=0; i<NumEls; i++)
        for(j=0; j<3; j++)
            meshele[i].p[j]=newnum[meshele[i].p[j]];

//    // now, sort nodes based on newnum;
//    for(i=0; i<NumNodes; i++)
//    {
//        while(newnum[i]!=i)
//        {
//            CNode swap;
//
//            j=newnum[i];
//            n=newnum[j];
//            newnum[j]=newnum[i];
//            newnum[i]=n;
//            swap=meshnode[j];
//            meshnode[j]=meshnode[i];
//            meshnode[i]=swap;
//        }
//    }

    // virtual method that must be overridden by child classes
    // as the mesh nodes class type varies
    SortNodes (newnum);

    free(newnum);

    SortElements();

    return TRUE;
}
示例#4
0
//=============================================================================
void
GetParticleMesh(
const mesh_t*     mesh,
      particle_t  particle[] )
{
  if ( particle == NULL ) return;
  
  debug( "\nParticles : meshing\n");
  
  // Elements touched by the particles
  int *ElemTouched = NULL,
         *ElemTouchedNodesIn = NULL,
         // store the surface nodes inside particle domain
         *NodesConnectedToOutside = NULL,
         // store the surface innode-outnode connectivity
         ***InOutSurfConTab = NULL;
  
  AllocVint( NODELMT, NodesConnectedToOutside );
  
  InOutSurfConTab = (int***) calloc( mesh->NbOfNodes + 1, sizeof(int**) );
  assert_error( InOutSurfConTab != NULL, "Memory allocation error");
  
  for ( int node = 1 ; node <= mesh->NbOfNodes ; node++ )
  {
    InOutSurfConTab[ node ] = (int**) calloc( 3, sizeof(int*) );
    assert_error( InOutSurfConTab[ node ] != NULL, "Memory allocation error");
    
    for ( int i = 0 ; i <= 2 ; i++ )
      AllocVint(0,InOutSurfConTab[ node ][ i ]);
  }

  // fill in the ParMesh structure
  for ( int iPar = 1 ; iPar <= particle[1].ParNb ; iPar++ )
  {
    // pointer to particle mesh
    Parmesh_t *ParMesh = particle[iPar].mesh;
    
    // Initialization
    InitializeMeshStructure( ParMesh );

    // Number of surface nodes in particle domain
    NodesConnectedToOutside[ 0 ] = 0;
  
    ElemTouched = (int*) realloc( ElemTouched, sizeof(int) );
    ElemTouched[ 0 ] = 0; // Number of element touched
    
    ElemTouchedNodesIn = (int*) realloc( ElemTouchedNodesIn, sizeof(int) );
    ElemTouchedNodesIn[ 0 ] = 0; // Number of element partly inside

    // Find the element which contains the center of mass of the particle
    int temp = 0, // for unused variables

    ElemMassCenter = SearchElemContainingPoint(
                      mesh, true, particle[iPar].Pos0, &temp, &temp);

    // Find the elements and nodes inside the current particle
    ParElemNodeTouch(
      mesh, &particle[ iPar ], ElemMassCenter,
      &ElemTouched, &ElemTouchedNodesIn, &(ParMesh->NodesIn) );

    // Distributes elements touched into elements fully and partly inside
    SortElements(
      ElemTouched, ElemTouchedNodesIn,
      &(ParMesh->ElemFull), &(ParMesh->ElemPartly) );

    debug( "\t" INT_FMT " elements fully inside" "\n",
          ParMesh->ElemFull[ 0 ] );
    debug( "\t" INT_FMT " elements partly inside" "\n",
          ParMesh->ElemPartly[ 0 ] );

    // Find the node-node connections cut
    // find edge node and fill InOutSurfConTab structure
    FillInOutSurfConTab(
      mesh, &particle[ iPar ],
      ParMesh->ElemPartly, ParMesh->points,
      InOutSurfConTab, NodesConnectedToOutside );
    
    // Surface elements are processed on the basis of InOutSurfConTab
    // and added to ElemFull
    ParConnGeo(
      mesh, &particle[ iPar ], ParMesh->points, ParMesh->ConTab,
      &(ParMesh->ElemFull), ParMesh->ElemPartly,
      InOutSurfConTab, NodesConnectedToOutside );
    
    debug( "\t" INT_FMT " nodes on surface\n",
          NodesConnectedToOutside[ 0 ] );
    debug( "\t" INT_FMT " nodes created\n",
          (int) ParMesh->points[ 0 ][ 0 ] );
    debug( "\t" INT_FMT " elements inside after sub-meshing\n",
          ParMesh->ElemFull[ 0 ] );
    
    // write particle mesh to file
//    WriteParMeshVTK( iPar, mesh, ParMesh );

    // statistics
    StatAdd("Particle meshing : elements fully inside",
            ParMesh->ElemFull[ 0 ]);
  }
  
  free(ElemTouched);
  free(ElemTouchedNodesIn);

  free(NodesConnectedToOutside);
  
  for ( int node = 1 ; node <= mesh->NbOfNodes ; node++ )
  {
    for ( int i = 0 ; i <= 2 ; i++ )
      free(InOutSurfConTab[ node ][i]);
    
    free(InOutSurfConTab[ node ]);
  }
  
  free(InOutSurfConTab);
}