Esempio n. 1
0
        public void testTripleBandMapSolve()
        {
            int[]      dims = new int[] { 100, 400 };
            List <int> dim  = new List <int>(dims);

            FdmLinearOpLayout layout = new FdmLinearOpLayout(dim);

            List <Pair <double?, double?> > boundaries = new List <Pair <double?, double?> > ();

            boundaries.Add(new Pair <double?, double?>(0, 1.0));
            boundaries.Add(new Pair <double?, double?>(0, 1.0));

            FdmMesher mesher = new UniformGridMesher(layout, boundaries);

            FirstDerivativeOp dy = new FirstDerivativeOp(1, mesher);

            dy.axpyb(new Vector(1, 2.0), dy, dy, new Vector(1, 1.0));

            // check copy constructor
            FirstDerivativeOp copyOfDy = new FirstDerivativeOp(dy);

            Vector u = new Vector(layout.size());

            for (int i = 0; i < layout.size(); ++i)
            {
                u[i] = Math.Sin(0.1 * i) + Math.Cos(0.35 * i);
            }

            Vector t = new Vector(dy.solve_splitting(copyOfDy.apply(u), 1.0, 0.0));

            for (int i = 0; i < u.size(); ++i)
            {
                if (Math.Abs(u[i] - t[i]) > 1e-6)
                {
                    QAssert.Fail("solve and apply are not consistent "
                                 + "\n expected      : " + u[i]
                                 + "\n calculated    : " + t[i]);
                }
            }

            FirstDerivativeOp dx = new FirstDerivativeOp(0, mesher);

            dx.axpyb(new Vector(), dx, dx, new Vector(1, 1.0));

            FirstDerivativeOp copyOfDx = new FirstDerivativeOp(0, mesher);

            // check assignment
            copyOfDx = dx;

            t = dx.solve_splitting(copyOfDx.apply(u), 1.0, 0.0);
            for (int i = 0; i < u.size(); ++i)
            {
                if (Math.Abs(u[i] - t[i]) > 1e-6)
                {
                    QAssert.Fail("solve and apply are not consistent "
                                 + "\n expected      : " + u[i]
                                 + "\n calculated    : " + t[i]);
                }
            }

            SecondDerivativeOp dxx = new SecondDerivativeOp(0, mesher);

            dxx.axpyb(new Vector(1, 0.5), dxx, dx, new Vector(1, 1.0));

            // check of copy constructor
            SecondDerivativeOp copyOfDxx = new SecondDerivativeOp(dxx);

            t = dxx.solve_splitting(copyOfDxx.apply(u), 1.0, 0.0);

            for (int i = 0; i < u.size(); ++i)
            {
                if (Math.Abs(u[i] - t[i]) > 1e-6)
                {
                    QAssert.Fail("solve and apply are not consistent "
                                 + "\n expected      : " + u[i]
                                 + "\n calculated    : " + t[i]);
                }
            }

            //check assignment operator
            copyOfDxx.add(new SecondDerivativeOp(1, mesher));
            copyOfDxx = dxx;

            t = dxx.solve_splitting(copyOfDxx.apply(u), 1.0, 0.0);

            for (int i = 0; i < u.size(); ++i)
            {
                if (Math.Abs(u[i] - t[i]) > 1e-6)
                {
                    QAssert.Fail("solve and apply are not consistent "
                                 + "\n expected      : " + u[i]
                                 + "\n calculated    : " + t[i]);
                }
            }
        }