136 lines
4.8 KiB
C#
136 lines
4.8 KiB
C#
|
|
using Apache.Arrow;
|
|||
|
|
using Apache.Arrow.Ipc;
|
|||
|
|
using Apache.Arrow.Memory;
|
|||
|
|
using CaeModel;
|
|||
|
|
using System;
|
|||
|
|
using System.Diagnostics;
|
|||
|
|
using System.Globalization;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|||
|
|
using Microsoft.Data.Analysis;
|
|||
|
|
|
|||
|
|
namespace ConsoleAppTest
|
|||
|
|
{
|
|||
|
|
internal class Program
|
|||
|
|
{
|
|||
|
|
static void Test1()
|
|||
|
|
{
|
|||
|
|
// 目前单位存在问题
|
|||
|
|
CultureInfo.CurrentCulture = new CultureInfo("en-US");
|
|||
|
|
|
|||
|
|
var dat = @"D:\WanNeng\01.dat";
|
|||
|
|
using (FileStream fs = new FileStream(dat,FileMode.Open))
|
|||
|
|
{
|
|||
|
|
BinaryFormatter formatter = new BinaryFormatter();
|
|||
|
|
var fem = (FeModel)formatter.Deserialize(fs);
|
|||
|
|
|
|||
|
|
foreach (var p in fem.Mesh.ElementSets)
|
|||
|
|
{
|
|||
|
|
var set = p.Value;
|
|||
|
|
|
|||
|
|
Console.WriteLine(set.Name + @" => " + set.Count);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static void Test2()
|
|||
|
|
{
|
|||
|
|
var memoryAllocator = new NativeMemoryAllocator(alignment: 64);
|
|||
|
|
|
|||
|
|
// Build a record batch using the Fluent API
|
|||
|
|
var recordBatch = new RecordBatch.Builder(memoryAllocator)
|
|||
|
|
.Append("Column A", false, col => col.Int32(array => array.AppendRange(Enumerable.Range(0, 10))))
|
|||
|
|
.Append("Column B", false, col => col.Float(array => array.AppendRange(Enumerable.Range(0, 10).Select(x => Convert.ToSingle(x * 0.2)))))
|
|||
|
|
.Append("Column C", false, col => col.String(array => array.AppendRange(Enumerable.Range(0, 10).Select(x => $"Item {x+1}"))))
|
|||
|
|
.Append("Column D", false, col => col.Boolean(array => array.AppendRange(Enumerable.Range(0, 10).Select(x => x % 2 == 0))))
|
|||
|
|
.Build();
|
|||
|
|
|
|||
|
|
// Print memory allocation statistics
|
|||
|
|
Console.WriteLine(@"Allocations: {0}", memoryAllocator.Statistics.Allocations);
|
|||
|
|
Console.WriteLine(@"Allocated: {0} byte(s)", memoryAllocator.Statistics.BytesAllocated);
|
|||
|
|
|
|||
|
|
// Write record batch to a file
|
|||
|
|
|
|||
|
|
using (var stream = File.OpenWrite("test.arrow"))
|
|||
|
|
using (var writer = new ArrowFileWriter(stream, recordBatch.Schema))
|
|||
|
|
{
|
|||
|
|
writer.WriteRecordBatch(recordBatch);
|
|||
|
|
writer.WriteEnd();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Console.WriteLine(@"Done");
|
|||
|
|
Console.ReadKey();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static void Test3()
|
|||
|
|
{
|
|||
|
|
using (var stream = File.OpenRead(@"D:\WorkSpace\deformed_domain.arrow"))
|
|||
|
|
using (var reader = new ArrowFileReader(stream))
|
|||
|
|
{
|
|||
|
|
var dataframe = DataFrame.FromArrowRecordBatch(reader.ReadNextRecordBatch());
|
|||
|
|
|
|||
|
|
foreach (var row in dataframe.Rows)
|
|||
|
|
{
|
|||
|
|
Console.WriteLine($@"{row["Id"]}, {row["X"]}, {row["Y"]},{row["Z"]}");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static void Test4()
|
|||
|
|
{
|
|||
|
|
using (var stream = File.OpenRead(@"D:\WorkSpace\deformed_mesh.arrow"))
|
|||
|
|
using (var reader = new ArrowFileReader(stream))
|
|||
|
|
{
|
|||
|
|
var dataframe = DataFrame.FromArrowRecordBatch(reader.ReadNextRecordBatch());
|
|||
|
|
|
|||
|
|
foreach (var row in dataframe.Rows)
|
|||
|
|
{
|
|||
|
|
Console.WriteLine($@"{row["id"]}, {row["dx"]}, {row["dy"]}, {row["dz"]}");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static void Test5()
|
|||
|
|
{
|
|||
|
|
// Set working directory and create process
|
|||
|
|
var workingDirectory = Path.GetFullPath("Scripts");
|
|||
|
|
var process = new Process
|
|||
|
|
{
|
|||
|
|
StartInfo = new ProcessStartInfo
|
|||
|
|
{
|
|||
|
|
FileName = "cmd.exe",
|
|||
|
|
RedirectStandardInput = true,
|
|||
|
|
UseShellExecute = false,
|
|||
|
|
RedirectStandardOutput = true,
|
|||
|
|
WorkingDirectory = workingDirectory
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
process.Start();
|
|||
|
|
// Pass multiple commands to cmd.exe
|
|||
|
|
using (var sw = process.StandardInput)
|
|||
|
|
{
|
|||
|
|
if (sw.BaseStream.CanWrite)
|
|||
|
|
{
|
|||
|
|
// Vital to activate Anaconda
|
|||
|
|
sw.WriteLine(@"J:\Users\Luke\miniconda3\Scripts\activate.bat");
|
|||
|
|
// Activate your environment
|
|||
|
|
sw.WriteLine("activate your-environment");
|
|||
|
|
// run your script. You can also pass in arguments
|
|||
|
|
sw.WriteLine(@"python YourScript.py");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
// read multiple output lines
|
|||
|
|
while (!process.StandardOutput.EndOfStream)
|
|||
|
|
{
|
|||
|
|
var line = process.StandardOutput.ReadLine();
|
|||
|
|
Console.WriteLine(line);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
static void Main(string[] args)
|
|||
|
|
{
|
|||
|
|
Test5();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|