Example #1
0
        private void CalculateAnomalyField(AnomalyCurrent src, AnomalyCurrent dst, GreenTensor gt, bool electric)
        {
            var forward  = src.Nz == 1 ? Pool.Plan3 : Pool.Plan3Nz;
            var backward = dst.Nz == 1 ? Pool.Plan3 : Pool.Plan3Nz;


            UNF.ClearBuffer(forward.Buffer1Ptr, forward.BufferLength);
            PrepareForForwardFft(src, forward.Buffer1Ptr);
            Pool.ExecuteForward(forward);


            //Clear(backward.Input);
            if (electric)
            {
                ApplyGreenTensorAlongZForE(gt, forward.Buffer1Ptr, backward.Buffer2Ptr);
            }
            else
            {
                ApplyGreenTensorAlongZForH(gt, forward.Buffer1Ptr, backward.Buffer2Ptr);
            }

            Pool.ExecuteBackward(backward);

            var scalar = new Complex(1 / ((double)Model.Nx * (double)Model.Ny * 4), 0);
            var len    = backward.BufferLength;

            Zscal(len, scalar, backward.Buffer2Ptr);

            ExtractData(backward.Buffer2Ptr, dst);
        }
Example #2
0
        private void PopulateGreenAlongY(Complex *ptr, int ySym, long srcJ, long dstJ)
        {
            long shift     = _layoutShiftFactor * srcJ;
            long shiftYSym = _layoutShiftFactor * dstJ;

            UNM.Zaxpy(_length, ySym, ptr + shift, _layoutStep, ptr + shiftYSym, _layoutStep);
        }
Example #3
0
        private void PopulateGreenAlongX(Complex *ptr, int xSym, long srcI, long dstI)
        {
            long shift     = _layoutShiftFactor * (srcI * _ny2);
            long shiftXSym = _layoutShiftFactor * (dstI * _ny2);

            UNM.Zaxpy(_length, xSym, ptr + shift, _layoutStep, ptr + shiftXSym, _layoutStep);
        }
Example #4
0
        private void ApplyGreenTensorAlongZ()
        {
            var input  = Pool.Plan3Nz.Buffer1Ptr;
            var result = Pool.Plan3Nz.Buffer2Ptr;

            int  nz     = Model.Nz;
            long asymNz = nz * nz;
            long symmNz = nz + nz * (nz - 1) / 2;
            int  length = Pool.Plan3Nz.BufferLength / (3 * nz);

            var xx = _greenTensor["xx"].Ptr;
            var xy = _greenTensor["xy"].Ptr;
            var xz = _greenTensor["xz"].Ptr;


            var yy = _greenTensor["yy"].Ptr;
            var yz = _greenTensor["yz"].Ptr;

            var zz = _greenTensor["zz"].Ptr;

            Iterate(length, i =>
            {
                //for (int i = 0; i < length; i++)
                //  {
                long dataShift = i * 3L * nz;
                long symmShift = i * symmNz;
                long asymShift = i * asymNz;

                var dstX = result + dataShift;
                var dstY = result + dataShift + nz;
                var dstZ = result + dataShift + nz + nz;

                var srcX = input + dataShift;
                var srcY = input + dataShift + nz;
                var srcZ = input + dataShift + nz + nz;

                var one      = Complex.One;
                var minusOne = -Complex.One;
                var zero     = Complex.Zero;

                UNM.ZgemvSym(nz, &one, &zero, xx + symmShift, srcX, dstX);
                UNM.ZgemvSym(nz, &one, &one, xy + symmShift, srcY, dstX);
                UNM.ZgemvAsymNoTrans(nz, &one, &one, xz + asymShift, srcZ, dstX);

                UNM.ZgemvSym(nz, &one, &zero, xy + symmShift, srcX, dstY);
                UNM.ZgemvSym(nz, &one, &one, yy + symmShift, srcY, dstY);
                UNM.ZgemvAsymNoTrans(nz, &one, &one, yz + asymShift, srcZ, dstY);

                UNM.ZgemvAsymTrans(nz, &minusOne, &zero, xz + asymShift, srcX, dstZ);
                UNM.ZgemvAsymTrans(nz, &minusOne, &one, yz + asymShift, srcY, dstZ);
                UNM.ZgemvSym(nz, &one, &one, zz + symmShift, srcZ, dstZ);
                //     }
            });
        }
Example #5
0
        private void PopulateGreen(Complex *ptr, int xSym, int ySym, int i, int j)
        {
            long shift = _layoutShiftFactor * (i * _ny2 + j);

            long shiftXSym  = _layoutShiftFactor * ((_nx2 - i) * _ny2 + j);
            long shiftYSym  = _layoutShiftFactor * (i * _ny2 + _ny2 - j);
            long shiftXYSym = _layoutShiftFactor * ((_nx2 - i) * _ny2 + _ny2 - j);

            var src = ptr + shift;

            UNM.Zaxpy(_length, xSym, src, _layoutStep, ptr + shiftXSym, _layoutStep);
            UNM.Zaxpy(_length, ySym, src, _layoutStep, ptr + shiftYSym, _layoutStep);
            UNM.Zaxpy(_length, xSym * ySym, src, _layoutStep, ptr + shiftXYSym, _layoutStep);
        }
