Skip to content

Commit 1b8ae1e

Browse files
committed
Remove TryVertexFromMshNode trait
1 parent b72172b commit 1b8ae1e

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

src/io/msh.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::mesh::Mesh;
33
use eyre::{eyre, Context};
44
use log::warn;
55
use nalgebra::allocator::Allocator;
6-
use nalgebra::{DefaultAllocator, DimName, OPoint, Point2, Point3, RealField, U2, U3};
6+
use nalgebra::{DefaultAllocator, DimName, OPoint, RealField};
77
use std::path::Path;
88

99
/// Loads a [`Mesh`] from a Gmsh MSH file at the given path.
@@ -12,7 +12,6 @@ where
1212
T: RealField,
1313
D: DimName,
1414
C: MshConnectivity,
15-
OPoint<T, D>: TryVertexFromMshNode<T, D, f64>,
1615
DefaultAllocator: Allocator<T, D>,
1716
{
1817
let msh_bytes = std::fs::read(file_path).wrap_err("failed to read file")?;
@@ -25,7 +24,6 @@ where
2524
T: RealField,
2625
D: DimName,
2726
C: MshConnectivity,
28-
OPoint<T, D>: TryVertexFromMshNode<T, D, f64>,
2927
DefaultAllocator: Allocator<T, D>,
3028
{
3129
let mut msh_file = mshio::parse_msh_bytes(bytes).map_err(|e| eyre!("failed to parse msh file: {}", e))?;
@@ -79,7 +77,6 @@ where
7977
D: DimName,
8078
F: mshio::MshFloatT,
8179
I: mshio::MshIntT,
82-
OPoint<T, D>: TryVertexFromMshNode<T, D, F>,
8380
DefaultAllocator: Allocator<T, D>,
8481
{
8582
// Ensure that node tags are consecutive
@@ -103,7 +100,7 @@ where
103100

104101
// Convert MSH vertices to points
105102
for node in &node_block.nodes {
106-
vertices.push(OPoint::try_vertex_from_msh_node(node)?);
103+
vertices.push(point_from_msh_node(node)?);
107104
}
108105

109106
Ok(vertices)
@@ -154,17 +151,6 @@ where
154151
== C::reference_dim()
155152
}
156153

157-
/// Allows conversion from `mshio::Node`s to `OPoint`s which are used as vertices in `fenris`.
158-
pub trait TryVertexFromMshNode<T, D, F>
159-
where
160-
T: RealField,
161-
D: DimName,
162-
F: mshio::MshFloatT,
163-
DefaultAllocator: Allocator<T, D>,
164-
{
165-
fn try_vertex_from_msh_node(node: &mshio::Node<F>) -> eyre::Result<OPoint<T, D>>;
166-
}
167-
168154
macro_rules! f_to_t {
169155
($component:expr) => {
170156
T::from_f64(
@@ -176,25 +162,24 @@ macro_rules! f_to_t {
176162
};
177163
}
178164

179-
impl<T, F> TryVertexFromMshNode<T, U2, F> for Point2<T>
165+
fn point_from_msh_node<T, D, F>(node: &mshio::Node<F>) -> eyre::Result<OPoint<T, D>>
180166
where
181167
T: RealField,
168+
D: DimName,
182169
F: mshio::MshFloatT,
170+
DefaultAllocator: Allocator<T, D>,
183171
{
184-
fn try_vertex_from_msh_node(node: &mshio::Node<F>) -> eyre::Result<Self> {
185-
// TODO: Ensure that node.z is zero?
186-
Ok(Self::new(f_to_t!(node.x), f_to_t!(node.y)))
172+
// TODO: Ensure that components i < D are zero?
173+
let mut point = OPoint::origin();
174+
point[0] = f_to_t!(node.x);
175+
if D::dim() > 1 {
176+
point[1] = f_to_t!(node.y);
187177
}
188-
}
189-
190-
impl<T, F> TryVertexFromMshNode<T, U3, F> for Point3<T>
191-
where
192-
T: RealField,
193-
F: mshio::MshFloatT,
194-
{
195-
fn try_vertex_from_msh_node(node: &mshio::Node<F>) -> eyre::Result<Self> {
196-
Ok(Self::new(f_to_t!(node.x), f_to_t!(node.y), f_to_t!(node.z)))
178+
if D::dim() > 2 {
179+
point[2] = f_to_t!(node.z);
197180
}
181+
182+
Ok(point)
198183
}
199184

200185
/// Allows conversion from `mshio::Element`s to connectivity types used in `fenris`.
@@ -267,7 +252,7 @@ impl MshConnectivity for Tet4Connectivity {
267252

268253
#[cfg(test)]
269254
mod msh_tests {
270-
use crate::connectivity::{Tet4Connectivity, Tri3d2Connectivity, Tri3d3Connectivity};
255+
use crate::connectivity::{Tet4Connectivity, Tri3d2Connectivity};
271256
use crate::io::msh::load_msh_from_file;
272257
use nalgebra::{U2, U3};
273258

0 commit comments

Comments
 (0)