TimeStepControl.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2014 IRIS AS
3  Copyright 2015 Dr. Blatt - HPC-Simulation-Software & Services
4  Copyright 2015 Statoil AS
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #ifndef OPM_TIMESTEPCONTROL_HEADER_INCLUDED
22 #define OPM_TIMESTEPCONTROL_HEADER_INCLUDED
23 
24 #include <vector>
25 
26 #include <boost/any.hpp>
27 #include <boost/range/iterator_range.hpp>
30 
31 namespace Opm
32 {
36  //
39  {
40  public:
43  // \param decayrate decayrate of time step when target iterations are not met (should be <= 1)
44  // \param growthrate growthrate of time step when target iterations are not met (should be >= 1)
46  SimpleIterationCountTimeStepControl( const int target_iterations,
47  const double decayrate,
48  const double growthrate,
49  const bool verbose = false);
50 
52  double computeTimeStepSize( const double dt, const int iterations, const SimulatorState& state ) const;
53 
54  protected:
55  const int target_iterations_;
56  const double decayrate_;
57  const double growthrate_;
58  const bool verbose_;
59  };
60 
76  {
77  public:
84  PIDTimeStepControl( const double tol = 1e-3,
85  const boost::any& pinfo = boost::any(),
86  const bool verbose = false );
87 
89  void initialize( const SimulatorState& state );
90 
92  double computeTimeStepSize( const double dt, const int /* iterations */, const SimulatorState& state ) const;
93 
94  protected:
95  template <class Iterator>
96  double euclidianNormSquared( Iterator it, const Iterator end, int num_components = 1 ) const
97  {
98  static_cast<void>(num_components); // Suppress warning in the serial case.
99 #if HAVE_MPI
100  if ( parallel_information_.type() == typeid(ParallelISTLInformation) )
101  {
102  const ParallelISTLInformation& info =
103  boost::any_cast<const ParallelISTLInformation&>(parallel_information_);
104  int size_per_component = (end - it) / num_components;
105  assert((end - it) == num_components * size_per_component);
106  double component_product = 0.0;
107  for( int i = 0; i < num_components; ++i )
108  {
109  auto component_container =
110  boost::make_iterator_range(it + i * size_per_component,
111  it + (i + 1) * size_per_component);
112  info.computeReduction(component_container,
113  Opm::Reduction::makeInnerProductFunctor<double>(),
114  component_product);
115  }
116  return component_product;
117  }
118  else
119 #endif
120  {
121  double product = 0.0 ;
122  for( ; it != end; ++it ) {
123  product += ( *it * *it );
124  }
125  return product;
126  }
127  }
128 
129  protected:
130  mutable std::vector<double> p0_;
131  mutable std::vector<double> sat0_;
132 
133  const double tol_;
134  mutable std::vector< double > errors_;
135 
136  const bool verbose_;
137  private:
138  const boost::any parallel_information_;
139  };
140 
145  //
148  {
150  public:
155  // \param maxgrowth max growth factor for new time step in relation of old time step (default = 3.0)
159  PIDAndIterationCountTimeStepControl( const int target_iterations = 20,
160  const double tol = 1e-3,
161  const boost::any& = boost::any(),
162  const bool verbose = false);
163 
165  double computeTimeStepSize( const double dt, const int iterations, const SimulatorState& state ) const;
166 
167  protected:
169  };
170 
171 
172 } // end namespace Opm
173 #endif
174 
Definition: TimeStepControl.hpp:75
Definition: AnisotropicEikonal.hpp:43
void initialize(const SimulatorState &state)
const bool verbose_
Definition: TimeStepControl.hpp:136
const double growthrate_
Definition: TimeStepControl.hpp:57
double computeTimeStepSize(const double dt, const int, const SimulatorState &state) const
const double decayrate_
Definition: TimeStepControl.hpp:56
double euclidianNormSquared(Iterator it, const Iterator end, int num_components=1) const
Definition: TimeStepControl.hpp:96
double computeTimeStepSize(const double dt, const int iterations, const SimulatorState &state) const
Definition: SimulatorState.hpp:16
Definition: TimeStepControlInterface.hpp:32
const double tol_
Definition: TimeStepControl.hpp:133
PIDAndIterationCountTimeStepControl(const int target_iterations=20, const double tol=1e-3, const boost::any &=boost::any(), const bool verbose=false)
constructor
const bool verbose_
Definition: TimeStepControl.hpp:58
const int target_iterations_
Definition: TimeStepControl.hpp:55
double computeTimeStepSize(const double dt, const int iterations, const SimulatorState &state) const
SimpleIterationCountTimeStepControl(const int target_iterations, const double decayrate, const double growthrate, const bool verbose=false)
constructor
std::vector< double > errors_
Definition: TimeStepControl.hpp:134
Definition: TimeStepControl.hpp:147
const int target_iterations_
Definition: TimeStepControl.hpp:168
Definition: TimeStepControl.hpp:38
PIDTimeStepControl(const double tol=1e-3, const boost::any &pinfo=boost::any(), const bool verbose=false)
constructor
std::vector< double > p0_
Definition: TimeStepControl.hpp:130
std::vector< double > sat0_
Definition: TimeStepControl.hpp:131