Example codes
and tutorials
The (Not-so) Quick Guide
List of tutorials/demo codes
Single-Physics Problems
Poisson
Adaptivity illustrated for Poisson
Advection-Diffusion
Unsteady heat equation
Linear wave equation
The Young-Laplace equation
Navier-Stokes
Free-surface Navier-Stokes
Axisymmetric Navier-Stokes
Solid mechanics
Beam structures
Shell structures
Multi-physics Problems
Fluid-structure interaction
Boussinesq convection
Steady thermoelasticity
Methods-based example codes and tutorials
Mesh generation
Linear solvers and preconditioners
Visualisation of the results
Parallel processing
How to write a new element
How to write a new refineable element
Default nonlinear solvers -- the sequence of action functions
...
Documentation
FE theory and top-down discussion of the data structure
The (Not-so) Quick Guide
Comprehensive bottom-up discussion of the data structure
List of available structured and unstructured meshes
Linear solvers and preconditioners
Visualisation of the results
Parallel processing
Coding conventions and C++ style
Creating documentation
Optimisation - robustness vs. "raw speed"
Linear vs. nonlinear problems
Storing shape functions
Changing the default "full" integration scheme
Disabling the ALE formulation of unsteady equations
C vs. C++ output
Different sparse assembly techniques and the STL memory pool
Publications
Publications
Talks
Journal publications
Theses
Picture show
Download
Copyright
Download/installation instructions
Download page
FAQ & Contact
FAQ
Change log
Bugs and other known problems
Completeness of the library & our "To-Do List"
Contact the developers
Get involved

 


Beta release!

Please note that the library has not been "officially" released. While we continue to work on the documentation, these web pages are likely to contain broken links and documents in draft form. Please send an email to

oomph-lib AT maths DOT man DOT ac DOT uk

if you wish to be informed of the library's "official" release.

Vector.h

Go to the documentation of this file.
00001 //LIC// ====================================================================
00002 //LIC// This file forms part of oomph-lib, the object-oriented, 
00003 //LIC// multi-physics finite-element library, available 
00004 //LIC// at http://www.oomph-lib.org.
00005 //LIC// 
00006 //LIC//           Version 0.90. August 3, 2009.
00007 //LIC// 
00008 //LIC// Copyright (C) 2006-2009 Matthias Heil and Andrew Hazel
00009 //LIC// 
00010 //LIC// This library is free software; you can redistribute it and/or
00011 //LIC// modify it under the terms of the GNU Lesser General Public
00012 //LIC// License as published by the Free Software Foundation; either
00013 //LIC// version 2.1 of the License, or (at your option) any later version.
00014 //LIC// 
00015 //LIC// This library is distributed in the hope that it will be useful,
00016 //LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 //LIC// Lesser General Public License for more details.
00019 //LIC// 
00020 //LIC// You should have received a copy of the GNU Lesser General Public
00021 //LIC// License along with this library; if not, write to the Free Software
00022 //LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00023 //LIC// 02110-1301  USA.
00024 //LIC// 
00025 //LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
00026 //LIC// 
00027 //LIC//====================================================================
00028 //A header file that is used to define the oomph-lib Vector class
00029 
00030 //Include guards to prevent multiple inclusions of the header
00031 #ifndef OOMPH_VECTOR_HEADER
00032 #define OOMPH_VECTOR_HEADER
00033 
00034 // Config header generated by autoconfig
00035 #ifdef HAVE_CONFIG_H
00036   #include <oomph-lib-config.h>
00037 #endif
00038 
00039 //Standard library includes
00040 #include<vector>
00041 #include<sstream>
00042 
00043 //Oomph-libe error handler
00044 #include "oomph_definitions.h"
00045 
00046 namespace oomph
00047 {
00048 
00049 
00050 //===========================================================================
00051 /// A slight extension to the standard template vector class so that
00052 /// we can include "graceful" array range checks if the RANGE_CHECKING
00053 /// flag is set. The generalisation to general allocators is NOT handled here, 
00054 /// mainly because we never use it, but also because the intel and gnu 
00055 /// compilers have different names for the internal classes, which makes 
00056 /// writing code that works for both a pain!
00057 //===========================================================================
00058 template<class _Tp>
00059 class Vector: public std::vector<_Tp>
00060 {
00061 
00062 public:
00063  
00064  /// Typedef to make the constructors look a bit cleaner
00065  typedef _Tp                                            value_type;
00066 
00067  /// Typedef to make the constructors look a bit cleaner
00068  typedef value_type&                                    reference;
00069 
00070  /// Typedef to make the constructors look a bit cleaner
00071  typedef const value_type&                              const_reference;
00072 
00073  /// Typedef to make the constructors look a bit cleaner
00074  typedef size_t                                         size_type;
00075 
00076 //Only include this code, if we are range checking
00077 #ifdef RANGE_CHECKING
00078 private:
00079 
00080  //Function to return a reference to a vector entry, 
00081  //including array range checking 
00082  reference error_checked_access(size_type __n)
00083   {
00084    //If there is an out of range error, die, but issue a warning message
00085    if (__n>=this->size())
00086     {
00087      //Construct an error message, as a string stream
00088      std::ostringstream error_message;
00089      error_message << "Range Error: " << __n 
00090                    << " is not in the range (0," 
00091                    << this->size()-1 << ")"; 
00092  
00093      //Throw an Oomph-lib error
00094      throw OomphLibError(error_message.str(),"Vector::error_checked_access",
00095                          OOMPH_EXCEPTION_LOCATION);
00096      
00097      //This is a dummy return to keep the Intel compiler happy
00098      return std::vector<_Tp>::operator[](__n);
00099     }
00100    else
00101     {
00102      return std::vector<_Tp>::operator[](__n);
00103     }
00104   }
00105 
00106  //Function to return a constant reference to a vector entry
00107  //including error range checking
00108   const_reference error_checked_access(size_type __n) const
00109   {
00110    //If there is an out of range error, die, but issue a warning message
00111    if (__n>=this->size())
00112     {
00113      //Construct an error message, as a string stream
00114      std::ostringstream error_message;
00115      error_message << "Range Error: " << __n 
00116                    << " is not in the range (0," 
00117                    << this->size()-1 << ")";
00118      
00119      //Throw an Oomph-lib error
00120      throw OomphLibError(error_message.str(),"Vector::error_checked_access",
00121                          OOMPH_EXCEPTION_LOCATION);
00122 
00123      //This is a dummy return to keep the Intel compiler happy
00124      return std::vector<_Tp>::operator[](__n);
00125     }
00126    else
00127     {
00128      return std::vector<_Tp>::operator[](__n);
00129     }
00130   }
00131 
00132 #endif
00133 
00134 public:
00135  
00136  //Standard Constuctors (some have been omitted from the stl classes)
00137 
00138  /// Construct an empty vector 
00139  Vector() : std::vector<_Tp>() {}
00140  
00141  /// \short A constructor that creates a vector of size __n.
00142  /// Note the use of explicit for "strong" type checking
00143  explicit Vector(size_type __n) : std::vector<_Tp>(__n) { }
00144 
00145  /// \short A constructor that creates a vector of size __n and 
00146  /// initialises every entry to __value
00147  Vector(size_type __n, const _Tp& __value) : std::vector<_Tp>(__n,__value) {}
00148 
00149  /// Copy constructor
00150  Vector(const Vector<_Tp>& __x) : std::vector<_Tp>(__x) {}
00151 
00152  //No explicit destructor is required because the base class destructor handles
00153  //all memory issues
00154  //~Vector() {}
00155 
00156  /// Iterate over all values and set to the desired value
00157  void initialise(const _Tp& __value)
00158   {
00159    for(typename std::vector<_Tp>::iterator it = std::vector<_Tp>::begin();
00160        it != std::vector<_Tp>::end(); it++)
00161     {
00162      *it = __value;
00163     }
00164   }
00165 
00166 #ifdef RANGE_CHECKING
00167  /// Overload the bracket access operator to include array-range checking
00168  /// if the RANGE_CHECKING flag is set
00169  reference operator[](size_type __n) 
00170   {
00171    return error_checked_access(__n);
00172   }
00173  
00174  /// Overloaded, range-checking, bracket access operator (const version)
00175  const_reference operator[](size_type __n) const 
00176   {
00177    return error_checked_access(__n);
00178   }
00179 #endif
00180 
00181 };
00182 
00183 //==================================================================
00184 ///\short A Vector of bools cannot be created because the is no
00185 ///compiler-independent  implementation of the bit manipulators.
00186 ///Making all the constructors private should lead to compile-time
00187 ///errors. 
00188 //=================================================================
00189 template<>
00190 class Vector<bool>: private std::vector<bool>
00191 {
00192 
00193 public:
00194  
00195  /// Typedef to make the constructors look a bit cleaner
00196  typedef bool                                           value_type;
00197 
00198  /// Typedef to make the constructors look a bit cleaner
00199  typedef value_type&                                    reference;
00200 
00201  /// Typedef to make the constructors look a bit cleaner
00202  typedef const value_type&                              const_reference;
00203 
00204  /// Typedef to make the constructors look a bit cleaner
00205  typedef size_t                                         size_type;
00206 
00207 
00208  /// \short Dummy constructor to avoid compiler from warning about
00209  /// only-private constructors
00210  Vector(const double& dont_call_this_constructor) 
00211   {
00212    //Throw an Oomph-lib error
00213    throw OomphLibError("Please use vector<bool> instead of Vector<bool>",
00214                        "Vector:: dummy constructor",
00215                        OOMPH_EXCEPTION_LOCATION);
00216   }
00217  
00218  private:
00219  
00220  //Standard Constuctors (some have been omitted from the stl classes)
00221 
00222  /// Construct an empty vector 
00223  Vector() : std::vector<bool>() {}
00224  
00225  /// \short A constructor that creates a vector of size __n.
00226  /// Note the use of explicit for "strong" type checking
00227  explicit Vector(size_type __n) : std::vector<bool>(__n) { }
00228 
00229  /// \short A constructor that creates a vector of size __n and 
00230  /// initialises every entry to __value
00231  Vector(size_type __n, const bool& __value) : std::vector<bool>(__n,__value) {}
00232 
00233  /// Copy constructor
00234  Vector(const Vector<bool>& __x) : std::vector<bool>(__x) {}
00235 
00236  /// Iterate over all values and set to the desired value
00237  void initialise(const bool& __value)
00238   {
00239    for(std::vector<bool>::iterator it = std::vector<bool>::begin();
00240        it != std::vector<bool>::end(); it++)
00241     {
00242      *it = __value;
00243     }
00244   }
00245 
00246 };
00247 
00248 }
00249 
00250 #endif

Generated on Mon Aug 10 11:23:52 2009 by  doxygen 1.4.7