diff --git a/CMakeLists.txt b/CMakeLists.txt index 96780b564c01ae7e5eaf11d4036a83cc8ad94ee1..d78b1952c0358822c7bf62009b13b6968cab87f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,12 +19,7 @@ add_subdirectory("test") add_subdirectory("examples" EXCLUDE_FROM_ALL) add_subdirectory("doc") add_subdirectory("cmake/modules") -add_subdirectory("externals" EXCLUDE_FROM_ALL) - -target_include_directories(amdis PUBLIC - $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>) -target_compile_definitions(amdis PUBLIC AMDIS_BACKEND_MTL=1) -target_compile_options(amdis PUBLIC -Wall -pedantic -Wno-unused-parameter) #-ftemplate-backtrace-limit=0 +add_subdirectory("externals") # finalize the dune project, e.g. generating config.h etc. finalize_dune_project(GENERATE_CONFIG_H_CMAKE) diff --git a/LICENSE b/LICENSE index 2c2d56d1414fda06e3df153f5fa2ca02ab303ff8..0abd3507f63bfb8dc5be8d32d2b222b4dd626625 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ The MIT License (MIT) -Copyright (c) 2016 Simon Praetorius +Copyright (c) 2016-2018 Simon Praetorius + 2018 Felix Müller Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/dune.module b/dune.module index 0a19748dfd64b9b1c23ea8dff5c83d155df460b2..390ad16e23f809e35891886e8edf4c13e2b551ce 100644 --- a/dune.module +++ b/dune.module @@ -2,10 +2,8 @@ # Dune module information file # ################################ -#Name of the module Module: amdis Version: 0.1 Maintainer: simon.praetorius@tu-dresden.de -#depending on Depends: dune-common (>= 2.6) dune-geometry (>= 2.6) dune-localfunctions (>= 2.6) dune-typetree (>= 2.6) dune-grid (>= 2.6) dune-functions (>= 2.6) -#Suggests: dune-uggrid dune-alugrid dune-foamgrid +Suggests: dune-uggrid dune-alugrid dune-foamgrid diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d799f6d14ed1e55fc0079930b91b678d0c568e21..2f16438f461cd6c7f5fdcb4304d8b55ecbca086b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -6,7 +6,7 @@ foreach(project ${projects2d}) add_executable(${project}.2d ${project}.cc) add_dune_alberta_flags(GRIDDIM 2 WORLDDIM 2 ${project}.2d) target_link_dune_default_libraries(${project}.2d) - target_link_libraries(${project}.2d amdis fmt) + target_link_libraries(${project}.2d amdis) target_compile_definitions(${project}.2d PRIVATE AMDIS_DIM=2 AMDIS_DOW=2) add_dependencies(examples ${project}.2d) endforeach() @@ -17,7 +17,7 @@ foreach(project ${projects3d}) add_executable(${project}.3d ${project}.cc) add_dune_alberta_flags(GRIDDIM 3 WORLDDIM 3 ${project}.3d) target_link_dune_default_libraries(${project}.3d) - target_link_libraries(${project}.3d amdis fmt) + target_link_libraries(${project}.3d amdis) target_compile_definitions(${project}.3d PRIVATE AMDIS_DIM=3 AMDIS_DOW=3) add_dependencies(examples ${project}.3d) endforeach() \ No newline at end of file diff --git a/examples/ellipt.cc b/examples/ellipt.cc index fc7830e8fee7e0b9b46ec87198a53e30593fb627..d898f3e2a50c636458159c7b8016916fe919fb00 100644 --- a/examples/ellipt.cc +++ b/examples/ellipt.cc @@ -3,8 +3,6 @@ #endif #include <iostream> -#include <fmt/core.h> - #include <amdis/AMDiS.hpp> #include <amdis/ProblemStat.hpp> #include <amdis/Operators.hpp> @@ -79,9 +77,9 @@ int main(int argc, char** argv) } std::cout << "\n"; - fmt::print("{:5} | {:12} | {:12} | {:12} | {:12} | {:12}\n", - "level", "h", "|u - u*|_L2","|u - u*|_H1","eoc_L2","eoc_H1"); - fmt::print("{0:->7}{0:->15}{0:->15}{0:->15}{0:->15}{1:->14}","+","\n"); + msg("{:5} | {:12} | {:12} | {:12} | {:12} | {:12}\n", + "level", "h", "|u - u*|_L2","|u - u*|_H1","eoc_L2","eoc_H1"); + msg("{0:->7}{0:->15}{0:->15}{0:->15}{0:->15}{1:->14}","+","\n"); std::vector<double> eocL2(numLevels, 0.0), eocH1(numLevels, 0.0); for (int i = 1; i < numLevels; ++i) { @@ -90,8 +88,8 @@ int main(int argc, char** argv) } for (int i = 0; i < numLevels; ++i) - fmt::print("{:<5} | {:<12} | {:<12} | {:<12} | {:<12} | {:<12}\n", - i+1, widths[i], errL2[i], errH1[i], eocL2[i], eocH1[i]); + msg("{:<5} | {:<12} | {:<12} | {:<12} | {:<12} | {:<12}\n", + i+1, widths[i], errL2[i], errH1[i], eocL2[i], eocH1[i]); AMDiS::finalize(); return 0; diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index 763f19e11d62943509a44746ba6c70ad04bd390e..458666474136fce6b1c85d7e6c56f0172a232854 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -1 +1,17 @@ -add_subdirectory(fmt) \ No newline at end of file +target_include_directories(amdis PUBLIC + $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/externals/fmt/include>) + +dune_library_add_sources(amdis SOURCES + fmt/src/format.cc + fmt/src/posix.cc) + +install(FILES + fmt/include/fmt/core.h + fmt/include/fmt/format-inl.h + fmt/include/fmt/format.h + fmt/include/fmt/ostream.h + fmt/include/fmt/posix.h + fmt/include/fmt/printf.h + fmt/include/fmt/ranges.h + fmt/include/fmt/time.h +DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fmt) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 40bcf102c971ada8c4e1fdb7e1f7da7e38259345..ae19d33d55975a9ac1374796afb1a40341a24033 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1 +1,5 @@ -add_subdirectory(amdis) \ No newline at end of file +add_subdirectory(amdis) + +target_include_directories(amdis PUBLIC + $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>) +target_compile_options(amdis PUBLIC -Wall -pedantic -Wno-unused-parameter) #-ftemplate-backtrace-limit=0 diff --git a/src/amdis/AdaptInstationary.cpp b/src/amdis/AdaptInstationary.cpp index 05e4b9fd030cdaf2dcd34e8dbb6b722d15ae99ab..0315af81c75ebd7c866af6b714d9b940293b173b 100644 --- a/src/amdis/AdaptInstationary.cpp +++ b/src/amdis/AdaptInstationary.cpp @@ -41,7 +41,7 @@ namespace AMDiS problemTime->setTime(adaptInfo); - msg("time = ", adaptInfo.getTime(), ", timestep = ", adaptInfo.getTimestep()); + msg("time = {}, timestep = {}", adaptInfo.getTime(), adaptInfo.getTimestep()); adaptInfo.setSpaceIteration(0); @@ -62,7 +62,7 @@ namespace AMDiS adaptInfo.setTime(adaptInfo.getTime() + adaptInfo.getTimestep()); problemTime->setTime(adaptInfo); - msg("time = ", adaptInfo.getTime(), ", timestep = ", adaptInfo.getTimestep()); + msg("time = {}, timestep = {}", adaptInfo.getTime(), adaptInfo.getTimestep()); problemIteration->oneIteration(adaptInfo, NO_ADAPTION); @@ -153,7 +153,7 @@ namespace AMDiS adaptInfo.setTime(adaptInfo.getTime() + adaptInfo.getTimestep()); problemTime->setTime(adaptInfo); - msg("time = ", adaptInfo.getTime(), ", timestep = ", adaptInfo.getTimestep()); + msg("time = {}, timestep = {}", adaptInfo.getTime(), adaptInfo.getTimestep()); problemIteration->oneIteration(adaptInfo, FULL_ITERATION); @@ -189,7 +189,7 @@ namespace AMDiS simpleAdaptiveTimeStrategy(); break; default: - error_exit("Unknown strategy = ", strategy); + error_exit("Unknown strategy = {}", strategy); } adaptInfo.incTimestepNumber(); diff --git a/src/amdis/Assembler.inc.hpp b/src/amdis/Assembler.inc.hpp index 2854493e03077196120f629a32ecb0fccbca0308..b8c897be96d22f894ee69fda40547c5a7ca8147f 100644 --- a/src/amdis/Assembler.inc.hpp +++ b/src/amdis/Assembler.inc.hpp @@ -95,7 +95,7 @@ void Assembler<Traits>::assemble( // 4. finish matrix insertion and apply dirichlet boundary conditions std::size_t nnz = finishMatrixVector(matrix, solution, rhs, asmMatrix, asmVector); - msg("fill-in of assembled matrix: ", nnz); + msg("fill-in of assembled matrix: {}", nnz); } @@ -142,7 +142,7 @@ void Assembler<Traits>::initMatrixVector( { #ifdef HAVE_EXTENDED_DUNE_FUNCTIONS if (rowNode.isLeaf) - msg(globalBasis_.dimension(rowTreePath), " DOFs for Basis[", to_string(rowTreePath), "]"); + msg("{} DOFs for Basis[{}]",globalBasis_.dimension(rowTreePath), to_string(rowTreePath)); #endif auto rowBasis = Dune::Functions::subspaceBasis(globalBasis_, rowTreePath); @@ -155,7 +155,7 @@ void Assembler<Traits>::initMatrixVector( bc->init(matrix, solution, rhs, rowBasis, colBasis); }); }); - msg(globalBasis_.dimension(), " total DOFs"); + msg("{} total DOFs", globalBasis_.dimension()); } diff --git a/src/amdis/CreatorMap.hpp b/src/amdis/CreatorMap.hpp index d0805353d1e817b88c94b50fb6f791d4e5ff97c8..4ec1eae1680e907dc23ca21e0569f50af748d3fe 100644 --- a/src/amdis/CreatorMap.hpp +++ b/src/amdis/CreatorMap.hpp @@ -36,7 +36,7 @@ namespace AMDiS static void addCreator(std::string key, CreatorInterface<BaseClass>* creator) { init(); - test_exit(!creatorMap[key], "There is already a creator for key ", key); + test_exit(!creatorMap[key], "There is already a creator for key {}", key); creatorMap[key] = creator; } @@ -50,7 +50,7 @@ namespace AMDiS key = "default"; auto creator = creatorMap[key]; - test_exit(creator, "No creator for key `", key, "` defined in init file for parameter `", initFileStr, "`"); + test_exit(creator, "No creator for key `{}` defined in init file for parameter `{}`", key, initFileStr); return creator; } diff --git a/src/amdis/FileWriter.hpp b/src/amdis/FileWriter.hpp index 7e0686d3fef0c5a45713fc661cf81416406ab04d..a66c8e9c2c27efd85a41d6bfc19d4c36a1d74043 100644 --- a/src/amdis/FileWriter.hpp +++ b/src/amdis/FileWriter.hpp @@ -94,7 +94,7 @@ namespace AMDiS /// Implements \ref FileWriterInterface::writeFiles virtual void writeFiles(AdaptInfo& adaptInfo, bool force) override { - test_exit(filesystem::exists(dir_), "Output directory '",dir_,"' does not exist!"); + test_exit(filesystem::exists(dir_), "Output directory '{}' does not exist!",dir_); if (vtkSeqWriter_) vtkSeqWriter_->write(adaptInfo.getTime(), mode_); diff --git a/src/amdis/InitfileParser.cpp b/src/amdis/InitfileParser.cpp index e1c7ee66755ec4447f249d7f2ee5f1aa0dc618f9..67b3de7fc6b0fc35eaf37537a190d4a538a111db 100644 --- a/src/amdis/InitfileParser.cpp +++ b/src/amdis/InitfileParser.cpp @@ -9,7 +9,7 @@ namespace AMDiS { void InitfileParser::readInitfile(std::string fn, Dune::ParameterTree& pt, bool overwrite) { test_exit(filesystem::exists(fn), - "init-file '", fn, "' cannot be opened for reading"); + "init-file '{}' cannot be opened for reading", fn); // read file if its not parsed already auto ins = includeList().insert(fn); diff --git a/src/amdis/Marker.inc.hpp b/src/amdis/Marker.inc.hpp index 7f06e94d711ef5514d9ba1b33242da5394ca03c7..7e5239b847be59ae5d1e94d9142f2123669d3c3f 100644 --- a/src/amdis/Marker.inc.hpp +++ b/src/amdis/Marker.inc.hpp @@ -52,8 +52,8 @@ void Marker<Traits>::initMarking(AdaptInfo& adaptInfo) template <class Traits> void Marker<Traits>::finishMarking(AdaptInfo& adaptInfo) { - msg(elMarkRefine_, " elements marked for refinement"); - msg(elMarkCoarsen_, " elements marked for coarsening"); + msg("{} elements marked for refinement", elMarkRefine_); + msg("{} elements marked for coarsening", elMarkCoarsen_); } @@ -110,7 +110,8 @@ void MSMarker<Traits>::initMarking(AdaptInfo& adaptInfo) this->markRLimit_ = msGammaP * adaptInfo.getEstMax(this->component_); this->markCLimit_ = msGammaCP * adaptInfo.getEstMax(this->component_); - msg("start max_est: ", adaptInfo.getEstMax(this->component_), ", mark_limits: ", this->markRLimit_, ", " , this->markCLimit_); + msg("start max_est: {}, mark_limits: {}, {}", + adaptInfo.getEstMax(this->component_), this->markRLimit_ , this->markCLimit_); } @@ -131,7 +132,7 @@ void ESMarker<Traits>::initMarking(AdaptInfo& adaptInfo) this->markRLimit_ = esThetaP * epsP / nLeaves; this->markCLimit_ = esThetaCP * epsP / nLeaves; - msg("start mark_limits: ", this->markRLimit_, ", " , this->markCLimit_, "; nt = ", nLeaves); + msg("start mark_limits: {}, {}; nt = {}", this->markRLimit_, this->markCLimit_, nLeaves); } @@ -156,7 +157,7 @@ Flag GERSMarker<Traits>::markGrid(AdaptInfo& adaptInfo) if (redfac < 1.0) { LTheta *= redfac; - msg("GERS: use extrapolated theta_star = ", std::pow(LTheta, 1.0 / this->p_)); + msg("GERS: use extrapolated theta_star = {}", std::pow(LTheta, 1.0 / this->p_)); } } @@ -176,7 +177,7 @@ Flag GERSMarker<Traits>::markGrid(AdaptInfo& adaptInfo) } while((GERSGamma > 0) && (gersSum_ < LTheta * this->estSum_)); } - msg("GERS refinement with gamma = ", GERSGamma); + msg("GERS refinement with gamma = {}", GERSGamma); } if (this->coarsenAllowed_) { @@ -191,10 +192,10 @@ Flag GERSMarker<Traits>::markGrid(AdaptInfo& adaptInfo) for (const auto& elem : Dune::elements(this->grid_->leafGridView())) markElementForCoarsening(adaptInfo, elem); - msg("coarse loop: gamma = ", GERSGamma, ", sum = ", gersSum_, ", limit = ", LTheta); + msg("coarse loop: gamma = {}, sum = {}, limit = {}", GERSGamma, gersSum_, LTheta); } while(gersSum_ > LTheta); - msg("GERS coarsening with gamma = ", GERSGamma); + msg("GERS coarsening with gamma = {}", GERSGamma); } Super::finishMarking(adaptInfo); diff --git a/src/amdis/Mesh.hpp b/src/amdis/Mesh.hpp index f45190373c1b454f7d08adc2c64b461e153423a5..4ee1b7e4199673eaa564352c65384a866ffa0017 100644 --- a/src/amdis/Mesh.hpp +++ b/src/amdis/Mesh.hpp @@ -145,8 +145,6 @@ namespace AMDiS Dune::FieldVector<double, dim> L; L = 1.0; // extension of the domain Parameters::get(meshName + "->dimension", L); - msg("L = ", L); - auto s = Dune::filledArray<std::size_t(dim)>(1); // number of cells on coarse mesh in each direction Parameters::get(meshName + "->num cells", s); diff --git a/src/amdis/Output.hpp b/src/amdis/Output.hpp index d3366ad1c85cd792f41262ba477e595ad0b8164c..b61ed5fdb80003ccba3308d0dd073db8f6c0db6b 100644 --- a/src/amdis/Output.hpp +++ b/src/amdis/Output.hpp @@ -5,6 +5,8 @@ #include <sstream> #include <string> +#include <fmt/core.h> + /** * \def AMDIS_NO_THROW * \brief The preprocessor constant sets whether to use c-asserts (if defined) or @@ -37,10 +39,6 @@ #endif #endif - -#define AMDIS_STATIC_ASSERT(...) \ - static_assert(__VA_ARGS__, #__VA_ARGS__) - #define AMDIS_UNUSED(var) __attribute__((unused)) var #define AMDIS_FUNCNAME(nn) AMDIS_UNUSED(const char *funcName); funcName = nn; @@ -58,23 +56,6 @@ namespace AMDiS { namespace Impl { - template <class OStream> - OStream& concat(OStream& out) { return out; } - - template <class OStream, class Arg0, class... Args> - OStream& concat(OStream& out, Arg0&& arg0, Args&&... args) - { - out << arg0; concat(out, std::forward<Args>(args)...); - return out; - } - - template <class... Args> - std::string to_string(Args&&... args) - { - std::stringstream ss; concat(ss, std::forward<Args>(args)...); - return ss.str(); - } - template <class OStream, class... Args> OStream& msg(OStream& out, Args&&... args) { @@ -84,12 +65,12 @@ namespace AMDiS MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &num_ranks); if (num_ranks > 1 && rank == 0) { - concat(out, "[0] ",std::forward<Args>(args)...); + out << "[0] " << fmt::format(std::forward<Args>(args)...); } else if (num_ranks == 1) { - concat(out, std::forward<Args>(args)...); + out << fmt::format(std::forward<Args>(args)...); } #else - concat(out, std::forward<Args>(args)...); + out << fmt::format(std::forward<Args>(args)...); #endif return out; } @@ -107,7 +88,7 @@ namespace AMDiS template <class... Args> void msg(Args&&... args) { - Impl::msg(std::cout, std::forward<Args>(args)..., "\n"); + Impl::msg(std::cout, std::forward<Args>(args)...) << std::endl; } @@ -135,14 +116,14 @@ namespace AMDiS void error_exit(Args&&... args) { #ifdef AMDIS_NO_THROW - Impl::msg(std::cerr, "ERROR: ", std::forward<Args>(args)..., "\n"); + Impl::msg(std::cerr << "ERROR: ", std::forward<Args>(args)...) << std::endl; #ifndef NDEBUG assert(false); #else std::exit(EXIT_FAILURE); #endif #else - throw std::runtime_error( Impl::to_string("ERROR: ", std::forward<Args>(args)...) ); + throw std::runtime_error( std::string("ERROR: ") + fmt::format(std::forward<Args>(args)...)); #endif } @@ -166,7 +147,7 @@ namespace AMDiS template <class... Args> void warning(Args&&... args) { - msg("WARNING: ", std::forward<Args>(args)...); + Impl::msg(std::cout << "WARNING: ", std::forward<Args>(args)...) << std::endl; } diff --git a/src/amdis/ProblemStat.hpp b/src/amdis/ProblemStat.hpp index 0a53c64db5594422c3182544185357dde60ab29a..d00ee6b9dbf50579da6b9cb7c4bd1c0d0b8ae62d 100644 --- a/src/amdis/ProblemStat.hpp +++ b/src/amdis/ProblemStat.hpp @@ -253,14 +253,14 @@ namespace AMDiS { gridName_ = ""; Parameters::get(name_ + "->mesh", gridName_); - test_exit(!gridName_.empty(), "No grid name specified for '", name_, "->mesh'!"); + test_exit(!gridName_.empty(), "No grid name specified for '{}->mesh'!", name_); grid_ = MeshCreator<Grid>::create(gridName_); msg("Create grid:"); - msg("#elements = " , grid_->size(0)); - msg("#faces/edges = ", grid_->size(1)); - msg("#vertices = " , grid_->size(dim)); + msg("#elements = {}" , grid_->size(0)); + msg("#faces/edges = {}", grid_->size(1)); + msg("#vertices = {}" , grid_->size(dim)); msg(""); } diff --git a/src/amdis/ProblemStat.inc.hpp b/src/amdis/ProblemStat.inc.hpp index 833b31c882d8ba0e9d665f100a2d564af54da3a0..1cd623d6f4448beb0cc2110735f7c352477cfe44 100644 --- a/src/amdis/ProblemStat.inc.hpp +++ b/src/amdis/ProblemStat.inc.hpp @@ -285,14 +285,14 @@ solve(AdaptInfo& adaptInfo, bool createMatrixData, bool storeMatrixData) solverInfo); if (solverInfo.getInfo() > 0) { - msg("solution of discrete system needed ", t.elapsed(), " seconds"); + msg("solution of discrete system needed {} seconds", t.elapsed()); if (solverInfo.getAbsResidual() >= 0.0) { if (solverInfo.getRelResidual() >= 0.0) - msg("Residual norm: ||b-Ax|| = ", solverInfo.getAbsResidual(), - ", ||b-Ax||/||b|| = ", solverInfo.getRelResidual()); + msg("Residual norm: ||b-Ax|| = {}, ||b-Ax||/||b|| = {}", + solverInfo.getAbsResidual(), solverInfo.getRelResidual()); else - msg("Residual norm: ||b-Ax|| = ", solverInfo.getAbsResidual()); + msg("Residual norm: ||b-Ax|| = {}", solverInfo.getAbsResidual()); } } @@ -304,7 +304,7 @@ solve(AdaptInfo& adaptInfo, bool createMatrixData, bool storeMatrixData) if (solverInfo.getRelTolerance() > 0 && solverInfo.getRelResidual() > solverInfo.getRelTolerance()) tol_str << "relTol = " << solverInfo.getRelTolerance() << " "; - error_exit("Tolerance ", tol_str.str(), " could not be reached!"); + error_exit("Tolerance {} could not be reached!", tol_str.str()); } } @@ -318,7 +318,7 @@ Flag ProblemStat<Traits>::markElements(AdaptInfo& adaptInfo) for (auto& currentMarker : marker_) markFlag |= currentMarker->markGrid(adaptInfo); - msg("markElements needed ", t.elapsed(), " seconds"); + msg("markElements needed {} seconds", t.elapsed()); return markFlag; } @@ -335,7 +335,7 @@ buildAfterCoarsen(AdaptInfo& /*adaptInfo*/, Flag /*flag*/, bool asmMatrix, bool globalBasis_->update(gv); assembler.assemble(*systemMatrix_, *solution_, *rhs_, asmMatrix, asmVector); - msg("buildAfterCoarsen needed ", t.elapsed(), " seconds"); + msg("buildAfterCoarsen needed {} seconds", t.elapsed()); } @@ -346,7 +346,7 @@ writeFiles(AdaptInfo& adaptInfo, bool force) Dune::Timer t; for (auto writer : filewriter_) writer->writeFiles(adaptInfo, force); - msg("writeFiles needed ", t.elapsed(), " seconds"); + msg("writeFiles needed {} seconds", t.elapsed()); } diff --git a/src/amdis/StandardProblemIteration.cpp b/src/amdis/StandardProblemIteration.cpp index 434e0d19df1d2e660d5035afd4a25388004064bc..26a9ca025ea60e8a7f891b55436ba507533aa7c4 100644 --- a/src/amdis/StandardProblemIteration.cpp +++ b/src/amdis/StandardProblemIteration.cpp @@ -28,7 +28,7 @@ namespace AMDiS AMDIS_FUNCNAME("StandardProblemIteration::beginIteration()"); msg(""); - msg("begin of iteration number: ", (adaptInfo.getSpaceIteration() + 1)); + msg("begin of iteration number: {}", (adaptInfo.getSpaceIteration() + 1)); msg("============================="); } @@ -55,7 +55,7 @@ namespace AMDiS AMDIS_FUNCNAME("StandardProblemIteration::endIteration()"); msg(""); - msg("end of iteration number: ", (adaptInfo.getSpaceIteration() + 1)); + msg("end of iteration number: {}", (adaptInfo.getSpaceIteration() + 1)); msg("============================="); } diff --git a/src/amdis/linear_algebra/LinearSolver.hpp b/src/amdis/linear_algebra/LinearSolver.hpp index b132ef31ba780e5591000c50bf304a5848b29837..fc5a5309c96e6b64b75ed148a87f0b896716820a 100644 --- a/src/amdis/linear_algebra/LinearSolver.hpp +++ b/src/amdis/linear_algebra/LinearSolver.hpp @@ -62,7 +62,7 @@ namespace AMDiS } if (solverInfo.getInfo() > 0) - msg("fill matrix needed ", t.elapsed(), " seconds"); + msg("fill matrix needed {} seconds", t.elapsed()); int error = runner_->solve(A, x, b, solverInfo); solverInfo.setError(error); diff --git a/src/amdis/linear_algebra/istl/DOFMatrix.hpp b/src/amdis/linear_algebra/istl/DOFMatrix.hpp index 61837bf6083cdb3830c306245e1edcff9880edfd..80533f0b4e944ce49626cdd888bc85faac63d6c8 100644 --- a/src/amdis/linear_algebra/istl/DOFMatrix.hpp +++ b/src/amdis/linear_algebra/istl/DOFMatrix.hpp @@ -61,7 +61,7 @@ namespace AMDiS { test_exit_dbg( initialized_, "Occupation pattern not initialized!"); test_exit_dbg( r < matrix_.N() && c < matrix_.M() , - "Indices out of range [0,", matrix_.N(), ")x[0,", matrix_.M(), ")" ); + "Indices out of range [0,{})x[0,{})", matrix_.N(), matrix_.M() ); matrix_[r][c] += value; } diff --git a/src/amdis/linear_algebra/istl/DOFVector.hpp b/src/amdis/linear_algebra/istl/DOFVector.hpp index a1234090740cb542c806b6e13b54bf5817ff1c2a..c1704a2235e56a326c8e6e8695bb8c8e472f1b15 100644 --- a/src/amdis/linear_algebra/istl/DOFVector.hpp +++ b/src/amdis/linear_algebra/istl/DOFVector.hpp @@ -66,7 +66,7 @@ namespace AMDiS value_type const& operator[](size_type i) const { test_exit_dbg(i < vector_.size(), - "Index ", i, " out of range [0,", vector_.size(), ")" ); + "Index {} out of range [0,{})", i, vector_.size()); return vector_[i]; } @@ -74,7 +74,7 @@ namespace AMDiS value_type& operator[](size_type i) { test_exit_dbg(i < vector_.size(), - "Index ", i, " out of range [0,", vector_.size(), ")" ); + "Index {} out of range [0,{})", i, vector_.size()); return vector_[i]; } diff --git a/src/amdis/linear_algebra/mtl/DOFMatrix.hpp b/src/amdis/linear_algebra/mtl/DOFMatrix.hpp index 5d3824c10d697d0d442f7714904e57f3c0b6a69c..0c663ee2e4aed3a653a92c7eb7ddaa6bf52a9af4 100644 --- a/src/amdis/linear_algebra/mtl/DOFMatrix.hpp +++ b/src/amdis/linear_algebra/mtl/DOFMatrix.hpp @@ -61,7 +61,7 @@ namespace AMDiS { test_exit_dbg(inserter_, "Inserter not initilized!"); test_exit_dbg(r < num_rows(matrix_) && c < num_cols(matrix_), - "Indices out of range [0,", num_rows(matrix_), ")x[0,", num_cols(matrix_), ")" ); + "Indices out of range [0,{})x[0,{})", num_rows(matrix_), num_cols(matrix_)); (*inserter_)[r][c] += value; } diff --git a/src/amdis/linear_algebra/mtl/DOFVector.hpp b/src/amdis/linear_algebra/mtl/DOFVector.hpp index 01842741a5ffae416f7fe4866204bab847b3072a..f87b5aaca0583ce2781d449825d2232a7ffd076d 100644 --- a/src/amdis/linear_algebra/mtl/DOFVector.hpp +++ b/src/amdis/linear_algebra/mtl/DOFVector.hpp @@ -54,7 +54,7 @@ namespace AMDiS value_type const& operator[](size_type i) const { test_exit_dbg(i < mtl::vec::size(vector_), - "Index ", i, " out of range [0,", mtl::vec::size(vector_), ")" ); + "Index {} out of range [0,{})", i, mtl::vec::size(vector_)); return vector_[i]; } @@ -62,7 +62,7 @@ namespace AMDiS value_type& operator[](size_type i) { test_exit_dbg(i < mtl::vec::size(vector_), - "Index ", i, " out of range [0,", mtl::vec::size(vector_), ")" ); + "Index {} out of range [0,{})", i, mtl::vec::size(vector_)); return vector_[i]; } diff --git a/src/amdis/linear_algebra/mtl/UmfpackRunner.hpp b/src/amdis/linear_algebra/mtl/UmfpackRunner.hpp index 26b0cb0805edca1fa5c349f0268be75264b56a38..f3d5351174b1e744ddbf7437e4542c713755b16d 100644 --- a/src/amdis/linear_algebra/mtl/UmfpackRunner.hpp +++ b/src/amdis/linear_algebra/mtl/UmfpackRunner.hpp @@ -60,7 +60,7 @@ namespace AMDiS try { code = (*solver_)(x, b); } catch (mtl::mat::umfpack::error& e) { - error_exit("UMFPACK_ERROR(solve, ", e.code, ") = ", e.what()); + error_exit("UMFPACK_ERROR(solve, {}) = {}", e.code, e.what()); } auto r = Vector(b); @@ -106,7 +106,7 @@ namespace AMDiS try { Super::solver_.reset(new SolverType(fullMatrix, Super::symmetricStrategy_, Super::allocInit_)); } catch (mtl::mat::umfpack::error const& e) { - error_exit("UMFPACK_ERROR(factorize, ", e.code, ") = ", e.what()); + error_exit("UMFPACK_ERROR(factorize, {}) = {}", e.code, e.what()); } } }; diff --git a/src/amdis/test/CMakeLists.txt b/src/amdis/test/CMakeLists.txt deleted file mode 100644 index 576b0a750d6395428d503c96b8a090318e2b4f87..0000000000000000000000000000000000000000 --- a/src/amdis/test/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# maybe unncessary (?) -dune_add_test(NAME test_duneamdis - TARGET duneamdis - COMPILE_ONLY) - -# find_package(GTest REQUIRED) - -set(projects "test1" "test2") -foreach(project ${projects}) - dune_add_test(NAME ${project} - SOURCES ${project}.cc - LINK_LIBRARIES duneamdis ${GTEST_BOTH_LIBRARIES} - COMPILE_DEFINITIONS "DIM=2;DOW=2" - CMD_ARGS "init/test.json.2d") - add_dune_alberta_flags(GRIDDIM 2 WORLDDIM 2 ${project}) - target_include_directories(${project} PRIVATE ${GTEST_INCLUDE_DIRS}) - set_tests_properties(${project} PROPERTIES WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) -endforeach() \ No newline at end of file diff --git a/src/amdis/test/kdtree.hpp b/src/amdis/test/kdtree.hpp deleted file mode 100644 index 007d74ca6b529cc04d87f05484b976b605220ddf..0000000000000000000000000000000000000000 --- a/src/amdis/test/kdtree.hpp +++ /dev/null @@ -1,217 +0,0 @@ -#pragma once - -#include <nanoflann.hpp> - -#include <cstdlib> -#include <iostream> - - -namespace AMDiS -{ - template <class FeSpace> - struct KDTreeMeshAdaptor - { - using MeshView = typename FeSpace::GridView; - using SizeType = typename FeSpace::LocalIndexSet::size_type; - using ValueType = double; - - static constexpr dimension = MeshView::dimension; - static constexpr dimensionworld = MeshView::dimensionworld; - - using Codim0 = typename GridView::template Codim<0>; - using PointType = typename Codim0::Geometry::GlobalCoordinate; - using VectorOfPointsType = std::vector<PointType> ; - - using DataType = typename MeshView::Grid::EntitySeed; - using VectorOfDataType = std::vector<DataType>; - - using Distance = nanoflann::metric_L2_Simple; - - using Self = KDTreeMeshAdaptor<FeSpace>; - using Metric = typename Distance::template traits<ValueType, Self>::distance_t; - using IndexType = nanoflann::KDTreeSingleIndexAdaptor<Metric, Self, dimensionworld, SizeType>; - - public: - unique_ptr<IndexType> index; //! The kd-tree index for the user to call its methods as usual with any other FLANN index. - FeSpace const& feSpace; - - VectorOfPointsType_ m_points; - VectorOfDataType_ m_data; - - std::map<std::hash<DataType>, DataType> shapeValues; - - public: - /// Constructor: takes a const ref to the vector of vectors object with the data points - KDTreeMeshAdaptor(FeSpace const& feSpace_, - const int leaf_max_size = 10) - : feSpace(feSpace_) - , localView(feSpace.localView()) - { - init(); - - index = make_unique<IndexType>(dimensionworld, *this /* adaptor */, - nanoflann::KDTreeSingleIndexAdaptorParams(leaf_max_size, dimensionworld)); - index->buildIndex(); - } - - /// Destructor. - ~KDTreeMeshAdaptor() {} - - void init() - { - for (auto const& element : elements(feSpace.gridView())) { - m_points.push_back(element.geometry().center()); - m_data.push_back(element.seed()); - } - } - - void reinit(const int leaf_max_size = 10) - { - m_points.clear(); - m_data.clear(); - init(); - index.reset(new IndexType(dimensionworld, *this /* adaptor */, - nanoflann::KDTreeSingleIndexAdaptorParams(leaf_max_size, dimensionworld)); - index->buildIndex(); - } - - /** Query for the \a num_closest closest points to a given point (entered as query_point[0:dim-1]). - * Note that this is a short-cut method for index->findNeighbors(). - * The user can also call index->... methods as desired. - * \note nChecks_IGNORED is ignored but kept for compatibility with the original FLANN interface. - */ - inline void query(const ValueType *query_point, - const std::size_t num_closest, - SizeType *out_indices, - ValueType *out_distances_sq, - const int nChecks_IGNORED = 10) const - { - nanoflann::KNNResultSet<ValueType, SizeType> resultSet(num_closest); - resultSet.init(out_indices, out_distances_sq); - index->findNeighbors(resultSet, query_point, nanoflann::SearchParams()); - } - - /** @name Interface expected by KDTreeSingleIndexAdaptor - * @{ */ - - Self const& derived() const - { - return *this; - } - Self& derived() - { - return *this; - } - - // Must return the number of data points - inline std::size_t kdtree_get_point_count() const - { - return m_points.size(); - } - - // Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class: - inline ValueType kdtree_distance(const double *p1, - const SizeType idx_p2, - std::size_t size) const - { - ValueType s = 0.0; - for (std::size_t i = 0; i < size; i++) { - const ValueType d = p1[i] - m_points[idx_p2][i]; - s += d*d; - } - return s; - } - - // Returns the dim'th component of the idx'th point in the class: - inline ValueType kdtree_get_pt(const SizeType idx, std::size_t dim) const - { - return m_points[idx][dim]; - } - - // Optional bounding-box computation: return false to default to a standard bbox computation loop. - // Return true if the BBOX was already computed by the class and returned in "bb" so it can be avoided to redo it again. - // Look at bb.size() to find out the expected dimensionality (e.g. 2 or 3 for point clouds) - template <class BBOX> - bool kdtree_get_bbox(BBOX &bb) const - { - return false; - } - - /** @} */ - - - /** - * strategy and nrOfPoints are ignored - * == evalAtPoint_simple - **/ - template <class DOFVector> - Value_t<DOFVector> evalAtPoint(DOFVector const& vec, PointType const& x) - { - Value_t<DOFVector> value = 0; - - auto const& grid = vec.getFeSpace().gridView().grid(); - DataType elementSeed; - if (getNearestElement(x, elementSeed)) { - auto element = grid.entity(elementSeed); - auto lambda = element.geometry().local(x); - value = localEval(vec, element, lambda); - } - return value; - } - - private: - /// evaluate DOFVector at barycentric coordinates \p lambda in element - template <class FE, class Value, class Element, class LocalCoords> - Value localEval(DOFVector<FE, Value> const& vec, - Element const& element, - LocalCoords const& lambda) - { - localView.bind(element); - - auto const& localFiniteElem = localView.tree().finiteElement(); - auto const& localBasis = localFiniteElem.localBasis(); - const std::size_t nBasisFct = localFiniteElem.size(); - - std::vector<Dune::FieldVector<double,1> > shapeValues; - localBasis.evaluateFunction(lambda, shapeValues); - - Value data = 0; - for (std::size_t j = 0; j < nBasisFct; ++j) { - auto const global_idx = localView.index(j); - data += vector[global_idx] * shapeValues[j]; - } - - return data; - } - - - bool getNearestElement(PointType const& x, DataType& elementSeed) - { - const std::size_t nrOfPoints = 1; - std::vector<DegreeOfFreedom> ret_indexes(nrOfPoints); - std::vector<double> out_dists_sqr(nrOfPoints); - nanoflann::KNNResultSet<double, DegreeOfFreedom> resultSet(nrOfPoints); - - resultSet.init(&ret_indexes[0], &out_dists_sqr[0]); - index->findNeighbors(resultSet, x.begin(), nanoflann::SearchParams()); - - elementSeed = m_data[ret_indexes[0]]; - return true; - } - - private: - typename FeSpace::LocalView localView; - - }; // end of KDTreeMeshAdaptor - - - - template <class FeSpace> - auto provideKDTree(FeSpace const& feSpace) - { - using KD_Tree = KDTreeMeshAdaptor<FeSpace>; - - return make_unique<KD_Tree>(feSpace); - } - -} // end namespace AMDiS diff --git a/src/amdis/test/macro.stand.2d b/src/amdis/test/macro.stand.2d deleted file mode 100644 index 7b0c2db020993373c50bf520a46a7b375f0825b5..0000000000000000000000000000000000000000 --- a/src/amdis/test/macro.stand.2d +++ /dev/null @@ -1,30 +0,0 @@ -DIM: 2 -DIM_OF_WORLD: 2 - -number of elements: 4 -number of vertices: 5 - -element vertices: -0 1 4 -1 2 4 -2 3 4 -3 0 4 - -element boundaries: -0 0 1 -0 0 2 -0 0 3 -0 0 4 - -vertex coordinates: - 0.0 0.0 - 1.0 0.0 - 1.0 1.0 - 0.0 1.0 - 0.5 0.5 - -element neighbours: -1 3 -1 -2 0 -1 -3 1 -1 -0 2 -1 diff --git a/src/amdis/test/test.json.2d b/src/amdis/test/test.json.2d deleted file mode 100644 index 7242fe2bc40ce43822b0d6fedafd5622067281ce..0000000000000000000000000000000000000000 --- a/src/amdis/test/test.json.2d +++ /dev/null @@ -1,29 +0,0 @@ -{ - "dimension of world": 2, - - "elliptMesh": { - "macro file name": "macro.stand.2d", - "global refinements": 10 - }, - - "ellipt": { - "mesh": "elliptMesh", - "dim": 2, - "components": 1, - "polynomial degree[0]": 1, - - "solver": "cg", - "solver" : { - "max iteration": 1000, - "tolerance": 1e-8, - "info": 10, - "left precon": "diag" - }, - - "output": { - "filename": "ellipt.2d", - "ParaView format": 1, - "ParaView mode": 1 - } - } -} diff --git a/src/amdis/test/test1.cc b/src/amdis/test/test1.cc deleted file mode 100644 index a3a154c5226c35ddba8e914b0a021615a1aac6e5..0000000000000000000000000000000000000000 --- a/src/amdis/test/test1.cc +++ /dev/null @@ -1,151 +0,0 @@ -#include <amdis/AMDiS.hpp> -#include <amdis/ProblemStat.hpp> -#include <amdis/common/Literals.hpp> - -#define TEST_EQ(expr1, expr2) test_exit( (expr1) == (expr2), "'" , #expr1 , "' != '" , #expr2 , "'" ) - -#ifndef DIM -#define DIM 2 -#endif -#ifndef DOW -#define DOW 2 -#endif - -using namespace AMDiS; -namespace { - - using TestParam = ProblemStatTraits<DIM, DOW, 1>; - using TestProblem = ProblemStat<TestParam>; - - using MeshView = typename TestProblem::MeshView; - using Geometry = typename MeshView::template Codim<0>::Geometry; - using RefElements = Dune::ReferenceElements<typename Geometry::ctype, Geometry::mydimension>; - - - - template <class FeSpace> - class LocalEvaluation - { - public: - LocalEvaluation(FeSpace const& feSpace) - : localView(feSpace.localView()) - {} - - template <class Element> - void bind(Element const& element) - { - localView.bind(element); - } - - /// evaluate DOFVector at barycentric coordinates \p lambda in element that - /// is bind to instance in \ref bind(). - template <class ValueType, class LocalCoord> - ValueType eval(DOFVector<FeSpace, ValueType> const& vec, LocalCoord const& lambda) - { - auto const& localBasis = localView.tree().finiteElement().localBasis(); - localBasis.evaluateFunction(lambda, shapeValues); - - ValueType data = 0; - for (std::size_t j = 0; j < shapeValues.size(); ++j) { - const auto global_idx = localView.index(j); - data += vec[global_idx] * shapeValues[j]; - } - - return data; - } - - private: - typename FeSpace::LocalView localView; - - std::vector<Dune::FieldVector<double,1> > shapeValues; - }; - - - class AMDiSTester - { - public: - // create a problemStat - AMDiSTester(std::string name) - : prob(make_shared<TestProblem>(name)) - { - prob->initialize(INIT_ALL); - } - - - void test1() // CreateDOFVector - { - using FeSpace = typename TestProblem::template FeSpace<0>; - - // construction of DOFVectors - DOFVector<FeSpace, double> vec1(prob->getFeSpace(0_c), "vec1"); - auto vec2 = makeDOFVector(prob->getFeSpace(0_c), "vec2"); - - // retrieving DOFVectors from problemStat - auto vec3 = prob->getSolution(0_c); - auto vec5 = prob->getSolution<0>(); - auto vec6 = prob->getSolution(index_<0>()); - - auto vec7 = prob->getSolution()->getDOFVector(0_c); - auto vec8 = prob->getSolution()->getDOFVector<0>(); - auto vec9 = prob->getSolution()->getDOFVector(index_<0>()); - - auto& sys_vec = *prob->getSolution(); - auto vec10 = sys_vec[0_c]; - auto vec11 = sys_vec[index_<0>()]; - - // construction of SystemVector - using FeSpaces = typename TestProblem::FeSpaces; - SystemVector<FeSpaces, double> sys_vec1(*prob->getFeSpaces(), prob->getComponentNames()); - auto sys_vec2 = makeSystemVector(*prob->getFeSpaces(), prob->getComponentNames()); - auto sys_vec3 = makeSystemVector(*prob->getFeSpaces(), "sys_vec"); - - // retrieving systemVector from problemStat - auto sys_vec4 = *prob->getSolution(); - } - - - void test2() // FillDOFVector - { - auto& vec = prob->getSolution(0_c); - auto const& feSpace = vec.getFeSpace(); - - // interpolate function to dofvector - vec.interpol([](auto const& x) { return x*x; }); - - // test whether interpolation is fine - using FeSpace = std::decay_t< decltype(feSpace) >; - LocalEvaluation<FeSpace> evaluator(feSpace); - - for (auto const& element : elements(feSpace.gridView())) { - evaluator.bind(element); - - auto const& refElement = RefElements::general(element.type()); - - std::size_t nVertices = element.subEntities(DIM); - for (std::size_t i = 0; i < nVertices; ++i) { - auto pos = refElement.position(i, DIM); - auto data = evaluator.eval(vec, pos); - - auto x = element.geometry().global(pos); - TEST_EQ(data, x*x); - } - } - } - - protected: - shared_ptr<TestProblem> prob; - }; - -} // end namespace - -int main(int argc, char** argv) -{ - AMDiS::init(argc, argv); - - auto tester = make_shared<AMDiSTester>("test"); - tester->test1(); - tester->test2(); - - AMDiS::finalize(); - return 0; -} diff --git a/src/amdis/test/test2.cc b/src/amdis/test/test2.cc deleted file mode 100644 index b24f9428ade461f302de919e0ab3a473629c0b68..0000000000000000000000000000000000000000 --- a/src/amdis/test/test2.cc +++ /dev/null @@ -1,105 +0,0 @@ -#include <amdis/AMDiS.hpp> -#include <amdis/ProblemStat.hpp> -#include <amdis/common/Literals.hpp> - -#ifndef DIM -#define DIM 2 -#endif -#ifndef DOW -#define DOW 2 -#endif - -using namespace AMDiS; - -namespace { - - using TestParam = ProblemStatTraits<DIM, DOW, 1>; - using TestProblem = ProblemStat<TestParam>; - using Op = TestProblem::OperatorType; - - class AMDiSTester - { - public: - // create a problemStat - AMDiSTester(std::string name) - : prob(make_shared<TestProblem>(name)) - { - prob->initialize(INIT_ALL); - } - - - void test1() // AddOperators - { - auto const& u = prob->getSolution<0>(); - - // define operators - Op op1; - op1.addZOT( 1.0 ); - op1.addZOT( constant(1.0) ); - - // value of DOFVector at QPs - op1.addZOT( valueOf(u) ); - op1.addZOT( valueOfFunc(u, [](auto const& U) { return U; }) ); - op1.addZOT( valueOfFunc(u, [](auto const& U) { return U; }, 1) ); - - // partial derivative of DOFVector - op1.addZOT( derivativeOf(u, 0) ); - op1.addZOT( derivativeOf(u, 1) ); - - // op1.addFOT( gradientOf(u), GRD_PSI ); - - // evaluate functor at coordinates - op1.addZOT( eval([](auto const& x) { return x[0]; }) ); - op1.addZOT( [](auto const& x) { return 1.0; } ); - - // add operator to system - prob->addMatrixOperator(op1, 0, 0); - prob->addVectorOperator(op1, 0); - - // define operators with factor argument - Op op2; - op2.addZOT( valueOf(u, 1.0) ); - - op2.addZOT( derivativeOf(u, 0, 1.0) ); - op2.addZOT( derivativeOf(u, 1, 1.0) ); - - // add operator to system, with optional factor as pointer - double* factor = new double(1.0); - prob->addMatrixOperator(op2, 0, 0, factor); - prob->addVectorOperator(op2, 0, factor); - } - - - void test2() // MatrixVector - { - auto const& u = prob->getSolution<0>(); - - using GradOp = std::decay_t< decltype(gradientOf(u)) >; - using DerivOp = std::decay_t< decltype(derivativeOf(u,0)) >; - - using Jacobian = typename GradOp::value_type; - using Derivative = typename DerivOp::value_type; - - Jacobian v, w; - - double erg = v[0].dot(w[0]); - } - - protected: - shared_ptr<TestProblem> prob; - }; - -} // end namespace - - -int main(int argc, char* argv[]) -{ - AMDiS::init(argc, argv); - - auto tester = make_shared<AMDiSTester>("test"); - tester->test1(); - tester->test2(); - - AMDiS::finalize(); - return 0; -} \ No newline at end of file