WellSwitchingLogger.hpp
1 /*
2  Copyright 2016 Dr. Blatt - HPC-Simulation-Software & Services
3  Copyright 2016 Statoil AS
4 
5  This file is part of the Open Porous Media project (OPM).
6 
7  OPM is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  OPM is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with OPM. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef OPM_WELLSWITCHINGLOGGER_HEADER_INCLUDED
22 #define OPM_WELLSWITCHINGLOGGER_HEADER_INCLUDED
23 
24 #include <array>
25 #include <map>
26 #include <string>
27 #include <vector>
28 
29 #include <dune/common/parallel/mpihelper.hh>
30 
31 #include <opm/common/OpmLog/OpmLog.hpp>
32 
33 #include <opm/core/well_controls.h>
34 
35 namespace Opm
36 {
37 namespace wellhelpers
38 {
39 
45 {
46  typedef std::map<std::string, std::array<char,2> > SwitchMap;
47 
48 public:
50  typedef Dune::CollectiveCommunication<typename Dune::MPIHelper::MPICommunicator>
52 
56  explicit WellSwitchingLogger(const Communication& cc =
57  Dune::MPIHelper::getCollectiveCommunication())
58  : cc_(cc)
59  {}
60 
65  void wellSwitched(std::string name,
66  WellControlType from,
67  WellControlType to)
68  {
69  if( cc_.size() > 1 )
70  {
71  using Pair = typename SwitchMap::value_type;
72  switchMap_.insert(Pair(name, {char(from), char(to)}));
73  }
74  else
75  {
76  std::ostringstream ss;
77  ss << " Switching control mode for well " << name
78  << " from " << modestring[from]
79  << " to " << modestring[to];
80  OpmLog::info(ss.str());
81  }
82  }
83 
86 
87 private:
88 
89 #if HAVE_MPI
90  void unpackDataAndLog(std::vector<char>& recv_buffer,
91  const std::vector<int>& displ);
92 
93  void packData(std::vector<int>& well_name_length,
94  std::vector<char>& buffer);
95 
96  int calculateMessageSize(std::vector<int>& well_name_length);
97 
98  void logSwitch(const char* name, std::array<char,2> fromto,
99  int rank);
100 
101 #endif // HAVE_MPI
102 
103  void gatherDataAndLog();
104 
106  SwitchMap switchMap_;
108  Communication cc_;
110  const std::string modestring[4] = { "BHP", "THP", "RESERVOIR_RATE", "SURFACE_RATE" };
111 };
112 } // end namespace wellhelpers
113 } // end namespace Opm
114 #endif
void wellSwitched(std::string name, WellControlType from, WellControlType to)
Log that a well switched.
Definition: WellSwitchingLogger.hpp:65
Utility class to handle the log messages about well switching.
Definition: WellSwitchingLogger.hpp:44
~WellSwitchingLogger()
Destructor send does the actual logging.
Definition: WellSwitchingLogger.cpp:200
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: AdditionalObjectDeleter.hpp:22
Dune::CollectiveCommunication< typename Dune::MPIHelper::MPICommunicator > Communication
The type of the collective communication used.
Definition: WellSwitchingLogger.hpp:51
WellSwitchingLogger(const Communication &cc=Dune::MPIHelper::getCollectiveCommunication())
Constructor.
Definition: WellSwitchingLogger.hpp:56