Example #1
0
        [Fact] public void HierarchyInput()
        {
            FReader.SetDirAndFile("Tests", "hierToRead", ".txt");
            var hierWriteBack = FReader.ReadHierarchy <double>();
            var strw          = new StringWriter();

            strw.Write <dbl>(hierWriteBack);
            Assert.True(strw.ToString() == "{{9, 7}, {6, 3}, {5, 2}}");
            var array = hierWriteBack.ConvertToArray();

            if (array != null)
            {
                var result   = (double[][])array;
                var expected = new double[][] {
                    new double[] { 9, 7 },
                    new double[] { 6, 3 },
                    new double[] { 5, 2 }
                };
                Assert.True(result.Equals <dbl, DblA>(expected, 0.000001));
            }
            else
            {
                Assert.True(false, "Could not convert hierarchy to array.");
            }
        }
Example #2
0
        [Fact] public void HierarchyInput2()
        {
            FReader.SetDirAndFile("Tests", "hierToRead2", ".txt");
            var hierWriteBack = FReader.ReadHierarchy <double>();
            var array         = hierWriteBack.ConvertToArray();

            if (array != null)
            {
                var result   = (double[][][])array;
                var expected = new double[][][] {
                    new double[][] {
                        new double[] { 7, 3 },
                        new double[] { 0, 5 }
                    },
                    new double[][] {
                        new double[] { 3, 5 },
                        new double[] { 4, 2 },
                        new double[] { 8, 1 }
                    },
                    new double[][] {
                        new double[] { 11, 88 },
                        new double[] { 33, 56 },
                        new double[] { 96, 28 },
                        new double[] { 28, 51 }
                    }
                };
                Assert.True(result.Equals <dbl, DblA>(expected, 0.000001));
            }
            else
            {
                Assert.True(false, "Could not convert hierarchy to array.");
            }
        }
Example #3
0
        [Fact] public void ReadAndParseArray()
        {
            FReader.SetDirAndFile("Tests/", "array1d", ".txt");
            var inputArray  = (double[])FReader.ReadArray <double>();
            var actualArray = new double[] { 0, 7, 3, 8, 2, 4, 9, 11, 15 };

            Assert.True(inputArray.Equals <dbl, DblA>(actualArray, 0.000001));
        }
