Write the data for the given attribute to file.
Write the given attribute to file using the CGNS format. The attribute may be a "mesh", "all" or some other predefined attribute.
Write the given attribute to file using the CGNS format. The attribute may be a "mesh", "all" or some other predefined attribute.
900 std::string fname(fname_in);
901 bool writeGhost = (ghosthandle ==
"write");
902 const Window* w = attr->window();
904 const Pane& pane = w->
pane(pane_id);
910 std::istringstream
sin(timelevel);
915 std::string timeLevel;
917 std::ostringstream sout;
919 timeLevel = sout.str();
922 DEBUG_MSG(
"Writing to file '" << fname <<
"', mode == '"
923 << (mode ?
"append'" :
"write'"));
924 DEBUG_MSG(
"Using mesh file '" << mfile <<
"'");
926 std::string::size_type loc = fname.rfind(
'/');
930 std::string prefix = fname.substr(0, loc+1);
945 CG_CHECK(cg_open, (fname.c_str(), MODE_WRITE, &fn));
948 CG_CHECK(cg_open, (fname.c_str(), MODE_MODIFY, &fn));
954 int i, B, nSteps = 0;
955 std::vector<double> times;
973 CG_CHECK(cg_units_write, (Kilogram, Meter, Second, Kelvin, Degree));
980 if (mode > 0 && cg_biter_read(fn, B, buffer, &nSteps) == 0) {
981 CG_CHECK(cg_goto, (fn, B,
"BaseIterativeData_t", 1,
"end"));
982 times.resize(nSteps + 1);
983 CG_CHECK(cg_array_read_as, (1, RealDouble, &(times[0])));
1001 for (timeIndex=0; timeIndex<nSteps; ++timeIndex)
1002 if (times[timeIndex] == timeValue) {
1008 if (timeIndex == nSteps) {
1010 times[timeIndex] = timeValue;
1014 CG_CHECK(cg_biter_write, (fn, B,
"TimeIterValues", nSteps));
1015 CG_CHECK(cg_goto, (fn, B,
"BaseIterativeData_t", 1,
"end"));
1016 CG_CHECK(cg_array_write, (
"TimeValues", RealDouble, 1, &nSteps,
1023 std::string zoneName;
1025 std::ostringstream sout;
1026 sout << std::setw(4) << std::setfill(
'0') << pane.
id();
1027 zoneName = sout.str();
1031 int Z, sizes[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1038 sizes[i++] = pane.
size_i() - 2 * ghost;
1039 sizes[i++] = pane.
size_j() - 2 * ghost;
1040 if (physDim > 2 && cellDim > 2)
1041 sizes[i++] = pane.
size_k() - 2 * ghost;
1042 sizes[i++] = sizes[0] - 1;
1043 sizes[i++] = sizes[1] - 1;
1044 if (physDim > 2 && cellDim > 2)
1045 sizes[i++] = sizes[2] - 1;
1051 zType = Unstructured;
1060 if (!mfile.empty()) {
1062 ((prefix + mfile).c_str(), MODE_READ, &meshfn));
1063 cg_zone_read(meshfn, 1, 1, zName, &(sizes[0]));
1071 zType, &Z, errorhandle));
1075 std::string gridName(
"Grid");
1076 if (timeLevel.length() + gridName.length() > 32)
1077 gridName.erase(32 - timeLevel.length());
1078 gridName += timeLevel;
1081 std::string winName(
"WinData");
1082 if (timeLevel.length() + winName.length() > 32)
1083 winName.erase(32 - timeLevel.length());
1084 winName += timeLevel;
1087 std::string paneName(
"PaneData");
1088 if (timeLevel.length() + paneName.length() > 32)
1089 paneName.erase(32 - timeLevel.length());
1090 paneName += timeLevel;
1093 std::string connName(
"ConnData");
1094 if (timeLevel.length() + connName.length() > 32)
1095 connName.erase(32 - timeLevel.length());
1096 connName += timeLevel;
1099 std::string elemName(
"ElemData");
1100 if (timeLevel.length() + elemName.length() > 32)
1101 elemName.erase(32 - timeLevel.length());
1102 elemName += timeLevel;
1105 std::string nodeName(
"NodeData");
1106 if (timeLevel.length() + nodeName.length() > 32)
1107 nodeName.erase(32 - timeLevel.length());
1108 nodeName += timeLevel;
1112 char (*gridNames)[32] = NULL;
1113 char (*nodeNames)[32] = NULL;
1115 if (mode > 0 && cg_ziter_read(fn, B, Z, buffer) == 0) {
1118 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"ZoneIterativeData_t", 1,
"end"));
1119 int numStr = nSteps;
1120 if (timeIndex >= nSteps)
1123 gridNames = (char(*)[32])
new char[32*numStr];
1124 std::fill_n((
char*)gridNames, 32 * numStr,
'\0');
1125 nodeNames = (char(*)[32])
new char[32*numStr];
1126 std::fill_n((
char*)nodeNames, 32 * numStr,
'\0');
1129 DataType_t dataType;
1133 (
"GridCoordinatesPointers", &A, &dataType, &rank, size,
1136 && size[1] == numStr),
1137 "GridCoordinatesPointers in ZoneIterativeData is corrupt");
1138 CG_CHECK(cg_array_read, (A, gridNames));
1139 if (timeIndex < nSteps) {
1141 "GridCoordinatesPointers in ZoneIterativeData is corrupt");
1143 std::strncpy(gridNames[timeIndex], gridName.c_str(), 32);
1149 (
"FlowSolutionsPointers", &A, &dataType, &rank, size,
1152 && size[1] == numStr),
1153 "FlowSolutionsPointers in ZoneIterativeData is corrupt");
1154 CG_CHECK(cg_array_read, (A, nodeNames));
1155 if (timeIndex < nSteps) {
1157 "FlowSolutionsPointers in ZoneIterativeData is corrupt");
1159 std::strncpy(nodeNames[timeIndex], nodeName.c_str(), 32);
1165 cg_ziter_write(fn, B, Z,
"ZoneIterativeData");
1167 gridNames = (char(*)[32])
new char[32];
1168 std::fill_n((
char*)gridNames, 32,
'\0');
1169 std::strncpy(gridNames[timeIndex], gridName.c_str(), 32);
1171 nodeNames = (char(*)[32])
new char[32];
1172 std::fill_n((
char*)nodeNames, 32,
'\0');
1173 std::strncpy(nodeNames[timeIndex], nodeName.c_str(), 32);
1178 if (timeIndex == nSteps) {
1187 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"ZoneIterativeData_t", 1,
"end"));
1190 (
"GridCoordinatesPointers", Character, 2, size, gridNames));
1193 (
"FlowSolutionsPointers", Character, 2, size, nodeNames));
1197 delete[] (
char*)gridNames;
1198 delete[] (
char*)nodeNames;
1200 std::vector<char> buf;
1201 int mfn = fn, mB = B, mZ = Z, nGC = 0, G = 0, numItems, dType;
1202 int rind[6] = { 0, 0, 0, 0, 0, 0 };
1204 std::string path(
"/"), range;
1206 path +=
'/' + zoneName +
'/';
1235 if (!mfile.empty()) {
1236 DEBUG_MSG(
"Writing to mesh file '" << mfile <<
"', mode == '"
1237 << (mode ?
"append'" :
"write'"));
1241 ((prefix + mfile).c_str(), mode ? MODE_MODIFY : MODE_WRITE, &mfn));
1250 sizes, zType, &mZ, errorhandle));
1259 CG_CHECK(cg_ngrids, (mfn, mB, mZ, &nGC));
1262 CG_CHECK(cg_grid_write, (mfn, mB, mZ,
"GridCoordinates", &G));
1263 if (mfile.empty()) {
1264 CG_CHECK(cg_goto, (mfn, mB,
"Zone_t", mZ,
"end"));
1265 CG_CHECK(cg_link_write, (gridName.c_str(),
"",
1266 (path +
"GridCoordinates").c_str()));
1269 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"end"));
1270 CG_CHECK(cg_ngrids, (fn, B, Z, &nGC));
1272 CG_CHECK(cg_link_write, (
"GridCoordinates", (mfile).c_str(),
1273 (path +
"GridCoordinates").c_str()));
1275 CG_CHECK(cg_link_write, (gridName.c_str(), (mfile).c_str(),
1276 (path +
"GridCoordinates").c_str()));
1279 if (mfile.empty()) {
1280 CG_CHECK(cg_grid_write, (mfn, mB, mZ, gridName.c_str(), &G));
1283 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"end"));
1284 CG_CHECK(cg_ngrids, (fn, B, Z, &nGC));
1286 CG_CHECK(cg_link_write, (
"GridCoordinates", (mfile).c_str(),
1287 (path +
"GridCoordinates").c_str()));
1289 CG_CHECK(cg_link_write, (gridName.c_str(), (mfile).c_str(),
1290 (path +
"GridCoordinates").c_str()));
1301 CG_CHECK(cg_goto, (mfn, mB,
"Zone_t", mZ,
"GridCoordinates_t", G,
1308 size[2] = (physDim == 3 && cellDim == 3 ? pane.
size_k(): 1);
1309 numItems = size[0] * size[1] * size[2];
1314 std::fill_n(rind, 6, 0);
1323 std::string ranges[3];
1324 int n, start = 0, finish = physDim;
1329 for (n=start; n<finish; ++
n) {
1334 const void* pData = nc->
pointer();
1335 bool isNull =
false;
1336 if (numItems <= 0) {
1338 std::fill(buf.begin(), buf.end(),
'\0');
1340 size[0] = size[1] = size[2] = 1;
1341 ranges[
n] =
"EMPTY";
1342 }
else if (pData == NULL) {
1345 std::fill(buf.begin(), buf.end(),
'\0');
1351 int stride = nc->
stride();
1354 buf.resize(dSize *
std::max(numItems, 1));
1355 for (i=0; i<numItems; ++
i)
1356 std::memcpy(&(buf[i*dSize]),
1357 &(((
const char*)pData)[i*stride*dSize]), dSize);
1361 #ifdef DEBUG_DUMP_PREFIX
1363 std::ofstream fout((DEBUG_DUMP_PREFIX + std::string(material) +
".nc" +
'_' + timeLevel +
".cgns").c_str(), std::ios_base::app);
1366 for (i=0; i<numItems; ++
i)
1367 fout << i <<
" : " << (
int)((
const char*)pData)[
i]
1371 for (i=0; i<numItems; ++
i)
1372 fout << i <<
" : " << ((
const int*)pData)[i] <<
'\n';
1375 for (i=0; i<numItems; ++
i)
1376 fout << i <<
" : " << ((
const float*)pData)[i] <<
'\n';
1379 for (i=0; i<numItems; ++
i)
1380 fout << i <<
" : " << ((
const double*)pData)[i]
1386 fout <<
"###########################################\n";
1388 #endif // DEBUG_DUMP_PREFIX
1391 (
const COM_TT*)pData,
1394 label =
"Coordinate";
1395 label += (char)(
'X' + n);
1401 rind, size, pData));
1403 DEBUG_MSG(
"Writing attribute '" << (
char)(
'x' + n) <<
"-nc', id == "
1404 << nc->
id() <<
", components == "
1410 for (n=start; n<finish; ++
n) {
1411 CG_CHECK(cg_goto, (mfn, mB,
"Zone_t", mZ,
"GridCoordinates_t", G,
1412 "DataArray_t", n + 1,
"end"));
1413 CG_CHECK(cg_descriptor_write, (
"Range", ranges[n].c_str()));
1414 DEBUG_MSG(
"Writing descriptor 'Range': '" << ranges[n] <<
'\'');
1415 if (!attr->unit().empty()) {
1417 DEBUG_MSG(
"Writing descriptor 'Units': '" << attr->unit()
1419 CG_CHECK(cg_descriptor_write, (
"Units", attr->unit().c_str()));
1422 DEBUG_MSG(
"Writing descriptor 'Units': 'm'");
1423 CG_CHECK(cg_descriptor_write, (
"Units",
"m"));
1434 CG_CHECK(cg_nsections, (mfn, mB, mZ, &nS));
1438 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"end"));
1440 std::vector<const Connectivity*> conns;
1445 std::vector<const Connectivity*>::const_iterator c;
1446 for (c=conns.begin(); c!=conns.end(); ++c) {
1447 int nItems = (*c)->size_of_items();
1448 int nGhost = (*c)->size_of_ghost_items();
1450 DEBUG_MSG(
"Writing attribute '" << (*c)->name() <<
"', nItems == "
1451 << nItems <<
", elemType == " << (*c)->element_type());
1453 label =
"Empty" + (*c)->name();
1454 S =
WriteElements(mfn, mB, mZ, (*c)->element_type(), nItems,
1455 NULL,
false, 0, (*c)->index_offset() + 1, label,
1457 }
else if ((*c)->pointer() == NULL) {
1458 label =
"Null" + (*c)->name();
1459 S =
WriteElements(mfn, mB, mZ, (*c)->element_type(), nItems,
1460 NULL,
false, 0, (*c)->index_offset() + 1, label,
1464 label = (*c)->name();
1465 S =
WriteElements(mfn, mB, mZ, (*c)->element_type(), nItems,
1466 (*c)->pointer(), ((*c)->stride() == 1),
1467 (*c)->capacity(), (*c)->index_offset() + 1,
1468 label, errorhandle);
1474 int elemRind[2] = { 0, nGhost };
1475 CG_CHECK(cg_goto, (mfn, mB,
"Zone_t", mZ,
"Elements_t", S,
"end"));
1476 CG_CHECK(cg_rind_write, (elemRind));
1480 if (!mfile.empty()) {
1492 CG_CHECK(cg_link_write, (label.c_str(), (mfile).c_str(),
1493 (path + label).c_str()));
1499 }
else if (!mfile.empty()) {
1504 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"end"));
1505 CG_CHECK(cg_ngrids, (fn, B, Z, &nGC));
1508 CG_CHECK(cg_link_write, (
"GridCoordinates", (mfile).c_str(),
1509 (path +
"GridCoordinates").c_str()));
1512 if (fname_in.compare(mfile)!=0){
1514 CG_CHECK(cg_link_write, (gridName.c_str(), (mfile).c_str(),
1515 (path +
"GridCoordinates").c_str()));
1518 CG_CHECK(cg_link_write, (gridName.c_str(),
"",
1519 (path +
"GridCoordinates").c_str()));
1525 ((prefix+mfile).c_str(), MODE_MODIFY, &mfn));
1532 sizes, zType, &mZ, errorhandle));
1534 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"end"));
1537 CG_CHECK(cg_nsections, (mfn, mB, mZ, &nS));
1540 ElementType_t eType;
1541 int min,
max, nBoundary, parent;
1542 for (S=1; S<=nS; ++S) {
1543 CG_CHECK(cg_section_read, (mfn, mB, mZ, S, label, &eType, &min, &max,
1544 &nBoundary, &parent));
1546 CG_CHECK(cg_link_write, (label, (mfile).c_str(), (path + label).c_str()));
1579 std::vector<const Attribute*> attrs;
1614 std::vector<const Attribute*>::const_iterator begin = attrs.begin();
1615 std::vector<const Attribute*>::const_iterator end = attrs.end();
1618 while (begin != end && (*begin)->id() != attr->id())
1621 "Rocout::write_attribute: can't find attribute in pane");
1625 std::vector<const Attribute*>::const_iterator a;
1632 for (a=begin; a!=end; ++a) {
1633 DEBUG_MSG(
"Writing attribute '" << (*a)->name() <<
"', id == "
1634 << (*a)->id() <<
", components == " << (*a)->size_of_components()
1635 <<
", location == '" << (*a)->location() <<
"\', datatype == "
1636 << (*a)->data_type());
1637 goToNextItem =
false;
1638 int A, size[3], nComp = (*a)->size_of_components(),
offset;
1639 const void* pData[9];
1640 dType = (*a)->data_type();
1641 switch ((*a)->location()) {
1644 size[0] = numItems = (*a)->size_of_items();
1645 size[1] = size[2] = 1;
1647 rind[1] = (*a)->size_of_ghost_items();
1653 CG_CHECK(cg_goto, (fn, B,
"IntegralData_t", T,
"end"));
1661 for (
int ii=1; ii<=
offset; ii++)
1663 cg_array_info(ii, arrName, &dT, &tt1, &tt2);
1665 if ((std::string(arrName)).find(std::string((*a)->name())) != std::string::npos) {
1667 goToNextItem =
true;
1674 for (A=0; A<nComp; ++
A) {
1675 CG_CHECK(cg_goto, (fn, B,
"IntegralData_t", T,
"end"));
1677 label = (*a)->name();
1683 pa = pane.
attribute((*a)->id() + A + 1);
1684 std::ostringstream sout;
1685 sout << label <<
'#' << A + 1 <<
"of" << nComp;
1689 #ifdef DEBUG_DUMP_PREFIX
1690 std::ofstream fout((DEBUG_DUMP_PREFIX + std::string(material) +
'.' + (*a)->name() +
'_' + timeLevel +
".cgns").c_str(), std::ios_base::app);
1691 #endif // DEBUG_DUMP_PREFIX
1692 bool isNull =
false;
1694 if (numItems <= (writeGhost ? 0 : rind[1])) {
1696 std::fill(buf.begin(), buf.end(),
'\0');
1697 pData[
A] = &(buf[0]);
1702 }
else if (pData[A] == NULL) {
1705 std::fill(buf.begin(), buf.end(),
'\0');
1706 pData[
A] = &(buf[0]);
1711 int stride = pa->
stride();
1714 buf.resize(dSize *
std::max(numItems, 1));
1715 for (i=0; i<numItems; ++
i)
1716 std::memcpy(&(buf[i*dSize]),
1717 &(((
const char*)pData[A])[i*stride*dSize]), dSize);
1718 pData[
A] = &(buf[0]);
1721 #ifdef DEBUG_DUMP_PREFIX
1725 for (i=0; i<numItems; ++
i)
1726 fout << i <<
" : " << (
int)((
const char*)(pData[A]))[i]
1730 for (i=0; i<numItems; ++
i)
1731 fout << i <<
" : " << ((
const int*)(pData[
A]))[
i] <<
'\n';
1734 for (i=0; i<numItems; ++
i)
1735 fout << i <<
" : " << ((
const float*)(pData[
A]))[
i] <<
'\n';
1738 for (i=0; i<numItems; ++
i)
1739 fout << i <<
" : " << ((
const double*)(pData[
A]))[
i]
1745 fout <<
"###########################################\n";
1747 #endif // DEBUG_DUMP_PREFIX
1752 (
const COM_TT*)pData[A], range));
1756 1, size, pData[
A]));
1759 1, rind, size, pData[
A]));
1762 CG_CHECK(cg_goto, (fn, B,
"IntegralData_t", T,
"DataArray_t",
1765 CG_CHECK(cg_descriptor_write, (
"Range", range.c_str()));
1766 DEBUG_MSG(
"Writing descriptor 'Range': '" << range <<
'\'');
1767 if (!pa->
unit().empty()) {
1769 CG_CHECK(cg_descriptor_write, (
"Units", pa->
unit().c_str()));
1770 DEBUG_MSG(
"Writing descriptor 'Units': '" << pa->
unit() <<
'\'');
1775 std::ostringstream sout;
1777 CG_CHECK(cg_descriptor_write, (
"Ghost", sout.str().c_str()));
1778 DEBUG_MSG(
"Writing descriptor 'Ghost': '" << sout.str() <<
'\'');
1784 size[0] = numItems = (*a)->size_of_items();
1785 size[1] = size[2] = 1;
1787 rind[1] = (*a)->size_of_ghost_items();
1789 DEBUG_MSG(
"numItems == " << numItems <<
", numGhostItems == "
1792 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"end"));
1796 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"IntegralData_t", T,
"end"));
1804 for (
int ii=1; ii<=
offset; ii++)
1806 cg_array_info(ii, arrName, &dT, &tt1, &tt2);
1808 if ((std::string(arrName)).find(std::string((*a)->name())) != std::string::npos) {
1810 goToNextItem =
true;
1820 for (A=0; A<nComp; ++
A) {
1821 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"IntegralData_t", T,
"end"));
1823 label = (*a)->name();
1829 pa = pane.
attribute((*a)->id() + A + 1);
1830 std::ostringstream sout;
1831 sout << label <<
'#' << A + 1 <<
"of" << nComp;
1835 #ifdef DEBUG_DUMP_PREFIX
1836 std::ofstream fout((DEBUG_DUMP_PREFIX + std::string(material) +
'.' + (*a)->name() +
'_' + timeLevel +
".cgns").c_str(), std::ios_base::app);
1837 #endif // DEBUG_DUMP_PREFIX
1838 bool isNull =
false;
1840 if (numItems <= (writeGhost ? 0 : rind[1])) {
1842 std::fill(buf.begin(), buf.end(),
'\0');
1843 pData[
A] = &(buf[0]);
1848 }
else if (pData[A] == NULL) {
1851 std::fill(buf.begin(), buf.end(),
'\0');
1852 pData[
A] = &(buf[0]);
1857 int stride = pa->
stride();
1860 buf.resize(dSize *
std::max(numItems, 1));
1861 for (i=0; i<numItems; ++
i)
1862 std::memcpy(&(buf[i*dSize]),
1863 &(((
const char*)pData[A])[i*stride*dSize]), dSize);
1864 pData[
A] = &(buf[0]);
1867 #ifdef DEBUG_DUMP_PREFIX
1871 for (i=0; i<numItems; ++
i)
1872 fout << i <<
" : " << (
int)((
const char*)(pData[A]))[i]
1876 for (i=0; i<numItems; ++
i)
1877 fout << i <<
" : " << ((
const int*)(pData[
A]))[
i] <<
'\n';
1880 for (i=0; i<numItems; ++
i)
1881 fout << i <<
" : " << ((
const float*)(pData[
A]))[
i] <<
'\n';
1884 for (i=0; i<numItems; ++
i)
1885 fout << i <<
" : " << ((
const double*)(pData[
A]))[
i]
1891 fout <<
"###########################################\n";
1893 #endif // DEBUG_DUMP_PREFIX
1897 (
const COM_TT*)pData[A], range));
1901 1, size, pData[
A]));
1904 1, rind, size, pData[
A]));
1911 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"IntegralData_t", T,
1912 "DataArray_t", A +
offset,
"end"));
1914 CG_CHECK(cg_descriptor_write, (
"Range", range.c_str()));
1915 DEBUG_MSG(
"Writing descriptor 'Range' == '" << range <<
'\'');
1916 if (!pa->
unit().empty()) {
1918 DEBUG_MSG(
"Writing descriptor 'Units' == '" << pa->
unit() <<
'\'');
1919 CG_CHECK(cg_descriptor_write, (
"Units", pa->
unit().c_str()));
1924 std::ostringstream sout;
1926 CG_CHECK(cg_descriptor_write, (
"Ghost", sout.str().c_str()));
1927 DEBUG_MSG(
"Writing descriptor 'Ghost' == '" << sout.str() <<
'\'');
1934 DEBUG_MSG(
"Special COM_RIDGES handling: zType == "
1935 << (zType == Structured ?
"Structured" :
"Unstructured")
1936 <<
", size_of_components() == "
1937 << (*a)->size_of_components() <<
", size_of_items() == "
1938 << (*a)->size_of_items());
1939 if (zType == Unstructured && (*a)->size_of_components() == 2
1940 && (*a)->size_of_items() > 0) {
1942 std::string newName(material);
1943 newName +=
"_ridges";
1946 <<
"\", cellDim == 1, physDim == " << physDim);
1951 CG_CHECK(cg_goto, (fn, RB,
"end"));
1952 CG_CHECK(cg_units_write, (Kilogram, Meter, Second, Kelvin, Degree));
1954 std::string rpath(
"/");
1958 if (cg_goto(fn, RB,
"BaseIterativeData_t", 1,
"end") != 0) {
1961 << rpath +
"TimeIterValues");
1962 CG_CHECK(cg_goto, (fn, RB,
"end"));
1963 CG_CHECK(cg_link_write, (
"TimeIterValues",
"",
1964 (rpath +
"TimeIterValues").c_str()));
1970 int RZ, rsizes[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
1971 rsizes[0] = sizes[0];
1972 rsizes[1] = (*a)->size_of_real_items();
1973 DEBUG_MSG(
"Creating zone \"" << zoneName <<
"\", size == [ "
1974 << rsizes[0] <<
", " << rsizes[1] <<
" ]");
1977 Unstructured, &RZ, errorhandle));
1980 if (cg_goto(fn, RB,
"Zone_t", RZ,
1981 "ZoneIterativeData_t", 1,
"end") != 0) {
1982 CG_CHECK(cg_goto, (fn, RB,
"Zone_t", RZ,
"end"));
1987 DEBUG_MSG(
"Linking ZoneIterativeData to "
1988 << rpath +
"ZoneIterativeData");
1989 CG_CHECK(cg_link_write, (
"ZoneIterativeData",
"",
1990 (rpath +
"ZoneIterativeData").c_str()));
1994 << rpath +
"GridCoordinates");
1995 CG_CHECK(cg_link_write, (
"GridCoordinates",
"",
1996 (rpath +
"GridCoordinates").c_str()));
1997 DEBUG_MSG(
"Linking " << gridName <<
" to " << rpath + gridName);
1998 CG_CHECK(cg_link_write, (gridName.c_str(),
"",
1999 (rpath + gridName).c_str()));
2002 DEBUG_MSG(
"Linking " << nodeName <<
" to "
2003 << rpath + nodeName);
2004 CG_CHECK(cg_link_write, (nodeName.c_str(),
"",
2005 (rpath + nodeName).c_str()));
2011 DEBUG_MSG(
"Retreived the 'ridges' components: '" << pa[0]->name()
2012 <<
"' and '" << pa[1]->name() <<
'\'');
2018 DEBUG_MSG(
"Writing " << nItems <<
" BAR_2 elements (with "
2019 << nGhost <<
" ghost elements)");
2022 COM_assertion((pa[0]->pointer()==NULL) == (pa[1]->pointer()==NULL));
2028 label = (*a)->name();
2029 std::vector<int> bar(2 * nItems);
2030 for (i=0; i<2; ++
i) {
2031 int* ptr = (
int*)pa[i]->pointer();
2032 int j, stride =
std::max(pa[i]->stride(), 1);
2033 for (j=0; j<nItems; ++
j)
2034 bar[2*j+i] = ptr[j*stride];
2037 &bar[0],
false, 0, 1, label, errorhandle);
2041 int elemRind[2] = { 0, nGhost };
2043 (fn, RB,
"Zone_t", RZ,
"Elements_t", RS,
"end"));
2044 CG_CHECK(cg_rind_write, (elemRind));
2047 }
else if ((*a)->name() ==
"bcflag") {
2054 size[0] = numItems = (*a)->size_of_items();
2055 size[1] = size[2] = 1;
2057 rind[1] = (*a)->size_of_ghost_items();
2059 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"end"));
2063 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"IntegralData_t", T,
"end"));
2067 for (A=0; A<nComp; ++
A) {
2068 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"IntegralData_t", T,
"end"));
2070 label = (*a)->name();
2076 pa = pane.
attribute((*a)->id() + A + 1);
2077 std::ostringstream sout;
2078 sout << label <<
'#' << A + 1 <<
"of" << nComp;
2082 #ifdef DEBUG_DUMP_PREFIX
2083 std::ofstream fout((DEBUG_DUMP_PREFIX + std::string(material) +
'.' + (*a)->name() +
'_' + timeLevel +
".cgns").c_str(), std::ios_base::app);
2084 #endif // DEBUG_DUMP_PREFIX
2085 bool isNull =
false;
2087 if (numItems <= (writeGhost ? 0 : rind[1])) {
2089 std::fill(buf.begin(), buf.end(),
'\0');
2090 pData[
A] = &(buf[0]);
2095 }
else if (pData[A] == NULL) {
2098 std::fill(buf.begin(), buf.end(),
'\0');
2099 pData[
A] = &(buf[0]);
2104 int stride = pa->
stride();
2107 buf.resize(dSize *
std::max(numItems, 1));
2108 for (i=0; i<numItems; ++
i)
2109 std::memcpy(&(buf[i*dSize]),
2110 &(((
const char*)pData[A])[i*stride*dSize]), dSize);
2111 pData[
A] = &(buf[0]);
2114 #ifdef DEBUG_DUMP_PREFIX
2118 for (i=0; i<numItems; ++
i)
2119 fout << i <<
" : " << (
int)((
const char*)(pData[A]))[i]
2123 for (i=0; i<numItems; ++
i)
2124 fout << i <<
" : " << ((
const int*)(pData[
A]))[
i] <<
'\n';
2127 for (i=0; i<numItems; ++
i)
2128 fout << i <<
" : " << ((
const float*)(pData[
A]))[
i] <<
'\n';
2131 for (i=0; i<numItems; ++
i)
2132 fout << i <<
" : " << ((
const double*)(pData[
A]))[
i]
2138 fout <<
"###########################################\n";
2140 #endif // DEBUG_DUMP_PREFIX
2144 (
const COM_TT*)pData[A], range));
2148 1, size, pData[
A]));
2151 1, rind, size, pData[
A]));
2154 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"IntegralData_t", T,
2155 "DataArray_t", A +
offset,
"end"));
2157 CG_CHECK(cg_descriptor_write, (
"Range", range.c_str()));
2158 DEBUG_MSG(
"Writing descriptor 'Range': '" << range <<
'\'');
2159 if (!pa->
unit().empty()) {
2161 CG_CHECK(cg_descriptor_write, (
"Units", pa->
unit().c_str()));
2162 DEBUG_MSG(
"Writing descriptor 'Units': '" << pa->
unit() <<
'\'');
2167 std::ostringstream sout;
2169 CG_CHECK(cg_descriptor_write, (
"Ghost", sout.str().c_str()));
2170 DEBUG_MSG(
"Writing descriptor 'Ghost': '" << sout.str() <<
'\'');
2181 size[2] = cellDim > 2 ? pane.
size_k() : 1;
2183 size[1] = size[2] = 1;
2185 numItems = size[0] * size[1] * size[2];
2189 size[0] = numItems = (*a)->size_of_items();
2190 size[1] = size[2] = 1;
2191 std::fill_n(rind, 6, 0);
2192 rind[1] = (*a)->size_of_ghost_items();
2198 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"FlowSolution_t", T,
"end"));
2199 CG_CHECK(cg_gridlocation_write, (Vertex));
2210 for (A=0; A<nComp; ++
A) {
2211 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"FlowSolution_t", T,
"end"));
2213 label = (*a)->name();
2219 pa = pane.
attribute((*a)->id() + A + 1);
2220 if (nComp == physDim) {
2221 label += (char)(
'X' + (
char)
A);
2222 }
else if (nComp == physDim * physDim) {
2223 label += (char)(
'X' + (
char)(A / physDim));
2224 label += (char)(
'X' + (
char)(A % physDim));
2226 std::ostringstream sout;
2227 sout << label <<
'#' << A + 1 <<
"of" << nComp;
2232 #ifdef DEBUG_DUMP_PREFIX
2233 std::ofstream fout((DEBUG_DUMP_PREFIX + std::string(material) +
'.' + (*a)->name() +
'_' + timeLevel +
".cgns").c_str(), std::ios_base::app);
2234 #endif // DEBUG_DUMP_PREFIX
2235 bool isNull =
false;
2237 if (numItems <= 0) {
2239 std::fill(buf.begin(), buf.end(),
'\0');
2240 pData[
A] = &(buf[0]);
2241 size[0] = size[1] = size[2] = 1;
2243 }
else if (pData[A] == NULL) {
2246 std::fill(buf.begin(), buf.end(),
'\0');
2247 pData[
A] = &(buf[0]);
2252 int stride = pa->
stride();
2255 buf.resize(dSize *
std::max(numItems, 1));
2256 for (i=0; i<numItems; ++
i) {
2257 std::memcpy(&(buf[i*dSize]),
2258 &(((
const char*)pData[A])[i*stride*dSize]), dSize);
2260 pData[
A] = &(buf[0]);
2262 #ifdef DEBUG_DUMP_PREFIX
2266 for (i=0; i<numItems; ++
i)
2267 fout << i <<
" : " << (
int)((
const char*)(pData[A]))[i]
2271 for (i=0; i<numItems; ++
i)
2272 fout << i <<
" : " << ((
const int*)(pData[
A]))[
i] <<
'\n';
2275 for (i=0; i<numItems; ++
i)
2276 fout << i <<
" : " << ((
const float*)(pData[
A]))[
i] <<
'\n';
2279 for (i=0; i<numItems; ++
i)
2280 fout << i <<
" : " << ((
const double*)(pData[
A]))[
i]
2286 fout <<
"###########################################\n";
2288 #endif // DEBUG_DUMP_PREFIX
2292 (
const COM_TT*)pData[A], range));
2295 DEBUG_MSG(
"Calling cg_array_write( name == '" << label
2296 <<
"', dataType == "
2297 << (
COM2CGNS(dType) == RealSingle ?
"float"
2298 : (
COM2CGNS(dType) == RealDouble ?
"double"
2299 : (
COM2CGNS(dType) == Character ?
"char" :
"int?")))
2300 <<
", rank == " << rank <<
", size[] = { " << size[0]
2301 <<
", " << size[1] <<
", " << size[2] <<
" } )");
2303 rank, size, pData[
A]));
2305 DEBUG_MSG(
"Calling cg_array_core_write( name == '" << label
2306 <<
"', dataType == "
2307 << (
COM2CGNS(dType) == RealSingle ?
"float"
2308 : (
COM2CGNS(dType) == RealDouble ?
"double"
2309 : (
COM2CGNS(dType) == Character ?
"char" :
"int?")))
2310 <<
", rank == " << rank <<
", rind[] = { " << rind[0]
2311 <<
", " << rind[1] <<
", " << rind[2] <<
", " << rind[3]
2312 <<
", " << rind[4] <<
", " << rind[5] <<
" }, size[] = { "
2313 << size[0] <<
", " << size[1] <<
", " << size[2]
2316 rank, rind, size, pData[
A]));
2319 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"FlowSolution_t", T,
2320 "DataArray_t", A +
offset,
"end"));
2322 DEBUG_MSG(
"Calling cg_descriptor_write( name == 'Range', "
2323 <<
"value == '" << range <<
"' )");
2324 CG_CHECK(cg_descriptor_write, (
"Range", range.c_str()));
2325 if (!pa->
unit().empty()) {
2327 DEBUG_MSG(
"Calling cg_descriptor_write( name == 'Units', "
2328 <<
"value == '" << pa->
unit() <<
"' )");
2329 CG_CHECK(cg_descriptor_write, (
"Units", pa->
unit().c_str()));
2336 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"FlowSolution_t", T,
2337 "DataArray_t",
offset,
"end"));
2340 (
const COM_TT**)pData,
2342 CG_CHECK(cg_descriptor_write, (
"MagnitudeRange", range.c_str()));
2343 }
else if (nComp == 9) {
2344 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"FlowSolution_t", T,
2345 "DataArray_t",
offset,
"end"));
2348 (
const COM_TT**)pData, range));
2349 CG_CHECK(cg_descriptor_write, (
"TraceRange", range.c_str()));
2356 size[0] = pane.
size_i() - 1;
2358 size[1] = pane.
size_j() - 1;
2359 size[2] = cellDim > 2 ? pane.
size_k() - 1 : 1;
2361 size[1] = size[2] = 1;
2363 numItems = size[0] * size[1] * size[2];
2367 size[0] = numItems = (*a)->size_of_items();
2368 size[1] = size[2] = 1;
2369 std::fill_n(rind, 6, 0);
2370 rind[1] = (*a)->size_of_ghost_items();
2376 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"FlowSolution_t", T,
"end"));
2377 CG_CHECK(cg_gridlocation_write, (CellCenter));
2393 for (
int ii=1; ii<=
offset; ii++)
2395 cg_array_info(ii, arrName, &dT, &tt1, &tt2);
2397 if ((std::string(arrName)).find(std::string((*a)->name())) != std::string::npos) {
2399 goToNextItem =
true;
2410 for (A=0; A<nComp; ++
A) {
2412 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"FlowSolution_t", T,
"end"));
2415 label = (*a)->name();
2422 pa = pane.
attribute((*a)->id() + A + 1);
2423 if (nComp == physDim) {
2424 label += (char)(
'X' + (
char)
A);
2425 }
else if (nComp == physDim * physDim) {
2426 label += (char)(
'X' + (
char)(A / physDim));
2427 label += (char)(
'X' + (
char)(A % physDim));
2429 std::ostringstream sout;
2430 sout << label <<
'#' << A + 1 <<
"of" << nComp;
2436 #ifdef DEBUG_DUMP_PREFIX
2437 std::ofstream fout((DEBUG_DUMP_PREFIX + std::string(material) +
'.' + (*a)->name() +
'_' + timeLevel +
".cgns").c_str(), std::ios_base::app);
2438 #endif // DEBUG_DUMP_PREFIX
2439 bool isNull =
false;
2442 if (numItems <= 0) {
2445 std::fill(buf.begin(), buf.end(),
'\0');
2446 pData[
A] = &(buf[0]);
2447 size[0] = size[1] = size[2] = 1;
2449 }
else if (pData[A] == NULL) {
2453 std::fill(buf.begin(), buf.end(),
'\0');
2454 pData[
A] = &(buf[0]);
2460 int stride = pa->
stride();
2465 buf.resize(dSize *
std::max(numItems, 1));
2467 for (i=0; i<numItems; ++
i) {
2468 std::memcpy(&(buf[i*dSize]),
2469 &(((
const char*)pData[A])[i*stride*dSize]), dSize);
2472 pData[
A] = &(buf[0]);
2474 #ifdef DEBUG_DUMP_PREFIX
2478 for (i=0; i<numItems; ++
i)
2479 fout << i <<
" : " << (
int)((
const char*)(pData[A]))[i]
2483 for (i=0; i<numItems; ++
i)
2484 fout << i <<
" : " << ((
const int*)(pData[
A]))[
i] <<
'\n';
2487 for (i=0; i<numItems; ++
i)
2488 fout << i <<
" : " << ((
const float*)(pData[
A]))[
i] <<
'\n';
2491 for (i=0; i<numItems; ++
i)
2492 fout << i <<
" : " << ((
const double*)(pData[
A]))[
i]
2498 fout <<
"###########################################\n";
2500 #endif // DEBUG_DUMP_PREFIX
2504 (
const COM_TT*)pData[A], range));
2507 DEBUG_MSG(
"Calling cg_array_write( name == '" << label
2508 <<
"', dataType == "
2509 << (
COM2CGNS(dType) == RealSingle ?
"float"
2510 : (
COM2CGNS(dType) == RealDouble ?
"double"
2511 : (
COM2CGNS(dType) == Character ?
"char" :
"int?")))
2512 <<
", rank == " << rank <<
", size[] = { " << size[0]
2513 <<
", " << size[1] <<
", " << size[2] <<
" } )");
2515 rank, size, pData[
A]));
2517 DEBUG_MSG(
"Calling cg_array_core_write( name == '" << label
2518 <<
"', dataType == "
2519 << (
COM2CGNS(dType) == RealSingle ?
"float"
2520 : (
COM2CGNS(dType) == RealDouble ?
"double"
2521 : (
COM2CGNS(dType) == Character ?
"char" :
"int?")))
2522 <<
", rank == " << rank <<
", rind[] = { " << rind[0]
2523 <<
", " << rind[1] <<
", " << rind[2] <<
", " << rind[3]
2524 <<
", " << rind[4] <<
", " << rind[5] <<
" }, size[] = { "
2525 << size[0] <<
", " << size[1] <<
", " << size[2]
2528 rank, rind, size, pData[
A]));
2531 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"FlowSolution_t", T,
2532 "DataArray_t", A +
offset,
"end"));
2534 DEBUG_MSG(
"Calling cg_descriptor_write( name == 'Range', "
2535 <<
"value == '" << range <<
"' )");
2536 CG_CHECK(cg_descriptor_write, (
"Range", range.c_str()));
2537 if (!pa->
unit().empty()) {
2539 DEBUG_MSG(
"Calling cg_descriptor_write( name == 'Units', "
2540 <<
"value == '" << pa->
unit() <<
"' )");
2541 CG_CHECK(cg_descriptor_write, (
"Units", pa->
unit().c_str()));
2549 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"FlowSolution_t", T,
2550 "DataArray_t",
offset,
"end"));
2553 (
const COM_TT**)pData,
2555 CG_CHECK(cg_descriptor_write, (
"MagnitudeRange", range.c_str()));
2556 }
else if (nComp == 9) {
2557 CG_CHECK(cg_goto, (fn, B,
"Zone_t", Z,
"FlowSolution_t", T,
2558 "DataArray_t",
offset,
"end"));
2561 (
const COM_TT**)pData, range));
2562 CG_CHECK(cg_descriptor_write, (
"TraceRange", range.c_str()));
static int cg_base_find_or_create(int fn, const char *name, int cellDim, int physDim, int *B, const std::string &errorhandle)
Find the named Base_t node, or create one if it doesn't exist.
Size size_of_real_elements() const
Get the number of real elements in the pane (excluding ghost elements).
A Pane object contains a mesh, pane attribute, and field variables.
void FindTraceRange(int physDim, int rank, const int *size, const int *rind, const T **pData, std::string &range)
Find the minimum and maximum core trace.
void FindRange(int rank, const int *size, const int *rind, const T *pData, std::string &range)
Find the minimum and maximum core value.
#define COM_assertion(EX)
Error checking utility similar to the assert macro of the C language.
Automatically save and restore the current working directory.
An Attribute object is a data member of a window.
#define COM_assertion_msg(EX, msg)
static DataType_t COM2CGNS(int dType)
Convert a Roccom data type to a CGNS data type.
void FindMagnitudeRange(int physDim, int rank, const int *size, const int *rind, const T **pData, std::string &range)
Find the minimum and maximum core magnitude.
static int cg_integral_find_or_create(const char *name, int *I, const std::string &errorhandle)
Find the named IntegralData_t node, or create one if it doesn't exist.
static int cg_zone_find_or_create(int fn, int B, const char *name, const int *sizes, ZoneType_t zType, int *Z, const std::string &errorhandle)
Find the named Zone_t node, or create one if it doesn't exist.
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
A Window object contains multiple panes and multiple data attributes.
static void cg_exponents_as_string_write(std::string unit, const std::string &errorhandle)
bool is_structured() const
Is mesh of the pane structured?
Size size_of_ghost_nodes() const
Get the number of ghost nodes.
Automatically close open files, datasets, etc.
real *8 function offset(vNorm, x2, y2, z2)
Size size_k() const
Get the number of nodes in k-dimension if the mesh is structured.
Shorter_size location() const
Obtain the location of the attribute.
Attribute * attribute(const std::string &a)
Obtain the attribute from given name.
const std::string & unit() const
Obtain the unit of the attribute.
const void * pointer() const
Obtain a constant pointer to the physical address.
int size_of_ghost_items() const
Obtain the number of ghost items in the attribute.
static int WriteElements(int fn, int B, int Z, int eType, int nElems, const int *elems, bool isStaggered, int length, int offset, const std::string &label, const std::string &errorhandle)
Build and write out an Elements_t node.
#define SwitchOnCOMDataType(dType, funcCall)
Call a templated function based on a Roccom data type.
Size size_of_ghost_layers() const
Dimension of the pane.
static int cg_array_info_by_name(const char *name, int *A, DataType_t *dType, int *rank, int *size, const std::string &errorhandle)
Return information on the named DataArray_t node.
Size size_j() const
Get the number of nodes in j-dimension if the mesh is structured.
static int get_sizeof(MPI_Datatype i)
Get the size of a given MPI data type.
int stride() const
Obtain the stride of the attribute in base datatype.
bool is_unstructured() const
Is mesh of the pane unstructured?
static int cg_sol_find_or_create(int fn, int B, int Z, const char *name, GridLocation_t location, int *S, const std::string &errorhandle)
Find the named FlowSolution_t node, or create one if it doesn't exist.
int size_of_real_items() const
Obtain the number of real items in the attribute.
void elements(std::vector< Connectivity * > &es)
Obtain all the element connectivities of the pane.
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Size size_of_real_nodes() const
Get the number of real nodes in the pane (excluding ghost nodes).
Pane & pane(const int pane_id, bool insert=false)
Find the pane with given ID. If not found, insert a pane with given ID.
Size size_of_nodes() const
Get the total number of nodes in the pane (including ghost nodes).
int dimension() const
Dimension of the pane.
static int cg_array_core_write(char const *name, DataType_t dType, int rank, int *rind, int const *size, void const *data)
COM_Type data_type() const
Obtain the data type of each component of the attribute.
int id() const
Obtain the id (or index) of the attribute.
Size size_i() const
Get the number of nodes in i-dimension if the mesh is structured.
void attributes(std::vector< Attribute * > &as)
Obtain all the attributes of the pane.
#define CG_CHECK(routine, args)
Perform CGNS error-checking.
int id() const
Get the ID of the pane.
int size_of_items() const
Obtain the number of items in the attribute.
int size_of_components() const
Obtain the number of components in the attribute.