Skip to content

Commit

Permalink
feat: Log refactor - Output PVT (#3149)
Browse files Browse the repository at this point in the history
Co-authored-by: MelReyCG <[email protected]>
Co-authored-by: Randolph Settgast <[email protected]>
  • Loading branch information
3 people authored Oct 1, 2024
1 parent c225416 commit 0db85be
Show file tree
Hide file tree
Showing 46 changed files with 527 additions and 214 deletions.
2 changes: 1 addition & 1 deletion .integrated_tests.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
baselines:
bucket: geosx
baseline: integratedTests/baseline_integratedTests-pr3163-7758-9fe3734
baseline: integratedTests/baseline_integratedTests-pr3149-7884-f97a068

allow_fail:
all: ''
Expand Down
4 changes: 4 additions & 0 deletions BASELINE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This file is designed to track changes to the integrated test baselines.
Any developer who updates the baseline ID in the .integrated_tests.yaml file is expected to create an entry in this file with the pull request number, date, and their justification for rebaselining.
These notes should be in reverse-chronological order, and use the following time format: (YYYY-MM-DD).

PR #3149( 2024-09-30)
=====================
Added new field "writeCSV"

PR #3163 (2024-09-20)
=====================
Added new fields (krylovStrongestTol, adaptiveGamma, adaptiveExponent) to the LinearSolverParameters for adaptive tolerances.
Expand Down
39 changes: 35 additions & 4 deletions src/coreComponents/common/format/table/TableData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,42 @@ std::vector< string > const & TableData::getErrorMsgs() const
return m_errorsMsg;
}

TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit,
string_view rowFmt,
string_view columnFmt ) const
void TableData2D::collectTableValues( arraySlice1d< real64 const > rowAxisValues,
arraySlice1d< real64 const > columnAxisValues,
arrayView1d< real64 const > values )
{
TableData2D::Conversion1D tableData1D;
integer const nX = rowAxisValues.size();
integer const nY = columnAxisValues.size();

for( integer i = 0; i < nX; i++ )
{
for( integer y = 0; y < nY; y++ )
{
addCell( rowAxisValues[i], columnAxisValues[y], values[ y*nX + i ] );
}
}
}

TableData2D::TableDataHolder TableData2D::convertTable2D( arrayView1d< real64 const > const values,
units::Unit const valueUnit,
ArrayOfArraysView< real64 const > const coordinates,
string_view rowAxisDescription,
string_view columnAxisDescription )
{
string const rowFmt = GEOS_FMT( "{} = {{}}", rowAxisDescription );
string const columnFmt = GEOS_FMT( "{} = {{}}", columnAxisDescription );

collectTableValues( coordinates[0], coordinates[1], values );
return buildTableData( string( units::getDescription( valueUnit )),
rowFmt,
columnFmt );
}

TableData2D::TableDataHolder TableData2D::buildTableData( string_view targetUnit,
string_view rowFmt,
string_view columnFmt ) const
{
TableData2D::TableDataHolder tableData1D;
std::vector< size_t > rowsLength;

tableData1D.headerNames.push_back( string( targetUnit ) );
Expand Down
31 changes: 29 additions & 2 deletions src/coreComponents/common/format/table/TableData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifndef GEOS_COMMON_FORMAT_TABLE_TABLEDATA_HPP
#define GEOS_COMMON_FORMAT_TABLE_TABLEDATA_HPP

#include "common/Units.hpp"
#include "common/DataTypes.hpp"
#include "common/format/Format.hpp"

Expand Down Expand Up @@ -85,9 +86,10 @@ class TableData2D
using ColumnType = real64;

/// Struct containing conversion informations
struct Conversion1D
struct TableDataHolder
{
/// Vector containing all columns names
/// A header value is presented as "pressure [K] = {}"
std::vector< string > headerNames;
/// TableData to be built
TableData tableData;
Expand All @@ -103,6 +105,30 @@ class TableData2D
template< typename T >
void addCell( RowType rowValue, ColumnType columnValue, T const & value );

/**
* @brief Collects all the values needed to build the table
* @param rowAxisValues Vector containing all row axis values
* @param columnAxisValues Vector containing all column axis values
* @param values Vector containing all table values
*/
void collectTableValues( arraySlice1d< real64 const > rowAxisValues,
arraySlice1d< real64 const > columnAxisValues,
arrayView1d< real64 const > values );

/**
* @param values Vector containing all table values
* @param valueUnit The table unit value
* @param coordinates Array containing row/column axis values
* @param rowAxisDescription The description for a row unit value
* @param columnAxisDescription The description for a column unit value
* @return A struct containing the tableData converted and all header values ;
*/
TableData2D::TableDataHolder convertTable2D( arrayView1d< real64 const > const values,
units::Unit const valueUnit,
ArrayOfArraysView< real64 const > const coordinates,
string_view rowAxisDescription,
string_view columnAxisDescription );

/**
* @return Convert and return a struct containing a 1D Table, the column names list from a TableData2D and any errors related to the table
* @param dataDescription The table dataDescription shown at the top left side
Expand All @@ -112,7 +138,8 @@ class TableData2D
* By default it displays the axis value.
* I.E to display a customized axis to show the pressures in y axis, a rowFmt value can be : "pressure [K] = {}"
*/
Conversion1D buildTableData( string_view dataDescription, string_view rowFmt = "{}", string_view columnFmt = "{}" ) const;
TableDataHolder buildTableData( string_view dataDescription,
string_view rowFmt = "{}", string_view columnFmt = "{}" ) const;

private:
/// @brief all cell values by their [ row ][ column ]
Expand Down
8 changes: 6 additions & 2 deletions src/coreComponents/common/format/table/TableFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @file TableFormatter.cpp
*/

#include "TableFormatter.hpp"
#include <numeric>
#include "common/format/StringUtilities.hpp"
#include "TableFormatter.hpp"
Expand Down Expand Up @@ -67,7 +68,8 @@ string TableCSVFormatter::dataToString( TableData const & tableData ) const
return oss.str();
}

string TableCSVFormatter::toString( TableData const & tableData ) const
template<>
string TableCSVFormatter::toString< TableData >( TableData const & tableData ) const
{
return headerToString() + dataToString( tableData );
}
Expand Down Expand Up @@ -155,7 +157,8 @@ string TableTextFormatter::layoutToString() const
return tableOutput.str();
}

