コード例 #1
0
        /// <summary>
        /// Gets the index of a record by ID.
        /// Accessing grid item IDs or URLs via EasyRepro is currently broken (see https://github.com/microsoft/EasyRepro/issues/800). Use this method instead.
        /// </summary>
        /// <param name="subGrid">The SubGrid.</param>
        /// <param name="subgridName">The name of the subgrid.</param>
        /// <param name="driver">The Selenium WebDriver.</param>
        /// <param name="index">The index of the record.</param>
        public static void HighlightRecord(this SubGrid subGrid, string subgridName, IWebDriver driver, int index)
        {
            if (driver is null)
            {
                throw new ArgumentNullException(nameof(driver));
            }

            var subGridElement = driver.FindElement(
                By.XPath(AppElements.Xpath[AppReference.Entity.SubGridContents].Replace("[NAME]", subgridName)));

            var rows = subGridElement.FindElements(By.CssSelector("div.wj-row[role=row][data-lp-id]"));

            if (rows.Count == 0)
            {
                throw new NoSuchElementException($"No records were found for subgrid {subgridName}");
            }

            if (index + 1 > rows.Count)
            {
                throw new IndexOutOfRangeException($"Subgrid {subgridName} record count: {rows.Count}. Expected: {index + 1}");
            }

            rows[index].FindElement(By.TagName("div")).Click();
            driver.WaitForTransaction();
        }
