Commit 7bd6ff1c authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

Merge branch 'issue/cleanup_dofvector' into 'develop'

Issue/cleanup dofvector

See merge request !29
parents 9d6a1e4c 55a910fd
Pipeline #1231 failed with stage
in 4 seconds
# File for module specific CMake tests.
include(AMDiSCXXFeatures)
# some additional packages and flags
find_package(MTL REQUIRED
PATHS /usr/local/lib/mtl4 /opt/sources/mtl4 /opt/development/mtl4)
find_package(MTL
PATHS ${MTL_DIR}
HINTS /usr/local/lib/mtl4 /opt/sources/mtl4 /opt/development/mtl4
)
set(CXX_ELEVEN_FEATURE_LIST "MOVE" "AUTO" "RANGEDFOR" "INITLIST" "STATICASSERT" "DEFAULTIMPL")
set(MTL_COMPILE_DEFINITIONS "")
foreach(feature ${CXX_ELEVEN_FEATURE_LIST})
if (MTL_FOUND)
set(CXX_ELEVEN_FEATURE_LIST "MOVE" "AUTO" "RANGEDFOR" "INITLIST" "STATICASSERT" "DEFAULTIMPL")
set(MTL_COMPILE_DEFINITIONS "")
foreach(feature ${CXX_ELEVEN_FEATURE_LIST})
list(APPEND MTL_COMPILE_DEFINITIONS "MTL_WITH_${feature}")
endforeach()
endforeach()
if(HAVE_UMFPACK OR ENABLE_SUITESPARSE OR SuiteSparse_FOUND)
find_package(SuiteSparse QUIET)
if (SuiteSparse_FOUND)
list(APPEND MTL_COMPILE_DEFINITIONS "MTL_HAS_UMFPACK")
endif()
endif (SuiteSparse_FOUND)
endif (MTL_FOUND)
set(HAVE_MTL MTL_FOUND)
dune_register_package_flags(
if (MTL_FOUND)
list(APPEND MTL_COMPILE_DEFINITIONS "ENABLE_MTL=1")
dune_register_package_flags(
COMPILE_DEFINITIONS ${MTL_COMPILE_DEFINITIONS}
INCLUDE_DIRS ${MTL_INCLUDE_DIRS})
endif (MTL_FOUND)
\ No newline at end of file
/* begin dune-amdis
/* begin amdis
put the definitions for config.h specific to
your project here. Everything above will be
overwritten
......@@ -40,12 +40,13 @@
/* Define to the revision of amdis */
#define AMDIS_VERSION_REVISION @AMDIS_VERSION_REVISION@
/* Define to ENABLE_UMFPACK if the MTL library is available */
#cmakedefine HAVE_MTL ENABLE_MTL
/* some detected compiler features may be used in AMDiS */
#cmakedefine AMDIS_HAS_CXX_FOLD_EXPRESSIONS 1
#cmakedefine AMDIS_HAS_CXX_CONSTEXPR_IF 1
/* end dune-amdis
/* end amdis
Everything below here will be overwritten
*/
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <iostream>
#include <amdis/AMDiS.hpp>
......@@ -26,13 +26,13 @@ int main(int argc, char** argv)
// -div(A*grad(u)) + div(b*u) + c*u = f
auto opCD = convectionDiffusion(/*A=*/1.0, /*b=*/0.0, /*c=*/1.0, /*f=*/1.0);
prob.addMatrixOperator(opCD, _0, _0);
prob.addVectorOperator(opCD, _0);
prob.addMatrixOperator(opCD, 0, 0);
prob.addVectorOperator(opCD, 0);
// set boundary condition
auto predicate = [](auto const& x){ return x[0] < 1.e-8 || x[1] < 1.e-8; }; // define boundary
auto dbcValues = [](auto const& x){ return 0.0; }; // set value
prob.addDirichletBC(predicate, _0, _0, dbcValues);
prob.addDirichletBC(predicate, 0, 0, dbcValues);
AdaptInfo adaptInfo("adapt");
prob.buildAfterCoarsen(adaptInfo, Flag(0));
......
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <iostream>
#include <fmt/core.h>
......@@ -15,7 +15,7 @@ using namespace AMDiS;
using namespace Dune::Indices;
// 1 component with polynomial degree 1
using Param = YaspGridBasis<AMDIS_DIM, 1>;
using Param = YaspGridBasis<AMDIS_DIM, 2>;
using ElliptProblem = ProblemStat<Param>;
int main(int argc, char** argv)
......
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <iostream>
#include <amdis/AMDiS.hpp>
......
......@@ -3,10 +3,10 @@ elliptMesh->global refinements: 0
ellipt->mesh: elliptMesh
ellipt->solver->name: bicgstab
ellipt->solver->max iteration: 1000
ellipt->solver->relative tolerance: 1.e-8
ellipt->solver->info: 10
ellipt->solver->left precon: diag
ellipt->solver->max iteration: 10000
ellipt->solver->relative tolerance: 1.e-10
ellipt->solver->info: 1
ellipt->solver->left precon: ilu
ellipt->solver->right precon: no
ellipt->output[0]->filename: ellipt.2d
......
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <iostream>
#include <ctime>
#include <cmath>
......@@ -41,8 +45,8 @@ int main(int argc, char** argv)
AdaptInfo adaptInfo("adapt");
// tree-paths for components
auto _v = 0_c;
auto _p = 1_c;
auto _v = Dune::Indices::_0;
auto _p = Dune::Indices::_1;
// <1/tau * u, v>
auto opTime = makeOperator(tag::testvec_trialvec{}, density);
......
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <iostream>
#include <ctime>
#include <cmath>
......@@ -30,8 +34,8 @@ int main(int argc, char** argv)
Parameters::get("stokes->viscosity", viscosity);
// tree-paths for components
auto _v = 0_c;
auto _p = 1_c;
auto _v = Dune::Indices::_0;
auto _p = Dune::Indices::_1;
// <viscosity*grad(u_i), grad(v_i)>
for (std::size_t i = 0; i < DOW; ++i) {
......@@ -76,10 +80,12 @@ int main(int argc, char** argv)
// assemble and solve system
prob.buildAfterCoarsen(adaptInfo, Flag(0));
#ifdef DEBUG_MTL
// write matrix to file
mtl::io::matrix_market_ostream out("matrix_stokes0.mtx");
out << prob.getSystemMatrix().getMatrix();
std::cout << prob.getSystemMatrix().getMatrix() << '\n';
out << prob.getSystemMatrix().matrix();
std::cout << prob.getSystemMatrix().matrix() << '\n';
#endif
prob.solve(adaptInfo);
......
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <iostream>
#include <ctime>
#include <cmath>
......@@ -30,8 +34,8 @@ int main(int argc, char** argv)
Parameters::get("stokes->viscosity", viscosity);
// tree-paths for components
auto _v = 0_c;
auto _p = 1_c;
auto _v = Dune::Indices::_0;
auto _p = Dune::Indices::_1;
// <viscosity*grad(u_i), grad(v_i)>
for (std::size_t i = 0; i < DOW; ++i) {
......@@ -77,10 +81,12 @@ int main(int argc, char** argv)
// assemble and solve system
prob.buildAfterCoarsen(adaptInfo, Flag(0));
#ifdef DEBUG_MTL
// write matrix to file
mtl::io::matrix_market_ostream out("matrix_stokes1.mtx");
out << prob.getSystemMatrix().getMatrix();
std::cout << prob.getSystemMatrix().getMatrix() << '\n';
out << prob.getSystemMatrix().matrix();
std::cout << prob.getSystemMatrix().matrix() << '\n';
#endif
prob.solve(adaptInfo);
......
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <iostream>
#include <ctime>
#include <cmath>
......@@ -24,8 +28,8 @@ int main(int argc, char** argv)
Parameters::get("stokes->viscosity", viscosity);
// tree-paths for components
auto _v = 0_c;
auto _p = 1_c;
auto _v = Dune::Indices::_0;
auto _p = Dune::Indices::_1;
auto opStokes = makeOperator(tag::stokes{}, viscosity);
prob.addMatrixOperator(opStokes, treepath(), treepath());
......
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <iostream>
#include <amdis/AMDiS.hpp>
......@@ -38,13 +42,15 @@ int main(int argc, char** argv)
prob.buildAfterCoarsen(adaptInfo, Flag(0));
#ifdef DEBUG_MTL
// write matrix to file
if (Parameters::get<int>("elliptMesh->global refinements").value_or(0) < 4) {
mtl::io::matrix_market_ostream out("matrix.mtx");
out << prob.getSystemMatrix().getMatrix();
out << prob.getSystemMatrix().matrix();
std::cout << prob.getSystemMatrix().getMatrix() << '\n';
std::cout << prob.getSystemMatrix().matrix() << '\n';
}
#endif
prob.solve(adaptInfo);
prob.writeFiles(adaptInfo, true);
......
......@@ -3,14 +3,9 @@
#include <memory>
#include <tuple>
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>
#include <amdis/DirichletBC.hpp>
#include <amdis/LinearAlgebra.hpp>
#include <amdis/LocalAssemblerList.hpp>
#include <amdis/common/Mpl.hpp>
#include <amdis/common/TypeDefs.hpp>
namespace AMDiS
{
......
#pragma once
#include <dune/common/dynmatrix.hh>
#include <dune/common/dynvector.hh>
#include <dune/functions/functionspacebases/subspacebasis.hh>
#include <amdis/utility/TreePath.hpp>
#include <amdis/utility/Visitor.hpp>
......@@ -24,14 +26,14 @@ void Assembler<Traits>::assemble(
// 2. create a local matrix and vector
std::size_t localSize = localView.maxSize();
Impl::ElementMatrix elementMatrix(localSize, localSize);
Impl::ElementVector elementVector(localSize);
Dune::DynamicMatrix<double> elementMatrix(localSize, localSize);
Dune::DynamicVector<double> elementVector(localSize);
// 3. traverse grid and assemble operators on the elements
for (auto const& element : elements(globalBasis_.gridView()))
{
set_to_zero(elementMatrix);
set_to_zero(elementVector);
elementMatrix = 0;
elementVector = 0;
localView.bind(element);
auto geometry = element.geometry();
......@@ -75,24 +77,9 @@ void Assembler<Traits>::assemble(
});
});
// add element-matrix to system-matrix
for (std::size_t i = 0; i < localView.size(); ++i) {
auto const row = localView.index(i);
for (std::size_t j = 0; j < localView.size(); ++j) {
if (std::abs(elementMatrix(i,j)) > threshold<double>) {
auto const col = localView.index(j);
matrix(row,col) += elementMatrix(i,j);
}
}
}
// add element-vector to system-vector
for (std::size_t i = 0; i < localView.size(); ++i) {
if (std::abs(elementVector[i]) > threshold<double>) {
auto const idx = localView.index(i);
rhs[idx] += elementVector[i];
}
}
// add element-matrix to system-matrix and element-vector to rhs
matrix.insert(localView, localView, elementMatrix);
rhs.insert(localView, elementVector);
// unbind all operators
forEachNode_(localView.tree(), [&,this](auto const& rowNode, auto&&) {
......@@ -203,7 +190,7 @@ std::size_t Assembler<Traits>::finishMatrixVector(
});
});
return matrix.getNnz();
return matrix.nnz();
}
} // end namespace AMDiS
......@@ -11,12 +11,14 @@
#include <amdis/Output.hpp>
#include <amdis/common/Concepts.hpp>
#include <amdis/common/ValueCategory.hpp>
#include <amdis/linear_algebra/mtl/MTLDenseVector.hpp>
#include <amdis/linear_algebra/HierarchicWrapper.hpp>
#include <amdis/utility/RangeType.hpp>
#include <amdis/utility/TreeData.hpp>
namespace AMDiS
{
struct BoundaryType { int b; };
/// Implements a boundary condition of Dirichlet-type.
/**
* By calling the methods \ref init() and \ref finish before and after
......@@ -82,13 +84,13 @@ namespace AMDiS
using Dune::Functions::interpolate;
Dune::Hybrid::ifElse(std::is_same<RangeType_t<typename RowBasis::LocalView::Tree>, Range>{},
[&](auto id) {
auto rhsWrapper = wrapper(rhs.getVector());
auto rhsWrapper = hierarchicVectorWrapper(rhs.vector());
interpolate(id(rowBasis), rhsWrapper, values_, dirichletNodes_);
});
Dune::Hybrid::ifElse(std::is_same<RangeType_t<typename ColBasis::LocalView::Tree>, Range>{},
[&](auto id) {
auto solutionWrapper = wrapper(solution.getVector());
auto solutionWrapper = hierarchicVectorWrapper(solution.vector());
interpolate(id(colBasis), solutionWrapper, values_, dirichletNodes_);
});
......
......@@ -3,9 +3,6 @@
#include <dune/functions/functionspacebases/boundarydofs.hh>
#include <dune/functions/functionspacebases/interpolate.hh>
#include <dune/functions/functionspacebases/subspacebasis.hh>
#include <amdis/LinearAlgebra.hpp>
#include <amdis/linear_algebra/HierarchicWrapper.hpp>
#include <amdis/linear_algebra/mtl/MTLDenseVector.hpp>
namespace AMDiS
{
......
......@@ -43,14 +43,13 @@ namespace AMDiS
constexpr std::size_t VTKFieldSize = Size<Range>;
template <class Traits, class TreePath>
template <class GlobalBasis, class RangeType, class TreePath>
class FileWriter
: public FileWriterInterface
{
private: // typedefs and static constants
using GlobalBasis = typename Traits::GlobalBasis;
using GridView = typename GlobalBasis::GridView;
using Vector = DOFVectorConstView<Traits,TreePath>;
using Vector = DOFVectorConstView<GlobalBasis,RangeType,TreePath>;
using Range = typename Vector::Range;
/// Dimension of the mesh
......@@ -123,12 +122,12 @@ namespace AMDiS
};
template <class Traits, class TreePath>
std::shared_ptr<FileWriter<Traits,TreePath>> makeFileWriterPtr(
std::string baseName,
DOFVectorConstView<Traits,TreePath> const& dofvector)
template <class GlobalBasis, class Range, class TreePath>
std::shared_ptr<FileWriter<GlobalBasis,Range,TreePath>>
makeFileWriterPtr(std::string baseName,
DOFVectorConstView<GlobalBasis,Range,TreePath> const& dofvector)
{
return std::make_shared<FileWriter<Traits,TreePath>>(baseName, dofvector);
return std::make_shared<FileWriter<GlobalBasis,Range,TreePath>>(baseName, dofvector);
}
} // end namespace AMDiS
......@@ -6,6 +6,7 @@
#include <amdis/GridFunctions.hpp>
#include <amdis/LocalOperator.hpp>
#include <amdis/QuadratureFactory.hpp>
#include <amdis/common/Transposed.hpp>
#include <amdis/common/Utility.hpp>
#include <amdis/utility/FiniteElementType.hpp>
......@@ -172,7 +173,7 @@ namespace AMDiS
ColNode const& colNode,
ElementMatrix& elementMatrix)
{
auto elementMatrixTransposed = trans(elementMatrix);
auto elementMatrixTransposed = transposed(elementMatrix);
transposedOp_.getElementMatrix(
context, colNode, rowNode, elementMatrixTransposed);
}
......
#pragma once
#include <amdis/linear_algebra/LinearSolverInterface.hpp>
#include <amdis/linear_algebra/LinearSolver.hpp>
#include <amdis/linear_algebra/SolverInfo.hpp>
#if defined(AMDIS_BACKEND_ISTL)
#include <amdis/linear_algebra/istl/SystemVector.hpp>
#include <amdis/linear_algebra/istl/SystemMatrix.hpp>
#include <amdis/linear_algebra/istl/LinearSolver.hpp>
#elif defined(AMDIS_BACKEND_MTL)
#include <amdis/linear_algebra/mtl/SystemVector.hpp>
#include <amdis/linear_algebra/mtl/SystemMatrix.hpp>
#include <amdis/linear_algebra/mtl/LinearSolver.hpp>
#if HAVE_MTL
#include <amdis/linear_algebra/mtl/DOFVector.hpp>
#include <amdis/linear_algebra/mtl/DOFMatrix.hpp>
#include <amdis/linear_algebra/mtl/ITL_Solver.hpp>
#include <amdis/linear_algebra/mtl/BITL_Solver.hpp>
#elif defined(AMDIS_BACKEND_PETSC)
#include <amdis/linear_algebra/petsc/SystemVector.hpp>
#include <amdis/linear_algebra/petsc/SystemMatrix.hpp>
#include <amdis/linear_algebra/petsc/LinearSolver.hpp>
#include <amdis/linear_algebra/mtl/ITL_Preconditioner.hpp>
#else
#error "Unknown linear algebra backend!. Set corresponding variable \
AMDIS_BACKEND_ISTL, AMDIS_BACKEND_MTL or AMDIS_BACKEND_PETSC."
#include <amdis/linear_algebra/istl/DOFVector.hpp>
#include <amdis/linear_algebra/istl/DOFMatrix.hpp>
#include <amdis/linear_algebra/istl/ISTL_Solver.hpp>
#include <amdis/linear_algebra/istl/ISTL_Preconditioner.hpp>
#endif
\ No newline at end of file
......@@ -2,9 +2,10 @@
#include <type_traits>
#include <dune/common/dynmatrix.hh>
#include <dune/common/dynvector.hh>
#include <amdis/ContextGeometry.hpp>
// #include <amdis/common/ConceptsBase.hpp>
#include <amdis/common/TypeDefs.hpp>
namespace AMDiS
{
......@@ -22,10 +23,13 @@ namespace AMDiS
static_assert( numNodes == 1 || numNodes == 2,
"VectorAssembler gets 1 Node, MatrixAssembler gets 2 Nodes!");
using ElementMatrix = Dune::DynamicMatrix<double>; // TODO: choose correct value_type
using ElementVector = Dune::DynamicVector<double>;
/// Either an ElementVector or an ElementMatrix (depending on the number of nodes)
using ElementMatrixVector = std::conditional_t<
(sizeof...(Nodes)==1), Impl::ElementVector, std::conditional_t<
(sizeof...(Nodes)==2), Impl::ElementMatrix, void>>;
(sizeof...(Nodes)==1), ElementVector, std::conditional_t<
(sizeof...(Nodes)==2), ElementMatrix, void>>;
public:
/// Virtual destructor
......
......@@ -60,6 +60,8 @@ namespace AMDiS
/// Returns \ref oldSolution.
std::unique_ptr<SystemVector> getOldSolutionVector() const
{
test_exit_dbg(oldSolution,
"OldSolution need to be created. Call initialize with INIT_UH_OLD.");
return *oldSolution;
}
......
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