Skip to content

Commit 4db02c8

Browse files
authored
Merge pull request #1826 from CEED/jeremy/rust-ex
rust - update rust examples to match c/python
2 parents 860922c + 2522059 commit 4db02c8

File tree

26 files changed

+1131
-48
lines changed

26 files changed

+1131
-48
lines changed

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ members = [
33
"rust/libceed",
44
"rust/libceed-sys",
55
"examples/rust/ex1-volume",
6+
"examples/rust/ex1-volume-vector",
67
"examples/rust/ex2-surface",
7-
"examples/rust/ex3-vector-volume",
8-
"examples/rust/ex4-vector-surface",
8+
"examples/rust/ex2-surface-vector",
9+
"examples/rust/ex3-volume",
10+
"examples/rust/ex3-volume-vector",
911
"examples/rust/mesh",
1012
]

examples/deal.II/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
1+
CMAKE_MINIMUM_REQUIRED(VERSION 3.5.0)
22

33
FIND_PACKAGE(deal.II 8.0 QUIET
44
HINTS ${deal.II_DIR} ${DEAL_II_DIR} ../ ../../ $ENV{DEAL_II_DIR}

examples/rust/ex3-vector-volume/Cargo.toml renamed to examples/rust/ex1-volume-vector/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "ex3-vector-volume"
2+
name = "ex1-volume-vector"
33
version = "0.11.0"
44
authors = [
55
"Jeremy L Thompson <[email protected]>",

examples/rust/ex3-vector-volume/src/main.rs renamed to examples/rust/ex1-volume-vector/src/main.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ mod transform;
3131
// ----------------------------------------------------------------------------
3232
fn main() -> libceed::Result<()> {
3333
let options = opt::Opt::parse();
34-
example_3(options)
34+
example_1_vector(options)
3535
}
3636

3737
#[allow(clippy::erasing_op)]
3838
#[allow(clippy::identity_op)]
39-
fn example_3(options: opt::Opt) -> libceed::Result<()> {
39+
fn example_1_vector(options: opt::Opt) -> libceed::Result<()> {
4040
// Process command line arguments
4141
let opt::Opt {
4242
ceed_spec,
@@ -304,7 +304,7 @@ mod tests {
304304
use super::*;
305305

306306
#[test]
307-
fn example_3_1d() {
307+
fn example_1_vector_1d() {
308308
let options = opt::Opt {
309309
ceed_spec: "/cpu/self/ref/serial".to_string(),
310310
dim: 1,
@@ -316,11 +316,11 @@ mod tests {
316316
quiet: true,
317317
gallery: false,
318318
};
319-
assert!(example_3(options).is_ok());
319+
assert!(example_1_vector(options).is_ok());
320320
}
321321

322322
#[test]
323-
fn example_3_2d() {
323+
fn example_1_vector_2d() {
324324
let options = opt::Opt {
325325
ceed_spec: "/cpu/self/ref/serial".to_string(),
326326
dim: 2,
@@ -332,11 +332,11 @@ mod tests {
332332
quiet: true,
333333
gallery: false,
334334
};
335-
assert!(example_3(options).is_ok());
335+
assert!(example_1_vector(options).is_ok());
336336
}
337337

338338
#[test]
339-
fn example_3_3d() {
339+
fn example_1_vector_3d() {
340340
let options = opt::Opt {
341341
ceed_spec: "/cpu/self/ref/serial".to_string(),
342342
dim: 3,
@@ -348,11 +348,11 @@ mod tests {
348348
quiet: false,
349349
gallery: false,
350350
};
351-
assert!(example_3(options).is_ok());
351+
assert!(example_1_vector(options).is_ok());
352352
}
353353

354354
#[test]
355-
fn example_3_1d_gallery() {
355+
fn example_1_vector_1d_gallery() {
356356
let options = opt::Opt {
357357
ceed_spec: "/cpu/self/ref/serial".to_string(),
358358
dim: 1,
@@ -364,11 +364,11 @@ mod tests {
364364
quiet: true,
365365
gallery: true,
366366
};
367-
assert!(example_3(options).is_ok());
367+
assert!(example_1_vector(options).is_ok());
368368
}
369369

370370
#[test]
371-
fn example_3_2d_gallery() {
371+
fn example_1_vector_2d_gallery() {
372372
let options = opt::Opt {
373373
ceed_spec: "/cpu/self/ref/serial".to_string(),
374374
dim: 2,
@@ -380,11 +380,11 @@ mod tests {
380380
quiet: true,
381381
gallery: true,
382382
};
383-
assert!(example_3(options).is_ok());
383+
assert!(example_1_vector(options).is_ok());
384384
}
385385

386386
#[test]
387-
fn example_3_3d_gallery() {
387+
fn example_1_vector_3d_gallery() {
388388
let options = opt::Opt {
389389
ceed_spec: "/cpu/self/ref/serial".to_string(),
390390
dim: 3,
@@ -396,7 +396,7 @@ mod tests {
396396
quiet: true,
397397
gallery: true,
398398
};
399-
assert!(example_3(options).is_ok());
399+
assert!(example_1_vector(options).is_ok());
400400
}
401401
}
402402

examples/rust/ex3-vector-volume/src/transform.rs renamed to examples/rust/ex1-volume-vector/src/transform.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ pub(crate) fn transform_mesh_coordinates(
3737
// Exact volume of transformed region
3838
let exact_volume = match dim {
3939
1 => 1.0,
40-
_ => 3.0 / 4.0 * std::f64::consts::PI as libceed::Scalar,
40+
2 | 3 => 3.0 / 4.0 * std::f64::consts::PI as libceed::Scalar,
41+
_ => unreachable!(),
4142
};
4243
Ok(exact_volume)
4344
}

examples/rust/ex1-volume/src/transform.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ pub(crate) fn transform_mesh_coordinates(
3737
// Exact volume of transformed region
3838
let exact_volume = match dim {
3939
1 => 1.0,
40-
_ => 3.0 / 4.0 * std::f64::consts::PI as libceed::Scalar,
40+
2 | 3 => 3.0 / 4.0 * std::f64::consts::PI as libceed::Scalar,
41+
_ => unreachable!(),
4142
};
4243
Ok(exact_volume)
4344
}

examples/rust/ex4-vector-surface/Cargo.toml renamed to examples/rust/ex2-surface-vector/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "ex4-vector-surface"
2+
name = "ex2-surface-vector"
33
version = "0.11.0"
44
authors = [
55
"Jeremy L Thompson <[email protected]>",

examples/rust/ex4-vector-surface/src/main.rs renamed to examples/rust/ex2-surface-vector/src/main.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ mod transform;
3232
// ----------------------------------------------------------------------------
3333
fn main() -> libceed::Result<()> {
3434
let options = opt::Opt::parse();
35-
example_4(options)
35+
example_2_vector(options)
3636
}
3737

3838
#[allow(clippy::erasing_op)]
3939
#[allow(clippy::identity_op)]
40-
fn example_4(options: opt::Opt) -> libceed::Result<()> {
40+
fn example_2_vector(options: opt::Opt) -> libceed::Result<()> {
4141
// Process command line arguments
4242
let opt::Opt {
4343
ceed_spec,
@@ -256,7 +256,7 @@ fn example_4(options: opt::Opt) -> libceed::Result<()> {
256256
match dim {
257257
1 => {
258258
let q = qdata.len();
259-
for c in 0..3 {
259+
for c in 0..ncomp_u {
260260
vg.iter_mut()
261261
.skip(c * q)
262262
.zip(ug.iter().skip(c * q).zip(qdata.iter()))
@@ -266,12 +266,12 @@ fn example_4(options: opt::Opt) -> libceed::Result<()> {
266266
2 => {
267267
let q = qdata.len() / 3;
268268
for i in 0..q {
269+
let dxdxdxdx_t = [
270+
[qdata[i + 0 * q], qdata[i + 2 * q]],
271+
[qdata[i + 2 * q], qdata[i + 1 * q]],
272+
];
269273
for c in 0..ncomp_u {
270274
let du = [ug[i + (c + 0 * ncomp_u) * q], ug[i + (c + 1 * ncomp_u) * q]];
271-
let dxdxdxdx_t = [
272-
[qdata[i + 0 * q], qdata[i + 2 * q]],
273-
[qdata[i + 2 * q], qdata[i + 1 * q]],
274-
];
275275
for j in 0..dim {
276276
vg[i + (c + j * ncomp_u) * q] =
277277
du[0] * dxdxdxdx_t[0][j] + du[1] * dxdxdxdx_t[1][j];
@@ -282,17 +282,17 @@ fn example_4(options: opt::Opt) -> libceed::Result<()> {
282282
3 => {
283283
let q = qdata.len() / 6;
284284
for i in 0..q {
285+
let dxdxdxdx_t = [
286+
[qdata[i + 0 * q], qdata[i + 5 * q], qdata[i + 4 * q]],
287+
[qdata[i + 5 * q], qdata[i + 1 * q], qdata[i + 3 * q]],
288+
[qdata[i + 4 * q], qdata[i + 3 * q], qdata[i + 2 * q]],
289+
];
285290
for c in 0..ncomp_u {
286291
let du = [
287292
ug[i + (c + 0 * ncomp_u) * q],
288293
ug[i + (c + 1 * ncomp_u) * q],
289294
ug[i + (c + 2 * ncomp_u) * q],
290295
];
291-
let dxdxdxdx_t = [
292-
[qdata[i + 0 * q], qdata[i + 5 * q], qdata[i + 4 * q]],
293-
[qdata[i + 5 * q], qdata[i + 1 * q], qdata[i + 3 * q]],
294-
[qdata[i + 4 * q], qdata[i + 3 * q], qdata[i + 2 * q]],
295-
];
296296
for j in 0..dim {
297297
vg[i + (c + j * ncomp_u) * q] = du[0] * dxdxdxdx_t[0][j]
298298
+ du[1] * dxdxdxdx_t[1][j]
@@ -395,7 +395,7 @@ mod tests {
395395
use super::*;
396396

397397
#[test]
398-
fn example_4_1d() {
398+
fn example_2_vector_1d() {
399399
let options = opt::Opt {
400400
ceed_spec: "/cpu/self/ref/serial".to_string(),
401401
dim: 1,
@@ -407,11 +407,11 @@ mod tests {
407407
quiet: true,
408408
gallery: false,
409409
};
410-
assert!(example_4(options).is_ok());
410+
assert!(example_2_vector(options).is_ok());
411411
}
412412

413413
#[test]
414-
fn example_4_2d() {
414+
fn example_2_vector_2d() {
415415
let options = opt::Opt {
416416
ceed_spec: "/cpu/self/ref/serial".to_string(),
417417
dim: 2,
@@ -423,11 +423,11 @@ mod tests {
423423
quiet: true,
424424
gallery: false,
425425
};
426-
assert!(example_4(options).is_ok());
426+
assert!(example_2_vector(options).is_ok());
427427
}
428428

429429
#[test]
430-
fn example_4_3d() {
430+
fn example_2_vector_3d() {
431431
let options = opt::Opt {
432432
ceed_spec: "/cpu/self/ref/serial".to_string(),
433433
dim: 3,
@@ -439,11 +439,11 @@ mod tests {
439439
quiet: false,
440440
gallery: false,
441441
};
442-
assert!(example_4(options).is_ok());
442+
assert!(example_2_vector(options).is_ok());
443443
}
444444

445445
#[test]
446-
fn example_4_1d_gallery() {
446+
fn example_2_vector_1d_gallery() {
447447
let options = opt::Opt {
448448
ceed_spec: "/cpu/self/ref/serial".to_string(),
449449
dim: 1,
@@ -455,11 +455,11 @@ mod tests {
455455
quiet: true,
456456
gallery: true,
457457
};
458-
assert!(example_4(options).is_ok());
458+
assert!(example_2_vector(options).is_ok());
459459
}
460460

461461
#[test]
462-
fn example_4_2d_gallery() {
462+
fn example_2_vector_2d_gallery() {
463463
let options = opt::Opt {
464464
ceed_spec: "/cpu/self/ref/serial".to_string(),
465465
dim: 2,
@@ -471,11 +471,11 @@ mod tests {
471471
quiet: true,
472472
gallery: true,
473473
};
474-
assert!(example_4(options).is_ok());
474+
assert!(example_2_vector(options).is_ok());
475475
}
476476

477477
#[test]
478-
fn example_4_3d_gallery() {
478+
fn example_2_vector_3d_gallery() {
479479
let options = opt::Opt {
480480
ceed_spec: "/cpu/self/ref/serial".to_string(),
481481
dim: 3,
@@ -487,7 +487,7 @@ mod tests {
487487
quiet: true,
488488
gallery: true,
489489
};
490-
assert!(example_4(options).is_ok());
490+
assert!(example_2_vector(options).is_ok());
491491
}
492492
}
493493

examples/rust/ex4-vector-surface/src/transform.rs renamed to examples/rust/ex2-surface-vector/src/transform.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ pub(crate) fn transform_mesh_coordinates(
2424
let exact_area = match dim {
2525
1 => 2.0,
2626
2 => 4.0,
27-
_ => 6.0,
27+
3 => 6.0,
28+
_ => unreachable!(),
2829
};
2930
Ok(exact_area)
3031
}

examples/rust/ex2-surface/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ fn example_2(options: opt::Opt) -> libceed::Result<()> {
123123
dim * (dim + 1) / 2,
124124
num_qpts,
125125
)?;
126-
127126
let (rstr_solution, _) =
128127
mesh::build_cartesian_restriction(&ceed, dim, num_xyz, solution_degree, 1, num_qpts)?;
129128
let mesh_size = rstr_mesh.lvector_size();

examples/rust/ex2-surface/src/transform.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ pub(crate) fn transform_mesh_coordinates(
2424
let exact_area = match dim {
2525
1 => 2.0,
2626
2 => 4.0,
27-
_ => 6.0,
27+
3 => 6.0,
28+
_ => unreachable!(),
2829
};
2930
Ok(exact_area)
3031
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
Cargo.lock
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "ex3-volume-vector"
3+
version = "0.11.0"
4+
authors = [
5+
"Jeremy L Thompson <[email protected]>",
6+
]
7+
edition = "2018"
8+
9+
[dependencies]
10+
clap = { version = "4.0.17", features = ["derive"] }
11+
libceed = { path = "../../../rust/libceed" }
12+
mesh = { path = "../mesh" }
13+
14+
[package.metadata.release]
15+
release = false

0 commit comments

Comments
 (0)