|
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_EXTRACT_STATE_AND_SENS_HPP 00030 #define RYTHMOS_EXTRACT_STATE_AND_SENS_HPP 00031 00032 00033 #include "Rythmos_Types.hpp" 00034 #include "Thyra_DefaultMultiVectorProductVector.hpp" 00035 #include "Thyra_ProductVectorBase.hpp" 00036 00037 00038 namespace Rythmos { 00039 00040 00058 template<class Scalar> 00059 void extractStateAndSens( 00060 const RCP<const Thyra::VectorBase<Scalar> > &x_bar, 00061 const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot, 00062 RCP<const Thyra::VectorBase<Scalar> > *x, 00063 RCP<const Thyra::MultiVectorBase<Scalar> > *S, 00064 RCP<const Thyra::VectorBase<Scalar> > *x_dot, 00065 RCP<const Thyra::MultiVectorBase<Scalar> > *S_dot 00066 ); 00067 00068 00071 template<class Scalar> 00072 void extractState( 00073 const RCP<const Thyra::VectorBase<Scalar> > &x_bar, 00074 const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot, 00075 RCP<const Thyra::VectorBase<Scalar> > *x, 00076 RCP<const Thyra::VectorBase<Scalar> > *x_dot 00077 ); 00078 00079 00082 template<class Scalar> 00083 void extractSens( 00084 const RCP<const Thyra::VectorBase<Scalar> > &x_bar, 00085 const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot, 00086 RCP<const Thyra::MultiVectorBase<Scalar> > *S, 00087 RCP<const Thyra::MultiVectorBase<Scalar> > *S_dot 00088 ); 00089 00090 00091 } // namespace Rythmos 00092 00093 00094 00095 // 00096 // Implementations 00097 // 00098 00099 namespace Rythmos { 00100 00101 namespace { 00102 00103 00104 template<class Scalar> 00105 void downcastStateAndSens( 00106 const RCP<const Thyra::VectorBase<Scalar> > &x_bar, 00107 const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot, 00108 RCP<const Thyra::ProductVectorBase<Scalar> > &x_bar_pv, 00109 RCP<const Thyra::ProductVectorBase<Scalar> > &x_bar_dot_pv 00110 ) 00111 { 00112 using Teuchos::rcp_dynamic_cast; 00113 00114 TEUCHOS_TEST_FOR_EXCEPT(is_null(x_bar)); 00115 x_bar_pv = Thyra::productVectorBase<Scalar>(x_bar); 00116 00117 TEUCHOS_TEST_FOR_EXCEPT(is_null(x_bar_dot)); 00118 x_bar_dot_pv = Thyra::productVectorBase<Scalar>(x_bar_dot); 00119 } 00120 00121 00122 template<class Scalar> 00123 void extractStateBlock( 00124 const RCP<const Thyra::ProductVectorBase<Scalar> > &x_bar_pv, 00125 const RCP<const Thyra::ProductVectorBase<Scalar> > &x_bar_dot_pv, 00126 RCP<const Thyra::VectorBase<Scalar> > *x, 00127 RCP<const Thyra::VectorBase<Scalar> > *x_dot 00128 ) 00129 { 00130 TEUCHOS_TEST_FOR_EXCEPT(0==x); 00131 *x = x_bar_pv->getVectorBlock(0); 00132 00133 TEUCHOS_TEST_FOR_EXCEPT(0==x_dot); 00134 *x_dot = x_bar_dot_pv->getVectorBlock(0); 00135 } 00136 00137 00138 template<class Scalar> 00139 void extractSensBlock( 00140 const RCP<const Thyra::ProductVectorBase<Scalar> > &x_bar_pv, 00141 const RCP<const Thyra::ProductVectorBase<Scalar> > &x_bar_dot_pv, 00142 RCP<const Thyra::MultiVectorBase<Scalar> > *S, 00143 RCP<const Thyra::MultiVectorBase<Scalar> > *S_dot) 00144 { 00145 using Teuchos::rcp_dynamic_cast; 00146 00147 TEUCHOS_TEST_FOR_EXCEPT(0==S); 00148 const RCP<const Thyra::DefaultMultiVectorProductVector<Scalar> > 00149 s_bar = rcp_dynamic_cast<const Thyra::DefaultMultiVectorProductVector<Scalar> >( 00150 x_bar_pv->getVectorBlock(1).assert_not_null(), true 00151 ); 00152 *S = s_bar->getMultiVector(); 00153 00154 TEUCHOS_TEST_FOR_EXCEPT(0==S_dot); 00155 const RCP<const Thyra::DefaultMultiVectorProductVector<Scalar> > 00156 s_bar_dot = rcp_dynamic_cast<const Thyra::DefaultMultiVectorProductVector<Scalar> >( 00157 x_bar_dot_pv->getVectorBlock(1).assert_not_null(), true 00158 ); 00159 *S_dot = s_bar_dot->getMultiVector(); 00160 } 00161 00162 00163 } // anonymous namespace 00164 00165 } // namespace Rythmos 00166 00167 00168 template<class Scalar> 00169 void Rythmos::extractStateAndSens( 00170 const RCP<const Thyra::VectorBase<Scalar> > &x_bar, 00171 const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot, 00172 RCP<const Thyra::VectorBase<Scalar> > *x, 00173 RCP<const Thyra::MultiVectorBase<Scalar> > *S, 00174 RCP<const Thyra::VectorBase<Scalar> > *x_dot, 00175 RCP<const Thyra::MultiVectorBase<Scalar> > *S_dot 00176 ) 00177 { 00178 RCP<const Thyra::ProductVectorBase<Scalar> > x_bar_pv, x_bar_dot_pv; 00179 downcastStateAndSens(x_bar, x_bar_dot, x_bar_pv, x_bar_dot_pv); 00180 00181 extractStateBlock(x_bar_pv, x_bar_dot_pv, x, x_dot); 00182 extractSensBlock(x_bar_pv, x_bar_dot_pv, S, S_dot); 00183 } 00184 00185 00186 template<class Scalar> 00187 void Rythmos::extractState( 00188 const RCP<const Thyra::VectorBase<Scalar> > &x_bar, 00189 const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot, 00190 RCP<const Thyra::VectorBase<Scalar> > *x, 00191 RCP<const Thyra::VectorBase<Scalar> > *x_dot 00192 ) 00193 { 00194 RCP<const Thyra::ProductVectorBase<Scalar> > x_bar_pv, x_bar_dot_pv; 00195 downcastStateAndSens(x_bar, x_bar_dot, x_bar_pv, x_bar_dot_pv); 00196 00197 extractStateBlock(x_bar_pv, x_bar_dot_pv, x, x_dot); 00198 } 00199 00200 00201 template<class Scalar> 00202 void Rythmos::extractSens( 00203 const RCP<const Thyra::VectorBase<Scalar> > &x_bar, 00204 const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot, 00205 RCP<const Thyra::MultiVectorBase<Scalar> > *S, 00206 RCP<const Thyra::MultiVectorBase<Scalar> > *S_dot 00207 ) 00208 { 00209 RCP<const Thyra::ProductVectorBase<Scalar> > x_bar_pv, x_bar_dot_pv; 00210 downcastStateAndSens(x_bar, x_bar_dot, x_bar_pv, x_bar_dot_pv); 00211 00212 extractSensBlock(x_bar_pv, x_bar_dot_pv, S, S_dot); 00213 } 00214 00215 00216 00217 #endif //RYTHMOS_EXTRACT_STATE_AND_SENS_HPP
1.7.6.1