Xyce  6.1
N_ANP_ModelEvaluator_Stateless.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // Copyright Notice
3 //
4 // Copyright 2002 Sandia Corporation. Under the terms
5 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
6 // Government retains certain rights in this software.
7 //
8 // Xyce(TM) Parallel Electrical Simulator
9 // Copyright (C) 2002-2015 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-----------------------------------------------------------------------------
26 // Filename : $RCSfile: N_ANP_ModelEvaluator_Stateless.C,v $
27 // Purpose : This file supports the integration of Xyce with
28 // Rythmos.
29 // Special Notes :
30 // Creator : Todd Coffey, 1414
31 // Creation Date : mid 2009
32 //
33 // Revision Information:
34 // ---------------------
35 
36 #include <Xyce_config.h>
37 
38 // ---------- Xyce Includes ----------
39 #include <N_DEV_fwd.h>
40 #undef HAVE_LIBPARMETIS
42 #include <N_LAS_Vector.h>
43 #include <N_LAS_BlockVector.h>
44 #include <N_LAS_BlockMatrix.h>
45 #include <N_PDS_ParMap.h>
46 // ---------- Trilinos Includes ----------
47 #include <Epetra_Map.h>
48 #include <Epetra_Vector.h>
49 #include <Epetra_Operator.h>
50 #include <Epetra_CrsMatrix.h>
51 
52 using Teuchos::rcp;
53 
54 namespace Xyce {
55 namespace Analysis {
56 
57 RCP<ModelEvaluator_Stateless> N_ANP_modelEvaluator_Stateless()
58 {
59  return rcp(new ModelEvaluator_Stateless());
60 }
61 
62 
63 RCP<ModelEvaluator_Stateless> N_ANP_modelEvaluator_Stateless(
64  const RCP<ModelEvaluator>& xyceME)
65 {
66  RCP<ModelEvaluator_Stateless>
68  xyceMES->set_XyceModelEvaluator(xyceME);
69  return xyceMES;
70 }
71 
72 
74  :isInitialized_(false)
75 {
76 }
77 
78 
80 {
81 }
82 
84  const RCP<Analysis::ModelEvaluator>& xyceME)
85 {
86  TEUCHOS_ASSERT(xyceME->isInitialized());
87  xyceME_ = xyceME;
88  tempStateVector_ = rcp(new Epetra_Vector(*xyceME_->get_g_map(0)));
89  tempStateDotVector_ = rcp(new Epetra_Vector(*xyceME_->get_g_map(0)));
90  tempVoltLimQVector_ = rcp(new Epetra_Vector(*xyceME_->get_x_map()));
91  tempVoltLimFVector_ = rcp(new Epetra_Vector(*xyceME_->get_x_map()));
92  tempFVector_ = rcp(new Epetra_Vector(*xyceME_->get_f_map()));
93  tempWOperator_ = xyceME_->create_W();
94  this->setupInOutArgs_();
95 }
96 
98 {
99  if (!isInitialized_) {
100  Np_ = 0;
101  Ng_ = 0;
102  EpetraExt::ModelEvaluator::InArgsSetup inArgs;
103  inArgs.setSupports(IN_ARG_t,true);
104  inArgs.setSupports(IN_ARG_x,true);
105  inArgs.setSupports(IN_ARG_x_dot,true);
106  inArgs.setSupports(IN_ARG_alpha,true);
107  inArgs.setSupports(IN_ARG_beta,true);
108  inArgs.set_Np(Np_);
109  inArgs_ = inArgs;
110 
111  EpetraExt::ModelEvaluator::OutArgsSetup outArgs;
112  outArgs.setSupports(OUT_ARG_f,true);
113  outArgs.setSupports(OUT_ARG_W,true);
114  outArgs.set_Np_Ng(Np_,Ng_);
115  outArgs_ = outArgs;
116 
117  isInitialized_ = true;
118  }
119 }
120 
121 
122 EpetraExt::ModelEvaluator::InArgs ModelEvaluator_Stateless::createInArgs() const
123 {
124  TEUCHOS_ASSERT(isInitialized_);
125  return inArgs_;
126 }
127 
128 
129 EpetraExt::ModelEvaluator::OutArgs ModelEvaluator_Stateless::createOutArgs() const
130 {
131  TEUCHOS_ASSERT(isInitialized_);
132  return outArgs_;
133 }
134 
135 
136 RCP<const Epetra_Map> ModelEvaluator_Stateless::get_x_map() const
137 {
138  TEUCHOS_ASSERT(isInitialized_);
139  return xyceME_->get_x_map();
140 }
141 
142 
143 RCP<const Epetra_Map> ModelEvaluator_Stateless::get_f_map() const
144 {
145  TEUCHOS_ASSERT(isInitialized_);
146  return xyceME_->get_f_map();
147 }
148 
149 
150 RCP<const Epetra_Map> ModelEvaluator_Stateless::get_p_map(int p) const
151 {
152  TEUCHOS_ASSERT(isInitialized_);
153  return Teuchos::null;
154 }
155 
156 
157 RCP<const Epetra_Map> ModelEvaluator_Stateless::get_g_map(int p) const
158 {
159  TEUCHOS_ASSERT(isInitialized_);
160  return Teuchos::null;
161 }
162 
163 
164 void ModelEvaluator_Stateless::evalModel( const InArgs& inArgs, const OutArgs& outArgs ) const
165 {
166 
167  TEUCHOS_ASSERT(isInitialized_);
168  double t = inArgs.get_t();
169  RCP<const Epetra_Vector> x = inArgs.get_x().assert_not_null();
170  RCP<const Epetra_Vector> x_dot = inArgs.get_x_dot().assert_not_null();
171  RCP<Epetra_Vector> f = outArgs.get_f();
172  RCP<Epetra_Operator> W = outArgs.get_W();
173 
174  // First we evaluate the state vector:
175  {
176  EpetraExt::ModelEvaluator::InArgs xyceInArgs = xyceME_->createInArgs();
177  EpetraExt::ModelEvaluator::OutArgs xyceOutArgs = xyceME_->createOutArgs();
178 
179  xyceInArgs.set_t(t);
180  xyceInArgs.set_x(x);
181  xyceInArgs.set_x_dot(x_dot);
182  xyceOutArgs.set_g(0,tempStateVector_);
183  xyceME_->evalModel(xyceInArgs,xyceOutArgs);
184  }
185 
186  {
187  // Fabricate a StateDot Vector
188  // tempStateDotVector_ = tempStateVector_
189  tempStateDotVector_->Update(1.0,*tempStateVector_,0.0);
190  }
191 
192  if (Teuchos::is_null(f)) {
193  // If the client did not ask for f, then we have to load it into a
194  // temporary vector because Xyce does not support loading f
195  // separately from W.
196  f = tempFVector_;
197  }
198  if (Teuchos::is_null(W)) {
199  // If the client did not ask for W, then we have to load it into a
200  // temporary vector because Xyce does not support loading f
201  // separately from W.
202  W = tempWOperator_;
203  }
204 
205  // Second, we evaluate f and W:
206  {
207  EpetraExt::ModelEvaluator::InArgs xyceInArgs = xyceME_->createInArgs();
208  EpetraExt::ModelEvaluator::OutArgs xyceOutArgs = xyceME_->createOutArgs();
209  xyceInArgs.set_t(t);
210  xyceInArgs.set_x(x);
211  xyceInArgs.set_x_dot(x_dot);
212  xyceInArgs.set_alpha(inArgs.get_alpha());
213  xyceInArgs.set_beta(inArgs.get_beta());
214  xyceInArgs.set_p(0,tempStateVector_);
215  xyceInArgs.set_p(1,tempStateDotVector_);
216  xyceOutArgs.set_g(1,tempVoltLimQVector_);
217  xyceOutArgs.set_g(2,tempVoltLimFVector_);
218  xyceOutArgs.set_f(f);
219  xyceOutArgs.set_W(W);
220  xyceME_->evalModel(xyceInArgs,xyceOutArgs);
221  }
222 }
223 
224 
225 RCP<Epetra_Operator> ModelEvaluator_Stateless::create_W() const
226 {
227  TEUCHOS_ASSERT(isInitialized_);
228  return xyceME_->create_W();
229 }
230 
231 } // namespace Analysis
232 } // namespace Xyce
Pure virtual class to augment a linear system.
Teuchos::RCP< const Epetra_Map > get_f_map() const
EpetraExt::ModelEvaluator::OutArgs createOutArgs() const
EpetraExt::ModelEvaluator::InArgs createInArgs() const
RCP< ModelEvaluator_Stateless > N_ANP_modelEvaluator_Stateless()
Teuchos::RCP< Epetra_Operator > create_W() const
Teuchos::RCP< const Epetra_Map > get_p_map(int p) const
Teuchos::RCP< const Epetra_Map > get_g_map(int p) const
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
#define W
Teuchos::RCP< const Epetra_Map > get_x_map() const
void set_XyceModelEvaluator(const RCP< Analysis::ModelEvaluator > &xyceME)