Example #1
0
void BlockVector::Update(const Array<int> &bOffsets)
{
   blockOffsets = bOffsets.GetData();
   if (OwnsData())
   {
      // check if 'bOffsets' agree with the 'blocks'
      if (bOffsets.Size() == numBlocks+1)
      {
         if (numBlocks == 0) { return; }
         if (Size() == bOffsets.Last())
         {
            for (int i = numBlocks - 1; true; i--)
            {
               if (i < 0) { return; }
               if (blocks[i].Size() != bOffsets[i+1] - bOffsets[i]) { break; }
               MFEM_ASSERT(blocks[i].GetData() == data + bOffsets[i],
                           "invalid blocks[" << i << ']');
            }
         }
      }
   }
   else
   {
      Destroy();
   }
   SetSize(bOffsets.Last());
   if (numBlocks != bOffsets.Size()-1)
   {
      delete [] blocks;
      numBlocks = bOffsets.Size()-1;
      blocks = new Vector[numBlocks];
   }
   SetBlocks();
}
Example #2
0
void FiniteElementSpace::EliminateEssentialBCFromGRM
(FiniteElementSpace *cfes, Array<int> &bdr_attr_is_ess, SparseMatrix *R)
{
   int i, j, k, one_vdim;
   Array<int> dofs;

   one_vdim = (cfes -> GetNDofs() == R -> Height()) ? 1 : 0;

   mesh -> SetState (Mesh::TWO_LEVEL_COARSE);
   if (bdr_attr_is_ess.Size() != 0)
      for (i=0; i < cfes -> GetNBE(); i++)
         if (bdr_attr_is_ess[cfes -> GetBdrAttribute (i)-1])
         {
            if (one_vdim == 1)
               cfes -> GetBdrElementDofs (i, dofs);
            else
               cfes -> GetBdrElementVDofs (i, dofs);
            for (j=0; j < dofs.Size(); j++)
               if ( (k = dofs[j]) >= 0 )
                  R -> EliminateRow(k);
               else
                  R -> EliminateRow(-1-k);
         }
   R -> Finalize();
}
Example #3
0
void ParBlockNonlinearForm::SetParSpaces(Array<ParFiniteElementSpace *> &pf)
{
   delete pBlockGrad;
   pBlockGrad = NULL;

   for (int s1=0; s1<fes.Size(); ++s1)
   {
      for (int s2=0; s2<fes.Size(); ++s2)
      {
         delete phBlockGrad(s1,s2);
      }
   }

   Array<FiniteElementSpace *> serialSpaces(pf.Size());

   for (int s=0; s<pf.Size(); s++)
   {
      serialSpaces[s] = (FiniteElementSpace *) pf[s];
   }

   SetSpaces(serialSpaces);

   phBlockGrad.SetSize(fes.Size(), fes.Size());

   for (int s1=0; s1<fes.Size(); ++s1)
   {
      for (int s2=0; s2<fes.Size(); ++s2)
      {
         phBlockGrad(s1,s2) = new OperatorHandle(Operator::Hypre_ParCSR);
      }
   }
}
Example #4
0
int RadixSort::Sort(Array &array) const
{
	int maxRadix = 100; 
	std::vector<int> rad(array.Size()); // for stroring mod
	std::vector<int> tmp(array.Size()); // 

	for(int m=1; m <= maxRadix; m*=10)
	{
		for(int i=0; i < array.Size();i++)
		{
			rad[i] = (array[i] / m) % 10;
		}
		
		int k = 0;
		for(int i=0; i < 10; i++)
		{
			for(int j=0; j < array.Size(); j++)
			{
				if(rad[j] == i)
				{
					tmp[k++] = array[j]; // copy array to tmp based on 'mod'
				}
			}
		}
		
		for(int i=0; i< array.Size(); i++)
		{
			array[i] = tmp[i];   // copy tmp back to array
		}
		// array.Print("->");
	}
	return 0;
}
Example #5
0
void GroupCommunicator::Create(Array<int> &ldof_group)
{
   group_ldof.MakeI(gtopo.NGroups());
   for (int i = 0; i < ldof_group.Size(); i++)
   {
      int group = ldof_group[i];
      if (group != 0)
      {
         group_ldof.AddAColumnInRow(group);
      }
   }
   group_ldof.MakeJ();

   for (int i = 0; i < ldof_group.Size(); i++)
   {
      int group = ldof_group[i];
      if (group != 0)
      {
         group_ldof.AddConnection(group, i);
      }
   }
   group_ldof.ShiftUpI();

   Finalize();
}
int DiscreteJacobianField::GetJacobian(const Array<Matrix> & jacobians, const Sample & sample, Matrix & jacobian) const
{
    if(! _domain.Adopt(sample, _sample))
    {
        throw Exception("DiscreteJacobianField::GetJacobian(): cannot adopt sample");
        return 0;
    }

    if(! LocateCell(_sample, _cell_size, _index))
    {
        throw Exception("DiscreteJacobianField::GetJacobian(): cannot locate cell");
        return 0;
    }

    for(unsigned int i = 0; i < _index.size(); i++)
    {
        if(_index[i] < 0) _index[i] = 0;
        if(_index[i] >= jacobians.Size(i)) _index[i] = jacobians.Size(i)-1;
    }

    if(!jacobians.Get(_index, jacobian))
    {
        throw Exception("DiscreteJacobianField::GetJacobian(): cannot get jacobian");
        return 0;
    }

    return 1;
}
Example #7
0
// Add a bunch of strings together to produce a more robust key
void Crypto::ConstructKeyFromStrings( const Array< SimpleString >& Keys, Array< char >& OutKey )
{
	ASSERT( Keys.Size() );

	Array< Array< char > > KeyArrays;
	uint Length = Keys[0].Length();

	// Push arrays one at a time instead of resizing, so they are constructed and not simply allocated
	for( uint KeyIndex = 0; KeyIndex < Keys.Size(); ++KeyIndex )
	{
		const SimpleString& Key = Keys[ KeyIndex ];
		KeyArrays.PushBack( Array< char >() );
		Key.FillArray( KeyArrays[ KeyIndex ] );
		Length = Min( Length, Key.Length() );
	}

	OutKey.Clear();
	for( uint Index = 0; Index < Length; ++Index )
	{
		OutKey.PushBack( 0 );
		for( uint KeyIndex = 0; KeyIndex < Keys.Size(); ++KeyIndex )
		{
			OutKey[ Index ] = ( OutKey[ Index ] + KeyArrays[ KeyIndex ][ Index ] ) & 255;
		}
	}
}
Example #8
0
void LineBatcher::Add(const Array<Vector>& m_AddPositions,
                      const Array<uint>& m_AddColors,
                      const Array<index_t>& m_AddIndices) {
#if BUILD_RELEASE
  if (m_IsDebug) {
    return;
  }
#endif

  ASSERT(m_AddPositions.Size() == m_AddColors.Size());

  uint OldSize = m_Positions.Size();
  uint NewSize = OldSize + m_AddPositions.Size();

  m_Positions.Resize(NewSize);
  m_Colors.Resize(NewSize);
  for (uint i = OldSize, j = 0; i < NewSize; ++i, ++j) {
    m_Positions[i] = m_AddPositions[j];
    m_Colors[i] = m_AddColors[j];
  }

  uint OldIndicesSize = m_Indices.Size();
  uint NewIndicesSize = OldIndicesSize + m_AddIndices.Size();
  m_Indices.Resize(NewIndicesSize);
  for (uint i = OldIndicesSize, j = 0; i < NewIndicesSize; ++i, ++j) {
    m_Indices[i] = m_AddIndices[j] + (index_t)OldSize;
  }
}
Example #9
0
void FiniteElementSpace::DofsToVDofs(int vd, Array<int> &dofs) const
{
   if (vdim == 1)
      return;
   if (ordering == Ordering::byNODES)
   {
      for (int i = 0; i < dofs.Size(); i++)
      {
         int dof = dofs[i];
         if (dof < 0)
            dofs[i] = -1 - ((-1-dof) + vd * ndofs);
         else
            dofs[i] = dof + vd * ndofs;
      }
   }
   else
   {
      for (int i = 0; i < dofs.Size(); i++)
      {
         int dof = dofs[i];
         if (dof < 0)
            dofs[i] = -1 - ((-1-dof) * vdim + vd);
         else
            dofs[i] = dof * vdim + vd;
      }
   }
}
Example #10
0
void STLEdgeDataList :: BuildClusterWithEdge(int ep1, int ep2, Array<twoint>& line)
{
    int status = Get(GetEdgeNum(ep1,ep2)).GetStatus();

    int p(0), en;
    int j, i, k;
    int oldend;
    int newend = 1;
    int pnew, ennew(0);

    int changed = 1;
    while (changed)
    {
        changed = 0;
        for (j = 1; j <= 2; j++)
        {
            oldend = newend;
            newend = line.Size();
            for (k = oldend; k <= line.Size(); k++)
            {
                if (j == 1) p = line.Get(k).i1;
                if (j == 2) p = line.Get(k).i2;
                en = GetEdgeNum(line.Get(k).i1, line.Get(k).i2);

                for (i = 1; i <= GetNEPP(p); i++)
                {
                    pnew = 0;
                    const STLTopEdge & e = Get(GetEdgePP(p,i));
                    if (GetEdgePP(p,i) != en && e.GetStatus() == status)
                    {
                        if (e.PNum(1) == p)
                        {
                            pnew = e.PNum(2);
                        }
                        else
                        {
                            pnew = e.PNum(1);
                        }

                        ennew = GetEdgePP(p,i);
                    }
                    if (pnew && !Exists(p,pnew,line))
                    {
                        changed = 1;
                        line.Append(twoint(p,pnew));
                        p = pnew;
                        en = ennew;
                    }
                }

            }
        }

    }

}
Example #11
0
  void MGPreconditioner::MemoryUsage (Array<MemoryUsageStruct*> & mu) const
  {
    int olds = mu.Size();
    
    // if (&GetMatrix())
    GetMatrix().MemoryUsage (mu);;

    for (int i = olds; i < mu.Size(); i++)
      mu[i]->AddName (string(" mgpre ")); // +GetName());
  }
