43 #include "PanzerAdaptersSTK_config.hpp"
48 #include "Teuchos_AbstractFactoryStd.hpp"
50 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
52 #include "Epetra_MpiComm.h"
53 #include "Epetra_Vector.h"
58 #include "Tpetra_Map.hpp"
59 #include "Tpetra_MultiVector.hpp"
61 #ifdef PANZER_HAVE_TEKO
62 #include "Teko_StratimikosFactory.hpp"
65 #ifdef PANZER_HAVE_MUELU
66 #include <Thyra_MueLuPreconditionerFactory.hpp>
67 #include <Thyra_MueLuRefMaxwellPreconditionerFactory.hpp>
68 #include "Stratimikos_MueLuHelpers.hpp"
70 #include "Xpetra_MapFactory.hpp"
71 #include "Xpetra_MultiVectorFactory.hpp"
74 #ifdef PANZER_HAVE_IFPACK2
75 #include <Thyra_Ifpack2PreconditionerFactory.hpp>
78 namespace panzer_stk {
85 std::vector<std::string> elementBlocks;
89 std::set<int> runningFields;
92 runningFields.insert(fields.begin(),fields.end());
96 for(std::size_t i=1;i<elementBlocks.size();i++) {
99 std::set<int> currentFields(runningFields);
100 runningFields.clear();
101 std::set_intersection(fields.begin(),fields.end(),
102 currentFields.begin(),currentFields.end(),
103 std::inserter(runningFields,runningFields.begin()));
106 if(runningFields.size()<1)
115 const std::string & fieldName,
118 std::vector<std::string> elementBlocks;
121 for(std::size_t e=0;e<elementBlocks.size();e++) {
122 std::string blockId = elementBlocks[e];
125 fieldPatterns[blockId] =
126 Teuchos::rcp_dynamic_cast<const panzer::Intrepid2FieldPattern>(globalIndexer.
getFieldPattern(blockId,fieldName),
true);
132 const std::string & fieldName,
136 using Teuchos::ptrFromRef;
137 using Teuchos::ptr_dynamic_cast;
142 Ptr<const DOFManager> dofManager = ptr_dynamic_cast<
const DOFManager>(ptrFromRef(globalIndexer));
144 if(dofManager!=Teuchos::null) {
145 fillFieldPatternMap(*dofManager,fieldName,fieldPatterns);
159 #ifdef PANZER_HAVE_TEKO
162 bool writeCoordinates,
170 using Teuchos::rcp_dynamic_cast;
172 Stratimikos::DefaultLinearSolverBuilder linearSolverBuilder;
178 #ifdef PANZER_HAVE_MUELU
180 Stratimikos::enableMueLu<int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLu");
181 Stratimikos::enableMueLuRefMaxwell<int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLuRefMaxwell");
182 #ifndef PANZER_HIDE_DEPRECATED_CODE
184 Stratimikos::enableMueLu<int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLu-Tpetra");
185 Stratimikos::enableMueLuRefMaxwell<int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLuRefMaxwell-Tpetra");
189 #ifdef PANZER_HAVE_IFPACK2
192 typedef Thyra::Ifpack2PreconditionerFactory<Tpetra::CrsMatrix<double, int, panzer::GlobalOrdinal,panzer::TpetraNodeType> > Impl;
194 linearSolverBuilder.setPreconditioningStrategyFactory(Teuchos::abstractFactoryStd<Base, Impl>(),
"Ifpack2");
199 #ifdef PANZER_HAVE_TEKO
202 if(!blockedAssembly) {
204 std::string fieldName;
209 if(reqHandler_local==Teuchos::null)
210 reqHandler_local =
rcp(
new Teko::RequestHandler);
213 if(determineCoordinateField(*globalIndexer,fieldName)) {
214 std::map<std::string,RCP<const panzer::Intrepid2FieldPattern> > fieldPatterns;
215 fillFieldPatternMap(*globalIndexer,fieldName,fieldPatterns);
218 panzer_stk::ParameterListCallback(fieldName,fieldPatterns,stkConn_manager,
219 rcp_dynamic_cast<const panzer::GlobalIndexer>(globalIndexer)));
220 reqHandler_local->addRequestCallback(callback);
277 if(writeCoordinates) {
282 const std::vector<double> & xcoords = callback->getXCoordsVector();
283 const std::vector<double> & ycoords = callback->getYCoordsVector();
284 const std::vector<double> & zcoords = callback->getZCoordsVector();
310 #ifdef PANZER_HAVE_MUELU
311 if(rcp_dynamic_cast<const panzer::GlobalIndexer>(globalIndexer)!=Teuchos::null
313 if(!writeCoordinates)
316 typedef Tpetra::Map<int,panzer::GlobalOrdinal,panzer::TpetraNodeType> Map;
317 typedef Tpetra::MultiVector<double,int,panzer::GlobalOrdinal,panzer::TpetraNodeType> MV;
320 unsigned dim = Teuchos::as<unsigned>(spatialDim);
322 for(
unsigned d=0;d<dim;d++) {
323 const std::vector<double> & coord = callback->getCoordsVector(d);
326 if(coords==Teuchos::null) {
330 std::vector<panzer::GlobalOrdinal> ownedIndices;
333 coords =
rcp(
new MV(coords_map,dim));
337 coords =
rcp(
new MV(coords_map,dim));
346 for(std::size_t i=0;i<coord.size();i++)
352 muelu_params.
set<
RCP<MV> >(
"Coordinates",coords);
358 Teko::addTekoToStratimikosBuilder(linearSolverBuilder,reqHandler_local);
362 if(reqHandler_local==Teuchos::null)
363 reqHandler_local =
rcp(
new Teko::RequestHandler);
365 std::string fieldName;
366 if(determineCoordinateField(*globalIndexer,fieldName)) {
372 rcp(
new panzer_stk::ParameterListCallbackBlocked(stkConn_manager,blkDofs,auxBlkDofs));
373 reqHandler_local->addRequestCallback(callback);
376 Teko::addTekoToStratimikosBuilder(linearSolverBuilder,reqHandler_local);
378 if(writeCoordinates) {
383 const std::vector<RCP<panzer::GlobalIndexer>> & dofVec
385 for(std::size_t i=0;i<dofVec.size();i++) {
390 std::map<std::string,RCP<const panzer::Intrepid2FieldPattern> > fieldPatterns;
391 fillFieldPatternMap(*dofVec[i],fieldName,fieldPatterns);
392 panzer_stk::ParameterListCallback plCall(fieldName,fieldPatterns,stkConn_manager,dofVec[i]);
393 plCall.buildArrayToVector();
394 plCall.buildCoordinates();
397 const std::vector<double> & xcoords = plCall.getXCoordsVector();
398 const std::vector<double> & ycoords = plCall.getYCoordsVector();
399 const std::vector<double> & zcoords = plCall.getZCoordsVector();
425 #ifdef PANZER_HAVE_MUELU
428 typedef Xpetra::Map<int,panzer::GlobalOrdinal> Map;
429 typedef Xpetra::MultiVector<double,int,panzer::GlobalOrdinal> MV;
432 RCP<const Map> coords_map = Xpetra::MapFactory<int,panzer::GlobalOrdinal>::Build(Xpetra::UseEpetra,
440 unsigned dim = Teuchos::as<unsigned>(spatialDim);
442 RCP<MV> coords = Xpetra::MultiVectorFactory<double,int,panzer::GlobalOrdinal>::Build(coords_map,spatialDim);
444 for(
unsigned d=0;d<dim;d++) {
450 for(std::size_t j=0;j<coords->getLocalLength();++j) {
451 if (d == 0) dest[j] = xcoords[j];
452 if (d == 1) dest[j] = ycoords[j];
453 if (d == 2) dest[j] = zcoords[j];
460 muelu_params.
set<
RCP<MV> >(
"Coordinates",coords);
476 "Topology writing is no longer implemented. It needs to be reimplemented for the "
477 "default DOFManager (estimate 2 days with testing)");
482 linearSolverBuilder.setParameterList(strat_params);
496 #ifdef PANZER_HAVE_TEKO
499 bool writeCoordinates,
505 #ifdef PANZER_HAVE_TEKO
507 if(reqHandler_local==Teuchos::null)
508 reqHandler_local =
Teuchos::rcp(
new Teko::RequestHandler);
513 return buildLOWSFactory(blockedAssembly,globalIndexer,stk_conn_manager,spatialDim,mpi_comm,strat_params,
514 #ifdef PANZER_HAVE_TEKO
525 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...