protected override void CorrectLevelSet(int timestepNo, CellMask CellsToCorrect = null, bool ReIteration = false)
        {
            DGField Interface_old = Interface.CloneAs();

            ScalarFunctionEx FrontTracking_LevelSetDistanceCorrectionFull = delegate(int cell0, int Len, NodeSet Ns, MultidimensionalArray result)
            {
                Interface_old.Evaluate(cell0, Len, Ns, result);
                MultidimensionalArray GlobalNodes = this.Grid.GlobalNodes.GetValue_Cell(Ns, cell0, Len);

                int c = 0;
                for (int cell = cell0; cell < cell0 + Len; cell++, c++)
                {
                    if (NarrowBandCells.Contains(cell))
                    //if(true)
                    {
                        for (int i = 0; i < Ns.NoOfNodes; i++)
                        {
                            MultidimensionalArray GlobalNode = MultidimensionalArray.Create(1, SpatialDimension);
                            for (int dim = 0; dim < SpatialDimension; dim++)
                            {
                                GlobalNode [0, dim] = GlobalNodes [c, i, dim];
                            }

                            double Phi_abs = AllEdges[0].SignedDistanceToPoint(GlobalNode);

                            foreach (Edge Edge in AllEdges)
                            {
                                double dist = Edge.SignedDistanceToPoint(GlobalNode);
                                if (Math.Abs(Phi_abs) > Math.Abs(dist))
                                {
                                    Phi_abs = dist;
                                }
                            }
                            result[c, i] = Phi_abs;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < Ns.NoOfNodes; i++)
                        {
                            if (result[c, i] > 0.0)
                            {
                                result[c, i] = 1;
                            }
                            else
                            {
                                result[c, i] = -1;
                            }
                        }
                    }
                }
            };

            Interface.ProjectField(FrontTracking_LevelSetDistanceCorrectionFull);
        }
Example #2
0
        /// <summary>
        /// Correction of LevelSet with escaped particles.
        /// First all particle are assigned with a recalculated level set phi
        /// Then they are marked as escaped depending on their position in the level set DGField.
        /// Finally a spherical local level set function is constructed around every escaped particle.
        /// These functions are overlapped using the following rules:
        /// For the plus(minus) particles the maximum(minimum) of the function is used.
        /// Positiv and negative particles are overlapped by prioritizing the level set corrections that are nearer to the interface.
        /// Method has to be called after the advection step but before the radius adjustment
        /// </summary>
        protected override void CorrectLevelSet(int timestepNo, CellMask CellsToCorrect = null, bool ReIteration = false)
        {
            DGField Interface_old = Interface.CloneAs();

            ScalarFunctionEx Particle_LevelSetCorrection = delegate(int cell0, int Len, NodeSet Ns, MultidimensionalArray result)
            {
                Interface_old.Evaluate(cell0, Len, Ns, result);

                MultidimensionalArray GlobalNodes = this.Grid.GlobalNodes.GetValue_Cell(Ns, cell0, Len);

                int c = 0;
                for (int cell = cell0; cell < cell0 + Len; cell++, c++)
                {
                    if (NarrowBandCells.Contains(cell))
                    {
                        List <int> listindex = new List <int>();
                        if (CelltoArrayindex.ContainsKey(cell))
                        {
                            listindex.Add(cell);
                        }

                        Grid.GetCellNeighbours(cell, GetCellNeighbours_Mode.ViaVertices, out int[] NeighbourIndex, out int[] ConnectingEntities);
                        foreach (int j in NeighbourIndex)
                        {
                            if (CelltoArrayindex.ContainsKey(j))
                            {
                                listindex.Add(j);
                            }
                        }
                        if (listindex.IsNullOrEmpty())
                        {
                            continue;
                        }

                        for (int l = 0; l < listindex.Count; l++)
                        {
                            listindex[l] = CelltoArrayindex[listindex[l]];
                        }


                        for (int i = 0; i < Ns.NoOfNodes; i++)
                        {
                            Dictionary <int, double> Phi_correction = new Dictionary <int, double>
                            {
                                [-1] = result[c, i],
                                [1]  = result[c, i]
                            };
                            if (MinimalDistanceSearch == MinimalDistanceSearchMode.FullSearch)
                            {
                                foreach (int index in listindex)
                                {
                                    foreach (KeyValuePair <int, List <SingleLvlSetParticle> > DictEntry in Points[index].ItemList)
                                    {
                                        foreach (SingleLvlSetParticle SingleParticle in DictEntry.Value)
                                        {
                                            if (SingleParticle.Escaped == false || SingleParticle.Active == false)
                                            {
                                                continue;
                                            }
                                            double dist = 0;
                                            for (int dim = 0; dim < SpatialDimension; dim++)
                                            {
                                                dist += (GlobalNodes[c, i, dim] - SingleParticle.Coordinates[0, dim]).Pow2();
                                            }
                                            dist = Math.Sqrt(dist);
                                            double Phi_p = DictEntry.Key * (SingleParticle.Radius - dist);
                                            Phi_correction[DictEntry.Key] = (DictEntry.Key * Phi_correction[DictEntry.Key] > DictEntry.Key * Phi_p)
                                            ? Phi_correction[DictEntry.Key] : Phi_p;
                                        }
                                    }
                                }
                            }
                            if (Math.Abs(Phi_correction[1]) <= Math.Abs(Phi_correction[-1]))
                            {
                                result[c, i] = Phi_correction[1];
                            }
                            else
                            {
                                result[c, i] = Phi_correction[-1];
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < Ns.NoOfNodes; i++)
                        {
                            if (result[c, i] > 0.0)
                            {
                                result[c, i] = 1;
                            }
                            else
                            {
                                result[c, i] = -1;
                            }
                        }
                    }
                }
            };

            Interface.ProjectField(Particle_LevelSetCorrection);
        }