Example #1
0
        /// <summary>
        /// The first order approximation as seen here (infinitesimal current loop):
        /// https://en.wikipedia.org/wiki/Magnetic_dipole#External_magnetic_field_produced_by_a_magnetic_dipole_moment
        /// The magConstant is also known as the permeability.
        /// Griffiths 5.87
        /// </summary>
        public static IVectorField MagneticDipole(Vector3 magMoment, double magConstant)
        {
            Vector3 constantVectOne = (-magConstant / (4 * Math.PI)) * magMoment;
            IVectorField termOne = FieldExtensions.SphericalScalarField(1.0, -3).Multiply(constantVectOne);

            double constantTwo = (magConstant / (4 * Math.PI)) * 3;
            Func<Vector3, Vector3> termTwoFunc = r => Math.Pow(r.Magnitude, -5) * (magMoment * r) * r;
            IVectorField termTwo = new CustomVectorField(termTwoFunc);

            return termOne.Add(termTwo);
        }
Example #2
0
        /// <summary>
        /// The first order approximation as seen here (infinitesimal seperation):
        /// https://en.wikipedia.org/wiki/Electric_dipole_moment#Potential_and_field_of_an_electric_dipole
        /// The elecConstant is the permitivity
        /// See griffiths 3.104
        /// </summary>
        public static IVectorField ElectricDipole(Vector3 elecMoment, double elecConstant)
        {
            if (elecConstant <= 0) throw new ArgumentException(nameof(elecConstant) + " must be positive");
            Vector3 constantVectOne = (-1 / (4 * Math.PI * elecConstant)) * elecMoment;
            IVectorField termOne = FieldExtensions.SphericalScalarField(1.0, -3).Multiply(constantVectOne);

            double constantTwo = (3 / (4 * Math.PI * elecConstant));
            Func<Vector3, Vector3> termTwoFunc = r => Math.Pow(r.Magnitude, -3) * (elecMoment * r.UnitDirection) * r.UnitDirection;
            IVectorField termTwo = new CustomVectorField(termTwoFunc);

            return termOne.Add(termTwo);
        }