Example #12
0
void QickSort (const Array<double> & values,
	       Array<int> & order)
{
  int i, n = values.Size();
  order.SetSize (n);
  for (i = 1; i <= n; i++)
    order.Elem(i) = i;

  QickSortRec (values, order, 1, order.Size());
}
Example #13
0
File: table.cpp Project: YPCC/mfem
void Transpose(const Array<int> &A, Table &At, int _ncols_A)
{
   At.MakeI((_ncols_A < 0) ? (A.Max() + 1) : _ncols_A);
   for (int i = 0; i < A.Size(); i++)
      At.AddAColumnInRow(A[i]);
   At.MakeJ();
   for (int i = 0; i < A.Size(); i++)
      At.AddConnection(A[i], i);
   At.ShiftUpI();
}
Example #14
0
void AddStatus( const SimpleString& Status, uint8 Color )
{
	SStatus NewStatus;
	NewStatus.m_Status = Status;
	NewStatus.m_Color = Color;

	g_Statuses.PushBack( NewStatus );
	g_StatusOffset = g_Statuses.Size() > g_NumStatusLines ? g_Statuses.Size() - g_NumStatusLines : 0;

	PRINTF( SimpleString::PrintF( "Status: %s\n", Status.CStr() ).CStr() );
}
Example #15
0
void InputManager::DispatchKeyboardEvent(CEvent * eventData) {
std::map<EEvent, Array<IObserver*>>::iterator it = m_observers.find(ON_KEYBOARD_EVENT);
	if (it != m_observers.end()) {
		Array<IObserver*> observers = it->second;
		if (observers.Size()) {
			for (uint32 i = 0; i < observers.Size(); i++) {
				observers[i]->OnKeyboardEvent(static_cast<CKeyboardEvent *>(eventData));
			}
		}
	}
}
Example #16
0
void BlockVector::Update(double *data, const Array<int> & bOffsets)
{
   NewDataAndSize(data, bOffsets.Last());
   blockOffsets = bOffsets.GetData();
   if (numBlocks != bOffsets.Size()-1)
   {
      delete [] blocks;
      numBlocks = bOffsets.Size()-1;
      blocks = new Vector[numBlocks];
   }
   SetBlocks();
}
Example #17
0
void GetStatus(MyStr & s, double & percentage)
{
  if(threadpercent_stack.Size() > 0)
    percentage = threadpercent_stack.Last();
  else
    percentage = multithread.percent;
  
  if ( msgstatus_stack.Size() )
    s = *msgstatus_stack.Last();
  else
    s = "idle";     
}
Example #18
0
		int Add(int _x, int _y, const Vec3 & pos)
		{
			for (int i = 0; i < vertArray.Size(); ++i)
			{
				if (vertArray[i]._x == _x && vertArray[i]._y == _y)
					return i;
			}

			Vertex v = { _x, _y, pos };

			vertArray.PushBack(v);

			return vertArray.Size() - 1;
		}
