welloperations.hpp
Go to the documentation of this file.
1// $Id: welloperations.hpp 883 2011-09-26 09:17:05Z perroe $
2
3// Copyright (c) 2011, Norwegian Computing Center
4// All rights reserved.
5// Redistribution and use in source and binary forms, with or without modification,
6// are permitted provided that the following conditions are met:
7// • Redistributions of source code must retain the above copyright notice, this
8// list of conditions and the following disclaimer.
9// • Redistributions in binary form must reproduce the above copyright notice, this list of
10// conditions and the following disclaimer in the documentation and/or other materials
11// provided with the distribution.
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
13// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
14// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
15// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
16// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
17// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
19// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
20// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
22#ifndef NRLIB_WELLOPERATIONS_HPP
23#define NRLIB_WELLOPERATIONS_HPP
24
25#include <string>
26#include <iomanip>
27#include <vector>
28#include <sstream>
29
30#include "../exception/exception.hpp"
31#include "well.hpp"
32#include "rmswell.hpp"
33#include "../stormgrid/stormcontgrid.hpp"
34#include "../stormgrid/stormfaciesgrid.hpp"
35
36namespace NRLib {
39 template <typename A>
40 void BlockWell(const NRLib::Well & well,
41 const A & grid,
42 NRLib::Well & blocked_well);
43}
44
45
46template <typename A>
47void NRLib::BlockWell(const NRLib::Well & well,
48 const A & grid,
49 NRLib::Well & blocked_well)
50{
51 size_t i;
52 size_t loglength = well.GetContLogLength("x");
53 std::vector<size_t> index(loglength);
54 double x, y, z;
55
56 for (i = 0; i < loglength; i++) {
57 x = well.GetContValue(i, "x");
58 y = well.GetContValue(i, "y");
59 z = well.GetContValue(i, "z");
60 index[i] = grid.FindIndex(x, y, z);
61 }
62
63 std::vector<size_t> indexvalues;
64 indexvalues.push_back(index[0]);
65 bool found = false;
66 size_t k;
67 for (i = 0; i < loglength; i++) {
68 for (k = 0; k < indexvalues.size(); k++)
69 if (index[i] == indexvalues[k])
70 found = true;
71 if (found == false)
72 indexvalues.push_back(index[i]);
73 found = false;
74 }
75
76 size_t novalues = indexvalues.size();
77 std::vector<int> no(novalues);
78
79 for (i = 0; i < novalues; i++) {
80 no[i] = 0;
81 for (k = 0; k < loglength; k++) {
82 if (index[k] == indexvalues[i])
83 no[i]++;
84 }
85 }
86 size_t ncont = well.GetNContLog();
87 size_t ndisc = well.GetNlog() - ncont;
88 std::vector<std::vector<int> > disclogs(ndisc, std::vector<int>(novalues));
89 std::vector<std::vector<int> > nodisc(ndisc, std::vector<int>(novalues));
90 std::vector<std::vector<int> > nocont(ncont, std::vector<int>(novalues));
91 std::vector<std::vector<double> > contlogs(ncont, std::vector<double>(novalues));
92 for (k = 0; k < novalues; k++) {
93 for (i = 0; i < ncont; i++) {
94 contlogs[i][k] = 0.0;
95 nocont[i][k] = 0;
96 }
97 for (i = 0; i < ndisc; i++) {
98 disclogs[i][k] = 0;
99 nodisc[i][k] = 0;
100 }
101 }
102 std::vector<std::string> discnames(ndisc);
103 std::vector<std::string> contnames(ncont);
104 typedef std::map<std::string, std::vector<int> >::const_iterator CI;
105 const std::map<std::string,std::vector<int> >& disclog = well.GetDiscLog();
106 i = 0;
107 for (CI p = disclog.begin(); p != disclog.end(); ++p) {
108 discnames[i] = p->first;
109 i++;
110 }
111 i = 0;
112 typedef std::map<std::string, std::vector<double> >::const_iterator CID;
113 const std::map<std::string,std::vector<double> >& contlog = well.GetContLog();
114 for (CID p = contlog.begin(); p != contlog.end(); ++p) {
115 contnames[i] = p->first;
116 i++;
117 }
118 size_t j;
119 double valuec;
120 int valuei;
121 for (i = 0; i < loglength; i++) {
122 for (k = 0; k < novalues; k++) {
123 if (index[i] == indexvalues[k]) {
124 for (j = 0; j < ncont; j++) {
125 valuec = well.GetContValue(i, contnames[j]);
126 if (!well.IsMissing(valuec)) {
127 contlogs[j][k] += valuec;
128 nocont[j][k]++;
129 }
130 }
131 for (j = 0; j < ndisc; j++) {
132 valuei = well.GetDiscValue(i, discnames[j]);
133 if (!well.IsMissing(valuei)) {
134 disclogs[j][k] += valuei;
135 nodisc[j][k]++;
136 }
137 }
138 }
139 }
140 }
141 for (k = 0; k < novalues; k++) {
142 for (j = 0; j < ncont; j++) {
143 if (nocont[j][k] == 0)
144 contlogs[j][k] = well.GetContMissing();
145 else
146 contlogs[j][k] /= nocont[j][k];
147 }
148 for (j = 0; j < ndisc; j++) {
149 if (nodisc[j][k] == 0)
150 disclogs[j][k] = well.GetIntMissing();
151 else
152 disclogs[j][k] /= nodisc[j][k];
153 }
154 }
155
156 std::map<std::string,std::vector<double> > contlognew;
157 for (i = 0; i < ncont; i++) {
158 contlognew[contnames[i]] = contlogs[i];
159 }
160 std::map<std::string, std::vector<int> > disclognew;
161 for (i = 0; i < ndisc; i++) {
162 disclognew[discnames[i]] = disclogs[i];
163 }
164 std::string well_name = well.GetWellName() + "blocked";
165 blocked_well = Well(contlognew, disclognew, well_name);
166}
167
168#endif
int index
Definition: cJSON.h:168
const char *const string
Definition: cJSON.h:170
Definition: NRLib/nrlib/well/well.hpp:30
Definition: exception.hpp:31
void BlockWell(const NRLib::Well &well, const A &grid, NRLib::Well &blocked_well)
Definition: welloperations.hpp:47
x y * z
Definition: exprtk.hpp:9663
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)