Skip to content
Snippets Groups Projects
Commit d5cb8d3b authored by Timo Koch's avatar Timo Koch
Browse files

Merge branch 'fix/timeloop-negative-time' into 'master'

[timeloop][fix] Fix timeloop when time is negative and/or endtime is zero

See merge request !3617
parents a48bde94 e790d743
No related branches found
No related tags found
1 merge request!3617[timeloop][fix] Fix timeloop when time is negative and/or endtime is zero
Pipeline #34177 passed
Pipeline: dumux

#34185

    Pipeline: dumux

    #34184

      Pipeline: dumux-lecture

      #34183

        +5
        ...@@ -16,6 +16,7 @@ Differences Between DuMu<sup>x</sup> 3.8 and DuMu<sup>x</sup> 3.7 ...@@ -16,6 +16,7 @@ Differences Between DuMu<sup>x</sup> 3.8 and DuMu<sup>x</sup> 3.7
        - __Input file__: A string expression parser was added (implementation based on the ExprTK library which is shipped with DuMux). Using the new class `FunctionFromStringExpression<numArgs, ArgType>` functions based on string expression can parsed and evaluated. The most prominent use case is parsing functions - __Input file__: A string expression parser was added (implementation based on the ExprTK library which is shipped with DuMux). Using the new class `FunctionFromStringExpression<numArgs, ArgType>` functions based on string expression can parsed and evaluated. The most prominent use case is parsing functions
        from the parameter input file. The constructor takes the expression and an array of variable names to be replaced by function arguments. The function can then from the parameter input file. The constructor takes the expression and an array of variable names to be replaced by function arguments. The function can then
        be evaluated with the function values provided in the same order as the names where specified. An arbitrary number of arguments is supported. ExprTK support very complex expressions, see https://www.partow.net/programming/exprtk/. be evaluated with the function values provided in the same order as the names where specified. An arbitrary number of arguments is supported. ExprTK support very complex expressions, see https://www.partow.net/programming/exprtk/.
        - __Time loop__: Fixed a bug when the time is chosen to be negative and/or the end time is set to zero. (Before we assume time is always positive and endtime never zero.)
        ### Immediate interface changes not allowing/requiring a deprecation period: ### Immediate interface changes not allowing/requiring a deprecation period:
        ......
        ...@@ -145,6 +145,7 @@ public: ...@@ -145,6 +145,7 @@ public:
        verbose && verbose &&
        Dune::MPIHelper::getCommunication().rank() == 0; Dune::MPIHelper::getCommunication().rank() == 0;
        startTime_ = startTime;
        time_ = startTime; time_ = startTime;
        endTime_ = tEnd; endTime_ = tEnd;
        ...@@ -244,7 +245,7 @@ public: ...@@ -244,7 +245,7 @@ public:
        { {
        using std::min; using std::min;
        timeStepSize_ = min(dt, maxTimeStepSize()); timeStepSize_ = min(dt, maxTimeStepSize());
        if (!finished() && Dune::FloatCmp::le(timeStepSize_, 0.0, 1e-14*endTime_)) if (!finished() && Dune::FloatCmp::le(timeStepSize_, 0.0, 1e-14*(endTime_ - startTime_)))
        std::cerr << Fmt::format("You have set a very small timestep size (dt = {:.5g}).", timeStepSize_) std::cerr << Fmt::format("You have set a very small timestep size (dt = {:.5g}).", timeStepSize_)
        << " This might lead to numerical problems!\n"; << " This might lead to numerical problems!\n";
        } }
        ...@@ -300,7 +301,7 @@ public: ...@@ -300,7 +301,7 @@ public:
        */ */
        bool finished() const override bool finished() const override
        { {
        return finished_ || endTime_-time_ < 1e-10*time_; return finished_ || (endTime_ - time_) < 1e-10*(time_ - startTime_);
        } }
        /*! /*!
        ...@@ -309,7 +310,7 @@ public: ...@@ -309,7 +310,7 @@ public:
        */ */
        bool willBeFinished() const bool willBeFinished() const
        { {
        return finished() || endTime_-time_-timeStepSize_ < 1e-10*timeStepSize_; return finished() || (endTime_ - time_ - timeStepSize_) < 1e-10*timeStepSize_;
        } }
        /*! /*!
        ...@@ -336,7 +337,7 @@ public: ...@@ -336,7 +337,7 @@ public:
        { {
        const auto cpuTime = wallClockTime(); const auto cpuTime = wallClockTime();
        using std::round; using std::round;
        const auto percent = round( time_ / endTime_ * 100 ); const auto percent = round( (time_ - startTime_) / (endTime_ - startTime_) * 100 );
        std::cout << Fmt::format("[{:3.0f}%] ", percent) std::cout << Fmt::format("[{:3.0f}%] ", percent)
        << Fmt::format("Time step {} done in {:.2g} seconds. ", timeStepIdx_, timeStepWallClockTime_) << Fmt::format("Time step {} done in {:.2g} seconds. ", timeStepIdx_, timeStepWallClockTime_)
        << Fmt::format("Wall clock time: {:.5g}, time: {:.5g}, time step size: {:.5g}\n", cpuTime, time_, previousTimeStepSize_); << Fmt::format("Wall clock time: {:.5g}, time: {:.5g}, time step size: {:.5g}\n", cpuTime, time_, previousTimeStepSize_);
        ...@@ -377,6 +378,7 @@ protected: ...@@ -377,6 +378,7 @@ protected:
        Dune::Timer timer_; Dune::Timer timer_;
        Scalar time_; Scalar time_;
        Scalar endTime_; Scalar endTime_;
        Scalar startTime_;
        Scalar timeStepSize_; Scalar timeStepSize_;
        Scalar previousTimeStepSize_; Scalar previousTimeStepSize_;
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment