Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_BlockedEpetraLinearObjContainer.cpp
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_VectorBase.hpp"
46 #include "Thyra_VectorStdOps.hpp"
47 #include "Thyra_ProductVectorSpaceBase.hpp"
48 #include "Thyra_get_Epetra_Operator.hpp"
49 
50 #include "Epetra_CrsMatrix.h"
51 
52 namespace panzer {
53 
57 {
59  using Teuchos::RCP;
60  using Teuchos::null;
61 
62  bool x_matches=false, f_matches=false, dxdt_matches=false;
63 
64  if(get_A()!=null) {
65  RCP<const VectorSpaceBase<double> > range = get_A()->range();
66  RCP<const VectorSpaceBase<double> > domain = get_A()->domain();
67 
68  if(get_x()!=null)
69  x_matches = range->isCompatible(*get_x()->space());
70  else
71  x_matches = true; // nothing to compare
72 
73  if(get_dxdt()!=null)
74  dxdt_matches = range->isCompatible(*get_dxdt()->space());
75  else
76  dxdt_matches = true; // nothing to compare
77 
78  if(get_f()!=null)
79  f_matches = range->isCompatible(*get_f()->space());
80  else
81  f_matches = true; // nothing to compare
82  }
83  else if(get_x()!=null && get_dxdt()!=null) {
84  f_matches = true; // nothing to compare f to
85  x_matches = get_x()->space()->isCompatible(*get_dxdt()->space()); // dxdt and x are in the same space
86  dxdt_matches = x_matches;
87  }
88  else {
89  f_matches = x_matches = dxdt_matches = true; // nothing to compare to
90  }
91 
92  return x_matches && dxdt_matches && f_matches;
93 }
94 
97 {
98  using Thyra::LinearOpBase;
99  using Thyra::PhysicallyBlockedLinearOpBase;
100  using Thyra::ProductVectorSpaceBase;
101  using Teuchos::RCP;
102  using Teuchos::rcp_dynamic_cast;
103 
104  if(get_x()!=Teuchos::null) Thyra::assign<double>(x.ptr(),0.0);
105  if(get_dxdt()!=Teuchos::null) Thyra::assign<double>(get_dxdt().ptr(),0.0);
106  if(get_f()!=Teuchos::null) Thyra::assign<double>(get_f().ptr(),0.0);
107  if(get_A()!=Teuchos::null) {
109  = rcp_dynamic_cast<PhysicallyBlockedLinearOpBase<double> >(get_A(),true);
110  RCP<const ProductVectorSpaceBase<double> > range = Amat->productRange();
111  RCP<const ProductVectorSpaceBase<double> > domain = Amat->productDomain();
112 
113  // loop over block entries
114  for(int i=0;i<range->numBlocks();i++) {
115  for(int j=0;j<domain->numBlocks();j++) {
116  RCP<LinearOpBase<double> > block = Amat->getNonconstBlock(i,j);
117  if(block!=Teuchos::null) {
118  RCP<Epetra_Operator> e_block = Thyra::get_Epetra_Operator(*block);
119  rcp_dynamic_cast<Epetra_CrsMatrix>(e_block,true)->PutScalar(0.0);
120  }
121  }
122  }
123  }
124 }
125 
127 initializeMatrix(double value)
128 {
129  using Thyra::LinearOpBase;
130  using Thyra::PhysicallyBlockedLinearOpBase;
131  using Thyra::ProductVectorSpaceBase;
132  using Teuchos::RCP;
133  using Teuchos::rcp_dynamic_cast;
134 
135  if(get_A()!=Teuchos::null) {
137  = rcp_dynamic_cast<PhysicallyBlockedLinearOpBase<double> >(get_A(),true);
138  RCP<const ProductVectorSpaceBase<double> > range = Amat->productRange();
139  RCP<const ProductVectorSpaceBase<double> > domain = Amat->productDomain();
140 
141  // loop over block entries
142  for(int i=0;i<range->numBlocks();i++) {
143  for(int j=0;j<domain->numBlocks();j++) {
144  RCP<LinearOpBase<double> > block = Amat->getNonconstBlock(i,j);
145  if(block!=Teuchos::null) {
146  RCP<Epetra_Operator> e_block = Thyra::get_Epetra_Operator(*block);
147  rcp_dynamic_cast<Epetra_CrsMatrix>(e_block,true)->PutScalar(value);
148  }
149  }
150  }
151  }
152 }
153 
156 {
157  set_x(Teuchos::null);
158  set_dxdt(Teuchos::null);
159  set_f(Teuchos::null);
160  set_A(Teuchos::null);
161 }
162 
163 }
void initializeMatrix(double value)
Put a particular scalar in the matrix.
Ptr< T > ptr() const
void set_A(const Teuchos::RCP< CrsMatrixType > &in)
bool checkCompatibility() const
Make sure row and column spaces match up.
void set_dxdt(const Teuchos::RCP< VectorType > &in)