Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
main.cpp File Reference
#include "main.h"
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 
vector< datafile * > openAndParseFiles ()
 Open the files specified at the command line and parse them. More...
 
void compareFiles (vector< datafile * > pFiles)
 Compare the two files, interpolating the points from the second onto the first mesh. More...
 
std::vector< points * > retrievePoints (datafile *pFile, vector< int > rPartitions)
 Construct a vector of pointers to datasets (point objects) from a list of partition numbers. More...
 
void printPointValues (points *pPoints)
 Write point values to standard out. More...
 
long double calcAverageValue (points *pPoints, int rVar)
 Calculates the average value of the points. More...
 
long double minPoint (points *pPoints, int rVar)
 Find the minimum value. More...
 
long double maxPoint (points *pPoints, int rVar)
 Find the maximum value. More...
 
void printUsage (string rErrorMessage)
 Print the rc_cmp usage message. More...
 

Variables

ComSwitch gCmdSwitches
 

Function Documentation

long double calcAverageValue ( points pPoints,
int  rVar 
)

Calculates the average value of the points.

Parameters
pPointsDatapoints
rVarVariable number to average
Returns
Returns the average

Definition at line 276 of file main.cpp.

References points::get_num_points(), points::get_point(), and pnt::vals.

276  {
277 
278  long double sum = 0.0;
279 
280  //Sum the points
281  for(int point_num = 0; point_num < pPoints->get_num_points(); point_num++){
282  pnt curr = pPoints->get_point(point_num);
283  sum += curr.vals[rVar];
284  }
285 
286  return (sum / (long double)pPoints->get_num_points());
287 }
long double * vals
Definition: datatypedef.h:69
pnt get_point(int n)
Definition: points.cpp:183
Point object that represents a single point.
Definition: datatypedef.h:68
int get_num_points()
Definition: points.cpp:117

Here is the call graph for this function:

void compareFiles ( vector< datafile * >  pFiles)

Compare the two files, interpolating the points from the second onto the first mesh.

Then, ouput results.

Definition at line 95 of file main.cpp.

References Interpolate::bilinear(), points::contains_null(), points::delete_all(), cmp_map::file1_partitions, cmp_map::file2_partition, metric::get_metric_name(), datafile::get_points(), metric::get_res(), ComSwitch::getComparisonList(), ComSwitch::getLogFile(), ComSwitch::getOutPrefix(), ComSwitch::getRange(), ComSwitch::getVerbosity(), i, ComSwitch::isRangeSpecified(), itoa(), cmp_map::metric, metric_select(), retrievePoints(), same_elements(), metric::setRange(), cmp_map::var1, and cmp_map::var2.

Referenced by main().

