FuncViz examples
Generalized bitree/quadtree/octree library
Loading...
Searching...
No Matches
performance_with_large_surface.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file performance_with_large_surface.cpp
5 @author Mitch Richling http://www.mitchr.me/
6 @date 2024-07-23
7 @brief Stress test with a large surface object.@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 Just a nice parametric surface without any weirdness. Some things demonstrated:
33
34 - How to time various operations.
35 - Try with a large mesh (use a 9 in refine_grid).
36 - Try reducing the number of data variables stored in the cell complex
37 - Try removing the normal vector from the output
38 - Try both MRccT5 & MRccF5 for cc_t
39 - How to include a synthetic value that can be used for color mapping -- @f$ c(u,v) @f$ can be used to render stripes on the surface.
40 - How to compute a normal to a parametric surface. If the surface is defined by
41 @f[ \vec{f}(u,v)=(x(u,v), y(u,v), z(u,v)) @f]
42 Then the normal vector is given by:
43 @f[ \vec{n}=\frac{\partial \vec{f}}{\partial u}\times\frac{\partial \vec{f}}{\partial v} @f]
44 Note that @f$ \frac{\partial \vec{f}}{\partial u} = \left[ \frac{\partial x}{\partial u}, \frac{\partial y}{\partial u}, \frac{\partial z}{\partial u} \right] @f$ &
45 @f$ \frac{\partial \vec{f}}{\partial v} = \left[ \frac{\partial x}{\partial v}, \frac{\partial y}{\partial v}, \frac{\partial z}{\partial v} \right] @f$
46 - How to include a normal in the cell complex
47*/
48/*******************************************************************************************************************************************************.H.E.**/
49/** @cond exj */
50
51////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52#include <chrono> /* time C++11 */
53#include <numbers> /* C++ math constants C++20 */
54
55////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
56#include "MR_rect_tree.hpp"
57#include "MR_cell_cplx.hpp"
58#include "MR_rt_to_cc.hpp"
59
60////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61typedef mjr::tree15b2d15rT tt_t;
62typedef mjr::MRccT5 cc_t; // Replace with mjr::MRccF5, and compare bridge performance.
63typedef mjr::MR_rt_to_cc<tt_t, cc_t> tc_t;
64
65////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66tt_t::rrpt_t stripy_shell(tt_t::drpt_t xvec) {
67 double u = std::numbers::pi * xvec[0] + std::numbers::pi + 0.1; // U transformed from unit interval
68 double v = std::numbers::pi/2 * xvec[1] + std::numbers::pi/2; // V transformed from unit interval
69 double x = u*std::sin(u)*std::cos(v); // X
70 double y = u*std::cos(u)*std::cos(v); // Y
71 double z = u*std::sin(v); // Z
72 double c = std::fmod(u*sin(v), 2); // Stripes
73 double dxdu = std::sin(u)*std::cos(v)+u*std::cos(u)*std::cos(v); // dX/du
74 double dxdv = -u*std::sin(u)*std::sin(v); // dX/dv
75 double dydu = std::cos(u)*std::cos(v)-u*std::sin(u)*std::cos(v); // dY/du
76 double dydv = -u*std::cos(u)*std::sin(v); // dY/dv
77 double dzdu = std::sin(v); // dZ/du
78 double dzdv = u*std::cos(v); // dZ/dv
79 double nx = dydu*dzdv-dydv*dzdu; // normal_X This noraml
80 double ny = dxdv*dzdu-dxdu*dzdv; // normal_Y will not be of
81 double nz = dxdu*dydv-dxdv*dydu; // normal_Z unit length
82 return {x, y, z, c, dxdu, dxdv, dydu, dydv, dzdu, dzdv, nx, ny, nz};
83}
84
85////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86int main() {
87 std::chrono::time_point<std::chrono::system_clock> start_time = std::chrono::system_clock::now();
88 tt_t tree;
89 cc_t ccplx;
90 std::chrono::time_point<std::chrono::system_clock> construct_time = std::chrono::system_clock::now();
91
92 tree.refine_grid(7, stripy_shell);
93 std::chrono::time_point<std::chrono::system_clock> sample_time = std::chrono::system_clock::now();
94
95 tree.dump_tree(10);
96 std::chrono::time_point<std::chrono::system_clock> tdump_time = std::chrono::system_clock::now();
97
98 tc_t::construct_geometry_fans(ccplx,
99 tree,
100 2,
101 {{tc_t::val_src_spc_t::FRANGE, 0},
102 {tc_t::val_src_spc_t::FRANGE, 1},
103 {tc_t::val_src_spc_t::FRANGE, 2}});
104 std::chrono::time_point<std::chrono::system_clock> fan_time = std::chrono::system_clock::now();
105
106 ccplx.create_named_datasets({"u", "v",
107 "x(u,v)", "y(u,v)", "z(u,v)",
108 "c(u,v)",
109 "dx(u,v)/du", "dx(u,v)/dv", "dy(u,v)/du", "dy(u,v)/dv", "dz(u,v)/du", "dz(u,v)/dv",
110 "nx", "ny", "nz"},
111 {{"NORMALS", {12, 13, 14}}});
112 std::chrono::time_point<std::chrono::system_clock> dat_anno_time = std::chrono::system_clock::now();
113
114 ccplx.dump_cplx(10);
115 std::chrono::time_point<std::chrono::system_clock> cdump_time = std::chrono::system_clock::now();
116
117 ccplx.write_xml_vtk("performance_with_large_surface.vtu", "performance_with_large_surface");
118 std::chrono::time_point<std::chrono::system_clock> write_time = std::chrono::system_clock::now();
119
120 std::cout << "construct_time time .. " << static_cast<std::chrono::duration<double>>(construct_time-start_time) << " sec" << std::endl;
121 std::cout << "sample_time time ..... " << static_cast<std::chrono::duration<double>>(sample_time-construct_time) << " sec" << std::endl;
122 std::cout << "tree dump time ....... " << static_cast<std::chrono::duration<double>>(tdump_time-sample_time) << " sec" << std::endl;
123 std::cout << "bridge time .......... " << static_cast<std::chrono::duration<double>>(fan_time-tdump_time) << " sec" << std::endl;
124 std::cout << "dataset anno time .... " << static_cast<std::chrono::duration<double>>(dat_anno_time-fan_time) << " sec" << std::endl;
125 std::cout << "complex dump time .... " << static_cast<std::chrono::duration<double>>(cdump_time-dat_anno_time) << " sec" << std::endl;
126 std::cout << "write_vtk time ....... " << static_cast<std::chrono::duration<double>>(write_time-cdump_time) << " sec" << std::endl;
127 std::cout << "Total Run _time ...... " << static_cast<std::chrono::duration<double>>(write_time-start_time) << " sec" << std::endl;
128}
129/** @endcond */
int main()