Debian Codegraph @

packages/panzer/disc-fe/test/la_factory/tTpetraLinearObjFactory.cpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10
11 #include <Teuchos_ConfigDefs.hpp>
12 #include <Teuchos_UnitTestHarness.hpp>
13 #include <Teuchos_RCP.hpp>
14 #include <Teuchos_TimeMonitor.hpp>
15
16 #include <string>
17 #include <iostream>
18
19 #include "Panzer_TpetraLinearObjFactory.hpp"
20 #include "Panzer_Traits.hpp"
21
22 // for testing gather/scatter construction
23 #include "Panzer_PureBasis.hpp"
24 #include "Panzer_IntegrationRule.hpp"
25 #include "Panzer_CellData.hpp"
26 #include "Panzer_PauseToAttach.hpp"
27
28 #include "UnitTest_GlobalIndexer.hpp"
29
30 #ifdef HAVE_MPI
31 #include "Teuchos_DefaultMpiComm.hpp"
32 #else
33 #include "NO_SERIAL_BUILD.h"
34 #endif
35
36 #include "Tpetra_Map.hpp"
37 #include "Tpetra_MultiVector.hpp"
38
39 #include "Thyra_TpetraThyraWrappers.hpp"
40
41 using Teuchos::rcp;
42 using Teuchos::rcp_dynamic_cast;
43 using Teuchos::RCP;
44 using Teuchos::rcpFromRef;
45
46 typedef Tpetra::MultiVector<double,int,panzer::GlobalOrdinal> MultiVector;
47 typedef Tpetra::Vector<double,int,panzer::GlobalOrdinal> Vector;
48 typedef Tpetra::CrsMatrix<double,int,panzer::GlobalOrdinal> CrsMatrix;
49 typedef Tpetra::CrsGraph<int,panzer::GlobalOrdinal> CrsGraph;
50 typedef Tpetra::Map<int,panzer::GlobalOrdinal> Map;
51
52 namespace panzer {
53
54 /*
55 RCP<MultiVector> getTpetraMultiVector(RCP<Thyra::MultiVectorBase<double> > & vec,const Map & map)
56 {
57 return Thyra::get_Tpetra_MultiVector<double,int,int>(map,vec);
58 }
59 */
60
61 TEUCHOS_UNIT_TEST(tTpetraLinearObjFactory, gather_scatter_constr)
62 {
63
64 // build global (or serial communicator)
65 #ifdef HAVE_MPI
66 Teuchos::RCP<Teuchos::Comm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(Teuchos::opaqueWrapper(MPI_COMM_WORLD)));
67 #else
68 Teuchos::RCP<Teuchos::Comm<int> > failure_comm = THIS_,_SERIAL_BUILDS_,_SHOULD_FAIL;
69 #endif
70
71 using Teuchos::RCP;
72 using Teuchos::rcp;
73 using Teuchos::rcp_dynamic_cast;
74
75 int myRank = tComm->getRank();
76 int numProc = tComm->getSize();
77
78 // panzer::pauseToAttach();
79
80 RCP<panzer::GlobalIndexer> indexer
81 = rcp(new unit_test::GlobalIndexer(myRank,numProc));
82
83 // setup factory
84 Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > la_factory
85 = Teuchos::rcp(new panzer::TpetraLinearObjFactory<panzer::Traits,double,int,panzer::GlobalOrdinal>(tComm.getConst(),indexer));
86
87 // build parameter lists for gather and scatters
88 //////////////////////////////////////////////////////////////////
89 std::size_t numCells = 10;
90
91 Teuchos::ParameterList gatherParams;
92 {
93 Teuchos::RCP<shards::CellTopology> topo =
94 Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >()));
95
96 // auxiliary information needed to construct basis object
97 std::string basisType = "Q1";
98 panzer::CellData cellData(numCells,topo);
99
100 // build DOF names
101 RCP<std::vector<std::string> > dofNames = rcp(new std::vector<std::string>);
102 dofNames->push_back("ux"); // in practice these probably would not be gathered together!
103 dofNames->push_back("p");
104
105 // build basis
106 RCP<panzer::PureBasis> basis = rcp(new panzer::PureBasis(basisType,1,cellData));
107
108 // build gather parameter list
109 gatherParams.set<RCP<std::vector<std::string> > >("DOF Names",dofNames);
110 gatherParams.set<RCP<std::vector<std::string> > >("Indexer Names",dofNames);
111 gatherParams.set<RCP<panzer::PureBasis> >("Basis",basis);
112 }
113
114 Teuchos::ParameterList scatterParams;
115 {
116 Teuchos::RCP<shards::CellTopology> topo =
117 Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >()));
118
119 std::string basisType = "Q1";
120 panzer::CellData cellData(numCells,topo);
121
122 // build basis
123 RCP<const panzer::PureBasis> basis = rcp(new panzer::PureBasis(basisType,1,cellData));
124
125 std::string scatterName = "Residual_NS";
126
127 // build DOF names
128 RCP<std::vector<std::string> > evaluatedNames = rcp(new std::vector<std::string>);
129 evaluatedNames->push_back("Residual_ux"); // in practice these probably would not be scattered together!
130 evaluatedNames->push_back("Residual_p");
131
132 // build evaluated map
133 RCP<std::map<std::string,std::string> > evaluatedMap = rcp(new std::map<std::string,std::string>);
134 evaluatedMap->insert(std::make_pair("Residual_ux","ux")); // in practice these probably would not be scattered together!
135 evaluatedMap->insert(std::make_pair("Residual_p","p"));
136
137 // build scatter parameter list
138 scatterParams.set<std::string>("Scatter Name",scatterName);
139 scatterParams.set<RCP<std::vector<std::string> > >("Dependent Names",evaluatedNames);
140 scatterParams.set<RCP<std::map<std::string,std::string> > >("Dependent Map",evaluatedMap);
141 scatterParams.set("Basis",basis);
142 }
143
144 Teuchos::ParameterList scatterDirichletParams;
145 {
146 Teuchos::RCP<shards::CellTopology> topo =
147 Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >()));
148
149 std::string basisType = "Q1";
150 panzer::CellData cellData(numCells,topo);
151
152 // build basis
153 RCP<panzer::PureBasis> basis = rcp(new panzer::PureBasis(basisType,1,cellData));
154
155 std::string scatterName = "Residual_NS";
156
157 // build DOF names
158 RCP<std::vector<std::string> > evaluatedNames = rcp(new std::vector<std::string>);
159 evaluatedNames->push_back("Residual_ux"); // in practice these probably would not be scattered together!
160 evaluatedNames->push_back("Residual_p");
161
162 // build evaluated map
163 RCP<std::map<std::string,std::string> > evaluatedMap = rcp(new std::map<std::string,std::string>);
164 evaluatedMap->insert(std::make_pair("Residual_ux","ux")); // in practice these probably would not be scattered together!
165 evaluatedMap->insert(std::make_pair("Residual_p","p"));
166
167 // build scatter parameter list
168 scatterDirichletParams.set<std::string>("Scatter Name",scatterName);
169 scatterDirichletParams.set<RCP<std::vector<std::string> > >("Dependent Names",evaluatedNames);
170 scatterDirichletParams.set<RCP<std::map<std::string,std::string> > >("Dependent Map",evaluatedMap);
171 scatterDirichletParams.set<RCP<panzer::PureBasis> >("Basis",basis);
172 scatterDirichletParams.set<int>("Side Subcell Dimension",1);
173 scatterDirichletParams.set<int>("Local Side ID",2);
174 scatterDirichletParams.set("Check Apply BC",false);
175 }
176
177 // Evaluator construction tests
178 ///////////////////////////////////////////////////////
179 RCP<PHX::Evaluator<panzer::Traits> > evaluator;
180
181 {
182 typedef panzer::Traits::Residual EvalType;
183
184 // gather test
185 {
186 evaluator = la_factory->buildGather<EvalType>(gatherParams);
187
188 TEST_ASSERT(evaluator!=Teuchos::null);
189 RCP<GatherSolution_Tpetra<EvalType,panzer::Traits,int,panzer::GlobalOrdinal> > gatherSolutionEval
190 = rcp_dynamic_cast<GatherSolution_Tpetra<EvalType,panzer::Traits,int,panzer::GlobalOrdinal> >(evaluator);
191 TEST_ASSERT(gatherSolutionEval!=Teuchos::null);
192
193 const std::vector<RCP<PHX::FieldTag> > & fields = gatherSolutionEval->evaluatedFields();
194 TEST_EQUALITY(fields.size(),2);
195
196 TEST_EQUALITY(fields[0]->name(),"ux");
197 TEST_EQUALITY(fields[1]->name(),"p");
198
199 TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
200 TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
201
202 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
203 TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
204 }
205
206 // scatter test
207 {
208 evaluator = la_factory->buildScatter<EvalType>(scatterParams);
209
210 out << "SCATTER RES NAME: \"" << evaluator->getName() << "\"" << std::endl;
211 TEST_ASSERT(evaluator!=Teuchos::null);
212 RCP<ScatterResidual_Tpetra<EvalType,panzer::Traits,int,panzer::GlobalOrdinal> > scatterResidual
213 = rcp_dynamic_cast<ScatterResidual_Tpetra<EvalType,panzer::Traits,int,panzer::GlobalOrdinal> >(evaluator);
214 TEST_ASSERT(scatterResidual!=Teuchos::null);
215
216 const std::vector<RCP<PHX::FieldTag> > & evalFields = scatterResidual->evaluatedFields();
217 TEST_EQUALITY(evalFields.size(),1); // this is a dummy holder for the sake of the field manager
218
219 const std::vector<RCP<PHX::FieldTag> > & fields = scatterResidual->dependentFields();
220 TEST_EQUALITY(fields.size(),2); // these store the residual values
221
222 TEST_EQUALITY(fields[0]->name(),"Residual_ux");
223 TEST_EQUALITY(fields[1]->name(),"Residual_p");
224
225 TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
226 TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
227
228 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
229 TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
230 }
231
232 // scatter dirichlet test
233 {
234 evaluator = la_factory->buildScatterDirichlet<EvalType>(scatterDirichletParams);
235
236 out << "SCATTER DIRICHLET RES NAME: \"" << evaluator->getName() << "\"" << std::endl;
237 TEST_ASSERT(evaluator!=Teuchos::null);
238 RCP<ScatterDirichletResidual_Tpetra<EvalType,panzer::Traits,int,panzer::GlobalOrdinal> > scatterResidual
239 = rcp_dynamic_cast<ScatterDirichletResidual_Tpetra<EvalType,panzer::Traits,int,panzer::GlobalOrdinal> >(evaluator);
240 TEST_ASSERT(scatterResidual!=Teuchos::null);
241
242 const std::vector<RCP<PHX::FieldTag> > & evalFields = scatterResidual->evaluatedFields();
243 TEST_EQUALITY(evalFields.size(),1); // this is a dummy holder for the sake of the field manager
244
245 const std::vector<RCP<PHX::FieldTag> > & fields = scatterResidual->dependentFields();
246 TEST_EQUALITY(fields.size(),2); // these store the residual values
247
248 TEST_EQUALITY(fields[0]->name(),"Residual_ux");
249 TEST_EQUALITY(fields[1]->name(),"Residual_p");
250
251 TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
252 TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
253
254 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
255 TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
256 }
257 }
258
259 {
260 typedef panzer::Traits::Jacobian EvalType;
261
262 // gather test
263 {
264 evaluator = la_factory->buildGather<EvalType>(gatherParams);
265
266 TEST_ASSERT(evaluator!=Teuchos::null);
267 RCP<GatherSolution_Tpetra<EvalType,panzer::Traits,int,panzer::GlobalOrdinal> > gatherSolutionEval
268 = rcp_dynamic_cast<GatherSolution_Tpetra<EvalType,panzer::Traits,int,panzer::GlobalOrdinal> >(evaluator);
269 TEST_ASSERT(gatherSolutionEval!=Teuchos::null);
270
271 const std::vector<RCP<PHX::FieldTag> > & fields = gatherSolutionEval->evaluatedFields();
272 TEST_EQUALITY(fields.size(),2);
273
274 TEST_EQUALITY(fields[0]->name(),"ux");
275 TEST_EQUALITY(fields[1]->name(),"p");
276
277 TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
278 TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
279
280 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
281 TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
282 }
283
284 // scatter test
285 {
286 evaluator = la_factory->buildScatter<EvalType>(scatterParams);
287
288 TEST_ASSERT(evaluator!=Teuchos::null);
289 RCP<ScatterResidual_Tpetra<EvalType,panzer::Traits,int,panzer::GlobalOrdinal> > scatterResidual
290 = rcp_dynamic_cast<ScatterResidual_Tpetra<EvalType,panzer::Traits,int,panzer::GlobalOrdinal> >(evaluator);
291 TEST_ASSERT(scatterResidual!=Teuchos::null);
292
293 const std::vector<RCP<PHX::FieldTag> > & evalFields = scatterResidual->evaluatedFields();
294 TEST_EQUALITY(evalFields.size(),1); // this is a dummy holder for the sake of the field manager
295
296 const std::vector<RCP<PHX::FieldTag> > & fields = scatterResidual->dependentFields();
297 TEST_EQUALITY(fields.size(),2); // these store the residual values
298
299 TEST_EQUALITY(fields[0]->name(),"Residual_ux");
300 TEST_EQUALITY(fields[1]->name(),"Residual_p");
301
302 TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
303 TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
304
305 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
306 TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
307 }
308
309 // scatter dirichlet test
310 {
311 evaluator = la_factory->buildScatterDirichlet<EvalType>(scatterDirichletParams);
312
313 out << "SCATTER DIRICHLET RES NAME: \"" << evaluator->getName() << "\"" << std::endl;
314 TEST_ASSERT(evaluator!=Teuchos::null);
315 RCP<ScatterDirichletResidual_Tpetra<EvalType,panzer::Traits,int,panzer::GlobalOrdinal> > scatterResidual
316 = rcp_dynamic_cast<ScatterDirichletResidual_Tpetra<EvalType,panzer::Traits,int,panzer::GlobalOrdinal> >(evaluator);
317 TEST_ASSERT(scatterResidual!=Teuchos::null);
318
319 const std::vector<RCP<PHX::FieldTag> > & evalFields = scatterResidual->evaluatedFields();
320 TEST_EQUALITY(evalFields.size(),1); // this is a dummy holder for the sake of the field manager
321
322 const std::vector<RCP<PHX::FieldTag> > & fields = scatterResidual->dependentFields();
323 TEST_EQUALITY(fields.size(),2); // these store the residual values
324
325 TEST_EQUALITY(fields[0]->name(),"Residual_ux");
326 TEST_EQUALITY(fields[1]->name(),"Residual_p");
327
328 TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
329 TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
330
331 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
332 TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
333 }
334 }
335 }
336
337 TEUCHOS_UNIT_TEST(tTpetraLinearObjFactory, adjustDirichlet)
338 {
339
340 // build global (or serial communicator)
341 #ifdef HAVE_MPI
342 Teuchos::RCP<Teuchos::Comm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(Teuchos::opaqueWrapper(MPI_COMM_WORLD)));
343 #else
344 Teuchos::RCP<Teuchos::Comm<int> > failure_comm = THIS_,_SERIAL_BUILDS_,_SHOULD_FAIL;
345 #endif
346
347 using Teuchos::RCP;
348 using Teuchos::rcp;
349 using Teuchos::rcp_dynamic_cast;
350
351 int myRank = tComm->getRank();
352 int numProc = tComm->getSize();
353
354 typedef TpetraLinearObjContainer<double,int,panzer::GlobalOrdinal> LOC;
355
356 RCP<panzer::GlobalIndexer> indexer
357 = rcp(new unit_test::GlobalIndexer(myRank,numProc));
358
359 // setup factory
360 Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > la_factory
361 = Teuchos::rcp(new panzer::TpetraLinearObjFactory<panzer::Traits,double,int,panzer::GlobalOrdinal>(tComm.getConst(),indexer));
362
363 RCP<LinearObjContainer> ghosted_0 = la_factory->buildGhostedLinearObjContainer();
364 RCP<LinearObjContainer> ghosted_1 = la_factory->buildGhostedLinearObjContainer();
365 RCP<LinearObjContainer> ghosted_sys = la_factory->buildGhostedLinearObjContainer();
366
367 la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_0);
368 la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_1);
369 la_factory->initializeGhostedContainer(LinearObjContainer::F | LinearObjContainer::Mat,*ghosted_sys);
370
371 RCP<LOC> t_0 = rcp_dynamic_cast<LOC>(ghosted_0);
372 RCP<LOC> t_1 = rcp_dynamic_cast<LOC>(ghosted_1);
373 RCP<LOC> t_sys = rcp_dynamic_cast<LOC>(ghosted_sys);
374
375 Teuchos::ArrayRCP<double> x_0_a = t_0->get_f()->get1dViewNonConst();
376 Teuchos::ArrayRCP<double> x_1_a = t_1->get_f()->get1dViewNonConst();
377 Teuchos::ArrayRCP<double> f_a = t_sys->get_f()->get1dViewNonConst();
378
379 TEST_ASSERT(!Teuchos::is_null(t_0->get_f()));
380 TEST_ASSERT(!Teuchos::is_null(t_1->get_f()));
381 TEST_ASSERT(!Teuchos::is_null(t_sys->get_f()));
382 TEST_ASSERT(!Teuchos::is_null(t_sys->get_A()));
383
384 t_sys->get_f()->putScalar(-3.0); // put some garbage in the systems
385 t_sys->get_A()->setAllToScalar(-3.0);
386
387 // there are 3 cases for adjustDirichlet
388 // 1. Local set only for GID
389 // 2. Set on multiple processors
390 // 3. Set remotely
391
392 if(myRank==0) {
393 // case 0
394 x_0_a[0] = 1.0; // GID = 0
395 x_1_a[0] = 1.0; // GID = 0
396
397 // case 1
398 x_0_a[2] = 1.0; // GID = 2
399 x_1_a[2] = 2.0; // GID = 2
400
401 // case 2
402 x_1_a[5] = 2.0; // GID = 5
403 }
404 else if(myRank==1) {
405 // case 0
406 x_0_a[3] = 1.0; // GID = 9
407 x_1_a[3] = 1.0; // GID = 9
408
409 // case 1
410 x_0_a[0] = 1.0; // GID = 2
411 x_1_a[0] = 2.0; // GID = 2
412
413 // case 2
414 x_1_a[6] = 2.0; // GID = 4
415 }
416 else
417 TEUCHOS_ASSERT(false);
418
419 // run test for conditions
420 la_factory->beginFill(*ghosted_sys);
421 la_factory->adjustForDirichletConditions(*ghosted_0,*ghosted_1,*ghosted_sys);
422 la_factory->endFill(*ghosted_sys);
423
424 std::size_t sz = t_sys->get_A()->getLocalMaxNumRowEntries();
425 std::size_t numEntries = 0;
426 typename CrsMatrix::nonconst_local_inds_host_view_type indices("indices", sz);
427 typename CrsMatrix::nonconst_values_host_view_type values("values", sz);
428
429 if(myRank==0) {
430 TEST_EQUALITY(f_a[0],-3.0); // case 0
431 t_sys->get_A()->getLocalRowCopy(0,indices,values,numEntries);
432 for(std::size_t i=0;i<numEntries;i++) TEST_EQUALITY(values[i],-3.0);
433
434 TEST_EQUALITY(f_a[2],-3.0/2.0); // case 1
435 t_sys->get_A()->getLocalRowCopy(2,indices,values,numEntries);
436 for(std::size_t i=0;i<numEntries;i++) TEST_EQUALITY(values[i],-3.0/2.0);
437
438 TEST_EQUALITY(f_a[5],0.0); // case 2
439 t_sys->get_A()->getLocalRowCopy(5,indices,values,numEntries);
440 for(std::size_t i=0;i<numEntries;i++) TEST_EQUALITY(values[i],0.0);
441 }
442 else if(myRank==1) {
443 TEST_EQUALITY(f_a[3],-3.0); // case 0
444 t_sys->get_A()->getLocalRowCopy(3,indices,values,numEntries);
445 for(std::size_t i=0;i<numEntries;i++) TEST_EQUALITY(values[i],-3.0);
446
447 TEST_EQUALITY(f_a[0],-3.0/2.0); // case 1
448 t_sys->get_A()->getLocalRowCopy(0,indices,values,numEntries);
449 for(std::size_t i=0;i<numEntries;i++) TEST_EQUALITY(values[i],-3.0/2.0);
450
451 TEST_EQUALITY(f_a[6],0.0); // case 2
452 t_sys->get_A()->getLocalRowCopy(6,indices,values,numEntries);
453 for(std::size_t i=0;i<numEntries;i++) TEST_EQUALITY(values[i],0.0);
454 }
455 else
456 TEUCHOS_ASSERT(false);
457 }
458
459 TEUCHOS_UNIT_TEST(tTpetraLinearObjFactory, initializeContainer)
460 {
461
462 // build global (or serial communicator)
463 #ifdef HAVE_MPI
464 Teuchos::RCP<Teuchos::Comm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(Teuchos::opaqueWrapper(MPI_COMM_WORLD)));
465 #else
466 Teuchos::RCP<Teuchos::Comm<int> > failure_comm = THIS_,_SERIAL_BUILDS_,_SHOULD_FAIL;
467 #endif
468
469 using Teuchos::RCP;
470 using Teuchos::rcp;
471 using Teuchos::rcp_dynamic_cast;
472
473 int myRank = tComm->getRank();
474 int numProc = tComm->getSize();
475
476 typedef TpetraLinearObjContainer<double,int,panzer::GlobalOrdinal> LOC;
477
478 RCP<panzer::GlobalIndexer> indexer
479 = rcp(new unit_test::GlobalIndexer(myRank,numProc));
480
481 std::vector<panzer::GlobalOrdinal> ownedIndices, ownedAndGhostedIndices;
482 indexer->getOwnedIndices(ownedIndices);
483 indexer->getOwnedAndGhostedIndices(ownedAndGhostedIndices);
484
485 // setup factory
486 Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > la_factory
487 = Teuchos::rcp(new panzer::TpetraLinearObjFactory<panzer::Traits,double,int,panzer::GlobalOrdinal>(tComm.getConst(),indexer));
488
489 RCP<LinearObjContainer> container = la_factory->buildLinearObjContainer();
490 RCP<LinearObjContainer> ghostedContainer = la_factory->buildGhostedLinearObjContainer();
491
492 RCP<TpetraLinearObjContainer<double,int,panzer::GlobalOrdinal> > tContainer = rcp_dynamic_cast<TpetraLinearObjContainer<double,int,panzer::GlobalOrdinal> >(container);
493 RCP<TpetraLinearObjContainer<double,int,panzer::GlobalOrdinal> > tGhostedContainer = rcp_dynamic_cast<TpetraLinearObjContainer<double,int,panzer::GlobalOrdinal> >(ghostedContainer);
494
495 // tests global initialize
496 {
497 // Generic code
498 /////////////////////////////////////////////////////////////
499
500 // test individial initializers
501 la_factory->initializeContainer(LOC::X,*container);
502 TEST_ASSERT(tContainer->get_x()!=Teuchos::null);
503 TEST_EQUALITY(tContainer->get_dxdt(), Teuchos::null)
504 TEST_EQUALITY(tContainer->get_f(), Teuchos::null)
505 TEST_EQUALITY(tContainer->get_A(), Teuchos::null)
506 TEST_EQUALITY(tContainer->get_x()->getLocalLength(),(std::size_t) ownedIndices.size());
507
508 la_factory->initializeContainer(LOC::DxDt,*container);
509 TEST_EQUALITY(tContainer->get_x(), Teuchos::null)
510 TEST_ASSERT(tContainer->get_dxdt()!=Teuchos::null);
511 TEST_EQUALITY(tContainer->get_f(), Teuchos::null)
512 TEST_EQUALITY(tContainer->get_A(), Teuchos::null)
513 TEST_EQUALITY(tContainer->get_dxdt()->getLocalLength(),(std::size_t) ownedIndices.size());
514
515 la_factory->initializeContainer(LOC::F,*container);
516 TEST_EQUALITY(tContainer->get_x(), Teuchos::null)
517 TEST_EQUALITY(tContainer->get_dxdt(), Teuchos::null)
518 TEST_ASSERT(tContainer->get_f()!=Teuchos::null);
519 TEST_EQUALITY(tContainer->get_A(), Teuchos::null)
520 TEST_EQUALITY(tContainer->get_f()->getLocalLength(),(std::size_t) ownedIndices.size());
521
522 la_factory->initializeContainer(LOC::Mat,*container);
523 TEST_EQUALITY(tContainer->get_x(), Teuchos::null)
524 TEST_EQUALITY(tContainer->get_dxdt(), Teuchos::null)
525 TEST_EQUALITY(tContainer->get_f(), Teuchos::null)
526 TEST_ASSERT(tContainer->get_A()!=Teuchos::null);
527 TEST_EQUALITY(tContainer->get_A()->getLocalNumRows(),(std::size_t) ownedIndices.size());
528
529 // jacobian and residual vector output
530 la_factory->initializeContainer(LOC::F | LOC::Mat,*container);
531 TEST_EQUALITY(tContainer->get_x(), Teuchos::null)
532 TEST_EQUALITY(tContainer->get_dxdt(), Teuchos::null)
533 TEST_ASSERT(tContainer->get_f()!=Teuchos::null);
534 TEST_ASSERT(tContainer->get_A()!=Teuchos::null);
535
536 // x and time dertivative input
537 la_factory->initializeContainer(LOC::X | LOC::DxDt,*container);
538 TEST_ASSERT(tContainer->get_x()!=Teuchos::null);
539 TEST_ASSERT(tContainer->get_dxdt()!=Teuchos::null);
540 TEST_EQUALITY(tContainer->get_f(), Teuchos::null)
541 TEST_EQUALITY(tContainer->get_A(), Teuchos::null)
542
543 // everything
544 la_factory->initializeContainer(LOC::X | LOC::DxDt | LOC::F | LOC::Mat,*container);
545 TEST_ASSERT(tContainer->get_x()!=Teuchos::null);
546 TEST_ASSERT(tContainer->get_dxdt()!=Teuchos::null);
547 TEST_ASSERT(tContainer->get_f()!=Teuchos::null);
548 TEST_ASSERT(tContainer->get_A()!=Teuchos::null);
549
550 // Tpetra specific code
551 /////////////////////////////////////////////////////////////
552
553 // test individial initializers
554 la_factory->initializeContainer(LOC::X,*tContainer);
555 TEST_ASSERT(tContainer->get_x()!=Teuchos::null);
556 TEST_EQUALITY(tContainer->get_dxdt(), Teuchos::null)
557 TEST_EQUALITY(tContainer->get_f(), Teuchos::null)
558 TEST_EQUALITY(tContainer->get_A(), Teuchos::null)
559
560 la_factory->initializeContainer(LOC::DxDt,*tContainer);
561 TEST_EQUALITY(tContainer->get_x(), Teuchos::null)
562 TEST_ASSERT(tContainer->get_dxdt()!=Teuchos::null);
563 TEST_EQUALITY(tContainer->get_f(), Teuchos::null)
564 TEST_EQUALITY(tContainer->get_A(), Teuchos::null)
565
566 la_factory->initializeContainer(LOC::F,*tContainer);
567 TEST_EQUALITY(tContainer->get_x(), Teuchos::null)
568 TEST_EQUALITY(tContainer->get_dxdt(), Teuchos::null)
569 TEST_ASSERT(tContainer->get_f()!=Teuchos::null);
570 TEST_EQUALITY(tContainer->get_A(), Teuchos::null)
571
572 la_factory->initializeContainer(LOC::Mat,*tContainer);
573 TEST_EQUALITY(tContainer->get_x(), Teuchos::null)
574 TEST_EQUALITY(tContainer->get_dxdt(), Teuchos::null)
575 TEST_EQUALITY(tContainer->get_f(), Teuchos::null)
576 TEST_ASSERT(tContainer->get_A()!=Teuchos::null);
577
578 // jacobian and residual vector output
579 la_factory->initializeContainer(LOC::F | LOC::Mat,*tContainer);
580 TEST_EQUALITY(tContainer->get_x(), Teuchos::null)
581 TEST_EQUALITY(tContainer->get_dxdt(), Teuchos::null)
582 TEST_ASSERT(tContainer->get_f()!=Teuchos::null);
583 TEST_ASSERT(tContainer->get_A()!=Teuchos::null);
584
585 // x and time dertivative input
586 la_factory->initializeContainer(LOC::X | LOC::DxDt,*tContainer);
587 TEST_ASSERT(tContainer->get_x()!=Teuchos::null);
588 TEST_ASSERT(tContainer->get_dxdt()!=Teuchos::null);
589 TEST_EQUALITY(tContainer->get_f(), Teuchos::null)
590 TEST_EQUALITY(tContainer->get_A(), Teuchos::null)
591
592 // everything
593 la_factory->initializeContainer(LOC::X | LOC::DxDt | LOC::F | LOC::Mat,*tContainer);
594 TEST_ASSERT(tContainer->get_x()!=Teuchos::null);
595 TEST_ASSERT(tContainer->get_dxdt()!=Teuchos::null);
596 TEST_ASSERT(tContainer->get_f()!=Teuchos::null);
597 TEST_ASSERT(tContainer->get_A()!=Teuchos::null);
598 }
599
600 // tests ghosted initialize
601 {
602 // Generic code
603 /////////////////////////////////////////////////////////////
604
605 // test individial initializers
606 la_factory->initializeGhostedContainer(LOC::X,*ghostedContainer);
607 TEST_ASSERT(tGhostedContainer->get_x()!=Teuchos::null);
608 TEST_EQUALITY(tGhostedContainer->get_dxdt(), Teuchos::null)
609 TEST_EQUALITY(tGhostedContainer->get_f(), Teuchos::null)
610 TEST_EQUALITY(tGhostedContainer->get_A(), Teuchos::null)
611 TEST_EQUALITY(tGhostedContainer->get_x()->getLocalLength(),(std::size_t) ownedAndGhostedIndices.size());
612
613 la_factory->initializeGhostedContainer(LOC::DxDt,*ghostedContainer);
614 TEST_EQUALITY(tGhostedContainer->get_x(), Teuchos::null)
615 TEST_ASSERT(tGhostedContainer->get_dxdt()!=Teuchos::null);
616 TEST_EQUALITY(tGhostedContainer->get_f(), Teuchos::null)
617 TEST_EQUALITY(tGhostedContainer->get_A(), Teuchos::null)
618 TEST_EQUALITY(tGhostedContainer->get_dxdt()->getLocalLength(),(std::size_t) ownedAndGhostedIndices.size());
619
620 la_factory->initializeGhostedContainer(LOC::F,*ghostedContainer);
621 TEST_EQUALITY(tGhostedContainer->get_x(), Teuchos::null)
622 TEST_EQUALITY(tGhostedContainer->get_dxdt(), Teuchos::null)
623 TEST_ASSERT(tGhostedContainer->get_f()!=Teuchos::null);
624 TEST_EQUALITY(tGhostedContainer->get_A(), Teuchos::null)
625 TEST_EQUALITY(tGhostedContainer->get_f()->getLocalLength(),(std::size_t) ownedAndGhostedIndices.size());
626
627 la_factory->initializeGhostedContainer(LOC::Mat,*ghostedContainer);
628 TEST_EQUALITY(tGhostedContainer->get_x(), Teuchos::null)
629 TEST_EQUALITY(tGhostedContainer->get_dxdt(), Teuchos::null)
630 TEST_EQUALITY(tGhostedContainer->get_f(), Teuchos::null)
631 TEST_ASSERT(tGhostedContainer->get_A()!=Teuchos::null);
632 TEST_EQUALITY(tGhostedContainer->get_A()->getLocalNumRows(),(std::size_t) ownedAndGhostedIndices.size());
633
634 // jacobian and residual vector output
635 la_factory->initializeGhostedContainer(LOC::F | LOC::Mat,*ghostedContainer);
636 TEST_EQUALITY(tGhostedContainer->get_x(), Teuchos::null)
637 TEST_EQUALITY(tGhostedContainer->get_dxdt(), Teuchos::null)
638 TEST_ASSERT(tGhostedContainer->get_f()!=Teuchos::null);
639 TEST_ASSERT(tGhostedContainer->get_A()!=Teuchos::null);
640
641 // x and time dertivative input
642 la_factory->initializeGhostedContainer(LOC::X | LOC::DxDt,*ghostedContainer);
643 TEST_ASSERT(tGhostedContainer->get_x()!=Teuchos::null);
644 TEST_ASSERT(tGhostedContainer->get_dxdt()!=Teuchos::null);
645 TEST_EQUALITY(tGhostedContainer->get_f(), Teuchos::null)
646 TEST_EQUALITY(tGhostedContainer->get_A(), Teuchos::null)
647
648 // everything
649 la_factory->initializeGhostedContainer(LOC::X | LOC::DxDt | LOC::F | LOC::Mat,*ghostedContainer);
650 TEST_ASSERT(tGhostedContainer->get_x()!=Teuchos::null);
651 TEST_ASSERT(tGhostedContainer->get_dxdt()!=Teuchos::null);
652 TEST_ASSERT(tGhostedContainer->get_f()!=Teuchos::null);
653 TEST_ASSERT(tGhostedContainer->get_A()!=Teuchos::null);
654
655 // Tpetra specific code
656 /////////////////////////////////////////////////////////////
657
658 // test individial initializers
659 la_factory->initializeGhostedContainer(LOC::X,*tGhostedContainer);
660 TEST_ASSERT(tGhostedContainer->get_x()!=Teuchos::null);
661 TEST_EQUALITY(tGhostedContainer->get_dxdt(), Teuchos::null)
662 TEST_EQUALITY(tGhostedContainer->get_f(), Teuchos::null)
663 TEST_EQUALITY(tGhostedContainer->get_A(), Teuchos::null)
664
665 la_factory->initializeGhostedContainer(LOC::DxDt,*tGhostedContainer);
666 TEST_EQUALITY(tGhostedContainer->get_x(), Teuchos::null)
667 TEST_ASSERT(tGhostedContainer->get_dxdt()!=Teuchos::null);
668 TEST_EQUALITY(tGhostedContainer->get_f(), Teuchos::null)
669 TEST_EQUALITY(tGhostedContainer->get_A(), Teuchos::null)
670
671 la_factory->initializeGhostedContainer(LOC::F,*tGhostedContainer);
672 TEST_EQUALITY(tGhostedContainer->get_x(), Teuchos::null)
673 TEST_EQUALITY(tGhostedContainer->get_dxdt(), Teuchos::null)
674 TEST_ASSERT(tGhostedContainer->get_f()!=Teuchos::null);
675 TEST_EQUALITY(tGhostedContainer->get_A(), Teuchos::null)
676
677 la_factory->initializeGhostedContainer(LOC::Mat,*tGhostedContainer);
678 TEST_EQUALITY(tGhostedContainer->get_x(), Teuchos::null)
679 TEST_EQUALITY(tGhostedContainer->get_dxdt(), Teuchos::null)
680 TEST_EQUALITY(tGhostedContainer->get_f(), Teuchos::null)
681 TEST_ASSERT(tGhostedContainer->get_A()!=Teuchos::null);
682
683 // jacobian and residual vector output
684 la_factory->initializeGhostedContainer(LOC::F | LOC::Mat,*tGhostedContainer);
685 TEST_EQUALITY(tGhostedContainer->get_x(), Teuchos::null)
686 TEST_EQUALITY(tGhostedContainer->get_dxdt(), Teuchos::null)
687 TEST_ASSERT(tGhostedContainer->get_f()!=Teuchos::null);
688 TEST_ASSERT(tGhostedContainer->get_A()!=Teuchos::null);
689
690 // x and time dertivative input
691 la_factory->initializeGhostedContainer(LOC::X | LOC::DxDt,*tGhostedContainer);
692 TEST_ASSERT(tGhostedContainer->get_x()!=Teuchos::null);
693 TEST_ASSERT(tGhostedContainer->get_dxdt()!=Teuchos::null);
694 TEST_EQUALITY(tGhostedContainer->get_f(), Teuchos::null)
695 TEST_EQUALITY(tGhostedContainer->get_A(), Teuchos::null)
696
697 // everything
698 la_factory->initializeGhostedContainer(LOC::X | LOC::DxDt | LOC::F | LOC::Mat,*tGhostedContainer);
699 TEST_ASSERT(tGhostedContainer->get_x()!=Teuchos::null);
700 TEST_ASSERT(tGhostedContainer->get_dxdt()!=Teuchos::null);
701 TEST_ASSERT(tGhostedContainer->get_f()!=Teuchos::null);
702 TEST_ASSERT(tGhostedContainer->get_A()!=Teuchos::null);
703 }
704 }
705
706 }