7 #ifndef PORTAGE_WRITE_TO_GMV_H_ 8 #define PORTAGE_WRITE_TO_GMV_H_ 21 #include "tangram/driver/CellMatPoly.h" 41 template<
int D,
class Mesh_Wrapper,
class State_Wrapper,
42 class InterfaceReconstructor>
44 State_Wrapper
const& state,
45 std::shared_ptr<InterfaceReconstructor> ir,
46 std::vector<std::string> &fieldnames,
47 std::string filename) {
49 std::cerr <<
"Writing material and field data to GMV file\n";
51 int nmats = state.num_materials();
52 int nc = mesh.num_entities(Entity_kind::CELL, Entity_type::PARALLEL_OWNED);
53 int nallc = mesh.num_entities(Entity_kind::CELL, Entity_type::ALL);
55 std::vector<int> cell_num_mats(nc, 0);
56 std::vector<std::vector<int>> cell_mat_ids(nc);
58 std::vector<int> icell_owned2all(nc, -1);
59 for (
int ic = 0, iowned = 0; ic < nallc; ic++)
60 if (mesh.cell_get_type(ic) == Wonton::PARALLEL_OWNED) {
61 state.cell_get_mats(iowned, &(cell_mat_ids[iowned]));
62 cell_num_mats[iowned] = cell_mat_ids[iowned].size();
63 icell_owned2all[iowned] = ic;
67 std::ofstream fout(filename);
68 fout << std::scientific;
71 fout <<
"gmvinput ascii" << std::endl;
72 fout <<
"codename Portage" << std::endl;
73 fout <<
"simdate 01/01/01" << std::endl;
78 int np = mesh.num_entities(Entity_kind::NODE, Entity_type::PARALLEL_OWNED);
79 int nallp = mesh.num_entities(Entity_kind::NODE, Entity_type::ALL);
82 std::vector<int> inode_owned2all(np, -1);
83 std::vector<int> inode_all2owned(nallp, -1);
84 for (
int ip = 0, iowned = 0; ip < nallp; ip++)
85 if (mesh.node_get_type(ip) == Wonton::PARALLEL_OWNED) {
86 inode_owned2all[iowned] = ip;
87 inode_all2owned[ip] = iowned;
91 for (
int c = 0; c < nc; c++) {
92 if (cell_num_mats[c] > 1) {
93 Tangram::CellMatPoly<D>
const& cellmatpoly =
94 ir->cell_matpoly_data(icell_owned2all[c]);
96 int ncp = cellmatpoly.num_matvertices();
97 for (
int i = 0; i < ncp; i++)
98 if (cellmatpoly.matvertex_parent_kind(i) != Tangram::Entity_kind::NODE)
103 std::vector<Point<D>>
points(nmatpnts);
105 for (
int i = 0; i < np; i++)
106 mesh.node_get_coordinates(inode_owned2all[i], &(points[i]));
109 for (
int c = 0; c < nc; c++) {
110 if (cell_num_mats[c] > 1) {
111 Tangram::CellMatPoly<D>
const& cellmatpoly =
112 ir->cell_matpoly_data(icell_owned2all[c]);
114 int ncp = cellmatpoly.num_matvertices();
115 for (
int i = 0; i < ncp; i++) {
116 if (cellmatpoly.matvertex_parent_kind(i) != Tangram::Entity_kind::NODE) {
117 points[nmatpnts] = Point<D>(cellmatpoly.matvertex_point(i));
124 fout <<
"nodev " << nmatpnts << std::endl;
125 for (
int ip = 0; ip < nmatpnts; ip++) {
128 fout <<
" " << 0.000000;
136 for (
int c = 0; c < nc; c++)
137 npoly += cell_num_mats[c];
138 fout <<
"cells " << npoly << std::endl;
143 for (
int m = 0; m < nmats; m++) {
144 std::vector<int> matcells;
145 state.mat_get_cells(m, &matcells);
147 for (
int c : matcells) {
148 if (cell_num_mats[c] > 1) {
150 Tangram::CellMatPoly<D>
const& cellmatpoly =
151 ir->cell_matpoly_data(icell_owned2all[c]);
154 int nmp = cellmatpoly.num_matpolys();
155 for (
int i = 0; i < nmp; i++) {
157 if (cellmatpoly.matpoly_matid(i) != m)
continue;
159 if (D == 1 || D == 2) {
160 std::vector<int> mverts = cellmatpoly.matpoly_vertices(i);
161 fout <<
"general 1 " << mverts.size() <<
" ";
162 for (
auto n : mverts) {
163 if (cellmatpoly.matvertex_parent_kind(n) == Tangram::Entity_kind::NODE)
164 fout << inode_all2owned[cellmatpoly.matvertex_parent_id(n)] + 1 <<
" ";
166 Point<D> pnt = cellmatpoly.matvertex_point(n);
167 for (
int j = np; j < nmatpnts; j++) {
168 if (points[j] == pnt) {
179 std::vector<int>
const& mfaces = cellmatpoly.matpoly_faces(i);
180 fout <<
"general " << mfaces.size() << std::endl;
181 for (
auto f : mfaces) {
182 std::vector<int>
const& mfverts = cellmatpoly.matface_vertices(f);
183 fout << mfverts.size() <<
" ";
186 for (
auto f : mfaces) {
187 std::vector<int>
const& mfverts = cellmatpoly.matface_vertices(f);
188 int nfv = mfverts.size();
190 cellmatpoly.matface_matpolys(f, &mp0, &mp1);
192 for (
int j = 0; j < nfv; j++) {
194 if (cellmatpoly.matvertex_parent_kind(n) == Tangram::Entity_kind::NODE)
195 fout << inode_all2owned[cellmatpoly.matvertex_parent_id(n)] + 1 <<
" ";
197 Point<D> pnt = cellmatpoly.matvertex_point(n);
198 for (
int j = np; j < nmatpnts; j++) {
199 if (points[j] == pnt) {
208 for (
int j = 0; j < nfv; j++) {
209 int n = mfverts[nfv-j-1];
210 if (cellmatpoly.matvertex_parent_kind(n) == Tangram::Entity_kind::NODE)
211 fout << inode_all2owned[cellmatpoly.matvertex_parent_id(n)] + 1 <<
" ";
213 Point<D> pnt = cellmatpoly.matvertex_point(n);
214 for (
int j = np; j < nmatpnts; j++) {
215 if (points[j] == pnt) {
230 if (cell_mat_ids[c][0] == m) {
231 if (D == 1 || D == 2) {
233 std::vector<int> cverts;
234 mesh.cell_get_nodes(icell_owned2all[c], &cverts);
237 fout <<
"general 1 " << cverts.size() <<
" ";
238 for (
auto n : cverts)
242 std::vector<int> cfaces;
243 std::vector<int> cfdirs;
244 mesh.cell_get_faces_and_dirs(icell_owned2all[c], &cfaces, &cfdirs);
245 fout <<
"general " << cfaces.size() << std::endl;
246 for (
auto f : cfaces) {
247 std::vector<int> fverts;
248 mesh.face_get_nodes(f, &fverts);
249 fout << fverts.size() <<
" ";
254 for (
auto f : cfaces) {
255 std::vector<int> fverts;
256 mesh.face_get_nodes(f, &fverts);
257 int nfverts = fverts.size();
258 if (cfdirs[j] == 1) {
259 for (
int k = 0; k < nfverts; k++)
260 fout << fverts[k]+1 <<
" ";
263 for (
int k = 0; k < nfverts; k++)
264 fout << fverts[nfverts-k-1]+1 <<
" ";
278 fout <<
"material " << std::endl;
279 fout << nmats <<
" 0" << std::endl;
280 for (
int m = 0; m < nmats; m++)
281 fout <<
"mat" << m+1 << std::endl;
283 for (
int m = 0; m < nmats; m++) {
284 std::vector<int> matcells;
285 state.mat_get_cells(m, &matcells);
287 for (
int c : matcells) {
288 for (
int cm : cell_mat_ids[c]) {
299 if (fieldnames.size()) {
300 fout <<
"variable" << std::endl;
301 for (
auto & fieldname : fieldnames) {
302 if (state.field_type(Portage::Entity_kind::CELL, fieldname) ==
303 Portage::Field_type::UNKNOWN_TYPE_FIELD)
306 fout << fieldname <<
" 0 " << std::endl;
307 for (
int m = 0; m < nmats; m++) {
308 std::vector<int> matcells;
309 state.mat_get_cells(m, &matcells);
310 int nmatcells = matcells.size();
312 double const *matvec;
313 state.mat_get_celldata(fieldname, m, &matvec);
315 for (
int i = 0; i < nmatcells; i++)
316 fout << matvec[i] << std::endl;
319 fout <<
"endvars" << std::endl;
322 fout <<
"endgmv" << std::endl;
328 #endif // PORTAGE_WRITE_TO_GMV_H_ void write_to_gmv(Mesh_Wrapper const &mesh, State_Wrapper const &state, std::shared_ptr< InterfaceReconstructor > ir, std::vector< std::string > &fieldnames, std::string filename)
Method to write out material polygons from an interface reconstruction and any associated material fi...
Definition: write_to_gmv.h:43
Definition: coredriver.h:42
constexpr std::vector< Point< oper::dimension(domain)> > points()
Definition: operator_references.h:29