[cig-commits] r11536 - cs/benchmark/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Mon Mar 24 09:27:33 PDT 2008
Author: luis
Date: 2008-03-24 09:27:33 -0700 (Mon, 24 Mar 2008)
New Revision: 11536
Added:
cs/benchmark/cigma/trunk/src/SearchCmd.cpp
cs/benchmark/cigma/trunk/src/SearchCmd.h
Log:
Added SearchCmd for testing the locator classes
Added: cs/benchmark/cigma/trunk/src/SearchCmd.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/SearchCmd.cpp (rev 0)
+++ cs/benchmark/cigma/trunk/src/SearchCmd.cpp 2008-03-24 16:27:33 UTC (rev 11536)
@@ -0,0 +1,271 @@
+#include <iostream>
+#include <cstdlib>
+#include <ctime>
+#include <cassert>
+
+#include "SearchCmd.h"
+#include "StringUtils.h"
+
+#include "MeshPart.h"
+#include "AnnLocator.h"
+
+#include "Reader.h"
+#include "Timer.h"
+
+#include "Writer.h"
+#include "HdfWriter.h"
+
+
+using namespace std;
+using namespace cigma;
+
+// ---------------------------------------------------------------------------
+
+SearchCmd::SearchCmd()
+{
+ name = "search";
+
+ points = 0;
+ meshPart = 0;
+ coordsField = 0;
+}
+
+SearchCmd::~SearchCmd()
+{
+ // XXX
+}
+
+// ---------------------------------------------------------------------------
+
+void SearchCmd::setupOptions(AnyOption *opt)
+{
+
+ assert(opt != 0);
+
+ /* setup usage */
+ opt->addUsage("Usage:");
+ opt->addUsage(" cigma search [options]");
+ opt->addUsage(" --points Path to search points");
+ opt->addUsage(" --mesh Path to mesh");
+ opt->addUsage(" --output Path to output dataset");
+
+ /* setup flags and options */
+ opt->setFlag("help", 'h');
+ opt->setFlag("debug");
+
+ // options for mesh
+ opt->setOption("mesh");
+ opt->setOption("mesh-coordinates");
+ opt->setOption("mesh-connectivity");
+
+ // options for points
+ opt->setOption("points");
+
+ // options for output
+ opt->setOption("output",'o');
+
+ // other options
+ opt->setFlag("verbose",'v');
+}
+
+
+void SearchCmd::configure(AnyOption *opt)
+{
+ string inputstr;
+ char *in;
+
+ /* Check if --verbose was enabled */
+
+ verbose = opt->getFlag("verbose");
+
+ /* Determine the output option */
+ in = opt->getValue("output");
+ if (in != 0)
+ {
+ inputstr = in;
+ }
+ string outputLoc, outputExt;
+ parse_dataset_path(inputstr, outputLoc, outputFile, outputExt);
+ writer = NewWriter(outputExt.c_str());
+ if (writer->getType() != Writer::HDF_WRITER)
+ {
+ cerr << "search: Please specify a target HDF5 file in --output option" << endl;
+ exit(1);
+ }
+
+
+ /* Gather up the expected command line arguments */
+
+ meshPartReader.load_args(opt, "mesh");
+ pointsReader.load_args(opt, "points");
+
+ meshPartReader.validate_args("search");
+ pointsReader.validate_args("search");
+
+ /* load mesh into memory */
+ meshPartReader.load_mesh();
+ pointsReader.load_points();
+
+ points = pointsReader.points;
+ meshPart = meshPartReader.meshPart;
+
+ if (meshPart == 0)
+ {
+ cerr << "search: Could not load mesh!" << endl;
+ exit(1);
+ }
+
+ if (points == 0)
+ {
+ cerr << "search: Could not load points!" << endl;
+ exit(1);
+ }
+
+ coordsField = new FE_Field();
+ coordsField->dim = meshPart->nsd;
+ coordsField->rank = meshPart->nsd;
+ coordsField->meshPart = meshPart;
+ coordsField->meshPart->set_cell();
+
+ /*
+ if (coordsField->meshPart->nsd == 3)
+ {
+ AnnLocator *locator = new AnnLocator();
+ coordsField->meshPart->set_locator(locator);
+ }
+ // */
+
+ return;
+}
+
+
+// ---------------------------------------------------------------------------
+
+int SearchCmd::run()
+{
+
+ assert(points != 0);
+ assert(meshPart != 0);
+
+
+ int i,j;
+ int e;
+ const int nsd = meshPart->nsd;
+ const int nel = meshPart->nel;
+ const int npts = points->n_points();
+
+ int *cellPointCount = new int[nel]; // how many points fall on given cell?
+ int *pointCellCount = new int[npts]; // how many cells were searched for a given point?
+
+ for (e = 0; e < nel; e++)
+ {
+ cellPointCount[e] = 0;
+ }
+
+ for (i = 0; i < npts; i++)
+ {
+ pointCellCount[i] = 0;
+ }
+
+ if (meshPart->locator != 0)
+ {
+ for (i = 0; i < points->n_points(); i++)
+ {
+ double *pt = (*points)[nsd*i];
+ //bool found = meshPart->find_cell(pt, &parentCell);
+ bool found = false;
+ meshPart->locator->search(pt);
+ for (j = 0; j < meshPart->locator->n_idx(); j++)
+ {
+ e = meshPart->locator->idx(j);
+ if (e < 0)
+ {
+ continue;
+ }
+ meshPart->select_cell(e);
+ if (meshPart->cell->global_interior(pt))
+ {
+ found = true;
+ cellPointCount[e]++;
+ pointCellCount[i] = j+1;
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ time_t t0,t1;
+ time(&t0);
+ if (verbose)
+ {
+ cout << "starting...";
+ }
+
+ for (i = 0; i < points->n_points(); i++)
+ {
+ double *pt = (*points)[nsd*i];
+ bool found = false;
+ for (e = 0; e < nel; e++)
+ {
+ meshPart->select_cell(e);
+ if (meshPart->cell->global_interior(pt))
+ {
+ found = true;
+ cellPointCount[e]++;
+ pointCellCount[i] = e+1;
+ break;
+ }
+ }
+ }
+
+ time(&t1);
+ double total_time = t1 - t0;
+ if (verbose)
+ {
+ cout << "done!" << endl;
+ cout << "total time: " << total_time << endl;
+ }
+ }
+
+
+ int ierr;
+
+ HdfWriter *hdfWriter = static_cast<HdfWriter*>(writer);
+
+ ierr = hdfWriter->open(outputFile.c_str());
+ if (ierr < 0)
+ {
+ cerr << "search: Could not open output file " << outputFile << endl;
+ exit(1);
+ }
+
+ string loc;
+
+ loc = "/CellPointCount";
+ ierr = hdfWriter->write_int_dataset(loc.c_str(), cellPointCount, nel, 1);
+ if (ierr < 0)
+ {
+ cerr << "search: Could not write dataset " << loc << endl;
+ exit(1);
+ }
+
+ loc = "/PointCellCount";
+ ierr = hdfWriter->write_int_dataset(loc.c_str(), pointCellCount, npts, 1);
+ if (ierr < 0)
+ {
+ cerr << "search: Could not write dataset " << loc << endl;
+ exit(1);
+ }
+
+ ierr = hdfWriter->close();
+
+
+ delete [] cellPointCount;
+ delete [] pointCellCount;
+
+
+ return 0;
+}
+
+// ---------------------------------------------------------------------------
Added: cs/benchmark/cigma/trunk/src/SearchCmd.h
===================================================================
--- cs/benchmark/cigma/trunk/src/SearchCmd.h (rev 0)
+++ cs/benchmark/cigma/trunk/src/SearchCmd.h 2008-03-24 16:27:33 UTC (rev 11536)
@@ -0,0 +1,49 @@
+#ifndef __SEARCH_CMD_H__
+#define __SEARCH_CMD_H__
+
+#include <string>
+#include "Command.h"
+
+
+#include "Points.h"
+#include "MeshPart.h"
+#include "FE_Field.h"
+
+#include "MeshPartReader.h"
+#include "PointsReader.h"
+#include "HdfWriter.h"
+#include "TextWriter.h"
+
+namespace cigma
+{
+ class SearchCmd;
+}
+
+/**
+ * @brief Callback object for `cigma search [args ...]'
+ */
+class cigma::SearchCmd : public Command
+{
+public:
+ SearchCmd();
+ ~SearchCmd();
+
+public:
+ void setupOptions(AnyOption *opt);
+ void configure(AnyOption *opt);
+ int run();
+
+public:
+ Points *points;
+ MeshPart *meshPart;
+ FE_Field *coordsField;
+
+public:
+ PointsReader pointsReader;
+ MeshPartReader meshPartReader;
+ Writer *writer;
+ std::string outputFile;
+ bool verbose;
+};
+
+#endif
More information about the cig-commits
mailing list