Пример #1
0
        /// <summary>Create nodes that we use inside FemVisualization2d.nb and FemVisualization3d.nb</summary>
        public static void CreateNodes()
        {
            var nodes =                                                                 // 10 by 10 array of nodes on a regular lattice.
                        Enumerable.Range(0, 10).Select(row =>
                                                       Enumerable.Range(0, 10).Select(col =>
                                                                                      new double[] { -3.0 + col * (6.0 / 9), -3.0 + row * (6.0 / 9) }
                                                                                      ).ToArray()
                                                       ).ToArray();

            FWriter.SetDirAndFile("Seminar/Mathematica/", nameof(nodes), ".txt");
            FWriter.WriteLine(nodes);
            var nodesM =                                                                // Only the mid 2 by 2 = 4 nodes on a regular lattice.
                         nodes.Take(7).Skip(3).Select(col =>
                                                      col.Take(7).Skip(3)
                                                      .ToArray()
                                                      ).ToArray();

            FWriter.WriteLine(nodesM, nameof(nodesM));
            Rng.SetRange(-0.6, 0.6);                                          // Set RNG range.
            var nodesC =                                                      // Only corners of elements.
                         nodes.Where((row, i) => i % 3 == 0)
                         .Select(row =>
                                 row.Where((col, j) => j % 3 == 0).ToArray()
                                 ).ToArray();

            FWriter.WriteLine(nodesC, nameof(nodesC));
            var transNodesCM =                                                                 // C = element corner nodes (only nodes on corners of elements)
                               nodesC.Take(3).Skip(1).Select(row =>                            // Pick only those nodes that we will be moving. Take 2 inner rows (3,6).
                                                             row.Take(3).Skip(1).Select(col => // Take 2 inner nodes from each row (3,6).
                                                                                        col.Select(coord => coord + Rng.Dbl).ToArray()
                                                                                        ).ToArray()
                                                             ).ToArray();

            FWriter.WriteLine(transNodesCM, nameof(transNodesCM));
        }
Пример #2
0
        public override void OnFrameworkInitializationCompleted()
        {
            if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
            {
                desktop.MainWindow = new MainWindow();
                desktop.Startup   += (o, e) =>                     // args are either "UI [...]" or "".
                                     Task.Factory.StartNew(() => { // Run a console application the old way, parallel to the window.
                    try {
                        //#if DEBUG
                        //args = new string[] { "Tests", "Tests/bin/Debug/netcoreapp3.1/Tests.dll" };
                        //#endif

                        // Print build time info independently from Fluid APIs. Enables us to see if the program recompiled even if Fluid.IO.Toolbox is not working.
                        var buildDT = GetBuildDate(Assembly.GetExecutingAssembly());         // Extract build time from assembly.
                        var dti     = DateTimeFormatInfo.InvariantInfo;                      // Formatting info with which buildDT will be printed.
                        Console.WriteLine($"\nAssembly version: {buildDT.ToString(dti)}");
                        // Initialize Fluid APIs.
                        R("Toolbox initialized.");
                        if (e.Args != null && e.Args.Length > 1 && e.Args[1] == "Console")
                        {
                            R("Starting parallel Console app.");
                            int res = 0;
                            if (e.Args.Length > 2)
                            {
                                res = e.Args[2] switch {
                                    "Tests" => Tests.Entry.Point(e.Args),                    // There's a third argument that specifies entry point: "UI Console Tests".
                                    "CavityFlow" => Runnables.CavityFlow.Entry.Point(),
                                    "Fiddle" => Runnables.Fiddle.Entry.Point(),
                                    "Markdig" => Runnables.Markdig.Entry.Point(),
                                    _ => throw new ArgumentException("Misspelled input args.")
                                };
                            }
                            else
                            {
                                res = Runnables.Fiddle.Entry.Point();
                            }
                        }
                    }                                                                        // No third argument specifying the entry point: "UI Console" Start "Fiddle".
                    // else  ...   No further args means no parallel console app to run.
                    catch (Exception exc) {
                        Console.WriteLine($"Exception occured: {exc.Message}");
                        Console.WriteLine($"Stack trace:{exc.StackTrace}");
                        throw exc;
                    }
                    finally {
                        R("Exiting parallel console application.");
                        Reporter.WriteLine();
                        FWriter.Flush();
                    }
                });
            }

            base.OnFrameworkInitializationCompleted();
        }
