Debian Codegraph @

packages/panzer/disc-fe/test/la_factory/tBlockedLinearObjFactory.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_Traits.hpp"
20
21 // for testing gather/scatter construction
22 #include "Panzer_PureBasis.hpp"
23 #include "Panzer_IntegrationRule.hpp"
24 #include "Panzer_EpetraLinearObjContainer.hpp"
25 #include "Panzer_BlockedEpetraLinearObjContainer.hpp"
26 #include "Panzer_BlockedEpetraLinearObjFactory.hpp"
27 #include "Panzer_PauseToAttach.hpp"
28 #include "Panzer_IntrepidFieldPattern.hpp"
29
30 #include "UnitTest_GlobalIndexer.hpp"
31
32 #include "Thyra_EpetraThyraWrappers.hpp"
33 #include "Thyra_ProductVectorBase.hpp"
34 #include "Thyra_BlockedLinearOpBase.hpp"
35 #include "Thyra_SpmdVectorBase.hpp"
36 #include "Thyra_get_Epetra_Operator.hpp"
37 #include "Thyra_VectorStdOps.hpp"
38
39 #include "Epetra_Comm.h"
40 #ifdef HAVE_MPI
41 #include "Epetra_MpiComm.h"
42 #else
43 #include "Epetra_SerialComm.h"
44 #endif
45 #include "Epetra_Operator.h"
46 #include "Epetra_CrsMatrix.h"
47
48 #include "UnitTest_ConnManager.hpp"
49
50 using Teuchos::rcp;
51 using Teuchos::rcp_dynamic_cast;
52 using Teuchos::RCP;
53 using Teuchos::rcpFromRef;
54
55 namespace panzer {
56
57 Teuchos::RCP<Epetra_CrsMatrix> getSubBlock(int i,int j,Thyra::LinearOpBase<double> & lo)
58 {
59 Thyra::BlockedLinearOpBase<double> & blo = Teuchos::dyn_cast<Thyra::BlockedLinearOpBase<double> >(lo);
60 Teuchos::RCP<Epetra_Operator> e_blo = Thyra::get_Epetra_Operator(*blo.getNonconstBlock(i,j));
61
62 return rcp_dynamic_cast<Epetra_CrsMatrix>(e_blo);
63 }
64
65 Teuchos::RCP<const Epetra_CrsMatrix> getSubBlock(int i,int j,const Thyra::LinearOpBase<double> & lo)
66 {
67 const Thyra::BlockedLinearOpBase<double> & blo = Teuchos::dyn_cast<const Thyra::BlockedLinearOpBase<double> >(lo);
68 Teuchos::RCP<const Epetra_Operator> e_blo = Thyra::get_Epetra_Operator(*blo.getBlock(i,j));
69
70 return rcp_dynamic_cast<const Epetra_CrsMatrix>(e_blo);
71 }
72
73 template <typename Intrepid2Type>
74 Teuchos::RCP<const panzer::FieldPattern> buildFieldPattern()
75 {
76 using Teuchos::RCP;
77 using Teuchos::rcp;
78
79 // build a geometric pattern from a single basis
80 RCP<Intrepid2::Basis<PHX::exec_space,double,double> > basis = rcp(new Intrepid2Type);
81 RCP<const panzer::FieldPattern> pattern = rcp(new panzer::Intrepid2FieldPattern(basis));
82 return pattern;
83 }
84
85 Teuchos::RCP<const panzer::BlockedDOFManager> buildBlockedIndexer(int myRank,int numProc,int numBlocks)
86 {
87 std::string names[] = {"U","V","W","X"};
88
89 Teuchos::RCP<const FieldPattern> patternC1
90 = buildFieldPattern<Intrepid2::Basis_HGRAD_QUAD_C1_FEM<PHX::exec_space,double,double> >();
91 Teuchos::RCP<ConnManager> connManager = rcp(new unit_test::ConnManager(myRank,numProc));
92 Teuchos::RCP<panzer::BlockedDOFManager> indexer = rcp(new panzer::BlockedDOFManager());
93
94 indexer->setConnManager(connManager,MPI_COMM_WORLD);
95
96 std::vector<std::vector<std::string> > fieldOrder(numBlocks);
97 for(int i=0;i<numBlocks;i++) {
98 indexer->addField(names[i],patternC1);
99
100 fieldOrder[i].push_back(names[i]);
101 }
102 indexer->setFieldOrder(fieldOrder);
103 indexer->buildGlobalUnknowns();
104
105 return indexer;
106 }
107
108 RCP<Epetra_MultiVector> getEpetraMultiVector(RCP<Thyra::MultiVectorBase<double> > & vec,const Epetra_Map & eMap)
109 {
110 return Thyra::get_Epetra_MultiVector(eMap,vec);
111 }
112
113 TEUCHOS_UNIT_TEST(tEpetraLinearObjFactory, gather_scatter_constr)
114 {
115
116 // build global (or serial communicator)
117 #ifdef HAVE_MPI
118 Teuchos::RCP<Epetra_Comm> eComm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD));
119 #else
120 Teuchos::RCP<Epetra_Comm> eComm = Teuchos::rcp(new Epetra_SerialComm());
121 #endif
122
123 Teuchos::RCP<const Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD));
124
125 using Teuchos::RCP;
126 using Teuchos::rcp;
127 using Teuchos::rcp_dynamic_cast;
128
129 int myRank = eComm->MyPID();
130 int numProc = eComm->NumProc();
131
132 RCP<panzer::GlobalIndexer> indexer
133 = rcp(new panzer::unit_test::GlobalIndexer(myRank,numProc));
134
135 // setup factory
136 Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > la_factory
137 = Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(tComm.getConst(),indexer));
138
139 // build parameter lists for gather and scatters
140 //////////////////////////////////////////////////////////////////
141 std::size_t numCells = 10;
142
143 Teuchos::ParameterList gatherParams;
144 {
145 Teuchos::RCP<shards::CellTopology> topo =
146 Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >()));
147
148 // auxiliary information needed to construct basis object
149 std::string basisType = "Q1";
150 panzer::CellData cellData(numCells,topo);
151
152 // build DOF names
153 RCP<std::vector<std::string> > dofNames = rcp(new std::vector<std::string>);
154 dofNames->push_back("ux"); // in practice these probably would not be gathered together!
155 dofNames->push_back("p");
156
157 // build basis
158 RCP<panzer::PureBasis> basis = rcp(new panzer::PureBasis(basisType,1,cellData));
159
160 // build gather parameter list
161 gatherParams.set<RCP<std::vector<std::string> > >("DOF Names",dofNames);
162 gatherParams.set<RCP<std::vector<std::string> > >("Indexer Names",dofNames);
163 gatherParams.set<RCP<panzer::PureBasis> >("Basis",basis);
164 }
165
166 Teuchos::ParameterList scatterParams;
167 {
168 Teuchos::RCP<shards::CellTopology> topo =
169 Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >()));
170
171 std::string basisType = "Q1";
172 panzer::CellData cellData(numCells,topo);
173
174 // build basis
175 RCP<const panzer::PureBasis> basis = rcp(new panzer::PureBasis(basisType,1,cellData));
176
177 std::string scatterName = "Residual_NS";
178
179 // build DOF names
180 RCP<std::vector<std::string> > evaluatedNames = rcp(new std::vector<std::string>);
181 evaluatedNames->push_back("Residual_ux"); // in practice these probably would not be scattered together!
182 evaluatedNames->push_back("Residual_p");
183
184 // build evaluated map
185 RCP<std::map<std::string,std::string> > evaluatedMap = rcp(new std::map<std::string,std::string>);
186 evaluatedMap->insert(std::make_pair("Residual_ux","ux")); // in practice these probably would not be scattered together!
187 evaluatedMap->insert(std::make_pair("Residual_p","p"));
188
189 // build scatter parameter list
190 scatterParams.set<std::string>("Scatter Name",scatterName);
191 scatterParams.set<RCP<std::vector<std::string> > >("Dependent Names",evaluatedNames);
192 scatterParams.set<RCP<std::map<std::string,std::string> > >("Dependent Map",evaluatedMap);
193 scatterParams.set("Basis",basis);
194 }
195
196 Teuchos::ParameterList scatterDirichletParams;
197 {
198 Teuchos::RCP<shards::CellTopology> topo =
199 Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Quadrilateral<4> >()));
200
201 std::string basisType = "Q1";
202 panzer::CellData cellData(numCells,topo);
203
204 // build basis
205 RCP<panzer::PureBasis> basis = rcp(new panzer::PureBasis(basisType,1,cellData));
206
207 std::string scatterName = "Residual_NS";
208
209 // build DOF names
210 RCP<std::vector<std::string> > evaluatedNames = rcp(new std::vector<std::string>);
211 evaluatedNames->push_back("Residual_ux"); // in practice these probably would not be scattered together!
212 evaluatedNames->push_back("Residual_p");
213
214 // build evaluated map
215 RCP<std::map<std::string,std::string> > evaluatedMap = rcp(new std::map<std::string,std::string>);
216 evaluatedMap->insert(std::make_pair("Residual_ux","ux")); // in practice these probably would not be scattered together!
217 evaluatedMap->insert(std::make_pair("Residual_p","p"));
218
219 // build scatter parameter list
220 scatterDirichletParams.set<std::string>("Scatter Name",scatterName);
221 scatterDirichletParams.set<RCP<std::vector<std::string> > >("Dependent Names",evaluatedNames);
222 scatterDirichletParams.set<RCP<std::map<std::string,std::string> > >("Dependent Map",evaluatedMap);
223 scatterDirichletParams.set<RCP<panzer::PureBasis> >("Basis",basis);
224 scatterDirichletParams.set<int>("Side Subcell Dimension",1);
225 scatterDirichletParams.set<int>("Local Side ID",2);
226 scatterDirichletParams.set("Check Apply BC",false);
227 }
228
229 // Evaluator construction tests
230 ///////////////////////////////////////////////////////
231 RCP<PHX::Evaluator<panzer::Traits> > evaluator;
232
233 {
234 typedef panzer::Traits::Residual EvalType;
235
236 // gather test
237 {
238 evaluator = la_factory->buildGather<EvalType>(gatherParams);
239
240 TEST_ASSERT(evaluator!=Teuchos::null);
241 RCP<GatherSolution_Epetra<EvalType,panzer::Traits,int,int> > gatherSolutionEval
242 = rcp_dynamic_cast<GatherSolution_Epetra<EvalType,panzer::Traits,int,int> >(evaluator);
243 TEST_ASSERT(gatherSolutionEval!=Teuchos::null);
244
245 const std::vector<RCP<PHX::FieldTag> > & fields = gatherSolutionEval->evaluatedFields();
246 TEST_EQUALITY(fields.size(),2);
247
248 TEST_EQUALITY(fields[0]->name(),"ux");
249 TEST_EQUALITY(fields[1]->name(),"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 // scatter test
259 {
260 evaluator = la_factory->buildScatter<EvalType>(scatterParams);
261
262 out << "SCATTER RES NAME: \"" << evaluator->getName() << "\"" << std::endl;
263 TEST_ASSERT(evaluator!=Teuchos::null);
264 RCP<ScatterResidual_Epetra<EvalType,panzer::Traits,int,int> > scatterResidual
265 = rcp_dynamic_cast<ScatterResidual_Epetra<EvalType,panzer::Traits,int,int> >(evaluator);
266 TEST_ASSERT(scatterResidual!=Teuchos::null);
267
268 const std::vector<RCP<PHX::FieldTag> > & evalFields = scatterResidual->evaluatedFields();
269 TEST_EQUALITY(evalFields.size(),1); // this is a dummy holder for the sake of the field manager
270
271 const std::vector<RCP<PHX::FieldTag> > & fields = scatterResidual->dependentFields();
272 TEST_EQUALITY(fields.size(),2); // these store the residual values
273
274 TEST_EQUALITY(fields[0]->name(),"Residual_ux");
275 TEST_EQUALITY(fields[1]->name(),"Residual_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 dirichlet test
285 {
286 evaluator = la_factory->buildScatterDirichlet<EvalType>(scatterDirichletParams);
287
288 out << "SCATTER DIRICHLET RES NAME: \"" << evaluator->getName() << "\"" << std::endl;
289 TEST_ASSERT(evaluator!=Teuchos::null);
290 RCP<ScatterDirichletResidual_Epetra<EvalType,panzer::Traits,int,int> > scatterResidual
291 = rcp_dynamic_cast<ScatterDirichletResidual_Epetra<EvalType,panzer::Traits,int,int> >(evaluator);
292 TEST_ASSERT(scatterResidual!=Teuchos::null);
293
294 const std::vector<RCP<PHX::FieldTag> > & evalFields = scatterResidual->evaluatedFields();
295 TEST_EQUALITY(evalFields.size(),1); // this is a dummy holder for the sake of the field manager
296
297 const std::vector<RCP<PHX::FieldTag> > & fields = scatterResidual->dependentFields();
298 TEST_EQUALITY(fields.size(),2); // these store the residual values
299
300 TEST_EQUALITY(fields[0]->name(),"Residual_ux");
301 TEST_EQUALITY(fields[1]->name(),"Residual_p");
302
303 TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
304 TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
305
306 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
307 TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
308 }
309
310 }
311
312 {
313 typedef panzer::Traits::Jacobian EvalType;
314
315 // gather test
316 {
317 evaluator = la_factory->buildGather<EvalType>(gatherParams);
318
319 TEST_ASSERT(evaluator!=Teuchos::null);
320 RCP<GatherSolution_Epetra<EvalType,panzer::Traits,int,int> > gatherSolutionEval
321 = rcp_dynamic_cast<GatherSolution_Epetra<EvalType,panzer::Traits,int,int> >(evaluator);
322 TEST_ASSERT(gatherSolutionEval!=Teuchos::null);
323
324 const std::vector<RCP<PHX::FieldTag> > & fields = gatherSolutionEval->evaluatedFields();
325 TEST_EQUALITY(fields.size(),2);
326
327 TEST_EQUALITY(fields[0]->name(),"ux");
328 TEST_EQUALITY(fields[1]->name(),"p");
329
330 TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
331 TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
332
333 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
334 TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
335 }
336
337 // scatter test
338 {
339 evaluator = la_factory->buildScatter<EvalType>(scatterParams);
340
341 TEST_ASSERT(evaluator!=Teuchos::null);
342 RCP<ScatterResidual_Epetra<EvalType,panzer::Traits,int,int> > scatterResidual
343 = rcp_dynamic_cast<ScatterResidual_Epetra<EvalType,panzer::Traits,int,int> >(evaluator);
344 TEST_ASSERT(scatterResidual!=Teuchos::null);
345
346 const std::vector<RCP<PHX::FieldTag> > & evalFields = scatterResidual->evaluatedFields();
347 TEST_EQUALITY(evalFields.size(),1); // this is a dummy holder for the sake of the field manager
348
349 const std::vector<RCP<PHX::FieldTag> > & fields = scatterResidual->dependentFields();
350 TEST_EQUALITY(fields.size(),2); // these store the residual values
351
352 TEST_EQUALITY(fields[0]->name(),"Residual_ux");
353 TEST_EQUALITY(fields[1]->name(),"Residual_p");
354
355 TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
356 TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
357
358 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
359 TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
360 }
361
362 // scatter dirichlet test
363 {
364 evaluator = la_factory->buildScatterDirichlet<EvalType>(scatterDirichletParams);
365
366 out << "SCATTER DIRICHLET RES NAME: \"" << evaluator->getName() << "\"" << std::endl;
367 TEST_ASSERT(evaluator!=Teuchos::null);
368 RCP<ScatterDirichletResidual_Epetra<EvalType,panzer::Traits,int,int> > scatterResidual
369 = rcp_dynamic_cast<ScatterDirichletResidual_Epetra<EvalType,panzer::Traits,int,int> >(evaluator);
370 TEST_ASSERT(scatterResidual!=Teuchos::null);
371
372 const std::vector<RCP<PHX::FieldTag> > & evalFields = scatterResidual->evaluatedFields();
373 TEST_EQUALITY(evalFields.size(),1); // this is a dummy holder for the sake of the field manager
374
375 const std::vector<RCP<PHX::FieldTag> > & fields = scatterResidual->dependentFields();
376 TEST_EQUALITY(fields.size(),2); // these store the residual values
377
378 TEST_EQUALITY(fields[0]->name(),"Residual_ux");
379 TEST_EQUALITY(fields[1]->name(),"Residual_p");
380
381 TEST_EQUALITY(fields[0]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
382 TEST_EQUALITY(fields[0]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
383
384 TEST_EQUALITY(fields[1]->dataLayout().extent_int(0),Teuchos::as<int>(numCells));
385 TEST_EQUALITY(fields[1]->dataLayout().extent_int(1),Teuchos::as<int>(4)); // for Q1
386 }
387
388 }
389 }
390
391 TEUCHOS_UNIT_TEST(tEpetraLinearObjFactory, initializeContainer)
392 {
393
394 // build global (or serial communicator)
395 #ifdef HAVE_MPI
396 Teuchos::RCP<Epetra_Comm> eComm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD));
397 #else
398 Teuchos::RCP<Epetra_Comm> eComm = Teuchos::rcp(new Epetra_SerialComm());
399 #endif
400
401 using Teuchos::RCP;
402 using Teuchos::rcp;
403 using Teuchos::rcp_dynamic_cast;
404
405 Teuchos::RCP<const Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD));
406
407 int myRank = eComm->MyPID();
408 int numProc = eComm->NumProc();
409
410 typedef EpetraLinearObjContainer ELOC;
411
412 RCP<panzer::GlobalIndexer> indexer
413 = rcp(new unit_test::GlobalIndexer(myRank,numProc));
414
415 std::vector<panzer::GlobalOrdinal> ownedIndices, ownedAndGhostedIndices;
416 indexer->getOwnedIndices(ownedIndices);
417 indexer->getOwnedAndGhostedIndices(ownedAndGhostedIndices);
418
419 // setup factory
420 Teuchos::RCP<panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int> > la_factory
421 = Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(tComm.getConst(),indexer));
422
423 RCP<LinearObjContainer> container = la_factory->buildLinearObjContainer();
424 RCP<LinearObjContainer> ghostedContainer = la_factory->buildGhostedLinearObjContainer();
425
426 RCP<EpetraLinearObjContainer> eContainer = rcp_dynamic_cast<EpetraLinearObjContainer>(container);
427 RCP<EpetraLinearObjContainer> eGhostedContainer = rcp_dynamic_cast<EpetraLinearObjContainer>(ghostedContainer);
428
429 // tests ghosted initialize
430 {
431 // Generic code
432 /////////////////////////////////////////////////////////////
433
434 // test individial initializers
435 la_factory->initializeGhostedContainer(ELOC::X,*ghostedContainer);
436 TEST_ASSERT(eGhostedContainer->get_x()!=Teuchos::null);
437 TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null)
438 TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null)
439 TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null)
440 TEST_EQUALITY(eGhostedContainer->get_x()->MyLength(),(int) ownedAndGhostedIndices.size());
441
442 la_factory->initializeGhostedContainer(ELOC::DxDt,*ghostedContainer);
443 TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null)
444 TEST_ASSERT(eGhostedContainer->get_dxdt()!=Teuchos::null);
445 TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null)
446 TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null)
447 TEST_EQUALITY(eGhostedContainer->get_dxdt()->MyLength(),(int) ownedAndGhostedIndices.size());
448
449 la_factory->initializeGhostedContainer(ELOC::F,*ghostedContainer);
450 TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null)
451 TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null)
452 TEST_ASSERT(eGhostedContainer->get_f()!=Teuchos::null);
453 TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null)
454 TEST_EQUALITY(eGhostedContainer->get_f()->MyLength(),(int) ownedAndGhostedIndices.size());
455
456 la_factory->initializeGhostedContainer(ELOC::Mat,*ghostedContainer);
457 TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null)
458 TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null)
459 TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null)
460 TEST_ASSERT(eGhostedContainer->get_A()!=Teuchos::null);
461 TEST_EQUALITY(eGhostedContainer->get_A()->NumMyRows(),(int) ownedAndGhostedIndices.size());
462
463 // jacobian and residual vector output
464 la_factory->initializeGhostedContainer(ELOC::F | ELOC::Mat,*ghostedContainer);
465 TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null)
466 TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null)
467 TEST_ASSERT(eGhostedContainer->get_f()!=Teuchos::null);
468 TEST_ASSERT(eGhostedContainer->get_A()!=Teuchos::null);
469
470 // x and time dertivative input
471 la_factory->initializeGhostedContainer(ELOC::X | ELOC::DxDt,*ghostedContainer);
472 TEST_ASSERT(eGhostedContainer->get_x()!=Teuchos::null);
473 TEST_ASSERT(eGhostedContainer->get_dxdt()!=Teuchos::null);
474 TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null)
475 TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null)
476
477 // everything
478 la_factory->initializeGhostedContainer(ELOC::X | ELOC::DxDt | ELOC::F | ELOC::Mat,*ghostedContainer);
479 TEST_ASSERT(eGhostedContainer->get_x()!=Teuchos::null);
480 TEST_ASSERT(eGhostedContainer->get_dxdt()!=Teuchos::null);
481 TEST_ASSERT(eGhostedContainer->get_f()!=Teuchos::null);
482 TEST_ASSERT(eGhostedContainer->get_A()!=Teuchos::null);
483
484 // Epetra specific code
485 /////////////////////////////////////////////////////////////
486
487 // test individial initializers
488 la_factory->initializeGhostedContainer(ELOC::X,*eGhostedContainer);
489 TEST_ASSERT(eGhostedContainer->get_x()!=Teuchos::null);
490 TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null)
491 TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null)
492 TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null)
493
494 la_factory->initializeGhostedContainer(ELOC::DxDt,*eGhostedContainer);
495 TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null)
496 TEST_ASSERT(eGhostedContainer->get_dxdt()!=Teuchos::null);
497 TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null)
498 TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null)
499
500 la_factory->initializeGhostedContainer(ELOC::F,*eGhostedContainer);
501 TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null)
502 TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null)
503 TEST_ASSERT(eGhostedContainer->get_f()!=Teuchos::null);
504 TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null)
505
506 la_factory->initializeGhostedContainer(ELOC::Mat,*eGhostedContainer);
507 TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null)
508 TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null)
509 TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null)
510 TEST_ASSERT(eGhostedContainer->get_A()!=Teuchos::null);
511
512 // jacobian and residual vector output
513 la_factory->initializeGhostedContainer(ELOC::F | ELOC::Mat,*eGhostedContainer);
514 TEST_EQUALITY(eGhostedContainer->get_x(), Teuchos::null)
515 TEST_EQUALITY(eGhostedContainer->get_dxdt(), Teuchos::null)
516 TEST_ASSERT(eGhostedContainer->get_f()!=Teuchos::null);
517 TEST_ASSERT(eGhostedContainer->get_A()!=Teuchos::null);
518
519 // x and time dertivative input
520 la_factory->initializeGhostedContainer(ELOC::X | ELOC::DxDt,*eGhostedContainer);
521 TEST_ASSERT(eGhostedContainer->get_x()!=Teuchos::null);
522 TEST_ASSERT(eGhostedContainer->get_dxdt()!=Teuchos::null);
523 TEST_EQUALITY(eGhostedContainer->get_f(), Teuchos::null)
524 TEST_EQUALITY(eGhostedContainer->get_A(), Teuchos::null)
525
526 // everything
527 la_factory->initializeGhostedContainer(ELOC::X | ELOC::DxDt | ELOC::F | ELOC::Mat,*eGhostedContainer);
528 TEST_ASSERT(eGhostedContainer->get_x()!=Teuchos::null);
529 TEST_ASSERT(eGhostedContainer->get_dxdt()!=Teuchos::null);
530 TEST_ASSERT(eGhostedContainer->get_f()!=Teuchos::null);
531 TEST_ASSERT(eGhostedContainer->get_A()!=Teuchos::null);
532 }
533
534 }
535
536 TEUCHOS_UNIT_TEST(tBlockedLinearObjFactory, intializeContainer_epetra)
537 {
538
539 panzer::BlockedEpetraLinearObjContainer container;
540
541 TEST_ASSERT(container.checkCompatibility());
542 }
543
544 TEUCHOS_UNIT_TEST(tBlockedEpetraLinearObjFactory, epetra_factory_tests)
545 {
546 #ifdef HAVE_MPI
547 Teuchos::RCP<Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD));
548 #else
549 NOPE_PANZER_DOESNT_SUPPORT_SERIAL
550 #endif
551
552 using Teuchos::RCP;
553 using Teuchos::rcp;
554 using Teuchos::rcp_dynamic_cast;
555
556 // pauseToAttach();
557
558 typedef LinearObjContainer LOC;
559 typedef BlockedEpetraLinearObjContainer BLOC;
560
561 int numBlocks = 3;
562 int myRank = tComm->getRank();
563 int numProc = tComm->getSize();
564
565 RCP<const panzer::BlockedDOFManager> blkIndexer = buildBlockedIndexer(myRank,numProc,numBlocks);
566
567 BlockedEpetraLinearObjFactory<panzer::Traits,int> factory(tComm,blkIndexer);
568
569 RCP<LinearObjContainer> container = factory.buildLinearObjContainer();
570 RCP<LinearObjContainer> ghosted = factory.buildGhostedLinearObjContainer();
571 TEST_ASSERT(container!=Teuchos::null);
572 TEST_ASSERT(ghosted!=Teuchos::null);
573
574 RCP<BLOC> bContainer = rcp_dynamic_cast<BLOC>(container);
575 RCP<BLOC> b_ghosted = rcp_dynamic_cast<BLOC>(ghosted);
576 TEST_ASSERT(bContainer!=Teuchos::null);
577 TEST_ASSERT(b_ghosted!=Teuchos::null);
578
579 // tests global initialize
580 {
581 // Generic code
582 /////////////////////////////////////////////////////////////
583
584 // test individial initializers
585 factory.initializeContainer(LOC::X,*container);
586 TEST_ASSERT(bContainer->get_x()!=Teuchos::null);
587 TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null)
588 TEST_EQUALITY(bContainer->get_f(), Teuchos::null)
589 TEST_EQUALITY(bContainer->get_A(), Teuchos::null)
590
591 factory.initializeContainer(LOC::DxDt,*container);
592 TEST_EQUALITY(bContainer->get_x(), Teuchos::null)
593 TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null);
594 TEST_EQUALITY(bContainer->get_f(), Teuchos::null)
595 TEST_EQUALITY(bContainer->get_A(), Teuchos::null)
596
597 factory.initializeContainer(LOC::F,*container);
598 TEST_EQUALITY(bContainer->get_x(), Teuchos::null)
599 TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null)
600 TEST_ASSERT(bContainer->get_f()!=Teuchos::null);
601 TEST_EQUALITY(bContainer->get_A(), Teuchos::null)
602
603 factory.initializeContainer(LOC::Mat,*container);
604 TEST_EQUALITY(bContainer->get_x(), Teuchos::null)
605 TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null)
606 TEST_EQUALITY(bContainer->get_f(), Teuchos::null)
607 TEST_ASSERT(bContainer->get_A()!=Teuchos::null);
608
609 // jacobian and residual vector output
610 factory.initializeContainer(LOC::F | LOC::Mat,*container);
611 TEST_EQUALITY(bContainer->get_x(), Teuchos::null)
612 TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null)
613 TEST_ASSERT(bContainer->get_f()!=Teuchos::null);
614 TEST_ASSERT(bContainer->get_A()!=Teuchos::null);
615
616 // x and time dertivative input
617 factory.initializeContainer(LOC::X | LOC::DxDt,*container);
618 TEST_ASSERT(bContainer->get_x()!=Teuchos::null);
619 TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null);
620 TEST_EQUALITY(bContainer->get_f(), Teuchos::null)
621 TEST_EQUALITY(bContainer->get_A(), Teuchos::null)
622
623 // everything
624 factory.initializeContainer(LOC::X | LOC::DxDt | LOC::F | LOC::Mat,*container);
625 TEST_ASSERT(bContainer->get_x()!=Teuchos::null);
626 TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null);
627 TEST_ASSERT(bContainer->get_f()!=Teuchos::null);
628 TEST_ASSERT(bContainer->get_A()!=Teuchos::null);
629
630 // Epetra specific code
631 /////////////////////////////////////////////////////////////
632
633 // test individial initializers
634 factory.initializeContainer(LOC::X,*bContainer);
635 TEST_ASSERT(bContainer->get_x()!=Teuchos::null);
636 TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null)
637 TEST_EQUALITY(bContainer->get_f(), Teuchos::null)
638 TEST_EQUALITY(bContainer->get_A(), Teuchos::null)
639
640 factory.initializeContainer(LOC::DxDt,*bContainer);
641 TEST_EQUALITY(bContainer->get_x(), Teuchos::null)
642 TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null);
643 TEST_EQUALITY(bContainer->get_f(), Teuchos::null)
644 TEST_EQUALITY(bContainer->get_A(), Teuchos::null)
645
646 factory.initializeContainer(LOC::F,*bContainer);
647 TEST_EQUALITY(bContainer->get_x(), Teuchos::null)
648 TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null)
649 TEST_ASSERT(bContainer->get_f()!=Teuchos::null);
650 TEST_EQUALITY(bContainer->get_A(), Teuchos::null)
651
652 factory.initializeContainer(LOC::Mat,*bContainer);
653 TEST_EQUALITY(bContainer->get_x(), Teuchos::null)
654 TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null)
655 TEST_EQUALITY(bContainer->get_f(), Teuchos::null)
656 TEST_ASSERT(bContainer->get_A()!=Teuchos::null);
657
658 // jacobian and residual vector output
659 factory.initializeContainer(LOC::F | LOC::Mat,*bContainer);
660 TEST_EQUALITY(bContainer->get_x(), Teuchos::null)
661 TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null)
662 TEST_ASSERT(bContainer->get_f()!=Teuchos::null);
663 TEST_ASSERT(bContainer->get_A()!=Teuchos::null);
664
665 // x and time dertivative input
666 factory.initializeContainer(LOC::X | LOC::DxDt,*bContainer);
667 TEST_ASSERT(bContainer->get_x()!=Teuchos::null);
668 TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null);
669 TEST_EQUALITY(bContainer->get_f(), Teuchos::null)
670 TEST_EQUALITY(bContainer->get_A(), Teuchos::null)
671
672 // everything
673 factory.initializeContainer(LOC::X | LOC::DxDt | LOC::F | LOC::Mat,*bContainer);
674 TEST_ASSERT(bContainer->get_x()!=Teuchos::null);
675 TEST_ASSERT(bContainer->get_dxdt()!=Teuchos::null);
676 TEST_ASSERT(bContainer->get_f()!=Teuchos::null);
677 TEST_ASSERT(bContainer->get_A()!=Teuchos::null);
678 }
679 }
680
681 TEUCHOS_UNIT_TEST(tBlockedEpetraLinearObjFactory, ghostToGlobal)
682 {
683
684 // build global (or serial communicator)
685 #ifdef HAVE_MPI
686 Teuchos::RCP<Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD));
687 #else
688 NOPE_PANZER_DOESNT_SUPPORT_SERIAL
689 #endif
690
691 using Teuchos::RCP;
692 using Teuchos::rcp;
693 using Teuchos::rcp_dynamic_cast;
694 using Thyra::ProductVectorBase;
695 using Thyra::SpmdVectorBase;
696
697 // pauseToAttach();
698
699 int numBlocks = 2;
700 int myRank = tComm->getRank();
701 int numProc = tComm->getSize();
702
703 RCP<const panzer::BlockedDOFManager> blkIndexer = buildBlockedIndexer(myRank,numProc,numBlocks);
704
705 out << "Built indexer = " << blkIndexer << std::endl;
706 Teuchos::RCP<BlockedEpetraLinearObjFactory<panzer::Traits,int> > la_factory
707 = Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(tComm,blkIndexer));
708
709 out << "LA Factory = " << la_factory << std::endl;
710
711 Teuchos::RCP<LinearObjContainer> global = la_factory->buildLinearObjContainer();
712 Teuchos::RCP<LinearObjContainer> ghosted = la_factory->buildGhostedLinearObjContainer();
713
714 out << "LOC = " << global << " " << ghosted << std::endl;
715
716 la_factory->initializeContainer(LinearObjContainer::Mat,*global);
717 la_factory->initializeGhostedContainer(LinearObjContainer::Mat,*ghosted);
718
719 out << "Initialized matrices" << std::endl;
720
721 Teuchos::rcp_dynamic_cast<BlockedEpetraLinearObjContainer>(ghosted)->initializeMatrix(1.0);
722
723 out << "Initialize matrix" << std::endl;
724
725 la_factory->ghostToGlobalContainer(*ghosted,*global,LinearObjContainer::Mat);
726
727 out << "GhostToGlobal" << std::endl;
728
729 Teuchos::RCP<Thyra::LinearOpBase<double> > th_A = Teuchos::rcp_dynamic_cast<BlockedEpetraLinearObjContainer>(global)->get_A();
730 Teuchos::RCP<Thyra::BlockedLinearOpBase<double> > blk_A = Teuchos::rcp_dynamic_cast<Thyra::BlockedLinearOpBase<double> >(th_A);
731
732 out << "Blk A " << blk_A << std::endl;
733 out << "Blk A " << Teuchos::describe(*blk_A,Teuchos::VERB_MEDIUM) << std::endl;
734
735 Teuchos::RCP<Epetra_Operator> cA_00 = Thyra::get_Epetra_Operator(*blk_A->getNonconstBlock(0,0));
736 out << "00" << std::endl;
737
738 Teuchos::RCP<Epetra_Operator> cA_01 = Thyra::get_Epetra_Operator(*blk_A->getNonconstBlock(0,1));
739 out << "01" << std::endl;
740
741 Teuchos::RCP<Epetra_Operator> cA_10 = Thyra::get_Epetra_Operator(*blk_A->getNonconstBlock(1,0));
742 out << "10" << std::endl;
743
744 Teuchos::RCP<Epetra_Operator> cA_11 = Thyra::get_Epetra_Operator(*blk_A->getNonconstBlock(1,1));
745 out << "11" << std::endl;
746
747 Teuchos::RCP<Epetra_CrsMatrix> A_00 = Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(cA_00);
748 Teuchos::RCP<Epetra_CrsMatrix> A_01 = Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(cA_01);
749
750 Teuchos::RCP<Epetra_CrsMatrix> A_10 = Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(cA_10);
751 Teuchos::RCP<Epetra_CrsMatrix> A_11 = Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(cA_11);
752
753 out << "A_00 = \n";
754 A_00->Print(out);
755
756 out << "A_01 = \n";
757 A_01->Print(out);
758
759 out << "A_10 = \n";
760 A_10->Print(out);
761
762 out << "A_11 = \n";
763 A_11->Print(out);
764 }
765
766 TEUCHOS_UNIT_TEST(tBlockedEpetraLinearObjFactory, graph_constr)
767 {
768
769 // build global (or serial communicator)
770 #ifdef HAVE_MPI
771 Teuchos::RCP<Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD));
772 #else
773 NOPE_PANZER_DOESNT_SUPPORT_SERIAL
774 #endif
775
776 using Teuchos::RCP;
777 using Teuchos::rcp;
778 using Teuchos::rcp_dynamic_cast;
779 using Thyra::ProductVectorBase;
780 using Thyra::SpmdVectorBase;
781
782 // pauseToAttach();
783
784 int numBlocks = 2;
785 int myRank = tComm->getRank();
786 int numProc = tComm->getSize();
787
788 RCP<const panzer::BlockedDOFManager> blkIndexer = buildBlockedIndexer(myRank,numProc,numBlocks);
789
790 Teuchos::RCP<BlockedEpetraLinearObjFactory<panzer::Traits,int> > la_factory
791 = Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(tComm,blkIndexer));
792
793 Teuchos::RCP<Epetra_CrsMatrix> A_00 = la_factory->getGhostedEpetraMatrix(0,0); A_00->PutScalar(1.0);
794 Teuchos::RCP<Epetra_CrsMatrix> A_01 = la_factory->getGhostedEpetraMatrix(0,1); A_01->PutScalar(1.0);
795
796 Teuchos::RCP<Epetra_CrsMatrix> A_10 = la_factory->getGhostedEpetraMatrix(1,0); A_10->PutScalar(1.0);
797 Teuchos::RCP<Epetra_CrsMatrix> A_11 = la_factory->getGhostedEpetraMatrix(1,1); A_11->PutScalar(1.0);
798
799 std::cout << "A_00 = \n";
800 A_00->Print(out);
801
802 std::cout << "A_01 = \n";
803 A_01->Print(out);
804
805 std::cout << "A_10 = \n";
806 A_10->Print(out);
807
808 std::cout << "A_11 = \n";
809 A_11->Print(out);
810 }
811
812 TEUCHOS_UNIT_TEST(tBlockedEpetraLinearObjFactory, adjustDirichlet)
813 {
814
815 // build global (or serial communicator)
816 #ifdef HAVE_MPI
817 Teuchos::RCP<Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD));
818 #else
819 NOPE_PANZER_DOESNT_SUPPORT_SERIAL
820 #endif
821
822 using Teuchos::RCP;
823 using Teuchos::rcp;
824 using Teuchos::rcp_dynamic_cast;
825 using Thyra::ProductVectorBase;
826 using Thyra::SpmdVectorBase;
827
828 // pauseToAttach();
829
830 int numBlocks = 3;
831 int myRank = tComm->getRank();
832 int numProc = tComm->getSize();
833
834 typedef BlockedEpetraLinearObjContainer BLOC;
835
836 RCP<const panzer::BlockedDOFManager> blkIndexer = buildBlockedIndexer(myRank,numProc,numBlocks);
837
838 Teuchos::RCP<BlockedEpetraLinearObjFactory<panzer::Traits,int> > la_factory
839 = Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(tComm,blkIndexer));
840
841 RCP<LinearObjContainer> ghosted_0 = la_factory->buildGhostedLinearObjContainer();
842 RCP<LinearObjContainer> ghosted_1 = la_factory->buildGhostedLinearObjContainer();
843 RCP<LinearObjContainer> ghosted_sys = la_factory->buildGhostedLinearObjContainer();
844
845 la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_0);
846 la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_1);
847 la_factory->initializeGhostedContainer(LinearObjContainer::F | LinearObjContainer::Mat,*ghosted_sys);
848
849 RCP<BLOC> b_0 = rcp_dynamic_cast<BLOC>(ghosted_0);
850 RCP<BLOC> b_1 = rcp_dynamic_cast<BLOC>(ghosted_1);
851 RCP<BLOC> b_sys = rcp_dynamic_cast<BLOC>(ghosted_sys);
852
853 TEST_ASSERT(!Teuchos::is_null(b_0->get_f()));
854 TEST_ASSERT(!Teuchos::is_null(b_1->get_f()));
855 TEST_ASSERT(!Teuchos::is_null(b_sys->get_f()));
856 TEST_ASSERT(!Teuchos::is_null(b_sys->get_A()));
857
858 Thyra::assign(b_0->get_f().ptr(),0.0); // put some garbage in the systems
859 Thyra::assign(b_1->get_f().ptr(),0.0); // put some garbage in the systems
860 Thyra::assign(b_sys->get_f().ptr(),-3.0); // put some garbage in the systems
861
862 // b_sys->get_A()->PutScalar(-3.0);
863 for(int i=0;i<numBlocks;i++)
864 for(int j=0;j<numBlocks;j++)
865 getSubBlock(i,j,*b_sys->get_A())->PutScalar(-3.0);
866
867 // there are 3 cases for adjustDirichlet
868 // 1. Local set only for GID
869 // 2. Set on multiple processors
870 // 3. Set remotely
871
872 if(myRank==0) {
873 for(int i=0;i<numBlocks;i++) {
874 RCP<Thyra::VectorBase<double> > x_0 = rcp_dynamic_cast<ProductVectorBase<double> >(b_0->get_f())->getNonconstVectorBlock(i);
875 RCP<Thyra::VectorBase<double> > x_1 = rcp_dynamic_cast<ProductVectorBase<double> >(b_1->get_f())->getNonconstVectorBlock(i);
876
877 Teuchos::ArrayRCP<double> data_0,data_1;
878 rcp_dynamic_cast<SpmdVectorBase<double> >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0));
879 rcp_dynamic_cast<SpmdVectorBase<double> >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1));
880
881 // case 0
882 data_0[0] = 1.0; // GID = 0
883 data_1[0] = 1.0;
884
885 // case 1
886 data_0[2] = 1.0; // GID = 2
887 data_1[2] = 2.0;
888
889 // case 2
890 data_1[5] = 2.0; // GID = 5
891 }
892 }
893 else if(myRank==1) {
894 for(int i=0;i<numBlocks;i++) {
895 RCP<Thyra::VectorBase<double> > x_0 = rcp_dynamic_cast<ProductVectorBase<double> >(b_0->get_f())->getNonconstVectorBlock(i);
896 RCP<Thyra::VectorBase<double> > x_1 = rcp_dynamic_cast<ProductVectorBase<double> >(b_1->get_f())->getNonconstVectorBlock(i);
897
898 Teuchos::ArrayRCP<double> data_0,data_1;
899 rcp_dynamic_cast<SpmdVectorBase<double> >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0));
900 rcp_dynamic_cast<SpmdVectorBase<double> >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1));
901
902 // case 0
903 data_0[3] = 1.0; // GID = 9
904 data_1[3] = 1.0;
905
906 // case 1
907 data_0[0] = 1.0; // GID =2
908 data_1[0] = 2.0;
909
910 // case 2
911 data_1[6] = 2.0; // GID = 4
912 }
913 }
914 else
915 TEUCHOS_ASSERT(false);
916
917 out << "LOCAL " << std::endl;
918 b_0->get_f()->describe(out,Teuchos::VERB_HIGH);
919 out << std::endl;
920 out << "GLOBAL " << std::endl;
921 b_1->get_f()->describe(out,Teuchos::VERB_HIGH);
922 out << std::endl;
923
924 // run test for conditions
925 la_factory->adjustForDirichletConditions(*ghosted_0,*ghosted_1,*ghosted_sys);
926
927 int numEntries = 0;
928 double * values = 0;
929 int * indices = 0;
930
931 if(myRank==0) {
932 RCP<const Thyra::LinearOpBase<double> > A = b_sys->get_A();
933
934 for(int i=0;i<numBlocks;i++) {
935 Teuchos::ArrayRCP<const double> data;
936 RCP<const Thyra::VectorBase<double> > f = rcp_dynamic_cast<ProductVectorBase<double> >(b_sys->get_f())->getVectorBlock(i);
937 rcp_dynamic_cast<const SpmdVectorBase<double> >(f)->getLocalData(Teuchos::ptrFromRef(data));
938
939 TEST_EQUALITY(data[0],-3.0); // case 0
940 TEST_EQUALITY(data[2],-3.0/2.0); // case 1
941 TEST_EQUALITY(data[5],0.0); // case 2
942
943 for(int j=0;j<numBlocks;j++) {
944 RCP<const Epetra_CrsMatrix> subA = getSubBlock(i,j,*A);
945
946 subA->ExtractMyRowView(0,numEntries,values,indices);
947 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0);
948
949 subA->ExtractMyRowView(2,numEntries,values,indices);
950 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0/2.0);
951
952 subA->ExtractMyRowView(5,numEntries,values,indices);
953 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],0.0);
954 }
955 }
956 }
957 else if(myRank==1) {
958 RCP<const Thyra::LinearOpBase<double> > A = b_sys->get_A();
959
960 for(int i=0;i<numBlocks;i++) {
961 Teuchos::ArrayRCP<const double> data;
962 RCP<const Thyra::VectorBase<double> > f = rcp_dynamic_cast<ProductVectorBase<double> >(b_sys->get_f())->getVectorBlock(i);
963 rcp_dynamic_cast<const SpmdVectorBase<double> >(f)->getLocalData(Teuchos::ptrFromRef(data));
964
965 TEST_EQUALITY(data[3],-3.0); // case 0
966 TEST_EQUALITY(data[0],-3.0/2.0); // case 1
967 TEST_EQUALITY(data[6],0.0); // case 2
968
969 for(int j=0;j<numBlocks;j++) {
970 RCP<const Epetra_CrsMatrix> subA = getSubBlock(i,j,*A);
971
972 subA->ExtractMyRowView(3,numEntries,values,indices);
973 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0);
974
975 subA->ExtractMyRowView(0,numEntries,values,indices);
976 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0/2.0);
977
978 subA->ExtractMyRowView(6,numEntries,values,indices);
979 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],0.0);
980 }
981 }
982 }
983 else
984 TEUCHOS_ASSERT(false);
985 }
986
987 TEUCHOS_UNIT_TEST(tBlockedEpetraLinearObjFactory, node_cell)
988 {
989
990 // build global (or serial communicator)
991 #ifdef HAVE_MPI
992 Teuchos::RCP<Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD));
993 #else
994 NOPE_PANZER_DOESNT_SUPPORT_SERIAL
995 #endif
996
997 using Teuchos::RCP;
998 using Teuchos::rcp;
999 using Teuchos::rcp_dynamic_cast;
1000 using Thyra::ProductVectorBase;
1001 using Thyra::SpmdVectorBase;
1002
1003 // pauseToAttach();
1004
1005 int numBlocks = 2;
1006 int myRank = tComm->getRank();
1007 int numProc = tComm->getSize();
1008
1009 typedef BlockedEpetraLinearObjContainer BLOC;
1010
1011 RCP<const panzer::BlockedDOFManager> blkIndexer = buildBlockedIndexer(myRank,numProc,numBlocks);
1012
1013 Teuchos::RCP<BlockedEpetraLinearObjFactory<panzer::Traits,int> > la_factory
1014 = Teuchos::rcp(new panzer::BlockedEpetraLinearObjFactory<panzer::Traits,int>(tComm,blkIndexer));
1015
1016 RCP<LinearObjContainer> ghosted_0 = la_factory->buildGhostedLinearObjContainer();
1017 RCP<LinearObjContainer> ghosted_1 = la_factory->buildGhostedLinearObjContainer();
1018 RCP<LinearObjContainer> ghosted_sys = la_factory->buildGhostedLinearObjContainer();
1019
1020 la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_0);
1021 la_factory->initializeGhostedContainer(LinearObjContainer::F,*ghosted_1);
1022 la_factory->initializeGhostedContainer(LinearObjContainer::F | LinearObjContainer::Mat,*ghosted_sys);
1023
1024 RCP<BLOC> b_0 = rcp_dynamic_cast<BLOC>(ghosted_0);
1025 RCP<BLOC> b_1 = rcp_dynamic_cast<BLOC>(ghosted_1);
1026 RCP<BLOC> b_sys = rcp_dynamic_cast<BLOC>(ghosted_sys);
1027
1028 TEST_ASSERT(!Teuchos::is_null(b_0->get_f()));
1029 TEST_ASSERT(!Teuchos::is_null(b_1->get_f()));
1030 TEST_ASSERT(!Teuchos::is_null(b_sys->get_f()));
1031 TEST_ASSERT(!Teuchos::is_null(b_sys->get_A()));
1032
1033 Thyra::assign(b_0->get_f().ptr(),0.0); // put some garbage in the systems
1034 Thyra::assign(b_1->get_f().ptr(),0.0); // put some garbage in the systems
1035 Thyra::assign(b_sys->get_f().ptr(),-3.0); // put some garbage in the systems
1036
1037 // b_sys->get_A()->PutScalar(-3.0);
1038 for(int i=0;i<numBlocks;i++)
1039 for(int j=0;j<numBlocks;j++)
1040 getSubBlock(i,j,*b_sys->get_A())->PutScalar(-3.0);
1041
1042 // there are 3 cases for adjustDirichlet
1043 // 1. Local set only for GID
1044 // 2. Set on multiple processors
1045 // 3. Set remotely
1046
1047 if(myRank==0) {
1048 RCP<Thyra::VectorBase<double> > x_0 = rcp_dynamic_cast<ProductVectorBase<double> >(b_0->get_f())->getNonconstVectorBlock(0);
1049 RCP<Thyra::VectorBase<double> > x_1 = rcp_dynamic_cast<ProductVectorBase<double> >(b_1->get_f())->getNonconstVectorBlock(0);
1050
1051 Teuchos::ArrayRCP<double> data_0,data_1;
1052 rcp_dynamic_cast<SpmdVectorBase<double> >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0));
1053 rcp_dynamic_cast<SpmdVectorBase<double> >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1));
1054
1055 // case 0
1056 data_0[0] = 1.0; // GID = 0
1057 data_1[0] = 1.0;
1058
1059 // case 1
1060 data_0[2] = 1.0; // GID = 2
1061 data_1[2] = 2.0;
1062
1063 // case 2
1064 data_1[5] = 2.0; // GID = 5
1065
1066 {
1067 x_0 = rcp_dynamic_cast<ProductVectorBase<double> >(b_0->get_f())->getNonconstVectorBlock(1);
1068 x_1 = rcp_dynamic_cast<ProductVectorBase<double> >(b_1->get_f())->getNonconstVectorBlock(1);
1069
1070 rcp_dynamic_cast<SpmdVectorBase<double> >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0));
1071 rcp_dynamic_cast<SpmdVectorBase<double> >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1));
1072
1073 data_1[0] = 2.0;
1074 }
1075 }
1076 else if(myRank==1) {
1077 RCP<Thyra::VectorBase<double> > x_0 = rcp_dynamic_cast<ProductVectorBase<double> >(b_0->get_f())->getNonconstVectorBlock(0);
1078 RCP<Thyra::VectorBase<double> > x_1 = rcp_dynamic_cast<ProductVectorBase<double> >(b_1->get_f())->getNonconstVectorBlock(0);
1079
1080 Teuchos::ArrayRCP<double> data_0,data_1;
1081 rcp_dynamic_cast<SpmdVectorBase<double> >(x_0)->getNonconstLocalData(Teuchos::ptrFromRef(data_0));
1082 rcp_dynamic_cast<SpmdVectorBase<double> >(x_1)->getNonconstLocalData(Teuchos::ptrFromRef(data_1));
1083
1084 // case 0
1085 data_0[3] = 1.0; // GID = 9
1086 data_1[3] = 1.0;
1087
1088 // case 1
1089 data_0[0] = 1.0; // GID =2
1090 data_1[0] = 2.0;
1091
1092 // case 2
1093 data_1[6] = 2.0; // GID = 4
1094 }
1095 else
1096 TEUCHOS_ASSERT(false);
1097
1098 out << "LOCAL " << std::endl;
1099 b_0->get_f()->describe(out,Teuchos::VERB_HIGH);
1100 out << std::endl;
1101 out << "GLOBAL " << std::endl;
1102 b_1->get_f()->describe(out,Teuchos::VERB_HIGH);
1103 out << std::endl;
1104
1105 // run test for conditions
1106 la_factory->adjustForDirichletConditions(*ghosted_0,*ghosted_1,*ghosted_sys);
1107
1108 int numEntries = 0;
1109 double * values = 0;
1110 int * indices = 0;
1111
1112 if(myRank==0) {
1113 RCP<const Thyra::LinearOpBase<double> > A = b_sys->get_A();
1114
1115 int i = 0;
1116 {
1117 Teuchos::ArrayRCP<const double> data;
1118 RCP<const Thyra::VectorBase<double> > f = rcp_dynamic_cast<ProductVectorBase<double> >(b_sys->get_f())->getVectorBlock(i);
1119 rcp_dynamic_cast<const SpmdVectorBase<double> >(f)->getLocalData(Teuchos::ptrFromRef(data));
1120
1121 TEST_EQUALITY(data[0],-3.0); // case 0
1122 TEST_EQUALITY(data[2],-3.0/2.0); // case 1
1123 TEST_EQUALITY(data[5],0.0); // case 2
1124
1125 for(int j=0;j<numBlocks;j++) {
1126 RCP<const Epetra_CrsMatrix> subA = getSubBlock(i,j,*A);
1127
1128 subA->ExtractMyRowView(0,numEntries,values,indices);
1129 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0);
1130
1131 subA->ExtractMyRowView(2,numEntries,values,indices);
1132 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0/2.0);
1133
1134 subA->ExtractMyRowView(5,numEntries,values,indices);
1135 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],0.0);
1136 }
1137 }
1138
1139 i = 1;
1140 {
1141 Teuchos::ArrayRCP<const double> data;
1142 RCP<const Thyra::VectorBase<double> > f = rcp_dynamic_cast<ProductVectorBase<double> >(b_sys->get_f())->getVectorBlock(i);
1143 rcp_dynamic_cast<const SpmdVectorBase<double> >(f)->getLocalData(Teuchos::ptrFromRef(data));
1144
1145 TEST_EQUALITY(data[0],0.0);
1146
1147 for(int j=0;j<numBlocks;j++) {
1148 RCP<const Epetra_CrsMatrix> subA = getSubBlock(i,j,*A);
1149
1150 subA->ExtractMyRowView(0,numEntries,values,indices);
1151 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],0.0);
1152 }
1153 }
1154 }
1155 else if(myRank==1) {
1156 RCP<const Thyra::LinearOpBase<double> > A = b_sys->get_A();
1157
1158 int i = 0;
1159 {
1160 Teuchos::ArrayRCP<const double> data;
1161 RCP<const Thyra::VectorBase<double> > f = rcp_dynamic_cast<ProductVectorBase<double> >(b_sys->get_f())->getVectorBlock(i);
1162 rcp_dynamic_cast<const SpmdVectorBase<double> >(f)->getLocalData(Teuchos::ptrFromRef(data));
1163
1164 TEST_EQUALITY(data[3],-3.0); // case 0
1165 TEST_EQUALITY(data[0],-3.0/2.0); // case 1
1166 TEST_EQUALITY(data[6],0.0); // case 2
1167
1168 for(int j=0;j<numBlocks;j++) {
1169 RCP<const Epetra_CrsMatrix> subA = getSubBlock(i,j,*A);
1170
1171 subA->ExtractMyRowView(3,numEntries,values,indices);
1172 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0);
1173
1174 subA->ExtractMyRowView(0,numEntries,values,indices);
1175 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0/2.0);
1176
1177 subA->ExtractMyRowView(6,numEntries,values,indices);
1178 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],0.0);
1179 }
1180 }
1181
1182 i = 1;
1183 {
1184 Teuchos::ArrayRCP<const double> data;
1185 RCP<const Thyra::VectorBase<double> > f = rcp_dynamic_cast<ProductVectorBase<double> >(b_sys->get_f())->getVectorBlock(i);
1186 rcp_dynamic_cast<const SpmdVectorBase<double> >(f)->getLocalData(Teuchos::ptrFromRef(data));
1187
1188 TEST_EQUALITY(data[0],-3.0);
1189
1190 for(int j=0;j<numBlocks;j++) {
1191 RCP<const Epetra_CrsMatrix> subA = getSubBlock(i,j,*A);
1192
1193 subA->ExtractMyRowView(0,numEntries,values,indices);
1194 for(int k=0;k<numEntries;k++) TEST_EQUALITY(values[k],-3.0);
1195 }
1196 }
1197 }
1198 else
1199 TEUCHOS_ASSERT(false);
1200 }
1201
1202 TEUCHOS_UNIT_TEST(tBlockedEpetraLinearObjFactory, exclusion)
1203 {
1204 #ifdef HAVE_MPI
1205 Teuchos::RCP<Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD));
1206 #else
1207 NOPE_PANZER_DOESNT_SUPPORT_SERIAL
1208 #endif
1209
1210 using Teuchos::RCP;
1211 using Teuchos::rcp;
1212 using Teuchos::rcp_dynamic_cast;
1213
1214 // pauseToAttach();
1215
1216 typedef LinearObjContainer LOC;
1217 typedef BlockedEpetraLinearObjContainer BLOC;
1218
1219 int numBlocks = 3;
1220 int myRank = tComm->getRank();
1221 int numProc = tComm->getSize();
1222
1223 RCP<const panzer::BlockedDOFManager> blkIndexer = buildBlockedIndexer(myRank,numProc,numBlocks);
1224
1225 BlockedEpetraLinearObjFactory<panzer::Traits,int> factory(tComm,blkIndexer);
1226
1227 // exclude some pairs
1228 std::vector<std::pair<int,int> > exPairs;
1229 exPairs.push_back(std::make_pair(0,2));
1230 exPairs.push_back(std::make_pair(2,1));
1231 factory.addExcludedPairs(exPairs);
1232 factory.addExcludedPair(1,2);
1233
1234 RCP<LinearObjContainer> container = factory.buildLinearObjContainer();
1235 RCP<LinearObjContainer> ghosted = factory.buildGhostedLinearObjContainer();
1236 TEST_ASSERT(container!=Teuchos::null);
1237 TEST_ASSERT(ghosted!=Teuchos::null);
1238
1239 RCP<BLOC> bContainer = rcp_dynamic_cast<BLOC>(container);
1240 RCP<BLOC> b_ghosted = rcp_dynamic_cast<BLOC>(ghosted);
1241 TEST_ASSERT(bContainer!=Teuchos::null);
1242 TEST_ASSERT(b_ghosted!=Teuchos::null);
1243
1244 // tests global initialize
1245 {
1246 // Generic code
1247 /////////////////////////////////////////////////////////////
1248 factory.initializeContainer(LOC::Mat,*container);
1249 TEST_EQUALITY(bContainer->get_x(), Teuchos::null)
1250 TEST_EQUALITY(bContainer->get_dxdt(), Teuchos::null)
1251 TEST_EQUALITY(bContainer->get_f(), Teuchos::null)
1252 TEST_ASSERT(bContainer->get_A()!=Teuchos::null);
1253
1254 RCP<Thyra::BlockedLinearOpBase<double> > blo
1255 = rcp_dynamic_cast<Thyra::BlockedLinearOpBase<double> >(bContainer->get_A());
1256
1257 TEST_ASSERT(!blo->getNonconstBlock(0,0).is_null());
1258 TEST_ASSERT(!blo->getNonconstBlock(0,1).is_null());
1259 TEST_ASSERT(blo->getNonconstBlock(0,2).is_null());
1260
1261 TEST_ASSERT(!blo->getNonconstBlock(1,0).is_null());
1262 TEST_ASSERT(!blo->getNonconstBlock(1,1).is_null());
1263 TEST_ASSERT(blo->getNonconstBlock(1,2).is_null());
1264
1265 TEST_ASSERT(!blo->getNonconstBlock(2,0).is_null());
1266 TEST_ASSERT(blo->getNonconstBlock(2,1).is_null());
1267 TEST_ASSERT(!blo->getNonconstBlock(2,2).is_null());
1268 }
1269 }
1270
1271 }