00001 /* @HEADER@ */ 00002 // ************************************************************************ 00003 // 00004 // Sundance 00005 // Copyright 2011 Sandia Corporation 00006 // 00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00008 // the U.S. Government retains certain rights in this software. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu) 00038 // 00039 00040 /* @HEADER@ */ 00041 00042 00043 #ifndef PDEOPT_POINTDATA_H 00044 #define PDEOPT_POINTDATA_H 00045 00046 #include "Sundance.hpp" 00047 #include <fstream> 00048 00049 00050 namespace Sundance 00051 { 00052 /** 00053 * PointData is a utility class that helps create the Sundance objects required 00054 * to include point measurements in an inversion problem. 00055 */ 00056 class PointData 00057 { 00058 public: 00059 /** Create a point data object given a set of sensor locations and 00060 * corresponding sensor readings */ 00061 PointData(const Array<Point>& locations, const Array<double>& values, 00062 const double& pointComparisonTolerance); 00063 00064 /** Create a point data object given a set of sensor locations and 00065 * a field to probe at those points */ 00066 PointData(const Array<Point>& locations, const Expr& field, 00067 const double& pointComparisonTolerance); 00068 00069 /** Read point data from an XML file */ 00070 PointData(const XMLObject& xml, const Mesh& mesh); 00071 00072 00073 00074 /** Return an expr that, when called at one of the measurement locations, 00075 * returns the value of the measurement there. */ 00076 Expr sensorValues() const {return sensorVals_;} 00077 00078 /** Return a cell filter that identifies the sensor points */ 00079 CellFilter sensorLocations() const {return sensorLocations_;} 00080 00081 00082 /** Adjust a set of points to the nearest vertices on a mesh */ 00083 static Array<Point> snapToMesh(const Mesh& mesh, const Array<Point>& locations) ; 00084 00085 /** Find the vertex nearest to a specified point */ 00086 static Point nearestMeshPoint(const Mesh& mesh, const Point& x); 00087 00088 00089 private: 00090 void init(const Array<Point>& locations, const Array<double>& values, 00091 const double& pointComparisonTolerance); 00092 00093 Expr sensorVals_; 00094 CellFilter sensorLocations_; 00095 }; 00096 00097 00098 00099 /** 00100 * Do lexigraphic comparison on points, including a bit of sloppiness 00101 */ 00102 class SloppyPointComparitor : public std::binary_function<Point, Point, bool> 00103 { 00104 public: 00105 SloppyPointComparitor(const double& tol) : tol_(tol) {;} 00106 00107 bool operator()(const Point& p1, const Point& p2) const ; 00108 private: 00109 double tol_; 00110 }; 00111 00112 00113 /** 00114 * This is a functor that allows the sensor readings to be obtained through 00115 * a Sundance user-defined expression. 00116 */ 00117 class PointDataExprFunctor : public PointwiseUserDefFunctor0 00118 { 00119 public: 00120 /** */ 00121 PointDataExprFunctor(const Array<Point>& locations, 00122 const Array<double>& values, 00123 const double& pointComparisonTolerance); 00124 00125 /** */ 00126 virtual void eval0(const double* in, double* out) const ; 00127 00128 /** */ 00129 int numArgs() const {return dim_;} 00130 00131 private: 00132 std::map<Point, double, SloppyPointComparitor> pointToValueMap_; 00133 int dim_; 00134 }; 00135 00136 /** 00137 * This is a functor that allows a positional cell predicate to test 00138 * against the locations of the sensors. 00139 */ 00140 class PointDataCellPredicateFunctor : public CellPredicateFunctorBase, 00141 public Playa::Handleable<CellPredicateFunctorBase> 00142 { 00143 public: 00144 /** */ 00145 PointDataCellPredicateFunctor(const Array<Point>& locations, 00146 const double& pointComparisonTolerance); 00147 00148 /** */ 00149 virtual bool operator()(const Point& x) const ; 00150 00151 GET_RCP(CellPredicateFunctorBase); 00152 00153 private: 00154 std::set<Point, SloppyPointComparitor> pointSet_; 00155 }; 00156 00157 00158 } 00159 00160 #endif