40 #include <Xyce_config.h>
43 #include <N_LAS_Vector.h>
44 #include <N_LAS_BlockVector.h>
45 #include <N_LAS_BlockMatrix.h>
46 #include <N_LAS_BlockSystemHelpers.h>
47 #include <N_PDS_ParMap.h>
49 #include <Epetra_Map.h>
50 #include <Epetra_Vector.h>
51 #include <Epetra_CrsGraph.h>
52 #include <Epetra_CrsMatrix.h>
53 #include <Epetra_Operator.h>
56 using Teuchos::is_null;
62 const RCP<const Epetra_Vector>& vec,
63 const RCP<N_PDS_ParMap> & map
67 int Nv = vec->GlobalLength();
68 int Nm = map->numGlobalEntities();
69 TEUCHOS_TEST_FOR_EXCEPTION( Nv != 2*Nm, std::logic_error,
70 "Error! The size of the vector must be twice the size of the map!"
72 Epetra_Vector* nonconst_vec =
const_cast<Epetra_Vector*
>(&*vec);
73 RCP<N_LAS_BlockVector> nlasBlockVec = rcp(
new N_LAS_BlockVector( nonconst_vec, map, 2,
false ));
79 const RCP<const Epetra_Vector>& vec
82 Epetra_Vector* nonconst_vec =
const_cast<Epetra_Vector*
>(&*vec);
83 RCP<N_LAS_Vector> nlasVec = rcp(
new N_LAS_Vector( nonconst_vec,
false ));
89 :isInitialized_(false)
98 xycePtr_->initializeTransientModel();
113 eVec_->putScalar(1.0);
132 return xycePtr_->getVariableNames();
140 EpetraExt::ModelEvaluator::InArgsSetup inArgs;
141 inArgs.setSupports(IN_ARG_t,
true);
142 inArgs.setSupports(IN_ARG_x,
true);
143 inArgs.setSupports(IN_ARG_x_dot,
true);
144 inArgs.setSupports(IN_ARG_alpha,
true);
145 inArgs.setSupports(IN_ARG_beta,
true);
149 EpetraExt::ModelEvaluator::OutArgsSetup outArgs;
150 outArgs.setSupports(OUT_ARG_f,
true);
151 outArgs.setSupports(OUT_ARG_W,
true);
152 outArgs.set_Np_Ng(
Np_,
Ng_);
163 int BlockSize =
x_map_->numGlobalEntities();
168 rcp(
new Epetra_CrsGraph(
170 *(
x_map_->petraBlockMap()),
178 std::vector<int> Indices;
179 Indices.resize(MaxIndices+1);
182 for(
int j = 0; j < BlockSize; ++j )
184 BaseRow =
x_map_->localToGlobalIndex(j);
185 dFdx_graph_->ExtractGlobalRowCopy( BaseRow, MaxIndices, NumIndices, &Indices[0] );
187 Indices[NumIndices] = BaseRow;
209 return rcp(
blockMap_->petraMap(), false );
215 return rcp(
blockMap_->petraMap(), false );
221 TEUCHOS_ASSERT( ((0 <= p) && (p <
Np_)) );
222 return Teuchos::rcpFromRef(*
s_map_->petraMap());
228 TEUCHOS_ASSERT( ((0 <= p) && (p <
Ng_)) );
230 return Teuchos::rcpFromRef(*
s_map_->petraMap());
233 return rcp(
blockMap_->petraMap(), false );
236 return rcp(
blockMap_->petraMap(), false );
238 return Teuchos::null;
244 return Teuchos::rcpFromRef(*
x_map_->petraMap());
251 "Error! Please call initialize before evalModel"
254 double t = inArgs.get_t();
255 RCP<const Epetra_Vector> x_in = inArgs.get_x().assert_not_null();
256 RCP<const Epetra_Vector> xdot_in = inArgs.get_x_dot().assert_not_null();
257 RCP<Epetra_Vector> s_out = outArgs.get_g(0);
258 RCP<Epetra_Vector> store_out = outArgs.get_g(0);
264 N_LAS_Vector & x = xyce_x->block(0);
265 N_LAS_Vector & z = xyce_x->block(1);
266 N_LAS_Vector & xdot = xyce_xdot->block(0);
267 N_LAS_Vector & zdot = xyce_xdot->block(1);
272 x_gnd_->update(1.0,x,0.0);
273 z_gnd_->update(1.0,z,0.0);
277 N_LAS_Vector & x_ref = *
x_gnd_;
278 N_LAS_Vector & z_ref = *
z_gnd_;
282 if (!Teuchos::is_null(s_out)) {
285 N_LAS_Vector & s_out = *xyce_s_out;
288 N_LAS_Vector & store_out = *xyce_store_out;
299 double alpha = inArgs.get_alpha();
300 double beta = inArgs.get_beta();
301 RCP<const Epetra_Vector> s_in = inArgs.get_p(0).assert_not_null();
302 RCP<const Epetra_Vector> sdot_in = inArgs.get_p(1).assert_not_null();
304 RCP<Epetra_Vector> f_out = outArgs.get_f().assert_not_null();
305 RCP<Epetra_Operator> W_out = outArgs.get_W().assert_not_null();
306 RCP<N_LAS_BlockMatrix> bMat;
309 RCP<Epetra_CrsMatrix> crsMat = Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(W_out,
true);
310 std::string label =
"N_LAS_BlockMatrix";
311 bMat = Teuchos::get_extra_data<RCP<N_LAS_BlockMatrix> >(crsMat,label);
326 RCP<Epetra_Vector> voltLimQVector = outArgs.get_g(1);
327 RCP<Epetra_Vector> voltLimFVector = outArgs.get_g(2);
335 RCP<N_LAS_Vector> xyce_voltLimQ;
336 if (Teuchos::is_null(voltLimQVector)) {
345 RCP<N_LAS_Vector> xyce_voltLimF;
346 if (Teuchos::is_null(voltLimFVector)) {
355 N_LAS_Vector & s = *xyce_s;
356 N_LAS_Vector & store = *xyce_store;
357 N_LAS_Vector & sdot = *xyce_sdot;
358 N_LAS_Vector & f_0 = xyce_f->block(0);
359 N_LAS_Vector & f_1 = xyce_f->block(1);
366 N_LAS_Vector & voltLimQ_ref = *xyce_voltLimQ;
367 N_LAS_Vector & voltLimF_ref = *xyce_voltLimF;
395 f_0_ref.update(1.0,zdot_ref,+1.0);
396 f_1_ref.update(-1.0,z_ref,1.0);
399 f_0.update(1.0,f_0_ref,0.0);
400 f_1.update(1.0,f_1_ref,0.0);
406 N_LAS_Matrix & ul = bMat->block(0,0);
410 N_LAS_Matrix & ll = bMat->block(1,0);
414 N_LAS_Matrix & ur = bMat->block(0,1);
415 N_LAS_Matrix & lr = bMat->block(1,1);
418 ur.replaceDiagonal(*
eVec_);
420 lr.replaceDiagonal(*
eVec_);
424 bMat->assembleGlobalMatrix();
436 std::vector< std::vector<int> > Cols;
438 for (
int i=0 ; i<Size ; ++i) {
439 Cols[i].resize(Size);
440 for (
int j=0 ; j<Size ; ++j) {
445 int MaxGID =
x_map_->maxGlobalEntity();
447 while ( offset <= MaxGID ) offset *= 10;
452 RCP<N_LAS_BlockMatrix> bMat = rcp(
new N_LAS_BlockMatrix( Size, offset, Cols, *blockGraph, *
dFdx_graph_with_diagonal_ ) );
456 Epetra_CrsMatrix & crsMat = bMat->epetraObj();
459 RCP<Epetra_CrsMatrix> outMatrix = rcp(&crsMat,
false);
460 std::string label =
"N_LAS_BlockMatrix";
461 Teuchos::set_extra_data( bMat, label, Teuchos::outArg(outMatrix) );