1 // Copyright (c) 2017-2025, Lawrence Livermore National Security, LLC and other CEED contributors. 2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3 // 4 // SPDX-License-Identifier: BSD-2-Clause 5 // 6 // This file is part of CEED: http://github.com/ceed 7 8 use libceed::prelude::*; 9 10 // ---------------------------------------------------------------------------- 11 // Transform mesh coordinates 12 // ---------------------------------------------------------------------------- 13 pub(crate) fn transform_mesh_coordinates( 14 dim: usize, 15 mesh_size: usize, 16 mesh_coords: &mut Vector, 17 ) -> libceed::Result<Scalar> { 18 // Transform coordinates 19 if dim == 1 { 20 for coord in mesh_coords.view_mut()?.iter_mut() { 21 // map [0,1] to [0,1] varying the mesh density 22 *coord = 0.5 23 + 1.0 / (3.0 as Scalar).sqrt() 24 * ((2.0 / 3.0) * std::f64::consts::PI as Scalar * (*coord - 0.5)).sin() 25 } 26 } else { 27 let mut coords = mesh_coords.view_mut()?; 28 let num_nodes = mesh_size / dim; 29 for i in 0..num_nodes { 30 // map (x,y) from [0,1]x[0,1] to the quarter annulus with polar 31 // coordinates, (r,phi) in [1,2]x[0,pi/2] with area = 3/4*pi 32 let u = 1.0 + coords[i]; 33 let v = std::f64::consts::PI as Scalar / 2.0 * coords[i + num_nodes]; 34 coords[i] = u * v.cos(); 35 coords[i + num_nodes] = u * v.sin(); 36 } 37 } 38 39 // Exact volume of transformed region 40 let exact_volume = match dim { 41 1 => 1.0, 42 _ => 3.0 / 4.0 * std::f64::consts::PI as Scalar, 43 }; 44 Ok(exact_volume) 45 } 46 47 // ---------------------------------------------------------------------------- 48