11 #include "PanzerAdaptersSTK_config.hpp"
17 #include "Teuchos_AbstractFactoryStd.hpp"
19 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
21 #ifdef PANZER_HAVE_EPETRA_STACK
22 #include "Epetra_MpiComm.h"
23 #include "Epetra_Vector.h"
25 #endif // PANZER_HAVE_EPETRA_STACK
27 #include "Tpetra_Map.hpp"
28 #include "Tpetra_MultiVector.hpp"
30 #ifdef PANZER_HAVE_TEKO
31 #include "Teko_StratimikosFactory.hpp"
34 #ifdef PANZER_HAVE_MUELU
35 #include "Stratimikos_MueLuHelpers.hpp"
37 #include "Xpetra_MapFactory.hpp"
38 #include "Xpetra_MultiVectorFactory.hpp"
41 namespace panzer_stk {
48 std::vector<std::string> elementBlocks;
52 std::set<int> runningFields;
55 runningFields.insert(fields.begin(),fields.end());
59 for(std::size_t i=1;i<elementBlocks.size();i++) {
62 std::set<int> currentFields(runningFields);
63 runningFields.clear();
64 std::set_intersection(fields.begin(),fields.end(),
65 currentFields.begin(),currentFields.end(),
66 std::inserter(runningFields,runningFields.begin()));
69 if(runningFields.size()<1)
78 const std::string & fieldName,
81 std::vector<std::string> elementBlocks;
84 for(std::size_t e=0;e<elementBlocks.size();e++) {
85 std::string blockId = elementBlocks[e];
88 fieldPatterns[blockId] =
89 Teuchos::rcp_dynamic_cast<const panzer::Intrepid2FieldPattern>(globalIndexer.
getFieldPattern(blockId,fieldName),
true);
95 const std::string & fieldName,
99 using Teuchos::ptrFromRef;
100 using Teuchos::ptr_dynamic_cast;
105 Ptr<const DOFManager> dofManager = ptr_dynamic_cast<
const DOFManager>(ptrFromRef(globalIndexer));
107 if(dofManager!=Teuchos::null) {
108 fillFieldPatternMap(*dofManager,fieldName,fieldPatterns);
122 #ifdef PANZER_HAVE_TEKO
125 bool writeCoordinates,
133 using Teuchos::rcp_dynamic_cast;
135 Stratimikos::DefaultLinearSolverBuilder linearSolverBuilder;
141 #ifdef PANZER_HAVE_MUELU
143 Stratimikos::enableMueLu<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLu");
144 Stratimikos::enableMueLuRefMaxwell<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLuRefMaxwell");
145 Stratimikos::enableMueLuMaxwell1<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLuMaxwell1");
146 #ifndef PANZER_HIDE_DEPRECATED_CODE
148 Stratimikos::enableMueLu<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLu-Tpetra");
149 Stratimikos::enableMueLuRefMaxwell<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLuRefMaxwell-Tpetra");
154 #ifdef PANZER_HAVE_TEKO
157 if(!blockedAssembly) {
159 std::string fieldName;
164 if(reqHandler_local==Teuchos::null)
165 reqHandler_local =
rcp(
new Teko::RequestHandler);
168 if(determineCoordinateField(*globalIndexer,fieldName)) {
169 std::map<std::string,RCP<const panzer::Intrepid2FieldPattern> > fieldPatterns;
170 fillFieldPatternMap(*globalIndexer,fieldName,fieldPatterns);
173 panzer_stk::ParameterListCallback(fieldName,fieldPatterns,stkConn_manager,
174 rcp_dynamic_cast<const panzer::GlobalIndexer>(globalIndexer)));
175 reqHandler_local->addRequestCallback(callback);
232 if(writeCoordinates) {
233 #ifdef PANZER_HAVE_EPETRA_STACK
238 const std::vector<double> & xcoords = callback->getXCoordsVector();
239 const std::vector<double> & ycoords = callback->getYCoordsVector();
240 const std::vector<double> & zcoords = callback->getZCoordsVector();
265 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::runtime_error,
"ERROR: Panzer_STK_SetupLOWSFactory.cpp - writeCoordinates not implemented for Tpetra yet!");
269 #ifdef PANZER_HAVE_MUELU
270 if(rcp_dynamic_cast<const panzer::GlobalIndexer>(globalIndexer)!=Teuchos::null
272 if(!writeCoordinates)
275 typedef Tpetra::Map<int,panzer::GlobalOrdinal,panzer::TpetraNodeType> Map;
276 typedef Tpetra::MultiVector<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType> MV;
279 unsigned dim = Teuchos::as<unsigned>(spatialDim);
281 for(
unsigned d=0;d<dim;d++) {
282 const std::vector<double> & coord = callback->getCoordsVector(d);
285 if(coords==Teuchos::null) {
289 std::vector<panzer::GlobalOrdinal> ownedIndices;
292 coords =
rcp(
new MV(coords_map,dim));
296 coords =
rcp(
new MV(coords_map,dim));
305 for(std::size_t i=0;i<coord.size();i++)
311 muelu_params.
set<
RCP<MV> >(
"Coordinates",coords);
317 Teko::addTekoToStratimikosBuilder(linearSolverBuilder,reqHandler_local);
321 if(reqHandler_local==Teuchos::null)
322 reqHandler_local =
rcp(
new Teko::RequestHandler);
324 std::string fieldName;
325 if(determineCoordinateField(*globalIndexer,fieldName)) {
331 rcp(
new panzer_stk::ParameterListCallbackBlocked(stkConn_manager,blkDofs,auxBlkDofs));
332 reqHandler_local->addRequestCallback(callback);
335 Teko::addTekoToStratimikosBuilder(linearSolverBuilder,reqHandler_local);
337 if(writeCoordinates) {
338 #ifdef PANZER_HAVE_EPETRA_STACK
343 const std::vector<RCP<panzer::GlobalIndexer>> & dofVec
345 for(std::size_t i=0;i<dofVec.size();i++) {
350 std::map<std::string,RCP<const panzer::Intrepid2FieldPattern> > fieldPatterns;
351 fillFieldPatternMap(*dofVec[i],fieldName,fieldPatterns);
352 panzer_stk::ParameterListCallback plCall(fieldName,fieldPatterns,stkConn_manager,dofVec[i]);
353 plCall.buildArrayToVector();
354 plCall.buildCoordinates();
357 const std::vector<double> & xcoords = plCall.getXCoordsVector();
358 const std::vector<double> & ycoords = plCall.getYCoordsVector();
359 const std::vector<double> & zcoords = plCall.getZCoordsVector();
385 #ifdef PANZER_HAVE_MUELU
388 typedef Xpetra::Map<int,panzer::GlobalOrdinal> Map;
389 typedef Xpetra::MultiVector<double,int,panzer::GlobalOrdinal> MV;
392 RCP<const Map> coords_map = Xpetra::MapFactory<int,panzer::GlobalOrdinal>::Build(Xpetra::UseEpetra,
400 unsigned dim = Teuchos::as<unsigned>(spatialDim);
402 RCP<MV> coords = Xpetra::MultiVectorFactory<double,int,panzer::GlobalOrdinal>::Build(coords_map,spatialDim);
404 for(
unsigned d=0;d<dim;d++) {
410 for(std::size_t j=0;j<coords->getLocalLength();++j) {
411 if (d == 0) dest[j] = xcoords[j];
412 if (d == 1) dest[j] = ycoords[j];
413 if (d == 2) dest[j] = zcoords[j];
420 muelu_params.
set<
RCP<MV> >(
"Coordinates",coords);
426 #else // PANZER_HAVE EPETRA
427 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::runtime_error,
"ERROR: Panzer_STK_SetupLOWSFactory - writeCoordinates not implemented for Tpetra yet!")
439 "Topology writing is no longer implemented. It needs to be reimplemented for the "
440 "default DOFManager (estimate 2 days with testing)");
445 linearSolverBuilder.setParameterList(strat_params);
459 #ifdef PANZER_HAVE_TEKO
462 bool writeCoordinates,
468 #ifdef PANZER_HAVE_TEKO
470 if(reqHandler_local==Teuchos::null)
471 reqHandler_local =
Teuchos::rcp(
new Teko::RequestHandler);
476 return buildLOWSFactory(blockedAssembly,globalIndexer,stk_conn_manager,spatialDim,mpi_comm,strat_params,
477 #ifdef PANZER_HAVE_TEKO
488 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
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const std::vector< Teuchos::RCP< GlobalIndexer > > & getFieldDOFManagers() const
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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...