Chi-Tech
sldfe_sq_03_print_quadrature.cc
Go to the documentation of this file.
1#include "sldfe_sq.h"
2
3#include "chi_runtime.h"
4#include "chi_log.h"
5
6//###################################################################
7/**Prints the quadrature to file.*/
9{
10 Chi::log.Log() << "Printing SLDFE-Quadrature to file.";
11
12 std::ofstream vert_file,cell_file,points_file,python_file;
13 vert_file.open(output_filename_prefix_ + "verts.txt");
14 {
15 for (const auto& sq : deployed_SQs_)
16 for (int v=0; v<4; ++v)
17 {
18 auto& v0 = sq.vertices_xyz_prime[v];
19 auto& v1 = sq.vertices_xyz_prime[(v<3)? v+1 : 0];
20
21 for (int d=0; d<=10; ++d)
22 {
23 auto vert = (1.0-d/10.0)*v0 + (d/10.0)*v1;
24 vert = vert*sq.octant_modifier;
25 vert.Normalize();
26 vert_file << vert.x << " " << vert.y << " " << vert.z << "\n";
27 }
28 }
29 }
30 vert_file.close();
31
32 cell_file.open(output_filename_prefix_ + "cells.txt");
33 {
34 int vi=0;
35 for (const auto& sq : deployed_SQs_)
36 {
37 for (const auto& vert : sq.vertices_xyz)
38 for (int d=0; d<=10; ++d)
39 cell_file << vi++ << " ";
40 cell_file << "\n";
41 }
42 }
43 cell_file.close();
44
45 double total_weight=0.0;
46 points_file.open(output_filename_prefix_ + "points.txt");
47 {
48 for (auto& sq : deployed_SQs_)
49 {
50 int ss=-1;
51 for (const auto& point : sq.sub_sqr_points)
52 {
53 ++ss;
54 for (int i=0; i<3; ++i)
55 points_file << point[i] << " ";
56 points_file << sq.sub_sqr_weights[ss];
57 total_weight += sq.sub_sqr_weights[ss];
58 points_file << "\n";
59 }
60 }
61 }
62 points_file.close();
63
64 python_file.open(output_filename_prefix_ + "python.py");
65 python_file <<
66 "import matplotlib.pyplot as plt\n"
67 "from mpl_toolkits import mplot3d\n"
68 "import mpl_toolkits.mplot3d.art3d as art3d\n"
69 "import mpl_toolkits.mplot3d as ax3\n"
70 "import matplotlib.transforms as mpltransform\n"
71 "\n"
72 "import numpy as np\n"
73 "import math\n"
74 "\n"
75 "#====================================== Read vertices\n"
76 "verts = []\n"
77 "verts_file = open(\"" << output_filename_prefix_ << "verts.txt\")\n"
78 "for line in verts_file:\n"
79 " words = line.split()\n"
80 " verts.append(np.array([float(words[0]),float(words[1]),float(words[2])]))\n"
81 "verts_file.close()\n"
82 "\n"
83 "#====================================== Read cells\n"
84 "cells = []\n"
85 "cells_file = open(\"" << output_filename_prefix_ << "cells.txt\")\n"
86 "for line in cells_file:\n"
87 " words = line.split()\n"
88 " cell = []\n"
89 " for word in words:\n"
90 " cell.append(int(word))\n"
91 " cells.append(cell)\n"
92 "cells_file.close()\n"
93 "\n"
94 "#====================================== Read points\n"
95 "points = []\n"
96 "weightsum=0.0\n"
97 "points_file = open(\"" << output_filename_prefix_ << "points.txt\")\n"
98 "for line in points_file:\n"
99 " words = line.split()\n"
100 " point = []\n"
101 " for word in words:\n"
102 " point.append(float(word))\n"
103 " points.append(point)\n"
104 " weightsum += point[3]\n"
105 "points_file.close()\n"
106 "\n"
107 "print(\"Weightsum check: \",weightsum,weightsum/4/math.pi)\n"
108 "\n"
109 "points_array = np.array(points)\n"
110 "\n"
111 "#====================================== Generate polygons\n"
112 "patches = []\n"
113 "for cell in cells:\n"
114 "\n"
115 " vertex_list = []\n"
116 " for index in cell:\n"
117 " vertex_list.append(verts[index])\n"
118 "\n"
119 " polygon = art3d.Poly3DCollection([vertex_list])\n"
120 " polygon.set_color([1.0,1.0,1.0,1.0])\n"
121 " polygon.set_edgecolor([0.0,0.0,0.0,1.0])\n"
122 " patches.append(polygon)\n"
123 "\n"
124 "#====================================== Plot polygons\n"
125 "fig = plt.figure(figsize=(10,8.5))\n"
126 "ax = ax3.Axes3D(fig, proj_type = 'ortho')\n"
127 "\n"
128 "ax.view_init(20,25)\n"
129 "limit = 1\n"
130 "end = int(len(patches)/limit)\n"
131 "for poly in patches[0:end]:\n"
132 " ax.add_collection3d(poly)\n"
133 "\n"
134 "avg_weight = 0.5*math.pi/len(points)\n"
135 "\n"
136 "psize=min(160.0,160*(1.0/avg_weight)*(48/len(points)))\n"
137 "# psize=160\n"
138 "# print(len(points))\n"
139 "end = int(len(points_array)/limit)\n"
140 "# ax.scatter3D(points_array[0:end,0],\n"
141 "# points_array[0:end,1],\n"
142 "# points_array[0:end,2],depthshade=False,\n"
143 "# s=psize*points_array[:,3],c=[[0,0,0,1]])\n"
144 "\n"
145 "\n"
146 "if limit==8:\n"
147 " ax.set_xlim([0.0,1.0])\n"
148 " ax.set_ylim([0.0,1.0])\n"
149 " ax.set_zlim([0.0,1.0])\n"
150 "else:\n"
151 " ax.set_xlim([-1.0,1.0])\n"
152 " ax.set_ylim([-1.0,1.0])\n"
153 " ax.set_zlim([-1.0,1.0])\n"
154 "\n"
155 "ax.margins(0.5)\n"
156 "ax.set_xlabel(r\"$\\mu$\")\n"
157 "ax.set_ylabel(r\"$\\eta$\")\n"
158 "ax.set_zlabel(r\"$\\xi$\")\n"
159 "plt.show()\n";
160 python_file.close();
161
162 Chi::log.Log() << "Done printing SLDFE-Quadrature to file.";
163}
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
std::vector< SphericalQuadrilateral > deployed_SQs_
Definition: sldfe_sq.h:75