|
Rythmos - Transient Integration for Differential Equations
Version of the Day
|
00001 //@HEADER 00002 // *********************************************************************** 00003 // 00004 // Rythmos Package 00005 // Copyright (2006) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00023 // USA 00024 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 //@HEADER 00028 00029 #ifndef Rythmos_INTERPOLATOR_BASE_HELPERS_H 00030 #define Rythmos_INTERPOLATOR_BASE_HELPERS_H 00031 00032 #include "Rythmos_InterpolatorBase.hpp" 00033 00034 namespace Rythmos { 00035 00036 00038 template<class Scalar> 00039 void interpolate( 00040 InterpolatorBase<Scalar>& interp, 00041 const RCP<const typename DataStore<Scalar>::DataStoreVector_t> & nodes, 00042 const Array<Scalar> &t_values, 00043 typename DataStore<Scalar>::DataStoreVector_t *data_out 00044 ) 00045 { 00046 interp.setNodes(nodes); 00047 interp.interpolate(t_values,data_out); 00048 } 00049 00050 00052 template<class Scalar> 00053 void assertBaseInterpolatePreconditions( 00054 const typename DataStore<Scalar>::DataStoreVector_t &data_in, 00055 const Array<Scalar> &t_values, 00056 typename DataStore<Scalar>::DataStoreVector_t *data_out 00057 ) 00058 { 00059 TEUCHOS_TEST_FOR_EXCEPTION( 00060 data_in.size()==0, std::logic_error, 00061 "Error, data_in.size() == 0!\n" 00062 ); 00063 Array<Scalar> time_vec; 00064 dataStoreVectorToVector<Scalar>(data_in, &time_vec, 0, 0, 0); 00065 assertTimePointsAreSorted<Scalar>(time_vec); 00066 assertTimePointsAreSorted<Scalar>(t_values); 00067 if (data_in.size() == 1) { 00068 TEUCHOS_TEST_FOR_EXCEPTION( 00069 t_values.size()>1, std::logic_error, 00070 "Error, data_in.size() == 1, but t_values.size() > 1!\n" 00071 ); 00072 TEUCHOS_TEST_FOR_EXCEPTION( 00073 compareTimeValues(t_values[0],data_in[0].time)!=0, std::logic_error, 00074 "Error, data_in.size) == 1, but t_values[0] = " << 00075 t_values[0] << " != " << data_in[0].time << " = data_in[0].time!\n" 00076 ); 00077 } 00078 TimeRange<Scalar> range(data_in.front().time,data_in.back().time); 00079 for (int i=0; i<Teuchos::as<int>(t_values.size()) ; ++i) { 00080 TEUCHOS_TEST_FOR_EXCEPTION( 00081 !range.isInRange(t_values[i]), std::out_of_range, 00082 "Error, t_values[" << i << "] = " << t_values[i] << 00083 " is not in range of data_in = " << range << "!\n" 00084 ); 00085 } 00086 TEUCHOS_TEST_FOR_EXCEPTION( 00087 data_out == 0, std::logic_error, 00088 "Error, data_out = NULL!\n" 00089 ); 00090 } 00091 00092 00093 template<class Scalar> 00094 void assertNodesUnChanged( 00095 const typename DataStore<Scalar>::DataStoreVector_t & nodes, 00096 const typename DataStore<Scalar>::DataStoreVector_t & nodes_copy 00097 ) 00098 { 00099 typedef Teuchos::ScalarTraits<Scalar> ST; 00100 int N = nodes.size(); 00101 int Ncopy = nodes_copy.size(); 00102 TEUCHOS_TEST_FOR_EXCEPTION( N != Ncopy, std::logic_error, 00103 "Error! The number of nodes passed in through setNodes has changed!" 00104 ); 00105 if (N > 0) { 00106 RCP<Thyra::VectorBase<Scalar> > xdiff = nodes[0].x->clone_v(); 00107 RCP<Thyra::VectorBase<Scalar> > xdotdiff = xdiff->clone_v(); 00108 V_S(outArg(*xdiff),ST::one()); 00109 V_S(outArg(*xdotdiff),ST::one()); 00110 for (int i=0 ; i<N ; ++i) { 00111 V_StVpStV(outArg(*xdiff),ST::one(),*nodes[i].x,-ST::one(),*nodes_copy[i].x); 00112 if ((!Teuchos::is_null(nodes[i].xdot)) && (!Teuchos::is_null(nodes_copy[i].xdot))) { 00113 V_StVpStV(outArg(*xdotdiff),ST::one(),*nodes[i].xdot,-ST::one(),*nodes_copy[i].xdot); 00114 } else if (Teuchos::is_null(nodes[i].xdot) && Teuchos::is_null(nodes_copy[i].xdot)) { 00115 V_S(outArg(*xdotdiff),ST::zero()); 00116 } 00117 Scalar xdiffnorm = norm_inf(*xdiff); 00118 Scalar xdotdiffnorm = norm_inf(*xdotdiff); 00119 TEUCHOS_TEST_FOR_EXCEPTION( 00120 ( ( nodes[i].time != nodes_copy[i].time ) || 00121 ( xdiffnorm != ST::zero() ) || 00122 ( xdotdiffnorm != ST::zero() ) || 00123 ( nodes[i].accuracy != nodes_copy[i].accuracy ) ), 00124 std::logic_error, 00125 "Error! The data in the nodes passed through setNodes has changed!" 00126 ); 00127 } 00128 } 00129 } 00130 00131 00132 } // namespace Rythmos 00133 00134 00135 #endif // Rythmos_INTERPOLATOR_BASE_HELPERS_H
1.7.6.1