From af6303a67e32c2e6ade3dc5a24a05a06280eb4fe Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 27 Feb 2012 18:14:08 +0000 Subject: [PATCH] Removed class ArrayViewer (use Array2D instead) --- include/cantera/base/Array.h | 16 +++ include/cantera/numerics/ArrayViewer.h | 173 ------------------------- samples/cxx/bvp/stagnation.cpp | 3 +- src/numerics/Makefile.am | 2 +- src/oneD/StFlow.cpp | 5 +- 5 files changed, 20 insertions(+), 179 deletions(-) delete mode 100644 include/cantera/numerics/ArrayViewer.h diff --git a/include/cantera/base/Array.h b/include/cantera/base/Array.h index 35496e858..e6435342f 100644 --- a/include/cantera/base/Array.h +++ b/include/cantera/base/Array.h @@ -74,6 +74,22 @@ public: std::fill(m_data.begin(), m_data.end(), v); } + //! Constructor. + /*! + * Create an \c m by \c n array, initialized with the contents + * of the array \c values. + * + * @param m Number of rows + * @param n Number of columns + * @param values Initial values of the array. Must be of length m*n, + * and stored in column-major order. + */ + Array2D(const size_t m, const size_t n, const doublereal* values) + : m_data(0), m_nrows(m), m_ncols(n) { + m_data.resize(n*m); + std::copy(values, values + m_nrows*m_ncols, m_data.begin()); + } + //! Copy constructor /*! * @param y Array2D to make the copy from diff --git a/include/cantera/numerics/ArrayViewer.h b/include/cantera/numerics/ArrayViewer.h deleted file mode 100644 index 0ab91a710..000000000 --- a/include/cantera/numerics/ArrayViewer.h +++ /dev/null @@ -1,173 +0,0 @@ -/** - * @file ArrayViewer.h - * - * Header file for class ArrayViewer - */ -// Copyright 2001 California Institute of Technology - - -#ifndef CT_ARRAYVIEWER_H -#define CT_ARRAYVIEWER_H - -#include "cantera/base/ct_defs.h" -#include "cantera/base/ctexceptions.h" -#include "cantera/base/stringUtils.h" -#include "cantera/base/utilities.h" - -namespace Cantera -{ - - -/** - * An interface for 2D arrays stored in column-major - * (Fortran-compatible) form. This class is designed for - * situations when you have a Fortran-compatible 2D array that - * you want to be able to easily get/set individual elements or - * entire rows or columns. Instances of ArrayViewer store only a - * pointer to the first element in the array; no copy is made of - * the array. @todo This class should probably be renamed, since - * it not only views, but also can modify, array elements. This - * class is hardly used; candidate for removal. - */ -class ArrayViewer -{ - -public: - - typedef doublereal* iterator; - typedef const doublereal* const_iterator; - - - /** - * Default constructor. Create an empty array viewer. - */ - ArrayViewer() : m_nrows(0), m_ncols(0) { - data = 0; - } - - - /** - * Constructor. Create an \c m by \c n array viewer for array v. - */ - ArrayViewer(size_t m, size_t n, doublereal* v) - : m_nrows(m), m_ncols(n) { - data = v; - } - - /// resize the array viewer - void resize(size_t n, size_t m) { - m_nrows = n; - m_ncols = m; - } - - /// set the nth row to array rw - void setRow(size_t n, doublereal* rw) { - for (size_t j = 0; j < m_ncols; j++) { - data[m_nrows*j + n] = rw[j]; - } - } - - /// get the nth row - void getRow(size_t n, doublereal* rw) { - for (size_t j = 0; j < m_ncols; j++) { - rw[j] = data[m_nrows*j + n]; - } - } - - /// set the values in column m to those in array col - void setColumn(size_t m, doublereal* col) { - for (size_t i = 0; i < m_nrows; i++) { - data[m_nrows*m + i] = col[i]; - } - } - - /// get the values in column m - void getColumn(size_t m, doublereal* col) { - for (size_t i = 0; i < m_nrows; i++) { - col[i] = data[m_nrows*m + i]; - } - } - - /// Destructor. Does nothing. - virtual ~ArrayViewer() {} - - doublereal& operator()(size_t i, size_t j) { - return value(i,j); - } - doublereal operator()(size_t i, size_t j) const { - return value(i,j); - } - - /// Return a reference to the (i,j) array element. - doublereal& value(size_t i, size_t j) { - return data[m_nrows*j + i]; - } - - /// Return the value of the (i,j) array element. - doublereal value(size_t i, size_t j) const { - return data[m_nrows*j + i]; - } - - /// Number of rows - size_t nRows() const { - return m_nrows; - } - - /// Number of columns - size_t nColumns() const { - return m_ncols; - } - - iterator begin() { - return data; - } - iterator end() { - return data + m_nrows*m_ncols; - } - const_iterator begin() const { - return data; - } - const_iterator end() const { - return data + m_nrows*m_ncols; - } - - doublereal* data; - -protected: - - size_t m_nrows, m_ncols; -}; - -/// output the array -inline std::ostream& operator<<(std::ostream& s, const ArrayViewer& m) -{ - size_t nr = m.nRows(); - size_t nc = m.nColumns(); - size_t i,j; - for (i = 0; i < nr; i++) { - for (j = 0; j < nc; j++) { - s << m(i,j) << ", "; - } - s << std::endl; - } - return s; -} - -/// Multiply the array by a constant. -inline void operator*=(ArrayViewer& m, doublereal a) -{ - scale(m.begin(), m.end(), m.begin(), a); -} - -/// Increment the entire array by a constant. -inline void operator+=(ArrayViewer& x, const ArrayViewer& y) -{ - sum_each(x.begin(), x.end(), y.begin()); -} - -} - -#endif - - - diff --git a/samples/cxx/bvp/stagnation.cpp b/samples/cxx/bvp/stagnation.cpp index cf321dee1..8eeee51e8 100644 --- a/samples/cxx/bvp/stagnation.cpp +++ b/samples/cxx/bvp/stagnation.cpp @@ -8,7 +8,6 @@ #include #include "AxiStagnBVP.h" -#include "cantera/numerics/ArrayViewer.h" #include "cantera/base/ctml.h" #include "cantera/oneD/MultiJac.h" @@ -1121,7 +1120,7 @@ void AxiStagnBVP::save(XML_Node& o, doublereal* sol) { int k; - ArrayViewer soln(m_nv, m_points, sol + loc()); + Array2D soln(m_nv, m_points, sol + loc()); XML_Node& flow = (XML_Node&)o.addChild("domain"); flow.addAttribute("type",flowType()); diff --git a/src/numerics/Makefile.am b/src/numerics/Makefile.am index abdb47f98..0fc1532a8 100644 --- a/src/numerics/Makefile.am +++ b/src/numerics/Makefile.am @@ -1,4 +1,4 @@ -h_sources = ArrayViewer.h DenseMatrix.h funcs.h ctlapack.h Func1.h \ +h_sources = DenseMatrix.h funcs.h ctlapack.h Func1.h \ FuncEval.h polyfit.h BandMatrix.h Integrator.h \ DAE_Solver.h ResidEval.h sort.h SquareMatrix.h \ ResidJacEval.h NonlinearSolver.h diff --git a/src/oneD/StFlow.cpp b/src/oneD/StFlow.cpp index 710259c7e..686825bb8 100644 --- a/src/oneD/StFlow.cpp +++ b/src/oneD/StFlow.cpp @@ -7,7 +7,6 @@ #include #include "cantera/oneD/StFlow.h" -#include "cantera/numerics/ArrayViewer.h" #include "cantera/base/ctml.h" #include "cantera/oneD/MultiJac.h" @@ -1178,7 +1177,7 @@ void StFlow::save(XML_Node& o, const doublereal* const sol) { size_t k; - ArrayViewer soln(m_nv, m_points, const_cast(sol) + loc()); + Array2D soln(m_nv, m_points, sol + loc()); XML_Node& flow = (XML_Node&)o.addChild("domain"); flow.addAttribute("type",flowType()); @@ -1193,7 +1192,7 @@ void StFlow::save(XML_Node& o, const doublereal* const sol) addFloat(flow, "pressure", m_press, "Pa", "pressure"); addFloatArray(gv,"z",m_z.size(),DATA_PTR(m_z), "m","length"); - vector_fp x(static_cast(soln.nColumns())); + vector_fp x(soln.nColumns()); soln.getRow(0,DATA_PTR(x)); addFloatArray(gv,"u",x.size(),DATA_PTR(x),"m/s","velocity");