xref: /libCEED/examples/rust/ex2-surface/src/transform.rs (revision 80a9ef0545a39c00cdcaab1ca26f8053604f3120)
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 // ----------------------------------------------------------------------------
22*80a9ef05SNatalie Beams pub(crate) fn transform_mesh_coordinates(dim: usize, mesh_coords: &mut Vector) -> Scalar {
23ded9b81dSJeremy L Thompson     // Transform coordinates
24ded9b81dSJeremy L Thompson     mesh_coords.view_mut().iter_mut().for_each(|coord| {
25ded9b81dSJeremy L Thompson         // map [0,1] to [0,1] varying the mesh density
26ded9b81dSJeremy L Thompson         *coord = 0.5
27*80a9ef05SNatalie Beams             + 1.0 / (3.0 as Scalar).sqrt()
28*80a9ef05SNatalie Beams                 * ((2.0 / 3.0) * std::f64::consts::PI as Scalar * (*coord - 0.5)).sin()
29ded9b81dSJeremy L Thompson     });
30ded9b81dSJeremy L Thompson 
31ded9b81dSJeremy L Thompson     // Exact surface area of transformed region
32ded9b81dSJeremy L Thompson     let exact_area = match dim {
33ded9b81dSJeremy L Thompson         1 => 2.0,
34ded9b81dSJeremy L Thompson         2 => 4.0,
35ded9b81dSJeremy L Thompson         _ => 6.0,
36ded9b81dSJeremy L Thompson     };
37ded9b81dSJeremy L Thompson     exact_area
38ded9b81dSJeremy L Thompson }
39ded9b81dSJeremy L Thompson 
40ded9b81dSJeremy L Thompson // ----------------------------------------------------------------------------
41