40 #include <boost/core/ignore_unused.hpp>
53 "QUADRILATERAL",
"TETRAHEDRON",
"BRICK",
54 "POLYGON",
"POLYHEDRON"};
58 OutputTecplot::create,
59 "Writes a Tecplot file.");
60 ModuleKey OutputTecplotBinary::m_className =
63 "Writes a Tecplot file in binary plt format.");
70 "Write double-precision format data:"
71 "more accurate but more disk space"
82 if (
m_config[
"writemultiplefiles"].as<bool>())
97 template <
typename T>
void WriteStream(std::ostream &outfile, T data)
100 outfile.write(
reinterpret_cast<char *
>(&tmp),
sizeof(T));
110 template <>
void WriteStream(std::ostream &outfile, std::string data)
113 for (std::string::size_type i = 0; i < data.size(); ++i)
115 char strChar = data[i];
128 template <
typename T>
133 outfile.write(
reinterpret_cast<char *
>(&data[0]),
134 data.size() *
sizeof(T));
141 template <
typename T>
146 outfile.write(
reinterpret_cast<char *
>(&data[0]),
147 data.size() *
sizeof(T));
156 if (fPts->GetNpoints() == 0)
161 int rank =
m_f->m_comm->GetRank();
167 fPts->GetConnectivity(
m_conn);
169 switch (fPts->GetPtsType())
198 for (
int i = 0; i <
m_conn.size(); ++i)
207 for (
int i = 0; i <
m_conn.size(); ++i)
214 ASSERTL0(
false,
"This points type is not supported yet.");
241 int nBases =
m_f->m_exp[0]->GetExp(0)->GetNumBases();
244 int totpoints =
m_f->m_exp[0]->GetTotPoints();
246 if (
m_f->m_numHomogeneousDir > 0)
248 int nPlanes =
m_f->m_exp[0]->GetZIDs().size();
259 totpoints +=
m_f->m_exp[0]->GetPlane(0)->GetTotPoints();
261 nBases +=
m_f->m_numHomogeneousDir;
299 for (
int i = 0; i <
m_f->m_variables.size(); ++i)
303 m_f->m_exp[i]->UpdatePhys(), 1,
310 for (
int i = 0; i <
m_f->m_variables.size(); ++i)
319 int points_on_plane =
m_f->m_exp[0]->GetPlane(0)->GetTotPoints();
320 const int offset = totpoints - points_on_plane;
335 for (
int i = 0; i <
m_f->m_variables.size(); ++i)
347 boost::ignore_unused(vm);
350 "OutputTecplot can't write using only FieldData.");
355 boost::ignore_unused(vm);
357 int nprocs =
m_f->m_comm->GetSize();
358 string returnstr(filename);
363 int rank =
m_f->m_comm->GetRank();
364 int dot = filename.find_last_of(
'.');
365 string ext = filename.substr(dot, filename.length() - dot);
366 string procId =
"_P" + boost::lexical_cast<std::string>(rank);
367 string start = filename.substr(0, dot);
368 returnstr = start + procId + ext;
370 return fs::path(returnstr);
374 po::variables_map &vm)
382 std::string coordVars[] = {
"x",
"y",
"z"};
383 std::vector<string> variables =
m_f->m_variables;
384 variables.insert(variables.begin(), coordVars, coordVars +
m_coordim);
386 int nprocs =
m_f->m_comm->GetSize();
387 int rank =
m_f->m_comm->GetRank();
390 string filename =
m_config[
"outfile"].as<
string>();
396 outfile.open(outFile.c_str(),
m_binary ? ios::binary : ios::out);
411 for (
int i = 0; i <
m_conn.size(); ++i)
447 std::vector<std::string> &var)
449 outfile <<
"Variables = " << var[0];
451 for (
int i = 1; i < var.size(); ++i)
453 outfile <<
", " << var[i];
456 outfile << std::endl << std::endl;
466 std::vector<std::string> &var)
474 outfile <<
"#!TDV112";
483 std::string
title =
"";
489 for (
int i = 0; i < var.size(); ++i)
503 bool useDoubles =
m_config[
"double"].as<
bool>();
507 int precision = std::numeric_limits<double>::max_digits10;
508 outfile << std::setprecision(precision);
522 outfile <<
"Zone, N=" << nPoints <<
", E=" <<
m_numBlocks
529 for (
int j = 0; j <
m_fields.size(); ++j)
531 for (
int i = 0; i <
m_fields[j].size(); ++i)
533 if ((!(i % 1000)) && i)
535 outfile << std::endl;
540 for (
int n = 1; n <
m_f->m_comm->GetSize(); ++n)
545 m_f->m_comm->Recv(n, tmp);
549 if ((!(i % 1000)) && i)
551 outfile << std::endl;
553 outfile << tmp[i] <<
" ";
557 outfile << std::endl;
564 for (
int i = 0; i <
m_fields.size(); ++i)
574 for (
int j = 0; j <
m_fields.size(); ++j)
576 for (
int i = 0; i <
m_fields[j].size(); ++i)
578 if ((!(i % 1000)) && i)
580 outfile << std::endl;
584 outfile << std::endl;
593 std::string dirs[] = {
"I",
"J",
"K"};
597 outfile <<
", " << dirs[i] <<
"=" <<
m_numPoints[i];
599 outfile <<
", F=POINT" << std::endl;
605 for (
int i = 0; i <
m_fields[0].size(); ++i)
607 for (
int j = 0; j <
m_fields.size(); ++j)
609 outfile << setw(12) <<
m_fields[j][i] <<
" ";
611 outfile << std::endl;
614 for (
int n = 1; n <
m_f->m_comm->GetSize(); ++n)
618 m_f->m_comm->Recv(n, tmp);
619 for (
int j = 0; j <
m_fields.size(); ++j)
621 outfile << setw(12) << tmp[j] <<
" ";
623 outfile << std::endl;
630 for (
int i = 0; i <
m_fields[0].size(); ++i)
632 for (
int j = 0; j <
m_fields.size(); ++j)
636 m_f->m_comm->Send(0, tmp);
643 for (
int i = 0; i <
m_fields[0].size(); ++i)
645 for (
int j = 0; j <
m_fields.size(); ++j)
647 outfile << setw(12) <<
m_fields[j][i] <<
" ";
649 outfile << std::endl;
666 bool useDoubles =
m_config[
"double"].as<
bool>();
676 int nPts = data.size();
677 std::vector<float> tmp(data.size());
678 std::copy(&data[0], &data[0] + nPts, &tmp[0]);
695 bool useDoubles =
m_config[
"double"].as<
bool>();
703 int rank =
m_f->m_comm->GetRank();
704 string zonename =
"ZONE " + boost::lexical_cast<string>(rank);
756 for (
int j = 0; j <
m_fields.size(); ++j)
768 for (
int i = 0; i <
m_fields.size(); ++i)
780 for (
int i = 0; i <
m_fields.size(); ++i)
789 for (
int i = 0; i <
m_fields.size(); ++i)
793 for (
int n = 1; n <
m_f->m_comm->GetSize(); ++n)
796 m_f->m_comm->Recv(n, tmp);
803 for (
int i = 0; i <
m_fields.size(); ++i)
810 for (
int i = 0; i <
m_fields.size(); ++i)
836 for (
int i = 0, cnt = 0; i <
m_conn.size(); ++i)
845 m_f->m_comm->Send(0, conn);
851 for (
int i = 0; i <
m_conn.size(); ++i)
853 const int nConn =
m_conn[i].size();
854 for (
int j = 0; j < nConn; ++j, ++cnt)
856 outfile <<
m_conn[i][j] + 1 <<
" ";
859 outfile << std::endl;
869 for (
int n = 1; n <
m_f->m_comm->GetSize(); ++n)
874 m_f->m_comm->Recv(n, conn);
875 for (
int j = 0; j < conn.size(); ++j)
877 outfile << conn[j] + offset + 1 <<
" ";
878 if ((!(j % 1000)) && j)
880 outfile << std::endl;
896 for (
int i = 0, cnt = 0; i <
m_conn.size(); ++i)
901 m_f->m_comm->Send(0, conn);
905 for (
int i = 0; i <
m_conn.size(); ++i)
914 for (
int n = 1; n <
m_f->m_comm->GetSize(); ++n)
917 m_f->m_comm->Recv(n, conn);
919 for (
int j = 0; j < conn.size(); ++j)
940 if (
m_f->m_exp[0]->GetExp(0)->GetNumBases() == 1)
942 for (
int i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
944 returnval += (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0) - 1);
947 else if (
m_f->m_exp[0]->GetExp(0)->GetNumBases() == 2)
949 for (
int i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
951 returnval += (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0) - 1) *
952 (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(1) - 1);
957 for (
int i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
959 returnval += (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0) - 1) *
960 (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(1) - 1) *
961 (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(2) - 1);
976 int nbase =
m_f->m_exp[0]->GetExp(0)->GetNumBases();
979 m_conn.resize(
m_f->m_exp[0]->GetNumElmts());
981 for (i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
983 cnt =
m_f->m_exp[0]->GetPhys_Offset(i);
988 int np0 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0);
993 nPlanes =
m_f->m_exp[0]->GetZIDs().size();
997 int totPoints =
m_f->m_exp[0]->GetPlane(0)->GetTotPoints();
1000 for (
int n = 1; n < nPlanes; ++n)
1002 for (k = 1; k < np0; ++k)
1004 conn[cnt2++] = cnt + (n - 1) * totPoints + k;
1005 conn[cnt2++] = cnt + (n - 1) * totPoints + k - 1;
1006 conn[cnt2++] = cnt + n * totPoints + k - 1;
1007 conn[cnt2++] = cnt + n * totPoints + k;
1018 for (k = 1; k < np0; ++k)
1020 conn[cnt2++] = cnt + k;
1021 conn[cnt2++] = cnt + k - 1;
1027 else if (nbase == 2)
1029 int np0 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0);
1030 int np1 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(1);
1031 int totPoints =
m_f->m_exp[0]->GetTotPoints();
1037 nPlanes =
m_f->m_exp[0]->GetZIDs().size();
1044 totPoints =
m_f->m_exp[0]->GetPlane(0)->GetTotPoints();
1049 for (
int n = 1; n < nPlanes; ++n)
1051 for (j = 1; j < np1; ++j)
1053 for (k = 1; k < np0; ++k)
1055 conn[cnt2++] = cnt + (n - 1) * totPoints +
1056 (j - 1) * np0 + k - 1;
1057 conn[cnt2++] = cnt + (n - 1) * totPoints +
1060 cnt + (n - 1) * totPoints + j * np0 + k;
1062 cnt + (n - 1) * totPoints + j * np0 + k - 1;
1064 cnt + n * totPoints + (j - 1) * np0 + k - 1;
1066 cnt + n * totPoints + (j - 1) * np0 + k;
1068 cnt + n * totPoints + j * np0 + k;
1070 cnt + n * totPoints + j * np0 + k - 1;
1081 for (j = 1; j < np1; ++j)
1083 for (k = 1; k < np0; ++k)
1085 conn[cnt2++] = cnt + (j - 1) * np0 + k - 1;
1086 conn[cnt2++] = cnt + (j - 1) * np0 + k;
1087 conn[cnt2++] = cnt + j * np0 + k;
1088 conn[cnt2++] = cnt + j * np0 + k - 1;
1094 else if (nbase == 3)
1096 int np0 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0);
1097 int np1 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(1);
1098 int np2 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(2);
1103 for (j = 1; j < np2; ++j)
1105 for (k = 1; k < np1; ++k)
1107 for (l = 1; l < np0; ++l)
1110 cnt + (j - 1) * np0 * np1 + (k - 1) * np0 + l - 1;
1112 cnt + (j - 1) * np0 * np1 + (k - 1) * np0 + l;
1113 conn[cnt2++] = cnt + (j - 1) * np0 * np1 + k * np0 + l;
1115 cnt + (j - 1) * np0 * np1 + k * np0 + l - 1;
1117 cnt + j * np0 * np1 + (k - 1) * np0 + l - 1;
1118 conn[cnt2++] = cnt + j * np0 * np1 + (k - 1) * np0 + l;
1119 conn[cnt2++] = cnt + j * np0 * np1 + k * np0 + l;
1120 conn[cnt2++] = cnt + j * np0 * np1 + k * np0 + l - 1;
1129 ASSERTL0(
false,
"Not set up for this dimension");
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
FieldSharedPtr m_f
Field object.
std::map< std::string, ConfigOption > m_config
List of configuration values.
Converter from fld to vtk.
virtual void Process(po::variables_map &vm)
Write fld to output file.
void WriteDoubleOrFloat(std::ofstream &outfile, Array< OneD, NekDouble > &data)
Write either double-precision or single-precision output of field data.
virtual void WriteTecplotZone(std::ofstream &outfile)
virtual void WriteTecplotHeader(std::ofstream &outfile, std::vector< std::string > &var)
Write Tecplot files header in binary format.
virtual void WriteTecplotConnectivity(std::ofstream &outfile)
Write Tecplot connectivity information (ASCII)
int m_totConn
Total number of connectivity entries.
std::vector< Array< OneD, int > > m_conn
Connectivty for each block: one per element.
Array< OneD, int > m_rankConnSizes
Each rank's connectivity sizes.
bool m_binary
True if writing binary field output.
bool m_oneOutputFile
True if writing a single output file.
virtual fs::path GetFullOutName(std::string &filename, po::variables_map &vm)
virtual void WriteTecplotZone(std::ofstream &outfile)
void CalculateConnectivity()
Calculate connectivity information for each expansion dimension.
virtual void WriteTecplotConnectivity(std::ofstream &outfile)
Write Tecplot connectivity information (ASCII)
virtual void Process(po::variables_map &vm)
Write fld to output file.
bool m_writeHeader
True if writing header.
virtual void OutputFromExp(po::variables_map &vm)
Write from m_exp to output file.
TecplotZoneType m_zoneType
Tecplot zone type of output.
Array< OneD, int > m_rankFieldSizes
Each rank's field sizes.
std::vector< int > m_numPoints
Number of points per block in Tecplot file.
virtual fs::path GetPath(std::string &filename, po::variables_map &vm)
virtual void WriteTecplotHeader(std::ofstream &outfile, std::vector< std::string > &var)
Write Tecplot files header.
void WriteTecplotFile(po::variables_map &vm)
virtual void OutputFromPts(po::variables_map &vm)
Write from pts to output file.
int m_numBlocks
Number of blocks in Tecplot file.
int m_coordim
Coordinate dimension of output.
int GetNumTecplotBlocks()
Calculate number of Tecplot blocks.
Array< OneD, Array< OneD, NekDouble > > m_fields
Field data to output.
virtual void OutputFromData(po::variables_map &vm)
Write from data to output file.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
void WriteStream(std::ostream &outfile, T data)
Helper function to write binary data to stream.
std::shared_ptr< Field > FieldSharedPtr
std::pair< ModuleType, std::string > ModuleKey
std::string TecplotZoneTypeMap[]
ModuleFactory & GetModuleFactory()
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
std::shared_ptr< PtsField > PtsFieldSharedPtr
The above copyright notice and this permission notice shall be included.
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add vector y = alpha - x.
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Represents a command-line configuration option.