Commit 16854a38 authored by Praetorius, Simon's avatar Praetorius, Simon

sequential petsc corrected

parent d51f8d70
......@@ -17,7 +17,7 @@ macro(enable_hypre _FLAGS_ _INC_DIRS_ _LIBS_)
HINTS ${PETSC_INCLUDE_DIRS})
if (_HYPRE_H)
get_filename_component(HYPRE_INCLUDE_DIRECTORIES ${HYPRE_H} PATH)
get_filename_component(HYPRE_INCLUDE_DIRECTORIES ${_HYPRE_H} PATH)
list(APPEND ${_INC_DIRS_} ${HYPRE_INCLUDE_DIRECTORIES})
endif (_HYPRE_H)
......
if (ENABLE_SEQ_PETSC)
target_enable_mpi(amdis PRIVATE)
target_enable_petsc(amdis PRIVATE)
target_enable_mpi(amdis PUBLIC)
target_enable_petsc(amdis PUBLIC)
target_compile_definitions(amdis PRIVATE HAVE_SEQ_PETSC=1)
target_compile_definitions(amdis PUBLIC HAVE_SEQ_PETSC=1)
target_sources(amdis PRIVATE
${SOURCE_DIR}/solver/PetscSolver.cc
......
......@@ -17,7 +17,7 @@ macro(target_enable_hypre _TARGET_ _SCOPE_)
HINTS ${PETSC_INCLUDE_DIRS})
if (_HYPRE_H)
get_filename_component(HYPRE_INCLUDE_DIRECTORIES ${HYPRE_H} PATH)
get_filename_component(HYPRE_INCLUDE_DIRECTORIES ${_HYPRE_H} PATH)
target_include_directories(${_TARGET_} ${_SCOPE_} ${HYPRE_INCLUDE_DIRECTORIES})
endif (_HYPRE_H)
......
......@@ -566,14 +566,16 @@ namespace AMDiS {
FUNCNAME("ProblemStat::createSolver()");
// definition of standard-backends
#if defined HAVE_PARALLEL_PETSC
string backend("p_petsc");
#elif defined HAVE_PARALLEL_MTL
string backend("p_mtl");
#elif defined HAVE_SEQ_PETSC
string backend("petsc");
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
std::string backend = "p_";
#else
std::string backend = "";
#endif
#if defined(HAVE_PARALLEL_PETSC) || defined(HAVE_SEQ_PETSC)
backend += "petsc";
#else
string backend("mtl");
backend += "mtl";
#endif
// === read backend-name ===
......
......@@ -30,6 +30,7 @@
#include <vector>
#include <petsc.h>
#include "AMDiS_fwd.h"
#include "utility/PetscWrapper.h"
namespace AMDiS
{
......@@ -121,80 +122,4 @@ namespace AMDiS
} // end namespace petsc_helper
} // end namespace Parallel
// functions for PETSc API changes
namespace petsc
{
inline PetscErrorCode options_view(PetscViewer viewer)
{
#if (PETSC_VERSION_MINOR >= 7)
return PetscOptionsView(PETSC_NULL, viewer);
#else
return PetscOptionsView(viewer);
#endif
}
inline PetscErrorCode options_insert_string(const char in_str[])
{
#if (PETSC_VERSION_MINOR >= 7)
return PetscOptionsInsertString(PETSC_NULL, in_str);
#else
return PetscOptionsInsertString(in_str);
#endif
}
inline PetscErrorCode ksp_set_operators(KSP ksp, Mat Amat,Mat Pmat)
{
#if (PETSC_VERSION_MINOR >= 5)
return KSPSetOperators(ksp, Amat, Pmat);
#else
return KSPSetOperators(ksp, Amat, Pmat, SAME_NONZERO_PATTERN);
#endif
}
inline PetscErrorCode ksp_get_operators(KSP ksp, Mat *Amat,Mat *Pmat)
{
#if (PETSC_VERSION_MINOR >= 5)
return KSPGetOperators(ksp, Amat, Pmat);
#else
return KSPGetOperators(ksp, Amat, Pmat, SAME_NONZERO_PATTERN);
#endif
}
template <class Monitor>
inline PetscErrorCode ksp_monitor_set(KSP ksp, Monitor monitor)
{
#if (PETSC_VERSION_MINOR >= 7)
PetscViewerAndFormat *vf;
PetscErrorCode ierr;
ierr = PetscViewerAndFormatCreate(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_DEFAULT,&vf);CHKERRQ(ierr);
ierr = KSPMonitorSet(ksp,(PetscErrorCode (*)(KSP,PetscInt,PetscReal,void*))monitor,vf,(PetscErrorCode (*)(void**))PetscViewerAndFormatDestroy);CHKERRQ(ierr);
return ierr;
#else
return KSPMonitorSet(ksp, monitor, PETSC_NULL, PETSC_NULL);
#endif
}
inline PetscErrorCode mat_create_vecs(Mat mat,Vec *right,Vec *left)
{
#if (PETSC_VERSION_MINOR >= 6)
return MatCreateVecs(mat, right, left);
#else
return MatGetVecs(mat, right, left);
#endif
}
inline PetscErrorCode mat_nullspace_remove(MatNullSpace sp,Vec vec)
{
#if (PETSC_VERSION_MINOR >= 5)
return MatNullSpaceRemove(sp, vec);
#else
return MatNullSpaceRemove(sp, vec, PETSC_NULL);
#endif
}
} // end namespace petsc
} // end namespace AMDiS
#endif
......@@ -91,14 +91,16 @@ namespace AMDiS {
int max_iter = 100, double tol = 1.e-8)
{
// definition of standard-backends
#if defined HAVE_PARALLEL_PETSC
std::string backend("p_petsc");
#elif defined HAVE_PARALLEL_MTL
std::string backend("p_mtl");
#elif defined HAVE_PETSC
std::string backend("petsc");
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
std::string backend = "p_";
#else
std::string backend("mtl");
std::string backend = "";
#endif
#if defined(HAVE_PARALLEL_PETSC) || defined(HAVE_SEQ_PETSC)
backend += "petsc";
#else
backend += "mtl";
#endif
// === read backend-name ===
......
......@@ -70,15 +70,16 @@ namespace AMDiS {
solver(NULL),
runner(NULL)
{
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
std::string backend = "p_";
#else
std::string backend = "";
#endif
#if defined HAVE_PARALLEL_PETSC
std::string backend("p_petsc");
#elif defined HAVE_PARALLEL_MTL
std::string backend("p_mtl");
#elif defined HAVE_PETSC || defined HAVE_SEQ_PETSC
std::string backend("petsc");
#if defined(HAVE_PARALLEL_PETSC) || defined(HAVE_SEQ_PETSC)
backend += "petsc";
#else
std::string backend("mtl");
backend += "mtl";
#endif
// === read backend-name ===
......
......@@ -29,6 +29,7 @@
#include "solver/LinearSolver.h"
#include "solver/PetscTypes.h"
#include "solver/MatrixStreams.h"
#include "utility/PetscWrapper.h"
#include "Timer.h"
#include <vector>
#include <iostream>
......@@ -58,7 +59,7 @@ namespace AMDiS {
virtual void init(PC pc, const SolverMatrix<Matrix<DOFMatrix*> >& A, const MatrixType& fullMatrix)
{
petsc_options_insert_string(("-" + prefix + "pc_type " + name).c_str());
petsc::options_insert_string(("-" + prefix + "pc_type " + name).c_str());
PCSetFromOptions(pc);
}
......
/******************************************************************************
*
* AMDiS - Adaptive multidimensional simulations
*
* Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
* Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
*
* Authors:
* Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
*
* This file is part of AMDiS
*
* See also license.opensource.txt in the distribution.
*
******************************************************************************/
/** \file PetscWrapper.h */
#ifndef AMDIS_PETSCWRAPPER_H
#define AMDIS_PETSCWRAPPER_H
#include <mpi.h>
#include <petsc.h>
namespace AMDiS
{
// functions for PETSc API changes
namespace petsc
{
inline PetscErrorCode options_view(PetscViewer viewer)
{
#if (PETSC_VERSION_MINOR >= 7)
return PetscOptionsView(PETSC_NULL, viewer);
#else
return PetscOptionsView(viewer);
#endif
}
inline PetscErrorCode options_insert_string(const char in_str[])
{
#if (PETSC_VERSION_MINOR >= 7)
return PetscOptionsInsertString(PETSC_NULL, in_str);
#else
return PetscOptionsInsertString(in_str);
#endif
}
inline PetscErrorCode ksp_set_operators(KSP ksp, Mat Amat,Mat Pmat)
{
#if (PETSC_VERSION_MINOR >= 5)
return KSPSetOperators(ksp, Amat, Pmat);
#else
return KSPSetOperators(ksp, Amat, Pmat, SAME_NONZERO_PATTERN);
#endif
}
inline PetscErrorCode ksp_get_operators(KSP ksp, Mat *Amat,Mat *Pmat)
{
#if (PETSC_VERSION_MINOR >= 5)
return KSPGetOperators(ksp, Amat, Pmat);
#else
return KSPGetOperators(ksp, Amat, Pmat, SAME_NONZERO_PATTERN);
#endif
}
template <class Monitor>
inline PetscErrorCode ksp_monitor_set(KSP ksp, Monitor monitor)
{
#if (PETSC_VERSION_MINOR >= 7)
PetscViewerAndFormat *vf;
PetscErrorCode ierr;
ierr = PetscViewerAndFormatCreate(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_DEFAULT,&vf);CHKERRQ(ierr);
ierr = KSPMonitorSet(ksp,(PetscErrorCode (*)(KSP,PetscInt,PetscReal,void*))monitor,vf,(PetscErrorCode (*)(void**))PetscViewerAndFormatDestroy);CHKERRQ(ierr);
return ierr;
#else
return KSPMonitorSet(ksp, monitor, PETSC_NULL, PETSC_NULL);
#endif
}
inline PetscErrorCode mat_create_vecs(Mat mat,Vec *right,Vec *left)
{
#if (PETSC_VERSION_MINOR >= 6)
return MatCreateVecs(mat, right, left);
#else
return MatGetVecs(mat, right, left);
#endif
}
inline PetscErrorCode mat_nullspace_remove(MatNullSpace sp,Vec vec)
{
#if (PETSC_VERSION_MINOR >= 5)
return MatNullSpaceRemove(sp, vec);
#else
return MatNullSpaceRemove(sp, vec, PETSC_NULL);
#endif
}
} // end namespace petsc
} // end namespace AMDiS
#endif
......@@ -2,21 +2,18 @@ project("extensions_demo_pfc")
cmake_minimum_required(VERSION 2.8)
find_package(AMDIS REQUIRED)
include(${AMDIS_USE_FILE})
if(AMDIS_FOUND)
message("amdis was found\n")
include(${AMDIS_USE_FILE})
SET(BASIS_LIBS ${AMDIS_LIBRARIES})
endif(AMDIS_FOUND)
add_definitions(-DUSE_MTL=1)
set(pfc src/pfc.cc)
add_executable("pfc" ${pfc})
target_link_libraries("pfc" ${BASIS_LIBS})
target_link_libraries("pfc" ${AMDIS_LIBRARIES})
set(pfc_rb src/pfc_rb.cc)
add_executable("pfc_rb" ${pfc_rb})
target_link_libraries("pfc_rb" ${BASIS_LIBS})
target_link_libraries("pfc_rb" ${AMDIS_LIBRARIES})
set(vpfc src/vpfc.cc)
add_executable("vpfc" ${vpfc})
target_link_libraries("vpfc" ${BASIS_LIBS})
target_link_libraries("vpfc" ${AMDIS_LIBRARIES})
......@@ -28,16 +28,8 @@ pfc->space->dim: 2
% ================== SOLVER ======================================
%#include "init/pfc_solver.inc"
pfc->space->solver: cg
pfc->space->MG->number of levels: 10
pfc->space->MG->max iteration: 100
pfc->space->MG->tolerance: 1.e-8
pfc->space->MG->nu1: 20
pfc->space->MG->nu2: 20
pfc->space->MG->gamma: 1
pfc->space->MG->mu: 3
pfc->space->MG->fine level: 12
pfc->space->solver->backend: bpetsc
#include "init/pfc_solver.mtl.inc"
% ==================== TIMESTEPS ===============================
adapt->timestep: 1.e-1
......
......@@ -29,6 +29,7 @@ pfc->space->dim: 2
% ================== SOLVER ======================================
pfc->space->solver->backend: mtl
#include "init/pfc_solver.mtl.inc"
......
%pfc->space->solver->backend: p_petsc
pfc->space->solver->backend: petsc
pfc->space->solver->petsc prefix: pfc_
pfc->space->solver: pfc
pfc->space->solver->ksp_type: fgmres
......@@ -26,4 +26,4 @@ precon_pfc_MpL2->max iteration: 1000
precon_pfc_MpL2->relative tolerance: 1.e-3
precon_pfc_MpL2->use direct solver: 0
precon_pfc_MpL2->solver: cg
precon_pfc_MpL2->use AMG: 0
\ No newline at end of file
precon_pfc_MpL2->use AMG: 0
......@@ -2,13 +2,11 @@
#include "Helpers.h"
#include "PhaseFieldCrystal.h"
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
#if defined(USE_SEQ_PETSC)
#include "preconditioner/PetscPreconPfc.h"
#endif
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
#elif defined(USE_PARALLEL_PETSC)
#include "preconditioner/PetscSolverPfc.h"
#endif
#if (!defined HAVE_SEQ_PETSC) && (!defined HAVE_PETSC) && (!defined HAVE_PARALLEL_DOMAIN_AMDIS)
#elif defined(USE_MTL)
#include "preconditioner/MTLPreconPfc.h"
#endif
......@@ -30,33 +28,24 @@ public:
{
super::finalizeData();
#ifdef USE_PRECON
#if defined(USE_SEQ_PETSC)
// sequential PFC preconditioner
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
PetscPreconPfc* precon = dynamic_cast<PetscPreconPfc*>(prob->getSolver()->getRightPrecon());
if (precon) {
precon->setData(getTau(), M0);
}
// PetscPreconPfcDiag* precon2 = dynamic_cast<PetscPreconPfcDiag*>(prob->getSolver()->getRightPrecon());
// if (precon2) {
// precon2->setData(getTau(), M0);
}
#elif !defined(HAVE_PARALLEL_DOMAIN_AMDIS)
MTLPreconPfc* precon = dynamic_cast<MTLPreconPfc*>(prob->getSolver()->getRightPrecon());
if (precon)
precon->setData(getTau(), M0);
#else
#elif defined(USE_PARALLEL_PETSC)
// parallel PFC preconditioner
Parallel::PetscSolverPfc* solver = dynamic_cast<Parallel::PetscSolverPfc*>(prob->getSolver());
if (solver)
if (solver) {
solver->setData(getTau(), M0);
// Parallel::PetscSolverPfcDiag* solver2 = dynamic_cast<Parallel::PetscSolverPfcDiag*>(prob->getSolver());
// if (solver2)
// solver2->setData(getTau(), M0);
#endif
}
#elif defined(USE_MTL)
// mtl4 preconditioner
MTLPreconPfc* precon = dynamic_cast<MTLPreconPfc*>(prob->getSolver()->getRightPrecon());
if (precon) {
precon->setData(getTau(), M0);
}
#endif
}
......@@ -82,20 +71,13 @@ int main(int argc, char** argv)
AMDiS::init(argc, argv);
Timer t;
#ifdef USE_PRECON
// add preconditioner / solver to the parameter list. Must be added before problem is initialized.
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
#if defined(USE_SEQ_PETSC)
CreatorMap<PetscPreconditionerNested>::addCreator("pfc", new PetscPreconPfc::Creator);
// CreatorMap<PetscPreconditionerNested>::addCreator("pfc_diag", new PetscPreconPfcDiag::Creator);
#elif !defined(HAVE_PARALLEL_DOMAIN_AMDIS)
CreatorMap<typename MTLPreconPfc::precon_base>::addCreator("pfc", new MTLPreconPfc::Creator);
// CreatorMap<typename MTLPreconPfc_Diag::base_precon>::addCreator("pfc", new MTLPreconPfc::Creator);
#else
#elif defined(USE_PARALLEL_PETSC)
CreatorMap<LinearSolverInterface>::addCreator("p_petsc_pfc", new Parallel::PetscSolverPfc::Creator);
// CreatorMap<LinearSolverInterface>::addCreator("p_petsc_pfc_diag", new Parallel::PetscSolverPfcDiag::Creator);
#endif
#elif defined(USE_MTL)
CreatorMap<typename MTLPreconPfc::precon_base>::addCreator("pfc", new MTLPreconPfc::Creator);
#endif
// create and initialize the PFC BaseProblem
......
......@@ -2,13 +2,11 @@
#include "Helpers.h"
#include "PhaseFieldCrystal.h"
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
#if defined(USE_SEQ_PETSC)
#include "preconditioner/PetscPreconPfc.h"
#endif
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
#elif defined(USE_PARALLEL_PETSC)
#include "preconditioner/PetscSolverPfc.h"
#endif
#if (!defined HAVE_SEQ_PETSC) && (!defined HAVE_PETSC) && (!defined HAVE_PARALLEL_DOMAIN_AMDIS)
#elif defined(USE_MTL)
#include "preconditioner/MTLPreconPfc.h"
#endif
......@@ -49,24 +47,19 @@ public:
{
super::initData();
#if defined(USE_SEQ_PETSC)
// sequential PFC preconditioner
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
PetscPreconPfc* runner = dynamic_cast<PetscPreconPfc*>(prob->getSolver()->getRunner());
if (runner) {
dynamic_cast<PetscSolver<PetscPreconPfc>*>(prob->getSolver())->setNested(true);
runner->setData(getTau());
}
#endif
#elif defined(USE_PARALLEL_PETSC)
// parallel PFC preconditioner
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
Parallel::PetscSolverPfc* solver = dynamic_cast<Parallel::PetscSolverPfc*>(prob->getSolver());
if (solver)
solver->setData(getTau());
#endif
#elif defined(USE_MTL)
// sequential PFC preconditioner using MTL
#if (!defined HAVE_SEQ_PETSC) && (!defined HAVE_PETSC) && (!defined HAVE_PARALLEL_DOMAIN_AMDIS)
using AMDiS::extensions::MTLPreconPfc;
MTLPreconPfc* precon = dynamic_cast<MTLPreconPfc*>(prob->getSolver()->getRightPrecon());
if (precon)
......@@ -197,15 +190,11 @@ int main(int argc, char** argv)
Timer t;
// add preconditioner / solver to the parameter list. Must be added before problem is initialized.
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
CreatorMap<LinearSolverInterface>::addCreator("petsc_pfc", new PetscSolver<PetscPreconPfc>::Creator);
#endif
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
#if defined(USE_SEQ_PETSC)
CreatorMap<PetscPreconditionerNested>::addCreator("petsc_pfc", new PetscPreconPfc::Creator);
#elif defined(USE_PARALLEL_PETSC)
CreatorMap<LinearSolverInterface>::addCreator("p_petsc_pfc", new Parallel::PetscSolverPfc::Creator);
#endif
#if (!defined HAVE_SEQ_PETSC) && (!defined HAVE_PETSC) && (!defined HAVE_PARALLEL_DOMAIN_AMDIS)
#elif defined(USE_MTL)
using AMDiS::extensions::MTLPreconPfc;
CreatorMap<typename MTLPreconPfc::precon_base>::addCreator("pfc", new MTLPreconPfc::Creator);
#endif
......@@ -216,7 +205,7 @@ int main(int argc, char** argv)
// Adapt-Infos
AdaptInfo adaptInfo("adapt", pfcProb.getNumComponents());
RosenbrockAdaptInstationary adaptInstat("adapt", pfcProb.getProblem(), &adaptInfo, &pfcProb, &adaptInfo);
RosenbrockAdaptInstationary adaptInstat("adapt", pfcProb.getProblem(), pfcProb.getProblem(), &adaptInfo, &pfcProb, &adaptInfo);
pfcProb.initTimeInterface(); // fill operators and BC
// Scale Mesh
......
......@@ -2,12 +2,12 @@
#include "Helpers.h"
#include "base_problems/PhaseFieldCrystal.h"
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
#if defined(USE_SEQ_PETSC)
#include "preconditioner/PetscPreconPfc.h"
#elif !defined(HAVE_PARALLEL_DOMAIN_AMDIS)
#include "preconditioner/MTLPreconPfc.h"
#else
#elif defined(USE_PARALLEL_PETSC)
#include "preconditioner/PetscSolverPfc.h"
#elif defined(USE_MTL)
#include "preconditioner/MTLPreconPfc.h"
#endif
// #include "OneModeApproximation.h"
......@@ -95,18 +95,18 @@ public:
{
super::finalizeData();
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
#if defined(USE_SEQ_PETSC)
PetscPreconPfc* precon = dynamic_cast<PetscPreconPfc*>(prob->getSolver()->getRightPrecon());
if (precon)
precon->setData(getTau(), M0);
#elif !defined(HAVE_PARALLEL_DOMAIN_AMDIS)
MTLPreconPfc* precon = dynamic_cast<MTLPreconPfc*>(prob->getSolver()->getRightPrecon());
if (precon)
precon->setData(getTau(), M0);
#else
#elif defined(USE_PARALLEL_PETSC)
Parallel::PetscSolverPfc* solver = dynamic_cast<Parallel::PetscSolverPfc*>(prob->getSolver());
if (solver)
solver->setData(getTau(), M0);
#elif defined(USE_MTL)
MTLPreconPfc* precon = dynamic_cast<MTLPreconPfc*>(prob->getSolver()->getRightPrecon());
if (precon)
precon->setData(getTau(), M0);
#endif
}
......@@ -233,12 +233,12 @@ int main(int argc, char** argv)
AMDiS::init(argc, argv);
#if (defined HAVE_SEQ_PETSC) || (defined HAVE_PETSC)
#if defined(USE_SEQ_PETSC)
CreatorMap<PetscPreconditionerNested>::addCreator("pfc", new PetscPreconPfc::Creator);
#elif !defined(HAVE_PARALLEL_DOMAIN_AMDIS)
CreatorMap<typename MTLPreconPfc::precon_base>::addCreator("pfc", new MTLPreconPfc::Creator);
#else
#elif defined(USE_PARALLEL_PETSC)
CreatorMap<LinearSolverInterface>::addCreator("p_petsc_pfc", new Parallel::PetscSolverPfc::Creator);
#elif defined(USE_MTL)
CreatorMap<typename MTLPreconPfc::precon_base>::addCreator("pfc", new MTLPreconPfc::Creator);
#endif
Timer t;
......
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