Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
probemon.C
Go to the documentation of this file.
1 #include "ProbeMon.H"
2 
3 std::string BuildProbeFileName(const std::string &caseName,int probeNumber)
4 {
5  std::ostringstream outString;
6  outString << caseName << ".prb_"
7  << (probeNumber >= 1000 ? "" :
8  (probeNumber >= 100 ? "0" :
9  (probeNumber >= 10 ? "00" :
10  "000"))) << probeNumber;
11  return(outString.str());
12 }
13 
14 int
15 main(int argc,char *argv[])
16 {
17  if(argc < 2) return(1);
18  std::string caseName(argv[1]);
19 
20  std::string configFileName(caseName+".probe_config");
21  std::ifstream configIn;
22  configIn.open(configFileName.c_str());
23  if(!configIn){
24  return(1);
25  }
26  int nProbes = 0;
27  configIn >> nProbes;
28  std::vector<double> probeLocations;
29  double location = 0.0;
30  while(configIn >> location)
31  probeLocations.push_back(location);
32  configIn.close();
33  int nProbeCoordinates = probeLocations.size();
34  assert(nProbeCoordinates == nProbes*3);
35  std::vector<double>::iterator coordinateIterator = probeLocations.begin();
36 
37  std::ostringstream htmlOut;
38  htmlOut << "<html>" << std::endl
39  << " <head>" << std::endl
40  << " <title>"
41  << caseName << " Probe Monitor"
42  << "</title>" << std::endl
43  << " <meta http-equiv=\"refresh\" content=\"300\" />"
44  << std::endl
45  << " </head>" << std::endl
46  << " <body>" << std::endl
47  << " <p>" << std::endl
48  << " <h1><center>" << caseName
49  << " Probe Monitor</center></h1>" << std::endl
50  << " </p>" << std::endl << std::endl
51  << " <hr>" << std::endl << std::endl;
52 
53 
54  std::vector<IR::flowprobe> probesData;
55  for(int iProbe = 1;iProbe <= nProbes;iProbe++){
56 
57  double probeLocationX = *coordinateIterator++;
58  double probeLocationY = *coordinateIterator++;
59  double probeLocationZ = *coordinateIterator++;
60 
61  htmlOut << " <p>" << std::endl
62  << " <h2><center>Probe "
63  << iProbe << "</center></h2>" << std::endl
64  << " <img src=\"velocity_plot_" << iProbe << ".png\" "
65  << "style=\"float: left; width: 50%\">" << std::endl
66  << " <img src=\"pandt_plot_" << iProbe << ".png\" "
67  << "style=\"float: left; width: 50%\">" << std::endl
68  << " </p>" << std::endl << std::endl
69  << " <hr>" << std::endl
70  << std::endl;
71 
72  std::string probeFileName(BuildProbeFileName(caseName,iProbe));
73  std::fstream probeFile;
74  probeFile.open(probeFileName.c_str());
75  if(!probeFile){
76  std::cout << "probemon: Unable to open probe file: "
77  << probeFileName << std::endl;
78  return(1);
79  }
80 
81  IR::flowprobe flowProbe;
82  unsigned int nTimes = flowProbe.ReadProbeData(probeFile);
83  probeFile.close();
84  flowProbe.SetLocation(probeLocationX,probeLocationY,probeLocationZ);
85  probesData.push_back(flowProbe);
86  std::cout << "probemon: Got " << nTimes << " probe values from "
87  << probeFileName << "." << std::endl;
88 
89 
90  std::ofstream plotFile;
91  std::ostringstream dataStreamOut;
92  dataStreamOut << "plot_data_" << iProbe << ".txt";
93  std::string plotFileName(dataStreamOut.str());
94  plotFile.open(plotFileName.c_str());
95  if(!plotFile){
96  std::cout << "probemon: Unable to open plot data file: " << plotFileName << std::endl;
97  return(1);
98  }
99  flowProbe.WriteData(plotFile,true);
100  plotFile.close();
101 
102  std::ostringstream plotCommands;
103  plotCommands << "set title 'Probe " << iProbe << " Velocity'" << std::endl
104  << "set ylabel 'Velocity (m/s)" << std::endl
105  << "set term png" << std::endl
106  << "set key top right title ''" << std::endl
107  << "set output 'velocity_plot_"<< iProbe << ".png'" << std::endl
108  << "plot '" << plotFileName << "' using 4:6 w l t 'X-velocity','"
109  << plotFileName << "' "
110  << "using 4:7 w l t 'Y-velocity','" << plotFileName
111  << "' using 4:8 w l t 'Z-velocity'"
112  << std::endl;
113  IR::GNUPlot(plotCommands.str());
114 
115  plotCommands.clear();
116  plotCommands.str("");
117  plotCommands << "set title 'Probe " << iProbe << " Pressure and Temperature'" << std::endl
118  << "set ylabel 'Pressure (Pa)" << std::endl
119  << "set y2label 'Temperature (K)'" << std::endl
120  << "set term png" << std::endl
121  << "set key bottom right title ''" << std::endl
122  << "set ytics nomirror" << std::endl
123  << "set y2tics" << std::endl
124  << "set output 'pandt_plot_" << iProbe << ".png'" << std::endl
125  << "plot '"<< plotFileName << "' using 4:9 w l t 'Pressure'"
126  << ",'" << plotFileName << "' using 4:10 w l t 'Temperature' axes x1y2"
127  << std::endl;
128  IR::GNUPlot(plotCommands.str());
129  }
130 
131  configFileName.assign(caseName+".derived_config");
132  configIn.open(configFileName.c_str());
133  if(configIn){
134  // Process derived quantities
135  std::vector<IR::derivedprobe> derivedProbes;
136  IR::derivedprobe derivedProbe;
137 // while(derivedProbe << configIn)
138 // derivedProbes.push_back(derivedProbe);
139 
140  }
141  htmlOut << " </body>" << std::endl
142  << "</html>" << std::endl;
143  std::ofstream htmlFile;
144  htmlFile.open("probemonitor.html");
145  htmlFile << htmlOut.str();
146  htmlFile.close();
147  return(0);
148 }
void WriteData(std::ostream &outStream, bool writeLoc=false)
Definition: ProbeMon.H:63
int GNUPlot(const std::string &commands)
Definition: ProbeMon.H:91
void SetLocation(double xLoc, double yLoc, double zLoc)
Definition: ProbeMon.H:76
unsigned int ReadProbeData(std::istream &inStream)
Definition: ProbeMon.H:37
int main(int argc, char *argv[])
Definition: blastest.C:94
std::string BuildProbeFileName(const std::string &caseName, int probeNumber)
Definition: probemon.C:3