|
29 | 29 | #include "ExportCommands/RicEclipseCellResultToFileImpl.h" |
30 | 30 |
|
31 | 31 | #include "RifEclipseInputPropertyLoader.h" |
| 32 | + |
32 | 33 | #include "RifEclipseKeywordContent.h" |
33 | 34 | #include "RifEclipseTextFileReader.h" |
34 | 35 | #include "RifReaderEclipseOutput.h" |
| 36 | +#include "RigResdataGridConverter.h" |
35 | 37 |
|
36 | 38 | #include "RigActiveCellInfo.h" |
37 | 39 | #include "RigCaseCellResultsData.h" |
|
55 | 57 | #include <QFileInfo> |
56 | 58 | #include <QTextStream> |
57 | 59 |
|
| 60 | +#include "RigCellGeometryTools.h" |
58 | 61 | #include "ert/ecl/ecl_box.hpp" |
59 | 62 | #include "ert/ecl/ecl_grid.hpp" |
60 | 63 | #include "ert/ecl/ecl_kw.h" |
@@ -227,155 +230,8 @@ bool RifEclipseInputFileTools::exportGrid( const QString& fileName, |
227 | 230 | const cvf::Vec3st& maxIn, |
228 | 231 | const cvf::Vec3st& refinement ) |
229 | 232 | { |
230 | | - if ( !eclipseCase ) |
231 | | - { |
232 | | - return false; |
233 | | - } |
234 | | - |
235 | | - const RigActiveCellInfo* activeCellInfo = eclipseCase->activeCellInfo( RiaDefines::PorosityModelType::MATRIX_MODEL ); |
236 | | - |
237 | | - CVF_ASSERT( activeCellInfo ); |
238 | | - |
239 | | - const RigMainGrid* mainGrid = eclipseCase->mainGrid(); |
240 | | - |
241 | | - cvf::Vec3st max = maxIn; |
242 | | - if ( max == cvf::Vec3st::UNDEFINED ) |
243 | | - { |
244 | | - max = cvf::Vec3st( mainGrid->cellCountI() - 1, mainGrid->cellCountJ() - 1, mainGrid->cellCountK() - 1 ); |
245 | | - } |
246 | | - |
247 | | - int ecl_nx = static_cast<int>( ( max.x() - min.x() + 1 ) * refinement.x() ); |
248 | | - int ecl_ny = static_cast<int>( ( max.y() - min.y() + 1 ) * refinement.y() ); |
249 | | - int ecl_nz = static_cast<int>( ( max.z() - min.z() + 1 ) * refinement.z() ); |
250 | | - |
251 | | - CVF_ASSERT( ecl_nx > 0 && ecl_ny > 0 && ecl_nz > 0 ); |
252 | | - |
253 | | - size_t cellsPerOriginal = refinement.x() * refinement.y() * refinement.z(); |
254 | | - |
255 | | - caf::ProgressInfo progress( mainGrid->cellCount() * 2, "Save Eclipse Grid" ); |
256 | | - int cellProgressInterval = 1000; |
257 | | - |
258 | | - std::vector<float*> ecl_corners; |
259 | | - ecl_corners.reserve( mainGrid->cellCount() * cellsPerOriginal ); |
260 | | - std::vector<int*> ecl_coords; |
261 | | - ecl_coords.reserve( mainGrid->cellCount() * cellsPerOriginal ); |
262 | | - |
263 | | - std::array<float, 6> mapAxes = mainGrid->mapAxesF(); |
264 | | - cvf::Mat4d mapAxisTrans = mainGrid->mapAxisTransform(); |
265 | | - if ( exportInLocalCoordinates ) |
266 | | - { |
267 | | - cvf::Vec3d minPoint3d( mainGrid->boundingBox().min() ); |
268 | | - cvf::Vec2f minPoint2f( minPoint3d.x(), minPoint3d.y() ); |
269 | | - cvf::Vec2f origin( mapAxes[2] - minPoint2f.x(), mapAxes[3] - minPoint2f.y() ); |
270 | | - cvf::Vec2f xPoint = cvf::Vec2f( mapAxes[4], mapAxes[5] ) - minPoint2f; |
271 | | - cvf::Vec2f yPoint = cvf::Vec2f( mapAxes[0], mapAxes[1] ) - minPoint2f; |
272 | | - mapAxes = { yPoint.x(), yPoint.y(), origin.x(), origin.y(), xPoint.x(), xPoint.y() }; |
273 | | - |
274 | | - mapAxisTrans.setTranslation( mapAxisTrans.translation() - minPoint3d ); |
275 | | - } |
276 | | - |
277 | | - const size_t* cellMappingECLRi = RifReaderEclipseOutput::eclipseCellIndexMapping(); |
278 | | - |
279 | | - int outputCellIndex = 0; |
280 | | - |
281 | | - for ( size_t k = 0; k <= max.z() - min.z(); ++k ) |
282 | | - { |
283 | | - for ( size_t j = 0; j <= max.y() - min.y(); ++j ) |
284 | | - { |
285 | | - for ( size_t i = 0; i <= max.x() - min.x(); ++i ) |
286 | | - { |
287 | | - size_t mainIndex = mainGrid->cellIndexFromIJK( min.x() + i, min.y() + j, min.z() + k ); |
288 | | - |
289 | | - int active = activeCellInfo->isActive( mainIndex ) ? 1 : 0; |
290 | | - if ( active && cellVisibilityOverrideForActnum ) |
291 | | - { |
292 | | - active = ( *cellVisibilityOverrideForActnum )[mainIndex]; |
293 | | - } |
294 | | - std::array<cvf::Vec3d, 8> cellCorners = mainGrid->cellCornerVertices( mainIndex ); |
295 | | - |
296 | | - if ( mainGrid->useMapAxes() ) |
297 | | - { |
298 | | - for ( cvf::Vec3d& corner : cellCorners ) |
299 | | - { |
300 | | - corner.transformPoint( mapAxisTrans ); |
301 | | - } |
302 | | - } |
303 | | - |
304 | | - auto refinedCoords = RiaCellDividingTools::createHexCornerCoords( cellCorners, refinement.x(), refinement.y(), refinement.z() ); |
305 | | - |
306 | | - for ( size_t subK = 0; subK < refinement.z(); ++subK ) |
307 | | - { |
308 | | - for ( size_t subJ = 0; subJ < refinement.y(); ++subJ ) |
309 | | - { |
310 | | - for ( size_t subI = 0; subI < refinement.x(); ++subI ) |
311 | | - { |
312 | | - int* ecl_cell_coords = new int[5]; |
313 | | - ecl_cell_coords[0] = static_cast<int>( i * refinement.x() + subI + 1 ); |
314 | | - ecl_cell_coords[1] = static_cast<int>( j * refinement.y() + subJ + 1 ); |
315 | | - ecl_cell_coords[2] = static_cast<int>( k * refinement.z() + subK + 1 ); |
316 | | - ecl_cell_coords[3] = outputCellIndex++; |
317 | | - ecl_cell_coords[4] = active; |
318 | | - ecl_coords.push_back( ecl_cell_coords ); |
319 | | - |
320 | | - size_t subIndex = subI + subJ * refinement.x() + subK * refinement.x() * refinement.y(); |
321 | | - |
322 | | - float* ecl_cell_corners = new float[24]; |
323 | | - for ( size_t cIdx = 0; cIdx < 8; ++cIdx ) |
324 | | - { |
325 | | - const auto cellCorner = refinedCoords[subIndex * 8 + cIdx]; |
326 | | - ecl_cell_corners[cellMappingECLRi[cIdx] * 3] = cellCorner[0]; |
327 | | - ecl_cell_corners[cellMappingECLRi[cIdx] * 3 + 1] = cellCorner[1]; |
328 | | - ecl_cell_corners[cellMappingECLRi[cIdx] * 3 + 2] = -cellCorner[2]; |
329 | | - } |
330 | | - ecl_corners.push_back( ecl_cell_corners ); |
331 | | - } |
332 | | - } |
333 | | - } |
334 | | - } |
335 | | - } |
336 | | - |
337 | | - if ( outputCellIndex % cellProgressInterval == 0 ) |
338 | | - { |
339 | | - progress.setProgress( outputCellIndex / cellsPerOriginal ); |
340 | | - } |
341 | | - } |
342 | | - |
343 | | - // Do not perform the transformation (applyMapaxes == false): |
344 | | - // The coordinates have been transformed to the map axes coordinate system already. |
345 | | - // However, send the map axes data in to resdata so that the coordinate system description is saved. |
346 | | - bool applyMapaxes = false; |
347 | | - ecl_grid_type* mainEclGrid = |
348 | | - ecl_grid_alloc_GRID_data( (int)ecl_coords.size(), ecl_nx, ecl_ny, ecl_nz, 5, &ecl_coords[0], &ecl_corners[0], applyMapaxes, mapAxes.data() ); |
349 | | - progress.setProgress( mainGrid->cellCount() ); |
350 | | - |
351 | | - for ( float* floatArray : ecl_corners ) |
352 | | - { |
353 | | - delete floatArray; |
354 | | - } |
355 | | - |
356 | | - for ( int* intArray : ecl_coords ) |
357 | | - { |
358 | | - delete intArray; |
359 | | - } |
360 | | - |
361 | | - FILE* filePtr = util_fopen( RiaStringEncodingTools::toNativeEncoded( fileName ).data(), "w" ); |
362 | | - |
363 | | - if ( !filePtr ) |
364 | | - { |
365 | | - return false; |
366 | | - } |
367 | | - |
368 | | - ert_ecl_unit_enum ecl_units = ECL_METRIC_UNITS; |
369 | | - if ( eclipseCase->unitsType() == RiaDefines::EclipseUnitSystem::UNITS_FIELD ) |
370 | | - ecl_units = ECL_FIELD_UNITS; |
371 | | - else if ( eclipseCase->unitsType() == RiaDefines::EclipseUnitSystem::UNITS_LAB ) |
372 | | - ecl_units = ECL_LAB_UNITS; |
373 | | - |
374 | | - ecl_grid_fprintf_grdecl2( mainEclGrid, filePtr, ecl_units ); |
375 | | - ecl_grid_free( mainEclGrid ); |
376 | | - fclose( filePtr ); |
377 | | - |
378 | | - return true; |
| 233 | + // Use the new native implementation instead of resdata |
| 234 | + return RigResdataGridConverter::exportGrid( fileName, eclipseCase, exportInLocalCoordinates, cellVisibilityOverrideForActnum, min, maxIn, refinement ); |
379 | 235 | } |
380 | 236 |
|
381 | 237 | //-------------------------------------------------------------------------------------------------- |
@@ -481,7 +337,8 @@ bool RifEclipseInputFileTools::exportKeywords( const QString& resul |
481 | 337 |
|
482 | 338 | // Multiple keywords can be exported to same file, so write ECHO keywords outside the loop |
483 | 339 | bool writeEchoKeywordsInExporterObject = false; |
484 | | - RicEclipseCellResultToFileImpl::writeDataToTextFile( &exportFile, writeEchoKeywordsInExporterObject, keyword, filteredResults ); |
| 340 | + int valuePerRow = 5; |
| 341 | + RicEclipseCellResultToFileImpl::writeDataToTextFile( &exportFile, writeEchoKeywordsInExporterObject, keyword, filteredResults, valuePerRow ); |
485 | 342 |
|
486 | 343 | progress.incrementProgress(); |
487 | 344 | } |
|
0 commit comments