Example #1
0
 public DateTimeField(long id, string name, Partitioning partitioning, DateTimeFieldProperties properties)
     : base(id, name, partitioning, properties)
 {
 }
Example #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="__ProblemMapping">
        /// Mapping of original problem, equal to <see cref="ProblemMapping"/>.
        /// </param>
        /// <param name="__aggGrdB">
        /// Sequence of aggregation grid DG basis objects, correlates to original mapping
        /// </param>
        /// <param name="DgDegrees"></param>
        public MultigridMapping(UnsetteledCoordinateMapping __ProblemMapping, AggregationGridBasis[] __aggGrdB, int[] DgDegrees)
        {
            using (new FuncTrace()) {
                // check args
                // ===========


                if (__aggGrdB.Length != __ProblemMapping.BasisS.Count)
                {
                    throw new ArgumentException("Mismatch between number of multigrid basis objects and number of variables in problem mapping.");
                }

                var mgGrid = __aggGrdB[0].AggGrid;
                for (int iVar = 0; iVar < __aggGrdB.Length; iVar++)
                {
                    if (__ProblemMapping.BasisS[iVar] is BoSSS.Foundation.XDG.XDGBasis)
                    {
                        if (!(__aggGrdB[iVar] is XdgAggregationBasis))
                        {
                            throw new ArgumentException();
                        }
                    }
                    else if (__ProblemMapping.BasisS[iVar] is BoSSS.Foundation.Basis)
                    {
                        //if((__aggGrdB[iVar] is XdgAggregationBasis))
                        //    throw new ArgumentException();
                    }

                    if (!object.ReferenceEquals(mgGrid, __aggGrdB[iVar].AggGrid))
                    {
                        throw new ArgumentException("Basis object must all be defined on the same grid.");
                    }
                }

                // find basis with maximum degree
                // ==============================
                this.ProblemMapping = __ProblemMapping;
                //this.MaxBasis = ProblemMapping.BasisS.ElementAtMax(basis => basis.Degree);
                this.m_DgDegree = DgDegrees.CloneAs();
                //if(!this.MaxBasis.IsSubBasis(__aggGrdB.DGBasis)) {
                //    throw new ArgumentException("Basis on aggregation grid is insufficient;");
                //}

                if (m_DgDegree.Length != __ProblemMapping.BasisS.Count())
                {
                    throw new ArgumentException("Wrong number of DG degrees.");
                }
                for (int i = 0; i < m_DgDegree.Length; i++)
                {
                    if (m_DgDegree[i] < 0)
                    {
                        throw new ArgumentException("DG degree must be greater of equal to 0.");
                    }
                    if (m_DgDegree[i] > __ProblemMapping.BasisS[i].Degree)
                    {
                        throw new ArgumentException("DG degree on sub-level can not exceed DG degree of the original problem.");
                    }
                }

                // create basis for this level
                // ===========================
                this.AggBasis = __aggGrdB;

                // min/max length
                // ==============
                {
                    int Smin     = 0;
                    int Smax     = 0;
                    int Nofields = this.m_DgDegree.Length;
                    for (int ifld = 0; ifld < Nofields; ifld++)
                    {
                        Smin += this.AggBasis[ifld].GetMinimalLength(this.m_DgDegree[ifld]);
                        Smax += this.AggBasis[ifld].GetMaximalLength(this.m_DgDegree[ifld]);
                    }
                    this.MinimalLength = Smin;
                    this.MaximalLength = Smax;
                }

                // offsets
                // =======
                if (this.MinimalLength != this.MaximalLength)
                {
                    int   JAGGloc = this.AggGrid.iLogicalCells.NoOfLocalUpdatedCells;
                    int   JAGGtot = this.AggGrid.iLogicalCells.Count;
                    int[] __i0Tmp = new int[JAGGtot];

                    HashSet <int> BlockLen = new HashSet <int>();

                    int LL = 0;
                    for (int jag = 0; jag < JAGGloc; jag++)
                    {
                        int S = 0;
                        for (int i = 0; i < m_DgDegree.Length; i++)
                        {
                            S += this.AggBasis[i].GetLength(jag, m_DgDegree[i]);
                        }

                        if (jag < JAGGloc - 1)
                        {
                            __i0Tmp[jag + 1] = __i0Tmp[jag] + S;
                        }
                        else
                        {
                            LL = __i0Tmp[jag] + S;
                        }

                        BlockLen.Add(S);
                    }
                    Partitioning = new Partitioning(LL);
                    int i0Part = Partitioning.i0;
                    m_i0 = new int[JAGGtot + 1];
                    for (int jag = 0; jag < JAGGloc; jag++)
                    {
                        m_i0[jag]     = __i0Tmp[jag]; // store local i0 index
                        __i0Tmp[jag] += i0Part;       // convert to global index
                    }
                    m_i0[JAGGloc] = LL;
                    __i0Tmp.MPIExchange(this.AggGrid);

                    // compute global cell i0's in the external range
                    m_i0_ExtGlob = new int[JAGGtot - JAGGloc];
                    Array.Copy(__i0Tmp, JAGGloc, m_i0_ExtGlob, 0, JAGGtot - JAGGloc);

                    // compute local cell i0's in the external range (very confusing)
                    for (int jag = JAGGloc; jag < JAGGtot; jag++)
                    {
                        int S = 0;
                        for (int i = 0; i < m_DgDegree.Length; i++)
                        {
                            S += this.AggBasis[i].GetLength(jag, m_DgDegree[i]);
                        }
                        m_i0[jag + 1] = this.m_i0[jag] + S;

                        BlockLen.Add(S);
                    }

                    // build look-up for block types
                    m_Len2SublockType = new Dictionary <int, int>();
                    m_Subblk_i0       = new int[BlockLen.Count][];
                    m_SubblkLen       = new int[BlockLen.Count][];
                    int type = 0;
                    foreach (int S in BlockLen)
                    {
                        m_Subblk_i0[type] = new int[] { 0 };
                        m_SubblkLen[type] = new int[] { S };
                        m_Len2SublockType.Add(S, type);
                        type++;
                    }

#if DEBUG
                    for (int jag = JAGGloc; jag < JAGGtot; jag++)
                    {
                        Debug.Assert(Partitioning.IsInLocalRange(m_i0_ExtGlob[jag - JAGGloc]) == false);
                    }
#endif
                }
                else
                {
                    m_Subblk_i0 = new int[][] { new int[] { 0 } };
                    m_SubblkLen = new int[][] { new int[] { this.MaximalLength } };

                    Partitioning = new Partitioning(this.AggGrid.iLogicalCells.NoOfLocalUpdatedCells * this.MaximalLength);
                }


                Debug.Assert(Partitioning != null);
                Debug.Assert(Partitioning.LocalLength == this.LocalLength);
            }
        }
 public override RootField CreateRootField(long id, string name, Partitioning partitioning, IFieldSettings?settings = null)
 {
     return(Fields.Array(id, name, partitioning, this, settings));
 }