95  {
96 
97  datafile *file1 = pFiles[0];
98  datafile *file2 = pFiles[1];
99 
101  gCmdSwitches.getLogFile() << "\n";
102 
103 
104  //Get comparison list
105  std::vector<cmp_map> comparison_list = gCmdSwitches.getComparisonList();
106 
107  std::vector<points*> interp_pts;
108 
109  for(int i=0; i<comparison_list.size(); i++){
110 
111  cmp_map curr_comp = comparison_list[i];
112 
113  //Check if previous interp_pts satisfies current interp_pts
114  if( i > 0 ){
115  cmp_map prev_comp = comparison_list[(i-1)];
116 
117  if( !same_elements(curr_comp.file1_partitions, curr_comp.file1_partitions) ||
118  curr_comp.file2_partition != prev_comp.file2_partition ||
119  curr_comp.var1 != prev_comp.var1 ||
120  curr_comp.var2 != prev_comp.var2 ){
121 
122  points::delete_all(interp_pts);
123 
124  for(int partition_1_num = 0; partition_1_num < curr_comp.file1_partitions.size(); partition_1_num++){
125  points *temp_points;
126  temp_points = Interpolate::bilinear( file1->get_points(curr_comp.file1_partitions[partition_1_num]),
127  file2->get_points(curr_comp.file2_partition),
128  curr_comp.var1,
129  curr_comp.var2 );
130  interp_pts.push_back(temp_points);
131  }
132 
133  }
134  }
135  else{
136 
137  for(int partition_1_num = 0; partition_1_num < curr_comp.file1_partitions.size(); partition_1_num++){
138  points *temp_points;
139  temp_points = Interpolate::bilinear( file1->get_points(curr_comp.file1_partitions[partition_1_num]),
140  file2->get_points(curr_comp.file2_partition),
141  curr_comp.var1,
142  curr_comp.var2 );
143  interp_pts.push_back(temp_points);
144  }
145  }
146 
147  if(points::contains_null(interp_pts)){
148 
149  string out_msg;
150  out_msg = "ERROR | Interpolation Failed, ";
151  out_msg += "Possible Invalid Partition or Variable Argument: \"";
152  out_msg += itoa(curr_comp.metric) + "=";
153 
154  for(int partition_1_num = 0; partition_1_num < curr_comp.file1_partitions.size(); partition_1_num++){
155 
156  if(partition_1_num != 0)
157  out_msg += ",";
158 
159  out_msg += itoa(curr_comp.file1_partitions[partition_1_num]);
160  }
161 
162  out_msg += ":";
163  out_msg += itoa(curr_comp.var1) + "/" + itoa(curr_comp.file2_partition) + ":";
164  out_msg += itoa(curr_comp.var2) + "\"";
165 
166  gCmdSwitches.getLogFile() << out_msg << endl;
167  cout << out_msg << endl;
168 
169  continue;
170  }
171 
172  //Construct the outprefix string for the metric
173  //Used by the metric to prefix output files
174  string metric_outprefix = gCmdSwitches.getOutPrefix();
175  metric_outprefix += "_part1_";
176 
177  for(int partition_1_num = 0; partition_1_num < curr_comp.file1_partitions.size(); partition_1_num++){
178 
179  if(partition_1_num != 0)
180  metric_outprefix += "_";
181 
182  metric_outprefix += itoa(curr_comp.file1_partitions[partition_1_num]);
183  }
184 
185  metric_outprefix += "_part2_" + itoa(curr_comp.file2_partition);
186 
187  //Create metric object
188  metric *comp = metric_select(curr_comp.metric, retrievePoints(file1, curr_comp.file1_partitions),
189  interp_pts, curr_comp.var1, 2, //Interpolation only returns the desired point
190  gCmdSwitches.getLogFile(), metric_outprefix);
191 
193  {
194  BoundingBox range = gCmdSwitches.getRange( );
195  comp ->setRange( &range );
196  }
197 
198  //Check metric object
199  if(comp == NULL){
200  gCmdSwitches.getLogFile() << "ERROR | " << "Invalid Metric Number: \"";
201  gCmdSwitches.getLogFile() << curr_comp.metric << "\"" << endl;
202 
203  cout << "ERROR | " << "Invalid Metric Number: \"";
204  cout << curr_comp.metric << "\"" << endl;
205 
206  continue;
207  }
208 
209  //Calculate metric
210  string res = comp->get_res();
211 
212  //Print result
213  gCmdSwitches.getLogFile().precision(10);
214  gCmdSwitches.getLogFile().width(65);
215  string msg_out = "RESULT | (" + itoa(curr_comp.file1_partitions[0]) + ":"
216  + itoa(curr_comp.var1) + " "
217  + itoa(curr_comp.file2_partition) + ":"
218  + itoa(curr_comp.var2) + ") "
219  + comp->get_metric_name() + ": ";
220 
221  gCmdSwitches.getLogFile() << std::left << msg_out;
222  gCmdSwitches.getLogFile() << std::right << res << "\n";
223 
224  cout.precision(10);
225  cout.width(65);
226  cout << std::left << msg_out;
227  cout << std::right << res << "\n";
228 
229  delete comp;
230  }
231 
232  //Cleanup Memory
233  points::delete_all(interp_pts);
234 }
BoundingBox getRange()
Returns a bounding box corresponding to the range of the region of interest.
Definition: main.h:144
virtual string get_res()
Definition: metric.cpp:30
A concrete object that provides the functionality for representing a bounding box geometric primitive...
Definition: BoundingBox.hpp:21
bool getVerbosity()
Get logging verbosity.
Definition: main.cpp:504
std::vector< int > file1_partitions
Definition: datatypedef.h:45
int metric
Definition: datatypedef.h:43
void setRange(BoundingBox *rangePtr)
Definition: metric.h:46
Base class for file parsing.
Definition: file.h:32
Definition: points.h:30
Used by cmd parser to store comparison information.
Definition: datatypedef.h:41
std::vector< cmp_map > getComparisonList()
Get Comparison List.
Definition: main.cpp:550
bool isRangeSpecified()
Returns a flag that indicates whether a range was supplied to this instance of CommSwitch.
Definition: main.h:133
int var2
Definition: datatypedef.h:49
ofstream & getLogFile()
Get Log File.
Definition: main.cpp:536
string itoa(int n)
Convert an int to a string.
std::vector< points * > retrievePoints(datafile *pFile, vector< int > rPartitions)
Construct a vector of pointers to datasets (point objects) from a list of partition numbers...
Definition: main.cpp:240
virtual string get_metric_name()
Definition: metric.cpp:34
ComSwitch gCmdSwitches
Definition: main.cpp:10
points * get_points(int partition)
Get a partitions&#39; points.
Definition: file.cpp:100
blockLoc i
Definition: read.cpp:79
metric * metric_select(int m, std::vector< points * > dss1, std::vector< points * > dss2, int var_ds1, int var_ds2, ofstream &outfile, string outprefix)
Definition: metric.cpp:1194
static void delete_all(std::vector< points * > points_vector)
Definition: points.cpp:227
static points * bilinear(points *pTarget, points *pSource, int rTargetVariable, int rSourceVariable)
Performs bilinear interpolation to find values from source mesh at the target points.
static bool contains_null(std::vector< points * > points_vector)
Definition: points.cpp:237
bool same_elements(std::vector< int > vector_1, std::vector< int > vector_2)
string getOutPrefix()
Get OutPrefix.
Definition: main.cpp:543
Definition: metric.h:35
int var1
Definition: datatypedef.h:46
int file2_partition
Definition: datatypedef.h:48

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 12 of file main.cpp.

