Skip to content

Commit 29d7ccf

Browse files
committed
Split long line and run cargo fmt
Still it does not work properly. See: * rust-lang/rustfmt#3391 * rust-lang/rustfmt#3863 * rust-lang/rustfmt#8
1 parent 13c58b5 commit 29d7ccf

File tree

4 files changed

+163
-89
lines changed

4 files changed

+163
-89
lines changed

src/geometry.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use tucanos::{
1010
};
1111
macro_rules! create_geometry {
1212
($name: ident, $dim: expr, $etype: ident, $mesh: ident, $geom: ident) => {
13-
#[doc = concat!("Piecewise linear geometry consisting of ", stringify!($etype), " in ", stringify!($dim), "D")]
13+
#[doc = concat!("Piecewise linear geometry consisting of ", stringify!($etype), " in ",
14+
stringify!($dim), "D")]
1415
#[pyclass]
1516
// #[derive(Clone)]
1617
pub struct $name {
@@ -22,11 +23,7 @@ macro_rules! create_geometry {
2223
#[new]
2324
#[must_use]
2425
#[pyo3(signature = (mesh, geom=None))]
25-
pub fn new(
26-
mesh: &$mesh,
27-
geom: Option<&$geom>,
28-
) -> Self {
29-
26+
pub fn new(mesh: &$mesh, geom: Option<&$geom>) -> Self {
3027
let mut gmesh = if let Some(geom) = geom {
3128
geom.mesh.clone()
3229
} else {
@@ -51,19 +48,23 @@ macro_rules! create_geometry {
5148
}
5249

5350
/// Compute the curvature
54-
pub fn compute_curvature(&mut self) {
55-
self.geom.compute_curvature()
51+
pub fn compute_curvature(&mut self) {
52+
self.geom.compute_curvature()
5653
}
5754

5855
/// Export the curvature to a vtk file
5956
pub fn write_curvature_vtk(&self, fname: &str) -> PyResult<()> {
60-
self.geom
57+
self.geom
6158
.write_curvature(fname)
6259
.map_err(|e| PyRuntimeError::new_err(e.to_string()))
6360
}
6461

6562
/// Project vertices
66-
pub fn project<'py>(&self, py: Python<'py>, mesh: &$mesh) -> PyResult<Bound<'py, PyArray2<f64>>> {
63+
pub fn project<'py>(
64+
&self,
65+
py: Python<'py>,
66+
mesh: &$mesh,
67+
) -> PyResult<Bound<'py, PyArray2<f64>>> {
6768
let vtags = mesh.mesh.get_vertex_tags().unwrap();
6869
let mut coords = Vec::with_capacity(mesh.mesh.n_verts() as usize * $dim);
6970

@@ -74,14 +75,10 @@ macro_rules! create_geometry {
7475
coords.extend(pt.iter().copied());
7576
}
7677

77-
Ok(to_numpy_2d(
78-
py,
79-
coords,
80-
$dim,
81-
))
78+
Ok(to_numpy_2d(py, coords, $dim))
8279
}
8380
}
84-
}
81+
};
8582
}
8683

8784
create_geometry!(LinearGeometry3d, 3, Triangle, Mesh33, Mesh32);

src/mesh.rs

+57-32
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ macro_rules! create_mesh {
6666
).collect();
6767

6868
let elems = elems.as_slice()?;
69-
let elems = elems.chunks($etype::N_VERTS as usize).map(|e| $etype::from_slice(e)).collect();
69+
let elems = elems.chunks($etype::N_VERTS as usize).map(
70+
|e| $etype::from_slice(e)).collect();
7071

7172
let faces = faces.as_slice()?;
72-
let faces = faces.chunks(<$etype as Elem>::Face::N_VERTS as usize).map(|e| <$etype as Elem>::Face::from_slice(e)).collect();
73+
let faces = faces.chunks(<$etype as Elem>::Face::N_VERTS as usize).map(
74+
|e| <$etype as Elem>::Face::from_slice(e)).collect();
7375

