Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_BlockedTpetraLinearObjContainer_impl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
44 
45 #include "Thyra_VectorStdOps.hpp"
46 #include "Thyra_ProductVectorSpaceBase.hpp"
47 #include "Thyra_get_Epetra_Operator.hpp"
48 #include "Thyra_TpetraLinearOp.hpp"
49 
50 #include "Tpetra_CrsMatrix.hpp"
51 
52 namespace panzer {
53 
55 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
58 {
60  using Teuchos::RCP;
61  using Teuchos::null;
62 
63  bool x_matches=false, f_matches=false, dxdt_matches=false;
64 
65  if(get_A()!=null) {
66  RCP<const VectorSpaceBase<ScalarT> > range = get_A()->range();
67  RCP<const VectorSpaceBase<ScalarT> > domain = get_A()->domain();
68 
69  if(get_x()!=null)
70  x_matches = range->isCompatible(*get_x()->space());
71  else
72  x_matches = true; // nothing to compare
73 
74  if(get_dxdt()!=null)
75  dxdt_matches = range->isCompatible(*get_dxdt()->space());
76  else
77  dxdt_matches = true; // nothing to compare
78 
79  if(get_f()!=null)
80  f_matches = range->isCompatible(*get_f()->space());
81  else
82  f_matches = true; // nothing to compare
83  }
84  else if(get_x()!=null && get_dxdt()!=null) {
85  f_matches = true; // nothing to compare f to
86  x_matches = get_x()->space()->isCompatible(*get_dxdt()->space()); // dxdt and x are in the same space
87  dxdt_matches = x_matches;
88  }
89  else {
90  f_matches = x_matches = dxdt_matches = true; // nothing to compare to
91  }
92 
93  return x_matches && dxdt_matches && f_matches;
94 }
95 
96 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
99 {
100  using Thyra::LinearOpBase;
101  using Thyra::PhysicallyBlockedLinearOpBase;
102  using Thyra::ProductVectorSpaceBase;
103  using Teuchos::RCP;
104  using Teuchos::rcp_dynamic_cast;
105 
106  if(get_x()!=Teuchos::null) Thyra::assign<ScalarT>(x.ptr(),0.0);
107  if(get_dxdt()!=Teuchos::null) Thyra::assign<ScalarT>(get_dxdt().ptr(),0.0);
108  if(get_f()!=Teuchos::null) Thyra::assign<ScalarT>(get_f().ptr(),0.0);
109  if(get_A()!=Teuchos::null) {
111  = rcp_dynamic_cast<PhysicallyBlockedLinearOpBase<ScalarT> >(get_A(),true);
112  RCP<const ProductVectorSpaceBase<ScalarT> > range = Amat->productRange();
113  RCP<const ProductVectorSpaceBase<ScalarT> > domain = Amat->productDomain();
114 
115  // loop over block entries
116  for(int i=0;i<range->numBlocks();i++) {
117  for(int j=0;j<domain->numBlocks();j++) {
118  RCP<LinearOpBase<ScalarT> > block = Amat->getNonconstBlock(i,j);
119  if(block!=Teuchos::null) {
121  rcp_dynamic_cast<Thyra::TpetraLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(block,true)->getTpetraOperator();
122 
123  RCP<const MapType> map_i = t_block->getRangeMap();
124  RCP<const MapType> map_j = t_block->getDomainMap();
125 
127  rcp_dynamic_cast<Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(t_block,true);
128 
129  mat->resumeFill();
130  mat->setAllToScalar(0.0);
131  mat->fillComplete(map_j,map_i);
132  }
133  }
134  }
135  }
136 }
137 
138 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
140 initializeMatrix(ScalarT value)
141 {
142  using Thyra::LinearOpBase;
143  using Thyra::PhysicallyBlockedLinearOpBase;
144  using Thyra::ProductVectorSpaceBase;
145  using Teuchos::RCP;
146  using Teuchos::rcp_dynamic_cast;
147 
148  if(get_A()!=Teuchos::null) {
150  = rcp_dynamic_cast<PhysicallyBlockedLinearOpBase<ScalarT> >(get_A(),true);
151  RCP<const ProductVectorSpaceBase<ScalarT> > range = Amat->productRange();
152  RCP<const ProductVectorSpaceBase<ScalarT> > domain = Amat->productDomain();
153 
154  // loop over block entries
155  for(int i=0;i<range->numBlocks();i++) {
156  for(int j=0;j<domain->numBlocks();j++) {
157  RCP<LinearOpBase<ScalarT> > block = Amat->getNonconstBlock(i,j);
158  if(block!=Teuchos::null) {
160  rcp_dynamic_cast<Thyra::TpetraLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(block,true)->getTpetraOperator();
161 
162  // why do I have to do this?
163  RCP<const MapType> map_i = t_block->getRangeMap();
164  RCP<const MapType> map_j = t_block->getDomainMap();
165 
167  rcp_dynamic_cast<Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(t_block,true);
168 
169  mat->resumeFill();
170  mat->setAllToScalar(value);
171  mat->fillComplete(map_j,map_i);
172  }
173  }
174  }
175  }
176 }
177 
178 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
181 {
182  set_x(Teuchos::null);
183  set_dxdt(Teuchos::null);
184  set_f(Teuchos::null);
185  set_A(Teuchos::null);
186 }
187 
188 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
191 {
192  using Thyra::LinearOpBase;
193  using Thyra::PhysicallyBlockedLinearOpBase;
194  using Thyra::ProductVectorSpaceBase;
195  using Teuchos::RCP;
196  using Teuchos::rcp_dynamic_cast;
197 
198  if(get_A()!=Teuchos::null) {
200  = rcp_dynamic_cast<PhysicallyBlockedLinearOpBase<ScalarT> >(get_A(),true);
201  RCP<const ProductVectorSpaceBase<ScalarT> > range = Amat->productRange();
202  RCP<const ProductVectorSpaceBase<ScalarT> > domain = Amat->productDomain();
203 
204  // loop over block entries
205  for(int i=0;i<range->numBlocks();i++) {
206  for(int j=0;j<domain->numBlocks();j++) {
207  RCP<LinearOpBase<ScalarT> > block = Amat->getNonconstBlock(i,j);
208  if(block!=Teuchos::null) {
210  rcp_dynamic_cast<Thyra::TpetraLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(block,true)->getTpetraOperator();
211 
213  rcp_dynamic_cast<Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(t_block,true);
214 
215  mat->resumeFill();
216  }
217  }
218  }
219  }
220 }
221 
222 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
225 {
226  using Thyra::LinearOpBase;
227  using Thyra::PhysicallyBlockedLinearOpBase;
228  using Thyra::ProductVectorSpaceBase;
229  using Teuchos::RCP;
230  using Teuchos::rcp_dynamic_cast;
231 
232  if(get_A()!=Teuchos::null) {
234  = rcp_dynamic_cast<PhysicallyBlockedLinearOpBase<ScalarT> >(get_A(),true);
235  RCP<const ProductVectorSpaceBase<ScalarT> > range = Amat->productRange();
236  RCP<const ProductVectorSpaceBase<ScalarT> > domain = Amat->productDomain();
237 
238  // loop over block entries
239  for(int i=0;i<range->numBlocks();i++) {
240  for(int j=0;j<domain->numBlocks();j++) {
241  RCP<LinearOpBase<ScalarT> > block = Amat->getNonconstBlock(i,j);
242  if(block!=Teuchos::null) {
244  rcp_dynamic_cast<Thyra::TpetraLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(block,true)->getTpetraOperator();
245 
246  RCP<const MapType> map_i = t_block->getRangeMap();
247  RCP<const MapType> map_j = t_block->getDomainMap();
248 
250  rcp_dynamic_cast<Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(t_block,true);
251 
252  mat->fillComplete(map_j,map_i);
253  }
254  }
255  }
256  }
257 }
258 
259 }
bool checkCompatibility() const
Make sure row and column spaces match up.
void initializeMatrix(ScalarT value)
Put a particular scalar in the matrix.