[cig-commits] r13823 - in cs/cigma/trunk: . src

luis at geodynamics.org luis at geodynamics.org
Mon Jan 12 14:09:45 PST 2009


Author: luis
Date: 2009-01-12 14:09:44 -0800 (Mon, 12 Jan 2009)
New Revision: 13823

Added:
   cs/cigma/trunk/src/vtk-residuals.cpp
Modified:
   cs/cigma/trunk/Makefile.am
Log:
Added program vtk-residuals, and commented out _cigma

Modified: cs/cigma/trunk/Makefile.am
===================================================================
--- cs/cigma/trunk/Makefile.am	2009-01-12 22:09:43 UTC (rev 13822)
+++ cs/cigma/trunk/Makefile.am	2009-01-12 22:09:44 UTC (rev 13823)
@@ -10,6 +10,7 @@
 if COND_HDF5
 bin_PROGRAMS += h5attr
 endif
+bin_PROGRAMS += vtk-residuals
 
 # Libraries
 lib_LTLIBRARIES =
@@ -47,6 +48,12 @@
 h5attr_LDADD    = $(h5attr_ldadd)
 endif
 
+# vtk-residuals
+vtk_residuals_SOURCES  = $(vtk_residuals_sources)
+vtk_residuals_CPPFLAGS = $(vtk_residuals_cppflags)
+vtk_residuals_LDFLAGS  = $(vtk_residuals_ldflags)
+vtk_residuals_LDADD    = $(vtk_residuals_ldadd)
+
 # cigma-test
 if COND_CPPUNIT
 cigma_test_SOURCES  = $(cigma_test_sources)
@@ -56,21 +63,21 @@
 endif
 
 # _cigma.so
-if COND_BOOST_PYTHON
-if COND_USE_DISTUTILS
-pyexec_PROGRAMS = _cigma.so
-_cigma_so_SOURCES  = $(cigma_mod_sources)
-_cigma_so_CPPFLAGS = $(cigma_mod_cppflags)
-_cigma_so_LDADD    = $(cigma_mod_libs)
-else
-pyexec_LTLIBRARIES = _cigma.la
-_cigma_la_DEPENDENCIES = libcigma.la libann.la
-_cigma_la_SOURCES      = $(cigma_mod_sources)
-_cigma_la_CPPFLAGS     = $(cigma_mod_cppflags)
-_cigma_la_LDFLAGS      = -module -avoid-version $(cigma_mod_ldflags)
-_cigma_la_LIBADD       = $(cigma_mod_libs)
-endif
-endif
+#if COND_BOOST_PYTHON
+#if COND_USE_DISTUTILS
+#pyexec_PROGRAMS = _cigma.so
+#_cigma_so_SOURCES  = $(cigma_mod_sources)
+#_cigma_so_CPPFLAGS = $(cigma_mod_cppflags)
+#_cigma_so_LDADD    = $(cigma_mod_libs)
+#else
+#pyexec_LTLIBRARIES = _cigma.la
+#_cigma_la_DEPENDENCIES = libcigma.la libann.la
+#_cigma_la_SOURCES      = $(cigma_mod_sources)
+#_cigma_la_CPPFLAGS     = $(cigma_mod_cppflags)
+#_cigma_la_LDFLAGS      = -module -avoid-version $(cigma_mod_ldflags)
+#_cigma_la_LIBADD       = $(cigma_mod_libs)
+#endif
+#endif
 
 # Additional files to include in tarball
 EXTRA_DIST =
@@ -305,6 +312,11 @@
 # Utilities
 # {{{
 
+vtk_residuals_sources  = src/vtk-residuals.cpp
+vtk_residuals_cppflags = $(cigma_cppflags)
+vtk_residuals_ldflags  = $(cigma_ldflags)
+vtk_residuals_ldadd    = $(cigma_ldadd)
+
 h5attr_cppflags =
 h5attr_cppflags += $(HDF5_INCLUDES)
 h5attr_cppflags += $(BOOST_CPPFLAGS)
@@ -376,40 +388,42 @@
 # }}}
 
 
