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(); }
/// <summary> /// Dot product of two vector: this and that. /// </summary> /// <param name="that">Result scalar</param> public double Dot( Vector that ) { return X * that.X + Y * that.Y + Z * that.Z; }
/// <summary> /// Cross product of two vector: [ this x that ]. /// </summary> /// <param name="that">Result vector.</param> public Vector Cross( Vector that ) { Vector res; res.X = Y * that.Z - Z * that.Y; res.Y = Z * that.X - X * that.Z; res.Z = X * that.Y - Y * that.X; return res; }
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 ); } }