Example #4
0
 public RootField(long id, string name, Partitioning partitioning, T?properties = null, IFieldSettings?settings = null)
     : base(id, name, partitioning, settings)
 {
     SetProperties(properties ?? new T());
 }
Example #5
0
 /// <summary>
 /// INSERT the specified tableName and data.
 /// </summary>
 /// <param name="tableName">Table name.</param>
 /// <param name="data">Data.</param>
 public void INSERT(string tableName, Dictionary<string, object> data)
 {
     Partitioning part = new Partitioning (data);
     INSERT (tableName, part.keys, part.values);
 }
Example #6
0
        /// <summary>
        /// UPDATE the specified tableName, data and addQuery.
        /// </summary>
        /// <param name="tableName">Table name.</param>
        /// <param name="data">Data.</param>
        /// <param name="addQuery">Add query.</param>
        public void UPDATE(string tableName, Dictionary<string, object> data, string addQuery)
        {
            Partitioning part = new Partitioning (data);

            UPDATE (tableName, part.keys, part.values, addQuery);
        }
Example #7
0
 public abstract RootField CreateRootField(long id, string name, Partitioning partitioning, IFieldSettings settings = null);
Example #8
0
 public ReferencesField(long id, string name, Partitioning partitioning)
     : base(id, name, partitioning, new ReferencesFieldProperties())
 {
 }
Example #9
0
 public AssetsField(long id, string name, Partitioning partitioning, AssetsFieldProperties properties, IAssetTester assetTester)
     : base(id, name, partitioning, properties)
 {
     this.assetTester = assetTester;
 }
Example #10
0
 public override RootField CreateRootField(long id, string name, Partitioning partitioning, IFieldSettings settings = null)
 {
     return(new RootField <UIFieldProperties>(id, name, partitioning, this, settings));
 }
Example #11
0
 public AssetsField(long id, string name, Partitioning partitioning, IAssetTester assetTester)
     : this(id, name, partitioning, new AssetsFieldProperties(), assetTester)
 {
 }
Example #12
0
 public static RootField <UIFieldProperties> UI(long id, string name, Partitioning partitioning,
                                                UIFieldProperties?properties = null, IFieldSettings?settings = null)
 {
     return(new RootField <UIFieldProperties>(id, name, partitioning, properties, settings));
 }
Example #13
0
 public static Schema AddUI(this Schema schema, long id, string name, Partitioning partitioning,
                            UIFieldProperties?properties = null, IFieldSettings?settings = null)
 {
     return(schema.AddField(UI(id, name, partitioning, properties, settings)));
 }
