16 std::string fileName = base_name;
17 fileName = fileName + std::to_string(
Chi::mpi.location_id);
18 fileName = fileName + std::string(
".py");
22 <<
"import numpy as np\n"
23 "import matplotlib.pyplot as plt\n"
24 "import matplotlib.cm as cm\n"
25 "from matplotlib.collections import PatchCollection\n"
26 "from matplotlib.patches import Polygon\n"
27 "import matplotlib.colors as colors\n"
29 <<
"class Datapoint:\n"
30 " def __init__(self,x,y,value):\n"
33 " self.value = value\n\n";
36 <<
"class CellData:\n"
37 " def __init__(self):\n"
38 " self.data_points=[]\n"
45 std::string submod_name = base_name;
46 submod_name = submod_name + std::to_string(
Chi::mpi.location_id+1);
50 ofile <<
"import " << submod_name <<
"\n\n";
54 <<
"class BaseDataClass:\n"
55 <<
" def __init__(self):\n"
56 <<
" data_object = []\n"
57 <<
" self.data_object = data_object\n";
59 offset = std::string(
" ");
66 std::string submod_name = base_name;
67 submod_name = submod_name + std::to_string(
Chi::mpi.location_id+1);
69 ofile <<
"import " << submod_name <<
"\n\n";
73 <<
"def AddData(data_object):\n";
75 offset = std::string(
" ");
79 for (
int c=0; c<num_cells; c++)
86 << offset <<
"new_cell_data = CellData()\n";
90 << offset <<
"new_cell_data.xy = np.zeros(("
91 << std::to_string(num_points) <<
",2))\n"
92 << offset <<
"new_cell_data.c = np.zeros("
93 << std::to_string(num_points) <<
")\n";
94 for (
int p=0; p<num_points; p++)
102 <<
"new_cell_data.xy[" << std::to_string(p)
103 <<
",0] = " << std::to_string(x) <<
"\n"
105 <<
"new_cell_data.xy[" << std::to_string(p)
106 <<
",1] = " << std::to_string(y) <<
"\n"
108 <<
"new_cell_data.c[" << std::to_string(p)
109 <<
"] = " << std::to_string(v) <<
"\n";
114 <<
"new_cell_data.avg = " << std::to_string(v) <<
"\n";
118 << offset <<
"data_object.append(new_cell_data)\n";
123 std::string submod_name = base_name;
124 submod_name = submod_name + std::to_string(
Chi::mpi.location_id+1);
127 << offset <<
"data_object = "
128 << submod_name <<
".AddData(data_object)\n\n";
133 << offset <<
"return data_object\n";
139 <<
"data = BaseDataClass()\n"
140 <<
"print(len(data.data_object))\n\n"
141 <<
"N = len(data.data_object)\n"
146 "for c in range(0,N):\n"
147 " for i in range(0,np.size(data.data_object[c].c)):\n"
149 " if data.data_object[c].avg>maxavg:\n"
150 " maxavg = data.data_object[c].avg\n"
151 " if data.data_object[c].c[i]>maxc:\n"
152 " maxc = data.data_object[c].c[i]\n"
154 "xmax = -9999999.0\n"
156 "ymax = -9999999.0\n"
158 "zmax = -9999999.0\n"
160 "x = np.zeros(xycount)\n"
161 "y = np.zeros(xycount)\n"
162 "z = np.zeros(xycount)\n"
164 "for c in range(0,N):\n"
165 " for i in range(0,np.size(data.data_object[c].c)):\n"
167 " x[xycount] = data.data_object[c].xy[i,0]\n"
168 " y[xycount] = data.data_object[c].xy[i,1]\n"
169 " z[xycount] = data.data_object[c].c[i]\n"
171 " if x[xycount]>xmax: xmax = x[xycount]\n"
172 " if x[xycount]<xmin: xmin = x[xycount]\n"
173 " if y[xycount]>ymax: ymax = y[xycount]\n"
174 " if y[xycount]<ymin: ymin = y[xycount]\n"
175 " if z[xycount]>zmax: zmax = z[xycount]\n"
176 " if z[xycount]<zmin: zmin = z[xycount]\n"
178 "print(\"phi_max=%g phi_min=%g\" %(zmax,zmin))\n"
180 "fig,ax = plt.subplots(1)\n"
181 "cmapjet = plt.get_cmap('jet')\n"
182 "cNorm = colors.Normalize(vmin=0,vmax=maxavg)\n"
183 "scalarMap = cm.ScalarMappable(norm=cNorm, cmap=cmapjet)\n"
185 "cb_scale = np.linspace(zmin,zmax*1.00001, 124, endpoint=True)\n"
187 "cntr1 = plt.tricontourf(x,y,z,cb_scale,cmap=cmapjet)\n"
189 "for c in range(0,N):\n"
190 " col = scalarMap.to_rgba(data.data_object[c].avg)\n"
191 " poly = Polygon(data.data_object[c].xy,\n"
192 " closed=True,linestyle='-',fill=False)\n"
194 " patch.append(poly)\n"
195 " coll = PatchCollection(patch)\n"
196 " coll.set_facecolor([0,0,0,0])\n"
197 " coll.set_edgecolor([0,0,0,1])\n"
198 " coll.set_linewidth(0.3)\n"
200 " ax.add_collection(coll)\n"
202 "cb = fig.colorbar(cntr1,ax=ax)\n"
203 "cb.set_ticks(np.linspace(zmin,zmax, 11, endpoint=True))\n"
204 "ax.set_xlim([xmin,xmax])\n"
205 "ax.set_ylim([ymin,ymax])\n"
212 <<
"Exported Python files for field func \""
214 <<
"\" to base name \""
215 << base_name <<
"\" Successfully";
static chi::MPI_Info & mpi
LogStream Log(LOG_LVL level=LOG_0)
std::vector< chi_physics::FieldFunctionGridBasedPtr > field_functions_
std::vector< FFICellIntersection > cell_intersections_
void ExportPython(std::string base_name) override