コード例 #1
0
ファイル: ExternalField.cs プロジェクト: RugCode/drg-pt
		public ExternalField(ParticleEnsemble ensemble)
		{
			GrabberCalls = 0;
			CalibrationCalls = 1;
			consecutiveZeroThreshold = 3;
			BoxHeight = ensemble.GetBoxHeight();
			BoxWidth = ensemble.GetBoxWidth();
			Calibrating = false;

			// initialize background pixels
			BackgroundPixels = new List<double>(new double[BoxHeight * BoxWidth]);

			// initialize the calibration count vector
			calibrationCountVector = new List<double>(new double[BoxHeight * BoxWidth]);

			// initialize timeTpixels
			timeTpixels = new List<double>(new double[BoxHeight * BoxWidth]);

			// initialize consecutiveZerosCount
			consecutiveZerosCount = new List<double>(new double[BoxHeight * BoxWidth]);

			// allocate vectors holding positions & forces
			xforces = new List<double>(new double[ensemble.GetNumberOfParticles()]);
			yforces = new List<double>(new double[ensemble.GetNumberOfParticles()]);

			// set up the gaussian array with the desired smoothing width parameter
			sigma = 10;
			nGaussPoints = 2 * (3 * sigma) + 1;
			RangeEitherSide = 3 * sigma;
			gaussian = new List<double>(new double[nGaussPoints]);
			double point = -1.0 * (3.0 * (double)sigma);
			for (int i = 0; i < nGaussPoints; ++i)
			{
				gaussian[i] = Math.Exp(-0.5 * (Math.Pow(point / (double)sigma, 2.0))) / ((double)sigma * Math.Sqrt(2.0 * Math.PI));
				//    cout << point << " " << gaussian[i] << endl;
				++point;
			}

		}
コード例 #2
0
ファイル: ExternalField.cs プロジェクト: RugCode/drg-pt
		/// <summary>
		/// function to calculate Soft Spheres forcefield
		/// </summary>
		/// <param name="ensemble"></param>
		public override void CalculateForceField(ParticleEnsemble ensemble)
		{
			//  variable declarations    
			int i;
			double posXi, posYi, radius;
			double PotentialEnergy = 0.0;

			// variable initializations  
			int BoxHeight = ensemble.GetBoxHeight();
			int BoxWidth = ensemble.GetBoxWidth();

			// #pragma omp parallel for
			for (i = 0; i < ensemble.GetNumberOfParticles(); ++i)
			{
				// initialize vectors holding forces
				xforces[i] = 0.0;																			// HERE'S THE PROBLEM - THE INDEX WILL OVERRUN THE VECTOR SIZE!!!
				yforces[i] = 0.0;
			}

			//#pragma omp parallel for
			for (i = 0; i < ensemble.GetNumberOfParticles(); ++i)
			{
				posXi = ensemble.GetXParticlePosition(i);
				posYi = ensemble.GetYParticlePosition(i);
				radius = ensemble.GetParticleRadius(i);

				// get pixel vectors along the particle's X & Y axes for getting gradient of image field
				// there are 2 steps to this process: 
				//  (1) do some gaussian smoothing with a user defined width parameter (this determines how
				//      many pixels we need
				//  (2) determine the gradient from linear regression of the 3 surrounding points...
				//    cout << "particle " << i << " Xpos " << posXi << " Ypos " << posYi << endl;

				//    first get the vectors that we need - the length of the vectors depend on the width of the gaussian
				//    if the pixels are near the edge, the pixels beyond them (which arent in the image) are simply returned as zeros

				//    vector < double > AllThePixelsAlongX = pParticleSet->GetAllThePixelsAlongX(posYi,posXi,RangeEitherSide);
				//    xforces[i] = pParticleSet->GetGradientScaleFactor()*GaussianSmoothedSlope(posXi,AllThePixelsAlongX);
				//    cout << "Xposition " << posXi << endl;

				if (m_CalculateForceField_TempArray.Length < RangeEitherSide + 1)
				{
					m_CalculateForceField_TempArray = new double[RangeEitherSide + 1]; 
				}

				int count; 

				GetSubsetOfPixelsAlongX(posYi, posXi, RangeEitherSide + 1, ref m_CalculateForceField_TempArray, out count);
				//    for(int kk=0; kk<SubsetOfPixelsAlongX.size(); ++kk){
				//      cout << kk << " " << SubsetOfPixelsAlongX[kk] << endl;      
				//    }

				//    cout << "Xposition " << posXi << endl;
				//    for(int kk=1;kk<SubsetOfPixelsAlongX.size();++kk){cout << kk << " " << SubsetOfPixelsAlongX[kk] << endl;}
				xforces[i] = ensemble.GetGradientScaleFactor() * GaussianSmoothedSlope(posXi, m_CalculateForceField_TempArray, count);

				//    vector < double > AllThePixelsAlongY = pParticleSet->GetAllThePixelsAlongY(posXi,posYi,RangeEitherSide);
				//    cout << "Yposition " << posYi << endl;
				//    for(int kk=0;kk<AllThePixelsAlongY.size();++kk){cout << kk << " " << AllThePixelsAlongY[kk] << endl;}
				//    yforces[i] = pParticleSet->GetGradientScaleFactor()*GaussianSmoothedSlope(posYi,AllThePixelsAlongY);


				GetSubsetOfPixelsAlongY(posXi, posYi, RangeEitherSide + 1, ref m_CalculateForceField_TempArray, out count);
				//List<double> SubsetOfPixelsAlongY = GetSubsetOfPixelsAlongY(posXi, posYi, RangeEitherSide + 1);
				//    cout << "Yposition " << endl;
				yforces[i] = ensemble.GetGradientScaleFactor() * GaussianSmoothedSlope(posYi, m_CalculateForceField_TempArray, count);
				//    cout << "yforces[i] " << i << " " << yforces[i] << endl;    

				// get the gradient scale factor, depending on whether the particle is attractive or repulsive

				ParticleInfo typeInfo = ParticleStaticObjects.AtomPropertiesDefinition.Lookup[(ensemble.pParticleVector[i]).TypeID];
				double attractiveOrRepulsiveFactor = typeInfo.AttractiveOrRepulsive;
				xforces[i] *= attractiveOrRepulsiveFactor;
				yforces[i] *= attractiveOrRepulsiveFactor;

			}


			ensemble.AddXForces(xforces);		  // set the forces in the Particle Ensemble Object
			ensemble.AddYForces(yforces);			// set the potential energy
			ensemble.AddPotentialEnergy(PotentialEnergy);		// add in the potential energy    

		}