Example #14
0
        /// <summary>
        /// Returns global unique indices which correlate to a certain species and basises.
        /// </summary>
        /// <param name="Fields">
        /// Indices into <see cref="BasisS"/>
        /// </param>
        /// <param name="map">
        /// </param>
        /// <returns>a list of global (over all MPI processes) unique indices.</returns>
        public int[] GetSubvectorIndices(Foundation.XDG.SpeciesId Species, params int[] Fields)
        {
            var map = this.ProblemMapping;

            var _BasisS = map.BasisS.ToArray();

            //XdgAggregationBasis XaggBasis;
            //if(this.AggBasis is XdgAggregationBasis) {
            //    // super-quick and super-dirty fix
            //    XaggBasis = (XdgAggregationBasis)(this.AggBasis);

            //    foreach(var b in _BasisS) {
            //        if(!b.IsSubBasis(XaggBasis.XDGBasis))
            //            throw new ArgumentException();
            //    }
            //} else {
            //    throw new NotSupportedException();
            //}
            XdgAggregationBasis[] XaggBasis = new XdgAggregationBasis[_BasisS.Length];
            for (int iVar = 0; iVar < _BasisS.Length; iVar++)
            {
                Basis b = _BasisS[iVar];

                if (b is BoSSS.Foundation.XDG.XDGBasis)
                {
                    if (!b.IsSubBasis(((XdgAggregationBasis)(this.AggBasis[iVar])).XDGBasis))
                    {
                        throw new ArgumentException();
                    }
                    XaggBasis[iVar] = ((XdgAggregationBasis)(this.AggBasis[iVar]));
                }
                else
                {
                    //if(!b.IsSubBasis(this.AggBasis[iVar].DGBasis))
                    //    throw new ArgumentException();
                    throw new NotSupportedException();
                }
            }

            var          ag         = this.AggGrid;
            int          JAGG       = ag.iLogicalCells.NoOfLocalUpdatedCells;
            Partitioning p          = new Partitioning(JAGG);
            List <int>   R          = new List <int>();
            int          j0_aggCell = p.i0;

            {
                int Nofields = this.m_DgDegree.Length;

                int[] Nfld = new int[Nofields];
                int[] Ofst = new int[Nofields];

                int i0 = this.Partitioning.i0;

                for (int jAgg = 0; jAgg < JAGG; jAgg++)
                {
                    for (int ifld = 0; ifld < Nofields; ifld++)
                    {
                        int pField = this.m_DgDegree[ifld];
                        Nfld[ifld] = this.AggBasis[ifld].GetLength(jAgg, pField);
                        if (ifld > 0)
                        {
                            Ofst[ifld] = Ofst[ifld - 1] + Nfld[ifld - 1];
                        }
                    }
                    int Ncell = Ofst[Nofields - 1] + Nfld[Nofields - 1];

                    for (int i = 0; i < Fields.Length; i++)
                    {
                        int iSpc = XaggBasis[i].GetSpeciesIndex(jAgg, Species);
                        if (iSpc >= 0)
                        {
                            int NoSpc = XaggBasis[i].GetNoOfSpecies(jAgg);

                            int iField = Fields[i];
                            int pField = this.m_DgDegree[iField];

                            int N_iField = Nfld[iField];
                            int N0       = Ofst[iField];

                            int N_Spc = N_iField / NoSpc;
                            Debug.Assert(N_iField % NoSpc == 0);


                            for (int n = 0; n < N_Spc; n++)
                            {
                                int iX = i0 + n + N0 + N_Spc * iSpc;
                                R.Add(iX);
                                Debug.Assert(this.Partitioning.IsInLocalRange(iX));
                                Debug.Assert(iX - j0_aggCell == this.LocalUniqueIndex(iField, jAgg, n + N_Spc * iSpc));
                            }
                        }
                    }
                    i0 += Ncell;
                }
            }

            return(R.ToArray());
        }
Example #15
0
 public abstract RootField CreateRootField(long id, string name, Partitioning partitioning);
Example #16
0
 public static ArrayField Array(long id, string name, Partitioning partitioning,
                                ArrayFieldProperties?properties = null, IFieldSettings?settings = null)
 {
     return(new ArrayField(id, name, partitioning, properties, settings));
 }
Example #17
0
 public GeolocationField(long id, string name, Partitioning partitioning)
     : this(id, name, partitioning, new GeolocationFieldProperties())
 {
 }
Example #18
0
 public ReferencesField(long id, string name, Partitioning partitioning, ReferencesFieldProperties properties)
     : base(id, name, partitioning, properties)
 {
 }
Example #19
0
 public GeolocationField(long id, string name, Partitioning partitioning, GeolocationFieldProperties properties)
     : base(id, name, partitioning, properties)
 {
 }
Example #20
0
        /// <summary>
        /// INSERT batch.
        /// </summary>
        /// <param name="tableName">Table name.</param>
        /// <param name="data">Data.</param>
        public void INSERT_BATCH(string tableName, List<Dictionary<string, object>> data)
        {
            string[] column = null;
            string[][] value = new string[data.Count][];

            for (int i = 0; i < data.Count; i++) {
                Partitioning part = new Partitioning (data [i]);
                value [i] = part.values;

                if (i == 0) {
                    column = part.keys;
                }
            }

            INSERT_BATCH (tableName, column, value);
        }
Example #21
0
 public BooleanField(long id, string name, Partitioning partitioning)
     : this(id, name, partitioning, new BooleanFieldProperties())
 {
 }
