/// <summary> /// Finds the best matching unit. /// </summary> /// <param name="grid">The grid.</param> /// <param name="datum">The datum.</param> /// <returns>INeuron.</returns> public IBestMatchingUnit FindBestMatchingUnit(IGrid2D grid, IDatum datum) { // get weights from datum var referenceWeighs = datum.MapToWeights(); // prepare search var metric = _metric; var smallestDistance = Double.NaN; var bmu = null as IGridNeuron; // linear search foreach (var gridNeuron in grid) { var weigths = gridNeuron.Neuron.Weights; var distance = metric.CalculateDistance(referenceWeighs, weigths); if (!(Double.IsNaN(smallestDistance) || distance < smallestDistance)) { continue; } smallestDistance = distance; bmu = gridNeuron; } return(new BestMatchingUnit(bmu, smallestDistance)); }
public CloudInCell(IParticleStorage<Particle> particles, IGrid2D grid, IMesh mesh, bool parallel) { this.particles = particles; this.grid = grid; this.mesh = mesh; this.parallel = parallel; }
public void Test() { u = 100000; particles = new ParticleArrayStorage<Particle>(1000000); boundaryConditions = new BoundaryConditions { Top = new BoundaryCondition { Value = x => 0, Type = BoundaryConditionType.Neumann }, Bottom = new BoundaryCondition { Value = x => 0, Type = BoundaryConditionType.Neumann }, Left = new BoundaryCondition { Value = x => 0, Type = BoundaryConditionType.Dirichlet }, Right = new BoundaryCondition { Value = x => u, Type = BoundaryConditionType.Dirichlet } }; grid = new Grid2D(); grid.InitializeGrid(5, 5, 0, 4, 0, 4); mesh = new Mesh2D(); mesh.InitializeMesh(grid.N * grid.M); interpolator = new CloudInCellCurrentLinkage(particles, grid, mesh, false); poissonSolver = new Poisson2DFdmSolver(grid, boundaryConditions); poissonSolver.FdmMatrix = poissonSolver.BuildMatrix(); var particle = new Particle(4, 1, 0, 0, 0, 0, 1); var particleId = particles.Add(particle); particles.Set(Field.PrevX, particleId, 2); particles.Set(Field.PrevY, particleId, 1); var cell = grid.FindCell(particles.Get(Field.X, particleId), particles.Get(Field.Y, particleId)); particles.SetParticleCell(particleId, cell); interpolator.InterpolateDensity(); }
public void Prepare(PICProject project) { w = project.Relaxation; backscattering = project.Backscattering; alfa = project.BackscatteringAlfa; beta = project.BackscatteringBeta; step = project.Step; u = project.Voltage; particles = new ParticleArrayStorage<Particle>(project.ParticlesCount); boundaryConditions = new BoundaryConditions { Top = new BoundaryCondition { Value = x => 0, Type = BoundaryConditionType.Neumann }, Bottom = new BoundaryCondition { Value = x => 0, Type = BoundaryConditionType.Neumann }, Left = new BoundaryCondition { Value = x => 0, Type = BoundaryConditionType.Dirichlet }, Right = new BoundaryCondition { Value = x => u, Type = BoundaryConditionType.Dirichlet } }; emitter = new Emitter2D(0, project.EmitterBottom, 0, project.EmitterTop, project.ParticlesCount, 0, 0, -0.5 * Constants.ChildLangmuirCurrent(project.Length, u), step); mover = new Leapfrog(); grid = new Grid2D(); grid.InitializeGrid(project.GridN, project.GridM, 0, project.Length, 0, project.Height); mesh = new Mesh2D(); mesh.InitializeMesh(grid.N * grid.M); interpolator = new CloudInCellCurrentLinkage(particles, grid, mesh, false); poissonSolver = new Poisson2DFdmSolver(grid, boundaryConditions); poissonSolver.FdmMatrix = poissonSolver.BuildMatrix(); h = step * Constants.LightVelocity; Monitor = new PICMonitor(grid, mesh, particles, this); density = new double[grid.N * grid.M]; Trajectories = new List<Tuple<int, double, double>>(particles.Count * 1000); }
public PICMonitor(IGrid2D grid, IMesh mesh, IParticleStorage<Particle> particles, IPICSolver solver) { this.grid = grid; this.particles = particles; this.mesh = mesh; this.solver = solver; GridX = grid.X; GridY = grid.Y; Status = PICStatus.Created; }
public Poisson2DFdmSolver(IGrid2D grid, BoundaryConditions boundary) { this.boundary = boundary; n = grid.N; m = grid.M; x = grid.X; y = grid.Y; dx = grid.Hx; dy = grid.Hy; InitializeSolver(); }
/// <summary> /// Sets the grid. /// </summary> /// <param name="grid">The grid.</param> public void SetGrid(IGrid2D grid) { _grid = grid; Invalidate(); }