Esempio n. 1
0
void test_write_header() {
    int nx = 10;
    int ny = 10;
    int nz = 5;

    int_vector_type * actnum = int_vector_alloc( nx*ny*nz , 1 );
    test_work_area_type * test_area = test_work_area_alloc( "ecl_init_file" );
    time_t start_time = util_make_date(15 , 12 , 2010 );
    ecl_grid_type * ecl_grid;

    int_vector_iset( actnum , 10 , 0 );
    int_vector_iset( actnum , 100 , 0 );

    ecl_grid = ecl_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, int_vector_get_ptr( actnum ));

    // Write poro with global size.
    {
        fortio_type * f = fortio_open_writer( "FOO1.INIT" , false , ECL_ENDIAN_FLIP );
        ecl_kw_type * poro = ecl_kw_alloc( "PORO" , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE );
        ecl_kw_scalar_set_float( poro , 0.10 );
        ecl_init_file_fwrite_header( f , ecl_grid , poro , 7 , start_time );
        ecl_kw_free( poro );
        fortio_fclose( f );
    }


    // Write poro with nactive size.
    {
        fortio_type * f = fortio_open_writer( "FOO2.INIT" , false , ECL_ENDIAN_FLIP );
        ecl_kw_type * poro = ecl_kw_alloc( "PORO" , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE );
        ecl_kw_scalar_set_float( poro , 0.10 );
        ecl_init_file_fwrite_header( f , ecl_grid , poro , 7 , start_time );
        ecl_kw_free( poro );
        fortio_fclose( f );
    }
    {
        ecl_file_type * file1 = ecl_file_open( "FOO1.INIT" , 0 );
        ecl_file_type * file2 = ecl_file_open( "FOO2.INIT" , 0 );

        test_assert_true( ecl_kw_equal( ecl_file_iget_named_kw( file1 , "PORV" , 0 ) ,
                                        ecl_file_iget_named_kw( file2 , "PORV" , 0)));

        ecl_file_close( file2 );
        ecl_file_close( file1 );
    }


    // Poro == NULL
    {
        fortio_type * f = fortio_open_writer( "FOO3.INIT" , false , ECL_ENDIAN_FLIP );
        ecl_init_file_fwrite_header( f , ecl_grid , NULL , 7 , start_time );
        fortio_fclose( f );
    }
    test_work_area_free( test_area );
}
Esempio n. 2
0
void EclipseIO::Impl::writeINITFile( const data::Solution& simProps, std::map<std::string, std::vector<int> > int_data, const NNC& nnc) const {
    const auto& units = this->es.getUnits();
    const IOConfig& ioConfig = this->es.cfg().io();

    std::string  initFile( ERT::EclFilename( this->outputDir,
                                             this->baseName,
                                             ECL_INIT_FILE,
                                             ioConfig.getFMTOUT() ));

    ERT::FortIO fortio( initFile,
                        std::ios_base::out,
                        ioConfig.getFMTOUT(),
                        ECL_ENDIAN_FLIP );


    // Write INIT header. Observe that the PORV vector is treated
    // specially; that is because for this particulat vector we write
    // a total of nx*ny*nz values, where the PORV vector has been
    // explicitly set to zero for inactive cells. The convention is
    // that the active/inactive cell mapping can be inferred by
    // reading the PORV vector.
    {

        const auto& opm_data = this->es.get3DProperties().getDoubleGridProperty("PORV").getData();
        auto ecl_data = opm_data;

        for (size_t global_index = 0; global_index < opm_data.size(); global_index++)
            if (!this->grid.cellActive( global_index ))
                ecl_data[global_index] = 0;


        ecl_init_file_fwrite_header( fortio.get(),
                                     this->grid.c_ptr(),
                                     NULL,
                                     units.getEclType(),
                                     this->es.runspec( ).eclPhaseMask( ),
                                     this->schedule.posixStartTime( ));

        units.from_si( UnitSystem::measure::volume, ecl_data );
        writeKeyword( fortio, "PORV" , ecl_data );
    }

    // Writing quantities which are calculated by the grid to the INIT file.
    ecl_grid_fwrite_depth( this->grid.c_ptr() , fortio.get() , units.getEclType( ) );
    ecl_grid_fwrite_dims( this->grid.c_ptr() , fortio.get() , units.getEclType( ) );

    // Write properties from the input deck.
    {
        const auto& properties = this->es.get3DProperties().getDoubleProperties();
        using double_kw = std::pair<std::string, UnitSystem::measure>;
        /*
          This is a rather arbitrary hardcoded list of 3D keywords
          which are written to the INIT file, if they are in the
          current EclipseState.
        */
        std::vector<double_kw> doubleKeywords = {{"PORO"  , UnitSystem::measure::identity },
                                                 {"PERMX" , UnitSystem::measure::permeability },
                                                 {"PERMY" , UnitSystem::measure::permeability },
                                                 {"PERMZ" , UnitSystem::measure::permeability },
                                                 {"NTG"   , UnitSystem::measure::identity }};

        // The INIT file should always contain the NTG property, we
        // therefor invoke the auto create functionality to ensure
        // that "NTG" is included in the properties container.
        properties.assertKeyword("NTG");

        for (const auto& kw_pair : doubleKeywords) {
            if (properties.hasKeyword( kw_pair.first)) {
                const auto& opm_property = properties.getKeyword(kw_pair.first);
                auto ecl_data = opm_property.compressedCopy( this->grid );

                units.from_si( kw_pair.second, ecl_data );
                writeKeyword( fortio, kw_pair.first, ecl_data );
            }
        }
    }


    // Write properties which have been initialized by the simulator.
    {
        for (const auto& prop : simProps) {
            auto ecl_data = this->grid.compressedVector( prop.second.data );
            writeKeyword( fortio, prop.first, ecl_data );
        }
    }

    // Write tables
    {
        Tables tables( this->es.getUnits() );
        tables.addPVTO( this->es.getTableManager().getPvtoTables() );
        tables.addPVTG( this->es.getTableManager().getPvtgTables() );
        tables.addPVTW( this->es.getTableManager().getPvtwTable() );
        tables.addDensity( this->es.getTableManager().getDensityTable( ) );
        tables.addSatFunc(this->es);
        fwrite(tables, fortio);
    }

    // Write all integer field properties from the input deck.
    {
        const auto& properties = this->es.get3DProperties().getIntProperties();

        // It seems that the INIT file should always contain these
        // keywords, we therefor call getKeyword() here to invoke the
        // autocreation property, and ensure that the keywords exist
        // in the properties container.
        properties.assertKeyword("PVTNUM");
        properties.assertKeyword("SATNUM");
        properties.assertKeyword("EQLNUM");
        properties.assertKeyword("FIPNUM");

        for (const auto& property : properties) {
            auto ecl_data = property.compressedCopy( this->grid );
            writeKeyword( fortio , property.getKeywordName() , ecl_data );
        }
    }


    //Write Integer Vector Map
    {
        for( const auto& pair : int_data)  {
            const std::string& key = pair.first;
            const std::vector<int>& int_vector = pair.second;
            if (key.size() > ECL_STRING8_LENGTH)
              throw std::invalid_argument("Keyword is too long.");            

            writeKeyword( fortio , key , int_vector );
        }
    }


    // Write NNC transmissibilities
    {
        std::vector<double> tran;
        for( const NNCdata& nd : nnc.nncdata() )
            tran.push_back( nd.trans );

        units.from_si( UnitSystem::measure::transmissibility , tran );
        writeKeyword( fortio, "TRANNNC" , tran );
    }
}