Exemplo n.º 1
0
        /// <summary>
        /// Generates the randrom particles.
        /// </summary>
        /// <param name="material">Particles material.</param>
        /// <param name="radius">The radius of the sphere.</param>
        /// <param name="count">Particles count.</param>
        public static List<Particle> GenerateRandromParticlesInSphere( Material material, double radius, int count )
        {
            var res = new List<Particle>();

            var rand = new Random();

            for( int i = 0; i < count; i++ )
            {
                var particle = new Particle( material );

                particle.RadiusVector = new Vector( ( rand.NextDouble() - 0.5 ) * radius, 
                    ( rand.NextDouble() - 0.5 ) * radius, 
                    ( rand.NextDouble() - 0.5 ) * radius );

                // TODO: Improve algorithm to avoid intersections
                bool isIntersected = res.Any( particle.isIntersected );
                if( isIntersected )
                {
                    i--;
                    continue;
                }

                res.Add( particle );
            }

            return res;
        }
Exemplo n.º 2
0
        public Particle( Material material )
        {
            Material = material;
        
            var rand = new Random();

            EasyAnisotropyAxis = new Vector( ( rand.NextDouble() - 0.5 ),
                ( rand.NextDouble() - 0.5 ),
                ( rand.NextDouble() - 0.5 ) );
            EasyAnisotropyAxis = EasyAnisotropyAxis.Norm();

            MagneticVector = new Vector( ( rand.NextDouble() - 0.5 ),
                ( rand.NextDouble() - 0.5 ),
                ( rand.NextDouble() - 0.5 ) );
            MagneticVector = MagneticVector.Norm();
        }
Exemplo n.º 3
0
        static void Main( string[] args )
        {
            var appName = AppDomain.CurrentDomain.FriendlyName;

            bool needShowHelp = false;

            double anisotropy = Defaults.Anisotropy;
            double saturation = Defaults.Saturation;
            double particleRadius = Defaults.ParticleRadius;

            double dt = Defaults.Dt;
            double epsillon = Defaults.Epsillon;

            double clusterRadius = Defaults.ClusterRadius;

            double minH = Defaults.MinH;
            double maxH = Defaults.MaxH;
            double stepH = Defaults.StepH;

            int particlesCount = 40;
            Utils.VerbosityLevel++;

            var p = new OptionSet();
            p.Add( "n|particles-count=", "Count of particles.", (int v ) => particlesCount = v );

            p.Add( "a|anisotropy=", "Magnetic anisotropy of the material.", (double v ) => anisotropy = v );
            p.Add( "s|saturation=", "Magnetic saturation of the material.", (double v ) => saturation = v );
            p.Add( "p|particle-radius=", "Radius of a particular of the material.", (double v ) => particleRadius = v );

            p.Add( "d|dt=", "", (double v ) => dt = v );
            p.Add( "e|epsillon=", "", (double v ) => epsillon = v );

            p.Add( "c|cluster-radius=", "Radius of the sphere.", (double v ) => clusterRadius = v );

            p.Add( "min=", "Min value of H.", (double v ) => minH = v );
            p.Add( "max=", "Max value of H.", (double v ) => maxH = v );
            p.Add( "step=", "Step for H.", (double v ) => stepH = v );

            p.Add( "h|help", "Show this message and exit", v => needShowHelp = v != null );
            p.Add( "v", "Increase debug message verbosity",
                v => {
                    if( v != null )
                    {
                        Utils.VerbosityLevel++;
                    }
                } );
            
            try
            {
                p.Parse( args );
            }
            catch( OptionException e )
            {
                Console.Write( appName + ": " );
                Console.WriteLine( e.Message );
                Console.WriteLine( "Try `" + appName + " --help' for more information." );
                return;
            }

            if( needShowHelp )
            {
                Usage( appName, p );
                return;
            }

            if( particlesCount <= 0 )
            {
                Console.Write( appName + ": " );
                Console.WriteLine( "Count of the particles must be positive" );
                Console.WriteLine( "Try `" + appName + " --help' for more information." );
                return;
            }

            var material = new Material( anisotropy, saturation, particleRadius );

            var cluster = new Sphere( clusterRadius );

            // Generate particles
            cluster.Particles = Utils.GenerateRandromParticlesInSphere( material, clusterRadius, particlesCount );

            var results = new Dictionary<double, double>();

            for( var i = minH; i <= maxH; i += stepH )
            {
                if( Math.Abs( i ) < double.Epsilon )
                {
                    //continue;
                }

                var externalMagneticField = new Vector( i, 0, 0 );

                var magneticMomentAverage = cluster.Calculate( externalMagneticField, dt, epsillon );

                results.Add( i, magneticMomentAverage.X );
            }

            Console.WriteLine( "Results:" );
            foreach( var pair in results )
            {
                Console.WriteLine( "ExternalMagneticField:\t" + pair.Key + "\tEffectiveMagneticField:\t" + pair.Value );
            }
        }