-if COND_USE_DISTUTILS
+#if COND_BOOST_PYTHON
+#if COND_USE_DISTUTILS
+##
+## Approximately, this is how distutils will compile the source files:
+##
+## gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2
+## 	  -Wall -Wstrict-prototypes -I./src -Wno-deprecated -DETLOG
+##     -I./src/contrib/ann/include -I/usr/include/python2.5
+##     -g -O2 -fPIC -DPYTHON_MODULE=1 -I/usr/include/python2.5
+##     -c py_Foo.cpp -o py_Foo.o
+##
+## g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions 
+## 	  -L/home/luis/cigma/.libs -I./src -Wno-deprecated -DETLOG
+## 	  -I./src/contrib/ann/include -I/usr/include/python2.5
+## 	  -g -O2 py_*.o libcigma.a libann.a -lboost_filesystem -lboost_python
+## 	  -o _cigma.so
+##
+#_cigma.so: $(cigma_mod_sources) $(cigma_mod_dependencies)
+#	BUILD_DIR=`cd $(top_builddir); pwd`; \
+#	(cd $(srcdir); \
+#	CFLAGS="-I$(top_srcdir) $(CPPFLAGS) $(cigma_mod_cppflags) $(AM_CXXFLAGS) $(CXXFLAGS)" \
+#	LDFLAGS="$(LDFLAGS) -L$$BUILD_DIR/.libs" \
+#	ARCHFLAGS="$(ARCHFLAGS)" PYLIBS="$(PYLIBS)" \
+#	$(PYTHON) src/py_cigma_setup.py build --build-lib=$$BUILD_DIR/ --build-temp=$$BUILD_DIR/pybuild -f)
 #
-# Approximately, this is how distutils will compile the source files:
+#clean-local:
+#	rm -rf pybuild
 #
-# gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2
-# 	  -Wall -Wstrict-prototypes -I./src -Wno-deprecated -DETLOG
-#     -I./src/contrib/ann/include -I/usr/include/python2.5
-#     -g -O2 -fPIC -DPYTHON_MODULE=1 -I/usr/include/python2.5
-#     -c py_Foo.cpp -o py_Foo.o
-#
-# g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions 
-# 	  -L/home/luis/cigma/.libs -I./src -Wno-deprecated -DETLOG
-# 	  -I./src/contrib/ann/include -I/usr/include/python2.5
-# 	  -g -O2 py_*.o libcigma.a libann.a -lboost_filesystem -lboost_python
-# 	  -o _cigma.so
-#
-_cigma.so: $(cigma_mod_sources) $(cigma_mod_dependencies)
-	BUILD_DIR=`cd $(top_builddir); pwd`; \
-	(cd $(srcdir); \
-	CFLAGS="-I$(top_srcdir) $(CPPFLAGS) $(cigma_mod_cppflags) $(AM_CXXFLAGS) $(CXXFLAGS)" \
-	LDFLAGS="$(LDFLAGS) -L$$BUILD_DIR/.libs" \
-	ARCHFLAGS="$(ARCHFLAGS)" PYLIBS="$(PYLIBS)" \
-	$(PYTHON) src/py_cigma_setup.py build --build-lib=$$BUILD_DIR/ --build-temp=$$BUILD_DIR/pybuild -f)
+#else
+##
+## Use libtool instead of distutils
+##
+#endif
+#endif
 
-clean-local:
-	rm -rf pybuild
 
-else
-#
-# Use libtool instead of distutils
-#
-endif
-
-
 cigma_mod_cppflags =
 cigma_mod_cppflags += -Wno-deprecated
 cigma_mod_cppflags += $(LOGGER_FLAGS)
@@ -459,7 +473,7 @@
 endif
 
 if ENABLE_TESTING
-TESTS += $(top_srcdir)/tests/pytests/runner.py
+#TESTS += $(top_srcdir)/tests/pytests/runner.py
 TESTS += $(top_srcdir)/tests/system/runner.py
 endif
 
