Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_Response_Probe_impl.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Panzer: A partial differential equation assembly
4// engine for strongly coupled complex multiphysics systems
5//
6// Copyright 2011 NTESS and the Panzer contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
11#ifndef __Panzer_Response_Probe_impl_hpp__
12#define __Panzer_Response_Probe_impl_hpp__
13
14#include "Teuchos_Comm.hpp"
15#include "Teuchos_CommHelpers.hpp"
16#include "Teuchos_dyn_cast.hpp"
17
18#include "PanzerDiscFE_config.hpp"
19#ifdef PANZER_HAVE_EPETRA_STACK
20#include "Epetra_LocalMap.h"
21#endif
22
23#include "Sacado_Traits.hpp"
24
25namespace panzer {
26
27template <typename EvalT>
29Response_Probe(const std::string & responseName, MPI_Comm comm,
30 const Teuchos::RCP<const panzer::LinearObjFactory<panzer::Traits> > & linObjFact)
31 : ResponseMESupport_Default<EvalT>(responseName,comm), value(0.0),
32 have_probe(false), linObjFactory_(linObjFact)
33{
34 if(linObjFactory_!=Teuchos::null) {
35 // requires thyra object factory
36 thyraObjFactory_ = Teuchos::rcp_dynamic_cast<const panzer::ThyraObjFactory<double> >(linObjFactory_,true);
37 setSolnVectorSpace(thyraObjFactory_->getThyraDomainSpace());
38
39 // build a ghosted container, with a solution vector
40 ghostedContainer_ = linObjFactory_->buildGhostedLinearObjContainer();
41
42 // set ghosted container (work space for assembly)
44 }
45}
46
47template <typename EvalT>
50{
51 value = 0.0;
52 have_probe = false;
53
54 if(ghostedContainer_!=Teuchos::null) ghostedContainer_->initialize();
55}
56
57template <typename EvalT>
60{
61 double glbValue = Sacado::scalarValue(value);
62
63 // find the minimum processor who has the probe value
64 int locProc = have_probe ? this->getComm()->getRank() : this->getComm()->getSize();
65 int glbProc = 0;
66 Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_MIN, Thyra::Ordinal(1), &locProc, &glbProc);
67
68 TEUCHOS_ASSERT(glbProc < this->getComm()->getSize());
69
70 // now broadcast the value from proc glbProc
71 Teuchos::broadcast(*this->getComm(), glbProc, Thyra::Ordinal(1), &glbValue);
72
73 value = glbValue;
74
75 // built data in vectors
76#ifdef PANZER_HAVE_EPETRA_STACK
77 if(this->useEpetra()) {
78 // use epetra
79 this->getEpetraVector()[0] = glbValue;
80 }
81 else
82#endif
83 {
84 // use thyra
85 TEUCHOS_ASSERT(this->useThyra());
86
87 this->getThyraVector()[0] = glbValue;
88 }
89}
90
91template < >
94{
95 using Teuchos::rcp_dynamic_cast;
96
97 Teuchos::RCP<Thyra::MultiVectorBase<double> > dgdx_unique = getDerivative();
98
99 uniqueContainer_ = linObjFactory_->buildLinearObjContainer();
100 Teuchos::rcp_dynamic_cast<ThyraObjContainer<double> >(uniqueContainer_)->set_x_th(dgdx_unique->col(0));
101
102 linObjFactory_->ghostToGlobalContainer(*ghostedContainer_,*uniqueContainer_,LinearObjContainer::X);
103
104 uniqueContainer_ = Teuchos::null;
105}
106
107#ifdef Panzer_BUILD_HESSIAN_SUPPORT
108template < >
111{
112 using Teuchos::rcp_dynamic_cast;
113
114 Teuchos::RCP<Thyra::MultiVectorBase<double> > dgdx_unique = getDerivative();
115
116 uniqueContainer_ = linObjFactory_->buildLinearObjContainer();
117 Teuchos::rcp_dynamic_cast<ThyraObjContainer<double> >(uniqueContainer_)->set_x_th(dgdx_unique->col(0));
118
119 linObjFactory_->ghostToGlobalContainer(*ghostedContainer_,*uniqueContainer_,LinearObjContainer::X);
120
121 uniqueContainer_ = Teuchos::null;
122}
123#endif
124
125template < >
128{
129 const int n = value.size();
130 const int num_deriv = this->numDeriv();
131 TEUCHOS_ASSERT(n == 0 || n == num_deriv);
132 if (n == 0)
133 value.resize(num_deriv);
134
135 // find the minimum processor who has the probe value
136 if (num_deriv > 0) {
137 int locProc = have_probe ? this->getComm()->getRank() : this->getComm()->getSize();
138 int glbProc = 0;
139 Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_MIN, Thyra::Ordinal(1), &locProc, &glbProc);
140
141 TEUCHOS_ASSERT(glbProc < this->getComm()->getSize());
142
143 // now broadcast the derivatives from proc glbProc
144 Teuchos::broadcast(*this->getComm(), glbProc, Thyra::Ordinal(num_deriv), &value.fastAccessDx(0));
145 }
146
147 // copy data in vectors
148#ifdef PANZER_HAVE_EPETRA_STACK
149 if(this->useEpetra()) {
150 // use epetra
151 Epetra_MultiVector& deriv = this->getEpetraMultiVector();
152 for (int i=0; i<num_deriv; ++i)
153 deriv[i][0] = value.dx(i);
154 }
155 else
156#endif
157 {
158 // use thyra
159 TEUCHOS_ASSERT(this->useThyra());
160 Thyra::ArrayRCP< Thyra::ArrayRCP<double> > deriv = this->getThyraMultiVector();
161 for (int i=0; i<num_deriv; ++i)
162 deriv[i][0] = value.dx(i);
163 }
164}
165
166// Do nothing unless derivatives are actually required
167template <typename EvalT>
169setSolnVectorSpace(const Teuchos::RCP<const Thyra::VectorSpaceBase<double> > & /* soln_vs */) { }
170
171// derivatives are required for
172template < >
174setSolnVectorSpace(const Teuchos::RCP<const Thyra::VectorSpaceBase<double> > & soln_vs)
175{
176 setDerivativeVectorSpace(soln_vs);
177}
178
179#ifdef Panzer_BUILD_HESSIAN_SUPPORT
180// derivatives are required for
181template < >
183setSolnVectorSpace(const Teuchos::RCP<const Thyra::VectorSpaceBase<double> > & soln_vs)
184{
185 setDerivativeVectorSpace(soln_vs);
186}
187#endif
188
189// Do nothing unless derivatives are required
190template <typename EvalT>
192adjustForDirichletConditions(const GlobalEvaluationData & /* localBCRows */, const GlobalEvaluationData & /* globalBCRows */) { }
193
194// Do nothing unless derivatives are required
195template < >
197adjustForDirichletConditions(const GlobalEvaluationData & localBCRows,const GlobalEvaluationData & globalBCRows)
198{
199 linObjFactory_->adjustForDirichletConditions(Teuchos::dyn_cast<const LinearObjContainer>(localBCRows),
200 Teuchos::dyn_cast<const LinearObjContainer>(globalBCRows),
201 *ghostedContainer_,true,true);
202}
203
204#ifdef Panzer_BUILD_HESSIAN_SUPPORT
205// Do nothing unless derivatives are required
206template < >
208adjustForDirichletConditions(const GlobalEvaluationData & localBCRows,const GlobalEvaluationData & globalBCRows)
209{
210 linObjFactory_->adjustForDirichletConditions(Teuchos::dyn_cast<const LinearObjContainer>(localBCRows),
211 Teuchos::dyn_cast<const LinearObjContainer>(globalBCRows),
212 *ghostedContainer_,true,true);
213}
214#endif
215
216}
217
218#endif
Teuchos::RCP< const panzer::ThyraObjFactory< double > > thyraObjFactory_
Teuchos::RCP< LinearObjContainer > ghostedContainer_
void setSolnVectorSpace(const Teuchos::RCP< const Thyra::VectorSpaceBase< double > > &soln_vs)
Set solution vector space.
Teuchos::RCP< const panzer::LinearObjFactory< panzer::Traits > > linObjFactory_
void adjustForDirichletConditions(const GlobalEvaluationData &localBCRows, const GlobalEvaluationData &globalBCRows)
virtual void scatterResponse()
This simply does global summation, then shoves the result into a vector.