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_size: usize, mesh_coords: &mut libceed::Vector, ) -> libceed::Result<libceed::Scalar>11ded9b81dSJeremy L Thompson pub(crate) fn transform_mesh_coordinates(
12ded9b81dSJeremy L Thompson dim: usize,
13ded9b81dSJeremy L Thompson mesh_size: usize,
14eb07d68fSJeremy L Thompson mesh_coords: &mut libceed::Vector,
15eb07d68fSJeremy L Thompson ) -> libceed::Result<libceed::Scalar> {
16ded9b81dSJeremy L Thompson // Transform coordinates
17ded9b81dSJeremy L Thompson if dim == 1 {
18d3677ae8SJeremy L Thompson for coord in mesh_coords.view_mut()?.iter_mut() {
19ded9b81dSJeremy L Thompson // map [0,1] to [0,1] varying the mesh density
20ded9b81dSJeremy L Thompson *coord = 0.5
21eb07d68fSJeremy L Thompson + 1.0 / (3.0 as libceed::Scalar).sqrt()
22eb07d68fSJeremy L Thompson * ((2.0 / 3.0) * std::f64::consts::PI as libceed::Scalar * (*coord - 0.5)).sin()
23d3677ae8SJeremy L Thompson }
24ded9b81dSJeremy L Thompson } else {
25e78171edSJeremy L Thompson let mut coords = mesh_coords.view_mut()?;
26ded9b81dSJeremy L Thompson let num_nodes = mesh_size / dim;
27ded9b81dSJeremy L Thompson for i in 0..num_nodes {
28ded9b81dSJeremy L Thompson // map (x,y) from [0,1]x[0,1] to the quarter annulus with polar
29ded9b81dSJeremy L Thompson // coordinates, (r,phi) in [1,2]x[0,pi/2] with area = 3/4*pi
30ded9b81dSJeremy L Thompson let u = 1.0 + coords[i];
31eb07d68fSJeremy L Thompson let v = std::f64::consts::PI as libceed::Scalar / 2.0 * coords[i + num_nodes];
32ded9b81dSJeremy L Thompson coords[i] = u * v.cos();
33ded9b81dSJeremy L Thompson coords[i + num_nodes] = u * v.sin();
34ded9b81dSJeremy L Thompson }
35ded9b81dSJeremy L Thompson }
36ded9b81dSJeremy L Thompson
37ded9b81dSJeremy L Thompson // Exact volume of transformed region
38ded9b81dSJeremy L Thompson let exact_volume = match dim {
39ded9b81dSJeremy L Thompson 1 => 1.0,
403eb59678SJeremy L Thompson 2 | 3 => 3.0 / 4.0 * std::f64::consts::PI as libceed::Scalar,
413eb59678SJeremy L Thompson _ => unreachable!(),
42ded9b81dSJeremy L Thompson };
43e78171edSJeremy L Thompson Ok(exact_volume)
44ded9b81dSJeremy L Thompson }
45ded9b81dSJeremy L Thompson
46ded9b81dSJeremy L Thompson // ----------------------------------------------------------------------------
47