From f5ad1614096d4fa207048d49dbe20035ff956057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Mon, 12 Mar 2012 13:44:05 +0100 Subject: [PATCH] Changed some function signatures to take const UnstructuredGrid& instead of ptr. --- examples/spu_2p.cpp | 15 +++++++------- opm/core/utility/writeVtkData.cpp | 34 +++++++++++++++---------------- opm/core/utility/writeVtkData.hpp | 2 +- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/examples/spu_2p.cpp b/examples/spu_2p.cpp index 9bc67bfa..7ba2c110 100644 --- a/examples/spu_2p.cpp +++ b/examples/spu_2p.cpp @@ -159,11 +159,10 @@ private: -template -void outputState(const UnstructuredGrid* grid, - const State& state, - const int step, - const std::string& output_dir) +void outputState(const UnstructuredGrid& grid, + const ReservoirState& state, + const int step, + const std::string& output_dir) { // Write data in VTK format. std::ostringstream vtkfilename; @@ -176,7 +175,7 @@ void outputState(const UnstructuredGrid* grid, dm["saturation"] = &state.saturation(); dm["pressure"] = &state.pressure(); std::vector cell_velocity; - Opm::estimateCellVelocity(*grid, state.faceflux(), cell_velocity); + Opm::estimateCellVelocity(grid, state.faceflux(), cell_velocity); dm["velocity"] = &cell_velocity; Opm::writeVtkData(grid, dm, vtkfile); @@ -592,7 +591,7 @@ main(int argc, char** argv) << "\n" << std::endl; if (output) { - outputState(grid->c_grid(), state, pstep, output_dir); + outputState(*grid->c_grid(), state, pstep, output_dir); } // Solve pressure. @@ -661,7 +660,7 @@ main(int argc, char** argv) << "\n Transport time: " << ttime << std::endl; if (output) { - outputState(grid->c_grid(), state, num_psteps, output_dir); + outputState(*grid->c_grid(), state, num_psteps, output_dir); } destroy_transport_source(tsrc); diff --git a/opm/core/utility/writeVtkData.cpp b/opm/core/utility/writeVtkData.cpp index b1eebe2c..8c337073 100644 --- a/opm/core/utility/writeVtkData.cpp +++ b/opm/core/utility/writeVtkData.cpp @@ -137,11 +137,11 @@ namespace Opm int Tag::indent_ = 0; - void writeVtkData(const UnstructuredGrid* grid, + void writeVtkData(const UnstructuredGrid& grid, const DataMap& data, std::ostream& os) { - if (grid->dimensions != 3) { + if (grid.dimensions != 3) { THROW("Vtk output for 3d grids only"); } os.precision(12); @@ -150,8 +150,8 @@ namespace Opm pm["type"] = "UnstructuredGrid"; Tag vtkfiletag("VTKFile", pm, os); Tag ugtag("UnstructuredGrid", os); - int num_pts = grid->number_of_nodes; - int num_cells = grid->number_of_cells; + int num_pts = grid.number_of_nodes; + int num_cells = grid.number_of_cells; pm.clear(); pm["NumberOfPoints"] = boost::lexical_cast(num_pts); pm["NumberOfCells"] = boost::lexical_cast(num_cells); @@ -166,9 +166,9 @@ namespace Opm Tag datag("DataArray", pm, os); for (int i = 0; i < num_pts; ++i) { Tag::indent(os); - os << grid->node_coordinates[3*i + 0] << ' ' - << grid->node_coordinates[3*i + 1] << ' ' - << grid->node_coordinates[3*i + 2] << '\n'; + os << grid.node_coordinates[3*i + 0] << ' ' + << grid.node_coordinates[3*i + 1] << ' ' + << grid.node_coordinates[3*i + 2] << '\n'; } } { @@ -185,10 +185,10 @@ namespace Opm int hf = 0; for (int c = 0; c < num_cells; ++c) { std::set cell_pts; - for (; hf < grid->cell_facepos[c+1]; ++hf) { - int f = grid->cell_faces[hf]; - const int* fnbeg = grid->face_nodes + grid->face_nodepos[f]; - const int* fnend = grid->face_nodes + grid->face_nodepos[f+1]; + for (; hf < grid.cell_facepos[c+1]; ++hf) { + int f = grid.cell_faces[hf]; + const int* fnbeg = grid.face_nodes + grid.face_nodepos[f]; + const int* fnend = grid.face_nodes + grid.face_nodepos[f+1]; cell_pts.insert(fnbeg, fnend); } cell_numpts.push_back(cell_pts.size()); @@ -220,21 +220,21 @@ namespace Opm { pm["Name"] = "faces"; Tag t("DataArray", pm, os); - const int* fp = grid->cell_facepos; + const int* fp = grid.cell_facepos; int offset = 0; for (int c = 0; c < num_cells; ++c) { Tag::indent(os); os << fp[c+1] - fp[c] << '\n'; ++offset; for (int hf = fp[c]; hf < fp[c+1]; ++hf) { - int f = grid->cell_faces[hf]; - const int* np = grid->face_nodepos; + int f = grid.cell_faces[hf]; + const int* np = grid.face_nodepos; int f_num_pts = np[f+1] - np[f]; Tag::indent(os); os << f_num_pts << ' '; ++offset; - std::copy(grid->face_nodes + np[f], - grid->face_nodes + np[f+1], + std::copy(grid.face_nodes + np[f], + grid.face_nodes + np[f+1], std::ostream_iterator(os, " ")); os << '\n'; offset += f_num_pts; @@ -290,7 +290,7 @@ namespace Opm for (DataMap::const_iterator dit = data.begin(); dit != data.end(); ++dit) { pm["Name"] = dit->first; const std::vector& field = *(dit->second); - const int num_comps = field.size()/grid->number_of_cells; + const int num_comps = field.size()/grid.number_of_cells; pm["NumberOfComponents"] = boost::lexical_cast(num_comps); Tag ptag("DataArray", pm, os); const int num_per_line = num_comps == 1 ? 5 : num_comps; diff --git a/opm/core/utility/writeVtkData.hpp b/opm/core/utility/writeVtkData.hpp index 7760f631..200b2b26 100644 --- a/opm/core/utility/writeVtkData.hpp +++ b/opm/core/utility/writeVtkData.hpp @@ -42,7 +42,7 @@ namespace Opm std::ostream& os); /// Vtk output for general grids. - void writeVtkData(const UnstructuredGrid* grid, + void writeVtkData(const UnstructuredGrid& grid, const DataMap& data, std::ostream& os); } // namespace Opm