void mirror_celldata(std::string keyword, Opm::DeckConstPtr deck, std::string direction, std::ofstream& out) { if ( ! deck->hasKeyword(keyword)) { std::cout << "Ignoring keyword " << keyword << " as it was not found." << std::endl; return; } // Get data from eclipse deck Opm::DeckRecordConstPtr specgridRecord = deck->getKeyword("SPECGRID")->getRecord(0); std::vector<int> dimensions(3); dimensions[0] = specgridRecord->getItem("NX")->getInt(0); dimensions[1] = specgridRecord->getItem("NY")->getInt(0); dimensions[2] = specgridRecord->getItem("NZ")->getInt(0); std::vector<T> values = getKeywordValues(keyword, deck, T(0.0)); std::vector<T> values_mirrored(2*dimensions[0]*dimensions[1]*dimensions[2], 0.0); // Handle the two directions differently due to ordering of the pillars. if (direction == "x") { typename std::vector<T>::iterator it_orig = values.begin(); typename std::vector<T>::iterator it_new = values_mirrored.begin(); // Loop through each line and copy old cell data and add new (which are the old reversed) for ( ; it_orig != values.end(); it_orig += dimensions[0]) { // Copy old cell data copy(it_orig, it_orig + dimensions[0], it_new); it_new += dimensions[0]; // Add new cell data std::vector<double> next_vec(it_orig, it_orig + dimensions[0]); std::vector<double> next_reversed = next_vec; reverse(next_reversed.begin(), next_reversed.end()); copy(next_reversed.begin(), next_reversed.end(), it_new); it_new += dimensions[0]; } } else if (direction =="y") { typename std::vector<T>::iterator it_orig = values.begin(); typename std::vector<T>::iterator it_new = values_mirrored.begin(); // Entries per layer const int entries_per_layer = dimensions[0]*dimensions[1]; // Loop through each layer and copy old cell data and add new (which are the old reordered) for ( ; it_orig != values.end(); it_orig += entries_per_layer) { // Copy old cell data copy(it_orig, it_orig + entries_per_layer, it_new); it_new += entries_per_layer; // Add new cell data std::vector<T> next_vec(it_orig, it_orig + entries_per_layer); std::vector<T> next_reordered(entries_per_layer, 0.0); typename std::vector<T>::iterator it_next = next_vec.end(); typename std::vector<T>::iterator it_reordered = next_reordered.begin(); // Reorder next entries for ( ; it_reordered != next_reordered.end(); it_reordered += dimensions[0]) { copy(it_next - dimensions[0], it_next, it_reordered); it_next -= dimensions[0]; } copy(next_reordered.begin(), next_reordered.end(), it_new); it_new += entries_per_layer; } } else { std::cerr << "Direction should be either x or y" << std::endl; exit(1); } // Write new keyword values to output file printKeywordValues(out, keyword, values_mirrored, 8); }
/// Mirror keyword ZCORN in deck void mirror_zcorn(Opm::DeckConstPtr deck, std::string direction, std::ofstream& out) { Opm::DeckRecordConstPtr specgridRecord = deck->getKeyword("SPECGRID")->getRecord(0); std::vector<int> dimensions(3); dimensions[0] = specgridRecord->getItem("NX")->getInt(0); dimensions[1] = specgridRecord->getItem("NY")->getInt(0); dimensions[2] = specgridRecord->getItem("NZ")->getInt(0); std::vector<double> zcorn = deck->getKeyword("ZCORN")->getRawDoubleData(); std::vector<double> zcorn_mirrored; // Handle the two directions differently due to ordering of the pillars. if (direction == "x") { // Total entries in mirrored ZCORN. Eight corners per cell. const int entries = dimensions[0]*2*dimensions[1]*dimensions[2]*8; zcorn_mirrored.assign(entries, 0.0); // Entries per line in x-direction. Two for each cell. const int entries_per_line = dimensions[0]*2; std::vector<double>::iterator it_new = zcorn_mirrored.begin(); std::vector<double>::iterator it_orig = zcorn.begin(); // Loop through each line and copy old corner-points and add new (which are the old reversed) for ( ; it_orig != zcorn.end(); it_orig += entries_per_line) { std::vector<double> next_vec(it_orig, it_orig + entries_per_line); std::vector<double> next_reversed = next_vec; reverse(next_reversed.begin(), next_reversed.end()); // Copy old corner-points copy(it_orig, it_orig + entries_per_line, it_new); it_new += entries_per_line; // Add new corner-points copy(next_reversed.begin(), next_reversed.end(), it_new); it_new += entries_per_line; } } else if (direction == "y") { // Total entries in mirrored ZCORN. Eight corners per cell. const int entries = dimensions[0]*dimensions[1]*2*dimensions[2]*8; zcorn_mirrored.assign(entries, 0.0); // Entries per line in x-direction. Two for each cell. const int entries_per_line_x = dimensions[0]*2; // Entries per layer of corner-points. Four for each cell const int entries_per_layer = dimensions[0]*dimensions[1]*4; std::vector<double>::iterator it_new = zcorn_mirrored.begin(); std::vector<double>::iterator it_orig = zcorn.begin(); // Loop through each layer and copy old corner-points and add new (which are the old reordered) for ( ; it_orig != zcorn.end(); it_orig += entries_per_layer) { // Copy old corner-points copy(it_orig, it_orig + entries_per_layer, it_new); it_new += entries_per_layer; // Add new corner-points std::vector<double> next_vec(it_orig, it_orig + entries_per_layer); std::vector<double> next_reordered(entries_per_layer, 0.0); std::vector<double>::iterator it_next = next_vec.end(); std::vector<double>::iterator it_reordered = next_reordered.begin(); // Reorder next entries for ( ; it_reordered != next_reordered.end(); it_reordered += entries_per_line_x) { copy(it_next - entries_per_line_x, it_next, it_reordered); it_next -= entries_per_line_x; } copy(next_reordered.begin(), next_reordered.end(), it_new); it_new += entries_per_layer; } } else { std::cerr << "Direction should be either x or y" << std::endl; exit(1); } // Write new ZCORN values to output file printKeywordValues(out, "ZCORN", zcorn_mirrored, 8); }
void eos::TextEditor::OnPaint() { ax::GC gc; ax::Rect rect(GetDrawingRect()); gc.SetColor(_info.bg_color); gc.DrawRectangle(ax::Rect(0, 0, rect.size.x, rect.size.y)); // Draw line number background. gc.SetColor(_info.line_number_bg_color); gc.DrawRectangle(ax::Rect(0, 0, 25, rect.size.y)); ax::Point num_pos(4, 2); gc.SetColor(_info.line_number_color); // Draw line number. for(int i = 0; i < _n_line_shown; i++) { int num = i + _file_start_index; std::string num_str = std::to_string(num); if(num < 10) { num_str = " " + num_str; } else if(num < 100) { num_str = " " + num_str; } gc.DrawString(_line_num_font, num_str, num_pos); num_pos += ax::Point(0, 15); } // Text initial position. //ax::Point line_pos(4, 0); ax::Point line_pos(25 + 4, 0); _next_pos_data.clear(); const ax::StringVector& data = _logic.GetFileData(); // Set text color. gc.SetColor(_info.text_color); // Draw text. for(int i = 0, k = _file_start_index; k < data.size() && i < _n_line_shown; i++, k++) { const std::string& text = data[k]; std::vector<int> next_vec(text.size() + 1); // Draw string. if(_font) { int x = line_pos.x; next_vec[0] = x; // //---------------------------------------- // ax::StringVector words = ax::Utils::String::Split(text, " "); // // int index = 0; // // for(auto& w : words) // { // std::string clean_word = RemoveSpecialChar(w); // // ax::Color word_color = _info.text_color; // // if(_key_words_cpp.find(clean_word) != _key_words_cpp.end()) // { // word_color = ax::Color(0.6627451, 0.05098039, 0.5686275); // } // // for (int i = 0; i < w.size(); i++) // { // gc.SetColor(word_color); // // if(text[index] == ' ') // { // i--; // _font.SetChar(' '); // } // else // { // _font.SetChar(w[i]); // // if(is_special(w[i])) // { // gc.SetColor(_info.text_color); // } // else if(std::isdigit(w[i])) // { // gc.SetColor(ax::Color(0.0, 0.0, 1.0)); // } // } // // ax::Point d = _font.GetDelta(); // // ax::Point txtPos(x + d.x, // line_pos.y - d.y + _font.GetFontSize()); // // ax::Rect txtRect(txtPos, _font.GetSize()); // gc.DrawTexture(_font.GetTexture(), txtRect); // // x += _font.GetNextPosition(); // // next_vec[index + 1] = x; // // index++; // // } // } // // _font.SetChar(' '); // ax::Point d = _font.GetDelta(); // // while(index < text.size()) // { // ax::Point txtPos(x + d.x, // line_pos.y - d.y + _font.GetFontSize()); // ax::Rect txtRect(txtPos, _font.GetSize()); // gc.DrawTexture(_font.GetTexture(), txtRect); // x += _font.GetNextPosition(); // next_vec[index + 1] = x; // index++; // } //------------------------ for (int i = 0; i < text.size(); i++) { _font.SetChar(text[i]); ax::Point d = _font.GetDelta(); ax::Point txtPos(x + d.x, line_pos.y - d.y + _font.GetFontSize()); ax::Rect txtRect(txtPos, _font.GetSize()); gc.DrawTexture(_font.GetTexture(), txtRect); x += _font.GetNextPosition(); next_vec[i + 1] = x; } } _next_pos_data.push_back(next_vec); line_pos += ax::Point(0, 15); } // Line cursor. ax::Point cursor_index = FileCursorPosToNextPosIndex(); if(cursor_index.x != -1 && cursor_index.y != -1) { ax::Print("Draw cursor"); int x = _next_pos_data[cursor_index.y][cursor_index.x]; int y = cursor_index.y * _line_height; // gc.SetColor(_info.cursor_color); gc.SetColor(ax::Color(1.0, 0.0, 0.0)); gc.DrawLine(ax::Point(x, y), ax::Point(x, y + _line_height)); } }
/// Mirror keyword COORD in deck void mirror_coord(Opm::DeckConstPtr deck, std::string direction, std::ofstream& out) { // We assume uniform spacing in x and y directions and parallel top and bottom faces Opm::DeckRecordConstPtr specgridRecord = deck->getKeyword("SPECGRID")->getRecord(0); std::vector<int> dimensions(3); dimensions[0] = specgridRecord->getItem("NX")->getInt(0); dimensions[1] = specgridRecord->getItem("NY")->getInt(0); dimensions[2] = specgridRecord->getItem("NZ")->getInt(0); std::vector<double> coord = deck->getKeyword("COORD")->getRawDoubleData(); const int entries_per_pillar = 6; std::vector<double> coord_mirrored; // Handle the two directions differently due to ordering of the pillars. if (direction == "x") { // Total entries in mirrored ZCORN. Number of pillars times 6 const int entries = (2*dimensions[0] + 1) * (dimensions[1] + 1) * entries_per_pillar; // Entries per line in x-direction. Number of pillars in x-direction times 6 const int entries_per_line = entries_per_pillar*(dimensions[0] + 1); coord_mirrored.assign(entries, 0.0); // Distance between pillars in x-directiion const double spacing = coord[entries_per_pillar]-coord[0]; std::vector<double>::iterator it_new = coord_mirrored.begin(); std::vector<double>::iterator it_orig; // Loop through each pillar line in the x-direction for (it_orig = coord.begin(); it_orig != coord.end(); it_orig += entries_per_line) { // Copy old pillars copy(it_orig, it_orig + entries_per_line, it_new); // Add new pillars in between it_new += entries_per_line; std::vector<double> next_vec(it_orig + entries_per_line - entries_per_pillar, it_orig + entries_per_line); for (int r=0; r < dimensions[0]; ++r) { next_vec[0] += spacing; next_vec[3] += spacing; copy(next_vec.begin(), next_vec.end(), it_new); it_new += entries_per_pillar; } } } else if (direction == "y") { // Total entries in mirrored ZCORN. Number of pillars times 6 const int entries = (dimensions[0] + 1) * (2*dimensions[1] + 1) * entries_per_pillar; // Entries per line in y-direction. Number of pillars in y-direction times 6 const int entries_per_line = entries_per_pillar*(dimensions[0] + 1); coord_mirrored.assign(entries, 0.0); // Distance between pillars in y-directiion const double spacing = coord[entries_per_line + 1]-coord[1]; std::vector<double>::iterator it_new = coord_mirrored.begin(); // Copy old pillars copy(coord.begin(), coord.end(), it_new); // Add new pillars at the end it_new += coord.size(); std::vector<double> next_vec(coord.end() - entries_per_line, coord.end()); for ( ; it_new != coord_mirrored.end(); it_new += entries_per_line) { for (int i = 1; i < entries_per_line; i += 3) { next_vec[i] += spacing; } copy(next_vec.begin(), next_vec.end(), it_new); } } else { std::cerr << "Direction should be either x or y" << std::endl; exit(1); } // Write new COORD values to output file printKeywordValues(out, "COORD", coord_mirrored, 6); }
fit_tuple_t find_next( const fit_tuple_t ¤t, const fit_tuple_t &grad, const fit_tuple_t &lapl ) { return boost::make_tuple( next_vec( current.get<0>(), grad.get<0>(), lapl.get<0>() ), next_vec( current.get<1>(), grad.get<1>(), lapl.get<1>() ) ); }