40 #include <Xyce_config.h>
43 #include <N_CIR_Xyce.h>
44 #include <N_LAS_Vector.h>
45 #include <N_LAS_BlockVector.h>
46 #include <N_LAS_BlockMatrix.h>
47 #include <N_LAS_BlockSystemHelpers.h>
48 #include <N_PDS_ParMap.h>
50 #include <Epetra_Map.h>
51 #include <Epetra_Vector.h>
52 #include <Epetra_CrsGraph.h>
53 #include <Epetra_CrsMatrix.h>
54 #include <Epetra_Operator.h>
57 using Teuchos::is_null;
63 const RCP<const Epetra_Vector>& vec,
64 const RCP<N_PDS_ParMap> & map
68 int Nv = vec->GlobalLength();
69 int Nm = map->numGlobalEntities();
70 TEUCHOS_TEST_FOR_EXCEPTION( Nv != 2*Nm, std::logic_error,
71 "Error! The size of the vector must be twice the size of the map!"
73 Epetra_Vector* nonconst_vec =
const_cast<Epetra_Vector*
>(&*vec);
74 RCP<Linear::BlockVector> nlasBlockVec = rcp(
new Linear::BlockVector( nonconst_vec, map, 2,
false ));
80 const RCP<const Epetra_Vector>& vec
83 Epetra_Vector* nonconst_vec =
const_cast<Epetra_Vector*
>(&*vec);
84 RCP<Linear::Vector> nlasVec = rcp(
new Linear::Vector( nonconst_vec,
false ));
90 :isInitialized_(false)
97 xycePtr_ = rcp(
new Circuit::Simulator());
99 xycePtr_->initializeTransientModel();
114 eVec_->putScalar(1.0);
133 return xycePtr_->getVariableNames();
141 EpetraExt::ModelEvaluator::InArgsSetup inArgs;
142 inArgs.setSupports(IN_ARG_t,
true);
143 inArgs.setSupports(IN_ARG_x,
true);
144 inArgs.setSupports(IN_ARG_x_dot,
true);
145 inArgs.setSupports(IN_ARG_alpha,
true);
146 inArgs.setSupports(IN_ARG_beta,
true);
150 EpetraExt::ModelEvaluator::OutArgsSetup outArgs;
151 outArgs.setSupports(OUT_ARG_f,
true);
152 outArgs.setSupports(OUT_ARG_W,
true);
153 outArgs.set_Np_Ng(
Np_,
Ng_);
164 int BlockSize =
x_map_->numGlobalEntities();
169 rcp(
new Epetra_CrsGraph(
171 *(
x_map_->petraBlockMap()),
179 std::vector<int> Indices;
180 Indices.resize(MaxIndices+1);
183 for(
int j = 0; j < BlockSize; ++j )
185 BaseRow =
x_map_->localToGlobalIndex(j);
186 dFdx_graph_->ExtractGlobalRowCopy( BaseRow, MaxIndices, NumIndices, &Indices[0] );
188 Indices[NumIndices] = BaseRow;
210 return rcp(
blockMap_->petraMap(), false );
216 return rcp(
blockMap_->petraMap(), false );
222 TEUCHOS_ASSERT( ((0 <= p) && (p <
Np_)) );
223 return Teuchos::rcpFromRef(*
s_map_->petraMap());
229 TEUCHOS_ASSERT( ((0 <= p) && (p <
Ng_)) );
231 return Teuchos::rcpFromRef(*
s_map_->petraMap());
234 return rcp(
blockMap_->petraMap(), false );
237 return rcp(
blockMap_->petraMap(), false );
239 return Teuchos::null;
245 return Teuchos::rcpFromRef(*
x_map_->petraMap());
252 "Error! Please call initialize before evalModel"
255 double t = inArgs.get_t();
256 RCP<const Epetra_Vector> x_in = inArgs.get_x().assert_not_null();
257 RCP<const Epetra_Vector> xdot_in = inArgs.get_x_dot().assert_not_null();
258 RCP<Epetra_Vector> s_out = outArgs.get_g(0);
259 RCP<Epetra_Vector> store_out = outArgs.get_g(0);
265 Linear::Vector & x = xyce_x->block(0);
266 Linear::Vector & z = xyce_x->block(1);
267 Linear::Vector & xdot = xyce_xdot->block(0);
268 Linear::Vector & zdot = xyce_xdot->block(1);
273 x_gnd_->update(1.0,x,0.0);
274 z_gnd_->update(1.0,z,0.0);
278 Linear::Vector & x_ref = *
x_gnd_;
279 Linear::Vector & z_ref = *
z_gnd_;
283 if (!Teuchos::is_null(s_out)) {
286 Linear::Vector & s_out = *xyce_s_out;
289 Linear::Vector & store_out = *xyce_store_out;
300 double alpha = inArgs.get_alpha();
301 double beta = inArgs.get_beta();
302 RCP<const Epetra_Vector> s_in = inArgs.get_p(0).assert_not_null();
303 RCP<const Epetra_Vector> sdot_in = inArgs.get_p(1).assert_not_null();
305 RCP<Epetra_Vector> f_out = outArgs.get_f().assert_not_null();
306 RCP<Epetra_Operator> W_out = outArgs.get_W().assert_not_null();
307 RCP<Linear::BlockMatrix> bMat;
310 RCP<Epetra_CrsMatrix> crsMat = Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(W_out,
true);
311 std::string label =
"Linear::BlockMatrix";
312 bMat = Teuchos::get_extra_data<RCP<Linear::BlockMatrix> >(crsMat,label);
327 RCP<Epetra_Vector> voltLimQVector = outArgs.get_g(1);
328 RCP<Epetra_Vector> voltLimFVector = outArgs.get_g(2);
336 RCP<Linear::Vector> xyce_voltLimQ;
337 if (Teuchos::is_null(voltLimQVector)) {
346 RCP<Linear::Vector> xyce_voltLimF;
347 if (Teuchos::is_null(voltLimFVector)) {
356 Linear::Vector & s = *xyce_s;
357 Linear::Vector & store = *xyce_store;
358 Linear::Vector & sdot = *xyce_sdot;
359 Linear::Vector & f_0 = xyce_f->block(0);
360 Linear::Vector & f_1 = xyce_f->block(1);
365 Linear::Vector & f_0_ref = *
f_0_gnd_;
366 Linear::Vector & f_1_ref = *
f_1_gnd_;
367 Linear::Vector & voltLimQ_ref = *xyce_voltLimQ;
368 Linear::Vector & voltLimF_ref = *xyce_voltLimF;
404 f_0_ref.update(1.0,zdot_ref,+1.0);
405 f_1_ref.update(-1.0,z_ref,1.0);
408 f_0.update(1.0,f_0_ref,0.0);
409 f_1.update(1.0,f_1_ref,0.0);
415 Linear::Matrix & ul = bMat->block(0,0);
419 Linear::Matrix & ll = bMat->block(1,0);
423 Linear::Matrix & ur = bMat->block(0,1);
424 Linear::Matrix & lr = bMat->block(1,1);
427 ur.replaceDiagonal(*
eVec_);
429 lr.replaceDiagonal(*
eVec_);
433 bMat->assembleGlobalMatrix();
443 std::vector< std::vector<int> > Cols;
445 for (
int i=0 ; i<Size ; ++i) {
446 Cols[i].resize(Size);
447 for (
int j=0 ; j<Size ; ++j) {
452 int MaxGID =
x_map_->maxGlobalEntity();
454 while ( offset <= MaxGID ) offset *= 10;
459 RCP<Linear::BlockMatrix> bMat = rcp(
new Linear::BlockMatrix( Size, offset, Cols, *blockGraph, *
dFdx_graph_with_diagonal_ ) );
463 Epetra_CrsMatrix & crsMat = bMat->epetraObj();
466 RCP<Epetra_CrsMatrix> outMatrix = rcp(&crsMat,
false);
467 std::string label =
"Linear::BlockMatrix";
468 Teuchos::set_extra_data( bMat, label, Teuchos::outArg(outMatrix) );
EpetraExt::ModelEvaluator::InArgs createInArgs() const
Teuchos::RCP< const Epetra_Map > get_p_map(int p) const
RCP< N_PDS_ParMap > blockMap_
RCP< Linear::Vector > convertEpetraToNLASVectorView(const RCP< const Epetra_Vector > &vec)
virtual ~ModelEvaluator()
RCP< Linear::Vector > x_gnd_
RCP< Epetra_CrsGraph > dFdx_graph_
EpetraExt::ModelEvaluator::OutArgs outArgs_
Pure virtual class to augment a linear system.
RCP< Linear::Vector > zdot_gnd_
RCP< Linear::Vector > z_gnd_
RCP< Linear::Vector > xdot_gnd_
Teuchos::RCP< Epetra_Operator > create_W() const
EpetraExt::ModelEvaluator::InArgs inArgs_
RCP< Epetra_CrsGraph > dQdx_graph_
RCP< Circuit::Simulator > xycePtr_
void initialize(int iargs, char *cargs[])
RCP< Linear::Matrix > dQdx_gnd_matrix_
std::vector< std::string > getVariableNames()
RCP< Linear::Vector > tempVoltLimFVector_
Teuchos::RCP< const Epetra_Map > get_f_map() const
RCP< Linear::Vector > tempVoltLimQVector_
void setupMapsAndGraphs_()
RCP< Linear::Vector > f_0_gnd_
Teuchos::RCP< const Epetra_Map > get_small_x_map() const
RCP< Epetra_CrsGraph > dFdx_ognd_graph_
RCP< Epetra_CrsGraph > dQdx_ognd_graph_
EpetraExt::ModelEvaluator::OutArgs createOutArgs() const
Teuchos::RCP< const Epetra_Map > get_g_map(int p) const
RCP< N_PDS_ParMap > x_map_
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
RCP< Linear::BlockVector > convertEpetraToNLASBlockVectorView(const RCP< const Epetra_Vector > &vec, const RCP< Epetra_Map > &map)
RCP< N_PDS_ParMap > x_ognd_map_
Teuchos::RCP< const Epetra_Map > get_x_map() const
bool isInitialized() const
RCP< Epetra_CrsGraph > dFdx_graph_with_diagonal_
RCP< Linear::Matrix > dFdx_gnd_matrix_
RCP< N_PDS_ParMap > s_map_
RCP< Linear::Vector > eVec_
RCP< N_PDS_ParMap > store_map_
RCP< Linear::Vector > f_1_gnd_