Example #6
0
        private void PerformLastStep()
        {
            var length = 3L * _output.Nz * _output.Nx * _output.Ny;

            if (_operatorType == OperatorType.A)
            {
                UNM.SubtractElementwise(length, _input.Ptr, _output.Ptr, _output.Ptr);
                UNM.SubtractElementwise(length, _output.Ptr, _rx.Ptr, _output.Ptr);
            }

            if (_operatorType == OperatorType.Chi0)
            {
                UNM.AddElementwise(length, _output.Ptr, _rx.Ptr, _output.Ptr);
            }
        }
Example #7
0
        private void ApplyOperatorR()
        {
            int length = _rx.Nx * _rx.Ny;
            int nz     = _rx.Nz;

            Iterate(length, i => //for (int i = 0; i < length; i++)
            {
                long inz  = i * nz;
                long inz3 = i * nz * 3;

                UNM.MultiplyElementwise(nz, _rFunction + inz, _input.Ptr + inz3, _rx.Ptr + inz3);
                UNM.MultiplyElementwise(nz, _rFunction + inz, _input.Ptr + inz3 + nz, _rx.Ptr + inz3 + nz);
                UNM.MultiplyElementwise(nz, _rFunction + inz, _input.Ptr + inz3 + nz + nz, _rx.Ptr + inz3 + nz + nz);
                //}
            });
        }
Example #8
0
        private void ExtractData()
        {
            int nx = _output.Nx;
            int ny = _output.Ny;
            int nz = Model.Nz;

            var output = Pool.Plan3Nz.Buffer2Ptr;

            Iterate(nx, i => //for (int i = 0; i < nx; i++)
            {
                for (int j = 0; j < ny; j++)
                {
                    long shiftDst = (i * ny + j) * 3L * nz;
                    long shiftSrc = (i * ny * 2 + j) * 3L * nz;

                    UNM.MultiplyElementwise(nz, _backwardFactors, output + shiftSrc, _output.Ptr + shiftDst);
                    UNM.MultiplyElementwise(nz, _backwardFactors, output + shiftSrc + nz,
                                            _output.Ptr + shiftDst + nz);
                    UNM.MultiplyElementwise(nz, _backwardFactors, output + shiftSrc + nz + nz,
                                            _output.Ptr + shiftDst + nz + nz);
                }
            });
        }
Example #9
0
        public static GreenTensor AllocateNew(INativeMemoryProvider memoryProvider,
                                              int nx, int ny, int nTr, int nRc, long compSize, params string[] components)
        {
            var gt       = new GreenTensor(memoryProvider, nx, ny, nTr, nRc);
            var fullSize = compSize * components.Length;

            var ptr = memoryProvider.AllocateComplex(fullSize);

            UNM.ClearBuffer(ptr, fullSize);


            var dict = new Dictionary <string, Component>();

            for (int i = 0; i < components.Length; i++)
            {
                var nextPtr = ptr + i * compSize;
                dict.Add(components[i], new Component(gt, nextPtr));
            }

            gt._basePtrs.Add(new IntPtr(ptr));
            gt._components = dict;

            return(gt);
        }
Example #10
0
        private void PrepareForForwardFft()
        {
            var inputPtr = Pool.Plan3Nz.Buffer1Ptr;

            UNM.ClearBuffer(inputPtr, Pool.Plan3Nz.BufferLength);

            int nx = _rx.Nx;
            int ny = _rx.Ny;
            int nz = Model.Nz;

            Iterate(nx, i => //for (int i = 0; i < nx; i++)
            {
                for (int j = 0; j < ny; j++)
                {
                    long shiftSrc = (i * ny + j) * 3L * nz;
                    long shiftDst = (i * ny * 2 + j) * 3L * nz;

                    UNM.MultiplyElementwise(nz, _forwardFactors, _rx.Ptr + shiftSrc, inputPtr + shiftDst);
                    UNM.MultiplyElementwise(nz, _forwardFactors, _rx.Ptr + shiftSrc + nz, inputPtr + shiftDst + nz);
                    UNM.MultiplyElementwise(nz, _forwardFactors, _rx.Ptr + shiftSrc + nz + nz,
                                            inputPtr + shiftDst + nz + nz);
                }
            });
        }
Example #11
0
 private void Zscal(long length, Complex alpha, Complex *ptr)
 => UNF.Zscal(length, alpha, ptr);
Example #12
0
 protected static void Copy(long length, Complex *ptr, Complex *complexPtr)
 => UNF.Zcopy(length, ptr, complexPtr);
Example #13
0
 private static void Zaxpy(long n, Complex alpha, Complex *x, Complex *y)
 => UNF.Zaxpy(n, alpha, x, y);
Example #14
0
 private static void Zgemv(int n, int m, Complex a, Complex b, Complex *gt, Complex *src, Complex *dst)
 {
     UNF.ZgemvAtoO(n, m, &a, &b, gt, src, dst);
 }
Example #15
0
 private void FillQ(Complex *src, Complex[] dst, Complex alpha)
 {
     fixed(Complex *dstPtr = &dst[0])
     UNM.Zaxpy(dst.Length, alpha, src, dstPtr);
 }
Example #16
0
 private void FillGreen(Complex[] buff, GreenTensor.Component ca, int sign, long shift, int step)
 {
     fixed(Complex *q = &buff[0])
     UNM.Zaxpy(buff.Length, sign, q, ca.Ptr + shift, step);
 }