Example #22
0
            public override bool ApplyEvent(IEvent @event)
            {
                var previousSchema = SchemaDef;

                switch (@event)
                {
                case SchemaCreated e:
                {
                    Id = e.SchemaId.Id;

                    SchemaDef         = e.Schema;
                    SchemaFieldsTotal = e.Schema.MaxId();

                    AppId = e.AppId;

                    return(true);
                }

                case FieldAdded e:
                {
                    if (e.ParentFieldId != null)
                    {
                        var field = e.Properties.CreateNestedField(e.FieldId.Id, e.Name);

                        SchemaDef = SchemaDef.UpdateField(e.ParentFieldId.Id, x => ((ArrayField)x).AddField(field));
                    }
                    else
                    {
                        var partitioning = Partitioning.FromString(e.Partitioning);

                        var field = e.Properties.CreateRootField(e.FieldId.Id, e.Name, partitioning);

                        SchemaDef = SchemaDef.DeleteField(e.FieldId.Id);
                        SchemaDef = SchemaDef.AddField(field);
                    }

                    SchemaFieldsTotal = Math.Max(SchemaFieldsTotal, e.FieldId.Id);

                    break;
                }

                case SchemaUIFieldsConfigured e:
                {
                    if (e.FieldsInLists != null)
                    {
                        SchemaDef = SchemaDef.SetFieldsInLists(e.FieldsInLists);
                    }

                    if (e.FieldsInReferences != null)
                    {
                        SchemaDef = SchemaDef.SetFieldsInReferences(e.FieldsInReferences);
                    }

                    break;
                }

                case SchemaCategoryChanged e:
                {
                    SchemaDef = SchemaDef.ChangeCategory(e.Name);

                    break;
                }

                case SchemaPreviewUrlsConfigured e:
                {
                    SchemaDef = SchemaDef.SetPreviewUrls(e.PreviewUrls);

                    break;
                }

                case SchemaScriptsConfigured e:
                {
                    SchemaDef = SchemaDef.SetScripts(e.Scripts);

                    break;
                }

                case SchemaFieldRulesConfigured e:
                {
                    SchemaDef = SchemaDef.SetFieldRules(e.FieldRules);

                    break;
                }

                case SchemaPublished:
                {
                    SchemaDef = SchemaDef.Publish();

                    break;
                }

                case SchemaUnpublished:
                {
                    SchemaDef = SchemaDef.Unpublish();

                    break;
                }

                case SchemaUpdated e:
                {
                    SchemaDef = SchemaDef.Update(e.Properties);

                    break;
                }

                case SchemaFieldsReordered e:
                {
                    SchemaDef = SchemaDef.ReorderFields(e.FieldIds.ToList(), e.ParentFieldId?.Id);

                    break;
                }

                case FieldUpdated e:
                {
                    SchemaDef = SchemaDef.UpdateField(e.FieldId.Id, e.Properties, e.ParentFieldId?.Id);

                    break;
                }

                case FieldLocked e:
                {
                    SchemaDef = SchemaDef.LockField(e.FieldId.Id, e.ParentFieldId?.Id);

                    break;
                }

                case FieldDisabled e:
                {
                    SchemaDef = SchemaDef.DisableField(e.FieldId.Id, e.ParentFieldId?.Id);

                    break;
                }

                case FieldEnabled e:
                {
                    SchemaDef = SchemaDef.EnableField(e.FieldId.Id, e.ParentFieldId?.Id);

                    break;
                }

                case FieldHidden e:
                {
                    SchemaDef = SchemaDef.HideField(e.FieldId.Id, e.ParentFieldId?.Id);

                    break;
                }

                case FieldShown e:
                {
                    SchemaDef = SchemaDef.ShowField(e.FieldId.Id, e.ParentFieldId?.Id);

                    break;
                }

                case FieldDeleted e:
                {
                    SchemaDef = SchemaDef.DeleteField(e.FieldId.Id, e.ParentFieldId?.Id);

                    break;
                }

                case SchemaDeleted:
                {
                    IsDeleted = true;

                    return(true);
                }
                }

                return(!ReferenceEquals(previousSchema, SchemaDef));
            }
Example #23
0
 public BooleanField(long id, string name, Partitioning partitioning, BooleanFieldProperties properties)
     : base(id, name, partitioning, properties)
 {
 }
Example #24
0
 public override RootField CreateRootField(long id, string name, Partitioning partitioning, IFieldSettings settings = null)
 {
     return(null);
 }
Example #25
0
 public NumberField(long id, string name, Partitioning partitioning)
     : this(id, name, partitioning, new NumberFieldProperties())
 {
 }
Example #26
0
 public DateTimeField(long id, string name, Partitioning partitioning)
     : this(id, name, partitioning, new DateTimeFieldProperties())
 {
 }
Example #27
0
 public NumberField(long id, string name, Partitioning partitioning, NumberFieldProperties properties)
     : base(id, name, partitioning, properties)
 {
 }
Example #28
0
 public int GetI0Offest(int proc)
 {
     return(Partitioning.GetI0Offest(proc));
 }
Example #29
0
 public override Field CreateField(long id, string name, Partitioning partitioning)
 {
     return(new StringField(id, name, partitioning, this));
 }
