From 797e9df01dfc7a352f80c3ffc8f1f48d0b2d94cf Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 07:30:00 +0100 Subject: [PATCH 01/51] Moved mock model identicators to RimDefines --- ApplicationCode/Application/RiaApplication.cpp | 6 +++--- ApplicationCode/ProjectDataModel/RimDefines.h | 9 +++++++++ ApplicationCode/ProjectDataModel/RimResultCase.cpp | 6 +++--- ApplicationCode/UserInterface/RiuMainWindow.cpp | 6 +++--- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index 15d74e3665..456443e89a 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -637,7 +637,7 @@ bool RiaApplication::openInputEclipseCaseFromFileNames(const QStringList& fileNa //-------------------------------------------------------------------------------------------------- void RiaApplication::createMockModel() { - openEclipseCase("Result Mock Debug Model Simple", "Result Mock Debug Model Simple"); + openEclipseCase(RimDefines::mockModelBasic(), RimDefines::mockModelBasic()); } //-------------------------------------------------------------------------------------------------- @@ -645,7 +645,7 @@ void RiaApplication::createMockModel() //-------------------------------------------------------------------------------------------------- void RiaApplication::createResultsMockModel() { - openEclipseCase("Result Mock Debug Model With Results", "Result Mock Debug Model With Results"); + openEclipseCase(RimDefines::mockModelBasicWithResults(), RimDefines::mockModelBasicWithResults()); } @@ -654,7 +654,7 @@ void RiaApplication::createResultsMockModel() //-------------------------------------------------------------------------------------------------- void RiaApplication::createLargeResultsMockModel() { - openEclipseCase("Result Mock Debug Model Large With Results", "Result Mock Debug Model Large With Results"); + openEclipseCase(RimDefines::mockModelLargeWithResults(), RimDefines::mockModelLargeWithResults()); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimDefines.h b/ApplicationCode/ProjectDataModel/RimDefines.h index 62e33fa8c3..d39cb86dcb 100644 --- a/ApplicationCode/ProjectDataModel/RimDefines.h +++ b/ApplicationCode/ProjectDataModel/RimDefines.h @@ -40,5 +40,14 @@ public: }; static QString undefinedResultName() { return "None"; } + + + // Mock model text identifiers + static QString mockModelBasic() { return "Result Mock Debug Model Simple"; } + static QString mockModelBasicWithResults() { return "Result Mock Debug Model With Results"; } + static QString mockModelLargeWithResults() { return "Result Mock Debug Model Large With Results"; } + static QString mockModelBasicInputCase() { return "Input Mock Debug Model Simple"; } + + }; diff --git a/ApplicationCode/ProjectDataModel/RimResultCase.cpp b/ApplicationCode/ProjectDataModel/RimResultCase.cpp index b4098e4408..7118479742 100644 --- a/ApplicationCode/ProjectDataModel/RimResultCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimResultCase.cpp @@ -192,7 +192,7 @@ cvf::ref RimResultCase::createMockModel(QString modelName) cvf::ref mockFileInterface = new RifReaderMockModel; cvf::ref reservoir = new RigCaseData; - if (modelName == "Result Mock Debug Model Simple") + if (modelName == RimDefines::mockModelBasic()) { // Create the mock file interface and and RigSerervoir and set them up. mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(20, 20, 20)); @@ -214,7 +214,7 @@ cvf::ref RimResultCase::createMockModel(QString modelName) //reservoir->mainGrid()->cell(idx).setActiveIndexInMatrixModel(cvf::UNDEFINED_SIZE_T); } } - else if (modelName == "Result Mock Debug Model With Results") + else if (modelName == RimDefines::mockModelBasicWithResults()) { mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(-20, -20, -20)); mockFileInterface->setGridPointDimensions(cvf::Vec3st(5, 10, 20)); @@ -227,7 +227,7 @@ cvf::ref RimResultCase::createMockModel(QString modelName) cvf::Vec3d& tmp = reservoir->mainGrid()->nodes()[1]; tmp += cvf::Vec3d(1, 0, 0); } - else if (modelName =="Result Mock Debug Model Large With Results") + else if (modelName == RimDefines::mockModelLargeWithResults()) { double startX = 0; double startY = 0; diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index 8013128714..9cf94b5d4f 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -1435,9 +1435,9 @@ void RiuMainWindow::slotOpenMultipleCases() if (1) { - gridFileNames += "Result Mock Debug Model With Results"; - gridFileNames += "Result Mock Debug Model With Results"; - gridFileNames += "Result Mock Debug Model With Results"; + gridFileNames += RimDefines::mockModelBasicWithResults(); + gridFileNames += RimDefines::mockModelBasicWithResults(); + gridFileNames += RimDefines::mockModelBasicWithResults(); } else { From 314512e4054c41c40f8be18c7668380089e771b6 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 10:30:11 +0100 Subject: [PATCH 02/51] Added serialization of pdm objects using QSettings --- Fwk/AppFwk/cafUserInterface/CMakeLists.txt | 2 + .../cafUserInterface/cafPdmSettings.cpp | 116 ++++++++++++++++++ Fwk/AppFwk/cafUserInterface/cafPdmSettings.h | 55 +++++++++ 3 files changed, 173 insertions(+) create mode 100644 Fwk/AppFwk/cafUserInterface/cafPdmSettings.cpp create mode 100644 Fwk/AppFwk/cafUserInterface/cafPdmSettings.h diff --git a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt index fdf3cde039..61b9318fb9 100644 --- a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt +++ b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt @@ -12,6 +12,7 @@ set( QOBJECT_HEADERS cafUiTreeModelPdm.h cafUiProcess.h + cafPdmSettings.h cafPdmUiLineEditor.h cafPdmUiCheckBoxEditor.h cafPdmUiComboBoxEditor.h @@ -38,6 +39,7 @@ endif() add_library( ${PROJECT_NAME} cafBasicAboutDialog.cpp cafBasicAboutDialog.h + cafPdmSettings.cpp cafPdmUiCheckBoxEditor.cpp cafPdmUiCheckBoxEditor.h cafPdmUiColorEditor.cpp diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmSettings.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmSettings.cpp new file mode 100644 index 0000000000..a8e3a3ba5c --- /dev/null +++ b/Fwk/AppFwk/cafUserInterface/cafPdmSettings.cpp @@ -0,0 +1,116 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2013 Ceetron AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + + +#include "cafPdmSettings.h" +#include "cafPdmField.h" + +#include + + +namespace caf +{ + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void Settings::readFieldsFromApplicationStore(caf::PdmObject* object) +{ + // Qt doc : + // + // Constructs a QSettings object for accessing settings of the application and organization + // set previously with a call to QCoreApplication::setOrganizationName(), + // QCoreApplication::setOrganizationDomain(), and QCoreApplication::setApplicationName(). + QSettings settings; + + QString prefix = object->classKeyword(); + if (!prefix.isEmpty()) + { + prefix += "/"; + } + + std::vector fields; + object->fields(fields); + size_t i; + for (i = 0; i < fields.size(); i++) + { + caf::PdmFieldHandle* fieldHandle = fields[i]; + + QString keywordWithPrefix = prefix + fieldHandle->keyword(); + if (settings.contains(keywordWithPrefix)) + { + QVariant val = settings.value(keywordWithPrefix); + fieldHandle->setValueFromUi(val); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void Settings::writeFieldsToApplicationStore(caf::PdmObject* object) +{ + assert(object); + + // Qt doc : + // + // Constructs a QSettings object for accessing settings of the application and organization + // set previously with a call to QCoreApplication::setOrganizationName(), + // QCoreApplication::setOrganizationDomain(), and QCoreApplication::setApplicationName(). + QSettings settings; + + QString prefix = object->classKeyword(); + if (!prefix.isEmpty()) + { + prefix += "/"; + } + + std::vector fields; + object->fields(fields); + + size_t i; + for (i = 0; i < fields.size(); i++) + { + caf::PdmFieldHandle* fieldHandle = fields[i]; + + QString keywordWithPrefix = prefix + fieldHandle->keyword(); + settings.setValue(keywordWithPrefix, fieldHandle->uiValue()); + } +} + + +} // namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmSettings.h b/Fwk/AppFwk/cafUserInterface/cafPdmSettings.h new file mode 100644 index 0000000000..2342eacd71 --- /dev/null +++ b/Fwk/AppFwk/cafUserInterface/cafPdmSettings.h @@ -0,0 +1,55 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2013 Ceetron AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + + +#pragma once + +#include + +namespace caf +{ + + class PdmObject; + +class Settings +{ +public: + static void readFieldsFromApplicationStore(caf::PdmObject* object); + static void writeFieldsToApplicationStore(caf::PdmObject* object); +}; + + +} // end namespace caf From e43bcd56b96af6bfc2580302b68ecccfe98ae822 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 10:30:58 +0100 Subject: [PATCH 03/51] Added mock model settings --- .../ProjectDataModel/CMakeLists_files.cmake | 2 + .../ProjectDataModel/RimMockModelSettings.cpp | 73 +++++++++++++++++++ .../ProjectDataModel/RimMockModelSettings.h | 52 +++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp create mode 100644 ApplicationCode/ProjectDataModel/RimMockModelSettings.h diff --git a/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake b/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake index 8dd1c8bebe..f6560de705 100644 --- a/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake +++ b/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake @@ -44,6 +44,7 @@ ${CEE_CURRENT_LIST_DIR}RimStatisticsCaseEvaluator.h ${CEE_CURRENT_LIST_DIR}RimMimeData.h ${CEE_CURRENT_LIST_DIR}RimCommandObject.h ${CEE_CURRENT_LIST_DIR}RimTools.h +${CEE_CURRENT_LIST_DIR}RimMockModelSettings.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -86,6 +87,7 @@ ${CEE_CURRENT_LIST_DIR}RimStatisticsCaseEvaluator.cpp ${CEE_CURRENT_LIST_DIR}RimMimeData.cpp ${CEE_CURRENT_LIST_DIR}RimCommandObject.cpp ${CEE_CURRENT_LIST_DIR}RimTools.cpp +${CEE_CURRENT_LIST_DIR}RimMockModelSettings.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp b/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp new file mode 100644 index 0000000000..3e032f107a --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp @@ -0,0 +1,73 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RiaStdInclude.h" + + +#include "RimMockModelSettings.h" + + + + +CAF_PDM_SOURCE_INIT(RimMockModelSettings, "MockModelSettings"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimMockModelSettings::RimMockModelSettings() +{ + CAF_PDM_InitObject("Mock Model Settings", "", "", ""); + + CAF_PDM_InitField(&cellCountX, "CellCountX", quint64(100), "Cell Count X", "", "", ""); + CAF_PDM_InitField(&cellCountY, "CellCountY", quint64(100), "Cell Count Y", "", "", ""); + CAF_PDM_InitField(&cellCountZ, "CellCountZ", quint64(100), "Cell Count Z", "", "", ""); + + CAF_PDM_InitFieldNoDefault(&totalCellCount, "TotalCellCount", "Total Cell Count", "", "", ""); + totalCellCount.setUiReadOnly(true); + + CAF_PDM_InitField(&resultCount, "ResultCount", quint64(3), "Result Count", "", "", ""); + CAF_PDM_InitField(&timeStepCount, "TimeStepCount", quint64(10), "Time Step Count", "", "", ""); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimMockModelSettings::~RimMockModelSettings() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimMockModelSettings::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) +{ + totalCellCount = cellCountX * cellCountY * cellCountZ; + totalCellCount.updateConnectedEditors(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimMockModelSettings::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) +{ + caf::PdmUiGroup* gridSizeGroup = uiOrdering.addNewGroup("Grid size"); + gridSizeGroup->add(&cellCountX); + gridSizeGroup->add(&cellCountY); + gridSizeGroup->add(&cellCountZ); + gridSizeGroup->add(&totalCellCount); +} diff --git a/ApplicationCode/ProjectDataModel/RimMockModelSettings.h b/ApplicationCode/ProjectDataModel/RimMockModelSettings.h new file mode 100644 index 0000000000..64d1beac66 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimMockModelSettings.h @@ -0,0 +1,52 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafPdmField.h" +#include "cafPdmObject.h" +#include "cafPdmPointer.h" + + +//================================================================================================== +/// +/// +//================================================================================================== +class RimMockModelSettings : public caf::PdmObject +{ + CAF_PDM_HEADER_INIT; +public: + + RimMockModelSettings(); + virtual ~RimMockModelSettings(); + + caf::PdmField cellCountX; + caf::PdmField cellCountY; + caf::PdmField cellCountZ; + + caf::PdmField totalCellCount; + + caf::PdmField resultCount; + caf::PdmField timeStepCount; + + + virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ); + + virtual void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ); + +}; From 2315ab9014ae84132f0da76ca5b9f8fbb77040d1 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 10:31:46 +0100 Subject: [PATCH 04/51] Added flag to control adding of well data --- .../ReservoirDataModel/RigReservoirBuilderMock.cpp | 14 +++++++++++++- .../ReservoirDataModel/RigReservoirBuilderMock.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp index 1c79a5bc77..7c1f5a203e 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp +++ b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp @@ -34,6 +34,7 @@ RigReservoirBuilderMock::RigReservoirBuilderMock() m_resultCount = 0; m_timeStepCount = 0; m_gridPointDimensions = cvf::Vec3st::ZERO; + m_enableWellData = true; } //-------------------------------------------------------------------------------------------------- @@ -246,7 +247,10 @@ void RigReservoirBuilderMock::populateReservoir(RigCaseData* eclipseCase) eclipseCase->mainGrid()->setGridPointDimensions(m_gridPointDimensions); - addWellData(eclipseCase, eclipseCase->mainGrid()); + if (m_enableWellData) + { + addWellData(eclipseCase, eclipseCase->mainGrid()); + } // Set all cells active RigActiveCellInfo* activeCellInfo = eclipseCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS); @@ -479,3 +483,11 @@ void RigReservoirBuilderMock::addWellData(RigCaseData* eclipseCase, RigGridBase* eclipseCase->setWellResults(wells); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigReservoirBuilderMock::enableWellData(bool enableWellData) +{ + m_enableWellData = false; +} + diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.h b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.h index d6c0f0fec4..2fb587d85b 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.h +++ b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.h @@ -48,6 +48,7 @@ public: void setWorldCoordinates(cvf::Vec3d minWorldCoordinate, cvf::Vec3d maxWorldCoordinate); void setGridPointDimensions(const cvf::Vec3st& gridPointDimensions); void setResultInfo(size_t resultCount, size_t timeStepCount); + void enableWellData(bool enableWellData); size_t resultCount() const { return m_resultCount; } size_t timeStepCount() const { return m_timeStepCount; } @@ -90,6 +91,7 @@ private: cvf::Vec3st m_gridPointDimensions; size_t m_resultCount; size_t m_timeStepCount; + bool m_enableWellData; std::vector m_localGridRefinements; }; From 93ba02c7db2777e54d0f8833398ede5240737030 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 10:32:24 +0100 Subject: [PATCH 05/51] Added customized mock model to user interface --- .../Application/RiaApplication.cpp | 11 +++++++- ApplicationCode/Application/RiaApplication.h | 1 + .../FileInterface/RifReaderMockModel.cpp | 8 ++++++ .../FileInterface/RifReaderMockModel.h | 1 + ApplicationCode/ProjectDataModel/RimDefines.h | 1 + .../ProjectDataModel/RimInputCase.cpp | 6 ++--- .../ProjectDataModel/RimResultCase.cpp | 27 +++++++++++++++++++ .../UserInterface/RiuMainWindow.cpp | 15 ++++++++--- ApplicationCode/UserInterface/RiuMainWindow.h | 2 ++ 9 files changed, 64 insertions(+), 8 deletions(-) diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index 456443e89a..78766fbe2d 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -657,12 +657,21 @@ void RiaApplication::createLargeResultsMockModel() openEclipseCase(RimDefines::mockModelLargeWithResults(), RimDefines::mockModelLargeWithResults()); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaApplication::createMockModelCustomized() +{ + openEclipseCase(RimDefines::mockModelCustomized(), RimDefines::mockModelCustomized()); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiaApplication::createInputMockModel() { - openInputEclipseCaseFromFileNames(QStringList("Input Mock Debug Model Simple")); + openInputEclipseCaseFromFileNames(QStringList(RimDefines::mockModelBasicInputCase())); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Application/RiaApplication.h b/ApplicationCode/Application/RiaApplication.h index 39744c7da1..c6721b2439 100644 --- a/ApplicationCode/Application/RiaApplication.h +++ b/ApplicationCode/Application/RiaApplication.h @@ -80,6 +80,7 @@ public: void createMockModel(); void createResultsMockModel(); void createLargeResultsMockModel(); + void createMockModelCustomized(); void createInputMockModel(); QString defaultFileDialogDirectory(const QString& dialogName); diff --git a/ApplicationCode/FileInterface/RifReaderMockModel.cpp b/ApplicationCode/FileInterface/RifReaderMockModel.cpp index f03a79e40f..64507ebc8d 100644 --- a/ApplicationCode/FileInterface/RifReaderMockModel.cpp +++ b/ApplicationCode/FileInterface/RifReaderMockModel.cpp @@ -175,3 +175,11 @@ void RifReaderMockModel::populateReservoir(RigCaseData* eclipseCase) m_reservoirBuilder.populateReservoir(eclipseCase); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RifReaderMockModel::enableWellData(bool enableWellData) +{ + m_reservoirBuilder.enableWellData(enableWellData); +} + diff --git a/ApplicationCode/FileInterface/RifReaderMockModel.h b/ApplicationCode/FileInterface/RifReaderMockModel.h index 0237381bbe..3acd5a7c7b 100644 --- a/ApplicationCode/FileInterface/RifReaderMockModel.h +++ b/ApplicationCode/FileInterface/RifReaderMockModel.h @@ -30,6 +30,7 @@ public: void setWorldCoordinates(cvf::Vec3d minWorldCoordinate, cvf::Vec3d maxWorldCoordinate); void setGridPointDimensions(const cvf::Vec3st& gridPointDimensions); void setResultInfo(size_t resultCount, size_t timeStepCount); + void enableWellData(bool enableWellData); void addLocalGridRefinement(const cvf::Vec3st& minCellPosition, const cvf::Vec3st& maxCellPosition, const cvf::Vec3st& singleCellRefinementFactors); diff --git a/ApplicationCode/ProjectDataModel/RimDefines.h b/ApplicationCode/ProjectDataModel/RimDefines.h index d39cb86dcb..ee90527161 100644 --- a/ApplicationCode/ProjectDataModel/RimDefines.h +++ b/ApplicationCode/ProjectDataModel/RimDefines.h @@ -46,6 +46,7 @@ public: static QString mockModelBasic() { return "Result Mock Debug Model Simple"; } static QString mockModelBasicWithResults() { return "Result Mock Debug Model With Results"; } static QString mockModelLargeWithResults() { return "Result Mock Debug Model Large With Results"; } + static QString mockModelCustomized() { return "Result Mock Debug Model Customized"; } static QString mockModelBasicInputCase() { return "Input Mock Debug Model Simple"; } diff --git a/ApplicationCode/ProjectDataModel/RimInputCase.cpp b/ApplicationCode/ProjectDataModel/RimInputCase.cpp index 42a130e15b..469730a82a 100644 --- a/ApplicationCode/ProjectDataModel/RimInputCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimInputCase.cpp @@ -77,7 +77,7 @@ RimInputCase::~RimInputCase() //-------------------------------------------------------------------------------------------------- void RimInputCase::openDataFileSet(const QStringList& fileNames) { - if (fileNames.contains("Input Mock Debug Model Simple")) + if (fileNames.contains(RimDefines::mockModelBasicInputCase())) { cvf::ref readerInterface = this->createMockModel(fileNames[0]); results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p()); @@ -182,7 +182,7 @@ bool RimInputCase::openEclipseGridFile() { cvf::ref readerInterface; - if (m_gridFileName().contains("Input Mock Debug Model Simple")) + if (m_gridFileName().contains(RimDefines::mockModelBasicInputCase())) { readerInterface = this->createMockModel(this->m_gridFileName()); } @@ -370,7 +370,7 @@ cvf::ref RimInputCase::createMockModel(QString modelName) cvf::ref reservoir = new RigCaseData; cvf::ref mockFileInterface = new RifReaderMockModel; - if (modelName == "Input Mock Debug Model Simple") + if (modelName == RimDefines::mockModelBasicInputCase()) { m_gridFileName = modelName; diff --git a/ApplicationCode/ProjectDataModel/RimResultCase.cpp b/ApplicationCode/ProjectDataModel/RimResultCase.cpp index 7118479742..a9a871e03b 100644 --- a/ApplicationCode/ProjectDataModel/RimResultCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimResultCase.cpp @@ -44,6 +44,7 @@ #include "Rim3dOverlayInfoConfig.h" #include "RimOilField.h" #include "RimAnalysisModels.h" +#include "RimMockModelSettings.h" CAF_PDM_SOURCE_INIT(RimResultCase, "EclipseCase"); //-------------------------------------------------------------------------------------------------- @@ -255,6 +256,32 @@ cvf::ref RimResultCase::createMockModel(QString modelName) mockFileInterface->open("", reservoir.p()); } + else if (modelName == RimDefines::mockModelCustomized()) + { + RimMockModelSettings rimMockModelSettings; + + //caf::Settings::readFieldsFromApplicationStore(&rimMockModelSettings); + + double startX = 0; + double startY = 0; + double startZ = 0; + + double widthX = 6000; + double widthY = 12000; + double widthZ = 500; + + // Test code to simulate UTM coordinates + double offsetX = 400000; + double offsetY = 6000000; + double offsetZ = 0; + + mockFileInterface->setWorldCoordinates(cvf::Vec3d(startX + offsetX, startY + offsetY, startZ + offsetZ), cvf::Vec3d(startX + widthX + offsetX, startY + widthY + offsetY, startZ + widthZ + offsetZ)); + mockFileInterface->setGridPointDimensions(cvf::Vec3st(rimMockModelSettings.cellCountX, rimMockModelSettings.cellCountX, rimMockModelSettings.cellCountX)); + mockFileInterface->setResultInfo(rimMockModelSettings.resultCount, rimMockModelSettings.timeStepCount); + mockFileInterface->enableWellData(false); + + mockFileInterface->open("", reservoir.p()); + } this->setReservoirData( reservoir.p() ); diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index 9cf94b5d4f..b389bed378 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -199,6 +199,7 @@ void RiuMainWindow::createActions() m_mockModelAction = new QAction("&Mock Model", this); m_mockResultsModelAction = new QAction("Mock Model With &Results", this); m_mockLargeResultsModelAction = new QAction("Large Mock Model", this); + m_mockModelCustomizedAction = new QAction("Customized Mock Model", this); m_mockInputModelAction = new QAction("Input Mock Model", this); m_snapshotToFile = new QAction(QIcon(":/SnapShotSave.png"), "Snapshot To File", this); @@ -226,6 +227,7 @@ void RiuMainWindow::createActions() connect(m_mockModelAction, SIGNAL(triggered()), SLOT(slotMockModel())); connect(m_mockResultsModelAction, SIGNAL(triggered()), SLOT(slotMockResultsModel())); connect(m_mockLargeResultsModelAction, SIGNAL(triggered()), SLOT(slotMockLargeResultsModel())); + connect(m_mockModelCustomizedAction, SIGNAL(triggered()), SLOT(slotMockModelCustomized())); connect(m_mockInputModelAction, SIGNAL(triggered()), SLOT(slotInputMockModel())); connect(m_snapshotToFile, SIGNAL(triggered()), SLOT(slotSnapshotToFile())); @@ -379,6 +381,7 @@ void RiuMainWindow::createMenus() testMenu->addAction(m_mockModelAction); testMenu->addAction(m_mockResultsModelAction); testMenu->addAction(m_mockLargeResultsModelAction); + testMenu->addAction(m_mockModelCustomizedAction); testMenu->addAction(m_mockInputModelAction); testMenu->addSeparator(); testMenu->addAction(m_createCommandObject); @@ -836,8 +839,6 @@ void RiuMainWindow::slotMockModel() { RiaApplication* app = RiaApplication::instance(); app->createMockModel(); - - //m_mainViewer->setDefaultView(); } //-------------------------------------------------------------------------------------------------- @@ -847,8 +848,6 @@ void RiuMainWindow::slotMockResultsModel() { RiaApplication* app = RiaApplication::instance(); app->createResultsMockModel(); - - //m_mainViewer->setDefaultView(); } @@ -861,6 +860,14 @@ void RiuMainWindow::slotMockLargeResultsModel() app->createLargeResultsMockModel(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMainWindow::slotMockModelCustomized() +{ + RiaApplication* app = RiaApplication::instance(); + app->createMockModelCustomized(); +} //-------------------------------------------------------------------------------------------------- /// diff --git a/ApplicationCode/UserInterface/RiuMainWindow.h b/ApplicationCode/UserInterface/RiuMainWindow.h index 631c44303c..684d39cf0c 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.h +++ b/ApplicationCode/UserInterface/RiuMainWindow.h @@ -153,6 +153,7 @@ private: QAction* m_mockModelAction; QAction* m_mockResultsModelAction; QAction* m_mockLargeResultsModelAction; + QAction* m_mockModelCustomizedAction; QAction* m_mockInputModelAction; QAction* m_snapshotToFile; @@ -240,6 +241,7 @@ private slots: void slotMockModel(); void slotMockResultsModel(); void slotMockLargeResultsModel(); + void slotMockModelCustomized(); void slotInputMockModel(); // Windows slots From 78b6f200b1b6fa610ae34dddab71524f11b37c86 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 11:55:34 +0100 Subject: [PATCH 06/51] Added default editor for quint64 --- Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp index 822d2c3185..5bfee7de4f 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp @@ -65,10 +65,11 @@ CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, QString); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, int); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, double); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, float); +CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, quint64); + CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector); - CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector); From b3f36df480357d93105b911948a025e81f7feab7 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 11:58:49 +0100 Subject: [PATCH 07/51] Added property dialog --- Fwk/AppFwk/cafUserInterface/CMakeLists.txt | 3 + .../cafPdmUiPropertyDialog.cpp | 92 +++++++++++++++++++ .../cafUserInterface/cafPdmUiPropertyDialog.h | 70 ++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.cpp create mode 100644 Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.h diff --git a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt index 61b9318fb9..b318062071 100644 --- a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt +++ b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt @@ -26,6 +26,7 @@ set( QOBJECT_HEADERS cafPdmUiColorEditor.h cafPdmUiPropertyView.h + cafPdmUiPropertyDialog.h cafPdmUiTreeView.h cafPdmUiListView.h cafPdmUiListViewEditor.h @@ -59,6 +60,8 @@ add_library( ${PROJECT_NAME} cafPdmUiListViewEditor.cpp cafPdmUiListViewEditor.h cafPdmUiListView.cpp + cafPdmUiPropertyDialog.cpp + cafPdmUiPropertyDialog.h cafPdmUiPropertyView.cpp cafPdmUiPropertyView.h cafPdmUiPushButtonEditor.cpp diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.cpp new file mode 100644 index 0000000000..277dc3153d --- /dev/null +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.cpp @@ -0,0 +1,92 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2013 Ceetron AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + + +#include "cafPdmUiPropertyDialog.h" + +#include "cafPdmObject.h" +#include "cafPdmUiPropertyView.h" + +#include +#include + +#include + + + +namespace caf { + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiPropertyDialog::PdmUiPropertyDialog(QWidget* parent, caf::PdmObject* object, const QString& windowTitle) + : QDialog(parent) +{ + assert(object); + + m_pdmObject = object; + m_windowTitle = windowTitle; + + setupUi(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiPropertyDialog::setupUi() +{ + setWindowTitle(m_windowTitle); + + m_pdmUiPropertyView = new caf::PdmUiPropertyView(this); + + QVBoxLayout* dialogLayout = new QVBoxLayout; + setLayout(dialogLayout); + + dialogLayout->addWidget(m_pdmUiPropertyView); + m_pdmUiPropertyView->showProperties(m_pdmObject); + + // Buttons + QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + dialogLayout->addWidget(buttonBox); + + this->resize(400, 200); +} + + +} // end namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.h new file mode 100644 index 0000000000..4c4ca7b797 --- /dev/null +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.h @@ -0,0 +1,70 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2013 Ceetron AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + + +#pragma once + +#include + +namespace caf +{ + class PdmObject; + class PdmUiPropertyView; + + +//================================================================================================== +// +// +// +//================================================================================================== +class PdmUiPropertyDialog : public QDialog +{ + Q_OBJECT + +public: + PdmUiPropertyDialog(QWidget* parent, caf::PdmObject* object, const QString& windowTitle); + +private: + void setupUi(); + +private: + QString m_windowTitle; + caf::PdmObject* m_pdmObject; + caf::PdmUiPropertyView* m_pdmUiPropertyView; +}; + + +} // end namespace caf From ae381289692a1aad4c6792676fbef34e94ce1cf2 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 12:05:06 +0100 Subject: [PATCH 08/51] Improved mock model settings and use caf property dialog --- .../ProjectDataModel/RimMockModelSettings.cpp | 6 +- .../ProjectDataModel/RimResultCase.cpp | 56 ++++++++++++------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp b/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp index 3e032f107a..1266629d4e 100644 --- a/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp +++ b/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp @@ -35,7 +35,7 @@ RimMockModelSettings::RimMockModelSettings() CAF_PDM_InitField(&cellCountX, "CellCountX", quint64(100), "Cell Count X", "", "", ""); CAF_PDM_InitField(&cellCountY, "CellCountY", quint64(100), "Cell Count Y", "", "", ""); - CAF_PDM_InitField(&cellCountZ, "CellCountZ", quint64(100), "Cell Count Z", "", "", ""); + CAF_PDM_InitField(&cellCountZ, "CellCountZ", quint64(10), "Cell Count Z", "", "", ""); CAF_PDM_InitFieldNoDefault(&totalCellCount, "TotalCellCount", "Total Cell Count", "", "", ""); totalCellCount.setUiReadOnly(true); @@ -70,4 +70,8 @@ void RimMockModelSettings::defineUiOrdering(QString uiConfigName, caf::PdmUiOrde gridSizeGroup->add(&cellCountY); gridSizeGroup->add(&cellCountZ); gridSizeGroup->add(&totalCellCount); + + caf::PdmUiGroup* resultGroup = uiOrdering.addNewGroup("Results"); + resultGroup->add(&resultCount); + resultGroup->add(&timeStepCount); } diff --git a/ApplicationCode/ProjectDataModel/RimResultCase.cpp b/ApplicationCode/ProjectDataModel/RimResultCase.cpp index a9a871e03b..d75aebbc8e 100644 --- a/ApplicationCode/ProjectDataModel/RimResultCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimResultCase.cpp @@ -17,6 +17,13 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RiaStdInclude.h" + +#include "cafProgressInfo.h" +#include "cafPdmSettings.h" +#include "cafPdmFieldCvfMat4d.h" +#include "cafPdmFieldCvfColor.h" +#include "cafPdmUiPropertyDialog.h" + #include "RimResultCase.h" #include "RigCaseData.h" #include "RifReaderEclipseOutput.h" @@ -24,7 +31,7 @@ #include "RimReservoirView.h" #include "RifReaderMockModel.h" #include "RifReaderEclipseInput.h" -#include "cafProgressInfo.h" + #include "RimProject.h" #include "RifEclipseOutputFileTools.h" #include "RiaApplication.h" @@ -34,8 +41,6 @@ #include "RimReservoirCellResultsCacher.h" #include "RimWellPathCollection.h" -#include "cafPdmFieldCvfMat4d.h" -#include "cafPdmFieldCvfColor.h" #include "RimResultSlot.h" #include "RimCellEdgeResultSlot.h" #include "RimCellRangeFilterCollection.h" @@ -258,29 +263,42 @@ cvf::ref RimResultCase::createMockModel(QString modelName) } else if (modelName == RimDefines::mockModelCustomized()) { + QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); + RimMockModelSettings rimMockModelSettings; + caf::Settings::readFieldsFromApplicationStore(&rimMockModelSettings); - //caf::Settings::readFieldsFromApplicationStore(&rimMockModelSettings); + caf::PdmUiPropertyDialog propertyDialog(NULL, &rimMockModelSettings, "Customize Mock Model"); + if (propertyDialog.exec() == QDialog::Accepted) + { + QApplication::restoreOverrideCursor(); - double startX = 0; - double startY = 0; - double startZ = 0; + caf::Settings::writeFieldsToApplicationStore(&rimMockModelSettings); - double widthX = 6000; - double widthY = 12000; - double widthZ = 500; + double startX = 0; + double startY = 0; + double startZ = 0; - // Test code to simulate UTM coordinates - double offsetX = 400000; - double offsetY = 6000000; - double offsetZ = 0; + double widthX = 6000; + double widthY = 12000; + double widthZ = 500; - mockFileInterface->setWorldCoordinates(cvf::Vec3d(startX + offsetX, startY + offsetY, startZ + offsetZ), cvf::Vec3d(startX + widthX + offsetX, startY + widthY + offsetY, startZ + widthZ + offsetZ)); - mockFileInterface->setGridPointDimensions(cvf::Vec3st(rimMockModelSettings.cellCountX, rimMockModelSettings.cellCountX, rimMockModelSettings.cellCountX)); - mockFileInterface->setResultInfo(rimMockModelSettings.resultCount, rimMockModelSettings.timeStepCount); - mockFileInterface->enableWellData(false); + // Test code to simulate UTM coordinates + double offsetX = 400000; + double offsetY = 6000000; + double offsetZ = 0; - mockFileInterface->open("", reservoir.p()); + mockFileInterface->setWorldCoordinates(cvf::Vec3d(startX + offsetX, startY + offsetY, startZ + offsetZ), cvf::Vec3d(startX + widthX + offsetX, startY + widthY + offsetY, startZ + widthZ + offsetZ)); + mockFileInterface->setGridPointDimensions(cvf::Vec3st(rimMockModelSettings.cellCountX + 1, rimMockModelSettings.cellCountY + 1, rimMockModelSettings.cellCountZ + 1)); + mockFileInterface->setResultInfo(rimMockModelSettings.resultCount, rimMockModelSettings.timeStepCount); + mockFileInterface->enableWellData(false); + + mockFileInterface->open("", reservoir.p()); + } + else + { + QApplication::restoreOverrideCursor(); + } } this->setReservoirData( reservoir.p() ); From c0c78c8ada062aecfda153edb1233ef0c66c46e9 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 12:50:39 +0100 Subject: [PATCH 09/51] Use caf property dialog and removed obsolete riuPreferencesDialog --- ApplicationCode/CMakeLists.txt | 2 - .../ProjectDataModel/RimUiTreeView.cpp | 15 ++--- .../UserInterface/RiuMainWindow.cpp | 8 +-- .../UserInterface/RiuPreferencesDialog.cpp | 67 ------------------- .../UserInterface/RiuPreferencesDialog.h | 49 -------------- 5 files changed, 11 insertions(+), 130 deletions(-) delete mode 100644 ApplicationCode/UserInterface/RiuPreferencesDialog.cpp delete mode 100644 ApplicationCode/UserInterface/RiuPreferencesDialog.h diff --git a/ApplicationCode/CMakeLists.txt b/ApplicationCode/CMakeLists.txt index be82147d67..6d0abc01cc 100644 --- a/ApplicationCode/CMakeLists.txt +++ b/ApplicationCode/CMakeLists.txt @@ -42,7 +42,6 @@ set( APPLICATION_FILES set( USER_INTERFACE_FILES UserInterface/RiuCursors.cpp UserInterface/RiuMainWindow.cpp - UserInterface/RiuPreferencesDialog.cpp UserInterface/RiuResultInfoPanel.cpp UserInterface/RiuViewer.cpp UserInterface/RiuSimpleHistogramWidget.cpp @@ -97,7 +96,6 @@ set ( QT_MOC_HEADERS ProjectDataModel/RimMimeData.h UserInterface/RiuMainWindow.h - UserInterface/RiuPreferencesDialog.h UserInterface/RiuResultInfoPanel.h UserInterface/RiuViewer.h UserInterface/RiuProcessMonitor.h diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp b/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp index f8c96f3653..af65cdb029 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp +++ b/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp @@ -19,6 +19,9 @@ //#include "RiaStdInclude.h" #include "cafPdmDocument.h" +#include "cafPdmFieldCvfColor.h" +#include "cafPdmFieldCvfMat4d.h" +#include "cafPdmUiPropertyDialog.h" #include #include @@ -37,7 +40,6 @@ #include "RimInputPropertyCollection.h" #include "RimExportInputPropertySettings.h" #include "RiaPreferences.h" -#include "RiuPreferencesDialog.h" #include "RifEclipseInputFileTools.h" #include "RimInputCase.h" #include "RimBinaryExportSettings.h" @@ -59,9 +61,6 @@ #include "RimWellPathCollection.h" #include "RimReservoirCellResultsCacher.h" #include "Rim3dOverlayInfoConfig.h" - -#include "cafPdmFieldCvfColor.h" -#include "cafPdmFieldCvfMat4d.h" #include "RimProject.h" #include "RimOilField.h" #include "RimAnalysisModels.h" @@ -834,8 +833,8 @@ void RimUiTreeView::slotWriteInputProperty() exportSettings.fileName = outputFileName; } - RiuPreferencesDialog preferencesDialog(this, &exportSettings, "Export Eclipse Property to Text File"); - if (preferencesDialog.exec() == QDialog::Accepted) + caf::PdmUiPropertyDialog propertyDialog(this, &exportSettings, "Export Eclipse Property to Text File"); + if (propertyDialog.exec() == QDialog::Accepted) { bool isOk = RifEclipseInputFileTools::writePropertyToTextFile(exportSettings.fileName, inputReservoir->reservoirData(), 0, inputProperty->resultName, exportSettings.eclipseKeyword); if (isOk) @@ -887,8 +886,8 @@ void RimUiTreeView::slotWriteBinaryResultAsInputProperty() exportSettings.fileName = outputFileName; } - RiuPreferencesDialog preferencesDialog(this, &exportSettings, "Export Binary Eclipse Data to Text File"); - if (preferencesDialog.exec() == QDialog::Accepted) + caf::PdmUiPropertyDialog propertyDialog(this, &exportSettings, "Export Binary Eclipse Data to Text File"); + if (propertyDialog.exec() == QDialog::Accepted) { size_t timeStep = resultSlot->reservoirView()->currentTimeStep(); RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(resultSlot->porosityModel()); diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index b389bed378..bb99acd830 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -43,7 +43,6 @@ #include "RiuMultiCaseImportDialog.h" #include "RiaPreferences.h" -#include "RiuPreferencesDialog.h" #include "RigCaseCellResultsData.h" @@ -63,6 +62,7 @@ #include "RimCalcScript.h" #include "RimTools.h" #include "RiaRegressionTest.h" +#include "cafPdmUiPropertyDialog.h" @@ -1214,8 +1214,8 @@ void RiuMainWindow::slotShowPerformanceInfo(bool enable) void RiuMainWindow::slotEditPreferences() { RiaApplication* app = RiaApplication::instance(); - RiuPreferencesDialog preferencesDialog(this, app->preferences(), "Preferences"); - if (preferencesDialog.exec() == QDialog::Accepted) + caf::PdmUiPropertyDialog propertyDialog(this, app->preferences(), "Preferences"); + if (propertyDialog.exec() == QDialog::Accepted) { // Write preferences using QSettings and apply them to the application app->writeFieldsToApplicationStore(app->preferences()); @@ -1739,7 +1739,7 @@ void RiuMainWindow::slotShowRegressionTestDialog() RiaApplication* app = RiaApplication::instance(); app->readFieldsFromApplicationStore(®TestConfig); - RiuPreferencesDialog regressionTestDialog(this, ®TestConfig, "Regression Test"); + caf::PdmUiPropertyDialog regressionTestDialog(this, ®TestConfig, "Regression Test"); if (regressionTestDialog.exec() == QDialog::Accepted) { // Write preferences using QSettings and apply them to the application diff --git a/ApplicationCode/UserInterface/RiuPreferencesDialog.cpp b/ApplicationCode/UserInterface/RiuPreferencesDialog.cpp deleted file mode 100644 index 7a094776c8..0000000000 --- a/ApplicationCode/UserInterface/RiuPreferencesDialog.cpp +++ /dev/null @@ -1,67 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS -// -// ResInsight is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. -// -// See the GNU General Public License at -// for more details. -// -///////////////////////////////////////////////////////////////////////////////// - -#include "RiaStdInclude.h" -#include "RiuPreferencesDialog.h" - -#include "cafAppEnum.h" -#include "cafPdmObject.h" - -#include "RimUiTreeModelPdm.h" -#include "cafPdmUiPropertyView.h" - - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RiuPreferencesDialog::RiuPreferencesDialog(QWidget* parent, caf::PdmObject* object, const QString& windowTitle) - : QDialog(parent) -{ - CVF_ASSERT(object); - - m_pdmObject = object; - m_windowTitle = windowTitle; - - setupUi(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuPreferencesDialog::setupUi() -{ - setWindowTitle(m_windowTitle); - - m_pdmUiPropertyView = new caf::PdmUiPropertyView(this); - - QVBoxLayout* dialogLayout = new QVBoxLayout; - setLayout(dialogLayout); - - dialogLayout->addWidget(m_pdmUiPropertyView); - m_pdmUiPropertyView->showProperties(m_pdmObject); - - // Buttons - QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); - connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); - - dialogLayout->addWidget(buttonBox); - - this->resize(400, 200); -} diff --git a/ApplicationCode/UserInterface/RiuPreferencesDialog.h b/ApplicationCode/UserInterface/RiuPreferencesDialog.h deleted file mode 100644 index 3751e108fb..0000000000 --- a/ApplicationCode/UserInterface/RiuPreferencesDialog.h +++ /dev/null @@ -1,49 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS -// -// ResInsight is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. -// -// See the GNU General Public License at -// for more details. -// -///////////////////////////////////////////////////////////////////////////////// - -#pragma once - -#include - -namespace caf -{ - class PdmObject; - class PdmUiPropertyView; -} - - -//================================================================================================== -// -// -// -//================================================================================================== -class RiuPreferencesDialog : public QDialog -{ - Q_OBJECT - -public: - RiuPreferencesDialog(QWidget* parent, caf::PdmObject* object, const QString& windowTitle); - -private: - void setupUi(); - -private: - QString m_windowTitle; - caf::PdmObject* m_pdmObject; - caf::PdmUiPropertyView* m_pdmUiPropertyView; -}; From e47f2e6317c04a776d9af83acc443af499585f55 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 8 Nov 2013 10:34:05 +0100 Subject: [PATCH 10/51] Performance: Added OpenMP to mock models --- .../RigReservoirBuilderMock.cpp | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp index 7c1f5a203e..d99f6d1a2d 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp +++ b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp @@ -135,10 +135,14 @@ void RigReservoirBuilderMock::appendCubeNodes(const cvf::Vec3d& min, const cvf:: void RigReservoirBuilderMock::appendCells(size_t nodeStartIndex, size_t cellCount, RigGridBase* hostGrid, std::vector& cells) { size_t activeCellIndex = 0; - size_t i; - for (i = 0; i < cellCount; i++) + long long i; + + cells.resize(cellCount); + +#pragma omp parallel for + for (i = 0; i < static_cast(cellCount); i++) { - RigCell riCell; + RigCell& riCell = cells[i]; riCell.setHostGrid(hostGrid); riCell.setCellIndex(i); @@ -165,8 +169,6 @@ void RigReservoirBuilderMock::appendCells(size_t nodeStartIndex, size_t cellCoun riCell.setActiveIndexInMatrixModel(activeCellIndex++); } */ - - cells.push_back(riCell); } } @@ -348,13 +350,15 @@ bool RigReservoirBuilderMock::dynamicResult(RigCaseData* eclipseCase, const QStr double scaleValue = 1.0 + resultIndex * 0.1; double offsetValue = 100 * resultIndex; - size_t k; - for (k = 0; k < eclipseCase->mainGrid()->cells().size(); k++) + values->resize(eclipseCase->mainGrid()->cells().size()); + +#pragma omp parallel for + for (long long k = 0; k < static_cast(eclipseCase->mainGrid()->cells().size()); k++) { RigCell& cell = eclipseCase->mainGrid()->cells()[k]; { double val = offsetValue + scaleValue * ( (stepIndex * 1000 + k) % eclipseCase->mainGrid()->cells().size() ); - values->push_back(val); + values->at(k) = val; } } From 4d467447837906451e5be17c81ec9653f435649e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 8 Nov 2013 14:27:21 +0100 Subject: [PATCH 11/51] Performance: Reduce memory use for riGetPropertyData --- .../SocketInterface/RiaPropertyDataCommands.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp index 40dc5d2efd..f31218d7e3 100644 --- a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp @@ -304,10 +304,10 @@ public: quint64 timestepCount = (quint64)requestedTimesteps.size(); socketStream << timestepCount; - size_t doubleValueCount = cellCountI * cellCountJ * cellCountK * timestepCount * sizeof(double); - std::vector values(doubleValueCount); size_t valueIdx = 0; + std::vector values(rigGrid->cellCount()); + for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) { cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); @@ -323,11 +323,11 @@ public: { cellValue = 0.0; } - values[valueIdx++] = cellValue; + values[cellIdx] = cellValue; } - } - server->currentClient()->write((const char *)values.data(), doubleValueCount); + server->currentClient()->write((const char *)values.data(), rigGrid->cellCount() * sizeof(double)); + } return true; } From f4559008ba513f617f0bfcdb4604b2e253c74f09 Mon Sep 17 00:00:00 2001 From: magnesj Date: Mon, 11 Nov 2013 14:36:59 +0100 Subject: [PATCH 12/51] Temporarily fixes for handling communication of more than 2GB data to/from octave --- OctavePlugin/riGetActiveCellProperty.cpp | 4 +- OctavePlugin/riGetGridProperty.cpp | 87 +++++++++++++++++++++--- OctavePlugin/riSetGridProperty.cpp | 13 ++-- 3 files changed, 88 insertions(+), 16 deletions(-) diff --git a/OctavePlugin/riGetActiveCellProperty.cpp b/OctavePlugin/riGetActiveCellProperty.cpp index a936b82d96..81b966f7d0 100644 --- a/OctavePlugin/riGetActiveCellProperty.cpp +++ b/OctavePlugin/riGetActiveCellProperty.cpp @@ -67,7 +67,7 @@ void getActiveCellProperty(Matrix& propertyFrames, const QString &serverName, qu for (size_t tIdx = 0; tIdx < timestepCount; ++tIdx) { - while (socket.bytesAvailable() < (int)byteCount) + while (socket.bytesAvailable() < (qint64)byteCount) { if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) { @@ -94,7 +94,7 @@ void getActiveCellProperty(Matrix& propertyFrames, const QString &serverName, qu } #endif - if ((int)byteCount != bytesRead) + if ((qint64)byteCount != bytesRead) { error("Could not read binary double data properly from socket"); octave_stdout << "Active cells: " << activeCellCount << ", Timesteps: " << timestepCount << std::endl; diff --git a/OctavePlugin/riGetGridProperty.cpp b/OctavePlugin/riGetGridProperty.cpp index 3771341644..3b1fbc589f 100644 --- a/OctavePlugin/riGetGridProperty.cpp +++ b/OctavePlugin/riGetGridProperty.cpp @@ -22,7 +22,7 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 QString command; command += "GetGridProperty " + QString::number(caseId) + " " + QString::number(gridIdx) + " " + propertyName + " " + porosityModel; - for (int i = 0; i < requestedTimeSteps.length(); ++i) + for (qint64 i = 0; i < requestedTimeSteps.length(); ++i) { if (i == 0) command += " "; command += QString::number(static_cast(requestedTimeSteps.elem(i)) - 1); // To make the index 0-based @@ -36,7 +36,7 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 // Get response. First wait for the header - while (socket.bytesAvailable() < (int)(4*sizeof(quint64))) + while (socket.bytesAvailable() < (qint64)(4*sizeof(quint64))) { if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) { @@ -48,6 +48,7 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 // Read sizes quint64 totalByteCount; + quint64 cellCountI; quint64 cellCountJ; quint64 cellCountK; @@ -59,6 +60,9 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 socketStream >> timestepCount; totalByteCount = cellCountI*cellCountJ*cellCountK*timestepCount*sizeof(double); + + qint64 timestepByteCount = cellCountI*cellCountJ*cellCountK*sizeof(double); + if (!(totalByteCount)) { error ("Could not find the requested data in ResInsight"); @@ -75,29 +79,92 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 propertyFrames.resize(dv); - // Wait for available data - - while (socket.bytesAvailable() < (int)totalByteCount) +#if 1 + // Wait for available data for each timestep, then read data for each timestep + + qint64 totalBytesRead = 0; + + for (size_t tIdx = 0; tIdx < timestepCount; ++tIdx) { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) + qint64 bytesAvailable = socket.bytesAvailable() ; + + while ( bytesAvailable < (qint64)timestepByteCount) { - error(("Waiting for data : " + socket.errorString()).toLatin1().data()); - return ; + if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) + { + error((("Waiting for timestep data number: ") + QString::number(tIdx)+ ": " + socket.errorString()).toLatin1().data()); + octave_stdout << "Cellcount: " << cellCountI*cellCountJ*cellCountK << ", Timesteps: " << timestepCount << std::endl; + return ; + } + + bytesAvailable = socket.bytesAvailable(); + + OCTAVE_QUIT; } + + qint64 bytesRead = 0; + double * internalMatrixData = propertyFrames.fortran_vec(); + + // Raw data transfer. Faster. Not possible when dealing with coarsening + bytesRead = socket.read(((char*)(internalMatrixData)) + tIdx * timestepByteCount, timestepByteCount); + + if ((qint64)timestepByteCount != bytesRead) + { + error("Could not read binary double data properly from socket"); + octave_stdout << "Cellcount: " << cellCountI*cellCountJ*cellCountK << ", Timesteps count: " << timestepCount << std::endl; + octave_stdout << "Timestep : " << tIdx << std::endl; + } + + totalBytesRead += bytesRead; + + OCTAVE_QUIT; + } + + if ((qint64)totalByteCount != totalBytesRead) + { + error("Could not read binary double data properly from socket"); + } + + #else + + // Wait for available data + qint64 bytesAvailable = socket.bytesAvailable() ; + + while (bytesAvailable < (qint64)totalByteCount) + { + octave_stdout << "Waiting for data. Has : " << bytesAvailable << " Needs :" << totalByteCount << std::endl; + if (!socket.waitForReadyRead(riOctavePlugin::shortTimeOutMilliSecs)) + { + //error(("Waiting for data : " + socket.errorString()).toLatin1().data()); + //return ; + } + + bytesAvailable = socket.bytesAvailable() ; OCTAVE_QUIT; } qint64 bytesRead = 0; double * internalMatrixData = propertyFrames.fortran_vec(); +#if 0 + + char* dataBuffer = new char[totalByteCount]; + bytesRead = socket.read(dataBuffer, totalByteCount); + + +#else + // Raw data transfer. Faster. bytesRead = socket.read((char*)(internalMatrixData ), totalByteCount); +#endif - if ((int)totalByteCount != bytesRead) + + if ((qint64)totalByteCount != bytesRead) { error("Could not read binary double data properly from socket"); } - + +#endif QString tmp = QString("riGetGridProperty : Read %1").arg(propertyName); if (caseId < 0) diff --git a/OctavePlugin/riSetGridProperty.cpp b/OctavePlugin/riSetGridProperty.cpp index 04773e8804..f5afe0a0f7 100644 --- a/OctavePlugin/riSetGridProperty.cpp +++ b/OctavePlugin/riSetGridProperty.cpp @@ -64,8 +64,13 @@ void setEclipseProperty(const NDArray& propertyFrames, const QString &hostName, socketStream << (qint64)singleTimeStepByteCount; const double* internalData = propertyFrames.fortran_vec(); - int dataWritten = socket.write((const char *)internalData, singleTimeStepByteCount*timeStepCount); - + qint64 dataWritten = 0; + + for (size_t tsIdx = 0; tsIdx < timeStepCount; ++tsIdx) + { + dataWritten += socket.write(((const char *)internalData) + tsIdx*singleTimeStepByteCount, singleTimeStepByteCount); + } + if (dataWritten == singleTimeStepByteCount*timeStepCount) { QString tmp = QString("riSetGridProperty : Wrote %1").arg(propertyName); @@ -92,8 +97,8 @@ void setEclipseProperty(const NDArray& propertyFrames, const QString &hostName, while(socket.bytesToWrite() && socket.state() == QAbstractSocket::ConnectedState) { - // octave_stdout << "Bytes to write: " << socket.bytesToWrite() << std::endl; - socket.waitForBytesWritten(riOctavePlugin::longTimeOutMilliSecs); + octave_stdout << "Bytes to write: " << socket.bytesToWrite() << std::endl << std::flush; + socket.waitForBytesWritten(2000); OCTAVE_QUIT; } From af6d92d64eb5c0f0d42ccb092f43593064725212 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 1 Apr 2014 13:02:52 +0200 Subject: [PATCH 13/51] Added flag to control how to do IO with sockets --- .../Application/RiaPreferences.cpp | 2 + ApplicationCode/Application/RiaPreferences.h | 2 + .../SocketInterface/RiaGeometryCommands.cpp | 68 ++++++++++++++----- .../RiaPropertyDataCommands.cpp | 61 +++++++++++++---- 4 files changed, 103 insertions(+), 30 deletions(-) diff --git a/ApplicationCode/Application/RiaPreferences.cpp b/ApplicationCode/Application/RiaPreferences.cpp index 19454642f1..bd065e418c 100644 --- a/ApplicationCode/Application/RiaPreferences.cpp +++ b/ApplicationCode/Application/RiaPreferences.cpp @@ -59,6 +59,8 @@ RiaPreferences::RiaPreferences(void) CAF_PDM_InitField(&autocomputeSOIL, "autocomputeSOIL", true, "SOIL", "", "SOIL = 1.0 - SGAS - SWAT", ""); CAF_PDM_InitField(&autocomputeDepthRelatedProperties,"autocomputeDepth", true, "DEPTH related properties", "", "DEPTH, DX, DY, DZ, TOP, BOTTOM", ""); + + CAF_PDM_InitField(&useStreamTransfer, "useStreamTransfer", true, "Use stream transfer to Octave", "", "", ""); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Application/RiaPreferences.h b/ApplicationCode/Application/RiaPreferences.h index 0f87fecc17..f877efdbb4 100644 --- a/ApplicationCode/Application/RiaPreferences.h +++ b/ApplicationCode/Application/RiaPreferences.h @@ -59,6 +59,8 @@ public: // Pdm Fields caf::PdmField autocomputeDepthRelatedProperties; + caf::PdmField useStreamTransfer; + protected: virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute); diff --git a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp index 2ec5878cb6..413f4791bc 100644 --- a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp @@ -34,6 +34,8 @@ #include "RigCaseCellResultsData.h" #include +#include "RiaApplication.h" +#include "RiaPreferences.h" //-------------------------------------------------------------------------------------------------- @@ -241,32 +243,66 @@ public: // dv(3) = 8; // dv(4) = 3; - std::vector cellCornerValues(doubleValueCount); - cvf::Vec3d cornerVerts[8]; - quint64 coordCount = 0; - for (int coordIdx = 0; coordIdx < 3; coordIdx++) + cvf::Timer timer; + + if (RiaApplication::instance()->preferences()->useStreamTransfer()) { - for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) + cvf::Vec3d cornerVerts[8]; + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { - size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - - for (size_t k = 0; k < cellCountK; k++) + for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) { - for (size_t j = 0; j < cellCountJ; j++) - { - for (size_t i = 0; i < cellCountI; i++) - { - size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); - rigGrid->cellCornerVertices(localCellIdx, cornerVerts); + size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx]; + for (size_t k = 0; k < cellCountK; k++) + { + for (size_t j = 0; j < cellCountJ; j++) + { + for (size_t i = 0; i < cellCountI; i++) + { + size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); + rigGrid->cellCornerVertices(localCellIdx, cornerVerts); + + socketStream << cornerVerts[cornerIndexMapping][coordIdx]; + } } } } } } + else + { + std::vector cellCornerValues(doubleValueCount); + cvf::Vec3d cornerVerts[8]; + quint64 coordCount = 0; + for (int coordIdx = 0; coordIdx < 3; coordIdx++) + { + for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) + { + size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - server->currentClient()->write((const char *)cellCornerValues.data(), byteCount); + for (size_t k = 0; k < cellCountK; k++) + { + for (size_t j = 0; j < cellCountJ; j++) + { + for (size_t i = 0; i < cellCountI; i++) + { + size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); + rigGrid->cellCornerVertices(localCellIdx, cornerVerts); + + cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx]; + } + } + } + } + } + server->currentClient()->write((const char *)cellCornerValues.data(), byteCount); + } + + double totalTimeMS = timer.time() * 1000.0; + QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); + + server->errorMessageDialog()->showMessage(resultInfo); return true; } diff --git a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp index f31218d7e3..4fa6a4f841 100644 --- a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp @@ -40,6 +40,8 @@ #include "Rim3dOverlayInfoConfig.h" #include +#include "RiaApplication.h" +#include "RiaPreferences.h" //-------------------------------------------------------------------------------------------------- @@ -305,30 +307,61 @@ public: socketStream << timestepCount; size_t valueIdx = 0; - - std::vector values(rigGrid->cellCount()); + cvf::Timer timer; - for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) + if (RiaApplication::instance()->preferences()->useStreamTransfer()) { - cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); - if (cellCenterDataAccessObject.isNull()) + for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) { - continue; - } - - for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) - { - double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); - if (cellValue == HUGE_VAL) + cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); + if (cellCenterDataAccessObject.isNull()) { - cellValue = 0.0; + continue; + } + + for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) + { + double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); + if (cellValue == HUGE_VAL) + { + cellValue = 0.0; + } + + socketStream << cellValue; + } + } + } + else + { + + std::vector values(rigGrid->cellCount()); + for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) + { + cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); + if (cellCenterDataAccessObject.isNull()) + { + continue; + } + + for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) + { + double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); + if (cellValue == HUGE_VAL) + { + cellValue = 0.0; + } + values[valueIdx++] = cellValue; } - values[cellIdx] = cellValue; } server->currentClient()->write((const char *)values.data(), rigGrid->cellCount() * sizeof(double)); } + double totalTimeMS = timer.time() * 1000.0; + QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); + + server->errorMessageDialog()->showMessage(resultInfo); + return true; } }; From 4ab5e28cf7b4c3906363165fc35a9eb4ac569b19 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 1 Apr 2014 15:31:13 +0200 Subject: [PATCH 14/51] Added block write to socket tools --- .../Application/RiaPreferences.cpp | 1 + ApplicationCode/Application/RiaPreferences.h | 1 + .../SocketInterface/RiaCaseInfoCommands.cpp | 9 +++- .../SocketInterface/RiaGeometryCommands.cpp | 10 ++-- .../RiaPropertyDataCommands.cpp | 5 +- .../SocketInterface/RiaSocketTools.cpp | 47 +++++++++++++++++++ .../SocketInterface/RiaSocketTools.h | 3 ++ 7 files changed, 67 insertions(+), 9 deletions(-) diff --git a/ApplicationCode/Application/RiaPreferences.cpp b/ApplicationCode/Application/RiaPreferences.cpp index bd065e418c..0c63994aec 100644 --- a/ApplicationCode/Application/RiaPreferences.cpp +++ b/ApplicationCode/Application/RiaPreferences.cpp @@ -61,6 +61,7 @@ RiaPreferences::RiaPreferences(void) CAF_PDM_InitField(&autocomputeDepthRelatedProperties,"autocomputeDepth", true, "DEPTH related properties", "", "DEPTH, DX, DY, DZ, TOP, BOTTOM", ""); CAF_PDM_InitField(&useStreamTransfer, "useStreamTransfer", true, "Use stream transfer to Octave", "", "", ""); + CAF_PDM_InitField(&blockSize, "blockSize", 10000, "blockSize", "", "", ""); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Application/RiaPreferences.h b/ApplicationCode/Application/RiaPreferences.h index f877efdbb4..f46f002b35 100644 --- a/ApplicationCode/Application/RiaPreferences.h +++ b/ApplicationCode/Application/RiaPreferences.h @@ -60,6 +60,7 @@ public: // Pdm Fields caf::PdmField useStreamTransfer; + caf::PdmField blockSize; protected: virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute); diff --git a/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp b/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp index 201267dfb0..e6444f314d 100644 --- a/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp @@ -16,9 +16,12 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RiaStdInclude.h" + #include "RiaSocketCommand.h" #include "RiaSocketServer.h" #include "RiaSocketTools.h" +#include "RiaApplication.h" +#include "RiaPreferences.h" #include "RimReservoirView.h" #include "RimResultSlot.h" @@ -28,8 +31,8 @@ #include "RimWellCollection.h" #include "Rim3dOverlayInfoConfig.h" #include "RimReservoirCellResultsCacher.h" - #include "RimCase.h" + #include "RigCaseData.h" #include "RigCaseCellResultsData.h" @@ -37,6 +40,7 @@ + //-------------------------------------------------------------------------------------------------- /// OBSOLETE, to be deleted //-------------------------------------------------------------------------------------------------- @@ -133,7 +137,8 @@ public: for (size_t tIdx = 0; tIdx < columnCount; ++tIdx) { #if 1 // Write data as raw bytes, fast but does not handle byteswapping - server->currentClient()->write((const char *)activeCellInfo[tIdx].data(), timestepByteCount); + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)activeCellInfo[tIdx].data(), timestepByteCount); + #else // Write data using QDataStream, does byteswapping for us. Must use QDataStream on client as well for (size_t cIdx = 0; cIdx < activeCellInfo[tIdx].size(); ++cIdx) { diff --git a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp index 413f4791bc..5a3c8bc8b7 100644 --- a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp @@ -38,6 +38,7 @@ #include "RiaPreferences.h" + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -108,7 +109,7 @@ public: CVF_ASSERT(coordCount == doubleValueCount); - server->currentClient()->write((const char *)cellCenterValues.data(), byteCount); + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount); return true; } @@ -181,7 +182,7 @@ public: quint64 byteCount = doubleValueCount * sizeof(double); socketStream << byteCount; - server->currentClient()->write((const char *)cellCenterValues.data(), byteCount); + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount); return true; } @@ -296,7 +297,8 @@ public: } } } - server->currentClient()->write((const char *)cellCornerValues.data(), byteCount); + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount); } double totalTimeMS = timer.time() * 1000.0; @@ -381,7 +383,7 @@ public: quint64 byteCount = doubleValueCount * sizeof(double); socketStream << byteCount; - server->currentClient()->write((const char *)cellCornerValues.data(), byteCount); + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount); return true; } diff --git a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp index 4fa6a4f841..00210e4e21 100644 --- a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp @@ -334,7 +334,6 @@ public: else { - std::vector values(rigGrid->cellCount()); for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) { cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); @@ -343,6 +342,7 @@ public: continue; } + std::vector values(rigGrid->cellCount()); for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) { double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); @@ -352,9 +352,8 @@ public: } values[valueIdx++] = cellValue; } + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), values.size() * sizeof(double)); } - - server->currentClient()->write((const char *)values.data(), rigGrid->cellCount() * sizeof(double)); } double totalTimeMS = timer.time() * 1000.0; diff --git a/ApplicationCode/SocketInterface/RiaSocketTools.cpp b/ApplicationCode/SocketInterface/RiaSocketTools.cpp index cc53f26824..4ad720d2a9 100644 --- a/ApplicationCode/SocketInterface/RiaSocketTools.cpp +++ b/ApplicationCode/SocketInterface/RiaSocketTools.cpp @@ -16,6 +16,10 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RiaStdInclude.h" + +#include "RiaApplication.h" +#include "RiaPreferences.h" + #include "RiaSocketTools.h" #include "RiaSocketServer.h" #include "RimCase.h" @@ -34,6 +38,8 @@ #include "RimInputPropertyCollection.h" +#include + //-------------------------------------------------------------------------------------------------- /// @@ -98,4 +104,45 @@ void RiaSocketTools::getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QStri } } +bool RiaSocketTools::writeBlockData(RiaSocketServer* server, QTcpSocket* socket, const char* data, quint64 bytesToWrite) +{ + cvf::Timer timer; + + quint64 bytesWritten = 0; + int blockCount = 0; + + quint64 maxBlockSize = RiaApplication::instance()->preferences()->blockSize(); + + while (bytesWritten < bytesToWrite) + { + quint64 byteCountToWrite = qMin(bytesToWrite - bytesWritten, maxBlockSize); + + quint64 actuallyBytesWritten = socket->write(data + bytesWritten, byteCountToWrite); + if (actuallyBytesWritten == -1) + { + if (server) + { + QString errorMessage = "Error detected when writing data, error string from socket : \n" + socket->errorString(); + + server->errorMessageDialog()->showMessage(errorMessage); + } + + return false; + } + + bytesWritten += actuallyBytesWritten; + + blockCount++; + } + + if (server) + { + double totalTimeMS = timer.time() * 1000.0; + QString resultInfo = QString("Total time '%1 ms'\nTotal bytes written . %2\nNumber of blocks : %3\nBlock size : %4").arg(totalTimeMS).arg(bytesWritten).arg(blockCount).arg(maxBlockSize); + + server->errorMessageDialog()->showMessage(resultInfo); + } + + return true; +} diff --git a/ApplicationCode/SocketInterface/RiaSocketTools.h b/ApplicationCode/SocketInterface/RiaSocketTools.h index 1baeb5a9fc..b331799e2e 100644 --- a/ApplicationCode/SocketInterface/RiaSocketTools.h +++ b/ApplicationCode/SocketInterface/RiaSocketTools.h @@ -17,6 +17,7 @@ class RimCase; class RiaSocketServer; +class QTcpSocket; #define PMonLog( MessageString ) RiuMainWindow::instance()->processMonitor()->addStringToLog( MessageString ); @@ -25,4 +26,6 @@ class RiaSocketTools public: static RimCase* findCaseFromArgs(RiaSocketServer* server, const QList& args); static void getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId); + + static bool writeBlockData(RiaSocketServer* server, QTcpSocket* socket, const char* data, quint64 bytesToWrite); }; From f5e1773fde10c245068e7ebed6a7b7c5c228229b Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 1 Apr 2014 15:36:08 +0200 Subject: [PATCH 15/51] Fixed used on unsigned --- ApplicationCode/SocketInterface/RiaSocketTools.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ApplicationCode/SocketInterface/RiaSocketTools.cpp b/ApplicationCode/SocketInterface/RiaSocketTools.cpp index 4ad720d2a9..0f645450f9 100644 --- a/ApplicationCode/SocketInterface/RiaSocketTools.cpp +++ b/ApplicationCode/SocketInterface/RiaSocketTools.cpp @@ -113,12 +113,13 @@ bool RiaSocketTools::writeBlockData(RiaSocketServer* server, QTcpSocket* socket, quint64 maxBlockSize = RiaApplication::instance()->preferences()->blockSize(); + while (bytesWritten < bytesToWrite) { quint64 byteCountToWrite = qMin(bytesToWrite - bytesWritten, maxBlockSize); - quint64 actuallyBytesWritten = socket->write(data + bytesWritten, byteCountToWrite); - if (actuallyBytesWritten == -1) + qint64 actuallyBytesWritten = socket->write(data + bytesWritten, byteCountToWrite); + if (actuallyBytesWritten < 0) { if (server) { From e748f087a7741fa79d5318c83999b12715d1c7d3 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 2 Apr 2014 08:55:26 +0200 Subject: [PATCH 16/51] Added block read from socket --- .../SocketInterface/RiaSocketTools.cpp | 43 +++++++++++++++++++ .../SocketInterface/RiaSocketTools.h | 1 + OctavePlugin/riGetCellCorners.cpp | 17 ++++++++ 3 files changed, 61 insertions(+) diff --git a/ApplicationCode/SocketInterface/RiaSocketTools.cpp b/ApplicationCode/SocketInterface/RiaSocketTools.cpp index 0f645450f9..64cc8e0c11 100644 --- a/ApplicationCode/SocketInterface/RiaSocketTools.cpp +++ b/ApplicationCode/SocketInterface/RiaSocketTools.cpp @@ -147,3 +147,46 @@ bool RiaSocketTools::writeBlockData(RiaSocketServer* server, QTcpSocket* socket, return true; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RiaSocketTools::readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages) +{ + quint64 bytesRead = 0; + int blockCount = 0; + + quint64 maxBlockSize = RiaApplication::instance()->preferences()->blockSize(); + + while (bytesRead < bytesToRead) + { + if (socket.bytesAvailable()) + { + quint64 byteCountToRead = qMin(bytesToRead - bytesRead, maxBlockSize); + + qint64 actuallyBytesRead = socket.read(data + bytesRead, byteCountToRead); + if (actuallyBytesRead < 0) + { + errorMessages.push_back("Error detected when writing data, error string from socket"); + errorMessages.push_back(socket.errorString()); + + return false; + } + + bytesRead += actuallyBytesRead; + blockCount++; + } + else + { + if (!socket.waitForReadyRead()) + { + errorMessages.push_back("Waited for data for %1 milli seconds."); + errorMessages.push_back(socket.errorString()); + + return false; + } + } + } + + return true; +} + diff --git a/ApplicationCode/SocketInterface/RiaSocketTools.h b/ApplicationCode/SocketInterface/RiaSocketTools.h index b331799e2e..5a24731237 100644 --- a/ApplicationCode/SocketInterface/RiaSocketTools.h +++ b/ApplicationCode/SocketInterface/RiaSocketTools.h @@ -28,4 +28,5 @@ public: static void getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId); static bool writeBlockData(RiaSocketServer* server, QTcpSocket* socket, const char* data, quint64 bytesToWrite); + static bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages); }; diff --git a/OctavePlugin/riGetCellCorners.cpp b/OctavePlugin/riGetCellCorners.cpp index ee8f810239..af659079c0 100644 --- a/OctavePlugin/riGetCellCorners.cpp +++ b/OctavePlugin/riGetCellCorners.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "../ApplicationCode/SocketInterface/RiaSocketTools.h" void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex) @@ -67,7 +70,20 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 dv(4) = 3; cellCornerValues.resize(dv); + double* internalMatrixData = cellCornerValues.fortran_vec(); + QStringList errorMessages; + if (!RiaSocketTools::readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) + { + for (int i = 0; i < errorMessages.size(); i++) + { + error(errorMessages[i].toLatin1().data()); + } + OCTAVE_QUIT; + } + + + /* while (socket.bytesAvailable() < (qint64)(byteCount)) { if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) @@ -97,6 +113,7 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 } #endif + */ return; } From ecf00881986dbf853395af5be2dd0a35f346b326 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 2 Apr 2014 09:52:02 +0200 Subject: [PATCH 17/51] Moved Octave socket reading into riSocketTools --- OctavePlugin/riGetCellCorners.cpp | 8 ++++-- OctavePlugin/riGetCurrentCase.cpp | 1 + OctavePlugin/riSocketTools.h | 46 +++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 OctavePlugin/riSocketTools.h diff --git a/OctavePlugin/riGetCellCorners.cpp b/OctavePlugin/riGetCellCorners.cpp index af659079c0..f5e3b2c356 100644 --- a/OctavePlugin/riGetCellCorners.cpp +++ b/OctavePlugin/riGetCellCorners.cpp @@ -4,7 +4,9 @@ #include #include "riSettings.h" -#include "../ApplicationCode/SocketInterface/RiaSocketTools.h" +#include "riSocketTools.h" + + void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex) @@ -72,7 +74,7 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 double* internalMatrixData = cellCornerValues.fortran_vec(); QStringList errorMessages; - if (!RiaSocketTools::readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) + if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) { for (int i = 0; i < errorMessages.size(); i++) { @@ -82,6 +84,8 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 OCTAVE_QUIT; } + octave_stdout << "Bytes count processed : " << byteCount << std::endl; + /* while (socket.bytesAvailable() < (qint64)(byteCount)) diff --git a/OctavePlugin/riGetCurrentCase.cpp b/OctavePlugin/riGetCurrentCase.cpp index 80b0ffe4ac..88cc38088d 100644 --- a/OctavePlugin/riGetCurrentCase.cpp +++ b/OctavePlugin/riGetCurrentCase.cpp @@ -3,6 +3,7 @@ #include #include "riSettings.h" +#include "riSocketTools.h" void getCurrentCase(qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId, const QString &hostName, quint16 port) { diff --git a/OctavePlugin/riSocketTools.h b/OctavePlugin/riSocketTools.h new file mode 100644 index 0000000000..7d01381668 --- /dev/null +++ b/OctavePlugin/riSocketTools.h @@ -0,0 +1,46 @@ + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages) +{ + quint64 bytesRead = 0; + int blockCount = 0; + + quint64 maxBlockSize = 100000; + + while (bytesRead < bytesToRead) + { + if (socket.bytesAvailable()) + { + quint64 byteCountToRead = qMin(bytesToRead - bytesRead, maxBlockSize); + + qint64 actuallyBytesRead = socket.read(data + bytesRead, byteCountToRead); + if (actuallyBytesRead < 0) + { + errorMessages.push_back("Error detected when writing data, error string from socket"); + errorMessages.push_back(socket.errorString()); + + return false; + } + + bytesRead += actuallyBytesRead; + + octave_stdout << "Bytes read " << bytesRead << " of total " << bytesToRead << std::endl; + + blockCount++; + } + else + { + if (!socket.waitForReadyRead()) + { + errorMessages.push_back("Waited for data for %1 milli seconds."); + errorMessages.push_back(socket.errorString()); + + return false; + } + } + } + + return true; +} From f19f080fb0be4274e986a9dfea071728b1603a0d Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 3 Apr 2014 08:16:15 +0200 Subject: [PATCH 18/51] Moved socket max byte count to riSettings Added header files to cmake --- OctavePlugin/CMakeLists.txt | 5 ++++- OctavePlugin/riSettings.h | 2 ++ OctavePlugin/riSocketTools.h | 38 ++++++++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/OctavePlugin/CMakeLists.txt b/OctavePlugin/CMakeLists.txt index 68a4b588d3..7a11e18ab9 100644 --- a/OctavePlugin/CMakeLists.txt +++ b/OctavePlugin/CMakeLists.txt @@ -141,7 +141,10 @@ if (RESINSIGHT_OCTAVE_PLUGIN_QMAKE AND RESINSIGHT_OCTAVE_PLUGIN_MKOCTFILE) "${CMAKE_CURRENT_BINARY_DIR}/riGetWellNames.oct" "${CMAKE_CURRENT_BINARY_DIR}/riGetWellStatus.oct" "${CMAKE_CURRENT_BINARY_DIR}/riGetWellCells.oct" - SOURCES ${CPP_SOURCES} + SOURCES + ${CPP_SOURCES} + riSocketTools.h + riSettings.h ) diff --git a/OctavePlugin/riSettings.h b/OctavePlugin/riSettings.h index bc7220e845..5765244a6d 100644 --- a/OctavePlugin/riSettings.h +++ b/OctavePlugin/riSettings.h @@ -24,6 +24,8 @@ namespace riOctavePlugin const int shortTimeOutMilliSecs = 5000; const int longTimeOutMilliSecs = 6000000; + const int socketMaxByteCount = 100000; + // Octave data structure : CaseInfo char caseInfo_CaseId[] = "CaseId"; char caseInfo_CaseName[] = "CaseName"; diff --git a/OctavePlugin/riSocketTools.h b/OctavePlugin/riSocketTools.h index 7d01381668..63cc24d890 100644 --- a/OctavePlugin/riSocketTools.h +++ b/OctavePlugin/riSocketTools.h @@ -7,7 +7,7 @@ bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringL quint64 bytesRead = 0; int blockCount = 0; - quint64 maxBlockSize = 100000; + quint64 maxBlockSize = riOctavePlugin::socketMaxByteCount; while (bytesRead < bytesToRead) { @@ -18,7 +18,7 @@ bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringL qint64 actuallyBytesRead = socket.read(data + bytesRead, byteCountToRead); if (actuallyBytesRead < 0) { - errorMessages.push_back("Error detected when writing data, error string from socket"); + errorMessages.push_back("Error detected when reading data, error string from socket :"); errorMessages.push_back(socket.errorString()); return false; @@ -41,6 +41,40 @@ bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringL } } } + + octave_stdout << "Bytes read " << bytesToRead << std::endl; + + return true; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool writeBlockData(QTcpSocket& socket, const char* data, quint64 bytesToWrite, QStringList& errorMessages) +{ + quint64 bytesWritten = 0; + int blockCount = 0; + + quint64 maxBlockSize = riOctavePlugin::socketMaxByteCount; + + while (bytesWritten < bytesToWrite) + { + quint64 byteCountToWrite = qMin(bytesToWrite - bytesWritten, maxBlockSize); + + qint64 actuallyBytesWritten = socket.write(data + bytesWritten, byteCountToWrite); + if (actuallyBytesWritten < 0) + { + errorMessages.push_back("Error detected when writing data, error string from socket"); + errorMessages.push_back(socket.errorString()); + + return false; + } + + bytesWritten += actuallyBytesWritten; + + blockCount++; + } return true; } From 05f1c056b7c4a12af8f23738d42dd83d520f0a22 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 3 Apr 2014 10:41:27 +0200 Subject: [PATCH 19/51] Use socket block read/write for geometry data --- .../SocketInterface/RiaGeometryCommands.cpp | 133 ++++++++---------- OctavePlugin/riGetActiveCellCenters.cpp | 27 ++-- OctavePlugin/riGetActiveCellCorners.cpp | 27 ++-- OctavePlugin/riGetCellCenters.cpp | 37 ++--- OctavePlugin/riGetCellCorners.cpp | 35 ----- 5 files changed, 89 insertions(+), 170 deletions(-) diff --git a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp index 5a3c8bc8b7..2ca72a655d 100644 --- a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp @@ -87,11 +87,14 @@ public: // dv(2) = cellCountK; // dv(3) = 3; - std::vector cellCenterValues(doubleValueCount); cvf::Vec3d cornerVerts[8]; - quint64 coordCount = 0; + size_t blockByteCount = cellCount * sizeof(double); + std::vector doubleValues(blockByteCount); + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { + quint64 valueIndex = 0; + for (size_t k = 0; k < cellCountK; k++) { for (size_t j = 0; j < cellCountJ; j++) @@ -101,16 +104,16 @@ public: size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); cvf::Vec3d center = rigGrid->cell(localCellIdx).center(); - cellCenterValues[coordCount++] = center[coordIdx]; + doubleValues[valueIndex++] = center[coordIdx]; } } } + + CVF_ASSERT(valueIndex == cellCount); + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } - CVF_ASSERT(coordCount == doubleValueCount); - - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount); - return true; } }; @@ -152,6 +155,11 @@ public: size_t activeCellCount = actCellInfo->globalActiveCellCount(); size_t doubleValueCount = activeCellCount * 3; + socketStream << (quint64)activeCellCount; + quint64 byteCount = doubleValueCount * sizeof(double); + socketStream << byteCount; + + // This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is // defined by the ordering of the receiving NDArray // @@ -162,28 +170,26 @@ public: // dv(0) = coordCount; // dv(1) = 3; - std::vector cellCenterValues(doubleValueCount); - quint64 coordCount = 0; + size_t blockByteCount = activeCellCount * sizeof(double); + std::vector doubleValues(blockByteCount); + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { + quint64 valueIndex = 0; + for (size_t globalCellIdx = 0; globalCellIdx < mainGrid->cells().size(); globalCellIdx++) { if (!actCellInfo->isActive(globalCellIdx)) continue; cvf::Vec3d center = mainGrid->cells()[globalCellIdx].center(); - cellCenterValues[coordCount++] = center[coordIdx]; + doubleValues[valueIndex++] = center[coordIdx]; } + + CVF_ASSERT(valueIndex == activeCellCount); + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } - CVF_ASSERT(coordCount == doubleValueCount); - - socketStream << (quint64)activeCellCount; - quint64 byteCount = doubleValueCount * sizeof(double); - socketStream << byteCount; - - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount); - return true; } @@ -244,67 +250,37 @@ public: // dv(3) = 8; // dv(4) = 3; - cvf::Timer timer; + cvf::Vec3d cornerVerts[8]; + size_t blockByteCount = cellCount * sizeof(double); + std::vector doubleValues(blockByteCount); - if (RiaApplication::instance()->preferences()->useStreamTransfer()) + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { - cvf::Vec3d cornerVerts[8]; - for (int coordIdx = 0; coordIdx < 3; coordIdx++) + for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) { - for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) + size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; + + quint64 valueIndex = 0; + + for (size_t k = 0; k < cellCountK; k++) { - size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - - for (size_t k = 0; k < cellCountK; k++) + for (size_t j = 0; j < cellCountJ; j++) { - for (size_t j = 0; j < cellCountJ; j++) + for (size_t i = 0; i < cellCountI; i++) { - for (size_t i = 0; i < cellCountI; i++) - { - size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); - rigGrid->cellCornerVertices(localCellIdx, cornerVerts); + size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); + rigGrid->cellCornerVertices(localCellIdx, cornerVerts); - socketStream << cornerVerts[cornerIndexMapping][coordIdx]; - } + doubleValues[valueIndex++] = cornerVerts[cornerIndexMapping][coordIdx]; } } } + + CVF_ASSERT(valueIndex, cellCount); + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } } - else - { - std::vector cellCornerValues(doubleValueCount); - cvf::Vec3d cornerVerts[8]; - quint64 coordCount = 0; - for (int coordIdx = 0; coordIdx < 3; coordIdx++) - { - for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) - { - size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - - for (size_t k = 0; k < cellCountK; k++) - { - for (size_t j = 0; j < cellCountJ; j++) - { - for (size_t i = 0; i < cellCountI; i++) - { - size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); - rigGrid->cellCornerVertices(localCellIdx, cornerVerts); - - cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx]; - } - } - } - } - } - - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount); - } - - double totalTimeMS = timer.time() * 1000.0; - QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); - - server->errorMessageDialog()->showMessage(resultInfo); return true; } @@ -348,6 +324,10 @@ public: size_t activeCellCount = actCellInfo->globalActiveCellCount(); size_t doubleValueCount = activeCellCount * 3 * 8; + socketStream << (quint64)activeCellCount; + quint64 byteCount = doubleValueCount * sizeof(double); + socketStream << byteCount; + // This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is // defined by the ordering of the receiving NDArray // @@ -359,32 +339,33 @@ public: // dv(1) = 8; // dv(2) = 3; - std::vector cellCornerValues(doubleValueCount); cvf::Vec3d cornerVerts[8]; - quint64 coordCount = 0; + size_t blockByteCount = activeCellCount * sizeof(double); + std::vector doubleValues(blockByteCount); + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) { size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; + quint64 valueIndex = 0; + for (size_t globalCellIdx = 0; globalCellIdx < mainGrid->cells().size(); globalCellIdx++) { if (!actCellInfo->isActive(globalCellIdx)) continue; mainGrid->cellCornerVertices(globalCellIdx, cornerVerts); - cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx]; + doubleValues[valueIndex++] = cornerVerts[cornerIndexMapping][coordIdx]; } + + CVF_ASSERT(valueIndex == activeCellCount); + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } } - socketStream << (quint64)activeCellCount; - quint64 byteCount = doubleValueCount * sizeof(double); - socketStream << byteCount; - - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount); - return true; } diff --git a/OctavePlugin/riGetActiveCellCenters.cpp b/OctavePlugin/riGetActiveCellCenters.cpp index 90c1631f30..a98ba06bac 100644 --- a/OctavePlugin/riGetActiveCellCenters.cpp +++ b/OctavePlugin/riGetActiveCellCenters.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "riSocketTools.h" void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const QString& porosityModel) @@ -61,24 +64,16 @@ void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, qu cellCenterValues.resize(dv); - while (socket.bytesAvailable() < (qint64)(byteCount)) - { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - error((("Waiting for data: ") + socket.errorString()).toLatin1().data()); - return; - } - OCTAVE_QUIT; - } - - quint64 bytesRead = 0; double* internalMatrixData = cellCenterValues.fortran_vec(); - bytesRead = socket.read((char*)(internalMatrixData), byteCount); - - if (byteCount != bytesRead) + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) { - error("Could not read binary double data properly from socket"); - octave_stdout << "Active cell count: " << activeCellCount << std::endl; + for (int i = 0; i < errorMessages.size(); i++) + { + error(errorMessages[i].toLatin1().data()); + } + + OCTAVE_QUIT; } return; diff --git a/OctavePlugin/riGetActiveCellCorners.cpp b/OctavePlugin/riGetActiveCellCorners.cpp index 6fb285cc4a..47ffad52bc 100644 --- a/OctavePlugin/riGetActiveCellCorners.cpp +++ b/OctavePlugin/riGetActiveCellCorners.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "riSocketTools.h" void getActiveCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 port, const qint32& caseId, const QString& porosityModel) @@ -61,24 +64,16 @@ void getActiveCellCorners(NDArray& cellCornerValues, const QString &hostName, qu dv(2) = 3; cellCornerValues.resize(dv); - while (socket.bytesAvailable() < (qint64)(byteCount)) - { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - error((("Waiting for data: ") + socket.errorString()).toLatin1().data()); - return; - } - OCTAVE_QUIT; - } - - quint64 bytesRead = 0; double* internalMatrixData = cellCornerValues.fortran_vec(); - bytesRead = socket.read((char*)(internalMatrixData), byteCount); - - if (byteCount != bytesRead) + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) { - error("Could not read binary double data properly from socket"); - octave_stdout << "Active cell count: " << activeCellCount << std::endl; + for (int i = 0; i < errorMessages.size(); i++) + { + error(errorMessages[i].toLatin1().data()); + } + + OCTAVE_QUIT; } return; diff --git a/OctavePlugin/riGetCellCenters.cpp b/OctavePlugin/riGetCellCenters.cpp index cb65de3d01..4f57d08a2b 100644 --- a/OctavePlugin/riGetCellCenters.cpp +++ b/OctavePlugin/riGetCellCenters.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "riSocketTools.h" void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex) @@ -66,39 +69,19 @@ void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 dv(3) = 3; cellCenterValues.resize(dv); - while (socket.bytesAvailable() < (qint64)(byteCount)) + + double* internalMatrixData = cellCenterValues.fortran_vec(); + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) + for (int i = 0; i < errorMessages.size(); i++) { - error((("Waiting for data: ") + socket.errorString()).toLatin1().data()); - return; + error(errorMessages[i].toLatin1().data()); } + OCTAVE_QUIT; } - //octave_stdout << " riGetCellCenters : I = " << cellCountI <<" J = " << cellCountJ << " K = " << cellCountK << std::endl; - //octave_stdout << " riGetCellCenters : numDoubles = " << valueCount << std::endl; - - double* internalMatrixData = cellCenterValues.fortran_vec(); - -#if 0 - octave_idx_type valueCount = cellCenterValues.length(); - double val; - for (octave_idx_type i = 0; i < valueCount; i++) - { - socketStream >> internalMatrixData[i]; - } -#else - quint64 bytesRead = 0; - bytesRead = socket.read((char*)(internalMatrixData), byteCount); - - if (byteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - octave_stdout << "Cell count: " << cellCount << std::endl; - } - -#endif return; } diff --git a/OctavePlugin/riGetCellCorners.cpp b/OctavePlugin/riGetCellCorners.cpp index f5e3b2c356..2571371a76 100644 --- a/OctavePlugin/riGetCellCorners.cpp +++ b/OctavePlugin/riGetCellCorners.cpp @@ -84,41 +84,6 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 OCTAVE_QUIT; } - octave_stdout << "Bytes count processed : " << byteCount << std::endl; - - - /* - while (socket.bytesAvailable() < (qint64)(byteCount)) - { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - error((("Waiting for data: ") + socket.errorString()).toLatin1().data()); - return; - } - OCTAVE_QUIT; - } - - double* internalMatrixData = cellCornerValues.fortran_vec(); - -#if 0 - double val; - for (octave_idx_type i = 0; i < valueCount; i++) - { - socketStream >> internalMatrixData[i]; - } -#else - quint64 bytesRead = 0; - bytesRead = socket.read((char*)(internalMatrixData), byteCount); - - if (byteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - octave_stdout << "Cell count: " << cellCount << std::endl; - } - -#endif - */ - return; } From 9aa32e4a887e2bc271201d5b5ab8e2fc94bdff2d Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 3 Apr 2014 10:58:29 +0200 Subject: [PATCH 20/51] Added isCoarseningActive --- ApplicationCode/ReservoirDataModel/RigActiveCellInfo.cpp | 8 ++++++++ ApplicationCode/ReservoirDataModel/RigActiveCellInfo.h | 1 + 2 files changed, 9 insertions(+) diff --git a/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.cpp b/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.cpp index bb0da770da..b58b17c5d4 100644 --- a/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.cpp +++ b/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.cpp @@ -193,6 +193,14 @@ void RigActiveCellInfo::clear() m_activeCellsBoundingBox.reset(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RigActiveCellInfo::isCoarseningActive() const +{ + return m_globalCellResultCount != m_globalActiveCellCount; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.h b/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.h index 2719dbffb5..cbe11c9b8c 100644 --- a/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.h +++ b/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.h @@ -36,6 +36,7 @@ public: size_t globalCellCount() const; size_t globalActiveCellCount() const; size_t globalCellResultCount() const; + bool isCoarseningActive() const; bool isActive(size_t globalCellIndex) const; size_t cellResultIndex(size_t globalCellIndex) const; From 34e6d98c767f05bb2fa25d33a757e2aecd73c800 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 3 Apr 2014 11:09:42 +0200 Subject: [PATCH 21/51] Updated use of buffer read --- OctavePlugin/riGetActiveCellInfo.cpp | 48 +++++++--------------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/OctavePlugin/riGetActiveCellInfo.cpp b/OctavePlugin/riGetActiveCellInfo.cpp index 824134e0f7..a7213a3697 100644 --- a/OctavePlugin/riGetActiveCellInfo.cpp +++ b/OctavePlugin/riGetActiveCellInfo.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "riSocketTools.h" void getActiveCellInfo(int32NDArray& activeCellInfo, const QString &hostName, quint16 port, const qint64& caseId, const QString& porosityModel) @@ -43,59 +46,32 @@ void getActiveCellInfo(int32NDArray& activeCellInfo, const QString &hostName, qu // Read timestep count and blocksize quint64 columnCount; - quint64 byteCount; + quint64 byteCountForOneTimestep; size_t activeCellCount; socketStream >> columnCount; - socketStream >> byteCount; + socketStream >> byteCountForOneTimestep; - activeCellCount = byteCount / sizeof(qint32); + activeCellCount = byteCountForOneTimestep / sizeof(qint32); dim_vector dv (2, 1); dv(0) = activeCellCount; dv(1) = columnCount; activeCellInfo.resize(dv); - if (!(byteCount && columnCount)) + if (!(byteCountForOneTimestep && columnCount)) { error ("Could not find the requested data in ResInsight"); return; } - // Wait for available data for each column, then read data for each column - for (size_t tIdx = 0; tIdx < columnCount; ++tIdx) + qint32* internalMatrixData = (qint32*)activeCellInfo.fortran_vec()->mex_get_data(); + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), columnCount * byteCountForOneTimestep, errorMessages)) { - while (socket.bytesAvailable() < (int)byteCount) + for (int i = 0; i < errorMessages.size(); i++) { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - QString errorMsg = QString("Waiting for column number: %1 of %2: %3").arg(tIdx).arg(columnCount).arg(socket.errorString()); - - error(errorMsg.toLatin1().data()); - octave_stdout << "Active cells: " << activeCellCount << ", Columns: " << columnCount << std::endl; - return ; - } - OCTAVE_QUIT; - } - - qint64 bytesRead = 0; - qint32* internalMatrixData = (qint32*)activeCellInfo.fortran_vec()->mex_get_data(); - -#if 1 // Use raw data transfer. Faster. - bytesRead = socket.read((char*)(internalMatrixData + tIdx * activeCellCount), byteCount); -#else - for (size_t cIdx = 0; cIdx < activeCellCount; ++cIdx) - { - socketStream >> internalMatrixData[tIdx * activeCellCount + cIdx]; - - if (socketStream.status() == QDataStream::Ok) bytesRead += sizeof(int); - } -#endif - - if ((int)byteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - octave_stdout << "Active cells: " << activeCellCount << ", Columns: " << columnCount << std::endl; + error(errorMessages[i].toLatin1().data()); } OCTAVE_QUIT; From 770f70680345d00c4b6c828e1e36f3f12000a390 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 3 Apr 2014 11:56:01 +0200 Subject: [PATCH 22/51] Updated riGetGridProperty --- .../RiaPropertyDataCommands.cpp | 57 +++--------- OctavePlugin/riGetGridProperty.cpp | 92 ++----------------- 2 files changed, 22 insertions(+), 127 deletions(-) diff --git a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp index 00210e4e21..87cf148f7c 100644 --- a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp @@ -306,61 +306,28 @@ public: quint64 timestepCount = (quint64)requestedTimesteps.size(); socketStream << timestepCount; - size_t valueIdx = 0; - cvf::Timer timer; - - if (RiaApplication::instance()->preferences()->useStreamTransfer()) + for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) { - for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) + cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); + if (cellCenterDataAccessObject.isNull()) { - cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); - if (cellCenterDataAccessObject.isNull()) - { - continue; - } - - for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) - { - double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); - if (cellValue == HUGE_VAL) - { - cellValue = 0.0; - } - - socketStream << cellValue; - } + continue; } - } - else - { - for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) + std::vector values(rigGrid->cellCount()); + for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) { - cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); - if (cellCenterDataAccessObject.isNull()) + double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); + if (cellValue == HUGE_VAL) { - continue; + cellValue = 0.0; } - - std::vector values(rigGrid->cellCount()); - for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) - { - double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); - if (cellValue == HUGE_VAL) - { - cellValue = 0.0; - } - values[valueIdx++] = cellValue; - } - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), values.size() * sizeof(double)); + values[cellIdx] = cellValue; } + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), values.size() * sizeof(double)); } - double totalTimeMS = timer.time() * 1000.0; - QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); - - server->errorMessageDialog()->showMessage(resultInfo); - return true; } }; diff --git a/OctavePlugin/riGetGridProperty.cpp b/OctavePlugin/riGetGridProperty.cpp index 3b1fbc589f..e477cd767a 100644 --- a/OctavePlugin/riGetGridProperty.cpp +++ b/OctavePlugin/riGetGridProperty.cpp @@ -1,6 +1,11 @@ #include +#include + #include + #include "riSettings.h" +#include "riSocketTools.h" + void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 serverPort, const int& caseId, int gridIdx, QString propertyName, const int32NDArray& requestedTimeSteps, QString porosityModel) @@ -61,8 +66,6 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 totalByteCount = cellCountI*cellCountJ*cellCountK*timestepCount*sizeof(double); - qint64 timestepByteCount = cellCountI*cellCountJ*cellCountK*sizeof(double); - if (!(totalByteCount)) { error ("Could not find the requested data in ResInsight"); @@ -78,93 +81,18 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 propertyFrames.resize(dv); - -#if 1 - // Wait for available data for each timestep, then read data for each timestep - - qint64 totalBytesRead = 0; - - for (size_t tIdx = 0; tIdx < timestepCount; ++tIdx) + double* internalMatrixData = propertyFrames.fortran_vec(); + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), totalByteCount, errorMessages)) { - qint64 bytesAvailable = socket.bytesAvailable() ; - - while ( bytesAvailable < (qint64)timestepByteCount) + for (int i = 0; i < errorMessages.size(); i++) { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - error((("Waiting for timestep data number: ") + QString::number(tIdx)+ ": " + socket.errorString()).toLatin1().data()); - octave_stdout << "Cellcount: " << cellCountI*cellCountJ*cellCountK << ", Timesteps: " << timestepCount << std::endl; - return ; - } - - bytesAvailable = socket.bytesAvailable(); - - OCTAVE_QUIT; + error(errorMessages[i].toLatin1().data()); } - qint64 bytesRead = 0; - double * internalMatrixData = propertyFrames.fortran_vec(); - - // Raw data transfer. Faster. Not possible when dealing with coarsening - bytesRead = socket.read(((char*)(internalMatrixData)) + tIdx * timestepByteCount, timestepByteCount); - - if ((qint64)timestepByteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - octave_stdout << "Cellcount: " << cellCountI*cellCountJ*cellCountK << ", Timesteps count: " << timestepCount << std::endl; - octave_stdout << "Timestep : " << tIdx << std::endl; - } - - totalBytesRead += bytesRead; - - OCTAVE_QUIT; - } - - if ((qint64)totalByteCount != totalBytesRead) - { - error("Could not read binary double data properly from socket"); - } - - #else - - // Wait for available data - qint64 bytesAvailable = socket.bytesAvailable() ; - - while (bytesAvailable < (qint64)totalByteCount) - { - octave_stdout << "Waiting for data. Has : " << bytesAvailable << " Needs :" << totalByteCount << std::endl; - if (!socket.waitForReadyRead(riOctavePlugin::shortTimeOutMilliSecs)) - { - //error(("Waiting for data : " + socket.errorString()).toLatin1().data()); - //return ; - } - - bytesAvailable = socket.bytesAvailable() ; OCTAVE_QUIT; } - qint64 bytesRead = 0; - double * internalMatrixData = propertyFrames.fortran_vec(); - -#if 0 - - char* dataBuffer = new char[totalByteCount]; - bytesRead = socket.read(dataBuffer, totalByteCount); - - -#else - - // Raw data transfer. Faster. - bytesRead = socket.read((char*)(internalMatrixData ), totalByteCount); -#endif - - - if ((qint64)totalByteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - } - -#endif QString tmp = QString("riGetGridProperty : Read %1").arg(propertyName); if (caseId < 0) From 3e8a206f13c5686ef6e81b2978ae34a9c0280e6e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 07:30:00 +0100 Subject: [PATCH 23/51] Moved mock model identicators to RimDefines --- ApplicationCode/Application/RiaApplication.cpp | 6 +++--- ApplicationCode/ProjectDataModel/RimDefines.h | 9 ++++++++- ApplicationCode/ProjectDataModel/RimResultCase.cpp | 6 +++--- ApplicationCode/UserInterface/RiuMainWindow.cpp | 6 +++--- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index f10595a388..9ff31cc740 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -699,7 +699,7 @@ bool RiaApplication::openInputEclipseCaseFromFileNames(const QStringList& fileNa //-------------------------------------------------------------------------------------------------- void RiaApplication::createMockModel() { - openEclipseCase("Result Mock Debug Model Simple", "Result Mock Debug Model Simple"); + openEclipseCase(RimDefines::mockModelBasic(), RimDefines::mockModelBasic()); } //-------------------------------------------------------------------------------------------------- @@ -707,7 +707,7 @@ void RiaApplication::createMockModel() //-------------------------------------------------------------------------------------------------- void RiaApplication::createResultsMockModel() { - openEclipseCase("Result Mock Debug Model With Results", "Result Mock Debug Model With Results"); + openEclipseCase(RimDefines::mockModelBasicWithResults(), RimDefines::mockModelBasicWithResults()); } @@ -716,7 +716,7 @@ void RiaApplication::createResultsMockModel() //-------------------------------------------------------------------------------------------------- void RiaApplication::createLargeResultsMockModel() { - openEclipseCase("Result Mock Debug Model Large With Results", "Result Mock Debug Model Large With Results"); + openEclipseCase(RimDefines::mockModelLargeWithResults(), RimDefines::mockModelLargeWithResults()); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimDefines.h b/ApplicationCode/ProjectDataModel/RimDefines.h index 95313686a3..cfb31f48ad 100644 --- a/ApplicationCode/ProjectDataModel/RimDefines.h +++ b/ApplicationCode/ProjectDataModel/RimDefines.h @@ -41,7 +41,14 @@ public: static QString undefinedResultName() { return "None"; } static QString undefinedGridFaultName() { return "Undefined grid faults"; } - static QString combinedTransmissibilityResultName() { return "TRANSXYZ"; } + + + // Mock model text identifiers + static QString mockModelBasic() { return "Result Mock Debug Model Simple"; } + static QString mockModelBasicWithResults() { return "Result Mock Debug Model With Results"; } + static QString mockModelLargeWithResults() { return "Result Mock Debug Model Large With Results"; } + static QString mockModelBasicInputCase() { return "Input Mock Debug Model Simple"; } + }; diff --git a/ApplicationCode/ProjectDataModel/RimResultCase.cpp b/ApplicationCode/ProjectDataModel/RimResultCase.cpp index 4e9157ac22..558245c5f6 100644 --- a/ApplicationCode/ProjectDataModel/RimResultCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimResultCase.cpp @@ -199,7 +199,7 @@ cvf::ref RimResultCase::createMockModel(QString modelName) cvf::ref mockFileInterface = new RifReaderMockModel; cvf::ref reservoir = new RigCaseData; - if (modelName == "Result Mock Debug Model Simple") + if (modelName == RimDefines::mockModelBasic()) { // Create the mock file interface and and RigSerervoir and set them up. mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(20, 20, 20)); @@ -221,7 +221,7 @@ cvf::ref RimResultCase::createMockModel(QString modelName) //reservoir->mainGrid()->cell(idx).setActiveIndexInMatrixModel(cvf::UNDEFINED_SIZE_T); } } - else if (modelName == "Result Mock Debug Model With Results") + else if (modelName == RimDefines::mockModelBasicWithResults()) { mockFileInterface->setWorldCoordinates(cvf::Vec3d(10, 10, 10), cvf::Vec3d(-20, -20, -20)); mockFileInterface->setGridPointDimensions(cvf::Vec3st(5, 10, 20)); @@ -234,7 +234,7 @@ cvf::ref RimResultCase::createMockModel(QString modelName) cvf::Vec3d& tmp = reservoir->mainGrid()->nodes()[1]; tmp += cvf::Vec3d(1, 0, 0); } - else if (modelName =="Result Mock Debug Model Large With Results") + else if (modelName == RimDefines::mockModelLargeWithResults()) { double startX = 0; double startY = 0; diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index 930a0c337c..dd1e7090c2 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -1446,9 +1446,9 @@ void RiuMainWindow::slotOpenMultipleCases() if (1) { - gridFileNames += "Result Mock Debug Model With Results"; - gridFileNames += "Result Mock Debug Model With Results"; - gridFileNames += "Result Mock Debug Model With Results"; + gridFileNames += RimDefines::mockModelBasicWithResults(); + gridFileNames += RimDefines::mockModelBasicWithResults(); + gridFileNames += RimDefines::mockModelBasicWithResults(); } else { From 00cc1a88a5b3d5f85c43749d2ce29869798146ce Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 10:30:11 +0100 Subject: [PATCH 24/51] Added serialization of pdm objects using QSettings --- Fwk/AppFwk/cafUserInterface/CMakeLists.txt | 2 + .../cafUserInterface/cafPdmSettings.cpp | 116 ++++++++++++++++++ Fwk/AppFwk/cafUserInterface/cafPdmSettings.h | 55 +++++++++ 3 files changed, 173 insertions(+) create mode 100644 Fwk/AppFwk/cafUserInterface/cafPdmSettings.cpp create mode 100644 Fwk/AppFwk/cafUserInterface/cafPdmSettings.h diff --git a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt index 69496b3ffe..b09a2f49a1 100644 --- a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt +++ b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt @@ -11,6 +11,7 @@ set( QOBJECT_HEADERS cafUiTreeModelPdm.h cafUiProcess.h + cafPdmSettings.h cafPdmUiLineEditor.h cafPdmUiCheckBoxEditor.h cafPdmUiComboBoxEditor.h @@ -38,6 +39,7 @@ endif() add_library( ${PROJECT_NAME} cafAboutDialog.cpp cafAboutDialog.h + cafPdmSettings.cpp cafPdmUiCheckBoxEditor.cpp cafPdmUiCheckBoxEditor.h cafPdmUiColorEditor.cpp diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmSettings.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmSettings.cpp new file mode 100644 index 0000000000..a8e3a3ba5c --- /dev/null +++ b/Fwk/AppFwk/cafUserInterface/cafPdmSettings.cpp @@ -0,0 +1,116 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2013 Ceetron AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + + +#include "cafPdmSettings.h" +#include "cafPdmField.h" + +#include + + +namespace caf +{ + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void Settings::readFieldsFromApplicationStore(caf::PdmObject* object) +{ + // Qt doc : + // + // Constructs a QSettings object for accessing settings of the application and organization + // set previously with a call to QCoreApplication::setOrganizationName(), + // QCoreApplication::setOrganizationDomain(), and QCoreApplication::setApplicationName(). + QSettings settings; + + QString prefix = object->classKeyword(); + if (!prefix.isEmpty()) + { + prefix += "/"; + } + + std::vector fields; + object->fields(fields); + size_t i; + for (i = 0; i < fields.size(); i++) + { + caf::PdmFieldHandle* fieldHandle = fields[i]; + + QString keywordWithPrefix = prefix + fieldHandle->keyword(); + if (settings.contains(keywordWithPrefix)) + { + QVariant val = settings.value(keywordWithPrefix); + fieldHandle->setValueFromUi(val); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void Settings::writeFieldsToApplicationStore(caf::PdmObject* object) +{ + assert(object); + + // Qt doc : + // + // Constructs a QSettings object for accessing settings of the application and organization + // set previously with a call to QCoreApplication::setOrganizationName(), + // QCoreApplication::setOrganizationDomain(), and QCoreApplication::setApplicationName(). + QSettings settings; + + QString prefix = object->classKeyword(); + if (!prefix.isEmpty()) + { + prefix += "/"; + } + + std::vector fields; + object->fields(fields); + + size_t i; + for (i = 0; i < fields.size(); i++) + { + caf::PdmFieldHandle* fieldHandle = fields[i]; + + QString keywordWithPrefix = prefix + fieldHandle->keyword(); + settings.setValue(keywordWithPrefix, fieldHandle->uiValue()); + } +} + + +} // namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmSettings.h b/Fwk/AppFwk/cafUserInterface/cafPdmSettings.h new file mode 100644 index 0000000000..2342eacd71 --- /dev/null +++ b/Fwk/AppFwk/cafUserInterface/cafPdmSettings.h @@ -0,0 +1,55 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2013 Ceetron AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + + +#pragma once + +#include + +namespace caf +{ + + class PdmObject; + +class Settings +{ +public: + static void readFieldsFromApplicationStore(caf::PdmObject* object); + static void writeFieldsToApplicationStore(caf::PdmObject* object); +}; + + +} // end namespace caf From 5961b267b62f5285f5176335e0a37fb41419fa26 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 10:30:58 +0100 Subject: [PATCH 25/51] Added mock model settings --- .../ProjectDataModel/CMakeLists_files.cmake | 2 + .../ProjectDataModel/RimMockModelSettings.cpp | 73 +++++++++++++++++++ .../ProjectDataModel/RimMockModelSettings.h | 52 +++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp create mode 100644 ApplicationCode/ProjectDataModel/RimMockModelSettings.h diff --git a/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake b/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake index d1eba17c50..4e0d185f37 100644 --- a/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake +++ b/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake @@ -46,6 +46,7 @@ ${CEE_CURRENT_LIST_DIR}RimCommandObject.h ${CEE_CURRENT_LIST_DIR}RimTools.h ${CEE_CURRENT_LIST_DIR}RimFault.h ${CEE_CURRENT_LIST_DIR}RimFaultCollection.h +${CEE_CURRENT_LIST_DIR}RimMockModelSettings.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -90,6 +91,7 @@ ${CEE_CURRENT_LIST_DIR}RimCommandObject.cpp ${CEE_CURRENT_LIST_DIR}RimTools.cpp ${CEE_CURRENT_LIST_DIR}RimFault.cpp ${CEE_CURRENT_LIST_DIR}RimFaultCollection.cpp +${CEE_CURRENT_LIST_DIR}RimMockModelSettings.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp b/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp new file mode 100644 index 0000000000..3e032f107a --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp @@ -0,0 +1,73 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RiaStdInclude.h" + + +#include "RimMockModelSettings.h" + + + + +CAF_PDM_SOURCE_INIT(RimMockModelSettings, "MockModelSettings"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimMockModelSettings::RimMockModelSettings() +{ + CAF_PDM_InitObject("Mock Model Settings", "", "", ""); + + CAF_PDM_InitField(&cellCountX, "CellCountX", quint64(100), "Cell Count X", "", "", ""); + CAF_PDM_InitField(&cellCountY, "CellCountY", quint64(100), "Cell Count Y", "", "", ""); + CAF_PDM_InitField(&cellCountZ, "CellCountZ", quint64(100), "Cell Count Z", "", "", ""); + + CAF_PDM_InitFieldNoDefault(&totalCellCount, "TotalCellCount", "Total Cell Count", "", "", ""); + totalCellCount.setUiReadOnly(true); + + CAF_PDM_InitField(&resultCount, "ResultCount", quint64(3), "Result Count", "", "", ""); + CAF_PDM_InitField(&timeStepCount, "TimeStepCount", quint64(10), "Time Step Count", "", "", ""); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimMockModelSettings::~RimMockModelSettings() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimMockModelSettings::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) +{ + totalCellCount = cellCountX * cellCountY * cellCountZ; + totalCellCount.updateConnectedEditors(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimMockModelSettings::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) +{ + caf::PdmUiGroup* gridSizeGroup = uiOrdering.addNewGroup("Grid size"); + gridSizeGroup->add(&cellCountX); + gridSizeGroup->add(&cellCountY); + gridSizeGroup->add(&cellCountZ); + gridSizeGroup->add(&totalCellCount); +} diff --git a/ApplicationCode/ProjectDataModel/RimMockModelSettings.h b/ApplicationCode/ProjectDataModel/RimMockModelSettings.h new file mode 100644 index 0000000000..64d1beac66 --- /dev/null +++ b/ApplicationCode/ProjectDataModel/RimMockModelSettings.h @@ -0,0 +1,52 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafPdmField.h" +#include "cafPdmObject.h" +#include "cafPdmPointer.h" + + +//================================================================================================== +/// +/// +//================================================================================================== +class RimMockModelSettings : public caf::PdmObject +{ + CAF_PDM_HEADER_INIT; +public: + + RimMockModelSettings(); + virtual ~RimMockModelSettings(); + + caf::PdmField cellCountX; + caf::PdmField cellCountY; + caf::PdmField cellCountZ; + + caf::PdmField totalCellCount; + + caf::PdmField resultCount; + caf::PdmField timeStepCount; + + + virtual void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ); + + virtual void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ); + +}; From 7ffe48bff9e7cd7919ecab686d03c17553199503 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 10:31:46 +0100 Subject: [PATCH 26/51] Added flag to control adding of well data --- .../ReservoirDataModel/RigReservoirBuilderMock.cpp | 11 ++++++++++- .../ReservoirDataModel/RigReservoirBuilderMock.h | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp index 0905772400..116dc4e8d3 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp +++ b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp @@ -34,6 +34,7 @@ RigReservoirBuilderMock::RigReservoirBuilderMock() m_resultCount = 0; m_timeStepCount = 0; m_gridPointDimensions = cvf::Vec3st::ZERO; + m_enableWellData = true; } //-------------------------------------------------------------------------------------------------- @@ -246,7 +247,10 @@ void RigReservoirBuilderMock::populateReservoir(RigCaseData* eclipseCase) eclipseCase->mainGrid()->setGridPointDimensions(m_gridPointDimensions); - addWellData(eclipseCase, eclipseCase->mainGrid()); + if (m_enableWellData) + { + addWellData(eclipseCase, eclipseCase->mainGrid()); + } addFaults(eclipseCase); @@ -521,3 +525,8 @@ void RigReservoirBuilderMock::addFaults(RigCaseData* eclipseCase) grid->setFaults(faults); } +void RigReservoirBuilderMock::enableWellData(bool enableWellData) +{ + m_enableWellData = false; +} + diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.h b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.h index 619fb0069a..7076027264 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.h +++ b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.h @@ -48,6 +48,7 @@ public: void setWorldCoordinates(cvf::Vec3d minWorldCoordinate, cvf::Vec3d maxWorldCoordinate); void setGridPointDimensions(const cvf::Vec3st& gridPointDimensions); void setResultInfo(size_t resultCount, size_t timeStepCount); + void enableWellData(bool enableWellData); size_t resultCount() const { return m_resultCount; } size_t timeStepCount() const { return m_timeStepCount; } @@ -91,6 +92,7 @@ private: cvf::Vec3st m_gridPointDimensions; size_t m_resultCount; size_t m_timeStepCount; + bool m_enableWellData; std::vector m_localGridRefinements; }; From ae9f72912eb2152c2b6adff6f46722c656a7a03b Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 10:32:24 +0100 Subject: [PATCH 27/51] Added customized mock model to user interface --- .../Application/RiaApplication.cpp | 11 +++++++- ApplicationCode/Application/RiaApplication.h | 1 + .../FileInterface/RifReaderMockModel.cpp | 8 ++++++ .../FileInterface/RifReaderMockModel.h | 1 + ApplicationCode/ProjectDataModel/RimDefines.h | 1 + .../ProjectDataModel/RimInputCase.cpp | 6 ++--- .../ProjectDataModel/RimResultCase.cpp | 27 +++++++++++++++++++ .../UserInterface/RiuMainWindow.cpp | 15 ++++++++--- ApplicationCode/UserInterface/RiuMainWindow.h | 2 ++ 9 files changed, 64 insertions(+), 8 deletions(-) diff --git a/ApplicationCode/Application/RiaApplication.cpp b/ApplicationCode/Application/RiaApplication.cpp index 9ff31cc740..d029af322f 100644 --- a/ApplicationCode/Application/RiaApplication.cpp +++ b/ApplicationCode/Application/RiaApplication.cpp @@ -719,12 +719,21 @@ void RiaApplication::createLargeResultsMockModel() openEclipseCase(RimDefines::mockModelLargeWithResults(), RimDefines::mockModelLargeWithResults()); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaApplication::createMockModelCustomized() +{ + openEclipseCase(RimDefines::mockModelCustomized(), RimDefines::mockModelCustomized()); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiaApplication::createInputMockModel() { - openInputEclipseCaseFromFileNames(QStringList("Input Mock Debug Model Simple")); + openInputEclipseCaseFromFileNames(QStringList(RimDefines::mockModelBasicInputCase())); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Application/RiaApplication.h b/ApplicationCode/Application/RiaApplication.h index 5688087195..f026d613b6 100644 --- a/ApplicationCode/Application/RiaApplication.h +++ b/ApplicationCode/Application/RiaApplication.h @@ -81,6 +81,7 @@ public: void createMockModel(); void createResultsMockModel(); void createLargeResultsMockModel(); + void createMockModelCustomized(); void createInputMockModel(); QString defaultFileDialogDirectory(const QString& dialogName); diff --git a/ApplicationCode/FileInterface/RifReaderMockModel.cpp b/ApplicationCode/FileInterface/RifReaderMockModel.cpp index f03a79e40f..64507ebc8d 100644 --- a/ApplicationCode/FileInterface/RifReaderMockModel.cpp +++ b/ApplicationCode/FileInterface/RifReaderMockModel.cpp @@ -175,3 +175,11 @@ void RifReaderMockModel::populateReservoir(RigCaseData* eclipseCase) m_reservoirBuilder.populateReservoir(eclipseCase); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RifReaderMockModel::enableWellData(bool enableWellData) +{ + m_reservoirBuilder.enableWellData(enableWellData); +} + diff --git a/ApplicationCode/FileInterface/RifReaderMockModel.h b/ApplicationCode/FileInterface/RifReaderMockModel.h index 0237381bbe..3acd5a7c7b 100644 --- a/ApplicationCode/FileInterface/RifReaderMockModel.h +++ b/ApplicationCode/FileInterface/RifReaderMockModel.h @@ -30,6 +30,7 @@ public: void setWorldCoordinates(cvf::Vec3d minWorldCoordinate, cvf::Vec3d maxWorldCoordinate); void setGridPointDimensions(const cvf::Vec3st& gridPointDimensions); void setResultInfo(size_t resultCount, size_t timeStepCount); + void enableWellData(bool enableWellData); void addLocalGridRefinement(const cvf::Vec3st& minCellPosition, const cvf::Vec3st& maxCellPosition, const cvf::Vec3st& singleCellRefinementFactors); diff --git a/ApplicationCode/ProjectDataModel/RimDefines.h b/ApplicationCode/ProjectDataModel/RimDefines.h index cfb31f48ad..0dd82175f1 100644 --- a/ApplicationCode/ProjectDataModel/RimDefines.h +++ b/ApplicationCode/ProjectDataModel/RimDefines.h @@ -48,6 +48,7 @@ public: static QString mockModelBasic() { return "Result Mock Debug Model Simple"; } static QString mockModelBasicWithResults() { return "Result Mock Debug Model With Results"; } static QString mockModelLargeWithResults() { return "Result Mock Debug Model Large With Results"; } + static QString mockModelCustomized() { return "Result Mock Debug Model Customized"; } static QString mockModelBasicInputCase() { return "Input Mock Debug Model Simple"; } }; diff --git a/ApplicationCode/ProjectDataModel/RimInputCase.cpp b/ApplicationCode/ProjectDataModel/RimInputCase.cpp index ddfa4876fe..e9ab1a607f 100644 --- a/ApplicationCode/ProjectDataModel/RimInputCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimInputCase.cpp @@ -77,7 +77,7 @@ RimInputCase::~RimInputCase() //-------------------------------------------------------------------------------------------------- void RimInputCase::openDataFileSet(const QStringList& fileNames) { - if (fileNames.contains("Input Mock Debug Model Simple")) + if (fileNames.contains(RimDefines::mockModelBasicInputCase())) { cvf::ref readerInterface = this->createMockModel(fileNames[0]); results(RifReaderInterface::MATRIX_RESULTS)->setReaderInterface(readerInterface.p()); @@ -184,7 +184,7 @@ bool RimInputCase::openEclipseGridFile() { cvf::ref readerInterface; - if (m_gridFileName().contains("Input Mock Debug Model Simple")) + if (m_gridFileName().contains(RimDefines::mockModelBasicInputCase())) { readerInterface = this->createMockModel(this->m_gridFileName()); } @@ -377,7 +377,7 @@ cvf::ref RimInputCase::createMockModel(QString modelName) cvf::ref reservoir = new RigCaseData; cvf::ref mockFileInterface = new RifReaderMockModel; - if (modelName == "Input Mock Debug Model Simple") + if (modelName == RimDefines::mockModelBasicInputCase()) { m_gridFileName = modelName; diff --git a/ApplicationCode/ProjectDataModel/RimResultCase.cpp b/ApplicationCode/ProjectDataModel/RimResultCase.cpp index 558245c5f6..d13fddbc2f 100644 --- a/ApplicationCode/ProjectDataModel/RimResultCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimResultCase.cpp @@ -45,6 +45,7 @@ #include "RimOilField.h" #include "RimAnalysisModels.h" #include "RiaPreferences.h" +#include "RimMockModelSettings.h" CAF_PDM_SOURCE_INIT(RimResultCase, "EclipseCase"); //-------------------------------------------------------------------------------------------------- @@ -262,6 +263,32 @@ cvf::ref RimResultCase::createMockModel(QString modelName) mockFileInterface->open("", reservoir.p()); } + else if (modelName == RimDefines::mockModelCustomized()) + { + RimMockModelSettings rimMockModelSettings; + + //caf::Settings::readFieldsFromApplicationStore(&rimMockModelSettings); + + double startX = 0; + double startY = 0; + double startZ = 0; + + double widthX = 6000; + double widthY = 12000; + double widthZ = 500; + + // Test code to simulate UTM coordinates + double offsetX = 400000; + double offsetY = 6000000; + double offsetZ = 0; + + mockFileInterface->setWorldCoordinates(cvf::Vec3d(startX + offsetX, startY + offsetY, startZ + offsetZ), cvf::Vec3d(startX + widthX + offsetX, startY + widthY + offsetY, startZ + widthZ + offsetZ)); + mockFileInterface->setGridPointDimensions(cvf::Vec3st(rimMockModelSettings.cellCountX, rimMockModelSettings.cellCountX, rimMockModelSettings.cellCountX)); + mockFileInterface->setResultInfo(rimMockModelSettings.resultCount, rimMockModelSettings.timeStepCount); + mockFileInterface->enableWellData(false); + + mockFileInterface->open("", reservoir.p()); + } this->setReservoirData( reservoir.p() ); diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index dd1e7090c2..2e39767fc2 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -199,6 +199,7 @@ void RiuMainWindow::createActions() m_mockModelAction = new QAction("&Mock Model", this); m_mockResultsModelAction = new QAction("Mock Model With &Results", this); m_mockLargeResultsModelAction = new QAction("Large Mock Model", this); + m_mockModelCustomizedAction = new QAction("Customized Mock Model", this); m_mockInputModelAction = new QAction("Input Mock Model", this); m_snapshotToFile = new QAction(QIcon(":/SnapShotSave.png"), "Snapshot To File", this); @@ -226,6 +227,7 @@ void RiuMainWindow::createActions() connect(m_mockModelAction, SIGNAL(triggered()), SLOT(slotMockModel())); connect(m_mockResultsModelAction, SIGNAL(triggered()), SLOT(slotMockResultsModel())); connect(m_mockLargeResultsModelAction, SIGNAL(triggered()), SLOT(slotMockLargeResultsModel())); + connect(m_mockModelCustomizedAction, SIGNAL(triggered()), SLOT(slotMockModelCustomized())); connect(m_mockInputModelAction, SIGNAL(triggered()), SLOT(slotInputMockModel())); connect(m_snapshotToFile, SIGNAL(triggered()), SLOT(slotSnapshotToFile())); @@ -386,6 +388,7 @@ void RiuMainWindow::createMenus() testMenu->addAction(m_mockModelAction); testMenu->addAction(m_mockResultsModelAction); testMenu->addAction(m_mockLargeResultsModelAction); + testMenu->addAction(m_mockModelCustomizedAction); testMenu->addAction(m_mockInputModelAction); testMenu->addSeparator(); testMenu->addAction(m_createCommandObject); @@ -845,8 +848,6 @@ void RiuMainWindow::slotMockModel() { RiaApplication* app = RiaApplication::instance(); app->createMockModel(); - - //m_mainViewer->setDefaultView(); } //-------------------------------------------------------------------------------------------------- @@ -856,8 +857,6 @@ void RiuMainWindow::slotMockResultsModel() { RiaApplication* app = RiaApplication::instance(); app->createResultsMockModel(); - - //m_mainViewer->setDefaultView(); } @@ -870,6 +869,14 @@ void RiuMainWindow::slotMockLargeResultsModel() app->createLargeResultsMockModel(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuMainWindow::slotMockModelCustomized() +{ + RiaApplication* app = RiaApplication::instance(); + app->createMockModelCustomized(); +} //-------------------------------------------------------------------------------------------------- /// diff --git a/ApplicationCode/UserInterface/RiuMainWindow.h b/ApplicationCode/UserInterface/RiuMainWindow.h index 2b92f9a7b4..ae3f922af3 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.h +++ b/ApplicationCode/UserInterface/RiuMainWindow.h @@ -154,6 +154,7 @@ private: QAction* m_mockModelAction; QAction* m_mockResultsModelAction; QAction* m_mockLargeResultsModelAction; + QAction* m_mockModelCustomizedAction; QAction* m_mockInputModelAction; QAction* m_snapshotToFile; @@ -243,6 +244,7 @@ private slots: void slotMockModel(); void slotMockResultsModel(); void slotMockLargeResultsModel(); + void slotMockModelCustomized(); void slotInputMockModel(); // Windows slots From c9116070de3420a1443c57473be0bddd023fe47e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 11:55:34 +0100 Subject: [PATCH 28/51] Added default editor for quint64 --- Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp index 822d2c3185..5bfee7de4f 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp @@ -65,10 +65,11 @@ CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, QString); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, int); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, double); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, float); +CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiLineEditor, quint64); + CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector); - CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector); From 4300e746749eceee4d121e5d7896a07fdabeba46 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 11:58:49 +0100 Subject: [PATCH 29/51] Added property dialog --- Fwk/AppFwk/cafUserInterface/CMakeLists.txt | 3 + .../cafPdmUiPropertyDialog.cpp | 92 +++++++++++++++++++ .../cafUserInterface/cafPdmUiPropertyDialog.h | 70 ++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.cpp create mode 100644 Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.h diff --git a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt index b09a2f49a1..b210e4a322 100644 --- a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt +++ b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt @@ -25,6 +25,7 @@ set( QOBJECT_HEADERS cafPdmUiColorEditor.h cafPdmUiPropertyView.h + cafPdmUiPropertyDialog.h cafPdmUiTreeView.h cafPdmUiTreeViewModel.h cafPdmUiListView.h @@ -59,6 +60,8 @@ add_library( ${PROJECT_NAME} cafPdmUiListViewEditor.cpp cafPdmUiListViewEditor.h cafPdmUiListView.cpp + cafPdmUiPropertyDialog.cpp + cafPdmUiPropertyDialog.h cafPdmUiPropertyView.cpp cafPdmUiPropertyView.h cafPdmUiPushButtonEditor.cpp diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.cpp new file mode 100644 index 0000000000..277dc3153d --- /dev/null +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.cpp @@ -0,0 +1,92 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2013 Ceetron AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + + +#include "cafPdmUiPropertyDialog.h" + +#include "cafPdmObject.h" +#include "cafPdmUiPropertyView.h" + +#include +#include + +#include + + + +namespace caf { + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +PdmUiPropertyDialog::PdmUiPropertyDialog(QWidget* parent, caf::PdmObject* object, const QString& windowTitle) + : QDialog(parent) +{ + assert(object); + + m_pdmObject = object; + m_windowTitle = windowTitle; + + setupUi(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiPropertyDialog::setupUi() +{ + setWindowTitle(m_windowTitle); + + m_pdmUiPropertyView = new caf::PdmUiPropertyView(this); + + QVBoxLayout* dialogLayout = new QVBoxLayout; + setLayout(dialogLayout); + + dialogLayout->addWidget(m_pdmUiPropertyView); + m_pdmUiPropertyView->showProperties(m_pdmObject); + + // Buttons + QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + dialogLayout->addWidget(buttonBox); + + this->resize(400, 200); +} + + +} // end namespace caf diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.h new file mode 100644 index 0000000000..4c4ca7b797 --- /dev/null +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiPropertyDialog.h @@ -0,0 +1,70 @@ +//################################################################################################## +// +// Custom Visualization Core library +// Copyright (C) 2011-2013 Ceetron AS +// +// This library may be used under the terms of either the GNU General Public License or +// the GNU Lesser General Public License as follows: +// +// GNU General Public License Usage +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at <> +// for more details. +// +// GNU Lesser General Public License Usage +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU Lesser General Public License at <> +// for more details. +// +//################################################################################################## + + +#pragma once + +#include + +namespace caf +{ + class PdmObject; + class PdmUiPropertyView; + + +//================================================================================================== +// +// +// +//================================================================================================== +class PdmUiPropertyDialog : public QDialog +{ + Q_OBJECT + +public: + PdmUiPropertyDialog(QWidget* parent, caf::PdmObject* object, const QString& windowTitle); + +private: + void setupUi(); + +private: + QString m_windowTitle; + caf::PdmObject* m_pdmObject; + caf::PdmUiPropertyView* m_pdmUiPropertyView; +}; + + +} // end namespace caf From 6e3860571ecb350320462244760349723f11fc46 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 12:05:06 +0100 Subject: [PATCH 30/51] Improved mock model settings and use caf property dialog --- .../ProjectDataModel/RimMockModelSettings.cpp | 6 +- .../ProjectDataModel/RimResultCase.cpp | 56 ++++++++++++------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp b/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp index 3e032f107a..1266629d4e 100644 --- a/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp +++ b/ApplicationCode/ProjectDataModel/RimMockModelSettings.cpp @@ -35,7 +35,7 @@ RimMockModelSettings::RimMockModelSettings() CAF_PDM_InitField(&cellCountX, "CellCountX", quint64(100), "Cell Count X", "", "", ""); CAF_PDM_InitField(&cellCountY, "CellCountY", quint64(100), "Cell Count Y", "", "", ""); - CAF_PDM_InitField(&cellCountZ, "CellCountZ", quint64(100), "Cell Count Z", "", "", ""); + CAF_PDM_InitField(&cellCountZ, "CellCountZ", quint64(10), "Cell Count Z", "", "", ""); CAF_PDM_InitFieldNoDefault(&totalCellCount, "TotalCellCount", "Total Cell Count", "", "", ""); totalCellCount.setUiReadOnly(true); @@ -70,4 +70,8 @@ void RimMockModelSettings::defineUiOrdering(QString uiConfigName, caf::PdmUiOrde gridSizeGroup->add(&cellCountY); gridSizeGroup->add(&cellCountZ); gridSizeGroup->add(&totalCellCount); + + caf::PdmUiGroup* resultGroup = uiOrdering.addNewGroup("Results"); + resultGroup->add(&resultCount); + resultGroup->add(&timeStepCount); } diff --git a/ApplicationCode/ProjectDataModel/RimResultCase.cpp b/ApplicationCode/ProjectDataModel/RimResultCase.cpp index d13fddbc2f..a392121b5f 100644 --- a/ApplicationCode/ProjectDataModel/RimResultCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimResultCase.cpp @@ -17,6 +17,13 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RiaStdInclude.h" + +#include "cafProgressInfo.h" +#include "cafPdmSettings.h" +#include "cafPdmFieldCvfMat4d.h" +#include "cafPdmFieldCvfColor.h" +#include "cafPdmUiPropertyDialog.h" + #include "RimResultCase.h" #include "RigCaseData.h" #include "RifReaderEclipseOutput.h" @@ -24,7 +31,7 @@ #include "RimReservoirView.h" #include "RifReaderMockModel.h" #include "RifReaderEclipseInput.h" -#include "cafProgressInfo.h" + #include "RimProject.h" #include "RifEclipseOutputFileTools.h" #include "RiaApplication.h" @@ -34,8 +41,6 @@ #include "RimReservoirCellResultsCacher.h" #include "RimWellPathCollection.h" -#include "cafPdmFieldCvfMat4d.h" -#include "cafPdmFieldCvfColor.h" #include "RimResultSlot.h" #include "RimCellEdgeResultSlot.h" #include "RimCellRangeFilterCollection.h" @@ -265,29 +270,42 @@ cvf::ref RimResultCase::createMockModel(QString modelName) } else if (modelName == RimDefines::mockModelCustomized()) { + QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); + RimMockModelSettings rimMockModelSettings; + caf::Settings::readFieldsFromApplicationStore(&rimMockModelSettings); - //caf::Settings::readFieldsFromApplicationStore(&rimMockModelSettings); + caf::PdmUiPropertyDialog propertyDialog(NULL, &rimMockModelSettings, "Customize Mock Model"); + if (propertyDialog.exec() == QDialog::Accepted) + { + QApplication::restoreOverrideCursor(); - double startX = 0; - double startY = 0; - double startZ = 0; + caf::Settings::writeFieldsToApplicationStore(&rimMockModelSettings); - double widthX = 6000; - double widthY = 12000; - double widthZ = 500; + double startX = 0; + double startY = 0; + double startZ = 0; - // Test code to simulate UTM coordinates - double offsetX = 400000; - double offsetY = 6000000; - double offsetZ = 0; + double widthX = 6000; + double widthY = 12000; + double widthZ = 500; - mockFileInterface->setWorldCoordinates(cvf::Vec3d(startX + offsetX, startY + offsetY, startZ + offsetZ), cvf::Vec3d(startX + widthX + offsetX, startY + widthY + offsetY, startZ + widthZ + offsetZ)); - mockFileInterface->setGridPointDimensions(cvf::Vec3st(rimMockModelSettings.cellCountX, rimMockModelSettings.cellCountX, rimMockModelSettings.cellCountX)); - mockFileInterface->setResultInfo(rimMockModelSettings.resultCount, rimMockModelSettings.timeStepCount); - mockFileInterface->enableWellData(false); + // Test code to simulate UTM coordinates + double offsetX = 400000; + double offsetY = 6000000; + double offsetZ = 0; - mockFileInterface->open("", reservoir.p()); + mockFileInterface->setWorldCoordinates(cvf::Vec3d(startX + offsetX, startY + offsetY, startZ + offsetZ), cvf::Vec3d(startX + widthX + offsetX, startY + widthY + offsetY, startZ + widthZ + offsetZ)); + mockFileInterface->setGridPointDimensions(cvf::Vec3st(rimMockModelSettings.cellCountX + 1, rimMockModelSettings.cellCountY + 1, rimMockModelSettings.cellCountZ + 1)); + mockFileInterface->setResultInfo(rimMockModelSettings.resultCount, rimMockModelSettings.timeStepCount); + mockFileInterface->enableWellData(false); + + mockFileInterface->open("", reservoir.p()); + } + else + { + QApplication::restoreOverrideCursor(); + } } this->setReservoirData( reservoir.p() ); From 4aeac9197bea6cfe44470ac3d3f05d3afe80068e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 28 Oct 2013 12:50:39 +0100 Subject: [PATCH 31/51] Use caf property dialog and removed obsolete riuPreferencesDialog --- ApplicationCode/CMakeLists.txt | 2 - .../ProjectDataModel/RimUiTreeView.cpp | 15 ++--- .../UserInterface/RiuMainWindow.cpp | 8 +-- .../UserInterface/RiuPreferencesDialog.cpp | 67 ------------------- .../UserInterface/RiuPreferencesDialog.h | 49 -------------- 5 files changed, 11 insertions(+), 130 deletions(-) delete mode 100644 ApplicationCode/UserInterface/RiuPreferencesDialog.cpp delete mode 100644 ApplicationCode/UserInterface/RiuPreferencesDialog.h diff --git a/ApplicationCode/CMakeLists.txt b/ApplicationCode/CMakeLists.txt index d5fea80758..29c2db248b 100644 --- a/ApplicationCode/CMakeLists.txt +++ b/ApplicationCode/CMakeLists.txt @@ -43,7 +43,6 @@ set( APPLICATION_FILES set( USER_INTERFACE_FILES UserInterface/RiuCursors.cpp UserInterface/RiuMainWindow.cpp - UserInterface/RiuPreferencesDialog.cpp UserInterface/RiuResultInfoPanel.cpp UserInterface/RiuViewer.cpp UserInterface/RiuSimpleHistogramWidget.cpp @@ -98,7 +97,6 @@ set ( QT_MOC_HEADERS ProjectDataModel/RimMimeData.h UserInterface/RiuMainWindow.h - UserInterface/RiuPreferencesDialog.h UserInterface/RiuResultInfoPanel.h UserInterface/RiuViewer.h UserInterface/RiuProcessMonitor.h diff --git a/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp b/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp index 272c7cca9b..690c0bdfa7 100644 --- a/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp +++ b/ApplicationCode/ProjectDataModel/RimUiTreeView.cpp @@ -19,6 +19,9 @@ //#include "RiaStdInclude.h" #include "cafPdmDocument.h" +#include "cafPdmFieldCvfColor.h" +#include "cafPdmFieldCvfMat4d.h" +#include "cafPdmUiPropertyDialog.h" #include #include @@ -37,7 +40,6 @@ #include "RimInputPropertyCollection.h" #include "RimExportInputPropertySettings.h" #include "RiaPreferences.h" -#include "RiuPreferencesDialog.h" #include "RifEclipseInputFileTools.h" #include "RimInputCase.h" #include "RimBinaryExportSettings.h" @@ -59,9 +61,6 @@ #include "RimWellPathCollection.h" #include "RimReservoirCellResultsCacher.h" #include "Rim3dOverlayInfoConfig.h" - -#include "cafPdmFieldCvfColor.h" -#include "cafPdmFieldCvfMat4d.h" #include "RimProject.h" #include "RimOilField.h" #include "RimAnalysisModels.h" @@ -834,8 +833,8 @@ void RimUiTreeView::slotWriteInputProperty() exportSettings.fileName = outputFileName; } - RiuPreferencesDialog preferencesDialog(this, &exportSettings, "Export Eclipse Property to Text File"); - if (preferencesDialog.exec() == QDialog::Accepted) + caf::PdmUiPropertyDialog propertyDialog(this, &exportSettings, "Export Eclipse Property to Text File"); + if (propertyDialog.exec() == QDialog::Accepted) { bool isOk = RifEclipseInputFileTools::writePropertyToTextFile(exportSettings.fileName, inputReservoir->reservoirData(), 0, inputProperty->resultName, exportSettings.eclipseKeyword); if (isOk) @@ -887,8 +886,8 @@ void RimUiTreeView::slotWriteBinaryResultAsInputProperty() exportSettings.fileName = outputFileName; } - RiuPreferencesDialog preferencesDialog(this, &exportSettings, "Export Binary Eclipse Data to Text File"); - if (preferencesDialog.exec() == QDialog::Accepted) + caf::PdmUiPropertyDialog propertyDialog(this, &exportSettings, "Export Binary Eclipse Data to Text File"); + if (propertyDialog.exec() == QDialog::Accepted) { size_t timeStep = resultSlot->reservoirView()->currentTimeStep(); RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(resultSlot->porosityModel()); diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index 2e39767fc2..103a853f52 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -43,7 +43,6 @@ #include "RiuMultiCaseImportDialog.h" #include "RiaPreferences.h" -#include "RiuPreferencesDialog.h" #include "RigCaseCellResultsData.h" @@ -63,6 +62,7 @@ #include "RimCalcScript.h" #include "RimTools.h" #include "RiaRegressionTest.h" +#include "cafPdmUiPropertyDialog.h" @@ -1223,8 +1223,8 @@ void RiuMainWindow::slotShowPerformanceInfo(bool enable) void RiuMainWindow::slotEditPreferences() { RiaApplication* app = RiaApplication::instance(); - RiuPreferencesDialog preferencesDialog(this, app->preferences(), "Preferences"); - if (preferencesDialog.exec() == QDialog::Accepted) + caf::PdmUiPropertyDialog propertyDialog(this, app->preferences(), "Preferences"); + if (propertyDialog.exec() == QDialog::Accepted) { // Write preferences using QSettings and apply them to the application app->writeFieldsToApplicationStore(app->preferences()); @@ -1772,7 +1772,7 @@ void RiuMainWindow::slotShowRegressionTestDialog() RiaApplication* app = RiaApplication::instance(); app->readFieldsFromApplicationStore(®TestConfig); - RiuPreferencesDialog regressionTestDialog(this, ®TestConfig, "Regression Test"); + caf::PdmUiPropertyDialog regressionTestDialog(this, ®TestConfig, "Regression Test"); if (regressionTestDialog.exec() == QDialog::Accepted) { // Write preferences using QSettings and apply them to the application diff --git a/ApplicationCode/UserInterface/RiuPreferencesDialog.cpp b/ApplicationCode/UserInterface/RiuPreferencesDialog.cpp deleted file mode 100644 index 7a094776c8..0000000000 --- a/ApplicationCode/UserInterface/RiuPreferencesDialog.cpp +++ /dev/null @@ -1,67 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS -// -// ResInsight is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. -// -// See the GNU General Public License at -// for more details. -// -///////////////////////////////////////////////////////////////////////////////// - -#include "RiaStdInclude.h" -#include "RiuPreferencesDialog.h" - -#include "cafAppEnum.h" -#include "cafPdmObject.h" - -#include "RimUiTreeModelPdm.h" -#include "cafPdmUiPropertyView.h" - - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RiuPreferencesDialog::RiuPreferencesDialog(QWidget* parent, caf::PdmObject* object, const QString& windowTitle) - : QDialog(parent) -{ - CVF_ASSERT(object); - - m_pdmObject = object; - m_windowTitle = windowTitle; - - setupUi(); -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuPreferencesDialog::setupUi() -{ - setWindowTitle(m_windowTitle); - - m_pdmUiPropertyView = new caf::PdmUiPropertyView(this); - - QVBoxLayout* dialogLayout = new QVBoxLayout; - setLayout(dialogLayout); - - dialogLayout->addWidget(m_pdmUiPropertyView); - m_pdmUiPropertyView->showProperties(m_pdmObject); - - // Buttons - QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); - connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); - - dialogLayout->addWidget(buttonBox); - - this->resize(400, 200); -} diff --git a/ApplicationCode/UserInterface/RiuPreferencesDialog.h b/ApplicationCode/UserInterface/RiuPreferencesDialog.h deleted file mode 100644 index 3751e108fb..0000000000 --- a/ApplicationCode/UserInterface/RiuPreferencesDialog.h +++ /dev/null @@ -1,49 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////// -// -// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS -// -// ResInsight is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. -// -// See the GNU General Public License at -// for more details. -// -///////////////////////////////////////////////////////////////////////////////// - -#pragma once - -#include - -namespace caf -{ - class PdmObject; - class PdmUiPropertyView; -} - - -//================================================================================================== -// -// -// -//================================================================================================== -class RiuPreferencesDialog : public QDialog -{ - Q_OBJECT - -public: - RiuPreferencesDialog(QWidget* parent, caf::PdmObject* object, const QString& windowTitle); - -private: - void setupUi(); - -private: - QString m_windowTitle; - caf::PdmObject* m_pdmObject; - caf::PdmUiPropertyView* m_pdmUiPropertyView; -}; From 60ff9c5a2ba9bb735b3bdec11b8b851647d304c5 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 8 Nov 2013 10:34:05 +0100 Subject: [PATCH 32/51] Performance: Added OpenMP to mock models --- .../RigReservoirBuilderMock.cpp | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp index 116dc4e8d3..f62e9c90c6 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp +++ b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp @@ -135,10 +135,14 @@ void RigReservoirBuilderMock::appendCubeNodes(const cvf::Vec3d& min, const cvf:: void RigReservoirBuilderMock::appendCells(size_t nodeStartIndex, size_t cellCount, RigGridBase* hostGrid, std::vector& cells) { size_t activeCellIndex = 0; - size_t i; - for (i = 0; i < cellCount; i++) + long long i; + + cells.resize(cellCount); + +#pragma omp parallel for + for (i = 0; i < static_cast(cellCount); i++) { - RigCell riCell; + RigCell& riCell = cells[i]; riCell.setHostGrid(hostGrid); riCell.setCellIndex(i); @@ -165,8 +169,6 @@ void RigReservoirBuilderMock::appendCells(size_t nodeStartIndex, size_t cellCoun riCell.setActiveIndexInMatrixModel(activeCellIndex++); } */ - - cells.push_back(riCell); } } @@ -350,13 +352,15 @@ bool RigReservoirBuilderMock::dynamicResult(RigCaseData* eclipseCase, const QStr double scaleValue = 1.0 + resultIndex * 0.1; double offsetValue = 100 * resultIndex; - size_t k; - for (k = 0; k < eclipseCase->mainGrid()->cells().size(); k++) + values->resize(eclipseCase->mainGrid()->cells().size()); + +#pragma omp parallel for + for (long long k = 0; k < static_cast(eclipseCase->mainGrid()->cells().size()); k++) { RigCell& cell = eclipseCase->mainGrid()->cells()[k]; { double val = offsetValue + scaleValue * ( (stepIndex * 1000 + k) % eclipseCase->mainGrid()->cells().size() ); - values->push_back(val); + values->at(k) = val; } } From b9b5441bdb5f060a7d8354104a25f29b059abf7b Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 8 Nov 2013 14:27:21 +0100 Subject: [PATCH 33/51] Performance: Reduce memory use for riGetPropertyData --- .../SocketInterface/RiaPropertyDataCommands.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp index 40dc5d2efd..f31218d7e3 100644 --- a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp @@ -304,10 +304,10 @@ public: quint64 timestepCount = (quint64)requestedTimesteps.size(); socketStream << timestepCount; - size_t doubleValueCount = cellCountI * cellCountJ * cellCountK * timestepCount * sizeof(double); - std::vector values(doubleValueCount); size_t valueIdx = 0; + std::vector values(rigGrid->cellCount()); + for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) { cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); @@ -323,11 +323,11 @@ public: { cellValue = 0.0; } - values[valueIdx++] = cellValue; + values[cellIdx] = cellValue; } - } - server->currentClient()->write((const char *)values.data(), doubleValueCount); + server->currentClient()->write((const char *)values.data(), rigGrid->cellCount() * sizeof(double)); + } return true; } From 7c42bf013869609c4989dc3f7aa82c1f25e1bacf Mon Sep 17 00:00:00 2001 From: magnesj Date: Mon, 11 Nov 2013 14:36:59 +0100 Subject: [PATCH 34/51] Temporarily fixes for handling communication of more than 2GB data to/from octave --- OctavePlugin/riGetActiveCellProperty.cpp | 4 +- OctavePlugin/riGetGridProperty.cpp | 87 +++++++++++++++++++++--- OctavePlugin/riSetGridProperty.cpp | 13 ++-- 3 files changed, 88 insertions(+), 16 deletions(-) diff --git a/OctavePlugin/riGetActiveCellProperty.cpp b/OctavePlugin/riGetActiveCellProperty.cpp index a936b82d96..81b966f7d0 100644 --- a/OctavePlugin/riGetActiveCellProperty.cpp +++ b/OctavePlugin/riGetActiveCellProperty.cpp @@ -67,7 +67,7 @@ void getActiveCellProperty(Matrix& propertyFrames, const QString &serverName, qu for (size_t tIdx = 0; tIdx < timestepCount; ++tIdx) { - while (socket.bytesAvailable() < (int)byteCount) + while (socket.bytesAvailable() < (qint64)byteCount) { if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) { @@ -94,7 +94,7 @@ void getActiveCellProperty(Matrix& propertyFrames, const QString &serverName, qu } #endif - if ((int)byteCount != bytesRead) + if ((qint64)byteCount != bytesRead) { error("Could not read binary double data properly from socket"); octave_stdout << "Active cells: " << activeCellCount << ", Timesteps: " << timestepCount << std::endl; diff --git a/OctavePlugin/riGetGridProperty.cpp b/OctavePlugin/riGetGridProperty.cpp index 3771341644..3b1fbc589f 100644 --- a/OctavePlugin/riGetGridProperty.cpp +++ b/OctavePlugin/riGetGridProperty.cpp @@ -22,7 +22,7 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 QString command; command += "GetGridProperty " + QString::number(caseId) + " " + QString::number(gridIdx) + " " + propertyName + " " + porosityModel; - for (int i = 0; i < requestedTimeSteps.length(); ++i) + for (qint64 i = 0; i < requestedTimeSteps.length(); ++i) { if (i == 0) command += " "; command += QString::number(static_cast(requestedTimeSteps.elem(i)) - 1); // To make the index 0-based @@ -36,7 +36,7 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 // Get response. First wait for the header - while (socket.bytesAvailable() < (int)(4*sizeof(quint64))) + while (socket.bytesAvailable() < (qint64)(4*sizeof(quint64))) { if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) { @@ -48,6 +48,7 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 // Read sizes quint64 totalByteCount; + quint64 cellCountI; quint64 cellCountJ; quint64 cellCountK; @@ -59,6 +60,9 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 socketStream >> timestepCount; totalByteCount = cellCountI*cellCountJ*cellCountK*timestepCount*sizeof(double); + + qint64 timestepByteCount = cellCountI*cellCountJ*cellCountK*sizeof(double); + if (!(totalByteCount)) { error ("Could not find the requested data in ResInsight"); @@ -75,29 +79,92 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 propertyFrames.resize(dv); - // Wait for available data - - while (socket.bytesAvailable() < (int)totalByteCount) +#if 1 + // Wait for available data for each timestep, then read data for each timestep + + qint64 totalBytesRead = 0; + + for (size_t tIdx = 0; tIdx < timestepCount; ++tIdx) { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) + qint64 bytesAvailable = socket.bytesAvailable() ; + + while ( bytesAvailable < (qint64)timestepByteCount) { - error(("Waiting for data : " + socket.errorString()).toLatin1().data()); - return ; + if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) + { + error((("Waiting for timestep data number: ") + QString::number(tIdx)+ ": " + socket.errorString()).toLatin1().data()); + octave_stdout << "Cellcount: " << cellCountI*cellCountJ*cellCountK << ", Timesteps: " << timestepCount << std::endl; + return ; + } + + bytesAvailable = socket.bytesAvailable(); + + OCTAVE_QUIT; } + + qint64 bytesRead = 0; + double * internalMatrixData = propertyFrames.fortran_vec(); + + // Raw data transfer. Faster. Not possible when dealing with coarsening + bytesRead = socket.read(((char*)(internalMatrixData)) + tIdx * timestepByteCount, timestepByteCount); + + if ((qint64)timestepByteCount != bytesRead) + { + error("Could not read binary double data properly from socket"); + octave_stdout << "Cellcount: " << cellCountI*cellCountJ*cellCountK << ", Timesteps count: " << timestepCount << std::endl; + octave_stdout << "Timestep : " << tIdx << std::endl; + } + + totalBytesRead += bytesRead; + + OCTAVE_QUIT; + } + + if ((qint64)totalByteCount != totalBytesRead) + { + error("Could not read binary double data properly from socket"); + } + + #else + + // Wait for available data + qint64 bytesAvailable = socket.bytesAvailable() ; + + while (bytesAvailable < (qint64)totalByteCount) + { + octave_stdout << "Waiting for data. Has : " << bytesAvailable << " Needs :" << totalByteCount << std::endl; + if (!socket.waitForReadyRead(riOctavePlugin::shortTimeOutMilliSecs)) + { + //error(("Waiting for data : " + socket.errorString()).toLatin1().data()); + //return ; + } + + bytesAvailable = socket.bytesAvailable() ; OCTAVE_QUIT; } qint64 bytesRead = 0; double * internalMatrixData = propertyFrames.fortran_vec(); +#if 0 + + char* dataBuffer = new char[totalByteCount]; + bytesRead = socket.read(dataBuffer, totalByteCount); + + +#else + // Raw data transfer. Faster. bytesRead = socket.read((char*)(internalMatrixData ), totalByteCount); +#endif - if ((int)totalByteCount != bytesRead) + + if ((qint64)totalByteCount != bytesRead) { error("Could not read binary double data properly from socket"); } - + +#endif QString tmp = QString("riGetGridProperty : Read %1").arg(propertyName); if (caseId < 0) diff --git a/OctavePlugin/riSetGridProperty.cpp b/OctavePlugin/riSetGridProperty.cpp index 04773e8804..f5afe0a0f7 100644 --- a/OctavePlugin/riSetGridProperty.cpp +++ b/OctavePlugin/riSetGridProperty.cpp @@ -64,8 +64,13 @@ void setEclipseProperty(const NDArray& propertyFrames, const QString &hostName, socketStream << (qint64)singleTimeStepByteCount; const double* internalData = propertyFrames.fortran_vec(); - int dataWritten = socket.write((const char *)internalData, singleTimeStepByteCount*timeStepCount); - + qint64 dataWritten = 0; + + for (size_t tsIdx = 0; tsIdx < timeStepCount; ++tsIdx) + { + dataWritten += socket.write(((const char *)internalData) + tsIdx*singleTimeStepByteCount, singleTimeStepByteCount); + } + if (dataWritten == singleTimeStepByteCount*timeStepCount) { QString tmp = QString("riSetGridProperty : Wrote %1").arg(propertyName); @@ -92,8 +97,8 @@ void setEclipseProperty(const NDArray& propertyFrames, const QString &hostName, while(socket.bytesToWrite() && socket.state() == QAbstractSocket::ConnectedState) { - // octave_stdout << "Bytes to write: " << socket.bytesToWrite() << std::endl; - socket.waitForBytesWritten(riOctavePlugin::longTimeOutMilliSecs); + octave_stdout << "Bytes to write: " << socket.bytesToWrite() << std::endl << std::flush; + socket.waitForBytesWritten(2000); OCTAVE_QUIT; } From 3ec22a92212c54b7f6c502c9c1cb7ce6a4c34aab Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 1 Apr 2014 13:02:52 +0200 Subject: [PATCH 35/51] Added flag to control how to do IO with sockets --- .../Application/RiaPreferences.cpp | 1 + ApplicationCode/Application/RiaPreferences.h | 2 + .../SocketInterface/RiaGeometryCommands.cpp | 68 ++++++++++++++----- .../RiaPropertyDataCommands.cpp | 61 +++++++++++++---- 4 files changed, 102 insertions(+), 30 deletions(-) diff --git a/ApplicationCode/Application/RiaPreferences.cpp b/ApplicationCode/Application/RiaPreferences.cpp index 3e45619055..5c060c7031 100644 --- a/ApplicationCode/Application/RiaPreferences.cpp +++ b/ApplicationCode/Application/RiaPreferences.cpp @@ -60,6 +60,7 @@ RiaPreferences::RiaPreferences(void) CAF_PDM_InitField(&autocomputeDepthRelatedProperties,"autocomputeDepth", true, "DEPTH related properties", "", "DEPTH, DX, DY, DZ, TOP, BOTTOM", ""); CAF_PDM_InitField(&readFaultData, "readFaultData", true, "Read fault data", "", "", ""); + CAF_PDM_InitField(&useStreamTransfer, "useStreamTransfer", true, "Use stream transfer to Octave", "", "", ""); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Application/RiaPreferences.h b/ApplicationCode/Application/RiaPreferences.h index 4623599926..5fcc691d3c 100644 --- a/ApplicationCode/Application/RiaPreferences.h +++ b/ApplicationCode/Application/RiaPreferences.h @@ -60,6 +60,8 @@ public: // Pdm Fields caf::PdmField readFaultData; + caf::PdmField useStreamTransfer; + protected: virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute); diff --git a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp index 2ec5878cb6..413f4791bc 100644 --- a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp @@ -34,6 +34,8 @@ #include "RigCaseCellResultsData.h" #include +#include "RiaApplication.h" +#include "RiaPreferences.h" //-------------------------------------------------------------------------------------------------- @@ -241,32 +243,66 @@ public: // dv(3) = 8; // dv(4) = 3; - std::vector cellCornerValues(doubleValueCount); - cvf::Vec3d cornerVerts[8]; - quint64 coordCount = 0; - for (int coordIdx = 0; coordIdx < 3; coordIdx++) + cvf::Timer timer; + + if (RiaApplication::instance()->preferences()->useStreamTransfer()) { - for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) + cvf::Vec3d cornerVerts[8]; + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { - size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - - for (size_t k = 0; k < cellCountK; k++) + for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) { - for (size_t j = 0; j < cellCountJ; j++) - { - for (size_t i = 0; i < cellCountI; i++) - { - size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); - rigGrid->cellCornerVertices(localCellIdx, cornerVerts); + size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx]; + for (size_t k = 0; k < cellCountK; k++) + { + for (size_t j = 0; j < cellCountJ; j++) + { + for (size_t i = 0; i < cellCountI; i++) + { + size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); + rigGrid->cellCornerVertices(localCellIdx, cornerVerts); + + socketStream << cornerVerts[cornerIndexMapping][coordIdx]; + } } } } } } + else + { + std::vector cellCornerValues(doubleValueCount); + cvf::Vec3d cornerVerts[8]; + quint64 coordCount = 0; + for (int coordIdx = 0; coordIdx < 3; coordIdx++) + { + for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) + { + size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - server->currentClient()->write((const char *)cellCornerValues.data(), byteCount); + for (size_t k = 0; k < cellCountK; k++) + { + for (size_t j = 0; j < cellCountJ; j++) + { + for (size_t i = 0; i < cellCountI; i++) + { + size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); + rigGrid->cellCornerVertices(localCellIdx, cornerVerts); + + cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx]; + } + } + } + } + } + server->currentClient()->write((const char *)cellCornerValues.data(), byteCount); + } + + double totalTimeMS = timer.time() * 1000.0; + QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); + + server->errorMessageDialog()->showMessage(resultInfo); return true; } diff --git a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp index f31218d7e3..4fa6a4f841 100644 --- a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp @@ -40,6 +40,8 @@ #include "Rim3dOverlayInfoConfig.h" #include +#include "RiaApplication.h" +#include "RiaPreferences.h" //-------------------------------------------------------------------------------------------------- @@ -305,30 +307,61 @@ public: socketStream << timestepCount; size_t valueIdx = 0; - - std::vector values(rigGrid->cellCount()); + cvf::Timer timer; - for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) + if (RiaApplication::instance()->preferences()->useStreamTransfer()) { - cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); - if (cellCenterDataAccessObject.isNull()) + for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) { - continue; - } - - for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) - { - double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); - if (cellValue == HUGE_VAL) + cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); + if (cellCenterDataAccessObject.isNull()) { - cellValue = 0.0; + continue; + } + + for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) + { + double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); + if (cellValue == HUGE_VAL) + { + cellValue = 0.0; + } + + socketStream << cellValue; + } + } + } + else + { + + std::vector values(rigGrid->cellCount()); + for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) + { + cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); + if (cellCenterDataAccessObject.isNull()) + { + continue; + } + + for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) + { + double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); + if (cellValue == HUGE_VAL) + { + cellValue = 0.0; + } + values[valueIdx++] = cellValue; } - values[cellIdx] = cellValue; } server->currentClient()->write((const char *)values.data(), rigGrid->cellCount() * sizeof(double)); } + double totalTimeMS = timer.time() * 1000.0; + QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); + + server->errorMessageDialog()->showMessage(resultInfo); + return true; } }; From 039ba48bed490e0c7cc693df66a9a67fdee0fe10 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 1 Apr 2014 15:31:13 +0200 Subject: [PATCH 36/51] Added block write to socket tools --- .../Application/RiaPreferences.cpp | 1 + ApplicationCode/Application/RiaPreferences.h | 1 + .../SocketInterface/RiaCaseInfoCommands.cpp | 9 +++- .../SocketInterface/RiaGeometryCommands.cpp | 10 ++-- .../RiaPropertyDataCommands.cpp | 5 +- .../SocketInterface/RiaSocketTools.cpp | 47 +++++++++++++++++++ .../SocketInterface/RiaSocketTools.h | 3 ++ 7 files changed, 67 insertions(+), 9 deletions(-) diff --git a/ApplicationCode/Application/RiaPreferences.cpp b/ApplicationCode/Application/RiaPreferences.cpp index 5c060c7031..793c2ffc9c 100644 --- a/ApplicationCode/Application/RiaPreferences.cpp +++ b/ApplicationCode/Application/RiaPreferences.cpp @@ -61,6 +61,7 @@ RiaPreferences::RiaPreferences(void) CAF_PDM_InitField(&readFaultData, "readFaultData", true, "Read fault data", "", "", ""); CAF_PDM_InitField(&useStreamTransfer, "useStreamTransfer", true, "Use stream transfer to Octave", "", "", ""); + CAF_PDM_InitField(&blockSize, "blockSize", 10000, "blockSize", "", "", ""); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Application/RiaPreferences.h b/ApplicationCode/Application/RiaPreferences.h index 5fcc691d3c..785eccf6d6 100644 --- a/ApplicationCode/Application/RiaPreferences.h +++ b/ApplicationCode/Application/RiaPreferences.h @@ -61,6 +61,7 @@ public: // Pdm Fields caf::PdmField readFaultData; caf::PdmField useStreamTransfer; + caf::PdmField blockSize; protected: virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute); diff --git a/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp b/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp index 201267dfb0..e6444f314d 100644 --- a/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp @@ -16,9 +16,12 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RiaStdInclude.h" + #include "RiaSocketCommand.h" #include "RiaSocketServer.h" #include "RiaSocketTools.h" +#include "RiaApplication.h" +#include "RiaPreferences.h" #include "RimReservoirView.h" #include "RimResultSlot.h" @@ -28,8 +31,8 @@ #include "RimWellCollection.h" #include "Rim3dOverlayInfoConfig.h" #include "RimReservoirCellResultsCacher.h" - #include "RimCase.h" + #include "RigCaseData.h" #include "RigCaseCellResultsData.h" @@ -37,6 +40,7 @@ + //-------------------------------------------------------------------------------------------------- /// OBSOLETE, to be deleted //-------------------------------------------------------------------------------------------------- @@ -133,7 +137,8 @@ public: for (size_t tIdx = 0; tIdx < columnCount; ++tIdx) { #if 1 // Write data as raw bytes, fast but does not handle byteswapping - server->currentClient()->write((const char *)activeCellInfo[tIdx].data(), timestepByteCount); + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)activeCellInfo[tIdx].data(), timestepByteCount); + #else // Write data using QDataStream, does byteswapping for us. Must use QDataStream on client as well for (size_t cIdx = 0; cIdx < activeCellInfo[tIdx].size(); ++cIdx) { diff --git a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp index 413f4791bc..5a3c8bc8b7 100644 --- a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp @@ -38,6 +38,7 @@ #include "RiaPreferences.h" + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -108,7 +109,7 @@ public: CVF_ASSERT(coordCount == doubleValueCount); - server->currentClient()->write((const char *)cellCenterValues.data(), byteCount); + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount); return true; } @@ -181,7 +182,7 @@ public: quint64 byteCount = doubleValueCount * sizeof(double); socketStream << byteCount; - server->currentClient()->write((const char *)cellCenterValues.data(), byteCount); + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount); return true; } @@ -296,7 +297,8 @@ public: } } } - server->currentClient()->write((const char *)cellCornerValues.data(), byteCount); + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount); } double totalTimeMS = timer.time() * 1000.0; @@ -381,7 +383,7 @@ public: quint64 byteCount = doubleValueCount * sizeof(double); socketStream << byteCount; - server->currentClient()->write((const char *)cellCornerValues.data(), byteCount); + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount); return true; } diff --git a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp index 4fa6a4f841..00210e4e21 100644 --- a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp @@ -334,7 +334,6 @@ public: else { - std::vector values(rigGrid->cellCount()); for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) { cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); @@ -343,6 +342,7 @@ public: continue; } + std::vector values(rigGrid->cellCount()); for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) { double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); @@ -352,9 +352,8 @@ public: } values[valueIdx++] = cellValue; } + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), values.size() * sizeof(double)); } - - server->currentClient()->write((const char *)values.data(), rigGrid->cellCount() * sizeof(double)); } double totalTimeMS = timer.time() * 1000.0; diff --git a/ApplicationCode/SocketInterface/RiaSocketTools.cpp b/ApplicationCode/SocketInterface/RiaSocketTools.cpp index cc53f26824..4ad720d2a9 100644 --- a/ApplicationCode/SocketInterface/RiaSocketTools.cpp +++ b/ApplicationCode/SocketInterface/RiaSocketTools.cpp @@ -16,6 +16,10 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RiaStdInclude.h" + +#include "RiaApplication.h" +#include "RiaPreferences.h" + #include "RiaSocketTools.h" #include "RiaSocketServer.h" #include "RimCase.h" @@ -34,6 +38,8 @@ #include "RimInputPropertyCollection.h" +#include + //-------------------------------------------------------------------------------------------------- /// @@ -98,4 +104,45 @@ void RiaSocketTools::getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QStri } } +bool RiaSocketTools::writeBlockData(RiaSocketServer* server, QTcpSocket* socket, const char* data, quint64 bytesToWrite) +{ + cvf::Timer timer; + + quint64 bytesWritten = 0; + int blockCount = 0; + + quint64 maxBlockSize = RiaApplication::instance()->preferences()->blockSize(); + + while (bytesWritten < bytesToWrite) + { + quint64 byteCountToWrite = qMin(bytesToWrite - bytesWritten, maxBlockSize); + + quint64 actuallyBytesWritten = socket->write(data + bytesWritten, byteCountToWrite); + if (actuallyBytesWritten == -1) + { + if (server) + { + QString errorMessage = "Error detected when writing data, error string from socket : \n" + socket->errorString(); + + server->errorMessageDialog()->showMessage(errorMessage); + } + + return false; + } + + bytesWritten += actuallyBytesWritten; + + blockCount++; + } + + if (server) + { + double totalTimeMS = timer.time() * 1000.0; + QString resultInfo = QString("Total time '%1 ms'\nTotal bytes written . %2\nNumber of blocks : %3\nBlock size : %4").arg(totalTimeMS).arg(bytesWritten).arg(blockCount).arg(maxBlockSize); + + server->errorMessageDialog()->showMessage(resultInfo); + } + + return true; +} diff --git a/ApplicationCode/SocketInterface/RiaSocketTools.h b/ApplicationCode/SocketInterface/RiaSocketTools.h index 1baeb5a9fc..b331799e2e 100644 --- a/ApplicationCode/SocketInterface/RiaSocketTools.h +++ b/ApplicationCode/SocketInterface/RiaSocketTools.h @@ -17,6 +17,7 @@ class RimCase; class RiaSocketServer; +class QTcpSocket; #define PMonLog( MessageString ) RiuMainWindow::instance()->processMonitor()->addStringToLog( MessageString ); @@ -25,4 +26,6 @@ class RiaSocketTools public: static RimCase* findCaseFromArgs(RiaSocketServer* server, const QList& args); static void getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId); + + static bool writeBlockData(RiaSocketServer* server, QTcpSocket* socket, const char* data, quint64 bytesToWrite); }; From c1419e53e895ecbdf3cc6593b7d9a538039820fa Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 1 Apr 2014 15:36:08 +0200 Subject: [PATCH 37/51] Fixed used on unsigned --- ApplicationCode/SocketInterface/RiaSocketTools.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ApplicationCode/SocketInterface/RiaSocketTools.cpp b/ApplicationCode/SocketInterface/RiaSocketTools.cpp index 4ad720d2a9..0f645450f9 100644 --- a/ApplicationCode/SocketInterface/RiaSocketTools.cpp +++ b/ApplicationCode/SocketInterface/RiaSocketTools.cpp @@ -113,12 +113,13 @@ bool RiaSocketTools::writeBlockData(RiaSocketServer* server, QTcpSocket* socket, quint64 maxBlockSize = RiaApplication::instance()->preferences()->blockSize(); + while (bytesWritten < bytesToWrite) { quint64 byteCountToWrite = qMin(bytesToWrite - bytesWritten, maxBlockSize); - quint64 actuallyBytesWritten = socket->write(data + bytesWritten, byteCountToWrite); - if (actuallyBytesWritten == -1) + qint64 actuallyBytesWritten = socket->write(data + bytesWritten, byteCountToWrite); + if (actuallyBytesWritten < 0) { if (server) { From 364ea1f9371c2898c1f8b9d1859906770639655f Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 2 Apr 2014 08:55:26 +0200 Subject: [PATCH 38/51] Added block read from socket --- .../SocketInterface/RiaSocketTools.cpp | 43 +++++++++++++++++++ .../SocketInterface/RiaSocketTools.h | 1 + OctavePlugin/riGetCellCorners.cpp | 17 ++++++++ 3 files changed, 61 insertions(+) diff --git a/ApplicationCode/SocketInterface/RiaSocketTools.cpp b/ApplicationCode/SocketInterface/RiaSocketTools.cpp index 0f645450f9..64cc8e0c11 100644 --- a/ApplicationCode/SocketInterface/RiaSocketTools.cpp +++ b/ApplicationCode/SocketInterface/RiaSocketTools.cpp @@ -147,3 +147,46 @@ bool RiaSocketTools::writeBlockData(RiaSocketServer* server, QTcpSocket* socket, return true; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RiaSocketTools::readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages) +{ + quint64 bytesRead = 0; + int blockCount = 0; + + quint64 maxBlockSize = RiaApplication::instance()->preferences()->blockSize(); + + while (bytesRead < bytesToRead) + { + if (socket.bytesAvailable()) + { + quint64 byteCountToRead = qMin(bytesToRead - bytesRead, maxBlockSize); + + qint64 actuallyBytesRead = socket.read(data + bytesRead, byteCountToRead); + if (actuallyBytesRead < 0) + { + errorMessages.push_back("Error detected when writing data, error string from socket"); + errorMessages.push_back(socket.errorString()); + + return false; + } + + bytesRead += actuallyBytesRead; + blockCount++; + } + else + { + if (!socket.waitForReadyRead()) + { + errorMessages.push_back("Waited for data for %1 milli seconds."); + errorMessages.push_back(socket.errorString()); + + return false; + } + } + } + + return true; +} + diff --git a/ApplicationCode/SocketInterface/RiaSocketTools.h b/ApplicationCode/SocketInterface/RiaSocketTools.h index b331799e2e..5a24731237 100644 --- a/ApplicationCode/SocketInterface/RiaSocketTools.h +++ b/ApplicationCode/SocketInterface/RiaSocketTools.h @@ -28,4 +28,5 @@ public: static void getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId); static bool writeBlockData(RiaSocketServer* server, QTcpSocket* socket, const char* data, quint64 bytesToWrite); + static bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages); }; diff --git a/OctavePlugin/riGetCellCorners.cpp b/OctavePlugin/riGetCellCorners.cpp index ee8f810239..af659079c0 100644 --- a/OctavePlugin/riGetCellCorners.cpp +++ b/OctavePlugin/riGetCellCorners.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "../ApplicationCode/SocketInterface/RiaSocketTools.h" void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex) @@ -67,7 +70,20 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 dv(4) = 3; cellCornerValues.resize(dv); + double* internalMatrixData = cellCornerValues.fortran_vec(); + QStringList errorMessages; + if (!RiaSocketTools::readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) + { + for (int i = 0; i < errorMessages.size(); i++) + { + error(errorMessages[i].toLatin1().data()); + } + OCTAVE_QUIT; + } + + + /* while (socket.bytesAvailable() < (qint64)(byteCount)) { if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) @@ -97,6 +113,7 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 } #endif + */ return; } From ed216f6de3511f2ac1fc47370618662ff60d72bc Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 2 Apr 2014 09:52:02 +0200 Subject: [PATCH 39/51] Moved Octave socket reading into riSocketTools --- OctavePlugin/riGetCellCorners.cpp | 8 ++++-- OctavePlugin/riGetCurrentCase.cpp | 1 + OctavePlugin/riSocketTools.h | 46 +++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 OctavePlugin/riSocketTools.h diff --git a/OctavePlugin/riGetCellCorners.cpp b/OctavePlugin/riGetCellCorners.cpp index af659079c0..f5e3b2c356 100644 --- a/OctavePlugin/riGetCellCorners.cpp +++ b/OctavePlugin/riGetCellCorners.cpp @@ -4,7 +4,9 @@ #include #include "riSettings.h" -#include "../ApplicationCode/SocketInterface/RiaSocketTools.h" +#include "riSocketTools.h" + + void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex) @@ -72,7 +74,7 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 double* internalMatrixData = cellCornerValues.fortran_vec(); QStringList errorMessages; - if (!RiaSocketTools::readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) + if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) { for (int i = 0; i < errorMessages.size(); i++) { @@ -82,6 +84,8 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 OCTAVE_QUIT; } + octave_stdout << "Bytes count processed : " << byteCount << std::endl; + /* while (socket.bytesAvailable() < (qint64)(byteCount)) diff --git a/OctavePlugin/riGetCurrentCase.cpp b/OctavePlugin/riGetCurrentCase.cpp index 80b0ffe4ac..88cc38088d 100644 --- a/OctavePlugin/riGetCurrentCase.cpp +++ b/OctavePlugin/riGetCurrentCase.cpp @@ -3,6 +3,7 @@ #include #include "riSettings.h" +#include "riSocketTools.h" void getCurrentCase(qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId, const QString &hostName, quint16 port) { diff --git a/OctavePlugin/riSocketTools.h b/OctavePlugin/riSocketTools.h new file mode 100644 index 0000000000..7d01381668 --- /dev/null +++ b/OctavePlugin/riSocketTools.h @@ -0,0 +1,46 @@ + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages) +{ + quint64 bytesRead = 0; + int blockCount = 0; + + quint64 maxBlockSize = 100000; + + while (bytesRead < bytesToRead) + { + if (socket.bytesAvailable()) + { + quint64 byteCountToRead = qMin(bytesToRead - bytesRead, maxBlockSize); + + qint64 actuallyBytesRead = socket.read(data + bytesRead, byteCountToRead); + if (actuallyBytesRead < 0) + { + errorMessages.push_back("Error detected when writing data, error string from socket"); + errorMessages.push_back(socket.errorString()); + + return false; + } + + bytesRead += actuallyBytesRead; + + octave_stdout << "Bytes read " << bytesRead << " of total " << bytesToRead << std::endl; + + blockCount++; + } + else + { + if (!socket.waitForReadyRead()) + { + errorMessages.push_back("Waited for data for %1 milli seconds."); + errorMessages.push_back(socket.errorString()); + + return false; + } + } + } + + return true; +} From 0bdacfba1729329cb1ec5cf6429dc643efefb15e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 3 Apr 2014 08:16:15 +0200 Subject: [PATCH 40/51] Moved socket max byte count to riSettings Added header files to cmake --- OctavePlugin/CMakeLists.txt | 5 ++++- OctavePlugin/riSettings.h | 2 ++ OctavePlugin/riSocketTools.h | 38 ++++++++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/OctavePlugin/CMakeLists.txt b/OctavePlugin/CMakeLists.txt index 68a4b588d3..7a11e18ab9 100644 --- a/OctavePlugin/CMakeLists.txt +++ b/OctavePlugin/CMakeLists.txt @@ -141,7 +141,10 @@ if (RESINSIGHT_OCTAVE_PLUGIN_QMAKE AND RESINSIGHT_OCTAVE_PLUGIN_MKOCTFILE) "${CMAKE_CURRENT_BINARY_DIR}/riGetWellNames.oct" "${CMAKE_CURRENT_BINARY_DIR}/riGetWellStatus.oct" "${CMAKE_CURRENT_BINARY_DIR}/riGetWellCells.oct" - SOURCES ${CPP_SOURCES} + SOURCES + ${CPP_SOURCES} + riSocketTools.h + riSettings.h ) diff --git a/OctavePlugin/riSettings.h b/OctavePlugin/riSettings.h index bc7220e845..5765244a6d 100644 --- a/OctavePlugin/riSettings.h +++ b/OctavePlugin/riSettings.h @@ -24,6 +24,8 @@ namespace riOctavePlugin const int shortTimeOutMilliSecs = 5000; const int longTimeOutMilliSecs = 6000000; + const int socketMaxByteCount = 100000; + // Octave data structure : CaseInfo char caseInfo_CaseId[] = "CaseId"; char caseInfo_CaseName[] = "CaseName"; diff --git a/OctavePlugin/riSocketTools.h b/OctavePlugin/riSocketTools.h index 7d01381668..63cc24d890 100644 --- a/OctavePlugin/riSocketTools.h +++ b/OctavePlugin/riSocketTools.h @@ -7,7 +7,7 @@ bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringL quint64 bytesRead = 0; int blockCount = 0; - quint64 maxBlockSize = 100000; + quint64 maxBlockSize = riOctavePlugin::socketMaxByteCount; while (bytesRead < bytesToRead) { @@ -18,7 +18,7 @@ bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringL qint64 actuallyBytesRead = socket.read(data + bytesRead, byteCountToRead); if (actuallyBytesRead < 0) { - errorMessages.push_back("Error detected when writing data, error string from socket"); + errorMessages.push_back("Error detected when reading data, error string from socket :"); errorMessages.push_back(socket.errorString()); return false; @@ -41,6 +41,40 @@ bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringL } } } + + octave_stdout << "Bytes read " << bytesToRead << std::endl; + + return true; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool writeBlockData(QTcpSocket& socket, const char* data, quint64 bytesToWrite, QStringList& errorMessages) +{ + quint64 bytesWritten = 0; + int blockCount = 0; + + quint64 maxBlockSize = riOctavePlugin::socketMaxByteCount; + + while (bytesWritten < bytesToWrite) + { + quint64 byteCountToWrite = qMin(bytesToWrite - bytesWritten, maxBlockSize); + + qint64 actuallyBytesWritten = socket.write(data + bytesWritten, byteCountToWrite); + if (actuallyBytesWritten < 0) + { + errorMessages.push_back("Error detected when writing data, error string from socket"); + errorMessages.push_back(socket.errorString()); + + return false; + } + + bytesWritten += actuallyBytesWritten; + + blockCount++; + } return true; } From acc1d732d7b05df3de19834f8da7e46d4e3aeb0f Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 3 Apr 2014 10:41:27 +0200 Subject: [PATCH 41/51] Use socket block read/write for geometry data --- .../SocketInterface/RiaGeometryCommands.cpp | 133 ++++++++---------- OctavePlugin/riGetActiveCellCenters.cpp | 27 ++-- OctavePlugin/riGetActiveCellCorners.cpp | 27 ++-- OctavePlugin/riGetCellCenters.cpp | 37 ++--- OctavePlugin/riGetCellCorners.cpp | 35 ----- 5 files changed, 89 insertions(+), 170 deletions(-) diff --git a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp index 5a3c8bc8b7..2ca72a655d 100644 --- a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp @@ -87,11 +87,14 @@ public: // dv(2) = cellCountK; // dv(3) = 3; - std::vector cellCenterValues(doubleValueCount); cvf::Vec3d cornerVerts[8]; - quint64 coordCount = 0; + size_t blockByteCount = cellCount * sizeof(double); + std::vector doubleValues(blockByteCount); + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { + quint64 valueIndex = 0; + for (size_t k = 0; k < cellCountK; k++) { for (size_t j = 0; j < cellCountJ; j++) @@ -101,16 +104,16 @@ public: size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); cvf::Vec3d center = rigGrid->cell(localCellIdx).center(); - cellCenterValues[coordCount++] = center[coordIdx]; + doubleValues[valueIndex++] = center[coordIdx]; } } } + + CVF_ASSERT(valueIndex == cellCount); + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } - CVF_ASSERT(coordCount == doubleValueCount); - - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount); - return true; } }; @@ -152,6 +155,11 @@ public: size_t activeCellCount = actCellInfo->globalActiveCellCount(); size_t doubleValueCount = activeCellCount * 3; + socketStream << (quint64)activeCellCount; + quint64 byteCount = doubleValueCount * sizeof(double); + socketStream << byteCount; + + // This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is // defined by the ordering of the receiving NDArray // @@ -162,28 +170,26 @@ public: // dv(0) = coordCount; // dv(1) = 3; - std::vector cellCenterValues(doubleValueCount); - quint64 coordCount = 0; + size_t blockByteCount = activeCellCount * sizeof(double); + std::vector doubleValues(blockByteCount); + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { + quint64 valueIndex = 0; + for (size_t globalCellIdx = 0; globalCellIdx < mainGrid->cells().size(); globalCellIdx++) { if (!actCellInfo->isActive(globalCellIdx)) continue; cvf::Vec3d center = mainGrid->cells()[globalCellIdx].center(); - cellCenterValues[coordCount++] = center[coordIdx]; + doubleValues[valueIndex++] = center[coordIdx]; } + + CVF_ASSERT(valueIndex == activeCellCount); + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } - CVF_ASSERT(coordCount == doubleValueCount); - - socketStream << (quint64)activeCellCount; - quint64 byteCount = doubleValueCount * sizeof(double); - socketStream << byteCount; - - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount); - return true; } @@ -244,67 +250,37 @@ public: // dv(3) = 8; // dv(4) = 3; - cvf::Timer timer; + cvf::Vec3d cornerVerts[8]; + size_t blockByteCount = cellCount * sizeof(double); + std::vector doubleValues(blockByteCount); - if (RiaApplication::instance()->preferences()->useStreamTransfer()) + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { - cvf::Vec3d cornerVerts[8]; - for (int coordIdx = 0; coordIdx < 3; coordIdx++) + for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) { - for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) + size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; + + quint64 valueIndex = 0; + + for (size_t k = 0; k < cellCountK; k++) { - size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - - for (size_t k = 0; k < cellCountK; k++) + for (size_t j = 0; j < cellCountJ; j++) { - for (size_t j = 0; j < cellCountJ; j++) + for (size_t i = 0; i < cellCountI; i++) { - for (size_t i = 0; i < cellCountI; i++) - { - size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); - rigGrid->cellCornerVertices(localCellIdx, cornerVerts); + size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); + rigGrid->cellCornerVertices(localCellIdx, cornerVerts); - socketStream << cornerVerts[cornerIndexMapping][coordIdx]; - } + doubleValues[valueIndex++] = cornerVerts[cornerIndexMapping][coordIdx]; } } } + + CVF_ASSERT(valueIndex, cellCount); + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } } - else - { - std::vector cellCornerValues(doubleValueCount); - cvf::Vec3d cornerVerts[8]; - quint64 coordCount = 0; - for (int coordIdx = 0; coordIdx < 3; coordIdx++) - { - for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) - { - size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - - for (size_t k = 0; k < cellCountK; k++) - { - for (size_t j = 0; j < cellCountJ; j++) - { - for (size_t i = 0; i < cellCountI; i++) - { - size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); - rigGrid->cellCornerVertices(localCellIdx, cornerVerts); - - cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx]; - } - } - } - } - } - - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount); - } - - double totalTimeMS = timer.time() * 1000.0; - QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); - - server->errorMessageDialog()->showMessage(resultInfo); return true; } @@ -348,6 +324,10 @@ public: size_t activeCellCount = actCellInfo->globalActiveCellCount(); size_t doubleValueCount = activeCellCount * 3 * 8; + socketStream << (quint64)activeCellCount; + quint64 byteCount = doubleValueCount * sizeof(double); + socketStream << byteCount; + // This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is // defined by the ordering of the receiving NDArray // @@ -359,32 +339,33 @@ public: // dv(1) = 8; // dv(2) = 3; - std::vector cellCornerValues(doubleValueCount); cvf::Vec3d cornerVerts[8]; - quint64 coordCount = 0; + size_t blockByteCount = activeCellCount * sizeof(double); + std::vector doubleValues(blockByteCount); + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) { size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; + quint64 valueIndex = 0; + for (size_t globalCellIdx = 0; globalCellIdx < mainGrid->cells().size(); globalCellIdx++) { if (!actCellInfo->isActive(globalCellIdx)) continue; mainGrid->cellCornerVertices(globalCellIdx, cornerVerts); - cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx]; + doubleValues[valueIndex++] = cornerVerts[cornerIndexMapping][coordIdx]; } + + CVF_ASSERT(valueIndex == activeCellCount); + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } } - socketStream << (quint64)activeCellCount; - quint64 byteCount = doubleValueCount * sizeof(double); - socketStream << byteCount; - - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount); - return true; } diff --git a/OctavePlugin/riGetActiveCellCenters.cpp b/OctavePlugin/riGetActiveCellCenters.cpp index 90c1631f30..a98ba06bac 100644 --- a/OctavePlugin/riGetActiveCellCenters.cpp +++ b/OctavePlugin/riGetActiveCellCenters.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "riSocketTools.h" void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const QString& porosityModel) @@ -61,24 +64,16 @@ void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, qu cellCenterValues.resize(dv); - while (socket.bytesAvailable() < (qint64)(byteCount)) - { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - error((("Waiting for data: ") + socket.errorString()).toLatin1().data()); - return; - } - OCTAVE_QUIT; - } - - quint64 bytesRead = 0; double* internalMatrixData = cellCenterValues.fortran_vec(); - bytesRead = socket.read((char*)(internalMatrixData), byteCount); - - if (byteCount != bytesRead) + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) { - error("Could not read binary double data properly from socket"); - octave_stdout << "Active cell count: " << activeCellCount << std::endl; + for (int i = 0; i < errorMessages.size(); i++) + { + error(errorMessages[i].toLatin1().data()); + } + + OCTAVE_QUIT; } return; diff --git a/OctavePlugin/riGetActiveCellCorners.cpp b/OctavePlugin/riGetActiveCellCorners.cpp index 6fb285cc4a..47ffad52bc 100644 --- a/OctavePlugin/riGetActiveCellCorners.cpp +++ b/OctavePlugin/riGetActiveCellCorners.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "riSocketTools.h" void getActiveCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 port, const qint32& caseId, const QString& porosityModel) @@ -61,24 +64,16 @@ void getActiveCellCorners(NDArray& cellCornerValues, const QString &hostName, qu dv(2) = 3; cellCornerValues.resize(dv); - while (socket.bytesAvailable() < (qint64)(byteCount)) - { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - error((("Waiting for data: ") + socket.errorString()).toLatin1().data()); - return; - } - OCTAVE_QUIT; - } - - quint64 bytesRead = 0; double* internalMatrixData = cellCornerValues.fortran_vec(); - bytesRead = socket.read((char*)(internalMatrixData), byteCount); - - if (byteCount != bytesRead) + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) { - error("Could not read binary double data properly from socket"); - octave_stdout << "Active cell count: " << activeCellCount << std::endl; + for (int i = 0; i < errorMessages.size(); i++) + { + error(errorMessages[i].toLatin1().data()); + } + + OCTAVE_QUIT; } return; diff --git a/OctavePlugin/riGetCellCenters.cpp b/OctavePlugin/riGetCellCenters.cpp index cb65de3d01..4f57d08a2b 100644 --- a/OctavePlugin/riGetCellCenters.cpp +++ b/OctavePlugin/riGetCellCenters.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "riSocketTools.h" void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex) @@ -66,39 +69,19 @@ void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 dv(3) = 3; cellCenterValues.resize(dv); - while (socket.bytesAvailable() < (qint64)(byteCount)) + + double* internalMatrixData = cellCenterValues.fortran_vec(); + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) + for (int i = 0; i < errorMessages.size(); i++) { - error((("Waiting for data: ") + socket.errorString()).toLatin1().data()); - return; + error(errorMessages[i].toLatin1().data()); } + OCTAVE_QUIT; } - //octave_stdout << " riGetCellCenters : I = " << cellCountI <<" J = " << cellCountJ << " K = " << cellCountK << std::endl; - //octave_stdout << " riGetCellCenters : numDoubles = " << valueCount << std::endl; - - double* internalMatrixData = cellCenterValues.fortran_vec(); - -#if 0 - octave_idx_type valueCount = cellCenterValues.length(); - double val; - for (octave_idx_type i = 0; i < valueCount; i++) - { - socketStream >> internalMatrixData[i]; - } -#else - quint64 bytesRead = 0; - bytesRead = socket.read((char*)(internalMatrixData), byteCount); - - if (byteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - octave_stdout << "Cell count: " << cellCount << std::endl; - } - -#endif return; } diff --git a/OctavePlugin/riGetCellCorners.cpp b/OctavePlugin/riGetCellCorners.cpp index f5e3b2c356..2571371a76 100644 --- a/OctavePlugin/riGetCellCorners.cpp +++ b/OctavePlugin/riGetCellCorners.cpp @@ -84,41 +84,6 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 OCTAVE_QUIT; } - octave_stdout << "Bytes count processed : " << byteCount << std::endl; - - - /* - while (socket.bytesAvailable() < (qint64)(byteCount)) - { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - error((("Waiting for data: ") + socket.errorString()).toLatin1().data()); - return; - } - OCTAVE_QUIT; - } - - double* internalMatrixData = cellCornerValues.fortran_vec(); - -#if 0 - double val; - for (octave_idx_type i = 0; i < valueCount; i++) - { - socketStream >> internalMatrixData[i]; - } -#else - quint64 bytesRead = 0; - bytesRead = socket.read((char*)(internalMatrixData), byteCount); - - if (byteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - octave_stdout << "Cell count: " << cellCount << std::endl; - } - -#endif - */ - return; } From 874b05b119caeaf1563bdde425f04dfaaf74feac Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 3 Apr 2014 10:58:29 +0200 Subject: [PATCH 42/51] Added isCoarseningActive --- ApplicationCode/ReservoirDataModel/RigActiveCellInfo.cpp | 8 ++++++++ ApplicationCode/ReservoirDataModel/RigActiveCellInfo.h | 1 + 2 files changed, 9 insertions(+) diff --git a/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.cpp b/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.cpp index bb0da770da..b58b17c5d4 100644 --- a/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.cpp +++ b/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.cpp @@ -193,6 +193,14 @@ void RigActiveCellInfo::clear() m_activeCellsBoundingBox.reset(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RigActiveCellInfo::isCoarseningActive() const +{ + return m_globalCellResultCount != m_globalActiveCellCount; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.h b/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.h index 2719dbffb5..cbe11c9b8c 100644 --- a/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.h +++ b/ApplicationCode/ReservoirDataModel/RigActiveCellInfo.h @@ -36,6 +36,7 @@ public: size_t globalCellCount() const; size_t globalActiveCellCount() const; size_t globalCellResultCount() const; + bool isCoarseningActive() const; bool isActive(size_t globalCellIndex) const; size_t cellResultIndex(size_t globalCellIndex) const; From bd528cc8d2bf17dcc77b1cebaf18ac36034d1843 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 3 Apr 2014 11:09:42 +0200 Subject: [PATCH 43/51] Updated use of buffer read --- OctavePlugin/riGetActiveCellInfo.cpp | 48 +++++++--------------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/OctavePlugin/riGetActiveCellInfo.cpp b/OctavePlugin/riGetActiveCellInfo.cpp index 824134e0f7..a7213a3697 100644 --- a/OctavePlugin/riGetActiveCellInfo.cpp +++ b/OctavePlugin/riGetActiveCellInfo.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "riSocketTools.h" void getActiveCellInfo(int32NDArray& activeCellInfo, const QString &hostName, quint16 port, const qint64& caseId, const QString& porosityModel) @@ -43,59 +46,32 @@ void getActiveCellInfo(int32NDArray& activeCellInfo, const QString &hostName, qu // Read timestep count and blocksize quint64 columnCount; - quint64 byteCount; + quint64 byteCountForOneTimestep; size_t activeCellCount; socketStream >> columnCount; - socketStream >> byteCount; + socketStream >> byteCountForOneTimestep; - activeCellCount = byteCount / sizeof(qint32); + activeCellCount = byteCountForOneTimestep / sizeof(qint32); dim_vector dv (2, 1); dv(0) = activeCellCount; dv(1) = columnCount; activeCellInfo.resize(dv); - if (!(byteCount && columnCount)) + if (!(byteCountForOneTimestep && columnCount)) { error ("Could not find the requested data in ResInsight"); return; } - // Wait for available data for each column, then read data for each column - for (size_t tIdx = 0; tIdx < columnCount; ++tIdx) + qint32* internalMatrixData = (qint32*)activeCellInfo.fortran_vec()->mex_get_data(); + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), columnCount * byteCountForOneTimestep, errorMessages)) { - while (socket.bytesAvailable() < (int)byteCount) + for (int i = 0; i < errorMessages.size(); i++) { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - QString errorMsg = QString("Waiting for column number: %1 of %2: %3").arg(tIdx).arg(columnCount).arg(socket.errorString()); - - error(errorMsg.toLatin1().data()); - octave_stdout << "Active cells: " << activeCellCount << ", Columns: " << columnCount << std::endl; - return ; - } - OCTAVE_QUIT; - } - - qint64 bytesRead = 0; - qint32* internalMatrixData = (qint32*)activeCellInfo.fortran_vec()->mex_get_data(); - -#if 1 // Use raw data transfer. Faster. - bytesRead = socket.read((char*)(internalMatrixData + tIdx * activeCellCount), byteCount); -#else - for (size_t cIdx = 0; cIdx < activeCellCount; ++cIdx) - { - socketStream >> internalMatrixData[tIdx * activeCellCount + cIdx]; - - if (socketStream.status() == QDataStream::Ok) bytesRead += sizeof(int); - } -#endif - - if ((int)byteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - octave_stdout << "Active cells: " << activeCellCount << ", Columns: " << columnCount << std::endl; + error(errorMessages[i].toLatin1().data()); } OCTAVE_QUIT; From 0562f92585f6b420caf1f6cf9d88c5c24083e8b7 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 3 Apr 2014 11:56:01 +0200 Subject: [PATCH 44/51] Updated riGetGridProperty --- .../RiaPropertyDataCommands.cpp | 57 +++--------- OctavePlugin/riGetGridProperty.cpp | 92 ++----------------- 2 files changed, 22 insertions(+), 127 deletions(-) diff --git a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp index 00210e4e21..87cf148f7c 100644 --- a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp @@ -306,61 +306,28 @@ public: quint64 timestepCount = (quint64)requestedTimesteps.size(); socketStream << timestepCount; - size_t valueIdx = 0; - cvf::Timer timer; - - if (RiaApplication::instance()->preferences()->useStreamTransfer()) + for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) { - for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) + cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); + if (cellCenterDataAccessObject.isNull()) { - cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); - if (cellCenterDataAccessObject.isNull()) - { - continue; - } - - for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) - { - double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); - if (cellValue == HUGE_VAL) - { - cellValue = 0.0; - } - - socketStream << cellValue; - } + continue; } - } - else - { - for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) + std::vector values(rigGrid->cellCount()); + for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) { - cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); - if (cellCenterDataAccessObject.isNull()) + double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); + if (cellValue == HUGE_VAL) { - continue; + cellValue = 0.0; } - - std::vector values(rigGrid->cellCount()); - for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) - { - double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); - if (cellValue == HUGE_VAL) - { - cellValue = 0.0; - } - values[valueIdx++] = cellValue; - } - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), values.size() * sizeof(double)); + values[cellIdx] = cellValue; } + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), values.size() * sizeof(double)); } - double totalTimeMS = timer.time() * 1000.0; - QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); - - server->errorMessageDialog()->showMessage(resultInfo); - return true; } }; diff --git a/OctavePlugin/riGetGridProperty.cpp b/OctavePlugin/riGetGridProperty.cpp index 3b1fbc589f..e477cd767a 100644 --- a/OctavePlugin/riGetGridProperty.cpp +++ b/OctavePlugin/riGetGridProperty.cpp @@ -1,6 +1,11 @@ #include +#include + #include + #include "riSettings.h" +#include "riSocketTools.h" + void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 serverPort, const int& caseId, int gridIdx, QString propertyName, const int32NDArray& requestedTimeSteps, QString porosityModel) @@ -61,8 +66,6 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 totalByteCount = cellCountI*cellCountJ*cellCountK*timestepCount*sizeof(double); - qint64 timestepByteCount = cellCountI*cellCountJ*cellCountK*sizeof(double); - if (!(totalByteCount)) { error ("Could not find the requested data in ResInsight"); @@ -78,93 +81,18 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 propertyFrames.resize(dv); - -#if 1 - // Wait for available data for each timestep, then read data for each timestep - - qint64 totalBytesRead = 0; - - for (size_t tIdx = 0; tIdx < timestepCount; ++tIdx) + double* internalMatrixData = propertyFrames.fortran_vec(); + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), totalByteCount, errorMessages)) { - qint64 bytesAvailable = socket.bytesAvailable() ; - - while ( bytesAvailable < (qint64)timestepByteCount) + for (int i = 0; i < errorMessages.size(); i++) { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - error((("Waiting for timestep data number: ") + QString::number(tIdx)+ ": " + socket.errorString()).toLatin1().data()); - octave_stdout << "Cellcount: " << cellCountI*cellCountJ*cellCountK << ", Timesteps: " << timestepCount << std::endl; - return ; - } - - bytesAvailable = socket.bytesAvailable(); - - OCTAVE_QUIT; + error(errorMessages[i].toLatin1().data()); } - qint64 bytesRead = 0; - double * internalMatrixData = propertyFrames.fortran_vec(); - - // Raw data transfer. Faster. Not possible when dealing with coarsening - bytesRead = socket.read(((char*)(internalMatrixData)) + tIdx * timestepByteCount, timestepByteCount); - - if ((qint64)timestepByteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - octave_stdout << "Cellcount: " << cellCountI*cellCountJ*cellCountK << ", Timesteps count: " << timestepCount << std::endl; - octave_stdout << "Timestep : " << tIdx << std::endl; - } - - totalBytesRead += bytesRead; - - OCTAVE_QUIT; - } - - if ((qint64)totalByteCount != totalBytesRead) - { - error("Could not read binary double data properly from socket"); - } - - #else - - // Wait for available data - qint64 bytesAvailable = socket.bytesAvailable() ; - - while (bytesAvailable < (qint64)totalByteCount) - { - octave_stdout << "Waiting for data. Has : " << bytesAvailable << " Needs :" << totalByteCount << std::endl; - if (!socket.waitForReadyRead(riOctavePlugin::shortTimeOutMilliSecs)) - { - //error(("Waiting for data : " + socket.errorString()).toLatin1().data()); - //return ; - } - - bytesAvailable = socket.bytesAvailable() ; OCTAVE_QUIT; } - qint64 bytesRead = 0; - double * internalMatrixData = propertyFrames.fortran_vec(); - -#if 0 - - char* dataBuffer = new char[totalByteCount]; - bytesRead = socket.read(dataBuffer, totalByteCount); - - -#else - - // Raw data transfer. Faster. - bytesRead = socket.read((char*)(internalMatrixData ), totalByteCount); -#endif - - - if ((qint64)totalByteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - } - -#endif QString tmp = QString("riGetGridProperty : Read %1").arg(propertyName); if (caseId < 0) From 7b68c3cb6b7b7fefc4d6a448db1d05218a00223f Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 14 Apr 2014 10:24:15 +0200 Subject: [PATCH 45/51] Fix after merge conflicts take two --- ApplicationCode/Application/RiaPreferences.cpp | 4 +--- ApplicationCode/Application/RiaPreferences.h | 3 --- ApplicationCode/ProjectDataModel/CMakeLists_files.cmake | 6 ------ ApplicationCode/ProjectDataModel/RimDefines.h | 7 ------- ApplicationCode/ProjectDataModel/RimResultCase.cpp | 3 --- .../ReservoirDataModel/RigReservoirBuilderMock.cpp | 9 +++------ Fwk/AppFwk/cafUserInterface/CMakeLists.txt | 5 ----- 7 files changed, 4 insertions(+), 33 deletions(-) diff --git a/ApplicationCode/Application/RiaPreferences.cpp b/ApplicationCode/Application/RiaPreferences.cpp index abe04fa30f..b1d94b514c 100644 --- a/ApplicationCode/Application/RiaPreferences.cpp +++ b/ApplicationCode/Application/RiaPreferences.cpp @@ -59,10 +59,8 @@ RiaPreferences::RiaPreferences(void) CAF_PDM_InitField(&autocomputeSOIL, "autocomputeSOIL", true, "SOIL", "", "SOIL = 1.0 - SGAS - SWAT", ""); CAF_PDM_InitField(&autocomputeDepthRelatedProperties,"autocomputeDepth", true, "DEPTH related properties", "", "DEPTH, DX, DY, DZ, TOP, BOTTOM", ""); -<<<<<<< HEAD CAF_PDM_InitField(&readFaultData, "readFaultData", true, "Read fault data", "", "", ""); -======= ->>>>>>> 770f70680345d00c4b6c828e1e36f3f12000a390 + CAF_PDM_InitField(&useStreamTransfer, "useStreamTransfer", true, "Use stream transfer to Octave", "", "", ""); CAF_PDM_InitField(&blockSize, "blockSize", 10000, "blockSize", "", "", ""); } diff --git a/ApplicationCode/Application/RiaPreferences.h b/ApplicationCode/Application/RiaPreferences.h index 978c4b144e..785eccf6d6 100644 --- a/ApplicationCode/Application/RiaPreferences.h +++ b/ApplicationCode/Application/RiaPreferences.h @@ -63,9 +63,6 @@ public: // Pdm Fields caf::PdmField useStreamTransfer; caf::PdmField blockSize; - caf::PdmField useStreamTransfer; - caf::PdmField blockSize; - protected: virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute); diff --git a/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake b/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake index 01c0213347..4e0d185f37 100644 --- a/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake +++ b/ApplicationCode/ProjectDataModel/CMakeLists_files.cmake @@ -44,11 +44,8 @@ ${CEE_CURRENT_LIST_DIR}RimStatisticsCaseEvaluator.h ${CEE_CURRENT_LIST_DIR}RimMimeData.h ${CEE_CURRENT_LIST_DIR}RimCommandObject.h ${CEE_CURRENT_LIST_DIR}RimTools.h -<<<<<<< HEAD ${CEE_CURRENT_LIST_DIR}RimFault.h ${CEE_CURRENT_LIST_DIR}RimFaultCollection.h -======= ->>>>>>> 770f70680345d00c4b6c828e1e36f3f12000a390 ${CEE_CURRENT_LIST_DIR}RimMockModelSettings.h ) @@ -92,11 +89,8 @@ ${CEE_CURRENT_LIST_DIR}RimStatisticsCaseEvaluator.cpp ${CEE_CURRENT_LIST_DIR}RimMimeData.cpp ${CEE_CURRENT_LIST_DIR}RimCommandObject.cpp ${CEE_CURRENT_LIST_DIR}RimTools.cpp -<<<<<<< HEAD ${CEE_CURRENT_LIST_DIR}RimFault.cpp ${CEE_CURRENT_LIST_DIR}RimFaultCollection.cpp -======= ->>>>>>> 770f70680345d00c4b6c828e1e36f3f12000a390 ${CEE_CURRENT_LIST_DIR}RimMockModelSettings.cpp ) diff --git a/ApplicationCode/ProjectDataModel/RimDefines.h b/ApplicationCode/ProjectDataModel/RimDefines.h index 1398300156..0dd82175f1 100644 --- a/ApplicationCode/ProjectDataModel/RimDefines.h +++ b/ApplicationCode/ProjectDataModel/RimDefines.h @@ -40,11 +40,8 @@ public: }; static QString undefinedResultName() { return "None"; } -<<<<<<< HEAD static QString undefinedGridFaultName() { return "Undefined grid faults"; } static QString combinedTransmissibilityResultName() { return "TRANSXYZ"; } -======= ->>>>>>> 770f70680345d00c4b6c828e1e36f3f12000a390 // Mock model text identifiers @@ -54,9 +51,5 @@ public: static QString mockModelCustomized() { return "Result Mock Debug Model Customized"; } static QString mockModelBasicInputCase() { return "Input Mock Debug Model Simple"; } -<<<<<<< HEAD -======= - ->>>>>>> 770f70680345d00c4b6c828e1e36f3f12000a390 }; diff --git a/ApplicationCode/ProjectDataModel/RimResultCase.cpp b/ApplicationCode/ProjectDataModel/RimResultCase.cpp index 66c43e6046..a392121b5f 100644 --- a/ApplicationCode/ProjectDataModel/RimResultCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimResultCase.cpp @@ -49,10 +49,7 @@ #include "Rim3dOverlayInfoConfig.h" #include "RimOilField.h" #include "RimAnalysisModels.h" -<<<<<<< HEAD #include "RiaPreferences.h" -======= ->>>>>>> 770f70680345d00c4b6c828e1e36f3f12000a390 #include "RimMockModelSettings.h" CAF_PDM_SOURCE_INIT(RimResultCase, "EclipseCase"); diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp index 715c489490..221bb9db1b 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp +++ b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp @@ -253,11 +253,8 @@ void RigReservoirBuilderMock::populateReservoir(RigCaseData* eclipseCase) { addWellData(eclipseCase, eclipseCase->mainGrid()); } -<<<<<<< HEAD addFaults(eclipseCase); -======= ->>>>>>> 770f70680345d00c4b6c828e1e36f3f12000a390 // Set all cells active RigActiveCellInfo* activeCellInfo = eclipseCase->activeCellInfo(RifReaderInterface::MATRIX_RESULTS); @@ -495,7 +492,6 @@ void RigReservoirBuilderMock::addWellData(RigCaseData* eclipseCase, RigGridBase* //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -<<<<<<< HEAD void RigReservoirBuilderMock::addFaults(RigCaseData* eclipseCase) { if (!eclipseCase) return; @@ -533,8 +529,9 @@ void RigReservoirBuilderMock::addFaults(RigCaseData* eclipseCase) grid->setFaults(faults); } -======= ->>>>>>> 770f70680345d00c4b6c828e1e36f3f12000a390 +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- void RigReservoirBuilderMock::enableWellData(bool enableWellData) { m_enableWellData = false; diff --git a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt index a732521f1d..b210e4a322 100644 --- a/Fwk/AppFwk/cafUserInterface/CMakeLists.txt +++ b/Fwk/AppFwk/cafUserInterface/CMakeLists.txt @@ -38,13 +38,8 @@ endif() add_library( ${PROJECT_NAME} -<<<<<<< HEAD cafAboutDialog.cpp cafAboutDialog.h -======= - cafBasicAboutDialog.cpp - cafBasicAboutDialog.h ->>>>>>> 770f70680345d00c4b6c828e1e36f3f12000a390 cafPdmSettings.cpp cafPdmUiCheckBoxEditor.cpp cafPdmUiCheckBoxEditor.h From 0f01703ac3202c8a0886e079e481ef1f44159db2 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 14 Apr 2014 14:36:47 +0200 Subject: [PATCH 46/51] Added socket data transfer Added one common class used to transfer data using socket. This class is used both from the Octave plugins and from the socket server code in ResInsight --- ApplicationCode/CMakeLists.txt | 3 + .../SocketInterface/RiaSocketDataTransfer.cpp | 102 ++++++++++++++++++ .../SocketInterface/RiaSocketDataTransfer.h | 36 +++++++ .../SocketInterface/RiaSocketTools.cpp | 88 +++------------ .../SocketInterface/RiaSocketTools.h | 1 - OctavePlugin/CMakeLists.txt | 6 +- 6 files changed, 158 insertions(+), 78 deletions(-) create mode 100644 ApplicationCode/SocketInterface/RiaSocketDataTransfer.cpp create mode 100644 ApplicationCode/SocketInterface/RiaSocketDataTransfer.h diff --git a/ApplicationCode/CMakeLists.txt b/ApplicationCode/CMakeLists.txt index 29c2db248b..d4e7e4113f 100644 --- a/ApplicationCode/CMakeLists.txt +++ b/ApplicationCode/CMakeLists.txt @@ -58,6 +58,7 @@ set( SOCKET_INTERFACE_FILES SocketInterface/RiaPropertyDataCommands.cpp SocketInterface/RiaWellDataCommands.cpp SocketInterface/RiaSocketTools.cpp + SocketInterface/RiaSocketDataTransfer.cpp ) @@ -153,6 +154,8 @@ list( REMOVE_ITEM RAW_SOURCES Application/RiaImageCompareReporter.cpp Application/RiaRegressionTest.cpp + SocketInterface/RiaSocketDataTransfer.cpp + FileInterface/RifEclipseInputFileTools.cpp FileInterface/RifEclipseOutputFileTools.cpp FileInterface/RifEclipseRestartFilesetAccess.cpp diff --git a/ApplicationCode/SocketInterface/RiaSocketDataTransfer.cpp b/ApplicationCode/SocketInterface/RiaSocketDataTransfer.cpp new file mode 100644 index 0000000000..c49ff5fa1f --- /dev/null +++ b/ApplicationCode/SocketInterface/RiaSocketDataTransfer.cpp @@ -0,0 +1,102 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Statoil ASA, Ceetron Solutions AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RiaSocketDataTransfer.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RiaSocketDataTransfer::writeBlockDataToSocket(QTcpSocket* socket, const char* data, quint64 bytesToWrite, QStringList& errorMessages) +{ + quint64 bytesWritten = 0; + int blockCount = 0; + + quint64 maxBlockSize = doubleValueCountInBlock() * sizeof(double); + + while (bytesWritten < bytesToWrite) + { + quint64 byteCountToWrite = qMin(bytesToWrite - bytesWritten, maxBlockSize); + + qint64 actuallyBytesWritten = socket->write(data + bytesWritten, byteCountToWrite); + if (actuallyBytesWritten < 0) + { + errorMessages.push_back("Error detected when writing data, error string from socket"); + errorMessages.push_back(socket->errorString()); + + return false; + } + + bytesWritten += actuallyBytesWritten; + + blockCount++; + } + + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RiaSocketDataTransfer::readBlockDataFromSocket(QTcpSocket* socket, char* data, quint64 bytesToRead, QStringList& errorMessages) +{ + quint64 bytesRead = 0; + int blockCount = 0; + + quint64 maxBlockSize = doubleValueCountInBlock() * sizeof(double); + + while (bytesRead < bytesToRead) + { + if (socket->bytesAvailable()) + { + quint64 byteCountToRead = qMin(bytesToRead - bytesRead, maxBlockSize); + + qint64 actuallyBytesRead = socket->read(data + bytesRead, byteCountToRead); + if (actuallyBytesRead < 0) + { + errorMessages.push_back("Error detected when reading data, error string from socket"); + errorMessages.push_back(socket->errorString()); + + return false; + } + + bytesRead += actuallyBytesRead; + blockCount++; + } + else + { + if (!socket->waitForReadyRead()) + { + errorMessages.push_back("Waited for data for %1 milli seconds."); + errorMessages.push_back(socket->errorString()); + + return false; + } + } + } + + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RiaSocketDataTransfer::doubleValueCountInBlock() +{ + return 2000; +} + diff --git a/ApplicationCode/SocketInterface/RiaSocketDataTransfer.h b/ApplicationCode/SocketInterface/RiaSocketDataTransfer.h new file mode 100644 index 0000000000..06ae14b379 --- /dev/null +++ b/ApplicationCode/SocketInterface/RiaSocketDataTransfer.h @@ -0,0 +1,36 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Statoil ASA, Ceetron Solutions AS +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include +#include + +//================================================================================================== +/// Utility class used for transfer of data using QTcpSocket +/// +/// As the compile configuration for octave plugins is quite complex, +// the octave plugins includes the cpp-file to be able to compile only one file per plugin +//================================================================================================== +class RiaSocketDataTransfer +{ +public: + static size_t doubleValueCountInBlock(); + +public: + static bool writeBlockDataToSocket(QTcpSocket* socket, const char* data, quint64 bytesToWrite, QStringList& errorMessages); + static bool readBlockDataFromSocket(QTcpSocket* socket, char* data, quint64 bytesToRead, QStringList& errorMessages); +}; diff --git a/ApplicationCode/SocketInterface/RiaSocketTools.cpp b/ApplicationCode/SocketInterface/RiaSocketTools.cpp index 64cc8e0c11..86f7ce6086 100644 --- a/ApplicationCode/SocketInterface/RiaSocketTools.cpp +++ b/ApplicationCode/SocketInterface/RiaSocketTools.cpp @@ -38,8 +38,9 @@ #include "RimInputPropertyCollection.h" -#include +#include "RiaSocketDataTransfer.h" +#include //-------------------------------------------------------------------------------------------------- /// @@ -104,89 +105,28 @@ void RiaSocketTools::getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QStri } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- bool RiaSocketTools::writeBlockData(RiaSocketServer* server, QTcpSocket* socket, const char* data, quint64 bytesToWrite) { cvf::Timer timer; - quint64 bytesWritten = 0; - int blockCount = 0; - - quint64 maxBlockSize = RiaApplication::instance()->preferences()->blockSize(); - - - while (bytesWritten < bytesToWrite) - { - quint64 byteCountToWrite = qMin(bytesToWrite - bytesWritten, maxBlockSize); - - qint64 actuallyBytesWritten = socket->write(data + bytesWritten, byteCountToWrite); - if (actuallyBytesWritten < 0) - { - if (server) - { - QString errorMessage = "Error detected when writing data, error string from socket : \n" + socket->errorString(); - - server->errorMessageDialog()->showMessage(errorMessage); - } - - return false; - } - - bytesWritten += actuallyBytesWritten; - - blockCount++; - } + QStringList errorMessages; + bool writeSucceded = RiaSocketDataTransfer::writeBlockDataToSocket(socket, data, bytesToWrite, errorMessages); if (server) { + for (int i = 0; i < errorMessages.size(); i++) + { + server->errorMessageDialog()->showMessage(errorMessages[i]); + } + double totalTimeMS = timer.time() * 1000.0; - QString resultInfo = QString("Total time '%1 ms'\nTotal bytes written . %2\nNumber of blocks : %3\nBlock size : %4").arg(totalTimeMS).arg(bytesWritten).arg(blockCount).arg(maxBlockSize); + QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); server->errorMessageDialog()->showMessage(resultInfo); } - return true; + return writeSucceded; } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RiaSocketTools::readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages) -{ - quint64 bytesRead = 0; - int blockCount = 0; - - quint64 maxBlockSize = RiaApplication::instance()->preferences()->blockSize(); - - while (bytesRead < bytesToRead) - { - if (socket.bytesAvailable()) - { - quint64 byteCountToRead = qMin(bytesToRead - bytesRead, maxBlockSize); - - qint64 actuallyBytesRead = socket.read(data + bytesRead, byteCountToRead); - if (actuallyBytesRead < 0) - { - errorMessages.push_back("Error detected when writing data, error string from socket"); - errorMessages.push_back(socket.errorString()); - - return false; - } - - bytesRead += actuallyBytesRead; - blockCount++; - } - else - { - if (!socket.waitForReadyRead()) - { - errorMessages.push_back("Waited for data for %1 milli seconds."); - errorMessages.push_back(socket.errorString()); - - return false; - } - } - } - - return true; -} - diff --git a/ApplicationCode/SocketInterface/RiaSocketTools.h b/ApplicationCode/SocketInterface/RiaSocketTools.h index 5a24731237..b331799e2e 100644 --- a/ApplicationCode/SocketInterface/RiaSocketTools.h +++ b/ApplicationCode/SocketInterface/RiaSocketTools.h @@ -28,5 +28,4 @@ public: static void getCaseInfoFromCase(RimCase* rimCase, qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId); static bool writeBlockData(RiaSocketServer* server, QTcpSocket* socket, const char* data, quint64 bytesToWrite); - static bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages); }; diff --git a/OctavePlugin/CMakeLists.txt b/OctavePlugin/CMakeLists.txt index 7a11e18ab9..80d714789f 100644 --- a/OctavePlugin/CMakeLists.txt +++ b/OctavePlugin/CMakeLists.txt @@ -88,7 +88,7 @@ if (RESINSIGHT_OCTAVE_PLUGIN_QMAKE AND RESINSIGHT_OCTAVE_PLUGIN_MKOCTFILE) OUTPUT "${octFileName}" COMMAND call "\"%VS100COMNTOOLS%../../VC/vcvarsall.bat\"" x86 COMMAND ${CMAKE_COMMAND} ARGS -E chdir ${RESINSIGHT_OCTAVE_BIN_DIR} ${RESINSIGHT_OCTAVE_PLUGIN_MKOCTFILE} -I${OCTAVE_QT_QTNETWORK_INCLUDE_DIR} - -I${OCTAVE_QT_QTCORE_INCLUDE_DIR} -I${OCTAVE_QT_INCLUDE_DIR} ${RPATH_COMMAND} + -I${OCTAVE_QT_QTCORE_INCLUDE_DIR} -I${OCTAVE_QT_INCLUDE_DIR} -I${ResInsight_SOURCE_DIR}/ApplicationCode/SocketInterface ${RPATH_COMMAND} -L${OCTAVE_QT_LIBRARY_DIR} -lQtCore${QT_LIBRARY_POSTFIX} -lQtNetwork${QT_LIBRARY_POSTFIX} -o "${octFileName}" "${srcFileName}" DEPENDS "${srcFileName}" COMMENT "===> 32-bit x86 VS2010 : Generating ${octFileName}" @@ -97,7 +97,7 @@ if (RESINSIGHT_OCTAVE_PLUGIN_QMAKE AND RESINSIGHT_OCTAVE_PLUGIN_MKOCTFILE) add_custom_command( OUTPUT "${octFileName}" COMMAND ${CMAKE_COMMAND} ARGS -E chdir ${RESINSIGHT_OCTAVE_BIN_DIR} ${RESINSIGHT_OCTAVE_PLUGIN_MKOCTFILE} -I${OCTAVE_QT_QTNETWORK_INCLUDE_DIR} - -I${OCTAVE_QT_QTCORE_INCLUDE_DIR} -I${OCTAVE_QT_INCLUDE_DIR} ${RPATH_COMMAND} + -I${OCTAVE_QT_QTCORE_INCLUDE_DIR} -I${OCTAVE_QT_INCLUDE_DIR} -I${ResInsight_SOURCE_DIR}/ApplicationCode/SocketInterface ${RPATH_COMMAND} -L${OCTAVE_QT_LIBRARY_DIR} -lQtCore${QT_LIBRARY_POSTFIX} -lQtNetwork${QT_LIBRARY_POSTFIX} -o "${octFileName}" "${srcFileName}" DEPENDS "${srcFileName}" COMMENT "===> Generating ${octFileName}" @@ -107,7 +107,7 @@ if (RESINSIGHT_OCTAVE_PLUGIN_QMAKE AND RESINSIGHT_OCTAVE_PLUGIN_MKOCTFILE) add_custom_command( OUTPUT "${octFileName}" COMMAND OCTAVE_HOME=${OCTAVE_HOME} ${RESINSIGHT_OCTAVE_PLUGIN_MKOCTFILE} - -I${OCTAVE_QT_QTNETWORK_INCLUDE_DIR} -I${OCTAVE_QT_QTCORE_INCLUDE_DIR} -I${OCTAVE_QT_INCLUDE_DIR} ${RPATH_COMMAND} + -I${OCTAVE_QT_QTNETWORK_INCLUDE_DIR} -I${OCTAVE_QT_QTCORE_INCLUDE_DIR} -I${OCTAVE_QT_INCLUDE_DIR} -I${ResInsight_SOURCE_DIR}/ApplicationCode/SocketInterface ${RPATH_COMMAND} -L${OCTAVE_QT_LIBRARY_DIR} -lQtCore -lQtNetwork -o "${octFileName}" "${srcFileName}" DEPENDS "${srcFileName}" COMMENT "===> Generating ${octFileName}" From 8ea418272d7241469ed5bcab8fd6f84bc0a36a1e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 15 Apr 2014 13:04:57 +0200 Subject: [PATCH 47/51] Fixed invalid assert --- ApplicationCode/SocketInterface/RiaGeometryCommands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp index 2ca72a655d..c76bc690ae 100644 --- a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp @@ -276,7 +276,7 @@ public: } } - CVF_ASSERT(valueIndex, cellCount); + CVF_ASSERT(valueIndex == cellCount); RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } From b4821ed7a3baf58aed653c93367da5c7fe858d22 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 15 Apr 2014 13:40:53 +0200 Subject: [PATCH 48/51] Use block transfer for data transfer of cell properties --- .../RiaPropertyDataCommands.cpp | 98 ++++++++++++------- .../SocketInterface/RiaSocketDataTransfer.cpp | 13 ++- .../SocketInterface/RiaSocketTools.cpp | 8 +- OctavePlugin/CMakeLists.txt | 36 +++---- OctavePlugin/riGetActiveCellProperty.cpp | 45 +++------ OctavePlugin/riGetGridProperty.cpp | 6 +- OctavePlugin/riSetActiveCellProperty.cpp | 34 ++++--- OctavePlugin/riSetGridProperty.cpp | 52 +++++----- OctavePlugin/riSocketTools.h | 4 +- 9 files changed, 155 insertions(+), 141 deletions(-) diff --git a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp index 87cf148f7c..385ee7603d 100644 --- a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp @@ -42,6 +42,7 @@ #include #include "RiaApplication.h" #include "RiaPreferences.h" +#include "RiaSocketDataTransfer.h" //-------------------------------------------------------------------------------------------------- @@ -145,6 +146,9 @@ public: socketStream << timestepByteCount ; // Then write the data. + size_t valueCount = RiaSocketDataTransfer::doubleValueCountInBlock(); + std::vector values(valueCount); + size_t valueIndex = 0; size_t globalCellCount = activeInfo->globalCellCount(); for (size_t tIdx = 0; tIdx < requestedTimesteps.size(); ++tIdx) @@ -156,37 +160,34 @@ public: { if (resultIdx < scalarResultFrames->at(requestedTimesteps[tIdx]).size()) { - socketStream << scalarResultFrames->at(requestedTimesteps[tIdx])[resultIdx]; + values[valueIndex] = scalarResultFrames->at(requestedTimesteps[tIdx])[resultIdx]; } else { - socketStream << HUGE_VAL; + values[valueIndex] = HUGE_VAL; + } + + valueIndex++; + if (valueIndex >= valueCount) + { + if (!RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), valueIndex * sizeof(double))) + { + return false; + } + + valueIndex = 0; } } } } -#if 0 - // This aproach is faster but does not handle coarsening - size_t timestepResultCount = scalarResultFrames->front().size(); - quint64 timestepByteCount = (quint64)(timestepResultCount*sizeof(double)); - socketStream << timestepByteCount ; - // Then write the data. - - for (size_t tIdx = 0; tIdx < requestedTimesteps.size(); ++tIdx) + // Write remaining data + if (!RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), valueIndex * sizeof(double))) { -#if 1 // Write data as raw bytes, fast but does not handle byteswapping - server->currentClient()->write((const char *)scalarResultFrames->at(requestedTimesteps[tIdx]).data(), timestepByteCount); // Raw print of data. Fast but no platform conversion -#else // Write data using QDataStream, does byteswapping for us. Must use QDataStream on client as well - for (size_t cIdx = 0; cIdx < scalarResultFrames->at(requestedTimesteps[tIdx]).size(); ++cIdx) - { - socketStream << scalarResultFrames->at(tIdx)[cIdx]; - } -#endif + return false; } -#endif - } + } return true; } }; @@ -314,7 +315,9 @@ public: continue; } - std::vector values(rigGrid->cellCount()); + size_t valueCount = RiaSocketDataTransfer::doubleValueCountInBlock(); + std::vector values(valueCount); + size_t valueIndex = 0; for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) { double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); @@ -322,10 +325,24 @@ public: { cellValue = 0.0; } - values[cellIdx] = cellValue; + values[valueIndex++] = cellValue; + + if (valueIndex >= valueCount) + { + if (!RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), valueIndex * sizeof(double))) + { + return false; + } + + valueIndex = 0; + } } - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), values.size() * sizeof(double)); + // Write remaining data + if (!RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), valueIndex * sizeof(double))) + { + return false; + } } return true; @@ -552,16 +569,18 @@ public: internalMatrixData = m_scalarResultsToAdd->at(m_requestedTimesteps[m_currentTimeStepNumberToRead]).data(); } -#if 1 // Use raw data transfer. Faster. - bytesRead = currentClient->read((char*)(internalMatrixData), m_bytesPerTimeStepToRead); -#else - for (size_t cIdx = 0; cIdx < cellCountFromOctave; ++cIdx) + QStringList errorMessages; + if (!RiaSocketDataTransfer::readBlockDataFromSocket(currentClient, (char*)(internalMatrixData), m_bytesPerTimeStepToRead, errorMessages)) { - socketStream >> internalMatrixData[cIdx]; + for (int i = 0; i < errorMessages.size(); i++) + { + server->errorMessageDialog()->showMessage(errorMessages[i]); + } - if (socketStream.status() == QDataStream::Ok) bytesRead += sizeof(double); + currentClient->abort(); + return true; } -#endif + // Map data from active to result index based container ( Coarsening is active) if (isCoarseningActive) { @@ -576,12 +595,6 @@ public: } } - if ((int)m_bytesPerTimeStepToRead != bytesRead) - { - server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + - RiaSocketServer::tr("Could not read binary double data properly from socket")); - } - ++m_currentTimeStepNumberToRead; } @@ -896,8 +909,17 @@ public: std::vector doubleValues(cellCountFromOctave); - qint64 bytesRead = currentClient->read((char*)(doubleValues.data()), m_bytesPerTimeStepToRead); - size_t doubleValueIndex = 0; + QStringList errorMessages; + if (!RiaSocketDataTransfer::readBlockDataFromSocket(currentClient, (char*)(doubleValues.data()), m_bytesPerTimeStepToRead, errorMessages)) + { + for (int i = 0; i < errorMessages.size(); i++) + { + server->errorMessageDialog()->showMessage(errorMessages[i]); + } + + currentClient->abort(); + return true; + } cvf::ref cellCenterDataAccessObject = m_currentReservoir->reservoirData()->dataAccessObject(grid, m_porosityModelEnum, m_requestedTimesteps[m_currentTimeStepNumberToRead], m_currentScalarIndex); diff --git a/ApplicationCode/SocketInterface/RiaSocketDataTransfer.cpp b/ApplicationCode/SocketInterface/RiaSocketDataTransfer.cpp index c49ff5fa1f..8671f2e28d 100644 --- a/ApplicationCode/SocketInterface/RiaSocketDataTransfer.cpp +++ b/ApplicationCode/SocketInterface/RiaSocketDataTransfer.cpp @@ -18,6 +18,7 @@ #include "RiaSocketDataTransfer.h" + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -55,15 +56,12 @@ bool RiaSocketDataTransfer::writeBlockDataToSocket(QTcpSocket* socket, const cha bool RiaSocketDataTransfer::readBlockDataFromSocket(QTcpSocket* socket, char* data, quint64 bytesToRead, QStringList& errorMessages) { quint64 bytesRead = 0; - int blockCount = 0; - - quint64 maxBlockSize = doubleValueCountInBlock() * sizeof(double); while (bytesRead < bytesToRead) { if (socket->bytesAvailable()) { - quint64 byteCountToRead = qMin(bytesToRead - bytesRead, maxBlockSize); + quint64 byteCountToRead = bytesToRead - bytesRead; qint64 actuallyBytesRead = socket->read(data + bytesRead, byteCountToRead); if (actuallyBytesRead < 0) @@ -75,7 +73,6 @@ bool RiaSocketDataTransfer::readBlockDataFromSocket(QTcpSocket* socket, char* da } bytesRead += actuallyBytesRead; - blockCount++; } else { @@ -87,6 +84,12 @@ bool RiaSocketDataTransfer::readBlockDataFromSocket(QTcpSocket* socket, char* da return false; } } + +// Allow Octave process to end a long running Octave function +#ifdef octave_oct_h + OCTAVE_QUIT; +#endif + } return true; diff --git a/ApplicationCode/SocketInterface/RiaSocketTools.cpp b/ApplicationCode/SocketInterface/RiaSocketTools.cpp index 86f7ce6086..967c0b43b4 100644 --- a/ApplicationCode/SocketInterface/RiaSocketTools.cpp +++ b/ApplicationCode/SocketInterface/RiaSocketTools.cpp @@ -122,10 +122,10 @@ bool RiaSocketTools::writeBlockData(RiaSocketServer* server, QTcpSocket* socket, server->errorMessageDialog()->showMessage(errorMessages[i]); } - double totalTimeMS = timer.time() * 1000.0; - QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); - - server->errorMessageDialog()->showMessage(resultInfo); +// double totalTimeMS = timer.time() * 1000.0; +// QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); +// +// server->errorMessageDialog()->showMessage(resultInfo); } return writeSucceded; diff --git a/OctavePlugin/CMakeLists.txt b/OctavePlugin/CMakeLists.txt index 80d714789f..a49a9e21d0 100644 --- a/OctavePlugin/CMakeLists.txt +++ b/OctavePlugin/CMakeLists.txt @@ -6,26 +6,26 @@ set(CPP_SOURCES riGetActiveCellProperty.cpp riSetActiveCellProperty.cpp - riGetActiveCellInfo.cpp - riGetMainGridDimensions.cpp - riGetCurrentCase.cpp - riGetCaseGroups.cpp - riGetSelectedCases.cpp - riGetCases.cpp - riGetTimeStepDates.cpp - riGetTimeStepDays.cpp - riGetGridDimensions.cpp - riGetCoarseningInfo.cpp - riGetCellCenters.cpp - riGetActiveCellCenters.cpp - riGetCellCorners.cpp - riGetActiveCellCorners.cpp +# riGetActiveCellInfo.cpp +# riGetMainGridDimensions.cpp +# riGetCurrentCase.cpp +# riGetCaseGroups.cpp +# riGetSelectedCases.cpp +# riGetCases.cpp +# riGetTimeStepDates.cpp +# riGetTimeStepDays.cpp +# riGetGridDimensions.cpp +# riGetCoarseningInfo.cpp +# riGetCellCenters.cpp +# riGetActiveCellCenters.cpp +# riGetCellCorners.cpp +# riGetActiveCellCorners.cpp riGetGridProperty.cpp riSetGridProperty.cpp - riGetPropertyNames.cpp - riGetWellNames.cpp - riGetWellStatus.cpp - riGetWellCells.cpp +# riGetPropertyNames.cpp +# riGetWellNames.cpp +# riGetWellStatus.cpp +# riGetWellCells.cpp ) if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") diff --git a/OctavePlugin/riGetActiveCellProperty.cpp b/OctavePlugin/riGetActiveCellProperty.cpp index 81b966f7d0..573e324f12 100644 --- a/OctavePlugin/riGetActiveCellProperty.cpp +++ b/OctavePlugin/riGetActiveCellProperty.cpp @@ -1,7 +1,12 @@ #include +#include + #include + #include "riSettings.h" +#include "RiaSocketDataTransfer.cpp" // NB! Include cpp-file to avoid linking of additional file in oct-compile configuration + void getActiveCellProperty(Matrix& propertyFrames, const QString &serverName, quint16 serverPort, const qint64& caseId, QString propertyName, const int32NDArray& requestedTimeSteps, QString porosityModel) { @@ -63,44 +68,18 @@ void getActiveCellProperty(Matrix& propertyFrames, const QString &serverName, qu return; } - // Wait for available data for each timestep, then read data for each timestep + quint64 totalByteCount = byteCount * timestepCount; - for (size_t tIdx = 0; tIdx < timestepCount; ++tIdx) + double* internalMatrixData = propertyFrames.fortran_vec(); + QStringList errorMessages; + if (!RiaSocketDataTransfer::readBlockDataFromSocket(&socket, (char*)(internalMatrixData), totalByteCount, errorMessages)) { - while (socket.bytesAvailable() < (qint64)byteCount) + for (int i = 0; i < errorMessages.size(); i++) { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - error((("Waiting for timestep data number: ") + QString::number(tIdx)+ ": " + socket.errorString()).toLatin1().data()); - octave_stdout << "Active cells: " << activeCellCount << ", Timesteps: " << timestepCount << std::endl; - return ; - } - OCTAVE_QUIT; + error(errorMessages[i].toLatin1().data()); } - qint64 bytesRead = 0; - double * internalMatrixData = propertyFrames.fortran_vec(); - -#if 0 - // Raw data transfer. Faster. Not possible when dealing with coarsening - // bytesRead = socket.read((char*)(internalMatrixData + tIdx * activeCellCount), byteCount); -#else - // Compatible transfer. Now the only one working - for (size_t cIdx = 0; cIdx < activeCellCount; ++cIdx) - { - socketStream >> internalMatrixData[tIdx * activeCellCount + cIdx]; - - if (socketStream.status() == QDataStream::Ok) bytesRead += sizeof(double); - } -#endif - - if ((qint64)byteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - octave_stdout << "Active cells: " << activeCellCount << ", Timesteps: " << timestepCount << std::endl; - } - - OCTAVE_QUIT; + return; } QString tmp = QString("riGetActiveCellProperty : Read %1").arg(propertyName); diff --git a/OctavePlugin/riGetGridProperty.cpp b/OctavePlugin/riGetGridProperty.cpp index e477cd767a..075c36ee48 100644 --- a/OctavePlugin/riGetGridProperty.cpp +++ b/OctavePlugin/riGetGridProperty.cpp @@ -4,7 +4,7 @@ #include #include "riSettings.h" -#include "riSocketTools.h" +#include "RiaSocketDataTransfer.cpp" // NB! Include cpp-file to avoid linking of additional file in oct-compile configuration void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 serverPort, @@ -83,14 +83,14 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 double* internalMatrixData = propertyFrames.fortran_vec(); QStringList errorMessages; - if (!readBlockData(socket, (char*)(internalMatrixData), totalByteCount, errorMessages)) + if (!RiaSocketDataTransfer::readBlockDataFromSocket(&socket, (char*)(internalMatrixData), totalByteCount, errorMessages)) { for (int i = 0; i < errorMessages.size(); i++) { error(errorMessages[i].toLatin1().data()); } - OCTAVE_QUIT; + return; } QString tmp = QString("riGetGridProperty : Read %1").arg(propertyName); diff --git a/OctavePlugin/riSetActiveCellProperty.cpp b/OctavePlugin/riSetActiveCellProperty.cpp index 4953f25778..b4981a70cc 100644 --- a/OctavePlugin/riSetActiveCellProperty.cpp +++ b/OctavePlugin/riSetActiveCellProperty.cpp @@ -1,6 +1,10 @@ #include +#include + #include + #include "riSettings.h" +#include "RiaSocketDataTransfer.cpp" // NB! Include cpp-file to avoid linking of additional file in oct-compile configuration void setEclipseProperty(const Matrix& propertyFrames, const QString &hostName, quint16 port, @@ -47,27 +51,29 @@ void setEclipseProperty(const Matrix& propertyFrames, const QString &hostName, q socketStream << (qint64)timeStepByteCount; const double* internalData = propertyFrames.fortran_vec(); - qint64 dataWritten = socket.write((const char *)internalData, timeStepByteCount*timeStepCount); - if (dataWritten == timeStepByteCount*timeStepCount) + QStringList errorMessages; + if (!RiaSocketDataTransfer::writeBlockDataToSocket(&socket, (const char *)internalData, timeStepByteCount*timeStepCount, errorMessages)) { - QString tmp = QString("riSetActiveCellProperty : Wrote %1").arg(propertyName); + for (int i = 0; i < errorMessages.size(); i++) + { + octave_stdout << errorMessages[i].toStdString(); + } - if (caseId == -1) - { - tmp += QString(" to current case."); - } - else - { - tmp += QString(" to case with Id = %1.").arg(caseId); - } - octave_stdout << tmp.toStdString() << " Active Cells : " << cellCount << " Time steps : " << timeStepCount << std::endl; + return; + } + + QString tmp = QString("riSetActiveCellProperty : Wrote %1").arg(propertyName); + + if (caseId == -1) + { + tmp += QString(" to current case."); } else { - error("riSetActiveCellProperty : Was not able to write the proper amount of data to ResInsight:"); - octave_stdout << " Active Cells : " << cellCount << "Time steps : " << timeStepCount << " Data Written: " << dataWritten << " Should have written: " << timeStepCount * cellCount * sizeof(double) << std::endl; + tmp += QString(" to case with Id = %1.").arg(caseId); } + octave_stdout << tmp.toStdString() << " Active Cells : " << cellCount << " Time steps : " << timeStepCount << std::endl; while(socket.bytesToWrite() && socket.state() == QAbstractSocket::ConnectedState) { diff --git a/OctavePlugin/riSetGridProperty.cpp b/OctavePlugin/riSetGridProperty.cpp index f5afe0a0f7..8598d4b32e 100644 --- a/OctavePlugin/riSetGridProperty.cpp +++ b/OctavePlugin/riSetGridProperty.cpp @@ -1,6 +1,10 @@ #include +#include + #include + #include "riSettings.h" +#include "RiaSocketDataTransfer.cpp" // NB! Include cpp-file to avoid linking of additional file in oct-compile configuration void setEclipseProperty(const NDArray& propertyFrames, const QString &hostName, quint16 port, @@ -64,41 +68,41 @@ void setEclipseProperty(const NDArray& propertyFrames, const QString &hostName, socketStream << (qint64)singleTimeStepByteCount; const double* internalData = propertyFrames.fortran_vec(); - qint64 dataWritten = 0; - - for (size_t tsIdx = 0; tsIdx < timeStepCount; ++tsIdx) + + QStringList errorMessages; + if (!RiaSocketDataTransfer::writeBlockDataToSocket(&socket, (const char *)internalData, timeStepCount*singleTimeStepByteCount, errorMessages)) { - dataWritten += socket.write(((const char *)internalData) + tsIdx*singleTimeStepByteCount, singleTimeStepByteCount); + for (int i = 0; i < errorMessages.size(); i++) + { + octave_stdout << errorMessages[i].toStdString(); + } + + size_t cellCount = cellCountI * cellCountJ * cellCountK; + error("riSetGridProperty : Was not able to write the proper amount of data to ResInsight:"); + octave_stdout << " Cell count : " << cellCount << "Time steps : " << timeStepCount << std::endl; + + return; } - if (dataWritten == singleTimeStepByteCount*timeStepCount) + QString tmp = QString("riSetGridProperty : Wrote %1").arg(propertyName); + + if (caseId == -1) { - QString tmp = QString("riSetGridProperty : Wrote %1").arg(propertyName); - - if (caseId == -1) - { - tmp += QString(" to current case,"); - } - else - { - tmp += QString(" to case with Id = %1,").arg(caseId); - } - - tmp += QString(" grid index: %1, ").arg(gridIndex); - - octave_stdout << tmp.toStdString() << " Time steps : " << timeStepCount << std::endl; + tmp += QString(" to current case,"); } else { - size_t cellCount = cellCountI * cellCountJ * cellCountK; - error("riSetGridProperty : Was not able to write the proper amount of data to ResInsight:"); - octave_stdout << " Cell count : " << cellCount << "Time steps : " << timeStepCount << " Data Written: " << dataWritten << " Should have written: " << timeStepCount * cellCount * sizeof(double) << std::endl; + tmp += QString(" to case with Id = %1,").arg(caseId); } + + tmp += QString(" grid index: %1, ").arg(gridIndex); + + octave_stdout << tmp.toStdString() << " Time steps : " << timeStepCount << std::endl; while(socket.bytesToWrite() && socket.state() == QAbstractSocket::ConnectedState) { - octave_stdout << "Bytes to write: " << socket.bytesToWrite() << std::endl << std::flush; - socket.waitForBytesWritten(2000); +// octave_stdout << "Bytes to write: " << socket.bytesToWrite() << std::endl << std::flush; + socket.waitForBytesWritten(riOctavePlugin::longTimeOutMilliSecs); OCTAVE_QUIT; } diff --git a/OctavePlugin/riSocketTools.h b/OctavePlugin/riSocketTools.h index 63cc24d890..f142313c4f 100644 --- a/OctavePlugin/riSocketTools.h +++ b/OctavePlugin/riSocketTools.h @@ -2,7 +2,7 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages) +bool readBlockData_to_be_deleted(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages) { quint64 bytesRead = 0; int blockCount = 0; @@ -51,7 +51,7 @@ bool readBlockData(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringL //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool writeBlockData(QTcpSocket& socket, const char* data, quint64 bytesToWrite, QStringList& errorMessages) +bool writeBlockData_to_be_deleted(QTcpSocket& socket, const char* data, quint64 bytesToWrite, QStringList& errorMessages) { quint64 bytesWritten = 0; int blockCount = 0; From 476387fda42f8916dda0c2bba226da825b90805a Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 15 Apr 2014 14:03:41 +0200 Subject: [PATCH 49/51] Block transfer for active cell info --- .../SocketInterface/RiaCaseInfoCommands.cpp | 15 ++------------- OctavePlugin/riGetActiveCellInfo.cpp | 6 ++---- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp b/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp index e6444f314d..2426f95252 100644 --- a/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp @@ -132,20 +132,9 @@ public: quint64 timestepByteCount = (quint64)(timestepResultCount*sizeof(qint32)); socketStream << timestepByteCount; - // Then write the data. - for (size_t tIdx = 0; tIdx < columnCount; ++tIdx) - { -#if 1 // Write data as raw bytes, fast but does not handle byteswapping - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)activeCellInfo[tIdx].data(), timestepByteCount); - -#else // Write data using QDataStream, does byteswapping for us. Must use QDataStream on client as well - for (size_t cIdx = 0; cIdx < activeCellInfo[tIdx].size(); ++cIdx) - { - socketStream << activeCellInfo[tIdx][cIdx]; - } -#endif - } + // Write data as raw bytes, fast but does not handle byteswapping + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)activeCellInfo.data(), columnCount*timestepByteCount); return true; } diff --git a/OctavePlugin/riGetActiveCellInfo.cpp b/OctavePlugin/riGetActiveCellInfo.cpp index a7213a3697..8a9f4bc8eb 100644 --- a/OctavePlugin/riGetActiveCellInfo.cpp +++ b/OctavePlugin/riGetActiveCellInfo.cpp @@ -2,10 +2,8 @@ #include #include - #include "riSettings.h" -#include "riSocketTools.h" - +#include "RiaSocketDataTransfer.cpp" // NB! Include cpp-file to avoid linking of additional file in oct-compile configuration void getActiveCellInfo(int32NDArray& activeCellInfo, const QString &hostName, quint16 port, const qint64& caseId, const QString& porosityModel) { @@ -67,7 +65,7 @@ void getActiveCellInfo(int32NDArray& activeCellInfo, const QString &hostName, qu qint32* internalMatrixData = (qint32*)activeCellInfo.fortran_vec()->mex_get_data(); QStringList errorMessages; - if (!readBlockData(socket, (char*)(internalMatrixData), columnCount * byteCountForOneTimestep, errorMessages)) + if (!RiaSocketDataTransfer::readBlockDataFromSocket(&socket, (char*)(internalMatrixData), columnCount * byteCountForOneTimestep, errorMessages)) { for (int i = 0; i < errorMessages.size(); i++) { From c0f5d0090f5724d5296543abf2fc2fc72eb3b9c6 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 15 Apr 2014 14:16:35 +0200 Subject: [PATCH 50/51] Removed riSocketTools and updated use of block data transfer --- OctavePlugin/CMakeLists.txt | 45 +++++++------- OctavePlugin/riGetActiveCellCenters.cpp | 5 +- OctavePlugin/riGetActiveCellCorners.cpp | 4 +- OctavePlugin/riGetCellCenters.cpp | 5 +- OctavePlugin/riGetCellCorners.cpp | 4 +- OctavePlugin/riGetCurrentCase.cpp | 1 - OctavePlugin/riSocketTools.h | 80 ------------------------- 7 files changed, 31 insertions(+), 113 deletions(-) delete mode 100644 OctavePlugin/riSocketTools.h diff --git a/OctavePlugin/CMakeLists.txt b/OctavePlugin/CMakeLists.txt index a49a9e21d0..4ee4dcc138 100644 --- a/OctavePlugin/CMakeLists.txt +++ b/OctavePlugin/CMakeLists.txt @@ -4,28 +4,28 @@ # See http://www.cmake.org/Wiki/CMakeUserFindOctave set(CPP_SOURCES - riGetActiveCellProperty.cpp - riSetActiveCellProperty.cpp -# riGetActiveCellInfo.cpp -# riGetMainGridDimensions.cpp -# riGetCurrentCase.cpp -# riGetCaseGroups.cpp -# riGetSelectedCases.cpp -# riGetCases.cpp -# riGetTimeStepDates.cpp -# riGetTimeStepDays.cpp -# riGetGridDimensions.cpp -# riGetCoarseningInfo.cpp -# riGetCellCenters.cpp -# riGetActiveCellCenters.cpp -# riGetCellCorners.cpp -# riGetActiveCellCorners.cpp - riGetGridProperty.cpp - riSetGridProperty.cpp -# riGetPropertyNames.cpp -# riGetWellNames.cpp -# riGetWellStatus.cpp -# riGetWellCells.cpp + riGetActiveCellProperty.cpp + riSetActiveCellProperty.cpp + riGetActiveCellInfo.cpp + riGetMainGridDimensions.cpp + riGetCurrentCase.cpp + riGetCaseGroups.cpp + riGetSelectedCases.cpp + riGetCases.cpp + riGetTimeStepDates.cpp + riGetTimeStepDays.cpp + riGetGridDimensions.cpp + riGetCoarseningInfo.cpp + riGetCellCenters.cpp + riGetActiveCellCenters.cpp + riGetCellCorners.cpp + riGetActiveCellCorners.cpp + riGetGridProperty.cpp + riSetGridProperty.cpp + riGetPropertyNames.cpp + riGetWellNames.cpp + riGetWellStatus.cpp + riGetWellCells.cpp ) if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") @@ -143,7 +143,6 @@ if (RESINSIGHT_OCTAVE_PLUGIN_QMAKE AND RESINSIGHT_OCTAVE_PLUGIN_MKOCTFILE) "${CMAKE_CURRENT_BINARY_DIR}/riGetWellCells.oct" SOURCES ${CPP_SOURCES} - riSocketTools.h riSettings.h ) diff --git a/OctavePlugin/riGetActiveCellCenters.cpp b/OctavePlugin/riGetActiveCellCenters.cpp index a98ba06bac..862172ba0a 100644 --- a/OctavePlugin/riGetActiveCellCenters.cpp +++ b/OctavePlugin/riGetActiveCellCenters.cpp @@ -4,7 +4,7 @@ #include #include "riSettings.h" -#include "riSocketTools.h" +#include "RiaSocketDataTransfer.cpp" // NB! Include cpp-file to avoid linking of additional file in oct-compile configuration void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const QString& porosityModel) @@ -66,7 +66,8 @@ void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, qu double* internalMatrixData = cellCenterValues.fortran_vec(); QStringList errorMessages; - if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) + + if (!RiaSocketDataTransfer::readBlockDataFromSocket(&socket, (char*)(internalMatrixData), byteCount, errorMessages)) { for (int i = 0; i < errorMessages.size(); i++) { diff --git a/OctavePlugin/riGetActiveCellCorners.cpp b/OctavePlugin/riGetActiveCellCorners.cpp index 47ffad52bc..d018310285 100644 --- a/OctavePlugin/riGetActiveCellCorners.cpp +++ b/OctavePlugin/riGetActiveCellCorners.cpp @@ -4,7 +4,7 @@ #include #include "riSettings.h" -#include "riSocketTools.h" +#include "RiaSocketDataTransfer.cpp" // NB! Include cpp-file to avoid linking of additional file in oct-compile configuration void getActiveCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 port, const qint32& caseId, const QString& porosityModel) @@ -66,7 +66,7 @@ void getActiveCellCorners(NDArray& cellCornerValues, const QString &hostName, qu double* internalMatrixData = cellCornerValues.fortran_vec(); QStringList errorMessages; - if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) + if (!RiaSocketDataTransfer::readBlockDataFromSocket(&socket, (char*)(internalMatrixData), byteCount, errorMessages)) { for (int i = 0; i < errorMessages.size(); i++) { diff --git a/OctavePlugin/riGetCellCenters.cpp b/OctavePlugin/riGetCellCenters.cpp index 4f57d08a2b..a8255b6fb5 100644 --- a/OctavePlugin/riGetCellCenters.cpp +++ b/OctavePlugin/riGetCellCenters.cpp @@ -4,7 +4,7 @@ #include #include "riSettings.h" -#include "riSocketTools.h" +#include "RiaSocketDataTransfer.cpp" // NB! Include cpp-file to avoid linking of additional file in oct-compile configuration void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex) @@ -69,10 +69,9 @@ void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 dv(3) = 3; cellCenterValues.resize(dv); - double* internalMatrixData = cellCenterValues.fortran_vec(); QStringList errorMessages; - if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) + if (!RiaSocketDataTransfer::readBlockDataFromSocket(&socket, (char*)(internalMatrixData), byteCount, errorMessages)) { for (int i = 0; i < errorMessages.size(); i++) { diff --git a/OctavePlugin/riGetCellCorners.cpp b/OctavePlugin/riGetCellCorners.cpp index 2571371a76..2ed5d264b9 100644 --- a/OctavePlugin/riGetCellCorners.cpp +++ b/OctavePlugin/riGetCellCorners.cpp @@ -4,7 +4,7 @@ #include #include "riSettings.h" -#include "riSocketTools.h" +#include "RiaSocketDataTransfer.cpp" // NB! Include cpp-file to avoid linking of additional file in oct-compile configuration @@ -74,7 +74,7 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 double* internalMatrixData = cellCornerValues.fortran_vec(); QStringList errorMessages; - if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) + if (!RiaSocketDataTransfer::readBlockDataFromSocket(&socket, (char*)(internalMatrixData), byteCount, errorMessages)) { for (int i = 0; i < errorMessages.size(); i++) { diff --git a/OctavePlugin/riGetCurrentCase.cpp b/OctavePlugin/riGetCurrentCase.cpp index 88cc38088d..80b0ffe4ac 100644 --- a/OctavePlugin/riGetCurrentCase.cpp +++ b/OctavePlugin/riGetCurrentCase.cpp @@ -3,7 +3,6 @@ #include #include "riSettings.h" -#include "riSocketTools.h" void getCurrentCase(qint64& caseId, QString& caseName, QString& caseType, qint64& caseGroupId, const QString &hostName, quint16 port) { diff --git a/OctavePlugin/riSocketTools.h b/OctavePlugin/riSocketTools.h deleted file mode 100644 index f142313c4f..0000000000 --- a/OctavePlugin/riSocketTools.h +++ /dev/null @@ -1,80 +0,0 @@ - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool readBlockData_to_be_deleted(QTcpSocket& socket, char* data, quint64 bytesToRead, QStringList& errorMessages) -{ - quint64 bytesRead = 0; - int blockCount = 0; - - quint64 maxBlockSize = riOctavePlugin::socketMaxByteCount; - - while (bytesRead < bytesToRead) - { - if (socket.bytesAvailable()) - { - quint64 byteCountToRead = qMin(bytesToRead - bytesRead, maxBlockSize); - - qint64 actuallyBytesRead = socket.read(data + bytesRead, byteCountToRead); - if (actuallyBytesRead < 0) - { - errorMessages.push_back("Error detected when reading data, error string from socket :"); - errorMessages.push_back(socket.errorString()); - - return false; - } - - bytesRead += actuallyBytesRead; - - octave_stdout << "Bytes read " << bytesRead << " of total " << bytesToRead << std::endl; - - blockCount++; - } - else - { - if (!socket.waitForReadyRead()) - { - errorMessages.push_back("Waited for data for %1 milli seconds."); - errorMessages.push_back(socket.errorString()); - - return false; - } - } - } - - octave_stdout << "Bytes read " << bytesToRead << std::endl; - - return true; -} - - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool writeBlockData_to_be_deleted(QTcpSocket& socket, const char* data, quint64 bytesToWrite, QStringList& errorMessages) -{ - quint64 bytesWritten = 0; - int blockCount = 0; - - quint64 maxBlockSize = riOctavePlugin::socketMaxByteCount; - - while (bytesWritten < bytesToWrite) - { - quint64 byteCountToWrite = qMin(bytesToWrite - bytesWritten, maxBlockSize); - - qint64 actuallyBytesWritten = socket.write(data + bytesWritten, byteCountToWrite); - if (actuallyBytesWritten < 0) - { - errorMessages.push_back("Error detected when writing data, error string from socket"); - errorMessages.push_back(socket.errorString()); - - return false; - } - - bytesWritten += actuallyBytesWritten; - - blockCount++; - } - - return true; -} From 8eb040e7cb0ec9b834fe5cbeab84bd87946db2a3 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 15 Apr 2014 16:20:21 +0200 Subject: [PATCH 51/51] Fixed block transfer --- ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp b/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp index 2426f95252..e81b9db3ea 100644 --- a/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaCaseInfoCommands.cpp @@ -132,9 +132,10 @@ public: quint64 timestepByteCount = (quint64)(timestepResultCount*sizeof(qint32)); socketStream << timestepByteCount; - - // Write data as raw bytes, fast but does not handle byteswapping - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)activeCellInfo.data(), columnCount*timestepByteCount); + for (size_t tIdx = 0; tIdx < columnCount; ++tIdx) + { + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)activeCellInfo[tIdx].data(), timestepByteCount); + } return true; }