private GreenTensor AllocateNewAsym(params string[] asym)
        {
            int compSize = (_nxTotalLength * 2 * Ny * Nz * Nz);
            var gt       = GreenTensor.AllocateNew(MemoryProvider, _nxTotalLength, 2 * Ny, Nz, Nz, compSize, asym);

            return(gt);
        }
        private GreenTensor AllocateNewSymm(params string[] symm)
        {
            var ny2      = 2 * Ny;
            int compSize = (_nxTotalLength * ny2 * (Nz + Nz * (Nz - 1) / 2));

            return(GreenTensor.AllocateNew(MemoryProvider, _nxTotalLength, ny2, Nz, Nz, compSize, symm));
        }
        public GreenTensor CalculateSymmAtoA(ScalarSegments segments, MemoryLayoutOrder layoutOrder, bool mirrorPart)
        {
            if (segments == null)
            {
                throw new ArgumentNullException(nameof(segments));
            }
            _mirrorPart = mirrorPart;
            SetSegments(segments);
            _symmGreenTensor = AllocateNewSymm("xx", "yy", "zz", "xy");
            SetGreenTensorAndRadii(_symmGreenTensor, segments.Radii);

            if (_calcLength != 0)
            {
                if (!KnotsAreReady)
                {
                    PrepareKnotsAtoA(segments.Radii, _nxStart, _calcLength);
                }

                PrepareValuesForSymmAtoA(layoutOrder);


                RunAlongXElectric(_nxStart, _calcLength);
                RunAlongYElectric(_nxStart, _calcLength);
            }

            return(_symmGreenTensor);
        }
Example #4
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 #5
0
 protected void SetNewGreenTensor(GreenTensor gt)
 {
     if (gt == null)
     {
         throw new ArgumentNullException(nameof(gt));
     }
     _greenTensorAtoA = gt;
 }
        GreenTensor CalculateExtremeGreenTensorAtoA()
        {
            _tensorCalc.SetNxSizes(_realCalcNxStart, _totalNxLength, _calcNxLength);
            var asym   = CalculateAsymGreenTensorAtoA();
            var symm   = CalculateSymmGreenTensorAtoA();
            var tensor = GreenTensor.Merge(asym, symm);

            return(tensor);
        }
        private void PerformFftGiem2g(GreenTensor gt, MemoryLayoutOrder layoutOrder)
        {
            if (layoutOrder != MemoryLayoutOrder.AlongVertical)
            {
                throw new InvalidOperationException($"{nameof(layoutOrder)} should be AlongVertical to perform fft");
            }

            Giem2gGreenTensor.CalcFFTofGreenTensor(gt);
        }
 public CieSolverFinishedEventArgs(AnomalyCurrent chi, GreenTensor gt)
 {
     if (chi == null)
     {
         throw new ArgumentNullException(nameof(chi));
     }
     Chi = chi;
     Gt  = gt;
 }
        private void AddMinusToXz(GreenTensor tensor)
        {
            var ptr    = tensor["xz"].Ptr;
            int length = tensor.Ny * tensor.Nx * Model.Nz * Model.Nz;

            for (long i = 0; i < length; i++)
            {
                ptr[i] = -ptr[i];
            }
        }
        private void AddMinusToXy(GreenTensor tensor)
        {
            var ptr    = tensor["xy"].Ptr;
            var nz     = Model.Nz;
            int length = tensor.Ny * tensor.Nx * (nz + nz * (nz - 1) / 2);

            for (long i = 0; i < length; i++)
            {
                ptr[i] = -ptr[i];
            }
        }
Example #11
0
 private unsafe void PerformGreenTensorFft(GreenTensor gt)
 {
     foreach (var component in gt.GetAvailableComponents())
     {
         var  ptr    = gt[component].Ptr;
         long length = gt.Nx * gt.Ny * gt.NTr * gt.NRc;
         Copy(length, ptr, Pool.Plan1Nz.Buffer1Ptr);
         Pool.ExecuteForward(Pool.Plan1Nz);
         Copy(length, Pool.Plan1Nz.Buffer1Ptr, ptr);
     }
 }
        private void PerformFftAsym(GreenTensor gt, MemoryLayoutOrder layoutOrder)
        {
            if (layoutOrder != MemoryLayoutOrder.AlongVertical)
            {
                throw new InvalidOperationException($"{nameof(layoutOrder)} should be AlongVertical to perform fft");
            }

            var nz       = Model.Nz;
            int sizeAsym = nz * nz;

            MakeFftForComponent(gt, "xz", sizeAsym);
            MakeFftForComponent(gt, "yz", sizeAsym);
        }
 private void PopulateForFft(GreenTensor gt, MemoryLayoutOrder layoutOrder, int nxLength, bool symm = false)
 {
     if (Solver.IsParallel)
     {
         new GreenTensorFftPopulator(gt, Model, symm)
         .PopulateForFftDistributedAlongX(layoutOrder, nxLength);
     }
     else
     {
         new GreenTensorFftPopulator(gt, Model, symm)
         .PopulateForFft(layoutOrder);
     }
 }
