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