@@ -539,23 +553,23 @@
 	tests/main.cpp
 
 # python tests
-EXTRA_DIST += \
-	tests/pytests/test_cigma.py \
-	tests/pytests/test_point.py \
-	tests/pytests/test_points.py \
-	tests/pytests/test_cell.py \
-	tests/pytests/test_quadrature.py \
-	tests/pytests/test_fe.py \
-	tests/pytests/test_mesh_part.py \
-	tests/pytests/test_locator.py \
-	tests/pytests/test_dof_handler.py \
-	tests/pytests/test_function.py \
-	tests/pytests/test_field.py \
-	tests/pytests/test_residuals.py \
-	tests/pytests/test_compare.py \
-	tests/pytests/test_eval.py \
-	tests/pytests/test_extract.py \
-	tests/pytests/runner.py
+#EXTRA_DIST += \
+#	tests/pytests/test_cigma.py \
+#	tests/pytests/test_point.py \
+#	tests/pytests/test_points.py \
+#	tests/pytests/test_cell.py \
+#	tests/pytests/test_quadrature.py \
+#	tests/pytests/test_fe.py \
+#	tests/pytests/test_mesh_part.py \
+#	tests/pytests/test_locator.py \
+#	tests/pytests/test_dof_handler.py \
+#	tests/pytests/test_function.py \
+#	tests/pytests/test_field.py \
+#	tests/pytests/test_residuals.py \
+#	tests/pytests/test_compare.py \
+#	tests/pytests/test_eval.py \
+#	tests/pytests/test_extract.py \
+#	tests/pytests/runner.py
 
 # system tests
 EXTRA_DIST += \