Example #14
0
        public GreenTensorFftPopulator(GreenTensor greenTensor, OmegaModel model, bool symm = false)
        {
            _greenTensor = greenTensor;

            _nx  = model.LateralDimensions.Nx;
            _ny  = model.LateralDimensions.Ny;
            _nx2 = _nx * 2;
            _ny2 = _ny * 2;

            var nz = model.Anomaly.Layers.Count;

            _length = symm ? nz + nz * (nz - 1) / 2 : nz * nz;
        }
Example #15
0
        protected void SetGreenTensorAndRadii(GreenTensor greenTensor, double[] radii)
        {
            if (greenTensor == null)
            {
                throw new ArgumentNullException(nameof(greenTensor));
            }
            if (radii == null)
            {
                throw new ArgumentNullException(nameof(radii));
            }

            _greenTensor = greenTensor;
            _radii       = radii;
        }
        private void PerformFftSymm(GreenTensor gt, MemoryLayoutOrder layoutOrder)
        {
            if (layoutOrder != MemoryLayoutOrder.AlongVertical)
            {
                throw new InvalidOperationException($"{nameof(layoutOrder)} should be AlongVertical to perform fft");
            }

            var nz       = Model.Nz;
            int sizeSymm = (nz * (nz + 1)) / 2;

            MakeFftForComponent(gt, "xx", sizeSymm);
            MakeFftForComponent(gt, "xy", sizeSymm);
            MakeFftForComponent(gt, "yy", sizeSymm);
            MakeFftForComponent(gt, "zz", sizeSymm);
        }
        private void MakeFftForComponent(GreenTensor gt, string comp, int size)
        {
            var ptr = gt[comp].Ptr;
            var nz3 = 3 * Model.Nz;

            int layerSize = gt.Nx * gt.Ny;

            for (int i = 0; i < size; i += nz3)
            {
                int length = i + nz3 <= size ? nz3 : size - i;

                CopyToBuffer(i, length, layerSize, size, ptr);
                Pool.ExecuteForward(Pool.Plan3Nz);
                CopyFromBuffer(i, length, layerSize, size, ptr);
            }
        }
 public GreenTensor CalculateGreenTensor(GreenTensor gt)
 {
     using (Profiler?.StartAuto(ProfilerEvent.GreenAtoATotal))
     {
         GreenTensor tensor;
         if (Solver.Engine != ForwardSolverEngine.Giem2g)
         {
             tensor = CalculateExtremeGreenTensorAtoA();
         }
         else
         {
             tensor = CalculateGiem2gGreenTensorAtoA(gt);
         }
         return(tensor);
     }
 }
Example #19
0
        public static void PrintLateral(GreenTensor gt, string comp, int ntr)
        {
            var gtc = gt[comp];

            for (int i = 0; i < gt.Nx; i++)
            {
                Console.Write($"[{i:000}] : ");
                for (int j = 0; j < gt.Ny; j++)
                {
                    var val = gtc.GetAlongLateralAsym(i, j, ntr, 0);

                    Console.Write($"{ val.Real:E4} ");
                }

                Console.WriteLine();
            }
        }