References compareFiles(), files(), openAndParseFiles(), ComSwitch::parseOptions(), and ComSwitch::setArguments().

12  {
13 
14  //Parse command line options
15  gCmdSwitches.setArguments(argc, argv);
17 
18  //Open files
19  vector<datafile*> files = openAndParseFiles();
20  if(files.size() != 2)
21  return 1;
22 
23  //Perform work on the files
24  compareFiles(files);
25 
26  //Free resources
27  for(int file_num = 0; file_num < files.size(); file_num++){
28  if( files[file_num] != NULL )
29  delete files[file_num];
30  }
31 
32  return 0;
33 }
void compareFiles(vector< datafile * > pFiles)
Compare the two files, interpolating the points from the second onto the first mesh.
Definition: main.cpp:95
void setArguments(int rArgc, char *rpArgv[])
Set command line arguments.
Definition: main.cpp:365
ComSwitch gCmdSwitches
Definition: main.cpp:10
vector< datafile * > openAndParseFiles()
Open the files specified at the command line and parse them.
Definition: main.cpp:40
bool parseOptions()
Parse command options, begin logging.
Definition: main.cpp:395
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation ** files(the"Software")

Here is the call graph for this function:

long double maxPoint ( points pPoints,
int  rVar 
)

Find the maximum value.

Parameters
pPointsPoints
rVarVariable number

Definition at line 309 of file main.cpp.

References points::get_num_points(), points::get_point(), max(), and pnt::vals.