7476
Ok(Self {
7577
mesh: SimplexMesh::<$dim, $etype>::new(
@@ -99,7 +101,8 @@ macro_rules! create_mesh {
99101

100102
/// Write a solution to a .sol(b) file
101103
pub fn write_solb(&self, fname: &str, arr: PyReadonlyArray2<f64>) -> PyResult<()> {
102-
self.mesh.write_solb(&arr.to_vec().unwrap(), fname).map_err(|e| PyRuntimeError::new_err(e.to_string()))
104+
self.mesh.write_solb(&arr.to_vec().unwrap(), fname).map_err(
105+
|e| PyRuntimeError::new_err(e.to_string()))
103106
}
104107

105108

@@ -222,9 +225,11 @@ macro_rules! create_mesh {
222225
}
223226
}
224227

225-
/// Add the missing boundary faces and make sure that boundary faces are oriented outwards
228+
/// Add the missing boundary faces and make sure that boundary faces are oriented
229+
/// outwards.
226230
/// If internal faces are present, these are keps
227-
pub fn add_boundary_faces<'py>(&mut self, py: Python<'py>) -> PyResult<(Bound<'py, PyDict>, Bound<'py, PyDict>)> {
231+
pub fn add_boundary_faces<'py>(&mut self, py: Python<'py>) ->
232+
PyResult<(Bound<'py, PyDict>, Bound<'py, PyDict>)> {
228233
let (bdy, ifc) = self.mesh.add_boundary_faces();
229234
let dict_bdy = PyDict::new_bound(py);
230235
for (k, v) in bdy.iter() {
@@ -277,7 +282,9 @@ macro_rules! create_mesh {
277282
Ok(())
278283
}
279284

280-
#[doc = concat!("Get a copy of the mesh coordinates as a numpy array of shape (# of vertices, ", stringify!($dim), ")")]
285+
#[doc = concat!(
286+
"Get a copy of the mesh coordinates as a numpy array of shape (# of vertices, ",
287+
stringify!($dim), ")")]
281288
pub fn get_coords<'py>(&mut self, py: Python<'py>) -> Bound<'py, PyArray2<f64>> {
282289
let mut coords = Vec::with_capacity(self.mesh.n_verts() as usize * $dim);
283290
for v in self.mesh.verts() {
@@ -318,8 +325,11 @@ macro_rules! create_mesh {
318325
}
319326

320327
/// Reorder the vertices, element and faces using a Hilbert SFC
321-
pub fn reorder_hilbert<'py>(&mut self, py: Python<'py>) -> PyResult<(Bound<'py, PyArray1<Idx>>, Bound<'py, PyArray1<Idx>>, Bound<'py, PyArray1<Idx>>)>{
322-
let (new_vertex_indices, new_elem_indices, new_face_indices) = self.mesh.reorder_hilbert();
328+
pub fn reorder_hilbert<'py>(&mut self, py: Python<'py>) ->
329+
PyResult<(Bound<'py, PyArray1<Idx>>, Bound<'py, PyArray1<Idx>>,
330+
Bound<'py, PyArray1<Idx>>)>{
331+
let (new_vertex_indices, new_elem_indices, new_face_indices) =
332+
self.mesh.reorder_hilbert();
323333
Ok(
324334
(
325335
to_numpy_1d(py, new_vertex_indices),
@@ -330,8 +340,8 @@ macro_rules! create_mesh {
330340

331341
}
332342

333-
/// Convert a (scalar or vector) field defined at the element centers (P0) to a field defined at the vertices (P1)
334-
/// using a weighted average.
343+
/// Convert a (scalar or vector) field defined at the element centers (P0) to a field
344+
/// defined at the vertices (P1) using a weighted average.
335345
pub fn elem_data_to_vertex_data<'py>(
336346
&mut self,
337347
py: Python<'py>,
@@ -349,8 +359,8 @@ macro_rules! create_mesh {
349359
Ok(to_numpy_2d(py, res.unwrap(), arr.shape()[1]))
350360
}
351361

352-
/// Convert a field (scalar or vector) defined at the vertices (P1) to a field defined at the
353-
/// element centers (P0)
362+
/// Convert a field (scalar or vector) defined at the vertices (P1) to a field defined
363+
/// at the element centers (P0)
354364
pub fn vertex_data_to_elem_data<'py>(
355365
&mut self,
356366
py: Python<'py>,
@@ -363,7 +373,8 @@ macro_rules! create_mesh {
363373
Ok(to_numpy_2d(py, res.unwrap(), arr.shape()[1]))
364374
}
365375

366-
/// Interpolate a field (scalar or vector) defined at the vertices (P1) to a different mesh using linear interpolation
376+
/// Interpolate a field (scalar or vector) defined at the vertices (P1) to a different
377+
/// mesh using linear interpolation
367378
#[pyo3(signature = (other, arr, tol=None))]
368379
pub fn interpolate_linear<'py>(
369380
&mut self,
@@ -376,11 +387,13 @@ macro_rules! create_mesh {
376387
return Err(PyValueError::new_err("Invalid dimension 0"));
377388
}
378389
let tree = self.mesh.compute_elem_tree();
379-
let res = self.mesh.interpolate_linear(&tree, &other.mesh, arr.as_slice().unwrap(), tol);
390+
let res = self.mesh.interpolate_linear(&tree, &other.mesh, arr.as_slice().unwrap(),
391+
tol);
380392
Ok(to_numpy_2d(py, res.unwrap(), arr.shape()[1]))
381393
}
382394

383-
/// Interpolate a field (scalar or vector) defined at the vertices (P1) to a different mesh using nearest neighbor interpolation
395+
/// Interpolate a field (scalar or vector) defined at the vertices (P1) to a different
396+
/// mesh using nearest neighbor interpolation
384397
pub fn interpolate_nearest<'py>(
385398
&mut self,
386399
py: Python<'py>,
@@ -391,11 +404,13 @@ macro_rules! create_mesh {
391404
return Err(PyValueError::new_err("Invalid dimension 0"));
392405
}
393406
let tree = self.mesh.compute_vert_tree();
394-
let res = self.mesh.interpolate_nearest(&tree, &other.mesh, arr.as_slice().unwrap());
407+
let res = self.mesh.interpolate_nearest(&tree, &other.mesh,
408+
arr.as_slice().unwrap());
395409
Ok(to_numpy_2d(py, res.unwrap(), arr.shape()[1]))
396410
}
397411

398-
/// Smooth a field defined at the mesh vertices using a 1st order least-square approximation
412+
/// Smooth a field defined at the mesh vertices using a 1st order least-square
413+
/// approximation
399414
#[pyo3(signature = (arr, weight_exp=None))]
400415
pub fn smooth<'py>(
401416
&self,
@@ -419,7 +434,8 @@ macro_rules! create_mesh {
419434
Ok(to_numpy_2d(py, res.unwrap(), arr.shape()[1]))
420435
}
421436

422-
/// Compute the gradient of a field defined at the mesh vertices using a 1st order least-square approximation
437+
/// Compute the gradient of a field defined at the mesh vertices using a 1st order
438+
/// least-square approximation
423439
#[pyo3(signature = (arr, weight_exp=None))]
424440
pub fn compute_gradient<'py>(
425441
&self,
@@ -447,9 +463,10 @@ macro_rules! create_mesh {
447463
))
448464
}
449465

