Files
wg_cpso/CPSO/Forms/92_Knowledge/FrmAnalysisResult.cs

172 lines
5.6 KiB
C#
Raw Normal View History

2026-03-25 18:20:24 +08:00
using CaeGlobals;
2026-03-26 06:50:22 +08:00
using CaeKnowledge;
2026-03-25 18:20:24 +08:00
using CaeKnowledge.View;
using CaeMesh;
using CaeResults;
2026-03-26 06:50:22 +08:00
using System;
2026-03-25 18:20:24 +08:00
using System.Collections.Generic;
using System.ComponentModel;
2026-03-26 06:50:22 +08:00
using System.IO;
using System.Linq;
2026-03-25 18:20:24 +08:00
using System.Windows.Forms;
namespace CPSO.Forms._92_Knowledge
{
public partial class FrmAnalysisResult : Form
{
public FrmAnalysisResult()
{
InitializeComponent();
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
}
private Controller _self;
public Controller Self { get { return _self; } }
public void PrepareForm(Controller self)
{
if (self != null)
{
_self = self;
toolStripComboBox1.Items.Clear();
2026-03-26 06:50:22 +08:00
toolStripComboBox1.Items.Add("None");
2026-03-25 18:20:24 +08:00
// 分析结果
2026-03-26 06:50:22 +08:00
foreach (string name in Self.AllResults.GetResultNames())
2026-03-25 18:20:24 +08:00
{
2026-03-26 06:50:22 +08:00
var result = Self.AllResults.GetResult(name);
2026-03-25 18:20:24 +08:00
2026-03-26 06:50:22 +08:00
if (result != null)
{
toolStripComboBox1.Items.Add(result.FileName);
}
2026-03-25 18:20:24 +08:00
}
2026-03-26 06:50:22 +08:00
toolStripComboBox1.SelectedIndex = 0;
2026-03-25 18:20:24 +08:00
}
}
private void toolStripButton1_Click(object sender, System.EventArgs e)
{
if (dataGridView1.DataSource is BindingList<ViewFeLog> list)
{
list.Clear();
2026-03-26 06:50:22 +08:00
if (toolStripComboBox1.SelectedIndex >= 0
&& toolStripComboBox1.SelectedItem is string resultName
&& File.Exists(resultName))
2026-03-25 18:20:24 +08:00
{
2026-03-26 06:50:22 +08:00
var results = LoadResult(resultName);
results.ForEach(x => list.Add(x));
2026-03-25 18:20:24 +08:00
}
else
{
2026-03-26 06:50:22 +08:00
MessageBox.Show($"没有指定已完成的分析结果,无法提取结果!",
"消息", MessageBoxButtons.OK, MessageBoxIcon.Error);
2026-03-25 18:20:24 +08:00
}
}
}
2026-03-26 06:50:22 +08:00
private List<ViewFeLog> LoadResult(string resultName)
2026-03-25 18:20:24 +08:00
{
if (resultName.IsNullOrEmptyOrWhiteSpace())
return null;
var list = new List<ViewFeLog>();
// 1. 分析结果文件
2026-03-26 06:50:22 +08:00
if (!_self.AllResults.ContainsResult(resultName))
2026-03-25 18:20:24 +08:00
{
FeResults results = FrdFileReader.Read(resultName);
_self.AllResults.Add(resultName, results);
}
2026-03-26 06:50:22 +08:00
// 2. 读取映射文件
string filePath = Path.GetDirectoryName(resultName);
string fileName = Path.GetFileNameWithoutExtension(resultName);
string fullPath = Path.Combine(filePath, $"{fileName}.st2");
2026-03-25 18:20:24 +08:00
2026-03-26 06:50:22 +08:00
var lines = File.ReadAllLines(fullPath, System.Text.Encoding.UTF8).ToList();
2026-03-25 18:20:24 +08:00
2026-03-26 06:50:22 +08:00
Dictionary<int, string> stepNames = new Dictionary<int, string>();
Dictionary<int, string> surfaceNames = new Dictionary<int, string>();
2026-03-25 18:20:24 +08:00
2026-03-26 06:50:22 +08:00
// 3. 解析每一行数据
foreach (var line in lines)
{
if (string.IsNullOrWhiteSpace(line)) continue; // 跳过空行
2026-03-25 18:20:24 +08:00
2026-03-26 06:50:22 +08:00
var parts = line.Split(',');
2026-03-25 18:20:24 +08:00
2026-03-26 06:50:22 +08:00
// 校验列数是否匹配(防止文件格式错误)
if (parts.Length != 3)
{
continue;
}
int id = int.Parse(parts[0]);
stepNames.Add(id, parts[1]);
surfaceNames.Add(id, parts[2]);
}
2026-03-25 18:20:24 +08:00
2026-03-26 06:50:22 +08:00
// 3. 物理场
FeResults fr = _self.AllResults.GetResult(resultName);
2026-03-25 18:20:24 +08:00
2026-03-26 06:50:22 +08:00
var allStepIds = fr.GetAllStepIds();
2026-03-25 18:20:24 +08:00
2026-03-26 06:50:22 +08:00
foreach (var stepId in allStepIds)
2026-03-25 18:20:24 +08:00
{
2026-03-26 06:50:22 +08:00
// 3.1 对应的曲面集
var stepName = stepNames[stepId];
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));
}
2026-03-25 18:20:24 +08:00
}
return list;
}
private void FrmAnalysisResult_Load(object sender, System.EventArgs e)
{
dataGridView1.Columns.Clear();
dataGridView1.DataSource = new BindingList<ViewFeLog>();
2026-03-26 06:50:22 +08:00
toolStripComboBox1.SelectedIndex = -1;
2026-03-25 18:20:24 +08:00
}
}
}