43 #ifndef __Panzer_STK_SetupLOWSFactory_impl_hpp__
44 #define __Panzer_STK_SetupLOWSFactory_impl_hpp__
46 #include "PanzerAdaptersSTK_config.hpp"
50 #include "Teuchos_AbstractFactoryStd.hpp"
52 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
54 #include "Epetra_MpiComm.h"
55 #include "Epetra_Vector.h"
60 #include "Tpetra_Map.hpp"
61 #include "Tpetra_MultiVector.hpp"
63 #ifdef PANZER_HAVE_TEKO
64 #include "Teko_StratimikosFactory.hpp"
67 #ifdef PANZER_HAVE_MUELU
68 #include <Thyra_MueLuPreconditionerFactory.hpp>
69 #include <Thyra_MueLuRefMaxwellPreconditionerFactory.hpp>
70 #include "Stratimikos_MueLuHelpers.hpp"
71 #include "MatrixMarket_Tpetra.hpp"
72 #include "Xpetra_MapFactory.hpp"
73 #include "Xpetra_MultiVectorFactory.hpp"
76 #ifdef PANZER_HAVE_IFPACK2
77 #include <Thyra_Ifpack2PreconditionerFactory.hpp>
80 namespace panzer_stk {
87 std::vector<std::string> elementBlocks;
91 std::set<int> runningFields;
94 runningFields.insert(fields.begin(),fields.end());
98 for(std::size_t i=1;i<elementBlocks.size();i++) {
101 std::set<int> currentFields(runningFields);
102 runningFields.clear();
103 std::set_intersection(fields.begin(),fields.end(),
104 currentFields.begin(),currentFields.end(),
105 std::inserter(runningFields,runningFields.begin()));
108 if(runningFields.size()<1)
115 template<
typename GO>
118 const std::string & fieldName,
121 std::vector<std::string> elementBlocks;
124 for(std::size_t e=0;e<elementBlocks.size();e++) {
125 std::string blockId = elementBlocks[e];
128 fieldPatterns[blockId] =
129 Teuchos::rcp_dynamic_cast<const panzer::Intrepid2FieldPattern>(globalIndexer.
getFieldPattern(blockId,fieldName),
true);
135 const std::string & fieldName,
139 using Teuchos::ptrFromRef;
140 using Teuchos::ptr_dynamic_cast;
145 Ptr<const DOFManager<int,int> > dofManager = ptr_dynamic_cast<
const DOFManager<int,int> >(ptrFromRef(globalIndexer));
147 if(dofManager!=Teuchos::null) {
148 fillFieldPatternMap(*dofManager,fieldName,fieldPatterns);
153 Ptr<const DOFManager<int,panzer::Ordinal64> > dofManager = ptr_dynamic_cast<
const DOFManager<int,panzer::Ordinal64> >(ptrFromRef(globalIndexer));
155 if(dofManager!=Teuchos::null) {
156 fillFieldPatternMap(*dofManager,fieldName,fieldPatterns);
163 template<
typename GO>
171 #ifdef PANZER_HAVE_TEKO
174 bool writeCoordinates,
182 using Teuchos::rcp_dynamic_cast;
184 Stratimikos::DefaultLinearSolverBuilder linearSolverBuilder;
190 #ifdef PANZER_HAVE_MUELU
193 Stratimikos::enableMueLu(linearSolverBuilder,
"MueLu");
194 Stratimikos::enableMueLuRefMaxwell(linearSolverBuilder,
"MueLuRefMaxwell");
195 Stratimikos::enableMueLu<int,panzer::Ordinal64,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLu-Tpetra");
196 Stratimikos::enableMueLuRefMaxwell<int,panzer::Ordinal64,panzer::TpetraNodeType>(linearSolverBuilder,
"MueLuRefMaxwell-Tpetra");
199 #ifdef PANZER_HAVE_IFPACK2
202 typedef Thyra::Ifpack2PreconditionerFactory<Tpetra::CrsMatrix<double, int, panzer::Ordinal64,panzer::TpetraNodeType> > Impl;
204 linearSolverBuilder.setPreconditioningStrategyFactory(Teuchos::abstractFactoryStd<Base, Impl>(),
"Ifpack2");
209 #ifdef PANZER_HAVE_TEKO
212 if(!blockedAssembly) {
214 std::string fieldName;
219 if(reqHandler_local==Teuchos::null)
220 reqHandler_local =
rcp(
new Teko::RequestHandler);
223 if(determineCoordinateField(*globalIndexer,fieldName)) {
224 std::map<std::string,RCP<const panzer::Intrepid2FieldPattern> > fieldPatterns;
225 fillFieldPatternMap(*globalIndexer,fieldName,fieldPatterns);
228 panzer_stk::ParameterListCallback<int,GO>(fieldName,fieldPatterns,stkConn_manager,
230 reqHandler_local->addRequestCallback(callback);
287 if(writeCoordinates) {
292 const std::vector<double> & xcoords = callback->getXCoordsVector();
293 const std::vector<double> & ycoords = callback->getYCoordsVector();
294 const std::vector<double> & zcoords = callback->getZCoordsVector();
320 #ifdef PANZER_HAVE_MUELU
323 if(!writeCoordinates)
326 typedef Tpetra::Map<int,panzer::Ordinal64,panzer::TpetraNodeType> Map;
327 typedef Tpetra::MultiVector<double,int,panzer::Ordinal64,panzer::TpetraNodeType> MV;
330 unsigned dim = Teuchos::as<unsigned>(spatialDim);
332 for(
unsigned d=0;d<dim;d++) {
333 const std::vector<double> & coord = callback->getCoordsVector(d);
336 if(coords==Teuchos::null) {
340 std::vector<panzer::Ordinal64> ownedIndices;
341 ugi->getOwnedIndices(ownedIndices);
343 coords =
rcp(
new MV(coords_map,dim));
347 coords =
rcp(
new MV(coords_map,dim));
356 for(std::size_t i=0;i<coord.size();i++)
362 muelu_params.
set<
RCP<MV> >(
"Coordinates",coords);
368 Teko::addTekoToStratimikosBuilder(linearSolverBuilder,reqHandler_local);
372 if(reqHandler_local==Teuchos::null)
373 reqHandler_local =
rcp(
new Teko::RequestHandler);
375 std::string fieldName;
376 if(determineCoordinateField(*globalIndexer,fieldName)) {
382 rcp(
new panzer_stk::ParameterListCallbackBlocked<int,GO>(stkConn_manager,blkDofs,auxBlkDofs));
383 reqHandler_local->addRequestCallback(callback);
386 Teko::addTekoToStratimikosBuilder(linearSolverBuilder,reqHandler_local);
388 if(writeCoordinates) {
393 const std::vector<RCP<panzer::UniqueGlobalIndexer<int,GO> > > & dofVec
394 = blkDofs->getFieldDOFManagers();
395 for(std::size_t i=0;i<dofVec.size();i++) {
400 std::map<std::string,RCP<const panzer::Intrepid2FieldPattern> > fieldPatterns;
401 fillFieldPatternMap(*dofVec[i],fieldName,fieldPatterns);
402 panzer_stk::ParameterListCallback<int,GO> plCall(fieldName,fieldPatterns,stkConn_manager,dofVec[i]);
403 plCall.buildArrayToVector();
404 plCall.buildCoordinates();
407 const std::vector<double> & xcoords = plCall.getXCoordsVector();
408 const std::vector<double> & ycoords = plCall.getYCoordsVector();
409 const std::vector<double> & zcoords = plCall.getZCoordsVector();
435 #ifdef PANZER_HAVE_MUELU
438 typedef Xpetra::Map<int,GO> Map;
439 typedef Xpetra::MultiVector<double,int,GO> MV;
442 RCP<const Map> coords_map = Xpetra::MapFactory<int,GO>::Build(Xpetra::UseEpetra,
450 unsigned dim = Teuchos::as<unsigned>(spatialDim);
452 RCP<MV> coords = Xpetra::MultiVectorFactory<double,int,GO>::Build(coords_map,spatialDim);
454 for(
unsigned d=0;d<dim;d++) {
460 for(std::size_t j=0;j<coords->getLocalLength();++j) {
461 if (d == 0) dest[j] = xcoords[j];
462 if (d == 1) dest[j] = ycoords[j];
463 if (d == 2) dest[j] = zcoords[j];
470 muelu_params.
set<
RCP<MV> >(
"Coordinates",coords);
486 "Topology writing is no longer implemented. It needs to be reimplemented for the "
487 "default DOFManager (estimate 2 days with testing)");
492 linearSolverBuilder.setParameterList(strat_params);
Teuchos::RCP< Thyra::LinearOpWithSolveFactoryBase< double > > buildLOWSFactory(bool blockedAssembly, const Teuchos::RCP< const panzer::UniqueGlobalIndexerBase > &globalIndexer, const Teuchos::RCP< panzer::ConnManagerBase< int > > &conn_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::UniqueGlobalIndexerBase > &auxGlobalIndexer, bool useCoordinates)
virtual int getNumFields() const =0
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)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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...
bool isSublist(const std::string &name) const
virtual void getElementBlockIds(std::vector< std::string > &elementBlockIds) const =0
virtual const std::vector< int > & getBlockFieldNumbers(const std::string &blockId) const =0
int VectorToMatrixMarketFile(const char *filename, const Epetra_Vector &A, const char *matrixName=0, const char *matrixDescription=0, bool writeHeader=true)
virtual const std::string & getFieldString(int num) const =0
Reverse lookup of the field string from a field number.
bool fieldInBlock(const std::string &field, const std::string &block) const
void getElementBlockIds(std::vector< std::string > &elementBlockIds) const
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
#define TEUCHOS_ASSERT(assertion_test)