65 OutputTecplot::create,
66 "Writes a Tecplot file.");
67 ModuleKey OutputTecplotBinary::m_className =
70 OutputTecplotBinary::create,
71 "Writes a Tecplot file in binary plt format.");
75 m_oneOutputFile(false)
77 if (!f->m_setUpEquiSpacedFields)
82 ConfigOption(
true,
"0",
"Write multiple files in parallel");
92 template<
typename T>
void WriteStream(std::ostream &outfile, T data)
95 outfile.write(reinterpret_cast<char *>(&tmp),
sizeof(T));
105 template<>
void WriteStream(std::ostream &outfile, std::string data)
108 for (std::string::size_type i = 0; i < data.size(); ++i)
110 char strChar = data[i];
126 outfile.write(reinterpret_cast<char *>(&data[0]),
127 data.num_elements() *
sizeof(T));
136 outfile.write(reinterpret_cast<char *>(&data[0]),
137 data.size() *
sizeof(T));
158 if (
m_f->m_comm->TreatAsRankZero())
160 cout <<
"OutputTecplot: Writing file..." << endl;
165 string filename =
m_config[
"outfile"].as<
string>();
167 int nprocs =
m_f->m_comm->GetSize();
168 int rank =
m_f->m_comm->GetRank();
170 if(
m_config[
"writemultiplefiles"].as<bool>())
182 int dot = filename.find_last_of(
'.');
183 string ext = filename.substr(dot, filename.length() - dot);
184 string procId =
"_P" + boost::lexical_cast<std::string>(rank);
185 string start = filename.substr(0, dot);
186 filename = start + procId + ext;
189 std::string coordVars[] = {
"x",
"y",
"z" };
190 bool doError = (vm.count(
"error") == 1) ?
true :
false;
197 outfile.open(filename.c_str(),
m_binary ? ios::binary : ios::out);
200 std::vector<std::string> var;
201 bool writeHeader =
true;
206 std::vector<LibUtilities::FieldDefinitionsSharedPtr> fDef =
211 var = fDef[0]->m_fields;
218 int nBases =
m_f->m_exp[0]->GetExp(0)->GetNumBases();
225 int nPlanes =
m_f->m_exp[0]->GetZIDs().num_elements();
244 var.insert(var.begin(), coordVars, coordVars +
m_coordim);
255 int totpoints =
m_f->m_exp[0]->GetTotPoints();
266 else if (m_coordim == 2)
278 for (
int i = 0; i <
m_f->m_exp.size(); ++i)
280 if (
m_f->m_exp[i]->GetPhysState() ==
false)
282 m_f->m_exp[i]->BwdTrans(
m_f->m_exp[i]->GetCoeffs(),
283 m_f->m_exp[i]->UpdatePhys());
288 for (
int i = 0; i <
m_f->m_exp.size(); ++i)
297 for (
int i = 0; i <
m_fields.num_elements(); ++i)
302 cout <<
"L 2 error (variable " << var[i] <<
") : "
312 if (fPts->GetNpoints() == 0)
318 fPts->GetConnectivity(
m_conn);
321 var = fPts->GetFieldNames();
322 var.insert(var.begin(), coordVars, coordVars +
m_coordim);
324 switch (fPts->GetPtsType())
348 for (
int i = 0; i <
m_conn.size(); ++i)
357 for (
int i = 0; i <
m_conn.size(); ++i)
364 ASSERTL0(
false,
"This points type is not supported yet.");
381 for (
int i = 0; i <
m_fields.num_elements(); ++i)
387 for (
int j = 0; j <
npts; ++j)
400 cout <<
"L 2 error (variable " << var[i] <<
") : "
423 for (
int i = 0; i <
m_conn.size(); ++i)
448 cout <<
"Written file: " << filename << endl;
459 std::vector<std::string> &var)
461 outfile <<
"Variables = " << var[0];
463 for (
int i = 1; i < var.size(); ++i)
465 outfile <<
", " << var[i];
468 outfile << std::endl << std::endl;
478 std::vector<std::string> &var)
486 outfile <<
"#!TDV112";
495 std::string
title =
"";
501 for (
int i = 0; i < var.size(); ++i)
526 outfile <<
"Zone, N=" << nPoints <<
", E="
528 << TecplotZoneTypeMap[
m_zoneType] << std::endl;
534 for (
int j = 0; j <
m_fields.num_elements(); ++j)
536 for (
int i = 0; i <
m_fields[j].num_elements(); ++i)
538 if ((!(i % 1000)) && i)
540 outfile << std::endl;
545 for (
int n = 1; n <
m_f->m_comm->GetSize(); ++n)
548 m_f->m_comm->Recv(n, tmp);
552 if ((!(i % 1000)) && i)
554 outfile << std::endl;
556 outfile << tmp[i] <<
" ";
559 outfile << std::endl;
564 for (
int i = 0; i <
m_fields.num_elements(); ++i)
573 for (
int j = 0; j <
m_fields.num_elements(); ++j)
575 for (
int i = 0; i <
m_fields[j].num_elements(); ++i)
577 if ((!(i % 1000)) && i)
579 outfile << std::endl;
583 outfile << std::endl;
589 std::string dirs[] = {
"I",
"J",
"K" };
593 outfile <<
", " << dirs[i] <<
"=" <<
m_numPoints[i];
595 outfile <<
", F=POINT" << std::endl;
599 for (
int i = 0; i <
m_fields[0].num_elements(); ++i)
601 for (
int j = 0; j <
m_fields.num_elements(); ++j)
603 outfile << setw(12) <<
m_fields[j][i] <<
" ";
605 outfile << std::endl;
621 bool useDoubles =
m_config[
"double"].m_beenSet;
631 int nPts = data.num_elements();
632 vector<float> tmp(data.num_elements());
633 std::copy(&data[0], &data[0] + nPts, &tmp[0]);
650 bool useDoubles =
m_config[
"double"].m_beenSet;
658 int rank =
m_f->m_comm->GetRank();
659 string zonename =
"ZONE " + boost::lexical_cast<
string>(rank);
711 for (
int j = 0; j <
m_fields.num_elements(); ++j)
723 for (
int i = 0; i <
m_fields.num_elements(); ++i)
735 for (
int i = 0; i <
m_fields.num_elements(); ++i)
744 for (
int i = 0; i <
m_fields.num_elements(); ++i)
748 for (
int n = 1; n <
m_f->m_comm->GetSize(); ++n)
751 m_f->m_comm->Recv(n, tmp);
758 for (
int i = 0; i <
m_fields.num_elements(); ++i)
765 for (
int i = 0; i <
m_fields.num_elements(); ++i)
789 for (
int i = 0, cnt = 0; i <
m_conn.size(); ++i)
793 cnt +=
m_conn[i].num_elements();
795 m_f->m_comm->Send(0, conn);
800 for (
int i = 0; i <
m_conn.size(); ++i)
802 const int nConn =
m_conn[i].num_elements();
803 for (
int j = 0; j < nConn; ++j,++cnt)
805 outfile <<
m_conn[i][j] + 1 <<
" ";
808 outfile << std::endl;
818 for (
int n = 1; n <
m_f->m_comm->GetSize(); ++n)
821 m_f->m_comm->Recv(n, conn);
822 for (
int j = 0; j < conn.num_elements(); ++j)
824 outfile << conn[j] + offset + 1 <<
" ";
825 if ((!(j % 1000)) && j)
827 outfile << std::endl;
842 for (
int i = 0, cnt = 0; i <
m_conn.size(); ++i)
846 cnt +=
m_conn[i].num_elements();
848 m_f->m_comm->Send(0, conn);
852 for (
int i = 0; i <
m_conn.size(); ++i)
861 for (
int n = 1; n <
m_f->m_comm->GetSize(); ++n)
864 m_f->m_comm->Recv(n, conn);
866 for (
int j = 0; j < conn.num_elements(); ++j)
887 if (
m_f->m_exp[0]->GetExp(0)->GetNumBases() == 1)
889 for (
int i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
891 returnval += (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0) - 1);
894 else if (
m_f->m_exp[0]->GetExp(0)->GetNumBases() == 2)
896 for (
int i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
898 returnval += (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0) - 1) *
899 (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(1) - 1);
904 for (
int i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
906 returnval += (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0) - 1) *
907 (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(1) - 1) *
908 (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(2) - 1);
923 int nbase =
m_f->m_exp[0]->GetExp(0)->GetNumBases();
926 m_conn.resize(
m_f->m_exp[0]->GetNumElmts());
928 for (i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
930 cnt =
m_f->m_exp[0]->GetPhys_Offset(i);
935 int np0 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0);
939 for (k = 1; k < np0; ++k)
941 conn[cnt2++] = cnt + k;
942 conn[cnt2++] = cnt + k - 1;
949 int np0 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0);
950 int np1 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(1);
951 int totPoints =
m_f->m_exp[0]->GetTotPoints();
957 nPlanes =
m_f->m_exp[0]->GetZIDs().num_elements();
962 totPoints =
m_f->m_exp[0]->GetPlane(0)->GetTotPoints();
966 for (
int n = 1; n < nPlanes; ++n)
968 for (j = 1; j < np1; ++j)
970 for (k = 1; k < np0; ++k)
972 conn[cnt2++] = cnt + (n - 1) * totPoints +
973 (j - 1) * np0 + k - 1;
974 conn[cnt2++] = cnt + (n - 1) * totPoints +
976 conn[cnt2++] = cnt + (n - 1) * totPoints +
978 conn[cnt2++] = cnt + (n - 1) * totPoints +
980 conn[cnt2++] = cnt + n * totPoints +
981 (j - 1) * np0 + k - 1;
982 conn[cnt2++] = cnt + n * totPoints +
984 conn[cnt2++] = cnt + n * totPoints +
986 conn[cnt2++] = cnt + n * totPoints +
998 for (j = 1; j < np1; ++j)
1000 for (k = 1; k < np0; ++k)
1002 conn[cnt2++] = cnt + (j - 1) * np0 + k - 1;
1003 conn[cnt2++] = cnt + (j - 1) * np0 + k;
1004 conn[cnt2++] = cnt + j * np0 + k;
1005 conn[cnt2++] = cnt + j * np0 + k - 1;
1011 else if (nbase == 3)
1013 int np0 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0);
1014 int np1 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(1);
1015 int np2 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(2);
1020 for (j = 1; j < np2; ++j)
1022 for (k = 1; k < np1; ++k)
1024 for (l = 1; l < np0; ++l)
1027 cnt + (j - 1) * np0 * np1 + (k - 1) * np0 + l - 1;
1029 cnt + (j - 1) * np0 * np1 + (k - 1) * np0 + l;
1031 cnt + (j - 1) * np0 * np1 + k * np0 + l;
1033 cnt + (j - 1) * np0 * np1 + k * np0 + l - 1;
1035 cnt + j * np0 * np1 + (k - 1) * np0 + l - 1;
1037 cnt + j * np0 * np1 + (k - 1) * np0 + l;
1039 cnt + j * np0 * np1 + k * np0 + l;
1041 cnt + j * np0 * np1 + k * np0 + l - 1;
1050 ASSERTL0(
false,
"Not set up for this dimension");
map< string, ConfigOption > m_config
List of configuration values.
#define ASSERTL0(condition, msg)
Represents a command-line configuration option.
TecplotZoneType m_zoneType
Tecplot zone type of output.
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
Array< OneD, int > m_rankConnSizes
Each rank's connectivity sizes.
virtual void WriteTecplotHeader(std::ofstream &outfile, std::vector< std::string > &var)
Write Tecplot files header in binary format.
pair< ModuleType, string > ModuleKey
bool m_oneOutputFile
True if writing a single output file.
void WriteDoubleOrFloat(std::ofstream &outfile, Array< OneD, NekDouble > &data)
Write either double-precision or single-precision output of field data.
boost::shared_ptr< PtsField > PtsFieldSharedPtr
virtual void WriteTecplotConnectivity(std::ofstream &outfile)
Write Tecplot connectivity information (ASCII)
void CalculateConnectivity()
Calculate connectivity information for each expansion dimension.
virtual void WriteTecplotHeader(std::ofstream &outfile, std::vector< std::string > &var)
Write Tecplot files header.
Array< OneD, int > m_rankFieldSizes
Each rank's field sizes.
boost::shared_ptr< Field > FieldSharedPtr
virtual void WriteTecplotZone(std::ofstream &outfile)
vector< Array< OneD, int > > m_conn
Connectivty for each block: one per element.
int m_numBlocks
Number of blocks in Tecplot file.
int m_totConn
Total number of connectivity entries.
static PtsFieldSharedPtr NullPtsField
std::string TecplotZoneTypeMap[]
int GetNumTecplotBlocks()
Calculate number of Tecplot blocks.
virtual void Process(po::variables_map &vm)
Set up member variables to dump Tecplot format output.
int m_coordim
Coordinate dimension of output.
Array< OneD, Array< OneD, NekDouble > > m_fields
Field data to output.
bool m_binary
True if writing binary field output.
T Vsum(int n, const T *x, const int incx)
Subtract return sum(x)
void WriteStream(std::ostream &outfile, T data)
Helper function to write binary data to stream.
virtual void WriteTecplotConnectivity(std::ofstream &outfile)
Write Tecplot connectivity information (ASCII)
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
virtual void WriteTecplotZone(std::ofstream &outfile)
vector< int > m_numPoints
Number of points per block in Tecplot file.
Abstract base class for output modules.
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.