[cig-commits] r11430 - cs/benchmark/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Wed Mar 12 11:03:35 PDT 2008
Author: luis
Date: 2008-03-12 11:03:35 -0700 (Wed, 12 Mar 2008)
New Revision: 11430
Modified:
cs/benchmark/cigma/trunk/src/EvalCmd.cpp
cs/benchmark/cigma/trunk/src/EvalCmd.h
Log:
Updates to EvalCmd.{h,cpp}
Modified: cs/benchmark/cigma/trunk/src/EvalCmd.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/EvalCmd.cpp 2008-03-12 18:03:34 UTC (rev 11429)
+++ cs/benchmark/cigma/trunk/src/EvalCmd.cpp 2008-03-12 18:03:35 UTC (rev 11430)
@@ -2,19 +2,28 @@
#include <cassert>
#include "EvalCmd.h"
#include "StringUtils.h"
+
+#include "HdfReader.h"
#include "VtkReader.h"
+#include "TextReader.h"
+
+#include "HdfWriter.h"
#include "VtkWriter.h"
+#include "TextWriter.h"
+
#include "MeshPart.h"
-#include "Tet.h"
-#include "Hex.h"
+using namespace std;
+using namespace cigma;
+
// ---------------------------------------------------------------------------
cigma::EvalCmd::EvalCmd()
{
name = "eval";
+ field = 0;
points = 0;
- field = 0;
+ values = 0;
}
cigma::EvalCmd::~EvalCmd()
@@ -25,122 +34,114 @@
void cigma::EvalCmd::setupOptions(AnyOption *opt)
{
- std::cout << "Calling cigma::EvalCmd::setupOptions()" << std::endl;
+ //cout << "Calling cigma::EvalCmd::setupOptions()" << endl;
assert(opt != 0);
/* setup usage */
opt->addUsage("Usage:");
opt->addUsage("");
opt->addUsage(" cigma eval [args ...]");
- opt->addUsage(" --field Field path");
- opt->addUsage(" --points List of points");
- opt->addUsage(" --output Output file");
+ opt->addUsage(" --points Input points to evaluate on");
+ opt->addUsage(" --field Input field to evaluate");
+ opt->addUsage(" --values Target path for result of evaluations");
/* setup flags and options */
opt->setFlag("help", 'h');
+ opt->setFlag("verbose", 'v');
opt->setOption("field");
+ opt->setOption("field-mesh");
+ opt->setOption("field-mesh-coordinates");
+ opt->setOption("field-mesh-connectivity");
+
opt->setOption("points");
- opt->setOption("output");
+ opt->setOption("values");
return;
}
+
void cigma::EvalCmd::configure(AnyOption *opt)
{
- using namespace cigma;
+ //cout << "Calling cigma::EvalCmd::configure()" << endl;
+ assert(opt != 0);
- std::cout << "Calling cigma::EvalCmd::configure()" << std::endl;
-
- std::string input, location, inputfile, ext;
- std::string pointsfile;
+ string inputstr;
char *in;
- in = opt->getValue("field");
+
+ // read verbose flag
+ verbose = opt->getFlag("verbose");
+
+
+ /* determine the output values path */
+ in = opt->getValue("values");
if (in == 0)
{
- std::cerr << "eval: Please specify the option --field" << std::endl;
+ cerr << "eval: Please specify the output option --values" << endl;
exit(1);
}
- input = in;
- parse_dataset_path(input, location, inputfile, ext);
- std::cout << "field location = " << location << std::endl;
- std::cout << "field inputfile = " << inputfile << std::endl;
- std::cout << "field extension = " << ext << std::endl;
+ inputstr = in;
- in = opt->getValue("points");
- if (in == 0)
+ // determine the extension and instantiate the appropriate writer object
+ string values_ext;
+ parse_dataset_path(inputstr, values_loc, values_file, values_ext);
+ new_writer(&values_writer, values_ext);
+ if (values_writer == 0)
{
- std::cerr << "eval: Please specify the option --points" << std::endl;
+ cerr << "eval: Specified a bad extension (" << values_ext << ") for "
+ << "output file" << values_file << endl;
exit(1);
}
- pointsfile = in;
+ if ((values_loc == "") && (values_writer->getType() == Writer::HDF_WRITER))
+ {
+ values_loc = "/values";
+ }
- in = opt->getValue("output");
+
+ /* determine the input points path */
+ in = opt->getValue("points");
if (in == 0)
{
- std::cerr << "eval: Please specify the option --output" << std::endl;
+ cerr << "eval: Please specify the input option --points" << endl;
exit(1);
}
- output_filename = in;
+ inputstr = in;
- int nno, nsd;
- int nel, ndofs;
- double *coords;
- int *connect;
- int dofs_nno, dofs_valdim;
- double *dofs;
-
- VtkReader *reader = new VtkReader();
- reader->open(inputfile);
- reader->get_coordinates(&coords, &nno, &nsd);
- reader->get_connectivity(&connect, &nel, &ndofs);
- reader->get_scalar_point_data(location.c_str(), &dofs, &dofs_nno, &dofs_valdim);
-
- field = new FE_Field();
- field->dim = nsd;
- field->rank = dofs_valdim;
- field->meshPart = new MeshPart();
- field->meshPart->set_coordinates(coords, nno, nsd);
- field->meshPart->set_connectivity(connect, nel, ndofs);
-
- switch (ndofs)
+ // determine the extension and instantiate the appropriate reader object
+ string points_ext;
+ parse_dataset_path(inputstr, points_loc, points_file, points_ext);
+ new_reader(&points_reader, points_ext);
+ if (points_reader == 0)
{
- case 4:
- field->fe = new FE();
- field->fe->cell = new Tet();
- break;
-
- case 8:
- field->fe = new FE();
- field->fe->cell = new Hex();
- break;
+ cerr << "eval: Specified a bad extension (" << points_ext << ") for "
+ << "input file" << points_file << endl;
+ exit(1);
}
- assert(field->fe != 0);
- assert(field->fe->cell != 0);
- field->meshPart->cell = field->fe->cell;
+ if ((points_loc == "") && (points_reader->getType() == Reader::HDF_READER))
+ {
+ points_loc = "/points";
+ }
- field->dofHandler = new DofHandler();
- field->dofHandler->meshPart = field->meshPart;
- field->dofHandler->set_data(dofs, dofs_nno, dofs_valdim);
+ /* determine the input field */
+ load_args(opt, &fieldIO, "field");
+ validate_args(&fieldIO, "eval");
+ fieldIO.load();
+ field = fieldIO.field;
+ assert(field != 0);
+ cout << "field path = " << fieldIO.field_path << endl;
+ cout << "field rank = " << field->n_rank() << endl;
+ //cout << (*field) << endl;
- int pts_nno, pts_nsd;
- double *pts_coords;
-
- VtkReader *pointsreader = new VtkReader();
- pointsreader->open(pointsfile);
- pointsreader->get_coordinates(&pts_coords, &pts_nno, &pts_nsd);
- points = new Points();
- points->set_data(pts_coords, pts_nno, pts_nsd);
-
return;
}
int cigma::EvalCmd::run()
{
- std::cout << "Calling cigma::EvalCmd::run()" << std::endl;
+ //cout << "Calling cigma::EvalCmd::run()" << endl;
assert(field != 0);
assert(points != 0);
+ assert(values != 0);
assert(field->n_dim() == points->n_dim());
// indices
@@ -153,9 +154,19 @@
// data
double *phi = new double[npts * valdim];
+
for (i = 0; i < npts; i++)
{
double *globalPoint = (*points)[i];
+ field->eval(globalPoint, &phi[valdim*i]);
+ }
+
+
+
+ /*
+ for (i = 0; i < npts; i++)
+ {
+ double *globalPoint = (*points)[i];
field->meshPart->find_cell(globalPoint, &e);
field->meshPart->get_cell_coords(e, field->fe->cell->globverts);
field->eval(globalPoint, &phi[valdim*i]);
@@ -168,6 +179,66 @@
writer->write_point_data("values", phi, npts, valdim);
writer->close();
//delete writer;
+ */
+
+
+ int ierr;
+
+ cout << "Creating file " << values_file << endl;
+
+ if (values_writer->getType() == Writer::HDF_WRITER)
+ {
+ HdfWriter *writer = static_cast<HdfWriter*>(values_writer);
+ ierr = writer->open(values_file);
+ if (ierr < 0)
+ {
+ cerr << "Error: Could not open (or create) the HDF5 file " << values_file << endl;
+ exit(1);
+ }
+
+ ierr = writer->write_coordinates(values_loc.c_str(), phi, npts, valdim);
+ if (ierr < 0)
+ {
+ cerr << "Error: Could not write values dataset " << values_loc << endl;
+ exit(1);
+ }
+ writer->close();
+ }
+ else if (values_writer->getType() == Writer::TXT_WRITER)
+ {
+ TextWriter *writer = static_cast<TextWriter*>(values_writer);
+ ierr = writer->open(values_file);
+ if (ierr < 0)
+ {
+ cerr << "Error: Could not create output text file " << values_file << endl;
+ exit(1);
+ }
+ writer->write_coordinates(phi, npts, valdim);
+ }
+ else if (values_writer->getType() == Writer::VTK_WRITER)
+ {
+ VtkWriter *writer = static_cast<VtkWriter*>(writer);
+ ierr = vtkWriter->open(values_file);
+ if (ierr < 0)
+ {
+ cerr << "Error: Could not create output VTK file " << values_file << endl;
+ exit(1);
+ }
+ writer->write_header();
+ //writer->write_points(...);
+ writer->write_point_data("values", phi, npts, valdim);
+ writer->close();
+ }
+ else
+ {
+ /* this should be unreachable */
+ cerr << "Fatal Error: Unsupported extension in output filename?" << endl;
+ return 1;
+ }
+
+ // XXX: wrap this guy inside an auto_ptr
+ delete [] phi;
+
return 0;
}
Modified: cs/benchmark/cigma/trunk/src/EvalCmd.h
===================================================================
--- cs/benchmark/cigma/trunk/src/EvalCmd.h 2008-03-12 18:03:34 UTC (rev 11429)
+++ cs/benchmark/cigma/trunk/src/EvalCmd.h 2008-03-12 18:03:35 UTC (rev 11430)
@@ -2,9 +2,14 @@
#define __EVAL_CMD_H__
#include "Command.h"
-#include "FE_Field.h"
+
+#include "Field.h"
#include "Points.h"
+//#include "FieldIO.h"
+//#include "PointsIO.h"
+
+
namespace cigma
{
class EvalCmd;
@@ -27,9 +32,22 @@
int run();
public:
- FE_Field *field;
+ FieldIO fieldIO;
+
+ Reader *points_reader;
+ std::string points_loc;
+ std::string points_file;
+
+ Writer *values_writer;
+ std::string values_loc;
+ std::string values_file;
+
+ bool verbose;
+
+public:
+ Field *field;
Points *points;
- std::string output_filename;
+ Points *values;
};
#endif
More information about the cig-commits
mailing list