diff --git a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp index d1f952bb07..e26e183587 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp +++ b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp @@ -35,6 +35,7 @@ #include "ecl_kw_magic.h" #include "cafProgressInfo.h" +#include //-------------------------------------------------------------------------------------------------- /// ECLIPSE cell numbering layout: @@ -153,7 +154,7 @@ bool transferGridCellData(RigMainGrid* mainGrid, RigActiveCellInfo* activeCellIn const ecl_grid_type* subGrid = ecl_grid_get_cell_lgr1(localEclGrid, localCellIdx); if (subGrid != NULL) { - int subGridFileIndex = ecl_grid_get_grid_nr(subGrid); + int subGridFileIndex = ecl_grid_get_lgr_nr(subGrid); CVF_ASSERT(subGridFileIndex > 0); cell.setSubGrid(static_cast(mainGrid->gridByIndex(subGridFileIndex))); } @@ -366,14 +367,10 @@ bool RifReaderEclipseOutput::open(const QString& fileName, RigCaseData* eclipseC if (!transferGeometry(mainEclGrid, eclipseCase)) return false; progInfo.incrementProgress(); - progInfo.setProgressDescription("Releasing reader memory"); - ecl_grid_free( mainEclGrid ); - progInfo.incrementProgress(); + m_eclipseCase = eclipseCase; progInfo.setProgressDescription("Reading Result index"); progInfo.setNextProgressIncrement(60); - - m_eclipseCase = eclipseCase; // Build results meta data buildMetaData(); @@ -381,9 +378,11 @@ bool RifReaderEclipseOutput::open(const QString& fileName, RigCaseData* eclipseC progInfo.setNextProgressIncrement(8); progInfo.setProgressDescription("Reading Well information"); - - readWellCells(); + readWellCells(mainEclGrid); + progInfo.setProgressDescription("Releasing reader memory"); + ecl_grid_free( mainEclGrid ); + progInfo.incrementProgress(); return true; } @@ -719,16 +718,263 @@ bool RifReaderEclipseOutput::dynamicResult(const QString& result, PorosityModelR return true; } + + +// Helper structure to handle the metadata for connections in segments +struct SegmentData +{ + SegmentData(const well_conn_collection_type* connections) : + m_branchId(-1), + m_segmentId(-1), + //m_gridIndex(cvf::UNDEFINED_SIZE_T), + m_connections(connections) + {} + + int m_branchId; + int m_segmentId; + //size_t m_gridIndex; + const well_conn_collection_type* m_connections; +}; + +struct SegmentTreeNode +{ + SegmentTreeNode() : outletSegment(NULL), mainChildSegment(NULL) {} + std::vector connections; + + SegmentTreeNode* outletSegment; + SegmentTreeNode* mainChildSegment; + std::vector additionalChildSegments; +}; + + +struct SegmentPositionContribution +{ + SegmentPositionContribution( int connectionSegmentId, + cvf::Vec3d connectionPosition, + double lengthFromConnection, + bool isInsolating, + int segmentIdUnder, + int segmentIdAbove, + bool isFromAbove) + : m_connectionSegmentId(connectionSegmentId), + m_lengthFromConnection(lengthFromConnection), + m_isInsolating(isInsolating), + m_connectionPosition(connectionPosition), + m_segmentIdUnder(segmentIdUnder), + m_segmentIdAbove(segmentIdAbove), + m_isFromAbove(isFromAbove) + {} + + int m_connectionSegmentId; + double m_lengthFromConnection; + bool m_isInsolating; + cvf::Vec3d m_connectionPosition; + int m_segmentIdUnder; + int m_segmentIdAbove; + bool m_isFromAbove; +}; + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RigWellResultPoint RifReaderEclipseOutput::createWellResultPoint(const RigGridBase* grid, const well_conn_type* ert_connection, int ertBranchId, int ertSegmentId) +{ + CVF_ASSERT(ert_connection); + CVF_ASSERT(grid); + + RigWellResultPoint resultPoint; + int cellI = well_conn_get_i( ert_connection ); + int cellJ = well_conn_get_j( ert_connection ); + int cellK = well_conn_get_k( ert_connection ); + bool isCellOpen = well_conn_open( ert_connection ); + + // If a well is defined in fracture region, the K-value is from (cellCountK - 1) -> cellCountK*2 - 1 + // Adjust K so index is always in valid grid region + if (cellK >= static_cast(grid->cellCountK())) + { + cellK -= static_cast(grid->cellCountK()); + } + + // The K value might also be -1. It is not yet known why, or what it is supposed to mean, + // but for now we will interpret as 0. + // TODO: Ask Joakim Haave regarding this. + if (cellK < 0) cellK = 0; + + resultPoint.m_gridIndex = grid->gridIndex(); + resultPoint.m_gridCellIndex = grid->cellIndexFromIJK(cellI, cellJ, cellK); + + resultPoint.m_isOpen = isCellOpen; + + resultPoint.m_ertBranchId = ertBranchId; + resultPoint.m_ertSegmentId = ertSegmentId; + + return resultPoint; +} + + +void getSegmentDataByBranchId(const std::list& segments, std::vector& branchSegments, int branchId) +{ + std::list::const_iterator it; + + for (it = segments.begin(); it != segments.end(); it++) + { + if (it->m_branchId == branchId) + { + branchSegments.push_back(*it); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// Inverse distance interpolation of the supplied points and distance weights +//-------------------------------------------------------------------------------------------------- +cvf::Vec3d interpolate3DPosition(const std::vector positions) +{ + std::vector filteredPositions; + filteredPositions.reserve(positions.size()); + + bool hasContibFromBelow = false; + bool hasContribFromAbove = false; + double minDistFromContribAbove = HUGE_VAL; + double minDistFromContribBelow = HUGE_VAL; + std::vector contrFromAbove; + std::vector contrFromBelow; + + + for (size_t i = 0; i < positions.size(); i++) + { + if (positions[i].m_connectionPosition != cvf::Vec3d::UNDEFINED) + { + if (positions[i].m_isFromAbove && positions[i].m_lengthFromConnection < minDistFromContribAbove) + { + if (contrFromAbove.size()) contrFromAbove[0] = positions[i]; + else contrFromAbove.push_back(positions[i]); + + minDistFromContribAbove = positions[i].m_lengthFromConnection; + } + + if (! positions[i].m_isFromAbove && positions[i].m_lengthFromConnection < minDistFromContribBelow) + { + if (contrFromBelow.size()) contrFromBelow[0] = positions[i]; + else contrFromBelow.push_back(positions[i]); + + minDistFromContribBelow = positions[i].m_lengthFromConnection; + + } + } + } + + filteredPositions = contrFromAbove; + filteredPositions.insert(filteredPositions.end(), contrFromBelow.begin(), contrFromBelow.end()); + + std::vector nominators(filteredPositions.size(), 0.0); + + double denominator = 0.0; + cvf::Vec3d interpolatedValue = cvf::Vec3d::ZERO; + double distance; + + for (size_t i = 0; i < filteredPositions.size(); i++) + { +#if 0 // Pure average test + nominators[i] = 1.0; +#else + distance = filteredPositions[i].m_lengthFromConnection; + + if (distance < 1e-6) + { + return filteredPositions[i].m_connectionPosition; + } + else if (distance < 1.0) + { + //distance = 1.0; + } + + + distance = 1.0 / distance; + nominators[i] = distance; + denominator += distance; + +#endif + } +#if 0 // Pure average test + denominator = positions.size(); // Pure average test +#endif + for (size_t i = 0; i < filteredPositions.size(); i++) + { + interpolatedValue += (nominators[i]/denominator) * filteredPositions[i].m_connectionPosition; + } + + return interpolatedValue; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void propagatePosContribDownwards(std::map > & segmentIdToPositionContrib, + const well_segment_collection_type * allErtSegments, + int ertSegmentId, + std::vector posContrib) +{ + + std::map >::iterator posContribIt; + posContribIt = segmentIdToPositionContrib.find(ertSegmentId); + + + if ( posContribIt != segmentIdToPositionContrib.end()) + { + // Create a set of the segments below this, that has to be followed. + + std::set segmentIdsBelow; + for (size_t i = 0 ; i < posContribIt->second.size(); ++i) + { + segmentIdsBelow.insert(posContribIt->second[i].m_segmentIdUnder); + } + + // Get the segment length to add to the contributions + + well_segment_type *segment = well_segment_collection_get( allErtSegments , posContribIt->first); + double sementLength = well_segment_get_length(segment); + + // If we do not have the contribution represented, add it, and accumulate the length + // If it is already present, do not touch + for (size_t i = 0; i < posContrib.size(); ++i) + { + bool foundContribution = false; + for (size_t j = 0 ; j < posContribIt->second.size(); ++j) + { + if (posContribIt->second[j].m_connectionSegmentId == posContrib[i].m_connectionSegmentId) + { + foundContribution = true; + break; + } + } + + if (! foundContribution) + { + posContrib[i].m_lengthFromConnection += sementLength; + posContrib[i].m_isFromAbove = true; + posContribIt->second.push_back(posContrib[i]); + } + posContrib[i].m_segmentIdAbove = ertSegmentId; + } + + for (std::set::iterator it = segmentIdsBelow.begin(); it != segmentIdsBelow.end(); ++it) + { + propagatePosContribDownwards(segmentIdToPositionContrib, allErtSegments, (*it), posContrib); + } + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RifReaderEclipseOutput::readWellCells() +void RifReaderEclipseOutput::readWellCells(const ecl_grid_type* mainEclGrid) { CVF_ASSERT(m_eclipseCase); if (m_dynamicResultsAccess.isNull()) return; - well_info_type* ert_well_info = well_info_alloc(NULL); + well_info_type* ert_well_info = well_info_alloc(mainEclGrid); if (!ert_well_info) return; m_dynamicResultsAccess->readWellData(ert_well_info); @@ -794,91 +1040,733 @@ void RifReaderEclipseOutput::readWellCells() wellResFrame.m_isOpen = well_state_is_open( ert_well_state ); - - - // Loop over all the grids in the model. If we have connections in one, we will discard - // the maingrid connections as they are "duplicates" - - bool hasWellConnectionsInLGR = false; - for (size_t gridNr = 1; gridNr < grids.size(); ++gridNr) - { - int branchCount = well_state_iget_lgr_num_branches(ert_well_state, static_cast(gridNr)); - if (branchCount > 0) - { - hasWellConnectionsInLGR = true; - break; - } - } - size_t gridNr = hasWellConnectionsInLGR ? 1 : 0; - for (; gridNr < grids.size(); ++gridNr) + if (well_state_is_MSW(ert_well_state)) { + wellResults->setMultiSegmentWell(true); - // Wellhead. If several grids have a wellhead definition for this well, we use tha last one. (Possibly the innermost LGR) - const well_conn_type* ert_wellhead = well_state_iget_wellhead(ert_well_state, static_cast(gridNr)); - if (ert_wellhead) - { - int cellI = well_conn_get_i( ert_wellhead ); - int cellJ = well_conn_get_j( ert_wellhead ); - int cellK = CVF_MAX(0, well_conn_get_k(ert_wellhead)); // Why this ? +#if 1 + // how do we handle LGR-s ? + // 1. Create separate visual branches for each Grid, with its own wellhead + // 2. Always use the connections to the grid with the highest number (innermost LGR). + // 3. Handle both and switch between them according to visual settings of grid visualization + // Will there ever exist connections to different grids for the same segment ? + // We have currently selected 2. - // If a well is defined in fracture region, the K-value is from (cellCountK - 1) -> cellCountK*2 - 1 - // Adjust K so index is always in valid grid region - if (cellK >= static_cast(grids[gridNr]->cellCountK())) + // Set the wellhead + + int lastGridNr = static_cast(grids.size()) - 1; + for (int gridNr = lastGridNr; gridNr >= 0; --gridNr) + { + // If several grids have a wellhead definition for this well, we use the last one. + // (Possibly the innermost LGR) + + const well_conn_type* ert_wellhead = well_state_iget_wellhead(ert_well_state, static_cast(gridNr)); + if (ert_wellhead) { - cellK -= static_cast(grids[gridNr]->cellCountK()); + wellResFrame.m_wellHead = createWellResultPoint(grids[gridNr], ert_wellhead, -1, -1 ); + break; } - - wellResFrame.m_wellHead.m_gridCellIndex = grids[gridNr]->cellIndexFromIJK(cellI, cellJ, cellK); - wellResFrame.m_wellHead.m_gridIndex = gridNr; } + well_branch_collection_type* branches = well_state_get_branches(ert_well_state); + int branchCount = well_branch_collection_get_size(branches); + wellResFrame.m_wellResultBranches.resize( branchCount); + std::map > segmentIdToPositionContrib; + std::vector upperSegmentIdsOfUnpositionedSegementGroup; - int branchCount = well_state_iget_lgr_num_branches(ert_well_state, static_cast(gridNr)); - if (branchCount > 0) + // For each branch, go from bottom segment upwards and transfer their connections to WellResultpoints. + // If they have no connections, create a resultpoint representing their bottom position, which will + // receive an actual position at a later stage. + // I addition, distribute contributions for calculating segment bottom positions from bottom and up. + + + for (int bIdx = 0; bIdx < well_branch_collection_get_size(branches); bIdx++) { - if (static_cast(wellResFrame.m_wellResultBranches.size()) < branchCount) wellResFrame.m_wellResultBranches.resize(branchCount); + RigWellResultBranch& wellResultBranch = wellResFrame.m_wellResultBranches[ bIdx]; - for (int branchIdx = 0; branchIdx < branchCount; ++branchIdx ) + const well_segment_type* segment = well_branch_collection_iget_start_segment(branches, bIdx); + + int branchId = well_segment_get_branch_id(segment); + wellResultBranch.m_ertBranchId = branchId; + + // Data for segment position calculation + int lastConnectionSegmentId = -1; + cvf::Vec3d lastConnectionPos = cvf::Vec3d::UNDEFINED; + cvf::Vec3d lastConnectionCellCorner= cvf::Vec3d::UNDEFINED; + double lastConnectionCellSize = 0; + double accLengthFromLastConnection = 0; + int segmentIdBelow = -1; + bool segmentBelowHasConnections = false; + std::set ertSegIdsOfPosContribToRemove; + + + while (segment && branchId == well_segment_get_branch_id(segment)) { - // Connections - int connectionCount = well_state_iget_num_lgr_connections(ert_well_state, static_cast(gridNr), branchIdx); - if (connectionCount > 0) + // Loop backwards, making us select the connection in the innermost lgr as the truth + bool segmentHasConnections = false; + + for (int gridNr = lastGridNr; gridNr >= 0; --gridNr) { + std::string gridName = this->ertGridName(gridNr); - RigWellResultBranch& wellSegment = wellResFrame.m_wellResultBranches[branchIdx]; // Is this completely right? Is the branch index actually the same between lgrs ? - wellSegment.m_branchNumber = branchIdx; - size_t existingConnCount = wellSegment.m_wellCells.size(); - wellSegment.m_wellCells.resize(existingConnCount + connectionCount); + // If this segment has connections in any grid, transfer the innermost ones - int connIdx; - for (connIdx = 0; connIdx < connectionCount; connIdx++) + if (well_segment_has_grid_connections(segment, gridName.data())) { - const well_conn_type* ert_connection = well_state_iget_lgr_connections( ert_well_state, static_cast(gridNr), branchIdx)[connIdx]; - CVF_ASSERT(ert_connection); + const well_conn_collection_type* connections = well_segment_get_connections(segment, gridName.data()); + int connectionCount = well_conn_collection_get_size(connections); - RigWellResultCell& data = wellSegment.m_wellCells[existingConnCount + connIdx]; - data.m_gridIndex = gridNr; + // Loop backwards to put the deepest connections first in the array. (The segments are also traversed deep to shallow) + for (int connIdx = connectionCount-1; connIdx >= 0; connIdx--) { - int cellI = well_conn_get_i( ert_connection ); - int cellJ = well_conn_get_j( ert_connection ); - int cellK = well_conn_get_k( ert_connection ); - bool open = well_conn_open( ert_connection ); - int branch = well_conn_get_branch( ert_connection ); - int segment = well_conn_get_segment( ert_connection ); - - // If a well is defined in fracture region, the K-value is from (cellCountK - 1) -> cellCountK*2 - 1 - // Adjust K so index is always in valid grid region - if (cellK >= static_cast(grids[gridNr]->cellCountK())) + well_conn_type* ert_connection = well_conn_collection_iget(connections, connIdx); + wellResultBranch.m_branchResultPoints.push_back( + createWellResultPoint(grids[gridNr], ert_connection, branchId, well_segment_get_id(segment))); + } + + segmentHasConnections = true; + + // Prepare data for segment position calculation + + well_conn_type* ert_connection = well_conn_collection_iget(connections, 0); + RigWellResultPoint point = createWellResultPoint(grids[gridNr], ert_connection, branchId, well_segment_get_id(segment)); + lastConnectionPos = grids[gridNr]->cell(point.m_gridCellIndex).center(); + cvf::Vec3d cellVxes[8]; + grids[gridNr]->cellCornerVertices(point.m_gridCellIndex, cellVxes); + lastConnectionCellCorner = cellVxes[0]; + lastConnectionCellSize = (lastConnectionPos - cellVxes[0]).length(); + + + lastConnectionSegmentId = well_segment_get_id(segment); + accLengthFromLastConnection = well_segment_get_length(segment)/(connectionCount+1); + if ( ! segmentBelowHasConnections) upperSegmentIdsOfUnpositionedSegementGroup.push_back(segmentIdBelow); + + break; // Stop looping over grids + } + } + + // If the segment did not have connections at all, we need to create a resultpoint representing the bottom of the segment + // and store it as an unpositioned segment + + if (!segmentHasConnections) + { + RigWellResultPoint data; + data.m_ertBranchId = branchId; + data.m_ertSegmentId = well_segment_get_id(segment); + + wellResultBranch.m_branchResultPoints.push_back(data); + + // Store data for segment position calculation + bool isAnInsolationContribution = accLengthFromLastConnection < lastConnectionCellSize; + + + segmentIdToPositionContrib[well_segment_get_id(segment)].push_back( + SegmentPositionContribution(lastConnectionSegmentId, lastConnectionPos, accLengthFromLastConnection, isAnInsolationContribution, segmentIdBelow, -1, false)); + accLengthFromLastConnection += well_segment_get_length(segment); + + } + + segmentIdBelow = well_segment_get_id(segment); + segmentBelowHasConnections = segmentHasConnections; + + if (well_segment_get_outlet_id(segment) == -1) + { + segment = NULL; + } + else + { + segment = well_segment_get_outlet(segment); + } + } + + // Add resultpoint representing the outlet segment (bottom), if not the branch ends at the wellhead. + + const well_segment_type* outletSegment = segment; + + if (outletSegment) + { + bool outletSegmentHasConnections = false; + + for (int gridNr = lastGridNr; gridNr >= 0; --gridNr) + { + std::string gridName = this->ertGridName(gridNr); + + // If this segment has connections in any grid, use the deepest innermost one + + if (well_segment_has_grid_connections(outletSegment, gridName.data())) + { + const well_conn_collection_type* connections = well_segment_get_connections(outletSegment, gridName.data()); + int connectionCount = well_conn_collection_get_size(connections); + + // Select the deepest connection + well_conn_type* ert_connection = well_conn_collection_iget(connections, connectionCount-1); + wellResultBranch.m_branchResultPoints.push_back( + createWellResultPoint(grids[gridNr], ert_connection, branchId, well_segment_get_id(outletSegment))); + + outletSegmentHasConnections = true; + break; // Stop looping over grids + } + } + + if (!outletSegmentHasConnections) + { + // Store the result point + + RigWellResultPoint data; + data.m_ertBranchId = well_segment_get_branch_id(outletSegment); + data.m_ertSegmentId = well_segment_get_id(outletSegment); + wellResultBranch.m_branchResultPoints.push_back(data); + + // Store data for segment position calculation, and propagate it upwards until we meet a segment with connections + + bool isAnInsolationContribution = accLengthFromLastConnection < lastConnectionCellSize; + + cvf::Vec3d lastConnectionPosWOffset = lastConnectionPos; + if (isAnInsolationContribution) lastConnectionPosWOffset += 0.4*(lastConnectionCellCorner-lastConnectionPos); + + segmentIdToPositionContrib[well_segment_get_id(outletSegment)].push_back( + SegmentPositionContribution(lastConnectionSegmentId, lastConnectionPosWOffset, accLengthFromLastConnection, isAnInsolationContribution, segmentIdBelow, -1, false)); + + /// Loop further to add this position contribution until a segment with connections is found + + accLengthFromLastConnection += well_segment_get_length(outletSegment); + segmentIdBelow = well_segment_get_id(outletSegment); + + const well_segment_type* aboveOutletSegment = NULL; + + if (well_segment_get_outlet_id(outletSegment) == -1) + { + aboveOutletSegment = NULL; + } + else + { + aboveOutletSegment = well_segment_get_outlet(outletSegment); + } + + while (aboveOutletSegment ) + { + // Loop backwards, just because we do that the other places + bool segmentHasConnections = false; + + for (int gridNr = lastGridNr; gridNr >= 0; --gridNr) { - cellK -= static_cast(grids[gridNr]->cellCountK()); + std::string gridName = this->ertGridName(gridNr); + + // If this segment has connections in any grid, stop traversal + + if (well_segment_has_grid_connections(aboveOutletSegment, gridName.data())) + { + segmentHasConnections = true; + break; + } } - data.m_gridCellIndex = grids[gridNr]->cellIndexFromIJK(cellI , cellJ , cellK); - - data.m_isOpen = open; - data.m_branchId = branch; - data.m_segmentId = segment; + if (!segmentHasConnections) + { + segmentIdToPositionContrib[well_segment_get_id(aboveOutletSegment)].push_back( + SegmentPositionContribution(lastConnectionSegmentId, lastConnectionPos, accLengthFromLastConnection, isAnInsolationContribution, segmentIdBelow, -1, false)); + accLengthFromLastConnection += well_segment_get_length(aboveOutletSegment); + } + else + { + break; // We have found a segment with connections. We do not need to propagate position contributions further + } + + segmentIdBelow = well_segment_get_id(aboveOutletSegment); + + if (well_segment_get_outlet_id(aboveOutletSegment) == -1) + { + aboveOutletSegment = NULL; + } + else + { + aboveOutletSegment = well_segment_get_outlet(aboveOutletSegment); + } } + + + } + } + else + { + // Add wellhead as result point Nope. Not Yet, but it is a good idea. + // The centerline calculations would be a bit simpler, I think. + } + + // Reverse the order of the resultpoints in this branch, making the deepest come last + + std::reverse(wellResultBranch.m_branchResultPoints.begin(), wellResultBranch.m_branchResultPoints.end()); + } + + // Propagate position contributions from connections above unpositioned segments downwards + + well_segment_collection_type * allErtSegments = well_state_get_segments( ert_well_state ); + + for (size_t bIdx = 0; bIdx < wellResFrame.m_wellResultBranches.size(); ++bIdx) + { + RigWellResultBranch& wellResultBranch = wellResFrame.m_wellResultBranches[ bIdx]; + bool previousResultPointWasCell = false; + if (bIdx == 0) previousResultPointWasCell = true; // Wellhead + + // Go downwards until we find a none-cell resultpoint just after a cell-resultpoint + // When we do, start propagating + + for (size_t rpIdx = 0; rpIdx < wellResultBranch.m_branchResultPoints.size(); ++rpIdx) + { + RigWellResultPoint resPoint = wellResultBranch.m_branchResultPoints[rpIdx]; + if ( resPoint.isCell() ) + { + previousResultPointWasCell = true; + } + else + { + if (previousResultPointWasCell) + { + RigWellResultPoint prevResPoint; + if (bIdx == 0 && rpIdx == 0) + { + prevResPoint = wellResFrame.m_wellHead; + } + else + { + prevResPoint = wellResultBranch.m_branchResultPoints[rpIdx - 1 ]; + } + + cvf::Vec3d lastConnectionPos = grids[prevResPoint.m_gridIndex]->cell(prevResPoint.m_gridCellIndex).center(); + + SegmentPositionContribution posContrib(prevResPoint.m_ertSegmentId, lastConnectionPos, 0.0, false, -1, prevResPoint.m_ertSegmentId, true); + + int ertSegmentId = resPoint.m_ertSegmentId; + + std::map >::iterator posContribIt; + posContribIt = segmentIdToPositionContrib.find(ertSegmentId); + CVF_ASSERT(posContribIt != segmentIdToPositionContrib.end()); + + std::vector posContributions = posContribIt->second; + for (size_t i = 0; i < posContributions.size(); ++i) + { + posContributions[i].m_segmentIdAbove = prevResPoint.m_ertSegmentId; + } + posContributions.push_back(posContrib); + + propagatePosContribDownwards(segmentIdToPositionContrib, allErtSegments, ertSegmentId, posContributions); + } + + previousResultPointWasCell = false; + } + } + } + + // Calculate the bottom position of all the unpositioned segments + // First merge all the contributions referring to the same segment under, to mean + // the interpolated position at the closest split point below +#if 0 + std::map >::iterator posContribIt = segmentIdToPositionContrib.begin(); + while (posContribIt != segmentIdToPositionContrib.end()) + { + std::vector posContribs = posContribIt->second; + // Merge contributions coming from above that has same segementAboveErtId + // Merge contributions coming from below that has same segementBelowErtId + + // Split the contributions in above, below and by respective above/below segmentErtId + std::map > aboveErtIdToContribs; + std::map > belowErtIdToContribs; + + for (size_t pcIdx = 0; pcIdx < posContribs.size(); ++pcIdx) + { + if (posContribs[pcIdx].m_isFromAbove ) + { + aboveErtIdToContribs[posContribs[pcIdx].m_segmentIdUnder].push_back(posContribs[pcIdx]); + } + else + { + belowErtIdToContribs[posContribs[pcIdx].m_segmentIdUnder].push_back(posContribs[pcIdx]); + } + } + + std::vector mergedPosContribs; + std::map >::iterator pcIt; + for (pcIt = aboveErtIdToContribs.begin(); pcIt != aboveErtIdToContribs.end(); ++pcIt) + { + if (pcIt->second.size() == 1) + { + mergedPosContribs.push_back(pcIt->second[0]); + } + else if (pcIt->second.size() > 1) + { + // Merge them + // Find the closest distance -> splitpoint distance + double splitPointDistance = HUGE_VAL; + for (size_t pcIdx = 0; pcIdx < pcIt->second.size(); ++pcIdx) + { + if (pcIt->second[pcIdx].m_lengthFromConnection < splitPointDistance) + { + splitPointDistance = pcIt->second[pcIdx].m_lengthFromConnection; + } + } + // calculate splitpoint position + // Merged posContrib made from splitpoint distance, and splitpoint + + } + } + + + } +#endif + // Then do the calculation based on the refined contributions + + std::map >::iterator posContribIt = segmentIdToPositionContrib.begin(); + std::map bottomPositions; + while (posContribIt != segmentIdToPositionContrib.end()) + { + bottomPositions[posContribIt->first] = interpolate3DPosition(posContribIt->second); + posContribIt++; + } + + // Distribute the positions to the resultpoints stored in the wellResultBranch.m_branchResultPoints + + for (size_t bIdx = 0; bIdx < wellResFrame.m_wellResultBranches.size(); ++bIdx) + { + RigWellResultBranch& wellResultBranch = wellResFrame.m_wellResultBranches[ bIdx]; + bool previousResultPointWasCell = false; + for (size_t rpIdx = 0; rpIdx < wellResultBranch.m_branchResultPoints.size(); ++rpIdx) + { + RigWellResultPoint & resPoint = wellResultBranch.m_branchResultPoints[rpIdx]; + if ( ! resPoint.isCell() ) + { + resPoint.m_bottomPosition = bottomPositions[resPoint.m_ertSegmentId]; + } + } + } + +#else + for (size_t gridNr = 0; gridNr < grids.size(); ++gridNr) + { + // Set the wellhead + { + // If several grids have a wellhead definition for this well, we use the last one. + // (Possibly the innermost LGR) + + const well_conn_type* ert_wellhead = well_state_iget_wellhead(ert_well_state, static_cast(gridNr)); + if (ert_wellhead) + { + wellResFrame.m_wellHead = createWellResultPoint(grids[gridNr], ert_wellhead, -1, -1 ); + } + } + + // Find the grid name to be used later as key towards ert + + std::string gridName; + if (gridNr == 0) + { + gridName = ECL_GRID_GLOBAL_GRID; + } + else + { + RigGridBase* rigGrid = m_eclipseCase->grid(gridNr); + gridName = rigGrid->gridName(); + } + + + // Fill the SegmentData list with the segments from ert in branch sorted order: + // Grid0(BrancN, ..., Branch0) ... GridN(BrancN, ..., Branch0) + + std::list segmentList; + std::vector outletBranchSegmentList; // Keep a list of branch outlet segments to avoid traversal twice + std::vector ertBranchIDs; + + well_branch_collection_type* branches = well_state_get_branches(ert_well_state); + int branchCount = well_branch_collection_get_size(branches); + + for (int branchIdx = 0; branchIdx < well_branch_collection_get_size(branches); branchIdx++) + { + const well_segment_type* segment = well_branch_collection_iget_start_segment(branches, branchIdx); + int branchId = well_segment_get_branch_id(segment); + + ertBranchIDs.push_back(branchId); + + while (segment && branchId == well_segment_get_branch_id(segment)) + { + SegmentData segmentData(NULL); + segmentData.m_branchId = branchId; + segmentData.m_segmentId = well_segment_get_id(segment); + //segmentData.m_gridIndex = gridNr; + + if (well_segment_has_grid_connections(segment, gridName.data())) + { + const well_conn_collection_type* connections = well_segment_get_connections(segment, gridName.data()); + segmentData.m_connections = connections; + } + + // Insert in front, as the segments are accessed starting from grid cell closes to well head + segmentList.push_front(segmentData); + + if (well_segment_get_outlet_id(segment) == -1) + { + break; + } + + segment = well_segment_get_outlet(segment); + } + + outletBranchSegmentList.push_back(segment); + } + + size_t currentGridBranchStartIndex = wellResFrame.m_wellResultBranches.size(); + wellResFrame.m_wellResultBranches.resize(currentGridBranchStartIndex + branchCount); + + // Import all well result cells for all connections, adding one ResultPoint to represent the bottom position + // for each segment having no connections + + for (int branchIdx = 0; branchIdx < branchCount; branchIdx++) + { + RigWellResultBranch& wellResultBranch = wellResFrame.m_wellResultBranches[currentGridBranchStartIndex + branchIdx]; + wellResultBranch.m_branchIndex = branchIdx; + + int ertBranchId = ertBranchIDs[branchIdx]; + wellResultBranch.m_ertBranchId = ertBranchId; + + std::vector branchSegments; + getSegmentDataByBranchId(segmentList, branchSegments, ertBranchId); + + for (size_t segmentIdx = 0; segmentIdx < branchSegments.size(); segmentIdx++) + { + SegmentData& connData = branchSegments[segmentIdx]; + + if (!connData.m_connections) + { + RigWellResultPoint data; + data.m_ertBranchId = connData.m_branchId; + data.m_ertSegmentId = connData.m_segmentId; + + wellResultBranch.m_branchResultPoints.push_back(data); + } + else + { + int connectionCount = well_conn_collection_get_size(connData.m_connections); + + size_t existingCellCount = wellResultBranch.m_branchResultPoints.size(); + wellResultBranch.m_branchResultPoints.resize(existingCellCount + connectionCount); + + for (int connIdx = 0; connIdx < connectionCount; connIdx++) + { + well_conn_type* ert_connection = well_conn_collection_iget(connData.m_connections, connIdx); + wellResultBranch.m_branchResultPoints[existingCellCount + connIdx] = + createWellResultPoint(grids[gridNr], ert_connection, connData.m_branchId, connData.m_segmentId); + } + } + } + } + + // Assign outlet well cells to leaf branch well heads + + for (int branchIdx = 0; branchIdx < branchCount; branchIdx++) + { + RigWellResultBranch& wellResultLeafBranch = wellResFrame.m_wellResultBranches[currentGridBranchStartIndex + branchIdx]; + + const well_segment_type* outletBranchSegment = outletBranchSegmentList[branchIdx]; + CVF_ASSERT(outletBranchSegment); + + int outletErtBranchId = well_segment_get_branch_id(outletBranchSegment); + + size_t outletErtBranchIndex = cvf::UNDEFINED_SIZE_T; + for (size_t i = 0; i < ertBranchIDs.size(); i++) + { + if (ertBranchIDs[i] == outletErtBranchId) + { + outletErtBranchIndex = i; + } + } + + if (outletErtBranchIndex != cvf::UNDEFINED_SIZE_T) // Todo: Is this a correct guarding ? Or is it indicating an error ? + { + RigWellResultBranch& outletResultBranch = wellResFrame.m_wellResultBranches[currentGridBranchStartIndex + outletErtBranchIndex]; + + int outletErtSegmentId = well_segment_get_branch_id(outletBranchSegment); + size_t lastCellIndexForSegmentIdInOutletBranch = cvf::UNDEFINED_SIZE_T; + + for (size_t outletCellIdx = 0; outletCellIdx < outletResultBranch.m_branchResultPoints.size(); outletCellIdx++) + { + if (outletResultBranch.m_branchResultPoints[outletCellIdx].m_ertSegmentId == outletErtSegmentId) + { + lastCellIndexForSegmentIdInOutletBranch = outletCellIdx; + } + } + + if (lastCellIndexForSegmentIdInOutletBranch == cvf::UNDEFINED_SIZE_T) + { + // Did not find the cell in the outlet branch based on branch id and segment id from outlet cell in leaf branch + //std::cout << "Did not find the cell in the outlet branch based on branch id and segment id from outlet cell in leaf branch" << std::endl; + //CVF_ASSERT(0); + } + else + { + RigWellResultPoint& outletCell = outletResultBranch.m_branchResultPoints[lastCellIndexForSegmentIdInOutletBranch]; + + wellResultLeafBranch.m_outletBranchIndex_OBSOLETE = currentGridBranchStartIndex + outletErtBranchIndex; + wellResultLeafBranch.m_outletBranchHeadCellIndex_OBSOLETE = lastCellIndexForSegmentIdInOutletBranch; + } + } + } + + + // Update outlet well cells with no grid cell connections + + for (int branchIdx = 0; branchIdx < branchCount; branchIdx++) + { + RigWellResultBranch& wellResultLeafBranch = wellResFrame.m_wellResultBranches[currentGridBranchStartIndex + branchIdx]; + + const RigWellResultPoint* leafBranchHead = wellResFrame.findResultCellFromOutletSpecification(wellResultLeafBranch.m_outletBranchIndex_OBSOLETE, wellResultLeafBranch.m_outletBranchHeadCellIndex_OBSOLETE); + if (!leafBranchHead || leafBranchHead->isCell()) + { + continue; + } + + RigWellResultBranch& outletResultBranch = wellResFrame.m_wellResultBranches[wellResultLeafBranch.m_outletBranchIndex_OBSOLETE]; + + size_t firstCellIndexWithGridConnectionInLeafBranch = cvf::UNDEFINED_SIZE_T; + for (size_t j = 0; j < wellResultLeafBranch.m_branchResultPoints.size(); j++) + { + if (wellResultLeafBranch.m_branchResultPoints[j].isCell()) + { + firstCellIndexWithGridConnectionInLeafBranch = j; + break; + } + } + + if (firstCellIndexWithGridConnectionInLeafBranch != cvf::UNDEFINED_SIZE_T) + { + const RigCell& firstCellWithGridConnectionInLeafBranch = m_eclipseCase->cellFromWellResultCell(wellResultLeafBranch.m_branchResultPoints[firstCellIndexWithGridConnectionInLeafBranch]); + cvf::Vec3d firstGridConnectionCenterInLeafBranch = firstCellWithGridConnectionInLeafBranch.center(); + + size_t cellIndexInOutletBranch = wellResultLeafBranch.m_outletBranchHeadCellIndex_OBSOLETE; + CVF_ASSERT(cellIndexInOutletBranch != cvf::UNDEFINED_SIZE_T); + + RigWellResultPoint& currCell = outletResultBranch.m_branchResultPoints[cellIndexInOutletBranch]; + + while (cellIndexInOutletBranch != cvf::UNDEFINED_SIZE_T && !currCell.isCell()) + { + size_t branchConnectionCount = currCell.m_branchConnectionCount; + if (branchConnectionCount == 0) + { + currCell.m_bottomPosition = firstGridConnectionCenterInLeafBranch; + } + else + { + cvf::Vec3d currentWeightedCoord = currCell.m_bottomPosition * branchConnectionCount / static_cast(branchConnectionCount + 1); + cvf::Vec3d additionalWeightedCoord = firstGridConnectionCenterInLeafBranch / static_cast(branchConnectionCount + 1); + + currCell.m_bottomPosition = currentWeightedCoord + additionalWeightedCoord; + } + + currCell.m_branchConnectionCount++; + + if (cellIndexInOutletBranch == 0) + { + cellIndexInOutletBranch = cvf::UNDEFINED_SIZE_T; + + // Find the branch the outlet is connected to, and continue update of + // segments until a segment with a grid connection is found + const RigWellResultPoint* leafBranchHead = wellResFrame.findResultCellFromOutletSpecification(outletResultBranch.m_outletBranchIndex_OBSOLETE, outletResultBranch.m_outletBranchHeadCellIndex_OBSOLETE); + + if (leafBranchHead && + !leafBranchHead->isCell() && + leafBranchHead->m_ertBranchId != outletResultBranch.m_ertBranchId) + { + outletResultBranch = wellResFrame.m_wellResultBranches[outletResultBranch.m_outletBranchIndex_OBSOLETE]; + cellIndexInOutletBranch = outletResultBranch.m_outletBranchHeadCellIndex_OBSOLETE; + } + } + else + { + cellIndexInOutletBranch--; + } + + if(cellIndexInOutletBranch >= 0 && cellIndexInOutletBranch < outletResultBranch.m_branchResultPoints.size()) + { + currCell = outletResultBranch.m_branchResultPoints[cellIndexInOutletBranch]; + } + } + } + } + } + + // Try to add a copy of the outlet wellResultPoint into the start of each branch + + size_t bCount = wellResFrame.m_wellResultBranches.size(); + for (size_t bIdx = 0; bIdx < bCount; ++bIdx) + { + size_t outBranchIdx = wellResFrame.m_wellResultBranches[bIdx].m_outletBranchIndex_OBSOLETE; + size_t outCellIdx = wellResFrame.m_wellResultBranches[bIdx].m_outletBranchHeadCellIndex_OBSOLETE; + + const RigWellResultPoint* resPoint = wellResFrame.findResultCellFromOutletSpecification(outBranchIdx, outCellIdx); + if (resPoint) // Todo: Is this a correct guarding or indicating an error ? + { + wellResFrame.m_wellResultBranches[bIdx].m_branchResultPoints.insert(wellResFrame.m_wellResultBranches[bIdx].m_branchResultPoints.begin(), *resPoint); + } + } +#endif + } + else + { + // Code handling None-MSW Wells ... Normal wells that is. + + // Loop over all the grids in the model. If we have connections in one, we will discard + // the main grid connections as the well connections are duplicated in the main grid and LGR grids + // Verified on 10 k case JJS. But smarter things could be done, like showing the "main grid well" if turning off the LGR's + + bool hasWellConnectionsInLGR = false; + + for (size_t gridIdx = 1; gridIdx < grids.size(); ++gridIdx) + { + RigGridBase* lgrGrid = m_eclipseCase->grid(gridIdx); + if (well_state_has_grid_connections(ert_well_state, lgrGrid->gridName().data())) + { + hasWellConnectionsInLGR = true; + break; + } + } + + size_t gridNr = hasWellConnectionsInLGR ? 1 : 0; + for (; gridNr < grids.size(); ++gridNr) + { + + // Wellhead. If several grids have a wellhead definition for this well, we use the last one. (Possibly the innermost LGR) + const well_conn_type* ert_wellhead = well_state_iget_wellhead(ert_well_state, static_cast(gridNr)); + if (ert_wellhead) + { + wellResFrame.m_wellHead = createWellResultPoint(grids[gridNr], ert_wellhead, -1, -1 ); + //std::cout << "Wellhead YES at timeIdx: " << timeIdx << " wellIdx: " << wellIdx << " Grid: " << gridNr << std::endl; + } + else + { + // std::cout << "Wellhead NO at timeIdx: " << timeIdx << " wellIdx: " << wellIdx << " Grid: " << gridNr << std::endl; + //CVF_ASSERT(0); // This is just a test assert to see if this condition exists in some files and it does. + // All the grids does not necessarily have a well head definition. + } + + const well_conn_collection_type* connections = well_state_get_grid_connections(ert_well_state, this->ertGridName(gridNr).data()); + + // Import all well result cells for all connections + if (connections) + { + int connectionCount = well_conn_collection_get_size(connections); + if (connectionCount) + { + wellResFrame.m_wellResultBranches.push_back(RigWellResultBranch()); + RigWellResultBranch& wellResultBranch = wellResFrame.m_wellResultBranches.back(); + + wellResultBranch.m_branchIndex = 0; + wellResultBranch.m_ertBranchId = 0; // Normal wells have only one branch + + size_t existingCellCount = wellResultBranch.m_branchResultPoints.size(); + wellResultBranch.m_branchResultPoints.resize(existingCellCount + connectionCount); + + for (int connIdx = 0; connIdx < connectionCount; connIdx++) + { + well_conn_type* ert_connection = well_conn_collection_iget(connections, connIdx); + wellResultBranch.m_branchResultPoints[existingCellCount + connIdx] = + createWellResultPoint(grids[gridNr], ert_connection, -1, -1); } } } @@ -886,6 +1774,7 @@ void RifReaderEclipseOutput::readWellCells() } } + wellResults->computeMappingFromResultTimeIndicesToWellTimeIndices(m_timeSteps); wells.push_back(wellResults.p()); @@ -1056,3 +1945,23 @@ void RifReaderEclipseOutput::transferCoarseningInfo(const ecl_grid_type* eclGrid } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::string RifReaderEclipseOutput::ertGridName(size_t gridNr) +{ + std::string gridName; + if (gridNr == 0) + { + gridName = ECL_GRID_GLOBAL_GRID; + } + else + { + CVF_ASSERT(m_eclipseCase); + CVF_ASSERT(m_eclipseCase->gridCount() > gridNr); + gridName = m_eclipseCase->grid(gridNr)->gridName(); + } + + return gridName; +} + diff --git a/ApplicationCode/FileInterface/RifReaderEclipseOutput.h b/ApplicationCode/FileInterface/RifReaderEclipseOutput.h index 5dc8794a3a..d6c96d77b2 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseOutput.h +++ b/ApplicationCode/FileInterface/RifReaderEclipseOutput.h @@ -22,6 +22,8 @@ #include #include +#include "RigSingleWellResultsData.h" + class RifEclipseOutputFileTools; class RifEclipseRestartDataAccess; class RigGridBase; @@ -30,7 +32,7 @@ class RigActiveCellInfo; typedef struct ecl_grid_struct ecl_grid_type; typedef struct ecl_file_struct ecl_file_type; - +typedef struct well_conn_struct well_conn_type; //================================================================================================== // @@ -56,8 +58,14 @@ public: private: bool readActiveCellInfo(); void buildMetaData(); - void readWellCells(); + void readWellCells(const ecl_grid_type* mainEclGrid); + + std::string ertGridName( size_t gridNr ); + + static RigWellResultPoint createWellResultPoint(const RigGridBase* grid, const well_conn_type* ert_connection, int ertBranchId, int ertSegmentId); + + void openInitFile(); bool openDynamicAccess(); diff --git a/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp b/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp index 8d1e738f1f..bd2233d436 100644 --- a/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp +++ b/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.cpp @@ -47,7 +47,6 @@ - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -97,7 +96,7 @@ void RivWellPipesPartMgr::buildWellPipeParts() std::vector< size_t > pipeBranchIds; std::vector< std::vector > pipeBranchesCLCoords; - std::vector< std::vector > pipeBranchesCellIds; + std::vector< std::vector > pipeBranchesCellIds; calculateWellPipeCenterline(pipeBranchesCLCoords, pipeBranchesCellIds); @@ -163,10 +162,12 @@ void RivWellPipesPartMgr::buildWellPipeParts() //-------------------------------------------------------------------------------------------------- -/// +/// Based on the points and cells, calculate a pipe centerline +/// The returned CellIds is one less than the number of centerline points, +/// and are describing the lines between the points, starting with the first line //-------------------------------------------------------------------------------------------------- void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< std::vector >& pipeBranchesCLCoords, - std::vector< std::vector >& pipeBranchesCellIds) const + std::vector< std::vector >& pipeBranchesCellIds) const { CVF_ASSERT(m_rimWell.notNull()); CVF_ASSERT(m_rimReservoirView.notNull()); @@ -176,15 +177,15 @@ void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< std::vector RigCaseData* rigReservoir = m_rimReservoirView->eclipseCase()->reservoirData(); RigSingleWellResultsData* wellResults = m_rimWell->wellResults(); - const RigWellResultFrame& staticWellFrame = m_rimWell->wellResults()->m_staticWellCells; - // Make sure we have computed the static representation of the well - if (staticWellFrame.m_wellResultBranches.size() == 0) + if (wellResults->m_staticWellCells.m_wellResultBranches.size() == 0) { wellResults->computeStaticWellCellPath(); } - if (staticWellFrame.m_wellResultBranches.size() == 0) return; + const RigWellResultFrame& staticWellFrame = wellResults->m_staticWellCells; + if (staticWellFrame.m_wellResultBranches.size() == 0) return; + // Initialize the return arrays pipeBranchesCLCoords.clear(); pipeBranchesCellIds.clear(); @@ -193,7 +194,7 @@ void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< std::vector // Match this position with well head position in RivWellHeadPartMgr::buildWellHeadParts() const RigCell& whCell = rigReservoir->cellFromWellResultCell(staticWellFrame.m_wellHead); cvf::Vec3d whStartPos = whCell.faceCenter(cvf::StructGridInterface::NEG_K); - const RigWellResultCell* whResCell = &(staticWellFrame.m_wellHead); + const RigWellResultPoint* whResCell = &(staticWellFrame.m_wellHead); // Loop over all the well branches const std::vector& resBranches = staticWellFrame.m_wellResultBranches; @@ -202,112 +203,259 @@ void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< std::vector { for (size_t i = 0 ; i < resBranches.size(); ++i) { - if (resBranches[i].m_wellCells.size() != 0) + if (resBranches[i].m_branchResultPoints.size() != 0) { hasResultCells = true; + break; } } } if (hasResultCells) { - // Create a new branch from wellhead - - pipeBranchesCLCoords.push_back(std::vector()); - pipeBranchesCellIds.push_back(std::vector ()); - - // We start by entering the first cell (the wellhead) - const RigWellResultCell* prevResCell = whResCell; - - pipeBranchesCLCoords.back().push_back(whStartPos); - pipeBranchesCellIds.back().push_back(*prevResCell ); // Add extra coordinate between cell face and cell center // to make sure the well pipe terminated in a segment parallel to z-axis cvf::Vec3d whIntermediate = whStartPos; whIntermediate.z() = (whStartPos.z() + whCell.center().z()) / 2.0; - pipeBranchesCLCoords.back().push_back(whIntermediate); - pipeBranchesCellIds.back().push_back(*prevResCell ); + const RigWellResultPoint* prevWellResPoint = NULL; + + CVF_ASSERT(wellResults->isMultiSegmentWell() || resBranches.size() <= 1); + + // The centerline is calculated by adding a point when the pipe enters a cell, + // and one when the line leaves the cell. + // For the sake of the loop: + // The currentResultPoint (Cell) and the one we index by the loop variable is the one we calculate the entry point to. + // The previous cell is the one we leave, and calculate the "out-point" from for (size_t brIdx = 0; brIdx < resBranches.size(); brIdx++) { - if (resBranches[brIdx].m_wellCells.size() == 0) - continue; // Skip empty branches. Do not know why they exist, but they make problems. - // Loop over all the resultCells in the branch - const std::vector& resBranchCells = resBranches[brIdx].m_wellCells; + // Skip empty branches. Do not know why they exist, but they make problems. + + bool hasValidData = false; + for (size_t cIdx = 0; cIdx < resBranches[brIdx].m_branchResultPoints.size(); ++cIdx) + { + if (resBranches[brIdx].m_branchResultPoints[cIdx].isValid()) + { + hasValidData = true; + break; + } + } + if (!hasValidData) continue; + + + prevWellResPoint = NULL; + + // Find the start the MSW well-branch centerline. Normal wells are started "once" at wellhead in the code above + + pipeBranchesCLCoords.push_back(std::vector()); + pipeBranchesCellIds.push_back(std::vector ()); + + if (brIdx == 0) + { + // The first branch contains segment number 1, and this is the only segment connected to well head + // See Eclipse documentation for the keyword WELSEGS + prevWellResPoint = whResCell; + + pipeBranchesCLCoords.back().push_back(whStartPos); + pipeBranchesCellIds.back().push_back(*prevWellResPoint); + + pipeBranchesCLCoords.back().push_back(whIntermediate); + pipeBranchesCellIds.back().push_back(*prevWellResPoint); + } + + // Loop over all the resultPoints in the branch + + const std::vector& resBranchCells = resBranches[brIdx].m_branchResultPoints; for (int cIdx = 0; cIdx < static_cast(resBranchCells.size()); cIdx++) // Need int because cIdx can temporarily end on -1 { std::vector& branchCLCoords = pipeBranchesCLCoords.back(); - std::vector& branchCellIds = pipeBranchesCellIds.back(); + std::vector& branchCellIds = pipeBranchesCellIds.back(); - const RigWellResultCell& resCell = resBranchCells[cIdx]; - const RigCell& cell = rigReservoir->cellFromWellResultCell(resCell); + const RigWellResultPoint& currentWellResPoint = resBranchCells[cIdx]; + + // Ignore invalid cells + + if (!currentWellResPoint.isValid()) + { + //CVF_ASSERT(false); // Some segments does not get anything yet. + continue; + } + + // Add cl contribution for a geometrical resultPoint by adding exit point from previous cell, + // and then the result point position + + if (!currentWellResPoint.isCell()) + { + // Use the interpolated value of branch head + CVF_ASSERT(currentWellResPoint.isPointValid()); + + cvf::Vec3d currentPoint = currentWellResPoint.m_bottomPosition; + + // If we have a real previous cell, we need to go out of it, before adding the current point + // That is: add a CL-point describing where it leaves the previous cell. + + if (prevWellResPoint && prevWellResPoint->isCell()) + { + // Create ray between the previous and this position + + const RigCell& prevCell = rigReservoir->cellFromWellResultCell(*prevWellResPoint); + cvf::Vec3d centerPreviousCell = prevCell.center(); + + cvf::Ray rayToThisCell; + rayToThisCell.setOrigin(centerPreviousCell); + rayToThisCell.setDirection((currentPoint - centerPreviousCell).getNormalized()); + + cvf::Vec3d outOfPrevCell(centerPreviousCell); + + int intersectionOk = prevCell.firstIntersectionPoint(rayToThisCell, &outOfPrevCell); + //CVF_ASSERT(intersectionOk); + //CVF_ASSERT(intersectionOk); + if ((currentPoint - outOfPrevCell).lengthSquared() > 1e-3) + { + branchCLCoords.push_back(outOfPrevCell); + branchCellIds.push_back(RigWellResultPoint()); + } + + } + + branchCLCoords.push_back(currentPoint); + branchCellIds.push_back(currentWellResPoint); + + prevWellResPoint = ¤tWellResPoint; + + continue; + } + + // + // Handle currentWellResPoint as a real cell result points. + // + + const RigCell& cell = rigReservoir->cellFromWellResultCell(currentWellResPoint); // Check if this and the previous cells has shared faces cvf::StructGridInterface::FaceType sharedFace; - if (rigReservoir->findSharedSourceFace(sharedFace, resCell, *prevResCell)) + if (prevWellResPoint && prevWellResPoint->isCell() && rigReservoir->findSharedSourceFace(sharedFace, currentWellResPoint, *prevWellResPoint)) { + // If they share faces, the shared face center is used as point + // describing the entry of this cell. (And exit of the previous cell) + branchCLCoords.push_back(cell.faceCenter(sharedFace)); - branchCellIds.push_back(resCell); + branchCellIds.push_back(currentWellResPoint); } else { - // This and the previous cell does not share a face. We need to go out of the previous cell, before entering this. - const RigCell& prevCell = rigReservoir->cellFromWellResultCell(*prevResCell); - cvf::Vec3d centerPrevCell = prevCell.center(); + // This and the previous cell does not share a face. + // Then we need to calculate the exit of the previous cell, and the entry point into this cell + + cvf::Vec3d centerPreviousCell(cvf::Vec3d::ZERO); cvf::Vec3d centerThisCell = cell.center(); + bool distanceToWellHeadIsLonger = true; - // First make sure this cell is not starting a new "display" branch - if ( !isAutoDetectBranches || (prevResCell == whResCell) - || (centerThisCell-centerPrevCell).lengthSquared() <= (centerThisCell - whStartPos).lengthSquared()) + // If we have a previous well result point, use its center as measure point and ray intersection start + // when considering things. + + if (prevWellResPoint && prevWellResPoint->isValid()) { - // Not starting a "display" branch - // Create ray and intersect with cells - - cvf::Ray rayToThisCell; - rayToThisCell.setOrigin(centerPrevCell); - rayToThisCell.setDirection((centerThisCell - centerPrevCell).getNormalized()); - - cvf::Vec3d outOfPrevCell(centerPrevCell); - cvf::Vec3d intoThisCell(centerThisCell); - - bool intersectionOk = prevCell.firstIntersectionPoint(rayToThisCell, &outOfPrevCell); - //CVF_ASSERT(intersectionOk); - intersectionOk = cell.firstIntersectionPoint(rayToThisCell, &intoThisCell); - //CVF_ASSERT(intersectionOk); - if ((intoThisCell - outOfPrevCell).lengthSquared() > 1e-3) + if (prevWellResPoint->isCell()) { - branchCLCoords.push_back(outOfPrevCell); - branchCellIds.push_back(RigWellResultCell()); + const RigCell& prevCell = rigReservoir->cellFromWellResultCell(*prevWellResPoint); + centerPreviousCell = prevCell.center(); } + else + { + centerPreviousCell = prevWellResPoint->m_bottomPosition; + } + + distanceToWellHeadIsLonger = (centerThisCell - centerPreviousCell).lengthSquared() <= (centerThisCell - whStartPos).lengthSquared(); + } + + + // First make sure this cell is not starting a new "display" branch for none MSW's + + if ( wellResults->isMultiSegmentWell() + || !isAutoDetectBranches + || (prevWellResPoint == whResCell) + || distanceToWellHeadIsLonger) + { + // Not starting a "display" branch for normal wells + // Calculate the exit of the previous cell, and the entry point into this cell + + cvf::Vec3d intoThisCell(centerThisCell); // Use cell center as default for "into" point. + + if (prevWellResPoint && prevWellResPoint->isValid()) + { + // We have a defined previous point + // Create ray between the previous and this cell + + cvf::Ray rayToThisCell; + rayToThisCell.setOrigin(centerPreviousCell); + rayToThisCell.setDirection((centerThisCell - centerPreviousCell).getNormalized()); + + // Intersect with the current cell to find a better entry point than the cell center + + int intersectionCount = cell.firstIntersectionPoint(rayToThisCell, &intoThisCell); + bool isPreviousResPointInsideCurrentCell = (intersectionCount % 2); // Must intersect uneven times to be inside. (1 % 2 = 1) + + // If we have a real previous cell, we need to go out of it, before entering this. + // That is: add a CL-point describing where it leaves the previous cell. + + if ( prevWellResPoint->isCell()) + { + cvf::Vec3d outOfPrevCell(centerPreviousCell); + + const RigCell& prevCell = rigReservoir->cellFromWellResultCell(*prevWellResPoint); + bool intersectionOk = prevCell.firstIntersectionPoint(rayToThisCell, &outOfPrevCell); + //CVF_ASSERT(intersectionOk); + //CVF_ASSERT(intersectionOk); + if ((intoThisCell - outOfPrevCell).lengthSquared() > 1e-3) + { + branchCLCoords.push_back(outOfPrevCell); + branchCellIds.push_back(RigWellResultPoint()); + } + } + else if (isPreviousResPointInsideCurrentCell) + { + // Since the previous point actually is inside this cell, + /// use that as the entry point into this cell + intoThisCell = centerPreviousCell; + } + + } + branchCLCoords.push_back(intoThisCell); - branchCellIds.push_back(resCell); + branchCellIds.push_back(currentWellResPoint); } else { + // Need to start a "display branch" for a Normal Well. + + CVF_ASSERT(!wellResults->isMultiSegmentWell()); + // This cell is further from the previous cell than from the well head, // thus we interpret it as a new branch. - // First finish the current branch - branchCLCoords.push_back(branchCLCoords.back() + 1.5*(centerPrevCell - branchCLCoords.back()) ); + // First finish the current branch in the previous cell + //branchCLCoords.push_back(branchCLCoords.back() + 1.5*(centerPreviousCell - branchCLCoords.back()) ); + finishPipeCenterLine(pipeBranchesCLCoords, centerPreviousCell); // Create new display branch pipeBranchesCLCoords.push_back(std::vector()); - pipeBranchesCellIds.push_back(std::vector ()); + pipeBranchesCellIds.push_back(std::vector ()); // Start the new branch by entering the first cell (the wellhead) and intermediate - prevResCell = whResCell; + prevWellResPoint = whResCell; pipeBranchesCLCoords.back().push_back(whStartPos); - pipeBranchesCellIds.back().push_back(*prevResCell); + pipeBranchesCellIds.back().push_back(*prevWellResPoint); // Include intermediate pipeBranchesCLCoords.back().push_back(whIntermediate); - pipeBranchesCellIds.back().push_back(*prevResCell); + pipeBranchesCellIds.back().push_back(*prevWellResPoint); // Well now we need to step one back to take this cell again, but in the new branch. cIdx--; @@ -315,16 +463,25 @@ void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< std::vector } } - prevResCell = &resCell; + prevWellResPoint = ¤tWellResPoint; + } + + // For the last cell, add the point 0.5 past the center of that cell + // Remember that prevWellResPoint actually is the last one in this branch. + cvf::Vec3d centerLastCell; + if (prevWellResPoint && prevWellResPoint->isCell()) + { + const RigCell& prevCell = rigReservoir->cellFromWellResultCell(*prevWellResPoint); + centerLastCell = prevCell.center(); + finishPipeCenterLine(pipeBranchesCLCoords, centerLastCell); + } + else + { + // Remove the ID that is superfluous since we will not add an ending point + pipeBranchesCellIds.back().pop_back(); } } - - // For the last cell, add the point 0.5 past the center of that cell - const RigCell& prevCell = rigReservoir->cellFromWellResultCell(*prevResCell); - cvf::Vec3d centerPrevCell = prevCell.center(); - pipeBranchesCLCoords.back().push_back(pipeBranchesCLCoords.back().back() + 1.5*(centerPrevCell - pipeBranchesCLCoords.back().back()) ); - } CVF_ASSERT(pipeBranchesCellIds.size() == pipeBranchesCLCoords.size()); @@ -334,6 +491,20 @@ void RivWellPipesPartMgr::calculateWellPipeCenterline( std::vector< std::vector } } +//-------------------------------------------------------------------------------------------------- +/// All branches are completed using the point 0.5 past the center of +/// last cell. +//-------------------------------------------------------------------------------------------------- +void RivWellPipesPartMgr::finishPipeCenterLine(std::vector< std::vector > &pipeBranchesCLCoords, const cvf::Vec3d& lastCellCenter) const +{ + CVF_ASSERT(pipeBranchesCLCoords.size()); + CVF_ASSERT(pipeBranchesCLCoords.back().size()); + + cvf::Vec3d entryPointLastCell = pipeBranchesCLCoords.back().back(); + + pipeBranchesCLCoords.back().push_back(entryPointLastCell + 1.5*(lastCellCenter - entryPointLastCell) ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -384,12 +555,17 @@ void RivWellPipesPartMgr::updatePipeResultColor(size_t frameIndex) wellCellStates.clear(); wellCellStates.resize(brIt->m_cellIds.size(), closed); - const std::vector & cellIds = brIt->m_cellIds; + const std::vector & cellIds = brIt->m_cellIds; for (size_t wcIdx = 0; wcIdx < cellIds.size(); ++wcIdx) { // we need a faster lookup, I guess - const RigWellResultCell* wResCell = wResFrame.findResultCell(cellIds[wcIdx].m_gridIndex, cellIds[wcIdx].m_gridCellIndex); + const RigWellResultPoint* wResCell = NULL; + + if (cellIds[wcIdx].isCell()) + { + wResCell = wResFrame.findResultCell(cellIds[wcIdx].m_gridIndex, cellIds[wcIdx].m_gridCellIndex); + } if (wResCell == NULL) { diff --git a/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.h b/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.h index 0bb8dec675..88a3cf0403 100644 --- a/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.h +++ b/ApplicationCode/ModelVisualization/RivWellPipesPartMgr.h @@ -67,11 +67,13 @@ private: //void calculateWellPipeCenterline(std::vector& coords) const; void calculateWellPipeCenterline(std::vector< std::vector >& pipeBranchesCLCoords, - std::vector< std::vector >& pipeBranchesCellIds ) const; + std::vector< std::vector >& pipeBranchesCellIds ) const; + + void finishPipeCenterLine( std::vector< std::vector > &pipeBranchesCLCoords, const cvf::Vec3d& lastCellCenter ) const; struct RivPipeBranchData { - std::vector m_cellIds; + std::vector m_cellIds; //std::vector< std::vector > m_cellStatusPrFrame; cvf::ref m_pipeGeomGenerator; diff --git a/ApplicationCode/ProjectDataModel/RimReservoirView.cpp b/ApplicationCode/ProjectDataModel/RimReservoirView.cpp index 266795d45a..ac10a7559a 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirView.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoirView.cpp @@ -560,7 +560,7 @@ void RimReservoirView::createDisplayModel() if (! this->propertyFilterCollection()->hasActiveFilters()) { std::vector geometryTypesToAdd; - + if (this->rangeFilterCollection()->hasActiveFilters() || this->wellCollection()->hasVisibleWellCells()) { geometryTypesToAdd.push_back(RivReservoirViewPartMgr::RANGE_FILTERED); @@ -582,7 +582,7 @@ void RimReservoirView::createDisplayModel() geometryTypesToAdd.push_back(RivReservoirViewPartMgr::INACTIVE); } } - + size_t frameIdx; for (frameIdx = 0; frameIdx < frameModels.size(); ++frameIdx) { @@ -1044,6 +1044,29 @@ void RimReservoirView::appendCellResultInfo(size_t gridIndex, size_t cellIndex, } } } + + cvf::Collection wellResults = m_reservoir->reservoirData()->wellResults(); + for (size_t i = 0; i < wellResults.size(); i++) + { + RigSingleWellResultsData* singleWellResultData = wellResults.at(i); + + if (m_currentTimeStep < singleWellResultData->firstResultTimeStep()) + { + continue; + } + + const RigWellResultFrame& wellResultFrame = singleWellResultData->wellResultFrame(m_currentTimeStep); + const RigWellResultPoint* wellResultCell = wellResultFrame.findResultCell(gridIndex, cellIndex); + if (wellResultCell) + { + resultInfoText->append(QString("(0-based) Branch Id : %1 Segment Id %2\n").arg(wellResultCell->m_ertBranchId).arg(wellResultCell->m_ertSegmentId)); + if (wellResultCell->m_branchConnectionCount) + { + resultInfoText->append(QString("Branch Connection Count : %1\n").arg(wellResultCell->m_branchConnectionCount)); + resultInfoText->append(QString("Center coord : %1 %2 %3\n").arg(wellResultCell->m_bottomPosition.x()).arg(wellResultCell->m_bottomPosition.y()).arg(wellResultCell->m_bottomPosition.z())); + } + } + } } } @@ -1395,11 +1418,16 @@ void RimReservoirView::calculateVisibleWellCellsIncFence(cvf::UByteArray* visibl const std::vector& wellResSegments = wellResFrames[wfIdx].m_wellResultBranches; for (size_t wsIdx = 0; wsIdx < wellResSegments.size(); ++wsIdx) { - const std::vector& wsResCells = wellResSegments[wsIdx].m_wellCells; + const std::vector& wsResCells = wellResSegments[wsIdx].m_branchResultPoints; for (size_t cIdx = 0; cIdx < wsResCells.size(); ++ cIdx) { if (wsResCells[cIdx].m_gridIndex == grid->gridIndex()) { + if (!wsResCells[cIdx].isCell()) + { + continue; + } + size_t gridCellIndex = wsResCells[cIdx].m_gridCellIndex; (*visibleCells)[gridCellIndex] = true; diff --git a/ApplicationCode/ProjectDataModel/RimWell.cpp b/ApplicationCode/ProjectDataModel/RimWell.cpp index 4e07d4a449..03c26b0566 100644 --- a/ApplicationCode/ProjectDataModel/RimWell.cpp +++ b/ApplicationCode/ProjectDataModel/RimWell.cpp @@ -199,16 +199,19 @@ bool RimWell::calculateWellPipeVisibility(size_t frameIndex) const std::vector& wellResSegments = wrsf.m_wellResultBranches; for (size_t wsIdx = 0; wsIdx < wellResSegments.size(); ++wsIdx) { - const std::vector& wsResCells = wellResSegments[wsIdx].m_wellCells; + const std::vector& wsResCells = wellResSegments[wsIdx].m_branchResultPoints; for (size_t cIdx = 0; cIdx < wsResCells.size(); ++ cIdx) { - gridIndex = wsResCells[cIdx].m_gridIndex; - gridCellIndex = wsResCells[cIdx].m_gridCellIndex; - - cvf::cref cellVisibility = rvMan->cellVisibility(visGridParts[gpIdx], gridIndex, frameIndex); - if ((*cellVisibility)[gridCellIndex]) + if (wsResCells[cIdx].isCell()) { - return true; + gridIndex = wsResCells[cIdx].m_gridIndex; + gridCellIndex = wsResCells[cIdx].m_gridCellIndex; + + cvf::cref cellVisibility = rvMan->cellVisibility(visGridParts[gpIdx], gridIndex, frameIndex); + if ((*cellVisibility)[gridCellIndex]) + { + return true; + } } } } diff --git a/ApplicationCode/ProjectDataModel/RimWellCollection.cpp b/ApplicationCode/ProjectDataModel/RimWellCollection.cpp index 9f4dea4e10..daca4824c0 100644 --- a/ApplicationCode/ProjectDataModel/RimWellCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellCollection.cpp @@ -156,7 +156,7 @@ bool RimWellCollection::hasVisibleWellCells() const RigWellResultFrame& wellResultFrame = well->wellResults()->m_wellCellsTimeSteps[tIdx]; for (size_t wsIdx = 0; !hasCells && wsIdx < wellResultFrame.m_wellResultBranches.size(); ++wsIdx) { - if (wellResultFrame.m_wellResultBranches[wsIdx].m_wellCells.size() > 0 ) hasCells = true; + if (wellResultFrame.m_wellResultBranches[wsIdx].m_branchResultPoints.size() > 0 ) hasCells = true; } } } diff --git a/ApplicationCode/ReservoirDataModel/RigCaseData.cpp b/ApplicationCode/ReservoirDataModel/RigCaseData.cpp index 4f6eebc983..e477f9ab08 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigCaseData.cpp @@ -173,10 +173,10 @@ void RigCaseData::computeWellCellsPrGrid() { RigWellResultBranch& wellSegment = wellCells.m_wellResultBranches[sIdx]; size_t cdIdx; - for (cdIdx = 0; cdIdx < wellSegment.m_wellCells.size(); ++cdIdx) + for (cdIdx = 0; cdIdx < wellSegment.m_branchResultPoints.size(); ++cdIdx) { - gridIndex = wellSegment.m_wellCells[cdIdx].m_gridIndex; - gridCellIndex = wellSegment.m_wellCells[cdIdx].m_gridCellIndex; + gridIndex = wellSegment.m_branchResultPoints[cdIdx].m_gridIndex; + gridCellIndex = wellSegment.m_branchResultPoints[cdIdx].m_gridCellIndex; if(gridIndex < m_wellCellsInGrid.size() && gridCellIndex < m_wellCellsInGrid[gridIndex]->size()) { @@ -227,8 +227,10 @@ cvf::UIntArray* RigCaseData::gridCellToWellIndex(size_t gridIndex) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RigCell& RigCaseData::cellFromWellResultCell(const RigWellResultCell& wellResultCell) +RigCell& RigCaseData::cellFromWellResultCell(const RigWellResultPoint& wellResultCell) { + CVF_ASSERT(wellResultCell.isCell()); + size_t gridIndex = wellResultCell.m_gridIndex; size_t gridCellIndex = wellResultCell.m_gridCellIndex; @@ -241,7 +243,7 @@ RigCell& RigCaseData::cellFromWellResultCell(const RigWellResultCell& wellResult //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RigCaseData::findSharedSourceFace(cvf::StructGridInterface::FaceType& sharedSourceFace,const RigWellResultCell& sourceWellCellResult, const RigWellResultCell& otherWellCellResult) const +bool RigCaseData::findSharedSourceFace(cvf::StructGridInterface::FaceType& sharedSourceFace,const RigWellResultPoint& sourceWellCellResult, const RigWellResultPoint& otherWellCellResult) const { size_t gridIndex = sourceWellCellResult.m_gridIndex; size_t gridCellIndex = sourceWellCellResult.m_gridCellIndex; @@ -265,12 +267,17 @@ bool RigCaseData::findSharedSourceFace(cvf::StructGridInterface::FaceType& share size_t ni, nj, nk; grid->neighborIJKAtCellFace(i, j, k, sourceFace, &ni, &nj, &nk); - size_t neighborCellIndex = grid->cellIndexFromIJK(ni, nj, nk); - if (neighborCellIndex == otherGridCellIndex) + if (grid->isCellValid(ni, nj, nk)) { - sharedSourceFace = sourceFace; - return true; + + size_t neighborCellIndex = grid->cellIndexFromIJK(ni, nj, nk); + + if (neighborCellIndex == otherGridCellIndex) + { + sharedSourceFace = sourceFace; + return true; + } } } diff --git a/ApplicationCode/ReservoirDataModel/RigCaseData.h b/ApplicationCode/ReservoirDataModel/RigCaseData.h index a4d100e3d7..2ab3432815 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseData.h +++ b/ApplicationCode/ReservoirDataModel/RigCaseData.h @@ -65,8 +65,8 @@ public: cvf::UByteArray* wellCellsInGrid(size_t gridIndex); cvf::UIntArray* gridCellToWellIndex(size_t gridIndex); - RigCell& cellFromWellResultCell(const RigWellResultCell& wellResultCell); - bool findSharedSourceFace(cvf::StructGridInterface::FaceType& sharedSourceFace, const RigWellResultCell& sourceWellCellResult, const RigWellResultCell& otherWellCellResult) const; + RigCell& cellFromWellResultCell(const RigWellResultPoint& wellResultCell); + bool findSharedSourceFace(cvf::StructGridInterface::FaceType& sharedSourceFace, const RigWellResultPoint& sourceWellCellResult, const RigWellResultPoint& otherWellCellResult) const; void computeActiveCellBoundingBoxes(); diff --git a/ApplicationCode/ReservoirDataModel/RigCell.cpp b/ApplicationCode/ReservoirDataModel/RigCell.cpp index 6ddf5be8fa..8a59df6ab6 100644 --- a/ApplicationCode/ReservoirDataModel/RigCell.cpp +++ b/ApplicationCode/ReservoirDataModel/RigCell.cpp @@ -242,9 +242,11 @@ cvf::Vec3d RigCell::faceCenter(cvf::StructGridInterface::FaceType face) const //-------------------------------------------------------------------------------------------------- /// Find the intersection between the cell and the ray. The point closest to the ray origin is returned -/// if no intersection is found, the intersection point is untouched. +/// in \a intersectionPoint, while the return value is the total number of intersections with the 24 triangles +/// the cell is interpreted as. +/// If no intersection is found, the intersection point is untouched. //-------------------------------------------------------------------------------------------------- -bool RigCell::firstIntersectionPoint(const cvf::Ray& ray, cvf::Vec3d* intersectionPoint) const +int RigCell::firstIntersectionPoint(const cvf::Ray& ray, cvf::Vec3d* intersectionPoint) const { CVF_ASSERT(intersectionPoint != NULL); @@ -254,6 +256,7 @@ bool RigCell::firstIntersectionPoint(const cvf::Ray& ray, cvf::Vec3d* intersecti cvf::Vec3d firstIntersection(cvf::Vec3d::ZERO); double minLsq = HUGE_VAL; + int intersectionCount = 0; for (face = 0; face < 6 ; ++face) { @@ -261,9 +264,6 @@ bool RigCell::firstIntersectionPoint(const cvf::Ray& ray, cvf::Vec3d* intersecti cvf::Vec3d intersection; cvf::Vec3d faceCenter = this->faceCenter(static_cast(face)); - ray.triangleIntersect(nodes[m_cornerIndices[faceVertexIndices[0]]], - nodes[m_cornerIndices[faceVertexIndices[1]]], faceCenter, &intersection); - for (size_t i = 0; i < 4; ++i) { size_t next = i < 3 ? i+1 : 0; @@ -272,6 +272,7 @@ bool RigCell::firstIntersectionPoint(const cvf::Ray& ray, cvf::Vec3d* intersecti faceCenter, &intersection)) { + intersectionCount++; double lsq = (intersection - ray.origin() ).lengthSquared(); if (lsq < minLsq) { @@ -282,12 +283,11 @@ bool RigCell::firstIntersectionPoint(const cvf::Ray& ray, cvf::Vec3d* intersecti } } - if (minLsq != HUGE_VAL) + if (intersectionCount > 0) { *intersectionPoint = firstIntersection; - return true; } - return false; + return intersectionCount; } diff --git a/ApplicationCode/ReservoirDataModel/RigCell.h b/ApplicationCode/ReservoirDataModel/RigCell.h index 2929fd7ea1..319ab28c8a 100644 --- a/ApplicationCode/ReservoirDataModel/RigCell.h +++ b/ApplicationCode/ReservoirDataModel/RigCell.h @@ -62,7 +62,7 @@ public: cvf::Vec3d center() const; cvf::Vec3d faceCenter(cvf::StructGridInterface::FaceType face) const; - bool firstIntersectionPoint(const cvf::Ray& ray, cvf::Vec3d* intersectionPoint) const; + int firstIntersectionPoint(const cvf::Ray& ray, cvf::Vec3d* intersectionPoint) const; bool isLongPyramidCell(double maxHeightFactor = 5, double nodeNearTolerance = 1e-3 ) const; private: caf::SizeTArray8 m_cornerIndices; diff --git a/ApplicationCode/ReservoirDataModel/RigGridBase.cpp b/ApplicationCode/ReservoirDataModel/RigGridBase.cpp index 7de99d1f11..be17a9c70b 100644 --- a/ApplicationCode/ReservoirDataModel/RigGridBase.cpp +++ b/ApplicationCode/ReservoirDataModel/RigGridBase.cpp @@ -168,6 +168,9 @@ void RigGridBase::cellCornerVertices(size_t cellIndex, cvf::Vec3d vertices[8]) c //-------------------------------------------------------------------------------------------------- size_t RigGridBase::cellIndexFromIJK(size_t i, size_t j, size_t k) const { + CVF_TIGHT_ASSERT(i != cvf::UNDEFINED_SIZE_T && j != cvf::UNDEFINED_SIZE_T && k != cvf::UNDEFINED_SIZE_T ); + CVF_TIGHT_ASSERT(i < m_gridPointDimensions.x() && j < m_gridPointDimensions.y() && k < m_gridPointDimensions.z() ); + size_t ci = i + j*(m_gridPointDimensions.x() - 1) + k*((m_gridPointDimensions.x() - 1)*(m_gridPointDimensions.y() - 1)); return ci; } diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp index 8f27fc9a20..1ebacb6c1a 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp +++ b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp @@ -407,7 +407,7 @@ void RigReservoirBuilderMock::addWellData(RigCaseData* eclipseCase, RigGridBase* { if (connIdx == (size_t)(connectionCount/4)) continue; - RigWellResultCell data; + RigWellResultPoint data; data.m_gridIndex = 0; if (connIdx < dim.y()-2) @@ -425,28 +425,28 @@ void RigReservoirBuilderMock::addWellData(RigCaseData* eclipseCase, RigGridBase* data.m_isOpen = false; } - if (wellSegment.m_wellCells.size() == 0 || wellSegment.m_wellCells.back().m_gridCellIndex != data.m_gridCellIndex) + if (wellSegment.m_branchResultPoints.size() == 0 || wellSegment.m_branchResultPoints.back().m_gridCellIndex != data.m_gridCellIndex) { - wellSegment.m_wellCells.push_back(data); + wellSegment.m_branchResultPoints.push_back(data); if (connIdx == connectionCount / 2 ) { - RigWellResultCell deadEndData = data; + RigWellResultPoint deadEndData = data; deadEndData.m_gridCellIndex = data.m_gridCellIndex + 1; deadEndData.m_isOpen = true; - RigWellResultCell deadEndData1 = data; + RigWellResultPoint deadEndData1 = data; deadEndData1.m_gridCellIndex = data.m_gridCellIndex + 2; deadEndData.m_isOpen = false; - wellSegment.m_wellCells.push_back(deadEndData); - wellSegment.m_wellCells.push_back(deadEndData1); + wellSegment.m_branchResultPoints.push_back(deadEndData); + wellSegment.m_branchResultPoints.push_back(deadEndData1); deadEndData.m_isOpen = true; - wellSegment.m_wellCells.push_back(deadEndData); + wellSegment.m_branchResultPoints.push_back(deadEndData); data.m_isOpen = true; - wellSegment.m_wellCells.push_back(data); + wellSegment.m_branchResultPoints.push_back(data); } } @@ -454,9 +454,9 @@ void RigReservoirBuilderMock::addWellData(RigCaseData* eclipseCase, RigGridBase* { data.m_gridCellIndex = grid->cellIndexFromIJK(1 , 1 + connIdx , 2 + connIdx); - if (wellSegment.m_wellCells.size() == 0 || wellSegment.m_wellCells.back().m_gridCellIndex != data.m_gridCellIndex) + if (wellSegment.m_branchResultPoints.size() == 0 || wellSegment.m_branchResultPoints.back().m_gridCellIndex != data.m_gridCellIndex) { - wellSegment.m_wellCells.push_back(data); + wellSegment.m_branchResultPoints.push_back(data); } } } diff --git a/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.cpp b/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.cpp index a36cf5752f..ced9d08835 100644 --- a/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.cpp @@ -104,6 +104,14 @@ size_t RigSingleWellResultsData::firstResultTimeStep() const return cvf::UNDEFINED_SIZE_T; } +bool operator== (const RigWellResultPoint& p1, const RigWellResultPoint& p2) +{ + return + p1.m_gridIndex == p2.m_gridIndex + && p1.m_gridCellIndex == p2.m_gridCellIndex + && p1.m_ertBranchId == p2.m_ertBranchId + && p1.m_ertSegmentId == p2.m_ertSegmentId; +} //-------------------------------------------------------------------------------------------------- /// @@ -112,16 +120,16 @@ void RigSingleWellResultsData::computeStaticWellCellPath() { if (m_wellCellsTimeSteps.size() == 0) return; - std::map < size_t, std::list< RigWellResultCell > > staticWellBranches; + std::map < int, std::list< RigWellResultPoint > > staticWellBranches; // Add ResultCell data from the first timestep to the final result. for (size_t bIdx = 0; bIdx < m_wellCellsTimeSteps[0].m_wellResultBranches.size(); ++bIdx) { - size_t branchNumber = m_wellCellsTimeSteps[0].m_wellResultBranches[bIdx].m_branchNumber; - std::vector& frameCells = m_wellCellsTimeSteps[0].m_wellResultBranches[bIdx].m_wellCells; + int branchNumber = m_wellCellsTimeSteps[0].m_wellResultBranches[bIdx].m_ertBranchId; + std::vector& frameCells = m_wellCellsTimeSteps[0].m_wellResultBranches[bIdx].m_branchResultPoints; - std::list< RigWellResultCell >& branch = staticWellBranches[branchNumber]; + std::list< RigWellResultPoint >& branch = staticWellBranches[branchNumber]; for(size_t cIdx = 0; cIdx < frameCells.size(); ++cIdx) { @@ -137,37 +145,25 @@ void RigSingleWellResultsData::computeStaticWellCellPath() for (size_t bIdx = 0; bIdx < m_wellCellsTimeSteps[tIdx].m_wellResultBranches.size(); ++bIdx) { - size_t branchNumber = m_wellCellsTimeSteps[tIdx].m_wellResultBranches[bIdx].m_branchNumber; - std::vector& resBranch = m_wellCellsTimeSteps[tIdx].m_wellResultBranches[bIdx].m_wellCells; + int branchId = m_wellCellsTimeSteps[tIdx].m_wellResultBranches[bIdx].m_ertBranchId; + std::vector& resBranch = m_wellCellsTimeSteps[tIdx].m_wellResultBranches[bIdx].m_branchResultPoints; - std::list< RigWellResultCell >& stBranch = staticWellBranches[branchNumber]; - std::list< RigWellResultCell >::iterator it; - std::list< RigWellResultCell >::iterator sStartIt; - std::list< RigWellResultCell >::iterator sEndIt; + std::list< RigWellResultPoint >& stBranch = staticWellBranches[branchId]; + std::list< RigWellResultPoint >::iterator it; + std::list< RigWellResultPoint >::iterator sStartIt; + std::list< RigWellResultPoint >::iterator sEndIt; size_t rStartIdx; size_t rEndIdx; - - size_t sGridIdx; - size_t sCellIdx; - size_t rGridIdx; - size_t rCellIdx; - // First detect if we have cells on the start of the result frame, that is not in the static frame { sEndIt = stBranch.begin(); bool found = false; if (stBranch.size()) { - sGridIdx = sEndIt->m_gridIndex; - sCellIdx = sEndIt->m_gridCellIndex; - for (rEndIdx = 0; !found && rEndIdx < resBranch.size(); ++rEndIdx) { - rGridIdx = resBranch[rEndIdx].m_gridIndex; - rCellIdx = resBranch[rEndIdx].m_gridCellIndex; - - if (sGridIdx == rGridIdx && sCellIdx == rCellIdx) { found = true; break; } + if ((*sEndIt) == (resBranch[rEndIdx])) { found = true; break; } } } @@ -202,16 +198,10 @@ void RigSingleWellResultsData::computeStaticWellCellPath() if (sEndIt != stBranch.end()) ++sEndIt; for ( ; sEndIt != stBranch.end() ; ++sEndIt) { - sGridIdx = sEndIt->m_gridIndex; - sCellIdx = sEndIt->m_gridCellIndex; - bool found = false; for (rEndIdx += 1; !found && rEndIdx < resBranch.size(); ++rEndIdx) { - rGridIdx = resBranch[rEndIdx].m_gridIndex; - rCellIdx = resBranch[rEndIdx].m_gridCellIndex; - - if (sGridIdx == rGridIdx && sCellIdx == rCellIdx) { found = true; break; } + if ((*sEndIt) == (resBranch[rEndIdx])) { found = true; break; } } if (found) @@ -245,27 +235,51 @@ void RigSingleWellResultsData::computeStaticWellCellPath() // Populate the static well info - std::map < size_t, std::list< RigWellResultCell > >::iterator bIt; + std::map < int, std::list< RigWellResultPoint > >::iterator bIt; m_staticWellCells.m_wellResultBranches.clear(); m_staticWellCells.m_wellHead = m_wellCellsTimeSteps[0].m_wellHead; for (bIt = staticWellBranches.begin(); bIt != staticWellBranches.end(); ++bIt) { - RigWellResultBranch rigBranch; - rigBranch.m_branchNumber = bIt->first; + if (bIt->first >= m_wellCellsTimeSteps[0].m_wellResultBranches.size()) + { + continue; + } - std::list< RigWellResultCell >& branch = bIt->second; - std::list< RigWellResultCell >::iterator cIt; + // Copy from first time step + RigWellResultBranch rigBranch = m_wellCellsTimeSteps[0].m_wellResultBranches[bIt->first]; + rigBranch.m_ertBranchId = bIt->first; + // Clear well cells, and insert the collection of well cells for the static situation + rigBranch.m_branchResultPoints.clear(); + + std::list< RigWellResultPoint >& branch = bIt->second; + std::list< RigWellResultPoint >::iterator cIt; for (cIt = branch.begin(); cIt != branch.end(); ++cIt) { - RigWellResultCell rwc = *cIt; + RigWellResultPoint rwc = *cIt; rwc.m_isOpen = false; // Reset the dynamic property - rigBranch.m_wellCells.push_back(*cIt); + rigBranch.m_branchResultPoints.push_back(*cIt); } m_staticWellCells.m_wellResultBranches.push_back(rigBranch); } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigSingleWellResultsData::setMultiSegmentWell(bool isMultiSegmentWell) +{ + m_isMultiSegmentWell = isMultiSegmentWell; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RigSingleWellResultsData::isMultiSegmentWell() const +{ + return m_isMultiSegmentWell; +} + diff --git a/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h b/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h index 7e27f23073..108448ab32 100644 --- a/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h +++ b/ApplicationCode/ReservoirDataModel/RigSingleWellResultsData.h @@ -25,33 +25,69 @@ #include "RimDefines.h" #include #include +#include "cvfVector3.h" -struct RigWellResultCell +struct RigWellResultPoint { - RigWellResultCell() : + RigWellResultPoint() : m_gridIndex(cvf::UNDEFINED_SIZE_T), m_gridCellIndex(cvf::UNDEFINED_SIZE_T), - m_branchId(-1), - m_segmentId(-1), - m_isOpen(false) + m_isOpen(false), + m_ertBranchId(-1), + m_ertSegmentId(-1), + m_bottomPosition(cvf::Vec3d::UNDEFINED), + m_branchConnectionCount(0) { } + bool isPointValid() const + { + return m_bottomPosition != cvf::Vec3d::UNDEFINED; + } + + bool isCell() const + { + return m_gridCellIndex != cvf::UNDEFINED_SIZE_T; + } + + bool isValid() const + { + return isCell() || isPointValid(); + } + + size_t m_gridIndex; size_t m_gridCellIndex; //< Index to cell which is included in the well - int m_branchId; - int m_segmentId; bool m_isOpen; //< Marks the well as open or closed as of Eclipse simulation + + int m_ertBranchId; + int m_ertSegmentId; + + cvf::Vec3d m_bottomPosition; + size_t m_branchConnectionCount; }; + struct RigWellResultBranch { RigWellResultBranch() : - m_branchNumber(cvf::UNDEFINED_SIZE_T) + m_branchIndex(cvf::UNDEFINED_SIZE_T), + m_ertBranchId(-1), + m_outletBranchIndex_OBSOLETE(cvf::UNDEFINED_SIZE_T), + m_outletBranchHeadCellIndex_OBSOLETE(cvf::UNDEFINED_SIZE_T) {} - size_t m_branchNumber; - std::vector m_wellCells; + + size_t m_branchIndex; + int m_ertBranchId; + + std::vector m_branchResultPoints; + + // Grid cell from last connection in outlet segment. For MSW wells, this is either well head or a well result cell in another branch + // For standard wells, this is always well head. + size_t m_outletBranchIndex_OBSOLETE; + size_t m_outletBranchHeadCellIndex_OBSOLETE; + }; class RigWellResultFrame @@ -65,8 +101,10 @@ public: m_productionType(UNDEFINED_PRODUCTION_TYPE) { } - const RigWellResultCell* findResultCell(size_t gridIndex, size_t gridCellIndex) const + const RigWellResultPoint* findResultCell(size_t gridIndex, size_t gridCellIndex) const { + CVF_ASSERT(gridIndex != cvf::UNDEFINED_SIZE_T && gridCellIndex != cvf::UNDEFINED_SIZE_T); + if (m_wellHead.m_gridCellIndex == gridCellIndex && m_wellHead.m_gridIndex == gridIndex ) { return &m_wellHead; @@ -74,12 +112,12 @@ public: for (size_t wb = 0; wb < m_wellResultBranches.size(); ++wb) { - for (size_t wc = 0; wc < m_wellResultBranches[wb].m_wellCells.size(); ++wc) + for (size_t wc = 0; wc < m_wellResultBranches[wb].m_branchResultPoints.size(); ++wc) { - if ( m_wellResultBranches[wb].m_wellCells[wc].m_gridCellIndex == gridCellIndex - && m_wellResultBranches[wb].m_wellCells[wc].m_gridIndex == gridIndex ) + if ( m_wellResultBranches[wb].m_branchResultPoints[wc].m_gridCellIndex == gridCellIndex + && m_wellResultBranches[wb].m_branchResultPoints[wc].m_gridIndex == gridIndex ) { - return &(m_wellResultBranches[wb].m_wellCells[wc]); + return &(m_wellResultBranches[wb].m_branchResultPoints[wc]); } } } @@ -87,9 +125,24 @@ public: return NULL; } + const RigWellResultPoint* findResultCellFromOutletSpecification(size_t branchIndex, size_t wellResultCellIndex) const + { + if (branchIndex != cvf::UNDEFINED_SIZE_T && branchIndex < m_wellResultBranches.size()) + { + const RigWellResultBranch& resBranch = m_wellResultBranches[branchIndex]; + if (wellResultCellIndex != cvf::UNDEFINED_SIZE_T && wellResultCellIndex < resBranch.m_branchResultPoints.size()) + { + return (&resBranch.m_branchResultPoints[wellResultCellIndex]); + } + } + + return NULL; + } + + WellProductionType m_productionType; bool m_isOpen; - RigWellResultCell m_wellHead; + RigWellResultPoint m_wellHead; QDateTime m_timestamp; std::vector m_wellResultBranches; @@ -102,6 +155,11 @@ public: class RigSingleWellResultsData : public cvf::Object { public: + RigSingleWellResultsData() { m_isMultiSegmentWell = false; } + + void setMultiSegmentWell(bool isMultiSegmentWell); + bool isMultiSegmentWell() const; + bool hasWellResult(size_t resultTimeStepIndex) const; size_t firstResultTimeStep() const; @@ -113,6 +171,7 @@ public: public: QString m_wellName; + bool m_isMultiSegmentWell; std::vector m_resultTimeStepIndexToWellTimeStepIndex; // Well result timesteps may differ from result timesteps std::vector< RigWellResultFrame > m_wellCellsTimeSteps; diff --git a/CommonCode/cvfStructGrid.cpp b/CommonCode/cvfStructGrid.cpp index a268228b9a..6788a8982e 100644 --- a/CommonCode/cvfStructGrid.cpp +++ b/CommonCode/cvfStructGrid.cpp @@ -160,11 +160,11 @@ void StructGridInterface::neighborIJKAtCellFace(size_t i, size_t j, size_t k, Fa switch (face) { case POS_I : (*ni)++; break; - case NEG_I : (*ni)--; break; + case NEG_I : if (i > 0) (*ni)--; else (*ni) = cvf::UNDEFINED_SIZE_T; break; case POS_J : (*nj)++; break; - case NEG_J : (*nj)--; break; + case NEG_J : if (j > 0) (*nj)--; else (*nj) = cvf::UNDEFINED_SIZE_T; break; case POS_K : (*nk)++; break; - case NEG_K : (*nk)--; break; + case NEG_K : if (k > 0) (*nk)--; else (*nk) = cvf::UNDEFINED_SIZE_T; break; } } diff --git a/ResInsightVersion.cmake b/ResInsightVersion.cmake index 4bd9b5a229..a516beae90 100644 --- a/ResInsightVersion.cmake +++ b/ResInsightVersion.cmake @@ -1,7 +1,7 @@ set(CMAKE_MAJOR_VERSION 0) set(CMAKE_MINOR_VERSION 9) -set(CMAKE_PATCH_VERSION 20) +set(CMAKE_PATCH_VERSION 23) set(PRODUCTVER ${CMAKE_MAJOR_VERSION},${CMAKE_MINOR_VERSION},0,${CMAKE_PATCH_VERSION}) set(STRPRODUCTVER ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}) diff --git a/ThirdParty/Ert/.gitignore b/ThirdParty/Ert/.gitignore new file mode 100644 index 0000000000..14df4ceb91 --- /dev/null +++ b/ThirdParty/Ert/.gitignore @@ -0,0 +1,23 @@ +*.o +*.so +.svn/ +*/.svn/ +*.pyc +*~ + +# /devel/libenkf/src/ +/devel/libenkf/src/.faultlist + +# /develbranch/libenkf/src/ +/develbranch/libenkf/src/.faultlist + +# Ignore build catalog +/build + +# Ignore pdf from tex-test +/devel/libert_util/tests/data/latex_OK.pdf +# Ignore Statoil test data +/devel/test-data/Statoil + +# Ignore the ert_local python file which is needed to run some python tests +/devel/python/python/ert/ecl/ecl_local.py diff --git a/ThirdParty/Ert/README b/ThirdParty/Ert/README index 5718e9c9d8..684da78e00 100644 --- a/ThirdParty/Ert/README +++ b/ThirdParty/Ert/README @@ -207,57 +207,45 @@ in the devel/python/docs directory and in the Python classes themselves. -5. Testing +5. Test -The ERT is very weak on tests, but that is being improved. There are two different -categories of tests: - - CMake tests: CMake has a system for adding and running tests, and - these can be invoked with the command 'make test' after the - normal build process has completed, or alternatively the - 'ctest' test-runner which allows more options on which tests to run. +The ert codebase has a small but increasing test coverage. The tests +are typically located in a per-library subdirectory tests/. The test +framework is based on ctest which basically works like this: - Python test: The python directory devel/python/test has several - python unittests. These tests test both the Python wrappers - and the underlying C code and serve as quite good integration - tests. Read the content of devel/python/test/README carfully - before you invoke the Python tests, you might have to update - the local_(csh|bash) scripts to reflect your build output - path. + 1. In the CMakeLists.txt file testing is enabled with + ENABLE_TESTING(). + 2. Tests are added with: -5.1 Test data & labels + add_test( test_name test_executable arg1 arg2 arg3 ... ) -Unfortunately a large fraction of the test data is based on Statoil -internal data, and is not available on GitHub. All the tests which are -based on Statoil internal test data are labeled with the label -'Statoil', and using the 'ctest' program you can use the -L and -LE -options to include/exclude tests based on their label. + If the executable exits with status 0 the test has passed, + otherwise it has failed. The executable run by the test can + typically be an executable built as part of the solution, but can + in principle be an arbitrary executable like a dedicated test + runner or e.g. the Python interpreter. - ctest -L Statoil # Run all the tests with the 'Statoil' label - ctest -LE Statoil # Run all the tests without the 'Statoil' label +5.1 Test of C code -The argument to the -L and -LE options are regular expressions, -i.e. in the case above all tests which have a label matching the -regexp 'Statoil' will be run. A test can only have one single label, -but due to to the regexp mechanism we can create a 'list-like' -structure by chaining labels together; by convention the label -elements are joined with ':'. In the example +The main part of the testing infrastructure is small C applications +which are added like this: - set_property( TEST test_name PROPERTY LABELS Statoil:Python ) + add_executable( test_exe test_source.c ) + target_link_libraries( test_exe lib ) + add_test( test_name ${EXECUTABLE_OUTPUT_PATH}/test_exe commandline_arg1 commandline_arg2 ) -the labels 'Statoil' and 'Python' are applied to the test. The labels -in use are: +Where the two first lines create the test executable in the normal +way, and the last line adds it as a test. - Statoil: This indicates that the test makes use of Statoil internal - test data, and will fail if the Statoil test data have not - been made available according to the description in - devel/test-data/README.txt +5.2 Test of Python Code - Python: This indicates that the test is a Python unittest, and the - Python interpreter will be the test runner for the test. +In devel/python/test there are several files with Python tests, these +files are executable files and they are invoked directly from the +commandline. A limited number of the tests have been integrated in the +ctest system. -5.2 Test names +5.3 Test names The tests in the cmake build system follow the naming convention of the library which functionality they are testing - i.e. all tests in @@ -269,5 +257,45 @@ can be used to include and exclude tests based on their name ctest -E ecl # Run all tests NOT matching the regexp 'ecl' -The python tests are not yet integrated into this convention.... - +5.4 Test labels + +Using the cmake set_property() function it is possible to assigne +labels to the test, and the -L and -LE options to ctest can be used to +limit which tests to run. A test can only have one label; in the +current ctest setup different labels are combined into one composite +label with a ":" separator, i.e. + + set_property( TEST test_xxx PROPERTY LABELS StatoilData:Python) + +will set the 'StatoilData' and 'Python' properties on test_xxx. The +labels currently maintained in the ert test setup are: + + StatoilData: This implies that the test makes use of Statoil + internal data. If you are in Statoil/Bergen you can see more + details in file devel/test-data/README for how to make this data + available. + + If you are not in Statoil/Bergen you must pass the option: "-EL + StatoilData" to ctest to skip all the tests which require + Statoil data. + + StatoilBuild: There is one python test which makes use of Statoil + internal configuration data, this test is labeled with + StatoilBuild. If you want to run this test you must set the + cmake option ECL_LOCAL_TARGET to point to a file which contains + some local configuration settings, e.g. where the ECLIPSE binary + is installed. + + Python: This label is used to indicate that we are talking about a + Python test. + + LSF: This labels indicates that the test needs a working LSF + environment to run. + + + + ctest -L Statoil # Run all tests labeled with Statoil - both + # StatoilData and StatoilBuild + + ctest -EL "Statoil|LSF" # Exclude all tests labeled with Statoil or LSF. + diff --git a/ThirdParty/Ert/devel/.gitignore b/ThirdParty/Ert/devel/.gitignore deleted file mode 100644 index 6d908bcd9a..0000000000 --- a/ThirdParty/Ert/devel/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/lib/ -ert_build_config.h -*_vector.[ch] diff --git a/ThirdParty/Ert/devel/CMakeLists.txt b/ThirdParty/Ert/devel/CMakeLists.txt index 4f60f3925c..f1f4687c25 100644 --- a/ThirdParty/Ert/devel/CMakeLists.txt +++ b/ThirdParty/Ert/devel/CMakeLists.txt @@ -22,21 +22,24 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows") set(ERT_WINDOWS TRUE) add_definitions( -DERT_WINDOWS ) +# This symbol must be defined to support large (> 2GB) files on windows. + add_definitions( -DWINDOWS_LFS ) endif() - +# Treat warnings as errors if not on Windows if (ERT_WINDOWS) set( CMAKE_C_FLAGS "-O2" ) set( CMAKE_CXX_FLAGS "-O2" ) else() - set( CMAKE_C_FLAGS "-g -O2 -Wall -Wno-unknown-pragmas -std=gnu99 " ) - set( CMAKE_CXX_FLAGS "-g -O2 -Wall" ) + set( CMAKE_C_FLAGS "-std=gnu99 -g -O2 -Wall -Wno-unknown-pragmas " ) + set( CMAKE_CXX_FLAGS "-g -Wall -O2 ") endif() - include(cmake/ert_check.cmake) include(cmake/ert_find.cmake) include(cmake/Modules/UseMultiArch.cmake) +include(cmake/ert_link.cmake) + set( INSTALL_GROUP "" CACHE STRING "Group to install as - blank to install as current group") set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) @@ -46,15 +49,9 @@ if (MSVC) set( LIBRARY_TYPE STATIC ) set( SHARED_LIB OFF ) else() - if (INSTALL_ERT) set( LIBRARY_TYPE SHARED ) set( SHARED_LIB ON ) - else() - set( LIBRARY_TYPE STATIC ) - set( SHARED_LIB OFF ) - endif(INSTALL_ERT) -endif(MSVC) - +endif() if (MSVC) diff --git a/ThirdParty/Ert/devel/cmake/cmake_pyc2 b/ThirdParty/Ert/devel/cmake/cmake_pyc2 index d1ecbf7279..b32fd967a7 100644 --- a/ThirdParty/Ert/devel/cmake/cmake_pyc2 +++ b/ThirdParty/Ert/devel/cmake/cmake_pyc2 @@ -11,7 +11,11 @@ target_file = sys.argv[2] (target_path , tail) = os.path.split( target_file ) if not os.path.exists( target_path ): - os.makedirs( target_path ) + try: + os.makedirs( target_path ) + except: + # When running with make -j 4 there might be a race to create this directory. + pass shutil.copyfile( src_file , target_file ) try: diff --git a/ThirdParty/Ert/devel/cmake/cmake_pyc_tree b/ThirdParty/Ert/devel/cmake/cmake_pyc_tree index 790ce984d9..eeeaa389b6 100644 --- a/ThirdParty/Ert/devel/cmake/cmake_pyc_tree +++ b/ThirdParty/Ert/devel/cmake/cmake_pyc_tree @@ -17,6 +17,10 @@ for (root , dir_list , file_list) in os.walk( root_path ): (tmp , ext) = os.path.splitext( full_path ) if ext == ".py": py_file = full_path + pyc_file = full_path + "c" + if os.path.exists( pyc_file ): + os.unlink( pyc_file ) + try: print "Compiling: %s" % py_file py_compile.compile( py_file , doraise = True ) diff --git a/ThirdParty/Ert/devel/cmake/ert_check.cmake b/ThirdParty/Ert/devel/cmake/ert_check.cmake index 04bdca9f22..7f0cf3e77f 100644 --- a/ThirdParty/Ert/devel/cmake/ert_check.cmake +++ b/ThirdParty/Ert/devel/cmake/ert_check.cmake @@ -1,3 +1,8 @@ +check_function_exists( fseeko HAVE_FSEEKO ) +if (HAVE_HFSEEKO) + add_definitions( -DHAVE_FSEEKO ) +endif() + check_function_exists( regexec HAVE_REGEXP ) if (HAVE_REGEXP) add_definitions( -DHAVE_REGEXP ) @@ -84,6 +89,16 @@ if (HAVE_OPENDIR) add_definitions( -DHAVE__USLEEP ) endif() +# Checking based on compiling. Some of the code generates warnings, so we just cut down to bare-bone compiler flags. + +set( CMAKE_C_FLAGS_main ${CMAKE_C_FLAGS} ) +set( CMAKE_CXX_FLAGS_main ${CMAKE_CXX_FLAGS} ) + +if (NOT ERT_WINDOWS) + set( CMAKE_C_FLAGS "-std=gnu99" ) + set( CMAKE_CXX_FLAGS "") +endif() + try_compile( HAVE_ISFINITE ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/Tests/test_isfinite.c ) if (HAVE_ISFINITE) add_definitions( -DHAVE_ISFINITE ) @@ -110,3 +125,5 @@ if (ISREG_POSIX) add_definitions( -DHAVE_ISREG ) endif() +set( CMAKE_C_FLAGS ${CMAKE_C_FLAGS_main} ) +set( CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_main} ) diff --git a/ThirdParty/Ert/devel/cmake/ert_link.cmake b/ThirdParty/Ert/devel/cmake/ert_link.cmake new file mode 100644 index 0000000000..8664a76564 --- /dev/null +++ b/ThirdParty/Ert/devel/cmake/ert_link.cmake @@ -0,0 +1,14 @@ +if (CMAKE_COMPILER_IS_GNUCC) + option (USE_RUNPATH "Embed original dependency paths in installed library" OFF) + if (USE_RUNPATH) + set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + endif (USE_RUNPATH) +else() + set(USE_RUNPATH OFF) +endif() + + +macro( add_runpath target ) + set_target_properties( ${target} PROPERTIES LINK_FLAGS -Wl,--enable-new-dtags) +endmacro() \ No newline at end of file diff --git a/ThirdParty/Ert/devel/libanalysis/src/CMakeLists.txt b/ThirdParty/Ert/devel/libanalysis/src/CMakeLists.txt index 2346c6e9f0..32706738ef 100644 --- a/ThirdParty/Ert/devel/libanalysis/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libanalysis/src/CMakeLists.txt @@ -10,7 +10,9 @@ if (NEED_LIBDL) target_link_libraries( analysis dl ) endif() - +if (USE_RUNPATH) + add_runpath( analysis ) +endif() # List of modules set( CMAKE_SHARED_MODULE_PREFIX "" ) diff --git a/ThirdParty/Ert/devel/libconfig/CMakeLists.txt b/ThirdParty/Ert/devel/libconfig/CMakeLists.txt index da0dfb169f..6d8bd6b946 100644 --- a/ThirdParty/Ert/devel/libconfig/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libconfig/CMakeLists.txt @@ -1,2 +1,4 @@ add_subdirectory( src ) -add_subdirectory( tests ) +if (BUILD_TESTS) + add_subdirectory( tests ) +endif() diff --git a/ThirdParty/Ert/devel/libconfig/src/CMakeLists.txt b/ThirdParty/Ert/devel/libconfig/src/CMakeLists.txt index 555a39c4cd..6bac305ba7 100644 --- a/ThirdParty/Ert/devel/libconfig/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libconfig/src/CMakeLists.txt @@ -5,6 +5,9 @@ add_library( config ${LIBRARY_TYPE} ${source_files} ) set_target_properties( config PROPERTIES VERSION 1.0 SOVERSION 1.0 ) target_link_libraries( config ert_util ) +if (USE_RUNPATH) + add_runpath( config ) +endif() if (INSTALL_ERT) install(TARGETS config DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/ThirdParty/Ert/devel/libconfig/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libconfig/tests/CMakeLists.txt index c877ff0679..d6854e88cf 100644 --- a/ThirdParty/Ert/devel/libconfig/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libconfig/tests/CMakeLists.txt @@ -1,44 +1,44 @@ add_executable( config_append_test config_append_test.c ) -target_link_libraries( config_append_test config ) +target_link_libraries( config_append_test config test_util ) add_executable( config_node_test config_node_test.c ) -target_link_libraries( config_node_test config ) +target_link_libraries( config_node_test config test_util ) add_executable( config_typeOK config_typeOK.c ) -target_link_libraries( config_typeOK config ) +target_link_libraries( config_typeOK config test_util ) add_executable( config_typeFail config_typeFail.c ) -target_link_libraries( config_typeFail config ) +target_link_libraries( config_typeFail config test_util ) add_executable( config_path_elm config_path_elm.c ) -target_link_libraries( config_path_elm config ) +target_link_libraries( config_path_elm config test_util ) add_executable( config_root_path config_root_path.c ) -target_link_libraries( config_root_path config ) +target_link_libraries( config_root_path config test_util ) add_executable( config_include_test config_include_test.c) -target_link_libraries( config_include_test config) +target_link_libraries( config_include_test config test_util ) add_executable( config_content_node config_content_node.c) -target_link_libraries( config_content_node config) +target_link_libraries( config_content_node config test_util ) add_executable( config_content_item config_content_item.c) -target_link_libraries( config_content_item config) +target_link_libraries( config_content_item config test_util ) add_executable( config_argc config_argc.c) -target_link_libraries( config_argc config) +target_link_libraries( config_argc config test_util ) add_executable( config_error config_error.c) -target_link_libraries( config_error config) +target_link_libraries( config_error config test_util ) add_test( config_error ${EXECUTABLE_OUTPUT_PATH}/config_error ) add_executable( config_config config_config.c) -target_link_libraries( config_config config) +target_link_libraries( config_config config test_util ) add_test( config_config ${EXECUTABLE_OUTPUT_PATH}/config_config ) add_executable( config_schema_item config_schema_item.c) -target_link_libraries( config_schema_item config) +target_link_libraries( config_schema_item config test_util ) add_test( config_schema_item ${EXECUTABLE_OUTPUT_PATH}/config_schema_item ) add_test( config_typeOK ${EXECUTABLE_OUTPUT_PATH}/config_typeOK ${CMAKE_CURRENT_SOURCE_DIR}/data/type_testOK ) diff --git a/ThirdParty/Ert/devel/libconfig/tests/config_path_elm.c b/ThirdParty/Ert/devel/libconfig/tests/config_path_elm.c index 0cd949bdcd..f1d759214b 100644 --- a/ThirdParty/Ert/devel/libconfig/tests/config_path_elm.c +++ b/ThirdParty/Ert/devel/libconfig/tests/config_path_elm.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -29,17 +30,19 @@ int main(int argc , char ** argv) { #ifdef ERT_LINUX - const char * root = "/tmp/root"; const char * rel_path = "rel/path"; - const char * abs_path = "/tmp/root/rel/path"; const char * rel_true = "rel/path/XXX"; - const char * abs_true = "/tmp/root/rel/path/XXX"; const char * path_true1 = "rel/path/XXX"; - const char * path_true2 = "/tmp/root/rel/path/XXX"; + #endif - - util_make_path( root ); + test_work_area_type * work_area = test_work_area_alloc( "config_path_elm" , true ); + const char * root = test_work_area_get_cwd( work_area ); + char * abs_path = util_alloc_filename( root , "rel/path" , NULL); + char * abs_true = util_alloc_filename( root , "rel/path/XXX" , NULL); + char * path_true2 = util_alloc_filename( root , "rel/path/XXX" , NULL); + + chdir( test_work_area_get_original_cwd( work_area )); config_root_path_type * root_path = config_root_path_alloc( root ); { config_path_elm_type * path_elm = config_path_elm_alloc( root_path , rel_path ); @@ -54,7 +57,6 @@ int main(int argc , char ** argv) { config_path_elm_free( path_elm ); } - printf("test1 OK \n"); { config_path_elm_type * path_elm = config_path_elm_alloc( root_path , abs_path ); @@ -67,7 +69,6 @@ int main(int argc , char ** argv) { config_path_elm_free( path_elm ); } - printf("test2 OK \n"); config_root_path_free( root_path ); chdir( root ); @@ -85,7 +86,6 @@ int main(int argc , char ** argv) { config_path_elm_free( path_elm ); } - printf("test3 OK \n"); exit(0); } diff --git a/ThirdParty/Ert/devel/libconfig/tests/config_root_path.c b/ThirdParty/Ert/devel/libconfig/tests/config_root_path.c index cd7a1fde9c..c23af67b29 100644 --- a/ThirdParty/Ert/devel/libconfig/tests/config_root_path.c +++ b/ThirdParty/Ert/devel/libconfig/tests/config_root_path.c @@ -32,13 +32,13 @@ int main(int argc , char ** argv) { { config_root_path_type * root_path = config_root_path_alloc( NULL ); - if (!test_string_equal( config_root_path_get_abs_path( root_path ) , cwd )) + if (!test_check_string_equal( config_root_path_get_abs_path( root_path ) , cwd )) test_error_exit("abs:path:%s expeceted:%s \n",config_root_path_get_abs_path( root_path ) , cwd ); - if (!test_string_equal( config_root_path_get_input_path( root_path ) , NULL )) + if (!test_check_string_equal( config_root_path_get_input_path( root_path ) , NULL )) test_error_exit("input:path:%s expeceted:%s \n",config_root_path_get_input_path( root_path ) , NULL ); - if (!test_string_equal( config_root_path_get_rel_path( root_path ) , NULL )) + if (!test_check_string_equal( config_root_path_get_rel_path( root_path ) , NULL )) test_error_exit("rel:path:%s expeceted:%s \n",config_root_path_get_rel_path( root_path ) , NULL ); @@ -62,10 +62,10 @@ int main(int argc , char ** argv) { config_root_path_type * root_path1 = config_root_path_alloc( input_path ); config_root_path_type * root_path2 = config_root_path_alloc( rel_path ); - if (!test_string_equal( config_root_path_get_rel_path( root_path1 ) , config_root_path_get_rel_path( root_path2 ))) + if (!test_check_string_equal( config_root_path_get_rel_path( root_path1 ) , config_root_path_get_rel_path( root_path2 ))) test_error_exit("Rel: %s != %s \n",config_root_path_get_rel_path( root_path1 ) , config_root_path_get_rel_path( root_path2)); - if (!test_string_equal( config_root_path_get_abs_path( root_path1 ) , config_root_path_get_abs_path( root_path2 ))) + if (!test_check_string_equal( config_root_path_get_abs_path( root_path1 ) , config_root_path_get_abs_path( root_path2 ))) test_error_exit("Abs: %s != %s \n",config_root_path_get_abs_path( root_path1 ) , config_root_path_get_abs_path( root_path2 )); config_root_path_free( root_path1 ); diff --git a/ThirdParty/Ert/devel/libecl/CMakeLists.txt b/ThirdParty/Ert/devel/libecl/CMakeLists.txt index 90b94538d4..faca95eb2b 100644 --- a/ThirdParty/Ert/devel/libecl/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl/CMakeLists.txt @@ -1,10 +1,5 @@ add_subdirectory( src ) -#if (BUILD_APPLICATIONS OR BUILD_ECL_SUMMARY) -# add_subdirectory( applications ) -#endif() add_subdirectory( applications ) -if (BUILD_TESTS) - add_subdirectory( tests ) -endif() +add_subdirectory( tests ) diff --git a/ThirdParty/Ert/devel/libecl/applications/CMakeLists.txt b/ThirdParty/Ert/devel/libecl/applications/CMakeLists.txt index afc4dba904..131e33900d 100644 --- a/ThirdParty/Ert/devel/libecl/applications/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl/applications/CMakeLists.txt @@ -3,6 +3,7 @@ if (BUILD_APPLICATIONS) add_executable( make_grid make_grid.c ) add_executable( grdecl_grid grdecl_grid.c ) add_executable( summary2csv summary2csv.c ) + add_executable( summary2csv2 summary2csv2.c ) if (ERT_LINUX) add_executable( esummary.x esummary.c ) add_executable( convert.x convert.c ) @@ -15,7 +16,7 @@ if (BUILD_APPLICATIONS) add_executable( summary.x view_summary.c ) add_executable( select_test.x select_test.c ) add_executable( load_test.x load_test.c ) - set(program_list summary2csv esummary.x kw_extract.x grdecl_grid make_grid sum_write load_test.x grdecl_test.x grid_dump_ascii.x select_test.x grid_dump.x convert.x kw_list.x grid_info.x summary.x) + set(program_list summary2csv2 summary2csv esummary.x kw_extract.x grdecl_grid make_grid sum_write load_test.x grdecl_test.x grid_dump_ascii.x select_test.x grid_dump.x convert.x kw_list.x grid_info.x summary.x) else() # The stupid .x extension creates problems on windows add_executable( convert convert.c ) @@ -28,13 +29,16 @@ if (BUILD_APPLICATIONS) add_executable( summary view_summary.c ) add_executable( select_test select_test.c ) add_executable( load_test load_test.c ) - set(program_list summary2csv kw_extract grdecl_grid make_grid sum_write load_test grdecl_test grid_dump_ascii select_test grid_dump convert kw_list grid_info summary) + set(program_list summary2csv2 summary2csv kw_extract grdecl_grid make_grid sum_write load_test grdecl_test grid_dump_ascii select_test grid_dump convert kw_list grid_info summary) endif() foreach(prog ${program_list}) target_link_libraries( ${prog} ecl ert_util ) - + if (USE_RUNPATH) + add_runpath( ${prog} ) + endif() + #----------------------------------------------------------------- set (destination ${CMAKE_INSTALL_PREFIX}/bin) if (INSTALL_ERT) @@ -51,6 +55,9 @@ if (BUILD_ENS_PLOT) include_directories( ${PLPLOT_HEADER} ) add_executable( ens_plot.x ens_plot.c ) target_link_libraries( ens_plot.x plot ecl) + if (USE_RUNPATH) + add_runpath( ens_plot.x ) + endif() set (destination ${CMAKE_INSTALL_PREFIX}/bin) if (INSTALL_ERT) @@ -67,6 +74,9 @@ endif() if (BUILD_ECL_SUMMARY) add_executable( ecl_summary view_summary.c ) target_link_libraries( ecl_summary ecl) + if (USE_RUNPATH) + add_runpath( ecl_summary ) + endif() set (destination ${CMAKE_INSTALL_PREFIX}/bin) if (INSTALL_ERT) diff --git a/ThirdParty/Ert/devel/libecl/applications/makefile b/ThirdParty/Ert/devel/libecl/applications/makefile deleted file mode 100644 index 7c3db2c7dd..0000000000 --- a/ThirdParty/Ert/devel/libecl/applications/makefile +++ /dev/null @@ -1,163 +0,0 @@ -# CMAKE generated file: DO NOT EDIT! -# Generated by "MinGW Makefiles" Generator, CMake Version 2.8 - -# Default target executed when no arguments are given to make. -default_target: all -.PHONY : default_target - -#============================================================================= -# Special targets provided by cmake. - -# Disable implicit rules so canoncical targets will work. -.SUFFIXES: - -# Remove some rules from gmake that .SUFFIXES does not remove. -SUFFIXES = - -.SUFFIXES: .hpux_make_needs_suffix_list - -# Suppress display of executed commands. -$(VERBOSE).SILENT: - -# A target that is always out of date. -cmake_force: -.PHONY : cmake_force - -#============================================================================= -# Set environment variables for the build. - -SHELL = cmd.exe - -# The CMake executable. -CMAKE_COMMAND = "C:\Program Files\CMake 2.8\bin\cmake.exe" - -# The command to remove a file. -RM = "C:\Program Files\CMake 2.8\bin\cmake.exe" -E remove -f - -# The program to use to edit the cache. -CMAKE_EDIT_COMMAND = "C:\Program Files\CMake 2.8\bin\cmake-gui.exe" - -# The top-level source directory on which CMake was run. -CMAKE_SOURCE_DIR = C:\code\ERT - -# The top-level build directory on which CMake was run. -CMAKE_BINARY_DIR = C:\code\ERT - -#============================================================================= -# Targets provided globally by CMake. - -# Special rule for the target edit_cache -edit_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..." - "C:\Program Files\CMake 2.8\bin\cmake-gui.exe" -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : edit_cache - -# Special rule for the target edit_cache -edit_cache/fast: edit_cache -.PHONY : edit_cache/fast - -# Special rule for the target rebuild_cache -rebuild_cache: - @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." - "C:\Program Files\CMake 2.8\bin\cmake.exe" -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) -.PHONY : rebuild_cache - -# Special rule for the target rebuild_cache -rebuild_cache/fast: rebuild_cache -.PHONY : rebuild_cache/fast - -# The main all target -all: cmake_check_build_system - cd /d C:\code\ERT && $(CMAKE_COMMAND) -E cmake_progress_start C:\code\ERT\CMakeFiles C:\code\ERT\libecl\applications\CMakeFiles\progress.marks - cd /d C:\code\ERT && $(MAKE) -f CMakeFiles\Makefile2 libecl/applications/all - $(CMAKE_COMMAND) -E cmake_progress_start C:\code\ERT\CMakeFiles 0 -.PHONY : all - -# The main clean target -clean: - cd /d C:\code\ERT && $(MAKE) -f CMakeFiles\Makefile2 libecl/applications/clean -.PHONY : clean - -# The main clean target -clean/fast: clean -.PHONY : clean/fast - -# Prepare targets for installation. -preinstall: all - cd /d C:\code\ERT && $(MAKE) -f CMakeFiles\Makefile2 libecl/applications/preinstall -.PHONY : preinstall - -# Prepare targets for installation. -preinstall/fast: - cd /d C:\code\ERT && $(MAKE) -f CMakeFiles\Makefile2 libecl/applications/preinstall -.PHONY : preinstall/fast - -# clear depends -depend: - cd /d C:\code\ERT && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles\Makefile.cmake 1 -.PHONY : depend - -# Convenience name for target. -libecl/applications/CMakeFiles/grid_info.x.dir/rule: - cd /d C:\code\ERT && $(MAKE) -f CMakeFiles\Makefile2 libecl/applications/CMakeFiles/grid_info.x.dir/rule -.PHONY : libecl/applications/CMakeFiles/grid_info.x.dir/rule - -# Convenience name for target. -grid_info.x: libecl/applications/CMakeFiles/grid_info.x.dir/rule -.PHONY : grid_info.x - -# fast build rule for target. -grid_info.x/fast: - cd /d C:\code\ERT && $(MAKE) -f libecl\applications\CMakeFiles\grid_info.x.dir\build.make libecl/applications/CMakeFiles/grid_info.x.dir/build -.PHONY : grid_info.x/fast - -grid_info.obj: grid_info.c.obj -.PHONY : grid_info.obj - -# target to build an object file -grid_info.c.obj: - cd /d C:\code\ERT && $(MAKE) -f libecl\applications\CMakeFiles\grid_info.x.dir\build.make libecl/applications/CMakeFiles/grid_info.x.dir/grid_info.c.obj -.PHONY : grid_info.c.obj - -grid_info.i: grid_info.c.i -.PHONY : grid_info.i - -# target to preprocess a source file -grid_info.c.i: - cd /d C:\code\ERT && $(MAKE) -f libecl\applications\CMakeFiles\grid_info.x.dir\build.make libecl/applications/CMakeFiles/grid_info.x.dir/grid_info.c.i -.PHONY : grid_info.c.i - -grid_info.s: grid_info.c.s -.PHONY : grid_info.s - -# target to generate assembly for a file -grid_info.c.s: - cd /d C:\code\ERT && $(MAKE) -f libecl\applications\CMakeFiles\grid_info.x.dir\build.make libecl/applications/CMakeFiles/grid_info.x.dir/grid_info.c.s -.PHONY : grid_info.c.s - -# Help Target -help: - @$(CMAKE_COMMAND) -E echo "The following are some of the valid targets for this Makefile:" - @$(CMAKE_COMMAND) -E echo "... all (the default if no target is provided)" - @$(CMAKE_COMMAND) -E echo "... clean" - @$(CMAKE_COMMAND) -E echo "... depend" - @$(CMAKE_COMMAND) -E echo "... edit_cache" - @$(CMAKE_COMMAND) -E echo "... grid_info.x" - @$(CMAKE_COMMAND) -E echo "... rebuild_cache" - @$(CMAKE_COMMAND) -E echo "... grid_info.obj" - @$(CMAKE_COMMAND) -E echo "... grid_info.i" - @$(CMAKE_COMMAND) -E echo "... grid_info.s" -.PHONY : help - - - -#============================================================================= -# Special targets to cleanup operation of make. - -# Special rule to run CMake to check the build system integrity. -# No rule that depends on this can have commands that come from listfiles -# because they might be regenerated. -cmake_check_build_system: - cd /d C:\code\ERT && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles\Makefile.cmake 0 -.PHONY : cmake_check_build_system - diff --git a/ThirdParty/Ert/devel/libecl/applications/summary2csv.c b/ThirdParty/Ert/devel/libecl/applications/summary2csv.c index 2a43ed4725..2b9fb94eb9 100644 --- a/ThirdParty/Ert/devel/libecl/applications/summary2csv.c +++ b/ThirdParty/Ert/devel/libecl/applications/summary2csv.c @@ -27,39 +27,32 @@ - -static void build_key_list( const ecl_sum_type * ecl_sum , stringlist_type * key_list ) { - int iw; +static bool extend_key_list( const ecl_sum_type * ecl_sum , const stringlist_type * var_list , const char * well , stringlist_type * key_list ) { + bool oil_producer = false; int last_step = ecl_sum_get_data_length( ecl_sum ) - 1; - stringlist_type * well_list = ecl_sum_alloc_well_list( ecl_sum , NULL ); - for (iw = 0; iw < stringlist_get_size( well_list ); iw++) { - const char * well = stringlist_iget( well_list , iw ); - char * wopt_key = ecl_sum_alloc_well_key( ecl_sum , "WOPR", well); - if (ecl_sum_has_key( ecl_sum , wopt_key) && (ecl_sum_get_well_var( ecl_sum , last_step , well , "WOPT") > 0 )) { - /* - We add all the keys unconditionally here; and then let the - ecl_sum_fprintf() function print a message on stderr if it is - missing. - */ - stringlist_append_owned_ref( key_list , ecl_sum_alloc_well_key( ecl_sum , "WOPR", well) ); - stringlist_append_owned_ref( key_list , ecl_sum_alloc_well_key( ecl_sum , "WOPT", well) ); - - stringlist_append_owned_ref( key_list , ecl_sum_alloc_well_key( ecl_sum , "WGPR", well) ); - stringlist_append_owned_ref( key_list , ecl_sum_alloc_well_key( ecl_sum , "WGPT", well) ); - - stringlist_append_owned_ref( key_list , ecl_sum_alloc_well_key( ecl_sum , "WWPR", well) ); - stringlist_append_owned_ref( key_list , ecl_sum_alloc_well_key( ecl_sum , "WWPT", well) ); - } else - printf("Ignoring well: %s \n",well); - free( wopt_key ); - } - stringlist_free( well_list ); + char * wopt_key = ecl_sum_alloc_well_key( ecl_sum , "WOPT", well); + if (ecl_sum_has_key( ecl_sum , wopt_key) && (ecl_sum_get_well_var( ecl_sum , last_step , well , "WOPT") > 0 )) { + /* + We add all the keys unconditionally here; and then let the + ecl_sum_fprintf() function print a message on stderr if it is + missing. + */ + int ivar; + for (ivar = 0; ivar < stringlist_get_size( var_list ); ivar++) { + const char * var = stringlist_iget( var_list , ivar ); + stringlist_append_owned_ref( key_list , ecl_sum_alloc_well_key( ecl_sum , var, well) ); + } + oil_producer = true; + } + free( wopt_key ); + return oil_producer; } int main(int argc , char ** argv) { { ecl_sum_fmt_type fmt; + bool well_rows = false; bool include_restart = true; int arg_offset = 1; @@ -71,23 +64,49 @@ int main(int argc , char ** argv) { { char * data_file = argv[arg_offset]; ecl_sum_type * ecl_sum; + stringlist_type * var_list = stringlist_alloc_new(); + + stringlist_append_ref( var_list , "WOPR" ); + stringlist_append_ref( var_list , "WOPT" ); + stringlist_append_ref( var_list , "WGPR" ); + stringlist_append_ref( var_list , "WGPT" ); + stringlist_append_ref( var_list , "WWPR" ); + stringlist_append_ref( var_list , "WWPT" ); ecl_sum_fmt_init_csv( &fmt ); ecl_sum = ecl_sum_fread_alloc_case__( data_file , ":" , include_restart); if (ecl_sum != NULL) { + char * csv_file = util_alloc_filename( NULL , ecl_sum_get_base(ecl_sum) , "txt"); // Will save to current path; can use ecl_sum_get_path() to save to target path instead. + FILE * stream = util_fopen( csv_file , "w"); + + stringlist_type * well_list = ecl_sum_alloc_well_list( ecl_sum , NULL ); stringlist_type * key_list = stringlist_alloc_new( ); - build_key_list( ecl_sum , key_list ); - { - char * csv_file = util_alloc_filename( NULL , ecl_sum_get_base(ecl_sum) , "txt"); // Weill save to current path; can use ecl_sum_get_path() to save to target path instead. - FILE * stream = util_fopen( csv_file , "w"); + int iw; + + for (iw = 0; iw < stringlist_get_size( well_list ); iw++) { + const char * well = stringlist_iget( well_list , iw ); + if (!extend_key_list( ecl_sum , var_list , well , key_list)) + fprintf(stderr , "Ignoring well: %s \n",well); + + if (well_rows) { + if (stringlist_get_size(key_list)) { + ecl_sum_fprintf(ecl_sum , stream , key_list , false , &fmt); + stringlist_clear( key_list ); + } + } + } + if (!well_rows) ecl_sum_fprintf(ecl_sum , stream , key_list , false , &fmt); - fclose( stream ); - free( csv_file ); - } + + stringlist_free( well_list ); stringlist_free( key_list ); ecl_sum_free(ecl_sum); + fclose( stream ); + free( csv_file ); } else fprintf(stderr,"summary2csv: No summary data found for case:%s\n", data_file ); + + stringlist_free( var_list ); } } } diff --git a/ThirdParty/Ert/devel/libecl/applications/summary2csv2.c b/ThirdParty/Ert/devel/libecl/applications/summary2csv2.c new file mode 100644 index 0000000000..7655f1f02b --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/applications/summary2csv2.c @@ -0,0 +1,146 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + The file 'summary2csv2.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include +#include + +#include +#include + +#include + + + + + +static void fprintf_line( const ecl_sum_type * ecl_sum , const ecl_sum_fmt_type * fmt , const char * well , int time_index , const stringlist_type * var_list , FILE * stream) { + /* WELL */ + fprintf(stream , fmt->header_fmt , well); + fprintf(stream , fmt->sep ); + + /* DAYS */ + fprintf(stream , fmt->days_fmt , ecl_sum_iget_sim_days(ecl_sum , time_index)); + fprintf(stream , fmt->sep ); + + /* DATE */ + { + struct tm ts; + const int DATE_STRING_LENGTH = 128; + char * date_string = util_malloc( DATE_STRING_LENGTH * sizeof * date_string); + time_t sim_time = ecl_sum_iget_sim_time(ecl_sum , time_index ); + util_localtime( &sim_time , &ts); + strftime( date_string , DATE_STRING_LENGTH - 1 , fmt->date_fmt , &ts); + fprintf(stream , date_string ); + free( date_string ); + } + + { + int ivar; + for (ivar = 0; ivar < stringlist_get_size( var_list ); ivar++) { + const char * var = stringlist_iget( var_list , ivar ); + double value = 0; + if (ecl_sum_has_well_var( ecl_sum , well , var )) + value = ecl_sum_get_well_var( ecl_sum , time_index , well , var ); + else + fprintf(stderr,"Missing variable:%s for well:%s - substituting 0.0 \n",var , well); + + fprintf(stream , fmt->sep ); + fprintf(stream , fmt->value_fmt , value ); + } + fprintf( stream , fmt->newline ); + } +} + + + +int main(int argc , char ** argv) { + { + ecl_sum_fmt_type fmt; + bool include_restart = true; + int arg_offset = 1; + + if (argc != 2) { + printf("You must supply the name of a case as:\n\n summary2csv.exe ECLIPSE_CASE\n\nThe case can optionally contain a leading path component.\n"); + exit(1); + } + + { + char * data_file = argv[arg_offset]; + ecl_sum_type * ecl_sum; + stringlist_type * var_list = stringlist_alloc_new(); + + stringlist_append_ref( var_list , "WOPR" ); + stringlist_append_ref( var_list , "WOPT" ); + stringlist_append_ref( var_list , "WGPR" ); + stringlist_append_ref( var_list , "WGPT" ); + stringlist_append_ref( var_list , "WWPR" ); + stringlist_append_ref( var_list , "WWPT" ); + + + ecl_sum_fmt_init_csv( &fmt ); + ecl_sum = ecl_sum_fread_alloc_case__( data_file , ":" , include_restart); + if (ecl_sum != NULL) { + char * csv_file = util_alloc_filename( NULL , ecl_sum_get_base(ecl_sum) , "txt"); // Will save to current path; can use ecl_sum_get_path() to save to target path instead. + FILE * stream = util_fopen( csv_file , "w"); + + stringlist_type * well_list = ecl_sum_alloc_well_list( ecl_sum , NULL ); + stringlist_type * key_list = stringlist_alloc_new( ); + + fprintf(stream , fmt.header_fmt , "WELLNAME"); + + fprintf(stream , fmt.sep ); + fprintf(stream , fmt.header_fmt , "DAYS"); + + fprintf(stream , fmt.sep ); + fprintf(stream , fmt.header_fmt , "DATES"); + + { + int ivar; + for (ivar = 0; ivar < stringlist_get_size( var_list ); ivar++) { + const char * var = stringlist_iget( var_list , ivar ); + fprintf(stream , fmt.sep ); + fprintf(stream , fmt.header_fmt , var ); + } + fprintf(stream , "\n"); + } + + { + int iw; + for (iw = 0; iw < stringlist_get_size( well_list ); iw++) { + const char * well = stringlist_iget( well_list , iw ); + if (ecl_sum_is_oil_producer( ecl_sum , well )) { + int time_index; + for (time_index = 0; time_index < ecl_sum_get_data_length( ecl_sum ); time_index++) + fprintf_line( ecl_sum , &fmt , well , time_index , var_list , stream); + } + } + } + + stringlist_free( well_list ); + stringlist_free( key_list ); + ecl_sum_free(ecl_sum); + fclose( stream ); + free( csv_file ); + } else + fprintf(stderr,"summary2csv2: No summary data found for case:%s\n", data_file ); + + stringlist_free( var_list ); + } + } +} diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_file_kw.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_file_kw.h index c6f5781404..e2f10ea252 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_file_kw.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_file_kw.h @@ -25,6 +25,8 @@ extern "C" { #include +#include + #include #include @@ -35,7 +37,7 @@ typedef struct inv_map_struct inv_map_type; ecl_file_kw_type * inv_map_get_file_kw( inv_map_type * inv_map , const ecl_kw_type * ecl_kw ); void inv_map_free( inv_map_type * map ); - ecl_file_kw_type * ecl_file_kw_alloc( const ecl_kw_type * ecl_kw , long offset); + ecl_file_kw_type * ecl_file_kw_alloc( const ecl_kw_type * ecl_kw , offset_type offset); void ecl_file_kw_free( ecl_file_kw_type * file_kw ); void ecl_file_kw_free__( void * arg ); ecl_kw_type * ecl_file_kw_get_kw( ecl_file_kw_type * file_kw , fortio_type * fortio, inv_map_type * inv_map); diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_grid.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_grid.h index 2ab1448567..124692ce9d 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_grid.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_grid.h @@ -30,7 +30,10 @@ extern "C" { #include #include #include +#include +#define ECL_GRID_GLOBAL_GRID "Global" // used as key in hash tables over grids. +#define ECL_GRID_MAINGRID_LGR_NR 0 typedef double (block_function_ftype) ( const double_vector_type *); typedef struct ecl_grid_struct ecl_grid_type; @@ -75,6 +78,10 @@ extern "C" { int ecl_grid_get_global_index3(const ecl_grid_type * , int , int , int ); int ecl_grid_get_global_index1A(const ecl_grid_type * ecl_grid , int active_index); int ecl_grid_get_global_index1F(const ecl_grid_type * ecl_grid , int active_fracture_index); + + const int_vector_type * ecl_grid_get_nnc_index_list( ecl_grid_type * grid ); + const nnc_info_type * ecl_grid_get_cell_nnc_info3( const ecl_grid_type * grid , int i , int j , int k); + const nnc_info_type * ecl_grid_get_cell_nnc_info1( const ecl_grid_type * grid , int global_index); ecl_grid_type * ecl_grid_alloc_GRDECL_kw( int nx, int ny , int nz , const ecl_kw_type * zcorn_kw , const ecl_kw_type * coord_kw , const ecl_kw_type * actnum_kw , const ecl_kw_type * mapaxes_kw ); ecl_grid_type * ecl_grid_alloc_GRDECL_data(int , int , int , const float * , const float * , const int * , const float * mapaxes); @@ -83,7 +90,7 @@ extern "C" { ecl_grid_type * ecl_grid_load_case( const char * case_input ); ecl_grid_type * ecl_grid_alloc_rectangular( int nx , int ny , int nz , double dx , double dy , double dz , const int * actnum); ecl_grid_type * ecl_grid_alloc_regular( int nx, int ny , int nz , const double * ivec, const double * jvec , const double * kvec , const int * actnum); - + bool ecl_grid_exists( const char * case_input ); char * ecl_grid_alloc_case_filename( const char * case_input ); @@ -130,16 +137,19 @@ extern "C" { void ecl_grid_dump(const ecl_grid_type * grid , FILE * stream); void ecl_grid_dump_ascii(const ecl_grid_type * grid , bool active_only , FILE * stream); - + /* lgr related functions */ const ecl_grid_type * ecl_grid_get_cell_lgr3(const ecl_grid_type * grid , int i, int j , int k); const ecl_grid_type * ecl_grid_get_cell_lgr1A(const ecl_grid_type * grid , int active_index); const ecl_grid_type * ecl_grid_get_cell_lgr1(const ecl_grid_type * grid , int global_index ); int ecl_grid_get_num_lgr(const ecl_grid_type * main_grid ); - int ecl_grid_get_grid_nr( const ecl_grid_type * ecl_grid ); - ecl_grid_type * ecl_grid_iget_lgr(const ecl_grid_type * main_grid , int lgr_nr); + int ecl_grid_get_lgr_nr( const ecl_grid_type * ecl_grid ); + ecl_grid_type * ecl_grid_iget_lgr(const ecl_grid_type * main_grid , int lgr_index); + ecl_grid_type * ecl_grid_get_lgr_from_lgr_nr(const ecl_grid_type * main_grid, int lgr_nr); ecl_grid_type * ecl_grid_get_lgr(const ecl_grid_type * main_grid, const char * __lgr_name); bool ecl_grid_has_lgr(const ecl_grid_type * main_grid, const char * __lgr_name); + const char * ecl_grid_iget_lgr_name( const ecl_grid_type * ecl_grid , int lgr_index); + const char * ecl_grid_get_lgr_name( const ecl_grid_type * ecl_grid , int lgr_nr); stringlist_type * ecl_grid_alloc_lgr_name_list(const ecl_grid_type * ecl_grid); int ecl_grid_get_parent_cell1( const ecl_grid_type * grid , int global_index); int ecl_grid_get_parent_cell3( const ecl_grid_type * grid , int i , int j , int k); @@ -171,6 +181,8 @@ extern "C" { void ecl_grid_cell_ri_export( const ecl_grid_type * ecl_grid , int global_index , double * ri_points); bool ecl_grid_dual_grid( const ecl_grid_type * ecl_grid ); + + UTIL_IS_INSTANCE_HEADER( ecl_grid ); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_kw_magic.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_kw_magic.h index 9bf019ffe2..7c664549eb 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_kw_magic.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_kw_magic.h @@ -104,6 +104,7 @@ extern "C" { #define ZWEL_KW "ZWEL" #define ICON_KW "ICON" #define ISEG_KW "ISEG" +#define RSEG_KW "RSEG" #define ECLIPSE100_OIL_DEN_KW "OIL_DEN" #define ECLIPSE100_GAS_DEN_KW "GAS_DEN" @@ -135,9 +136,9 @@ extern "C" { #define INTEHEAD_NSEGMX_INDEX 176 #define INTEHEAD_NLBRMX_INDEX 177 #define INTEHEAD_NISEGZ_INDEX 178 +#define INTEHEAD_NRSEGZ_INDEX 179 #define INTEHEAD_NILBRZ_INDEX 180 - #define DOUBHEAD_DAYS_INDEX 0 /*****************************************************************/ @@ -230,7 +231,12 @@ extern "C" { #define CONGRAT_KW "CONGRAT" /* Gas ... */ #define CONORAT_KW "CONORAT" /* Oil ... */ #define CONPRES_KW "CONPRES" /* Pressure ... */ - +#define CONLENST_KW "CONLENST" /* Length along MSW well */ +#define CONLENEN_KW "CONLENEN" /* Length to connection end for MSW well */ +#define CONVTUB_KW "CONVTUB" /* Volumetric flow at tubing head conditions. */ +#define CONOTUB_KW "CONOTUB" /* Volumetric oil flow at tubing head conditions. */ +#define CONGTUB_KW "CONGTUB" /* Volumetric gas flow at tubing head conditions. */ +#define CONWTUB_KW "CONWTUB" /* Volumetric water flow at tubing head conditions. */ #define WELLETC_TYPE_INDEX 5 /* At this keyword the WELLETC keyword contains a string @@ -264,7 +270,20 @@ extern "C" { the second element will be the name of the parent. */ #define MAPUNITS_KW "MAPUNITS" #define GRIDUNIT_KW "GRIDUNIT" - + +#define NNCHEAD_KW "NNCHEAD" /*Non-neighbour connection header*/ +#define NNC1_KW "NNC1" /*Upstream cell numbers for non-neighbour connections*/ +#define NNC2_KW "NNC2" /*Downstream cell numbers for non-neighbour connections*/ +#define NNCL_KW "NNCL" /*Cell numbers for LGR cells that are connected to global grid cells*/ +#define NNCG_KW "NNCG" /*Cell numbers for global cells connected to LGR cells*/ +#define NNCHEAD_NUMNNC_INDEX 0 /*Item 1 in non-neighbour connection header: number of NNCs. Only present for main grid*/ +#define NNCHEAD_LGR_INDEX 1 /*Item 2 in non-neighbour connection header: LGR number (0 for global grid)*/ +#define NNCHEADA_KW "NNCHEADA" /*Header for NNC's between two amalgamated LGRs*/ +#define NNA1_KW "NNA1" /*Cell numbers in connecting local grid ILOC1*/ +#define NNA2_KW "NNA2" /*Cell numbers in connecting local grid ILOC2*/ +#define NNCHEADA_ILOC1_INDEX 0 /*ILOC1: Index of first LGR*/ +#define NNCHEADA_ILOC2_INDEX 1 /*ILOC2: Index of second LGR*/ +#define NNA_NUMNNC_INDEX 0 /*Item 1 in NNA1 or NNA2 is number of NNCs*/ /* EGRID keywords */ #define LGR_PARENT_KW "LGRPARNT" /* The name of the parent for an LGR. */ @@ -277,7 +296,7 @@ extern "C" { #define ENDGRID_KW "ENDGRID" #define ENDLGR_KW "ENDLGR" #define CORSNUM_KW "CORSNUM" - + /* GRID keywords */ #define GRIDHEAD_KW "GRIDHEAD" /* Header information for GRID files. */ #define COORD_KW "COORD" /* Header information for one cell in GRID file. */ @@ -293,7 +312,7 @@ extern "C" { #define GRIDHEAD_NZ_INDEX 3 #define GRIDHEAD_LGR_INDEX 4 #define GRIDHEAD_SIZE 100 - + /* Observe that these indices are one value lower than the values used in the ecl_smspec file. */ #define DIMENS_NX_INDEX 0 diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_cell.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_cell.h new file mode 100644 index 0000000000..a38b89edea --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_cell.h @@ -0,0 +1,85 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_rft_cell.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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. +*/ + +#ifndef __ECL_RFT_CELL_H__ +#define __ECL_RFT_CELL_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define ECL_RFT_CELL_INVALID_VALUE -1 + +typedef struct ecl_rft_cell_struct ecl_rft_cell_type; + + + + +UTIL_IS_INSTANCE_HEADER( ecl_rft_cell ); + + ecl_rft_cell_type * ecl_rft_cell_alloc_PLT( int i , + int j , + int k , + double depth , + double pressure , + double orat , + double grat , + double wrat , + double connection_start, + double connection_end, + double flowrate, + double oil_flowrate, + double gas_flowrate, + double water_flowrate); + + ecl_rft_cell_type * ecl_rft_cell_alloc_RFT( int i , int j , int k , double depth , double pressure , double swat , double sgas); + void ecl_rft_cell_free( ecl_rft_cell_type * cell ); + void ecl_rft_cell_free__( void * arg); + + bool ecl_rft_cell_ijk_equal( const ecl_rft_cell_type * cell , int i , int j , int k); + void ecl_rft_cell_get_ijk( const ecl_rft_cell_type * cell , int * i , int * j , int * k); + int ecl_rft_cell_get_i( const ecl_rft_cell_type * cell ); + int ecl_rft_cell_get_j( const ecl_rft_cell_type * cell ); + int ecl_rft_cell_get_k( const ecl_rft_cell_type * cell ); + double ecl_rft_cell_get_depth( const ecl_rft_cell_type * cell ); + double ecl_rft_cell_get_pressure( const ecl_rft_cell_type * cell ); + + double ecl_rft_cell_get_swat( const ecl_rft_cell_type * cell ); + double ecl_rft_cell_get_sgas( const ecl_rft_cell_type * cell ); + double ecl_rft_cell_get_soil( const ecl_rft_cell_type * cell ); + + double ecl_rft_cell_get_wrat( const ecl_rft_cell_type * cell ); + double ecl_rft_cell_get_grat( const ecl_rft_cell_type * cell ); + double ecl_rft_cell_get_orat( const ecl_rft_cell_type * cell ); + double ecl_rft_cell_get_connection_start( const ecl_rft_cell_type * cell ); + double ecl_rft_cell_get_connection_end( const ecl_rft_cell_type * cell ); + double ecl_rft_cell_get_flowrate( const ecl_rft_cell_type * cell ); + double ecl_rft_cell_get_oil_flowrate( const ecl_rft_cell_type * cell ); + double ecl_rft_cell_get_gas_flowrate( const ecl_rft_cell_type * cell ); + double ecl_rft_cell_get_water_flowrate( const ecl_rft_cell_type * cell ); + + int ecl_rft_cell_cmp__( const void * arg1 , const void * arg2); + int ecl_rft_cell_cmp( const ecl_rft_cell_type * cell1 , const ecl_rft_cell_type * cell2); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_file.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_file.h index d6ff6ded25..1118fdd011 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_file.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_file.h @@ -39,15 +39,13 @@ void ecl_rft_file_free(ecl_rft_file_type * ); void ecl_rft_file_block(const ecl_rft_file_type * , double , const char * , int , const double * , int * , int * , int *); void ecl_rft_file_fprintf_rft_obs(const ecl_rft_file_type * , double , const char * , const char *, const char * , double); ecl_rft_node_type * ecl_rft_file_get_node(const ecl_rft_file_type * , const char * ); -void ecl_rft_file_summarize(const ecl_rft_file_type * , bool ); -void ecl_rft_file_xml_summary( const ecl_rft_file_type * rft_file ); -const ecl_rft_node_type * ecl_rft_file_get_well_time_rft( const ecl_rft_file_type * rft_file , const char * well , time_t recording_time); int ecl_rft_file_get_size__( const ecl_rft_file_type * rft_file, const char * well_pattern , time_t recording_time); int ecl_rft_file_get_size( const ecl_rft_file_type * rft_file); -const ecl_rft_node_type * ecl_rft_file_iget_node( const ecl_rft_file_type * rft_file , int index); -const ecl_rft_node_type * ecl_rft_file_iget_well_rft( const ecl_rft_file_type * rft_file , const char * well, int index); +ecl_rft_node_type * ecl_rft_file_get_well_time_rft( const ecl_rft_file_type * rft_file , const char * well , time_t recording_time); +ecl_rft_node_type * ecl_rft_file_iget_node( const ecl_rft_file_type * rft_file , int index); +ecl_rft_node_type * ecl_rft_file_iget_well_rft( const ecl_rft_file_type * rft_file , const char * well, int index); bool ecl_rft_file_has_well( const ecl_rft_file_type * rft_file , const char * well); int ecl_rft_file_get_well_occurences( const ecl_rft_file_type * rft_file , const char * well); stringlist_type * ecl_rft_file_alloc_well_list(const ecl_rft_file_type * rft_file ); diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_node.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_node.h index f6fd0d7b7c..1a4f9fed27 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_node.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rft_node.h @@ -24,6 +24,7 @@ extern "C" { #include #include +#include typedef enum { RFT = 1 , PLT = 2 , @@ -31,28 +32,34 @@ typedef enum { RFT = 1 , typedef struct ecl_rft_node_struct ecl_rft_node_type; -int ecl_rft_node_lookup_ijk( const ecl_rft_node_type * rft_node , int i, int j , int k); +void ecl_rft_node_inplace_sort_cells( ecl_rft_node_type * rft_node ); +const ecl_rft_cell_type * ecl_rft_node_iget_cell_sorted( ecl_rft_node_type * rft_node , int index); +const ecl_rft_cell_type * ecl_rft_node_iget_cell( const ecl_rft_node_type * rft_node , int index); +const ecl_rft_cell_type * ecl_rft_node_lookup_ijk( const ecl_rft_node_type * rft_node , int i, int j , int k); void ecl_rft_node_fprintf_rft_obs(const ecl_rft_node_type * , double , const char * , const char * , double ); ecl_rft_node_type * ecl_rft_node_alloc(const ecl_file_type * file_map ); const char * ecl_rft_node_get_well_name(const ecl_rft_node_type * ); void ecl_rft_node_free(ecl_rft_node_type * ); void ecl_rft_node_free__(void * ); -void ecl_rft_node_block2(const ecl_rft_node_type * , int , const double * , const double * , int * , int * , int *); -void ecl_rft_node_block(const ecl_rft_node_type * , double , int , const double * , int * , int * , int *); time_t ecl_rft_node_get_date(const ecl_rft_node_type * ); int ecl_rft_node_get_size(const ecl_rft_node_type * ); -void ecl_rft_node_summarize(const ecl_rft_node_type * , bool ); const char * ecl_rft_node_get_well_name( const ecl_rft_node_type * rft_node ); void ecl_rft_node_iget_ijk( const ecl_rft_node_type * rft_node , int index , int *i , int *j , int *k); -void ecl_rft_node_export_DEPTH(const ecl_rft_node_type * , const char * ); +bool ecl_rft_node_is_RFT( const ecl_rft_node_type * rft_node ); +bool ecl_rft_node_is_PLT( const ecl_rft_node_type * rft_node ); +bool ecl_rft_node_is_SEGMENT( const ecl_rft_node_type * rft_node ); +bool ecl_rft_node_is_MSW( const ecl_rft_node_type * rft_node ); + double ecl_rft_node_iget_pressure( const ecl_rft_node_type * rft_node , int index); double ecl_rft_node_iget_depth( const ecl_rft_node_type * rft_node , int index); double ecl_rft_node_iget_wrat( const ecl_rft_node_type * rft_node , int index); double ecl_rft_node_iget_grat( const ecl_rft_node_type * rft_node , int index); double ecl_rft_node_iget_orat( const ecl_rft_node_type * rft_node , int index); + double ecl_rft_node_iget_swat( const ecl_rft_node_type * rft_node , int index); double ecl_rft_node_iget_sgas( const ecl_rft_node_type * rft_node , int index); +double ecl_rft_node_iget_soil( const ecl_rft_node_type * rft_node , int index); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rsthead.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rsthead.h index a128e2adf1..4068ed4528 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rsthead.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_rsthead.h @@ -63,6 +63,7 @@ extern "C" { int nswlmx; // The maximum number of segmented wells int nlbrmx; // The maximum number of lateral branches pr well int nilbrz; // The number of entries pr segment in ILBR array + int nrsegz; // The number of entries pr segment in RSEG array // Properteies from the LOGIHEAD keyword: bool dualp; diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_smspec.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_smspec.h index c37575eea1..bf32c70799 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_smspec.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_smspec.h @@ -87,7 +87,7 @@ typedef struct ecl_smspec_struct ecl_smspec_type; const smspec_node_type * ecl_smspec_get_block_var_node(const ecl_smspec_type * ecl_smspec , const char * block_var , int block_nr); int ecl_smspec_get_block_var_params_index(const ecl_smspec_type * ecl_smspec , const char * block_var , int block_nr); bool ecl_smspec_has_block_var(const ecl_smspec_type * ecl_smspec , const char * block_var , int block_nr); - + const smspec_node_type * ecl_smspec_get_block_var_node_ijk(const ecl_smspec_type * ecl_smspec , const char * block_var , int i , int j , int k); int ecl_smspec_get_block_var_params_index_ijk(const ecl_smspec_type * ecl_smspec , const char * block_var , int i , int j , int k); bool ecl_smspec_has_block_var_ijk(const ecl_smspec_type * ecl_smspec , const char * block_var , int i , int j , int k); diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum.h index c62fc61f42..a5f51aafef 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum.h @@ -200,7 +200,11 @@ typedef struct ecl_sum_struct ecl_sum_type; ecl_sum_tstep_type * ecl_sum_add_tstep( ecl_sum_type * ecl_sum , int report_step , double sim_days); void ecl_sum_update_wgname( ecl_sum_type * ecl_sum , smspec_node_type * node , const char * wgname ); + bool ecl_sum_is_oil_producer( const ecl_sum_type * ecl_sum , const char * well); char * ecl_sum_alloc_well_key( const ecl_sum_type * ecl_sum , const char * keyword , const char * wgname); + bool ecl_sum_report_step_equal( const ecl_sum_type * ecl_sum1 , const ecl_sum_type * ecl_sum2); + bool ecl_sum_report_step_compatible( const ecl_sum_type * ecl_sum1 , const ecl_sum_type * ecl_sum2); + UTIL_IS_INSTANCE_HEADER( ecl_sum ); #ifdef __cplusplus diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_data.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_data.h index 496eecb00b..047800dc1c 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_data.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_data.h @@ -83,6 +83,8 @@ typedef struct ecl_sum_data_struct ecl_sum_data_type ; int ecl_sum_data_iget_report_end( const ecl_sum_data_type * data , int report_step ); int ecl_sum_data_iget_report_start( const ecl_sum_data_type * data , int report_step ); ecl_sum_tstep_type * ecl_sum_data_add_new_tstep( ecl_sum_data_type * data , int report_step , double sim_days); + bool ecl_sum_data_report_step_equal( const ecl_sum_data_type * data1 , const ecl_sum_data_type * data2); + bool ecl_sum_data_report_step_compatible( const ecl_sum_data_type * data1 , const ecl_sum_data_type * data2); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_tstep.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_tstep.h index ba37173cd8..94dc7e32e4 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_tstep.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/ecl_sum_tstep.h @@ -51,6 +51,7 @@ typedef struct ecl_sum_tstep_struct ecl_sum_tstep_type; void ecl_sum_tstep_iset( ecl_sum_tstep_type * tstep , int index , float value); void ecl_sum_tstep_set_from_node( ecl_sum_tstep_type * tstep , const smspec_node_type * smspec_node , float value); void ecl_sum_tstep_set_from_key( ecl_sum_tstep_type * tstep , const char * gen_key , float value); + bool ecl_sum_tstep_sim_time_equal( const ecl_sum_tstep_type * tstep1 , const ecl_sum_tstep_type * tstep2 ); UTIL_SAFE_CAST_HEADER( ecl_sum_tstep ); UTIL_SAFE_CAST_HEADER_CONST( ecl_sum_tstep ); diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/fortio.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/fortio.h index 87fdcfaa3d..99e0b68b7f 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/fortio.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/fortio.h @@ -26,6 +26,8 @@ extern "C" { #include #include +#include + typedef enum { FORTIO_NOENTRY = 0, /* File does not exists at all - application error. */ FORTIO_EOF = 1, /* The file / record is empty */ @@ -66,8 +68,8 @@ typedef struct fortio_struct fortio_type; void fortio_rewind(const fortio_type *fortio); const char * fortio_filename_ref(const fortio_type * ); bool fortio_fmt_file(const fortio_type *); - long fortio_ftell( const fortio_type * fortio ); - int fortio_fseek( fortio_type * fortio , long offset , int whence); + offset_type fortio_ftell( const fortio_type * fortio ); + int fortio_fseek( fortio_type * fortio , offset_type offset , int whence); int fortio_fileno( fortio_type * fortio ); bool fortio_fclose_stream( fortio_type * fortio ); diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_index_list.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_index_list.h new file mode 100644 index 0000000000..f18860f893 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_index_list.h @@ -0,0 +1,42 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'nnc_index_list.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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. +*/ + + +#ifndef __NNC_INDEX_LIST_H__ +#define __NNC_INDEX_LIST_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + + typedef struct nnc_index_list_struct nnc_index_list_type; + + UTIL_IS_INSTANCE_HEADER(nnc_index_list); + + nnc_index_list_type * nnc_index_list_alloc(); + void nnc_index_list_free( nnc_index_list_type * index_list ); + void nnc_index_list_add_index(nnc_index_list_type * index_list , int index); + const int_vector_type * nnc_index_list_get_list(nnc_index_list_type * index_list); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_info.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_info.h new file mode 100644 index 0000000000..a27057b4e7 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_info.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'nnc_info.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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. +*/ + + +#ifndef __NNC_INFO_H__ +#define __NNC_INFO_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include + + typedef struct nnc_info_struct nnc_info_type; + + UTIL_IS_INSTANCE_HEADER(nnc_info); + + nnc_info_type * nnc_info_alloc(int lgr_nr); + void nnc_info_free( nnc_info_type * nnc_info ); + void nnc_info_add_nnc(nnc_info_type * nnc_info, int lgr_nr, int global_cell_number); + + const int_vector_type * nnc_info_iget_index_list(const nnc_info_type * nnc_info, int lgr_index); + nnc_vector_type * nnc_info_iget_vector( const nnc_info_type * nnc_info , int lgr_index); + + const int_vector_type * nnc_info_get_index_list(const nnc_info_type * nnc_info, int lgr_nr); + nnc_vector_type * nnc_info_get_vector( const nnc_info_type * nnc_info , int lgr_nr); + + const int_vector_type * nnc_info_get_self_index_list(const nnc_info_type * nnc_info); + nnc_vector_type * nnc_info_get_self_vector( const nnc_info_type * nnc_info ); + + int nnc_info_get_lgr_nr(const nnc_info_type * nnc_info ); + int nnc_info_get_size( const nnc_info_type * nnc_info ); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_vector.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_vector.h new file mode 100644 index 0000000000..bd4ac59de1 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/nnc_vector.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'nnc_vector.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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. +*/ + + +#ifndef __NNC_VECTOR_H__ +#define __NNC_VECTOR_H__ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + + typedef struct nnc_vector_struct nnc_vector_type; + + UTIL_IS_INSTANCE_HEADER(nnc_vector); + + nnc_vector_type * nnc_vector_alloc(int lgr_nr); + void nnc_vector_free( nnc_vector_type * nnc_vector ); + void nnc_vector_add_nnc(nnc_vector_type * nnc_vector, int global_cell_number); + const int_vector_type * nnc_vector_get_index_list(const nnc_vector_type * nnc_vector); + int nnc_vector_get_lgr_nr(const nnc_vector_type * nnc_vector ); + void nnc_vector_free__(void * arg); + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/ThirdParty/Ert/devel/libecl/include/ert/ecl/smspec_node.h b/ThirdParty/Ert/devel/libecl/include/ert/ecl/smspec_node.h index 725376e9ca..27e44f8416 100644 --- a/ThirdParty/Ert/devel/libecl/include/ert/ecl/smspec_node.h +++ b/ThirdParty/Ert/devel/libecl/include/ert/ecl/smspec_node.h @@ -61,6 +61,8 @@ typedef enum {ECL_SMSPEC_INVALID_VAR = 0 , char * smspec_alloc_group_key( const char * join_string , const char * keyword , const char * wgname); char * smspec_alloc_well_key( const char * join_string , const char * keyword , const char * wgname); char * smspec_alloc_region_key( const char * join_string , const char * keyword , int num); + char * smspec_alloc_region_2_region_r1r2_key( const char * join_string , const char * keyword , int r1, int r2); + char * smspec_alloc_region_2_region_num_key( const char * join_string , const char * keyword , int num); char * smspec_alloc_segment_key( const char * join_string , const char * keyword , const char * wgname , int num); char * smspec_alloc_block_num_key( const char * join_string , const char * keyword , int num); char * smspec_alloc_local_well_key( const char * join_string , const char * keyword , const char * lgr_name , const char * wgname); diff --git a/ThirdParty/Ert/devel/libecl/src/CMakeLists.txt b/ThirdParty/Ert/devel/libecl/src/CMakeLists.txt index 1ddeaf0066..67195441ec 100644 --- a/ThirdParty/Ert/devel/libecl/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl/src/CMakeLists.txt @@ -2,14 +2,17 @@ include_directories( ext ) file(GLOB ext_source "ext/*.c" ) file(GLOB ext_header "ext/*.h" ) -set( source_files ecl_rsthead.c ecl_sum_tstep.c ecl_rst_file.c ecl_init_file.c ecl_grid_cache.c smspec_node.c ecl_kw_grdecl.c ecl_file_kw.c ecl_grav.c ecl_grav_calc.c ecl_smspec.c ecl_sum_data.c ecl_util.c ecl_kw.c ecl_sum.c fortio.c ecl_rft_file.c ecl_rft_node.c ecl_grid.c ecl_coarse_cell.c ecl_box.c ecl_io_config.c ecl_file.c ecl_region.c point.c tetrahedron.c ecl_subsidence.c ecl_grid_dims.c grid_dims.c ecl_grav_common.c ${ext_source}) +set( source_files ecl_rsthead.c ecl_sum_tstep.c ecl_rst_file.c ecl_init_file.c ecl_grid_cache.c smspec_node.c ecl_kw_grdecl.c ecl_file_kw.c ecl_grav.c ecl_grav_calc.c ecl_smspec.c ecl_sum_data.c ecl_util.c ecl_kw.c ecl_sum.c fortio.c ecl_rft_file.c ecl_rft_node.c ecl_rft_cell.c ecl_grid.c ecl_coarse_cell.c ecl_box.c ecl_io_config.c ecl_file.c ecl_region.c point.c tetrahedron.c ecl_subsidence.c ecl_grid_dims.c grid_dims.c nnc_info.c ecl_grav_common.c nnc_vector.c nnc_index_list.c ${ext_source}) -set( header_files ecl_rsthead.h ecl_sum_tstep.h ecl_rst_file.h ecl_init_file.h smspec_node.h ecl_grid_cache.h ecl_kw_grdecl.h ecl_file_kw.h ecl_grav.h ecl_grav_calc.h ecl_endian_flip.h ecl_smspec.h ecl_sum_data.h ecl_util.h ecl_kw.h ecl_sum.h fortio.h ecl_rft_file.h ecl_rft_node.h ecl_box.h ecl_coarse_cell.h ecl_grid.h ecl_io_config.h ecl_file.h ecl_region.h ecl_kw_magic.h ecl_subsidence.h ecl_grid_dims.h grid_dims.h ${ext_header} ecl_grav_common.h) +set( header_files ecl_rsthead.h ecl_sum_tstep.h ecl_rst_file.h ecl_init_file.h smspec_node.h ecl_grid_cache.h ecl_kw_grdecl.h ecl_file_kw.h ecl_grav.h ecl_grav_calc.h ecl_endian_flip.h ecl_smspec.h ecl_sum_data.h ecl_util.h ecl_kw.h ecl_sum.h fortio.h ecl_rft_file.h ecl_rft_node.h ecl_rft_cell.h ecl_box.h ecl_coarse_cell.h ecl_grid.h ecl_io_config.h ecl_file.h ecl_region.h ecl_kw_magic.h ecl_subsidence.h ecl_grid_dims.h grid_dims.h nnc_info.h nnc_vector.h ${ext_header} ecl_grav_common.h nnc_index_list.h) add_library( ecl ${LIBRARY_TYPE} ${source_files} ) set_target_properties( ecl PROPERTIES VERSION 1.0 SOVERSION 1.0 ) +if (USE_RUNPATH) + add_runpath( ecl ) +endif() #----------------------------------------------------------------- set( OPENMP OFF ) diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_file.c b/ThirdParty/Ert/devel/libecl/src/ecl_file.c index c2baf8d43b..9c60277efc 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_file.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_file.c @@ -823,7 +823,7 @@ static void ecl_file_scan( ecl_file_type * ecl_file ) { fortio_fseek( ecl_file->fortio , 0 , SEEK_SET ); { ecl_kw_type * work_kw = ecl_kw_alloc_new("WORK-KW" , 0 , ECL_INT_TYPE , NULL); - long current_offset; + offset_type current_offset; while (true) { current_offset = fortio_ftell( ecl_file->fortio ); if (ecl_kw_fread_header( work_kw , ecl_file->fortio )) { diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_file_kw.c b/ThirdParty/Ert/devel/libecl/src/ecl_file_kw.c index ad2dbd382f..3ca6f42f48 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_file_kw.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_file_kw.c @@ -56,7 +56,7 @@ struct inv_map_struct { struct ecl_file_kw_struct { UTIL_TYPE_ID_DECLARATION; - long file_offset; + offset_type file_offset; ecl_type_enum ecl_type; int kw_size; char * header; @@ -135,7 +135,7 @@ UTIL_IS_INSTANCE_FUNCTION( ecl_file_kw , ECL_FILE_KW_TYPE_ID ) -static ecl_file_kw_type * ecl_file_kw_alloc__( const char * header , ecl_type_enum ecl_type , int size , long offset) { +static ecl_file_kw_type * ecl_file_kw_alloc__( const char * header , ecl_type_enum ecl_type , int size , offset_type offset) { ecl_file_kw_type * file_kw = util_malloc( sizeof * file_kw ); UTIL_TYPE_ID_INIT( file_kw , ECL_FILE_KW_TYPE_ID ); @@ -160,7 +160,7 @@ static ecl_file_kw_type * ecl_file_kw_alloc__( const char * header , ecl_type_en access the ecl_file_kw instances. */ -ecl_file_kw_type * ecl_file_kw_alloc( const ecl_kw_type * ecl_kw , long offset ) { +ecl_file_kw_type * ecl_file_kw_alloc( const ecl_kw_type * ecl_kw , offset_type offset ) { return ecl_file_kw_alloc__( ecl_kw_get_header( ecl_kw ) , ecl_kw_get_type( ecl_kw ) , ecl_kw_get_size( ecl_kw ) , offset ); } diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_grid.c b/ThirdParty/Ert/devel/libecl/src/ecl_grid.c index f8bc1846d4..b9613ea387 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_grid.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_grid.c @@ -39,7 +39,8 @@ #include #include #include - +#include +#include /* If openmp is enabled the main loop in ecl_grid_init_GRDECL_data is @@ -358,6 +359,73 @@ */ +/* + About nnc + --------- + + When loading a grid file the various NNC related keywords are read + in to assemble information of the NNC. The NNC information is + organized as follows: + + 1. The field nnc_index_list is a thin wrapper around a int_vector + instance which will return a sorted list of indicies of cells + which have attached NNC information. + + 2. For cells with NNC's attached the information is kept in a + nnc_info_type structure. For a particular cell the nnc_info + structure keeps track of which other cells this particular cell + is connected to, on a per grid (i.e. LGR) basis. + + In the nnc_info structure the different grids are identified + through the lgr_nr. + + + + Example usage: + -------------- + + ecl_grid_type * grid = ecl_grid_alloc("FILE.EGRID"); + + // Get a int_vector instance with all the cells which have nnc info + // attached. + const int_vector_type * cells_with_nnc = ecl_grid_get_nnc_index_list( grid ); + + // Iterate over all the cells with nnc info: + for (int i=0; i < int_vector_size( cells_with_nnc ); i++) { + int cell_index = int_vector_iget( cells_with_nnc , i); + const nnc_info_type * nnc_info = ecl_grid_get_nnc_info1( grid , cell_index); + + // Get all the nnc connections from @cell_index to other cells in the same grid + { + const int_vector_type * nnc_list = nnc_info_get_self_index_list( nnc_info ); + for (int j=0; j < int_vector_size( nnc_list ); j++) + printf("Cell[%d] -> %d in the same grid \n",cell_index , int_vector_iget(nnc_list , j)); + } + + + { + for (int lgr_index=0; lgr_index < nnc_info_get_size( nnc_info ); lgr_index++) { + nnc_vector_type * nnc_vector = nnc_info_iget_vector( nnc_info , lgr_index ); + int lgr_nr = nnc_vector_get_lgr_nr( nnc_vector ); + if (lgr_nr != nnc_info_get_lgr_nr( nnc_info )) { + const int_vector_type * nnc_list = nnc_vector_get_index_list( nnc_vector ); + for (int j=0; j < int_vector_size( nnc_list ); j++) + printf("Cell[%d] -> %d in lgr:%d/%s \n",cell_index , int_vector_iget(nnc_list , j) , lgr_nr , ecl_grid_get_lgr_name(ecl_grid , lgr_nr)); + } + } + } + } + + + Dual porosity and nnc: In ECLIPSE the connection between the matrix + properties and the fracture properties in a cell is implemented as a + nnc where the fracture cell has global index in the range [nx*ny*nz, + 2*nz*ny*nz). In ert we we have not implemented this double covering + in the case of dual porosity models, and therefor NNC involving + fracture cells are not considered. +*/ + + /* about tetraheder decomposition @@ -467,6 +535,7 @@ struct ecl_cell_struct { int host_cell; /* the global index of the host cell for an lgr cell, set to -1 for normal cells. */ int coarse_group; /* The index of the coarse group holding this cell -1 for non-coarsened cells. */ int cell_flags; + nnc_info_type * nnc_info; /* Non-neighbour connection info*/ }; @@ -476,7 +545,8 @@ struct ecl_cell_struct { struct ecl_grid_struct { UTIL_TYPE_ID_DECLARATION; - int grid_nr; /* this corresponds to item 4 in gridhead - 0 for the main grid. */ + int lgr_nr; /* EGRID files: corresponds to item 4 in gridhead - 0 for the main grid. + GRID files: 0 for the main grid, then 1 -> number of LGRs in order read from file*/ char * name; /* the name of the file for the main grid - name of the lgr for lgrs. */ int ny,nz,nx; int size; /* == nx*ny*nz */ @@ -488,6 +558,7 @@ struct ecl_grid_struct { int * fracture_index_map; /* For fractures: this a list of nx*ny*nz elements, where value -1 means inactive cell .*/ int * inv_fracture_index_map; /* For fractures: this is list of total_active elements - which point back to the index_map. */ + nnc_index_list_type * nnc_index_list; #ifdef LARGE_CELL_MALLOC ecl_cell_type * cells; @@ -506,19 +577,20 @@ struct ecl_grid_struct { /* the two fields below are for *storing* lgr grid instances. observe that these fields will be NULL for lgr grids, i.e. grids with - grid_nr > 0. + lgr_nr > 0. */ - vector_type * LGR_list; /* a vector of ecl_grid instances for lgr's - the index corresponds to the grid_nr. */ + vector_type * LGR_list; /* a vector of ecl_grid instances for LGRs - the index corresponds to the order LGRs are read from file*/ + int_vector_type * lgr_index_map; /* a vector that maps LGR-nr for EGRID files to index into the LGR_list.*/ hash_type * LGR_hash; /* a hash of pointers to ecl_grid instances - for name based lookup of lgr. */ int parent_box[6]; /* integers i1,i2, j1,j2, k1,k2 of the parent grid region containing this lgr. the indices are inclusive - zero offset */ /* not used yet .. */ - int dualp_flag; - bool use_mapaxes; - double unit_x[2]; - double unit_y[2]; - double origo[2]; - float mapaxes[6]; + int dualp_flag; + bool use_mapaxes; + double unit_x[2]; + double unit_y[2]; + double origo[2]; + float mapaxes[6]; /*------------------------------: the fields below this line are used for blocking algorithms - and not allocated by default.*/ int block_dim; /* == 2 for maps and 3 for fields. 0 when not in use. */ int block_size; @@ -826,6 +898,8 @@ static void ecl_cell_init( ecl_cell_type * cell , bool init_valid) { if (init_valid) cell->cell_flags = CELL_FLAG_VALID; + + cell->nnc_info = NULL; } @@ -1089,6 +1163,7 @@ static void ecl_cell_init_regular( ecl_cell_type * cell , const double * offset /* starting on the ecl_grid proper implementation */ UTIL_SAFE_CAST_FUNCTION(ecl_grid , ECL_GRID_ID); +UTIL_IS_INSTANCE_FUNCTION( ecl_grid , ECL_GRID_ID); /** this function allocates the internal index_map and inv_index_map fields. @@ -1121,6 +1196,14 @@ static void ecl_grid_taint_cells( ecl_grid_type * ecl_grid ) { static void ecl_grid_free_cells( ecl_grid_type * grid ) { + + int i; + for (i=0; i < grid->size; i++) { + ecl_cell_type * cell = ecl_grid_get_cell( grid , i ); + if (cell->nnc_info) + nnc_info_free(cell->nnc_info); + } + #ifndef LARGE_CELL_MALLOC int i; for (i=0; i < grid->size; i++) { @@ -1161,7 +1244,7 @@ static void ecl_grid_alloc_cells( ecl_grid_type * grid , bool init_valid) { is performed. */ -static ecl_grid_type * ecl_grid_alloc_empty(ecl_grid_type * global_grid , int dualp_flag , int nx , int ny , int nz, int grid_nr , bool init_valid) { +static ecl_grid_type * ecl_grid_alloc_empty(ecl_grid_type * global_grid , int dualp_flag , int nx , int ny , int nz, int lgr_nr, bool init_valid) { ecl_grid_type * grid = util_malloc(sizeof * grid ); UTIL_TYPE_ID_INIT(grid , ECL_GRID_ID); grid->total_active = 0; @@ -1170,7 +1253,7 @@ static ecl_grid_type * ecl_grid_alloc_empty(ecl_grid_type * global_grid , int du grid->ny = ny; grid->nz = nz; grid->size = nx*ny*nz; - grid->grid_nr = grid_nr; + grid->lgr_nr = lgr_nr; grid->global_grid = global_grid; grid->coarsening_active = false; @@ -1181,8 +1264,9 @@ static ecl_grid_type * ecl_grid_alloc_empty(ecl_grid_type * global_grid , int du grid->index_map = NULL; grid->fracture_index_map = NULL; grid->inv_fracture_index_map = NULL; + grid->nnc_index_list = nnc_index_list_alloc( ); ecl_grid_alloc_cells( grid , init_valid ); - + if (global_grid != NULL) { /* this is an lgr instance, and we inherit the global grid @@ -1205,21 +1289,22 @@ static ecl_grid_type * ecl_grid_alloc_empty(ecl_grid_type * global_grid , int du } - grid->block_dim = 0; - grid->values = NULL; - if (grid_nr == 0) { /* this is the main grid */ - grid->LGR_list = vector_alloc_new(); - vector_append_ref( grid->LGR_list , grid ); /* adding a 'self' pointer as first inistance - without destructor! */ - grid->LGR_hash = hash_alloc(); + grid->block_dim = 0; + grid->values = NULL; + if (ECL_GRID_MAINGRID_LGR_NR == lgr_nr) { /* this is the main grid */ + grid->LGR_list = vector_alloc_new(); + grid->lgr_index_map = int_vector_alloc(0,0); + grid->LGR_hash = hash_alloc(); } else { - grid->LGR_list = NULL; - grid->LGR_hash = NULL; + grid->LGR_list = NULL; + grid->lgr_index_map = NULL; + grid->LGR_hash = NULL; } - grid->name = NULL; - grid->parent_name = NULL; - grid->parent_grid = NULL; - grid->children = hash_alloc(); - grid->coarse_cells = vector_alloc_new(); + grid->name = NULL; + grid->parent_name = NULL; + grid->parent_grid = NULL; + grid->children = hash_alloc(); + grid->coarse_cells = vector_alloc_new(); return grid; } @@ -1321,12 +1406,12 @@ static void ecl_grid_set_cell_GRID(ecl_grid_type * ecl_grid , int coords_size , /* - The grid_nr > 0 test essentially checks if this is a LGR; if - this test applies we either have bug - or a GRID file with LGRs - and only 4/5 elements in the coords keywords. In the latter - case we must start using the LGRILG keyword. + The ECL_GRID_MAINGRID_LGR_NR != ecl_grid->lgr_nr test checks if + this is a LGR; if this test applies we either have bug - or a + GRID file with LGRs and only 4/5 elements in the coords keywords. + In the latter case we must start using the LGRILG keyword. */ - if ((ecl_grid->grid_nr > 0) && (coords_size != 7)) + if ((ECL_GRID_MAINGRID_LGR_NR != ecl_grid->lgr_nr) && (coords_size != 7)) util_abort("%s: Need 7 element coords keywords for LGR - or reimplement to use LGRILG keyword.\n",__func__); switch(coords_size) { @@ -1698,13 +1783,9 @@ static void ecl_grid_init_mapaxes( ecl_grid_type * ecl_grid , const float * mapa static void ecl_grid_add_lgr( ecl_grid_type * main_grid , ecl_grid_type * lgr_grid) { - int next_grid_nr = vector_get_size( main_grid->LGR_list ); - if (next_grid_nr != lgr_grid->grid_nr) - util_abort("%s: index based insertion of lgr grid failed. next_grid_nr:%d lgr->grid_nr:%d \n",__func__ , next_grid_nr , lgr_grid->grid_nr); - { - vector_append_owned_ref( main_grid->LGR_list , lgr_grid , ecl_grid_free__); - hash_insert_ref( main_grid->LGR_hash , lgr_grid->name , lgr_grid); - } + vector_append_owned_ref( main_grid->LGR_list , lgr_grid , ecl_grid_free__); + int_vector_iset(main_grid->lgr_index_map, lgr_grid->lgr_nr, vector_get_size(main_grid->LGR_list)-1); + hash_insert_ref( main_grid->LGR_hash , lgr_grid->name , lgr_grid); } @@ -1763,7 +1844,7 @@ static void ecl_grid_set_lgr_name_EGRID(ecl_grid_type * lgr_grid , const ecl_fil ecl_kw_type * lgrname_kw = ecl_file_iget_named_kw( ecl_file , LGR_KW , grid_nr - 1); lgr_grid->name = util_alloc_strip_copy( ecl_kw_iget_ptr( lgrname_kw , 0) ); /* trailing zeros are stripped away. */ if (ecl_file_has_kw( ecl_file , LGR_PARENT_KW)) { - ecl_kw_type * parent_kw = ecl_file_iget_named_kw( ecl_file , LGR_PARENT_KW , grid_nr - 1); + ecl_kw_type * parent_kw = ecl_file_iget_named_kw( ecl_file , LGR_PARENT_KW , grid_nr -1); char * parent = util_alloc_strip_copy( ecl_kw_iget_ptr( parent_kw , 0)); if (strlen( parent ) > 0) @@ -1794,7 +1875,7 @@ static void ecl_grid_set_lgr_name_GRID(ecl_grid_type * lgr_grid , const ecl_file if ((strlen(parent) == 0) || (strcmp(parent , GLOBAL_STRING ) == 0)) free( parent ); - else + else lgr_grid->parent_name = parent; } } @@ -1892,9 +1973,9 @@ void ecl_grid_init_GRDECL_data(ecl_grid_type * ecl_grid , const float * zcorn , static ecl_grid_type * ecl_grid_alloc_GRDECL_data__(ecl_grid_type * global_grid , int dualp_flag , int nx , int ny , int nz , const float * zcorn , const float * coord , const int * actnum, const float * mapaxes, const int * corsnum, - int grid_nr) { + int lgr_nr) { - ecl_grid_type * ecl_grid = ecl_grid_alloc_empty(global_grid , dualp_flag , nx,ny,nz,grid_nr,true); + ecl_grid_type * ecl_grid = ecl_grid_alloc_empty(global_grid , dualp_flag , nx,ny,nz,lgr_nr,true); if (mapaxes != NULL) ecl_grid_init_mapaxes( ecl_grid , mapaxes ); @@ -1929,15 +2010,14 @@ static ecl_grid_type * ecl_grid_alloc_GRDECL_kw__(ecl_grid_type * global_grid , const ecl_kw_type * coord_kw , const ecl_kw_type * actnum_kw , /* Can be NULL */ const ecl_kw_type * mapaxes_kw , /* Can be NULL */ - const ecl_kw_type * corsnum_kw , /* Can be NULL */ - int grid_nr) { - - int gtype, nx,ny,nz; + const ecl_kw_type * corsnum_kw) { /* Can be NULL */ + int gtype, nx,ny,nz, lgr_nr; gtype = ecl_kw_iget_int(gridhead_kw , GRIDHEAD_TYPE_INDEX); nx = ecl_kw_iget_int(gridhead_kw , GRIDHEAD_NX_INDEX); ny = ecl_kw_iget_int(gridhead_kw , GRIDHEAD_NY_INDEX); nz = ecl_kw_iget_int(gridhead_kw , GRIDHEAD_NZ_INDEX); + lgr_nr = ecl_kw_iget_int(gridhead_kw , GRIDHEAD_LGR_INDEX); /* The code used to have this test: @@ -1950,7 +2030,7 @@ static ecl_grid_type * ecl_grid_alloc_GRDECL_kw__(ecl_grid_type * global_grid , if (gtype != GRIDHEAD_GRIDTYPE_CORNERPOINT) util_abort("%s: gtype:%d fatal error when loading grid - must have corner point grid - aborting\n",__func__ , gtype ); - + { const float * mapaxes_data = NULL; const int * actnum_data = NULL; @@ -1973,7 +2053,7 @@ static ecl_grid_type * ecl_grid_alloc_GRDECL_kw__(ecl_grid_type * global_grid , actnum_data, mapaxes_data, corsnum_data, - grid_nr); + lgr_nr); } } @@ -1982,7 +2062,7 @@ static ecl_grid_type * ecl_grid_alloc_GRDECL_kw__(ecl_grid_type * global_grid , If you create/load ecl_kw instances for the various fields, this function can be used to create a GRID instance, without going through a GRID/EGRID file. Does not support LGR or coarsening - hierarchies. + hierarchies. */ ecl_grid_type * ecl_grid_alloc_GRDECL_kw( int nx, int ny , int nz , @@ -1990,10 +2070,10 @@ ecl_grid_type * ecl_grid_alloc_GRDECL_kw( int nx, int ny , int nz , const ecl_kw_type * coord_kw , const ecl_kw_type * actnum_kw , /* Can be NULL */ const ecl_kw_type * mapaxes_kw ) { /* Can be NULL */ - + ecl_kw_type * gridhead_kw = ecl_grid_alloc_gridhead_kw( nx , ny , nz , 0); - ecl_grid_type * ecl_grid = ecl_grid_alloc_GRDECL_kw__(NULL , FILEHEAD_SINGLE_POROSITY , gridhead_kw , zcorn_kw , coord_kw , actnum_kw , mapaxes_kw , NULL , 0); + ecl_grid_type * ecl_grid = ecl_grid_alloc_GRDECL_kw__(NULL , FILEHEAD_SINGLE_POROSITY , gridhead_kw , zcorn_kw , coord_kw , actnum_kw , mapaxes_kw , NULL); ecl_kw_free( gridhead_kw ); return ecl_grid; @@ -2001,6 +2081,126 @@ ecl_grid_type * ecl_grid_alloc_GRDECL_kw( int nx, int ny , int nz , + + + +static void ecl_grid_init_cell_nnc_info(ecl_grid_type * ecl_grid, int global_index) { + ecl_cell_type * grid_cell = ecl_grid_get_cell(ecl_grid, global_index); + + if (!grid_cell->nnc_info) + grid_cell->nnc_info = nnc_info_alloc(ecl_grid->lgr_nr); +} + + +/* + This function populates nnc_info for cells with non neighbour connections + */ +static void ecl_grid_init_nnc_cells( ecl_grid_type * grid1, ecl_grid_type * grid2, const ecl_kw_type * keyword1, const ecl_kw_type * keyword2) { + + int * grid1_nnc_cells = ecl_kw_get_int_ptr(keyword1); + int * grid2_nnc_cells = ecl_kw_get_int_ptr(keyword2); + int nnc_count = ecl_kw_get_size(keyword2); + + int i; + for (i = 0; i < nnc_count; i++) { + int grid1_cell_index = grid1_nnc_cells[i] -1; + int grid2_cell_index = grid2_nnc_cells[i] -1; + + + /* + In the ECLIPSE output format grids with dual porosity are (to some + extent ...) modeled as two independent grids stacked on top of + eachother, where the fracture cells have global index in the range + [nx*ny*nz, 2*nx*ny*nz). + + The physical connection between the matrix and the fractures in + cell nr c is modelled as an nnc: cell[c] -> cell[c + nx*ny*nz]. In + the ert ecl library we only have cells in the range [0,nx*ny*nz), + and fracture is a property of a cell, we therefor do not include + nnc connections involving fracture cells (i.e. cell_index >= + nx*ny*nz). + */ + if ((FILEHEAD_SINGLE_POROSITY != grid1->dualp_flag) && + ((grid1_cell_index >= grid1->size) || + (grid2_cell_index >= grid2->size))) + break; + + + ecl_grid_init_cell_nnc_info(grid1, grid1_cell_index); + ecl_grid_init_cell_nnc_info(grid2, grid2_cell_index); + + { + ecl_cell_type * grid1_cell = ecl_grid_get_cell(grid1, grid1_cell_index); + ecl_cell_type * grid2_cell = ecl_grid_get_cell(grid2, grid2_cell_index); + + //Add the non-neighbour connection in both directions + nnc_info_add_nnc(grid1_cell->nnc_info, grid2->lgr_nr, grid2_cell_index); + nnc_info_add_nnc(grid2_cell->nnc_info, grid1->lgr_nr, grid1_cell_index); + + nnc_index_list_add_index( grid1->nnc_index_list , grid1_cell_index ); + nnc_index_list_add_index( grid2->nnc_index_list , grid2_cell_index ); + } + } +} + + +/* + This function reads the non-neighbour connection data from file and initializes the grid structure with the the nnc data +*/ +static void ecl_grid_init_nnc(ecl_grid_type * main_grid, ecl_file_type * ecl_file) { + int num_nnchead_kw = ecl_file_get_num_named_kw( ecl_file , NNCHEAD_KW ); + int num_nncg_kw = ecl_file_get_num_named_kw( ecl_file , NNCG_KW ); + + int i; + for (i = 0; i < num_nnchead_kw; i++) { + ecl_kw_type * nnchead_kw = ecl_file_iget_named_kw( ecl_file , NNCHEAD_KW , i); + int lgr_nr = ecl_kw_iget_int(nnchead_kw, NNCHEAD_LGR_INDEX); + ecl_kw_type * keyword1 = NULL; + ecl_kw_type * keyword2 = NULL; + + if (ECL_GRID_MAINGRID_LGR_NR == lgr_nr) { + keyword1 = ecl_file_iget_named_kw( ecl_file , NNC1_KW , i); + keyword2 = ecl_file_iget_named_kw( ecl_file , NNC2_KW , i); + } else { + int nnc_lgr_index = (num_nnchead_kw == num_nncg_kw) ? i : i-1; //Subtract 1 if no nnc data for main grid + keyword1 = ecl_file_iget_named_kw( ecl_file , NNCL_KW , nnc_lgr_index); + keyword2 = ecl_file_iget_named_kw( ecl_file , NNCG_KW , nnc_lgr_index); + } + + { + ecl_grid_type * grid = (lgr_nr > 0) ? ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr) : main_grid; + ecl_grid_init_nnc_cells(grid, main_grid, keyword1, keyword2); + } + } +} + +/* + This function reads the non-neighbour connection data for amalgamated LGRs (that is, non-neighbour + connections between two LGRs) and initializes the grid structure with the nnc data. + */ +static void ecl_grid_init_nnc_amalgamated(ecl_grid_type * main_grid, ecl_file_type * ecl_file) { + int num_nncheada_kw = ecl_file_get_num_named_kw( ecl_file , NNCHEADA_KW ); + + int i; + for (i = 0; i < num_nncheada_kw; i++) { + ecl_kw_type * nncheada_kw = ecl_file_iget_named_kw( ecl_file , NNCHEADA_KW , i); + int lgr_nr1 = ecl_kw_iget_int(nncheada_kw, NNCHEADA_ILOC1_INDEX); + int lgr_nr2 = ecl_kw_iget_int(nncheada_kw, NNCHEADA_ILOC2_INDEX); + + ecl_grid_type * lgr_grid1 = ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr1); + ecl_grid_type * lgr_grid2 = ecl_grid_get_lgr_from_lgr_nr(main_grid, lgr_nr2); + + ecl_kw_type * nna1_kw = ecl_file_iget_named_kw( ecl_file , NNA1_KW , i); + ecl_kw_type * nna2_kw = ecl_file_iget_named_kw( ecl_file , NNA2_KW , i); + + ecl_grid_init_nnc_cells( lgr_grid1 ,lgr_grid2, nna1_kw, nna2_kw); + + } +} + + + + /** Creating a grid based on a EGRID file is a three step process: @@ -2044,7 +2244,7 @@ static ecl_grid_type * ecl_grid_alloc_EGRID__( ecl_grid_type * main_grid , const corsnum_kw = ecl_file_iget_named_kw( ecl_file , CORSNUM_KW , 0); } - + { ecl_grid_type * ecl_grid = ecl_grid_alloc_GRDECL_kw__( main_grid , @@ -2054,10 +2254,9 @@ static ecl_grid_type * ecl_grid_alloc_EGRID__( ecl_grid_type * main_grid , const coord_kw , actnum_kw , mapaxes_kw , - corsnum_kw , - grid_nr ); - - if (grid_nr > 0) ecl_grid_set_lgr_name_EGRID(ecl_grid , ecl_file , grid_nr); + corsnum_kw ); + + if (ECL_GRID_MAINGRID_LGR_NR != grid_nr) ecl_grid_set_lgr_name_EGRID(ecl_grid , ecl_file , grid_nr); return ecl_grid; } } @@ -2090,6 +2289,10 @@ static ecl_grid_type * ecl_grid_alloc_EGRID(const char * grid_file) { } } main_grid->name = util_alloc_string_copy( grid_file ); + + ecl_grid_init_nnc(main_grid, ecl_file); + ecl_grid_init_nnc_amalgamated(main_grid, ecl_file); + ecl_file_close( ecl_file ); return main_grid; } @@ -2105,7 +2308,7 @@ static ecl_grid_type * ecl_grid_alloc_GRID_data__(ecl_grid_type * global_grid , if (dualp_flag != FILEHEAD_SINGLE_POROSITY) nz = nz / 2; { - ecl_grid_type * grid = ecl_grid_alloc_empty( global_grid , dualp_flag , nx , ny , nz , grid_nr , false); + ecl_grid_type * grid = ecl_grid_alloc_empty( global_grid , dualp_flag , nx , ny , nz , grid_nr, false); if (mapaxes != NULL) ecl_grid_init_mapaxes( grid , mapaxes ); @@ -2343,7 +2546,7 @@ static ecl_grid_type * ecl_grid_alloc_GRID(const char * grid_file) { */ ecl_grid_type * ecl_grid_alloc_regular( int nx, int ny , int nz , const double * ivec, const double * jvec , const double * kvec , const int * actnum) { - ecl_grid_type * grid = ecl_grid_alloc_empty(NULL , FILEHEAD_SINGLE_POROSITY , nx , ny , nz , 0,true); + ecl_grid_type * grid = ecl_grid_alloc_empty(NULL , FILEHEAD_SINGLE_POROSITY , nx , ny , nz , 0, true); const double offset[3] = {0,0,0}; int k,j,i; @@ -2601,7 +2804,10 @@ ecl_grid_type * ecl_grid_load_case( const char * case_input ) { ecl_grid_type * ecl_grid = NULL; char * grid_file = ecl_grid_alloc_case_filename( case_input ); if (grid_file != NULL) { - ecl_grid = ecl_grid_alloc( grid_file ); + + if (util_file_exists( grid_file )) + ecl_grid = ecl_grid_alloc( grid_file ); + free( grid_file ); } return ecl_grid; @@ -2946,13 +3152,15 @@ void ecl_grid_free(ecl_grid_type * grid) { double_vector_free( grid->values[i] ); free( grid->values ); } - if (grid->grid_nr == 0) { /* This is the main grid. */ + if (ECL_GRID_MAINGRID_LGR_NR == grid->lgr_nr) { /* This is the main grid. */ vector_free( grid->LGR_list ); + int_vector_free( grid->lgr_index_map); hash_free( grid->LGR_hash ); } if (grid->coord_kw != NULL) ecl_kw_free( grid->coord_kw ); + nnc_index_list_free( grid->nnc_index_list ); vector_free( grid->coarse_cells ); hash_free( grid->children ); util_safe_free( grid->parent_name ); @@ -3040,10 +3248,10 @@ grid_dims_type ecl_grid_iget_dims( const ecl_grid_type * grid , int grid_nr) { grid_dims_type dims; const ecl_grid_type * lgr; - if (grid_nr == 0) + if (grid_nr == 0) lgr = grid; else - lgr = ecl_grid_iget_lgr( grid , grid_nr - 1 ); + lgr = ecl_grid_iget_lgr(grid, grid_nr - 1); dims.nx = lgr->nx; dims.ny = lgr->ny; @@ -3365,6 +3573,25 @@ double ecl_grid_get_cell_thickness3( const ecl_grid_type * grid , int i , int j } +const int_vector_type * ecl_grid_get_nnc_index_list( ecl_grid_type * grid ) { + return nnc_index_list_get_list( grid->nnc_index_list ); +} + + +const nnc_info_type * ecl_grid_get_cell_nnc_info1( const ecl_grid_type * grid , int global_index) { + const ecl_cell_type * cell = ecl_grid_get_cell( grid , global_index); + return cell->nnc_info; +} + + + +const nnc_info_type * ecl_grid_get_cell_nnc_info3( const ecl_grid_type * grid , int i , int j , int k) { + const int global_index = ecl_grid_get_global_index3(grid , i,j,k); + return ecl_grid_get_cell_nnc_info1(grid, global_index); +} + + + /*****************************************************************/ /* Functions to query whether a cell is active or not. */ @@ -3409,7 +3636,7 @@ double ecl_grid_cell_invalid1A(const ecl_grid_type * grid , int active_index) { /* Functions for LGR query/lookup/... */ static void __assert_main_grid(const ecl_grid_type * ecl_grid) { - if (ecl_grid->grid_nr != 0) + if (ecl_grid->lgr_nr != ECL_GRID_MAINGRID_LGR_NR) util_abort("%s: tried to get LGR grid from another LGR_grid - only main grid can be used as first input \n",__func__); } @@ -3468,20 +3695,37 @@ bool ecl_grid_have_coarse_cells( const ecl_grid_type * main_grid ) { */ int ecl_grid_get_num_lgr(const ecl_grid_type * main_grid ) { __assert_main_grid( main_grid ); - return vector_get_size( main_grid->LGR_list ) - 1; + return vector_get_size( main_grid->LGR_list ); } /** - The lgr_nr has zero offset, not counting the main grid, i.e. - - ecl_grid_iget_lgr( ecl_grid , 0); - - will return the first LGR - and fail HARD if there are no LGR's. + The lgr_index has zero offset + ecl_grid_iget_lgr( ecl_grid , 0); will return the first lgr + ecl_grid_iget_lgr( ecl_grid , 1); will return the second lgr + The method will fail HARD if lgr_index is out of bounds. */ -ecl_grid_type * ecl_grid_iget_lgr(const ecl_grid_type * main_grid, int lgr_nr) { +ecl_grid_type * ecl_grid_iget_lgr(const ecl_grid_type * main_grid, int lgr_index) { __assert_main_grid( main_grid ); - return vector_iget( main_grid->LGR_list , lgr_nr + 1); + return vector_iget( main_grid->LGR_list , lgr_index); +} + +/* + This function returns the lgr with the given lgr_nr. The lgr_nr is + the fourth element in the GRIDHEAD for EGRID files. The lgr nr is + equal to the grid nr if the grid's are consecutive numbered and + read from file in increasing lgr nr order. + + This method can only be used for EGRID files. For GRID files the + lgr_nr is 0 for all grids. +*/ + +ecl_grid_type * ecl_grid_get_lgr_from_lgr_nr(const ecl_grid_type * main_grid, int lgr_nr) { + __assert_main_grid( main_grid ); + { + int lgr_index = int_vector_iget( main_grid->lgr_index_map , lgr_nr ); + return vector_iget( main_grid->LGR_list , lgr_index); + } } @@ -3523,7 +3767,7 @@ const ecl_grid_type * ecl_grid_get_cell_lgr1A(const ecl_grid_type * grid , int a Will return the global grid for a lgr. If the input grid is indeed a global grid itself the function will return NULL. */ -const ecl_grid_type * ecl_grid_get_global_grid( const ecl_grid_type * grid ) { + const ecl_grid_type * ecl_grid_get_global_grid( const ecl_grid_type * grid ) { return grid->global_grid; } @@ -3541,27 +3785,40 @@ stringlist_type * ecl_grid_alloc_lgr_name_list(const ecl_grid_type * ecl_grid) { } } +const char * ecl_grid_iget_lgr_name( const ecl_grid_type * ecl_grid , int lgr_index) { + __assert_main_grid( ecl_grid ); + if (lgr_index < (vector_get_size( ecl_grid->LGR_list ))) { + const ecl_grid_type * lgr = vector_iget( ecl_grid->LGR_list , lgr_index); + return lgr->name; + } else + return NULL; +} + + +const char * ecl_grid_get_lgr_name( const ecl_grid_type * ecl_grid , int lgr_nr) { + __assert_main_grid( ecl_grid ); + { + int lgr_index = int_vector_iget( ecl_grid->lgr_index_map , lgr_nr ); + return ecl_grid_iget_lgr_name( ecl_grid , lgr_index ); + } +} /*****************************************************************/ /** - This function returns the grid_nr field of the field; this is just - the occurence number in the grid file. Starting with 0 at the main + This function returns the lgr_nr field of the grid; for GRID files, this + is just the occurence number in the grid file. Starting with 0 at the main grid, and then increasing consecutively through the lgr sections. - - Observe that there is A MAJOR POTENTIAL for confusion with the - ecl_grid_iget_lgr() function, the latter does not refer to the main - grid and returns the first lgr section (which has grid_nr == 1) for - input argument 0. + For EGRID files, this is the LGR number (fourth element in the + gridhead). */ -int ecl_grid_get_grid_nr( const ecl_grid_type * ecl_grid ) { - return ecl_grid->grid_nr; +int ecl_grid_get_lgr_nr( const ecl_grid_type * ecl_grid ) { + return ecl_grid->lgr_nr; } - const char * ecl_grid_get_name( const ecl_grid_type * ecl_grid ) { return ecl_grid->name; } @@ -3600,7 +3857,7 @@ void ecl_grid_summarize(const ecl_grid_type * ecl_grid) { printf(" Origo X................: %10.2f \n",ecl_grid->origo[0]); printf(" Origo Y................: %10.2f \n",ecl_grid->origo[1]); - if (ecl_grid->grid_nr == 0) { + if (ECL_GRID_MAINGRID_LGR_NR == ecl_grid->lgr_nr) { int grid_nr; for (grid_nr=1; grid_nr < vector_get_size( ecl_grid->LGR_list ); grid_nr++) { printf("\n"); @@ -3941,7 +4198,7 @@ bool ecl_grid_test_lgr_consistency( const ecl_grid_type * ecl_grid ) { static void ecl_grid_dump__(const ecl_grid_type * grid , FILE * stream) { - util_fwrite_int( grid->grid_nr , stream ); + util_fwrite_int( grid->lgr_nr , stream ); util_fwrite_string( grid->name , stream ); util_fwrite_int( grid->nx , stream ); util_fwrite_int( grid->nz , stream ); @@ -3962,7 +4219,7 @@ static void ecl_grid_dump__(const ecl_grid_type * grid , FILE * stream) { static void ecl_grid_dump_ascii__(const ecl_grid_type * grid , bool active_only , FILE * stream) { - fprintf(stream , "Grid nr : %d\n",grid->grid_nr); + fprintf(stream , "Grid nr : %d\n",grid->lgr_nr); fprintf(stream , "Grid name : %s\n",grid->name); fprintf(stream , "nx : %6d\n",grid->nx); fprintf(stream , "ny : %6d\n",grid->ny); @@ -3994,15 +4251,21 @@ static void ecl_grid_dump_ascii__(const ecl_grid_type * grid , bool active_only void ecl_grid_dump(const ecl_grid_type * grid , FILE * stream) { - int i; - for (i = 0; i < vector_get_size( grid->LGR_list ); i++) - ecl_grid_dump__( vector_iget_const( grid->LGR_list , i) , stream ); + ecl_grid_dump__(grid, stream ); + { + int i; + for (i = 0; i < vector_get_size( grid->LGR_list ); i++) + ecl_grid_dump__( vector_iget_const( grid->LGR_list , i) , stream ); + } } void ecl_grid_dump_ascii(const ecl_grid_type * grid , bool active_only , FILE * stream) { - int i; - for (i = 0; i < vector_get_size( grid->LGR_list ); i++) - ecl_grid_dump_ascii__( vector_iget_const( grid->LGR_list , i) , active_only , stream ); + ecl_grid_dump_ascii__( grid , active_only , stream ); + { + int i; + for (i = 0; i < vector_get_size( grid->LGR_list ); i++) + ecl_grid_dump_ascii__( vector_iget_const( grid->LGR_list , i) , active_only , stream ); + } } @@ -4167,6 +4430,8 @@ void ecl_grid_fwrite_GRID( const ecl_grid_type * grid , const char * filename) { if (grid->coarsening_active) coords_size = 7; + ecl_grid_fwrite_GRID__( grid , coords_size , fortio ); + { int grid_nr; for (grid_nr = 0; grid_nr < vector_get_size( grid->LGR_list ); grid_nr++) { @@ -4578,7 +4843,7 @@ static void ecl_grid_fwrite_EGRID__( ecl_grid_type * grid , fortio_type * fortio } } - ecl_grid_fwrite_gridhead_kw( grid->nx , grid->ny , grid->nz , grid->grid_nr , fortio); + ecl_grid_fwrite_gridhead_kw( grid->nx , grid->ny , grid->nz , grid->lgr_nr , fortio); /* Writing main grid data */ { { @@ -4624,6 +4889,8 @@ static void ecl_grid_fwrite_EGRID__( ecl_grid_type * grid , fortio_type * fortio void ecl_grid_fwrite_EGRID( ecl_grid_type * grid , const char * filename) { bool fmt_file = false; fortio_type * fortio = fortio_open_writer( filename , fmt_file , ECL_ENDIAN_FLIP ); + + ecl_grid_fwrite_EGRID__( grid , fortio ); { int grid_nr; for (grid_nr = 0; grid_nr < vector_get_size( grid->LGR_list ); grid_nr++) { diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_kw.c b/ThirdParty/Ert/devel/libecl/src/ecl_kw.c index 85432ec2c3..296d03f20f 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_kw.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_kw.c @@ -2374,7 +2374,7 @@ void ecl_kw_inplace_update_file(const ecl_kw_type * ecl_kw , const char * filena /******************************************************************/ bool ecl_kw_is_kw_file(FILE * stream , bool fmt_file ) { - const long int init_pos = ftell(stream); + const long int init_pos = util_ftell(stream); bool kw_file; { @@ -2394,7 +2394,7 @@ bool ecl_kw_is_kw_file(FILE * stream , bool fmt_file ) { ecl_kw_free(ecl_kw); } - fseek(stream , init_pos , SEEK_SET); + util_fseek(stream , init_pos , SEEK_SET); return kw_file; } @@ -2403,7 +2403,7 @@ bool ecl_kw_is_kw_file(FILE * stream , bool fmt_file ) { bool ecl_kw_is_grdecl_file(FILE * stream) { - const long int init_pos = ftell(stream); + const long int init_pos = util_ftell(stream); bool grdecl_file; bool at_eof = false; util_fskip_chars(stream , " \r\n\t" , &at_eof); /* Skipping intial space */ @@ -2427,7 +2427,7 @@ bool ecl_kw_is_grdecl_file(FILE * stream) { } while (c == ' '); } } - fseek(stream , init_pos , SEEK_SET); + util_fseek(stream , init_pos , SEEK_SET); return grdecl_file; } diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_kw_grdecl.c b/ThirdParty/Ert/devel/libecl/src/ecl_kw_grdecl.c index 1fb0f3bb5a..cc6d71c29a 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_kw_grdecl.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_kw_grdecl.c @@ -71,7 +71,7 @@ bool ecl_kw_grdecl_fseek_next_kw( FILE * stream ) { - long start_pos = ftell( stream ); + long start_pos = util_ftell( stream ); long current_pos; char next_kw[256]; @@ -83,14 +83,14 @@ bool ecl_kw_grdecl_fseek_next_kw( FILE * stream ) { { while (true) { char c; - if (ftell(stream) == 0) + if (util_ftell(stream) == 0) /* We are at the very beginning of the file. Can just jump out of the loop. */ break; - fseek( stream , -1 , SEEK_CUR ); + util_fseek( stream , -1 , SEEK_CUR ); c = fgetc( stream ); if (c == '\n') { /* @@ -98,7 +98,7 @@ bool ecl_kw_grdecl_fseek_next_kw( FILE * stream ) { have not reached any !isspace() characters on the way and can go back to start_pos and read from there. */ - fseek( stream , start_pos , SEEK_SET ); + util_fseek( stream , start_pos , SEEK_SET ); break; } @@ -111,25 +111,25 @@ bool ecl_kw_grdecl_fseek_next_kw( FILE * stream ) { util_fskip_lines( stream , 1 ); break; } - fseek( stream , -2 , SEEK_CUR ); + util_fseek( stream , -2 , SEEK_CUR ); } } while (true) { - current_pos = ftell( stream ); + current_pos = util_ftell( stream ); if (fscanf(stream , "%s" , next_kw) == 1) { if ((next_kw[0] == next_kw[1]) && (next_kw[0] == ECL_COMMENT_CHAR)) // This is a comment line - skip it. util_fskip_lines( stream , 1 ); else { // This is a valid keyword i.e. a non-commented out string; return true. - fseek( stream , current_pos , SEEK_SET ); + util_fseek( stream , current_pos , SEEK_SET ); return true; } } else { // EOF reached - return False. - fseek( stream , start_pos , SEEK_SET ); + util_fseek( stream , start_pos , SEEK_SET ); return false; } } @@ -167,17 +167,17 @@ char * ecl_kw_grdecl_alloc_next_header( FILE * stream ) { */ static bool ecl_kw_grdecl_fseek_kw__(const char * kw , FILE * stream) { - long init_pos = ftell( stream ); + long init_pos = util_ftell( stream ); while (true) { if (ecl_kw_grdecl_fseek_next_kw( stream )) { char next_kw[256]; fscanf( stream , "%s" , next_kw); if (strcmp( kw , next_kw ) == 0) { - fseek( stream , -strlen(next_kw) , SEEK_CUR); + util_fseek( stream , -strlen(next_kw) , SEEK_CUR); return true; } } else { - fseek( stream , init_pos , SEEK_SET); + util_fseek( stream , init_pos , SEEK_SET); return false; } } @@ -274,13 +274,13 @@ bool ecl_kw_grdecl_fseek_kw(const char * kw , bool rewind , FILE * stream) { if (ecl_kw_grdecl_fseek_kw__(kw , stream)) return true; /* OK - we found the kw between current file pos and EOF. */ else if (rewind) { - long int init_pos = ftell(stream); + long int init_pos = util_ftell(stream); - fseek(stream , 0L , SEEK_SET); + util_fseek(stream , 0L , SEEK_SET); if (ecl_kw_grdecl_fseek_kw__( kw , stream )) /* Try again from the beginning of the file. */ return true; else - fseek(stream , init_pos , SEEK_SET); /* Could not find it - reposition to initial position. */ + util_fseek(stream , init_pos , SEEK_SET); /* Could not find it - reposition to initial position. */ } /* OK: If we are here - that means that we failed to find the kw. */ diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_region.c b/ThirdParty/Ert/devel/libecl/src/ecl_region.c index 2c872abaf1..cab67acd54 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_region.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_region.c @@ -689,8 +689,9 @@ void ecl_region_deselect_i1i2( ecl_region_type * region , int i1 , int i2) { static void ecl_region_select_j1j2__( ecl_region_type * region , int j1 , int j2 , bool select) { if (j1 > j2) util_abort("%s: i1 > i2 - this is illogical ... \n",__func__); + j1 = util_int_max(0 , j1); - j2 = util_int_min(region->grid_nx - 1 , j2); + j2 = util_int_min(region->grid_ny - 1 , j2); { int i,j,k; for (k = 0; k < region->grid_nz; k++) @@ -729,7 +730,7 @@ static void ecl_region_select_k1k2__( ecl_region_type * region , int k1 , int k2 if (k1 > k2) util_abort("%s: i1 > i2 - this is illogical ... \n",__func__); k1 = util_int_max(0 , k1); - k2 = util_int_min(region->grid_nx - 1 , k2); + k2 = util_int_min(region->grid_nz - 1 , k2); { int i,j,k; for (k = k1; k <= k2; k++) diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_rft_cell.c b/ThirdParty/Ert/devel/libecl/src/ecl_rft_cell.c new file mode 100644 index 0000000000..1891855d2e --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/src/ecl_rft_cell.c @@ -0,0 +1,367 @@ +/* + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'ecl_rft_cell.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + + +#define ECL_RFT_CELL_TYPE_ID 99164012 +#define RFT_DATA_TYPE_ID 66787166 +#define PLT_DATA_TYPE_ID 87166667 + + +struct ecl_rft_cell_struct { + UTIL_TYPE_ID_DECLARATION; + int i,j,k; + double pressure; + double depth; + + void * data; +}; + + +typedef struct plt_data_struct plt_data_type; +typedef struct rft_data_struct rft_data_type; + + +struct rft_data_struct { + UTIL_TYPE_ID_DECLARATION; + double swat; + double sgas; +}; + + + + +struct plt_data_struct { + UTIL_TYPE_ID_DECLARATION; + double orat; + double wrat; + double grat; + double connection_start; + double connection_end; + double flowrate; + double oil_flowrate; + double gas_flowrate; + double water_flowrate; +}; + + +/*****************************************************************/ + +static rft_data_type * rft_data_alloc( double swat , double sgas) { + rft_data_type * data = util_malloc( sizeof * data ); + UTIL_TYPE_ID_INIT( data , RFT_DATA_TYPE_ID ); + + data->swat = swat; + data->sgas = sgas; + + return data; +} + + +static void rft_data_free( rft_data_type * data ) { + free( data ); +} + +static UTIL_TRY_CAST_FUNCTION_CONST( rft_data , RFT_DATA_TYPE_ID) +static UTIL_IS_INSTANCE_FUNCTION( rft_data , RFT_DATA_TYPE_ID) + +/*****************************************************************/ + + static plt_data_type * plt_data_alloc( double orat , double grat , double wrat,double connection_start, double connection_end, double flowrate , double oil_flowrate , double gas_flowrate , double water_flowrate) { + plt_data_type * data = util_malloc( sizeof * data ); + UTIL_TYPE_ID_INIT( data , PLT_DATA_TYPE_ID ); + + data->orat = orat; + data->grat = grat; + data->wrat = wrat; + data->connection_start = connection_start; + data->connection_end = connection_end; + data->flowrate = flowrate; + data->oil_flowrate = oil_flowrate; + data->gas_flowrate = gas_flowrate; + data->water_flowrate = water_flowrate; + + return data; +} + + +static void plt_data_free( plt_data_type * data ) { + free( data ); +} + +static UTIL_TRY_CAST_FUNCTION_CONST( plt_data , PLT_DATA_TYPE_ID) +static UTIL_IS_INSTANCE_FUNCTION( plt_data , PLT_DATA_TYPE_ID) + + + +/*****************************************************************/ + +static UTIL_SAFE_CAST_FUNCTION( ecl_rft_cell , ECL_RFT_CELL_TYPE_ID) +static UTIL_SAFE_CAST_FUNCTION_CONST( ecl_rft_cell , ECL_RFT_CELL_TYPE_ID) +UTIL_IS_INSTANCE_FUNCTION( ecl_rft_cell , ECL_RFT_CELL_TYPE_ID) + + + +static ecl_rft_cell_type * ecl_rft_cell_alloc_common(int i , int j , int k , double depth , double pressure) { + ecl_rft_cell_type * cell = util_malloc( sizeof * cell ); + UTIL_TYPE_ID_INIT( cell , ECL_RFT_CELL_TYPE_ID ); + + cell->i = i; + cell->j = j; + cell->k = k; + cell->depth = depth; + cell->pressure = pressure; + + return cell; +} + + + +ecl_rft_cell_type * ecl_rft_cell_alloc_RFT( int i , int j , int k , double depth , double pressure , double swat , double sgas) { + ecl_rft_cell_type * cell = ecl_rft_cell_alloc_common( i , j , k , depth , pressure ); + + cell->data = rft_data_alloc( swat , sgas ); + return cell; +} + + +ecl_rft_cell_type * ecl_rft_cell_alloc_PLT( int i , + int j , + int k , + double depth , + double pressure , + double orat , + double grat , + double wrat, + double connection_start, + double connection_end, + double flowrate , + double oil_flowrate , + double gas_flowrate , + double water_flowrate) { + + ecl_rft_cell_type * cell = ecl_rft_cell_alloc_common( i , j , k , depth , pressure ); + + cell->data = plt_data_alloc( orat , grat , wrat , connection_start , connection_end , flowrate , oil_flowrate , gas_flowrate , water_flowrate); + return cell; +} + + + +void ecl_rft_cell_free( ecl_rft_cell_type * cell ) { + if (rft_data_is_instance( cell->data )) + rft_data_free( cell->data ); + else if (plt_data_is_instance( cell->data )) + plt_data_free( cell->data ); + + free( cell ); +} + +void ecl_rft_cell_free__( void * arg) { + ecl_rft_cell_type * cell = ecl_rft_cell_safe_cast( arg ); + ecl_rft_cell_free( cell ); +} + + +/*****************************************************************/ + +int ecl_rft_cell_get_i( const ecl_rft_cell_type * cell ) { + return cell->i; +} + +int ecl_rft_cell_get_j( const ecl_rft_cell_type * cell ) { + return cell->j; +} + +int ecl_rft_cell_get_k( const ecl_rft_cell_type * cell ) { + return cell->k; +} + +void ecl_rft_cell_get_ijk( const ecl_rft_cell_type * cell , int * i , int * j , int * k) { + *i = cell->i; + *j = cell->j; + *k = cell->k; +} + +double ecl_rft_cell_get_depth( const ecl_rft_cell_type * cell ) { + return cell->depth; +} + +double ecl_rft_cell_get_pressure( const ecl_rft_cell_type * cell ) { + return cell->pressure; +} + + +/*****************************************************************/ + +double ecl_rft_cell_get_swat( const ecl_rft_cell_type * cell ) { + const rft_data_type * data = rft_data_try_cast_const( cell->data ); + if (data) + return data->swat; + else + return ECL_RFT_CELL_INVALID_VALUE; +} + + +double ecl_rft_cell_get_sgas( const ecl_rft_cell_type * cell ) { + const rft_data_type * data = rft_data_try_cast_const( cell->data ); + if (data) + return data->sgas; + else + return ECL_RFT_CELL_INVALID_VALUE; +} + + +double ecl_rft_cell_get_soil( const ecl_rft_cell_type * cell ) { + const rft_data_type * data = rft_data_try_cast_const( cell->data ); + if (data) + return 1 - (data->swat + data->sgas); + else + return ECL_RFT_CELL_INVALID_VALUE; +} + +/*****************************************************************/ + +double ecl_rft_cell_get_orat( const ecl_rft_cell_type * cell ) { + const plt_data_type * data = plt_data_try_cast_const( cell->data ); + if (data) + return data->orat; + else + return ECL_RFT_CELL_INVALID_VALUE; +} + + +double ecl_rft_cell_get_grat( const ecl_rft_cell_type * cell ) { + const plt_data_type * data = plt_data_try_cast_const( cell->data ); + if (data) + return data->grat; + else + return ECL_RFT_CELL_INVALID_VALUE; +} + + +double ecl_rft_cell_get_wrat( const ecl_rft_cell_type * cell ) { + const plt_data_type * data = plt_data_try_cast_const( cell->data ); + if (data) + return data->wrat; + else + return ECL_RFT_CELL_INVALID_VALUE; +} + +double ecl_rft_cell_get_connection_start( const ecl_rft_cell_type * cell ) { + const plt_data_type * data = plt_data_try_cast_const( cell->data ); + if (data) + return data->connection_start; + else + return ECL_RFT_CELL_INVALID_VALUE; +} + +double ecl_rft_cell_get_connection_end( const ecl_rft_cell_type * cell ) { + const plt_data_type * data = plt_data_try_cast_const( cell->data ); + if (data) + return data->connection_end; + else + return ECL_RFT_CELL_INVALID_VALUE; +} + +double ecl_rft_cell_get_flowrate( const ecl_rft_cell_type * cell ) { + const plt_data_type * data = plt_data_try_cast_const( cell->data ); + if (data) + return data->flowrate; + else + return ECL_RFT_CELL_INVALID_VALUE; +} + + +double ecl_rft_cell_get_oil_flowrate( const ecl_rft_cell_type * cell ) { + const plt_data_type * data = plt_data_try_cast_const( cell->data ); + if (data) + return data->oil_flowrate; + else + return ECL_RFT_CELL_INVALID_VALUE; +} + + +double ecl_rft_cell_get_gas_flowrate( const ecl_rft_cell_type * cell ) { + const plt_data_type * data = plt_data_try_cast_const( cell->data ); + if (data) + return data->gas_flowrate; + else + return ECL_RFT_CELL_INVALID_VALUE; +} + + +double ecl_rft_cell_get_water_flowrate( const ecl_rft_cell_type * cell ) { + const plt_data_type * data = plt_data_try_cast_const( cell->data ); + if (data) + return data->water_flowrate; + else + return ECL_RFT_CELL_INVALID_VALUE; +} + + + + + +/*****************************************************************/ + + + +bool ecl_rft_cell_ijk_equal( const ecl_rft_cell_type * cell , int i , int j , int k) { + return ( (i == cell->i) && + (j == cell->j) && + (k == cell->k) ); +} + + +/* + Currently only comparison based on connection length along PLT is supported. +*/ +int ecl_rft_cell_cmp( const ecl_rft_cell_type * cell1 , const ecl_rft_cell_type * cell2) { + double val1 = ecl_rft_cell_get_connection_start( cell1 ); + double val2 = ecl_rft_cell_get_connection_start( cell2 ); + + if (val1 < val2) + return -1; + else if (val1 == val2) + return 0; + else + return 1; + +} + + +int ecl_rft_cell_cmp__( const void * arg1 , const void * arg2) { + const ecl_rft_cell_type * cell1 = ecl_rft_cell_safe_cast_const( arg1 ); + const ecl_rft_cell_type * cell2 = ecl_rft_cell_safe_cast_const( arg2 ); + return ecl_rft_cell_cmp( cell1 , cell2 ); +} diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_rft_file.c b/ThirdParty/Ert/devel/libecl/src/ecl_rft_file.c index f65f0e6937..f06f9d00c2 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_rft_file.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_rft_file.c @@ -226,8 +226,8 @@ int ecl_rft_file_get_size__( const ecl_rft_file_type * rft_file, const char * we for ( i=0; i < vector_get_size( rft_file->data ); i++) { const ecl_rft_node_type * rft = vector_iget_const( rft_file->data , i); - if (well_pattern != NULL) { - if (!util_fnmatch( well_pattern , ecl_rft_node_get_well_name( rft ))) + if (well_pattern) { + if (util_fnmatch( well_pattern , ecl_rft_node_get_well_name( rft )) != 0) continue; } @@ -269,8 +269,8 @@ const char * ecl_rft_file_get_filename( const ecl_rft_file_type * rft_file ) { handle that. */ -const ecl_rft_node_type * ecl_rft_file_iget_node( const ecl_rft_file_type * rft_file , int index) { - return vector_iget_const( rft_file->data , index ); +ecl_rft_node_type * ecl_rft_file_iget_node( const ecl_rft_file_type * rft_file , int index) { + return vector_iget( rft_file->data , index ); } @@ -301,7 +301,7 @@ const ecl_rft_node_type * ecl_rft_file_iget_node( const ecl_rft_file_type * rft_ -const ecl_rft_node_type * ecl_rft_file_iget_well_rft( const ecl_rft_file_type * rft_file , const char * well, int index) { +ecl_rft_node_type * ecl_rft_file_iget_well_rft( const ecl_rft_file_type * rft_file , const char * well, int index) { const int_vector_type * index_vector = hash_get(rft_file->well_index , well); return ecl_rft_file_iget_node( rft_file , int_vector_iget(index_vector , index)); } @@ -315,8 +315,8 @@ const ecl_rft_node_type * ecl_rft_file_iget_well_rft( const ecl_rft_file_type * */ -const ecl_rft_node_type * ecl_rft_file_get_well_time_rft( const ecl_rft_file_type * rft_file , const char * well , time_t recording_time) { - const ecl_rft_node_type * node = NULL; +ecl_rft_node_type * ecl_rft_file_get_well_time_rft( const ecl_rft_file_type * rft_file , const char * well , time_t recording_time) { + ecl_rft_node_type * node = NULL; if (hash_has_key( rft_file->well_index , well)) { const int_vector_type * index_vector = hash_get(rft_file->well_index , well); int index = 0; @@ -367,56 +367,6 @@ stringlist_type * ecl_rft_file_alloc_well_list(const ecl_rft_file_type * rft_fil } -/*****************************************************************/ -void ecl_rft_file_summarize(const ecl_rft_file_type * rft_vector , bool show_completions) { - int iw; - for (iw = 0; iw < vector_get_size( rft_vector->data ); iw++) { - ecl_rft_node_summarize(vector_iget( rft_vector->data , iw) , show_completions); - printf("\n"); - } -} - -void ecl_rft_file_xml_summary( const ecl_rft_file_type * rft_file ) { - stringlist_type * wells = ecl_rft_file_alloc_well_list( rft_file ); - printf("\n"); - { - int iw; - for (iw = 0; iw < stringlist_get_size( wells ); iw++) { - const char * well = stringlist_iget(wells , iw); - printf(" \n"); - { - int it; - for (it = 0; it < ecl_rft_file_get_well_occurences( rft_file , well ); it++) { - const ecl_rft_node_type * node = ecl_rft_file_iget_well_rft( rft_file , well , it); - time_t date = ecl_rft_node_get_date( node ); - { - int mday, year,month; - util_set_date_values( date , &mday , &month , &year); - printf(" \n"); - printf(" %02d/%02d/%4d \n",mday,month,year); - { - int num_cells = ecl_rft_node_get_size( node ); - int icell; - for (icell = 0; icell < num_cells; icell++) { - int i,j,k; - ecl_rft_node_iget_ijk( node , icell , &i , &j , &k); - printf(" \n"); - printf(" %g \n", ecl_rft_node_iget_pressure( node, icell)); - printf(" %g \n" , ecl_rft_node_iget_depth( node , icell)); - printf(" %3d,%3d,%3d \n",i,j,k); - printf(" \n"); - } - } - printf(" \n"); - } - } - } - printf(" \n"); - } - } - printf("\n"); - stringlist_free( wells ); -} diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_rft_node.c b/ThirdParty/Ert/devel/libecl/src/ecl_rft_node.c index 6c37f90306..090f4ba05c 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_rft_node.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_rft_node.c @@ -25,12 +25,14 @@ #include #include +#include +#include #include #include #include #include - +#include /** The RFT's from several wells, and possibly also several timesteps @@ -48,80 +50,20 @@ */ -/** - Here comes some small structs containing various pieces of - information. Observe the following which is common to all these - structs: - - * In the implementation only 'full instance' are employed, and - not pointers. This implies that the code does not provide - xxx_alloc() and xx_free() functions. - - * They should NOT be exported out of this file. -*/ - - -/** - This type is used to hold the coordinates of a perforated - cell. This type is used irrespective of whether this is a simple - RFT or a PLT. -*/ - -typedef struct { - int i; - int j; - int k; - double depth; - double pressure; /* both CONPRES from PLT and PRESSURE from RFT are internalized as pressure in the cell_type. */ -} cell_type; - -/*-----------------------------------------------------------------*/ -/** - Type which contains the information for one cell in an RFT. -*/ -typedef struct { - double swat; - double sgas; -} rft_data_type; - - -/*-----------------------------------------------------------------*/ -/** - Type which contains the information for one cell in an PLT. -*/ -typedef struct { - double orat; - double grat; - double wrat; - /* There is quite a lot of more information in the PLT - not yet internalized. */ -} plt_data_type; - - - - -/* This is not implemented at all ..... */ -typedef struct { - double data; -} segment_data_type; - #define ECL_RFT_NODE_ID 887195 struct ecl_rft_node_struct { UTIL_TYPE_ID_DECLARATION; char * well_name; /* Name of the well. */ - int size; /* The number of entries in this RFT vector (i.e. the number of cells) .*/ ecl_rft_enum data_type; /* What type of data: RFT|PLT|SEGMENT */ time_t recording_date; /* When was the RFT recorded - date.*/ double days; /* When was the RFT recorded - days after simulaton start. */ - cell_type *cells; /* Coordinates and depth of the well cells. */ - - /* Only one of segment_data, rft_data or plt_data can be != NULL */ - segment_data_type * segment_data; - rft_data_type * rft_data; - plt_data_type * plt_data; - - bool __vertical_well; /* Internal variable - when this is true we can try to block - otherwise it is NO FUXXXX WAY. */ + bool MSW; + + bool sort_perm_in_sync ; + int_vector_type * sort_perm; + vector_type *cells; }; @@ -131,7 +73,7 @@ struct ecl_rft_node_struct { that is not (yet) supported. */ -static ecl_rft_node_type * ecl_rft_node_alloc_empty(int size , const char * data_type_string) { +static ecl_rft_node_type * ecl_rft_node_alloc_empty(const char * data_type_string) { ecl_rft_enum data_type = SEGMENT; /* According to the ECLIPSE documentaton. */ @@ -140,7 +82,7 @@ static ecl_rft_node_type * ecl_rft_node_alloc_empty(int size , const char * data else if (strchr(data_type_string, 'R') != NULL) data_type = RFT; else if (strchr(data_type_string , 'S') != NULL) - data_type = SEGMENT; + data_type = SEGMENT; else util_abort("%s: Could not determine type of RFT/PLT/SEGMENT data - aborting\n",__func__); @@ -153,24 +95,13 @@ static ecl_rft_node_type * ecl_rft_node_alloc_empty(int size , const char * data { ecl_rft_node_type * rft_node = util_malloc(sizeof * rft_node ); - rft_node->plt_data = NULL; - rft_node->rft_data = NULL; - rft_node->segment_data = NULL; - UTIL_TYPE_ID_INIT( rft_node , ECL_RFT_NODE_ID ); - rft_node->cells = util_calloc( size , sizeof * rft_node->cells ); - if (data_type == RFT) - rft_node->rft_data = util_calloc( size , sizeof * rft_node->rft_data ); - else if (data_type == PLT) - rft_node->plt_data = util_calloc( size , sizeof * rft_node->plt_data); - else if (data_type == SEGMENT) - rft_node->segment_data = util_calloc( size , sizeof * rft_node->segment_data ); - - rft_node->__vertical_well = false; - rft_node->size = size; + rft_node->cells = vector_alloc_new(); rft_node->data_type = data_type; - + rft_node->sort_perm = NULL; + rft_node->sort_perm_in_sync = false; + return rft_node; } } @@ -180,112 +111,146 @@ UTIL_SAFE_CAST_FUNCTION( ecl_rft_node , ECL_RFT_NODE_ID ); UTIL_IS_INSTANCE_FUNCTION( ecl_rft_node , ECL_RFT_NODE_ID ); +static void ecl_rft_node_append_cell( ecl_rft_node_type * rft_node , ecl_rft_cell_type * cell) { + vector_append_owned_ref( rft_node->cells , cell , ecl_rft_cell_free__ ); + rft_node->sort_perm_in_sync = false; +} + + + +static void ecl_rft_node_init_RFT_cells( ecl_rft_node_type * rft_node , const ecl_file_type * rft) { + const ecl_kw_type * conipos = ecl_file_iget_named_kw( rft , CONIPOS_KW , 0); + const ecl_kw_type * conjpos = ecl_file_iget_named_kw( rft , CONJPOS_KW , 0); + const ecl_kw_type * conkpos = ecl_file_iget_named_kw( rft , CONKPOS_KW , 0); + const ecl_kw_type * depth_kw = ecl_file_iget_named_kw( rft , DEPTH_KW , 0); + const ecl_kw_type * swat_kw = ecl_file_iget_named_kw( rft , SWAT_KW , 0); + const ecl_kw_type * sgas_kw = ecl_file_iget_named_kw( rft , SGAS_KW , 0); + const ecl_kw_type * pressure_kw = ecl_file_iget_named_kw( rft , PRESSURE_KW , 0); + + const float * SW = ecl_kw_get_float_ptr( swat_kw ); + const float * SG = ecl_kw_get_float_ptr( sgas_kw ); + const float * P = ecl_kw_get_float_ptr( pressure_kw ); + const float * depth = ecl_kw_get_float_ptr( depth_kw ); + const int * i = ecl_kw_get_int_ptr( conipos ); + const int * j = ecl_kw_get_int_ptr( conjpos ); + const int * k = ecl_kw_get_int_ptr( conkpos ); + + { + int c; + for (c = 0; c < ecl_kw_get_size( conipos ); c++) { + /* The connection coordinates are shifted -= 1; i.e. all internal usage is offset 0. */ + ecl_rft_cell_type * cell = ecl_rft_cell_alloc_RFT( i[c] - 1 , j[c] - 1 , k[c] - 1 , + depth[c] , P[c] , SW[c] , SG[c]); + ecl_rft_node_append_cell( rft_node , cell ); + } + } +} + + + + + +static void ecl_rft_node_init_PLT_cells( ecl_rft_node_type * rft_node , const ecl_file_type * rft) { + /* For PLT there is quite a lot of extra information which is not yet internalized. */ + const ecl_kw_type * conipos = ecl_file_iget_named_kw( rft , CONIPOS_KW , 0); + const ecl_kw_type * conjpos = ecl_file_iget_named_kw( rft , CONJPOS_KW , 0); + const ecl_kw_type * conkpos = ecl_file_iget_named_kw( rft , CONKPOS_KW , 0); + + const int * i = ecl_kw_get_int_ptr( conipos ); + const int * j = ecl_kw_get_int_ptr( conjpos ); + const int * k = ecl_kw_get_int_ptr( conkpos ); + + const float * WR = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONWRAT_KW , 0)); + const float * GR = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONGRAT_KW , 0)); + const float * OR = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONORAT_KW , 0)); + const float * P = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONPRES_KW , 0)); + const float * depth = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONDEPTH_KW , 0)); + const float * flowrate = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONVTUB_KW , 0)); + const float * oil_flowrate = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONOTUB_KW , 0)); + const float * gas_flowrate = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONGTUB_KW , 0)); + const float * water_flowrate = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONWTUB_KW , 0)); + const float * connection_start = NULL; + const float * connection_end = NULL; + + /* The keywords CONLENST_KW and CONLENEN_KW are ONLY present if we are dealing with a MSW well. */ + if (ecl_file_has_kw( rft , CONLENST_KW)) + connection_start = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONLENST_KW , 0)); + + if (ecl_file_has_kw( rft , CONLENEN_KW)) + connection_end = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONLENEN_KW , 0)); + + { + int c; + for ( c = 0; c < ecl_kw_get_size( conipos ); c++) { + ecl_rft_cell_type * cell; + double cs = 0; + double ce = 0; + + if (connection_start) + cs = connection_start[c]; + + if (connection_end) + ce = connection_end[c]; + + /* The connection coordinates are shifted -= 1; i.e. all internal usage is offset 0. */ + cell = ecl_rft_cell_alloc_PLT( i[c] -1 , j[c] -1 , k[c] -1 , + depth[c] , P[c] , OR[c] , GR[c] , WR[c] , cs , ce, flowrate[c] , oil_flowrate[c] , gas_flowrate[c] , water_flowrate[c]); + ecl_rft_node_append_cell( rft_node , cell ); + } + } +} + + + + + +static void ecl_rft_node_init_cells( ecl_rft_node_type * rft_node , const ecl_file_type * rft ) { + + if (rft_node->data_type == RFT) + ecl_rft_node_init_RFT_cells( rft_node , rft ); + else if (rft_node->data_type == PLT) + ecl_rft_node_init_PLT_cells( rft_node , rft ); + +} + + ecl_rft_node_type * ecl_rft_node_alloc(const ecl_file_type * rft) { - ecl_kw_type * conipos = ecl_file_iget_named_kw(rft , CONIPOS_KW , 0); ecl_kw_type * welletc = ecl_file_iget_named_kw(rft , WELLETC_KW , 0); - ecl_rft_node_type * rft_node = ecl_rft_node_alloc_empty(ecl_kw_get_size(conipos) , - ecl_kw_iget_ptr(welletc , WELLETC_TYPE_INDEX)); + ecl_rft_node_type * rft_node = ecl_rft_node_alloc_empty(ecl_kw_iget_ptr(welletc , WELLETC_TYPE_INDEX)); if (rft_node != NULL) { ecl_kw_type * date_kw = ecl_file_iget_named_kw( rft , DATE_KW , 0); - ecl_kw_type * conjpos = ecl_file_iget_named_kw( rft , CONJPOS_KW , 0); - ecl_kw_type * conkpos = ecl_file_iget_named_kw( rft , CONKPOS_KW , 0); - ecl_kw_type * depth_kw; - if (rft_node->data_type == RFT) - depth_kw = ecl_file_iget_named_kw( rft , DEPTH_KW , 0); - else - depth_kw = ecl_file_iget_named_kw( rft , CONDEPTH_KW , 0); rft_node->well_name = util_alloc_strip_copy( ecl_kw_iget_ptr(welletc , WELLETC_NAME_INDEX)); - + /* Time information. */ { int * time = ecl_kw_get_int_ptr( date_kw ); rft_node->recording_date = util_make_date( time[DATE_DAY_INDEX] , time[DATE_MONTH_INDEX] , time[DATE_YEAR_INDEX] ); } rft_node->days = ecl_kw_iget_float( ecl_file_iget_named_kw( rft , TIME_KW , 0 ) , 0); - - - /* Cell information */ - { - const int * i = ecl_kw_get_int_ptr( conipos ); - const int * j = ecl_kw_get_int_ptr( conjpos ); - const int * k = ecl_kw_get_int_ptr( conkpos ); - const float * depth = ecl_kw_get_float_ptr( depth_kw ); + if (ecl_file_has_kw( rft , CONLENST_KW)) + rft_node->MSW = true; + else + rft_node->MSW = false; - - /* The ECLIPSE file has offset-1 coordinates, and that is - currently what we store; What a fxxxing mess. */ - int c; - for (c = 0; c < rft_node->size; c++) { - rft_node->cells[c].i = i[c]; - rft_node->cells[c].j = j[c]; - rft_node->cells[c].k = k[c]; - rft_node->cells[c].depth = depth[c]; - } - - } - - - /* Now we are done with the information which is common to both RFT and PLT. */ - if (rft_node->data_type == RFT) { - const float * SW = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , SWAT_KW , 0)); - const float * SG = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , SGAS_KW , 0)); - const float * P = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , PRESSURE_KW , 0)); - int c; - for (c = 0; c < rft_node->size; c++) { - rft_node->rft_data[c].swat = SW[c]; - rft_node->rft_data[c].sgas = SG[c]; - rft_node->cells[c].pressure = P[c]; - } - } else if (rft_node->data_type == PLT) { - /* For PLT there is quite a lot of extra information which is not yet internalized. */ - const float * WR = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONWRAT_KW , 0)); - const float * GR = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONGRAT_KW , 0)); - const float * OR = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONORAT_KW , 0)); - const float * P = ecl_kw_get_float_ptr( ecl_file_iget_named_kw( rft , CONPRES_KW , 0)); - int c; - for ( c = 0; c < rft_node->size; c++) { - rft_node->plt_data[c].orat = OR[c]; - rft_node->plt_data[c].grat = GR[c]; - rft_node->plt_data[c].wrat = WR[c]; - rft_node->cells[c].pressure = P[c]; - } - } else { - /* Segmnet code - not implemented. */ - } - - /* - Checking if the well is monotone in the z-direction; if it is we can - reasonably safely try some blocking. - */ - { - int i; - double first_delta = rft_node->cells[1].depth - rft_node->cells[0].depth; - rft_node->__vertical_well = true; - for (i = 1; i < (rft_node->size - 1); i++) { - double delta = rft_node->cells[i+1].depth - rft_node->cells[i].depth; - if (fabs(delta) > 0) { - if (first_delta * delta < 0) - rft_node->__vertical_well = false; - } - } - } + ecl_rft_node_init_cells( rft_node , rft ); } return rft_node; } - + const char * ecl_rft_node_get_well_name(const ecl_rft_node_type * rft_node) { return rft_node->well_name; } void ecl_rft_node_free(ecl_rft_node_type * rft_node) { + free(rft_node->well_name); - free(rft_node->cells); - util_safe_free(rft_node->segment_data); - util_safe_free(rft_node->rft_data); - util_safe_free(rft_node->plt_data); + vector_free( rft_node->cells ); + if (rft_node->sort_perm) + int_vector_free( rft_node->sort_perm ); + free(rft_node); } @@ -295,247 +260,10 @@ void ecl_rft_node_free__(void * void_node) { -void ecl_rft_node_summarize(const ecl_rft_node_type * rft_node , bool print_cells) { - int i; - printf("--------------------------------------------------------------\n"); - printf("Well.............: %s \n",rft_node->well_name); - printf("Completed cells..: %d \n",rft_node->size); - printf("Vertical well....: %d \n",rft_node->__vertical_well); - { - int day , month , year; - util_set_date_values(rft_node->recording_date , &day , &month , &year); - printf("Recording date...: %02d/%02d/%4d / %g days after simulation start.\n" , day , month , year , rft_node->days); - } - printf("-----------------------------------------\n"); - if (print_cells) { - printf(" i j k Depth Pressure\n"); - printf("-----------------------------------------\n"); - for (i=0; i < rft_node->size; i++) - printf("%2d: %3d %3d %3d | %10.2f %10.2f \n",i, - rft_node->cells[i].i , - rft_node->cells[i].j , - rft_node->cells[i].k , - rft_node->cells[i].depth, - rft_node->cells[i].pressure); - printf("-----------------------------------------\n"); - } -} -/* - For this function to work the ECLIPSE keyword COMPORD must be used. -*/ -void ecl_rft_node_block(const ecl_rft_node_type * rft_node , double epsilon , int size , const double * tvd , int * i, int * j , int *k) { - int rft_index , tvd_index; - int last_rft_index = 0; - bool * blocked = util_calloc(rft_node->size , sizeof * blocked); - - if (!rft_node->__vertical_well) { - fprintf(stderr,"**************************************************************************\n"); - fprintf(stderr,"** WARNING: Trying to block horizontal well: %s from only tvd, this **\n", ecl_rft_node_get_well_name(rft_node)); - fprintf(stderr,"** is extremely error prone - blocking should be carefully checked. **\n"); - fprintf(stderr,"**************************************************************************\n"); - } - ecl_rft_node_summarize(rft_node , true); - for (tvd_index = 0; tvd_index < size; tvd_index++) { - double min_diff = 100000; - int min_diff_index = 0; - if (rft_node->__vertical_well) { - for (rft_index = last_rft_index; rft_index < rft_node->size; rft_index++) { - double diff = fabs(tvd[tvd_index] - rft_node->cells[rft_index].depth); - if (diff < min_diff) { - min_diff = diff; - min_diff_index = rft_index; - } - } - } else { - for (rft_index = last_rft_index; rft_index < (rft_node->size - 1); rft_index++) { - int next_rft_index = rft_index + 1; - if ((rft_node->cells[next_rft_index].depth - tvd[tvd_index]) * (tvd[tvd_index] - rft_node->cells[rft_index].depth) > 0) { - /* - We have bracketing ... !! - */ - min_diff_index = rft_index; - min_diff = 0; - printf("Bracketing: %g | %g | %g \n",rft_node->cells[next_rft_index].depth , - tvd[tvd_index] , rft_node->cells[rft_index].depth); - break; - } - } - } - - if (min_diff < epsilon) { - i[tvd_index] = rft_node->cells[min_diff_index].i; - j[tvd_index] = rft_node->cells[min_diff_index].j; - k[tvd_index] = rft_node->cells[min_diff_index].k; - - blocked[min_diff_index] = true; - last_rft_index = min_diff_index; - } else { - i[tvd_index] = -1; - j[tvd_index] = -1; - k[tvd_index] = -1; - fprintf(stderr,"%s: Warning: True Vertical Depth:%g (Point:%d/%d) could not be mapped to well_path for well:%s \n",__func__ , tvd[tvd_index] , tvd_index+1 , size , rft_node->well_name); - } - } - free(blocked); -} - - - -/* - Faen - dette er jeg egentlig *ikke* interessert i .... -*/ -static double * ecl_rft_node_alloc_well_md(const ecl_rft_node_type * rft_node , int fixed_index , double md_offset) { - double * md = util_calloc(rft_node->size , sizeof * md ); - - - - return md; -} - - -void ecl_rft_node_block_static(const ecl_rft_node_type * rft_node , int rft_index_offset , int md_size , int md_index_offset , const double * md , int * i , int * j , int * k) { - const double md_offset = md[md_index_offset]; - double *well_md = ecl_rft_node_alloc_well_md(rft_node , rft_index_offset , md_offset); - int index; - for (index = 0; index < md_size; index++) { - i[index] = -1; - j[index] = -1; - k[index] = -1; - } - i[md_index_offset] = rft_node->cells[rft_index_offset].i; - j[md_index_offset] = rft_node->cells[rft_index_offset].j; - k[md_index_offset] = rft_node->cells[rft_index_offset].k; - - - free(well_md); -} - - - - -void ecl_rft_node_block2(const ecl_rft_node_type * rft_node , int tvd_size , const double * md , const double * tvd , int * i, int * j , int *k) { - const double epsilon = 1.0; - int rft_index ; - - ecl_rft_node_summarize(rft_node , true); - { - double min_diff = 100000; - int min_diff_index = 0; - int tvd_index = 0; - double local_tvd_peak = 99999999; - { - int index; - for (index = 1; index < (tvd_size - 1); index++) - if (tvd[index] < tvd[index+1] && tvd[index] < tvd[index-1]) - local_tvd_peak = util_double_min(tvd[index] , local_tvd_peak); - } - - - while (min_diff > epsilon) { - for (rft_index = 0; rft_index < rft_node->size; rft_index++) { - double diff = fabs(tvd[tvd_index] - rft_node->cells[rft_index].depth); - if (diff < min_diff) { - min_diff = diff; - min_diff_index = rft_index; - } - } - if (min_diff > epsilon) { - tvd_index++; - if (tvd_index == tvd_size) { - fprintf(stderr,"%s: could not map tvd:%g to well-path depth - aborting \n",__func__ , tvd[tvd_index]); - abort(); - } - - if (tvd[tvd_index] > local_tvd_peak) { - fprintf(stderr,"%s: could not determine offset before well path becomes multivalued - aborting\n",__func__); - abort(); - } - } - } - ecl_rft_node_block_static(rft_node , min_diff_index , tvd_size , tvd_index , md , i , j , k); - } -} - - - - - -void ecl_rft_node_fprintf_rft_obs(const ecl_rft_node_type * rft_node , double epsilon , const char * tvd_file , const char * target_file , double p_std) { - FILE * input_stream = util_fopen(tvd_file , "r" ); - int size = util_count_file_lines(input_stream); - double *p = util_calloc(size , sizeof * p ); - double *tvd = util_calloc(size , sizeof * tvd ); - double *md = util_calloc(size , sizeof * md ); - int *i = util_calloc(size , sizeof * i); - int *j = util_calloc(size , sizeof * j); - int *k = util_calloc(size , sizeof * k); - - { - double *arg1 , *arg2; - int line; - arg1 = p; - arg2 = tvd; - for (line = 0; line < size; line++) - if (fscanf(input_stream , "%lg %lg", &arg1[line] , &arg2[line]) != 2) { - fprintf(stderr,"%s: something wrong when reading: %s - aborting \n",__func__ , tvd_file); - abort(); - } - } - fclose(input_stream); - ecl_rft_node_block(rft_node , epsilon , size , tvd , i , j , k); - - { - int active_lines = 0; - int line; - for (line = 0; line < size; line++) - if (i[line] != -1) - active_lines++; - - if (active_lines > 0) { - FILE * output_stream = util_fopen(target_file , "w" ); - fprintf(output_stream,"%d\n" , active_lines); - for (line = 0; line < size; line++) - if (i[line] != -1) - fprintf(output_stream , "%3d %3d %3d %g %g\n",i[line] , j[line] , k[line] , p[line] , p_std); - fclose(output_stream); - } else - fprintf(stderr,"%s: Warning found no active cells when blocking well:%s to data_file:%s \n",__func__ , rft_node->well_name , tvd_file); - } - - free(md); - free(p); - free(tvd); - free(i); - free(j); - free(k); -} - - -void ecl_rft_node_export_DEPTH(const ecl_rft_node_type * rft_node , const char * path) { - FILE * stream; - char * full; - char * filename = util_alloc_string_copy(ecl_rft_node_get_well_name(rft_node)); - int i; - - filename = util_strcat_realloc(filename , ".DEPTH"); - full = util_alloc_filename(path , filename , NULL); - - stream = fopen(full , "w"); - for (i=0; i < rft_node->size; i++) - fprintf(stream , "%d %g \n",i , rft_node->cells[i].depth); - fclose(stream); - - /* - free(full); - free(filename); - */ -} - - -int ecl_rft_node_get_size(const ecl_rft_node_type * rft_node) { return rft_node->size; } +int ecl_rft_node_get_size(const ecl_rft_node_type * rft_node) { return vector_get_size( rft_node->cells ); } time_t ecl_rft_node_get_date(const ecl_rft_node_type * rft_node) { return rft_node->recording_date; } ecl_rft_enum ecl_rft_node_get_type(const ecl_rft_node_type * rft_node) { return rft_node->data_type; } @@ -543,65 +271,87 @@ ecl_rft_enum ecl_rft_node_get_type(const ecl_rft_node_type * rft_node) { return /*****************************************************************/ /* various functions to access properties at the cell level */ -static cell_type * ecl_rft_node_iget_cell( const ecl_rft_node_type * rft_node , int index) { - if (index < rft_node->size) - return &rft_node->cells[index]; +const ecl_rft_cell_type * ecl_rft_node_iget_cell( const ecl_rft_node_type * rft_node , int index) { + return vector_iget_const( rft_node->cells , index ); +} + + +static void ecl_rft_node_create_sort_perm( ecl_rft_node_type * rft_node ) { + if (rft_node->sort_perm) + int_vector_free( rft_node->sort_perm ); + + rft_node->sort_perm = vector_alloc_sort_perm( rft_node->cells , ecl_rft_cell_cmp__ ); + rft_node->sort_perm_in_sync = true; +} + +void ecl_rft_node_inplace_sort_cells( ecl_rft_node_type * rft_node ) { + vector_sort( rft_node->cells , ecl_rft_cell_cmp__ ); + rft_node->sort_perm_in_sync = false; // The permutation is no longer sorted; however the vector itself is sorted .... +} + +const ecl_rft_cell_type * ecl_rft_node_iget_cell_sorted( ecl_rft_node_type * rft_node , int index) { + if (ecl_rft_node_is_RFT( rft_node )) + return ecl_rft_node_iget_cell( rft_node , index ); else { - util_abort("%s: asked for cell:%d max:%d \n",__func__ , index , rft_node->size - 1); - return NULL; + if (!rft_node->sort_perm_in_sync) + ecl_rft_node_create_sort_perm( rft_node ); + + return vector_iget_const( rft_node->cells , int_vector_iget( rft_node->sort_perm , index )); } } double ecl_rft_node_iget_depth( const ecl_rft_node_type * rft_node , int index) { - const cell_type * cell = ecl_rft_node_iget_cell( rft_node , index ); - return cell->depth; + const ecl_rft_cell_type * cell = ecl_rft_node_iget_cell( rft_node , index ); + return ecl_rft_cell_get_depth( cell ); } double ecl_rft_node_iget_pressure( const ecl_rft_node_type * rft_node , int index) { - const cell_type * cell = ecl_rft_node_iget_cell( rft_node , index ); - return cell->pressure; + const ecl_rft_cell_type * cell = ecl_rft_node_iget_cell( rft_node , index ); + return ecl_rft_cell_get_pressure( cell ); } void ecl_rft_node_iget_ijk( const ecl_rft_node_type * rft_node , int index , int *i , int *j , int *k) { - const cell_type * cell = ecl_rft_node_iget_cell( rft_node , index ); - *i = cell->i; - *j = cell->j; - *k = cell->k; + const ecl_rft_cell_type * cell = ecl_rft_node_iget_cell( rft_node , index ); + + ecl_rft_cell_get_ijk( cell , i,j,k); } -int ecl_rft_node_lookup_ijk( const ecl_rft_node_type * rft_node , int i, int j , int k) { +const ecl_rft_cell_type * ecl_rft_node_lookup_ijk( const ecl_rft_node_type * rft_node , int i, int j , int k) { int index = 0; + int size = ecl_rft_node_get_size( rft_node ); while (true) { - const cell_type * cell = ecl_rft_node_iget_cell( rft_node , index ); - if ((cell->i == (i+1)) && (cell->j == (j+1)) && (cell->k == (k+1))) /* OK - found it. */ - return index; + const ecl_rft_cell_type * cell = ecl_rft_node_iget_cell( rft_node , index ); + + if (ecl_rft_cell_ijk_equal( cell , i , j , k )) + return cell; index++; - if (index == rft_node->size) /* Could not find it. */ - return -1; + if (index == size) /* Could not find it. */ + return NULL; } } + static void assert_type_and_index( const ecl_rft_node_type * rft_node , ecl_rft_enum target_type , int index) { if (rft_node->data_type != target_type) util_abort("%s: wrong type \n",__func__); - if ((index < 0) || (index >= rft_node->size)) + if ((index < 0) || (index >= vector_get_size( rft_node->cells ))) util_abort("%s: invalid index:%d \n",__func__ , index); } double ecl_rft_node_iget_sgas( const ecl_rft_node_type * rft_node , int index) { assert_type_and_index( rft_node , RFT , index ); { - const rft_data_type rft_data = rft_node->rft_data[ index ]; - return rft_data.sgas; + const ecl_rft_cell_type * cell = vector_iget_const( rft_node->cells , index ); + return ecl_rft_cell_get_sgas( cell ); } } @@ -609,17 +359,28 @@ double ecl_rft_node_iget_sgas( const ecl_rft_node_type * rft_node , int index) { double ecl_rft_node_iget_swat( const ecl_rft_node_type * rft_node , int index) { assert_type_and_index( rft_node , RFT , index ); { - const rft_data_type rft_data = rft_node->rft_data[ index ]; - return rft_data.swat; + const ecl_rft_cell_type * cell = vector_iget_const( rft_node->cells , index ); + return ecl_rft_cell_get_swat( cell ); } } +double ecl_rft_node_iget_soil( const ecl_rft_node_type * rft_node , int index) { + assert_type_and_index( rft_node , RFT , index ); + { + const ecl_rft_cell_type * cell = vector_iget_const( rft_node->cells , index ); + return ecl_rft_cell_get_soil( cell ); + } +} + +/*****************************************************************/ + + double ecl_rft_node_iget_orat( const ecl_rft_node_type * rft_node , int index) { assert_type_and_index( rft_node , PLT , index ); { - const plt_data_type plt_data = rft_node->plt_data[ index ]; - return plt_data.orat; + const ecl_rft_cell_type * cell = vector_iget_const( rft_node->cells , index ); + return ecl_rft_cell_get_orat( cell ); } } @@ -627,8 +388,8 @@ double ecl_rft_node_iget_orat( const ecl_rft_node_type * rft_node , int index) { double ecl_rft_node_iget_wrat( const ecl_rft_node_type * rft_node , int index) { assert_type_and_index( rft_node , PLT , index ); { - const plt_data_type plt_data = rft_node->plt_data[ index ]; - return plt_data.wrat; + const ecl_rft_cell_type * cell = vector_iget_const( rft_node->cells , index); + return ecl_rft_cell_get_wrat( cell ); } } @@ -636,8 +397,36 @@ double ecl_rft_node_iget_wrat( const ecl_rft_node_type * rft_node , int index) { double ecl_rft_node_iget_grat( const ecl_rft_node_type * rft_node , int index) { assert_type_and_index( rft_node , PLT , index ); { - const plt_data_type plt_data = rft_node->plt_data[ index ]; - return plt_data.grat; + const ecl_rft_cell_type * cell = vector_iget_const( rft_node->cells , index); + return ecl_rft_cell_get_grat( cell ); } } + +bool ecl_rft_node_is_MSW( const ecl_rft_node_type * rft_node ) { + return rft_node->MSW; +} + + +bool ecl_rft_node_is_PLT( const ecl_rft_node_type * rft_node ) { + if (rft_node->data_type == PLT) + return true; + else + return false; +} + +bool ecl_rft_node_is_SEGMENT( const ecl_rft_node_type * rft_node ) { + if (rft_node->data_type == SEGMENT) + return true; + else + return false; +} + +bool ecl_rft_node_is_RFT( const ecl_rft_node_type * rft_node ) { + if (rft_node->data_type == RFT) + return true; + else + return false; +} + + diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_rsthead.c b/ThirdParty/Ert/devel/libecl/src/ecl_rsthead.c index 05995747cc..b0baf402ed 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_rsthead.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_rsthead.c @@ -71,6 +71,7 @@ ecl_rsthead_type * ecl_rsthead_ialloc( const ecl_file_type * rst_file , int occu rsthead->nisegz = data[INTEHEAD_NISEGZ_INDEX]; rsthead->nsegmx = data[INTEHEAD_NSEGMX_INDEX]; rsthead->nswlmx = data[INTEHEAD_NSWLMX_INDEX]; + rsthead->nrsegz = data[INTEHEAD_NRSEGZ_INDEX]; // The only derived quantity rsthead->sim_time = rsthead_date( rsthead->day , rsthead->month , rsthead->year ); diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_smspec.c b/ThirdParty/Ert/devel/libecl/src/ecl_smspec.c index 3201750c50..1519207f3f 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_smspec.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_smspec.c @@ -485,6 +485,7 @@ static ecl_smspec_var_type ecl_smspec_identify_special_var( const char * var ) { ecl_smspec_var_type ecl_smspec_identify_var_type(const char * var) { ecl_smspec_var_type var_type = ecl_smspec_identify_special_var( var ); + int str_length = strlen(var); if (var_type == ECL_SMSPEC_INVALID_VAR) { switch(var[0]) { case('A'): @@ -521,10 +522,13 @@ ecl_smspec_var_type ecl_smspec_identify_var_type(const char * var) { var_type = ECL_SMSPEC_NETWORK_VAR; break; case('R'): - if (var[2] == 'F') - var_type = ECL_SMSPEC_REGION_2_REGION_VAR; - else + if (((3 == str_length) && var[2] == 'F') || + ((4 == str_length) && var[3] == 'F')) { + var_type = ECL_SMSPEC_REGION_2_REGION_VAR; + } + else { var_type = ECL_SMSPEC_REGION_VAR; + } break; case('S'): var_type = ECL_SMSPEC_SEGMENT_VAR; @@ -649,7 +653,7 @@ static void ecl_smspec_install_gen_keys( ecl_smspec_type * smspec , smspec_node_ hash_insert_ref(smspec->gen_var_index , gen_key1 , smspec_node); } - /* Insert the (optional) extra mapping for block related variables: */ + /* Insert the (optional) extra mapping for block related variables and region_2_region variables: */ { const char * gen_key2 = smspec_node_get_gen_key2( smspec_node ); if (gen_key2 != NULL) @@ -751,6 +755,8 @@ static void ecl_smspec_install_special_keys( ecl_smspec_type * ecl_smspec , smsp break; case(ECL_SMSPEC_SEGMENT_VAR): break; + case(ECL_SMSPEC_REGION_2_REGION_VAR): + break; default: util_abort("%: Internal error - should never be here ?? \n",__func__); break; @@ -778,6 +784,9 @@ bool ecl_smspec_needs_wgname( ecl_smspec_var_type var_type ) { case(ECL_SMSPEC_REGION_VAR): return false; break; + case(ECL_SMSPEC_REGION_2_REGION_VAR): + return false; + break; case(ECL_SMSPEC_MISC_VAR): return false; break; @@ -821,6 +830,9 @@ bool ecl_smspec_needs_num( ecl_smspec_var_type var_type ) { case(ECL_SMSPEC_REGION_VAR): return true; break; + case(ECL_SMSPEC_REGION_2_REGION_VAR): + return true; + break; case(ECL_SMSPEC_MISC_VAR): return false; break; diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_sum.c b/ThirdParty/Ert/devel/libecl/src/ecl_sum.c index f07e1de355..126b81def6 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_sum.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_sum.c @@ -333,6 +333,7 @@ void ecl_sum_free( ecl_sum_type * ecl_sum ) { util_safe_free( ecl_sum->path ); util_safe_free( ecl_sum->ext ); + util_safe_free( ecl_sum->abs_path ); free( ecl_sum->base ); free( ecl_sum->ecl_case ); @@ -882,8 +883,6 @@ void ecl_sum_fmt_init_summary_x( ecl_sum_fmt_type * fmt ) { #define DATE_STRING_LENGTH 128 static void __ecl_sum_fprintf_line( const ecl_sum_type * ecl_sum , FILE * stream , int internal_index , const bool_vector_type * has_var , const int_vector_type * var_index , char * date_string , const ecl_sum_fmt_type * fmt) { - int ivar , day,month,year; - util_set_date_values(ecl_sum_iget_sim_time(ecl_sum , internal_index ) , &day , &month, &year); fprintf(stream , fmt->days_fmt , ecl_sum_iget_sim_days(ecl_sum , internal_index)); fprintf(stream , fmt->sep ); @@ -895,12 +894,15 @@ static void __ecl_sum_fprintf_line( const ecl_sum_type * ecl_sum , FILE * stream fprintf(stream , date_string ); } - for (ivar = 0; ivar < int_vector_size( var_index ); ivar++) { - if (bool_vector_iget( has_var , ivar )) { - fprintf(stream , fmt->sep); - fprintf(stream , fmt->value_fmt , ecl_sum_iget(ecl_sum , internal_index, int_vector_iget( var_index , ivar ))); + { + int ivar; + for (ivar = 0; ivar < int_vector_size( var_index ); ivar++) { + if (bool_vector_iget( has_var , ivar )) { + fprintf(stream , fmt->sep); + fprintf(stream , fmt->value_fmt , ecl_sum_iget(ecl_sum , internal_index, int_vector_iget( var_index , ivar ))); + } } - } + } fprintf(stream , fmt->newline); } @@ -980,6 +982,7 @@ void ecl_sum_fprintf(const ecl_sum_type * ecl_sum , FILE * stream , const string bool_vector_free( has_var ); if (current_locale != NULL) setlocale( LC_NUMERIC , current_locale); + free( date_string ); } #undef DATE_STRING_LENGTH @@ -1163,8 +1166,37 @@ char * ecl_sum_alloc_well_key( const ecl_sum_type * ecl_sum , const char * keywo +bool ecl_sum_is_oil_producer( const ecl_sum_type * ecl_sum , const char * well) { + const char * WOPT_KEY = "WOPT"; + bool oil_producer = false; + + if (ecl_sum_has_well_var( ecl_sum , well , WOPT_KEY)) { + int last_step = ecl_sum_get_data_length( ecl_sum ) - 1; + double wopt = ecl_sum_get_well_var( ecl_sum , last_step , well , WOPT_KEY); + + if (wopt > 0) + oil_producer = true; + } + + return oil_producer; +} +bool ecl_sum_report_step_equal( const ecl_sum_type * ecl_sum1 , const ecl_sum_type * ecl_sum2) { + if (ecl_sum1 == ecl_sum2) + return true; + else + return ecl_sum_data_report_step_equal( ecl_sum1->data , ecl_sum2->data ); +} + + +bool ecl_sum_report_step_compatible( const ecl_sum_type * ecl_sum1 , const ecl_sum_type * ecl_sum2) { + if (ecl_sum1 == ecl_sum2) + return true; + else + return ecl_sum_data_report_step_compatible( ecl_sum1->data , ecl_sum2->data ); +} + diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_sum_data.c b/ThirdParty/Ert/devel/libecl/src/ecl_sum_data.c index 09d4e684cc..73b1e87a1c 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_sum_data.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_sum_data.c @@ -204,7 +204,7 @@ - +#define INVALID_MINISTEP_NR -1 struct ecl_sum_data_struct { @@ -255,8 +255,8 @@ static void ecl_sum_data_clear_index( ecl_sum_data_type * data ) { data->last_report_step = -1024 * 1024; data->days_start = 0; data->sim_length = -1; - data->first_ministep = -1; - data->last_ministep = -1; + data->first_ministep = INVALID_MINISTEP_NR; + data->last_ministep = INVALID_MINISTEP_NR; data->index_valid = false; time_interval_reopen( data->sim_time ); } @@ -268,8 +268,8 @@ ecl_sum_data_type * ecl_sum_data_alloc(ecl_smspec_type * smspec) { data->smspec = smspec; data->__min_time = 0; - data->report_first_index = int_vector_alloc( 0 , -1 ); /* This -1 value is hard-wired around in the place - not good. */ - data->report_last_index = int_vector_alloc( 0 , -1 ); + data->report_first_index = int_vector_alloc( 0 , INVALID_MINISTEP_NR ); + data->report_last_index = int_vector_alloc( 0 , INVALID_MINISTEP_NR ); data->sim_time = time_interval_alloc_open(); ecl_sum_data_clear_index( data ); @@ -545,7 +545,7 @@ static int ecl_sum_data_get_index_from_sim_time( const ecl_sum_data_type * data { int low_index = 0; int high_index = vector_get_size( data->data ); - int internal_index = -1; + int internal_index = INVALID_MINISTEP_NR; while (internal_index < 0) { @@ -1043,7 +1043,7 @@ bool ecl_sum_data_has_report_step(const ecl_sum_data_type * data , int report_st /** Returns the last index included in report step @report_step. Observe that if the dataset does not include @report_step at all, - the function will return -1; this must be checked for in the + the function will return INVALID_MINISTEP_NR; this must be checked for in the calling scope. */ @@ -1056,7 +1056,7 @@ int ecl_sum_data_iget_report_end( const ecl_sum_data_type * data , int report_st /** Returns the first index included in report step @report_step. Observe that if the dataset does not include @report_step at all, - the function will return -1; this must be checked for in the + the function will return INVALID_MINISTEP_NR; this must be checked for in the calling scope. */ @@ -1349,3 +1349,52 @@ int ecl_sum_data_get_length( const ecl_sum_data_type * data ) { return vector_get_size( data->data ); } + +bool ecl_sum_data_report_step_equal( const ecl_sum_data_type * data1 , const ecl_sum_data_type * data2) { + bool equal = true; + if (int_vector_size( data1->report_last_index ) == int_vector_size(data2->report_last_index)) { + int i; + for (i = 0; i < int_vector_size( data1->report_last_index ); i++) { + int time_index1 = int_vector_iget( data1->report_last_index , i ); + int time_index2 = int_vector_iget( data2->report_last_index , i ); + + if ((time_index1 != INVALID_MINISTEP_NR) && (time_index2 != INVALID_MINISTEP_NR)) { + const ecl_sum_tstep_type * ministep1 = ecl_sum_data_iget_ministep( data1 , time_index1 ); + const ecl_sum_tstep_type * ministep2 = ecl_sum_data_iget_ministep( data2 , time_index2 ); + + if (!ecl_sum_tstep_sim_time_equal( ministep1 , ministep2)) { + equal = false; + break; + } + } else if (time_index1 != time_index2) { + equal = false; + break; + } + } + } else + equal = false; + + return equal; +} + + +bool ecl_sum_data_report_step_compatible( const ecl_sum_data_type * data1 , const ecl_sum_data_type * data2) { + bool compatible = true; + int min_size = util_int_min( int_vector_size( data1->report_last_index ) , int_vector_size( data2->report_last_index)); + int i; + for (i = 0; i < min_size; i++) { + int time_index1 = int_vector_iget( data1->report_last_index , i ); + int time_index2 = int_vector_iget( data2->report_last_index , i ); + + if ((time_index1 != INVALID_MINISTEP_NR) && (time_index2 != INVALID_MINISTEP_NR)) { + const ecl_sum_tstep_type * ministep1 = ecl_sum_data_iget_ministep( data1 , time_index1 ); + const ecl_sum_tstep_type * ministep2 = ecl_sum_data_iget_ministep( data2 , time_index2 ); + + if (!ecl_sum_tstep_sim_time_equal( ministep1 , ministep2)) { + compatible = false; + break; + } + } + } + return compatible; +} diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_sum_tstep.c b/ThirdParty/Ert/devel/libecl/src/ecl_sum_tstep.c index 49dab11754..e982a24106 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_sum_tstep.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_sum_tstep.c @@ -289,3 +289,10 @@ void ecl_sum_tstep_set_from_key( ecl_sum_tstep_type * tstep , const char * gen_k } +bool ecl_sum_tstep_sim_time_equal( const ecl_sum_tstep_type * tstep1 , const ecl_sum_tstep_type * tstep2 ) { + if (tstep1->sim_time == tstep2->sim_time) + return true; + else + return false; +} + diff --git a/ThirdParty/Ert/devel/libecl/src/ecl_util.c b/ThirdParty/Ert/devel/libecl/src/ecl_util.c index 92f3dde9c5..f28fb9abce 100644 --- a/ThirdParty/Ert/devel/libecl/src/ecl_util.c +++ b/ThirdParty/Ert/devel/libecl/src/ecl_util.c @@ -1215,16 +1215,16 @@ time_t ecl_util_get_start_date(const char * data_file) { util_abort("%s: sorry - could not find START in DATA file %s \n",__func__ , data_file); { - long int start_pos = ftell( stream ); + long int start_pos = util_ftell( stream ); int buffer_size; /* Look for terminating '/' */ if (!parser_fseek_string( parser , stream , "/" , false , true)) util_abort("%s: sorry - could not find \"/\" termination of START keyword in data_file: \n",__func__ , data_file); - buffer_size = (ftell(stream) - start_pos) ; + buffer_size = (util_ftell(stream) - start_pos) ; buffer = util_calloc( buffer_size + 1 , sizeof * buffer ); - fseek( stream , start_pos , SEEK_SET); + util_fseek( stream , start_pos , SEEK_SET); util_fread( buffer , sizeof * buffer , buffer_size ,stream , __func__); buffer[buffer_size] = '\0'; } @@ -1257,16 +1257,16 @@ int ecl_util_get_num_cpu(const char * data_file) { char * buffer; if (parser_fseek_string( parser , stream , "PARALLEL" , true , true)) { /* Seeks case insensitive. */ - long int start_pos = ftell( stream ); + long int start_pos = util_ftell( stream ); int buffer_size; /* Look for terminating '/' */ if (!parser_fseek_string( parser , stream , "/" , false , true)) util_abort("%s: sorry - could not find \"/\" termination of PARALLEL keyword in data_file: \n",__func__ , data_file); - buffer_size = (ftell(stream) - start_pos) ; + buffer_size = (util_ftell(stream) - start_pos) ; buffer = util_calloc( buffer_size + 1 , sizeof * buffer ); - fseek( stream , start_pos , SEEK_SET); + util_fseek( stream , start_pos , SEEK_SET); util_fread( buffer , sizeof * buffer , buffer_size ,stream , __func__); buffer[buffer_size] = '\0'; @@ -1277,14 +1277,15 @@ int ecl_util_get_num_cpu(const char * data_file) { for (i=0; i < stringlist_get_size( tokens ); i++) { item = util_realloc_string_copy( item , stringlist_iget( tokens , i )); util_strupr( item ); - if ( util_string_equal( item , "DISTRIBUTED" )) { + if (( util_string_equal( item , "DISTRIBUTED" )) || + ( util_string_equal( item , "DIST" ))) { num_cpu = atoi( stringlist_iget( tokens , i - 1)); break; } } free( item ); stringlist_free( tokens ); - } + } free( buffer ); } diff --git a/ThirdParty/Ert/devel/libecl/src/fortio.c b/ThirdParty/Ert/devel/libecl/src/fortio.c index cece604fbd..fd27c6ca71 100644 --- a/ThirdParty/Ert/devel/libecl/src/fortio.c +++ b/ThirdParty/Ert/devel/libecl/src/fortio.c @@ -119,7 +119,7 @@ static bool __read_int(FILE * stream , int * value, bool endian_flip) { static bool fortio_is_fortran_stream__(FILE * stream , bool endian_flip) { const bool strict_checking = true; /* True: requires that *ALL* records in the file are fortran formatted */ - long init_pos = ftell(stream); + offset_type init_pos = util_ftell(stream); bool is_fortran_stream = false; int header , tail; bool cont; @@ -128,7 +128,7 @@ static bool fortio_is_fortran_stream__(FILE * stream , bool endian_flip) { cont = false; if (__read_int(stream , &header , endian_flip)) { if (header >= 0) { - if (fseek(stream , header , SEEK_CUR) == 0) { + if (util_fseek(stream , (offset_type) header , SEEK_CUR) == 0) { if (__read_int(stream , &tail , endian_flip)) { cont = true; /* @@ -155,7 +155,7 @@ static bool fortio_is_fortran_stream__(FILE * stream , bool endian_flip) { } } } while (cont); - fseek(stream , init_pos , SEEK_SET); + util_fseek(stream , init_pos , SEEK_SET); return is_fortran_stream; } @@ -423,7 +423,7 @@ void fortio_fclose(fortio_type *fortio) { bool fortio_is_fortio_file(fortio_type * fortio) { FILE * stream = fortio->stream; - int init_pos = ftell(stream); + offset_type init_pos = fortio_ftell(fortio); int elm_read; bool is_fortio_file = false; elm_read = fread(&fortio->active_header , sizeof(fortio->active_header) , 1 , fortio->stream); @@ -433,7 +433,7 @@ bool fortio_is_fortio_file(fortio_type * fortio) { if (fortio->endian_flip_header) util_endian_flip_vector(&fortio->active_header , sizeof fortio->active_header , 1); - if (fseek(stream , fortio->active_header , SEEK_CUR) == 0) { + if (fortio_fseek(fortio , (offset_type) fortio->active_header , SEEK_CUR) == 0) { if (fread(&trailer , sizeof(fortio->active_header) , 1 , fortio->stream) == 1) { if (fortio->endian_flip_header) util_endian_flip_vector(&trailer , sizeof trailer , 1); @@ -444,7 +444,7 @@ bool fortio_is_fortio_file(fortio_type * fortio) { } } - fseek(stream , init_pos , SEEK_SET); + fortio_fseek(fortio , init_pos , SEEK_SET); return is_fortio_file; } @@ -527,7 +527,7 @@ void fortio_fread_buffer(fortio_type * fortio, char * buffer , int buffer_size) int fortio_fskip_record(fortio_type *fortio) { int record_size = fortio_init_read(fortio); - fseek(fortio->stream , record_size , SEEK_CUR); + fortio_fseek(fortio , (offset_type) record_size , SEEK_CUR); fortio_complete_read(fortio); return record_size; } @@ -624,7 +624,7 @@ static fortio_status_type fortio_check_record( FILE * stream , bool endian_flip if (endian_flip) util_endian_flip_vector(&header , sizeof header , 1); - if (fseek( stream , header , SEEK_CUR ) != 0) + if (util_fseek( stream , (offset_type) header , SEEK_CUR ) != 0) /* The fseek() failed - i.e. the data section was not sufficiently long. */ status = FORTIO_MISSING_DATA; else { @@ -697,13 +697,13 @@ fortio_status_type fortio_check_file( const char * filename , bool endian_flip) } -long fortio_ftell( const fortio_type * fortio ) { - return ftell( fortio->stream ); +offset_type fortio_ftell( const fortio_type * fortio ) { + return util_ftell( fortio->stream ); } -int fortio_fseek( fortio_type * fortio , long offset , int whence) { - int fseek_return = fseek( fortio->stream , offset , whence ); +int fortio_fseek( fortio_type * fortio , offset_type offset , int whence) { + int fseek_return = util_fseek( fortio->stream , offset , whence ); /* if fseek_return != 0 -> util_abort(). */ @@ -723,6 +723,6 @@ FILE * fortio_get_FILE(const fortio_type *fortio) { return fortio- int fortio_get_record_size(const fortio_type *fortio) { return fortio->active_header; } //bool fortio_endian_flip(const fortio_type *fortio) { return fortio->endian_flip_header; } bool fortio_fmt_file(const fortio_type *fortio) { return fortio->fmt_file; } -void fortio_rewind(const fortio_type *fortio) { rewind(fortio->stream); } +void fortio_rewind(const fortio_type *fortio) { util_rewind(fortio->stream); } const char * fortio_filename_ref(const fortio_type * fortio) { return (const char *) fortio->filename; } diff --git a/ThirdParty/Ert/devel/libecl/src/nnc_index_list.c b/ThirdParty/Ert/devel/libecl/src/nnc_index_list.c new file mode 100644 index 0000000000..73c6401924 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/src/nnc_index_list.c @@ -0,0 +1,73 @@ + +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'nnc_index_list.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include + + +#define NNC_INDEX_LIST_TYPE_ID 87225078 + + +struct nnc_index_list_struct { + UTIL_TYPE_ID_DECLARATION; + int_vector_type *index_list; + int lgr_nr; + bool sorted; +}; + + +UTIL_IS_INSTANCE_FUNCTION( nnc_index_list , NNC_INDEX_LIST_TYPE_ID ) + + + +nnc_index_list_type * nnc_index_list_alloc() { + nnc_index_list_type * nnc_index_list = util_malloc( sizeof * nnc_index_list ); + UTIL_TYPE_ID_INIT(nnc_index_list , NNC_INDEX_LIST_TYPE_ID); + nnc_index_list->index_list = int_vector_alloc(0 , 0 ); + nnc_index_list->sorted = true; + return nnc_index_list; +} + + +void nnc_index_list_free( nnc_index_list_type * nnc_index_list ) { + int_vector_free( nnc_index_list->index_list ); + free( nnc_index_list ); +} + + +const int_vector_type * nnc_index_list_get_list( nnc_index_list_type * nnc_index_list) { + if (!nnc_index_list->sorted) + int_vector_select_unique( nnc_index_list->index_list ); + + nnc_index_list->sorted = true; + return nnc_index_list->index_list; +} + + + +void nnc_index_list_add_index( nnc_index_list_type * nnc_index_list , int index) { + nnc_index_list->sorted = false; + int_vector_append( nnc_index_list->index_list , index ); +} diff --git a/ThirdParty/Ert/devel/libecl/src/nnc_info.c b/ThirdParty/Ert/devel/libecl/src/nnc_info.c new file mode 100644 index 0000000000..a6b745cbc6 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/src/nnc_info.c @@ -0,0 +1,128 @@ + +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'nnc_info.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include +#include + +#include +#include + +#define NNC_INFO_TYPE_ID 675415078 + + +struct nnc_info_struct { + UTIL_TYPE_ID_DECLARATION; + vector_type * lgr_list; /*List of int vector * for nnc connections for LGRs*/ + int_vector_type * lgr_index_map; /* A vector that maps LGR-nr to index into the LGR_list.*/ + int lgr_nr; /* The lgr_nr of the cell holding this nnc_info structure. */ +}; + + +UTIL_IS_INSTANCE_FUNCTION( nnc_info , NNC_INFO_TYPE_ID ) + + +nnc_info_type * nnc_info_alloc(int lgr_nr) { + nnc_info_type * nnc_info = util_malloc( sizeof * nnc_info ); + UTIL_TYPE_ID_INIT(nnc_info , NNC_INFO_TYPE_ID); + nnc_info->lgr_list = vector_alloc_new(); + nnc_info->lgr_index_map = int_vector_alloc(0, -1); + nnc_info->lgr_nr = lgr_nr; + return nnc_info; +} + +void nnc_info_free( nnc_info_type * nnc_info ) { + vector_free(nnc_info->lgr_list); + int_vector_free(nnc_info->lgr_index_map); + free (nnc_info); +} + +nnc_vector_type * nnc_info_get_vector( const nnc_info_type * nnc_info , int lgr_nr) { + int lgr_index = int_vector_safe_iget( nnc_info->lgr_index_map , lgr_nr ); + if (-1 == lgr_index) + return NULL; + else + return vector_iget( nnc_info->lgr_list , lgr_index ); +} + + +nnc_vector_type * nnc_info_iget_vector( const nnc_info_type * nnc_info , int lgr_index) { + return vector_iget( nnc_info->lgr_list , lgr_index ); +} + + +nnc_vector_type * nnc_info_get_self_vector( const nnc_info_type * nnc_info ) { + return nnc_info_get_vector( nnc_info , nnc_info->lgr_nr ); +} + + +static void nnc_info_assert_vector( nnc_info_type * nnc_info , int lgr_nr ) { + nnc_vector_type * nnc_vector = nnc_info_get_vector( nnc_info , lgr_nr); + if (!nnc_vector) { + nnc_vector = nnc_vector_alloc( lgr_nr ); + vector_append_owned_ref( nnc_info->lgr_list , nnc_vector , nnc_vector_free__ ); + int_vector_iset( nnc_info->lgr_index_map , lgr_nr , vector_get_size( nnc_info->lgr_list ) - 1 ); + } +} + + + + + +void nnc_info_add_nnc(nnc_info_type * nnc_info, int lgr_nr, int global_cell_number) { + nnc_info_assert_vector( nnc_info , lgr_nr ); + { + nnc_vector_type * nnc_vector = nnc_info_get_vector( nnc_info , lgr_nr ); + nnc_vector_add_nnc( nnc_vector , global_cell_number ); + } +} + + +const int_vector_type * nnc_info_get_index_list(const nnc_info_type * nnc_info, int lgr_nr) { + nnc_vector_type * nnc_vector = nnc_info_get_vector( nnc_info , lgr_nr ); + if (nnc_vector) + return nnc_vector_get_index_list( nnc_vector ); + else + return NULL; +} + + +const int_vector_type * nnc_info_iget_index_list(const nnc_info_type * nnc_info, int lgr_index) { + nnc_vector_type * nnc_vector = nnc_info_iget_vector( nnc_info , lgr_index ); + return nnc_vector_get_index_list( nnc_vector ); +} + + + +const int_vector_type * nnc_info_get_self_index_list(const nnc_info_type * nnc_info) { + return nnc_info_get_index_list( nnc_info , nnc_info->lgr_nr ); +} + + + +int nnc_info_get_lgr_nr( const nnc_info_type * nnc_info ) { + return nnc_info->lgr_nr; +} + + +int nnc_info_get_size( const nnc_info_type * nnc_info ) { + return vector_get_size( nnc_info->lgr_list ); +} diff --git a/ThirdParty/Ert/devel/libecl/src/nnc_vector.c b/ThirdParty/Ert/devel/libecl/src/nnc_vector.c new file mode 100644 index 0000000000..921ada21ab --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/src/nnc_vector.c @@ -0,0 +1,76 @@ + +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'nnc_vector.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include +#include + +#include + + +#define NNC_VECTOR_TYPE_ID 875615078 + + +struct nnc_vector_struct { + UTIL_TYPE_ID_DECLARATION; + int_vector_type *nnc_index_list; + int lgr_nr; +}; + + +UTIL_IS_INSTANCE_FUNCTION( nnc_vector , NNC_VECTOR_TYPE_ID ) +static UTIL_SAFE_CAST_FUNCTION(nnc_vector , NNC_VECTOR_TYPE_ID) + + + +nnc_vector_type * nnc_vector_alloc(int lgr_nr) { + nnc_vector_type * nnc_vector = util_malloc( sizeof * nnc_vector ); + UTIL_TYPE_ID_INIT(nnc_vector , NNC_VECTOR_TYPE_ID); + nnc_vector->nnc_index_list = int_vector_alloc(0, 0); + nnc_vector->lgr_nr = lgr_nr; + return nnc_vector; +} + +void nnc_vector_free( nnc_vector_type * nnc_vector ) { + int_vector_free( nnc_vector->nnc_index_list ); + free( nnc_vector ); +} + + +void nnc_vector_free__(void * arg) { + nnc_vector_type * nnc_vector = nnc_vector_safe_cast( arg ); + nnc_vector_free( nnc_vector ); +} + + +void nnc_vector_add_nnc(nnc_vector_type * nnc_vector, int global_cell_number) { + int_vector_append( nnc_vector->nnc_index_list , global_cell_number ); +} + + +const int_vector_type * nnc_vector_get_index_list(const nnc_vector_type * nnc_vector) { + return nnc_vector->nnc_index_list; +} + + +int nnc_vector_get_lgr_nr( const nnc_vector_type * nnc_vector ) { + return nnc_vector->lgr_nr; +} diff --git a/ThirdParty/Ert/devel/libecl/src/smspec_node.c b/ThirdParty/Ert/devel/libecl/src/smspec_node.c index 20b0f70ce5..1c85b371be 100644 --- a/ThirdParty/Ert/devel/libecl/src/smspec_node.c +++ b/ThirdParty/Ert/devel/libecl/src/smspec_node.c @@ -53,7 +53,7 @@ struct smspec_node_struct { UTIL_TYPE_ID_DECLARATION; char * gen_key1; /* The main composite key, i.e. WWCT:OP3 for this element. */ - char * gen_key2; /* Some of the ijk based elements will have both a xxx:i,j,k and a xxx:num key. Mostly NULL. */ + char * gen_key2; /* Some of the ijk based elements will have both a xxx:i,j,k and a xxx:num key. Some of the region_2_region elements will have both a xxx:num and a xxx:r2-r2 key. Mostly NULL. */ ecl_smspec_var_type var_type; /* The variable type */ char * wgname; /* The value of the WGNAMES vector for this element. */ char * keyword; /* The value of the KEYWORDS vector for this elements. */ @@ -89,6 +89,8 @@ struct smspec_node_struct { #define ECL_SUM_KEYFMT_GROUP "%s%s%s" #define ECL_SUM_KEYFMT_WELL "%s%s%s" #define ECL_SUM_KEYFMT_REGION "%s%s%d" +#define ECL_SUM_KEYFMT_REGION_2_REGION_R1R2 "%s%s%d-%d" +#define ECL_SUM_KEYFMT_REGION_2_REGION_NUM "%s%s%d" #define ECL_SUM_KEYFMT_SEGMENT "%s%s%s%s%d" #define ECL_SUM_KEYFMT_LOCAL_WELL "%s%s%s%s%s" @@ -119,6 +121,23 @@ char * smspec_alloc_region_key( const char * join_string , const char * keyword num ); } +char * smspec_alloc_region_2_region_r1r2_key( const char * join_string , const char * keyword , int r1, int r2) { + return util_alloc_sprintf(ECL_SUM_KEYFMT_REGION_2_REGION_R1R2, + keyword, + join_string, + r1, + r2); +} + +char * smspec_alloc_region_2_region_num_key( const char * join_string , const char * keyword , int num) { + return util_alloc_sprintf(ECL_SUM_KEYFMT_REGION_2_REGION_NUM, + keyword , + join_string , + num); +} + + + char * smspec_alloc_block_ijk_key( const char * join_string , const char * keyword , int i , int j , int k) { return util_alloc_sprintf(ECL_SUM_KEYFMT_BLOCK_IJK , keyword, @@ -308,10 +327,11 @@ static void smspec_node_set_flags( smspec_node_type * smspec_node) { file. */ { - if (smspec_node->var_type == ECL_SMSPEC_COMPLETION_VAR || - smspec_node->var_type == ECL_SMSPEC_SEGMENT_VAR || - smspec_node->var_type == ECL_SMSPEC_REGION_VAR || - smspec_node->var_type == ECL_SMSPEC_BLOCK_VAR || + if (smspec_node->var_type == ECL_SMSPEC_COMPLETION_VAR || + smspec_node->var_type == ECL_SMSPEC_SEGMENT_VAR || + smspec_node->var_type == ECL_SMSPEC_REGION_VAR || + smspec_node->var_type == ECL_SMSPEC_REGION_2_REGION_VAR || + smspec_node->var_type == ECL_SMSPEC_BLOCK_VAR || smspec_node->var_type == ECL_SMSPEC_AQUIFER_VAR) smspec_node->need_nums = true; else @@ -354,7 +374,7 @@ smspec_node_type * smspec_node_alloc_new(int params_index, float default_value) node->keyword = NULL; node->lgr_name = NULL; node->lgr_ijk = NULL; - + smspec_node_set_invalid_flags( node ); return node; // This is NOT usable } @@ -446,9 +466,18 @@ static void smspec_node_set_gen_keys( smspec_node_type * smspec_node , const cha // KEYWORD:NUM smspec_node->gen_key1 = smspec_alloc_region_key( key_join_string , smspec_node->keyword , smspec_node->num); break; - case(ECL_SMSPEC_SEGMENT_VAR): - // KEYWORD:WGNAME:NUM - smspec_node->gen_key1 = smspec_alloc_segment_key( key_join_string , smspec_node->keyword , smspec_node->wgname , smspec_node->num); + case (ECL_SMSPEC_SEGMENT_VAR): + // KEYWORD:WGNAME:NUM + smspec_node->gen_key1 = smspec_alloc_segment_key( key_join_string , smspec_node->keyword , smspec_node->wgname , smspec_node->num); + break; + case(ECL_SMSPEC_REGION_2_REGION_VAR): + // KEYWORDS:RXF:NUM and RXF:R1-R2 + smspec_node->gen_key1 = smspec_alloc_region_2_region_num_key( key_join_string , smspec_node->keyword , smspec_node->num); + { + int r1 = smspec_node->num % 32768; + int r2 = ((smspec_node->num-r1) / 32768)-10; + smspec_node->gen_key2 = smspec_alloc_region_2_region_r1r2_key( key_join_string , smspec_node->keyword , r1, r2); + } break; case(ECL_SMSPEC_MISC_VAR): // KEYWORD @@ -549,7 +578,7 @@ bool smspec_node_init( smspec_node_type * smspec_node, initOK = false; break; case(ECL_SMSPEC_SEGMENT_VAR): - if (wgnameOK) { + if (wgnameOK && num >= 0) { smspec_node_set_wgname( smspec_node , wgname ); smspec_node_set_num( smspec_node , grid_dims , num ); } else @@ -563,6 +592,10 @@ bool smspec_node_init( smspec_node_type * smspec_node, /* Region variable : NUM */ smspec_node_set_num( smspec_node , grid_dims , num ); break; + case(ECL_SMSPEC_REGION_2_REGION_VAR): + /* Region 2 region variable : NUM */ + smspec_node_set_num( smspec_node , grid_dims , num ); + break; case(ECL_SMSPEC_BLOCK_VAR): /* A block variable : NUM*/ smspec_node_set_num( smspec_node , grid_dims , num ); diff --git a/ThirdParty/Ert/devel/libecl/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libecl/tests/CMakeLists.txt index 2236c08c93..402ccc319a 100644 --- a/ThirdParty/Ert/devel/libecl/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl/tests/CMakeLists.txt @@ -1,94 +1,11 @@ -add_executable( ecl_coarse_test ecl_coarse_test.c ) -target_link_libraries( ecl_coarse_test ecl ) -add_test( ecl_coarse_test ${EXECUTABLE_OUTPUT_PATH}/ecl_coarse_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2 ) +if (BUILD_TESTS) + include( tests.cmake ) +endif() +# The ecl_win64 application is not built as a proper test integrated +# into the CTEST system. Should be invoked manually on Windows. +if (ERT_WINDOWS) + add_executable( ecl_lfs ecl_lfs.c ) + target_link_libraries( ecl_lfs ecl ert_util ) +endif() -add_executable( ecl_restart_test ecl_restart_test.c ) -target_link_libraries( ecl_restart_test ecl ) -add_test( ecl_restart_test ${EXECUTABLE_OUTPUT_PATH}/ecl_restart_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ) - - - -add_executable( ecl_lgr_test ecl_lgr_test.c ) -target_link_libraries( ecl_lgr_test ecl ) -add_test( ecl_lgr_test1 ${EXECUTABLE_OUTPUT_PATH}/ecl_lgr_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.EGRID) -add_test( ecl_lgr_test2 ${EXECUTABLE_OUTPUT_PATH}/ecl_lgr_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.GRID) -add_test( ecl_lgr_test3 ${EXECUTABLE_OUTPUT_PATH}/ecl_lgr_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID ) - - -add_executable( ecl_grid_simple ecl_grid_simple.c ) -target_link_libraries( ecl_grid_simple ecl ) -add_test( ecl_grid_simple ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_simple ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ) - - -add_executable( ecl_grid_dims ecl_grid_dims.c ) -target_link_libraries( ecl_grid_dims ecl ) - -add_test( ecl_grid_dims0 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ) -add_test( ecl_grid_dims1 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.INIT ) -add_test( ecl_grid_dims2 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.INIT) -add_test( ecl_grid_dims3 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ) -add_test( ecl_grid_dims4 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID ) -add_test( ecl_grid_dims5 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.EGRID - ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.INIT ) - - - - - -add_executable( ecl_kw_grdecl ecl_kw_grdecl.c ) -target_link_libraries( ecl_kw_grdecl ecl ) -add_test( ecl_kw_grdecl ${EXECUTABLE_OUTPUT_PATH}/ecl_kw_grdecl ) - -add_executable( ecl_kw_equal ecl_kw_equal.c ) -target_link_libraries( ecl_kw_equal ecl ) -add_test( ecl_kw_equal ${EXECUTABLE_OUTPUT_PATH}/ecl_kw_equal ) - - -add_executable( ecl_dualp ecl_dualp.c ) -target_link_libraries( ecl_dualp ecl ) -add_test( ecl_dualp ${EXECUTABLE_OUTPUT_PATH}/ecl_dualp ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2 ) - -add_executable( ecl_util_month_range ecl_util_month_range.c ) -target_link_libraries( ecl_util_month_range ecl ) -add_test( ecl_util_month_range ${EXECUTABLE_OUTPUT_PATH}/ecl_util_month_range ) - -add_executable( ecl_sum_test ecl_sum_test.c ) -target_link_libraries( ecl_sum_test ecl ) -add_test( ecl_sum_test ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ) - -add_executable( ecl_fortio ecl_fortio.c ) -target_link_libraries( ecl_fortio ecl ) -add_test( ecl_fortio ${EXECUTABLE_OUTPUT_PATH}/ecl_fortio ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ) - -add_executable( ecl_file ecl_file.c ) -target_link_libraries( ecl_file ecl ) -add_test( ecl_file ${EXECUTABLE_OUTPUT_PATH}/ecl_file ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ECLIPSE.UNRST) - -add_executable( ecl_fmt ecl_fmt.c ) -target_link_libraries( ecl_fmt ecl ) -add_test( ecl_fmt ${EXECUTABLE_OUTPUT_PATH}/ecl_fmt ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.DATA) - - -add_executable( ecl_rsthead ecl_rsthead.c ) -target_link_libraries( ecl_rsthead ecl ) -add_test( ecl_rsthead ${EXECUTABLE_OUTPUT_PATH}/ecl_rsthead ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST - ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/DualPoro/DUALPORO.X0005 ) - -set_property( TEST ecl_fmt PROPERTY LABELS Statoil ) -set_property( TEST ecl_coarse_test PROPERTY LABELS Statoil ) -set_property( TEST ecl_restart_test PROPERTY LABELS Statoil ) -set_property( TEST ecl_lgr_test1 PROPERTY LABELS Statoil ) -set_property( TEST ecl_lgr_test2 PROPERTY LABELS Statoil ) -set_property( TEST ecl_lgr_test3 PROPERTY LABELS Statoil ) -set_property( TEST ecl_grid_simple PROPERTY LABELS Statoil ) -set_property( TEST ecl_dualp PROPERTY LABELS Statoil ) -set_property( TEST ecl_sum_test PROPERTY LABELS Statoil ) -set_property( TEST ecl_fortio PROPERTY LABELS Statoil) -set_property( TEST ecl_grid_dims1 PROPERTY LABELS Statoil ) -set_property( TEST ecl_grid_dims2 PROPERTY LABELS Statoil ) -set_property( TEST ecl_grid_dims3 PROPERTY LABELS Statoil ) -set_property( TEST ecl_grid_dims4 PROPERTY LABELS Statoil ) -set_property( TEST ecl_grid_dims5 PROPERTY LABELS Statoil ) -set_property( TEST ecl_file PROPERTY LABELS Statoil) -set_property( TEST ecl_rsthead PROPERTY LABELS Statoil) diff --git a/ThirdParty/Ert/devel/libecl/tests/data/num_cpu1 b/ThirdParty/Ert/devel/libecl/tests/data/num_cpu1 new file mode 100644 index 0000000000..0f2473552d --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/data/num_cpu1 @@ -0,0 +1,2 @@ +PARALLEL + 4 DISTRIBUTED/ diff --git a/ThirdParty/Ert/devel/libecl/tests/data/num_cpu2 b/ThirdParty/Ert/devel/libecl/tests/data/num_cpu2 new file mode 100644 index 0000000000..663a393104 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/data/num_cpu2 @@ -0,0 +1,2 @@ +PARALLEL +4 'DIST'/ diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_file.c b/ThirdParty/Ert/devel/libecl/tests/ecl_file.c index ef36d2f082..8a7abfa59d 100644 --- a/ThirdParty/Ert/devel/libecl/tests/ecl_file.c +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_file.c @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -103,9 +104,12 @@ void test_close_stream1(const char * src_file , const char * target_file ) { void test_writable(const char * src_file ) { - util_copy_file( src_file , "/tmp/ECL.UNRST" ); + test_work_area_type * work_area = test_work_area_alloc("ecl_file_writable" , true); + char * fname = util_split_alloc_filename( src_file ); + + test_work_area_copy_file( work_area , src_file ); { - ecl_file_type * ecl_file = ecl_file_open( "/tmp/ECL.UNRST" , ECL_FILE_WRITABLE); + ecl_file_type * ecl_file = ecl_file_open( fname , ECL_FILE_WRITABLE); ecl_kw_type * swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 ); ecl_kw_type * swat0 = ecl_kw_alloc_copy( swat ); test_assert_true( ecl_kw_equal( swat , swat0 )); @@ -114,26 +118,30 @@ void test_writable(const char * src_file ) { test_assert_true( ecl_file_writable( ecl_file )); ecl_file_close( ecl_file ); - ecl_file = ecl_file_open( "/tmp/ECL.UNRST" , 0); + ecl_file = ecl_file_open( fname , 0); swat = ecl_file_iget_named_kw( ecl_file , "SWAT" , 0 ); test_assert_true( util_double_approx_equal( ecl_kw_iget_float( swat , 0 ) , 1000 )); } - util_unlink_existing( "/tmp/ECL.UNRST" ); + test_work_area_free( work_area ); } int main( int argc , char ** argv) { - const char * src_file = argv[1]; - const char * filename = argv[2]; - char * target_file = util_alloc_filename("/tmp" , filename , NULL ); + const char * target_file = argv[2]; - test_flags( src_file ); - test_loadall(src_file , target_file ); - test_close_stream1( src_file , target_file ); - test_close_stream2( src_file , target_file ); - test_writable( src_file ); - util_unlink_existing( target_file ); - + { + test_work_area_type * work_area = test_work_area_alloc("ecl_file" , true); + + test_work_area_install_file( work_area , src_file ); + test_flags( src_file ); + test_loadall(src_file , target_file ); + + test_close_stream1( src_file , target_file); + test_close_stream2( src_file , target_file); + test_writable( src_file ); + + test_work_area_free( work_area ); + } exit(0); } diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_fmt.c b/ThirdParty/Ert/devel/libecl/tests/ecl_fmt.c index fafa15b40c..482915f4a3 100644 --- a/ThirdParty/Ert/devel/libecl/tests/ecl_fmt.c +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_fmt.c @@ -20,21 +20,22 @@ #include #include +#include #include #include -void test_content( const char * src_file , bool fmt_file ) { - char * base_name , *path; - char * target_file; - bool fmt; - util_alloc_file_components( src_file , &path , &base_name , NULL); - target_file = util_alloc_filename( "/tmp" , base_name , NULL ); - util_copy_file( src_file , target_file); - - test_assert_true( ecl_util_fmt_file( target_file , &fmt )); - test_assert_bool_equal( fmt , fmt_file ); - unlink( target_file ); +void test_content( test_work_area_type * work_area , const char * src_file , bool fmt_file ) { + test_work_area_install_file( work_area , src_file ); + { + char * base_name; + bool fmt; + util_alloc_file_components( src_file , NULL , &base_name , NULL); + util_copy_file( src_file , base_name ); + + test_assert_true( ecl_util_fmt_file( base_name , &fmt )); + test_assert_bool_equal( fmt , fmt_file ); + } } @@ -43,11 +44,11 @@ void test_content( const char * src_file , bool fmt_file ) { void test_small( ) { bool fmt; - FILE * stream = util_fopen("/tmp/small.txt" , "w"); + FILE * stream = util_fopen("small.txt" , "w"); fprintf(stream , "Some bytes\n"); fclose( stream ); - test_assert_false( ecl_util_fmt_file( "/tmp/small.txt" , &fmt )); + test_assert_false( ecl_util_fmt_file( "small.txt" , &fmt )); } @@ -55,29 +56,32 @@ void test_small( ) { int main(int argc , char ** argv) { - const char * binary_file = argv[1]; - const char * text_file = argv[2]; + test_work_area_type * work_area = test_work_area_alloc( "ecl_fmt" , true); + { + const char * binary_file = argv[1]; + const char * text_file = argv[2]; - bool fmt_file; + bool fmt_file; - test_assert_true( ecl_util_fmt_file( binary_file , &fmt_file )); - test_assert_false( fmt_file ); + test_assert_true( ecl_util_fmt_file( binary_file , &fmt_file )); + test_assert_false( fmt_file ); - test_assert_true( ecl_util_fmt_file( text_file , &fmt_file )); - test_assert_true( fmt_file ); + test_assert_true( ecl_util_fmt_file( text_file , &fmt_file )); + test_assert_true( fmt_file ); - test_assert_true( ecl_util_fmt_file( "TEST.EGRID" , &fmt_file )); - test_assert_false( fmt_file ); + test_assert_true( ecl_util_fmt_file( "TEST.EGRID" , &fmt_file )); + test_assert_false( fmt_file ); - test_assert_true( ecl_util_fmt_file( "TEST.FEGRID" , &fmt_file )); - test_assert_true( fmt_file ); + test_assert_true( ecl_util_fmt_file( "TEST.FEGRID" , &fmt_file )); + test_assert_true( fmt_file ); - test_assert_false(ecl_util_fmt_file( "TEST_DOES_NOT_EXIST" , &fmt_file )); - - test_content( binary_file , false ); - test_content( text_file , true ); - test_small( ); + test_assert_false(ecl_util_fmt_file( "TEST_DOES_NOT_EXIST" , &fmt_file )); + test_content( work_area , binary_file , false ); + test_content( work_area , text_file , true ); + test_small( ); + } + test_work_area_free( work_area ); exit(0); } diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_fortio.c b/ThirdParty/Ert/devel/libecl/tests/ecl_fortio.c index 4dc9f76a7c..a7eb31ad99 100644 --- a/ThirdParty/Ert/devel/libecl/tests/ecl_fortio.c +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_fortio.c @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -79,10 +80,15 @@ int main( int argc , char ** argv) { test_existing_read( file ); test_not_existing_read( ); - test_write( "/tmp/file.x" , true ); - test_write( "/tmp/path/does/not/exist" , false ); test_open_close_read( file ); test_wrapper( file ); + test_write( "/tmp/path/does/not/exist" , false ); + { + test_work_area_type * work_area = test_work_area_alloc("ecl_fortio.write" , true ); + util_make_path("path"); + test_write( "path/file.x" , true ); + test_work_area_free( work_area ); + } exit(0); } diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_get_num_cpu_test.c b/ThirdParty/Ert/devel/libecl/tests/ecl_get_num_cpu_test.c new file mode 100644 index 0000000000..92d18884c4 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_get_num_cpu_test.c @@ -0,0 +1,33 @@ +/* + Copyright (C) 2012 Statoil ASA, Norway. + + The file 'ecl_get_num_cpu_test.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include + + +int main(int argc , char ** argv) { + const char * filename1 = argv[1]; + const char * filename2 = argv[2]; + int num_cpu = 4; + test_assert_int_equal(ecl_util_get_num_cpu(filename1), num_cpu); + test_assert_int_equal(ecl_util_get_num_cpu(filename2), num_cpu); + exit(0); +} + diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_grid_case.c b/ThirdParty/Ert/devel/libecl/tests/ecl_grid_case.c new file mode 100644 index 0000000000..cbf40c6a83 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_grid_case.c @@ -0,0 +1,46 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_grid_case.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include + +#include + + +void test_grid( const char * input , bool expected) { + ecl_grid_type * grid = ecl_grid_load_case( input ); + if (expected) { + test_assert_true( ecl_grid_is_instance( grid )); + ecl_grid_free( grid ); + } else + test_assert_NULL( grid ); +} + + +int main(int argc , char ** argv) { + const char * grid_file = argv[1]; + const char * case_path = argv[2]; + + test_grid( grid_file , true ); + test_grid( case_path , true ); + test_grid( "/tmp/does/not/exists/file.EGRID" , false ); + test_grid( "/tmp/does/not/exists/CASE" , false ); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_grid_lgr_name.c b/ThirdParty/Ert/devel/libecl/tests/ecl_grid_lgr_name.c new file mode 100644 index 0000000000..a9d54a951f --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_grid_lgr_name.c @@ -0,0 +1,38 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_grid_lgr_name.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include + +#include + + + +int main(int argc , char ** argv) { + const char * grid_file = argv[1]; + ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_file ); + + test_assert_int_equal( 1 , ecl_grid_get_num_lgr( ecl_grid )); + test_assert_string_equal( "LGR1" , ecl_grid_iget_lgr_name( ecl_grid , 0 )); + test_assert_string_equal( NULL , ecl_grid_iget_lgr_name( ecl_grid , 1 )); + + ecl_grid_free( ecl_grid ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_kw_grdecl.c b/ThirdParty/Ert/devel/libecl/tests/ecl_kw_grdecl.c index 5b68d278eb..a18d168131 100644 --- a/ThirdParty/Ert/devel/libecl/tests/ecl_kw_grdecl.c +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_kw_grdecl.c @@ -20,6 +20,8 @@ #include #include +#include + #include int main(int argc , char ** argv) { @@ -30,6 +32,7 @@ int main(int argc , char ** argv) { ecl_kw_iset_int(ecl_kw , i , i ); { + test_work_area_type * work_area = test_work_area_alloc("ecl_kw_grdecl" , true); FILE * stream = util_fopen( "FILE.grdecl" , "w"); ecl_kw_fprintf_grdecl(ecl_kw , stream ); @@ -62,7 +65,7 @@ int main(int argc , char ** argv) { ecl_kw_free( ecl_kw2 ); } fclose( stream ); - + test_work_area_free( work_area ); } ecl_kw_free( ecl_kw ); diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_lfs.c b/ThirdParty/Ert/devel/libecl/tests/ecl_lfs.c new file mode 100644 index 0000000000..871b7bfa0a --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_lfs.c @@ -0,0 +1,91 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_win64.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include + +#include +#include +#include + + + + +int main( int argc , char ** argv) { + int num_kw = 1000; // Total file size should roughly exceed 2GB + int kw_size = 600000; + ecl_kw_type * kw = ecl_kw_alloc("KW" , kw_size , ECL_INT_TYPE ); + rng_type * rng = rng_alloc( MZRAN , INIT_DEFAULT ); + int i; + offset_type file_size; + for (i=0; i < kw_size; i++) + ecl_kw_iset_int( kw , i , rng_get_int( rng , 912732 )); + + { + fortio_type * fortio = fortio_open_writer( "LARGE_FILE.UNRST" , false , ECL_ENDIAN_FLIP); + for (i = 0; i < num_kw; i++) { + printf("Writing keyword %d/%d to file:LARGE_FILE.UNRST \n",i+1 , num_kw ); + ecl_kw_fwrite( kw , fortio ); + } + fortio_fclose( fortio ); + } + + /*{ + fortio_type * fortio = fortio_open_reader( "LARGE_FILE.UNRST" , false , ECL_ENDIAN_FLIP); + for (i = 0; i < num_kw - 1; i++) { + printf("SKipping keyword %d/%d from file:LARGE_FILE.UNRST \n",i+1 , num_kw ); + ecl_kw_fskip( fortio ); + } + { + ecl_kw_type * file_kw = ecl_kw_fread_alloc( fortio ); + if (ecl_kw_equal( kw , file_kw )) + printf("Keyword read back from file correctly :-) \n"); + else + printf("Fatal error - keyword different on return ...\n"); + ecl_kw_free( file_kw ); + } + fortio_fclose( fortio ); + } + */ + file_size = util_file_size( "LARGE_FILE.UNRST" ); + printf("File size: %lld \n",file_size); + { + fortio_type * fortio = fortio_open_reader( "LARGE_FILE.UNRST" , false , ECL_ENDIAN_FLIP); + printf("Seeking to file end: "); + fortio_fseek( fortio , file_size , SEEK_SET); + fortio_fclose( fortio ); + printf("Seek OK \n"); + } + + + printf("Doing ecl_file_open(..)\n"); + { + ecl_file_type * file = ecl_file_open( "LARGE_FILE.UNRST" , 0); + ecl_kw_type * file_kw = ecl_file_iget_named_kw( file , "KW" , num_kw - 1); + if (ecl_kw_equal( kw , file_kw )) + printf("Keyword read back from file correctly :-) \n"); + else + printf("Fatal error - keyword different on return ...\n"); + ecl_file_close( file ); + } + + remove( "LARGE_FILE.UNRST" ); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_lgr_name.c b/ThirdParty/Ert/devel/libecl/tests/ecl_lgr_name.c new file mode 100644 index 0000000000..6ce84cc4db --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_lgr_name.c @@ -0,0 +1,44 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_lgr_name.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include + +#include + + +int main( int argc , char ** argv) { + ecl_grid_type * grid = ecl_grid_alloc( argv[1] ); + + int num_lgr = ecl_grid_get_num_lgr( grid ); + int lgr_index; + for (lgr_index = 0; lgr_index < num_lgr; lgr_index++) { + ecl_grid_type * lgr_from_index = ecl_grid_iget_lgr( grid, lgr_index ); + int lgr_nr = ecl_grid_get_lgr_nr( lgr_from_index); + ecl_grid_type * lgr_from_nr = ecl_grid_get_lgr_from_lgr_nr( grid , lgr_nr); + + test_assert_ptr_equal( lgr_from_index , lgr_from_nr ); + + test_assert_string_equal( ecl_grid_get_lgr_name( grid , lgr_nr) , ecl_grid_iget_lgr_name( grid , lgr_index)); + printf("Grid[%d:%d] : %s \n",lgr_index , lgr_nr , ecl_grid_iget_lgr_name( grid , lgr_index )); + } + ecl_grid_free( grid ); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_index_list.c b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_index_list.c new file mode 100644 index 0000000000..64c60819af --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_index_list.c @@ -0,0 +1,103 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_nnc_index_list.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include + + +void test_create() { + nnc_index_list_type * index_list = nnc_index_list_alloc(); + test_assert_true( nnc_index_list_is_instance( index_list )); + { + const int_vector_type * list = nnc_index_list_get_list( index_list ); + test_assert_int_equal( 0 , int_vector_size( list )); + } + nnc_index_list_free( index_list ); +} + + +void test_content() { + nnc_index_list_type * index_list = nnc_index_list_alloc(); + + nnc_index_list_add_index( index_list , 0 ); + nnc_index_list_add_index( index_list , 1 ); + nnc_index_list_add_index( index_list , 2 ); + nnc_index_list_add_index( index_list , 3 ); + + { + const int_vector_type * list = nnc_index_list_get_list( index_list ); + test_assert_int_equal( 4 , int_vector_size( list )); + + test_assert_int_equal( 0 , int_vector_iget( list , 0)); + test_assert_int_equal( 1 , int_vector_iget( list , 1)); + test_assert_int_equal( 2 , int_vector_iget( list , 2)); + test_assert_int_equal( 3 , int_vector_iget( list , 3)); + + } + nnc_index_list_free( index_list ); +} + + +void test_sort_unique() { + nnc_index_list_type * index_list = nnc_index_list_alloc(); + + nnc_index_list_add_index( index_list , 3 ); + nnc_index_list_add_index( index_list , 1 ); + nnc_index_list_add_index( index_list , 2 ); + nnc_index_list_add_index( index_list , 0 ); + + { + const int_vector_type * list = nnc_index_list_get_list( index_list ); + test_assert_int_equal( 4 , int_vector_size( list )); + + test_assert_int_equal( 0 , int_vector_iget( list , 0)); + test_assert_int_equal( 1 , int_vector_iget( list , 1)); + test_assert_int_equal( 2 , int_vector_iget( list , 2)); + test_assert_int_equal( 3 , int_vector_iget( list , 3)); + + } + nnc_index_list_add_index( index_list , 3 ); + nnc_index_list_add_index( index_list , 1 ); + nnc_index_list_add_index( index_list , 2 ); + nnc_index_list_add_index( index_list , 0 ); + { + const int_vector_type * list = nnc_index_list_get_list( index_list ); + test_assert_int_equal( 4 , int_vector_size( list )); + + test_assert_int_equal( 0 , int_vector_iget( list , 0)); + test_assert_int_equal( 1 , int_vector_iget( list , 1)); + test_assert_int_equal( 2 , int_vector_iget( list , 2)); + test_assert_int_equal( 3 , int_vector_iget( list , 3)); + + } + nnc_index_list_free( index_list ); +} + + + +int main( int argc , char ** argv) { + test_create(); + test_content(); + test_sort_unique(); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_index_list_grid.c b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_index_list_grid.c new file mode 100644 index 0000000000..65645a5f2a --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_index_list_grid.c @@ -0,0 +1,60 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_nnc_index_list_grid.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include +#include +#include + + + +int main( int argc , char ** argv) { + const char * egrid_file = argv[1]; + + ecl_grid_type * grid = ecl_grid_alloc( egrid_file ); + ecl_file_type * gfile = ecl_file_open( egrid_file , 0 ); + const ecl_kw_type * nnc1_kw = ecl_file_iget_named_kw( gfile , "NNC1" ,0 ); + const ecl_kw_type * nnc2_kw = ecl_file_iget_named_kw( gfile , "NNC2" ,0 ); + const int_vector_type * index_list = ecl_grid_get_nnc_index_list( grid ); + + { + int_vector_type * nnc = int_vector_alloc(0,0); + + int_vector_set_many( nnc , 0 , ecl_kw_get_ptr( nnc1_kw ) , ecl_kw_get_size( nnc1_kw )); + int_vector_append_many( nnc , ecl_kw_get_ptr( nnc2_kw ) , ecl_kw_get_size( nnc2_kw )); + int_vector_select_unique( nnc ); + test_assert_int_equal( int_vector_size( index_list ) , int_vector_size( nnc )); + + { + int i; + for (i=0; i < int_vector_size( nnc ); i++) + test_assert_int_equal( int_vector_iget( nnc , i ) - 1 , int_vector_iget(index_list , i )); + } + int_vector_free( nnc ); + } + + ecl_file_close( gfile ); + ecl_grid_free( grid ); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_info_test.c b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_info_test.c new file mode 100644 index 0000000000..af5acb5456 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_info_test.c @@ -0,0 +1,66 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_nnc_info_test.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include +#include +#include + + +int main(int argc , char ** argv) { + int lgr_nr = 77; + nnc_info_type * nnc_info = nnc_info_alloc(lgr_nr); + + test_assert_int_equal( lgr_nr , nnc_info_get_lgr_nr( nnc_info )); + test_assert_true(nnc_info_is_instance(nnc_info)); + test_assert_not_NULL(nnc_info); + + nnc_info_add_nnc(nnc_info, 1, 110); + nnc_info_add_nnc(nnc_info, 1, 111); + + const nnc_vector_type * nnc_vector = nnc_info_get_vector( nnc_info , 1); + const int_vector_type * nnc_cells = nnc_info_get_index_list(nnc_info, 1); + test_assert_int_equal(int_vector_size(nnc_cells), 2); + test_assert_ptr_equal( nnc_cells , nnc_vector_get_index_list( nnc_vector )); + + + const nnc_vector_type * nnc_vector_null = nnc_info_get_vector( nnc_info , 2); + const int_vector_type * nnc_cells_null = nnc_info_get_index_list(nnc_info, 2); + test_assert_NULL(nnc_cells_null); + test_assert_NULL(nnc_vector_null); + + const nnc_vector_type * nnc_vector_self = nnc_info_get_self_vector( nnc_info ); + const nnc_vector_type * nnc_vector_77 = nnc_info_get_vector( nnc_info , lgr_nr ); + test_assert_ptr_equal( nnc_vector_77 , nnc_vector_self ); + + const int_vector_type * nnc_cells_77 = nnc_info_get_index_list(nnc_info, lgr_nr); + const int_vector_type * nnc_cells_self = nnc_info_get_self_index_list(nnc_info); + test_assert_ptr_equal( nnc_cells_77 , nnc_cells_self ); + + + test_assert_int_equal( 1 , nnc_info_get_size( nnc_info )); + test_assert_ptr_equal( nnc_info_get_vector( nnc_info , 1 ) , nnc_info_iget_vector( nnc_info , 0 )); + nnc_info_free(nnc_info); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_test.c b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_test.c new file mode 100644 index 0000000000..ed8d8e53aa --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_test.c @@ -0,0 +1,341 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_nnc_test.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include +#include + + +void test_nnc_global_grid( const char * grid_filename ) { + ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_filename ); + test_assert_not_NULL( ecl_grid ); + + const int data[] = {2675, 5235, 7795, 10355, 12915, 15475, 18035, 20595, 23155, 25715, 28275, 30835, 33395}; + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(ecl_grid, 114); + test_assert_not_NULL( nnc_info ); + test_assert_int_equal( ecl_grid_get_lgr_nr( ecl_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + + ecl_grid_free(ecl_grid); +} + +void test_nnc_dual_poro(const char * grid_filename ) { + ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_filename ); + test_assert_not_NULL( ecl_grid ); + ecl_grid_free(ecl_grid); +} + +void test_nnc_lgr( const char * grid_filename ) { + ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_filename ); + test_assert_not_NULL( ecl_grid ); + + //Global grid + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(ecl_grid, 125132); + test_assert_not_NULL( nnc_info ); + test_assert_int_equal( ecl_grid_get_lgr_nr( ecl_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), 1); + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, 0), 151053); + + //LGR + const int data[] = {126394, 126305}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 0); + test_assert_not_NULL( lgr_grid ); + + const nnc_info_type * lgr_nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 2017-1); + test_assert_not_NULL( lgr_nnc_info ); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( lgr_nnc_info )); + + const int_vector_type * lgr_nnc_cell_number_vec = nnc_info_get_index_list(lgr_nnc_info, 0); + test_assert_not_NULL(lgr_nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(lgr_nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(lgr_nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(lgr_nnc_cell_number_vec, i), data[i]); + + ecl_grid_free(ecl_grid); +} + + + +void test_nnc_multiple_lgr( const char * grid_filename) { + ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_filename ); + test_assert_not_NULL( ecl_grid ); + + { + //Global grid, check NNC for cell with global index 736 + int data[] = {11957, 20336, 3528, 6321, 9114, 11907, 20286}; + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(ecl_grid, 736); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( ecl_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) { + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + } + + //Check grid name + test_assert_string_equal(ecl_grid_get_name(ecl_grid), grid_filename); + } + + { + //Global grid, check NNC for cell with global index 138291 + int data[] = {141035, 143828, 141085, 143878}; + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(ecl_grid, 138291); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( ecl_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) { + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + } + } + + + { + //LGR nr 1, cell global index 0: check NNCs to main grid + int data[] = {29012, 26220}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 0); + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 0); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i = 0; + for (; i < int_vector_size(nnc_cell_number_vec); ++i) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + + //Check name + test_assert_string_equal(ecl_grid_get_name(lgr_grid), "LG006023"); + } + + + { + //LGR nr 1, cell global index 0: check NNCs to grid with lgr nr 20 + int data[] = {12}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 0); + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 0); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 20); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i = 0; + for (; i < int_vector_size(nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + } + + + + + { + //LGR nr 3, check NNC for cell with global index 8 + int data[] = {20681, 23474, 26267, 37440}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 2); + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 8); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + + //Check LGR name + test_assert_string_equal(ecl_grid_get_name(lgr_grid), "LG005024"); + } + + { + //LGR nr 99, check NNC for cell with global index 736 + int data[] = {126671, 79142}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 98-1); //Subtract 1: LGR nr 98 is not present in the test file. LGRs are numbered 1-97 and 99-110 in test file. + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 736); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + + //Check LGR name + test_assert_string_equal(ecl_grid_get_name(lgr_grid), "LG008021"); + } + + { + //LGR nr 110, cell with global index 271: Check NNCs to global grid + int data[] = {20191, 22983}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 109-1); //Subtract 1: LGR nr 98 is not present in the test file. LGRs are numbered 1-97 and 99-110 in test file. + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 271); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 0); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + + //Check LGR name + test_assert_string_equal(ecl_grid_get_name(lgr_grid), "LG003014"); + } + + { + //LGR nr 110, cell with global index 271: Check NNCs to lgr nr 109 + int data[] = {275}; + + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 109-1); //Subtract 1: LGR nr 98 is not present in the test file. LGRs are numbered 1-97 and 99-110 in test file. + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 271); + test_assert_not_NULL(nnc_info); + test_assert_int_equal( ecl_grid_get_lgr_nr( lgr_grid ) , nnc_info_get_lgr_nr( nnc_info )); + + const int_vector_type * nnc_cell_number_vec = nnc_info_get_index_list(nnc_info, 109); + test_assert_not_NULL(nnc_cell_number_vec); + + test_assert_int_equal(int_vector_size(nnc_cell_number_vec), (sizeof(data)/sizeof(data[0]))); + + int i; + for (i = 0; i < int_vector_size(nnc_cell_number_vec); i++) + test_assert_int_equal(int_vector_iget(nnc_cell_number_vec, i), data[i]); + } + + + { + //Test global versus ijk indexing + const nnc_info_type * nnc_info1 = ecl_grid_get_cell_nnc_info1(ecl_grid, 736); + test_assert_not_NULL(nnc_info1); + + int i = 0; + int j = 0; + int k = 0; + + ecl_grid_get_ijk1(ecl_grid, 736, &i, &j, &k); + + const nnc_info_type * nnc_info2 = ecl_grid_get_cell_nnc_info3(ecl_grid, i, j, k); + test_assert_not_NULL(nnc_info2); + + test_assert_ptr_equal(nnc_info1, nnc_info2); + } + + ecl_grid_free(ecl_grid); +} + + +void test_nnc_amalgamated_lgrs(const char * grid_filename) { + ecl_grid_type * ecl_grid = ecl_grid_alloc( grid_filename ); + test_assert_not_NULL( ecl_grid ); + + + //Get the NNC info for cell with global index 0 in LGR nr 1 + ecl_grid_type * lgr_grid = ecl_grid_iget_lgr(ecl_grid, 0); + test_assert_not_NULL(lgr_grid); + + const nnc_info_type * nnc_info = ecl_grid_get_cell_nnc_info1(lgr_grid, 0); + test_assert_not_NULL(nnc_info); + + //Get the connections that this cell has to LGR 20 + const int_vector_type * nnc_lgr_20 = nnc_info_get_index_list(nnc_info, 20); + test_assert_not_NULL(nnc_lgr_20); + + test_assert_int_equal(int_vector_size(nnc_lgr_20), 1); + test_assert_int_equal(int_vector_iget(nnc_lgr_20, 0), 12); + + ecl_grid_free(ecl_grid); +} + + + + +int main(int argc , char ** argv) { + const char * EGRID_file1 = argv[1]; + const char * EGRID_file2 = argv[2]; + const char * EGRID_file3 = argv[3]; + const char * EGRID_file4 = argv[4]; + + test_nnc_global_grid( EGRID_file1 ); + test_nnc_lgr( EGRID_file2 ); + test_nnc_multiple_lgr( EGRID_file3 ); + test_nnc_amalgamated_lgrs(EGRID_file3); + test_nnc_dual_poro( EGRID_file4 ); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_vector.c b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_vector.c new file mode 100644 index 0000000000..d12cbeda03 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_nnc_vector.c @@ -0,0 +1,49 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_nnc_vector.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include + +#include + + +int main(int argc , char ** argv) { + int lgr_nr = 100; + nnc_vector_type * vector = nnc_vector_alloc( lgr_nr ); + + test_assert_true( nnc_vector_is_instance( vector )); + test_assert_int_equal( lgr_nr , nnc_vector_get_lgr_nr( vector )); + + nnc_vector_add_nnc( vector , 100 ); + nnc_vector_add_nnc( vector , 200 ); + nnc_vector_add_nnc( vector , 300 ); + + { + const int_vector_type * index_list = nnc_vector_get_index_list( vector ); + + test_assert_int_equal( 3 , int_vector_size( index_list )); + test_assert_int_equal( 100 , int_vector_iget( index_list , 0 )); + test_assert_int_equal( 200 , int_vector_iget( index_list , 1 )); + test_assert_int_equal( 300 , int_vector_iget( index_list , 2 )); + } + + nnc_vector_free( vector ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_region.c b/ThirdParty/Ert/devel/libecl/tests/ecl_region.c new file mode 100644 index 0000000000..2c0b339814 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_region.c @@ -0,0 +1,70 @@ +/* + Copyright (C) 2012 Statoil ASA, Norway. + + The file 'ecl_region.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include + +#include +#include + +void test_list( int volume , int nactive , ecl_region_type * region ) { + const int_vector_type * active_list; + const int_vector_type * global_list; + active_list = ecl_region_get_active_list( region ); + global_list = ecl_region_get_global_list( region ); + test_assert_int_equal( nactive , int_vector_size( active_list )); + test_assert_int_equal( volume , int_vector_size( global_list )); + + + ecl_region_deselect_all( region ); + active_list = ecl_region_get_active_list( region ); + global_list = ecl_region_get_global_list( region ); + test_assert_int_equal( 0 , int_vector_size( active_list )); + test_assert_int_equal( 0 , int_vector_size( global_list )); +} + + + +void test_slice( const ecl_grid_type * grid ) { + int nx = ecl_grid_get_nx( grid ); + int ny = ecl_grid_get_ny( grid ); + int nz = ecl_grid_get_nz( grid ); + int nactive = ecl_grid_get_nactive( grid ); + ecl_region_type * region = ecl_region_alloc( grid , false ); + + ecl_region_select_i1i2( region , 0 , nx - 1); + test_list( nx*ny*nz , nactive , region ); + ecl_region_select_j1j2( region , 0 , ny - 1); + test_list( nx*ny*nz , nactive , region ); + ecl_region_select_k1k2( region , 0 , nz - 1); + test_list( nx*ny*nz , nactive , region ); + + ecl_region_free( region ); +} + + +int main(int argc , char ** argv) { + const char * grid_file = argv[1]; + ecl_grid_type * grid = ecl_grid_alloc( grid_file ); + + test_slice( grid ); + + ecl_grid_free( grid ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_region2region_test.c b/ThirdParty/Ert/devel/libecl/tests/ecl_region2region_test.c new file mode 100644 index 0000000000..98694d278b --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_region2region_test.c @@ -0,0 +1,70 @@ +/* + Copyright (C) 2012 Statoil ASA, Norway. + + The file 'ecl_region2region.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include + + +void has_r2r_key(const ecl_sum_type* ecl_sum) { + test_assert_true(ecl_sum_has_key( ecl_sum , "RGF:393217" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "RGF:1-2" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "ROF:524291" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "RWF:393222" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "RWF:6-2" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "ROF:3-6" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "RNLF:458753" )); + test_assert_true(ecl_sum_has_key( ecl_sum , "RNLF:1-4" )); +} + +void get_unit(const ecl_sum_type* ecl_sum) { + test_assert_string_equal(ecl_sum_get_unit( ecl_sum , "RGF:1-2" ), "GFLOW"); + test_assert_string_equal(ecl_sum_get_unit( ecl_sum , "ROF:3-6" ), "OFLOW"); + test_assert_string_equal(ecl_sum_get_unit( ecl_sum , "RWF:6-2" ), "WFLOW"); + test_assert_string_equal(ecl_sum_get_unit( ecl_sum , "RNLF:1-4" ), "NLFLOW"); +} + +void get_var_params_index(const ecl_sum_type* ecl_sum) { + test_assert_int_equal(ecl_sum_get_general_var_params_index( ecl_sum , "RGF:1-2"), 21917); + test_assert_int_equal(ecl_sum_get_general_var_params_index( ecl_sum , "ROF:3-6"), 21918); + test_assert_int_equal(ecl_sum_get_general_var_params_index( ecl_sum, "RWF:6-2"), 21919); + test_assert_int_equal(ecl_sum_get_general_var_params_index( ecl_sum, "RNLF:1-4"), 21920); +} + +int main(int argc , char ** argv) { + + const char * headerfile = argv[1]; + + ecl_sum_type * ecl_sum = ecl_sum_fread_alloc_case( headerfile , ":"); + + if (ecl_sum) { + has_r2r_key(ecl_sum); + get_unit(ecl_sum); + get_var_params_index(ecl_sum); + } + else + test_error_exit("ecl_region2region_test: Test file not read correctly"); + + + if (ecl_sum) + ecl_sum_free( ecl_sum ); + + exit(0); +} + diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_rft.c b/ThirdParty/Ert/devel/libecl/tests/ecl_rft.c new file mode 100644 index 0000000000..5a71d86bc5 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_rft.c @@ -0,0 +1,148 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_rft.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include + + + + +// Hardcoded GURBAT values +void test_rft( const char * rft_file ) { + ecl_rft_file_type * rft = ecl_rft_file_alloc( rft_file ); + ecl_rft_node_type * rft_node = ecl_rft_file_iget_node( rft , 0 ); + + test_assert_true( ecl_rft_node_is_RFT( rft_node )); + test_assert_int_equal( 14 , ecl_rft_node_get_size( rft_node )); + test_assert_false( ecl_rft_node_is_MSW( rft_node )); + + test_assert_double_equal( 260.6111 , ecl_rft_node_iget_pressure( rft_node , 0 )); + test_assert_double_equal( 0.0581993 , ecl_rft_node_iget_soil( rft_node , 0 )); + test_assert_double_equal( 0.9405648 , ecl_rft_node_iget_swat( rft_node , 0 )); + test_assert_double_equal( 0.00123579 , ecl_rft_node_iget_sgas( rft_node , 0 )); + + { + int i,j,k; + + ecl_rft_node_iget_ijk( rft_node , 0 , &i , &j , &k ); + test_assert_int_equal( 32 , i ); + test_assert_int_equal( 53 , j ); + test_assert_int_equal( 0 , k ); + + ecl_rft_node_iget_ijk( rft_node , 13 , &i , &j , &k ); + test_assert_int_equal( 32 , i ); + test_assert_int_equal( 54 , j ); + test_assert_int_equal( 12 , k ); + + for (i=0; i < ecl_rft_node_get_size( rft_node ); i++) { + const ecl_rft_cell_type * cell1 = ecl_rft_node_iget_cell( rft_node , i ); + const ecl_rft_cell_type * cell2 = ecl_rft_node_iget_cell_sorted( rft_node , i ); + + test_assert_ptr_equal( cell1 , cell2 ); + } + } + ecl_rft_node_inplace_sort_cells( rft_node ); + + ecl_rft_file_free( rft ); +} + + +void test_plt_msw( const char * plt_file ) { + ecl_rft_file_type * plt = ecl_rft_file_alloc( plt_file ); + ecl_rft_node_type * plt_node = ecl_rft_file_iget_node( plt , 11 ); + + test_assert_true( ecl_rft_node_is_PLT( plt_node )); + test_assert_true( ecl_rft_node_is_MSW( plt_node )); + test_assert_int_equal( 22 , ecl_rft_node_get_size( plt_node )); + ecl_rft_node_inplace_sort_cells( plt_node ); + { + int i; + for (i=1; i < ecl_rft_node_get_size( plt_node ); i++) { + const ecl_rft_cell_type * prev_cell = ecl_rft_node_iget_cell( plt_node , i - 1); + const ecl_rft_cell_type * this_cell = ecl_rft_node_iget_cell( plt_node , i ); + + test_assert_true( ecl_rft_cell_get_connection_start( prev_cell ) < ecl_rft_cell_get_connection_start( this_cell )); + test_assert_true( ecl_rft_cell_get_connection_end( prev_cell ) < ecl_rft_cell_get_connection_end( this_cell )); + } + } + + ecl_rft_file_free( plt ); +} + + +// Hardcoded values from a test case with a PLT. +void test_plt( const char * plt_file ) { + ecl_rft_file_type * plt = ecl_rft_file_alloc( plt_file ); + ecl_rft_node_type * plt_node = ecl_rft_file_iget_node( plt , 11 ); + + test_assert_true( ecl_rft_node_is_PLT( plt_node )); + test_assert_false( ecl_rft_node_is_MSW( plt_node )); + test_assert_int_equal( 22 , ecl_rft_node_get_size( plt_node )); + + test_assert_double_equal( 244.284 , ecl_rft_node_iget_pressure( plt_node , 0 )); + test_assert_double_equal( 167.473 , ecl_rft_node_iget_orat( plt_node , 0 )); + test_assert_double_equal( 41682.2 , ecl_rft_node_iget_grat( plt_node , 0 )); + test_assert_double_equal( 0.958927 , ecl_rft_node_iget_wrat( plt_node , 0 )); + + { + int i,j,k; + + ecl_rft_node_iget_ijk( plt_node , 0 , &i , &j , &k ); + test_assert_int_equal( 39 , i ); + test_assert_int_equal( 33 , j ); + test_assert_int_equal( 16 , k ); + + ecl_rft_node_iget_ijk( plt_node , 21 , &i , &j , &k ); + test_assert_int_equal( 44 , i ); + test_assert_int_equal( 34 , j ); + test_assert_int_equal( 7 , k ); + + for (i=0; i < ecl_rft_node_get_size( plt_node ); i++) { + const ecl_rft_cell_type * cell1 = ecl_rft_node_iget_cell( plt_node , i ); + const ecl_rft_cell_type * cell2 = ecl_rft_node_iget_cell_sorted( plt_node , i ); + + test_assert_ptr_equal( cell1 , cell2 ); + } + ecl_rft_node_inplace_sort_cells( plt_node ); + } + + ecl_rft_file_free( plt ); +} + + + +int main( int argc , char ** argv) { + const char * rft_file = argv[1]; + const char * mode_string = argv[2]; + + if (strcmp( mode_string , "RFT") == 0) + test_rft( rft_file ); + else if (strcmp( mode_string , "PLT") == 0) + test_plt( rft_file ); + else if (strcmp( mode_string , "MSW-PLT") == 0) + test_plt_msw( rft_file ); + else + test_error_exit("Second argument:%s not recognized. Valid values are: RFT and PLT" , mode_string); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_rft_cell.c b/ThirdParty/Ert/devel/libecl/tests/ecl_rft_cell.c new file mode 100644 index 0000000000..19328a7087 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_rft_cell.c @@ -0,0 +1,150 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_rft_cell.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include +#include + + + +void test_rft_cell() { + const int i = 10; + const int j = 11; + const int k = 12; + + const double depth = 100; + const double pressure = 200; + const double swat = 0.25; + const double sgas = 0.35; + + ecl_rft_cell_type * cell = ecl_rft_cell_alloc_RFT(i,j,k,depth,pressure,swat,sgas); + + test_assert_int_equal( i , ecl_rft_cell_get_i( cell )); + test_assert_int_equal( j , ecl_rft_cell_get_j( cell )); + test_assert_int_equal( k , ecl_rft_cell_get_k( cell )); + + { + int ii,jj,kk; + ecl_rft_cell_get_ijk( cell , &ii , &jj , &kk); + test_assert_int_equal( i , ii); + test_assert_int_equal( j , jj); + test_assert_int_equal( k , kk); + } + + test_assert_double_equal( depth , ecl_rft_cell_get_depth( cell )); + test_assert_double_equal( pressure , ecl_rft_cell_get_pressure( cell )); + test_assert_double_equal( swat , ecl_rft_cell_get_swat( cell )); + test_assert_double_equal( sgas , ecl_rft_cell_get_sgas( cell )); + test_assert_double_equal( 1 - (swat + sgas) , ecl_rft_cell_get_soil( cell )); + + test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_orat( cell )); + test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_grat( cell )); + test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_wrat( cell )); + test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_flowrate( cell )); + test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_connection_start( cell )); + test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_connection_end( cell )); + test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_oil_flowrate( cell )); + test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_gas_flowrate( cell )); + test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_water_flowrate( cell )); + + ecl_rft_cell_free( cell ); + { + ecl_rft_cell_type * cell = ecl_rft_cell_alloc_RFT(i,j,k,depth,pressure,swat,sgas); + + test_assert_true( ecl_rft_cell_ijk_equal( cell , i , j , k )); + test_assert_false( ecl_rft_cell_ijk_equal( cell , i , j , k + 1 )); + + ecl_rft_cell_free__( cell ); + } +} + + + +void test_plt_cell() { + const int i = 10; + const int j = 11; + const int k = 12; + + const double depth = 100; + const double pressure = 200; + const double orat = 0.25; + const double grat = 0.35; + const double wrat = 0.45; + const double flowrate = 100.0; + const double connection_start = 891; + const double connection_end = 979; + const double oil_flowrate = 0.891; + const double gas_flowrate = 7771; + const double water_flowrate = 77614; + + ecl_rft_cell_type * cell = ecl_rft_cell_alloc_PLT(i,j,k,depth,pressure,orat,grat,wrat,connection_start,connection_end, flowrate,oil_flowrate , gas_flowrate , water_flowrate); + + test_assert_int_equal( i , ecl_rft_cell_get_i( cell )); + test_assert_int_equal( j , ecl_rft_cell_get_j( cell )); + test_assert_int_equal( k , ecl_rft_cell_get_k( cell )); + + { + int ii,jj,kk; + ecl_rft_cell_get_ijk( cell , &ii , &jj , &kk); + test_assert_int_equal( i , ii); + test_assert_int_equal( j , jj); + test_assert_int_equal( k , kk); + } + + test_assert_double_equal( depth , ecl_rft_cell_get_depth( cell )); + test_assert_double_equal( pressure , ecl_rft_cell_get_pressure( cell )); + + test_assert_double_equal( orat , ecl_rft_cell_get_orat( cell )); + test_assert_double_equal( grat , ecl_rft_cell_get_grat( cell )); + test_assert_double_equal( wrat , ecl_rft_cell_get_wrat( cell )); + test_assert_double_equal( connection_start, ecl_rft_cell_get_connection_start( cell )); + test_assert_double_equal( connection_end, ecl_rft_cell_get_connection_end( cell )); + test_assert_double_equal(flowrate , ecl_rft_cell_get_flowrate( cell )); + + test_assert_double_equal(oil_flowrate , ecl_rft_cell_get_oil_flowrate( cell )); + test_assert_double_equal(gas_flowrate , ecl_rft_cell_get_gas_flowrate( cell )); + test_assert_double_equal(water_flowrate , ecl_rft_cell_get_water_flowrate( cell )); + + test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_swat( cell )); + test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_sgas( cell )); + test_assert_double_equal( ECL_RFT_CELL_INVALID_VALUE , ecl_rft_cell_get_soil( cell )); + + ecl_rft_cell_free( cell ); +} + + + + + +int main( int argc , char ** argv) { + + test_rft_cell(); + test_plt_cell(); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_sum_report_step_compatible.c b/ThirdParty/Ert/devel/libecl/tests/ecl_sum_report_step_compatible.c new file mode 100644 index 0000000000..e76932c528 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_sum_report_step_compatible.c @@ -0,0 +1,49 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_sum_test.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include + + + +int main( int argc , char ** argv) { + const char * case1 = argv[1]; + const char * case2 = argv[2]; + const char * compatible_string = argv[3]; + bool compatible; + ecl_sum_type * ecl_sum1 = ecl_sum_fread_alloc_case( case1 , ":"); + ecl_sum_type * ecl_sum2 = ecl_sum_fread_alloc_case( case2 , ":"); + + test_assert_true( ecl_sum_is_instance( ecl_sum1 )); + test_assert_true( ecl_sum_is_instance( ecl_sum2 )); + test_assert_true( ecl_sum_report_step_compatible( ecl_sum1 , ecl_sum1) ); + test_assert_true( util_sscanf_bool( compatible_string , &compatible )); + + test_assert_true( ecl_sum_report_step_compatible( ecl_sum1 , ecl_sum1) ); + test_assert_true( ecl_sum_report_step_compatible( ecl_sum2 , ecl_sum2) ); + test_assert_bool_equal( compatible , ecl_sum_report_step_compatible( ecl_sum1 , ecl_sum2 )); + + ecl_sum_free( ecl_sum1 ); + ecl_sum_free( ecl_sum2 ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_sum_report_step_equal.c b/ThirdParty/Ert/devel/libecl/tests/ecl_sum_report_step_equal.c new file mode 100644 index 0000000000..86465c7bf5 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_sum_report_step_equal.c @@ -0,0 +1,49 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'ecl_sum_test.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include + + + +int main( int argc , char ** argv) { + const char * case1 = argv[1]; + const char * case2 = argv[2]; + const char * equal_string = argv[3]; + bool equal; + ecl_sum_type * ecl_sum1 = ecl_sum_fread_alloc_case( case1 , ":"); + ecl_sum_type * ecl_sum2 = ecl_sum_fread_alloc_case( case2 , ":"); + + test_assert_true( ecl_sum_is_instance( ecl_sum1 )); + test_assert_true( ecl_sum_is_instance( ecl_sum2 )); + test_assert_true( ecl_sum_report_step_equal( ecl_sum1 , ecl_sum1) ); + test_assert_true( util_sscanf_bool( equal_string , &equal )); + + test_assert_true( ecl_sum_report_step_equal( ecl_sum1 , ecl_sum1) ); + test_assert_true( ecl_sum_report_step_equal( ecl_sum2 , ecl_sum2) ); + test_assert_bool_equal( equal , ecl_sum_report_step_equal( ecl_sum1 , ecl_sum2 )); + + ecl_sum_free( ecl_sum1 ); + ecl_sum_free( ecl_sum2 ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl/tests/ecl_sum_test.c b/ThirdParty/Ert/devel/libecl/tests/ecl_sum_test.c index beb85d875d..af33502b9b 100644 --- a/ThirdParty/Ert/devel/libecl/tests/ecl_sum_test.c +++ b/ThirdParty/Ert/devel/libecl/tests/ecl_sum_test.c @@ -51,16 +51,25 @@ void test_days( const ecl_sum_type * ecl_sum ) { } +void test_is_oil_producer( const ecl_sum_type * ecl_sum) { + test_assert_true( ecl_sum_is_oil_producer( ecl_sum , "OP_1")); + test_assert_false( ecl_sum_is_oil_producer( ecl_sum , "WI_1")); + test_assert_false( ecl_sum_is_oil_producer( ecl_sum , "DoesNotExist")); +} + + int main( int argc , char ** argv) { - const char * casename = argv[1]; - - ecl_sum_type * ecl_sum = ecl_sum_fread_alloc_case( casename , ":"); - - test_time_range( ecl_sum ); - test_days( ecl_sum ); + const char * case1 = argv[1]; + ecl_sum_type * ecl_sum1 = ecl_sum_fread_alloc_case( case1 , ":"); + + test_assert_true( ecl_sum_is_instance( ecl_sum1 )); + test_time_range( ecl_sum1 ); + test_days( ecl_sum1 ); + test_is_oil_producer(ecl_sum1); + ecl_sum_free( ecl_sum1 ); exit(0); } diff --git a/ThirdParty/Ert/devel/libecl/tests/tests.cmake b/ThirdParty/Ert/devel/libecl/tests/tests.cmake new file mode 100644 index 0000000000..d122914436 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl/tests/tests.cmake @@ -0,0 +1,175 @@ +add_executable( ecl_coarse_test ecl_coarse_test.c ) +target_link_libraries( ecl_coarse_test ecl test_util ) +add_test( ecl_coarse_test ${EXECUTABLE_OUTPUT_PATH}/ecl_coarse_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2 ) + + +add_executable( ecl_restart_test ecl_restart_test.c ) +target_link_libraries( ecl_restart_test ecl test_util ) +add_test( ecl_restart_test ${EXECUTABLE_OUTPUT_PATH}/ecl_restart_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ) + + +add_executable( ecl_grid_lgr_name ecl_grid_lgr_name.c ) +target_link_libraries( ecl_grid_lgr_name ecl test_util ) +set_target_properties( ecl_grid_lgr_name PROPERTIES COMPILE_FLAGS "-Werror") +add_test( ecl_grid_lgr_name ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_lgr_name ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.EGRID) + +add_executable( ecl_region ecl_region.c ) +target_link_libraries( ecl_region ecl test_util ) +add_test( ecl_region ${EXECUTABLE_OUTPUT_PATH}/ecl_region ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ) + +add_executable( ecl_region2region ecl_region2region_test.c ) +target_link_libraries( ecl_region2region ecl test_util ) +add_test( ecl_region2region ${EXECUTABLE_OUTPUT_PATH}/ecl_region2region ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/R2R/R2R.SMSPEC ) + +add_executable( ecl_grid_case ecl_grid_case.c ) +target_link_libraries( ecl_grid_case ecl test_util ) +add_test( ecl_grid_case ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_case ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ) + + +add_executable( ecl_lgr_test ecl_lgr_test.c ) +target_link_libraries( ecl_lgr_test ecl test_util ) +add_test( ecl_lgr_test1 ${EXECUTABLE_OUTPUT_PATH}/ecl_lgr_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.EGRID) +add_test( ecl_lgr_test2 ${EXECUTABLE_OUTPUT_PATH}/ecl_lgr_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.GRID) +add_test( ecl_lgr_test3 ${EXECUTABLE_OUTPUT_PATH}/ecl_lgr_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID ) + + +add_executable( ecl_grid_simple ecl_grid_simple.c ) +target_link_libraries( ecl_grid_simple ecl test_util ) +add_test( ecl_grid_simple ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_simple ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ) + + +add_executable( ecl_grid_dims ecl_grid_dims.c ) +target_link_libraries( ecl_grid_dims ecl test_util ) + +add_test( ecl_grid_dims0 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ) +add_test( ecl_grid_dims1 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.INIT ) +add_test( ecl_grid_dims2 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.INIT) +add_test( ecl_grid_dims3 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ) +add_test( ecl_grid_dims4 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID ) +add_test( ecl_grid_dims5 ${EXECUTABLE_OUTPUT_PATH}/ecl_grid_dims ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.INIT ) + + +add_executable( ecl_nnc_test ecl_nnc_test.c ) +target_link_libraries( ecl_nnc_test ecl test_util ) +add_test (ecl_nnc_test ${EXECUTABLE_OUTPUT_PATH}/ecl_nnc_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Troll/MSW_LGR/2BRANCHES-CCEWELLPATH-NEW-SCH-TUNED-AR3.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/DualPoro/DUAL_DIFF.EGRID ) +add_executable( ecl_nnc_info_test ecl_nnc_info_test.c ) +target_link_libraries( ecl_nnc_info_test ecl test_util ) +add_test (ecl_nnc_info_test ${EXECUTABLE_OUTPUT_PATH}/ecl_nnc_info_test ) + + +add_executable( ecl_kw_grdecl ecl_kw_grdecl.c ) +target_link_libraries( ecl_kw_grdecl ecl test_util ) +add_test( ecl_kw_grdecl ${EXECUTABLE_OUTPUT_PATH}/ecl_kw_grdecl ) + +add_executable( ecl_kw_equal ecl_kw_equal.c ) +target_link_libraries( ecl_kw_equal ecl test_util ) +add_test( ecl_kw_equal ${EXECUTABLE_OUTPUT_PATH}/ecl_kw_equal ) + + +add_executable( ecl_dualp ecl_dualp.c ) +target_link_libraries( ecl_dualp ecl test_util ) +add_test( ecl_dualp ${EXECUTABLE_OUTPUT_PATH}/ecl_dualp ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2 ) + +add_executable( ecl_util_month_range ecl_util_month_range.c ) +target_link_libraries( ecl_util_month_range ecl test_util ) +add_test( ecl_util_month_range ${EXECUTABLE_OUTPUT_PATH}/ecl_util_month_range ) + +add_executable( ecl_sum_test ecl_sum_test.c ) +target_link_libraries( ecl_sum_test ecl test_util ) +add_test( ecl_sum_test ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_test ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ) + +add_executable( ecl_sum_report_step_equal ecl_sum_report_step_equal.c ) +target_link_libraries( ecl_sum_report_step_equal ecl test_util ) +add_test( ecl_sum_report_step_equal1 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre/SNORRE FALSE) +add_test( ecl_sum_report_step_equal2 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE TRUE) +add_test( ecl_sum_report_step_equal3 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/modGurbat/extraMinistep/ECLIPSE TRUE) +add_test( ecl_sum_report_step_equal4 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/modGurbat/short/ECLIPSE FALSE) +add_test( ecl_sum_report_step_equal5 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/modGurbat/enkf/ECLIPSE FALSE) +add_test( ecl_sum_report_step_equal6 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre/SNORRE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre2/SNORRE2 FALSE) + +add_executable( ecl_sum_report_step_compatible ecl_sum_report_step_compatible.c ) +target_link_libraries( ecl_sum_report_step_compatible ecl test_util ) +add_test( ecl_sum_report_step_compatible1 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_compatible ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre/SNORRE FALSE) +add_test( ecl_sum_report_step_compatible2 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_compatible ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE TRUE) +add_test( ecl_sum_report_step_compatible3 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_compatible ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/modGurbat/extraMinistep/ECLIPSE TRUE) +add_test( ecl_sum_report_step_compatible4 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_compatible ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/modGurbat/short/ECLIPSE TRUE) +add_test( ecl_sum_report_step_compatible5 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_compatible ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/modGurbat/enkf/ECLIPSE TRUE) +add_test( ecl_sum_report_step_compatible6 ${EXECUTABLE_OUTPUT_PATH}/ecl_sum_report_step_equal ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre/SNORRE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre2/SNORRE2 FALSE) + +add_executable( ecl_fortio ecl_fortio.c ) +target_link_libraries( ecl_fortio ecl test_util ) +add_test( ecl_fortio ${EXECUTABLE_OUTPUT_PATH}/ecl_fortio ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ) + +add_executable( ecl_file ecl_file.c ) +target_link_libraries( ecl_file ecl test_util ) +add_test( ecl_file ${EXECUTABLE_OUTPUT_PATH}/ecl_file ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ECLIPSE.UNRST) + +add_executable( ecl_fmt ecl_fmt.c ) +target_link_libraries( ecl_fmt ecl test_util ) +add_test( ecl_fmt ${EXECUTABLE_OUTPUT_PATH}/ecl_fmt ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.DATA) + + +add_executable( ecl_rsthead ecl_rsthead.c ) +target_link_libraries( ecl_rsthead ecl test_util ) +add_test( ecl_rsthead ${EXECUTABLE_OUTPUT_PATH}/ecl_rsthead ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/DualPoro/DUALPORO.X0005 ) + +add_executable( ecl_rft ecl_rft.c ) +target_link_libraries( ecl_rft ecl test_util ) +add_test( ecl_rft_rft ${EXECUTABLE_OUTPUT_PATH}/ecl_rft ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.RFT RFT) +add_test( ecl_rft_plt ${EXECUTABLE_OUTPUT_PATH}/ecl_rft ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/RFT/TEST1_1A.RFT PLT) +add_test( ecl_rft_plt ${EXECUTABLE_OUTPUT_PATH}/ecl_rft ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/RFT/RFT2.RFT MSW-PLT) + +add_executable( ecl_rft_cell ecl_rft_cell.c ) +target_link_libraries( ecl_rft_cell ecl test_util ) +add_test( ecl_rft_cell ${EXECUTABLE_OUTPUT_PATH}/ecl_rft_cell ) + +add_executable( ecl_get_num_cpu ecl_get_num_cpu_test.c ) +target_link_libraries( ecl_get_num_cpu ecl test_util ) +add_test( ecl_get_num_cpu ${EXECUTABLE_OUTPUT_PATH}/ecl_get_num_cpu ${PROJECT_SOURCE_DIR}/libecl/tests/data/num_cpu1 ${PROJECT_SOURCE_DIR}/libecl/tests/data/num_cpu2) + + + +set_property( TEST ecl_fmt PROPERTY LABELS StatoilData ) +set_property( TEST ecl_coarse_test PROPERTY LABELS StatoilData ) +set_property( TEST ecl_restart_test PROPERTY LABELS StatoilData ) +set_property( TEST ecl_lgr_test1 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_lgr_test2 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_lgr_test3 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_grid_lgr_name PROPERTY LABELS StatoilData ) +set_property( TEST ecl_grid_simple PROPERTY LABELS StatoilData ) +set_property( TEST ecl_dualp PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_test PROPERTY LABELS StatoilData ) + +set_property( TEST ecl_sum_report_step_equal1 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_equal2 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_equal3 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_equal4 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_equal5 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_equal6 PROPERTY LABELS StatoilData ) + +set_property( TEST ecl_sum_report_step_compatible1 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_compatible2 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_compatible3 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_compatible4 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_compatible5 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_sum_report_step_compatible6 PROPERTY LABELS StatoilData ) + +set_property( TEST ecl_fortio PROPERTY LABELS StatoilData) +set_property( TEST ecl_grid_dims1 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_grid_dims2 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_grid_dims3 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_grid_dims4 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_grid_dims5 PROPERTY LABELS StatoilData ) +set_property( TEST ecl_nnc_test PROPERTY LABELS StatoilData ) +set_property( TEST ecl_file PROPERTY LABELS StatoilData) +set_property( TEST ecl_rsthead PROPERTY LABELS StatoilData) +set_property( TEST ecl_region PROPERTY LABELS StatoilData) +set_property( TEST ecl_region2region PROPERTY LABELS StatoilData) +set_property( TEST ecl_grid_case PROPERTY LABELS StatoilData) +set_property( TEST ecl_rft_rft PROPERTY LABELS StatoilData) +set_property( TEST ecl_rft_plt PROPERTY LABELS StatoilData) diff --git a/ThirdParty/Ert/devel/libecl_well/CMakeLists.txt b/ThirdParty/Ert/devel/libecl_well/CMakeLists.txt index 3edab07684..c59e944fce 100644 --- a/ThirdParty/Ert/devel/libecl_well/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl_well/CMakeLists.txt @@ -1,5 +1,5 @@ add_subdirectory( src ) -if (BUILD_APPLICATONS) +if (BUILD_APPLICATIONS) add_subdirectory( applications ) endif() diff --git a/ThirdParty/Ert/devel/libecl_well/applications/CMakeLists.txt b/ThirdParty/Ert/devel/libecl_well/applications/CMakeLists.txt index 4e4b78d7d6..9015221393 100644 --- a/ThirdParty/Ert/devel/libecl_well/applications/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl_well/applications/CMakeLists.txt @@ -1,8 +1,11 @@ -add_executable( well_info_test well_info_test.c ) - -set(program_list well_info_test ) +add_executable( segment_info segment_info.c ) +set(program_list segment_info ) foreach(prog ${program_list}) target_link_libraries( ${prog} ecl_well ecl) + if (USE_RUNPATH) + add_runpath( ${prog} ) + endif() + #----------------------------------------------------------------- diff --git a/ThirdParty/Ert/devel/libecl_well/applications/segment_info.c b/ThirdParty/Ert/devel/libecl_well/applications/segment_info.c new file mode 100644 index 0000000000..fa720032cc --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/applications/segment_info.c @@ -0,0 +1,105 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'segment_info.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + + +int main(int argc , char ** argv) { + const char * Xfile = argv[1]; + ecl_file_type * rst_file = ecl_file_open( Xfile , 0 ); + ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_file ); + const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 ); + const ecl_kw_type * iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0 ); + const ecl_kw_type * rseg_kw = ecl_file_iget_named_kw( rst_file , RSEG_KW , 0 ); + const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 ); + const ecl_kw_type * zwel_kw = ecl_file_iget_named_kw( rst_file , ZWEL_KW , 0 ); + + { + int well_nr; + for (well_nr = 0; well_nr < rst_head->nwells; well_nr++) { + const int zwel_offset = rst_head->nzwelz * well_nr; + char * well_name = util_alloc_strip_copy(ecl_kw_iget_ptr( zwel_kw , zwel_offset )); + + printf("=================================================================\n"); + printf("Well: %s ",well_name); + { + well_conn_collection_type * connections = well_conn_collection_alloc(); + well_segment_collection_type * segments = well_segment_collection_alloc(); + + if (well_segment_collection_load_from_kw( segments , well_nr , iwel_kw , iseg_kw , rseg_kw , rst_head )) { + well_branch_collection_type * branches = well_branch_collection_alloc(); + + well_conn_collection_load_from_kw( connections , iwel_kw , icon_kw , well_nr , rst_head); + well_segment_collection_link( segments ); + well_segment_collection_add_branches( segments , branches ); + well_segment_collection_add_connections( segments , ECL_GRID_GLOBAL_GRID , connections ); + + printf("\n"); + printf("Segments:\n"); + { + int is; + for (is=0; is < well_segment_collection_get_size( segments ); is++) { + well_segment_type * segment = well_segment_collection_iget( segments , is ); + printf("-----------------------------------------------------------------\n"); + printf("ID : %d \n",well_segment_get_id( segment )); + printf("Outlet : %d \n",well_segment_get_outlet_id( segment )); + printf("Branch : %d \n",well_segment_get_branch_id( segment )); + printf("Connections : ["); + { + const well_conn_collection_type * connections = well_segment_get_global_connections( segment ); + if (connections) { + int ic; + for (ic = 0; ic < well_conn_collection_get_size( connections ); ic++) { + const well_conn_type * conn = well_conn_collection_iget( connections , ic ); + printf("(%d , %d , %d) ",well_conn_get_i( conn ), well_conn_get_j( conn ), well_conn_get_k( conn )); + } + } + } + + printf("]\n"); + } + } + well_branch_collection_free( branches ); + } else + printf("not MSW well\n\n"); + + well_conn_collection_free( connections ); + well_segment_collection_free( segments ); + } + } + } + + ecl_file_close( rst_file ); + ecl_rsthead_free( rst_head ); +} diff --git a/ThirdParty/Ert/devel/libecl_well/applications/well_info_test.c b/ThirdParty/Ert/devel/libecl_well/applications/well_info_test.c deleted file mode 100644 index 2ecfa829cd..0000000000 --- a/ThirdParty/Ert/devel/libecl_well/applications/well_info_test.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'well_info_test.c' is part of ERT - Ensemble based Reservoir Tool. - - ERT 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. - - ERT 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 -#include - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -int main( int argc , char ** argv) { - signal(SIGSEGV , util_abort_signal); /* Segmentation violation, i.e. overwriting memory ... */ - signal(SIGTERM , util_abort_signal); /* If killing the enkf program with SIGTERM (the default kill signal) you will get a backtrace. - Killing with SIGKILL (-9) will not give a backtrace.*/ - signal(SIGABRT , util_abort_signal); /* Signal abort. */ - { - well_info_type * well_info = well_info_alloc( NULL ); - int i; - for (i=1; i < argc; i++) { - printf("Loading file: %s \n",argv[i]); - well_info_load_rstfile( well_info , argv[i]); - } - - // List all wells: - { - int iwell; - for (iwell = 0; iwell < well_info_get_num_wells( well_info ); iwell++) { - well_ts_type * well_ts = well_info_get_ts( well_info , well_info_iget_well_name( well_info , iwell)); - well_state_type * well_state = well_ts_get_last_state( well_ts ); - - well_state_summarize( well_state , stdout ); - printf("\n"); - } - } - well_info_free( well_info ); - exit(1); - - // Look at the timeseries for one well: - { - well_ts_type * well_ts = well_info_get_ts( well_info , well_info_iget_well_name( well_info , 0)); - int i; - for (i =0; i < well_ts_get_size( well_ts ); i++) { - well_state_type * well_state = well_ts_iget_state( well_ts , i ); - - printf("Well:%s report:%04d state:",well_state_get_name( well_state ), well_state_get_report_nr( well_state )); - if (well_state_is_open( well_state )) - printf("OPEN\n"); - else - printf("CLOSED\n"); - } - } - - // Look at one well_state: - { - well_state_type * well_state = well_info_iiget_state( well_info , 0 , 0 ); - printf("Well:%s report:%04d \n",well_state_get_name( well_state ), well_state_get_report_nr( well_state )); - { - const well_conn_type ** connections = well_state_get_connections( well_state , 0 ); - printf("Branches: %d \n",well_state_get_num_branches( well_state )); - printf("num_connections: %d \n",well_state_get_num_connections( well_state , 0 )); - { - int iconn; - for (iconn = 0; iconn < well_state_get_num_connections( well_state , 0 ); iconn++) { - const well_conn_type * conn = connections[ iconn ]; - printf("Connection:%02d i=%3d j=%3d k=%3d State:",iconn , well_conn_get_i( conn ) , well_conn_get_j( conn ) , well_conn_get_k( conn )); - if (well_conn_open( conn ) ) - printf("Open\n"); - else - printf("Closed\n"); - } - } - } - } - well_info_free( well_info ); - } -} diff --git a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_branch.h b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_branch.h deleted file mode 100644 index f876ba370f..0000000000 --- a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_branch.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - Copyright (C) 2012 Statoil ASA, Norway. - - The file 'well_branch.h' is part of ERT - Ensemble based Reservoir Tool. - - ERT 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. - - ERT 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. -*/ - -#ifndef __WELL_BRANCH_H__ -#define __WELL_BRANCH_H__ - - -#ifdef __cplusplus -extern "C" { -#endif - -#include - - typedef struct well_branch_struct well_branch_type; - - well_branch_type * well_branch_alloc(int branch_nr); - void well_branch_free( well_branch_type * branch ); - void well_branch_add_conn( well_branch_type * branch , well_conn_type * connection ); - int well_branch_get_length( const well_branch_type * branch ); - const well_conn_type ** well_branch_get_connections( const well_branch_type * branch ); - int well_branch_get_nr( const well_branch_type * branch ); - -#ifdef __cplusplus -} -#endif -#endif - diff --git a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_branch_collection.h b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_branch_collection.h new file mode 100644 index 0000000000..de472c3dbd --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_branch_collection.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_branch_collection.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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. +*/ + + +#ifndef __WELL_BRANCH_COLLECTION_H__ +#define __WELL_BRANCH_COLLECTION_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include + +#include + + typedef struct well_branch_collection_struct well_branch_collection_type; + + well_branch_collection_type * well_branch_collection_alloc(); + void well_branch_collection_free( well_branch_collection_type * branches ); + void well_branch_collection_free__( void * arg ); + bool well_branch_collection_has_branch( const well_branch_collection_type * branches , int branch_id); + int well_branch_collection_get_size( const well_branch_collection_type * branches ); + const well_segment_type * well_branch_collection_iget_start_segment( const well_branch_collection_type * branches , int index ); + const well_segment_type * well_branch_collection_get_start_segment( const well_branch_collection_type * branches , int branch_id); + bool well_branch_collection_add_start_segment( well_branch_collection_type * branches , const well_segment_type * start_segment); + + UTIL_IS_INSTANCE_HEADER( well_branch_collection ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_conn.h b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_conn.h index f6b1194cca..d2c2fd2a17 100644 --- a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_conn.h +++ b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_conn.h @@ -27,6 +27,8 @@ extern "C" { #include +#include + #include typedef enum { @@ -43,10 +45,17 @@ extern "C" { void well_conn_free( well_conn_type * conn); void well_conn_free__( void * arg ); - well_conn_type * well_conn_alloc( const ecl_kw_type * icon_kw , const ecl_kw_type * iseg_kw , const ecl_rsthead_type * header , int well_nr , int seg_well_nr , int conn_nr); + + well_conn_type * well_conn_alloc( int i , int j , int k , well_conn_dir_enum dir, bool open); + well_conn_type * well_conn_alloc_MSW( int i , int j , int k , well_conn_dir_enum dir, bool open, int segment); + well_conn_type * well_conn_alloc_fracture( int i , int j , int k , well_conn_dir_enum dir, bool open); + well_conn_type * well_conn_alloc_fracture_MSW( int i , int j , int k , well_conn_dir_enum dir, bool open, int segment); + + bool well_conn_MSW(const well_conn_type * conn); + + well_conn_type * well_conn_alloc_from_kw( const ecl_kw_type * icon_kw , const ecl_rsthead_type * header , int well_nr , int conn_nr); well_conn_type * well_conn_alloc_wellhead( const ecl_kw_type * iwel_kw , const ecl_rsthead_type * header , int well_nr); - int well_conn_get_branch(const well_conn_type * conn); int well_conn_get_i(const well_conn_type * conn); int well_conn_get_j(const well_conn_type * conn); int well_conn_get_k(const well_conn_type * conn); @@ -55,6 +64,11 @@ extern "C" { int well_conn_get_segment( const well_conn_type * conn ); bool well_conn_fracture_connection( const well_conn_type * conn); bool well_conn_matrix_connection( const well_conn_type * conn); + bool well_conn_equal( const well_conn_type *conn1 , const well_conn_type * conn2); + + UTIL_IS_INSTANCE_HEADER( well_conn ); + UTIL_SAFE_CAST_HEADER( well_conn ); + #ifdef __cplusplus } diff --git a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_conn_collection.h b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_conn_collection.h new file mode 100644 index 0000000000..3357c61a8d --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_conn_collection.h @@ -0,0 +1,51 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_conn_collection.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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. +*/ + + +#ifndef __WELL_CONN_COLLECTION_H__ +#define __WELL_CONN_COLLECTION_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include + +#include + + typedef struct well_conn_collection_struct well_conn_collection_type; + + well_conn_collection_type * well_conn_collection_alloc(); + void well_conn_collection_free( well_conn_collection_type * wellcc ); + void well_conn_collection_free__( void * arg ); + int well_conn_collection_get_size( const well_conn_collection_type * wellcc ); + const well_conn_type * well_conn_collection_iget_const( const well_conn_collection_type * wellcc , int index); + well_conn_type * well_conn_collection_iget(const well_conn_collection_type * wellcc , int index); + void well_conn_collection_add( well_conn_collection_type * wellcc , well_conn_type * conn); + void well_conn_collection_add_ref( well_conn_collection_type * wellcc , well_conn_type * conn); + int well_conn_collection_load_from_kw( well_conn_collection_type * wellcc , const ecl_kw_type * iwel_kw , const ecl_kw_type * icon_kw , int iwell , const ecl_rsthead_type * rst_head); + + UTIL_IS_INSTANCE_HEADER( well_conn_collection ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_const.h b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_const.h index e7319067a5..3fca6fa5c6 100644 --- a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_const.h +++ b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_const.h @@ -39,6 +39,8 @@ extern "C" { #define IWEL_LGR_ITEM 42 #define IWEL_SEGMENTED_WELL_NR_ITEM 70 +#define IWEL_SEGMENTED_WELL_NR_NORMAL_VALUE -1 + #define ISEG_OUTLET_ITEM 1 #define ISEG_BRANCH_ITEM 3 @@ -59,6 +61,11 @@ extern "C" { #define ICON_DEFAULT_DIR_TARGET ICON_DIRZ +#define RSEG_LENGTH_INDEX 0 +#define RSEG_DIAMETER_INDEX 2 +#define RSEG_TOTAL_LENGTH_INDEX 6 +#define RSEG_DEPTH_INDEX 7 + /* The ECLIPSE documentation says that a certain item in the IWEL array should indicate the type of the well, the available types are the diff --git a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_path.h b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_path.h deleted file mode 100644 index 69a4607112..0000000000 --- a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_path.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright (C) 2012 Statoil ASA, Norway. - - The file 'well_path.h' is part of ERT - Ensemble based Reservoir Tool. - - ERT 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. - - ERT 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. -*/ - -#ifndef __WELL_PATH_H__ -#define __WELL_PATH_H__ - - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include -#include - - - typedef struct well_path_struct well_path_type; - - well_path_type * well_path_alloc(const char * grid_name ); - void well_path_free( well_path_type * path ); - void well_path_add_conn( well_path_type * well_path , well_conn_type * conn); - well_branch_type * well_path_iget_branch( const well_path_type * well_path , int branch_nr); - void well_path_free__(void * arg); - int well_path_get_max_branches( const well_path_type * well_path ); - int well_path_get_num_active_branches( const well_path_type * well_path ); - const char * well_path_get_grid_name( const well_path_type * well_path ); - -#ifdef __cplusplus -} -#endif -#endif - diff --git a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_segment.h b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_segment.h new file mode 100644 index 0000000000..689af32cf2 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_segment.h @@ -0,0 +1,79 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_segment.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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. +*/ + + +#ifndef __WELL_SEGMENT_H__ +#define __WELL_SEGMENT_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include + +#include +#include + + /* The values are shifted one down compared to ISEG description in table 6.1 in ECLIPSE file formats reference. */ + +#define ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE -1 +#define ECLIPSE_WELL_SEGMENT_BRANCH_MAIN_STEM_VALUE 0 +#define ECLIPSE_WELL_SEGMENT_BRANCH_INACTIVE_VALUE -1 + + + + typedef struct well_segment_struct well_segment_type; + + well_segment_type * well_segment_alloc_from_kw( const ecl_kw_type * iseg_kw , const ecl_kw_type * rseg_kw , const ecl_rsthead_type * header , int well_nr, int segment_id); + well_segment_type * well_segment_alloc(int segment_id , int outlet_segment_id , int branch_id , const double * rseg_data); + void well_segment_free(well_segment_type * segment ); + void well_segment_free__(void * arg); + + bool well_segment_active( const well_segment_type * segment ); + bool well_segment_main_stem( const well_segment_type * segment ); + bool well_segment_nearest_wellhead( const well_segment_type * segment ); + + int well_segment_get_link_count( const well_segment_type * segment ); + int well_segment_get_branch_id( const well_segment_type * segment ); + int well_segment_get_outlet_id( const well_segment_type * segment ); + int well_segment_get_id( const well_segment_type * segment ); + well_segment_type * well_segment_get_outlet( const well_segment_type * segment ); + bool well_segment_link( well_segment_type * segment , well_segment_type * outlet_segment ); + void well_segment_link_strict( well_segment_type * segment , well_segment_type * outlet_segment ); + bool well_segment_has_grid_connections( const well_segment_type * segment , const char * grid_name); + bool well_segment_has_global_grid_connections( const well_segment_type * segment); + bool well_segment_add_connection( well_segment_type * segment , const char * grid_name , well_conn_type * conn); + const well_conn_collection_type * well_segment_get_connections(const well_segment_type * segment , const char * grid_name ); + const well_conn_collection_type * well_segment_get_global_connections(const well_segment_type * segment ); + bool well_segment_well_is_MSW(int well_nr , const ecl_kw_type * iwel_kw , const ecl_rsthead_type * rst_head); + + double well_segment_get_depth( const well_segment_type * segment ); + double well_segment_get_length( const well_segment_type * segment ); + double well_segment_get_total_length( const well_segment_type * segment ); + double well_segment_get_diameter( const well_segment_type * segment ); + + UTIL_IS_INSTANCE_HEADER( well_segment ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_segment_collection.h b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_segment_collection.h new file mode 100644 index 0000000000..3a2e1b8deb --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_segment_collection.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_segment_collection.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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. +*/ + + +#ifndef __WELL_SEGMENT_COLLECTION_H__ +#define __WELL_SEGMENT_COLLECTION_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include + +#include +#include +#include + + typedef struct well_segment_collection_struct well_segment_collection_type; + + well_segment_collection_type * well_segment_collection_alloc(); + void well_segment_collection_free(well_segment_collection_type * segment_collection ); + int well_segment_collection_get_size( const well_segment_collection_type * segment_collection ); + void well_segment_collection_add( well_segment_collection_type * segment_collection , well_segment_type * segment); + bool well_segment_collection_has_segment( const well_segment_collection_type * segment_collection , int segment_id); + well_segment_type * well_segment_collection_get( const well_segment_collection_type * segment_collection , int segment_id); + well_segment_type * well_segment_collection_iget( const well_segment_collection_type * segment_collection , int index); + int well_segment_collection_load_from_kw( well_segment_collection_type * segment_collection , int well_nr , + const ecl_kw_type * iwel_kw , + const ecl_kw_type * iseg_kw , + const ecl_kw_type * rseg_kw , + const ecl_rsthead_type * rst_head); + void well_segment_collection_link(const well_segment_collection_type * segment_collection); + void well_segment_collection_add_connections(well_segment_collection_type * segment_collection , + const char * grid_name , + const well_conn_collection_type * connections); + void well_segment_collection_add_branches( const well_segment_collection_type * segment_collection , + well_branch_collection_type * branches ); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_state.h b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_state.h index 0db96bc313..8481573e8c 100644 --- a/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_state.h +++ b/ThirdParty/Ert/devel/libecl_well/include/ert/ecl_well/well_state.h @@ -27,16 +27,37 @@ extern "C" { #include #include +#include #include #include +#include +#include +#include #define GLOBAL_GRID_NAME "GLOBAL" // The name assigned to the global grid for name based lookup. typedef struct well_state_struct well_state_type; - well_state_type * well_state_alloc( ecl_file_type * ecl_file , int report_step , int well_nr); + well_state_type * well_state_alloc(const char * well_name , int global_well_nr , bool open, well_type_enum type , int report_nr, time_t valid_from); + well_state_type * well_state_alloc_from_file( ecl_file_type * ecl_file , const ecl_grid_type * grid , int report_step , int well_nr); + + void well_state_add_connections( well_state_type * well_state , + const ecl_grid_type * grid , + ecl_file_type * rst_file , + int well_nr); + + bool well_state_add_MSW( well_state_type * well_state , + const ecl_file_type * rst_file , + int well_nr); + + bool well_state_is_MSW( const well_state_type * well_state); + + well_segment_collection_type * well_state_get_segments( const well_state_type * well_state ); + well_branch_collection_type * well_state_get_branches( const well_state_type * well_state ); + + void well_state_free( well_state_type * well ); const char * well_state_get_name( const well_state_type * well ); int well_state_get_report_nr( const well_state_type * well_state ); @@ -44,24 +65,18 @@ extern "C" { well_conn_type * well_state_iget_connection( const well_state_type * well_state , int index); well_type_enum well_state_get_type( const well_state_type * well_state); bool well_state_is_open( const well_state_type * well_state ); - + int well_state_get_well_nr( const well_state_type * well_state ); + const well_conn_type * well_state_iget_wellhead( const well_state_type * well_state , int grid_nr); const well_conn_type * well_state_get_wellhead( const well_state_type * well_state , const char * grid_name); - - const well_conn_type ** well_state_iget_lgr_connections(const well_state_type * well_state , int grid_nr , int branch_nr ); - const well_conn_type ** well_state_get_lgr_connections(const well_state_type * well_state , const char * lgr_name , int branch_nr); - const well_conn_type ** well_state_get_connections(const well_state_type * well_state , int branch_nr ); - - int well_state_iget_num_lgr_connections(const well_state_type * well_state , int grid_nr , int branch_nr ); - int well_state_get_num_lgr_connections(const well_state_type * well_state , const char * lgr_name , int branch_nr); - int well_state_get_num_connections(const well_state_type * well_state , int branch_nr ); - - int well_state_iget_lgr_num_branches( const well_state_type * well_state , int grid_nr); - int well_state_get_lgr_num_branches( const well_state_type * well_state , const char * lgr_name); - int well_state_get_num_branches(const well_state_type * well_state ); - void well_state_summarize( const well_state_type * well_state , FILE * stream ); + well_type_enum well_state_translate_ecl_type_int(int int_type); + + const well_conn_collection_type * well_state_get_grid_connections( const well_state_type * well_state , const char * grid_name); + const well_conn_collection_type * well_state_get_global_connections( const well_state_type * well_state ); + bool well_state_has_grid_connections( const well_state_type * well_state , const char * grid_name); + bool well_state_has_global_connections( const well_state_type * well_state ); UTIL_IS_INSTANCE_HEADER( well_state ); diff --git a/ThirdParty/Ert/devel/libecl_well/src/CMakeLists.txt b/ThirdParty/Ert/devel/libecl_well/src/CMakeLists.txt index 59182ea3c8..88d84809de 100644 --- a/ThirdParty/Ert/devel/libecl_well/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl_well/src/CMakeLists.txt @@ -1,5 +1,10 @@ -set( source_files well_state.c well_conn.c well_info.c well_ts.c well_branch.c well_path.c ) -set( header_files well_state.h well_const.h well_conn.h well_info.h well_ts.h well_branch.h well_path.h ) +set( source_files well_state.c well_conn.c well_info.c well_ts.c well_conn_collection.c well_segment.c well_segment_collection.c well_branch_collection.c) +set( header_files well_state.h well_const.h well_conn.h well_info.h well_ts.h well_conn_collection.h well_segment.h well_segment_collection.h well_branch_collection.h) + +if (NOT ERT_WINDOWS) + set_property( SOURCE well_branch_collection.c well_segment.c well_segment_collection.c well_conn_collection.c well_conn.c PROPERTY COMPILE_FLAGS "-Werror") +endif() + include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ) include_directories( ${libgeometry_src_path} ) @@ -8,6 +13,10 @@ include_directories( ${libgeometry_src_path} ) add_library( ecl_well ${LIBRARY_TYPE} ${source_files} ) set_target_properties( ecl_well PROPERTIES VERSION 1.0 SOVERSION 1.0 ) target_link_libraries( ecl_well ecl ) +if (USE_RUNPATH) + add_runpath( ecl_well ) +endif() + #----------------------------------------------------------------- if (INSTALL_ERT) diff --git a/ThirdParty/Ert/devel/libecl_well/src/well_branch.c b/ThirdParty/Ert/devel/libecl_well/src/well_branch.c deleted file mode 100644 index dd2ccd8416..0000000000 --- a/ThirdParty/Ert/devel/libecl_well/src/well_branch.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - Copyright (C) 2012 Statoil ASA, Norway. - - The file 'well_branch.c' is part of ERT - Ensemble based Reservoir Tool. - - ERT 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. - - ERT 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 - -#include -#include -#include - -/* - - See also documentation on the top of well_path.c for how a path and - a branch are related. -*/ - -struct well_branch_struct { - int branch_nr; - well_conn_type ** connections; - int size; - int alloc_size; -}; - - -static void well_branch_resize( well_branch_type * branch , int new_size) { - if (new_size < branch->alloc_size) - util_abort("%s: sorry - can only grow \n",__func__); - - branch->connections = util_realloc( branch->connections , new_size * sizeof * branch->connections ); - { - int i; - for (i=branch->alloc_size; i < new_size; i++) - branch->connections[i] = NULL; - } - branch->alloc_size = new_size; -} - - -well_branch_type * well_branch_alloc(int branch_nr) { - well_branch_type * branch = util_malloc( sizeof * branch ); - branch->branch_nr = branch_nr; - branch->connections = NULL; - branch->alloc_size = 0; - branch->size = 0; - - well_branch_resize( branch , 10 ); - return branch; -} - - -void well_branch_free( well_branch_type * branch ) { - int i; - for ( i=0; i < branch->alloc_size; i++) { - well_conn_type * conn = branch->connections[i]; - if (conn != NULL) - well_conn_free( conn ); - } - free( branch->connections ); - free( branch ); -} - - -int well_branch_get_length( const well_branch_type * branch) { - return branch->size; -} - - -const well_conn_type ** well_branch_get_connections( const well_branch_type * branch ) { - if (branch->size == 0) - return NULL; - else - return (const well_conn_type **) branch->connections; -} - - -void well_branch_add_conn( well_branch_type * branch, well_conn_type * connection ) { - if (branch->size == branch->alloc_size) - well_branch_resize(branch , 2*( 1 + branch->alloc_size )); - branch->connections[ branch->size ] = connection; - branch->size++; -} - - -int well_branch_get_nr( const well_branch_type * branch ) { - return branch->branch_nr; -} - diff --git a/ThirdParty/Ert/devel/libecl_well/src/well_branch_collection.c b/ThirdParty/Ert/devel/libecl_well/src/well_branch_collection.c new file mode 100644 index 0000000000..0e514cb6fb --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/src/well_branch_collection.c @@ -0,0 +1,117 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_branch_collection.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include +#include +#include + +#include +#include +#include + + +#define WELL_BRANCH_COLLECTION_TYPE_ID 67177087 + +struct well_branch_collection_struct { + UTIL_TYPE_ID_DECLARATION; + + vector_type * __start_segments; + int_vector_type * index_map; +}; + + +UTIL_IS_INSTANCE_FUNCTION( well_branch_collection , WELL_BRANCH_COLLECTION_TYPE_ID ) +static UTIL_SAFE_CAST_FUNCTION( well_branch_collection , WELL_BRANCH_COLLECTION_TYPE_ID ) + + +well_branch_collection_type * well_branch_collection_alloc() { + well_branch_collection_type * branch_collection = util_malloc( sizeof * branch_collection ); + UTIL_TYPE_ID_INIT( branch_collection , WELL_BRANCH_COLLECTION_TYPE_ID ); + branch_collection->__start_segments = vector_alloc_new(); + branch_collection->index_map = int_vector_alloc(0 , -1 ); + return branch_collection; +} + + + +void well_branch_collection_free( well_branch_collection_type * branches ) { + vector_free( branches->__start_segments ); + int_vector_free( branches->index_map ); + free( branches ); +} + + + +void well_branch_collection_free__( void * arg ) { + well_branch_collection_type * branches = well_branch_collection_safe_cast( arg ); + well_branch_collection_free( branches ); +} + + +int well_branch_collection_get_size( const well_branch_collection_type * branches ) { + return vector_get_size( branches->__start_segments ); +} + + +bool well_branch_collection_has_branch( const well_branch_collection_type * branches , int branch_id) { + if (int_vector_safe_iget( branches->index_map , branch_id) >= 0) + return true; + else + return false; +} + + + +const well_segment_type * well_branch_collection_iget_start_segment( const well_branch_collection_type * branches , int index ) { + if (index < vector_get_size( branches->__start_segments)) + return vector_iget_const( branches->__start_segments , index); + else + return NULL; +} + + + +const well_segment_type * well_branch_collection_get_start_segment( const well_branch_collection_type * branches , int branch_id) { + int internal_index = int_vector_safe_iget( branches->index_map , branch_id); + if (internal_index >= 0) + return well_branch_collection_iget_start_segment( branches , internal_index ); + else + return NULL; +} + + +bool well_branch_collection_add_start_segment( well_branch_collection_type * branches , const well_segment_type * start_segment) { + if ((well_segment_get_link_count( start_segment ) == 0) && (well_segment_get_outlet(start_segment))) { + int branch_id = well_segment_get_branch_id( start_segment ); + int current_index = int_vector_safe_iget( branches->index_map , branch_id); + if (current_index >= 0) + vector_iset_ref( branches->__start_segments , current_index , start_segment); + else { + int new_index = vector_get_size( branches->__start_segments ); + vector_append_ref( branches->__start_segments , start_segment); + int_vector_iset( branches->index_map , branch_id , new_index); + } + + return true; + } else + return false; +} + diff --git a/ThirdParty/Ert/devel/libecl_well/src/well_conn.c b/ThirdParty/Ert/devel/libecl_well/src/well_conn.c index 0d10cd786d..bc2e536948 100644 --- a/ThirdParty/Ert/devel/libecl_well/src/well_conn.c +++ b/ThirdParty/Ert/devel/libecl_well/src/well_conn.c @@ -17,8 +17,10 @@ */ #include +#include #include +#include #include #include @@ -26,110 +28,151 @@ #include #include + +#define WELL_CONN_NORMAL_WELL_SEGMENT_ID -999 +#define ECLIPSE_NORMAL_WELL_SEGMENT_ID -1 + /* Observe that when the (ijk) values are initialized they are shifted to zero offset values, to be aligned with the rest of the ert libraries. */ +#define WELL_CONN_TYPE_ID 702052013 + struct well_conn_struct { - int i; - int j; - int k; - well_conn_dir_enum dir; - bool open; - int segment; // -1: Ordinary well - bool matrix_connection; // k >= nz => fracture (and k -= nz ) - /*-----------------------------------------------------------------*/ - /* If the segment field == -1 - i.e. an ordinary well, the - outlet_segment is rubbish and should not be consulted. - */ - int branch; - int outlet_segment; // -1: This segment flows to the wellhead. + UTIL_TYPE_ID_DECLARATION; + int i; + int j; + int k; + well_conn_dir_enum dir; + bool open; + int segment; // -1: Ordinary well + bool matrix_connection; // k >= nz => fracture (and k -= nz ) }; -static void well_conn_set_k( well_conn_type * conn , const ecl_rsthead_type * header , int icon_k) { - conn->k = icon_k; - conn->matrix_connection = true; - if (header->dualp) { - int geometric_nz = header->nz / 2; - if (icon_k >= geometric_nz) { - conn->k -= geometric_nz; - conn->matrix_connection = false; - } - } +bool well_conn_equal( const well_conn_type *conn1 , const well_conn_type * conn2) { + if (memcmp(conn1 , conn2 , sizeof * conn1) == 0) + return true; + else + return false; } +bool well_conn_MSW( const well_conn_type * conn ) { + if (conn->segment == WELL_CONN_NORMAL_WELL_SEGMENT_ID) + return false; + else + return true; +} + +static bool well_conn_assert_direction( well_conn_dir_enum dir, bool matrix_connection) { + if ((dir == well_conn_fracX || dir == well_conn_fracY) && matrix_connection) + return false; + else + return true; +} -well_conn_type * well_conn_alloc_wellhead( const ecl_kw_type * iwel_kw , const ecl_rsthead_type * header , int well_nr) { - const int iwel_offset = header->niwelz * well_nr; - int conn_i = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_HEADI_ITEM ); - - if (conn_i > 0) { +UTIL_IS_INSTANCE_FUNCTION( well_conn , WELL_CONN_TYPE_ID) +UTIL_SAFE_CAST_FUNCTION( well_conn , WELL_CONN_TYPE_ID) + + +static well_conn_type * well_conn_alloc__( int i , int j , int k , well_conn_dir_enum dir , bool open, int segment_id, bool matrix_connection) { + if (well_conn_assert_direction( dir , matrix_connection)) { well_conn_type * conn = util_malloc( sizeof * conn ); + UTIL_TYPE_ID_INIT( conn , WELL_CONN_TYPE_ID ); + conn->i = i; + conn->j = j; + conn->k = k; + conn->open = open; + conn->dir = dir; - conn->i = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_HEADI_ITEM ) - 1; - conn->j = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_HEADJ_ITEM ) - 1; - { - int icon_k = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_HEADK_ITEM ) - 1; - well_conn_set_k( conn , header , icon_k); - } - - conn->open = true; // This is not really specified anywhere. - conn->branch = 0; - conn->segment = 0; - conn->outlet_segment = 0; + conn->matrix_connection = matrix_connection; + if (segment_id == ECLIPSE_NORMAL_WELL_SEGMENT_ID) + conn->segment = WELL_CONN_NORMAL_WELL_SEGMENT_ID; + else + conn->segment = segment_id; + return conn; - } else - // The well is completed in this LGR - however the wellhead is in another LGR. + } else { + printf("assert-direction failed. dir:%d matrix_connection:%d \n",dir , matrix_connection); return NULL; -} - - -static well_conn_type * well_conn_alloc__( const ecl_kw_type * icon_kw , const ecl_rsthead_type * header , int icon_offset) { - well_conn_type * conn = util_malloc( sizeof * conn ); - - conn->i = ecl_kw_iget_int( icon_kw , icon_offset + ICON_I_ITEM ) - 1; - conn->j = ecl_kw_iget_int( icon_kw , icon_offset + ICON_J_ITEM ) - 1; - { - int icon_k = ecl_kw_iget_int( icon_kw , icon_offset + ICON_K_ITEM ) - 1; - well_conn_set_k( conn , header , icon_k); } - - conn->segment = ecl_kw_iget_int( icon_kw , icon_offset + ICON_SEGMENT_ITEM ) - 1; - - conn->outlet_segment = -999; - conn->branch = -999; - return conn; } + +well_conn_type * well_conn_alloc( int i , int j , int k , well_conn_dir_enum dir , bool open) { + return well_conn_alloc__(i , j , k , dir , open , WELL_CONN_NORMAL_WELL_SEGMENT_ID , true ); +} + + + +well_conn_type * well_conn_alloc_MSW( int i , int j , int k , well_conn_dir_enum dir , bool open, int segment) { + return well_conn_alloc__(i , j , k , dir , open , segment , true ); +} + + + +well_conn_type * well_conn_alloc_fracture( int i , int j , int k , well_conn_dir_enum dir , bool open) { + return well_conn_alloc__(i , j , k , dir , open , WELL_CONN_NORMAL_WELL_SEGMENT_ID , false); +} + + + +well_conn_type * well_conn_alloc_fracture_MSW( int i , int j , int k , well_conn_dir_enum dir , bool open, int segment) { + return well_conn_alloc__(i , j , k , dir , open , segment , false); +} + + + + /* Observe that the (ijk) and branch values are shifted to zero offset to be aligned with the rest of the ert libraries. */ -well_conn_type * well_conn_alloc( const ecl_kw_type * icon_kw , - const ecl_kw_type * iseg_kw , - const ecl_rsthead_type * header , - int well_nr , - int seg_well_nr , - int conn_nr ) { +well_conn_type * well_conn_alloc_from_kw( const ecl_kw_type * icon_kw , + const ecl_rsthead_type * header , + int well_nr , + int conn_nr ) { const int icon_offset = header->niconz * ( header->ncwmax * well_nr + conn_nr ); int IC = ecl_kw_iget_int( icon_kw , icon_offset + ICON_IC_ITEM ); if (IC > 0) { - well_conn_type * conn = well_conn_alloc__( icon_kw , header , icon_offset ); + well_conn_type * conn; + int i = ecl_kw_iget_int( icon_kw , icon_offset + ICON_I_ITEM ) - 1; + int j = ecl_kw_iget_int( icon_kw , icon_offset + ICON_J_ITEM ) - 1; + int k = ecl_kw_iget_int( icon_kw , icon_offset + ICON_K_ITEM ) - 1; + int segment = ecl_kw_iget_int( icon_kw , icon_offset + ICON_SEGMENT_ITEM ) - 1; + bool matrix_connection = true; + bool open; + well_conn_dir_enum dir = well_conn_fracX; + + /* Set the status */ { int int_status = ecl_kw_iget_int( icon_kw , icon_offset + ICON_STATUS_ITEM ); if (int_status > 0) - conn->open = true; + open = true; else - conn->open = false; + open = false; } + + /* Set the K value and fracture flag. */ + { + if (header->dualp) { + int geometric_nz = header->nz / 2; + if (k >= geometric_nz) { + k -= geometric_nz; + matrix_connection = false; + } + } + } + + + /* Set the direction flag */ { int int_direction = ecl_kw_iget_int( icon_kw , icon_offset + ICON_DIRECTION_ITEM ); if (int_direction == ICON_DEFAULT_DIR_VALUE) @@ -137,25 +180,27 @@ well_conn_type * well_conn_alloc( const ecl_kw_type * icon_kw , switch (int_direction) { case(ICON_DIRX): - conn->dir = well_conn_dirX; + dir = well_conn_dirX; break; case(ICON_DIRY): - conn->dir = well_conn_dirY; + dir = well_conn_dirY; break; case(ICON_DIRZ): - conn->dir = well_conn_dirZ; + dir = well_conn_dirZ; break; case(ICON_FRACX): - conn->dir = well_conn_fracX; + dir = well_conn_fracX; break; case(ICON_FRACY): - conn->dir = well_conn_fracY; + dir = well_conn_fracY; break; default: util_abort("%s: icon direction value:%d not recognized\n",__func__ , int_direction); } } - + + conn = well_conn_alloc__(i,j,k,dir,open,segment,matrix_connection); + /** For multisegmented wells ONLY the global part of the restart file has segment information, i.e. the ?SEG @@ -163,8 +208,9 @@ well_conn_type * well_conn_alloc( const ecl_kw_type * icon_kw , MSW + LGR well. */ + /* if (iseg_kw != NULL) { - if (conn->segment >= 0) { + if (conn->segment != WELL_CONN_NORMAL_WELL_SEGMENT_ID) { const int iseg_offset = header->nisegz * ( header->nsegmx * seg_well_nr + conn->segment ); conn->outlet_segment = ecl_kw_iget_int( iseg_kw , iseg_offset + ISEG_OUTLET_ITEM ); conn->branch = ecl_kw_iget_int( iseg_kw , iseg_offset + ISEG_BRANCH_ITEM ); @@ -176,7 +222,8 @@ well_conn_type * well_conn_alloc( const ecl_kw_type * icon_kw , conn->branch = 0; conn->outlet_segment = 0; } - + */ + return conn; } else return NULL; /* IC < 0: Connection not in current LGR. */ @@ -189,11 +236,42 @@ void well_conn_free( well_conn_type * conn) { void well_conn_free__( void * arg ) { - well_conn_type * conn = (well_conn_type *) arg; + well_conn_type * conn = well_conn_safe_cast( arg ); well_conn_free( conn ); } +well_conn_type * well_conn_alloc_wellhead( const ecl_kw_type * iwel_kw , const ecl_rsthead_type * header , int well_nr) { + const int iwel_offset = header->niwelz * well_nr; + int conn_i = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_HEADI_ITEM ) - 1; + + if (conn_i >= 0) { + //well_conn_type * conn = util_malloc( sizeof * conn ); + int conn_j = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_HEADJ_ITEM ) - 1; + int conn_k = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_HEADK_ITEM ) - 1; + bool matrix_connection = true; + bool open = true; + + if (header->dualp) { + int geometric_nz = header->nz / 2; + if (conn_k >= geometric_nz) { + conn_k -= geometric_nz; + matrix_connection = false; + } + } + + if (matrix_connection) + return well_conn_alloc( conn_i , conn_j , conn_k , open , well_conn_dirZ ); + else + return well_conn_alloc_fracture( conn_i , conn_j , conn_k , open , well_conn_dirZ ); + } else + // The well is completed in this LGR - however the wellhead is in another LGR. + return NULL; +} + + + + /*****************************************************************/ @@ -210,9 +288,6 @@ int well_conn_get_k(const well_conn_type * conn) { } -int well_conn_get_branch(const well_conn_type * conn) { - return conn->branch; -} well_conn_dir_enum well_conn_get_dir(const well_conn_type * conn) { return conn->dir; @@ -222,6 +297,7 @@ bool well_conn_open( const well_conn_type * conn ) { return conn->open; } + int well_conn_get_segment( const well_conn_type * conn ) { return conn->segment; } diff --git a/ThirdParty/Ert/devel/libecl_well/src/well_conn_collection.c b/ThirdParty/Ert/devel/libecl_well/src/well_conn_collection.c new file mode 100644 index 0000000000..f409566517 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/src/well_conn_collection.c @@ -0,0 +1,115 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_conn_collection.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include +#include + +#include +#include + +#include +#include +#include + + +#define WELL_CONN_COLLECTION_TYPE_ID 67150087 + +struct well_conn_collection_struct { + UTIL_TYPE_ID_DECLARATION; + vector_type * connection_list; +}; + + +UTIL_IS_INSTANCE_FUNCTION( well_conn_collection , WELL_CONN_COLLECTION_TYPE_ID ) +static UTIL_SAFE_CAST_FUNCTION( well_conn_collection , WELL_CONN_COLLECTION_TYPE_ID ) + + +well_conn_collection_type * well_conn_collection_alloc() { + well_conn_collection_type * wellcc = util_malloc( sizeof * wellcc ); + UTIL_TYPE_ID_INIT( wellcc , WELL_CONN_COLLECTION_TYPE_ID ); + wellcc->connection_list = vector_alloc_new(); + return wellcc; +} + +/* + The collection takes ownership of the connection object and frees it + when the collection is discarded. +*/ + +void well_conn_collection_add( well_conn_collection_type * wellcc , well_conn_type * conn) { + vector_append_owned_ref( wellcc->connection_list , conn , well_conn_free__); +} + +/* + The collection only stores a refernce to the object, which will be destroyed by 'someone else'. +*/ + +void well_conn_collection_add_ref( well_conn_collection_type * wellcc , well_conn_type * conn) { + vector_append_ref( wellcc->connection_list , conn ); +} + + +void well_conn_collection_free( well_conn_collection_type * wellcc ) { + vector_free( wellcc->connection_list ); + free( wellcc ); +} + +void well_conn_collection_free__( void * arg ) { + well_conn_collection_type * wellcc = well_conn_collection_safe_cast( arg ); + well_conn_collection_free( wellcc ); +} + + +int well_conn_collection_get_size( const well_conn_collection_type * wellcc ) { + return vector_get_size( wellcc->connection_list ); +} + + +const well_conn_type * well_conn_collection_iget_const(const well_conn_collection_type * wellcc , int index) { + int size = well_conn_collection_get_size( wellcc ); + if (index < size) + return vector_iget_const( wellcc->connection_list , index ); + else + return NULL; +} + +well_conn_type * well_conn_collection_iget(const well_conn_collection_type * wellcc , int index) { + int size = well_conn_collection_get_size( wellcc ); + if (index < size) + return vector_iget( wellcc->connection_list , index ); + else + return NULL; +} + + +int well_conn_collection_load_from_kw( well_conn_collection_type * wellcc , const ecl_kw_type * iwel_kw , const ecl_kw_type * icon_kw , int iwell , const ecl_rsthead_type * rst_head) { + const int iwel_offset = rst_head->niwelz * iwell; + int num_connections = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_CONNECTIONS_ITEM ); + int iconn; + + for (iconn = 0; iconn < num_connections; iconn++) { + well_conn_type * conn = well_conn_alloc_from_kw( icon_kw , rst_head , iwell , iconn ); + if (conn) + well_conn_collection_add( wellcc , conn ); + } + return num_connections; +} + diff --git a/ThirdParty/Ert/devel/libecl_well/src/well_info.c b/ThirdParty/Ert/devel/libecl_well/src/well_info.c index 4c2c13abed..4980c22ded 100644 --- a/ThirdParty/Ert/devel/libecl_well/src/well_info.c +++ b/ThirdParty/Ert/devel/libecl_well/src/well_info.c @@ -52,22 +52,9 @@ contains a time series for one well. well_state_type: The well_state_type datatype contains the - state/properties of one well at one particular instant of time. - - well_path_type: The well_path_type datatype hold information about - the path of the well, i.e. which cells it goes through. The - well_path_type instance is for one grid only; and if the well - goes through LGRs the well_state instance contains one - well_path instance for the global grid and additional well_path - instances for each LGR. - - well_branch_type: The wells can be split into several - branches. The well_branch_type datatype contain a collection of - well connections which form a 1-dimensional segment. - - well_conn_type: This is the connection of a well to one cell. This - datatype is exported, i.e. calling scope can inspect - (read-only!) the members of a well_conn_type instance. + state/properties of one well at one particular instant of + time. The well_state.c file contains further documentation of + the concepts connections, branches and segments. WELL1 @@ -279,18 +266,18 @@ static void well_info_add_state( well_info_type * well_info , well_state_type * by calling this function repeatedly. This function will go through all the wells by number and call the - well_state_alloc() function to create a well state object for each - well. The well_state_alloc() function will iterate through all the + well_state_alloc_from_file() function to create a well state object for each + well. The well_state_alloc_from_file() function will iterate through all the grids and assign well properties corresponding to each of the grids, the global grid special-cased to determine is consulted to determine the number of wells. */ void well_info_add_wells( well_info_type * well_info , ecl_file_type * rst_file , int report_nr) { - ecl_rsthead_type * global_header = ecl_rsthead_alloc( rst_file ); int well_nr; + ecl_rsthead_type * global_header = ecl_rsthead_alloc( rst_file ); for (well_nr = 0; well_nr < global_header->nwells; well_nr++) { - well_state_type * well_state = well_state_alloc( rst_file , report_nr , well_nr ); + well_state_type * well_state = well_state_alloc_from_file( rst_file , well_info->grid , report_nr , well_nr ); if (well_state != NULL) well_info_add_state( well_info , well_state ); } @@ -340,7 +327,7 @@ void well_info_load_rstfile( well_info_type * well_info , const char * filename) well_info_add_wells( well_info , ecl_file , report_nr ); else well_info_add_UNRST_wells( well_info , ecl_file ); - + ecl_file_close( ecl_file ); } else util_abort("%s: invalid file type:%s - must be a restart file\n",__func__ , filename); diff --git a/ThirdParty/Ert/devel/libecl_well/src/well_path.c b/ThirdParty/Ert/devel/libecl_well/src/well_path.c deleted file mode 100644 index 72208435fb..0000000000 --- a/ThirdParty/Ert/devel/libecl_well/src/well_path.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - Copyright (C) 2012 Statoil ASA, Norway. - - The file 'well_path.c' is part of ERT - Ensemble based Reservoir Tool. - - ERT 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. - - ERT 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 - -#include -#include -#include -#include - -/* - This file implements the well_path structure which is container for - the grid connections for one grid realisation; i.e. if the well is - perforated in LGRs in addition to the global grid the parent - well_state structure will have several well_path instances - one for - the global grid and one for each LGR. - - The well_path structure consist of one or several well_branch_type - instances; the well_branch is a collection of cells which are - connected on a 1D line. - - --------------D - / - / - A---------------B----------C - - - All of this figure is one well; how this structure is connected to - one particular grid is described by the well_path structure in this - file. The current well consist of two branches: A-B-C and B-D; these - are two well_branch instance in the well_path structure. -*/ - - -#define WELL_PATH_TYPE_ID 91916433 - -struct well_path_struct { - UTIL_TYPE_ID_DECLARATION; - char * grid_name; // Will be NULL for 'null_path' construction in the well_state object. - well_branch_type ** branches; - int max_branches; // This might be misleading due to NULL pointers 'inside' the branches array. - int alloc_size; -}; - - - -static void well_path_resize( well_path_type * well_path , int new_size) { - well_path->branches = util_realloc( well_path->branches , new_size * sizeof * well_path->branches ); - { - int i; - for (i=well_path->alloc_size; i < new_size; i++) - well_path->branches[i] = NULL; - } - - well_path->alloc_size = new_size; -} - -static UTIL_SAFE_CAST_FUNCTION( well_path , WELL_PATH_TYPE_ID ) - -well_path_type * well_path_alloc(const char * grid_name) { - well_path_type * well_path = util_malloc( sizeof * well_path ); - UTIL_TYPE_ID_INIT( well_path , WELL_PATH_TYPE_ID ); - well_path->grid_name = util_alloc_string_copy( grid_name ); - well_path->branches = NULL; - well_path->max_branches = 0; - well_path->alloc_size = 0; - well_path_resize( well_path , 4 ); - return well_path; -} - - - -well_branch_type * well_path_add_branch( well_path_type * well_path , int branch_nr) { - - well_branch_type * new_branch = well_branch_alloc( branch_nr ); - if (branch_nr >= well_path->alloc_size) - well_path_resize( well_path , 2 * branch_nr ); - - well_path->branches[ branch_nr ] = new_branch; - if (branch_nr >= well_path->max_branches) - well_path->max_branches = branch_nr + 1; - - return new_branch; -} - - -bool well_path_has_branch( const well_path_type * well_path , int branch_nr ) { - if (branch_nr >= 0 && branch_nr < well_path->max_branches) { - well_branch_type * branch = well_path->branches[ branch_nr ]; - if (branch != NULL) - return true; - else - return false; - } else - return false; -} - -/** - This will return the maximum branch number; there can be holes in - the branches array: - - branches = [ branch0, NULL , branch1 , NULL , branch3] - - In this case the the well_path_get_max_branches() will return five; - however there are only three active branches in this case. The - alternative function well_path_get_num_active_branches() will count - the number of active (i.e. != NULL) branches. -*/ -int well_path_get_max_branches( const well_path_type * well_path ) { - return well_path->max_branches; -} - - -int well_path_get_num_active_branches( const well_path_type * well_path) { - int branch_nr; - int num_active = 0; - for (branch_nr = 0; branch_nr < well_path->max_branches; branch_nr++) - if (well_path->branches[ branch_nr ] != NULL) - num_active++; - return num_active; -} - - - -/** - Will return NULL if the branch does not exist. -*/ - -well_branch_type * well_path_iget_branch( const well_path_type * well_path , int branch_nr) { - if (well_path_has_branch( well_path , branch_nr )) - return well_path->branches[ branch_nr ]; - else - return NULL; -} - - -void well_path_add_conn( well_path_type * well_path , well_conn_type * conn) { - int branch_nr = well_conn_get_branch( conn ); - if (!well_path_has_branch( well_path , branch_nr)) - well_path_add_branch( well_path , branch_nr ); - { - well_branch_type * branch = well_path_iget_branch( well_path , branch_nr ); - well_branch_add_conn( branch , conn ); - } -} - - -void well_path_free( well_path_type * well_path ) { - int i; - for (i=0; i < well_path->alloc_size; i++) { - if (well_path->branches[i] != NULL) - well_branch_free( well_path->branches[i] ); - } - util_safe_free( well_path->grid_name ); - free( well_path->branches ); - free( well_path ); -} - -void well_path_free__(void * arg) { - well_path_type * well_path = well_path_safe_cast( arg ); - well_path_free( well_path ); -} - - - -const char * well_path_get_grid_name( const well_path_type * well_path ) { - return well_path->grid_name; -} diff --git a/ThirdParty/Ert/devel/libecl_well/src/well_segment.c b/ThirdParty/Ert/devel/libecl_well/src/well_segment.c new file mode 100644 index 0000000000..6e91541195 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/src/well_segment.c @@ -0,0 +1,251 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_segment.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include + +#include +#include +#include + +#include +#include +#include +#include + +#define WELL_SEGMENT_TYPE_ID 2209166 + +struct well_segment_struct { + UTIL_TYPE_ID_DECLARATION; + int link_count; + int segment_id; + int branch_id; + int outlet_segment_id; // This is in the global index space given by the ISEG keyword. + well_segment_type * outlet_segment; + hash_type * connections; // hash_type; + + double depth; // The depth of the segment node; furthest away from the wellhead. + double length; + double total_length; // Total length from wellhead. + double diameter; // The tube diametere available for flow. +}; + + +UTIL_IS_INSTANCE_FUNCTION( well_segment , WELL_SEGMENT_TYPE_ID ) +static UTIL_SAFE_CAST_FUNCTION( well_segment , WELL_SEGMENT_TYPE_ID ) + + +well_segment_type * well_segment_alloc(int segment_id , int outlet_segment_id , int branch_id , const double * rseg_data) { + well_segment_type * segment = util_malloc( sizeof * segment ); + UTIL_TYPE_ID_INIT( segment , WELL_SEGMENT_TYPE_ID ); + + segment->link_count = 0; + segment->segment_id = segment_id; + segment->outlet_segment_id = outlet_segment_id; + segment->branch_id = branch_id; + segment->outlet_segment = NULL; + segment->connections = hash_alloc(); + + segment->depth = rseg_data[ RSEG_DEPTH_INDEX ]; + segment->length = rseg_data[ RSEG_LENGTH_INDEX ]; + segment->total_length = rseg_data[ RSEG_TOTAL_LENGTH_INDEX ]; + segment->diameter = rseg_data[ RSEG_DIAMETER_INDEX ]; + + return segment; +} + + +well_segment_type * well_segment_alloc_from_kw( const ecl_kw_type * iseg_kw , const ecl_kw_type * rseg_kw , const ecl_rsthead_type * header , int well_nr, int segment_id) { + if (rseg_kw == NULL) { + util_abort("%s: fatal internal error - tried to create well_segment instance without RSEG keyword.\n",__func__); + return NULL; + } else { + const int iseg_offset = header->nisegz * ( header->nsegmx * well_nr + segment_id); + const int rseg_offset = header->nrsegz * ( header->nsegmx * well_nr + segment_id); + int outlet_segment_id = ecl_kw_iget_int( iseg_kw , iseg_offset + ISEG_OUTLET_ITEM ) - 1; + int branch_id = ecl_kw_iget_int( iseg_kw , iseg_offset + ISEG_BRANCH_ITEM ) - 1; + const double * rseg_data = ecl_kw_iget_ptr( rseg_kw , rseg_offset ); + + well_segment_type * segment = well_segment_alloc( segment_id , outlet_segment_id , branch_id , rseg_data); + return segment; + } +} + + +/* + if (iseg_kw != NULL) { + if (conn->segment != WELL_CONN_NORMAL_WELL_SEGMENT_ID) { + + } else { + conn->branch = 0; + conn->outlet_segment = 0; + } + } else { + conn->branch = 0; + conn->outlet_segment = 0; + } + */ + + +void well_segment_free(well_segment_type * segment ) { + hash_free( segment->connections ); + free( segment ); +} + +void well_segment_free__(void * arg) { + well_segment_type * segment = well_segment_safe_cast( arg ); + well_segment_free( segment ); +} + + +bool well_segment_active( const well_segment_type * segment ) { + if (segment->branch_id == ECLIPSE_WELL_SEGMENT_BRANCH_INACTIVE_VALUE) + return false; + else + return true; +} + + +bool well_segment_main_stem( const well_segment_type * segment ) { + if (segment->branch_id == ECLIPSE_WELL_SEGMENT_BRANCH_MAIN_STEM_VALUE) + return true; + else + return false; +} + + +bool well_segment_nearest_wellhead( const well_segment_type * segment ) { + if (segment->outlet_segment_id == ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE) + return true; + else + return false; +} + + +int well_segment_get_link_count( const well_segment_type * segment ) { + return segment->link_count; +} + +int well_segment_get_branch_id( const well_segment_type * segment ) { + return segment->branch_id; +} + +int well_segment_get_outlet_id( const well_segment_type * segment ) { + return segment->outlet_segment_id; +} + +int well_segment_get_id( const well_segment_type * segment ) { + return segment->segment_id; +} + + +well_segment_type * well_segment_get_outlet( const well_segment_type * segment ) { + return segment->outlet_segment; +} + + +bool well_segment_link( well_segment_type * segment , well_segment_type * outlet_segment ) { + if (segment->outlet_segment_id == outlet_segment->segment_id) { + segment->outlet_segment = outlet_segment; + if (outlet_segment->branch_id == segment->branch_id){ + outlet_segment->link_count++; + } + return true; + } else + /* + This is a quite fatal topological error - and aborting is probaly the wisest + thing to do. I.e. the function well_segment_link_strict() is recommended. + */ + return false; +} + + +void well_segment_link_strict( well_segment_type * segment , well_segment_type * outlet_segment ) { + if (!well_segment_link( segment , outlet_segment)) + util_abort("%s: tried to create invalid link between segments %d and %d \n",segment->segment_id , outlet_segment->segment_id); +} + + + +bool well_segment_has_grid_connections( const well_segment_type * segment , const char * grid_name) { + return hash_has_key( segment->connections , grid_name ); +} + + +bool well_segment_has_global_grid_connections( const well_segment_type * segment) { + return well_segment_has_grid_connections( segment , ECL_GRID_GLOBAL_GRID ); +} + + +bool well_segment_add_connection( well_segment_type * segment , const char * grid_name , well_conn_type * conn) { + int conn_segment_id = well_conn_get_segment( conn ); + if (conn_segment_id == segment->segment_id) { + if (!well_segment_has_grid_connections( segment , grid_name )) + hash_insert_hash_owned_ref( segment->connections , grid_name , well_conn_collection_alloc() , well_conn_collection_free__ ); + + { + well_conn_collection_type * connections = hash_get( segment->connections , grid_name ); + well_conn_collection_add_ref( connections , conn ); + } + return true; + } else + return false; +} + + +const well_conn_collection_type * well_segment_get_connections(const well_segment_type * segment , const char * grid_name ) { + if (well_segment_has_grid_connections( segment , grid_name)) + return hash_get( segment->connections , grid_name); + else + return NULL; +} + + +const well_conn_collection_type * well_segment_get_global_connections(const well_segment_type * segment ) { + return well_segment_get_connections( segment , ECL_GRID_GLOBAL_GRID ); +} + + +bool well_segment_well_is_MSW(int well_nr , const ecl_kw_type * iwel_kw , const ecl_rsthead_type * rst_head) { + int iwel_offset = rst_head->niwelz * well_nr; + int segment_well_nr = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_SEGMENTED_WELL_NR_ITEM) - 1; + + if (segment_well_nr == IWEL_SEGMENTED_WELL_NR_NORMAL_VALUE) + return false; + else + return true; +} + + +double well_segment_get_depth( const well_segment_type * segment ) { + return segment->depth; +} + +double well_segment_get_length( const well_segment_type * segment ) { + return segment->length; +} + +double well_segment_get_total_length( const well_segment_type * segment ) { + return segment->total_length; +} + +double well_segment_get_diameter( const well_segment_type * segment ) { + return segment->diameter; +} diff --git a/ThirdParty/Ert/devel/libecl_well/src/well_segment_collection.c b/ThirdParty/Ert/devel/libecl_well/src/well_segment_collection.c new file mode 100644 index 0000000000..403c373de7 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/src/well_segment_collection.c @@ -0,0 +1,169 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_segment_collection.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + + +struct well_segment_collection_struct { + int_vector_type * segment_index_map; + vector_type * __segment_storage; +}; + + + +well_segment_collection_type * well_segment_collection_alloc() { + well_segment_collection_type * segment_collection = util_malloc( sizeof * segment_collection ); + + segment_collection->__segment_storage = vector_alloc_new(); + segment_collection->segment_index_map = int_vector_alloc( 0 , -1 ); + return segment_collection; +} + + + +void well_segment_collection_free(well_segment_collection_type * segment_collection ) { + vector_free( segment_collection->__segment_storage ); + int_vector_free( segment_collection->segment_index_map ); + free( segment_collection ); +} + + + +int well_segment_collection_get_size( const well_segment_collection_type * segment_collection ) { + return vector_get_size( segment_collection->__segment_storage ); +} + + +void well_segment_collection_add( well_segment_collection_type * segment_collection , well_segment_type * segment) { + int segment_id = well_segment_get_id( segment ); + int current_index = int_vector_safe_iget( segment_collection->segment_index_map , segment_id ); + if (current_index >= 0) + vector_iset_owned_ref( segment_collection->__segment_storage , current_index , segment , well_segment_free__); + else { + int new_index = vector_get_size(segment_collection->__segment_storage); + vector_append_owned_ref( segment_collection->__segment_storage , segment , well_segment_free__); + int_vector_iset( segment_collection->segment_index_map , segment_id , new_index); + } +} + + + +well_segment_type * well_segment_collection_iget( const well_segment_collection_type * segment_collection , int index) { + return vector_iget( segment_collection->__segment_storage , index ); +} + + +well_segment_type * well_segment_collection_get( const well_segment_collection_type * segment_collection , int segment_id) { + int internal_index = int_vector_safe_iget( segment_collection->segment_index_map , segment_id ); + if (internal_index >= 0) + return well_segment_collection_iget( segment_collection , internal_index ); + else + return NULL; +} + + +bool well_segment_collection_has_segment( const well_segment_collection_type * segment_collection , int segment_id) { + int internal_index = int_vector_safe_iget( segment_collection->segment_index_map , segment_id ); + if (internal_index >= 0) + return true; + else + return false; +} + + + +int well_segment_collection_load_from_kw( well_segment_collection_type * segment_collection , int well_nr , + const ecl_kw_type * iwel_kw , + const ecl_kw_type * iseg_kw , + const ecl_kw_type * rseg_kw , + const ecl_rsthead_type * rst_head) { + + int iwel_offset = rst_head->niwelz * well_nr; + int segment_well_nr = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_SEGMENTED_WELL_NR_ITEM) - 1; + int segments_added = 0; + + if (segment_well_nr != IWEL_SEGMENTED_WELL_NR_NORMAL_VALUE) { + int segment_id; + for (segment_id = 0; segment_id < rst_head->nsegmx; segment_id++) { + well_segment_type * segment = well_segment_alloc_from_kw( iseg_kw , rseg_kw , rst_head , segment_well_nr , segment_id ); + + if (well_segment_active( segment )) { + well_segment_collection_add( segment_collection , segment ); + segments_added++; + } else + well_segment_free( segment ); + } + } + + return segments_added; +} + + +void well_segment_collection_link(const well_segment_collection_type * segment_collection) { + int index; + for (index = 0; index < vector_get_size( segment_collection->__segment_storage); index++) { + well_segment_type * segment = well_segment_collection_iget( segment_collection , index ); + int outlet_segment_id = well_segment_get_outlet_id( segment ); + if (!well_segment_nearest_wellhead(segment)) { + well_segment_type * target_segment = well_segment_collection_get( segment_collection , outlet_segment_id ); + well_segment_link( segment , target_segment ); + } + } +} + + + +void well_segment_collection_add_connections(well_segment_collection_type * segment_collection , + const char * grid_name , + const well_conn_collection_type * connections) { + int iconn; + for (iconn = 0; iconn < well_conn_collection_get_size( connections ); iconn++) { + well_conn_type * conn = well_conn_collection_iget( connections , iconn ); + if (well_conn_MSW( conn )) { + int segment_id = well_conn_get_segment( conn ); + well_segment_type * segment = well_segment_collection_get( segment_collection , segment_id ); + well_segment_add_connection( segment , grid_name , conn ); + } + } +} + + + +void well_segment_collection_add_branches( const well_segment_collection_type * segment_collection , + well_branch_collection_type * branches ) { + int iseg; + for (iseg =0; iseg < well_segment_collection_get_size( segment_collection ); iseg++) { + const well_segment_type * segment = well_segment_collection_iget( segment_collection , iseg ); + if (well_segment_get_link_count( segment ) == 0) + well_branch_collection_add_start_segment( branches , segment ); + } +} + diff --git a/ThirdParty/Ert/devel/libecl_well/src/well_state.c b/ThirdParty/Ert/devel/libecl_well/src/well_state.c index 2212050578..1620d4935f 100644 --- a/ThirdParty/Ert/devel/libecl_well/src/well_state.c +++ b/ThirdParty/Ert/devel/libecl_well/src/well_state.c @@ -1,19 +1,19 @@ /* - Copyright (C) 2011 Statoil ASA, Norway. - - The file 'well_state.c' is part of ERT - Ensemble based Reservoir Tool. - - ERT 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. - - ERT 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. + Copyright (C) 2011 Statoil ASA, Norway. + + The file 'well_state.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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. */ /** @@ -36,11 +36,126 @@ #include #include #include +#include #include #include #include -#include +#include +#include + +/* + +Connections, segments and branches +---------------------------------- + + + +-----+ + | | <- Wellhead + | | + +-----+ _________ Segment 2 + |\ / + | \/ Segment 1 Segment 0 + | \-----0---------------0--<----------------------O <-- Branch: 0 + \ | | | | + \ +-----+ +-----++-----+ +-----+ + \ | C3 | | C2 || C1 | | C0 | + \ | | | || | | | + \ +-----+ +-----++-----+ +-----+ + \ +Segment 5 \ + \ + \ Segment 4 Segment 3 + \-<--O-------<-------O----------------<------------O <-- Branch: 1 + | | | | + +-----+ +-----+ +-----+ +-----+ + | C7 | | C6 | | C5 | | C4 | + | | | | | | | | + +-----+ +-----+ +-----+ +-----+ + + + + +The boxes show connections C0 - C7; the connections serve as sinks (or +sources in the case of injectors) removing fluids from the +reservoir. As ind icated by the use of isolated boxes the ECLIPSE model +contains no geomtric concept linking the different connections into a +connected 'well-like' object. + +Ordinary wells in the ECLIPSE model are just a collection of +connections like these illustrated boxes, and to draw a connected 1D +object heuristics of some kind must be used to determine how the +various connections should be connected. In particular for wells which +consist of multiple branches this heuristic is non obvious. + +More advanced (i.e. newer) wells are modelles as multisegment wells; +the important thing about multisegment wells is that the 1D segments +constituting the flowpipe are modelled explicitly as 'segments', and +the equations of fluid flow are solved by ECLIPSE in these 1D +domains. The figure above shows a multisegment well with six segments +marked as Segment0 ... Segment5. The segments themselves are quite +abstract objects not directly linked to the grid, but indriectly +through the connections. In the figure the segment <-> connection +links are as follows: + + Segment0: C0, C1 + Segment1: C2 + Segment2: C3 + Segment3: C4, C5 + Segment4: C6 + Segment5: C7 + +Each segment has an outlet segment, which will link the segments +together into a geometry. + +The connection can in general be both to the main global grid, and to +an LGR. Hence all questions about connections must be LGR aware. This +is in contrast to the segments and branches which are geometric +objects, not directly coupled to a specific grid; however the segments +have a collection of connections - and these connections are of course +coupledte implementation these objects are modelled as such: + + 1. The well_state has hash table which is indexed by LGR name, and + the values are well_conn_collection instances. The + well_conn_collection type is a quite simple collection which can + tell how may connections there are, and index based lookup: + + + well_conn_collection_type * connections = well_state_get_grid_connections( well_state , LGR_NAME); + if (connections) { + well_conn_type * conn = well_conn_collection_iget( connections , 0 ); + printf("Have %d connections \n",well_conn_collection_get_size( connections ); + } + + The connections to the global grid are stored with the 'LGR' name + given by the symbole ECL_GRID_GLOBAL_GRID, or alternatively the + function well_state_get_global_connections( well_state ) can be + used. + + + + 2. If - AND ONLY IF - the well is a multisegment well, you can query + the well_state object for information about segments and branches: + + if (well_state_is_MSW( well_state )) { + well_segment_collection_type * segments = well_state_get_segments( well_state ); + well_branch_collection_type * branches = well_state_get_branches( well_state ); + int branch_nr; + + for (branch_nr = 0; branch_nr < well_branch_collection_get_size( branches ); branch_nr++) { + well_segment_type * segment = well_branch_collection_iget_start_segment( branches , branhc_nr ); + while (segment) { + // Inspect the current segment. + segment = well_segment_get_outlet( segment ); + } + } + } + + + + +*/ + #define WELL_STATE_TYPE_ID 613307832 @@ -49,16 +164,18 @@ struct well_state_struct { char * name; time_t valid_from_time; int valid_from_report; + int global_well_nr; bool open; well_type_enum type; - - well_path_type * null_path; // This is a valid - empty path instance returned when the well does not have any cells in a particular LGR. + + hash_type * connections; // hash + well_segment_collection_type * segments; + well_branch_collection_type * branches; + + /*****************************************************************/ vector_type * index_wellhead; // An well_conn_type instance representing the wellhead - indexed by grid_nr. hash_type * name_wellhead; // An well_conn_type instance representing the wellhead - indexed by lgr_name. - - vector_type * index_lgr_path; // Contains the various well_path instances indexed by grid_nr - global has grid_nr == 0. - hash_type * name_lgr_path; // Contains the different well_path instances indexed by lgr_name }; @@ -66,34 +183,30 @@ struct well_state_struct { UTIL_IS_INSTANCE_FUNCTION( well_state , WELL_STATE_TYPE_ID) -static well_state_type * well_state_alloc_empty() { +well_state_type * well_state_alloc(const char * well_name , int global_well_nr , bool open, well_type_enum type , int report_nr, time_t valid_from) { well_state_type * well_state = util_malloc( sizeof * well_state ); UTIL_TYPE_ID_INIT( well_state , WELL_STATE_TYPE_ID ); - well_state->index_lgr_path = vector_alloc_new(); - well_state->name_lgr_path = hash_alloc(); - well_state->index_wellhead = vector_alloc_new(); well_state->name_wellhead = hash_alloc(); - well_state->null_path = well_path_alloc( NULL ); + well_state->name = util_alloc_string_copy( well_name ); + well_state->valid_from_time = valid_from; + well_state->valid_from_report = report_nr; + well_state->open = open; + well_state->type = type; + well_state->global_well_nr = global_well_nr; + well_state->connections = hash_alloc(); + well_state->segments = well_segment_collection_alloc(); + well_state->branches = well_branch_collection_alloc(); + + /* See documentation of the 'IWEL_UNDOCUMENTED_ZERO' in well_const.h */ + if ((type == UNDOCUMENTED_ZERO) && open) + util_abort("%s: Invalid type value for open wells.\n",__func__ ); return well_state; } -/* - This function assumes that the ecl_file state has been restricted - to one LGR block with the ecl_file_subselect_block() function. -*/ -well_path_type * well_state_add_path( well_state_type * well_state , const ecl_file_type * rst_file , const char * grid_name , int grid_nr) { - well_path_type * well_path; - well_path = well_path_alloc( grid_name ); - - vector_safe_iset_owned_ref( well_state->index_lgr_path , grid_nr , well_path , well_path_free__); - hash_insert_ref( well_state->name_lgr_path , grid_name , well_path ); - - return well_path; -} void well_state_add_wellhead( well_state_type * well_state , const ecl_rsthead_type * header , const ecl_kw_type * iwel_kw , int well_nr , const char * grid_name , int grid_nr) { @@ -103,72 +216,26 @@ void well_state_add_wellhead( well_state_type * well_state , const ecl_rsthead_t vector_safe_iset_owned_ref( well_state->index_wellhead , grid_nr , wellhead , well_conn_free__ ); hash_insert_ref( well_state->name_wellhead , grid_name , wellhead ); } - + } -/* - This function assumes that the ecl_file state has been restricted - to one LGR block with the ecl_file_subselect_block() function. -*/ -static void well_state_add_connections( well_state_type * well_state , const ecl_file_type * rst_file , int grid_nr, int well_nr ) { - ecl_rsthead_type * header = ecl_rsthead_alloc( rst_file ); - const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0); - const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0); - const int iwel_offset = header->niwelz * well_nr; - int num_connections = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_CONNECTIONS_ITEM ); - ecl_kw_type * iseg_kw = NULL; - bool MSW = false; // MultiSegmentWell - int seg_well_nr = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_SEGMENTED_WELL_NR_ITEM) - 1; // -1: Ordinary well. - well_path_type * path; - - { - char * grid_name; - - if (grid_nr > 0) { - const ecl_kw_type * lgr_kw = ecl_file_iget_named_kw( rst_file , LGR_KW , 0 ); - grid_name = util_alloc_strip_copy(ecl_kw_iget_ptr( lgr_kw , 0)); - } else - grid_name = util_alloc_string_copy( GLOBAL_GRID_NAME ); - - path = well_state_add_path( well_state , rst_file , grid_name , grid_nr ); - well_state_add_wellhead( well_state , header , iwel_kw , well_nr , grid_name , grid_nr ); - free( grid_name ); - } - - /* The MSW information is only attached to the global grid. */ - if (seg_well_nr >= 0 && grid_nr == 0) - MSW = true; - - if (MSW) - iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0 ); - - { - int conn_nr; - for (conn_nr = 0; conn_nr < num_connections; conn_nr++) { - well_conn_type * conn = well_conn_alloc( icon_kw , iseg_kw , header , well_nr , seg_well_nr , conn_nr ); - if (conn != NULL) - well_path_add_conn( path , conn ); - } - } - ecl_rsthead_free( header ); -} /* This function assumes that the ecl_file state has been restricted to one LGR block with the ecl_file_subselect_block() function. Return value: -1 means that the well is not found in this LGR at - all. + all. */ static int well_state_get_lgr_well_nr( const well_state_type * well_state , const ecl_file_type * ecl_file) { int well_nr = -1; - + if (ecl_file_has_kw( ecl_file , ZWEL_KW)) { - ecl_rsthead_type * header = ecl_rsthead_alloc( ecl_file ); // - const ecl_kw_type * zwel_kw = ecl_file_iget_named_kw( ecl_file , ZWEL_KW , 0); + ecl_rsthead_type * header = ecl_rsthead_alloc( ecl_file ); + const ecl_kw_type * zwel_kw = ecl_file_iget_named_kw( ecl_file , ZWEL_KW , 0 ); int num_wells = header->nwells; well_nr = 0; while (true) { @@ -180,10 +247,10 @@ static int well_state_get_lgr_well_nr( const well_state_type * well_state , cons found = true; else well_nr++; - + free( lgr_well_name ); } - + if (found) break; else if (well_nr == num_wells) { @@ -191,7 +258,7 @@ static int well_state_get_lgr_well_nr( const well_state_type * well_state , cons well_nr = -1; break; } - + } ecl_rsthead_free( header ); } @@ -199,97 +266,217 @@ static int well_state_get_lgr_well_nr( const well_state_type * well_state , cons } -well_state_type * well_state_alloc( ecl_file_type * ecl_file , int report_nr , int global_well_nr) { + +well_type_enum well_state_translate_ecl_type_int(int int_type) { + well_type_enum type = UNDOCUMENTED_ZERO; + + switch (int_type) { + /* See documentation of the 'IWEL_UNDOCUMENTED_ZERO' in well_const.h */ + case(IWEL_UNDOCUMENTED_ZERO): + type = UNDOCUMENTED_ZERO; + break; + case(IWEL_PRODUCER): + type = PRODUCER; + break; + case(IWEL_OIL_INJECTOR): + type = OIL_INJECTOR; + break; + case(IWEL_GAS_INJECTOR): + type = GAS_INJECTOR; + break; + case(IWEL_WATER_INJECTOR): + type = WATER_INJECTOR; + break; + default: + util_abort("%s: Invalid type value %d\n",__func__ , int_type); + } + return type; +} + + + +/* + This function assumes that the ecl_file state has been restricted + to one LGR block with the ecl_file_subselect_block() function. +*/ + +static void well_state_add_connections__( well_state_type * well_state , + const ecl_file_type * rst_file , + const char * grid_name , + int grid_nr, + int well_nr ) { + + ecl_rsthead_type * header = ecl_rsthead_alloc( rst_file ); + const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0); + const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0); + + //const int iwel_offset = header->niwelz * well_nr; + //int seg_well_nr = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_SEGMENTED_WELL_NR_ITEM) - 1; // -1: Ordinary well. + + well_state_add_wellhead( well_state , header , iwel_kw , well_nr , grid_name , grid_nr ); + + if (!well_state_has_grid_connections( well_state , grid_name )) + hash_insert_hash_owned_ref( well_state->connections , grid_name, well_conn_collection_alloc( ) , well_conn_collection_free__ ); + + { + well_conn_collection_type * wellcc = hash_get( well_state->connections , grid_name ); + well_conn_collection_load_from_kw( wellcc , iwel_kw , icon_kw , well_nr , header ); + } + ecl_rsthead_free( header ); +} + + +static void well_state_add_global_connections( well_state_type * well_state , + const ecl_file_type * rst_file , + int well_nr ) { + well_state_add_connections__( well_state , rst_file , ECL_GRID_GLOBAL_GRID , 0 , well_nr ); +} + +static void well_state_add_LGR_connections( well_state_type * well_state , const ecl_grid_type * grid , ecl_file_type * ecl_file, int global_well_nr ) { + // Go through all the LGRs and add connections; both in the bulk + // grid and as wellhead. + int num_lgr = ecl_grid_get_num_lgr( grid ); + int lgr_index; + for (lgr_index = 0; lgr_index < num_lgr; lgr_index++) { + ecl_file_push_block( ecl_file ); // <-------------------------// + { // + ecl_file_subselect_block( ecl_file , LGR_KW , lgr_index ); // + { // Restrict the file view + const char * grid_name = ecl_grid_iget_lgr_name( grid , lgr_index ); // + int well_nr = well_state_get_lgr_well_nr( well_state , ecl_file ); // to one LGR block. + if (well_nr >= 0) // + well_state_add_connections__( well_state , ecl_file , grid_name , lgr_index + 1, well_nr ); // + } // + } // + ecl_file_pop_block( ecl_file ); // <-------------------------// + } +} + + + +void well_state_add_connections( well_state_type * well_state , + const ecl_grid_type * grid , + ecl_file_type * rst_file , // Either an open .Xnnnn file or UNRST file restricted to one report step + int well_nr) { + + well_state_add_global_connections( well_state , rst_file , well_nr ); + well_state_add_LGR_connections( well_state , grid , rst_file , well_nr ); + +} + + +bool well_state_add_MSW( well_state_type * well_state , + const ecl_file_type * rst_file , + int well_nr) { + + if (ecl_file_has_kw( rst_file , ISEG_KW)) { + ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_file ); + const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0); + const ecl_kw_type * iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0); + ecl_kw_type * rseg_kw = NULL; + + int segments; + + if (ecl_file_has_kw( rst_file , RSEG_KW )) + /* + Here we check that the file has the RSEG_KW keyword, and pass + NULL if not. The rseg_kw pointer will later be used in + well_segment_collection_load_from_kw() where we test if this + is a MSW well. If this indeed is a MSW well the rseg_kw + pointer will be used unchecked, if it is then NULL => Crash + and burn. + */ + rseg_kw = ecl_file_iget_named_kw( rst_file , RSEG_KW , 0); + + segments = well_segment_collection_load_from_kw( well_state->segments , + well_nr , + iwel_kw , + iseg_kw , + rseg_kw , + rst_head); + + if (segments) { + hash_iter_type * grid_iter = hash_iter_alloc( well_state->connections ); + while (!hash_iter_is_complete( grid_iter )) { + const char * grid_name = hash_iter_get_next_key( grid_iter ); + const well_conn_collection_type * connections = hash_get( well_state->connections , grid_name ); + well_segment_collection_add_connections( well_state->segments , grid_name , connections ); + } + hash_iter_free( grid_iter ); + well_segment_collection_link( well_state->segments ); + well_segment_collection_add_branches( well_state->segments , well_state->branches ); + } + ecl_rsthead_free( rst_head ); + return true; + } else + return false; +} + + +bool well_state_is_MSW( const well_state_type * well_state) { + if (well_segment_collection_get_size( well_state->segments ) > 0) + return true; + else + return false; +} + + +well_state_type * well_state_alloc_from_file( ecl_file_type * ecl_file , const ecl_grid_type * grid , int report_nr , int global_well_nr) { if (ecl_file_has_kw( ecl_file , IWEL_KW)) { well_state_type * well_state = NULL; ecl_rsthead_type * global_header = ecl_rsthead_alloc( ecl_file ); const ecl_kw_type * global_iwel_kw = ecl_file_iget_named_kw( ecl_file , IWEL_KW , 0); const ecl_kw_type * global_zwel_kw = ecl_file_iget_named_kw( ecl_file , ZWEL_KW , 0); - + const int iwel_offset = global_header->niwelz * global_well_nr; { - const int zwel_offset = global_header->nzwelz * global_well_nr; - well_state = well_state_alloc_empty(); - - well_state->valid_from_time = global_header->sim_time; - well_state->valid_from_report = report_nr; - well_state->name = util_alloc_strip_copy(ecl_kw_iget_ptr( global_zwel_kw , zwel_offset )); // Hardwired max 8 characters in Well Name - + char * name; + bool open; + well_type_enum type = UNDOCUMENTED_ZERO; { int int_state = ecl_kw_iget_int( global_iwel_kw , iwel_offset + IWEL_STATUS_ITEM ); if (int_state > 0) - well_state->open = true; + open = true; else - well_state->open = false; + open = false; } - + { int int_type = ecl_kw_iget_int( global_iwel_kw , iwel_offset + IWEL_TYPE_ITEM); - switch (int_type) { - /* See documentation of the 'IWEL_UNDOCUMENTED_ZERO' in well_const.h */ - case(IWEL_UNDOCUMENTED_ZERO): - well_state->type = UNDOCUMENTED_ZERO; - if (well_state->open) - util_abort("%s: Invalid type value %d\n",__func__ , int_type); - break; - case(IWEL_PRODUCER): - well_state->type = PRODUCER; - break; - case(IWEL_OIL_INJECTOR): - well_state->type = OIL_INJECTOR; - break; - case(IWEL_GAS_INJECTOR): - well_state->type = GAS_INJECTOR; - break; - case(IWEL_WATER_INJECTOR): - well_state->type = WATER_INJECTOR; - break; - default: - util_abort("%s: Invalid type value %d\n",__func__ , int_type); - } + type = well_state_translate_ecl_type_int( int_type ); } - - - // Add global connections: - well_state_add_connections( well_state , ecl_file , 0 , global_well_nr ); - - - - // Go through all the LGRs and add connections; both in the bulk - // grid and as wellhead. - + { - int num_lgr = ecl_file_get_num_named_kw( ecl_file , LGR_KW ); - int lgr_nr; - for (lgr_nr = 0; lgr_nr < num_lgr; lgr_nr++) { - ecl_file_push_block( ecl_file ); // <-------------------- - { // - ecl_file_subselect_block( ecl_file , LGR_KW , lgr_nr ); // - { // Restrict the file view - int well_nr = well_state_get_lgr_well_nr( well_state , ecl_file); // to one LGR block. - if (well_nr >= 0) // - well_state_add_connections( well_state , ecl_file , lgr_nr + 1, well_nr ); // - } // - } // - ecl_file_pop_block( ecl_file ); // <-------------------- - } + const int zwel_offset = global_header->nzwelz * global_well_nr; + name = util_alloc_strip_copy(ecl_kw_iget_ptr( global_zwel_kw , zwel_offset )); // Hardwired max 8 characters in Well Name } - } + + well_state = well_state_alloc(name , global_well_nr , open , type , report_nr , global_header->sim_time); + free( name ); + + well_state_add_connections( well_state , grid , ecl_file , global_well_nr); + if (ecl_file_has_kw( ecl_file , ISEG_KW)) + well_state_add_MSW( well_state , ecl_file , global_well_nr ); + } ecl_rsthead_free( global_header ); return well_state; - } else + } else /* This seems a bit weird - have come over E300 restart files without the IWEL keyword. */ return NULL; } -void well_state_free( well_state_type * well ) { - hash_free( well->name_lgr_path ); - vector_free( well->index_lgr_path ); + + + + + +void well_state_free( well_state_type * well ) { hash_free( well->name_wellhead ); vector_free( well->index_wellhead ); - - well_path_free( well->null_path ); + hash_free( well->connections ); + well_segment_collection_free( well->segments ); + well_branch_collection_free( well->branches ); free( well->name ); free( well ); @@ -321,7 +508,7 @@ const well_conn_type * well_state_get_wellhead( const well_state_type * well_sta } -well_type_enum well_state_get_type( const well_state_type * well_state){ +well_type_enum well_state_get_type( const well_state_type * well_state){ return well_state->type; } @@ -329,146 +516,54 @@ bool well_state_is_open( const well_state_type * well_state ) { return well_state->open; } +int well_state_get_well_nr( const well_state_type * well_state ) { + return well_state->global_well_nr; +} + + const char * well_state_get_name( const well_state_type * well_state ) { return well_state->name; } -/*****************************************************************/ - -well_path_type * well_state_get_path( const well_state_type * well_state , const char * lgr_name) { - if (hash_has_key( well_state->name_lgr_path , lgr_name)) - return hash_get( well_state->name_lgr_path , lgr_name ); - else - return well_state->null_path; -} - -well_path_type * well_state_iget_path( const well_state_type * well_state , int grid_nr) { - well_path_type * path = vector_safe_iget( well_state->index_lgr_path , grid_nr ); - if (path != NULL) - return path; - else - return well_state->null_path; -} - - -const well_conn_type ** well_state_iget_lgr_connections(const well_state_type * well_state , int grid_nr , int branch_nr ) { - well_path_type * well_path = well_state_iget_path( well_state , grid_nr ); - well_branch_type * branch = well_path_iget_branch( well_path , branch_nr ); - - if (branch != NULL) - return well_branch_get_connections( branch ); - else - return NULL; // Branch does not exist - or has 0 connections. -} - - -const well_conn_type ** well_state_get_lgr_connections(const well_state_type * well_state , const char * lgr_name , int branch_nr) { - well_path_type * well_path = well_state_get_path( well_state , lgr_name ); - well_branch_type * branch = well_path_iget_branch( well_path , branch_nr ); - if (branch != NULL) - return well_branch_get_connections( branch ); - else - return NULL; // Branch does not exist - or has 0 connections. -} - - -const well_conn_type ** well_state_get_connections(const well_state_type * well_state , int branch_nr ) { - return well_state_iget_lgr_connections(well_state , 0 , branch_nr ); -} - -/*****************************************************************/ - -int well_state_iget_num_lgr_connections(const well_state_type * well_state , int grid_nr , int branch_nr ) { - well_path_type * well_path = well_state_iget_path( well_state , grid_nr ); - well_branch_type * branch = well_path_iget_branch( well_path , branch_nr ); - if (branch != NULL) - return well_branch_get_length( branch ); - else - return 0; -} - -int well_state_get_num_lgr_connections(const well_state_type * well_state , const char * lgr_name , int branch_nr) { - well_path_type * well_path = well_state_get_path( well_state , lgr_name ); - well_branch_type * branch = well_path_iget_branch( well_path , branch_nr ); - if (branch != NULL) - return well_branch_get_length( branch ); - else - return 0; -} - - -int well_state_get_num_connections(const well_state_type * well_state , int branch_nr ) { - return well_state_iget_num_lgr_connections(well_state , 0 , branch_nr ); -} - -/*****************************************************************/ - -int well_state_iget_lgr_num_branches( const well_state_type * well_state , int grid_nr) { - well_path_type * well_path = well_state_iget_path( well_state , grid_nr ); - return well_path_get_max_branches( well_path ); -} - -int well_state_get_lgr_num_branches( const well_state_type * well_state , const char * lgr_name) { - well_path_type * well_path = well_state_get_path( well_state , lgr_name ); - return well_path_get_max_branches( well_path ); -} - - -int well_state_get_num_branches(const well_state_type * well_state ) { - return well_state_iget_lgr_num_branches( well_state , 0 ); -} - -/*****************************************************************/ - -int well_state_get_num_paths( const well_state_type * well_state ) { - return vector_get_size( well_state->index_lgr_path ); -} /*****************************************************************/ void well_state_summarize( const well_state_type * well_state , FILE * stream ) { - fprintf(stream , "Well: %s \n" , well_state->name ); - { - int grid_nr; - for (grid_nr=0; grid_nr < well_state_get_num_paths( well_state ); grid_nr++) { - well_path_type * well_path = well_state_iget_path(well_state , grid_nr ); - if (well_path_get_grid_name( well_path ) != NULL) { - fprintf(stream , " Grid: %-8s\n",well_path_get_grid_name( well_path )); - - { - const well_conn_type * global_head = well_state_iget_wellhead( well_state , grid_nr ); - if (global_head != NULL) - fprintf(stream , " Wellhead: (%3d,%3d,%3d)\n" , well_conn_get_i( global_head ) , well_conn_get_j(global_head) , well_conn_get_k( global_head) ); - else - fprintf(stream , " Wellhead: ------------\n" ); - } - - { - int num_branches = well_path_get_max_branches(well_path); - int branch_nr; - for (branch_nr = 0; branch_nr < num_branches; branch_nr++) { - well_branch_type * branch = well_path_iget_branch( well_path , branch_nr ); - if (branch != NULL) { - const well_conn_type ** connections = well_branch_get_connections( branch ); - int num_connections = well_branch_get_length( branch ); - int iconn; - - fprintf(stream , " Branch %2d: [" , branch_nr ); - for (iconn=0; iconn < num_connections; iconn++) { - const well_conn_type * conn = connections[ iconn ]; - fprintf(stream, "(%3d,%3d,%3d)",well_conn_get_i( conn ) , well_conn_get_j( conn ), well_conn_get_k( conn )); - if (iconn == (num_connections - 1)) - fprintf(stream , "]\n"); - else { - fprintf(stream , ", "); - if ((iconn + 1) % 10 == 0) - fprintf(stream , "\n "); - } - } - } - } - } - } - } - } } + + +const well_conn_collection_type * well_state_get_grid_connections( const well_state_type * well_state , const char * grid_name) { + if (hash_has_key( well_state->connections , grid_name)) + return hash_get( well_state->connections , grid_name); + else + return NULL; +} + + +const well_conn_collection_type * well_state_get_global_connections( const well_state_type * well_state ) { + return well_state_get_grid_connections( well_state , ECL_GRID_GLOBAL_GRID ); +} + + +bool well_state_has_grid_connections( const well_state_type * well_state , const char * grid_name) { + if (hash_has_key( well_state->connections , grid_name)) + return true; + else + return false; +} + + +bool well_state_has_global_connections( const well_state_type * well_state ) { + return well_state_has_grid_connections( well_state , ECL_GRID_GLOBAL_GRID ); +} + + +well_segment_collection_type * well_state_get_segments( const well_state_type * well_state ) { + return well_state->segments; +} + + +well_branch_collection_type * well_state_get_branches( const well_state_type * well_state ) { + return well_state->branches; +} + diff --git a/ThirdParty/Ert/devel/libecl_well/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libecl_well/tests/CMakeLists.txt index d17c7ee460..9460918d2f 100644 --- a/ThirdParty/Ert/devel/libecl_well/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libecl_well/tests/CMakeLists.txt @@ -1,21 +1,132 @@ +add_executable( well_conn_collection well_conn_collection.c ) +target_link_libraries( well_conn_collection ecl_well test_util ) +set_target_properties( well_conn_collection PROPERTIES COMPILE_FLAGS "-Werror") +add_test( well_conn_collection ${EXECUTABLE_OUTPUT_PATH}/well_conn_collection ) + +add_executable( well_branch_collection well_branch_collection.c ) +target_link_libraries( well_branch_collection ecl_well test_util ) +set_target_properties( well_branch_collection PROPERTIES COMPILE_FLAGS "-Werror") +add_test( well_branch_collection ${EXECUTABLE_OUTPUT_PATH}/well_branch_collection ) + +add_executable( well_conn well_conn.c ) +target_link_libraries( well_conn ecl_well test_util ) +set_target_properties( well_conn PROPERTIES COMPILE_FLAGS "-Werror") +add_test( well_conn ${EXECUTABLE_OUTPUT_PATH}/well_conn ) + +add_executable( well_state well_state.c ) +target_link_libraries( well_state ecl_well test_util ) +set_target_properties( well_state PROPERTIES COMPILE_FLAGS "-Werror") +add_test( well_state ${EXECUTABLE_OUTPUT_PATH}/well_state ) + +add_executable( well_state_load well_state_load.c ) +target_link_libraries( well_state_load ecl_well test_util ) +set_target_properties( well_state_load PROPERTIES COMPILE_FLAGS "-Werror") + +add_executable( well_state_load_missing_RSEG well_state_load_missing_RSEG.c ) +target_link_libraries( well_state_load_missing_RSEG ecl_well test_util ) +set_target_properties( well_state_load_missing_RSEG PROPERTIES COMPILE_FLAGS "-Werror") + + +add_test( well_state_load1 ${EXECUTABLE_OUTPUT_PATH}/well_state_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.X0030) + +add_test( well_state_load2 ${EXECUTABLE_OUTPUT_PATH}/well_state_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/MSWcase/MSW_CASE.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/MSWcase/MSW_CASE.X0021) + +add_test( well_state_load3 ${EXECUTABLE_OUTPUT_PATH}/well_state_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Troll/MSW/MSW.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Troll/MSW/MSW.X0123) + +add_test( well_state_load4 ${EXECUTABLE_OUTPUT_PATH}/well_state_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Troll/MSW_LGR/LGR.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Troll/MSW_LGR/LGR.X0095) + +add_test( well_state_load5 ${EXECUTABLE_OUTPUT_PATH}/well_state_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.X0061) + +add_test( well_state_load_missing_RSEG1 ${EXECUTABLE_OUTPUT_PATH}/well_state_load_missing_RSEG ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.X0061) + +add_test( well_state_load_missing_RSEG2 ${EXECUTABLE_OUTPUT_PATH}/well_state_load_missing_RSEG ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Troll/MSW/MSW.EGRID + ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Troll/MSW/MSW.X0123) + + +add_executable( well_segment well_segment.c ) +target_link_libraries( well_segment ecl_well test_util ) +set_target_properties( well_segment PROPERTIES COMPILE_FLAGS "-Werror") +add_test( well_segment ${EXECUTABLE_OUTPUT_PATH}/well_segment ) + +add_executable( well_segment_conn well_segment_conn.c ) +target_link_libraries( well_segment_conn ecl_well test_util ) +set_target_properties( well_segment_conn PROPERTIES COMPILE_FLAGS "-Werror") +add_test( well_segment_conn ${EXECUTABLE_OUTPUT_PATH}/well_segment_conn ) + +add_executable( well_segment_load well_segment_load.c ) +target_link_libraries( well_segment_load ecl_well test_util ) +set_target_properties( well_segment_load PROPERTIES COMPILE_FLAGS "-Werror") +add_test( well_segment_load ${EXECUTABLE_OUTPUT_PATH}/well_segment_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/MSWcase/MSW_CASE.X0021) + + +add_executable( well_segment_branch_conn_load well_segment_branch_conn_load.c ) +target_link_libraries( well_segment_branch_conn_load ecl_well test_util ) +set_target_properties( well_segment_branch_conn_load PROPERTIES COMPILE_FLAGS "-Werror") +add_test( well_segment_branch_conn_load ${EXECUTABLE_OUTPUT_PATH}/well_segment_branch_conn_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/MSWcase/MSW_CASE.X0021) + +add_executable( well_info well_info.c ) +target_link_libraries( well_info ecl_well test_util ) +set_target_properties( well_info PROPERTIES COMPILE_FLAGS "-Werror") +add_test( well_info ${EXECUTABLE_OUTPUT_PATH}/well_info ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID ) + + +add_executable( well_segment_collection well_segment_collection.c ) +target_link_libraries( well_segment_collection ecl_well test_util ) +set_target_properties( well_segment_collection PROPERTIES COMPILE_FLAGS "-Werror") +add_test( well_segment_collection ${EXECUTABLE_OUTPUT_PATH}/well_segment_collection ) + + +add_executable( well_conn_load well_conn_load.c ) +target_link_libraries( well_conn_load ecl_well test_util ) +set_target_properties( well_conn_load PROPERTIES COMPILE_FLAGS "-Werror") +add_test( well_conn_load1 ${EXECUTABLE_OUTPUT_PATH}/well_conn_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.X0030 F) +add_test( well_conn_load2 ${EXECUTABLE_OUTPUT_PATH}/well_conn_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/10kcase/TEST10K_FLT_LGR_NNC.X0021 F) +add_test( well_conn_load3 ${EXECUTABLE_OUTPUT_PATH}/well_conn_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/MSWcase/MSW_CASE.X0021 T) +add_test( well_conn_load4 ${EXECUTABLE_OUTPUT_PATH}/well_conn_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.X0021 F) +add_test( well_conn_load5 ${EXECUTABLE_OUTPUT_PATH}/well_conn_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/DualPoro/DUALPORO.X0009 F) +add_test( well_conn_load6 ${EXECUTABLE_OUTPUT_PATH}/well_conn_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.X0003 F) + add_executable( well_ts well_ts.c ) -target_link_libraries( well_ts ecl_well ) +target_link_libraries( well_ts ecl_well test_util ) add_test( well_ts ${EXECUTABLE_OUTPUT_PATH}/well_ts ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/CO2case/BASE_CASE ) add_executable( well_dualp well_dualp.c ) -target_link_libraries( well_dualp ecl_well ) +target_link_libraries( well_dualp ecl_well test_util ) add_test( well_dualp ${EXECUTABLE_OUTPUT_PATH}/well_dualp ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/DualPoro/DUALPORO.X0005 ) add_executable( well_lgr_load well_lgr_load.c ) -target_link_libraries( well_lgr_load ecl_well ) +target_link_libraries( well_lgr_load ecl_well test_util ) -add_test( well_lgr_load1 ${EXECUTABLE_OUTPUT_PATH}/well_lgr_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.X0003) -add_test( well_lgr_load2 ${EXECUTABLE_OUTPUT_PATH}/well_lgr_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.X0016) +add_test( well_lgr_load1 ${EXECUTABLE_OUTPUT_PATH}/well_lgr_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.EGRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/0.9.2_LGR/BASE_REF_XY3Z1_T30_WI.X0003) +add_test( well_lgr_load2 ${EXECUTABLE_OUTPUT_PATH}/well_lgr_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.EGRID ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/AmalgLGRcase/TESTCASE_AMALG_LGR.X0016) -set_property( TEST well_lgr_load1 PROPERTY LABELS Statoil ) -set_property( TEST well_lgr_load2 PROPERTY LABELS Statoil ) -set_property( TEST well_dualp PROPERTY LABELS Statoil ) -set_property( TEST well_ts PROPERTY LABELS Statoil ) +set_property( TEST well_lgr_load1 PROPERTY LABELS StatoilData ) +set_property( TEST well_lgr_load2 PROPERTY LABELS StatoilData ) +set_property( TEST well_dualp PROPERTY LABELS StatoilData ) +set_property( TEST well_state_load1 PROPERTY LABELS StatoilData ) +set_property( TEST well_state_load2 PROPERTY LABELS StatoilData ) +set_property( TEST well_state_load3 PROPERTY LABELS StatoilData ) +set_property( TEST well_state_load4 PROPERTY LABELS StatoilData ) +set_property( TEST well_state_load5 PROPERTY LABELS StatoilData ) +set_property( TEST well_state_load_missing_RSEG1 PROPERTY LABELS StatoilData ) +set_property( TEST well_state_load_missing_RSEG2 PROPERTY LABELS StatoilData ) +set_property( TEST well_dualp PROPERTY LABELS StatoilData ) +set_property( TEST well_conn_load1 PROPERTY LABELS StatoilData ) +set_property( TEST well_conn_load2 PROPERTY LABELS StatoilData ) +set_property( TEST well_conn_load3 PROPERTY LABELS StatoilData ) +set_property( TEST well_conn_load4 PROPERTY LABELS StatoilData ) +set_property( TEST well_conn_load5 PROPERTY LABELS StatoilData ) +set_property( TEST well_conn_load6 PROPERTY LABELS StatoilData ) +set_property( TEST well_info PROPERTY LABELS StatoilData ) +set_property( TEST well_segment_load PROPERTY LABELS StatoilData ) +set_property( TEST well_segment_branch_conn_load PROPERTY LABELS StatoilData ) +set_property( TEST well_ts PROPERTY LABELS StatoilData ) diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_branch_collection.c b/ThirdParty/Ert/devel/libecl_well/tests/well_branch_collection.c new file mode 100644 index 0000000000..bd6d410d3a --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_branch_collection.c @@ -0,0 +1,70 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_branch_collection.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include + + +#include +#include +#include + +int main(int argc , char ** argv) { + test_install_SIGNALS(); + + well_branch_collection_type * branches = well_branch_collection_alloc(); + double * rseg_data = util_calloc( 100 , sizeof * rseg_data ); + const double depth = 100; + const double length = 20; + const double total_length = 200; + const double diameter = 10; + + rseg_data[ RSEG_DEPTH_INDEX ] = depth; + rseg_data[ RSEG_LENGTH_INDEX ] = length; + rseg_data[ RSEG_TOTAL_LENGTH_INDEX ] = total_length; + rseg_data[ RSEG_DIAMETER_INDEX ] = diameter; + + test_assert_true( well_branch_collection_is_instance( branches )); + test_assert_int_equal( well_branch_collection_get_size( branches ) , 0 ); + test_assert_NULL( well_branch_collection_iget_start_segment( branches , 0 )); + test_assert_NULL( well_branch_collection_get_start_segment( branches , 0 )); + test_assert_false( well_branch_collection_has_branch( branches , 0 )); + { + well_segment_type * segment1 = well_segment_alloc(189 , 99 , 78 , rseg_data); + well_segment_type * segment2 = well_segment_alloc(200 , 189 , 78 , rseg_data); + + test_assert_false( well_branch_collection_add_start_segment( branches , segment1 )); + + test_assert_true( well_segment_link( segment2 , segment1 )); + test_assert_true( well_branch_collection_add_start_segment( branches , segment2 )); + + test_assert_int_equal( well_branch_collection_get_size( branches ) , 1 ); + test_assert_true( well_segment_is_instance( well_branch_collection_iget_start_segment( branches , 0 ))); + test_assert_true( well_segment_is_instance( well_branch_collection_get_start_segment( branches , 78 ))); + test_assert_true( well_branch_collection_has_branch( branches , 78 )); + + } + well_branch_collection_free( branches ); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_conn.c b/ThirdParty/Ert/devel/libecl_well/tests/well_conn.c new file mode 100644 index 0000000000..255aac1d8a --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_conn.c @@ -0,0 +1,123 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_conn.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include + + +#include +#include + + +int main(int argc , char ** argv) { + int i = 10; + int j = 5; + int k = 16; + bool open = true; + test_install_SIGNALS(); + + { + well_conn_dir_enum dir = well_conn_dirX; + well_conn_type * conn = well_conn_alloc(i,j,k,dir,open); + well_conn_type * conn2 = well_conn_alloc(i,j,k,dir,open); + well_conn_type * conn3 = well_conn_alloc(i,j,k+1,dir,open); + test_assert_not_NULL( conn ); + test_assert_true( well_conn_is_instance( conn )); + test_assert_int_equal( i , well_conn_get_i( conn )); + test_assert_int_equal( j , well_conn_get_j( conn )); + test_assert_int_equal( k , well_conn_get_k( conn )); + test_assert_int_equal( dir , well_conn_get_dir( conn )); + test_assert_bool_equal( open , well_conn_open( conn )); + test_assert_false( well_conn_MSW( conn )); + test_assert_true( well_conn_matrix_connection( conn )); + test_assert_true( well_conn_equal( conn , conn2 )); + test_assert_false( well_conn_equal( conn , conn3 )); + well_conn_free( conn ); + } + + { + well_conn_dir_enum dir = well_conn_fracX; + well_conn_type * conn = well_conn_alloc(i,j,k,dir,open); + test_assert_NULL( conn ); + } + + + { + well_conn_dir_enum dir = well_conn_fracX; + well_conn_type * conn = well_conn_alloc_fracture(i,j,k,dir,open); + test_assert_not_NULL( conn ); + test_assert_int_equal( i , well_conn_get_i( conn )); + test_assert_int_equal( j , well_conn_get_j( conn )); + test_assert_int_equal( k , well_conn_get_k( conn )); + test_assert_bool_equal( open , well_conn_open( conn )); + test_assert_int_equal( dir , well_conn_get_dir( conn )); + test_assert_false( well_conn_MSW( conn )); + test_assert_false( well_conn_matrix_connection( conn )); + test_assert_true( well_conn_fracture_connection( conn )); + well_conn_free( conn ); + } + + + { + well_conn_dir_enum dir = well_conn_dirX; + well_conn_type * conn = well_conn_alloc_fracture(i,j,k,dir,open); + test_assert_not_NULL( conn ); + } + + { + int segment = 16; + well_conn_dir_enum dir = well_conn_dirX; + well_conn_type * conn = well_conn_alloc_MSW(i,j,k,dir,open,segment); + test_assert_not_NULL( conn ); + test_assert_int_equal( i , well_conn_get_i( conn )); + test_assert_int_equal( j , well_conn_get_j( conn )); + test_assert_int_equal( k , well_conn_get_k( conn )); + test_assert_int_equal( segment , well_conn_get_segment( conn )); + test_assert_bool_equal( open , well_conn_open( conn )); + test_assert_int_equal( dir , well_conn_get_dir( conn )); + test_assert_true( well_conn_MSW( conn )); + test_assert_true( well_conn_matrix_connection( conn )); + well_conn_free( conn ); + } + + + { + int segment = 16; + well_conn_dir_enum dir = well_conn_fracX; + well_conn_type * conn = well_conn_alloc_fracture_MSW(i,j,k,dir,open,segment); + test_assert_not_NULL( conn ); + test_assert_int_equal( i , well_conn_get_i( conn )); + test_assert_int_equal( j , well_conn_get_j( conn )); + test_assert_int_equal( k , well_conn_get_k( conn )); + test_assert_int_equal( segment , well_conn_get_segment( conn )); + test_assert_bool_equal( open , well_conn_open( conn )); + test_assert_int_equal( dir , well_conn_get_dir( conn )); + test_assert_true( well_conn_MSW( conn )); + test_assert_false( well_conn_matrix_connection( conn )); + well_conn_free( conn ); + } + + + + +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_conn_collection.c b/ThirdParty/Ert/devel/libecl_well/tests/well_conn_collection.c new file mode 100644 index 0000000000..41b4fa4cfe --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_conn_collection.c @@ -0,0 +1,55 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_conn_collection.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include + + +#include +#include + + +void test_empty() { + well_conn_collection_type * wellcc = well_conn_collection_alloc( ); + test_assert_not_NULL( wellcc ); + test_assert_true( well_conn_collection_is_instance( wellcc )); + + test_assert_int_equal( 0 , well_conn_collection_get_size( wellcc )); + { + well_conn_type * conn = well_conn_collection_iget( wellcc , 0 ); + test_assert_NULL( conn ); + } + { + const well_conn_type * conn = well_conn_collection_iget_const( wellcc , 10 ); + test_assert_NULL( conn ); + } + + well_conn_collection_free( wellcc ); +} + + + +int main(int argc , char ** argv) { + test_empty(); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_conn_load.c b/ThirdParty/Ert/devel/libecl_well/tests/well_conn_load.c new file mode 100644 index 0000000000..928744ec5b --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_conn_load.c @@ -0,0 +1,104 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_conn_load.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + + + +int main(int argc , char ** argv) { + const char * Xfile = argv[1]; + bool MSW; + ecl_file_type * rst_file = ecl_file_open( Xfile , 0 ); + ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_file ); + + test_install_SIGNALS(); + test_assert_true( util_sscanf_bool( argv[2] , &MSW )); + test_assert_not_NULL( rst_file ); + test_assert_not_NULL( rst_head ); + + { + int iwell; + const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 ); + const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 ); + bool caseMSW = false; + + for (iwell = 0; iwell < rst_head->nwells; iwell++) { + const int iwel_offset = rst_head->niwelz * iwell; + int num_connections = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_CONNECTIONS_ITEM ); + int iconn; + well_conn_collection_type * wellcc = well_conn_collection_alloc( ); + well_conn_collection_type * wellcc_ref = well_conn_collection_alloc(); + + for (iconn = 0; iconn < num_connections; iconn++) { + well_conn_type * conn = well_conn_alloc_from_kw( icon_kw , rst_head , iwell , iconn ); + + test_assert_true( well_conn_is_instance( conn )); + test_assert_not_NULL( conn ); + if (!MSW) + test_assert_bool_equal( well_conn_MSW( conn ) , MSW); + else + caseMSW |= well_conn_MSW( conn ); + + well_conn_collection_add( wellcc , conn ); + well_conn_collection_add_ref( wellcc_ref , conn ); + test_assert_int_equal( iconn + 1 , well_conn_collection_get_size( wellcc )); + test_assert_ptr_equal( well_conn_collection_iget_const( wellcc , iconn) , conn); + test_assert_ptr_equal( well_conn_collection_iget_const( wellcc_ref , iconn) , conn); + } + well_conn_collection_free( wellcc_ref ); + { + + int i; + for (i=0; i < well_conn_collection_get_size( wellcc ); i++) + test_assert_true( well_conn_is_instance( well_conn_collection_iget_const( wellcc , i ))); + + } + { + well_conn_collection_type * wellcc2 = well_conn_collection_alloc(); + int i; + + test_assert_int_equal( well_conn_collection_get_size( wellcc ) , + well_conn_collection_load_from_kw( wellcc2 , iwel_kw , icon_kw , iwell , rst_head)); + + for (i=0; i < well_conn_collection_get_size( wellcc2 ); i++) { + test_assert_true( well_conn_is_instance( well_conn_collection_iget_const( wellcc2 , i ))); + test_assert_true( well_conn_equal( well_conn_collection_iget_const( wellcc2 , i ) , well_conn_collection_iget_const( wellcc , i ))); + } + well_conn_collection_free( wellcc2 ); + } + well_conn_collection_free( wellcc ); + } + test_assert_bool_equal( caseMSW , MSW); + } + + + exit( 0 ); +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_info.c b/ThirdParty/Ert/devel/libecl_well/tests/well_info.c new file mode 100644 index 0000000000..8a8dcb5424 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_info.c @@ -0,0 +1,44 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_conn.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include +#include + + +#include + + +int main(int argc , char ** argv) { + const char * grid_file = argv[1]; + + ecl_grid_type * grid = ecl_grid_alloc( grid_file ); + test_assert_not_NULL( grid ); + { + well_info_type * well_info = well_info_alloc( grid ); + test_assert_not_NULL( well_info ); + well_info_free( well_info ); + } + ecl_grid_free( grid ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_lgr_load.c b/ThirdParty/Ert/devel/libecl_well/tests/well_lgr_load.c index d3a3b477c6..ea656e1164 100644 --- a/ThirdParty/Ert/devel/libecl_well/tests/well_lgr_load.c +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_lgr_load.c @@ -41,12 +41,10 @@ int main( int argc , char ** argv) { Killing with SIGKILL (-9) will not give a backtrace.*/ signal(SIGABRT , util_abort_signal); /* Signal abort. */ { - well_info_type * well_info = well_info_alloc( NULL ); - int i; - for (i=1; i < argc; i++) { - printf("Loading file: %s \n",argv[i]); - well_info_load_rstfile( well_info , argv[i]); - } + ecl_grid_type * grid = ecl_grid_alloc( argv[1] ); + well_info_type * well_info = well_info_alloc( grid ); + + well_info_load_rstfile( well_info , argv[2]); // List all wells: { diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_segment.c b/ThirdParty/Ert/devel/libecl_well/tests/well_segment.c new file mode 100644 index 0000000000..fcc34ad73d --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_segment.c @@ -0,0 +1,115 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_segment.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include + + +#include +#include + +int main(int argc , char ** argv) { + test_install_SIGNALS(); + double * rseg_data = util_calloc( 100 , sizeof * rseg_data ); + const double depth = 100; + const double length = 20; + const double total_length = 200; + const double diameter = 10; + + rseg_data[ RSEG_DEPTH_INDEX ] = depth; + rseg_data[ RSEG_LENGTH_INDEX ] = length; + rseg_data[ RSEG_TOTAL_LENGTH_INDEX ] = total_length; + rseg_data[ RSEG_DIAMETER_INDEX ] = diameter; + { + int segment_id = 78; + int outlet_segment_id = 100; + int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_MAIN_STEM_VALUE; + well_segment_type * ws = well_segment_alloc(segment_id , outlet_segment_id , branch_nr, rseg_data); + + test_assert_true( well_segment_is_instance( ws )); + test_assert_int_equal( 0 , well_segment_get_link_count( ws )); + test_assert_NULL( well_segment_get_outlet( ws )); + test_assert_int_equal( well_segment_get_outlet_id( ws ) , outlet_segment_id ); + test_assert_int_equal( well_segment_get_branch_id( ws ) , branch_nr ); + test_assert_int_equal( well_segment_get_id( ws ) , segment_id ); + + test_assert_false( well_segment_nearest_wellhead( ws )); + test_assert_true( well_segment_active( ws )); + test_assert_true( well_segment_main_stem( ws )); + + test_assert_double_equal( depth , well_segment_get_depth( ws )); + test_assert_double_equal( length , well_segment_get_length( ws )); + test_assert_double_equal( total_length , well_segment_get_total_length( ws )); + test_assert_double_equal( diameter , well_segment_get_diameter( ws )); + + well_segment_free( ws ); + } + + { + int outlet_segment_id = ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE; + int branch_nr = 100; + well_segment_type * ws = well_segment_alloc(12 , outlet_segment_id , branch_nr, rseg_data); + + test_assert_true( well_segment_nearest_wellhead( ws )); + test_assert_false( well_segment_main_stem( ws )); + } + + + { + int outlet_segment_id = ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE; + int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_INACTIVE_VALUE; + well_segment_type * ws = well_segment_alloc(89 , outlet_segment_id , branch_nr, rseg_data); + + test_assert_false( well_segment_active( ws )); + } + + { + int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_MAIN_STEM_VALUE; + int outlet_id = 0; + well_segment_type * outlet = well_segment_alloc(outlet_id , ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE , branch_nr, rseg_data); + well_segment_type * ws = well_segment_alloc(100 , outlet_id , branch_nr, rseg_data); + + test_assert_true( well_segment_link( ws , outlet )); + test_assert_ptr_equal( well_segment_get_outlet( ws ) , outlet ); + test_assert_int_equal( well_segment_get_link_count( outlet ) , 1 ); + test_assert_ptr_not_equal( ws , well_segment_get_outlet( ws )); + + well_segment_link_strict( ws , outlet ); // This relinks - not very logical; refcount gets wrong. + well_segment_free( ws ); + } + + { + int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_MAIN_STEM_VALUE; + int outlet_id = 0; + well_segment_type * outlet = well_segment_alloc(outlet_id , ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE , branch_nr , rseg_data); + well_segment_type * ws = well_segment_alloc(100 , outlet_id + 1, branch_nr, rseg_data); + + test_assert_false( well_segment_link( ws , outlet )); + test_assert_NULL( well_segment_get_outlet( ws ) ); + test_assert_int_equal( well_segment_get_link_count( outlet ) , 0 ); + + well_segment_free( ws ); + } + free( rseg_data ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_segment_branch_conn_load.c b/ThirdParty/Ert/devel/libecl_well/tests/well_segment_branch_conn_load.c new file mode 100644 index 0000000000..36349ba508 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_segment_branch_conn_load.c @@ -0,0 +1,106 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_segment_conn_load.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + + +int main(int argc , char ** argv) { + const char * Xfile = argv[1]; + ecl_file_type * rst_file = ecl_file_open( Xfile , 0 ); + ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_file ); + const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 ); + const ecl_kw_type * iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0 ); + const ecl_kw_type * rseg_kw = ecl_file_iget_named_kw( rst_file , RSEG_KW , 0 ); + const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 ); + + test_install_SIGNALS(); + test_assert_not_NULL( rst_file ); + test_assert_not_NULL( rst_head ); + { + int well_nr; + for (well_nr = 0; well_nr < rst_head->nwells; well_nr++) { + well_conn_collection_type * connections = well_conn_collection_alloc(); + well_conn_collection_load_from_kw( connections , iwel_kw , icon_kw , well_nr , rst_head); + { + well_segment_collection_type * segments = well_segment_collection_alloc(); + + if (well_segment_collection_load_from_kw( segments , well_nr , iwel_kw , iseg_kw , rseg_kw , rst_head )) { + well_branch_collection_type * branches = well_branch_collection_alloc(); + + test_assert_true( well_segment_well_is_MSW( well_nr , iwel_kw , rst_head)); + well_segment_collection_link( segments ); + { + int is; + for (is=0; is < well_segment_collection_get_size( segments ); is++) { + well_segment_type * segment = well_segment_collection_iget( segments , is ); + + if (well_segment_nearest_wellhead( segment )) + test_assert_NULL( well_segment_get_outlet( segment )); + else + test_assert_not_NULL( well_segment_get_outlet( segment )); + + test_assert_int_not_equal( well_segment_get_id( segment ) , well_segment_get_outlet_id( segment )); + test_assert_ptr_not_equal( segment , well_segment_get_outlet( segment )); + } + } + well_segment_collection_add_branches( segments , branches ); + { + int ib; + for (ib = 0; ib < well_branch_collection_get_size( branches ); ib++) { + const well_segment_type * start_segment = well_branch_collection_iget_start_segment( branches , ib ); + const well_segment_type * segment = start_segment; + + printf("Branch %d " , ib ); + while (segment) { + printf("%d -> ",well_segment_get_id( segment )); + segment = well_segment_get_outlet( segment ); + } + printf(" X \n"); + } + } + well_segment_collection_add_connections( segments , ECL_GRID_GLOBAL_GRID , connections ); + well_branch_collection_free( branches ); + } else + test_assert_false( well_segment_well_is_MSW( well_nr , iwel_kw , rst_head )); + + well_segment_collection_free( segments ); + } + well_conn_collection_free( connections ); + } + } + + ecl_file_close( rst_file ); + ecl_rsthead_free( rst_head ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_segment_collection.c b/ThirdParty/Ert/devel/libecl_well/tests/well_segment_collection.c new file mode 100644 index 0000000000..98c3772b68 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_segment_collection.c @@ -0,0 +1,87 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_segment_collection.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include + + +#include + + +int main(int argc , char ** argv) { + test_install_SIGNALS(); + + double * rseg_data = util_calloc( 100 , sizeof * rseg_data ); + well_segment_collection_type * sc = well_segment_collection_alloc(); + test_assert_not_NULL( sc ); + test_assert_int_equal( well_segment_collection_get_size( sc ) , 0 ); + + { + int outlet_segment_id = ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE; + int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_INACTIVE_VALUE; + well_segment_type * ws = well_segment_alloc(89 , outlet_segment_id , branch_nr, rseg_data); + + well_segment_collection_add( sc , ws ); + test_assert_int_equal( well_segment_collection_get_size( sc ) , 1); + test_assert_ptr_equal( well_segment_collection_iget( sc , 0 ) , ws ); + + test_assert_false( well_segment_collection_has_segment( sc , 451 )); + test_assert_true( well_segment_collection_has_segment( sc , 89 )); + test_assert_ptr_equal( well_segment_collection_get( sc , 89 ) , ws ); + } + + { + int outlet_segment_id = ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE; + int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_INACTIVE_VALUE; + well_segment_type * ws = well_segment_alloc(90 , outlet_segment_id , branch_nr , rseg_data); + + well_segment_collection_add( sc , ws ); + test_assert_int_equal( well_segment_collection_get_size( sc ) , 2); + test_assert_ptr_equal( well_segment_collection_iget( sc , 1 ) , ws ); + + test_assert_false( well_segment_collection_has_segment( sc , 451 )); + test_assert_true( well_segment_collection_has_segment( sc , 89 )); + test_assert_true( well_segment_collection_has_segment( sc , 90 )); + test_assert_ptr_equal( well_segment_collection_get( sc , 90 ) , ws ); + test_assert_NULL( well_segment_collection_get( sc , 76 )); + } + + { + int outlet_segment_id = ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE; + int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_INACTIVE_VALUE; + well_segment_type * ws = well_segment_alloc(89 , outlet_segment_id , branch_nr, rseg_data); + + well_segment_collection_add( sc , ws ); + test_assert_int_equal( well_segment_collection_get_size( sc ) , 2); + test_assert_ptr_equal( well_segment_collection_iget( sc , 0 ) , ws ); + + test_assert_false( well_segment_collection_has_segment( sc , 451 )); + test_assert_true( well_segment_collection_has_segment( sc , 89 )); + test_assert_ptr_equal( well_segment_collection_get( sc , 89 ) , ws ); + } + + free( rseg_data ); + well_segment_collection_free( sc ); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_segment_conn.c b/ThirdParty/Ert/devel/libecl_well/tests/well_segment_conn.c new file mode 100644 index 0000000000..1779f6734d --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_segment_conn.c @@ -0,0 +1,59 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_segment_conn.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include +#include + +#include +#include +#include + + +int main(int argc , char ** argv) { + test_install_SIGNALS(); + double * rseg_data = util_calloc( 100 , sizeof * rseg_data ); + { + int segment_id = 78; + int outlet_segment_id = 100; + int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_MAIN_STEM_VALUE; + well_segment_type * ws = well_segment_alloc(segment_id , outlet_segment_id , branch_nr, rseg_data); + well_conn_type * conn1 = well_conn_alloc_MSW(1,1,1,true,well_conn_dirX,segment_id); + well_conn_type * conn2 = well_conn_alloc_MSW(1,1,1,true,well_conn_dirX,segment_id + 1); + + test_assert_false( well_segment_has_global_grid_connections( ws )); + + test_assert_true( well_segment_add_connection( ws , ECL_GRID_GLOBAL_GRID , conn1 )); + test_assert_false( well_segment_add_connection( ws , ECL_GRID_GLOBAL_GRID , conn2 )); + + test_assert_true( well_segment_has_grid_connections( ws , ECL_GRID_GLOBAL_GRID )); + test_assert_true( well_segment_has_global_grid_connections( ws )); + test_assert_false( well_segment_has_grid_connections( ws , "DoesNotExist")); + + test_assert_true( well_conn_collection_is_instance( well_segment_get_connections( ws , ECL_GRID_GLOBAL_GRID))); + test_assert_true( well_conn_collection_is_instance( well_segment_get_global_connections( ws))); + test_assert_NULL( well_segment_get_connections( ws , "doesNotExist")); + } + free( rseg_data ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_segment_conn_load.c b/ThirdParty/Ert/devel/libecl_well/tests/well_segment_conn_load.c new file mode 100644 index 0000000000..6fbdb46eb6 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_segment_conn_load.c @@ -0,0 +1,107 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_segment_conn_load.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + + +int main(int argc , char ** argv) { + const char * Xfile = argv[1]; + ecl_file_type * rst_file = ecl_file_open( Xfile , 0 ); + ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_file ); + const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 ); + const ecl_kw_type * iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0 ); + const ecl_kw_type * rseg_kw = ecl_file_iget_named_kw( rst_file , RSEG_KW , 0 ); + const ecl_kw_type * icon_kw = ecl_file_iget_named_kw( rst_file , ICON_KW , 0 ); + + test_install_SIGNALS(); + test_assert_not_NULL( rst_file ); + test_assert_not_NULL( rst_head ); + { + int well_nr; + for (well_nr = 0; well_nr < rst_head->nwells; well_nr++) { + well_conn_collection_type * connections = well_conn_collection_alloc(); + well_conn_collection_load_from_kw( connections , iwel_kw , icon_kw , well_nr , rst_head); + { + well_segment_collection_type * segments = well_segment_collection_alloc(); + + if (well_segment_collection_load_from_kw( segments , well_nr , iwel_kw , iseg_kw , rseg_kw , rst_head )) { + well_branch_collection_type * branches = well_branch_collection_alloc(); + + test_assert_true( well_segment_well_is_MSW( well_nr , iwel_kw , rst_head)); + well_segment_collection_link( segments ); + { + int is; + for (is=0; is < well_segment_collection_get_size( segments ); is++) { + well_segment_type * segment = well_segment_collection_iget( segments , is ); + + if (well_segment_nearest_wellhead( segment )) + test_assert_NULL( well_segment_get_outlet( segment )); + else + test_assert_not_NULL( well_segment_get_outlet( segment )); + + test_assert_ptr_not_equal( segment , well_segment_get_outlet( segment )); + } + } + + well_segment_collection_add_branches( segments , branches ); + { + int ib; + for (ib = 0; ib < well_branch_collection_get_size( branches ); ib++) { + const well_segment_type * start_segment = well_branch_collection_iget_start_segment( branches , ib ); + const well_segment_type * segment = start_segment; + + printf("Branch %d/%d " , ib , well_branch_collection_get_size( branches ) ); + while (segment) { + printf("[%p]%d -> \n",segment , well_segment_get_id( segment )); + segment = well_segment_get_outlet( segment ); + } + printf("\n"); + sleep(1); + } + } + well_segment_collection_add_connections( segments , ECL_GRID_GLOBAL_GRID , connections ); + well_branch_collection_free( branches ); + } else + test_assert_false( well_segment_well_is_MSW( well_nr , iwel_kw , rst_head )); + + well_segment_collection_free( segments ); + } + well_conn_collection_free( connections ); + } + } + + ecl_file_close( rst_file ); + ecl_rsthead_free( rst_head ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_segment_load.c b/ThirdParty/Ert/devel/libecl_well/tests/well_segment_load.c new file mode 100644 index 0000000000..032632b186 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_segment_load.c @@ -0,0 +1,88 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_segment_load.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + + +int main(int argc , char ** argv) { + const char * Xfile = argv[1]; + ecl_file_type * rst_file = ecl_file_open( Xfile , 0 ); + ecl_rsthead_type * rst_head = ecl_rsthead_alloc( rst_file ); + const ecl_kw_type * iwel_kw = ecl_file_iget_named_kw( rst_file , IWEL_KW , 0 ); + const ecl_kw_type * iseg_kw = ecl_file_iget_named_kw( rst_file , ISEG_KW , 0 ); + const ecl_kw_type * rseg_kw = ecl_file_iget_named_kw( rst_file , RSEG_KW , 0 ); + + test_install_SIGNALS(); + test_assert_not_NULL( rst_file ); + test_assert_not_NULL( rst_head ); + + { + int well_nr; + + for (well_nr = 0; well_nr < rst_head->nwells; well_nr++) { + int iwel_offset = rst_head->niwelz * well_nr; + well_segment_collection_type * segments = well_segment_collection_alloc(); + int seg_well_nr = ecl_kw_iget_int( iwel_kw , iwel_offset + IWEL_SEGMENTED_WELL_NR_ITEM) - 1; // -1: Ordinary well. + if (seg_well_nr >= 0) { + int segment_id; + int segment_count = 0; + + for (segment_id = 0; segment_id < rst_head->nsegmx; segment_id++) { + well_segment_type * segment = well_segment_alloc_from_kw( iseg_kw , rseg_kw , rst_head , seg_well_nr , segment_id ); + + test_assert_true( well_segment_is_instance( segment )); + + if (well_segment_active( segment )) { + well_segment_collection_add( segments , segment ); + test_assert_int_equal( well_segment_collection_get_size( segments ) , segment_count + 1); + test_assert_ptr_equal( well_segment_collection_iget( segments , segment_count) , segment ); + segment_count++; + } else + well_segment_free( segment ); + } + } + + { + well_segment_collection_type * segments2 = well_segment_collection_alloc(); + test_assert_int_equal( well_segment_collection_load_from_kw( segments2 , well_nr , iwel_kw , iseg_kw , rseg_kw , rst_head ) , + well_segment_collection_get_size( segments)); + + well_segment_collection_link( segments ); + well_segment_collection_link( segments2 ); + well_segment_collection_free( segments ); + well_segment_collection_free( segments2 ); + } + } + } + ecl_file_close( rst_file ); + ecl_rsthead_free( rst_head ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_state.c b/ThirdParty/Ert/devel/libecl_well/tests/well_state.c new file mode 100644 index 0000000000..9131c3ebe7 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_state.c @@ -0,0 +1,67 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_state.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include + +#include + + +int main(int argc , char ** argv) { + test_install_SIGNALS(); + + test_assert_int_equal( well_state_translate_ecl_type_int( IWEL_UNDOCUMENTED_ZERO) , UNDOCUMENTED_ZERO); + test_assert_int_equal( well_state_translate_ecl_type_int( IWEL_PRODUCER) , PRODUCER); + test_assert_int_equal( well_state_translate_ecl_type_int( IWEL_WATER_INJECTOR) , WATER_INJECTOR); + test_assert_int_equal( well_state_translate_ecl_type_int( IWEL_GAS_INJECTOR) , GAS_INJECTOR); + test_assert_int_equal( well_state_translate_ecl_type_int( IWEL_OIL_INJECTOR) , OIL_INJECTOR); + + { + const char * well_name = "WELL"; + int report_nr = 100; + int global_well_nr = 67; + time_t valid_from = -1; + bool open = false; + well_type_enum type = GAS_INJECTOR; + + well_state_type * well_state = well_state_alloc(well_name , global_well_nr , open , type , report_nr , valid_from); + test_assert_true( well_state_is_instance( well_state) ); + + test_assert_false( well_state_is_MSW( well_state )); + test_assert_string_equal( well_name , well_state_get_name( well_state )); + test_assert_int_equal( global_well_nr , well_state_get_well_nr( well_state )); + test_assert_bool_equal( open , well_state_is_open( well_state )); + test_assert_int_equal( type , well_state_get_type( well_state )); + test_assert_int_equal( report_nr , well_state_get_report_nr( well_state )); + test_assert_time_t_equal( valid_from , well_state_get_sim_time( well_state )); + + test_assert_NULL( well_state_get_global_connections( well_state )); + test_assert_false( well_state_has_global_connections( well_state )); + test_assert_NULL( well_state_get_grid_connections( well_state , "GRID")); + test_assert_false( well_state_has_grid_connections( well_state , "GRID")); + + well_state_free( well_state ); + } + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_state_load.c b/ThirdParty/Ert/devel/libecl_well/tests/well_state_load.c new file mode 100644 index 0000000000..d9375259d4 --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_state_load.c @@ -0,0 +1,78 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_state_load.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include +#include +#include +#include + +#include + + +int main(int argc , char ** argv) { + test_install_SIGNALS(); + { + const char * grid_file = argv[1]; + const char * rst_file_name = argv[2]; + + ecl_grid_type * grid = ecl_grid_alloc( grid_file ); + ecl_file_type * rst_file = ecl_file_open( rst_file_name , 0); + ecl_rsthead_type * header = ecl_rsthead_alloc( rst_file ); + const char * well_name = "WELL"; + int report_nr = 100; + time_t valid_from = -1; + bool open = false; + well_type_enum type = GAS_INJECTOR; + int global_well_nr = 0; + + for (global_well_nr = 0; global_well_nr < header->nwells; global_well_nr++) { + well_state_type * well_state = well_state_alloc(well_name , global_well_nr , open , type , report_nr , valid_from); + test_assert_true( well_state_is_instance( well_state) ); + well_state_add_connections( well_state , grid , rst_file , 0 ); + + test_assert_true( well_state_has_grid_connections( well_state , ECL_GRID_GLOBAL_GRID )); + test_assert_false( well_state_has_grid_connections( well_state , "???" )); + test_assert_true( well_state_has_global_connections( well_state )); + + well_state_add_MSW( well_state , rst_file , global_well_nr ); + { + const well_segment_collection_type * segments = well_state_get_segments( well_state ); + const well_branch_collection_type * branches = well_state_get_branches( well_state ); + + if (well_state_is_MSW( well_state )) { + test_assert_true( ecl_file_has_kw( rst_file , ISEG_KW )); + test_assert_int_not_equal( well_segment_collection_get_size( segments ) , 0); + test_assert_int_not_equal( well_branch_collection_get_size( branches ) , 0); + } else { + test_assert_int_equal( well_segment_collection_get_size( segments ) , 0); + test_assert_int_equal( well_branch_collection_get_size( branches ) , 0); + test_assert_false( well_state_is_MSW( well_state )); + } + } + well_state_free( well_state ); + } + } + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_state_load_missing_RSEG.c b/ThirdParty/Ert/devel/libecl_well/tests/well_state_load_missing_RSEG.c new file mode 100644 index 0000000000..b0a7e4071e --- /dev/null +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_state_load_missing_RSEG.c @@ -0,0 +1,67 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'well_state_load_missing_RSEG.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include +#include +#include + +#include +#include +#include +#include + +#include + + +int main(int argc , char ** argv) { + test_install_SIGNALS(); + { + const char * grid_file = argv[1]; + const char * rst_file_name = argv[2]; + + ecl_grid_type * grid = ecl_grid_alloc( grid_file ); + ecl_file_type * rst_file = ecl_file_open( rst_file_name , 0); + ecl_rsthead_type * header = ecl_rsthead_alloc( rst_file ); + const char * well_name = "WELL"; + int report_nr = 100; + time_t valid_from = -1; + bool open = false; + well_type_enum type = GAS_INJECTOR; + int global_well_nr = 0; + + for (global_well_nr = 0; global_well_nr < header->nwells; global_well_nr++) { + well_state_type * well_state = well_state_alloc(well_name , global_well_nr , open , type , report_nr , valid_from); + test_assert_true( well_state_is_instance( well_state) ); + well_state_add_connections( well_state , grid , rst_file , 0 ); + well_state_add_MSW( well_state , rst_file , global_well_nr ); + + { + const well_segment_collection_type * segments = well_state_get_segments( well_state ); + + if (!ecl_file_has_kw( rst_file , RSEG_KW )) + test_assert_int_equal( 0 , well_segment_collection_get_size( segments )); + + } + well_state_free( well_state ); + } + } + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libecl_well/tests/well_ts.c b/ThirdParty/Ert/devel/libecl_well/tests/well_ts.c index 33b1d4c0fb..25d221f0c0 100644 --- a/ThirdParty/Ert/devel/libecl_well/tests/well_ts.c +++ b/ThirdParty/Ert/devel/libecl_well/tests/well_ts.c @@ -23,13 +23,16 @@ #include #include +#include #include int main(int argc , char ** argv) { const char * case_path = argv[1]; + char * grid_file = util_alloc_filename(NULL , case_path, "EGRID"); stringlist_type * file_list = stringlist_alloc_new( ); + ecl_grid_type * grid = ecl_grid_alloc( grid_file ); ecl_util_select_filelist( NULL , case_path , ECL_RESTART_FILE , false , file_list); printf("Searching in:%s \n",case_path); @@ -50,7 +53,7 @@ int main(int argc , char ** argv) { } } { - well_info_type * well_info = well_info_alloc( NULL ); + well_info_type * well_info = well_info_alloc( grid ); int i; for (i=0; i < stringlist_get_size( file_list ); i++) well_info_load_rstfile( well_info , stringlist_iget(file_list , i)); @@ -58,7 +61,7 @@ int main(int argc , char ** argv) { } { - well_info_type * well_info = well_info_alloc( NULL ); + well_info_type * well_info = well_info_alloc( grid ); int i; stringlist_reverse( file_list ); for (i=0; i < stringlist_get_size( file_list ); i++) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/analysis.py b/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/analysis.py deleted file mode 100644 index 1a6d312eb4..0000000000 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/analysis.py +++ /dev/null @@ -1,93 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'analysis.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - - -# ---------------------------------------------------------------------------------------------- -# Analysis tab -# ---------------------------------------------------------------------------------------------- -from ert_gui.widgets.checkbox import CheckBox -from ert_gui.widgets.spinnerwidgets import IntegerSpinner, DoubleSpinner, DoubleSpinner -import ert_gui.widgets.tablewidgets -from ert_gui.widgets.pathchooser import PathChooser -from ert_gui.widgets.combochoice import ComboChoice -from PyQt4 import QtGui -import ert.enkf - -def createAnalysisPage(configPanel, parent): - configPanel.startPage("Analysis") - - r = configPanel.addRow(CheckBox(parent, "ENKF rerun", "config/analysis/enkf_rerun", "Perform rerun")) - r.getter = lambda ert : ert.enkf.analysis_config_get_rerun(ert.analysis_config) - r.setter = lambda ert, value : ert.enkf.analysis_config_set_rerun(ert.analysis_config, value) - - r = configPanel.addRow(IntegerSpinner(parent, "Rerun start", "config/analysis/rerun_start", 0, 100000)) - r.getter = lambda ert : ert.enkf.analysis_config_get_rerun_start(ert.analysis_config) - r.setter = lambda ert, value : ert.enkf.analysis_config_set_rerun_start(ert.analysis_config, value) - - r = configPanel.addRow(PathChooser(parent, "ENKF schedule file", "config/analysis/enkf_sched_file")) - r.getter = lambda ert : ert.enkf.model_config_get_enkf_sched_file(ert.enkf.enkf_main_get_model_config(ert.main)) - r.setter = lambda ert, value : ert.enkf.model_config_set_enkf_sched_file(ert.enkf.enkf_main_get_model_config(ert.main), str(value)) - - r = configPanel.addRow(ert_gui.widgets.tablewidgets.KeywordList(parent, "Local config", "config/analysis/local_config")) - r.newKeywordPopup = lambda list : QtGui.QFileDialog.getOpenFileName(r, "Select a path", "") - - def get_local_config_files(ert): - local_config = ert.enkf.enkf_main_get_local_config(ert.main) - config_files_pointer = ert.enkf.local_config_get_config_files(local_config) - return ert.getStringList(config_files_pointer) - - r.getter = get_local_config_files - - def add_config_file(ert, value): - local_config = ert.enkf.enkf_main_get_local_config(ert.main) - ert.enkf.local_config_clear_config_files(local_config) - - for file in value: - ert.enkf.local_config_add_config_file(local_config, file) - - r.setter = add_config_file - - r = configPanel.addRow(PathChooser(parent, "Update log", "config/analysis/update_log")) - r.getter = lambda ert : ert.enkf.analysis_config_get_log_path(ert.analysis_config) - r.setter = lambda ert, value : ert.enkf.analysis_config_set_log_path(ert.analysis_config, str(value)) - - - configPanel.startGroup("EnKF") - - r = configPanel.addRow(DoubleSpinner(parent, "Alpha", "config/analysis/enkf_alpha", 0, 100000, 2)) - r.getter = lambda ert : ert.enkf.analysis_config_get_alpha(ert.analysis_config) - r.setter = lambda ert, value : ert.enkf.analysis_config_set_alpha(ert.analysis_config, value) - - r = configPanel.addRow(CheckBox(parent, "Merge Observations", "config/analysis/enkf_merge_observations", "Perform merge")) - r.getter = lambda ert : ert.enkf.analysis_config_get_merge_observations(ert.analysis_config) - r.setter = lambda ert, value : ert.enkf.analysis_config_set_merge_observations(ert.analysis_config, value) - - - enkf_mode_type = {"ENKF_STANDARD" : 10, "ENKF_SQRT" : 20} - enkf_mode_type_inverted = {10 : "ENKF_STANDARD" , 20 : "ENKF_SQRT"} - r = configPanel.addRow(ComboChoice(parent, enkf_mode_type.keys(), "Mode", "config/analysis/enkf_mode")) - r.getter = lambda ert : enkf_mode_type_inverted[ert.enkf.analysis_config_get_enkf_mode(ert.analysis_config)] - r.setter = lambda ert, value : ert.enkf.analysis_config_set_enkf_mode(ert.analysis_config, enkf_mode_type[str(value)]) - - - r = configPanel.addRow(DoubleSpinner(parent, "Truncation", "config/analysis/enkf_truncation", 0, 1, 2)) - r.getter = lambda ert : ert.enkf.analysis_config_get_truncation(ert.analysis_config) - r.setter = lambda ert, value : ert.enkf.analysis_config_set_truncation(ert.analysis_config, value) - - - - configPanel.endGroup() - configPanel.endPage() diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/rftfetcher.py b/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/rftfetcher.py deleted file mode 100644 index 08d1da4521..0000000000 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/rftfetcher.py +++ /dev/null @@ -1,192 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'rftfetcher.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - - -from fetcher import PlotDataFetcherHandler -import ert.ert.ertwrapper as ertwrapper -import ert.ert.enums as enums -import plotdata -from ert.ert.enums import ert_state_enum, obs_impl_type -import numpy - -class RFTFetcher(PlotDataFetcherHandler): - - def __init__(self): - PlotDataFetcherHandler.__init__(self) - - def initialize(self, ert): - ert.prototype("long enkf_main_get_obs(long)") - ert.prototype("long enkf_main_get_fs(long)") - ert.prototype("int enkf_main_get_ensemble_size(long)") - ert.prototype("int enkf_main_get_history_length(long)") - - ert.prototype("bool enkf_fs_has_node(long, long, int, int, int)") - ert.prototype("void enkf_fs_fread_node(long, long, int, int, int)") - - ert.prototype("bool enkf_obs_has_key(long, char*)") - ert.prototype("long enkf_obs_get_vector(long, char*)") - ert.prototype("long enkf_obs_alloc_typed_keylist(long, int)") - - ert.prototype("char* obs_vector_get_state_kw(long)") - ert.prototype("long obs_vector_iget_node(long, int)") - ert.prototype("int obs_vector_get_num_active(long)") - ert.prototype("bool obs_vector_iget_active(long, int)") - - ert.prototype("long enkf_config_node_get_ref(long)") - - ert.prototype("int* field_obs_get_i(long)") - ert.prototype("int* field_obs_get_j(long)") - ert.prototype("int* field_obs_get_k(long)") - ert.prototype("int field_obs_get_size(long)") - ert.prototype("void field_obs_iget(long, int, double*, double*)") - - ert.prototype("double field_ijk_get_double(long, int, int, int)") - - ert.prototype("long field_config_get_grid(long)") - - ert.prototype("long enkf_node_alloc(long)") - ert.prototype("void enkf_node_free(long)") - ert.prototype("long enkf_node_value_ptr(long)") - - ert.prototype("void ecl_grid_get_xyz3(long, int, int, int, double*, double*, double*)", lib=ert.ecl) - - def isHandlerFor(self, ert, key): - enkf_obs = ert.enkf.enkf_main_get_obs(ert.main) - key_list = ert.enkf.enkf_obs_alloc_typed_keylist(enkf_obs, obs_impl_type.FIELD_OBS.value()) - field_obs = ert.getStringList(key_list, free_after_use=True) - return key in field_obs - - def fetch(self, ert, key, parameter, data, comparison_fs): - enkf_obs = ert.enkf.enkf_main_get_obs(ert.main) - obs_vector = ert.enkf.enkf_obs_get_vector(enkf_obs, key) - - num_active = ert.enkf.obs_vector_get_num_active(obs_vector) - if num_active == 1: - report_step = ert.enkf.obs_vector_get_active_report_step(obs_vector) - elif num_active > 1: - history_length = ert.enkf.enkf_main_get_history_length(ert.main) - active = [] - for index in range(history_length): - if ert.enkf.obs_vector_iget_active(obs_vector , index): - active.append(index) - print "Active:", active - report_step = active[0] #todo: enable selection from GUI - else: - return - - fs = ert.enkf.enkf_main_get_fs(ert.main) - state_kw = ert.enkf.obs_vector_get_state_kw(obs_vector) - - ens_size = ert.enkf.enkf_main_get_ensemble_size(ert.main) - config_node = ert.enkf.ensemble_config_get_node(ert.ensemble_config, state_kw) - field_config = ert.enkf.enkf_config_node_get_ref(config_node) - field_obs = ert.enkf.obs_vector_iget_node(obs_vector, report_step) - - i = ert.enkf.field_obs_get_i(field_obs) - j = ert.enkf.field_obs_get_j(field_obs) - k = ert.enkf.field_obs_get_k(field_obs) - obs_size = ert.enkf.field_obs_get_size(field_obs) - grid = ert.enkf.field_config_get_grid(field_config) - - node = ert.enkf.enkf_node_alloc(config_node) - - y_obs = [] - x_obs = [] - x_std = [] - xpos = (ertwrapper.c_double)() - ypos = (ertwrapper.c_double)() - zpos = (ertwrapper.c_double)() - value = (ertwrapper.c_double)() - std = (ertwrapper.c_double)() - for index in range(obs_size): - ert.ecl.ecl_grid_get_xyz3(grid, i[index], j[index], k[index], xpos, ypos , zpos) - y_obs.append(zpos.value) - ert.enkf.field_obs_iget(field_obs, index, value, std) - x_obs.append(value.value) - x_std.append(std.value) - data.checkMaxMin(value.value + std.value) - data.checkMaxMin(value.value - std.value) - data.obs_y = numpy.array(y_obs) - data.obs_x = numpy.array(x_obs) - data.obs_std_x = numpy.array(x_std) - data.obs_std_y = None - - - for member in range(ens_size): - if ert.enkf.enkf_fs_has_node(fs, config_node, report_step, member, ert_state_enum.ANALYZED.value()): - ert.enkf.enkf_fs_fread_node(fs, node, report_step, member, ert_state_enum.ANALYZED.value()) - elif ert.enkf.enkf_fs_has_node(fs, config_node, report_step, member, ert_state_enum.FORECAST.value()): - ert.enkf.enkf_fs_fread_node(fs, node, report_step, member, ert_state_enum.FORECAST.value()) - else: - print "No data found for member %d/%d." % (member, report_step) - continue - - data.x_data[member] = [] - data.y_data[member] = [] - x_data = data.x_data[member] - y_data = data.y_data[member] - - field = ert.enkf.enkf_node_value_ptr(node) - for index in range(obs_size): - value = ert.enkf.field_ijk_get_double(field, i[index] , j[index] , k[index]) - x_data.append(value) - y_data.append(y_obs[index]) - data.checkMaxMin(value) - - data.x_data[member] = numpy.array(x_data) - data.y_data[member] = numpy.array(y_data) - - if not comparison_fs is None: - comp_node = ert.enkf.enkf_node_alloc(config_node) - for member in range(ens_size): - if ert.enkf.enkf_fs_has_node(comparison_fs, config_node, report_step, member, ert_state_enum.ANALYZED.value()): - ert.enkf.enkf_fs_fread_node(comparison_fs, comp_node, report_step, member, ert_state_enum.ANALYZED.value()) - elif ert.enkf.enkf_fs_has_node(comparison_fs, config_node, report_step, member, ert_state_enum.FORECAST.value()): - ert.enkf.enkf_fs_fread_node(comparison_fs, comp_node, report_step, member, ert_state_enum.FORECAST.value()) - else: - print "No data found for member %d/%d." % (member, report_step) - continue - - data.x_comp_data[member] = [] - data.y_comp_data[member] = [] - x_data = data.x_comp_data[member] - y_data = data.y_comp_data[member] - - field = ert.enkf.enkf_node_value_ptr(comp_node) - for index in range(obs_size): - value = ert.enkf.field_ijk_get_double(field, i[index] , j[index] , k[index]) - x_data.append(value) - y_data.append(y_obs[index]) - data.checkMaxMin(value) - - data.x_comp_data[member] = numpy.array(x_data) - data.y_comp_data[member] = numpy.array(y_data) - - ert.enkf.enkf_node_free(comp_node) - - ert.enkf.enkf_node_free(node) - - data.x_data_type = "number" - data.inverted_y_axis = True - - def getConfigurationWidget(self, context_data): - return None - - def configure(self, parameter, context_data): - pass #nothing to configure, yet - - - diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/CMakeLists.txt b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/CMakeLists.txt index e4b996c246..dfb31fc396 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/CMakeLists.txt @@ -31,6 +31,9 @@ set_source_files_properties( main.c PROPERTIES COMPILE_DEFINITIONS "COMPILE_TIME add_executable( ert ${src_list} ) target_link_libraries( ert enkf sched rms ecl config plot job_queue analysis ert_util ) +if (USE_RUNPATH) + add_runpath( ert ) +endif() if (ERT_INSTALL_PREFIX) set (destination ${CMAKE_INSTALL_PREFIX}/${ERT_INSTALL_PREFIX}/bin) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_analysis.c b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_analysis.c index 6ab512c6a7..6a75b3c5dc 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_analysis.c +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_analysis.c @@ -65,6 +65,17 @@ void enkf_tui_analysis_analyze_selected__(void * arg) { } } +void enkf_tui_analysis_scale_observation_std__(void * arg) { + enkf_main_type * enkf_main = enkf_main_safe_cast(arg); + + double scale_factor = enkf_tui_util_scanf_double_with_lower_limit("Global scaling factor", PROMPT_LEN, 0); + + if (enkf_main_have_obs(enkf_main)) { + enkf_obs_type * observations = enkf_main_get_obs(enkf_main); + enkf_obs_scale_std(observations, scale_factor); + } +} + /** @@ -228,19 +239,26 @@ void enkf_tui_analysis_menu(void * arg) { arg_pack_type * arg_pack = arg_pack_alloc(); arg_pack_append_ptr( arg_pack , enkf_main ); arg_pack_append_ptr( arg_pack , menu ); - + { - enkf_tui_analysis_update_title( enkf_main , menu ); - menu_add_item(menu , "Analyze one step manually" , "aA" , enkf_tui_analysis_analyze__ , enkf_main , NULL); - menu_add_item(menu , "Analyze interval manually" , "iI" , enkf_tui_analysis_smooth__ , enkf_main , NULL); - menu_add_item(menu , "Analyze selected steps manually" , "nN" , enkf_tui_analysis_analyze_selected__ , enkf_main , NULL); - menu_add_separator( menu ); - menu_add_item(menu , "Select analysis module" , "sS" , enkf_tui_analysis_select_module__ , arg_pack , NULL); - menu_add_item(menu , "List available modules" , "lL" , enkf_tui_analysis_list_modules__ , enkf_main , NULL); - menu_add_item(menu , "Modify analysis module parameters" , "mM" , enkf_tui_analysis_update_module__ , enkf_main , NULL); - menu_add_item(menu , "Reload current module (external only)" , "rR" , enkf_tui_analysis_reload_module__ , enkf_main , NULL); + enkf_tui_analysis_update_title(enkf_main, menu); + menu_add_item(menu, "Analyze one step manually", "aA", enkf_tui_analysis_analyze__, enkf_main, NULL); + menu_add_item(menu, "Analyze interval manually", "iI", enkf_tui_analysis_smooth__, enkf_main, NULL); + menu_add_item(menu, "Analyze selected steps manually", "nN", enkf_tui_analysis_analyze_selected__, enkf_main, NULL); + menu_add_separator(menu); + { + menu_item_type * item = menu_add_item(menu, "Global scaling of uncertainty", "gG", enkf_tui_analysis_scale_observation_std__, enkf_main, NULL); + if (!enkf_main_have_obs(enkf_main)) { + menu_item_disable(item); + } + } + menu_add_separator(menu); + menu_add_item(menu, "Select analysis module", "sS", enkf_tui_analysis_select_module__, arg_pack, NULL); + menu_add_item(menu, "List available modules", "lL", enkf_tui_analysis_list_modules__, enkf_main, NULL); + menu_add_item(menu, "Modify analysis module parameters", "mM", enkf_tui_analysis_update_module__, enkf_main, NULL); + menu_add_item(menu, "Reload current module (external only)", "rR", enkf_tui_analysis_reload_module__, enkf_main, NULL); } menu_run(menu); menu_free(menu); - arg_pack_free( arg_pack ); + arg_pack_free(arg_pack); } diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.c b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.c index 8a1ec81d51..36ccaa82b5 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.c +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.c @@ -20,9 +20,9 @@ #include #include #include -#include +#include #include -#include +#include #include #include #include @@ -34,8 +34,8 @@ #include #include #include -#include -#include +#include +#include /** diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.h b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.h index 8060aa0ad0..f87730e8a7 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.h +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_main.h @@ -18,7 +18,7 @@ #ifndef __ENKF_INTER_MAIN_H__ #define __ENKF_INTER_MAIN_H__ -#include +#include void enkf_tui_main_menu(void * arg); diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_plot_rft.c b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_plot_rft.c index b5c036cdbf..87eada994b 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_plot_rft.c +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_plot_rft.c @@ -37,6 +37,8 @@ #include #include +#include +#include #include #include @@ -245,7 +247,12 @@ void enkf_tui_plot_RFT_simIn(enkf_main_type * enkf_main, path_fmt_type * runpath for (int nobs =0; nobs -1){ - int cell_index = ecl_rft_node_lookup_ijk( rft_refcase_node , - int_vector_iget(i_values,nobs) , - int_vector_iget(j_values,nobs) , - int_vector_iget(k_values,nobs) ); //lookup cell - - if(cell_index > -1){ - double pressure_value = ecl_rft_node_iget_pressure( rft_refcase_node , cell_index); // Pressure + const ecl_rft_cell_type * cell = ecl_rft_node_lookup_ijk( rft_refcase_node , + int_vector_iget(i_values,nobs) , + int_vector_iget(j_values,nobs) , + int_vector_iget(k_values,nobs) ); + + if (cell) { + double pressure_value = ecl_rft_cell_get_pressure( cell ); double_vector_append(RFT_refcase, pressure_value); bool_vector_append(refcase_has_data, true); - } - else{ + } else { double_vector_append(RFT_refcase, 0.0); bool_vector_append(refcase_has_data, false); } @@ -337,17 +343,19 @@ void enkf_tui_plot_RFT_simIn(enkf_main_type * enkf_main, path_fmt_type * runpath else{ for( int nobs = 0; nobs < lines; nobs++){ if( int_vector_iget(active,nobs) > -1){ - int cell_index = ecl_rft_node_lookup_ijk( rftnode , int_vector_iget(i_values,nobs), int_vector_iget(j_values,nobs),int_vector_iget(k_values,nobs) ); //lookup cell - double pressure_value = ecl_rft_node_iget_pressure( rftnode , cell_index); // Pressure - double_vector_iset(simulated_pressures,nobs , pressure_value); - if(cell_index > -1) + const ecl_rft_cell_type * cell = ecl_rft_node_lookup_ijk( rftnode , + int_vector_iget(i_values,nobs), + int_vector_iget(j_values,nobs), + int_vector_iget(k_values,nobs) ); //lookup cell + if (cell) { + double pressure_value = ecl_rft_cell_get_pressure( cell ); + double_vector_iset(simulated_pressures, nobs , pressure_value); bool_vector_iset(has_data, nobs, true); - else + } else { + double_vector_iset(simulated_pressures,nobs ,0.0); bool_vector_iset(has_data, nobs, false); - } - else { - double_vector_iset(simulated_pressures,nobs ,0.0); - bool_vector_iset(has_data, nobs, false); + } + } } } diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_plot_rft.h b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_plot_rft.h index b7b0a88aaf..8fe6895b4b 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_plot_rft.h +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_plot_rft.h @@ -23,7 +23,7 @@ extern "C" { #endif -#include +#include void enkf_tui_plot_RFT_sim_all_MD( void * arg); void enkf_tui_plot_RFT_sim_all_TVD( void * arg); diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.c b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.c index 2bfaa24736..d89e507240 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.c +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.c @@ -434,6 +434,19 @@ bool enkf_tui_util_sscanf_active_list( bool_vector_type * iactive , const char * } } +/** + The limit is not inclusive +*/ +double enkf_tui_util_scanf_double_with_lower_limit(const char * prompt , int prompt_len , double min_value) { + double value; + char * new_prompt = util_alloc_sprintf("%s (greater than %g)" , prompt , min_value ); + do { + value = util_scanf_double(new_prompt , prompt_len); + } while (value <= min_value); + free(new_prompt); + return value; +} + /*****************************************************************/ diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.h b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.h index 49245e18f0..5298e09d81 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.h +++ b/ThirdParty/Ert/devel/libenkf/applications/ert_tui/enkf_tui_util.h @@ -41,6 +41,6 @@ char * enkf_tui_util_scanf_report_step_as_char(int , cons void enkf_tui_util_msg(const char * , ...); int enkf_tui_util_scanf_int_with_default(const char * prompt , int prompt_len , bool * default_used); int enkf_tui_util_scanf_int_with_default_return_to_menu(const char * prompt , int prompt_len , bool * default_used); - +double enkf_tui_util_scanf_double_with_lower_limit(const char * prompt , int prompt_len , double min_value); bool enkf_tui_util_sscanf_active_list( bool_vector_type * iactive , const char * select_string , int ens_size ); #endif diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/block_obs.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/block_obs.h index 81698a58b9..3316d518a7 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/block_obs.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/block_obs.h @@ -70,6 +70,11 @@ int block_obs_get_size(const block_obs_type * ); void block_obs_iget(const block_obs_type * block_obs, int , double * , double * ); void block_obs_iget_ijk(const block_obs_type * block_obs , int block_nr , int * i , int * j , int * k); +void block_obs_scale_std(block_obs_type * block_obs, double scale_factor); +void block_obs_scale_std__(void * block_obs, double scale_factor); + + + VOID_FREE_HEADER(block_obs); VOID_GET_OBS_HEADER(block_obs); UTIL_IS_INSTANCE_HEADER(block_obs); diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/config_keys.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/config_keys.h index d8a40f9eb1..9386cc114e 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/config_keys.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/config_keys.h @@ -110,7 +110,6 @@ extern "C" { #define MAX_RUNNING_LOCAL_KEY "MAX_RUNNING_LOCAL" #define MAX_RUNNING_LSF_KEY "MAX_RUNNING_LSF" #define MAX_RUNNING_RSH_KEY "MAX_RUNNING_RSH" -#define MAX_RUNNING_TORQUE_KEY "MAX_RUNNING_TORQUE" #define MAX_SUBMIT_KEY "MAX_SUBMIT" #define NUM_REALIZATIONS_KEY "NUM_REALIZATIONS" #define OBS_CONFIG_KEY "OBS_CONFIG" @@ -141,6 +140,7 @@ extern "C" { #define RERUN_START_KEY "RERUN_START" #define RSH_COMMAND_KEY "RSH_COMMAND" #define RSH_HOST_KEY "RSH_HOST" +#define RUNPATH_FILE_KEY "RUNPATH_FILE" #define RUNPATH_KEY "RUNPATH" #define ITER_RUNPATH_KEY "ITER_RUNPATH" #define RERUN_PATH_KEY "RERUN_PATH" diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_config_node.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_config_node.h index 112f53d9d2..15568a322b 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_config_node.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_config_node.h @@ -139,6 +139,7 @@ extern "C" { const char * enkf_config_node_get_min_std_file( const enkf_config_node_type * config_node ); const char * enkf_config_node_get_enkf_outfile( const enkf_config_node_type * conifg_node ); const char * enkf_config_node_get_enkf_infile( const enkf_config_node_type * config_node ); + const char * enkf_config_node_get_init_file_fmt( const enkf_config_node_type * config_node ); char * enkf_config_node_alloc_initfile( const enkf_config_node_type * node , const char * path , int iens); void enkf_config_node_set_internalize(enkf_config_node_type * node, int report_step); diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_main.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_main.h index 5a92a734fa..81708ac754 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_main.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_main.h @@ -69,6 +69,7 @@ extern "C" { char * enkf_main_alloc_mount_point( const enkf_main_type * enkf_main , const char * case_path); const char * enkf_main_get_current_fs( const enkf_main_type * enkf_main ); void enkf_main_user_select_fs(enkf_main_type * enkf_main , const char * case_path ); + bool enkf_main_fs_exists(const enkf_main_type * enkf_main, const char * input_case); void enkf_main_set_eclbase( enkf_main_type * enkf_main , const char * eclbase_fmt); void enkf_main_set_data_file( enkf_main_type * enkf_main , const char * data_file ); void enkf_main_set_user_config_file( enkf_main_type * enkf_main , const char * user_config_file ); @@ -91,6 +92,7 @@ extern "C" { const char * enkf_main_get_data_file(const enkf_main_type * ); const char ** enkf_main_get_well_list_ref(const enkf_main_type * , int *); + bool enkf_main_get_endian_swap(const enkf_main_type * ); bool enkf_main_get_fmt_file(const enkf_main_type * ); bool enkf_main_has_key(const enkf_main_type * , const char *); diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_node.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_node.h index 6875728790..630bd43a5b 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_node.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_node.h @@ -108,6 +108,7 @@ extern "C" { bool enkf_node_user_get_vector( enkf_node_type * enkf_node , enkf_fs_type * fs , const char * key , int iens , state_enum state , double_vector_type * values); + bool enkf_node_user_get_no_id(enkf_node_type * enkf_node , enkf_fs_type * fs , const char * key , int report_step, int iens, state_enum state , double * value); bool enkf_node_user_get(enkf_node_type * , enkf_fs_type * , const char * , node_id_type , double * ); enkf_node_type * enkf_node_alloc(const enkf_config_node_type *); enkf_node_type * enkf_node_copyc(const enkf_node_type * ); diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_obs.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_obs.h index 02bbbb1ed9..dd5265664e 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_obs.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/enkf_obs.h @@ -45,6 +45,7 @@ extern "C" { void enkf_obs_free( enkf_obs_type * enkf_obs); obs_vector_type * enkf_obs_get_vector(const enkf_obs_type * , const char * ); + void enkf_obs_add_obs_vector(enkf_obs_type * enkf_obs, const char * key, const obs_vector_type * vector); void enkf_obs_load(enkf_obs_type * enkf_obs, const history_type * history , @@ -80,6 +81,7 @@ extern "C" { stringlist_type * enkf_obs_alloc_matching_keylist(const enkf_obs_type * enkf_obs , const char * input_string); time_t enkf_obs_iget_obs_time(enkf_obs_type * enkf_obs , int report_step); void enkf_obs_fprintf_config( const enkf_obs_type * enkf_obs , FILE * stream); + void enkf_obs_scale_std(enkf_obs_type * enkf_obs, double scale_factor); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/gen_obs.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/gen_obs.h index e10d5d0e60..7e6cfdb99d 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/gen_obs.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/gen_obs.h @@ -29,6 +29,10 @@ typedef struct gen_obs_struct gen_obs_type; gen_obs_type * gen_obs_alloc(gen_data_config_type * config , const char * obs_key , const char * , double , double , const char * , const char * , const char * ); void gen_obs_user_get_with_data_index(const gen_obs_type * gen_obs , const char * index_key , double * value , double * std , bool * valid); +void gen_obs_scale_std(gen_obs_type * gen_obs, double std_multiplier ); +void gen_obs_scale_std__(void * gen_obs, double std_multiplier ); + + VOID_CHI2_HEADER(gen_obs); UTIL_IS_INSTANCE_HEADER(gen_obs); VOID_FREE_HEADER(gen_obs); diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/model_config.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/model_config.h index ffa0e2cd47..2f57e3fde6 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/model_config.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/model_config.h @@ -74,6 +74,7 @@ extern "C" { const char * model_config_iget_casename( const model_config_type * model_config , int index); //void model_config_set_max_resample( model_config_type * model_config , int max_resample ); //int model_config_get_max_resample(const model_config_type * model_config ); + void model_config_set_max_internal_submit(model_config_type * config, int max_resample); int model_config_get_max_internal_submit( const model_config_type * config ); bool model_config_select_runpath( model_config_type * model_config , const char * path_key); void model_config_add_runpath( model_config_type * model_config , const char * path_key , const char * fmt ); @@ -82,7 +83,8 @@ extern "C" { void model_config_set_refcase( model_config_type * model_config , const ecl_sum_type * refcase ); void model_config_fprintf_config( const model_config_type * model_config , int ens_size ,FILE * stream ); model_config_type * model_config_alloc_empty(); - + bool model_config_select_history( model_config_type * model_config , history_source_type source_type, const sched_file_type * sched_file , const ecl_sum_type * refcase); + #ifdef __cplusplus } #endif diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/obs_vector.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/obs_vector.h index 934272b3e2..fc381374e0 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/obs_vector.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/obs_vector.h @@ -47,6 +47,7 @@ extern "C" { typedef void (obs_get_ftype) (const void * , obs_data_type * , int , const active_list_type * ); typedef void (obs_meas_ftype) (const void * , const void *, node_id_type , meas_data_type * , const active_list_type * ); typedef void (obs_user_get_ftype) (void * , const char * , double * , double * , bool *); + typedef void (obs_scale_std_ftype) (void * , double ); typedef double (obs_chi2_ftype) (const void * , const void *, node_id_type ); typedef enum { GEN_OBS = 1, @@ -60,7 +61,6 @@ extern "C" { void obs_vector_del_node(obs_vector_type * obs_vector , int index); void obs_vector_free(obs_vector_type * ); int obs_vector_get_num_active(const obs_vector_type * ); - time_t obs_vector_iget_obs_time( const obs_vector_type * vector , int index); bool obs_vector_iget_active(const obs_vector_type * , int ); void obs_vector_iget_observations(const obs_vector_type * , int , obs_data_type * , const active_list_type * active_list); void obs_vector_measure(const obs_vector_type * , enkf_fs_type * fs, state_enum state , int report_step , const enkf_state_type * , meas_data_type * , const active_list_type * active_list); @@ -70,13 +70,15 @@ extern "C" { void obs_vector_user_get(const obs_vector_type * obs_vector , const char * index_key , int report_step , double * value , double * std , bool * valid); int obs_vector_get_next_active_step(const obs_vector_type * , int ); void * obs_vector_iget_node(const obs_vector_type * , int ); - obs_vector_type * obs_vector_alloc_from_GENERAL_OBSERVATION(const conf_instance_type * , const history_type * , const ensemble_config_type * , const time_t_vector_type * obs_time); + obs_vector_type * obs_vector_alloc_from_GENERAL_OBSERVATION(const conf_instance_type * , const history_type * , const ensemble_config_type * ); void obs_vector_load_from_SUMMARY_OBSERVATION(obs_vector_type * obs_vector , const conf_instance_type * , const history_type * , ensemble_config_type * ); bool obs_vector_load_from_HISTORY_OBSERVATION(obs_vector_type * obs_vector , const conf_instance_type * , const history_type * , ensemble_config_type * , double std_cutoff ); - obs_vector_type * obs_vector_alloc_from_BLOCK_OBSERVATION(const conf_instance_type * , const ecl_grid_type * grid , const ecl_sum_type * refcase , const history_type * , ensemble_config_type * , const time_t_vector_type * obs_time); + obs_vector_type * obs_vector_alloc_from_BLOCK_OBSERVATION(const conf_instance_type * , const ecl_grid_type * grid , const ecl_sum_type * refcase , const history_type *, ensemble_config_type * ); void obs_vector_set_config_node(obs_vector_type * , const enkf_config_node_type * ); - obs_vector_type * obs_vector_alloc(obs_impl_type obs_type , const char * obs_key , enkf_config_node_type * config_node , const time_t_vector_type * obs_time , int num_reports); - + obs_vector_type * obs_vector_alloc(obs_impl_type obs_type , const char * obs_key , enkf_config_node_type * config_node, int num_reports); + void obs_vector_scale_std(obs_vector_type * obs_vector, double std_multiplier); + void obs_vector_install_node(obs_vector_type * obs_vector , int obs_index , void * node ); + double obs_vector_chi2(const obs_vector_type * , enkf_fs_type * , node_id_type node_id); void obs_vector_ensemble_chi2(const obs_vector_type * obs_vector , diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/qc_module.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/qc_module.h index cacf78b946..e4fec2d135 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/qc_module.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/qc_module.h @@ -39,7 +39,7 @@ extern "C" { void qc_module_init( qc_module_type * qc_module , const config_type * config); void qc_module_export_runpath_list( const qc_module_type * qc_module ); void qc_module_add_config_items( config_type * config ); - void qc_module_set_runpath_list_file( qc_module_type * qc_module , const char * filename); + void qc_module_set_runpath_list_file( qc_module_type * qc_module , const char * path, const char * filename); const char * qc_module_get_runpath_list_file( qc_module_type * qc_module); diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/site_config.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/site_config.h index f3b627f844..16714d1535 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/site_config.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/site_config.h @@ -58,8 +58,6 @@ typedef struct site_config_struct site_config_type; int site_config_get_max_running_rsh( const site_config_type * site_config); void site_config_set_max_running_local( site_config_type * site_config , int max_running_local); int site_config_get_max_running_local( const site_config_type * site_config ); - void site_config_set_max_running_torque( site_config_type * site_config , int max_running_torque); - int site_config_get_max_running_torque( const site_config_type * site_config ); void site_config_setenv( site_config_type * site_config , const char * variable, const char * value); hash_type * site_config_get_env_hash( const site_config_type * site_config ); void site_config_clear_env( site_config_type * site_config ); diff --git a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/summary_obs.h b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/summary_obs.h index 52ed9699bf..b446800aab 100644 --- a/ThirdParty/Ert/devel/libenkf/include/ert/enkf/summary_obs.h +++ b/ThirdParty/Ert/devel/libenkf/include/ert/enkf/summary_obs.h @@ -80,6 +80,8 @@ summary_obs_type * summary_obs_alloc_from_SUMMARY_OBSERVATION( void summary_obs_set(summary_obs_type * , double , double ); +void summary_obs_scale_std(summary_obs_type * summary_obs, double std_multiplier ); +void summary_obs_scale_std__(void * summary_obs, double std_multiplier ); VOID_FREE_HEADER(summary_obs); VOID_GET_OBS_HEADER(summary_obs); diff --git a/ThirdParty/Ert/devel/libenkf/src/CMakeLists.txt b/ThirdParty/Ert/devel/libenkf/src/CMakeLists.txt index 24dcedbcdf..ba08fa8437 100644 --- a/ThirdParty/Ert/devel/libenkf/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libenkf/src/CMakeLists.txt @@ -2,7 +2,6 @@ set( source_files ert_report.c time_map.c rng_config.c trans_func.c enkf_types.c set( header_files ert_report.h time_map.h rng_config.h enkf_analysis.h enkf_fs_type.h trans_func.h enkf_obs.h obs_data.h enkf_config_node.h block_obs.h field_config.h field.h enkf_macros.h ecl_static_kw.h enkf_state.h enkf_util.h enkf_main.h enkf_node.h enkf_fs.h gen_kw_config.h gen_kw.h enkf_types.h fs_driver.h meas_data.h summary_obs.h summary_config.h summary_config.h gen_data_config.h gen_data.h gen_common.h gen_obs.h enkf_sched.h fs_types.h enkf_serialize.h plain_driver.h ecl_config.h ensemble_config.h model_config.h site_config.h active_list.h obs_vector.h field_trans.h plain_driver.h local_ministep.h container.h local_updatestep.h local_config.h analysis_config.h misfit_ensemble.h misfit_ensemble_typedef.h misfit_ts.h misfit_member.h data_ranking.h ranking_table.h ranking_common.h misfit_ranking.h block_fs_driver.h field_common.h gen_kw_common.h gen_data_common.h plot_config.h ert_template.h member_config.h enkf_defaults.h container_config.h local_dataset.h local_obsset.h surface.h surface_config.h local_context.h enkf_plot_data.h enkf_plot_member.h qc_module.h ert_report_list.h enkf_plot_arg.h runpath_list.h ert_workflow_list.h analysis_iter_config.h ecl_refcase_list.h) - add_library( enkf ${LIBRARY_TYPE} ${source_files} ) set_target_properties( enkf PROPERTIES VERSION 1.0 SOVERSION 1.0 ) @@ -12,6 +11,10 @@ set_target_properties( enkf PROPERTIES VERSION 1.0 SOVERSION 1.0 ) target_link_libraries( enkf ecl sched analysis rms plot config job_queue ) +if (USE_RUNPATH) + add_runpath( enkf ) +endif() + #----------------------------------------------------------------- if (INSTALL_ERT) install(TARGETS enkf DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/ThirdParty/Ert/devel/libenkf/src/block_obs.c b/ThirdParty/Ert/devel/libenkf/src/block_obs.c index d8ec61f638..7515399bb6 100644 --- a/ThirdParty/Ert/devel/libenkf/src/block_obs.c +++ b/ThirdParty/Ert/devel/libenkf/src/block_obs.c @@ -356,6 +356,20 @@ int block_obs_get_size(const block_obs_type * block_obs) { return block_obs->size; } +void block_obs_scale_std(block_obs_type * block_obs, double scale_factor) { + for (int i = 0; i < block_obs->size; i++) { + if (block_obs->point_list[i] != NULL) { + point_obs_type * point_observation = block_obs->point_list[i]; + point_observation->std = point_observation->std * scale_factor; + } + } +} + +void block_obs_scale_std__(void * block_obs, double scale_factor) { + block_obs_type * observation = block_obs_safe_cast(block_obs); + block_obs_scale_std(observation, scale_factor); +} + /*****************************************************************/ diff --git a/ThirdParty/Ert/devel/libenkf/src/enkf_config_node.c b/ThirdParty/Ert/devel/libenkf/src/enkf_config_node.c index ce73d26b75..c274875712 100644 --- a/ThirdParty/Ert/devel/libenkf/src/enkf_config_node.c +++ b/ThirdParty/Ert/devel/libenkf/src/enkf_config_node.c @@ -576,6 +576,10 @@ const char * enkf_config_node_get_enkf_infile( const enkf_config_node_type * con return path_fmt_get_fmt( config_node->enkf_infile_fmt ); } +const char * enkf_config_node_get_init_file_fmt( const enkf_config_node_type * config_node) +{ + return path_fmt_get_fmt( config_node->init_file_fmt ); +} void enkf_config_node_set_min_std( enkf_config_node_type * config_node , enkf_node_type * min_std ) { if (config_node->min_std != NULL) diff --git a/ThirdParty/Ert/devel/libenkf/src/enkf_main.c b/ThirdParty/Ert/devel/libenkf/src/enkf_main.c index 8e0f04b9ec..8ddebb290a 100644 --- a/ThirdParty/Ert/devel/libenkf/src/enkf_main.c +++ b/ThirdParty/Ert/devel/libenkf/src/enkf_main.c @@ -2144,7 +2144,6 @@ enkf_main_type * enkf_main_alloc_empty( ) { enkf_main_init_subst_list( enkf_main ); enkf_main_set_verbose( enkf_main , true ); - printf("enkf_main->subst_list :%p \n",enkf_main->subst_list); return enkf_main; } @@ -2262,22 +2261,20 @@ void enkf_main_update_node( enkf_main_type * enkf_main , const char * key ) { } - - - -/** - When the case has changed it is essential to invalidate the meta - information in the enkf_nodes, otherwise the nodes might reuse old - data (from a previous case). -*/ - -static void enkf_main_invalidate_cache( enkf_main_type * enkf_main ) { - int ens_size = enkf_main_get_ensemble_size( enkf_main ); - int iens; - for (iens = 0; iens < ens_size; iens++) - enkf_state_invalidate_cache( enkf_main->ensemble[iens] ); -} - +// NOTE KF 20130628: This is commented out, because I don't think it is used, but we'll give it some time +// +///** +// When the case has changed it is essential to invalidate the meta +// information in the enkf_nodes, otherwise the nodes might reuse old +// data (from a previous case). +//*/ +// +//static void enkf_main_invalidate_cache( enkf_main_type * enkf_main ) { +// int ens_size = enkf_main_get_ensemble_size( enkf_main ); +// int iens; +// for (iens = 0; iens < ens_size; iens++) +// enkf_state_invalidate_cache( enkf_main->ensemble[iens] ); +//} void enkf_main_create_fs( enkf_main_type * enkf_main , const char * fs_path) { @@ -2387,7 +2384,8 @@ void enkf_main_set_fs( enkf_main_type * enkf_main , enkf_fs_type * fs , const ch enkf_main_link_current_fs__( enkf_main , case_path); enkf_main->current_fs_case = util_realloc_string_copy( enkf_main->current_fs_case , case_path); enkf_main_gen_data_special( enkf_main ); - enkf_main_add_subst_kw( enkf_main , "CASE" , enkf_main->current_fs_case , "Current case" , true ); + enkf_main_add_subst_kw( enkf_main , "ERT-CASE" , enkf_main->current_fs_case , "Current case" , true ); + enkf_main_add_subst_kw( enkf_main , "ERTCASE" , enkf_main->current_fs_case , "Current case" , true ); } } @@ -2469,7 +2467,15 @@ const char * enkf_main_get_current_fs( const enkf_main_type * enkf_main ) { return enkf_main->current_fs_case; } +bool enkf_main_fs_exists(const enkf_main_type * enkf_main, const char * input_case){ + bool exists = false; + char * new_mount_point = enkf_main_alloc_mount_point( enkf_main , input_case); + if(enkf_fs_exists( new_mount_point )) + exists = true; + free( new_mount_point ); + return exists; +} void enkf_main_user_select_fs(enkf_main_type * enkf_main , const char * input_case ) { @@ -2836,7 +2842,6 @@ enkf_main_type * enkf_main_bootstrap(const char * _site_config, const char * _mo enkf_main_rng_init( enkf_main ); /* Must be called before the ensmeble is created. */ enkf_main_init_subst_list( enkf_main ); ert_workflow_list_init( enkf_main->workflow_list , config , enkf_main->logh ); - enkf_main_init_qc( enkf_main , config ); enkf_main_init_data_kw( enkf_main , config ); analysis_config_load_internal_modules( enkf_main->analysis_config ); @@ -2852,6 +2857,8 @@ enkf_main_type * enkf_main_bootstrap(const char * _site_config, const char * _mo ecl_config_get_last_history_restart( enkf_main->ecl_config ), ecl_config_get_sched_file(enkf_main->ecl_config) , ecl_config_get_refcase( enkf_main->ecl_config )); + + enkf_main_init_qc( enkf_main , config ); enkf_main_update_num_cpu( enkf_main ); { const config_content_item_type * pred_item = config_get_content_item( config , SCHEDULE_PREDICTION_FILE_KEY ); diff --git a/ThirdParty/Ert/devel/libenkf/src/enkf_main_jobs.c b/ThirdParty/Ert/devel/libenkf/src/enkf_main_jobs.c index 513e6f165b..b993d5f99a 100644 --- a/ThirdParty/Ert/devel/libenkf/src/enkf_main_jobs.c +++ b/ThirdParty/Ert/devel/libenkf/src/enkf_main_jobs.c @@ -58,7 +58,7 @@ void * enkf_main_smoother_JOB( void * self , const stringlist_type * args ) { int ens_size = enkf_main_get_ensemble_size( enkf_main ); bool_vector_type * iactive = bool_vector_alloc( 0 , true ); bool rerun = true; - const char * target_case = "AUTO-SMOOTHER"; + const char * target_case = stringlist_iget( args , 0 ); bool_vector_iset( iactive , ens_size - 1 , true ); enkf_main_run_smoother( enkf_main , target_case , rerun); @@ -75,3 +75,15 @@ void * enkf_main_create_reports_JOB(void * self , const stringlist_type * args ) return NULL; } +void * enkf_main_scale_obs_std_JOB(void * self, const stringlist_type * args ) { + enkf_main_type * enkf_main = enkf_main_safe_cast( self ); + + double scale_factor; + util_sscanf_double(stringlist_iget(args, 0), &scale_factor); + + if (enkf_main_have_obs(enkf_main)) { + enkf_obs_type * observations = enkf_main_get_obs(enkf_main); + enkf_obs_scale_std(observations, scale_factor); + } + return NULL; +} diff --git a/ThirdParty/Ert/devel/libenkf/src/enkf_node.c b/ThirdParty/Ert/devel/libenkf/src/enkf_node.c index 15ec40cfbc..dc0e742490 100644 --- a/ThirdParty/Ert/devel/libenkf/src/enkf_node.c +++ b/ThirdParty/Ert/devel/libenkf/src/enkf_node.c @@ -341,22 +341,25 @@ void enkf_node_ecl_write(const enkf_node_type *enkf_node , const char *path , fo bool enkf_node_user_get(enkf_node_type * enkf_node , enkf_fs_type * fs , const char * key , node_id_type node_id , double * value) { + return enkf_node_user_get_no_id( enkf_node , fs , key , node_id.report_step , node_id.iens , node_id.state , value ); +} + +bool enkf_node_user_get_no_id(enkf_node_type * enkf_node , enkf_fs_type * fs , const char * key , int report_step, int iens, state_enum state , double * value) { + node_id_type node_id = {.report_step = report_step , .iens = iens, .state = state }; bool loadOK; FUNC_ASSERT( enkf_node->user_get ); { loadOK = enkf_node_try_load( enkf_node , fs , node_id); if (loadOK) - return enkf_node->user_get(enkf_node->data , key , node_id.report_step, node_id.state , value); + return enkf_node->user_get(enkf_node->data , key , report_step, state , value); else { *value = 0; return false; } - } } - bool enkf_node_user_get_vector( enkf_node_type * enkf_node , enkf_fs_type * fs , const char * key , int iens , state_enum state , double_vector_type * values) { if (enkf_node->vector_storage) { if (enkf_node_try_load_vector( enkf_node , fs , iens , state)) { diff --git a/ThirdParty/Ert/devel/libenkf/src/enkf_obs.c b/ThirdParty/Ert/devel/libenkf/src/enkf_obs.c index f95cc2340a..7c0d65907b 100644 --- a/ThirdParty/Ert/devel/libenkf/src/enkf_obs.c +++ b/ThirdParty/Ert/devel/libenkf/src/enkf_obs.c @@ -46,7 +46,7 @@ The observation system ---------------------- -The observation system in the EnKF code is a three leayer system. At +The observation system in the EnKF code is a three layer system. At the the top is the enkf_obs_type. The enkf_main object contains one enkf_obs instance which has internalized ALL the observation data. In enkf_obs the the data is internalized in a hash table, where the keys @@ -59,7 +59,7 @@ be NULL, if the observation is not active at this report step. In addition the obs_vector contains function pointers to manipulate the observation data at the lowest level. -At the lowest level we have spsesific observation instances, +At the lowest level we have specific observation instances, field_obs, summary_obs and gen_obs. These instances contain the actual data. @@ -484,7 +484,7 @@ void enkf_obs_load(enkf_obs_type * enkf_obs , conf_instance_type * enkf_conf = conf_instance_alloc_from_file(enkf_conf_class, "enkf_conf", config_file); if(conf_instance_validate(enkf_conf) == false) - util_abort("Can not proceed with this configuration.\n"); + util_abort("Can not proceed with this configuration.\n"); if (enkf_obs->config_file != NULL) /* Clear current instance, observe that this function */ hash_clear( enkf_obs->obs_hash ); /* will reload even if it is called repeatedly with the */ @@ -503,9 +503,13 @@ void enkf_obs_load(enkf_obs_type * enkf_obs , config_node = ensemble_config_add_summary( ensemble_config , obs_key , LOAD_FAIL_WARN ); if (config_node != NULL) { - obs_vector = obs_vector_alloc( SUMMARY_OBS , obs_key , ensemble_config_get_node( ensemble_config , obs_key ) , enkf_obs->obs_time , last_report); + obs_vector = obs_vector_alloc( SUMMARY_OBS , obs_key , ensemble_config_get_node( ensemble_config , obs_key ), last_report); if (obs_vector != NULL) { - if (obs_vector_load_from_HISTORY_OBSERVATION(obs_vector , hist_obs_conf , enkf_obs->history , ensemble_config , std_cutoff )) + if (obs_vector_load_from_HISTORY_OBSERVATION(obs_vector , + hist_obs_conf , + enkf_obs->history , + ensemble_config, + std_cutoff )) enkf_obs_add_obs_vector(enkf_obs, obs_key, obs_vector); else { fprintf(stderr,"** Could not load historical data for observation:%s - ignored\n",obs_key); @@ -536,7 +540,7 @@ void enkf_obs_load(enkf_obs_type * enkf_obs , config_node = ensemble_config_add_summary( ensemble_config , sum_key , LOAD_FAIL_WARN ); if (config_node != NULL) { - obs_vector = obs_vector_alloc( SUMMARY_OBS , obs_key , ensemble_config_get_node( ensemble_config , sum_key ) , enkf_obs->obs_time , last_report); + obs_vector = obs_vector_alloc( SUMMARY_OBS , obs_key , ensemble_config_get_node( ensemble_config , sum_key ), last_report); if (obs_vector != NULL) { obs_vector_load_from_SUMMARY_OBSERVATION(obs_vector , sum_obs_conf , enkf_obs->history , ensemble_config); enkf_obs_add_obs_vector(enkf_obs, obs_key, obs_vector); @@ -557,7 +561,7 @@ void enkf_obs_load(enkf_obs_type * enkf_obs , { const char * obs_key = stringlist_iget(block_obs_keys, block_obs_nr); const conf_instance_type * block_obs_conf = conf_instance_get_sub_instance_ref(enkf_conf, obs_key); - obs_vector_type * obs_vector = obs_vector_alloc_from_BLOCK_OBSERVATION(block_obs_conf , grid , refcase , enkf_obs->history , ensemble_config , enkf_obs->obs_time); + obs_vector_type * obs_vector = obs_vector_alloc_from_BLOCK_OBSERVATION(block_obs_conf , grid , refcase , enkf_obs->history ,ensemble_config); if (obs_vector != NULL) enkf_obs_add_obs_vector(enkf_obs, obs_key, obs_vector); } @@ -575,7 +579,7 @@ void enkf_obs_load(enkf_obs_type * enkf_obs , const char * obs_key = stringlist_iget(block_obs_keys, block_obs_nr); const conf_instance_type * gen_obs_conf = conf_instance_get_sub_instance_ref(enkf_conf, obs_key); - obs_vector_type * obs_vector = obs_vector_alloc_from_GENERAL_OBSERVATION(gen_obs_conf , enkf_obs->history , ensemble_config , enkf_obs->obs_time); + obs_vector_type * obs_vector = obs_vector_alloc_from_GENERAL_OBSERVATION(gen_obs_conf , enkf_obs->history , ensemble_config); if (obs_vector != NULL) enkf_obs_add_obs_vector(enkf_obs, obs_key, obs_vector); } @@ -1052,7 +1056,17 @@ const obs_vector_type * enkf_obs_user_get_vector(const enkf_obs_type * obs , con return vector; } - - /*****************************************************************/ +void enkf_obs_scale_std(enkf_obs_type * enkf_obs, double scale_factor) { + + hash_iter_type * observation_vector_iterator = enkf_obs_alloc_iter(enkf_obs); + + while (!hash_iter_is_complete(observation_vector_iterator)) { + obs_vector_type * current_obs_vector = hash_iter_get_next_value(observation_vector_iterator); + obs_vector_scale_std(current_obs_vector, scale_factor); + } + + hash_iter_free(observation_vector_iterator); +} + diff --git a/ThirdParty/Ert/devel/libenkf/src/enkf_state.c b/ThirdParty/Ert/devel/libenkf/src/enkf_state.c index c0d15b6c7c..3453705a68 100644 --- a/ThirdParty/Ert/devel/libenkf/src/enkf_state.c +++ b/ThirdParty/Ert/devel/libenkf/src/enkf_state.c @@ -752,7 +752,8 @@ static bool enkf_state_internalize_dynamic_results(enkf_state_type * enkf_state if (ecl_config_active( ecl_config )) { bool eclipse_load = enkf_state_internalize_dynamic_eclipse_results( enkf_state , fs , model_config , loadOK, interactive , msg_list); - fprintf(stderr , "** Warning: could not load ECLIPSE summary data from %s - this will probably fail later ...\n" , enkf_state->run_info->run_path); + if (!eclipse_load) + fprintf(stderr , "** Warning: could not load ECLIPSE summary data from %s - this will probably fail later ...\n" , enkf_state->run_info->run_path); return eclipse_load; } else return false; diff --git a/ThirdParty/Ert/devel/libenkf/src/field.c b/ThirdParty/Ert/devel/libenkf/src/field.c index 8e79942027..a70d77e2f7 100644 --- a/ThirdParty/Ert/devel/libenkf/src/field.c +++ b/ThirdParty/Ert/devel/libenkf/src/field.c @@ -1383,7 +1383,6 @@ void field_update_sum(field_type * sum , field_type * field , double lower_limit */ bool field_user_get(const field_type * field, const char * index_key, int report_step , state_enum state, double * value) { - printf("index_key : %s \n",index_key); const bool internal_value = false; bool valid; int i,j,k; diff --git a/ThirdParty/Ert/devel/libenkf/src/field_config.c b/ThirdParty/Ert/devel/libenkf/src/field_config.c index c409719aa9..70d49c7ea0 100644 --- a/ThirdParty/Ert/devel/libenkf/src/field_config.c +++ b/ThirdParty/Ert/devel/libenkf/src/field_config.c @@ -954,8 +954,6 @@ bool field_config_parse_user_key__( const char * index_key , int *i , int *j , i *k = int_vector_iget( indices , 2) - 1; } - int_vector_fprintf( indices , stdout , "INDEXLIST" , " %4d"); - int_vector_free( indices ); } if (length == 3) diff --git a/ThirdParty/Ert/devel/libenkf/src/gen_kw.c b/ThirdParty/Ert/devel/libenkf/src/gen_kw.c index 8759dc5ae7..2a58c09aea 100644 --- a/ThirdParty/Ert/devel/libenkf/src/gen_kw.c +++ b/ThirdParty/Ert/devel/libenkf/src/gen_kw.c @@ -260,7 +260,7 @@ bool gen_kw_fload(gen_kw_type * gen_kw , const char * filename) { if (!readOK) { int counter = 0; readOK = true; - fseek( stream , 0 , SEEK_SET ); + util_fseek( stream , 0 , SEEK_SET ); while ((counter < size) && readOK) { char key[128]; diff --git a/ThirdParty/Ert/devel/libenkf/src/gen_obs.c b/ThirdParty/Ert/devel/libenkf/src/gen_obs.c index ec080e4c0f..0e05394fe5 100644 --- a/ThirdParty/Ert/devel/libenkf/src/gen_obs.c +++ b/ThirdParty/Ert/devel/libenkf/src/gen_obs.c @@ -330,11 +330,6 @@ void gen_obs_get_observations(gen_obs_type * gen_obs , obs_data_type * obs_data, - - - - - /** In general the gen_obs observation vector can be smaller than the gen_data field it is observing, i.e. we can have a situation like @@ -368,11 +363,11 @@ void gen_obs_get_observations(gen_obs_type * gen_obs , obs_data_type * obs_data, The function gen_obs_user_get_with_data_index() will do the translation from data based indexing to observation based indexing, i.e. - gen_obs_user_get_with_data_index("obs_key:4") + gen_obs_user_get_with_data_index("4") will do an inverse lookup of the '4' and further call - gen_obs_user_get("obs_key:2") + gen_obs_user_get("2") */ @@ -416,6 +411,18 @@ void gen_obs_user_get_with_data_index(const gen_obs_type * gen_obs , const char } } +void gen_obs_scale_std(gen_obs_type * gen_obs, double std_multiplier) { + for (int i = 0; i < gen_obs->obs_size; i++) { + gen_obs->obs_std[i] *= std_multiplier; + } +} + +void gen_obs_scale_std__(void * gen_obs, double std_multiplier) { + gen_obs_type * observation = gen_obs_safe_cast(gen_obs); + gen_obs_scale_std(observation, std_multiplier); +} + + diff --git a/ThirdParty/Ert/devel/libenkf/src/local_config.c b/ThirdParty/Ert/devel/libenkf/src/local_config.c index 9bd4a995b9..64b143ca55 100644 --- a/ThirdParty/Ert/devel/libenkf/src/local_config.c +++ b/ThirdParty/Ert/devel/libenkf/src/local_config.c @@ -60,12 +60,13 @@ ministep to the updatestep, otherwise it will not be able to do anything. -CREATE_MINISTEP [NAME_OF_MINISTEP] ----------------------------------- +CREATE_MINISTEP [NAME_OF_MINISTEP OBSSET_NAME] +----------------------------------------------- This function will create a new ministep with the name -'NAME_OF_MINISTEP'. The ministep is then ready for adding data and -observation keys. Before the ministep will be used you must attach it -to an updatestep with the ATTACH_MINISTEP command +'NAME_OF_MINISTEP'. The ministep will be based on the observation +set given by OBSSET_NAME (which must be created first).The ministep +is then ready for adding data. Before the ministep can be used you +must attach it to an updatestep with the ATTACH_MINISTEP command CREATE_DATASET [NAME_OF_DATASET] -------------------------------- diff --git a/ThirdParty/Ert/devel/libenkf/src/model_config.c b/ThirdParty/Ert/devel/libenkf/src/model_config.c index 95867b8d4a..a8f1faa12f 100644 --- a/ThirdParty/Ert/devel/libenkf/src/model_config.c +++ b/ThirdParty/Ert/devel/libenkf/src/model_config.c @@ -286,7 +286,7 @@ int model_config_get_max_internal_submit( const model_config_type * config ) { return config->max_internal_submit; } -static void model_config_set_max_internal_submit( model_config_type * model_config , int max_resample ) { +void model_config_set_max_internal_submit( model_config_type * model_config , int max_resample ) { model_config->max_internal_submit = max_resample; } @@ -330,7 +330,7 @@ model_config_type * model_config_alloc_empty() { } -static bool model_config_select_history( model_config_type * model_config , history_source_type source_type, const sched_file_type * sched_file , const ecl_sum_type * refcase) { +bool model_config_select_history( model_config_type * model_config , history_source_type source_type, const sched_file_type * sched_file , const ecl_sum_type * refcase) { bool selectOK = false; if (source_type == SCHEDULE && sched_file != NULL) { @@ -512,7 +512,6 @@ history_type * model_config_get_history(const model_config_type * config) { } int model_config_get_last_history_restart(const model_config_type * config) { - printf("config->history:%p \n",config->history); return history_get_last_restart( config->history ); } diff --git a/ThirdParty/Ert/devel/libenkf/src/obs_vector.c b/ThirdParty/Ert/devel/libenkf/src/obs_vector.c index 51e3790425..7d32b64f84 100644 --- a/ThirdParty/Ert/devel/libenkf/src/obs_vector.c +++ b/ThirdParty/Ert/devel/libenkf/src/obs_vector.c @@ -58,8 +58,8 @@ struct obs_vector_struct { obs_meas_ftype *measure; /* Function used to measure on the state, and add to to the S matrix. */ obs_user_get_ftype *user_get; /* Function to get an observation based on KEY:INDEX input from user.*/ obs_chi2_ftype *chi2; /* Function to evaluate chi-squared for an observation. */ + obs_scale_std_ftype *scale_std; /* Function to scale the standard deviation with a given factor */ - const time_t_vector_type * obs_time; /* Global vector owned by the enkf_obs structure. */ vector_type * nodes; char * obs_key; /* The key this observation vector has in the enkf_obs layer. */ enkf_config_node_type * config_node; /* The config_node of the node type we are observing - shared reference */ @@ -108,8 +108,7 @@ static void obs_vector_resize(obs_vector_type * vector , int new_size) { } - -obs_vector_type * obs_vector_alloc(obs_impl_type obs_type , const char * obs_key , enkf_config_node_type * config_node , const time_t_vector_type * obs_time , int num_reports) { +obs_vector_type * obs_vector_alloc(obs_impl_type obs_type , const char * obs_key , enkf_config_node_type * config_node, int num_reports) { obs_vector_type * vector = util_malloc(sizeof * vector ); UTIL_TYPE_ID_INIT( vector , OBS_VECTOR_TYPE_ID); @@ -118,7 +117,8 @@ obs_vector_type * obs_vector_alloc(obs_impl_type obs_type , const char * obs_key vector->get_obs = NULL; vector->user_get = NULL; vector->chi2 = NULL; - + vector->scale_std = NULL; + switch (obs_type) { case(SUMMARY_OBS): vector->freef = summary_obs_free__; @@ -126,6 +126,7 @@ obs_vector_type * obs_vector_alloc(obs_impl_type obs_type , const char * obs_key vector->get_obs = summary_obs_get_observations__; vector->user_get = summary_obs_user_get__; vector->chi2 = summary_obs_chi2__; + vector->scale_std = summary_obs_scale_std__; break; case(BLOCK_OBS): vector->freef = block_obs_free__; @@ -133,6 +134,7 @@ obs_vector_type * obs_vector_alloc(obs_impl_type obs_type , const char * obs_key vector->get_obs = block_obs_get_observations__; vector->user_get = block_obs_user_get__; vector->chi2 = block_obs_chi2__; + vector->scale_std = block_obs_scale_std__; break; case(GEN_OBS): vector->freef = gen_obs_free__; @@ -140,6 +142,7 @@ obs_vector_type * obs_vector_alloc(obs_impl_type obs_type , const char * obs_key vector->get_obs = gen_obs_get_observations__; vector->user_get = gen_obs_user_get__; vector->chi2 = gen_obs_chi2__; + vector->scale_std = gen_obs_scale_std__; break; default: util_abort("%s: internal error - obs_type:%d not recognized \n",__func__ , obs_type); @@ -150,8 +153,7 @@ obs_vector_type * obs_vector_alloc(obs_impl_type obs_type , const char * obs_key vector->obs_key = util_alloc_string_copy( obs_key ); vector->num_active = 0; vector->nodes = vector_alloc_new(); - vector->obs_time = obs_time; - obs_vector_resize(vector , num_reports + 1); /* +1 here ?? Ohh - these fucking +/- problems. */ + obs_vector_resize(vector , num_reports + 1); /* +1 here ?? Ohh - these +/- problems. */ return vector; } @@ -198,7 +200,7 @@ static void obs_vector_assert_node_type( const obs_vector_type * obs_vector , co type_OK = gen_obs_is_instance( node ); break; default: - util_abort("%s: What the fuck? \n",__func__); + util_abort("%s: Error in type check: \n",__func__); type_OK = false; } if (!type_OK) @@ -229,7 +231,7 @@ void obs_vector_clear_nodes( obs_vector_type * obs_vector ) { -static void obs_vector_install_node(obs_vector_type * obs_vector , int index , void * node) { +void obs_vector_install_node(obs_vector_type * obs_vector , int index , void * node) { obs_vector_assert_node_type( obs_vector , node ); { if (vector_iget_const( obs_vector->nodes , index ) == NULL) @@ -239,8 +241,6 @@ static void obs_vector_install_node(obs_vector_type * obs_vector , int index , v } } - - /** Observe that @summary_key is the key used to look up the corresponding simulated value in the ensemble, and not the @@ -253,14 +253,6 @@ static void obs_vector_add_summary_obs( obs_vector_type * obs_vector , int obs_i } -time_t obs_vector_iget_obs_time( const obs_vector_type * obs_vector , int report_step) { - return time_t_vector_safe_iget( obs_vector->obs_time , report_step ); -} - - - - - /*****************************************************************/ int obs_vector_get_num_active(const obs_vector_type * vector) { @@ -271,7 +263,7 @@ int obs_vector_get_num_active(const obs_vector_type * vector) { /** IFF - only one - report step is active this function will return that report step. If more than report step is active, the function - is ambigous, and will fail HARD. Check with get_num_active first! + is ambiguous, and will fail HARD. Check with get_num_active first! */ int obs_vector_get_active_report_step(const obs_vector_type * vector) { @@ -395,7 +387,7 @@ void obs_vector_load_from_SUMMARY_OBSERVATION(obs_vector_type * obs_vector , con -obs_vector_type * obs_vector_alloc_from_GENERAL_OBSERVATION(const conf_instance_type * conf_instance , const history_type * history, const ensemble_config_type * ensemble_config , const time_t_vector_type * obs_time) { +obs_vector_type * obs_vector_alloc_from_GENERAL_OBSERVATION(const conf_instance_type * conf_instance , const history_type * history, const ensemble_config_type * ensemble_config) { if(!conf_instance_is_of_class(conf_instance, "GENERAL_OBSERVATION")) util_abort("%s: internal error. expected \"GENERAL_OBSERVATION\" instance, got \"%s\".\n", __func__, conf_instance_get_class_name_ref(conf_instance) ); @@ -404,7 +396,7 @@ obs_vector_type * obs_vector_alloc_from_GENERAL_OBSERVATION(const conf_instance_ if (ensemble_config_has_key( ensemble_config , state_kw )) { const char * obs_key = conf_instance_get_name_ref(conf_instance); int size = history_get_last_restart( history ); - obs_vector_type * obs_vector = obs_vector_alloc( GEN_OBS , obs_key , ensemble_config_get_node(ensemble_config , state_kw ) , obs_time , size); + obs_vector_type * obs_vector = obs_vector_alloc( GEN_OBS , obs_key , ensemble_config_get_node(ensemble_config , state_kw ), size); int obs_restart_nr = __conf_instance_get_restart_nr(conf_instance , obs_key , history , size); const char * index_file = NULL; const char * index_list = NULL; @@ -587,6 +579,17 @@ bool obs_vector_load_from_HISTORY_OBSERVATION(obs_vector_type * obs_vector , } } +void obs_vector_scale_std(obs_vector_type * obs_vector, double std_multiplier) { + vector_type * observation_nodes = obs_vector->nodes; + + for (int i=0; iscale_std(observation, std_multiplier); + } + + } +} static const char * __summary_kw( const char * field_name ) { @@ -597,7 +600,7 @@ static const char * __summary_kw( const char * field_name ) { else if (strcmp( field_name , "SGAS") == 0) return "BSGAS"; else { - util_abort("%s: sorry - could not \'translate\' field:%s to block summayr variable\n",__func__ , field_name); + util_abort("%s: sorry - could not \'translate\' field:%s to block summary variable\n",__func__ , field_name); return NULL; } } @@ -607,8 +610,7 @@ obs_vector_type * obs_vector_alloc_from_BLOCK_OBSERVATION(const conf_instance_ty const ecl_grid_type * grid , const ecl_sum_type * refcase , const history_type * history, - ensemble_config_type * ensemble_config, - const time_t_vector_type * obs_time) { + ensemble_config_type * ensemble_config) { if(!conf_instance_is_of_class(conf_instance, "BLOCK_OBSERVATION")) util_abort("%s: internal error. expected \"BLOCK_OBSERVATION\" instance, got \"%s\".\n", @@ -692,7 +694,7 @@ obs_vector_type * obs_vector_alloc_from_BLOCK_OBSERVATION(const conf_instance_ty block_obs_type * block_obs = block_obs_alloc(obs_label, source_type , NULL , field_config , grid , num_obs_pts, obs_i, obs_j, obs_k, obs_value, obs_std); if (block_obs != NULL) { - obs_vector = obs_vector_alloc( BLOCK_OBS , obs_label , ensemble_config_get_node(ensemble_config , field_name) , obs_time , size ); + obs_vector = obs_vector_alloc( BLOCK_OBS , obs_label , ensemble_config_get_node(ensemble_config , field_name), size ); obs_vector_install_node( obs_vector , obs_restart_nr , block_obs); } } else if (source_type == SOURCE_SUMMARY) { @@ -723,7 +725,7 @@ obs_vector_type * obs_vector_alloc_from_BLOCK_OBSERVATION(const conf_instance_ty { block_obs_type * block_obs = block_obs_alloc(obs_label, source_type , summary_keys , container_config , grid , num_obs_pts, obs_i, obs_j, obs_k, obs_value, obs_std); if (block_obs != NULL) { - obs_vector = obs_vector_alloc( BLOCK_OBS , obs_label , container_config , obs_time , size ); + obs_vector = obs_vector_alloc( BLOCK_OBS , obs_label , container_config, size ); obs_vector_install_node( obs_vector , obs_restart_nr , block_obs); } } diff --git a/ThirdParty/Ert/devel/libenkf/src/qc_module.c b/ThirdParty/Ert/devel/libenkf/src/qc_module.c index 760ffa436e..556d4b5871 100644 --- a/ThirdParty/Ert/devel/libenkf/src/qc_module.c +++ b/ThirdParty/Ert/devel/libenkf/src/qc_module.c @@ -54,21 +54,15 @@ qc_module_type * qc_module_alloc( ert_workflow_list_type * workflow_list , const qc_module->runpath_list = runpath_list_alloc(); qc_module->runpath_list_file = NULL; qc_module_set_path( qc_module , qc_path ); - { - char * cwd = util_alloc_cwd(); - char * runpath_list_file = util_alloc_filename( cwd , RUNPATH_LIST_FILE , NULL); + qc_module_set_runpath_list_file( qc_module , NULL, RUNPATH_LIST_FILE ); - qc_module_set_runpath_list_file( qc_module , runpath_list_file ); - - free( runpath_list_file ); - free( cwd ); - } return qc_module; } void qc_module_free( qc_module_type * qc_module ) { util_safe_free( qc_module->qc_path ); + util_safe_free( qc_module->runpath_list_file); runpath_list_free( qc_module->runpath_list ); free( qc_module ); } @@ -83,9 +77,38 @@ void qc_module_export_runpath_list( const qc_module_type * qc_module ) { runpath_list_fprintf( qc_module->runpath_list , stream ); fclose( stream ); } + +static void qc_module_set_runpath_list_file__( qc_module_type * qc_module , const char * runpath_list_file) { + util_safe_free( qc_module->runpath_list_file ); + qc_module->runpath_list_file = util_alloc_string_copy( runpath_list_file ); +} -void qc_module_set_runpath_list_file( qc_module_type * qc_module , const char * filename) { - qc_module->runpath_list_file = util_realloc_string_copy( qc_module->runpath_list_file , filename ); + +void qc_module_set_runpath_list_file( qc_module_type * qc_module , const char * basepath, const char * filename) { + + if (filename && util_is_abs_path( filename )) + qc_module_set_runpath_list_file__( qc_module , filename ); + else { + const char * file = RUNPATH_LIST_FILE; + + if (filename != NULL) + file = filename; + + char * file_with_path_prefix = NULL; + if (basepath != NULL) { + file_with_path_prefix = util_alloc_filename(basepath, file, NULL); + } + else + file_with_path_prefix = util_alloc_string_copy(file); + + { + char * absolute_path = util_alloc_abs_path(file_with_path_prefix); + qc_module_set_runpath_list_file__( qc_module , absolute_path ); + free( absolute_path ); + } + + free(file_with_path_prefix); + } } const char * qc_module_get_runpath_list_file( qc_module_type * qc_module) { @@ -149,6 +172,9 @@ void qc_module_init( qc_module_type * qc_module , const config_type * config) { const char * qc_workflow = config_get_value_as_path(config , QC_WORKFLOW_KEY); qc_module_set_workflow( qc_module , qc_workflow ); } + + if (config_item_set( config, RUNPATH_FILE_KEY)) + qc_module_set_runpath_list_file(qc_module, NULL, config_get_value(config, RUNPATH_FILE_KEY)); } @@ -162,6 +188,9 @@ void qc_module_add_config_items( config_type * config ) { item = config_add_schema_item( config , QC_WORKFLOW_KEY , false ); config_schema_item_set_argc_minmax(item , 1 , 1 ); config_schema_item_iset_type( item , 0 , CONFIG_EXISTING_PATH ); + + item = config_add_schema_item( config , RUNPATH_FILE_KEY , false ); + config_schema_item_set_argc_minmax(item , 1 , 1 ); } diff --git a/ThirdParty/Ert/devel/libenkf/src/rng_config.c b/ThirdParty/Ert/devel/libenkf/src/rng_config.c index bea6a62229..d4be6ed809 100644 --- a/ThirdParty/Ert/devel/libenkf/src/rng_config.c +++ b/ThirdParty/Ert/devel/libenkf/src/rng_config.c @@ -98,10 +98,12 @@ rng_type * rng_config_alloc_rng( rng_config_type * rng_config ) { In the special case that seed_load == seed_store; we accept a seed_load argument pointing to a non-existant file. */ - if (test_string_equal( seed_load , seed_store)) - rng_init( rng , INIT_DEV_URANDOM ); - else - util_abort("%s: tried to load random seed from non-existing file:%s \n",__func__ , seed_load); + if (seed_store) { + if (util_string_equal( seed_store , seed_load)) + rng_init( rng , INIT_DEV_URANDOM ); + else + util_abort("%s: tried to load random seed from non-existing file:%s \n",__func__ , seed_load); + } } } else rng_init( rng , INIT_DEV_URANDOM ); diff --git a/ThirdParty/Ert/devel/libenkf/src/site_config.c b/ThirdParty/Ert/devel/libenkf/src/site_config.c index 206b19ca2d..b112d6d87a 100644 --- a/ThirdParty/Ert/devel/libenkf/src/site_config.c +++ b/ThirdParty/Ert/devel/libenkf/src/site_config.c @@ -113,10 +113,6 @@ struct site_config_struct { int max_running_local_site; - int max_running_torque_site; - - - job_driver_type driver_type; job_driver_type driver_type_site; int max_submit; @@ -421,45 +417,36 @@ static void site_config_select_TORQUE_job_queue(site_config_type * site_config) /*****************************************************************/ -/** - This is quite awkward because the max_running variable is located - both in the job_queue instance, and in each separate driver - individually: - - o If you call set_max_running - i.e. without specifiying a - particular driver, it will tell the queue system to use this - many jobs, and also look up the currently active driver and - update the internal info on that. - - o If you tell a specific driver a value for max_running, it will - update the internal field for that driver, AND the queue IFF the - queue is currently running this driver; otherwise the queue will - be left untouched. - - What a mess. - */ +/*****************************************************************/ +static int site_config_get_queue_max_running_option(queue_driver_type * driver) { + const char * max_running_string = queue_driver_get_option(driver, MAX_RUNNING); + int max_running = 0; + if(!util_sscanf_int(max_running_string, &max_running)) { + fprintf(stderr, "** Warning: String:%s for max_running is not parsable as int, using 0\n", max_running_string); + } + return max_running; +} -void site_config_set_max_running(site_config_type * site_config, int max_running) { - queue_driver_set_max_running(site_config->current_driver, max_running); /* We set the max running of the current driver */ +static void site_config_set_queue_max_running_option(site_config_type * site_config, const char* driver_name, int max_running) { + char* max_running_string = util_alloc_sprintf("%d", max_running); + site_config_set_queue_option(site_config, driver_name, MAX_RUNNING, max_running_string); + free(max_running_string); } void site_config_set_max_running_lsf(site_config_type * site_config, int max_running_lsf) { - queue_driver_type * lsf_driver = site_config_get_queue_driver(site_config, LSF_DRIVER_NAME); - queue_driver_set_max_running(lsf_driver, max_running_lsf); - + site_config_set_queue_max_running_option(site_config, LSF_DRIVER_NAME, max_running_lsf); if (!site_config->user_mode) site_config->max_running_lsf_site = max_running_lsf; } int site_config_get_max_running_lsf(const site_config_type * site_config) { queue_driver_type * lsf_driver = site_config_get_queue_driver(site_config, LSF_DRIVER_NAME); - return queue_driver_get_max_running(lsf_driver); + return site_config_get_queue_max_running_option(lsf_driver); } void site_config_set_max_running_rsh(site_config_type * site_config, int max_running_rsh) { - queue_driver_type * rsh_driver = site_config_get_queue_driver(site_config, RSH_DRIVER_NAME); - queue_driver_set_max_running(rsh_driver, max_running_rsh); + site_config_set_queue_max_running_option(site_config, RSH_DRIVER_NAME, max_running_rsh); if (!site_config->user_mode) site_config->max_running_rsh_site = max_running_rsh; @@ -467,12 +454,11 @@ void site_config_set_max_running_rsh(site_config_type * site_config, int max_run int site_config_get_max_running_rsh(const site_config_type * site_config) { queue_driver_type * rsh_driver = site_config_get_queue_driver(site_config, RSH_DRIVER_NAME); - return queue_driver_get_max_running(rsh_driver); + return site_config_get_queue_max_running_option(rsh_driver); } void site_config_set_max_running_local(site_config_type * site_config, int max_running_local) { - queue_driver_type * local_driver = site_config_get_queue_driver(site_config, LOCAL_DRIVER_NAME); - queue_driver_set_max_running(local_driver, max_running_local); + site_config_set_queue_max_running_option(site_config, LOCAL_DRIVER_NAME, max_running_local); if (!site_config->user_mode) site_config->max_running_local_site = max_running_local; @@ -480,20 +466,7 @@ void site_config_set_max_running_local(site_config_type * site_config, int max_r int site_config_get_max_running_local(const site_config_type * site_config) { queue_driver_type * local_driver = site_config_get_queue_driver(site_config, LOCAL_DRIVER_NAME); - return queue_driver_get_max_running(local_driver); -} - -void site_config_set_max_running_torque(site_config_type * site_config, int max_running_torque) { - queue_driver_type * torque_driver = site_config_get_queue_driver(site_config, TORQUE_DRIVER_NAME); - queue_driver_set_max_running(torque_driver, max_running_torque); - - if (!site_config->user_mode) - site_config->max_running_torque_site = max_running_torque; -} - -int site_config_get_max_running_torque(const site_config_type * site_config) { - queue_driver_type * torque_driver = site_config_get_queue_driver(site_config, TORQUE_DRIVER_NAME); - return queue_driver_get_max_running(torque_driver); + return site_config_get_queue_max_running_option(local_driver); } /*****************************************************************/ @@ -775,10 +748,6 @@ bool site_config_init(site_config_type * site_config, const config_type * config } } - /* Torque options */ - if (config_item_set(config, MAX_RUNNING_TORQUE_KEY)) - site_config_set_max_running_torque(site_config, config_get_value_as_int(config, MAX_RUNNING_TORQUE_KEY)); - if (config_item_set(config, QUEUE_SYSTEM_KEY)) { job_driver_type driver_type; @@ -982,25 +951,18 @@ void site_config_fprintf_config(const site_config_type * site_config, FILE * str } { - queue_driver_type * rsh_driver = site_config_get_queue_driver( site_config , RSH_DRIVER_NAME ); - hash_type * host_list = hash_safe_cast( (void *) queue_driver_get_option( rsh_driver , RSH_HOSTLIST ) ); - hash_iter_type * iter = hash_iter_alloc( host_list ); - while (!hash_iter_is_complete( iter )) { - const char * host_name = hash_iter_get_next_key( iter ); - fprintf(stream , CONFIG_KEY_FORMAT , RSH_HOST_KEY ); - fprintf(stream , "%s:%d\n" , host_name , hash_get_int( host_list , host_name)); + queue_driver_type * rsh_driver = site_config_get_queue_driver(site_config, RSH_DRIVER_NAME); + hash_type * host_list = hash_safe_cast((void *) queue_driver_get_option(rsh_driver, RSH_HOSTLIST)); + hash_iter_type * iter = hash_iter_alloc(host_list); + while (!hash_iter_is_complete(iter)) { + const char * host_name = hash_iter_get_next_key(iter); + fprintf(stream, CONFIG_KEY_FORMAT, RSH_HOST_KEY); + fprintf(stream, "%s:%d\n", host_name, hash_get_int(host_list, host_name)); } hash_iter_free(iter); } } - /* Storing TORQUE settings. */ - { - if (site_config_get_max_running_torque(site_config) != site_config->max_running_torque_site) { - fprintf(stream, CONFIG_KEY_FORMAT, MAX_RUNNING_TORQUE_KEY); - fprintf(stream, CONFIG_INT_FORMAT, site_config_get_max_running_torque(site_config)); - fprintf(stream, "\n"); - } - } + fprintf(stream, "\n\n"); } @@ -1025,11 +987,6 @@ void site_config_add_queue_config_items(config_type * config, bool site_mode) { "MAX_RUNNING_LOCAL" }, 1); - // TODO: Hva er dette for noe greier - // stringlist_type * torque_dep = stringlist_alloc_argv_ref((const char *[1]) { - // "MAX_RUNNING_TORQUE"}, 1); - // - if (site_mode) { config_schema_item_set_common_selection_set(item, 3, (const char *[3]) { @@ -1114,10 +1071,7 @@ void site_config_add_config_items(config_type * config, bool site_mode) { item = config_add_schema_item(config, MAX_RUNNING_LOCAL_KEY, false); config_schema_item_set_argc_minmax(item, 1, 1); config_schema_item_iset_type(item, 0, CONFIG_INT); - - item = config_add_schema_item(config, MAX_RUNNING_TORQUE_KEY, false); - config_schema_item_set_argc_minmax(item, 1, 1); - config_schema_item_iset_type(item, 0, CONFIG_INT); + /*****************************************************************/ item = config_add_schema_item(config, QUEUE_OPTION_KEY, false); diff --git a/ThirdParty/Ert/devel/libenkf/src/summary_obs.c b/ThirdParty/Ert/devel/libenkf/src/summary_obs.c index 3c002bedb4..7a5f2ba57f 100644 --- a/ThirdParty/Ert/devel/libenkf/src/summary_obs.c +++ b/ThirdParty/Ert/devel/libenkf/src/summary_obs.c @@ -119,6 +119,7 @@ UTIL_IS_INSTANCE_FUNCTION(summary_obs , SUMMARY_OBS_TYPE_ID); void summary_obs_free(summary_obs_type * summary_obs) { free(summary_obs->summary_key); + free(summary_obs->obs_key); free(summary_obs); } @@ -198,6 +199,15 @@ double summary_obs_get_std( const summary_obs_type * summary_obs ) { return summary_obs->std; } +void summary_obs_scale_std(summary_obs_type * summary_obs, double std_multiplier ) { + summary_obs->std = summary_obs->std * std_multiplier; +} + +void summary_obs_scale_std__(void * summary_obs, double std_multiplier ) { + summary_obs_type * observation = summary_obs_safe_cast(summary_obs); + summary_obs_scale_std(observation, std_multiplier); +} + /*****************************************************************/ diff --git a/ThirdParty/Ert/devel/libenkf/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libenkf/tests/CMakeLists.txt index 7f959cf417..a4ebfbc40e 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libenkf/tests/CMakeLists.txt @@ -1,67 +1,80 @@ add_executable( enkf_runpath_list enkf_runpath_list.c ) -target_link_libraries( enkf_runpath_list enkf ) +target_link_libraries( enkf_runpath_list enkf test_util ) add_executable( enkf_site_config enkf_site_config.c ) -target_link_libraries( enkf_site_config enkf ) +target_link_libraries( enkf_site_config enkf test_util ) add_executable( enkf_time_map enkf_time_map.c ) -target_link_libraries( enkf_time_map enkf ) +target_link_libraries( enkf_time_map enkf test_util ) add_executable( enkf_ensemble_GEN_PARAM enkf_ensemble_GEN_PARAM.c ) -target_link_libraries( enkf_ensemble_GEN_PARAM enkf ) +target_link_libraries( enkf_ensemble_GEN_PARAM enkf test_util ) add_executable( enkf_ensemble enkf_ensemble.c ) -target_link_libraries( enkf_ensemble enkf ) +target_link_libraries( enkf_ensemble enkf test_util ) add_executable( enkf_main enkf_main.c ) -target_link_libraries( enkf_main enkf ) +target_link_libraries( enkf_main enkf test_util ) add_test( enkf_main ${EXECUTABLE_OUTPUT_PATH}/enkf_main ) #----------------------------------------------------------------- add_executable( enkf_forward_init_GEN_KW enkf_forward_init_GEN_KW.c ) -target_link_libraries( enkf_forward_init_GEN_KW enkf ) -add_test( enkf_forward_init_GEN_KW_TRUE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_KW ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/config_GEN_KW_true TRUE) -add_test( enkf_forward_init_GEN_KW_FALSE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_KW ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/config_GEN_KW_false FALSE) +target_link_libraries( enkf_forward_init_GEN_KW enkf test_util ) + +add_test( enkf_forward_init_GEN_KW_TRUE + ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_KW + ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/ert config_GEN_KW_true TRUE) + +add_test( enkf_forward_init_GEN_KW_FALSE + ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_KW + ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/ert config_GEN_KW_false FALSE) + #----------------------------------------------------------------- add_executable( enkf_forward_init_GEN_PARAM enkf_forward_init_GEN_PARAM.c ) -target_link_libraries( enkf_forward_init_GEN_PARAM enkf ) -add_test( enkf_forward_init_GEN_PARAM_TRUE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_PARAM ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/config_GEN_PARAM_true TRUE) -add_test( enkf_forward_init_GEN_PARAM_FALSE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_PARAM ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/config_GEN_PARAM_false FALSE) +target_link_libraries( enkf_forward_init_GEN_PARAM enkf test_util ) + +add_test( enkf_forward_init_GEN_PARAM_TRUE + ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_PARAM + ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/ert config_GEN_PARAM_true TRUE) + +add_test( enkf_forward_init_GEN_PARAM_FALSE + ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_GEN_PARAM + ${CMAKE_CURRENT_SOURCE_DIR}/data/config/forward/ert config_GEN_PARAM_false FALSE) #----------------------------------------------------------------- add_executable( enkf_forward_init_SURFACE enkf_forward_init_SURFACE.c ) -target_link_libraries( enkf_forward_init_SURFACE enkf ) +target_link_libraries( enkf_forward_init_SURFACE enkf test_util ) add_test( enkf_forward_init_SURFACE_TRUE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_SURFACE - ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/surface/config_surface_true + ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/surface config_surface_true ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/surface/Surface.irap TRUE) add_test( enkf_forward_init_SURFACE_FALSE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_SURFACE - ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/surface/config_surface_false + ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/surface config_surface_false ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/surface/Surface.irap FALSE) #----------------------------------------------------------------- add_executable( enkf_forward_init_FIELD enkf_forward_init_FIELD.c ) -target_link_libraries( enkf_forward_init_FIELD enkf ) +target_link_libraries( enkf_forward_init_FIELD enkf test_util ) add_test( enkf_forward_init_FIELD_TRUE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_FIELD - ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/field/config_field_true + ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/field config_field_true ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/field/petro.grdecl TRUE) add_test( enkf_forward_init_FIELD_FALSE ${EXECUTABLE_OUTPUT_PATH}/enkf_forward_init_FIELD - ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/field/config_field_false + ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/field config_field_false ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/forward_init/field/petro.grdecl FALSE) @@ -69,39 +82,50 @@ add_test( enkf_forward_init_FIELD_FALSE add_executable( enkf_iter_config enkf_iter_config.c ) -target_link_libraries( enkf_iter_config enkf ) +target_link_libraries( enkf_iter_config enkf test_util ) add_test( enkf_iter_config ${EXECUTABLE_OUTPUT_PATH}/enkf_iter_config ) add_executable( enkf_model_config enkf_model_config.c ) -target_link_libraries( enkf_model_config enkf ) +target_link_libraries( enkf_model_config enkf test_util ) add_test( enkf_model_config ${EXECUTABLE_OUTPUT_PATH}/enkf_model_config ) add_executable( enkf_rng enkf_rng.c ) -target_link_libraries( enkf_rng enkf ) -add_test( enkf_rng ${EXECUTABLE_OUTPUT_PATH}/enkf_rng ${CMAKE_CURRENT_SOURCE_DIR}/data/config/rng) +target_link_libraries( enkf_rng enkf test_util ) +add_test( enkf_rng ${EXECUTABLE_OUTPUT_PATH}/enkf_rng ${CMAKE_CURRENT_SOURCE_DIR}/data/config rng) add_executable( enkf_report_list enkf_report_list.c ) -target_link_libraries( enkf_report_list enkf ) +target_link_libraries( enkf_report_list enkf test_util ) add_test( enkf_report_list ${EXECUTABLE_OUTPUT_PATH}/enkf_report_list ${CMAKE_CURRENT_SOURCE_DIR}/data/config/ert_report_list) add_executable( enkf_refcase_list enkf_refcase_list.c ) -target_link_libraries( enkf_refcase_list enkf ) +target_link_libraries( enkf_refcase_list enkf test_util ) add_test( enkf_refcase_list ${EXECUTABLE_OUTPUT_PATH}/enkf_refcase_list ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat*/ECLIPSE) add_test( enkf_refcase_list2 ${EXECUTABLE_OUTPUT_PATH}/enkf_refcase_list ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat*/ECLIPSE.*) -set_property( TEST enkf_refcase_list PROPERTY LABELS Statoil ) -set_property( TEST enkf_refcase_list2 PROPERTY LABELS Statoil ) - +set_property( TEST enkf_refcase_list PROPERTY LABELS StatoilData ) +set_property( TEST enkf_refcase_list2 PROPERTY LABELS StatoilData ) add_executable( enkf_ecl_config enkf_ecl_config.c ) -target_link_libraries( enkf_ecl_config enkf ) +target_link_libraries( enkf_ecl_config enkf test_util ) add_test( enkf_ecl_config1 ${EXECUTABLE_OUTPUT_PATH}/enkf_ecl_config ) add_test( enkf_ecl_config2 ${EXECUTABLE_OUTPUT_PATH}/enkf_ecl_config ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE) -set_property( TEST enkf_ecl_config2 PROPERTY LABELS Statoil ) +set_property( TEST enkf_ecl_config2 PROPERTY LABELS StatoilData ) add_executable( enkf_ecl_config_config enkf_ecl_config_config.c ) -target_link_libraries( enkf_ecl_config_config enkf ) +target_link_libraries( enkf_ecl_config_config enkf test_util ) add_test( enkf_ecl_config_config ${EXECUTABLE_OUTPUT_PATH}/enkf_ecl_config_config ${PROJECT_SOURCE_DIR}/test-data/Statoil/config/ecl_config ) -set_property( TEST enkf_ecl_config_config PROPERTY LABELS Statoil ) +set_property( TEST enkf_ecl_config_config PROPERTY LABELS StatoilData ) + +add_executable( enkf_qc_module_test enkf_qc_module_test.c ) +target_link_libraries( enkf_qc_module_test enkf test_util ) +add_test( enkf_qc_module_test ${EXECUTABLE_OUTPUT_PATH}/enkf_qc_module_test ) + +add_executable(enkf_obs_tests enkf_obs_tests.c) +target_link_libraries(enkf_obs_tests enkf test_util ) +add_test(enkf_obs_tests ${EXECUTABLE_OUTPUT_PATH}/enkf_obs_tests) + +add_executable(obs_vector_tests obs_vector_tests.c) +target_link_libraries(obs_vector_tests enkf test_util ) +add_test(obs_vector_tests ${EXECUTABLE_OUTPUT_PATH}/obs_vector_tests) add_test( enkf_runpath_list ${EXECUTABLE_OUTPUT_PATH}/enkf_runpath_list ) add_test( enkf_site_config ${EXECUTABLE_OUTPUT_PATH}/enkf_site_config /project/res/etc/ERT/site-config) @@ -111,10 +135,10 @@ add_test( enkf_ensemble_GEN_PARAM ${EXECUTABLE_OUTPUT_PATH}/enkf_ensemble_GEN_P add_test( enkf_ensemble ${EXECUTABLE_OUTPUT_PATH}/enkf_ensemble ) -set_property( TEST enkf_time_map2 PROPERTY LABELS Statoil ) -set_property( TEST enkf_site_config PROPERTY LABELS Statoil ) -set_property( TEST enkf_forward_init_SURFACE_FALSE PROPERTY LABELS Statoil ) -set_property( TEST enkf_forward_init_SURFACE_TRUE PROPERTY LABELS Statoil ) -set_property( TEST enkf_forward_init_FIELD_FALSE PROPERTY LABELS Statoil ) -set_property( TEST enkf_forward_init_FIELD_TRUE PROPERTY LABELS Statoil ) +set_property( TEST enkf_time_map2 PROPERTY LABELS StatoilData ) +set_property( TEST enkf_site_config PROPERTY LABELS StatoilData ) +set_property( TEST enkf_forward_init_SURFACE_FALSE PROPERTY LABELS StatoilData ) +set_property( TEST enkf_forward_init_SURFACE_TRUE PROPERTY LABELS StatoilData ) +set_property( TEST enkf_forward_init_FIELD_FALSE PROPERTY LABELS StatoilData ) +set_property( TEST enkf_forward_init_FIELD_TRUE PROPERTY LABELS StatoilData ) diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/FAULT_TEMPLATE b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/FAULT_TEMPLATE similarity index 100% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/FAULT_TEMPLATE rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/FAULT_TEMPLATE diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/MULTFLT.TXT b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/MULTFLT.TXT similarity index 100% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/MULTFLT.TXT rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/MULTFLT.TXT diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_KW_false b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_KW_false similarity index 75% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_KW_false rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_KW_false index 0a66f8edee..d66f17444a 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_KW_false +++ b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_KW_false @@ -1,8 +1,8 @@ JOBNAME Job%d -RUNPATH /tmp/simulations/run%d +RUNPATH simulations/run%d NUM_REALIZATIONS 1 -ENSPATH /tmp/Storage +ENSPATH Storage JOB_SCRIPT script.sh GEN_KW MULTFLT FAULT_TEMPLATE MULTFLT.INC MULTFLT.TXT INIT_FILES:MULTFLT_INIT diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_KW_true b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_KW_true similarity index 77% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_KW_true rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_KW_true index 4f883ec841..f8d48f73c5 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_KW_true +++ b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_KW_true @@ -1,8 +1,8 @@ JOBNAME Job%d -RUNPATH /tmp/simulations/run%d +RUNPATH simulations/run%d NUM_REALIZATIONS 1 -ENSPATH /tmp/Storage +ENSPATH Storage JOB_SCRIPT script.sh GEN_KW MULTFLT FAULT_TEMPLATE MULTFLT.INC MULTFLT.TXT INIT_FILES:MULTFLT_INIT FORWARD_INIT:TRUE diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_PARAM_false b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_PARAM_false similarity index 54% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_PARAM_false rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_PARAM_false index 4c00c3f259..4454bbab15 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_PARAM_false +++ b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_PARAM_false @@ -1,8 +1,8 @@ JOBNAME Job%d -RUNPATH /tmp/simulations/run%d +RUNPATH simulations/run%d NUM_REALIZATIONS 1 -ENSPATH /tmp/Storage +ENSPATH Storage JOB_SCRIPT script.sh diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_PARAM_true b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_PARAM_true similarity index 76% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_PARAM_true rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_PARAM_true index f354a72795..da1d098edb 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/config_GEN_PARAM_true +++ b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/config_GEN_PARAM_true @@ -1,8 +1,8 @@ JOBNAME Job%d -RUNPATH /tmp/simulations/run%d +RUNPATH simulations/run%d NUM_REALIZATIONS 1 -ENSPATH /tmp/Storage +ENSPATH Storage JOB_SCRIPT script.sh diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/script.sh b/ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/script.sh similarity index 100% rename from ThirdParty/Ert/devel/libenkf/tests/data/config/forward/script.sh rename to ThirdParty/Ert/devel/libenkf/tests/data/config/forward/ert/script.sh diff --git a/ThirdParty/Ert/devel/libenkf/tests/data/config/rng b/ThirdParty/Ert/devel/libenkf/tests/data/config/rng index 07caf77275..ad8ee50cb1 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/data/config/rng +++ b/ThirdParty/Ert/devel/libenkf/tests/data/config/rng @@ -1,6 +1,6 @@ NUM_REALIZATIONS 25 -STORE_SEED /tmp/seed2 -LOAD_SEED /tmp/seed2 +STORE_SEED seed2 +LOAD_SEED seed2 -- The settings below here are artifacts which should not be necessary ... JOB_SCRIPT script.sh diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_FIELD.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_FIELD.c index 779072920c..33fae2b179 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_FIELD.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_FIELD.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -44,17 +45,21 @@ void create_runpath(enkf_main_type * enkf_main ) { int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); + const char * root_path = argv[1]; + const char * config_file = argv[2]; + const char * init_file = argv[3]; + const char * forward_init_string = argv[4]; + test_work_area_type * work_area = test_work_area_alloc(config_file , false); + test_work_area_copy_directory_content( work_area , root_path ); + test_work_area_install_file( work_area , init_file ); { - const char * config_file = argv[1]; - const char * init_file = argv[2]; - const char * forward_init_string = argv[3]; bool forward_init; bool strict = true; enkf_main_type * enkf_main; test_assert_true( util_sscanf_bool( forward_init_string , &forward_init)); - util_clear_directory( "/tmp/Storage" , true , true ); + util_clear_directory( "Storage" , true , true ); enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true ); { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); @@ -88,7 +93,7 @@ int main(int argc , char ** argv) { .state = ANALYZED }; create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); + test_assert_true( util_is_directory( "simulations/run0" )); { bool loadOK = true; @@ -102,9 +107,9 @@ int main(int argc , char ** argv) { test_assert_false( enkf_node_has_data( field_node , fs, node_id )); - util_unlink_existing( "/tmp/simulations/run0/petro.grdecl" ); + util_unlink_existing( "simulations/run0/petro.grdecl" ); - test_assert_false( enkf_node_forward_init( field_node , "/tmp/simulations/run0" , 0 )); + test_assert_false( enkf_node_forward_init( field_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_false( loadOK ); @@ -115,7 +120,7 @@ int main(int argc , char ** argv) { } - util_copy_file( init_file , "/tmp/simulations/run0/petro.grdecl"); + util_copy_file( init_file , "simulations/run0/petro.grdecl"); { bool loadOK = true; stringlist_type * msg_list = stringlist_alloc_new(); @@ -125,7 +130,7 @@ int main(int argc , char ** argv) { enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ } - test_assert_true( enkf_node_forward_init( field_node , "/tmp/simulations/run0" , 0)); + test_assert_true( enkf_node_forward_init( field_node , "simulations/run0" , 0)); enkf_state_forward_init( state , fs , &loadOK ); test_assert_true( loadOK ); enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list ); @@ -138,17 +143,17 @@ int main(int argc , char ** argv) { test_assert_double_equal( 0.28485405445 , value); } } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); - test_assert_true( util_is_file( "/tmp/simulations/run0/PORO.grdecl" )); - test_assert_true( enkf_node_fload( field_node , "/tmp/simulations/run0/PORO.grdecl")); + test_assert_true( util_is_directory( "simulations/run0" )); + test_assert_true( util_is_file( "simulations/run0/PORO.grdecl" )); + test_assert_true( enkf_node_fload( field_node , "simulations/run0/PORO.grdecl")); { double value; test_assert_true( enkf_node_user_get( field_node , fs , "4,4,4" , node_id , &value)); test_assert_double_equal( 0.130251303315 , value); } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); } enkf_main_free( enkf_main ); } diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_KW.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_KW.c index d041901b41..4de0c97afc 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_KW.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_KW.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -44,16 +45,19 @@ void create_runpath(enkf_main_type * enkf_main ) { int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); - { - const char * config_file = argv[1]; - const char * forward_init_string = argv[2]; + const char * root_path = argv[1]; + const char * config_file = argv[2]; + const char * forward_init_string = argv[3]; + test_work_area_type * work_area = test_work_area_alloc(config_file , false); + test_work_area_copy_directory_content( work_area , root_path ); + { bool forward_init; bool strict = true; enkf_main_type * enkf_main; - + test_assert_true( util_sscanf_bool( forward_init_string , &forward_init)); - - util_clear_directory( "/tmp/Storage" , true , true ); + + util_clear_directory( "Storage" , true , true ); enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true ); { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); @@ -62,15 +66,15 @@ int main(int argc , char ** argv) { const enkf_config_node_type * gen_kw_config_node = enkf_node_get_config( gen_kw_node ); char * init_file1 = enkf_config_node_alloc_initfile( gen_kw_config_node , NULL , 0); char * init_file2 = enkf_config_node_alloc_initfile( gen_kw_config_node , "/tmp", 0); - + test_assert_bool_equal( enkf_config_node_use_forward_init( gen_kw_config_node ) , forward_init ); test_assert_string_equal( init_file1 , "MULTFLT_INIT"); test_assert_string_equal( init_file2 , "/tmp/MULTFLT_INIT"); - + free( init_file1 ); free( init_file2 ); } - + test_assert_bool_equal( enkf_node_use_forward_init( gen_kw_node ) , forward_init ); if (forward_init) test_assert_bool_not_equal( enkf_node_initialize( gen_kw_node , 0 , enkf_state_get_rng( state )) , forward_init); @@ -85,14 +89,14 @@ int main(int argc , char ** argv) { node_id_type node_id = {.report_step = 0 , .iens = 0, .state = ANALYZED }; - + create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); + test_assert_true( util_is_directory( "simulations/run0" )); { bool loadOK = true; stringlist_type * msg_list = stringlist_alloc_new(); - + { run_mode_type run_mode = ENSEMBLE_EXPERIMENT; enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ @@ -100,23 +104,22 @@ int main(int argc , char ** argv) { test_assert_false( enkf_node_has_data( gen_kw_node , fs, node_id )); + util_unlink_existing( "simulations/run0/MULTFLT_INIT" ); - util_unlink_existing( "/tmp/simulations/run0/MULTFLT_INIT" ); - - test_assert_false( enkf_node_forward_init( gen_kw_node , "/tmp/simulations/run0" , 0 )); + test_assert_false( enkf_node_forward_init( gen_kw_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_false( loadOK ); - + loadOK = true; enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list ); stringlist_free( msg_list ); test_assert_false( loadOK ); } - - + + { - FILE * stream = util_fopen("/tmp/simulations/run0/MULTFLT_INIT" , "w"); + FILE * stream = util_fopen("simulations/run0/MULTFLT_INIT" , "w"); fprintf(stream , "123456.0\n" ); fclose( stream ); } @@ -130,7 +133,7 @@ int main(int argc , char ** argv) { enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ } - test_assert_true( enkf_node_forward_init( gen_kw_node , "/tmp/simulations/run0" , 0 )); + test_assert_true( enkf_node_forward_init( gen_kw_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_true( loadOK ); enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list ); @@ -143,20 +146,20 @@ int main(int argc , char ** argv) { test_assert_double_equal( 123456.0 , value); } } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); - test_assert_true( util_is_file( "/tmp/simulations/run0/MULTFLT.INC" )); + test_assert_true( util_is_directory( "simulations/run0" )); + test_assert_true( util_is_file( "simulations/run0/MULTFLT.INC" )); { - FILE * stream = util_fopen("/tmp/simulations/run0/MULTFLT.INC" , "r"); + FILE * stream = util_fopen("simulations/run0/MULTFLT.INC" , "r"); double value; fscanf(stream , "%lg" , &value); fclose( stream ); test_assert_double_equal( 123456.0 , value); } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); } enkf_main_free( enkf_main ); } + test_work_area_free( work_area ); } - diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_PARAM.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_PARAM.c index 7b76059dc3..a6a0424759 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_PARAM.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_GEN_PARAM.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -44,16 +45,19 @@ void create_runpath(enkf_main_type * enkf_main ) { int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); + const char * root_path = argv[1]; + const char * config_file = argv[2]; + const char * forward_init_string = argv[3]; + test_work_area_type * work_area = test_work_area_alloc(config_file , false); + test_work_area_copy_directory_content( work_area , root_path ); { - const char * config_file = argv[1]; - const char * forward_init_string = argv[2]; bool forward_init; bool strict = true; enkf_main_type * enkf_main; - + test_assert_true( util_sscanf_bool( forward_init_string , &forward_init)); - util_clear_directory( "/tmp/Storage" , true , true ); + util_clear_directory( "Storage" , true , true ); enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true ); { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); @@ -87,7 +91,7 @@ int main(int argc , char ** argv) { .state = ANALYZED }; create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); + test_assert_true( util_is_directory( "simulations/run0" )); { run_mode_type run_mode = ENSEMBLE_EXPERIMENT; @@ -95,13 +99,13 @@ int main(int argc , char ** argv) { test_assert_false( enkf_node_has_data( gen_param_node , fs, node_id )); - util_unlink_existing( "/tmp/simulations/run0/PARAM_INIT" ); + util_unlink_existing( "simulations/run0/PARAM_INIT" ); } { - FILE * stream = util_fopen("/tmp/simulations/run0/PARAM_INIT" , "w"); + FILE * stream = util_fopen("simulations/run0/PARAM_INIT" , "w"); fprintf(stream , "0\n1\n2\n3\n" ); fclose( stream ); } @@ -115,7 +119,7 @@ int main(int argc , char ** argv) { enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ } - test_assert_true( enkf_node_forward_init( gen_param_node , "/tmp/simulations/run0" , 0 )); + test_assert_true( enkf_node_forward_init( gen_param_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_true( loadOK ); enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list ); @@ -134,12 +138,12 @@ int main(int argc , char ** argv) { test_assert_double_equal( 2 , value); } } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); - test_assert_true( util_is_file( "/tmp/simulations/run0/PARAM.INC" )); + test_assert_true( util_is_directory( "simulations/run0" )); + test_assert_true( util_is_file( "simulations/run0/PARAM.INC" )); { - FILE * stream = util_fopen("/tmp/simulations/run0/PARAM.INC" , "r"); + FILE * stream = util_fopen("simulations/run0/PARAM.INC" , "r"); double v0,v1,v2,v3; fscanf(stream , "%lg %lg %lg %lg" , &v0,&v1,&v2,&v3); fclose( stream ); @@ -148,9 +152,10 @@ int main(int argc , char ** argv) { test_assert_double_equal( 2 , v2); test_assert_double_equal( 3 , v3); } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); } enkf_main_free( enkf_main ); } + test_work_area_free( work_area ); } diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_SURFACE.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_SURFACE.c index e540d075e5..0122e6f0ad 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_SURFACE.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_forward_init_SURFACE.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -44,17 +45,23 @@ void create_runpath(enkf_main_type * enkf_main ) { int main(int argc , char ** argv) { enkf_main_install_SIGNALS(); + const char * root_path = argv[1]; + const char * config_file = argv[2]; + const char * init_file = argv[3]; + const char * forward_init_string = argv[4]; + test_work_area_type * work_area = test_work_area_alloc(config_file , false); + + test_work_area_copy_directory_content( work_area , root_path ); + test_work_area_install_file( work_area , init_file ); { - const char * config_file = argv[1]; - const char * init_file = argv[2]; - const char * forward_init_string = argv[3]; + bool forward_init; bool strict = true; enkf_main_type * enkf_main; test_assert_true( util_sscanf_bool( forward_init_string , &forward_init)); - util_clear_directory( "/tmp/Storage" , true , true ); + util_clear_directory( "Storage" , true , true ); enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true ); { enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 ); @@ -88,7 +95,7 @@ int main(int argc , char ** argv) { .state = ANALYZED }; create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); + test_assert_true( util_is_directory( "simulations/run0" )); { bool loadOK = true; @@ -102,9 +109,9 @@ int main(int argc , char ** argv) { test_assert_false( enkf_node_has_data( surface_node , fs, node_id )); - util_unlink_existing( "/tmp/simulations/run0/Surface.irap" ); + util_unlink_existing( "simulations/run0/Surface.irap" ); - test_assert_false( enkf_node_forward_init( surface_node , "/tmp/simulations/run0" , 0 )); + test_assert_false( enkf_node_forward_init( surface_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_false( loadOK ); @@ -115,7 +122,7 @@ int main(int argc , char ** argv) { } - util_copy_file( init_file , "/tmp/simulations/run0/Surface.irap"); + util_copy_file( init_file , "simulations/run0/Surface.irap"); { bool loadOK = true; stringlist_type * msg_list = stringlist_alloc_new(); @@ -125,7 +132,7 @@ int main(int argc , char ** argv) { enkf_main_init_run(enkf_main , run_mode); /* This is ugly */ } - test_assert_true( enkf_node_forward_init( surface_node , "/tmp/simulations/run0" , 0 )); + test_assert_true( enkf_node_forward_init( surface_node , "simulations/run0" , 0 )); enkf_state_forward_init( state , fs , &loadOK ); test_assert_true( loadOK ); enkf_state_load_from_forward_model( state , fs , &loadOK , false , msg_list ); @@ -141,11 +148,11 @@ int main(int argc , char ** argv) { test_assert_double_equal( 2737.0122 , value); } } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); create_runpath( enkf_main ); - test_assert_true( util_is_directory( "/tmp/simulations/run0" )); - test_assert_true( util_is_file( "/tmp/simulations/run0/SURFACE.INC" )); - test_assert_true( enkf_node_fload( surface_node , "/tmp/simulations/run0/SURFACE.INC")); + test_assert_true( util_is_directory( "simulations/run0" )); + test_assert_true( util_is_file( "simulations/run0/SURFACE.INC" )); + test_assert_true( enkf_node_fload( surface_node , "simulations/run0/SURFACE.INC")); { double value; test_assert_true( enkf_node_user_get( surface_node , fs , "0" , node_id , &value)); @@ -154,7 +161,7 @@ int main(int argc , char ** argv) { test_assert_true( enkf_node_user_get( surface_node , fs , "5" , node_id , &value)); test_assert_double_equal( 2737.0122 , value); } - util_clear_directory( "/tmp/simulations" , true , true ); + util_clear_directory( "simulations" , true , true ); } enkf_main_free( enkf_main ); } diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_obs_tests.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_obs_tests.c new file mode 100644 index 0000000000..45fdf8d5c3 --- /dev/null +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_obs_tests.c @@ -0,0 +1,50 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'enkf_enkf_obs_tests.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include +#include + +int main(int argc, char ** argv) { + enkf_obs_type * enkf_obs = enkf_obs_alloc(); + + obs_vector_type * obs_vector = obs_vector_alloc(SUMMARY_OBS, "WWCT", NULL, 2); + summary_obs_type * summary_obs1 = summary_obs_alloc( "SummaryKey" , "ObservationKey" , 43.2, 2.0 , AUTO_CORRF_EXP, 42); + obs_vector_install_node( obs_vector , 0 , summary_obs1 ); + + summary_obs_type * summary_obs2 = summary_obs_alloc( "SummaryKey2" , "ObservationKey2" , 4.2, 0.1 , AUTO_CORRF_EXP, 42); + obs_vector_install_node( obs_vector , 1 , summary_obs2 ); + + obs_vector_type * obs_vector2 = obs_vector_alloc(SUMMARY_OBS, "WWCT2", NULL, 2); + summary_obs_type * summary_obs3 = summary_obs_alloc( "SummaryKey" , "ObservationKey" , 43.2, 2.0 , AUTO_CORRF_EXP, 42); + obs_vector_install_node( obs_vector2 , 0 , summary_obs3 ); + + summary_obs_type * summary_obs4 = summary_obs_alloc( "SummaryKey2" , "ObservationKey2" , 4.2, 0.1 , AUTO_CORRF_EXP, 42); + obs_vector_install_node( obs_vector2 , 1 , summary_obs4 ); + + enkf_obs_add_obs_vector(enkf_obs, "PROP0", obs_vector); + enkf_obs_add_obs_vector(enkf_obs, "PROP", obs_vector2); + + enkf_obs_scale_std(enkf_obs, 3.3); + + enkf_obs_free(enkf_obs); + + exit(0); +} + diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_qc_module_test.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_qc_module_test.c new file mode 100644 index 0000000000..aed44b9498 --- /dev/null +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_qc_module_test.c @@ -0,0 +1,49 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'enkf_ecl_config.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include +#include + +int main(int argc, char ** argv) { + + ert_workflow_list_type * list = NULL; + qc_module_type * qc_module = qc_module_alloc(list, ""); + + char * expected_path = util_alloc_abs_path(".ert_runpath_list"); + test_assert_string_equal(expected_path, qc_module_get_runpath_list_file(qc_module)); + free(expected_path); + + qc_module_set_runpath_list_file(qc_module, "Folder", NULL); + expected_path = util_alloc_abs_path("Folder/.ert_runpath_list"); + test_assert_string_equal(expected_path, qc_module_get_runpath_list_file(qc_module)); + free(expected_path); + + qc_module_set_runpath_list_file(qc_module, "Folder", "thefilename.txt"); + expected_path = util_alloc_abs_path("Folder/thefilename.txt"); + test_assert_string_equal(expected_path, qc_module_get_runpath_list_file(qc_module)); + free(expected_path); + + qc_module_set_runpath_list_file(qc_module, "/tmp/ouagadogo", "thefilename.txt"); + test_assert_string_equal("/tmp/ouagadogo/thefilename.txt", qc_module_get_runpath_list_file(qc_module)); + + qc_module_free(qc_module); + + exit(0); +} + diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_rng.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_rng.c index b74d51a8a1..f5b5f9d02c 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_rng.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_rng.c @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -30,6 +31,7 @@ int main(int argc , char ** argv) { unsigned int rand1,rand2; { + test_work_area_type * work_area = test_work_area_alloc("enkf-rng-0", false); { enkf_main_type * enkf_main = enkf_main_alloc_empty(); enkf_main_resize_ensemble( enkf_main , 10 ); @@ -50,12 +52,14 @@ int main(int argc , char ** argv) { enkf_main_free( enkf_main ); } test_assert_uint_not_equal( rand1 , rand2 ); + test_work_area_free( work_area ); } /*****************************************************************/ { - const char * seed_file = "/tmp/seed"; + test_work_area_type * work_area = test_work_area_alloc("enkf-rng-1" , false ); + const char * seed_file = "seed"; { enkf_main_type * enkf_main = enkf_main_alloc_empty(); { @@ -88,19 +92,24 @@ int main(int argc , char ** argv) { enkf_main_free( enkf_main ); } test_assert_uint_equal( rand1 , rand2 ); - util_unlink_existing( seed_file ); + test_work_area_free( work_area ); + } /*****************************************************************/ { + const char * config_path = argv[1]; + const char * config_file = argv[2]; + test_work_area_type * work_area = test_work_area_alloc("enkf-rng-2" , false ); + test_work_area_copy_directory_content( work_area , config_path ); { - enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , argv[1] , true , true ); + enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , config_file , true , true ); enkf_state_type * state = enkf_main_iget_state( enkf_main , 9 ); rand1 = enkf_state_get_random( state ); enkf_main_free( enkf_main ); } { - enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , argv[1] , true , true ); + enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , config_file , true , true ); enkf_state_type * state = enkf_main_iget_state( enkf_main , 9 ); rand2 = enkf_state_get_random( state ); enkf_main_free( enkf_main ); @@ -108,12 +117,13 @@ int main(int argc , char ** argv) { test_assert_uint_equal( rand1 , rand2 ); { - enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , argv[1] , true , true ); + enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , config_file , true , true ); enkf_state_type * state = enkf_main_iget_state( enkf_main , 9 ); rand2 = enkf_state_get_random( state ); enkf_main_free( enkf_main ); } test_assert_uint_equal( rand1 , rand2 ); + test_work_area_free( work_area ); } exit(0); } diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_runpath_list.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_runpath_list.c index 4fe6d9676a..44e66c0145 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_runpath_list.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_runpath_list.c @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -98,7 +99,8 @@ int main(int argc , char ** argv) { } { - const char *filename = "/tmp/runpath_list.txt"; + test_work_area_type * work_area = test_work_area_alloc("enkf_runpath_list" , true); + const char *filename = "runpath_list.txt"; { FILE * stream = util_fopen( filename, "w"); runpath_list_fprintf( list , stream ); @@ -118,6 +120,7 @@ int main(int argc , char ** argv) { } fclose( stream ); } + test_work_area_free( work_area ); } } runpath_list_free( list ); diff --git a/ThirdParty/Ert/devel/libenkf/tests/enkf_time_map.c b/ThirdParty/Ert/devel/libenkf/tests/enkf_time_map.c index 21c6d50f9b..034a3ccce2 100644 --- a/ThirdParty/Ert/devel/libenkf/tests/enkf_time_map.c +++ b/ThirdParty/Ert/devel/libenkf/tests/enkf_time_map.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -55,8 +56,9 @@ void ecl_test( const char * ecl_case ) { void simple_test() { -time_map_type * time_map = time_map_alloc( ); - const char * mapfile = "/tmp/map"; + time_map_type * time_map = time_map_alloc( ); + test_work_area_type * work_area = test_work_area_alloc("enkf_time_map" , true); + const char * mapfile = "map"; test_assert_true( time_map_update( time_map , 0 , 100 ) ); test_assert_true( time_map_update( time_map , 1 , 200 ) ); @@ -83,6 +85,7 @@ time_map_type * time_map = time_map_alloc( ); time_map_fwrite( time_map , mapfile); test_assert_time_t_not_equal( mtime1 , util_file_mtime( mapfile ) ); } + test_work_area_free( work_area ); } diff --git a/ThirdParty/Ert/devel/libenkf/tests/obs_vector_tests.c b/ThirdParty/Ert/devel/libenkf/tests/obs_vector_tests.c new file mode 100644 index 0000000000..5bf7f83fc6 --- /dev/null +++ b/ThirdParty/Ert/devel/libenkf/tests/obs_vector_tests.c @@ -0,0 +1,222 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'enkf_obs_vector_tests.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include +#include + +#include "ert/enkf/gen_obs.h" + +bool alloc_strippedparameters_noerrors() { + obs_vector_type * obs_vector = obs_vector_alloc(SUMMARY_OBS, "WHAT", NULL, 0); + obs_vector_free(obs_vector); + return true; +} + +/*******Summary obs tests*******************/ +bool scale_std_summary_nodata_no_errors() { + obs_vector_type * obs_vector = obs_vector_alloc(SUMMARY_OBS, "WHAT", NULL, 0); + obs_vector_scale_std(obs_vector, 2.0); + obs_vector_free(obs_vector); + return true; +} + +bool scale_std_summarysingleobservation_no_errors() { + obs_vector_type * obs_vector = obs_vector_alloc(SUMMARY_OBS, "WHAT", NULL, 1); + + summary_obs_type * summary_obs = summary_obs_alloc("SummaryKey", "ObservationKey", 43.2, 2.0, AUTO_CORRF_EXP, 42); + obs_vector_install_node(obs_vector, 0, summary_obs); + + test_assert_double_equal(2.0, summary_obs_get_std(summary_obs)); + obs_vector_scale_std(obs_vector, 2.0); + test_assert_double_equal(4.0, summary_obs_get_std(summary_obs)); + + obs_vector_free(obs_vector); + return true; +} + +bool scale_std_summarymanyobservations_no_errors() { + int num_observations = 100; + double scaling_factor = 1.456; + + obs_vector_type * obs_vector = obs_vector_alloc(SUMMARY_OBS, "WHAT", NULL, num_observations); + + test_assert_bool_equal(0, obs_vector_get_num_active(obs_vector)); + + summary_obs_type * observations[num_observations]; + for (int i = 0; i < num_observations; i++) { + summary_obs_type * summary_obs = summary_obs_alloc("SummaryKey", "ObservationKey", 43.2, i, AUTO_CORRF_EXP, 42); + obs_vector_install_node(obs_vector, i, summary_obs); + observations[i] = summary_obs; + } + + for (int i = 0; i < num_observations; i++) { + summary_obs_type * before_scale = observations[i]; + test_assert_double_equal(i, summary_obs_get_std(before_scale)); + } + + test_assert_bool_equal(num_observations, obs_vector_get_num_active(obs_vector)); + + obs_vector_scale_std(obs_vector, scaling_factor); + + for (int i = 0; i < num_observations; i++) { + summary_obs_type * after_scale = observations[i]; + test_assert_double_equal(i * scaling_factor, summary_obs_get_std(after_scale)); + } + + obs_vector_free(obs_vector); + return true; +} + +/************ Block obs tests *****************************************************/ + +bool scale_std_block_nodata_no_errors() { + obs_vector_type * obs_vector = obs_vector_alloc(BLOCK_OBS, "WHAT", NULL, 0); + obs_vector_scale_std(obs_vector, 2.0); + obs_vector_free(obs_vector); + return true; +} + +block_obs_type * create_block_obs(ecl_grid_type * grid, int size, double value, double std_dev) { + int * i = util_calloc(size, sizeof * i); + int * j = util_calloc(size, sizeof * j); + int * k = util_calloc(size, sizeof * k); + double * obs_value = util_calloc(size, sizeof * obs_value); + double * obs_std = util_calloc(size, sizeof * obs_std); + + for (int num = 0; num < size; num++) { + obs_value[num] = value; + obs_std[num] = std_dev; + i[num] = num; + j[num] = num; + k[num] = num; + } + + block_obs_type * block_obs = block_obs_alloc("Label", SOURCE_FIELD, NULL, NULL, grid, size, i, j, k, obs_value, obs_std); + + free(i); + free(j); + free(k); + free(obs_value); + free(obs_std); + + return block_obs; +} + +bool scale_std_block100observations_no_errors() { + int num_observations = 100; + int num_points = 10; + + obs_vector_type * obs_vector = obs_vector_alloc(BLOCK_OBS, "WHAT", NULL, num_observations); + ecl_grid_type * grid = ecl_grid_alloc_rectangular(num_points, num_points, num_points, 1.0, 1.0, 1.0, NULL); + + double scale_factor = 3.3; + double obs_value = 44; + double obs_std = 3.2; + + block_obs_type * observations[num_observations]; + + for (int i = 0; i < num_observations; i++) { + block_obs_type * block_obs = create_block_obs(grid, num_points, obs_value, obs_std); + obs_vector_install_node(obs_vector, i, block_obs); + observations[i] = block_obs; + } + + for (int i = 0; i < num_observations; i++) { + for (int point_nr = 0; point_nr < num_points; point_nr++) { + double value, std; + block_obs_iget(observations[i], point_nr, &value, &std); + test_assert_double_equal(obs_value, value); + test_assert_double_equal(obs_std, std); + } + } + + obs_vector_scale_std(obs_vector, scale_factor); + + for (int i = 0; i < num_observations; i++) { + for (int point_nr = 0; point_nr < num_points; point_nr++) { + double value, std; + block_obs_iget(observations[i], point_nr, &value, &std); + test_assert_double_equal(obs_value, value); + test_assert_double_equal(obs_std * scale_factor, std); + } + } + + ecl_grid_free(grid); + obs_vector_free(obs_vector); + return true; +} + +/*************Gen obs tests************************************************/ + +bool scale_std_gen_nodata_no_errors() { + obs_vector_type * obs_vector = obs_vector_alloc(GEN_OBS, "WHAT", NULL, 0); + obs_vector_scale_std(obs_vector, 2.0); + obs_vector_free(obs_vector); + return true; +} + +bool scale_std_gen_withdata_no_errors() { + int num_observations = 100; + double value = 42; + double std_dev = 2.2; + double multiplier = 3.4; + + obs_vector_type * obs_vector = obs_vector_alloc(GEN_OBS, "WHAT", NULL, num_observations); + + gen_obs_type * observations[num_observations]; + for (int i = 0; i < num_observations; i++) { + gen_obs_type * gen_obs = gen_obs_alloc(NULL, "WWCT-GEN", NULL, value, std_dev, NULL, NULL, NULL); + obs_vector_install_node(obs_vector, i, gen_obs); + observations[i] = gen_obs; + } + + obs_vector_scale_std(obs_vector, multiplier); + + + + for (int i = 0; i < num_observations; i++) { + char * index_key = util_alloc_sprintf("%d", i); + double value_new, std_new; + bool valid; + gen_obs_user_get_with_data_index(observations[i], index_key, &value_new, &std_new, &valid); + test_assert_double_equal(std_dev * multiplier, std_new); + test_assert_double_equal(value, value_new); + free(index_key); + } + + obs_vector_free(obs_vector); + return true; +} + +int main(int argc, char ** argv) { + test_assert_bool_equal(alloc_strippedparameters_noerrors(), true); + test_assert_bool_equal(scale_std_summary_nodata_no_errors(), true); + test_assert_bool_equal(scale_std_summarysingleobservation_no_errors(), true); + test_assert_bool_equal(scale_std_summarymanyobservations_no_errors(), true); + + test_assert_bool_equal(scale_std_block_nodata_no_errors(), true); + test_assert_bool_equal(scale_std_block100observations_no_errors(), true); + + test_assert_bool_equal(scale_std_gen_nodata_no_errors(), true); + test_assert_bool_equal(scale_std_gen_withdata_no_errors(), true); + + exit(0); +} + diff --git a/ThirdParty/Ert/devel/libert_util/applications/CMakeLists.txt b/ThirdParty/Ert/devel/libert_util/applications/CMakeLists.txt index 33ae1ade68..b16c480385 100644 --- a/ThirdParty/Ert/devel/libert_util/applications/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libert_util/applications/CMakeLists.txt @@ -2,3 +2,6 @@ link_directories( ${ERT_BINARY_DIR}/libert_util/src ) add_executable( matrix_test matrix_test.c ) target_link_libraries( matrix_test ert_util ) +if (USE_RUNPATH) + add_runpath( matrix_test ) +endif() diff --git a/ThirdParty/Ert/devel/libert_util/include/ert/util/rng.h b/ThirdParty/Ert/devel/libert_util/include/ert/util/rng.h index bfe0f2db32..73ea7e6259 100644 --- a/ThirdParty/Ert/devel/libert_util/include/ert/util/rng.h +++ b/ThirdParty/Ert/devel/libert_util/include/ert/util/rng.h @@ -22,6 +22,7 @@ #ifdef __cplusplus extern "C" { #endif +#include #include diff --git a/ThirdParty/Ert/devel/libert_util/include/ert/util/test_util.h b/ThirdParty/Ert/devel/libert_util/include/ert/util/test_util.h index 27bc4a7a6e..92721b931d 100644 --- a/ThirdParty/Ert/devel/libert_util/include/ert/util/test_util.h +++ b/ThirdParty/Ert/devel/libert_util/include/ert/util/test_util.h @@ -30,13 +30,13 @@ extern "C" { void test_error_exit( const char * fmt , ...); - bool test_string_equal( const char * s1 , const char * s2 ); #define test_exit( fmt, ...) test_exit__( __FILE__ , __LINE__ , fmt , __VA_ARGS__); void test_exit__(const char * file , int line , const char * fmt , ...); #define test_assert_string_equal( s1 , s2 ) test_assert_string_equal__(s1 , s2 , __FILE__ , __LINE__) - void test_assert_string_equal__( const char * s1 , const char * s2 , const char * file , int line); + void test_assert_string_equal__( const char * s1 , const char * s2 , const char * file , int line); + bool test_check_string_equal( const char *s1 , const char * s2); #define test_assert_int_equal( i1 , i2 ) test_assert_int_equal__( (i1) , (i2) , __FILE__ , __LINE__ ) void test_assert_int_equal__( int i1 , int i2 , const char * file , int line ); @@ -53,6 +53,7 @@ extern "C" { #define test_assert_double_equal( d1 , d2 ) test_assert_double_equal__( (d1) , (d2) , __FILE__ , __LINE__ ) void test_assert_double_equal__( double d1 , double d2 , const char * file , int line ); + bool test_check_double_equal( double d1 , double d2); #define test_assert_double_not_equal( d1 , d2 ) test_assert_double_not_equal__( (d1) , (d2) , __FILE__ , __LINE__ ) void test_assert_double_not_equal__( double d1 , double d2 , const char * file , int line ); @@ -98,6 +99,8 @@ extern "C" { void test_util_addr2line(); #endif + void test_install_SIGNALS(void); + #ifdef __cplusplus } #endif diff --git a/ThirdParty/Ert/devel/libert_util/include/ert/util/test_work_area.h b/ThirdParty/Ert/devel/libert_util/include/ert/util/test_work_area.h new file mode 100644 index 0000000000..1cd04aa900 --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/include/ert/util/test_work_area.h @@ -0,0 +1,43 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'test_work_area.h' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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. +*/ + + +#ifndef __TEST_WORK_AREA_H__ +#define __TEST_WORK_AREA_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + + typedef struct test_work_area_struct test_work_area_type; + + test_work_area_type * test_work_area_alloc(const char * test_name , bool store); + void test_work_area_free(test_work_area_type * work_area); + const char * test_work_area_get_cwd( const test_work_area_type * work_area ); + const char * test_work_area_get_original_cwd( const test_work_area_type * work_area ); + void test_work_area_install_file( test_work_area_type * work_area , const char * input_src_file ); + void test_work_area_copy_directory( test_work_area_type * work_area , const char * input_directory); + void test_work_area_copy_directory_content( test_work_area_type * work_area , const char * input_directory); + void test_work_area_copy_file( test_work_area_type * work_area , const char * input_file); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/ThirdParty/Ert/devel/libert_util/include/ert/util/type_macros.h b/ThirdParty/Ert/devel/libert_util/include/ert/util/type_macros.h index c4e1156f01..aeefb0d4e9 100644 --- a/ThirdParty/Ert/devel/libert_util/include/ert/util/type_macros.h +++ b/ThirdParty/Ert/devel/libert_util/include/ert/util/type_macros.h @@ -95,6 +95,41 @@ const type ## _type * type ## _safe_cast_const( const void * __arg ) { } #define UTIL_SAFE_CAST_HEADER_CONST( type ) const type ## _type * type ## _safe_cast_const( const void * __arg ) + + + +#define UTIL_TRY_CAST_FUNCTION(type , TYPE_ID) \ +type ## _type * type ## _try_cast( void * __arg ) { \ + if (__arg == NULL) \ + return NULL; \ + { \ + type ## _type * arg = (type ## _type *) __arg; \ + if ( arg->__type_id == TYPE_ID) \ + return arg; \ + else \ + return NULL; \ + } \ +} +#define UTIL_TRY_CAST_HEADER( type ) type ## _type * type ## _try_cast( void * __arg ) + + +#define UTIL_TRY_CAST_FUNCTION_CONST(type , TYPE_ID) \ +const type ## _type * type ## _try_cast_const( const void * __arg ) { \ + if (__arg == NULL) \ + return NULL; \ + { \ + const type ## _type * arg = (type ## _type *) __arg; \ + if ( arg->__type_id == TYPE_ID) \ + return arg; \ + else \ + return NULL; \ + } \ +} +#define UTIL_TRY_CAST_HEADER_CONST( type ) const type ## _type * type ## _try_cast_const( const void * __arg ) + + + + #define UTIL_TYPE_ID_DECLARATION int __type_id #define UTIL_TYPE_ID_INIT(var , TYPE_ID) var->__type_id = TYPE_ID; diff --git a/ThirdParty/Ert/devel/libert_util/include/ert/util/util.h b/ThirdParty/Ert/devel/libert_util/include/ert/util/util.h index a8dea74729..b664a78ea5 100644 --- a/ThirdParty/Ert/devel/libert_util/include/ert/util/util.h +++ b/ThirdParty/Ert/devel/libert_util/include/ert/util/util.h @@ -24,10 +24,10 @@ #include #include #include +#include #ifdef HAVE_GETUID #include -#include #endif #ifdef ERT_WINDOWS @@ -47,6 +47,28 @@ extern"C" { #endif +/* + These ifdefs are an attempt to support large files (> 2GB) + transparently on both Windows and Linux. See source file + libert_util/src/util_lfs.c for more details. + + The symbol WINDOWS_LFS should be defined during compilation + if you want support of large files on windows. +*/ + +#ifdef WINDOWS_LFS +typedef struct _stat64 stat_type; +typedef __int64 offset_type; +#else +typedef struct stat stat_type; +#ifdef HAVE_FSEEKO + typedef off_t offset_type; +#else + typedef long offset_type; +#endif +#endif + + /*****************************************************************/ /* @@ -65,6 +87,7 @@ typedef bool (walk_dir_callback_ftype) (const char * , /* The current director void *); /* Arbitrary argument */ + typedef enum {left_pad = 0, right_pad = 1, center_pad = 2} string_alignement_type; @@ -141,6 +164,11 @@ typedef enum {left_pad = 0, int util_roundf( float x ); int util_round( double x ); + offset_type util_ftell(FILE * stream); + int util_fseek(FILE * stream, offset_type offset, int whence); + void util_rewind(FILE * stream); + int util_stat(const char * filename , stat_type * stat_info); + int util_fstat(int fileno, stat_type * stat_info); #ifdef HAVE_VA_COPY #define UTIL_VA_COPY(target,src) va_copy(target,src) @@ -150,7 +178,8 @@ typedef enum {left_pad = 0, #ifdef HAVE_OPENDIR - void util_copy_directory(const char * , const char * , const char *); + void util_copy_directory_content(const char * src_path , const char * target_path); + void util_copy_directory(const char * , const char *); void util_walk_directory(const char * root_path , walk_file_callback_ftype * file_callback , void * file_callback_arg , walk_dir_callback_ftype * dir_callback , void * dir_callback_arg); #endif @@ -176,6 +205,8 @@ typedef enum {left_pad = 0, FILE * util_fopen__(const char * filename , const char * mode); void util_fclose( FILE * stream ); bool util_fopen_test(const char *, const char *); + char * util_split_alloc_dirname( const char * input_path ); + char * util_split_alloc_filename( const char * input_path ); void util_alloc_file_components(const char * , char ** , char **, char **); //char * util_realloc_full_path(char * , const char *, const char *); char * util_alloc_tmp_file(const char * , const char * , bool ); @@ -329,6 +360,7 @@ typedef enum {left_pad = 0, bool util_files_equal( const char * file1 , const char * file2 ); double util_kahan_sum(const double *data, size_t N); bool util_double_approx_equal( double d1 , double d2); + bool util_double_approx_equal__( double d1 , double d2, double epsilon); int util_fnmatch( const char * pattern , const char * string ); void util_localtime( time_t * t , struct tm * ts ); diff --git a/ThirdParty/Ert/devel/libert_util/include/ert/util/vector.h b/ThirdParty/Ert/devel/libert_util/include/ert/util/vector.h index 2f8e44ef89..b6f0cee0d9 100644 --- a/ThirdParty/Ert/devel/libert_util/include/ert/util/vector.h +++ b/ThirdParty/Ert/devel/libert_util/include/ert/util/vector.h @@ -24,6 +24,7 @@ extern "C" { #endif #include #include +#include typedef void ( vector_func_type ) (void * , void *); typedef int ( vector_cmp_ftype) (const void * , const void *); @@ -75,6 +76,7 @@ extern "C" { void * vector_pop_back(vector_type * ); void * vector_pop_front(vector_type * ); void vector_sort(vector_type * vector , vector_cmp_ftype * cmp); + int_vector_type * vector_alloc_sort_perm(const vector_type * vector , vector_cmp_ftype * cmp); void vector_inplace_reverse(vector_type * vector); vector_type * vector_alloc_copy(const vector_type * src , bool deep_copy); diff --git a/ThirdParty/Ert/devel/libert_util/include/ert/util/vector_template.h b/ThirdParty/Ert/devel/libert_util/include/ert/util/vector_template.h index 5e94d3461a..2ae2b65317 100644 --- a/ThirdParty/Ert/devel/libert_util/include/ert/util/vector_template.h +++ b/ThirdParty/Ert/devel/libert_util/include/ert/util/vector_template.h @@ -51,6 +51,7 @@ typedef @TYPE@ (@TYPE@_ftype) (@TYPE@); @TYPE@_vector_type * @TYPE@_vector_alloc_copy( const @TYPE@_vector_type * src); void @TYPE@_vector_imul(@TYPE@_vector_type * vector, int index, @TYPE@ factor); void @TYPE@_vector_scale(@TYPE@_vector_type * vector, @TYPE@ factor); + void @TYPE@_vector_div(@TYPE@_vector_type * vector, @TYPE@ divisor); @TYPE@ @TYPE@_vector_reverse_iget(const @TYPE@_vector_type * vector , int index); @TYPE@ @TYPE@_vector_iget(const @TYPE@_vector_type * , int); @TYPE@ @TYPE@_vector_safe_iget(const @TYPE@_vector_type * , int); diff --git a/ThirdParty/Ert/devel/libert_util/src/CMakeLists.txt b/ThirdParty/Ert/devel/libert_util/src/CMakeLists.txt index a753d36d3b..ec8e8d4e20 100644 --- a/ThirdParty/Ert/devel/libert_util/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libert_util/src/CMakeLists.txt @@ -1,6 +1,11 @@ -set(source_files rng.c lookup_table.c statistics.c mzran.c set.c hash_node.c hash_sll.c hash.c node_data.c node_ctype.c util.c thread_pool.c msg.c arg_pack.c path_fmt.c menu.c subst_list.c subst_func.c vector.c parser.c stringlist.c matrix.c buffer.c log.c template.c timer.c test_util.c time_interval.c string_util.c) +set(source_files rng.c lookup_table.c statistics.c mzran.c set.c hash_node.c hash_sll.c hash.c node_data.c node_ctype.c util.c thread_pool.c msg.c arg_pack.c path_fmt.c menu.c subst_list.c subst_func.c vector.c parser.c stringlist.c matrix.c buffer.c log.c template.c timer.c time_interval.c string_util.c) -set(header_files ssize_t.h type_macros.h rng.h lookup_table.h statistics.h mzran.h set.h hash.h hash_node.h hash_sll.h node_data.h node_ctype.h util.h thread_pool.h msg.h arg_pack.h path_fmt.h stringlist.h menu.h subst_list.h subst_func.h vector.h parser.h matrix.h buffer.h log.h template.h timer.h test_util.h time_interval.h string_util.h) +set(header_files ssize_t.h type_macros.h rng.h lookup_table.h statistics.h mzran.h set.h hash.h hash_node.h hash_sll.h node_data.h node_ctype.h util.h thread_pool.h msg.h arg_pack.h path_fmt.h stringlist.h menu.h subst_list.h subst_func.h vector.h parser.h matrix.h buffer.h log.h template.h timer.h time_interval.h string_util.h) + +set( test_source test_util.c test_work_area.c ) + + +#set_property(SOURCE hash.c PROPERTY COMPILE_FLAGS "-Wno-error") if (WITH_LATEX) @@ -43,8 +48,17 @@ if (WITH_PTHREAD) list( APPEND header_files thread_pool_posix.h ) endif() -add_library( ert_util ${LIBRARY_TYPE} ${source_files} ) +add_library( ert_util ${LIBRARY_TYPE} ${source_files} ) +if (BUILD_TESTS) + add_library( test_util ${LIBRARY_TYPE} ${test_source} ) + target_link_libraries( test_util ert_util ) +endif() + set_target_properties( ert_util PROPERTIES VERSION 1.0 SOVERSION 1.0 ) +if (USE_RUNPATH) + add_runpath( ert_util ) +endif() + if (WITH_PTHREAD) target_link_libraries( ert_util ${PTHREAD_LIBRARY} ) diff --git a/ThirdParty/Ert/devel/libert_util/src/log.c b/ThirdParty/Ert/devel/libert_util/src/log.c index bea28caa3c..ccb3cabb32 100644 --- a/ThirdParty/Ert/devel/libert_util/src/log.c +++ b/ThirdParty/Ert/devel/libert_util/src/log.c @@ -196,7 +196,7 @@ void log_sync(log_type * logh) { #ifdef HAVE_FSYNC fsync( logh->fd ); #endif - fseek( logh->stream , 0 , SEEK_END ); + util_fseek( logh->stream , 0 , SEEK_END ); } diff --git a/ThirdParty/Ert/devel/libert_util/src/lookup_table.c b/ThirdParty/Ert/devel/libert_util/src/lookup_table.c index 0a4d4e2da2..5b2e9a5f65 100644 --- a/ThirdParty/Ert/devel/libert_util/src/lookup_table.c +++ b/ThirdParty/Ert/devel/libert_util/src/lookup_table.c @@ -162,7 +162,7 @@ double lookup_table_get_max_value( lookup_table_type * lookup_table ) { double lookup_table_get_min_value( lookup_table_type * lookup_table ) { lookup_table_assert_sorted( lookup_table ); - return lookup_table->ymax; + return lookup_table->ymin; } diff --git a/ThirdParty/Ert/devel/libert_util/src/parser.c b/ThirdParty/Ert/devel/libert_util/src/parser.c index 73c5de9a03..353abcaaed 100644 --- a/ThirdParty/Ert/devel/libert_util/src/parser.c +++ b/ThirdParty/Ert/devel/libert_util/src/parser.c @@ -560,7 +560,7 @@ static bool fseek_quote_end( char quoter , FILE * stream ) { static bool fgetc_while_equal( FILE * stream , const char * string , bool case_sensitive) { bool equal = true; - long int current_pos = ftell(stream); + long int current_pos = util_ftell(stream); int string_index; for ( string_index = 0; string_index < strlen(string); string_index++) { int c = fgetc( stream ); @@ -574,7 +574,7 @@ static bool fgetc_while_equal( FILE * stream , const char * string , bool case_s } if (!equal) /* OK - not equal - go back. */ - fseek( stream , current_pos , SEEK_SET); + util_fseek( stream , current_pos , SEEK_SET); return equal; } @@ -598,7 +598,7 @@ bool parser_fseek_string(const parser_type * parser , FILE * stream , const char if (!case_sensitive) util_strupr( string ); { - long int initial_pos = ftell( stream ); /* Store the inital position. */ + long int initial_pos = util_ftell( stream ); /* Store the inital position. */ bool cont = true; if (strstr( string , parser->comment_start ) != NULL) @@ -610,11 +610,11 @@ bool parser_fseek_string(const parser_type * parser , FILE * stream , const char /* Special treatment of quoters - does not properly handle escaping of the quoters. */ if (is_in_quoters( c , parser )) { - long int quote_start_pos = ftell(stream); + long int quote_start_pos = util_ftell(stream); if (!fseek_quote_end( c , stream )) { - fseek( stream , quote_start_pos , SEEK_SET); + util_fseek( stream , quote_start_pos , SEEK_SET); fprintf(stderr,"Warning: unterminated quotation starting at line: %d \n",util_get_current_linenr( stream )); - fseek(stream , 0 , SEEK_END); + util_fseek(stream , 0 , SEEK_END); } /* Now we are either at the first character following a @@ -628,7 +628,7 @@ bool parser_fseek_string(const parser_type * parser , FILE * stream , const char /* OK - this might be the start of a comment - let us check further. */ bool comment_start = fgetc_while_equal( stream , &parser->comment_start[1] , false); if (comment_start) { - long int comment_start_pos = ftell(stream) - strlen( parser->comment_start ); + long int comment_start_pos = util_ftell(stream) - strlen( parser->comment_start ); /* Start seeking for comment_end */ if (!util_fseek_string(stream , parser->comment_end , true , true)) { /* @@ -636,9 +636,9 @@ bool parser_fseek_string(const parser_type * parser , FILE * stream , const char The file is just positioned at the end - and the routine will exit at the next step - with a Warning. */ - fseek( stream , comment_start_pos , SEEK_SET); + util_fseek( stream , comment_start_pos , SEEK_SET); fprintf(stderr,"Warning: unterminated comment starting at line: %d \n",util_get_current_linenr( stream )); - fseek(stream , 0 , SEEK_END); + util_fseek(stream , 0 , SEEK_END); } continue; /* Now we are at the character following a comment end - or at EOF. */ } @@ -662,9 +662,9 @@ bool parser_fseek_string(const parser_type * parser , FILE * stream , const char if (string_found) { if (!skip_string) - fseek(stream , -strlen(string) , SEEK_CUR); /* Reposition to the beginning of 'string' */ + util_fseek(stream , -strlen(string) , SEEK_CUR); /* Reposition to the beginning of 'string' */ } else - fseek(stream , initial_pos , SEEK_SET); /* Could not find the string reposition at initial position. */ + util_fseek(stream , initial_pos , SEEK_SET); /* Could not find the string reposition at initial position. */ } free( string ); return string_found; diff --git a/ThirdParty/Ert/devel/libert_util/src/test_util.c b/ThirdParty/Ert/devel/libert_util/src/test_util.c index d2c95ea53e..e89fefdffd 100644 --- a/ThirdParty/Ert/devel/libert_util/src/test_util.c +++ b/ThirdParty/Ert/devel/libert_util/src/test_util.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -52,7 +53,7 @@ void test_exit__(const char * file , int line , const char * fmt , ...) { } -bool test_string_equal( const char * s1 , const char * s2 ) { +bool test_check_string_equal( const char * s1 , const char * s2 ) { bool equal = true; if (s1 == NULL && s2 == NULL) return true; @@ -71,7 +72,7 @@ bool test_string_equal( const char * s1 , const char * s2 ) { void test_assert_string_equal__( const char * s1 , const char * s2 , const char * file, int line) { - bool equal = test_string_equal( s1 , s2 ); + bool equal = test_check_string_equal( s1 , s2 ); if (!equal) test_error_exit( "%s:%d => String are different s1:[%s] s2:[%s]\n" , file , line , s1 , s2 ); } @@ -156,7 +157,7 @@ void test_assert_ptr_equal__( const void * p1 , const void * p2 , const char * f void test_assert_ptr_not_equal__( const void * p1 , const void * p2 , const char * file , int line) { bool equal = (p1 == p2); if (equal) - test_error_exit( "%s:%d => Pointers are different p1:[%p] p2:[%p]\n" , file , line , p1 , p2 ); + test_error_exit( "%s:%d => Pointers are equal p1:[%p] p2:[%p]\n" , file , line , p1 , p2 ); } @@ -192,18 +193,31 @@ void test_assert_mem_not_equal__( const void * p1 , const void * p2 , size_t byt } +bool test_check_double_equal( double d1 , double d2) { + const double tolerance = 1e-5; + return util_double_approx_equal__( d1 , d2 , tolerance ); +} + void test_assert_double_equal__( double d1 , double d2, const char * file , int line) { - if (!util_double_approx_equal(d1 , d2)) + if (!test_check_double_equal(d1 , d2)) test_error_exit( "%s:%d => double values:%g %g are not sufficiently similar\n" , file , line , d1 , d2); } void test_assert_double_not_equal__( double d1 , double d2, const char * file , int line) { - if (util_double_approx_equal(d1 , d2)) + if (test_check_double_equal(d1 , d2)) test_error_exit( "%s:%d => double values:%15.12g %15.12g are equal.\n" , file , line , d1 , d2); } +/*****************************************************************/ + +void test_install_SIGNALS(void) { + signal(SIGSEGV , util_abort_signal); /* Segmentation violation, i.e. overwriting memory ... */ + signal(SIGINT , util_abort_signal); /* Control C */ + signal(SIGTERM , util_abort_signal); /* If killing the program with SIGTERM (the default kill signal) you will get a backtrace. + Killing with SIGKILL (-9) will not give a backtrace.*/ +} /*****************************************************************/ diff --git a/ThirdParty/Ert/devel/libert_util/src/test_work_area.c b/ThirdParty/Ert/devel/libert_util/src/test_work_area.c new file mode 100644 index 0000000000..c1b1f60738 --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/src/test_work_area.c @@ -0,0 +1,216 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'test_work_area.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include +#include +#include + + +#include +#include +#include + +/* + This file implements a small work area implementation to be used for + tests which write to disk. The implementation works by creating a + work area in /tmp and then call chdir() change the current working + directory. + + An important aspect of this implementation is that test output from + different users should not come in conflict with e.g. permission + problems, to achieve this the directories created will be per user. + + When creating the work area you pass in a boolean flag whether you + want the area to be retained when the destructor is called. After + the the work_area is destroyed the cwd is changed back to the value + it had before the area was created. + + The functions test_work_area_install_file(), + test_work_area_copy_directory() and + test_work_area_copy_directory_content() can be used to populate the + work area with files and directories needed for the test + execution. These functions have some intelligence when it comes to + interpreting relative paths; a relative path input argument is + interpreted relative to the original cwd. + + Basic usage example: + -------------------- + + + -- Create directory /tmp/$USER/ert-test/my/funn/test and call + -- chdir() to the newly created directory. + test_work_area_type * work_area = test_work_area_alloc("my/funny/test" , true); + + -- Make files available from the test directory. + test_work_area_install_file(work_area , "/home/user/build/test-data/file1"); + test_work_area_install_file(work_area , "relative/path/file2"); + + -- Recursively copy directory and directory content into test area: + test_work_area_copy_directory(work_area , "/home/user/build/test-data/case1"); + + ... + -- Do normal test operations + ... + + -- Destroy test_work_area structure; since the work_area is created + -- with input flag @retain set to true the are on disk will not be + -- cleared. After the test_work_area_free( ) function has been + -- called the original cwd will be restored. + + test_work_area_free( work_area ); +*/ + + +#define PATH_FMT "/tmp/%s/ert-test/%s/%08d" /* /tmp/username/ert-test/test_name/random-integer */ + +struct test_work_area_struct { + bool retain; + char * cwd; + char * original_cwd; +}; + + +static test_work_area_type * test_work_area_alloc__(const char * path , bool retain) { + util_make_path( path ); + if (true) { + test_work_area_type * work_area = util_malloc( sizeof * work_area ); + work_area->retain = retain; + work_area->cwd = util_alloc_string_copy( path ); + work_area->original_cwd = util_alloc_cwd(); + chdir( work_area->cwd ); + + return work_area; + } +} + + + +test_work_area_type * test_work_area_alloc(const char * test_name, bool retain) { + if (test_name) { + uid_t uid = getuid(); + struct passwd * pw = getpwuid( uid ); + rng_type * rng = rng_alloc(MZRAN , INIT_CLOCK ); + char * path = util_alloc_sprintf( PATH_FMT , pw->pw_name , test_name , rng_get_int( rng , 100000000 )); + test_work_area_type * work_area = test_work_area_alloc__( path , retain ); + free( path ); + rng_free( rng ); + return work_area; + } else + return NULL; +} + + + +void test_work_area_free(test_work_area_type * work_area) { + if (!work_area->retain) + util_clear_directory( work_area->cwd , true , true ); + + chdir( work_area->original_cwd ); + free( work_area->original_cwd ); + free( work_area->cwd ); + free( work_area ); +} + + +const char * test_work_area_get_cwd( const test_work_area_type * work_area ) { + return work_area->cwd; +} + + +const char * test_work_area_get_original_cwd( const test_work_area_type * work_area ) { + return work_area->original_cwd; +} + + +/** + The point of this function is that the test code should be able to + access the file @input_file independent of the fact that it has + changed path. If @input_file is an absolute path the function will + do nothing, if @input_file is a realtive path the function will + copy @input_file from the location relative to the original cwd to + the corresponding location relative to the test cwd. +*/ + +void test_work_area_install_file( test_work_area_type * work_area , const char * input_src_file ) { + if (util_is_abs_path( input_src_file )) + return; + else { + char * src_file = util_alloc_filename( work_area->original_cwd , input_src_file , NULL ); + char * src_path; + + util_alloc_file_components( input_src_file , &src_path , NULL , NULL); + if (!util_entry_exists( src_path )) + util_make_path( src_path ); + + if (util_file_exists( src_file )) { + char * target_file = util_alloc_filename( work_area->cwd , input_src_file , NULL ); + util_copy_file( src_file , target_file ); + free( target_file ); + } + free( src_file ); + } +} + + +void test_work_area_copy_directory( test_work_area_type * work_area , const char * input_directory) { + char * src_directory; + + if (util_is_abs_path( input_directory )) + src_directory = util_alloc_string_copy( input_directory ); + else + src_directory = util_alloc_filename( work_area->original_cwd , input_directory , NULL); + + util_copy_directory(src_directory , work_area->cwd ); + free( src_directory ); +} + + +void test_work_area_copy_directory_content( test_work_area_type * work_area , const char * input_directory) { + char * src_directory; + + if (util_is_abs_path( input_directory )) + src_directory = util_alloc_string_copy( input_directory ); + else + src_directory = util_alloc_filename( work_area->original_cwd , input_directory , NULL); + + util_copy_directory_content(src_directory , work_area->cwd ); + free( src_directory ); +} + + + +void test_work_area_copy_file( test_work_area_type * work_area , const char * input_file) { + if (input_file) { + char * src_file; + + if (util_is_abs_path( input_file )) + src_file = util_alloc_string_copy( input_file ); + else + src_file = util_alloc_filename( work_area->original_cwd , input_file , NULL); + + if (util_file_exists( src_file )) { + char * target_file = util_split_alloc_filename( input_file ); + util_copy_file( src_file , target_file ); + } + free( src_file ); + } +} + + diff --git a/ThirdParty/Ert/devel/libert_util/src/util.c b/ThirdParty/Ert/devel/libert_util/src/util.c index de0cee7d73..d28337a9bd 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util.c +++ b/ThirdParty/Ert/devel/libert_util/src/util.c @@ -349,11 +349,10 @@ double util_kahan_sum(const double *data, size_t N) { } -bool util_double_approx_equal( double d1 , double d2) { +bool util_double_approx_equal__( double d1 , double d2, double epsilon) { if (d1 == d2) return true; else { - double epsilon = 1e-6; double diff = fabs(d1 - d2); double sum = fabs(d1) + fabs(d2); @@ -365,6 +364,12 @@ bool util_double_approx_equal( double d1 , double d2) { } +bool util_double_approx_equal( double d1 , double d2) { + double epsilon = 1e-6; + return util_double_approx_equal__( d1 , d2 , epsilon ); +} + + char * util_alloc_substring_copy(const char *src , int offset , int N) { char *copy; if ((N + offset) < strlen(src)) { @@ -453,14 +458,14 @@ void util_rewind_line(FILE *stream) { int c; do { - if (ftell(stream) == 0) + if (util_ftell(stream) == 0) at_eol = true; else { - fseek(stream , -1 , SEEK_CUR); + util_fseek(stream , -1 , SEEK_CUR); c = fgetc(stream); at_eol = EOL_CHAR(c); if (!at_eol) - fseek(stream , -1 , SEEK_CUR); + util_fseek(stream , -1 , SEEK_CUR); } } while (!at_eol); } @@ -489,7 +494,7 @@ bool util_fseek_string(FILE * stream , const char * __string , bool skip_string util_strupr( string ); { int len = strlen( string ); - long int initial_pos = ftell( stream ); /* Store the inital position. */ + long int initial_pos = util_ftell( stream ); /* Store the inital position. */ bool cont = true; do { int c = fgetc( stream ); @@ -497,7 +502,7 @@ bool util_fseek_string(FILE * stream , const char * __string , bool skip_string c = toupper( c ); if (c == string[0]) { /* OK - we got the first character right - lets try in more detail: */ - long int current_pos = ftell(stream); + long int current_pos = util_ftell(stream); bool equal = true; int string_index; for (string_index = 1; string_index < len; string_index++) { @@ -515,7 +520,7 @@ bool util_fseek_string(FILE * stream , const char * __string , bool skip_string string_found = true; cont = false; } else /* Go back to current pos and continue searching. */ - fseek(stream , current_pos , SEEK_SET); + util_fseek(stream , current_pos , SEEK_SET); } if (c == EOF) @@ -525,9 +530,9 @@ bool util_fseek_string(FILE * stream , const char * __string , bool skip_string if (string_found) { if (!skip_string) - fseek(stream , -strlen(string) , SEEK_CUR); /* Reposition to the beginning of 'string' */ + util_fseek(stream , -strlen(string) , SEEK_CUR); /* Reposition to the beginning of 'string' */ } else - fseek(stream , initial_pos , SEEK_SET); /* Could not find the string reposition at initial position. */ + util_fseek(stream , initial_pos , SEEK_SET); /* Could not find the string reposition at initial position. */ } free( string ); @@ -551,13 +556,13 @@ bool util_fseek_string(FILE * stream , const char * __string , bool skip_string char * util_fscanf_alloc_upto(FILE * stream , const char * stop_string, bool include_stop_string) { - long int start_pos = ftell(stream); + long int start_pos = util_ftell(stream); if (util_fseek_string(stream , stop_string , include_stop_string , true)) { /* Default case sensitive. */ - long int end_pos = ftell(stream); + long int end_pos = util_ftell(stream); int len = end_pos - start_pos; char * buffer = util_calloc( (len + 1) , sizeof * buffer ); - fseek(stream , start_pos , SEEK_SET); + util_fseek(stream , start_pos , SEEK_SET); util_fread( buffer , 1 , len , stream , __func__); buffer[len] = '\0'; @@ -569,7 +574,7 @@ char * util_fscanf_alloc_upto(FILE * stream , const char * stop_string, bool inc static char * util_fscanf_alloc_line__(FILE *stream , bool *at_eof , char * line) { - int init_pos = ftell(stream); + int init_pos = util_ftell(stream); char * new_line; int len; char end_char; @@ -598,7 +603,7 @@ static char * util_fscanf_alloc_line__(FILE *stream , bool *at_eof , char * line end_char = c; } - if (fseek(stream , init_pos , SEEK_SET) != 0) + if (util_fseek(stream , init_pos , SEEK_SET) != 0) util_abort("%s: fseek failed: %d/%s \n",__func__ , errno , strerror(errno)); new_line = util_realloc(line , len + 1 ); @@ -753,9 +758,9 @@ char * util_alloc_cwd(void) { bool util_is_cwd( const char * path ) { bool is_cwd = false; - struct stat path_stat; + stat_type path_stat; - if (stat(path , &path_stat) == 0) { + if (util_stat(path , &path_stat) == 0) { if (S_ISDIR( path_stat.st_mode )) { char * cwd = util_alloc_cwd(); #ifdef ERT_WINDOWS @@ -766,8 +771,8 @@ bool util_is_cwd( const char * path ) { */ util_abort("%s: Internal error - function not properly implmented on Windows \n",__func__); #else - struct stat cwd_stat; - stat(cwd , &cwd_stat); + stat_type cwd_stat; + util_stat(cwd , &cwd_stat); if (cwd_stat.st_ino == path_stat.st_ino) is_cwd = true; #endif @@ -1110,7 +1115,7 @@ void util_fskip_lines(FILE * stream , int lines) { at_eof = true; else { if (c != '\n') - fseek( stream , -1 , SEEK_CUR ); + util_fseek( stream , -1 , SEEK_CUR ); } } @@ -1154,7 +1159,7 @@ int util_forward_line(FILE * stream , bool * at_eof) { *at_eof = true; else { if (!EOL_CHAR(c)) - fseek(stream , -1 , SEEK_CUR); + util_fseek(stream , -1 , SEEK_CUR); } } else col++; @@ -1219,7 +1224,7 @@ static void util_fskip_chars__(FILE * stream , const char * skip_set , bool comp } } while (cont); if (!*at_eof) - fseek(stream , -1 , SEEK_CUR); + util_fseek(stream , -1 , SEEK_CUR); } @@ -1252,7 +1257,7 @@ static void util_fskip_space__(FILE * stream , bool complimentary_set , bool *at } } while (cont); if (!*at_eof) - fseek(stream , -1 , SEEK_CUR); + util_fseek(stream , -1 , SEEK_CUR); } @@ -1324,16 +1329,16 @@ char * util_fscanf_alloc_token(FILE * stream) { /* Skipping initial whitespace */ do { - int pos = ftell(stream); + int pos = util_ftell(stream); c = fgetc(stream); if (EOL_CHAR(c)) { /* Going back to position at newline */ - fseek(stream , pos , SEEK_SET); + util_fseek(stream , pos , SEEK_SET); cont = false; } else if (c == EOF) cont = false; else if (!util_char_in(c , 2 , space_set)) { - fseek(stream , pos , SEEK_SET); + util_fseek(stream , pos , SEEK_SET); cont = false; } } while (cont); @@ -1346,7 +1351,7 @@ char * util_fscanf_alloc_token(FILE * stream) { cont = true; { int length = 0; - long int token_start = ftell(stream); + long int token_start = util_ftell(stream); do { c = fgetc(stream); @@ -1359,10 +1364,10 @@ char * util_fscanf_alloc_token(FILE * stream) { else length++; } while (cont); - if (EOL_CHAR(c)) fseek(stream , -1 , SEEK_CUR); + if (EOL_CHAR(c)) util_fseek(stream , -1 , SEEK_CUR); token = util_calloc(length + 1 , sizeof * token ); - fseek(stream , token_start , SEEK_SET); + util_fseek(stream , token_start , SEEK_SET); { int i; for (i = 0; i < length; i++) @@ -1907,14 +1912,14 @@ bool util_fscanf_bool(FILE * stream , bool * value) { bool util_fscanf_int(FILE * stream , int * value) { - long int start_pos = ftell(stream); + long int start_pos = util_ftell(stream); char * token = util_fscanf_alloc_token(stream); bool value_OK = false; if (token != NULL) { value_OK = util_sscanf_int(token , value); if (!value_OK) - fseek(stream , start_pos , SEEK_SET); + util_fseek(stream , start_pos , SEEK_SET); free(token); } return value_OK; @@ -2072,14 +2077,14 @@ char * util_scanf_alloc_string(const char * prompt) { int util_count_file_lines(FILE * stream) { - long int init_pos = ftell(stream); + long int init_pos = util_ftell(stream); int lines = 0; bool at_eof = false; do { int col = util_forward_line(stream , &at_eof); if (col > 0) lines++; } while (!at_eof); - fseek(stream , init_pos , SEEK_SET); + util_fseek(stream , init_pos , SEEK_SET); return lines; } @@ -2103,10 +2108,10 @@ int util_count_content_file_lines(FILE * stream) { c = fgetc(stream); if (! feof(stream) ) { if (!EOL_CHAR(c)){ - fseek(stream , -1 , SEEK_CUR); - } + util_fseek(stream , -1 , SEEK_CUR); + } }else if (c == EOF){ - lines++; + lines++; } } else if (c == EOF){ @@ -2301,7 +2306,7 @@ bool util_files_equal( const char * file1 , const char * file2 ) { static void util_fclear_region( FILE * stream , long offset , long region_size) { - fseek( stream , offset , SEEK_SET ); + util_fseek( stream , offset , SEEK_SET ); { int i; for ( i=0; i < region_size; i++) @@ -2311,10 +2316,10 @@ static void util_fclear_region( FILE * stream , long offset , long region_size) static void util_fmove_block(FILE * stream , long offset , long shift , char * buffer , int buffer_size) { - fseek( stream , offset , SEEK_SET ); + util_fseek( stream , offset , SEEK_SET ); { int bytes_read = fread( buffer , sizeof * buffer , buffer_size , stream ); - fseek( stream , offset + shift , SEEK_SET ); + util_fseek( stream , offset + shift , SEEK_SET ); fwrite( buffer , sizeof * buffer , bytes_read , stream ); } } @@ -2342,10 +2347,10 @@ int util_fmove( FILE * stream , long offset , long shift) { long file_size; // Determine size of file. { - long init_pos = ftell( stream ); - fseek( stream , 0 , SEEK_END); - file_size = ftell( stream ); - fseek( stream , init_pos , SEEK_SET ); + long init_pos = util_ftell( stream ); + util_fseek( stream , 0 , SEEK_END); + file_size = util_ftell( stream ); + util_fseek( stream , init_pos , SEEK_SET ); } // Validate offset and shift input values. @@ -2409,8 +2414,8 @@ bool util_file_exists(const char *filename) { */ bool util_entry_exists( const char * entry ) { - struct stat stat_buffer; - int stat_return = stat(entry, &stat_buffer); + stat_type stat_buffer; + int stat_return = util_stat(entry, &stat_buffer); if (stat_return == 0) return true; else { @@ -2445,9 +2450,9 @@ bool util_entry_exists( const char * entry ) { bool util_is_directory(const char * path) { - struct stat stat_buffer; + stat_type stat_buffer; - if (stat(path , &stat_buffer) == 0) + if (util_stat(path , &stat_buffer) == 0) return S_ISDIR(stat_buffer.st_mode); else if (errno == ENOENT) /*Path does not exist at all. */ @@ -2461,9 +2466,9 @@ bool util_is_directory(const char * path) { bool util_is_file(const char * path) { - struct stat stat_buffer; + stat_type stat_buffer; - if (stat(path , &stat_buffer) == 0) + if (util_stat(path , &stat_buffer) == 0) return S_ISREG(stat_buffer.st_mode); else if (errno == ENOENT) /*Path does not exist at all. */ @@ -2483,8 +2488,8 @@ bool util_is_file(const char * path) { #ifdef HAVE_FORK bool util_is_executable(const char * path) { if (util_file_exists(path)) { - struct stat stat_buffer; - stat(path , &stat_buffer); + stat_type stat_buffer; + util_stat(path , &stat_buffer); if (S_ISREG(stat_buffer.st_mode)) return (stat_buffer.st_mode & S_IXUSR); else @@ -2498,8 +2503,8 @@ bool util_is_executable(const char * path) { Will not differtiate between files and directories. */ bool util_entry_readable( const char * entry ) { - struct stat buffer; - if (stat( entry , &buffer ) == 0) + stat_type buffer; + if (util_stat( entry , &buffer ) == 0) return buffer.st_mode & S_IRUSR; else return false; /* If stat failed - typically not existing entry - we return false. */ @@ -2514,8 +2519,8 @@ bool util_file_readable( const char * file ) { } bool util_entry_writable( const char * entry ) { - struct stat buffer; - if (stat( entry , &buffer ) == 0) + stat_type buffer; + if (util_stat( entry , &buffer ) == 0) return buffer.st_mode & S_IWUSR; else return false; /* If stat failed - typically not existing entry - we return false. */ @@ -2538,8 +2543,8 @@ bool util_is_executable(const char * path) { /* If it exists on windows it is readable ... */ bool util_entry_readable( const char * entry ) { - struct stat buffer; - if (stat( entry , &buffer ) == 0) + stat_type buffer; + if (util_stat( entry , &buffer ) == 0) return true; else return false; /* If stat failed - typically not existing entry - we return false. */ @@ -2547,8 +2552,8 @@ bool util_entry_readable( const char * entry ) { /* If it exists on windows it is readable ... */ bool util_entry_writable( const char * entry ) { - struct stat buffer; - if (stat( entry , &buffer ) == 0) + stat_type buffer; + if (util_stat( entry , &buffer ) == 0) return true; else return false; /* If stat failed - typically not existing entry - we return false. */ @@ -2710,14 +2715,14 @@ void util_alloc_file_components(const char * file, char **_path , char **_basena size_t util_file_size(const char *file) { - struct stat buffer; + stat_type buffer; int fildes; fildes = open(file , O_RDONLY); if (fildes == -1) util_abort("%s: failed to open:%s - %s \n",__func__ , file , strerror(errno)); - fstat(fildes, &buffer); + util_fstat(fildes, &buffer); close(fildes); return buffer.st_size; @@ -2757,11 +2762,11 @@ void util_ftruncate(FILE * stream , long size) { */ bool util_same_file(const char * file1 , const char * file2) { - struct stat buffer1 , buffer2; + stat_type buffer1 , buffer2; int stat1,stat2; - stat1 = stat(file1, &buffer1); // In the case of symlinks the stat call will stat the target file and not the link. - stat2 = stat(file2, &buffer2); + stat1 = util_stat(file1, &buffer1); // In the case of symlinks the stat call will stat the target file and not the link. + stat2 = util_stat(file2, &buffer2); if ((stat1 == 0) && (stat1 == stat2)) { if (buffer1.st_ino == buffer2.st_ino) @@ -2788,7 +2793,7 @@ bool util_fmt_bit8_stream(FILE * stream ) { const int min_read = 256; /* Critically small */ const double bit8set_limit = 0.00001; const int buffer_size = 131072; - long int start_pos = ftell(stream); + long int start_pos = util_ftell(stream); bool fmt_file; { double bit8set_fraction; @@ -2812,7 +2817,7 @@ bool util_fmt_bit8_stream(FILE * stream ) { else fmt_file = false; } - fseek(stream , start_pos , SEEK_SET); + util_fseek(stream , start_pos , SEEK_SET); return fmt_file; } @@ -2850,17 +2855,17 @@ bool util_fmt_bit8(const char *filename ) { double util_file_difftime(const char *file1 , const char *file2) { - struct stat b1, b2; + stat_type b1, b2; int f1,f2; time_t t1,t2; f1 = open(file1 , O_RDONLY); - fstat(f1, &b1); + util_fstat(f1, &b1); t1 = b1.st_mtime; close(f1); f2 = open(file2 , O_RDONLY); - fstat(f2, &b2); + util_fstat(f2, &b2); t2 = b2.st_mtime; close(f2); @@ -2872,8 +2877,8 @@ time_t util_file_mtime(const char * file) { time_t mtime = -1; int fd = open( file , O_RDONLY); if (fd != -1) { - struct stat f_stat; - fstat(fd , &f_stat ); + stat_type f_stat; + util_fstat(fd , &f_stat ); mtime = f_stat.st_mtime; close( fd ); } @@ -3021,10 +3026,10 @@ bool util_sscanf_date(const char * date_token , time_t * t) { bool util_fscanf_date(FILE *stream , time_t *t) { - int init_pos = ftell(stream); + int init_pos = util_ftell(stream); char * date_token = util_fscanf_alloc_token(stream); bool return_value = util_sscanf_date(date_token , t); - if (!return_value) fseek(stream , init_pos , SEEK_SET); + if (!return_value) util_fseek(stream , init_pos , SEEK_SET); free(date_token); return return_value; } @@ -4072,9 +4077,9 @@ void util_fskip_string(FILE *stream) { if (len == 0) return; /* The user has written NULL with util_fwrite_string(). */ else if (len == -1) - fseek( stream , 1 , SEEK_CUR); /* Magic length for "" - skip the '\0' */ + util_fseek( stream , 1 , SEEK_CUR); /* Magic length for "" - skip the '\0' */ else - fseek(stream , len + 1 , SEEK_CUR); /* Skip the data in a normal string. */ + util_fseek(stream , len + 1 , SEEK_CUR); /* Skip the data in a normal string. */ } @@ -4128,15 +4133,15 @@ bool util_fread_bool(FILE * stream) { void util_fskip_int(FILE * stream) { - fseek( stream , sizeof (int) , SEEK_CUR); + util_fseek( stream , sizeof (int) , SEEK_CUR); } void util_fskip_long(FILE * stream) { - fseek( stream , sizeof (long) , SEEK_CUR); + util_fseek( stream , sizeof (long) , SEEK_CUR); } void util_fskip_bool(FILE * stream) { - fseek( stream , sizeof (bool) , SEEK_CUR); + util_fseek( stream , sizeof (bool) , SEEK_CUR); } @@ -4773,9 +4778,9 @@ int util_get_type( void * data ) { */ int util_get_current_linenr(FILE * stream) { - long init_pos = ftell(stream); + long init_pos = util_ftell(stream); int line_nr = 0; - fseek( stream , 0L , SEEK_SET); + util_fseek( stream , 0L , SEEK_SET); { int char_nr; int c; @@ -4893,7 +4898,7 @@ int util_fnmatch( const char * pattern , const char * string ) { #ifdef HAVE_FNMATCH return fnmatch( pattern , string , 0 ); #else -#pragma comment(lib , "shlwapi.lib"); +#pragma comment(lib , "shlwapi.lib") bool match = PathMatchSpec( string , pattern ); // shlwapi if (match) return 0; @@ -4975,6 +4980,7 @@ int util_round( double x ) { return (int) (x + 0.5); } #endif #include "util_path.c" +#include "util_lfs.c" int util_type_get_id( const void * data ) { int type_id = ((const int*) data)[0]; diff --git a/ThirdParty/Ert/devel/libert_util/src/util_fork.c b/ThirdParty/Ert/devel/libert_util/src/util_fork.c index 2eda0d2806..3af24be1a9 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util_fork.c +++ b/ThirdParty/Ert/devel/libert_util/src/util_fork.c @@ -239,7 +239,7 @@ char * util_alloc_filename_from_stream( FILE * input_stream ) { */ bool util_ping(const char *hostname) { - pid_t ping_pid = util_fork_exec(PING_CMD , 4 , (const char *[4]) {"-c" , "3" , "-q", hostname} , false , NULL , NULL , NULL , NULL , NULL); + pid_t ping_pid = util_fork_exec(PING_CMD , 4 , (const char *[4]) {"-c" , "3" , "-q", hostname} , false , NULL , NULL , NULL , "/dev/null" , "/dev/null"); int wait_status; pid_t wait_pid = waitpid(ping_pid , &wait_status , 0); diff --git a/ThirdParty/Ert/devel/libert_util/src/util_getuid.c b/ThirdParty/Ert/devel/libert_util/src/util_getuid.c index 23c18633c3..2f95fa7f2b 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util_getuid.c +++ b/ThirdParty/Ert/devel/libert_util/src/util_getuid.c @@ -1,15 +1,15 @@ uid_t util_get_entry_uid( const char * file ) { - struct stat buffer; - stat( file , &buffer); + stat_type buffer; + util_stat( file , &buffer); return buffer.st_uid; } bool util_chmod_if_owner( const char * filename , mode_t new_mode) { - struct stat buffer; + stat_type buffer; uid_t exec_uid = getuid(); - stat( filename , &buffer ); + util_stat( filename , &buffer ); if (exec_uid == buffer.st_uid) { /* OKAY - the current running uid is also the owner of the file. */ mode_t current_mode = buffer.st_mode & ( S_IRWXU + S_IRWXG + S_IRWXO ); @@ -39,8 +39,8 @@ bool util_chmod_if_owner( const char * filename , mode_t new_mode) { bool util_addmode_if_owner( const char * filename , mode_t add_mode) { - struct stat buffer; - stat( filename , &buffer ); + stat_type buffer; + util_stat( filename , &buffer ); { mode_t current_mode = buffer.st_mode & ( S_IRWXU + S_IRWXG + S_IRWXO ); @@ -56,8 +56,8 @@ bool util_addmode_if_owner( const char * filename , mode_t add_mode) { Implements shell chmod -??? behaviour. */ bool util_delmode_if_owner( const char * filename , mode_t del_mode) { - struct stat buffer; - stat( filename , &buffer ); + stat_type buffer; + util_stat( filename , &buffer ); { mode_t current_mode = buffer.st_mode & ( S_IRWXU + S_IRWXG + S_IRWXO ); diff --git a/ThirdParty/Ert/devel/libert_util/src/util_lfs.c b/ThirdParty/Ert/devel/libert_util/src/util_lfs.c new file mode 100644 index 0000000000..fb1413843a --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/src/util_lfs.c @@ -0,0 +1,110 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'util_win64.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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. +*/ + +/* + This file, together with ifdef and typedef in util.h together try to + define transparent large file (> 2GB) support on windows and + linux. To support large files the datatype used to hold a file + offset must be 64 bit, in practical consequences this means: + + - functions ftell() and fseek() must use 64 bit offset types. + - The size field in struct stat must be 64 bit. + + On linux (at least on 64 bit platform) this is the deafult, + i.e. large files can be accessed out of the box. On windows the + situaton is more complicated: + + - functions ftell() and fseek() expect 32 bit offset types. + - The size field in struct stat is a 32 bit variable. + + Observe that the situation where 32 bit offset variables are used on + windows apply even on a 64 bit platform. To provide large file + support windows has the functions _ftelli64() and _fseeki64() and + the struct _stat64. Here we provide small wrapper functions + util_ftell(), util_fseek() and typedef struct stat_info. + + The final challenge is that the types 'long' and 'off_t == long' + have different size on windows and linux: + + + Windows(64 bit): sizeof(long) = 4 + sizeof(off_t) = 4 + + Linux(64 bit): sizeof(long) = 8 + sizeof(off_t) = 8 + + + To protect against this confusion we have typedefed a type + 'offset_type' in util.h, and all file operations should use that type. +*/ + +offset_type util_ftell(FILE * stream) { +#ifdef WINDOWS_LFS + return _ftelli64(stream); +#else + #ifdef HAVE_FSEEKO + return ftello(stream); + #else + return ftell(stream); + #endif +#endif +} + + +int util_fseek(FILE * stream, offset_type offset, int whence) { +#ifdef WINDOWS_LFS + return _fseeki64(stream , offset , whence); +#else + #ifdef HAVE_FSEEKO + return fseeko( stream , offset , whence ); + #else + return fseek( stream , offset , whence ); + #endif +#endif +} + + + +void util_rewind(FILE * stream) { +#ifdef WINDOWS_LFS + _fseeki64(stream , 0L , SEEK_SET); +#else + rewind( stream ); +#endif +} + + + + + +int util_stat(const char * filename , stat_type * stat_info) { +#ifdef WINDOWS_LFS + return _stat64(filename , stat_info); +#else + return stat(filename , stat_info); +#endif +} + + +int util_fstat(int fileno, stat_type * stat_info) { +#ifdef WINDOWS_LFS + return _fstat64(fileno , stat_info); +#else + return fstat(fileno , stat_info); +#endif +} diff --git a/ThirdParty/Ert/devel/libert_util/src/util_opendir.c b/ThirdParty/Ert/devel/libert_util/src/util_opendir.c index e12da3bc8c..05848bf898 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util_opendir.c +++ b/ThirdParty/Ert/devel/libert_util/src/util_opendir.c @@ -1,13 +1,5 @@ -/** - Externals: -*/ -typedef struct msg_struct msg_type; -msg_type * msg_alloc(const char * , bool); -void msg_show(msg_type * ); -void msg_free(msg_type * , bool); -void msg_update(msg_type * , const char * ); -static void util_copy_directory__(const char * src_path , const char * target_path , int buffer_size , void * buffer , msg_type * msg) { +static void util_copy_directory__(const char * src_path , const char * target_path , int buffer_size , void * buffer ) { if (!util_is_directory(src_path)) util_abort("%s: %s is not a directory \n",__func__ , src_path); @@ -26,11 +18,11 @@ static void util_copy_directory__(const char * src_path , const char * target_pa char * full_src_path = util_alloc_filename(src_path , dp->d_name , NULL); char * full_target_path = util_alloc_filename(target_path , dp->d_name , NULL); if (util_is_file( full_src_path )) { - if (msg != NULL) - msg_update( msg , full_src_path); util_copy_file__( full_src_path , full_target_path , buffer_size , buffer , true); - } else - util_copy_directory__( full_src_path , full_target_path , buffer_size , buffer , msg); + } else { + if (util_is_directory( full_src_path ) && !util_is_link( full_src_path)) + util_copy_directory__( full_src_path , full_target_path , buffer_size , buffer); + } free( full_src_path ); free( full_target_path ); @@ -43,6 +35,14 @@ static void util_copy_directory__(const char * src_path , const char * target_pa } +void util_copy_directory_content(const char * src_path , const char * target_path) { + int buffer_size = 16 * 1024 * 1024; /* 16 MB */ + void * buffer = util_malloc( buffer_size ); + + util_copy_directory__( src_path , target_path , buffer_size , buffer); + free( buffer ); +} + /** Equivalent to shell command cp -r src_path target_path */ @@ -50,35 +50,18 @@ static void util_copy_directory__(const char * src_path , const char * target_pa /* Does not handle symlinks (I think ...). */ -void util_copy_directory(const char * src_path , const char * __target_path , const char * prompt) { +void util_copy_directory(const char * src_path , const char * __target_path) { int num_components; char ** path_parts; char * path_tail; char * target_path; - void * buffer = NULL; - int buffer_size = 512 * 1024 * 1024; /* 512 MB */ - do { - buffer = malloc(buffer_size); - if (buffer == NULL) buffer_size /= 2; - } while ((buffer == NULL) && (buffer_size > 0)); - - if (buffer_size == 0) - util_abort("%s: failed to allocate any memory ?? \n",__func__); util_path_split(src_path , &num_components , &path_parts); path_tail = path_parts[num_components - 1]; target_path = util_alloc_filename(__target_path , path_tail , NULL); - { - msg_type * msg = NULL; - if (prompt != NULL) { - msg = msg_alloc(prompt , false); - msg_show( msg ); - util_copy_directory__(src_path , target_path , buffer_size , buffer ,msg); - } - msg_free(msg , true); - } - free( buffer ); + util_copy_directory_content(src_path , target_path ); + free(target_path); util_free_stringlist( path_parts , num_components ); } diff --git a/ThirdParty/Ert/devel/libert_util/src/util_path.c b/ThirdParty/Ert/devel/libert_util/src/util_path.c index 40e512aaff..2bf953f232 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util_path.c +++ b/ThirdParty/Ert/devel/libert_util/src/util_path.c @@ -105,11 +105,11 @@ void util_make_path(const char *_path) { char * util_alloc_tmp_file(const char * path, const char * prefix , bool include_pid ) { // Should be reimplemented to use mkstemp() const int pid_digits = 6; - const int pid_max = 1000000; const int random_digits = 6; const int random_max = 1000000; #ifdef HAVE_PID_T + const int pid_max = 1000000; pid_t pid = getpid() % pid_max; #else int pid = 0; @@ -201,8 +201,31 @@ int util_proc_mem_free(void) { +char * util_split_alloc_dirname( const char * input_path ) { + char * path; + util_alloc_file_components( input_path , &path , NULL , NULL); + return path; +} +char * util_split_alloc_filename( const char * input_path ) { + char * filename = NULL; + { + char * basename; + char * extension; + + util_alloc_file_components( input_path , NULL , &basename , &extension); + + if (basename) + filename = util_alloc_filename( NULL , basename , extension ); + + util_safe_free( basename ); + util_safe_free( extension ); + } + + return filename; +} + void util_path_split(const char *line , int *_tokens, char ***_token_list) { diff --git a/ThirdParty/Ert/devel/libert_util/src/util_symlink.c b/ThirdParty/Ert/devel/libert_util/src/util_symlink.c index 6f051825d5..10e414640a 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util_symlink.c +++ b/ThirdParty/Ert/devel/libert_util/src/util_symlink.c @@ -24,7 +24,7 @@ void util_make_slink(const char *target , const char * link) { */ bool util_is_link(const char * path) { - struct stat stat_buffer; + stat_type stat_buffer; if (lstat(path , &stat_buffer) == 0) return S_ISLNK(stat_buffer.st_mode); else if (errno == ENOENT) diff --git a/ThirdParty/Ert/devel/libert_util/src/util_zlib.c b/ThirdParty/Ert/devel/libert_util/src/util_zlib.c index acdad08263..d8f098de04 100644 --- a/ThirdParty/Ert/devel/libert_util/src/util_zlib.c +++ b/ThirdParty/Ert/devel/libert_util/src/util_zlib.c @@ -201,7 +201,7 @@ void util_fread_compressed(void *__data , FILE * stream) { */ void * util_fread_alloc_compressed(FILE * stream) { - long current_pos = ftell(stream); + long current_pos = util_ftell(stream); char * data; int size; @@ -209,7 +209,7 @@ void * util_fread_alloc_compressed(FILE * stream) { if (size == 0) return NULL; else { - fseek(stream , current_pos , SEEK_SET); + util_fseek(stream , current_pos , SEEK_SET); data = util_calloc(size , sizeof * data ); util_fread_compressed(data , stream); return data; @@ -226,7 +226,7 @@ int util_fread_sizeof_compressed(FILE * stream) { int size; fread(&size , sizeof size , 1 , stream); - fseek( stream , pos , SEEK_SET ); + util_fseek( stream , pos , SEEK_SET ); return size; } @@ -244,7 +244,7 @@ void util_fskip_compressed(FILE * stream) { do { unsigned long compressed_size; fread(&compressed_size , sizeof compressed_size , 1 , stream); - fseek(stream , compressed_size , SEEK_CUR); + util_fseek(stream , compressed_size , SEEK_CUR); fread(&offset , sizeof offset , 1 , stream); } while (offset < size); } diff --git a/ThirdParty/Ert/devel/libert_util/src/vector.c b/ThirdParty/Ert/devel/libert_util/src/vector.c index 99fa0c445e..63ae3a0c4c 100644 --- a/ThirdParty/Ert/devel/libert_util/src/vector.c +++ b/ThirdParty/Ert/devel/libert_util/src/vector.c @@ -43,6 +43,7 @@ struct vector_struct { typedef struct { vector_cmp_ftype * user_cmp; node_data_type * data; + int index; } vector_sort_node_type; @@ -555,29 +556,50 @@ static int vector_cmp(const void * s1 , const void * s2) { */ +static vector_sort_node_type * vector_alloc_sort_data( const vector_type * vector , vector_cmp_ftype * cmp) { + vector_sort_node_type * sort_data = util_calloc( vector->size , sizeof * sort_data ); + int i; + + /* Fill up the temporary storage used for sorting */ + for (i = 0; i < vector->size; i++) { + sort_data[i].data = vector->data[i]; + sort_data[i].user_cmp = cmp; + sort_data[i].index = i; + } + + /* Sort the temporary vector */ + qsort(sort_data , vector->size , sizeof * sort_data , vector_cmp); + + return sort_data; +} + void vector_sort(vector_type * vector , vector_cmp_ftype * cmp) { - vector_sort_node_type * sort_data = util_calloc( vector->size , sizeof * sort_data ); - { - int i; - - /* Fill up the temporary storage used for sorting */ - for (i = 0; i < vector->size; i++) { - sort_data[i].data = vector->data[i]; - sort_data[i].user_cmp = cmp; - } - - /* Sort the temporary vector */ - qsort(sort_data , vector->size , sizeof * sort_data , vector_cmp); - - /* Recover the sorted vector */ - for (i = 0; i < vector->size; i++) - vector->data[i] = sort_data[i].data; - } + vector_sort_node_type * sort_data = vector_alloc_sort_data( vector , cmp ); + int i; + /* Recover the sorted vector */ + for (i = 0; i < vector->size; i++) + vector->data[i] = sort_data[i].data; + free( sort_data ); } +int_vector_type * vector_alloc_sort_perm(const vector_type * vector , vector_cmp_ftype * cmp) { + vector_sort_node_type * sort_data = vector_alloc_sort_data( vector , cmp ); + int_vector_type * sort_perm = int_vector_alloc(0,0); + int i; + for (i = 0; i < vector->size; i++) + int_vector_iset( sort_perm , i , sort_data[i].index); + + free( sort_data ); + return sort_perm; +} + + + + + void vector_inplace_reverse(vector_type * vector) { if (vector->size > 0) { node_data_type ** new_data = util_calloc( vector->size , sizeof * new_data ); diff --git a/ThirdParty/Ert/devel/libert_util/src/vector_template.c b/ThirdParty/Ert/devel/libert_util/src/vector_template.c index c032a184c6..5ae8e9bb4b 100644 --- a/ThirdParty/Ert/devel/libert_util/src/vector_template.c +++ b/ThirdParty/Ert/devel/libert_util/src/vector_template.c @@ -500,6 +500,15 @@ void @TYPE@_vector_scale(@TYPE@_vector_type * vector, @TYPE@ factor) { vector->data[i] *= factor; } + +/* Vector / scalar; seperate _div function to ensure correct integer division. */ +void @TYPE@_vector_div(@TYPE@_vector_type * vector, @TYPE@ divisor) { + int i; + for (i=0; i < vector->size; i++) + vector->data[i] /= divisor; +} + + /* vector + scalar */ void @TYPE@_vector_shift(@TYPE@_vector_type * vector, @TYPE@ delta) { int i; diff --git a/ThirdParty/Ert/devel/libert_util/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libert_util/tests/CMakeLists.txt index 5c88534d83..5457bf2469 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libert_util/tests/CMakeLists.txt @@ -5,104 +5,116 @@ # 1. First server - this should be an existing server which should return true. # 2. This should be an invalid hostname - should return false. # 3. This should be an valid host which does not answer ping - i.e currently off? -set(PING_SERVERS "localhost" CACHE STRING "List of LSF servers for testing") +set(PING_SERVERS "" CACHE STRING "List of servers for testing ping") link_directories( ${ERT_BINARY_DIR}/libert_util/src ) add_executable( ert_util_type_vector_test ert_util_type_vector_test.c ) -target_link_libraries( ert_util_type_vector_test ert_util ) +target_link_libraries( ert_util_type_vector_test ert_util test_util ) add_test( ert_util_type_vector_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_type_vector_test ) +add_executable( ert_util_filename ert_util_filename.c ) +target_link_libraries( ert_util_filename ert_util test_util ) +add_test( ert_util_filename ${EXECUTABLE_OUTPUT_PATH}/ert_util_filename ) + add_executable( ert_util_string_util ert_util_string_util.c ) -target_link_libraries( ert_util_string_util ert_util ) +target_link_libraries( ert_util_string_util ert_util test_util ) add_test( ert_util_string_util ${EXECUTABLE_OUTPUT_PATH}/ert_util_string_util ) add_executable( ert_util_vector_test ert_util_vector_test.c ) -target_link_libraries( ert_util_vector_test ert_util ) +target_link_libraries( ert_util_vector_test ert_util test_util ) add_test( ert_util_vector_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_vector_test ) add_executable( ert_util_cwd_test ert_util_cwd_test.c ) -target_link_libraries( ert_util_cwd_test ert_util ) +target_link_libraries( ert_util_cwd_test ert_util test_util ) add_test( ert_util_cwd_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_cwd_test ${CMAKE_CURRENT_BINARY_DIR}) add_executable( ert_util_relpath_test ert_util_relpath_test.c ) -target_link_libraries( ert_util_relpath_test ert_util ) +target_link_libraries( ert_util_relpath_test ert_util test_util ) add_test( ert_util_relpath_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_relpath_test ) add_executable( ert_util_path_stack_test ert_util_path_stack_test.c ) -target_link_libraries( ert_util_path_stack_test ert_util ) +target_link_libraries( ert_util_path_stack_test ert_util test_util ) add_test( ert_util_path_stack_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_path_stack_test ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) add_executable( ert_util_PATH_test ert_util_PATH_test.c ) -target_link_libraries( ert_util_PATH_test ert_util ) +target_link_libraries( ert_util_PATH_test ert_util test_util ) add_test( ert_util_PATH_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_PATH_test ) add_executable( ert_util_strcat_test ert_util_strcat_test.c ) -target_link_libraries( ert_util_strcat_test ert_util ) +target_link_libraries( ert_util_strcat_test ert_util test_util ) add_test( ert_util_strcat_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_strcat_test ) add_executable( ert_util_sprintf_escape ert_util_sprintf_escape.c ) -target_link_libraries( ert_util_sprintf_escape ert_util ) +target_link_libraries( ert_util_sprintf_escape ert_util test_util ) add_test( ert_util_sprintf_escape ${EXECUTABLE_OUTPUT_PATH}/ert_util_sprintf_escape ) add_executable( ert_util_stringlist_test ert_util_stringlist_test.c ) -target_link_libraries( ert_util_stringlist_test ert_util ) +target_link_libraries( ert_util_stringlist_test ert_util test_util ) add_test( ert_util_stringlist_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_stringlist_test ) add_executable( ert_util_realpath ert_util_realpath.c ) -target_link_libraries( ert_util_realpath ert_util ) +target_link_libraries( ert_util_realpath ert_util test_util ) add_test( ert_util_realpath ${EXECUTABLE_OUTPUT_PATH}/ert_util_realpath ) add_executable( ert_util_hash_test ert_util_hash_test.c ) -target_link_libraries( ert_util_hash_test ert_util ) +target_link_libraries( ert_util_hash_test ert_util test_util ) add_test( ert_util_hash_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_hash_test ) add_executable( ert_util_binary_split ert_util_binary_split.c ) -target_link_libraries( ert_util_binary_split ert_util ) +target_link_libraries( ert_util_binary_split ert_util test_util ) add_test( ert_util_binary_split ${EXECUTABLE_OUTPUT_PATH}/ert_util_binary_split ) add_executable( ert_util_logh ert_util_logh.c ) -target_link_libraries( ert_util_logh ert_util ) +target_link_libraries( ert_util_logh ert_util test_util ) add_test( ert_util_logh ${EXECUTABLE_OUTPUT_PATH}/ert_util_logh ) add_executable( ert_util_rng ert_util_rng.c ) -target_link_libraries( ert_util_rng ert_util ) +target_link_libraries( ert_util_rng ert_util test_util ) add_test( ert_util_rng ${EXECUTABLE_OUTPUT_PATH}/ert_util_rng ) add_executable( ert_util_time_interval ert_util_time_interval.c ) -target_link_libraries( ert_util_time_interval ert_util ) +target_link_libraries( ert_util_time_interval ert_util test_util ) add_test( ert_util_time_interval ${EXECUTABLE_OUTPUT_PATH}/ert_util_time_interval ) add_executable( ert_util_before_after ert_util_before_after.c ) -target_link_libraries( ert_util_before_after ert_util ) +target_link_libraries( ert_util_before_after ert_util test_util ) add_test( ert_util_before_after ${EXECUTABLE_OUTPUT_PATH}/ert_util_before_after ) add_executable( ert_util_approx_equal ert_util_approx_equal.c ) -target_link_libraries( ert_util_approx_equal ert_util ) +target_link_libraries( ert_util_approx_equal ert_util test_util ) add_test( ert_util_approx_equal ${EXECUTABLE_OUTPUT_PATH}/ert_util_approx_equal ) add_executable( ert_util_ping ert_util_ping.c ) -target_link_libraries( ert_util_ping ert_util ) +target_link_libraries( ert_util_ping ert_util test_util ) add_test( ert_util_ping ${EXECUTABLE_OUTPUT_PATH}/ert_util_ping ${PING_SERVERS}) add_executable( ert_util_file_readable ert_util_file_readable.c ) -target_link_libraries( ert_util_file_readable ert_util ) +target_link_libraries( ert_util_file_readable ert_util test_util ) add_test( ert_util_file_readable ${EXECUTABLE_OUTPUT_PATH}/ert_util_file_readable ${FILE_READABLE_SERVERS}) add_executable( ert_util_addr2line ert_util_addr2line.c ) -target_link_libraries( ert_util_addr2line ert_util ) +target_link_libraries( ert_util_addr2line ert_util test_util ) add_test( ert_util_addr2line ${EXECUTABLE_OUTPUT_PATH}/ert_util_addr2line) +add_executable( ert_util_work_area ert_util_work_area.c ) +target_link_libraries( ert_util_work_area ert_util test_util ) +add_test( NAME ert_util_work_area + COMMAND ${EXECUTABLE_OUTPUT_PATH}/ert_util_work_area data/file1.txt ${CMAKE_CURRENT_SOURCE_DIR}/data/file2.txt data + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + + + if (WITH_LATEX) add_executable( ert_util_latex_test ert_util_latex_test.c ) - target_link_libraries(ert_util_latex_test ert_util ) + target_link_libraries(ert_util_latex_test ert_util test_util ) add_test( ert_util_latex_test ${EXECUTABLE_OUTPUT_PATH}/ert_util_latex_test ${CMAKE_CURRENT_SOURCE_DIR}/data/latex_OK.tex ) endif() add_executable( ert_util_arg_pack ert_util_arg_pack.c) set_target_properties( ert_util_arg_pack PROPERTIES COMPILE_FLAGS "-Werror") -target_link_libraries( ert_util_arg_pack ert_util ) +target_link_libraries( ert_util_arg_pack ert_util test_util ) add_test( ert_util_arg_pack ${EXECUTABLE_OUTPUT_PATH}/ert_util_arg_pack) diff --git a/ThirdParty/Ert/devel/libert_util/tests/data/file1.txt b/ThirdParty/Ert/devel/libert_util/tests/data/file1.txt new file mode 100644 index 0000000000..0ee389557a --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/tests/data/file1.txt @@ -0,0 +1 @@ +Some content diff --git a/ThirdParty/Ert/devel/libert_util/tests/data/file2.txt b/ThirdParty/Ert/devel/libert_util/tests/data/file2.txt new file mode 100644 index 0000000000..de9afa7f69 --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/tests/data/file2.txt @@ -0,0 +1 @@ +More content diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_filename.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_filename.c new file mode 100644 index 0000000000..4bd358ecd9 --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_filename.c @@ -0,0 +1,73 @@ +/* + Copyright (C) 2012 Statoil ASA, Norway. + + The file 'ert_util_PATH_test.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include +#include + +#include +#include + + +void test_dirname() { + const char * src_file1 = "/some/very/long/path/file.txt"; + const char * src_file2 = "relative/path/file.txt"; + const char * src_file3 = "file.txt"; + + char * path1 = util_split_alloc_dirname( src_file1 ); + char * path2 = util_split_alloc_dirname( src_file2 ); + char * path3 = util_split_alloc_dirname( src_file3 ); + + test_assert_string_equal( "/some/very/long/path" , path1); + test_assert_string_equal( "relative/path" , path2); + test_assert_NULL( path3 ); + + free( path1 ); + free( path2 ); +} + + + +void test_filename() { + const char * src_file1 = "/some/very/long/path/file1.txt"; + const char * src_file2 = "relative/path/file2"; + const char * src_file3 = "/tmp"; + + char * file1 = util_split_alloc_filename( src_file1 ); + char * file2 = util_split_alloc_filename( src_file2 ); + char * file3 = util_split_alloc_filename( src_file3 ); + + test_assert_string_equal( "file1.txt" , file1); + test_assert_string_equal( "file2" , file2); + test_assert_NULL( file3 ); + free( file1 ); + free( file2 ); + +} + + + + +int main(int argc , char ** argv) { + + test_dirname(); + test_filename(); + exit(0); + +} diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_logh.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_logh.c index 2f928c1fd1..0528fe2601 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/ert_util_logh.c +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_logh.c @@ -19,12 +19,14 @@ #include #include +#include #include #include -#define LOG_FILE "/tmp/log.txt" +#define LOG_FILE "log.txt" int main(int argc , char ** argv) { + test_work_area_type * work_area = test_work_area_alloc("util/logh" , false); { log_type * logh = log_open( NULL , 0 ); @@ -40,5 +42,6 @@ int main(int argc , char ** argv) { test_assert_true( log_is_open( logh )); log_close( logh ); } + test_work_area_free( work_area ); exit(0); } diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_ping.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_ping.c index 5b0a31876b..5b41aa69e7 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/ert_util_ping.c +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_ping.c @@ -25,17 +25,17 @@ int main( int argc , char ** argv) { - stringlist_type * server_list = stringlist_alloc_from_split( argv[1] , " "); - argc = stringlist_get_size( server_list ); - - if (argc >= 1) - test_assert_true( util_ping( stringlist_iget( server_list , 0 ))); + test_assert_true( util_ping("localhost" )); + test_assert_true( util_ping("127.0.0.1" )); + test_assert_false( util_ping("does.not.exist")); - if (argc >= 2) - test_assert_false( util_ping( stringlist_iget( server_list , 1 ))); - - if (argc >= 3) - test_assert_false( util_ping( stringlist_iget( server_list , 2 ))); + if (argc > 1) { + stringlist_type * server_list = stringlist_alloc_from_split( argv[1] , " "); + int is ; + for (is = 0; is < stringlist_get_size( server_list ); is++) { + test_assert_true( util_ping( stringlist_iget( server_list , is ))); + } + } exit(0); } diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_realpath.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_realpath.c index c42adf6108..cd742c31bd 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/ert_util_realpath.c +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_realpath.c @@ -24,7 +24,7 @@ void test_path(const char * input , const char * expected) { char * rpath = util_alloc_realpath__( input ); - if (!test_string_equal( rpath , expected )) + if (!test_check_string_equal( rpath , expected )) test_error_exit("util_alloc_realpath__(%s) => %s expected:%s \n",input , rpath , expected); else printf("OK: %s -> %s \n",input , rpath); diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_relpath_test.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_relpath_test.c index 0eac93bf9a..f571fcfbb5 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/ert_util_relpath_test.c +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_relpath_test.c @@ -28,7 +28,7 @@ void test_path(int nr , const char * root , const char * path , const char * true_path) { char * rel_path = util_alloc_rel_path( root , path); - if (!test_string_equal( rel_path , true_path)) + if (!test_check_string_equal( rel_path , true_path)) test_error_exit("Case:%d rel_path(%s,%s) -> %s failed - expected: %s\n" , nr , root , path , rel_path , true_path); else printf("Case:%d OK \n",nr); diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_strcat_test.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_strcat_test.c index e022fc51d1..a3831dde94 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/ert_util_strcat_test.c +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_strcat_test.c @@ -26,7 +26,7 @@ void test_strcat(char * s1 , const char *s2 , const char * expected) { char * cat = util_strcat_realloc(s1 , s2 ); - if (test_string_equal( cat , expected )) + if (test_check_string_equal( cat , expected )) util_safe_free( cat ); else test_error_exit("util_strcat_realloc(%s,%s) Got:%s expected:%s \n",s1,s2,cat , expected); diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_type_vector_test.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_type_vector_test.c index 78649421f2..a3d44d5c3e 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/ert_util_type_vector_test.c +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_type_vector_test.c @@ -27,6 +27,19 @@ void assert_equal( bool equal ) { } +void test_div() { + int_vector_type * int_vector = int_vector_alloc( 0 , 100); + int_vector_iset( int_vector , 10 , 100 ); + int_vector_div( int_vector , 10 ); + { + int i; + for (i=0; i < int_vector_size( int_vector ); i++) + test_assert_int_equal( 10 , int_vector_iget( int_vector , i )); + } +} + + + int main(int argc , char ** argv) { int_vector_type * int_vector = int_vector_alloc( 0 , 99); @@ -99,6 +112,7 @@ int main(int argc , char ** argv) { int_vector_free( v1 ); int_vector_free( v2 ); } - + + test_div(); exit(0); } diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_vector_test.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_vector_test.c index 29a22eeffb..3ee8d0146a 100644 --- a/ThirdParty/Ert/devel/libert_util/tests/ert_util_vector_test.c +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_vector_test.c @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -70,10 +71,51 @@ void test_reverse() { +void test_sort() { + vector_type * v1 = vector_alloc_new(); + vector_type * v2 = vector_alloc_new(); + + vector_append_ref(v1 , "2"); + vector_append_ref(v2 , "2"); + + vector_append_ref(v1 , "0"); + vector_append_ref(v2 , "0"); + + vector_append_ref(v1 , "1"); + vector_append_ref(v2 , "1"); + + vector_append_ref(v1 , "4"); + vector_append_ref(v2 , "4"); + + vector_append_ref(v1 , "3"); + vector_append_ref(v2 , "3"); + + + { + int_vector_type * sort_map = vector_alloc_sort_perm( v1 , (vector_cmp_ftype *) util_strcmp_int ); + vector_sort( v2 , (vector_cmp_ftype *) util_strcmp_int); + + test_assert_int_equal( 1 , int_vector_iget( sort_map , 0 )); + test_assert_int_equal( 2 , int_vector_iget( sort_map , 1 )); + test_assert_int_equal( 0 , int_vector_iget( sort_map , 2 )); + test_assert_int_equal( 4 , int_vector_iget( sort_map , 3 )); + test_assert_int_equal( 3 , int_vector_iget( sort_map , 4 )); + + test_assert_string_equal( "0" , vector_iget(v2 , 0 )); + test_assert_string_equal( "1" , vector_iget(v2 , 1 )); + test_assert_string_equal( "2" , vector_iget(v2 , 2 )); + test_assert_string_equal( "3" , vector_iget(v2 , 3 )); + test_assert_string_equal( "4" , vector_iget(v2 , 4 )); + + int_vector_free( sort_map ); + } +} + int main(int argc , char ** argv) { test_iset( ); test_reverse( ); + test_sort( ); exit(0); } diff --git a/ThirdParty/Ert/devel/libert_util/tests/ert_util_work_area.c b/ThirdParty/Ert/devel/libert_util/tests/ert_util_work_area.c new file mode 100644 index 0000000000..5f257a70cd --- /dev/null +++ b/ThirdParty/Ert/devel/libert_util/tests/ert_util_work_area.c @@ -0,0 +1,124 @@ +/* + Copyright (C) 2012 Statoil ASA, Norway. + + The file 'ert_util_PATH_test.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 +#include +#include + +#include +#include + + +void test_get_cwd() { + test_work_area_type * work_area = test_work_area_alloc( "CWD-TEST", false); + char * cwd = util_alloc_cwd(); + test_assert_string_equal( cwd , test_work_area_get_cwd( work_area )); + free( cwd ); + test_work_area_free( work_area ); +} + + +void test_get_original_cwd() { + char * cwd = util_alloc_cwd(); + test_work_area_type * work_area = test_work_area_alloc( "CWD-ORG-TEST", false); + test_assert_string_equal( cwd , test_work_area_get_original_cwd( work_area )); + free( cwd ); + test_work_area_free( work_area ); +} + + + + +void create_test_area(const char * test_name , bool store) { + char * pre_cwd = util_alloc_cwd(); + test_work_area_type * work_area = test_work_area_alloc( test_name , store); + char * work_path = util_alloc_string_copy( test_work_area_get_cwd( work_area )); + + test_assert_true( util_is_directory( work_path )); + test_work_area_free( work_area ); + test_assert_bool_equal( store , util_entry_exists( work_path )); + + { + char * post_cwd = util_alloc_cwd(); + test_assert_string_equal( pre_cwd , post_cwd ); + free( post_cwd ); + } + free( pre_cwd ); + free( work_path ); +} + + +void test_install_file_exists(const char * filename ) { + char * abs_input_path = util_alloc_abs_path( filename ); + test_work_area_type * work_area = test_work_area_alloc( "FILE-TEST" , false); + + test_work_area_install_file( work_area , filename ); + test_assert_true( util_files_equal( abs_input_path , filename )); + test_work_area_free( work_area ); + free( abs_input_path ); +} + + +void test_copy_directory(const char * rel_path) { + test_work_area_type * work_area = test_work_area_alloc( "FILE-TEST" , false); + test_work_area_copy_directory( work_area , rel_path ); + test_assert_true( util_is_directory( rel_path )); + test_work_area_free( work_area ); +} + + +void test_input() { + test_work_area_type * work_area = test_work_area_alloc( NULL , false ); + test_assert_NULL( work_area ); +} + + + +void test_copy_file( const char * src_file ) { + char * filename = util_split_alloc_filename( src_file ); + test_work_area_type * work_area = test_work_area_alloc( "copy-file" , true ); + test_work_area_copy_file( work_area , src_file ); + + test_assert_true( util_file_exists( filename )); + + test_work_area_free( work_area ); + free( filename ); +} + + + +int main(int argc , char ** argv) { + const char * rel_path_file = argv[1]; + const char * abs_path_file = argv[2]; + const char * rel_directory = argv[3]; + + create_test_area("STORE-TEST" , true ); + create_test_area("DEL-TEST" , false); + test_install_file_exists( rel_path_file ); + test_install_file_exists( abs_path_file ); + test_copy_directory( rel_directory ); + test_input(); + test_get_cwd(); + test_get_original_cwd(); + + test_copy_file( rel_path_file ); + test_copy_file( abs_path_file ); + + exit(0); +} diff --git a/ThirdParty/Ert/devel/libgeometry/src/CMakeLists.txt b/ThirdParty/Ert/devel/libgeometry/src/CMakeLists.txt index cc1391ab09..8dc42c6d20 100644 --- a/ThirdParty/Ert/devel/libgeometry/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libgeometry/src/CMakeLists.txt @@ -4,6 +4,9 @@ set( header_files geo_surface.h geo_util.h geo_pointset.h geo_region.h geo_polyg add_library( ert_geometry ${LIBRARY_TYPE} ${source_files} ) set_target_properties( ert_geometry PROPERTIES VERSION 1.0 SOVERSION 1.0 ) target_link_libraries( ert_geometry ert_util ) +if (USE_RUNPATH) + add_runpath( ert_geometry ) +endif() #----------------------------------------------------------------- diff --git a/ThirdParty/Ert/devel/libgeometry/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libgeometry/tests/CMakeLists.txt index d263b1d252..fccc73ffaf 100644 --- a/ThirdParty/Ert/devel/libgeometry/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libgeometry/tests/CMakeLists.txt @@ -1,9 +1,9 @@ add_executable( geo_surface geo_surface.c ) -target_link_libraries( geo_surface ert_geometry ) +target_link_libraries( geo_surface ert_geometry test_util ) add_test( geo_surface ${EXECUTABLE_OUTPUT_PATH}/geo_surface ${PROJECT_SOURCE_DIR}/test-data/Statoil/Geometry/Surface.irap ${PROJECT_SOURCE_DIR}/test-data/Statoil/Geometry/Surface_incompatible.irap ) -set_property( TEST geo_surface PROPERTY LABELS Statoil ) +set_property( TEST geo_surface PROPERTY LABELS StatoilData ) diff --git a/ThirdParty/Ert/devel/libjob_queue/CMakeLists.txt b/ThirdParty/Ert/devel/libjob_queue/CMakeLists.txt index 159c0c64e8..31482517e7 100644 --- a/ThirdParty/Ert/devel/libjob_queue/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libjob_queue/CMakeLists.txt @@ -23,7 +23,7 @@ endif() add_subdirectory( src ) -if (BUILD_APPLICATONS) +if (BUILD_APPLICATIONS) add_subdirectory( applications ) endif() diff --git a/ThirdParty/Ert/devel/libjob_queue/applications/CMakeLists.txt b/ThirdParty/Ert/devel/libjob_queue/applications/CMakeLists.txt index c80e58df09..1358818a99 100644 --- a/ThirdParty/Ert/devel/libjob_queue/applications/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libjob_queue/applications/CMakeLists.txt @@ -1,2 +1,8 @@ add_executable( block_node block_node.c ) target_link_libraries( block_node job_queue ert_util) +if (USE_RUNPATH) + add_runpath( block_node ) +endif() + +set (destination ${CMAKE_INSTALL_PREFIX}/bin) +install(TARGETS block_node DESTINATION ${destination}) diff --git a/ThirdParty/Ert/devel/libjob_queue/applications/block_node.c b/ThirdParty/Ert/devel/libjob_queue/applications/block_node.c index 6056bea60a..32b26ab595 100644 --- a/ThirdParty/Ert/devel/libjob_queue/applications/block_node.c +++ b/ThirdParty/Ert/devel/libjob_queue/applications/block_node.c @@ -15,144 +15,191 @@ See the GNU General Public License at for more details. */ -#ifdef INCLUDE_LSF -#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include -#define BLOCK_COMMAND "/d/proj/bg/enkf/bin/block_node.py" +#include + +#define BLOCK_COMMAND "/project/res/bin/block-job" #define STATOIL_LSF_REQUEST "select[cs && x86_64Linux]" + +static lsf_driver_type * lsf_driver; +static vector_type * job_pool; +static hash_type * nodes; + + typedef struct { - struct submit lsf_request; - struct submitReply lsf_reply; - long int lsf_jobnr; - char * host_name; - const char * command; - bool running; - bool block_job; -} lsf_job_type; + lsf_job_type * lsf_job; + stringlist_type * hostlist; + bool running; + bool block_job; +} block_job_type; +typedef struct { + int target; + int current; +} count_pair_type; -lsf_job_type * lsf_job_alloc(char * queue_name) { - lsf_job_type * lsf_job = util_malloc( sizeof * lsf_job ); - - memset(&lsf_job->lsf_request , 0 , sizeof (lsf_job->lsf_request)); - lsf_job->lsf_request.queue = queue_name; - lsf_job->lsf_request.beginTime = 0; - lsf_job->lsf_request.termTime = 0; - lsf_job->lsf_request.numProcessors = 1; - lsf_job->lsf_request.maxNumProcessors = 1; - lsf_job->lsf_request.command = BLOCK_COMMAND; - lsf_job->lsf_request.outFile = "/tmp/lsf"; - lsf_job->lsf_request.jobName = "lsf"; - lsf_job->lsf_request.resReq = STATOIL_LSF_REQUEST; - { - int i; - for (i=0; i < LSF_RLIM_NLIMITS; i++) - lsf_job->lsf_request.rLimits[i] = DEFAULT_RLIMIT; - } - lsf_job->lsf_request.options2 = 0; - lsf_job->lsf_request.options = SUB_QUEUE + SUB_JOB_NAME + SUB_OUT_FILE + SUB_RES_REQ; - lsf_job->host_name = NULL; - lsf_job->running = false; - lsf_job->block_job = false; - return lsf_job; +count_pair_type * count_pair_alloc() { + count_pair_type * pair = util_malloc( sizeof * pair ); + pair->target = 0; + pair->current = 0; + return pair; } -void update_job_status( lsf_job_type * job , hash_type * nodes) { - if (!job->running) { - struct jobInfoEnt *job_info; - if (lsb_openjobinfo(job->lsf_jobnr , NULL , NULL , NULL , NULL , ALL_JOB) == 1) { - job_info = lsb_readjobinfo( NULL ); - lsb_closejobinfo(); - - if (job_info->status == JOB_STAT_RUN) { - job->running = true; - job->host_name = util_realloc_string_copy( job->host_name , job_info->exHosts[0]); /* Hardcoded only one node. */ - if (hash_has_key( nodes, job->host_name)) {/* This is one of the instances which should be left running. */ - job->block_job = true; - printf("Got a block on:%s \n",job->host_name); +block_job_type * block_job_alloc() { + block_job_type * job = util_malloc( sizeof * job ); + + job->lsf_job = NULL; + job->running = false; + job->block_job = false; + job->hostlist = stringlist_alloc_new(); + + return job; +} + + +void block_job_free( block_job_type * block_job ) { + stringlist_free( block_job->hostlist ); + if (block_job->lsf_job) + lsf_job_free( block_job->lsf_job ); + + free( block_job ); +} + + +const char * block_job_get_hostname( const block_job_type * block_job ) { + return stringlist_iget( block_job->hostlist , 0 ); +} + + + +void update_job_status( block_job_type * job ) { + if (!job->running) { + int lsf_status = lsf_driver_get_job_status_lsf( lsf_driver , job->lsf_job ); + if (lsf_status == JOB_STAT_RUN) { + lsf_job_export_hostnames( job->lsf_job , job->hostlist ); + { + int ihost; + for (ihost = 0; ihost < stringlist_get_size( job->hostlist ); ihost++) { + const char * host = stringlist_iget( job->hostlist , ihost ); + if (hash_has_key( nodes, host)) { /* This is one of the instances which should be left running. */ + count_pair_type * pair = hash_get( nodes , host); + if (pair->current < pair->target) { + pair->current += 1; + job->block_job = true; + } + } } } + job->running = true; } } } -void lsf_job_submit( lsf_job_type * job ) { - job->lsf_jobnr = lsb_submit( &job->lsf_request , &job->lsf_reply ); -} - - - - -void lsf_job_kill( lsf_job_type * job ) { - lsb_forcekilljob(job->lsf_jobnr); -} - - - -void lsf_job_free( lsf_job_type * job ) { - if (job->block_job) - printf("Node: %-16s blocked by job:%ld \n",job->host_name , job->lsf_jobnr); - else - lsf_job_kill( job ); - - util_safe_free( job->host_name ); - free( job ); -} - - -void lsf_job_free__( void * arg) { - lsf_job_free( (lsf_job_type * ) arg); -} - /*****************************************************************/ -void add_jobs(vector_type * job_pool , int chunk_size) { +void add_jobs( int chunk_size) { int i; + char * cwd = util_alloc_cwd(); for (i=0; i < chunk_size; i++) { - lsf_job_type * job = lsf_job_alloc("normal"); - vector_append_owned_ref( job_pool , job , lsf_job_free__); - lsf_job_submit( job ); + block_job_type * job = block_job_alloc(); + job->lsf_job = lsf_driver_submit_job(lsf_driver , BLOCK_COMMAND , 1 , cwd , "BLOCK" , 0 , NULL ); + vector_append_ref( job_pool , job ); } + free( cwd ); } -void update_pool_status(vector_type * job_pool , hash_type * block_nodes , int * blocked , int * pending) { +void update_pool_status( bool *all_blocked , int * pending) { int i; - int block_count = 0; - int pend_count = 0; + int pend_count = 0; + *all_blocked = true; + for (i=0; i < vector_get_size( job_pool ); i++) { - lsf_job_type * job = vector_iget( job_pool , i ); - update_job_status( job , block_nodes ); + block_job_type * job = vector_iget( job_pool , i ); + update_job_status( job ); + if (!job->running) pend_count++; - else { - if (job->block_job) - block_count++; + } + + { + hash_iter_type * iter = hash_iter_alloc( nodes ); + while (!hash_iter_is_complete( iter )) { + const char * hostname = hash_iter_get_next_key( iter ); + const count_pair_type * count = hash_get( nodes , hostname ); + if (count->current < count->target) + *all_blocked = false; } } - *blocked = block_count; *pending = pend_count; } +void print_status() { + int total_running = 0; + int total_pending = 0; + for (int i=0; i < vector_get_size( job_pool ); i++) { + block_job_type * job = vector_iget( job_pool , i ); + if (job->running) + total_running += 1; + else + total_pending += 1; + } + printf("Running:%3d Pending: %3d Blocks active: ",total_running , total_pending); + { + hash_iter_type * iter = hash_iter_alloc( nodes ); + while (!hash_iter_is_complete( iter )) { + const char * hostname = hash_iter_get_next_key( iter ); + const count_pair_type * count = hash_get( nodes , hostname ); + printf("%s %d/%d ",hostname , count->current , count->target); + } + printf("\n"); + hash_iter_free( iter ); + } +} + + +void block_node_exit( int signal ) { + int job_nr; + + print_status(); + for (job_nr = 0; job_nr < vector_get_size( job_pool ); job_nr++) { + block_job_type * job = vector_iget( job_pool , job_nr ); + + if (job->block_job) { + printf("Job:%ld is running on host: ", lsf_job_get_jobnr( job->lsf_job )); + stringlist_fprintf( job->hostlist , " " , stdout ); + printf("\n"); + } else + lsf_driver_kill_job( lsf_driver , job->lsf_job ); + + block_job_free( job ); + } + printf("Remember to kill these jobs when the BLOCK is no longer needed\n"); + if (signal != 0) + exit(0); +} int main( int argc, char ** argv) { @@ -160,78 +207,78 @@ int main( int argc, char ** argv) { util_exit("block_node node1 node2 node3:2 \n"); /* Initialize lsf environment */ - util_setenv__( "LSF_BINDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/bin" ); - util_setenv__( "LSF_LINDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/lib" ); - util_setenv__( "XLSF_UIDDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/lib/uid" ); - util_setenv__( "LSF_SERVERDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/etc"); - util_setenv__( "LSF_ENVDIR" , "/prog/LSF/conf"); + util_setenv( "LSF_BINDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/bin" ); + util_setenv( "LSF_LINDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/lib" ); + util_setenv( "XLSF_UIDDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/lib/uid" ); + util_setenv( "LSF_SERVERDIR" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/etc"); + util_setenv( "LSF_ENVDIR" , "/prog/LSF/conf"); util_update_path_var( "PATH" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/bin" , false); util_update_path_var( "LD_LIBRARY_PATH" , "/prog/LSF/8.0/linux2.6-glibc2.3-x86_64/lib" , false); - if (lsb_init(NULL) != 0) - util_abort("%s failed to initialize LSF environment : %s/%d \n",__func__ , lsb_sysmsg() , lsberrno); - util_setenv__("BSUB_QUIET" , "yes" ); - { - hash_type * nodes = hash_alloc(); - int node_count = 0; - int iarg; - printf("Attempting to block nodes \n"); - for (iarg = 1; iarg < argc; iarg++) { - char node_name[64]; - int num_slots; - if (sscanf(argv[iarg] , "%s:%d" , node_name , &num_slots) != 2) - num_slots = 1; + + lsf_driver = lsf_driver_alloc(); + if (lsf_driver_get_submit_method( lsf_driver ) != LSF_SUBMIT_INTERNAL) + util_exit("Sorry - the block_node program must be invoked on a proper LSF node \n"); - hash_insert_int( nodes , node_name , num_slots ); - node_count += num_slots; - - printf(" %s",node_name); - if (num_slots != 1) - printf(" * %d",num_slots ); - printf("\n"); - } - printf("-----------------------------------------------------------------\n"); + { + int iarg; + int total_blocked_target = 0; + nodes = hash_alloc(); + for (iarg = 1; iarg < argc; iarg++) { + char *node_name; + int num_slots; + + { + char * num_slots_string; + util_binary_split_string( argv[iarg] , ":" , true , &node_name , &num_slots_string); + if (num_slots_string) + util_sscanf_int( num_slots_string , &num_slots); + else + num_slots = 1; + } + + if (!hash_has_key( nodes , node_name)) + hash_insert_hash_owned_ref( nodes , node_name , count_pair_alloc() , free); + + { + count_pair_type * pair = hash_get( nodes , node_name); + pair->target += num_slots; + } + total_blocked_target += num_slots; + } + + signal(SIGINT , block_node_exit ); { const int sleep_time = 5; - const int max_attempt = 25; - const int chunk_size = 10; /* We submit this many at a time. */ - const int max_pool_size = 100; /* The absolute total maximum of jobs we will submit. */ + const int chunk_size = 10; /* We submit this many at a time. */ + const int max_pool_size = 1000; /* The absolute total maximum of jobs we will submit. */ - vector_type * job_pool = vector_alloc_new(); bool cont = true; int pending = 0; - int blocked; - int attempt = 0; + bool all_blocked; + job_pool = vector_alloc_new(); + while (cont) { - printf("Attempt: %2d/%2d ",attempt , max_attempt); fflush( stdout ); + printf("[Ctrl-C to give up] "); fflush( stdout ); + if (cont) sleep( sleep_time ); if (pending == 0) { if (vector_get_size( job_pool ) < max_pool_size) - add_jobs( job_pool , chunk_size ); + add_jobs( chunk_size ); } - update_pool_status( job_pool , nodes , &blocked , &pending); - if (blocked == node_count) - cont = false; /* Ok - we have got them all blocked - leave the building. */ + update_pool_status( &all_blocked , &pending); + print_status(); - attempt++; - if (attempt > max_attempt) + if (all_blocked) cont = false; - - if (cont) sleep( sleep_time ); - printf("\n"); } - if (blocked < node_count) + if (!all_blocked) printf("Sorry - failed to block all the nodes \n"); - vector_free( job_pool ); + block_node_exit( 0 ); hash_free( nodes ); } } } -#else -int main( int argc, char ** argv) { - return 0; -} -#endif diff --git a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/job_queue.h b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/job_queue.h index 4694c30649..6c670ef579 100644 --- a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/job_queue.h +++ b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/job_queue.h @@ -69,9 +69,7 @@ extern "C" { void * job_queue_run_jobs__(void * ); job_status_type job_queue_iget_job_status(const job_queue_type * , int ); const char * job_queue_status_name( job_status_type status ); - void job_queue_set_max_running( job_queue_type * queue , int max_running ); - int job_queue_inc_max_runnning( job_queue_type * queue, int delta ); - int job_queue_get_max_running( const job_queue_type * queue ); + int job_queue_iget_status_summary( const job_queue_type * queue , job_status_type status); time_t job_queue_iget_sim_start( job_queue_type * queue, int job_index); time_t job_queue_iget_submit_time( job_queue_type * queue, int job_index); diff --git a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/local_driver.h b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/local_driver.h index e172626aae..dbfcdc245e 100644 --- a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/local_driver.h +++ b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/local_driver.h @@ -42,6 +42,7 @@ extern "C" { void local_driver_free__(void * __driver ); job_status_type local_driver_get_job_status(void * __driver , void * __job); void local_driver_free_job(void * __job); + void local_driver_init_option_list(stringlist_type * option_list); diff --git a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/lsf_driver.h b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/lsf_driver.h index 5adf0c2b06..69f9fd7ac5 100644 --- a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/lsf_driver.h +++ b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/lsf_driver.h @@ -53,6 +53,9 @@ extern "C" { typedef struct lsf_driver_struct lsf_driver_type; typedef struct lsf_job_struct lsf_job_type; + void lsf_job_export_hostnames( const lsf_job_type * job , stringlist_type * hostlist); + void lsf_job_free(lsf_job_type * job); + long lsf_job_get_jobnr( const lsf_job_type * job ); void * lsf_driver_alloc( ); stringlist_type * lsf_driver_alloc_cmd(lsf_driver_type * driver , @@ -85,6 +88,9 @@ typedef struct lsf_job_struct lsf_job_type; bool lsf_driver_has_option( const void * __driver , const char * option_key); const void * lsf_driver_get_option( const void * __driver , const char * option_key); bool lsf_driver_set_option( void * __driver , const char * option_key , const void * value); + void lsf_driver_init_option_list(stringlist_type * option_list); + + UTIL_SAFE_CAST_HEADER( lsf_driver ); diff --git a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/queue_driver.h b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/queue_driver.h index e842668c9c..f99ab17254 100644 --- a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/queue_driver.h +++ b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/queue_driver.h @@ -40,7 +40,12 @@ extern "C" { {.value = 4 , .name = "TORQUE_DRIVER"} #define JOB_DRIVER_ENUM_SIZE 5 - + + /* + The options supported by the base queue_driver. + */ +#define MAX_RUNNING "MAX_RUNNING" + typedef enum { JOB_QUEUE_NOT_ACTIVE = 1, /* This value is used in external query routines - for jobs which are (currently) not active. */ //JOB_QUEUE_LOADING = 2 , /* This value is used by external routines. Not used in the libjob_queue implementation. */ @@ -116,7 +121,8 @@ extern "C" { typedef bool (set_option_ftype) (void *, const char*, const void *); typedef const void * (get_option_ftype) (const void *, const char *); typedef bool (has_option_ftype) (const void *, const char *); - + typedef void (init_option_list_ftype) (stringlist_type *); + queue_driver_type * queue_driver_alloc_RSH(const char * rsh_cmd, const hash_type * rsh_hostlist); queue_driver_type * queue_driver_alloc_LSF(const char * queue_name, const char * resource_request, const char * remote_lsf_server); @@ -128,13 +134,12 @@ extern "C" { void queue_driver_free_job(queue_driver_type * driver, void * job_data); void queue_driver_kill_job(queue_driver_type * driver, void * job_data); job_status_type queue_driver_get_status(queue_driver_type * driver, void * job_data); - - void queue_driver_set_max_running(queue_driver_type * driver, int max_running); - int queue_driver_get_max_running(const queue_driver_type * driver); + const char * queue_driver_get_name(const queue_driver_type * driver); bool queue_driver_set_option(queue_driver_type * driver, const char * option_key, const void * value); const void * queue_driver_get_option(queue_driver_type * driver, const char * option_key); + void queue_driver_init_option_list(queue_driver_type * driver, stringlist_type * option_list); void queue_driver_free(queue_driver_type * driver); void queue_driver_free__(void * driver); diff --git a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/rsh_driver.h b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/rsh_driver.h index ad7909ae13..7e41c4e768 100644 --- a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/rsh_driver.h +++ b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/rsh_driver.h @@ -49,6 +49,7 @@ extern "C" { bool rsh_driver_set_option( void * __driver, const char * option_key , const void * value ); const void * rsh_driver_get_option( const void * __driver , const char * option_key); + void rsh_driver_init_option_list(stringlist_type * option_list); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/torque_driver.h b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/torque_driver.h index 5f3db45f65..5df778021f 100644 --- a/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/torque_driver.h +++ b/ThirdParty/Ert/devel/libjob_queue/include/ert/job_queue/torque_driver.h @@ -65,9 +65,10 @@ extern "C" { const void * torque_driver_get_option(const void * __driver, const char * option_key); bool torque_driver_set_option(void * __driver, const char * option_key, const void * value); + void torque_driver_init_option_list(stringlist_type * option_list); void torque_job_create_submit_script(const char * run_path, const char * submit_cmd, int argc, const char ** job_argv); - + UTIL_SAFE_CAST_HEADER(torque_driver); #ifdef __cplusplus diff --git a/ThirdParty/Ert/devel/libjob_queue/src/CMakeLists.txt b/ThirdParty/Ert/devel/libjob_queue/src/CMakeLists.txt index 95984eef9e..85dafa3738 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libjob_queue/src/CMakeLists.txt @@ -2,6 +2,7 @@ set(source_files forward_model.c queue_driver.c job_queue.c local_driver.c rsh_driver.c torque_driver.c ext_job.c ext_joblist.c workflow_job.c workflow.c workflow_joblist.c) set(header_files job_queue.h queue_driver.h local_driver.h rsh_driver.h torque_driver.h ext_job.h ext_joblist.h forward_model.h workflow_job.h workflow.h workflow_joblist.h) +set_property(SOURCE rsh_driver.c PROPERTY COMPILE_FLAGS "-Wno-error") if (USE_LSF) list( APPEND source_files lsf_driver.c) @@ -16,6 +17,9 @@ endif() add_library( job_queue SHARED ${source_files} ) set_target_properties( job_queue PROPERTIES VERSION 1.0 SOVERSION 1.0 ) target_link_libraries( job_queue config ert_util ) +if (USE_RUNPATH) + add_runpath( job_queue ) +endif() if (NEED_LIBDL) target_link_libraries( job_queue dl ) diff --git a/ThirdParty/Ert/devel/libjob_queue/src/job_queue.c b/ThirdParty/Ert/devel/libjob_queue/src/job_queue.c index e9f4052104..97fbe5acc9 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/job_queue.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/job_queue.c @@ -1139,8 +1139,55 @@ static void job_queue_handle_EXIT( job_queue_type * queue , job_queue_node_type } +/*****************************************************************/ +int job_queue_get_max_running_option(queue_driver_type * driver) { + char * max_running_string = (char*)queue_driver_get_option(driver, MAX_RUNNING); + int max_running; + if (!util_sscanf_int(max_running_string, &max_running)) { + fprintf(stderr, "%s: Unable to parse option MAX_RUNNING with value %s to an int", __func__, max_running_string); + } + return max_running; +} + +void job_queue_set_max_running_option(queue_driver_type * driver, int max_running) { + char * max_running_string = util_alloc_sprintf("%d", max_running); + queue_driver_set_option(driver, MAX_RUNNING, max_running_string); + free(max_running_string); +} + + +/** + Observe that if the max number of running jobs is decreased, + nothing will be done to reduce the number of jobs currently + running; but no more jobs will be submitted until the number of + running has fallen below the new limit. + + The updated value will also be pushed down to the current driver. + NOTE: These next three *max_running functions should not be used, rather + use the set_option feature, with MAX_RUNNING. They are (maybe) used by python + therefore not removed. +*/ +int job_queue_get_max_running( const job_queue_type * queue ) { + return job_queue_get_max_running_option(queue->driver); +} + +void job_queue_set_max_running( job_queue_type * queue , int max_running ) { + job_queue_set_max_running_option(queue->driver, max_running); +} + +/* + The return value is the new value for max_running. +*/ +int job_queue_inc_max_runnning( job_queue_type * queue, int delta ) { + job_queue_set_max_running( queue , job_queue_get_max_running( queue ) + delta ); + return job_queue_get_max_running( queue ); +} + +/*****************************************************************/ + + /** If the total number of jobs is not known in advance the job_queue_run_jobs function can be called with @num_total_run == 0. In that case it is paramount @@ -1297,6 +1344,11 @@ void job_queue_run_jobs(job_queue_type * queue , int num_total_run, bool verbose thread_pool_join( queue->work_pool ); thread_pool_free( queue->work_pool ); } + /* + Observe that after the job_queue_finalize() function has been + called the queue object should not be queried on any longer; that + will silently give horribly wrong results. + */ job_queue_finalize( queue ); pthread_mutex_unlock( &queue->run_mutex ); } @@ -1519,34 +1571,6 @@ bool job_queue_has_driver(const job_queue_type * queue ) { } -/** - Observe that if the max number of running jobs is decreased, - nothing will be done to reduce the number of jobs currently - running; but no more jobs will be submitted until the number of - running has fallen below the new limit. - - The updated value will also be pushed down to the current driver. -*/ - -void job_queue_set_max_running( job_queue_type * queue , int max_running ) { - queue_driver_set_max_running( queue->driver , max_running ); -} - -/* - The return value is the new value for max_running. -*/ -int job_queue_inc_max_runnning( job_queue_type * queue, int delta ) { - job_queue_set_max_running( queue , job_queue_get_max_running( queue ) + delta ); - return job_queue_get_max_running( queue ); -} - -int job_queue_get_max_running( const job_queue_type * queue ) { - return queue_driver_get_max_running( queue->driver ); -} - - -/*****************************************************************/ - job_driver_type job_queue_lookup_driver_name( const char * driver_name ) { if (strcmp( driver_name , "LOCAL") == 0) diff --git a/ThirdParty/Ert/devel/libjob_queue/src/local_driver.c b/ThirdParty/Ert/devel/libjob_queue/src/local_driver.c index d12872dda9..2d57a2c914 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/local_driver.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/local_driver.c @@ -199,6 +199,10 @@ bool local_driver_set_option( void * __driver , const char * option_key , const return false; } +void local_driver_init_option_list(stringlist_type * option_list) { + //No options specific for local driver; do nothing +} + #undef LOCAL_DRIVER_ID #undef LOCAL_JOB_ID diff --git a/ThirdParty/Ert/devel/libjob_queue/src/lsb.c b/ThirdParty/Ert/devel/libjob_queue/src/lsb.c index 13dadd89bc..6702eeaa3e 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/lsb.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/lsb.c @@ -153,7 +153,6 @@ int lsb_initialize( const lsb_type * lsb) { directory containing LSF configuration information, the whole thing will crash and burn if this is not properly set. */ - printf("Calling initialize ... \n"); if ( lsb->lsb_init(NULL) != 0 ) { fprintf(stderr,"LSF_ENVDIR: "); if (getenv("LSF_ENVDIR") != NULL) diff --git a/ThirdParty/Ert/devel/libjob_queue/src/lsf_driver.c b/ThirdParty/Ert/devel/libjob_queue/src/lsf_driver.c index 642ececf25..36265836e6 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/lsf_driver.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/lsf_driver.c @@ -181,6 +181,20 @@ void lsf_job_free(lsf_job_type * job) { } +void lsf_job_export_hostnames( const lsf_job_type * job , stringlist_type * hostlist) { + int host_nr; + + stringlist_clear( hostlist ); + for (host_nr = 0; host_nr < job->num_exec_host; host_nr++) + stringlist_append_copy( hostlist , job->exec_host[ host_nr ]); +} + + +long lsf_job_get_jobnr( const lsf_job_type * job ) { + return job->lsf_jobnr; +} + + static int lsf_job_parse_bsub_stdout(const lsf_driver_type * driver , const char * stdout_file) { int jobid = -1; FILE * stream = util_fopen(stdout_file , "r"); @@ -859,6 +873,16 @@ bool lsf_driver_has_option( const void * __driver , const char * option_key) { return false; } +void lsf_driver_init_option_list(stringlist_type * option_list) { + stringlist_append_ref(option_list, LSF_QUEUE); + stringlist_append_ref(option_list, LSF_RESOURCE); + stringlist_append_ref(option_list, LSF_SERVER); + stringlist_append_ref(option_list, LSF_RSH_CMD); + stringlist_append_ref(option_list, LSF_LOGIN_SHELL); + stringlist_append_ref(option_list, LSF_BSUB_CMD); + stringlist_append_ref(option_list, LSF_BJOBS_CMD); + stringlist_append_ref(option_list, LSF_BKILL_CMD); +} diff --git a/ThirdParty/Ert/devel/libjob_queue/src/queue_driver.c b/ThirdParty/Ert/devel/libjob_queue/src/queue_driver.c index 507130e6eb..be68d3f475 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/queue_driver.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/queue_driver.c @@ -69,6 +69,7 @@ struct queue_driver_struct { set_option_ftype * set_option; get_option_ftype * get_option; has_option_ftype * has_option; + init_option_list_ftype * init_options; void * data; /* Driver specific data - passed as first argument to the driver functions above. */ @@ -77,6 +78,7 @@ struct queue_driver_struct { */ char * name; /* String name of driver. */ job_driver_type driver_type; /* Enum value for driver. */ + char * max_running_string; int max_running; /* Possible to maintain different max_running values for different drivers; the value 0 is interpreted as no limit - i.e. the queue layer will (try) to send an unlimited number of jobs to the driver. */ @@ -108,6 +110,8 @@ static queue_driver_type * queue_driver_alloc_empty() { driver->has_option = NULL; driver->name = NULL; driver->data = NULL; + driver->max_running_string = NULL; + driver->init_options = NULL; return driver; } @@ -137,6 +141,7 @@ queue_driver_type * queue_driver_alloc(job_driver_type type) { driver->get_option = lsf_driver_get_option; driver->has_option = lsf_driver_has_option; driver->name = util_alloc_string_copy("LSF"); + driver->init_options = lsf_driver_init_option_list; driver->data = lsf_driver_alloc(); break; case LOCAL_DRIVER: @@ -146,6 +151,7 @@ queue_driver_type * queue_driver_alloc(job_driver_type type) { driver->free_job = local_driver_free_job; driver->free_driver = local_driver_free__; driver->name = util_alloc_string_copy("local"); + driver->init_options = local_driver_init_option_list; driver->data = local_driver_alloc(); break; case RSH_DRIVER: @@ -157,6 +163,7 @@ queue_driver_type * queue_driver_alloc(job_driver_type type) { driver->set_option = rsh_driver_set_option; driver->get_option = rsh_driver_get_option; driver->name = util_alloc_string_copy("RSH"); + driver->init_options = rsh_driver_init_option_list; driver->data = rsh_driver_alloc(); break; case TORQUE_DRIVER: @@ -168,32 +175,85 @@ queue_driver_type * queue_driver_alloc(job_driver_type type) { driver->set_option = torque_driver_set_option; driver->get_option = torque_driver_get_option; driver->name = util_alloc_string_copy("TORQUE"); + driver->init_options = torque_driver_init_option_list; driver->data = torque_driver_alloc(); break; default: - util_abort("%s: unrecognized driver type:%d \n", type); + util_abort("%s: unrecognized driver type:%d \n", __func__, type); } return driver; } /*****************************************************************/ + +/*****************************************************************/ + +void queue_driver_set_max_running(queue_driver_type * driver, int max_running) { + driver->max_running_string = util_realloc_sprintf(driver->max_running_string,"%d", max_running); + driver->max_running = max_running; +} + +int queue_driver_get_max_running(const queue_driver_type * driver) { + return driver->max_running; +} + +const char * queue_driver_get_name(const queue_driver_type * driver) { + return driver->name; +} + + +/*****************************************************************/ + + +static bool queue_driver_set_generic_option__(queue_driver_type * driver, const char * option_key, const void * value) { + bool option_set = true; + { + if (strcmp(MAX_RUNNING, option_key) == 0) { + int max_running_int = 0; + if (util_sscanf_int(value, &max_running_int)) { + queue_driver_set_max_running(driver, max_running_int); + option_set = true; + } + else + option_set = false; + } else + option_set = false; + } + return option_set; +} + +static void * queue_driver_get_generic_option__(queue_driver_type * driver, const char * option_key) { + if (strcmp(MAX_RUNNING, option_key) == 0) { + return driver->max_running_string; + } else { + util_abort("%s: driver:%s does not support generic option %s\n", __func__, driver->name, option_key); + return NULL; + } +} + +static bool queue_driver_has_generic_option__(queue_driver_type * driver, const char * option_key) { + if (strcmp(MAX_RUNNING, option_key) == 0) + return true; + else + return false; +} + /** Set option - can also be used to perform actions - not only setting of parameters. There is no limit :-) */ bool queue_driver_set_option(queue_driver_type * driver, const char * option_key, const void * value) { - if (driver->set_option != NULL) + if (queue_driver_set_generic_option__(driver, option_key, value)) { + return true; + } else if (driver->set_option != NULL) /* The actual low level set functions can not fail! */ return driver->set_option(driver->data, option_key, value); else { util_abort("%s: driver:%s does not support run time setting of options\n", __func__, driver->name); return false; } -} - -bool queue_driver_set_string_option(queue_driver_type * driver, const char * option_key, const char * value) { - return queue_driver_set_option(driver, option_key, value); + return false; } /*****************************************************************/ @@ -208,17 +268,31 @@ bool queue_driver_has_option(queue_driver_type * driver, const char * option_key /*****************************************************************/ const void * queue_driver_get_option(queue_driver_type * driver, const char * option_key) { - if (driver->get_option != NULL) + if (queue_driver_has_generic_option__(driver, option_key)) { + return queue_driver_get_generic_option__(driver, option_key); + } else if (driver->get_option != NULL) /* The actual low level set functions can not fail! */ return driver->get_option(driver->data, option_key); else { util_abort("%s: driver:%s does not support run time reading of options\n", __func__, driver->name); return NULL; } + return NULL; } /*****************************************************************/ +void queue_driver_init_option_list(queue_driver_type * driver, stringlist_type * option_list) { + //Add options common for all driver types + stringlist_append_ref(option_list, MAX_RUNNING); + + //Add options for the specific driver type + if (driver->init_options) + driver->init_options(option_list); + else + util_abort("%s: driver:%s does not support run time reading of options\n", __func__, driver->name); + } + queue_driver_type * queue_driver_alloc_LSF(const char * queue_name, const char * resource_request, const char * remote_lsf_server) { queue_driver_type * driver = queue_driver_alloc(LSF_DRIVER); @@ -252,23 +326,6 @@ queue_driver_type * queue_driver_alloc_local() { return driver; } -/*****************************************************************/ - -void queue_driver_set_max_running(queue_driver_type * driver, int max_running) { - driver->max_running = max_running; -} - -int queue_driver_get_max_running(const queue_driver_type * driver) { - return driver->max_running; -} - -const char * queue_driver_get_name(const queue_driver_type * driver) { - return driver->name; -} - - -/*****************************************************************/ - /* These are the functions used by the job_queue layer. */ void * queue_driver_submit_job(queue_driver_type * driver, const char * run_cmd, int num_cpu, const char * run_path, const char * job_name, int argc, const char ** argv) { @@ -297,6 +354,7 @@ void queue_driver_free_driver(queue_driver_type * driver) { void queue_driver_free(queue_driver_type * driver) { queue_driver_free_driver(driver); util_safe_free(driver->name); + util_safe_free(driver->max_running_string); free(driver); } diff --git a/ThirdParty/Ert/devel/libjob_queue/src/rsh_driver.c b/ThirdParty/Ert/devel/libjob_queue/src/rsh_driver.c index 871466d6d8..ee916b8380 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/rsh_driver.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/rsh_driver.c @@ -465,6 +465,12 @@ const void * rsh_driver_get_option( const void * __driver , const char * option_ } +void rsh_driver_init_option_list(stringlist_type * option_list) { + stringlist_append_ref(option_list, RSH_HOST); + stringlist_append_ref(option_list, RSH_HOSTLIST); + stringlist_append_ref(option_list, RSH_CMD); + stringlist_append_ref(option_list, RSH_CLEAR_HOSTLIST); +} #undef RSH_JOB_ID diff --git a/ThirdParty/Ert/devel/libjob_queue/src/torque_driver.c b/ThirdParty/Ert/devel/libjob_queue/src/torque_driver.c index 19f01caec7..00bfafbf27 100644 --- a/ThirdParty/Ert/devel/libjob_queue/src/torque_driver.c +++ b/ThirdParty/Ert/devel/libjob_queue/src/torque_driver.c @@ -169,6 +169,16 @@ const void * torque_driver_get_option(const void * __driver, const char * option } } +void torque_driver_init_option_list(stringlist_type * option_list) { + stringlist_append_ref(option_list, TORQUE_QSUB_CMD); + stringlist_append_ref(option_list, TORQUE_QSTAT_CMD); + stringlist_append_ref(option_list, TORQUE_QDEL_CMD); + stringlist_append_ref(option_list, TORQUE_QUEUE); + stringlist_append_ref(option_list, TORQUE_NUM_CPUS_PER_NODE); + stringlist_append_ref(option_list, TORQUE_NUM_NODES); + stringlist_append_ref(option_list, TORQUE_KEEP_QSUB_OUTPUT); +} + torque_job_type * torque_job_alloc() { torque_job_type * job; job = util_malloc(sizeof * job); diff --git a/ThirdParty/Ert/devel/libjob_queue/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libjob_queue/tests/CMakeLists.txt index 53c960f96b..7612e1aec7 100644 --- a/ThirdParty/Ert/devel/libjob_queue/tests/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libjob_queue/tests/CMakeLists.txt @@ -4,10 +4,10 @@ add_executable( "create file" create_file.c ) add_executable( job_workflow_test job_workflow_test.c ) -target_link_libraries( job_workflow_test job_queue ) -target_link_libraries( "create file" job_queue ) -target_link_libraries( job_loadOK job_queue ) -target_link_libraries( job_loadFail job_queue ) +target_link_libraries( job_workflow_test job_queue test_util ) +target_link_libraries( "create file" job_queue test_util ) +target_link_libraries( job_loadOK job_queue test_util ) +target_link_libraries( job_loadFail job_queue test_util ) add_test( job_workflow_test ${EXECUTABLE_OUTPUT_PATH}/job_workflow_test ${EXECUTABLE_OUTPUT_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/data/internal_job) @@ -22,7 +22,7 @@ add_test( job_loadFail3 ${EXECUTABLE_OUTPUT_PATH}/job_loadFail ${CMAKE_CURRENT_S add_executable( job_queue_test job_queue_test.c ) -target_link_libraries( job_queue_test job_queue ) +target_link_libraries( job_queue_test job_queue test_util ) add_test( job_queue_test ${EXECUTABLE_OUTPUT_PATH}/job_queue_test ) @@ -37,16 +37,16 @@ set(LSF_SERVERS "LOCAL" CACHE STRING "List of LSF servers for testing") add_executable( job_lsf_test job_lsf_test.c ) -target_link_libraries( job_lsf_test job_queue util ) +target_link_libraries( job_lsf_test job_queue util test_util ) add_executable( job_lsf_submit_test job_lsf_submit_test.c ) -target_link_libraries( job_lsf_submit_test job_queue util ) +target_link_libraries( job_lsf_submit_test job_queue util test_util ) add_executable( job_program job_program.c ) if (HAVE_LSF_LIBRARY) add_executable( job_lsb job_lsb.c ) - target_link_libraries( job_lsb job_queue util ) + target_link_libraries( job_lsb job_queue util test_util ) add_test( job_lsb ${EXECUTABLE_OUTPUT_PATH}/job_lsb ) endif() @@ -58,11 +58,11 @@ if (LSF_SERVERS) endif() add_executable( job_torque_test job_torque_test.c ) -target_link_libraries( job_torque_test job_queue util ) +target_link_libraries( job_torque_test job_queue util test_util ) add_test( job_torque_test ${EXECUTABLE_OUTPUT_PATH}/job_torque_test ) add_executable( job_torque_submit_test job_torque_submit_test.c ) -target_link_libraries( job_torque_submit_test job_queue util ) +target_link_libraries( job_torque_submit_test job_queue util test_util ) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data/qsub_emulators/ DESTINATION ${EXECUTABLE_OUTPUT_PATH}) add_test(NAME job_torque_submit_test WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} COMMAND ${EXECUTABLE_OUTPUT_PATH}/job_torque_submit_test dummyparam) set_property(TEST job_torque_submit_test PROPERTY ENVIRONMENT “setenv PATH ${EXECUTABLE_OUTPUT_PATH}:$PATH”) diff --git a/ThirdParty/Ert/devel/libjob_queue/tests/job_lsf_submit_test.c b/ThirdParty/Ert/devel/libjob_queue/tests/job_lsf_submit_test.c index 42ce02fcbe..f93160388a 100644 --- a/ThirdParty/Ert/devel/libjob_queue/tests/job_lsf_submit_test.c +++ b/ThirdParty/Ert/devel/libjob_queue/tests/job_lsf_submit_test.c @@ -64,7 +64,6 @@ void test_submit(lsf_driver_type * driver , const char * server , const char * b free( run_path ); } - printf("Submit:%s OK \n",server); } diff --git a/ThirdParty/Ert/devel/libjob_queue/tests/job_queue_test.c b/ThirdParty/Ert/devel/libjob_queue/tests/job_queue_test.c index 1a7361eb68..d3de35cda7 100644 --- a/ThirdParty/Ert/devel/libjob_queue/tests/job_queue_test.c +++ b/ThirdParty/Ert/devel/libjob_queue/tests/job_queue_test.c @@ -14,7 +14,7 @@ See the GNU General Public License at for more details. -*/ + */ #include #include @@ -27,18 +27,142 @@ #include #include +#include "ert/job_queue/torque_driver.h" +#include void job_queue_set_driver_(job_driver_type driver_type) { - job_queue_type * queue = job_queue_alloc( 10 , "OK" , "ERROR"); - queue_driver_type * driver = queue_driver_alloc( driver_type ); - test_assert_false( job_queue_has_driver( queue )); - - job_queue_set_driver( queue , driver ); - test_assert_true( job_queue_has_driver( queue )); + job_queue_type * queue = job_queue_alloc(10, "OK", "ERROR"); + queue_driver_type * driver = queue_driver_alloc(driver_type); + test_assert_false(job_queue_has_driver(queue)); + + job_queue_set_driver(queue, driver); + test_assert_true(job_queue_has_driver(queue)); + + job_queue_free(queue); + queue_driver_free(driver); + } -int main( int argc , char ** argv) { +void set_option_max_running_max_running_value_set() { + queue_driver_type * driver_torque = queue_driver_alloc(TORQUE_DRIVER); + test_assert_true(queue_driver_set_option(driver_torque, MAX_RUNNING, "42")); + test_assert_string_equal("42", queue_driver_get_option(driver_torque, MAX_RUNNING)); + queue_driver_free(driver_torque); + + + queue_driver_type * driver_lsf = queue_driver_alloc(LSF_DRIVER); + test_assert_true(queue_driver_set_option(driver_lsf, MAX_RUNNING, "72")); + test_assert_string_equal("72", queue_driver_get_option(driver_lsf, MAX_RUNNING)); + queue_driver_free(driver_lsf); +} + +void set_option_max_running_max_running_option_set() { + queue_driver_type * driver_torque = queue_driver_alloc(TORQUE_DRIVER); + test_assert_true(queue_driver_set_option(driver_torque, MAX_RUNNING, "42")); + test_assert_string_equal("42", queue_driver_get_option(driver_torque, MAX_RUNNING)); + queue_driver_free(driver_torque); + +} + +void set_option_invalid_option_returns_false() { + queue_driver_type * driver_torque = queue_driver_alloc(TORQUE_DRIVER); + test_assert_false(queue_driver_set_option(driver_torque, "MAKS_RUNNING", "42")); + queue_driver_free(driver_torque); +} + +void set_option_invalid_value_returns_false() { + queue_driver_type * driver_torque = queue_driver_alloc(TORQUE_DRIVER); + test_assert_false(queue_driver_set_option(driver_torque, "MAX_RUNNING", "2a")); + queue_driver_free(driver_torque); +} + +void set_option_valid_on_specific_driver_returns_true() { + queue_driver_type * driver_torque = queue_driver_alloc(TORQUE_DRIVER); + test_assert_true(queue_driver_set_option(driver_torque, TORQUE_NUM_CPUS_PER_NODE, "33")); + test_assert_string_equal("33", queue_driver_get_option(driver_torque, TORQUE_NUM_CPUS_PER_NODE)); + queue_driver_free(driver_torque); +} + +void get_driver_option_lists() { + //Torque driver option list + { + queue_driver_type * driver_torque = queue_driver_alloc(TORQUE_DRIVER); + stringlist_type * option_list = stringlist_alloc_new(); + queue_driver_init_option_list(driver_torque, option_list); + + test_assert_true(stringlist_contains(option_list, MAX_RUNNING)); + test_assert_true(stringlist_contains(option_list, TORQUE_QSUB_CMD)); + test_assert_true(stringlist_contains(option_list, TORQUE_QSTAT_CMD)); + test_assert_true(stringlist_contains(option_list, TORQUE_QDEL_CMD)); + test_assert_true(stringlist_contains(option_list, TORQUE_QUEUE)); + test_assert_true(stringlist_contains(option_list, TORQUE_NUM_CPUS_PER_NODE)); + test_assert_true(stringlist_contains(option_list, TORQUE_NUM_NODES)); + test_assert_true(stringlist_contains(option_list, TORQUE_KEEP_QSUB_OUTPUT)); + + stringlist_free(option_list); + queue_driver_free(driver_torque); + } + + //Local driver option list (only general queue_driver options) + { + queue_driver_type * driver_local = queue_driver_alloc(LOCAL_DRIVER); + stringlist_type * option_list = stringlist_alloc_new(); + queue_driver_init_option_list(driver_local, option_list); + + test_assert_true(stringlist_contains(option_list, MAX_RUNNING)); + + stringlist_free(option_list); + queue_driver_free(driver_local); + } + + //Lsf driver option list + { + queue_driver_type * driver_lsf = queue_driver_alloc(LSF_DRIVER); + stringlist_type * option_list = stringlist_alloc_new(); + queue_driver_init_option_list(driver_lsf, option_list); + + test_assert_true(stringlist_contains(option_list, MAX_RUNNING)); + test_assert_true(stringlist_contains(option_list, LSF_QUEUE)); + test_assert_true(stringlist_contains(option_list, LSF_RESOURCE)); + test_assert_true(stringlist_contains(option_list, LSF_SERVER)); + test_assert_true(stringlist_contains(option_list, LSF_RSH_CMD)); + test_assert_true(stringlist_contains(option_list, LSF_LOGIN_SHELL)); + test_assert_true(stringlist_contains(option_list, LSF_BSUB_CMD)); + test_assert_true(stringlist_contains(option_list, LSF_BJOBS_CMD)); + test_assert_true(stringlist_contains(option_list, LSF_BKILL_CMD)); + + stringlist_free(option_list); + queue_driver_free(driver_lsf); + } + + //Rsh driver option list + { + queue_driver_type * driver_rsh = queue_driver_alloc(RSH_DRIVER); + stringlist_type * option_list = stringlist_alloc_new(); + queue_driver_init_option_list(driver_rsh, option_list); + + test_assert_true(stringlist_contains(option_list, MAX_RUNNING)); + test_assert_true(stringlist_contains(option_list, RSH_HOST)); + test_assert_true(stringlist_contains(option_list, RSH_HOSTLIST)); + test_assert_true(stringlist_contains(option_list, RSH_CMD)); + test_assert_true(stringlist_contains(option_list, RSH_CLEAR_HOSTLIST)); + + stringlist_free(option_list); + queue_driver_free(driver_rsh); + } +} + +int main(int argc, char ** argv) { job_queue_set_driver_(LSF_DRIVER); job_queue_set_driver_(TORQUE_DRIVER); + + set_option_max_running_max_running_value_set(); + set_option_max_running_max_running_option_set(); + set_option_invalid_option_returns_false(); + set_option_invalid_value_returns_false(); + + set_option_valid_on_specific_driver_returns_true(); + get_driver_option_lists(); + exit(0); } diff --git a/ThirdParty/Ert/devel/libjob_queue/tests/job_torque_submit_test.c b/ThirdParty/Ert/devel/libjob_queue/tests/job_torque_submit_test.c index 7c06fada7b..7007b8c2b6 100644 --- a/ThirdParty/Ert/devel/libjob_queue/tests/job_torque_submit_test.c +++ b/ThirdParty/Ert/devel/libjob_queue/tests/job_torque_submit_test.c @@ -35,8 +35,8 @@ void test_submit(torque_driver_type * driver, const char * cmd) { } torque_driver_kill_job(driver, job); - printf("Waiting 5 seconds"); - for (int i = 0; i < 5; i++) { + printf("Waiting 2 seconds"); + for (int i = 0; i < 2; i++) { printf("."); fflush(stdout); sleep(1); diff --git a/ThirdParty/Ert/devel/libjob_queue/tests/job_torque_test.c b/ThirdParty/Ert/devel/libjob_queue/tests/job_torque_test.c index 15340b4e65..3f4ffe6aea 100644 --- a/ThirdParty/Ert/devel/libjob_queue/tests/job_torque_test.c +++ b/ThirdParty/Ert/devel/libjob_queue/tests/job_torque_test.c @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -71,34 +72,43 @@ void getoption_nooptionsset_defaultoptionsreturned() { } void create_submit_script_script_according_to_input() { - char ** args = util_calloc(2, sizeof * args); - args[0] = "/tmp/jaja/"; - args[1] = "number2arg"; - char * script_filename = util_alloc_filename("/tmp/", "qsub_script", "sh"); - torque_job_create_submit_script(script_filename, "job_program.py", 2, (const char **) args); - printf("Create submit script OK\n"); + test_work_area_type * work_area = test_work_area_alloc("job_torque_test" , true); + const char * script_filename = "qsub_script.sh"; - FILE* file_stream = util_fopen(script_filename, "r"); - bool at_eof = false; + { + char ** args = util_calloc(2, sizeof * args); + args[0] = "/tmp/jaja/"; + args[1] = "number2arg"; + torque_job_create_submit_script(script_filename, "job_program.py", 2, (const char **) args); + free( args ); + } + + { + FILE* file_stream = util_fopen(script_filename, "r"); + bool at_eof = false; + + char * line = util_fscanf_alloc_line(file_stream, &at_eof); + test_assert_string_equal("#!/bin/sh", line); + free(line); - char * line = util_fscanf_alloc_line(file_stream, &at_eof); - test_assert_string_equal("#!/bin/sh", line); - free(line); + line = util_fscanf_alloc_line(file_stream, &at_eof); + test_assert_string_equal("job_program.py /tmp/jaja/ number2arg", line); + free(line); - line = util_fscanf_alloc_line(file_stream, &at_eof); - test_assert_string_equal("job_program.py /tmp/jaja/ number2arg", line); - free(line); + line = util_fscanf_alloc_line(file_stream, &at_eof); + free(line); + test_assert_true(at_eof); - line = util_fscanf_alloc_line(file_stream, &at_eof); - free(line); - test_assert_true(at_eof); - - fclose(file_stream); + fclose(file_stream); + } + test_work_area_free( work_area ); } + int main(int argc, char ** argv) { getoption_nooptionsset_defaultoptionsreturned(); setoption_setalloptions_optionsset(); + setoption_set_typed_options_wrong_format_returns_false(); create_submit_script_script_according_to_input(); exit(0); diff --git a/ThirdParty/Ert/devel/libjob_queue/tests/job_workflow_test.c b/ThirdParty/Ert/devel/libjob_queue/tests/job_workflow_test.c index 7ee25a005a..00e9bb5678 100644 --- a/ThirdParty/Ert/devel/libjob_queue/tests/job_workflow_test.c +++ b/ThirdParty/Ert/devel/libjob_queue/tests/job_workflow_test.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -78,12 +79,11 @@ static void create_exjob( const char * workflow , const char * bin_path) int main( int argc , char ** argv) { -#ifdef ERT_LINUX - const char * exjob_file = "/tmp/xflow"; -#endif - + const char * exjob_file = "job"; const char * bin_path = argv[1]; const char * internal_workflow = argv[2]; + test_work_area_type * work_area = test_work_area_alloc( "job_workflow_test" , true); + signal(SIGSEGV , util_abort_signal); create_exjob( exjob_file , bin_path ); { @@ -113,8 +113,8 @@ int main( int argc , char ** argv) { { - const char * workflow_file = "/tmp/workflow"; - const char * tmp_file = "/tmp/fileX"; + const char * workflow_file = "workflow"; + const char * tmp_file = "fileX"; workflow_type * workflow; create_workflow( workflow_file , tmp_file , int_value ); @@ -161,8 +161,8 @@ int main( int argc , char ** argv) { } { workflow_joblist_type * joblist = workflow_joblist_alloc(); - const char * workflow_file = "/tmp/workflow"; - const char * tmp_file = "/tmp/fileX"; + const char * workflow_file = "workflow"; + const char * tmp_file = "fileX"; int read_value; int int_value = 100; workflow_type * workflow; @@ -174,5 +174,6 @@ int main( int argc , char ** argv) { test_assert_false( workflow_run( workflow , &read_value , false , NULL) ); test_assert_int_equal( workflow_get_stack_size( workflow ) , 0 ); } + test_work_area_free( work_area ); exit(0); } diff --git a/ThirdParty/Ert/devel/libplot/src/CMakeLists.txt b/ThirdParty/Ert/devel/libplot/src/CMakeLists.txt index cfa0e164a5..993fe20327 100644 --- a/ThirdParty/Ert/devel/libplot/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libplot/src/CMakeLists.txt @@ -6,6 +6,9 @@ add_library( plot ${LIBRARY_TYPE} ${source_files} ) target_link_libraries( plot ert_util ${PLPLOT_LIBRARY} ) set_target_properties( plot PROPERTIES VERSION 1.0 SOVERSION 1.0 ) +if (USE_RUNPATH) + add_runpath( plot ) +endif() #----------------------------------------------------------------- if (INSTALL_ERT) install(TARGETS plot DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/ThirdParty/Ert/devel/librms/applications/CMakeLists.txt b/ThirdParty/Ert/devel/librms/applications/CMakeLists.txt index 8ed1bafa79..4f360d8506 100644 --- a/ThirdParty/Ert/devel/librms/applications/CMakeLists.txt +++ b/ThirdParty/Ert/devel/librms/applications/CMakeLists.txt @@ -8,6 +8,10 @@ add_executable( tag_list tag_list.c ) set(program_list rms_extract rms_setname rms_stat rms_test tag_list) foreach(prog ${program_list}) target_link_libraries( ${prog} rms ecl util ) + if (USE_RUNPATH) + add_runpath( ${prog} ) + endif() + #----------------------------------------------------------------- if (RMS_INSTALL_PREFIX) set (destination ${RMS_INSTALL_PREFIX}/bin) diff --git a/ThirdParty/Ert/devel/librms/src/CMakeLists.txt b/ThirdParty/Ert/devel/librms/src/CMakeLists.txt index bba790f2d5..fd90066a09 100644 --- a/ThirdParty/Ert/devel/librms/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/librms/src/CMakeLists.txt @@ -3,6 +3,9 @@ set( header_files rms_file.h rms_util.h rms_tag.h rms_type.h rms_tagkey.h rms_st add_library( rms ${LIBRARY_TYPE} ${source_files} ) set_target_properties( rms PROPERTIES VERSION 1.0 SOVERSION 1.0 ) +if (USE_RUNPATH) + add_runpath( rms ) +endif() #----------------------------------------------------------------- if (INSTALL_ERT) diff --git a/ThirdParty/Ert/devel/librms/src/makefile b/ThirdParty/Ert/devel/librms/src/makefile deleted file mode 100644 index 79b8e2f27f..0000000000 --- a/ThirdParty/Ert/devel/librms/src/makefile +++ /dev/null @@ -1,74 +0,0 @@ -include global_config -SDP_ROOT = $(shell get_sdp_root.py) -################################################################# -COMPILE_INCLUDE = -I$(LIBRMS_HOME)/src -I$(LIBECL_HOME)/include -I$(LIBUTIL_HOME)/include -INSTALL_INC_PATH = $(LIBRMS_HOME)/include -INSTALL_LIB_PATH = $(LIBRMS_HOME)/lib -################################################################# -OBJECTS = rms_file.o rms_util.o rms_tag.o rms_type.o rms_tagkey.o rms_stats.o rms_export.o -INC_FILES = rms_file.h rms_util.h rms_tag.h rms_type.h rms_tagkey.h rms_stats.h rms_export.h -LIB = librms.a - - -LOCAL: LIB - install -d $(INSTALL_INC_PATH) - install -d $(INSTALL_LIB_PATH) - install $(INC_FILES) $(INSTALL_INC_PATH) - install $(LIB) $(INSTALL_LIB_PATH) - -SDP_INSTALL: LIB BIN - install $(LIB) $(SDP_ROOT)/lib/lib$(LIB_ROOT).a - install $(INC_FILES) $(SDP_ROOT)/include - -LIB: $(LIB) - -clean: - rm -f *.o *~ - rm -f $(LIB) - rm -f $(INSTALL_LIB_PATH)/$(LIB) - rm -f $(INSTALL_INC_PATH)/*.h - -rebuild: clean LOCAL - -$(LIB): $(OBJECTS) - $(AR) $(ARFLAGS) $(LIB) $(OBJECTS) - - -%.o : %.c - $(CC) -c $(CFLAGS) $(COMPILE_INCLUDE) $(CPPFLAGS) $< -o $@ - - -new: - ../../Scripts/cdep.py all_include.h 0 - -include dependencies - -################################################################## -## Binaries -# -#BIN_FILES = rms.x rms_stat.x roff_tags.x rms_extract.x rms_setname.x -#BIN: $(BIN_FILES) -#BIN_FILES_SDP_INSTALL = roff_tags.x -# -#rms_test.o : rms_test.c -#rms_stat.o : rms_stat.c -#tag_list.o : tag_list.c -#rms_extract.o : rms_extract.c -#rms_setname.o : rms_setname.c -# -#roff_tags.x: tag_list.o $(LIB) -# $(CC) -$(MFLAG) $(LDFLAGS) tag_list.o -o roff_tags.x $(LIB_PATH) $(LIB_LINK) -# -#rms.x: rms_test.o $(LIB) -# $(CC) -$(MFLAG) $(LDFLAGS) rms_test.o -o rms.x $(LIB_PATH) $(LIB_LINK) -# -#rms_stat.x: rms_stat.o $(LIB) -# $(CC) -$(MFLAG) $(LDFLAGS) rms_stat.o -o rms_stat.x $(LIB_PATH) $(LIB_LINK) -# -#rms_extract.x: rms_extract.o $(LIB) -# $(CC) -$(MFLAG) $(LDFLAGS) rms_extract.o -o rms_extract.x $(LIB_PATH) $(LIB_LINK) -# -#rms_setname.x: rms_setname.o $(LIB) -# $(CC) -$(MFLAG) $(LDFLAGS) rms_setname.o -o rms_setname.x $(LIB_PATH) $(LIB_LINK) - - diff --git a/ThirdParty/Ert/devel/librms/src/rms_file.c b/ThirdParty/Ert/devel/librms/src/rms_file.c index b973b36761..ef0461a24f 100644 --- a/ThirdParty/Ert/devel/librms/src/rms_file.c +++ b/ThirdParty/Ert/devel/librms/src/rms_file.c @@ -268,8 +268,8 @@ rms_tag_type * rms_file_fread_alloc_tag(rms_file_type * rms_file , const char *t bool cont = true; bool tag_found = false; - long int start_pos = ftell(rms_file->stream); - fseek(rms_file->stream , 0 , SEEK_SET); + long int start_pos = util_ftell(rms_file->stream); + util_fseek(rms_file->stream , 0 , SEEK_SET); rms_file_init_fread(rms_file); while (cont) { bool eof_tag; @@ -283,7 +283,7 @@ rms_tag_type * rms_file_fread_alloc_tag(rms_file_type * rms_file , const char *t cont = false; } if (tag == NULL) { - fseek(rms_file->stream , start_pos , SEEK_SET); + util_fseek(rms_file->stream , start_pos , SEEK_SET); fprintf(stderr,"%s: could not find tag: \"%s\" (with %s=%s) in file:%s - aborting.\n",__func__ , tagname , keyname , keyvalue , rms_file->filename); abort(); } @@ -457,15 +457,15 @@ void rms_file_2eclipse(const char * rms_file , const char * ecl_path, bool ecl_f bool rms_file_is_roff(FILE * stream) { const int len = strlen(rms_comment1); char *header = malloc(strlen(rms_comment1) + 1); - const long int current_pos = ftell(stream); + const long int current_pos = util_ftell(stream); bool roff_file = false; - fseek(stream , 1 + 1 + 8 , SEEK_CUR); /* Skipping #roff-bin#0# WILL Fail with formatted files */ + util_fseek(stream , 1 + 1 + 8 , SEEK_CUR); /* Skipping #roff-bin#0# WILL Fail with formatted files */ rms_util_fread_string(header , len+1 , stream); if (strncmp(rms_comment1 , header , len) == 0) roff_file = true; - fseek(stream , current_pos , SEEK_SET); + util_fseek(stream , current_pos , SEEK_SET); free(header); return roff_file; } @@ -481,7 +481,7 @@ void old_rms_roff_load(const char *filename , const char *param_name , float *pa int size; FILE *stream = fopen(filename , "r"); - fseek(stream , offset , SEEK_SET); + util_fseek(stream , offset , SEEK_SET); fread(&size , 1 , sizeof size , stream); n_read = fread(param , sizeof *param , size , stream); diff --git a/ThirdParty/Ert/devel/librms/src/rms_tag.c b/ThirdParty/Ert/devel/librms/src/rms_tag.c index 4384f4055a..f21235f726 100644 --- a/ThirdParty/Ert/devel/librms/src/rms_tag.c +++ b/ThirdParty/Ert/devel/librms/src/rms_tag.c @@ -187,7 +187,7 @@ static void rms_tag_add_tagkey(const rms_tag_type *tag , const rms_tagkey_type * static bool rms_tag_at_endtag(FILE *stream) { - const int init_pos = ftell(stream); + const int init_pos = util_ftell(stream); bool at_endtag; char tag[7]; if (rms_util_fread_string(tag , 7 , stream)) { @@ -199,7 +199,7 @@ static bool rms_tag_at_endtag(FILE *stream) { at_endtag = false; if (!at_endtag) - fseek(stream , init_pos , SEEK_SET); + util_fseek(stream , init_pos , SEEK_SET); return at_endtag; } diff --git a/ThirdParty/Ert/devel/librms/src/rms_tagkey.c b/ThirdParty/Ert/devel/librms/src/rms_tagkey.c index c9014cb1ed..3e0fb2ccd1 100644 --- a/ThirdParty/Ert/devel/librms/src/rms_tagkey.c +++ b/ThirdParty/Ert/devel/librms/src/rms_tagkey.c @@ -420,12 +420,12 @@ static void rms_tagkey_set_data_size(rms_tagkey_type *tagkey , FILE *stream , in if (tagkey->rms_type == rms_char_type) { if (stream != NULL) { - const long int init_pos = ftell(stream); + const long int init_pos = util_ftell(stream); int i; for (i=0; i < tagkey->size; i++) rms_util_fskip_string(stream); - tagkey->data_size = ftell(stream) - init_pos; - fseek(stream , init_pos , SEEK_SET); + tagkey->data_size = util_ftell(stream) - init_pos; + util_fseek(stream , init_pos , SEEK_SET); } else tagkey->data_size = strlen + 1; } else diff --git a/ThirdParty/Ert/devel/librms/src/rms_util.c b/ThirdParty/Ert/devel/librms/src/rms_util.c index 59b92bbeaf..16dd6533bd 100644 --- a/ThirdParty/Ert/devel/librms/src/rms_util.c +++ b/ThirdParty/Ert/devel/librms/src/rms_util.c @@ -101,11 +101,11 @@ void rms_util_fskip_string(FILE *stream) { int rms_util_fread_strlen(FILE *stream) { - long int init_pos = ftell(stream); + long int init_pos = util_ftell(stream); int len; rms_util_fskip_string(stream); - len = ftell(stream) - init_pos; - fseek(stream , init_pos , SEEK_SET); + len = util_ftell(stream) - init_pos; + util_fseek(stream , init_pos , SEEK_SET); return len; } @@ -116,7 +116,7 @@ int rms_util_fread_strlen(FILE *stream) { bool rms_util_fread_string(char *string , int max_length , FILE *stream) { bool read_ok = true; bool cont = true; - long int init_pos = ftell(stream); + long int init_pos = util_ftell(stream); int pos = 0; while (cont) { fread(&string[pos] , sizeof *string , 1 , stream); @@ -128,7 +128,7 @@ bool rms_util_fread_string(char *string , int max_length , FILE *stream) { if (max_length > 0) { if (pos == max_length) { read_ok = false; - fseek(stream , init_pos , SEEK_SET); + util_fseek(stream , init_pos , SEEK_SET); cont = false; } } diff --git a/ThirdParty/Ert/devel/libsched/CMakeLists.txt b/ThirdParty/Ert/devel/libsched/CMakeLists.txt index c5e65c48a3..3edab07684 100644 --- a/ThirdParty/Ert/devel/libsched/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libsched/CMakeLists.txt @@ -3,6 +3,6 @@ if (BUILD_APPLICATONS) add_subdirectory( applications ) endif() -#if (BUILD_TESTS) -# add_subdirectory( tests ) -#endif() +if (BUILD_TESTS) + add_subdirectory( tests ) +endif() diff --git a/ThirdParty/Ert/devel/libsched/applications/CMakeLists.txt b/ThirdParty/Ert/devel/libsched/applications/CMakeLists.txt index 3416f7625b..83f41113b9 100644 --- a/ThirdParty/Ert/devel/libsched/applications/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libsched/applications/CMakeLists.txt @@ -10,6 +10,9 @@ add_executable( sched_summary.x sched_summary.c ) set(program_list sched_summary.x) foreach(prog ${program_list}) target_link_libraries( ${prog} sched ecl ert_util ) + if (USE_RUNPATH) + add_runpath( ${prog} ) + endif() #----------------------------------------------------------------- if (SCHED_INSTALL_PREFIX) set (destination ${SCHED_INSTALL_PREFIX}/bin) diff --git a/ThirdParty/Ert/devel/libsched/include/ert/sched/history.h b/ThirdParty/Ert/devel/libsched/include/ert/sched/history.h index f56376055d..efa10fec51 100644 --- a/ThirdParty/Ert/devel/libsched/include/ert/sched/history.h +++ b/ThirdParty/Ert/devel/libsched/include/ert/sched/history.h @@ -28,6 +28,7 @@ extern "C" { #include #include +#include #include @@ -66,6 +67,8 @@ typedef struct history_struct history_type; int history_get_restart_nr_from_days(const history_type *, double days); time_t history_get_time_t_from_restart_nr( const history_type * history , int restart_nr); int history_get_restart_nr_from_time_t( const history_type * history , time_t time); + + UTIL_IS_INSTANCE_HEADER( history ); #ifdef __cplusplus } diff --git a/ThirdParty/Ert/devel/libsched/src/CMakeLists.txt b/ThirdParty/Ert/devel/libsched/src/CMakeLists.txt index ab88ff6800..60eb417cb4 100644 --- a/ThirdParty/Ert/devel/libsched/src/CMakeLists.txt +++ b/ThirdParty/Ert/devel/libsched/src/CMakeLists.txt @@ -10,7 +10,9 @@ add_library( sched ${LIBRARY_TYPE} ${source_files} ) set_target_properties( sched PROPERTIES VERSION 1.0 SOVERSION 1.0 ) target_link_libraries( sched ert_util ecl) - +if (USE_RUNPATH) + add_runpath( sched ) +endif() #----------------------------------------------------------------- if (INSTALL_ERT) install(TARGETS sched DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/ThirdParty/Ert/devel/libsched/src/history.c b/ThirdParty/Ert/devel/libsched/src/history.c index 5c3f155b18..49c7e1759e 100644 --- a/ThirdParty/Ert/devel/libsched/src/history.c +++ b/ThirdParty/Ert/devel/libsched/src/history.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -25,13 +26,17 @@ #include #include +#include #include #include #include +#define HISTORY_TYPE_ID 66143109 + struct history_struct{ + UTIL_TYPE_ID_DECLARATION; const ecl_sum_type * refcase; /* ecl_sum instance used when the data are taken from a summary instance. Observe that this is NOT owned by history instance.*/ const sched_file_type * sched_file; /* Not owned. */ sched_history_type * sched_history; @@ -73,13 +78,13 @@ const char * history_get_source_string( history_source_type history_source ) { } - - +UTIL_IS_INSTANCE_FUNCTION( history , HISTORY_TYPE_ID ) static history_type * history_alloc_empty( ) { history_type * history = util_malloc(sizeof * history); + UTIL_TYPE_ID_INIT( history , HISTORY_TYPE_ID ); history->refcase = NULL; history->sched_history = NULL; history->sched_file = NULL; @@ -155,9 +160,9 @@ bool history_init_ts( const history_type * history , const char * summary_key , double_vector_reset( value ); bool_vector_reset( valid ); bool_vector_set_default( valid , false); - + if (history->source == SCHEDULE) { - + for (int tstep = 0; tstep <= sched_history_get_last_history(history->sched_history); tstep++) { if (sched_history_open( history->sched_history , summary_key , tstep)) { bool_vector_iset( valid , tstep , true ); @@ -174,25 +179,36 @@ bool history_init_ts( const history_type * history , const char * summary_key , /* Must create a new key with 'H' for historical values. */ const ecl_smspec_type * smspec = ecl_sum_get_smspec( history->refcase ); const char * join_string = ecl_smspec_get_join_string( smspec ); - - local_key = util_alloc_sprintf( "%sH%s%s" , ecl_sum_get_keyword( history->refcase , summary_key ) , join_string , ecl_sum_get_wgname( history->refcase , summary_key )); + ecl_smspec_var_type var_type = ecl_smspec_identify_var_type( summary_key ); + + if ((var_type == ECL_SMSPEC_WELL_VAR) || (var_type == ECL_SMSPEC_GROUP_VAR)) + local_key = util_alloc_sprintf( "%sH%s%s" , + ecl_sum_get_keyword( history->refcase , summary_key ) , + join_string , + ecl_sum_get_wgname( history->refcase , summary_key )); + else if (var_type == ECL_SMSPEC_FIELD_VAR) + local_key = util_alloc_sprintf( "%sH" , ecl_sum_get_keyword( history->refcase , summary_key )); + else + local_key = NULL; // If we try to get historical values of e.g. Region quantities it will fail. } else local_key = (char *) summary_key; - if (ecl_sum_has_general_var( history->refcase , local_key )) { - for (int tstep = 0; tstep <= history_get_last_restart(history); tstep++) { - int time_index = ecl_sum_iget_report_end( history->refcase , tstep ); - if (time_index >= 0) { - double_vector_iset( value , tstep , ecl_sum_get_general_var( history->refcase , time_index , local_key )); - bool_vector_iset( valid , tstep , true ); - } else - bool_vector_iset( valid , tstep , false ); /* Did not have this report step */ + if (local_key) { + if (ecl_sum_has_general_var( history->refcase , local_key )) { + for (int tstep = 0; tstep <= history_get_last_restart(history); tstep++) { + int time_index = ecl_sum_iget_report_end( history->refcase , tstep ); + if (time_index >= 0) { + double_vector_iset( value , tstep , ecl_sum_get_general_var( history->refcase , time_index , local_key )); + bool_vector_iset( valid , tstep , true ); + } else + bool_vector_iset( valid , tstep , false ); /* Did not have this report step */ + } + initOK = true; } - initOK = true; + + if (history->source == REFCASE_HISTORY) + free( local_key ); } - - if (history->source == REFCASE_HISTORY) - free( local_key ); } return initOK; } diff --git a/ThirdParty/Ert/devel/libsched/tests/CMakeLists.txt b/ThirdParty/Ert/devel/libsched/tests/CMakeLists.txt new file mode 100644 index 0000000000..66bac6124d --- /dev/null +++ b/ThirdParty/Ert/devel/libsched/tests/CMakeLists.txt @@ -0,0 +1,16 @@ +#add_executable( sched_load sched_load.c ) +#target_link_libraries( sched_load sched test_util ) +#add_test( sched_load ${EXECUTABLE_OUTPUT_PATH}/sched_load ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Heidrun/Schedule.sch ) + +#add_executable( sched_tokenize sched_tokenize.c ) +#target_link_libraries( sched_tokenize sched test_util ) +#add_test( sched_tokenize ${EXECUTABLE_OUTPUT_PATH}/sched_tokenize ${CMAKE_CURRENT_SOURCE_DIR}/test-data/token_test1 ) + +add_executable( sched_history_summary sched_history_summary.c ) +target_link_libraries( sched_history_summary sched test_util ) +add_test( sched_history_summary1 ${EXECUTABLE_OUTPUT_PATH}/sched_history_summary ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE ) +add_test( sched_history_summary2 ${EXECUTABLE_OUTPUT_PATH}/sched_history_summary ${PROJECT_SOURCE_DIR}/test-data/Statoil/ECLIPSE/Snorre/SNORRE ) + +#set_property( TEST sched_load PROPERTY LABELS StatoilData) +set_property( TEST sched_history_summary1 PROPERTY LABELS StatoilData) +set_property( TEST sched_history_summary2 PROPERTY LABELS StatoilData) diff --git a/ThirdParty/Ert/devel/libsched/tests/sched_history_summary.c b/ThirdParty/Ert/devel/libsched/tests/sched_history_summary.c new file mode 100644 index 0000000000..6f94d38d36 --- /dev/null +++ b/ThirdParty/Ert/devel/libsched/tests/sched_history_summary.c @@ -0,0 +1,72 @@ +/* + Copyright (C) 2013 Statoil ASA, Norway. + + The file 'sched_history_summary.c' is part of ERT - Ensemble based Reservoir Tool. + + ERT 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. + + ERT 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 + +#include + +#include + + + +int main(int argc, char **argv) { + char * sum_case = argv[1]; + ecl_sum_type * refcase = ecl_sum_fread_alloc_case( sum_case , ":" ); + history_type * hist_h = history_alloc_from_refcase( refcase , true ); + history_type * hist_sim = history_alloc_from_refcase( refcase , false ); + + test_assert_true( history_is_instance( hist_h ) ); + test_assert_true( history_is_instance( hist_sim ) ); + test_assert_int_equal( history_get_last_restart( hist_sim ) , ecl_sum_get_last_report_step( refcase ) ); + test_assert_int_equal( history_get_last_restart( hist_h ) , ecl_sum_get_last_report_step( refcase ) ); + + { + double_vector_type * value_sim = double_vector_alloc(0 , 0); + double_vector_type * value_h = double_vector_alloc(0 , 0); + bool_vector_type * valid_sim = bool_vector_alloc( 0 , false ); + bool_vector_type * valid_h = bool_vector_alloc( 0 , false ); + + test_assert_true( history_init_ts( hist_sim , "FOPT" , value_sim , valid_sim )); + test_assert_true( history_init_ts( hist_h , "FOPT" , value_h , valid_h )); + { + int step; + for (step = 1; step < ecl_sum_get_last_report_step( refcase ); step++) { + test_assert_true( bool_vector_iget( valid_sim , step )); + test_assert_true( bool_vector_iget( valid_h , step )); + { + int time_index = ecl_sum_iget_report_end( refcase , step ); + test_assert_double_equal( ecl_sum_get_general_var( refcase , time_index , "FOPT" ) , double_vector_iget( value_sim , step )); + test_assert_double_equal( ecl_sum_get_general_var( refcase , time_index , "FOPTH" ) , double_vector_iget( value_h , step )); + } + } + } + bool_vector_free( valid_sim ); + bool_vector_free( valid_h ); + + double_vector_free( value_sim ); + double_vector_free( value_h ); + } + + + history_free( hist_h ); + history_free( hist_sim ); + ecl_sum_free( refcase ); + exit(0); +} diff --git a/ThirdParty/Ert/devel/python/CMakeLists.txt b/ThirdParty/Ert/devel/python/CMakeLists.txt index eff179dba0..db21efb45b 100644 --- a/ThirdParty/Ert/devel/python/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/CMakeLists.txt @@ -1,3 +1,5 @@ set(PYTHON_INSTALL_PREFIX "python") -add_subdirectory( test ) +if (BUILD_TESTS) + add_subdirectory( test ) +endif() add_subdirectory( python ) diff --git a/ThirdParty/Ert/devel/python/ert/config/config_enums.py b/ThirdParty/Ert/devel/python/ert/config/config_enums.py deleted file mode 100644 index 199c16dfd0..0000000000 --- a/ThirdParty/Ert/devel/python/ert/config/config_enums.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'config.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import libconfig -from ert.cwrap.cenum import create_enum - - -# config_item_types from config_schema_item.h -create_enum( libconfig.lib , "config_schema_item_type_enum_iget" , "config_types_enum" , globals()) - -# config_item_types from config_schema_item.h -create_enum( libconfig.lib , "config_schema_item_unrecognized_enum_iget" , "config_unrecognized_enum" , name_space = globals()) diff --git a/ThirdParty/Ert/devel/python/ert/config/config_parser.py b/ThirdParty/Ert/devel/python/ert/config/config_parser.py deleted file mode 100644 index d3a7477b93..0000000000 --- a/ThirdParty/Ert/devel/python/ert/config/config_parser.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'config_parser.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - - - -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from config_enums import * - -class ConfigParser(CClass): - - def __init__(self): - c_ptr = cfunc.alloc() - self.init_cobj( c_ptr , cfunc.free ) - - - def parse(self , filename , comment_string = "--" , include_kw = "INCLUDE" , define_kw = None , unrecognized = CONFIG_UNRECOGNIZED_WARN , validate = True): - return cfunc.parse(self , filename , comment_string , include_kw , define_kw , unrecognized , validate) - - - def add(self , kw , required = False): - cfunc.add_schema_item( self , kw , required ) - - -################################################################# - -cwrapper = CWrapper( libconfig.lib ) -cwrapper.registerType( "config" , ConfigParser ) -cfunc = CWrapperNameSpace("config") -cfunc.alloc = cwrapper.prototype("c_void_p config_alloc()") -cfunc.free = cwrapper.prototype("void config_free( config )") -cfunc.parse = cwrapper.prototype("bool config_parse( config , char* , char* , char* , char*, int , bool)") -cfunc.add_schema_item = cwrapper.prototype("bool config_add_schema_item( config , char* , bool)") diff --git a/ThirdParty/Ert/devel/python/python/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/CMakeLists.txt index 970c600891..4e27dd7af2 100644 --- a/ThirdParty/Ert/devel/python/python/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/CMakeLists.txt @@ -1 +1,3 @@ add_subdirectory( ert ) +add_subdirectory( ert_gui ) + diff --git a/ThirdParty/Ert/devel/python/python/ert/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/CMakeLists.txt index 08727c8c72..48c01a8417 100644 --- a/ThirdParty/Ert/devel/python/python/ert/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/CMakeLists.txt @@ -10,4 +10,4 @@ add_subdirectory( rms ) add_subdirectory( sched ) add_subdirectory( util ) add_subdirectory( well ) - +add_subdirectory( ert ) diff --git a/ThirdParty/Ert/devel/python/python/ert/config/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/config/CMakeLists.txt index 63bc5fa791..337282c11a 100644 --- a/ThirdParty/Ert/devel/python/python/ert/config/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/config/CMakeLists.txt @@ -1 +1,7 @@ -add_python_package("Python ert.config" ${PYTHON_INSTALL_PREFIX}/ert/config "config.py;__init__.py;libconfig.py;config_enums.py;config_parser.py" True) +set(PYTHON_SOURCES + __init__.py + config_enums.py + config_parser.py +) + +add_python_package("Python ert.config" ${PYTHON_INSTALL_PREFIX}/ert/config "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/config/__init__.py b/ThirdParty/Ert/devel/python/python/ert/config/__init__.py index e69de29bb2..302cb8031f 100644 --- a/ThirdParty/Ert/devel/python/python/ert/config/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/config/__init__.py @@ -0,0 +1,23 @@ +# Copyright (C) 2013 Statoil ASA, Norway. +# +# The file '__init__.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +from ert.cwrap import clib +import ert.util + +CONFIG_LIB = clib.ert_load("libconfig.so") + + +from .config_enums import ContentTypeEnum, UnrecognizedEnum +from .config_parser import ConfigParser , SchemaItem , ContentItem , ContentNode \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/python/ert/config/config.py b/ThirdParty/Ert/devel/python/python/ert/config/config.py deleted file mode 100644 index cc5a0a1458..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/config/config.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'config.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. -import libconfig - -from config_enums import * -from config_parser import ConfigParser , SchemaItem , ContentItem , ContentNode - diff --git a/ThirdParty/Ert/devel/python/python/ert/config/config_enums.py b/ThirdParty/Ert/devel/python/python/ert/config/config_enums.py index da30d1cf9b..22279e6fa2 100644 --- a/ThirdParty/Ert/devel/python/python/ert/config/config_enums.py +++ b/ThirdParty/Ert/devel/python/python/ert/config/config_enums.py @@ -12,10 +12,11 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. -from ert.cwrap.cenum import create_enum -import libconfig +# for more details. -create_enum( libconfig.lib , "config_schema_item_type_enum_iget" , "content_type" , name_space = globals()) +from ert.cwrap import create_enum +from ert.config import CONFIG_LIB -create_enum( libconfig.lib , "config_schema_item_unrecognized_enum_iget" , "unrecognized" , name_space = globals()) +ContentTypeEnum = create_enum(CONFIG_LIB, "config_schema_item_type_enum_iget", "ContentTypeEnum") + +UnrecognizedEnum = create_enum(CONFIG_LIB, "config_schema_item_unrecognized_enum_iget", "UnrecognizedEnum") diff --git a/ThirdParty/Ert/devel/python/python/ert/config/config_parser.py b/ThirdParty/Ert/devel/python/python/ert/config/config_parser.py index 3b03978494..e60d45ab44 100644 --- a/ThirdParty/Ert/devel/python/python/ert/config/config_parser.py +++ b/ThirdParty/Ert/devel/python/python/ert/config/config_parser.py @@ -15,62 +15,58 @@ # for more details. import os.path -import libconfig -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -import config_enums + +from ert.config import UnrecognizedEnum, CONFIG_LIB +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace class SchemaItem(CClass): - - def __init__(self , keyword , required = False): - c_ptr = cfunc.schema_alloc( keyword , required ) - self.init_cref( c_ptr , cfunc.schema_free) + def __init__(self, keyword, required=False): + c_ptr = cfunc.schema_alloc(keyword, required) + self.init_cref(c_ptr, cfunc.schema_free) + - @classmethod - def wrap(cls , c_ptr , parent): - obj = object.__new__( cls ) - obj.init_cref( c_ptr , parent ) + def wrap(cls, c_ptr, parent): + obj = object.__new__(cls) + obj.init_cref(c_ptr, parent) return obj - def iget_type( self , index ): - return cfunc.schema_iget_type( self , index ) + def iget_type( self, index ): + return cfunc.schema_iget_type(self, index) - def iset_type( self , index , type ): - cfunc.schema_iset_type( self , index , type ) - - def set_argc_minmax(self , min , max): - cfunc.schema_set_argc_minmax( self , min , max ) + def iset_type( self, index, schema_type ): + cfunc.schema_iset_type(self, index, schema_type) + + def set_argc_minmax(self, minimum, maximum): + cfunc.schema_set_argc_minmax(self, minimum, maximum) #----------------------------------------------------------------- class ContentItem(CClass): # Not possible to create new python instances of this class - + @classmethod - def wrap(cls , c_ptr , parent): - obj = object.__new__( cls ) - obj.init_cref( c_ptr , parent ) + def wrap(cls, c_ptr, parent): + obj = object.__new__(cls) + obj.init_cref(c_ptr, parent) return obj def __len__(self): - return cfunc.content_size( self ) - + return cfunc.content_size(self) - def __getitem__(self , index): - if isinstance(index , int): - if index >= 0 and index < self.__len__(): - c_ptr = cfunc.iget_content_node( self , index ) - return ContentNode.wrap( c_ptr , self ) + + def __getitem__(self, index): + if isinstance(index, int): + if (index >= 0) and (index < self.__len__()): + c_ptr = cfunc.iget_content_node(self, index) + return ContentNode.wrap(c_ptr, self) else: raise IndexError else: raise ValueError("[] operator must have integer index") - - #----------------------------------------------------------------- @@ -79,87 +75,86 @@ class ContentItem(CClass): class ContentNode(CClass): # Not possible to create new python instances of this class - - @classmethod - def wrap(cls , c_ptr , parent): - obj = object.__new__( cls ) - obj.init_cref( c_ptr , parent ) - return obj - - def __len__(self): - return cfunc.content_node_size( self ) - def __getitem__(self , index): - if isinstance(index , int): - if index >= 0 and index < self.__len__(): - return cfunc.content_node_iget( self , index ) + @classmethod + def wrap(cls, c_ptr, parent): + obj = object.__new__(cls) + obj.init_cref(c_ptr, parent) + return obj + + def __len__(self): + return cfunc.content_node_size(self) + + def __getitem__(self, index): + if isinstance(index, int): + if (index >= 0) and (index < self.__len__()): + return cfunc.content_node_iget(self, index) else: raise IndexError else: raise ValueError("[] operator must have integer index") - def content(self , sep = " "): - return cfunc.content_full_string(self , sep) - + def content(self, sep=" "): + return cfunc.content_full_string(self, sep) #----------------------------------------------------------------- class ConfigParser(CClass): - def __init__(self): c_ptr = cfunc.config_alloc() - self.init_cobj(c_ptr , cfunc.config_free ) + self.init_cobj(c_ptr, cfunc.config_free) - - def add(self , keyword , required = False): - c_ptr = cfunc.add( self , keyword , required ) - schema_item = SchemaItem.wrap(c_ptr , self) + + def add(self, keyword, required=False): + c_ptr = cfunc.add(self, keyword, required) + schema_item = SchemaItem.wrap(c_ptr, self) return schema_item - - - def parse( self , config_file , comment_string = "--" , include_kw = "INCLUDE" , define_kw = "DEFINE" , unrecognized = config_enums.unrecognized.CONFIG_UNRECOGNIZED_WARN , validate = True): - if os.path.exists( config_file ): - return cfunc.parse( self , config_file , comment_string , include_kw , define_kw , unrecognized , validate ) + + + def parse( self, config_file, comment_string="--", include_kw="INCLUDE", define_kw="DEFINE", + unrecognized=UnrecognizedEnum.CONFIG_UNRECOGNIZED_WARN, validate=True): + if os.path.exists(config_file): + return cfunc.parse(self, config_file, comment_string, include_kw, define_kw, unrecognized, validate) else: raise IOError("File: %s does not exists") - def __getitem__(self , keyword): - if cfunc.has_content(self , keyword): - c_ptr = cfunc.get_content(self , keyword ) - return ContentItem.wrap( c_ptr , self ) + def __getitem__(self, keyword): + if cfunc.has_content(self, keyword): + c_ptr = cfunc.get_content(self, keyword) + return ContentItem.wrap(c_ptr, self) else: return None #----------------------------------------------------------------- - -cwrapper = CWrapper( libconfig.lib ) -cwrapper.registerType( "config_parser" , ConfigParser ) -cwrapper.registerType( "schema_item" , SchemaItem ) -cwrapper.registerType( "content_item" , ContentItem ) -cwrapper.registerType( "content_node" , ContentNode ) +cwrapper = CWrapper(CONFIG_LIB) +cwrapper.registerType("config_parser", ConfigParser) +cwrapper.registerType("schema_item", SchemaItem) +cwrapper.registerType("content_item", ContentItem) +cwrapper.registerType("content_node", ContentNode) cfunc = CWrapperNameSpace("config") -cfunc.add = cwrapper.prototype("c_void_p config_add_schema_item( config_parser , char* , bool)") +cfunc.add = cwrapper.prototype("c_void_p config_add_schema_item( config_parser , char* , bool)") cfunc.config_alloc = cwrapper.prototype("c_void_p config_alloc( )") -cfunc.config_free = cwrapper.prototype("void config_free( config_parser )") -cfunc.parse = cwrapper.prototype("bool config_parse( config_parser , char* , char* , char* , char* , int , bool )") -cfunc.has_content = cwrapper.prototype("bool config_has_content_item( config_parser , char*) ") -cfunc.get_content = cwrapper.prototype("c_void_p config_get_content_item( config_parser , char*) ") +cfunc.config_free = cwrapper.prototype("void config_free( config_parser )") +cfunc.parse = cwrapper.prototype("bool config_parse( config_parser , char* , char* , char* , char* , int , bool )") +cfunc.has_content = cwrapper.prototype("bool config_has_content_item( config_parser , char*) ") +cfunc.get_content = cwrapper.prototype("c_void_p config_get_content_item( config_parser , char*) ") -cfunc.schema_alloc = cwrapper.prototype("c_void_p config_schema_item_alloc( char* , bool )") -cfunc.schema_free = cwrapper.prototype("void config_schema_item_free( schema_item )") -cfunc.schema_iget_type = cwrapper.prototype("int config_schema_item_iget_type( schema_item ,int)") -cfunc.schema_iset_type = cwrapper.prototype("void config_schema_item_iset_type( schema_item , int , int)") -cfunc.schema_set_argc_minmax = cwrapper.prototype("void config_schema_item_set_argc_minmax( schema_item , int , int)") +cfunc.schema_alloc = cwrapper.prototype("c_void_p config_schema_item_alloc( char* , bool )") +cfunc.schema_free = cwrapper.prototype("void config_schema_item_free( schema_item )") +cfunc.schema_iget_type = cwrapper.prototype("int config_schema_item_iget_type( schema_item ,int)") +cfunc.schema_iset_type = cwrapper.prototype("void config_schema_item_iset_type( schema_item , int , int)") +cfunc.schema_set_argc_minmax = cwrapper.prototype("void config_schema_item_set_argc_minmax( schema_item , int , int)") -cfunc.content_size = cwrapper.prototype("int config_content_item_get_size( content_item )") -cfunc.iget_content_node = cwrapper.prototype("int config_content_item_iget_node( content_item , int)") -cfunc.content_node_iget = cwrapper.prototype("char* config_content_node_iget( content_node , int)") -cfunc.content_node_size = cwrapper.prototype("int config_content_node_get_size( content_node )") +cfunc.content_size = cwrapper.prototype("int config_content_item_get_size( content_item )") +cfunc.iget_content_node = cwrapper.prototype("int config_content_item_iget_node( content_item , int)") +cfunc.content_node_iget = cwrapper.prototype("char* config_content_node_iget( content_node , int)") +cfunc.content_node_size = cwrapper.prototype("int config_content_node_get_size( content_node )") cfunc.content_full_string = cwrapper.prototype("char* config_content_node_get_full_string( content_node , char* )") + diff --git a/ThirdParty/Ert/devel/python/python/ert/config/libconfig.py b/ThirdParty/Ert/devel/python/python/ert/config/libconfig.py deleted file mode 100644 index ed57ae0943..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/config/libconfig.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'libconfig.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - - -import ert.cwrap.clib as clib -lib = clib.ert_load("libconfig.so") - diff --git a/ThirdParty/Ert/devel/python/python/ert/cwrap/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/cwrap/CMakeLists.txt index 38297e14f2..e05fd016d3 100644 --- a/ThirdParty/Ert/devel/python/python/ert/cwrap/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/cwrap/CMakeLists.txt @@ -1 +1,10 @@ -add_python_package("Python ert.cwrap" ${PYTHON_INSTALL_PREFIX}/ert/cwrap "cclass.py;cenum.py;cfile.py;clib.py;cwrap.py;__init__.py" True) +set(PYTHON_SOURCES + __init__.py + cclass.py + cenum.py + cfile.py + clib.py + cwrap.py +) + +add_python_package("Python ert.cwrap" ${PYTHON_INSTALL_PREFIX}/ert/cwrap "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/cwrap/__init__.py b/ThirdParty/Ert/devel/python/python/ert/cwrap/__init__.py index be661504b2..062953444e 100644 --- a/ThirdParty/Ert/devel/python/python/ert/cwrap/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/cwrap/__init__.py @@ -39,3 +39,8 @@ the process of interacting with a C library: FILE pointer. """ +from .cclass import CClass +from .cenum import create_enum +from .cfile import CFILE +from .clib import load, ert_lib_path, ert_load +from .cwrap import CWrapper, CWrapperNameSpace \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/python/ert/cwrap/cclass.py b/ThirdParty/Ert/devel/python/python/ert/cwrap/cclass.py index b6543c67b2..419b11ddf8 100644 --- a/ThirdParty/Ert/devel/python/python/ert/cwrap/cclass.py +++ b/ThirdParty/Ert/devel/python/python/ert/cwrap/cclass.py @@ -97,6 +97,19 @@ class CClass(object): else: return ctypes.c_void_p( obj.c_ptr ) + @classmethod + def asPythonObject( cls , c_ptr, cfree): + assert cfree is not None + obj = cls( ) + obj.init_cobj( c_ptr , cfree) + return obj + + @classmethod + def asPythonReference( cls , c_ptr , parent ): + obj = cls( ) + obj.init_cref( c_ptr , parent ) + return obj + def init_cref(self , c_ptr , parent): self.c_ptr = c_ptr diff --git a/ThirdParty/Ert/devel/python/python/ert/cwrap/cenum.py b/ThirdParty/Ert/devel/python/python/ert/cwrap/cenum.py index e1ce2d9bec..926d12dbdd 100644 --- a/ThirdParty/Ert/devel/python/python/ert/cwrap/cenum.py +++ b/ThirdParty/Ert/devel/python/python/ert/cwrap/cenum.py @@ -21,19 +21,20 @@ import ctypes import sys - -def make_enum(name , attrs): +def make_enum(name, attributes): class cls(object): pass cls.__name__ = name - for key in attrs.keys(): - setattr(cls , key , attrs[key]) + cls.enum_names = [] + for key in attributes.keys(): + setattr(cls, key, attributes[key]) + cls.enum_names.append(key) + return cls - -def create_enum( lib, func_name , enum_name , name_space = None): +def create_enum( lib, func_name, enum_name, name_space=None): """ Create and insert enum values as integer constants. @@ -98,27 +99,27 @@ def create_enum( lib, func_name , enum_name , name_space = None): """ try: - func = getattr( lib , func_name ) + func = getattr(lib, func_name) except AttributeError: - sys.exit("Could not find enum description function:%s - can not load enum:%s." % (func_name , enum_name)) + sys.exit("Could not find enum description function:%s - can not load enum:%s." % (func_name, enum_name)) func.restype = ctypes.c_char_p - func.argtypes = [ ctypes.c_int , ctypes.POINTER(ctypes.c_int) ] + func.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_int)] enum = {} index = 0 while True: value = ctypes.c_int() - name = func( index , ctypes.byref( value )) + name = func(index, ctypes.byref(value)) if name: if name_space: - name_space[ name ] = value.value - enum[ name ] = value.value + name_space[name] = value.value + enum[name] = value.value index += 1 else: break - enum = make_enum( enum_name , enum ) + enum = make_enum(enum_name, enum) if name_space: - name_space[ enum_name ] = enum + name_space[enum_name] = enum return enum diff --git a/ThirdParty/Ert/devel/python/python/ert/cwrap/clib.py b/ThirdParty/Ert/devel/python/python/ert/cwrap/clib.py index f772ab6b11..d15bd4ea83 100644 --- a/ThirdParty/Ert/devel/python/python/ert/cwrap/clib.py +++ b/ThirdParty/Ert/devel/python/python/ert/cwrap/clib.py @@ -19,12 +19,11 @@ Convenience module for loading shared library. import ctypes import os -import os.path ert_lib_path = None -def __load__( lib_list , ert_prefix): +def __load__( lib_list, ert_prefix): """ Thin wrapper around the ctypes.CDLL function for loading shared library. @@ -44,17 +43,17 @@ def __load__( lib_list , ert_prefix): for lib in lib_list: try: if ert_prefix: - ert_lib = os.path.join( ert_lib_path , lib ) - dll = ctypes.CDLL( ert_lib , ctypes.RTLD_GLOBAL ) + ert_lib = os.path.join(ert_lib_path, lib) + dll = ctypes.CDLL(ert_lib, ctypes.RTLD_GLOBAL) else: - dll = ctypes.CDLL( lib , ctypes.RTLD_GLOBAL ) + dll = ctypes.CDLL(lib, ctypes.RTLD_GLOBAL) return dll - except Exception,exc: + except Exception, exc: error_list[lib] = exc error_msg = "\nFailed to load shared library:%s\n\ndlopen() error:\n" % lib_list[0] for lib in error_list.keys(): - error_msg += " %16s : %s\n" % (lib , error_list[lib]) + error_msg += " %16s : %s\n" % (lib, error_list[lib]) error_msg += "\n" LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH") @@ -70,7 +69,7 @@ variable. Your current LD_LIBRARY_PATH setting is: You might need to update this variable? """ % LD_LIBRARY_PATH - raise ImportError( error_msg ) + raise ImportError(error_msg) ################################################################# @@ -79,7 +78,7 @@ def load( *lib_list ): """ Will try to load shared library with normal load semantics. """ - return __load__(lib_list , False ) + return __load__(lib_list, False) def ert_load( *lib_list ): @@ -90,10 +89,10 @@ def ert_load( *lib_list ): """ if ert_lib_path: try: - return __load__(lib_list , True ) + return __load__(lib_list, True) except ImportError: # Try again - ignoring the ert_lib_path setting. - return load( *lib_list ) + return load(*lib_list) else: # The ert_lib_path variable has not been set; just try a normal load. - return load( *lib_list ) + return load(*lib_list) diff --git a/ThirdParty/Ert/devel/python/python/ert/cwrap/cwrap.py b/ThirdParty/Ert/devel/python/python/ert/cwrap/cwrap.py index e1b7243c2d..a94bf5ddb3 100644 --- a/ThirdParty/Ert/devel/python/python/ert/cwrap/cwrap.py +++ b/ThirdParty/Ert/devel/python/python/ert/cwrap/cwrap.py @@ -123,7 +123,15 @@ class CWrapper: return func - + def safe_prototype(self,pattern , lib = None): + try: + func = self.prototype(pattern, lib) + except AttributeError: + func = None + sys.stderr.write("****Defunct function call: %s\n" % pattern) + return func + + def print_types(self): for ctype in self.registered_types.keys(): print "%16s -> %s" % (ctype , self.registered_types[ ctype ]) diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/ecl/CMakeLists.txt index b61bbe51de..6a1cb0f0ac 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/CMakeLists.txt @@ -1,5 +1,37 @@ -add_python_package("Python ert.ecl" ${PYTHON_INSTALL_PREFIX}/ert/ecl "ecl_case.py;ecl_default.py;ecl_file.py;ecl_grav_calc.py;ecl_grav.py;ecl_grid.py;ecl_kw.py;ecl.py;ecl_queue.py;ecl_region.py;ecl_rft.py;ecl_subsidence.py;ecl_sum.py;ecl_util.py;fortio.py;__init__.py;libecl.py" True) +SET(PYTHON_SOURCES + __init__.py + ecl.py + ecl_case.py + ecl_default.py + ecl_file.py + ecl_grav.py + ecl_grav_calc.py + ecl_grid.py + ecl_kw.py + ecl_queue.py + ecl_region.py + ecl_rft.py + ecl_rft_cell.py + ecl_subsidence.py + ecl_sum.py + ecl_util.py + fortio.py -if (EXISTS "ecl_local.py") - add_python_file( "Python ert.ecl.ecl_local" ${PYTHON_INSTALL_PREFIX}/ert/ecl "ecl_local.py" True) + ) + +add_python_package("Python ert.ecl" ${PYTHON_INSTALL_PREFIX}/ert/ecl "${PYTHON_SOURCES}" True) + + +set( ECL_LOCAL_TARGET "" CACHE FILE "Name of optional external ecl_local module") + +if (EXISTS ${ECL_LOCAL_TARGET}) + if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ecl_local.py") + EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_CURRENT_SOURCE_DIR}/ecl_local.py") + endif() + + EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E create_symlink "${ECL_LOCAL_TARGET}" "${CMAKE_CURRENT_SOURCE_DIR}/ecl_local.py") +endif() + +if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ecl_local.py") + add_python_package( "Python ert.ecl.ecl_local" ${PYTHON_INSTALL_PREFIX}/ert/ecl "ecl_local.py" True) endif() diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/__init__.py b/ThirdParty/Ert/devel/python/python/ert/ecl/__init__.py index 182104376a..a759125d37 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/__init__.py @@ -68,7 +68,36 @@ per module organization: all symbols in the package are available under the common namespace 'ecl'. - libecl: This module contains some low-level ctypes trickery to - actually load the shared library libecl.so. """ +from ert.cwrap import clib + +import ert.util +import ert.geo + + + +try: + clib.load("libgomp" , "libgomp.so.1") + openmp = True +except ImportError: + openmp = False + +ECL_LIB = clib.ert_load("libecl.so") + + +from .ecl_sum import EclSum #, EclSumVector, EclSumNode, EclSMSPECNode +from .ecl_util import EclFileEnum, EclFileFlagEnum, EclPhaseEnum, EclTypeEnum, EclUtil +from .ecl_default import EclDefault +from .ecl_rft_cell import EclPLTCell, EclRFTCell +from .ecl_rft import EclRFT, EclRFTFile +from .fortio import FortIO +from .ecl_kw import EclKW +from .ecl_file import EclFile +from .ecl_grid import EclGrid +from .ecl_region import EclRegion +from .ecl_subsidence import EclSubsidence +from .ecl_grav_calc import phase_deltag, deltag +from .ecl_queue import EclQueue + +#from .ecl_queue import diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl.py index 8d4847e8c6..ec599ab6a8 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl.py @@ -31,25 +31,67 @@ following construction: It is not necessary to use the this module. See the doc/import.txt document in the ert-python source distribution for more details of module import and namespace resolution. -""" -import libecl -from ecl_kw import EclKW -from ecl_case import EclCase -from ecl_file import EclFile -from ecl_sum import EclSum -from ecl_rft import EclRFTFile , EclRFT , EclRFTCell -from ecl_grid import EclGrid -from ecl_grav import EclGrav -from ecl_subsidence import EclSubsidence -from ecl_region import EclRegion -from fortio import FortIO -from ecl_queue import EclQueue -import ecl_util -from ecl_util import * - -import ecl_default +# """ +# import libecl +# from ecl_kw import EclKW +# from ecl_case import EclCase +# from ecl_file import EclFile +# from ecl_sum import EclSum +# from ecl_rft import EclRFTFile , EclRFT +# from ecl_rft_cell import EclRFTCell, EclPLTCell +# from ecl_grid import EclGrid +# from ecl_grav import EclGrav +# from ecl_subsidence import EclSubsidence +# from ecl_region import EclRegion +# from fortio import FortIO +# from ecl_queue import EclQueue +# import ecl_util +# from ecl_util import * +# +# import ecl_default +#from warnings import warn +#warn("The ecl namespace is deprecated! Please import ecl classes like this: import ert.ecl as ecl!") + +from .ecl_sum import EclSum #, EclSumVector, EclSumNode, EclSMSPECNode +from .ecl_rft_cell import EclPLTCell, EclRFTCell +from .ecl_rft import EclRFT, EclRFTFile +from .ecl_kw import EclKW +from .ecl_file import EclFile +from .fortio import FortIO +from .ecl_grid import EclGrid +from .ecl_region import EclRegion +from .ecl_case import EclCase +from .ecl_subsidence import EclSubsidence +from .ecl_grav_calc import deltag, phase_deltag +from .ecl_grav import EclGrav +from .ecl_queue import EclQueue + +from .ecl_default import default + + +#Legacy import support +class default_wrapper(object): + default = default + +ecl_default = default_wrapper() + + +from .ecl_util import EclFileEnum, EclFileFlagEnum, EclPhaseEnum, EclTypeEnum, EclUtil + +#make enum values globally available in ert.ecl.ecl +for enum in EclFileEnum.enum_names: + globals()[enum] = getattr(EclFileEnum, enum) + +for enum in EclFileFlagEnum.enum_names: + globals()[enum] = getattr(EclFileFlagEnum, enum) + +for enum in EclPhaseEnum.enum_names: + globals()[enum] = getattr(EclPhaseEnum, enum) + +for enum in EclTypeEnum.enum_names: + globals()[enum] = getattr(EclTypeEnum, enum) diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_case.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_case.py index 5c29c919ad..e72d958d04 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_case.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_case.py @@ -19,14 +19,11 @@ Implements EclCase class which is a container for one ECLIPSE case. This module is a pure Python module which does not directly invoke any C based functions. """ - -import os.path -import ecl_sum -import ecl_grid -import ecl_rft -import ecl_default -import ecl_util +import os import warnings +from ert.ecl import EclRFTFile, EclGrid, EclSum, EclUtil + + class EclCase: """ @@ -95,7 +92,7 @@ class EclCase: at these times will lead to an instant 'crash and burn'. """ if not self.__sum: - self.__sum = ecl_sum.EclSum( self.case ) + self.__sum = EclSum( self.case ) return self.__sum @@ -105,7 +102,7 @@ class EclCase: An EclGrid instance for the current case; or None. """ if not self.__grid: - self.__grid = ecl_grid.EclGrid( self.case ) + self.__grid = EclGrid( self.case ) return self.__grid @@ -115,7 +112,7 @@ class EclCase: An EclRFTFile instance for the current case; or None. """ if not self.__rft: - self.__rft = ecl_rft.EclRFTFile( self.case ) + self.__rft = EclRFTFile( self.case ) return self.__rft @@ -191,21 +188,21 @@ class EclCase: """ import ert.job_queue.driver as queue_driver - num_cpu = ecl_util.get_num_cpu( self.datafile ) + num_cpu = EclUtil.get_num_cpu( self.datafile ) argv = [ecl_version , self.datafile , num_cpu] if ecl_cmd is None: ecl_cmd = ecl_default.default.ecl_cmd if driver_type is None: - driver_type = ecl_default.default.driver_type + driver_type = ECL_DEFAULT.driver_type if ecl_version is None: - ecl_version = ecl_default.default.ecl_version + ecl_version = ECL_DEFAULT.ecl_version if driver is None: if driver_options is None: - driver_options = ecl_default.default.driver_options[ driver_type ] + driver_options = ECL_DEFAULT.driver_options[ driver_type ] driver = queue_driver.Driver( driver_type , max_running = 0 , options = driver_options ) job = driver.submit( self.base , ecl_cmd , self.path , argv , blocking = blocking) return job diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_default.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_default.py index 7524be7dde..c30de32685 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_default.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_default.py @@ -1,6 +1,6 @@ # Copyright (C) 2011 Statoil ASA, Norway. # -# The file 'ecl_default.py' is part of ERT - Ensemble based Reservoir Tool. +# The file 'ecl_default.py' is part of ERT - Ensemble based Reservoir Tool. # # ERT is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -56,77 +56,119 @@ The ecl_local module can define the following variables: Depending on the computing environment some variables might be irrelevant; it is not necessary to set variables which will not be used. -""" +""" -class EclDefault: - __ecl_cmd = None - __ecl_version = None - __lsf_resource_request = None - __driver_type = None - __driver_options = None - def __init__(self): - pass +class EclDefault(object): + _initialized = False - def safe_get( self , attr ): - """ - Internal function to get class attributes. - - Will raise NotImplemtedError if the attribute has not been - loaded from the site spesific ecl_default module. - """ - if hasattr( self , "__%s" % attr): - value = getattr( self , "__%s" % attr) - return value - else: - raise NotImplementedError("The default attribute:%s has not been set - you must update/provide a ecl_local module." % attr) - - @property - def ecl_cmd( self ): + _ecl_cmd = None + _ecl_version = None + _lsf_resource_request = None + _driver_type = None + _driver_options = None + + @staticmethod + def _initializeEclDefaults(): + if not EclDefault._initialized: + try: + import ert.ecl.ecl_local as ecl_local + + if hasattr(ecl_local, "ecl_cmd"): + EclDefault._ecl_cmd = ecl_local.ecl_cmd + + if hasattr(ecl_local, "ecl_version"): + EclDefault._ecl_version = ecl_local.ecl_version + + if hasattr(ecl_local, "lsf_resource_request"): + EclDefault._lsf_resource_request = ecl_local.lsf_resource_request + + if hasattr(ecl_local, "driver_type"): + EclDefault._driver_type = ecl_local.driver_type + + if hasattr(ecl_local, "driver_options"): + EclDefault._driver_options = ecl_local.driver_options + + + except ImportError as e: + pass + + EclDefault._initialized = True + + + @staticmethod + def ecl_cmd(): """ The path to the executable used to invoke ECLIPSE. """ - return self.safe_get( "ecl_cmd" ) + EclDefault._initializeEclDefaults() + + if EclDefault._ecl_cmd is None: + EclDefault._attributeIsNotSet("ecl_cmd") + return EclDefault._ecl_cmd + + @staticmethod + def driver_type(): + EclDefault._initializeEclDefaults() + + if EclDefault._driver_type is None: + EclDefault._attributeIsNotSet("driver_type") + return EclDefault._driver_type + + @staticmethod + def driver_options(): + EclDefault._initializeEclDefaults() + + if EclDefault._driver_options is None: + EclDefault._attributeIsNotSet("driver_options") + return EclDefault._driver_options + + @staticmethod + def ecl_version(): + EclDefault._initializeEclDefaults() + + if EclDefault._ecl_version is None: + EclDefault._attributeIsNotSet("ecl_version") + return EclDefault._ecl_version + + @staticmethod + def lsf_resource_request(): + EclDefault._initializeEclDefaults() + + if EclDefault._lsf_resource_request is None: + EclDefault._attributeIsNotSet("lsf_resource_request") + return EclDefault._lsf_resource_request + + @staticmethod + def _attributeIsNotSet(attribute_name): + raise NotImplementedError("The default attribute:%s has not been set - you must update/provide a ecl_local module." % attribute_name) + + +#Legacy import support + +class default_wrapper(object): + #from warnings import warn + #warn("The ecl_default namespace is deprecated! Please retrieve ecl_default values from the class: ert.ecl.EclDefault!") @property - def driver_type( self ): - return self.safe_get( "driver_type" ) + def ecl_cmd(self): + return EclDefault.ecl_cmd() @property - def driver_options( self ): - return self.safe_get( "driver_options" ) + def driver_type(self): + return EclDefault.driver_type() @property - def ecl_version( self ): - return self.safe_get( "ecl_version" ) + def driver_options(self): + return EclDefault.driver_options() @property - def lsf_resource_request( self ): - return self.safe_get( "lsf_resource_request" ) + def ecl_version(self): + return EclDefault.ecl_version() + + @property + def lsf_resource_request(self): + return EclDefault.lsf_resource_request() -try: - import ecl_local - - if hasattr( ecl_local , "ecl_cmd"): - EclDefault.__ecl_cmd = ecl_local.ecl_cmd - - if hasattr( ecl_local , "ecl_version"): - EclDefault.__ecl_version = ecl_local.ecl_version - - if hasattr( ecl_local , "lsf_resource_request"): - EclDefault.__lsf_resource_request = ecl_local.lsf_resource_request - - if hasattr( ecl_local , "driver_type"): - EclDefault.__driver_type = ecl_local.driver_type - - if hasattr( ecl_local , "driver_options"): - EclDefault.__driver_options = ecl_local.driver_options - - -except ImportError: - pass - - -default = EclDefault() - +default = default_wrapper() \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_file.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_file.py index 37ab3eed4b..fd299f580e 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_file.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_file.py @@ -35,19 +35,13 @@ implementation from the libecl library. [1]: In particular for restart files, which do not have a special RestartFile class, there is some specialized functionality. """ - -import os.path -import datetime -import ctypes -import types -import libecl import re +import types +import datetime +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.ecl import EclKW, ECL_LIB +from ert.util import ctime -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ecl_kw import EclKW -from ert.util.ctime import ctime -from ert.util.stringlist import StringList class EclFile(CClass): @@ -73,7 +67,7 @@ class EclFile(CClass): if dtime: OK = cfunc.restart_block_time( obj , ctime( dtime )) - elif not report_step == None: + elif not report_step is None: OK = cfunc.restart_block_step( obj , report_step ) else: raise TypeError("restart_block() requires either dtime or report_step argument - none given.") @@ -703,7 +697,7 @@ class EclFile(CClass): # 2. Creating a wrapper object around the libecl library, -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_file" , EclFile ) diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav.py index 5d3ad12596..e16dad67e7 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav.py @@ -21,14 +21,9 @@ results and calculate the change in gravitational strength between the different surveys. The implementation is a thin wrapper around the ecl_grav.c implementation in the libecl library. """ +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.ecl import EclPhaseEnum, ECL_LIB -import libecl -import ecl_file -import ecl_region -import ecl_grid -from ecl_util import ECL_WATER_PHASE , ECL_OIL_PHASE , ECL_GAS_PHASE, ecl_phase_enum -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass class EclGrav(CClass): """ @@ -47,7 +42,7 @@ class EclGrav(CClass): 3. Evalute the gravitational response with the eval() method. """ - def __init__( self , grid , init_file ): + def __init__( self, grid, init_file ): """ Creates a new EclGrav instance. @@ -55,12 +50,10 @@ class EclGrav(CClass): of EclGrid and EclFile respectively. """ self.init_file = init_file # Inhibit premature garbage collection of init_file - self.init_cobj( cfunc.grav_alloc(grid , init_file) , cfunc.free) - + self.init_cobj(cfunc.grav_alloc(grid, init_file), cfunc.free) - - def add_survey_RPORV( self , survey_name , restart_file ): + def add_survey_RPORV( self, survey_name, restart_file ): """ Add new survey based on RPORV keyword. @@ -84,9 +77,9 @@ class EclGrav(CClass): add_survey_PORMOD() and add_survey_FIP() are alternatives which are based on other keywords. """ - cfunc.add_survey_RPORV( self , survey_name , restart_file ) + cfunc.add_survey_RPORV(self, survey_name, restart_file) - def add_survey_PORMOD( self , survey_name , restart_file ): + def add_survey_PORMOD( self, survey_name, restart_file ): """ Add new survey based on PORMOD keyword. @@ -94,9 +87,9 @@ class EclGrav(CClass): the PORV_MOD keyword from the restart file; see add_survey_RPORV() for further details. """ - cfunc.add_survey_PORMOD( self , survey_name , restart_file ) + cfunc.add_survey_PORMOD(self, survey_name, restart_file) - def add_survey_FIP( self , survey_name , restart_file ): + def add_survey_FIP( self, survey_name, restart_file ): """ Add new survey based on FIP keywords. @@ -109,9 +102,9 @@ class EclGrav(CClass): the new_std_density() (and possibly also add_std_density()) method before calling the add_survey_FIP() method. """ - cfunc.add_survey_FIP( self , survey_name , restart_file ) + cfunc.add_survey_FIP(self, survey_name, restart_file) - def add_survey_RFIP( self , survey_name , restart_file ): + def add_survey_RFIP( self, survey_name, restart_file ): """ Add new survey based on RFIP keywords. @@ -120,10 +113,11 @@ class EclGrav(CClass): calculated based on the RFIPxxx keyword along with the per-cell mass density of the respective phases. """ - cfunc.add_survey_RFIP( self , survey_name , restart_file ) + cfunc.add_survey_RFIP(self, survey_name, restart_file) - - def eval(self , base_survey , monitor_survey , pos , region = None , phase_mask = ECL_OIL_PHASE + ECL_GAS_PHASE + ECL_WATER_PHASE): + + def eval(self, base_survey, monitor_survey, pos, region=None, + phase_mask=EclPhaseEnum.ECL_OIL_PHASE + EclPhaseEnum.ECL_GAS_PHASE + EclPhaseEnum.ECL_WATER_PHASE): """ Calculates the gravity change between two surveys. @@ -150,10 +144,10 @@ class EclGrav(CClass): sum of the relevant integer constants 'ECL_OIL_PHASE', 'ECL_GAS_PHASE' and 'ECL_WATER_PHASE'. """ - return cfunc.eval( self , base_survey , monitor_survey , region , pos[0] , pos[1] , pos[2] , phase_mask) - + return cfunc.eval(self, base_survey, monitor_survey, region, pos[0], pos[1], pos[2], phase_mask) - def new_std_density( self , phase_enum , default_density): + + def new_std_density( self, phase_enum, default_density): """ Adds a new phase with a corresponding density. @@ -171,9 +165,9 @@ class EclGrav(CClass): used before you use the add_survey_FIP() method to add a survey based on the FIP keyword. """ - cfunc.new_std_density( self , phase_enum , default_density ) - - def add_std_density( self , phase_enum , pvtnum , density): + cfunc.new_std_density(self, phase_enum, default_density) + + def add_std_density( self, phase_enum, pvtnum, density): """ Add standard conditions density for PVT region @pvtnum. @@ -191,12 +185,12 @@ class EclGrav(CClass): used before you use the add_survey_FIP() method to add a survey based on the FIP keyword. """ - cfunc.add_std_density( self , phase_enum , pvtnum , density ) + cfunc.add_std_density(self, phase_enum, pvtnum, density) # 2. Creating a wrapper object around the libecl library, -cwrapper = CWrapper( libecl.lib ) -cwrapper.registerType( "ecl_grav" , EclGrav ) +cwrapper = CWrapper(ECL_LIB) +cwrapper.registerType("ecl_grav", EclGrav) # 3. Installing the c-functions used to manipulate ecl_grav instances. @@ -204,16 +198,16 @@ cwrapper.registerType( "ecl_grav" , EclGrav ) # used outside this scope. cfunc = CWrapperNameSpace("ecl_grav") -cfunc.grav_alloc = cwrapper.prototype("c_void_p ecl_grav_alloc( ecl_grid , ecl_file )") -cfunc.free = cwrapper.prototype("void ecl_grav_free( ecl_grav )") +cfunc.grav_alloc = cwrapper.prototype("c_void_p ecl_grav_alloc( ecl_grid , ecl_file )") +cfunc.free = cwrapper.prototype("void ecl_grav_free( ecl_grav )") # Return value ignored in the add_survey_xxx() functions: -cfunc.add_survey_RPORV = cwrapper.prototype("c_void_p ecl_grav_add_survey_RPORV( ecl_grav , char* , ecl_file )") -cfunc.add_survey_PORMOD = cwrapper.prototype("c_void_p ecl_grav_add_survey_PORMOD( ecl_grav , char* , ecl_file )") -cfunc.add_survey_FIP = cwrapper.prototype("c_void_p ecl_grav_add_survey_FIP( ecl_grav , char* , ecl_file )") -cfunc.add_survey_RFIP = cwrapper.prototype("c_void_p ecl_grav_add_survey_RFIP( ecl_grav , char* , ecl_file )") +cfunc.add_survey_RPORV = cwrapper.prototype("c_void_p ecl_grav_add_survey_RPORV( ecl_grav , char* , ecl_file )") +cfunc.add_survey_PORMOD = cwrapper.prototype("c_void_p ecl_grav_add_survey_PORMOD( ecl_grav , char* , ecl_file )") +cfunc.add_survey_FIP = cwrapper.prototype("c_void_p ecl_grav_add_survey_FIP( ecl_grav , char* , ecl_file )") +cfunc.add_survey_RFIP = cwrapper.prototype("c_void_p ecl_grav_add_survey_RFIP( ecl_grav , char* , ecl_file )") -cfunc.new_std_density = cwrapper.prototype("void ecl_grav_new_std_density( ecl_grav , int , double)") -cfunc.add_std_density = cwrapper.prototype("void ecl_grav_add_std_density( ecl_grav , int , int , double)") -cfunc.eval = cwrapper.prototype("double ecl_grav_eval( ecl_grav , char* , char* , ecl_region , double , double , double, int)") +cfunc.new_std_density = cwrapper.prototype("void ecl_grav_new_std_density( ecl_grav , int , double)") +cfunc.add_std_density = cwrapper.prototype("void ecl_grav_add_std_density( ecl_grav , int , int , double)") +cfunc.eval = cwrapper.prototype("double ecl_grav_eval( ecl_grav , char* , char* , ecl_region , double , double , double, int)") diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav_calc.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav_calc.py index fce876cd92..68d911c8b5 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav_calc.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grav_calc.py @@ -12,19 +12,12 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. +# for more details. +from ert.cwrap import CWrapper, CWrapperNameSpace +from ert.ecl import ECL_LIB -from ert.cwrap.cwrap import * -import libecl -import ctypes -from ecl_kw import EclKW , ECL_INT_TYPE -from ecl_grid import EclGrid - - - -def phase_deltag( xyz , grid , init , sat1 , rho1 , porv1 , sat2 , rho2 , porv2): - +def phase_deltag( xyz, grid, init, sat1, rho1, porv1, sat2, rho2, porv2): # Observe that the function cfunc.phase_deltag() is called # directly with c_ptr pointer values, and that the function is # prototyped with c_void_p arguments instead of ecl_grid and @@ -34,13 +27,11 @@ def phase_deltag( xyz , grid , init , sat1 , rho1 , porv1 , sat2 , rho2 , porv2) # Python/ctypes bug in the current 2.4 implementation; the call # sequencence should modified to use the from_param() method like # the rest of the bindings. - - return cfunc.phase_deltag( xyz[0] , xyz[1] , xyz[2] , - grid.c_ptr , init.c_ptr , - sat1.c_ptr , rho1.c_ptr , porv1.c_ptr , - sat2.c_ptr , rho2.c_ptr , porv2.c_ptr ) - + return cfunc.phase_deltag(xyz[0], xyz[1], xyz[2], + grid.c_ptr, init.c_ptr, + sat1.c_ptr, rho1.c_ptr, porv1.c_ptr, + sat2.c_ptr, rho2.c_ptr, porv2.c_ptr) # 1. All restart files should have water, i.e. the SWAT keyword. @@ -48,58 +39,56 @@ def phase_deltag( xyz , grid , init , sat1 , rho1 , porv1 , sat2 , rho2 , porv2) # in addition the model must contain one additional phase - which should have a density. # 3. The restart files can never contain oil saturation. -def deltag( xyz , grid , init_file , restart_file1 , restart_file2): - swat1 = restart_file1.iget_named_kw( "SWAT" , 0) - swat2 = restart_file2.iget_named_kw( "SWAT" , 0) +def deltag( xyz, grid, init_file, restart_file1, restart_file2): + swat1 = restart_file1.iget_named_kw("SWAT", 0) + swat2 = restart_file2.iget_named_kw("SWAT", 0) - phase_list = [ ( swat1 , swat2) ] + phase_list = [( swat1, swat2)] - if restart_file1.has_kw( "SGAS" ): + if restart_file1.has_kw("SGAS"): # This is a three phase Water / Gas / Oil system - sgas1 = restart_file1.iget_named_kw( "SGAS" , 0 ) - sgas2 = restart_file2.iget_named_kw( "SGAS" , 0 ) + sgas1 = restart_file1.iget_named_kw("SGAS", 0) + sgas2 = restart_file2.iget_named_kw("SGAS", 0) soil1 = 1 - (sgas1 + swat1) soil2 = 1 - (sgas2 + swat2) soil1.name = "SOIL" soil2.name = "SOIL" - phase_list += [ (sgas1 , sgas2), - (soil1 , soil2) ] + phase_list += [(sgas1, sgas2), + (soil1, soil2)] else: # This is a two phase Water / xxx System. Will look for # OIL_DEN and GAS_DEN keywords to determine whether it is a # Water / Oil or Water / Gas system. - if restart_file.has_kw( "OIL_DEN" ): + if restart_file1.has_kw("OIL_DEN"): # Oil / Water system soil1 = 1 - swat1 soil2 = 1 - swat2 soil1.name = "SOIL" soil2.name = "SOIL" - phase_list += [ (soil1 , soil2) ] + phase_list += [(soil1, soil2)] else: # Gas / Water system sgas1 = 1 - swat1 sgas2 = 1 - swat2 sgas1.name = "SGAS" sgas2.name = "SGAS" - phase_list += [ (sgas1 , sgas2) ] + phase_list += [(sgas1, sgas2)] + + porv1 = restart_file1.iget_named_kw("RPORV", 0) + porv2 = restart_file2.iget_named_kw("RPORV", 0) - porv1 = restart_file1.iget_named_kw( "RPORV" , 0 ) - porv2 = restart_file2.iget_named_kw( "RPORV" , 0 ) - deltag = 0 - for (sat1,sat2) in phase_list: - rho_name = "%s_DEN" % sat1.name[1:] - rho1 = restart_file1.iget_named_kw( rho_name , 0 ) - rho2 = restart_file2.iget_named_kw( rho_name , 0 ) - deltag += phase_deltag( xyz , grid , init_file , sat1 , rho1 , porv1 , sat2 , rho2 , porv2) + for (sat1, sat2) in phase_list: + rho_name = "%s_DEN" % sat1.name[1:] + rho1 = restart_file1.iget_named_kw(rho_name, 0) + rho2 = restart_file2.iget_named_kw(rho_name, 0) + deltag += phase_deltag(xyz, grid, init_file, sat1, rho1, porv1, sat2, rho2, porv2) return deltag - - -cwrapper = CWrapper( libecl.lib ) -cfunc = CWrapperNameSpace("ecl_grav") +cwrapper = CWrapper(ECL_LIB) +cfunc = CWrapperNameSpace("ecl_grav") cfunc.phase_deltag = cwrapper.prototype("double ecl_grav_phase_deltag( double, double ,double , c_void_p , c_void_p , c_void_p , c_void_p , c_void_p , c_void_p , c_void_p , c_void_p)") diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grid.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grid.py index fa65609ae1..c2822f8832 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grid.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_grid.py @@ -23,16 +23,13 @@ alone create a grid with ecl_grid module. The functionality is implemented in the EclGrid class. The ecl_grid module is a thin wrapper around the ecl_grid.c implementation from the libecl library. """ - - import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import DoubleVector # Requires merging of typemaps .... -import libecl -import ecl_kw -from ert.cwrap.cfile import CFILE + import numpy +import sys +from ert.cwrap import CClass, CFILE, CWrapper, CWrapperNameSpace +from ert.ecl import EclTypeEnum, EclKW, ECL_LIB + class EclGrid(CClass): """ @@ -93,7 +90,7 @@ class EclGrid(CClass): obj.init_cobj( c_ptr , cfunc.free ) return obj else: - return None + raise IOError("Loading grid from:%s failed" % filename) def equal(self , other , include_lgr = True , verbose = False): @@ -567,11 +564,11 @@ class EclGrid(CClass): if dims[0] == self.nx and dims[1] == self.ny and dims[2] == self.nz: dtype = array.dtype if dtype == numpy.int32: - type = ecl_kw.ECL_INT_TYPE + type = EclTypeEnum.ECL_INT_TYPE elif dtype == numpy.float32: - type = ecl_kw.ECL_FLOAT_TYPE + type = EclTypeEnum.ECL_FLOAT_TYPE elif dtype == numpy.float64: - type = ecl_kw.ECL_DOUBLE_TYPE + type = EclTypeEnum.ECL_DOUBLE_TYPE else: sys.exit("Do not know how to create ecl_kw from type:%s" % dtype) @@ -584,7 +581,7 @@ class EclGrid(CClass): # Silently truncate to length 8 - ECLIPSE has it's challenges. kw_name = kw_name[0:8] - kw = ecl_kw.EclKW.new( kw_name , size , type ) + kw = EclKW.new( kw_name , size , type ) active_index = 0 global_index = 0 for k in range( self.nz ): @@ -713,7 +710,7 @@ class EclGrid(CClass): # 2. Creating a wrapper object around the libecl library, # registering the type map : ecl_kw <-> EclKW -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_grid" , EclGrid ) # 3. Installing the c-functions used to manipulate ecl_kw instances. diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_kw.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_kw.py index 3dd54874b9..613cd9e383 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_kw.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_kw.py @@ -37,17 +37,12 @@ files. This module also has (some) support for working with GRDECL The ecl_kw.py implementation wraps the ecl_kw.c implementation from the libecl library. """ -import types -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.cwrap.cfile import CFILE -from ecl_util import ECL_CHAR_TYPE, ECL_DOUBLE_TYPE, ECL_INT_TYPE, ECL_BOOL_TYPE, ECL_MESS_TYPE, ECL_FLOAT_TYPE -import ecl_util -import fortio -import libecl -import warnings +import ctypes +import types + import numpy +from ert.cwrap import CClass, CFILE, CWrapper, CWrapperNameSpace +from ert.ecl import ECL_LIB, EclTypeEnum, EclUtil class classprop(object): @@ -95,28 +90,28 @@ class EclKW(CClass): @classmethod - def create( cls , name, size , type): + def create( cls , name, size , data_type): """ Creates a brand new EclKW instance. This method will create a grand spanking new EclKW instance. The instance will get name @name (silently truncated - to eight characters), @size elements and datatype @type. Using + to eight characters), @size elements and datatype @data_type. Using this method you could create a SOIL keyword with: soil_kw = EclKW.new( "SOIL" , 10000 , ECL_FLOAT_TYPE ) """ obj = cls() - c_ptr = cfunc.alloc_new( name , size , type ) + c_ptr = cfunc.alloc_new( name , size , data_type ) obj.init_cobj( c_ptr , cfunc.free ) obj.__init( ) return obj @classmethod - def new( cls , name, size , type): - return cls.create( name , size , type ) + def new( cls , name, size , data_type): + return cls.create( name , size , data_type ) # Could this method be avoided totally by using an ecl_kw return @@ -135,8 +130,8 @@ class EclKW(CClass): @classmethod - def slice_copy( cls , src , slice ): - (start , stop , step) = slice.indices( src.size ) + def slice_copy( cls , src , slice_range ): + (start , stop , step) = slice_range.indices( src.size ) if stop > start: c_ptr = cfunc.slice_copyc( src , start , stop , step) obj = cls( ) @@ -162,7 +157,7 @@ class EclKW(CClass): @classmethod - def read_grdecl( cls , file , kw , strict = True , ecl_type = None): + def read_grdecl( cls , filename , kw , strict = True , ecl_type = None): """ Function to load an EclKW instance from a grdecl file. @@ -231,18 +226,18 @@ class EclKW(CClass): it finds in the file. """ - cfile = CFILE( file ) + cfile = CFILE( filename ) if kw: if len(kw) > 8: raise TypeError("Sorry keyword:%s is too long, must be eight characters or less." % kw) if ecl_type is None: if cls.int_kw_set.__contains__( kw ): - ecl_type = ECL_INT_TYPE + ecl_type = EclTypeEnum.ECL_INT_TYPE else: - ecl_type = ECL_FLOAT_TYPE + ecl_type = EclTypeEnum.ECL_FLOAT_TYPE - if not ecl_type in [ECL_FLOAT_TYPE , ECL_INT_TYPE]: + if not ecl_type in [EclTypeEnum.ECL_FLOAT_TYPE , EclTypeEnum.ECL_INT_TYPE]: raise TypeError("The type:%d is invalid when loading keyword:%s" % (ecl_type , kw)) c_ptr = cfunc.load_grdecl( cfile , kw , strict , ecl_type ) @@ -255,7 +250,7 @@ class EclKW(CClass): return None @classmethod - def fseek_grdecl( cls , file , kw , rewind = False): + def fseek_grdecl( cls , filename , kw , rewind = False): """ Will search through the open file and look for string @kw. @@ -279,13 +274,13 @@ class EclKW(CClass): true the function rewind to the beginning of the file and search from there after the initial search. """ - cfile = CFILE( file ) + cfile = CFILE( filename ) return cfunc.fseek_grdecl( kw , rewind , cfile) @classmethod - def grdecl_load( cls , file , kw , ecl_type = ECL_FLOAT_TYPE): + def grdecl_load( cls , file , kw , ecl_type = EclTypeEnum.ECL_FLOAT_TYPE): """Use read_grdecl() instead.""" #warnings.warn("The grdecl_load method has been renamed to read_grdecl()" , DeprecationWarning) return cls.read_grdecl(file , kw , ecl_type ) @@ -343,15 +338,15 @@ class EclKW(CClass): def __init(self): self.data_ptr = None self.ecl_type = cfunc.get_type( self ) - if self.ecl_type == ECL_INT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_INT_TYPE: self.data_ptr = cfunc.int_ptr( self ) self.dtype = numpy.int32 self.str_fmt = "%8d" - elif self.ecl_type == ECL_FLOAT_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_FLOAT_TYPE: self.data_ptr = cfunc.float_ptr( self ) self.dtype = numpy.float32 self.str_fmt = "%13.4f" - elif self.ecl_type == ECL_DOUBLE_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_DOUBLE_TYPE: self.data_ptr = cfunc.double_ptr( self ) self.dtype = numpy.float64 self.str_fmt = "%13.4f" @@ -359,9 +354,9 @@ class EclKW(CClass): # Iteration not supported for CHAR / BOOL self.data_ptr = None self.dtype = None - if self.ecl_type == ECL_CHAR_TYPE: + if self.ecl_type == EclTypeEnum.ECL_CHAR_TYPE: self.str_fmt = "%8s" - elif self.ecl_type == ECL_BOOL_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_BOOL_TYPE: self.str_fmt = "%d" else: self.str_fmt = "%s" #"Message type" @@ -398,9 +393,9 @@ class EclKW(CClass): if self.data_ptr: return self.data_ptr[ index ] else: - if self.ecl_type == ECL_BOOL_TYPE: + if self.ecl_type == EclTypeEnum.ECL_BOOL_TYPE: return cfunc.iget_bool( self, index) - elif self.ecl_type == ECL_CHAR_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_CHAR_TYPE: return cfunc.iget_char_ptr( self , index ) else: raise TypeError("Internal implementation error ...") @@ -426,9 +421,9 @@ class EclKW(CClass): if self.data_ptr: self.data_ptr[ index ] = value else: - if self.ecl_type == ECL_BOOL_TYPE: + if self.ecl_type == EclTypeEnum.ECL_BOOL_TYPE: cfunc.iset_bool( self , index , value) - elif self.ecl_type == ECL_CHAR_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_CHAR_TYPE: return cfunc.iset_char_ptr( self , index , value) else: raise SystemError("Internal implementation error ...") @@ -453,7 +448,7 @@ class EclKW(CClass): if not mul: factor = 1.0 / factor - if self.ecl_type == ECL_INT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_INT_TYPE: if isinstance( factor , int ): cfunc.scale_int( self , factor ) else: @@ -485,7 +480,7 @@ class EclKW(CClass): else: sign = -1 - if self.ecl_type == ECL_INT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_INT_TYPE: if isinstance( delta , int ): cfunc.shift_int( self , delta * sign) else: @@ -607,7 +602,7 @@ class EclKW(CClass): if mask: mask.set_kw( self , value , force_active ) else: - if self.ecl_type == ECL_INT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_INT_TYPE: if isinstance( value , int ): cfunc.set_int( self , value ) else: @@ -754,17 +749,17 @@ class EclKW(CClass): @property def type( self ): # enum ecl_type_enum from ecl_util.h - if self.ecl_type == ECL_CHAR_TYPE: + if self.ecl_type == EclTypeEnum.ECL_CHAR_TYPE: return "CHAR" - if self.ecl_type == ECL_FLOAT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_FLOAT_TYPE: return "REAL" - if self.ecl_type == ECL_DOUBLE_TYPE: + if self.ecl_type == EclTypeEnum.ECL_DOUBLE_TYPE: return "DOUB" - if self.ecl_type == ECL_INT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_INT_TYPE: return "INTE" - if self.ecl_type == ECL_BOOL_TYPE: + if self.ecl_type == EclTypeEnum.ECL_BOOL_TYPE: return "BOOL" - if self.ecl_type == ECL_MESS_TYPE: + if self.ecl_type == EclTypeEnum.ECL_MESS_TYPE: return "MESS" @@ -776,15 +771,15 @@ class EclKW(CClass): Will raise TypeError exception if the keyword is not of numerical type. """ - if self.ecl_type == ECL_FLOAT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_FLOAT_TYPE: min = ctypes.c_float() max = ctypes.c_float() cfunc.max_min_float( self , ctypes.byref( max ) , ctypes.byref( min )) - elif self.ecl_type == ECL_DOUBLE_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_DOUBLE_TYPE: min = ctypes.c_double() max = ctypes.c_double() cfunc.max_min_double( self , ctypes.byref( max ) , ctypes.byref( min )) - elif self.ecl_type == ECL_INT_TYPE: + elif self.ecl_type == EclTypeEnum.ECL_INT_TYPE: min = ctypes.c_int() max = ctypes.c_int() cfunc.max_min_int( self , ctypes.byref( max ) , ctypes.byref( min )) @@ -805,11 +800,11 @@ class EclKW(CClass): @property def numeric(self): - if self.ecl_type == ECL_FLOAT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_FLOAT_TYPE: return True - if self.ecl_type == ECL_DOUBLE_TYPE: + if self.ecl_type == EclTypeEnum.ECL_DOUBLE_TYPE: return True - if self.ecl_type == ECL_INT_TYPE: + if self.ecl_type == EclTypeEnum.ECL_INT_TYPE: return True return False @@ -820,7 +815,7 @@ class EclKW(CClass): @property def type_name( self ): - return ecl_util.type_name( self.ecl_type ) + return EclUtil.type_name( self.ecl_type ) @property def header( self ): @@ -828,7 +823,8 @@ class EclKW(CClass): def iget( self , index ): - raise DeprecationWarning("The iget() method is deprecated use array notation: kw[index] instead.") + from warnings import warn + warn("The iget() method is deprecated use array notation: kw[index] instead.", DeprecationWarning) return self.__getitem__( index ) @@ -962,7 +958,7 @@ class EclKW(CClass): # 2. Creating a wrapper object around the libecl library, # registering the type map : ecl_kw <-> EclKW -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_kw" , EclKW ) # 3. Installing the c-functions used to manipulate ecl_kw instances. diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_local.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_local.py deleted file mode 100644 index a2c6642432..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_local.py +++ /dev/null @@ -1,72 +0,0 @@ -import os -import socket -import sys -import ert.job_queue.driver as driver - -################################################################# -# Only a quite few of the Linux computers in Statoil are proper LSF -# nodes, in the sense that they can talk directly to the LSF -# demons. When using LSF from a computer which is not properly part of -# the LSF cluster you must first ssh to a node which can serve as LSF -# server, and then issue the LSF commands there. This is controlled by -# the LSF_SERVER option in the LSF driver. -# -# In this configuration file the LSF server to use is determined by -# using the two first characters from the name of the submitting host -# as a lookup key in the server_list dictionary. -# -# If your workstation has proper access to LSF you can set the -# environment variable LOCAL_LSF; in that case the lsf_server variable -# will be left at None and the LSF driver instance will issue the LSF -# commands directly at the calling host without going through ssh. -# -# Observe that the ssh-based scheme requires that you have -# passwordless login to the server used as lsf server. -################################################################# - -server_list = { "be" : "be-grid01.be.statoil.no", - "st" : "st-grid01.st.statoil.no", - "tr" : "tr-grid01.tr.statoil.no", - "stj" : "tr-grid01.tr.statoil.no", - "rio" : "rio-grid01.rio.statoil.no" } - - -def get_lsf_server(): - if os.getenv("LOCAL_LSF"): - # The user has set the LOCAL_LSF environment variable - - # signalling that she has access to a proper LSF node. - return None - else: - host = socket.gethostname() - host_prefix = host.split("-")[0] - lsf_server = server_list.get( host_prefix , None) - # This will silently return None if no appropriate LSF server - # is found. In that case things will blow up at a later stage - # if/when someone tries to use the invalid lsf server. - return lsf_server - - -# The command used to run ECLIPSE. The executable will be called with -# commandline arguments: version data_file num_cpu -ecl_cmd = "/project/res/etc/ERT/Scripts/run_eclipse.py" - -# The ECLIPSE version which will be used, by default. -ecl_version = "2010.2" - -# The resource request passed to the LSF server. In practice every god-damn compute node -# in Statoil will satisfy these needs, so it could just be left as None. -lsf_resource_request = "select[cs && x86_64Linux] rusage[ecl100v2000=1:duration=5]" - -lsf_queue = "normal" -rsh_command = "/usr/bin/ssh" - -driver_options = { driver.LSF_DRIVER : [("LSF_QUEUE" , lsf_queue), - ("LSF_RESOURCE" , lsf_resource_request), - ("LSF_SERVER" , get_lsf_server())], - driver.RSH_DRIVER : [("RSH_COMMAND" , rsh_command)], - driver.LOCAL_DRIVER : []} - -driver_type = driver.LSF_DRIVER - - - diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_queue.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_queue.py index 3487dcd9a1..840d35e3b2 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_queue.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_queue.py @@ -34,23 +34,19 @@ the EclQueue class it is important to consult the documentation of the JobQueue class in ert.job_queue.queue as well. """ import os.path - -from ert.job_queue.queue import JobQueue -import ert.job_queue.driver as queue_driver -import libecl -from ecl_default import default -import ecl_util +from ert.ecl import EclUtil, EclDefault +from ert.job_queue import JobQueue, Driver -class EclQueue( JobQueue ): - def __init__(self , - driver = None , - driver_type = None, - driver_options = None, - ecl_version = None, - ecl_cmd = None, - max_running = 0, - size = 0): +class EclQueue(JobQueue): + def __init__(self, + driver=None, + driver_type=None, + driver_options=None, + ecl_version=None, + ecl_cmd=None, + max_running=0, + size=0): """ Create a new queue instance to manage ECLIPSE simulations. @@ -146,24 +142,25 @@ class EclQueue( JobQueue ): after the main thread has exited - not yet :-( """ if ecl_cmd is None: - ecl_cmd = ecl_default.default.ecl_cmd - + ecl_cmd = EclDefault.ecl_cmd() + if driver_type is None: - driver_type = ecl_default.default.driver_type + driver_type = EclDefault.driver_type() if ecl_version is None: - ecl_version = ecl_default.default.ecl_version + ecl_version = EclDefault.ecl_version() self.ecl_version = ecl_version - self.ecl_cmd = ecl_cmd + self.ecl_cmd = ecl_cmd if driver is None: if driver_options is None: - driver_options = default.driver_options[ driver_type ] - driver = queue_driver.Driver( driver_type , max_running = max_running , options = driver_options ) - JobQueue.__init__( self , driver , size = size) + driver_options = EclDefault.driver_options()[driver_type] + driver = Driver(driver_type, max_running=max_running, options=driver_options) - - def submit( self , data_file): + JobQueue.__init__(self, driver, size=size) + + + def submit( self, data_file): """ Will submit a new simulation of case given by @data_file. @@ -171,9 +168,10 @@ class EclQueue( JobQueue ): ert.job_queue.queue.job module which can be used to query the status of the job while it is running. """ - (path_base , ext) = os.path.splitext( data_file ) - (run_path , base) = os.path.split( path_base ) - - argv = [ self.ecl_version , path_base , "%s" % ecl_util.get_num_cpu( data_file )] - return JobQueue.submit( self , self.ecl_cmd , run_path , base , argv) + (path_base, ext) = os.path.splitext(data_file) + (run_path, base) = os.path.split(path_base) + + num_cpu = EclUtil.get_num_cpu(data_file) + argv = [self.ecl_version, path_base, "%s" % num_cpu] + return JobQueue.submit(self, self.ecl_cmd, run_path, base, argv, num_cpu=num_cpu) diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_region.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_region.py index 2c95f114d3..300a065bad 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_region.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_region.py @@ -25,16 +25,52 @@ combined e.g. with logical &. When the selection process is complete the region instance can be queried for the corresponding list of indices. """ +import ctypes import warnings -import libecl -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import IntVector -from ert.geo.geo_polygon import GeoPolygon -from ecl_kw import ECL_INT_TYPE , ECL_FLOAT_TYPE , ECL_DOUBLE_TYPE, EclKW -import ecl_grid +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.ecl import EclKW, EclTypeEnum, ECL_LIB +from ert.geo import GeoPolygon +from ert.util import IntVector +def select_method(select): + """ + The select_method method decorator is applied to all the + select_xxx() methods. The purpose of this decorator is to + allow the select_xxx() methods to have an optional argument + @intersect. If the @intersect argument is True the results of + the current select method will be and'ed with the current + selection, instead of or'ed which is the default. + + Consider this example: + + region = EclRegion( grid , False ) + region.select_islice(0 , 5) # Selects all cells with i:[0:5] + region.select_jslice(0 , 5) # Selects all cells with j:[0:5] + + When these two calls have completed selection will contain all + the cells which are either in i-interval [0:5] or in + j-interval [0:5]. If we supply the @intersect argument in the + second call the j selection will only be applied to the cells + in i:[0:5] interval: + + region = EclRegion( grid , False ) + region.select_islice(0 , 5) # Selects all cells with i:[0:5] + region.select_jslice(0 , 5) # Selects all cells with j:[0:5] AND i:[0:5] + """ + + def select_wrapper(self , *args , **kwargs): + intersect = kwargs.has_key('intersect') and kwargs['intersect'] + if intersect: + new_region = EclRegion( self.grid , False ) + select(new_region , *args ) + + self &= new_region + else: + select(self , *args ) + + return select_wrapper + class EclRegion(CClass): @@ -203,45 +239,6 @@ class EclRegion(CClass): ################################################################## - - def select_method(select): - """ - The select_method method decorator is applied to all the - select_xxx() methods. The purpose of this decorator is to - allow the select_xxx() methods to have an optional argument - @intersect. If the @intersect argument is True the results of - the current select method will be and'ed with the current - selection, instead of or'ed which is the default. - - Consider this example: - - region = EclRegion( grid , False ) - region.select_islice(0 , 5) # Selects all cells with i:[0:5] - region.select_jslice(0 , 5) # Selects all cells with j:[0:5] - - When these two calls have completed selection will contain all - the cells which are either in i-interval [0:5] or in - j-interval [0:5]. If we supply the @intersect argument in the - second call the j selection will only be applied to the cells - in i:[0:5] interval: - - region = EclRegion( grid , False ) - region.select_islice(0 , 5) # Selects all cells with i:[0:5] - region.select_jslice(0 , 5) # Selects all cells with j:[0:5] AND i:[0:5] - """ - - def select_wrapper(self , *args , **kwargs): - intersect = kwargs.has_key('intersect') and kwargs['intersect'] - if intersect: - new_region = EclRegion( self.grid , False ) - select(new_region , *args ) - - self &= new_region - else: - select(self , *args ) - - return select_wrapper - @select_method def select_more( self , ecl_kw , limit , intersect = False): @@ -735,9 +732,9 @@ class EclRegion(CClass): """ See usage documentation on iadd_kw(). """ - self.scalar_apply_kw( ecl_kw , shift , {ECL_INT_TYPE : cfunc.shift_kw_int, - ECL_FLOAT_TYPE : cfunc.shift_kw_float , - ECL_DOUBLE_TYPE : cfunc.shift_kw_double} , force_active) + self.scalar_apply_kw( ecl_kw , shift , {EclTypeEnum.ECL_INT_TYPE : cfunc.shift_kw_int, + EclTypeEnum.ECL_FLOAT_TYPE : cfunc.shift_kw_float , + EclTypeEnum.ECL_DOUBLE_TYPE : cfunc.shift_kw_double} , force_active) def isub_kw( self , target_kw , delta_kw , force_active = False): if isinstance(delta_kw , EclKW): @@ -753,9 +750,9 @@ class EclRegion(CClass): """ See usage documentation on iadd_kw(). """ - self.scalar_apply_kw( ecl_kw , scale , {ECL_INT_TYPE : cfunc.scale_kw_int, - ECL_FLOAT_TYPE : cfunc.scale_kw_float , - ECL_DOUBLE_TYPE : cfunc.scale_kw_double} , force_active) + self.scalar_apply_kw( ecl_kw , scale , {EclTypeEnum.ECL_INT_TYPE : cfunc.scale_kw_int, + EclTypeEnum.ECL_FLOAT_TYPE : cfunc.scale_kw_float , + EclTypeEnum.ECL_DOUBLE_TYPE : cfunc.scale_kw_double} , force_active) def imul_kw( self , target_kw , other , force_active = False): if isinstance(other , EclKW): @@ -790,9 +787,9 @@ class EclRegion(CClass): """ See usage documentation on iadd_kw(). """ - self.scalar_apply_kw( ecl_kw , value , {ECL_INT_TYPE : cfunc.set_kw_int, - ECL_FLOAT_TYPE : cfunc.set_kw_float , - ECL_DOUBLE_TYPE : cfunc.set_kw_double} , force_active) + self.scalar_apply_kw( ecl_kw , value , {EclTypeEnum.ECL_INT_TYPE : cfunc.set_kw_int, + EclTypeEnum.ECL_FLOAT_TYPE : cfunc.set_kw_float , + EclTypeEnum.ECL_DOUBLE_TYPE : cfunc.set_kw_double} , force_active) @@ -813,7 +810,7 @@ class EclRegion(CClass): IntVector instance with active indices in the region. """ c_ptr = cfunc.get_active_list( self ) - active_list = IntVector.ref( c_ptr , self ) + active_list = IntVector.asPythonReference( c_ptr , self ) return active_list @property @@ -822,7 +819,7 @@ class EclRegion(CClass): IntVector instance with global indices in the region. """ c_ptr = cfunc.get_global_list( self ) - global_list = IntVector.ref( c_ptr , self ) + global_list = IntVector.asPythonReference( c_ptr , self ) return global_list @property @@ -864,7 +861,7 @@ class EclRegion(CClass): def kw_index_list(self , ecl_kw , force_active): c_ptr = cfunc.get_kw_index_list( self , ecl_kw , force_active) - index_list = IntVector.ref( c_ptr , self ) + index_list = IntVector.asPythonReference( c_ptr , self ) return index_list @@ -878,7 +875,7 @@ class EclRegion(CClass): # 2. Creating a wrapper object around the libecl library. -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_region" , EclRegion ) # 3. Installing the c-functions used to manipulate. diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft.py index d567759a1f..1544a1b96d 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft.py @@ -17,18 +17,28 @@ Module for loading ECLIPSE RFT files. """ -import libecl -import ctypes import types -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.ctime import ctime +import warnings +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.ecl import EclRFTCell, EclPLTCell, ECL_LIB +from ert.util import ctime -RFT = 1 -PLT = 2 - class EclRFTFile(CClass): + """ + The EclRFTFile class is used to load an ECLIPSE RFT file. + + The EclRFTFile serves as a container which can load and hold the + content of an ECLIPSE RFT file. The RFT files will in general + contain data for several wells and several times in one large + container. The EclRFTClass class contains methods get the the RFT + results for a specific time and/or well. + + The EclRFTFile class can in general contain a mix of RFT and PLT + measurements. The class does not really differentiate between + these. + """ + def __new__( cls , case ): c_ptr = cfunc_file.load( case ) if c_ptr: @@ -53,29 +63,63 @@ class EclRFTFile(CClass): else: raise TypeError("Index should be integer type") - - @property def size( self , well = None , date = None): - return cfunc_file.get_size( self , well , -1) + """ + The number of elements in EclRFTFile container. + + By default the size() method will return the total number of + RFTs/PLTs in the container, but by specifying the optional + arguments date and/or well the function will only count the + number of well measurements matching that time or well + name. The well argument can contain wildcards. + + rftFile = ecl.EclRFTFile( "ECLIPSE.RFT" ) + print "Total number of RFTs : %d" % rftFile.size( ) + print "RFTs matching OP* : %d" % rftFile.size( well = "OP*" ) + print "RFTs at 01/01/2010 : %d" % rftFile.size( date = datetime.date( 2010 , 1 , 1 )) + + """ + if date: + cdate = ctime( date ) + else: + cdate = -1 + + return cfunc_file.get_size( self , well , cdate) + @property def num_wells( self ): + """ + Returns the total number of distinct wells in the RFT file. + """ return cfunc_file.get_num_wells( self ) @property def headers(self): + """ + Returns a list of two tuples (well_name , date) for the whole file. + """ header_list = [] for i in (range(cfunc_file.get_size( self , None , -1))): rft = self.iget( i ) - print rft header_list.append( (rft.well , rft.date) ) return header_list + def iget(self , index): + """ + Will lookup RFT @index - equivalent to [@index]. + """ return self.__getitem__( index ) + def get(self , well_name , date ): + """ + Will look up the RFT object corresponding to @well and @date. + + Returns None if no matching RFT can be found. + """ c_ptr = cfunc_file.get_rft( self , well_name , ctime( date )) if c_ptr: return EclRFT( c_ptr , self) @@ -87,13 +131,56 @@ class EclRFTFile(CClass): class EclRFT(CClass): + """The EclRFT class contains the information for *one* RFT. + + The ECLIPSE RFT file can contain three different types of RFT like + objects which are lumped together; the EclRFTClass is a container + for such objects. The three different object types which can be + found in an RFT file are: + + RFT: This is old-fashioned RFT which contains measurements of + saturations for each of the completed cells. + + PLT: This contains production and flow rates for each phase in + each cell. + + SEGMENT: Not implemented. + + In addition to the measurements specific for RFT and PLT each cell + has coordinates, pressure and depth. + """ def __init__(self , c_ptr , parent): self.init_cref( c_ptr , parent ) - def __len__(self): + """ + The number of completed cells in this RFT. + """ return cfunc_rft.get_size( self ) + def is_RFT(self): + """ + Is instance an RFT; in that case all the cells will be EclRFTCell instances. + """ + return cfunc_rft.is_RFT( self ) + + def is_PLT(self): + """ + Is instance a PLT; in that case all the cells will be EclPLTCell instances. + """ + return cfunc_rft.is_PLT( self ) + + def is_SEGMENT(self): + """ + Is this a SEGMENT - not implemented. + """ + return cfunc_rft.is_SEGMENT( self ) + + def is_MSW(self): + """ + Is this well a MSW well. Observe that the test ONLY applies to PLTs. + """ + return cfunc_rft.is_MSW( self ) @property @@ -102,176 +189,165 @@ class EclRFT(CClass): # RFT = 1 # PLT = 2 # Segment = 3 -- Not properly implemented + """ + Deprecated - use query methods: is_RFT(), is_PLT() and is_SEGMENT() instead. + """ + warnings.warn("The property type is deprecated, use the query methods is_RFT(), is_PLT() and is_SEGMENT() instead.") return cfunc_rft.get_type( self ) @property def well(self): + """ + The name of the well we are considering. + """ return cfunc_rft.get_well( self ) @property def date(self): + """ + The date when this RFT/PLT/... was recorded. + """ return cfunc_rft.get_date( self ) @property def size(self): + """ + The number of completed cells. + """ return self.__len__() - def __make_node( self , index ): - i = ctypes.c_int() - j = ctypes.c_int() - k = ctypes.c_int() - pressure = cfunc_rft.iget_pressure( self, index ) - depth = cfunc_rft.iget_depth( self, index ) - cfunc_rft.iget_ijk( self, index , ctypes.byref(i), ctypes.byref(j) , ctypes.byref(k)) - - - if self.type == RFT: - swat = cfunc_rft.iget_swat( self, index ) - sgas = cfunc_rft.iget_sgas( self, index ) - return EclRFTCell.RFTCell( i,j,k,depth , pressure,swat,sgas) + def __cell_ref( self , cell_ptr ): + if self.is_RFT(): + return EclRFTCell.asPythonReference( cell_ptr , self ) + elif self.is_PLT(): + return EclPLTCell.asPythonReference( cell_ptr , self ) else: - orat = cfunc_rft.iget_orat( self, index ) - wrat = cfunc_rft.iget_wrat( self, index ) - grat = cfunc_rft.iget_grat( self, index ) - return EclRFTCell.PLTCell( i,j,k,depth , pressure,orat,grat,wrat) + raise NotImplementedError("Only RFT and PLT cells are implemented") - def __getitem__(self , index): + + def assert_cell_index( self , index ): if isinstance( index , types.IntType): length = self.__len__() if index < 0 or index >= length: raise IndexError - else: - return self.__make_node( index ) else: raise TypeError("Index should be integer type") + + def __getitem__(self , index): + """Implements the [] operator to return the cells. + + To get the object related to cell nr 5: + + cell = rft[4] + + The return value from the __getitem__() method is either an + EclRFTCell instance or a EclPLTCell instance, depending on the + type of this particular RFT object. + """ + self.assert_cell_index( index ) + cell_ptr = cfunc_rft.iget_cell( self , index ) + return self.__cell_ref( cell_ptr ) + + def iget( self , index ): return self.__getitem__( index ) + + def iget_sorted( self , index ): + """ + Will return the cell nr @index in the list of sorted cells. + + See method sort() for further documentation. + """ + self.assert_cell_index( index ) + cell_ptr = cfunc_rft.iget_cell_sorted( self , index ) + return self.__cell_ref( cell_ptr ) + + + def sort(self): + """ + Will sort cells in RFT; currently only applies to MSW wells. + + By default the cells in the RFT come in the order they are + specified in the ECLIPSE input file; that is not necessarily + in a suitable order. In the case of MSW wells it is possible + to sort the connections after distance along the wellpath. To + access the cells in sort order you have two options: + + 1. Sort the cells using the sort() method, and then + subsequently access them sequentially: + + rft.sort() + for cell in rft: + print cell + + 2. Let the rft object stay unsorted, but access the cells + using the iget_sorted() method: + + for i in range(len(rft)): + cell = rft.iget_sorted( i ) + + Currently only MSW/PLTs are sorted, based on the CONLENST + keyword; for other wells the sort() method does nothing. + """ + cfunc_rft.sort_cells( self ) + # ijk are zero offset def ijkget( self , ijk ): - index = cfunc_rft.lookup_ijk( self , ijk[0] , ijk[1] , ijk[2]) - if index >= 0: - return self.iget( index ) + """ + Will look up the cell based on (i,j,k). + + If the cell (i,j,k) is not part of this RFT/PLT None will be + returned. The (i,j,k) input values should be zero offset, + i.e. you must subtract 1 from the (i,j,k) values given in the ECLIPSE input. + """ + cell_ptr = cfunc_rft.lookup_ijk( self , ijk[0] , ijk[1] , ijk[2]) + if cell_ptr: + return self.__cell_ref( cell_ptr ) else: return None -class EclRFTCell: - def __init__(self , type , i , j , k , depth , pressure): - self.type = type - self.__i = i - self.__j = j - self.__k = k - self.__depth = depth - self.__pressure = pressure - - self.__sgas = None - self.__swat = None - self.__orat = None - self.__wrat = None - self.__grat = None - - @classmethod - def RFTCell( cls , i,j,k,depth,pressure,swat,sgas): - cell = cls(RFT , i,j,k,depth,pressure) - cell.__swat = swat - cell.__sgas = sgas - return cell - - @classmethod - def PLTCell(cls , i,j,k,depth,pressure,orat,grat,wrat): - cell = cls(PLT , i,j,k,depth,pressure) - cell.__orat = orat - cell.__wrat = wrat - cell.__grat = grat - return cell - - @property - def i(self): - return self.__i.value - - @property - def j(self): - return self.__j.value - - @property - def k(self): - return self.__k.value - - @property - def ijk(self): - return (self.__i.value , self.__j.value , self.__k.value) - - @property - def pressure(self): - return self.__pressure - - @property - def depth(self): - return self.__depth - - @property - def PLT(self): - if self.type == PLT: - return True - else: - return False - - @property - def sgas(self): - return self.__sgas - - @property - def swat(self): - return self.__swat - - @property - def orat(self): - return self.__orat - - @property - def grat(self): - return self.__grat - - @property - def wrat(self): - return self.__wrat - - # 2. Creating a wrapper object around the libecl library, # registering the type map : ecl_kw <-> EclKW -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_rft_file" , EclRFTFile ) cwrapper.registerType( "ecl_rft" , EclRFT ) cfunc_file = CWrapperNameSpace("ecl_rft_file") cfunc_rft = CWrapperNameSpace("ecl_rft") -cfunc_file.load = cwrapper.prototype("long ecl_rft_file_alloc_case( char* )") +cfunc_file.load = cwrapper.prototype("c_void_p ecl_rft_file_alloc_case( char* )") cfunc_file.has_rft = cwrapper.prototype("bool ecl_rft_file_case_has_rft( char* )") cfunc_file.free = cwrapper.prototype("void ecl_rft_file_free( ecl_rft_file )") cfunc_file.get_size = cwrapper.prototype("int ecl_rft_file_get_size__( ecl_rft_file , char* , time_t)") -cfunc_file.iget = cwrapper.prototype("long ecl_rft_file_iget_node( ecl_rft_file , int )") +cfunc_file.iget = cwrapper.prototype("c_void_p ecl_rft_file_iget_node( ecl_rft_file , int )") cfunc_file.get_num_wells = cwrapper.prototype("int ecl_rft_file_get_num_wells( ecl_rft_file )") -cfunc_file.get_rft = cwrapper.prototype("long ecl_rft_file_get_well_time_rft( ecl_rft_file , char* , time_t)") - -cfunc_rft.get_type = cwrapper.prototype("int ecl_rft_node_get_type( ecl_rft )") -cfunc_rft.get_well = cwrapper.prototype("char* ecl_rft_node_get_well_name( ecl_rft )") -cfunc_rft.get_date = cwrapper.prototype("time_t ecl_rft_node_get_date( ecl_rft )") -cfunc_rft.get_size = cwrapper.prototype("int ecl_rft_node_get_size( ecl_rft )") -cfunc_rft.iget_depth = cwrapper.prototype("double ecl_rft_node_iget_depth( ecl_rft )") -cfunc_rft.iget_pressure = cwrapper.prototype("double ecl_rft_node_iget_pressure(ecl_rft)") -cfunc_rft.iget_ijk = cwrapper.prototype("void ecl_rft_node_iget_ijk( ecl_rft , int , int*, int*, int*)") -cfunc_rft.iget_swat = cwrapper.prototype("double ecl_rft_node_iget_swat(ecl_rft)") -cfunc_rft.iget_sgas = cwrapper.prototype("double ecl_rft_node_iget_sgas(ecl_rft)") -cfunc_rft.iget_orat = cwrapper.prototype("double ecl_rft_node_iget_orat(ecl_rft)") -cfunc_rft.iget_wrat = cwrapper.prototype("double ecl_rft_node_iget_wrat(ecl_rft)") -cfunc_rft.iget_grat = cwrapper.prototype("double ecl_rft_node_iget_grat(ecl_rft)") -cfunc_rft.lookup_ijk = cwrapper.prototype("int ecl_rft_node_lookup_ijk( ecl_rft , int , int , int)") +cfunc_file.get_rft = cwrapper.prototype("c_void_p ecl_rft_file_get_well_time_rft( ecl_rft_file , char* , time_t)") +cfunc_rft.get_type = cwrapper.prototype("int ecl_rft_node_get_type( ecl_rft )") +cfunc_rft.get_well = cwrapper.prototype("char* ecl_rft_node_get_well_name( ecl_rft )") +cfunc_rft.get_date = cwrapper.prototype("time_t ecl_rft_node_get_date( ecl_rft )") +cfunc_rft.get_size = cwrapper.prototype("int ecl_rft_node_get_size( ecl_rft )") +cfunc_rft.iget_cell = cwrapper.prototype("c_void_p ecl_rft_node_iget_cell( ecl_rft )") +cfunc_rft.iget_cell_sorted = cwrapper.prototype("c_void_p ecl_rft_node_iget_cell_sorted( ecl_rft )") +cfunc_rft.sort_cells = cwrapper.prototype("c_void_p ecl_rft_node_inplace_sort_cells( ecl_rft )") +cfunc_rft.iget_depth = cwrapper.prototype("double ecl_rft_node_iget_depth( ecl_rft )") +cfunc_rft.iget_pressure = cwrapper.prototype("double ecl_rft_node_iget_pressure(ecl_rft)") +cfunc_rft.iget_ijk = cwrapper.prototype("void ecl_rft_node_iget_ijk( ecl_rft , int , int*, int*, int*)") +cfunc_rft.iget_swat = cwrapper.prototype("double ecl_rft_node_iget_swat(ecl_rft)") +cfunc_rft.iget_sgas = cwrapper.prototype("double ecl_rft_node_iget_sgas(ecl_rft)") +cfunc_rft.iget_orat = cwrapper.prototype("double ecl_rft_node_iget_orat(ecl_rft)") +cfunc_rft.iget_wrat = cwrapper.prototype("double ecl_rft_node_iget_wrat(ecl_rft)") +cfunc_rft.iget_grat = cwrapper.prototype("double ecl_rft_node_iget_grat(ecl_rft)") +cfunc_rft.lookup_ijk = cwrapper.prototype("c_void_p ecl_rft_node_lookup_ijk( ecl_rft , int , int , int)") +cfunc_rft.is_RFT = cwrapper.prototype("bool ecl_rft_node_is_RFT( ecl_rft )") +cfunc_rft.is_PLT = cwrapper.prototype("bool ecl_rft_node_is_PLT( ecl_rft )") +cfunc_rft.is_SEGMENT = cwrapper.prototype("bool ecl_rft_node_is_SEGMENT( ecl_rft )") +cfunc_rft.is_MSW = cwrapper.prototype("bool ecl_rft_node_is_MSW( ecl_rft )") diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft_cell.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft_cell.py new file mode 100644 index 0000000000..b853386c85 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_rft_cell.py @@ -0,0 +1,227 @@ +# Copyright (C) 2011 Statoil ASA, Norway. +# +# The file 'ecl_rft_cell.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +import warnings +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.ecl import ECL_LIB + + +class RFTCell(CClass): + """The RFTCell is a base class for the cells which are part of an RFT/PLT. + + The RFTCell class contains the elements which are common to both + RFT and PLT. The list of common elements include the corrdinates + (i,j,k) the pressure and the depth of the cell. Actual user access + should be based on the derived classes EclRFTCell and EclPLTCell. + + Observe that from june 2013 the properties i,j and k which return + offset 1 coordinate values are deprecated, and you should rather + use the methods get_i(), get_j() and get_k() which return offset 0 + coordinate values. + """ + + + def warn(self , old , new): + msg = """ + +The cell property:%s has been deprecated, and the method:%s() should +be used instead. Observe that the new method %s() returns coordinate +values starting at 0, whereas the old property %s returned values +starting at 1; hence you must adapt the calling code when you change +from %s -> %s() +""" % (old , new , new , old , old , new) + warnings.warn( msg , DeprecationWarning ) + + @property + def i(self): + self.warn("i" , "get_i") + return self.get_i() + 1 + + @property + def j(self): + self.warn("j" , "get_j") + return self.get_j() + 1 + + @property + def k(self): + self.warn("k" , "get_k") + return self.get_k() + 1 + + @property + def ijk(self): + self.warn("ijk" , "get_ijk") + return (self.get_i() + 1 , self.get_j() + 1 , self.get_k() + 1) + + def get_i(self): + return cfunc.get_i( self ) + + def get_j(self): + return cfunc.get_j( self ) + + def get_k(self): + return cfunc.get_k( self ) + + def get_ijk(self): + return (cfunc.get_i( self ) , cfunc.get_j( self ) , cfunc.get_k( self )) + + @property + def pressure(self): + return cfunc.get_pressure( self ) + + @property + def depth(self): + return cfunc.get_depth( self ) + + +################################################################# + + +class EclRFTCell(RFTCell): + + @classmethod + def new(cls , i , j , k , depth , pressure , swat , sgas ): + cell = EclRFTCell() + c_ptr = cfunc.alloc_RFT( i,j,k,depth,pressure,swat,sgas) + cell.init_cobj( c_ptr , cfunc.free ) + return cell + + @classmethod + def asPythonReference(cls, c_ptr , parent): + cell = EclRFTCell() + cell.init_cref( c_ptr , parent ) + return cell + + @property + def swat(self): + return cfunc.get_swat( self ) + + @property + def sgas(self): + return cfunc.get_sgas( self ) + + @property + def soil(self): + return 1 - (cfunc.get_sgas( self ) + cfunc.get_swat( self )) + + +################################################################# + + +class EclPLTCell(RFTCell): + + @classmethod + def new(self , i , j , k , depth , pressure , orat , grat , wrat , conn_start ,conn_end, flowrate , oil_flowrate , gas_flowrate , water_flowrate ): + cell = EclPLTCell() + c_ptr = cfunc.alloc_PLT( i,j,k,depth,pressure,orat , grat , wrat , conn_start , conn_end, flowrate , oil_flowrate , gas_flowrate , water_flowrate) + cell.init_cobj( c_ptr , cfunc.free ) + return cell + + @classmethod + def asPythonReference(cls, c_ptr , parent): + cell = EclPLTCell() + cell.init_cref( c_ptr , parent ) + return cell + + @property + def orat(self): + return cfunc.get_orat( self ) + + @property + def grat(self): + return cfunc.get_grat( self ) + + @property + def wrat(self): + return cfunc.get_wrat( self ) + + @property + def conn_start(self): + """Will return the length from wellhead(?) to connection. + + For MSW wells this property will return the distance from a + fixed point (wellhead) to the current connection. This value + will be used to sort the completed cells along the well + path. In the case of non MSW wells this will just return a + fixed default value. + """ + return cfunc.get_conn_start( self ) + + @property + def conn_end(self): + """Will return the length from wellhead(?) to connection end. + + For MSW wells this property will return the distance from a + fixed point (wellhead) to the current connection end. This value + will be used to sort the completed cells along the well + path. In the case of non MSW wells this will just return a + fixed default value. + """ + return cfunc.get_conn_end( self ) + + @property + def flowrate(self): + return cfunc.get_flowrate( self ) + + @property + def oil_flowrate(self): + return cfunc.get_oil_flowrate( self ) + + @property + def gas_flowrate(self): + return cfunc.get_gas_flowrate( self ) + + @property + def water_flowrate(self): + return cfunc.get_water_flowrate( self ) + + +################################################################# + + +cwrapper = CWrapper(ECL_LIB) +cwrapper.registerType( "rft_cell" , RFTCell) +cwrapper.registerType( "ecl_rft_cell" , EclRFTCell ) +cwrapper.registerType( "ecl_plt_cell" , EclPLTCell ) + +cfunc = CWrapperNameSpace("ecl_rft_cell") + +cfunc.alloc_RFT = cwrapper.prototype("c_void_p ecl_rft_cell_alloc_RFT( int, int , int , double , double , double , double)") +cfunc.alloc_PLT = cwrapper.prototype("c_void_p ecl_rft_cell_alloc_PLT( int, int , int , double , double , double, double , double, double , double , double , double , double , double )") +cfunc.free = cwrapper.prototype("void ecl_rft_cell_free( rft_cell )") + +cfunc.get_pressure = cwrapper.prototype("double ecl_rft_cell_get_pressure( rft_cell )") +cfunc.get_depth = cwrapper.prototype("double ecl_rft_cell_get_depth( rft_cell )") +cfunc.get_i = cwrapper.prototype("int ecl_rft_cell_get_i( rft_cell )") +cfunc.get_j = cwrapper.prototype("int ecl_rft_cell_get_j( rft_cell )") +cfunc.get_k = cwrapper.prototype("int ecl_rft_cell_get_k( rft_cell )") + +cfunc.get_swat = cwrapper.prototype("double ecl_rft_cell_get_swat( ecl_rft_cell )") +cfunc.get_soil = cwrapper.prototype("double ecl_rft_cell_get_soil( ecl_rft_cell )") +cfunc.get_sgas = cwrapper.prototype("double ecl_rft_cell_get_sgas( ecl_rft_cell )") + +cfunc.get_orat = cwrapper.prototype("double ecl_rft_cell_get_orat( ecl_plt_cell )") +cfunc.get_grat = cwrapper.prototype("double ecl_rft_cell_get_grat( ecl_plt_cell )") +cfunc.get_wrat = cwrapper.prototype("double ecl_rft_cell_get_wrat( ecl_plt_cell )") + +cfunc.get_conn_start = cwrapper.prototype("double ecl_rft_cell_get_connection_start( ecl_plt_cell )") +cfunc.get_conn_end = cwrapper.prototype("double ecl_rft_cell_get_connection_end( ecl_plt_cell )") + +cfunc.get_flowrate = cwrapper.prototype("double ecl_rft_cell_get_flowrate( ecl_plt_cell )") +cfunc.get_oil_flowrate = cwrapper.prototype("double ecl_rft_cell_get_oil_flowrate( ecl_plt_cell )") +cfunc.get_gas_flowrate = cwrapper.prototype("double ecl_rft_cell_get_gas_flowrate( ecl_plt_cell )") +cfunc.get_water_flowrate = cwrapper.prototype("double ecl_rft_cell_get_water_flowrate( ecl_plt_cell )") + + diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_subsidence.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_subsidence.py index 4aa41274ef..c47f37e69b 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_subsidence.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_subsidence.py @@ -22,13 +22,8 @@ results and calculate the change in seafloor subsidence between the different surveys. The implementation is a thin wrapper around the ecl_subsidence.c implementation in the libecl library. """ - -import libecl -import ecl_file -import ecl_region -import ecl_grid -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.ecl import ECL_LIB class EclSubsidence(CClass): @@ -48,7 +43,7 @@ class EclSubsidence(CClass): 3. Evalute the subsidence response with the eval() method. """ - def __init__( self , grid , init_file ): + def __init__( self, grid, init_file ): """ Creates a new EclSubsidence instance. @@ -56,10 +51,10 @@ class EclSubsidence(CClass): of EclGrid and EclFile respectively. """ self.init_file = init_file # Inhibit premature garbage collection of init_file - self.init_cobj( cfunc.subsidence_alloc( grid , init_file ) , cfunc.free ) - + self.init_cobj(cfunc.subsidence_alloc(grid, init_file), cfunc.free) - def add_survey_PRESSURE( self , survey_name , restart_file ): + + def add_survey_PRESSURE( self, survey_name, restart_file ): """ Add new survey based on PRESSURE keyword. @@ -81,10 +76,10 @@ class EclSubsidence(CClass): The pore volume is calculated from the initial pore volume and the PRESSURE keyword from the restart file. """ - cfunc.add_survey_PRESSURE( self , survey_name , restart_file ) + cfunc.add_survey_PRESSURE(self, survey_name, restart_file) - - def eval(self , base_survey , monitor_survey , pos , compressibility , poisson_ratio , region = None): + + def eval(self, base_survey, monitor_survey, pos, compressibility, poisson_ratio, region=None): """ Calculates the subsidence change between two surveys. @@ -108,20 +103,21 @@ class EclSubsidence(CClass): The argument @compressibility is the total reservoir compressibility. """ - return cfunc.eval( self , base_survey , monitor_survey , region , pos[0] , pos[1] , pos[2] , compressibility, poisson_ratio) + return cfunc.eval(self, base_survey, monitor_survey, region, pos[0], pos[1], pos[2], compressibility, + poisson_ratio) # 2. Creating a wrapper object around the libecl library, -cwrapper = CWrapper( libecl.lib ) -cwrapper.registerType( "ecl_subsidence" , EclSubsidence ) +cwrapper = CWrapper(ECL_LIB) +cwrapper.registerType("ecl_subsidence", EclSubsidence) # 3. Installing the c-functions used to manipulate ecl_subsidence instances. # These functions are used when implementing the EclSubsidence class, not # used outside this scope. cfunc = CWrapperNameSpace("ecl_subsidence") -cfunc.subsidence_alloc = cwrapper.prototype("c_void_p ecl_subsidence_alloc( ecl_grid , ecl_file )") -cfunc.free = cwrapper.prototype("void ecl_subsidence_free( ecl_subsidence )") +cfunc.subsidence_alloc = cwrapper.prototype("c_void_p ecl_subsidence_alloc( ecl_grid , ecl_file )") +cfunc.free = cwrapper.prototype("void ecl_subsidence_free( ecl_subsidence )") # Return value ignored in the add_survey_xxx() functions: -cfunc.add_survey_PRESSURE = cwrapper.prototype("c_void_p ecl_subsidence_add_survey_PRESSURE( ecl_subsidence , char* , ecl_file )") -cfunc.eval = cwrapper.prototype("double ecl_subsidence_eval( ecl_subsidence , char* , char* , ecl_region , double , double , double, double, double)") +cfunc.add_survey_PRESSURE = cwrapper.prototype("c_void_p ecl_subsidence_add_survey_PRESSURE( ecl_subsidence , char* , ecl_file )") +cfunc.eval = cwrapper.prototype("double ecl_subsidence_eval( ecl_subsidence , char* , char* , ecl_region , double , double , double, double, double)") diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_sum.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_sum.py index d687e329e2..e335cce4c0 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_sum.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_sum.py @@ -25,16 +25,11 @@ libecl/src directory. # regarding order of arguments: The C code generally takes the time # index as the first argument and the key/key_index as second # argument. In the python code this order has been reversed. +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.util import StringList, ctime, DoubleVector, TimeVector +from ert.ecl import ECL_LIB - - -import libecl -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.stringlist import StringList -from ert.util.ctime import ctime - -import numpy +import numpy #import ert.ecl_plot.sum_plot as sum_plot @@ -45,11 +40,13 @@ import numpy # implementation could be replaced with: # # from matplotlib.dates import date2num +from ert.util.tvector import TimeVector + HOURS_PER_DAY = 24.0 -MINUTES_PER_DAY = 60*HOURS_PER_DAY -SECONDS_PER_DAY = 60*MINUTES_PER_DAY -MUSECONDS_PER_DAY = 1e6*SECONDS_PER_DAY +MINUTES_PER_DAY = 60 * HOURS_PER_DAY +SECONDS_PER_DAY = 60 * MINUTES_PER_DAY +MUSECONDS_PER_DAY = 1e6 * SECONDS_PER_DAY def date2num( dt ): """ @@ -507,7 +504,7 @@ class EclSMSPECNode( CClass ): class EclSum( CClass ): - def __new__( cls , load_case , join_string = ":" , include_restart = True): + def __new__( cls , load_case , join_string = ":" , include_restart = True, c_ptr = None, parent = None): """ Loads a new EclSum instance with summary data. @@ -525,16 +522,24 @@ class EclSum( CClass ): loader will, in the case of a restarted ECLIPSE simulation, try to load summary results also from the restarted case. """ - c_ptr = cfunc.fread_alloc( load_case , join_string , include_restart) if c_ptr: obj = object.__new__( cls ) - obj.init_cobj( c_ptr , cfunc.free ) + if parent: + obj.init_cref( c_ptr , parent) + else: + obj.init_cobj( c_ptr , cfunc.free ) return obj else: - return None + c_ptr = cfunc.fread_alloc( load_case , join_string , include_restart) + if c_ptr: + obj = object.__new__( cls ) + obj.init_cobj( c_ptr , cfunc.free ) + return obj + else: + return None - def __init__(self , load_case , join_string = ":" ,include_restart = True , c_ptr = None): + def __init__(self , load_case , join_string = ":" ,include_restart = True , c_ptr = None, parent = None): """ Initialize a new EclSum instance. @@ -1221,15 +1226,27 @@ class EclSum( CClass ): cfunc.fwrite_sum( self ) - + def alloc_time_vector(self, report_only): + c_ptr = cfunc.alloc_time_vector(self, report_only) + v = TimeVector.asPythonObject(c_ptr, TimeVector.free) + return v + + def alloc_data_vector(self, data_index, report_only): + c_ptr = cfunc.alloc_data_vector(self, data_index, report_only) + v = DoubleVector.asPythonObject(c_ptr, DoubleVector.free) + return v + def get_general_var_index(self, key): + c_ptr = cfunc.get_general_var_index( self , key ) + v = TimeVector.asPythonObject(c_ptr, TimeVector.free) + return v ################################################################# # 2. Creating a wrapper object around the libecl library, # registering the type map : ecl_kw <-> EclKW -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType( "ecl_sum" , EclSum ) cwrapper.registerType( "smspec_node" , EclSMSPECNode ) @@ -1280,7 +1297,8 @@ cfunc.get_report_time = cwrapper.prototype("time_t ecl_sum_get_r cfunc.fwrite_sum = cwrapper.prototype("void ecl_sum_fwrite(ecl_sum)") cfunc.set_case = cwrapper.prototype("void ecl_sum_set_case(ecl_sum, char*)") - +cfunc.alloc_time_vector = cwrapper.prototype("c_void_p ecl_sum_alloc_time_vector(ecl_sum, bool)") +cfunc.alloc_data_vector = cwrapper.prototype("c_void_p ecl_sum_alloc_data_vector(ecl_sum, int, bool)") #----------------------------------------------------------------- # smspec node related stuff diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_util.py b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_util.py index f4217d4334..65ca98009c 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_util.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/ecl_util.py @@ -24,58 +24,64 @@ ert.cwrap.cenum.create_enum() function in a semi-automagic manner. In addition to the enum definitions there are a few stateless functions from ecl_util.c which are not bound to any class type. """ +from ert.cwrap import create_enum, CWrapper, CWrapperNameSpace -from ert.cwrap.cwrap import * -from ert.cwrap.cenum import create_enum -from ert.util.ctime import ctime -import libecl +from ert.ecl import ECL_LIB # ecl_file_enum from ecl_util.h -create_enum( libecl.lib , "ecl_util_file_enum_iget" , "ecl_file_enum" , globals()) +EclFileEnum = create_enum(ECL_LIB, "ecl_util_file_enum_iget", "ecl_file_enum") # ecl_phase_enum from ecl_util.h -create_enum( libecl.lib , "ecl_util_phase_enum_iget" , "ecl_phase_enum" , name_space = globals()) +EclPhaseEnum = create_enum(ECL_LIB, "ecl_util_phase_enum_iget", "ecl_phase_enum") # ecl_type_enum defintion from ecl_util.h -create_enum( libecl.lib , "ecl_util_type_enum_iget" , "ecl_type_enum" , name_space = globals()) +EclTypeEnum = create_enum(ECL_LIB, "ecl_util_type_enum_iget", "ecl_type_enum") # ecl_file_flag_type defintion from ecl_file.h -create_enum( libecl.lib , "ecl_util_file_flags_enum_iget" , "ecl_file_flag_enum" , name_space = globals()) +EclFileFlagEnum = create_enum(ECL_LIB, "ecl_util_file_flags_enum_iget", "ecl_file_flag_enum") -def get_num_cpu( datafile ): - """ - Parse ECLIPSE datafile and determine how many CPUs are needed. - Will look for the "PARALLELL" keyword, and then read off the - number of CPUs required. Will return one if no PARALLELL keyword - is found. - """ - return cfunc.get_num_cpu( datafile ) +cwrapper = CWrapper(ECL_LIB) +cfunc = CWrapperNameSpace("ecl_util") - -def get_file_type( filename ): - """ - Will inspect an ECLIPSE filename and return an integer type flag. - """ - return cfunc.get_file_type( filename , None , None ) - - -def type_name( ecl_type ): - return cfunc.get_type_name( ecl_type ) - - -def get_start_date( datafile ): - return cfunc.get_start_date( datafile ).datetime() - - - -cwrapper = CWrapper( libecl.lib ) -cfunc = CWrapperNameSpace("ecl_util") - -cfunc.get_num_cpu = cwrapper.prototype("int ecl_util_get_num_cpu( char* )") -cfunc.get_file_type = cwrapper.prototype("int ecl_util_get_file_type( char* , bool* , int*)") -cfunc.get_type_name = cwrapper.prototype("char* ecl_util_get_type_name( int )") +cfunc.get_num_cpu = cwrapper.prototype("int ecl_util_get_num_cpu( char* )") +cfunc.get_file_type = cwrapper.prototype("int ecl_util_get_file_type( char* , bool* , int*)") +cfunc.get_type_name = cwrapper.prototype("char* ecl_util_get_type_name( int )") cfunc.get_start_date = cwrapper.prototype("time_t ecl_util_get_start_date( char* )") + +class EclUtil(object): + @staticmethod + def get_num_cpu( datafile ): + """ + Parse ECLIPSE datafile and determine how many CPUs are needed. + + Will look for the "PARALLELL" keyword, and then read off the + number of CPUs required. Will return one if no PARALLELL keyword + is found. + """ + return cfunc.get_num_cpu(datafile) + + @staticmethod + def get_file_type( filename ): + """ + Will inspect an ECLIPSE filename and return an integer type flag. + """ + return cfunc.get_file_type(filename, None, None) + + @staticmethod + def type_name(ecl_type): + return cfunc.get_type_name(ecl_type) + + @staticmethod + def get_start_date(datafile): + return cfunc.get_start_date(datafile).datetime() + + + +get_num_cpu = EclUtil.get_num_cpu +get_file_type = EclUtil.get_file_type +type_name = EclUtil.type_name +get_start_date = EclUtil.get_start_date diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/fortio.py b/ThirdParty/Ert/devel/python/python/ert/ecl/fortio.py index b5411c3a6a..03f5dafdac 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/fortio.py +++ b/ThirdParty/Ert/devel/python/python/ert/ecl/fortio.py @@ -36,12 +36,9 @@ python module is a minimal wrapping of this datastructure; mainly to support passing of FortIO handles to the underlying C functions. A more extensive wrapping of the fortio implementation would be easy. """ +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace, CFILE +from ert.ecl import ECL_LIB -import libecl -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cfile import CFILE -from ert.cwrap.cclass import CClass class FortIO(CClass): """ @@ -59,7 +56,7 @@ class FortIO(CClass): # """ # Create a FortIO handle connected to file @filename. @mode as in fopen() # - # Will create a FortIO handle conntected to the file + # Will create a FortIO handle connected to the file # @filename. The @mode flag is passed directly to the final # fopen() call and should be "r" to open the file for reading # and "w" for writing. @@ -147,7 +144,7 @@ class FortIO(CClass): # 2. Creating a wrapper object around the libecl library, # registering the type map : fortio <-> FortIO -cwrapper = CWrapper( libecl.lib ) +cwrapper = CWrapper(ECL_LIB) cwrapper.registerType("fortio" , FortIO ) diff --git a/ThirdParty/Ert/devel/python/python/ert/ecl/libecl.py b/ThirdParty/Ert/devel/python/python/ert/ecl/libecl.py deleted file mode 100644 index 929daaa7b2..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/ecl/libecl.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'libecl.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. -""" -This module will load the libecl.so shared library. -""" - -# This statement is necessary for side-effects (i.e. the final -# dlopen("libutil.so") call). -import ert.util.libutil -import ert.geo.libgeo - -import ert.cwrap.clib as clib - -try: - clib.load("libgomp" , "libgomp.so.1") - openmp = True -except ImportError: - openmp = False - -lib = clib.ert_load("libecl.so") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/enkf/CMakeLists.txt index cd664575a1..5969d2c5ee 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/CMakeLists.txt @@ -1 +1,30 @@ -add_python_package("Python ert.enkf" ${PYTHON_INSTALL_PREFIX}/ert/enkf "enkf_enum.py;enkf_main.py;enkf.py;ens_config.py;__init__.py;analysis_config.py;libenkf.py" True) +set(PYTHON_SOURCES + __init__.py + analysis_config.py + enkf_main.py + ert_templates.py + gen_kw_config.py + model_config.py + ecl_config.py + enkf_node.py + field_config.py + obs_vector.py + enkf_config_node.py + enkf_obs.py + block_obs.py + libenkf.py + plot_conf.py + enkf_enum.py + enkf.py + field.py + local_config.py + site_config.py + enkf_fs.py + ens_config.py + gen_data_config.py + time_map.py + ert_template.py + enkf_state.py +) + +add_python_package("Python ert.enkf" ${PYTHON_INSTALL_PREFIX}/ert/enkf "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/analysis_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/analysis_config.py index 567c632451..6325c4c21d 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/analysis_config.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/analysis_config.py @@ -23,35 +23,57 @@ import libenkf class AnalysisConfig(CClass): - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + @property + def get_rerun(self): + return cfunc.get_rerun( self ) + + def set_rerun(self, rerun): + cfunc.set_rerun(self, rerun) - - def __del__(self): - if self.owner: - cfunc.free( self ) + @property + def get_rerun_start(self): + return cfunc.get_rerun_start( self ) + def set_rerun_start(self, int): + cfunc.set_rerun_start( self , int) - def has_key(self , key): - return cfunc.has_key( self ,key ) + @property + def get_log_path(self): + return cfunc.get_log_path( self ) + def set_log_path(self, path): + cfunc.set_log_path( self, path) + @property + def get_alpha(self): + return cfunc.get_alpha( self ) + def set_alpha(self, alpha): + cfunc.set_alpha( self , alpha) + + @property + def get_merge_observations(self): + return cfunc.get_merge_observations( self ) + + def set_merge_observations(self, merge_observations): + return cfunc.set_merge_observations( self , merge_observations) ################################################################## cwrapper = CWrapper( libenkf.lib ) cwrapper.registerType( "analysis_config" , AnalysisConfig ) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("analysis_config") cfunc.free = cwrapper.prototype("void analysis_config_free( analysis_config )") cfunc.get_rerun = cwrapper.prototype("int analysis_config_get_rerun( analysis_config )") -cfunc.set_rerun = cwrapper.prototype("void analysis_config_set_rerun analysis_config, bool)") +cfunc.set_rerun = cwrapper.prototype("void analysis_config_set_rerun( analysis_config, bool)") cfunc.get_rerun_start = cwrapper.prototype("int analysis_config_get_rerun_start( analysis_config )") cfunc.set_rerun_start = cwrapper.prototype("void analysis_config_set_rerun_start( analysis_config, int)") cfunc.get_log_path = cwrapper.prototype("char* analysis_config_get_log_path( analysis_config)") @@ -59,8 +81,5 @@ cfunc.set_log_path = cwrapper.prototype("void analysis_config_set_log_ cfunc.get_alpha = cwrapper.prototype("double analysis_config_get_alpha(analysis_config)") cfunc.set_alpha = cwrapper.prototype("void analysis_config_set_alpha(analysis_config, double)") cfunc.get_merge_observations = cwrapper.prototype("bool analysis_config_get_merge_observations(analysis_config)") -cfunc.set_merge_observations = cwrapper.prototype("void analysis_config_set_merge_observations(analysis_config, int)") -cfunc.get_enkf_mode = cwrapper.prototype("int analysis_config_get_enkf_mode(analysis_config)") -cfunc.set_enkf_mode = cwrapper.prototype("void analysis_config_set_enkf_mode(analysis_config, int)") -cfunc.get_truncation = cwrapper.prototype("double analysis_config_get_truncation(analysis_config)") -cfunc.get_truncation = cwrapper.prototype("void analysis_config_set_truncation(analysis_config, double)") +cfunc.set_merge_observations = cwrapper.prototype("void analysis_config_set_merge_observations(analysis_config, bool)") + diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/block_obs.py b/ThirdParty/Ert/devel/python/python/ert/enkf/block_obs.py new file mode 100644 index 0000000000..af15b20f8c --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/block_obs.py @@ -0,0 +1,58 @@ +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file 'block_obs.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +import ctypes +from ert.cwrap.cwrap import * +from ert.cwrap.cclass import CClass +from ert.util.tvector import * +from enkf_enum import * +import libenkf +class BlockObs(CClass): + + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + def iget_i(self , index): + return cfunc.iget_i( self ,index ) + + def iget_j(self , index): + return cfunc.iget_j( self ,index ) + + def iget_k(self , index): + return cfunc.iget_k( self ,index ) + + def get_size(self): + return cfunc.get_size(self) + + def iget(self, index, value, std): + return cfunc.iget(self, index, value, std) + +################################################################## + +cwrapper = CWrapper( libenkf.lib ) +cwrapper.registerType( "block_obs" , BlockObs ) +cfunc = CWrapperNameSpace("block_obs") + + +cfunc.free = cwrapper.prototype("void block_obs_free( block_obs )") +cfunc.iget_i = cwrapper.prototype("int block_obs_iget_i(block_obs, int)") +cfunc.iget_j = cwrapper.prototype("int block_obs_iget_j( block_obs, int)") +cfunc.iget_k = cwrapper.prototype("int block_obs_iget_k( block_obs , int)") +cfunc.get_size = cwrapper.prototype("int block_obs_get_size( block_obs )") +cfunc.iget = cwrapper.prototype("void block_obs_iget( block_obs, int, double*, double*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/ecl_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/ecl_config.py index fffec1a3aa..afe2c50419 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/ecl_config.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/ecl_config.py @@ -14,52 +14,108 @@ # See the GNU General Public License at # for more details. -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -from enkf_enum import * -import libenkf +from ert.cwrap.cwrap import * +from ert.cwrap.cclass import CClass +from ert.util.tvector import * +import libenkf +from ert.ecl.ecl_sum import EclSum +from ert.util.stringlist import StringList + + class EclConfig(CClass): - - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) + def __init__(self, c_ptr, parent=None): + if parent: + self.init_cref(c_ptr, parent) + else: + self.init_cobj(c_ptr, cfunc.free) + @property + def get_eclbase(self): + eclbase = cfunc.get_eclbase(self) + return eclbase - def has_key(self , key): - return cfunc.has_key( self ,key ) + @property + def get_data_file(self): + datafile = cfunc.get_data_file(self) + return datafile + @property + def get_gridfile(self): + gridfile = cfunc.get_gridfile(self) + return gridfile + def set_gridfile(self, gridfile): + cfunc.set_gridfile(self, gridfile) -################################################################## + @property + def get_schedule_file(self): + schedule_file = cfunc.get_schedule_file(self) + return schedule_file -cwrapper = CWrapper( libenkf.lib ) -cwrapper.registerType( "ecl_config" , EclConfig ) + def set_schedule_file(self, schedule_file): + schedule_file = cfunc.set_schedule_file(self, schedule_file) + + @property + def get_init_section(self): + init_section = cfunc.get_init_section(self) + return init_section + + def set_init_section(self, init_section): + cfunc.set_init_section(self, init_section) + + @property + def get_refcase_name(self): + refcase_name = cfunc.get_refcase_name(self) + return refcase_name + + def load_refcase(self, refcase): + cfunc.load_refcase(self, refcase) + + @property + def get_static_kw_list(self): + return StringList(c_ptr=cfunc.get_static_kw_list(self), parent=self) + + @property + def get_refcase(self): + refcase = EclSum(self.get_refcase_name, join_string=":", include_restart=True, c_ptr=cfunc.get_refcase(self), + parent=self) + return refcase + + def clear_static_kw(self): + cfunc.clear_static_kw(self) + + def add_static_kw(self, kw): + cfunc.add_static_kw(self, kw) + + @property + def get_grid(self): + return cfunc.get_grid(self) + + @property + def get_sched_file(self): + return cfunc.get_sched_file(self) + + ################################################################## + +cwrapper = CWrapper(libenkf.lib) +cwrapper.registerType("ecl_config", EclConfig) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("ecl_config") - -cfunc.free = cwrapper.prototype("void ecl_config_free( ecl_config )") -cfunc.get_eclbase = cwrapper.prototype("char* ecl_config_get_eclbase( ecl_config )") -cfunc.get_data_file = cwrapper.prototype("char* ecl_config_get_data_file(ecl_config)") -cfunc.get_gridfile = cwrapper.prototype("char* ecl_config_get_gridfile(ecl_config)") -cfunc.set_gridfile = cwrapper.prototype("void ecl_config_set_grid(ecl_config, char*)") -cfunc.get_schedule = cwrapper.prototype("char* ecl_config_get_schedule_file(ecl_config)") -cfunc.set_schedule = cwrapper.prototype("void ecl_config_set_schedule_file(ecl_config, char*)") -cfunc.get_init_section = cwrapper.prototype("char* ecl_config_get_init_section(ecl_config)") -cfunc.set_init_section = cwrapper.prototype("void ecl_config_set_init_section(ecl_config, char*)") -cfunc.get_refcase_name = cwrapper.prototype("char* ecl_config_get_refcase_name(ecl_config)") -cfunc.set_refcase_name = cwrapper.prototype("void ecl_config_load_refcase(ecl_config, char*)") +cfunc.free = cwrapper.prototype("void ecl_config_free( ecl_config )") +cfunc.get_eclbase = cwrapper.prototype("char* ecl_config_get_eclbase( ecl_config )") +cfunc.get_data_file = cwrapper.prototype("char* ecl_config_get_data_file(ecl_config)") +cfunc.get_gridfile = cwrapper.prototype("char* ecl_config_get_gridfile(ecl_config)") +cfunc.set_gridfile = cwrapper.prototype("void ecl_config_set_grid(ecl_config, char*)") +cfunc.get_schedule_file = cwrapper.prototype("char* ecl_config_get_schedule_file(ecl_config)") +cfunc.set_schedule_file = cwrapper.prototype("void ecl_config_set_schedule_file(ecl_config, char*)") +cfunc.get_init_section = cwrapper.prototype("char* ecl_config_get_init_section(ecl_config)") +cfunc.set_init_section = cwrapper.prototype("void ecl_config_set_init_section(ecl_config, char*)") +cfunc.get_refcase_name = cwrapper.prototype("char* ecl_config_get_refcase_name(ecl_config)") +cfunc.load_refcase = cwrapper.prototype("void ecl_config_load_refcase(ecl_config, char*)") cfunc.get_static_kw_list = cwrapper.prototype("c_void_p ecl_config_get_static_kw_list(ecl_config)") -cfunc.clear_static_kw = cwrapper.prototype("void ecl_config_clear_static_kw(ecl_config)") -cfunc.add_static_kw = cwrapper.prototype("void ecl_config_add_static_kw(ecl_config, char*)") -cfunc.get_grid = cwrapper.prototype("c_void_p ecl_config_get_grid(ecl_config)") +cfunc.clear_static_kw = cwrapper.prototype("void ecl_config_clear_static_kw(ecl_config)") +cfunc.add_static_kw = cwrapper.prototype("void ecl_config_add_static_kw(ecl_config, char*)") +cfunc.get_grid = cwrapper.prototype("c_void_p ecl_config_get_grid(ecl_config)") +cfunc.get_refcase = cwrapper.prototype("c_void_p ecl_config_get_refcase(ecl_config)") +cfunc.get_sched_file = cwrapper.prototype("c_void_p ecl_config_get_sched_file(ecl_config)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_config_node.py b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_config_node.py index 0bca2c408b..a0d07f96b3 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_config_node.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_config_node.py @@ -20,43 +20,76 @@ from ert.cwrap.cclass import CClass from ert.util.tvector import * from enkf_enum import * import libenkf +from ert.enkf.gen_data_config import GenDataConfig +from ert.enkf.gen_kw_config import GenKwConfig +from ert.enkf.field_config import FieldConfig +from ert.enkf.enkf_node import EnkfNode + class EnkfConfigNode(CClass): - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + @property + def get_impl_type( self ): + return cfunc.get_impl_type( self ) - def has_key(self , key): - return cfunc.has_key( self ,key ) + @property + def get_var_type( self ): + return cfunc.get_var_type( self ) + @property + def get_ref(self): + return cfunc.get_ref( self) + @property + def get_min_std_file(self): + return cfunc.get_min_std_file( self) + @property + def get_enkf_outfile(self): + return cfunc.get_enkf_outfile( self) + + @property + def field_model(self): + return FieldConfig(c_ptr = cfunc.get_ref( self), parent = self) + + @property + def data_model(self): + return GenDataConfig(c_ptr = cfunc.get_ref( self), parent = self) + + @property + def keyword_model(self): + return GenKwConfig(c_ptr = cfunc.get_ref( self), parent = self) + + @property + def get_enkf_infile(self): + return cfunc.get_enkf_infile( self) + + @property + def alloc_node(self): + node = EnkfNode.alloc(self) + return node + + @property + def get_init_file_fmt(self): + return cfunc.get_init_file_fmt(self) ################################################################## cwrapper = CWrapper( libenkf.lib ) cwrapper.registerType( "enkf_config_node" , EnkfConfigNode ) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("enkf_config_node") - - -cfunc.free = cwrapper.prototype("void enkf_config_node_free( enkf_config_node )") -cfunc.get_impl_type = cwrapper.prototype("c_void_p enkf_config_node_get_impl_type(enkf_config_node)") -cfunc.get_ref = cwrapper.prototype("c_void_p enkf_config_node_get_ref(enkf_config_node)") -cfunc.is_valid = cwrapper.prototype("bool enkf_config_node_is_valid(enkf_config_node)") -cfunc.get_min_std_file = cwrapper.prototype("char* enkf_config_node_get_min_std_file(enkf_config_node)") -cfunc.get_enkf_outfile = cwrapper.prototype("char* enkf_config_node_get_enkf_outfile(enkf_config_node)") -cfunc.get_enkf_infile = cwrapper.prototype("char* enkf_config_node_get_enkf_infile(enkf_config_node)") -cfunc.update_gen_kw = cwrapper.prototype("void enkf_config_node_update_gen_kw(enkf_config_node, char*, char*, char*, char*, char*)") -cfunc.update_state_field = cwrapper.prototype("void enkf_config_node_update_state_field(enkf_config_node, int, double, double)") -cfunc.update_parameter_field = cwrapper.prototype("void enkf_config_node_update_parameter_field(enkf_config_node, char*, char*, char*, int, double, double, char*, char*)") -cfunc.update_general_field = cwrapper.prototype("void enkf_config_node_update_general_field(enkf_config_node, char*, char*, char*, char*, int, double, double, char*, char*, char*)") -cfunc.update_gen_data = cwrapper.prototype("void enkf_config_node_update_gen_data(enkf_config_node, int, int, char*, char*, char*, char*, char*, char*)") +################################################################## +################################################################## +cfunc.free = cwrapper.prototype("void enkf_config_node_free( enkf_config_node )") +cfunc.get_ref = cwrapper.prototype("c_void_p enkf_config_node_get_ref(enkf_config_node)") +cfunc.get_impl_type = cwrapper.prototype("c_void_p enkf_config_node_get_impl_type(enkf_config_node)") +cfunc.get_enkf_outfile = cwrapper.prototype("char* enkf_config_node_get_enkf_outfile(enkf_config_node)") +cfunc.get_min_std_file = cwrapper.prototype("char* enkf_config_node_get_min_std_file(enkf_config_node)") +cfunc.get_enkf_infile = cwrapper.prototype("char* enkf_config_node_get_enkf_infile(enkf_config_node)") +cfunc.get_init_file_fmt = cwrapper.prototype("char* enkf_config_node_get_init_file_fmt(enkf_config_node)") +cfunc.get_var_type = cwrapper.prototype("c_void_p enkf_config_node_get_var_type(enkf_config_node)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_fs.py b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_fs.py new file mode 100644 index 0000000000..49bae0d6d1 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_fs.py @@ -0,0 +1,73 @@ +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file 'enkf_fs.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +import ctypes +from ctypes import c_buffer +from ert.cwrap.cwrap import * +from ert.cwrap.cclass import CClass +from ert.util.tvector import * +from enkf_enum import * +from ert.ert.enums import enkf_var_type, ert_state_enum +from ert.enkf.time_map import TimeMap +from ert.util.buffer import Buffer +import libenkf +from ert.ert.c_enums import state_enum +from ert.ert.c_enums import var_type +class EnkfFs(CClass): + + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.close ) + + def has_node(self, node_key, var_type, report_step, iens, state): + return cfunc.has_node(self, node_key, var_type, report_step, iens, state) + + def has_vector(self, node_key, var_type, iens, state): + return cfunc.has_vector(self, node_key, var_type, iens, state) + + + def fread_node(self, key, type, step, member, value): + buffer = Buffer(100) + cfunc.fread_node(self, buffer, key, type, step, member, value) + + def fread_vector(self, key, type, member, value): + buffer = Buffer(100) + cfunc.fread_vector(self, buffer, key, type, member, value) + + @property + def get_time_map(self): + return TimeMap(cfunc.get_time_map(self), parent = self) + + @staticmethod + def exists(path): + return cfunc.exists(path) + +################################################################## + +cwrapper = CWrapper( libenkf.lib ) +cwrapper.registerType( "enkf_fs" , EnkfFs ) + +cfunc = CWrapperNameSpace("enkf_fs") + +cfunc.close = cwrapper.prototype("void enkf_fs_close(enkf_fs)") +cfunc.has_node = cwrapper.prototype("bool enkf_fs_has_node(enkf_fs, char*, c_uint, int, int, c_uint)") +cfunc.has_vector = cwrapper.prototype("bool enkf_fs_has_vector(enkf_fs, char*, c_uint, int, c_uint)") +cfunc.fread_node = cwrapper.prototype("void enkf_fs_fread_node(enkf_fs, buffer, char*, c_uint, int, int, c_uint)") +cfunc.fread_vector = cwrapper.prototype("void enkf_fs_fread_vector(enkf_fs, buffer, char*, c_uint, int, c_uint)") +cfunc.get_time_map = cwrapper.prototype("c_void_p enkf_fs_get_time_map(enkf_fs)") +cfunc.exists = cwrapper.prototype("bool enkf_fs_exists(char*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_main.py b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_main.py index 57b4a319e5..229228e369 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_main.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_main.py @@ -15,25 +15,26 @@ # for more details. import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -from ert.job_queue.job_queue import JobQueue -from enkf_enum import * -import ens_config -import ecl_config -import analysis_config -import local_config -import model_config -import enkf_config_node -import gen_kw_config -import gen_data_config -import field_config -import enkf_obs -import plot_config -import site_config -import libenkf -import ert_local +from ert.enkf.enkf_enum import * +from ert.ert.enums import * +from ert.enkf.ens_config import * +from ert.enkf.ecl_config import * +from ert.enkf.analysis_config import * +from ert.enkf.local_config import * +from ert.enkf.model_config import * +from ert.enkf.enkf_config_node import * +from ert.enkf.gen_kw_config import * +from ert.enkf.gen_data_config import * +from ert.enkf.field_config import * +from ert.enkf.enkf_obs import * +from ert.enkf.plot_conf import * +from ert.enkf.site_config import * +from ert.enkf.libenkf import * +from ert.enkf.enkf_fs import * +from ert.enkf.ert_templates import * +from ert.enkf.enkf_state import * +from ert.util import Log + class EnKFMain(CClass): @@ -43,11 +44,13 @@ class EnKFMain(CClass): @classmethod - def bootstrap(cls , model_config , site_config = ert_local.site_config): + def bootstrap(cls , model_config , site_config , strict = True): obj = EnKFMain() - obj.c_ptr = cfunc.bootstrap( site_config , model_config , True , False ) + obj.c_ptr = cfunc.bootstrap( site_config , model_config , strict , False ) return obj - + + def set_eclbase(self, eclbase): + cfunc.set_eclbase(self, eclbase) def __del__(self): if self.c_ptr: @@ -58,48 +61,209 @@ class EnKFMain(CClass): @property def ens_size( self ): return cfunc.ens_size( self ) - + + @property + def ensemble_config(self): + config = EnsConfig( c_ptr = cfunc.get_ens_config( self ) , parent = self) + return config + + @property + def analysis_config(self): + anal_config = AnalysisConfig( c_ptr = cfunc.get_analysis_config( self ), parent = self) + return anal_config + + @property + def model_config(self): + mod_config = ModelConfig( c_ptr = cfunc.get_model_config( self ) , parent = self) + return mod_config - def sim( self ): - iactive = BoolVector( True ) - iactive[ self.ens_size -1 ] = True - - start_state = enkf_state_enum.ANALYZED - run_mode = enkf_run_enum.ENSEMBLE_EXPERIMENT - start_report = 0 - init_step_parameters = 0 - cfunc.run( self , run_mode , iactive , init_step_parameters , start_report , start_state ) + @property + def logh(self): + mog = Log( c_ptr = cfunc.get_logh( self ), parent = self) + return mog + + @property + def local_config(self): + loc_config = LocalConfig( c_ptr = cfunc.get_local_config( self ), parent = self) + return loc_config + + @property + def site_config(self): + site_conf = SiteConfig( c_ptr = cfunc.get_site_config( self ) , parent = self) + return site_conf + + @property + def ecl_config(self): + ecl_conf = EclConfig( c_ptr = cfunc.get_ecl_config( self ) , parent = self) + return ecl_conf + + @property + def plot_config(self): + plot_conf = PlotConf( c_ptr = cfunc.get_plot_config( self ), parent = self) + return plot_conf + + def set_eclbase(self, eclbase): + cfunc.set_eclbase(self, eclbase) - def update(self , step_list): - cfunc.update( self , step_list ) - + def set_datafile(self, datafile): + cfunc.set_eclbase(self, datafile) + + @property + def get_schedule_prediction_file(self): + schedule_prediction_file = cfunc.get_schedule_prediction_file(self) + return schedule_prediction_file + + def set_schedule_prediction_file(self,file): + cfunc.set_schedule_prediction_file(self,file) + + @property + def get_data_kw(self): + data_kw = cfunc.get_data_kw(self) + return data_kw + + def clear_data_kw(self): + cfunc.set_data_kw(self) + + def add_data_kw(self, key, value): + cfunc.add_data_kw(self, key, value) + + def resize_ensemble(self, value): + cfunc.resize_ensemble(self, value) + + def del_node(self, key): + cfunc.del_node(self, key) @property - def config(self): - config = ens_config.EnsConfig( cfunc.get_ens_config( self )) - return config + def get_obs(self): + ob = EnkfObs( c_ptr = cfunc.get_obs( self ), parent = self) + return ob + + def load_obs(self, obs_config_file): + cfunc.load_obs(self, obs_config_file) + + def reload_obs(self): + cfunc.reload_obs(self) + + def set_case_table(self, case_table_file): + cfunc.set_case_table(self, case_table_file) + + @property + def get_pre_clear_runpath(self): + pre_clear = cfunc.get_pre_clear_runpath(self) + return pre_clear + + def set_pre_clear_runpath(self, value): + cfunc.set_pre_clear_runpath(self, value) + + def iget_keep_runpath(self, iens): + ikeep = cfunc.iget_keep_runpath(self, iens) + return ikeep + + def iset_keep_runpath(self, iens, keep_runpath): + cfunc.iset_keep_runpath(self, iens, keep_runpath) + + @property + def get_templates(self): + temp = ErtTemplates( c_ptr = cfunc.get_templates( self ), parent = self) + return temp + + @property + def get_site_config_file(self): + site_conf_file = cfunc.get_site_config_file(self) + return site_conf_file + + def initialize_from_scratch(self, parameter_list, iens1, iens2, force_init = True): + cfunc.initialize_from_scratch(self, parameter_list, iens1, iens2, force_init) + + @property + def get_fs(self): + return EnkfFs(c_ptr = cfunc.get_fs(self), parent = self) + + @property + def get_history_length(self): + return cfunc.get_history_length(self) + + def initialize_from_existing__(self, source_case,source_report_step, source_state, member_mask, ranking_key, node_list): + cfunc.initialize_from_existing__(self, source_case, source_report_step, source_state, member_mask, ranking_key, node_list) + + + def copy_ensemble(self, source_case, source_report_step, source_state, target_case, target_report_step, target_state, member_mask, ranking_key, node_list): + cfunc.copy_ensemble(self, source_case, source_report_step, source_state, target_case, target_report_step, target_state, member_mask, ranking_key, node_list) + def iget_state(self, ens_memb): + i_enkf_state = EnKFState( c_ptr = cfunc.iget_state( self ,ens_memb), parent = self) + return i_enkf_state + + def get_observations(self, user_key, obs_count, obs_x, obs_y, obs_std): + cfunc.get_observations(self, user_key, obs_count, obs_x, obs_y, obs_std) + + def get_observation_count(self, user_key): + return cfunc.get_observation_count(self, user_key) + + @property + def is_initialized(self): + return cfunc.is_initialized(self) + + def run(self, boolPtr, init_step_parameter, simFrom, state, mode): + #{"ENKF_ASSIMILATION" : 1, "ENSEMBLE_EXPERIMENT" : 2, "ENSEMBLE_PREDICTION" : 3, "INIT_ONLY" : 4, "SMOOTHER" : 5} + if mode == 1: + cfunc.run_assimilation(self, boolPtr, init_step_parameter, simFrom, state) + if mode == 2: + cfunc.run_exp(self, boolPtr, True, init_step_parameter, simFrom, state) + if mode == 4: + cfunc.run_exp(self, boolPtr, False, init_step_parameter, simFrom, state) + if mode == 5: + cfunc.run_smoother(self, "AUTOSMOOTHER", True) + + @property + def alloc_caselist(self): + return StringList(c_ptr = cfunc.alloc_caselist(self), parent = self) + + @property + def get_current_fs(self): + return cfunc.get_current_fs(self) + + def user_select_fs(self, input_case): + cfunc.user_select_fs(self, input_case) + + @property + def get_alt_fs(self, fs, read_only, create): + return EnkfFS(cfunc.get_alt_fs(self, fs, read_only, create), parent = self) + + @staticmethod + def create_new_config(config_file, storage_path, case_name, dbase_type, num_realizations): + cfunc.create_new_config(config_file, storage_path, case_name, dbase_type, num_realizations) + + def fprintf_config(self): + cfunc.fprintf_config(self) + + def select_fs(self,path): + cfunc.select_fs(self,path) + + def fs_exists(self,case): + return cfunc.fs_exists(self,case) + ################################################################## cwrapper = CWrapper( libenkf.lib ) cwrapper.registerType( "enkf_main" , EnKFMain ) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("enkf_main") +################################################################## +################################################################## -cfunc.bootstrap = cwrapper.prototype("c_void_p enkf_main_bootstrap(char*, char*, bool)") +cfunc.bootstrap = cwrapper.prototype("c_void_p enkf_main_bootstrap(char*, char*, bool , bool)") cfunc.free = cwrapper.prototype("void enkf_main_free( enkf_main )") -cfunc.run = cwrapper.prototype("void enkf_main_run( enkf_main , int , bool_vector , int , int , int)") cfunc.ens_size = cwrapper.prototype("int enkf_main_get_ensemble_size( enkf_main )") cfunc.get_ens_config = cwrapper.prototype("c_void_p enkf_main_get_ensemble_config( enkf_main )") -cfunc.set_verbose = cwrapper.prototype("void enkf_main_set_verbose( enkf_main , bool )") -cfunc.update = cwrapper.prototype("void enkf_main_UPDATE(enkf_main , int_vector)") cfunc.get_model_config = cwrapper.prototype("c_void_p enkf_main_get_model_config( enkf_main )") cfunc.get_local_config = cwrapper.prototype("c_void_p enkf_main_get_local_config( enkf_main )") +cfunc.get_analysis_config = cwrapper.prototype("c_void_p enkf_main_get_analysis_config( enkf_main)") +cfunc.get_site_config = cwrapper.prototype("c_void_p enkf_main_get_site_config( enkf_main)") +cfunc.get_ecl_config = cwrapper.prototype("c_void_p enkf_main_get_ecl_config( enkf_main)") +cfunc.get_plot_config = cwrapper.prototype("c_void_p enkf_main_get_plot_config( enkf_main)") cfunc.set_eclbase = cwrapper.prototype("void enkf_main_set_eclbase( enkf_main, char*)") cfunc.set_datafile = cwrapper.prototype("void enkf_main_set_data_file( enkf_main, char*)") cfunc.get_schedule_prediction_file = cwrapper.prototype("char* enkf_main_get_schedule_prediction_file( enkf_main )") @@ -107,23 +271,36 @@ cfunc.set_schedule_prediction_file = cwrapper.prototype("void enkf_main_set_sche cfunc.get_data_kw = cwrapper.prototype("c_void_p enkf_main_get_data_kw(enkf_main)") cfunc.clear_data_kw = cwrapper.prototype("void enkf_main_clear_data_kw(enkf_main)") cfunc.add_data_kw = cwrapper.prototype("void enkf_main_add_data_kw(enkf_main, char*, char*)") -cfunc.get_ensemble_size = cwrapper.prototype("int enkf_main_get_ensemble_size(enkf_main)") -cfunc.resize_ensemble = cwrapper.prototype("void enkf_main_resize_ensemble(int)") +cfunc.resize_ensemble = cwrapper.prototype("void enkf_main_resize_ensemble(enkf_main, int)") cfunc.del_node = cwrapper.prototype("void enkf_main_del_node(enkf_main, char*)") cfunc.get_obs = cwrapper.prototype("c_void_p enkf_main_get_obs(enkf_main)") cfunc.load_obs = cwrapper.prototype("void enkf_main_load_obs(enkf_main, char*)") cfunc.reload_obs = cwrapper.prototype("void enkf_main_reload_obs(enkf_main)") cfunc.set_case_table = cwrapper.prototype("void enkf_main_set_case_table(enkf_main, char*)") -cfunc.get_pre_clear_runpath = cwrapper.prototype("bool enkf_main_get_pre_clear_runpath(enkf_main)"), +cfunc.get_pre_clear_runpath = cwrapper.prototype("bool enkf_main_get_pre_clear_runpath(enkf_main)") cfunc.set_pre_clear_runpath = cwrapper.prototype("void enkf_main_set_pre_clear_runpath(enkf_main, bool)") -cfunc.get_ensemble_size = cwrapper.prototype("int enkf_main_get_ensemble_size(enkf_main)"), -cfunc.iget_keep_runpath = cwrapper.prototype("int enkf_main_iget_keep_runpath(enkf_main, int)"), -cfunc.iset_keep_runpath = cwrapper.prototype("void enkf_main_iset_keep_runpath(enkf_main, int, keep_runpath)") +cfunc.iget_keep_runpath = cwrapper.prototype("int enkf_main_iget_keep_runpath(enkf_main, int)") +cfunc.iset_keep_runpath = cwrapper.prototype("void enkf_main_iset_keep_runpath(enkf_main, int, int_vector)") cfunc.get_templates = cwrapper.prototype("c_void_p enkf_main_get_templates(enkf_main)") cfunc.get_site_config_file = cwrapper.prototype("char* enkf_main_get_site_config_file(enkf_main)") -cfunc.initialize_from_scratch = cwrapper.prototype("int enkf_main_initialize_from_scratch(enkf_main, stringlist, int, int)") -cfunc.get_ensemble_size = cwrapper.prototype("int enkf_main_get_ensemble_size(enkf_main)") +cfunc.initialize_from_scratch = cwrapper.prototype("void enkf_main_initialize_from_scratch(enkf_main, stringlist, int, int, bool)") cfunc.get_fs = cwrapper.prototype("c_void_p enkf_main_get_fs(enkf_main)") cfunc.get_history_length = cwrapper.prototype("int enkf_main_get_history_length(enkf_main)") cfunc.initialize_from_existing__ = cwrapper.prototype("void enkf_main_initialize_from_existing__(enkf_main, char*, int, int, bool_vector, char*, stringlist)") cfunc.copy_ensemble = cwrapper.prototype("void enkf_main_copy_ensemble(enkf_main, char*, int, int, char*, int, int, bool_vector, char*, stringlist)") +cfunc.get_observations = cwrapper.prototype("void enkf_main_get_observations(enkf_main, char*, int, long*, double*, double*)") +cfunc.get_observation_count = cwrapper.prototype("int enkf_main_get_observation_count(enkf_main, char*)") +cfunc.get_alt_fs = cwrapper.prototype("c_void_p enkf_main_get_alt_fs(enkf_main , char* , bool , bool)") +cfunc.is_initialized = cwrapper.prototype("bool enkf_main_is_initialized(enkf_main)") +cfunc.iget_state = cwrapper.prototype("c_void_p enkf_main_iget_state(enkf_main, int)") +cfunc.user_select_fs = cwrapper.prototype("void enkf_main_user_select_fs(enkf_main , char*)") +cfunc.get_logh = cwrapper.prototype("void enkf_main_get_logh( enkf_main )") +cfunc.run_exp = cwrapper.prototype("void enkf_main_run_exp( enkf_main, bool_vector, bool, int, int, int)") +cfunc.run_assimilation = cwrapper.prototype("void enkf_main_run_assimilation( enkf_main, bool_vector, int, int, int)") +cfunc.run_smoother = cwrapper.prototype("void enkf_main_run_smoother(enkf_main, char*, bool)") +cfunc.get_current_fs = cwrapper.prototype("char* enkf_main_get_current_fs(enkf_main)") +cfunc.alloc_caselist = cwrapper.prototype("c_void_p enkf_main_alloc_caselist(enkf_main)") +cfunc.fprintf_config = cwrapper.prototype("void enkf_main_fprintf_config(enkf_main)") +cfunc.create_new_config = cwrapper.prototype("void enkf_main_create_new_config(char* , char*, char* , char* , int)") +cfunc.select_fs = cwrapper.prototype("void enkf_main_select_fs(enkf_main, char*)") +cfunc.fs_exists = cwrapper.prototype("bool enkf_main_fs_exists(enkf_main, char*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_node.py b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_node.py new file mode 100644 index 0000000000..0b51273fa6 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_node.py @@ -0,0 +1,66 @@ +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file 'enkf_node.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +import ctypes +from ert.cwrap.cwrap import * +from ert.cwrap.cclass import CClass +from ert.util.tvector import * +from enkf_enum import * +from ert.enkf.enkf_fs import EnkfFs +from ert.util.tvector import DoubleVector +import libenkf +class EnkfNode(CClass): + + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + @staticmethod + def alloc(config_node): + node = EnkfNode(c_ptr = cfunc.alloc( config_node ) , parent = config_node) + return node + + def user_get(self, fs, key, report_step, iens, state, value): + return cfunc.user_get(self, fs, key, report_step, iens, state, value) + + def user_get_vector( self , fs , key , iens , state , vector): + return cfunc.user_get_vector( self , fs , key , iens , state, vector) + + def value_ptr(self): + cfunc.value_ptr(self) + + @property + def vector_storage(self): + return cfunc.vector_storage(self) +################################################################## + +cwrapper = CWrapper( libenkf.lib ) +cwrapper.registerType( "enkf_node" , EnkfNode ) + +# 3. Installing the c-functions used to manipulate ecl_kw instances. +# These functions are used when implementing the EclKW class, not +# used outside this scope. +cfunc = CWrapperNameSpace("enkf_node") + + +cfunc.free = cwrapper.prototype("void enkf_node_free( enkf_node )") +cfunc.alloc = cwrapper.prototype("c_void_p enkf_node_alloc( enkf_node)") +cfunc.user_get = cwrapper.prototype("bool enkf_node_user_get_no_id(enkf_node , enkf_fs , char* , int, int , c_uint, double*)") +cfunc.user_get_vector = cwrapper.prototype("bool enkf_node_user_get_vector( enkf_node , enkf_fs , char*, int, c_uint, double_vector)") +cfunc.value_ptr = cwrapper.prototype("void enkf_node_value_ptr(enkf_node)") +cfunc.vector_storage = cwrapper.prototype("bool enkf_node_vector_storage(enkf_node)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_obs.py b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_obs.py index 2706af6419..0ebf92ff64 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_obs.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_obs.py @@ -20,22 +20,31 @@ from ert.cwrap.cclass import CClass from ert.util.tvector import * from enkf_enum import * import libenkf +from ert.util.stringlist import StringList +from ert.enkf.obs_vector import ObsVector + class EnkfObs(CClass): - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + @property + def get_config_file(self): + return cfunc.get_config_file(self) + def alloc_typed_keylist(self, type): + return StringList(c_ptr = cfunc.alloc_typed_keylist(self, type), parent = self) - def has_key(self , key): - return cfunc.has_key( self ,key ) - + @property + def has_key(self, key): + return cfunc.has_key(self, key) + @property + def get_vector(self, key): + return ObsVector(cfunc.get_vector(self,key), parent = self) ################################################################## @@ -50,3 +59,6 @@ cfunc = CWrapperNameSpace("enkf_obs") cfunc.free = cwrapper.prototype("void enkf_obs_free( enkf_obs )") cfunc.get_config_file = cwrapper.prototype("char* enkf_obs_get_config_file( enkf_obs )") +cfunc.alloc_typed_keylist = cwrapper.prototype("c_void_p enkf_obs_alloc_typed_keylist(enkf_obs, int)") +cfunc.has_key = cwrapper.prototype("bool enkf_obs_has_key(enkf_obs, char*)") +cfunc.get_vector = cwrapper.prototype("c_void_p enkf_obs_get_vector(enkf_obs, char*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_state.py b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_state.py new file mode 100644 index 0000000000..0522ca7cf7 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/enkf_state.py @@ -0,0 +1,64 @@ +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file 'enkf_state.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +import ctypes +from ert.cwrap.cwrap import * +from ert.cwrap.cclass import CClass +from ert.util.tvector import * +from enkf_enum import * +import libenkf +from ert.util.ctime import ctime +#from ert.util.ctime import time_t +class EnKFState(CClass): + + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + def kill_simulation(self): + cfunc.kill_simulation(self) + + def resubmit_simulation(self, sim_number): + cfunc.resubmit_simulation(self, sim_number) + + @property + def get_run_status(self): + return cfunc.get_run_status(self) + + @property + def get_start_time(self): + return cfunc.get_start_time(self) + + @property + def get_submit_time(self): + return cfunc.get_submit_time(self) +################################################################## + +cwrapper = CWrapper( libenkf.lib ) +cwrapper.registerType( "enkf_state" , EnKFState ) + +cfunc = CWrapperNameSpace("enkf_state") + +################################################################## +################################################################## +cfunc.free = cwrapper.prototype("void enkf_state_free( enkf_state )") +cfunc.kill_simulation = cwrapper.prototype("void enkf_state_kill_simulation(enkf_state)") +cfunc.resubmit_simulation = cwrapper.prototype("void enkf_state_resubmit_simulation(enkf_state, int)") +cfunc.get_run_status = cwrapper.prototype("int enkf_state_get_run_status(enkf_state)") +cfunc.get_start_time = cwrapper.prototype("int enkf_state_get_start_time(enkf_state)") +cfunc.get_submit_time = cwrapper.prototype("int enkf_state_get_submit_time(enkf_state)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/ens_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/ens_config.py index 49860688ba..b5a689a9cc 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/ens_config.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/ens_config.py @@ -18,42 +18,64 @@ import ctypes from ert.cwrap.cwrap import * from ert.cwrap.cclass import CClass from ert.util.tvector import * -from enkf_enum import * -import libenkf +from ert.enkf.enkf_enum import * +import ert.enkf.libenkf +from ert.ecl.ecl_grid import EclGrid +from ert.enkf.enkf_config_node import EnkfConfigNode +from ert.util.stringlist import StringList + class EnsConfig(CClass): - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) - - def __del__(self): - if self.owner: - cfunc.free( self ) - - def has_key(self , key): return cfunc.has_key( self ,key ) + def get_node(self, key): + node = EnkfConfigNode( cfunc.get_node(self, key), parent = self) + return node + + @property + def alloc_keylist(self): + key_list = StringList( c_ptr = cfunc.alloc_keylist(self), parent = self) + return key_list + + def add_summary(self, key): + node = EnkfConfigNode( cfunc.add_summary(self, key, 2), parent = self) + return node + def add_gen_kw(self, key): + node = EnkfConfigNode( cfunc.add_gen_kw(self, key), parent = self) + return node + + def add_gen_data(self, key): + node = EnkfConfigNode( cfunc.add_gen_data(self, key), parent = self) + return node + + def add_field(self, key, eclipse_grid): + node = EnkfConfigNode( cfunc.add_field(self, key, eclipse_grid), parent = self) + return node + + def alloc_keylist_from_var_type(self, var_mask): + return StringList(c_ptr = cfunc.alloc_keylist_from_var_type(self,var_mask), parent = self) ################################################################## cwrapper = CWrapper( libenkf.lib ) cwrapper.registerType( "ens_config" , EnsConfig ) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("ens_config") - -cfunc.free = cwrapper.prototype("void ensemble_config_free( ens_config )") -cfunc.has_key = cwrapper.prototype("bool ensemble_config_has_key( ens_config , char* )") -cfunc.get_node = cwrapper.prototype("c_void_p ensemble_config_get_node( ens_config , char*)") -cfunc.alloc_keylist = cwrapper.prototype("c_void_p ensemble_config_alloc_keylist( ens_config )") -cfunc.add_summary = cwrapper.prototype("c_void_p ensemble_config_add_summary( ens_config, char*)") -cfunc.add_gen_kw = cwrapper.prototype("c_void_p ensemble_config_add_gen_kw( ens_config, char*)") -cfunc.add_gen_data = cwrapper.prototype("c_void_p ensemble_config_add_gen_data( ens_config, char*)") -cfunc.add_field = cwrapper.prototype("c_void_p ensemble_config_add_field( ens_config, char*, ecl_grid)") +cfunc.free = cwrapper.prototype("void ensemble_config_free( ens_config )") +cfunc.has_key = cwrapper.prototype("bool ensemble_config_has_key( ens_config , char* )") +cfunc.get_node = cwrapper.prototype("c_void_p ensemble_config_get_node( ens_config , char*)") +cfunc.alloc_keylist = cwrapper.prototype("c_void_p ensemble_config_alloc_keylist( ens_config )") +cfunc.add_summary = cwrapper.prototype("c_void_p ensemble_config_add_summary( ens_config, char*, int)") +cfunc.add_gen_kw = cwrapper.prototype("c_void_p ensemble_config_add_gen_kw( ens_config, char*)") +cfunc.add_gen_data = cwrapper.prototype("c_void_p ensemble_config_add_gen_data( ens_config, char*)") +cfunc.add_field = cwrapper.prototype("c_void_p ensemble_config_add_field( ens_config, char*, ecl_grid)") cfunc.alloc_keylist_from_var_type = cwrapper.prototype("c_void_p ensemble_config_alloc_keylist_from_var_type(ens_config, int)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/ert_template.py b/ThirdParty/Ert/devel/python/python/ert/enkf/ert_template.py index dbb1ee5bd9..59d763a6ad 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/ert_template.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/ert_template.py @@ -22,37 +22,32 @@ from enkf_enum import * import libenkf class ErtTemplate(CClass): - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) - - - def has_key(self , key): - return cfunc.has_key( self ,key ) + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + @property + def get_template_file(self): + return cfunc.get_template_file(self) + @property + def get_target_file(self): + return cfunc.get_target_file(self) + @property + def get_args_as_string(self): + return cfunc.get_args_as_string(self) ################################################################## cwrapper = CWrapper( libenkf.lib ) -cwrapper.registerType( "ert_template" , AnalysisConfig ) +cwrapper.registerType( "ert_template" , ErtTemplate ) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("ert_template") - - +################################################################## +################################################################## cfunc.free = cwrapper.prototype("void ert_template_free( ert_template )") -cfunc.alloc_list = cwrapper.prototype("c_void_p ert_templates_alloc_list(long)"), -cfunc.get_template = cwrapper.prototype("c_void_p ert_templates_get_template(long, char*)"), -cfunc.get_template_file = cwrapper.prototype("char* ert_template_get_template_file(long)"), -cfunc.get_target_file = cwrapper.prototype("char* ert_template_get_target_file(long)"), -cfunc.get_args_as_string = cwrapper.prototype("char* ert_template_get_args_as_string(long)"), -cfunc.clear = cwrapper.prototype("void ert_templates_clear(long)"), -cfunc.add_template = cwrapper.prototype("void ert_templates_add_template(long, char*, char*, char*, char*)"),] +cfunc.get_template_file = cwrapper.prototype("char* ert_template_get_template_file(ert_template)") +cfunc.get_target_file = cwrapper.prototype("char* ert_template_get_target_file(ert_template)") +cfunc.get_args_as_string = cwrapper.prototype("char* ert_template_get_args_as_string(ert_template)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/ert_templates.py b/ThirdParty/Ert/devel/python/python/ert/enkf/ert_templates.py new file mode 100644 index 0000000000..fe7170c6f6 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/ert_templates.py @@ -0,0 +1,62 @@ +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file 'ert_templates.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +import ctypes +from ert.cwrap.cwrap import * +from ert.cwrap.cclass import CClass +from ert.util.tvector import * +from enkf_enum import * +import libenkf +from ert.util.stringlist import StringList +from ert.enkf.ert_template import ErtTemplate +class ErtTemplates(CClass): + + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + @property + def alloc_list(self): + return StringList(c_ptr = cfunc.alloc_list(self), parent = self) + + def clear(self): + cfunc.clear(self) + + def get_template(self,key): + template = ErtTemplate( cfunc.get_template( self, key ), parent = self) + return template + + @property + def add_template(self, key, template_file, target_file, arg_string): + return ErtTemplate(cfunc.add_template(self, key, template_file, target_file, arg_string), parent = self) + + + +################################################################## + +cwrapper = CWrapper( libenkf.lib ) +cwrapper.registerType( "ert_templates" , ErtTemplates ) + +cfunc = CWrapperNameSpace("ert_templates") +################################################################## +################################################################## +cfunc.free = cwrapper.prototype("void ert_templates_free( ert_templates )") +cfunc.alloc_list = cwrapper.prototype("c_void_p ert_templates_alloc_list(ert_templates)") +cfunc.get_template = cwrapper.prototype("c_void_p ert_templates_get_template(ert_templates, char*)") +cfunc.clear = cwrapper.prototype("void ert_templates_clear(ert_templates)") +cfunc.add_template = cwrapper.prototype("void ert_templates_add_template(ert_templates, char*, char*, char*, char*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/field.py b/ThirdParty/Ert/devel/python/python/ert/enkf/field.py new file mode 100644 index 0000000000..679f114ebf --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/field.py @@ -0,0 +1,48 @@ +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file 'field.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +import ctypes +from ert.cwrap.cwrap import * +from ert.cwrap.cclass import CClass +from ert.util.tvector import * +from enkf_enum import * +import libenkf +class FieldObs(CClass): + + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + def ijk_get_double(self , i,j,k): + return cfunc.ijk_get_double( self ,i,j,k ) + + + +################################################################## + +cwrapper = CWrapper( libenkf.lib ) +cwrapper.registerType( "field" , FieldObs ) + +# 3. Installing the c-functions used to manipulate ecl_kw instances. +# These functions are used when implementing the EclKW class, not +# used outside this scope. +cfunc = CWrapperNameSpace("field") + + +cfunc.free = cwrapper.prototype("void field_free( field )") +cfunc.ijk_get_double = cwrapper.prototype("double field_ijk_get_double(field, int, int, int)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/field_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/field_config.py index 3ff7b3a1f5..6f333cc876 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/field_config.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/field_config.py @@ -20,34 +20,59 @@ from ert.cwrap.cclass import CClass from ert.util.tvector import * from enkf_enum import * import libenkf -class GenDataConfig(CClass): +class FieldConfig(CClass): - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + @property + def get_type(self): + return cfunc.get_type(self) + @property + def get_truncation_mode(self): + return cfunc.get_truncation_mode(self) - def has_key(self , key): - return cfunc.has_key( self ,key ) + @property + def get_truncation_min(self): + return cfunc.get_truncation_min(self) + @property + def get_init_transform_name(self): + return cfunc.get_init_transform_name(self) + @property + def get_output_transform_name(self): + return cfunc.get_output_transform_name(self) + @property + def get_truncation_max(self): + return cfunc.get_truncation_max(self) + + @property + def get_nx(self): + return cfunc.get_nx(self) + + @property + def get_ny(self): + return cfunc.get_ny(self) + + @property + def get_nz(self): + return cfunc.get_ny(self) + + def ijk_active(self, i,j,k): + return cfunc.ijk_active(self,i,j,k) ################################################################## - cwrapper = CWrapper( libenkf.lib ) -cwrapper.registerType( "field_config" , GenDataConfig ) +cwrapper.registerType( "field_config" , FieldConfig ) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("field_config") - - +################################################################## +################################################################## cfunc.free = cwrapper.prototype("void field_config_free( field_config )") cfunc.get_type = cwrapper.prototype("int field_config_get_type(field_config)") cfunc.get_truncation_mode = cwrapper.prototype("int field_config_get_truncation_mode(field_config)") @@ -55,4 +80,8 @@ cfunc.get_truncation_min = cwrapper.prototype("double field_config_get_tr cfunc.get_truncation_max = cwrapper.prototype("double field_config_get_truncation_max(field_config)") cfunc.get_init_transform_name = cwrapper.prototype("char* field_config_get_init_transform_name(field_config)") cfunc.get_output_transform_name = cwrapper.prototype("char* field_config_get_output_transform_name(field_config)") -cfunc.get_init_file_fmt = cwrapper.prototype("char* field_config_get_init_file_fmt(field_config)") +cfunc.ijk_active = cwrapper.prototype("bool field_config_ijk_active(field_config, int, int, int)") +cfunc.get_nx = cwrapper.prototype("int field_config_get_nx(field_config)") +cfunc.get_ny = cwrapper.prototype("int field_config_get_ny(field_config)") +cfunc.get_nz = cwrapper.prototype("int field_config_get_nz(field_config)") +cfunc.get_grid = cwrapper.prototype("c_void_p field_config_get_grid(field_config)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/gen_data_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/gen_data_config.py index b5f9f4dd07..39144f0580 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/gen_data_config.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/gen_data_config.py @@ -20,20 +20,34 @@ from ert.cwrap.cclass import CClass from ert.util.tvector import * from enkf_enum import * import libenkf + class GenDataConfig(CClass): - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + @property + def get_template_file(self): + return cfunc.get_template_file(self) + @property + def get_template_key(self): + return cfunc.get_template_key(self) - def has_key(self , key): - return cfunc.has_key( self ,key ) + @property + def get_initial_size(self): + return cfunc.get_initial_size(self) + + @property + def get_output_format(self): + return cfunc.get_output_format(self) + + @property + def get_input_format(self): + return cfunc.get_input_format(self) @@ -53,4 +67,5 @@ cfunc.get_output_format = cwrapper.prototype("c_void_p gen_data_config_get_ cfunc.get_input_format = cwrapper.prototype("c_void_p gen_data_config_get_input_format(gen_data_config)") cfunc.get_template_file = cwrapper.prototype("char* gen_data_config_get_template_file(gen_data_config)") cfunc.get_template_key = cwrapper.prototype("char* gen_data_config_get_template_key(gen_data_config)") -cfunc.get_init_file_fmt = cwrapper.prototype("char* gen_data_config_get_init_file_fmt(gen_data_config)") +cfunc.get_initial_size = cwrapper.prototype("int gen_data_config_get_initial_size(gen_data_config)") + diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/gen_kw_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/gen_kw_config.py index 66cdf2795b..afe9def000 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/gen_kw_config.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/gen_kw_config.py @@ -18,37 +18,38 @@ import ctypes from ert.cwrap.cwrap import * from ert.cwrap.cclass import CClass from ert.util.tvector import * -from enkf_enum import * -import libenkf +from ert.enkf.enkf_enum import * +import ert.enkf.libenkf +from ert.util.stringlist import StringList class GenKwConfig(CClass): - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + @property + def get_template_file(self): + return cfunc.get_template_file(self) - def has_key(self , key): - return cfunc.has_key( self ,key ) - + @property + def get_parameter_file(self): + return cfunc.get_parameter_file(self) + @property + def alloc_name_list(self): + return StringList(c_ptr = cfunc.alloc_name_list(self), parent = self) ################################################################## cwrapper = CWrapper( libenkf.lib ) cwrapper.registerType( "gen_kw_config" , GenKwConfig ) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("gen_kw_config") - - +################################################################## +################################################################## cfunc.free = cwrapper.prototype("void gen_kw_config_free( gen_kw_config )") cfunc.get_template_file = cwrapper.prototype("char* gen_kw_config_get_template_file(gen_kw_config)") -cfunc.get_init_file_fmt = cwrapper.prototype("char* gen_kw_config_get_init_file_fmt(gen_kw_config)") cfunc.get_parameter_file = cwrapper.prototype("char* gen_kw_config_get_parameter_file(gen_kw_config)") +cfunc.alloc_name_list = cwrapper.prototype("c_void_p gen_kw_config_alloc_name_list(gen_kw_config)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/libenkf.py b/ThirdParty/Ert/devel/python/python/ert/enkf/libenkf.py index 89452d3add..5adf6f9361 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/libenkf.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/libenkf.py @@ -13,9 +13,10 @@ # # See the GNU General Public License at # for more details. -import ert.util.libutil -import ert.ecl.libecl -import ert.job_queue.libjob_queue + +import ert.util +import ert.ecl +import ert.job_queue import ert.rms.librms import ert.cwrap.clib as clib diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/local_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/local_config.py index 3b28a60050..682c03823c 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/local_config.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/local_config.py @@ -20,33 +20,34 @@ from ert.cwrap.cclass import CClass from ert.util.tvector import * from enkf_enum import * import libenkf +from ert.util.stringlist import StringList class LocalConfig(CClass): - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) - - - def has_key(self , key): - return cfunc.has_key( self ,key ) - + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + @property + def get_config_files(self): + config_files = StringList(c_ptr = cfunc.get_config_files(self), parent = self) + return config_files + def clear_config_files(self): + cfunc.clear_config_files(self) + def add_config_file(self, file): + cfunc.add_config_file(self, file) ################################################################## cwrapper = CWrapper( libenkf.lib ) cwrapper.registerType( "local_config" , LocalConfig ) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("local_config") +################################################################## +################################################################## cfunc.free = cwrapper.prototype("void local_config_free( local_config )") cfunc.get_config_files = cwrapper.prototype("c_void_p local_config_get_config_files( local_config )") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/model_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/model_config.py index ffb6fd8a11..4c9ce0a684 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/model_config.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/model_config.py @@ -14,49 +14,79 @@ # See the GNU General Public License at # for more details. -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -from enkf_enum import * -import libenkf +import ctypes +from ert.job_queue import ForwardModel +from ert.sched import HistoryType +from libenkf import * +from enkf_enum import * +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace + + class ModelConfig(CClass): - - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) + def __init__(self, c_ptr, parent=None): + if parent: + self.init_cref(c_ptr, parent) + else: + self.init_cobj(c_ptr, cfunc.free) + + @property + def get_enkf_sched_file(self): + return cfunc.get_enkf_sched_file(self) + + def set_enkf_sched_file(self, file): + cfunc.get_enkf_sched_file(self, file) + + @property + def get_history_source(self): + return HistoryType(c_ptr=cfunc.get_history_source(self), parent=self) + + def set_history_source(self, history_source, sched_file, refcase): + return cfunc.select_history(self, history_source, sched_file, refcase) - def has_key(self , key): - return cfunc.has_key( self ,key ) + @property + def get_max_internal_submit(self): + return cfunc.get_max_internal_submit(self) + def set_max_internal_submit(self, max): + cfunc.get_max_internal_submit(self, max) + @property + def get_forward_model(self): + ford_model = ForwardModel(c_ptr=cfunc.get_forward_model(self), parent=self) + return ford_model -################################################################## + @property + def get_case_table_file(self): + return cfunc.get_case_table_file(self) -cwrapper = CWrapper( libenkf.lib ) -cwrapper.registerType( "model_config" , ModelConfig ) + @property + def get_runpath_as_char(self): + return cfunc.get_runpath_as_char(self) + + def select_runpath(self, path_key): + return cfunc.select_runpath(self, path_key) + + ################################################################## + +cwrapper = CWrapper(libenkf.lib) +cwrapper.registerType("model_config", ModelConfig) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("model_config") +################################################################## +################################################################## -cfunc.free = cwrapper.prototype("void model_config_free( model_config )") +cfunc.free = cwrapper.prototype("void model_config_free( model_config )") cfunc.get_enkf_sched_file = cwrapper.prototype("char* model_config_get_enkf_sched_file( model_config )") cfunc.set_enkf_sched_file = cwrapper.prototype("void model_config_set_enkf_sched_file( model_config, char*)") -cfunc.get_history_source = cwrapper.prototype("int model_config_get_history_source(model_config)") -cfunc.set_history_source = cwrapper.prototype("void model_config_set_history_source(model_config, int)") -cfunc.get_forward_model = cwrapper.prototype("c_void_p model_config_get_forward_model(model_config)") -cfunc.get_max_resample = cwrapper.prototype("int model_config_get_max_resample(model_config)") -cfunc.set_max_resample = cwrapper.prototype("void model_config_set_max_resample(model_config, int)") +cfunc.get_history_source = cwrapper.prototype("c_void_p model_config_get_history_source(model_config)") +cfunc.select_history = cwrapper.prototype( + "bool model_config_select_history(model_config, history_type, c_void_p, ecl_sum)") +cfunc.get_forward_model = cwrapper.prototype("c_void_p model_config_get_forward_model(model_config)") +cfunc.get_max_internal_submit = cwrapper.prototype("int model_config_get_max_internal_submit(model_config)") +cfunc.set_max_internal_submit = cwrapper.prototype("void model_config_set_max_internal_submit(model_config, int)") cfunc.get_case_table_file = cwrapper.prototype("char* model_config_get_case_table_file(model_config)") cfunc.get_runpath_as_char = cwrapper.prototype("char* model_config_get_runpath_as_char(model_config)") -cfunc.set_runpath_fmt = cwrapper.prototype("void model_config_set_runpath_fmt(model_config, char*)") +cfunc.select_runpath = cwrapper.prototype("void model_config_select_runpath(model_config, char*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/obs_vector.py b/ThirdParty/Ert/devel/python/python/ert/enkf/obs_vector.py new file mode 100644 index 0000000000..4bed9d61ac --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/obs_vector.py @@ -0,0 +1,60 @@ +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file 'obs_vector.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +import ctypes +from ert.cwrap.cwrap import * +from ert.cwrap.cclass import CClass +from ert.util.tvector import * +from enkf_enum import * +import libenkf +class ObsVector(CClass): + + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + @property + def get_state_kw(self): + return cfunc.get_state_kw(self) + + def iget_node(self, index): + cfunc.iget_node(self,index) + + @property + def get_num_active(self): + return cfunc.get_num_active(self) + + @property + def iget_active(self, index): + return cfunc.iget_active(self, index) +################################################################## + +cwrapper = CWrapper( libenkf.lib ) +cwrapper.registerType( "obs_vector" , ObsVector ) + +# 3. Installing the c-functions used to manipulate ecl_kw instances. +# These functions are used when implementing the EclKW class, not +# used outside this scope. +cfunc = CWrapperNameSpace("obs_vector") + + +cfunc.free = cwrapper.prototype("void obs_vector_free( obs_vector )") +cfunc.get_state_kw = cwrapper.prototype("char* obs_vector_get_state_kw( obs_vector )") +cfunc.iget_node = cwrapper.prototype("void obs_vector_iget_node( obs_vector, int)") +cfunc.get_num_active = cwrapper.prototype("int obs_vector_get_num_active( obs_vector )") +cfunc.iget_active = cwrapper.prototype("bool obs_vector_iget_active( obs_vector, int)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/plot_conf.py b/ThirdParty/Ert/devel/python/python/ert/enkf/plot_conf.py new file mode 100644 index 0000000000..a3f652ad49 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/plot_conf.py @@ -0,0 +1,103 @@ +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file 'plot_conf.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +import ctypes +from ert.cwrap.cwrap import * +from ert.cwrap.cclass import CClass +from ert.util.tvector import * +from enkf_enum import * +import ert.enkf.libenkf + +class PlotConf(CClass): + + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + @property + def get_path(self): + return cfunc.get_path(self) + + def set_path(self, path): + cfunc.set_path(self, path) + + @property + def get_driver(self): + return cfunc.get_driver(self) + + def set_driver(self, driver): + cfunc.set_driver(self, driver) + + @property + def get_errorbar_max(self): + return cfunc.get_errorbar_max(self) + + def set_errorbar_max(self, max): + cfunc.set_errorbar_max(self, max) + + @property + def get_width(self): + return cfunc.get_width(self) + + def set_width(self, value): + cfunc.set_width(self, value) + + @property + def get_height(self): + return cfunc.get_height(self) + + def set_height(self, value): + cfunc.set_height(self, value) + + @property + def get_viewer(self): + return cfunc.get_viewer(self) + + def set_viewer(self, value): + cfunc.set_viewer(self, value) + + @property + def get_image_type(self): + return cfunc.get_image_type(self) + + def set_image_type(self, value): + cfunc.set_image_type(self, value) +################################################################## + +cwrapper = CWrapper( libenkf.lib ) +cwrapper.registerType( "plot_conf" , PlotConf ) + +cfunc = CWrapperNameSpace("plot_conf") +################################################################## +################################################################## +cfunc.free = cwrapper.prototype("void plot_config_free( plot_conf )") +cfunc.get_path = cwrapper.prototype("char* plot_config_get_path(plot_conf)") +cfunc.set_path = cwrapper.prototype("void plot_config_set_path(plot_conf, char*)") +cfunc.get_driver = cwrapper.prototype("char* plot_config_get_driver(plot_conf)") +cfunc.set_driver = cwrapper.prototype("void plot_config_set_driver(plot_conf, char*)") +cfunc.get_errorbar_max = cwrapper.prototype("int plot_config_get_errorbar_max(plot_conf)") +cfunc.set_errorbar_max = cwrapper.prototype("void plot_config_set_errorbar_max(plot_conf, int)") +cfunc.get_width = cwrapper.prototype("int plot_config_get_width(plot_conf)") +cfunc.set_width = cwrapper.prototype("void plot_config_set_width(plot_conf, int)") +cfunc.get_height = cwrapper.prototype("int plot_config_get_height(plot_conf)") +cfunc.set_height = cwrapper.prototype("void plot_config_set_height(plot_conf, int)") +cfunc.get_viewer = cwrapper.prototype("char* plot_config_get_viewer(plot_conf)") +cfunc.set_viewer = cwrapper.prototype("void plot_config_set_viewer(plot_conf, char*)") +cfunc.get_image_type = cwrapper.prototype("char* plot_config_get_image_type(plot_conf)") +cfunc.set_image_type = cwrapper.prototype("void plot_config_set_image_type(plot_conf, char*)") + diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/plot_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/plot_config.py deleted file mode 100644 index 33ea1c309e..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/plot_config.py +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'plot_config.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -from enkf_enum import * -import libenkf -class PlotConfig(CClass): - - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) - - - def has_key(self , key): - return cfunc.has_key( self ,key ) - - - -################################################################## - -cwrapper = CWrapper( libenkf.lib ) -cwrapper.registerType( "plot_config" , PlotConfig ) - -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. -cfunc = CWrapperNameSpace("plot_config") - - -cfunc.free = cwrapper.prototype("void plot_config_free( plot_config )") -cfunc.get_path = cwrapper.prototype("char* plot_config_get_path(plot_config)") -cfunc.set_path = cwrapper.prototype("void plot_config_set_path(plot_config, char*)") -cfunc.get_driver = cwrapper.prototype("char* plot_config_get_driver(plot_config)") -cfunc.set_driver = cwrapper.prototype("void plot_config_set_driver(plot_config, char*)") -cfunc.get_errorbar_max = cwrapper.prototype("int plot_config_get_errorbar_max(plot_config)") -cfunc.set_errorbar_max = cwrapper.prototype("void plot_config_set_errorbar_max(plot_config, int)") -cfunc.get_width = cwrapper.prototype("int plot_config_get_width(plot_config)") -cfunc.set_width = cwrapper.prototype("void plot_config_set_width(plot_config, int)") -cfunc.get_height = cwrapper.prototype("int plot_config_get_height(plot_config)") -cfunc.set_height = cwrapper.prototype("void plot_config_set_height(plot_config, int)") -cfunc.get_viewer = cwrapper.prototype("char* plot_config_get_viewer(plot_config)") -cfunc.set_viewer = cwrapper.prototype("void plot_config_set_viewer(plot_config, char*)") -cfunc.get_image_type = cwrapper.prototype("char* plot_config_get_image_type(plot_config)") -cfunc.set_image_type = cwrapper.prototype("void plot_config_set_image_type(plot_config, char*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/site_config.py b/ThirdParty/Ert/devel/python/python/ert/enkf/site_config.py index a91da3a5b9..6c121b85b1 100644 --- a/ThirdParty/Ert/devel/python/python/ert/enkf/site_config.py +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/site_config.py @@ -15,38 +15,149 @@ # for more details. import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -from enkf_enum import * +from enkf_enum import * +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.job_queue import ExtJoblist, JobQueue +from ert.util import StringList import libenkf +from ert.enkf.libenkf import * + + + + class SiteConfig(CClass): - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) - - def __del__(self): - if self.owner: - cfunc.free( self ) + @property + def get_queue_name(self): + return cfunc.get_queue_name( self ) - def has_key(self , key): - return cfunc.has_key( self ,key ) + def set_job_queue(self, queue): + cfunc.set_job_queue( self , queue) + @property + def get_lsf_queue(self): + return cfunc.get_lsf_queue( self ) + def set_lsf_queue(self, queue): + cfunc.set_lsf_queue( self , queue) + @property + def get_max_running_lsf(self): + return cfunc.get_max_running_lsf( self ) + + def set_max_running_lsf(self, max_running): + cfunc.set_max_running_lsf( self , max_running) + + @property + def get_lsf_request(self): + return cfunc.get_lsf_request( self ) + + def set_lsf_request(self, lsf_request): + cfunc.set_lsf_request( self , lsf_request) + + def clear_rsh_host_list(self): + cfunc.set_rsh_host_list( self ) + + @property + def get_rsh_command(self): + return cfunc.get_rsh_command( self ) + + def set_rsh_command(self, rsh_command): + cfunc.set_rsh_command( self , rsh_command) + + @property + def get_max_running_rsh(self): + return cfunc.get_max_running_rsh( self ) + + def set_max_running_rsh(self, max_running): + cfunc.set_max_running_rsh( self , max_running) + + @property + def get_max_running_local(self): + return cfunc.get_max_running_local( self ) + + def set_max_running_local(self, max_running): + cfunc.set_max_running_local( self , max_running) + + @property + def get_job_script(self): + return cfunc.get_job_script( self ) + + def set_job_script(self, job_script): + cfunc.set_job_script( self , job_script) + + @property + def get_env_hash(self): + return cfunc.get_env_hash( self ) + + def setenv(self, var, value): + cfunc.setenv( self , var, value) + + def clear_env(self): + cfunc.clear_env( self ) + + @property + def get_path_variables(self): + return StringList(c_ptr = cfunc.get_path_variables( self ), parent = self) + + @property + def get_path_values(self): + return StringList(c_ptr = cfunc.get_path_values( self ), parent = self) + + def clear_pathvar(self): + cfunc.clear_pathvar( self ) + + def update_pathvar(self, pathvar, value): + cfunc.update_pathvar( self ) + + @property + def get_installed_jobs(self): + installed_jobs = ExtJoblist( cfunc.get_installed_jobs( self ), parent = self) + return installed_jobs + + @property + def get_max_submit(self): + return cfunc.get_max_submit( self ) + + def set_max_submit(self, max): + cfunc.set_max_submit( self , max) + + @property + def get_license_root_path(self): + return cfunc.get_license_root_path( self ) + + def set_license_root_pathmax_submit(self, path): + cfunc.set_license_root_path( self , path) + + @property + def queue_is_running(self): + return cfunc.queue_is_running( self ) + + def get_job_queue(self): + return JobQueue( c_ptr = cfunc.get_job_queue(self), parent = self) + + @property + def get_rsh_host_list(self): + return cfunc.get_rsh_host_list(self) + + def add_rsh_host(self, host, max_running): + cfunc.add_rsh_host(self, host, max_running) ################################################################## cwrapper = CWrapper( libenkf.lib ) cwrapper.registerType( "site_config" , SiteConfig ) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("site_config") +################################################################## +################################################################## cfunc.free = cwrapper.prototype("void site_config_free( site_config )") cfunc.get_queue_name = cwrapper.prototype("char* site_config_get_queue_name(site_config)") @@ -71,14 +182,14 @@ cfunc.get_max_submit = cwrapper.prototype("int site_config_get_max_submit cfunc.set_max_submit = cwrapper.prototype("void site_config_set_max_submit(site_config, int)") cfunc.get_license_root_path = cwrapper.prototype("char* site_config_get_license_root_path(site_config)") cfunc.set_license_root_path = cwrapper.prototype("void site_config_set_license_root_path(site_config, char*)") -cfunc.get_job_script = cwrapper.prototype("char* site_config_get_job_script(site_config)"), +cfunc.get_job_script = cwrapper.prototype("char* site_config_get_job_script(site_config)") cfunc.set_job_script = cwrapper.prototype("void site_config_set_job_script(site_config, char*)") -cfunc.get_env_hash = cwrapper.prototype("c_void_p site_config_get_env_hash(site_config)"), -cfunc.clear_env = cwrapper.prototype("void site_config_clear_env(site_config)"), +cfunc.get_env_hash = cwrapper.prototype("c_void_p site_config_get_env_hash(site_config)") +cfunc.clear_env = cwrapper.prototype("void site_config_clear_env(site_config)") cfunc.setenv = cwrapper.prototype("void site_config_setenv(site_config, char*, char*)") -cfunc.get_path_variables = cwrapper.prototype("c_void_p site_config_get_path_variables(site_config)"), -cfunc.get_path_values = cwrapper.prototype("c_void_p site_config_get_path_values(site_config)"), -cfunc.clear_pathvar = cwrapper.prototype("void site_config_clear_pathvar(site_config)"), +cfunc.get_path_variables = cwrapper.prototype("c_void_p site_config_get_path_variables(site_config)") +cfunc.get_path_values = cwrapper.prototype("c_void_p site_config_get_path_values(site_config)") +cfunc.clear_pathvar = cwrapper.prototype("void site_config_clear_pathvar(site_config)") cfunc.update_pathvar = cwrapper.prototype("void site_config_update_pathvar(site_config, char*, char*)") -cfunc.get_installed_jobs = cwrapper.prototype("c_void_p site_config_get_installed_jobs(site_config)"), -cfunc.get_license_root_path = cwrapper.prototype("char* site_config_get_license_root_path(site_config)") +cfunc.get_job_queue = cwrapper.prototype("c_void_p site_config_get_job_queue(site_config)") +cfunc.queue_is_running = cwrapper.prototype("bool site_config_queue_is_running(site_config)") diff --git a/ThirdParty/Ert/devel/python/python/ert/enkf/time_map.py b/ThirdParty/Ert/devel/python/python/ert/enkf/time_map.py new file mode 100644 index 0000000000..086ca8e6b9 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/enkf/time_map.py @@ -0,0 +1,53 @@ +# Copyright (C) 2013 Statoil ASA, Norway. +# +# The file 'time_map.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +import ctypes +from ert.cwrap.cwrap import * +from ert.cwrap.cclass import CClass +from ert.util.ctime import ctime +from ert.util.tvector import * +from enkf_enum import * +import libenkf +from ert.enkf.libenkf import * +from ert.ert.erttypes import time_t + +class TimeMap(CClass): + + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + @property + def iget_sim_days(self, step): + return cfunc.iget_sim_days(self,step) + + def iget(self,step): + return cfunc.iget(self,step) + +################################################################## +cwrapper = CWrapper( libenkf.lib ) +cwrapper.registerType( "time_map" , TimeMap ) + +cfunc = CWrapperNameSpace("time_map") + +################################################################## +################################################################## + +cfunc.free = cwrapper.prototype("void time_map_free( time_map )") +cfunc.iget_sim_days = cwrapper.prototype("double time_map_iget_sim_days(time_map, int)") +cfunc.iget = cwrapper.prototype("int time_map_iget(time_map, int)") diff --git a/ThirdParty/Ert/devel/python/python/ert/ert/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/ert/CMakeLists.txt new file mode 100644 index 0000000000..615ca11b3c --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/ert/CMakeLists.txt @@ -0,0 +1,9 @@ +set(PYTHON_SOURCES + __init__.py + enums.py + erttypes.py + ertwrapper.py + c_enums.py +) + +add_python_package( "Python ert.ert" ${PYTHON_INSTALL_PREFIX}/ert/ert "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/ert/c_enums.py b/ThirdParty/Ert/devel/python/python/ert/ert/c_enums.py new file mode 100644 index 0000000000..1b760d2306 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/ert/c_enums.py @@ -0,0 +1,79 @@ +# Copyright (C) 2013 Statoil ASA, Norway. +# +# The file 'c_enums.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +from ctypes import * + +class EnumerationType(type(c_uint)): + def __new__(metacls, name, bases, dict): + if not "_members_" in dict: + _members_ = {} + for key,value in dict.items(): + if not key.startswith("_"): + _members_[key] = value + dict["_members_"] = _members_ + cls = type(c_uint).__new__(metacls, name, bases, dict) + for key,value in cls._members_.items(): + globals()[key] = value + return cls + + def __contains__(self, value): + return value in self._members_.values() + + def __repr__(self): + return "" % self.__name__ + +class Enumeration(c_uint): + __metaclass__ = EnumerationType + _members_ = {} + def __init__(self, value): + for k,v in self._members_.items(): + if v == value: + self.name = k + break + else: + raise ValueError("No enumeration member with value %r" % value) + c_uint.__init__(self, value) + + + @classmethod + def from_param(cls, param): + if isinstance(param, Enumeration): + if param.__class__ != cls: + raise ValueError("Cannot mix enumeration members") + else: + return param + else: + return cls(param) + + def __repr__(self): + return "" % (self.name, self.value, self.__class__) +#------------------------------------------------------------------- +# enum implementations +#------------------------------------------------------------------- + +class state_enum(Enumeration): + UNDEFINED = 0 + SERIALIZED = 1 + FORECAST = 2 + ANALYZED = 4 + BOTH = 6 + +class var_type(Enumeration): + INVALID_VAR = 0 + PARAMETER = 1 + DYNAMIC_STATE = 2 + DYNAMIC_RESULT = 4 + STATIC_STATE = 8 + INDEX_STATE = 16 diff --git a/ThirdParty/Ert/devel/python/python/ert/ert/enums.py b/ThirdParty/Ert/devel/python/python/ert/ert/enums.py index 93af61dcee..fb957139d8 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ert/enums.py +++ b/ThirdParty/Ert/devel/python/python/ert/ert/enums.py @@ -161,6 +161,21 @@ enkf_impl_type.GEN_KW = enkf_impl_type("Keyword", 107) enkf_impl_type.SUMMARY = enkf_impl_type("Summary", 110) enkf_impl_type.GEN_DATA = enkf_impl_type("Data", 113) +class enkf_var_type(enum): + #INVALID_VAR = None #, /* */ + PARAMETER = None #, /* A parameter which is updated with enkf: PORO , MULTFLT , ..*/ + DYNAMIC_STATE = None #, /* Dynamic data which are needed for a restart - i.e. pressure and saturations. */ + DYNAMIC_RESULT = None #, /* Dynamic results which are NOT needed for a restart - i.e. well rates. */ + #STATIC_STATE = None #, /* Keywords like XCON++ from eclipse restart files - which are just dragged along */ + #INDEX_STATE = None + +#enkf_var_type.INVALID_VAR +enkf_var_type.PARAMETER = enkf_var_type("Parameter", 1) +enkf_var_type.DYNAMIC_STATE = enkf_var_type("DynamicState", 2) +enkf_var_type.DYNAMIC_RESULT = enkf_var_type("DynamicResult", 4) +#enkf_var_type.STATIC_STATE +#enkf_var_type.INDEX_STATE + class ert_job_status_type(enum): """These "enum" values are all copies from the header file "basic_queue_driver.h".""" @@ -179,6 +194,9 @@ class ert_job_status_type(enum): ALL_FAIL = None USER_KILLED = None USER_EXIT = None + SUCCESS = None + RUNNING_CALLBACK = None + FAILED = None ert_job_status_type.NOT_ACTIVE = ert_job_status_type("JOB_QUEUE_NOT_ACTIVE", 1) ert_job_status_type.LOADING = ert_job_status_type("JOB_QUEUE_LOADING", 2) @@ -194,6 +212,11 @@ ert_job_status_type.ALL_OK = ert_job_status_type("JOB_QUEUE_ALL_OK", 1024) ert_job_status_type.ALL_FAIL = ert_job_status_type("JOB_QUEUE_ALL_FAIL", 2048) ert_job_status_type.USER_KILLED = ert_job_status_type("JOB_QUEUE_USER_KILLED", 4096) ert_job_status_type.USER_EXIT = ert_job_status_type("JOB_QUEUE_USER_EXIT", 8192) +ert_job_status_type.SUCCESS = ert_job_status_type("JOB_QUEUE_SUCCESS", 16384) +ert_job_status_type.RUNNING_CALLBACK = ert_job_status_type("JOB_QUEUE_RUNNING_CALLBACK", 32768) +ert_job_status_type.JOB_QUEUE_FAILED = ert_job_status_type("JOB_QUEUE_FAILED", 65536) + + class gen_data_file_format(enum): @@ -269,6 +292,17 @@ keep_runpath_type.DEFAULT_KEEP = keep_runpath_type("DEFAULT_KEEP", 0) keep_runpath_type.EXPLICIT_DELETE = keep_runpath_type("EXPLICIT_DELETE", 1) keep_runpath_type.EXPLICIT_KEEP = keep_runpath_type("EXPLICIT_KEEP", 2) +class run_mode_type(enum): + ENKF_ASSIMILATION = None + ENSEMBLE_EXPERIMENT = None + SMOOTHER_UPDATE = None + INIT_ONLY = None + +run_mode_type.ENKF_ASSIMILATION = run_mode_type( "ENKF_ASSIMILATION", 1) +run_mode_type.ENKF_EXPERIMENT = run_mode_type( "ENKF_EXPERIMENT", 2) +run_mode_type.SMOOTHER_UPDATE = run_mode_type( "SMOOTHER_UPDATE", 4) +run_mode_type.INIT_ONLY = run_mode_type( "INIT_ONLY", 8) + class history_source_type(enum): SCHEDULE = None REFCASE_SIMULATED = None @@ -286,4 +320,4 @@ class obs_impl_type(enum): obs_impl_type.GEN_OBS = obs_impl_type("GEN_OBS", 1) obs_impl_type.SUMMARY_OBS = obs_impl_type("SUMMARY_OBS", 2) -obs_impl_type.FIELD_OBS = obs_impl_type("FIELD_OBS", 3) \ No newline at end of file +obs_impl_type.FIELD_OBS = obs_impl_type("FIELD_OBS", 3) diff --git a/ThirdParty/Ert/devel/python/python/ert/ert/erttypes.py b/ThirdParty/Ert/devel/python/python/ert/ert/erttypes.py index 777d6be4de..456f5a291e 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ert/erttypes.py +++ b/ThirdParty/Ert/devel/python/python/ert/ert/erttypes.py @@ -23,6 +23,12 @@ import ctypes class time_t(ctypes.c_long): """A convenience class for working with time_t objects.""" +# def __init__(self , c_ptr , parent = None): +# if parent: +# self.init_cref( c_ptr , parent) +# else: +# self.init_cobj( c_ptr , cfunc.free ) + def time(self): """Return this time_t as a time.localtime() object""" diff --git a/ThirdParty/Ert/devel/python/python/ert/ert/ertwrapper.py b/ThirdParty/Ert/devel/python/python/ert/ert/ertwrapper.py index b6528e8349..39f4929748 100644 --- a/ThirdParty/Ert/devel/python/python/ert/ert/ertwrapper.py +++ b/ThirdParty/Ert/devel/python/python/ert/ert/ertwrapper.py @@ -12,18 +12,21 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. +# for more details. +from _ctypes import RTLD_GLOBAL - - -from ctypes import * -import ctypes.util import atexit +from ctypes import CDLL +import ctypes import re import sys import os +from ert.ecl import ECL_LIB +from ert.enkf import libenkf +from ert.job_queue import JOB_QUEUE_LIB +from ert.util import UTIL_LIB import erttypes - +import ert.enkf.enkf_main as enkf def RH_version(): RH = open('/etc/redhat-release' , 'r').read().split()[6] @@ -42,19 +45,9 @@ class ErtWrapper: def bootstrap(self, enkf_config , site_config , strict = True): - self.prototype("long enkf_main_bootstrap(char*, char*, bool)") - self.main = self.enkf.enkf_main_bootstrap(site_config, enkf_config, strict) + self.main = enkf.EnKFMain.bootstrap( enkf_config, site_config, strict ) print "\nBootstrap complete!" - - self.plot_config = self.__getErtPointer("enkf_main_get_plot_config") - self.analysis_config = self.__getErtPointer("enkf_main_get_analysis_config") - self.ecl_config = self.__getErtPointer("enkf_main_get_ecl_config") - self.site_config = self.__getErtPointer("enkf_main_get_site_config") - self.ensemble_config = self.__getErtPointer("enkf_main_get_ensemble_config") - self.model_config = self.__getErtPointer("enkf_main_get_model_config") - self.logh = self.__getErtPointer("enkf_main_get_logh") - self.initializeTypes() atexit.register(self.cleanup) @@ -72,11 +65,8 @@ class ErtWrapper: def __loadLibraries(self ): """Load libraries that are required by ERT and ERT itself""" - CDLL("libblas.so" , RTLD_GLOBAL) - CDLL("liblapack.so" , RTLD_GLOBAL) - CDLL("libz.so" , RTLD_GLOBAL) CDLL("libnsl.so" , RTLD_GLOBAL) - + LSF_HOME = os.getenv("LSF_HOME") if LSF_HOME: CDLL("%s/lib/liblsf.so" % LSF_HOME , RTLD_GLOBAL) @@ -84,16 +74,10 @@ class ErtWrapper: else: sys.exit("Need a value for environment variable LSF_HOME") - self.util = self.__loadLibrary( "libert_util" ) - self.__loadLibrary( "libgeometry" ) - self.ecl = self.__loadLibrary( "libecl" ) - self.__loadLibrary( "libsched" ) - self.__loadLibrary( "librms" ) - self.__loadLibrary( "libconfig" ) - self.__loadLibrary( "libanalysis" ) - self.job_queue = self.__loadLibrary( "libjob_queue" ) - self.enkf = self.__loadLibrary( "libenkf" ) - + self.util = UTIL_LIB + self.ecl = ECL_LIB + self.job_queue = JOB_QUEUE_LIB + self.enkf = libenkf.lib self.enkf.enkf_main_install_SIGNALS() @@ -133,7 +117,7 @@ class ErtWrapper: prototype expects a string formatted like this: - "type functionName(type, ... ,type)" + #type functionName(type, ... ,type)# where type is a type available to ctypes Some type are automatically converted: @@ -181,12 +165,6 @@ class ErtWrapper: return func def initializeTypes(self): - self.prototype("char* stringlist_iget(long, int)", lib=self.util) - self.prototype("long stringlist_alloc_new()", lib=self.util) - self.prototype("void stringlist_append_copy(long, char*)", lib=self.util) - self.prototype("int stringlist_get_size(long)", lib=self.util) - self.prototype("void stringlist_free(long)", lib=self.util) - self.prototype("long hash_iter_alloc(long)", lib=self.util) self.prototype("char* hash_iter_get_next_key(long)", lib=self.util) self.prototype("char* hash_get(long, char*)", lib=self.util) @@ -198,12 +176,6 @@ class ErtWrapper: self.prototype("char* subst_list_iget_key(long, int)", lib=self.util) self.prototype("char* subst_list_iget_value(long, int)", lib=self.util) - self.prototype("long bool_vector_alloc(int, bool)", lib=self.util) - self.prototype("void bool_vector_iset(long, int, bool)", lib=self.util) - self.prototype("long bool_vector_get_ptr(long)", lib=self.util) - self.prototype("void bool_vector_free(long)", lib=self.util) - - self.prototype("void enkf_main_free(long)") self.prototype("void enkf_main_fprintf_config(long)") self.prototype("void enkf_main_create_new_config(long , char*, char* , char* , int)") @@ -213,38 +185,6 @@ class ErtWrapper: erttypes.double_vector.initialize(self) - def getStringList(self, stringlist_pointer, free_after_use=False): - """Retrieve a list of strings""" - result = [] - - if stringlist_pointer == 0: - return result - - number_of_strings = self.util.stringlist_get_size(stringlist_pointer) - - for index in range(number_of_strings): - result.append(self.util.stringlist_iget(stringlist_pointer, index)) - - if free_after_use: - self.freeStringList(stringlist_pointer) - - return result - - def createStringList(self, list): - """Creates a new string list from the specified list. Remember to free the list after use.""" - sl = self.util.stringlist_alloc_new() - - for item in list: - self.util.stringlist_append_copy(sl , item) - - return sl - - - def freeStringList(self, stringlistpointer): - """Must be used if the stringlist was allocated on the python side""" - self.util.stringlist_free(stringlistpointer) - - def getHash(self, hashpointer, intValue = False, return_type="char*"): """Retrieves a hash as a list of 2 element lists""" if hashpointer == 0: @@ -284,31 +224,14 @@ class ErtWrapper: def __getErtPointer(self, function): """Returns a pointer from ERT as a c_long (64-bit support)""" func = getattr( self.enkf, function ) - func.restype = c_long # Should be c_size_t - if that exists. + func.restype = ctypes.c_long # Should be c_size_t - if that exists. return func( self.main ) - def createBoolVector(self, size, list): - """Allocates a bool vector""" - mask = self.util.bool_vector_alloc(size , False) - - for index in list: - self.util.bool_vector_iset(mask, index, True) - - return mask - - def getBoolVectorPtr(self, mask): - """Returns the pointer to a bool vector""" - return self.util.bool_vector_get_ptr(mask) - - def freeBoolVector(self, mask): - """Frees an allocated bool vector""" - self.util.bool_vector_free(mask) - def cleanup(self): """Called at atexit to clean up before shutdown""" print "Calling enkf_main_free()" - self.enkf.enkf_main_free(self.main) + self.main.__del__ def nonify(self, s): """Convert an empty string to None.""" @@ -316,7 +239,7 @@ class ErtWrapper: def save(self): """Save the state of ert to a configuration file.""" - self.enkf.enkf_main_fprintf_config(self.main) + self.main.fprintf_config diff --git a/ThirdParty/Ert/devel/python/python/ert/geo/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/geo/CMakeLists.txt index f2337e0759..99166aa0b4 100644 --- a/ThirdParty/Ert/devel/python/python/ert/geo/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/geo/CMakeLists.txt @@ -1 +1,6 @@ -add_python_package("Python ert.geo" ${PYTHON_INSTALL_PREFIX}/ert/geo "geo_polygon.py;geo.py;__init__.py;libgeo.py" True) +set(PYTHON_SOURCES + __init__.py + geo_polygon.py +) + +add_python_package("Python ert.geo" ${PYTHON_INSTALL_PREFIX}/ert/geo "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/geo/__init__.py b/ThirdParty/Ert/devel/python/python/ert/geo/__init__.py index ced6e30bc0..133eca3906 100644 --- a/ThirdParty/Ert/devel/python/python/ert/geo/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/geo/__init__.py @@ -15,4 +15,13 @@ # for more details. """ Simple package for working with 2D geometry. + """ +from ert.cwrap import clib + +import ert.util + +ERT_GEOMETRY_LIB = clib.ert_load("libert_geometry.so") + +from .geo_polygon import GeoPolygon + diff --git a/ThirdParty/Ert/devel/python/python/ert/geo/geo.py b/ThirdParty/Ert/devel/python/python/ert/geo/geo.py deleted file mode 100644 index d447d535a0..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/geo/geo.py +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'geo.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. -""" -Convenience module importing all symbols in the geo package. -""" -import libgeo -from geo_polygon import GeoPolygon - diff --git a/ThirdParty/Ert/devel/python/python/ert/geo/geo_polygon.py b/ThirdParty/Ert/devel/python/python/ert/geo/geo_polygon.py index 47a8756c64..52fcf180cb 100644 --- a/ThirdParty/Ert/devel/python/python/ert/geo/geo_polygon.py +++ b/ThirdParty/Ert/devel/python/python/ert/geo/geo_polygon.py @@ -16,32 +16,28 @@ """ Create a polygon """ +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.geo import ERT_GEOMETRY_LIB -import ctypes -import libgeo -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass - class GeoPolygon(CClass): - - def __init__(self , points): + def __init__(self, points): c_ptr = cfunc.alloc_new() - self.init_cobj( c_ptr , cfunc.free ) - for (xc,yz) in points: - self.add_point( self , xc , yc ) + self.init_cobj(c_ptr, cfunc.free) + for (xc, yc) in points: + self.add_point(xc, yc) - def add_point( self , xc , yc ): - cfunc.add_point( self , xc , yc ) + def add_point( self, xc, yc ): + cfunc.add_point(self, xc, yc) ################################################################# -cwrapper = CWrapper( libgeo.lib ) -cwrapper.registerType( "geo_polygon" , GeoPolygon ) +cwrapper = CWrapper(ERT_GEOMETRY_LIB) +cwrapper.registerType("geo_polygon", GeoPolygon) -cfunc = CWrapperNameSpace("geo_polygon") -cfunc.alloc_new = cwrapper.prototype("c_void_p geo_polygon_alloc( )") -cfunc.add_point = cwrapper.prototype("void geo_polygon_add_point( geo_polygon , double , double )") -cfunc.free = cwrapper.prototype("void geo_polygon_free( geo_polygon )") +cfunc = CWrapperNameSpace("geo_polygon") +cfunc.alloc_new = cwrapper.prototype("c_void_p geo_polygon_alloc( )") +cfunc.add_point = cwrapper.prototype("void geo_polygon_add_point( geo_polygon , double , double )") +cfunc.free = cwrapper.prototype("void geo_polygon_free( geo_polygon )") diff --git a/ThirdParty/Ert/devel/python/python/ert/geo/libgeo.py b/ThirdParty/Ert/devel/python/python/ert/geo/libgeo.py deleted file mode 100644 index 51a82db28b..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/geo/libgeo.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'libecl.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. -""" -This module will load the libgeometry.so shared library. -""" - -# This statement is necessary for side-effects (i.e. the final -# dlopen("libutil.so") call). -import ctypes -import ert.util.libutil -import ert.cwrap.clib as clib - -lib = clib.ert_load("libert_geometry.so") diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/job_queue/CMakeLists.txt index a7d4e1102e..77386d8609 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/CMakeLists.txt @@ -1 +1,11 @@ -add_python_package("Python ert.job_queue" ${PYTHON_INSTALL_PREFIX}/ert/job_queue "driver.py;__init__.py;job.py;job_queue.py;libjob_queue.py;queue.py;ext_job.py;ext_joblist.py;forward_model.py" True) +set(PYTHON_SOURCES + __init__.py + driver.py + job.py + queue.py + ext_job.py + ext_joblist.py + forward_model.py +) + +add_python_package("Python ert.job_queue" ${PYTHON_INSTALL_PREFIX}/ert/job_queue "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/__init__.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/__init__.py index 59776ca4de..97e06ca9e9 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/__init__.py @@ -18,3 +18,64 @@ The job_queue package contains modules and classes for running external commands. """ +# Getting LSF to work properly is quite painful. The situation +# is a mix of build complexity and LSF specific requirements: +# +# 1. The LSF libraries are accessed from the libjob_queue.so +# library, but observe that the dependancy on the liblsf and +# libbat libraries is through dlopen(), i.e. runtime. This module +# will therefor load happily without access to the lsf libraries. +# +# If you at a later stage create a lsf driver the runtime +# environment must be able to locate the liblsf.so, libbat.so and +# libnsl.so shared libraries, either through LD_LIBRARY_PATH or +# other means. +# +# 2. To actually use LSF you need a whole list of environment +# variables to be set: LSF_BINDIR , LSF_LIBDIR , XLDF_UIDDIR , +# LSF_SERVERDIR, LSF_ENVDIR - this is an LSF requirement and not +# related to ERT or the Python bindings. The normal way to +# achieve this is by sourcing a shell script. +# +# If the environment variable LSF_HOME is set we set the +# remaining LSF variables according to: +# +# LSF_BINDIR = $LSF_HOME/bin +# LSF_LIBDIR = $LSF_HOME/lib +# XLSF_UIDDIR = $LSF_HOME/lib/uid +# LSF_SERVERDIR = $LSF_HOME/etc +# LSF_ENVDIR = $LSF_HOME/conf +# PATH = $PATH:$LSF_BINDIR +# +# Observe that none of these variables are modified if they +# already have a value, furthermore it should be observed that +# the use of an LSF_HOME variable is something invented with ERT, +# and not standard LSF approach. + + +import os +import ert.util +import ert.cwrap.clib as clib + + +def setenv( var, value): + if not os.getenv(var): + os.environ[var] = value + +# Set up the full LSF environment - based onf LSF_HOME +LSF_HOME = os.getenv("LSF_HOME") +if LSF_HOME: + setenv("LSF_BINDIR", "%s/bin" % LSF_HOME) + setenv("LSF_LIBDIR", "%s/lib" % LSF_HOME) + setenv("XLSF_UIDDIR", "%s/lib/uid" % LSF_HOME) + setenv("LSF_SERVERDIR", "%s/etc" % LSF_HOME) + setenv("LSF_ENVDIR", "%s/conf" % LSF_HOME) # This is wrong: Statoil: /prog/LSF/conf + +JOB_QUEUE_LIB = clib.ert_load("libjob_queue.so") + +from .job import Job +from .queue import JobList, JobQueue, statusList, exList, runtimeList +from .driver import QueueDriverEnum, Driver, LSFDriver, RSHDriver, LocalDriver +from .ext_job import ExtJob +from .ext_joblist import ExtJoblist +from .forward_model import ForwardModel \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/driver.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/driver.py index e0866bfd94..075c7243bb 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/driver.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/driver.py @@ -16,137 +16,134 @@ import ctypes -import os.path +from ert.cwrap import create_enum, CClass, CWrapper, CWrapperNameSpace -import libjob_queue -from job import Job -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.cwrap.cenum import create_enum +from ert.job_queue import JOB_QUEUE_LIB, Job -# job_driver_type defintion from queue_driver.h -create_enum( libjob_queue.lib , "queue_driver_type_enum_iget" , "queue_driver_enum" , globals()) +QueueDriverEnum = create_enum(JOB_QUEUE_LIB, "queue_driver_type_enum_iget", "QueueDriverEnum") + class Driver(CClass): - def __init__( self , type , max_running = 1 , options = None): + def __init__( self, driver_type, max_running=1, options=None): """ Creates a new driver instance """ - c_ptr = cfunc.alloc_driver( type ) - self.init_cobj( c_ptr , cfunc.free_driver ) + c_ptr = cfunc.alloc_driver(driver_type) + self.init_cobj(c_ptr, cfunc.free_driver) if options: - for (key,value) in options: - self.set_option( key , value ) - self.set_max_running( max_running ) + for (key, value) in options: + self.set_option(key, value) + self.set_max_running(max_running) - def set_option(self , option , value): + def set_option(self, option, value): """ Set the driver option @option to @value. - If the option is sucessfully set the method will return True, + If the option is succlessfully set the method will return True, otherwise the method will return False. If the @option is not recognized the method will return False. The supplied value should be a string. """ - return cfunc.set_str_option( self , option , str(value) ) - + return cfunc.set_str_option(self, option, str(value)) + def is_driver_instance( self ): return True - def submit( self , name , cmd , run_path , argList , num_cpu = 1 , blocking = False): - argc = len( argList ) + def submit( self, name, cmd, run_path, argList, num_cpu=1, blocking=False): + argc = len(argList) argv = (ctypes.c_char_p * argc)() - argv[:] = map( str , argList ) - job_c_ptr = cfunc.submit( self , cmd , num_cpu , run_path , name , argc , argv ) - job = Job( self , job_c_ptr , blocking ) + argv[:] = map(str, argList) + job_c_ptr = cfunc.submit(self, cmd, num_cpu, run_path, name, argc, argv) + job = Job(self, job_c_ptr, blocking) if blocking: job.block() job = None return job - def free_job( self , job ): - cfunc.free_job( self , job ) - - def get_status( self , job ): - status = cfunc.cget_status( self , job ) + def free_job( self, job ): + cfunc.free_job(self, job) + + def get_status( self, job ): + status = cfunc.cget_status(self, job) return status - - def kill_job( self , job ): - cfunc.ckill_job( self , job ) + + def kill_job( self, job ): + cfunc.ckill_job(self, job) def get_max_running( self ): - return cfunc.get_max_running( self ) - - def set_max_running( self , max_running ): - cfunc.set_max_running( self , max_running ) - - max_running = property( get_max_running , set_max_running ) + return cfunc.get_max_running(self) + + def set_max_running( self, max_running ): + cfunc.set_max_running(self, max_running) + + max_running = property(get_max_running, set_max_running) + + @property + def name(self): + return cfunc.get_name(self) class LSFDriver(Driver): - - def __init__(self , - max_running , - lsf_server = None , - queue = "normal" , - resource_request = None): - + def __init__(self, + max_running, + lsf_server=None, + queue="normal", + resource_request=None): # The strings should match the available keys given in the # lsf_driver.h header file. - options = [("LSF_QUEUE" , queue), - ("LSF_SERVER" , lsf_server), - ("LSF_RESOURCE" , resource_request )] - Driver.__init__( self , LSF_DRIVER , max_running = max_running , options = options) - + options = [("LSF_QUEUE", queue), + ("LSF_SERVER", lsf_server), + ("LSF_RESOURCE", resource_request )] + Driver.__init__(self, QueueDriverEnum.LSF_DRIVER, max_running=max_running, options=options) + class LocalDriver(Driver): - - def __init__( self , max_running ): - Driver.__init__( self , LOCAL_DRIVER , max_running , options = [] ) - - + def __init__( self, max_running ): + Driver.__init__(self, QueueDriverEnum.LOCAL_DRIVER, max_running, options=[]) class RSHDriver(Driver): - # Changing shell to bash can come in conflict with running ssh # commands. - - def __init__( self , max_running , rsh_host_list , rsh_cmd = "/usr/bin/ssh" ): + + def __init__( self, max_running, rsh_host_list, rsh_cmd="/usr/bin/ssh" ): """ @rsh_host_list should be a list of tuples like: (hostname , max_running) """ - - options = [("RSH_CMD" , rsh_cmd)] - for (host,host_max) in rsh_host_list: - options.append( ("RSH_HOST" , "%s:%d" % (host , host_max)) ) - Driver.__init__( self , RSH_DRIVER , max_running , options = options ) - + + options = [("RSH_CMD", rsh_cmd)] + for (host, host_max) in rsh_host_list: + options.append(("RSH_HOST", "%s:%d" % (host, host_max))) + Driver.__init__(self, QueueDriverEnum.RSH_DRIVER, max_running, options=options) +#Legacy enum support for ecl_local.py +LSF_DRIVER = QueueDriverEnum.LSF_DRIVER +RSH_DRIVER = QueueDriverEnum.RSH_DRIVER +LOCAL_DRIVER = QueueDriverEnum.LOCAL_DRIVER ################################################################# -cwrapper = CWrapper( libjob_queue.lib ) -cwrapper.registerType( "driver" , Driver ) -cwrapper.registerType( "job" , Job ) -cfunc = CWrapperNameSpace( "driver" ) +cwrapper = CWrapper(JOB_QUEUE_LIB) +cwrapper.registerType("driver", Driver) +cwrapper.registerType("job", Job) +cfunc = CWrapperNameSpace("driver") -cfunc.alloc_driver_lsf = cwrapper.prototype("c_void_p queue_driver_alloc_LSF( char* , char* , char* )") -cfunc.alloc_driver_local = cwrapper.prototype("c_void_p queue_driver_alloc_local( )") -cfunc.alloc_driver_rsh = cwrapper.prototype("c_void_p queue_driver_alloc_RSH( char* , c_void_p )") -cfunc.alloc_driver = cwrapper.prototype("c_void_p queue_driver_alloc( int )") -cfunc.set_driver_option = cwrapper.prototype("void queue_driver_set_option(driver , char* , char*)") +cfunc.alloc_driver_lsf = cwrapper.prototype("c_void_p queue_driver_alloc_LSF( char* , char* , char* )") +cfunc.alloc_driver_local = cwrapper.prototype("c_void_p queue_driver_alloc_local( )") +cfunc.alloc_driver_rsh = cwrapper.prototype("c_void_p queue_driver_alloc_RSH( char* , c_void_p )") +cfunc.alloc_driver = cwrapper.prototype("c_void_p queue_driver_alloc( int )") +cfunc.set_driver_option = cwrapper.prototype("void queue_driver_set_option(driver , char* , char*)") -cfunc.free_driver = cwrapper.prototype("void queue_driver_free( driver )") -cfunc.submit = cwrapper.prototype("c_void_p queue_driver_submit_job( driver , char* , int , char* , char* , int , char**)") -cfunc.free_job = cwrapper.prototype("void queue_driver_free_job( driver , job )") -cfunc.cget_status = cwrapper.prototype("int job_queue_get_status( driver , job)") -cfunc.kill_job = cwrapper.prototype("void queue_driver_kill_job( driver , job )") -cfunc.set_str_option = cwrapper.prototype("void queue_driver_set_string_option( driver , char* , char*)") +cfunc.free_driver = cwrapper.prototype("void queue_driver_free( driver )") +cfunc.submit = cwrapper.prototype("c_void_p queue_driver_submit_job( driver , char* , int , char* , char* , int , char**)") +cfunc.free_job = cwrapper.prototype("void queue_driver_free_job( driver , job )") +cfunc.cget_status = cwrapper.prototype("int job_queue_get_status( driver , job)") +cfunc.kill_job = cwrapper.prototype("void queue_driver_kill_job( driver , job )") cfunc.set_max_running = cwrapper.prototype("void queue_driver_set_max_running( driver , int )") cfunc.get_max_running = cwrapper.prototype("int queue_driver_get_max_running( driver )") - +cfunc.set_str_option = cwrapper.prototype("bool queue_driver_set_option( driver , char* , char*) ") +cfunc.get_name = cwrapper.prototype("char* queue_driver_get_name(driver)") diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_job.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_job.py index 5cb9458e88..7f8f4bd396 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_job.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_job.py @@ -12,44 +12,119 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. - -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -from ert.enkf.enkf_enum import * -import libjob_queue +# for more details. +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.job_queue import JOB_QUEUE_LIB class ExtJob(CClass): - - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) + def __init__(self, c_ptr, parent=None): + if parent: + self.init_cref(c_ptr, parent) + else: + self.init_cobj(c_ptr, cfunc.free) + @property + def get_private_args_as_string(self): + return cfunc.get_private_args_as_string(self) - def has_key(self , key): - return cfunc.has_key( self ,key ) + def set_private_args_as_string(self, args): + cfunc.set_private_args_as_string(self, args) + @property + def get_help_text(self): + return cfunc.get_help_text(self) + @property + def is_private(self): + return cfunc.is_private(self) + + @property + def get_config_file(self): + return cfunc.get_config_file(self) + + def set_config_file(self, config_file): + cfunc.set_config_file(self, config_file) + + @property + def get_stdin_file(self): + return cfunc.get_stdin_file(self) + + def set_stdin_file(self, filename): + cfunc.set_stdin_file(self, filename) + + @property + def get_stdout_file(self): + return cfunc.get_stdout_file(self) + + def set_stdout_file(self, filename): + cfunc.set_stdout_file(self, filename) + + @property + def get_stderr_file(self): + return cfunc.get_stderr_file(self) + + def set_stderr_file(self, filename): + cfunc.set_stderr_file(self, filename) + + @property + def get_target_file(self): + return cfunc.get_target_file(self) + + def set_target_file(self, filename): + cfunc.set_target_file(self, filename) + + @property + def get_executable(self): + return cfunc.get_executable(self) + + def set_executable(self, executable): + cfunc.set_executable(self, executable) + + @property + def get_max_running(self): + return cfunc.get_max_running(self) + + def set_max_running(self, max_running): + cfunc.set_max_running(self, max_running) + + @property + def get_max_running_minutes(self): + return cfunc.get_max_running_minutes(self) + + def set_max_running_minutes(self, min_value): + cfunc.set_max_running_minutes(self, min_value) + + @property + def get_environment(self): + return cfunc.get_environment(self) + + def set_environment(self, key, value): + cfunc.set_environment(self, key, value) + + def clear_environment(self): + cfunc.clear_environment(self) + + def save(self): + cfunc.save(self) + + @staticmethod + def alloc(name, root_path, private): + job = ExtJob(c_ptr=cfunc.alloc(name, root_path, private)) + return job + + @staticmethod + def fscanf_alloc(name, root_path, private, config_file): + job = ExtJob(c_ptr=cfunc.fscanf_alloc(name, root_path, private, config_file)) + return job ################################################################## -cwrapper = CWrapper( libjob_queue.lib ) -cwrapper.registerType( "ext_job" , ExtJob ) +cwrapper = CWrapper(JOB_QUEUE_LIB) +cwrapper.registerType("ext_job", ExtJob) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("ext_job") - cfunc.free = cwrapper.prototype("void ext_job_free( ext_job )") cfunc.get_help_text = cwrapper.prototype("char* ext_job_get_help_text(ext_job)") cfunc.get_private_args_as_string = cwrapper.prototype("char* ext_job_get_private_args_as_string(ext_job)") diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_joblist.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_joblist.py index 9199cca390..6472304c2f 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_joblist.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/ext_joblist.py @@ -12,42 +12,47 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. +# for more details. +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.job_queue import JOB_QUEUE_LIB, ExtJob +from ert.util import StringList + -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -#from enkf_enum import * -import libjob_queue class ExtJoblist(CClass): - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + @property + def get_jobs(self): + return cfunc.get_jobs( self ) + @property + def alloc_list(self): + return StringList(c_ptr = cfunc.alloc_list( self ), parent = self) - def has_key(self , key): - return cfunc.has_key( self ,key ) + def del_job(self, job): + return cfunc.del_job(self, job) + def has_job(self, job): + return cfunc.has_job(self, job) + def get_job(self, job): + return ExtJob( c_ptr = cfunc.get_job( self , job), parent = self) + def add_job(self, job_name, new_job): + cfunc.add_job(self, job_name, new_job) ################################################################## -cwrapper = CWrapper( libjob_queue.lib ) +cwrapper = CWrapper(JOB_QUEUE_LIB) cwrapper.registerType( "ext_joblist" , ExtJoblist ) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("ext_joblist") - - +################################################################## +################################################################## cfunc.free = cwrapper.prototype("void ext_joblist_free( ext_joblist )") cfunc.alloc_list = cwrapper.prototype("c_void_p ext_joblist_alloc_list(ext_joblist)") cfunc.get_job = cwrapper.prototype("c_void_p ext_joblist_get_job(ext_joblist, char*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/forward_model.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/forward_model.py index cf3885d1f1..9966aad3b3 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/forward_model.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/forward_model.py @@ -12,42 +12,45 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. +# for more details. +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.job_queue import ExtJob, JOB_QUEUE_LIB +from ert.util import StringList + -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -import libjob_queue class ForwardModel(CClass): - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) - - - def has_key(self , key): - return cfunc.has_key( self ,key ) + def __init__(self , c_ptr , parent = None): + if parent: + self.init_cref( c_ptr , parent) + else: + self.init_cobj( c_ptr , cfunc.free ) + + @property + def alloc_joblist(self): + s = StringList(initial = None, c_ptr = cfunc.alloc_joblist(self)) + return s + def iget_job(self, index): + job = ExtJob( cfunc.iget_job( self, index ), parent = self) + return job + def add_job(self, name): + job = ExtJob( cfunc.add_job( self, name ), parent = self) + return job + def clear(self): + cfunc.clear(self) ################################################################## -cwrapper = CWrapper( libjob_queue.lib ) +cwrapper = CWrapper(JOB_QUEUE_LIB) cwrapper.registerType( "forward_model" , ForwardModel ) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("forward_model") - - +################################################################## +################################################################## cfunc.free = cwrapper.prototype("void forward_model_free( forward_model )") cfunc.clear = cwrapper.prototype("void forward_model_clear(forward_model)") cfunc.add_job = cwrapper.prototype("c_void_p forward_model_add_job(forward_model, char*)") cfunc.alloc_joblist = cwrapper.prototype("c_void_p forward_model_alloc_joblist(forward_model)") +cfunc.iget_job = cwrapper.prototype("c_void_p forward_model_iget_job( forward_model, int)") diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/job.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/job.py index 0f66d68be6..25367bb3f4 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/job.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/job.py @@ -17,36 +17,34 @@ import time import datetime -import ctypes -from ert.cwrap.cclass import CClass +from ert.cwrap.cclass import CClass # Enum values nicked from libjob_queue/src/basic_queue_driver.h -STATUS_PENDING = 16 -STATUS_RUNNING = 32 -STATUS_DONE = 64 -STATUS_EXIT = 128 +STATUS_PENDING = 16 +STATUS_RUNNING = 32 +STATUS_DONE = 64 +STATUS_EXIT = 128 class Job(CClass): - def __init__(self , driver , c_ptr , queue_index , blocking = False): - self.driver = driver - self.init_cobj( c_ptr , self.driver.free_job) + def __init__(self, driver, c_ptr, queue_index, blocking=False): + self.driver = driver + self.init_cobj(c_ptr, self.driver.free_job) self.submit_time = datetime.datetime.now() self.queue_index = queue_index - def block( self ): while True: status = self.status() if status == STATUS_DONE or status == STATUS_EXIT: break else: - time.sleep( 1 ) - + time.sleep(1) + def kill( self ): - self.driver.kill_job( self ) - + self.driver.kill_job(self) + @property def run_time( self ): @@ -55,12 +53,12 @@ class Job(CClass): @property def status( self ): - st = self.driver.get_status( self ) + st = self.driver.get_status(self) return st @property def running( self ): - status = self.driver.get_status( self ) + status = self.driver.get_status(self) if status == STATUS_RUNNING: return True else: @@ -69,7 +67,7 @@ class Job(CClass): @property def pending( self ): - status = self.driver.get_status( self ) + status = self.driver.get_status(self) if status == STATUS_PENDING: return True else: @@ -77,7 +75,7 @@ class Job(CClass): @property def complete( self ): - status = self.driver.get_status( self ) + status = self.driver.get_status(self) if status == STATUS_DONE or status == STATUS_EXIT: return True else: diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/job_queue.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/job_queue.py deleted file mode 100644 index 1fcda04d1b..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/job_queue.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'job_queue.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. -""" -Module doc -""" -import libjob_queue -from queue import JobQueue -from driver import Driver -from job import Job - -import ext_job -import ext_joblist -import forward_model diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/libjob_queue.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/libjob_queue.py deleted file mode 100644 index 2615a4c36b..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/libjob_queue.py +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'libjob_queue.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import os -import sys -import ctypes -import ert.util.libutil -import ert.config.libconfig -import ert.cwrap.clib as clib - - -# Getting LSF to work properly is quite painful. The situation -# is a mix of build complexity and LSF specific requirements: -# -# 1. The LSF libraries are accessed from the libjob_queue.so -# library, but observe that the dependancy on the liblsf and -# libbat libraries is through dlopen(), i.e. runtime. This module -# will therefor load happily without access to the lsf libraries. -# -# If you at a later stage create a lsf driver the runtime -# environment must be able to locate the liblsf.so, libbat.so and -# libnsl.so shared libraries, either through LD_LIBRARY_PATH or -# other means. -# -# 2. To actually use LSF you need a whole list of environment -# variables to be set: LSF_BINDIR , LSF_LIBDIR , XLDF_UIDDIR , -# LSF_SERVERDIR, LSF_ENVDIR - this is an LSF requirement and not -# related to ERT or the Python bindings. The normal way to -# achieve this is by sourcing a shell script. -# -# If the environment variable LSF_HOME is set we set the -# remaining LSF variables according to: -# -# LSF_BINDIR = $LSF_HOME/bin -# LSF_LIBDIR = $LSF_HOME/lib -# XLSF_UIDDIR = $LSF_HOME/lib/uid -# LSF_SERVERDIR = $LSF_HOME/etc -# LSF_ENVDIR = $LSF_HOME/conf -# PATH = $PATH:$LSF_BINDIR -# -# Observe that none of these variables are modified if they -# already have a value, furthermore it should be observed that -# the use of an LSF_HOME variable is something invented with ERT, -# and not standard LSF approach. - - -def setenv( var , value): - if not os.getenv( var ): - os.environ[ var ] = value - -# Set up the full LSF environment - based onf LSF_HOME -LSF_HOME = os.getenv( "LSF_HOME") -if LSF_HOME: - setenv( "LSF_BINDIR" , "%s/bin" % LSF_HOME ) - setenv( "LSF_LIBDIR" , "%s/lib" % LSF_HOME ) - setenv( "XLSF_UIDDIR" , "%s/lib/uid" % LSF_HOME ) - setenv( "LSF_SERVERDIR" , "%s/etc" % LSF_HOME) - setenv( "LSF_ENVDIR" , "%s/conf" % LSF_HOME) # This is wrong: Statoil: /prog/LSF/conf - -lib = clib.ert_load("libjob_queue.so") diff --git a/ThirdParty/Ert/devel/python/python/ert/job_queue/queue.py b/ThirdParty/Ert/devel/python/python/ert/job_queue/queue.py index 4f99352b50..b9ab94a26b 100644 --- a/ThirdParty/Ert/devel/python/python/ert/job_queue/queue.py +++ b/ThirdParty/Ert/devel/python/python/ert/job_queue/queue.py @@ -16,77 +16,69 @@ """ Module implementing a queue for managing external jobs. - """ +import time +import ctypes -import time -import threading -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass +from types import StringType, IntType # Need to import this to ensure that the ctime type is registered -import ert.util.ctime +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.util.ctime import ctime +from ert.job_queue import JOB_QUEUE_LIB, Job -import libjob_queue - -from job import Job - - class JobList: def __init__(self): self.job_list = [] self.job_dict = {} - - def __getitem__(self , index): + + def __getitem__(self, index): job = None - if isinstance(index , types.StringType): - job = self.job_dict.get( index ) - elif isinstance(index , types.IntType): + if isinstance(index, StringType): + job = self.job_dict.get(index) + elif isinstance(index, IntType): try: job = self.job_list[index] - except: + except LookupError: job = None return job - def add_job( self , job , job_name ): - job_index = len( self.job_list ) + def add_job( self, job, job_name ): + job_index = len(self.job_list) job.job_nr = job_index - self.job_dict[ job_name ] = job - self.job_list.append( job ) - + self.job_dict[job_name] = job + self.job_list.append(job) + @property def size(self): - return len( self.job_list ) - + return len(self.job_list) class exList: - def __init__(self , joblist): - self.joblist = joblist + def __init__(self, job_list): + self.job_list = job_list - def __getitem__(self , index): - job = self.joblist.__getitem__(index) + def __getitem__(self, index): + job = self.job_list.__getitem__(index) if job: return True else: return False - class statusList: - def __init__(self , joblist ): - self.joblist = joblist + def __init__(self, job_list ): + self.job_list = job_list - def __getitem__(self , index): - job = self.joblist.__getitem__(index) + def __getitem__(self, index): + job = self.job_list.__getitem__(index) if job: return job.status() else: @@ -94,16 +86,16 @@ class statusList: class runtimeList: - def __init__(self , joblist , queue): - self.joblist = joblist - self.queue = queue + def __init__(self, job_list, queue): + self.job_list = job_list + self.queue = queue - def __getitem__(self , index): - job = self.joblist.__getitem__(index) + def __getitem__(self, index): + job = self.job_list.__getitem__(index) if job: - sim_start = cfunc.iget_sim_start( self.queue , job.job_nr ) + sim_start = cfunc.iget_sim_start(self.queue, job.job_nr) if not sim_start.ctime() == -1: - return time.time( ) - sim_start.ctime() + return time.time() - sim_start.ctime() else: return None else: @@ -111,7 +103,6 @@ class runtimeList: class JobQueue(CClass): - # If the queue is created with size == 0 that means that it will # just grow as needed; for the queue layer to know when to exit # you must call the function submit_complete() when you have no @@ -122,56 +113,59 @@ class JobQueue(CClass): # necessary to explitly inform the queue layer when all jobs have # been submitted. - def __init__(self , driver , max_submit = 1 , size = 0): + def __init__(self, driver=None, max_submit=1, size=0): """ - SHort doc... - - + Short doc... The @size argument is used to say how many jobs the queue will run, in total. + + size = 0: That means that you do not tell the queue in + advance how many jobs you have. The queue will just run + all the jobs you add, but you have to inform the queue in + some way that all jobs have been submitted. To achieve + this you should call the submit_complete() method when all + jobs have been submitted.# + + size > 0: The queue will know exactly how many jobs to run, + and will continue until this number of jobs have completed + - it is not necessary to call the submit_complete() method + in this case. + """ - size = 0: That means that you do not tell the queue in - advance how many jobs you have. The queue will just run - all the jobs you add, but you have to inform the queue in - some way that all jobs have been submitted. To achieve - this you should call the submit_complete() method when all - jobs have been submitted. + OK_file = None + exit_file = None - size > 0: The queue will now exactly how many jobs to run, - and will continue until this number of jobs have completed - - it is not necessary to call the submit_complete() method - in this case. - """ + c_ptr = cfunc.alloc(max_submit, OK_file, exit_file) + self.init_cobj(c_ptr, cfunc.free) - OK_file = None - exit_file = None - self.init_cobj( c_ptr , cfunc.free_queue ) - self.driver = driver - self.jobs = JobList() - self.size = size + self.jobs = JobList() + self.size = size - self.exists = exList( self.jobs ) - self.status = statusList( self.jobs ) - self.run_time = runtimeList( self.jobs , self ) - cfunc.set_driver( self , driver.c_ptr ) - self.start( blocking = False ) + self.exists = exList(self.jobs) + self.status = statusList(self.jobs) + self.run_time = runtimeList(self.jobs, self) + + self.start(blocking=False) + if driver: + self.driver = driver + cfunc.set_driver(self, driver.c_ptr) - def kill_job(self , index): + def kill_job(self, index): """ Will kill job nr @index. """ - job = self.jobs.__getitem__( index ) + job = self.jobs.__getitem__(index) if job: job.kill() - def start( self , blocking = False): + def start( self, blocking=False): verbose = False - cfunc.run_jobs( self , self.size , verbose ) + cfunc.run_jobs(self, self.size, verbose) - def submit( self , cmd , run_path , job_name , argv , num_cpu = 1): + def submit( self, cmd, run_path, job_name, argv, num_cpu=1): c_argv = (ctypes.c_char_p * len(argv))() c_argv[:] = argv job_index = self.jobs.size @@ -179,11 +173,20 @@ class JobQueue(CClass): done_callback = None callback_arg = None retry_callback = None - - queue_index = cfunc.cadd_job_mt( self , cmd , done_callback , retry_callback , callback_arg , num_cpu , run_path , job_name , len(argv) , c_argv) - job = Job( self.driver , cfunc.get_job_ptr( self , queue_index ) , queue_index , False ) - - self.jobs.add_job( job , job_name ) + + queue_index = cfunc.cadd_job_mt(self, + cmd, + done_callback, + retry_callback, + callback_arg, + num_cpu, + run_path, + job_name, + len(argv), + c_argv) + job = Job(self.driver, cfunc.get_job_ptr(self, queue_index), queue_index, False) + + self.jobs.add_job(job, job_name) return job @@ -195,14 +198,14 @@ class JobQueue(CClass): Will block as long as there are waiting jobs. """ while self.num_waiting > 0: - time.sleep( 1 ) - + time.sleep(1) + def block(self): """ Will block as long as there are running jobs. """ while self.running: - time.sleep( 1 ) + time.sleep(1) def submit_complete( self ): @@ -219,30 +222,30 @@ class JobQueue(CClass): queue, in that case it is not necessary to call the submit_complete() method. """ - cfunc.submit_complete( self ) + cfunc.submit_complete(self) @property def running(self): - return cfunc.is_running( self ) + return cfunc.is_running(self) @property def num_running( self ): - return cfunc.num_running( self ) + return cfunc.num_running(self) @property def num_pending( self ): - return cfunc.num_pending( self ) + return cfunc.num_pending(self) @property def num_waiting( self ): - return cfunc.num_waiting( self ) + return cfunc.num_waiting(self) @property def num_complete( self ): - return cfunc.num_complete( self ) + return cfunc.num_complete(self) - def exists(self , index): + def exists(self, index): job = self.__getitem__(index) if job: return True @@ -251,22 +254,28 @@ class JobQueue(CClass): def get_max_running( self ): return self.driver.get_max_running() - - def set_max_running( self , max_running ): - self.driver.set_max_running( max_running ) - - #max_running = property( fget = get_max_running , fset = set_max_running ) + def set_max_running( self, max_running ): + self.driver.set_max_running(max_running) + + def user_exit(self): + cfunc.user_exit(self) + + def set_pause_on(self): + cfunc.set_pause_on() + + def set_pause_off(self): + cfunc.set_pause_off() ################################################################# -cwrapper = CWrapper( libjob_queue.lib ) -cwrapper.registerType( "job_queue" , JobQueue ) -cfunc = CWrapperNameSpace( "JobQueue" ) +cwrapper = CWrapper(JOB_QUEUE_LIB) +cwrapper.registerType("job_queue", JobQueue) +cfunc = CWrapperNameSpace("JobQueue") -cfunc.user_exit = cwrapper.prototype("void job_queue_user_exit( job_queue )") -cfunc.alloc_queue = cwrapper.prototype("c_void_p job_queue_alloc( int , char* , char* )") -cfunc.free_queue = cwrapper.prototype("void job_queue_free( job_queue )") +cfunc.alloc = cwrapper.prototype("c_void_p job_queue_alloc( int , char* , char* )") +cfunc.user_exit = cwrapper.prototype("void job_queue_user_exit( job_queue )") +cfunc.free = cwrapper.prototype("void job_queue_free( job_queue )") cfunc.set_max_running = cwrapper.prototype("void job_queue_set_max_running( job_queue , int)") cfunc.get_max_running = cwrapper.prototype("int job_queue_get_max_running( job_queue )") cfunc.set_driver = cwrapper.prototype("void job_queue_set_driver( job_queue , c_void_p )") @@ -274,12 +283,17 @@ cfunc.cadd_job_mt = cwrapper.prototype("int job_queue_add_job_mt( job_queue cfunc.cadd_job_st = cwrapper.prototype("int job_queue_add_job_st( job_queue , char* , c_void_p , c_void_p , c_void_p , int , char* , char* , int , char**)") cfunc.start_queue = cwrapper.prototype("void job_queue_run_jobs( job_queue , int , bool)") cfunc.run_jobs = cwrapper.prototype("void job_queue_run_jobs_threaded(job_queue , int , bool)") + cfunc.num_running = cwrapper.prototype("int job_queue_get_num_running( job_queue )") cfunc.num_complete = cwrapper.prototype("int job_queue_get_num_complete( job_queue )") cfunc.num_waiting = cwrapper.prototype("int job_queue_get_num_waiting( job_queue )") cfunc.num_pending = cwrapper.prototype("int job_queue_get_num_pending( job_queue )") + cfunc.is_running = cwrapper.prototype("int job_queue_is_running( job_queue )") cfunc.submit_complete = cwrapper.prototype("void job_queue_submit_complete( job_queue )") cfunc.get_job_ptr = cwrapper.prototype("c_void_p job_queue_iget_job( job_queue , int)") -cfunc.iget_sim_start = cwrapper.prototype("time_t job_queue_iget_sim_start( job_queue , int)") +cfunc.iget_sim_start = cwrapper.prototype("int job_queue_iget_sim_start( job_queue , int)") cfunc.get_active_size = cwrapper.prototype("int job_queue_get_active_size( job_queue )") +cfunc.get_pause = cwrapper.prototype("bool job_queue_get_pause(job_queue)") +cfunc.set_pause_on = cwrapper.prototype("void job_queue_set_pause_on(job_queue)") +cfunc.set_pause_off = cwrapper.prototype("void job_queue_set_pause_off(job_queue)") diff --git a/ThirdParty/Ert/devel/python/python/ert/rms/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/rms/CMakeLists.txt index 3c92090d20..d967186453 100644 --- a/ThirdParty/Ert/devel/python/python/ert/rms/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/rms/CMakeLists.txt @@ -1 +1,8 @@ -add_python_package("Python ert.rms" ${PYTHON_INSTALL_PREFIX}/ert/rms "__init__.py;librms.py;rms.py" True) +set(PYTHON_SOURCES + __init__.py + librms.py + rms.py + +) + +add_python_package("Python ert.rms" ${PYTHON_INSTALL_PREFIX}/ert/rms "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/sched/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/sched/CMakeLists.txt index 16885d61a5..714bb73a2b 100644 --- a/ThirdParty/Ert/devel/python/python/ert/sched/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/sched/CMakeLists.txt @@ -1 +1,7 @@ -add_python_package("Python ert.sched" ${PYTHON_INSTALL_PREFIX}/ert/sched "__init__.py;libsched.py;sched_file.py;sched.py" True) +set(PYTHON_SOURCES + __init__.py + sched_file.py + history.py +) + +add_python_package("Python ert.sched" ${PYTHON_INSTALL_PREFIX}/ert/sched "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/sched/__init__.py b/ThirdParty/Ert/devel/python/python/ert/sched/__init__.py index e69de29bb2..5257711e70 100644 --- a/ThirdParty/Ert/devel/python/python/ert/sched/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/sched/__init__.py @@ -0,0 +1,26 @@ +# Copyright (C) 2013 Statoil ASA, Norway. +# +# The file '__init__.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +from ert.cwrap import clib + +import ert.ecl +import ert.util +import ert.geo + +SCHED_LIB = clib.ert_load("libsched.so") + + +from .sched_file import SchedFile +from .history import HistoryType \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/python/ert/sched/history.py b/ThirdParty/Ert/devel/python/python/ert/sched/history.py new file mode 100644 index 0000000000..144ffb4a9e --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/sched/history.py @@ -0,0 +1,51 @@ +# Copyright (C) 2013 Statoil ASA, Norway. +# +# The file 'history.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.sched import SCHED_LIB + + +class HistoryType(CClass): + def __init__(self, c_ptr, parent=None): + if parent: + self.init_cref(c_ptr, parent) + else: + self.init_cobj(c_ptr, cfunc.free) + + def get_source_string(self): + return cfunc.get_source_string(self) + + @staticmethod + def alloc_from_refcase(refcase, use_history): + return HistoryType(cfunc.alloc_from_refcase(refcase, use_history)) + + @staticmethod + def alloc_from_sched_file(sched_file): + return HistoryType(cfunc.alloc_from_sched_file(":", sched_file)) + + ################################################################## + +cwrapper = CWrapper(SCHED_LIB) +cwrapper.registerType("history_type", HistoryType) + +cfunc = CWrapperNameSpace("history_type") + +################################################################## +################################################################## + +cfunc.free = cwrapper.prototype("void history_free( history_type )") +cfunc.get_source_string = cwrapper.prototype("char* history_get_source_string(history_type)") +cfunc.alloc_from_refcase = cwrapper.prototype("c_void_p history_alloc_from_refcase(ecl_sum, bool)") +cfunc.alloc_from_sched_file = cwrapper.prototype("c_void_p history_alloc_from_sched_file(char*, c_void_p)") diff --git a/ThirdParty/Ert/devel/python/python/ert/sched/libsched.py b/ThirdParty/Ert/devel/python/python/ert/sched/libsched.py deleted file mode 100644 index 04daaffba5..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/sched/libsched.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'libsched.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - - -import ctypes -import ert.cwrap.clib as clib -import ert.util.libutil -import ert.geo.libgeo -import ert.ecl.libecl - -lib = clib.ert_load("libsched.so") - diff --git a/ThirdParty/Ert/devel/python/python/ert/sched/sched.py b/ThirdParty/Ert/devel/python/python/ert/sched/sched.py deleted file mode 100644 index cd96d74f77..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/sched/sched.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'sched.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import libsched -from sched_file import SchedFile - diff --git a/ThirdParty/Ert/devel/python/python/ert/sched/sched_file.py b/ThirdParty/Ert/devel/python/python/ert/sched/sched_file.py index 48287b687b..b6095fd20d 100644 --- a/ThirdParty/Ert/devel/python/python/ert/sched/sched_file.py +++ b/ThirdParty/Ert/devel/python/python/ert/sched/sched_file.py @@ -12,17 +12,12 @@ # FITNESS FOR A PARTICULAR PURPOSE. # # See the GNU General Public License at -# for more details. +# for more details. +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.sched import SCHED_LIB +from ert.util import ctime -import types -import ctypes -import libsched -from ert.cwrap.cwrap import * -from ert.cwrap.cfile import CFILE -from ert.cwrap.cclass import CClass -from ert.util.ctime import ctime - class SchedFile(CClass): def __init__(self , filename , start_time): @@ -39,7 +34,7 @@ class SchedFile(CClass): -cwrapper = CWrapper( libsched.lib ) +cwrapper = CWrapper(SCHED_LIB) cwrapper.registerType( "sched_file" , SchedFile ) # 3. Installing the c-functions used to manipulate ecl_kw instances. diff --git a/ThirdParty/Ert/devel/python/python/ert/util/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/util/CMakeLists.txt index 92e1128323..fd40f8ebd0 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/util/CMakeLists.txt @@ -1,2 +1,20 @@ -add_python_package("Python ert.util" ${PYTHON_INSTALL_PREFIX}/ert/util - "ctime.py;hash.py;__init__.py;latex.py;libutil.py;lookup_table.py;matrix.py;stat.py;stringlist.py;tvector.py;util_func.py" T) +set(PYTHON_SOURCES + __init__.py + buffer.py + ctime.py + hash.py + latex.py + log.py + lookup_table.py + matrix.py + stat.py + stringlist.py + tvector.py + util_func.py + +) + + +add_python_package("Python ert.util" ${PYTHON_INSTALL_PREFIX}/ert/util "${PYTHON_SOURCES}" T) + +add_python_package("Python ert.util test" ${PYTHON_INSTALL_PREFIX}/ert/util "test_area.py" F) diff --git a/ThirdParty/Ert/devel/python/python/ert/util/__init__.py b/ThirdParty/Ert/devel/python/python/ert/util/__init__.py index c2ab14ebb8..95010d5a28 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/__init__.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/__init__.py @@ -36,3 +36,33 @@ The modules included in the util package are: """ +import ert.cwrap.clib as clib + +clib.load("libz" , "libz.so.1") + +# Depending on the Fortran compiler which has been used to compile +# blas / lapack the there might be an additional dependency on libg2c: + +try: + # First try to load without libg2c + clib.load("libblas.so" , "libblas.so.3") + clib.load("liblapack.so") +except ImportError: + # Then try to load with libg2c + clib.load("libg2c.so.0") + clib.load("libblas.so" , "libblas.so.3") + clib.load("liblapack.so") + +UTIL_LIB = clib.ert_load("libert_util.so") + +from .tvector import DoubleVector, IntVector, BoolVector, TimeVector, TVector +from .stringlist import StringList +from .stat import quantile, quantile_sorted +from .matrix import Matrix +from .log import Log +from .lookup_table import LookupTable +from .buffer import Buffer +from .ctime import ctime +from .hash import Hash +from .test_area import TestArea, TestAreaContext +from .latex import LaTeX \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/python/ert/util/buffer.py b/ThirdParty/Ert/devel/python/python/ert/util/buffer.py new file mode 100644 index 0000000000..1067af70aa --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/util/buffer.py @@ -0,0 +1,38 @@ +# Copyright (C) 2013 Statoil ASA, Norway. +# +# The file 'buffer.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.util import UTIL_LIB + + +class Buffer(CClass): + def __init__(self, size, parent=None): + c_ptr = cfunc.alloc(size) + if parent: + self.init_cref(c_ptr, parent) + else: + self.init_cobj(c_ptr, cfunc.free) + + +################################################################## + +cwrapper = CWrapper(UTIL_LIB) +cwrapper.registerType("buffer", Buffer) + +cfunc = CWrapperNameSpace("buffer") + +cfunc.free = cwrapper.prototype("void buffer_free( buffer )") +cfunc.alloc = cwrapper.prototype("c_void_p buffer_alloc(int)") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/ctime.py b/ThirdParty/Ert/devel/python/python/ert/util/ctime.py index 5991d37514..e8ae49de15 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/ctime.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/ctime.py @@ -20,35 +20,36 @@ import ctypes import types import datetime import time -from ert.cwrap.cwrap import * +from ert.cwrap import CWrapper class ctime(ctypes.c_long): - def __init__(self , value): - if isinstance(value , types.IntType): + def __init__(self, value): + if isinstance(value, types.IntType): self.value = value else: try: # Input value is assumed to be datetime.datetime instance - self.value = int(math.floor(time.mktime( (value.year , value.month , value.day , value.hour , value.minute , value.second , 0 , 0 , -1 ) ))) - except: + self.value = int(math.floor(time.mktime( + (value.year, value.month, value.day, value.hour, value.minute, value.second, 0, 0, -1 )))) + except (OverflowError, ValueError, AttributeError): # Input value is assumed to be datetime.date instance - self.value = int(math.floor(time.mktime( (value.year , value.month , value.day , 0 , 0 , 0 , 0 , 0 , -1 ) ))) - - + self.value = int(math.floor(time.mktime((value.year, value.month, value.day, 0, 0, 0, 0, 0, -1 )))) + + def ctime(self): return self.value def time(self): """Return this time_t as a time.localtime() object""" - return time.localtime( self.value ) + return time.localtime(self.value) def date(self): """Return this time_t as a datetime.date([year, month, day])""" - return datetime.date( *self.time()[0:3]) + return datetime.date(*self.time()[0:3]) def datetime(self): - return datetime.datetime( *self.time()[0:6] ) + return datetime.datetime(*self.time()[0:6]) def __str__(self): return "%s" % (str(self.datetime())) @@ -59,9 +60,15 @@ class ctime(ctypes.c_long): def __lt__(self, other): return not self >= other + def __eq__(self, other): + return self.value == other.value + + @property + def stripped(self): + return time.strptime(self, "%Y-%m-%d %H:%M:S%") -cwrapper = CWrapper( None ) -cwrapper.registerType( "time_t" , ctime ) -cwrapper.registerType( "time_t*" , ctypes.POINTER(ctime)) +cwrapper = CWrapper(None) +cwrapper.registerType("time_t", ctime) +cwrapper.registerType("time_t*", ctypes.POINTER(ctime)) diff --git a/ThirdParty/Ert/devel/python/python/ert/util/hash.py b/ThirdParty/Ert/devel/python/python/ert/util/hash.py index ac7d504474..3f9ced5742 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/hash.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/hash.py @@ -15,28 +15,26 @@ # for more details. -import sys -import ctypes -import libutil -from ert.cwrap.cwrap import * +from ert.cwrap import CWrapper, CWrapperNameSpace, CClass +from ert.util import UTIL_LIB -class Hash: - +class Hash(CClass): def __init__( self ): self.c_ptr = cfunc.hash_alloc() - + def __del__( self ): - cfunc.hash_del( self ) - - def __getitem__(self , key): + cfunc.hash_del(self) + + def __getitem__(self, key): #todo: missing implementation? pass -CWrapper.registerType( "hash" , Hash ) -cwrapper = CWrapper( libutil.lib ) -cfunc = CWrapperNameSpace("hash") +CWrapper.registerType("hash", Hash) +cwrapper = CWrapper(UTIL_LIB) + +cfunc = CWrapperNameSpace("hash") cfunc.hash_alloc = cwrapper.prototype("long hash_alloc( )") -cfunc.hash_free = cwrapper.prototype("void hash_free( hash )") -cfunc.hash_get = cwrapper.prototype("long hash_get(hash , char*)") +cfunc.hash_free = cwrapper.prototype("void hash_free( hash )") +cfunc.hash_get = cwrapper.prototype("long hash_get(hash , char*)") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/latex.py b/ThirdParty/Ert/devel/python/python/ert/util/latex.py index 6df9052cd8..ce6911ef75 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/latex.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/latex.py @@ -16,70 +16,68 @@ """ Module implmenting LaTeX class for wrapping the latex compilation of a file. """ -import libutil -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass - +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.util import UTIL_LIB class LaTeX(CClass): - def __init__(self , src_file , in_place = False): - c_ptr = cfunc.alloc( src_file , in_place ) - self.init_cobj( c_ptr , cfunc.free ) + def __init__(self, src_file, in_place=False): + c_ptr = cfunc.alloc(src_file, in_place) + self.init_cobj(c_ptr, cfunc.free) @property def runpath(self): - return cfunc.get_runpath( self ) + return cfunc.get_runpath(self) + + def compile(self, ignore_errors=False, with_xref=False, cleanup=True): + return cfunc.compile(self, ignore_errors, with_xref, cleanup) - def compile(self , ignore_errors = False , with_xref = False , cleanup = True): - return cfunc.compile( self , ignore_errors , with_xref , cleanup) - @property def in_place(self): - return cfunc.compile_in_place( self ) - + return cfunc.compile_in_place(self) + #----------------------------------------------------------------- - def set_target( self , target_file): - cfunc.set_target( self , target_file ) + def set_target( self, target_file): + cfunc.set_target(self, target_file) def get_target( self ): - return cfunc.get_target( self ) + return cfunc.get_target(self) - target = property( get_target , set_target) + target = property(get_target, set_target) #----------------------------------------------------------------- #----------------------------------------------------------------- def get_timeout( self ): - return cfunc.get_timeout( self ) - - def set_timeout( self , timeout): - cfunc.set_timeout( self , timeout) + return cfunc.get_timeout(self) - timeout = property( get_timeout , set_timeout) + def set_timeout( self, timeout): + cfunc.set_timeout(self, timeout) + + timeout = property(get_timeout, set_timeout) #----------------------------------------------------------------- - def link_content( self , directory ): - cfunc.link_directory_content( self , directory ) + def link_content( self, directory ): + cfunc.link_directory_content(self, directory) - def link_path( self , path): - cfunc.link_path( self , path) + def link_path( self, path): + cfunc.link_path(self, path) -cwrapper = CWrapper( libutil.lib ) -cwrapper.registerType( "latex" , LaTeX ) +cwrapper = CWrapper(UTIL_LIB) +cwrapper.registerType("latex", LaTeX) # 3. Installing the c-functions used to manipulate. cfunc = CWrapperNameSpace("latex") -cfunc.alloc = cwrapper.prototype("c_void_p latex_alloc( char* , bool )") -cfunc.free = cwrapper.prototype("void latex_free( latex )") -cfunc.compile = cwrapper.prototype("bool latex_compile(latex , bool , bool , bool)") -cfunc.get_runpath = cwrapper.prototype("char* latex_get_runpath( latex )") -cfunc.get_target = cwrapper.prototype("char* latex_get_target_file( latex )") -cfunc.set_target = cwrapper.prototype("void latex_set_target_file( latex , char* )") -cfunc.set_timeout = cwrapper.prototype("void latex_set_timeout( latex , int )") -cfunc.get_timeout = cwrapper.prototype("int latex_get_timeout( latex )") -cfunc.compile_in_place = cwrapper.prototype("bool latex_compile_in_place( latex )"); -cfunc.link_directory_content = cwrapper.prototype("void latex_link_directory_content( latex , char*)"); -cfunc.link_path = cwrapper.prototype("void latex_link_path( latex , char*)"); +cfunc.alloc = cwrapper.prototype("c_void_p latex_alloc( char* , bool )") +cfunc.free = cwrapper.prototype("void latex_free( latex )") +cfunc.compile = cwrapper.prototype("bool latex_compile(latex , bool , bool , bool)") +cfunc.get_runpath = cwrapper.prototype("char* latex_get_runpath( latex )") +cfunc.get_target = cwrapper.prototype("char* latex_get_target_file( latex )") +cfunc.set_target = cwrapper.prototype("void latex_set_target_file( latex , char* )") +cfunc.set_timeout = cwrapper.prototype("void latex_set_timeout( latex , int )") +cfunc.get_timeout = cwrapper.prototype("int latex_get_timeout( latex )") +cfunc.compile_in_place = cwrapper.prototype("bool latex_compile_in_place( latex )"); +cfunc.link_directory_content = cwrapper.prototype("void latex_link_directory_content( latex , char*)"); +cfunc.link_path = cwrapper.prototype("void latex_link_path( latex , char*)"); diff --git a/ThirdParty/Ert/devel/python/python/ert/util/libutil.py b/ThirdParty/Ert/devel/python/python/ert/util/libutil.py deleted file mode 100644 index 6b909df0d6..0000000000 --- a/ThirdParty/Ert/devel/python/python/ert/util/libutil.py +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'libutil.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - - -import ert.cwrap.clib as clib - -clib.load("libz" , "libz.so.1") - -# Depending on the Fortran compiler which has been used to compile -# blas / lapack the there might be an additional dependency on libg2c: - -try: - # First try to load without libg2c - clib.load("libblas.so" , "libblas.so.3") - clib.load("liblapack.so") -except: - # Then try to load with libg2c - clib.load("libg2c.so.0") - clib.load("libblas.so" , "libblas.so.3") - clib.load("liblapack.so") - -lib = clib.ert_load("libert_util.so") - diff --git a/ThirdParty/Ert/devel/python/python/ert/util/log.py b/ThirdParty/Ert/devel/python/python/ert/util/log.py index 29a597e95d..ec74372aee 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/log.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/log.py @@ -14,40 +14,43 @@ # See the GNU General Public License at # for more details. -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass -from ert.util.tvector import * -from enkf_enum import * -import libenkf +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace +from ert.util import UTIL_LIB + + class Log(CClass): - - def __init__(self , c_ptr = None): - self.owner = False - self.c_ptr = c_ptr - - - def __del__(self): - if self.owner: - cfunc.free( self ) + def __init__(self, c_ptr, parent=None): + if parent: + self.init_cref(c_ptr, parent) + else: + self.init_cobj(c_ptr, cfunc.free) + @property + def get_filename(self): + #return cfunc.get_filename( self ) + return "ert_config.log" - def has_key(self , key): - return cfunc.has_key( self ,key ) + def reopen(self, filename): + print "Logfile cannot be reopened" + #cfunc.reopen( self , filename) + @property + def get_level(self): + #return cfunc.get_level( self ) + return 0 + def set_level(self, level): + cfunc.set_level(self, level) ################################################################## -cwrapper = CWrapper( libenkf.lib ) -cwrapper.registerType( "log" , Log ) +cwrapper = CWrapper(UTIL_LIB) +cwrapper.registerType("log", Log) -# 3. Installing the c-functions used to manipulate ecl_kw instances. -# These functions are used when implementing the EclKW class, not -# used outside this scope. cfunc = CWrapperNameSpace("log") -cfunc.free = cwrapper.prototype("void log( log )") -cfunc.get_filename = cwrapper.prototype("char* log_get_filename(long)") -cfunc.reset_filename = cwrapper.prototype("void log_reset_filename(long, char*)") -cfunc.get_level = cwrapper.prototype("int log_get_level(long)") -cfunc.set_level = cwrapper.prototype("void log_set_level(long, int)") + +cfunc.free = cwrapper.prototype("void log( log )") +cfunc.get_filename = cwrapper.prototype("char* log_get_filename(log)") +cfunc.reopen = cwrapper.prototype("void log_reopen(log, char*)") +cfunc.get_level = cwrapper.prototype("int log_get_level(log)") +cfunc.set_level = cwrapper.prototype("void log_set_level(log, int)") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/lookup_table.py b/ThirdParty/Ert/devel/python/python/ert/util/lookup_table.py index f0b3a60551..1eca28b904 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/lookup_table.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/lookup_table.py @@ -15,61 +15,60 @@ # for more details. -import sys -import ctypes -import libutil -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass - +from ert.util import UTIL_LIB +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace class LookupTable(CClass): - def __init__(self): self.c_ptr = cfunc.alloc() - - - @property + + + @property def max(self): - return cfunc.max( self ) + return cfunc.max(self) - @property + @property def min(self): - return cfunc.min( self ) + return cfunc.min(self) - @property + @property def arg_max(self): - return cfunc.arg_max( self ) + return cfunc.arg_max(self) - @property + @property def arg_min(self): - return cfunc.arg_min( self ) - - def interp( self , x ): - return cfunc.interp(self , x ) + return cfunc.arg_min(self) + + def interp(self, x): + return cfunc.interp(self, x) + + def append(self, x, y): + cfunc.append(self, x, y) - def append( self , x , y ): - cfunc.append( self , x , y ) - @property def size(self): - return cfunc.size( self ) + return cfunc.size(self) def __del__(self): - cfunc.free( self ) + cfunc.free(self) - -CWrapper.registerType( "lookup_table" , LookupTable ) -cwrapper = CWrapper( libutil.lib ) -cfunc = CWrapperNameSpace("lookup_table") + def __len__(self): + return self.size -cfunc.alloc = cwrapper.prototype("c_void_p lookup_table_alloc_empty()") -cfunc.max = cwrapper.prototype("double lookup_table_get_max_value( lookup_table )") -cfunc.min = cwrapper.prototype("double lookup_table_get_min_value( lookup_table )") -cfunc.arg_max = cwrapper.prototype("double lookup_table_get_max_arg( lookup_table )") -cfunc.arg_min = cwrapper.prototype("double lookup_table_get_min_arg( lookup_table )") -cfunc.append = cwrapper.prototype("void lookup_table_append( lookup_table , double , double )") -cfunc.size = cwrapper.prototype("int lookup_table_get_size( lookup_table )") -cfunc.interp = cwrapper.prototype("double lookup_table_interp( lookup_table , double)") -cfunc.free = cwrapper.prototype("void lookup_table_free( lookup_table )") + +CWrapper.registerType("lookup_table", LookupTable) +cwrapper = CWrapper(UTIL_LIB) + +cfunc = CWrapperNameSpace("lookup_table") + +cfunc.alloc = cwrapper.prototype("c_void_p lookup_table_alloc_empty()") +cfunc.max = cwrapper.prototype("double lookup_table_get_max_value( lookup_table )") +cfunc.min = cwrapper.prototype("double lookup_table_get_min_value( lookup_table )") +cfunc.arg_max = cwrapper.prototype("double lookup_table_get_max_arg( lookup_table )") +cfunc.arg_min = cwrapper.prototype("double lookup_table_get_min_arg( lookup_table )") +cfunc.append = cwrapper.prototype("void lookup_table_append( lookup_table , double , double )") +cfunc.size = cwrapper.prototype("int lookup_table_get_size( lookup_table )") +cfunc.interp = cwrapper.prototype("double lookup_table_interp( lookup_table , double)") +cfunc.free = cwrapper.prototype("void lookup_table_free( lookup_table )") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/matrix.py b/ThirdParty/Ert/devel/python/python/ert/util/matrix.py index 49bbe9b0ca..06858af2c9 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/matrix.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/matrix.py @@ -27,37 +27,34 @@ # choice. -import sys -import ctypes -import libutil -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass +from ert.util import UTIL_LIB +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace + class Matrix(CClass): + def __init__(self, rows, columns): + c_ptr = cfunc.matrix_alloc(rows, columns) + self.init_cobj(c_ptr, cfunc.free) - def __init__(self , rows , columns): - c_ptr = cfunc.matrix_alloc( rows , columns ) - self.init_cobj( c_ptr , cfunc.free ) - def __getitem__(self, index_tuple ): - print index_tuple - (i,j) = index_tuple - return cfunc.iget( self , i,j) + # print index_tuple + (i, j) = index_tuple + return cfunc.iget(self, i, j) - def __setitem__(self, index_tuple , value): - (i,j) = index_tuple - return cfunc.iset( self , i,j , value) + def __setitem__(self, index_tuple, value): + (i, j) = index_tuple + return cfunc.iset(self, i, j, value) ################################################################# -CWrapper.registerType( "matrix" , Matrix ) -cwrapper = CWrapper( libutil.lib ) -cfunc = CWrapperNameSpace("matrix") +CWrapper.registerType("matrix", Matrix) +cwrapper = CWrapper(UTIL_LIB) +cfunc = CWrapperNameSpace("matrix") cfunc.matrix_alloc = cwrapper.prototype("c_void_p matrix_alloc( int , int )") -cfunc.free = cwrapper.prototype("void matrix_free( matrix )") -cfunc.iget = cwrapper.prototype("double matrix_iget( matrix , int , int )") -cfunc.iset = cwrapper.prototype("void matrix_iset( matrix , int , int , double)") +cfunc.free = cwrapper.prototype("void matrix_free( matrix )") +cfunc.iget = cwrapper.prototype("double matrix_iget( matrix , int , int )") +cfunc.iset = cwrapper.prototype("void matrix_iset( matrix , int , int , double)") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/stat.py b/ThirdParty/Ert/devel/python/python/ert/util/stat.py index e8654361e6..8342491faf 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/stat.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/stat.py @@ -15,22 +15,20 @@ # for more details. -import ctypes -import libutil -import tvector -from ert.cwrap.cwrap import * - -def quantile( data , q ): - return cfunc.quantile( data , q ) +from ert.util import UTIL_LIB +from ert.cwrap import CWrapper, CWrapperNameSpace -def quantile_sorted( data , q ): - return cfunc.quantile_sorted( data , q ) +def quantile( data, q ): + return cfunc.quantile(data, q) -cwrapper = CWrapper( libutil.lib ) -cfunc = CWrapperNameSpace("stat") +def quantile_sorted( data, q ): + return cfunc.quantile_sorted(data, q) -cfunc.quantile = cwrapper.prototype("double statistics_empirical_quantile( double_vector , double )") +cwrapper = CWrapper(UTIL_LIB) +cfunc = CWrapperNameSpace("stat") + +cfunc.quantile = cwrapper.prototype("double statistics_empirical_quantile( double_vector , double )") cfunc.quantile_sorted = cwrapper.prototype("double statistics_empirical_quantile( double_vector , double )") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/stringlist.py b/ThirdParty/Ert/devel/python/python/ert/util/stringlist.py index 833e733249..783b9b95a8 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/stringlist.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/stringlist.py @@ -30,17 +30,14 @@ be an iterable consisting of strings, and the strings property will return a normal python list of string objects, used in this way you hardly need to notice that the StringList class is at play. """ +import sys -import libutil -import types -import ctypes -from ert.cwrap.cwrap import * -from ert.cwrap.cclass import CClass - +from ert.util import UTIL_LIB +from types import StringType, IntType +from ert.cwrap import CClass, CWrapper, CWrapperNameSpace class StringList(CClass): - #@classmethod #def NULL( cls ): # obj = object.__new__( cls ) @@ -54,7 +51,7 @@ class StringList(CClass): # return obj - def __init__( self , initial = None , c_ptr = None): + def __init__( self, initial=None, c_ptr=None, parent=None): """ Creates a new stringlist instance. @@ -73,21 +70,24 @@ class StringList(CClass): ownership of the underlying object. """ if c_ptr: - self.init_cobj( c_ptr , cfunc.free ) + if parent: + self.init_cref(c_ptr, parent) + else: + self.init_cobj(c_ptr, cfunc.free) else: - c_ptr = cfunc.stringlist_alloc( ) - self.init_cobj( c_ptr , cfunc.free ) + c_ptr = cfunc.stringlist_alloc() + self.init_cobj(c_ptr, cfunc.free) if initial: for s in initial: - if isinstance( s , types.StringType): - self.append( s ) + if isinstance(s, StringType): + self.append(s) else: raise TypeError("Item:%s not a string" % s) - def __setitem__(self, index , value): - if isinstance( index , types.IntType): + def __setitem__(self, index, value): + if isinstance(index, IntType): length = self.__len__() if index < 0: # Will only wrap backwards once @@ -95,53 +95,53 @@ class StringList(CClass): if index < 0 or index >= length: raise IndexError - if isinstance(value , types.StringType): - cfunc.stringlist_iset( self , index , value) + if isinstance(value, StringType): + cfunc.stringlist_iset(self, index, value) else: raise TypeError("Item:%s not string type" % value) - def __getitem__(self , index): + def __getitem__(self, index): """ Implements [] read operator on the stringlist. The __getitem__ method supports negative, i.e. from the right, indexing; but not slices. """ - if isinstance( index , types.IntType): + if isinstance(index, IntType): length = self.__len__() if index < 0: index += length if index < 0 or index >= length: raise IndexError else: - return cfunc.stringlist_iget( self , index ) + return cfunc.stringlist_iget(self, index) else: raise TypeError("Index should be integer type") - def __contains__(self , s): + def __contains__(self, s): """ Implements the 'in' operator. The 'in' check is based on string equality. """ - return cfunc.contains( self , s ) + return cfunc.contains(self, s) - def contains(self , s): + def contains(self, s): """ Checks if the list contains @s. Functionality also available through the 'in' builtin in Python. """ - return self.__contains__( s ) + return self.__contains__(s) def __len__(self): """ The length of the list - used to support builtin len(). """ - return cfunc.stringlist_get_size( self ) + return cfunc.stringlist_get_size(self) def __str__(self): @@ -151,7 +151,7 @@ class StringList(CClass): buffer = "[" length = len(self) for i in range(length): - if i == length -1: + if i == length - 1: buffer += "\'%s\'" % self[i] else: buffer += "\'%s\'," % self[i] @@ -166,17 +166,17 @@ class StringList(CClass): Will raise IndexError if list is empty. """ if len(self): - return cfunc.pop( self ) + return cfunc.pop(self) else: raise IndexError("pop() failed - the list is empty") - + def append(self, s): """ Appends a new string @s to list. """ - if isinstance( s, types.StringType): - cfunc.stringlist_append( self , s) + if isinstance(s, StringType): + cfunc.stringlist_append(self, s) else: sys.exit("Type mismatch") @@ -191,7 +191,7 @@ class StringList(CClass): """ slist = [] for s in self: - slist.append( s ) + slist.append(s) return slist @property @@ -200,12 +200,12 @@ class StringList(CClass): Will return the last element in list. Raise IndexError if empty. """ if len(self): - return cfunc.last( self ) + return cfunc.last(self) else: raise IndexError("The list is empty") - def sort(self , cmp_flag = 0): + def sort(self, cmp_flag=0): """ Will sort the list inplace. @@ -217,22 +217,21 @@ class StringList(CClass): 2 : util_strcmp_float() string comparison """ - cfunc.sort( self , cmp_flag ) + cfunc.sort(self, cmp_flag) +CWrapper.registerType("stringlist", StringList) -CWrapper.registerType( "stringlist" , StringList ) - -cwrapper = CWrapper( libutil.lib ) -cfunc = CWrapperNameSpace("StringList") -cfunc.stringlist_alloc = cwrapper.prototype("c_void_p stringlist_alloc_new( )") -cfunc.free = cwrapper.prototype("void stringlist_free( stringlist )") -cfunc.stringlist_append = cwrapper.prototype("void stringlist_append_copy( stringlist , char* )") -cfunc.stringlist_iget = cwrapper.prototype("char* stringlist_iget( stringlist , int )") -cfunc.stringlist_iget_copy = cwrapper.prototype("char* stringlist_iget_copy(stringlist, int)") -cfunc.stringlist_iset = cwrapper.prototype("void stringlist_iset_copy( stringlist , int , char* )") -cfunc.stringlist_get_size = cwrapper.prototype("int stringlist_get_size( stringlist )") -cfunc.contains = cwrapper.prototype("bool stringlist_contains(stringlist , char*)") -cfunc.sort = cwrapper.prototype("void stringlist_python_sort( stringlist , int)") -cfunc.pop = cwrapper.prototype("char* stringlist_pop( stringlist )") -cfunc.last = cwrapper.prototype("char* stringlist_get_last( stringlist )") +cwrapper = CWrapper(UTIL_LIB) +cfunc = CWrapperNameSpace("StringList") +cfunc.stringlist_alloc = cwrapper.prototype("c_void_p stringlist_alloc_new( )") +cfunc.free = cwrapper.prototype("void stringlist_free( stringlist )") +cfunc.stringlist_append = cwrapper.prototype("void stringlist_append_copy( stringlist , char* )") +cfunc.stringlist_iget = cwrapper.prototype("char* stringlist_iget( stringlist , int )") +cfunc.stringlist_iget_copy = cwrapper.prototype("char* stringlist_iget_copy(stringlist, int)") +cfunc.stringlist_iset = cwrapper.prototype("void stringlist_iset_copy( stringlist , int , char* )") +cfunc.stringlist_get_size = cwrapper.prototype("int stringlist_get_size( stringlist )") +cfunc.contains = cwrapper.prototype("bool stringlist_contains(stringlist , char*)") +cfunc.sort = cwrapper.prototype("void stringlist_python_sort( stringlist , int)") +cfunc.pop = cwrapper.safe_prototype("char* stringlist_pop( stringlist )") +cfunc.last = cwrapper.safe_prototype("char* stringlist_get_last( stringlist )") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/test_area.py b/ThirdParty/Ert/devel/python/python/ert/util/test_area.py new file mode 100644 index 0000000000..b3fb3767c7 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert/util/test_area.py @@ -0,0 +1,77 @@ +# Copyright (C) 2013 Statoil ASA, Norway. +# +# The file 'test_work_area.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +from ert.cwrap import clib, CClass, CWrapper, CWrapperNameSpace + + +lib = clib.ert_load("libtest_util.so") + + +class TestArea(CClass): + def __init__(self, test_name, store_area=False): + c_ptr = cfunc.test_area_alloc(test_name, store_area) + if not c_ptr: + raise Exception("Failed to create TestArea instance") + + self.init_cobj(c_ptr, cfunc.free) + + + def install_file( self, filename): + cfunc.install_file(self, filename) + + + def copy_directory( self, directory): + cfunc.copy_directory(self, directory) + + + def copy_directory_content( self, directory): + cfunc.copy_directory_content(self, directory) + + def copy_file( self, filename): + cfunc.copy_file(self, filename) + + +class TestAreaContext(object): + def __init__(self, test_name, store_area=False): + self.test_name = test_name + self.store_area = store_area + + def __enter__(self): + """ + @rtype: TestArea + """ + self.test_area = TestArea(self.test_name, self.store_area) + return self.test_area + + + def __exit__(self, exc_type, exc_val, exc_tb): + del self.test_area + return False + + + +CWrapper.registerType("test_area", TestArea) + +cwrapper = CWrapper(lib) + +cfunc = CWrapperNameSpace("TestArea") + +cfunc.test_area_alloc = cwrapper.prototype("c_void_p test_work_area_alloc( char* , bool)") +cfunc.free = cwrapper.prototype("void test_work_area_free( test_area )") +cfunc.install_file = cwrapper.prototype("void test_work_area_install_file( test_area , char* )") +cfunc.copy_directory = cwrapper.prototype("void test_work_area_copy_directory( test_area , char* )") +cfunc.copy_file = cwrapper.prototype("void test_work_area_copy_file( test_area , char* )") +cfunc.copy_directory_content = cwrapper.prototype("void test_work_area_copy_directory_content( test_area , char* )") diff --git a/ThirdParty/Ert/devel/python/python/ert/util/tvector.py b/ThirdParty/Ert/devel/python/python/ert/util/tvector.py index 4b30ebe5ab..1e0c6e4951 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/tvector.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/tvector.py @@ -41,19 +41,21 @@ float and size_t not currently implemented in the Python version. """ import sys -import types +from types import IntType, SliceType import ctypes -import libutil -from ert.cwrap.cwrap import * -from ert.cwrap.cfile import CFILE -from ert.cwrap.cclass import CClass import numpy +from ert.cwrap import CWrapper, CClass, CFILE, CWrapperNameSpace +from ert.util import UTIL_LIB, ctime + + + + class TVector(CClass): - + @classmethod - def strided_copy( cls , obj , slice ): + def strided_copy( cls , obj , slice_range ): """ Will create a new copy according to @slice. @@ -69,7 +71,7 @@ class TVector(CClass): Now 'c' will be a Intvector() instance containing every tenth element from 'v'. """ - (start , stop , step) = slice.indices( obj.size ) + (start , stop , step) = slice_range.indices( obj.size ) if stop > start: new_obj = TVector.__new__( cls ) c_ptr = cls.cstrided_copy( obj , start , stop , step ) @@ -85,20 +87,13 @@ class TVector(CClass): c_ptr = cls.alloc_copy( obj ) new_obj.init_cobj( c_ptr , new_obj.free ) return new_obj - - def __new__( cls ): + + def __new__( cls , **kwargs): obj = object.__new__( cls ) return obj - @classmethod - def ref( cls , c_ptr , parent ): - obj = cls( ) - obj.init_cref( c_ptr , parent ) - return obj - - def copy( self ): """ Create a new copy of the current vector. @@ -118,8 +113,8 @@ class TVector(CClass): init_size = 0 c_ptr = self.alloc( init_size , default_value ) self.init_cobj( c_ptr , self.free ) - self.element_size = self.get_element_size( self ) - + self.element_size = self.get_element_size( self ) + def str_data( self , width , index1 , index2 , fmt): """ @@ -184,7 +179,7 @@ class TVector(CClass): """ Implements read [] operator - @index can be slice instance. """ - if isinstance( index , types.IntType): + if isinstance( index , IntType): length = self.__len__() if index < 0: index += length @@ -193,16 +188,16 @@ class TVector(CClass): raise IndexError else: return self.iget( self , index ) - elif isinstance( index , types.SliceType ): + elif isinstance( index , SliceType ): return self.strided_copy( self , index ) else: raise TypeError("Index should be integer or slice type.") - + def __setitem__( self , index , value ): """ Implements write [] operator - @index must be integer. """ - if isinstance( index , types.IntType): + if isinstance( index , IntType): self.iset( self, index , value ) else: raise TypeError("Index should be integer type") @@ -229,10 +224,13 @@ class TVector(CClass): subtraction operations: __isub__, __sub__ and __rsub__. """ if type(self) == type(delta): - # This is vector + vector operation. - if not add: - self.scale( delta , -1 ) - self.inplace_add( self , delta ) + if self.size == delta.size: + # This is vector + vector operation. + if not add: + self.scale( delta , -1 ) + self.inplace_add( self , delta ) + else: + raise ValueError("Incompatible sizes for add self:%d other:%d" % (self.size , delta.size)) else: if isinstance( delta , int ) or isinstance( delta, float): if not add: @@ -260,7 +258,10 @@ class TVector(CClass): if type(self) == type(factor): # This is vector * vector operation. - self.inplace_mul( self , factor ) + if self.size == factor.size: + self.inplace_mul( self , factor ) + else: + raise ValueError("Incompatible sizes for mul self:%d other:%d" % (self.size , factor.size)) else: if isinstance( factor , int ) or isinstance( factor, float): self.scale( self , factor ) @@ -307,11 +308,11 @@ class TVector(CClass): return copy def __rsub__( self , delta): - return self.__sub__( delta ) * -1 + return self.__sub__( delta ) * -1 def __imul__(self , factor ): return self.__IMUL__( factor ) - + def __mul__( self , factor ): copy = self.__copy__( self ) copy *= factor @@ -319,12 +320,16 @@ class TVector(CClass): def __rmul__(self , factor): return self.__mul__( factor ) - - def __div__(self , factor): - copy = self.deep_copy() - copy /= factor - return copy - + + + def __div__(self , divisor): + if isinstance( divisor , int ) or isinstance( divisor , float): + copy = self.__copy__( self ) + copy.div( copy , divisor ) + return copy + else: + raise TypeError("Divisor has wrong type:%s" % type( divisor )) + # No __rdiv__() @@ -361,10 +366,10 @@ class TVector(CClass): def __len__(self): """ - The number of elements in the vector." + The number of elements in the vector. """ return self.get_size( self ) - + def printf( self , fmt = None , name = None , stream = sys.stdout ): """ @@ -396,7 +401,8 @@ class TVector(CClass): return self.get_min( self ) else: raise IndexError - + + def min_index( self , reverse = False ): if self.get_size( self ) > 0: return self.get_min_index( self , reverse ) @@ -443,7 +449,7 @@ class TVector(CClass): def get_read_only( self ): return self.get_read_only( self ) - + read_only = property( get_read_only , set_read_only ) def set_default( self , value ): @@ -488,23 +494,29 @@ class TVector(CClass): ################################################################# +# The ctypes type system with CWrapper.registerType() needs access to +# the wrapper object class definitions, and the warpper objects need +# access to the cfunc.xxxx function objects; that is the reason we +# invoke the ugly cls.initialized flag. class DoubleVector(TVector): initialized = False - def __new__( cls , *arglist ): + + + def __new__( cls , **kwargs ): if not cls.initialized: cls.csort = cfunc.double_vector_sort cls.crsort = cfunc.double_vector_rsort cls.alloc = cfunc.double_vector_alloc cls.alloc_copy = cfunc.double_vector_alloc_copy - cls.free = cfunc.double_vector_free + # cls.free = cfunc.double_vector_free cls.get_size = cfunc.double_vector_size cls.iget = cfunc.double_vector_iget cls.iset = cfunc.double_vector_iset cls.fprintf = cfunc.double_vector_fprintf cls.cappend = cfunc.double_vector_append - cls.idel_block = cfunc.double_vector_idel_block + cls.idel_block = cfunc.double_vector_idel_block cls.cclear = cfunc.double_vector_reset cls.cstrided_copy = cfunc.double_vector_strided_copy cls.csafe_iget = cfunc.double_vector_safe_iget @@ -516,6 +528,7 @@ class DoubleVector(TVector): cls.get_min_index = cfunc.double_vector_get_min_index cls.shift = cfunc.double_vector_shift cls.scale = cfunc.double_vector_scale + cls.div = cfunc.double_vector_div cls.inplace_add = cfunc.double_vector_inplace_add cls.inplace_mul = cfunc.double_vector_inplace_mul cls.cassign = cfunc.double_vector_assign @@ -529,27 +542,27 @@ class DoubleVector(TVector): cls.def_fmt = "%8.4f" cls.initialized = True - obj = TVector.__new__( cls ) + obj = TVector.__new__( cls , **kwargs ) return obj - + class BoolVector(TVector): initialized = False - def __new__( cls , *arglist ): + def __new__( cls , **kwargs ): if not cls.initialized: cls.csort = cfunc.bool_vector_sort cls.crsort = cfunc.bool_vector_rsort cls.alloc = cfunc.bool_vector_alloc cls.alloc_copy = cfunc.bool_vector_alloc_copy - cls.free = cfunc.bool_vector_free + # cls.free = cfunc.bool_vector_free cls.get_size = cfunc.bool_vector_size cls.iget = cfunc.bool_vector_iget cls.iset = cfunc.bool_vector_iset cls.fprintf = cfunc.bool_vector_fprintf cls.cappend = cfunc.bool_vector_append - cls.idel_block = cfunc.bool_vector_idel_block + cls.idel_block = cfunc.bool_vector_idel_block cls.cclear = cfunc.bool_vector_reset cls.cstrided_copy = cfunc.bool_vector_strided_copy cls.csafe_iget = cfunc.bool_vector_safe_iget @@ -561,6 +574,7 @@ class BoolVector(TVector): cls.get_min_index = cfunc.bool_vector_get_min_index cls.shift = cfunc.bool_vector_shift cls.scale = cfunc.bool_vector_scale + cls.div = cfunc.bool_vector_div cls.inplace_add = cfunc.bool_vector_inplace_add cls.inplace_mul = cfunc.bool_vector_inplace_mul cls.cassign = cfunc.bool_vector_assign @@ -574,7 +588,7 @@ class BoolVector(TVector): cls.def_fmt = "%8d" cls.initialized = True - obj = TVector.__new__( cls ) + obj = TVector.__new__( cls , **kwargs) return obj @@ -598,28 +612,39 @@ class BoolVector(TVector): new_obj.init_cobj( c_ptr , new_obj.free ) return new_obj + @classmethod + def create_from_list(cls, size, source_list): + """Allocates a bool vector from a Python list""" + new_obj = BoolVector.__new__(cls) + c_ptr = cfunc.bool_vector_alloc(size , False) + for index in source_list: + cfunc.bool_vector_iset(c_ptr, index, True) + + #c_ptr = cfunc.bool_vector_data_ptr(mask) + new_obj.init_cobj( c_ptr , new_obj.free ) + return new_obj + - class IntVector(TVector): initialized = False - - def __new__( cls , *arglist ): + + def __new__( cls , **kwargs ): if not cls.initialized: cls.csort = cfunc.int_vector_sort - cls.crsort = cfunc.int_vector_rsort + cls.crsort = cfunc.int_vector_rsort cls.alloc = cfunc.int_vector_alloc cls.alloc_copy = cfunc.int_vector_alloc_copy - cls.free = cfunc.int_vector_free + # cls.free = cfunc.int_vector_free cls.get_size = cfunc.int_vector_size cls.iget = cfunc.int_vector_iget cls.iset = cfunc.int_vector_iset cls.fprintf = cfunc.int_vector_fprintf cls.cappend = cfunc.int_vector_append - cls.idel_block = cfunc.int_vector_idel_block + cls.idel_block = cfunc.int_vector_idel_block cls.cclear = cfunc.int_vector_reset cls.cstrided_copy = cfunc.int_vector_strided_copy cls.csafe_iget = cfunc.int_vector_safe_iget @@ -631,6 +656,7 @@ class IntVector(TVector): cls.get_min_index = cfunc.int_vector_get_min_index cls.shift = cfunc.int_vector_shift cls.scale = cfunc.int_vector_scale + cls.div = cfunc.int_vector_div cls.inplace_add = cfunc.int_vector_inplace_add cls.inplace_mul = cfunc.int_vector_inplace_mul cls.cassign = cfunc.int_vector_assign @@ -644,9 +670,9 @@ class IntVector(TVector): cls.def_fmt = "%d" cls.initialized = True - obj = TVector.__new__( cls ) + obj = TVector.__new__( cls , **kwargs) return obj - + @classmethod def active_list(cls , range_string): """ @@ -668,6 +694,50 @@ class IntVector(TVector): return new_obj +class TimeVector(TVector): + initialized = False + + def __new__( cls , **kwargs ): + if not cls.initialized: + cls.csort = cfunc.time_t_vector_sort + cls.crsort = cfunc.time_t_vector_rsort + cls.alloc = cfunc.time_t_vector_alloc + cls.alloc_copy = cfunc.time_t_vector_alloc_copy + # cls.free = cfunc.time_t_vector_free + cls.get_size = cfunc.time_t_vector_size + cls.iget = cfunc.time_t_vector_iget + cls.iset = cfunc.time_t_vector_iset + cls.fprintf = cfunc.time_t_vector_fprintf + cls.cappend = cfunc.time_t_vector_append + cls.idel_block = cfunc.time_t_vector_idel_block + cls.cclear = cfunc.time_t_vector_reset + cls.cstrided_copy = cfunc.time_t_vector_strided_copy + cls.csafe_iget = cfunc.time_t_vector_safe_iget + cls.set_read_only = cfunc.time_t_vector_set_read_only + cls.get_read_only = cfunc.time_t_vector_get_read_only + cls.get_max = cfunc.time_t_vector_get_max + cls.get_min = cfunc.time_t_vector_get_min + cls.get_max_index = cfunc.time_t_vector_get_max_index + cls.get_min_index = cfunc.time_t_vector_get_min_index + cls.shift = cfunc.time_t_vector_shift + cls.scale = cfunc.time_t_vector_scale + cls.div = cfunc.time_t_vector_div + cls.inplace_add = cfunc.time_t_vector_inplace_add + cls.inplace_mul = cfunc.time_t_vector_inplace_mul + cls.cassign = cfunc.time_t_vector_assign + cls.memcpy = cfunc.time_t_vector_memcpy + cls.cset_default = cfunc.time_t_vector_set_default + cls.cget_default = cfunc.time_t_vector_get_default + cls.alloc_data_copy = cfunc.time_t_vector_alloc_data_copy + cls.get_element_size = cfunc.time_t_vector_element_size + cls.data_ptr = cfunc.time_t_vector_data_ptr + cls.numpy_dtype = numpy.float64 + cls.def_fmt = "%8.4f" + cls.initialized = True + + obj = TVector.__new__( cls , **kwargs ) + return obj + ################################################################# @@ -677,38 +747,46 @@ buffer_from_ptr.argtypes = [ ctypes.c_void_p , ctypes.c_long ] CWrapper.registerType( "double_vector" , DoubleVector ) CWrapper.registerType( "int_vector" , IntVector ) -CWrapper.registerType( "bool_vector" , BoolVector ) +CWrapper.registerType( "bool_vector" , BoolVector ) +CWrapper.registerType( "time_t_vector" , TimeVector ) -cwrapper = CWrapper( libutil.lib ) +cwrapper = CWrapper(UTIL_LIB) cfunc = CWrapperNameSpace("tvector") + +BoolVector.free = cwrapper.prototype("void bool_vector_free( bool_vector )") +DoubleVector.free = cwrapper.prototype("void double_vector_free( double_vector )") +IntVector.free = cwrapper.prototype("void int_vector_free( int_vector )") +TimeVector.free = cwrapper.prototype("void time_t_vector_free( time_t_vector )") + cfunc.double_vector_alloc = cwrapper.prototype("c_void_p double_vector_alloc( int , double )") cfunc.double_vector_alloc_copy = cwrapper.prototype("c_void_p double_vector_alloc_copy( double_vector )") cfunc.double_vector_strided_copy = cwrapper.prototype("c_void_p double_vector_alloc_strided_copy( double_vector , int , int , int)") -cfunc.double_vector_free = cwrapper.prototype("void double_vector_free( double_vector )") +# cfunc.double_vector_free = cwrapper.prototype("void double_vector_free( double_vector )") cfunc.double_vector_iget = cwrapper.prototype("double double_vector_iget( double_vector , int )") cfunc.double_vector_safe_iget = cwrapper.prototype("double double_vector_safe_iget( int_vector , int )") cfunc.double_vector_iset = cwrapper.prototype("double double_vector_iset( double_vector , int , double)") cfunc.double_vector_size = cwrapper.prototype("int double_vector_size( double_vector )") -cfunc.double_vector_append = cwrapper.prototype("void double_vector_append( double_vector , double )") -cfunc.double_vector_idel_block = cwrapper.prototype("void double_vector_idel_block( double_vector , int , int )") +cfunc.double_vector_append = cwrapper.prototype("void double_vector_append( double_vector , double )") +cfunc.double_vector_idel_block = cwrapper.prototype("void double_vector_idel_block( double_vector , int , int )") cfunc.double_vector_fprintf = cwrapper.prototype("void double_vector_fprintf( double_vector , FILE , char* , char*)") -cfunc.double_vector_sort = cwrapper.prototype("void double_vector_sort( double_vector )") -cfunc.double_vector_rsort = cwrapper.prototype("void double_vector_rsort( double_vector )") -cfunc.double_vector_reset = cwrapper.prototype("void double_vector_reset( double_vector )") -cfunc.double_vector_get_read_only = cwrapper.prototype("bool double_vector_set_read_only( double_vector )") -cfunc.double_vector_set_read_only = cwrapper.prototype("void double_vector_set_read_only( double_vector , bool )") +cfunc.double_vector_sort = cwrapper.prototype("void double_vector_sort( double_vector )") +cfunc.double_vector_rsort = cwrapper.prototype("void double_vector_rsort( double_vector )") +cfunc.double_vector_reset = cwrapper.prototype("void double_vector_reset( double_vector )") +cfunc.double_vector_get_read_only = cwrapper.prototype("bool double_vector_get_read_only( double_vector )") +cfunc.double_vector_set_read_only = cwrapper.prototype("void double_vector_set_read_only( double_vector , bool )") cfunc.double_vector_get_max = cwrapper.prototype("double double_vector_get_max( double_vector )") cfunc.double_vector_get_min = cwrapper.prototype("double double_vector_get_min( double_vector )") cfunc.double_vector_get_max_index = cwrapper.prototype("int double_vector_get_max_index( double_vector , bool)") cfunc.double_vector_get_min_index = cwrapper.prototype("int double_vector_get_min_index( double_vector , bool)") cfunc.double_vector_shift = cwrapper.prototype("void double_vector_shift( double_vector , double )") -cfunc.double_vector_scale = cwrapper.prototype("void double_vector_scale( double_vector , double )") +cfunc.double_vector_scale = cwrapper.prototype("void double_vector_scale( double_vector , double )") +cfunc.double_vector_div = cwrapper.prototype("void double_vector_div( double_vector , double )") cfunc.double_vector_inplace_add = cwrapper.prototype("void double_vector_inplace_add( double_vector , double_vector )") cfunc.double_vector_inplace_mul = cwrapper.prototype("void double_vector_inplace_mul( double_vector , double_vector )") -cfunc.double_vector_assign = cwrapper.prototype("void double_vector_set_all( double_vector , double)") +cfunc.double_vector_assign = cwrapper.prototype("void double_vector_set_all( double_vector , double)") cfunc.double_vector_memcpy = cwrapper.prototype("void double_vector_memcpy(double_vector , double_vector )") cfunc.double_vector_set_default = cwrapper.prototype("void double_vector_set_default( double_vector , double)") cfunc.double_vector_get_default = cwrapper.prototype("double double_vector_get_default( double_vector )") @@ -720,28 +798,29 @@ cfunc.double_vector_element_size = cwrapper.prototype("int double_ve cfunc.int_vector_alloc_copy = cwrapper.prototype("c_void_p int_vector_alloc_copy( int_vector )") cfunc.int_vector_alloc = cwrapper.prototype("c_void_p int_vector_alloc( int , int )") cfunc.int_vector_strided_copy = cwrapper.prototype("c_void_p int_vector_alloc_strided_copy( int_vector , int , int , int)") -cfunc.int_vector_free = cwrapper.prototype("void int_vector_free( int_vector )") +# cfunc.int_vector_free = cwrapper.prototype("void int_vector_free( int_vector )") cfunc.int_vector_iget = cwrapper.prototype("int int_vector_iget( int_vector , int )") cfunc.int_vector_safe_iget = cwrapper.prototype("int int_vector_safe_iget( int_vector , int )") cfunc.int_vector_iset = cwrapper.prototype("int int_vector_iset( int_vector , int , int)") cfunc.int_vector_size = cwrapper.prototype("int int_vector_size( int_vector )") -cfunc.int_vector_append = cwrapper.prototype("void int_vector_append( int_vector , int )") -cfunc.int_vector_idel_block = cwrapper.prototype("void int_vector_idel_block( int_vector , int , int )") +cfunc.int_vector_append = cwrapper.prototype("void int_vector_append( int_vector , int )") +cfunc.int_vector_idel_block = cwrapper.prototype("void int_vector_idel_block( int_vector , int , int )") cfunc.int_vector_fprintf = cwrapper.prototype("void int_vector_fprintf( int_vector , FILE , char* , char*)") -cfunc.int_vector_sort = cwrapper.prototype("void int_vector_sort( int_vector )") -cfunc.int_vector_rsort = cwrapper.prototype("void int_vector_rsort( int_vector )") -cfunc.int_vector_reset = cwrapper.prototype("void int_vector_reset( int_vector )") -cfunc.int_vector_set_read_only = cwrapper.prototype("void int_vector_set_read_only( int_vector , bool )") -cfunc.int_vector_get_read_only = cwrapper.prototype("bool int_vector_get_read_only( int_vector )") +cfunc.int_vector_sort = cwrapper.prototype("void int_vector_sort( int_vector )") +cfunc.int_vector_rsort = cwrapper.prototype("void int_vector_rsort( int_vector )") +cfunc.int_vector_reset = cwrapper.prototype("void int_vector_reset( int_vector )") +cfunc.int_vector_set_read_only = cwrapper.prototype("void int_vector_set_read_only( int_vector , bool )") +cfunc.int_vector_get_read_only = cwrapper.prototype("bool int_vector_get_read_only( int_vector )") cfunc.int_vector_get_max = cwrapper.prototype("int int_vector_get_max( int_vector )") cfunc.int_vector_get_min = cwrapper.prototype("int int_vector_get_min( int_vector )") cfunc.int_vector_get_max_index = cwrapper.prototype("int int_vector_get_max_index( int_vector , bool)") cfunc.int_vector_get_min_index = cwrapper.prototype("int int_vector_get_min_index( int_vector , bool)") cfunc.int_vector_shift = cwrapper.prototype("void int_vector_shift( int_vector , int )") -cfunc.int_vector_scale = cwrapper.prototype("void int_vector_scale( int_vector , int )") +cfunc.int_vector_scale = cwrapper.prototype("void int_vector_scale( int_vector , int )") +cfunc.int_vector_div = cwrapper.prototype("void int_vector_div( int_vector , int )") cfunc.int_vector_inplace_add = cwrapper.prototype("void int_vector_inplace_add( int_vector , int_vector )") cfunc.int_vector_inplace_mul = cwrapper.prototype("void int_vector_inplace_mul( int_vector , int_vector )") -cfunc.int_vector_assign = cwrapper.prototype("void int_vector_set_all( int_vector , int)") +cfunc.int_vector_assign = cwrapper.prototype("void int_vector_set_all( int_vector , int)") cfunc.int_vector_memcpy = cwrapper.prototype("void int_vector_memcpy(int_vector , int_vector )") cfunc.int_vector_set_default = cwrapper.prototype("void int_vector_set_default( int_vector , int)") cfunc.int_vector_get_default = cwrapper.prototype("int int_vector_get_default( int_vector )") @@ -751,30 +830,31 @@ cfunc.int_vector_element_size = cwrapper.prototype("int int_vector_ele cfunc.bool_vector_alloc_copy = cwrapper.prototype("c_void_p bool_vector_alloc_copy( bool_vector )") -cfunc.bool_vector_alloc = cwrapper.prototype("c_void_p bool_vector_alloc( bool , bool )") +cfunc.bool_vector_alloc = cwrapper.prototype("c_void_p bool_vector_alloc( int , bool )") cfunc.bool_vector_strided_copy = cwrapper.prototype("c_void_p bool_vector_alloc_strided_copy( bool_vector , bool , bool , bool)") -cfunc.bool_vector_free = cwrapper.prototype("void bool_vector_free( bool_vector )") +# cfunc.bool_vector_free = cwrapper.prototype("void bool_vector_free( bool_vector )") cfunc.bool_vector_iget = cwrapper.prototype("bool bool_vector_iget( bool_vector , bool )") cfunc.bool_vector_safe_iget = cwrapper.prototype("bool bool_vector_safe_iget( bool_vector , bool )") cfunc.bool_vector_iset = cwrapper.prototype("bool bool_vector_iset( bool_vector , bool , bool)") cfunc.bool_vector_size = cwrapper.prototype("bool bool_vector_size( bool_vector )") -cfunc.bool_vector_append = cwrapper.prototype("void bool_vector_append( bool_vector , bool )") -cfunc.bool_vector_idel_block = cwrapper.prototype("void bool_vector_idel_block( bool_vector , bool , bool )") +cfunc.bool_vector_append = cwrapper.prototype("void bool_vector_append( bool_vector , bool )") +cfunc.bool_vector_idel_block = cwrapper.prototype("void bool_vector_idel_block( bool_vector , bool , bool )") cfunc.bool_vector_fprintf = cwrapper.prototype("void bool_vector_fprintf( bool_vector , FILE , char* , char*)") -cfunc.bool_vector_sort = cwrapper.prototype("void bool_vector_sort( bool_vector )") -cfunc.bool_vector_rsort = cwrapper.prototype("void bool_vector_rsort( bool_vector )") -cfunc.bool_vector_reset = cwrapper.prototype("void bool_vector_reset( bool_vector )") -cfunc.bool_vector_set_read_only = cwrapper.prototype("void bool_vector_set_read_only( bool_vector , bool )") -cfunc.bool_vector_get_read_only = cwrapper.prototype("bool bool_vector_get_read_only( bool_vector )") +cfunc.bool_vector_sort = cwrapper.prototype("void bool_vector_sort( bool_vector )") +cfunc.bool_vector_rsort = cwrapper.prototype("void bool_vector_rsort( bool_vector )") +cfunc.bool_vector_reset = cwrapper.prototype("void bool_vector_reset( bool_vector )") +cfunc.bool_vector_set_read_only = cwrapper.prototype("void bool_vector_set_read_only( bool_vector , bool )") +cfunc.bool_vector_get_read_only = cwrapper.prototype("bool bool_vector_get_read_only( bool_vector )") cfunc.bool_vector_get_max = cwrapper.prototype("bool bool_vector_get_max( bool_vector )") cfunc.bool_vector_get_min = cwrapper.prototype("bool bool_vector_get_min( bool_vector )") cfunc.bool_vector_get_max_index = cwrapper.prototype("bool bool_vector_get_max_index( bool_vector , bool)") cfunc.bool_vector_get_min_index = cwrapper.prototype("bool bool_vector_get_min_index( bool_vector , bool)") cfunc.bool_vector_shift = cwrapper.prototype("void bool_vector_shift( bool_vector , bool )") -cfunc.bool_vector_scale = cwrapper.prototype("void bool_vector_scale( bool_vector , bool )") +cfunc.bool_vector_scale = cwrapper.prototype("void bool_vector_scale( bool_vector , bool )") +cfunc.bool_vector_div = cwrapper.prototype("void bool_vector_div( bool_vector , bool )") cfunc.bool_vector_inplace_add = cwrapper.prototype("void bool_vector_inplace_add( bool_vector , bool_vector )") cfunc.bool_vector_inplace_mul = cwrapper.prototype("void bool_vector_inplace_mul( bool_vector , bool_vector )") -cfunc.bool_vector_assign = cwrapper.prototype("void bool_vector_set_all( bool_vector , bool)") +cfunc.bool_vector_assign = cwrapper.prototype("void bool_vector_set_all( bool_vector , bool)") cfunc.bool_vector_memcpy = cwrapper.prototype("void bool_vector_memcpy(bool_vector , bool_vector )") cfunc.bool_vector_set_default = cwrapper.prototype("void bool_vector_set_default( bool_vector , bool)") cfunc.bool_vector_get_default = cwrapper.prototype("bool bool_vector_get_default( bool_vector )") @@ -782,7 +862,42 @@ cfunc.bool_vector_alloc_data_copy = cwrapper.prototype("bool* bool_vector_a cfunc.bool_vector_data_ptr = cwrapper.prototype("bool* bool_vector_get_ptr( bool_vector )") cfunc.bool_vector_element_size = cwrapper.prototype("int bool_vector_element_size( bool_vector )") + +cfunc.time_t_vector_alloc = cwrapper.prototype("c_void_p time_t_vector_alloc(int, time_t )") +cfunc.time_t_vector_alloc_copy = cwrapper.prototype("c_void_p time_t_vector_alloc_copy(time_t_vector )") +cfunc.time_t_vector_strided_copy = cwrapper.prototype("c_void_p time_t_vector_alloc_strided_copy(time_t_vector , time_t , time_t , time_t)") +# cfunc.time_t_vector_free = cwrapper.prototype("void time_t_vector_free( time_t_vector )") +cfunc.time_t_vector_iget = cwrapper.prototype("time_t time_t_vector_iget( time_t_vector , int )") +cfunc.time_t_vector_safe_iget = cwrapper.prototype("time_t time_t_vector_safe_iget( time_t_vector , int )") +cfunc.time_t_vector_iset = cwrapper.prototype("time_t time_t_vector_iset( time_t_vector , int , time_t)") +cfunc.time_t_vector_size = cwrapper.prototype("int time_t_vector_size( time_t_vector )") +cfunc.time_t_vector_append = cwrapper.prototype("void time_t_vector_append( time_t_vector , time_t )") +cfunc.time_t_vector_idel_block = cwrapper.prototype("void time_t_vector_idel_block( time_t_vector , int , int )") +cfunc.time_t_vector_fprintf = cwrapper.prototype("void time_t_vector_fprintf( time_t_vector , FILE , char* , char*)") +cfunc.time_t_vector_sort = cwrapper.prototype("void time_t_vector_sort( time_t_vector )") +cfunc.time_t_vector_rsort = cwrapper.prototype("void time_t_vector_rsort( time_t_vector )") +cfunc.time_t_vector_reset = cwrapper.prototype("void time_t_vector_reset( time_t_vector )") +cfunc.time_t_vector_set_read_only = cwrapper.prototype("void time_t_vector_set_read_only( time_t_vector , bool )") +cfunc.time_t_vector_get_read_only = cwrapper.prototype("bool time_t_vector_get_read_only( time_t_vector )") +cfunc.time_t_vector_get_max = cwrapper.prototype("time_t time_t_vector_get_max( time_t_vector )") +cfunc.time_t_vector_get_min = cwrapper.prototype("time_t time_t_vector_get_min( time_t_vector )") +cfunc.time_t_vector_get_max_index = cwrapper.prototype("int time_t_vector_get_max_index( time_t_vector , bool)") +cfunc.time_t_vector_get_min_index = cwrapper.prototype("int time_t_vector_get_min_index( time_t_vector , bool)") +cfunc.time_t_vector_shift = cwrapper.prototype("void time_t_vector_shift( time_t_vector , time_t )") +cfunc.time_t_vector_scale = cwrapper.prototype("void time_t_vector_scale( time_t_vector , time_t )") +cfunc.time_t_vector_div = cwrapper.prototype("void time_t_vector_div( time_t_vector , time_t )") +cfunc.time_t_vector_inplace_add = cwrapper.prototype("void time_t_vector_inplace_add( time_t_vector , time_t_vector )") +cfunc.time_t_vector_inplace_mul = cwrapper.prototype("void time_t_vector_inplace_mul( time_t_vector , time_t_vector )") +cfunc.time_t_vector_assign = cwrapper.prototype("void time_t_vector_set_all( time_t_vector , time_t)") +cfunc.time_t_vector_memcpy = cwrapper.prototype("void time_t_vector_memcpy(time_t_vector , time_t_vector )") +cfunc.time_t_vector_set_default = cwrapper.prototype("void time_t_vector_set_default( time_t_vector , time_t)") +cfunc.time_t_vector_get_default = cwrapper.prototype("time_t time_t_vector_get_default( time_t_vector )") +cfunc.time_t_vector_alloc_data_copy = cwrapper.prototype("time_t* time_t_vector_alloc_data_copy( time_t_vector )") +cfunc.time_t_vector_data_ptr = cwrapper.prototype("time_t* time_t_vector_get_ptr( time_t_vector )") +cfunc.time_t_vector_element_size = cwrapper.prototype("int time_t_vector_element_size( time_t_vector )") + #----------------------------------------------------------------- cfunc.create_active_list = cwrapper.prototype("c_void_p string_util_alloc_active_list( char* )") cfunc.create_active_mask = cwrapper.prototype("c_void_p string_util_alloc_active_mask( char* )") + diff --git a/ThirdParty/Ert/devel/python/python/ert/util/util_func.py b/ThirdParty/Ert/devel/python/python/ert/util/util_func.py index d6a5ca4dae..4a4f3622ba 100644 --- a/ThirdParty/Ert/devel/python/python/ert/util/util_func.py +++ b/ThirdParty/Ert/devel/python/python/ert/util/util_func.py @@ -17,12 +17,11 @@ Module with utility functions from util.c """ -import ctypes -import libutil -from ert.cwrap.cwrap import * +from ert.util import UTIL_LIB +from ert.cwrap import CWrapper, CWrapperNameSpace -def strcmp_int( s1 , s2): +def strcmp_int( s1, s2): """ Function to compare strings with embedded integers. @@ -45,20 +44,20 @@ def strcmp_int( s1 , s2): character, wheras the strcmp_float() function will interpret '.' as a descimal point. """ - return cfunc.strcmp_int( s1 , s2 ) + return cfunc.strcmp_int(s1, s2) -def strcmp_float( s1 , s2): +def strcmp_float( s1, s2): """ Function to compare strings with embedded numbers. See documentation of strcmp_int() for further details. """ - return cfunc.strcmp_float( s1 , s2 ) + return cfunc.strcmp_float(s1, s2) -cwrapper = CWrapper( libutil.lib ) -cfunc = CWrapperNameSpace("util_func") +cwrapper = CWrapper(UTIL_LIB) +cfunc = CWrapperNameSpace("util_func") -cfunc.strcmp_int = cwrapper.prototype("int util_strcmp_int( char* , char* )") +cfunc.strcmp_int = cwrapper.prototype("int util_strcmp_int( char* , char* )") cfunc.strcmp_float = cwrapper.prototype("int util_strcmp_float( char* , char* )") diff --git a/ThirdParty/Ert/devel/python/python/ert/well/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert/well/CMakeLists.txt index 0ca38624ff..6d71748709 100644 --- a/ThirdParty/Ert/devel/python/python/ert/well/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/python/ert/well/CMakeLists.txt @@ -1 +1,10 @@ -add_python_package("Python ert.well" ${PYTHON_INSTALL_PREFIX}/ert/well "__init__.py;libwell.py;well_info.py;well.py;well_state.py;well_ts.py" True) +set(PYTHON_SOURCES + __init__.py + libwell.py + well_info.py + well.py + well_state.py + well_ts.py +) + +add_python_package("Python ert.well" ${PYTHON_INSTALL_PREFIX}/ert/well "${PYTHON_SOURCES}" True) diff --git a/ThirdParty/Ert/devel/python/python/ert/well/libwell.py b/ThirdParty/Ert/devel/python/python/ert/well/libwell.py index 223cb5090a..d0f94e7195 100644 --- a/ThirdParty/Ert/devel/python/python/ert/well/libwell.py +++ b/ThirdParty/Ert/devel/python/python/ert/well/libwell.py @@ -1,3 +1,3 @@ -import ert.ecl.libecl +import ert.ecl import ert.cwrap.clib as clib lib = clib.ert_load("libecl_well.so") diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert_gui/CMakeLists.txt new file mode 100644 index 0000000000..9df22897b1 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert_gui/CMakeLists.txt @@ -0,0 +1,3 @@ +add_python_package( "Python ert_gui" ${PYTHON_INSTALL_PREFIX}/ert_gui "__init__.py;gert_main.py;newconfig.py" True) +add_subdirectory( pages ) +add_subdirectory( widgets ) diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/README.txt b/ThirdParty/Ert/devel/python/python/ert_gui/README.txt new file mode 100644 index 0000000000..203cbbf45b --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert_gui/README.txt @@ -0,0 +1,43 @@ +How to develop/run the GUI: + +You can run the gui in two ways: + +1a There are CMakeLists.txt files all the ways through the gui filesystem, + and if you build the ert distribution you will get file hierarchy + xxxx/build/python/ert_gui beside the xxxx/build/python/ert hierarchy. + + This is the way the gui should be organized when installed, to invoke the + gui this way: + + gert -v xxxx/build + + Observe that the 'xxxx' part must be an ABSOLUTE path, otherwise the + frontend script will search in the default installation directory. + + +1b Alternatively you can use the gert command to invoke the gui in the source + directory: + + gert -v xxxx/devel/python + + Observe only one 'python' above. + + + +2. You can invoke gui as a python module directly from the source, without + going through the gert frontend script. This requires that set several + environment variables: + + ERT_SITE_CONFIG -> /project/res/etc/ERT/site-config + ERT_SHARE_PATH -> xxxx/devel/libenkf/applications/ert_gui/share + LD_LIBRARY_PATH -> xxxx/build/lib64 + + And in addition you must source the local_csh file in + xxxx/devel/python/test to set the PYTHONPATH correctly. + + +About the ERT_SHARE_PATH variable: the correct value for the ERT_SHARE_PATH +variable is currently xxxx/devel/libenkf/applications/ert_gui/share, so if +you are using alternative 2 you get this one correctly, whereas if you use +alternative 1 it will be set to a generally incorrect value by the gert +frontend script. diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/__init__.py b/ThirdParty/Ert/devel/python/python/ert_gui/__init__.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/__init__.py rename to ThirdParty/Ert/devel/python/python/ert_gui/__init__.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/gert_main.py b/ThirdParty/Ert/devel/python/python/ert_gui/gert_main.py similarity index 59% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/gert_main.py rename to ThirdParty/Ert/devel/python/python/ert_gui/gert_main.py index 828d8f4483..0f19da4192 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/gert_main.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/gert_main.py @@ -96,7 +96,7 @@ # # in principle be shared among gert versions built for different operating # # system versions: # -# export GERT_SHARE_PATH=/opt/ert/share +# export ERT_SHARE_PATH=/opt/ert/share # # # The ERT site configuration file is assumed to be in # # /opt/ert/etc/site-config, i.e. we set the variable ERT_SITE_CONFIG as: @@ -106,7 +106,7 @@ # # Now the environment should be fully initialized, and we are ready to invoke # # the gert_main.py script, i.e. this file: # -# exec python /opt/ert/python/ert_gui/gert_main.py +# exec python /opt/ert/python/ert_gui/gert_main.py $@ # #-------------------- -------------------- @@ -114,94 +114,102 @@ from PyQt4 import QtGui, QtCore import sys import os + from ert.ert.ertwrapper import ErtWrapper import ert_gui.widgets.util import ert_gui.widgets.help -ert_gui.widgets.help.help_prefix = os.getenv("GERT_SHARE_PATH")+ "/help/" -ert_gui.widgets.util.img_prefix = os.getenv("GERT_SHARE_PATH")+ "/img/" - +ert_gui.widgets.help.help_prefix = os.getenv("ERT_SHARE_PATH")+ "/gui/help/" +ert_gui.widgets.util.img_prefix = os.getenv("ERT_SHARE_PATH")+ "/gui/img/" +from ert.enkf.enkf_main import EnKFMain from ert_gui.newconfig import NewConfigurationDialog - -app = QtGui.QApplication(sys.argv) #Early so that QT is initialized before other imports - from ert_gui.pages.application import Application from ert_gui.pages.init.initpanel import InitPanel from ert_gui.pages.run.runpanel import RunPanel -from ert_gui.pages.config.configpages import ConfigPages -from ert_gui.pages.plot.plotpanel import PlotPanel from ert_gui.widgets.helpedwidget import ContentModel from ert_gui.widgets.util import resourceImage, resourceIcon + + import matplotlib -print "PyQt4 version: ", QtCore.qVersion() -print "matplotlib version: ", matplotlib.__version__ -splash = QtGui.QSplashScreen(resourceImage("splash") , QtCore.Qt.WindowStaysOnTopHint) -splash.show() -splash.showMessage("Starting up...", color=QtCore.Qt.white) -app.processEvents() +def main(): + app = QtGui.QApplication(sys.argv) #Early so that QT is initialized before other imports + from ert_gui.pages.config.configpages import ConfigPages + from ert_gui.pages.plot.plotpanel import PlotPanel -window = Application() + splash = QtGui.QSplashScreen(resourceImage("newsplash") , QtCore.Qt.WindowStaysOnTopHint) + splash.show() + splash.showMessage("Starting up...", QtCore.Qt.AlignLeft, QtCore.Qt.white) + app.processEvents() -splash.showMessage("Bootstrapping...", color=QtCore.Qt.white) -app.processEvents() + window = Application() -ert = ErtWrapper( ) -strict = True -site_config = os.getenv("ERT_SITE_CONFIG") -if len(sys.argv) == 1: - print "-----------------------------------------------------------------" - print "-- You must supply the name of configuration file as the first --" - print "-- commandline argument: --" - print "-- --" - print "-- bash% gert --" - print "-- --" - print "-- If the configuration file does not exist, gert will create --" - print "-- create a new configuration file. --" - print "-----------------------------------------------------------------" - sys.exit( ) + splash.showMessage("Bootstrapping...", QtCore.Qt.AlignLeft, QtCore.Qt.white) + app.processEvents() -enkf_config = sys.argv[1] -if not os.path.exists(enkf_config): - print "Trying to start new config" - new_configuration_dialog = NewConfigurationDialog(enkf_config) - success = new_configuration_dialog.exec_() - if not success: - print "Can not run without a configuration file." - sys.exit(1) + ert = ErtWrapper( ) + strict = True + site_config = os.getenv("ERT_SITE_CONFIG") + if len(sys.argv) == 1: + print "-----------------------------------------------------------------" + print "-- You must supply the name of configuration file as the first --" + print "-- commandline argument: --" + print "-- --" + print "-- bash% gert --" + print "-- --" + print "-- If the configuration file does not exist, gert will create --" + print "-- create a new configuration file. --" + print "-----------------------------------------------------------------" + #sys.exit(0) else: - enkf_config = new_configuration_dialog.getConfigurationPath() - firste_case_name = new_configuration_dialog.getCaseName() - dbase_type = new_configuration_dialog.getDBaseType() - num_realizations = new_configuration_dialog.getNumberOfRealizations() - storage_path = new_configuration_dialog.getStoragePath() - ert.enkf.enkf_main_create_new_config(enkf_config, storage_path , firste_case_name, dbase_type, num_realizations) - strict = False + enkf_config = sys.argv[1] + if not os.path.exists(enkf_config): + print "Trying to start new config" + new_configuration_dialog = NewConfigurationDialog(enkf_config) + success = new_configuration_dialog.exec_() + if not success: + print "Can not run without a configuration file." + sys.exit(1) + else: + enkf_config = new_configuration_dialog.getConfigurationPath() + firste_case_name = new_configuration_dialog.getCaseName() + dbase_type = new_configuration_dialog.getDBaseType() + num_realizations = new_configuration_dialog.getNumberOfRealizations() + storage_path = new_configuration_dialog.getStoragePath() -ert.bootstrap(enkf_config, site_config = site_config, strict = strict) -window.setSaveFunction(ert.save) + EnKFMain.create_new_config(enkf_config, storage_path , firste_case_name, dbase_type, num_realizations) + strict = False -splash.showMessage("Creating GUI...", color=QtCore.Qt.white) -app.processEvents() + ert.bootstrap(enkf_config, site_config = site_config, strict = strict) + window.setSaveFunction(ert.save) -#window.addPage("Configuration", resourceIcon("config"), ConfigPages(window)) -window.addPage("Init", resourceIcon("db"), InitPanel(window)) -window.addPage("Run", resourceIcon("run"), RunPanel(window)) -window.addPage("Plots", resourceIcon("plot"), PlotPanel()) + splash.showMessage("Creating GUI...", QtCore.Qt.AlignLeft, QtCore.Qt.white) + app.processEvents() -splash.showMessage("Communicating with ERT...", color=QtCore.Qt.white) -app.processEvents() + window.addPage("Configuration", resourceIcon("config"), ConfigPages(window)) + window.addPage("Init" , resourceIcon("db"), InitPanel(window)) + window.addPage("Run" , resourceIcon("run"), RunPanel(window)) + window.addPage("Plots", resourceIcon("plot"), PlotPanel()) + + splash.showMessage("Communicating with ERT...", QtCore.Qt.AlignLeft, QtCore.Qt.white) + app.processEvents() + + ContentModel.contentModel = ert + ContentModel.updateObservers() + + window.show() + splash.finish(window) + + sys.exit(app.exec_()) + +if __name__ =="__main__": + main() -ContentModel.contentModel = ert -ContentModel.updateObservers() -window.show() -splash.finish(window) -sys.exit(app.exec_()) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/newconfig.py b/ThirdParty/Ert/devel/python/python/ert_gui/newconfig.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/newconfig.py rename to ThirdParty/Ert/devel/python/python/ert_gui/newconfig.py diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert_gui/pages/CMakeLists.txt new file mode 100644 index 0000000000..73e3edd049 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/CMakeLists.txt @@ -0,0 +1,5 @@ +add_python_package( "Python gui.pages" ${PYTHON_INSTALL_PREFIX}/ert_gui/pages "application.py;__init__.py" True) +add_subdirectory( config ) +add_subdirectory( init ) +add_subdirectory( plot ) +add_subdirectory( run ) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/__init__.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/__init__.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/__init__.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/__init__.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/application.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/application.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/application.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/application.py diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/CMakeLists.txt new file mode 100644 index 0000000000..ffe74a9b66 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/CMakeLists.txt @@ -0,0 +1,4 @@ +add_python_package( "Python ert_gui.pages.config" ${PYTHON_INSTALL_PREFIX}/ert_gui/pages/config "__init__.py;analysis.py;configpages.py;eclipse.py;ensemble.py;observations.py;plot.py;queuesystem.py;simulation.py;systemenv.py" True) +add_subdirectory( jobs ) +add_subdirectory( parameters ) +add_subdirectory( simulations ) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/__init__.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/__init__.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/__init__.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/__init__.py diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/analysis.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/analysis.py new file mode 100644 index 0000000000..ffd0839516 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/analysis.py @@ -0,0 +1,85 @@ +# Copyright (C) 2011 Statoil ASA, Norway. +# +# The file 'analysis.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + + +# ---------------------------------------------------------------------------------------------- +# Analysis tab +# ---------------------------------------------------------------------------------------------- +from ert_gui.widgets.checkbox import CheckBox +from ert_gui.widgets.spinnerwidgets import IntegerSpinner, DoubleSpinner, DoubleSpinner +import ert_gui.widgets.tablewidgets +from ert_gui.widgets.pathchooser import PathChooser +from PyQt4 import QtGui +import ert.enkf + +def createAnalysisPage(configPanel, parent): + configPanel.startPage("Analysis") + + r = configPanel.addRow(CheckBox(parent, "ENKF rerun", "config/analysis/enkf_rerun", "Perform rerun")) + r.initialize = lambda ert : ert.main.analysis_config.get_rerun + r.getter = lambda ert : ert.main.analysis_config.get_rerun + r.setter = lambda ert, value : ert.main.analysis_config.set_rerun( value) + + r = configPanel.addRow(IntegerSpinner(parent, "Rerun start", "config/analysis/rerun_start", 0, 100000)) + r.initialize = lambda ert : ert.main.analysis_config.get_rerun_start + r.getter = lambda ert : ert.main.analysis_config.get_rerun_start + r.setter = lambda ert, value : ert.main.analysis_config.set_rerun_start( value) + + r = configPanel.addRow(PathChooser(parent, "ENKF schedule file", "config/analysis/enkf_sched_file")) + r.initialize = lambda ert : ert.main.model_config.get_enkf_sched_file + r.getter = lambda ert : ert.main.model_config.get_enkf_sched_file + r.setter = lambda ert, value : ert.main.model_config.set_enkf_sched_file(str(value)) + + r = configPanel.addRow(ert_gui.widgets.tablewidgets.KeywordList(parent, "Local config", "config/analysis/local_config")) + r.newKeywordPopup = lambda list : QtGui.QFileDialog.getOpenFileName(r, "Select a path", "") + + def get_local_config_files(ert): + local_config = ert.main.local_config + config_files_pointer = ert.main.local_config.get_config_files + return config_files_pointer + + r.initialize = get_local_config_files + r.getter = get_local_config_files + + def add_config_file(ert, value): + local_config = ert.main.local_config + ert.main.local_config.clear_config_files + + for file in value: + ert.main.local_config.add_config_file( file) + + r.setter = add_config_file + + r = configPanel.addRow(PathChooser(parent, "Update log", "config/analysis/update_log")) + r.initialize = lambda ert : ert.main.analysis_config.get_log_path + r.getter = lambda ert : ert.main.analysis_config.get_log_path + r.setter = lambda ert, value : ert.main.analysis_config.set_log_path( str(value)) + + + configPanel.startGroup("EnKF") + + r = configPanel.addRow(DoubleSpinner(parent, "Alpha", "config/analysis/enkf_alpha", 0, 100000, 2)) + r.initialize = lambda ert : ert.main.analysis_config.get_alpha + r.getter = lambda ert : ert.main.analysis_config.get_alpha + r.setter = lambda ert, value : ert.main.analysis_config.set_alpha( value) + + r = configPanel.addRow(CheckBox(parent, "Merge Observations", "config/analysis/enkf_merge_observations", "Perform merge")) + r.initialize = lambda ert : ert.main.analysis_config.get_merge_observations + r.getter = lambda ert : ert.main.analysis_config.get_merge_observations + r.setter = lambda ert, value : ert.main.analysis_config.set_merge_observations( value) + + configPanel.endGroup() + configPanel.endPage() diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/configpages.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/configpages.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/configpages.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/configpages.py index 0bfed3f9da..e9be36339f 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/configpages.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/configpages.py @@ -14,16 +14,16 @@ # See the GNU General Public License at # for more details. - from ert_gui.widgets.configpanel import ConfigPanel import eclipse import analysis import queuesystem import systemenv import plot -import ensemble import observations import simulation +import ensemble + class ConfigPages(ConfigPanel): diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/eclipse.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/eclipse.py similarity index 60% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/eclipse.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/eclipse.py index 4a5504dc27..0d6c7415ea 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/eclipse.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/eclipse.py @@ -27,47 +27,54 @@ def createEclipsePage(configPanel, parent): configPanel.startPage("Eclipse") r = configPanel.addRow(PathChooser(parent, "Eclipse Base", "config/eclipse/eclbase", path_format=True)) - r.getter = lambda ert : ert.enkf.ecl_config_get_eclbase(ert.ecl_config) - r.setter = lambda ert, value : ert.enkf.enkf_main_set_eclbase(ert.main , str(value)) + r.initialize = lambda ert : ert.main.ecl_config.get_eclbase + r.getter = lambda ert : ert.main.ecl_config.get_eclbase + r.setter = lambda ert, value : ert.main.set_eclbase(str(value)) r = configPanel.addRow(PathChooser(parent, "Data file", "config/eclipse/data_file", show_files=True)) - r.getter = lambda ert : ert.enkf.ecl_config_get_data_file(ert.ecl_config) - r.setter = lambda ert, value : ert.enkf.enkf_main_set_data_file(ert.main , str(value)) + r.initialize = lambda ert : ert.main.ecl_config.get_data_file + r.getter = lambda ert : ert.main.ecl_config.get_data_file + r.setter = lambda ert, value : ert.main.set_datafile(str(value)) r = configPanel.addRow(PathChooser(parent, "Grid", "config/eclipse/grid", show_files=True)) - r.getter = lambda ert : ert.enkf.ecl_config_get_gridfile(ert.ecl_config) - r.setter = lambda ert, value : ert.enkf.ecl_config_set_grid(ert.ecl_config, str(value)) + r.initialize = lambda ert : ert.main.ecl_config.get_gridfile + r.getter = lambda ert : ert.main.ecl_config.get_gridfile + r.setter = lambda ert, value : ert.main.ecl_config.set_gridfile(str(value)) r = configPanel.addRow(PathChooser(parent, "Schedule file" , "config/eclipse/schedule_file" , show_files = True)) - r.getter = lambda ert : ert.enkf.ecl_config_get_schedule_file(ert.ecl_config) - r.setter = lambda ert, value : ert.enkf.ecl_config_set_schedule_file(ert.ecl_config, str(value)) + r.initialize = lambda ert : ert.main.ecl_config.get_schedule_file + r.getter = lambda ert : ert.main.ecl_config.get_schedule_file + r.setter = lambda ert, value : ert.main.ecl_config.set_schedule_file( str(value)) r = configPanel.addRow(PathChooser(parent, "Init section", "config/eclipse/init_section", show_files=True)) - r.getter = lambda ert : ert.enkf.ecl_config_get_init_section(ert.ecl_config) - r.setter = lambda ert, value : ert.enkf.ecl_config_set_init_section(ert.ecl_config, str(value)) + r.initialize = lambda ert : ert.main.ecl_config.get_init_section + r.getter = lambda ert : ert.main.ecl_config.get_init_section + r.setter = lambda ert, value : ert.main.ecl_config.set_init_section( str(value)) r = configPanel.addRow(PathChooser(parent, "Refcase", "config/eclipse/refcase", show_files=True)) - r.getter = lambda ert : ert.enkf.ecl_config_get_refcase_name(ert.ecl_config) - r.setter = lambda ert, value : ert.enkf.ecl_config_load_refcase(ert.ecl_config, str(value)) + r.initialize = lambda ert : ert.main.ecl_config.get_refcase_name + r.getter = lambda ert : ert.main.ecl_config.get_refcase_name + r.setter = lambda ert, value : ert.main.ecl_config.load_refcase( str(value)) r = configPanel.addRow(PathChooser(parent, "Schedule prediction file", "config/eclipse/schedule_prediction_file", show_files=True)) - r.getter = lambda ert : ert.enkf.enkf_main_get_schedule_prediction_file(ert.main) - r.setter = lambda ert, value : ert.enkf.enkf_main_set_schedule_prediction_file(ert.main, ert.nonify( value )) + r.initialize = lambda ert : ert.main.get_schedule_prediction_file + r.getter = lambda ert : ert.main.get_schedule_prediction_file + r.setter = lambda ert, value : ert.main.set_schedule_prediction_file( ert.nonify( value )) r = configPanel.addRow(KeywordTable(parent, "Data keywords", "config/eclipse/data_kw")) - r.getter = lambda ert : ert.getSubstitutionList(ert.enkf.enkf_main_get_data_kw(ert.main)) + r.getter = lambda ert : ert.getSubstitutionList(ert.main.get_data_kw) def add_data_kw(ert, listOfKeywords): - ert.enkf.enkf_main_clear_data_kw(ert.main) + ert.main.clear_data_kw for keyword in listOfKeywords: - ert.enkf.enkf_main_add_data_kw(ert.main, keyword[0], keyword[1]) + ert.main.add_data_kw( keyword[0], keyword[1]) r.setter = add_data_kw - + r.initialize = lambda ert : ert.getSubstitutionList(ert.main.get_data_kw) configPanel.addSeparator() @@ -76,16 +83,16 @@ def createEclipsePage(configPanel, parent): internalPanel.startPage("Static keywords") r = internalPanel.addRow(KeywordList(parent, "", "config/eclipse/add_static_kw")) - r.getter = lambda ert : ert.getStringList(ert.enkf.ecl_config_get_static_kw_list(ert.ecl_config)) + r.getter = lambda ert : ert.main.ecl_config.get_static_kw_list def add_static_kw(ert, listOfKeywords): - ert.enkf.ecl_config_clear_static_kw(ert.ecl_config) + ert.main.ecl_config.clear_static_kw for keyword in listOfKeywords: - ert.enkf.ecl_config_add_static_kw(ert.ecl_config, keyword) + ert.main.ecl_config.add_static_kw(keyword) r.setter = add_static_kw - + r.initialize = lambda ert : ert.main.ecl_config.get_static_kw_list internalPanel.endPage() # todo: add support for fixed length schedule keywords diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/ensemble.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/ensemble.py similarity index 65% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/ensemble.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/ensemble.py index ba40fec8f1..74fcce42af 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/ensemble.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/ensemble.py @@ -18,21 +18,23 @@ # ---------------------------------------------------------------------------------------------- # Ensemble tab # ---------------------------------------------------------------------------------------------- -from PyQt4 import QtGui, QtCore +from PyQt4 import QtCore from ert_gui.widgets.spinnerwidgets import IntegerSpinner -from parameters.parameterpanel import ParameterPanel, enums +from parameters.parameterpanel import ParameterPanel from parameters.parametermodels import SummaryModel, DataModel, FieldModel, KeywordModel -from ert.ert.enums import field_type -from ert.ert.enums import truncation_type -from ert.ert.enums import gen_data_file_format +import ert.ert.enums as enums +import ert.enkf.enkf_config_node +import ert.enkf.gen_kw_config +import ert.enkf.gen_data_config def createEnsemblePage(configPanel, parent): configPanel.startPage("Ensemble") r = configPanel.addRow(IntegerSpinner(parent, "Number of realizations", "config/ensemble/num_realizations", 1, 10000)) - r.getter = lambda ert : ert.enkf.enkf_main_get_ensemble_size(ert.main) - r.setter = lambda ert, value : ert.enkf.enkf_main_resize_ensemble(ert.main, value) + r.initialize = lambda ert : ert.main.ens_size + r.getter = lambda ert : ert.main.ens_size + r.setter = lambda ert, value : ert.main.resize_ensemble( value) parent.connect(r, QtCore.SIGNAL("contentsChanged()"), lambda : r.modelEmit("ensembleResized()")) @@ -41,52 +43,52 @@ def createEnsemblePage(configPanel, parent): r = configPanel.addRow(ParameterPanel(parent, "", "")) # no help file necessary parent.connect(r, QtCore.SIGNAL("contentsChanged()"), lambda : r.modelEmit("ensembleUpdated()")) + def getEnsembleParameters(ert): - keys = ert.getStringList(ert.enkf.ensemble_config_alloc_keylist(ert.ensemble_config), free_after_use=True) + keys = ert.main.ensemble_config.alloc_keylist parameters = [] for key in keys: - node = ert.enkf.ensemble_config_get_node(ert.ensemble_config, key) - type = ert.enkf.enkf_config_node_get_impl_type(node) - data = ert.enkf.enkf_config_node_get_ref(node) - #print key, type + node = ert.main.ensemble_config.get_node( key) + type = node.get_impl_type + data = node.get_ref model = None if type == FieldModel.TYPE: model = FieldModel(key) - field_type = ert.enkf.field_config_get_type(data) + field_type = node.field_model.get_type field_type = enums.field_type[field_type] model["type"] = field_type - truncation = ert.enkf.field_config_get_truncation_mode(data) + truncation = node.field_model.get_truncation_mode if truncation & enums.truncation_type.TRUNCATE_MAX: - model["max"] = ert.enkf.field_config_get_truncation_max(data) + model["max"] = node.field_model.get_truncation_max if truncation & enums.truncation_type.TRUNCATE_MIN: - model["min"] = ert.enkf.field_config_get_truncation_min(data) + model["min"] = node.field_model.get_truncation_min - model["init"] = ert.enkf.field_config_get_init_transform_name(data) - model["output"] = ert.enkf.field_config_get_output_transform_name(data) + model["init"] = node.field_model.get_init_transform_name + model["output"] = node.field_model.get_output_transform_name - model["init_files"] = ert.enkf.field_config_get_init_file_fmt(data) - model["min_std"] = ert.enkf.enkf_config_node_get_min_std_file(node) - model["enkf_outfile"] = ert.enkf.enkf_config_node_get_enkf_outfile(node) - model["enkf_infile"] = ert.enkf.enkf_config_node_get_enkf_infile(node) + model["init_files"] = node.get_init_file_fmt + model["min_std"] = node.get_min_std_file + model["enkf_outfile"] = node.get_enkf_outfile + model["enkf_infile"] = node.get_enkf_infile elif type == DataModel.TYPE: model = DataModel(key) - output_format_value = ert.enkf.gen_data_config_get_output_format(data) - output_format = gen_data_file_format.resolveValue(output_format_value) + output_format_value = node.data_model.get_output_format + output_format = enums.gen_data_file_format.resolveValue(output_format_value) - input_format_value = ert.enkf.gen_data_config_get_input_format(data) - input_format = gen_data_file_format.resolveValue(input_format_value) + input_format_value = node.data_model.get_input_format + input_format = enums.gen_data_file_format.resolveValue(input_format_value) - template_file = ert.enkf.gen_data_config_get_template_file(data) - template_key = ert.enkf.gen_data_config_get_template_key(data) - init_file_fmt = ert.enkf.gen_data_config_get_init_file_fmt(data) + template_file = node.data_model.get_template_file + template_key = node.data_model.get_template_key + init_file_fmt = node.get_init_file_fmt model["output_format"] = output_format model["input_format"] = input_format @@ -94,9 +96,9 @@ def createEnsemblePage(configPanel, parent): model["template_key"] = template_key model["init_file_fmt"] = init_file_fmt - min_std = ert.enkf.enkf_config_node_get_min_std_file(node) - enkf_outfile = ert.enkf.enkf_config_node_get_enkf_outfile(node) - enkf_infile = ert.enkf.enkf_config_node_get_enkf_infile(node) + min_std = node.get_min_std_file + enkf_outfile = node.get_enkf_outfile + enkf_infile = node.get_enkf_infile @@ -106,40 +108,40 @@ def createEnsemblePage(configPanel, parent): elif type == KeywordModel.TYPE: model = KeywordModel(key) - model["min_std"] = ert.enkf.enkf_config_node_get_min_std_file(node) - model["enkf_outfile"] = ert.enkf.enkf_config_node_get_enkf_outfile(node) - model["template"] = ert.enkf.gen_kw_config_get_template_file(data) - model["init_file"] = ert.enkf.gen_kw_config_get_init_file_fmt(data) - model["parameter_file"] = ert.enkf.gen_kw_config_get_parameter_file(data) + model["min_std"] = node.get_min_std_file + model["enkf_outfile"] = node.get_enkf_outfile + model["template"] = node.keyword_model.get_template_file + model["init_file"] = node.get_init_file_fmt + model["parameter_file"] = node.keyword_model.get_parameter_file elif type == SummaryModel.TYPE: model = SummaryModel(key) else: pass #Unknown type - model.setValid(ert.enkf.enkf_config_node_is_valid(node)) + #model.setValid(ert.main.enkf_config_node.is_valid) parameters.append(model) return parameters def removeParameter(ert, parameter_key): - ert.enkf.enkf_main_del_node(ert.main, parameter_key) + ert.main.del_node(ert.main, parameter_key) def insertParameter(ert, parameter): key = parameter.getName() if parameter.getType() == FieldModel.TYPE: - grid = ert.enkf.ecl_config_get_grid(ert.ecl_config) - node = ert.enkf.ensemble_config_add_field(ert.ensemble_config, key, grid) - parameter.setValid(ert.enkf.enkf_config_node_is_valid(node)) + grid = ert.main.ecl_config.get_grid + node = ert.main.ensemble_config.add_field( key, grid) + parameter.setValid(ert.main.enkf_config_node.is_valid) elif parameter.getType() == DataModel.TYPE: - node = ert.enkf.ensemble_config_add_gen_data(ert.ensemble_config, key) - parameter.setValid(ert.enkf.enkf_config_node_is_valid(node)) + node = ert.main.ensemble_config.add_gen_data( key) + parameter.setValid(ert.main.enkf_config_node.is_valid) elif parameter.getType() == KeywordModel.TYPE: - node = ert.enkf.ensemble_config_add_gen_kw(ert.ensemble_config, key) - parameter.setValid(ert.enkf.enkf_config_node_is_valid(node)) + node = ert.main.ensemble_config.add_gen_kw( key) + parameter.setValid(ert.main.enkf_config_node.is_valid) elif parameter.getType() == SummaryModel.TYPE: parameter.setValid(True) - b = ert.enkf.ensemble_config_add_summary(ert.ensemble_config, key) + b = ert.main.ensemble_config.add_summary( key) return b > 0 #0 == NULL else: print "Unknown type: ", parameter @@ -149,7 +151,7 @@ def createEnsemblePage(configPanel, parent): def updateParameter(ert, parameter_model): key = parameter_model.getName() - node = ert.enkf.ensemble_config_get_node(ert.ensemble_config, key) + node = ert.main.ensemble_config.get_node( key) if isinstance(parameter_model, FieldModel): type = parameter_model["type"] @@ -165,12 +167,12 @@ def createEnsemblePage(configPanel, parent): maximum = 0.0 if type == field_type.ECLIPSE_RESTART: #dynamic - ert.enkf.enkf_config_node_update_state_field(node, + ert.main.enkf_config_node.update_state_field(node, truncate.value(), float(minimum), float(maximum)) elif type == field_type.ECLIPSE_PARAMETER: #parameter - ert.enkf.enkf_config_node_update_parameter_field(node, + ert.main.enkf_config_node.update_parameter_field(node, ert.nonify(parameter_model["enkf_outfile"]), ert.nonify(parameter_model["init_files"]), ert.nonify(parameter_model["min_std"]), @@ -180,7 +182,7 @@ def createEnsemblePage(configPanel, parent): parameter_model["init"], parameter_model["output"]) elif type == field_type.GENERAL: #general - ert.enkf.enkf_config_node_update_general_field(node, + ert.main.enkf_config_node.update_general_field(node, ert.nonify(parameter_model["enkf_outfile"]), ert.nonify(parameter_model["enkf_infile"]), ert.nonify(parameter_model["init_files"]), @@ -192,7 +194,7 @@ def createEnsemblePage(configPanel, parent): None, parameter_model["output"]) - parameter_model.setValid(ert.enkf.enkf_config_node_is_valid(node)) + parameter_model.setValid(ert.main.enkf_config_node.is_valid) elif isinstance(parameter_model, KeywordModel): enkf_outfile_fmt = parameter_model["enkf_outfile"] @@ -200,20 +202,20 @@ def createEnsemblePage(configPanel, parent): parameter_file = parameter_model["parameter_file"] min_std_file = parameter_model["min_std"] init_file_fmt = parameter_model["init_files"] - ert.enkf.enkf_config_node_update_gen_kw(node, + ert.main.enkf_config_node.update_gen_kw(node, ert.nonify(enkf_outfile_fmt), ert.nonify(template_file), ert.nonify(parameter_file), ert.nonify(min_std_file), ert.nonify(init_file_fmt)) - parameter_model.setValid(ert.enkf.enkf_config_node_is_valid(node)) + parameter_model.setValid(ert.main.enkf_config_node.is_valid) elif isinstance(parameter_model, SummaryModel): #should never be called from SummaryModel... raise AssertionError("Summary keys can not be updated!") elif isinstance(parameter_model, DataModel): input_format = gen_data_file_format.resolveName(str(parameter_model["input_format"])) output_format = gen_data_file_format.resolveName(str(parameter_model["output_format"])) - ert.enkf.enkf_config_node_update_gen_data(node, + ert.main.enkf_config_node.update_gen_data(node, input_format.value(), output_format.value(), ert.nonify(parameter_model["init_file_fmt"]), @@ -222,17 +224,18 @@ def createEnsemblePage(configPanel, parent): ert.nonify(parameter_model["enkf_outfile"]), ert.nonify(parameter_model["enkf_infile"]), ert.nonify(parameter_model["min_std"])) - parameter_model.setValid(ert.enkf.enkf_config_node_is_valid(node)) + parameter_model.setValid(ert.main.enkf_config_node.is_valid) else: raise AssertionError("Type is not supported: %s" % (parameter_model.__class__)) - if ert.enkf.enkf_config_node_is_valid(node): - ert.enkf.enkf_main_update_node( ert.main , key ) + if ert.main.enkf_config_node.is_valid: + ert.main.update_node( ert.main , key ) r.getter = getEnsembleParameters + r.initialize = getEnsembleParameters r.remove = removeParameter r.insert = insertParameter r.setter = updateParameter diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/CMakeLists.txt new file mode 100644 index 0000000000..6eda67f87d --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/CMakeLists.txt @@ -0,0 +1 @@ +add_python_package( "Python ert_gui.pages.config.jobs" ${PYTHON_INSTALL_PREFIX}/ert_gui/pages/config/jobs "__init__.py;forwardmodelpanel.py;jobsdialog.py;jobspanel.py" True) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/jobs/__init__.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/__init__.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/jobs/__init__.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/__init__.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/jobs/forwardmodelpanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/forwardmodelpanel.py similarity index 97% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/jobs/forwardmodelpanel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/forwardmodelpanel.py index ffb35bfd55..bdab0fa371 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/jobs/forwardmodelpanel.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/forwardmodelpanel.py @@ -52,11 +52,10 @@ class ForwardModelPanel(HelpedWidget): def createWidgets(self, parent): self.searchableList = SearchableList(parent, list_height=150, list_width=150, ignore_case=True, order_editable=True) self.addWidget(self.searchableList) - self.connect(self.searchableList, QtCore.SIGNAL('currentItemChanged(QListWidgetItem, QListWidgetItem)'), - self.changeParameter) - self.connect(self.searchableList, QtCore.SIGNAL('addItem(list)'), self.addItem) - self.connect(self.searchableList, QtCore.SIGNAL('removeItem(list)'), self.removeItem) - self.connect(self.searchableList, QtCore.SIGNAL('orderChanged(list)'), self.forwardModelChanged) + self.connect(self.searchableList, QtCore.SIGNAL('currentItemChanged(QListWidgetItem, QListWidgetItem)'),self.changeParameter) + self.connect(self.searchableList, QtCore.SIGNAL('addItem(QListWidgetItem)'), self.addItem) + self.connect(self.searchableList, QtCore.SIGNAL('removeItem(QListWidgetItem)'), self.removeItem) + self.connect(self.searchableList, QtCore.SIGNAL('orderChanged(QListWidgetItem)'), self.forwardModelChanged) self.forward_model_panel = ert_gui.widgets.util.createEmptyPanel() diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/jobs/jobsdialog.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/jobsdialog.py similarity index 67% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/jobs/jobsdialog.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/jobsdialog.py index 468009b714..df006158d6 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/jobs/jobsdialog.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/jobsdialog.py @@ -87,53 +87,124 @@ class JobConfigPanel(ConfigPanel): def jid(ert): """Returns the pointer to the current job (self.job)""" - jl = ert.enkf.site_config_get_installed_jobs(ert.site_config) - return ert.job_queue.ext_joblist_get_job(jl, self.job.name) + jl = ert.main.site_config.get_installed_jobs + return jl.get_job(self.job.name) + def set_stdin(ert,value): + job = jid(ert) + job.set_stdin_file(value) + + def get_stdin(ert): + job = jid(ert) + return job.get_stdin_file + self.stdin = PathChooser(self, "", "config/systemenv/install_job_stdin", show_files=True, must_be_set=False, must_exist=True) - self.stdin.setter = lambda ert, value : ert.job_queue.ext_job_set_stdin_file(jid(ert), value) - self.stdin.getter = lambda ert : ert.job_queue.ext_job_get_stdin_file(jid(ert)) + self.stdin.setter = set_stdin + self.stdin.getter = get_stdin + self.stdin.initialize =get_stdin + def set_stdout(ert,value): + job = jid(ert) + job.set_stdout_file(value) + + def get_stdout(ert): + job = jid(ert) + return job.get_stdout_file + self.stdout = PathChooser(self, "", "config/systemenv/install_job_stdout", show_files=True, must_be_set=True, must_exist=False) - self.stdout.setter = lambda ert, value : ert.job_queue.ext_job_set_stdout_file(jid(ert), value) - self.stdout.getter = lambda ert : ert.job_queue.ext_job_get_stdout_file(jid(ert)) + self.stdout.setter = set_stdout + self.stdout.getter = get_stdout + self.stdout.initialize = get_stdout + def set_stderr(ert,value): + job = jid(ert) + job.set_stderr_file(value) + + def get_stderr(ert): + job = jid(ert) + return job.get_stderr_file + self.stderr = PathChooser(self, "", "config/systemenv/install_job_stderr", show_files=True, must_be_set=True, must_exist=False) - self.stderr.setter = lambda ert, value : ert.job_queue.ext_job_set_stderr_file(jid(ert), value) - self.stderr.getter = lambda ert : ert.job_queue.ext_job_get_stderr_file(jid(ert)) + self.stderr.setter = set_stderr + self.stderr.getter = get_stderr + self.stderr.initialize = get_stderr - self.target_file = PathChooser(self, "", "config/systemenv/install_job_target_file", show_files=True, must_be_set=False, - must_exist=False) - self.target_file.setter = lambda ert, value : ert.job_queue.ext_job_set_target_file(jid(ert), value) - self.target_file.getter = lambda ert : ert.job_queue.ext_job_get_target_file(jid(ert)) + def set_target_file(ert,value): + job = jid(ert) + job.set_target_file(value) + def get_target_file(ert): + job = jid(ert) + return job.get_target_file + + self.target_file = PathChooser(self, "", "config/systemenv/install_job_target_file", show_files=True, must_be_set=False, must_exist=False) + self.target_file.setter = set_target_file + self.target_file.getter = get_target_file + self.target_file.initialize = get_target_file + + def set_executable(ert,value): + job = jid(ert) + job.set_executable(value) + + def get_executable(ert): + job = jid(ert) + return job.get_executable + self.executable = PathChooser(self, "", "config/systemenv/install_job_executable", show_files=True, must_be_set=True, must_exist=True, is_executable_file=True) - self.executable.setter = lambda ert, value : ert.job_queue.ext_job_set_executable(jid(ert), value) - self.executable.getter = lambda ert : ert.job_queue.ext_job_get_executable(jid(ert)) + self.executable.setter = set_executable + self.executable.getter = get_executable def setEnv(ert, value): job = jid(ert) - ert.job_queue.ext_job_clear_environment(job) + job.clear_environment for env in value: - ert.job_queue.ext_job_add_environment(job, env[0], env[1]) + job.set_environment(env[0], env[1]) + + def getEnv(ert): + job = jid(ert) + return ert.getHash(job.get_environment) self.env = KeywordTable(self, "", "config/systemenv/install_job_env", colHead1="Variable", colHead2="Value") self.env.setter = setEnv - self.env.getter = lambda ert : ert.getHash(ert.job_queue.ext_job_get_environment(jid(ert))) + self.env.getter = getEnv + + def set_arglist(ert,value): + job = jid(ert) + job.set_private_args_from_string(value) + + def get_arglist(ert): + job = jid(ert) + return job.get_private_args_as_string self.arglist = StringBox(self, "", "config/systemenv/install_job_arglist") - self.arglist.setter = lambda ert, value : ert.job_queue.ext_job_set_private_args_from_string(jid(ert), value) - self.arglist.getter = lambda ert : ert.job_queue.ext_job_get_private_args_as_string(jid(ert)) + self.arglist.setter = set_arglist + self.arglist.getter = get_arglist + def set_max_running(ert,value): + job = jid(ert) + job.set_max_running(value) + + def get_max_running(ert): + job = jid(ert) + return job.get_max_running + self.max_running = IntegerSpinner(self, "", "config/systemenv/install_job_max_running", 0, 10000) - self.max_running.setter = lambda ert, value : ert.job_queue.ext_job_set_max_running(jid(ert), value) - self.max_running.getter = lambda ert : ert.job_queue.ext_job_get_max_running(jid(ert)) + self.max_running.setter = set_max_running + self.max_running.getter = get_max_running + def set_max_running_minutes(ert,value): + job = jid(ert) + job.set_max_running_minutes(value) + + def get_max_running(ert): + job = jid(ert) + return job.get_max_running_minutes + self.max_running_minutes = IntegerSpinner(self, "", "config/systemenv/install_job_max_running_minutes", 0, 10000) - self.max_running_minutes.setter = lambda ert, value : ert.job_queue.ext_job_set_max_running_minutes(jid(ert), value) - self.max_running_minutes.getter = lambda ert : ert.job_queue.ext_job_get_max_running_minutes(jid(ert)) + self.max_running_minutes.setter = set_max_running_minutes + self.max_running_minutes.getter = get_max_running_minutes self.startPage("Standard") diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/jobs/jobspanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/jobspanel.py similarity index 94% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/jobs/jobspanel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/jobspanel.py index 1fd7421fb7..18f4681a10 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/jobs/jobspanel.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/jobs/jobspanel.py @@ -49,10 +49,9 @@ class JobsPanel(HelpedWidget): def createWidgets(self, parent): self.searchableList = SearchableList(parent, list_height=200, list_width=150, ignore_case=True) self.addWidget(self.searchableList) - self.connect(self.searchableList, QtCore.SIGNAL('currentItemChanged(QListWidgetItem, QListWidgetItem)'), - self.changeParameter) - self.connect(self.searchableList, QtCore.SIGNAL('addItem(list)'), self.addItem) - self.connect(self.searchableList, QtCore.SIGNAL('removeItem(list)'), self.removeItem) + self.connect(self.searchableList , QtCore.SIGNAL('currentItemChanged(QListWidgetItem, QListWidgetItem)'),self.changeParameter) + self.connect(self.searchableList , QtCore.SIGNAL('addItem(QListWidgetItem)'), self.addItem) + self.connect(self.searchableList , QtCore.SIGNAL('removeItem(QListWidgetItem)'), self.removeItem) self.jobPanel = ert_gui.widgets.util.createEmptyPanel() diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/observations.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/observations.py similarity index 63% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/observations.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/observations.py index e7f0609726..b32de5adc4 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/observations.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/observations.py @@ -22,6 +22,7 @@ from ert_gui.widgets.combochoice import ComboChoice from ert_gui.widgets.pathchooser import PathChooser from ert.ert.enums import history_source_type from ert_gui.widgets.reloadbutton import ReloadButton +from ert.sched.history import HistoryType def createObservationsPage(configPanel, parent): configPanel.startPage("Observations") @@ -29,14 +30,23 @@ def createObservationsPage(configPanel, parent): r = configPanel.addRow(ComboChoice(parent, history_source_type.values(), "History source", "config/observations/history_source")) def get_history_source(ert): - history_source = ert.enkf.model_config_get_history_source(ert.model_config) - return history_source_type.resolveValue(history_source) + history_source = ert.main.model_config.get_history_source + return history_source_type.resolveValue(history_source.get_source_string) + r.initialize = get_history_source r.getter = get_history_source def set_history_source(ert, value): - history_source = history_source_type.resolveName(str(value)) - ert.enkf.model_config_get_history_source(ert.model_config, history_source.value()) + history_source_enum = history_source_type.resolveName(str(value)) + sched_file = ert.main.ecl_config.get_sched_file + refcase = ert.main.ecl_config.get_refcase + if history_source_enum.value() == 0: + history = HistoryType.alloc_from_sched_file(sched_file) + if history_source_enum.value() == 1: + history = HistoryType.alloc_from_refcase(refcase, True) + if history_source_enum.value() == 2: + history = HistoryType.alloc_from_refcase(refcase, False) + ert.main.model_config.set_history_source(history, sched_file, refcase) r.setter = set_history_source @@ -44,19 +54,21 @@ def createObservationsPage(configPanel, parent): r = configPanel.addRow(PathChooser(parent, "Observations config", "config/observations/obs_config", True)) def get_obs(ert): - obs = ert.enkf.enkf_main_get_obs(ert.main) - return ert.enkf.enkf_obs_get_config_file(obs) + obs = ert.main.get_obs + return obs.get_config_file + r.initialize = get_obs r.getter = get_obs def set_obs(ert, value): - ert.enkf.enkf_main_load_obs(ert.main, str(value)) + ert.main.load_obs( str(value)) r.setter = set_obs r = configPanel.addRow(ReloadButton(parent, "Reload Observations", "config/observations/reload_observation", "Reload")) - r.getter = lambda ert : ert.enkf.enkf_main_reload_obs(ert.main) + r.initialize = lambda ert : ert.main.reload_obs + r.getter = lambda ert : ert.main.reload_obs configPanel.endPage() diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/CMakeLists.txt new file mode 100644 index 0000000000..0d5db1aa04 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/CMakeLists.txt @@ -0,0 +1 @@ +add_python_package( "Python ert_gui.pages.config.parameters" ${PYTHON_INSTALL_PREFIX}/ert_gui/pages/config/parameters "__init__.py;datapanel.py;fieldpanel.py;keywordpanel.py;parameterdialog.py;parametermodels.py;parameterpanel.py" True) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/__init__.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/__init__.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/__init__.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/__init__.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/datapanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/datapanel.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/datapanel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/datapanel.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/fieldpanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/fieldpanel.py similarity index 93% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/fieldpanel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/fieldpanel.py index 6120bc5575..978245006a 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/fieldpanel.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/fieldpanel.py @@ -48,10 +48,10 @@ class FieldPanel(QtGui.QFrame): self.max = DoubleBox(self, "", "config/ensemble/field_max") self.modelWrap(self.max, "max") - self.init = ComboChoice(self, ["None", "EXP", "LOG", "POW10", "ADD", "MUL", "RANDINT", "RANDFLOAT"], "", "config/ensemble/field_init") + self.init = ComboChoice(self, ["None", "EXP", "EXP0", "LOG", "LN","LN0", "POW10", "ADD", "MUL", "RANDINT", "RANDFLOAT"], "", "config/ensemble/field_init") self.modelWrap(self.init, "init") - self.output = ComboChoice(self, ["None", "EXP", "LOG", "POW10", "ADD", "MUL", "RANDINT", "RANDFLOAT"], "", "config/ensemble/field_output") + self.output = ComboChoice(self, ["None", "EXP", "EXP0", "LOG", "LN","LN0", "POW10", "ADD", "MUL", "RANDINT", "RANDFLOAT"], "", "config/ensemble/field_output") self.modelWrap(self.output, "output") self.init_files = PathChooser(self, "", "config/ensemble/field_init_files", True) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/keywordpanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/keywordpanel.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/keywordpanel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/keywordpanel.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/parameterdialog.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/parameterdialog.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/parameterdialog.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/parameterdialog.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/parametermodels.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/parametermodels.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/parametermodels.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/parametermodels.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/parameterpanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/parameterpanel.py similarity index 89% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/parameterpanel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/parameterpanel.py index 9fb8dd15eb..46a27fc694 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/parameters/parameterpanel.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/parameters/parameterpanel.py @@ -32,6 +32,7 @@ import ert_gui.widgets.util from parametermodels import SummaryModel, FieldModel, DataModel, KeywordModel from PyQt4.QtCore import SIGNAL + class ParameterPanel(HelpedWidget): """Shows a widget for parameters. The data structure expected and sent to the getter and setter is an array of Parameters.""" @@ -59,8 +60,8 @@ class ParameterPanel(HelpedWidget): self.addWidget(self.pagesWidget) self.connect(self.searchableList, QtCore.SIGNAL('currentItemChanged(QListWidgetItem, QListWidgetItem)'), self.changeParameter) - self.connect(self.searchableList, QtCore.SIGNAL('addItem(list)'), self.addItem) - self.connect(self.searchableList, QtCore.SIGNAL('removeItem(list)'), self.removeItem) + self.connect(self.searchableList, QtCore.SIGNAL('addItem(QListWidgetItem)'), self.addItem) + self.connect(self.searchableList, QtCore.SIGNAL('removeItem(QListWidgetItem)'), self.removeItem) #self.addHelpButton() @@ -110,7 +111,7 @@ class ParameterPanel(HelpedWidget): list.setCurrentItem(parameter) user_data = parameter.getUserData() - self.connect(user_data, SIGNAL('modelChanged(Model)'), self.modelChanged) + ##self.connect(user_data, SIGNAL('modelChanged(Model)'), self.modelChanged) def modelChanged(self, parameter_model): """Called whenever the content of a model changes""" @@ -123,7 +124,7 @@ class ParameterPanel(HelpedWidget): for index in range(list.count()): uniqueNames.append(str(list.item(index).text())) - pd = ParameterDialog(self, Parameter.typeIcons, uniqueNames) + pd = ParameterDialog(self, Parameter.get_typeIcons() , uniqueNames) if pd.exec_(): parameter = self.createParameter(pd.getTypeName(), pd.getName()) ok = self.updateContent(parameter, operation=ContentModel.INSERT) @@ -154,7 +155,9 @@ class ParameterPanel(HelpedWidget): for parameter in parameters: if parameter is None: - raise AssertionError("Unknown type name!") + sys.stderr.write("Unknown type name!\n") + break + #raise AssertionError("Unknown type name!") param = Parameter(parameter.name, parameter.TYPE) param.setUserData(parameter) @@ -166,54 +169,65 @@ class ParameterPanel(HelpedWidget): self.searchableList.getList().setCurrentRow(0) + class Parameter(QtGui.QListWidgetItem): """ListWidgetItem class that represents a Parameter with an associated icon.""" - typeIcons = {FieldModel.TYPE: util.resourceIcon("grid_16"), - DataModel.TYPE: util.resourceIcon("data"), - SummaryModel.TYPE: util.resourceIcon("summary"), - KeywordModel.TYPE: util.resourceIcon("key")} + + typeIcons__ = None + + @classmethod + def get_typeIcons(cls): + if cls.typeIcons__ is None: + typeIcons__ = {FieldModel.TYPE: util.resourceIcon("grid_16"), + DataModel.TYPE: util.resourceIcon("data"), + SummaryModel.TYPE: util.resourceIcon("summary"), + KeywordModel.TYPE: util.resourceIcon("key")} + return typeIcons__ + def __init__(self, name, type, icon=None): if icon is None: - icon = Parameter.typeIcons[type] - + icon = Parameter.get_typeIcons()[type] + QtGui.QListWidgetItem.__init__(self, icon, name) self.type = type self.name = name self.user_data = None self.setValid(True) - + def getType(self): """Retruns the type of this parameter""" return self.type - + def getName(self): """Returns the name of this parameter (keyword)""" return self.name - + def __ge__(self, other): if self.type.name == other.type.name: return self.name.lower() >= other.name.lower() else: return self.type.name >= other.type.name - + def __lt__(self, other): return not self >= other - + def setUserData(self, data): """Set user data for this parameter.""" self.user_data = data - + def getUserData(self): """Retrieve the user data.""" return self.user_data - + def setValid(self, valid): """Set the validity of this item. An invalid item is colored red""" self.valid = valid - + if valid: self.setBackgroundColor(QtCore.Qt.white) else: self.setBackgroundColor(HelpedWidget.STRONG_ERROR_COLOR) + + diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/plot.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/plot.py similarity index 56% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/plot.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/plot.py index 268e8d4391..aa670fd133 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/plot.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/plot.py @@ -27,32 +27,39 @@ def createPlotPage(configPanel, parent): configPanel.startPage("Plot") r = configPanel.addRow(PathChooser(parent, "Output path", "config/plot/path")) - r.getter = lambda ert : ert.enkf.plot_config_get_path(ert.plot_config) - r.setter = lambda ert, value : ert.enkf.plot_config_set_path(ert.plot_config, str(value)) + r.initialize = lambda ert : ert.main.plot_config.get_path + r.getter = lambda ert : ert.main.plot_config.get_path + r.setter = lambda ert, value : ert.main.plot_config.set_path( str(value)) r = configPanel.addRow(ComboChoice(parent, ["PLPLOT", "TEXT"], "Driver", "config/plot/plot_driver")) - r.getter = lambda ert : ert.enkf.plot_config_get_driver(ert.plot_config) - r.setter = lambda ert, value : ert.enkf.plot_config_set_driver(ert.plot_config, str(value)) + r.initialize = lambda ert : ert.main.plot_config.get_driver + r.getter = lambda ert : ert.main.plot_config.get_driver + r.setter = lambda ert, value : ert.main.plot_config.set_driver( str(value)) r = configPanel.addRow(IntegerSpinner(parent, "Errorbar max", "config/plot/plot_errorbar_max", 1, 10000000)) - r.getter = lambda ert : ert.enkf.plot_config_get_errorbar_max(ert.plot_config) - r.setter = lambda ert, value : ert.enkf.plot_config_set_errorbar_max(ert.plot_config, value) + r.initialize = lambda ert : ert.main.plot_config.get_errorbar_max + r.getter = lambda ert : ert.main.plot_config.get_errorbar_max + r.setter = lambda ert, value : ert.main.plot_config.set_errorbar_max( value) r = configPanel.addRow(IntegerSpinner(parent, "Width", "config/plot/width", 1, 10000)) - r.getter = lambda ert : ert.enkf.plot_config_get_width(ert.plot_config) - r.setter = lambda ert, value : ert.enkf.plot_config_set_width(ert.plot_config, value) + r.initialize = lambda ert : ert.main.plot_config.get_width + r.getter = lambda ert : ert.main.plot_config.get_width + r.setter = lambda ert, value : ert.main.plot_config.set_width( value) r = configPanel.addRow(IntegerSpinner(parent, "Height", "config/plot/plot_height", 1, 10000)) - r.getter = lambda ert : ert.enkf.plot_config_get_height(ert.plot_config) - r.setter = lambda ert, value : ert.enkf.plot_config_set_height(ert.plot_config, value) + r.initialize = lambda ert : ert.main.plot_config.get_height + r.getter = lambda ert : ert.main.plot_config.get_height + r.setter = lambda ert, value : ert.main.plot_config.set_height( value) r = configPanel.addRow(PathChooser(parent, "Image Viewer", "config/plot/image_viewer", True)) - r.getter = lambda ert : ert.enkf.plot_config_get_viewer(ert.plot_config) - r.setter = lambda ert, value : ert.enkf.plot_config_set_viewer(ert.plot_config, str(value)) + r.initialize = lambda ert : ert.main.plot_config.get_viewer + r.getter = lambda ert : ert.main.plot_config.get_viewer + r.setter = lambda ert, value : ert.main.plot_config.set_viewer( str(value)) r = configPanel.addRow(ComboChoice(parent, ["bmp", "jpg", "png", "tif"], "Image type", "config/plot/image_type")) - r.getter = lambda ert : ert.enkf.plot_config_get_image_type(ert.plot_config) - r.setter = lambda ert, value : ert.enkf.plot_config_set_image_type(ert.plot_config, str(value)) + r.initialize = lambda ert : ert.main.plot_config.get_image_type + r.getter = lambda ert : ert.main.plot_config.get_image_type + r.setter = lambda ert, value : ert.main.plot_config.set_image_type( str(value)) configPanel.endPage() diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/queuesystem.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/queuesystem.py similarity index 60% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/queuesystem.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/queuesystem.py index 9f82da1f5e..f890b6a1db 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/queuesystem.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/queuesystem.py @@ -29,24 +29,28 @@ def createQueueSystemPage(configPanel, parent): configPanel.startPage("Queue System") r = configPanel.addRow(ComboChoice(parent, ["LSF", "RSH", "LOCAL"], "Queue system", "config/queue_system/queue_system")) - r.getter = lambda ert : ert.enkf.site_config_get_queue_name(ert.site_config) - r.setter = lambda ert, value : ert.enkf.site_config_set_job_queue(ert.site_config, str(value)) + r.initialize = lambda ert : ert.main.site_config.get_queue_name + r.getter = lambda ert : ert.main.site_config.get_queue_name + r.setter = lambda ert, value : ert.main.site_config.set_job_queue(str(value)) internalPanel = ConfigPanel(parent) internalPanel.startPage("LSF") r = internalPanel.addRow(StringBox(parent, "LSF Queue", "config/queue_system/lsf_queue")) - r.getter = lambda ert : ert.enkf.site_config_get_lsf_queue(ert.site_config) - r.setter = lambda ert, value : ert.enkf.site_config_set_lsf_queue(ert.site_config, str(value)) + r.initialize = lambda ert : ert.main.site_config.get_lsf_queue + r.getter = lambda ert : ert.main.site_config.get_lsf_queue + r.setter = lambda ert, value : ert.main.site_config.set_lsf_queue( str(value)) r = internalPanel.addRow(IntegerSpinner(parent, "Max running", "config/queue_system/max_running_lsf", 1, 1000)) - r.getter = lambda ert : ert.enkf.site_config_get_max_running_lsf(ert.site_config) - r.setter = lambda ert, value : ert.enkf.site_config_set_max_running_lsf(ert.site_config, value) + r.initialize = lambda ert : ert.main.site_config.get_max_running_lsf + r.getter = lambda ert : ert.main.site_config.get_max_running_lsf + r.setter = lambda ert, value : ert.main.site_config.set_max_running_lsf( value) r = internalPanel.addRow(StringBox(parent, "Resources", "config/queue_system/lsf_resources")) - r.getter = lambda ert : ert.enkf.site_config_get_lsf_request(ert.site_config) - r.setter = lambda ert, value : ert.enkf.site_config_set_lsf_request(ert.site_config, str(value)) + r.initialize = lambda ert : ert.main.site_config.get_lsf_request + r.getter = lambda ert : ert.main.site_config.get_lsf_request + r.setter = lambda ert, value : ert.main.site_config.set_lsf_request(str(value)) internalPanel.endPage() @@ -54,19 +58,22 @@ def createQueueSystemPage(configPanel, parent): internalPanel.startPage("RSH") r = internalPanel.addRow(PathChooser(parent, "Command", "config/queue_system/rsh_command", show_files=True, must_exist=True, is_executable_file=True)) - r.getter = lambda ert : ert.enkf.site_config_get_rsh_command(ert.site_config) - r.setter = lambda ert, value : ert.enkf.site_config_set_rsh_command(ert.site_config, str(value)) + r.initialize = lambda ert : ert.main.site_config.get_rsh_command + r.getter = lambda ert : ert.main.site_config.get_rsh_command + r.setter = lambda ert, value : ert.main.site_config.set_rsh_command(str(value)) r = internalPanel.addRow(IntegerSpinner(parent, "Max running", "config/queue_system/max_running_rsh", 1, 1000)) - r.getter = lambda ert : ert.enkf.site_config_get_max_running_rsh(ert.site_config) - r.setter = lambda ert, value : ert.enkf.site_config_set_max_running_rsh(ert.site_config, value) + r.initialize = lambda ert : ert.main.site_config.get_max_running_rsh + r.getter = lambda ert : ert.main.site_config.get_max_running_rsh + r.setter = lambda ert, value : ert.main.site_config.set_max_running_rsh( value) r = internalPanel.addRow(KeywordTable(parent, "Host List", "config/queue_system/rsh_host_list", "Host", "Number of jobs")) - r.getter = lambda ert : ert.getHash(ert.enkf.site_config_get_rsh_host_list(ert.site_config), True) + r.initialize = lambda ert : ert.getHash(ert.main.site_config.get_rsh_host_list, True) + r.getter = lambda ert : ert.getHash(ert.main.site_config.get_rsh_host_list, True) def add_rsh_host(ert, listOfKeywords): - ert.enkf.site_config_clear_rsh_host_list(ert.site_config) + ert.main.site_config.clear_rsh_host_list for keyword in listOfKeywords: if keyword[1].strip() == "": @@ -74,7 +81,7 @@ def createQueueSystemPage(configPanel, parent): else: max_running = int(keyword[1]) - ert.enkf.site_config_add_rsh_host(ert.site_config, keyword[0], max_running) + ert.main.site_config.add_rsh_host( keyword[0], max_running) r.setter = add_rsh_host @@ -84,8 +91,9 @@ def createQueueSystemPage(configPanel, parent): internalPanel.startPage("LOCAL") r = internalPanel.addRow(IntegerSpinner(parent, "Max running", "config/queue_system/max_running_local", 1, 1000)) - r.getter = lambda ert : ert.enkf.site_config_get_max_running_local(ert.site_config) - r.setter = lambda ert, value : ert.enkf.site_config_set_max_running_local(ert.site_config, value) + r.initialize = lambda ert : ert.main.site_config.get_max_running_local + r.getter = lambda ert : ert.main.site_config.get_max_running_local + r.setter = lambda ert, value : ert.main.site_config.set_max_running_local(value) internalPanel.endPage() configPanel.addRow(internalPanel) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/simulation.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/simulation.py similarity index 57% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/simulation.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/simulation.py index db12479cca..d833e20cb1 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/simulation.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/simulation.py @@ -31,18 +31,21 @@ from ert.ert.enums import keep_runpath_type from simulations.runtemplatepanel import RunTemplatePanel import ert_gui.widgets.helpedwidget import os +from ert.util.stringlist import StringList def createSimulationsPage(configPanel, parent): configPanel.startPage("Simulations") r = configPanel.addRow(IntegerSpinner(parent, "Max submit", "config/simulation/max_submit", 1, 10000)) - r.getter = lambda ert : ert.enkf.site_config_get_max_submit(ert.site_config) - r.setter = lambda ert, value : ert.enkf.site_config_set_max_submit(ert.site_config, value) + r.initialize = lambda ert : ert.main.site_config.get_max_submit + r.getter = lambda ert : ert.main.site_config.get_max_submit + r.setter = lambda ert, value : ert.main.site_config.set_max_submit( value) - r = configPanel.addRow(IntegerSpinner(parent, "Max resample", "config/simulation/max_resample", 1, 10000)) - r.getter = lambda ert : ert.enkf.model_config_get_max_resample(ert.model_config) - r.setter = lambda ert, value : ert.enkf.model_config_set_max_resample(ert.model_config, value) + r = configPanel.addRow(IntegerSpinner(parent, "Max internal submit", "config/simulation/max_resample", 1, 10000)) + r.initialize = lambda ert : ert.main.model_config.get_max_internal_submit + r.getter = lambda ert : ert.main.model_config.get_max_internal_submit + r.setter = lambda ert, value : ert.main.model_config.set_max_internal_submit( value) @@ -50,25 +53,23 @@ def createSimulationsPage(configPanel, parent): def get_forward_model(ert): - site_config = ert.site_config - installed_jobs_pointer = ert.enkf.site_config_get_installed_jobs(site_config) - installed_jobs_stringlist_pointer = ert.job_queue.ext_joblist_alloc_list(installed_jobs_pointer) - available_jobs = ert.getStringList(installed_jobs_stringlist_pointer , free_after_use=True) + site_config = ert.main.site_config + installed_jobs = ert.main.site_config.get_installed_jobs + available_jobs = installed_jobs.alloc_list result = {'available_jobs': available_jobs} - model_config = ert.model_config - forward_model = ert.enkf.model_config_get_forward_model(model_config) - name_string_list = ert.job_queue.forward_model_alloc_joblist(forward_model) - job_names = ert.getStringList(name_string_list, free_after_use=True) - + model_config = ert.main.model_config + forward_model = model_config.get_forward_model + job_names = forward_model.alloc_joblist + forward_model_jobs = [] count = 0 for name in job_names: - ext_job = ert.job_queue.forward_model_iget_job(forward_model, count) - arg_string = ert.job_queue.ext_job_get_private_args_as_string(ext_job) - help_text = ert.job_queue.ext_job_get_help_text(ext_job) + ext_job = forward_model.iget_job( count) + arg_string = ext_job.get_private_args_as_string + help_text = ext_job.get_help_text forward_model_jobs.append((name, arg_string, help_text)) count+=1 @@ -77,16 +78,17 @@ def createSimulationsPage(configPanel, parent): return result r.getter = get_forward_model + r.initialize = get_forward_model def update_forward_model(ert, forward_model): - forward_model_pointer = ert.enkf.model_config_get_forward_model(ert.model_config) - ert.job_queue.forward_model_clear(forward_model_pointer) + forward_model_object = ert.main.model_config.get_forward_model + forward_model_object.clear for job in forward_model: name = job[0] args = job[1] - ext_job = ert.job_queue.forward_model_add_job(forward_model_pointer, name) - ert.job_queue.ext_job_set_private_args_from_string(ext_job, args) + ext_job = forward_model.add_job( name) + ext_job.set_private_args_from_string( args) r.setter = update_forward_model @@ -96,17 +98,19 @@ def createSimulationsPage(configPanel, parent): def get_case_table(ert): - return ert.enkf.model_config_get_case_table_file(ert.model_config) + return ert.main.model_config.get_case_table_file r.getter = get_case_table - + r.initialize = get_case_table + def set_case_table(ert, value): if os.path.exists(value): - ert.enkf.enkf_main_set_case_table(ert.model_config, ert.nonify(value)) + ert.main.set_case_table( ert.nonify(value)) r.setter = set_case_table r = configPanel.addRow(PathChooser(parent, "License path", "config/simulation/license_path")) - r.getter = lambda ert : ert.enkf.site_config_get_license_root_path(ert.site_config) + r.getter = lambda ert : ert.main.site_config.get_license_root_path + r.initialize = lambda ert : ert.main.site_config.get_license_root_path def ls(string): if string is None: @@ -114,7 +118,7 @@ def createSimulationsPage(configPanel, parent): else: return string - r.setter = lambda ert, value : ert.enkf.site_config_set_license_root_path(ert.site_config, ls(value)) + r.setter = lambda ert, value : ert.main.site_config.set_license_root_path( ls(value)) @@ -124,33 +128,36 @@ def createSimulationsPage(configPanel, parent): r = internalPanel.addRow(PathChooser(parent, "Runpath", "config/simulation/runpath", path_format=True)) - r.getter = lambda ert : ert.enkf.model_config_get_runpath_as_char(ert.model_config) - r.setter = lambda ert, value : ert.enkf.model_config_set_runpath_fmt(ert.model_config, str(value)) + r.getter = lambda ert : ert.main.model_config.get_runpath_as_char + r.initialize = lambda ert : ert.main.model_config.get_runpath_as_char + r.setter = lambda ert, value : ert.main.model_config.select_runpath( str(value)) parent.connect(r, QtCore.SIGNAL("contentsChanged()"), lambda : r.modelEmit("runpathChanged()")) r = internalPanel.addRow(CheckBox(parent, "Pre clear", "config/simulation/pre_clear_runpath", "Perform pre clear")) - r.getter = lambda ert : ert.enkf.enkf_main_get_pre_clear_runpath(ert.main) - r.setter = lambda ert, value : ert.enkf.enkf_main_set_pre_clear_runpath(ert.main, value) + r.getter = lambda ert : ert.main.get_pre_clear_runpath + r.initialize = lambda ert : ert.main.get_pre_clear_runpath + r.setter = lambda ert, value : ert.main.set_pre_clear_runpath( value) r = internalPanel.addRow(RunpathMemberPanel(widgetLabel="Retain runpath", helpLabel="config/simulation/runpath_retain")) def get_runpath_retain_state(ert): - ensemble_size = ert.enkf.enkf_main_get_ensemble_size(ert.main) + ensemble_size = ert.main.ens_size result = [] for index in range(ensemble_size): - state = ert.enkf.enkf_main_iget_keep_runpath(ert.main, index) + state = ert.main.iget_keep_runpath( index) result.append((index, keep_runpath_type.resolveValue(state))) return result r.getter = get_runpath_retain_state - + r.initialize = get_runpath_retain_state + def set_runpath_retain_state(ert, items): for item in items: - ert.enkf.enkf_main_iset_keep_runpath(ert.main, item.member, item.runpath_state.value()) + ert.main.iset_keep_runpath(item.member, item.runpath_state.value()) r.setter = set_runpath_retain_state @@ -162,27 +169,27 @@ def createSimulationsPage(configPanel, parent): r = internalPanel.addRow(RunTemplatePanel(parent)) def get_run_templates(ert): - templates = ert.enkf.enkf_main_get_templates(ert.main) - template_list = ert.enkf.ert_template_alloc_list(templates) - - template_names = ert.getStringList(template_list, free_after_use=True) + templates = ert.main.get_templates + template_names = templates.alloc_list + result = [] for name in template_names: - template = ert.enkf.ert_template_get_template(templates, name) - template_file = ert.enkf.ert_template_get_template_file(template) - target_file = ert.enkf.ert_template_get_target_file(template) - arguments = ert.enkf.ert_template_get_args_as_string(template) + template = templates.get_template(name) + template_file = template.get_template_file + target_file = template.get_target_file + arguments = template.get_args_as_string result.append((name, template_file, target_file, arguments)) return result r.getter = get_run_templates + r.initialize = get_run_templates def set_run_templates(ert, template_list): - templates_pointer = ert.enkf.enkf_main_get_templates(ert.main) - ert.enkf.ert_template_clear(templates_pointer) + templates_object = ert.main.get_templates + templates_object.clear for template in template_list: - ert.enkf.ert_template_add_template(templates_pointer, template[0], template[1], template[2], template[3]) + templates_object.add_template( template[0], template[1], template[2], template[3]) r.setter = set_run_templates diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/simulations/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/simulations/CMakeLists.txt new file mode 100644 index 0000000000..56a1241e5e --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/simulations/CMakeLists.txt @@ -0,0 +1 @@ +add_python_package( "Python ert_gui.pages.config.simulations" ${PYTHON_INSTALL_PREFIX}/ert_gui/pages/config/simulations "__init__.py;runpathpanel.py;runtemplatepanel.py" True) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/simulations/__init__.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/simulations/__init__.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/simulations/__init__.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/simulations/__init__.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/simulations/runpathpanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/simulations/runpathpanel.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/simulations/runpathpanel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/simulations/runpathpanel.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/simulations/runtemplatepanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/simulations/runtemplatepanel.py similarity index 99% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/simulations/runtemplatepanel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/simulations/runtemplatepanel.py index a661172500..98b263b37d 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/simulations/runtemplatepanel.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/simulations/runtemplatepanel.py @@ -53,8 +53,8 @@ class RunTemplatePanel(HelpedWidget): self.addWidget(self.searchableList) self.connect(self.searchableList, QtCore.SIGNAL('currentItemChanged(QListWidgetItem, QListWidgetItem)'), self.changeParameter) - self.connect(self.searchableList, QtCore.SIGNAL('addItem(list)'), self.addItem) - self.connect(self.searchableList, QtCore.SIGNAL('removeItem(list)'), self.removeItem) + self.connect(self.searchableList, QtCore.SIGNAL('addItem(QListWidgetItem)'), self.addItem) + self.connect(self.searchableList, QtCore.SIGNAL('removeItem(QListWidgetItem)'), self.removeItem) self.run_template_panel = ert_gui.widgets.util.createEmptyPanel() diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/systemenv.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/systemenv.py similarity index 60% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/systemenv.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/config/systemenv.py index e9c4f663d6..e4ee7873f5 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/config/systemenv.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/config/systemenv.py @@ -26,6 +26,7 @@ from jobs.jobspanel import JobsPanel, Job import os import ert_gui.widgets.spinnerwidgets from ert_gui.widgets.activelabel import ActiveLabel +from ert.job_queue.ext_job import ExtJob def createSystemPage(configPanel, parent): configPanel.startPage("System") @@ -34,25 +35,28 @@ def createSystemPage(configPanel, parent): # the site configuration file; this should only be a label - not # user editable. r = configPanel.addRow(ActiveLabel(None, "Site Config", "", "Not specified.")) - r.getter = lambda ert : ert.enkf.enkf_main_get_site_config_file(ert.main) + r.initialize = lambda ert : ert.main.get_site_config_file + r.getter = lambda ert : ert.main.get_site_config_file r.modelConnect("casesUpdated()", r.fetchContent) r = configPanel.addRow(PathChooser(parent, "Job script", "config/systemenv/job_script", True)) - r.getter = lambda ert : ert.enkf.site_config_get_job_script(ert.site_config) - r.setter = lambda ert, value : ert.enkf.site_config_set_job_script(ert.site_config, str(value)) + r.initialize = lambda ert : ert.main.site_config.get_job_script + r.getter = lambda ert : ert.main.site_config.get_job_script + r.setter = lambda ert, value : ert.main.site_config.set_job_script( str(value)) internalPanel = ConfigPanel(parent) internalPanel.startPage("setenv") r = internalPanel.addRow(KeywordTable(parent, "", "config/systemenv/setenv")) - r.getter = lambda ert : ert.getHash(ert.enkf.site_config_get_env_hash(ert.site_config)) + r.initialize = lambda ert : ert.getHash(ert.main.site_config.get_env_hash) + r.getter = lambda ert : ert.getHash(ert.main.site_config.get_env_hash) def setenv(ert, value): - ert.enkf.site_config_clear_env(ert.site_config) + ert.main.site_config.clear_env for env in value: - ert.enkf.site_config_setenv(ert.site_config, env[0], env[1]) + ert.main.site_config.setenv( env[0], env[1]) r.setter = setenv @@ -61,19 +65,21 @@ def createSystemPage(configPanel, parent): internalPanel.startPage("Update path") r = internalPanel.addRow(KeywordTable(parent, "", "config/systemenv/update_path")) + def get_update_path(ert): - paths = ert.getStringList(ert.enkf.site_config_get_path_variables(ert.site_config)) - values = ert.getStringList(ert.enkf.site_config_get_path_values(ert.site_config)) + paths = ert.main.site_config.get_path_variables + values = ert.main.site_config.get_path_values return [[p, v] for p, v in zip(paths, values)] r.getter = get_update_path - + r.initialize = get_update_path + def update_pathvar(ert, value): - ert.enkf.site_config_clear_pathvar(ert.site_config) + ert.main.site_config.clear_pathvar for pathvar in value: - ert.enkf.site_config_update_pathvar(ert.site_config, pathvar[0], pathvar[1]) + ert.main.site_config.update_pathvar( pathvar[0], pathvar[1]) r.setter = update_pathvar @@ -83,59 +89,66 @@ def createSystemPage(configPanel, parent): internalPanel.startPage("Jobs") r = internalPanel.addRow(JobsPanel(parent)) - def get_jobs(ert): - jl = ert.enkf.site_config_get_installed_jobs(ert.site_config) - h = ert.job_queue.ext_joblist_get_jobs(jl) - jobs = ert.getHash(h, return_type="long") + def get_jobs(ert): + jl = ert.main.site_config.get_installed_jobs + h = jl.get_jobs + stringlist = jl.alloc_list + jobs = ert.getHash(h, return_type="c_void_p") private_jobs = [] - for k, v in jobs: - v = int(v) - path = ert.job_queue.ext_job_get_config_file(v) - if ert.job_queue.ext_job_is_private(v): - private_jobs.append(Job(k, path)) + for v in stringlist: + job = jl.get_job(v) + path = job.get_config_file + if job.is_private: + private_jobs.append(Job(v, path)) + #for k, v in jobs: + # job = jl.get_job(v) + # path = job.get_config_file + # if v.is_private: + # private_jobs.append(Job(k, path)) return private_jobs def update_job(ert, value): - jl = ert.enkf.site_config_get_installed_jobs(ert.site_config) + jl = ert.main.site_config.get_installed_jobs if os.path.exists(value.path): - license = ert.enkf.site_config_get_license_root_path(ert.site_config) + license = ert.main.site_config.get_license_root_path job = ert.job_queue.ext_job_fscanf_alloc(value.name, license, True, value.path) - ert.job_queue.ext_joblist_add_job(jl, value.name, job) + jl.add_job(value.name, job) else: - job = ert.job_queue.ext_joblist_get_job(jl, value.name) - ert.job_queue.ext_job_set_config_file(job, value.path) + job = jl.get_job(value.name) + job.set_config_file(value.path) def add_job(ert, value): - jl = ert.enkf.site_config_get_installed_jobs(ert.site_config) - if not ert.job_queue.ext_joblist_has_job(jl, value.name): - license = ert.enkf.site_config_get_license_root_path(ert.site_config) + jl = ert.main.site_config.get_installed_jobs + if not jl.has_job(value.name): + license = ert.main.site_config.get_license_root_path if os.path.exists(value.path): job = ert.job_queue.ext_job_fscanf_alloc(value.name, license, True, value.path) - ert.job_queue.ext_joblist_add_job(jl, value.name, job) + jl.add_job(value.name, job) else: job = ert.job_queue.ext_job_alloc(value.name, license, True) - ert.job_queue.ext_job_set_config_file(job, value.path) - ert.job_queue.ext_joblist_add_job(jl, value.name, job) + job.set_config_file(value.path) + jl.add_job(value.name, job) return True return False def remove_job(ert, value): - jl = ert.enkf.site_config_get_installed_jobs(ert.site_config) - success = ert.job_queue.ext_joblist_del_job(jl, value.name) + jl = ert.main.site_config.get_installed_jobs + success = jl.del_job(value.name) if not success: QtGui.QMessageBox.question(parent, "Failed", "Unable to delete job!", QtGui.QMessageBox.Ok) return False return True - + r.getter = get_jobs + r.initialize = get_jobs r.setter = update_job r.insert = add_job r.remove = remove_job @@ -146,12 +159,14 @@ def createSystemPage(configPanel, parent): configPanel.addRow(internalPanel) r = configPanel.addRow(PathChooser(parent, "Log file", "config/systemenv/log_file", True)) - r.getter = lambda ert : ert.util.log_get_filename(ert.logh) - r.setter = lambda ert, value : ert.util.log_reset_filename(ert.logh, value) + r.initialize = lambda ert: ert.main.logh.get_filename + r.getter = lambda ert : ert.main.logh.get_filename + r.setter = lambda ert, value : ert.main.logh.reopen(value) r = configPanel.addRow(ert_gui.widgets.spinnerwidgets.IntegerSpinner(parent, "Log level", "config/systemenv/log_level", 0, 1000)) - r.getter = lambda ert : ert.util.log_get_level(ert.logh) - r.setter = lambda ert, value : ert.util.log_set_level(ert.logh, value) + r.initialize = lambda ert : ert.main.logh.get_level + r.getter = lambda ert : ert.main.logh.get_level + r.setter = lambda ert, value : ert.main.logh.set_level( value) configPanel.endPage() diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/init/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert_gui/pages/init/CMakeLists.txt new file mode 100644 index 0000000000..f1b0339f60 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/init/CMakeLists.txt @@ -0,0 +1 @@ +add_python_package( "Python ert_gui.pages.init" ${PYTHON_INSTALL_PREFIX}/ert_gui/pages/init "__init__.py;initandcopy.py;initpanel.py" True) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/init/__init__.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/init/__init__.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/init/__init__.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/init/__init__.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/init/initandcopy.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/init/initandcopy.py similarity index 88% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/init/initandcopy.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/init/initandcopy.py index 092c4bd9f0..6573307996 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/init/initandcopy.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/init/initandcopy.py @@ -19,6 +19,9 @@ from ert_gui.widgets.helpedwidget import HelpedWidget from PyQt4 import QtGui, QtCore from ert_gui.widgets.util import resourceIcon, ListCheckPanel, ValidatedTimestepCombo, getItemsFromList from ert.ert.enums import ert_state_enum +from ert.util.stringlist import StringList +from ctypes import * +from ert.util.tvector import BoolVector class ParametersAndMembers(HelpedWidget): @@ -102,13 +105,14 @@ class ParametersAndMembers(HelpedWidget): def initializeCaseFromScratch(self, parameters, members): ert = self.getModel() - stringlist = ert.createStringList(parameters) + stringlist = StringList(parameters) for member in members: m = int(member.strip()) - ert.enkf.enkf_main_initialize_from_scratch(ert.main, stringlist, m , m) + ert.main.initialize_from_scratch(stringlist, m , m) + + stringlist.__del__ - ert.freeStringList(stringlist) def initializeCaseFromCase(self, selected_parameters, selected_members): ert = self.getModel() @@ -119,20 +123,18 @@ class ParametersAndMembers(HelpedWidget): source_case = str(self.sourceCase.currentText()) source_report_step = self.sourceReportStep.getSelectedValue() source_state = ert_state_enum.resolveName(str(self.sourceType.currentText())).value() - member_mask = ert.createBoolVector(self.membersList.count(), selected_members) + member_mask = BoolVector.active_mask(str(selected_members).strip('[]')) ranking_key = None - node_list = ert.createStringList(selected_parameters) + node_list = StringList(selected_parameters) - ert.enkf.enkf_main_initialize_from_existing__(ert.main, - source_case, + ert.main.initialize_from_existing__( source_case, source_report_step, source_state, member_mask, ranking_key, node_list) - ert.freeStringList(node_list) - ert.freeBoolVector(member_mask) + node_list.__del__ def copyEnsemble(self, selected_parameters, selected_members): ert = self.getModel() @@ -148,12 +150,11 @@ class ParametersAndMembers(HelpedWidget): target_report_step = self.targetReportStep.getSelectedValue() target_state = ert_state_enum.resolveName(str(self.targetType.currentText())).value() - member_mask = ert.createBoolVector(self.membersList.count(), selected_members) + member_mask = BoolVector.active_mask(str(selected_members).strip('[]')) ranking_key = None - node_list = ert.createStringList(selected_parameters) + node_list = StringList(selected_parameters) - ert.enkf.enkf_main_copy_ensemble(ert.main, - source_case, + ert.main.copy_ensemble( source_case, source_report_step, source_state, target_case, @@ -163,8 +164,7 @@ class ParametersAndMembers(HelpedWidget): ranking_key, node_list) - ert.freeStringList(node_list) - ert.freeBoolVector(member_mask) + node_list.__del__ def initializeOrCopy(self): selected_parameters = getItemsFromList(self.parametersList) @@ -227,25 +227,17 @@ class ParametersAndMembers(HelpedWidget): #enums from enkf_types.h PARAMETER = 1 DYNAMIC_STATE = 2 - keylist = ert.enkf.ensemble_config_alloc_keylist_from_var_type(ert.ensemble_config, PARAMETER ) + parameters = ert.main.ensemble_config.alloc_keylist_from_var_type( PARAMETER ) - parameters = ert.getStringList(keylist) - ert.freeStringList(keylist) + dynamicParameters = ert.main.ensemble_config.alloc_keylist_from_var_type( DYNAMIC_STATE ) - keylist = ert.enkf.ensemble_config_alloc_keylist_from_var_type(ert.ensemble_config, DYNAMIC_STATE ) - dynamicParameters = ert.getStringList(keylist) - ert.freeStringList(keylist) + members = ert.main.ens_size - members = ert.enkf.enkf_main_get_ensemble_size(ert.main) + fs = ert.main.get_fs + currentCase = ert.main.get_current_fs - fs = ert.enkf.enkf_main_get_fs(ert.main) - currentCase = "default" #ert.enkf.enkf_fs_get_read_dir(fs) - - #caseList = ert.enkf.enkf_fs_alloc_dirlist(fs) - #list = ert.getStringList(caseList) - #ert.freeStringList(caseList) - list = ["default"] - historyLength = ert.enkf.enkf_main_get_history_length(ert.main) + list = ert.main.alloc_caselist + historyLength = ert.main.get_history_length return {"parameters" : parameters, "dynamic_parameters" : dynamicParameters, diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/init/initpanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/init/initpanel.py similarity index 79% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/init/initpanel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/init/initpanel.py index 67289b9da6..c7d892b6c3 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/init/initpanel.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/init/initpanel.py @@ -20,7 +20,7 @@ from ert_gui.widgets.tablewidgets import KeywordList from ert_gui.widgets.validateddialog import ValidatedDialog import ert.ert.ertwrapper as ertwrapper from ert_gui.widgets.combochoice import ComboChoice - +from ert.enkf.enkf_fs import EnkfFs from ert_gui.widgets.helpedwidget import HelpedWidget from ert_gui.widgets.util import resourceIcon, createSeparator, may_take_a_long_time @@ -42,11 +42,8 @@ class InitPanel(QtGui.QFrame): def get_case_list(ert): - fs = ert.enkf.enkf_main_get_fs(ert.main) - caseList = ["default"] #ert.enkf.enkf_fs_alloc_dirlist(fs) - - list = caseList #ert.getStringList(caseList) - #ert.freeStringList(caseList) + fs = ert.main.get_fs + list = ert.main.alloc_caselist return list self.get_case_list = get_case_list # convenience: used by several functions @@ -75,16 +72,13 @@ class InitPanel(QtGui.QFrame): cases.addRemoveWidget.enableRemoveButton(False) #todo: add support for removal cases.list.setMaximumHeight(150) - cases.initialize = lambda ert : [ert.prototype("long enkf_main_get_fs(long)"), - ert.prototype("void enkf_main_select_case(long , char*)"), - ert.prototype("long enkf_fs_alloc_dirlist(long)")] def create_case(ert, cases): - fs = ert.enkf.enkf_main_get_fs(ert.main) + fs = ert.main.get_fs for case in cases: - if not ert.enkf.enkf_fs_has_dir(fs, case): - ert.enkf.enkf_fs_select_write_dir(fs, case, True) + if not ert.main.fs_exists(case): + ert.main.select_fs(case) break self.currentCase.updateList(self.get_case_list(ert)) @@ -92,6 +86,7 @@ class InitPanel(QtGui.QFrame): self.casesUpdated() cases.getter = self.get_case_list + cases.initialize = self.get_case_list cases.setter = create_case return cases @@ -103,17 +98,15 @@ class InitPanel(QtGui.QFrame): self.currentCase.combo.setMinimumWidth(150) def initialize_cases(ert): - ert.prototype("long enkf_main_get_fs(long)") - self.currentCase.updateList(self.get_case_list(ert)) self.currentCase.initialize = initialize_cases def get_current_case(ert): - fs = ert.enkf.enkf_main_get_fs(ert.main) + fs = ert.main.get_fs tmp = self.get_case_list(ert) - currentCase = tmp[0] #ert.enkf.enkf_fs_get_read_dir(fs) - #print "The selected case is: " + currentCase + currentCase = ert.main.get_current_fs + print "The selected case is: " + currentCase return currentCase self.currentCase.getter = get_current_case @@ -122,9 +115,11 @@ class InitPanel(QtGui.QFrame): def select_case(ert, case): case = str(case) if not case == "": - ert.enkf.enkf_main_select_case( ert.main , case ) + ert.main.user_select_fs( case ) self.casesUpdated() self.currentCase.setter = select_case return self.currentCase + + diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/CMakeLists.txt new file mode 100644 index 0000000000..137c02c8b7 --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/CMakeLists.txt @@ -0,0 +1 @@ +add_python_package( "Python ert_gui.pages.plot" ${PYTHON_INSTALL_PREFIX}/ert_gui/pages/plot "__init__.py;fetcher.py;plotconfig.py;plotfigure.py;plotpanel.py;plotsettings.py;plotview.py;zoomslider.py;ensemblefetcher.py;plotdata.py;plotgenerator.py;plotrenderer.py;plotsettingsxml.py;rftfetcher.py" True) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/__init__.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/__init__.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/__init__.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/__init__.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/ensemblefetcher.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/ensemblefetcher.py similarity index 70% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/ensemblefetcher.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/ensemblefetcher.py index 5e366ad39d..0e98043037 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/ensemblefetcher.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/ensemblefetcher.py @@ -22,9 +22,10 @@ import ert.ert.ertwrapper as ertwrapper import ert.ert.enums as enums from PyQt4.QtGui import QWidget, QFormLayout, QSpinBox, QComboBox from PyQt4.QtCore import SIGNAL -from ert.ert.erttypes import time_t +from ert.ert.erttypes import time_t, time_vector import numpy - +from ert.util.tvector import DoubleVector +import datetime class EnsembleFetcher(PlotDataFetcherHandler): """A data fetcher for ensemble parameters.""" @@ -36,60 +37,30 @@ class EnsembleFetcher(PlotDataFetcherHandler): self.keyword_configuration = KeywordConfigurationWidget() self.data_configuration = DataConfigurationWidget() - def emitter(): - self.emit(SIGNAL('dataChanged()')) + def initialize(self, ert): + self.initialized = True + def emitter(): + self.emit(SIGNAL('dataChanged()')) self.connect(self.field_configuration, SIGNAL('configurationChanged()'), emitter) self.connect(self.summary_configuration, SIGNAL('configurationChanged()'), emitter) self.connect(self.keyword_configuration, SIGNAL('configurationChanged()'), emitter) self.connect(self.data_configuration, SIGNAL('configurationChanged()'), emitter) - def initialize(self, ert): - - - ert.prototype("long enkf_main_get_fs(long)") - ert.prototype("int enkf_main_get_ensemble_size(long)") - ert.prototype("long enkf_main_iget_member_config(long, int)") - ert.prototype("void enkf_main_get_observations(long, char*, int, long*, double*, double*)") #main, user_key, *time, *y, *std - ert.prototype("int enkf_main_get_observation_count(long, char*)") - - ert.prototype("bool enkf_fs_has_node(long, long, int, int, int)") - ert.prototype("void enkf_fs_fread_node(long, long, int, int, int)") - - ert.prototype("long enkf_node_alloc(long)") - ert.prototype("void enkf_node_free(long)") - ert.prototype("double enkf_node_user_get(long, char*, bool*)") - - ert.prototype("double member_config_iget_sim_days(long, int, int)") - ert.prototype("time_t member_config_iget_sim_time(long, int, int)") - ert.prototype("int enkf_main_get_history_length(long)") - - - ert.prototype("long enkf_config_node_get_ref(long)") - ert.prototype("bool field_config_ijk_active(long, int, int, int)") - - ert.prototype("bool ecl_sum_has_general_var(long, char*)", lib=ert.ecl) - ert.prototype("int ecl_sum_get_general_var_index(long, char*)", lib=ert.ecl) - - ert.prototype("time_vector ecl_sum_alloc_time_vector(long, bool)", lib=ert.ecl) - ert.prototype("double_vector ecl_sum_alloc_data_vector(long, int, bool)", lib=ert.ecl) - - + + def isHandlerFor(self, ert, key): - return ert.enkf.ensemble_config_has_key(ert.ensemble_config, key) - + return ert.main.ensemble_config.has_key( key) def fetch(self, ert, key, parameter, data, comparison_fs): data.x_data_type = "time" - - fs = ert.enkf.enkf_main_get_fs(ert.main) - config_node = ert.enkf.ensemble_config_get_node(ert.ensemble_config, key) - node = ert.enkf.enkf_node_alloc(config_node) - comp_node = ert.enkf.enkf_node_alloc(config_node) - num_realizations = ert.enkf.enkf_main_get_ensemble_size(ert.main) - + fs = ert.main.get_fs + config_node = ert.main.ensemble_config.get_node(key) + node = config_node.alloc_node + comp_node = config_node.alloc_node + num_realizations = ert.main.ens_size + var_type_set = False user_data = parameter.getUserData() - if user_data is None: return False @@ -98,20 +69,28 @@ class EnsembleFetcher(PlotDataFetcherHandler): key_index = user_data['key_index'] if parameter.getType() == FieldModel.TYPE: - field_position = user_data['field_position'] - field_config = ert.enkf.enkf_config_node_get_ref(config_node) - if ert.enkf.field_config_ijk_active(field_config, field_position[0] - 1, field_position[1] - 1, field_position[2] - 1): + var_type = enums.enkf_var_type.PARAMETER + var_type_set = True + field_position = user_data['field_position'] + field_config = config_node.field_model + if field_config.ijk_active(field_position[0] - 1, field_position[1] - 1, field_position[2] - 1): key_index = "%i,%i,%i" % (field_position[0], field_position[1], field_position[2]) data.setKeyIndexIsIndex(True) else: return False + elif parameter.getType() == DataModel.TYPE: + var_type = enums.enkf_var_type.PARAMETER + var_type_set = True data_index = user_data['data_index'] key_index = "KEY:%d" % data_index data.setKeyIndexIsIndex(True) - data.setKeyIndex(key_index) + if not var_type_set: + var_type = enums.enkf_var_type.DYNAMIC_RESULT + + data.setKeyIndex(key_index) state_list = [user_data['state']] if state_list[0] == enums.ert_state_enum.BOTH: state_list = [enums.ert_state_enum.FORECAST, enums.ert_state_enum.ANALYZED] @@ -128,43 +107,48 @@ class EnsembleFetcher(PlotDataFetcherHandler): x_comp_time = data.x_comp_data[member] y_comp = data.y_comp_data[member] - member_config = ert.enkf.enkf_main_iget_member_config(ert.main, member) - stop_time = ert.enkf.enkf_main_get_history_length( ert.main ) - - for step in range(0, stop_time + 1): - for state in state_list: - if ert.enkf.enkf_fs_has_node(fs, config_node, step, member, state.value()): - sim_time = ert.enkf.member_config_iget_sim_time(member_config, step, fs) - ert.enkf.enkf_fs_fread_node(fs, node, step, member, state.value()) - valid = ertwrapper.c_int() - value = ert.enkf.enkf_node_user_get(node, key_index, ertwrapper.byref(valid)) - if valid.value == 1: - data.checkMaxMin(sim_time) - data.checkMaxMinY(value) - x_time.append(sim_time) - y.append(value) - #else: - # print "Not valid: ", key, member, step, key_index + stop_time = ert.main.get_history_length + for state in state_list: + start_time = 0 + if config_node.get_impl_type == SummaryModel.TYPE: + start_time = 1 + for step in range(start_time, stop_time): + time_map = fs.get_time_map + sim_time_as_c_int = time_map.iget(step) + sim_time_as_time_t = time_t(sim_time_as_c_int) + sim_time_as_ordinal = sim_time_as_time_t.datetime().toordinal() + valid = ertwrapper.c_double() + value = node.user_get(fs, key_index, step, member, state.value(), ertwrapper.byref(valid)) + if value == True: + data.checkMaxMin(sim_time_as_time_t) + data.checkMaxMinY(valid.value) + x_time.append(sim_time_as_ordinal) + y.append(valid.value) + #else: + #print "Not valid: ", key, member, step, key_index, value, state.value() + if not comparison_fs is None: - if ert.enkf.enkf_fs_has_node(comparison_fs, config_node, step, member, state.value()): - sim_time = ert.enkf.member_config_iget_sim_time(member_config, step, comparison_fs) - ert.enkf.enkf_fs_fread_node(comparison_fs, comp_node, step, member, state.value()) - valid = ertwrapper.c_int() - value = ert.enkf.enkf_node_user_get(comp_node, key_index, ertwrapper.byref(valid)) - if valid.value == 1: - #data.checkMaxMin(sim_time) - #data.checkMaxMinY(value) - x_comp_time.append(sim_time) - y_comp.append(value) - #else: - # print "Not valid: ", key, member, step, key_index - - data.x_data[member] = numpy.array([t.datetime() for t in x_time]) + time_map = comparison_fs.get_time_map + sim_time_as_c_int = time_map.iget(step) + sim_time_as_time_t = time_t(sim_time_as_c_int) + sim_time_as_ordinal = sim_time_as_time_t.datetime().toordinal() + valid = ertwrapper.c_double() + value = node.user_get(comparison_fs, key, step, member, state.value(), ertwrapper.byref(valid)) + if value == 1: + data.checkMaxMin(sim_time_as_time_t) + data.checkMaxMinY(valid.value) + x_comp_time.append(sim_time_as_ordinal) + y_comp.append(valid.value) + #else: + # print "Not valid: ", key, member, step, key_index + + + data.x_data[member] = numpy.array(x_time)#[t.datetime() for t in x_time]) data.y_data[member] = numpy.array(y) if not comparison_fs is None: - data.x_comp_data[member] = numpy.array([t.datetime() for t in x_comp_time]) + data.x_comp_data[member] = numpy.array(x_comp_time)#[t.datetime() for t in x_comp_time]) data.y_comp_data[member] = numpy.array(y_comp) @@ -172,8 +156,8 @@ class EnsembleFetcher(PlotDataFetcherHandler): self._getRefCase(ert, key, data) - ert.enkf.enkf_node_free(node) - ert.enkf.enkf_node_free(comp_node) + #node.__del__ + #comp_node.__del__ data.inverted_y_axis = False @@ -183,12 +167,12 @@ class EnsembleFetcher(PlotDataFetcherHandler): else: user_key = key - obs_count = ert.enkf.enkf_main_get_observation_count(ert.main, user_key) + obs_count = ert.main.get_observation_count(user_key) if obs_count > 0: obs_x = (time_t * obs_count)() obs_y = (ertwrapper.c_double * obs_count)() obs_std = (ertwrapper.c_double * obs_count)() - ert.enkf.enkf_main_get_observations(ert.main, user_key, obs_count, obs_x, obs_y, obs_std) + ert.main.get_observations(user_key, obs_count, obs_x, obs_y, obs_std) data.obs_x = numpy.array([t.datetime() for t in obs_x]) data.obs_y = numpy.array(obs_y) @@ -203,12 +187,13 @@ class EnsembleFetcher(PlotDataFetcherHandler): def _getRefCase(self, ert, key, data): - ecl_sum = ert.enkf.ecl_config_get_refcase(ert.ecl_config) + ecl_config = ert.main.ecl_config + ecl_sum = ecl_config.get_refcase - if(ert.ecl.ecl_sum_has_general_var(ecl_sum, key)): - ki = ert.ecl.ecl_sum_get_general_var_index(ecl_sum, key) - x_data = ert.ecl.ecl_sum_alloc_time_vector(ecl_sum, True) - y_data = ert.ecl.ecl_sum_alloc_data_vector(ecl_sum, ki, True) + if(ecl_sum.has_key(key)): + ki = ecl_sum.get_general_var_index(key) + x_data = ecl_sum.alloc_time_vector(True) + y_data = ecl_sum.alloc_data_vector(ki, True) data.refcase_x = [] data.refcase_y = [] @@ -216,7 +201,7 @@ class EnsembleFetcher(PlotDataFetcherHandler): for x in x_data: if not first: data.refcase_x.append(x) - data.checkMaxMin(x) + #data.checkMaxMin(x) else: first = False #skip first element because of eclipse behavior diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/fetcher.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/fetcher.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/fetcher.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/fetcher.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotconfig.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotconfig.py similarity index 97% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotconfig.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotconfig.py index efc16ac434..3e6f843d2c 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotconfig.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotconfig.py @@ -15,7 +15,7 @@ # for more details. -from PyQt4.QtCore import QObject, QSize +from PyQt4.QtCore import QObject, QSize, pyqtSignal from PyQt4.Qt import SIGNAL from PyQt4.QtGui import QFormLayout, QFrame, QComboBox, QHBoxLayout, QDoubleSpinBox, QWidget, QPainter, QColor, QColorDialog from PyQt4.QtGui import QCheckBox, QDialog @@ -40,6 +40,7 @@ class PlotConfig(object): def notify(self): """Tell all listeners that something has changed. Automatically called by setters.""" + #self.signal_handler.emit(plotConfigChanged) self.signal_handler.emit(SIGNAL('plotConfigChanged(PlotConfig)'), self) def get_name(self): @@ -120,17 +121,17 @@ class PlotConfig(object): picker = property(getPicker, setPicker, doc="Picker radius") - class PlotConfigPanel(QFrame): """A panel to interact with PlotConfig instances.""" plot_marker_styles = ["", ".", ",", "o", "*", "s", "+", "x", "p", "h", "H", "D", "d"] plot_line_styles = ["", "-", "--", "-.", ":"] + changed = pyqtSignal(object) + def __init__(self, plot_config): QFrame.__init__(self) self.plot_config = plot_config - self.connect(plot_config.signal_handler, SIGNAL('plotConfigChanged(PlotConfig)'), self._fetchValues) - + self.changed.connect( self._fetchValues ) layout = QFormLayout() layout.setRowWrapPolicy(QFormLayout.WrapLongRows) @@ -210,13 +211,12 @@ class PlotConfigPanel(QFrame): class ColorPicker(QWidget): """A widget that shows a colored box and pops up a color dialog.""" - color_dialog = QColorDialog() def __init__(self, plot_config): QWidget.__init__(self) self.plot_config = plot_config - + self.color_dialog = QColorDialog() size = 20 self.setMaximumSize(QSize(size, size)) self.setMinimumSize(QSize(size, size)) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotdata.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotdata.py similarity index 73% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotdata.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotdata.py index d5c9670b3a..9d43a79ee5 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotdata.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotdata.py @@ -54,8 +54,7 @@ class PlotDataFetcher(ContentModel, QObject): handler.initialize(ert) self.connect(handler, SIGNAL('dataChanged()'), self.__dataChanged) - ert.prototype("long enkf_main_mount_extra_fs(long, char*)") - ert.prototype("void enkf_fs_free(long)") + #@print_timing @@ -113,12 +112,12 @@ class PlotDataFetcher(ContentModel, QObject): ert = self.getModel() if self.fs_for_comparison_plots: - ert.enkf.enkf_fs_free(self.fs_for_comparison_plots) + fs_for_comparison_plots.__del__ self.fs_for_comparison_plots = None self.comparison_fs_name = "None" if not new_fs == "None": - self.fs_for_comparison_plots = ert.enkf.enkf_main_mount_extra_fs(ert.main, new_fs) + self.fs_for_comparison_plots = ert.main.get_alt_fs(new_fs, false, true) self.comparison_fs_name = new_fs self.__dataChanged() @@ -163,7 +162,7 @@ class PlotData: if self.x_min is None or self.x_max is None: self.x_min = value self.x_max = value - + self.x_min = min(value, self.x_min) self.x_max = max(value, self.x_max) @@ -225,34 +224,12 @@ class PlotData: class PlotContextDataFetcher(ContentModel): - observation_icon = resourceIcon("observation") def __init__(self): ContentModel.__init__(self) + self.observation_icon = resourceIcon("observation") def initialize(self, ert): - - ert.prototype("long enkf_config_node_get_impl_type(long)") - ert.prototype("long enkf_config_node_get_ref(long)") - - ert.prototype("long gen_kw_config_alloc_name_list(long)") - - ert.prototype("long gen_data_config_get_initial_size(long)") - - ert.prototype("int field_config_get_nx(long)") - ert.prototype("int field_config_get_ny(long)") - ert.prototype("int field_config_get_nz(long)") - - ert.prototype("long enkf_main_get_fs(long)") - ert.prototype("char* enkf_fs_get_read_dir(long)") - ert.prototype("long enkf_fs_alloc_dirlist(long)") - - ert.prototype("int plot_config_get_errorbar_max(long)") - ert.prototype("char* plot_config_get_path(long)") - - ert.prototype("long enkf_main_get_obs(long)") - ert.prototype("long enkf_obs_alloc_typed_keylist(long, int)") - self.modelConnect("casesUpdated()", self.fetchContent) @@ -260,14 +237,14 @@ class PlotContextDataFetcher(ContentModel): def getter(self, ert): data = PlotContextData() - keys = ert.getStringList(ert.enkf.ensemble_config_alloc_keylist(ert.ensemble_config), free_after_use=True) + keys = ert.main.ensemble_config.alloc_keylist data.keys = keys data.parameters = [] for key in keys: - config_node = ert.enkf.ensemble_config_get_node(ert.ensemble_config, key) - type = ert.enkf.enkf_config_node_get_impl_type(config_node) - node_ref = ert.enkf.enkf_config_node_get_ref(config_node) + config_node = ert.main.ensemble_config.get_node( key) + type = config_node.get_impl_type + node_ref = config_node.get_ref if type == SummaryModel.TYPE: p = Parameter(key, SummaryModel.TYPE) @@ -278,44 +255,42 @@ class PlotContextDataFetcher(ContentModel): data.parameters.append(p) if data.field_bounds is None: - x = ert.enkf.field_config_get_nx(node_ref) - y = ert.enkf.field_config_get_ny(node_ref) - z = ert.enkf.field_config_get_nz(node_ref) + x = config_node.field_model.get_nx + y = config_node.field_model.get_ny + z = config_node.field_model.get_nz data.field_bounds = (x,y,z) elif type == DataModel.TYPE: data.parameters.append(Parameter(key, DataModel.TYPE)) - data.gen_data_size = ert.enkf.gen_data_config_get_initial_size(node_ref) + data.gen_data_size = config_node.data_model.get_initial_size elif type == KeywordModel.TYPE: p = Parameter(key, KeywordModel.TYPE) data.parameters.append(p) - s = ert.enkf.gen_kw_config_alloc_name_list(node_ref) - data.key_index_list[key] = ert.getStringList(s, free_after_use=True) + s = config_node.keyword_model.alloc_name_list + data.key_index_list[key] = s - data.errorbar_max = ert.enkf.plot_config_get_errorbar_max(ert.plot_config) + data.errorbar_max = ert.main.plot_config.get_errorbar_max - fs = ert.enkf.enkf_main_get_fs(ert.main) - current_case = "default" #ert.enkf.enkf_fs_get_read_dir(fs) + fs = ert.main.get_fs + current_case = ert.main.get_current_fs - data.plot_config_path = ert.enkf.plot_config_get_path(ert.plot_config) - #data.plot_path = ert.enkf.plot_config_get_path(ert.plot_config) + "/" + current_case - data.plot_path = "PLOTXXX" + data.plot_config_path = ert.main.plot_config.get_path + data.plot_path = ert.main.plot_config.get_path + "/" + current_case - enkf_obs = ert.enkf.enkf_main_get_obs(ert.main) - key_list = ert.enkf.enkf_obs_alloc_typed_keylist(enkf_obs, obs_impl_type.FIELD_OBS.value()) - field_obs = ert.getStringList(key_list, free_after_use=True) + enkf_obs = ert.main.get_obs + key_list = enkf_obs.alloc_typed_keylist( obs_impl_type.FIELD_OBS.value()) - for obs in field_obs: - p = Parameter(obs, obs_impl_type.FIELD_OBS, PlotContextDataFetcher.observation_icon) + for obs in key_list: + p = Parameter(obs, obs_impl_type.FIELD_OBS, self.observation_icon) data.parameters.append(p) - #case_list_pointer = ert.enkf.enkf_fs_alloc_dirlist(fs) - #case_list = ert.getStringList(case_list_pointer) - case_list = ["default"] + + case_list = ert.main.alloc_caselist + data.current_case = current_case - #ert.freeStringList(case_list_pointer) + for case in case_list: data.case_list.append(case) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotfigure.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotfigure.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotfigure.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotfigure.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotgenerator.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotgenerator.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotgenerator.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotgenerator.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotpanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotpanel.py similarity index 97% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotpanel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotpanel.py index c2b23c770b..8f7fade950 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotpanel.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotpanel.py @@ -30,7 +30,7 @@ import matplotlib.dates from zoomslider import ZoomSlider from ert_gui.widgets.configpanel import ConfigPanel from PyQt4.Qt import SIGNAL -from PyQt4.QtCore import QDate, Qt, QPoint +from PyQt4.QtCore import QDate, Qt, QPoint , pyqtSignal from plotconfig import PlotConfigPanel from PyQt4.QtGui import QTabWidget, QFormLayout, QFrame, QVBoxLayout, QHBoxLayout, QCheckBox, QPushButton, QToolButton, QMainWindow from PyQt4.QtGui import QCalendarWidget @@ -38,6 +38,9 @@ import plotsettings import ert.ert.erttypes as erttypes class PlotPanel(QtGui.QWidget): + + changed = pyqtSignal() + def __init__(self): QtGui.QWidget.__init__(self) @@ -82,14 +85,15 @@ class PlotPanel(QtGui.QWidget): plotLayout.addLayout(plot_view_layout) self.plotViewSettings = PlotViewSettingsPanel(plotView=self.plot, width=250) - self.connect(self.plotViewSettings, QtCore.SIGNAL('comparisonCaseSelected(String)'), self.plotDataFetcher.updateComparisonFS) + self.connect(self.plotViewSettings, QtCore.SIGNAL('comparisonCaseSelected(QString)'), self.plotDataFetcher.updateComparisonFS) plotLayout.addWidget(self.plotViewSettings) self.setLayout(plotLayout) - self.connect(self.plot.plot_settings, QtCore.SIGNAL('plotSettingsChanged(PlotSettings)'), self.fetchSettings) - + self.changed.connect( self.fetchSettings ) + #self.connect(self.plot.plot_settings, QtCore.SIGNAL('plotSettingsChanged(PlotSettings)'), self.fetchSettings) ContentModel.modelConnect('casesUpdated()', self.updateList) + def drawPlot(self): self.plot.setData(self.plotDataFetcher.data) @@ -175,12 +179,12 @@ class PlotViewSettingsPanel(QtGui.QFrame): for plot_config in plot_configs: config_panel = PlotConfigPanel(plot_config) tabbed_panel.addTab(config_panel, plot_config.name) - #self.connect(config_panel, SIGNAL('plotConfigChanged()'), self.plotView.drawPlot) + self.connect(config_panel, SIGNAL('plotConfigChanged()'), self.plotView.drawPlot) layout.addWidget(tabbed_panel) tabbed_panel = QTabWidget() - #tabbed_panel.setTabPosition(QTabWidget.West) + tabbed_panel.setTabPosition(QTabWidget.West) tabbed_panel.addTab(self.createMemberSelectionPanel(), "Members") tabbed_panel.addTab(self.createPlotRangePanel(), "Plot") diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotrenderer.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotrenderer.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotrenderer.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotrenderer.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotsettings.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotsettings.py similarity index 98% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotsettings.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotsettings.py index 4b58fb0587..01d1fcb878 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotsettings.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotsettings.py @@ -19,7 +19,7 @@ from plotconfig import PlotConfig import matplotlib from ert.ert.erttypes import time_t import datetime -from PyQt4.QtCore import QObject, SIGNAL +from PyQt4.QtCore import QObject, SIGNAL, pyqtSignal class PlotSettings(QObject): """ @@ -33,6 +33,8 @@ class PlotSettings(QObject): refcase_color = (0/255.0, 200/255.0, 0/255.0) # green comparison_color = (199/255.0, 63/255.0, 0/255.0) # orange + changed = pyqtSignal(object) + def __init__(self): QObject.__init__(self) @@ -64,9 +66,9 @@ class PlotSettings(QObject): self.std_plot_config, self.errorbar_plot_config, self.comparison_plot_config] - + for pc in self._plot_configs: - self.connect(pc.signal_handler, SIGNAL('plotConfigChanged(PlotConfig)'), self.notify) + self.changed.connect( self.notify ) self._plot_config_dict = {} for pc in self._plot_configs: diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotsettingsxml.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotsettingsxml.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotsettingsxml.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotsettingsxml.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotview.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotview.py similarity index 99% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotview.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotview.py index 5f74965471..5c1e12618a 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/plotview.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/plotview.py @@ -22,7 +22,7 @@ import time from ert.ert.erttypes import time_t from ert_gui.widgets.util import print_timing -from plotdata import PlotData +from ert_gui.pages.plot.plotdata import PlotData import ert_gui.widgets from PyQt4.QtCore import SIGNAL diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/rftfetcher.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/rftfetcher.py new file mode 100644 index 0000000000..de87e4860c --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/rftfetcher.py @@ -0,0 +1,164 @@ +# Copyright (C) 2011 Statoil ASA, Norway. +# +# The file 'rftfetcher.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + + +from fetcher import PlotDataFetcherHandler +import ert.ert.ertwrapper as ertwrapper +import ert.ert.enums as enums +from ert.ert.enums import ert_state_enum, obs_impl_type +import numpy + +class RFTFetcher(PlotDataFetcherHandler): + + def __init__(self): + PlotDataFetcherHandler.__init__(self) + + def initialize(self, ert): + self.initialized = True + + def isHandlerFor(self, ert, key): + enkf_obs = ert.main.get_obs + key_list = enkf_obs.alloc_typed_keylist(obs_impl_type.GEN_OBS.value()) + return key in key_list + + def fetch(self, ert, key, parameter, data, comparison_fs): + enkf_obs = ert.main.get_obs + obs_vector = enkf_obs.get_vector(key) + + num_active = obs_vector.get_num_active + if num_active == 1: + report_step = obs_vector.get_active_report_step + elif num_active > 1: + history_length = ert.main.get_history_length + active = [] + for index in range(history_length): + if obs_vector.iget_active(index): + active.append(index) + print "Active:", active + report_step = active[0] #todo: enable selection from GUI + else: + return + + fs = ert.main.get_fs + state_kw = obs_vector.get_state_kw + + ens_size = ert.main.get_ensemble_size + + config_node = ert.main.ensemble_config.get_node(state_kw) + field_config = config_node.get_ref + block_obs = obs_vector.iget_node(report_step) + + obs_size = block_obs.get_size + grid = field_config.get_grid + + node = config_node.alloc_node + + y_obs = [] + x_obs = [] + x_std = [] + xpos = (ertwrapper.c_double)() + ypos = (ertwrapper.c_double)() + zpos = (ertwrapper.c_double)() + value = (ertwrapper.c_double)() + std = (ertwrapper.c_double)() + for index in range(obs_size): + grid.get_xyz3(block_obs.iget_i(index),block_obs.iget_j(index),block_obs.iget_k(index), xpos, ypos , zpos) + y_obs.append(zpos.value) + block_obs.iget(index, value, std) + x_obs.append(value.value) + x_std.append(std.value) + data.checkMaxMin(value.value + std.value) + data.checkMaxMin(value.value - std.value) + data.obs_y = numpy.array(y_obs) + data.obs_x = numpy.array(x_obs) + data.obs_std_x = numpy.array(x_std) + data.obs_std_y = None + var_type = enums.enkf_var_type.DYNAMIC_RESULT + + for member in range(ens_size): + if node.vector_storage: + if fs.has_vector(config_node, member, ert_state_enum.ANALYZED.value()): + fs.fread_vector(node, member, ert_state_enum.ANALYZED.value()) + elif fs.has_vector(config_node, member, ert_state_enum.FORECAST.value()): + fs.fread_vector(node, member, ert_state_enum.FORECAST.value()) + else: + print "No data found for member %d/%d." % (member, report_step) + continue + else: + if fs.has_node(config_node, var_type, report_step, member, ert_state_enum.ANALYZED.value()): + fs.fread_node(node, var_type, report_step, member, ert_state_enum.ANALYZED.value()) + elif fs.has_node(config_node, var_type, report_step, member, ert_state_enum.FORECAST.value()): + fs.fread_node(node, var_type, report_step, member, ert_state_enum.FORECAST.value()) + else: + print "No data found for member %d/%d." % (member, report_step) + continue + + data.x_data[member] = [] + data.y_data[member] = [] + x_data = data.x_data[member] + y_data = data.y_data[member] + + field = node.value_ptr + for index in range(obs_size): + value = field.ijk_get_double(i[index] , j[index] , k[index]) + x_data.append(value) + y_data.append(y_obs[index]) + data.checkMaxMin(value) + + data.x_data[member] = numpy.array(x_data) + data.y_data[member] = numpy.array(y_data) + + if not comparison_fs is None: + comp_node = config_node.alloc + for member in range(ens_size): + if comparison_fs.has_node(config_node, report_step, member, ert_state_enum.ANALYZED.value()): + comparison_fs.fread_node(comp_node, report_step, member, ert_state_enum.ANALYZED.value()) + elif comparison_fs.has_node(config_node, report_step, member, ert_state_enum.FORECAST.value()): + comparison_fs.fread_node(comp_node, report_step, member, ert_state_enum.FORECAST.value()) + else: + print "No data found for member %d/%d." % (member, report_step) + continue + + data.x_comp_data[member] = [] + data.y_comp_data[member] = [] + x_data = data.x_comp_data[member] + y_data = data.y_comp_data[member] + + field = ert.enkf.enkf_node_value_ptr(comp_node) + for index in range(obs_size): + value = field.ijk_get_double(block_obs.iget_i(index),block_obs.iget_j(index),block_obs.iget_k(index)) + x_data.append(value) + y_data.append(y_obs[index]) + data.checkMaxMin(value) + + data.x_comp_data[member] = numpy.array(x_data) + data.y_comp_data[member] = numpy.array(y_data) + + comp_node.free + + node.free + + data.x_data_type = "number" + data.inverted_y_axis = True + + def getConfigurationWidget(self, context_data): + return None + + def configure(self, parameter, context_data): + pass #nothing to configure, yet + + + diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/zoomslider.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/zoomslider.py similarity index 98% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/zoomslider.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/zoomslider.py index d33162c698..72fd79558c 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/plot/zoomslider.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/plot/zoomslider.py @@ -190,7 +190,6 @@ class ZoomSlider(QFrame): if self.max_value > 1.0: self.max_value = 1 - #print "max:", self.min_value, self.max_value self.emit(SIGNAL('zoomValueChanged(float, float)'), self.min_value, self.max_value) @@ -213,7 +212,6 @@ class ZoomSlider(QFrame): if self.min_value < 0.0: self.min_value = 0.0 - #print "min:", self.min_value, self.max_value self.emit(SIGNAL('zoomValueChanged(float, float)'), self.min_value, self.max_value) diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/CMakeLists.txt new file mode 100644 index 0000000000..4594781ddb --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/CMakeLists.txt @@ -0,0 +1 @@ +add_python_package( "Python ert_gui.pages.run" ${PYTHON_INSTALL_PREFIX}/ert_gui/pages/run "__init__.py;runpanel.py;simulation.py;simulationsdialog.py;legend.py" True) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/run/__init__.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/__init__.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/run/__init__.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/run/__init__.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/run/legend.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/legend.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/run/legend.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/run/legend.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/run/runpanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/runpanel.py similarity index 90% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/run/runpanel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/run/runpanel.py index dfc44d7eb0..30e1f923bd 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/run/runpanel.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/runpanel.py @@ -30,7 +30,7 @@ from simulationsdialog import SimulationsDialog class RunWidget(HelpedWidget): """A widget that shows simulation parameters and the possibility to start the simulation""" - run_mode_type = {"ENKF_ASSIMILATION" : 1, "ENSEMBLE_EXPERIMENT" : 2, "ENSEMBLE_PREDICTION" : 3, "INIT_ONLY" : 4} + run_mode_type = {"ENKF_ASSIMILATION" : 1, "ENSEMBLE_EXPERIMENT" : 2, "ENSEMBLE_PREDICTION" : 3, "INIT_ONLY" : 4, "SMOOTHER" : 5} state_enum = {"UNDEFINED" : 0, "SERIALIZED" : 1, "FORECAST" : 2, "ANALYZED" : 4, "BOTH" : 6} def __init__(self, parent=None): @@ -40,8 +40,9 @@ class RunWidget(HelpedWidget): self.modelConnect("ensembleResized()", self.fetchContent) self.modelConnect("runpathChanged()", self.fetchContent) - #self.rbAssimilation.toggle() - self.rbExperiment.toggle() + self.rbAssimilation.toggle() + #self.rbExperiment.toggle() + #self.rbSmoother.toggle() def createPanel(self, parent): """Creates the panel with the simulation parameters.""" @@ -114,11 +115,9 @@ class RunWidget(HelpedWidget): QtGui.QMessageBox.warning(self, "Missing data", "At least one member must be selected!") return - member_mask = ert.createBoolVector(self.membersList.count(), selectedMembers) - if not ert.enkf.enkf_main_is_initialized(ert.main, member_mask): + if not ert.main.is_initialized: QtGui.QMessageBox.warning(self, "Case not initialized", "The case must be initialized before simulation can start!") return - ert.freeBoolVector(member_mask) simFrom = self.simulateFrom.getSelectedValue() @@ -126,11 +125,13 @@ class RunWidget(HelpedWidget): if self.rbAssimilation.isChecked(): mode = self.run_mode_type["ENKF_ASSIMILATION"] - else: + if self.rbExperiment.isChecked(): if simTo == -1: # -1 == End mode = self.run_mode_type["ENSEMBLE_PREDICTION"] else: mode = self.run_mode_type["ENSEMBLE_EXPERIMENT"] + if self.rbSmoother.isChecked(): + mode = self.run_mode_type["SMOOTHER"] state = self.state_enum["ANALYZED"] if self.startState.currentText() == "Forecast" and not simFrom == 0: @@ -183,18 +184,12 @@ class RunWidget(HelpedWidget): self.membersList.selectAll() - def initialize(self, ert): - """Prototype functions""" - ert.prototype("int enkf_main_get_ensemble_size(long)") - ert.prototype("int enkf_main_get_history_length(long)") - ert.prototype("char* model_config_get_runpath_as_char(long)") - ert.prototype("bool enkf_main_is_initialized(long)") def getter(self, ert): """Fetch data from EnKF. Such as number of realizations, runpath and number of timesteps.""" - members = ert.enkf.enkf_main_get_ensemble_size(ert.main) - historyLength = ert.enkf.enkf_main_get_history_length(ert.main) - runpath = ert.enkf.model_config_get_runpath_as_char(ert.model_config) + members = ert.main.ens_size + historyLength = ert.main.get_history_length + runpath = ert.main.model_config.get_runpath_as_char return {"members" : range(members), "history_length" : historyLength, "runpath" : runpath} @@ -210,17 +205,19 @@ class RunWidget(HelpedWidget): def createRadioButtons(self): """Create a toggle between assimilation and experiment.""" radioLayout = QtGui.QVBoxLayout() - radioLayout.setSpacing(2) + radioLayout.setSpacing(3) self.rbExperiment = QtGui.QRadioButton("Ensemble experiment") radioLayout.addWidget(self.rbExperiment) self.rbAssimilation = QtGui.QRadioButton("EnKF assimilation") radioLayout.addWidget(self.rbAssimilation) - + self.rbSmoother = QtGui.QRadioButton("Smoother") + radioLayout.addWidget(self.rbSmoother) self.connect(self.rbAssimilation , QtCore.SIGNAL('toggled(bool)'), lambda : self.rbToggle()) self.connect(self.rbExperiment , QtCore.SIGNAL('toggled(bool)'), lambda : self.rbToggle()) - + self.connect(self.rbSmoother , QtCore.SIGNAL('toggled(bool)'), lambda : self.rbToggle()) + return radioLayout diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/run/simulation.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulation.py similarity index 91% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/run/simulation.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulation.py index 25b3b57d70..c9fa8ce5b2 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/run/simulation.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulation.py @@ -314,18 +314,9 @@ class SimulationPanelController: self.selectedSimulations = [] self.view.connect(self.view, QtCore.SIGNAL('simulationsUpdated()'), self.showSelectedSimulations) + def initialize(self, ert): - """Set prototypes for ERT""" if not self.initialized: - ert.prototype("bool job_queue_get_pause(long)", lib = ert.job_queue) - ert.prototype("void job_queue_set_pause_on(long)", lib = ert.job_queue) - ert.prototype("void job_queue_set_pause_off(long)", lib = ert.job_queue) - ert.prototype("void job_queue_user_exit(long)", lib = ert.job_queue) - ert.prototype("long enkf_main_iget_state(long, int)") - ert.prototype("void enkf_state_kill_simulation(long)") - ert.prototype("void enkf_state_resubmit_simulation(long, int)") - ert.prototype("int enkf_state_get_run_status(long)") - ert.prototype("long site_config_get_job_queue(long)") self.initialized = True def setModel(self, ert): @@ -336,39 +327,40 @@ class SimulationPanelController: def kill(self): """Kills the selected simulations.""" for simulation in self.selectedSimulations: - state = self.ert.enkf.enkf_main_iget_state(self.ert.main, simulation.name) - status = self.ert.enkf.enkf_state_get_run_status(state) + state = self.ert.main.iget_state(simulation.name) + status = state.get_run_status #if status == Simulation.RUNNING: - self.ert.enkf.enkf_state_kill_simulation(state) + state.kill_simulation def restart(self, resample): """Restarts the selected simulations. May also resample.""" for simulation in self.selectedSimulations: - state = self.ert.enkf.enkf_main_iget_state(self.ert.main, simulation.name) - status = self.ert.enkf.enkf_state_get_run_status(state) + state = self.ert.main.iget_state(simulation.name) + status = state.get_run_status #if status == Simulation.USER_KILLED: - self.ert.enkf.enkf_state_resubmit_simulation(state , resample) + state.resubmit_simulation(resample) def pause(self, pause): """Pause the job queue after the currently running jobs are finished.""" - job_queue = self.ert.enkf.site_config_get_job_queue(self.ert.site_config) + job_queue = self.ert.main.site_config.get_job_queue() if pause: self.statistics.stop() - self.ert.job_queue.job_queue_set_pause_on(job_queue) + job_queue.set_pause_on else: self.statistics.startTiming() - self.ert.job_queue.job_queue_set_pause_off(job_queue) + job_queue.set_pause_off def killAll(self): """Kills all simulations""" killAll = QtGui.QMessageBox.question(self.view, "Remove all jobs?", "Are you sure you want to remove all jobs from the queue?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) if killAll == QtGui.QMessageBox.Yes: - job_queue = self.ert.enkf.site_config_get_job_queue(self.ert.site_config) - self.ert.job_queue.job_queue_user_exit(job_queue) + job_queue = self.ert.main.site_config.get_job_queue( ) + job_queue.user_exit( ) + def showSelectedSimulations(self): """Update information relating to a single job""" @@ -452,7 +444,7 @@ class Simulation: def hasFailed(self): """Has the job failed?""" - return self.checkStatus(ert_job_status_type.ALL_FAIL) + return self.checkStatus(ert_job_status_type.FAILED) def notActive(self): """Is the job active?""" @@ -460,7 +452,7 @@ class Simulation: def finishedSuccessfully(self): """Has the job finished?""" - return self.checkStatus(ert_job_status_type.ALL_OK) + return self.checkStatus(ert_job_status_type.SUCCESS) def isUserKilled(self): """Has the job been killed by the user?""" @@ -472,7 +464,7 @@ class Simulation: if len(self.statuslog) == 0 or not self.statuslog[len(self.statuslog) - 1] == status: self.statuslog.append(status) - if status == ert_job_status_type.ALL_OK: + if status == ert_job_status_type.SUCCESS: self.setFinishedTime(int(time.time())) self.status = status diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/run/simulationsdialog.py b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulationsdialog.py similarity index 90% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/run/simulationsdialog.py rename to ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulationsdialog.py index 9f41bd57b6..250571ae91 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/pages/run/simulationsdialog.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/pages/run/simulationsdialog.py @@ -25,6 +25,7 @@ import time from ert_gui.widgets.util import getItemsFromList from ert.ert.enums import ert_job_status_type from PyQt4.QtGui import QApplication +from ert.util.tvector import BoolVector class SimulationsDialog(QtGui.QDialog): """A dialog that shows the progress of a simulation""" @@ -99,7 +100,7 @@ class SimulationsDialog(QtGui.QDialog): selectAll = self._createAction("Select all", self.simulationList.selectAll) unselectAll = self._createAction("Unselect all", self.simulationList.clearSelection) selectRunning = self._createAction("Select all running", lambda : self.ctrl.select(ert_job_status_type.RUNNING)) - selectFailed = self._createAction("Select all failed", lambda : self.ctrl.select(ert_job_status_type.ALL_FAIL)) + selectFailed = self._createAction("Select all failed", lambda : self.ctrl.select(ert_job_status_type.FAILED)) selectUserKilled = self._createAction("Select all user killed", lambda : self.ctrl.select(ert_job_status_type.USER_KILLED)) selectWaiting = self._createAction("Select all waiting", lambda : self.ctrl.select(ert_job_status_type.WAITING, ert_job_status_type.PENDING)) @@ -159,17 +160,10 @@ class SimulationsDialogController: selection = getItemsFromList(self.view.simulationList, lambda item : item.simulation) self.view.simulationPanel.setSimulations(selection) - def initialize(self, ert): - """Protoype ERT functions""" if not self.initialized: - ert.prototype("long enkf_main_iget_state(long, int)") - ert.prototype("int enkf_state_get_run_status(long)") - ert.prototype("long site_config_queue_is_running(long)") - ert.prototype("long enkf_state_get_start_time(long)") - ert.prototype("long enkf_state_get_submit_time(long)") self.initialized = True - + def start(self, **kwargs): """Start the simulation. Two threads are started one for the simulation and one for progress monitoring""" ert = kwargs["ert"] @@ -196,11 +190,8 @@ class SimulationsDialogController: self.runthread = threading.Thread(name="enkf_main_run") def run(): self.view.setRunningState(True) - boolVector = ert.createBoolVector(memberCount, selectedMembers) - boolPtr = ert.getBoolVectorPtr(boolVector) - - ert.enkf.enkf_main_run(ert.main, mode, boolPtr, init_step_parameter, simFrom, state) - ert.freeBoolVector(boolVector) + boolVector = BoolVector.active_mask(str(selectedMembers).strip('[]')) + ert.main.run(boolVector, init_step_parameter, simFrom, state, mode) self.view.setRunningState(False) self.runthread.setDaemon(True) @@ -209,21 +200,21 @@ class SimulationsDialogController: self.pollthread = threading.Thread(name="polling_thread") def poll(): - while not ert.enkf.site_config_queue_is_running(ert.site_config): + while not ert.main.site_config.queue_is_running: time.sleep(0.5) job_start_time = int(time.time()) while(self.runthread.isAlive()): for member in selectedMembers: - state = ert.enkf.enkf_main_iget_state( ert.main , member) - status = ert.enkf.enkf_state_get_run_status( state ) - + state = ert.main.iget_state(member) + status = state.get_run_status + simulations[member].simulation.setStatus(ert_job_status_type.resolveValue(status)) if not ert_job_status_type.NOT_ACTIVE == status: - start_time = ert.enkf.enkf_state_get_start_time(state) - submit_time = ert.enkf.enkf_state_get_submit_time(state) + start_time = state.get_start_time + submit_time = state.get_submit_time simulations[member].simulation.setStartTime(start_time) simulations[member].simulation.setSubmitTime(submit_time) diff --git a/ThirdParty/Ert/devel/python/python/ert_gui/widgets/CMakeLists.txt b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/CMakeLists.txt new file mode 100644 index 0000000000..95ee1e73ca --- /dev/null +++ b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/CMakeLists.txt @@ -0,0 +1,2 @@ +add_python_package( "Python ert_gui.widgets" ${PYTHON_INSTALL_PREFIX}/ert_gui/widgets "__init__.py;activelabel.py;checkbox.py;cogwheel.py;combochoice.py;configpanel.py;helpedwidget.py;help.py;pathchooser.py;reloadbutton.py;searchablelist.py;spinnerwidgets.py;stringbox.py;tablewidgets.py;util.py;validateddialog.py" True) + diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/__init__.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/__init__.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/__init__.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/__init__.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/activelabel.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/activelabel.py similarity index 96% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/activelabel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/activelabel.py index 56fd67d916..223fca5856 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/activelabel.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/activelabel.py @@ -44,4 +44,4 @@ class ActiveLabel(HelpedWidget): if self_get_from_model is None: self_get_from_model = "" - self.active_label.setText(self_get_from_model) + self.active_label.setText("%s" % self_get_from_model) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/checkbox.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/checkbox.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/checkbox.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/checkbox.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/cogwheel.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/cogwheel.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/cogwheel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/cogwheel.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/combochoice.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/combochoice.py similarity index 90% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/combochoice.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/combochoice.py index 93ff0d700f..6813e8e99a 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/combochoice.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/combochoice.py @@ -14,7 +14,7 @@ # See the GNU General Public License at # for more details. - +import sys from PyQt4 import QtGui, QtCore from helpedwidget import * @@ -54,7 +54,11 @@ class ComboChoice(HelpedWidget): break if not indexSet: - raise AssertionError("ComboBox can not be set to: " + str(newValue)) + self.combo.setCurrentIndex(0) + sys.stderr.write("AssertionError: ComboBox can not be set to: " + str(newValue) + "\n") + #raise AssertionError("ComboBox can not be set to: " + str(newValue)) + + def updateList(self, choiceList): """Replace the list of choices with the specified items""" diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/configpanel.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/configpanel.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/configpanel.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/configpanel.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/help.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/help.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/help.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/help.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/helpedwidget.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/helpedwidget.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/helpedwidget.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/helpedwidget.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/pathchooser.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/pathchooser.py similarity index 99% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/pathchooser.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/pathchooser.py index b9ee45750e..0c24134f26 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/pathchooser.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/pathchooser.py @@ -182,7 +182,7 @@ class PathChooser(HelpedWidget): path = self.getFromModel() if path is None: path = "" - - self.pathLine.setText(path) + + self.pathLine.setText("%s" % path) self.editing = False diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/reloadbutton.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/reloadbutton.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/reloadbutton.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/reloadbutton.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/searchablelist.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/searchablelist.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/searchablelist.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/searchablelist.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/spinnerwidgets.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/spinnerwidgets.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/spinnerwidgets.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/spinnerwidgets.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/stringbox.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/stringbox.py similarity index 98% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/stringbox.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/stringbox.py index 88384e4eee..71064308a5 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/stringbox.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/stringbox.py @@ -56,7 +56,7 @@ class StringBox(HelpedWidget): if self_get_from_model is None: self_get_from_model = "" - self.boxString.setText(self_get_from_model) + self.boxString.setText("%s" % self_get_from_model) diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/tablewidgets.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/tablewidgets.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/tablewidgets.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/tablewidgets.py diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/util.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/util.py similarity index 99% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/util.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/util.py index 128830af34..d6c42ebee4 100644 --- a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/util.py +++ b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/util.py @@ -22,7 +22,7 @@ import time # The variable @img_prefix should be set to point to a directory # containing icons and images. In the current implementation this # variable is set from the gert_main.py script. -img_prefix = None +img_prefix = "" def resourceIcon(name): """Load an image as an icon""" diff --git a/ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/validateddialog.py b/ThirdParty/Ert/devel/python/python/ert_gui/widgets/validateddialog.py similarity index 100% rename from ThirdParty/Ert/devel/libenkf/applications/ert_gui/lib/ert_gui/widgets/validateddialog.py rename to ThirdParty/Ert/devel/python/python/ert_gui/widgets/validateddialog.py diff --git a/ThirdParty/Ert/devel/python/test/CMakeLists.txt b/ThirdParty/Ert/devel/python/test/CMakeLists.txt index ddb67a7448..8c9e3f1146 100644 --- a/ThirdParty/Ert/devel/python/test/CMakeLists.txt +++ b/ThirdParty/Ert/devel/python/test/CMakeLists.txt @@ -1,22 +1,206 @@ -add_python_package("Python test" "${PYTHON_INSTALL_PREFIX}/test" "ecl_isosurf.py;enkf_test.py;ens_config_test.py;file_test.py;fortio_test.py;grav_test.py;grdecl_test.py;grid_test0.py;grid_test.py;import_test.py;job_test.py;kw_test.py;large_mem_test.py;latex_test.py;petrel_kw.py;poly_test.py;region_test.py;restart_test.py;rft_test.py;sched_test.py;stringlist_test.py;sum_test.py;test_all.py;test_fast.py;test_util.py;troll_test.py;util_test.py;ctest_run.py" OFF) +set(NFS_RUNPATH "" CACHE STRING "Disk area which is shared among cluster nodes and can be used as CWD for LSF/RSH jobs.") +set(RSH_SERVERS "" CACHE STRING "List of nodes which will be used to test the RSH driver") -add_test( NAME python.import_all WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} import_test ) +set(TEST_SOURCES + ert_tests/__init__.py + ert_tests/run_tests.py + ert_tests/test_ert_import.py + ert_tests/test_ert_gui_import.py -add_test( NAME python.ert.util.stringlist WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} stringlist_test ) + ert_tests/config/__init__.py + ert_tests/config/test_config.py -add_test( NAME python.ert.ecl.ecl_grid WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} grid_test ) -add_test( NAME python.ert.ecl.ecl_kw WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} kw_test ) -add_test( NAME python.ert.ecl.ecl_sum WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} sum_test ) -add_test( NAME python.ert.ecl.ecl_file WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} file_test False) -add_test( NAME python.ert.ecl.ecl_file_slow WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} file_test True) + ert_tests/ecl/__init__.py + ert_tests/ecl/test_ecl_default.py + ert_tests/ecl/test_ecl_file.py + ert_tests/ecl/test_ecl_submit.py + ert_tests/ecl/test_fortio.py + ert_tests/ecl/test_grdecl.py + ert_tests/ecl/test_grid.py + ert_tests/ecl/test_kw.py + ert_tests/ecl/test_legacy_ecl.py + ert_tests/ecl/test_region.py + ert_tests/ecl/test_restart.py + ert_tests/ecl/test_rft.py + ert_tests/ecl/test_rft_cell.py + ert_tests/ecl/test_sum.py + + ert_tests/sched/__init__.py + ert_tests/sched/test_sched.py + + ert_tests/util/__init__.py + ert_tests/util/test_ctime.py + ert_tests/util/test_lookup_table.py + ert_tests/util/test_matrix.py + ert_tests/util/test_stat.py + ert_tests/util/test_string_list.py + ert_tests/util/test_vectors.py + + ecl_isosurf.py + enkf_test.py + ens_config_test.py + grav_test.py + grid_test0.py + job_test.py + petrel_kw.py + poly_test.py + troll_test.py + ctest_run.py +) + + +add_python_package("Python test" "${PYTHON_INSTALL_PREFIX}/test" "${TEST_SOURCES}" True) + +# The test data is located in the current source directory; that is +# the reason we set that as the working directory for the test +# run. The module to import should then be in the default python +# module search path (i.e. current directory), whereas the location of +# the actual ert package is given by the first argument to ctest. + +add_test( NAME python.ert.import_all_ert + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.test_ert_import.ErtImportTest ) + +add_test( NAME python.ert.import_all_ert_gui + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.test_ert_gui_import.ErtGuiImportTest ) + + +#UTIL + +add_test( NAME python.ert.util.stringlist + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_string_list.StringListTest ) + +add_test( NAME python.ert.util.tvector + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_vectors.UtilTest ) + +add_test( NAME python.ert.util.ctime + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_ctime.CTimeTest) + +add_test( NAME python.ert.util.latex + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_latex.LatexTest ) + +add_test( NAME python.ert.util.lookup_table + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_lookup_table.LookupTableTest ) + +add_test( NAME python.ert.util.matrix + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_matrix.MatrixTest ) + +add_test( NAME python.ert.util.stat + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.util.test_stat.StatTest ) + + +#ECL + + +add_test( NAME python.ert.ecl.ecl_default + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_ecl_default.EclDefaultTest ) + +add_test( NAME python.ert.ecl.ecl_file + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_ecl_file.FileTest) + +add_test( NAME python.ert.ecl.ecl_queue_LOCAL + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_ecl_submit.LocalSubmitTest ) + +if (NOT ${NFS_RUNPATH} STREQUAL "") + add_test( NAME python.ert.ecl.ecl_queue_LSF + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_ecl_submit.LSFSubmitTest ${NFS_RUNPATH} ) + set_property( TEST python.ert.ecl.ecl_queue_LSF PROPERTY LABELS Python:StatoilData:Slow ) + + if (NOT ${RSH_SERVERS} STREQUAL "") + add_test( NAME python.ert.ecl.ecl_queue_RSH + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_ecl_submit.RSHSubmitTest ${NFS_RUNPATH} ${RSH_SERVERS}) + set_property( TEST python.ert.ecl.ecl_queue_RSH PROPERTY LABELS Python:StatoilData:Slow ) + endif() +endif() + + +add_test( NAME python.ert.ecl.fortio + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_fortio.FortIOTest) + + +add_test( NAME python.ert.ecl.ecl_grdecl + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_grdecl.GRDECLTest ) + +add_test( NAME python.ert.ecl.ecl_grid + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_grid.GridTest ) + +add_test( NAME python.ert.ecl.ecl_kw + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_kw.KWTest ) + +add_test( NAME python.ert.ecl.legacy_ecl + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_legacy_ecl.LegacyEclTest) + +add_test( NAME python.ert.ecl.ecl_restart + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_restart.RestartTest) + +add_test( NAME python.ert.ecl.ecl_region + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_region.RegionTest) + +add_test( NAME python.ert.ecl.ecl_rft + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_rft.RFTTest) + +add_test( NAME python.ert.ecl.ecl_rft_cell + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_rft_cell.RFTCellTest) + +add_test( NAME python.ert.ecl.ecl_sum + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.ecl.test_sum.SumTest) -set_property( TEST python.ert.ecl.ecl_file PROPERTY LABELS Python:Statoil ) -set_property( TEST python.ert.ecl.ecl_file_slow PROPERTY LABELS Python:Statoil:Slow ) -set_property( TEST python.ert.ecl.ecl_sum PROPERTY LABELS Python:Statoil ) -set_property( TEST python.ert.ecl.ecl_kw PROPERTY LABELS Python:Statoil ) -set_property( TEST python.ert.ecl.ecl_grid PROPERTY LABELS Python:Statoil:Slow ) -set_property( TEST python.import_all PROPERTY LABELS Python ) -set_property( TEST python.ert.util.stringlist PROPERTY LABELS Python ) +#SCHED +add_test( NAME python.ert.sched.sched + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.sched.test_sched.SchedFileTest) + +#CONFIG +add_test( NAME python.ert.config + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND ctest_run.py ${PROJECT_BINARY_DIR}/${PYTHON_INSTALL_PREFIX} ert_tests.config.test_config.ConfigTest) + + + + +set_property( TEST python.ert.sched.sched PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.fortio PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_grdecl PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_restart PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_region PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_file PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_queue_LOCAL PROPERTY LABELS Python:StatoilData:Slow ) +set_property( TEST python.ert.ecl.ecl_sum PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_kw PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_rft PROPERTY LABELS Python:StatoilData ) +set_property( TEST python.ert.ecl.ecl_grid PROPERTY LABELS Python:StatoilData:Slow ) +#set_property( TEST python.import_local PROPERTY LABELS Python:StatoilBuild ) + +set_property( TEST python.ert.import_all_ert PROPERTY LABELS Python) +set_property( TEST python.ert.import_all_ert_gui PROPERTY LABELS Python) +set_property( TEST python.ert.util.stringlist PROPERTY LABELS Python ) +set_property( TEST python.ert.util.tvector PROPERTY LABELS Python ) +#set_property( TEST python.ert.import_all_ert PROPERTY ENVIRONMENT "ERT_SHARE_PATH=${PROJECT_SOURCE_PATH}/share") +set_property( TEST python.ert.import_all_ert_gui PROPERTY ENVIRONMENT "ERT_SHARE_PATH=${PROJECT_SOURCE_PATH}/share") + diff --git a/ThirdParty/Ert/devel/python/test/config_test.py b/ThirdParty/Ert/devel/python/test/config_test.py deleted file mode 100644 index 3086b4f0cf..0000000000 --- a/ThirdParty/Ert/devel/python/test/config_test.py +++ /dev/null @@ -1,101 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'config_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import os -import unittest -import stat -import math -import ert -import ert.ecl.ecl as ecl -import ert.config.config as config -import ert.config.config_enums as config_enums - -import sys -from test_util import * - - - -class ConfigTest( unittest.TestCase ): - - def setUp( self ): - self.file_list = [] - - - def test_enums(self): - self.assertTrue( config_enums.content_type.CONFIG_STRING ) - self.assertTrue( config_enums.content_type.CONFIG_INVALID ) - self.assertTrue( config_enums.unrecognized.CONFIG_UNRECOGNIZED_ERROR ) - - - - def test_parse(self): - conf = config.ConfigParser() - conf.add("FIELD" , False) - schema_item = conf.add("RSH_HOST" , False) - self.assertTrue( isinstance( schema_item , config.SchemaItem )) - self.assertTrue( conf.parse("test-data/local/config/simple_config" , unrecognized = config_enums.unrecognized.CONFIG_UNRECOGNIZED_IGNORE) ) - - - content_item = conf["RSH_HOST"] - self.assertTrue( isinstance( content_item , config.ContentItem )) - self.assertTrue( conf["BJARNE"] is None ) - - self.assertTrue( len(content_item) == 1) - self.assertRaises( ValueError , content_item.__getitem__ , "BJARNE") - self.assertRaises( IndexError , content_item.__getitem__ , 10 ) - - content_node = content_item[0] - self.assertTrue( isinstance( content_node , config.ContentNode )) - - self.assertTrue( len(content_node) == 2) - self.assertRaises( ValueError , content_node.__getitem__ , "BJARNE") - self.assertRaises( IndexError , content_node.__getitem__ , 10 ) - self.assertTrue( content_node[1] == "be-lx633214:2") - - self.assertTrue( content_node.content( sep = ",") == "be-lx655082:2,be-lx633214:2") - self.assertTrue( content_node.content( ) == "be-lx655082:2 be-lx633214:2") - - - content_item = conf["FIELD"] - self.assertTrue( len(content_item) == 5) - self.assertRaises(IOError , config.ConfigParser.parse , conf , "DoesNotExits") - - - - def test_schema(self): - schema_item = config.SchemaItem("TestItem") - self.assertTrue( isinstance( schema_item , config.SchemaItem )) - self.assertTrue( schema_item.iget_type( 6 ) == config_enums.content_type.CONFIG_STRING ) - schema_item.iset_type( 0 , config_enums.content_type.CONFIG_INT ) - self.assertTrue( schema_item.iget_type( 0 ) == config_enums.content_type.CONFIG_INT ) - schema_item.set_argc_minmax( 3 , 6) - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( ConfigTest( 'test_enums' )) - suite.addTest( ConfigTest( 'test_schema' )) - suite.addTest( ConfigTest( 'test_parse' )) - return suite - - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - - diff --git a/ThirdParty/Ert/devel/python/test/ctest_run.py b/ThirdParty/Ert/devel/python/test/ctest_run.py index 3a92296e4d..7710d86349 100644 --- a/ThirdParty/Ert/devel/python/test/ctest_run.py +++ b/ThirdParty/Ert/devel/python/test/ctest_run.py @@ -1,40 +1,43 @@ #!/usr/bin/env python import sys -import os -import unittest +from unittest2 import TextTestRunner +from ert_tests.run_tests import getTestsFromTestClass -def run_suite( test_suite ): - test_result = unittest.TextTestRunner(verbosity = 0).run( test_suite ) - if test_result.errors: - for (test , trace_back) in test_result.errors: + +def runTestCase(tests): + test_result = TextTestRunner(verbosity=0).run(tests) + if test_result.errors or test_result.failures: + for (test, trace_back) in test_result.errors: sys.stderr.write("=================================================================\n") - sys.stderr.write("Test:%s failed \n" % test.id()) + sys.stderr.write("Test:%s error \n" % test.id()) sys.stderr.write("%s\n" % trace_back) + + for (test, trace_back) in test_result.failures: + sys.stderr.write("=================================================================\n") + sys.stderr.write("Test:%s failure \n" % test.id()) + sys.stderr.write("%s\n" % trace_back) + return False else: return True +if __name__ == '__main__': + PYTHONPATH = sys.argv[1] + test_class_path = sys.argv[2] + argv = [] -PYTHONPATH = sys.argv[1] -test_module = sys.argv[2] -argv = [] + sys.path.insert(0, PYTHONPATH) -sys.path.insert( 0 , PYTHONPATH ) -test_module = __import__(sys.argv[2]) + try: + argv = sys.argv[3:] + except IndexError: + pass -try: - argv = sys.argv[3:] -except: - pass + tests = getTestsFromTestClass(test_class_path, argv) -test_suite = test_module.test_suite( argv ) -if test_suite: - if run_suite( test_suite ): - sys.exit( 0 ) + if runTestCase(tests): + sys.exit(0) else: - sys.exit( 1 ) -else: - sys.exit( 0 ) - + sys.exit(1) diff --git a/ThirdParty/Ert/devel/python/test/enkf_test.py b/ThirdParty/Ert/devel/python/test/enkf_test.py index 1126f0248f..b923a7ce9c 100644 --- a/ThirdParty/Ert/devel/python/test/enkf_test.py +++ b/ThirdParty/Ert/devel/python/test/enkf_test.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # Copyright (C) 2012 Statoil ASA, Norway. # -# The file 'sum_test.py' is part of ERT - Ensemble based Reservoir Tool. +# The file 'enkf_test.py' is part of ERT - Ensemble based Reservoir Tool. # # ERT is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,10 +19,12 @@ import datetime import unittest import ert import ert.enkf.enkf as enkf -from ert.util.tvector import * +from ert.util.tvector import * from test_util import approx_equal, approx_equalv -case = "../../../libenkf/src/Gurbat/enkf.ext" +case = "/private/inmyr/ERT-Intro/testcase/ert_config" +site_conf_file = "/project/res/etc/ERT/site-config" +obs_config_file = "/private/inmyr/ERT-Intro/testcase/observations" class EnKFtest( unittest.TestCase ): def setUp(self): @@ -30,30 +32,43 @@ class EnKFtest( unittest.TestCase ): def test_boot( self ): - self.main = enkf.EnKFMain.bootstrap( case ) + self.main = enkf.EnKFMain.bootstrap( case, site_conf_file ) self.assertTrue( self.main , "Load failed" ) del self - def test_enum(self): self.assertEqual( enkf.enkf_state_enum.FORECAST , 2 ) self.assertEqual( enkf.enkf_state_enum.ANALYZED , 4 ) - + del self def test_config( self ): - self.main = enkf.EnKFMain.bootstrap( case ) - config = self.main.config - self.assertTrue( isinstance( config , ert.enkf.ens_config.EnsConfig)) - - def test_update(self): - step_list = IntVector(0) - step_list.append(30) - self.main = enkf.EnKFMain.bootstrap( case ) - self.main.update(step_list) - - - #def test_sim(self): - # self.main = enkf.EnKFMain.bootstrap( case ) - # self.main.sim() - + self.main = enkf.EnKFMain.bootstrap( case, site_conf_file ) + config = self.main.ensemble_config + anal_config = self.main.analysis_config + mod_config = self.main.model_config + loc_config = self.main.local_config + site_conf = self.main.site_config + ecl_conf = self.main.ecl_config + plot_conf = self.main.plot_config + self.main.load_obs(obs_config_file) + ob = self.main.get_obs + temp = self.main.get_templates + enkf_fsout = self.main.get_fs + mem_conf = self.main.iget_member_config(0) + enkf_stat = self.main.iget_state(0) + self.assertTrue( isinstance( config , ert.enkf.ens_config.EnsConfig)) + self.assertTrue( isinstance( anal_config , ert.enkf.analysis_config.AnalysisConfig)) + self.assertTrue( isinstance( mod_config , ert.enkf.model_config.ModelConfig)) + self.assertTrue( isinstance( loc_config , ert.enkf.local_config.LocalConfig)) + self.assertTrue( isinstance( site_conf , ert.enkf.site_config.SiteConfig)) + self.assertTrue( isinstance( ecl_conf , ert.enkf.ecl_config.EclConfig)) + self.assertTrue( isinstance( plot_conf , ert.enkf.plot_config.PlotConfig)) + self.assertTrue( isinstance( ob , ert.enkf.enkf_obs.EnkfObs)) + self.assertTrue( isinstance( temp , ert.enkf.ert_templates.ErtTemplates)) + self.assertTrue( isinstance( enkf_fsout , ert.enkf.enkf_fs.EnkfFs)) + self.assertTrue( isinstance( mem_conf , ert.enkf.member_config.MemberConfig)) + self.assertTrue( isinstance( enkf_stat , ert.enkf.enkf_state.EnKFState)) + del self + unittest.main() +e diff --git a/ThirdParty/Ert/devel/python/test/ens_config_test.py b/ThirdParty/Ert/devel/python/test/ens_config_test.py index b62cd8948d..54fd984238 100644 --- a/ThirdParty/Ert/devel/python/test/ens_config_test.py +++ b/ThirdParty/Ert/devel/python/test/ens_config_test.py @@ -20,19 +20,29 @@ import unittest import ert import ert.enkf.enkf as enkf from test_util import approx_equal, approx_equalv +from ert.util.stringlist import StringList -case = "../../../libenkf/src/Gurbat/enkf.ext" +case = "/private/inmyr/ERT-Intro/testcase/ert_config" +site_conf_file = "/project/res/etc/ERT/site-config" +obs_config_file = "/private/inmyr/ERT-Intro/testcase/observations" class EnsConfigTest( unittest.TestCase ): def setUp(self): pass def test_key(self): - main = enkf.EnKFMain.bootstrap( case ) + main = enkf.EnKFMain.bootstrap( case , site_conf_file) conf = main.config self.assertTrue( conf.has_key("WWCT:OP_1" )) self.assertFalse( conf.has_key("WWCT:OP_1X" )) - + def test_enkf_conf_node(self): + main = enkf.EnKFMain.bootstrap( case , site_conf_file) + conf = main.config + s = StringList(initial = None, c_ptr=conf.alloc_keylist) + self.assertTrue( isinstance( conf.get_node("MULTFLT") , ert.enkf.enkf_config_node.EnkfConfigNode)) + self.assertTrue( isinstance( s , ert.util.stringlist.StringList)) + + unittest.main() diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/__init__.py b/ThirdParty/Ert/devel/python/test/ert_tests/__init__.py new file mode 100644 index 0000000000..5120406b82 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/__init__.py @@ -0,0 +1,86 @@ +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file '__init__.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +import numbers +import os +import traceback +from unittest2 import TestCase + + +""" + This class provides some extra functionality for testing values that are almost equal. + """ + + +class ExtendedTestCase(TestCase): + def assertAlmostEqualScaled(self, first, second, msg=None): + if isinstance(first, numbers.Number) and isinstance(second, numbers.Number): + tolerance = 1e-6 + diff = abs(first - second) + scale = max(1, abs(first) + abs(second)) + + self.assertTrue(diff < tolerance * scale, msg=msg) + else: + self.assertTrue(first == second, msg=msg) + + + def assertAlmostEqualList(self, first, second, msg=None): + if len(first) != len(second): + self.fail("Lists are not of same length!") + + for index in range(len(first)): + self.assertAlmostEqualScaled(first[index], second[index], msg=msg) + + def assertImportable(self, module_name): + try: + __import__(module_name) + except ImportError: + tb = traceback.format_exc() + self.fail("Module %s not found!\n\nTrace:\n%s" % (module_name, str(tb))) + except Exception: + tb = traceback.format_exc() + self.fail("Import of module %s caused errors!\n\nTrace:\n%s" % (module_name, str(tb))) + + def assertFilesAreEqual(self, first, second): + if not self.__filesAreEqual(first, second): + self.fail("Buffer contents of files are not identical!") + + def assertFilesAreNotEqual(self, first, second): + if self.__filesAreEqual(first, second): + self.fail("Buffer contents of files are identical!") + + def __filesAreEqual(self, first, second): + buffer1 = open(first).read() + buffer2 = open(second).read() + + return buffer1 == buffer2 + + def createTestPath(self, path): + """ + @param: The test root path can be set by environment variable ERT_TEST_ROOT_PATH + """ + file_path = os.path.realpath(__file__) + default_test_root = os.path.realpath(os.path.join(os.path.dirname(file_path), "../test-data/")) + test_root = os.path.realpath(os.environ.get("ERT_TEST_ROOT_PATH", default_test_root)) + + return os.path.realpath(os.path.join(test_root, path)) + + @staticmethod + def slowTestShouldNotRun(): + """ + @param: The slow test flag can be set by environment variable SKIP_SLOW_TESTS = [True|False] + """ + + return os.environ.get("SKIP_SLOW_TESTS", "False") == "True" \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/config/__init__.py b/ThirdParty/Ert/devel/python/test/ert_tests/config/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/config/test_config.py b/ThirdParty/Ert/devel/python/test/ert_tests/config/test_config.py new file mode 100644 index 0000000000..ddba94a7aa --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/config/test_config.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file 'test_config.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +from unittest2 import TestSuite, TextTestRunner +from ert.config import ContentTypeEnum, UnrecognizedEnum, SchemaItem, ContentItem, ContentNode, ConfigParser +from ert_tests import ExtendedTestCase + + +class ConfigTest(ExtendedTestCase): + def setUp( self ): + self.file_list = [] + + + def test_enums(self): + self.assertTrue(ContentTypeEnum.CONFIG_STRING) + self.assertTrue(ContentTypeEnum.CONFIG_INVALID) + self.assertTrue(UnrecognizedEnum.CONFIG_UNRECOGNIZED_ERROR) + + + def test_parse(self): + conf = ConfigParser() + conf.add("FIELD", False) + schema_item = conf.add("RSH_HOST", False) + self.assertIsInstance(schema_item, SchemaItem) + test_path = self.createTestPath("local/config/simple_config") + self.assertTrue(conf.parse(test_path, unrecognized=UnrecognizedEnum.CONFIG_UNRECOGNIZED_IGNORE)) + + + content_item = conf["RSH_HOST"] + self.assertIsInstance(content_item, ContentItem) + self.assertIsNone(conf["BJARNE"]) + + self.assertEqual(len(content_item), 1) + self.assertRaises(ValueError, content_item.__getitem__, "BJARNE") + self.assertRaises(IndexError, content_item.__getitem__, 10) + + content_node = content_item[0] + self.assertIsInstance(content_node, ContentNode) + + self.assertEqual(len(content_node), 2) + self.assertRaises(ValueError, content_node.__getitem__, "BJARNE") + self.assertRaises(IndexError, content_node.__getitem__, 10) + self.assertEqual(content_node[1], "be-lx633214:2") + + self.assertEqual(content_node.content(sep=","), "be-lx655082:2,be-lx633214:2") + self.assertEqual(content_node.content(), "be-lx655082:2 be-lx633214:2") + + content_item = conf["FIELD"] + self.assertEqual(len(content_item), 5) + self.assertRaises(IOError, ConfigParser.parse, conf, "DoesNotExits") + + + def test_schema(self): + schema_item = SchemaItem("TestItem") + self.assertIsInstance(schema_item, SchemaItem) + self.assertEqual(schema_item.iget_type(6), ContentTypeEnum.CONFIG_STRING) + schema_item.iset_type(0, ContentTypeEnum.CONFIG_INT) + self.assertEqual(schema_item.iget_type(0), ContentTypeEnum.CONFIG_INT) + schema_item.set_argc_minmax(3, 6) + + +def fast_suite(): + suite = TestSuite() + suite.addTest(ConfigTest('test_enums')) + suite.addTest(ConfigTest('test_schema')) + suite.addTest(ConfigTest('test_parse')) + return suite + + +if __name__ == "__main__": + TextTestRunner().run(fast_suite()) + + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/__init__.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_default.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_default.py new file mode 100644 index 0000000000..cfe20c6ec8 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_default.py @@ -0,0 +1,18 @@ +from unittest2 import TestCase +from ert.ecl import EclDefault + + +class EclDefaultTest(TestCase): + + def test_ecl_defaults_methods(self): + try: + import ert.ecl.ecl_local as ecl_local + + self.assertEqual(EclDefault.ecl_cmd(), ecl_local.ecl_cmd) + self.assertEqual(EclDefault.ecl_version(), ecl_local.ecl_version) + self.assertEqual(EclDefault.lsf_resource_request(), ecl_local.lsf_resource_request) + self.assertEqual(EclDefault.driver_type(), ecl_local.driver_type) + self.assertEqual(EclDefault.driver_options(), ecl_local.driver_options) + except ImportError: + self.fail("Unable to import ecl_local.py") + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_file.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_file.py new file mode 100644 index 0000000000..d850841f66 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_file.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python +# Copyright (C) 2011 Statoil ASA, Norway. +# +# The file 'sum_test.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +from unittest2 import skipIf +from ert.ecl import EclFile, FortIO +from ert.ecl.ecl_util import EclFileFlagEnum + +from ert.util import TestAreaContext +from ert_tests import ExtendedTestCase + + +class FileTest(ExtendedTestCase): + def setUp(self): + self.test_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") + self.test_fmt_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.FUNRST") + + + def test_IOError(self): + with self.assertRaises(IOError): + EclFile("No/Does/not/exist") + + + def test_fwrite( self ): + #work_area = TestArea("python/ecl_file/fwrite") + with TestAreaContext("python/ecl_file/fwrite"): + rst_file = EclFile(self.test_file) + fortio = FortIO.writer("ECLIPSE.UNRST") + rst_file.fwrite(fortio) + fortio.close() + rst_file.close() + self.assertFilesAreEqual("ECLIPSE.UNRST", self.test_file) + + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow file test skipped!") + def test_save(self): + #work_area = TestArea("python/ecl_file/save") + with TestAreaContext("python/ecl_file/save") as work_area: + work_area.copy_file(self.test_file) + rst_file = EclFile("ECLIPSE.UNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE) + swat0 = rst_file["SWAT"][0] + swat0.assign(0.75) + rst_file.save_kw(swat0) + rst_file.close() + self.assertFilesAreNotEqual("ECLIPSE.UNRST",self.test_file) + + rst_file1 = EclFile(self.test_file) + rst_file2 = EclFile("ECLIPSE.UNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE) + + swat1 = rst_file1["SWAT"][0] + swat2 = rst_file2["SWAT"][0] + swat2.assign(swat1) + + rst_file2.save_kw(swat2) + self.assertTrue(swat1.equal(swat2)) + rst_file1.close() + rst_file2.close() + + # Random failure .... + self.assertFilesAreEqual("ECLIPSE.UNRST", self.test_file) + + + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow file test skipped!") + def test_save_fmt(self): + #work_area = TestArea("python/ecl_file/save_fmt") + with TestAreaContext("python/ecl_file/save_fmt") as work_area: + work_area.copy_file(self.test_fmt_file) + rst_file = EclFile("ECLIPSE.FUNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE) + swat0 = rst_file["SWAT"][0] + swat0.assign(0.75) + rst_file.save_kw(swat0) + rst_file.close() + self.assertFilesAreNotEqual("ECLIPSE.FUNRST", self.test_fmt_file) + + rst_file1 = EclFile(self.test_fmt_file) + rst_file2 = EclFile("ECLIPSE.FUNRST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE) + + swat1 = rst_file1["SWAT"][0] + swat2 = rst_file2["SWAT"][0] + + swat2.assign(swat1) + rst_file2.save_kw(swat2) + self.assertTrue(swat1.equal(swat2)) + rst_file1.close() + rst_file2.close() + + # Random failure .... + self.assertFilesAreEqual("ECLIPSE.FUNRST", self.test_fmt_file) + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_submit.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_submit.py new file mode 100644 index 0000000000..8dade805b0 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_ecl_submit.py @@ -0,0 +1,160 @@ +# #!/usr/bin/env python +# # Copyright (C) 2011 Statoil ASA, Norway. +# # +# # The file 'sum_test.py' is part of ERT - Ensemble based Reservoir Tool. +# # +# # ERT 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. +# # +# # ERT 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. +# +import os +import getpass +from unittest2 import TestSuite, TextTestRunner, skip, skipIf +import time +import shutil +from ert.ecl import EclQueue, EclSum +from ert.job_queue import QueueDriverEnum, RSHDriver +from ert.util import TestAreaContext +from ert_tests import ExtendedTestCase + + +path = "Statoil/ECLIPSE/Gurbat" + +base = "ECLIPSE_SHORT" +LSF_base = "ECLIPSE_SHORT_MPI" + +case = "%s/%s" % (path, base) +LSF_case = "%s/%s" % (path, LSF_base) + + + +class EclSubmitTest(ExtendedTestCase): + nfs_work_path = None + rsh_servers = None + + def setUp(self): + if hasattr(self, "argv"): + if len(self.argv) > 0: + self.nfs_work_path = self.argv[0] + + if len(self.argv) > 1: + self.rsh_servers = self.argv[1] + + def make_run_path(self, iens, LSF=False): + run_path = "run%d" % iens + if os.path.exists(run_path): + shutil.rmtree(run_path) + + os.makedirs(run_path) + shutil.copytree("%s/include" % self.createTestPath(path), "%s/include" % run_path) + if LSF: + shutil.copy("%s.DATA" % self.createTestPath(LSF_case), run_path) + else: + shutil.copy("%s.DATA" % self.createTestPath(case), run_path) + + return os.path.abspath(run_path) + + +class LSFSubmitTest(EclSubmitTest): + + def test_start_parameters(self): + self.assertIsNotNone(self.nfs_work_path, "NFS work path missing!") + self.assertIsNone(self.rsh_servers) + + + #@skip("LSF not defined!") + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow LSF job submit skipped!") + def test_LSF_submit(self): + root = os.path.join(self.nfs_work_path, getpass.getuser(), "ert-test/python/ecl_submit/LSF") + if not os.path.exists(root): + os.makedirs(root) + os.chdir(root) + + num_submit = 6 + queue = EclQueue(driver_type=QueueDriverEnum.LSF_DRIVER, max_running=4, size=num_submit) + path_list = [] + + for iens in (range(num_submit)): + run_path = self.make_run_path(iens, LSF=True) + path_list.append(run_path) + job = queue.submit("%s/%s.DATA" % (run_path, LSF_base)) + + while queue.running: + time.sleep(1) + + for path in path_list: + sum = EclSum("%s/%s" % (path, LSF_base)) + self.assertIsInstance(sum, EclSum) + self.assertEqual(2, sum.last_report) + + +class RSHSubmitTest(EclSubmitTest): + + #@skip("RSH not defined!") + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow RSH job submit skipped!") + def test_RSH_submit(self): + root = os.path.join(self.nfs_work_path, getpass.getuser(), "ert-test/python/ecl_submit/RSH") + if not os.path.exists(root): + os.makedirs(root) + os.chdir(root) + + num_submit = 6 + host_list = [] + for h in self.rsh_servers.split(): + tmp = h.split(":") + if len(tmp) > 1: + num = int(tmp[1]) + else: + num = 1 + host_list.append((tmp[0], num)) + + queue = EclQueue(RSHDriver(3, host_list), size=num_submit) + path_list = [] + + for iens in (range(num_submit)): + run_path = self.make_run_path(iens) + path_list.append(run_path) + job = queue.submit("%s/%s.DATA" % (run_path, base)) + + while queue.running: + time.sleep(1) + + for path in path_list: + sum = EclSum("%s/%s" % (path, base)) + self.assertTrue(isinstance(sum, EclSum)) + self.assertEqual(2, sum.last_report) + +class LocalSubmitTest(EclSubmitTest): + + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow LOCAL job submit skipped!") + def test_LOCAL_submit(self): + #work_area = TestArea("python/ecl_submit/LOCAL", True) + + with TestAreaContext("python/ecl_submit/LOCAL", True) as work_area: + num_submit = 4 + queue = EclQueue(driver_type=QueueDriverEnum.LOCAL_DRIVER, max_running=2) + path_list = [] + + for iens in range(num_submit): + run_path = self.make_run_path(iens) + path_list.append(run_path) + job = queue.submit("%s/%s.DATA" % (run_path, base)) + + queue.submit_complete() + while queue.running: + time.sleep(1) + + for path in path_list: + sum = EclSum("%s/%s" % (path, base)) + self.assertTrue(isinstance(sum, EclSum)) + self.assertEqual(2, sum.last_report) + shutil.rmtree(path) + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_fortio.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_fortio.py new file mode 100644 index 0000000000..d071f4cee6 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_fortio.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python +# Copyright (C) 2011 Statoil ASA, Norway. +# +# The file 'kw_test.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +import os +from ert.ecl import FortIO, EclTypeEnum, EclKW +from ert_tests import ExtendedTestCase +from ert.util import TestAreaContext + + + + +class FortIOTest(ExtendedTestCase): + def setUp(self): + self.unrst_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") + self.file_list = [] + + + def test_open_read(self): + f = FortIO.reader(self.unrst_file) + self.assertTrue(f) + + + def test_open_write(self): + with TestAreaContext("python/fortio/write"): + f = FortIO.writer("newfile") + f.close() + self.assertTrue(True) + + def test_noex(self): + with self.assertRaises(IOError): + f = FortIO.reader("/tmp/does/notExist") + + def test_kw(self): + kw1 = EclKW.create("KW1", 2, EclTypeEnum.ECL_INT_TYPE) + kw2 = EclKW.create("KW2", 2, EclTypeEnum.ECL_INT_TYPE) + + kw1[0] = 99 + kw1[1] = 77 + kw2[0] = 113 + kw2[1] = 335 + + with TestAreaContext("python/fortio/write-kw"): + f = FortIO.writer("test", fmt_file=False) + kw1.fwrite(f) + f.close() + + f = FortIO.open("test", mode="a") + kw2.fwrite(f) + f.close() + + f = FortIO.open("test", fmt_file=False) + k1 = EclKW.fread(f) + k2 = EclKW.fread(f) + f.close() + + self.assertTrue(k1.equal(kw1)) + self.assertTrue(k2.equal(kw2)) + + + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_grdecl.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_grdecl.py new file mode 100644 index 0000000000..baab05ad55 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_grdecl.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python +# Copyright (C) 2011 Statoil ASA, Norway. +# +# The file 'sum_test.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +import os +from ert.ecl import EclKW +from ert_tests import ExtendedTestCase + + + + + +class GRDECLTest(ExtendedTestCase): + def setUp(self): + self.src_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/include/example_permx.GRDECL") + self.file_list = [] + + def addFile(self, filename): + self.file_list.append(filename) + + def tearDown(self): + for f in self.file_list: + if os.path.exists(f): + os.unlink(f) + + + def test_Load( self ): + kw = EclKW.read_grdecl(open(self.src_file, "r"), "PERMX") + self.assertTrue(kw) + + + def test_reload( self ): + kw = EclKW.read_grdecl(open(self.src_file, "r"), "PERMX") + tmp_file1 = "/tmp/permx1.grdecl" + tmp_file2 = "/tmp/permx2.grdecl" + self.addFile(tmp_file1) + self.addFile(tmp_file2) + + fileH = open(tmp_file1, "w") + kw.write_grdecl(fileH) + fileH.close() + + kw1 = EclKW.read_grdecl(open(tmp_file1, "r"), "PERMX") + + fileH = open(tmp_file2, "w") + kw1.write_grdecl(fileH) + fileH.close() + + self.assertFilesAreEqual(tmp_file1, tmp_file2) + + + def test_fseek( self ): + file = open(self.src_file, "r") + self.assertTrue(EclKW.fseek_grdecl(file, "PERMX")) + self.assertFalse(EclKW.fseek_grdecl(file, "PERMY")) + file.close() + + file = open(self.src_file, "r") + kw1 = EclKW.read_grdecl(file, "PERMX") + self.assertFalse(EclKW.fseek_grdecl(file, "PERMX")) + self.assertTrue(EclKW.fseek_grdecl(file, "PERMX", rewind=True)) + file.close() + + + def test_fseek2(self): + test_src = self.createTestPath("local/ECLIPSE/grdecl-test/test.grdecl") + # Test kw at the the very start + file = open(test_src, "r") + self.assertTrue(EclKW.fseek_grdecl(file, "PERMX")) + + # Test commented out kw: + self.assertFalse(EclKW.fseek_grdecl(file, "PERMY")) + self.assertFalse(EclKW.fseek_grdecl(file, "PERMZ")) + + # Test ignore not start of line: + self.assertTrue(EclKW.fseek_grdecl(file, "MARKER")) + self.assertFalse(EclKW.fseek_grdecl(file, "PERMXYZ")) + + # Test rewind + self.assertFalse(EclKW.fseek_grdecl(file, "PERMX", rewind=False)) + self.assertTrue(EclKW.fseek_grdecl(file, "PERMX", rewind=True)) + + # Test multiline comments + blanks + self.assertTrue(EclKW.fseek_grdecl(file, "LASTKW")) + + + def test_fseek_dos(self): + test_src = self.createTestPath("local/ECLIPSE/grdecl-test/test.grdecl_dos") # File formatted with \r\n line endings. + # Test kw at the the very start + file = open(test_src, "r") + self.assertTrue(EclKW.fseek_grdecl(file, "PERMX")) + + # Test commented out kw: + self.assertFalse(EclKW.fseek_grdecl(file, "PERMY")) + self.assertFalse(EclKW.fseek_grdecl(file, "PERMZ")) + + # Test ignore not start of line: + self.assertTrue(EclKW.fseek_grdecl(file, "MARKER")) + self.assertFalse(EclKW.fseek_grdecl(file, "PERMXYZ")) + + # Test rewind + self.assertFalse(EclKW.fseek_grdecl(file, "PERMX", rewind=False)) + self.assertTrue(EclKW.fseek_grdecl(file, "PERMX", rewind=True)) + + # Test multiline comments + blanks + self.assertTrue(EclKW.fseek_grdecl(file, "LASTKW")) diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_grid.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_grid.py new file mode 100644 index 0000000000..fe2b804f52 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_grid.py @@ -0,0 +1,210 @@ +#!/usr/bin/env python +# Copyright (C) 2011 Statoil ASA, Norway. +# +# The file 'test_grid.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +import time +from unittest2 import skipIf +from ert.ecl import EclTypeEnum, EclKW, EclGrid +from ert.util import DoubleVector, TestAreaContext +from ert_tests import ExtendedTestCase + + +class GridTest(ExtendedTestCase): + def egrid_file(self): + return self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") + + + def grid_file(self): + return self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID") + + + def grdecl_file(self): + return self.createTestPath("Statoil/ECLIPSE/Gurbat/include/example_grid_sim.GRDECL") + + def test_GRID( self ): + grid = EclGrid(self.grid_file()) + self.assertTrue(grid) + + + def test_EGRID( self ): + grid = EclGrid(self.egrid_file()) + self.assertTrue(grid) + + + def create(self, filename, load_actnum=True): + fileH = open(filename, "r") + specgrid = EclKW.read_grdecl(fileH, "SPECGRID", ecl_type=EclTypeEnum.ECL_INT_TYPE, strict=False) + zcorn = EclKW.read_grdecl(fileH, "ZCORN") + coord = EclKW.read_grdecl(fileH, "COORD") + if load_actnum: + actnum = EclKW.read_grdecl(fileH, "ACTNUM", ecl_type=EclTypeEnum.ECL_INT_TYPE) + else: + actnum = None + + mapaxes = EclKW.read_grdecl(fileH, "MAPAXES") + grid = EclGrid.create(specgrid, zcorn, coord, actnum, mapaxes=mapaxes) + return grid + + + def test_rect(self): + #work_area = TestArea("python/grid-test/testRect", True) + with TestAreaContext("python/grid-test/testRect", True): + a1 = 1.0 + a2 = 2.0 + a3 = 3.0 + grid = EclGrid.create_rectangular((9, 9, 9), (a1, a2, a3)) + grid.save_EGRID("rect.EGRID") + grid2 = EclGrid("rect.EGRID") + self.assertTrue(grid) + self.assertTrue(grid2) + + (x, y, z) = grid.get_xyz(ijk=(4, 4, 4)) + self.assertAlmostEqualList([x, y, z], [4.5 * a1, 4.5 * a2, 4.5 * a3]) + + v = grid.cell_volume(ijk=(4, 4, 4)) + self.assertAlmostEqualScaled(v, a1 * a2 * a3) + + z = grid.depth(ijk=(4, 4, 4 )) + self.assertAlmostEqualScaled(z, 4.5 * a3) + + g1 = grid.global_index(ijk=(2, 2, 2)) + g2 = grid.global_index(ijk=(4, 4, 4)) + (dx, dy, dz) = grid.distance(g2, g1) + self.assertAlmostEqualList([dx, dy, dz], [2 * a1, 2 * a2, 2 * a3]) + + self.assertTrue(grid.cell_contains(2.5 * a1, 2.5 * a2, 2.5 * a3, ijk=(2, 2, 2))) + + ijk = grid.find_cell(1.5 * a1, 2.5 * a2, 3.5 * a3) + self.assertAlmostEqualList(ijk, [1, 2, 3]) + + + def test_create(self): + grid = self.create(self.grdecl_file()) + self.assertTrue(grid) + + + def test_ACTNUM(self): + g1 = self.create(self.grdecl_file()) + g2 = self.create(self.grdecl_file(), load_actnum=False) + self.assertTrue(g1.equal(g2)) + + + def test_time(self): + t0 = time.clock() + g1 = EclGrid(self.egrid_file()) + t1 = time.clock() + t = t1 - t0 + self.assertTrue(t < 1.0) + + + def test_save(self): + #work_area = TestArea("python/grid-test/testSave", True) + with TestAreaContext("python/grid-test/testSave", True): + g1 = EclGrid(self.egrid_file()) + + g1.save_EGRID("test.EGRID") + g2 = EclGrid("test.EGRID") + self.assertTrue(g1.equal(g2)) + + g1.save_GRID("test.GRID") + g2 = EclGrid("test.GRID") + self.assertTrue(g1.equal(g2)) + + fileH = open("test.grdecl", "w") + g1.save_grdecl(fileH) + fileH.close() + g2 = self.create("test.grdecl") + self.assertTrue(g1.equal(g2)) + + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test of coarse grid skipped!") + def test_coarse(self): + #work_area = TestArea("python/grid-test/testCoarse") + with TestAreaContext("python/grid-test/testCoarse"): + testGRID = True + g1 = EclGrid(self.createTestPath("Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2.EGRID")) + + g1.save_EGRID("LGC.EGRID") + g2 = EclGrid("LGC.EGRID") + self.assertTrue(g1.equal(g2, verbose=True)) + + if testGRID: + g1.save_GRID("LGC.GRID") + g3 = EclGrid("LGC.GRID") + self.assertTrue(g1.equal(g3, verbose=True)) + + self.assertTrue(g1.coarse_groups() == 3384) + + + def test_raise_IO_error(self): + with self.assertRaises(IOError): + g = EclGrid("/does/not/exist.EGRID") + + + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test of dual grid skipped!") + def test_dual(self): + #work_area = TestArea("python/grid-test/testDual", True) + with TestAreaContext("python/grid-test/testDual", True): + grid = EclGrid(self.egrid_file()) + self.assertFalse(grid.dual_grid) + self.assertTrue(grid.nactive_fracture == 0) + + grid2 = EclGrid(self.grid_file()) + self.assertFalse(grid.dual_grid) + self.assertTrue(grid.nactive_fracture == 0) + + dgrid = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.EGRID")) + self.assertTrue(dgrid.nactive == dgrid.nactive_fracture) + self.assertTrue(dgrid.nactive == 46118) + + dgrid2 = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.GRID")) + self.assertTrue(dgrid.nactive == dgrid.nactive_fracture) + self.assertTrue(dgrid.nactive == 46118) + self.assertTrue(dgrid.equal(dgrid2)) + + + # The DUAL_DIFF grid has been manipulated to create a + # situation where some cells are only matrix active, and some + # cells are only fracture active. + dgrid = EclGrid(self.createTestPath("Statoil/ECLIPSE/DualPoro/DUAL_DIFF.EGRID")) + self.assertTrue(dgrid.nactive == 106) + self.assertTrue(dgrid.nactive_fracture == 105) + + self.assertTrue(dgrid.get_active_fracture_index(global_index=0) == -1) + self.assertTrue(dgrid.get_active_fracture_index(global_index=2) == -1) + self.assertTrue(dgrid.get_active_fracture_index(global_index=3) == 0) + self.assertTrue(dgrid.get_active_fracture_index(global_index=107) == 104) + + self.assertTrue(dgrid.get_active_index(global_index=1) == 1) + self.assertTrue(dgrid.get_active_index(global_index=105) == 105) + self.assertTrue(dgrid.get_active_index(global_index=106) == -1) + self.assertTrue(dgrid.get_global_index1F(2) == 5) + + dgrid.save_GRID("DUAL_DIFF.GRID") + dgrid2 = EclGrid("DUAL_DIFF.GRID") + self.assertTrue(dgrid.equal(dgrid2)) + + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test of nactive large memory skipped!") + def test_nactive_large_memory(self): + case = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE") + vecList = [] + for i in range(12500): + vec = DoubleVector() + vec[81920] = 0 + vecList.append(vec) + + grid1 = EclGrid(case) + grid2 = EclGrid(case) + self.assertEqual(grid1.nactive, grid2.nactive) + self.assertEqual(grid1.nactive, 34770) \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_kw.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_kw.py new file mode 100644 index 0000000000..c364b0da3e --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_kw.py @@ -0,0 +1,230 @@ +#!/usr/bin/env python +# Copyright (C) 2011 Statoil ASA, Norway. +# +# The file 'test_kw.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +import os +from ert.ecl import EclKW, EclTypeEnum, EclFile +from ert.util import TestAreaContext + +from ert_tests import ExtendedTestCase + + +def copy_long(): + src = EclKW.create("NAME", 100, EclTypeEnum.ECL_FLOAT_TYPE) + copy = src.sub_copy(0, 2000) + + +def copy_offset(): + src = EclKW.create("NAME", 100, EclTypeEnum.ECL_FLOAT_TYPE) + copy = src.sub_copy(200, 100) + + +class KWTest(ExtendedTestCase): + def test_fortio_size( self ): + unrst_file_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") + unrst_file = EclFile(unrst_file_path) + size = 0 + for kw in unrst_file: + size += kw.fortio_size + + stat = os.stat(unrst_file_path) + self.assertTrue(size == stat.st_size) + + + def test_equal(self): + kw1 = EclKW.new("TEST", 3, EclTypeEnum.ECL_CHAR_TYPE) + kw1[0] = "Test1" + kw1[1] = "Test13" + kw1[2] = "Test15" + + kw2 = EclKW.new("TEST", 3, EclTypeEnum.ECL_CHAR_TYPE) + kw2[0] = "Test1" + kw2[1] = "Test13" + kw2[2] = "Test15" + + self.assertTrue(kw1.equal(kw2)) + self.assertTrue(kw1.equal_numeric(kw2)) + + kw2[2] = "Test15X" + self.assertFalse(kw1.equal(kw2)) + self.assertFalse(kw1.equal_numeric(kw2)) + + unrst_file_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") + unrst_file = EclFile(unrst_file_path) + kw1 = unrst_file["PRESSURE"][0] + kw2 = kw1.deep_copy() + + self.assertTrue(kw1.equal(kw2)) + self.assertTrue(kw1.equal_numeric(kw2)) + + kw2 *= 1.00001 + self.assertFalse(kw1.equal(kw2)) + self.assertFalse(kw1.equal_numeric(kw2, epsilon=1e-8)) + self.assertTrue(kw1.equal_numeric(kw2, epsilon=1e-2)) + + kw1 = unrst_file["ICON"][10] + kw2 = kw1.deep_copy() + self.assertTrue(kw1.equal(kw2)) + self.assertTrue(kw1.equal_numeric(kw2)) + + kw1[-1] += 1 + self.assertFalse(kw1.equal(kw2)) + self.assertFalse(kw1.equal_numeric(kw2)) + + + def kw_test( self, data_type, data, fmt ): + name1 = "file1.txt" + name2 = "file2.txt" + kw = EclKW.new("TEST", len(data), data_type) + i = 0 + for d in data: + kw[i] = d + i += 1 + + file1 = open(name1, "w") + kw.fprintf_data(file1, fmt) + file1.close() + + file2 = open(name2, "w") + for d in data: + file2.write(fmt % d) + file2.close() + self.assertFilesAreEqual(name1, name2) + + + def test_sub_copy(self): + unrst_file_path = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") + unrst_file = EclFile(unrst_file_path) + swat = unrst_file["SWAT"][0] + + swat1 = swat.sub_copy(0, -1) + swat2 = swat.sub_copy(0, swat.size) + + self.assertTrue(swat.equal(swat1)) + self.assertTrue(swat.equal(swat2)) + + swat3 = swat.sub_copy(20000, 100, new_header="swat") + self.assertTrue(swat3.name == "swat") + self.assertTrue(swat3.size == 100) + equal = True + for i in range(swat3.size): + if swat3[i] != swat[i + 20000]: + equal = False + self.assertTrue(equal) + + self.assertRaises(IndexError, copy_long) + self.assertRaises(IndexError, copy_offset) + + + def test_fprintf( self ): + #work_area = TestArea("python.ecl_kw") + with TestAreaContext("python.ecl_kw"): + self.kw_test(EclTypeEnum.ECL_INT_TYPE, [0, 1, 2, 3, 4, 5], "%4d\n") + self.kw_test(EclTypeEnum.ECL_FLOAT_TYPE, [0.0, 1.1, 2.2, 3.3, 4.4, 5.5], "%12.6f\n") + self.kw_test(EclTypeEnum.ECL_DOUBLE_TYPE, [0.0, 1.1, 2.2, 3.3, 4.4, 5.5], "%12.6f\n") + self.kw_test(EclTypeEnum.ECL_BOOL_TYPE, [True, True, True, False, True], "%4d\n") + self.kw_test(EclTypeEnum.ECL_CHAR_TYPE, ["1", "22", "4444", "666666", "88888888"], "%-8s\n") + + +#def cutoff( x , arg ): +# if x < arg: +# return 0 +# else: +# return x +# +# +#init_file = ecl.EclFile( "data/eclipse/case/ECLIPSE.INIT" ) +#permx = init_file.iget_named_kw("PERMX" , 0 ) +#poro = init_file.iget_named_kw("PORO" , 0 ) +#pvt = init_file.iget_named_kw("PVTNUM" , 0 ) +#grid = ecl.EclGrid( "data/eclipse/case/ECLIPSE.EGRID" ) +# +# +#poro3d = grid.create3D( poro , default = -100) +# +#print "max:%g" % poro.max +#print "min:%g" % poro.min +# +#mask1 = ecl.EclRegion( grid , False ) +#mask2 = ecl.EclRegion( grid , False ) +#mask1.select_less( poro , 0.15 ) +#mask2.select_more( poro , 0.30 ) +# +#mask3 = mask1.copy() +#mask3 |= mask2 +# +#mask1.reset() +#(x,y,z) = grid.get_xyz( ijk = (grid.nx / 2 , grid.ny /2 , grid.nz / 2) ) +#mask1.select_above_plane( [0,0,1] , [x,y,z] ) +#print mask1.active_list.size +#print mask1.active_list.str( max_lines = None ) +# +#print mask2.active_list.size +#print mask3.active_list.size +# +#poro.apply( cutoff , mask = mask1 , arg = 0.05) +# +# +#poro.write_grdecl( open("/tmp/poro_cos.grdecl" , "w") ) +# +#poro.add( permx , mask = mask1) +#poro.sub( 1 ) +#poro.mul( poro ) +#poro.assign( 14.0 ) +#poro.div( 7.0 ) +# +#new_p = poro / 7.0 +# +#poro.write_grdecl( open("/tmp/poro_cos.grdecl" , "w") ) +# +#init_file = ecl.EclFile( "data/eclipse/case/ECLIPSE.INIT" ) +#permx_kw = init_file.iget_named_kw( "PERMX" , 0 ) +#permx_new = ecl.EclKW.new( "PERMX" , 3 , ecl.ECL_FLOAT_TYPE ) +#print ecl.ECL_GRID_FILE +#print ecl.ecl_file_enum +#permx_new[0] = 1 +#permx_new[1] = 2 +#permx_new[2] = 3 +# +##init_file.replace_kw( permx_kw , permx_new ) +#fortio = ecl.FortIO.writer( "/tmp/init" ) +#print fortio +#init_file.fwrite( fortio ) +#fortio.close() +# +#poro = ecl.EclKW.read_grdecl( open( "data/eclipse/case/include/example_poro.GRDECL" , "r") , "PORO" ) +#eqlnum = ecl.EclKW.read_grdecl( open( "data/eclipse/case/include/example_eqlnum.GRDECL" , "r") , "EQLNUM" ) +#dummy = ecl.EclKW.read_grdecl( open( "data/eclipse/case/include/example_eqlnum.GRDECL" , "r") , "BJARNE" , ecl_type = ecl.ECL_INT_TYPE) +# +#if dummy: +# print "Loading BJARNE OK" +#else: +# print "Loading BJARNE Failed (correctly)" +# +#print "Poro[100] :%g eqlnum[100]:%d" % (poro[100] , eqlnum[100]) +# +#if not eqlnum.type == ecl.ECL_INT_TYPE: +# sys.exit("Type error when loading eqlnum") +# +#p2 = poro[100:160] +#if p2: +# print p2.header +#print poro +#print pvt.str( max_lines = 8 ) +#print eqlnum +# +#print ecl.EclKW.int_kw +#poro.add_int_kw("BJARNE") +#print eqlnum.int_kw diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_legacy_ecl.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_legacy_ecl.py new file mode 100644 index 0000000000..40383b43d0 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_legacy_ecl.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# Copyright (C) 2013 Statoil ASA, Norway. +# +# The file 'test_rft_cell.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +from unittest2 import TestCase +from ert.ecl import EclTypeEnum, EclFileFlagEnum, EclPhaseEnum + +import ert.ecl.ecl as ecl +import ert.ecl as new_ecl +import ert.ecl.ecl_default as ecl_default + + +class LegacyEclTest(TestCase): + + def test_classes(self): + self.assertEqual(ecl.EclSum, new_ecl.EclSum) + + self.assertEqual(ecl.EclRFTFile, new_ecl.EclRFTFile) + self.assertEqual(ecl.EclRFTCell, new_ecl.EclRFTCell) + self.assertEqual(ecl.EclPLTCell, new_ecl.EclPLTCell) + + self.assertEqual(ecl.EclKW, new_ecl.EclKW) + self.assertEqual(ecl.EclFile, new_ecl.EclFile) + + self.assertEqual(ecl.FortIO, new_ecl.FortIO) + + self.assertEqual(ecl.EclGrid, new_ecl.EclGrid) + + self.assertEqual(ecl.EclRegion, new_ecl.EclRegion) + + self.assertEqual(ecl.ecl_default.default.ecl_version, new_ecl.EclDefault.ecl_version()) + + self.assertEqual(ecl.EclQueue, new_ecl.EclQueue) + + def test_enums(self): + self.assertEqual(ecl.ECL_FLOAT_TYPE, EclTypeEnum.ECL_FLOAT_TYPE) + self.assertEqual(ecl.ECL_CHAR_TYPE, EclTypeEnum.ECL_CHAR_TYPE) + self.assertEqual(ecl.ECL_DOUBLE_TYPE, EclTypeEnum.ECL_DOUBLE_TYPE) + self.assertEqual(ecl.ECL_BOOL_TYPE, EclTypeEnum.ECL_BOOL_TYPE) + self.assertEqual(ecl.ECL_CHAR_TYPE, EclTypeEnum.ECL_CHAR_TYPE) + + self.assertEqual(ecl.ECL_FILE_WRITABLE, EclFileFlagEnum.ECL_FILE_WRITABLE) + + self.assertEqual(ecl.ECL_OIL_PHASE, EclPhaseEnum.ECL_OIL_PHASE) + self.assertEqual(ecl.ECL_GAS_PHASE, EclPhaseEnum.ECL_GAS_PHASE) + self.assertEqual(ecl.ECL_WATER_PHASE, EclPhaseEnum.ECL_WATER_PHASE) + + + + def test_ecl_defaults(self): + self.assertIsNotNone(ecl_default.default.ecl_version) + self.assertIsNotNone(ecl_default.default.driver_options) + self.assertIsNotNone(ecl_default.default.ecl_cmd) + self.assertIsNotNone(ecl_default.default.driver_type) + self.assertIsNotNone(ecl_default.default.lsf_resource_request) \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_region.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_region.py new file mode 100644 index 0000000000..9579bfbc66 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_region.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file 'test_region.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +from ert.ecl import EclFile, EclGrid, EclRegion +from ert_tests import ExtendedTestCase + + +class RegionTest(ExtendedTestCase): + def setUp(self): + case = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE") + self.grid = EclGrid(case) + self.rst_file = EclFile("%s.UNRST" % case) + self.init_file = EclFile("%s.INIT" % case) + + + def test_kw_imul(self): + P = self.rst_file["PRESSURE"][5] + fipnum = self.init_file["FIPNUM"][0] + fipnum_copy = fipnum.deep_copy() + + reg = EclRegion(self.grid, False) + reg.select_more(P, 260) + fipnum.mul(-1, mask=reg) + self.assertFalse(fipnum.equal(fipnum_copy)) + + fipnum.mul(-1, mask=reg) + self.assertTrue(fipnum.equal(fipnum_copy)) + + + def test_kw_idiv(self): + P = self.rst_file["PRESSURE"][5] + fipnum = self.init_file["FIPNUM"][0] + fipnum_copy = fipnum.deep_copy() + + reg = EclRegion(self.grid, False) + reg.select_more(P, 260) + fipnum.div(-1, mask=reg) + self.assertFalse(fipnum.equal(fipnum_copy)) + + fipnum.div(-1, mask=reg) + self.assertTrue(fipnum.equal(fipnum_copy)) + + + def test_kw_iadd(self): + P = self.rst_file["PRESSURE"][5] + fipnum = self.init_file["FIPNUM"][0] + fipnum_copy = fipnum.deep_copy() + + reg = EclRegion(self.grid, False) + reg.select_more(P, 260) + fipnum.add(1, mask=reg) + self.assertFalse(fipnum.equal(fipnum_copy)) + + reg.invert() + fipnum.add(1, mask=reg) + + fipnum.sub(1) + self.assertTrue(fipnum.equal(fipnum_copy)) + + + def test_kw_isub(self): + P = self.rst_file["PRESSURE"][5] + fipnum = self.init_file["FIPNUM"][0] + fipnum_copy = fipnum.deep_copy() + + reg = EclRegion(self.grid, False) + reg.select_more(P, 260) + fipnum.sub(1, mask=reg) + self.assertFalse(fipnum.equal(fipnum_copy)) + fipnum.add(1, mask=reg) + self.assertTrue(fipnum.equal(fipnum_copy)) + + + def test_slice(self): + reg = EclRegion(self.grid, False) + reg.select_islice(0, 5) + OK = True + for gi in reg.global_list: + (i, j, k) = self.grid.get_ijk(global_index=gi) + if i > 5: + OK = False + self.assertTrue(OK) + self.assertTrue(self.grid.ny * self.grid.nz * 6 == len(reg.global_list)) + + reg.select_jslice(7, 8, intersect=True) + OK = True + for gi in reg.global_list: + (i, j, k) = self.grid.get_ijk(global_index=gi) + if i > 5: + OK = False + + if j < 7 or j > 8: + OK = False + + self.assertTrue(OK) + self.assertTrue(2 * self.grid.nz * 6 == len(reg.global_list)) + + reg2 = EclRegion(self.grid, False) + reg2.select_kslice(3, 5) + reg &= reg2 + OK = True + for gi in reg.global_list: + (i, j, k) = self.grid.get_ijk(global_index=gi) + if i > 5: + OK = False + + if j < 7 or j > 8: + OK = False + + if k < 3 or k > 5: + OK = False + + self.assertTrue(OK) + self.assertTrue(2 * 3 * 6 == len(reg.global_list)) + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_restart.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_restart.py new file mode 100644 index 0000000000..8ced2e07d3 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_restart.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python +# Copyright (C) 2011 Statoil ASA, Norway. +# +# The file 'sum_test.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +from _ctypes import ArgumentError +import os +import datetime +from ert.ecl import EclFile +from ert_tests import ExtendedTestCase + + + + + +class RestartTest(ExtendedTestCase): + def setUp(self): + self.xfile0 = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.X0000") + self.u_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST") + self.fmt_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.FUNRST") + self.grid_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID") + self.file_list = [] + + def addFile( self, filename ): + self.file_list.append(filename) + + def tearDown(self): + for f in self.file_list: + if os.path.exists(f): + os.unlink(f) + + + def report_file_test(self, fname): + self.assertTrue(EclFile.contains_report_step(fname, 4)) + self.assertTrue(EclFile.contains_report_step(fname, 0)) + self.assertTrue(EclFile.contains_report_step(fname, 62)) + self.assertFalse(EclFile.contains_report_step(fname, -1)) + self.assertFalse(EclFile.contains_report_step(fname, 100)) + + f = EclFile(fname) + self.assertTrue(f.has_report_step(4)) + self.assertTrue(f.has_report_step(0)) + self.assertTrue(f.has_report_step(62)) + + self.assertFalse(f.has_report_step(-1)) + self.assertFalse(f.has_report_step(100)) + + + def test_report(self): + self.report_file_test(self.u_file) + + + def test_date(self): + f = EclFile(self.u_file) + self.assertTrue(f.has_sim_time(datetime.datetime(2001, 6, 1))) + self.assertFalse(f.has_sim_time(datetime.datetime(2005, 6, 1))) + self.assertFalse(f.has_sim_time(datetime.datetime(1999, 6, 1))) + self.assertFalse(f.has_sim_time(datetime.datetime(2001, 6, 11))) + + self.assertTrue(EclFile.contains_sim_time(self.u_file, datetime.datetime(2001, 6, 1))) + self.assertFalse(EclFile.contains_sim_time(self.u_file, datetime.datetime(2005, 6, 1))) + self.assertFalse(EclFile.contains_sim_time(self.u_file, datetime.datetime(1999, 6, 1))) + self.assertFalse(EclFile.contains_sim_time(self.u_file, datetime.datetime(2001, 6, 11))) + + + def report_list_file_test(self, fname, rlist0): + rlist = EclFile.file_report_list(fname) + self.assertAlmostEqualList(rlist, rlist0) + + f = EclFile(fname) + rlist = f.report_list + self.assertAlmostEqualList(rlist, rlist0) + + + def test_report_list(self): + rlist0 = range(63) + self.report_list_file_test(self.u_file, rlist0) + + rlist0 = [0] + self.report_list_file_test(self.xfile0, rlist0) + + f = EclFile(self.grid_file) + with self.assertRaises(ArgumentError): #argumentError wraps the expected TypeError + EclFile.file_report_list(f) + + + def test_dates(self): + f = EclFile(self.u_file) + dates = f.dates + self.assertTrue(len(dates) == 63) + + f = EclFile(self.xfile0) + dates = f.dates + self.assertTrue(len(dates) == 1) + self.assertTrue(dates[0] == datetime.datetime(2000, 1, 1)) + + + def test_name(self): + f = EclFile(self.u_file) + self.assertTrue(f.name == self.u_file) + + f = EclFile(self.xfile0) + self.assertTrue(f.name == self.xfile0) + + + def test_kw( self ): + f = EclFile(self.u_file) + kw1 = f["SWAT"][40] + kw2 = f.restart_get_kw("SWAT", datetime.datetime(2003, 3, 1)) + kw3 = f.restart_get_kw("SWAT", datetime.datetime(2003, 3, 1), copy=True) + + self.assertTrue(kw1.equal(kw2)) + self.assertTrue(kw1.equal(kw3)) + + kw4 = f.restart_get_kw("SWAT", datetime.datetime(2009, 3, 1)) + self.assertIsNone(kw4) + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_rft.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_rft.py new file mode 100644 index 0000000000..8c2a1106e7 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_rft.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# Copyright (C) 2011 Statoil ASA, Norway. +# +# The file 'test_rft.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + + +import datetime +from ert.ecl import EclRFTFile, EclRFTCell, EclPLTCell +from ert_tests import ExtendedTestCase + + +class RFTTest(ExtendedTestCase): + def setUp(self): + self.RFT_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.RFT") + self.PLT_file = self.createTestPath("Statoil/ECLIPSE/RFT/TEST1_1A.RFT") + + + def test_RFT_load( self ): + rftFile = EclRFTFile(self.RFT_file) + + rft = rftFile[0] + cell = rft.ijkget((32, 53, 0)) + self.assertIsInstance(cell, EclRFTCell) + + self.assertEqual(2, rftFile.size()) + self.assertEqual(0, rftFile.size(well="OP*")) + self.assertEqual(0, rftFile.size(well="XXX")) + self.assertEqual(1, rftFile.size(date=datetime.date(2000, 6, 1))) + self.assertEqual(0, rftFile.size(date=datetime.date(2000, 6, 17))) + + cell = rft.ijkget((30, 20, 1880)) + self.assertIsNone(cell) + + for rft in rftFile: + self.assertTrue(rft.is_RFT()) + self.assertFalse(rft.is_SEGMENT()) + self.assertFalse(rft.is_PLT()) + self.assertFalse(rft.is_MSW()) + + for cell in rft: + self.assertIsInstance(cell, EclRFTCell) + + cell0 = rft.iget_sorted(0) + self.assertIsInstance(cell, EclRFTCell) + rft.sort() + + + def test_PLT_load( self ): + pltFile = EclRFTFile(self.PLT_file) + plt = pltFile[11] + self.assertTrue(plt.is_PLT()) + self.assertFalse(plt.is_SEGMENT()) + self.assertFalse(plt.is_RFT()) + self.assertFalse(plt.is_MSW()) + + for cell in plt: + self.assertIsInstance(cell, EclPLTCell) + + + def test_exceptions( self ): + with self.assertRaises(IndexError): + rftFile = EclRFTFile(self.RFT_file) + rft = rftFile[100] diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_rft_cell.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_rft_cell.py new file mode 100644 index 0000000000..e6dccc3296 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_rft_cell.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# Copyright (C) 2013 Statoil ASA, Norway. +# +# The file 'test_rft_cell.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + + +import warnings +from ert.ecl import EclRFTCell, EclPLTCell +from ert_tests import ExtendedTestCase + + +# def out_of_range(): +# rftFile = ecl.EclRFTFile(RFT_file) +# rft = rftFile[100] + + +class RFTCellTest(ExtendedTestCase): + def setUp(self): + self.RFT_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/ECLIPSE.RFT") + self.PLT_file = self.createTestPath("Statoil/ECLIPSE/RFT/TEST1_1A.RFT") + + def test_RFT_cell(self): + i = 10 + j = 8 + k = 100 + depth = 100 + pressure = 65 + swat = 0.56 + sgas = 0.10 + cell = EclRFTCell.new(i, j, k, depth, pressure, swat, sgas) + + self.assertEqual(i, cell.get_i()) + self.assertEqual(j, cell.get_j()) + self.assertEqual(k, cell.get_k()) + + self.assertAlmostEqualScaled(pressure, cell.pressure) + self.assertAlmostEqualScaled(depth, cell.depth) + self.assertAlmostEqualScaled(swat, cell.swat) + self.assertAlmostEqualScaled(sgas, cell.sgas) + self.assertAlmostEqualScaled(1 - (sgas + swat), cell.soil) + + + def test_PLT_cell(self): + i = 2 + j = 16 + k = 100 + depth = 100 + pressure = 65 + orat = 0.78 + grat = 88 + wrat = 97213 + conn_start = 214 + conn_end = 400 + flowrate = 111 + oil_flowrate = 12 + gas_flowrate = 132 + water_flowrate = 13344 + + cell = EclPLTCell.new(i, j, k, depth, pressure, orat, grat, wrat, conn_start, conn_end, flowrate, + oil_flowrate, gas_flowrate, water_flowrate) + + + self.assertEqual(i, cell.get_i()) + self.assertEqual(j, cell.get_j()) + self.assertEqual(k, cell.get_k()) + + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + self.assertTrue(cell.get_i() + 1 == cell.i) + self.assertTrue(cell.get_j() + 1 == cell.j) + self.assertTrue(cell.get_k() + 1 == cell.k) + + self.assertAlmostEqualScaled(pressure, cell.pressure) + self.assertAlmostEqualScaled(depth, cell.depth) + self.assertAlmostEqualScaled(orat, cell.orat) + self.assertAlmostEqualScaled(grat, cell.grat) + self.assertAlmostEqualScaled(wrat, cell.wrat) + + self.assertAlmostEqualScaled(conn_start, cell.conn_start) + self.assertAlmostEqualScaled(conn_end, cell.conn_end) + self.assertAlmostEqualScaled(flowrate, cell.flowrate) + self.assertAlmostEqualScaled(oil_flowrate, cell.oil_flowrate) + self.assertAlmostEqualScaled(gas_flowrate, cell.gas_flowrate) + self.assertAlmostEqualScaled(water_flowrate, cell.water_flowrate) + + + + + + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_sum.py b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_sum.py new file mode 100644 index 0000000000..9927493b7c --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/ecl/test_sum.py @@ -0,0 +1,263 @@ +#!/usr/bin/env python +# Copyright (C) 2011 Statoil ASA, Norway. +# +# The file 'sum_test.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + +import os +import datetime +from unittest2 import skip, skipUnless, skipIf +from ert.ecl import EclSum + +from ert.util import StringList, TestAreaContext + +from ert_tests import ExtendedTestCase + + +base = "ECLIPSE" +path = "Statoil/ECLIPSE/Gurbat" +case = "%s/%s" % (path, base) + + + + +def sum_get(*args): + sum = args[0] + key = args[1] + vec = sum[key] + + +class SumTest(ExtendedTestCase): + def setUp(self): + self.case = self.createTestPath(case) + self.ecl_sum = EclSum(self.case) + + self.assertIsInstance(self.ecl_sum, EclSum) + + + def test_load(self): + self.assertIsNotNone(self.ecl_sum, "Load failed") + + + def test_interp(self): + sum = self.ecl_sum + + self.assertAlmostEqual(sum.get_interp("WWCT:OP_3", days=750), 0.11719122) + self.assertAlmostEqual(sum.get_interp("WWCT:OP_3", date=datetime.date(2004, 1, 1)), 0.603358387947) + + v = sum.get_interp_vector("WOPT:OP_1", days_list=[100, 200, 400, 800]) + self.assertAlmostEqualList([805817.11875, 1614955.34677419, 3289267.67857143, 6493021.6218035], v) + + v = sum.get_interp_vector("WGPT:OP_2", date_list=[datetime.date(2002, 1, 1), datetime.date(2003, 1, 1), datetime.date(2004, 1, 1)]) + self.assertAlmostEqualList(v, [8.20773632e+08, 9.68444032e+08, 1.02515213e+09]) + + + def test_wells(self): + wells = self.ecl_sum.wells() + wells.sort() + self.assertAlmostEqualList(wells, ["OP_1", "OP_2", "OP_3", "OP_4", "OP_5", "WI_1", "WI_2", "WI_3"]) + + wells = self.ecl_sum.wells(pattern="*_3") + wells.sort() + self.assertAlmostEqualList(wells, ["OP_3", "WI_3"]) + + groups = self.ecl_sum.groups() + groups.sort() + self.assertAlmostEqualList(groups, ['GMWIN', 'OP', 'WI']) + + + def test_last( self ): + last = self.ecl_sum.get_last("FOPT") + self.assertAlmostEqual(last.value, 38006336.0) + self.assertAlmostEqual(last.days, 1826.0) + self.assertEqual(last.date, datetime.datetime(2004, 12, 31, 0, 0, 0)) + + self.assertAlmostEqual(self.ecl_sum.get_last_value("FGPT"), 6605249024.0) + + + def test_dates( self ): + sum = self.ecl_sum + d = sum.dates + + self.assertEqual(d[0], datetime.datetime(2000, 1, 1, 0, 0, 0)) + self.assertEqual(d[62], datetime.datetime(2004, 12, 31, 0, 0, 0)) + self.assertEqual(len(d), 63) + self.assertEqual(d[25], datetime.datetime(2001, 12, 1, 0, 0, 0)) + self.assertEqual(sum.iget_date(25), datetime.datetime(2001, 12, 1, 0, 0, 0)) + + mpl_dates = sum.mpl_dates + self.assertAlmostEqual(mpl_dates[25], 730820) + + days = sum.days + self.assertAlmostEqual(days[50], 1461) + + self.assertEqual(sum.start_time, datetime.datetime(2000, 1, 1, 0, 0, 0)) + self.assertEqual(sum.end_time, datetime.datetime(2004, 12, 31, 0, 0, 0)) + self.assertTrue(sum.check_sim_time(datetime.datetime(2004, 12, 31, 0, 0, 0))) + + def test_keys(self): + sum = self.ecl_sum + self.assertRaises(KeyError, sum.__getitem__, "BJARNE") + + v = sum["FOPT"] + self.assertEqual(len(v), 63) + + + def test_index(self): + sum = self.ecl_sum + index = sum.get_key_index("TCPUDAY") + self.assertEqual(index, 10239) + + + def test_report(self): + sum = self.ecl_sum + self.assertEqual(sum.get_report(date=datetime.date(2000, 10, 1)), 10) + self.assertEqual(sum.get_report(date=datetime.date(2000, 10, 3)), -1) + self.assertEqual(sum.get_report(date=datetime.date(1980, 10, 3)), -1) + self.assertEqual(sum.get_report(date=datetime.date(2012, 10, 3)), -1) + + self.assertEqual(sum.get_report(days=91), 3) + self.assertEqual(sum.get_report(days=92), -1) + self.assertAlmostEqual(sum.get_interp("FOPT", days=91), sum.get_from_report("FOPT", 3)) + + self.assertEqual(sum.first_report, 1) + self.assertEqual(sum.last_report, 62) + + self.assertEqual(sum.get_report_time(10), datetime.date(2000, 10, 1)) + self.assertAlmostEqualScaled(sum.get_from_report("FOPT", 10), 6.67447e+06) + + @skipIf(ExtendedTestCase.slowTestShouldNotRun(), "Slow test skipped") + def test_fwrite(self): + # todo: What is tested here? + #work_area = TestArea("python/sum-test/fwrite", True) + with TestAreaContext("python/sum-test/fwrite", True): + self.ecl_sum.fwrite(ecl_case="CASE") + self.assertTrue(True) + + + def test_block(self): + sum = self.ecl_sum + index_ijk = sum.get_key_index("BPR:15,28,1") + index_num = sum.get_key_index("BPR:1095") + self.assertEqual(index_ijk, index_num) + + + def test_restart(self): + hist = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/history/T07-4A-W2011-18-P1")) + base = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE")) + pred = EclSum(self.createTestPath("Statoil/ECLIPSE/sum-restart/prediction/BASECASE"), include_restart=False) + + self.assertIsNotNone(hist) + self.assertIsNotNone(base) + self.assertIsNotNone(pred) + + + def test_case1(self ): + self.assertTrue(self.ecl_sum.path == self.createTestPath(path)) + self.assertTrue(self.ecl_sum.base == base) + self.assertTrue(self.ecl_sum.case == self.createTestPath(case)) + self.assertTrue(self.ecl_sum.abs_path == self.createTestPath(path)) + + + def test_case2( self ): + cwd = os.getcwd() + os.chdir(self.createTestPath(path)) + sum = EclSum(base) + self.assertIsNone(sum.path) + self.assertTrue(sum.base == base) + self.assertTrue(sum.case == base) + self.assertTrue(sum.abs_path == self.createTestPath(path)) + os.chdir(cwd) + + + def test_var_properties( self ): + sum = self.ecl_sum + self.assertRaises(KeyError, sum.smspec_node, "BJARNE") + + node = sum.smspec_node("FOPT") + self.assertTrue(node.is_total) + self.assertFalse(node.is_historical) + + node = sum.smspec_node("FOPR") + self.assertFalse(node.is_total) + self.assertFalse(node.is_historical) + self.assertTrue(node.keyword == "FOPR") + + node = sum.smspec_node("FOPRH") + self.assertFalse(node.is_total) + self.assertTrue(node.is_historical) + self.assertTrue(node.is_rate) + self.assertTrue(node.keyword == "FOPRH") + + node = sum.smspec_node("WOPR:OP_1") + self.assertFalse(node.is_total) + self.assertTrue(node.is_rate) + self.assertTrue(node.keyword == "WOPR") + + node = sum.smspec_node("WOPT:OP_1") + self.assertTrue(node.is_total) + self.assertFalse(node.is_rate) + self.assertTrue(node.unit == "SM3") + self.assertTrue(node.wgname == "OP_1") + self.assertTrue(node.keyword == "WOPT") + + self.assertTrue(sum.unit("FOPR") == "SM3/DAY") + + node = sum.smspec_node("FOPTH") + self.assertTrue(node.is_total) + self.assertFalse(node.is_rate) + self.assertIsNone(node.wgname) + + node = sum.smspec_node("FOPTH") + self.assertIsNone(node.num) + + node = sum.smspec_node("BPR:1095") + self.assertEquals(node.num, 1095) + + def test_stringlist_gc(self): + sum = EclSum(self.case) + wells = sum.wells() + well1 = wells[0] + del wells + self.assertTrue(well1 == "OP_1") + + + def test_stringlist_reference(self): + sum = EclSum(self.case) + wells = sum.wells() + self.assertAlmostEqualList(wells, ['OP_1', 'OP_2', 'OP_3', 'OP_4', 'OP_5', 'WI_1', 'WI_2', 'WI_3']) + self.assertIsInstance(wells, StringList) + + + def test_stringlist_setitem(self): + sum = EclSum(self.case) + wells = sum.wells() + wells[0] = "Bjarne" + well0 = wells[0] + self.assertTrue(well0 == "Bjarne") + self.assertTrue(wells[0] == "Bjarne") + wells[0] = "XXX" + self.assertTrue(well0 == "Bjarne") + self.assertTrue(wells[0] == "XXX") + + + def test_segment(self): + sum = EclSum(self.createTestPath("Statoil/ECLIPSE/Oseberg/F8MLT/F8MLT-F4")) + segment_vars = sum.keys("SOFR:F-8:*") + self.assertIn("SOFR:F-8:1", segment_vars) + for var in segment_vars: + tmp = var.split(":") + nr = int(tmp[2]) + self.assertTrue(nr >= 0) + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/run_tests.py b/ThirdParty/Ert/devel/python/test/ert_tests/run_tests.py new file mode 100644 index 0000000000..b232be1afd --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/run_tests.py @@ -0,0 +1,36 @@ +from unittest2 import TestLoader, TextTestRunner + + +def runTestsInDirectory(path="."): + loader = TestLoader() + tests = loader.discover(path) + testRunner = TextTestRunner() + testRunner.run(tests) + + +def runTestsInClass(classpath): + klass = importClass(classpath) + loader = TestLoader() + tests = loader.loadTestsFromTestCase(klass) + testRunner = TextTestRunner() + testRunner.run(tests) + + +def importClass(classpath): + dot = classpath.rfind(".") + classname = classpath[dot + 1:len(classpath)] + m = __import__(classpath[0:dot], globals(), locals(), [classname]) + return getattr(m, classname) + +def getTestsFromTestClass(test_class_path, argv=None): + klass = importClass(test_class_path) + klass.argv = argv + loader = TestLoader() + return loader.loadTestsFromTestCase(klass) + + +if __name__ == '__main__': + # runTestsInDirectory() + runTestsInClass("ert_tests.util.test_string_list.StringListTest") + + print(getTestsFromTestClass("ert_tests.util.test_string_list.StringListTest")) diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/sched/__init__.py b/ThirdParty/Ert/devel/python/test/ert_tests/sched/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/sched/test_sched.py b/ThirdParty/Ert/devel/python/test/ert_tests/sched/test_sched.py new file mode 100644 index 0000000000..1dcbeb5462 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/sched/test_sched.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# Copyright (C) 2012 Statoil ASA, Norway. +# +# The file 'test_sched.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +import datetime +import os +from ert.sched import SchedFile +from ert_tests import ExtendedTestCase + + + + +class SchedFileTest(ExtendedTestCase): + def setUp(self): + src_file = self.createTestPath("Statoil/ECLIPSE/Gurbat/target.SCH") + self.start_time = datetime.date(2000, 1, 1) + + self.sched_file = SchedFile(src_file, self.start_time) + self.file_list = [] + + def addFile( self, filename ): + self.file_list.append(filename) + + def tearDown(self): + for f in self.file_list: + if os.path.exists(f): + os.unlink(f) + + def test_load(self): + self.assertTrue(self.sched_file, "Load failed") + + + def test_length(self): + self.assertEqual(self.sched_file.length, 63) + + + def test_write_loop(self): + self.sched_file.write("/tmp/schedule1", 62) + sched_file2 = SchedFile("/tmp/schedule1", self.start_time) + sched_file2.write("/tmp/schedule2", 62) + self.assertFilesAreEqual("/tmp/schedule1", "/tmp/schedule2") + + self.addFile("/tmp/schedule1") + self.addFile("/tmp/schedule2") diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/test_ert_gui_import.py b/ThirdParty/Ert/devel/python/test/ert_tests/test_ert_gui_import.py new file mode 100644 index 0000000000..899816a8d4 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/test_ert_gui_import.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python +# Copyright (C) 2013 Statoil ASA, Norway. +# +# The file 'test_ert_gui_import.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +import traceback + +from ert_tests import ExtendedTestCase + + +class ErtGuiImportTest(ExtendedTestCase): + + def test_ert_gui(self): + self.assertImportable("ert_gui") + self.assertImportable("ert_gui.gert_main") + self.assertImportable("ert_gui.newconfig") + + def test_ert_gui_widgets(self): + self.assertImportable("ert_gui.widgets") + self.assertImportable("ert_gui.widgets.activelabel") + self.assertImportable("ert_gui.widgets.checkbox") + self.assertImportable("ert_gui.widgets.cogwheel") + self.assertImportable("ert_gui.widgets.combochoice") + self.assertImportable("ert_gui.widgets.configpanel") + self.assertImportable("ert_gui.widgets.help") + self.assertImportable("ert_gui.widgets.helpedwidget") + self.assertImportable("ert_gui.widgets.pathchooser") + self.assertImportable("ert_gui.widgets.reloadbutton") + self.assertImportable("ert_gui.widgets.searchablelist") + self.assertImportable("ert_gui.widgets.spinnerwidgets") + self.assertImportable("ert_gui.widgets.stringbox") + self.assertImportable("ert_gui.widgets.tablewidgets") + self.assertImportable("ert_gui.widgets.util") + self.assertImportable("ert_gui.widgets.validateddialog") + + def test_ert_gui_pages(self): + self.assertImportable("ert_gui.pages") + self.assertImportable("ert_gui.pages.application") + + def test_ert_gui_pages_init(self): + self.assertImportable("ert_gui.pages.init") + self.assertImportable("ert_gui.pages.init.initandcopy") + self.assertImportable("ert_gui.pages.init.initpanel") + + def test_ert_gui_pages_run(self): + self.assertImportable("ert_gui.pages.run") + self.assertImportable("ert_gui.pages.run.legend") + self.assertImportable("ert_gui.pages.run.runpanel") + self.assertImportable("ert_gui.pages.run.simulation") + self.assertImportable("ert_gui.pages.run.simulationsdialog") + + def test_ert_gui_pages_plot(self): + self.assertImportable("ert_gui.pages.plot") + self.assertImportable("ert_gui.pages.plot.ensemblefetcher") + self.assertImportable("ert_gui.pages.plot.fetcher") + self.assertImportable("ert_gui.pages.plot.plotconfig") + self.assertImportable("ert_gui.pages.plot.plotdata") + self.assertImportable("ert_gui.pages.plot.plotfigure") + self.assertImportable("ert_gui.pages.plot.plotgenerator") + self.assertImportable("ert_gui.pages.plot.plotpanel") + self.assertImportable("ert_gui.pages.plot.plotrenderer") + self.assertImportable("ert_gui.pages.plot.plotsettings") + self.assertImportable("ert_gui.pages.plot.plotsettingsxml") + self.assertImportable("ert_gui.pages.plot.plotview") + self.assertImportable("ert_gui.pages.plot.rftfetcher") + self.assertImportable("ert_gui.pages.plot.zoomslider") + + def test_ert_gui_pages_config(self): + self.assertImportable("ert_gui.pages.config") + self.assertImportable("ert_gui.pages.config.analysis") + self.assertImportable("ert_gui.pages.config.configpages") + self.assertImportable("ert_gui.pages.config.eclipse") + self.assertImportable("ert_gui.pages.config.ensemble") + self.assertImportable("ert_gui.pages.config.observations") + self.assertImportable("ert_gui.pages.config.plot") + self.assertImportable("ert_gui.pages.config.queuesystem") + self.assertImportable("ert_gui.pages.config.simulation") + self.assertImportable("ert_gui.pages.config.systemenv") + + def test_ert_gui_pages_config_jobs(self): + self.assertImportable("ert_gui.pages.config.jobs") + self.assertImportable("ert_gui.pages.config.jobs.forwardmodelpanel") + self.assertImportable("ert_gui.pages.config.jobs.jobsdialog") + self.assertImportable("ert_gui.pages.config.jobs.jobspanel") + + def test_ert_gui_pages_config_parameters(self): + self.assertImportable("ert_gui.pages.config.parameters") + self.assertImportable("ert_gui.pages.config.parameters.datapanel") + self.assertImportable("ert_gui.pages.config.parameters.fieldpanel") + self.assertImportable("ert_gui.pages.config.parameters.keywordpanel") + self.assertImportable("ert_gui.pages.config.parameters.parameterdialog") + self.assertImportable("ert_gui.pages.config.parameters.parametermodels") + self.assertImportable("ert_gui.pages.config.parameters.parameterpanel") + + def test_ert_gui_pages_config_simulations(self): + self.assertImportable("ert_gui.pages.config.simulations") + self.assertImportable("ert_gui.pages.config.simulations.runpathpanel") + self.assertImportable("ert_gui.pages.config.simulations.runtemplatepanel") diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/test_ert_import.py b/ThirdParty/Ert/devel/python/test/ert_tests/test_ert_import.py new file mode 100644 index 0000000000..e36e9847ad --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/test_ert_import.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python +# Copyright (C) 2013 Statoil ASA, Norway. +# +# The file 'test_ert_import.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. +import traceback + +from ert_tests import ExtendedTestCase + + +class ErtImportTest(ExtendedTestCase): + + def test_ert(self): + self.assertImportable("ert") + + def test_ert_config(self): + self.assertImportable("ert.config") + self.assertImportable("ert.config.config_enums") + self.assertImportable("ert.config.config_parser") + + def test_ert_cwrap(self): + self.assertImportable("ert.cwrap") + self.assertImportable("ert.cwrap.cclass") + self.assertImportable("ert.cwrap.cenum") + self.assertImportable("ert.cwrap.cfile") + self.assertImportable("ert.cwrap.clib") + self.assertImportable("ert.cwrap.cwrap") + + def test_ert_ecl(self): + self.assertImportable("ert.ecl") + self.assertImportable("ert.ecl.ecl") + self.assertImportable("ert.ecl.ecl_case") + self.assertImportable("ert.ecl.ecl_default") + self.assertImportable("ert.ecl.ecl_file") + self.assertImportable("ert.ecl.ecl_grav") + self.assertImportable("ert.ecl.ecl_grav_calc") + self.assertImportable("ert.ecl.ecl_grid") + self.assertImportable("ert.ecl.ecl_kw") + self.assertImportable("ert.ecl.ecl_local") + self.assertImportable("ert.ecl.ecl_queue") + self.assertImportable("ert.ecl.ecl_region") + self.assertImportable("ert.ecl.ecl_rft") + self.assertImportable("ert.ecl.ecl_rft_cell") + self.assertImportable("ert.ecl.ecl_subsidence") + self.assertImportable("ert.ecl.ecl_sum") + self.assertImportable("ert.ecl.ecl_util") + self.assertImportable("ert.ecl.fortio") + + + def test_ert_enkf(self): + self.assertImportable("ert.enkf") + self.assertImportable("ert.enkf.analysis_config") + self.assertImportable("ert.enkf.block_obs") + self.assertImportable("ert.enkf.ecl_config") + self.assertImportable("ert.enkf.enkf") + self.assertImportable("ert.enkf.enkf_config_node") + self.assertImportable("ert.enkf.enkf_enum") + self.assertImportable("ert.enkf.enkf_fs") + self.assertImportable("ert.enkf.enkf_main") + self.assertImportable("ert.enkf.enkf_node") + self.assertImportable("ert.enkf.enkf_obs") + self.assertImportable("ert.enkf.enkf_state") + self.assertImportable("ert.enkf.ens_config") + self.assertImportable("ert.enkf.ert_template") + self.assertImportable("ert.enkf.ert_templates") + self.assertImportable("ert.enkf.field") + self.assertImportable("ert.enkf.field_config") + self.assertImportable("ert.enkf.gen_data_config") + self.assertImportable("ert.enkf.gen_kw_config") + self.assertImportable("ert.enkf.libenkf") + self.assertImportable("ert.enkf.local_config") + self.assertImportable("ert.enkf.model_config") + self.assertImportable("ert.enkf.obs_vector") + self.assertImportable("ert.enkf.plot_conf") + self.assertImportable("ert.enkf.site_config") + self.assertImportable("ert.enkf.time_map") + + def test_ert_ert(self): + self.assertImportable("ert.ert") + self.assertImportable("ert.ert.c_enums") + self.assertImportable("ert.ert.enums") + self.assertImportable("ert.ert.erttypes") + self.assertImportable("ert.ert.ertwrapper") + + def test_ert_geo(self): + self.assertImportable("ert.geo") + self.assertImportable("ert.geo.geo_polygon") + + def test_ert_job_queue(self): + self.assertImportable("ert.job_queue") + self.assertImportable("ert.job_queue.driver") + self.assertImportable("ert.job_queue.ext_job") + self.assertImportable("ert.job_queue.ext_joblist") + self.assertImportable("ert.job_queue.forward_model") + self.assertImportable("ert.job_queue.job") + self.assertImportable("ert.job_queue.queue") + + def test_ert_rms(self): + self.assertImportable("ert.rms") + self.assertImportable("ert.rms.librms") + self.assertImportable("ert.rms.rms") + + def test_ert_sched(self): + self.assertImportable("ert.sched") + self.assertImportable("ert.sched.history") + self.assertImportable("ert.sched.sched_file") + + def test_ert_sched(self): + self.assertImportable("ert.util") + self.assertImportable("ert.util.buffer") + self.assertImportable("ert.util.ctime") + self.assertImportable("ert.util.hash") + self.assertImportable("ert.util.latex") + self.assertImportable("ert.util.log") + self.assertImportable("ert.util.lookup_table") + self.assertImportable("ert.util.matrix") + self.assertImportable("ert.util.stat") + self.assertImportable("ert.util.stringlist") + self.assertImportable("ert.util.test_area") + self.assertImportable("ert.util.tvector") + self.assertImportable("ert.util.util_func") + + def test_ert_well(self): + self.assertImportable("ert.well") + self.assertImportable("ert.well.libwell") + self.assertImportable("ert.well.well") + self.assertImportable("ert.well.well_info") + self.assertImportable("ert.well.well_state") + self.assertImportable("ert.well.well_ts") + + + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/__init__.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_ctime.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_ctime.py new file mode 100644 index 0000000000..f9250f98e6 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_ctime.py @@ -0,0 +1,17 @@ +from datetime import datetime +from unittest2 import TestCase +from ert.util import ctime + + +class CTimeTest(TestCase): + + def test_c_time(self): + c_time = ctime(0) + self.assertEqual(str(c_time), "1970-01-01 01:00:00") + + date_time = ctime(datetime(1970, 1, 1, 1, 0, 0)) + self.assertEqual(c_time, date_time) + + date_time_after = ctime(datetime(1970, 1, 1, 1, 0, 5)) + + self.assertTrue(date_time_after > date_time) \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_latex.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_latex.py new file mode 100644 index 0000000000..35d8d6d13a --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_latex.py @@ -0,0 +1,54 @@ +import os +from unittest2 import skip +from ert.util import LaTeX +from ert_tests import ExtendedTestCase + + +class LatexTest(ExtendedTestCase): + + def setUp(self): + self.local_path = self.createTestPath("local/util/latex") + self.statoil_path = self.createTestPath("Statoil/util/latex") + + + def test_simple_compile(self): + lx = LaTeX("%s/test_OK.tex" % self.local_path) + self.assertTrue(lx.compile()) + + lx = LaTeX("%s/test_error.tex" % self.local_path) + self.assertFalse(lx.compile()) + + @skip("Unknown errors!") + def test_cleanup( self ): + lx = LaTeX("%s/report_OK.tex" % self.statoil_path, in_place=True) + self.assertTrue(lx.in_place) + self.assertTrue(lx.compile()) + for ext in ["log", "aux", "nav", "out", "snm", "toc"]: + self.assertFalse(os.path.exists("%s/report_OK.%s" % (self.statoil_path, ext))) + + lx = LaTeX("%s/report_OK.tex" % self.statoil_path, in_place=False) + self.assertFalse(lx.in_place) + run_path = lx.runpath + self.assertTrue(lx.compile()) + self.assertFalse(os.path.exists(run_path)) + + lx = LaTeX("%s/report_OK.tex" % self.statoil_path, in_place=False) + run_path = lx.runpath + self.assertTrue(lx.compile(cleanup=False)) + self.assertTrue(os.path.exists("%s/report_OK.log" % run_path)) + + + @skip("Unknown errors!") + def test_report(self): + lx = LaTeX("%s/report_error.tex" % self.statoil_path) + lx.timeout = 4 + self.assertFalse(lx.compile()) + + lx = LaTeX("%s/report_OK.tex" % self.statoil_path) + self.assertTrue(lx.compile()) + + @skip("Unknown errors!") + def test_target(self): + lx = LaTeX("%s/report_OK.tex" % self.statoil_path) + self.assertTrue(lx.compile()) + self.assertTrue(os.path.exists(lx.target)) \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_lookup_table.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_lookup_table.py new file mode 100644 index 0000000000..aa225e8ff3 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_lookup_table.py @@ -0,0 +1,40 @@ +from unittest2 import TestCase +from ert.util import LookupTable +import numpy + +class LookupTableTest(TestCase): + + def test_lookup_table_no_values(self): + lookup = LookupTable() + + self.assertTrue(numpy.isnan(lookup.max)) + self.assertTrue(numpy.isnan(lookup.min)) + self.assertTrue(numpy.isnan(lookup.arg_max)) + self.assertTrue(numpy.isnan(lookup.arg_min)) + self.assertEqual(len(lookup), 0) + + + lookup.append(0.0, 0.0) + lookup.append(1.0, 10.0) + + def test_lookup_table_min_and_max(self): + lookup = LookupTable() + + lookup.append(0.0, 0.0) + lookup.append(1.0, 10.0) + + self.assertEqual(lookup.max, 10.0) + self.assertEqual(lookup.min, 0.0) + self.assertEqual(lookup.arg_max, 1.0) + self.assertEqual(lookup.arg_min, 0.0) + self.assertEqual(len(lookup), 2) + + + def test_lookup_table_interpolation(self): + lookup = LookupTable() + + lookup.append(0.0, 0.0) + lookup.append(1.0, 10.0) + + self.assertEqual(lookup.interp(0.5), 5.0) + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_matrix.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_matrix.py new file mode 100644 index 0000000000..f1ef5c9667 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_matrix.py @@ -0,0 +1,22 @@ +from ert.util import Matrix +from unittest2 import TestCase + +class MatrixTest(TestCase): + def test_matrix(self): + m = Matrix(2, 2) + + self.assertEqual(m[(0, 0)], 0) + + m[(1, 1)] = 1.5 + self.assertEqual(m[(1, 1)], 1.5) + + m[1,0] = 5 + self.assertEqual(m[1, 0], 5) + + with self.assertRaises(TypeError): + m[5] = 5 + + #todo: random crashes happens if we do this... + #m[2, 2] = 2 # no exception raised... + + diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_stat.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_stat.py new file mode 100644 index 0000000000..dab76c3a76 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_stat.py @@ -0,0 +1,21 @@ +import random +from ert.util import DoubleVector, quantile, quantile_sorted +from ert_tests import ExtendedTestCase + + +class StatTest(ExtendedTestCase): + def test_stat_quantiles(self): + v = DoubleVector() + for i in range(100000): + v.append(random.random()) + + self.assertAlmostEqual(quantile(v, 0.1), 0.1, 2) + self.assertAlmostEqual(quantile_sorted(v, 0.2), 0.2, 2) + self.assertAlmostEqual(quantile_sorted(v, 0.3), 0.3, 2) + self.assertAlmostEqual(quantile_sorted(v, 0.4), 0.4, 2) + self.assertAlmostEqual(quantile_sorted(v, 0.5), 0.5, 2) + # print quantile( v , 0.10 ) + # print quantile_sorted( v , 0.20 ) + # print quantile_sorted( v , 0.30 ) + # print quantile_sorted( v , 0.40 ) + # print quantile_sorted( v , 0.50 ) \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_string_list.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_string_list.py new file mode 100644 index 0000000000..f5fa635290 --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_string_list.py @@ -0,0 +1,75 @@ +from unittest2 import TestCase +from ert.util import StringList + + +class StringListTest(TestCase): + def test_del(self): + s = StringList( initial = ["A", "list"] ) + internal_list_of_strings = s.strings + python_list_of_strings = list(s) + + self.assertEqual(internal_list_of_strings, python_list_of_strings) + + del s + + self.assertEqual(python_list_of_strings, ["A", "list"]) + + def test_iterate(self): + s = ["A", "list", "of", "strings"] + s1 = StringList(initial=s) + s2 = s1.strings + s3 = list(s1) + + for index in range(len(s1)): + self.assertEqual(s[index], s1[index]) + + for index in range(len(s2)): + self.assertEqual(s[index], s2[index]) + + for index in range(len(s3)): + self.assertEqual(s[index], s3[index]) + + + def test_pop( self ): + s = StringList(initial=["A", "list", "of", "strings"]) + s1 = s.pop() + self.assertTrue(len(s) == 3) + self.assertTrue(s1 == "strings") + + s1 = s.pop() + self.assertTrue(len(s) == 2) + self.assertTrue(s1 == "of") + + s1 = s.pop() + self.assertTrue(len(s) == 1) + self.assertTrue(s1 == "list") + + s1 = s.pop() + self.assertTrue(len(s) == 0) + self.assertTrue(s1 == "A") + + with self.assertRaises(IndexError): + s.pop() + + def test_last(self): + s = StringList(initial=["A", "list", "of", "strings"]) + self.assertEqual(s.last, "strings") + + with self.assertRaises(IndexError): + s.pop() + s.pop() + s.pop() + s.pop() + s.last + + + def test_in_and_not_in(self): + s = StringList(["A", "list", "of", "strings"]) + + self.assertTrue("A" in s) + self.assertTrue("Bjarne" not in s) + + def test_append(self): + s = StringList(["A", "B"]) + s.append("C") + self.assertEqual(list(s), ["A", "B", "C"]) \ No newline at end of file diff --git a/ThirdParty/Ert/devel/python/test/ert_tests/util/test_vectors.py b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_vectors.py new file mode 100644 index 0000000000..e056db9fea --- /dev/null +++ b/ThirdParty/Ert/devel/python/test/ert_tests/util/test_vectors.py @@ -0,0 +1,216 @@ +#!/usr/bin/env python +# Copyright (C) 2011 Statoil ASA, Norway. +# +# The file 'test_vectors.py' is part of ERT - Ensemble based Reservoir Tool. +# +# ERT 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. +# +# ERT 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. + + +import copy +from datetime import datetime +from unittest2 import TestCase + +from ert.util import DoubleVector, IntVector, BoolVector, TimeVector, ctime + + +class UtilTest(TestCase): + def test_double_vector(self): + v = DoubleVector() + + v[0] = 77.25 + v[1] = 123.25 + v[2] = 66.25 + v[3] = 56.25 + v[4] = 111.25 + v[5] = 99.25 + v[12] = 12 + + self.assertEqual(len(v), 13) + self.assertEqual(list(v), [v[0], v[1], v[2], v[3], v[4], v[5], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, v[12]]) + + v.clear() + self.assertEqual(len(v), 0) + + v.clear() + + v[0] = 0.1 + v[1] = 0.2 + v[2] = 0.4 + v[3] = 0.8 + + v2 = v * 2 + + self.assertEqual(list(v2), [v[0] * 2, v[1] * 2, v[2] * 2, v[3] * 2]) + + v2 += v + self.assertEqual(list(v2), [v[0] * 3, v[1] * 3, v[2] * 3, v[3] * 3]) + + v2.assign(0.66) + self.assertEqual(list(v2), [0.66, 0.66, 0.66, 0.66]) + + v.assign(v2) + self.assertEqual(list(v), [0.66, 0.66, 0.66, 0.66]) + + v.clear() + v.default = 0.75 + self.assertEqual(v.default, 0.75) + v[2] = 0.0 + self.assertEqual(v[1], 0.75) + + + + def test_vector_operations_with_exceptions(self): + iv1 = IntVector() + iv1.append(1) + iv1.append(2) + iv1.append(3) + + iv2 = IntVector() + iv2.append(4) + iv2.append(5) + + dv1 = DoubleVector() + dv1.append(0.5) + dv1.append(0.75) + dv1.append(0.25) + + #Size mismatch + with self.assertRaises(ValueError): + iv3 = iv1 + iv2 + + #Size mismatch + with self.assertRaises(ValueError): + iv3 = iv1 * iv2 + + #Type mismatch + with self.assertRaises(TypeError): + iv1 += dv1 + + #Type mismatch + with self.assertRaises(TypeError): + iv1 *= dv1 + + + def test_bool_vector(self): + b = BoolVector() + b.default = True + + b[4] = False + + self.assertEqual(list(b), [True, True, True, True, False]) + + + def test_activeList(self): + active_list = IntVector.active_list("1,10,100-105") + self.assertTrue(len(active_list) == 8) + self.assertTrue(active_list[0] == 1) + self.assertTrue(active_list[2] == 100) + self.assertTrue(active_list[7] == 105) + + active_list = IntVector.active_list("1,10,100-105X") + self.assertFalse(active_list) + + + def test_activeMask(self): + active_list = BoolVector.active_mask("1 , 4 - 7 , 10") + self.assertTrue(len(active_list) == 11) + self.assertTrue(active_list[1]) + self.assertTrue(active_list[4]) + self.assertTrue(active_list[10]) + self.assertFalse(active_list[9]) + self.assertFalse(active_list[8]) + + active_list = BoolVector.active_mask("1,4-7,10X") + self.assertFalse(active_list) + + + + + def test_int_vector(self): + a = IntVector() + a.append(1) + a.append(2) + a.append(3) + a.append(4) + a.append(5) + + self.assertEqual(list(a), [1, 2, 3, 4, 5]) + + a.rsort() + self.assertEqual(list(a), [5, 4, 3, 2, 1]) + + self.assertTrue(a.max, 5) + self.assertTrue(a.min, 1) + self.assertTrue(a.min_index(), 4) + + self.assertEqual(a.max_index(reverse=True), 0) + self.assertEqual(a.max_index(reverse=False), 0) + + a[4] = 5 + self.assertTrue(a[4] == 5) + + a_plus_one = a + 1 + self.assertEqual(list(a_plus_one), [6, 5, 4, 3, 6]) + + sliced = a[0:3] + self.assertEqual(list(sliced), [5, 4, 3]) + + with self.assertRaises(IndexError): + item = a[6] + + copy_of_a = copy.deepcopy(a) + self.assertEqual(list(a), list(copy_of_a)) + + another_copy_of_a = copy.copy(a) + self.assertEqual(list(a), list(another_copy_of_a)) + + + def test_div(self): + v = IntVector() + v[0] = 100 + v[1] = 10 + v[2] = 1 + v /= 10 + + self.assertEqual(list(v), [10, 1, 0]) + + + def test_true(self): + iv = IntVector() + self.assertFalse(iv) # Will invoke the __len__ function; could override with __nonzero__ + iv[0] = 1 + self.assertTrue(iv) + + + def test_asPythonObject(self): + v = DoubleVector.asPythonObject(0, DoubleVector.free) + + self.assertIsInstance(v, DoubleVector) + self.assertIsNotNone(v.cfree) + + + def test_time_vector(self): + time_vector = TimeVector() + + time1 = ctime(datetime(2013, 8, 13, 0, 0, 0)) + time2 = ctime(datetime(2013, 8, 13, 1, 0, 0)) + + time_vector.default = time2 + + time_vector.append(time1) + time_vector[2] = time2 + + self.assertEqual(time_vector[0], time1) + self.assertEqual(time_vector[1], time2) + self.assertEqual(time_vector[2], time2) + diff --git a/ThirdParty/Ert/devel/python/test/file_test.py b/ThirdParty/Ert/devel/python/test/file_test.py deleted file mode 100644 index bf80c7219e..0000000000 --- a/ThirdParty/Ert/devel/python/test/file_test.py +++ /dev/null @@ -1,146 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'sum_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import filecmp -import datetime -import unittest -import shutil -import time -import os -import os.path -import ert -import ert.ecl.ecl as ecl -from test_util import approx_equal, approx_equalv, file_equal - - -file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" -fmt_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.FUNRST" - -def load_missing(): - ecl.EclFile( "No/Does/not/exist") - - -class FileTest( unittest.TestCase ): - - def setUp(self): - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - - def testIOError(self): - self.assertRaises( IOError , load_missing) - - - def test_fwrite( self ): - self.addFile( "/tmp/ECLIPSE.UNRST" ) - rst_file = ecl.EclFile( file ) - fortio = ecl.FortIO.writer("/tmp/ECLIPSE.UNRST") - rst_file.fwrite( fortio ) - fortio.close() - rst_file.close() - self.assertTrue( file_equal( "/tmp/ECLIPSE.UNRST" , file ) ) - - - def test_save(self): - self.addFile( "/tmp/ECLIPSE.UNRST" ) - shutil.copyfile( file , "/tmp/ECLIPSE.UNRST" ) - rst_file = ecl.EclFile( "/tmp/ECLIPSE.UNRST" , flags = ecl.ECL_FILE_WRITABLE ) - swat0 = rst_file["SWAT"][0] - swat0.assign( 0.75 ) - rst_file.save_kw( swat0 ) - rst_file.close( ) - self.assertFalse( file_equal( "/tmp/ECLIPSE.UNRST" , file ) ) - - rst_file1 = ecl.EclFile( file ) - rst_file2 = ecl.EclFile( "/tmp/ECLIPSE.UNRST" , flags = ecl.ECL_FILE_WRITABLE) - - swat1 = rst_file1["SWAT"][0] - swat2 = rst_file2["SWAT"][0] - swat2.assign( swat1 ) - - rst_file2.save_kw( swat2 ) - self.assertTrue( swat1.equal( swat2 )) - rst_file1.close() - rst_file2.close() - - # Random failure .... - self.assertTrue( file_equal( "/tmp/ECLIPSE.UNRST" , file ) ) - - - def test_save_fmt(self): - self.addFile( "/tmp/ECLIPSE.FUNRST" ) - shutil.copyfile( fmt_file , "/tmp/ECLIPSE.FUNRST" ) - rst_file = ecl.EclFile( "/tmp/ECLIPSE.FUNRST" , flags = ecl.ECL_FILE_WRITABLE) - swat0 = rst_file["SWAT"][0] - swat0.assign( 0.75 ) - rst_file.save_kw( swat0 ) - rst_file.close( ) - self.assertFalse( file_equal( "/tmp/ECLIPSE.FUNRST" , fmt_file ) ) - - rst_file1 = ecl.EclFile( fmt_file ) - rst_file2 = ecl.EclFile( "/tmp/ECLIPSE.FUNRST" , flags = ecl.ECL_FILE_WRITABLE) - - swat1 = rst_file1["SWAT"][0] - swat2 = rst_file2["SWAT"][0] - - swat2.assign( swat1 ) - rst_file2.save_kw( swat2 ) - self.assertTrue( swat1.equal( swat2 )) - rst_file1.close() - rst_file2.close() - - # Random failure .... - self.assertTrue( file_equal( "/tmp/ECLIPSE.FUNRST" , fmt_file ) ) - - - -def slow_suite(): - suite = unittest.TestSuite() - suite.addTest( FileTest( 'test_save' )) - suite.addTest( FileTest( 'test_save_fmt' )) - return suite - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( FileTest( 'testIOError' )) - suite.addTest( FileTest( 'test_fwrite' )) - return suite - - - - -def test_suite( argv ): - test_list = fast_suite() - if argv: - if argv[0][0] == "T": - for t in slow_suite(): - test_list.addTest( t ) - return test_list - - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - unittest.TextTestRunner().run( slow_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/fortio_test.py b/ThirdParty/Ert/devel/python/test/fortio_test.py deleted file mode 100644 index 40bc1fed7c..0000000000 --- a/ThirdParty/Ert/devel/python/test/fortio_test.py +++ /dev/null @@ -1,101 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'kw_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import os -import unittest -import stat -import math -import ert -import ert.ecl.ecl as ecl -import sys - - -unrst_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" - -def open_noex(): - f = ecl.FortIO.reader("/tmp/does/notExist") - - -class FortIOTest( unittest.TestCase ): - - def setUp(self): - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - - def test_open_read(self): - f = ecl.FortIO.reader(unrst_file) - self.assertTrue( f ) - - - def test_open_write(self): - self.addFile( "/tmp/newfile" ) - f = ecl.FortIO.writer("/tmp/newfile") - f.close() - self.assertTrue( True ) - - def test_noex(self): - self.assertRaises( IOError , open_noex) - - def test_kw(self): - self.addFile( "/tmp/test" ) - kw1 = ecl.EclKW.create( "KW1" , 2 , ecl.ECL_INT_TYPE ) - kw2 = ecl.EclKW.create( "KW2" , 2 , ecl.ECL_INT_TYPE ) - - kw1[0] = 99 - kw1[1] = 77 - kw2[0] = 113 - kw2[1] = 335 - - f = ecl.FortIO.writer( "/tmp/test" , fmt_file = False) - kw1.fwrite( f ) - f.close() - - f = ecl.FortIO.open( "/tmp/test" , mode = "a") - kw2.fwrite( f ) - f.close() - - f = ecl.FortIO.open( "/tmp/test" , fmt_file = False) - k1 = ecl.EclKW.fread( f ) - k2 = ecl.EclKW.fread( f ) - f.close() - - self.assertTrue( k1.equal( kw1 )) - self.assertTrue( k2.equal( kw2 )) - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( FortIOTest('test_open_read')) - suite.addTest( FortIOTest('test_open_write')) - suite.addTest( FortIOTest('test_noex')) - suite.addTest( FortIOTest('test_kw')) - return suite - - - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/grdecl_test.py b/ThirdParty/Ert/devel/python/test/grdecl_test.py deleted file mode 100644 index 5860bd30b7..0000000000 --- a/ThirdParty/Ert/devel/python/test/grdecl_test.py +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'sum_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import datetime -import unittest -import ert -import os -import ert.ecl.ecl as ecl -from test_util import approx_equal, approx_equalv, file_equal - - -src_file = "test-data/Statoil/ECLIPSE/Gurbat/include/example_permx.GRDECL" - - -class GRDECLTest( unittest.TestCase ): - - def setUp(self): - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - - - def testLoad( self ): - kw = ecl.EclKW.read_grdecl( open( src_file , "r") , "PERMX") - self.assertTrue( kw ) - - - def testReLoad( self ): - kw = ecl.EclKW.read_grdecl( open( src_file , "r") , "PERMX") - tmp_file1 = "/tmp/permx1.grdecl" - tmp_file2 = "/tmp/permx2.grdecl" - self.addFile( tmp_file1 ) - self.addFile( tmp_file2 ) - - fileH = open( tmp_file1 , "w") - kw.write_grdecl( fileH ) - fileH.close() - - kw1 = ecl.EclKW.read_grdecl( open( tmp_file1 , "r") , "PERMX") - - fileH = open( tmp_file2 , "w") - kw1.write_grdecl( fileH ) - fileH.close() - - self.assertTrue( file_equal( tmp_file1 , tmp_file2 )) - - - - def test_fseek( self ): - file = open( src_file , "r") - self.assertTrue( ecl.EclKW.fseek_grdecl( file , "PERMX" ) ) - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMY" ) ) - file.close() - - file = open( src_file , "r") - kw1 = ecl.EclKW.read_grdecl( file , "PERMX") - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMX" ) ) - self.assertTrue( ecl.EclKW.fseek_grdecl( file , "PERMX" , rewind = True) ) - file.close() - - - - def test_fseek2(self): - test_src = "test-data/local/ECLIPSE/grdecl-test/test.grdecl" - # Test kw at the the very start - file = open( test_src , "r") - self.assertTrue( ecl.EclKW.fseek_grdecl( file , "PERMX" ) ) - - # Test commented out kw: - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMY" ) ) - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMZ" ) ) - - # Test ignore not start of line: - self.assertTrue( ecl.EclKW.fseek_grdecl( file , "MARKER" ) ) - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMXYZ" ) ) - - # Test rewind - self.assertFalse(ecl.EclKW.fseek_grdecl( file , "PERMX" , rewind = False) ) - self.assertTrue(ecl.EclKW.fseek_grdecl( file , "PERMX" , rewind = True) ) - - # Test multiline comments + blanks - self.assertTrue(ecl.EclKW.fseek_grdecl( file , "LASTKW" ) ) - - - def test_fseek_dos(self): - test_src = "test-data/local/ECLIPSE/grdecl-test/test.grdecl_dos" # File formatted with \r\n line endings. - # Test kw at the the very start - file = open( test_src , "r") - self.assertTrue( ecl.EclKW.fseek_grdecl( file , "PERMX" ) ) - - # Test commented out kw: - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMY" ) ) - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMZ" ) ) - - # Test ignore not start of line: - self.assertTrue( ecl.EclKW.fseek_grdecl( file , "MARKER" ) ) - self.assertFalse( ecl.EclKW.fseek_grdecl( file , "PERMXYZ" ) ) - - # Test rewind - self.assertFalse(ecl.EclKW.fseek_grdecl( file , "PERMX" , rewind = False) ) - self.assertTrue(ecl.EclKW.fseek_grdecl( file , "PERMX" , rewind = True) ) - - # Test multiline comments + blanks - self.assertTrue(ecl.EclKW.fseek_grdecl( file , "LASTKW" ) ) - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( GRDECLTest( 'testLoad' )) - suite.addTest( GRDECLTest( 'testReLoad' )) - suite.addTest( GRDECLTest( 'test_fseek' )) - suite.addTest( GRDECLTest( 'test_fseek_dos' )) - return suite - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/grid_test.py b/ThirdParty/Ert/devel/python/test/grid_test.py deleted file mode 100644 index 10f35d67df..0000000000 --- a/ThirdParty/Ert/devel/python/test/grid_test.py +++ /dev/null @@ -1,234 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'grid_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import sys -import ert -import ert.ecl.ecl as ecl -import datetime -import time -import os -import unittest -import ert -import ert.ecl.ecl as ecl -from ert.util.tvector import DoubleVector -from ert.util.tvector import DoubleVector -from numpy import isnan -from test_util import approx_equal, approx_equalv - -egrid_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID" -grid_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.GRID" -grdecl_file = "test-data/Statoil/ECLIPSE/Gurbat/include/example_grid_sim.GRDECL" - -class GridTest( unittest.TestCase ): - - def setUp(self): - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - def testGRID( self ): - grid = ecl.EclGrid( grid_file ) - self.assertTrue( grid ) - - - def testEGRID( self ): - grid = ecl.EclGrid( egrid_file ) - self.assertTrue( grid ) - - - def create(self , filename , load_actnum = True): - fileH = open( filename , "r") - specgrid = ecl.EclKW.read_grdecl( fileH , "SPECGRID" , ecl_type = ecl.ECL_INT_TYPE , strict = False) - zcorn = ecl.EclKW.read_grdecl( fileH , "ZCORN" ) - coord = ecl.EclKW.read_grdecl( fileH , "COORD" ) - if load_actnum: - actnum = ecl.EclKW.read_grdecl( fileH , "ACTNUM" , ecl_type = ecl.ECL_INT_TYPE ) - else: - actnum = None - - mapaxes = ecl.EclKW.read_grdecl( fileH , "MAPAXES" ) - grid = ecl.EclGrid.create( specgrid , zcorn , coord , actnum , mapaxes = mapaxes) - return grid - - - def testRect(self): - a1 = 1.0 - a2 = 2.0 - a3 = 3.0 - grid = ecl.EclGrid.create_rectangular((9,9,9) , (a1,a2,a3)) - grid.save_EGRID( "/tmp/rect.EGRID" ) - grid2 = ecl.EclGrid( "/tmp/rect.EGRID") - self.addFile( "/tmp/rect.EGRID" ) - self.assertTrue( grid ) - self.assertTrue( grid2 ) - - (x,y,z) = grid.get_xyz( ijk=(4,4,4) ) - self.assertTrue( approx_equalv( [x,y,z],[4.5 * a1,4.5*a2,4.5*a3] )) - - v = grid.cell_volume( ijk=(4,4,4) ) - self.assertTrue( approx_equal( v , a1*a2*a3 )) - - z = grid.depth( ijk = (4,4,4 )) - self.assertTrue( approx_equal( z , 4.5*a3 )) - - g1 = grid.global_index( ijk = (2,2,2) ) - g2 = grid.global_index( ijk = (4,4,4) ) - (dx,dy,dz) = grid.distance( g2 , g1 ) - self.assertTrue( approx_equalv([dx,dy,dz],[2*a1,2*a2,2*a3] ) ) - - self.assertTrue( grid.cell_contains(2.5*a1 , 2.5*a2, 2.5*a3 , ijk=(2,2,2))) - - ijk = grid.find_cell( 1.5*a1 , 2.5*a2, 3.5*a3 ) - self.assertTrue( approx_equalv( ijk , [1 , 2 , 3])) - - - - def testCreate(self): - grid = self.create( grdecl_file ) - self.assertTrue( grid ) - - - def testACTNUM(self): - g1 = self.create( grdecl_file ) - g2 = self.create( grdecl_file , load_actnum = False ) - self.assertTrue( g1.equal( g2 ) ) - - - def testTime(self): - t0 = time.clock() - g1 = ecl.EclGrid( egrid_file ) - t1 = time.clock() - t = t1 - t0 - self.assertTrue( t < 1.0 ) - - - def testSave(self): - self.addFile( "/tmp/test.EGRID" ) - self.addFile( "/tmp/test.GRID" ) - self.addFile( "/tmp/test.grdecl" ) - - g1 = ecl.EclGrid( egrid_file ) - - g1.save_EGRID( "/tmp/test.EGRID" ) - g2 = ecl.EclGrid( "/tmp/test.EGRID" ) - self.assertTrue( g1.equal( g2 ) ) - - g1.save_GRID( "/tmp/test.GRID" ) - g2 = ecl.EclGrid( "/tmp/test.GRID" ) - self.assertTrue( g1.equal( g2 ) ) - - fileH = open("/tmp/test.grdecl" , "w") - g1.save_grdecl( fileH ) - fileH.close() - g2 = self.create( "/tmp/test.grdecl" ) - self.assertTrue( g1.equal( g2 ) ) - - - def testCoarse(self): - self.addFile( "/tmp/LGC.EGRID" ) - self.addFile( "/tmp/LGC.GRID" ) - - testGRID = True - g1 = ecl.EclGrid( "test-data/Statoil/ECLIPSE/LGCcase/LGC_TESTCASE2.EGRID" ) - - g1.save_EGRID( "/tmp/LGC.EGRID" ) - g2 = ecl.EclGrid( "/tmp/LGC.EGRID") - self.assertTrue( g1.equal(g2, verbose = True) ) - - if testGRID: - g1.save_GRID( "/tmp/LGC.GRID" ) - g3 = ecl.EclGrid( "/tmp/LGC.GRID") - self.assertTrue( g1.equal(g3 , verbose = True) ) - - self.assertTrue( g1.coarse_groups() == 3384) - - - - def testDual(self): - grid = ecl.EclGrid( egrid_file ) - self.assertFalse( grid.dual_grid ) - self.assertTrue( grid.nactive_fracture == 0 ) - - grid2 = ecl.EclGrid( grid_file ) - self.assertFalse( grid.dual_grid ) - self.assertTrue( grid.nactive_fracture == 0 ) - - dgrid = ecl.EclGrid( "test-data/Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.EGRID" ) - self.assertTrue( dgrid.nactive == dgrid.nactive_fracture ) - self.assertTrue( dgrid.nactive == 46118 ) - - dgrid2 = ecl.EclGrid( "test-data/Statoil/ECLIPSE/DualPoro/DUALPOR_MSW.GRID" ) - self.assertTrue( dgrid.nactive == dgrid.nactive_fracture ) - self.assertTrue( dgrid.nactive == 46118 ) - self.assertTrue( dgrid.equal( dgrid2 )) - - - # The DUAL_DIFF grid has been manipulated to create a - # situation where some cells are only matrix active, and some - # cells are only fracture active. - dgrid = ecl.EclGrid( "test-data/Statoil/ECLIPSE/DualPoro/DUAL_DIFF.EGRID" ) - self.assertTrue( dgrid.nactive == 106 ) - self.assertTrue( dgrid.nactive_fracture == 105 ) - - self.assertTrue( dgrid.get_active_fracture_index( global_index = 0 ) == -1 ) - self.assertTrue( dgrid.get_active_fracture_index( global_index = 2 ) == -1 ) - self.assertTrue( dgrid.get_active_fracture_index( global_index = 3 ) == 0 ) - self.assertTrue( dgrid.get_active_fracture_index( global_index = 107 ) == 104) - - self.assertTrue( dgrid.get_active_index( global_index = 1 ) == 1) - self.assertTrue( dgrid.get_active_index( global_index = 105 ) == 105) - self.assertTrue( dgrid.get_active_index( global_index = 106 ) == -1) - self.assertTrue( dgrid.get_global_index1F( 2 ) == 5 ) - - self.addFile( "/tmp/DUAL_DIFF.GRID" ) - dgrid.save_GRID("/tmp/DUAL_DIFF.GRID") - dgrid2 = ecl.EclGrid( "/tmp/DUAL_DIFF.GRID" ) - self.assertTrue( dgrid.equal( dgrid2 )) - - - - - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( GridTest( 'testDual' )) - suite.addTest( GridTest( 'testGRID' )) - suite.addTest( GridTest( 'testEGRID' )) - suite.addTest( GridTest( 'testCreate' )) - - suite.addTest( GridTest( 'testSave' )) - suite.addTest( GridTest( 'testTime' )) - suite.addTest( GridTest( 'testACTNUM') ) - suite.addTest( GridTest( 'testRect' )) - suite.addTest( GridTest( 'testCoarse' )) - return suite - -def test_suite(argv): - return fast_suite() - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/import_test.py b/ThirdParty/Ert/devel/python/test/import_test.py deleted file mode 100644 index ddb049ec2b..0000000000 --- a/ThirdParty/Ert/devel/python/test/import_test.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'import_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - - -def test_import( module ): - print "Importing: %s ..." % module , - __import__( module ) - print - - -test_import( "ert" ) - -test_import( "ert.cwrap" ) -test_import( "ert.ecl" ) -test_import( "ert.util" ) -test_import( "ert.geo" ) -test_import( "ert.config" ) -test_import( "ert.job_queue" ) -test_import( "ert.rms" ) -test_import( "ert.enkf" ) -test_import( "ert.sched" ) -test_import( "ert.well") - -test_import("ert.ecl.ecl") -test_import("ert.rms.rms") -test_import("ert.enkf.enkf") -test_import("ert.config.config") -test_import("ert.job_queue.job_queue") -test_import("ert.geo.geo") -test_import("ert.well.well") - - -def test_suite( argv ): - return False diff --git a/ThirdParty/Ert/devel/python/test/kw_test.py b/ThirdParty/Ert/devel/python/test/kw_test.py deleted file mode 100644 index 8b64501de3..0000000000 --- a/ThirdParty/Ert/devel/python/test/kw_test.py +++ /dev/null @@ -1,276 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'kw_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import os -import unittest -import stat -import math -import ert -import ert.ecl.ecl as ecl -import sys -from test_util import * - -def copy_long(): - src = ecl.EclKW.create("NAME" , 100 , ecl.ECL_FLOAT_TYPE ) - copy = src.sub_copy( 0 , 2000 ) - - -def copy_offset(): - src = ecl.EclKW.create("NAME" , 100 , ecl.ECL_FLOAT_TYPE ) - copy = src.sub_copy( 200 , 100 ) - - - - -class KWTest( unittest.TestCase ): - - def setUp( self ): - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - - def fortio_size( self ): - unrst_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" - file = ecl.EclFile( unrst_file ) - size = 0 - for kw in file: - size += kw.fortio_size - - stat = os.stat( unrst_file) - self.assertTrue( size == stat.st_size ) - - - def test_equal(self): - kw1 = ecl.EclKW.new( "TEST" , 3 , ecl.ECL_CHAR_TYPE ) - kw1[0] = "Test1" - kw1[1] = "Test13" - kw1[2] = "Test15" - - kw2 = ecl.EclKW.new( "TEST" , 3 , ecl.ECL_CHAR_TYPE ) - kw2[0] = "Test1" - kw2[1] = "Test13" - kw2[2] = "Test15" - - self.assertTrue( kw1.equal(kw2) ) - self.assertTrue( kw1.equal_numeric( kw2 )) - - kw2[2] = "Test15X" - self.assertFalse( kw1.equal(kw2) ) - self.assertFalse( kw1.equal_numeric( kw2 )) - - unrst_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" - file = ecl.EclFile( unrst_file ) - kw1 = file["PRESSURE"][0] - kw2 = kw1.deep_copy() - - self.assertTrue( kw1.equal(kw2) ) - self.assertTrue( kw1.equal_numeric( kw2 )) - - kw2 *= 1.00001 - self.assertFalse( kw1.equal(kw2) ) - self.assertFalse( kw1.equal_numeric( kw2 , epsilon = 1e-8)) - self.assertTrue( kw1.equal_numeric( kw2 , epsilon = 1e-2)) - - kw1 = file["ICON"][10] - kw2 = kw1.deep_copy() - self.assertTrue( kw1.equal(kw2) ) - self.assertTrue( kw1.equal_numeric( kw2 )) - - kw1[-1] += 1 - self.assertFalse( kw1.equal(kw2) ) - self.assertFalse( kw1.equal_numeric( kw2 )) - - - def test_kw( self , type , data , fmt ): - name1 = "/tmp/file1.txt" - name2 = "/tmp/file2.txt" - kw = ecl.EclKW.new( "TEST" , len(data) , type) - i = 0 - for d in data: - kw[i] = d - i += 1 - - file1 = open(name1 , "w") - kw.fprintf_data( file1 , fmt ) - file1.close() - - - - file2 = open(name2 , "w") - for d in data: - file2.write( fmt % d ) - file2.close() - self.assertTrue( file_equal( name1 , name2) ) - self.addFile( name1 ) - self.addFile( name2 ) - - - def testSubCopy(self): - unrst_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" - file = ecl.EclFile( unrst_file ) - swat = file["SWAT"][0] - - swat1 = swat.sub_copy( 0 , -1 ) - swat2 = swat.sub_copy( 0 , swat.size ) - - self.assertTrue( swat.equal( swat1 )) - self.assertTrue( swat.equal( swat2 )) - - swat3 = swat.sub_copy(20000 , 100 , new_header = "swat") - self.assertTrue( swat3.name == "swat" ) - self.assertTrue( swat3.size == 100 ) - equal = True - for i in range(swat3.size): - if swat3[i] != swat[i + 20000]: - equal = False - self.assertTrue( equal ) - - self.assertRaises( IndexError , copy_long ) - self.assertRaises( IndexError , copy_offset ) - - - - - - def fprintf_test( self ): - self.test_kw( ecl.ECL_INT_TYPE , [0 , 1 , 2 , 3 , 4 , 5 ] , "%4d\n") - self.test_kw( ecl.ECL_FLOAT_TYPE , [0.0 , 1.1 , 2.2 , 3.3 , 4.4 , 5.5 ] , "%12.6f\n") - self.test_kw( ecl.ECL_DOUBLE_TYPE , [0.0 , 1.1 , 2.2 , 3.3 , 4.4 , 5.5 ] , "%12.6f\n") - self.test_kw( ecl.ECL_BOOL_TYPE , [True , True , True , False , True] , "%4d\n") - self.test_kw( ecl.ECL_CHAR_TYPE , ["1" , "22" , "4444" , "666666" , "88888888" ] , "%-8s\n") - - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( KWTest( 'fortio_size' )) - suite.addTest( KWTest( 'fprintf_test' )) - suite.addTest( KWTest( 'test_equal' )) - suite.addTest( KWTest( 'testSubCopy' )) - return suite - - -def test_suite(argv): - return fast_suite() - - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - - - - -#def cutoff( x , arg ): -# if x < arg: -# return 0 -# else: -# return x -# -# -#init_file = ecl.EclFile( "data/eclipse/case/ECLIPSE.INIT" ) -#permx = init_file.iget_named_kw("PERMX" , 0 ) -#poro = init_file.iget_named_kw("PORO" , 0 ) -#pvt = init_file.iget_named_kw("PVTNUM" , 0 ) -#grid = ecl.EclGrid( "data/eclipse/case/ECLIPSE.EGRID" ) -# -# -#poro3d = grid.create3D( poro , default = -100) -# -#print "max:%g" % poro.max -#print "min:%g" % poro.min -# -#mask1 = ecl.EclRegion( grid , False ) -#mask2 = ecl.EclRegion( grid , False ) -#mask1.select_less( poro , 0.15 ) -#mask2.select_more( poro , 0.30 ) -# -#mask3 = mask1.copy() -#mask3 |= mask2 -# -#mask1.reset() -#(x,y,z) = grid.get_xyz( ijk = (grid.nx / 2 , grid.ny /2 , grid.nz / 2) ) -#mask1.select_above_plane( [0,0,1] , [x,y,z] ) -#print mask1.active_list.size -#print mask1.active_list.str( max_lines = None ) -# -#print mask2.active_list.size -#print mask3.active_list.size -# -#poro.apply( cutoff , mask = mask1 , arg = 0.05) -# -# -#poro.write_grdecl( open("/tmp/poro_cos.grdecl" , "w") ) -# -#poro.add( permx , mask = mask1) -#poro.sub( 1 ) -#poro.mul( poro ) -#poro.assign( 14.0 ) -#poro.div( 7.0 ) -# -#new_p = poro / 7.0 -# -#poro.write_grdecl( open("/tmp/poro_cos.grdecl" , "w") ) -# -#init_file = ecl.EclFile( "data/eclipse/case/ECLIPSE.INIT" ) -#permx_kw = init_file.iget_named_kw( "PERMX" , 0 ) -#permx_new = ecl.EclKW.new( "PERMX" , 3 , ecl.ECL_FLOAT_TYPE ) -#print ecl.ECL_GRID_FILE -#print ecl.ecl_file_enum -#permx_new[0] = 1 -#permx_new[1] = 2 -#permx_new[2] = 3 -# -##init_file.replace_kw( permx_kw , permx_new ) -#fortio = ecl.FortIO.writer( "/tmp/init" ) -#print fortio -#init_file.fwrite( fortio ) -#fortio.close() -# -#poro = ecl.EclKW.read_grdecl( open( "data/eclipse/case/include/example_poro.GRDECL" , "r") , "PORO" ) -#eqlnum = ecl.EclKW.read_grdecl( open( "data/eclipse/case/include/example_eqlnum.GRDECL" , "r") , "EQLNUM" ) -#dummy = ecl.EclKW.read_grdecl( open( "data/eclipse/case/include/example_eqlnum.GRDECL" , "r") , "BJARNE" , ecl_type = ecl.ECL_INT_TYPE) -# -#if dummy: -# print "Loading BJARNE OK" -#else: -# print "Loading BJARNE Failed (correctly)" -# -#print "Poro[100] :%g eqlnum[100]:%d" % (poro[100] , eqlnum[100]) -# -#if not eqlnum.type == ecl.ECL_INT_TYPE: -# sys.exit("Type error when loading eqlnum") -# -#p2 = poro[100:160] -#if p2: -# print p2.header -#print poro -#print pvt.str( max_lines = 8 ) -#print eqlnum -# -#print ecl.EclKW.int_kw -#poro.add_int_kw("BJARNE") -#print eqlnum.int_kw diff --git a/ThirdParty/Ert/devel/python/test/large_mem_test.py b/ThirdParty/Ert/devel/python/test/large_mem_test.py deleted file mode 100644 index ba0d8bacb3..0000000000 --- a/ThirdParty/Ert/devel/python/test/large_mem_test.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'large_mem_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import datetime -import unittest -import ert -import ert.ecl.ecl as ecl -from ert.util.tvector import DoubleVector -from test_util import approx_equal, approx_equalv - - -case = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE" - - -class MemTest( unittest.TestCase ): - def setUp(self): - # Funny setup to ensure that the 32 bit memory region is - # exhausted. Then we do some (grid-based) pointer - # dereferencing in the 64 bit memory region - this has been - # problematic in the past. - vecList = [] - for i in range(12500): - vec = DoubleVector() - vec[81920] = 0 - vecList.append( vec ) - - self.grid1 = ecl.EclGrid( case ) - self.grid2 = ecl.EclGrid( case ) - - - def test_nactive(self): - self.assertEqual( self.grid1.nactive , self.grid2.nactive ) - self.assertEqual( self.grid1.nactive , 34770 ) - - -def slow_suite(): - suite = unittest.TestSuite() - suite.addTest( MemTest( 'test_nactive' )) - return suite - -if __name__ == "__main__": - unittest.TextTestRunner().run( slow_suite() ) - diff --git a/ThirdParty/Ert/devel/python/test/latex_test.py b/ThirdParty/Ert/devel/python/test/latex_test.py deleted file mode 100644 index ae2de24f2f..0000000000 --- a/ThirdParty/Ert/devel/python/test/latex_test.py +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'latex_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import datetime -import unittest -import os.path -import ert -import ert.util.latex as latex -from test_util import approx_equal, approx_equalv - -local_path = "test-data/local/util/latex" -statoil_path = "test-data/Statoil/util/latex" - -class LaTeXTest( unittest.TestCase ): - def setUp(self): - pass - - - def test1(self): - lx = latex.LaTeX( "%s/test_OK.tex" % local_path ) - self.assertTrue( lx.compile( ) ) - - lx = latex.LaTeX( "%s/test_error.tex" % local_path ) - self.assertFalse( lx.compile( ) ) - - - - def test_cleanup( self ): - lx = latex.LaTeX( "%s/report_OK.tex" % statoil_path , in_place = True ) - self.assertTrue( lx.in_place ) - self.assertTrue( lx.compile() ) - for ext in ["log" , "aux" , "nav" , "out" , "snm" , "toc"]: - self.assertFalse( os.path.exists( "%s/report_OK.%s" % (statoil_path , ext) )) - - lx = latex.LaTeX( "%s/report_OK.tex" % statoil_path , in_place = False ) - self.assertFalse( lx.in_place ) - run_path = lx.runpath - self.assertTrue( lx.compile() ) - self.assertFalse( os.path.exists( run_path ) ) - - lx = latex.LaTeX( "%s/report_OK.tex" % statoil_path , in_place = False ) - run_path = lx.runpath - self.assertTrue( lx.compile( cleanup = False) ) - self.assertTrue( os.path.exists( "%s/report_OK.log" % run_path)) - - - - def test_report(self): - lx = latex.LaTeX( "%s/report_error.tex" % statoil_path ) - lx.timeout = 4 - self.assertFalse( lx.compile() ) - - lx = latex.LaTeX( "%s/report_OK.tex" % statoil_path ) - self.assertTrue( lx.compile() ) - - - def test_target(self): - lx = latex.LaTeX( "%s/report_OK.tex" % statoil_path ) - self.assertTrue( lx.compile() ) - self.assertTrue( os.path.exists( lx.target )) - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( LaTeXTest( 'test1' )) - suite.addTest( LaTeXTest( 'test_report' )) - suite.addTest( LaTeXTest( 'test_cleanup' )) - suite.addTest( LaTeXTest( 'test_target' )) - return suite - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/region_test.py b/ThirdParty/Ert/devel/python/test/region_test.py deleted file mode 100644 index 4e99395f35..0000000000 --- a/ThirdParty/Ert/devel/python/test/region_test.py +++ /dev/null @@ -1,155 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'region_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import datetime -import unittest -import ert -import ert.ecl.ecl as ecl -from test_util import approx_equal, approx_equalv - - -case = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE" - - -class RegionTest( unittest.TestCase ): - - def setUp(self): - self.grid = ecl.EclGrid( case ) - self.rst_file = ecl.EclFile( "%s.UNRST" % case ) - self.init_file = ecl.EclFile( "%s.INIT" % case ) - - - - def test_kw_imul(self): - P = self.rst_file["PRESSURE"][5] - fipnum = self.init_file["FIPNUM"][0] - fipnum_copy = fipnum.deep_copy() - - reg = ecl.EclRegion( self.grid , False ) - reg.select_more( P , 260 ) - fipnum.mul( -1 , mask = reg ) - self.assertFalse( fipnum.equal( fipnum_copy ) ) - - fipnum.mul( -1 , mask = reg ) - self.assertTrue( fipnum.equal( fipnum_copy ) ) - - - - def test_kw_idiv(self): - P = self.rst_file["PRESSURE"][5] - fipnum = self.init_file["FIPNUM"][0] - fipnum_copy = fipnum.deep_copy() - - reg = ecl.EclRegion( self.grid , False ) - reg.select_more( P , 260 ) - fipnum.div( -1 , mask = reg ) - self.assertFalse( fipnum.equal( fipnum_copy ) ) - - fipnum.div( -1 , mask = reg ) - self.assertTrue( fipnum.equal( fipnum_copy ) ) - - - - def test_kw_iadd(self): - P = self.rst_file["PRESSURE"][5] - fipnum = self.init_file["FIPNUM"][0] - fipnum_copy = fipnum.deep_copy() - - reg = ecl.EclRegion( self.grid , False ) - reg.select_more( P , 260 ) - fipnum.add( 1 , mask = reg ) - self.assertFalse( fipnum.equal( fipnum_copy ) ) - - reg.invert( ) - fipnum.add( 1 , mask = reg ) - - fipnum.sub(1) - self.assertTrue( fipnum.equal( fipnum_copy ) ) - - - def test_kw_isub(self): - P = self.rst_file["PRESSURE"][5] - fipnum = self.init_file["FIPNUM"][0] - fipnum_copy = fipnum.deep_copy() - - reg = ecl.EclRegion( self.grid , False ) - reg.select_more( P , 260 ) - fipnum.sub( 1 , mask = reg ) - self.assertFalse( fipnum.equal( fipnum_copy ) ) - fipnum.add( 1 , mask = reg) - self.assertTrue( fipnum.equal( fipnum_copy ) ) - - - - def test_slice(self): - reg = ecl.EclRegion( self.grid , False ) - reg.select_islice( 0 , 5 ) - OK = True - for gi in reg.global_list: - (i,j,k) = self.grid.get_ijk( global_index = gi ) - if i > 5: - OK = False - self.assertTrue( OK ) - self.assertTrue( self.grid.ny * self.grid.nz *6 == len(reg.global_list)) - - reg.select_jslice( 7 , 8 , intersect = True) - OK = True - for gi in reg.global_list: - (i,j,k) = self.grid.get_ijk( global_index = gi ) - if i > 5: - OK = False - - if j < 7 or j > 8: - OK = False - - self.assertTrue( OK ) - self.assertTrue( 2 * self.grid.nz * 6 == len(reg.global_list)) - - reg2 = ecl.EclRegion( self.grid , False ) - reg2.select_kslice( 3 , 5 ) - reg &= reg2 - OK = True - for gi in reg.global_list: - (i,j,k) = self.grid.get_ijk( global_index = gi ) - if i > 5: - OK = False - - if j < 7 or j > 8: - OK = False - - if k < 3 or k > 5: - OK = False - - self.assertTrue( OK ) - self.assertTrue( 2 * 3 *6 == len(reg.global_list)) - - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( RegionTest( 'test_kw_imul' )) - suite.addTest( RegionTest( 'test_kw_iadd' )) - suite.addTest( RegionTest( 'test_kw_idiv' )) - suite.addTest( RegionTest( 'test_kw_isub' )) - suite.addTest( RegionTest( 'test_slice' )) - return suite - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/restart_test.py b/ThirdParty/Ert/devel/python/test/restart_test.py deleted file mode 100644 index 4aa7382244..0000000000 --- a/ThirdParty/Ert/devel/python/test/restart_test.py +++ /dev/null @@ -1,162 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'sum_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import filecmp -import datetime -import unittest -import shutil -import time -import os -import os.path -import ert -import ert.ecl.ecl as ecl -from test_util import approx_equal, approx_equalv, file_equal - -xfile0 = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.X0000" -file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.UNRST" -fmt_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.FUNRST" -grid_file = "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.EGRID" - -def load_missing(): - ecl.EclFile( "No/Does/not/exist") - - -class RestartTest( unittest.TestCase ): - - def setUp(self): - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - - - def test_report_file(self , fname): - self.assertTrue( ecl.EclFile.contains_report_step( fname , 4 )) - self.assertTrue( ecl.EclFile.contains_report_step( fname , 0 )) - self.assertTrue( ecl.EclFile.contains_report_step( fname , 62 )) - self.assertFalse( ecl.EclFile.contains_report_step( fname , -1 )) - self.assertFalse( ecl.EclFile.contains_report_step( fname , 100 )) - - f = ecl.EclFile( fname ) - self.assertTrue( f.has_report_step( 4 )) - self.assertTrue( f.has_report_step( 0 )) - self.assertTrue( f.has_report_step( 62 )) - - self.assertFalse( f.has_report_step( -1 )) - self.assertFalse( f.has_report_step( 100 )) - - - def test_report(self): - self.test_report_file(file) - - - - def test_date(self): - f = ecl.EclFile( file ) - self.assertTrue( f.has_sim_time( datetime.datetime( 2001 , 6 , 1) )) - self.assertFalse( f.has_sim_time( datetime.datetime( 2005 , 6 , 1) )) - self.assertFalse( f.has_sim_time( datetime.datetime( 1999 , 6 , 1) )) - self.assertFalse( f.has_sim_time( datetime.datetime( 2001 , 6 , 11) )) - - self.assertTrue( ecl.EclFile.contains_sim_time( file , datetime.datetime( 2001 , 6 , 1) )) - self.assertFalse( ecl.EclFile.contains_sim_time( file , datetime.datetime( 2005 , 6 , 1) )) - self.assertFalse( ecl.EclFile.contains_sim_time( file , datetime.datetime( 1999 , 6 , 1) )) - self.assertFalse( ecl.EclFile.contains_sim_time( file , datetime.datetime( 2001 , 6 , 11) )) - - - - - def test_report_list_file(self , fname , rlist0): - rlist = ecl.EclFile.file_report_list( fname ) - self.assertTrue( approx_equalv( rlist , rlist0 )) - - f = ecl.EclFile( fname ) - rlist = f.report_list - self.assertTrue( approx_equalv( rlist , rlist0 )) - - - - def test_report_list(self): - rlist0 = range(63) - self.test_report_list_file( file , rlist0 ) - - rlist0 = [0] - self.test_report_list_file( xfile0 , rlist0 ) - - f = ecl.EclFile( grid_file ) - self.assertRaises( TypeError , ecl.EclFile.file_report_list) - - - def test_dates(self): - f = ecl.EclFile(file) - dates = f.dates - self.assertTrue( len(dates) == 63 ) - - f = ecl.EclFile(xfile0) - dates = f.dates - self.assertTrue( len(dates) == 1 ) - self.assertTrue( dates[0] == datetime.datetime(2000,1,1)) - - - - def test_name(self): - f = ecl.EclFile( file ) - self.assertTrue( f.name == file ) - - f = ecl.EclFile( xfile0 ) - self.assertTrue( f.name == xfile0 ) - - - - def test_kw( self ): - f = ecl.EclFile( file ) - kw1 = f["SWAT"][40] - kw2 = f.restart_get_kw( "SWAT" , datetime.datetime( 2003 , 3 , 1 )) - kw3 = f.restart_get_kw( "SWAT" , datetime.datetime( 2003 , 3 , 1 ) , copy = True) - - self.assertTrue( kw1.equal( kw2 )) - self.assertTrue( kw1.equal( kw3 )) - - - kw4 = f.restart_get_kw( "SWAT" , datetime.datetime( 2009 , 3 , 1 )) - self.assertTrue( kw4 is None ) - - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( RestartTest( 'test_name' )) - suite.addTest( RestartTest( 'test_report' )) - suite.addTest( RestartTest( 'test_date' )) - suite.addTest( RestartTest( 'test_kw' )) - suite.addTest( RestartTest( 'test_report_list' )) - suite.addTest( RestartTest( 'test_dates' )) - return suite - - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - diff --git a/ThirdParty/Ert/devel/python/test/rft_test.py b/ThirdParty/Ert/devel/python/test/rft_test.py deleted file mode 100644 index fa9b77aa0f..0000000000 --- a/ThirdParty/Ert/devel/python/test/rft_test.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'rft_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - - -import ert.ecl.ecl as ecl - - -rft = ecl.EclRFTFile( "test-data/Statoil/ECLIPSE/Gurbat/ECLIPSE.RFT" ) - -for node in rft: - print rft - - diff --git a/ThirdParty/Ert/devel/python/test/sched_test.py b/ThirdParty/Ert/devel/python/test/sched_test.py deleted file mode 100644 index 2f7cc6b24b..0000000000 --- a/ThirdParty/Ert/devel/python/test/sched_test.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'sched_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import os -import datetime -import unittest -import ert -import ert.sched.sched as sched -from test_util import approx_equal, approx_equalv, file_equal - - -src_file = "test-data/Statoil/ECLIPSE/Gurbat/target.SCH" -start_time = datetime.date(2000 , 1, 1) - -class SchedFileTest( unittest.TestCase ): - def setUp(self): - self.sched_file = sched.SchedFile( src_file , start_time ) - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - def test_load(self): - self.assertTrue( self.sched_file , "Load failed") - - - def test_length(self): - self.assertEqual( self.sched_file.length , 63 ) - - - def test_write_loop(self): - self.sched_file.write( "/tmp/schedule1" , 62) - sched_file2 = sched.SchedFile( "/tmp/schedule1" , start_time) - sched_file2.write( "/tmp/schedule2" , 62) - self.assertTrue( file_equal( "/tmp/schedule1" , "/tmp/schedule2") ) - - self.addFile( "/tmp/schedule1" ) - self.addFile( "/tmp/schedule2" ) - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( SchedFileTest( 'test_load' )) - suite.addTest( SchedFileTest( 'test_length' )) - suite.addTest( SchedFileTest( 'test_write_loop' )) - return suite - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/stringlist_test.py b/ThirdParty/Ert/devel/python/test/stringlist_test.py deleted file mode 100644 index d25225df71..0000000000 --- a/ThirdParty/Ert/devel/python/test/stringlist_test.py +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'stringlist_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import os -import unittest -import stat -import math -import ert -from ert.util.stringlist import StringList -import sys -from test_util import * -import ert.ecl.ecl as ecl - -initList = ["S1" , "SABC" , "S33"] - -base = "ECLIPSE" -path = "test-data/Statoil/ECLIPSE/Gurbat" -case = "%s/%s" % (path , base) - - -def pop_empty(): - s = StringList( initial = initList ) - s.pop() - s.pop() - s.pop() - s.pop() - -def last_empty(): - s = StringList( initial = initList ) - s.pop() - s.pop() - s.pop() - s.last - - -class StringListTest( unittest.TestCase ): - - def setUp( self ): - pass - - - def create(self): - s = StringList( initial = initList ) - st = s.strings - del s - return st - - def test_pop( self ): - s = StringList( initial = initList ) - s1 = s.pop() - self.assertTrue( len(s) == 2 ) - self.assertTrue( s1 == "S33") - - s1 = s.pop() - self.assertTrue( len(s) == 1 ) - self.assertTrue( s1 == "SABC") - - s1 = s.pop() - self.assertTrue( len(s) == 0 ) - self.assertTrue( s1 == "S1") - - self.assertRaises( IndexError , pop_empty ) - - - def test_create( self ): - s = StringList() - - s = StringList( initial = initList ) - self.assertTrue( len(s) == 3 ) - for i in range(len(s)): - self.assertTrue( s[i] == initList[i] ) - - s2 = s.strings - for i in range(len(s)): - self.assertTrue( s2[i] == initList[i] ) - - s3 = self.create() - for i in range(len(s)): - self.assertTrue( s3[i] == initList[i] ) - - - def test_last( self ): - s = StringList( initial = initList ) - l = s.last - self.assertTrue( "S33" == l ) - self.assertRaises( IndexError , last_empty) - - - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( StringListTest( 'test_create' )) - suite.addTest( StringListTest( 'test_pop' )) - suite.addTest( StringListTest( 'test_last' )) - return suite - - -def test_suite(argv): - return fast_suite() - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - diff --git a/ThirdParty/Ert/devel/python/test/sum_test.py b/ThirdParty/Ert/devel/python/test/sum_test.py deleted file mode 100644 index 67514ca8ea..0000000000 --- a/ThirdParty/Ert/devel/python/test/sum_test.py +++ /dev/null @@ -1,289 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'sum_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - -import os -import datetime -import unittest -import ert -import ert.ecl.ecl as ecl -from ert.util.stringlist import StringList -from test_util import approx_equal, approx_equalv - - -base = "ECLIPSE" -path = "test-data/Statoil/ECLIPSE/Gurbat" -case = "%s/%s" % (path , base) - - -def sum_get(*args): - sum = args[0] - key = args[1] - vec = sum[key] - - - - -class SumTest( unittest.TestCase ): - - def setUp(self): - self.case = case - self.sum = ecl.EclSum( self.case ) - self.file_list = [] - - def addFile( self , file ): - self.file_list.append( file ) - - def tearDown(self): - for file in self.file_list: - if os.path.exists( file ): - os.unlink( file ) - - def test_load(self): - self.assertTrue( self.sum , "Load failed") - - - def test_interp(self): - sum = self.sum - self.assertTrue( approx_equal( sum.get_interp( "WWCT:OP_3" , days = 750 ) , 0.11719122)) - self.assertTrue( approx_equal( sum.get_interp( "WWCT:OP_3" , date = datetime.date( 2004,1,1)) , 0.603358387947 )) - - v = sum.get_interp_vector( "WOPT:OP_1" , days_list = [100 , 200 , 400 , 800] ) - self.assertTrue( approx_equalv( [805817.11875 , 1614955.34677419 , 3289267.67857143 , 6493021.6218035 ] , v)) - - v = sum.get_interp_vector( "WGPT:OP_2" , date_list = [datetime.date(2002,1,1) , datetime.date(2003,1,1) , datetime.date(2004 , 1 , 1)]) - self.assertTrue( approx_equalv( v , [ 8.20773632e+08 , 9.68444032e+08 , 1.02515213e+09]) ) - - - def test_wells(self): - sum = self.sum - wells = sum.wells() - wells.sort() - self.assertTrue( approx_equalv( wells , ["OP_1" , "OP_2" , "OP_3" , "OP_4" , "OP_5" , "WI_1" , "WI_2" , "WI_3"])) - - wells = sum.wells( pattern = "*_3") - wells.sort() - self.assertTrue( approx_equalv( wells , ["OP_3" , "WI_3"])) - - groups = sum.groups() - groups.sort() - self.assertTrue( approx_equalv( groups , ['GMWIN','OP','WI'])) - - - def test_last( self ): - sum = self.sum - last = sum.get_last("FOPT") - self.assertTrue( approx_equal( last.value , 38006336.0 )) - self.assertTrue( approx_equal( last.days , 1826.0 )) - self.assertEqual( last.date , datetime.datetime( 2004 , 12 , 31, 0,0,0)) - - self.assertTrue( approx_equal( sum.get_last_value("FGPT") , 6605249024.0)) - - - def test_dates( self ): - sum = self.sum - d = sum.dates - - self.assertEqual( d[0] , datetime.datetime( 2000 , 1 , 1 , 0 , 0 , 0)) - self.assertEqual( d[62] , datetime.datetime( 2004 , 12 , 31 , 0 , 0 , 0)) - self.assertEqual( len(d) , 63 ) - self.assertEqual( d[25] , datetime.datetime( 2001 , 12 , 1 , 0 , 0 , 0)) - self.assertEqual( sum.iget_date( 25 ) , datetime.datetime( 2001 , 12 , 1 , 0 , 0 , 0)) - - mpl_dates = sum.mpl_dates - self.assertTrue( approx_equal( mpl_dates[25] , 730820 )) - - days = sum.days - self.assertTrue( approx_equal( days[50] , 1461 )) - - self.assertEqual( sum.start_time , datetime.datetime( 2000 , 1 , 1 , 0 , 0 , 0)) - self.assertEqual( sum.end_time , datetime.datetime( 2004 , 12 , 31 , 0 , 0 , 0)) - self.assertTrue( sum.check_sim_time(datetime.datetime( 2004 , 12 , 31 , 0 , 0 , 0))) - - def test_keys(self): - sum = self.sum - self.assertRaises( KeyError , sum.__getitem__ , "BJARNE" ) - - v = sum["FOPT"] - self.assertEqual( len(v) , 63 ) - - - def test_index(self): - sum = self.sum - index = sum.get_key_index( "TCPUDAY") - self.assertEqual( index , 10239 ) - - - def test_report(self): - sum = self.sum - self.assertEqual( sum.get_report( date = datetime.date( 2000,10,1) ) , 10) - self.assertEqual( sum.get_report( date = datetime.date( 2000,10,3) ) , -1) - self.assertEqual( sum.get_report( date = datetime.date( 1980,10,3) ) , -1) - self.assertEqual( sum.get_report( date = datetime.date( 2012,10,3) ) , -1) - - self.assertEqual( sum.get_report( days = 91 ) , 3) - self.assertEqual( sum.get_report( days = 92 ) , -1) - self.assertTrue( approx_equal( sum.get_interp( "FOPT" , days = 91 ) , sum.get_from_report( "FOPT" , 3 )) ) - - self.assertEqual( sum.first_report , 1 ) - self.assertEqual( sum.last_report , 62 ) - - self.assertEqual( sum.get_report_time( 10 ) , datetime.date( 2000 , 10 , 1)) - self.assertTrue( approx_equal( sum.get_from_report( "FOPT" , 10 ) , 6.67447e+06) ) - - - def test_fwrite(self): - self.sum.fwrite(ecl_case = "/tmp/CASE" ) - self.assertTrue( True ) - - - def test_block(self): - sum = self.sum - index_ijk = sum.get_key_index("BPR:15,28,1") - index_num = sum.get_key_index("BPR:1095") - self.assertEqual( index_ijk , index_num ) - - - def test_restart(self): - hist = ecl.EclSum( "test-data/Statoil/ECLIPSE/sum-restart/history/T07-4A-W2011-18-P1" ) - base = ecl.EclSum( "test-data/Statoil/ECLIPSE/sum-restart/prediction/BASECASE" ) - pred = ecl.EclSum( "test-data/Statoil/ECLIPSE/sum-restart/prediction/BASECASE" , include_restart = False) - - self.assertTrue( pred ) - - - def test_case1(self ): - self.assertTrue( self.sum.path == path ) - self.assertTrue( self.sum.base == base ) - self.assertTrue( self.sum.case == case ) - self.assertTrue( self.sum.abs_path == os.path.realpath(os.path.join( os.getcwd() , path ))) - - - def test_case2( self ): - cwd = os.getcwd() - os.chdir( path ) - sum = ecl.EclSum( base ) - self.assertTrue( sum.path is None ) - self.assertTrue( sum.base == base ) - self.assertTrue( sum.case == base ) - self.assertTrue( sum.abs_path == os.path.realpath(os.path.join( cwd , path ))) - os.chdir( cwd ) - - - - - def test_var_properties( self ): - sum = self.sum - self.assertRaises( KeyError , sum.smspec_node , "BJARNE" ) - - node = sum.smspec_node( "FOPT" ) - self.assertTrue( node.is_total ) - self.assertFalse( node.is_historical ) - - node = sum.smspec_node( "FOPR" ) - self.assertFalse( node.is_total ) - self.assertFalse( node.is_historical ) - self.assertTrue( node.keyword == "FOPR" ) - - node = sum.smspec_node( "FOPRH" ) - self.assertFalse( node.is_total ) - self.assertTrue( node.is_historical ) - self.assertTrue( node.is_rate ) - self.assertTrue( node.keyword == "FOPRH" ) - - node = sum.smspec_node( "WOPR:OP_1" ) - self.assertFalse( node.is_total ) - self.assertTrue( node.is_rate ) - self.assertTrue( node.keyword == "WOPR" ) - - node = sum.smspec_node( "WOPT:OP_1" ) - self.assertTrue( node.is_total ) - self.assertFalse( node.is_rate ) - self.assertTrue( node.unit == "SM3" ) - self.assertTrue( node.wgname == "OP_1") - self.assertTrue( node.keyword == "WOPT" ) - - self.assertTrue( sum.unit( "FOPR" ) == "SM3/DAY") - - - node = sum.smspec_node( "FOPTH" ) - self.assertTrue( node.is_total ) - self.assertFalse( node.is_rate ) - self.assertTrue( node.wgname is None ) - - node = sum.smspec_node( "FOPTH" ) - self.assertTrue( node.num is None ) - - node = sum.smspec_node( "BPR:1095" ) - self.assertTrue( node.num == 1095 ) - - def test_stringlist_gc(self): - sum = ecl.EclSum( case ) - wells = sum.wells() - well1 = wells[0] - del wells - self.assertTrue( well1 == "OP_1" ) - - - def test_stringlist_reference(self): - sum = ecl.EclSum( case ) - wells = sum.wells() - self.assertTrue( approx_equalv( wells , ['OP_1','OP_2','OP_3','OP_4','OP_5','WI_1','WI_2','WI_3'])) - self.assertTrue( isinstance( wells , StringList )) - - - def test_stringlist_setitem(self): - sum = ecl.EclSum( case ) - wells = sum.wells() - wells[0] = "Bjarne" - well0 = wells[0] - self.assertTrue( well0 == "Bjarne" ) - self.assertTrue( wells[0] == "Bjarne" ) - wells[0] = "XXX" - self.assertTrue( well0 == "Bjarne" ) - self.assertTrue( wells[0] == "XXX" ) - - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( SumTest( 'test_load' )) - suite.addTest( SumTest( 'test_case1' )) - suite.addTest( SumTest( 'test_case2' )) - suite.addTest( SumTest( 'test_interp' )) - suite.addTest( SumTest( 'test_wells' )) - suite.addTest( SumTest( 'test_last' )) - suite.addTest( SumTest( 'test_dates' )) - suite.addTest( SumTest( 'test_keys' )) - suite.addTest( SumTest( 'test_index' )) - suite.addTest( SumTest( 'test_report' )) - suite.addTest( SumTest( 'test_fwrite' )) - suite.addTest( SumTest( 'test_block' )) - suite.addTest( SumTest( 'test_restart' )) - suite.addTest( SumTest( 'test_var_properties' )) - suite.addTest( SumTest( 'test_stringlist_gc')) - suite.addTest( SumTest( 'test_stringlist_reference')) - suite.addTest( SumTest( 'test_stringlist_setitem')) - return suite - - -def test_suite( argv ): - return fast_suite() - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) diff --git a/ThirdParty/Ert/devel/python/test/test_all.py b/ThirdParty/Ert/devel/python/test/test_all.py deleted file mode 100644 index e1f21e2322..0000000000 --- a/ThirdParty/Ert/devel/python/test/test_all.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -import unittest -import sys - -import troll_test -import sum_test -import sched_test -import large_mem_test -import file_test -import grdecl_test -import grid_test -import kw_test -import region_test -import latex_test -import fortio_test -import restart_test -import config_test -import stringlist_test -import tvector_test - -def run_suite(name , suite): - print "Running tests from %12s:" % name, - sys.stdout.flush() - unittest.TextTestRunner().run( suite ) - - -def run(name , module): - if hasattr(module , "fast_suite"): - run_suite( name , getattr(module , "fast_suite")()) - - if hasattr(module , "slow_suite"): - run_suite( name , getattr(module , "slow_suite")()) - -run("config" , config_test) -run("restart" , restart_test) -run("kw" , kw_test) -run("summary" , sum_test) -run("troll" , troll_test) -run("sched_file" , sched_test) -run("file_test" , file_test) -run("large_mem" , large_mem_test) -run("grdecl" , grdecl_test) -run("grid" , grid_test) -run("region" , region_test) -run("latex" , latex_test) -run("fortio" , fortio_test) -run("stringlist" , stringlist_test) -run("tvector" , tvector_test) diff --git a/ThirdParty/Ert/devel/python/test/test_fast.py b/ThirdParty/Ert/devel/python/test/test_fast.py deleted file mode 100644 index 12b0872f39..0000000000 --- a/ThirdParty/Ert/devel/python/test/test_fast.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python -import unittest -import sys - -import sum_test -import sched_test -import large_mem_test -import file_test -import grdecl_test -import grid_test - -def run_suite(name , suite): - print "Running tests from %12s:" % name, - sys.stdout.flush() - unittest.TextTestRunner().run( suite ) - - -def run(name , module): - if hasattr(module , "fast_suite"): - run_suite( name , getattr(module , "fast_suite")()) - -run("kw" , kw_test) -run("summary" , sum_test) -run("sched_file" , sched_test) -run("file_test" , file_test) -run("large_mem" , large_mem_test) -run("grdecl" , grdecl_test) -run("grid" , grid_test) diff --git a/ThirdParty/Ert/devel/python/test/test_util.py b/ThirdParty/Ert/devel/python/test/test_util.py deleted file mode 100644 index 9ebe97fe9e..0000000000 --- a/ThirdParty/Ert/devel/python/test/test_util.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Statoil ASA, Norway. -# -# The file 'test_util.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. -import filecmp - -def is_number(x): - try: - y = x + 1 - return True - except TypeError: - return False - -def approx_equal(a,b): - if is_number(a): - tol = 1e-6 - d = abs(a - b) - s = max(1 , abs(a) + abs(b)) - - return d < tol * s - else: - return a == b - -def approx_equalv(a,b): - equal = False - if len(a) == len(b): - equal = True - for (ai,bi) in zip(a,b): - if not approx_equal(ai,bi): - equal = False - break - return equal - - -def file_equal(f1,f2): - buffer1 = open(f1).read() - buffer2 = open(f2).read() - if buffer1 == buffer2: - return True - else: - return False - - diff --git a/ThirdParty/Ert/devel/python/test/tvector_test.py b/ThirdParty/Ert/devel/python/test/tvector_test.py deleted file mode 100644 index f3b5c4b70c..0000000000 --- a/ThirdParty/Ert/devel/python/test/tvector_test.py +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'tvector_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - - -import os -import datetime -import unittest -import ert -from ert.util.tvector import DoubleVector -from ert.util.tvector import IntVector -from ert.util.tvector import BoolVector - -from test_util import approx_equal, approx_equalv - - - -class TVectorTest( unittest.TestCase ): - - - def setUp(self): - pass - - - def test_activeList(self): - active_list = IntVector.active_list("1,10,100-105") - self.assertTrue( len(active_list) == 8 ) - self.assertTrue( active_list[0] == 1) - self.assertTrue( active_list[2] == 100) - self.assertTrue( active_list[7] == 105) - - active_list = IntVector.active_list("1,10,100-105X") - self.assertFalse( active_list ) - - - - def test_activeMask(self): - active_list = BoolVector.active_mask("1 , 4 - 7 , 10") - self.assertTrue( len(active_list) == 11 ) - self.assertTrue( active_list[1]) - self.assertTrue( active_list[4]) - self.assertTrue( active_list[10]) - self.assertFalse( active_list[9]) - self.assertFalse( active_list[8]) - - active_list = BoolVector.active_mask("1,4-7,10X") - self.assertFalse( active_list ) - - - - def test_true(self): - l = IntVector() - self.assertFalse( l ) # Will invoke the __len__ function; could override with __nonzero__ - l[0] = 1 - self.assertTrue( l ) - - - -def fast_suite(): - suite = unittest.TestSuite() - suite.addTest( TVectorTest( 'test_activeList' )) - suite.addTest( TVectorTest( 'test_activeMask' )) - suite.addTest( TVectorTest( 'test_true' )) - return suite - - -if __name__ == "__main__": - unittest.TextTestRunner().run( fast_suite() ) - - diff --git a/ThirdParty/Ert/devel/python/test/util_test.py b/ThirdParty/Ert/devel/python/test/util_test.py deleted file mode 100644 index dc2f2a7cf4..0000000000 --- a/ThirdParty/Ert/devel/python/test/util_test.py +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2011 Statoil ASA, Norway. -# -# The file 'util_test.py' is part of ERT - Ensemble based Reservoir Tool. -# -# ERT 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. -# -# ERT 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. - - -import random -import copy - -from ert.util.tvector import DoubleVector -from ert.util.tvector import IntVector -from ert.util.tvector import BoolVector -from ert.util.stringlist import StringList -import ert.util.stat as stat -from ert.util.util_func import * - -v = DoubleVector( 0 ) -print v -v[0] = 77.25 -v[1] = 123.25 -v[2] = 66.25 -v[3] = 56.25 -v[4] = 111.25 -v[5] = 99.25 -v[12] = 12 -v.printf( ) -v.clear() - -for i in range( 100000 ): - r = random.random() - v.append( r ) - - -print stat.quantile( v , 0.10 ) -print stat.quantile_sorted( v , 0.20 ) -print stat.quantile_sorted( v , 0.30 ) -print stat.quantile_sorted( v , 0.40 ) -print stat.quantile_sorted( v , 0.50 ) - -a = v[0:10] -print a -print a[6] -print a - - -b = copy.deepcopy( a ) -c = a.copy( ) -print c -print b -print v -c = IntVector( 0 ) -c.append( 1 ) -c.append( 2 ) -c.append( 3 ) -c.append( 4 ) -c.append( 5 ) - -c.rsort() -c.printf() - -print c.max -print c.min -print c.min_index() -c[4] = 5 -print c.max_index( reverse = True ) -print c.max_index( reverse = False ) - -d = c + 1 -d.printf() - -v2 = v.copy() -v2 = v2 * 2 -v2 += v - -print v2.assign -v2.assign( 1.0 ) -print v2[77] - -v2.default = 100 -print v2.default - -B = BoolVector( True ) -B[4] = False -B.printf() - -l = ["CASE-9","CASE-10"] -print l.sort() -print l.sort( strcmp_int ) - -v.default = 13 -v[1000] = 99 -print v.size -np = v.numpy_copy() -v[0] = 77 -v[5] = 99 -print v.str( max_lines = None ) - -S = StringList(["A" , "list" ,"of" , "strings"]) - -print S - -if "A" in S: - print "S contains A" - -if not "Bjarne" in S: - print "S does not contain BJARNE" - - diff --git a/ThirdParty/Ert/devel/share/gui/img/newsplash.jpg b/ThirdParty/Ert/devel/share/gui/img/newsplash.jpg new file mode 100644 index 0000000000..4a605e7321 Binary files /dev/null and b/ThirdParty/Ert/devel/share/gui/img/newsplash.jpg differ