Example #30
0
        /// <summary>
        /// Returns global unique indices which correlate to a certain sub-set of this mapping's
        /// basises (<see cref="UnsetteledCoordinateMapping.BasisS"/>).
        /// </summary>
        /// <param name="Fields">
        /// Indices into <see cref="BasisS"/>
        /// </param>
        public int[] GetSubvectorIndices(params int[] Fields)
        {
            ilPSP.MPICollectiveWatchDog.Watch();
            var map = this.ProblemMapping;

            var _BasisS = map.BasisS.ToArray();

            for (int iVar = 0; iVar < _BasisS.Length; iVar++)
            {
                Basis b = _BasisS[iVar];

                if (b is BoSSS.Foundation.XDG.XDGBasis)
                {
                    if (!b.IsSubBasis(((XdgAggregationBasis)(this.AggBasis[iVar])).XDGBasis))
                    {
                        throw new ArgumentException();
                    }
                }
                else
                {
                    if (!b.IsSubBasis(this.AggBasis[iVar].DGBasis))
                    {
                        throw new ArgumentException();
                    }
                }
            }
            var          ag         = this.AggGrid;
            int          JAGG       = ag.iLogicalCells.NoOfLocalUpdatedCells;
            List <int>   R          = new List <int>();
            Partitioning p          = new Partitioning(JAGG);
            int          j0_aggCell = p.i0;

            if (this.MaximalLength == this.MinimalLength)
            {
                // ++++++++++++++++++++++++++++++
                // case: constant length per cell
                // ++++++++++++++++++++++++++++++


                Debug.Assert(this.m_DgDegree.Length == this.AggBasis.Length);
                int[] DofVar = new int[this.m_DgDegree.Length];
                for (int i = 0; i < DofVar.Length; i++)
                {
                    DofVar[i] = AggBasis[i].GetLength(0, m_DgDegree[i]);
                }

                int   L      = DofVar.Sum();
                int[] Offset = new int[Fields.Length];
                for (int i = 0; i < Fields.Length; i++)
                {
                    int iField = Fields[i];
                    if (iField < 0 || iField > _BasisS.Length)
                    {
                        throw new IndexOutOfRangeException();
                    }
                    Offset[i] = iField.ForLoop(k => DofVar[k]).Sum();
                }


                for (int jAgg = 0; jAgg < JAGG; jAgg++)  // loop over aggregate cells

                {
                    for (int i = 0; i < Fields.Length; i++)
                    {
                        int iField = Fields[i];
                        int N      = DofVar[iField];

                        N = ag.iLogicalCells.AggregateCellToParts[jAgg].Max(j => DofVar[iField]);

                        int i0 = L * (j0_aggCell + jAgg) + Offset[i];

                        for (int n = 0; n < N; n++)
                        {
                            int iX = i0 + n;
                            R.Add(iX);
                            Debug.Assert(this.Partitioning.IsInLocalRange(iX));
                            Debug.Assert(iX - j0_aggCell * L == this.LocalUniqueIndex(iField, jAgg, n));
                        }
                    }
                }
            }
            else
            {
                // ++++++++++++++++++++++++++++++
                // case: variable length per cell
                // ++++++++++++++++++++++++++++++

                int Nofields = this.m_DgDegree.Length;

                //int[] Nfld = new int[Nofields];
                //int[] Ofst = new int[Nofields];

                int i0Proc = this.Partitioning.i0;

                for (int jAgg = 0; jAgg < JAGG; jAgg++)
                {
                    //for(int ifld = 0; ifld < Nofields; ifld++) {
                    //    int pField = this.m_DgDegree[ifld];
                    //    Nfld[ifld] = this.AggBasis[ifld].GetLength(jAgg, pField);
                    //    if(ifld > 0)
                    //        Ofst[ifld] = Ofst[ifld - 1] + Nfld[ifld - 1];
                    //}
                    //int Ncell = Ofst[Nofields - 1] + Nfld[Nofields - 1];


                    for (int i = 0; i < Fields.Length; i++)
                    {
                        int iField = Fields[i];
                        int pField = this.m_DgDegree[iField];
                        int Nfld   = this.AggBasis[iField].GetLength(jAgg, pField);



                        //int N_iField = Nfld[iField];
                        //int N0 = Ofst[iField];

                        int i0Loc = this.LocalUniqueIndex(iField, jAgg, 0);

                        for (int n = 0; n < Nfld; n++)
                        {
                            int iX = i0Proc + i0Loc + n;
                            R.Add(iX);
                            Debug.Assert(this.Partitioning.IsInLocalRange(iX));
                            Debug.Assert(iX - i0Proc == this.LocalUniqueIndex(iField, jAgg, n));
                        }
                    }
                }
            }

            return(R.ToArray());
        }
