1*9ba83ac0SJeremy L Thompson // Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors. 23eb59678SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 33eb59678SJeremy L Thompson // 43eb59678SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 53eb59678SJeremy L Thompson // 63eb59678SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 73eb59678SJeremy L Thompson 83eb59678SJeremy L Thompson // ---------------------------------------------------------------------------- 93eb59678SJeremy L Thompson // Transform mesh coordinates 103eb59678SJeremy L Thompson // ---------------------------------------------------------------------------- 113eb59678SJeremy L Thompson pub(crate) fn transform_mesh_coordinates( 123eb59678SJeremy L Thompson dim: usize, 133eb59678SJeremy L Thompson mesh_size: usize, 143eb59678SJeremy L Thompson mesh_coords: &mut libceed::Vector, 153eb59678SJeremy L Thompson ) -> libceed::Result<libceed::Scalar> { 163eb59678SJeremy L Thompson // Transform coordinates 173eb59678SJeremy L Thompson if dim == 1 { 183eb59678SJeremy L Thompson for coord in mesh_coords.view_mut()?.iter_mut() { 193eb59678SJeremy L Thompson // map [0,1] to [0,1] varying the mesh density 203eb59678SJeremy L Thompson *coord = 0.5 213eb59678SJeremy L Thompson + 1.0 / (3.0 as libceed::Scalar).sqrt() 223eb59678SJeremy L Thompson * ((2.0 / 3.0) * std::f64::consts::PI as libceed::Scalar * (*coord - 0.5)).sin() 233eb59678SJeremy L Thompson } 243eb59678SJeremy L Thompson } else { 253eb59678SJeremy L Thompson let mut coords = mesh_coords.view_mut()?; 263eb59678SJeremy L Thompson let num_nodes = mesh_size / dim; 273eb59678SJeremy L Thompson for i in 0..num_nodes { 283eb59678SJeremy L Thompson // map (x,y) from [0,1]x[0,1] to the quarter annulus with polar 293eb59678SJeremy L Thompson // coordinates, (r,phi) in [1,2]x[0,pi/2] with area = 3/4*pi 303eb59678SJeremy L Thompson let u = 1.0 + coords[i]; 313eb59678SJeremy L Thompson let v = std::f64::consts::PI as libceed::Scalar / 2.0 * coords[i + num_nodes]; 323eb59678SJeremy L Thompson coords[i] = u * v.cos(); 333eb59678SJeremy L Thompson coords[i + num_nodes] = u * v.sin(); 343eb59678SJeremy L Thompson } 353eb59678SJeremy L Thompson } 363eb59678SJeremy L Thompson 373eb59678SJeremy L Thompson // Exact volume of transformed region 383eb59678SJeremy L Thompson let exact_volume = match dim { 393eb59678SJeremy 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!(), 423eb59678SJeremy L Thompson }; 433eb59678SJeremy L Thompson Ok(exact_volume) 443eb59678SJeremy L Thompson } 453eb59678SJeremy L Thompson 463eb59678SJeremy L Thompson // ---------------------------------------------------------------------------- 47