450-
/// Compute the hessian of a field defined at the mesh vertices using a 2nd order least-square approximation
451-
/// if `weight_exp` is `None`, the vertex has a weight 10, its first order neighbors have
452-
/// a weight 1 and the 2nd order neighbors (if used) have a weight of 0.1
466+
/// Compute the hessian of a field defined at the mesh vertices using a 2nd order
467+
/// least-square approximation
468+
/// if `weight_exp` is `None`, the vertex has a weight 10, its first order neighbors
469+
/// have a weight 1 and the 2nd order neighbors (if used) have a weight of 0.1
453470
#[pyo3(signature = (arr, weight_exp=None, use_second_order_neighbors=None))]
454471
pub fn compute_hessian<'py>(
455472
&self,
@@ -467,7 +484,8 @@ macro_rules! create_mesh {
467484

468485
let res = self
469486
.mesh
470-
.hessian(arr.as_slice().unwrap(), weight_exp, use_second_order_neighbors.unwrap_or(true));
487+
.hessian(arr.as_slice().unwrap(), weight_exp,
488+
use_second_order_neighbors.unwrap_or(true));
471489
if let Err(res) = res {
472490
return Err(PyRuntimeError::new_err(res.to_string()));
473491
}
@@ -530,7 +548,8 @@ macro_rules! create_mesh {
530548
}
531549

532550
/// Automatically tag the elements based on a feature angle
533-
pub fn autotag<'py>(&mut self, py: Python<'py>, angle_deg: f64) -> PyResult<Bound<'py, PyDict>> {
551+
pub fn autotag<'py>(&mut self, py: Python<'py>, angle_deg: f64)
552+
-> PyResult<Bound<'py, PyDict>> {
534553
let res = self.mesh.autotag(angle_deg);
535554
if let Err(res) = res {
536555
Err(PyRuntimeError::new_err(res.to_string()))
@@ -544,7 +563,8 @@ macro_rules! create_mesh {
544563
}
545564

546565
/// Automatically tag the faces based on a feature angle
547-
pub fn autotag_bdy<'py>(&mut self, py: Python<'py>, angle_deg: f64) -> PyResult<Bound<'py, PyDict>> {
566+
pub fn autotag_bdy<'py>(&mut self, py: Python<'py>, angle_deg: f64)
567+
-> PyResult<Bound<'py, PyDict>> {
548568
let res = self.mesh.autotag_bdy(angle_deg);
549569
if let Err(res) = res {
550570
Err(PyRuntimeError::new_err(res.to_string()))
@@ -572,7 +592,9 @@ impl Mesh33 {
572592
#[allow(clippy::too_many_arguments)]
573593
#[allow(clippy::too_many_lines)]
574594
#[classmethod]
575-
#[pyo3(signature = (coords, hexs=None, hex_tags=None, pris=None, pri_tags=None, pyrs=None, pyr_tags=None, tets=None, tet_tags=None, quas=None, qua_tags=None, tris=None, tri_tags=None))]
595+
#[pyo3(signature = (coords, hexs=None, hex_tags=None, pris=None, pri_tags=None, pyrs=None,
596+
pyr_tags=None, tets=None, tet_tags=None, quas=None, qua_tags=None, tris=None,
597+
tri_tags=None))]
576598
pub fn from_basic_elems(
577599
_cls: &Bound<'_, PyType>,
578600
coords: PyReadonlyArray2<f64>,
@@ -734,10 +756,11 @@ impl Mesh33 {
734756
}
735757

736758
/// Get a metric defined on all the mesh vertices such that
737-
/// - for boundary vertices, the principal directions are aligned with the principal curvature directions
738-
/// and the sizes to curvature radius ratio is r_h
759+
/// - for boundary vertices, the principal directions are aligned with the principal curvature
760+
/// directions and the sizes to curvature radius ratio is r_h
739761
/// - the metric is entended into the volume with gradation beta
740-
/// - if an implied metric is provided, the result is limited to (1/step,step) times the implied metric
762+
/// - if an implied metric is provided, the result is limited to (1/step,step) times the
763+
/// implied metric
741764
/// - if a normal size array is not provided, the minimum of the tangential sizes is used.
742765
#[allow(clippy::too_many_arguments)]
743766
#[pyo3(signature = (geom, r_h, beta, h_min=None, h_n=None, h_n_tags=None))]
@@ -786,7 +809,8 @@ impl Mesh32 {
786809
/// Create a Mesh32 from basic elements
787810
#[classmethod]
788811
#[allow(clippy::too_many_arguments)]
789-
#[pyo3(signature = (coords, quas=None, qua_tags=None, tris=None, tri_tags=None, edgs=None, edg_tags=None))]
812+
#[pyo3(signature = (coords, quas=None, qua_tags=None, tris=None, tri_tags=None, edgs=None,
813+
edg_tags=None))]
790814
pub fn from_basic_elems(
791815
_cls: &Bound<'_, PyType>,
792816
coords: PyReadonlyArray2<f64>,
@@ -895,7 +919,8 @@ impl Mesh22 {
895919
/// Create a Mesh22 from basic elements
896920
#[allow(clippy::too_many_arguments)]
897921
#[classmethod]
898-
#[pyo3(signature = (coords, quas=None, qua_tags=None, tris=None, tri_tags=None, edgs=None, edg_tags=None))]
922+
#[pyo3(signature = (coords, quas=None, qua_tags=None, tris=None, tri_tags=None, edgs=None,
923+
edg_tags=None))]
899924
pub fn from_basic_elems(
900925
_cls: &Bound<'_, PyType>,
901926
coords: PyReadonlyArray2<f64>,
@@ -993,8 +1018,8 @@ impl Mesh22 {
9931018
}
9941019

9951020
/// Get a metric defined on all the mesh vertices such that
996-
/// - for boundary vertices, the principal directions are aligned with the principal curvature directions
997-
/// and the sizes to curvature radius ratio is r_h
1021+
/// - for boundary vertices, the principal directions are aligned with the principal curvature
1022+
/// directions and the sizes to curvature radius ratio is r_h
9981023
/// - the metric is entended into the volume with gradation beta
9991024
/// - if a normal size array is not provided, the minimum of the tangential sizes is used.
10001025
#[allow(clippy::too_many_arguments)]

0 commit comments

Comments
 (0)