|
| 1 | +/* |
| 2 | + * TAUFileWrapper.cxx |
| 3 | + * |
| 4 | + * Created on: Jan 07, 2019 |
| 5 | + * Author: jww |
| 6 | + */ |
| 7 | + |
| 8 | +/* |
| 9 | + Copyright (C) The University of British Columbia, 2018. |
| 10 | +
|
| 11 | + This file is part of UnstructuredMeshAnalyzer. |
| 12 | +
|
| 13 | + UnstructuredMeshAnalyzer is free software: you can redistribute it |
| 14 | + and/or modify it under the terms of the GNU General Public License |
| 15 | + as published by the Free Software Foundation, either version 3 of |
| 16 | + the License, or (at your option) any later version. |
| 17 | +
|
| 18 | + UnstructuredMeshAnalyzer is distributed in the hope that it will be |
| 19 | + useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
| 20 | + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | + General Public License for more details. |
| 22 | +
|
| 23 | + You should have received a copy of the GNU General Public License |
| 24 | + along with UnstructuredMeshAnalyzer. If not, see |
| 25 | + <https://www.gnu.org/licenses/>. |
| 26 | +*/ |
| 27 | + |
| 28 | +#include <stdlib.h> |
| 29 | +#include <stdio.h> |
| 30 | + |
| 31 | +#include <GMGW_unstr.hxx> |
| 32 | +#include <GMGW_TAUFileWrapper.hxx> |
| 33 | +#include "check_malloc.h" |
| 34 | +#include "stream_interface.h" |
| 35 | +#include "tau_io_names.h" |
| 36 | +#include "primgrid_io_pdat.h" |
| 37 | +#include <cstring> |
| 38 | + |
| 39 | +static long int m_point_idx=0; |
| 40 | +static long int m_cell_idx=0; |
| 41 | + |
| 42 | + |
| 43 | +TAUFileWrapper::TAUFileWrapper(const char fileNameBase[]) : |
| 44 | + FileWrapper()//, m_pg(nullptr) , m_point_idx(0), m_cell_idx(0) |
| 45 | +{ |
| 46 | + char fileNameIn[1000]; |
| 47 | + char *stream = "primgrid_read"; |
| 48 | +// m_pg = init_primgrid(); |
| 49 | + snprintf(fileNameIn, 1000, "%s", fileNameBase); |
| 50 | + stream_open(stream, STREAM_BUFFER_ATTS); |
| 51 | + |
| 52 | + stream_open_file(stream, STREAM_NETCDF, fileNameIn, STREAM_READ_ONLY); |
| 53 | +} |
| 54 | + |
| 55 | +TAUFileWrapper::~TAUFileWrapper(void) |
| 56 | +{ |
| 57 | + char *stream = "primgrid_read"; |
| 58 | + stream_close(stream); |
| 59 | +// free_primgrid(&m_pg); |
| 60 | +} |
| 61 | + |
| 62 | +void TAUFileWrapper::scanFile() |
| 63 | +{ |
| 64 | + char *stream = "primgrid_read"; |
| 65 | + |
| 66 | + coordsStart = 0; |
| 67 | + nVerts = stream_get_dim(stream, NO_OF_POINTS); |
| 68 | + |
| 69 | + connectStart = 0; |
| 70 | + nTets = stream_get_dim(stream, NO_OF_TETRAS); |
| 71 | + nPrisms = stream_get_dim(stream, NO_OF_PRISMS); |
| 72 | + nHexes = stream_get_dim(stream, NO_OF_HEXAS); |
| 73 | + nPyrs = stream_get_dim(stream, NO_OF_PYRAS); |
| 74 | + nBdryTris = stream_get_dim(stream, NO_OF_SURFACETRIANGLES); |
| 75 | + nBdryQuads = stream_get_dim(stream, NO_OF_SURFACEQUADRILATERALS); |
| 76 | + nCells = nTets + nPrisms + nHexes + nPyrs + nBdryTris + nBdryQuads; |
| 77 | + |
| 78 | + m_cellTypes = new char[nCells]; |
| 79 | + m_isBdryFace = new bool[nCells]; |
| 80 | + |
| 81 | + unsigned int i_cell = 0; |
| 82 | + for (unsigned int ii = 0; ii < nTets; ii++,i_cell++) { |
| 83 | + m_isBdryFace[i_cell] = false; |
| 84 | + m_cellTypes[i_cell] = TET; |
| 85 | + } |
| 86 | + for (unsigned int ii = 0; ii < nPrisms; ii++,i_cell++) { |
| 87 | + m_isBdryFace[i_cell] = false; |
| 88 | + m_cellTypes[i_cell] = PRISM; |
| 89 | + } |
| 90 | + for (unsigned int ii = 0; ii < nHexes; ii++,i_cell++) { |
| 91 | + m_isBdryFace[i_cell] = false; |
| 92 | + m_cellTypes[i_cell] = HEX; |
| 93 | + } |
| 94 | + for (unsigned int ii = 0; ii < nPyrs; ii++,i_cell++) { |
| 95 | + m_isBdryFace[i_cell] = false; |
| 96 | + m_cellTypes[i_cell] = PYRAMID; |
| 97 | + } |
| 98 | + for (unsigned int ii = 0; ii < nBdryTris; ii++,i_cell++) { |
| 99 | + m_isBdryFace[i_cell] = true; |
| 100 | + m_cellTypes[i_cell] = BDRY_TRI; |
| 101 | + } |
| 102 | + for (unsigned int ii = 0; ii < nBdryQuads; ii++,i_cell++) { |
| 103 | + m_isBdryFace[i_cell] = true; |
| 104 | + m_cellTypes[i_cell] = BDRY_QUAD; |
| 105 | + } |
| 106 | + |
| 107 | + identifyBdryVerts(); |
| 108 | + |
| 109 | + printf("Scanned mesh and found:\n"); |
| 110 | + printf("%'13lu verts\n", nVerts); |
| 111 | + printf("%'13lu bdry verts\n", nBdryVerts); |
| 112 | + printf("%'13lu bdry tris\n", nBdryTris); |
| 113 | + printf("%'13lu bdry quads\n", nBdryQuads); |
| 114 | + printf("%'13lu tets\n", nTets); |
| 115 | + printf("%'13lu pyramids\n", nPyrs); |
| 116 | + printf("%'13lu prisms\n", nPrisms); |
| 117 | + printf("%'13lu hexes\n", nHexes); |
| 118 | + printf("%'13lu total cells\n", nCells); |
| 119 | +} |
| 120 | + |
| 121 | +void TAUFileWrapper::getNextVertexCoords(double& x, double& y, double& z) const |
| 122 | +{ |
| 123 | + char *st = "primgrid_read"; |
| 124 | + size_t tmp_offset = m_point_idx; |
| 125 | + size_t tmp_pnts = 1; |
| 126 | + |
| 127 | + QueVarFormat format = stream_array_format(&tmp_offset, &tmp_pnts); |
| 128 | + TauDouble (*xx)[3] = NULL; |
| 129 | + xx = stream_get_double3_format_var(st, POINT_COORDINATES, |
| 130 | + &format); |
| 131 | + |
| 132 | + if(xx == NULL) /* if coordinates are stored with old names */ |
| 133 | + { |
| 134 | + char *xyzname[3] = { POINT_X_COORDINATES, |
| 135 | + POINT_Y_COORDINATES, |
| 136 | + POINT_Z_COORDINATES }; |
| 137 | + int n_points = static_cast<int> (nVerts); |
| 138 | + read_xyz(st, &xx, &n_points, xyzname, &format); |
| 139 | + } |
| 140 | + |
| 141 | + x = xx[0][0]; |
| 142 | + y = xx[0][1]; |
| 143 | + z = xx[0][2]; |
| 144 | + check_free(xx); |
| 145 | + m_point_idx++; |
| 146 | +} |
| 147 | + |
| 148 | +void TAUFileWrapper::getNextCellConnectivity(GMGW_int& nConn, GMGW_int connect[]) const |
| 149 | +{ |
| 150 | + char *stream = "primgrid_read"; |
| 151 | + assert (m_cell_idx < nCells); |
| 152 | + |
| 153 | + long int cell_offset = m_cell_idx; |
| 154 | + if (cell_offset >= nTets) { |
| 155 | + cell_offset-= nTets; |
| 156 | + if (cell_offset >= nPrisms) { |
| 157 | + cell_offset-= nPrisms; |
| 158 | + if (cell_offset >= nHexes) { |
| 159 | + cell_offset-= nHexes; |
| 160 | + if (cell_offset >= nPyrs) { |
| 161 | + cell_offset-= nPyrs; |
| 162 | + if (cell_offset >= nBdryTris) { |
| 163 | + cell_offset-= nBdryTris; |
| 164 | + assert (cell_offset < nBdryQuads); |
| 165 | + } |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + size_t start[2], tmp_offset[2]; |
| 172 | + start[0] = cell_offset; |
| 173 | + start[1] = 0; |
| 174 | + tmp_offset[0] = 1; |
| 175 | + |
| 176 | + TauIndex act[8]; |
| 177 | + QueVarFormat format; |
| 178 | + |
| 179 | + int j; |
| 180 | + switch(m_cellTypes[m_cell_idx]) |
| 181 | + { |
| 182 | + case TET: |
| 183 | + nConn = tmp_offset[1] = 4; |
| 184 | + format = stream_array_format(start, tmp_offset); |
| 185 | + |
| 186 | + TauIndex (*act_tet)[4]; |
| 187 | + act_tet = stream_get_index4_format_var(stream, TETRA_POINTS, &format); |
| 188 | + memcpy(act,act_tet[0],tmp_offset[1]*sizeof(TauIndex)); |
| 189 | + check_free(act_tet); |
| 190 | + |
| 191 | + break; |
| 192 | + case PRISM: |
| 193 | + nConn = tmp_offset[1] = 6; |
| 194 | + format = stream_array_format(start, tmp_offset); |
| 195 | + |
| 196 | +// act = stream_get_index6_format_var(stream, PRISM_POINTS, &format); |
| 197 | + TauIndex (*act_prism)[6]; |
| 198 | + act_prism = stream_get_index6_format_var(stream, PRISM_POINTS, &format); |
| 199 | + memcpy(act,act_prism[0],tmp_offset[1]*sizeof(TauIndex)); |
| 200 | + check_free(act_prism); |
| 201 | + |
| 202 | + break; |
| 203 | + case HEX: |
| 204 | + nConn = tmp_offset[1] = 8; |
| 205 | + format = stream_array_format(start, tmp_offset); |
| 206 | + |
| 207 | +// act = stream_get_index8_format_var(stream, HEXA_POINTS, &format); |
| 208 | + TauIndex (*act_hexa)[8]; |
| 209 | + act_hexa = stream_get_index8_format_var(stream, HEXA_POINTS, &format); |
| 210 | + memcpy(act,act_hexa[0],tmp_offset[1]*sizeof(TauIndex)); |
| 211 | + check_free(act_hexa); |
| 212 | + |
| 213 | + break; |
| 214 | + case PYRAMID: |
| 215 | + nConn = tmp_offset[1] = 5; |
| 216 | + format = stream_array_format(start, tmp_offset); |
| 217 | + |
| 218 | +// act = stream_get_index5_format_var(stream, PYRA_POINTS, &format); |
| 219 | + TauIndex (*act_pyra)[5]; |
| 220 | + act_pyra = stream_get_index5_format_var(stream, PYRA_POINTS, &format); |
| 221 | + memcpy(act,act_pyra[0],tmp_offset[1]*sizeof(TauIndex)); |
| 222 | + check_free(act_pyra); |
| 223 | + |
| 224 | + break; |
| 225 | + case BDRY_TRI: |
| 226 | + nConn = tmp_offset[1] = 3; |
| 227 | + format = stream_array_format(start, tmp_offset); |
| 228 | + |
| 229 | +// act = stream_get_index3_format_var(stream, SURFTRI_POINTS, &format); |
| 230 | + TauIndex (*act_stri)[3]; |
| 231 | + act_stri = stream_get_index3_format_var(stream, SURFTRI_POINTS, &format); |
| 232 | + memcpy(act,act_stri[0],tmp_offset[1]*sizeof(TauIndex)); |
| 233 | + check_free(act_stri); |
| 234 | + |
| 235 | + break; |
| 236 | + case BDRY_QUAD: |
| 237 | + nConn = tmp_offset[1] = 4; |
| 238 | + format = stream_array_format(start, tmp_offset); |
| 239 | + |
| 240 | +// act = stream_get_index4_format_var(stream, SURFQUAD_POINTS, &format); |
| 241 | + TauIndex (*act_squad)[4]; |
| 242 | + act_squad = stream_get_index4_format_var(stream, SURFQUAD_POINTS, &format); |
| 243 | + memcpy(act,act_squad[0],tmp_offset[1]*sizeof(TauIndex)); |
| 244 | + check_free(act_squad); |
| 245 | + |
| 246 | + break; |
| 247 | + } |
| 248 | + for (j=0; j<nConn; j++) |
| 249 | + connect[j] = act[j]; |
| 250 | +// check_free(act); |
| 251 | + m_cell_idx++; |
| 252 | +} |
| 253 | + |
| 254 | +void TAUFileWrapper::seekStartOfCoords() const {m_point_idx = 0;} |
| 255 | +void TAUFileWrapper::seekStartOfConnectivity() const {m_cell_idx = 0;} |
0 commit comments