Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixnum #30

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,41 @@ struct Args {
/// Name of the output file.
#[arg(short, long)]
output: String,

/// Number of voxels in the x-direction.
#[arg(long, default_value_t = 0)]
nelx: usize,

/// Number of voxels in the y-direction.
#[arg(long, default_value_t = 0)]
nely: usize,

/// Number of voxels in the z-direction.
#[arg(long, default_value_t = 0)]
nelz: usize,
}

fn main() {
let args = Args::parse();
let input = if args.input.ends_with(".npy") {
Spn::from_npy(&args.input)
} else if args.input.ends_with(".spn") {
if args.nelx < 1 {
panic!("Need to specify nelx > 0.")
} else if args.nely < 1 {
panic!("Need to specify nely > 0.")
} else if args.nelz < 1 {
panic!("Need to specify nelz > 0.")
} else {
Spn::new(&args.input, args.nelx, args.nely, args.nelz)
}
} else {
panic!("Invalid input {} specified.", args.input)
panic!("Invalid input ({}) specified.", args.input)
};
let output = if args.output.ends_with(".exo") {
input.into_exodus()
} else {
panic!("Invalid output {} specified.", args.output)
panic!("Invalid output ({}) specified.", args.output)
};
output.write(&args.output);
}
108 changes: 77 additions & 31 deletions src/spn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use std::{
io::{BufRead, BufReader},
};

const NODE_NUMBERING_OFFSET: usize = 1;

type SpnData = Array3<u8>;
type VoxelData<const N: usize> = Vec<[usize; N]>;

Expand Down Expand Up @@ -88,43 +90,87 @@ fn exodus_data_from_npy_data(
.iter()
.map(|entry| {
vec![
entry[2] * nelzplus1 * nelyplus1 + entry[1] * nelzplus1 + entry[0] + 2,
entry[2] * nelzplus1 * nelyplus1 + entry[1] * nelzplus1 + entry[0] + 1,
entry[2] * nelzplus1 * nelyplus1 + (entry[1] + 1) * nelzplus1 + entry[0] + 1,
entry[2] * nelzplus1 * nelyplus1 + (entry[1] + 1) * nelzplus1 + entry[0] + 2,
(entry[2] + 1) * nelzplus1 * nelyplus1 + entry[1] * nelzplus1 + entry[0] + 2,
(entry[2] + 1) * nelzplus1 * nelyplus1 + entry[1] * nelzplus1 + entry[0] + 1,
(entry[2] + 1) * nelzplus1 * nelyplus1 + (entry[1] + 1) * nelzplus1 + entry[0] + 1,
(entry[2] + 1) * nelzplus1 * nelyplus1 + (entry[1] + 1) * nelzplus1 + entry[0] + 2,
entry[2] * nelzplus1 * nelyplus1
+ entry[1] * nelzplus1
+ entry[0]
+ 1
+ NODE_NUMBERING_OFFSET,
entry[2] * nelzplus1 * nelyplus1
+ entry[1] * nelzplus1
+ entry[0]
+ NODE_NUMBERING_OFFSET,
entry[2] * nelzplus1 * nelyplus1
+ (entry[1] + 1) * nelzplus1
+ entry[0]
+ NODE_NUMBERING_OFFSET,
entry[2] * nelzplus1 * nelyplus1
+ (entry[1] + 1) * nelzplus1
+ entry[0]
+ 1
+ NODE_NUMBERING_OFFSET,
(entry[2] + 1) * nelzplus1 * nelyplus1
+ entry[1] * nelzplus1
+ entry[0]
+ 1
+ NODE_NUMBERING_OFFSET,
(entry[2] + 1) * nelzplus1 * nelyplus1
+ entry[1] * nelzplus1
+ entry[0]
+ NODE_NUMBERING_OFFSET,
(entry[2] + 1) * nelzplus1 * nelyplus1
+ (entry[1] + 1) * nelzplus1
+ entry[0]
+ NODE_NUMBERING_OFFSET,
(entry[2] + 1) * nelzplus1 * nelyplus1
+ (entry[1] + 1) * nelzplus1
+ entry[0]
+ 1
+ NODE_NUMBERING_OFFSET,
]
})
.collect();
element_connectivity_node_renumbering(&mut element_connectivity);
let nodal_coordinates = filtered_voxel_data
.iter()
.map(|entry| {
vec![
[entry[2], entry[1], entry[0] + 1],
[entry[2], entry[1], entry[0]],
[entry[2], entry[1] + 1, entry[0]],
[entry[2], entry[1] + 1, entry[0] + 1],
[entry[2] + 1, entry[1], entry[0] + 1],
[entry[2] + 1, entry[1], entry[0]],
[entry[2] + 1, entry[1] + 1, entry[0]],
[entry[2] + 1, entry[1] + 1, entry[0] + 1],
]
})
.collect::<Vec<Vec<[usize; 3]>>>()
.iter()
let number_of_nodes = element_connectivity
.clone()
.into_iter()
.flatten()
.unique()
.map(|coordinates| {
coordinates
.iter()
.map(|coordinate| *coordinate as f64)
.collect()
})
.collect();
.collect::<Vec<usize>>()
.len();
let mut nodal_coordinates = vec![vec![0.0; 3]; number_of_nodes];
filtered_voxel_data
.iter()
.zip(element_connectivity.iter())
.for_each(|(entry, connectivity)| {
nodal_coordinates[connectivity[0] - NODE_NUMBERING_OFFSET] =
vec![entry[2] as f64, entry[1] as f64, entry[0] as f64 + 1.0];
nodal_coordinates[connectivity[1] - NODE_NUMBERING_OFFSET] =
vec![entry[2] as f64, entry[1] as f64, entry[0] as f64];
nodal_coordinates[connectivity[2] - NODE_NUMBERING_OFFSET] =
vec![entry[2] as f64, entry[1] as f64 + 1.0, entry[0] as f64];
nodal_coordinates[connectivity[3] - NODE_NUMBERING_OFFSET] = vec![
entry[2] as f64,
entry[1] as f64 + 1.0,
entry[0] as f64 + 1.0,
];
nodal_coordinates[connectivity[4] - NODE_NUMBERING_OFFSET] = vec![
entry[2] as f64 + 1.0,
entry[1] as f64,
entry[0] as f64 + 1.0,
];
nodal_coordinates[connectivity[5] - NODE_NUMBERING_OFFSET] =
vec![entry[2] as f64 + 1.0, entry[1] as f64, entry[0] as f64];
nodal_coordinates[connectivity[6] - NODE_NUMBERING_OFFSET] = vec![
entry[2] as f64 + 1.0,
entry[1] as f64 + 1.0,
entry[0] as f64,
];
nodal_coordinates[connectivity[7] - NODE_NUMBERING_OFFSET] = vec![
entry[2] as f64 + 1.0,
entry[1] as f64 + 1.0,
entry[0] as f64 + 1.0,
];
});
(element_blocks, element_connectivity, nodal_coordinates)
}