Example #19
0
int main(int argc, char* argv[]) {
    Screen& screen = Screen::Instance();
    const Renderer& renderer = Renderer::Instance();

    screen.Open(screen.GetDesktopWidth(), screen.GetDesktopHeight(), true);
    //screen.Open(800, 600, false);
    renderer.SetBlendMode(Renderer::ALPHA);

	// Cargamos la imagen
    Image* image = ResourceManager::Instance().LoadImage("data/images/ball.png");
    image->SetMidHandle();
	
	float angle = 0;
	double accum = 0;
    Array<Trail> trails;
    while ( screen.IsOpened()  &&  !screen.KeyPressed(GLFW_KEY_ESC) ) {
		// Actualizamos angulo de la imagen
        angle += 30 * screen.ElapsedTime();

		// Actualizamos los rastros
        accum += screen.ElapsedTime();
		if ( accum >= 0.05 ) {
            trails.Add(Trail(screen.GetMouseX(), screen.GetMouseY(), angle));
            if ( trails.Size() > NUMTRAILS ) {
                trails.RemoveAt(0);
				accum = 0;
			}
		}

		// Limpiamos fondo de pantalla
        renderer.Clear(0, 0, 0);

		// Dibujamos rastro
        for ( int i = 0; i < trails.Size(); i++ ) {
            renderer.SetColor(255, 255, 255, 256/(trails.Size()-i+1));
            renderer.DrawImage(image, trails[i].x, trails[i].y, 0, 0, 0, trails[i].angle);
		}

		// Dibujamos imagen
        renderer.SetColor(255, 255, 255, 255);
        renderer.DrawImage(image, screen.GetMouseX(), screen.GetMouseY(), 0, 0, 0, angle);

		// Refrescamos la pantalla
        screen.Refresh();
	}

    ResourceManager::Instance().FreeResources();

	return 0;
}
Example #20
0
  void VisualSceneSpecPoints :: BuildScene (int zoomall)
  {
    if (!mesh) 
      {
	VisualScene::BuildScene(zoomall);
	return;
      }
  
    Box3d box;
  
    if (mesh->GetNSeg())
      {
	box.SetPoint (mesh->Point (mesh->LineSegment(1)[0]));
	for (int i = 1; i <= mesh->GetNSeg(); i++)
	  {
	    box.AddPoint (mesh->Point (mesh->LineSegment(i)[0]));
	    box.AddPoint (mesh->Point (mesh->LineSegment(i)[1]));
	  }
      }
    else if (specpoints.Size() >= 2)
      {
	box.SetPoint (specpoints.Get(1).p);
	for (int i = 2; i <= specpoints.Size(); i++)
	  box.AddPoint (specpoints.Get(i).p);
      }
    else
      {
	box = Box3d (Point3d (0,0,0), Point3d (1,1,1));
      }
  
    if (zoomall == 2 && ((vispar.centerpoint >= 1 && vispar.centerpoint <= mesh->GetNP()) ||
			 vispar.use_center_coords))
      {
	if (vispar.use_center_coords)
	  {
	    center.X() = vispar.centerx; center.Y() = vispar.centery; center.Z() = vispar.centerz; 
	  }
	else
	  center = mesh->Point (vispar.centerpoint);
      }
    else
      center = Center (box.PMin(), box.PMax());
        

    rad = 0.5 * Dist (box.PMin(), box.PMax());
  
  
    CalcTransformationMatrices();
  }