Example #31
0
        //
        public static IEnumerable<Tuple<int, int>> FindAgglomeration(LevelSetTracker Tracker, SpeciesId spId, double AgglomerationThreshold,
            MultidimensionalArray CellVolumes, MultidimensionalArray edgeArea,
            bool AgglomerateNewborn, bool AgglomerateDeceased, bool ExceptionOnFailedAgglomeration,
            MultidimensionalArray[] oldCellVolumes, double[] oldTs__AgglomerationTreshold, double NewbornAndDecasedThreshold)
        {
            using (var tracer = new FuncTrace()) {
                MPICollectiveWatchDog.Watch();

                // init
                // =======

                GridData grdDat = Tracker.GridDat;
                int[,] Edge2Cell = grdDat.Edges.CellIndices;
                byte[] EdgeTags = grdDat.Edges.EdgeTags;
                var Cell2Edge = grdDat.Cells.Cells2Edges;
                int myMpiRank = Tracker.GridDat.MpiRank;
                int NoOfEdges = grdDat.Edges.Count;
                int Jup = grdDat.Cells.NoOfLocalUpdatedCells;
                int Jtot = grdDat.Cells.Count;
                Partitioning CellPart = Tracker.GridDat.CellPartitioning;
                int i0 = CellPart.i0;
                var GidxExt = Tracker.GridDat.Parallel.GlobalIndicesExternalCells;
                var GidxExt2Lidx = Tracker.GridDat.Parallel.Global2LocalIdx;
                //double[] RefVolumes = grdDat.Grid.RefElements.Select(Kref => Kref.Volume).ToArray();

                if (CellVolumes.GetLength(0) != Jtot)
                    throw new ArgumentException();
                if (edgeArea.GetLength(0) != NoOfEdges)
                    throw new ArgumentException();

                double EmptyEdgeTreshold = 1.0e-10; // edges with a measure blow or equal to this threshold are
                // considered to be 'empty', therefore they should not be used for agglomeration;
                //                                     there is, as always, an exception: if all inner edges which belong to a
                //                                     cell that should be agglomerated, the criterion mentioned above must be ignored.

                // determine agglomeration cells
                // ================================
                var _AccEdgesMask = new BitArray(NoOfEdges);
                var AgglomCellsBitmask = new BitArray(Jup);
                var _AgglomCellsEdges = new BitArray(NoOfEdges);
                //var _AllowedEdges =  new BitArray(NoOfEdges); _AllowedEdges.SetAll(true); // AllowedEdges.GetBitMask();
                var AgglomerationPairs = new List<CellAgglomerator.AgglomerationPair>();
                {

                    // mask for the cells in which we -- potentially -- want to do agglomeration
                    var AggCandidates = Tracker.Regions.GetSpeciesMask(spId).GetBitMaskWithExternal().CloneAs();

                    // pass 1: determine agglomeration sources
                    // ---------------------------------------

                    List<int> AgglomCellsList = new List<int>();
                    {
                        // for the present timestep
                        // - - - - - - - - - - - - -

                        CellMask suspectsForAgg = Tracker.Regions.GetCutCellMask().Intersect(Tracker.Regions.GetSpeciesMask(spId));
                        foreach (int jCell in suspectsForAgg.ItemEnum) {
                            double totVol = grdDat.Cells.GetCellVolume(jCell);

                            double spcVol = CellVolumes[jCell];
                            double alpha = AgglomerationThreshold;
                            spcVol = Math.Max(spcVol, 0.0);
                            double frac = spcVol / totVol;
                            //if (!(frac >= 0.0 && frac <= 1.00000001))
                            //    throw new Exception("Strange volume fraction: cell " + jCell + ", species" + spId.ToString() + ", volume fraction =" + frac + ".");
                            frac = Math.Min(1.0, Math.Max(0.0, frac));

                            if (frac < alpha) {
                                // cell 'jCell' should be agglomerated to some other cell
                                AgglomCellsBitmask[jCell] = true;
                                AgglomCellsList.Add(jCell);
                            }
                        }
                    }

                    int NoTimeLev = oldTs__AgglomerationTreshold != null ? oldTs__AgglomerationTreshold.Length : 0;
                    if (NoTimeLev > 0) {
                        // for the previous timestep
                        // - - - - - - - - - - - - -

                        //ushort[][] PrevRegions = new ushort[NoTimeLev][];
                        //CellMask suspectsForAgg = Tracker.PreviousRegions.GetSpeciesMask(spId);
                        //CellMask[] suspectsForAgg = new CellMask[NoTimeLev];
                        //for(int itl = 0; itl < NoTimeLev; itl++) {
                        //    PrevRegions[itl] = Tracker.RegionsHistory[-itl].LevelSetRegionsCode;
                        //    suspectsForAgg[itl] = Tracker.RegionsHistory[-itl].GetSpeciesMask(spId);
                        //}

                        LevelSetSignCode[] signCodes = Tracker.GetLevelSetSignCodes(spId);
                        int NoOfLevSets = Tracker.LevelSets.Count;

                        for (int iTimeLev = 0; iTimeLev < NoTimeLev; iTimeLev++) {
                            CellMask suspectsForAgg = Tracker.RegionsHistory[-iTimeLev].GetSpeciesMask(spId);
                            foreach (int jCell in suspectsForAgg.ItemEnum) {

                                double totVol = grdDat.Cells.GetCellVolume(jCell);
                                double spcVol = oldCellVolumes[iTimeLev][jCell];
                                double alpha = oldTs__AgglomerationTreshold[iTimeLev];
                                spcVol = Math.Max(spcVol, 0.0);
                                double frac = spcVol / totVol;
                                frac = Math.Min(1.0, Math.Max(0.0, frac));

                                if (frac < alpha) {
                                    // cell 'jCell' should be agglomerated to some other cell
                                    if (!AgglomCellsBitmask[jCell]) {
                                        AgglomCellsBitmask[jCell] = true;
                                        AgglomCellsList.Add(jCell);
                                    }
                                }
                            }
                        }
                    }

                    if (AgglomerateNewborn) {

                        for (int j = 0; j < Jup; j++) {
                            double vol = grdDat.Cells.GetCellVolume(j);
                            double volNewFrac_j = Math.Max(CellVolumes[j], 0.0) / vol;
                            volNewFrac_j = Math.Min(1.0, Math.Max(0.0, volNewFrac_j));

                            if (volNewFrac_j > NewbornAndDecasedThreshold) {
                                for (int nTs = 0; nTs < oldCellVolumes.Length; nTs++) {

                                    double volOldFrac_j = Math.Max(oldCellVolumes[nTs][j], 0.0) / vol;
                                    volOldFrac_j = Math.Min(1.0, Math.Max(0.0, volOldFrac_j));
                                    if (volOldFrac_j <= NewbornAndDecasedThreshold) {
                                        // cell exists at new time, but not at some old time -> newborn

                                        int jNewbornCell = j;
                                        AggCandidates[jNewbornCell] = false;
                                        if (!AgglomCellsBitmask[jNewbornCell]) {
                                            AgglomCellsList.Add(jNewbornCell);
                                            AgglomCellsBitmask[jNewbornCell] = true;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (AgglomerateDeceased) {

                        for (int j = 0; j < Jup; j++) {
                            double vol = grdDat.Cells.GetCellVolume(j);
                            double volNewFrac_j = Math.Max(CellVolumes[j], 0.0) / vol;
                            volNewFrac_j = Math.Min(1.0, Math.Max(0.0, volNewFrac_j));

                            if (volNewFrac_j <= NewbornAndDecasedThreshold) {
                                for (int nTs = 0; nTs < oldCellVolumes.Length; nTs++) {

                                    double volOldFrac_j = Math.Max(oldCellVolumes[nTs][j], 0.0) / vol;
                                    volOldFrac_j = Math.Min(1.0, Math.Max(0.0, volOldFrac_j));
                                    if (volOldFrac_j > NewbornAndDecasedThreshold) {
                                        // cell does not exist at new time, but at some old time -> decased

                                        int jNewbornCell = j;
                                        AggCandidates[jNewbornCell] = false;
                                        if (!AgglomCellsBitmask[jNewbornCell]) {
                                            AgglomCellsList.Add(jNewbornCell);
                                            AgglomCellsBitmask[jNewbornCell] = true;
                                        }
                                    }

                                }
                            }

                        }

                    }
                    //*/

                    /*
                    if (AgglomerateNewborn || AgglomerateDeceased) {
                        //CellMask oldSpeciesCells = this.Tracker.LevelSetData.PreviousSubGrids[spId].VolumeMask;
                        CellMask newSpeciesCells = Tracker.Regions.GetSpeciesMask(spId);

                        // only accept cells with positive volume (new species cells)
                        BitArray newSpeciesCellsBitmask = newSpeciesCells.GetBitMask().CloneAs();
                        Debug.Assert(newSpeciesCellsBitmask.Count == Jup);
                        for (int j = 0; j < Jup; j++) {
                            double vol = grdDat.Cells.GetCellVolume(j);
                            double volFrac_j = Math.Max(CellVolumes[j], 0.0) / vol;
                            volFrac_j = Math.Min(1.0, Math.Max(0.0, volFrac_j));

                            if (volFrac_j > NewbornAndDecasedThreshold) {
                                Debug.Assert(newSpeciesCellsBitmask[j] == true);
                            } else {
                                newSpeciesCellsBitmask[j] = false;
                            }
                        }
                        newSpeciesCells = new CellMask(grdDat, newSpeciesCellsBitmask);

                        // only accept cells with positive volume (old species cells)
                        BitArray oldSpeciesCellsBitmask = new BitArray(Jup); //  oldSpeciesCells.GetBitMask().CloneAs();
                        //Debug.Assert(oldSpeciesCellsBitmask.Count == Jup);
                        for (int nTs = 0; nTs < oldCellVolumes.Length; nTs++) {
                            MultidimensionalArray _oldCellVolumes = oldCellVolumes[nTs];

                            for (int j = 0; j < Jup; j++) {
                                double vol = grdDat.Cells.GetCellVolume(j);
                                double volFrac_j = Math.Max(_oldCellVolumes[j],0.0) / vol;
                                volFrac_j = Math.Min(1.0, Math.Max(0.0, volFrac_j));

                                if (volFrac_j > NewbornAndDecasedThreshold) {
                                    //Debug.Assert(oldSpeciesCellsBitmask[j] == true);
                                    oldSpeciesCellsBitmask[j] = true;
                                } else {
                                    //oldSpeciesCellsBitmask[j] = false;
                                }
                            }
                        }
                        var oldSpeciesCells = new CellMask(grdDat, oldSpeciesCellsBitmask);

                        // find newborn and decased
                        CellMask newBorn = newSpeciesCells.Except(oldSpeciesCells);
                        CellMask deceased = oldSpeciesCells.Except(newSpeciesCells);

                        foreach (int jNewbornCell in newBorn.ItemEnum) {
                            AggCandidates[jNewbornCell] = false;
                            if (!AgglomCellsBitmask[jNewbornCell]) {
                                AgglomCellsList.Add(jNewbornCell);
                                AgglomCellsBitmask[jNewbornCell] = true;
                            }
                            //Console.WriteLine("  agglom newborn: " + jNewbornCell);
                        }

                        foreach (int jDeceasedCell in deceased.ItemEnum) {
                            AggCandidates[jDeceasedCell] = false;
                            if (!AgglomCellsBitmask[jDeceasedCell]) {
                                AgglomCellsList.Add(jDeceasedCell);
                                AgglomCellsBitmask[jDeceasedCell] = true;
                            }
                            //Console.WriteLine("  agglom deceased: " + jDeceasedCell);
                        }

                    }
                    //*/

                    // pass 2: determine agglomeration targets
                    // ---------------------------------------

                    foreach (int jCell in AgglomCellsList) {
                        var Cell2Edge_jCell = Cell2Edge[jCell];

                        // cell 'jCell' should be agglomerated to some other cell
                        Debug.Assert(AgglomCellsBitmask[jCell] == true);

                        double frac_neigh_max = -1.0;
                        int e_max = -1;
                        int jEdge_max = int.MinValue;
                        int jCellNeigh_max = int.MinValue;

                        int NoOfEdges_4_jCell = Cell2Edge_jCell.Length;

                        // determine if there is a non-empty edge which connects cell 'jCell'
                        // to some other cell
                        bool NonEmptyEdgeAvailable = false;
                        for (int e = 0; e < NoOfEdges_4_jCell; e++) { // loop over faces/neighbour cells...
                            int iEdge = Cell2Edge_jCell[e];
                            int OtherCell;
                            if (iEdge < 0) {
                                // cell 'jCell' is the OUT-cell of edge 'iEdge'
                                OtherCell = 0;
                                iEdge *= -1;
                            } else {
                                OtherCell = 1;
                            }
                            iEdge--;
                            int jCellNeigh = Edge2Cell[iEdge, OtherCell];

                            double EdgeArea_iEdge = edgeArea[iEdge];
                            if (jCellNeigh >= 0 && EdgeArea_iEdge > EmptyEdgeTreshold)
                                NonEmptyEdgeAvailable = true;
                        }

                        for (int e = 0; e < NoOfEdges_4_jCell; e++) { // loop over faces/neighbour cells...
                            int iEdge = Cell2Edge_jCell[e];
                            int OtherCell, ThisCell;
                            if (iEdge < 0) {
                                // cell 'jCell' is the OUT-cell of edge 'iEdge'
                                OtherCell = 0;
                                ThisCell = 1;
                                iEdge *= -1;
                            } else {
                                OtherCell = 1;
                                ThisCell = 0;
                            }
                            iEdge--;

                            double EdgeArea_iEdge = edgeArea[iEdge];

                            _AgglomCellsEdges[iEdge] = true;

                            Debug.Assert(Edge2Cell[iEdge, ThisCell] == jCell);

                            int jCellNeigh = Edge2Cell[iEdge, OtherCell];
                            if (jCellNeigh < 0 || EdgeTags[iEdge] >= GridCommons.FIRST_PERIODIC_BC_TAG || (EdgeArea_iEdge <= EmptyEdgeTreshold && NonEmptyEdgeAvailable)) {
                                // boundary edge, no neighbour for agglomeration
                                Debug.Assert(Edge2Cell[iEdge, ThisCell] == jCell, "sollte aber so sein");
                                continue;
                            }

                            if (!AggCandidates[jCellNeigh])
                                // not suitable for agglomeration
                                continue;

                            // volume fraction of neighbour cell
                            double spcVol_neigh = CellVolumes[jCellNeigh];
                            //double totVol_neigh = RefVolumes[grdDat.Cells.GetRefElementIndex(jCellNeigh)];
                            double totVol_neigh = grdDat.Cells.GetCellVolume(jCellNeigh);
                            double frac_neigh = spcVol_neigh / totVol_neigh;

                            // max?
                            if (frac_neigh > frac_neigh_max) {
                                frac_neigh_max = frac_neigh;
                                e_max = e;
                                jCellNeigh_max = jCellNeigh;
                                jEdge_max = iEdge;
                            }
                        }

                        if (jCellNeigh_max < 0) {
                            string message = ("Agglomeration failed - no candidate for agglomeration found");
                            if (ExceptionOnFailedAgglomeration)
                                throw new Exception(message);
                            else
                                Console.WriteLine(message);
                        } else {
                            _AccEdgesMask[jEdge_max] = true;

                            int jCellNeighRank;
                            if (jCellNeigh_max < Jup) {
                                jCellNeighRank = myMpiRank;
                            } else {
                                jCellNeighRank = CellPart.FindProcess(GidxExt[jCellNeigh_max - Jup]);
                            }

                            AgglomerationPairs.Add(new CellAgglomerator.AgglomerationPair() {
                                jCellTarget = jCellNeigh_max,
                                jCellSource = jCell,
                                OwnerRank4Target = jCellNeighRank,
                                OwnerRank4Source = myMpiRank
                            });
                        }
                    }
                }

                // store & return
                // ================
                return AgglomerationPairs.Select(pair => new Tuple<int, int>(pair.jCellSource, pair.jCellTarget)).ToArray();
            }
        }
Example #32
0
 public IFieldPartitioning ResolvePartition(Partitioning key)
 {
     return(partitionResolver(key));
 }
Example #33
0
 public static ArrayField Array(long id, string name, Partitioning partitioning, params NestedField[] fields)
 {
     return(new ArrayField(id, name, partitioning, fields));
 }