FuncViz examples
Generalized bitree/quadtree/octree library
Loading...
Searching...
No Matches
surface_plot_annular_edge.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file surface_plot_annular_edge.cpp
5 @author Mitch Richling http://www.mitchr.me/
6 @date 2024-07-16
7 @brief Surface with an undefined annular region.@EOL
8 @std C++23
9 @copyright
10 @parblock
11 Copyright (c) 2024, Mitchell Jay Richling <http://www.mitchr.me/> All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
14
15 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
16
17 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19
20 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
21 without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28 DAMAGE.
29 @endparblock
30 @filedetails
31
32 In example surface_plot_edge.cpp we had a surface plot with a large, undefined region easily discovered by Maple & Nathematica. In this example we have a
33 surface with a smaller, annular undefined region that is harder for automatic software to get right. The function in question is as follows:
34
35 @f[ \sqrt{\sqrt{\vert 1 - x^2 - y^2\vert} - \frac{3}{20}} @f]
36
37 This example differs from surface_plot_edge.cpp in that we direct additional sampling near the unit circle. Other than that, it's just about identical.
38*/
39/*******************************************************************************************************************************************************.H.E.**/
40/** @cond exj */
41
42////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
43#include "MR_rect_tree.hpp"
44#include "MR_cell_cplx.hpp"
45#include "MR_rt_to_cc.hpp"
46
47////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
48typedef mjr::tree15b2d1rT tt_t;
49typedef mjr::MRccT5 cc_t;
50typedef mjr::MR_rt_to_cc<tt_t, cc_t> tc_t;
51
52////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
53tt_t::rrpt_t annular_hat(tt_t::drpt_t xvec) {
54 double v = std::sqrt(std::abs(1 - xvec[0] * xvec[0] - xvec[1] * xvec[1])) - 0.15;
55 if (v < 0.0) {
56 return std::numeric_limits<double>::quiet_NaN();
57 } else {
58 return std::sqrt(v);
59 }
60}
61
62////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63tt_t::src_t unit_circle_sdf(tt_t::drpt_t xvec) {
64 double m = xvec[0] * xvec[0] + xvec[1] * xvec[1];
65 return (1-m);
66}
67
68////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
69int main() {
70 tt_t tree({-1.1, -1.1},
71 { 1.1, 1.1});
72 cc_t ccplx;
73
74 // Sample a uniform grid across the domain
75 tree.refine_grid(5, annular_hat);
76
77 /* annular_hat produces NaNs in a thin annulus near the unit circle.*/
78 tree.refine_leaves_recursive_cell_pred(7, annular_hat, [&tree](int i) { return (tree.cell_cross_sdf(i, unit_circle_sdf)); });
79
80 /* Balance the three to the traditional level of 1 (no cell borders a cell more than half it's size) */
81 tree.balance_tree(1, annular_hat);
82
83 tree.dump_tree(10);
84
85 /* By passing annular_hat() to the construct_geometry_fans() we enable broken edges (an edge with one good point and one NaN) to be repaired. */
86 tc_t::construct_geometry_fans(ccplx,
87 tree,
88 2,
89 {{tc_t::val_src_spc_t::FDOMAIN, 0},
90 {tc_t::val_src_spc_t::FDOMAIN, 1},
91 {tc_t::val_src_spc_t::FRANGE, 0}},
92 annular_hat
93 );
94
95 ccplx.create_named_datasets({"x", "y", "f(x,y)"},
96 {{"NORMALS", {0, 1, 2}}});
97
98 ccplx.dump_cplx(10);
99
100 ccplx.write_xml_vtk("surface_plot_annular_edge.vtu", "surface_plot_annular_edge");
101}
102/** @endcond */
int main()