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