[cig-commits] r11193 - cs/benchmark/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Wed Feb 20 01:27:56 PST 2008
Author: luis
Date: 2008-02-20 01:27:56 -0800 (Wed, 20 Feb 2008)
New Revision: 11193
Added:
cs/benchmark/cigma/trunk/src/ResidualField.cpp
cs/benchmark/cigma/trunk/src/ResidualField.h
Modified:
cs/benchmark/cigma/trunk/src/CompareCmd.cpp
cs/benchmark/cigma/trunk/src/CompareCmd.h
cs/benchmark/cigma/trunk/src/Makefile.am
Log:
Added cigma::ResidualField class
* Factored out output code from the CompareCmd main loop
* Simplified processing of --output cmd line option
Modified: cs/benchmark/cigma/trunk/src/CompareCmd.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/CompareCmd.cpp 2008-02-20 09:27:54 UTC (rev 11192)
+++ cs/benchmark/cigma/trunk/src/CompareCmd.cpp 2008-02-20 09:27:56 UTC (rev 11193)
@@ -34,8 +34,10 @@
// fields
field_a = 0;
field_b = 0;
- residuals = 0; //XXX: create ResidualField class?
+ // residuals
+ residuals = new ResidualField();
+
// parameters
verbose = false;
output_frequency = 0;
@@ -43,6 +45,7 @@
cigma::CompareCmd::~CompareCmd()
{
+ delete residuals;
}
@@ -106,6 +109,53 @@
std::string inputstr;
char *in;
+
+ /* Check if --verbose was enabled */
+
+ verbose = opt->getFlag("verbose");
+ if (verbose)
+ {
+ output_frequency = 1000;
+ }
+
+ /* Determine the --output-frequency option */
+
+ in = opt->getValue("output-frequency");
+ if (in != 0)
+ {
+ inputstr = in;
+ string_to_int(inputstr, output_frequency);
+ }
+
+ if (output_frequency == 0)
+ {
+ // XXX: emit warning, or quit?
+ if (opt->getValue("output-frequency") != 0)
+ {
+ cerr << "compare: Warning: ignoring option --output-frequency" << endl;
+ }
+ verbose = false;
+ }
+
+ /* Determine the --output option */
+
+ in = opt->getValue("output");
+ if (in == 0)
+ {
+ if (opt->getFlag("debug"))
+ {
+ // XXX: provide default name when in debug mode
+ in = (char *)"foo.vtk";
+ }
+ else
+ {
+ cerr << "compare: Please specify the option --output" << endl;
+ exit(1);
+ }
+ }
+ output_path = in;
+
+
/*
* Initialization order:
* Load First field
@@ -133,7 +183,6 @@
load_args(opt, &quadratureIO, "rule");
load_args(opt, &firstIO, "first");
load_args(opt, &secondIO, "second");
- load_args(opt, &residualsIO, "output");
/* Validate these arguments and complain about missing ones */
@@ -149,12 +198,8 @@
if (secondIO.field_path == "")
secondIO.field_path = "./tests/strikeslip_hex8_1000m_t0.vtk:displacements_t0";
-
- if (residualsIO.field_path == "")
- residualsIO.field_path = "foo.vtk";
}
- validate_args(&residualsIO, "compare");
validate_args(&firstIO, "compare");
validate_args(&secondIO, "compare");
validate_args(&meshIO, "compare");
@@ -202,6 +247,7 @@
mesh = firstIO.field->meshPart;
}
assert(mesh != 0);
+ residuals->set_mesh(mesh);
/* Now load the quadrature rule. If no rule is specified on the
@@ -215,31 +261,6 @@
field_a->fe->set_quadrature(quadrature);
- /* Determine the output-frequency option */
-
- verbose = opt->getFlag("verbose");
- if (verbose)
- {
- output_frequency = 1000;
- }
-
- in = opt->getValue("output-frequency");
- if (in != 0)
- {
- inputstr = in;
- string_to_int(inputstr, output_frequency);
- }
-
- if (output_frequency == 0)
- {
- // XXX: emit warning, or quit?
- if (opt->getValue("output-frequency") != 0)
- {
- cerr << "compare: Warning: ignoring option --output-frequency" << endl;
- }
- verbose = false;
- }
-
return;
}
@@ -280,8 +301,10 @@
// norm
double L2 = 0.0;
- double *epsilon = new double[nel];
+ //double *epsilon = new double[nel]; // XXX: instead, use memory allocated by residuals member
+ double *epsilon = residuals->epsilon;
+
// XXX: what about case (mesh != field_a->meshPart)?
//FE *fe;
Cell *cell = cell_a;
@@ -368,59 +391,15 @@
/* write out data */
- /* use residualsIO
- residuals = new FE_Field();
- residuals->fe = 0;
- residuals->meshPart = mesh;
- residuals->dofHandler = new DofHandler();
- residuals->dofHandler->nno = nel; //XXX: In DofHandler, rename nno to num
- residuals->dofHandler->ndim = 1;
- residuals->dofHandler->dofs = epsilon;
+ residuals->write_vtk(output_path.c_str());
- residualsIO.field = residuals;
- residualsIO.save();
- //writer->open(output_filename);
- //writer->write_field(residuals);
- //writer->close();
-
- // */
-
- //* write out data
- {
- int nno = mesh->nno;
- int nsd = mesh->nsd;
- int ndofs = mesh->ndofs;
- double *coords = mesh->coords;
- int *connect = mesh->connect;
-
- string output_filename = residualsIO.field_path;
- string output_name = "epsilon";
-
- // XXX: create a cell-based ResidualField class
-
- std::cout << "Creating file " << output_filename << std::endl;
- //VtkUgSimpleWriter *writer = new VtkUgSimpleWriter();
- VtkWriter *writer = new VtkWriter();
- writer->open(output_filename);
- writer->write_header();
- writer->write_points(coords, nno, nsd);
- writer->write_cells(connect, nel, ndofs);
- writer->write_cell_types(nsd, nel, ndofs);
- writer->write_cell_data(output_name.c_str(), epsilon, nel, 1);
- writer->close();
- //delete writer;
- } // */
-
-
/* clean up */
- //delete residuals->dofHandler;
- //delete residuals;
- //residualsIO.field = 0;
+ //delete [] phi_a;
+ delete [] phi_b;
+ delete [] dofs_a;
- delete [] epsilon;
-
return 0;
}
Modified: cs/benchmark/cigma/trunk/src/CompareCmd.h
===================================================================
--- cs/benchmark/cigma/trunk/src/CompareCmd.h 2008-02-20 09:27:54 UTC (rev 11192)
+++ cs/benchmark/cigma/trunk/src/CompareCmd.h 2008-02-20 09:27:56 UTC (rev 11193)
@@ -1,10 +1,12 @@
#ifndef __COMPARE_CMD_H__
#define __COMPARE_CMD_H__
+#include <string>
#include "Command.h"
#include "MeshPart.h"
#include "Field.h"
#include "FE_Field.h"
+#include "ResidualField.h"
#include "Writer.h"
#include "Reader.h"
#include "MeshIO.h"
@@ -36,14 +38,14 @@
MeshPart *mesh;
FE_Field *field_a;
FE_Field *field_b;
- FE_Field *residuals;
+ ResidualField *residuals;
public:
MeshIO meshIO;
QuadratureIO quadratureIO;
FieldIO firstIO;
FieldIO secondIO;
- FieldIO residualsIO;
+ std::string output_path;
public:
bool verbose;
Modified: cs/benchmark/cigma/trunk/src/Makefile.am
===================================================================
--- cs/benchmark/cigma/trunk/src/Makefile.am 2008-02-20 09:27:54 UTC (rev 11192)
+++ cs/benchmark/cigma/trunk/src/Makefile.am 2008-02-20 09:27:56 UTC (rev 11193)
@@ -121,6 +121,8 @@
QuadratureIO.h \
Reader.cpp \
Reader.h \
+ ResidualField.cpp \
+ ResidualField.h \
SkelCmd.cpp \
SkelCmd.h \
StringUtils.cpp \
Added: cs/benchmark/cigma/trunk/src/ResidualField.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/ResidualField.cpp (rev 0)
+++ cs/benchmark/cigma/trunk/src/ResidualField.cpp 2008-02-20 09:27:56 UTC (rev 11193)
@@ -0,0 +1,52 @@
+#include <iostream>
+#include <string>
+#include "ResidualField.h"
+#include "VtkWriter.h"
+
+using namespace std;
+
+// ---------------------------------------------------------------------------
+
+cigma::ResidualField::ResidualField()
+{
+ nel = 0;
+ epsilon = 0;
+ meshPart = 0;
+}
+
+cigma::ResidualField::~ResidualField()
+{
+ if (epsilon != 0) delete [] epsilon;
+}
+
+// ---------------------------------------------------------------------------
+
+void cigma::ResidualField::set_mesh(MeshPart *meshPart)
+{
+ assert(meshPart != 0);
+ this->meshPart = meshPart;
+ this->nel = meshPart->nel;
+ epsilon = new double[nel];
+}
+
+// ---------------------------------------------------------------------------
+
+void cigma::ResidualField::write_vtk(const char *filename)
+{
+ assert(meshPart != 0); // XXX: add support for dumping residuals w/o mesh
+ assert(meshPart->nel == nel);
+
+ string output_filename = filename;
+ cout << "Creating file " << output_filename << endl;
+
+ VtkWriter writer;
+ writer.open(output_filename); // XXX: change signature to 'const char *'
+ writer.write_header();
+ writer.write_points(meshPart->coords, meshPart->nno, meshPart->nsd);
+ writer.write_cells(meshPart->connect, meshPart->nel, meshPart->ndofs);
+ writer.write_cell_types(meshPart->nsd, meshPart->nel, meshPart->ndofs); // XXX: call from w/i write_cells()
+ writer.write_cell_data("epsilon", epsilon, nel, 1);
+ writer.close();
+}
+
+// ---------------------------------------------------------------------------
Added: cs/benchmark/cigma/trunk/src/ResidualField.h
===================================================================
--- cs/benchmark/cigma/trunk/src/ResidualField.h (rev 0)
+++ cs/benchmark/cigma/trunk/src/ResidualField.h 2008-02-20 09:27:56 UTC (rev 11193)
@@ -0,0 +1,33 @@
+#ifndef __RESIDUAL_FIELD_H__
+#define __RESIDUAL_FIELD_H__
+
+//#include "Field.h"
+#include "MeshPart.h"
+
+namespace cigma
+{
+ class ResidualField;
+}
+
+//
+// XXX: do we need to derive from cigma::Field?
+//
+class cigma::ResidualField
+{
+public:
+ ResidualField();
+ ~ResidualField();
+
+public:
+ void set_mesh(MeshPart *meshPart);
+
+public:
+ void write_vtk(const char *filename);
+
+public:
+ int nel;
+ double *epsilon;
+ MeshPart *meshPart;
+};
+
+#endif
More information about the cig-commits
mailing list