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