コード例 #1
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(((Ns != null ? Ns.GetHashCode() : 0) * 397) ^ (Name != null ? Name.GetHashCode() : 0));
     }
 }
コード例 #2
0
ファイル: TestTable.cs プロジェクト: andysoftdev/ht4n
        public void DropIndexedTable()
        {
            DropTables(this.regex);

            Assert.IsFalse(Ns.TableExists("test"));

            const string Schema =
                "<Schema><AccessGroup name=\"default\">" +
                "<ColumnFamily><Name>a</Name><Index>true</Index><QualifierIndex>true</QualifierIndex></ColumnFamily>" +
                "</AccessGroup></Schema>";

            Ns.CreateTable("test", Schema, CreateDispositions.CreateIfNotExist);
            Assert.IsTrue(Ns.TableExists("test"));

            if (IsHyper || IsThrift)
            {
                Assert.IsTrue(Ns.TableExists("^test"));
                Assert.IsTrue(Ns.TableExists("^^test"));
            }

            Ns.DropTable("test");

            if (IsHyper || IsThrift)
            {
                Assert.IsFalse(Ns.TableExists("^test"));
                Assert.IsFalse(Ns.TableExists("^^test"));
            }
        }
コード例 #3
0
 public static void ClassCleanup()
 {
     if (table != null)
     {
         table.Dispose();
     }
     Ns.DropNamespaces(DropDispositions.Complete);
     Ns.DropTables();
 }
コード例 #4
0
ファイル: OpLog.cs プロジェクト: aikloy/MongoConnector.Net
        public Boolean IsValid()
        {
            if (Ns.Contains("$cmd") || Ns.Contains("_unused_"))
            {
                return(false);
            }

            return(true);
        }
コード例 #5
0
ファイル: TestHql.cs プロジェクト: andysoftdev/ht4n
        public void Revisions()
        {
            if (!HasHQL)
            {
                return;
            }

            Ns.Exec("CREATE TABLE fruit (tag, description)");
            Ns.Exec("INSERT INTO fruit VALUES" + "(\"2009-08-02 08:30:00\", \"banana\", \"tag:great\", \"Had with lunch\")");

            var cells = Ns.Query("SELECT * FROM fruit");

            Assert.IsNotNull(cells);
            Assert.AreEqual(1, cells.Count);
            Assert.AreEqual(cells[0].Key.Row, "banana");
            Assert.AreEqual(cells[0].Key.ColumnFamily, "tag");
            Assert.AreEqual(cells[0].Key.ColumnQualifier, "great");
            Assert.AreEqual(Encoding.Default.GetString(cells[0].Value), "Had with lunch");
            Assert.AreEqual(cells[0].Key.DateTime, new DateTime(2009, 8, 2, 8, 30, 0, DateTimeKind.Local).ToUniversalTime());

            Ns.Exec("INSERT INTO fruit VALUES" + "(\"2009-08-02 08:30:01\", \"banana\", \"tag:great\", \"Had with dinner\")");

            cells = Ns.Query("SELECT * FROM fruit");
            Assert.IsNotNull(cells);
            Assert.AreEqual(2, cells.Count);
            Assert.AreEqual(cells[0].Key.Row, "banana");
            Assert.AreEqual(cells[0].Key.ColumnFamily, "tag");
            Assert.AreEqual(cells[0].Key.ColumnQualifier, "great");
            Assert.AreEqual(Encoding.Default.GetString(cells[0].Value), "Had with dinner");
            Assert.AreEqual(cells[0].Key.DateTime, new DateTime(2009, 8, 2, 8, 30, 1, DateTimeKind.Local).ToUniversalTime());

            Assert.AreEqual(cells[1].Key.Row, "banana");
            Assert.AreEqual(cells[1].Key.ColumnFamily, "tag");
            Assert.AreEqual(cells[1].Key.ColumnQualifier, "great");
            Assert.AreEqual(Encoding.Default.GetString(cells[1].Value), "Had with lunch");
            Assert.AreEqual(cells[1].Key.DateTime, new DateTime(2009, 8, 2, 8, 30, 0, DateTimeKind.Local).ToUniversalTime());

            Ns.Exec("INSERT INTO fruit VALUES" + "(\"2009-08-02 08:30:01\", \"banana\", \"tag:great\", \"Had with breakfast\")");

            cells = Ns.Query("SELECT * FROM fruit");
            Assert.IsNotNull(cells);
            Assert.AreEqual(2, cells.Count);
            Assert.AreEqual(cells[0].Key.Row, "banana");
            Assert.AreEqual(cells[0].Key.ColumnFamily, "tag");
            Assert.AreEqual(cells[0].Key.ColumnQualifier, "great");
            Assert.AreEqual(Encoding.Default.GetString(cells[0].Value), "Had with breakfast");
            Assert.AreEqual(cells[0].Key.DateTime, new DateTime(2009, 8, 2, 8, 30, 1, DateTimeKind.Local).ToUniversalTime());

            Assert.AreEqual(cells[1].Key.Row, "banana");
            Assert.AreEqual(cells[1].Key.ColumnFamily, "tag");
            Assert.AreEqual(cells[1].Key.ColumnQualifier, "great");
            Assert.AreEqual(Encoding.Default.GetString(cells[1].Value), "Had with lunch");
            Assert.AreEqual(cells[1].Key.DateTime, new DateTime(2009, 8, 2, 8, 30, 0, DateTimeKind.Local).ToUniversalTime());

            Ns.Exec("DROP TABLE fruit");
        }
コード例 #6
0
ファイル: TestTable.cs プロジェクト: andysoftdev/ht4n
        public void RenameIndexedTable()
        {
            DropTables(this.regex);

            Assert.IsFalse(Ns.TableExists("test-1"));
            Assert.IsFalse(Ns.TableExists("test-2"));
            Assert.IsFalse(Ns.TableExists("Test-2"));

            const string Schema =
                "<Schema><AccessGroup name=\"default\">" +
                "<ColumnFamily><Name>a</Name><Index>true</Index><QualifierIndex>true</QualifierIndex></ColumnFamily>" +
                "</AccessGroup></Schema>";

            Ns.CreateTable("test-1", Schema, CreateDispositions.CreateIfNotExist);
            Assert.IsTrue(Ns.TableExists("test-1"));

            if (IsHyper || IsThrift)
            {
                Assert.IsTrue(Ns.TableExists("^test-1"));
                Assert.IsTrue(Ns.TableExists("^^test-1"));
            }

            using (var table = Ns.OpenTable("test-1")) {
                Assert.AreEqual(table.Name, Ns.Name + "/test-1");
            }

            Ns.RenameTable("test-1", "test-2");
            Assert.IsFalse(Ns.TableExists("test-1"));
            Assert.IsTrue(Ns.TableExists("test-2"));

            if (IsHyper || IsThrift)
            {
                Assert.IsFalse(Ns.TableExists("^test-1"));
                Assert.IsFalse(Ns.TableExists("^^test-1"));
                Assert.IsTrue(Ns.TableExists("^test-2"));
                Assert.IsTrue(Ns.TableExists("^^test-2"));
            }

            Ns.RenameTable("test-2", "Test-2");
            Assert.IsFalse(Ns.TableExists("test-2"));
            using (var table = Ns.OpenTable("Test-2")) {
                Assert.AreEqual(table.Name, Ns.Name + "/Test-2");
            }

            Assert.IsTrue(Ns.TableExists("Test-2"));

            if (IsHyper || IsThrift)
            {
                Assert.IsFalse(Ns.TableExists("^test-2"));
                Assert.IsFalse(Ns.TableExists("^^test-2"));
                Assert.IsTrue(Ns.TableExists("^Test-2"));
                Assert.IsTrue(Ns.TableExists("^^Test-2"));
            }
        }
コード例 #7
0
        private static XmlElement CreateTextElement(string name, string value, Ns ns, XmlDocument document)
        {
            XmlElement element = CreateElement(name, ns, document);

            if (!string.IsNullOrEmpty(value))
            {
                element.AppendChild(document.CreateTextNode(value));
            }

            return(element);
        }
コード例 #8
0
ファイル: NsBaseTest.cs プロジェクト: sucaba/IronTextLibrary
        public void Test()
        {
#if false
            object cellValue = new object();
            var    name      = new Idn("foo");
            var    target    = new Ns <object>();
            target.PushFrame();
            var defineResult = target.Define(name);
            var getResult    = target.Get(name);
            Assert.AreSame(defineResult, getResult);
            Assert.AreSame(cellValue, getResult);
            target.PopFrame();
#endif
        }
