xref: /libCEED/examples/rust/ex2-surface/src/transform.rs (revision d4cc18453651bd0f94c1a2e078b2646a92dafdcc)
1*9ba83ac0SJeremy L Thompson // Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3ded9b81dSJeremy L Thompson //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5ded9b81dSJeremy L Thompson //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
7ded9b81dSJeremy L Thompson 
8ded9b81dSJeremy L Thompson // ----------------------------------------------------------------------------
9ded9b81dSJeremy L Thompson // Transform mesh coordinates
10ded9b81dSJeremy L Thompson // ----------------------------------------------------------------------------
transform_mesh_coordinates( dim: usize, mesh_coords: &mut libceed::Vector, ) -> libceed::Result<libceed::Scalar>114d27c890SJeremy L Thompson pub(crate) fn transform_mesh_coordinates(
124d27c890SJeremy L Thompson     dim: usize,
13eb07d68fSJeremy L Thompson     mesh_coords: &mut libceed::Vector,
14eb07d68fSJeremy L Thompson ) -> libceed::Result<libceed::Scalar> {
15ded9b81dSJeremy L Thompson     // Transform coordinates
16d3677ae8SJeremy L Thompson     for coord in mesh_coords.view_mut()?.iter_mut() {
17ded9b81dSJeremy L Thompson         // map [0,1] to [0,1] varying the mesh density
18ded9b81dSJeremy L Thompson         *coord = 0.5
19eb07d68fSJeremy L Thompson             + 1.0 / (3.0 as libceed::Scalar).sqrt()
20eb07d68fSJeremy L Thompson                 * ((2.0 / 3.0) * std::f64::consts::PI as libceed::Scalar * (*coord - 0.5)).sin()
21d3677ae8SJeremy L Thompson     }
22ded9b81dSJeremy L Thompson 
23ded9b81dSJeremy L Thompson     // Exact surface area of transformed region
24ded9b81dSJeremy L Thompson     let exact_area = match dim {
25ded9b81dSJeremy L Thompson         1 => 2.0,
26ded9b81dSJeremy L Thompson         2 => 4.0,
273eb59678SJeremy L Thompson         3 => 6.0,
283eb59678SJeremy L Thompson         _ => unreachable!(),
29ded9b81dSJeremy L Thompson     };
30e78171edSJeremy L Thompson     Ok(exact_area)
31ded9b81dSJeremy L Thompson }
32ded9b81dSJeremy L Thompson 
33ded9b81dSJeremy L Thompson // ----------------------------------------------------------------------------
34