Exemplo n.º 1
0
        public void test(Solver1D solver, string name)
        {
            double[] accuracy = new double[] { 1.0e-4, 1.0e-6, 1.0e-8 };
            double   expected = 1.0;

            for (int i = 0; i < accuracy.Length; i++)
            {
                double root = solver.solve(new Foo(), accuracy[i], 1.5, 0.1);
                if (Math.Abs(root - expected) > accuracy[i])
                {
                    Assert.Fail(name + " solver:\n"
                                + "    expected:   " + expected + "\n"
                                + "    calculated: " + root + "\n"
                                + "    accuracy:   " + accuracy[i]);
                }
                root = solver.solve(new Foo(), accuracy[i], 1.5, 0.0, 1.0);
                if (Math.Abs(root - expected) > accuracy[i])
                {
                    Assert.Fail(name + " solver (bracketed):\n"
                                + "    expected:   " + expected + "\n"
                                + "    calculated: " + root + "\n"
                                + "    accuracy:   " + accuracy[i]);
                }
            }
        }
Exemplo n.º 2
0
        public static void Run()
        {
            var solver = new Solver1D(200, 1)
            {
                Sources =
                {
                    new FunctionSource1D(50)
                    {
                        Ez = t => 2 * Exp(-Sqr(t - 30) / 100)
                    },
                },
                Boundaries =
                {
                    MinEz = new ABC1DMin(),
                    MaxHy = new ABC1DMax()
                }
            };

            using var file = File.CreateText("solver1d.txt");
            foreach (var frame in solver.Calculation(250, 1))
            {
                frame.WriteEzTo(file);
            }
        }
Exemplo n.º 3
0
 private async Task ProcessFieldsAsync()
 {
     var solver = new Solver1D(
         SpaceCharacteristic.Create(f_SpaceSize),
         new Solver1D.Boundary(
             Xmin: BoundaryType.PMC,
             Xmax: BoundaryType.PMC),
         f_SpaceStep,
         new[]
     {
         new FieldSource(
             position: 50,
             type: FieldSource.FieldTypes.E,
             orientation: FieldSource.SourceOrientation.Z,
             f: t => Math.Exp(-(t - 30) * (t - 30) / 100))
     });
     await Task.Run(() =>
     {
         while (solver.Time < f_Tmax)
         {
             solver.TimeStep(f_dt);
         }
     }).ConfigureAwait(false);
 }