コード例 #2
0
        public override void ProcessSubGridResult(IClientLeafSubGrid[][] subGrids)
        {
            lock (this)
            {
                foreach (IClientLeafSubGrid[] subGrid in subGrids)
                {
                    if ((subGrid?.Length ?? 0) > 0 && subGrid[0] is ClientHeightLeafSubGrid SubGrid)
                    {
                        CellsScanned += SubGridTreeConsts.SubGridTreeCellsPerSubGrid;

                        BoundingExtents.Include(SubGrid.WorldExtents());

                        SubGridUtilities.SubGridDimensionalIterator((I, J) =>
                        {
                            var heightValue = SubGrid.Cells[I, J];

                            if (Math.Abs(heightValue - CellPassConsts.NullHeight) > Consts.TOLERANCE_HEIGHT)
                            {
                                CellsUsed++;

                                if (MinElevation > heightValue)
                                {
                                    MinElevation = heightValue;
                                }

                                if (MaxElevation < heightValue)
                                {
                                    MaxElevation = heightValue;
                                }
                            }
                        });
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Determines the admissible step-size within
        /// <paramref name="subGrid"/> by calling
        /// <see cref="GetLocalStepSize"/> for all contiguous chunks of cells.
        /// </summary>
        /// <param name="subGrid">
        /// The sub-grid for which the step size shall be determined. If null
        /// is given, the full domain will be considered.
        /// </param>
        /// <returns>
        /// The maximum step size dictated by the CFL restriction in the given
        /// <paramref name="subGrid"/>.
        /// </returns>
        /// <remarks>
        /// This is a collective call which requires all processes to
        /// synchronize.
        /// </remarks>
        public double GetGloballyAdmissibleStepSize(SubGrid subGrid = null)
        {
            MPICollectiveWatchDog.Watch();
            subGrid = subGrid ?? new SubGrid(CellMask.GetFullMask(gridData));

            double maxTimeStep = double.MaxValue;
            double globalMaxTimeStep;

            System.Exception e = null;
            try {
                foreach (Chunk chunk in subGrid.VolumeMask)
                {
                    maxTimeStep = Math.Min(
                        maxTimeStep,
                        GetLocalStepSize(chunk.i0, chunk.Len));
                }
            } catch (System.Exception ee) {
                e = ee;
            }
            e.ExceptionBcast();

            unsafe
            {
                csMPI.Raw.Allreduce(
                    (IntPtr)(&maxTimeStep),
                    (IntPtr)(&globalMaxTimeStep),
                    1,
                    csMPI.Raw._DATATYPE.DOUBLE,
                    csMPI.Raw._OP.MIN,
                    csMPI.Raw._COMM.WORLD);
            }

            return(dtFraction * globalMaxTimeStep);
        }
コード例 #4
0
        //-----------------------------------------------------------------------------
        // finalize
        //-----------------------------------------------------------------------------
        //static public void finalize()
        //{
        //    while (true)
        //    {
        //        Thread.Sleep(500);
        //        prepareGlobalSendFrameToConsoleStrBuilder();
        //        printVector();
        //    }
        //}


        //-----------------------------------------------------------------------------
        // Main
        //
        //   Only draw one edge and flip due to symmetry?
        //       https://youtu.be/6nUMiJfHLSA
        //------------------------------------------------------------------------------
        public static int MainFunction(bool isPlayer = true)
        {
            CALLED++;
            initializeFrameBuffer(' '); // M is the widest, this creates the most symmetrical square
            SubGrid infoBox = new SubGrid(42, 1, 1, 0);

            infoBox.sendTextToBuffer("Get as close as you can to the right edge.");
            infoBox.sendToGlobalBuffer();
            //sendFrameToConsole();

            diceWidget diceWidget = new diceWidget(40, 1, 0, 0); // Currently 40 long, can be dynamicaly adjusted
            Thread     thread     = new Thread(diceWidget.activate);

            thread.Start();

            while (diceWidget.isActive())
            {
                sendFrameToConsole();
            }

            //thread.Interrupt();

            return(diceWidget.evaluateResults());
            //return 6;
        }
コード例 #5
0
        /// <summary>
        /// Update of level-set gradient in 'upwind'-direction, i.e. at boundaries towards accepted cells,
        /// the outer value is taken.
        /// </summary>
        /// <param name="jCell">Cell index to update.</param>
        /// <param name="AcceptedMask"></param>
        /// <param name="Phi">Input: the level-set</param>
        /// <param name="gradPhi">Output: gradient of <paramref name="Phi"/> in cell <paramref name="jCell"/>.</param>
        public void GradientUpdate(int jCell, BitArray AcceptedMask, SinglePhaseField Phi, VectorField <SinglePhaseField> gradPhi)
        {
            var GridDat = Phi.GridDat;

            if (m_gradEvo == null || jCell != m_gradEvo_jCell)
            {
                var Sgrd = new SubGrid(new CellMask(GridDat, Chunk.GetSingleElementChunk(jCell)));



                SpatialOperator op = new SpatialOperator(1, 2, QuadOrderFunc.Linear(), "Phi", "g0", "g1");
                op.EquationComponents["g0"].Add(new Gradient(0, jCell, AcceptedMask));
                op.EquationComponents["g1"].Add(new Gradient(1, jCell, AcceptedMask));
                op.EdgeQuadraturSchemeProvider   = g => new EdgeQuadratureScheme(domain: Sgrd.AllEdgesMask);
                op.VolumeQuadraturSchemeProvider = g => new CellQuadratureScheme(domain: Sgrd.VolumeMask);
                op.Commit();

                m_gradEvo = op.GetEvaluatorEx(
                    Phi.Mapping, null, gradPhi.Mapping);
                m_gradEvo.ActivateSubgridBoundary(subGridBoundaryTreatment: SubGridBoundaryModes.BoundaryEdge, sgrd: Sgrd.VolumeMask);

                m_gradEvo_jCell = jCell;
            }

            foreach (var f in gradPhi)
            {
                f.Coordinates.ClearRow(jCell);
            }
            m_gradEvo.MPITtransceive = false;
            m_gradEvo.Evaluate(1.0, 1.0, gradPhi.CoordinateVector);
        }
コード例 #6
0
 public void SubGridLinked(SubGrid _subGrid)
 {
     if (mainGrid != null)
     {
         spawnableSubGridList = mainGrid.FindNeightbourSubgrids(_subGrid);
     }
 }
コード例 #7
0
        /// <summary>
        /// simplified version of
        /// <see cref="ComputeMatrixEx{M,V}"/>;
        /// </summary>
        static public void ComputeMatrix <M, V>(this SpatialOperator op,
                                                UnsetteledCoordinateMapping DomainMap, IList <DGField> Parameters, UnsetteledCoordinateMapping CodomainMap,
                                                M Matrix, V AffineOffset, bool OnlyAffine, double time = 0.0,
                                                SubGrid sgrd = null)
            where M : IMutableMatrixEx
            where V : IList <double>
        {
            var GridDat = CheckArguments(DomainMap, Parameters, CodomainMap);


            var ev = op.GetMatrixBuilder(DomainMap, Parameters, CodomainMap,
                                         new EdgeQuadratureScheme(true, sgrd == null ? null : sgrd.AllEdgesMask),
                                         new CellQuadratureScheme(true, sgrd == null ? null : sgrd.VolumeMask));

            ev.time = time;

            if (OnlyAffine)
            {
                ev.ComputeAffine(AffineOffset);
            }
            else
            {
                ev.ComputeMatrix(Matrix, AffineOffset);
            }
        }
コード例 #8
0
            /// <summary>
            /// gets a subgrid of width <paramref name="FieldWidth"/>, around level set No. <paramref name="levSetIdx"/>;
            /// </summary>
            /// <remarks>
            /// In contrast to <see cref="SubGrid"/>'s, <see cref="CellMask"/>'s are not MPI-collective, and should therefore be preferred.
            /// </remarks>
            public SubGrid GetNearFieldSubgrid4LevSet(int levSetIdx, int FieldWidth)
            {
                MPICollectiveWatchDog.Watch();

                if (FieldWidth > m_owner.m_NearRegionWidth)
                {
                    throw new ArgumentException("Near-" + FieldWidth + " cannot be acquired, because this tracker is set to detect at most Near-" + m_owner.m_NearRegionWidth + ".", "FieldWidth");
                }
                if (levSetIdx < 0 || levSetIdx >= this.m_owner.NoOfLevelSets)
                {
                    throw new IndexOutOfRangeException();
                }


                if (m_NearField4LevelSet == null || m_NearField4LevelSet.GetLength(1) != this.m_owner.m_NearRegionWidth)
                {
                    m_NearField4LevelSet = new SubGrid[this.m_owner.NoOfLevelSets, this.m_owner.m_NearRegionWidth + 1];
                }

                if (m_NearField4LevelSet[levSetIdx, FieldWidth] == null)
                {
                    // create subgrid
                    m_NearField4LevelSet[levSetIdx, FieldWidth] = new SubGrid(GetNearMask4LevSet(levSetIdx, FieldWidth));
                }

                return(m_NearField4LevelSet[levSetIdx, FieldWidth]);
            }
コード例 #9
0
            /// <summary>
            /// gets a subgrid of width <paramref name="FieldWidth"/>, around any level set
            /// </summary>
            /// <remarks>
            /// In contrast to <see cref="SubGrid"/>'s, <see cref="CellMask"/>'s are not MPI-collective, and should therefore be preferred.
            /// </remarks>
            public SubGrid GetNearFieldSubgrid(int FieldWidth)
            {
                MPICollectiveWatchDog.Watch();

                if (FieldWidth > m_owner.m_NearRegionWidth)
                {
                    throw new ArgumentException("Near-" + FieldWidth + " cannot be acquired, because this tracker is set to detect at most Near-" + m_owner.m_NearRegionWidth + ".", "FieldWidth");
                }

                if (m_owner.NoOfLevelSets == 1)
                {
                    // if there is only one Level Set, no need to separate between
                    // cells-cut-by-any-level-set and cells-cut-by-a-specific-level-set
                    return(GetNearFieldSubgrid4LevSet(0, FieldWidth));
                }

                if (m_NearField == null)
                {
                    m_NearField = new SubGrid[m_owner.m_NearRegionWidth + 1];
                }

                if (m_NearField[FieldWidth] == null)
                {
                    m_NearField[FieldWidth] = new SubGrid(GetNearFieldMask(FieldWidth));
                }

                return(m_NearField[FieldWidth]);
            }
コード例 #10
0
        public void Test_SubGridTree_Clear()
        {
            // Create a tree with the default number of levels (representing cells at the on-the-ground level)
            ISubGridTree tree = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());

            int count;

            // Test clearing the tree with no elements in it
            tree.Clear();

            // Verify tree is empty
            count = 0;
            tree.ScanAllSubGrids(x => { count++; return(true); });
            Assert.Equal(0, count);

            // Add a single subgrid to the tree and verify it can be cleared
            ISubGrid subgrid = new SubGrid(tree, null, 2); // Subgrid at second level, we will attach it as a child of root

            tree.Root.SetSubGrid(0, 0, subgrid);

            // Verify tree has a single subgrid other than root
            count = 0;
            tree.Root.ForEachSubGrid(x => { count++; return(SubGridProcessNodeSubGridResult.OK); });
            Assert.Equal(1, count);

            tree.Clear();

            // Verify tree is empty
            count = 0;
            tree.Root.ForEachSubGrid(x => { count++; return(SubGridProcessNodeSubGridResult.OK); });
            Assert.Equal(0, count);
        }
コード例 #11
0
        /// <summary>
        ///
        /// </summary>
        public void GradientUpdate(SubGrid Sgrd, double[] PhiMean, SinglePhaseField Phi, VectorField <SinglePhaseField> gradPhi)
        {
            var GridDat = Phi.GridDat;


            gradPhi.Clear(Sgrd.VolumeMask);

            SpatialOperator op = new SpatialOperator(1, 2, QuadOrderFunc.Linear(), "Phi", "g0", "g1");

            op.EquationComponents["g0"].Add(new Gradient2(0, PhiMean));
            op.EquationComponents["g1"].Add(new Gradient2(1, PhiMean));
            op.Commit();

            var gradEvo = op.GetEvaluatorEx(
                Phi.Mapping, null, gradPhi.Mapping,
                edgeQrCtx: (new EdgeQuadratureScheme(domain: Sgrd.AllEdgesMask)),
                volQrCtx: (new CellQuadratureScheme(domain: Sgrd.VolumeMask)),
                subGridBoundaryTreatment: SpatialOperator.SubGridBoundaryModes.BoundaryEdge, sgrd: Sgrd);

            //Sgrd.VolumeMask.ToTxtFile("nar.csv", false);


            gradPhi.Clear(Sgrd.VolumeMask);
            gradEvo.Evaluate(1.0, 0.0, gradPhi.CoordinateVector, 0.0, MPIexchange: false);
            //gradPhi.GradientByFlux(1.0, Phi, optionalSubGrid:Sgrd , bndMode: SpatialOperator.SubGridBoundaryModes.BoundaryEdge);
        }
コード例 #12
0
        /// <summary>
        ///
        /// </summary>
        public void GradientUpdate(SubGrid Sgrd, double[] PhiMean, SinglePhaseField Phi, VectorField <SinglePhaseField> gradPhi)
        {
            var GridDat = Phi.GridDat;


            gradPhi.Clear(Sgrd.VolumeMask);

            SpatialOperator op = new SpatialOperator(1, 2, QuadOrderFunc.Linear(), "Phi", "g0", "g1");

            op.EquationComponents["g0"].Add(new Gradient2(0, PhiMean));
            op.EquationComponents["g1"].Add(new Gradient2(1, PhiMean));
            op.EdgeQuadraturSchemeProvider   = g => (new EdgeQuadratureScheme(domain: Sgrd.AllEdgesMask));
            op.VolumeQuadraturSchemeProvider = g => (new CellQuadratureScheme(domain: Sgrd.VolumeMask));
            op.Commit();

            var gradEvo = op.GetEvaluatorEx(Phi.Mapping, null, gradPhi.Mapping);

            gradEvo.ActivateSubgridBoundary(Sgrd.VolumeMask, SubGridBoundaryModes.BoundaryEdge);

            //Sgrd.VolumeMask.ToTxtFile("nar.csv", false);


            gradPhi.Clear(Sgrd.VolumeMask);
            gradEvo.time           = 0.0;
            gradEvo.MPITtransceive = false;
            gradEvo.Evaluate(1.0, 0.0, gradPhi.CoordinateVector);
            //gradPhi.GradientByFlux(1.0, Phi, optionalSubGrid:Sgrd , bndMode: SubGridBoundaryModes.BoundaryEdge);
        }
コード例 #13
0
        /// <summary>
        /// accumulates the derivative of DG field <paramref name="f"/>
        /// (along the <paramref name="d"/>-th axis) times <paramref name="alpha"/>
        /// to this field, i.e. <br/>
        /// this = this + <paramref name="alpha"/>* \f$ \frac{\partial}{\partial x_d} \f$ <paramref name="f"/>;
        /// </summary>
        /// <param name="f"></param>
        /// <param name="d">
        /// 0 for the x-derivative, 1 for the y-derivative, 2 for the
        /// z-derivative
        /// </param>
        /// <param name="alpha">
        /// scaling of <paramref name="f"/>;
        /// </param>
        /// <param name="optionalSubGrid">
        /// An optional restriction to the domain in which the derivative is
        /// computed (it may, e.g. be only required in boundary cells, so a
        /// computation over the whole domain would be a waste of computational
        /// power. A proper execution mask would be see e.g.
        /// <see cref="GridData.BoundaryCells"/>.)
        /// <br/>
        /// if null, the computation is carried out in the whole domain.
        /// </param>
        /// <param name="bndMode">
        /// if a sub-grid is provided, this determines how the sub-grid
        /// boundary should be treated.
        /// </param>
        /// <remarks>
        /// The derivative is calculated using Riemann flux functions
        /// (central difference);<br/>
        /// In comparison to
        /// <see cref="Derivative(double, DGField, int, CellMask)"/>, this method
        /// should be slower, but produce more sane results, especially for
        /// fields of low polynomial degree (0 or 1);
        /// </remarks>
        virtual public void DerivativeByFlux(double alpha, DGField f, int d, SubGrid optionalSubGrid = null, SubGridBoundaryModes bndMode = SubGridBoundaryModes.OpenBoundary)
        {
            int D = this.Basis.GridDat.SpatialDimension;

            if (d < 0 || d >= D)
            {
                throw new ArgumentException("spatial dimension out of range.", "d");
            }
            MPICollectiveWatchDog.Watch(csMPI.Raw._COMM.WORLD);

            EdgeMask emEdge = (optionalSubGrid != null) ? optionalSubGrid.AllEdgesMask : null;
            CellMask emVol  = (optionalSubGrid != null) ? optionalSubGrid.VolumeMask : null;

            SpatialOperator d_dx = new SpatialOperator(1, 1, QuadOrderFunc.Linear(), "in", "out");

            d_dx.EdgeQuadraturSchemeProvider   = g => new Quadrature.EdgeQuadratureScheme(true, emEdge);
            d_dx.VolumeQuadraturSchemeProvider = g => new Quadrature.CellQuadratureScheme(true, emVol);
            var flux = CreateDerivativeFlux(d, f.Identification);

            d_dx.EquationComponents["out"].Add(flux);
            d_dx.Commit();


            var ev = d_dx.GetEvaluatorEx(
                new CoordinateMapping(f), null, this.Mapping);

            if (optionalSubGrid != null)
            {
                ev.ActivateSubgridBoundary(optionalSubGrid.VolumeMask, bndMode);
            }

            ev.Evaluate <CoordinateVector>(alpha, 1.0, this.CoordinateVector);
        }
コード例 #14
0
ファイル: FastMarchReinit.cs プロジェクト: xj361685640/BoSSS
        public void GradientUpdate(SubGrid NEAr, SinglePhaseField Phi, VectorField <SinglePhaseField> GradPhi)
        {
            this.gradModule.GradientUpdate(NEAr, this.m_PhiAvg, Phi, GradPhi);

            //GradPhi.Clear(NEAr.VolumeMask);
            //GradPhi.Gradient(1, Phi, NEAr.VolumeMask);
        }
コード例 #15
0
ファイル: IBMABevolve.cs プロジェクト: octwanna/BoSSS
        public IBMABevolve(
            SpatialOperator standardOperator,
            SpatialOperator boundaryOperator,
            CoordinateMapping fieldsMap,
            CoordinateMapping parametersMap,
            ISpeciesMap ibmSpeciesMap,
            int explicitOrder,
            int levelSetQuadratureOrder,
            XQuadFactoryHelper.MomentFittingVariants momentFittingVariant,
            SubGrid sgrd,
            bool adaptive = false)
            : base(standardOperator, fieldsMap, parametersMap, explicitOrder, adaptive: adaptive, sgrd: sgrd)
        {
            speciesMap = ibmSpeciesMap as ImmersedSpeciesMap;
            if (speciesMap == null)
            {
                throw new ArgumentException(
                          "Only supported for species maps of type 'ImmersedSpeciesMap'",
                          "speciesMap");
            }

            this.boundaryOperator          = boundaryOperator;
            this.boundaryParameterMap      = parametersMap;
            agglomerationPatternHasChanged = true;
        }
コード例 #16
0
        /// <summary>
        /// Constructs a new PlotDriver
        /// </summary>
        /// <param name="context">The omnipresent context</param>
        /// <param name="showJumps">
        /// If true, ghost cell values will be calculated and additional ghost
        /// zone information will be exported (i.e. ghost cells will be
        /// included in the plots)
        /// </param>
        /// <param name="showGhostCells">
        /// If true, the real DG data (including discontinuities) should be
        /// exported. Otherwise, the mean value of all values in one node
        /// should be calculated
        /// </param>
        /// <param name="superSampling">
        /// how often one computational cell should be subdivided;
        /// <see cref="ZoneDriver.superSampling"/>
        /// </param>
        /// <param name="__sgrd">
        /// </param>
        protected PlotDriver(GridData context, bool showJumps, bool showGhostCells, uint superSampling, SubGrid __sgrd)
        {
            var RefElms = context.Grid.RefElements;

            ZoneDrivers = new ZoneDriver[RefElms.Length];
            for (int iKref = 0; iKref < RefElms.Length; iKref++)
            {
                SubGrid ZoneSgrd;
                if (__sgrd == null)
                {
                    ZoneSgrd = context.GetRefElementSubGrid(iKref);
                }
                else
                {
                    var B = context.GetRefElementSubGrid(iKref);
                    ZoneSgrd = new SubGrid(B.VolumeMask.Intersect(__sgrd.VolumeMask));
                }

                if (ZoneSgrd.GlobalNoOfCells <= 0)
                {
                    continue;
                }

                //Debug.Assert(false, "break: " + context.MyRank);
                ZoneDrivers[iKref] = CreateZoneDriver(context, iKref, showJumps, showGhostCells, superSampling, ZoneSgrd);
            }

            this.gridData = context;
        }
コード例 #17
0
ファイル: ExplicitEuler.cs プロジェクト: rohitvuppala/BoSSS
        /// <summary>
        ///
        /// </summary>
        /// <param name="spatialOp"></param>
        /// <param name="Fieldsmap"></param>
        /// <param name="Parameters">
        /// optional parameter fields, can be null if
        /// <paramref name="spatialOp"/> contains no parameters; must match
        /// the parameter field list of <paramref name="spatialOp"/>, see
        /// <see cref="BoSSS.Foundation.SpatialOperator.ParameterVar"/>
        /// </param>
        /// <param name="sgrdBnd">
        /// Options for the treatment of edges at the boundary of a SubGrid,
        /// <see cref="SubGridBoundaryModes"/></param>
        /// <param name="timeStepConstraints">
        /// optional list of time step constraints <see cref="TimeStepConstraint"/>
        /// </param>
        /// <param name="sgrd">
        /// optional restriction to computational domain
        /// </param>
        public ExplicitEuler(SpatialOperator spatialOp, CoordinateMapping Fieldsmap, CoordinateMapping Parameters, SubGridBoundaryModes sgrdBnd, IList <TimeStepConstraint> timeStepConstraints = null, SubGrid sgrd = null)
        {
            using (new ilPSP.Tracing.FuncTrace()) {
                // verify input
                // ============
                TimeStepperCommon.VerifyInput(spatialOp, Fieldsmap, Parameters);


                Mapping          = Fieldsmap;
                CurrentState     = new CoordinateVector(Mapping);
                ParameterMapping = Parameters;
                IList <DGField> ParameterFields =
                    (ParameterMapping == null) ? (new DGField[0]) : ParameterMapping.Fields;

                this.TimeStepConstraints = timeStepConstraints;

                SubGrid = sgrd ?? new SubGrid(CellMask.GetFullMask(Fieldsmap.First().GridDat));

                // generate Evaluator
                // ==================

                CellMask cm = SubGrid.VolumeMask;
                EdgeMask em = SubGrid.AllEdgesMask;

                Operator    = spatialOp;
                m_Evaluator = new Lazy <IEvaluatorNonLin>(delegate() {
                    spatialOp.EdgeQuadraturSchemeProvider   = g => new EdgeQuadratureScheme(true, em);
                    spatialOp.VolumeQuadraturSchemeProvider = g => new CellQuadratureScheme(true, cm);
                    var op = spatialOp.GetEvaluatorEx(
                        Fieldsmap, ParameterFields, Fieldsmap);
                    op.ActivateSubgridBoundary(SubGrid.VolumeMask, sgrdBnd);
                    return(op);
                });
            }
        }
コード例 #18
0
        /// <summary>
        /// Interpolates the boundary elements for sub-grid of "id"
        /// </summary>
        /// <param name="historyDG">History of DG coordinates</param>
        /// <param name="id">ID of the sub-grid</param>
        /// <param name="interpolTime">Interpolation time</param>
        /// <returns>
        /// Array of the complete grid, which has only non-zero entries for
        /// the interpolated cells
        /// </returns>
        protected Dictionary <int, double> InterpolateBoundaryValues(Queue <double[]>[] historyDG, int id, double interpolTime)
        {
            SubGrid subGrid = BoundarySgrds[id - 1];
            Dictionary <int, double> myDic = new Dictionary <int, double>();

            for (int j = 0; j < subGrid.LocalNoOfCells; j++)
            {
                int cell           = jSub2jCell[id - 1][j];
                int BoundaryGridId = BoundaryTopology[id - 1, cell];
                // cell at boundary
                // f== each field
                // n== basis polynomial
                foreach (DGField f in Mapping.Fields)
                {
                    for (int n = 0; n < f.Basis.GetLength(cell); n++)
                    {
                        int      cellIndex = Mapping.LocalUniqueCoordinateIndex(f, cell, n);
                        double[] valueHist = new double[order];
                        int      k         = 0;
                        foreach (double[] histArray in historyDG[BoundaryGridId])
                        {
                            valueHist[k] = histArray[cellIndex];
                            k++;
                        }
                        double[] timeHistory       = GetBoundaryCellTimeHistory(BoundaryGridId, cell);
                        double   interpolatedValue = Interpolate(timeHistory, valueHist, interpolTime, order);
                        myDic.Add(cellIndex, interpolatedValue);
                    }
                }
            }
            return(myDic);
        }
コード例 #19
0
        public void Test_SubGrid_SetAbsoluteOriginPosition()
        {
            ISubGrid subgrid = null;

            SubGridTree tree = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());

            subgrid = new SubGrid(tree, null, 2); // create a node to be a chile of the root node

            // Test setting origin for unattached subgrid
            subgrid.SetAbsoluteOriginPosition(100, 100);

            Assert.True(subgrid.OriginX == 100 && subgrid.OriginY == 100,
                        "SetAbsoluteOriginPosition did not set origin position for subgrid");

            // Add subgrid to the root (which will set it's parent and prevent the origin position from
            // being changed and will throw an exception)
            tree.Root.SetSubGrid(0, 0, subgrid);
            try
            {
                subgrid.SetAbsoluteOriginPosition(100, 100);

                Assert.True(false, "Setting absolute position for node with a parent did not raise an exception");
            } catch (Exception)
            {
                // As expected`
            }
        }
コード例 #20
0
        /// <summary>
        /// Legacy interface, preserved as static function.
        /// </summary>
        public static void ComputeMatrixEx <M, V>(
            this XSpatialOperator xOp,
            LevelSetTracker lsTrk,
            UnsetteledCoordinateMapping DomainMap, IList <DGField> Parameters, UnsetteledCoordinateMapping CodomainMap,
            M Matrix, V AffineOffset, bool OnlyAffine, double time, bool ParameterMPIExchange,
            IDictionary <SpeciesId, MultidimensionalArray> CellLengthScales,
            IDictionary <SpeciesId, MultidimensionalArray> InterfaceLengthScales, MultidimensionalArray SlipLengths,
            SubGrid SubGrid, params SpeciesId[] whichSpc)
            where M : IMutableMatrixEx
            where V : IList <double> //
        {
            var SpeciesDictionary = new Dictionary <SpeciesId, XSpatialOperator.QrSchemPair>();

            foreach (var sp in whichSpc)
            {
                SpeciesDictionary.Add(sp, new XSpatialOperator.QrSchemPair());
            }

            ComputeMatrixEx <M, V>(
                xOp,
                lsTrk,
                DomainMap, Parameters, CodomainMap,
                Matrix, AffineOffset, OnlyAffine, time,
                ParameterMPIExchange, SpeciesDictionary, CellLengthScales,
                InterfaceLengthScales, SlipLengths,
                //agg, out mass,
                SubGrid);
        }
コード例 #21
0
        /// <summary>
        /// Determines the total curvature which is twice the mean curvature
        /// Please pay attention to the sign of this expression!
        /// </summary>
        /// <param name="Output">The total curvature</param>
        /// <param name="optionalSubGrid">
        /// Subgrid which can be defined, for example for carrying out
        /// computations on a narrow band
        /// </param>
        /// <param name="bndMode">
        /// Definition of the behavior at subgrid boundaries
        /// </param>
        public void ComputeTotalCurvatureByFlux(SinglePhaseField Output,
                                                SubGrid optionalSubGrid = null,
                                                SpatialOperator.SubGridBoundaryModes bndMode = SpatialOperator.SubGridBoundaryModes.OpenBoundary)
        {
            if (this.m_Basis.Degree <= 1)
            {
                throw new ArgumentException("For correct computation of these level set quantities, the level set has to be at least of degree 2!");
            }

            Basis basisForNormalVec = new Basis(this.GridDat, this.m_Basis.Degree - 1);
            Basis basisForCurvature = new Basis(this.GridDat, this.m_Basis.Degree - 2);

            Func <Basis, string, SinglePhaseField> fac          = (Basis b, string id) => new SinglePhaseField(b, id);
            VectorField <SinglePhaseField>         normalVector = new VectorField <SinglePhaseField>(this.GridDat.SpatialDimension, basisForNormalVec, fac);

            ComputeNormalByFlux(normalVector, optionalSubGrid, bndMode);
            VectorField <SinglePhaseField> secondDerivatives = new VectorField <SinglePhaseField>(this.GridDat.SpatialDimension, basisForCurvature, fac);

            Output.Clear();
            for (int i = 0; i < normalVector.Dim; i++)
            {
                secondDerivatives[i].DerivativeByFlux(1.0, normalVector[i], i, optionalSubGrid, bndMode);

                Output.Acc(-1.0, secondDerivatives[i], optionalSubGrid.VolumeMask);
            }
        }
コード例 #22
0
        /// <summary>
        /// Returns a cell metric value in every cell
        /// </summary>
        /// <returns>Cell metric as <see cref="MultidimensionalArray"/></returns>
        private MultidimensionalArray GetStableTimestepSize(SubGrid subGrid, IList <TimeStepConstraint> timeStepConstraints)
        {
            MultidimensionalArray cellMetric = MultidimensionalArray.Create(subGrid.LocalNoOfCells);

            for (int subGridCell = 0; subGridCell < subGrid.LocalNoOfCells; subGridCell++)
            {
                int localCellIndex = subGrid.SubgridIndex2LocalCellIndex[subGridCell];
                //cellMetric[subGridCell] = timeStepConstraints.Min(c => c.GetLocalStepSize(localCellIndex, 1));    // cell metric based on smallest time step constraint
                //cellMetric[subGridCell] = 1.0 / timeStepConstraints.Sum(c => 1.0 / c.GetLocalStepSize(localCellIndex, 1));  // cell metric based on harmonic sum of time step constraints

                List <double> result = new List <double>();
                foreach (TimeStepConstraint constraint in timeStepConstraints)
                {
                    result.Add(constraint.GetLocalStepSize(localCellIndex, 1));
                }
                if (result.All(c => c == double.MaxValue))                      // For IBM source cells: All timeStepConstraints return double.MaxValue --> No influence on clustering
                {
                    cellMetric[subGridCell] = double.MaxValue;
                }
                else
                {
                    cellMetric[subGridCell] = 1.0 / result.Sum(c => 1.0 / c);  // cell metric based on harmonic sum of time step constraints
                }
            }

            return(cellMetric);
        }
コード例 #23
0
        public void Test_SubGrid_SetOriginPosition_FailWithNoParent()
        {
            var leafSubgrid = new SubGrid(null, null, SubGridTreeConsts.SubGridTreeLevels);

            Action act = () => leafSubgrid.SetOriginPosition(10, 10);

            act.Should().Throw <ArgumentException>().WithMessage("Cannot set origin position without parent");
        }
コード例 #24
0
        public void Test_SubGrid_Creation()
        {
            ISubGrid subgrid = null;

            // Try creating a new base subgrid instance directly, supplying
            subgrid = new SubGrid(new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>()), null, SubGridTreeConsts.SubGridTreeLevels);
            Assert.NotNull(subgrid);
        }
コード例 #25
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="spatialOp"></param>
        /// <param name="Fieldsmap"></param>
        /// <param name="Parameters">
        /// optional parameter fields, can be null if
        /// <paramref name="spatialOp"/> contains no parameters; must match
        /// the parameter field list of <paramref name="spatialOp"/>, see
        /// <see cref="BoSSS.Foundation.SpatialOperator.ParameterVar"/>
        /// </param>
        /// <param name="sgrdBnd">
        /// Options for the treatment of edges at the boundary of a SubGrid,
        /// <see cref="SpatialOperator.SubGridBoundaryModes"/></param>
        /// <param name="timeStepConstraints">
        /// optional list of time step constraints <see cref="TimeStepConstraint"/>
        /// </param>
        /// <param name="sgrd">
        /// optional restriction to computational domain
        /// </param>
        public ExplicitEuler(SpatialOperator spatialOp, CoordinateMapping Fieldsmap, CoordinateMapping Parameters, SpatialOperator.SubGridBoundaryModes sgrdBnd, IList <TimeStepConstraint> timeStepConstraints = null, SubGrid sgrd = null)
        {
            using (new ilPSP.Tracing.FuncTrace()) {
                // verify input
                // ============

                if (!spatialOp.ContainsNonlinear && !(spatialOp.ContainsLinear()))
                {
                    throw new ArgumentException("spatial differential operator seems to contain no components.", "spatialOp");
                }
                if (spatialOp.DomainVar.Count != spatialOp.CodomainVar.Count)
                {
                    throw new ArgumentException("spatial differential operator must have the same number of domain and codomain variables.", "spatialOp");
                }
                if (Fieldsmap.Fields.Count != spatialOp.CodomainVar.Count)
                {
                    throw new ArgumentException("the number of fields in the coordinate mapping must be equal to the number of domain/codomain variables of the spatial differential operator", "fields");
                }
                if (Parameters == null)
                {
                    if (spatialOp.ParameterVar.Count != 0)
                    {
                        throw new ArgumentException("the number of fields in the parameter mapping must be equal to the number of parameter variables of the spatial differential operator", "Parameters");
                    }
                }
                else
                {
                    if (Parameters.Fields.Count != spatialOp.ParameterVar.Count)
                    {
                        throw new ArgumentException("the number of fields in the parameter mapping must be equal to the number of parameter variables of the spatial differential operator", "Parameters");
                    }
                }

                Mapping          = Fieldsmap;
                DGCoordinates    = new CoordinateVector(Mapping);
                ParameterMapping = Parameters;
                IList <DGField> ParameterFields =
                    (ParameterMapping == null) ? (new DGField[0]) : ParameterMapping.Fields;

                this.TimeStepConstraints = timeStepConstraints;

                SubGrid = sgrd ?? new SubGrid(CellMask.GetFullMask(Fieldsmap.First().GridDat));

                // generate Evaluator
                // ==================

                CellMask cm = SubGrid.VolumeMask;
                EdgeMask em = SubGrid.AllEdgesMask;

                Operator    = spatialOp;
                m_Evaluator = new Lazy <SpatialOperator.Evaluator>(() => spatialOp.GetEvaluatorEx(
                                                                       Fieldsmap, ParameterFields, Fieldsmap,
                                                                       new EdgeQuadratureScheme(true, em),
                                                                       new CellQuadratureScheme(true, cm),
                                                                       SubGrid,
                                                                       sgrdBnd));
            }
        }
コード例 #26
0
        /// <summary>
        /// Constructs the quadrature rules all edges of all cells in
        /// <paramref name="mask"/>. For edges that are not intersected by the
        /// zero iso-contour, standard Gaussian quadrature rules of
        /// sufficiently high order will be used.
        /// </summary>
        /// <param name="mask">
        /// Cells for which quadrature rules shall be created
        /// </param>
        /// <param name="order">
        /// Desired order of the moment-fitting system. Assuming that
        /// <see cref="edgeSurfaceRuleFactory"/> integrates the basis
        /// polynomials exactly over the zero iso-contour (which it usually
        /// doesn't!), the resulting quadrature rules will be exact up to this
        /// order.
        /// </param>
        /// <returns>A set of quadrature rules</returns>
        /// <remarks>
        /// Since the selected level set is generally discontinuous across cell
        /// boundaries, this method does not make use of the fact that
        /// neighboring cells share edges. That is, the optimization will be
        /// performed twice for each inner edge in <paramref name="mask"/>.
        /// </remarks>
        public IEnumerable <IChunkRulePair <CellBoundaryQuadRule> > GetQuadRuleSet(ExecutionMask mask, int order)
        {
            using (var tr = new FuncTrace()) {
                if (!(mask is CellMask))
                {
                    throw new ArgumentException("CellMask required", "mask");
                }
                if (mask.MaskType != MaskType.Geometrical)
                {
                    throw new ArgumentException("Expecting a geometrical mask.");
                }

                int      noOfEdges      = LevelSetData.GridDat.Grid.RefElements[0].NoOfFaces;
                CellMask tmpLogicalMask = new CellMask(mask.GridData, mask.GetBitMask(), MaskType.Logical);
#if DEBUG
                CellMask differingCells = tmpLogicalMask.Except(this.LevelSetData.Region.GetCutCellMask4LevSet(this.levelSetIndex));
                if (differingCells.NoOfItemsLocally > 0)
                {
                    throw new ArgumentException("The provided mask has to be a sub-set of the cut cells. " +
                                                "Cells {0} are not in the CutCellMaks of this tracker.", differingCells.GetSummary());
                }
#endif

                subGrid = new SubGrid(tmpLogicalMask);
                localCellIndex2SubgridIndex = subGrid.LocalCellIndex2SubgridIndex;

                if (order != lastOrder)
                {
                    cache.Clear();
                    SwitchOrder(order);
                }

                var result = new List <ChunkRulePair <CellBoundaryQuadRule> >(mask.NoOfItemsLocally);
                CellBoundaryQuadRule[] optimizedRules = GetOptimizedRules((CellMask)mask, order);
                int n = 0;
                foreach (Chunk chunk in mask)
                {
                    foreach (int cell in chunk.Elements)
                    {
                        if (cache.ContainsKey(cell))
                        {
                            result.Add(new ChunkRulePair <CellBoundaryQuadRule>(
                                           Chunk.GetSingleElementChunk(cell), cache[cell]));
                        }
                        else
                        {
                            cache.Add(cell, optimizedRules[n]);
                            result.Add(new ChunkRulePair <CellBoundaryQuadRule>(
                                           Chunk.GetSingleElementChunk(cell), optimizedRules[n]));
                        }

                        n++;
                    }
                }

                return(result);
            }
        }
コード例 #27
0
        /// <summary>
        /// method for setting up the timestepper, i.e. the necessary
        /// </summary>
        protected void Setup1(Context ctx, ISparseSolver solver, bool[] temporalOp, MsrMatrix spatialOpMtx, IList <double> spatialOpAffine,
                              SubGrid subgrid, SubgridCoordinateMapping fields, double InitialDeltat)
        {
            // check operator and arguments
            if (spatialOpMtx.NoOfRows != spatialOpMtx.NoOfCols)
            {
                throw new ArgumentException("matrix must be quadratic.", "spatialOpMtx");
            }
            if (spatialOpMtx.NoOfRows != fields.GlobalCount)
            {
                throw new ArgumentException("matrix size must be equal to the GlobalCount of fields mapping", "fields,spatialOpMtx");
            }
            if (spatialOpMtx.RowPartition.LocalLength != fields.NUpdate)
            {
                throw new ArgumentException("number of locally stored matrix rows nust be equal to NUpdate of fields mapping.", "fields,spatialOpMtx");
            }
            if (spatialOpAffine.Count < fields.NUpdate)
            {
                throw new ArgumentException("length affine offset vector must be equal or larger than NUpdate of the mapping", "spatialOpAffine");
            }

            m_Context        = ctx;
            m_Solver         = solver;
            m_Subgrid        = subgrid;
            m_SubgridMapping = fields;
            m_AffineOffset1  = spatialOpAffine.ToArray();
            this.temporalOp  = temporalOp;
            BLAS.dscal(m_AffineOffset1.Length, -1.0, m_AffineOffset1, 1);
            {
                // check temporal operator
                // -----------------------
                if (m_SubgridMapping.Fields.Count != temporalOp.Length)
                {
                    throw new ArgumentException(
                              "lenght of temporalOp must be equal to number of domain/codomain variables of the spatial differential operator",
                              "temporalOp");
                }
                m_SubgridMapping.Compress();
                m_SubgridDGCoordinates = m_SubgridMapping.subgridCoordinates;

                m_SubgridMapping.SetupSubmatrix(m_AffineOffset1, spatialOpMtx, out m_CompressedAffine, out m_CompressedMatrix);

                bool timedep      = false;
                bool fullyTimeDep = true;
                foreach (bool b in temporalOp)
                {
                    timedep      = timedep || b;
                    fullyTimeDep = fullyTimeDep & b;
                }
                if (!timedep)
                {
                    throw new ArgumentException("At least one equation must be time-dependent; one entry in temporalOp must be true;", "temporalOp");
                }

                DefineMatrix(m_CompressedMatrix, InitialDeltat);
            }
        }
コード例 #28
0
        public void Test_SubGrid_IsEmpty()
        {
            ISubGrid leafSubgrid = null;

            SubGridTree tree = new SubGridTree(SubGridTreeConsts.SubGridTreeLevels, 1.0, new SubGridFactory <NodeSubGrid, LeafSubGrid>());

            leafSubgrid = new SubGrid(tree, null, SubGridTreeConsts.SubGridTreeLevels);

            Assert.False(leafSubgrid.IsEmpty(), "Base subgrid class identifying itself as empty");
        }
コード例 #29
0
            public IEnumerable <IChunkRulePair <QuadRule> > GetQuadRuleSet(ExecutionMask mask, int order)
            {
                if (!(mask is CellMask))
                {
                    throw new ArgumentException("Expecting a cell mask.");
                }
                if (mask.MaskType != MaskType.Geometrical)
                {
                    throw new ArgumentException("Expecting a geometrical mask.");
                }

#if DEBUG
                if (mask.Except(m_Owner.MaxGrid).NoOfItemsLocally > 0)
                {
                    throw new NotSupportedException("'mask' must be a subset of the cut cells, for my reference element.");
                }
#endif
                if (!Rules.ContainsKey(order))
                {
                    m_Owner.GetQuadRuleSet_Internal(order);
                }

                if (mask.NoOfItemsLocally == m_Owner.MaxGrid.NoOfItemsLocally)
                {
                    // aggressive
                    return(Rules[order]);
                }
                else
                {
                    var Rule = Rules[order];

                    SubGrid S          = new SubGrid((CellMask)mask);
                    var     jsub2jcell = S.SubgridIndex2LocalCellIndex;
                    var     Ret        = new ChunkRulePair <QuadRule> [S.LocalNoOfCells_WithExternal];

                    int L = Ret.Length, H = Rule.Length;
                    int h = 0;
                    for (int jsub = 0; jsub < L; jsub++)
                    {
                        int jCell = jsub2jcell[jsub];

                        Debug.Assert(Rule[h].Chunk.Len == 1);

                        while (jCell > Rule[h].Chunk.i0)
                        {
                            h++;
                        }

                        Debug.Assert(jCell == Rule[h].Chunk.i0);
                        Ret[jsub] = Rule[h];
                    }

                    return(Ret);
                }
            }
コード例 #30
0
ファイル: Solver.cs プロジェクト: OlivierInGithub/Sudoku
        private bool TrySolveGridWithAssumptions()
        {
            var     numberOfPossibleCells = 2;
            short   number = 1;
            SubGrid subGridWithNumberOfPossibleCells = null;

            while (numberOfPossibleCells <= 9)
            {
                while (number <= 9)
                {
                    subGridWithNumberOfPossibleCells = GetSubGridWithNumberOfPossibleCells(_mainGrid.SubGrids3x3, numberOfPossibleCells, number);
                    if (subGridWithNumberOfPossibleCells != null)
                    {
                        break;
                    }
                    subGridWithNumberOfPossibleCells = GetSubGridWithNumberOfPossibleCells(_mainGrid.Rows, numberOfPossibleCells, number);
                    if (subGridWithNumberOfPossibleCells != null)
                    {
                        break;
                    }
                    subGridWithNumberOfPossibleCells = GetSubGridWithNumberOfPossibleCells(_mainGrid.Columns, numberOfPossibleCells, number);
                    if (subGridWithNumberOfPossibleCells != null)
                    {
                        break;
                    }
                    number++;
                }
                if (subGridWithNumberOfPossibleCells != null)
                {
                    break;
                }
                numberOfPossibleCells++;
            }
            foreach (Cell cell in subGridWithNumberOfPossibleCells.Cells.Where((cell) => cell.CanHaveValue(number)))
            {
                cell.Value = number;
                var fullGrid = new FullGrid();
                fullGrid.CopyValues(_mainGrid);
                cell.Value = 0;
                var solver = new Solver(fullGrid);
                try
                {
                    if (solver.TrySolveGrid())
                    {
                        _mainGrid.CopyValues(fullGrid);
                        return(true);
                    }
                }
                catch
                {
                    //All but one of the assumptions should lead to invalid grid and raise an exception
                }
            }
            return(false);
        }