Example #21
0
void referencetransform :: ToPlain (const Array<Point3d> & p,
                                    Array<Point3d> & pp) const
{
  Vec3d v;
  int i;

  pp.SetSize (p.Size());
  for (i = 1; i <= p.Size(); i++)
    {
      v = p.Get(i) - rp;
      pp.Elem(i).X() = (ex_h * v);
      pp.Elem(i).Y() = (ey_h * v);
      pp.Elem(i).Z() = (ez_h * v);
    }
}
Example #22
0
// Convert archived names and comments to Unicode.
// Allows user to select a code page in GUI.
void ArcCharToWide(const char *Src,wchar *Dest,size_t DestSize,ACTW_ENCODING Encoding)
{
#if defined(_WIN_ALL) // Console Windows RAR.
  if (Encoding==ACTW_UTF8)
    UtfToWide(Src,Dest,DestSize);
  else
  {
    Array<char> NameA;
    if (Encoding==ACTW_OEM)
    {
      NameA.Alloc(DestSize+1);
      IntToExt(Src,&NameA[0],NameA.Size());
      Src=&NameA[0];
    }
    CharToWide(Src,Dest,DestSize);
  }
#else // RAR for Unix.
  if (Encoding==ACTW_UTF8)
    UtfToWide(Src,Dest,DestSize);
  else
    CharToWide(Src,Dest,DestSize);
#endif
  // Ensure that we return a zero terminate string for security reason.
  // While [Jni]CharToWide might already do it, be protected in case of future
  // changes in these functions.
  if (DestSize>0)
    Dest[DestSize-1]=0;
}
Example #23
0
void _stdcall SendVars(CObjNPC* npc, short value, short var){
	if(!g_pZoneLIST) return;
	if(!gInitDone) return;

	classPACKET* cpak = Packet_AllocNLock();
	if(!cpak) return;

	int npcid = npc->m_nCharIdx;
	for(unsigned int i = 0; i < gNpcVars.Size(); ++i){
		NpcCmd* pCmd = gNpcVars[i];
		if(pCmd->mNpc != npcid) continue;

		if(var == 0 && (value == 0 || value == 1))
			ClearPvpIpList(npcid);

		CPacket* pak = (CPacket*)cpak;
		pak->CreateNew(PAK_NPCVAR);
		pak->Add<OneVAR>(OneVAR(pCmd->mGame, pCmd->mInstance, pCmd->mScore, var, value));

		if(pCmd->mScore == true && value != 0){
			CZoneTHREAD* zone = g_pZoneLIST->GetZONE(pCmd->mZone);
			if(zone)
				zone->SendPacketToZONE((t_PACKET*)cpak);
		}else{
			for(int i = 1; i <= g_pZoneLIST->GetZoneCNT(); ++i){
				CZoneTHREAD* zone = g_pZoneLIST->GetZONE(i);
				if(!zone) continue;
				zone->SendPacketToZONE((t_PACKET*)cpak);
			}
		}
	}

	Packet_ReleaseNUnlock(cpak);
}
Example #24
0
void FiniteElementSpace::DofsToVDofs (Array<int> &dofs) const
{
   int i, j, size;

   if (vdim == 1)  return;

   size = dofs.Size();
   dofs.SetSize (size * vdim);

   switch(ordering)
   {
   case Ordering::byNODES:
      for (i = 1; i < vdim; i++)
         for (j = 0; j < size; j++)
            if (dofs[j] < 0)
               dofs[size * i + j] = -1 - ( ndofs * i + (-1-dofs[j]) );
            else
               dofs[size * i + j] = ndofs * i + dofs[j];
      break;

   case Ordering::byVDIM:
      for (i = vdim-1; i >= 0; i--)
         for (j = 0; j < size; j++)
            if (dofs[j] < 0)
               dofs[size * i + j] = -1 - ( (-1-dofs[j]) * vdim + i );
            else
               dofs[size * i + j] = dofs[j] * vdim + i;
      break;
   }
}
 inline void MyMPI_Bcast (Array<T, 0> & s, MPI_Comm comm = MPI_COMM_WORLD)
 {
   int size = s.Size();
   MyMPI_Bcast (size, comm);
   if (id != 0) s.SetSize (size);
   MPI_Bcast (&s[0], size, MyGetMPIType<T>(), 0, comm);
 }
