Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_Response_ExtremeValue_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
43#ifndef __Panzer_Response_ExtremeValue_impl_hpp__
44#define __Panzer_Response_ExtremeValue_impl_hpp__
45
46#include "Teuchos_Comm.hpp"
47#include "Teuchos_CommHelpers.hpp"
48#include "Teuchos_dyn_cast.hpp"
49
50#include "PanzerDiscFE_config.hpp"
51#ifdef PANZER_HAVE_EPETRA_STACK
52#include "Epetra_LocalMap.h"
53#endif
54
55#include "Sacado_Traits.hpp"
56
57namespace panzer {
58
59template <typename EvalT>
62{
63 double locValue = Sacado::scalarValue(value);
64 double glbValue = 0.0;
65
66 // do global summation
67 if(useMax_)
68 Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_MAX, static_cast<Thyra::Ordinal>(1), &locValue,&glbValue);
69 else
70 Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_MIN, static_cast<Thyra::Ordinal>(1), &locValue,&glbValue);
71
72 value = glbValue;
73
74#ifdef PANZER_HAVE_EPETRA_STACK
75 // built data in vectors
76 if(this->useEpetra()) {
77 // use epetra
78 this->getEpetraVector()[0] = glbValue;
79 }
80 else
81#endif
82 {
83 // use thyra
84 TEUCHOS_ASSERT(this->useThyra());
85
86 this->getThyraVector()[0] = glbValue;
87 }
88}
89
90template < >
93{
94 using Teuchos::rcp_dynamic_cast;
95
96 Teuchos::RCP<Thyra::MultiVectorBase<double> > dgdx_unique = getDerivative();
97
98 uniqueContainer_ = linObjFactory_->buildLinearObjContainer();
99 Teuchos::rcp_dynamic_cast<ThyraObjContainer<double> >(uniqueContainer_)->set_x_th(dgdx_unique->col(0));
100
101 linObjFactory_->ghostToGlobalContainer(*ghostedContainer_,*uniqueContainer_,LinearObjContainer::X);
102
103 uniqueContainer_ = Teuchos::null;
104}
105
106#ifdef Panzer_BUILD_HESSIAN_SUPPORT
107template < >
110{
111 using Teuchos::rcp_dynamic_cast;
112
113 Teuchos::RCP<Thyra::MultiVectorBase<double> > dgdx_unique = getDerivative();
114
115 uniqueContainer_ = linObjFactory_->buildLinearObjContainer();
116 Teuchos::rcp_dynamic_cast<ThyraObjContainer<double> >(uniqueContainer_)->set_x_th(dgdx_unique->col(0));
117
118 linObjFactory_->ghostToGlobalContainer(*ghostedContainer_,*uniqueContainer_,LinearObjContainer::X);
119
120 uniqueContainer_ = Teuchos::null;
121}
122#endif
123
124template < >
127{
128 const int n = value.size();
129 const int num_deriv = this->numDeriv();
130 TEUCHOS_ASSERT(n == 0 || n == num_deriv);
131 ScalarT glbValue = ScalarT(num_deriv, 0.0);
132
133 // do global min/max on value
134 if(useMax_)
135 Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_MAX, Thyra::Ordinal(1), &value.val(), &glbValue.val());
136 else
137 Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_MIN, Thyra::Ordinal(1), &value.val(), &glbValue.val());
138
139 // find the minimum processor who's local value == the global min/max value
140 if (num_deriv > 0) {
141 int locProc = value.val() == glbValue.val() ? this->getComm()->getRank() : this->getComm()->getSize();
142 int glbProc = 0;
143 Teuchos::reduceAll(*this->getComm(), Teuchos::REDUCE_MIN, Thyra::Ordinal(1), &locProc, &glbProc);
144
145 // now broadcast the derivatives from proc glbProc
146 Teuchos::broadcast(*this->getComm(), glbProc, Thyra::Ordinal(n), &glbValue.fastAccessDx(0));
147 }
148
149 value = glbValue;
150
151 // copy data in vectors
152#ifdef PANZER_HAVE_EPETRA_STACK
153 if(this->useEpetra()) {
154 // use epetra
155 Epetra_MultiVector& deriv = this->getEpetraMultiVector();
156 for (int i=0; i<num_deriv; ++i)
157 deriv[i][0] = glbValue.dx(i);
158 }
159 else
160#endif
161 {
162 // use thyra
163 TEUCHOS_ASSERT(this->useThyra());
164 Thyra::ArrayRCP< Thyra::ArrayRCP<double> > deriv = this->getThyraMultiVector();
165 for (int i=0; i<num_deriv; ++i)
166 deriv[i][0] = glbValue.dx(i);
167 }
168}
169
170// Do nothing unless derivatives are actually required
171template <typename EvalT>
173setSolnVectorSpace(const Teuchos::RCP<const Thyra::VectorSpaceBase<double> > & /* soln_vs */) { }
174
175// derivatives are required for
176template < >
178setSolnVectorSpace(const Teuchos::RCP<const Thyra::VectorSpaceBase<double> > & soln_vs)
179{
180 setDerivativeVectorSpace(soln_vs);
181}
182
183#ifdef Panzer_BUILD_HESSIAN_SUPPORT
184// derivatives are required for
185template < >
187setSolnVectorSpace(const Teuchos::RCP<const Thyra::VectorSpaceBase<double> > & soln_vs)
188{
189 setDerivativeVectorSpace(soln_vs);
190}
191#endif
192
193// Do nothing unless derivatives are required
194template <typename EvalT>
196adjustForDirichletConditions(const GlobalEvaluationData & /* localBCRows */, const GlobalEvaluationData & /* globalBCRows */) { }
197
198// Do nothing unless derivatives are required
199template < >
201adjustForDirichletConditions(const GlobalEvaluationData & localBCRows,const GlobalEvaluationData & globalBCRows)
202{
203 linObjFactory_->adjustForDirichletConditions(Teuchos::dyn_cast<const LinearObjContainer>(localBCRows),
204 Teuchos::dyn_cast<const LinearObjContainer>(globalBCRows),
205 *ghostedContainer_,true,true);
206}
207
208#ifdef Panzer_BUILD_HESSIAN_SUPPORT
209// Do nothing unless derivatives are required
210template < >
212adjustForDirichletConditions(const GlobalEvaluationData & localBCRows,const GlobalEvaluationData & globalBCRows)
213{
214 linObjFactory_->adjustForDirichletConditions(Teuchos::dyn_cast<const LinearObjContainer>(localBCRows),
215 Teuchos::dyn_cast<const LinearObjContainer>(globalBCRows),
216 *ghostedContainer_,true,true);
217}
218#endif
219
220}
221
222#endif
void setSolnVectorSpace(const Teuchos::RCP< const Thyra::VectorSpaceBase< double > > &soln_vs)
Set solution vector space.
void adjustForDirichletConditions(const GlobalEvaluationData &localBCRows, const GlobalEvaluationData &globalBCRows)
virtual void scatterResponse()
This simply does global summation, then shoves the result into a vector.