Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs Pages
Rythmos_extractStateAndSens.hpp
1 //@HEADER
2 // ***********************************************************************
3 //
4 // Rythmos Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
25 //
26 // ***********************************************************************
27 //@HEADER
28 
29 #ifndef RYTHMOS_EXTRACT_STATE_AND_SENS_HPP
30 #define RYTHMOS_EXTRACT_STATE_AND_SENS_HPP
31 
32 
33 #include "Rythmos_Types.hpp"
34 #include "Thyra_DefaultMultiVectorProductVector.hpp"
35 #include "Thyra_ProductVectorBase.hpp"
36 
37 
38 namespace Rythmos {
39 
40 
58 template<class Scalar>
59 void extractStateAndSens(
60  const RCP<const Thyra::VectorBase<Scalar> > &x_bar,
61  const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot,
62  RCP<const Thyra::VectorBase<Scalar> > *x,
63  RCP<const Thyra::MultiVectorBase<Scalar> > *S,
64  RCP<const Thyra::VectorBase<Scalar> > *x_dot,
65  RCP<const Thyra::MultiVectorBase<Scalar> > *S_dot
66  );
67 
68 
71 template<class Scalar>
72 void extractState(
73  const RCP<const Thyra::VectorBase<Scalar> > &x_bar,
74  const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot,
75  RCP<const Thyra::VectorBase<Scalar> > *x,
76  RCP<const Thyra::VectorBase<Scalar> > *x_dot
77  );
78 
79 
82 template<class Scalar>
83 void extractSens(
84  const RCP<const Thyra::VectorBase<Scalar> > &x_bar,
85  const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot,
86  RCP<const Thyra::MultiVectorBase<Scalar> > *S,
87  RCP<const Thyra::MultiVectorBase<Scalar> > *S_dot
88  );
89 
90 
91 } // namespace Rythmos
92 
93 
94 
95 //
96 // Implementations
97 //
98 
99 namespace Rythmos {
100 
101 namespace {
102 
103 
104 template<class Scalar>
105 void downcastStateAndSens(
106  const RCP<const Thyra::VectorBase<Scalar> > &x_bar,
107  const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot,
108  RCP<const Thyra::ProductVectorBase<Scalar> > &x_bar_pv,
109  RCP<const Thyra::ProductVectorBase<Scalar> > &x_bar_dot_pv
110  )
111 {
112  using Teuchos::rcp_dynamic_cast;
113 
114  TEUCHOS_TEST_FOR_EXCEPT(is_null(x_bar));
115  x_bar_pv = Thyra::productVectorBase<Scalar>(x_bar);
116 
117  TEUCHOS_TEST_FOR_EXCEPT(is_null(x_bar_dot));
118  x_bar_dot_pv = Thyra::productVectorBase<Scalar>(x_bar_dot);
119 }
120 
121 
122 template<class Scalar>
123 void extractStateBlock(
124  const RCP<const Thyra::ProductVectorBase<Scalar> > &x_bar_pv,
125  const RCP<const Thyra::ProductVectorBase<Scalar> > &x_bar_dot_pv,
126  RCP<const Thyra::VectorBase<Scalar> > *x,
127  RCP<const Thyra::VectorBase<Scalar> > *x_dot
128  )
129 {
130  TEUCHOS_TEST_FOR_EXCEPT(0==x);
131  *x = x_bar_pv->getVectorBlock(0);
132 
133  TEUCHOS_TEST_FOR_EXCEPT(0==x_dot);
134  *x_dot = x_bar_dot_pv->getVectorBlock(0);
135 }
136 
137 
138 template<class Scalar>
139 void extractSensBlock(
140  const RCP<const Thyra::ProductVectorBase<Scalar> > &x_bar_pv,
141  const RCP<const Thyra::ProductVectorBase<Scalar> > &x_bar_dot_pv,
142  RCP<const Thyra::MultiVectorBase<Scalar> > *S,
143  RCP<const Thyra::MultiVectorBase<Scalar> > *S_dot)
144 {
145  using Teuchos::rcp_dynamic_cast;
146 
147  TEUCHOS_TEST_FOR_EXCEPT(0==S);
148  const RCP<const Thyra::DefaultMultiVectorProductVector<Scalar> >
149  s_bar = rcp_dynamic_cast<const Thyra::DefaultMultiVectorProductVector<Scalar> >(
150  x_bar_pv->getVectorBlock(1).assert_not_null(), true
151  );
152  *S = s_bar->getMultiVector();
153 
154  TEUCHOS_TEST_FOR_EXCEPT(0==S_dot);
155  const RCP<const Thyra::DefaultMultiVectorProductVector<Scalar> >
156  s_bar_dot = rcp_dynamic_cast<const Thyra::DefaultMultiVectorProductVector<Scalar> >(
157  x_bar_dot_pv->getVectorBlock(1).assert_not_null(), true
158  );
159  *S_dot = s_bar_dot->getMultiVector();
160 }
161 
162 
163 } // anonymous namespace
164 
165 } // namespace Rythmos
166 
167 
168 template<class Scalar>
169 void Rythmos::extractStateAndSens(
170  const RCP<const Thyra::VectorBase<Scalar> > &x_bar,
171  const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot,
172  RCP<const Thyra::VectorBase<Scalar> > *x,
173  RCP<const Thyra::MultiVectorBase<Scalar> > *S,
174  RCP<const Thyra::VectorBase<Scalar> > *x_dot,
175  RCP<const Thyra::MultiVectorBase<Scalar> > *S_dot
176  )
177 {
178  RCP<const Thyra::ProductVectorBase<Scalar> > x_bar_pv, x_bar_dot_pv;
179  downcastStateAndSens(x_bar, x_bar_dot, x_bar_pv, x_bar_dot_pv);
180 
181  extractStateBlock(x_bar_pv, x_bar_dot_pv, x, x_dot);
182  extractSensBlock(x_bar_pv, x_bar_dot_pv, S, S_dot);
183 }
184 
185 
186 template<class Scalar>
187 void Rythmos::extractState(
188  const RCP<const Thyra::VectorBase<Scalar> > &x_bar,
189  const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot,
190  RCP<const Thyra::VectorBase<Scalar> > *x,
191  RCP<const Thyra::VectorBase<Scalar> > *x_dot
192  )
193 {
194  RCP<const Thyra::ProductVectorBase<Scalar> > x_bar_pv, x_bar_dot_pv;
195  downcastStateAndSens(x_bar, x_bar_dot, x_bar_pv, x_bar_dot_pv);
196 
197  extractStateBlock(x_bar_pv, x_bar_dot_pv, x, x_dot);
198 }
199 
200 
201 template<class Scalar>
202 void Rythmos::extractSens(
203  const RCP<const Thyra::VectorBase<Scalar> > &x_bar,
204  const RCP<const Thyra::VectorBase<Scalar> > &x_bar_dot,
205  RCP<const Thyra::MultiVectorBase<Scalar> > *S,
206  RCP<const Thyra::MultiVectorBase<Scalar> > *S_dot
207  )
208 {
209  RCP<const Thyra::ProductVectorBase<Scalar> > x_bar_pv, x_bar_dot_pv;
210  downcastStateAndSens(x_bar, x_bar_dot, x_bar_pv, x_bar_dot_pv);
211 
212  extractSensBlock(x_bar_pv, x_bar_dot_pv, S, S_dot);
213 }
214 
215 
216 
217 #endif //RYTHMOS_EXTRACT_STATE_AND_SENS_HPP