138 lines
3.8 KiB
Rust
138 lines
3.8 KiB
Rust
use femm_doc_elec::FemmDoc;
|
|
|
|
const FIXTURE: &str = r#"[Format] = 1
|
|
[Precision] = 1e-08
|
|
[MinAngle] = 30
|
|
[DoSmartMesh] = 1
|
|
[Depth] = 1
|
|
[LengthUnits] = millimeters
|
|
[ProblemType] = planar
|
|
[Coordinates] = cartesian
|
|
[Comment] = "parallel-plate capacitor"
|
|
[PointProps] = 1
|
|
<BeginPoint>
|
|
<PointName> = "V=0"
|
|
<Vp> = 0
|
|
<qp> = 0
|
|
<EndPoint>
|
|
[BdryProps] = 1
|
|
<BeginBdry>
|
|
<BdryName> = "outer"
|
|
<BdryType> = 0
|
|
<Vs> = 0
|
|
<qs> = 0
|
|
<c0> = 0
|
|
<c1> = 0
|
|
<EndBdry>
|
|
[BlockProps] = 2
|
|
<BeginBlock>
|
|
<BlockName> = "Air"
|
|
<ex> = 1
|
|
<ey> = 1
|
|
<qv> = 0
|
|
<EndBlock>
|
|
<BeginBlock>
|
|
<BlockName> = "Dielectric"
|
|
<ex> = 4.2
|
|
<ey> = 4.2
|
|
<qv> = 0
|
|
<EndBlock>
|
|
[ConductorProps] = 2
|
|
<BeginConductor>
|
|
<ConductorName> = "Plate+"
|
|
<Vc> = 100
|
|
<qc> = 0
|
|
<ConductorType> = 1
|
|
<EndConductor>
|
|
<BeginConductor>
|
|
<ConductorName> = "Plate-"
|
|
<Vc> = 0
|
|
<qc> = 0
|
|
<ConductorType> = 1
|
|
<EndConductor>
|
|
[NumPoints] = 4
|
|
0 0 1 0 1
|
|
10 0 0 0 0
|
|
10 10 0 0 2
|
|
0 10 0 0 0
|
|
[NumSegments] = 4
|
|
0 1 -1 1 0 0 0
|
|
1 2 -1 1 0 0 0
|
|
2 3 -1 1 0 0 0
|
|
3 0 -1 1 0 0 0
|
|
[NumArcSegments] = 0
|
|
[NumHoles] = 0
|
|
[NumBlockLabels] = 1
|
|
5 5 2 0.1 0 0
|
|
"#;
|
|
|
|
#[test]
|
|
fn parses_fixture_geometry() {
|
|
let doc = FemmDoc::parse(FIXTURE).expect("parse");
|
|
assert_eq!(doc.nodes.len(), 4);
|
|
assert_eq!(doc.segments.len(), 4);
|
|
assert_eq!(doc.arcs.len(), 0);
|
|
assert_eq!(doc.block_labels.len(), 1);
|
|
assert_eq!(doc.materials.len(), 2);
|
|
assert_eq!(doc.boundaries.len(), 1);
|
|
assert_eq!(doc.points.len(), 1);
|
|
assert_eq!(doc.conductors.len(), 2);
|
|
|
|
assert_eq!(doc.nodes[0].boundary_marker, "V=0");
|
|
assert_eq!(doc.nodes[0].in_conductor, "Plate+");
|
|
assert_eq!(doc.nodes[2].in_conductor, "Plate-");
|
|
|
|
assert_eq!(doc.segments[0].boundary_marker, "outer");
|
|
assert_eq!(doc.block_labels[0].block_type, "Dielectric");
|
|
assert_eq!(doc.block_labels[0].in_conductor, "<None>");
|
|
assert_eq!(doc.conductors[0].vc, 100.0);
|
|
assert_eq!(doc.conductors[0].conductor_type, 1);
|
|
assert_eq!(doc.materials[1].ex, 4.2);
|
|
assert_eq!(doc.comment, "parallel-plate capacitor");
|
|
}
|
|
|
|
#[test]
|
|
fn round_trips_parse_write_parse() {
|
|
let a = FemmDoc::parse(FIXTURE).expect("parse a");
|
|
let text = a.write();
|
|
let b = FemmDoc::parse(&text).expect("parse b");
|
|
|
|
assert_eq!(a.precision, b.precision);
|
|
assert_eq!(a.depth, b.depth);
|
|
assert_eq!(a.nodes.len(), b.nodes.len());
|
|
assert_eq!(a.segments.len(), b.segments.len());
|
|
assert_eq!(a.materials.len(), b.materials.len());
|
|
assert_eq!(a.conductors.len(), b.conductors.len());
|
|
assert_eq!(a.points.len(), b.points.len());
|
|
assert_eq!(a.boundaries.len(), b.boundaries.len());
|
|
|
|
for (x, y) in a.nodes.iter().zip(b.nodes.iter()) {
|
|
assert!((x.x - y.x).abs() < 1e-12);
|
|
assert!((x.y - y.y).abs() < 1e-12);
|
|
assert_eq!(x.boundary_marker, y.boundary_marker);
|
|
assert_eq!(x.in_conductor, y.in_conductor);
|
|
}
|
|
for (x, y) in a.segments.iter().zip(b.segments.iter()) {
|
|
assert_eq!(x.n0, y.n0);
|
|
assert_eq!(x.n1, y.n1);
|
|
assert_eq!(x.boundary_marker, y.boundary_marker);
|
|
assert_eq!(x.in_conductor, y.in_conductor);
|
|
}
|
|
for (x, y) in a.materials.iter().zip(b.materials.iter()) {
|
|
assert_eq!(x.name, y.name);
|
|
assert!((x.ex - y.ex).abs() < 1e-12);
|
|
assert!((x.ey - y.ey).abs() < 1e-12);
|
|
}
|
|
for (x, y) in a.conductors.iter().zip(b.conductors.iter()) {
|
|
assert_eq!(x.name, y.name);
|
|
assert!((x.vc - y.vc).abs() < 1e-12);
|
|
assert_eq!(x.conductor_type, y.conductor_type);
|
|
}
|
|
assert_eq!(a.block_labels.len(), b.block_labels.len());
|
|
let la = &a.block_labels[0];
|
|
let lb = &b.block_labels[0];
|
|
assert!((la.x - lb.x).abs() < 1e-12);
|
|
assert_eq!(la.block_type, lb.block_type);
|
|
assert!((la.max_area - lb.max_area).abs() < 1e-10);
|
|
}
|