309  {
310  long double max = -std::numeric_limits<long double>::infinity();
311 
312  for(int point_num = 0; point_num < pPoints->get_num_points(); point_num++){
313  pnt curr = pPoints->get_point(point_num);
314  if(curr.vals[rVar] > max)
315  max = curr.vals[rVar];
316  }
317 
318  return max;
319 }
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
long double * vals
Definition: datatypedef.h:69
pnt get_point(int n)
Definition: points.cpp:183
Point object that represents a single point.
Definition: datatypedef.h:68
int get_num_points()
Definition: points.cpp:117

Here is the call graph for this function:

long double minPoint ( points pPoints,
int  rVar 
)

Find the minimum value.

Parameters
pPointsPoints
rVarVariable number

Definition at line 293 of file main.cpp.

References points::get_num_points(), points::get_point(), min(), and pnt::vals.

293  {
294  long double min = std::numeric_limits<long double>::infinity();
295 
296  for(int point_num = 0; point_num < pPoints->get_num_points(); point_num++){
297  pnt curr = pPoints->get_point(point_num);
298  if(curr.vals[rVar] < min)
299  min = curr.vals[rVar];
300  }
301 
302  return min;
303 }
long double * vals
Definition: datatypedef.h:69
pnt get_point(int n)
Definition: points.cpp:183
Point object that represents a single point.
Definition: datatypedef.h:68
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
int get_num_points()
Definition: points.cpp:117

Here is the call graph for this function:

vector<datafile*> openAndParseFiles ( )

Open the files specified at the command line and parse them.

Returns
Pointers to the files

Definition at line 40 of file main.cpp.

References Fileselect::detectFiletype(), ComSwitch::getConvFactor(), ComSwitch::getFieldMappings(), ComSwitch::getFileDimensions(), ComSwitch::getFileName(), ComSwitch::getIndexOrder(), ComSwitch::getInputFile(), ComSwitch::getLogFile(), ComSwitch::getNormVal(), ComSwitch::getVerbosity(), and datafile::parse().

Referenced by main().

40  {
41 
42  vector<datafile*> file_pointers;
43 
44  //Create file objects
54 
64 
65  //Check to make sure files have been properly opened
66  if(file1 == NULL || file2 == NULL){
67 
68  if(file1 != NULL)
69  delete file1;
70 
71  if(file2 != NULL)
72  delete file2;
73 
74  file1 = NULL;
75  file2 = NULL;
76 
77  return file_pointers;
78 
79  }
80 
81  //Parse file content
82  file1->parse();
83  file2->parse();
84 
85  file_pointers.push_back(file1);
86  file_pointers.push_back(file2);
87 
88  return file_pointers;
89 }
static datafile * detectFiletype(ifstream &infile, ofstream &outfile, bool loud, string infile_name, int dim, std::vector< std::vector< int > > rFieldMappings, std::vector< index_order > rIndexOrder, std::vector< adj_map > conv_factor, std::vector< adj_map > norm_val)
Use test functions to determine the filetype and to create a new file object for the input file...
Definition: fileselect.cpp:3
bool getVerbosity()
Get logging verbosity.
Definition: main.cpp:504
std::vector< adj_map > getNormVal(int rFile)
Get normalization values.
Definition: main.cpp:489
Base class for file parsing.
Definition: file.h:32
virtual void parse()
Parse the data file.
Definition: file.cpp:57
ifstream & getInputFile(int rFile)
Get Input File.
Definition: main.cpp:511
ofstream & getLogFile()
Get Log File.
Definition: main.cpp:536
std::vector< std::vector< int > > getFieldMappings(int rFile)
Get the field mapping vector for the specified file.
Definition: main.cpp:557
string getFileName(int rFile)
Get File Name.
Definition: main.cpp:523
ComSwitch gCmdSwitches
Definition: main.cpp:10
std::vector< adj_map > getConvFactor(int rFile)
Get conversion factors.
Definition: main.cpp:474
std::vector< index_order > getIndexOrder(int rFile)
Get the index order for the specified file.
Definition: main.cpp:577
int getFileDimensions(int rFile)
Get file dimensions.
Definition: main.cpp:462