Example #20
0
        //	public static ForwardSolver current_solver;

        public static GreenTensor CalcAtoATensor(ForwardSolver solver, GreenTensor gt)
        {
            var giem2g_ie_op = new giem2g_data();
            var bkg          = new giem2g_background();
            var anomaly      = new giem2g_anomaly();

            GreenTensor gt_new;

            //	current_solver = solver;


            PrepareBkgAndAnomaly(solver, ref bkg, ref anomaly);



            //giem2g_set_logger(GIEM2G_LOGGER);

            IntPtr ie_op_ptr;

            if (gt == null || !gt.Has("giem2g"))
            {
                gt_new    = PrepareGIEM2GTensor(solver, ref giem2g_ie_op, anomaly);
                ie_op_ptr = giem2g_ie_op.giem2g_tensor;
            }
            else
            {
                ie_op_ptr = new IntPtr(gt ["giem2g"].Ptr);
                gt_new    = gt;
            }



            var omega = solver.Model.Omega;

            giem2g_calc_ie_kernel(ie_op_ptr, bkg, anomaly, omega);

            solver.MemoryProvider.Release((void *)bkg.csigb);
            solver.MemoryProvider.Release((void *)bkg.thickness);
            solver.MemoryProvider.Release((void *)anomaly.z);
            solver.MemoryProvider.Release((void *)anomaly.dz);



            return(gt_new);
        }
Example #21
0
        public unsafe static void PrintAsym(GreenTensor gt, string comp, int rc, int tr)
        {
            var gtc = gt[comp];

            int length = gt.NTr * gt.NRc;

            for (int i = 0; i < gt.Nx; i++)
            {
                Console.Write($"[{i:000}] : ");
                for (int j = 0; j < gt.Ny; j++)
                {
                    var val = gtc.Ptr[(i * gt.Ny + j) * length + rc * gt.NTr + tr];//  .GetAlongVerticalAsym(i, j, 1, 0);

                    Console.Write($"{ val.Real:E4} ");
                }

                Console.WriteLine();
            }
        }
        private GreenTensor CalculateGiem2gGreenTensorAtoA(GreenTensor gt)
        {
            using (Profiler?.StartAuto(ProfilerEvent.GreenTensorAtoA))
            {
                GreenTensor tensor;

                using (Profiler?.StartAuto(ProfilerEvent.GreenTensorAtoACalc))
                {
                    MemoryUtils.PrintMemoryReport("Before GIEM2G tensor", Logger, MemoryProvider);
                    tensor = Giem2gGreenTensor.CalcAtoATensor(Solver, gt);
                    MemoryUtils.PrintMemoryReport("after GIEM2G tensor", Logger, MemoryProvider);
                }

                using (Profiler?.StartAuto(ProfilerEvent.GreenTensorAtoAFft))
                {
                    PerformFftGiem2g(tensor, MemoryLayoutOrder.AlongVertical);
                }

                return(tensor);
            }
        }
Example #23
0
        public void PrepareOperator(GreenTensor greenTensor, OperatorType operatorType)
        {
            if (greenTensor == null)
            {
                throw new ArgumentNullException(nameof(greenTensor));
            }
            _greenTensor  = greenTensor;
            _operatorType = operatorType;
            if (_solver.Engine != ForwardSolverEngine.Giem2g)
            {
                var zeta0 = GetBackgroundZeta(Model.Anomaly, Model.Section1D);

                PrepareRFunction(zeta0);
                PrepareBackwardFactors(zeta0);
                PrepareForwardFactors(zeta0);
            }
            else
            {
                PrepareGiem2gOperator();
            }
        }
Example #24
0
        private void SolvePrivate(OmegaModel model, GreenTensor aToA, TensorCache tensors = null)
        {
            Logger.WriteStatus("Starting Cartesian MT Forward solver...");

            using (Profiler?.StartAuto(ProfilerEvent.ForwardSolving))
            {
                SetModel(model, tensors);

                if (aToA == null)
                {
                    CalculateGreenTensor();
                }
                else
                {
                    SetNewGreenTensor(aToA);
                }

                SolverPolarizationX();
                SolverPolarizationY();
            }
        }
