FuncViz examples
Generalized bitree/quadtree/octree library
Loading...
Searching...
No Matches
holy_wave_surf.cpp
Go to the documentation of this file.
1// -*- Mode:C++; Coding:us-ascii-unix; fill-column:158 -*-
2/*******************************************************************************************************************************************************.H.S.**/
3/**
4 @file holy_wave_surf.cpp
5 @author Mitch Richling http://www.mitchr.me/
6 @date 2024-08-15
7 @brief Directly use MR_cell_cplx to randomly place triangles on a surface.@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 Just a fun example directly using MR_cell_cplx to drop randomly placed triangles on a surface.
32*/
33/*******************************************************************************************************************************************************.H.E.**/
34
35////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
36#include <random> /* C++ random numbers C++11 */
37#include <chrono> /* time C++11 */
38
39////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
40#include "MR_cell_cplx.hpp"
41
42////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
43double f(double x, double y) {
44 double d = x*x+y*y;
45 double z = std::exp(-d/4)*std::cos(4*std::sqrt(d));
46 return z;
47}
48
49////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50int main() {
51 std::cout << "PROGRAM: START" << std::endl;
52 std::chrono::time_point<std::chrono::system_clock> program_start_time = std::chrono::system_clock::now();
53
54 mjr::MRccT5 aPoly;
55
56 aPoly.create_dataset_to_point_mapping({0, 1, 2});
57 aPoly.create_named_datasets({"x", "y", "z", "za", "xyMag", "xyzMag", "dir"});
58
59 const int num_tri = 20000;
60 const double tri_siz = 0.07;
61 const double x_min = -2.1;
62 const double x_max = 2.1;
63 const double y_min = -2.1;
64 const double y_max = 2.1;
65
66 std::random_device rd;
67 std::mt19937 rEng(rd());
68 std::uniform_real_distribution<double> x_uniform_dist_float(x_min, x_max);
69 std::uniform_real_distribution<double> y_uniform_dist_float(y_min, y_max);
70 std::uniform_real_distribution<double> siz_uniform_dist_float(-tri_siz, tri_siz);
71
72 std::cout << "SAMPLE: START" << std::endl;
73 std::chrono::time_point<std::chrono::system_clock> sample_start_time = std::chrono::system_clock::now();
74 for(int i=0; i<num_tri; i++) {
75 double xc = x_uniform_dist_float(rEng);
76 double yc = y_uniform_dist_float(rEng);
77
78 double x1 = xc + siz_uniform_dist_float(rEng);
79 double y1 = yc + siz_uniform_dist_float(rEng);
80 double z1 = f(x1, y1);
81 double x2 = xc + siz_uniform_dist_float(rEng);
82 double y2 = yc + siz_uniform_dist_float(rEng);
83 double z2 = f(x2, y2);
84 double x3 = xc + siz_uniform_dist_float(rEng);
85 double y3 = yc + siz_uniform_dist_float(rEng);
86 double z3 = f(x3, y3);
87
88 double xa = (x1+x2+x3)/3;
89 double ya = (y1+y2+y3)/3;
90 double za = (z1+z2+z3)/3;
91
92 double xy_mag = std::sqrt(xa*xa+ya*ya);
93 double xyz_mag = std::sqrt(xa*xa+ya*ya+za*za);
94
95 mjr::MRccT5::node_idx_t p1i = aPoly.add_node({x1, y1, z1, za, xy_mag, xyz_mag});
96 mjr::MRccT5::node_idx_t p2i = aPoly.add_node({x2, y2, z2, za, xy_mag, xyz_mag});
97 mjr::MRccT5::node_idx_t p3i = aPoly.add_node({x3, y3, z3, za, xy_mag, xyz_mag});
98
99 aPoly.add_cell(mjr::MRccT5::cell_kind_t::TRIANGLE, {p1i, p2i, p3i});
100 }
101
102 std::cout << "SAMPLE: Total Points: " << aPoly.node_count() << std::endl;
103 std::cout << "SAMPLE: Total Cells: " << aPoly.num_cells() << std::endl;
104
105 std::chrono::duration<double> sample_run_time = std::chrono::system_clock::now() - sample_start_time;
106 std::cout << "SAMPLE: Total Runtime " << sample_run_time.count() << " sec" << std::endl;
107 std::cout << "SAMPLE: END" << std::endl;
108
109 std::cout << "XML WRITE: START" << std::endl;
110 std::chrono::time_point<std::chrono::system_clock> xwrite_start_time = std::chrono::system_clock::now();
111 int xwrite_result = aPoly.write_xml_vtk("holy_wave_surf.vtu", "holy_wave_surf");
112 std::chrono::duration<double> xwrite_run_time = std::chrono::system_clock::now() - xwrite_start_time;
113 std::cout << "XML WRITE: Total Runtime " << xwrite_run_time.count() << " sec" << std::endl;
114 std::cout << "XML WRITE: END -- " << (xwrite_result != 0 ? "BAD" : "GOOD") << std::endl;
115
116 std::chrono::duration<double> program_run_time = std::chrono::system_clock::now() - program_start_time;
117 std::cout << "PROGRAM: Total Runtime " << program_run_time.count() << " sec" << std::endl;
118 std::cout << "PROGRAM: END" << std::endl;
119
120 return 0;
121}
122
double f(double x, double y)
int main()