-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsimulation-handler.ts
More file actions
73 lines (64 loc) · 2.1 KB
/
Copy pathsimulation-handler.ts
File metadata and controls
73 lines (64 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: AGPL-3.0-or-later
/**
* Simulation Result Artifact Handler
*
* Handles FEA (Finite Element Analysis) and CFD (Computational Fluid Dynamics)
* result files. Supports VTK XML formats (.vtu, .vtp, .vtk).
*
* At publish time, extracts mesh statistics and field metadata.
* For web viewing, provides a viewer descriptor that maps to
* the SimulationResultViewer frontend component.
*/
import type { ArtifactHandler, ArtifactMetadata, ArtifactViewDescriptor } from "./registry.js";
export interface SimulationFieldMeta {
name: string;
association: "point" | "cell";
numComponents: number;
range: [number, number];
unit?: string;
}
export interface SimulationDetails {
format: string;
meshType?: string;
numPoints?: number;
numCells?: number;
bounds?: [number, number, number, number, number, number];
fields?: SimulationFieldMeta[];
solverInfo?: {
name: string;
version?: string;
};
}
export class SimulationArtifactHandler implements ArtifactHandler {
readonly type = "simulation";
readonly displayName = "Simulation Results (FEA/CFD)";
readonly extensions = [".vtu", ".vtp", ".vtk"];
async extractMetadata(_fileBuffer: Buffer, filePath: string): Promise<ArtifactMetadata | null> {
// Basic metadata from file extension
const ext = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
const formatMap: Record<string, string> = {
".vtu": "VTK XML Unstructured Grid",
".vtp": "VTK XML PolyData",
".vtk": "VTK Legacy",
};
return {
type: this.type,
path: filePath,
description: `Simulation result (${formatMap[ext] || "VTK"})`,
details: { format: ext } as Record<string, unknown>,
};
}
validate(artifact: Record<string, unknown>): string[] {
const errors: string[] = [];
if (!artifact.path) errors.push("Missing artifact path");
return errors;
}
getViewDescriptor(metadata: ArtifactMetadata): ArtifactViewDescriptor | null {
return {
viewer: "simulation-result",
label: "3D Results Viewer",
icon: "flame",
config: { ...metadata.details },
};
}
}