43 #include "PanzerAdaptersSTK_config.hpp"
49 #include "Teuchos_AbstractFactoryStd.hpp"
51 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
53 #ifdef PANZER_HAVE_EPETRA_STACK
54 #include "Epetra_MpiComm.h"
55 #include "Epetra_Vector.h"
57 #endif // PANZER_HAVE_EPETRA_STACK
59 #include "Tpetra_Map.hpp"
60 #include "Tpetra_MultiVector.hpp"
62 #ifdef PANZER_HAVE_TEKO
63 #include "Teko_StratimikosFactory.hpp"
66 #ifdef PANZER_HAVE_MUELU
67 #include "Stratimikos_MueLuHelpers.hpp"
69 #include "Xpetra_MapFactory.hpp"
70 #include "Xpetra_MultiVectorFactory.hpp"
73 namespace panzer_stk {
80 std::vector<std::string> elementBlocks;
84 std::set<int> runningFields;
87 runningFields.insert(fields.begin(),fields.end());
91 for(std::size_t i=1;i<elementBlocks.size();i++) {
94 std::set<int> currentFields(runningFields);
95 runningFields.clear();
96 std::set_intersection(fields.begin(),fields.end(),
97 currentFields.begin(),currentFields.end(),
98 std::inserter(runningFields,runningFields.begin()));
101 if(runningFields.size()<1)
110 const std::string & fieldName,
113 std::vector<std::string> elementBlocks;
116 for(std::size_t e=0;e<elementBlocks.size();e++) {
117 std::string blockId = elementBlocks[e];
120 fieldPatterns[blockId] =
121 Teuchos::rcp_dynamic_cast<const panzer::Intrepid2FieldPattern>(globalIndexer.
getFieldPattern(blockId,fieldName),
true);
127 const std::string & fieldName,
131 using Teuchos::ptrFromRef;
132 using Teuchos::ptr_dynamic_cast;
137 Ptr<const DOFManager> dofManager = ptr_dynamic_cast<
const DOFManager>(ptrFromRef(globalIndexer));
139 if(dofManager!=Teuchos::null) {
140 fillFieldPatternMap(*dofManager,fieldName,fieldPatterns);
154 #ifdef PANZER_HAVE_TEKO
157 bool writeCoordinates,
165 using Teuchos::rcp_dynamic_cast;
167 Stratimikos::DefaultLinearSolverBuilder linearSolverBuilder;
173 #ifdef PANZER_HAVE_MUELU
175 Stratimikos::enableMueLu<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLu");
176 Stratimikos::enableMueLuRefMaxwell<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLuRefMaxwell");
177 Stratimikos::enableMueLuMaxwell1<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLuMaxwell1");
178 #ifndef PANZER_HIDE_DEPRECATED_CODE
180 Stratimikos::enableMueLu<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLu-Tpetra");
181 Stratimikos::enableMueLuRefMaxwell<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLuRefMaxwell-Tpetra");
186 #ifdef PANZER_HAVE_TEKO
189 if(!blockedAssembly) {
191 std::string fieldName;
196 if(reqHandler_local==Teuchos::null)
197 reqHandler_local =
rcp(
new Teko::RequestHandler);
200 if(determineCoordinateField(*globalIndexer,fieldName)) {
201 std::map<std::string,RCP<const panzer::Intrepid2FieldPattern> > fieldPatterns;
202 fillFieldPatternMap(*globalIndexer,fieldName,fieldPatterns);
205 panzer_stk::ParameterListCallback(fieldName,fieldPatterns,stkConn_manager,
206 rcp_dynamic_cast<const panzer::GlobalIndexer>(globalIndexer)));
207 reqHandler_local->addRequestCallback(callback);
264 if(writeCoordinates) {
265 #ifdef PANZER_HAVE_EPETRA_STACK
270 const std::vector<double> & xcoords = callback->getXCoordsVector();
271 const std::vector<double> & ycoords = callback->getYCoordsVector();
272 const std::vector<double> & zcoords = callback->getZCoordsVector();
297 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::runtime_error,
"ERROR: Panzer_STK_SetupLOWSFactory.cpp - writeCoordinates not implemented for Tpetra yet!");
301 #ifdef PANZER_HAVE_MUELU
302 if(rcp_dynamic_cast<const panzer::GlobalIndexer>(globalIndexer)!=Teuchos::null
304 if(!writeCoordinates)
307 typedef Tpetra::Map<int,panzer::GlobalOrdinal,panzer::TpetraNodeType> Map;
308 typedef Tpetra::MultiVector<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType> MV;
311 unsigned dim = Teuchos::as<unsigned>(spatialDim);
313 for(
unsigned d=0;d<dim;d++) {
314 const std::vector<double> & coord = callback->getCoordsVector(d);
317 if(coords==Teuchos::null) {
321 std::vector<panzer::GlobalOrdinal> ownedIndices;
324 coords =
rcp(
new MV(coords_map,dim));
328 coords =
rcp(
new MV(coords_map,dim));
337 for(std::size_t i=0;i<coord.size();i++)
343 muelu_params.
set<
RCP<MV> >(
"Coordinates",coords);
349 Teko::addTekoToStratimikosBuilder(linearSolverBuilder,reqHandler_local);
353 if(reqHandler_local==Teuchos::null)
354 reqHandler_local =
rcp(
new Teko::RequestHandler);
356 std::string fieldName;
357 if(determineCoordinateField(*globalIndexer,fieldName)) {
363 rcp(
new panzer_stk::ParameterListCallbackBlocked(stkConn_manager,blkDofs,auxBlkDofs));
364 reqHandler_local->addRequestCallback(callback);
367 Teko::addTekoToStratimikosBuilder(linearSolverBuilder,reqHandler_local);
369 if(writeCoordinates) {
370 #ifdef PANZER_HAVE_EPETRA_STACK
375 const std::vector<RCP<panzer::GlobalIndexer>> & dofVec
377 for(std::size_t i=0;i<dofVec.size();i++) {
382 std::map<std::string,RCP<const panzer::Intrepid2FieldPattern> > fieldPatterns;
383 fillFieldPatternMap(*dofVec[i],fieldName,fieldPatterns);
384 panzer_stk::ParameterListCallback plCall(fieldName,fieldPatterns,stkConn_manager,dofVec[i]);
385 plCall.buildArrayToVector();
386 plCall.buildCoordinates();
389 const std::vector<double> & xcoords = plCall.getXCoordsVector();
390 const std::vector<double> & ycoords = plCall.getYCoordsVector();
391 const std::vector<double> & zcoords = plCall.getZCoordsVector();
417 #ifdef PANZER_HAVE_MUELU
420 typedef Xpetra::Map<int,panzer::GlobalOrdinal> Map;
421 typedef Xpetra::MultiVector<double,int,panzer::GlobalOrdinal> MV;
424 RCP<const Map> coords_map = Xpetra::MapFactory<int,panzer::GlobalOrdinal>::Build(Xpetra::UseEpetra,
432 unsigned dim = Teuchos::as<unsigned>(spatialDim);
434 RCP<MV> coords = Xpetra::MultiVectorFactory<double,int,panzer::GlobalOrdinal>::Build(coords_map,spatialDim);
436 for(
unsigned d=0;d<dim;d++) {
442 for(std::size_t j=0;j<coords->getLocalLength();++j) {
443 if (d == 0) dest[j] = xcoords[j];
444 if (d == 1) dest[j] = ycoords[j];
445 if (d == 2) dest[j] = zcoords[j];
452 muelu_params.
set<
RCP<MV> >(
"Coordinates",coords);
458 #else // PANZER_HAVE EPETRA
459 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::runtime_error,
"ERROR: Panzer_STK_SetupLOWSFactory - writeCoordinates not implemented for Tpetra yet!")
471 "Topology writing is no longer implemented. It needs to be reimplemented for the "
472 "default DOFManager (estimate 2 days with testing)");
477 linearSolverBuilder.setParameterList(strat_params);
491 #ifdef PANZER_HAVE_TEKO
494 bool writeCoordinates,
500 #ifdef PANZER_HAVE_TEKO
502 if(reqHandler_local==Teuchos::null)
503 reqHandler_local =
Teuchos::rcp(
new Teko::RequestHandler);
508 return buildLOWSFactory(blockedAssembly,globalIndexer,stk_conn_manager,spatialDim,mpi_comm,strat_params,
509 #ifdef PANZER_HAVE_TEKO
520 return Teuchos::null;
bool fieldInBlock(const std::string &field, const std::string &block) const
virtual const std::string & getFieldString(int num) const =0
Reverse lookup of the field string from a field number.
void getElementBlockIds(std::vector< std::string > &elementBlockIds) const
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const std::vector< Teuchos::RCP< GlobalIndexer > > & getFieldDOFManagers() const
virtual void getElementBlockIds(std::vector< std::string > &elementBlockIds) const =0
virtual void getOwnedIndices(std::vector< panzer::GlobalOrdinal > &indices) const =0
Get the set of indices owned by this processor.
virtual int getNumFields() const =0
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool isSublist(const std::string &name) const
Teuchos::RCP< Thyra::LinearOpWithSolveFactoryBase< double > > buildLOWSFactory(bool blockedAssembly, const Teuchos::RCP< const panzer::GlobalIndexer > &globalIndexer, const Teuchos::RCP< panzer_stk::STKConnManager > &stkConn_manager, int spatialDim, const Teuchos::RCP< const Teuchos::MpiComm< int > > &mpi_comm, const Teuchos::RCP< Teuchos::ParameterList > &strat_params, bool writeCoordinates, bool writeTopo, const Teuchos::RCP< const panzer::GlobalIndexer > &auxGlobalIndexer, bool useCoordinates)
int VectorToMatrixMarketFile(const char *filename, const Epetra_Vector &A, const char *matrixName=0, const char *matrixDescription=0, bool writeHeader=true)
virtual const std::vector< int > & getBlockFieldNumbers(const std::string &blockId) const =0
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< const FieldPattern > getFieldPattern(const std::string &name) const
Find a field pattern stored for a particular block and field number. This will retrive the pattern ad...