string TableTextFormatter::toString( TableData const & tableData ) const
template<>
string TableTextFormatter::toString< TableData >( TableData const & tableData ) const
{
std::ostringstream tableOutput;
string sectionSeparatingLine;
Expand Down Expand Up @@ -403,4 +406,5 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c
tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine );
}
}

}
55 changes: 46 additions & 9 deletions src/coreComponents/common/format/table/TableFormatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class TableFormatter
/// Layout for a table
TableLayout m_tableLayout;

TableFormatter() = default;

/**
* @brief Construct a new Table Formatter from a tableLayout
* @param tableLayout Contain all column names and optionnaly the table title
Expand All @@ -56,6 +58,13 @@ class TableCSVFormatter : public TableFormatter
{
public:

/**
* @brief Construct a new Table Formatter
*/
TableCSVFormatter():
TableFormatter( TableLayout() )
{}

/**
* @brief Construct a new Table Formatter from a tableLayout
* @param tableLayout Contain all column names and optionnaly the table title
Expand All @@ -80,28 +89,47 @@ class TableCSVFormatter : public TableFormatter
string dataToString( TableData const & tableData ) const;

/**
* @brief Convert the TableData to a table string.
* @param tableData The TableData to convert.
* @return The table string representation of the TableData.
* @brief Convert a data source to a CSV string.
* @tparam DATASOURCE The source to convert
* @param tableData The data source to convert
* @return The CSV string representation of a data source.
*/
string toString( TableData const & tableData ) const;
template< typename DATASOURCE >
string toString( DATASOURCE const & tableData ) const;

};

/**
* @brief Convert the TableData to a CSV string.
* @param tableData The TableData to convert.
* @return The CSV string representation of the TableData.
*/
template<>
string TableCSVFormatter::toString< TableData >( TableData const & tableData ) const;


/**
* @brief class for log formatting
*/
class TableTextFormatter : public TableFormatter
{

public:


/**
* @brief Construct a new TableFormatter
*/
TableTextFormatter():
TableFormatter( TableLayout() )
{}

/**
* @brief Construct a new TableFormatter from a tableLayout
* @param tableLayout Contain all column names and optionnaly the table title
*/
TableTextFormatter( TableLayout const & tableLayout );


/**
* @brief Destroy the Table Text Formatter object
*/
Expand All @@ -113,11 +141,12 @@ class TableTextFormatter : public TableFormatter
string layoutToString() const;

/**
* @brief Convert the TableData to a table string.
* @param tableData The TableData to convert.
* @brief Convert a data source to a table string.
* @param tableData The data source to convert.
* @return The table string representation of the TableData.
*/
string toString( TableData const & tableData ) const;
template< typename DATASOURCE >
string toString( DATASOURCE const & tableData ) const;

private:

Expand All @@ -126,7 +155,7 @@ class TableTextFormatter : public TableFormatter
/// for the extremity of a row
static constexpr char m_horizontalLine = '-';

/**F
/**
* @brief Fill the vector (m_column) in tableData with values from rows stored in tableData.
* @param columns Vector of columns to be filled.
* @param tableData Vector containing all rows filled with values
Expand Down Expand Up @@ -217,6 +246,14 @@ class TableTextFormatter : public TableFormatter
integer const nbRows,
TableLayout::Section const section ) const;
};

/**
* @brief Convert a TableData to a table string.
* @param tableData The TableData to convert.
* @return The table string representation of the TableData.
*/
template<>
string TableTextFormatter::toString< TableData >( TableData const & tableData ) const;
}