コード例 #9
0
        private async Task <HttpRequest> ReadRequsetLine()
        {
            using (var timeout = new CancellationTokenSource(3000))
            {
                timeout.Token.Register(() => Ns.Close());

                string requestLine = null;
                using (var sr = new StreamReader(Ns, Encoding.ASCII, false, 65535, true))
                {
                    requestLine = await sr.ReadLineAsync();

                    if (string.IsNullOrEmpty(requestLine))
                    {
                        return(null);
                    }

                    // Discard all other headers
                    while (true)
                    {
                        var dummy = await sr.ReadLineAsync();

                        if (string.IsNullOrEmpty(dummy))
                        {
                            break;
                        }
                    }
                }

                if (requestLine != null)
                {
                    var m = requestLineMatcher.Match(requestLine);
                    if (m.Success)
                    {
                        var result = new HttpRequest {
                            Method = m.Groups[1].Value, RawUri = m.Groups[2].Value
                        };
                        try
                        {
                            result.DecodedUri = new Uri(new Uri("http://localhost/"), result.RawUri);
                        }
                        catch (FormatException)
                        {
                            // The Uri may be invalid
                        }
                        return(result);
                    }
                }
            }
            return(null);
        }
コード例 #10
0
ファイル: TestHql.cs プロジェクト: andysoftdev/ht4n
        public void Unsupported()
        {
            if (HasHQL)
            {
                return;
            }

            try {
                Ns.Exec("CREATE NAMESPACE abc");
                Assert.Fail();
            }
            catch (NotImplementedException) {
            }
        }
コード例 #11
0
        private static XmlElement CreateElement(string name, Ns ns, XmlDocument document)
        {
            switch (ns)
            {
            case Ns.Kml:
                return(document.CreateElement(name, KML_NS));

            case Ns.Atom:
                return(document.CreateElement(ATOM_PREFIX, name, ATOM_NS));

            default:
                throw Error.Internal("Invalid Ns");
            }
        }
コード例 #12
0
 public void Test()
 {
     #if false
     object cellValue = new object();
     var name = new Idn("foo");
     var target = new Ns<object>();
     target.PushFrame();
     var defineResult = target.Define(name);
     var getResult = target.Get(name);
     Assert.AreSame(defineResult, getResult);
     Assert.AreSame(cellValue, getResult);
     target.PopFrame();
     #endif
 }
コード例 #13
0
        protected override async Task WriteStreamingHeader()
        {
            using (var timeout = new CancellationTokenSource(3000))
            {
                var b = Encoding.ASCII.GetBytes(
                    "HTTP/1.1 200 OK\r\n" +
                    "Content-Type: multipart/x-mixed-replace; boundary=" +
                    BOUNDARY +
                    "\r\n"
                    );
                await Ns.WriteAsync(b, 0, b.Length);

                await Ns.FlushAsync();
            }
        }
コード例 #14
0
ファイル: TestHql.cs プロジェクト: andysoftdev/ht4n
        private void ValidateFruitTable(string tableName)
        {
            var cells = Ns.Query(string.Format("SELECT * FROM {0}", tableName));

            Assert.IsNotNull(cells);
            Assert.AreEqual(3, cells.Count);
            Assert.AreEqual(cells[0].Key.Row, "banana");
            Assert.AreEqual(cells[0].Key.ColumnFamily, "tag");
            Assert.AreEqual(cells[0].Key.ColumnQualifier, "great");
            Assert.AreEqual(Encoding.Default.GetString(cells[0].Value), "Had with lunch");
            Assert.AreEqual(cells[1].Key.Row, "cantelope");
            Assert.AreEqual(cells[1].Key.ColumnFamily, "tag");
            Assert.AreEqual(cells[1].Key.ColumnQualifier, "good");
            Assert.AreEqual(Encoding.Default.GetString(cells[1].Value), "Had with breakfast");
            Assert.AreEqual(cells[2].Key.Row, "cantelope");
            Assert.AreEqual(cells[2].Key.ColumnFamily, "description");
            Assert.AreEqual(cells[2].Key.ColumnQualifier, string.Empty);
            Assert.AreEqual(cells[2].Key.DateTime, new DateTime(2009, 8, 2, 8, 30, 0, DateTimeKind.Local).ToUniversalTime());
            Assert.AreEqual(Encoding.Default.GetString(cells[2].Value), "A cultivated variety of muskmelon with orange flesh");

            cells = Ns.Query(string.Format("SELECT tag FROM {0}", tableName));
            Assert.IsNotNull(cells);
            Assert.AreEqual(2, cells.Count);
            Assert.AreEqual(cells[0].Key.Row, "banana");
            Assert.AreEqual(cells[0].Key.ColumnFamily, "tag");
            Assert.AreEqual(cells[0].Key.ColumnQualifier, "great");
            Assert.AreEqual(Encoding.Default.GetString(cells[0].Value), "Had with lunch");
            Assert.AreEqual(cells[1].Key.Row, "cantelope");
            Assert.AreEqual(cells[1].Key.ColumnFamily, "tag");
            Assert.AreEqual(cells[1].Key.ColumnQualifier, "good");
            Assert.AreEqual(Encoding.Default.GetString(cells[1].Value), "Had with breakfast");

            cells = Ns.Query(string.Format("SELECT * FROM {0} WHERE ROW=\"cantelope\"", tableName));
            Assert.IsNotNull(cells);
            Assert.AreEqual(2, cells.Count);
            Assert.AreEqual(cells[0].Key.Row, "cantelope");
            Assert.AreEqual(cells[0].Key.ColumnFamily, "tag");
            Assert.AreEqual(cells[0].Key.ColumnQualifier, "good");
            Assert.AreEqual(Encoding.Default.GetString(cells[0].Value), "Had with breakfast");
            Assert.AreEqual(cells[1].Key.Row, "cantelope");
            Assert.AreEqual(cells[1].Key.ColumnFamily, "description");
            Assert.AreEqual(cells[1].Key.ColumnQualifier, string.Empty);
            Assert.AreEqual(cells[1].Key.DateTime, new DateTime(2009, 8, 2, 8, 30, 0, DateTimeKind.Local).ToUniversalTime());
            Assert.AreEqual(Encoding.Default.GetString(cells[1].Value), "A cultivated variety of muskmelon with orange flesh");
        }