Пример #3
0
        public static int StartConsoleApp(string[] args)
        {
            int res = 0;

            try {
                //#if DEBUG
                //args = new string[] { "Tests", "Tests/bin/Debug/netcoreapp3.1/Tests.dll" };
                //#endif

                // Print build time info independently from Fluid APIs. Enables us to see if the program recompiled even if Fluid.IO.Toolbox is not working.
                var buildDT = GetBuildDate(Assembly.GetExecutingAssembly());  // Extract build time from assembly.
                var dti     = DateTimeFormatInfo.InvariantInfo;               // Formatting info with which buildDT will be printed.
                Console.WriteLine($"\nAssembly version: {buildDT.ToString(dti)}");
                // Initialize Fluid APIs.
                R("Toolbox initialized. Starting pure console application.");
                if (args != null && args.Length > 0)
                {
                    res = args[0] switch {
                        "Tests" => Tests.Entry.Point(args),
                        "CavityFlow" => Runnables.CavityFlow.Entry.Point(),
                        "Fiddle" => Runnables.Fiddle.Entry.Point(),
                        "Markdig" => Runnables.Markdig.Entry.Point(),
                        _ => throw new ArgumentException("Misspelled input args.")
                    };
                }
                else
                {
                    res = Runnables.Fiddle.Entry.Point();
                }
            }
            catch (Exception exc) {
                Console.WriteLine($"Exception occured: {exc.Message}");
                Console.WriteLine($"Stack trace:{exc.StackTrace}");
                throw exc;
            }
            finally {
                R("Exiting parallel console application.");
                Reporter.WriteLine();
                FWriter.Flush();
            }
            return(res);
        }
Пример #4
0
        /// check if all placeholders have been replaced in the template; ignore IFDEF
        public Boolean CheckTemplateCompletion(StringBuilder s)
        {
            int    posPlaceholder = s.IndexOf("{#");
            string remainingTemplatePlaceholders = "";

            while (posPlaceholder > -1)
            {
                string latestPlaceholder = s.Substring(posPlaceholder + 2, s.IndexOf("}", posPlaceholder) - posPlaceholder - 2);
                remainingTemplatePlaceholders +=
                    latestPlaceholder + Environment.NewLine;
                posPlaceholder = s.IndexOf("{#", posPlaceholder + 2);
            }

            if (remainingTemplatePlaceholders.Length > 0)
            {
                if (FDestinationFile.Length > 0)
                {
                    StreamWriter FWriter;
                    FWriter = File.CreateText(FDestinationFile + ".error");
                    FWriter.Write(s.ToString());
                    FWriter.Close();

                    throw new Exception("The template has not completely been filled in. " +
                                        Environment.NewLine + "You are missing: " + Environment.NewLine +
                                        remainingTemplatePlaceholders + Environment.NewLine +
                                        "Check file " + FDestinationFile + ".error");
                }
                else
                {
                    TLogging.Log("Failure in this code: ");
                    TLogging.Log(s.ToString());

                    throw new Exception("The template has not completely been filled in. " +
                                        Environment.NewLine + "You are missing: " + Environment.NewLine +
                                        remainingTemplatePlaceholders);
                }
            }

            return(true);
        }
Пример #5
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));
        }
Пример #6
0
 static int Point()
 {
     R("Writing solution to file.");
     FWriter.SetDirAndFile("ChannelFlow/Results", "solution", ".txt");
     return(0);
 }