Commit 92775cf7 authored by Naumann, Andreas's avatar Naumann, Andreas
Browse files

merge from linearAlg-branch. my parallelization needed a slightly more general...

merge from linearAlg-branch. my parallelization needed a slightly more general linear solver interface and uses the pvd-naming scheme from the petsc-parallelization
parent 2daa8f2e
......@@ -142,6 +142,7 @@ namespace AMDiS
#endif
///TODO: use the getParaViewFilename.. consistent with the parallel domain??
if (appendIndex) {
TEST_EXIT(indexLength <= 99)("index lenght > 99\n");
TEST_EXIT(indexDecimals <= 97)("index decimals > 97\n");
......@@ -269,5 +270,24 @@ namespace AMDiS
delete dataCollectors[i];
}
template<>
string FileWriter<double>::getParaViewFilename(AdaptInfo* adaptInfo) const
{
string ret(filename);
if (appendIndex) {
TEST_EXIT(indexLength <= 99)("index lenght > 99\n");
TEST_EXIT(indexDecimals <= 97)("index decimals > 97\n");
TEST_EXIT(indexDecimals < indexLength)("index length <= index decimals\n");
char formatStr[9];
char timeStr[20];
sprintf(formatStr, "%%0%d.%df", indexLength, indexDecimals);
sprintf(timeStr, formatStr, adaptInfo ? adaptInfo->getTime() : 0.0);
ret += timeStr;
}
return ret;
}
} // end namespace detail
} // end namespace AMDiS
......@@ -82,6 +82,11 @@ namespace AMDiS {
return paraviewAnimationFrames;
}
bool getWriteParaViewFormat() const { return writeParaViewFormat; }
std::string getParaViewFilename(AdaptInfo* info) const ;
const std::vector< std::string >& getSolutionNames() const
{ return solutionNames; }
protected:
/// Initialization of the filewriter.
void initialize();
......
......@@ -200,6 +200,8 @@ namespace AMDiS { namespace io {
}
void writeParallelFile(string name, int nRanks,
string fnPrefix, string fnPostfix,
vector<string> &componentNames,
......@@ -207,6 +209,22 @@ namespace AMDiS { namespace io {
bool highPrecision,
bool writeAsVector
)
{
using boost::lexical_cast;
vector< string > fileNames(nRanks);
for (int i = 0; i < nRanks; i++) {
fileNames[i] = fnPrefix + "-p" + lexical_cast<string>(i) + "-" + fnPostfix;
}
writeParallelFile(name, nRanks, fileNames, componentNames, format, highPrecision, writeAsVector);
}
void writeParallelFile(string name, int nRanks,
vector<string>& subNames,
const vector<string> &componentNames,
::AMDiS::io::VtkWriter::Vtuformat format,
bool highPrecision,
bool writeAsVector
)
{
FUNCNAME("writeParallelFile()");
......@@ -277,8 +295,7 @@ namespace AMDiS { namespace io {
file << " </PPointData>\n";
for (int i = 0; i < nRanks; i++) {
string pname(fnPrefix + "-p" + lexical_cast<string>(i) + "-" + fnPostfix);
boost::filesystem::path filepath(pname);
boost::filesystem::path filepath(subNames[i]);
file << " <Piece Source=\""
<< boost::filesystem::basename(filepath)
<< boost::filesystem::extension(filepath) << "\"/>\n";
......
......@@ -292,7 +292,16 @@ namespace AMDiS { namespace io {
/// Writes a pvtu file, which contains the links to all the rank files.
void writeParallelFile(std::string name, int nRanks,
std::string fnPrefix, std::string fnPostfix,
std::vector<std::string> &componentNames,
const std::vector<std::string> &componentNames,
::AMDiS::io::VtkWriter::Vtuformat format = ::AMDiS::io::VtkWriter::ASCII,
bool highPrecision = false,
bool writeAsVector = false
);
/// Writes a pvtu file which contains the links to the rank files in @subNames
void writeParallelFile(std::string name, int nRanks,
std::vector<std::string>& subNames,
const std::vector<std::string> &componentNames,
::AMDiS::io::VtkWriter::Vtuformat format = ::AMDiS::io::VtkWriter::ASCII,
bool highPrecision = false,
bool writeAsVector = false
......
......@@ -50,10 +50,10 @@ namespace AMDiS {
/// Wrapper for template-argument dependent constructors
template < typename MatrixType, typename Enable = void >
template < typename MatrixType, typename Mapper_ = BlockMapper, typename Enable = void >
struct LinearSolverBase : public LinearSolverInterface
{
typedef BlockMapper Mapper;
typedef Mapper_ Mapper;
LinearSolverBase(std::string name)
: LinearSolverInterface(name) {}
......@@ -63,25 +63,26 @@ namespace AMDiS {
return matrix;
}
protected:
/// create a sequential BlockMapper
void initMapper(const SolverMatrix<Matrix<DOFMatrix*> >& A)
virtual void initMapper(const SolverMatrix<Matrix<DOFMatrix*> >& A)
{
mapper = new BlockMapper(A);
mapper = new Mapper(A);
}
void exitMapper()
virtual void exitMapper()
{
delete mapper;
}
protected:
MatrixType matrix;
Mapper* mapper;
};
#ifdef HAVE_PARALLEL_MTL4
template< typename MatrixType >
struct LinearSolverBase<MatrixType, typename boost::enable_if< mtl::traits::is_distributed<MatrixType> > >
struct LinearSolverBase<MatrixType, ParallelMapper, typename boost::enable_if< mtl::traits::is_distributed<MatrixType> > >
: public ParallelSolver
{
typedef ParallelMapper Mapper;
......@@ -94,18 +95,18 @@ namespace AMDiS {
return matrix;
}
protected:
/// create a parallel mapper based on local-to-global mapping
void initMapper(const SolverMatrix<Matrix<DOFMatrix*> >& A)
virtual void initMapper(const SolverMatrix<Matrix<DOFMatrix*> >& A)
{
mapper = new ParallelMapper(*ParallelSolver::getDofMapping());
}
void exitMapper()
virtual void exitMapper()
{
delete mapper;
}
protected:
MatrixType matrix;
Mapper* mapper;
};
......@@ -120,16 +121,14 @@ namespace AMDiS {
* solvers where MTL4 provides an interface, can be assigned
* by different Runner objects.
**/
template< typename MatrixType, typename VectorType, typename Runner >
class LinearSolver : public LinearSolverBase<MatrixType>
template< typename MatrixType, typename VectorType, typename Runner, typename Mapper_ = BlockMapper >
class LinearSolver : public LinearSolverBase<MatrixType, Mapper_>
{
private:
typedef LinearSolverBase<MatrixType> super;
typedef LinearSolver<MatrixType, VectorType, Runner> self;
protected:
typedef LinearSolverBase<MatrixType, Mapper_> super;
typedef LinearSolver<MatrixType, VectorType, Runner, Mapper_> self;
typedef typename super::Mapper Mapper;
Runner runner; // redirect the implementation to a runner
public:
/// Creator class used in the LinearSolverInterfaceMap.
class Creator : public LinearSolverCreator
......@@ -172,6 +171,7 @@ namespace AMDiS {
}
protected:
/// Implementation of \ref LinearSolverInterface::solveLinearSystem()
int solveLinearSystem(const SolverMatrix<Matrix<DOFMatrix*> >& A,
SystemVector& x,
......@@ -182,7 +182,7 @@ namespace AMDiS {
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
MPI::COMM_WORLD.Barrier();
#endif
super::initMapper(A);
this->initMapper(A);
Timer t;
if (createMatrixData) {
......@@ -206,7 +206,7 @@ namespace AMDiS {
if (!storeMatrixData)
runner.exit();
super::exitMapper();
this->exitMapper();
return error;
}
......@@ -228,6 +228,9 @@ namespace AMDiS {
dispatch::initVector(target, super::matrix);
dispatch::fillVector(target, source, mapper.self());
}
Runner runner; // redirect the implementation to a runner
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment