vtf-logo

shells/utilities/MinMaxSensor.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00004 // 
00005 //                                   Fehmi Cirak
00006 //                        California Institute of Technology
00007 //                           (C) 2004 All Rights Reserved
00008 //
00009 // <LicenseText>
00010 //
00011 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00012 //
00013 
00014 #ifndef MINMAXSENSOR_H
00015 #define MINMAXSENSOR_H
00016 
00017 #include "../driverCC/MShell.h"
00018 #include "../driverCC/SVertexFunctors.h"
00019 
00020 #include <functional>
00021 #include <iterator>
00022 #include <ostream>
00023 #include <cassert>
00024 
00025 
00026 namespace shells {
00027     class MShell;
00028 }
00029  
00030 namespace utilities {
00031     template<typename EXTR>
00032     class MinMaxSensor;
00033 }
00034 
00035 
00036 namespace utilities {
00037 
00038 template<typename EXTR>
00039 class MinMaxSensor {
00040 public:
00041     MinMaxSensor(std::ostream& os, shells::MShell * const mShell): 
00042         _os(os), _mShell(mShell)
00043         {
00044             _os << std::scientific;
00045         }
00046     ~MinMaxSensor(){_os.flush();}
00047     
00048     void printData(double timeStamp);
00049 
00050 private:
00051     MinMaxSensor(const MinMaxSensor &);
00052     const MinMaxSensor & operator=(const MinMaxSensor &);
00053     
00054 private:
00055     typedef std::vector<typename EXTR::DataType>     _DataCont;
00056 
00057     _DataCont                      _variable;
00058     std::ostream&                  _os;
00059     shells::MShell     * const     _mShell;
00060 };
00061 
00062 
00063 // implementation    
00064 template<typename EXTR>
00065 void MinMaxSensor<EXTR> ::printData(double timeStamp) 
00066 {
00067     const size_t numVar = EXTR::numVar;
00068     size_t numVertices = _mShell->numberOfVertices();
00069     
00070     _variable.clear();
00071     _variable.reserve(numVertices*numVar);
00072     shells::SVertexCollector<std::back_insert_iterator<_DataCont>, EXTR> getData;
00073     _mShell->iterateOverVertices(std::bind2nd(getData, 
00074                                               std::back_inserter(_variable)));  
00075 
00076     assert((numVertices*numVar)==_variable.size());
00077     
00078     // find the minum and maximum
00079     typename EXTR::DataType min[numVar];
00080     typename EXTR::DataType max[numVar];
00081     
00082     for (size_t j=0; j<numVar; ++j) {
00083         min[j] = _variable[j];
00084         max[j] = min[j];
00085     }
00086     
00087     for (size_t i=0; i<numVertices; ++i ) {
00088         for (size_t j=0; j<numVar; ++j) {
00089             min[j] = std::min(min[j],_variable[numVar*i+j]);
00090                 max[j] = std::max(max[j],_variable[numVar*i+j]);
00091         }
00092     }
00093         
00094     _os << timeStamp << " ";
00095     for (size_t i=0; i<numVar; ++i) {
00096         _os << min[i] << " " << max[i] << " ";
00097     }
00098     _os << std::endl;
00099 }
00100 
00101 } // namespace utilities
00102 
00103 #endif

Generated on Fri Aug 24 13:00:24 2007 for SFC Thin-Shell Finite Element Solver by  doxygen 1.4.7