EpetraExt Development
Loading...
Searching...
No Matches
EpetraExt_DiagonalQuadraticResponseOnlyModelEvaluator.cpp
Go to the documentation of this file.
1/*
2//@HEADER
3// ***********************************************************************
4//
5// EpetraExt: Epetra Extended - Linear Algebra Services Package
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 Michael A. Heroux (maherou@sandia.gov)
39//
40// ***********************************************************************
41//@HEADER
42*/
43
45#include "Teuchos_ScalarTraits.hpp"
46#include "Epetra_SerialComm.h"
47#include "Epetra_CrsMatrix.h"
48
49
50namespace EpetraExt {
51
52
53DiagonalQuadraticResponseOnlyModelEvaluator
54::DiagonalQuadraticResponseOnlyModelEvaluator(
55 const Teuchos::RCP<Epetra_Comm> &comm,
56 const int localDim, const double &pt, const double &p0, const double &scale
57 )
58 :epetra_comm_(comm), scale_(scale)
59{
60
61 using Teuchos::rcp;
62
63 const int ng = 1;
64
65 map_p_ = rcp(new Epetra_Map(-1, localDim, 0, *epetra_comm_));
66 map_g_ = rcp(new Epetra_Map(ng, ng, 0, *epetra_comm_));
67
68 pt_ = rcp(new Epetra_Vector(*map_p_));
69 pt_->PutScalar(pt);
70
71 p0_ = rcp(new Epetra_Vector(*map_p_));
72 p0_->PutScalar(p0);
73
74}
75
76
77// Overridden from EpetraExt::ModelEvaluator
78
79
80Teuchos::RCP<const Epetra_Map>
82{
83 return Teuchos::null;
84}
85
86
87Teuchos::RCP<const Epetra_Map>
89{
90 return Teuchos::null;
91}
92
93
94Teuchos::RCP<const Epetra_Map>
96{
97 TEUCHOS_TEST_FOR_EXCEPT(l!=0);
98 return map_p_;
99}
100
101
102Teuchos::RCP<const Epetra_Map>
104{
105 TEUCHOS_TEST_FOR_EXCEPT(j!=0);
106 return map_g_;
107}
108
109
110Teuchos::RCP<const Epetra_Vector>
112{
113 TEUCHOS_TEST_FOR_EXCEPT(l!=0);
114 return p0_;
115}
116
117
120{
121 InArgsSetup inArgs;
122 inArgs.setModelEvalDescription(this->description());
123 inArgs.set_Np(1);
124 return inArgs;
125}
126
127
130{
131 OutArgsSetup outArgs;
132 outArgs.setModelEvalDescription(this->description());
133 outArgs.set_Np_Ng(1, 1);
135 outArgs.set_DgDp_properties(
139 true // supportsAdjoint
140 )
141 );
142 return outArgs;
143}
144
145
147 const InArgs& inArgs, const OutArgs& outArgs
148 ) const
149{
150
151 using Teuchos::RCP;
152 using Teuchos::dyn_cast;
153 using Teuchos::rcp_dynamic_cast;
154
155 //
156 // Get the input arguments
157 //
158
159 const Epetra_Vector &p = *inArgs.get_p(0);
160
161 //
162 // Get the output arguments
163 //
164
165 const RCP<Epetra_Vector> g_out = outArgs.get_g(0);
166
167 const RCP<Epetra_MultiVector> DgDp_trans_out =
169
170 //
171 // Compute the functions
172 //
173
174 if (nonnull(g_out) || nonnull(DgDp_trans_out)) {
175
176 Epetra_Vector p_minus_pt(*map_p_);
177
178 p_minus_pt = p;
179 p_minus_pt.Update(-1.0, *pt_, 1.0);
180
181 if (nonnull(g_out)) {
182 double dot[1];
183 p_minus_pt.Dot(p_minus_pt, dot);
184 (*g_out)[0] = scale_ * 0.5 * dot[0];
185 }
186
187 if (nonnull(DgDp_trans_out)) {
188 (*DgDp_trans_out) = p_minus_pt;
189 DgDp_trans_out->Scale(scale_);
190 }
191
192 }
193
194}
195
196
197} // namespace EpetraExt
void setModelEvalDescription(const std::string &modelEvalDescription)
Teuchos::RCP< const Epetra_Vector > get_p(int l) const
void setModelEvalDescription(const std::string &modelEvalDescription)
void set_DgDp_properties(int j, int l, const DerivativeProperties &properties)
void setSupports(EOutArgsMembers arg, bool supports=true)
Evaluation< Epetra_Vector > get_g(int j) const
Get g(j) where 0 <= j && j < this->Ng().
int Dot(const Epetra_MultiVector &A, double *Result) const
int Update(double ScalarA, const Epetra_MultiVector &A, double ScalarThis)
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.
Teuchos::RCP< Epetra_MultiVector > get_DgDp_mv(const int j, const int l, const ModelEvaluator::OutArgs &outArgs, const ModelEvaluator::EDerivativeMultiVectorOrientation mvOrientation)