コード例 #15
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Ns.Length != 0)
            {
                hash ^= Ns.GetHashCode();
            }
            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (Kind != 0)
            {
                hash ^= Kind.GetHashCode();
            }
            if (Value != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(Value);
            }
            if (count_ != null)
            {
                hash ^= Count.GetHashCode();
            }
            if (min_ != null)
            {
                hash ^= Min.GetHashCode();
            }
            if (max_ != null)
            {
                hash ^= Max.GetHashCode();
            }
            if (stdDev_ != null)
            {
                hash ^= StdDev.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #16
0
ファイル: NetworkModel.cs プロジェクト: SunyDays/graduate
        private void ComputeStationaryPTC()
        {
            for (int i = 0; i < NodesCount; i++)
            {
                double sum = 0.0;
                for (int stream = 0; stream < StreamsCount; stream++)
                {
                    sum += RoBar[stream][i] / Mu[stream][i];
                }

                Ws.AddElement(sum / (1 - RoTotal[i]));
            }

            for (int stream = 0; stream < StreamsCount; stream++)
            {
                Us.Add(Ws.AddElementWise(Mu[stream].Pow(-1)));
                Ls.Add(LambdaBar[stream].MultiplyElementWise(Ws));
                Ns.Add(LambdaBar[stream].MultiplyElementWise(Us[stream]));
            }
        }
コード例 #17
0
        protected async Task SendTextRensponse(string status, string mimeType, string content)
        {
            var contentBytes = Encoding.UTF8.GetBytes(content);
            var header       =
                "HTTP/1.1 " + status + "\r\n" +
                "Cache-Control: no-cache\r\n" +
                "Content-Length: " + contentBytes.Length.ToString(CultureInfo.InvariantCulture) + "\r\n" +
                "Content-Type: " + mimeType + "\r\n\r\n";

            var headerBytes = Encoding.ASCII.GetBytes(header);

            using (var timeout = new CancellationTokenSource(3000))
            {
                timeout.Token.Register(() => Ns.Close());
                await Ns.WriteAsync(headerBytes, 0, headerBytes.Length);

                await Ns.WriteAsync(contentBytes, 0, contentBytes.Length);

                await Ns.FlushAsync();
            }
        }
コード例 #18
0
        /// <summary>
        /// Calculate Forces acting from fluid onto the particle
        /// </summary>
        internal double Torque(double[] position, CellMask cutCells)
        {
            double tempTorque = new double();

            void ErrFunc2(int j0, int Len, NodeSet Ns, MultidimensionalArray result)
            {
                int K = result.GetLength(1);
                MultidimensionalArray Grad_UARes = MultidimensionalArray.Create(Len, K, m_SpatialDim, m_SpatialDim);;
                MultidimensionalArray pARes      = MultidimensionalArray.Create(Len, K);
                MultidimensionalArray Normals    = m_LevelSetTracker.DataHistories[0].Current.GetLevelSetNormals(Ns, j0, Len);

                for (int i = 0; i < m_SpatialDim; i++)
                {
                    m_U[i].EvaluateGradient(j0, Len, Ns, Grad_UARes.ExtractSubArrayShallow(-1, -1, i, -1), 0, 1);
                }
                m_P.Evaluate(j0, Len, Ns, pARes);
                for (int j = 0; j < Len; j++)
                {
                    MultidimensionalArray Ns_Global = Ns.CloneAs();
                    m_LevelSetTracker.GridDat.TransformLocal2Global(Ns, Ns_Global, j0 + j);
                    for (int k = 0; k < K; k++)
                    {
                        result[j, k] = TorqueStressTensor(Grad_UARes, pARes, Normals, Ns_Global, m_FluidViscosity, k, j, position);
                    }
                }
            }

            var SchemeHelper2         = m_LevelSetTracker.GetXDGSpaceMetrics(new[] { m_LevelSetTracker.GetSpeciesId("A") }, m_RequiredOrder, 1).XQuadSchemeHelper;
            CellQuadratureScheme cqs2 = SchemeHelper2.GetLevelSetquadScheme(0, cutCells);

            CellQuadrature.GetQuadrature(new int[] { 1 }, m_LevelSetTracker.GridDat, cqs2.Compile(m_LevelSetTracker.GridDat, m_RequiredOrder),
                                         delegate(int i0, int Length, QuadRule QR, MultidimensionalArray EvalResult) {
                ErrFunc2(i0, Length, QR.Nodes, EvalResult.ExtractSubArrayShallow(-1, -1, 0));
            },
                                         delegate(int i0, int Length, MultidimensionalArray ResultsOfIntegration) {
                tempTorque = ForceTorqueSummationWithNeumaierArray(tempTorque, ResultsOfIntegration, Length);
            }
                                         ).Execute();
            return(tempTorque);
        }
コード例 #19
0
        public FSMNet <TInput, TOutput> Solve()
        {
            if (FSM == null)
            {
                throw new NullReferenceException();
            }

            FSMNet <TInput, TOutput> result = null;

            try
            {
                RefreshWorkSets();

                result = new FSMNet <TInput, TOutput>(FSM);
                result.DecomposeAlg = this;

                foreach (var pi in PIs)
                {
                    result.AddToEnd(new FSMNet <TInput, TOutput> .NetComponent(new ComponentFSM <TInput, TOutput>(this, pi.Value, FSM.InitialState, pi.Key))
                    {
                    });
                }
            }
            catch (Exception exc)
            {
                EPSs.Clear();
                TAUs.Clear();
                Ns.Clear();
                TTs.Clear();
                throw exc;
            }
            if (result != null)
            {
                result.FSM.CalcIsProbabilityMachine();
            }
            return(result);
        }
コード例 #20
0
ファイル: TestHql.cs プロジェクト: andysoftdev/ht4n
        public void Query()
        {
            if (!HasHQL)
            {
                return;
            }

            Ns.Exec("CREATE TABLE fruit (tag, description)");
            Ns.Exec(
                "INSERT INTO fruit VALUES" + "(\"cantelope\", \"tag:good\", \"Had with breakfast\"),"
                + "(\"2009-08-02 08:30:00\", \"cantelope\", \"description\", \"A cultivated variety of muskmelon with orange flesh\"),"
                + "(\"banana\", \"tag:great\", \"Had with lunch\")");

            ValidateFruitTable("fruit");

            Ns.Exec("DELETE description FROM fruit WHERE ROW=\"cantelope\"");

            var cells = Ns.Query("SELECT * FROM fruit", "SELECT * FROM fruit WHERE ROW=\"banana\""); // multiple queries

            Assert.IsNotNull(cells);
            Assert.AreEqual(3, cells.Count);
            Assert.AreEqual(cells[0].Key.Row, "banana");
            Assert.AreEqual(cells[0].Key.ColumnFamily, "tag");
            Assert.AreEqual(cells[0].Key.ColumnQualifier, "great");
            Assert.AreEqual(Encoding.Default.GetString(cells[0].Value), "Had with lunch");
            Assert.AreEqual(cells[1].Key.Row, "cantelope");
            Assert.AreEqual(cells[1].Key.ColumnFamily, "tag");
            Assert.AreEqual(cells[1].Key.ColumnQualifier, "good");
            Assert.AreEqual(Encoding.Default.GetString(cells[1].Value), "Had with breakfast");
            Assert.AreEqual(cells[2].Key.Row, "banana");
            Assert.AreEqual(cells[2].Key.ColumnFamily, "tag");
            Assert.AreEqual(cells[2].Key.ColumnQualifier, "great");
            Assert.AreEqual(Encoding.Default.GetString(cells[0].Value), "Had with lunch");

            Ns.Exec("DROP TABLE fruit");
        }
コード例 #21
0
ファイル: Particle.cs プロジェクト: leyel/BoSSS
        /// <summary>
        /// Update forces and torque acting from fluid onto the particle
        /// </summary>
        /// <param name="U"></param>
        /// <param name="P"></param>
        /// <param name="LsTrk"></param>
        /// <param name="muA"></param>
        public void UpdateForcesAndTorque(VectorField <SinglePhaseField> U, SinglePhaseField P,
                                          LevelSetTracker LsTrk,
                                          double muA)
        {
            if (skipForceIntegration)
            {
                skipForceIntegration = false;
                return;
            }

            int D = LsTrk.GridDat.SpatialDimension;
            // var UA = U.Select(u => u.GetSpeciesShadowField("A")).ToArray();
            var UA = U.ToArray();

            int RequiredOrder = U[0].Basis.Degree * 3 + 2;

            //int RequiredOrder = LsTrk.GetXQuadFactoryHelper(momentFittingVariant).GetCachedSurfaceOrders(0).Max();
            //Console.WriteLine("Order reduction: {0} -> {1}", _RequiredOrder, RequiredOrder);

            //if (RequiredOrder > agg.HMForder)
            //    throw new ArgumentException();

            Console.WriteLine("Forces coeff: {0}, order = {1}", LsTrk.CutCellQuadratureType, RequiredOrder);


            ConventionalDGField pA = null;

            //pA = P.GetSpeciesShadowField("A");
            pA = P;

            #region Force
            double[] forces = new double[D];
            for (int d = 0; d < D; d++)
            {
                ScalarFunctionEx ErrFunc = delegate(int j0, int Len, NodeSet Ns, MultidimensionalArray result) {
                    int K = result.GetLength(1); // No nof Nodes
                    MultidimensionalArray Grad_UARes = MultidimensionalArray.Create(Len, K, D, D);;
                    MultidimensionalArray pARes      = MultidimensionalArray.Create(Len, K);

                    // Evaluate tangential velocity to level-set surface
                    var Normals = LsTrk.DataHistories[0].Current.GetLevelSetNormals(Ns, j0, Len);


                    for (int i = 0; i < D; i++)
                    {
                        UA[i].EvaluateGradient(j0, Len, Ns, Grad_UARes.ExtractSubArrayShallow(-1, -1, i, -1), 0, 1);
                    }

                    pA.Evaluate(j0, Len, Ns, pARes);

                    if (LsTrk.GridDat.SpatialDimension == 2)
                    {
                        for (int j = 0; j < Len; j++)
                        {
                            for (int k = 0; k < K; k++)
                            {
                                double acc = 0.0;
                                // pressure
                                switch (d)
                                {
                                case 0:
                                    acc += (pARes[j, k]) * Normals[j, k, 0];
                                    acc -= (2 * muA) * Grad_UARes[j, k, 0, 0] * Normals[j, k, 0];
                                    acc -= (muA) * Grad_UARes[j, k, 0, 1] * Normals[j, k, 1];
                                    acc -= (muA) * Grad_UARes[j, k, 1, 0] * Normals[j, k, 1];
                                    break;

                                case 1:
                                    acc += (pARes[j, k]) * Normals[j, k, 1];
                                    acc -= (2 * muA) * Grad_UARes[j, k, 1, 1] * Normals[j, k, 1];
                                    acc -= (muA) * Grad_UARes[j, k, 1, 0] * Normals[j, k, 0];
                                    acc -= (muA) * Grad_UARes[j, k, 0, 1] * Normals[j, k, 0];
                                    break;

                                default:
                                    throw new NotImplementedException();
                                }

                                result[j, k] = acc;
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < Len; j++)
                        {
                            for (int k = 0; k < K; k++)
                            {
                                double acc = 0.0;

                                // pressure
                                switch (d)
                                {
                                case 0:
                                    acc += pARes[j, k] * Normals[j, k, 0];
                                    acc -= (2 * muA) * Grad_UARes[j, k, 0, 0] * Normals[j, k, 0];
                                    acc -= (muA) * Grad_UARes[j, k, 0, 2] * Normals[j, k, 2];
                                    acc -= (muA) * Grad_UARes[j, k, 0, 1] * Normals[j, k, 1];
                                    acc -= (muA) * Grad_UARes[j, k, 1, 0] * Normals[j, k, 1];
                                    acc -= (muA) * Grad_UARes[j, k, 2, 0] * Normals[j, k, 2];
                                    break;

                                case 1:
                                    acc += pARes[j, k] * Normals[j, k, 1];
                                    acc -= (2 * muA) * Grad_UARes[j, k, 1, 1] * Normals[j, k, 1];
                                    acc -= (muA) * Grad_UARes[j, k, 1, 2] * Normals[j, k, 2];
                                    acc -= (muA) * Grad_UARes[j, k, 1, 0] * Normals[j, k, 0];
                                    acc -= (muA) * Grad_UARes[j, k, 0, 1] * Normals[j, k, 0];
                                    acc -= (muA) * Grad_UARes[j, k, 2, 1] * Normals[j, k, 2];
                                    break;

                                case 2:
                                    acc += pARes[j, k] * Normals[j, k, 2];
                                    acc -= (2 * muA) * Grad_UARes[j, k, 2, 2] * Normals[j, k, 2];
                                    acc -= (muA) * Grad_UARes[j, k, 2, 0] * Normals[j, k, 0];
                                    acc -= (muA) * Grad_UARes[j, k, 2, 1] * Normals[j, k, 1];
                                    acc -= (muA) * Grad_UARes[j, k, 0, 2] * Normals[j, k, 0];
                                    acc -= (muA) * Grad_UARes[j, k, 1, 2] * Normals[j, k, 1];
                                    break;

                                default:
                                    throw new NotImplementedException();
                                }

                                result[j, k] = acc;
                            }
                        }
                    }
                };

                var SchemeHelper = LsTrk.GetXDGSpaceMetrics(new[] { LsTrk.GetSpeciesId("A") }, RequiredOrder, 1).XQuadSchemeHelper;
                //var SchemeHelper = new XQuadSchemeHelper(LsTrk, momentFittingVariant, );

                //CellQuadratureScheme cqs = SchemeHelper.GetLevelSetquadScheme(0, LsTrk.Regions.GetCutCellMask());
                CellQuadratureScheme cqs = SchemeHelper.GetLevelSetquadScheme(0, this.cutCells_P(LsTrk));


                CellQuadrature.GetQuadrature(new int[] { 1 }, LsTrk.GridDat,
                                             cqs.Compile(LsTrk.GridDat, RequiredOrder), //  agg.HMForder),
                                             delegate(int i0, int Length, QuadRule QR, MultidimensionalArray EvalResult) {
                    ErrFunc(i0, Length, QR.Nodes, EvalResult.ExtractSubArrayShallow(-1, -1, 0));
                },
                                             delegate(int i0, int Length, MultidimensionalArray ResultsOfIntegration) {
                    for (int i = 0; i < Length; i++)
                    {
                        forces[d] += ResultsOfIntegration[i, 0];
                    }
                }
                                             ).Execute();
            }
            #endregion

            #region Torque
            double           torque   = 0;
            ScalarFunctionEx ErrFunc2 = delegate(int j0, int Len, NodeSet Ns, MultidimensionalArray result) {
                int K = result.GetLength(1); // No nof Nodes
                MultidimensionalArray Grad_UARes = MultidimensionalArray.Create(Len, K, D, D);;
                MultidimensionalArray pARes      = MultidimensionalArray.Create(Len, K);

                // Evaluate tangential velocity to level-set surface
                var Normals = LsTrk.DataHistories[0].Current.GetLevelSetNormals(Ns, j0, Len);

                for (int i = 0; i < D; i++)
                {
                    UA[i].EvaluateGradient(j0, Len, Ns, Grad_UARes.ExtractSubArrayShallow(-1, -1, i, -1), 0, 1);
                }

                //var trafo = LsTrk.GridDat.Edges.Edge2CellTrafos;
                //var trafoIdx = LsTrk.GridDat.TransformLocal2Global(Ns)
                //var transFormed = trafo[trafoIdx].Transform(Nodes);
                //var newVertices = transFormed.CloneAs();
                //GridData.TransformLocal2Global(transFormed, newVertices, jCell);


                MultidimensionalArray tempArray = Ns.CloneAs();

                LsTrk.GridDat.TransformLocal2Global(Ns, tempArray, j0);

                pA.Evaluate(j0, Len, Ns, pARes);

                for (int j = 0; j < Len; j++)
                {
                    for (int k = 0; k < K; k++)
                    {
                        double acc  = 0.0;
                        double acc2 = 0.0;

                        // Calculate the torque around a circular particle with a given radius (Paper Wan and Turek 2005)

                        acc += (pARes[j, k] * Normals[j, k, 0]);
                        acc -= (2 * muA) * Grad_UARes[j, k, 0, 0] * Normals[j, k, 0];
                        acc -= (muA) * Grad_UARes[j, k, 0, 1] * Normals[j, k, 1];
                        acc -= (muA) * Grad_UARes[j, k, 1, 0] * Normals[j, k, 1];
                        //acc *= -Normals[j, k, 1] * this.radius_P;
                        acc *= -Normals[j, k, 1] * (this.currentPos_P[0][1] - tempArray[k, 1]).Abs();


                        acc2 += pARes[j, k] * Normals[j, k, 1];
                        acc2 -= (2 * muA) * Grad_UARes[j, k, 1, 1] * Normals[j, k, 1];
                        acc2 -= (muA) * Grad_UARes[j, k, 1, 0] * Normals[j, k, 0];
                        acc2 -= (muA) * Grad_UARes[j, k, 0, 1] * Normals[j, k, 0];
                        //acc2 *= Normals[j, k, 0] * this.radius_P;
                        acc2 *= Normals[j, k, 0] * (this.currentPos_P[0][0] - tempArray[k, 0]).Abs();

                        result[j, k] = acc + acc2;
                    }
                }
            };

            var SchemeHelper2 = LsTrk.GetXDGSpaceMetrics(new[] { LsTrk.GetSpeciesId("A") }, RequiredOrder, 1).XQuadSchemeHelper;
            //var SchemeHelper = new XQuadSchemeHelper(LsTrk, momentFittingVariant, );
            //CellQuadratureScheme cqs2 = SchemeHelper2.GetLevelSetquadScheme(0, LsTrk.Regions.GetCutCellMask());
            CellQuadratureScheme cqs2 = SchemeHelper2.GetLevelSetquadScheme(0, this.cutCells_P(LsTrk));

            CellQuadrature.GetQuadrature(new int[] { 1 }, LsTrk.GridDat,
                                         cqs2.Compile(LsTrk.GridDat, RequiredOrder),
                                         delegate(int i0, int Length, QuadRule QR, MultidimensionalArray EvalResult) {
                ErrFunc2(i0, Length, QR.Nodes, EvalResult.ExtractSubArrayShallow(-1, -1, 0));
            },
                                         delegate(int i0, int Length, MultidimensionalArray ResultsOfIntegration) {
                for (int i = 0; i < Length; i++)
                {
                    torque += ResultsOfIntegration[i, 0];
                }
            }

                                         ).Execute();

            double   underrelaxationFT = 1.0;
            double[] temp_underR       = new double[D + 1];
            for (int k = 0; k < D + 1; k++)
            {
                temp_underR[k] = underrelaxation_factor;
            }
            if (iteration_counter_P == 0)
            {
                underrelaxationFT = 1;
            }
            else if (underrelaxationFT_constant == true)
            {
                underrelaxationFT = underrelaxation_factor * Math.Pow(10, underrelaxationFT_exponent);
            }
            else if (underrelaxationFT_constant == false)
            {
                //double[] temp_underR = new double[D + 1];
                bool underrelaxation_ok = false;
                underrelaxationFT_exponent = 1;
                for (int j = 0; j < D; j++)
                {
                    underrelaxation_ok = false;
                    temp_underR[j]     = underrelaxation_factor;
                    for (int i = 0; underrelaxation_ok == false; i++)
                    {
                        if (Math.Abs(temp_underR[j] * forces[j]) > Math.Abs(forces_P[0][j]))
                        {
                            underrelaxationFT_exponent -= 1;
                            temp_underR[j]              = underrelaxation_factor * Math.Pow(10, underrelaxationFT_exponent);
                        }
                        else
                        {
                            underrelaxation_ok = true;
                            if (underrelaxationFT_exponent > -0)
                            {
                                underrelaxationFT_exponent = -0;
                                temp_underR[j]             = underrelaxation_factor * Math.Pow(10, underrelaxationFT_exponent);
                            }
                        }
                    }
                }
                underrelaxation_ok = false;
                temp_underR[D]     = underrelaxation_factor;
                for (int i = 0; underrelaxation_ok == false; i++)
                {
                    if (Math.Abs(temp_underR[D] * torque) > Math.Abs(torque_P[0]))
                    {
                        underrelaxationFT_exponent -= 1;
                        temp_underR[D]              = underrelaxation_factor * Math.Pow(10, underrelaxationFT_exponent);
                    }
                    else
                    {
                        underrelaxation_ok = true;
                        if (underrelaxationFT_exponent > -0)
                        {
                            underrelaxationFT_exponent = -0;
                            temp_underR[D]             = underrelaxation_factor * Math.Pow(10, underrelaxationFT_exponent);
                        }
                    }
                }
            }

            double[] forces_underR = new double[D];
            for (int i = 0; i < D; i++)
            {
                forces_underR[i] = temp_underR[i] * forces[i] + (1 - temp_underR[i]) * forces_P[0][i];
            }
            double torque_underR = temp_underR[D] * torque + (1 - temp_underR[D]) * torque_P[0];
            this.forces_P.Insert(0, forces_underR);
            forces_P.Remove(forces_P.Last());
            this.torque_P.Remove(torque_P.Last());
            this.torque_P.Insert(0, torque_underR);

            #endregion
        }
コード例 #22
0
        /// <summary>
        /// Update Forces and Torque acting from fluid onto the particle
        /// </summary>
        /// <param name="U"></param>
        /// <param name="P"></param>
        /// <param name="LsTrk"></param>
        /// <param name="muA"></param>
        public void UpdateForcesAndTorque(VectorField <SinglePhaseField> U, SinglePhaseField P, LevelSetTracker LsTrk, double muA, double dt, double fluidDensity, bool NotFullyCoupled)
        {
            if (skipForceIntegration)
            {
                skipForceIntegration = false;
                return;
            }
            HydrodynamicForces[0][0] = 0;
            HydrodynamicForces[0][1] = 0;
            HydrodynamicTorque[0]    = 0;
            int RequiredOrder = U[0].Basis.Degree * 3 + 2;

            Console.WriteLine("Forces coeff: {0}, order = {1}", LsTrk.CutCellQuadratureType, RequiredOrder);
            double[]            Forces = new double[SpatialDim];
            SinglePhaseField[]  UA     = U.ToArray();
            ConventionalDGField pA     = null;

            pA = P;
            if (IncludeTranslation)
            {
                for (int d = 0; d < SpatialDim; d++)
                {
                    void ErrFunc(int CurrentCellID, int Length, NodeSet Ns, MultidimensionalArray result)
                    {
                        int NumberOfNodes = result.GetLength(1);
                        MultidimensionalArray Grad_UARes = MultidimensionalArray.Create(Length, NumberOfNodes, SpatialDim, SpatialDim);
                        MultidimensionalArray pARes      = MultidimensionalArray.Create(Length, NumberOfNodes);
                        var Normals = LsTrk.DataHistories[0].Current.GetLevelSetNormals(Ns, CurrentCellID, Length);

                        for (int i = 0; i < SpatialDim; i++)
                        {
                            UA[i].EvaluateGradient(CurrentCellID, Length, Ns, Grad_UARes.ExtractSubArrayShallow(-1, -1, i, -1), 0, 1);
                        }
                        pA.Evaluate(CurrentCellID, Length, Ns, pARes);
                        for (int j = 0; j < Length; j++)
                        {
                            for (int k = 0; k < NumberOfNodes; k++)
                            {
                                result[j, k] = ForceIntegration.CalculateStressTensor(Grad_UARes, pARes, Normals, muA, k, j, this.SpatialDim, d);
                            }
                        }
                    }

                    var SchemeHelper         = LsTrk.GetXDGSpaceMetrics(new[] { LsTrk.GetSpeciesId("A") }, RequiredOrder, 1).XQuadSchemeHelper;
                    CellQuadratureScheme cqs = SchemeHelper.GetLevelSetquadScheme(0, CutCells_P(LsTrk));
                    CellQuadrature.GetQuadrature(new int[] { 1 }, LsTrk.GridDat,
                                                 cqs.Compile(LsTrk.GridDat, RequiredOrder),
                                                 delegate(int i0, int Length, QuadRule QR, MultidimensionalArray EvalResult)
                    {
                        ErrFunc(i0, Length, QR.Nodes, EvalResult.ExtractSubArrayShallow(-1, -1, 0));
                    },
                                                 delegate(int i0, int Length, MultidimensionalArray ResultsOfIntegration)
                    {
                        Forces[d] = ParticleAuxillary.ForceTorqueSummationWithNeumaierArray(Forces[d], ResultsOfIntegration, Length);
                    }
                                                 ).Execute();
                }
            }

            double Torque = 0;

            if (IncludeRotation)
            {
                void ErrFunc2(int j0, int Len, NodeSet Ns, MultidimensionalArray result)
                {
                    int K = result.GetLength(1); // No nof Nodes
                    MultidimensionalArray Grad_UARes = MultidimensionalArray.Create(Len, K, SpatialDim, SpatialDim);;
                    MultidimensionalArray pARes      = MultidimensionalArray.Create(Len, K);
                    // Evaluate tangential velocity to level-set surface
                    var Normals = LsTrk.DataHistories[0].Current.GetLevelSetNormals(Ns, j0, Len);

                    for (int i = 0; i < SpatialDim; i++)
                    {
                        UA[i].EvaluateGradient(j0, Len, Ns, Grad_UARes.ExtractSubArrayShallow(-1, -1, i, -1), 0, 1);
                    }
                    pA.Evaluate(j0, Len, Ns, pARes);
                    for (int j = 0; j < Len; j++)
                    {
                        MultidimensionalArray tempArray = Ns.CloneAs();
                        LsTrk.GridDat.TransformLocal2Global(Ns, tempArray, j0 + j);
                        for (int k = 0; k < K; k++)
                        {
                            result[j, k] = ForceIntegration.CalculateTorqueFromStressTensor2D(Grad_UARes, pARes, Normals, tempArray, muA, k, j, Position[0]);
                        }
                    }
                }

                var SchemeHelper2         = LsTrk.GetXDGSpaceMetrics(new[] { LsTrk.GetSpeciesId("A") }, RequiredOrder, 1).XQuadSchemeHelper;
                CellQuadratureScheme cqs2 = SchemeHelper2.GetLevelSetquadScheme(0, CutCells_P(LsTrk));
                CellQuadrature.GetQuadrature(new int[] { 1 }, LsTrk.GridDat,
                                             cqs2.Compile(LsTrk.GridDat, RequiredOrder),
                                             delegate(int i0, int Length, QuadRule QR, MultidimensionalArray EvalResult)
                {
                    ErrFunc2(i0, Length, QR.Nodes, EvalResult.ExtractSubArrayShallow(-1, -1, 0));
                },
                                             delegate(int i0, int Length, MultidimensionalArray ResultsOfIntegration)
                {
                    Torque = ParticleAuxillary.ForceTorqueSummationWithNeumaierArray(Torque, ResultsOfIntegration, Length);
                }
                                             ).Execute();
            }
            // add gravity
            {
                Forces[1] += (particleDensity - fluidDensity) * Area_P * GravityVertical;
            }
            // Sum forces and moments over all MPI processors
            // ==============================================
            {
                int      NoOfVars    = 1 + SpatialDim;
                double[] StateBuffer = new double[NoOfVars];
                StateBuffer[0] = Torque;
                for (int d = 0; d < SpatialDim; d++)
                {
                    StateBuffer[1 + d] = Forces[d];
                }
                double[] GlobalStateBuffer = StateBuffer.MPISum();
                Torque = GlobalStateBuffer[0];
                for (int d = 0; d < SpatialDim; d++)
                {
                    Forces[d] = GlobalStateBuffer[1 + d];
                }
            }
            if (neglectAddedDamping == false)
            {
                double fest = Forces[0];
                Forces[0] = Forces[0] + AddedDampingCoefficient * dt * (AddedDampingTensor[0, 0] * TranslationalAcceleration[0][0] + AddedDampingTensor[1, 0] * TranslationalAcceleration[0][1] + AddedDampingTensor[0, 2] * RotationalAcceleration[0]);
                Forces[1] = Forces[1] + AddedDampingCoefficient * dt * (AddedDampingTensor[0, 1] * TranslationalAcceleration[0][0] + AddedDampingTensor[1, 1] * TranslationalAcceleration[0][1] + AddedDampingTensor[1, 2] * RotationalAcceleration[0]);
                Torque   += AddedDampingCoefficient * dt * (AddedDampingTensor[2, 0] * TranslationalAcceleration[0][0] + AddedDampingTensor[2, 1] * TranslationalAcceleration[0][1] + AddedDampingTensor[2, 2] * RotationalAcceleration[0]);
            }

            if (iteration_counter_P == -1 || NotFullyCoupled || iteration_counter_P == 250 || stupidcounter == 0)
            {
                Console.WriteLine();
                if (iteration_counter_P == 1)
                {
                    Console.WriteLine("First iteration of the current timestep, all relaxation factors are set to 1");
                }
                if (iteration_counter_P == 250)
                {
                    Console.WriteLine("250 iterations, I'm trying to jump closer to the real solution");
                }
                for (int d = 0; d < SpatialDim; d++)
                {
                    HydrodynamicForces[0][d] = 0;
                    if (Math.Abs(Forces[d]) < ForceAndTorque_convergence * 1e-2 && ClearSmallValues == true)
                    {
                        Forces[d] = 0;
                    }
                    HydrodynamicForces[0][d] = Forces[d];
                }
                HydrodynamicTorque[0] = 0;
                if (Math.Abs(Torque) < ForceAndTorque_convergence * 1e-2 && ClearSmallValues == true)
                {
                    Torque = 0;
                }
                HydrodynamicTorque[0] = Torque;
                stupidcounter         = 1;
            }
            else
            {
                double[] RelaxatedForceAndTorque = Underrelaxation.RelaxatedForcesAndTorque(Forces, Torque, ForcesPrevIteration, TorquePrevIteration, ForceAndTorque_convergence, underrelaxation_factor, ClearSmallValues, AddaptiveUnderrelaxation, AverageDistance, iteration_counter_P);
                for (int d = 0; d < SpatialDim; d++)
                {
                    HydrodynamicForces[0][d] = RelaxatedForceAndTorque[d];
                }
                HydrodynamicTorque[0] = RelaxatedForceAndTorque[SpatialDim];
            }
            //for (int d = 0; d < SpatialDim; d++)// changes sign depending on the sign of Forces[d], should increase the convergence rate. (testing needed)
            //{
            //    if (Math.Abs(HydrodynamicForces[0][d] - Forces[0]) > Math.Abs(Forces[d]))
            //    {
            //        HydrodynamicForces[0][d] *= -1;
            //    }
            //}
            if (double.IsNaN(HydrodynamicForces[0][0]) || double.IsInfinity(HydrodynamicForces[0][0]))
            {
                throw new ArithmeticException("Error trying to calculate hydrodynamic forces (x). Value:  " + HydrodynamicForces[0][0]);
            }
            if (double.IsNaN(HydrodynamicForces[0][1]) || double.IsInfinity(HydrodynamicForces[0][1]))
            {
                throw new ArithmeticException("Error trying to calculate hydrodynamic forces (y). Value:  " + HydrodynamicForces[0][1]);
            }
            if (double.IsNaN(HydrodynamicTorque[0]) || double.IsInfinity(HydrodynamicTorque[0]))
            {
                throw new ArithmeticException("Error trying to calculate hydrodynamic torque. Value:  " + HydrodynamicTorque[0]);
            }
        }
コード例 #23
0
ファイル: TestHql.cs プロジェクト: andysoftdev/ht4n
 public void TestInitialize()
 {
     TestBase.ContinueExecution();
     Ns.DropTables();
     Ns.DropNamespaces(DropDispositions.Complete);
 }
コード例 #24
0
ファイル: TestHql.cs プロジェクト: andysoftdev/ht4n
        public void DumpAndLoadData()
        {
            if (!HasHQL)
            {
                return;
            }

            var tempPath  = Path.GetTempPath();
            var filenames = new[] { tempPath + "DumpTest.txt", tempPath + "DumpTest.gz", "fs://DumpTest.txt", "fs://DumpTest.gz" };

            {
                Ns.Exec("DROP TABLE IF EXISTS fruit", "CREATE TABLE fruit (tag, description)");

                Ns.Exec(
                    "INSERT INTO fruit VALUES" + "(\"cantelope\", \"tag:good\", \"Had with breakfast\"),"
                    + "(\"2009-08-02 08:30:00\", \"cantelope\", \"description\", \"A cultivated variety of muskmelon with orange flesh\"),"
                    + "(\"banana\", \"tag:great\", \"Had with lunch\")");

                ValidateFruitTable("fruit");

                foreach (var filename in filenames)
                {
                    Ns.Exec(string.Format("DUMP TABLE fruit INTO FILE '{0}'", filename));

                    var fname = filename;
                    if (filename.StartsWith("fs:"))
                    {
                        fname = Path.Combine(
                            (string)Context.Properties["Hypertable.DataDirectory"],
                            "fs/local",
                            filename.Replace("fs://", ""));
                    }

                    Assert.IsTrue(File.Exists(fname));

                    Ns.Exec("DROP TABLE IF EXISTS fruit2", "CREATE TABLE fruit2 (tag, description)");
                    Ns.Exec(string.Format("LOAD DATA INFILE '{0}' INTO TABLE fruit2", filename));
                    ValidateFruitTable("fruit2");

                    File.Delete(fname);
                }

                foreach (var filename in filenames)
                {
                    Ns.Exec(string.Format("SELECT * FROM fruit DISPLAY_TIMESTAMPS INTO FILE '{0}'", filename));

                    var fname = filename;
                    if (filename.StartsWith("fs:"))
                    {
                        fname = Path.Combine(
                            (string)Context.Properties["Hypertable.DataDirectory"],
                            "fs/local",
                            filename.Replace("fs://", ""));
                    }

                    Assert.IsTrue(File.Exists(fname));

                    Ns.Exec("DROP TABLE IF EXISTS fruit2", "CREATE TABLE fruit2 (tag, description)");
                    Ns.Exec(string.Format("LOAD DATA INFILE '{0}' INTO TABLE fruit2", filename));
                    ValidateFruitTable("fruit2");

                    File.Delete(fname);
                }

                Ns.Exec("DROP TABLE fruit", "DROP TABLE fruit2");
            }

            {
                const string Schema = "<Schema><AccessGroup><ColumnFamily><Name>bin</Name></ColumnFamily></AccessGroup></Schema>";

                var rng = new Random();
                var buf = new byte[1024];
                var all = new byte[255];
                for (var i = 0; i < 255; ++i)
                {
                    all[i] = (byte)i;
                }

                var data = new Dictionary <string, byte[]>();

                var table = Ns.OpenTable("bin", Schema, OpenDispositions.CreateAlways);
                using (var mutator = table.CreateMutator())
                {
                    var key = new Key {
                        ColumnFamily = "bin"
                    };
                    for (var i = 0; i < 10000; ++i)
                    {
                        do
                        {
                            key.Row = Guid.NewGuid().ToString();
                        }while (data.ContainsKey(key.Row));

                        rng.NextBytes(buf);
                        mutator.Set(key, buf);

                        data.Add(key.Row, (byte[])buf.Clone());
                    }

                    do
                    {
                        key.Row = Guid.NewGuid().ToString();
                    }while (data.ContainsKey(key.Row));

                    mutator.Set(key, all);
                    data.Add(key.Row, (byte[])all.Clone());
                }

                foreach (var filename in filenames)
                {
                    Ns.Exec(string.Format("DUMP TABLE bin INTO FILE '{0}'", filename));

                    var fname = filename;
                    if (filename.StartsWith("fs:"))
                    {
                        fname = Path.Combine(
                            (string)Context.Properties["Hypertable.DataDirectory"],
                            "fs/local",
                            filename.Replace("fs://", ""));
                    }

                    Assert.IsTrue(File.Exists(fname));

                    Ns.Exec("DROP TABLE IF EXISTS bin2", "CREATE TABLE bin2 (bin)");
                    Ns.Exec(string.Format("LOAD DATA INFILE '{0}' INTO TABLE bin2", filename));

                    foreach (var cell in table.CreateScanner())
                    {
                        Assert.IsTrue(data.ContainsKey(cell.Key.Row));
                        Assert.IsTrue(data[cell.Key.Row].SequenceEqual(cell.Value));
                    }

                    File.Delete(fname);
                }

                Ns.Exec("DROP TABLE bin", "DROP TABLE bin2");
            }
        }
コード例 #25
0
        /// <summary>
        /// Calculates the added damping tensor by integrating over the level set of the particle.
        /// </summary>
        /// <param name="particle">
        /// The current particle.
        /// </param>
        /// <param name="levelSetTracker">
        /// The level set tracker.
        /// </param>
        /// <param name="fluidViscosity"></param>
        /// <param name="fluidDensity"></param>
        /// <param name="dt"></param>
        /// <param name="currentPosition"></param>
        /// <returns></returns>
        internal double[,] IntegrationOverLevelSet(Particle particle, LevelSetTracker levelSetTracker, double fluidViscosity, double fluidDensity, double dt, double[] currentPosition)
        {
            double[,] addedDampingTensor = new double[6, 6];
            double alpha         = 0.5;
            int    RequiredOrder = 2;

            for (int DampingTensorID = 0; DampingTensorID < 4; DampingTensorID++)
            {
                for (int d1 = 0; d1 < 3; d1++)
                {
                    for (int d2 = 0; d2 < 3; d2++)
                    {
                        void evalfD(int j0, int Len, NodeSet Ns, MultidimensionalArray result)
                        {
                            int K = result.GetLength(1);
                            MultidimensionalArray Normals       = levelSetTracker.DataHistories[0].Current.GetLevelSetNormals(Ns, j0, Len);
                            MultidimensionalArray NodeSetGlobal = Ns.CloneAs();

                            if (levelSetTracker.GridDat.SpatialDimension == 2)
                            {
                                for (int j = 0; j < Len; j++)
                                {
                                    for (int k = 0; k < K; k++)
                                    {
                                        levelSetTracker.GridDat.TransformLocal2Global(Ns, NodeSetGlobal, j0 + j);
                                        double   dh    = CalculateNormalMeshSpacing(levelSetTracker, Ns, Normals, j, k);
                                        double   delta = dh * Math.Sqrt(fluidDensity) / (Math.Sqrt(alpha * fluidViscosity * dt));
                                        double   dn    = dh / (1 - Math.Exp(-delta));
                                        double[] R     = new double[3];
                                        R[0] = NodeSetGlobal[k, 0] - currentPosition[0];
                                        R[1] = NodeSetGlobal[k, 1] - currentPosition[1];
                                        R[2] = 0;
                                        double[] NormalComponent = new double[3];
                                        double   test            = NodeSetGlobal[k, 0];
                                        double   test2           = NodeSetGlobal[k, 1];
                                        NormalComponent[0] = Normals[j, k, 0];
                                        NormalComponent[1] = Normals[j, k, 1];
                                        NormalComponent[2] = 0;
                                        switch (DampingTensorID)
                                        {
                                        case 0:    //D^{vv}
                                            result[j, k] = d1 == d2 ? (1 - NormalComponent[d1] * NormalComponent[d2]) * fluidViscosity / dn : -NormalComponent[d1] * NormalComponent[d2] * fluidViscosity / dn;
                                            break;

                                        case 1:    //D^{vw}
                                            if (d1 == 2 && d2 != 2)
                                            {
                                                result[j, k] = R[1 - d2] * Math.Pow(-1, d2) * fluidViscosity / dn;
                                            }
                                            else if (d1 != 2 && d2 == 2)
                                            {
                                                result[j, k] = ((1 - NormalComponent[d1] * NormalComponent[d1]) * (-R[1 - d1]) - NormalComponent[d1] * NormalComponent[1 - d1] * R[d1]) * Math.Pow(-1, d1) * fluidViscosity / dn;
                                            }
                                            else
                                            {
                                                result[j, k] = 0;
                                            }
                                            break;

                                        case 2:    //D^{wv}
                                            if (d2 == 2 && d1 != 2)
                                            {
                                                result[j, k] = R[1 - d1] * Math.Pow(-1, d1) * fluidViscosity / dn;
                                            }
                                            else if (d2 != 2 && d1 == 2)
                                            {
                                                result[j, k] = ((1 - NormalComponent[d2] * NormalComponent[d2]) * (-R[1 - d2]) - NormalComponent[d2] * NormalComponent[1 - d2] * R[d2]) * Math.Pow(-1, d2) * fluidViscosity / dn;
                                            }
                                            else
                                            {
                                                result[j, k] = 0;
                                            }
                                            break;

                                        case 3:    //D^{ww}
                                            if (d1 == d2 && d1 != 2)
                                            {
                                                result[j, k] = R[1 - d1].Pow2() * fluidViscosity / dn;
                                            }
                                            else if (d1 != d2 && d1 != 2 && d2 != 2)
                                            {
                                                result[j, k] = -R[0] * R[1] * fluidViscosity / dn;
                                            }
                                            else if (d1 == 2 && d2 == 2)
                                            {
                                                result[j, k] = (((1 - NormalComponent[0] * NormalComponent[0]) * R[1] + NormalComponent[0] * NormalComponent[1] * R[0]) * R[1] + ((1 - NormalComponent[1] * NormalComponent[1]) * R[0] + NormalComponent[0] * NormalComponent[1] * R[1]) * R[0]) * fluidViscosity / dn;
                                            }
                                            else
                                            {
                                                result[j, k] = 0;
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                throw new NotImplementedException("Currently the calculation of the Damping tensors is only available for 2D");
                            }
                        }

                        var SchemeHelper         = levelSetTracker.GetXDGSpaceMetrics(new[] { levelSetTracker.GetSpeciesId("A") }, RequiredOrder, 1).XQuadSchemeHelper;
                        CellQuadratureScheme cqs = SchemeHelper.GetLevelSetquadScheme(0, particle.CutCells_P(levelSetTracker));
                        CellQuadrature.GetQuadrature(new int[] { 1 }, levelSetTracker.GridDat,
                                                     cqs.Compile(levelSetTracker.GridDat, RequiredOrder),
                                                     delegate(int i0, int Length, QuadRule QR, MultidimensionalArray EvalResult) {
                            evalfD(i0, Length, QR.Nodes, EvalResult.ExtractSubArrayShallow(-1, -1, 0));
                        },
                                                     delegate(int i0, int Length, MultidimensionalArray ResultsOfIntegration) {
                            for (int l = 0; l < Length; l++)
                            {
                                switch (DampingTensorID)
                                {
                                case 0:
                                    addedDampingTensor[d1, d2] += ResultsOfIntegration[l, 0];
                                    break;

                                case 1:
                                    addedDampingTensor[d1, d2 + 3] += ResultsOfIntegration[l, 0];
                                    break;

                                case 2:
                                    addedDampingTensor[d1 + 3, d2] += ResultsOfIntegration[l, 0];
                                    break;

                                case 3:
                                    addedDampingTensor[d1 + 3, d2 + 3] += ResultsOfIntegration[l, 0];
                                    break;
                                }
                            }
                        }
                                                     ).Execute();
                    }
                }
            }
            if (levelSetTracker.GridDat.SpatialDimension == 2)
            {
                return(ModifyDampingTensor2D(addedDampingTensor));
            }
            else
            {
                throw new NotImplementedException("Currently the calculation of the Damping tensors is only available for 2D");
            }
        }
コード例 #26
0
        public void Render()
        {
            DropTables(this.regex);

            Assert.IsFalse(Ns.TableExists("test-1"));

            var schema = new TableSchema {
                AccessGroups = new List <AccessGroup>()
            };

            var accessGroup = new AccessGroup {
                Name = "default", ColumnFamilies = new List <ColumnFamily>()
            };

            accessGroup.ColumnFamilies.Add(new ColumnFamily {
                Name = "a"
            });
            accessGroup.ColumnFamilies.Add(new ColumnFamily {
                Name = "b", Options = new ColumnFamilyOptions {
                    MaxVersions = 5, MaxVersionsSpecified = true
                }
            });
            schema.AccessGroups.Add(accessGroup);

            accessGroup = new AccessGroup {
                Name = "other", ColumnFamilies = new List <ColumnFamily>()
            };
            accessGroup.ColumnFamilies.Add(new ColumnFamily {
                Name = "c"
            });
            schema.AccessGroups.Add(accessGroup);

            var xml = schema.ToString();

            schema = TableSchema.Parse(xml);
            Assert.IsNotNull(schema);
            Assert.IsFalse(schema.GenerationSpecified);

            Assert.IsNotNull(schema.AccessGroups);
            Assert.AreEqual(2, schema.AccessGroups.Count);

            accessGroup = schema.AccessGroups[0];
            Assert.AreEqual("default", accessGroup.Name);
            Assert.IsNotNull(accessGroup.ColumnFamilies);
            Assert.AreEqual(2, accessGroup.ColumnFamilies.Count);

            var columnFamily = accessGroup.ColumnFamilies[0];

            Assert.AreEqual("a", columnFamily.Name);

            columnFamily = accessGroup.ColumnFamilies[1];
            Assert.AreEqual("b", columnFamily.Name);
            Assert.IsNotNull(columnFamily.Options);
            Assert.IsTrue(columnFamily.Options.MaxVersionsSpecified);
            Assert.AreEqual(5, columnFamily.Options.MaxVersions);

            accessGroup = schema.AccessGroups[1];
            Assert.AreEqual("other", accessGroup.Name);
            Assert.IsNotNull(accessGroup.ColumnFamilies);
            Assert.AreEqual(1, accessGroup.ColumnFamilies.Count);

            columnFamily = accessGroup.ColumnFamilies[0];
            Assert.AreEqual("c", columnFamily.Name);

            Ns.CreateTable("test-1", xml);
            Assert.IsTrue(Ns.TableExists("test-1"));
        }
コード例 #27
0
ファイル: TestHql.cs プロジェクト: andysoftdev/ht4n
        public void Exec()
        {
            if (!HasHQL)
            {
                return;
            }

            try {
                Ns.Exec("this is not hql");
                Assert.Fail();
            }
            catch (HqlParseException) {
            }
            catch {
                Assert.Fail();
            }

            try {
                Ns.Exec("DROP TABLE table_does_not_exists");
                Assert.Fail();
            }
            catch (TableNotFoundException) {
            }
            catch {
                Assert.Fail();
            }

            Ns.Exec("DROP TABLE IF EXISTS table_does_not_exists");

            try {
                Ns.Exec("DROP NAMESPACE namespace_does_not_exists");
                Assert.Fail();
            }
            catch (NamespaceDoesNotExistsException) {
            }
            catch {
                Assert.Fail();
            }

            Ns.Exec("DROP NAMESPACE IF EXISTS namespace_does_not_exists");

            Ns.Exec("CREATE NAMESPACE abc");
            try {
                Ns.Exec("USE abc");
                Assert.Fail();
            }
            catch (BadNamespaceException) {
            }
            catch {
                Assert.Fail();
            }

            Ns.Exec("DROP NAMESPACE abc");
            Ns.Exec("CREATE TABLE t (a, description)");
            Ns.Exec("ALTER TABLE t ADD (e) RENAME COLUMN FAMILY (a, tag)");
            Ns.Exec("RENAME TABLE t TO fruit");
            Ns.Exec(
                "INSERT INTO fruit VALUES" + "(\"cantelope\", \"tag:good\", \"Had with breakfast\"),"
                + "(\"2009-08-02 08:30:00\", \"cantelope\", \"description\", \"A cultivated variety of muskmelon with orange flesh\"),"
                + "(\"banana\", \"tag:great\", \"Had with lunch\")");
            Ns.Exec("DELETE * FROM fruit WHERE ROW=\"banana\"", "DROP TABLE fruit"); // multiple commands
        }
コード例 #28
0
 public void zatvoriRegistracijaView(object o)
 {
     Ns.GoBack();
 }
コード例 #29
0
 /// <summary>
 /// Creates and opens a table in the 'test' namespace, drops existing table.
 /// </summary>
 /// <param name = "tableName">Table name.</param>
 /// <param name = "schema">Table xml schema.</param>
 /// <returns>Opened table.</returns>
 protected static ITable EnsureTable(string tableName, string schema)
 {
     return(Ns.OpenTable(tableName, schema, OpenDispositions.CreateAlways));
 }
コード例 #30
0
        public void ScanMultipleTableAsync()
        {
            if (!HasAsyncTableScanner)
            {
                return;
            }

            const int CountTables = 10;
            var       tables      = new List <ITable>();

            try {
                for (var t = 0; t < CountTables; ++t)
                {
                    var testTable = EnsureTable(string.Format("ScanMultipleTableAsync-{0}", t), Schema);
                    InitializeTableData(testTable);
                    tables.Add(testTable);
                }

                var c = 0;
                using (var asyncResult = new AsyncResult(
                           (ctx, cells) =>
                {
                    foreach (var cell in cells)
                    {
                        Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                        Interlocked.Increment(ref c);
                    }

                    return(AsyncCallbackResult.Continue);
                })) {
                    tables.ForEach(t => t.BeginScan(asyncResult, new ScanSpec().AddColumn("a")));
                    tables.ForEach(t => t.BeginScan(asyncResult, new ScanSpec().AddColumn("b")));
                    asyncResult.Join();
                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                    Assert.IsTrue(asyncResult.IsCompleted);
                }

                Assert.AreEqual(CountTables * (CountA + CountB), c);

                c = 0;
                using (var asyncResult = new AsyncResult()) {
                    tables.ForEach(
                        t => t.BeginScan(
                            asyncResult,
                            new ScanSpec().AddColumn("b"),
                            (ctx, cells) =>
                    {
                        foreach (var cell in cells)
                        {
                            Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                            Interlocked.Increment(ref c);
                        }

                        return(AsyncCallbackResult.Continue);
                    }));
                    tables.ForEach(
                        t => t.BeginScan(
                            asyncResult,
                            new ScanSpec().AddColumn("c"),
                            (ctx, cells) =>
                    {
                        foreach (var cell in cells)
                        {
                            Assert.IsFalse(string.IsNullOrEmpty(cell.Key.Row));
                            Interlocked.Increment(ref c);
                        }

                        return(AsyncCallbackResult.Continue);
                    }));
                    asyncResult.Join();
                    Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
                    Assert.IsTrue(asyncResult.IsCompleted);
                }

                Assert.AreEqual(CountTables * (CountB + CountC), c);
            }
            finally {
                tables.ForEach(t => t.Dispose());
                for (var t = 0; t < CountTables; ++t)
                {
                    Ns.DropTable(string.Format("ScanMultipleTableAsync-{0}", t), DropDispositions.IfExists);
                }
            }
        }
コード例 #31
0
 /// <summary>
 /// Drop tables from 'test' namespace.
 /// </summary>
 /// <param name = "regex">Table name regular expression.</param>
 protected static void DropTables(Regex regex)
 {
     Ns.DropTables(regex, DropDispositions.IfExists);
 }