xref: /libCEED/examples/rust/ex2-surface/src/transform.rs (revision d3677ae8c8463ed424a8c5269c03811212785cd9)
1ded9b81dSJeremy L Thompson // Copyright (c) 2017-2021, Lawrence Livermore National Security, LLC.
2ded9b81dSJeremy L Thompson // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3ded9b81dSJeremy L Thompson // All Rights reserved. See files LICENSE and NOTICE for details.
4ded9b81dSJeremy L Thompson //
5ded9b81dSJeremy L Thompson // This file is part of CEED, a collection of benchmarks, miniapps, software
6ded9b81dSJeremy L Thompson // libraries and APIs for efficient high-order finite element and spectral
7ded9b81dSJeremy L Thompson // element discretizations for exascale applications. For more information and
8ded9b81dSJeremy L Thompson // source code availability see http://github.com/ceed.
9ded9b81dSJeremy L Thompson //
10ded9b81dSJeremy L Thompson // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11ded9b81dSJeremy L Thompson // a collaborative effort of two U.S. Department of Energy organizations (Office
12ded9b81dSJeremy L Thompson // of Science and the National Nuclear Security Administration) responsible for
13ded9b81dSJeremy L Thompson // the planning and preparation of a capable exascale ecosystem, including
14ded9b81dSJeremy L Thompson // software, applications, hardware, advanced system engineering and early
15ded9b81dSJeremy L Thompson // testbed platforms, in support of the nation's exascale computing imperative.
16ded9b81dSJeremy L Thompson 
17ded9b81dSJeremy L Thompson use libceed::prelude::*;
18ded9b81dSJeremy L Thompson 
19ded9b81dSJeremy L Thompson // ----------------------------------------------------------------------------
20ded9b81dSJeremy L Thompson // Transform mesh coordinates
21ded9b81dSJeremy L Thompson // ----------------------------------------------------------------------------
224d27c890SJeremy L Thompson pub(crate) fn transform_mesh_coordinates(
234d27c890SJeremy L Thompson     dim: usize,
244d27c890SJeremy L Thompson     mesh_coords: &mut Vector,
254d27c890SJeremy L Thompson ) -> libceed::Result<Scalar> {
26ded9b81dSJeremy L Thompson     // Transform coordinates
27*d3677ae8SJeremy L Thompson     for coord in mesh_coords.view_mut()?.iter_mut() {
28ded9b81dSJeremy L Thompson         // map [0,1] to [0,1] varying the mesh density
29ded9b81dSJeremy L Thompson         *coord = 0.5
3080a9ef05SNatalie Beams             + 1.0 / (3.0 as Scalar).sqrt()
3180a9ef05SNatalie Beams                 * ((2.0 / 3.0) * std::f64::consts::PI as Scalar * (*coord - 0.5)).sin()
32*d3677ae8SJeremy L Thompson     }
33ded9b81dSJeremy L Thompson 
34ded9b81dSJeremy L Thompson     // Exact surface area of transformed region
35ded9b81dSJeremy L Thompson     let exact_area = match dim {
36ded9b81dSJeremy L Thompson         1 => 2.0,
37ded9b81dSJeremy L Thompson         2 => 4.0,
38ded9b81dSJeremy L Thompson         _ => 6.0,
39ded9b81dSJeremy L Thompson     };
40e78171edSJeremy L Thompson     Ok(exact_area)
41ded9b81dSJeremy L Thompson }
42ded9b81dSJeremy L Thompson 
43ded9b81dSJeremy L Thompson // ----------------------------------------------------------------------------
44