Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_ResponseMESupport_Default.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
43#ifndef __Panzer_ResponseMESupport_Default_hpp__
44#define __Panzer_ResponseMESupport_Default_hpp__
45
46#include "Teuchos_DefaultMpiComm.hpp"
47#include "Teuchos_ArrayRCP.hpp"
48#include "Teuchos_RCP.hpp"
49#include "Teuchos_OpaqueWrapper.hpp"
50
52
53#include "Thyra_DefaultSpmdVectorSpace.hpp"
54#include "Thyra_SpmdVectorBase.hpp"
55
56#include "PanzerDiscFE_config.hpp"
57#ifdef PANZER_HAVE_EPETRA_STACK
58#include "Epetra_LocalMap.h"
59#include "Epetra_Map.h"
60#include "Thyra_EpetraThyraWrappers.hpp"
61#endif
62
63namespace panzer {
64
65template <typename EvalT>
67public:
68 ResponseMESupport_Default(const std::string & responseName,MPI_Comm comm)
69 : ResponseMESupportBase<EvalT>(responseName), useEpetra_(false),
70#ifdef PANZER_HAVE_EPETRA_STACK
71 eComm_(comm),
72#endif
73 useThyra_(false)
74 {
75 tComm_ = Teuchos::rcp(new Teuchos::MpiComm<Thyra::Ordinal>(Teuchos::opaqueWrapper(comm)));
76 }
77
79
81 virtual std::size_t localSizeRequired() const = 0;
82
84 virtual bool vectorIsDistributed() const = 0;
85
86#ifdef PANZER_HAVE_EPETRA_STACK
87 // This is the epetra view of the world
89
91 Teuchos::RCP<const Epetra_Map> getMap() const;
92
96 void setVector(const Teuchos::RCP<Epetra_Vector> & destVec);
97#endif
98
99 // This is the Thyra view of the world
101
103 Teuchos::RCP<const Thyra::VectorSpaceBase<double> > getVectorSpace() const;
104
108 void setVector(const Teuchos::RCP<Thyra::VectorBase<double> > & destVec);
109
111 void setVectorSpace(Teuchos::RCP<const Thyra::VectorSpaceBase<double> > vs)
112 { vSpace_ = vs; }
113
115 Teuchos::RCP<Thyra::VectorBase<double> > getVector() const
116 { return tVector_; }
117
118protected:
120 Teuchos::RCP<const Teuchos::Comm<Thyra::Ordinal> > getComm() const { return tComm_; }
121
123 bool useEpetra() const { return useEpetra_; }
124
126 bool useThyra() const { return useThyra_; }
127
128#ifdef PANZER_HAVE_EPETRA_STACK
130 Epetra_Vector & getEpetraVector() const;
131#endif
132
134 Thyra::ArrayRCP<double> getThyraVector() const;
135
137 Teuchos::RCP<Thyra::MultiVectorBase<double> > getThyraMultiVector() const
138 { return tVector_;}
139
140
141private:
142 // hide these methods
145
147#ifdef PANZER_HAVE_EPETRA_STACK
148 Epetra_MpiComm eComm_;
149 mutable Teuchos::RCP<const Epetra_Map> map_;
150 Teuchos::RCP<Epetra_Vector> eVector_;
151#endif
152
154 mutable Teuchos::RCP<const Thyra::VectorSpaceBase<double> > vSpace_;
155 Teuchos::RCP<Thyra::VectorBase<double> > tVector_;
156 Teuchos::RCP<const Teuchos::Comm<Thyra::Ordinal> > tComm_;
157};
158
159template < >
160class ResponseMESupport_Default<panzer::Traits::Jacobian> : public ResponseMESupportBase<panzer::Traits::Jacobian> {
161public:
162
163 ResponseMESupport_Default(const std::string & responseName,MPI_Comm comm,
164 const Teuchos::RCP<const Thyra::VectorSpaceBase<double> > & derivVecSpace=Teuchos::null)
165 : ResponseMESupportBase<panzer::Traits::Jacobian>(responseName), derivVecSpace_(derivVecSpace)
166 { tComm_ = Teuchos::rcp(new Teuchos::MpiComm<Thyra::Ordinal>(Teuchos::opaqueWrapper(comm))); }
167
169
171 virtual std::size_t localSizeRequired() const = 0;
172
174 virtual bool vectorIsDistributed() const = 0;
175
177 bool supportsDerivative() const { return getDerivativeVectorSpace()!=Teuchos::null; }
178
182 Teuchos::RCP<Thyra::MultiVectorBase<double> > getDerivative() const
183 { return derivative_; }
184
185#ifdef PANZER_HAVE_EPETRA_STACK
186 // This is the epetra view of the world
188
190 virtual Teuchos::RCP<Epetra_MultiVector> buildEpetraDerivative() const
191 {
192 TEUCHOS_ASSERT(!vectorIsDistributed());
193 TEUCHOS_ASSERT(localSizeRequired()==1);
194 TEUCHOS_ASSERT(supportsDerivative());
195
196 if(eMap_==Teuchos::null)
197 eMap_ = Thyra::get_Epetra_Map(*getDerivativeVectorSpace(),Thyra::get_Epetra_Comm(*tComm_));
198
199 return Teuchos::rcp(new Epetra_Vector(*eMap_));
200 }
201
205 virtual void setDerivative(const Teuchos::RCP<Epetra_MultiVector> & derivative)
206 {
207 TEUCHOS_ASSERT(!vectorIsDistributed());
208 TEUCHOS_ASSERT(localSizeRequired()==1);
209 TEUCHOS_ASSERT(supportsDerivative());
210 TEUCHOS_ASSERT(eMap_!=Teuchos::null);
211
212 derivative_ = Thyra::create_MultiVector(derivative,getDerivativeVectorSpace());
213 }
214#endif
215
216 // This is the Thyra view of the world
218
220 virtual Teuchos::RCP<Thyra::MultiVectorBase<double> > buildDerivative() const
221 {
222 TEUCHOS_ASSERT(!vectorIsDistributed());
223 TEUCHOS_ASSERT(localSizeRequired()==1);
224 TEUCHOS_ASSERT(supportsDerivative());
225 return Thyra::createMember(*getDerivativeVectorSpace());
226 }
227
231 virtual void setDerivative(const Teuchos::RCP<Thyra::MultiVectorBase<double> > & derivative)
232 {
233 TEUCHOS_ASSERT(!vectorIsDistributed());
234 TEUCHOS_ASSERT(localSizeRequired()==1);
235 TEUCHOS_ASSERT(supportsDerivative());
236 derivative_ = derivative;
237 }
238
239protected:
241 Teuchos::RCP<const Teuchos::Comm<Thyra::Ordinal> > getComm() const { return tComm_; }
242
244 Teuchos::RCP<const Thyra::VectorSpaceBase<double> > getDerivativeVectorSpace() const
245 { return derivVecSpace_; }
246
248 void setDerivativeVectorSpace(const Teuchos::RCP<const Thyra::VectorSpaceBase<double> > & vs)
249 { derivVecSpace_ = vs; }
250
251private:
252 // hide these methods
255
256 Teuchos::RCP<const Teuchos::Comm<Thyra::Ordinal> > tComm_;
257 Teuchos::RCP<const Thyra::VectorSpaceBase<double> > derivVecSpace_;
258#ifdef PANZER_HAVE_EPETRA_STACK
259 mutable Teuchos::RCP<const Epetra_Map> eMap_;
260#endif
261
262 Teuchos::RCP<Thyra::MultiVectorBase<double> > derivative_;
263};
264
265template < >
267public:
269
270 ResponseMESupport_Default(const std::string & responseName,MPI_Comm comm)
271 : ResponseMESupportBase<EvalT>(responseName), useEpetra_(false),
272#ifdef PANZER_HAVE_EPETRA_STACK
273 eComm_(comm),
274#endif
275 useThyra_(false)
276 {
277 tComm_ = Teuchos::rcp(new Teuchos::MpiComm<Thyra::Ordinal>(Teuchos::opaqueWrapper(comm)));
278 }
279
281
283 virtual std::size_t localSizeRequired() const = 0;
284
286 virtual bool vectorIsDistributed() const = 0;
287
288#ifdef PANZER_HAVE_EPETRA_STACK
289 // This is the epetra view of the world
291
293 Teuchos::RCP<const Epetra_Map> getMap() const {
294 TEUCHOS_TEST_FOR_EXCEPTION(useThyra_,std::logic_error,
295 "Reponse field \"" << this->getName() << "\" has previously been initialized as a "
296 "Thyra object, now trying to initalize as a Epetra! Error!");
297 // lazily construct the map only as needed
298 if(map_==Teuchos::null) {
299 if(this->vectorIsDistributed())
300 map_ = Teuchos::rcp(new Epetra_Map(-1,(int) this->localSizeRequired(),0,eComm_));
301 else
302 map_ = Teuchos::rcp(new Epetra_LocalMap((int) this->localSizeRequired(),0,eComm_));
303 }
304 return map_;
305 }
306
310 void setVector(const Teuchos::RCP<Epetra_MultiVector> & destVec) {
311 TEUCHOS_TEST_FOR_EXCEPTION(useThyra_,std::logic_error,
312 "Reponse field \"" << this->getName() << "\" has previously been initialized as a "
313 "Thyra object, now trying to initalize as a Epetra! Error!");
314 eVector_ = destVec;
315 useEpetra_ = true;
316 }
317#endif
318
319 // This is the Thyra view of the world
321
323 Teuchos::RCP<const Thyra::VectorSpaceBase<double> > getVectorSpace() const {
324 TEUCHOS_TEST_FOR_EXCEPTION(useEpetra_,std::logic_error,
325 "Reponse field \"" << this->getName() << "\" has previously been initialized as an "
326 "Epetra object, now trying to initalize as a Thyra object! Error!");
327 // lazily build the space and return it
328 if(vSpace_==Teuchos::null) {
329 if(this->vectorIsDistributed())
330 vSpace_ = Thyra::defaultSpmdVectorSpace<double>(tComm_,this->localSizeRequired(),-1);
331 else
332 vSpace_ = Thyra::locallyReplicatedDefaultSpmdVectorSpace<double>(tComm_,this->localSizeRequired());
333 }
334 return vSpace_;
335 }
336
340 void setVector(const Teuchos::RCP<Thyra::MultiVectorBase<double> > & destVec) {
341 TEUCHOS_TEST_FOR_EXCEPTION(useEpetra_,std::logic_error,
342 "Reponse field \"" << this->getName() << "\" has previously been initialized as an "
343 "Epetra object, now trying to initalize as a Thyra object! Error!");
344 tVector_ = destVec;
345 useThyra_ = true;
346 }
347
348protected:
350 Teuchos::RCP<const Teuchos::Comm<Thyra::Ordinal> > getComm() const { return tComm_; }
351
353 bool useEpetra() const { return useEpetra_; }
354
356 bool useThyra() const { return useThyra_; }
357
358#ifdef PANZER_HAVE_EPETRA_STACK
360 Epetra_MultiVector & getEpetraMultiVector() const {
361 TEUCHOS_ASSERT(useEpetra());
362 return *eVector_;
363 }
364#endif
365
367 Thyra::ArrayRCP< Thyra::ArrayRCP<double> > getThyraMultiVector() const {
368 TEUCHOS_ASSERT(useThyra());
369 const int num_col = tVector_->domain()->dim();
370 Thyra::ArrayRCP< Thyra::ArrayRCP<double> > data(num_col);
371 for (int i=0; i<num_col; ++i)
372 Teuchos::rcp_dynamic_cast<Thyra::SpmdVectorBase<double> >(tVector_->col(i),true)->getNonconstLocalData(Teuchos::outArg(data[i]));
373 return data;
374 }
375
377 int numDeriv() const {
378#ifdef PANZER_HAVE_EPETRA_STACK
379 if (useEpetra())
380 return eVector_->NumVectors();
381 else
382#endif
383 return tVector_->domain()->dim();
384 }
385
386
387private:
388 // hide these methods
391
393#ifdef PANZER_HAVE_EPETRA_STACK
394 Epetra_MpiComm eComm_;
395 mutable Teuchos::RCP<const Epetra_Map> map_;
396 Teuchos::RCP<Epetra_MultiVector> eVector_;
397#endif
398
400 mutable Teuchos::RCP<const Thyra::VectorSpaceBase<double> > vSpace_;
401 Teuchos::RCP<Thyra::MultiVectorBase<double> > tVector_;
402 Teuchos::RCP<const Teuchos::Comm<Thyra::Ordinal> > tComm_;
403};
404
405#ifdef Panzer_BUILD_HESSIAN_SUPPORT
406
407template < >
409public:
410
411 ResponseMESupport_Default(const std::string & responseName,MPI_Comm comm,
412 const Teuchos::RCP<const Thyra::VectorSpaceBase<double> > & derivVecSpace=Teuchos::null)
413 : ResponseMESupportBase<panzer::Traits::Hessian>(responseName), derivVecSpace_(derivVecSpace)
414 { tComm_ = Teuchos::rcp(new Teuchos::MpiComm<Thyra::Ordinal>(Teuchos::opaqueWrapper(comm))); }
415
417
419 virtual std::size_t localSizeRequired() const = 0;
420
422 virtual bool vectorIsDistributed() const = 0;
423
425 bool supportsDerivative() const { return getDerivativeVectorSpace()!=Teuchos::null; }
426
430 Teuchos::RCP<Thyra::MultiVectorBase<double> > getDerivative() const
431 { return derivative_; }
432
434 virtual Teuchos::RCP<Thyra::MultiVectorBase<double> > buildDerivative() const
435 {
436 TEUCHOS_ASSERT(!vectorIsDistributed());
437 TEUCHOS_ASSERT(localSizeRequired()==1);
438 TEUCHOS_ASSERT(supportsDerivative());
439 return Thyra::createMember(*getDerivativeVectorSpace());
440 }
441
445 virtual void setDerivative(const Teuchos::RCP<Thyra::MultiVectorBase<double> > & derivative)
446 {
447 TEUCHOS_ASSERT(!vectorIsDistributed());
448 TEUCHOS_ASSERT(localSizeRequired()==1);
449 TEUCHOS_ASSERT(supportsDerivative());
450 derivative_ = derivative;
451 }
452
453protected:
455 Teuchos::RCP<const Teuchos::Comm<Thyra::Ordinal> > getComm() const { return tComm_; }
456
458 Teuchos::RCP<const Thyra::VectorSpaceBase<double> > getDerivativeVectorSpace() const
459 { return derivVecSpace_; }
460
462 void setDerivativeVectorSpace(const Teuchos::RCP<const Thyra::VectorSpaceBase<double> > & vs)
463 { derivVecSpace_ = vs; }
464
465private:
466 // hide these methods
469
470 Teuchos::RCP<const Teuchos::Comm<Thyra::Ordinal> > tComm_;
471 Teuchos::RCP<const Thyra::VectorSpaceBase<double> > derivVecSpace_;
472
473 Teuchos::RCP<Thyra::MultiVectorBase<double> > derivative_;
474};
475
476#endif
477
478}
479
481
482#endif
std::string getName() const
virtual void setDerivative(const Teuchos::RCP< Thyra::MultiVectorBase< double > > &derivative)
bool supportsDerivative() const
Does this response support derivative evaluation?
Teuchos::RCP< Thyra::MultiVectorBase< double > > getDerivative() const
virtual bool vectorIsDistributed() const =0
Is the vector distributed (or replicated). For derivative assembly this must be false!
virtual Teuchos::RCP< Thyra::MultiVectorBase< double > > buildDerivative() const
Get the Epetra_Map for this response, map is constructed lazily.
Teuchos::RCP< const Teuchos::Comm< Thyra::Ordinal > > getComm() const
Get the teuchos comm object.
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > derivVecSpace_
void setDerivativeVectorSpace(const Teuchos::RCP< const Thyra::VectorSpaceBase< double > > &vs)
Set the derivative vector space.
virtual std::size_t localSizeRequired() const =0
What is the number of values you need locally.
ResponseMESupport_Default(const ResponseMESupport_Default< panzer::Traits::Hessian > &)
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > getDerivativeVectorSpace() const
Get the derivative vector space.
ResponseMESupport_Default(const std::string &responseName, MPI_Comm comm, const Teuchos::RCP< const Thyra::VectorSpaceBase< double > > &derivVecSpace=Teuchos::null)
Teuchos::RCP< const Teuchos::Comm< Thyra::Ordinal > > getComm() const
Get the teuchos comm object.
Teuchos::RCP< Thyra::MultiVectorBase< double > > getDerivative() const
virtual Teuchos::RCP< Thyra::MultiVectorBase< double > > buildDerivative() const
Get the Epetra_Map for this response, map is constructed lazily.
void setDerivativeVectorSpace(const Teuchos::RCP< const Thyra::VectorSpaceBase< double > > &vs)
Set the derivative vector space.
ResponseMESupport_Default(const ResponseMESupport_Default< panzer::Traits::Jacobian > &)
ResponseMESupport_Default(const std::string &responseName, MPI_Comm comm, const Teuchos::RCP< const Thyra::VectorSpaceBase< double > > &derivVecSpace=Teuchos::null)
virtual bool vectorIsDistributed() const =0
Is the vector distributed (or replicated). For derivative assembly this must be false!
bool supportsDerivative() const
Does this response support derivative evaluation?
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > derivVecSpace_
virtual std::size_t localSizeRequired() const =0
What is the number of values you need locally.
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > getDerivativeVectorSpace() const
Get the derivative vector space.
virtual void setDerivative(const Teuchos::RCP< Thyra::MultiVectorBase< double > > &derivative)
void setVector(const Teuchos::RCP< Thyra::MultiVectorBase< double > > &destVec)
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > getVectorSpace() const
Get the vector space for this response, vector space is constructed lazily.
virtual std::size_t localSizeRequired() const =0
What is the number of values you need locally.
Teuchos::RCP< const Teuchos::Comm< Thyra::Ordinal > > getComm() const
Get the teuchos comm object.
int numDeriv() const
Return the number of columns in the multivector.
virtual bool vectorIsDistributed() const =0
Is the vector distributed (or replicated)
Thyra::ArrayRCP< Thyra::ArrayRCP< double > > getThyraMultiVector() const
Access the thyra vector.
ResponseMESupport_Default(const ResponseMESupport_Default< EvalT > &)
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > vSpace_
Teuchos::RCP< Thyra::VectorBase< double > > tVector_
void setVectorSpace(Teuchos::RCP< const Thyra::VectorSpaceBase< double > > vs)
set the vector space for this response
Teuchos::RCP< const Teuchos::Comm< Thyra::Ordinal > > getComm() const
Get the teuchos comm object.
bool useEpetra() const
Is Epetra the right vector.
Teuchos::RCP< const Teuchos::Comm< Thyra::Ordinal > > tComm_
Teuchos::RCP< Thyra::MultiVectorBase< double > > getThyraMultiVector() const
Access the thyra MultiVector.
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > vSpace_
ResponseMESupport_Default(const ResponseMESupport_Default< EvalT > &)
virtual bool vectorIsDistributed() const =0
Is the vector distributed (or replicated)
virtual std::size_t localSizeRequired() const =0
What is the number of values you need locally.
void setVector(const Teuchos::RCP< Thyra::VectorBase< double > > &destVec)
Thyra::ArrayRCP< double > getThyraVector() const
Access the thyra vector.
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > getVectorSpace() const
Get the vector space for this response, vector space is constructed lazily.
Teuchos::RCP< Thyra::VectorBase< double > > getVector() const
Access the response vector.
bool useThyra() const
Is Thyra the right vector.
ResponseMESupport_Default(const std::string &responseName, MPI_Comm comm)