分析模块重新调整
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
using CaeGlobals;
|
||||
using CaeKnowledge;
|
||||
using CaeKnowledge.View;
|
||||
using CaeMesh;
|
||||
using CaeResults;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CPSO.Forms._92_Knowledge
|
||||
@@ -26,25 +30,28 @@ namespace CPSO.Forms._92_Knowledge
|
||||
|
||||
public Controller Self { get { return _self; } }
|
||||
|
||||
private Dictionary<string, string> _data = new Dictionary<string, string>();
|
||||
|
||||
public void PrepareForm(Controller self)
|
||||
{
|
||||
_data.Clear();
|
||||
|
||||
if (self != null)
|
||||
{
|
||||
_self = self;
|
||||
|
||||
toolStripComboBox1.Items.Clear();
|
||||
|
||||
// 分析结果
|
||||
foreach (var job in self.CompletedJobs)
|
||||
{
|
||||
toolStripComboBox1.Items.Add(job.JobName);
|
||||
toolStripComboBox1.Items.Add("None");
|
||||
|
||||
_data.Add(job.JobName, job.SurfaceName);
|
||||
// 分析结果
|
||||
foreach (string name in Self.AllResults.GetResultNames())
|
||||
{
|
||||
var result = Self.AllResults.GetResult(name);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
toolStripComboBox1.Items.Add(result.FileName);
|
||||
}
|
||||
}
|
||||
|
||||
toolStripComboBox1.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,92 +61,100 @@ namespace CPSO.Forms._92_Knowledge
|
||||
{
|
||||
list.Clear();
|
||||
|
||||
if (toolStripComboBox1.SelectedIndex >= 0)
|
||||
if (toolStripComboBox1.SelectedIndex >= 0
|
||||
&& toolStripComboBox1.SelectedItem is string resultName
|
||||
&& File.Exists(resultName))
|
||||
{
|
||||
var jobName = toolStripComboBox1.SelectedItem as string;
|
||||
var surfaceName = toolStripTextBox1.Text;
|
||||
|
||||
LoadJob(list, jobName, surfaceName);
|
||||
var results = LoadResult(resultName);
|
||||
|
||||
results.ForEach(x => list.Add(x));
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show($"没有选择指定作业Job,将提取全部结果!",
|
||||
"消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
foreach (var job in Self.CompletedJobs)
|
||||
{
|
||||
LoadJob(list, job.JobName, job.SurfaceName);
|
||||
}
|
||||
MessageBox.Show($"没有指定已完成的分析结果,无法提取结果!",
|
||||
"消息", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadJob(BindingList<ViewFeLog> list, string jobName, string surfaceName)
|
||||
private List<ViewFeLog> LoadResult(string resultName)
|
||||
{
|
||||
var job = Self.GetJob(jobName);
|
||||
var surface = Self.GetSurface(surfaceName);
|
||||
|
||||
// 读取结果文件
|
||||
if (job != null && job.Active && surface != null && surface.Active)
|
||||
{
|
||||
var loadJobs = LoadResult(jobName, surfaceName);
|
||||
|
||||
loadJobs.ForEach(x => list.Add(x));
|
||||
}
|
||||
}
|
||||
|
||||
private List<ViewFeLog> LoadResult(string jobName, string surfaceName)
|
||||
{
|
||||
var job = Self.Jobs[jobName];
|
||||
|
||||
var resultName = job.ResultsFileName; // 分析结果文件名
|
||||
|
||||
if (resultName.IsNullOrEmptyOrWhiteSpace())
|
||||
return null;
|
||||
|
||||
var list = new List<ViewFeLog>();
|
||||
|
||||
// 1. 分析结果文件
|
||||
if(!_self.AllResults.ContainsResult(resultName))
|
||||
if (!_self.AllResults.ContainsResult(resultName))
|
||||
{
|
||||
FeResults results = FrdFileReader.Read(resultName);
|
||||
|
||||
_self.AllResults.Add(resultName, results);
|
||||
}
|
||||
// 2. 读取映射文件
|
||||
string filePath = Path.GetDirectoryName(resultName);
|
||||
string fileName = Path.GetFileNameWithoutExtension(resultName);
|
||||
string fullPath = Path.Combine(filePath, $"{fileName}.st2");
|
||||
|
||||
FeResults fr = _self.AllResults.GetResult(resultName);
|
||||
var lines = File.ReadAllLines(fullPath, System.Text.Encoding.UTF8).ToList();
|
||||
|
||||
// 2. 对应的曲面集
|
||||
FeSurface surface = Self.GetSurface(surfaceName);
|
||||
Dictionary<int, string> stepNames = new Dictionary<int, string>();
|
||||
Dictionary<int, string> surfaceNames = new Dictionary<int, string>();
|
||||
|
||||
var nodeSet = Self.GetNodeSet(surface.NodeSetName); // 该曲面集对应的内部节点集合
|
||||
// 3. 解析每一行数据
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line)) continue; // 跳过空行
|
||||
|
||||
int[] labels = nodeSet.Labels; // 对应的节点
|
||||
var parts = line.Split(',');
|
||||
|
||||
// 校验列数是否匹配(防止文件格式错误)
|
||||
if (parts.Length != 3)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int id = int.Parse(parts[0]);
|
||||
stepNames.Add(id, parts[1]);
|
||||
surfaceNames.Add(id, parts[2]);
|
||||
}
|
||||
|
||||
// 3. 物理场
|
||||
var allFieldData = fr.GetAllFieldData();
|
||||
FeResults fr = _self.AllResults.GetResult(resultName);
|
||||
|
||||
// 3.1 位移场
|
||||
Field disp = fr.GetField(allFieldData[0]);
|
||||
var allStepIds = fr.GetAllStepIds();
|
||||
|
||||
var allValues = disp.GetComponentValues("ALL");
|
||||
var uValues = disp.GetComponentValues("U1");
|
||||
var vValues = disp.GetComponentValues("U2");
|
||||
var wValues = disp.GetComponentValues("U3");
|
||||
|
||||
foreach (var id in labels)
|
||||
foreach (var stepId in allStepIds)
|
||||
{
|
||||
var node = Self.GetNode(id);
|
||||
int index = id - 1;
|
||||
// 3.1 对应的曲面集
|
||||
var stepName = stepNames[stepId];
|
||||
|
||||
list.Add(new ViewFeLog(
|
||||
jobName, // 作业名称
|
||||
id, node.X, node.Y, node.Z, // 节点Id, x, y, z
|
||||
allValues[index], // 位移All, u, v, w
|
||||
uValues[index],
|
||||
vValues[index],
|
||||
wValues[index])
|
||||
);
|
||||
var surfaceName = surfaceNames[stepId];
|
||||
FeSurface surface = Self.GetSurface(surfaceName);
|
||||
|
||||
var nodeSet = Self.GetNodeSet(surface.NodeSetName); // 该曲面集对应的内部节点集合
|
||||
|
||||
int[] labels = nodeSet.Labels; // 对应的节点
|
||||
|
||||
// 3.2 提取出的位移值
|
||||
var dispAll = fr.GetField(fr.GetFieldData("DISP", "ALL", stepId, 1)).GetComponentValues("ALL");
|
||||
var dispU = fr.GetField(fr.GetFieldData("DISP", "U1", stepId, 1)).GetComponentValues("U1");
|
||||
var dispV = fr.GetField(fr.GetFieldData("DISP", "U2", stepId, 1)).GetComponentValues("U2");
|
||||
var dispW = fr.GetField(fr.GetFieldData("DISP", "U3", stepId, 1)).GetComponentValues("U3");
|
||||
|
||||
foreach ( var label in labels)
|
||||
{
|
||||
int index = label - 1;
|
||||
|
||||
var node = Self.GetNode(label);
|
||||
|
||||
double all = dispAll[index];
|
||||
double u = dispU[index];
|
||||
double v = dispV[index];
|
||||
double w = dispW[index];
|
||||
|
||||
list.Add(new ViewFeLog(stepId, stepName, node.Id, node.X, node.Y, node.Z, all, u, v, w));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
@@ -149,18 +164,8 @@ namespace CPSO.Forms._92_Knowledge
|
||||
{
|
||||
dataGridView1.Columns.Clear();
|
||||
dataGridView1.DataSource = new BindingList<ViewFeLog>();
|
||||
}
|
||||
|
||||
private void toolStripComboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
if (toolStripComboBox1.SelectedIndex >= 0)
|
||||
{
|
||||
toolStripTextBox1.Text = _data[toolStripComboBox1.SelectedItem as string];
|
||||
}
|
||||
else
|
||||
{
|
||||
toolStripTextBox1.Text = null;
|
||||
}
|
||||
toolStripComboBox1.SelectedIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user