diff --git a/examples/Makefile.am b/examples/Makefile.am
index 043a44c3..85dce93a 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -31,6 +31,7 @@ $(BOOST_SYSTEM_LIB)
noinst_PROGRAMS = \
compute_tof \
+compute_tof_from_files \
refine_wells \
scaneclipsedeck \
sim_2p_comp_reorder \
@@ -54,6 +55,9 @@ endif
compute_tof_SOURCES = compute_tof.cpp
compute_tof_LDADD = $(LDADD) $(LINK_BOOST_FILESYSTEM)
+compute_tof_from_files_SOURCES = compute_tof_from_files.cpp
+compute_tof_from_files_LDADD = $(LDADD) $(LINK_BOOST_FILESYSTEM)
+
refine_wells_SOURCES = refine_wells.cpp
if HAVE_ERT
diff --git a/examples/compute_tof_from_files.cpp b/examples/compute_tof_from_files.cpp
new file mode 100644
index 00000000..012def4e
--- /dev/null
+++ b/examples/compute_tof_from_files.cpp
@@ -0,0 +1,174 @@
+/*
+ Copyright 2012 SINTEF ICT, Applied Mathematics.
+
+ This file is part of the Open Porous Media project (OPM).
+
+ OPM is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OPM is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OPM. If not, see .
+*/
+
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif // HAVE_CONFIG_H
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+
+namespace
+{
+ void warnIfUnusedParams(const Opm::parameter::ParameterGroup& param)
+ {
+ if (param.anyUnused()) {
+ std::cout << "-------------------- Warning: unused parameters: --------------------\n";
+ param.displayUsage();
+ std::cout << "-------------------------------------------------------------------------" << std::endl;
+ }
+ }
+} // anon namespace
+
+
+
+// ----------------- Main program -----------------
+int
+main(int argc, char** argv)
+{
+ using namespace Opm;
+
+ parameter::ParameterGroup param(argc, argv, false);
+
+ // Read grid.
+ GridManager grid_manager(param.get("grid_filename"));
+ const UnstructuredGrid& grid = *grid_manager.c_grid();
+
+ // Read porosity, compute pore volume.
+ std::vector porevol;
+ {
+ std::ifstream poro_stream(param.get("poro_filename").c_str());
+ std::istream_iterator beg(poro_stream);
+ std::istream_iterator end;
+ porevol.assign(beg, end); // Now contains poro.
+ if (int(porevol.size()) != grid.number_of_cells) {
+ THROW("Size of porosity field differs from number of cells.");
+ }
+ for (int i = 0; i < grid.number_of_cells; ++i) {
+ porevol[i] *= grid.cell_volumes[i];
+ }
+ }
+
+ // Read flux.
+ std::vector flux;
+ {
+ std::ifstream flux_stream(param.get("flux_filename").c_str());
+ std::istream_iterator beg(flux_stream);
+ std::istream_iterator end;
+ flux.assign(beg, end);
+ if (int(flux.size()) != grid.number_of_faces) {
+ THROW("Size of flux field differs from number of faces.");
+ }
+ }
+
+ // Read source terms.
+ std::vector src;
+ {
+ std::ifstream src_stream(param.get("src_filename").c_str());
+ std::istream_iterator beg(src_stream);
+ std::istream_iterator end;
+ src.assign(beg, end);
+ if (int(src.size()) != grid.number_of_cells) {
+ THROW("Size of source term field differs from number of cells.");
+ }
+ }
+
+ // Choice of tof solver.
+ bool use_dg = param.getDefault("use_dg", false);
+ int dg_degree = -1;
+ bool use_cvi = false;
+ if (use_dg) {
+ dg_degree = param.getDefault("dg_degree", 0);
+ use_cvi = param.getDefault("use_cvi", false);
+ }
+
+ // Write parameters used for later reference.
+ bool output = param.getDefault("output", true);
+ std::ofstream epoch_os;
+ std::string output_dir;
+ if (output) {
+ output_dir =
+ param.getDefault("output_dir", std::string("output"));
+ boost::filesystem::path fpath(output_dir);
+ try {
+ create_directories(fpath);
+ }
+ catch (...) {
+ THROW("Creating directories failed: " << fpath);
+ }
+ param.writeParam(output_dir + "/simulation.param");
+ }
+
+ // Issue a warning if any parameters were unused.
+ warnIfUnusedParams(param);
+
+ // Solve time-of-flight.
+ Opm::time::StopWatch transport_timer;
+ transport_timer.start();
+ std::vector tof;
+ if (use_dg) {
+ Opm::TransportModelTracerTofDiscGal tofsolver(grid, use_cvi);
+ tofsolver.solveTof(&flux[0], &porevol[0], &src[0], dg_degree, tof);
+ } else {
+ Opm::TransportModelTracerTof tofsolver(grid);
+ tofsolver.solveTof(&flux[0], &porevol[0], &src[0], tof);
+ }
+ transport_timer.stop();
+ double tt = transport_timer.secsSinceStart();
+ std::cout << "Transport solver took: " << tt << " seconds." << std::endl;
+
+ // Output.
+ if (output) {
+ std::string tof_filename = output_dir + "/tof.txt";
+ std::ofstream tof_stream(tof_filename.c_str());
+ tof_stream.precision(16);
+ std::copy(tof.begin(), tof.end(), std::ostream_iterator(tof_stream, "\n"));
+ }
+}
diff --git a/opm/core/GridManager.cpp b/opm/core/GridManager.cpp
index d286e504..528e2e12 100644
--- a/opm/core/GridManager.cpp
+++ b/opm/core/GridManager.cpp
@@ -97,6 +97,20 @@ namespace Opm
+ /// Construct a grid from an input file.
+ /// The file format used is currently undocumented,
+ /// and is therefore only suited for internal use.
+ GridManager::GridManager(const std::string& input_filename)
+ {
+ ug_ = read_grid(input_filename.c_str());
+ if (!ug_) {
+ THROW("Failed to read grid from file " << input_filename);
+ }
+ }
+
+
+
+
/// Destructor.
GridManager::~GridManager()
{
diff --git a/opm/core/GridManager.hpp b/opm/core/GridManager.hpp
index 26e335f2..36846f2c 100644
--- a/opm/core/GridManager.hpp
+++ b/opm/core/GridManager.hpp
@@ -20,6 +20,7 @@
#ifndef OPM_GRIDMANAGER_HEADER_INCLUDED
#define OPM_GRIDMANAGER_HEADER_INCLUDED
+#include
struct UnstructuredGrid;
@@ -53,6 +54,11 @@ namespace Opm
GridManager(int nx, int ny, int nz,
double dx, double dy, double dz);
+ /// Construct a grid from an input file.
+ /// The file format used is currently undocumented,
+ /// and is therefore only suited for internal use.
+ GridManager(const std::string& input_filename);
+
/// Destructor.
~GridManager();