Added: cs/cigma/trunk/src/vtk-residuals.cpp
===================================================================
--- cs/cigma/trunk/src/vtk-residuals.cpp	                        (rev 0)
+++ cs/cigma/trunk/src/vtk-residuals.cpp	2009-01-12 22:09:44 UTC (rev 13823)
@@ -0,0 +1,188 @@
+#include <cstdlib>
+#include <iostream>
+#include <string>
+
+#include <boost/program_options.hpp>
+#include <boost/filesystem.hpp>
+#include <boost/shared_ptr.hpp>
+
+#include "tri_logger.hpp"
+
+#include "MeshPart.h"
+#include "Residuals.h"
+#include "core_args.h"
+#include "core_array.h"
+#include "core_writers.h"
+#include "core_readers.h"
+#include "io_hdf5_reader.h"
+#include "io_vtk_writer.h"
+
+using namespace std;
+using namespace boost;
+using namespace cigma;
+
+namespace po = boost::program_options;
+namespace fs = boost::filesystem;
+
+
+int main(int argc, char* argv[])
+{
+    string inloc, outloc;
+    string meshloc, ncloc, ebloc, celltype;
+    
+    po::options_description all, opts, other;
+    po::positional_options_description args;
+    po::variables_map vm;
+
+    opts.add_options()
+        ("mesh,m", po::value<string>(&meshloc), "Associated mesh for residuals")
+        ("mesh-cell", po::value<string>(&celltype), "...cell type for mesh")
+        ("mesh-coords", po::value<string>(&ncloc),  "...node coordinates for mesh")
+        ("mesh-connect", po::value<string>(&ebloc), "...connectivity for mesh")
+        ("input,i", po::value<string>(&inloc), "HDF5 input file for residuals")
+        ("output,o", po::value<string>(&outloc), "VTK output file for residuals")
+        ;
+
+    other.add_options()
+        ("help,h", "produce help message")
+        ("debug,D", "print debugging information")
+        ;
+    
+    all.add(opts).add(other);
+
+    args.add("mesh", 1);
+    args.add("input", 1);
+    args.add("output", 1);
+
+    po::store(po::command_line_parser(argc, argv).options(all).positional(args).run(), vm);
+    po::notify(vm);
+
+    if (vm.count("help") || (argc == 1))
+    {
+        cout << "Usage: vtk-residuals <IN-MESH> <IN-HDF5-RESIDUALS> <OUT-VTK-RESIDUALS>" << endl;
+        cout << endl;
+
+        if (opts.options().size() > 0)
+        {
+            cout << "Main Options: " << endl;
+            cout << opts << endl;
+        }
+
+        if (other.options().size() > 0)
+        {
+            cout << "Other Options: " << endl;
+            cout << other << endl;
+        }
+
+        return 1;
+    }
+
+    if (!vm.count("debug"))
+    {
+        TRI_LOG_OFF();
+    }
+
+    if (!vm.count("mesh") && !vm.count("mesh-coords") && !vm.count("mesh-connect"))
+    {
+        cout << "Error: No mesh was specified (use --mesh options)" << endl;
+        return 2;
+    }
+
+    if (!vm.count("input"))
+    {
+        cout << "Error: No input residuals dataset was given (use --input option)" << endl;
+        return 2;
+    }
+
+    if (!vm.count("output"))
+    {
+        cout << "Error: No output residuals file was given (use --output option)" << endl;
+        return 2;
+    }
+
+    MeshInfo mesh_info;
+    mesh_info.p_mesh = DataPath(meshloc);
+    mesh_info.p_nc = DataPath(ncloc);
+    mesh_info.p_eb = DataPath(ebloc);
+    mesh_info.cell_type_name = celltype;
+
+    DataPath in(inloc);
+    DataPath out(outloc);
+
+    if (!in.is_hdf5_file())
+    {
+        cout << "Error: For input residuals, please specify a HDF5 file" << endl;
+        return 2;
+    }
+
+    if (!out.is_vtk_file())
+    {
+        cout << "Error: For output residuals, please specify a VTK file" << endl;
+        return 2;
+    }
+
+    TRI_LOG_STR(">> Configuring mesh object");
+    TRI_LOG(mesh_info);
+    shared_ptr<MeshPart> mesh = MeshPart::New(mesh_info);
+    if (!mesh)
+    {
+        cout << "Error: Could not initialize mesh (review the given --mesh options)" << endl;
+        return 2;
+    }
+
+    TRI_LOG_STR(">> Configuring residuals object");
+    shared_ptr<Residuals> residuals(new Residuals);
+    residuals->meshPart = mesh;
+    residuals->nel = mesh->n_cells();
+
+    residuals->volume = new double[residuals->nel];
+    residuals->computeMaxCellDiameter();
+    residuals->computeVolume();
+
+    TRI_LOG_STR(">> Reading residuals from HDF5 file");
+    TRI_LOG(in);
+    cigma::array<double>* epsilon = 0;
+    try
+    {
+        epsilon = ReadArray(in);
+    }
+    catch (cigma::Exception& e)
+    {
+        cout << "Error: " << e.getMessage() << " (in " << e.getName() << ")" << endl;
+        return 3;
+    }
+    if (epsilon == 0)
+    {
+        cout << "Error: Could not read input residuals from '" << in << "'" << endl;
+        return 3;
+    }
+    if (mesh->n_cells() != epsilon->n_points())
+    {
+        cout << "Error: Mesh is incompatible with given residuals (found "
+             << mesh->n_cells() << " cells in mesh, but expecting "
+             << epsilon->n_points() << ")"
+             << endl;
+        delete epsilon;
+        return 4;
+    }
+    if (epsilon->n_dim() != 1)
+    {
+        cout << "Error: For input residuals, expected dimensions ["
+             << epsilon->n_points() << " x 1] but found ["
+             << epsilon->n_points() << " x " << epsilon->n_dim()
+             << "]" << endl;
+        delete epsilon;
+        return 4;
+    }
+    residuals->epsilon = epsilon->_data;
+    epsilon->_data = 0;
+    delete epsilon;
+    epsilon = 0;
+    residuals->computeMaxResidual();
+
+    TRI_LOG_STR(">> Writing residuals to VTK file");
+    cout << "Writing residuals to VTK file '" << out.filename() << "'" << endl;
+    WriteResiduals(out, residuals, true);
+
+    return 0;
+}



More information about the CIG-COMMITS mailing list