Example #26
0
int ShellSort::Sort(Array &array) const
{

	int inc = 4;

	while(inc > 0)
	{
		for(int i=0; i < array.Size(); i++)
		{
			int j = i;
			int temp = array[i];
			while((j>=inc) && (array[j-inc] > temp))
			{
				array[j]= array[j-inc];
				j = j - inc;
			}
			array[j] = temp;
		}
		array.Print("->");
		if(inc / 2 != 0)
			inc = inc / 2;
		else if(inc == 1)
			inc = 0;
		else
			inc = 1;
	}
	
	return 0;
}
Example #27
0
bool Segment2D::Intersects( const Array<Triangle2D>& Tris, CollisionInfo2D* const pInfo /*= NULL*/ ) const
{
	CollisionInfo2D Info;
	CollisionInfo2D MinInfo;

	if( pInfo )
	{
		Info.CopyInParametersFrom( *pInfo );
	}

	const uint NumTris = Tris.Size();
	for( uint TriangleIndex = 0; TriangleIndex < NumTris; ++TriangleIndex )
	{
		if( Intersects( Tris[ TriangleIndex ], &Info ) )
		{
			if( Info.m_HitT < MinInfo.m_HitT || !MinInfo.m_Collision )
			{
				MinInfo = Info;
			}
		}
	}

	if( MinInfo.m_Collision )
	{
		if( pInfo )
		{
			pInfo->CopyOutParametersFrom( MinInfo );
		}
		return true;
	}

	return false;
}
Example #28
0
File: CHR.hpp Project: exjam/r3e
			AnimationLink* GetAnimation(int type){
				for(unsigned int i = 0; i < mAnimationLinks.Size(); ++i)
					if(mAnimationLinks[i].mType == type)
						return &mAnimationLinks[i];

				return NULL;
			}