Example #4
0
        /// <summary>Once transformed nodes have been created, generate array combinations appropriate for Mathematica plotting.</summary>
        public static void CreateDerivedData()
        {
            FReader.SetDirAndFile("Seminar/Mathematica", "transNodesCM", ".txt");
            var transNodesCM = (double[][][])FReader.ReadArray <double>();

            FReader.SetFile("nodesC", ".txt");
            var nodesC       = (double[][][])FReader.ReadArray <double>();
            var transNodesC1 =                                                                                                        // Reassemble the rows (including static nodes).
                               transNodesCM.Select((row, i) =>                                                                        // Take the newly created array.
                                                   new double[][] { nodesC[i + 1][0] }.Concat(row).Append(nodesC[i + 1][3]).ToArray() // Attach a static node to the left and a static node to the right of each row.
                                                   ).ToArray();

            FWriter.SetDirAndFile("Seminar/Mathematica/", nameof(transNodesC1), ".txt");   // Have to set dir for the first time.
            FWriter.WriteLine(transNodesC1);
            var transNodesC = transNodesC1.Prepend(nodesC[0]).Append(nodesC[3]).ToArray(); // Reassemble the array (including filtered static rows).

            FWriter.WriteLine(transNodesC, nameof(transNodesC));
            var transNodesCByElms = Enumerable.Range(0, 3).Select(row =>                          // Groups of 4 corner nodes for each element.
                                                                  Enumerable.Range(0, 3).Select(col =>
                                                                                                new double[][] {
                (double[])transNodesC[row][col].Clone(),
                (double[])transNodesC[row][col + 1].Clone(),
                (double[])transNodesC[row + 1][col + 1].Clone(),
                (double[])transNodesC[row + 1][col].Clone()
            }
                                                                                                ).ToArray()
                                                                  ).ToArray();

            FWriter.WriteLine(transNodesCByElms, nameof(transNodesCByElms));
            var transNodesByElms = transNodesCByElms.Select(row =>
                                                            row.Select(elm =>
                                                                       new double[][][] {
                new double[][] { elm[0], TrueCoords(new double[] { -1.0 / 3, -1 }, elm), TrueCoords(new double[] { 1.0 / 3, -1 }, elm), elm[1] },
                new double[][] { TrueCoords(new double[] { -1, -1.0 / 3 }, elm), TrueCoords(new double[] { -1.0 / 3, -1.0 / 3 }, elm), TrueCoords(new double[] { 1.0 / 3, -1.0 / 3 }, elm), TrueCoords(new double[] { 1, -1.0 / 3 }, elm) },
                new double[][] { TrueCoords(new double[] { -1, 1.0 / 3 }, elm), TrueCoords(new double[] { -1.0 / 3, 1.0 / 3 }, elm), TrueCoords(new double[] { 1.0 / 3, 1.0 / 3 }, elm), TrueCoords(new double[] { 1, 1.0 / 3 }, elm) },
                new double[][] { elm[3], TrueCoords(new double[] { -1.0 / 3, 1 }, elm), TrueCoords(new double[] { 1.0 / 3, 1 }, elm), elm[2] }
            }
                                                                       ).ToArray()
                                                            ).ToArray();

            FWriter.WriteLine(transNodesByElms, nameof(transNodesByElms));
            var transNodes = Enumerable.Range(0, 10).Select(row =>            // Create an empty 10 by 10 array.
                                                            Enumerable.Range(0, 10).Select(col =>
                                                                                           new double[2] {
                0.0, 0.0
            }
                                                                                           ).ToArray()
                                                            ).ToArray();

            Enumerable.Range(0, 3).Select(i =>                              // This will fill the lower left part of the new array.
                                          Enumerable.Range(0, 3).Select(j =>
                                                                        Enumerable.Range(0, 3).Select(k =>
                                                                                                      Enumerable.Range(0, 3).Select(m =>
                                                                                                                                    transNodes[3 * i + k][3 * j + m] = (double[])transNodesByElms[i][j][k][m].Clone()
                                                                                                                                    ).ToArray()
                                                                                                      ).ToArray()
                                                                        ).ToArray()
                                          ).ToArray();
            Enumerable.Range(0, 3).Select(i =>                                 // Over 3 elements in last row.
                                          Enumerable.Range(0, 3).Select(j => { // Over 3 nodes in last row of each element.
                transNodes[9][3 * i + j] = transNodesByElms[2][i][3][j];       // Add the upper most row.
                transNodes[3 * i + j][9] = transNodesByElms[i][2][j][3];       // Add the right most col.
                return(j);
            }).ToArray()
                                          ).ToArray();
            transNodes[9][9] = transNodesByElms[2][2][3][3];                  // Assign the last corner element.
            FWriter.WriteLine(transNodes, nameof(transNodes));
            var transNodesM =
                transNodes.Where((row, i) => i > 2 && i < 7)    // Take only middle nodes.
                .Select(row =>
                        row.Where((col, j) => j > 2 && j < 7)
                        .ToArray()
                        ).ToArray();

            FWriter.WriteLine(transNodesM, nameof(transNodesM));
            FReader.SetFile("nodes", ".txt");
            var nodes    = (double[][][])FReader.ReadArray <double>();
            var nodes3dF =
                nodes.Select(row =>
                             row.Select(col =>
                                        col.Append(0.0).ToArray()
                                        ).ToArray()
                             ).ToArray();

            FWriter.WriteLine(nodes3dF, nameof(nodes3dF));
            var transNodes3dF =
                transNodes.Select(row =>
                                  row.Select(col =>
                                             col.Append(0.0).ToArray()
                                             ).ToArray()
                                  ).ToArray();

            FWriter.WriteLine(transNodes3dF, nameof(transNodes3dF));
            var nodes3dMF =
                nodes.Take(7).Skip(3).Select(row =>
                                             row.Take(7).Skip(3).Select(col =>
                                                                        col.Append(0.0).ToArray()
                                                                        ).ToArray()
                                             ).ToArray();

            FWriter.WriteLine(nodes3dMF, nameof(nodes3dMF));
            var nodes3dMT =
                nodes.Take(7).Skip(3).Select(row =>
                                             row.Take(7).Skip(3).Select(col =>
                                                                        col.Append(1.0).ToArray()
                                                                        ).ToArray()
                                             ).ToArray();

            FWriter.WriteLine(nodes3dMT, nameof(nodes3dMT));
            var transNodes3dMF =
                transNodesM.Select(row =>
                                   row.Select(col =>
                                              col.Append(0.0).ToArray()
                                              ).ToArray()
                                   ).ToArray();

            FWriter.WriteLine(transNodes3dMF, nameof(transNodes3dMF));
            var transNodes3dMT =
                transNodesM.Select(row =>
                                   row.Select(col =>
                                              col.Append(1.0).ToArray()
                                              ).ToArray()
                                   ).ToArray();

            FWriter.WriteLine(transNodes3dMT, nameof(transNodes3dMT));
        }