Expand Down
158 changes: 79 additions & 79 deletions tests/spn.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,108 +50,108 @@
[25, 24, 29, 30, 55, 54, 59, 60],
])
gold_coordinates = np.array([
[0.0, 0.0, 1.0],
[0.0, 0.0, 0.0],
[0.0, 0.0, 1.0],
[0.0, 0.0, 2.0],
[0.0, 0.0, 3.0],
[0.0, 0.0, 4.0],
[0.0, 1.0, 0.0],
[0.0, 1.0, 1.0],
[1.0, 0.0, 1.0],
[1.0, 0.0, 0.0],
[1.0, 1.0, 0.0],
[1.0, 1.0, 1.0],
[2.0, 0.0, 1.0],
[2.0, 0.0, 0.0],
[2.0, 1.0, 0.0],
[2.0, 1.0, 1.0],
[3.0, 0.0, 1.0],
[3.0, 0.0, 0.0],
[3.0, 1.0, 0.0],
[3.0, 1.0, 1.0],
[0.0, 1.0, 2.0],
[0.0, 1.0, 3.0],
[0.0, 1.0, 4.0],
[0.0, 2.0, 0.0],
[0.0, 2.0, 1.0],
[1.0, 2.0, 0.0],
[1.0, 2.0, 1.0],
[2.0, 2.0, 0.0],
[2.0, 2.0, 1.0],
[3.0, 2.0, 0.0],
[3.0, 2.0, 1.0],
[0.0, 2.0, 2.0],
[0.0, 2.0, 3.0],
[0.0, 2.0, 4.0],
[0.0, 3.0, 0.0],
[0.0, 3.0, 1.0],
[1.0, 3.0, 0.0],
[1.0, 3.0, 1.0],
[2.0, 3.0, 0.0],
[2.0, 3.0, 1.0],
[3.0, 3.0, 0.0],
[3.0, 3.0, 1.0],
[0.0, 3.0, 2.0],
[0.0, 3.0, 3.0],
[0.0, 3.0, 4.0],
[0.0, 4.0, 0.0],
[0.0, 4.0, 1.0],
[1.0, 4.0, 0.0],
[1.0, 4.0, 1.0],
[2.0, 4.0, 0.0],
[2.0, 4.0, 1.0],
[3.0, 4.0, 0.0],
[3.0, 4.0, 1.0],
[0.0, 4.0, 2.0],
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