Example #29
0
void Emitter::Update(double elapsed)
{	
	Array<int> deleteParticles;

	if (emitting) 
	{
		int nParticles = (minrate + (maxrate - minrate) * (float)rand() / RAND_MAX) * elapsed;	
        for (int i = 0; i < nParticles; i++) 
            particles.Add(CreateParticle());        
	}	    

    for (int i = 0; i < particles.Size(); i++) 
	{
		particles[i]->Update(elapsed);

		for (uint8 a = 0; a < affectors.Size(); a++)
			if (affectors[a]->IsCollide(particles[i])) affectors[a]->AffectParticle(particles[i]);

        if ( particles[i]->GetLifetime() <= 0 )
            deleteParticles.Add(i);
	}

    for (int i = 0; i < deleteParticles.Size(); i++ ) 
    {    		
		for (uint8 a = 0; a < affectors.Size(); a++)
			affectors[a]->DeleteAffectedParticle(particles[i]);

		particles.RemoveAt(i);
	}
							
}
Example #30
0
 void Flags :: SetFlag (const char * name, const Array<double> & val)
 {
   Array<double> * numarray = new Array<double>;
   for (int i = 1; i <= val.Size(); i++)
     numarray->Append (val.Get(i));
   numlistflags.Set (name, numarray);
 }