#endif /* GEOS_COMMON_FORMAT_TABLE_TABLEFORMATTER_HPP */
2 changes: 2 additions & 0 deletions src/coreComponents/common/format/table/TableLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class TableLayout
string m_maxStringSize;
};

TableLayout() = default;

/**
* @brief Construct a new Table object, all values in the table are centered by default
* @param columnNames The names of the columns
Expand Down
15 changes: 7 additions & 8 deletions src/coreComponents/common/format/table/unitTests/testTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ TEST( testTable, table2DTable )
//convert
string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" );
string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" );
TableData2D::Conversion1D tableconverted = tableData.buildTableData( "Viscosity kg*s",
rowFmt,
columnFmt );
TableData2D::TableDataHolder tableconverted = tableData.buildTableData( "Viscosity kg*s",
rowFmt,
columnFmt );

//format
TableLayout const tableLayout( tableconverted.headerNames );
Expand Down Expand Up @@ -248,9 +248,9 @@ TEST( testTable, table2DColumnMismatch )
//convert
string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" );
string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" );
TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s",
rowFmt,
columnFmt );
TableData2D::TableDataHolder tableConverted = tableData.buildTableData( "Viscosity kg*s",
rowFmt,
columnFmt );

//format
TableLayout const tableLayout( tableConverted.headerNames );
Expand All @@ -274,11 +274,10 @@ TEST( testTable, table2DColumnMismatch )
TEST( testTable, layoutTable )
{
string filename = "fluid1_phaseModel1_PhillipsBrineDensity_table";
//2. format

string log = GEOS_FMT( "The {} PVT table exceeding 500 rows.\nTo visualize the tables, go to the generated csv \n", filename );
TableLayout const tableLayoutInfos( {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}}, filename );

//3. log
TableTextFormatter const tableLog( tableLayoutInfos );
EXPECT_EQ( tableLog.layoutToString(),
"\n-------------------------------------------------------------------------------------\n"
Expand Down
10 changes: 9 additions & 1 deletion src/coreComponents/constitutive/ConstitutiveBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace constitutive
ConstitutiveBase::ConstitutiveBase( string const & name,
Group * const parent ):
Group( name, parent ),
m_numQuadraturePoints( 1 )
m_numQuadraturePoints( 1 ),
m_isClone( false )
{
setInputFlags( InputFlags::OPTIONAL_NONUNIQUE );
}
Expand Down Expand Up @@ -72,6 +73,11 @@ void ConstitutiveBase::allocateConstitutiveData( dataRepository::Group & parent,
this->resize( parent.size() );
}

void ConstitutiveBase::setIsClone( bool const newState )
{
m_isClone = newState;
}

std::unique_ptr< ConstitutiveBase >
ConstitutiveBase::deliverClone( string const & name,
Group * const parent ) const
Expand All @@ -84,6 +90,8 @@ ConstitutiveBase::deliverClone( string const & name,
wrapper.copyWrapper( this->getWrapperBase( wrapper.getName() ) );
} );

newModel->setIsClone( true );

return newModel;
}

Expand Down
14 changes: 14 additions & 0 deletions src/coreComponents/constitutive/ConstitutiveBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ class ConstitutiveBase : public dataRepository::Group

localIndex numQuadraturePoints() const { return m_numQuadraturePoints; }

/**
* @return true if the instance has been produced with deliverClone()
*/
bool isClone() const { return m_isClone; }

virtual std::vector< string > getSubRelationNames() const { return {}; }

/**
Expand Down Expand Up @@ -162,7 +167,16 @@ class ConstitutiveBase : public dataRepository::Group

private:

/**
* @brief Set a isClone state boolean
* @param newState The state of the new constitutive model
*/
void setIsClone( bool const newState );

localIndex m_numQuadraturePoints;

/// Indicate if this constitutive model a clone
bool m_isClone;
};

}
Expand Down
Loading

0 comments on commit 0db85be

Please sign in to comment.