Example #25
0
        private static void ApplyGreenTensorAlongZForE(GreenTensor gt, Complex *input, Complex *result)
        {
            int gtNz   = gt.NTr * gt.NRc;
            int srcNz  = gt.NTr;
            int dstNz  = gt.NRc;
            int length = gt.Nx * gt.Ny;

            //int srcNz = input.Nz;
            //int dstNz = result.Nz;
            //int length = input.Nx * input.Ny;

            //for (int i = 0; i < length; i++)
            Iterate(length, i =>
            {
                int dstShift = i * 3 * dstNz;
                int srcShift = i * 3 * srcNz;
                int gtShift  = i * gtNz;

                var dstX = result + dstShift;
                var dstY = result + dstShift + dstNz;
                var dstZ = result + dstShift + dstNz + dstNz;

                var srcX = input + srcShift;
                var srcY = input + srcShift + srcNz;
                var srcZ = input + srcShift + srcNz + srcNz;

                Zgemv(srcNz, dstNz, Complex.One, Complex.Zero, gt["xx"][gtShift], srcX, dstX);
                Zgemv(srcNz, dstNz, Complex.One, Complex.One, gt["xy"][gtShift], srcY, dstX);
                Zgemv(srcNz, dstNz, Complex.One, Complex.One, gt["xz"][gtShift], srcZ, dstX);

                Zgemv(srcNz, dstNz, Complex.One, Complex.Zero, gt["xy"][gtShift], srcX, dstY);
                Zgemv(srcNz, dstNz, Complex.One, Complex.One, gt["yy"][gtShift], srcY, dstY);
                Zgemv(srcNz, dstNz, Complex.One, Complex.One, gt["yz"][gtShift], srcZ, dstY);

                Zgemv(srcNz, dstNz, Complex.One, Complex.Zero, gt["zx"][gtShift], srcX, dstZ);
                Zgemv(srcNz, dstNz, Complex.One, Complex.One, gt["zy"][gtShift], srcY, dstZ);
                Zgemv(srcNz, dstNz, Complex.One, Complex.One, gt["zz"][gtShift], srcZ, dstZ);
                //}
            });
        }
Example #26
0
        protected void SetModel(OmegaModel model, TensorCache tensors = null)
        {
            if (IsParallel)
            {
                Mpi.CheckNumberOfProcesses(model.LateralDimensions);
            }

            Model = model;

            if (_aToOCalculator == null)
            {
                _aToOCalculator = new AtoOCalculator(this);
            }

            if (_fgmresSolver == null)
            {
                _fgmresSolver = new AnomalyCurrentFgmresSolver(this);
            }

            if (_convolutionOperator == null)
            {
                _convolutionOperator = new ConvolutionOperator(this);
            }

            if (tensors == null)
            {
                _aToOCalculator.CleanGreenTensors();
                if (!StoreAtoA)
                {
                    _greenTensorAtoA?.Dispose();
                    _greenTensorAtoA = null;
                }
            }
            else
            {
                _aToOCalculator.SetTensors(tensors.eGreenTensors, tensors.hGreenTensors);
                SetNewGreenTensor(tensors.gtAtoA);
            }
        }
Example #27
0
        static GreenTensor PrepareGIEM2GTensor(ForwardSolver solver, ref giem2g_data giem2g_ie_op, giem2g_anomaly anomaly)
        {
            int nz = solver.Model.Nz;
            int nx = solver.Model.Nx;
            int ny = solver.Model.Ny;

            giem2g_ie_op.comm = solver.Mpi.CommunicatorC2Fortran();
            giem2g_calc_data_sizes(anomaly, ref giem2g_ie_op);



            var buff = FftBuffersPool.GetBuffer(solver.Model);

            if (buff.Plan3Nz.BufferLength >= giem2g_ie_op.fft_buffers_length)
            {
                giem2g_ie_op.fft_buffer_in  = buff.Plan3Nz.Buffer1Ptr;
                giem2g_ie_op.fft_buffer_out = buff.Plan3Nz.Buffer2Ptr;
            }
            else
            {
                var len = giem2g_ie_op.fft_buffers_length;
                giem2g_ie_op.fft_buffer_in  = solver.MemoryProvider.AllocateComplex(len);
                giem2g_ie_op.fft_buffer_out = solver.MemoryProvider.AllocateComplex(len);
                solver.Logger.WriteError("Allocate additional memory for FFT inside GIEM2G!!");
            }
            var giem2g_ptrs = AllocateGiem2gDataBuffers(solver.MemoryProvider, ref giem2g_ie_op, nz);


            giem2g_prepare_ie_kernel(anomaly, giem2g_ie_op);



            var gt = GreenTensor.CreateGiem2gTensor(solver.MemoryProvider, nx, ny, nz, nz, giem2g_ptrs);

            return(gt);
        }
Example #28
0
 protected void CalculateAnomalyFieldH(AnomalyCurrent src, AnomalyCurrent dst, GreenTensor greenTensor)
 => CalculateAnomalyField(src, dst, greenTensor, electric: false);
Example #29
0
 private ComplexVector CalculateH(GreenTensor gt, AnomalyCurrent jQ)
 {
     throw new NotImplementedException();
 }
Example #30
0
 private ComplexVector ConvolutorE(GreenTensor gt, AnomalyCurrent jQ)
 {
     throw new NotImplementedException();
 }