コード例 #3
0
ファイル: SoftSpheres.cs プロジェクト: RugCode/drg-pt
		public override void CalculateForceField(ParticleEnsemble ensemble)
		{

			//variable declarations
			double posXi, posYi;
			double posXj, posYj;
			double LJxf,  LJyf;
			double ijSeparation = 0.0, LJforce = 0.0, PotentialEnergy = 0.0;
			int j, kk, ctr, dimensions = 2;
  
			//variable initializations

			int BoxHeight = ensemble.GetBoxHeight();
			int BoxWidth = ensemble.GetBoxWidth();
			double MaxForce = ensemble.GetMaxForceThreshold();
			double MinForce = -1.0 * (ensemble.GetMaxForceThreshold());
  
			// initialize vectors holding forces
			for (int i = 0; i < ensemble.GetNumberOfParticles(); ++i)
			{
				LJxforces[i]=0.0;
				LJyforces[i]=0.0;
			}

			for (int i = 0; i < ensemble.GetNumberOfParticles(); ++i)
			{

				for (j = (i + 1); j < ensemble.GetNumberOfParticles(); ++j)
				{
      
					//    get the interparticle separation distances
					ijSeparation = ensemble.GetInterParticleSeparation(i, j);
						
					//		update the radial distribution function
			  //			pParticleSet->UpdateRadialDistributionFunction((int)(ijSeparation));
			
					double cutoffDistance = MinimumDistance[i, j];
			
					if (ijSeparation < cutoffDistance) {
	
						// for each particle, change the appropriate element of the setWithinRangeOfAnotherParticle vector to true

						posXi = ensemble.GetXParticlePosition(i);
						posYi = ensemble.GetYParticlePosition(i);

						posXj = ensemble.GetXParticlePosition(j);
						posYj = ensemble.GetYParticlePosition(j);
												
						//        PotentialEnergy += LJenergyTermA[i][j]/(pow(ijSeparation,12.0))+LJenergyTermB[i][j]/pow(ijSeparation,6.0)+epsilon;
						LJforce = (posXj - posXi) * (LJgradientTermA[i, j] / Math.Pow(ijSeparation, 13.0) + LJgradientTermB[i, j] / Math.Pow(ijSeparation, 7.0)) / ijSeparation;
						if (Math.Abs(LJforce) > MaxForce || Math.Abs(LJforce) < MinForce) { LJforce = 0.0; }    // error check for real-time stability...
						else if(double.IsNaN(LJforce) || double.IsInfinity(LJforce)){LJforce = 0.0;} // error check for real-time stability...
				
						LJxforces[i] += LJforce;
						LJxforces[j] += -1.0*LJforce;
						//        cout << "x "<< i << " " << j << " " << LJforce << endl; 
				//				cout << "i " << i << " LJxforces[i] " << LJxforces[i] << " j " << j <<  " LJxforces[j] " << LJxforces[j] << endl;
						//        cout << "xi:=" << posXi << ";" << "xj:=" << posXj << ";" << "yi:=" << posYi << ";" << "yj:=" << posYj << ";" << LJxforces[i] << endl;
						LJforce = (posYj - posYi) * (LJgradientTermA[i, j] / Math.Pow(ijSeparation, 13.0) + LJgradientTermB[i, j] / Math.Pow(ijSeparation, 7.0)) / ijSeparation;

						if (Math.Abs(LJforce) > MaxForce || Math.Abs(LJforce) < MinForce) { LJforce = 0.0; }    // error check for real-time stability...
						else if (double.IsNaN(LJforce) || double.IsInfinity(LJforce)) { LJforce = 0.0; } // error check for real-time stability...
				
						LJyforces[i] += LJforce;
						LJyforces[j] += -1.0*LJforce;

						ensemble.SetParticlesWithinRange(i, j);
						ensemble.SetParticlesWithinRange(j, i);
				
						//        cout << i << " " << j << endl; 
					}
					else{
						ensemble.SetParticlesNotWithinRange(i, j);
						ensemble.SetParticlesNotWithinRange(j, i);			
					}
				}        
			}
	
			// set the forces in the Particle Ensemble Object
			ensemble.AddXForces(LJxforces);
			ensemble.AddYForces(LJyforces);
			// set the potential energy
			ensemble.AddPotentialEnergy(PotentialEnergy);
		}