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();
222 var.insert(var.begin(), coordVars, coordVars +
m_coordim);
226 int nPlanes =
m_f->m_exp[0]->GetZIDs().num_elements();
254 int totpoints =
m_f->m_exp[0]->GetTotPoints();
265 else if (m_coordim == 2)
277 for (
int i = 0; i <
m_f->m_exp.size(); ++i)
279 if (
m_f->m_exp[i]->GetPhysState() ==
false)
281 m_f->m_exp[i]->BwdTrans(
m_f->m_exp[i]->GetCoeffs(),
282 m_f->m_exp[i]->UpdatePhys());
287 for (
int i = 0; i <
m_f->m_exp.size(); ++i)
296 for (
int i = 0; i <
m_fields.num_elements(); ++i)
301 cout <<
"L 2 error (variable " << var[i] <<
") : "
311 if (fPts->GetNpoints() == 0)
317 fPts->GetConnectivity(
m_conn);
320 var = fPts->GetFieldNames();
321 var.insert(var.begin(), coordVars, coordVars +
m_coordim);
323 switch (fPts->GetPtsType())
347 for (
int i = 0; i <
m_conn.size(); ++i)
356 for (
int i = 0; i <
m_conn.size(); ++i)
363 ASSERTL0(
false,
"This points type is not supported yet.");
380 for (
int i = 0; i <
m_fields.num_elements(); ++i)
386 for (
int j = 0; j <
npts; ++j)
399 cout <<
"L 2 error (variable " << var[i] <<
") : "
422 for (
int i = 0; i <
m_conn.size(); ++i)
447 cout <<
"Written file: " << filename << endl;
458 std::vector<std::string> &var)
460 outfile <<
"Variables = " << var[0];
462 for (
int i = 1; i < var.size(); ++i)
464 outfile <<
", " << var[i];
467 outfile << std::endl << std::endl;
477 std::vector<std::string> &var)
485 outfile <<
"#!TDV112";
494 std::string
title =
"";
500 for (
int i = 0; i < var.size(); ++i)
525 outfile <<
"Zone, N=" << nPoints <<
", E="
527 << TecplotZoneTypeMap[
m_zoneType] << std::endl;
533 for (
int j = 0; j <
m_fields.num_elements(); ++j)
535 for (
int i = 0; i <
m_fields[j].num_elements(); ++i)
537 if ((!(i % 1000)) && i)
539 outfile << std::endl;
544 for (
int n = 1; n <
m_f->m_comm->GetSize(); ++n)
547 m_f->m_comm->Recv(n, tmp);
551 if ((!(i % 1000)) && i)
553 outfile << std::endl;
555 outfile << tmp[i] <<
" ";
558 outfile << std::endl;
563 for (
int i = 0; i <
m_fields.num_elements(); ++i)
572 for (
int j = 0; j <
m_fields.num_elements(); ++j)
574 for (
int i = 0; i <
m_fields[j].num_elements(); ++i)
576 if ((!(i % 1000)) && i)
578 outfile << std::endl;
582 outfile << std::endl;
588 std::string dirs[] = {
"I",
"J",
"K" };
592 outfile <<
", " << dirs[i] <<
"=" <<
m_numPoints[i];
594 outfile <<
", F=POINT" << std::endl;
598 for (
int i = 0; i <
m_fields[0].num_elements(); ++i)
600 for (
int j = 0; j <
m_fields.num_elements(); ++j)
602 outfile << setw(12) <<
m_fields[j][i] <<
" ";
604 outfile << std::endl;
620 bool useDoubles =
m_config[
"double"].m_beenSet;
630 int nPts = data.num_elements();
631 vector<float> tmp(data.num_elements());
632 std::copy(&data[0], &data[0] + nPts, &tmp[0]);
649 bool useDoubles =
m_config[
"double"].m_beenSet;
657 int rank =
m_f->m_comm->GetRank();
658 string zonename =
"ZONE " + boost::lexical_cast<
string>(rank);
710 for (
int j = 0; j <
m_fields.num_elements(); ++j)
722 for (
int i = 0; i <
m_fields.num_elements(); ++i)
734 for (
int i = 0; i <
m_fields.num_elements(); ++i)
743 for (
int i = 0; i <
m_fields.num_elements(); ++i)
747 for (
int n = 1; n <
m_f->m_comm->GetSize(); ++n)
750 m_f->m_comm->Recv(n, tmp);
757 for (
int i = 0; i <
m_fields.num_elements(); ++i)
764 for (
int i = 0; i <
m_fields.num_elements(); ++i)
788 for (
int i = 0, cnt = 0; i <
m_conn.size(); ++i)
792 cnt +=
m_conn[i].num_elements();
794 m_f->m_comm->Send(0, conn);
799 for (
int i = 0; i <
m_conn.size(); ++i)
801 const int nConn =
m_conn[i].num_elements();
802 for (
int j = 0; j < nConn; ++j,++cnt)
804 outfile <<
m_conn[i][j] + 1 <<
" ";
807 outfile << std::endl;
817 for (
int n = 1; n <
m_f->m_comm->GetSize(); ++n)
820 m_f->m_comm->Recv(n, conn);
821 for (
int j = 0; j < conn.num_elements(); ++j)
823 outfile << conn[j] + offset + 1 <<
" ";
824 if ((!(j % 1000)) && j)
826 outfile << std::endl;
841 for (
int i = 0, cnt = 0; i <
m_conn.size(); ++i)
845 cnt +=
m_conn[i].num_elements();
847 m_f->m_comm->Send(0, conn);
851 for (
int i = 0; i <
m_conn.size(); ++i)
860 for (
int n = 1; n <
m_f->m_comm->GetSize(); ++n)
863 m_f->m_comm->Recv(n, conn);
865 for (
int j = 0; j < conn.num_elements(); ++j)
886 if (
m_f->m_exp[0]->GetExp(0)->GetNumBases() == 1)
888 for (
int i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
890 returnval += (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0) - 1);
893 else if (
m_f->m_exp[0]->GetExp(0)->GetNumBases() == 2)
895 for (
int i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
897 returnval += (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0) - 1) *
898 (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(1) - 1);
903 for (
int i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
905 returnval += (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0) - 1) *
906 (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(1) - 1) *
907 (
m_f->m_exp[0]->GetExp(i)->GetNumPoints(2) - 1);
922 int nbase =
m_f->m_exp[0]->GetExp(0)->GetNumBases();
925 m_conn.resize(
m_f->m_exp[0]->GetNumElmts());
927 for (i = 0; i <
m_f->m_exp[0]->GetNumElmts(); ++i)
929 cnt =
m_f->m_exp[0]->GetPhys_Offset(i);
934 int np0 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0);
938 for (k = 1; k < np0; ++k)
940 conn[cnt2++] = cnt + k;
941 conn[cnt2++] = cnt + k - 1;
948 int np0 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0);
949 int np1 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(1);
950 int totPoints =
m_f->m_exp[0]->GetTotPoints();
956 nPlanes =
m_f->m_exp[0]->GetZIDs().num_elements();
961 totPoints =
m_f->m_exp[0]->GetPlane(0)->GetTotPoints();
965 for (
int n = 1; n < nPlanes; ++n)
967 for (j = 1; j < np1; ++j)
969 for (k = 1; k < np0; ++k)
971 conn[cnt2++] = cnt + (n - 1) * totPoints +
972 (j - 1) * np0 + k - 1;
973 conn[cnt2++] = cnt + (n - 1) * totPoints +
975 conn[cnt2++] = cnt + (n - 1) * totPoints +
977 conn[cnt2++] = cnt + (n - 1) * totPoints +
979 conn[cnt2++] = cnt + n * totPoints +
980 (j - 1) * np0 + k - 1;
981 conn[cnt2++] = cnt + n * totPoints +
983 conn[cnt2++] = cnt + n * totPoints +
985 conn[cnt2++] = cnt + n * totPoints +
997 for (j = 1; j < np1; ++j)
999 for (k = 1; k < np0; ++k)
1001 conn[cnt2++] = cnt + (j - 1) * np0 + k - 1;
1002 conn[cnt2++] = cnt + (j - 1) * np0 + k;
1003 conn[cnt2++] = cnt + j * np0 + k;
1004 conn[cnt2++] = cnt + j * np0 + k - 1;
1010 else if (nbase == 3)
1012 int np0 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(0);
1013 int np1 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(1);
1014 int np2 =
m_f->m_exp[0]->GetExp(i)->GetNumPoints(2);
1019 for (j = 1; j < np2; ++j)
1021 for (k = 1; k < np1; ++k)
1023 for (l = 1; l < np0; ++l)
1026 cnt + (j - 1) * np0 * np1 + (k - 1) * np0 + l - 1;
1028 cnt + (j - 1) * np0 * np1 + (k - 1) * np0 + l;
1030 cnt + (j - 1) * np0 * np1 + k * np0 + l;
1032 cnt + (j - 1) * np0 * np1 + k * np0 + l - 1;
1034 cnt + j * np0 * np1 + (k - 1) * np0 + l - 1;
1036 cnt + j * np0 * np1 + (k - 1) * np0 + l;
1038 cnt + j * np0 * np1 + k * np0 + l;
1040 cnt + j * np0 * np1 + k * np0 + l - 1;
1049 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.