Here is the call graph for this function:

Here is the caller graph for this function:

void printPointValues ( points pPoints)

Write point values to standard out.

Definition at line 259 of file main.cpp.

References points::get_num_points(), points::get_point(), pnt::size, and pnt::vals.

259  {
260 
261  //Print points
262  for(int point_num = 0; point_num < pPoints->get_num_points(); point_num++){
263  pnt curr = pPoints->get_point(point_num);
264 
265  for(int dimension = 0; dimension < curr.size; dimension++)
266  cout << curr.vals[dimension] << ", ";
267  cout << endl;
268  }
269 
270  cout << endl << "Printed " << pPoints->get_num_points() << " points" << endl;
271 }
int size
Definition: datatypedef.h:70
long double * vals
Definition: datatypedef.h:69
pnt get_point(int n)
Definition: points.cpp:183
Point object that represents a single point.
Definition: datatypedef.h:68
int get_num_points()
Definition: points.cpp:117

Here is the call graph for this function:

void printUsage ( string  rErrorMessage)

Print the rc_cmp usage message.

Parameters
rErrorStringThe error message

Definition at line 326 of file main.cpp.

References gUsage(), print_metrics(), and Fileselect::printFiletypes().

326  {
327 
328  if(rErrorMessage.compare("") != 0)
329  cout << "\n" << rErrorMessage << endl;
330  cout << "\n" << gUsage << endl;
331 
332  cout << "Comparisons are made at the point locations of input file 1" << endl << endl;
333 
334  cout << "Valid Filetypes:\n";
336  cout << endl;
337 
338  cout << "Metrics:\n";
339  print_metrics();
340  cout << endl;
341 
342 }
string gUsage("Usage: [--outfile | -o] <output file prefix>\n\t""[--infile1 | -1] <intput file 1 name>:<dimensions>\n\t""[--infile2 | -2] <intput file 2 name>:<dimensions>\n\t""[--fieldmap | -f] <File (1,2)>:<File Dimension>/<Mapped Dimension or \"null\">\n\t""[--index-order | -i] <File (1,2)>:<Partition>:<Dimension 1>,<Dimension 2>,...\n\t""[--conv | -c] <File (1,2)>:<Variable>:<Conversion Factor> \n\t""[--norm | -n] <File (1,2)>:<Variable>:<Normalization Factor> \n\t""[--range | -r] <xmin>,<ymin>,<zmin>,<xmax>,<ymax>,<zmax> \n\t""[--metric | -m] <metric number>=<file 1 partition 1>,<file 1 partition 2>,...:<file 1 variable>/\n\t"" <file 2 partition>:<file 2 variable>\n\t""[--verbose | -v]\n")
void print_metrics()
Sample Correlation Coefficient.
Definition: metric.cpp:1161
static void printFiletypes()
Print list valid filetypes to stdout.
Definition: fileselect.cpp:193

Here is the call graph for this function:

std::vector<points*> retrievePoints ( datafile pFile,
vector< int >  rPartitions 
)

Construct a vector of pointers to datasets (point objects) from a list of partition numbers.

Definition at line 240 of file main.cpp.

References datafile::get_num_partitions(), and datafile::get_points().

Referenced by compareFiles().

240  {
241 
242  std::vector<points*> datasets;
243 
244  for(int partition_record = 0; partition_record < rPartitions.size(); partition_record++){
245  if(rPartitions[partition_record] < pFile->get_num_partitions()){
246  datasets.push_back( pFile->get_points(rPartitions[partition_record]) );
247  }
248  else
249  datasets.push_back( NULL );
250  }
251 
252  return datasets;
253 }
points * get_points(int partition)
Get a partitions&#39; points.
Definition: file.cpp:100
int get_num_partitions()
Get number of partition in the file.
Definition: file.cpp:151

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

ComSwitch gCmdSwitches

Definition at line 10 of file main.cpp.