00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef OPM_WELLSWITCHINGLOGGER_HEADER_INCLUDED
00022 #define OPM_WELLSWITCHINGLOGGER_HEADER_INCLUDED
00023
00024 #include <array>
00025 #include <map>
00026 #include <string>
00027 #include <vector>
00028
00029 #include <dune/common/parallel/mpihelper.hh>
00030
00031 #include <opm/common/OpmLog/OpmLog.hpp>
00032
00033 #include <opm/core/well_controls.h>
00034
00035 namespace Opm
00036 {
00037 namespace wellhelpers
00038 {
00039
00044 class WellSwitchingLogger
00045 {
00046 typedef std::map<std::string, std::array<char,2> > SwitchMap;
00047
00048 public:
00050 typedef Dune::CollectiveCommunication<typename Dune::MPIHelper::MPICommunicator>
00051 Communication;
00052
00056 explicit WellSwitchingLogger(const Communication& cc =
00057 Dune::MPIHelper::getCollectiveCommunication())
00058 : cc_(cc)
00059 {}
00060
00065 void wellSwitched(std::string name,
00066 WellControlType from,
00067 WellControlType to)
00068 {
00069 if( cc_.size() > 1 )
00070 {
00071 using Pair = typename SwitchMap::value_type;
00072 switchMap_.insert(Pair(name, {char(from), char(to)}));
00073 }
00074 else
00075 {
00076 std::ostringstream ss;
00077 ss << " Switching control mode for well " << name
00078 << " from " << modestring[from]
00079 << " to " << modestring[to];
00080 OpmLog::info(ss.str());
00081 }
00082 }
00083
00085 ~WellSwitchingLogger();
00086
00087 private:
00088
00089 #if HAVE_MPI
00090 void unpackDataAndLog(std::vector<char>& recv_buffer,
00091 const std::vector<int>& displ);
00092
00093 void packData(std::vector<int>& well_name_length,
00094 std::vector<char>& buffer);
00095
00096 int calculateMessageSize(std::vector<int>& well_name_length);
00097
00098 void logSwitch(const char* name, std::array<char,2> fromto,
00099 int rank);
00100
00101 #endif // HAVE_MPI
00102
00103 void gatherDataAndLog();
00104
00106 SwitchMap switchMap_;
00108 Communication cc_;
00110 const std::string modestring[4] = { "BHP", "THP", "RESERVOIR_RATE", "SURFACE_RATE" };
00111 };
00112 }
00113 }
00114 #endif