From 751a91919fb8d1a4f806f65d197be0dade06be0f Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 9 Feb 2024 16:11:56 +0100 Subject: [PATCH 001/216] Table function creation --- .../codingUtilities/CMakeLists.txt | 4 +- .../codingUtilities/StringUtilities.hpp | 7 + src/coreComponents/codingUtilities/Table.cpp | 312 ++++++++++++++++++ src/coreComponents/codingUtilities/Table.hpp | 209 ++++++++++++ .../codingUtilities/tests/CMakeLists.txt | 4 +- .../codingUtilities/tests/testTable.cpp | 297 +++++++++++++++++ src/coreComponents/common/Units.hpp | 11 + .../mesh/generators/InternalWellGenerator.cpp | 64 ++-- 8 files changed, 880 insertions(+), 28 deletions(-) create mode 100644 src/coreComponents/codingUtilities/Table.cpp create mode 100644 src/coreComponents/codingUtilities/Table.hpp create mode 100644 src/coreComponents/codingUtilities/tests/testTable.cpp diff --git a/src/coreComponents/codingUtilities/CMakeLists.txt b/src/coreComponents/codingUtilities/CMakeLists.txt index 784e4aa0455..bbc691fd203 100644 --- a/src/coreComponents/codingUtilities/CMakeLists.txt +++ b/src/coreComponents/codingUtilities/CMakeLists.txt @@ -9,6 +9,7 @@ set( codingUtilities_headers UnitTestUtilities.hpp Utilities.hpp traits.hpp + Table.hpp ) # @@ -16,7 +17,8 @@ set( codingUtilities_headers # set( codingUtilities_sources Parsing.cpp - StringUtilities.cpp ) + StringUtilities.cpp + Table.cpp ) set( dependencyList ${parallelDeps} common fast_float ) diff --git a/src/coreComponents/codingUtilities/StringUtilities.hpp b/src/coreComponents/codingUtilities/StringUtilities.hpp index db1fac9d409..f0ac1c49dfb 100644 --- a/src/coreComponents/codingUtilities/StringUtilities.hpp +++ b/src/coreComponents/codingUtilities/StringUtilities.hpp @@ -255,6 +255,13 @@ constexpr bool endsWith( std::string_view str, std::string_view suffix ) str.compare( str.size()-suffix.size(), suffix.size(), suffix ) == 0; } +template +std::ostream& operator<<(std::ostream& os, std::optional const& t) +{ + if (t) os << t.value(); + return os; +} + } // namespace stringutilities } // namespace geos diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp new file mode 100644 index 00000000000..3f0d0b1ee0f --- /dev/null +++ b/src/coreComponents/codingUtilities/Table.cpp @@ -0,0 +1,312 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file Table.cpp + */ + +#include "Table.hpp" + +namespace geos +{ + +std::string const cellAlignment( Table::Alignment const & a, std::string const & value, int spaces ) +{ + switch( a ) + { + case Table::right: return GEOS_FMT( "{:>{}}", value, spaces ); + case Table::left: return GEOS_FMT( "{:<{}}", value, spaces ); + case Table::middle: return GEOS_FMT( "{:^{}}", value, spaces ); + default: return GEOS_FMT( "{:<{}}", value, spaces ); + } +} + +std::string Table::getStringSection( Section section ) const +{ + switch( section ) + { + case Section::header: return "header"; + case Section::values: return "values"; + default: return "values"; + } +} + + +Table::Table( std::vector< std::string > const & headers ): + maxRowHeader( 0 ) +{ + for( size_t idx = 0; idx< headers.size(); idx++ ) + { + m_columns.push_back( {Table::ColumnParam{{headers[idx]}, Alignment::middle, true}, {}, ""} ); + } +} + +Table::Table( std::vector< ColumnParam > const & columnParameter ) +{ + for( size_t idx = 0; idx< columnParameter.size(); idx++ ) + { + if( columnParameter[idx].enabled ) + { + m_columns.push_back( {columnParameter[idx], {}, ""} ); + } + } + maxRowHeader = 0; +} + +void Table::splitHeadersStringAndStore() +{ + for( size_t columnParamIdx = 0; columnParamIdx< m_columns.size(); columnParamIdx++ ) + { + std::vector< std::string > splitHeaderParts; + std::stringstream ss( m_columns[columnParamIdx].parameter.headerName[0] ); + std::string subHeaderName; + + while( getline( ss, subHeaderName, '\n' )) + { + splitHeaderParts.push_back( subHeaderName ); + } + + size_t cellSize = splitHeaderParts.size(); + maxRowHeader = std::max( maxRowHeader, cellSize ); + + m_splitHeader.push_back( splitHeaderParts ); + } +} + +void Table::addSpaceToSplitHeaderAndStore() +{ + for( size_t columnParamIdx = 0; columnParamIdx < m_columns.size(); columnParamIdx++ ) + { + if( m_splitHeader[columnParamIdx].size() < maxRowHeader ) + { + integer whiteRowToAdd = maxRowHeader - m_splitHeader[columnParamIdx].size(); + m_splitHeader[columnParamIdx].insert( m_splitHeader[columnParamIdx].end(), whiteRowToAdd, " " ); + } + m_columns[columnParamIdx].parameter.headerName = m_splitHeader[columnParamIdx]; + } +} + +void Table::setTitle( std::string const & title_ ) +{ + title = title_; +} + +std::string const & Table::getTitle() +{ + return title; +} + +void Table::findMaxStringSize() +{ + std::string maxStringSize = ""; + for( size_t idxColumn = 0; idxColumn < m_columns.size(); idxColumn++ ) + { + auto it = std::max_element( m_columns[idxColumn].parameter.headerName.begin(), + m_columns[idxColumn].parameter.headerName.end(), + []( const auto & a, const auto & b ) { + return a.size() < b.size(); + } ); + + maxStringSize = *it; + + for( size_t idxRow = 0; idxRow < m_cellsRows.size(); idxRow++ ) + { + std::string cell = m_columns[idxColumn].columnValues[idxRow]; + if( maxStringSize.length() < cell.length()) + { + maxStringSize = cell; + } + } + m_columns[idxColumn].m_maxStringSize = maxStringSize; + } +} + +void Table::computeAndSetMaxStringSize( string::size_type const & sectionlineLength, + string::size_type const & titleLineLength ) +{ + integer extraLinesPerColumn; + integer extraLines; + integer newStringSize; + + extraLines = titleLineLength - sectionlineLength; + extraLinesPerColumn = std::ceil( extraLines / m_columns.size() ); + + for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) + { + newStringSize = extraLinesPerColumn + m_columns[idxColumn].m_maxStringSize.size(); + if( idxColumn == m_columns.size() - 1 || m_columns.size() == 1 ) + { + m_columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", + m_columns[idxColumn].m_maxStringSize, + newStringSize + columnMargin ); + } + else + { + m_columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", + m_columns[idxColumn].m_maxStringSize, + newStringSize ); + } + } +} + +void Table::computeAndBuildLines() +{ + string::size_type sectionlineLength = 0; + string::size_type titleLineLength = title.length() + ( marginTitle * 2 ); + integer nbSpaceBetweenColumn = ( ( m_columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); + + if( !title.empty()) + { + title = GEOS_FMT( "{:^{}}", title, titleLineLength ); + } + + for( std::size_t i = 0; i < m_columns.size(); ++i ) + { + sectionlineLength += m_columns[i].m_maxStringSize.length(); + } + + sectionlineLength += nbSpaceBetweenColumn; + + if( sectionlineLength < titleLineLength ) + { + computeAndSetMaxStringSize( sectionlineLength, titleLineLength ); + } + + if( m_columns.size() == 1 ) + { + sectionSeparator += GEOS_FMT( "+{:-<{}}+", + "", + ( m_columns[0].m_maxStringSize.length() + (borderMargin - 1) + columnMargin )); + } + else + { + for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) + { + integer cellSize = m_columns[idxColumn].m_maxStringSize.length(); + + if( idxColumn == 0 ) + { + sectionSeparator += GEOS_FMT( "+{:-<{}}", "", ( cellSize + borderMargin )); + } + else if( idxColumn == (m_columns.size() - 1)) + { + sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); + sectionSeparator += GEOS_FMT( "{:->{}}", "+", ( cellSize + borderMargin + 1 ) ); + } + else + { + sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); + sectionSeparator += GEOS_FMT( "{:->{}}", "", cellSize ); + } + } + } + topSeparator = GEOS_FMT( "+{:-<{}}+", "", sectionSeparator.size() - 2 );// -2 for ++ +} + +void Table::buildTitleRow() +{ + titleRow = GEOS_FMT( "\n{}\n|", topSeparator ); + titleRow += cellAlignment( Alignment::middle, + title, + (sectionSeparator.length() - 2) // -2 for || + ); + titleRow += GEOS_FMT( "{}\n", "|" ); +} + +void Table::buildSectionRows( integer const & nbRows, Section const & sectionName ) +{ + + for( integer idxRow = 0; idxRow< nbRows; idxRow++ ) + { + rows += GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); + for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) + { + std::string cell; + + if( getStringSection( sectionName ) == "header" ) + { + cell = m_columns[idxColumn].parameter.headerName[idxRow]; + } + else + { + cell = m_columns[idxColumn].columnValues[idxRow]; + } + integer cellSize = m_columns[idxColumn].m_maxStringSize.length(); + rows += cellAlignment( m_columns[idxColumn].parameter.alignment, + cell, + cellSize ); + + if( idxColumn < m_columns.size() - 1 ) + { + rows += GEOS_FMT( "{:^{}}", "|", columnMargin ); + } + + } + if( m_columns.size() == 1 ) + { + rows += GEOS_FMT( "{:>{}}\n", "|", columnMargin ); + } + else + { + rows += GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); + } + + } + if( nbRows != 0 ) + { + rows += GEOS_FMT( "{}\n", sectionSeparator ); + } +} + +void Table::fillColumnsValuesFromCellsRows() +{ + for( size_t idxRow = 0; idxRow < m_cellsRows.size(); idxRow++ ) + { + for( size_t idxColumn = 0; idxColumn < m_columns.size(); idxColumn++ ) + { + m_columns[idxColumn].columnValues.push_back( m_cellsRows[idxRow][idxColumn] ); + } + } +} + +void Table::draw( std::ostringstream & oss ) +{ + oss.clear(); + std::string tableOutput; + + fillColumnsValuesFromCellsRows(); + + splitHeadersStringAndStore(); + addSpaceToSplitHeaderAndStore(); + + findMaxStringSize(); + computeAndBuildLines(); + + if( !title.empty()) + { + buildTitleRow(); + } + + rows += GEOS_FMT( "{}\n", sectionSeparator ); + buildSectionRows( maxRowHeader, Section::header ); + buildSectionRows( m_cellsRows.size(), Section::values ); + + tableOutput = titleRow + rows; + + std::cout << tableOutput; + + oss << tableOutput; +} + +} diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp new file mode 100644 index 00000000000..c000c328adb --- /dev/null +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -0,0 +1,209 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file Table.hpp + */ + +#ifndef GEOS_COMMON_TABLE_HPP +#define GEOS_COMMON_TABLE_HPP + +#include "common/DataTypes.hpp" + +namespace geos +{ + +class Table +{ +public: + + enum Alignment { right, left, middle }; + + enum MarginColumn {small, medium, large}; + + /** + * @brief Struct for a ColumnParam. + * @param [in] headerName A vector containing all string for a header name + * @param [in] columnValues Alignment for a column. By default aligned to the right side + * @param [in] enabled A boolean to display a colummn + */ + struct ColumnParam + { + std::vector< std::string > headerName; + Alignment alignment = Alignment::right; + bool enabled = true; + }; + + /** + * @brief Construct a new Table object, all values in the table are centered by default + * + * @param columnNames + */ + Table( std::vector< std::string > const & columnNames ); + + /** + * @brief Construct a new Table object by specifying alignment of values in the table and optionally their display according to their log + *level + * + * @param columnParameter + */ + Table( std::vector< ColumnParam > const & columnParameter ); + + /** + * @brief Add a row the the table. The number of arguments need to match with the number of header values + * + * @tparam N + * @tparam Args + * @param args + */ + template< size_t N, typename ... Args > + void addRow( const Args &... args ); + + /** + * @brief Display the table + * + * @param os + */ + void draw( std::ostringstream & os ); + + /** + * @brief Set the name of the table + * @param [in] title The name of the table + */ + void setTitle( const std::string & title ); + + /** + * @brief Get the table title + * + * @return return the table name + */ + std::string const & getTitle(); + +private: + + enum Section { header, values }; + + /** + * @brief Struct for a column. + * @param [in] parameter Column parameter + * @param [in] columnValues All column values + * @param [in] m_maxStringSize The largest string in the column + */ + struct Column + { + ColumnParam parameter; + std::vector< std::string > columnValues; + std::string m_maxStringSize; + }; + + /** + * @brief Get the name of the section given an enum + * + * @param section + * @return The name of the section + */ + std::string getStringSection( Section section ) const; + + /** + * @brief the vector column \p m_column with all values previously stored in the constructor + * + */ + void fillColumnsValuesFromCellsRows(); + + /** + * @brief Split all header names by detecting \p '\n' character and store each split header name into a vector. + * + */ + void splitHeadersStringAndStore(); + + /** + * @brief Iterate throught all header name vector and set them to the same size by adding an empty string. + * + */ + void addSpaceToSplitHeaderAndStore(); + + /** + * @brief For each column find the largest string size + * + */ + void findMaxStringSize(); + + /** + * @brief If the title is the largest string size in the table, recalculate for all column the \p m_maxStringSize value + * by adding an extra number of characters + * + */ + void computeAndSetMaxStringSize( string::size_type const & sectionlineLength, + string::size_type const & titleLineLength ); + /** + * @brief Compute the lines separator + * + */ + void computeAndBuildLines(); + + /** + * @brief Build the title section + * + */ + void buildTitleRow(); + + /** + * @brief build the header or values section + * + * @param nbRows + * @param sectionName + */ + void buildSectionRows( integer const & nbRows, Section const & sectionName ); + + std::vector< std::vector< std::string > > m_splitHeader; + std::vector< std::vector< string > > m_cellsRows; + std::vector< Column > m_columns; + + std::string title; + std::string topSeparator; + std::string sectionSeparator; + size_t maxRowHeader; + + int marginTitle = 2; + int borderMargin = 2; + int columnMargin = 5; + + std::string titleRow; + std::string rows; + +}; + +template< size_t N, typename ... Args > +void Table::addRow( const Args &... args ) +{ + constexpr std::size_t nbColumn_ = sizeof...(args); + static_assert( nbColumn_ == N, + "The number of cells per line does not correspond to the number of parameters" ); + + std::vector< std::string > rowsValues; + int idx = 0; + ( [&] { + std::string cellValue = GEOS_FMT( "{}", args ); + if( m_columns[idx].parameter.enabled ) + { + rowsValues.push_back( cellValue ); + } + } (), ...); + + m_cellsRows.push_back( rowsValues ); +} + +} + +#endif diff --git a/src/coreComponents/codingUtilities/tests/CMakeLists.txt b/src/coreComponents/codingUtilities/tests/CMakeLists.txt index f70776694a0..734991b3b91 100644 --- a/src/coreComponents/codingUtilities/tests/CMakeLists.txt +++ b/src/coreComponents/codingUtilities/tests/CMakeLists.txt @@ -2,12 +2,14 @@ set( testSources testGeosxTraits.cpp testStringUtilities.cpp - testParsing.cpp ) + testParsing.cpp + testTable.cpp ) set( dependencyList gtest codingUtilities ${parallelDeps} ) # Add gtest C++ based tests foreach( test ${testSources} ) + get_filename_component( test_name ${test} NAME_WE ) blt_add_executable( NAME ${test_name} SOURCES ${test} diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp new file mode 100644 index 00000000000..36f7bb6c810 --- /dev/null +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -0,0 +1,297 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +// Source includes +#include "../Table.hpp" +#include "../../dataRepository/Group.hpp" +// TPL includes +#include + +using namespace geos; + + +TEST( testTable, tableClass ) +{ + + std::vector< std::string > tableTestsOutput; + + std::ostringstream oss; + + Table tableTest( {"Well\nelement no.\nPV weighted\nbar", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"} + ); + tableTest.setTitle( "InternalWellGenerator well_injector1" ); + tableTest.addRow< 5 >( "value1", "[30.21543]", "3.0", 54, 0 ); + tableTest.addRow< 5 >( "", "", "", "", "" ); + tableTest.addRow< 5 >( "Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", "[30.21543]", "30.45465142", + 787442, 10 ); + tableTest.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.str( "" ); + EXPECT_EQ( tableTestsOutput[0], + "\n+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| Well | CordX | CoordZ | Prev | Next |\n" + "| element no. | | | element | element |\n" + "| PV weighted | | | | |\n" + "| bar | | | | |\n" + "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" + "| | | | | |\n" + "| Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | [30.21543] | 30.45465142 | 787442 | 10 |\n" + "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + ); + + Table tableTest2( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"} + ); + tableTest2.setTitle( "InternalWellGenerator well_injector1" ); + tableTest2.addRow< 5 >( "value1", "[30.21543]", "3.0", 54, 0 ); + tableTest2.addRow< 5 >( "", "", "", "", "" ); + tableTest2.addRow< 5 >( "value23", "[30.21543]", "30.45465142", 787442, 10 ); + tableTest2.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.str( "" ); + EXPECT_EQ( tableTestsOutput[1], + "\n+---------------------------------------------------------------------------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| Duis fringilla, ligula sed porta fringilla, | CordX | CoordZ | Prev | Next |\n" + "| ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | | | element | element |\n" + "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" + "| | | | | |\n" + "| value23 | [30.21543] | 30.45465142 | 787442 | 10 |\n" + "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + ); + + Table tableTest3 ( + { + "Cras egestas ipsum a nisl. Vivamus variu\ndolor utsisicdis parturient montes,\nnascetur ridiculus mus. Duis fringilla, ligula sed porta fringilla, ligula wisicommodo felis,\nut adi\npiscing felis dui in enim. Suspendisse malesuada ultrices ante", + "CoordX", "C", "CoordZ", + } ); + tableTest3.setTitle( "InternalWellGenerator well_injector1" ); + tableTest3.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.str( "" ); + EXPECT_EQ ( tableTestsOutput[2], + "\n+-----------------------------------------------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+-------------------------------------------------------------------------------------------------+----------+-----+----------+\n" + "| Cras egestas ipsum a nisl. Vivamus variu | CoordX | C | CoordZ |\n" + "| dolor utsisicdis parturient montes, | | | |\n" + "| nascetur ridiculus mus. Duis fringilla, ligula sed porta fringilla, ligula wisicommodo felis, | | | |\n" + "| ut adi | | | |\n" + "| piscing felis dui in enim. Suspendisse malesuada ultrices ante | | | |\n" + "+-------------------------------------------------------------------------------------------------+----------+-----+----------+\n" + ); + + Table tableTest4( { + Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordX"}, Table::Alignment::left}, + Table::ColumnParam{{"C"}, Table::Alignment::left}, + Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, + Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::right}, + Table::ColumnParam{{"Next\nelement"}, Table::Alignment::right} + } ); + tableTest4.setTitle( "InternalWellGenerator well_injector1" ); + tableTest4.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest4.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest4.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.str( "" ); + EXPECT_EQ( tableTestsOutput[3], + "\n+-----------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" + "| | | | | element | element |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + ); + + Table tableTest5( { + Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordX"}, Table::Alignment::left}, + Table::ColumnParam{{"C"}, Table::Alignment::left}, + Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, + Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::right, false}, + Table::ColumnParam{{"Next\nelement"}, Table::Alignment::right, false}, + + } ); + tableTest5.setTitle( "InternalWellGenerator well_injector1" ); + tableTest5.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest5.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest5.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.str( "" ); + EXPECT_EQ( tableTestsOutput[4], + "\n+-----------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+----------------+----------+-----------------------+-------------+\n" + "| Cras egestas | CoordX | C | CoordZ |\n" + "+----------------+----------+-----------------------+-------------+\n" + "| value1 | | 3.0 | 3.0129877 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 |\n" + "+----------------+----------+-----------------------+-------------+\n" + ); + + Table tableTest6( { + Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordX"}, Table::Alignment::left}, + Table::ColumnParam{{"C"}, Table::Alignment::left}, + Table::ColumnParam{{"CoordZ"}, Table::Alignment::middle}, + Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::right}, + Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, + } ); + tableTest6.setTitle( "InternalWellGenerator well_injector1" ); + tableTest6.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest6.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest6.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.str( "" ); + EXPECT_EQ( tableTestsOutput[5], + "\n+-----------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" + "| | | | | element | element |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + ); + + Table tableTest7( { + Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordX"}, Table::Alignment::right}, + Table::ColumnParam{{"C"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, + Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::left, false}, + Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle, false}, + } ); + tableTest7.setTitle( "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + tableTest7.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest7.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest7.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.str( "" ); + EXPECT_EQ( tableTestsOutput[6], + "\n+------------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" + "| Cras egestas | CoordX | C | CoordZ |\n" + "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" + "| value1 | | 3.0 | 3.0129877 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 |\n" + "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" + ); + + Table tableTest8( { + Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordX"}, Table::Alignment::right}, + Table::ColumnParam{{"C"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, + Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::left}, + Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, + } ); + tableTest8.setTitle( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + tableTest8.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest8.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest8.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.str( "" ); + EXPECT_EQ( tableTestsOutput[7], + "\n+----------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "+-------------------+-------------+--------------------------+----------------+--------------+-------------------+\n" + "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" + "| | | | | element | element |\n" + "+-------------------+-------------+--------------------------+----------------+--------------+-------------------+\n" + "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" + "+-------------------+-------------+--------------------------+----------------+--------------+-------------------+\n" + ); + + Table tableTest9( { + Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, + + } ); + tableTest9.setTitle( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + tableTest9.addRow< 1 >( "value1" ); + tableTest9.addRow< 1 >( "val1" ); + tableTest9.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.str( "" ); + EXPECT_EQ( tableTestsOutput[8], + "\n+-------------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "+-------------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas |\n" + "+-------------------------------------------------------------------------------------------------------------------+\n" + "| value1 |\n" + "| val1 |\n" + "+-------------------------------------------------------------------------------------------------------------------+\n" + ); + + Table tableTest10( { + Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, + } ); + tableTest10.setTitle( "title1" ); + tableTest10.addRow< 1 >( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + tableTest10.addRow< 1 >( "val1" ); + tableTest10.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.str( "" ); + EXPECT_EQ( tableTestsOutput[9], + "\n+--------------------------------------------------------------------------------------------------------------+\n" + "| title1 |\n" + "+--------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas |\n" + "+--------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "| val1 |\n" + "+--------------------------------------------------------------------------------------------------------------+\n" + ); + + Table tableTest11( { + Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, + } ); + tableTest11.setTitle( "title1" ); + tableTest11.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.str( "" ); + EXPECT_EQ( tableTestsOutput[10], + "\n+------------------+\n" + "| title1 |\n" + "+------------------+\n" + "| Cras egestas |\n" + "+------------------+\n" + ); +} + +int main( int argc, char * * argv ) +{ + testing::InitGoogleTest( &argc, argv ); + return RUN_ALL_TESTS();; +} diff --git a/src/coreComponents/common/Units.hpp b/src/coreComponents/common/Units.hpp index 43e8fc680e3..19e6847673c 100644 --- a/src/coreComponents/common/Units.hpp +++ b/src/coreComponents/common/Units.hpp @@ -245,4 +245,15 @@ struct GEOS_FMT_NS::formatter< geos::units::TimeFormatInfo > : GEOS_FMT_NS::form } }; +template +struct GEOS_FMT_NS::formatter> : GEOS_FMT_NS::formatter< T > +{ + auto format(std::optional const& opt, format_context & ctx) { + if (opt) { + return GEOS_FMT_NS::formatter::format(*opt, ctx); + } + return GEOS_FMT_NS::format_to(ctx.out(), "NO VALUE"); + } +}; + #endif //GEOS_MATH_PHYSICSCONSTANTS_HPP_ diff --git a/src/coreComponents/mesh/generators/InternalWellGenerator.cpp b/src/coreComponents/mesh/generators/InternalWellGenerator.cpp index 22060669605..c6d6f61d8ac 100644 --- a/src/coreComponents/mesh/generators/InternalWellGenerator.cpp +++ b/src/coreComponents/mesh/generators/InternalWellGenerator.cpp @@ -24,6 +24,7 @@ #include "mesh/generators/LineBlockABC.hpp" #include "LvArray/src/genericTensorOps.hpp" #include "physicsSolvers/fluidFlow/wells/WellControls.hpp" +#include "codingUtilities/Table.hpp" namespace geos { @@ -543,53 +544,64 @@ void InternalWellGenerator::debugWellGeometry() const return; } - std::cout << std::endl; - std::cout << "++++++++++++++++++++++++++" << std::endl; - std::cout << "InternalWellGenerator = " << getName() << std::endl; - std::cout << "MPI rank = " << MpiWrapper::commRank( MPI_COMM_GEOSX ) << std::endl << std::endl; - std::cout << "Number of well elements = " << m_numElems << std::endl; + std::vector< std::string > row; + std::ostringstream oss; + Table table = Table( { + Table::ColumnParam{{"Element no."}, Table::Alignment::right}, + Table::ColumnParam{{"CoordX"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordY"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordZ"}, Table::Alignment::middle}, + Table::ColumnParam{{"Prev\nElement"}, Table::Alignment::right}, + Table::ColumnParam{{"Next\nElement"}, Table::Alignment::right}, + } + ); + + std::string titleName = "InternalWellGenerator " + getName(); + table.setTitle( titleName ); for( globalIndex iwelem = 0; iwelem < m_numElems; ++iwelem ) { - std::cout << "Well element #" << iwelem << std::endl; - std::cout << "Coordinates of the element center: " << m_elemCenterCoords[iwelem] << std::endl; - if( m_nextElemId[iwelem] < 0 ) - { - std::cout << "No next well element" << std::endl; - } - else - { - std::cout << "Next well element # = " << m_nextElemId[iwelem] << std::endl; - } - if( m_prevElemId[iwelem][0] < 0 ) + std::optional< globalIndex > nextElement; + std::optional< globalIndex > prevElement; + + if( m_nextElemId[iwelem] >= 0 ) { - std::cout << "No previous well element" << std::endl; + nextElement = m_nextElemId[iwelem]; } - else + + if( m_prevElemId[iwelem][0] >= 0 ) { - std::cout << "Previous well element #" << m_prevElemId[iwelem][0] << std::endl; + prevElement = m_prevElemId[iwelem][0]; } + for( globalIndex inode = 0; inode < m_numNodesPerElem; ++inode ) { if( inode == 0 ) { - std::cout << "First well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; + //std::cout << "First well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; } else { - std::cout << "Second well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; + //std::cout << "Second well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; } } - } + table.addRow< 6 >( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, + nextElement ); - std::cout << std::endl << "Number of perforations = " << m_numPerforations << std::endl; + } + table.draw( oss ); + Table tablePerforation = Table( {"Perforation no.", "Coordinates\nlong string", "connected toO" } ); + std::string titlePerfo = "Peforation table "; + tablePerforation.setTitle( titlePerfo ); + for( globalIndex iperf = 0; iperf < m_numPerforations; ++iperf ) { - std::cout << "Perforation #" << iperf << std::endl; - std::cout << "Coordinates of the perforation: " << m_perfCoords[iperf] << std::endl; - std::cout << "Is connected to well element #" << m_perfElemId[iperf] << std::endl; + tablePerforation.addRow< 3 >( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); } + + tablePerforation.draw( oss ); + std::cout << std::endl; } From c84a06eedd6f11b95c5e2e52b8bf763ad669d986 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 9 Feb 2024 17:19:46 +0100 Subject: [PATCH 002/216] add title off case --- .../codingUtilities/tests/testTable.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 36f7bb6c810..d3308063322 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -288,8 +288,32 @@ TEST( testTable, tableClass ) "| Cras egestas |\n" "+------------------+\n" ); + + Table tableTest12( { + Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordX"}, Table::Alignment::right}, + Table::ColumnParam{{"C"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, + Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::left}, + Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, + } ); + tableTest12.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest12.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest12.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.str( "" ); + EXPECT_EQ( tableTestsOutput[11], + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" + "| | | | | element | element |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + ); } + int main( int argc, char * * argv ) { testing::InitGoogleTest( &argc, argv ); From 57bc05501a88e86742ab11e2729d0ab1793953a1 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 12 Feb 2024 11:02:30 +0100 Subject: [PATCH 003/216] setMargin function added --- src/coreComponents/codingUtilities/Table.cpp | 64 ++++++++++++++++---- src/coreComponents/codingUtilities/Table.hpp | 41 +++++++++++-- 2 files changed, 88 insertions(+), 17 deletions(-) diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp index 3f0d0b1ee0f..cebd3311a8b 100644 --- a/src/coreComponents/codingUtilities/Table.cpp +++ b/src/coreComponents/codingUtilities/Table.cpp @@ -42,8 +42,9 @@ std::string Table::getStringSection( Section section ) const } } - Table::Table( std::vector< std::string > const & headers ): + borderMargin( getMargin( MarginType::border )), + columnMargin( getMargin( MarginType::column )), maxRowHeader( 0 ) { for( size_t idx = 0; idx< headers.size(); idx++ ) @@ -52,7 +53,9 @@ Table::Table( std::vector< std::string > const & headers ): } } -Table::Table( std::vector< ColumnParam > const & columnParameter ) +Table::Table( std::vector< ColumnParam > const & columnParameter ): + borderMargin( getMargin( MarginType::border )), + columnMargin( getMargin( MarginType::column )) { for( size_t idx = 0; idx< columnParameter.size(); idx++ ) { @@ -64,6 +67,18 @@ Table::Table( std::vector< ColumnParam > const & columnParameter ) maxRowHeader = 0; } +Table::Margin Table::getMargin( MarginType const & type ) + { + Margin marginBorder {0, 1, 2, 3, 2}; + Margin marginColumn {0, 3, 5, 7, 5}; + if(type == MarginType::border) + { + return marginBorder; + } + return marginColumn; + + } + void Table::splitHeadersStringAndStore() { for( size_t columnParamIdx = 0; columnParamIdx< m_columns.size(); columnParamIdx++ ) @@ -107,6 +122,29 @@ std::string const & Table::getTitle() return title; } +void Table::setMargin( MarginValue const & valueType ) +{ + switch( valueType ) + { + case MarginValue::tiny: + borderMargin.setWorkingValue( borderMargin.tiny ); + columnMargin.setWorkingValue( columnMargin.tiny ); + break; + case MarginValue::small: + borderMargin.setWorkingValue( borderMargin.small ); + columnMargin.setWorkingValue( columnMargin.small ); + break; + case MarginValue::medium: + borderMargin.setWorkingValue( borderMargin.medium ); + columnMargin.setWorkingValue( columnMargin.medium ); + break; + case MarginValue::large: + borderMargin.setWorkingValue( borderMargin.large ); + columnMargin.setWorkingValue( columnMargin.large ); + break; + } +} + void Table::findMaxStringSize() { std::string maxStringSize = ""; @@ -149,7 +187,7 @@ void Table::computeAndSetMaxStringSize( string::size_type const & sectionlineLen { m_columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", m_columns[idxColumn].m_maxStringSize, - newStringSize + columnMargin ); + newStringSize + columnMargin.marginValue ); } else { @@ -164,7 +202,7 @@ void Table::computeAndBuildLines() { string::size_type sectionlineLength = 0; string::size_type titleLineLength = title.length() + ( marginTitle * 2 ); - integer nbSpaceBetweenColumn = ( ( m_columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); + integer nbSpaceBetweenColumn = ( ( m_columns.size() - 1 ) * columnMargin.marginValue ) + (borderMargin.marginValue * 2); if( !title.empty()) { @@ -187,7 +225,7 @@ void Table::computeAndBuildLines() { sectionSeparator += GEOS_FMT( "+{:-<{}}+", "", - ( m_columns[0].m_maxStringSize.length() + (borderMargin - 1) + columnMargin )); + ( m_columns[0].m_maxStringSize.length() + (borderMargin.marginValue - 1) + columnMargin.marginValue )); } else { @@ -197,16 +235,16 @@ void Table::computeAndBuildLines() if( idxColumn == 0 ) { - sectionSeparator += GEOS_FMT( "+{:-<{}}", "", ( cellSize + borderMargin )); + sectionSeparator += GEOS_FMT( "+{:-<{}}", "", ( cellSize + borderMargin.marginValue )); } else if( idxColumn == (m_columns.size() - 1)) { - sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); - sectionSeparator += GEOS_FMT( "{:->{}}", "+", ( cellSize + borderMargin + 1 ) ); + sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin.marginValue ); + sectionSeparator += GEOS_FMT( "{:->{}}", "+", ( cellSize + borderMargin.marginValue + 1 ) ); } else { - sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); + sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin.marginValue ); sectionSeparator += GEOS_FMT( "{:->{}}", "", cellSize ); } } @@ -229,7 +267,7 @@ void Table::buildSectionRows( integer const & nbRows, Section const & sectionNam for( integer idxRow = 0; idxRow< nbRows; idxRow++ ) { - rows += GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); + rows += GEOS_FMT( "{:<{}}", "|", 1 + borderMargin.marginValue ); for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) { std::string cell; @@ -249,17 +287,17 @@ void Table::buildSectionRows( integer const & nbRows, Section const & sectionNam if( idxColumn < m_columns.size() - 1 ) { - rows += GEOS_FMT( "{:^{}}", "|", columnMargin ); + rows += GEOS_FMT( "{:^{}}", "|", columnMargin.marginValue ); } } if( m_columns.size() == 1 ) { - rows += GEOS_FMT( "{:>{}}\n", "|", columnMargin ); + rows += GEOS_FMT( "{:>{}}\n", "|", columnMargin.marginValue ); } else { - rows += GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); + rows += GEOS_FMT( "{:>{}}\n", "|", borderMargin.marginValue + 1 ); } } diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index c000c328adb..c581dac6dcc 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -30,7 +30,24 @@ class Table enum Alignment { right, left, middle }; - enum MarginColumn {small, medium, large}; + enum MarginType {border, column}; + + enum MarginValue { tiny, small, medium, large}; + + struct Margin + { + integer tiny; + integer small; + integer medium; + integer large; + + integer marginValue; + + void setWorkingValue( integer const & value ) + { + marginValue = value; + } + }; /** * @brief Struct for a ColumnParam. @@ -54,7 +71,7 @@ class Table /** * @brief Construct a new Table object by specifying alignment of values in the table and optionally their display according to their log - *level + * level * * @param columnParameter */ @@ -83,6 +100,13 @@ class Table */ void setTitle( const std::string & title ); + /** + * @brief Set the Margin object + * + * @param valueType + */ + void setMargin( MarginValue const & valueType ); + /** * @brief Get the table title * @@ -90,6 +114,9 @@ class Table */ std::string const & getTitle(); + Margin borderMargin; + Margin columnMargin; + private: enum Section { header, values }; @@ -107,6 +134,14 @@ class Table std::string m_maxStringSize; }; + /** + * @brief Get the Margin object + * + * @param type + * @return Margin + */ + Margin getMargin( MarginType const & type ); + /** * @brief Get the name of the section given an enum * @@ -176,8 +211,6 @@ class Table size_t maxRowHeader; int marginTitle = 2; - int borderMargin = 2; - int columnMargin = 5; std::string titleRow; std::string rows; From 6255f9b4a75100621913402835f5f9eda38863c5 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 12 Feb 2024 11:46:46 +0100 Subject: [PATCH 004/216] add comments + test for tiny table --- src/coreComponents/codingUtilities/Table.hpp | 21 ++++++++++----- .../codingUtilities/tests/testTable.cpp | 27 +++++++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index c581dac6dcc..8f7441e861c 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -34,6 +34,15 @@ class Table enum MarginValue { tiny, small, medium, large}; + /** + * @brief Struct for a column margin and border margin. + * @param tiny 0 margin for both; + * @param small 1 margin from | + * @param medium 2 margin from | + * @param large 3 margin from | + * + * @param marginValue current margin value + */ struct Margin { integer tiny; @@ -51,9 +60,9 @@ class Table /** * @brief Struct for a ColumnParam. - * @param [in] headerName A vector containing all string for a header name - * @param [in] columnValues Alignment for a column. By default aligned to the right side - * @param [in] enabled A boolean to display a colummn + * @param headerName A vector containing all string for a header name + * @param columnValues Alignment for a column. By default aligned to the right side + * @param enabled A boolean to display a colummn */ struct ColumnParam { @@ -114,9 +123,6 @@ class Table */ std::string const & getTitle(); - Margin borderMargin; - Margin columnMargin; - private: enum Section { header, values }; @@ -205,6 +211,9 @@ class Table std::vector< std::vector< string > > m_cellsRows; std::vector< Column > m_columns; + Margin borderMargin; + Margin columnMargin; + std::string title; std::string topSeparator; std::string sectionSeparator; diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index d3308063322..c535efaf448 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -311,6 +311,33 @@ TEST( testTable, tableClass ) "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" ); + + Table tableTest13( { + Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordX"}, Table::Alignment::right}, + Table::ColumnParam{{"C"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, + Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::left}, + Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, + } ); + tableTest13.setTitle( "InternalWellGenerator well_injector1" ); + tableTest13.setMargin( Table::MarginValue::tiny ); + tableTest13.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest13.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest13.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.str( "" ); + EXPECT_EQ( tableTestsOutput[12], + "\n+-----------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+------------+------+-------------------+---------+-------+-------+\n" + "|Cras egestas|CoordX| C |CoordZ |Prev | Next |\n" + "| | | | |element|element|\n" + "+------------+------+-------------------+---------+-------+-------+\n" + "| value1 | | 3.0 |3.0129877|2 | 1 |\n" + "| val1 | v|[3.045,42.02,89.25]|3 |10 | 3 |\n" + "+------------+------+-------------------+---------+-------+-------+\n" + ); } From 601a2c5ff6cb562701171376590919c5797f4960 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 13 Feb 2024 13:56:23 +0100 Subject: [PATCH 005/216] value default optionnal variable changed --- src/coreComponents/common/Units.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/common/Units.hpp b/src/coreComponents/common/Units.hpp index 19e6847673c..acdc0560f6f 100644 --- a/src/coreComponents/common/Units.hpp +++ b/src/coreComponents/common/Units.hpp @@ -252,7 +252,7 @@ struct GEOS_FMT_NS::formatter> : GEOS_FMT_NS::formatter< T > if (opt) { return GEOS_FMT_NS::formatter::format(*opt, ctx); } - return GEOS_FMT_NS::format_to(ctx.out(), "NO VALUE"); + return GEOS_FMT_NS::format_to(ctx.out(), ""); } }; From 677fdb687372bfe246f6c45ec3aa1a10cc5f8bb9 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 13 Feb 2024 14:21:20 +0100 Subject: [PATCH 006/216] add log to wellGeneratorBase --- .../mesh/generators/WellGeneratorBase.cpp | 64 +++++++++++-------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 554f4530bf7..3e02fd03fcb 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -528,55 +528,65 @@ void WellGeneratorBase::debugWellGeometry() const return; } - std::cout << std::endl; - std::cout << "++++++++++++++++++++++++++" << std::endl; - std::cout << "WellGeneratorBase = " << getName() << std::endl; - std::cout << "MPI rank = " << MpiWrapper::commRank( MPI_COMM_GEOSX ) << std::endl << std::endl; - std::cout << "Number of well elements = " << m_numElems << std::endl; + std::vector< std::string > row; + std::ostringstream oss; + Table table = Table( { + Table::ColumnParam{{"Element no."}, Table::Alignment::right}, + Table::ColumnParam{{"CoordX"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordY"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordZ"}, Table::Alignment::middle}, + Table::ColumnParam{{"Prev\nElement"}, Table::Alignment::right}, + Table::ColumnParam{{"Next\nElement"}, Table::Alignment::right}, + } + ); + + std::string titleName = "InternalWellGenerator " + getName(); + table.setTitle( titleName ); for( globalIndex iwelem = 0; iwelem < m_numElems; ++iwelem ) { - std::cout << "Well element #" << iwelem << std::endl; - std::cout << "Coordinates of the element center: " << m_elemCenterCoords[iwelem] << std::endl; - if( m_nextElemId[iwelem] < 0 ) - { - std::cout << "No next well element" << std::endl; - } - else - { - std::cout << "Next well element # = " << m_nextElemId[iwelem] << std::endl; - } - if( m_prevElemId[iwelem][0] < 0 ) + std::optional< globalIndex > nextElement; + std::optional< globalIndex > prevElement; + + if( m_nextElemId[iwelem] >= 0 ) { - std::cout << "No previous well element" << std::endl; + nextElement = m_nextElemId[iwelem]; } - else + + if( m_prevElemId[iwelem][0] >= 0 ) { - std::cout << "Previous well element #" << m_prevElemId[iwelem][0] << std::endl; + prevElement = m_prevElemId[iwelem][0]; } + for( globalIndex inode = 0; inode < m_numNodesPerElem; ++inode ) { if( inode == 0 ) { - std::cout << "First well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; + //std::cout << "First well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; } else { - std::cout << "Second well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; + //std::cout << "Second well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; } } - } + table.addRow< 6 >( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, + nextElement ); - std::cout << std::endl << "Number of perforations = " << m_numPerforations << std::endl; + } + table.draw( oss ); + Table tablePerforation = Table( {"Perforation no.", "Coordinates\nlong string", "connected toO" } ); + std::string titlePerfo = "Peforation table "; + tablePerforation.setTitle( titlePerfo ); + for( globalIndex iperf = 0; iperf < m_numPerforations; ++iperf ) { - std::cout << "Perforation #" << iperf << std::endl; - std::cout << "Coordinates of the perforation: " << m_perfCoords[iperf] << std::endl; - std::cout << "Is connected to well element #" << m_perfElemId[iperf] << std::endl; + tablePerforation.addRow< 3 >( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); } - std::cout << std::endl; + tablePerforation.draw( oss ); + + std::cout << std::endl; } } From 623b6ad275313d7c5bb03deb9685156f08d4bea7 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 13 Feb 2024 17:02:45 +0100 Subject: [PATCH 007/216] uncrustify + missing doc --- src/coreComponents/codingUtilities/Table.cpp | 18 ++++++++--------- src/coreComponents/codingUtilities/Table.hpp | 6 +++--- .../codingUtilities/tests/testTable.cpp | 2 +- src/coreComponents/common/Units.hpp | 20 ++++++++++++------- .../mesh/generators/InternalWellGenerator.cpp | 1 - .../mesh/generators/WellGeneratorBase.cpp | 10 +++++----- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp index cebd3311a8b..dc291bf54c4 100644 --- a/src/coreComponents/codingUtilities/Table.cpp +++ b/src/coreComponents/codingUtilities/Table.cpp @@ -67,17 +67,17 @@ Table::Table( std::vector< ColumnParam > const & columnParameter ): maxRowHeader = 0; } -Table::Margin Table::getMargin( MarginType const & type ) +Table::Margin Table::getMargin( MarginType const & type ) +{ + Margin marginBorder {0, 1, 2, 3, 2}; + Margin marginColumn {0, 3, 5, 7, 5}; + if( type == MarginType::border ) { - Margin marginBorder {0, 1, 2, 3, 2}; - Margin marginColumn {0, 3, 5, 7, 5}; - if(type == MarginType::border) - { - return marginBorder; - } - return marginColumn; - + return marginBorder; } + return marginColumn; + +} void Table::splitHeadersStringAndStore() { diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index 8f7441e861c..7323f3bf027 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -35,13 +35,13 @@ class Table enum MarginValue { tiny, small, medium, large}; /** - * @brief Struct for a column margin and border margin. + * @brief Struct for a column margin and border margin. * @param tiny 0 margin for both; * @param small 1 margin from | * @param medium 2 margin from | * @param large 3 margin from | - * - * @param marginValue current margin value + * + * @param marginValue current margin value */ struct Margin { diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index c535efaf448..5a96f9f925b 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -320,7 +320,7 @@ TEST( testTable, tableClass ) Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::left}, Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, } ); - tableTest13.setTitle( "InternalWellGenerator well_injector1" ); + tableTest13.setTitle( "InternalWellGenerator well_injector1" ); tableTest13.setMargin( Table::MarginValue::tiny ); tableTest13.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); tableTest13.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); diff --git a/src/coreComponents/common/Units.hpp b/src/coreComponents/common/Units.hpp index acdc0560f6f..c91c217a4e1 100644 --- a/src/coreComponents/common/Units.hpp +++ b/src/coreComponents/common/Units.hpp @@ -245,14 +245,20 @@ struct GEOS_FMT_NS::formatter< geos::units::TimeFormatInfo > : GEOS_FMT_NS::form } }; -template -struct GEOS_FMT_NS::formatter> : GEOS_FMT_NS::formatter< T > +/** + * @brief Format the std::optional to a string. + * @return return the corresponding value string. If std::optional is empty retun an empty string + */ +template< typename T > +struct GEOS_FMT_NS::formatter< std::optional< T > > : GEOS_FMT_NS::formatter< T > { - auto format(std::optional const& opt, format_context & ctx) { - if (opt) { - return GEOS_FMT_NS::formatter::format(*opt, ctx); - } - return GEOS_FMT_NS::format_to(ctx.out(), ""); + auto format( std::optional< T > const & opt, format_context & ctx ) + { + if( opt ) + { + return GEOS_FMT_NS::formatter< T >::format( *opt, ctx ); + } + return GEOS_FMT_NS::format_to( ctx.out(), "" ); } }; diff --git a/src/coreComponents/mesh/generators/InternalWellGenerator.cpp b/src/coreComponents/mesh/generators/InternalWellGenerator.cpp index 2b6abe8db16..5e5d9211a58 100644 --- a/src/coreComponents/mesh/generators/InternalWellGenerator.cpp +++ b/src/coreComponents/mesh/generators/InternalWellGenerator.cpp @@ -18,7 +18,6 @@ */ #include "InternalWellGenerator.hpp" -#include "codingUtilities/Table.hpp" namespace geos { diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 3e02fd03fcb..30e351594f7 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -17,7 +17,8 @@ #include "mesh/Perforation.hpp" #include "mesh/generators/LineBlockABC.hpp" #include "LvArray/src/genericTensorOps.hpp" - +#include "codingUtilities/Table.hpp" +#include "common/Units.hpp" namespace geos { using namespace dataRepository; @@ -562,15 +563,14 @@ void WellGeneratorBase::debugWellGeometry() const { if( inode == 0 ) { - //std::cout << "First well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; + //std::cout << "First well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; } else { //std::cout << "Second well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; } } - table.addRow< 6 >( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, - nextElement ); + table.addRow< 6 >( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, nextElement ); } table.draw( oss ); @@ -578,7 +578,7 @@ void WellGeneratorBase::debugWellGeometry() const Table tablePerforation = Table( {"Perforation no.", "Coordinates\nlong string", "connected toO" } ); std::string titlePerfo = "Peforation table "; tablePerforation.setTitle( titlePerfo ); - + for( globalIndex iperf = 0; iperf < m_numPerforations; ++iperf ) { tablePerforation.addRow< 3 >( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); From 37dc5dd007781e546c3a3f3c3a903a24a50f3595 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 14 Feb 2024 16:08:48 +0100 Subject: [PATCH 008/216] first review with correction --- .../codingUtilities/StringUtilities.hpp | 9 ++-- src/coreComponents/codingUtilities/Table.cpp | 45 +++++++++---------- src/coreComponents/codingUtilities/Table.hpp | 38 ++++++++-------- .../codingUtilities/tests/testTable.cpp | 15 ++++++- .../mesh/generators/WellGeneratorBase.cpp | 10 ++--- 5 files changed, 65 insertions(+), 52 deletions(-) diff --git a/src/coreComponents/codingUtilities/StringUtilities.hpp b/src/coreComponents/codingUtilities/StringUtilities.hpp index f0ac1c49dfb..2a6b2370f11 100644 --- a/src/coreComponents/codingUtilities/StringUtilities.hpp +++ b/src/coreComponents/codingUtilities/StringUtilities.hpp @@ -255,10 +255,13 @@ constexpr bool endsWith( std::string_view str, std::string_view suffix ) str.compare( str.size()-suffix.size(), suffix.size(), suffix ) == 0; } -template -std::ostream& operator<<(std::ostream& os, std::optional const& t) +template< typename T > +std::ostream & operator<<( std::ostream & os, std::optional< T > const & t ) { - if (t) os << t.value(); + if( t ) + { + os << t.value(); + } return os; } diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp index dc291bf54c4..3a1c5354fab 100644 --- a/src/coreComponents/codingUtilities/Table.cpp +++ b/src/coreComponents/codingUtilities/Table.cpp @@ -21,18 +21,18 @@ namespace geos { -std::string const cellAlignment( Table::Alignment const & a, std::string const & value, int spaces ) +string const cellAlignment( Table::Alignment const & a, string_view value, int spaces ) { switch( a ) { case Table::right: return GEOS_FMT( "{:>{}}", value, spaces ); - case Table::left: return GEOS_FMT( "{:<{}}", value, spaces ); - case Table::middle: return GEOS_FMT( "{:^{}}", value, spaces ); - default: return GEOS_FMT( "{:<{}}", value, spaces ); + case Table::left: return GEOS_FMT( "{:<{}}", value, spaces ); + case Table::middle: return GEOS_FMT( "{:^{}}", value, spaces ); + default: return GEOS_FMT( "{:<{}}", value, spaces ); } } -std::string Table::getStringSection( Section section ) const +string Table::getStringSection( Section section ) const { switch( section ) { @@ -42,7 +42,7 @@ std::string Table::getStringSection( Section section ) const } } -Table::Table( std::vector< std::string > const & headers ): +Table::Table( std::vector< string > const & headers ): borderMargin( getMargin( MarginType::border )), columnMargin( getMargin( MarginType::column )), maxRowHeader( 0 ) @@ -83,16 +83,16 @@ void Table::splitHeadersStringAndStore() { for( size_t columnParamIdx = 0; columnParamIdx< m_columns.size(); columnParamIdx++ ) { - std::vector< std::string > splitHeaderParts; - std::stringstream ss( m_columns[columnParamIdx].parameter.headerName[0] ); - std::string subHeaderName; + std::vector< string > splitHeaderParts; + std::istringstream ss( m_columns[columnParamIdx].parameter.headerName[0] ); + string subHeaderName; while( getline( ss, subHeaderName, '\n' )) { splitHeaderParts.push_back( subHeaderName ); } - size_t cellSize = splitHeaderParts.size(); + const size_t cellSize = splitHeaderParts.size(); maxRowHeader = std::max( maxRowHeader, cellSize ); m_splitHeader.push_back( splitHeaderParts ); @@ -105,24 +105,24 @@ void Table::addSpaceToSplitHeaderAndStore() { if( m_splitHeader[columnParamIdx].size() < maxRowHeader ) { - integer whiteRowToAdd = maxRowHeader - m_splitHeader[columnParamIdx].size(); + const integer whiteRowToAdd = maxRowHeader - m_splitHeader[columnParamIdx].size(); m_splitHeader[columnParamIdx].insert( m_splitHeader[columnParamIdx].end(), whiteRowToAdd, " " ); } m_columns[columnParamIdx].parameter.headerName = m_splitHeader[columnParamIdx]; } } -void Table::setTitle( std::string const & title_ ) +void Table::setTitle( string_view title_ ) { title = title_; } -std::string const & Table::getTitle() +string_view Table::getTitle() { return title; } -void Table::setMargin( MarginValue const & valueType ) +void Table::setMargin( MarginValue valueType ) { switch( valueType ) { @@ -147,7 +147,7 @@ void Table::setMargin( MarginValue const & valueType ) void Table::findMaxStringSize() { - std::string maxStringSize = ""; + string maxStringSize = ""; for( size_t idxColumn = 0; idxColumn < m_columns.size(); idxColumn++ ) { auto it = std::max_element( m_columns[idxColumn].parameter.headerName.begin(), @@ -160,7 +160,7 @@ void Table::findMaxStringSize() for( size_t idxRow = 0; idxRow < m_cellsRows.size(); idxRow++ ) { - std::string cell = m_columns[idxColumn].columnValues[idxRow]; + string cell = m_columns[idxColumn].columnValues[idxRow]; if( maxStringSize.length() < cell.length()) { maxStringSize = cell; @@ -170,8 +170,8 @@ void Table::findMaxStringSize() } } -void Table::computeAndSetMaxStringSize( string::size_type const & sectionlineLength, - string::size_type const & titleLineLength ) +void Table::computeAndSetMaxStringSize( string::size_type sectionlineLength, + string::size_type titleLineLength ) { integer extraLinesPerColumn; integer extraLines; @@ -270,7 +270,7 @@ void Table::buildSectionRows( integer const & nbRows, Section const & sectionNam rows += GEOS_FMT( "{:<{}}", "|", 1 + borderMargin.marginValue ); for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) { - std::string cell; + string cell; if( getStringSection( sectionName ) == "header" ) { @@ -318,10 +318,9 @@ void Table::fillColumnsValuesFromCellsRows() } } -void Table::draw( std::ostringstream & oss ) +void Table::draw( std::ostream & oss ) { - oss.clear(); - std::string tableOutput; + string tableOutput; fillColumnsValuesFromCellsRows(); @@ -342,8 +341,6 @@ void Table::draw( std::ostringstream & oss ) tableOutput = titleRow + rows; - std::cout << tableOutput; - oss << tableOutput; } diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index 7323f3bf027..87afa2a255c 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -66,7 +66,7 @@ class Table */ struct ColumnParam { - std::vector< std::string > headerName; + std::vector< string > headerName; Alignment alignment = Alignment::right; bool enabled = true; }; @@ -76,7 +76,7 @@ class Table * * @param columnNames */ - Table( std::vector< std::string > const & columnNames ); + Table( std::vector< string > const & columnNames ); /** * @brief Construct a new Table object by specifying alignment of values in the table and optionally their display according to their log @@ -101,27 +101,27 @@ class Table * * @param os */ - void draw( std::ostringstream & os ); + void draw( std::ostream & os = std::cout ); /** * @brief Set the name of the table * @param [in] title The name of the table */ - void setTitle( const std::string & title ); + void setTitle( string_view title ); /** * @brief Set the Margin object * * @param valueType */ - void setMargin( MarginValue const & valueType ); + void setMargin( MarginValue valueType ); /** * @brief Get the table title * * @return return the table name */ - std::string const & getTitle(); + string_view getTitle(); private: @@ -136,8 +136,8 @@ class Table struct Column { ColumnParam parameter; - std::vector< std::string > columnValues; - std::string m_maxStringSize; + std::vector< string > columnValues; + string m_maxStringSize; }; /** @@ -154,7 +154,7 @@ class Table * @param section * @return The name of the section */ - std::string getStringSection( Section section ) const; + string getStringSection( Section section ) const; /** * @brief the vector column \p m_column with all values previously stored in the constructor @@ -185,8 +185,8 @@ class Table * by adding an extra number of characters * */ - void computeAndSetMaxStringSize( string::size_type const & sectionlineLength, - string::size_type const & titleLineLength ); + void computeAndSetMaxStringSize( string::size_type const sectionlineLength, + string::size_type const titleLineLength ); /** * @brief Compute the lines separator * @@ -207,22 +207,22 @@ class Table */ void buildSectionRows( integer const & nbRows, Section const & sectionName ); - std::vector< std::vector< std::string > > m_splitHeader; + std::vector< std::vector< string > > m_splitHeader; std::vector< std::vector< string > > m_cellsRows; std::vector< Column > m_columns; Margin borderMargin; Margin columnMargin; - std::string title; - std::string topSeparator; - std::string sectionSeparator; + string title; + string topSeparator; + string sectionSeparator; size_t maxRowHeader; int marginTitle = 2; - std::string titleRow; - std::string rows; + string titleRow; + string rows; }; @@ -233,10 +233,10 @@ void Table::addRow( const Args &... args ) static_assert( nbColumn_ == N, "The number of cells per line does not correspond to the number of parameters" ); - std::vector< std::string > rowsValues; + std::vector< string > rowsValues; int idx = 0; ( [&] { - std::string cellValue = GEOS_FMT( "{}", args ); + string cellValue = GEOS_FMT( "{}", args ); if( m_columns[idx].parameter.enabled ) { rowsValues.push_back( cellValue ); diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 5a96f9f925b..56ab0baa52b 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -24,7 +24,7 @@ using namespace geos; TEST( testTable, tableClass ) { - std::vector< std::string > tableTestsOutput; + std::vector< string > tableTestsOutput; std::ostringstream oss; @@ -41,6 +41,7 @@ TEST( testTable, tableClass ) 787442, 10 ); tableTest.draw( oss ); tableTestsOutput.push_back( oss.str() ); + oss.clear(); oss.str( "" ); EXPECT_EQ( tableTestsOutput[0], "\n+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n" @@ -69,6 +70,7 @@ TEST( testTable, tableClass ) tableTest2.addRow< 5 >( "value23", "[30.21543]", "30.45465142", 787442, 10 ); tableTest2.draw( oss ); tableTestsOutput.push_back( oss.str() ); + oss.clear(); oss.str( "" ); EXPECT_EQ( tableTestsOutput[1], "\n+---------------------------------------------------------------------------------------------------------------------------------------------------------+\n" @@ -91,6 +93,7 @@ TEST( testTable, tableClass ) tableTest3.setTitle( "InternalWellGenerator well_injector1" ); tableTest3.draw( oss ); tableTestsOutput.push_back( oss.str() ); + oss.clear(); oss.str( "" ); EXPECT_EQ ( tableTestsOutput[2], "\n+-----------------------------------------------------------------------------------------------------------------------------+\n" @@ -117,6 +120,7 @@ TEST( testTable, tableClass ) tableTest4.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest4.draw( oss ); tableTestsOutput.push_back( oss.str() ); + oss.clear(); oss.str( "" ); EXPECT_EQ( tableTestsOutput[3], "\n+-----------------------------------------------------------------------------------------+\n" @@ -144,6 +148,7 @@ TEST( testTable, tableClass ) tableTest5.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest5.draw( oss ); tableTestsOutput.push_back( oss.str() ); + oss.clear(); oss.str( "" ); EXPECT_EQ( tableTestsOutput[4], "\n+-----------------------------------------------------------------+\n" @@ -169,6 +174,7 @@ TEST( testTable, tableClass ) tableTest6.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest6.draw( oss ); tableTestsOutput.push_back( oss.str() ); + oss.clear(); oss.str( "" ); EXPECT_EQ( tableTestsOutput[5], "\n+-----------------------------------------------------------------------------------------+\n" @@ -195,6 +201,7 @@ TEST( testTable, tableClass ) tableTest7.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest7.draw( oss ); tableTestsOutput.push_back( oss.str() ); + oss.clear(); oss.str( "" ); EXPECT_EQ( tableTestsOutput[6], "\n+------------------------------------------------------------------------------------------------------------------+\n" @@ -220,6 +227,7 @@ TEST( testTable, tableClass ) tableTest8.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest8.draw( oss ); tableTestsOutput.push_back( oss.str() ); + oss.clear(); oss.str( "" ); EXPECT_EQ( tableTestsOutput[7], "\n+----------------------------------------------------------------------------------------------------------------+\n" @@ -242,6 +250,7 @@ TEST( testTable, tableClass ) tableTest9.addRow< 1 >( "val1" ); tableTest9.draw( oss ); tableTestsOutput.push_back( oss.str() ); + oss.clear(); oss.str( "" ); EXPECT_EQ( tableTestsOutput[8], "\n+-------------------------------------------------------------------------------------------------------------------+\n" @@ -262,6 +271,7 @@ TEST( testTable, tableClass ) tableTest10.addRow< 1 >( "val1" ); tableTest10.draw( oss ); tableTestsOutput.push_back( oss.str() ); + oss.clear(); oss.str( "" ); EXPECT_EQ( tableTestsOutput[9], "\n+--------------------------------------------------------------------------------------------------------------+\n" @@ -280,6 +290,7 @@ TEST( testTable, tableClass ) tableTest11.setTitle( "title1" ); tableTest11.draw( oss ); tableTestsOutput.push_back( oss.str() ); + oss.clear(); oss.str( "" ); EXPECT_EQ( tableTestsOutput[10], "\n+------------------+\n" @@ -301,6 +312,7 @@ TEST( testTable, tableClass ) tableTest12.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest12.draw( oss ); tableTestsOutput.push_back( oss.str() ); + oss.clear(); oss.str( "" ); EXPECT_EQ( tableTestsOutput[11], "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" @@ -326,6 +338,7 @@ TEST( testTable, tableClass ) tableTest13.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest13.draw( oss ); tableTestsOutput.push_back( oss.str() ); + oss.clear(); oss.str( "" ); EXPECT_EQ( tableTestsOutput[12], "\n+-----------------------------------------------------------------+\n" diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 30e351594f7..ac18a54da52 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -529,7 +529,7 @@ void WellGeneratorBase::debugWellGeometry() const return; } - std::vector< std::string > row; + std::vector< string > row; std::ostringstream oss; Table table = Table( { Table::ColumnParam{{"Element no."}, Table::Alignment::right}, @@ -541,7 +541,7 @@ void WellGeneratorBase::debugWellGeometry() const } ); - std::string titleName = "InternalWellGenerator " + getName(); + string titleName = "InternalWellGenerator " + getName(); table.setTitle( titleName ); for( globalIndex iwelem = 0; iwelem < m_numElems; ++iwelem ) @@ -573,10 +573,10 @@ void WellGeneratorBase::debugWellGeometry() const table.addRow< 6 >( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, nextElement ); } - table.draw( oss ); + table.draw(); Table tablePerforation = Table( {"Perforation no.", "Coordinates\nlong string", "connected toO" } ); - std::string titlePerfo = "Peforation table "; + string titlePerfo = "Peforation table "; tablePerforation.setTitle( titlePerfo ); for( globalIndex iperf = 0; iperf < m_numPerforations; ++iperf ) @@ -584,7 +584,7 @@ void WellGeneratorBase::debugWellGeometry() const tablePerforation.addRow< 3 >( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); } - tablePerforation.draw( oss ); + tablePerforation.draw(); std::cout << std::endl; } From 8678fc00df17823e630cf4c7b9f812f0c8c9bf73 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 15 Feb 2024 13:50:28 +0100 Subject: [PATCH 009/216] constness modification, doc/test updated --- src/coreComponents/codingUtilities/Table.cpp | 8 ++-- src/coreComponents/codingUtilities/Table.hpp | 48 +++++++------------ .../codingUtilities/tests/testTable.cpp | 26 +++++----- .../mesh/generators/WellGeneratorBase.cpp | 1 - 4 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp index 3a1c5354fab..bcfe926ac92 100644 --- a/src/coreComponents/codingUtilities/Table.cpp +++ b/src/coreComponents/codingUtilities/Table.cpp @@ -92,7 +92,7 @@ void Table::splitHeadersStringAndStore() splitHeaderParts.push_back( subHeaderName ); } - const size_t cellSize = splitHeaderParts.size(); + size_t const cellSize = splitHeaderParts.size(); maxRowHeader = std::max( maxRowHeader, cellSize ); m_splitHeader.push_back( splitHeaderParts ); @@ -307,7 +307,7 @@ void Table::buildSectionRows( integer const & nbRows, Section const & sectionNam } } -void Table::fillColumnsValuesFromCellsRows() +void Table::fillColumnsValuesFromMCellsRows() { for( size_t idxRow = 0; idxRow < m_cellsRows.size(); idxRow++ ) { @@ -322,7 +322,7 @@ void Table::draw( std::ostream & oss ) { string tableOutput; - fillColumnsValuesFromCellsRows(); + fillColumnsValuesFromMCellsRows(); splitHeadersStringAndStore(); addSpaceToSplitHeaderAndStore(); @@ -339,7 +339,7 @@ void Table::draw( std::ostream & oss ) buildSectionRows( maxRowHeader, Section::header ); buildSectionRows( m_cellsRows.size(), Section::values ); - tableOutput = titleRow + rows; + tableOutput = titleRow + rows + '\n'; oss << tableOutput; } diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index 87afa2a255c..b855e22d37d 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -30,9 +30,9 @@ class Table enum Alignment { right, left, middle }; - enum MarginType {border, column}; + enum MarginType { border, column }; - enum MarginValue { tiny, small, medium, large}; + enum MarginValue { tiny, small, medium, large }; /** * @brief Struct for a column margin and border margin. @@ -60,20 +60,19 @@ class Table /** * @brief Struct for a ColumnParam. - * @param headerName A vector containing all string for a header name - * @param columnValues Alignment for a column. By default aligned to the right side - * @param enabled A boolean to display a colummn */ struct ColumnParam { + // A vector containing all string for a header name std::vector< string > headerName; + // Alignment for a column. By default aligned to the right side Alignment alignment = Alignment::right; + // A boolean to display a colummn bool enabled = true; }; /** * @brief Construct a new Table object, all values in the table are centered by default - * * @param columnNames */ Table( std::vector< string > const & columnNames ); @@ -81,14 +80,12 @@ class Table /** * @brief Construct a new Table object by specifying alignment of values in the table and optionally their display according to their log * level - * * @param columnParameter */ Table( std::vector< ColumnParam > const & columnParameter ); /** * @brief Add a row the the table. The number of arguments need to match with the number of header values - * * @tparam N * @tparam Args * @param args @@ -97,8 +94,7 @@ class Table void addRow( const Args &... args ); /** - * @brief Display the table - * + * @brief Write the the table into specified stream * @param os */ void draw( std::ostream & os = std::cout ); @@ -110,15 +106,12 @@ class Table void setTitle( string_view title ); /** - * @brief Set the Margin object - * + * @brief Sets the minimal margin width between the row content an its borders. * @param valueType */ void setMargin( MarginValue valueType ); /** - * @brief Get the table title - * * @return return the table name */ string_view getTitle(); @@ -129,20 +122,18 @@ class Table /** * @brief Struct for a column. - * @param [in] parameter Column parameter - * @param [in] columnValues All column values - * @param [in] m_maxStringSize The largest string in the column */ struct Column { ColumnParam parameter; + // A vector containing all column values std::vector< string > columnValues; + // The largest string in the column string m_maxStringSize; }; /** * @brief Get the Margin object - * * @param type * @return Margin */ @@ -150,46 +141,39 @@ class Table /** * @brief Get the name of the section given an enum - * * @param section * @return The name of the section */ string getStringSection( Section section ) const; /** - * @brief the vector column \p m_column with all values previously stored in the constructor - * + * @brief fill the vector \p m_column with values from m_cellsRows who store all value in an unsorted order */ - void fillColumnsValuesFromCellsRows(); + void fillColumnsValuesFromMCellsRows(); /** * @brief Split all header names by detecting \p '\n' character and store each split header name into a vector. - * */ void splitHeadersStringAndStore(); /** - * @brief Iterate throught all header name vector and set them to the same size by adding an empty string. - * + * @brief Iterate throught all header name vector and set them to the same size by adding empty string(s). */ void addSpaceToSplitHeaderAndStore(); /** * @brief For each column find the largest string size - * */ void findMaxStringSize(); /** - * @brief If the title is the largest string size in the table, recalculate for all column the \p m_maxStringSize value + * @brief If the title is the largest string size in the table, recalculate for all column, the \p m_maxStringSize value * by adding an extra number of characters - * */ - void computeAndSetMaxStringSize( string::size_type const sectionlineLength, - string::size_type const titleLineLength ); + void computeAndSetMaxStringSize( string::size_type sectionlineLength, + string::size_type titleLineLength ); /** * @brief Compute the lines separator - * */ void computeAndBuildLines(); @@ -201,7 +185,6 @@ class Table /** * @brief build the header or values section - * * @param nbRows * @param sectionName */ @@ -209,6 +192,7 @@ class Table std::vector< std::vector< string > > m_splitHeader; std::vector< std::vector< string > > m_cellsRows; + std::vector< Column > m_columns; Margin borderMargin; diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 56ab0baa52b..3b9930a5caa 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -55,7 +55,7 @@ TEST( testTable, tableClass ) "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" "| | | | | |\n" "| Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | [30.21543] | 30.45465142 | 787442 | 10 |\n" - "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" ); Table tableTest2( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", @@ -82,7 +82,7 @@ TEST( testTable, tableClass ) "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" "| | | | | |\n" "| value23 | [30.21543] | 30.45465142 | 787442 | 10 |\n" - "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" ); Table tableTest3 ( @@ -104,7 +104,7 @@ TEST( testTable, tableClass ) "| nascetur ridiculus mus. Duis fringilla, ligula sed porta fringilla, ligula wisicommodo felis, | | | |\n" "| ut adi | | | |\n" "| piscing felis dui in enim. Suspendisse malesuada ultrices ante | | | |\n" - "+-------------------------------------------------------------------------------------------------+----------+-----+----------+\n" + "+-------------------------------------------------------------------------------------------------+----------+-----+----------+\n\n" ); Table tableTest4( { @@ -131,7 +131,7 @@ TEST( testTable, tableClass ) "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" ); Table tableTest5( { @@ -158,7 +158,7 @@ TEST( testTable, tableClass ) "+----------------+----------+-----------------------+-------------+\n" "| value1 | | 3.0 | 3.0129877 |\n" "| val1 | v | [3.045,42.02,89.25] | 3 |\n" - "+----------------+----------+-----------------------+-------------+\n" + "+----------------+----------+-----------------------+-------------+\n\n" ); Table tableTest6( { @@ -185,7 +185,7 @@ TEST( testTable, tableClass ) "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" ); Table tableTest7( { @@ -211,7 +211,7 @@ TEST( testTable, tableClass ) "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" "| value1 | | 3.0 | 3.0129877 |\n" "| val1 | v | [3.045,42.02,89.25] | 3 |\n" - "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" + "+---------------------------+---------------------+----------------------------------+-----------------------------+\n\n" ); Table tableTest8( { @@ -238,7 +238,7 @@ TEST( testTable, tableClass ) "+-------------------+-------------+--------------------------+----------------+--------------+-------------------+\n" "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+-------------------+-------------+--------------------------+----------------+--------------+-------------------+\n" + "+-------------------+-------------+--------------------------+----------------+--------------+-------------------+\n\n" ); Table tableTest9( { @@ -260,7 +260,7 @@ TEST( testTable, tableClass ) "+-------------------------------------------------------------------------------------------------------------------+\n" "| value1 |\n" "| val1 |\n" - "+-------------------------------------------------------------------------------------------------------------------+\n" + "+-------------------------------------------------------------------------------------------------------------------+\n\n" ); Table tableTest10( { @@ -281,7 +281,7 @@ TEST( testTable, tableClass ) "+--------------------------------------------------------------------------------------------------------------+\n" "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" "| val1 |\n" - "+--------------------------------------------------------------------------------------------------------------+\n" + "+--------------------------------------------------------------------------------------------------------------+\n\n" ); Table tableTest11( { @@ -297,7 +297,7 @@ TEST( testTable, tableClass ) "| title1 |\n" "+------------------+\n" "| Cras egestas |\n" - "+------------------+\n" + "+------------------+\n\n" ); Table tableTest12( { @@ -321,7 +321,7 @@ TEST( testTable, tableClass ) "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" ); Table tableTest13( { @@ -349,7 +349,7 @@ TEST( testTable, tableClass ) "+------------+------+-------------------+---------+-------+-------+\n" "| value1 | | 3.0 |3.0129877|2 | 1 |\n" "| val1 | v|[3.045,42.02,89.25]|3 |10 | 3 |\n" - "+------------+------+-------------------+---------+-------+-------+\n" + "+------------+------+-------------------+---------+-------+-------+\n\n" ); } diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index ac18a54da52..1c609a19cc0 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -586,7 +586,6 @@ void WellGeneratorBase::debugWellGeometry() const tablePerforation.draw(); - std::cout << std::endl; } } From 9475286992ab2783924175fa4009792cf55d5249 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 15 Feb 2024 15:26:44 +0100 Subject: [PATCH 010/216] const declaration updated --- src/coreComponents/codingUtilities/Table.cpp | 6 +++--- src/coreComponents/codingUtilities/Table.hpp | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp index bcfe926ac92..4f0e54ec080 100644 --- a/src/coreComponents/codingUtilities/Table.cpp +++ b/src/coreComponents/codingUtilities/Table.cpp @@ -21,7 +21,7 @@ namespace geos { -string const cellAlignment( Table::Alignment const & a, string_view value, int spaces ) +string cellAlignment( Table::Alignment const a, string_view value, integer spaces ) { switch( a ) { @@ -67,7 +67,7 @@ Table::Table( std::vector< ColumnParam > const & columnParameter ): maxRowHeader = 0; } -Table::Margin Table::getMargin( MarginType const & type ) +Table::Margin Table::getMargin( MarginType type ) const { Margin marginBorder {0, 1, 2, 3, 2}; Margin marginColumn {0, 3, 5, 7, 5}; @@ -262,7 +262,7 @@ void Table::buildTitleRow() titleRow += GEOS_FMT( "{}\n", "|" ); } -void Table::buildSectionRows( integer const & nbRows, Section const & sectionName ) +void Table::buildSectionRows( integer const nbRows, Section const sectionName ) { for( integer idxRow = 0; idxRow< nbRows; idxRow++ ) diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index b855e22d37d..69e980d2f08 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -52,7 +52,7 @@ class Table integer marginValue; - void setWorkingValue( integer const & value ) + void setWorkingValue( integer const value ) { marginValue = value; } @@ -91,7 +91,7 @@ class Table * @param args */ template< size_t N, typename ... Args > - void addRow( const Args &... args ); + void addRow( Args const &... args ); /** * @brief Write the the table into specified stream @@ -137,13 +137,13 @@ class Table * @param type * @return Margin */ - Margin getMargin( MarginType const & type ); + Margin getMargin( MarginType type ) const; /** * @brief Get the name of the section given an enum * @param section * @return The name of the section - */ + */0 string getStringSection( Section section ) const; /** @@ -157,7 +157,7 @@ class Table void splitHeadersStringAndStore(); /** - * @brief Iterate throught all header name vector and set them to the same size by adding empty string(s). + * @brief Iterate throught all header names vector and set them to the same size by adding empty string(s). */ void addSpaceToSplitHeaderAndStore(); @@ -188,7 +188,7 @@ class Table * @param nbRows * @param sectionName */ - void buildSectionRows( integer const & nbRows, Section const & sectionName ); + void buildSectionRows( integer nbRows, Section sectionName ); std::vector< std::vector< string > > m_splitHeader; std::vector< std::vector< string > > m_cellsRows; @@ -211,11 +211,11 @@ class Table }; template< size_t N, typename ... Args > -void Table::addRow( const Args &... args ) +void Table::addRow( Args const &... args ) { constexpr std::size_t nbColumn_ = sizeof...(args); static_assert( nbColumn_ == N, - "The number of cells per line does not correspond to the number of parameters" ); + "The number of cells per line does not correspond to the number of parameters." ); std::vector< string > rowsValues; int idx = 0; From 13206512ed6d3f4c65a24ac2383e04158860435c Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 19 Feb 2024 11:00:29 +0100 Subject: [PATCH 011/216] doc + minor restructuring --- src/coreComponents/codingUtilities/Table.cpp | 107 +++++++++++-------- src/coreComponents/codingUtilities/Table.hpp | 97 +++++++++-------- 2 files changed, 114 insertions(+), 90 deletions(-) diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp index 4f0e54ec080..af17c778c20 100644 --- a/src/coreComponents/codingUtilities/Table.cpp +++ b/src/coreComponents/codingUtilities/Table.cpp @@ -21,9 +21,17 @@ namespace geos { -string cellAlignment( Table::Alignment const a, string_view value, integer spaces ) +/** + * @brief Build a value cell given an alignment and spaces from "|" + * + * @param alignment + * @param value + * @param spaces + * @return A cell value + */ +string buildValueCell( Table::Alignment const alignment, string_view value, integer spaces ) { - switch( a ) + switch( alignment ) { case Table::right: return GEOS_FMT( "{:>{}}", value, spaces ); case Table::left: return GEOS_FMT( "{:<{}}", value, spaces ); @@ -44,8 +52,7 @@ string Table::getStringSection( Section section ) const Table::Table( std::vector< string > const & headers ): borderMargin( getMargin( MarginType::border )), - columnMargin( getMargin( MarginType::column )), - maxRowHeader( 0 ) + columnMargin( getMargin( MarginType::column )) { for( size_t idx = 0; idx< headers.size(); idx++ ) { @@ -64,7 +71,6 @@ Table::Table( std::vector< ColumnParam > const & columnParameter ): m_columns.push_back( {columnParameter[idx], {}, ""} ); } } - maxRowHeader = 0; } Table::Margin Table::getMargin( MarginType type ) const @@ -79,7 +85,8 @@ Table::Margin Table::getMargin( MarginType type ) const } -void Table::splitHeadersStringAndStore() +void Table::parseAndStoreHeaderSections( size_t & largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeader ) { for( size_t columnParamIdx = 0; columnParamIdx< m_columns.size(); columnParamIdx++ ) { @@ -93,33 +100,34 @@ void Table::splitHeadersStringAndStore() } size_t const cellSize = splitHeaderParts.size(); - maxRowHeader = std::max( maxRowHeader, cellSize ); + largestHeaderVectorSize = std::max( largestHeaderVectorSize, cellSize ); - m_splitHeader.push_back( splitHeaderParts ); + splitHeader.push_back( splitHeaderParts ); } } -void Table::addSpaceToSplitHeaderAndStore() +void Table::adjustHeaderSizesAndStore( size_t largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeader ) { for( size_t columnParamIdx = 0; columnParamIdx < m_columns.size(); columnParamIdx++ ) { - if( m_splitHeader[columnParamIdx].size() < maxRowHeader ) + if( splitHeader[columnParamIdx].size() < largestHeaderVectorSize ) { - const integer whiteRowToAdd = maxRowHeader - m_splitHeader[columnParamIdx].size(); - m_splitHeader[columnParamIdx].insert( m_splitHeader[columnParamIdx].end(), whiteRowToAdd, " " ); + const integer whiteRowToAdd = largestHeaderVectorSize - splitHeader[columnParamIdx].size(); + splitHeader[columnParamIdx].insert( splitHeader[columnParamIdx].end(), whiteRowToAdd, " " ); } - m_columns[columnParamIdx].parameter.headerName = m_splitHeader[columnParamIdx]; + m_columns[columnParamIdx].parameter.headerName = splitHeader[columnParamIdx]; } } void Table::setTitle( string_view title_ ) { - title = title_; + tableTitle = title_; } string_view Table::getTitle() { - return title; + return tableTitle; } void Table::setMargin( MarginValue valueType ) @@ -145,7 +153,7 @@ void Table::setMargin( MarginValue valueType ) } } -void Table::findMaxStringSize() +void Table::findAndSetMaxStringSize() { string maxStringSize = ""; for( size_t idxColumn = 0; idxColumn < m_columns.size(); idxColumn++ ) @@ -198,15 +206,14 @@ void Table::computeAndSetMaxStringSize( string::size_type sectionlineLength, } } -void Table::computeAndBuildLines() +void Table::computeAndBuildSeparator( string & topSeparator, string & sectionSeparator ) { string::size_type sectionlineLength = 0; - string::size_type titleLineLength = title.length() + ( marginTitle * 2 ); + string::size_type titleLineLength = tableTitle.length() + ( marginTitle * 2 ); integer nbSpaceBetweenColumn = ( ( m_columns.size() - 1 ) * columnMargin.marginValue ) + (borderMargin.marginValue * 2); - - if( !title.empty()) + if( !tableTitle.empty()) { - title = GEOS_FMT( "{:^{}}", title, titleLineLength ); + tableTitle = GEOS_FMT( "{:^{}}", tableTitle, titleLineLength ); } for( std::size_t i = 0; i < m_columns.size(); ++i ) @@ -215,12 +222,10 @@ void Table::computeAndBuildLines() } sectionlineLength += nbSpaceBetweenColumn; - if( sectionlineLength < titleLineLength ) { computeAndSetMaxStringSize( sectionlineLength, titleLineLength ); } - if( m_columns.size() == 1 ) { sectionSeparator += GEOS_FMT( "+{:-<{}}+", @@ -232,7 +237,6 @@ void Table::computeAndBuildLines() for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) { integer cellSize = m_columns[idxColumn].m_maxStringSize.length(); - if( idxColumn == 0 ) { sectionSeparator += GEOS_FMT( "+{:-<{}}", "", ( cellSize + borderMargin.marginValue )); @@ -252,19 +256,21 @@ void Table::computeAndBuildLines() topSeparator = GEOS_FMT( "+{:-<{}}+", "", sectionSeparator.size() - 2 );// -2 for ++ } -void Table::buildTitleRow() +void Table::buildTitleRow( string & titleRows, string topSeparator, string sectionSeparator ) { - titleRow = GEOS_FMT( "\n{}\n|", topSeparator ); - titleRow += cellAlignment( Alignment::middle, - title, - (sectionSeparator.length() - 2) // -2 for || - ); - titleRow += GEOS_FMT( "{}\n", "|" ); + titleRows = GEOS_FMT( "\n{}\n|", topSeparator ); + titleRows += buildValueCell( Alignment::middle, + tableTitle, + (sectionSeparator.length() - 2) // -2 for || + ); + titleRows += GEOS_FMT( "{}\n", "|" ); } -void Table::buildSectionRows( integer const nbRows, Section const sectionName ) +void Table::buildSectionRows( string sectionSeparator, + string & rows, + integer const nbRows, + Section const sectionName ) { - for( integer idxRow = 0; idxRow< nbRows; idxRow++ ) { rows += GEOS_FMT( "{:<{}}", "|", 1 + borderMargin.marginValue ); @@ -281,9 +287,9 @@ void Table::buildSectionRows( integer const nbRows, Section const sectionName ) cell = m_columns[idxColumn].columnValues[idxRow]; } integer cellSize = m_columns[idxColumn].m_maxStringSize.length(); - rows += cellAlignment( m_columns[idxColumn].parameter.alignment, - cell, - cellSize ); + rows += buildValueCell( m_columns[idxColumn].parameter.alignment, + cell, + cellSize ); if( idxColumn < m_columns.size() - 1 ) { @@ -307,7 +313,7 @@ void Table::buildSectionRows( integer const nbRows, Section const sectionName ) } } -void Table::fillColumnsValuesFromMCellsRows() +void Table::fillColumnsValuesFromCellsRows() { for( size_t idxRow = 0; idxRow < m_cellsRows.size(); idxRow++ ) { @@ -321,25 +327,32 @@ void Table::fillColumnsValuesFromMCellsRows() void Table::draw( std::ostream & oss ) { string tableOutput; + string rows; + string titleRows; + string topSeparator; + string sectionSeparator; + + std::vector< std::vector< string > > splitHeader; + size_t largestHeaderVectorSize = 0; - fillColumnsValuesFromMCellsRows(); - splitHeadersStringAndStore(); - addSpaceToSplitHeaderAndStore(); + fillColumnsValuesFromCellsRows(); + parseAndStoreHeaderSections( largestHeaderVectorSize, splitHeader ); + adjustHeaderSizesAndStore( largestHeaderVectorSize, splitHeader ); - findMaxStringSize(); - computeAndBuildLines(); + findAndSetMaxStringSize(); + computeAndBuildSeparator( topSeparator, sectionSeparator ); - if( !title.empty()) + if( !tableTitle.empty()) { - buildTitleRow(); + buildTitleRow( titleRows, topSeparator, sectionSeparator ); } rows += GEOS_FMT( "{}\n", sectionSeparator ); - buildSectionRows( maxRowHeader, Section::header ); - buildSectionRows( m_cellsRows.size(), Section::values ); + buildSectionRows( sectionSeparator, rows, largestHeaderVectorSize, Section::header ); + buildSectionRows( sectionSeparator, rows, m_cellsRows.size(), Section::values ); - tableOutput = titleRow + rows + '\n'; + tableOutput = titleRows + rows + '\n'; oss << tableOutput; } diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index 69e980d2f08..0b4088da97e 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -35,21 +35,19 @@ class Table enum MarginValue { tiny, small, medium, large }; /** - * @brief Struct for a column margin and border margin. - * @param tiny 0 margin for both; - * @param small 1 margin from | - * @param medium 2 margin from | - * @param large 3 margin from | - * - * @param marginValue current margin value + * @brief Struct for a column margin and a border margin. */ struct Margin { + // 0 margin from | integer tiny; + // 1 margin from | integer small; + // 2 margin from | integer medium; + // 3 margin from | integer large; - + // current margin value integer marginValue; void setWorkingValue( integer const value ) @@ -78,14 +76,14 @@ class Table Table( std::vector< string > const & columnNames ); /** - * @brief Construct a new Table object by specifying alignment of values in the table and optionally their display according to their log + * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels * level * @param columnParameter */ Table( std::vector< ColumnParam > const & columnParameter ); /** - * @brief Add a row the the table. The number of arguments need to match with the number of header values + * @brief Add a row the the table. The number of arguments must match with the number of header values * @tparam N * @tparam Args * @param args @@ -101,12 +99,12 @@ class Table /** * @brief Set the name of the table - * @param [in] title The name of the table + * @param tableTitle The name of the table */ - void setTitle( string_view title ); + void setTitle( string_view tableTitle ); /** - * @brief Sets the minimal margin width between the row content an its borders. + * @brief Sets the minimal margin width between row content and borders. * @param valueType */ void setMargin( MarginValue valueType ); @@ -133,7 +131,7 @@ class Table }; /** - * @brief Get the Margin object + * @brief Get the margin type either a borderMagin or a column * @param type * @return Margin */ @@ -143,71 +141,84 @@ class Table * @brief Get the name of the section given an enum * @param section * @return The name of the section - */0 + */ string getStringSection( Section section ) const; /** - * @brief fill the vector \p m_column with values from m_cellsRows who store all value in an unsorted order + * @brief Fill the vector \p m_column with values from m_cellsRows who store all values in an unsorted order */ - void fillColumnsValuesFromMCellsRows(); + void fillColumnsValuesFromCellsRows( ); /** - * @brief Split all header names by detecting \p '\n' character and store each split header name into a vector. + * @brief Split all header names by detecting the newline \\n character. + * @param splitHeader A vector containing all split header names + * @param largestHeaderVectorSize The largest split header vector size */ - void splitHeadersStringAndStore(); + void parseAndStoreHeaderSections( size_t & largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeader ); /** - * @brief Iterate throught all header names vector and set them to the same size by adding empty string(s). + * @brief Iterate throught the header names vector + * Adjust the size of each header vector by adding empty strings if needed. + * Store the modified header names in the corresponding column parameter. + * @param largestHeaderVectorSize The largest split header vector size + * @param splitHeader A vector containing all split header names */ - void addSpaceToSplitHeaderAndStore(); + void adjustHeaderSizesAndStore( size_t largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeader ); /** - * @brief For each column find the largest string size + * @brief For each column find and set the column's longest string */ - void findMaxStringSize(); + void findAndSetMaxStringSize(); /** - * @brief If the title is the largest string size in the table, recalculate for all column, the \p m_maxStringSize value - * by adding an extra number of characters + * @brief Compute the largest string size in the table. If the table title is the largest string size in the table, recalculate for all + * columns the \p m_maxStringSize value by adding extra characters + * @param sectionlineLength The length of a section line + * @param titleLineLength The length of a title line */ void computeAndSetMaxStringSize( string::size_type sectionlineLength, string::size_type titleLineLength ); + /** - * @brief Compute the lines separator + * @brief Compute and build the top and the section line separator + * @param topSeparator + * @param sectionSeparator */ - void computeAndBuildLines(); + void computeAndBuildSeparator( string & topSeparator, string & sectionSeparator ); /** - * @brief Build the title section - * + * @brief Build the table title section + * @param titleRows Rows containing the title section + * @param topSeparator The top line separator + * @param sectionSeparator The section line separator */ - void buildTitleRow(); + void buildTitleRow( string & titleRows, string topSeparator, string sectionSeparator ); /** - * @brief build the header or values section - * @param nbRows - * @param sectionName + * @brief Build a section by specifying it's type ( header or section ) + * @param sectionSeparator Line separator between sections + * @param rows A section row + * @param nbRows Indicates the number of lines in a section + * @param sectionName The section to be built */ - void buildSectionRows( integer nbRows, Section sectionName ); + void buildSectionRows( string sectionSeparator, + string & rows, + integer const nbRows, + Section const sectionName ); - std::vector< std::vector< string > > m_splitHeader; - std::vector< std::vector< string > > m_cellsRows; + std::vector< std::vector< string > > m_cellsRows; std::vector< Column > m_columns; Margin borderMargin; Margin columnMargin; - string title; - string topSeparator; - string sectionSeparator; - size_t maxRowHeader; + string tableTitle; int marginTitle = 2; - string titleRow; - string rows; - }; template< size_t N, typename ... Args > From f78bd83d7861af942aa58ba5f1a9bf624a18070d Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 20 Feb 2024 11:08:07 +0100 Subject: [PATCH 012/216] doc + method for row from vector --- src/coreComponents/codingUtilities/Table.cpp | 19 ++++++++++- src/coreComponents/codingUtilities/Table.hpp | 14 +++++--- .../codingUtilities/tests/testTable.cpp | 32 +++++++++++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp index af17c778c20..d85accad7eb 100644 --- a/src/coreComponents/codingUtilities/Table.cpp +++ b/src/coreComponents/codingUtilities/Table.cpp @@ -73,6 +73,23 @@ Table::Table( std::vector< ColumnParam > const & columnParameter ): } } +void Table::addRowsFromVector( std::vector< std::vector< string > > vecRows ) +{ + for( size_t indexRow = 0; indexRow < vecRows.size(); indexRow++ ) + { + std::vector< string > rowsValues; + for( size_t indexValue = 0; indexValue < vecRows[indexRow].size(); indexValue++ ) + { + string cellValue = GEOS_FMT( "{}", vecRows[indexRow][indexValue] ); + if( m_columns[indexValue].parameter.enabled ) + { + rowsValues.push_back( cellValue ); + } + } + m_cellsRows.push_back( rowsValues ); + } +} + Table::Margin Table::getMargin( MarginType type ) const { Margin marginBorder {0, 1, 2, 3, 2}; @@ -113,7 +130,7 @@ void Table::adjustHeaderSizesAndStore( size_t largestHeaderVectorSize, { if( splitHeader[columnParamIdx].size() < largestHeaderVectorSize ) { - const integer whiteRowToAdd = largestHeaderVectorSize - splitHeader[columnParamIdx].size(); + integer const whiteRowToAdd = largestHeaderVectorSize - splitHeader[columnParamIdx].size(); splitHeader[columnParamIdx].insert( splitHeader[columnParamIdx].end(), whiteRowToAdd, " " ); } m_columns[columnParamIdx].parameter.headerName = splitHeader[columnParamIdx]; diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index 0b4088da97e..9eaddb52b83 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -57,7 +57,7 @@ class Table }; /** - * @brief Struct for a ColumnParam. + * @brief Structure to set up each colum parameters. */ struct ColumnParam { @@ -84,16 +84,22 @@ class Table /** * @brief Add a row the the table. The number of arguments must match with the number of header values - * @tparam N - * @tparam Args + * @tparam N Number of values passed to addRow. + * @tparam Args Values passed to addRow. * @param args */ template< size_t N, typename ... Args > void addRow( Args const &... args ); + /** + * @brief Add rows to the table. + * @param vecRows + */ + void addRowsFromVector( std::vector< std::vector< string > > vecRows ); + /** * @brief Write the the table into specified stream - * @param os + * @param os An output stream. By defaut os is set to std::cout. */ void draw( std::ostream & os = std::cout ); diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 3b9930a5caa..495343f397a 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -351,6 +351,38 @@ TEST( testTable, tableClass ) "| val1 | v|[3.045,42.02,89.25]|3 |10 | 3 |\n" "+------------+------+-------------------+---------+-------+-------+\n\n" ); + + std::vector< std::vector< std::string > > vecValues = { + {"value1", " ", "3.0", "3.0129877", "2", "1" }, + {"val1", "v", "[3.045,42.02,89.25]", "3", "10", "3" }, + }; + Table tableTest14( { + Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordX"}, Table::Alignment::right}, + Table::ColumnParam{{"C"}, Table::Alignment::middle}, + Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, + Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::left}, + Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, + } ); + + tableTest14.setTitle( "InternalWellGenerator well_injector1" ); + tableTest14.setMargin( Table::MarginValue::tiny ); + tableTest14.addRowsFromVector( vecValues ); + tableTest14.draw( oss ); + tableTestsOutput.push_back( oss.str() ); + oss.clear(); + oss.str( "" ); + EXPECT_EQ( tableTestsOutput[13], + "\n+-----------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+------------+------+-------------------+---------+-------+-------+\n" + "|Cras egestas|CoordX| C |CoordZ |Prev | Next |\n" + "| | | | |element|element|\n" + "+------------+------+-------------------+---------+-------+-------+\n" + "| value1 | | 3.0 |3.0129877|2 | 1 |\n" + "| val1 | v|[3.045,42.02,89.25]|3 |10 | 3 |\n" + "+------------+------+-------------------+---------+-------+-------+\n\n" + ); } From 294f07546ac8e4615b4f7e4fc408b78ab98bae22 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 21 Feb 2024 11:39:10 +0100 Subject: [PATCH 013/216] clean code + doc + add test for rows from vector --- src/coreComponents/codingUtilities/Table.cpp | 90 ++++++------------- src/coreComponents/codingUtilities/Table.hpp | 71 ++++----------- .../codingUtilities/tests/testTable.cpp | 2 +- 3 files changed, 46 insertions(+), 117 deletions(-) diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp index d85accad7eb..4ca16877214 100644 --- a/src/coreComponents/codingUtilities/Table.cpp +++ b/src/coreComponents/codingUtilities/Table.cpp @@ -40,47 +40,38 @@ string buildValueCell( Table::Alignment const alignment, string_view value, inte } } -string Table::getStringSection( Section section ) const +Table::Table( std::vector< string > const & headers ) { - switch( section ) - { - case Section::header: return "header"; - case Section::values: return "values"; - default: return "values"; - } -} + setMargin( MarginValue::medium ); -Table::Table( std::vector< string > const & headers ): - borderMargin( getMargin( MarginType::border )), - columnMargin( getMargin( MarginType::column )) -{ for( size_t idx = 0; idx< headers.size(); idx++ ) { m_columns.push_back( {Table::ColumnParam{{headers[idx]}, Alignment::middle, true}, {}, ""} ); } } -Table::Table( std::vector< ColumnParam > const & columnParameter ): - borderMargin( getMargin( MarginType::border )), - columnMargin( getMargin( MarginType::column )) +Table::Table( std::vector< ColumnParam > const & columnParameter ) { + setMargin( MarginValue::medium ); + for( size_t idx = 0; idx< columnParameter.size(); idx++ ) { if( columnParameter[idx].enabled ) { m_columns.push_back( {columnParameter[idx], {}, ""} ); } + } } -void Table::addRowsFromVector( std::vector< std::vector< string > > vecRows ) +void Table::addRowsFromVectors( std::vector< std::vector< string > > tableRows ) { - for( size_t indexRow = 0; indexRow < vecRows.size(); indexRow++ ) + for( size_t indexRow = 0; indexRow < tableRows.size(); indexRow++ ) { std::vector< string > rowsValues; - for( size_t indexValue = 0; indexValue < vecRows[indexRow].size(); indexValue++ ) + for( size_t indexValue = 0; indexValue < tableRows[indexRow].size(); indexValue++ ) { - string cellValue = GEOS_FMT( "{}", vecRows[indexRow][indexValue] ); + string cellValue = GEOS_FMT( "{}", tableRows[indexRow][indexValue] ); if( m_columns[indexValue].parameter.enabled ) { rowsValues.push_back( cellValue ); @@ -90,18 +81,6 @@ void Table::addRowsFromVector( std::vector< std::vector< string > > vecRows ) } } -Table::Margin Table::getMargin( MarginType type ) const -{ - Margin marginBorder {0, 1, 2, 3, 2}; - Margin marginColumn {0, 3, 5, 7, 5}; - if( type == MarginType::border ) - { - return marginBorder; - } - return marginColumn; - -} - void Table::parseAndStoreHeaderSections( size_t & largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ) { @@ -147,27 +126,10 @@ string_view Table::getTitle() return tableTitle; } -void Table::setMargin( MarginValue valueType ) +void Table::setMargin( MarginValue marginType ) { - switch( valueType ) - { - case MarginValue::tiny: - borderMargin.setWorkingValue( borderMargin.tiny ); - columnMargin.setWorkingValue( columnMargin.tiny ); - break; - case MarginValue::small: - borderMargin.setWorkingValue( borderMargin.small ); - columnMargin.setWorkingValue( columnMargin.small ); - break; - case MarginValue::medium: - borderMargin.setWorkingValue( borderMargin.medium ); - columnMargin.setWorkingValue( columnMargin.medium ); - break; - case MarginValue::large: - borderMargin.setWorkingValue( borderMargin.large ); - columnMargin.setWorkingValue( columnMargin.large ); - break; - } + borderMargin = marginType; + columnMargin = integer( marginType ) * 2 + 1; } void Table::findAndSetMaxStringSize() @@ -212,7 +174,7 @@ void Table::computeAndSetMaxStringSize( string::size_type sectionlineLength, { m_columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", m_columns[idxColumn].m_maxStringSize, - newStringSize + columnMargin.marginValue ); + newStringSize + columnMargin ); } else { @@ -227,7 +189,7 @@ void Table::computeAndBuildSeparator( string & topSeparator, string & sectionSep { string::size_type sectionlineLength = 0; string::size_type titleLineLength = tableTitle.length() + ( marginTitle * 2 ); - integer nbSpaceBetweenColumn = ( ( m_columns.size() - 1 ) * columnMargin.marginValue ) + (borderMargin.marginValue * 2); + integer nbSpaceBetweenColumn = ( ( m_columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); if( !tableTitle.empty()) { tableTitle = GEOS_FMT( "{:^{}}", tableTitle, titleLineLength ); @@ -247,7 +209,7 @@ void Table::computeAndBuildSeparator( string & topSeparator, string & sectionSep { sectionSeparator += GEOS_FMT( "+{:-<{}}+", "", - ( m_columns[0].m_maxStringSize.length() + (borderMargin.marginValue - 1) + columnMargin.marginValue )); + ( m_columns[0].m_maxStringSize.length() + (borderMargin - 1) + columnMargin )); } else { @@ -256,16 +218,16 @@ void Table::computeAndBuildSeparator( string & topSeparator, string & sectionSep integer cellSize = m_columns[idxColumn].m_maxStringSize.length(); if( idxColumn == 0 ) { - sectionSeparator += GEOS_FMT( "+{:-<{}}", "", ( cellSize + borderMargin.marginValue )); + sectionSeparator += GEOS_FMT( "+{:-<{}}", "", ( cellSize + borderMargin )); } else if( idxColumn == (m_columns.size() - 1)) { - sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin.marginValue ); - sectionSeparator += GEOS_FMT( "{:->{}}", "+", ( cellSize + borderMargin.marginValue + 1 ) ); + sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); + sectionSeparator += GEOS_FMT( "{:->{}}", "+", ( cellSize + borderMargin + 1 ) ); } else { - sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin.marginValue ); + sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); sectionSeparator += GEOS_FMT( "{:->{}}", "", cellSize ); } } @@ -286,16 +248,16 @@ void Table::buildTitleRow( string & titleRows, string topSeparator, string secti void Table::buildSectionRows( string sectionSeparator, string & rows, integer const nbRows, - Section const sectionName ) + Section const section ) { for( integer idxRow = 0; idxRow< nbRows; idxRow++ ) { - rows += GEOS_FMT( "{:<{}}", "|", 1 + borderMargin.marginValue ); + rows += GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) { string cell; - if( getStringSection( sectionName ) == "header" ) + if( section == Section::header ) { cell = m_columns[idxColumn].parameter.headerName[idxRow]; } @@ -310,17 +272,17 @@ void Table::buildSectionRows( string sectionSeparator, if( idxColumn < m_columns.size() - 1 ) { - rows += GEOS_FMT( "{:^{}}", "|", columnMargin.marginValue ); + rows += GEOS_FMT( "{:^{}}", "|", columnMargin ); } } if( m_columns.size() == 1 ) { - rows += GEOS_FMT( "{:>{}}\n", "|", columnMargin.marginValue ); + rows += GEOS_FMT( "{:>{}}\n", "|", columnMargin ); } else { - rows += GEOS_FMT( "{:>{}}\n", "|", borderMargin.marginValue + 1 ); + rows += GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); } } diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index 9eaddb52b83..c3d60fff834 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -30,30 +30,11 @@ class Table enum Alignment { right, left, middle }; - enum MarginType { border, column }; - - enum MarginValue { tiny, small, medium, large }; - - /** - * @brief Struct for a column margin and a border margin. - */ - struct Margin - { - // 0 margin from | - integer tiny; - // 1 margin from | - integer small; - // 2 margin from | - integer medium; - // 3 margin from | - integer large; - // current margin value - integer marginValue; - - void setWorkingValue( integer const value ) - { - marginValue = value; - } + enum MarginValue : integer { + tiny = 0, + small = 1, + medium = 2, + large = 3 }; /** @@ -78,7 +59,7 @@ class Table /** * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels * level - * @param columnParameter + * @param columnParameter List of structures to set up each colum parameters. */ Table( std::vector< ColumnParam > const & columnParameter ); @@ -92,10 +73,10 @@ class Table void addRow( Args const &... args ); /** - * @brief Add rows to the table. - * @param vecRows + * @brief Add rows from vectors to the table. + * @param vecRows Vector who contains all table's rows */ - void addRowsFromVector( std::vector< std::vector< string > > vecRows ); + void addRowsFromVectors( std::vector< std::vector< string > > tableRows ); /** * @brief Write the the table into specified stream @@ -111,9 +92,9 @@ class Table /** * @brief Sets the minimal margin width between row content and borders. - * @param valueType + * @param marginType */ - void setMargin( MarginValue valueType ); + void setMargin( MarginValue marginType ); /** * @return return the table name @@ -136,20 +117,6 @@ class Table string m_maxStringSize; }; - /** - * @brief Get the margin type either a borderMagin or a column - * @param type - * @return Margin - */ - Margin getMargin( MarginType type ) const; - - /** - * @brief Get the name of the section given an enum - * @param section - * @return The name of the section - */ - string getStringSection( Section section ) const; - /** * @brief Fill the vector \p m_column with values from m_cellsRows who store all values in an unsorted order */ @@ -164,7 +131,7 @@ class Table std::vector< std::vector< string > > & splitHeader ); /** - * @brief Iterate throught the header names vector + * @brief Iterate throught the header names vector. * Adjust the size of each header vector by adding empty strings if needed. * Store the modified header names in the corresponding column parameter. * @param largestHeaderVectorSize The largest split header vector size @@ -189,14 +156,14 @@ class Table /** * @brief Compute and build the top and the section line separator - * @param topSeparator - * @param sectionSeparator + * @param topSeparator An empty string to be built + * @param sectionSeparator An empty string to be built */ void computeAndBuildSeparator( string & topSeparator, string & sectionSeparator ); /** * @brief Build the table title section - * @param titleRows Rows containing the title section + * @param titleRows Rows containing the title section. * @param topSeparator The top line separator * @param sectionSeparator The section line separator */ @@ -207,19 +174,19 @@ class Table * @param sectionSeparator Line separator between sections * @param rows A section row * @param nbRows Indicates the number of lines in a section - * @param sectionName The section to be built + * @param section The section to be built */ void buildSectionRows( string sectionSeparator, string & rows, integer const nbRows, - Section const sectionName ); + Section const section ); std::vector< std::vector< string > > m_cellsRows; std::vector< Column > m_columns; - Margin borderMargin; - Margin columnMargin; + integer borderMargin; + integer columnMargin; string tableTitle; diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 495343f397a..92283c45e74 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -367,7 +367,7 @@ TEST( testTable, tableClass ) tableTest14.setTitle( "InternalWellGenerator well_injector1" ); tableTest14.setMargin( Table::MarginValue::tiny ); - tableTest14.addRowsFromVector( vecValues ); + tableTest14.addRowsFromVectors( vecValues ); tableTest14.draw( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); From 36dd7a402298aa29ed22d3e8311b2def95b6330b Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 22 Feb 2024 10:58:18 +0100 Subject: [PATCH 014/216] doc updated --- src/coreComponents/codingUtilities/Table.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index c3d60fff834..397f456c4d4 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -65,8 +65,8 @@ class Table /** * @brief Add a row the the table. The number of arguments must match with the number of header values - * @tparam N Number of values passed to addRow. - * @tparam Args Values passed to addRow. + * @tparam N The Number of values passed to addRow. + * @tparam Args The values passed to addRow. * @param args */ template< size_t N, typename ... Args > @@ -79,7 +79,7 @@ class Table void addRowsFromVectors( std::vector< std::vector< string > > tableRows ); /** - * @brief Write the the table into specified stream + * @brief Write the table into specified stream * @param os An output stream. By defaut os is set to std::cout. */ void draw( std::ostream & os = std::cout ); @@ -91,7 +91,7 @@ class Table void setTitle( string_view tableTitle ); /** - * @brief Sets the minimal margin width between row content and borders. + * @brief Set the minimal margin width between row content and borders. * @param marginType */ void setMargin( MarginValue marginType ); @@ -124,7 +124,7 @@ class Table /** * @brief Split all header names by detecting the newline \\n character. - * @param splitHeader A vector containing all split header names + * @param splitHeader A empty vector who will contain all split header names * @param largestHeaderVectorSize The largest split header vector size */ void parseAndStoreHeaderSections( size_t & largestHeaderVectorSize, @@ -182,6 +182,7 @@ class Table Section const section ); + //Vector who contains all rows in the table std::vector< std::vector< string > > m_cellsRows; std::vector< Column > m_columns; From 8f74cfa7027ab13a3b82f0be10ba83fccf1f04ba Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 22 Feb 2024 14:26:49 +0100 Subject: [PATCH 015/216] Merge commit 'c11ad8ecd2d0d0aba5cd0661eb6e72951252409d' into feature/dudes/table-layout --- .devcontainer/devcontainer.json | 2 +- .github/workflows/ci_tests.yml | 15 +- host-configs/LLNL/quartz-base.cmake | 7 + ...4.1.2-openblas0.3.10-cuda11.7.1-sm70.cmake | 28 + host-configs/Stanford/sherlock-modules.sh | 17 +- .../benchmarks/SPE10/SPE10.ats | 19 + .../buckleyLeverettProblem.ats | 19 + .../isothermalLeakyWell.ats | 19 + .../thermalLeakyWell/thermalLeakyWell.ats | 19 + .../c1-ppu/c1_ppu.ats | 17 + .../compositionalMultiphaseFlow.ats | 91 +++ .../benchmarks/Class09Pb3/Class09Pb3.ats | 24 + .../Egg/compositionalMultiphaseWell_Egg.ats | 26 + .../compositionalMultiphaseWell.ats | 88 +++ .../efemFractureMechanics.ats | 68 ++ .../hydraulicFracturing/Hydrofracturing.ats | 203 ++++++ .../hydrofractureSinglePhase2d.xml | 3 + .../kgdToughnessDominated_base.xml | 5 +- .../scripts/hydrofractureCurveChecks.py | 10 +- .../contactMechanics.ats | 51 ++ inputFiles/main.ats | 21 + .../solidMechanicsMPM_dfgMovingGrid.ats | 20 + .../solidMechanicsMPM_particleRepartition.ats | 20 + .../solidMechanicsMPM_singleParticle.ats | 20 + .../multiphaseFlowFractures.ats | 25 + inputFiles/phaseField/PhaseFieldFracture.ats | 56 ++ .../PoroElastic_Mandel_benchmark_fim.xml | 2 +- .../poroelasticCoupling_validation.ats | 91 +++ .../poromechanics/poroElasticCoupling.ats | 281 ++++++++ inputFiles/poromechanics/viscoPlastic.ats | 33 + ...ayPermeability_conformingFracture_base.xml | 3 +- ...c_conformingFracture_2d_faultSlip_base.xml | 5 +- ...conformingFracture_2d_openingFrac_base.xml | 5 +- .../poromechanicsFractures.ats | 74 ++ inputFiles/proppant/proppantTransport.ats | 34 + inputFiles/simplePDE/SimpleSolvers.ats | 58 ++ .../singlePhaseFlow/singlePhaseFlow.ats | 81 +++ .../thermalSinglePhaseFlow.ats | 28 + .../fractureFlow_conforming_2d_vtk_input.xml | 3 +- .../fractureMatrixFlow_conforming_2d.xml | 3 +- .../impermeableFault_conforming_base.xml | 3 +- .../singlePhaseFlowFractures.ats | 86 +++ .../singlePhaseWell/singlePhaseWell.ats | 58 ++ inputFiles/solidMechanics/SSLE.ats | 19 + inputFiles/solidMechanics/anisotropic.ats | 36 + inputFiles/solidMechanics/beamBending.ats | 38 ++ inputFiles/solidMechanics/gravity.ats | 20 + .../solidMechanics/plasticCubeReset.ats | 19 + inputFiles/solidMechanics/plasticWellbore.ats | 34 + inputFiles/solidMechanics/sedov.ats | 27 + inputFiles/solidMechanics/viscoPlastic.ats | 20 + inputFiles/solidMechanics/wellbore.ats | 19 + .../surfaceGeneration/SurfaceGenerator.ats | 46 ++ .../thermalMultiphaseFlow.ats | 28 + ...ctureMatrixThermalFlow_conforming_base.xml | 2 +- .../thermalSinglePhaseFlowFractures.ats | 26 + .../thermoPoromechanics.ats | 32 + .../thermoPoromechanicsFractures.ats | 23 + .../wavePropagation/AcousticElasticSEM.ats | 20 + .../wavePropagation/AcousticFirstOrderSEM.ats | 44 ++ inputFiles/wavePropagation/AcousticSEM.ats | 58 ++ .../wavePropagation/ElasticFirstOrderSEM.ats | 44 ++ inputFiles/wavePropagation/ElasticSEM.ats | 42 ++ .../wellbore/thermoPoromechanics_wellbore.ats | 18 + inputFiles/wellbore/wellboreMesh.ats | 67 ++ integratedTests | 2 +- scripts/ci_build_and_test_in_container.sh | 4 +- scripts/setupPythonEnvironment.bash | 14 +- src/CMakeLists.txt | 91 ++- .../Qk_Hexahedron_Lagrange_GaussLobatto.hpp | 2 +- .../physicsSolvers/CMakeLists.txt | 5 +- .../NonlinearSolverParameters.cpp | 39 ++ .../NonlinearSolverParameters.hpp | 13 +- .../physicsSolvers/SolverBase.cpp | 181 +++-- .../physicsSolvers/SolverBase.hpp | 4 + .../contact/LagrangianContactSolver.cpp | 2 + .../SolidMechanicsEmbeddedFractures.cpp | 1 + .../fluidFlow/CompositionalMultiphaseBase.cpp | 122 ++-- .../fluidFlow/CompositionalMultiphaseBase.hpp | 12 +- .../CompositionalMultiphaseStatistics.cpp | 2 +- .../fluidFlow/FlowSolverBase.cpp | 96 ++- .../fluidFlow/FlowSolverBase.hpp | 18 +- .../ReactiveCompositionalMultiphaseOBL.cpp | 2 + .../fluidFlow/SinglePhaseBase.cpp | 39 +- .../fluidFlow/wells/WellSolverBase.cpp | 1 + ...mpositionalMultiphaseReservoirAndWells.hpp | 2 +- .../multiphysics/CoupledSolver.hpp | 63 +- .../multiphysics/HydrofractureSolver.cpp | 8 + .../multiphysics/HydrofractureSolver.hpp | 3 + .../HydrofractureSolverKernels.hpp | 46 +- .../multiphysics/MultiphasePoromechanics.cpp | 4 + .../multiphysics/PoromechanicsSolver.hpp | 3 - .../multiphysics/SinglePhasePoromechanics.cpp | 2 + ...ePhasePoromechanicsConformingFractures.cpp | 1 + ...glePhasePoromechanicsEmbeddedFractures.cpp | 2 + .../SinglePhaseReservoirAndWells.hpp | 2 +- .../simplePDE/PhaseFieldDamageFEM.cpp | 4 + .../simplePDE/PhaseFieldDamageFEM.hpp | 2 + .../SolidMechanicsLagrangianFEM.cpp | 5 + .../SolidMechanicsLagrangianFEM.hpp | 2 + .../AcousticElasticWaveEquationSEM.cpp | 53 +- .../AcousticElasticWaveEquationSEM.hpp | 29 +- .../wavePropagation/AcousticFields.hpp | 203 ++++++ .../AcousticFirstOrderWaveEquationSEM.cpp | 95 +-- .../AcousticFirstOrderWaveEquationSEM.hpp | 17 +- .../wavePropagation/AcousticVTIFields.hpp | 193 ++++++ .../AcousticVTIWaveEquationSEM.cpp | 152 ++--- .../AcousticVTIWaveEquationSEM.hpp | 3 +- .../AcousticVTIWaveEquationSEMKernel.hpp | 18 +- .../AcousticWaveEquationSEM.cpp | 202 +++--- .../AcousticWaveEquationSEM.hpp | 143 +--- .../AcousticWaveEquationSEMKernel.hpp | 9 +- .../wavePropagation/AcoustoElasticFields.hpp | 66 ++ ...SolverBaseFields.hpp => ElasticFields.hpp} | 294 +++----- .../ElasticFirstOrderWaveEquationSEM.cpp | 181 +++-- .../ElasticFirstOrderWaveEquationSEM.hpp | 15 +- ...ElasticFirstOrderWaveEquationSEMKernel.hpp | 2 +- .../ElasticWaveEquationSEM.cpp | 207 +++--- .../ElasticWaveEquationSEM.hpp | 205 +----- .../ElasticWaveEquationSEMKernel.hpp | 22 +- .../wavePropagation/WaveSolverUtils.hpp | 2 - .../docs/CompositionalMultiphaseFVM.rst | 3 + .../docs/CompositionalMultiphaseHybridFVM.rst | 3 + .../docs/ElasticFirstOrderSEM_other.rst | 6 + .../schema/docs/Hydrofracture.rst | 1 + .../schema/docs/NonlinearSolverParameters.rst | 2 + .../schema/docs/ProppantTransport.rst | 46 +- .../ReactiveCompositionalMultiphaseOBL.rst | 52 +- .../schema/docs/SinglePhaseFVM.rst | 34 +- .../schema/docs/SinglePhaseHybridFVM.rst | 34 +- .../schema/docs/SinglePhaseProppantFVM.rst | 34 +- src/coreComponents/schema/schema.xsd | 41 +- src/coreComponents/schema/schema.xsd.other | 12 + src/coreComponents/unitTests/CMakeLists.txt | 2 +- .../wavePropagationTests/CMakeLists.txt | 1 + .../testWavePropagationAcousticFirstOrder.cpp | 1 - .../testWavePropagationElasticFirstOrder.cpp | 303 +++++++++ .../Contributing/IntegratedTests.rst | 634 +++++++++++++++++- 138 files changed, 5034 insertions(+), 1508 deletions(-) create mode 100644 host-configs/Stanford/sherlock-gcc10-ompi4.1.2-openblas0.3.10-cuda11.7.1-sm70.cmake create mode 100644 inputFiles/compositionalMultiphaseFlow/benchmarks/SPE10/SPE10.ats create mode 100644 inputFiles/compositionalMultiphaseFlow/benchmarks/buckleyLeverettProblem/buckleyLeverettProblem.ats create mode 100644 inputFiles/compositionalMultiphaseFlow/benchmarks/isothermalLeakyWell/isothermalLeakyWell.ats create mode 100644 inputFiles/compositionalMultiphaseFlow/benchmarks/thermalLeakyWell/thermalLeakyWell.ats create mode 100644 inputFiles/compositionalMultiphaseFlow/c1-ppu/c1_ppu.ats create mode 100644 inputFiles/compositionalMultiphaseFlow/compositionalMultiphaseFlow.ats create mode 100644 inputFiles/compositionalMultiphaseWell/benchmarks/Class09Pb3/Class09Pb3.ats create mode 100644 inputFiles/compositionalMultiphaseWell/benchmarks/Egg/compositionalMultiphaseWell_Egg.ats create mode 100644 inputFiles/compositionalMultiphaseWell/compositionalMultiphaseWell.ats create mode 100644 inputFiles/efemFractureMechanics/efemFractureMechanics.ats create mode 100644 inputFiles/hydraulicFracturing/Hydrofracturing.ats create mode 100644 inputFiles/lagrangianContactMechanics/contactMechanics.ats create mode 100644 inputFiles/main.ats create mode 100644 inputFiles/materialPointMethod/dfgMovingGrid/solidMechanicsMPM_dfgMovingGrid.ats create mode 100644 inputFiles/materialPointMethod/particleRepartition/solidMechanicsMPM_particleRepartition.ats create mode 100644 inputFiles/materialPointMethod/singleParticle/solidMechanicsMPM_singleParticle.ats create mode 100644 inputFiles/multiphaseFlowFractures/multiphaseFlowFractures.ats create mode 100644 inputFiles/phaseField/PhaseFieldFracture.ats create mode 100644 inputFiles/poromechanics/nonlinearAcceleration/validationCase/poroelasticCoupling_validation.ats create mode 100644 inputFiles/poromechanics/poroElasticCoupling.ats create mode 100644 inputFiles/poromechanics/viscoPlastic.ats create mode 100644 inputFiles/poromechanicsFractures/poromechanicsFractures.ats create mode 100644 inputFiles/proppant/proppantTransport.ats create mode 100644 inputFiles/simplePDE/SimpleSolvers.ats create mode 100644 inputFiles/singlePhaseFlow/singlePhaseFlow.ats create mode 100644 inputFiles/singlePhaseFlow/thermalSinglePhaseFlow.ats create mode 100644 inputFiles/singlePhaseFlowFractures/singlePhaseFlowFractures.ats create mode 100644 inputFiles/singlePhaseWell/singlePhaseWell.ats create mode 100644 inputFiles/solidMechanics/SSLE.ats create mode 100644 inputFiles/solidMechanics/anisotropic.ats create mode 100644 inputFiles/solidMechanics/beamBending.ats create mode 100644 inputFiles/solidMechanics/gravity.ats create mode 100644 inputFiles/solidMechanics/plasticCubeReset.ats create mode 100644 inputFiles/solidMechanics/plasticWellbore.ats create mode 100644 inputFiles/solidMechanics/sedov.ats create mode 100644 inputFiles/solidMechanics/viscoPlastic.ats create mode 100644 inputFiles/solidMechanics/wellbore.ats create mode 100644 inputFiles/surfaceGeneration/SurfaceGenerator.ats create mode 100644 inputFiles/thermalMultiphaseFlow/thermalMultiphaseFlow.ats create mode 100644 inputFiles/thermalSinglePhaseFlowFractures/thermalSinglePhaseFlowFractures.ats create mode 100644 inputFiles/thermoPoromechanics/thermoPoromechanics.ats create mode 100644 inputFiles/thermoPoromechanicsFractures/thermoPoromechanicsFractures.ats create mode 100644 inputFiles/wavePropagation/AcousticElasticSEM.ats create mode 100644 inputFiles/wavePropagation/AcousticFirstOrderSEM.ats create mode 100644 inputFiles/wavePropagation/AcousticSEM.ats create mode 100644 inputFiles/wavePropagation/ElasticFirstOrderSEM.ats create mode 100644 inputFiles/wavePropagation/ElasticSEM.ats create mode 100644 inputFiles/wellbore/thermoPoromechanics_wellbore.ats create mode 100644 inputFiles/wellbore/wellboreMesh.ats create mode 100644 src/coreComponents/physicsSolvers/wavePropagation/AcousticFields.hpp create mode 100644 src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIFields.hpp create mode 100644 src/coreComponents/physicsSolvers/wavePropagation/AcoustoElasticFields.hpp rename src/coreComponents/physicsSolvers/wavePropagation/{WaveSolverBaseFields.hpp => ElasticFields.hpp} (53%) create mode 100644 src/coreComponents/unitTests/wavePropagationTests/testWavePropagationElasticFirstOrder.cpp diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 68b2774c020..7729845a464 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ "build": { "dockerfile": "Dockerfile", "args": { - "GEOS_TPL_TAG": "254-134" + "GEOS_TPL_TAG": "256-147" } }, "runArgs": [ diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index ad4913ba5c6..46b45151698 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -167,8 +167,8 @@ jobs: DOCKER_REPOSITORY: geosx/sherlock-gcc10.1.0-openmpi4.1.2-openblas0.3.10-zlib1.2.11 ENABLE_HYPRE: ON ENABLE_TRILINOS: OFF - HOST_CONFIG: host-configs/Stanford/sherlock-gcc10-ompi4.1.2-openblas0.3.10.cmake GCP_BUCKET: geosx/Sherlock-CPU + HOST_CONFIG: host-configs/Stanford/sherlock-gcc10-ompi4.1.2-openblas0.3.10.cmake uses: ./.github/workflows/build_and_test.yml with: @@ -263,6 +263,18 @@ jobs: DOCKER_REPOSITORY: geosx/pecan-gpu-gcc8.2.0-openmpi4.0.1-mkl2019.5-cuda11.5.119 HOST_CONFIG: host-configs/TOTAL/pecan-GPU.cmake RUNS_ON: Runner_4core_16GB + + - name: Sherlock GPU (centos 7.9.2009, gcc 10.1.0, open-mpi 4.1.2, openblas 0.3.10, cuda 11.7.1,) + BUILD_AND_TEST_CLI_ARGS: "--no-run-unit-tests --no-install-schema" + CMAKE_BUILD_TYPE: Release + DOCKER_REPOSITORY: geosx/sherlock-gcc10.1.0-openmpi4.1.2-cuda11.7.1-openblas0.3.10-zlib1.2.11 + ENABLE_HYPRE_DEVICE: CUDA + ENABLE_HYPRE: ON + ENABLE_TRILINOS: OFF + GCP_BUCKET: geosx/Sherlock-GPU + HOST_CONFIG: host-configs/Stanford/sherlock-gcc10-ompi4.1.2-openblas0.3.10-cuda11.7.1-sm70.cmake + RUNS_ON: Runner_4core_16GB + uses: ./.github/workflows/build_and_test.yml with: BUILD_AND_TEST_CLI_ARGS: ${{ matrix.BUILD_AND_TEST_CLI_ARGS }} @@ -273,6 +285,7 @@ jobs: ENABLE_HYPRE_DEVICE: ${{ matrix.ENABLE_HYPRE_DEVICE }} ENABLE_HYPRE: ${{ matrix.ENABLE_HYPRE }} ENABLE_TRILINOS: ${{ matrix.ENABLE_TRILINOS }} + GCP_BUCKET: ${{ matrix.GCP_BUCKET }} HOST_CONFIG: ${{ matrix.HOST_CONFIG }} RUNS_ON: ${{ matrix.RUNS_ON }} secrets: inherit diff --git a/host-configs/LLNL/quartz-base.cmake b/host-configs/LLNL/quartz-base.cmake index f5ff404044c..38047f8e0ce 100644 --- a/host-configs/LLNL/quartz-base.cmake +++ b/host-configs/LLNL/quartz-base.cmake @@ -58,5 +58,12 @@ set(MKL_LIBRARIES ${MKL_ROOT}/lib/intel64/libmkl_intel_lp64.so # ATS set(ATS_ARGUMENTS "--machine slurm36" CACHE STRING "") +# set(USER $ENV{USER} CACHE STRING "") +# set(ATS_WORKING_DIR "/p/lustre2/${USER}/integratedTests/${CONFIG_NAME}" CACHE PATH "") +# set(ATS_BASELINE_DIR "/p/lustre2/${USER}/integratedTests/baselines" CACHE PATH "") + +# Temporary argument for python module change testing +# set(GEOS_PYTHON_PACKAGES_BRANCH "feature/sherman/outOfPlaceATS" CACHE STRING "" FORCE) + include(${CMAKE_CURRENT_LIST_DIR}/../tpls.cmake) diff --git a/host-configs/Stanford/sherlock-gcc10-ompi4.1.2-openblas0.3.10-cuda11.7.1-sm70.cmake b/host-configs/Stanford/sherlock-gcc10-ompi4.1.2-openblas0.3.10-cuda11.7.1-sm70.cmake new file mode 100644 index 00000000000..51031871d6b --- /dev/null +++ b/host-configs/Stanford/sherlock-gcc10-ompi4.1.2-openblas0.3.10-cuda11.7.1-sm70.cmake @@ -0,0 +1,28 @@ +include(${CMAKE_CURRENT_LIST_DIR}/sherlock-gcc10-ompi4.1.2-openblas0.3.10.cmake) + +# OpenMP options +set(ENABLE_OPENMP OFF CACHE BOOL "" FORCE) + +# CUDA options +set(ENABLE_CUDA ON CACHE BOOL "" FORCE) +set(CUDA_VERSION "11.7.1" CACHE PATH "") +set(CUDA_HOME "${SOFTWARE_ROOT}/cuda/${CUDA_VERSION}" CACHE PATH "") +set(CMAKE_CUDA_ARCHITECTURES "70" CACHE STRING "") +set(CUDA_ARCH "sm_${CMAKE_CUDA_ARCHITECTURES}" CACHE STRING "") +set(CUDA_TOOLKIT_ROOT_DIR "${CUDA_HOME}" CACHE STRING "") + +set(CONFIG_NAME "sherlock-gcc10-ompi4.1.2-openblas0.3.10-cuda${CUDA_VERSION}-${CUDA_ARCH}" CACHE PATH "" FORCE) + +set(CMAKE_CUDA_HOST_COMPILER ${MPI_CXX_COMPILER} CACHE STRING "") +set(CMAKE_CUDA_COMPILER ${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc CACHE STRING "") +set(CMAKE_CUDA_FLAGS "-restrict -arch ${CUDA_ARCH} --expt-extended-lambda --expt-relaxed-constexpr -Werror cross-execution-space-call,reorder,deprecated-declarations " CACHE STRING "") +set(CMAKE_CUDA_FLAGS_RELEASE "-O3 -DNDEBUG -Xcompiler -DNDEBUG -Xcompiler -O3" CACHE STRING "") +set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO "-g -lineinfo ${CMAKE_CUDA_FLAGS_RELEASE}" CACHE STRING "") +set(CMAKE_CUDA_FLAGS_DEBUG "-g -G -O0 -Xcompiler -O0" CACHE STRING "") + +# LAI options +set(GEOSX_LA_INTERFACE "Hypre" CACHE STRING "" FORCE) +set(ENABLE_HYPRE ON CACHE BOOL "" FORCE) +set(ENABLE_HYPRE_DEVICE "CUDA" CACHE STRING "" FORCE) +set(ENABLE_PETSC OFF CACHE BOOL "" FORCE) +set(ENABLE_TRILINOS OFF CACHE BOOL "" FORCE) diff --git a/host-configs/Stanford/sherlock-modules.sh b/host-configs/Stanford/sherlock-modules.sh index 3bdbe8257c5..316116271e2 100755 --- a/host-configs/Stanford/sherlock-modules.sh +++ b/host-configs/Stanford/sherlock-modules.sh @@ -1,11 +1,12 @@ module load system -module load git/2.12.2 -module load git-lfs/2.4.0 -module load cmake/3.20.3 -module load ninja/1.9.0 -module load py-mpi4py/3.0.3_py36 -module load py-h5py/2.10.0_py36 +module load git +module load git-lfs +module load cmake module load gcc/10.1.0 -module load openmpi/4.1.0 -module load cuda/11.2.0 +module load openmpi/4.1.2 +module load openblas/0.3.10 module load libevent/2.1.12 # needed for silo +module load py-mpi4py/3.1.3_py39 +module load py-h5py/3.7.0_py39 +module unload cuda +module load cuda/11.7.1 diff --git a/inputFiles/compositionalMultiphaseFlow/benchmarks/SPE10/SPE10.ats b/inputFiles/compositionalMultiphaseFlow/benchmarks/SPE10/SPE10.ats new file mode 100644 index 00000000000..3d37c8e5c7b --- /dev/null +++ b/inputFiles/compositionalMultiphaseFlow/benchmarks/SPE10/SPE10.ats @@ -0,0 +1,19 @@ +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-6 +restartcheck_params["rtol"] = 1.0E-5 + +decks = [ + TestDeck( + name="deadOilSpe10Layers84_85_smoke_2d", + description= + "Smoke test for SPE10 (2D displacement, 2-phase dead-oil, Brooks-Corey pairwise 2-phase relperm curves)", + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=49, + check_step=89, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), +] + +generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseFlow/benchmarks/buckleyLeverettProblem/buckleyLeverettProblem.ats b/inputFiles/compositionalMultiphaseFlow/benchmarks/buckleyLeverettProblem/buckleyLeverettProblem.ats new file mode 100644 index 00000000000..30944577aa4 --- /dev/null +++ b/inputFiles/compositionalMultiphaseFlow/benchmarks/buckleyLeverettProblem/buckleyLeverettProblem.ats @@ -0,0 +1,19 @@ +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-6 +restartcheck_params["rtol"] = 1.0E-5 + +decks = [ + TestDeck( + name="buckleyLeverett_smoke", + description= + "Smoke test for a CO2 core flood experiment (1D displacement, 2-phase dead-oil, Brooks-Corey pairwise 2-phase relperm curves)", + partitions=((1, 1, 1), (2, 1, 1)), + restart_step=9, + check_step=13, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseFlow/benchmarks/isothermalLeakyWell/isothermalLeakyWell.ats b/inputFiles/compositionalMultiphaseFlow/benchmarks/isothermalLeakyWell/isothermalLeakyWell.ats new file mode 100644 index 00000000000..acc7382aa8f --- /dev/null +++ b/inputFiles/compositionalMultiphaseFlow/benchmarks/isothermalLeakyWell/isothermalLeakyWell.ats @@ -0,0 +1,19 @@ +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-6 +restartcheck_params["rtol"] = 1.0E-5 + +decks = [ + TestDeck( + name="isothermalLeakyWell_smoke_3d", + description= + "Smoke test for isothermalLeakyWell (3D displacement, 2-phase dead-oil, hydrostatic initial condition)", + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=60, + check_step=104, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), +] + +generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseFlow/benchmarks/thermalLeakyWell/thermalLeakyWell.ats b/inputFiles/compositionalMultiphaseFlow/benchmarks/thermalLeakyWell/thermalLeakyWell.ats new file mode 100644 index 00000000000..f0a149ff298 --- /dev/null +++ b/inputFiles/compositionalMultiphaseFlow/benchmarks/thermalLeakyWell/thermalLeakyWell.ats @@ -0,0 +1,19 @@ +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-6 +restartcheck_params["rtol"] = 1.0E-5 + +decks = [ + TestDeck( + name="thermalLeakyWell_smoke_3d", + description= + "Smoke test for thermalLeakyWell (3D displacement, 2-phase co2-brine, hydrostatic initial condition)", + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=60, + check_step=104, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), +] + +generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseFlow/c1-ppu/c1_ppu.ats b/inputFiles/compositionalMultiphaseFlow/c1-ppu/c1_ppu.ats new file mode 100644 index 00000000000..52d47c61ff4 --- /dev/null +++ b/inputFiles/compositionalMultiphaseFlow/c1-ppu/c1_ppu.ats @@ -0,0 +1,17 @@ +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-6 +restartcheck_params["rtol"] = 1.0E-5 + +decks = [ + TestDeck(name="grav_seg_c1ppu_hyst", + description="Smoke test for C1-PPU (1D displacement, C1-PPU)", + partitions=((1, 1, 1), (1, 1, 2)), + restart_step=87, + check_step=109, + restartcheck_params=RestartcheckParameters(atol=1e-4, rtol=1e-3)), +] + +generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseFlow/compositionalMultiphaseFlow.ats b/inputFiles/compositionalMultiphaseFlow/compositionalMultiphaseFlow.ats new file mode 100644 index 00000000000..a0072bc2653 --- /dev/null +++ b/inputFiles/compositionalMultiphaseFlow/compositionalMultiphaseFlow.ats @@ -0,0 +1,91 @@ +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-6 +restartcheck_params["rtol"] = 1.0E-5 + +decks = [ + TestDeck( + name="4comp_2ph_1d", + description= + "Compositional multiphase flow test (1D displacement, 2-phase 4-component)", + partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), + restart_step=6, + check_step=11, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="4comp_2ph_cap_1d", + description= + "Compositional multiphase flow test (1D displacement, 2-phase 4-component, capillary pressure)", + partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), + restart_step=118, + check_step=218, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="deadoil_3ph_corey_1d", + description= + "Compositional multiphase flow test (1D displacement, 3-phase dead-oil, Brooks-Corey pairwise 2-phase relperm curves)", + partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), + restart_step=109, + check_step=209, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="co2_hybrid_1d", + description= + "Compositional co2-brine flow test (1D displacement, hybrid FVM, Brooks-Corey pairwise 2-phase relperm curves)", + partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), + restart_step=5, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="deadoil_3ph_baker_1d", + description= + "Compositional multiphase flow test (1D displacement, 3-phase dead-oil, Brooks-Corey-Baker 3-phase relperm curves)", + partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), + restart_step=109, + check_step=209, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="deadoil_3ph_staircase_3d", + description= + "Compositional multiphase flow test (3D staircase, 3-phase dead-oil, Brooks-Corey-Baker 3-phase relperm curves)", + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=28, + check_step=38, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="deadoil_3ph_staircase_hybrid_3d", + description= + "Compositional multiphase flow test (3D staircase, hybrid FVM, 3-phase dead-oil, Brooks-Corey-Baker 3-phase relperm curves)", + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=28, + check_step=38, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="deadoil_2ph_staircase_gravity_segregation_3d", + description= + "Compositional multiphase flow test (3D staircase, no-flow BC, 2-phase dead-oil, hysteresis)", + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=61, + check_step=121, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="co2_flux_3d", + description= + "Compositional co2-brine flow test (3D co2 injection, 2-phase co2-brine, Brooks-Corey 2-phase relperm curves)", + partitions=((1, 1, 1), (2, 2, 2), (3, 3, 3)), + restart_step=10, + check_step=20, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="deadoil_3ph_staircase_obl_3d", + description= + "Smoke test for a staircase deadoil test (3D displacement, 3-phase dead-oil, OBL)", + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=28, + check_step=38, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), +] + +generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseWell/benchmarks/Class09Pb3/Class09Pb3.ats b/inputFiles/compositionalMultiphaseWell/benchmarks/Class09Pb3/Class09Pb3.ats new file mode 100644 index 00000000000..f860f8651da --- /dev/null +++ b/inputFiles/compositionalMultiphaseWell/benchmarks/Class09Pb3/Class09Pb3.ats @@ -0,0 +1,24 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-6 +restartcheck_params["rtol"] = 1.0E-5 + +# exclude any derivative fields from restart checks +# example field name: dGlobalComponentFraction_dPressure +#restartcheck_params["exclude"] = [r"d[A-Z]\w+_d[A-Z]\w+"] + +decks = [ + TestDeck( + name="class09_pb3_smoke_3d", + description= + "Smoke test for the Johansen model (3D displacement, structured mesh, CO2-brine)", + partitions=[(1, 1, 1), (2, 2, 2)], + restart_step=5, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), +] + +generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseWell/benchmarks/Egg/compositionalMultiphaseWell_Egg.ats b/inputFiles/compositionalMultiphaseWell/benchmarks/Egg/compositionalMultiphaseWell_Egg.ats new file mode 100644 index 00000000000..065b75a6645 --- /dev/null +++ b/inputFiles/compositionalMultiphaseWell/benchmarks/Egg/compositionalMultiphaseWell_Egg.ats @@ -0,0 +1,26 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-6 +restartcheck_params["rtol"] = 1.0E-5 + +# exclude any derivative fields from restart checks +# example field name: dGlobalComponentFraction_dPressure +#restartcheck_params["exclude"] = [r"d[A-Z]\w+_d[A-Z]\w+"] + +decks = [ + TestDeck( + name="deadOilEgg_smoke_3d", + description= + "Smoke test for the Egg model (3D displacement, structured mesh, 2-phase dead-oil, many wells)", + partitions=[ + (1, 1, 1), + ], + restart_step=20, + check_step=35, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), +] + +generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseWell/compositionalMultiphaseWell.ats b/inputFiles/compositionalMultiphaseWell/compositionalMultiphaseWell.ats new file mode 100644 index 00000000000..6cfaf320a36 --- /dev/null +++ b/inputFiles/compositionalMultiphaseWell/compositionalMultiphaseWell.ats @@ -0,0 +1,88 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-6 +restartcheck_params["rtol"] = 1.0E-5 + +# exclude any derivative fields from restart checks +# example field name: dGlobalComponentFraction_dPressure +#restartcheck_params["exclude"] = [r"d[A-Z]\w+_d[A-Z]\w+"] + +decks = [ + TestDeck( + name="compositional_multiphase_wells_1d", + description= + "Compositional multiphase well test (1D displacement, 2-phase 4-component, 2 wells)", + partitions=[(1, 1, 1), (2, 1, 1)], + restart_step=5, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="compositional_multiphase_wells_2d", + description= + "Compositional multiphase flow test (2D displacement, 2-phase 4-component, 3 wells)", + partitions=[(1, 1, 1), (2, 2, 1)], + restart_step=3, + check_step=7, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="dead_oil_wells_2d", + description= + "Dead oil well test (2D displacement, 3-phase dead-oil, 3 wells)", + partitions=[(1, 1, 1), (2, 2, 1)], + restart_step=50, + check_step=100, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="dead_oil_wells_hybrid_2d", + description= + "Dead oil well test (2D displacement, hybrid FVM, 3-phase dead-oil, 3 wells)", + partitions=[(1, 1, 1), (2, 2, 1)], + restart_step=50, + check_step=100, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="black_oil_wells_saturated_3d", + description= + "Black oil well test (3D displacement, 3-phase black-oil, 2 wells)", + partitions=[(1, 1, 1), (2, 2, 1)], + restart_step=13, + check_step=25, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="black_oil_wells_unsaturated_3d", + description= + "Black oil well test (3D displacement, hybrid FVM, 3-phase black-oil, 2 wells)", + partitions=[(1, 1, 1), (2, 2, 1)], + restart_step=8, + check_step=12, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="staircase_co2_wells_3d", + description= + "CO2 well test (3D staircase, 2-phase 2-component, 2 wells)", + partitions=[(1, 1, 1), (2, 2, 2)], + restart_step=3, + check_step=5, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="staircase_co2_wells_hybrid_3d", + description= + "CO2 well test (3D staircase, unstructured mesh, hybrid FVM, 2-phase 2-component, 2 wells)", + partitions=[(1, 1, 1), (2, 2, 2)], + restart_step=0, + check_step=17, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="black_oil_wells_saturated_3d_stone2", + description= + "Black oil well test using stone2 interp (3D displacement, hybrid FVM, 3-phase black-oil, 2 wells)", + partitions=[(1, 1, 1), (2, 2, 1)], + restart_step=12, + check_step=25, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/efemFractureMechanics/efemFractureMechanics.ats b/inputFiles/efemFractureMechanics/efemFractureMechanics.ats new file mode 100644 index 00000000000..8242a30cc6c --- /dev/null +++ b/inputFiles/efemFractureMechanics/efemFractureMechanics.ats @@ -0,0 +1,68 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, CurveCheckParameters, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {'atol': 1e-08, 'rtol': 4e-07} + +curvecheck_params = {} +curvecheck_params["filename"] = "displacementJump_embeddedFrac.hdf5" +curvecheck_params["tolerance"] = [1e-5] +curvecheck_params["script_instructions"] = [[ + "./scripts/sneddonCurveChecks.py", "sneddon_curve_check_solution", + "displacementJump" +]] +curvecheck_params["curves"] = "displacementJump" + +decks = [ + TestDeck( + name="Sneddon_embeddedFrac_smoke", + description="Smoke test for Sneddon's problem with horizontal fracture", + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="Sneddon_embeddedFrac_benchmark", + description="Sneddon's problem with horizontal fracture (uses MGR)", + partitions=((1, 1, 1), ), + restart_step=0, + check_step=1, + curvecheck_params=CurveCheckParameters(**curvecheck_params)), + TestDeck( + name="Sneddon_embeddedFrac_staticCondensation_smoke", + description="Sneddon with horizontal fracture usic static condensation", + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="Sneddon_embeddedFrac_staticCondensation_benchmark", + description="Sneddon with horizontal fracture usic static condensation", + partitions=((1, 1, 1), ), + restart_step=0, + check_step=1, + curvecheck_params=CurveCheckParameters(**curvecheck_params)), + TestDeck( + name="SneddonRotated_smoke", + description='Sneddon with inclined fracture', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="EmbFrac_Compression_Frictionless_smoke", + description='Single efem fracture under compression - frictionless', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(atol= 1e-06, rtol= 4e-07)), + TestDeck( + name="EmbFrac_Compression_CoulombFriction_smoke", + description='Single efem fracture under compression - Coulomb friction', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(atol= 1e-06, rtol= 4e-07)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/hydraulicFracturing/Hydrofracturing.ats b/inputFiles/hydraulicFracturing/Hydrofracturing.ats new file mode 100644 index 00000000000..ab32dc09f55 --- /dev/null +++ b/inputFiles/hydraulicFracturing/Hydrofracturing.ats @@ -0,0 +1,203 @@ +import copy +import geos_ats +from geos_ats.test_builder import generate_geos_tests, RestartcheckParameters, CurveCheckParameters, TestDeck + +# Define cases +kgd_viscosity_dominated = { + "name": "kgdViscosityDominated_smoke", + "description": "KGD fracture in viscosity-dominated regime", + "partitions": ((1, 1, 1), (2, 3, 1)), + "restart_step": 0, + "check_step": 1, + "tolerance": [2.3e-5, 27000.0], + "aperture_curve_method": "kgd_viscosity_dominated_aperture_curve", + "pressure_curve_method": "kgd_viscosity_dominated_pressure_curve" +} + +kgd_viscosity_dominated_poroelastic = { + "name": "kgdViscosityDominated_poroelastic_smoke", + "description": + "KGD fracture in viscosity-dominated regime in a poroelastic solid", + "partitions": ((1, 1, 1), (2, 3, 1)), + "restart_step": 0, + "check_step": 1 +} + +kgd_toughness_dominated = { + "name": "kgdToughnessDominated_smoke", + "description": "KGD fracture in toughness-dominated regime", + "partitions": ((1, 1, 1), (2, 3, 1)), + "restart_step": 0, + "check_step": 1, + "tolerance": [1e-5, 21000.0], + "aperture_curve_method": "kgd_toughness_dominated_aperture_curve", + "pressure_curve_method": "kgd_toughness_dominated_pressure_curve" +} + +kgd_toughness_dominated_poroelastic = { + "name": "kgdToughnessDominated_poroelastic_smoke", + "description": + "KGD fracture in toughness-dominated regime in a poroelastic solid", + "partitions": ((1, 1, 1), (2, 3, 1)), + "restart_step": 0, + "check_step": 1 +} + +kgd_validation = { + "name": "kgdValidation_smoke", + "description": "Validation example based on Rubin's experiment", + "partitions": ((1, 1, 1), (2, 2, 1)), + "restart_step": 0, + "check_step": 1 +} + +kgd_node_based_C3D6 = { + "name": "kgdNodeBased_C3D6_smoke", + "description": + "KGD hydrofracturing (node-based) problem with C3D6 element type", + "partitions": ((1, 1, 1), (3, 3, 1)), + "restart_step": 0, + "check_step": 1 +} + +kgd_edge_based_C3D6 = { + "name": "kgdEdgeBased_C3D6_smoke", + "description": + "KGD hydrofracturing (edge-based) problem with C3D6 element type", + "partitions": ((1, 1, 1), (3, 3, 1)), + "restart_step": 0, + "check_step": 1 +} + +heterogeneous_fracture = { + "name": "heterogeneousInSitu_smoke", + "description": "Single fracture within a heterogeneous reservoir", + "partitions": ((1, 1, 1), (2, 2, 1)), + "restart_step": 0, + "check_step": 4 +} + +penny_shaped_toughness_dominated = { + "name": "pennyShapedToughnessDominated_smoke", + "description": "Penny Shaped fracture in Toughness-dominated regime", + "partitions": ((1, 1, 1), (1, 3, 2)), + "restart_step": 0, + "check_step": 5, + "tolerance": [3.4e-6, 1e5], + "aperture_curve_method": "penny_shaped_toughness_dominated_aperture_curve", + "pressure_curve_method": "penny_shaped_toughness_dominated_pressure_curve" +} + +penny_shaped_toughness_dominated_poroelastic = { + "name": "pennyShapedToughnessDominated_poroelastic_smoke", + "description": + "Penny Shaped fracture in Toughness-dominated regime in a poroelastic solid", + "partitions": ((1, 1, 1), (1, 3, 2)), + "restart_step": 0, + "check_step": 5 +} + +penny_shaped_viscosity_dominated = { + "name": "pennyShapedViscosityDominated_smoke", + "description": "Penny Shaped fracture in Viscosity-dominated regime", + "partitions": ((1, 1, 1), (1, 2, 2)), + "restart_step": 0, + "check_step": 5, + "tolerance": [2.7e-3, 3e6], + "aperture_curve_method": "penny_shaped_viscosity_dominated_aperture_curve", + "pressure_curve_method": "penny_shaped_viscosity_dominated_pressure_curve" +} + +penny_shaped_viscosity_dominated_poroelastic = { + "name": "pennyShapedViscosityDominated_poroelastic_smoke", + "description": + "Penny Shaped fracture in Viscosity-dominated regime in a poroelastic solid", + "partitions": ((1, 1, 1), (1, 3, 2)), + "restart_step": 0, + "check_step": 5 +} + +pkn_viscosity_dominated = { + "name": "pknViscosityDominated_smoke", + "description": "PKN fracture in Viscosity-dominated regime", + "partitions": ((1, 1, 1), (1, 2, 2)), + "restart_step": 0, + "check_step": 5, + "tolerance": [1.8e-5, 2e5], + "aperture_curve_method": "pkn_viscosity_dominated_aperture_curve", + "pressure_curve_method": "pkn_viscosity_dominated_pressure_curve" +} + +pkn_viscosity_dominated_poroelastic = { + "name": "pknViscosityDominated_poroelastic_smoke", + "description": + "PKN fracture in Viscosity-dominated regime in a poroelastic solid", + "partitions": ((1, 1, 1), (1, 2, 2)), + "restart_step": 0, + "check_step": 5 +} + +sneddon = { + "name": "Sneddon_hydroFrac_smoke", + "description": "Sneddon type problem using a conforming discretization", + "partitions": ((1, 1, 1), (2, 2, 1)), + "restart_step": 1, + "check_step": 5 +} + +walsh_quarter_no_chombo = { + "name": "walshQuarterNoChombo_smoke", + "description": "Sneddon type problem using a conforming discretization", + "partitions": ((1, 1, 1), (2, 2, 2)), + "restart_step": 5, + "check_step": 5 +} + +decks = (kgd_viscosity_dominated, kgd_viscosity_dominated_poroelastic, + kgd_toughness_dominated, kgd_toughness_dominated_poroelastic, + kgd_validation, kgd_edge_based_C3D6, kgd_node_based_C3D6, + heterogeneous_fracture, penny_shaped_toughness_dominated, + penny_shaped_toughness_dominated_poroelastic, + penny_shaped_viscosity_dominated, + penny_shaped_viscosity_dominated_poroelastic, pkn_viscosity_dominated, + pkn_viscosity_dominated_poroelastic, sneddon, walsh_quarter_no_chombo) + +# Check parameters +restartcheck_params = RestartcheckParameters(atol=2.0E-4, rtol=1.0E-7) + +curvecheck_params_base = {} +curvecheck_params_base["filename"] = "hydrofracture_source_curves.hdf5" +curvecheck_params_base["tolerance"] = [1e-10, 1e-10] +curvecheck_params_base["script_instructions"] = [[ + "./scripts/hydrofractureCurveChecks.py", "tbd", "hydraulicAperture", + "source" +], ["./scripts/hydrofractureCurveChecks.py", "tbd", "pressure", "source"]] +curvecheck_params_base["curves"] = [["hydraulicAperture", "source"], + ["pressure", "source"]] + +deck_instances = [] +for deck in decks: + if ("aperture_curve_method" in deck) and ("pressure_curve_method" in deck): + curvecheck_params = copy.deepcopy(curvecheck_params_base) + curvecheck_params["script_instructions"][0][1] = deck[ + "aperture_curve_method"] + curvecheck_params["script_instructions"][1][1] = deck[ + "pressure_curve_method"] + + if ("tolerance" in deck): + curvecheck_params["tolerance"] = deck["tolerance"] + curvecheck_params = CurveCheckParameters(**curvecheck_params) + else: + curvecheck_params = None + + deck_instance = TestDeck(name=deck["name"], + description=deck["description"], + partitions=deck["partitions"], + restart_step=deck["restart_step"], + check_step=deck["check_step"], + restartcheck_params=restartcheck_params, + curvecheck_params=curvecheck_params) + + deck_instances.append(deck_instance) + +generate_geos_tests(deck_instances) diff --git a/inputFiles/hydraulicFracturing/hydrofractureSinglePhase2d.xml b/inputFiles/hydraulicFracturing/hydrofractureSinglePhase2d.xml index ad68c034e65..4b935534255 100644 --- a/inputFiles/hydraulicFracturing/hydrofractureSinglePhase2d.xml +++ b/inputFiles/hydraulicFracturing/hydrofractureSinglePhase2d.xml @@ -5,6 +5,7 @@ gravityVector="{ 0.0, 0.0, 0.0 }"> diff --git a/inputFiles/hydraulicFracturing/kgdToughnessDominated_base.xml b/inputFiles/hydraulicFracturing/kgdToughnessDominated_base.xml index f246ebf15ea..686921aa1f3 100644 --- a/inputFiles/hydraulicFracturing/kgdToughnessDominated_base.xml +++ b/inputFiles/hydraulicFracturing/kgdToughnessDominated_base.xml @@ -9,10 +9,11 @@ solidSolverName="lagsolve" flowSolverName="SinglePhaseFlow" surfaceGeneratorName="SurfaceGen" - logLevel="1" + logLevel="1" targetRegions="{ Fracture }" contactRelationName="fractureContact" - maxNumResolves="2"> + maxNumResolves="2" + useQuasiNewton="1"> - + \ No newline at end of file diff --git a/inputFiles/poromechanics/nonlinearAcceleration/validationCase/poroelasticCoupling_validation.ats b/inputFiles/poromechanics/nonlinearAcceleration/validationCase/poroelasticCoupling_validation.ats new file mode 100644 index 00000000000..ae39bd6c1d7 --- /dev/null +++ b/inputFiles/poromechanics/nonlinearAcceleration/validationCase/poroelasticCoupling_validation.ats @@ -0,0 +1,91 @@ +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + + +class Description(object): + + def __init__(self, description_builder, label, owner, isIndependent): + """ + The ATS description of the test case for poro-elastic coupling. + + description_builder: callable + A callable taking the partition tuple in argument and returning the TestCase description. + label: str + The label of the TestCase + owner: str + The owner of the TestCase + isIndependent: boolean + Is the TestCase independent from other cases? + """ + self.description_builder = description_builder + self.label = label + self.owner = owner + self.isIndependent = isIndependent + + +def _n_ranks(partition): + """ + Returns the number of ranks for a given MPI partitioning. + + partition: iterable + The MPI cartesian partitioning. + (x, y, z) ranks are supposed to be integers (or None which will be considered as 1). + """ + result = 1 + # I wanted to do `filter( None, partition )` with the `filter` builtin function + # but it has been rewritten by ATS. This is sooo wrong :( + for n in partition: + result *= n if n else 1 + return result + + +def _build_poro_elastic_coupling_case(deck, cycles, partitions, description, + restartcheck_params): + """ + Generic function that build the poro-elastic cases. + A first run is done and a second takes an intermediate timestep to validate the restart. + + deck: str + XML input file + cycles: pair of integers + The (intermediate_cycle, last_cycle). First being the restart initial timestep. + The second being the last simulated cycle. + partitions: Iterable of length-3 iterables + The (x, y, z) parallel partitioning. + `None` can be provided when nothing has to be done in the considered direction. + description: Description + Description of the TestCase + restartcheck_params: dict + Restart validation parameters (relative or absolute tolerance mainly). + test_name_builder: callable + A callable taking the partition tuple in argument and returning the test name. + """ + + # The simulation will generate data for two cycles + intermediate_cycle, last_cycle = cycles + + return TestDeck( + name=deck.split(".")[0], + description=description.description_builder, + partitions=partitions, + restart_step=intermediate_cycle, + check_step=last_cycle, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) + + +def _build_NonlinearAccelerationValidation_cases(): + description = Description("Nonlinear acceleration validation problem ", + "auto", "Sohail Waziri", True) + restartcheck_params = {"atol": 1.0e-4, "rtol": 2.0e-6} + return _build_poro_elastic_coupling_case("validationCase.xml", (3, 6), + ((1, 1, 1), ), description, + restartcheck_params) + + +def test_poro_elastic_coupling_cases(): + deck_instances = [_build_NonlinearAccelerationValidation_cases()] + + generate_geos_tests(deck_instances) + + +test_poro_elastic_coupling_cases() diff --git a/inputFiles/poromechanics/poroElasticCoupling.ats b/inputFiles/poromechanics/poroElasticCoupling.ats new file mode 100644 index 00000000000..6f3bf4afe32 --- /dev/null +++ b/inputFiles/poromechanics/poroElasticCoupling.ats @@ -0,0 +1,281 @@ +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + + +class Description(object): + + def __init__(self, description_builder, label, owner, isIndependent): + """ + The ATS description of the test case for poro-elastic coupling. + + description_builder: callable + A callable taking the partition tuple in argument and returning the TestCase description. + label: str + The label of the TestCase + owner: str + The owner of the TestCase + isIndependent: boolean + Is the TestCase independent from other cases? + """ + self.description_builder = description_builder + self.label = label + self.owner = owner + self.isIndependent = isIndependent + + +def _n_ranks(partition): + """ + Returns the number of ranks for a given MPI partitioning. + + partition: iterable + The MPI cartesian partitioning. + (x, y, z) ranks are supposed to be integers (or None which will be considered as 1). + """ + result = 1 + # I wanted to do `filter( None, partition )` with the `filter` builtin function + # but it has been rewritten by ATS. This is sooo wrong :( + for n in partition: + result *= n if n else 1 + return result + + +def _build_poro_elastic_coupling_case(deck, cycles, partitions, description, + restartcheck_params): + """ + Generic function that build the poro-elastic cases. + A first run is done and a second takes an intermediate timestep to validate the restart. + + deck: str + XML input file + cycles: pair of integers + The (intermediate_cycle, last_cycle). First being the restart initial timestep. + The second being the last simulated cycle. + partitions: Iterable of length-3 iterables + The (x, y, z) parallel partitioning. + `None` can be provided when nothing has to be done in the considered direction. + description: Description + Description of the TestCase + restartcheck_params: dict + Restart validation parameters (relative or absolute tolerance mainly). + test_name_builder: callable + A callable taking the partition tuple in argument and returning the test name. + """ + + # The simulation will generate data for two cycles + intermediate_cycle, last_cycle = cycles + + return TestDeck( + name=deck.split(".")[0], + description=description.description_builder, + partitions=partitions, + restart_step=intermediate_cycle, + check_step=last_cycle, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) + + +def _build_Terzaghi_cases(): + description = Description("Terzaghi's 1D Consolidation", "auto", + "Nicola Castelletto", True) + restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} + return _build_poro_elastic_coupling_case("PoroElastic_Terzaghi_smoke.xml", + (50, 91), + ((1, 1, 1), (2, 1, 1), (7, 1, 1)), + description, restartcheck_params) + + +def _build_Mandel_fim_cases(): + description = Description("Mandel's 2D Consolidation on ranks", "auto", + "Nicola Castelletto, Jian Huang", True) + restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} + return _build_poro_elastic_coupling_case( + "PoroElastic_Mandel_smoke_fim.xml", (2, 4), + ((1, 1, 1), (3, 1, 1), (3, 1, 2)), description, restartcheck_params) + + +def _build_Mandel_sequential_cases(): + description = Description("Sequential Mandel's 2D Consolidation ", "auto", + "Nicola Castelletto, Jian Huang", True) + restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} + return _build_poro_elastic_coupling_case( + "PoroElastic_Mandel_smoke_sequential.xml", (2, 4), + ((1, 1, 1), (3, 1, 1), (3, 1, 2)), description, restartcheck_params) + + +def _build_Mandel_prism6_cases(): + description = Description( + "Mandel's 2D Consolidation using VEM-MFD on a prism mesh ", "auto", + "Andrea Borio, Francois Hamon", True) + restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} + return _build_poro_elastic_coupling_case( + "PoroElastic_Mandel_prism6_smoke.xml", (2, 4), ((1, 1, 1), ), + description, restartcheck_params) + + +def _build_Deadoil_fim_cases(): + description = Description("Deadoil 3 phase poroelastic case ", "auto", + "N. Castelletto & M. Cusini", True) + restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} + return _build_poro_elastic_coupling_case( + "PoroElastic_deadoil_3ph_baker_2d_fim.xml", (0, 15), + ((1, 1, 1), (2, 1, 2)), description, restartcheck_params) + + +def _build_Deadoil_sequential_cases(): + description = Description("Sequential Deadoil 3 phase poroelastic case ", + "auto", "N. Castelletto & M. Cusini", True) + restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} + return _build_poro_elastic_coupling_case( + "PoroElastic_deadoil_3ph_baker_2d_sequential.xml", (0, 15), + ((1, 1, 1), (2, 1, 2)), description, restartcheck_params) + + +def _build_PoroElasticWell_cases(): + description = Description("PoroElastic wellbore problem ", "auto", + "Jian Huang", True) + restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} + return _build_poro_elastic_coupling_case("PoroElasticWellbore_smoke.xml", + (2, 8), ((1, 1, 1), (2, 2, 1)), + description, restartcheck_params) + + +def _build_PoroDruckerPragerWell_cases(): + description = Description("PoroDruckerPrager wellbore problem", "auto", + "Jian Huang", True) + restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} + return _build_poro_elastic_coupling_case( + "PoroDruckerPragerWellbore_smoke.xml", (2, 8), ((1, 1, 1), (2, 2, 1)), + description, restartcheck_params) + + +def _build_PoroDelftEggWell_cases(): + description = Description("PoroDelftEgg wellbore problem ", "auto", + "Jian Huang", True) + restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} + return _build_poro_elastic_coupling_case("PoroDelftEggWellbore_smoke.xml", + (2, 8), ((1, 1, 1), (2, 2, 1)), + description, restartcheck_params) + + +def _build_PoroModifiedCamClayWell_cases(): + description = Description("PoroModifiedCamClay wellbore problem ", "auto", + "Jian Huang", True) + restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} + return _build_poro_elastic_coupling_case( + "PoroModifiedCamClayWellbore_smoke.xml", (2, 8), + ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) + + +def _build_PoroImpermeableFault_cases(): + description = Description("Impermeable fault problem ", "auto", + "Jian Huang", True) + restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} + return _build_poro_elastic_coupling_case("impermeableFault_smoke.xml", + (0, 1), ((1, 1, 1), (2, 2, 1)), + description, restartcheck_params) + + +def _build_PoroPermeableFault_cases(): + description = Description("Permeable fault problem ", "auto", "Jian Huang", + True) + restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} + return _build_poro_elastic_coupling_case("permeableFault_smoke.xml", + (0, 1), ((1, 1, 1), (2, 2, 1)), + description, restartcheck_params) + + +def _build_PoroStaircaseSinglePhasePeacemanWell_fim_cases(): + description = Description( + "Staircase single-phase poroelastic problem with Peaceman wells ", + "auto", "Francois Hamon", True) + restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} + return _build_poro_elastic_coupling_case( + "PoroElastic_staircase_singlephase_3d_fim.xml", (6, 11), + ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) + + +def _build_PoroStaircaseSinglePhasePeacemanWell_sequential_cases(): + description = Description( + "Staircase single-phase poroelastic problem with Peaceman wells ", + "auto", "Francois Hamon", True) + restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} + return _build_poro_elastic_coupling_case( + "PoroElastic_staircase_singlephase_3d_sequential.xml", (6, 11), + ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) + + +def _build_PoroStaircaseCO2PeacemanWell_fim_cases(): + description = Description( + "Staircase CO2 poroelastic problem with Peaceman wells ", "auto", + "Francois Hamon", True) + restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} + return _build_poro_elastic_coupling_case( + "PoroElastic_staircase_co2_3d_fim.xml", (22, 33), + ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) + + +def _build_PoroStaircaseCO2PeacemanWell_sequential_cases(): + description = Description( + "Staircase CO2 poroelastic problem with Peaceman wells ", "auto", + "Francois Hamon", True) + restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} + return _build_poro_elastic_coupling_case( + "PoroElastic_staircase_co2_3d_sequential.xml", (22, 33), + ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) + + +def _build_PoroElasticPEBICO2FIM_cases(): + description = Description( + "CO2 poroelastic problem with VEM-TPFA (FIM) on a PEBI mesh ", "auto", + "Francois Hamon", True) + restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} + return _build_poro_elastic_coupling_case( + "PoroElastic_hybridHexPrism_co2_fim_3d.xml", (10, 20), + ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) + + +def _build_PoroElasticPEBICO2Sequential_cases(): + description = Description( + "CO2 poroelastic problem with VEM-TPFA (Sequential) on a PEBI mesh ", + "auto", "Francois Hamon", True) + restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} + return _build_poro_elastic_coupling_case( + "PoroElastic_hybridHexPrism_co2_sequential_3d.xml", (10, 20), + ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) + + +def _build_PoroElasticGravity_cases(): + description = Description("Single-phase poroelastic problem with gravity ", + "auto", "Francois Hamon", True) + restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} + return _build_poro_elastic_coupling_case("PoroElastic_gravity.xml", + (5, 10), ((1, 1, 1), (1, 1, 2)), + description, restartcheck_params) + + +def test_poro_elastic_coupling_cases(): + deck_instances = [ + _build_Terzaghi_cases(), + _build_Mandel_fim_cases(), + _build_Mandel_sequential_cases(), + _build_Mandel_prism6_cases(), + _build_Deadoil_fim_cases(), + _build_Deadoil_sequential_cases(), + _build_PoroElasticWell_cases(), + _build_PoroDruckerPragerWell_cases(), + _build_PoroDelftEggWell_cases(), + _build_PoroModifiedCamClayWell_cases(), + _build_PoroImpermeableFault_cases(), + _build_PoroPermeableFault_cases(), + _build_PoroStaircaseSinglePhasePeacemanWell_fim_cases(), + _build_PoroStaircaseSinglePhasePeacemanWell_sequential_cases(), + _build_PoroStaircaseCO2PeacemanWell_fim_cases(), + _build_PoroStaircaseCO2PeacemanWell_sequential_cases(), + _build_PoroElasticPEBICO2FIM_cases(), + _build_PoroElasticPEBICO2Sequential_cases(), + _build_PoroElasticGravity_cases() + ] + + generate_geos_tests(deck_instances) + + +test_poro_elastic_coupling_cases() diff --git a/inputFiles/poromechanics/viscoPlastic.ats b/inputFiles/poromechanics/viscoPlastic.ats new file mode 100644 index 00000000000..1f2a7db87fe --- /dev/null +++ b/inputFiles/poromechanics/viscoPlastic.ats @@ -0,0 +1,33 @@ +import geos_ats +from geos_ats.test_builder import generate_geos_tests, RestartcheckParameters, TestDeck + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-5 +restartcheck_params["rtol"] = 1.0E-5 + +partitions = ((1, 1, 1), (1, 1, 2)) + +decks = [ + TestDeck( + name="PoroViscoDruckerPrager_smoke", + description="PoroViscoDruckerPrager wellbore problem", + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=2, + check_step=6, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="PoroViscoExtendedDruckerPrager_smoke", + description="PoroViscoExtendedDruckerPrager wellbore problem", + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=2, + check_step=6, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck(name="PoroViscoModifiedCamClay_smoke", + description="PoroViscoModifiedCamClay wellbore problem", + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=2, + check_step=6, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/poromechanicsFractures/ExponentialDecayPermeability_conformingFracture_base.xml b/inputFiles/poromechanicsFractures/ExponentialDecayPermeability_conformingFracture_base.xml index 2393dc2477b..f8ddbc628cd 100644 --- a/inputFiles/poromechanicsFractures/ExponentialDecayPermeability_conformingFracture_base.xml +++ b/inputFiles/poromechanicsFractures/ExponentialDecayPermeability_conformingFracture_base.xml @@ -51,8 +51,7 @@ targetRegions="{ Domain, Fracture }"> + newtonMaxIter="8"/> diff --git a/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_faultSlip_base.xml b/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_faultSlip_base.xml index c45bcbdb0e5..5d7235c36f6 100644 --- a/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_faultSlip_base.xml +++ b/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_faultSlip_base.xml @@ -52,8 +52,7 @@ targetRegions="{ Domain, Fracture }"> + newtonMaxIter="8"/> @@ -262,4 +261,4 @@ - \ No newline at end of file + diff --git a/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_openingFrac_base.xml b/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_openingFrac_base.xml index 543423eac0f..6ffe3a235ab 100644 --- a/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_openingFrac_base.xml +++ b/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_openingFrac_base.xml @@ -51,8 +51,7 @@ targetRegions="{ Domain, Fracture }"> + newtonMaxIter="8"/> @@ -163,4 +162,4 @@ values="{ 0.0, 1.5 }"/> - \ No newline at end of file + diff --git a/inputFiles/poromechanicsFractures/poromechanicsFractures.ats b/inputFiles/poromechanicsFractures/poromechanicsFractures.ats new file mode 100644 index 00000000000..02dfc957812 --- /dev/null +++ b/inputFiles/poromechanicsFractures/poromechanicsFractures.ats @@ -0,0 +1,74 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {'atol': 1e-07, 'rtol': 4e-06} + +decks = [ + TestDeck( + name="SlipPermeability_pEDFM_smoke", + description='pEDFM slip dependent permeability case', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="WillisRichardsPermeability_efem-edfm_smoke", + description='WillisRichards Permeability model with EDFM', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=5, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="PoroElastic_conformingFracture_2d_openingFrac_horizontal_smoke", + description='PoroElastic conformingFracture 2d case', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="PoroElastic_conformingFracture_2d_openingFrac_vertical_smoke", + description='PoroElastic conformingFracture 2d case', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="PoroElastic_efem-edfm_pressurizedFrac_smoke", + description='poromechanics efem-edfm pressurized vertical frac', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="PoroElastic_efem-edfm_verticalFrac_smoke", + description='poromechanics efem-edfm vertical frac', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="PoroElastic_efem-edfm_inclinedFrac_smoke", + description='poromechanics efem-edfm inclined frac', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="ExponentialDecayPermeability_edfm_smoke", + description='Exponential Decay Permeability model with EDFM', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=5, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck(name="ExponentialDecayPermeability_conformingFracture_smoke", + description= + 'Exponential Decay Permeability model with conforming fracture', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=12, + restartcheck_params=RestartcheckParameters(atol=1e-05, + rtol=4e-04)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/proppant/proppantTransport.ats b/inputFiles/proppant/proppantTransport.ats new file mode 100644 index 00000000000..9a9a0b99872 --- /dev/null +++ b/inputFiles/proppant/proppantTransport.ats @@ -0,0 +1,34 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 1e-10 +restartcheck_params['rtol'] = 4e-09 + +decks = [ + TestDeck( + name="FlowProppantTransport2d_smoke", + description= + 'Coupled Single phase flow and proppant transport test (2D, compressible, gravity, fracture flow)', + partitions=((1, 1, 1), (1, 2, 2), (1, 3, 3)), + restart_step=5, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="FlowProppantBedTransport2d_smoke", + description= + 'Proppant transport and bed-build-up test (2D, proppant, fracture flow)', + partitions=((1, 1, 1), (1, 2, 1), (1, 3, 1)), + restart_step=20, + check_step=40, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck(name="ProppantSlotTest_smoke", + description='Slot test on proppant transport with slickwater', + partitions=((1, 1, 1), (1, 3, 1), (1, 3, 3)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/simplePDE/SimpleSolvers.ats b/inputFiles/simplePDE/SimpleSolvers.ats new file mode 100644 index 00000000000..8e5de718d0d --- /dev/null +++ b/inputFiles/simplePDE/SimpleSolvers.ats @@ -0,0 +1,58 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 1e-08 +restartcheck_params['rtol'] = 2e-10 + +decks = [ + TestDeck( + name="10x10x10Hex_LaplaceFEM_smoke", + description='Testing the Laplace solver with Finite Elements', + partitions=((1, 1, 1), (2, 2, 2), (3, 3, 3)), + restart_step=1, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="50x10x5Hex_LaplaceFEM_smoke", + description='Testing the Laplace solver with Finite Elements', + partitions=((1, 1, 1), (2, 2, 2), (3, 3, 2)), + restart_step=1, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="10x10x10Hex_LaplaceVEM_smoke", + description= + 'Testing the Laplace solver with the Virtual Element Method (hexahedral cells)', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=1, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="15x5x10Tets_LaplaceVEM_smoke", + description= + 'Testing the Laplace solver with the Virtual Element Method (tetrahedral cells)', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=1, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="10x5x15Wedges_LaplaceVEM_smoke", + description= + 'Testing the Laplace solver with the Virtual Element Method (wedges)', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=1, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="hybridHexPrism_LaplaceVEM_smoke", + description= + 'Testing the Laplace solver with the Virtual Element Method (hexahedra and prisms)', + partitions=((1, 1, 1), (3, 1, 1)), + restart_step=1, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/singlePhaseFlow/singlePhaseFlow.ats b/inputFiles/singlePhaseFlow/singlePhaseFlow.ats new file mode 100644 index 00000000000..2f0bb232b86 --- /dev/null +++ b/inputFiles/singlePhaseFlow/singlePhaseFlow.ats @@ -0,0 +1,81 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 1e-10 +restartcheck_params['rtol'] = 4e-09 + +decks = [ + TestDeck( + name="sourceFlux_1d", + description='Single phase flow test (1D, compressible, source flux)', + partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), + restart_step=10, + check_step=20, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="compressible_1d", + description='Single phase flow test (1D, compressible, Dirichlet BC)', + partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), + restart_step=10, + check_step=20, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="compressible_1d_2solids", + description= + 'Single phase flow test (1D, compressible, Dirichlet BC, 2 regions with different solids)', + partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), + restart_step=10, + check_step=20, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="incompressible_1d", + description= + 'Single phase flow test (1D, steady-state incompressible, Dirichlet BC)', + partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="incompressible_pebi3d", + description= + 'Single phase flow test (3D PEBI grid, steady-state incompressible, Dirichlet BC)', + partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="compressible_2d_2fluids", + description= + 'Single phase flow test (2D, compressible, Dirichlet BC, 2 regions with different fluids, trans multipliers)', + partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), + restart_step=10, + check_step=20, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="compressible_2d_2fluids_hybrid", + description= + 'Single phase flow test (2D, compressible, Dirichlet BC, 2 regions with different fluids, trans multipliers)', + partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), + restart_step=10, + check_step=20, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="sourceFlux_2d", + description='Single phase flow test (2D, incompressible)', + partitions=((1, 1, 1), (2, 2, 1), (3, 3, 1)), + restart_step=10, + check_step=20, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="staircase_3d", + description= + 'Single phase flow test (3D, compressible, gravity, face boundary conditions)', + partitions=((1, 1, 1), (2, 2, 2), (3, 3, 3)), + restart_step=10, + check_step=20, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/singlePhaseFlow/thermalSinglePhaseFlow.ats b/inputFiles/singlePhaseFlow/thermalSinglePhaseFlow.ats new file mode 100644 index 00000000000..532b1b1f989 --- /dev/null +++ b/inputFiles/singlePhaseFlow/thermalSinglePhaseFlow.ats @@ -0,0 +1,28 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 1e-06 +restartcheck_params['rtol'] = 1e-05 + +decks = [ + TestDeck( + name="thermalCompressible_2d_smoke", + description= + 'Pure thermal convection problem (2D, compressible, Dirichlet BC, thermal)', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=5, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="3D_10x10x10_thermalCompressible_smoke", + description= + 'Thermal single phase flow test (3D, compressible, Dirichlet BC, thermal)', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=6, + check_step=20, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/singlePhaseFlowFractures/fractureFlow_conforming_2d_vtk_input.xml b/inputFiles/singlePhaseFlowFractures/fractureFlow_conforming_2d_vtk_input.xml index 3d7d8d4f16c..4b77e706571 100644 --- a/inputFiles/singlePhaseFlowFractures/fractureFlow_conforming_2d_vtk_input.xml +++ b/inputFiles/singlePhaseFlowFractures/fractureFlow_conforming_2d_vtk_input.xml @@ -10,8 +10,7 @@ targetRegions="{ Region, Fracture }"> + newtonMaxIter="8"/> diff --git a/inputFiles/singlePhaseFlowFractures/fractureMatrixFlow_conforming_2d.xml b/inputFiles/singlePhaseFlowFractures/fractureMatrixFlow_conforming_2d.xml index 13d0917680a..1bc3e6b5c81 100644 --- a/inputFiles/singlePhaseFlowFractures/fractureMatrixFlow_conforming_2d.xml +++ b/inputFiles/singlePhaseFlowFractures/fractureMatrixFlow_conforming_2d.xml @@ -10,8 +10,7 @@ targetRegions="{ Region2, Fracture }"> + newtonMaxIter="8"/> diff --git a/inputFiles/singlePhaseFlowFractures/impermeableFault_conforming_base.xml b/inputFiles/singlePhaseFlowFractures/impermeableFault_conforming_base.xml index be9fc697ee2..3b4c2b58957 100644 --- a/inputFiles/singlePhaseFlowFractures/impermeableFault_conforming_base.xml +++ b/inputFiles/singlePhaseFlowFractures/impermeableFault_conforming_base.xml @@ -10,8 +10,7 @@ targetRegions="{ RockMatrix, Fracture }"> + newtonMaxIter="8"/> diff --git a/inputFiles/singlePhaseFlowFractures/singlePhaseFlowFractures.ats b/inputFiles/singlePhaseFlowFractures/singlePhaseFlowFractures.ats new file mode 100644 index 00000000000..392c4217da4 --- /dev/null +++ b/inputFiles/singlePhaseFlowFractures/singlePhaseFlowFractures.ats @@ -0,0 +1,86 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 1e-10 +restartcheck_params['rtol'] = 4e-09 + +decks = [ + TestDeck( + name="fractureFlow_conforming_2d", + description= + 'Single phase flow test (2D, compressible, fracture flow, conforming)', + partitions=((1, 1, 1), (2, 1, 1), (4, 1, 1)), + restart_step=5, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="fractureJunctionFlow_conforming_2d", + description= + 'Single phase flow test (2D, compressible, intersecting fracture flow, conforming)', + partitions=((1, 1, 1), ), + restart_step=25, + check_step=50, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="fractureMatrixFlow_conforming_2d", + description= + 'Single phase flow test (2D, compressible, fracture/matrix flow)', + partitions=((1, 1, 1), (2, 2, 1), (3, 3, 1)), + restart_step=25, + check_step=50, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="fractureMatrixFlow_edfm_horizontalFrac_smoke", + description= + 'Single phase flow test (3D, incompressible, fracture/matrix flow, EDFM)', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=1, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="fractureMatrixFlow_edfm_inclinedFrac_smoke", + description= + 'Single phase flow test (3D, incompressible, fracture/matrix flow, EDFM)', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=1, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="fractureMatrixFlow_pedfm_impermeableFracture_smoke", + description='SinglePhase flow with pedfm', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="fractureMatrixFlowWithGravity_edfm_verticalFrac_smoke", + description='SinglePhase flow with edfm frac with gravity', + partitions=((1, 1, 1), (1, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="fractureMatrixFlowWithGravity_conforming_2d_smoke", + description='SinglePhase flow with conforming frac with gravity', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="fractureFlowWithGravity_conforming_2d_smoke", + description='SinglePhase flow in conforming frac with gravity', + partitions=((1, 1, 1), (1, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck(name="impermeableFault_conforming_smoke", + description='impermeable conforming fault', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/singlePhaseWell/singlePhaseWell.ats b/inputFiles/singlePhaseWell/singlePhaseWell.ats new file mode 100644 index 00000000000..45bd8377dc5 --- /dev/null +++ b/inputFiles/singlePhaseWell/singlePhaseWell.ats @@ -0,0 +1,58 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 1e-09 +restartcheck_params['rtol'] = 4e-08 + +decks = [ + TestDeck( + name="compressible_single_phase_wells_1d", + description='Single phase well test (1D, compressible, 2 wells)', + partitions=((1, 1, 1), (2, 1, 1)), + restart_step=5, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="compressible_single_phase_wells_hybrid_1d", + description= + 'Single phase well test (1D, hybrid FVM, compressible, 2 wells)', + partitions=((1, 1, 1), (2, 1, 1)), + restart_step=5, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="incompressible_single_phase_wells_2d", + description='Single phase flow test (2D, incompressible, 3 wells)', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=5, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="incompressible_single_phase_wells_hybrid_2d", + description= + 'Single phase flow test (2D, hybrid FVM, incompressible, 3 wells)', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=5, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="staircase_single_phase_wells_3d", + description= + 'Single phase flow test (3D staircase, compressible, 2 wells)', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=5, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="staircase_single_phase_wells_hybrid_3d", + description= + 'Single phase flow test (3D staircase, hybrid FVM, compressible, 2 wells)', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=5, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/SSLE.ats b/inputFiles/solidMechanics/SSLE.ats new file mode 100644 index 00000000000..38b590c519d --- /dev/null +++ b/inputFiles/solidMechanics/SSLE.ats @@ -0,0 +1,19 @@ +import geos_ats +from geos_ats.test_builder import generate_geos_tests, RestartcheckParameters, TestDeck + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-10 +restartcheck_params["rtol"] = 2.0E-13 + +partitions = ((1, 1, 1), (2, 2, 2), (3, 3, 3)) + +decks = [ + TestDeck(name="sedov_ssle_smoke", + description="Test the small strain linear elastic solver", + partitions=partitions, + restart_step=50, + check_step=100, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/anisotropic.ats b/inputFiles/solidMechanics/anisotropic.ats new file mode 100644 index 00000000000..a6afc13b144 --- /dev/null +++ b/inputFiles/solidMechanics/anisotropic.ats @@ -0,0 +1,36 @@ +import geos_ats +from geos_ats.test_builder import generate_geos_tests, TestDeck, RestartcheckParameters + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-5 +restartcheck_params["rtol"] = 1.0E-5 + +partitions = ((1, 1, 1), (2, 2, 1)) + +decks = [ + TestDeck( + name="elasticHollowCylinder_isotropic_smoke", + description= + "Test the elastic hollow cylinder with an isotropic material", + partitions=partitions, + restart_step=0, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="elasticHollowCylinder_transverseIsotropic_smoke", + description= + "Test the elastic hollow cylinder with a transverse isotropic material", + partitions=partitions, + restart_step=0, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck(name="elasticHollowCylinder_orthotropic_smoke", + description= + "Test the elastic hollow cylinder with an orthotropic material", + partitions=partitions, + restart_step=0, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/beamBending.ats b/inputFiles/solidMechanics/beamBending.ats new file mode 100644 index 00000000000..352a2ae5d3f --- /dev/null +++ b/inputFiles/solidMechanics/beamBending.ats @@ -0,0 +1,38 @@ +import geos_ats +from geos_ats.test_builder import RestartcheckParameters, CurveCheckParameters, TestDeck, generate_geos_tests + +restartcheck_params = RestartcheckParameters(atol=1.0E-3, rtol=1.0E-7) + +curvecheck_params = CurveCheckParameters( + filename='displacement_history.hdf5', + tolerance=[0.0002], + script_instructions=[[ + './beamBending_curve.py', 'curve', 'totalDisplacement', 'trace' + ]], + curves=[['totalDisplacement', 'trace']]) + +partitions = ((1, 1, 1), (2, 2, 2)) + +decks = [ + TestDeck(name="beamBending_smoke", + description="Tests beam bending.", + partitions=partitions, + restart_step=0, + check_step=1, + restartcheck_params=restartcheck_params, + curvecheck_params=curvecheck_params), + TestDeck(name="beamBending_vem_smoke", + description="Tests beam bending applying Virtual Elements.", + partitions=partitions, + restart_step=0, + check_step=1, + restartcheck_params=restartcheck_params), + TestDeck(name="beamBending_hybridHexPrism_smoke", + description="Tests beam bending on general polyhedral mesh.", + partitions=partitions, + restart_step=0, + check_step=1, + restartcheck_params=restartcheck_params) +] + +generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/gravity.ats b/inputFiles/solidMechanics/gravity.ats new file mode 100644 index 00000000000..0da665c416e --- /dev/null +++ b/inputFiles/solidMechanics/gravity.ats @@ -0,0 +1,20 @@ +import geos_ats +from geos_ats.test_builder import generate_geos_tests, TestDeck, RestartcheckParameters + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-5 +restartcheck_params["rtol"] = 1.0E-5 + +partitions = ((1, 1, 1), (1, 1, 2)) + +decks = [ + TestDeck( + name="gravity", + description="Test the gravity application in solid mechanics solver", + partitions=partitions, + restart_step=1, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/plasticCubeReset.ats b/inputFiles/solidMechanics/plasticCubeReset.ats new file mode 100644 index 00000000000..9efdc1738c5 --- /dev/null +++ b/inputFiles/solidMechanics/plasticCubeReset.ats @@ -0,0 +1,19 @@ +import geos_ats +from geos_ats.test_builder import generate_geos_tests, RestartcheckParameters, TestDeck + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-5 +restartcheck_params["rtol"] = 1.0E-5 + +partitions = ((1, 1, 1), (1, 1, 2)) + +decks = [ + TestDeck(name="plasticCubeReset", + description="Test the initialization step of for solid mechanics", + partitions=partitions, + restart_step=4, + check_step=7, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/plasticWellbore.ats b/inputFiles/solidMechanics/plasticWellbore.ats new file mode 100644 index 00000000000..4c285454533 --- /dev/null +++ b/inputFiles/solidMechanics/plasticWellbore.ats @@ -0,0 +1,34 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 1e-06 +restartcheck_params['rtol'] = 0.0001 + +decks = [ + TestDeck( + name="ModifiedCamClayWellbore_smoke", + description='test of wellbore mesh generation and simple loading', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=1, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="ExtendedDruckerPragerWellbore_smoke", + description= + 'test of wellbore with ExtendedDruckerPrager material and simple loading', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=1, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck(name="DruckerPragerWellbore_smoke", + description= + 'test of wellbore with DruckerPrager material and simple loading', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=1, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/sedov.ats b/inputFiles/solidMechanics/sedov.ats new file mode 100644 index 00000000000..07d74a25999 --- /dev/null +++ b/inputFiles/solidMechanics/sedov.ats @@ -0,0 +1,27 @@ +import geos_ats +from geos_ats.test_builder import generate_geos_tests, RestartcheckParameters, TestDeck, CurveCheckParameters + +restartcheck_params = {} +restartcheck_params["atol"] = 2.0E-10 +restartcheck_params["rtol"] = 2.0E-13 + +curvecheck_params = {} +curvecheck_params['filename'] = 'veloc_history.hdf5' +curvecheck_params['tolerance'] = 1e-10 +curvecheck_params['time_units'] = 'milliseconds' +curvecheck_params['curves'] = [['velocity', 'source']] + +partitions = ((1, 1, 1), (2, 2, 2), (3, 3, 3)) + +decks = [ + TestDeck( + name="sedov_finiteStrain_smoke", + description="Test the basic sedov problem and restart capabilities", + partitions=partitions, + restart_step=50, + check_step=100, + restartcheck_params=RestartcheckParameters(**restartcheck_params), + curvecheck_params=CurveCheckParameters(**curvecheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/viscoPlastic.ats b/inputFiles/solidMechanics/viscoPlastic.ats new file mode 100644 index 00000000000..e61a1ac8a92 --- /dev/null +++ b/inputFiles/solidMechanics/viscoPlastic.ats @@ -0,0 +1,20 @@ +import geos_ats +from geos_ats.test_builder import generate_geos_tests, RestartcheckParameters, TestDeck + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-5 +restartcheck_params["rtol"] = 1.0E-5 + +partitions = ((1, 1, 1), (1, 1, 2)) + +decks = [ + TestDeck( + name="viscoExtendedDruckerPrager_relaxation_smoke", + description="Relaxation test with viscoplastic solver", + partitions=((1, 1, 1), (1, 1, 2)), + restart_step=0, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), +] + +generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/wellbore.ats b/inputFiles/solidMechanics/wellbore.ats new file mode 100644 index 00000000000..f858b683f22 --- /dev/null +++ b/inputFiles/solidMechanics/wellbore.ats @@ -0,0 +1,19 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 0.0001 +restartcheck_params['rtol'] = 0.0001 + +decks = [ + TestDeck( + name="KirschProblem_smoke", + description= + 'test of wellbore mesh generation and open well with simple loading', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), +] +generate_geos_tests(decks) diff --git a/inputFiles/surfaceGeneration/SurfaceGenerator.ats b/inputFiles/surfaceGeneration/SurfaceGenerator.ats new file mode 100644 index 00000000000..58a7bdce307 --- /dev/null +++ b/inputFiles/surfaceGeneration/SurfaceGenerator.ats @@ -0,0 +1,46 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params["atol"] = 1.0E-5 +restartcheck_params["rtol"] = 2.0E-10 + +partitions = ((1, 1, 1), (2, 2, 2)) + +decks = [ + TestDeck( + name="SurfaceGenerator", + description= + "Test the basic surface generator problem and restart capabilities.", + partitions=partitions, + restart_step=2, + check_step=3, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="DryFrac_StaticPenny_PrismElem", + description= + "Testing the SIF calculation (node-based) for a penny-shaped fracture", + partitions=partitions, + restart_step=0, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="DryFrac_ThreeNodesPinched_HorizontalFrac", + description= + "Testing the SIF calculation (node-based) under three nodes pinched scenario (fracture plane parallel to model boundary)", + partitions=partitions, + restart_step=0, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="DryFrac_ThreeNodesPinched_SlantFrac", + description= + "Testing the SIF calculation (node-based) under three nodes pinched scenario (fracture plane for an angle of 45 degree with model boundary)", + partitions=partitions, + restart_step=0, + check_step=2, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/thermalMultiphaseFlow/thermalMultiphaseFlow.ats b/inputFiles/thermalMultiphaseFlow/thermalMultiphaseFlow.ats new file mode 100644 index 00000000000..63f0a1eb79e --- /dev/null +++ b/inputFiles/thermalMultiphaseFlow/thermalMultiphaseFlow.ats @@ -0,0 +1,28 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 1e-06 +restartcheck_params['rtol'] = 1e-05 + +decks = [ + TestDeck( + name="co2_thermal_2d", + description= + 'Thermal compositional co2-brine flow test (2D co2 injection, 2-phase co2-brine, Brooks-Corey relperm curves, thermal)', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=9, + check_step=11, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="co2_thermal_obl_3d", + description= + 'Smoke test for a co2-brine test (3D displacement, 2-phase co2-brine, thermal, OBL)', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=14, + check_step=19, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/thermalSinglePhaseFlowFractures/fractureMatrixThermalFlow_conforming_base.xml b/inputFiles/thermalSinglePhaseFlowFractures/fractureMatrixThermalFlow_conforming_base.xml index 6a3c2e68250..6d25802c993 100644 --- a/inputFiles/thermalSinglePhaseFlowFractures/fractureMatrixThermalFlow_conforming_base.xml +++ b/inputFiles/thermalSinglePhaseFlowFractures/fractureMatrixThermalFlow_conforming_base.xml @@ -17,7 +17,7 @@ + maxAllowedResidualNorm="1e15"/> diff --git a/inputFiles/thermalSinglePhaseFlowFractures/thermalSinglePhaseFlowFractures.ats b/inputFiles/thermalSinglePhaseFlowFractures/thermalSinglePhaseFlowFractures.ats new file mode 100644 index 00000000000..ab39f64db8c --- /dev/null +++ b/inputFiles/thermalSinglePhaseFlowFractures/thermalSinglePhaseFlowFractures.ats @@ -0,0 +1,26 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 1e-06 +restartcheck_params['rtol'] = 1e-05 + +decks = [ + TestDeck( + name="fractureMatrixThermalFlow_edfm_smoke", + description='Thermal single-phase flow with an edfm fracture.', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="fractureMatrixThermalFlow_conforming_smoke", + description='Thermal single-phase flow with a conforming fracture', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/thermoPoromechanics/thermoPoromechanics.ats b/inputFiles/thermoPoromechanics/thermoPoromechanics.ats new file mode 100644 index 00000000000..561fe62ba25 --- /dev/null +++ b/inputFiles/thermoPoromechanics/thermoPoromechanics.ats @@ -0,0 +1,32 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {'atol': 1e-06, 'rtol': 4e-06} + +decks = [ + TestDeck( + name="ThermoPoroElastic_consolidation_smoke_fim", + description='1D thermo poro elastic case consolidation problem (FIM)', + partitions=((1, 1, 1), (1, 2, 1)), + restart_step=633, + check_step=683, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="ThermoPoroElastic_consolidation_smoke_sequential", + description= + '1D thermo poro elastic case consolidation problem (sequential)', + partitions=((1, 1, 1), (1, 2, 1)), + restart_step=633, + check_step=683, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="ThermoPoroElastic_staircase_co2_smoke", + description='Staircase thermo-poro-mechanics with cold CO2 injection', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=22, + check_step=33, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/thermoPoromechanicsFractures/thermoPoromechanicsFractures.ats b/inputFiles/thermoPoromechanicsFractures/thermoPoromechanicsFractures.ats new file mode 100644 index 00000000000..cca95c6e68e --- /dev/null +++ b/inputFiles/thermoPoromechanicsFractures/thermoPoromechanicsFractures.ats @@ -0,0 +1,23 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {'atol': 1e-06, 'rtol': 4e-06} + +decks = [ + TestDeck( + name="ThermoPoroElastic_efem-edfm_verticalFrac_smoke", + description='Thermoporoelastic case with an embeded fracture', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck(name="ThermoPoroElastic_conforming_smoke", + description='Thermoporoelastic case with a conforming fracture', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/wavePropagation/AcousticElasticSEM.ats b/inputFiles/wavePropagation/AcousticElasticSEM.ats new file mode 100644 index 00000000000..642390f5b7d --- /dev/null +++ b/inputFiles/wavePropagation/AcousticElasticSEM.ats @@ -0,0 +1,20 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 0.0001 +restartcheck_params['rtol'] = 2e-05 + +decks = [ + TestDeck( + name="acouselas3D_Q2_abc_smoke", + description= + 'Acoustic Elastic solver (pseudo 2D), third-order FE, absorbing BC', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=10, + check_step=20, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), +] + +generate_geos_tests(decks) diff --git a/inputFiles/wavePropagation/AcousticFirstOrderSEM.ats b/inputFiles/wavePropagation/AcousticFirstOrderSEM.ats new file mode 100644 index 00000000000..4eafac6e6bb --- /dev/null +++ b/inputFiles/wavePropagation/AcousticFirstOrderSEM.ats @@ -0,0 +1,44 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 0.0001 +restartcheck_params['rtol'] = 2e-05 + +decks = [ + TestDeck( + name="acous3D_firstOrder_abc_smoke", + description= + 'Acoustic wave solver, first-order FE, first order formulation, absorbing BC', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="acous3D_firstOrder_fs_smoke", + description= + 'Acoustic wave solver, first-order FE, first order formulation, absorbing BC on the sides, free surface BC at the top', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="acous3D_Q3_firstOrder_abc_smoke", + description= + 'Acoustic wave solver, third-order FE, first order formulation, absorbing BC', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="acous3D_Q3_firstOrder_fs_smoke", + description= + 'Acoustic wave solver, third-order FE, first order formulation, absorbing BC on the sides, free surface BC at the top', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/wavePropagation/AcousticSEM.ats b/inputFiles/wavePropagation/AcousticSEM.ats new file mode 100644 index 00000000000..006d7958153 --- /dev/null +++ b/inputFiles/wavePropagation/AcousticSEM.ats @@ -0,0 +1,58 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 0.0001 +restartcheck_params['rtol'] = 2e-05 + +decks = [ + TestDeck( + name="acous3D_abc_smoke", + description='Acoustic wave solver, first-order FE, absorbing BC', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="acous3D_abc_fs_smoke", + description= + 'Acoustic wave solver, first-order FE, absorbing BC on the sides, free surface BC at the top', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="acous3D_pml_smoke", + description= + 'Acoustic wave solver, first-order FE, perfectly matched layer BC', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=20, + check_step=40, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="acous3D_vti_smoke", + description= + 'Acoustic wave solver, first-order FE, vertical transverse isotropic', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="acous3D_Q3_abc_smoke", + description='Acoustic wave solver, third-order FE, absorbing BC', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="acous3D_Q3_abc_fs_smoke", + description= + 'Acoustic wave solver, third-order FE, absorbing BC on the sides, free surface BC at the top', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/wavePropagation/ElasticFirstOrderSEM.ats b/inputFiles/wavePropagation/ElasticFirstOrderSEM.ats new file mode 100644 index 00000000000..dfad33d399f --- /dev/null +++ b/inputFiles/wavePropagation/ElasticFirstOrderSEM.ats @@ -0,0 +1,44 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 0.0001 +restartcheck_params['rtol'] = 2e-05 + +decks = [ + TestDeck( + name="elas3D_firstOrder_abc_smoke", + description= + 'Elastic wave solver, first-order FE, first order formulation, absorbing BC', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="elas3D_firstOrder_fs_smoke", + description= + 'Elastic wave solver, first-order FE, first order formulation, absorbing BC on the sides, free surface BC at the top', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="elas3D_Q3_firstOrder_abc_smoke", + description= + 'Elastic wave solver, third-order FE, first order formulation, absorbing BC', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="elas3D_Q3_firstOrder_fs_smoke", + description= + 'Elastic wave solver, third-order FE, first order formulation, absorbing BC on the sides, free surface BC at the top', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/wavePropagation/ElasticSEM.ats b/inputFiles/wavePropagation/ElasticSEM.ats new file mode 100644 index 00000000000..7ea1adb9713 --- /dev/null +++ b/inputFiles/wavePropagation/ElasticSEM.ats @@ -0,0 +1,42 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 0.0001 +restartcheck_params['rtol'] = 2e-05 + +decks = [ + TestDeck( + name="elas3D_abc_smoke", + description='Elastic wave solver, first-order FE, absorbing BC', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="elas3D_abc_fs_smoke", + description= + 'Elastic wave solver, first-order FE, absorbing BC on the sides, free surface BC at the top', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="elas3D_Q3_abc_smoke", + description='Elastic wave solver, third-order FE, absorbing BC', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="elas3D_Q3_abc_fs_smoke", + description= + 'Elastic wave solver, third-order FE, absorbing BC on the sides, free surface BC at the top', + partitions=((1, 1, 1), (2, 2, 2)), + restart_step=100, + check_step=200, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] + +generate_geos_tests(decks) diff --git a/inputFiles/wellbore/thermoPoromechanics_wellbore.ats b/inputFiles/wellbore/thermoPoromechanics_wellbore.ats new file mode 100644 index 00000000000..4541246b809 --- /dev/null +++ b/inputFiles/wellbore/thermoPoromechanics_wellbore.ats @@ -0,0 +1,18 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {'atol': 1e-06, 'rtol': 4e-06} + +decks = [ + TestDeck( + name="CasedThermoElasticWellbore_smoke", + description= + 'Near wellbore thermo elastic case simulated as a single-phase poromechanics case', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=5, + check_step=10, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), +] + +generate_geos_tests(decks) diff --git a/inputFiles/wellbore/wellboreMesh.ats b/inputFiles/wellbore/wellboreMesh.ats new file mode 100644 index 00000000000..23086646dd8 --- /dev/null +++ b/inputFiles/wellbore/wellboreMesh.ats @@ -0,0 +1,67 @@ +import os +import geos_ats +from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests + +restartcheck_params = {} +restartcheck_params['atol'] = 0.0001 +restartcheck_params['rtol'] = 0.0001 + +decks = [ + TestDeck( + name="CasedElasticWellbore_smoke", + description='test of cased wellbore mesh generation and simple loading', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="CasedElasticWellbore_ImperfectInterfaces_smoke", + description= + 'test of cased wellbore mesh generation and contact mechanics', + partitions=[ + (1, 1, 1), + ], + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="CasedThermoElasticWellbore_ImperfectInterfaces_smoke", + description= + 'test the debonding of cased wellbore with thermoelastic solver', + partitions=[(1, 1, 1),], + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="DeviatedElasticWellbore_smoke", + description= + 'test a deviated wellbore problem with open hole completion', + partitions=((1, 1, 1), (3, 1, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="DeviatedPoroElasticWellbore_Injection_smoke", + description= + 'a deviated wellbore subjected to a fluid pressure loaded at wellbore wall', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="DeviatedPoroElasticWellbore_Drilling_smoke", + description= + 'drilling a deviated poro-elastic wellbore with in-situ stresses', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)), + TestDeck( + name="ThermoPoroElasticWellbore_smoke", + description='single-phase thermo-hydro-mechanical wellbore', + partitions=((1, 1, 1), (2, 2, 1)), + restart_step=0, + check_step=1, + restartcheck_params=RestartcheckParameters(**restartcheck_params)) +] +generate_geos_tests(decks) diff --git a/integratedTests b/integratedTests index 511253b330d..8f03e8e1c8d 160000 --- a/integratedTests +++ b/integratedTests @@ -1 +1 @@ -Subproject commit 511253b330d2cce7ebbd0e65e317f72b6883b7bc +Subproject commit 8f03e8e1c8df683135db5968f244336fbf20c96e diff --git a/scripts/ci_build_and_test_in_container.sh b/scripts/ci_build_and_test_in_container.sh index f74a0795b48..c292755a605 100755 --- a/scripts/ci_build_and_test_in_container.sh +++ b/scripts/ci_build_and_test_in_container.sh @@ -236,7 +236,7 @@ else if [[ ! -z "${DATA_BASENAME_WE}" ]]; then # Here we pack the installation. # The `--transform` parameter provides consistency between the tarball name and the unpacked folder. - or_die tar czf ${DATA_EXCHANGE_DIR}/${DATA_BASENAME_WE}.tar.gz --directory=${GEOSX_TPL_DIR}/.. --transform "s/^./${DATA_BASENAME_WE}/" . + or_die tar czf ${DATA_EXCHANGE_DIR}/${DATA_BASENAME_WE}.tar.gz --directory=${GEOSX_TPL_DIR}/.. --transform "s|^./|${DATA_BASENAME_WE}/|" . fi fi @@ -295,4 +295,4 @@ if [[ ! -z "${INTEGRATED_TEST_EXIT_STATUS+x}" ]]; then else echo "Exiting the build process with exit status 0." exit 0 -fi +fi \ No newline at end of file diff --git a/scripts/setupPythonEnvironment.bash b/scripts/setupPythonEnvironment.bash index 8732edf3130..edd5c91296f 100755 --- a/scripts/setupPythonEnvironment.bash +++ b/scripts/setupPythonEnvironment.bash @@ -8,6 +8,7 @@ BIN_DIR= PACKAGE_DIR= TMP_CLONE_DIR= PIP_CMD="pip --disable-pip-version-check" +PACKAGE_BRANCH=main declare -a TARGET_PACKAGES=("geosx_mesh_tools_package" @@ -51,6 +52,10 @@ case $key in PACKAGE_DIR="$2" shift # past argument ;; + -r|--python-pkg-branch) + PACKAGE_BRANCH="$2" + shift # past argument + ;; -v|--verbose) VERBOSE=true shift # past argument @@ -61,6 +66,7 @@ case $key in echo "-p/--python-target \"Target parent python bin\"" echo "-b/--bin-dir \"Directory to link new scripts\"" echo "-d/--pkg-dir \"Directory containing target python packages\"" + echo "-t/--tool-branch \"Target branch for geosPythonPackages (default=main) \"" echo "-v/--verbose \"Increase verbosity level\"" echo "" exit @@ -95,10 +101,10 @@ fi echo "Checking for python packages..." if [[ -z "${PACKAGE_DIR}" ]] then - echo "Cloning the GEOS python package repository..." + echo "Cloning the GEOS python package repository (branch=$PACKAGE_BRANCH)..." TMP_CLONE_DIR=$(mktemp -d) PACKAGE_DIR=$TMP_CLONE_DIR/geosPythonPackages - git clone --depth 1 --branch main --single-branch https://github.com/GEOS-DEV/geosPythonPackages.git $PACKAGE_DIR + git clone --depth 1 --branch $PACKAGE_BRANCH --single-branch https://github.com/GEOS-DEV/geosPythonPackages.git $PACKAGE_DIR elif [ ! -d "${PACKAGE_DIR}/geosx_xml_tools_package" ] then echo "The specified package directory does not contain the expected targets." @@ -117,10 +123,10 @@ do # Try installing the package if $VERBOSE - INSTALL_MSG=$($PYTHON_TARGET -m $PIP_CMD install $PACKAGE_DIR/$p) + INSTALL_MSG=$($PYTHON_TARGET -m $PIP_CMD install --upgrade $PACKAGE_DIR/$p) INSTALL_RC=$? then - INSTALL_MSG=$($PYTHON_TARGET -m $PIP_CMD install $PACKAGE_DIR/$p 2>&1) + INSTALL_MSG=$($PYTHON_TARGET -m $PIP_CMD install --upgrade $PACKAGE_DIR/$p 2>&1) INSTALL_RC=$? fi diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7041bf98ff1..7fb71e7cbe9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -256,19 +256,25 @@ if ( Python3_EXECUTABLE ) message(WARNING "The \"virtualenv\" package was not found in the target python environment (${Python3_EXECUTABLE}). This package may be required to build PYGEOSX or the python development environment.") endif() - # Build targets + # Check for the requested branch of geosPythonPackages (used for testing) + if( NOT GEOS_PYTHON_PACKAGES_BRANCH ) + set(GEOS_PYTHON_PACKAGES_BRANCH "main" CACHE STRING "" FORCE) + endif() + set( GEOSX_PYTHON_TOOLS_BINS "${CMAKE_BINARY_DIR}/bin/preprocess_xml" "${CMAKE_BINARY_DIR}/bin/format_xml" ) add_custom_command( OUTPUT ${GEOSX_PYTHON_TOOLS_BINS} - COMMAND bash ${CMAKE_SOURCE_DIR}/../scripts/setupPythonEnvironment.bash -p ${PYTHON_POST_EXECUTABLE} -b ${CMAKE_BINARY_DIR}/bin - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - ) + COMMAND bash ${CMAKE_SOURCE_DIR}/../scripts/setupPythonEnvironment.bash -p ${PYTHON_POST_EXECUTABLE} -b ${CMAKE_BINARY_DIR}/bin --python-pkg-branch ${GEOS_PYTHON_PACKAGES_BRANCH} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) add_custom_target( geosx_python_tools DEPENDS ${GEOSX_PYTHON_TOOLS_BINS} ) + add_custom_target( geosx_python_tools_clean + COMMAND rm ${GEOSX_PYTHON_TOOLS_BINS} ) + add_custom_target( geosx_python_tools_test COMMAND ${CMAKE_BINARY_DIR}/python/geosx/bin/test_geosx_xml_tools COMMAND rm -r ${CMAKE_BINARY_DIR}/python/geosx_xml_tools_tests* @@ -291,12 +297,81 @@ endif() ################################ # Add integratedTests ################################ -if( EXISTS "${CMAKE_SOURCE_DIR}/../integratedTests/CMakeLists.txt") - add_subdirectory( ${CMAKE_SOURCE_DIR}/../integratedTests integratedTests ) -else() - message( "Could not find the integratedTests submodule" ) +if (NOT DEFINED ENABLE_ATS) + set( ENABLE_ATS true CACHE BOOL "") +endif() + + +if ( ENABLE_ATS ) + if (NOT DEFINED ATS_WORKING_DIR) + message( WARNING "ATS_WORKING_DIR is not defined (required for integrated testing system)" ) + message( WARNING "Defaulting to ${CMAKE_BINARY_DIR}/integratedTests/workingDir" ) + set( ATS_WORKING_DIR "${CMAKE_BINARY_DIR}/integratedTests/workingDir" CACHE PATH "") + endif() + + if (NOT DEFINED ATS_BASELINE_DIR) + message( WARNING "ATS_BASELINE_DIR is not defined (required for integrated testing system)" ) + message( WARNING "Defaulting to ${CMAKE_SOURCE_DIR}/../integratedTests" ) + set( ATS_BASELINE_DIR "${CMAKE_SOURCE_DIR}/../integratedTests" CACHE PATH "") + endif() + + if (NOT Python3_EXECUTABLE) + message( FATAL_ERROR "An appropriate version of python was not found (required for integrated testing system). Try setting Python3_ROOT_DIR and/or Python3_EXECUTABLE in your host config." ) + endif() + + # Setup testing + set( ATS_SCRIPT + "${CMAKE_BINARY_DIR}/integratedTests/geos_ats.sh" + ) + + add_custom_command( OUTPUT ${ATS_SCRIPT} + COMMAND ${CMAKE_BINARY_DIR}/bin/setup_ats_environment ${CMAKE_SOURCE_DIR}/.. ${CMAKE_BINARY_DIR} ${ATS_BASELINE_DIR} ${ATS_WORKING_DIR} ${ATS_ARGUMENTS} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + + add_custom_target( ats_environment + DEPENDS geosx_python_tools + DEPENDS ${ATS_SCRIPT} ) + + add_custom_target( ats_run + COMMAND ${CMAKE_BINARY_DIR}/integratedTests/geos_ats.sh + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPENDS ats_environment + ) + + add_custom_target( ats_clean + COMMAND ${CMAKE_BINARY_DIR}/integratedTests/geos_ats.sh -a veryclean + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPENDS ats_environment + ) + + add_custom_target( ats_rebaseline + COMMAND ${CMAKE_BINARY_DIR}/integratedTests/geos_ats.sh -a rebaseline + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPENDS ats_environment + ) + + add_custom_target( ats_rebaseline_failed + COMMAND ${CMAKE_BINARY_DIR}/integratedTests/geos_ats.sh -a rebaselinefailed + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPENDS ats_environment + ) +endif() + + +# Python formatting +if ( ENABLE_YAPF ) + set( integrated_tests_python_sources ) + file( GLOB_RECURSE integrated_tests_python_sources "${CMAKE_SOURCE_DIR}/../inputFiles/*.py" ) + set( integrated_tests_ats_sources ) + file( GLOB_RECURSE integrated_tests_ats_sources "${CMAKE_SOURCE_DIR}/../inputFiles/*.ats" ) + + blt_add_code_checks( PREFIX integrated_tests_yapf_style + SOURCES ${integrated_tests_python_sources} ${integrated_tests_ats_sources} ${CMAKE_SOURCE_DIR}/coreComponents/dummy.cpp + YAPF_CFG_FILE ${PROJECT_SOURCE_DIR}/yapf.cfg ) endif() + # the following adds a `build_test` CMake target such that running `$ make build_test test` # builds the unit tests before running them get_property( tmp GLOBAL PROPERTY geos_tests_exe_list ) diff --git a/src/coreComponents/finiteElement/elementFormulations/Qk_Hexahedron_Lagrange_GaussLobatto.hpp b/src/coreComponents/finiteElement/elementFormulations/Qk_Hexahedron_Lagrange_GaussLobatto.hpp index e8cead63acf..8b1c73c1b85 100644 --- a/src/coreComponents/finiteElement/elementFormulations/Qk_Hexahedron_Lagrange_GaussLobatto.hpp +++ b/src/coreComponents/finiteElement/elementFormulations/Qk_Hexahedron_Lagrange_GaussLobatto.hpp @@ -1320,7 +1320,7 @@ computeFirstOrderStiffnessTerm( localIndex const q, const real64 w02 = w * gia * gjc; func( ibc, abj, w02 * detJ, J, 0, 2 ); func( abj, ibc, w02 * detJ, J, 2, 0 ); - const real64 w01 = w * gia * gjc; + const real64 w01 = w * gia * gjb; func( ibc, ajc, w01 * detJ, J, 0, 1 ); func( ajc, ibc, w01 * detJ, J, 1, 0 ); } diff --git a/src/coreComponents/physicsSolvers/CMakeLists.txt b/src/coreComponents/physicsSolvers/CMakeLists.txt index def7de24ea1..2dc8662f05c 100644 --- a/src/coreComponents/physicsSolvers/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/CMakeLists.txt @@ -130,17 +130,20 @@ set( physicsSolvers_headers surfaceGeneration/kernels/surfaceGenerationKernelsHelpers.hpp wavePropagation/WaveSolverBase.hpp wavePropagation/WaveSolverUtils.hpp - wavePropagation/WaveSolverBaseFields.hpp + wavePropagation/AcousticFields.hpp wavePropagation/AcousticWaveEquationSEM.hpp wavePropagation/AcousticWaveEquationSEMKernel.hpp + wavePropagation/ElasticFields.hpp wavePropagation/ElasticWaveEquationSEM.hpp wavePropagation/ElasticWaveEquationSEMKernel.hpp wavePropagation/ElasticFirstOrderWaveEquationSEM.hpp wavePropagation/ElasticFirstOrderWaveEquationSEMKernel.hpp wavePropagation/AcousticFirstOrderWaveEquationSEM.hpp wavePropagation/AcousticFirstOrderWaveEquationSEMKernel.hpp + wavePropagation/AcousticVTIFields.hpp wavePropagation/AcousticVTIWaveEquationSEM.hpp wavePropagation/AcousticVTIWaveEquationSEMKernel.hpp + wavePropagation/AcoustoElasticFields.hpp wavePropagation/AcousticElasticWaveEquationSEM.hpp wavePropagation/AcousticElasticWaveEquationSEMKernel.hpp ) diff --git a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp index af316a23062..05946aa15b8 100644 --- a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp +++ b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp @@ -13,6 +13,7 @@ */ #include "NonlinearSolverParameters.hpp" +#include "common/Logger.hpp" namespace geos { @@ -54,6 +55,11 @@ NonlinearSolverParameters::NonlinearSolverParameters( string const & name, setDescription( "Line search cut factor. For instance, a value of 0.5 will result in the effective application of" " the last solution by a factor of (0.5, 0.25, 0.125, ...)" ); + registerWrapper( viewKeysStruct::lineSearchStartingIterationString(), &m_lineSearchStartingIteration ). + setApplyDefaultValue( 0 ). + setInputFlag( InputFlags::OPTIONAL ). + setDescription( "Iteration when line search starts." ); + registerWrapper( viewKeysStruct::normTypeString(), &m_normType ). setInputFlag( InputFlags::FALSE ). setApplyDefaultValue( solverBaseKernels::NormType::Linf ). @@ -166,6 +172,39 @@ void NonlinearSolverParameters::postProcessInput() GEOS_ERROR_IF_LE_MSG( m_timeStepDecreaseIterLimit, m_timeStepIncreaseIterLimit, getWrapperDataContext( viewKeysStruct::timeStepIncreaseIterLimString() ) << ": should be smaller than " << viewKeysStruct::timeStepDecreaseIterLimString() ); + + if( getLogLevel() > 0 ) + { + GEOS_LOG_RANK_0( "Nonlinear solver parameters:" ); + GEOS_LOG_RANK_0( GEOS_FMT( " Line search action = {}", EnumStrings< LineSearchAction >::toString( m_lineSearchAction ) ) ); + if( m_lineSearchAction != LineSearchAction::None ) + { + GEOS_LOG_RANK_0( GEOS_FMT( " Line search interpolation type = {}", EnumStrings< LineSearchInterpolationType >::toString( m_lineSearchInterpType ) ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Line search maximum number of cuts = {}", m_lineSearchMaxCuts ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Line search cut factor = {}", m_lineSearchCutFactor ) ); + } + GEOS_LOG_RANK_0( GEOS_FMT( " Norm type (flow solver) = {}", EnumStrings< solverBaseKernels::NormType >::toString( m_normType ) ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Minimum residual normalizer = {}", m_minNormalizer ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Convergence tolerance = {}", m_newtonTol ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Maximum iterations = {}", m_maxIterNewton ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Minimum iterations = {}", m_minIterNewton ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Maximum allowed residual norm = {}", m_maxAllowedResidualNorm ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Allow non-converged = {}", m_allowNonConverged ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Time step decrease iterations limit = {}", m_timeStepDecreaseIterLimit ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Time step increase iterations limit = {}", m_timeStepIncreaseIterLimit ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Time step decrease factor = {}", m_timeStepDecreaseFactor ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Time step increase factor = {}", m_timeStepDecreaseFactor ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Time step cut factor = {}", m_timeStepCutFactor ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Maximum time step cuts = {}", m_maxTimeStepCuts ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Maximum sub time steps = {}", m_maxSubSteps ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Maximum number of configuration attempts = {}", m_maxNumConfigurationAttempts ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Coupling type = {}", EnumStrings< CouplingType >::toString( m_couplingType ) ) ); + if( m_couplingType == CouplingType::Sequential ) + { + GEOS_LOG_RANK_0( GEOS_FMT( " Sequential convergence criterion = {}", EnumStrings< SequentialConvergenceCriterion >::toString( m_sequentialConvergenceCriterion ) ) ); + GEOS_LOG_RANK_0( GEOS_FMT( " Subcycling = {}", m_subcyclingOption ) ); + } + } } diff --git a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.hpp b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.hpp index 2a41b03d7d4..9f9f93da0fc 100644 --- a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.hpp +++ b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.hpp @@ -63,6 +63,7 @@ class NonlinearSolverParameters : public dataRepository::Group m_lineSearchInterpType = params.m_lineSearchInterpType; m_lineSearchMaxCuts = params.m_lineSearchMaxCuts; m_lineSearchCutFactor = params.m_lineSearchCutFactor; + m_lineSearchStartingIteration = params.m_lineSearchStartingIteration; m_newtonTol = params.m_newtonTol; m_maxIterNewton = params.m_maxIterNewton; @@ -101,6 +102,7 @@ class NonlinearSolverParameters : public dataRepository::Group static constexpr char const * lineSearchMaxCutsString() { return "lineSearchMaxCuts"; } static constexpr char const * lineSearchCutFactorString() { return "lineSearchCutFactor"; } static constexpr char const * lineSearchInterpolationTypeString() { return "lineSearchInterpolationType"; } + static constexpr char const * lineSearchStartingIterationString() { return "lineSearchStartingIteration"; } static constexpr char const * normTypeString() { return "normType"; } static constexpr char const * minNormalizerString() { return "minNormalizer"; } @@ -165,7 +167,8 @@ class NonlinearSolverParameters : public dataRepository::Group enum class SequentialConvergenceCriterion : integer { ResidualNorm, ///< convergence achieved when the residual drops below a given norm - NumberOfNonlinearIterations ///< convergence achieved when the subproblems convergence is achieved in less than minNewtonIteration + NumberOfNonlinearIterations, ///< convergence achieved when the subproblems convergence is achieved in less than minNewtonIteration + SolutionIncrements ///< convergence achieved when the solution increments are small enough }; /** @@ -246,7 +249,7 @@ class NonlinearSolverParameters : public dataRepository::Group /// Flag to apply a line search. LineSearchAction m_lineSearchAction; - /// Flag to pick the type of linesearch + /// Flag to pick the type of line search LineSearchInterpolationType m_lineSearchInterpType; /// The maximum number of line search cuts to attempt. @@ -255,6 +258,9 @@ class NonlinearSolverParameters : public dataRepository::Group /// The reduction factor for each line search cut. real64 m_lineSearchCutFactor; + /// Iteration when line search starts + integer m_lineSearchStartingIteration; + /// Norm used to check the nonlinear loop convergence solverBaseKernels::NormType m_normType; @@ -337,7 +343,8 @@ ENUM_STRINGS( NonlinearSolverParameters::CouplingType, ENUM_STRINGS( NonlinearSolverParameters::SequentialConvergenceCriterion, "ResidualNorm", - "NumberOfNonlinearIterations" ); + "NumberOfNonlinearIterations", + "SolutionIncrements" ); ENUM_STRINGS( NonlinearSolverParameters::NonlinearAccelerationType, "None", diff --git a/src/coreComponents/physicsSolvers/SolverBase.cpp b/src/coreComponents/physicsSolvers/SolverBase.cpp index 5ea5eea1754..59d5e29a041 100644 --- a/src/coreComponents/physicsSolvers/SolverBase.cpp +++ b/src/coreComponents/physicsSolvers/SolverBase.cpp @@ -268,7 +268,16 @@ bool SolverBase::execute( real64 const time_n, if( dtRemaining > 0.0 ) { nextDt = setNextDt( dtAccepted, domain ); - nextDt = std::min( nextDt, dtRemaining ); + if( nextDt < dtRemaining ) + { + // better to do two equal steps than one big and one small (even potentially tiny) + if( nextDt * 2 > dtRemaining ) + nextDt = dtRemaining / 2; + } + else + { + nextDt = dtRemaining; + } } if( getLogLevel() >= 1 && dtRemaining > 0.0 ) @@ -298,15 +307,13 @@ real64 SolverBase::setNextDt( real64 const & currentDt, integer const iterIncreaseLimit = m_nonlinearSolverParameters.timeStepIncreaseIterLimit(); if( nextDtNewton > currentDt ) { - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( - "{}: Newton solver converged in less than {} iterations, time-step required will be increased.", - getName(), iterIncreaseLimit )); + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( "{}: solver converged in less than {} iterations, time-step required will be increased.", + getName(), iterIncreaseLimit ) ); } else if( nextDtNewton < currentDt ) { - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( - "{}: Newton solver converged in more than {} iterations, time-step required will be decreased.", - getName(), iterDecreaseLimit )); + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( "{}: solver converged in more than {} iterations, time-step required will be decreased.", + getName(), iterDecreaseLimit ) ); } } else // time step size decided based on state change @@ -473,6 +480,8 @@ bool SolverBase::lineSearch( real64 const & time_n, real64 const scaleFactor, real64 & lastResidual ) { + Timer timer( m_timers["line search"] ); + integer const maxNumberLineSearchCuts = m_nonlinearSolverParameters.m_lineSearchMaxCuts; real64 const lineSearchCutFactor = m_nonlinearSolverParameters.m_lineSearchCutFactor; @@ -490,55 +499,39 @@ bool SolverBase::lineSearch( real64 const & time_n, // main loop for the line search. for( integer lineSearchIteration = 0; lineSearchIteration < maxNumberLineSearchCuts; ++lineSearchIteration ) { - { - Timer timer( m_timers["apply solution"] ); - - // cut the scale factor by half. This means that the scale factors will - // have values of -0.5, -0.25, -0.125, ... - localScaleFactor *= lineSearchCutFactor; - cumulativeScale += localScaleFactor; - - if( !checkSystemSolution( domain, dofManager, solution.values(), localScaleFactor ) ) - { - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " Line search {}, solution check failed", lineSearchIteration ) ); - continue; - } - - applySystemSolution( dofManager, solution.values(), localScaleFactor, dt, domain ); - } + // cut the scale factor by half. This means that the scale factors will + // have values of -0.5, -0.25, -0.125, ... + localScaleFactor *= lineSearchCutFactor; + cumulativeScale += localScaleFactor; + if( !checkSystemSolution( domain, dofManager, solution.values(), localScaleFactor ) ) { - Timer timer( m_timers["update state"] ); - - // update non-primary variables (constitutive models) - updateState( domain ); + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " Line search {}, solution check failed", lineSearchIteration ) ); + continue; } - { - Timer timer( m_timers["assemble"] ); + applySystemSolution( dofManager, solution.values(), localScaleFactor, dt, domain ); - // re-assemble system - localMatrix.zero(); - rhs.zero(); + // update non-primary variables (constitutive models) + updateState( domain ); - arrayView1d< real64 > const localRhs = rhs.open(); - assembleSystem( time_n, dt, domain, dofManager, localMatrix, localRhs ); - applyBoundaryConditions( time_n, dt, domain, dofManager, localMatrix, localRhs ); - rhs.close(); - } + // re-assemble system + localMatrix.zero(); + rhs.zero(); + + arrayView1d< real64 > const localRhs = rhs.open(); + assembleSystem( time_n, dt, domain, dofManager, localMatrix, localRhs ); + applyBoundaryConditions( time_n, dt, domain, dofManager, localMatrix, localRhs ); + rhs.close(); if( getLogLevel() >= 1 && logger::internal::rank==0 ) { std::cout << GEOS_FMT( " Line search @ {:0.3f}: ", cumulativeScale ); } - { - Timer timer( m_timers["convergence check"] ); - - // get residual norm - residualNorm = calculateResidualNorm( time_n, dt, domain, dofManager, rhs.values() ); - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " ( R ) = ( {:4.2e} )", residualNorm ) ); - } + // get residual norm + residualNorm = calculateResidualNorm( time_n, dt, domain, dofManager, rhs.values() ); + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " ( R ) = ( {:4.2e} )", residualNorm ) ); // if the residual norm is less than the last residual, we can proceed to the // solution step @@ -565,6 +558,8 @@ bool SolverBase::lineSearchWithParabolicInterpolation( real64 const & time_n, real64 & lastResidual, real64 & residualNormT ) { + Timer timer( m_timers["line search"] ); + bool lineSearchSuccess = true; integer const maxNumberLineSearchCuts = m_nonlinearSolverParameters.m_lineSearchMaxCuts; @@ -586,70 +581,55 @@ bool SolverBase::lineSearchWithParabolicInterpolation( real64 const & time_n, while( residualNormT >= (1.0 - alpha*localScaleFactor)*residualNorm0 ) { + real64 const previousLocalScaleFactor = localScaleFactor; + // Apply the three point parabolic model + if( lineSearchIteration == 0 ) { - Timer timer( m_timers["apply solution"] ); - - real64 const previousLocalScaleFactor = localScaleFactor; - // Apply the three point parabolic model - if( lineSearchIteration == 0 ) - { - localScaleFactor *= sigma1; - } - else - { - localScaleFactor = interpolation::parabolicInterpolationThreePoints( lamc, lamm, ff0, ffT, ffm ); - } - - // Update x; keep the books on lambda - real64 const deltaLocalScaleFactor = ( localScaleFactor - previousLocalScaleFactor ); - cumulativeScale += deltaLocalScaleFactor; + localScaleFactor *= sigma1; + } + else + { + localScaleFactor = interpolation::parabolicInterpolationThreePoints( lamc, lamm, ff0, ffT, ffm ); + } - if( !checkSystemSolution( domain, dofManager, solution.values(), deltaLocalScaleFactor ) ) - { - GEOS_LOG_LEVEL_RANK_0( 1, " Line search " << lineSearchIteration << ", solution check failed" ); - continue; - } + // Update x; keep the books on lambda + real64 const deltaLocalScaleFactor = ( localScaleFactor - previousLocalScaleFactor ); + cumulativeScale += deltaLocalScaleFactor; - applySystemSolution( dofManager, solution.values(), deltaLocalScaleFactor, dt, domain ); + if( !checkSystemSolution( domain, dofManager, solution.values(), deltaLocalScaleFactor ) ) + { + GEOS_LOG_LEVEL_RANK_0( 1, " Line search " << lineSearchIteration << ", solution check failed" ); + continue; } - { - Timer timer( m_timers["update state"] ); + applySystemSolution( dofManager, solution.values(), deltaLocalScaleFactor, dt, domain ); - updateState( domain ); - } + updateState( domain ); lamm = lamc; lamc = localScaleFactor; // Keep the books on the function norms - { - Timer timer( m_timers["assemble"] ); + // re-assemble system + // TODO: add a flag to avoid a completely useless Jacobian computation: rhs is enough + localMatrix.zero(); + rhs.zero(); - // re-assemble system - // TODO: add a flag to avoid a completely useless Jacobian computation: rhs is enough - localMatrix.zero(); - rhs.zero(); - - arrayView1d< real64 > const localRhs = rhs.open(); - assembleSystem( time_n, dt, domain, dofManager, localMatrix, localRhs ); - applyBoundaryConditions( time_n, dt, domain, dofManager, localMatrix, localRhs ); - rhs.close(); - } + arrayView1d< real64 > const localRhs = rhs.open(); + assembleSystem( time_n, dt, domain, dofManager, localMatrix, localRhs ); + applyBoundaryConditions( time_n, dt, domain, dofManager, localMatrix, localRhs ); + rhs.close(); if( getLogLevel() >= 1 && logger::internal::rank==0 ) { std::cout << GEOS_FMT( " Line search @ {:0.3f}: ", cumulativeScale ); } - { - Timer timer( m_timers["convergence check"] ); + // get residual norm + residualNormT = calculateResidualNorm( time_n, dt, domain, dofManager, rhs.values() ); + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " ( R ) = ( {:4.2e} )", residualNormT ) ); - // get residual norm - residualNormT = calculateResidualNorm( time_n, dt, domain, dofManager, rhs.values() ); - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " ( R ) = ( {:4.2e} )", residualNormT ) ); - } ffm = ffT; ffT = residualNormT*residualNormT; lineSearchIteration += 1; @@ -895,13 +875,6 @@ bool SolverBase::solveNonlinearSystem( real64 const & time_n, GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " ( R ) = ( {:4.2e} )", residualNorm ) ); } - if( newtonIter > 0 ) - { - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " Last LinSolve(iter,res) = ( {:3}, {:4.2e} )", - m_linearSolverResult.numIterations, - m_linearSolverResult.residualReduction ) ); - } - // if the residual norm is less than the Newton tolerance we denote that we have // converged and break from the Newton loop immediately. if( residualNorm < newtonTol && newtonIter >= minNewtonIter ) @@ -924,7 +897,7 @@ bool SolverBase::solveNonlinearSystem( real64 const & time_n, // do line search in case residual has increased if( m_nonlinearSolverParameters.m_lineSearchAction != NonlinearSolverParameters::LineSearchAction::None - && residualNorm > lastResidual ) + && residualNorm > lastResidual && newtonIter >= m_nonlinearSolverParameters.m_lineSearchStartingIteration ) { bool lineSearchSuccess = false; if( m_nonlinearSolverParameters.m_lineSearchInterpType == NonlinearSolverParameters::LineSearchInterpolationType::Linear ) @@ -1246,6 +1219,10 @@ void SolverBase::solveLinearSystem( DofManager const & dofManager, m_linearSolverResult = solver->result(); } + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " Last LinSolve(iter,res) = ( {:3}, {:4.2e} )", + m_linearSolverResult.numIterations, + m_linearSolverResult.residualReduction ) ); + if( params.stopIfError ) { GEOS_ERROR_IF( m_linearSolverResult.breakdown(), getDataContext() << ": Linear solution breakdown -> simulation STOP" ); @@ -1370,6 +1347,18 @@ R1Tensor const SolverBase::gravityVector() const return rval; } +bool SolverBase::checkSequentialSolutionIncrements( DomainPartition & GEOS_UNUSED_PARAM( domain ) ) const +{ + // default behavior - assume converged + return true; +} + +void SolverBase::saveSequentialIterationState( DomainPartition & GEOS_UNUSED_PARAM( domain ) ) const +{ + // up to specific solver to save what is needed + GEOS_ERROR( "Call to SolverBase::saveSequentialIterationState. Method should be overloaded by the solver" ); +} + #if defined(GEOSX_USE_PYGEOSX) PyTypeObject * SolverBase::getPythonType() const { return python::getPySolverType(); } diff --git a/src/coreComponents/physicsSolvers/SolverBase.hpp b/src/coreComponents/physicsSolvers/SolverBase.hpp index f6174cd9b57..b3390f828e6 100644 --- a/src/coreComponents/physicsSolvers/SolverBase.hpp +++ b/src/coreComponents/physicsSolvers/SolverBase.hpp @@ -627,6 +627,10 @@ class SolverBase : public ExecutableGroup */ R1Tensor const gravityVector() const; + virtual bool checkSequentialSolutionIncrements( DomainPartition & domain ) const; + + virtual void saveSequentialIterationState( DomainPartition & domain ) const; + /** * @brief accessor for the linear solver parameters. * @return the linear solver parameter list diff --git a/src/coreComponents/physicsSolvers/contact/LagrangianContactSolver.cpp b/src/coreComponents/physicsSolvers/contact/LagrangianContactSolver.cpp index 9d81e6801ab..7d3717e570a 100644 --- a/src/coreComponents/physicsSolvers/contact/LagrangianContactSolver.cpp +++ b/src/coreComponents/physicsSolvers/contact/LagrangianContactSolver.cpp @@ -1741,6 +1741,8 @@ void LagrangianContactSolver::applySystemSolution( DofManager const & dofManager void LagrangianContactSolver::updateState( DomainPartition & domain ) { + GEOS_MARK_FUNCTION; + computeFaceDisplacementJump( domain ); } diff --git a/src/coreComponents/physicsSolvers/contact/SolidMechanicsEmbeddedFractures.cpp b/src/coreComponents/physicsSolvers/contact/SolidMechanicsEmbeddedFractures.cpp index 54aac882187..98ef126ae4c 100644 --- a/src/coreComponents/physicsSolvers/contact/SolidMechanicsEmbeddedFractures.cpp +++ b/src/coreComponents/physicsSolvers/contact/SolidMechanicsEmbeddedFractures.cpp @@ -731,6 +731,7 @@ void SolidMechanicsEmbeddedFractures::updateJump( DofManager const & dofManager, void SolidMechanicsEmbeddedFractures::updateState( DomainPartition & domain ) { + GEOS_MARK_FUNCTION; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, MeshLevel & mesh, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index b20d1018c4f..b1a01eec570 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -150,6 +150,11 @@ CompositionalMultiphaseBase::CompositionalMultiphaseBase( const string & name, setApplyDefaultValue( isothermalCompositionalMultiphaseBaseKernels::minDensForDivision ). setDescription( "Minimum allowed global component density" ); + this->registerWrapper( viewKeyStruct::maxSequentialCompDensChangeString(), &m_maxSequentialCompDensChange ). + setSizedFromParent( 0 ). + setInputFlag( InputFlags::OPTIONAL ). + setApplyDefaultValue( 1.0 ). + setDescription( "Maximum (absolute) component density change in a sequential iteration, used for outer loop convergence check" ); } void CompositionalMultiphaseBase::postProcessInput() @@ -321,26 +326,6 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ); MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); - subRegion.registerField< pressure >( getName() ); - subRegion.registerField< pressure_n >( getName() ); - subRegion.registerField< initialPressure >( getName() ); - subRegion.registerField< deltaPressure >( getName() ); // for reporting/stats purposes - subRegion.registerField< bcPressure >( getName() ); // needed for the application of boundary conditions - if( m_isFixedStressPoromechanicsUpdate ) - { - subRegion.registerField< pressure_k >( getName() ); // needed for the fixed-stress porosity update - } - - // these fields are always registered for the evaluation of the fluid properties - subRegion.registerField< temperature >( getName() ); - subRegion.registerField< temperature_n >( getName() ); - subRegion.registerField< initialTemperature >( getName() ); - subRegion.registerField< bcTemperature >( getName() ); // needed for the application of boundary conditions - if( m_isFixedStressPoromechanicsUpdate ) - { - subRegion.registerField< temperature_k >( getName() ); // needed for the fixed-stress porosity update - } - subRegion.registerField< pressureScalingFactor >( getName() ); subRegion.registerField< temperatureScalingFactor >( getName() ); subRegion.registerField< globalCompDensityScalingFactor >( getName() ); @@ -353,6 +338,12 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) reference().resizeDimension< 1 >( m_numComponents ); subRegion.registerField< globalCompDensity_n >( getName() ). reference().resizeDimension< 1 >( m_numComponents ); + if( m_isFixedStressPoromechanicsUpdate ) + { + subRegion.registerField< globalCompDensity_k >( getName() ). + setDimLabels( 1, fluid.componentNames() ). + reference().resizeDimension< 1 >( m_numComponents ); + } subRegion.registerField< globalCompFraction >( getName() ). setDimLabels( 1, fluid.componentNames() ). @@ -632,8 +623,6 @@ real64 CompositionalMultiphaseBase::updatePhaseVolumeFraction( ObjectManagerBase dataGroup, fluid ); - maxDeltaPhaseVolFrac = MpiWrapper::max( maxDeltaPhaseVolFrac ); - return maxDeltaPhaseVolFrac; } @@ -1254,14 +1243,6 @@ CompositionalMultiphaseBase::implicitStepSetup( real64 const & GEOS_UNUSED_PARAM [&]( localIndex const, auto & subRegion ) { - arrayView1d< real64 const > const & pres = - subRegion.template getField< fields::flow::pressure >(); - arrayView1d< real64 const > const & initPres = - subRegion.template getField< fields::flow::initialPressure >(); - arrayView1d< real64 > const & deltaPres = - subRegion.template getField< fields::flow::deltaPressure >(); - isothermalCompositionalMultiphaseBaseKernels::StatisticsKernel:: - saveDeltaPressure< parallelDevicePolicy<> >( subRegion.size(), pres, initPres, deltaPres ); saveConvergedState( subRegion ); // update porosity, permeability @@ -2314,6 +2295,12 @@ void CompositionalMultiphaseBase::implicitStepComplete( real64 const & time, [&]( localIndex const, ElementSubRegionBase & subRegion ) { + // update deltaPressure + arrayView1d< real64 const > const pres = subRegion.getField< fields::flow::pressure >(); + arrayView1d< real64 const > const initPres = subRegion.getField< fields::flow::initialPressure >(); + arrayView1d< real64 > const deltaPres = subRegion.getField< fields::flow::deltaPressure >(); + isothermalCompositionalMultiphaseBaseKernels::StatisticsKernel:: + saveDeltaPressure< parallelDevicePolicy<> >( subRegion.size(), pres, initPres, deltaPres ); // Step 2: save the converged fluid state string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ); @@ -2398,21 +2385,22 @@ void CompositionalMultiphaseBase::saveConvergedState( ElementSubRegionBase & sub arrayView2d< real64, compflow::USD_COMP > const & compDens_n = subRegion.template getField< fields::flow::globalCompDensity_n >(); compDens_n.setValues< parallelDevicePolicy<> >( compDens ); + if( m_isFixedStressPoromechanicsUpdate ) + { + arrayView2d< real64, compflow::USD_COMP > const & compDens_k = + subRegion.template getField< fields::flow::globalCompDensity_k >(); + compDens_k.setValues< parallelDevicePolicy<> >( compDens ); + } } -void CompositionalMultiphaseBase::saveIterationState( DomainPartition & domain ) const +void CompositionalMultiphaseBase::saveSequentialIterationState( DomainPartition & domain ) const { - FlowSolverBase::saveIterationState( domain ); + FlowSolverBase::saveSequentialIterationState( domain ); } -void CompositionalMultiphaseBase::saveIterationState( ElementSubRegionBase & subRegion ) const +void CompositionalMultiphaseBase::saveSequentialIterationState( ElementSubRegionBase & subRegion ) const { - FlowSolverBase::saveIterationState( subRegion ); - - if( !subRegion.hasField< fields::flow::globalCompDensity_k >() ) - { - return; - } + FlowSolverBase::saveSequentialIterationState( subRegion ); arrayView2d< real64 const, compflow::USD_COMP > const compDens = subRegion.template getField< fields::flow::globalCompDensity >(); arrayView2d< real64, compflow::USD_COMP > const compDens_k = subRegion.template getField< fields::flow::globalCompDensity_k >(); @@ -2422,6 +2410,8 @@ void CompositionalMultiphaseBase::saveIterationState( ElementSubRegionBase & sub void CompositionalMultiphaseBase::updateState( DomainPartition & domain ) { + GEOS_MARK_FUNCTION; + real64 maxDeltaPhaseVolFrac = 0.0; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -2444,13 +2434,65 @@ void CompositionalMultiphaseBase::updateState( DomainPartition & domain ) } ); } ); + maxDeltaPhaseVolFrac = MpiWrapper::max( maxDeltaPhaseVolFrac ); + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " {}: Max phase volume fraction change = {}", getName(), fmt::format( "{:.{}f}", maxDeltaPhaseVolFrac, 4 ) ) ); } +bool CompositionalMultiphaseBase::checkSequentialSolutionIncrements( DomainPartition & domain ) const +{ + bool isConverged = FlowSolverBase::checkSequentialSolutionIncrements( domain ); + + integer const numComp = m_numComponents; + + real64 maxCompDensChange = 0.0; + forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, + MeshLevel & mesh, + arrayView1d< string const > const & regionNames ) + { + mesh.getElemManager().forElementSubRegions( regionNames, + [&]( localIndex const, + ElementSubRegionBase & subRegion ) + { + arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); + + arrayView2d< real64 const, compflow::USD_COMP > + const compDens = subRegion.getField< fields::flow::globalCompDensity >(); + arrayView2d< real64 const, compflow::USD_COMP > + const compDens_k = subRegion.getField< fields::flow::globalCompDensity_k >(); + + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxCompDensChange( 0.0 ); + + forAll< parallelDevicePolicy<> >( subRegion.size(), [=] + GEOS_HOST_DEVICE ( localIndex + const ei ) + { + if( ghostRank[ei] < 0 ) + { + for( integer ic = 0; ic < numComp; ++ic ) + { + subRegionMaxCompDensChange.max( LvArray::math::abs( compDens[ei][ic] - compDens_k[ei][ic] ) ); + } + } + } ); + + maxCompDensChange = LvArray::math::max( maxCompDensChange, subRegionMaxCompDensChange.get() ); + } ); + } ); + + maxCompDensChange = MpiWrapper::max( maxCompDensChange ); + + string const unit = m_useMass ? "kg/m3" : "mol/m3"; + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " {}: Max component density change during outer iteration: {} {}", + getName(), fmt::format( "{:.{}f}", maxCompDensChange, 3 ), unit ) ); + + return isConverged && (maxCompDensChange < m_maxSequentialCompDensChange); +} + real64 CompositionalMultiphaseBase::setNextDt( const geos::real64 & currentDt, geos::DomainPartition & domain ) { - if( m_targetFlowCFL<0 ) + if( m_targetFlowCFL < 0 ) return SolverBase::setNextDt( currentDt, domain ); else return setNextDtBasedOnCFL( currentDt, domain ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp index 3c9c383aee6..21e16c269d2 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp @@ -153,9 +153,7 @@ class CompositionalMultiphaseBase : public FlowSolverBase virtual void saveConvergedState( ElementSubRegionBase & subRegion ) const override final; - virtual void saveIterationState( DomainPartition & domain ) const override final; - - virtual void saveIterationState( ElementSubRegionBase & subRegion ) const override final; + virtual void saveSequentialIterationState( DomainPartition & domain ) const override final; virtual void updateState( DomainPartition & domain ) override final; @@ -256,6 +254,7 @@ class CompositionalMultiphaseBase : public FlowSolverBase static constexpr char const * useTotalMassEquationString() { return "useTotalMassEquation"; } static constexpr char const * useSimpleAccumulationString() { return "useSimpleAccumulation"; } static constexpr char const * minCompDensString() { return "minCompDens"; } + static constexpr char const * maxSequentialCompDensChangeString() { return "maxSequentialCompDensChange"; } }; @@ -378,6 +377,8 @@ class CompositionalMultiphaseBase : public FlowSolverBase integer useTotalMassEquation() const { return m_useTotalMassEquation; } + virtual bool checkSequentialSolutionIncrements( DomainPartition & domain ) const override; + protected: virtual void postProcessInput() override; @@ -416,6 +417,8 @@ class CompositionalMultiphaseBase : public FlowSolverBase string const fieldKey, string const boundaryFieldKey ) const; + virtual void saveSequentialIterationState( ElementSubRegionBase & subRegion ) const override final; + /// the max number of fluid phases integer m_numPhases; @@ -479,6 +482,9 @@ class CompositionalMultiphaseBase : public FlowSolverBase /// name of the fluid constitutive model used as a reference for component/phase description string m_referenceFluidModelName; + /// maximum (absolute) component density change in a sequential iteration + real64 m_maxSequentialCompDensChange; + /// the targeted CFL for timestep real64 m_targetFlowCFL; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp index 5f7bf339c4b..137a760069d 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp @@ -232,10 +232,10 @@ void CompositionalMultiphaseStatistics::computeRegionStatistics( real64 const ti arrayView1d< integer const > const elemGhostRank = subRegion.ghostRank(); arrayView1d< real64 const > const volume = subRegion.getElementVolume(); arrayView1d< real64 const > const pres = subRegion.getField< fields::flow::pressure >(); - arrayView1d< real64 > const deltaPres = subRegion.getField< fields::flow::deltaPressure >(); arrayView1d< real64 const > const temp = subRegion.getField< fields::flow::temperature >(); arrayView2d< real64 const, compflow::USD_PHASE > const phaseVolFrac = subRegion.getField< fields::flow::phaseVolumeFraction >(); + arrayView1d< real64 const > const deltaPres = subRegion.getField< fields::flow::deltaPressure >(); Group const & constitutiveModels = subRegion.getGroup( ElementSubRegionBase::groupKeyStruct::constitutiveModelsString() ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp index 62e21cd33f3..26aec0a2c1a 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp @@ -121,16 +121,28 @@ FlowSolverBase::FlowSolverBase( string const & name, setInputFlag( InputFlags::OPTIONAL ). setDescription( "Flag indicating whether the problem is thermal or not." ); + this->registerWrapper( viewKeyStruct::allowNegativePressureString(), &m_allowNegativePressure ). + setApplyDefaultValue( 1 ). // negative pressure is allowed by default + setInputFlag( InputFlags::OPTIONAL ). + setDescription( "Flag indicating if negative pressure is allowed" ); + this->registerWrapper( viewKeyStruct::maxAbsolutePresChangeString(), &m_maxAbsolutePresChange ). setSizedFromParent( 0 ). setInputFlag( InputFlags::OPTIONAL ). setApplyDefaultValue( -1.0 ). // disabled by default setDescription( "Maximum (absolute) pressure change in a Newton iteration" ); - this->registerWrapper( viewKeyStruct::allowNegativePressureString(), &m_allowNegativePressure ). - setApplyDefaultValue( 1 ). // negative pressure is allowed by default + this->registerWrapper( viewKeyStruct::maxSequentialPresChangeString(), &m_maxSequentialPresChange ). + setSizedFromParent( 0 ). setInputFlag( InputFlags::OPTIONAL ). - setDescription( "Flag indicating if negative pressure is allowed" ); + setApplyDefaultValue( 1e5 ). // 0.1 bar = 1e5 Pa + setDescription( "Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check" ); + + this->registerWrapper( viewKeyStruct::maxSequentialTempChangeString(), &m_maxSequentialTempChange ). + setSizedFromParent( 0 ). + setInputFlag( InputFlags::OPTIONAL ). + setApplyDefaultValue( 0.1 ). + setDescription( "Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check" ); // allow the user to select a norm getNonlinearSolverParameters().getWrapper< solverBaseKernels::NormType >( NonlinearSolverParameters::viewKeysStruct::normTypeString() ).setInputFlag( InputFlags::OPTIONAL ); @@ -154,6 +166,25 @@ void FlowSolverBase::registerDataOnMesh( Group & meshBodies ) subRegion.registerField< fields::flow::gravityCoefficient >( getName() ). setApplyDefaultValue( 0.0 ); subRegion.registerField< fields::flow::netToGross >( getName() ); + + subRegion.registerField< fields::flow::pressure >( getName() ); + subRegion.registerField< fields::flow::pressure_n >( getName() ); + subRegion.registerField< fields::flow::initialPressure >( getName() ); + subRegion.registerField< fields::flow::deltaPressure >( getName() ); // for reporting/stats purposes + subRegion.registerField< fields::flow::bcPressure >( getName() ); // needed for the application of boundary conditions + if( m_isFixedStressPoromechanicsUpdate ) + { + subRegion.registerField< fields::flow::pressure_k >( getName() ); // needed for the fixed-stress porosity update + } + + subRegion.registerField< fields::flow::temperature >( getName() ); + subRegion.registerField< fields::flow::temperature_n >( getName() ); + subRegion.registerField< fields::flow::initialTemperature >( getName() ); + subRegion.registerField< fields::flow::bcTemperature >( getName() ); // needed for the application of boundary conditions + if( m_isFixedStressPoromechanicsUpdate ) + { + subRegion.registerField< fields::flow::temperature_k >( getName() ); // needed for the fixed-stress porosity update + } } ); elemManager.forElementSubRegionsComplete< SurfaceElementSubRegion >( [&]( localIndex const, @@ -221,10 +252,9 @@ void FlowSolverBase::saveConvergedState( ElementSubRegionBase & subRegion ) cons } } -void FlowSolverBase::saveIterationState( ElementSubRegionBase & subRegion ) const +void FlowSolverBase::saveSequentialIterationState( ElementSubRegionBase & subRegion ) const { - if( !m_isFixedStressPoromechanicsUpdate ) - return; + GEOS_ASSERT( m_isFixedStressPoromechanicsUpdate ); arrayView1d< real64 const > const pres = subRegion.template getField< fields::flow::pressure >(); arrayView1d< real64 const > const temp = subRegion.template getField< fields::flow::temperature >(); @@ -234,7 +264,7 @@ void FlowSolverBase::saveIterationState( ElementSubRegionBase & subRegion ) cons temp_k.setValues< parallelDevicePolicy<> >( temp ); } -void FlowSolverBase::saveIterationState( DomainPartition & domain ) const +void FlowSolverBase::saveSequentialIterationState( DomainPartition & domain ) const { forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -244,7 +274,7 @@ void FlowSolverBase::saveIterationState( DomainPartition & domain ) const [&]( localIndex const, ElementSubRegionBase & subRegion ) { - saveIterationState( subRegion ); + saveSequentialIterationState( subRegion ); } ); } ); } @@ -755,4 +785,54 @@ void FlowSolverBase::updateStencilWeights( DomainPartition & domain ) const } ); } +bool FlowSolverBase::checkSequentialSolutionIncrements( DomainPartition & domain ) const +{ + real64 maxPresChange = 0.0; + real64 maxTempChange = 0.0; + forDiscretizationOnMeshTargets ( domain.getMeshBodies(), [&]( string const &, + MeshLevel & mesh, + arrayView1d< string const > const & regionNames ) + { + mesh.getElemManager().forElementSubRegions ( regionNames, + [&]( localIndex const, + ElementSubRegionBase & subRegion ) + { + arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); + + arrayView1d< real64 const > const pres = subRegion.getField< fields::flow::pressure >(); + arrayView1d< real64 const > const pres_k = subRegion.getField< fields::flow::pressure_k >(); + arrayView1d< real64 const > const temp = subRegion.getField< fields::flow::temperature >(); + arrayView1d< real64 const > const temp_k = subRegion.getField< fields::flow::temperature_k >(); + + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPresChange( 0.0 ); + RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxTempChange( 0.0 ); + + forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) + { + if( ghostRank[ei] < 0 ) + { + subRegionMaxPresChange.max( LvArray::math::abs( pres[ei] - pres_k[ei] ) ); + subRegionMaxTempChange.max( LvArray::math::abs( temp[ei] - temp_k[ei] ) ); + } + } ); + + maxPresChange = LvArray::math::max( maxPresChange, subRegionMaxPresChange.get() ); + maxTempChange = LvArray::math::max( maxTempChange, subRegionMaxTempChange.get() ); + } ); + } ); + + maxPresChange = MpiWrapper::max( maxPresChange ); + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " {}: Max pressure change during outer iteration: {} Pa", + getName(), fmt::format( "{:.{}f}", maxPresChange, 3 ) ) ); + + if( m_isThermal ) + { + maxTempChange = MpiWrapper::max( maxTempChange ); + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " {}: Max temperature change during outer iteration: {} K", + getName(), fmt::format( "{:.{}f}", maxTempChange, 3 ) ) ); + } + + return (maxPresChange < m_maxSequentialPresChange) && (maxTempChange < m_maxSequentialTempChange); +} + } // namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp index 8fcb9d89522..0dac0799c6b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp @@ -73,6 +73,8 @@ class FlowSolverBase : public SolverBase static constexpr char const * solidInternalEnergyNamesString() { return "solidInternalEnergyNames"; } static constexpr char const * allowNegativePressureString() { return "allowNegativePressure"; } static constexpr char const * maxAbsolutePresChangeString() { return "maxAbsolutePressureChange"; } + static constexpr char const * maxSequentialPresChangeString() { return "maxSequentialPressureChange"; } + static constexpr char const * maxSequentialTempChangeString() { return "maxSequentialTemperatureChange"; } }; /** @@ -99,7 +101,7 @@ class FlowSolverBase : public SolverBase * @brief Utility function to save the iteration state (useful for sequential simulations) * @param[in] domain the domain partition */ - virtual void saveIterationState( DomainPartition & domain ) const; + virtual void saveSequentialIterationState( DomainPartition & domain ) const override; /** * @brief For each equilibrium initial condition, loop over all the target cells and compute the min/max elevation @@ -134,6 +136,8 @@ class FlowSolverBase : public SolverBase */ void allowNegativePressure() { m_allowNegativePressure = 1; } + virtual bool checkSequentialSolutionIncrements( DomainPartition & domain ) const override; + protected: /** @@ -159,7 +163,7 @@ class FlowSolverBase : public SolverBase * @brief Utility function to save the state at the end of a sequential iteration * @param[in] subRegion the element subRegion */ - virtual void saveIterationState( ElementSubRegionBase & subRegion ) const; + virtual void saveSequentialIterationState( ElementSubRegionBase & subRegion ) const; /** * @brief Helper function to compute/report the elements with small pore volumes @@ -185,11 +189,17 @@ class FlowSolverBase : public SolverBase /// enable the fixed stress poromechanics update of porosity bool m_isFixedStressPoromechanicsUpdate; + /// flag if negative pressure is allowed + integer m_allowNegativePressure; + /// maximum (absolute) pressure change in a Newton iteration real64 m_maxAbsolutePresChange; - /// flag if negative pressure is allowed - integer m_allowNegativePressure; + /// maximum (absolute) pressure change in a sequential iteration + real64 m_maxSequentialPresChange; + + /// maximum (absolute) temperature change in a sequential iteration + real64 m_maxSequentialTempChange; private: virtual void setConstitutiveNames( ElementSubRegionBase & subRegion ) const override; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp index d360defde51..bbfe022fbf6 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp @@ -1334,6 +1334,8 @@ void ReactiveCompositionalMultiphaseOBL::updateOBLOperators( ObjectManagerBase & void ReactiveCompositionalMultiphaseOBL::updateState( DomainPartition & domain ) { + GEOS_MARK_FUNCTION; + forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, arrayView1d< string const > const & regionNames ) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp index c94e705ba3e..1b344dc0130 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp @@ -80,27 +80,8 @@ void SinglePhaseBase::registerDataOnMesh( Group & meshBodies ) [&]( localIndex const, ElementSubRegionBase & subRegion ) { - subRegion.registerField< pressure >( getName() ); - subRegion.registerField< pressure_n >( getName() ); - subRegion.registerField< initialPressure >( getName() ); - subRegion.registerField< deltaPressure >( getName() ); // for reporting/stats purposes - subRegion.registerField< bcPressure >( getName() ); // needed for the application of boundary conditions - if( m_isFixedStressPoromechanicsUpdate ) - { - subRegion.registerField< pressure_k >( getName() ); // needed for the fixed-stress porosity update - } - subRegion.registerField< deltaVolume >( getName() ); - subRegion.registerField< temperature >( getName() ); - subRegion.registerField< temperature_n >( getName() ); - subRegion.registerField< initialTemperature >( getName() ); - subRegion.registerField< bcTemperature >( getName() ); // needed for the application of boundary conditions - if( m_isFixedStressPoromechanicsUpdate ) - { - subRegion.registerField< temperature_k >( getName() ); // needed for the fixed-stress porosity update - } - subRegion.registerField< mobility >( getName() ); subRegion.registerField< dMobility_dPressure >( getName() ); @@ -634,12 +615,6 @@ void SinglePhaseBase::implicitStepSetup( real64 const & GEOS_UNUSED_PARAM( time_ mesh.getElemManager().forElementSubRegions< CellElementSubRegion, SurfaceElementSubRegion >( regionNames, [&]( localIndex const, auto & subRegion ) { - arrayView1d< real64 const > const & pres = subRegion.template getField< fields::flow::pressure >(); - arrayView1d< real64 const > const & initPres = subRegion.template getField< fields::flow::initialPressure >(); - arrayView1d< real64 > const & deltaPres = subRegion.template getField< fields::flow::deltaPressure >(); - - singlePhaseBaseKernels::StatisticsKernel:: - saveDeltaPressure( subRegion.size(), pres, initPres, deltaPres ); saveConvergedState( subRegion ); arrayView1d< real64 > const & dVol = subRegion.template getField< fields::flow::deltaVolume >(); @@ -653,7 +628,6 @@ void SinglePhaseBase::implicitStepSetup( real64 const & GEOS_UNUSED_PARAM( time_ { updateSolidInternalEnergyModel( subRegion ); updateThermalConductivity( subRegion ); - } } ); @@ -680,9 +654,6 @@ void SinglePhaseBase::implicitStepSetup( real64 const & GEOS_UNUSED_PARAM( time_ } ); } ); - - - } void SinglePhaseBase::implicitStepComplete( real64 const & time, @@ -702,6 +673,13 @@ void SinglePhaseBase::implicitStepComplete( real64 const & time, mesh.getElemManager().forElementSubRegions( regionNames, [&]( localIndex const, ElementSubRegionBase & subRegion ) { + // update deltaPressure + arrayView1d< real64 const > const pres = subRegion.getField< fields::flow::pressure >(); + arrayView1d< real64 const > const initPres = subRegion.getField< fields::flow::initialPressure >(); + arrayView1d< real64 > const deltaPres = subRegion.getField< fields::flow::deltaPressure >(); + singlePhaseBaseKernels::StatisticsKernel:: + saveDeltaPressure( subRegion.size(), pres, initPres, deltaPres ); + arrayView1d< real64 const > const dVol = subRegion.getField< fields::flow::deltaVolume >(); arrayView1d< real64 > const vol = subRegion.getReference< array1d< real64 > >( CellElementSubRegion::viewKeyStruct::elementVolumeString() ); @@ -1213,8 +1191,8 @@ void SinglePhaseBase::keepFlowVariablesConstantDuringInitStep( real64 const time void SinglePhaseBase::updateState( DomainPartition & domain ) { + GEOS_MARK_FUNCTION; -// set mass fraction flag on fluid models forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, arrayView1d< string const > const & regionNames ) @@ -1235,7 +1213,6 @@ void SinglePhaseBase::updateState( DomainPartition & domain ) void SinglePhaseBase::resetStateToBeginningOfStep( DomainPartition & domain ) { - // set mass fraction flag on fluid models forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, arrayView1d< string const > const & regionNames ) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.cpp index 5086f5f2d83..a25112cd74a 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.cpp @@ -196,6 +196,7 @@ void WellSolverBase::assembleSystem( real64 const time, void WellSolverBase::updateState( DomainPartition & domain ) { + GEOS_MARK_FUNCTION; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, MeshLevel & mesh, diff --git a/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.hpp b/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.hpp index 6ffff4efd28..108dfed9d80 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.hpp @@ -106,7 +106,7 @@ class CompositionalMultiphaseReservoirAndWells : public CoupledReservoirAndWells void enableFixedStressPoromechanicsUpdate() { flowSolver()->enableFixedStressPoromechanicsUpdate(); } - void saveIterationState( DomainPartition & domain ) const { flowSolver()->saveIterationState( domain ); } + virtual void saveSequentialIterationState( DomainPartition & domain ) const override final { flowSolver()->saveSequentialIterationState( domain ); } protected: diff --git a/src/coreComponents/physicsSolvers/multiphysics/CoupledSolver.hpp b/src/coreComponents/physicsSolvers/multiphysics/CoupledSolver.hpp index ad49c26ea2c..61b69720a39 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/CoupledSolver.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/CoupledSolver.hpp @@ -345,6 +345,24 @@ class CoupledSolver : public SolverBase /**@}*/ + virtual bool checkSequentialSolutionIncrements( DomainPartition & domain ) const override + { + bool isConverged = true; + forEachArgInTuple( m_solvers, [&]( auto & solver, auto ) + { + isConverged &= solver->checkSequentialSolutionIncrements( domain ); + } ); + return isConverged; + } + + virtual void saveSequentialIterationState( DomainPartition & domain ) const override + { + forEachArgInTuple( m_solvers, [&]( auto & solver, auto ) + { + solver->saveSequentialIterationState( domain ); + } ); + } + protected: /** @@ -381,15 +399,10 @@ class CoupledSolver : public SolverBase { GEOS_MARK_FUNCTION; + // Only build the sparsity pattern if the mesh has changed Timestamp const meshModificationTimestamp = getMeshModificationTimestamp( domain ); - - // First call Coupled Solver setup (important for poromechanics initialization for sequentially coupled) - implicitStepSetup( time_n, dt, domain ); - forEachArgInTuple( m_solvers, [&]( auto & solver, auto ) { - - // Only build the sparsity pattern if the mesh has changed if( meshModificationTimestamp > solver->getSystemSetupTimestamp() ) { solver->setupSystem( domain, @@ -399,11 +412,10 @@ class CoupledSolver : public SolverBase solver->getSystemSolution() ); solver->setSystemSetupTimestamp( meshModificationTimestamp ); } - - solver->implicitStepSetup( time_n, dt, domain ); - } ); + implicitStepSetup( time_n, dt, domain ); + NonlinearSolverParameters & solverParams = getNonlinearSolverParameters(); integer const maxNumberDtCuts = solverParams.m_maxTimeStepCuts; real64 const dtCutFactor = solverParams.m_timeStepCutFactor; @@ -463,14 +475,12 @@ class CoupledSolver : public SolverBase stepDt, domain ); + // save fields (e.g. pressure and temperature) at the end of this iteration + saveSequentialIterationState( domain ); + if( isConverged ) { - // Save Time step statistics for the subsolvers - forEachArgInTuple( m_solvers, [&]( auto & solver, - auto ) - { - solver->getSolverStatistics().saveTimeStepStatistics(); - } ); + // exit outer loop break; } else @@ -483,7 +493,12 @@ class CoupledSolver : public SolverBase if( isConverged ) { - // get out of time loop + // Save time step statistics for the subsolvers + forEachArgInTuple( m_solvers, [&]( auto & solver, auto ) + { + solver->getSolverStatistics().saveTimeStepStatistics(); + } ); + // get out of the time loop break; } else @@ -494,8 +509,7 @@ class CoupledSolver : public SolverBase // notify the solver statistics counter that this is a time step cut m_solverStatistics.logTimeStepCut(); - forEachArgInTuple( m_solvers, [&]( auto & solver, - auto ) + forEachArgInTuple( m_solvers, [&]( auto & solver, auto ) { solver->getSolverStatistics().logTimeStepCut(); } ); @@ -527,7 +541,8 @@ class CoupledSolver : public SolverBase * @param domain the domain partition * @param solverType the index of the solver withing this coupled solver. */ - virtual void mapSolutionBetweenSolvers( DomainPartition & domain, integer const solverType ) + virtual void mapSolutionBetweenSolvers( DomainPartition & domain, + integer const solverType ) { GEOS_UNUSED_VAR( domain, solverType ); } @@ -535,7 +550,7 @@ class CoupledSolver : public SolverBase bool checkSequentialConvergence( int const & iter, real64 const & time_n, real64 const & dt, - DomainPartition & domain ) const + DomainPartition & domain ) { NonlinearSolverParameters const & params = getNonlinearSolverParameters(); bool isConverged = true; @@ -546,9 +561,10 @@ class CoupledSolver : public SolverBase } else { + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " Iteration {:2}: outer-loop convergence check", iter + 1 ) ); + if( params.sequentialConvergenceCriterion() == NonlinearSolverParameters::SequentialConvergenceCriterion::ResidualNorm ) { - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " Iteration {:2}: outer-loop convergence check", iter+1 ) ); real64 residualNorm = 0; // loop over all the single-physics solvers @@ -592,6 +608,7 @@ class CoupledSolver : public SolverBase } else if( params.sequentialConvergenceCriterion() == NonlinearSolverParameters::SequentialConvergenceCriterion::NumberOfNonlinearIterations ) { + // TODO also make recursive? forEachArgInTuple( m_solvers, [&]( auto & solver, auto ) { NonlinearSolverParameters const & singlePhysicsParams = solver->getNonlinearSolverParameters(); @@ -601,6 +618,10 @@ class CoupledSolver : public SolverBase } } ); } + else if( params.sequentialConvergenceCriterion() == NonlinearSolverParameters::SequentialConvergenceCriterion::SolutionIncrements ) + { + isConverged = checkSequentialSolutionIncrements( domain ); + } else { GEOS_ERROR( getDataContext() << ": Invalid sequential convergence criterion." ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.cpp b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.cpp index 236581534fc..1d52bfee359 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.cpp @@ -96,6 +96,10 @@ HydrofractureSolver< POROMECHANICS_SOLVER >::HydrofractureSolver( const string & setApplyDefaultValue( 0 ). setInputFlag( InputFlags::OPTIONAL ); + registerWrapper( viewKeyStruct::useQuasiNewtonString(), &m_useQuasiNewton ). + setApplyDefaultValue( 0 ). + setInputFlag( InputFlags::OPTIONAL ); + m_numResolves[0] = 0; // This may need to be different depending on whether poroelasticity is on or not. @@ -175,6 +179,8 @@ void HydrofractureSolver< POROMECHANICS_SOLVER >::postProcessInput() m_surfaceGenerator = &this->getParent().template getGroup< SurfaceGenerator >( m_surfaceGeneratorName ); flowSolver()->allowNegativePressure(); + + GEOS_LOG_RANK_0_IF( m_useQuasiNewton, GEOS_FMT( "{}: activated Quasi-Newton", this->getName())); } template< typename POROMECHANICS_SOLVER > @@ -834,6 +840,7 @@ assembleFluidMassResidualDerivativeWrtDisplacement( DomainPartition const & doma launch< parallelDevicePolicy<> >( subRegion.size(), rankOffset, contactWrapper, + m_useQuasiNewton, elemsToFaces, faceToNodeMap, faceNormal, @@ -853,6 +860,7 @@ assembleFluidMassResidualDerivativeWrtDisplacement( DomainPartition const & doma template< typename POROMECHANICS_SOLVER > void HydrofractureSolver< POROMECHANICS_SOLVER >::updateState( DomainPartition & domain ) { + GEOS_MARK_FUNCTION; Base::updateState( domain ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.hpp b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.hpp index 5deca2e42e9..9ee4adcdd04 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.hpp @@ -148,6 +148,7 @@ class HydrofractureSolver : public POROMECHANICS_SOLVER constexpr static char const * isMatrixPoroelasticString() { return "isMatrixPoroelastic"; } + constexpr static char const * useQuasiNewtonString() { return "useQuasiNewton"; } #ifdef GEOSX_USE_SEPARATION_COEFFICIENT constexpr static char const * separationCoeff0String() { return "separationCoeff0"; } @@ -210,6 +211,8 @@ class HydrofractureSolver : public POROMECHANICS_SOLVER integer m_isMatrixPoroelastic; + integer m_useQuasiNewton; // use Quasi-Newton (see https://arxiv.org/abs/2111.00264) + }; diff --git a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolverKernels.hpp b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolverKernels.hpp index 1a14d0b49dc..fe23b8b491f 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolverKernels.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolverKernels.hpp @@ -205,6 +205,7 @@ struct FluidMassResidualDerivativeAssemblyKernel launch( localIndex const size, globalIndex const rankOffset, CONTACT_WRAPPER const & contactWrapper, + integer const useQuasiNewton, ArrayOfArraysView< localIndex const > const elemsToFaces, ArrayOfArraysView< localIndex const > const faceToNodeMap, arrayView2d< real64 const > const faceNormal, @@ -248,29 +249,32 @@ struct FluidMassResidualDerivativeAssemblyKernel 2 * numNodesPerFace * 3 ); } // - localIndex const numColumns = dFluxResidual_dNormalJump.numNonZeros( ei ); - arraySlice1d< localIndex const > const & columns = dFluxResidual_dNormalJump.getColumns( ei ); - arraySlice1d< real64 const > const & values = dFluxResidual_dNormalJump.getEntries( ei ); - - for( localIndex kfe2 = 0; kfe2 < numColumns; ++kfe2 ) + if( useQuasiNewton == 0 ) // when Quasi Newton is not enabled - add flux derivatives { - computeFluxDerivative( kfe2, - numNodesPerFace, - columns, - values, - elemsToFaces, - faceToNodeMap, - dispDofNumber, - Nbar, - nodeDOF, - dRdU ); - - if( rowNumber >= 0 && rowNumber < localMatrix.numRows() ) + localIndex const numColumns = dFluxResidual_dNormalJump.numNonZeros( ei ); + arraySlice1d< localIndex const > const & columns = dFluxResidual_dNormalJump.getColumns( ei ); + arraySlice1d< real64 const > const & values = dFluxResidual_dNormalJump.getEntries( ei ); + + for( localIndex kfe2 = 0; kfe2 < numColumns; ++kfe2 ) { - localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic >( rowNumber, - nodeDOF, - dRdU.data(), - 2 * numNodesPerFace * 3 ); + computeFluxDerivative( kfe2, + numNodesPerFace, + columns, + values, + elemsToFaces, + faceToNodeMap, + dispDofNumber, + Nbar, + nodeDOF, + dRdU ); + + if( rowNumber >= 0 && rowNumber < localMatrix.numRows() ) + { + localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic >( rowNumber, + nodeDOF, + dRdU.data(), + 2 * numNodesPerFace * 3 ); + } } } } ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.cpp b/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.cpp index 98079dae637..d748a62fb0c 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.cpp @@ -271,6 +271,8 @@ void MultiphasePoromechanics< FLOW_SOLVER >::assembleSystem( real64 const GEOS_U template< typename FLOW_SOLVER > void MultiphasePoromechanics< FLOW_SOLVER >::updateState( DomainPartition & domain ) { + GEOS_MARK_FUNCTION; + real64 maxDeltaPhaseVolFrac = 0.0; this->template forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, MeshLevel & mesh, @@ -290,6 +292,8 @@ void MultiphasePoromechanics< FLOW_SOLVER >::updateState( DomainPartition & doma } ); } ); + maxDeltaPhaseVolFrac = MpiWrapper::max( maxDeltaPhaseVolFrac ); + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " {}: Max phase volume fraction change = {}", this->getName(), GEOS_FMT( "{:.{}f}", maxDeltaPhaseVolFrac, 4 ) ) ); } diff --git a/src/coreComponents/physicsSolvers/multiphysics/PoromechanicsSolver.hpp b/src/coreComponents/physicsSolvers/multiphysics/PoromechanicsSolver.hpp index 05eaca5fdef..ed7734f4ab1 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/PoromechanicsSolver.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/PoromechanicsSolver.hpp @@ -346,9 +346,6 @@ class PoromechanicsSolver : public CoupledSolver< FLOW_SOLVER, /// After the flow solver if( solverType == static_cast< integer >( SolverType::Flow ) ) { - // save pressure and temperature at the end of this iteration - flowSolver()->saveIterationState( domain ); - this->template forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, arrayView1d< string const > const & regionNames ) diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.cpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.cpp index 4ab8faa8214..15d25abcd1c 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.cpp @@ -315,6 +315,8 @@ void SinglePhasePoromechanics< FLOW_SOLVER >::createPreconditioner() template< typename FLOW_SOLVER > void SinglePhasePoromechanics< FLOW_SOLVER >::updateState( DomainPartition & domain ) { + GEOS_MARK_FUNCTION; + this->template forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, MeshLevel & mesh, arrayView1d< string const > const & regionNames ) diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsConformingFractures.cpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsConformingFractures.cpp index 93a32ddb123..5884bcf05ad 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsConformingFractures.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsConformingFractures.cpp @@ -738,6 +738,7 @@ void SinglePhasePoromechanicsConformingFractures:: void SinglePhasePoromechanicsConformingFractures::updateState( DomainPartition & domain ) { + GEOS_MARK_FUNCTION; Base::updateState( domain ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsEmbeddedFractures.cpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsEmbeddedFractures.cpp index a2ea2930021..34272cc7a52 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsEmbeddedFractures.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsEmbeddedFractures.cpp @@ -529,6 +529,8 @@ void SinglePhasePoromechanicsEmbeddedFractures::applySystemSolution( DofManager void SinglePhasePoromechanicsEmbeddedFractures::updateState( DomainPartition & domain ) { + GEOS_MARK_FUNCTION; + /// 1. update the reservoir SinglePhasePoromechanics::updateState( domain ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.hpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.hpp index aca5b35eea0..ef7315a6c95 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.hpp @@ -93,7 +93,7 @@ class SinglePhaseReservoirAndWells : public CoupledReservoirAndWellsBase< SINGLE void enableFixedStressPoromechanicsUpdate() { flowSolver()->enableFixedStressPoromechanicsUpdate(); } - void saveIterationState( DomainPartition & domain ) const { flowSolver()->saveIterationState( domain ); } + virtual void saveSequentialIterationState( DomainPartition & domain ) const override { flowSolver()->saveSequentialIterationState( domain ); } protected: diff --git a/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.cpp b/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.cpp index 4ba2a40c684..75818129611 100644 --- a/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.cpp +++ b/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.cpp @@ -645,6 +645,10 @@ void PhaseFieldDamageFEM::applyIrreversibilityConstraint( DofManager const & dof } ); } +void PhaseFieldDamageFEM::saveSequentialIterationState( DomainPartition & GEOS_UNUSED_PARAM( domain ) ) const +{ + // nothing to save yet +} REGISTER_CATALOG_ENTRY( SolverBase, PhaseFieldDamageFEM, string const &, Group * const ) diff --git a/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.hpp b/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.hpp index 5adaa2c23f2..6c623e73fe3 100644 --- a/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.hpp +++ b/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.hpp @@ -131,6 +131,8 @@ class PhaseFieldDamageFEM : public SolverBase CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs ); + virtual void saveSequentialIterationState( DomainPartition & domain ) const override; + enum class TimeIntegrationOption { SteadyState, diff --git a/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp b/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp index c6a0a2167d9..58f8b7489a7 100644 --- a/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp +++ b/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp @@ -1398,5 +1398,10 @@ void SolidMechanicsLagrangianFEM::enableFixedStressPoromechanicsUpdate() m_isFixedStressPoromechanicsUpdate = true; } +void SolidMechanicsLagrangianFEM::saveSequentialIterationState( DomainPartition & GEOS_UNUSED_PARAM( domain ) ) const +{ + // nothing to save +} + REGISTER_CATALOG_ENTRY( SolverBase, SolidMechanicsLagrangianFEM, string const &, dataRepository::Group * const ) } diff --git a/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.hpp b/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.hpp index 830c1096f46..af974e111cf 100644 --- a/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.hpp +++ b/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.hpp @@ -227,6 +227,8 @@ class SolidMechanicsLagrangianFEM : public SolverBase void enableFixedStressPoromechanicsUpdate(); + virtual void saveSequentialIterationState( DomainPartition & domain ) const override; + struct viewKeyStruct : SolverBase::viewKeyStruct { static constexpr char const * cflFactorString() { return "cflFactor"; } diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.cpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.cpp index 3e0e5743550..590cfd0f084 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.cpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.cpp @@ -25,6 +25,7 @@ namespace geos { using namespace dataRepository; +using namespace fields; void AcousticElasticWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) { @@ -35,9 +36,9 @@ void AcousticElasticWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) arrayView1d< string const > const & ) { NodeManager & nodeManager = mesh.getNodeManager(); - nodeManager.registerField< fields::CouplingVectorx >( getName() ); - nodeManager.registerField< fields::CouplingVectory >( getName() ); - nodeManager.registerField< fields::CouplingVectorz >( getName() ); + nodeManager.registerField< acoustoelasticfields::CouplingVectorx >( getName() ); + nodeManager.registerField< acoustoelasticfields::CouplingVectory >( getName() ); + nodeManager.registerField< acoustoelasticfields::CouplingVectorz >( getName() ); } ); } @@ -80,13 +81,13 @@ void AcousticElasticWaveEquationSEM::initializePostInitialConditionsPreSubGroups arrayView2d< localIndex const > const faceToRegion = faceManager.elementRegionList(); arrayView2d< localIndex const > const faceToElement = faceManager.elementList(); - arrayView1d< real32 > const couplingVectorx = nodeManager.getField< fields::CouplingVectorx >(); + arrayView1d< real32 > const couplingVectorx = nodeManager.getField< acoustoelasticfields::CouplingVectorx >(); couplingVectorx.zero(); - arrayView1d< real32 > const couplingVectory = nodeManager.getField< fields::CouplingVectory >(); + arrayView1d< real32 > const couplingVectory = nodeManager.getField< acoustoelasticfields::CouplingVectory >(); couplingVectory.zero(); - arrayView1d< real32 > const couplingVectorz = nodeManager.getField< fields::CouplingVectorz >(); + arrayView1d< real32 > const couplingVectorz = nodeManager.getField< acoustoelasticfields::CouplingVectorz >(); couplingVectorz.zero(); elemManager.forElementRegions( m_acousRegions, [&] ( localIndex const regionIndex, ElementRegionBase const & elemRegion ) @@ -137,26 +138,26 @@ real64 AcousticElasticWaveEquationSEM::solverStep( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const acousticMass = nodeManager.getField< fields::AcousticMassVector >(); - arrayView1d< real32 const > const elasticMass = nodeManager.getField< fields::ElasticMassVector >(); - arrayView1d< localIndex > const acousticFSNodeIndicator = nodeManager.getField< fields::AcousticFreeSurfaceNodeIndicator >(); - arrayView1d< localIndex > const elasticFSNodeIndicator = nodeManager.getField< fields::ElasticFreeSurfaceNodeIndicator >(); - - arrayView1d< real32 const > const p_n = nodeManager.getField< fields::Pressure_n >(); - arrayView1d< real32 const > const ux_nm1 = nodeManager.getField< fields::Displacementx_nm1 >(); - arrayView1d< real32 const > const uy_nm1 = nodeManager.getField< fields::Displacementy_nm1 >(); - arrayView1d< real32 const > const uz_nm1 = nodeManager.getField< fields::Displacementz_nm1 >(); - arrayView1d< real32 const > const ux_n = nodeManager.getField< fields::Displacementx_n >(); - arrayView1d< real32 const > const uy_n = nodeManager.getField< fields::Displacementy_n >(); - arrayView1d< real32 const > const uz_n = nodeManager.getField< fields::Displacementz_n >(); - arrayView1d< real32 const > const atoex = nodeManager.getField< fields::CouplingVectorx >(); - arrayView1d< real32 const > const atoey = nodeManager.getField< fields::CouplingVectory >(); - arrayView1d< real32 const > const atoez = nodeManager.getField< fields::CouplingVectorz >(); - - arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< fields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< fields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< fields::Displacementz_np1 >(); + arrayView1d< real32 const > const acousticMass = nodeManager.getField< acousticfields::AcousticMassVector >(); + arrayView1d< real32 const > const elasticMass = nodeManager.getField< elasticfields::ElasticMassVector >(); + arrayView1d< localIndex const > const acousticFSNodeIndicator = nodeManager.getField< acousticfields::AcousticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex const > const elasticFSNodeIndicator = nodeManager.getField< elasticfields::ElasticFreeSurfaceNodeIndicator >(); + + arrayView1d< real32 const > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); + arrayView1d< real32 const > const ux_nm1 = nodeManager.getField< elasticfields::Displacementx_nm1 >(); + arrayView1d< real32 const > const uy_nm1 = nodeManager.getField< elasticfields::Displacementy_nm1 >(); + arrayView1d< real32 const > const uz_nm1 = nodeManager.getField< elasticfields::Displacementz_nm1 >(); + arrayView1d< real32 const > const ux_n = nodeManager.getField< elasticfields::Displacementx_n >(); + arrayView1d< real32 const > const uy_n = nodeManager.getField< elasticfields::Displacementy_n >(); + arrayView1d< real32 const > const uz_n = nodeManager.getField< elasticfields::Displacementz_n >(); + arrayView1d< real32 const > const atoex = nodeManager.getField< acoustoelasticfields::CouplingVectorx >(); + arrayView1d< real32 const > const atoey = nodeManager.getField< acoustoelasticfields::CouplingVectory >(); + arrayView1d< real32 const > const atoez = nodeManager.getField< acoustoelasticfields::CouplingVectorz >(); + + arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); real32 const dt2 = pow( dt, 2 ); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.hpp index 326b248abd8..ea72af060af 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.hpp @@ -23,6 +23,7 @@ #include "physicsSolvers/wavePropagation/ElasticWaveEquationSEM.hpp" #include "physicsSolvers/wavePropagation/AcousticWaveEquationSEM.hpp" #include "physicsSolvers/SolverBase.hpp" +#include "AcoustoElasticFields.hpp" #include namespace geos @@ -179,34 +180,6 @@ class AcousticElasticWaveEquationSEM : public CoupledWaveSolver< AcousticWaveEqu arrayView1d< string const > m_elasRegions; }; -namespace fields -{ - -DECLARE_FIELD( CouplingVectorx, - "couplingVectorx", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Coupling term on x." ); - -DECLARE_FIELD( CouplingVectory, - "couplingVectory", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Coupling term on y." ); - -DECLARE_FIELD( CouplingVectorz, - "couplingVectorz", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Coupling term on z." ); -} - } /* namespace geos */ #endif /* SRC_CORECOMPONENTS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICELASTICWAVEEQUATIONSEM_HPP_ */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticFields.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticFields.hpp new file mode 100644 index 00000000000..903809d893b --- /dev/null +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticFields.hpp @@ -0,0 +1,203 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + + +/** + * @file AcousticFields.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICFIELDS_HPP_ +#define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICFIELDS_HPP_ + +#include "common/DataLayouts.hpp" +#include "mesh/MeshFields.hpp" + + +namespace geos +{ + +namespace fields +{ + +namespace acousticfields +{ + +DECLARE_FIELD( Pressure_nm1, + "pressure_nm1", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Scalar pressure at time n-1." ); + +DECLARE_FIELD( Pressure_n, + "pressure_n", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Scalar pressure at time n." ); + + +DECLARE_FIELD( Pressure_np1, + "pressure_np1", + array1d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "Scalar pressure at time n+1." ); + +DECLARE_FIELD( PressureDoubleDerivative, + "pressureDoubleDerivative", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Double derivative of the pressure for each node to compute the gradient" ); + +DECLARE_FIELD( Velocity_x, + "velocity_x", + array2d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "Velocity in the x-direction." ); + +DECLARE_FIELD( Velocity_y, + "velocity_y", + array2d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "Velocity in the y-direction." ); + +DECLARE_FIELD( Velocity_z, + "velocity_z", + array2d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "Velocity in the z-direction." ); + +DECLARE_FIELD( PartialGradient, + "partialGradient", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Partiel gradient computed during backward propagation" ); + +DECLARE_FIELD( ForcingRHS, + "rhs", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "RHS" ); + +DECLARE_FIELD( AcousticMassVector, + "acousticMassVector", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Diagonal of the Mass Matrix." ); + +DECLARE_FIELD( StiffnessVector, + "stiffnessVector", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Stiffness vector contains R_h*Pressure_n." ); + +DECLARE_FIELD( DampingVector, + "dampingVector", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Diagonal of the Damping Matrix." ); + +DECLARE_FIELD( AcousticVelocity, + "acousticVelocity", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Medium velocity of the cell" ); + +DECLARE_FIELD( AcousticDensity, + "acousticDensity", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Medium density of the cell" ); + +DECLARE_FIELD( AcousticFreeSurfaceFaceIndicator, + "acousticFreeSurfaceFaceIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Free surface indicator, 1 if a face is on free surface 0 otherwise." ); + +DECLARE_FIELD( AcousticFreeSurfaceNodeIndicator, + "acousticFreeSurfaceNodeIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Free surface indicator, 1 if a node is on free surface 0 otherwise." ); + +DECLARE_FIELD( AuxiliaryVar1PML, + "auxiliaryVar1PML", + array2d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "PML vectorial auxiliary variable 1." ); + +DECLARE_FIELD( AuxiliaryVar2PML, + "auxiliaryVar2PML", + array2d< real32 >, + 0, + NOPLOT, + NO_WRITE, + "PML vectorial auxiliary variable 2." ); + +DECLARE_FIELD( AuxiliaryVar3PML, + "auxiliaryVar3PML", + array1d< real32 >, + 0, + NOPLOT, + NO_WRITE, + "PML scalar auxiliary variable 3." ); + +DECLARE_FIELD( AuxiliaryVar4PML, + "auxiliaryVar4PML", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "PML scalar auxiliary variable 4." ); + +} + +} + +} /* namespace geos */ + +#endif /* GEOS_PHYSICSSOLVERS_WAVEPROPAGATION__HPP_ACOUSTICFIELDS */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.cpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.cpp index bdc1f623278..1ede25c9b42 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.cpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.cpp @@ -32,7 +32,6 @@ namespace geos using namespace dataRepository; using namespace fields; -//using namespace wavesolverfields; AcousticFirstOrderWaveEquationSEM::AcousticFirstOrderWaveEquationSEM( const std::string & name, Group * const parent ): @@ -94,25 +93,25 @@ void AcousticFirstOrderWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) { NodeManager & nodeManager = mesh.getNodeManager(); - nodeManager.registerField< wavesolverfields::Pressure_np1, - wavesolverfields::ForcingRHS, - wavesolverfields::AcousticMassVector, - wavesolverfields::DampingVector, - wavesolverfields::AcousticFreeSurfaceNodeIndicator >( getName() ); + nodeManager.registerField< acousticfields::Pressure_np1, + acousticfields::ForcingRHS, + acousticfields::AcousticMassVector, + acousticfields::DampingVector, + acousticfields::AcousticFreeSurfaceNodeIndicator >( getName() ); FaceManager & faceManager = mesh.getFaceManager(); - faceManager.registerField< wavesolverfields::AcousticFreeSurfaceFaceIndicator >( getName() ); + faceManager.registerField< acousticfields::AcousticFreeSurfaceFaceIndicator >( getName() ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< CellElementSubRegion >( [&]( CellElementSubRegion & subRegion ) { - subRegion.registerField< wavesolverfields::AcousticVelocity >( getName() ); - subRegion.registerField< wavesolverfields::AcousticDensity >( getName() ); + subRegion.registerField< acousticfields::AcousticVelocity >( getName() ); + subRegion.registerField< acousticfields::AcousticDensity >( getName() ); - subRegion.registerField< wavesolverfields::Velocity_x >( getName() ); - subRegion.registerField< wavesolverfields::Velocity_y >( getName() ); - subRegion.registerField< wavesolverfields::Velocity_z >( getName() ); + subRegion.registerField< acousticfields::Velocity_x >( getName() ); + subRegion.registerField< acousticfields::Velocity_y >( getName() ); + subRegion.registerField< acousticfields::Velocity_z >( getName() ); finiteElement::FiniteElementBase const & fe = subRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); @@ -123,9 +122,9 @@ void AcousticFirstOrderWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) constexpr localIndex numNodesPerElem = FE_TYPE::numNodes; - subRegion.getField< wavesolverfields::Velocity_x >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< wavesolverfields::Velocity_y >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< wavesolverfields::Velocity_z >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< acousticfields::Velocity_x >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< acousticfields::Velocity_y >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< acousticfields::Velocity_z >().resizeDimension< 1 >( numNodesPerElem ); } ); @@ -247,28 +246,6 @@ void AcousticFirstOrderWaveEquationSEM::precomputeSourceAndReceiverTerm( MeshLev } - -void AcousticFirstOrderWaveEquationSEM::addSourceToRightHandSide( integer const & cycleNumber, arrayView1d< real32 > const rhs ) -{ - arrayView2d< localIndex const > const sourceNodeIds = m_sourceNodeIds.toViewConst(); - arrayView2d< real64 const > const sourceConstants = m_sourceConstants.toViewConst(); - arrayView1d< localIndex const > const sourceIsAccessible = m_sourceIsAccessible.toViewConst(); - arrayView2d< real32 const > const sourceValue = m_sourceValue.toViewConst(); - - GEOS_THROW_IF( cycleNumber > sourceValue.size( 0 ), getDataContext() << ": Too many steps compared to array size", std::runtime_error ); - forAll< EXEC_POLICY >( sourceConstants.size( 0 ), [=] GEOS_HOST_DEVICE ( localIndex const isrc ) - { - if( sourceIsAccessible[isrc] == 1 ) - { - for( localIndex inode = 0; inode < sourceConstants.size( 1 ); ++inode ) - { - real32 const localIncrement = sourceConstants[isrc][inode] * sourceValue[cycleNumber][isrc]; - RAJA::atomicAdd< ATOMIC_POLICY >( &rhs[sourceNodeIds[isrc][inode]], localIncrement ); - } - } - } ); -} - void AcousticFirstOrderWaveEquationSEM::initializePostInitialConditionsPreSubGroups() { WaveSolverBase::initializePostInitialConditionsPreSubGroups(); @@ -294,23 +271,23 @@ void AcousticFirstOrderWaveEquationSEM::initializePostInitialConditionsPreSubGro ArrayOfArraysView< localIndex const > const facesToNodes = faceManager.nodeList().toViewConst(); // mass matrix to be computed in this function - arrayView1d< real32 > const mass = nodeManager.getField< wavesolverfields::AcousticMassVector >(); + arrayView1d< real32 > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); /// damping matrix to be computed for each dof in the boundary of the mesh - arrayView1d< real32 > const damping = nodeManager.getField< wavesolverfields::DampingVector >(); + arrayView1d< real32 > const damping = nodeManager.getField< acousticfields::DampingVector >(); damping.zero(); mass.zero(); /// get array of indicators: 1 if face is on the free surface; 0 otherwise - arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< wavesolverfields::AcousticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< acousticfields::AcousticFreeSurfaceFaceIndicator >(); mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const, CellElementSubRegion & elementSubRegion ) { arrayView2d< localIndex const, cells::NODE_MAP_USD > const elemsToNodes = elementSubRegion.nodeList(); arrayView2d< localIndex const > const elemsToFaces = elementSubRegion.faceList(); - arrayView1d< real32 const > const velocity = elementSubRegion.getField< wavesolverfields::AcousticVelocity >(); - arrayView1d< real32 const > const density = elementSubRegion.getField< wavesolverfields::AcousticDensity >(); + arrayView1d< real32 const > const velocity = elementSubRegion.getField< acousticfields::AcousticVelocity >(); + arrayView1d< real32 const > const density = elementSubRegion.getField< acousticfields::AcousticDensity >(); finiteElement::FiniteElementBase const & fe = elementSubRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); @@ -353,15 +330,15 @@ void AcousticFirstOrderWaveEquationSEM::applyFreeSurfaceBC( real64 const time, D FaceManager & faceManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getFaceManager(); NodeManager & nodeManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getNodeManager(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< wavesolverfields::Pressure_np1 >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); ArrayOfArraysView< localIndex const > const faceToNodeMap = faceManager.nodeList().toViewConst(); /// array of indicators: 1 if a face is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< wavesolverfields::AcousticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< acousticfields::AcousticFreeSurfaceFaceIndicator >(); /// array of indicators: 1 if a node is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< wavesolverfields::AcousticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< acousticfields::AcousticFreeSurfaceNodeIndicator >(); freeSurfaceFaceIndicator.zero(); @@ -455,21 +432,21 @@ real64 AcousticFirstOrderWaveEquationSEM::explicitStepInternal( real64 const & t arrayView2d< wsCoordType const, nodes::REFERENCE_POSITION_USD > const X = nodeManager.getField< fields::referencePosition32 >().toViewConst(); - arrayView1d< real32 const > const mass = nodeManager.getField< wavesolverfields::AcousticMassVector >(); - arrayView1d< real32 const > const damping = nodeManager.getField< wavesolverfields::DampingVector >(); + arrayView1d< real32 const > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); + arrayView1d< real32 const > const damping = nodeManager.getField< acousticfields::DampingVector >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< wavesolverfields::Pressure_np1 >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); - arrayView1d< real32 > const rhs = nodeManager.getField< wavesolverfields::ForcingRHS >(); + arrayView1d< real32 > const rhs = nodeManager.getField< acousticfields::ForcingRHS >(); mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const regionIndex, CellElementSubRegion & elementSubRegion ) { arrayView2d< localIndex const, cells::NODE_MAP_USD > const & elemsToNodes = elementSubRegion.nodeList(); - arrayView1d< real32 const > const density = elementSubRegion.getField< wavesolverfields::AcousticDensity >(); - arrayView2d< real32 > const velocity_x = elementSubRegion.getField< wavesolverfields::Velocity_x >(); - arrayView2d< real32 > const velocity_y = elementSubRegion.getField< wavesolverfields::Velocity_y >(); - arrayView2d< real32 > const velocity_z = elementSubRegion.getField< wavesolverfields::Velocity_z >(); + arrayView1d< real32 const > const density = elementSubRegion.getField< acousticfields::AcousticDensity >(); + arrayView2d< real32 > const velocity_x = elementSubRegion.getField< acousticfields::Velocity_x >(); + arrayView2d< real32 > const velocity_y = elementSubRegion.getField< acousticfields::Velocity_y >(); + arrayView2d< real32 > const velocity_z = elementSubRegion.getField< acousticfields::Velocity_z >(); finiteElement::FiniteElementBase const & fe = elementSubRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); finiteElement::FiniteElementDispatchHandler< SEM_FE_TYPES >::dispatch3D( fe, [&] ( auto const finiteElement ) @@ -523,8 +500,8 @@ real64 AcousticFirstOrderWaveEquationSEM::explicitStepInternal( real64 const & t } ); FieldIdentifiers fieldsToBeSync; - fieldsToBeSync.addFields( FieldLocation::Node, { wavesolverfields::Pressure_np1::key() } ); - fieldsToBeSync.addElementFields( {wavesolverfields::Velocity_x::key(), wavesolverfields::Velocity_y::key(), wavesolverfields::Velocity_z::key()}, regionNames ); + fieldsToBeSync.addFields( FieldLocation::Node, { acousticfields::Pressure_np1::key() } ); + fieldsToBeSync.addElementFields( {acousticfields::Velocity_x::key(), acousticfields::Velocity_y::key(), acousticfields::Velocity_z::key()}, regionNames ); CommunicationTools & syncFields = CommunicationTools::getInstance(); syncFields.synchronizeFields( fieldsToBeSync, @@ -550,13 +527,13 @@ void AcousticFirstOrderWaveEquationSEM::cleanup( real64 const time_n, integer co arrayView1d< string const > const & regionNames ) { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const p_np1 = nodeManager.getField< wavesolverfields::Pressure_np1 >(); + arrayView1d< real32 const > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const regionIndex, CellElementSubRegion & elementSubRegion ) { - arrayView2d< real32 > const velocity_x = elementSubRegion.getField< wavesolverfields::Velocity_x >(); - arrayView2d< real32 > const velocity_y = elementSubRegion.getField< wavesolverfields::Velocity_y >(); - arrayView2d< real32 > const velocity_z = elementSubRegion.getField< wavesolverfields::Velocity_z >(); + arrayView2d< real32 > const velocity_x = elementSubRegion.getField< acousticfields::Velocity_x >(); + arrayView2d< real32 > const velocity_y = elementSubRegion.getField< acousticfields::Velocity_y >(); + arrayView2d< real32 > const velocity_z = elementSubRegion.getField< acousticfields::Velocity_z >(); arrayView2d< real32 > const uxReceivers = m_uxNp1AtReceivers.toView(); arrayView2d< real32 > const uyReceivers = m_uyNp1AtReceivers.toView(); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.hpp index 2ed6728bb22..14a6dc502ae 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.hpp @@ -21,7 +21,7 @@ #define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICFIRSTORDERWAVEEQUATIONSEM_HPP_ #include "mesh/MeshFields.hpp" -#include "WaveSolverBaseFields.hpp" +#include "AcousticFields.hpp" #include "WaveSolverBase.hpp" namespace geos @@ -34,12 +34,6 @@ class AcousticFirstOrderWaveEquationSEM : public WaveSolverBase using EXEC_POLICY = parallelDevicePolicy< >; using ATOMIC_POLICY = parallelDeviceAtomic; - - /** - * @brief Safeguard for timeStep. Used to avoid memory issue due to too small value. - */ - static constexpr real64 epsilonLoc = 1e-8; - AcousticFirstOrderWaveEquationSEM( const std::string & name, Group * const parent ); @@ -73,15 +67,6 @@ class AcousticFirstOrderWaveEquationSEM : public WaveSolverBase integer const cycleNumber, DomainPartition & domain, bool const computeGradient ) override; - /**@}*/ - - /** - * @brief Multiply the precomputed term by the Ricker and add to the right-hand side - * @param cycleNumber the cycle number/step number of evaluation of the source - * @param rhs the right hand side vector to be computed - */ - virtual void addSourceToRightHandSide( integer const & cycleNumber, arrayView1d< real32 > const rhs ); - /** * @brief Initialize Perfectly Matched Layer (PML) information diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIFields.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIFields.hpp new file mode 100644 index 00000000000..a361d77e55c --- /dev/null +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIFields.hpp @@ -0,0 +1,193 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + + +/** + * @file AcousticVTIFields.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICVTIFIELDS_HPP_ +#define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICVTIFIELDS_HPP_ + +#include "common/DataLayouts.hpp" +#include "mesh/MeshFields.hpp" + + +namespace geos +{ + +namespace fields +{ + +namespace acousticvtifields +{ + +DECLARE_FIELD( Delta, + "delta", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Delta thomsen anisotropy parameter" ); + +DECLARE_FIELD( Epsilon, + "epsilon", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Epsilon thomsen anisotropy parameter" ); + +DECLARE_FIELD( F, + "f", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "f quantity in VTI/TTI Fletcher's equations" ); + +DECLARE_FIELD( StiffnessVector_p, + "stiffnessVector_p", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Stiffness vector contains R_h*Pressure_n." ); + +DECLARE_FIELD( StiffnessVector_q, + "stiffnessVector_q", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Stiffness vector contains R_h*Pressure_n." ); + +DECLARE_FIELD( Pressure_p_nm1, + "pressure_p_nm1", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Scalar pressure at time n-1." ); + +DECLARE_FIELD( Pressure_p_n, + "pressure_p_n", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Scalar pressure at time n." ); + +DECLARE_FIELD( Pressure_p_np1, + "pressure_p_np1", + array1d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "Scalar pressure at time n+1." ); + +DECLARE_FIELD( Pressure_q_nm1, + "pressure_q_nm1", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Scalar auxiliary pressure q at time n-1." ); + +DECLARE_FIELD( Pressure_q_n, + "pressure_q_n", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Scalar auxiliary pressure q at time n." ); + +DECLARE_FIELD( Pressure_q_np1, + "pressure_q_np1", + array1d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "Scalar auxiliary pressure q at time n+1." ); + +DECLARE_FIELD( DampingVector_p, + "dampingVector_p", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Diagonal of the Damping Matrix for p terms in p equation." ); + +DECLARE_FIELD( DampingVector_pq, + "dampingVector_pq", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Diagonal of the Damping Matrix for q terms in p equation." ); + +DECLARE_FIELD( DampingVector_q, + "dampingVector_q", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Diagonal of the Damping Matrix for q terms in q equation." ); + +DECLARE_FIELD( DampingVector_qp, + "dampingVector_qp", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Diagonal of the Damping Matrix for p terms in q equation." ); + +DECLARE_FIELD( LateralSurfaceFaceIndicator, + "lateralSurfaceFaceIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Free surface indicator, 1 if a face is on a lateral surface 0 otherwise." ); + +DECLARE_FIELD( LateralSurfaceNodeIndicator, + "lateralSurfaceNodeIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Lateral surface indicator, 1 if a face is on a lateral surface 0 otherwise." ); + +DECLARE_FIELD( BottomSurfaceFaceIndicator, + "bottomSurfaceFaceIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Bottom surface indicator, 1 if a face is on the bottom surface 0 otherwise." ); + +DECLARE_FIELD( BottomSurfaceNodeIndicator, + "bottomSurfaceNodeIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Bottom surface indicator, 1 if a face is on the bottom surface 0 otherwise." ); +} + +} + +} /* namespace geos */ + +#endif /* GEOS_PHYSICSSOLVERS_WAVEPROPAGATION__HPP_ACOUSTICVTIFIELDS */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.cpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.cpp index 08e6b724d8f..967327730a6 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.cpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.cpp @@ -27,12 +27,12 @@ #include "mesh/ElementType.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "WaveSolverUtils.hpp" -#include "WaveSolverBaseFields.hpp" namespace geos { using namespace dataRepository; +using namespace fields; AcousticVTIWaveEquationSEM::AcousticVTIWaveEquationSEM( const std::string & name, Group * const parent ): @@ -62,38 +62,38 @@ void AcousticVTIWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) { NodeManager & nodeManager = mesh.getNodeManager(); - nodeManager.registerField< fields::wavesolverfields::Pressure_p_nm1, - fields::wavesolverfields::Pressure_p_n, - fields::wavesolverfields::Pressure_p_np1, - fields::wavesolverfields::Pressure_q_nm1, - fields::wavesolverfields::Pressure_q_n, - fields::wavesolverfields::Pressure_q_np1, - fields::wavesolverfields::ForcingRHS, - fields::wavesolverfields::AcousticMassVector, - fields::wavesolverfields::DampingVector_p, - fields::wavesolverfields::DampingVector_pq, - fields::wavesolverfields::DampingVector_q, - fields::wavesolverfields::DampingVector_qp, - fields::wavesolverfields::StiffnessVector_p, - fields::wavesolverfields::StiffnessVector_q, - fields::wavesolverfields::AcousticFreeSurfaceNodeIndicator, - fields::wavesolverfields::LateralSurfaceNodeIndicator, - fields::wavesolverfields::BottomSurfaceNodeIndicator >( getName() ); + nodeManager.registerField< acousticvtifields::Pressure_p_nm1, + acousticvtifields::Pressure_p_n, + acousticvtifields::Pressure_p_np1, + acousticvtifields::Pressure_q_nm1, + acousticvtifields::Pressure_q_n, + acousticvtifields::Pressure_q_np1, + acousticfields::ForcingRHS, + acousticfields::AcousticMassVector, + acousticvtifields::DampingVector_p, + acousticvtifields::DampingVector_pq, + acousticvtifields::DampingVector_q, + acousticvtifields::DampingVector_qp, + acousticvtifields::StiffnessVector_p, + acousticvtifields::StiffnessVector_q, + acousticfields::AcousticFreeSurfaceNodeIndicator, + acousticvtifields::LateralSurfaceNodeIndicator, + acousticvtifields::BottomSurfaceNodeIndicator >( getName() ); FaceManager & faceManager = mesh.getFaceManager(); - faceManager.registerField< fields::wavesolverfields::AcousticFreeSurfaceFaceIndicator >( getName() ); - faceManager.registerField< fields::wavesolverfields::LateralSurfaceFaceIndicator >( getName() ); - faceManager.registerField< fields::wavesolverfields::BottomSurfaceFaceIndicator >( getName() ); + faceManager.registerField< acousticfields::AcousticFreeSurfaceFaceIndicator >( getName() ); + faceManager.registerField< acousticvtifields::LateralSurfaceFaceIndicator >( getName() ); + faceManager.registerField< acousticvtifields::BottomSurfaceFaceIndicator >( getName() ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< CellElementSubRegion >( [&]( CellElementSubRegion & subRegion ) { - subRegion.registerField< fields::wavesolverfields::Delta >( getName() ); - subRegion.registerField< fields::wavesolverfields::Epsilon >( getName() ); - subRegion.registerField< fields::wavesolverfields::F >( getName() ); - subRegion.registerField< fields::wavesolverfields::AcousticVelocity >( getName() ); + subRegion.registerField< acousticvtifields::Delta >( getName() ); + subRegion.registerField< acousticvtifields::Epsilon >( getName() ); + subRegion.registerField< acousticvtifields::F >( getName() ); + subRegion.registerField< acousticfields::AcousticVelocity >( getName() ); } ); } ); } @@ -248,22 +248,22 @@ void AcousticVTIWaveEquationSEM::initializePostInitialConditionsPreSubGroups() ArrayOfArraysView< localIndex const > const facesToNodes = faceManager.nodeList().toViewConst(); // mass matrix to be computed in this function - arrayView1d< real32 > const mass = nodeManager.getField< fields::wavesolverfields::AcousticMassVector >(); + arrayView1d< real32 > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); mass.zero(); /// damping matrices to be computed for each dof in the boundary of the mesh - arrayView1d< real32 > const damping_p = nodeManager.getField< fields::wavesolverfields::DampingVector_p >(); - arrayView1d< real32 > const damping_pq = nodeManager.getField< fields::wavesolverfields::DampingVector_pq >(); - arrayView1d< real32 > const damping_q = nodeManager.getField< fields::wavesolverfields::DampingVector_q >(); - arrayView1d< real32 > const damping_qp = nodeManager.getField< fields::wavesolverfields::DampingVector_qp >(); + arrayView1d< real32 > const damping_p = nodeManager.getField< acousticvtifields::DampingVector_p >(); + arrayView1d< real32 > const damping_pq = nodeManager.getField< acousticvtifields::DampingVector_pq >(); + arrayView1d< real32 > const damping_q = nodeManager.getField< acousticvtifields::DampingVector_q >(); + arrayView1d< real32 > const damping_qp = nodeManager.getField< acousticvtifields::DampingVector_qp >(); damping_p.zero(); damping_pq.zero(); damping_q.zero(); damping_qp.zero(); /// get array of indicators: 1 if face is on the free surface; 0 otherwise - arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< fields::wavesolverfields::AcousticFreeSurfaceFaceIndicator >(); - arrayView1d< localIndex const > const lateralSurfaceFaceIndicator = faceManager.getField< fields::wavesolverfields::LateralSurfaceFaceIndicator >(); - arrayView1d< localIndex const > const bottomSurfaceFaceIndicator = faceManager.getField< fields::wavesolverfields::BottomSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< acousticfields::AcousticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const lateralSurfaceFaceIndicator = faceManager.getField< acousticvtifields::LateralSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const bottomSurfaceFaceIndicator = faceManager.getField< acousticvtifields::BottomSurfaceFaceIndicator >(); mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const, CellElementSubRegion & elementSubRegion ) @@ -271,10 +271,10 @@ void AcousticVTIWaveEquationSEM::initializePostInitialConditionsPreSubGroups() arrayView2d< localIndex const, cells::NODE_MAP_USD > const elemsToNodes = elementSubRegion.nodeList(); arrayView2d< localIndex const > const elemsToFaces = elementSubRegion.faceList(); - arrayView1d< real32 const > const velocity = elementSubRegion.getField< fields::wavesolverfields::AcousticVelocity >(); - arrayView1d< real32 const > const epsilon = elementSubRegion.getField< fields::wavesolverfields::Epsilon >(); - arrayView1d< real32 const > const delta = elementSubRegion.getField< fields::wavesolverfields::Delta >(); - arrayView1d< real32 const > const vti_f = elementSubRegion.getField< fields::wavesolverfields::F >(); + arrayView1d< real32 const > const velocity = elementSubRegion.getField< acousticfields::AcousticVelocity >(); + arrayView1d< real32 const > const epsilon = elementSubRegion.getField< acousticvtifields::Epsilon >(); + arrayView1d< real32 const > const delta = elementSubRegion.getField< acousticvtifields::Delta >(); + arrayView1d< real32 const > const vti_f = elementSubRegion.getField< acousticvtifields::F >(); finiteElement::FiniteElementBase const & fe = elementSubRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); @@ -327,14 +327,14 @@ void AcousticVTIWaveEquationSEM::precomputeSurfaceFieldIndicator( DomainPartitio ArrayOfArraysView< localIndex const > const faceToNodeMap = faceManager.nodeList().toViewConst(); /// array of indicators: 1 if a face is on on lateral surface; 0 otherwise - arrayView1d< localIndex > const lateralSurfaceFaceIndicator = faceManager.getField< fields::wavesolverfields::LateralSurfaceFaceIndicator >(); + arrayView1d< localIndex > const lateralSurfaceFaceIndicator = faceManager.getField< acousticvtifields::LateralSurfaceFaceIndicator >(); /// array of indicators: 1 if a node is on on lateral surface; 0 otherwise - arrayView1d< localIndex > const lateralSurfaceNodeIndicator = nodeManager.getField< fields::wavesolverfields::LateralSurfaceNodeIndicator >(); + arrayView1d< localIndex > const lateralSurfaceNodeIndicator = nodeManager.getField< acousticvtifields::LateralSurfaceNodeIndicator >(); /// array of indicators: 1 if a face is on on bottom surface; 0 otherwise - arrayView1d< localIndex > const bottomSurfaceFaceIndicator = faceManager.getField< fields::wavesolverfields::BottomSurfaceFaceIndicator >(); + arrayView1d< localIndex > const bottomSurfaceFaceIndicator = faceManager.getField< acousticvtifields::BottomSurfaceFaceIndicator >(); /// array of indicators: 1 if a node is on on bottom surface; 0 otherwise - arrayView1d< localIndex > const bottomSurfaceNodeIndicator = nodeManager.getField< fields::wavesolverfields::BottomSurfaceNodeIndicator >(); + arrayView1d< localIndex > const bottomSurfaceNodeIndicator = nodeManager.getField< acousticvtifields::BottomSurfaceNodeIndicator >(); // Lateral surfaces fsManager.apply< FaceManager >( time, @@ -411,21 +411,21 @@ void AcousticVTIWaveEquationSEM::applyFreeSurfaceBC( real64 time, DomainPartitio FaceManager & faceManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getFaceManager(); NodeManager & nodeManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getNodeManager(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< fields::wavesolverfields::Pressure_p_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticvtifields::Pressure_p_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< acousticvtifields::Pressure_p_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticvtifields::Pressure_p_np1 >(); - arrayView1d< real32 > const q_nm1 = nodeManager.getField< fields::wavesolverfields::Pressure_q_nm1 >(); - arrayView1d< real32 > const q_n = nodeManager.getField< fields::wavesolverfields::Pressure_q_n >(); - arrayView1d< real32 > const q_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_q_np1 >(); + arrayView1d< real32 > const q_nm1 = nodeManager.getField< acousticvtifields::Pressure_q_nm1 >(); + arrayView1d< real32 > const q_n = nodeManager.getField< acousticvtifields::Pressure_q_n >(); + arrayView1d< real32 > const q_np1 = nodeManager.getField< acousticvtifields::Pressure_q_np1 >(); ArrayOfArraysView< localIndex const > const faceToNodeMap = faceManager.nodeList().toViewConst(); /// array of indicators: 1 if a face is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< fields::wavesolverfields::AcousticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< acousticfields::AcousticFreeSurfaceFaceIndicator >(); /// array of indicators: 1 if a node is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< fields::wavesolverfields::AcousticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< acousticfields::AcousticFreeSurfaceNodeIndicator >(); fsManager.apply< FaceManager >( time, domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ), @@ -485,13 +485,13 @@ real64 AcousticVTIWaveEquationSEM::explicitStepForward( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< fields::wavesolverfields::Pressure_p_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticvtifields::Pressure_p_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< acousticvtifields::Pressure_p_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticvtifields::Pressure_p_np1 >(); - arrayView1d< real32 > const q_nm1 = nodeManager.getField< fields::wavesolverfields::Pressure_q_nm1 >(); - arrayView1d< real32 > const q_n = nodeManager.getField< fields::wavesolverfields::Pressure_q_n >(); - arrayView1d< real32 > const q_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_q_np1 >(); + arrayView1d< real32 > const q_nm1 = nodeManager.getField< acousticvtifields::Pressure_q_nm1 >(); + arrayView1d< real32 > const q_n = nodeManager.getField< acousticvtifields::Pressure_q_n >(); + arrayView1d< real32 > const q_np1 = nodeManager.getField< acousticvtifields::Pressure_q_np1 >(); if( computeGradient ) { @@ -551,26 +551,26 @@ real64 AcousticVTIWaveEquationSEM::explicitStepInternal( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const mass = nodeManager.getField< fields::wavesolverfields::AcousticMassVector >(); - arrayView1d< real32 const > const damping_p = nodeManager.getField< fields::wavesolverfields::DampingVector_p >(); - arrayView1d< real32 const > const damping_q = nodeManager.getField< fields::wavesolverfields::DampingVector_q >(); - arrayView1d< real32 const > const damping_pq = nodeManager.getField< fields::wavesolverfields::DampingVector_pq >(); - arrayView1d< real32 const > const damping_qp = nodeManager.getField< fields::wavesolverfields::DampingVector_qp >(); + arrayView1d< real32 const > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); + arrayView1d< real32 const > const damping_p = nodeManager.getField< acousticvtifields::DampingVector_p >(); + arrayView1d< real32 const > const damping_q = nodeManager.getField< acousticvtifields::DampingVector_q >(); + arrayView1d< real32 const > const damping_pq = nodeManager.getField< acousticvtifields::DampingVector_pq >(); + arrayView1d< real32 const > const damping_qp = nodeManager.getField< acousticvtifields::DampingVector_qp >(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< fields::wavesolverfields::Pressure_p_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticvtifields::Pressure_p_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< acousticvtifields::Pressure_p_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticvtifields::Pressure_p_np1 >(); - arrayView1d< real32 > const q_nm1 = nodeManager.getField< fields::wavesolverfields::Pressure_q_nm1 >(); - arrayView1d< real32 > const q_n = nodeManager.getField< fields::wavesolverfields::Pressure_q_n >(); - arrayView1d< real32 > const q_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_q_np1 >(); + arrayView1d< real32 > const q_nm1 = nodeManager.getField< acousticvtifields::Pressure_q_nm1 >(); + arrayView1d< real32 > const q_n = nodeManager.getField< acousticvtifields::Pressure_q_n >(); + arrayView1d< real32 > const q_np1 = nodeManager.getField< acousticvtifields::Pressure_q_np1 >(); - arrayView1d< localIndex const > const freeSurfaceNodeIndicator = nodeManager.getField< fields::wavesolverfields::AcousticFreeSurfaceNodeIndicator >(); - arrayView1d< localIndex const > const lateralSurfaceNodeIndicator = nodeManager.getField< fields::wavesolverfields::LateralSurfaceNodeIndicator >(); - arrayView1d< localIndex const > const bottomSurfaceNodeIndicator = nodeManager.getField< fields::wavesolverfields::BottomSurfaceNodeIndicator >(); - arrayView1d< real32 > const stiffnessVector_p = nodeManager.getField< fields::wavesolverfields::StiffnessVector_p >(); - arrayView1d< real32 > const stiffnessVector_q = nodeManager.getField< fields::wavesolverfields::StiffnessVector_q >(); - arrayView1d< real32 > const rhs = nodeManager.getField< fields::wavesolverfields::ForcingRHS >(); + arrayView1d< localIndex const > const freeSurfaceNodeIndicator = nodeManager.getField< acousticfields::AcousticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex const > const lateralSurfaceNodeIndicator = nodeManager.getField< acousticvtifields::LateralSurfaceNodeIndicator >(); + arrayView1d< localIndex const > const bottomSurfaceNodeIndicator = nodeManager.getField< acousticvtifields::BottomSurfaceNodeIndicator >(); + arrayView1d< real32 > const stiffnessVector_p = nodeManager.getField< acousticvtifields::StiffnessVector_p >(); + arrayView1d< real32 > const stiffnessVector_q = nodeManager.getField< acousticvtifields::StiffnessVector_q >(); + arrayView1d< real32 > const rhs = nodeManager.getField< acousticfields::ForcingRHS >(); auto kernelFactory = acousticVTIWaveEquationSEMKernels::ExplicitAcousticVTISEMFactory( dt ); @@ -637,8 +637,8 @@ real64 AcousticVTIWaveEquationSEM::explicitStepInternal( real64 const & time_n, /// synchronize pressure fields FieldIdentifiers fieldsToBeSync; - fieldsToBeSync.addFields( FieldLocation::Node, { fields::wavesolverfields::Pressure_p_np1::key() } ); - fieldsToBeSync.addFields( FieldLocation::Node, { fields::wavesolverfields::Pressure_q_np1::key() } ); + fieldsToBeSync.addFields( FieldLocation::Node, { acousticvtifields::Pressure_p_np1::key() } ); + fieldsToBeSync.addFields( FieldLocation::Node, { acousticvtifields::Pressure_q_np1::key() } ); CommunicationTools & syncFields = CommunicationTools::getInstance(); syncFields.synchronizeFields( fieldsToBeSync, @@ -680,8 +680,8 @@ void AcousticVTIWaveEquationSEM::cleanup( real64 const time_n, arrayView1d< string const > const & ) { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const p_n = nodeManager.getField< fields::wavesolverfields::Pressure_p_n >(); - arrayView1d< real32 const > const p_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_np1 >(); + arrayView1d< real32 const > const p_n = nodeManager.getField< acousticvtifields::Pressure_p_n >(); + arrayView1d< real32 const > const p_np1 = nodeManager.getField< acousticvtifields::Pressure_p_np1 >(); arrayView2d< real32 > const pReceivers = m_pressureNp1AtReceivers.toView(); computeAllSeismoTraces( time_n, 0.0, p_np1, p_n, pReceivers ); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.hpp index b0c152ec45e..932568e3f6e 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.hpp @@ -23,7 +23,8 @@ #include "mesh/MeshFields.hpp" #include "physicsSolvers/SolverBase.hpp" #include "WaveSolverBase.hpp" -#include "WaveSolverBaseFields.hpp" +#include "AcousticFields.hpp" +#include "AcousticVTIFields.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEMKernel.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEMKernel.hpp index eba56694b26..72cd2da8d73 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEMKernel.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEMKernel.hpp @@ -21,12 +21,12 @@ #include "finiteElement/elementFormulations/Qk_Hexahedron_Lagrange_GaussLobatto.hpp" #include "finiteElement/kernelInterface/KernelBase.hpp" -#include "WaveSolverBaseFields.hpp" #include "WaveSolverUtils.hpp" - +#include "AcousticVTIFields.hpp" namespace geos { +using namespace fields; /// Namespace to contain the acoustic wave kernels. namespace acousticVTIWaveEquationSEMKernels @@ -430,13 +430,13 @@ class ExplicitAcousticVTISEM : public finiteElement::KernelBase< SUBREGION_TYPE, finiteElementSpace, inputConstitutiveType ), m_nodeCoords( nodeManager.getField< fields::referencePosition32 >() ), - m_p_n( nodeManager.getField< fields::wavesolverfields::Pressure_p_n >() ), - m_q_n( nodeManager.getField< fields::wavesolverfields::Pressure_q_n >() ), - m_stiffnessVector_p( nodeManager.getField< fields::wavesolverfields::StiffnessVector_p >() ), - m_stiffnessVector_q( nodeManager.getField< fields::wavesolverfields::StiffnessVector_q >() ), - m_epsilon( elementSubRegion.template getField< fields::wavesolverfields::Epsilon >() ), - m_delta( elementSubRegion.template getField< fields::wavesolverfields::Delta >() ), - m_vti_f( elementSubRegion.template getField< fields::wavesolverfields::F >() ), + m_p_n( nodeManager.getField< acousticvtifields::Pressure_p_n >() ), + m_q_n( nodeManager.getField< acousticvtifields::Pressure_q_n >() ), + m_stiffnessVector_p( nodeManager.getField< acousticvtifields::StiffnessVector_p >() ), + m_stiffnessVector_q( nodeManager.getField< acousticvtifields::StiffnessVector_q >() ), + m_epsilon( elementSubRegion.template getField< acousticvtifields::Epsilon >() ), + m_delta( elementSubRegion.template getField< acousticvtifields::Delta >() ), + m_vti_f( elementSubRegion.template getField< acousticvtifields::F >() ), m_dt( dt ) { GEOS_UNUSED_VAR( edgeManager ); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.cpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.cpp index d822d1b5a06..0dc0f3f97c7 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.cpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.cpp @@ -32,6 +32,7 @@ namespace geos { using namespace dataRepository; +using namespace fields; AcousticWaveEquationSEM::AcousticWaveEquationSEM( const std::string & name, Group * const parent ): @@ -66,38 +67,38 @@ void AcousticWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) { NodeManager & nodeManager = mesh.getNodeManager(); - nodeManager.registerField< fields::Pressure_nm1, - fields::Pressure_n, - fields::Pressure_np1, - fields::PressureDoubleDerivative, - fields::ForcingRHS, - fields::AcousticMassVector, - fields::DampingVector, - fields::StiffnessVector, - fields::AcousticFreeSurfaceNodeIndicator >( getName() ); + nodeManager.registerField< acousticfields::Pressure_nm1, + acousticfields::Pressure_n, + acousticfields::Pressure_np1, + acousticfields::PressureDoubleDerivative, + acousticfields::ForcingRHS, + acousticfields::AcousticMassVector, + acousticfields::DampingVector, + acousticfields::StiffnessVector, + acousticfields::AcousticFreeSurfaceNodeIndicator >( getName() ); /// register PML auxiliary variables only when a PML is specified in the xml if( m_usePML ) { - nodeManager.registerField< fields::AuxiliaryVar1PML, - fields::AuxiliaryVar2PML, - fields::AuxiliaryVar3PML, - fields::AuxiliaryVar4PML >( getName() ); + nodeManager.registerField< acousticfields::AuxiliaryVar1PML, + acousticfields::AuxiliaryVar2PML, + acousticfields::AuxiliaryVar3PML, + acousticfields::AuxiliaryVar4PML >( getName() ); - nodeManager.getField< fields::AuxiliaryVar1PML >().resizeDimension< 1 >( 3 ); - nodeManager.getField< fields::AuxiliaryVar2PML >().resizeDimension< 1 >( 3 ); + nodeManager.getField< acousticfields::AuxiliaryVar1PML >().resizeDimension< 1 >( 3 ); + nodeManager.getField< acousticfields::AuxiliaryVar2PML >().resizeDimension< 1 >( 3 ); } FaceManager & faceManager = mesh.getFaceManager(); - faceManager.registerField< fields::AcousticFreeSurfaceFaceIndicator >( getName() ); + faceManager.registerField< acousticfields::AcousticFreeSurfaceFaceIndicator >( getName() ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< CellElementSubRegion >( [&]( CellElementSubRegion & subRegion ) { - subRegion.registerField< fields::AcousticVelocity >( getName() ); - subRegion.registerField< fields::AcousticDensity >( getName() ); - subRegion.registerField< fields::PartialGradient >( getName() ); + subRegion.registerField< acousticfields::AcousticVelocity >( getName() ); + subRegion.registerField< acousticfields::AcousticDensity >( getName() ); + subRegion.registerField< acousticfields::PartialGradient >( getName() ); } ); } ); @@ -261,19 +262,15 @@ void AcousticWaveEquationSEM::initializePostInitialConditionsPreSubGroups() ArrayOfArraysView< localIndex const > const facesToNodes = faceManager.nodeList().toViewConst(); // mass matrix to be computed in this function - arrayView1d< real32 > const mass = nodeManager.getField< fields::AcousticMassVector >(); - { - GEOS_MARK_SCOPE( mass_zero ); - mass.zero(); - } + arrayView1d< real32 > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); + mass.zero(); + /// damping matrix to be computed for each dof in the boundary of the mesh - arrayView1d< real32 > const damping = nodeManager.getField< fields::DampingVector >(); - { - GEOS_MARK_SCOPE( damping_zero ); - damping.zero(); - } + arrayView1d< real32 > const damping = nodeManager.getField< acousticfields::DampingVector >(); + damping.zero(); + /// get array of indicators: 1 if face is on the free surface; 0 otherwise - arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< fields::AcousticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< acousticfields::AcousticFreeSurfaceFaceIndicator >(); elemManager.forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const, CellElementSubRegion & elementSubRegion ) @@ -286,11 +283,11 @@ void AcousticWaveEquationSEM::initializePostInitialConditionsPreSubGroups() computeTargetNodeSet( elemsToNodes, elementSubRegion.size(), fe.getNumQuadraturePoints() ); - arrayView1d< real32 const > const velocity = elementSubRegion.getField< fields::AcousticVelocity >(); - arrayView1d< real32 const > const density = elementSubRegion.getField< fields::AcousticDensity >(); + arrayView1d< real32 const > const velocity = elementSubRegion.getField< acousticfields::AcousticVelocity >(); + arrayView1d< real32 const > const density = elementSubRegion.getField< acousticfields::AcousticDensity >(); /// Partial gradient if gradient as to be computed - arrayView1d< real32 > grad = elementSubRegion.getField< fields::PartialGradient >(); + arrayView1d< real32 > grad = elementSubRegion.getField< acousticfields::PartialGradient >(); grad.zero(); finiteElement::FiniteElementDispatchHandler< SEM_FE_TYPES >::dispatch3D( fe, [&] ( auto const finiteElement ) @@ -304,19 +301,18 @@ void AcousticWaveEquationSEM::initializePostInitialConditionsPreSubGroups() velocity, density, mass ); - { - GEOS_MARK_SCOPE( DampingMatrixKernel ); - acousticWaveEquationSEMKernels::DampingMatrixKernel< FE_TYPE > kernelD( finiteElement ); - kernelD.template launch< EXEC_POLICY, ATOMIC_POLICY >( elementSubRegion.size(), - nodeCoords, - elemsToFaces, - facesToNodes, - facesDomainBoundaryIndicator, - freeSurfaceFaceIndicator, - velocity, - density, - damping ); - } + + acousticWaveEquationSEMKernels::DampingMatrixKernel< FE_TYPE > kernelD( finiteElement ); + kernelD.template launch< EXEC_POLICY, ATOMIC_POLICY >( elementSubRegion.size(), + nodeCoords, + elemsToFaces, + facesToNodes, + facesDomainBoundaryIndicator, + freeSurfaceFaceIndicator, + velocity, + density, + damping ); + } ); } ); } ); @@ -334,17 +330,17 @@ void AcousticWaveEquationSEM::applyFreeSurfaceBC( real64 time, DomainPartition & FaceManager & faceManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getFaceManager(); NodeManager & nodeManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getNodeManager(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::Pressure_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< fields::Pressure_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticfields::Pressure_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); ArrayOfArraysView< localIndex const > const faceToNodeMap = faceManager.nodeList().toViewConst(); /// array of indicators: 1 if a face is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< fields::AcousticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< acousticfields::AcousticFreeSurfaceFaceIndicator >(); /// array of indicators: 1 if a node is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< fields::AcousticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< acousticfields::AcousticFreeSurfaceNodeIndicator >(); // freeSurfaceFaceIndicator.zero(); // freeSurfaceNodeIndicator.zero(); @@ -429,7 +425,7 @@ void AcousticWaveEquationSEM::initializePML() NodeManager & nodeManager = mesh.getNodeManager(); /// WARNING: the array below is one of the PML auxiliary variables - arrayView1d< real32 > const indicatorPML = nodeManager.getField< fields::AuxiliaryVar4PML >(); + arrayView1d< real32 > const indicatorPML = nodeManager.getField< acousticfields::AuxiliaryVar4PML >(); arrayView2d< wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords32 = nodeManager.getField< fields::referencePosition32 >().toViewConst(); indicatorPML.zero(); @@ -558,7 +554,7 @@ void AcousticWaveEquationSEM::initializePML() CellElementSubRegion::NodeMapType const & elemToNodes = subRegion.getReference< CellElementSubRegion::NodeMapType >( CellElementSubRegion::viewKeyStruct::nodeListString() ); traits::ViewTypeConst< CellElementSubRegion::NodeMapType > const elemToNodesViewConst = elemToNodes.toViewConst(); - arrayView1d< real32 const > const vel = subRegion.getReference< array1d< real32 > >( fields::AcousticVelocity::key()); + arrayView1d< real32 const > const vel = subRegion.getReference< array1d< real32 > >( acousticfields::AcousticVelocity::key()); finiteElement::FiniteElementBase const & fe = subRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); @@ -659,11 +655,11 @@ void AcousticWaveEquationSEM::applyPML( real64 const time, DomainPartition & dom NodeManager & nodeManager = mesh.getNodeManager(); /// Array views of the pressure p, PML auxiliary variables, and node coordinates - arrayView1d< real32 const > const p_n = nodeManager.getField< fields::Pressure_n >(); - arrayView2d< real32 const > const v_n = nodeManager.getField< fields::AuxiliaryVar1PML >(); - arrayView2d< real32 > const grad_n = nodeManager.getField< fields::AuxiliaryVar2PML >(); - arrayView1d< real32 > const divV_n = nodeManager.getField< fields::AuxiliaryVar3PML >(); - arrayView1d< real32 const > const u_n = nodeManager.getField< fields::AuxiliaryVar4PML >(); + arrayView1d< real32 const > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); + arrayView2d< real32 const > const v_n = nodeManager.getField< acousticfields::AuxiliaryVar1PML >(); + arrayView2d< real32 > const grad_n = nodeManager.getField< acousticfields::AuxiliaryVar2PML >(); + arrayView1d< real32 > const divV_n = nodeManager.getField< acousticfields::AuxiliaryVar3PML >(); + arrayView1d< real32 const > const u_n = nodeManager.getField< acousticfields::AuxiliaryVar4PML >(); arrayView2d< wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords32 = nodeManager.getField< fields::referencePosition32 >().toViewConst(); /// Select the subregions concerned by the PML (specified in the xml by the Field Specification) @@ -688,7 +684,7 @@ void AcousticWaveEquationSEM::applyPML( real64 const time, DomainPartition & dom traits::ViewTypeConst< CellElementSubRegion::NodeMapType > const elemToNodesViewConst = elemToNodes.toViewConst(); /// Array view of the wave speed - arrayView1d< real32 const > const vel = subRegion.getReference< array1d< real32 > >( fields::AcousticVelocity::key()); + arrayView1d< real32 const > const vel = subRegion.getReference< array1d< real32 > >( acousticfields::AcousticVelocity::key()); /// Get the object needed to determine the type of the element in the subregion finiteElement::FiniteElementBase const & @@ -757,14 +753,14 @@ real64 AcousticWaveEquationSEM::explicitStepForward( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::Pressure_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< fields::Pressure_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticfields::Pressure_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); if( computeGradient && cycleNumber >= 0 ) { - arrayView1d< real32 > const p_dt2 = nodeManager.getField< fields::PressureDoubleDerivative >(); + arrayView1d< real32 > const p_dt2 = nodeManager.getField< acousticfields::PressureDoubleDerivative >(); if( m_enableLifo ) { @@ -801,10 +797,6 @@ real64 AcousticWaveEquationSEM::explicitStepForward( real64 const & time_n, makeDirsForPath( dirName ); } - //std::string fileName = GEOS_FMT( "pressuredt2_{:06}_{:08}_{:04}.dat", m_shotIndex, cycleNumber, rank ); - //const int fileDesc = open( fileName.c_str(), O_CREAT | O_WRONLY | O_DIRECT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | - // S_IROTH | S_IWOTH ); - std::ofstream wf( fileName, std::ios::out | std::ios::binary ); GEOS_THROW_IF( !wf, getDataContext() << ": Could not open file "<< fileName << " for writing", @@ -839,11 +831,11 @@ real64 AcousticWaveEquationSEM::explicitStepBackward( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const mass = nodeManager.getField< fields::AcousticMassVector >(); + arrayView1d< real32 const > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::Pressure_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< fields::Pressure_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticfields::Pressure_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); EventManager const & event = getGroupByPath< EventManager >( "/Problem/Events" ); real64 const & maxTime = event.getReference< real64 >( EventManager::viewKeyStruct::maxTimeString() ); @@ -853,7 +845,7 @@ real64 AcousticWaveEquationSEM::explicitStepBackward( real64 const & time_n, { ElementRegionManager & elemManager = mesh.getElemManager(); - arrayView1d< real32 > const p_dt2 = nodeManager.getField< fields::PressureDoubleDerivative >(); + arrayView1d< real32 > const p_dt2 = nodeManager.getField< acousticfields::PressureDoubleDerivative >(); if( m_enableLifo ) { @@ -871,11 +863,7 @@ real64 AcousticWaveEquationSEM::explicitStepBackward( real64 const & time_n, GEOS_THROW_IF( !wf, getDataContext() << ": Could not open file "<< fileName << " for reading", InputError ); - //std::string fileName = GEOS_FMT( "pressuredt2_{:06}_{:08}_{:04}.dat", m_shotIndex, cycleNumber, rank ); - //const int fileDesc = open( fileName.c_str(), O_RDONLY | O_DIRECT ); - //GEOS_ERROR_IF( fileDesc == -1, - // "Could not open file "<< fileName << " for reading: " << strerror( errno ) ); - // maybe better with registerTouch() + p_dt2.move( MemorySpace::host, true ); wf.read( (char *)&p_dt2[0], p_dt2.size()*sizeof( real32 ) ); wf.close( ); @@ -884,8 +872,8 @@ real64 AcousticWaveEquationSEM::explicitStepBackward( real64 const & time_n, elemManager.forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const, CellElementSubRegion & elementSubRegion ) { - arrayView1d< real32 const > const velocity = elementSubRegion.getField< fields::AcousticVelocity >(); - arrayView1d< real32 > grad = elementSubRegion.getField< fields::PartialGradient >(); + arrayView1d< real32 const > const velocity = elementSubRegion.getField< acousticfields::AcousticVelocity >(); + arrayView1d< real32 > grad = elementSubRegion.getField< acousticfields::PartialGradient >(); arrayView2d< localIndex const, cells::NODE_MAP_USD > const & elemsToNodes = elementSubRegion.nodeList(); constexpr localIndex numNodesPerElem = 8; arrayView1d< integer const > const elemGhostRank = elementSubRegion.ghostRank(); @@ -914,12 +902,12 @@ void AcousticWaveEquationSEM::prepareNextTimestep( MeshLevel & mesh ) { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::Pressure_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< fields::Pressure_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticfields::Pressure_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); - arrayView1d< real32 > const stiffnessVector = nodeManager.getField< fields::StiffnessVector >(); - arrayView1d< real32 > const rhs = nodeManager.getField< fields::ForcingRHS >(); + arrayView1d< real32 > const stiffnessVector = nodeManager.getField< acousticfields::StiffnessVector >(); + arrayView1d< real32 > const rhs = nodeManager.getField< acousticfields::ForcingRHS >(); SortedArrayView< localIndex const > const solverTargetNodesSet = m_solverTargetNodesSet.toViewConst(); @@ -943,16 +931,16 @@ void AcousticWaveEquationSEM::computeUnknowns( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const mass = nodeManager.getField< fields::AcousticMassVector >(); - arrayView1d< real32 const > const damping = nodeManager.getField< fields::DampingVector >(); + arrayView1d< real32 const > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); + arrayView1d< real32 const > const damping = nodeManager.getField< acousticfields::DampingVector >(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::Pressure_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< fields::Pressure_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticfields::Pressure_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); - arrayView1d< localIndex const > const freeSurfaceNodeIndicator = nodeManager.getField< fields::AcousticFreeSurfaceNodeIndicator >(); - arrayView1d< real32 > const stiffnessVector = nodeManager.getField< fields::StiffnessVector >(); - arrayView1d< real32 > const rhs = nodeManager.getField< fields::ForcingRHS >(); + arrayView1d< localIndex const > const freeSurfaceNodeIndicator = nodeManager.getField< acousticfields::AcousticFreeSurfaceNodeIndicator >(); + arrayView1d< real32 > const stiffnessVector = nodeManager.getField< acousticfields::StiffnessVector >(); + arrayView1d< real32 > const rhs = nodeManager.getField< acousticfields::ForcingRHS >(); auto kernelFactory = acousticWaveEquationSEMKernels::ExplicitAcousticSEMFactory( dt ); @@ -993,10 +981,10 @@ void AcousticWaveEquationSEM::computeUnknowns( real64 const & time_n, else { parametersPML const & param = getReference< parametersPML >( viewKeyStruct::parametersPMLString() ); - arrayView2d< real32 > const v_n = nodeManager.getField< fields::AuxiliaryVar1PML >(); - arrayView2d< real32 > const grad_n = nodeManager.getField< fields::AuxiliaryVar2PML >(); - arrayView1d< real32 > const divV_n = nodeManager.getField< fields::AuxiliaryVar3PML >(); - arrayView1d< real32 > const u_n = nodeManager.getField< fields::AuxiliaryVar4PML >(); + arrayView2d< real32 > const v_n = nodeManager.getField< acousticfields::AuxiliaryVar1PML >(); + arrayView2d< real32 > const grad_n = nodeManager.getField< acousticfields::AuxiliaryVar2PML >(); + arrayView1d< real32 > const divV_n = nodeManager.getField< acousticfields::AuxiliaryVar3PML >(); + arrayView1d< real32 > const u_n = nodeManager.getField< acousticfields::AuxiliaryVar4PML >(); arrayView2d< wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords32 = nodeManager.getField< fields::referencePosition32 >().toViewConst(); @@ -1063,21 +1051,21 @@ void AcousticWaveEquationSEM::synchronizeUnknowns( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 > const p_n = nodeManager.getField< fields::Pressure_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); - arrayView1d< real32 > const stiffnessVector = nodeManager.getField< fields::StiffnessVector >(); - arrayView1d< real32 > const rhs = nodeManager.getField< fields::ForcingRHS >(); + arrayView1d< real32 > const stiffnessVector = nodeManager.getField< acousticfields::StiffnessVector >(); + arrayView1d< real32 > const rhs = nodeManager.getField< acousticfields::ForcingRHS >(); /// synchronize pressure fields FieldIdentifiers fieldsToBeSync; - fieldsToBeSync.addFields( FieldLocation::Node, { fields::Pressure_np1::key() } ); + fieldsToBeSync.addFields( FieldLocation::Node, { acousticfields::Pressure_np1::key() } ); if( m_usePML ) { fieldsToBeSync.addFields( FieldLocation::Node, { - fields::AuxiliaryVar1PML::key(), - fields::AuxiliaryVar4PML::key() } ); + acousticfields::AuxiliaryVar1PML::key(), + acousticfields::AuxiliaryVar4PML::key() } ); } CommunicationTools & syncFields = CommunicationTools::getInstance(); @@ -1093,8 +1081,8 @@ void AcousticWaveEquationSEM::synchronizeUnknowns( real64 const & time_n, if( m_usePML ) { - arrayView2d< real32 > const grad_n = nodeManager.getField< fields::AuxiliaryVar2PML >(); - arrayView1d< real32 > const divV_n = nodeManager.getField< fields::AuxiliaryVar3PML >(); + arrayView2d< real32 > const grad_n = nodeManager.getField< acousticfields::AuxiliaryVar2PML >(); + arrayView1d< real32 > const divV_n = nodeManager.getField< acousticfields::AuxiliaryVar3PML >(); grad_n.zero(); divV_n.zero(); } @@ -1135,8 +1123,8 @@ void AcousticWaveEquationSEM::cleanup( real64 const time_n, arrayView1d< string const > const & ) { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const p_n = nodeManager.getField< fields::Pressure_n >(); - arrayView1d< real32 const > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); + arrayView1d< real32 const > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); + arrayView1d< real32 const > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); arrayView2d< real32 > const pReceivers = m_pressureNp1AtReceivers.toView(); computeAllSeismoTraces( time_n, 0.0, p_np1, p_n, pReceivers ); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.hpp index 67ea9982df2..9396a8201bf 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.hpp @@ -23,6 +23,7 @@ #include "WaveSolverBase.hpp" #include "mesh/MeshFields.hpp" #include "physicsSolvers/SolverBase.hpp" +#include "AcousticFields.hpp" namespace geos { @@ -169,148 +170,6 @@ class AcousticWaveEquationSEM : public WaveSolverBase }; - -namespace fields -{ - -DECLARE_FIELD( Pressure_nm1, - "pressure_nm1", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Scalar pressure at time n-1." ); - -DECLARE_FIELD( Pressure_n, - "pressure_n", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Scalar pressure at time n." ); - -DECLARE_FIELD( Pressure_np1, - "pressure_np1", - array1d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "Scalar pressure at time n+1." ); - -DECLARE_FIELD( ForcingRHS, - "rhs", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "RHS" ); - -DECLARE_FIELD( AcousticMassVector, - "acousticMassVector", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal of the Mass Matrix." ); - -DECLARE_FIELD( DampingVector, - "dampingVector", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal of the Damping Matrix." ); - -DECLARE_FIELD( AcousticVelocity, - "acousticVelocity", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Medium velocity of the cell" ); - -DECLARE_FIELD( AcousticDensity, - "acousticDensity", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Medium density of the cell" ); - -DECLARE_FIELD( StiffnessVector, - "stiffnessVector", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Stiffness vector contains R_h*Pressure_n." ); - -DECLARE_FIELD( AcousticFreeSurfaceFaceIndicator, - "acousticFreeSurfaceFaceIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Free surface indicator, 1 if a face is on free surface 0 otherwise." ); - -DECLARE_FIELD( AcousticFreeSurfaceNodeIndicator, - "acousticFreeSurfaceNodeIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Free surface indicator, 1 if a node is on free surface 0 otherwise." ); - -DECLARE_FIELD( PressureDoubleDerivative, - "pressureDoubleDerivative", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Double derivative of the pressure for each node to compute the gradient" ); - -DECLARE_FIELD( PartialGradient, - "partialGradient", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Partiel gradient computed during backward propagation" ); - -DECLARE_FIELD( AuxiliaryVar1PML, - "auxiliaryVar1PML", - array2d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "PML vectorial auxiliary variable 1." ); - -DECLARE_FIELD( AuxiliaryVar2PML, - "auxiliaryVar2PML", - array2d< real32 >, - 0, - NOPLOT, - NO_WRITE, - "PML vectorial auxiliary variable 2." ); - -DECLARE_FIELD( AuxiliaryVar3PML, - "auxiliaryVar3PML", - array1d< real32 >, - 0, - NOPLOT, - NO_WRITE, - "PML scalar auxiliary variable 3." ); - -DECLARE_FIELD( AuxiliaryVar4PML, - "auxiliaryVar4PML", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "PML scalar auxiliary variable 4." ); - -} - } /* namespace geos */ #endif /* GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICWAVEEQUATIONSEM_HPP_ */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEMKernel.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEMKernel.hpp index 708cba74cd6..a0179b278d9 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEMKernel.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEMKernel.hpp @@ -24,10 +24,13 @@ #if !defined( GEOS_USE_HIP ) #include "finiteElement/elementFormulations/Qk_Hexahedron_Lagrange_GaussLobatto.hpp" #endif +#include "AcousticFields.hpp" namespace geos { +using namespace fields; + /// Namespace to contain the acoustic wave kernels. namespace acousticWaveEquationSEMKernels { @@ -736,9 +739,9 @@ class ExplicitAcousticSEM : public finiteElement::KernelBase< SUBREGION_TYPE, finiteElementSpace, inputConstitutiveType ), m_nodeCoords( nodeManager.getField< fields::referencePosition32 >() ), - m_p_n( nodeManager.getField< fields::Pressure_n >() ), - m_stiffnessVector( nodeManager.getField< fields::StiffnessVector >() ), - m_density( elementSubRegion.template getField< fields::AcousticDensity >() ), + m_p_n( nodeManager.getField< acousticfields::Pressure_n >() ), + m_stiffnessVector( nodeManager.getField< acousticfields::StiffnessVector >() ), + m_density( elementSubRegion.template getField< acousticfields::AcousticDensity >() ), m_dt( dt ) { GEOS_UNUSED_VAR( edgeManager ); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcoustoElasticFields.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcoustoElasticFields.hpp new file mode 100644 index 00000000000..bdc80bea84f --- /dev/null +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcoustoElasticFields.hpp @@ -0,0 +1,66 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + + +/** + * @file AcoustoElasticFields.hpp + */ + +#ifndef GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTOELASTICFIELDS_HPP_ +#define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTOELASTICFIELDS_HPP_ + +#include "common/DataLayouts.hpp" +#include "mesh/MeshFields.hpp" + + +namespace geos +{ + +namespace fields +{ + +namespace acoustoelasticfields +{ + +DECLARE_FIELD( CouplingVectorx, + "couplingVectorx", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Coupling term on x." ); + +DECLARE_FIELD( CouplingVectory, + "couplingVectory", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Coupling term on y." ); + +DECLARE_FIELD( CouplingVectorz, + "couplingVectorz", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Coupling term on z." ); + +} + +} + +} /* namespace geos */ + +#endif /* GEOS_PHYSICSSOLVERS_WAVEPROPAGATION__HPP_ACOUSTOELASTICFIELDS */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/WaveSolverBaseFields.hpp b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFields.hpp similarity index 53% rename from src/coreComponents/physicsSolvers/wavePropagation/WaveSolverBaseFields.hpp rename to src/coreComponents/physicsSolvers/wavePropagation/ElasticFields.hpp index 333139c21c1..8669c653534 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/WaveSolverBaseFields.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFields.hpp @@ -14,11 +14,11 @@ /** - * @file WaveSolverBaseFields.hpp + * @file ElasticFields.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_WAVESOLVERBASEFIELDS_HPP_ -#define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_WAVESOLVERBASEFIELDS_HPP_ +#ifndef GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASTICFIELDS_HPP_ +#define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASTICFIELDS_HPP_ #include "common/DataLayouts.hpp" #include "mesh/MeshFields.hpp" @@ -29,128 +29,128 @@ namespace geos namespace fields { -namespace wavesolverfields +namespace elasticfields { -DECLARE_FIELD( Delta, - "delta", +DECLARE_FIELD( Displacementx_nm1, + "displacementx_nm1", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "Delta thomsen anisotropy parameter" ); + "x-component of displacement at time n-1." ); -DECLARE_FIELD( Epsilon, - "epsilon", +DECLARE_FIELD( Displacementy_nm1, + "displacementy_nm1", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "Epsilon thomsen anisotropy parameter" ); + "y-component of displacement at time n-1." ); -DECLARE_FIELD( F, - "f", +DECLARE_FIELD( Displacementz_nm1, + "displacementz_nm1", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "f quantity in VTI/TTI Fletcher's equations" ); + "z-component of displacement at time n-1." ); -DECLARE_FIELD( StiffnessVector_p, - "stiffnessVector_p", +DECLARE_FIELD( Displacementx_n, + "displacementx_n", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "Stiffness vector contains R_h*Pressure_n." ); + "x-component of displacement at time n." ); -DECLARE_FIELD( StiffnessVector_q, - "stiffnessVector_q", +DECLARE_FIELD( Displacementy_n, + "displacementy_n", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "Stiffness vector contains R_h*Pressure_n." ); + "y-component of displacement at time n." ); -DECLARE_FIELD( Pressure_np1, - "pressure_np1", +DECLARE_FIELD( Displacementz_n, + "displacementz_n", array1d< real32 >, 0, - LEVEL_0, + NOPLOT, WRITE_AND_READ, - "Scalar pressure at time n+1." ); + "z-component of displacement at time n." ); -DECLARE_FIELD( Pressure_p_nm1, - "pressure_p_nm1", +DECLARE_FIELD( Displacementx_np1, + "displacementx_np1", array1d< real32 >, 0, - NOPLOT, + LEVEL_0, WRITE_AND_READ, - "Scalar pressure at time n-1." ); + "x-component of displacement at time n+1." ); -DECLARE_FIELD( Pressure_p_n, - "pressure_p_n", +DECLARE_FIELD( Displacementy_np1, + "displacementy_np1", array1d< real32 >, 0, - NOPLOT, + LEVEL_0, WRITE_AND_READ, - "Scalar pressure at time n." ); + "y-component of displacement at time n+1." ); -DECLARE_FIELD( Pressure_p_np1, - "pressure_p_np1", +DECLARE_FIELD( Displacementz_np1, + "displacementz_np1", array1d< real32 >, 0, LEVEL_0, WRITE_AND_READ, - "Scalar pressure at time n+1." ); + "z-component of displacement at time n+1." ); -DECLARE_FIELD( Pressure_q_nm1, - "pressure_q_nm1", - array1d< real32 >, +DECLARE_FIELD( Stresstensorxx, + "stresstensorxx", + array2d< real32 >, 0, - NOPLOT, + LEVEL_0, WRITE_AND_READ, - "Scalar auxiliary pressure q at time n-1." ); + "xx-components of the stress tensor." ); -DECLARE_FIELD( Pressure_q_n, - "pressure_q_n", - array1d< real32 >, +DECLARE_FIELD( Stresstensoryy, + "stresstensoryy", + array2d< real32 >, 0, - NOPLOT, + LEVEL_0, WRITE_AND_READ, - "Scalar auxiliary pressure q at time n." ); + "yy-components of the stress tensor." ); -DECLARE_FIELD( Pressure_q_np1, - "pressure_q_np1", - array1d< real32 >, +DECLARE_FIELD( Stresstensorzz, + "stresstensorzz", + array2d< real32 >, 0, LEVEL_0, WRITE_AND_READ, - "Scalar auxiliary pressure q at time n+1." ); + "zz-components of the stress tensor." ); -DECLARE_FIELD( Velocity_x, - "velocity_x", +DECLARE_FIELD( Stresstensorxy, + "stresstensorxy", array2d< real32 >, 0, LEVEL_0, WRITE_AND_READ, - "Velocity in the x-direction." ); + "xy-components of the stress tensor (symetric of yx-component)." ); -DECLARE_FIELD( Velocity_y, - "velocity_y", +DECLARE_FIELD( Stresstensorxz, + "stresstensorxz", array2d< real32 >, 0, LEVEL_0, WRITE_AND_READ, - "Velocity in the y-direction." ); + "xz-components of the stress tensor (symetric of zx-component)." ); -DECLARE_FIELD( Velocity_z, - "velocity_z", +DECLARE_FIELD( Stresstensoryz, + "stresstensoryz", array2d< real32 >, 0, LEVEL_0, WRITE_AND_READ, - "Velocity in the z-direction." ); + "yz-components of the stress tensor (symetric of zy-component)." ); DECLARE_FIELD( ForcingRHS, "rhs", @@ -160,117 +160,29 @@ DECLARE_FIELD( ForcingRHS, WRITE_AND_READ, "RHS" ); -DECLARE_FIELD( AcousticMassVector, - "acousticMassVector", +DECLARE_FIELD( ForcingRHSx, + "rhsx", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "Diagonal of the Mass Matrix." ); + "RHS for x-direction" ); -DECLARE_FIELD( DampingVector, - "dampingVector", +DECLARE_FIELD( ForcingRHSy, + "rhsy", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "Diagonal of the Damping Matrix." ); + "RHS for y-direction" ); -DECLARE_FIELD( DampingVector_p, - "dampingVector_p", +DECLARE_FIELD( ForcingRHSz, + "rhsz", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "Diagonal of the Damping Matrix for p terms in p equation." ); - -DECLARE_FIELD( DampingVector_pq, - "dampingVector_pq", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal of the Damping Matrix for q terms in p equation." ); - -DECLARE_FIELD( DampingVector_q, - "dampingVector_q", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal of the Damping Matrix for q terms in q equation." ); - -DECLARE_FIELD( DampingVector_qp, - "dampingVector_qp", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal of the Damping Matrix for p terms in q equation." ); - -DECLARE_FIELD( AcousticVelocity, - "acousticVelocity", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Medium velocity of the cell" ); - -DECLARE_FIELD( AcousticDensity, - "acousticDensity", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Medium density of the cell" ); - -DECLARE_FIELD( AcousticFreeSurfaceFaceIndicator, - "acousticFreeSurfaceFaceIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Free surface indicator, 1 if a face is on free surface 0 otherwise." ); - -DECLARE_FIELD( AcousticFreeSurfaceNodeIndicator, - "acousticFreeSurfaceNodeIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Free surface indicator, 1 if a node is on free surface 0 otherwise." ); - -DECLARE_FIELD( LateralSurfaceFaceIndicator, - "lateralSurfaceFaceIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Free surface indicator, 1 if a face is on a lateral surface 0 otherwise." ); - -DECLARE_FIELD( LateralSurfaceNodeIndicator, - "lateralSurfaceNodeIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Lateral surface indicator, 1 if a face is on a lateral surface 0 otherwise." ); - -DECLARE_FIELD( BottomSurfaceFaceIndicator, - "bottomSurfaceFaceIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Bottom surface indicator, 1 if a face is on the bottom surface 0 otherwise." ); - -DECLARE_FIELD( BottomSurfaceNodeIndicator, - "bottomSurfaceNodeIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Bottom surface indicator, 1 if a face is on the bottom surface 0 otherwise." ); + "RHS for z-direction" ); DECLARE_FIELD( ElasticMassVector, "elasticMassVector", @@ -280,77 +192,29 @@ DECLARE_FIELD( ElasticMassVector, WRITE_AND_READ, "Diagonal of the Mass Matrix." ); -DECLARE_FIELD( Displacementx_np1, - "displacementx_np1", +DECLARE_FIELD( StiffnessVectorx, + "stiffnessVectorx", array1d< real32 >, 0, - LEVEL_0, + NOPLOT, WRITE_AND_READ, - "x-component of displacement at time n+1." ); + "x-component of stiffness vector." ); -DECLARE_FIELD( Displacementy_np1, - "displacementy_np1", +DECLARE_FIELD( StiffnessVectory, + "stiffnessVectory", array1d< real32 >, 0, - LEVEL_0, + NOPLOT, WRITE_AND_READ, - "y-component of displacement at time n+1." ); + "y-component of stiffness vector." ); -DECLARE_FIELD( Displacementz_np1, - "displacementz_np1", +DECLARE_FIELD( StiffnessVectorz, + "stiffnessVectorz", array1d< real32 >, 0, - LEVEL_0, - WRITE_AND_READ, - "z-component of displacement at time n+1." ); - -DECLARE_FIELD( Stresstensorxx, - "stresstensorxx", - array2d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "xx-components of the stress tensor." ); - -DECLARE_FIELD( Stresstensoryy, - "stresstensoryy", - array2d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "yy-components of the stress tensor." ); - -DECLARE_FIELD( Stresstensorzz, - "stresstensorzz", - array2d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "zz-components of the stress tensor." ); - -DECLARE_FIELD( Stresstensorxy, - "stresstensorxy", - array2d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "xy-components of the stress tensor (symetric of yx-component)." ); - -DECLARE_FIELD( Stresstensorxz, - "stresstensorxz", - array2d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "xz-components of the stress tensor (symetric of zx-component)." ); - -DECLARE_FIELD( Stresstensoryz, - "stresstensoryz", - array2d< real32 >, - 0, - LEVEL_0, + NOPLOT, WRITE_AND_READ, - "yz-components of the stress tensor (symetric of zy-component)." ); + "z-component of stiffness vector." ); DECLARE_FIELD( DampingVectorx, "dampingVectorx", @@ -439,4 +303,4 @@ DECLARE_FIELD( Mu, } /* namespace geos */ -#endif /* GEOS_PHYSICSSOLVERS_WAVEPROPAGATION__HPP_WAVESOLVERBASEFIELDS */ +#endif /* GEOS_PHYSICSSOLVERS_WAVEPROPAGATION__HPP_ELASTICFIELDS */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.cpp b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.cpp index 512ee4e9ded..5a2c9e053b8 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.cpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.cpp @@ -54,32 +54,32 @@ ElasticFirstOrderWaveEquationSEM::ElasticFirstOrderWaveEquationSEM( const std::s setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); - registerWrapper( viewKeyStruct::displacementzNp1AtReceiversString(), &m_sigmaxxNp1AtReceivers ). + registerWrapper( viewKeyStruct::sigmaxxNp1AtReceiversString(), &m_sigmaxxNp1AtReceivers ). setInputFlag( InputFlags::FALSE ). setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); - registerWrapper( viewKeyStruct::displacementzNp1AtReceiversString(), &m_sigmayyNp1AtReceivers ). + registerWrapper( viewKeyStruct::sigmayyNp1AtReceiversString(), &m_sigmayyNp1AtReceivers ). setInputFlag( InputFlags::FALSE ). setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); - registerWrapper( viewKeyStruct::displacementzNp1AtReceiversString(), &m_sigmazzNp1AtReceivers ). + registerWrapper( viewKeyStruct::sigmazzNp1AtReceiversString(), &m_sigmazzNp1AtReceivers ). setInputFlag( InputFlags::FALSE ). setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); - registerWrapper( viewKeyStruct::displacementzNp1AtReceiversString(), &m_sigmaxyNp1AtReceivers ). + registerWrapper( viewKeyStruct::sigmaxyNp1AtReceiversString(), &m_sigmaxyNp1AtReceivers ). setInputFlag( InputFlags::FALSE ). setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); - registerWrapper( viewKeyStruct::displacementzNp1AtReceiversString(), &m_sigmaxzNp1AtReceivers ). + registerWrapper( viewKeyStruct::sigmaxzNp1AtReceiversString(), &m_sigmaxzNp1AtReceivers ). setInputFlag( InputFlags::FALSE ). setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); - registerWrapper( viewKeyStruct::displacementzNp1AtReceiversString(), &m_sigmayzNp1AtReceivers ). + registerWrapper( viewKeyStruct::sigmayzNp1AtReceiversString(), &m_sigmayzNp1AtReceivers ). setInputFlag( InputFlags::FALSE ). setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); @@ -117,35 +117,35 @@ void ElasticFirstOrderWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) { NodeManager & nodeManager = mesh.getNodeManager(); - nodeManager.registerField< wavesolverfields::Displacementx_np1, - wavesolverfields::Displacementy_np1, - wavesolverfields::Displacementz_np1, - wavesolverfields::ForcingRHS, - wavesolverfields::ElasticMassVector, - wavesolverfields::DampingVectorx, - wavesolverfields::DampingVectory, - wavesolverfields::DampingVectorz, - wavesolverfields::ElasticFreeSurfaceNodeIndicator >( getName() ); + nodeManager.registerField< elasticfields::Displacementx_np1, + elasticfields::Displacementy_np1, + elasticfields::Displacementz_np1, + elasticfields::ForcingRHS, + elasticfields::ElasticMassVector, + elasticfields::DampingVectorx, + elasticfields::DampingVectory, + elasticfields::DampingVectorz, + elasticfields::ElasticFreeSurfaceNodeIndicator >( getName() ); FaceManager & faceManager = mesh.getFaceManager(); - faceManager.registerField< wavesolverfields::ElasticFreeSurfaceFaceIndicator >( getName() ); + faceManager.registerField< elasticfields::ElasticFreeSurfaceFaceIndicator >( getName() ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< CellElementSubRegion >( [&]( CellElementSubRegion & subRegion ) { - subRegion.registerField< wavesolverfields::ElasticVelocityVp >( getName() ); - subRegion.registerField< wavesolverfields::ElasticVelocityVs >( getName() ); - subRegion.registerField< wavesolverfields::ElasticDensity >( getName() ); - subRegion.registerField< wavesolverfields::Lambda >( getName() ); - subRegion.registerField< wavesolverfields::Mu >( getName() ); - - subRegion.registerField< wavesolverfields::Stresstensorxx >( getName()); - subRegion.registerField< wavesolverfields::Stresstensoryy >( getName()); - subRegion.registerField< wavesolverfields::Stresstensorzz >( getName()); - subRegion.registerField< wavesolverfields::Stresstensorxy >( getName()); - subRegion.registerField< wavesolverfields::Stresstensorxz >( getName()); - subRegion.registerField< wavesolverfields::Stresstensoryz >( getName()); + subRegion.registerField< elasticfields::ElasticVelocityVp >( getName() ); + subRegion.registerField< elasticfields::ElasticVelocityVs >( getName() ); + subRegion.registerField< elasticfields::ElasticDensity >( getName() ); + subRegion.registerField< elasticfields::Lambda >( getName() ); + subRegion.registerField< elasticfields::Mu >( getName() ); + + subRegion.registerField< elasticfields::Stresstensorxx >( getName()); + subRegion.registerField< elasticfields::Stresstensoryy >( getName()); + subRegion.registerField< elasticfields::Stresstensorzz >( getName()); + subRegion.registerField< elasticfields::Stresstensorxy >( getName()); + subRegion.registerField< elasticfields::Stresstensorxz >( getName()); + subRegion.registerField< elasticfields::Stresstensoryz >( getName()); finiteElement::FiniteElementBase const & fe = subRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); @@ -156,12 +156,12 @@ void ElasticFirstOrderWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) constexpr localIndex numNodesPerElem = FE_TYPE::numNodes; - subRegion.getField< wavesolverfields::Stresstensorxx >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< wavesolverfields::Stresstensoryy >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< wavesolverfields::Stresstensorzz >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< wavesolverfields::Stresstensorxy >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< wavesolverfields::Stresstensorxz >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< wavesolverfields::Stresstensoryz >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< elasticfields::Stresstensorxx >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< elasticfields::Stresstensoryy >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< elasticfields::Stresstensorzz >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< elasticfields::Stresstensorxy >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< elasticfields::Stresstensorxz >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< elasticfields::Stresstensoryz >().resizeDimension< 1 >( numNodesPerElem ); } ); @@ -296,31 +296,6 @@ void ElasticFirstOrderWaveEquationSEM::precomputeSourceAndReceiverTerm( MeshLeve } ); } - -void ElasticFirstOrderWaveEquationSEM::addSourceToRightHandSide( integer const & cycleNumber, arrayView1d< real32 > const rhs ) -{ - arrayView2d< localIndex const > const sourceNodeIds = m_sourceNodeIds.toViewConst(); - arrayView2d< real64 const > const sourceConstants = m_sourceConstants.toViewConst(); - arrayView1d< localIndex const > const sourceIsAccessible = m_sourceIsAccessible.toViewConst(); - arrayView2d< real32 const > const sourceValue = m_sourceValue.toViewConst(); - - GEOS_THROW_IF( cycleNumber > sourceValue.size( 0 ), - getDataContext() << ": Too many steps compared to array size", - std::runtime_error ); - - forAll< serialPolicy >( m_sourceConstants.size( 0 ), [=] ( localIndex const isrc ) - { - if( sourceIsAccessible[isrc] == 1 ) - { - for( localIndex inode = 0; inode < m_sourceConstants.size( 1 ); ++inode ) - { - real32 const localIncrement = sourceConstants[isrc][inode] * sourceValue[cycleNumber][isrc]; - RAJA::atomicAdd< ATOMIC_POLICY >( &rhs[sourceNodeIds[isrc][inode]], localIncrement ); - } - } - } ); -} - void ElasticFirstOrderWaveEquationSEM::initializePostInitialConditionsPreSubGroups() { @@ -349,18 +324,18 @@ void ElasticFirstOrderWaveEquationSEM::initializePostInitialConditionsPreSubGrou ArrayOfArraysView< localIndex const > const facesToNodes = faceManager.nodeList().toViewConst(); // mass matrix to be computed in this function - arrayView1d< real32 > const mass = nodeManager.getField< wavesolverfields::ElasticMassVector >(); + arrayView1d< real32 > const mass = nodeManager.getField< elasticfields::ElasticMassVector >(); mass.zero(); /// damping matrix to be computed for each dof in the boundary of the mesh - arrayView1d< real32 > const dampingx = nodeManager.getField< wavesolverfields::DampingVectorx >(); - arrayView1d< real32 > const dampingy = nodeManager.getField< wavesolverfields::DampingVectory >(); - arrayView1d< real32 > const dampingz = nodeManager.getField< wavesolverfields::DampingVectorz >(); + arrayView1d< real32 > const dampingx = nodeManager.getField< elasticfields::DampingVectorx >(); + arrayView1d< real32 > const dampingy = nodeManager.getField< elasticfields::DampingVectory >(); + arrayView1d< real32 > const dampingz = nodeManager.getField< elasticfields::DampingVectorz >(); dampingx.zero(); dampingy.zero(); dampingz.zero(); /// get array of indicators: 1 if face is on the free surface; 0 otherwise - arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< wavesolverfields::ElasticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< elasticfields::ElasticFreeSurfaceFaceIndicator >(); mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const, CellElementSubRegion & elementSubRegion ) @@ -368,9 +343,9 @@ void ElasticFirstOrderWaveEquationSEM::initializePostInitialConditionsPreSubGrou arrayView2d< localIndex const, cells::NODE_MAP_USD > const elemsToNodes = elementSubRegion.nodeList(); arrayView2d< localIndex const > const elemsToFaces = elementSubRegion.faceList(); - arrayView1d< real32 > const density = elementSubRegion.getField< wavesolverfields::ElasticDensity >(); - arrayView1d< real32 > const velocityVp = elementSubRegion.getField< wavesolverfields::ElasticVelocityVp >(); - arrayView1d< real32 > const velocityVs = elementSubRegion.getField< wavesolverfields::ElasticVelocityVs >(); + arrayView1d< real32 > const density = elementSubRegion.getField< elasticfields::ElasticDensity >(); + arrayView1d< real32 > const velocityVp = elementSubRegion.getField< elasticfields::ElasticVelocityVp >(); + arrayView1d< real32 > const velocityVs = elementSubRegion.getField< elasticfields::ElasticVelocityVs >(); finiteElement::FiniteElementBase const & fe = elementSubRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); @@ -418,17 +393,17 @@ void ElasticFirstOrderWaveEquationSEM::applyFreeSurfaceBC( real64 const time, Do FaceManager & faceManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getFaceManager(); NodeManager & nodeManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getNodeManager(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< wavesolverfields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< wavesolverfields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< wavesolverfields::Displacementz_np1 >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); ArrayOfArraysView< localIndex const > const faceToNodeMap = faceManager.nodeList().toViewConst(); /// set array of indicators: 1 if a face is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< wavesolverfields::ElasticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< elasticfields::ElasticFreeSurfaceFaceIndicator >(); /// set array of indicators: 1 if a node is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< wavesolverfields::ElasticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< elasticfields::ElasticFreeSurfaceNodeIndicator >(); freeSurfaceFaceIndicator.zero(); freeSurfaceNodeIndicator.zero(); @@ -523,15 +498,15 @@ real64 ElasticFirstOrderWaveEquationSEM::explicitStepInternal( real64 const & ti arrayView2d< wsCoordType const, nodes::REFERENCE_POSITION_USD > const X = nodeManager.getField< fields::referencePosition32 >().toViewConst(); - arrayView1d< real32 const > const mass = nodeManager.getField< wavesolverfields::ElasticMassVector >(); - arrayView1d< real32 > const dampingx = nodeManager.getField< wavesolverfields::DampingVectorx >(); - arrayView1d< real32 > const dampingy = nodeManager.getField< wavesolverfields::DampingVectory >(); - arrayView1d< real32 > const dampingz = nodeManager.getField< wavesolverfields::DampingVectorz >(); + arrayView1d< real32 const > const mass = nodeManager.getField< elasticfields::ElasticMassVector >(); + arrayView1d< real32 > const dampingx = nodeManager.getField< elasticfields::DampingVectorx >(); + arrayView1d< real32 > const dampingy = nodeManager.getField< elasticfields::DampingVectory >(); + arrayView1d< real32 > const dampingz = nodeManager.getField< elasticfields::DampingVectorz >(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< wavesolverfields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< wavesolverfields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< wavesolverfields::Displacementz_np1 >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const regionIndex, CellElementSubRegion & elementSubRegion ) @@ -539,19 +514,19 @@ real64 ElasticFirstOrderWaveEquationSEM::explicitStepInternal( real64 const & ti arrayView2d< localIndex const, cells::NODE_MAP_USD > const & elemsToNodes = elementSubRegion.nodeList(); - arrayView1d< real32 const > const velocityVp = elementSubRegion.getField< wavesolverfields::ElasticVelocityVp >(); - arrayView1d< real32 const > const velocityVs = elementSubRegion.getField< wavesolverfields::ElasticVelocityVs >(); - arrayView1d< real32 const > const density = elementSubRegion.getField< wavesolverfields::ElasticDensity >(); + arrayView1d< real32 const > const velocityVp = elementSubRegion.getField< elasticfields::ElasticVelocityVp >(); + arrayView1d< real32 const > const velocityVs = elementSubRegion.getField< elasticfields::ElasticVelocityVs >(); + arrayView1d< real32 const > const density = elementSubRegion.getField< elasticfields::ElasticDensity >(); - arrayView1d< real32 > const lambda = elementSubRegion.getField< wavesolverfields::Lambda >(); - arrayView1d< real32 > const mu = elementSubRegion.getField< wavesolverfields::Mu >(); + arrayView1d< real32 > const lambda = elementSubRegion.getField< elasticfields::Lambda >(); + arrayView1d< real32 > const mu = elementSubRegion.getField< elasticfields::Mu >(); - arrayView2d< real32 > const stressxx = elementSubRegion.getField< wavesolverfields::Stresstensorxx >(); - arrayView2d< real32 > const stressyy = elementSubRegion.getField< wavesolverfields::Stresstensoryy >(); - arrayView2d< real32 > const stresszz = elementSubRegion.getField< wavesolverfields::Stresstensorzz >(); - arrayView2d< real32 > const stressxy = elementSubRegion.getField< wavesolverfields::Stresstensorxy >(); - arrayView2d< real32 > const stressxz = elementSubRegion.getField< wavesolverfields::Stresstensorxz >(); - arrayView2d< real32 > const stressyz = elementSubRegion.getField< wavesolverfields::Stresstensoryz >(); + arrayView2d< real32 > const stressxx = elementSubRegion.getField< elasticfields::Stresstensorxx >(); + arrayView2d< real32 > const stressyy = elementSubRegion.getField< elasticfields::Stresstensoryy >(); + arrayView2d< real32 > const stresszz = elementSubRegion.getField< elasticfields::Stresstensorzz >(); + arrayView2d< real32 > const stressxy = elementSubRegion.getField< elasticfields::Stresstensorxy >(); + arrayView2d< real32 > const stressxz = elementSubRegion.getField< elasticfields::Stresstensorxz >(); + arrayView2d< real32 > const stressyz = elementSubRegion.getField< elasticfields::Stresstensoryz >(); finiteElement::FiniteElementBase const & @@ -630,10 +605,10 @@ real64 ElasticFirstOrderWaveEquationSEM::explicitStepInternal( real64 const & ti } ); FieldIdentifiers fieldsToBeSync; - fieldsToBeSync.addFields( FieldLocation::Node, { wavesolverfields::Displacementx_np1::key(), wavesolverfields::Displacementy_np1::key(), wavesolverfields::Displacementz_np1::key()} ); - fieldsToBeSync.addElementFields( {wavesolverfields::Stresstensorxx::key(), wavesolverfields::Stresstensoryy::key(), wavesolverfields::Stresstensorzz::key(), - wavesolverfields::Stresstensorxy::key(), - wavesolverfields::Stresstensorxz::key(), wavesolverfields::Stresstensoryz::key()}, regionNames ); + fieldsToBeSync.addFields( FieldLocation::Node, { elasticfields::Displacementx_np1::key(), elasticfields::Displacementy_np1::key(), elasticfields::Displacementz_np1::key()} ); + fieldsToBeSync.addElementFields( {elasticfields::Stresstensorxx::key(), elasticfields::Stresstensoryy::key(), elasticfields::Stresstensorzz::key(), + elasticfields::Stresstensorxy::key(), + elasticfields::Stresstensorxz::key(), elasticfields::Stresstensoryz::key()}, regionNames ); CommunicationTools & syncFields = CommunicationTools::getInstance(); @@ -676,12 +651,12 @@ void ElasticFirstOrderWaveEquationSEM::cleanup( real64 const time_n, mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const regionIndex, CellElementSubRegion & elementSubRegion ) { - arrayView2d< real32 const > const stressxx = elementSubRegion.getField< wavesolverfields::Stresstensorxx >(); - arrayView2d< real32 const > const stressyy = elementSubRegion.getField< wavesolverfields::Stresstensoryy >(); - arrayView2d< real32 const > const stresszz = elementSubRegion.getField< wavesolverfields::Stresstensorzz >(); - arrayView2d< real32 const > const stressxy = elementSubRegion.getField< wavesolverfields::Stresstensorxy >(); - arrayView2d< real32 const > const stressxz = elementSubRegion.getField< wavesolverfields::Stresstensorxz >(); - arrayView2d< real32 const > const stressyz = elementSubRegion.getField< wavesolverfields::Stresstensoryz >(); + arrayView2d< real32 const > const stressxx = elementSubRegion.getField< elasticfields::Stresstensorxx >(); + arrayView2d< real32 const > const stressyy = elementSubRegion.getField< elasticfields::Stresstensoryy >(); + arrayView2d< real32 const > const stresszz = elementSubRegion.getField< elasticfields::Stresstensorzz >(); + arrayView2d< real32 const > const stressxy = elementSubRegion.getField< elasticfields::Stresstensorxy >(); + arrayView2d< real32 const > const stressxz = elementSubRegion.getField< elasticfields::Stresstensorxz >(); + arrayView2d< real32 const > const stressyz = elementSubRegion.getField< elasticfields::Stresstensoryz >(); arrayView2d< real32 > const sigmaxxReceivers = m_sigmaxxNp1AtReceivers.toView(); arrayView2d< real32 > const sigmayyReceivers = m_sigmayyNp1AtReceivers.toView(); @@ -703,9 +678,9 @@ void ElasticFirstOrderWaveEquationSEM::cleanup( real64 const time_n, m_receiverIsLocal, m_nsamplesSeismoTrace, sigmaxyReceivers, sigmaxzReceivers, sigmayzReceivers ); } ); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< wavesolverfields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< wavesolverfields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< wavesolverfields::Displacementz_np1 >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); // compute the seismic traces since last step. arrayView2d< real32 > const uxReceivers = m_displacementxNp1AtReceivers.toView(); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.hpp b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.hpp index 746051b0028..b96d8697412 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.hpp @@ -21,7 +21,7 @@ #define SRC_CORECOMPONENTS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASTICFIRSTORDERWAVEEQUATIONSEM_HPP_ #include "mesh/MeshFields.hpp" -#include "WaveSolverBaseFields.hpp" +#include "ElasticFields.hpp" #include "WaveSolverBase.hpp" @@ -35,8 +35,6 @@ class ElasticFirstOrderWaveEquationSEM : public WaveSolverBase using EXEC_POLICY = parallelDevicePolicy< >; using ATOMIC_POLICY = parallelDeviceAtomic; - static constexpr real64 epsilonLoc = 1e-8; - ElasticFirstOrderWaveEquationSEM( const std::string & name, Group * const parent ); @@ -71,15 +69,6 @@ class ElasticFirstOrderWaveEquationSEM : public WaveSolverBase DomainPartition & domain, bool const computeGradient ) override; - /**@}*/ - - /** - * @brief Multiply the precomputed term by the Ricker and add to the right-hand side - * @param cycleNumber the cycle number/step number of evaluation of the source - * @param rhs the right hand side vector to be computed - */ - void addSourceToRightHandSide( integer const & cycleNumber, arrayView1d< real32 > const rhs ); - /** * @brief Initialize Perfectly Matched Layer (PML) information @@ -191,4 +180,4 @@ class ElasticFirstOrderWaveEquationSEM : public WaveSolverBase } /* namespace geos */ -#endif /* SRC_CORECOMPONENTS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASSTICWAVEEQUATIONSEM_HPP_ */ +#endif /* SRC_CORECOMPONENTS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASTICFIRSTORDERWAVEEQUATIONSEM_HPP_ */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEMKernel.hpp b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEMKernel.hpp index dd074679238..8ab22a047d1 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEMKernel.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEMKernel.hpp @@ -628,4 +628,4 @@ struct VelocityComputation } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ElasticFirstOrderWaveEquationSEMKERNEL_HPP_ +#endif //GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASTICFIRSTORDERWAVEEQUATIONSEMKERNEL_HPP_ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.cpp b/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.cpp index 3c91681eee6..1d9e8fed402 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.cpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.cpp @@ -31,6 +31,7 @@ namespace geos { using namespace dataRepository; +using namespace fields; ElasticWaveEquationSEM::ElasticWaveEquationSEM( const std::string & name, Group * const parent ): @@ -98,7 +99,7 @@ void ElasticWaveEquationSEM::initializePreSubGroups() WaveSolverBase::initializePreSubGroups(); - localIndex const numNodesPerElem = getNumNodesPerElem(); + localIndex const numNodesPerElem = WaveSolverBase::getNumNodesPerElem(); localIndex const numSourcesGlobal = m_sourceCoordinates.size( 0 ); m_sourceConstantsx.resize( numSourcesGlobal, numNodesPerElem ); @@ -122,37 +123,37 @@ void ElasticWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) { NodeManager & nodeManager = mesh.getNodeManager(); - nodeManager.registerField< fields::Displacementx_nm1, - fields::Displacementy_nm1, - fields::Displacementz_nm1, - fields::Displacementx_n, - fields::Displacementy_n, - fields::Displacementz_n, - fields::Displacementx_np1, - fields::Displacementy_np1, - fields::Displacementz_np1, - fields::ForcingRHSx, - fields::ForcingRHSy, - fields::ForcingRHSz, - fields::ElasticMassVector, - fields::DampingVectorx, - fields::DampingVectory, - fields::DampingVectorz, - fields::StiffnessVectorx, - fields::StiffnessVectory, - fields::StiffnessVectorz, - fields::ElasticFreeSurfaceNodeIndicator >( getName() ); + nodeManager.registerField< elasticfields::Displacementx_nm1, + elasticfields::Displacementy_nm1, + elasticfields::Displacementz_nm1, + elasticfields::Displacementx_n, + elasticfields::Displacementy_n, + elasticfields::Displacementz_n, + elasticfields::Displacementx_np1, + elasticfields::Displacementy_np1, + elasticfields::Displacementz_np1, + elasticfields::ForcingRHSx, + elasticfields::ForcingRHSy, + elasticfields::ForcingRHSz, + elasticfields::ElasticMassVector, + elasticfields::DampingVectorx, + elasticfields::DampingVectory, + elasticfields::DampingVectorz, + elasticfields::StiffnessVectorx, + elasticfields::StiffnessVectory, + elasticfields::StiffnessVectorz, + elasticfields::ElasticFreeSurfaceNodeIndicator >( getName() ); FaceManager & faceManager = mesh.getFaceManager(); - faceManager.registerField< fields::ElasticFreeSurfaceFaceIndicator >( getName() ); + faceManager.registerField< elasticfields::ElasticFreeSurfaceFaceIndicator >( getName() ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< CellElementSubRegion >( [&]( CellElementSubRegion & subRegion ) { - subRegion.registerField< fields::ElasticVelocityVp >( getName() ); - subRegion.registerField< fields::ElasticVelocityVs >( getName() ); - subRegion.registerField< fields::ElasticDensity >( getName() ); + subRegion.registerField< elasticfields::ElasticVelocityVp >( getName() ); + subRegion.registerField< elasticfields::ElasticVelocityVs >( getName() ); + subRegion.registerField< elasticfields::ElasticDensity >( getName() ); } ); } ); @@ -364,18 +365,18 @@ void ElasticWaveEquationSEM::initializePostInitialConditionsPreSubGroups() arrayView2d< wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords = nodeManager.getField< fields::referencePosition32 >().toViewConst(); // mass matrix to be computed in this function - arrayView1d< real32 > const mass = nodeManager.getField< fields::ElasticMassVector >(); + arrayView1d< real32 > const mass = nodeManager.getField< elasticfields::ElasticMassVector >(); mass.zero(); /// damping matrix to be computed for each dof in the boundary of the mesh - arrayView1d< real32 > const dampingx = nodeManager.getField< fields::DampingVectorx >(); - arrayView1d< real32 > const dampingy = nodeManager.getField< fields::DampingVectory >(); - arrayView1d< real32 > const dampingz = nodeManager.getField< fields::DampingVectorz >(); + arrayView1d< real32 > const dampingx = nodeManager.getField< elasticfields::DampingVectorx >(); + arrayView1d< real32 > const dampingy = nodeManager.getField< elasticfields::DampingVectory >(); + arrayView1d< real32 > const dampingz = nodeManager.getField< elasticfields::DampingVectorz >(); dampingx.zero(); dampingy.zero(); dampingz.zero(); /// get array of indicators: 1 if face is on the free surface; 0 otherwise - arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< fields::ElasticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< elasticfields::ElasticFreeSurfaceFaceIndicator >(); arrayView1d< integer const > const & facesDomainBoundaryIndicator = faceManager.getDomainBoundaryIndicator(); ArrayOfArraysView< localIndex const > const facesToNodes = faceManager.nodeList().toViewConst(); arrayView2d< real64 const > const faceNormal = faceManager.faceNormal(); @@ -391,9 +392,9 @@ void ElasticWaveEquationSEM::initializePostInitialConditionsPreSubGroups() computeTargetNodeSet( elemsToNodes, elementSubRegion.size(), fe.getNumQuadraturePoints() ); - arrayView1d< real32 const > const density = elementSubRegion.getField< fields::ElasticDensity >(); - arrayView1d< real32 const > const velocityVp = elementSubRegion.getField< fields::ElasticVelocityVp >(); - arrayView1d< real32 const > const velocityVs = elementSubRegion.getField< fields::ElasticVelocityVs >(); + arrayView1d< real32 const > const density = elementSubRegion.getField< elasticfields::ElasticDensity >(); + arrayView1d< real32 const > const velocityVp = elementSubRegion.getField< elasticfields::ElasticVelocityVp >(); + arrayView1d< real32 const > const velocityVs = elementSubRegion.getField< elasticfields::ElasticVelocityVs >(); finiteElement::FiniteElementDispatchHandler< SEM_FE_TYPES >::dispatch3D( fe, [&] ( auto const finiteElement ) { @@ -437,23 +438,23 @@ void ElasticWaveEquationSEM::applyFreeSurfaceBC( real64 const time, DomainPartit FaceManager & faceManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getFaceManager(); NodeManager & nodeManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getNodeManager(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< fields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< fields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< fields::Displacementz_np1 >(); - arrayView1d< real32 > const ux_n = nodeManager.getField< fields::Displacementx_n >(); - arrayView1d< real32 > const uy_n = nodeManager.getField< fields::Displacementy_n >(); - arrayView1d< real32 > const uz_n = nodeManager.getField< fields::Displacementz_n >(); - arrayView1d< real32 > const ux_nm1 = nodeManager.getField< fields::Displacementx_nm1 >(); - arrayView1d< real32 > const uy_nm1 = nodeManager.getField< fields::Displacementy_nm1 >(); - arrayView1d< real32 > const uz_nm1 = nodeManager.getField< fields::Displacementz_nm1 >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); + arrayView1d< real32 > const ux_n = nodeManager.getField< elasticfields::Displacementx_n >(); + arrayView1d< real32 > const uy_n = nodeManager.getField< elasticfields::Displacementy_n >(); + arrayView1d< real32 > const uz_n = nodeManager.getField< elasticfields::Displacementz_n >(); + arrayView1d< real32 > const ux_nm1 = nodeManager.getField< elasticfields::Displacementx_nm1 >(); + arrayView1d< real32 > const uy_nm1 = nodeManager.getField< elasticfields::Displacementy_nm1 >(); + arrayView1d< real32 > const uz_nm1 = nodeManager.getField< elasticfields::Displacementz_nm1 >(); ArrayOfArraysView< localIndex const > const faceToNodeMap = faceManager.nodeList().toViewConst(); /// set array of indicators: 1 if a face is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< fields::ElasticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< elasticfields::ElasticFreeSurfaceFaceIndicator >(); /// set array of indicators: 1 if a node is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< fields::ElasticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< elasticfields::ElasticFreeSurfaceNodeIndicator >(); fsManager.apply( time, @@ -535,30 +536,30 @@ void ElasticWaveEquationSEM::computeUnknowns( real64 const &, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const mass = nodeManager.getField< fields::ElasticMassVector >(); - arrayView1d< real32 const > const dampingx = nodeManager.getField< fields::DampingVectorx >(); - arrayView1d< real32 const > const dampingy = nodeManager.getField< fields::DampingVectory >(); - arrayView1d< real32 const > const dampingz = nodeManager.getField< fields::DampingVectorz >(); - arrayView1d< real32 > const stiffnessVectorx = nodeManager.getField< fields::StiffnessVectorx >(); - arrayView1d< real32 > const stiffnessVectory = nodeManager.getField< fields::StiffnessVectory >(); - arrayView1d< real32 > const stiffnessVectorz = nodeManager.getField< fields::StiffnessVectorz >(); - - arrayView1d< real32 > const ux_nm1 = nodeManager.getField< fields::Displacementx_nm1 >(); - arrayView1d< real32 > const uy_nm1 = nodeManager.getField< fields::Displacementy_nm1 >(); - arrayView1d< real32 > const uz_nm1 = nodeManager.getField< fields::Displacementz_nm1 >(); - arrayView1d< real32 > const ux_n = nodeManager.getField< fields::Displacementx_n >(); - arrayView1d< real32 > const uy_n = nodeManager.getField< fields::Displacementy_n >(); - arrayView1d< real32 > const uz_n = nodeManager.getField< fields::Displacementz_n >(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< fields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< fields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< fields::Displacementz_np1 >(); + arrayView1d< real32 const > const mass = nodeManager.getField< elasticfields::ElasticMassVector >(); + arrayView1d< real32 const > const dampingx = nodeManager.getField< elasticfields::DampingVectorx >(); + arrayView1d< real32 const > const dampingy = nodeManager.getField< elasticfields::DampingVectory >(); + arrayView1d< real32 const > const dampingz = nodeManager.getField< elasticfields::DampingVectorz >(); + arrayView1d< real32 > const stiffnessVectorx = nodeManager.getField< elasticfields::StiffnessVectorx >(); + arrayView1d< real32 > const stiffnessVectory = nodeManager.getField< elasticfields::StiffnessVectory >(); + arrayView1d< real32 > const stiffnessVectorz = nodeManager.getField< elasticfields::StiffnessVectorz >(); + + arrayView1d< real32 > const ux_nm1 = nodeManager.getField< elasticfields::Displacementx_nm1 >(); + arrayView1d< real32 > const uy_nm1 = nodeManager.getField< elasticfields::Displacementy_nm1 >(); + arrayView1d< real32 > const uz_nm1 = nodeManager.getField< elasticfields::Displacementz_nm1 >(); + arrayView1d< real32 > const ux_n = nodeManager.getField< elasticfields::Displacementx_n >(); + arrayView1d< real32 > const uy_n = nodeManager.getField< elasticfields::Displacementy_n >(); + arrayView1d< real32 > const uz_n = nodeManager.getField< elasticfields::Displacementz_n >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); /// get array of indicators: 1 if node on free surface; 0 otherwise - arrayView1d< localIndex const > const freeSurfaceNodeIndicator = nodeManager.getField< fields::ElasticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex const > const freeSurfaceNodeIndicator = nodeManager.getField< elasticfields::ElasticFreeSurfaceNodeIndicator >(); - arrayView1d< real32 > const rhsx = nodeManager.getField< fields::ForcingRHSx >(); - arrayView1d< real32 > const rhsy = nodeManager.getField< fields::ForcingRHSy >(); - arrayView1d< real32 > const rhsz = nodeManager.getField< fields::ForcingRHSz >(); + arrayView1d< real32 > const rhsx = nodeManager.getField< elasticfields::ForcingRHSx >(); + arrayView1d< real32 > const rhsy = nodeManager.getField< elasticfields::ForcingRHSy >(); + arrayView1d< real32 > const rhsz = nodeManager.getField< elasticfields::ForcingRHSz >(); auto kernelFactory = elasticWaveEquationSEMKernels::ExplicitElasticSEMFactory( dt ); @@ -609,27 +610,27 @@ void ElasticWaveEquationSEM::synchronizeUnknowns( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 > const stiffnessVectorx = nodeManager.getField< fields::StiffnessVectorx >(); - arrayView1d< real32 > const stiffnessVectory = nodeManager.getField< fields::StiffnessVectory >(); - arrayView1d< real32 > const stiffnessVectorz = nodeManager.getField< fields::StiffnessVectorz >(); + arrayView1d< real32 > const stiffnessVectorx = nodeManager.getField< elasticfields::StiffnessVectorx >(); + arrayView1d< real32 > const stiffnessVectory = nodeManager.getField< elasticfields::StiffnessVectory >(); + arrayView1d< real32 > const stiffnessVectorz = nodeManager.getField< elasticfields::StiffnessVectorz >(); - arrayView1d< real32 > const ux_nm1 = nodeManager.getField< fields::Displacementx_nm1 >(); - arrayView1d< real32 > const uy_nm1 = nodeManager.getField< fields::Displacementy_nm1 >(); - arrayView1d< real32 > const uz_nm1 = nodeManager.getField< fields::Displacementz_nm1 >(); - arrayView1d< real32 > const ux_n = nodeManager.getField< fields::Displacementx_n >(); - arrayView1d< real32 > const uy_n = nodeManager.getField< fields::Displacementy_n >(); - arrayView1d< real32 > const uz_n = nodeManager.getField< fields::Displacementz_n >(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< fields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< fields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< fields::Displacementz_np1 >(); + arrayView1d< real32 > const ux_nm1 = nodeManager.getField< elasticfields::Displacementx_nm1 >(); + arrayView1d< real32 > const uy_nm1 = nodeManager.getField< elasticfields::Displacementy_nm1 >(); + arrayView1d< real32 > const uz_nm1 = nodeManager.getField< elasticfields::Displacementz_nm1 >(); + arrayView1d< real32 > const ux_n = nodeManager.getField< elasticfields::Displacementx_n >(); + arrayView1d< real32 > const uy_n = nodeManager.getField< elasticfields::Displacementy_n >(); + arrayView1d< real32 > const uz_n = nodeManager.getField< elasticfields::Displacementz_n >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); - arrayView1d< real32 > const rhsx = nodeManager.getField< fields::ForcingRHSx >(); - arrayView1d< real32 > const rhsy = nodeManager.getField< fields::ForcingRHSy >(); - arrayView1d< real32 > const rhsz = nodeManager.getField< fields::ForcingRHSz >(); + arrayView1d< real32 > const rhsx = nodeManager.getField< elasticfields::ForcingRHSx >(); + arrayView1d< real32 > const rhsy = nodeManager.getField< elasticfields::ForcingRHSy >(); + arrayView1d< real32 > const rhsz = nodeManager.getField< elasticfields::ForcingRHSz >(); /// synchronize displacement fields FieldIdentifiers fieldsToBeSync; - fieldsToBeSync.addFields( FieldLocation::Node, { fields::Displacementx_np1::key(), fields::Displacementy_np1::key(), fields::Displacementz_np1::key() } ); + fieldsToBeSync.addFields( FieldLocation::Node, { elasticfields::Displacementx_np1::key(), elasticfields::Displacementy_np1::key(), elasticfields::Displacementz_np1::key() } ); CommunicationTools & syncFields = CommunicationTools::getInstance(); syncFields.synchronizeFields( fieldsToBeSync, @@ -662,23 +663,23 @@ void ElasticWaveEquationSEM::prepareNextTimestep( MeshLevel & mesh ) { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 > const ux_nm1 = nodeManager.getField< fields::Displacementx_nm1 >(); - arrayView1d< real32 > const uy_nm1 = nodeManager.getField< fields::Displacementy_nm1 >(); - arrayView1d< real32 > const uz_nm1 = nodeManager.getField< fields::Displacementz_nm1 >(); - arrayView1d< real32 > const ux_n = nodeManager.getField< fields::Displacementx_n >(); - arrayView1d< real32 > const uy_n = nodeManager.getField< fields::Displacementy_n >(); - arrayView1d< real32 > const uz_n = nodeManager.getField< fields::Displacementz_n >(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< fields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< fields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< fields::Displacementz_np1 >(); + arrayView1d< real32 > const ux_nm1 = nodeManager.getField< elasticfields::Displacementx_nm1 >(); + arrayView1d< real32 > const uy_nm1 = nodeManager.getField< elasticfields::Displacementy_nm1 >(); + arrayView1d< real32 > const uz_nm1 = nodeManager.getField< elasticfields::Displacementz_nm1 >(); + arrayView1d< real32 > const ux_n = nodeManager.getField< elasticfields::Displacementx_n >(); + arrayView1d< real32 > const uy_n = nodeManager.getField< elasticfields::Displacementy_n >(); + arrayView1d< real32 > const uz_n = nodeManager.getField< elasticfields::Displacementz_n >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); - arrayView1d< real32 > const stiffnessVectorx = nodeManager.getField< fields::StiffnessVectorx >(); - arrayView1d< real32 > const stiffnessVectory = nodeManager.getField< fields::StiffnessVectory >(); - arrayView1d< real32 > const stiffnessVectorz = nodeManager.getField< fields::StiffnessVectorz >(); + arrayView1d< real32 > const stiffnessVectorx = nodeManager.getField< elasticfields::StiffnessVectorx >(); + arrayView1d< real32 > const stiffnessVectory = nodeManager.getField< elasticfields::StiffnessVectory >(); + arrayView1d< real32 > const stiffnessVectorz = nodeManager.getField< elasticfields::StiffnessVectorz >(); - arrayView1d< real32 > const rhsx = nodeManager.getField< fields::ForcingRHSx >(); - arrayView1d< real32 > const rhsy = nodeManager.getField< fields::ForcingRHSy >(); - arrayView1d< real32 > const rhsz = nodeManager.getField< fields::ForcingRHSz >(); + arrayView1d< real32 > const rhsx = nodeManager.getField< elasticfields::ForcingRHSx >(); + arrayView1d< real32 > const rhsy = nodeManager.getField< elasticfields::ForcingRHSy >(); + arrayView1d< real32 > const rhsz = nodeManager.getField< elasticfields::ForcingRHSz >(); SortedArrayView< localIndex const > const solverTargetNodesSet = m_solverTargetNodesSet.toViewConst(); @@ -734,14 +735,12 @@ void ElasticWaveEquationSEM::cleanup( real64 const time_n, arrayView1d< string const > const & ) { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const ux_n = nodeManager.getField< fields::Displacementx_n >(); - arrayView1d< real32 const > const ux_np1 = nodeManager.getField< fields::Displacementx_np1 >(); - arrayView1d< real32 const > const uy_n = nodeManager.getField< fields::Displacementy_n >(); - arrayView1d< real32 const > const uy_np1 = nodeManager.getField< fields::Displacementy_np1 >(); - arrayView1d< real32 const > const uz_n = nodeManager.getField< fields::Displacementz_n >(); - arrayView1d< real32 const > const uz_np1 = nodeManager.getField< fields::Displacementz_np1 >(); - - + arrayView1d< real32 const > const ux_n = nodeManager.getField< elasticfields::Displacementx_n >(); + arrayView1d< real32 const > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); + arrayView1d< real32 const > const uy_n = nodeManager.getField< elasticfields::Displacementy_n >(); + arrayView1d< real32 const > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); + arrayView1d< real32 const > const uz_n = nodeManager.getField< elasticfields::Displacementz_n >(); + arrayView1d< real32 const > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); if( m_useDAS == WaveSolverUtils::DASType::none ) { diff --git a/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.hpp b/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.hpp index 7d803b11a78..74d58e3cfd0 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.hpp @@ -23,6 +23,7 @@ #include "WaveSolverBase.hpp" #include "mesh/MeshFields.hpp" #include "physicsSolvers/SolverBase.hpp" +#include "ElasticFields.hpp" namespace geos { @@ -34,11 +35,6 @@ class ElasticWaveEquationSEM : public WaveSolverBase using EXEC_POLICY = parallelDevicePolicy< >; using ATOMIC_POLICY = parallelDeviceAtomic; - /** - * @brief Safeguard for timeStep. Used to avoid memory issue due to too small value. - */ - static constexpr real64 epsilonLoc = 1e-8; - ElasticWaveEquationSEM( const std::string & name, Group * const parent ); @@ -220,205 +216,6 @@ class ElasticWaveEquationSEM : public WaveSolverBase }; - -namespace fields -{ - -DECLARE_FIELD( Displacementx_nm1, - "displacementx_nm1", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "x-component of displacement at time n-1." ); - -DECLARE_FIELD( Displacementy_nm1, - "displacementy_nm1", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "y-component of displacement at time n-1." ); - -DECLARE_FIELD( Displacementz_nm1, - "displacementz_nm1", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "z-component of displacement at time n-1." ); - -DECLARE_FIELD( Displacementx_n, - "displacementx_n", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "x-component of displacement at time n." ); - -DECLARE_FIELD( Displacementy_n, - "displacementy_n", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "y-component of displacement at time n." ); - -DECLARE_FIELD( Displacementz_n, - "displacementz_n", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "z-component of displacement at time n." ); - -DECLARE_FIELD( Displacementx_np1, - "displacementx_np1", - array1d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "x-component of displacement at time n+1." ); - -DECLARE_FIELD( Displacementy_np1, - "displacementy_np1", - array1d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "y-component of displacement at time n+1." ); - -DECLARE_FIELD( Displacementz_np1, - "displacementz_np1", - array1d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "z-component of displacement at time n+1." ); - -DECLARE_FIELD( ForcingRHSx, - "rhsx", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "RHS for x-direction" ); - -DECLARE_FIELD( ForcingRHSy, - "rhsy", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "RHS for y-direction" ); - -DECLARE_FIELD( ForcingRHSz, - "rhsz", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "RHS for z-direction" ); - -DECLARE_FIELD( ElasticMassVector, - "elasticMassVector", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal Mass Matrix." ); - -DECLARE_FIELD( DampingVectorx, - "dampingVectorx", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal Damping Matrix in x-direction." ); - -DECLARE_FIELD( DampingVectory, - "dampingVectory", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal Damping Matrix in y-direction." ); - -DECLARE_FIELD( DampingVectorz, - "dampingVectorz", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal Damping Matrix in z-direction." ); - -DECLARE_FIELD( StiffnessVectorx, - "stiffnessVectorx", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "x-component of stiffness vector." ); - -DECLARE_FIELD( StiffnessVectory, - "stiffnessVectory", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "y-component of stiffness vector." ); - -DECLARE_FIELD( StiffnessVectorz, - "stiffnessVectorz", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "z-component of stiffness vector." ); - -DECLARE_FIELD( ElasticVelocityVp, - "elasticVelocityVp", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "P-waves speed in the cell" ); - -DECLARE_FIELD( ElasticVelocityVs, - "elasticVelocityVs", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "S-waves speed in the cell" ); - -DECLARE_FIELD( ElasticDensity, - "elasticDensity", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Medium density of the cell" ); - -DECLARE_FIELD( ElasticFreeSurfaceFaceIndicator, - "elasticFreeSurfaceFaceIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Free surface indicator, 1 if a face is on free surface 0 otherwise." ); - -DECLARE_FIELD( ElasticFreeSurfaceNodeIndicator, - "elasticFreeSurfaceNodeIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Free surface indicator, 1 if a node is on free surface 0 otherwise." ); - -} - - } /* namespace geos */ #endif /* SRC_CORECOMPONENTS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASSTICWAVEEQUATIONSEM_HPP_ */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEMKernel.hpp b/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEMKernel.hpp index fe7e9d34aa2..78b7292eda7 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEMKernel.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEMKernel.hpp @@ -21,11 +21,11 @@ #include "finiteElement/kernelInterface/KernelBase.hpp" #include "WaveSolverUtils.hpp" - +#include "ElasticFields.hpp" namespace geos { - +using namespace fields; /// Namespace to contain the elastic wave kernels. namespace elasticWaveEquationSEMKernels { @@ -509,15 +509,15 @@ class ExplicitElasticSEM : public finiteElement::KernelBase< SUBREGION_TYPE, finiteElementSpace, inputConstitutiveType ), m_nodeCoords( nodeManager.getField< fields::referencePosition32 >() ), - m_ux_n( nodeManager.getField< fields::Displacementx_n >() ), - m_uy_n( nodeManager.getField< fields::Displacementy_n >() ), - m_uz_n( nodeManager.getField< fields::Displacementz_n >() ), - m_stiffnessVectorx( nodeManager.getField< fields::StiffnessVectorx >() ), - m_stiffnessVectory( nodeManager.getField< fields::StiffnessVectory >() ), - m_stiffnessVectorz( nodeManager.getField< fields::StiffnessVectorz >() ), - m_density( elementSubRegion.template getField< fields::ElasticDensity >() ), - m_velocityVp( elementSubRegion.template getField< fields::ElasticVelocityVp >() ), - m_velocityVs( elementSubRegion.template getField< fields::ElasticVelocityVs >() ), + m_ux_n( nodeManager.getField< elasticfields::Displacementx_n >() ), + m_uy_n( nodeManager.getField< elasticfields::Displacementy_n >() ), + m_uz_n( nodeManager.getField< elasticfields::Displacementz_n >() ), + m_stiffnessVectorx( nodeManager.getField< elasticfields::StiffnessVectorx >() ), + m_stiffnessVectory( nodeManager.getField< elasticfields::StiffnessVectory >() ), + m_stiffnessVectorz( nodeManager.getField< elasticfields::StiffnessVectorz >() ), + m_density( elementSubRegion.template getField< elasticfields::ElasticDensity >() ), + m_velocityVp( elementSubRegion.template getField< elasticfields::ElasticVelocityVp >() ), + m_velocityVs( elementSubRegion.template getField< elasticfields::ElasticVelocityVs >() ), m_dt( dt ) { GEOS_UNUSED_VAR( edgeManager ); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/WaveSolverUtils.hpp b/src/coreComponents/physicsSolvers/wavePropagation/WaveSolverUtils.hpp index a1849fcbca2..5b9e91dbcb8 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/WaveSolverUtils.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/WaveSolverUtils.hpp @@ -30,8 +30,6 @@ namespace geos struct WaveSolverUtils { static constexpr real64 epsilonLoc = 1e-8; - static constexpr real64 eps64 = std::numeric_limits< real64 >::epsilon(); - static constexpr real32 eps32 = std::numeric_limits< real32 >::epsilon(); using EXEC_POLICY = parallelDevicePolicy< >; using wsCoordType = real32; diff --git a/src/coreComponents/schema/docs/CompositionalMultiphaseFVM.rst b/src/coreComponents/schema/docs/CompositionalMultiphaseFVM.rst index beeff3f3b0a..7202cd18e81 100644 --- a/src/coreComponents/schema/docs/CompositionalMultiphaseFVM.rst +++ b/src/coreComponents/schema/docs/CompositionalMultiphaseFVM.rst @@ -17,6 +17,9 @@ maxAbsolutePressureChange real64 maxCompFractionChange real64 0.5 Maximum (absolute) change in a component fraction in a Newton iteration maxRelativePressureChange real64 0.5 Maximum (relative) change in pressure in a Newton iteration maxRelativeTemperatureChange real64 0.5 Maximum (relative) change in temperature in a Newton iteration +maxSequentialCompDensChange real64 1 Maximum (absolute) component density change in a sequential iteration, used for outer loop convergence check +maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check +maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check minCompDens real64 1e-10 Minimum allowed global component density miscibleDBC integer 0 Flag for enabling DBC formulation with/without miscibility name groupName required A name is required for any non-unique nodes diff --git a/src/coreComponents/schema/docs/CompositionalMultiphaseHybridFVM.rst b/src/coreComponents/schema/docs/CompositionalMultiphaseHybridFVM.rst index 88c616ae31f..4cdd10dd766 100644 --- a/src/coreComponents/schema/docs/CompositionalMultiphaseHybridFVM.rst +++ b/src/coreComponents/schema/docs/CompositionalMultiphaseHybridFVM.rst @@ -14,6 +14,9 @@ maxAbsolutePressureChange real64 -1 Maximum (a maxCompFractionChange real64 0.5 Maximum (absolute) change in a component fraction in a Newton iteration maxRelativePressureChange real64 0.5 Maximum (relative) change in pressure in a Newton iteration maxRelativeTemperatureChange real64 0.5 Maximum (relative) change in temperature in a Newton iteration +maxSequentialCompDensChange real64 1 Maximum (absolute) component density change in a sequential iteration, used for outer loop convergence check +maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check +maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check minCompDens real64 1e-10 Minimum allowed global component density name groupName required A name is required for any non-unique nodes solutionChangeScalingFactor real64 0.5 Damping factor for solution change targets diff --git a/src/coreComponents/schema/docs/ElasticFirstOrderSEM_other.rst b/src/coreComponents/schema/docs/ElasticFirstOrderSEM_other.rst index d5e3c9c7a50..a5e6f05623a 100644 --- a/src/coreComponents/schema/docs/ElasticFirstOrderSEM_other.rst +++ b/src/coreComponents/schema/docs/ElasticFirstOrderSEM_other.rst @@ -17,6 +17,12 @@ receiverConstants real64_array2d receiverIsLocal integer_array Flag that indicates whether the receiver is local to this MPI rank receiverNodeIds integer_array2d Indices of the nodes (in the right order) for each receiver point receiverRegion integer_array Region containing the receivers +sigmaxxNp1AtReceivers real32_array2d Displacement value at each receiver for each timestep (z-components) +sigmaxyNp1AtReceivers real32_array2d Displacement value at each receiver for each timestep (z-components) +sigmaxzNp1AtReceivers real32_array2d Displacement value at each receiver for each timestep (z-components) +sigmayyNp1AtReceivers real32_array2d Displacement value at each receiver for each timestep (z-components) +sigmayzNp1AtReceivers real32_array2d Displacement value at each receiver for each timestep (z-components) +sigmazzNp1AtReceivers real32_array2d Displacement value at each receiver for each timestep (z-components) sourceConstants real64_array2d Constant part of the source for the nodes listed in m_sourceNodeIds sourceElem integer_array Element containing the sources sourceIsAccessible integer_array Flag that indicates whether the source is local to this MPI rank diff --git a/src/coreComponents/schema/docs/Hydrofracture.rst b/src/coreComponents/schema/docs/Hydrofracture.rst index 8f484061b08..c65d103f356 100644 --- a/src/coreComponents/schema/docs/Hydrofracture.rst +++ b/src/coreComponents/schema/docs/Hydrofracture.rst @@ -15,6 +15,7 @@ name groupName required A name is required for any solidSolverName groupNameRef required Name of the solid solver used by the coupled solver surfaceGeneratorName groupNameRef required Name of the surface generator to use in the hydrofracture solver targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. +useQuasiNewton integer 0 (no description available) LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` ========================= ================== ======== ====================================================================================================================================================================================================================================================================================================================== diff --git a/src/coreComponents/schema/docs/NonlinearSolverParameters.rst b/src/coreComponents/schema/docs/NonlinearSolverParameters.rst index c8511aad1ff..0a48c42e401 100644 --- a/src/coreComponents/schema/docs/NonlinearSolverParameters.rst +++ b/src/coreComponents/schema/docs/NonlinearSolverParameters.rst @@ -16,6 +16,7 @@ lineSearchInterpolationType geos_NonlinearSolverParameters_LineSearchInterpol | * Linear | * Parabolic lineSearchMaxCuts integer 4 Maximum number of line search cuts. +lineSearchStartingIteration integer 0 Iteration when line search starts. logLevel integer 0 Log level maxAllowedResidualNorm real64 1e+09 Maximum value of residual norm that is allowed in a Newton loop maxNumConfigurationAttempts integer 10 Max number of times that the configuration can be changed @@ -32,6 +33,7 @@ normType geos_solverBaseKernels_NormType sequentialConvergenceCriterion geos_NonlinearSolverParameters_SequentialConvergenceCriterion ResidualNorm | Criterion used to check outer-loop convergence in sequential schemes. Valid options: | * ResidualNorm | * NumberOfNonlinearIterations + | * SolutionIncrements subcycling integer 0 Flag to decide whether to iterate between sequentially coupled solvers or not. timeStepCutFactor real64 0.5 Factor by which the time step will be cut if a timestep cut is required. timeStepDecreaseFactor real64 0.5 Factor by which the time step is decreased when the number of Newton iterations is large. diff --git a/src/coreComponents/schema/docs/ProppantTransport.rst b/src/coreComponents/schema/docs/ProppantTransport.rst index 7a8c3089ec0..c7b0b39c500 100644 --- a/src/coreComponents/schema/docs/ProppantTransport.rst +++ b/src/coreComponents/schema/docs/ProppantTransport.rst @@ -1,26 +1,28 @@ -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== -Name Type Default Description -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== -allowNegativePressure integer 1 Flag indicating if negative pressure is allowed -bridgingFactor real64 0 Bridging factor used for bridging/screen-out calculation -cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] -criticalShieldsNumber real64 0 Critical Shields number -discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. -frictionCoefficient real64 0.03 Friction coefficient -initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. -isThermal integer 0 Flag indicating whether the problem is thermal or not. -logLevel integer 0 Log level -maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration -maxProppantConcentration real64 0.6 Maximum proppant concentration -name groupName required A name is required for any non-unique nodes -proppantDensity real64 2500 Proppant density -proppantDiameter real64 0.0004 Proppant diameter -targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. -updateProppantPacking integer 0 Flag that enables/disables proppant-packing update -LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` -NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +Name Type Default Description +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +allowNegativePressure integer 1 Flag indicating if negative pressure is allowed +bridgingFactor real64 0 Bridging factor used for bridging/screen-out calculation +cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] +criticalShieldsNumber real64 0 Critical Shields number +discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. +frictionCoefficient real64 0.03 Friction coefficient +initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. +isThermal integer 0 Flag indicating whether the problem is thermal or not. +logLevel integer 0 Log level +maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration +maxProppantConcentration real64 0.6 Maximum proppant concentration +maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check +maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check +name groupName required A name is required for any non-unique nodes +proppantDensity real64 2500 Proppant density +proppantDiameter real64 0.0004 Proppant diameter +targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. +updateProppantPacking integer 0 Flag that enables/disables proppant-packing update +LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` +NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== diff --git a/src/coreComponents/schema/docs/ReactiveCompositionalMultiphaseOBL.rst b/src/coreComponents/schema/docs/ReactiveCompositionalMultiphaseOBL.rst index af0ee1e1c5c..da7fa66a198 100644 --- a/src/coreComponents/schema/docs/ReactiveCompositionalMultiphaseOBL.rst +++ b/src/coreComponents/schema/docs/ReactiveCompositionalMultiphaseOBL.rst @@ -1,29 +1,31 @@ -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== -Name Type Default Description -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== -OBLOperatorsTableFile path required File containing OBL operator values -allowLocalOBLChopping integer 1 Allow keeping solution within OBL limits -allowNegativePressure integer 1 Flag indicating if negative pressure is allowed -cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] -componentNames string_array {} List of component names -discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. -enableEnergyBalance integer required Enable energy balance calculation and temperature degree of freedom -initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. -isThermal integer 0 Flag indicating whether the problem is thermal or not. -logLevel integer 0 Log level -maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration -maxCompFractionChange real64 1 Maximum (absolute) change in a component fraction between two Newton iterations -name groupName required A name is required for any non-unique nodes -numComponents integer required Number of components -numPhases integer required Number of phases -phaseNames groupNameRef_array {} List of fluid phases -targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. -transMultExp real64 1 Exponent of dynamic transmissibility multiplier -useDARTSL2Norm integer 1 Use L2 norm calculation similar to one used DARTS -LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` -NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +Name Type Default Description +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +OBLOperatorsTableFile path required File containing OBL operator values +allowLocalOBLChopping integer 1 Allow keeping solution within OBL limits +allowNegativePressure integer 1 Flag indicating if negative pressure is allowed +cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] +componentNames string_array {} List of component names +discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. +enableEnergyBalance integer required Enable energy balance calculation and temperature degree of freedom +initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. +isThermal integer 0 Flag indicating whether the problem is thermal or not. +logLevel integer 0 Log level +maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration +maxCompFractionChange real64 1 Maximum (absolute) change in a component fraction between two Newton iterations +maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check +maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check +name groupName required A name is required for any non-unique nodes +numComponents integer required Number of components +numPhases integer required Number of phases +phaseNames groupNameRef_array {} List of fluid phases +targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. +transMultExp real64 1 Exponent of dynamic transmissibility multiplier +useDARTSL2Norm integer 1 Use L2 norm calculation similar to one used DARTS +LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` +NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== diff --git a/src/coreComponents/schema/docs/SinglePhaseFVM.rst b/src/coreComponents/schema/docs/SinglePhaseFVM.rst index 1f7ecbc504a..6000056c728 100644 --- a/src/coreComponents/schema/docs/SinglePhaseFVM.rst +++ b/src/coreComponents/schema/docs/SinglePhaseFVM.rst @@ -1,20 +1,22 @@ -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== -Name Type Default Description -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== -allowNegativePressure integer 1 Flag indicating if negative pressure is allowed -cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] -discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. -initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. -isThermal integer 0 Flag indicating whether the problem is thermal or not. -logLevel integer 0 Log level -maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration -name groupName required A name is required for any non-unique nodes -targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. -temperature real64 0 Temperature -LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` -NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +Name Type Default Description +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +allowNegativePressure integer 1 Flag indicating if negative pressure is allowed +cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] +discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. +initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. +isThermal integer 0 Flag indicating whether the problem is thermal or not. +logLevel integer 0 Log level +maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration +maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check +maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check +name groupName required A name is required for any non-unique nodes +targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. +temperature real64 0 Temperature +LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` +NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== diff --git a/src/coreComponents/schema/docs/SinglePhaseHybridFVM.rst b/src/coreComponents/schema/docs/SinglePhaseHybridFVM.rst index 1f7ecbc504a..6000056c728 100644 --- a/src/coreComponents/schema/docs/SinglePhaseHybridFVM.rst +++ b/src/coreComponents/schema/docs/SinglePhaseHybridFVM.rst @@ -1,20 +1,22 @@ -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== -Name Type Default Description -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== -allowNegativePressure integer 1 Flag indicating if negative pressure is allowed -cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] -discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. -initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. -isThermal integer 0 Flag indicating whether the problem is thermal or not. -logLevel integer 0 Log level -maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration -name groupName required A name is required for any non-unique nodes -targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. -temperature real64 0 Temperature -LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` -NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +Name Type Default Description +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +allowNegativePressure integer 1 Flag indicating if negative pressure is allowed +cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] +discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. +initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. +isThermal integer 0 Flag indicating whether the problem is thermal or not. +logLevel integer 0 Log level +maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration +maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check +maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check +name groupName required A name is required for any non-unique nodes +targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. +temperature real64 0 Temperature +LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` +NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== diff --git a/src/coreComponents/schema/docs/SinglePhaseProppantFVM.rst b/src/coreComponents/schema/docs/SinglePhaseProppantFVM.rst index 1f7ecbc504a..6000056c728 100644 --- a/src/coreComponents/schema/docs/SinglePhaseProppantFVM.rst +++ b/src/coreComponents/schema/docs/SinglePhaseProppantFVM.rst @@ -1,20 +1,22 @@ -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== -Name Type Default Description -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== -allowNegativePressure integer 1 Flag indicating if negative pressure is allowed -cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] -discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. -initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. -isThermal integer 0 Flag indicating whether the problem is thermal or not. -logLevel integer 0 Log level -maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration -name groupName required A name is required for any non-unique nodes -targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. -temperature real64 0 Temperature -LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` -NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` -========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +Name Type Default Description +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +allowNegativePressure integer 1 Flag indicating if negative pressure is allowed +cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] +discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. +initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. +isThermal integer 0 Flag indicating whether the problem is thermal or not. +logLevel integer 0 Log level +maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration +maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check +maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check +name groupName required A name is required for any non-unique nodes +targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. +temperature real64 0 Temperature +LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` +NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` +============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index 30b6086298b..3ec4907afa8 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -1868,6 +1868,8 @@ the relative residual norm satisfies: + + @@ -1890,7 +1892,8 @@ the relative residual norm satisfies: +* NumberOfNonlinearIterations +* SolutionIncrements--> @@ -1931,7 +1934,7 @@ the relative residual norm satisfies: - + @@ -2367,6 +2370,12 @@ the relative residual norm satisfies: + + + + + + @@ -2439,6 +2448,12 @@ the relative residual norm satisfies: + + + + + + @@ -2792,6 +2807,8 @@ Equal to 1 for surface conditions, and to 0 for reservoir conditions--> + + @@ -2986,6 +3003,10 @@ Local - Add stabilization only to interiors of macro elements.--> + + + + @@ -3026,6 +3047,10 @@ Local - Add stabilization only to interiors of macro elements.--> + + + + @@ -3060,6 +3085,10 @@ Local - Add stabilization only to interiors of macro elements.--> + + + + @@ -3086,6 +3115,10 @@ Local - Add stabilization only to interiors of macro elements.--> + + + + @@ -3200,6 +3233,10 @@ Local - Add stabilization only to interiors of macro elements.--> + + + + diff --git a/src/coreComponents/schema/schema.xsd.other b/src/coreComponents/schema/schema.xsd.other index 7293c48421c..2f28666e192 100644 --- a/src/coreComponents/schema/schema.xsd.other +++ b/src/coreComponents/schema/schema.xsd.other @@ -810,6 +810,18 @@ + + + + + + + + + + + + diff --git a/src/coreComponents/unitTests/CMakeLists.txt b/src/coreComponents/unitTests/CMakeLists.txt index ad8e50cf3fa..3d49c154263 100644 --- a/src/coreComponents/unitTests/CMakeLists.txt +++ b/src/coreComponents/unitTests/CMakeLists.txt @@ -11,4 +11,4 @@ add_subdirectory( finiteVolumeTests ) add_subdirectory( fileIOTests ) add_subdirectory( fluidFlowTests ) add_subdirectory( wellsTests ) -add_subdirectory( wavePropagationTests ) +add_subdirectory( wavePropagationTests ) diff --git a/src/coreComponents/unitTests/wavePropagationTests/CMakeLists.txt b/src/coreComponents/unitTests/wavePropagationTests/CMakeLists.txt index b95a1dd7e3e..a555936aeaf 100644 --- a/src/coreComponents/unitTests/wavePropagationTests/CMakeLists.txt +++ b/src/coreComponents/unitTests/wavePropagationTests/CMakeLists.txt @@ -1,6 +1,7 @@ # Specify list of tests set( gtest_geosx_tests testWavePropagation.cpp + testWavePropagationElasticFirstOrder.cpp testWavePropagationDAS.cpp testWavePropagationAcousticFirstOrder.cpp ) diff --git a/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationAcousticFirstOrder.cpp b/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationAcousticFirstOrder.cpp index 9b787e6a7ab..2da611b46e7 100644 --- a/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationAcousticFirstOrder.cpp +++ b/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationAcousticFirstOrder.cpp @@ -22,7 +22,6 @@ #include "mainInterface/GeosxState.hpp" #include "physicsSolvers/PhysicsSolverManager.hpp" #include "physicsSolvers/wavePropagation/WaveSolverBase.hpp" -#include "physicsSolvers/wavePropagation/WaveSolverBaseFields.hpp" #include "physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.hpp" #include diff --git a/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationElasticFirstOrder.cpp b/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationElasticFirstOrder.cpp new file mode 100644 index 00000000000..f34f65d7a92 --- /dev/null +++ b/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationElasticFirstOrder.cpp @@ -0,0 +1,303 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 Total, S.A + * Copyright (c) 2020- GEOSX Contributors + * All right reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +// using some utility classes from the following unit test +#include "unitTests/fluidFlowTests/testCompFlowUtils.hpp" + +#include "common/DataTypes.hpp" +#include "mainInterface/initialization.hpp" +#include "mainInterface/ProblemManager.hpp" +#include "mesh/DomainPartition.hpp" +#include "mainInterface/GeosxState.hpp" +#include "physicsSolvers/PhysicsSolverManager.hpp" +#include "physicsSolvers/wavePropagation/WaveSolverBase.hpp" +#include "physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.hpp" + +#include + +using namespace geos; +using namespace geos::dataRepository; +using namespace geos::testing; + +CommandLineOptions g_commandLineOptions; + +// This unit test checks the interpolation done to extract seismic traces from a wavefield. +// It computes a seismogram at a receiver co-located with the source and compares it to the surrounding receivers. +char const * xmlInput = + R"xml( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + )xml"; + +class ElasticFirstOrderWaveEquationSEMTest : public ::testing::Test +{ +public: + + ElasticFirstOrderWaveEquationSEMTest(): + state( std::make_unique< CommandLineOptions >( g_commandLineOptions ) ) + {} + +protected: + + void SetUp() override + { + setupProblemFromXML( state.getProblemManager(), xmlInput ); + } + + static real64 constexpr time = 0.0; + static real64 constexpr dt = 5e-2; + static real64 constexpr eps = std::numeric_limits< real64 >::epsilon(); + + GeosxState state; + ElasticFirstOrderWaveEquationSEM * propagator; +}; + +real64 constexpr ElasticFirstOrderWaveEquationSEMTest::time; +real64 constexpr ElasticFirstOrderWaveEquationSEMTest::dt; +real64 constexpr ElasticFirstOrderWaveEquationSEMTest::eps; + +TEST_F( ElasticFirstOrderWaveEquationSEMTest, SeismoTrace ) +{ + + DomainPartition & domain = state.getProblemManager().getDomainPartition(); + propagator = &state.getProblemManager().getPhysicsSolverManager().getGroup< ElasticFirstOrderWaveEquationSEM >( "elasticFirstOrderSolver" ); + real64 time_n = time; + // run for 1s (20 steps) + for( int i=0; i<20; i++ ) + { + propagator->solverStep( time_n, dt, i, domain ); + time_n += dt; + } + // cleanup (triggers calculation of the remaining seismograms data points) + propagator->cleanup( 1.0, 20, 0, 0, domain ); + + // retrieve seismo + arrayView2d< real32 > const uxReceivers = propagator->getReference< array2d< real32 > >( ElasticFirstOrderWaveEquationSEM::viewKeyStruct::displacementxNp1AtReceiversString() ).toView(); + arrayView2d< real32 > const uyReceivers = propagator->getReference< array2d< real32 > >( ElasticFirstOrderWaveEquationSEM::viewKeyStruct::displacementyNp1AtReceiversString() ).toView(); + arrayView2d< real32 > const uzReceivers = propagator->getReference< array2d< real32 > >( ElasticFirstOrderWaveEquationSEM::viewKeyStruct::displacementzNp1AtReceiversString() ).toView(); + arrayView2d< real32 > const sigmaxxReceivers = propagator->getReference< array2d< real32 > >( ElasticFirstOrderWaveEquationSEM::viewKeyStruct::sigmaxxNp1AtReceiversString()).toView(); + arrayView2d< real32 > const sigmayyReceivers = propagator->getReference< array2d< real32 > >( ElasticFirstOrderWaveEquationSEM::viewKeyStruct::sigmayyNp1AtReceiversString()).toView(); + arrayView2d< real32 > const sigmazzReceivers = propagator->getReference< array2d< real32 > >( ElasticFirstOrderWaveEquationSEM::viewKeyStruct::sigmazzNp1AtReceiversString()).toView(); + // move it to CPU, if needed + uxReceivers.move( LvArray::MemorySpace::host, false ); + uyReceivers.move( LvArray::MemorySpace::host, false ); + uzReceivers.move( LvArray::MemorySpace::host, false ); + sigmaxxReceivers.move( LvArray::MemorySpace::host, false ); + sigmayyReceivers.move( LvArray::MemorySpace::host, false ); + sigmazzReceivers.move( LvArray::MemorySpace::host, false ); + + // check number of seismos and trace length + ASSERT_EQ( uxReceivers.size( 1 ), 10 ); + ASSERT_EQ( uxReceivers.size( 0 ), 21 ); + ASSERT_EQ( uyReceivers.size( 1 ), 10 ); + ASSERT_EQ( uyReceivers.size( 0 ), 21 ); + ASSERT_EQ( uzReceivers.size( 1 ), 10 ); + ASSERT_EQ( uzReceivers.size( 0 ), 21 ); + ASSERT_EQ( sigmaxxReceivers.size( 1 ), 10 ); + ASSERT_EQ( sigmaxxReceivers.size( 0 ), 21 ); + ASSERT_EQ( sigmayyReceivers.size( 1 ), 10 ); + ASSERT_EQ( sigmayyReceivers.size( 0 ), 21 ); + ASSERT_EQ( sigmazzReceivers.size( 1 ), 10 ); + ASSERT_EQ( sigmazzReceivers.size( 0 ), 21 ); + + // check seismo content. The pressure and velocity values cannot be directly checked as the problem is too small. + // Since the basis is linear, check that the seismograms are nonzero (for t>0) and the seismogram at the center is equal + // to the average of the others. + for( int i = 0; i < 21; i++ ) + { + if( i > 0 ) + { + ASSERT_TRUE( std::abs( uxReceivers[i][8] ) > 0 ); + ASSERT_TRUE( std::abs( uyReceivers[i][8] ) > 0 ); + ASSERT_TRUE( std::abs( uzReceivers[i][8] ) > 0 ); + ASSERT_TRUE( std::abs( sigmaxxReceivers[i][8] ) > 0 ); + ASSERT_TRUE( std::abs( sigmayyReceivers[i][8] ) > 0 ); + ASSERT_TRUE( std::abs( sigmazzReceivers[i][8] ) > 0 ); + } + double avgUx = 0; + double avgUy = 0; + double avgUz = 0; + double avgSxx = 0; + double avgSyy = 0; + double avgSzz = 0; + for( int r=0; r<8; r++ ) + { + avgUx += uxReceivers[i][r]; + avgUy += uyReceivers[i][r]; + avgUz += uzReceivers[i][r]; + avgSxx += sigmaxxReceivers[i][r]; + avgSyy += sigmayyReceivers[i][r]; + avgSzz += sigmazzReceivers[i][r]; + } + avgUx /= 8.0; + avgUy /= 8.0; + avgUz /= 8.0; + avgSxx /= 8.0; + avgSyy /= 8.0; + avgSzz /= 8.0; + ASSERT_TRUE( std::abs( uxReceivers[i][8] - avgUx ) < 0.00001 ); + ASSERT_TRUE( std::abs( uyReceivers[i][8] - avgUy ) < 0.00001 ); + ASSERT_TRUE( std::abs( uzReceivers[i][8] - avgUz ) < 0.00001 ); + ASSERT_TRUE( std::abs( sigmaxxReceivers[i][8] - avgSxx ) < 0.00001 ); + ASSERT_TRUE( std::abs( sigmayyReceivers[i][8] - avgSyy ) < 0.00001 ); + ASSERT_TRUE( std::abs( sigmazzReceivers[i][8] - avgSzz ) < 0.00001 ); + } +} + +int main( int argc, char * * argv ) +{ + ::testing::InitGoogleTest( &argc, argv ); + g_commandLineOptions = *geos::basicSetup( argc, argv ); + int const result = RUN_ALL_TESTS(); + geos::basicCleanup(); + return result; +} diff --git a/src/docs/sphinx/developerGuide/Contributing/IntegratedTests.rst b/src/docs/sphinx/developerGuide/Contributing/IntegratedTests.rst index 034c41cc487..f2e355372c2 100644 --- a/src/docs/sphinx/developerGuide/Contributing/IntegratedTests.rst +++ b/src/docs/sphinx/developerGuide/Contributing/IntegratedTests.rst @@ -1,3 +1,631 @@ -.. _IntegratedTests: - -.. include:: ../../../../../integratedTests/docs/getting_started.rst +.. _IntegratedTests: + +############################################################################### +Integrated Tests +############################################################################### + +About +================================= +*integratedTests* is a submodule of *GEOS* residing at the top level of the directory structure. +It defines a set of tests that will run *GEOS* with various *.xml* files and partitioning schemes using the `Automated Test System `_ (ATS). +For each scenario, test performance is evaluated by comparing output files to baselines recorded in this repository. + + +Structure +================================= + +The *integratedTests* repository includes a python package (*integratedTests/scripts/geos_ats_package*) and a directory containing test definitions (*integratedTests/tests/allTests*). +A typical test directory will include an *.ats* file, which defines the behavior of tests or points to child test directories, symbolic links to any required *.xml* files, and a directory containing baseline files. + + +.. code-block:: sh + + - integratedTests/ + - scripts/ + - geos_ats_package + - tests/ + - allTests/ + - main.ats/ + - sedov/ + - baselines/ + - sedov_XX/ + - + - sedov.ats + - sedov.xml + + +High level integrated test results are recorded in the GEOS build directory: */path/to/GEOS/build-xyz/integratedTests/TestsResults*. +These include *.log* and *.err* files for each test and a *test_results.html* summary file, which can be inspected in your browser. + + +.. note:: + Baseline files are stored using the git LFS (large file storage) plugin. + If you followed the suggested commands in the quickstart guide, then your environment is likely already setup. + + However, if lfs is not yet activated, then the contents of baseline files may look something like this: + + 0to100_restart_000000100/rank_0000003.hdf5 + version https://git-lfs.github.com/spec/v1 + oid sha256:09bbe1e92968852cb915b971af35b0bba519fae7cf5934f3abc7b709ea76308c + size 1761208 + + If this is the case, try running the following commands: ``git lfs install`` and ``git lfs pull``. + + + +How to Run the Tests +================================= + +In most cases, integrated tests processes can be triggered in the GEOS build directory with the following commands: + +* `make ats_environment` : Setup the testing environment (Note: this step is run by default for the other make targets). This process will install packages required for testing into the python environment defined in your current host config file. Depending on how you have built GEOS, you may be prompted to manually run the `make pygeosx` command and then re-run this step. +* `make ats_run` : Run all of the available tests (see the below note on testing resources). +* `make ats_clean` : Remove any unnecessary files created during the testing process (.vtk, .hdf5 files, etc.) +* `make ats_rebaseline` : Selectively update the baseline files for tests. +* `make ats_rebaseline_failed` : Automatically update the baseline files for any failed tests. + + +.. note:: + The `make_ats_environment` step will attempt to collect python packages github and pypi, so it should be run from a machine with internet access. + + +.. note:: + Running the integrated tests requires significant computational resources. + If you are on a shared system, we recommend that you only run `make ats_run` within an allocation. + + +.. note:: + We forward any arguments included in the `ATS_ARGUMENTS` cmake variable to the testing system. + For example, on LLNL Lassen builds we select a couple of runtime options: + set(ATS_ARGUMENTS "--ats jsrun_omp --ats jsrun_bind=packed" CACHE STRING "") + + +.. note:: + When running test or creating new baselines on LC systems, we recommend that you use the *quartz-gcc-12-release* configuration + + +Override Test Behavior +------------------------- + +For cases where you need additional control over the integrated tests behavior, you can use this script in your build directory: */path/to/GEOS/build-xyz/integratedTests/geos_ats.sh*. +To run the tests, simply call this script with any desired arguments (see the output of `geos_ats.sh --help` for additional details.) +Common options for this script include: + +* -a/--action : The type of action to run. Common options include: `run`, `veryclean`, `rebaseline`, and `rebaselinefailed`. +* -r/--restartCheckOverrides : Arguments to pass to the restart check function. Common options include: `skip_missing` (ignores any new/missing values in restart files) and `exclude parameter1 parameter2` (ignore these values in restart files). +* --machine : Set the ats machine type name. +* --ats : Pass an argument to the underlying ats framework. Running `geos_ats.sh --ats help` will show you a list of available options for your current machine. + + +Machine Definitions +------------------------ + +On many machines, ATS will automatically identify your machine's configuration and optimize it's performance. +If the tests fail to run or to properly leverage your machine's resources, you may need to manually configure the machine. +If you know the appropriate name for your machine in ATS (or the geos_ats package), then you can run `./geos_ats.sh --machine machine_name --ats help` to see a list of potential configuration options. + +The `openmpi` machine is a common option for non-LC systems. +For a system with 32 cores/node, an appropriate run command might look like: + +.. code-block:: sh + + ./geos_ats.sh --machine openmpi --ats openmpi_numnodes 32 --ats openmpi_args=--report-bindings --ats openmpi_args="--bind-to none" --ats openmpi_install "/path/to/openmpi/installation" + + +.. note:: + In this example, the path given by `openmpi_install` should include `bin/mpirun`. + + +.. note:: + When you have identified a set of arguments that work for your machine, we recommend recording in the `ATS_ARGUMENTS` cmake variable in your system host config file. + + +Test Filtering +------------------------ + +An arbitrary number of filter arguments can be supplied to ATS to limit the number of tests to be run. +Filter arguments should refer to an ATS test variable and use a python-syntax (e.g.: "'some_string' in ats_variable" or "ats_variable<10"). +These can be set via command-line arguments (possible via the `ATS_ARGUMENTS` variable): + +.. code-block:: sh + + ./geos_ats.sh --ats f "np==1" --ats f "'SinglePhaseFVM' in solvers" + + +or via an environment variable (`ATS_FILTER`): + +.. code-block:: sh + + export ATS_FILTER="np==1,'SinglePhaseFVM' in solvers" + + +Common ATS variables that you can filter tests include: + +* np : The number of parallel processes for the test +* label : The name of the test case (e.g.: "sedov_01") +* collection : The name of the parent test folder (e.g.: "contactMechanics") +* checks : A comma-separated list of checks (e.g.: "curve,restart") +* solvers : A comma-separated list of solver types (e.g.: "SinglePhaseFVM,SurfaceGenerator") +* outputs : A comma-separated list of output types (e.g.: "Restart,VTK") +* constitutive_models : A comma-separated list of constitutive model types (e.g.: "CompressibleSinglePhaseFluid,ElasticIsotropic") + + +Inspecting Test Results +================================= + +While the tests are running, the name and size of the active test will be periodically printed out to the screen. +Test result summaries will also be periodically written to the screen and files in */path/to/GEOS/build-xyz/integratedTests/TestsResults*. +For most users, we recommend inspecting the *test_results.html* file in your browser (e.g.: `firefox integratedTests/TestsResults/test_results.html`). +Tests will be organized by their status variable, which includes: + + +* *RUNNING* : The test is currently running +* *NOT RUN* : The test is waiting to start +* *PASSED* : The test and associated checks succeeded +* *FAIL RUN* : The test was unable to run (this often occurs when there is an error in the .ats file) +* *FAIL CHECK* : The test ran to completion, but failed either its restart or curve check +* *SKIPPED* : The test was skipped (likely due to lack of computational resources) + + +If each test ends up in the *PASSED* category, then you are likely done with the integrated testing procedure. +However, if tests end up in any other category, it is your responsibility to address the failure. +If you identify that a failure is due to an expected change in the code (e.g.: adding a new parameter to the xml structure or fixing a bug in an algorithm), you can follow the :ref:`rebaselining procedure `. +Otherwise, you will need to track down and potentially fix the issue that triggered the failure. + + +Test Output +-------------------------------- + +Output files from the tests will be stored in the TestResults directory (*/path/to/GEOS/build-xyz/integratedTests/TestsResults*) or in a subdirectory next to their corresponding *.xml* file (*integratedTests/tests/allTests/testGroup/testName_xx*). +Using the serial beam bending test as an example, key output files include: + +* *beamBending_01.data* : Contains the standard output for all test steps. +* *beamBending_01.err* : Contains the standard error output for all test steps. +* *displacement_history.hdf5* : Contains time history information that is used as an input to the curve check step. +* *totalDisplacement_trace.png* : A figure displaying the results of the curve check step. +* *beamBending.geos.out* : Contains the standard output for only the geos run step. +* *beamBending_restart_000000010.restartcheck* which holds all of the standard output for only the *restartcheck* step. +* *beamBending_restart_000000010.0.diff.hdf5* which mimmics the hierarchy of the restart file and has links to the + +See :ref:`Restart Check ` and :ref:`Curve Check ` for further details on the test checks and output files. + + +.. _restart-check: + +Restart Check +================================= + +This check compares a restart file output at the end of a run against a baseline. +The python script that evaluates the diff is included in the `geos_ats` package, and is located here: *integratedTests/scripts/geos_ats_package/geos_ats/helpers/restart_check.py*. +The script compares the two restart files and writes out a *.restart_check* file with the results, as well as exiting with an error code if the files compare differently. +This script takes two positional arguments and a number of optional keyword arguments: + +* file_pattern : Regex specifying the restart file. If the regex matches multiple files the one with the greater string is selected. For example *restart_100.hdf5* wins out over *restart_088.hdf5*. +* baseline_pattern : Regex specifying the baseline file. +* -r/--relative : The relative tolerance for floating point comparison, the default is 0.0. +* -a/--absolute : The absolute tolerance for floating point comparison, the default is 0.0. +* -e/--exclude : A list of regex expressions that match paths in the restart file tree to exclude from comparison. The default is [.*/commandLine]. +* -w/-Werror : Force warnings to be treated as errors, default is false. +* -m/--skip-missing : Ignore values that are missing from either the baseline or target file. + +The itself starts off with a summary of the arguments. +The script begins by recording the arguments to the *.restart_check* file header, and then compares the *.root* restart files to their baseline. +If these match, the script will compare the linked *.hdf5* data files to their baseline. +If the script encounters any differences it will output an error message, and record a summary to the *.restart_check* file. + +The restart check step can be run in parallel using mpi via + +.. code-block:: sh + + mpirun -n NUM_PROCESSES python -m mpi4py restartcheck.py ... + +In this case rank zero reads in the restart root file and then each rank parses a subset of the data files creating a *.$RANK.restartcheck* file. Rank zero then merges the output from each of these files into the main *.restartcheck* file and prints it to standard output. + + +Scalar Error Example +------------------------------- + +An error message for scalar values looks as follows + +.. code-block:: sh + + Error: /datagroup_0000000/sidre/external/ProblemManager/domain/ConstitutiveManager/shale/YoungsModulus + Scalar values of types float64 and float64 differ: 22500000000.0, 10000022399.9. + +Where the first value is the value in the test's restart file and the second is the value in the baseline. + + +Array Error Example +-------------------------------- + +An example of an error message for arrays is + +.. code-block:: sh + + Error: /datagroup_0000000/sidre/external/ProblemManager/domain/MeshBodies/mesh1/Level0/nodeManager/TotalDisplacement + Arrays of types float64 and float64 have 1836 values of which 1200 have differing values. + Statistics of the differences greater than 0: + max_index = (1834,), max = 2.47390764755, mean = 0.514503482629, std = 0.70212888881 + +This means that the max absolute difference is 2.47 which occurs at value 1834. Of the values that are not equal the mean absolute difference is 0.514 and the standard deviation of the absolute difference is 0.702. + +When the tolerances are non zero the comparison is a bit more complicated. From the *FileComparison.compareFloatArrays* method documentation + +.. code-block:: sh + + Entries x1 and x2 are considered equal iff + |x1 - x2| <= ATOL or |x1 - x2| <= RTOL * |x2|. + To measure the degree of difference a scaling factor q is introduced. The goal is now to minimize q such that + |x1 - x2| <= ATOL * q or |x1 - x2| <= RTOL * |x2| * q. + If RTOL * |x2| > ATOL + q = |x1 - x2| / (RTOL * |x2|) + else + q = |x1 - x2| / ATOL. + If the maximum value of q over all the entries is greater than 1.0 then the arrays are considered different and an error message is produced. + +An sample error message is + +.. code-block:: sh + + Error: /datagroup_0000000/sidre/external/ProblemManager/domain/MeshBodies/mesh1/Level0/nodeManager/TotalDisplacement + Arrays of types float64 and float64 have 1836 values of which 1200 fail both the relative and absolute tests. + Max absolute difference is at index (1834,): value = 2.07474948094, base_value = 4.54865712848 + Max relative difference is at index (67,): value = 0.00215842135281, base_value = 0.00591771127792 + Statistics of the q values greater than 1.0 defined by the absolute tolerance: N = 1200 + max = 16492717650.3, mean = 3430023217.52, std = 4680859258.74 + Statistics of the q values greater than 1.0 defined by the relative tolerance: N = 0 + + +The *.diff.hdf5* File +--------------------------------- + +Each error generated in the *restartcheck* step creates a group with three children in the *_diff.df5* file. +For example the error given above will generate a hdf5 group + +.. code-block:: sh + + /FILENAME/datagroup_0000000/sidre/external/ProblemManager/domain/MeshBodies/mesh1/Level0/nodeManager/TotalDisplacement + +with datasets *baseline*, *run* and *message* where *FILENAME* is the name of the restart data file being compared. +The *message* dataset contains a copy of the error message while *baseline* is a symbolic link to the baseline dataset and *run* is a sumbolic link to the dataset genereated by the run. +This allows for easy access to the raw data underlying the diff without data duplication. For example if you want to extract the datasets into python you could do this: + +.. code-block:: python + + import h5py + file_path = "beamBending_restart_000000003_diff.hdf5" + path_to_data = "/beamBending_restart_000000011_0000000.hdf5/datagroup_0000000/sidre/external/ProblemManager/domain/MeshBodies/mesh1/Level0/nodeManager/TotalDisplacement" + f = h5py.File("file_path", "r") + error_message = f["path_to_data/message"] + run_data = f["path_to_data/run"][:] + baseline_data = f["path_to_data/baseline"][:] + + # Now run_data and baseline_data are numpy arrays that you may use as you see fit. + rtol = 1e-10 + atol = 1e-15 + absolute_diff = np.abs(run_data - baseline_data) < atol + hybrid_diff = np.close(run_data, baseline_data, rtol, atol) + +When run in parallel each rank creates a *.$RANK.diff.hdf5* file which contains the diff of each data file processed by that rank. + + +.. _curve-check: + +Curve Check +================================= + +This check compares time history (*.hdf5*) curves generated during GEOS execution against baseline and/or analytic solutions. +In contrast to restart checks, curve checks are designed to be flexible with regards to things like mesh construction, time stepping, etc. +The python script that evaluates the diff is included in the `geos_ats` package, and is located here: *integratedTests/scripts/geos_ats_package/geos_ats/helpers/curve_check.py*. +The script renders the curve check results as a figure, and will throw an error if curves are out of tolerance. +This script takes two positional arguments and a number of optional keyword arguments: + +* filename : Path to the time history file. +* baseline : Path to the baseline file. +* -c/--curve : Add a curve to the check (value) or (value, setname). Multiple curves are allowed. +* -s/--script : Python script instructions for curve comparisons (path, function, value, setname) +* -t/--tolerance : The tolerance for each curve check diffs (||x-y||/N). Default is 0. +* -w/-Werror : Force warnings to be treated as errors, default is false. +* -o/--output : Output figures to this directory. Default is ./curve_check_figures +* -n/--n-column : Number of columns to use for the output figure. Default is 1. +* -u/--units-time : Time units for plots. Options include milliseconds, seconds (default), minutes, hours, days, years + + +The curve check script begins by checking the target time history file for expected key values. +These include the time array ("value Time"), location array ("value ReferencePosition setname" or "value elementCenter setname"), and value array ("value setname"). +Any missing values will be recorded as errors in the output. + +The script will then run and record any user-requested python script instructions. +To do this, python will attempt to import the file given by *path* and evaluate the target function, which should accept the time history data as keyword arguments. +Note: to avoid side effects, please ensure that any imported scripts are appropriately guarded if they also allow direct execution: + + +.. code-block:: python + + if __name__ == '__main__': + main() + + +This script will then check the size of the time history items, and will attempt to interpolate them if they do not match (currently, we only support interpolation in time). +Finally, the script will compare the time history values to the baseline values and any script-generated values. +If any curves do not match (`||x-y||/N > tol`), this will be recorded as an error. + + +Item Not Found Errors +---------------------------- + +The following error would indicate that the requested baseline file was not found: + +.. code-block:: sh + + baseline file not found: /path/to/baseline/file + + +This type of error can occur if you are adding a new test, or if you time history output failed. + + + +The following errors would indicate that values were not found in time history files: + +.. code-block:: sh + + Value not found in target file: value + Set not found in target file: setname + Could not find location string for parameter: value, search... + + +The following error would indicate that a given curve exceeded its tolerance compared to script-generated values: + + +.. code-block:: sh + + script_value_setname diff exceeds tolerance: ||t-b||/N=100.0, script_tolerance=1.0 + + + +Adding and Modifying Tests +================================= + + +ATS Configuration File +--------------------------------- + +Files with the *.ats* extension are used to configure the integratedTests. +They use a Python 3.x syntax, and have a set of ATS-related methods loaded into the scope (TestCase, geos, source, etc.). +The root configuration file (*integratedTests/tests/allTests/main.ats*) finds and includes any test definitions in its subdirectories. +The remaining configuration files typically add one or more tests with varying partitioning and input xml files to ATS. + +The *integratedTests/tests/allTests/sedov/sedov.ats* file shows how to add three groups of tests. +This file begins by defining a set of common parameters, which are used later: + +.. literalinclude:: ../../../../../integratedTests/tests/allTests/sedov/sedov.ats + :language: python + :start-after: # Integrated Test Docs Begin Parameters + :end-before: # Integrated Test Docs End Parameters + + +It then enters over the requested partitioning schemes: + +.. literalinclude:: ../../../../../integratedTests/tests/allTests/sedov/sedov.ats + :language: python + :start-after: # Integrated Test Docs Begin Test Loop + :end-before: # Integrated Test Docs End Test Loop + + +and registers a unique test case with the `TestCase` method, which accepts the following arguments: + +* name : The name of the test. The expected convention for this variable is 'testName_N' (N = number of ranks) or 'testName_X_Y_Z' (X, Y, and Z ranks per dimension) +* desc : A brief description of the test +* label : The test label (typically 'auto') +* owner : The point(s) of contact for the test +* independent : A flag indicating whether the test is dependent on another test (typically True) +* steps: A tuple containing the test steps (minimum length = 1) + + +Test steps are run sequentially, and are created with the `geos` method. +If a given test step fails, then it will produce an error and any subsequent steps will be canceled. +This method accepts the following keyword arguments: + +* deck : The name of the input xml file. +* np : The number of parallel processes required to run the step. +* ngpu : The number of GPU devices required to run the step. Note: this argument is typically ignored for geos builds/machines that are not configured to use GPU's. In addition, we typically expect that np=ngpu. +* x_partitions : The number of partitions to use along the x-dimension +* y_partitions : The number of partitions to use along the y-dimension +* z_partitions : The number of partitions to use along the z-dimension +* name : The header to use for output file names +* restartcheck_params : (optional) If this value is defined, run a restart check with these parameters (specified as a dictionary). +* curvecheck_params : (optional) If this value is defined, run a curve check with these parameters (specified as a dictionary). +* restart_file : (optional) The name of a restart file to resume from. To use this option, there must be a previous step that produces the selected restart file. +* baseline_pattern : (optional) The regex for the baseline files to use (required if the name of the step differs from the baseline) +* allow_rebaseline : A flag that indicates whether this step can be rebaselined. This is typically only true for the first step in a test case. + + +Note that a given *.ats* file can create any number of tests and link to any number of input xml files. +For any given test step, we expect that at least one restart or curve check be defined. + + +Creating a New Test Directory +------------------------------- + +To add a new set of tests, create a new folder in the `integratedTests/tests/allTests*` directory. +This folder needs to include at least one *.ats* file to be included in the integrated tests. +Using the sedov example, after creating *sedov.ats* the directory should look like + +.. code-block:: sh + + - integratedTests/tests/allTests/sedov/ + - sedov.ats + - sedov.xml (this file should be a symbolic link to a GEOS input file located somewhere within */path/to/GEOS/inputFiles*) + +At this point you should run the integrated tests (in the build directory run: `make ats_run`). +Assuming that the new *geos* step for your test case was successful, the subsequent *restartcheck* step will fail because the baselines have not yet been created. +At this point the directory should look like this: + +.. code-block:: sh + + - integratedTests/tests/allTests/sedov/ + - sedov/ + - ... + - ... + - sedov.ats + - sedov.xml + - ... + + +You can then follow the steps in the next section to record the initial baseline files. + + +.. _rebaselining-tests: + +Rebaselining Tests +---------------------------- + +Occasionally you may need to add or update baseline files in the repository (possibly due to feature changes in the code). +This process is called rebaselining. +We suggest the following workflow: + + +Step 1 +^^^^^^^^^ + +In the GEOS repository, create or checkout a branch with your modifications: + +.. code-block:: sh + + cd /path/to/GEOS + git checkout -b user/feature/newFeature + + +Add your changes, confirm that they produce the expected results, and get approval for a pull request. +If your branch needs to be rebaselined, make sure to indicate this in your pull request with the appropriate Label. + + +Step 2 +^^^^^^^^^ + +Go to the integratedTests submodule, checkout and pull develop, and create a branch with the same name as the one in the main GEOS repository: + +.. code-block:: sh + + cd /path/to/GEOS/integratedTests + git checkout develop + git pull + git checkout -b user/feature/newFeature + + +Step 3 +^^^^^^^^^ + +Go back to your GEOS build directory and run the integrated tests: + +.. code-block:: sh + + # Note: on shared machines, run these commands in an allocation + cd /path/to/GEOS/build-dir/ + make ats_run + + +Inspect the test results that fail and determine which need to be **legitimately** rebaselined. +Arbitrarily changing baselines defeats the purpose of the integrated tests. +In your PR discussion, please identify which tests will change and any unusual behavior. + + +Step 4 +^^^^^^^^^ + +We can then rebaseline the tests. +In most cases, you will want to rebaseline all of the tests marked as **FAILED**. +To do this you can run this command in the build directory: + +.. code-block:: sh + + make ats_rebaseline_failed + + +Otherwise, you can run the following command, and select whether tests should be rebaselined one at a time via a ``[y/n]`` prompt. + +.. code-block:: sh + + make ats_rebaseline_failed + + +Make sure to only answer ``y`` to the tests that you actually want to rebaseline, otherwise correct baselines for already passing tests will still be updated and bloat your pull request and repository size. + + +Step 5 +^^^^^^^^^ + +Confirm that the new baselines are working as expected. +You can do this by cleaning the test directories and re-running the tests: + +.. code-block:: sh + + # Note: on shared machines, run these commands in an allocation + cd /path/to/GEOS/build-dir/ + make ats_clean + make ats_run + + +At this point you should pass all the integratedTests. + + +Step 6 +^^^^^^^^^ + +Clean out unnecessary files and add new ones to the branch: + +.. code-block:: sh + + cd /path/to/GEOS/build-dir/ + make ats_clean + + # Check for new or modified files + cd /path/to/GEOS/integratedTests + git status + + # Add new or modified files + git add file_a file_b ... + git commit -m "Updating baselines" + git push origin user/feature/newFeature + + +Step 6 +^^^^^^^^^ + +If you haven't already done so, create a merge request for your integratedTests branch. +Once you have received approval for your PR and are ready to continue, you can click merge the branch by clicking the button on github. + +You should then checkout the develop branch of integratedTests and pull the new changes. + +.. code-block:: sh + + cd /path/to/GEOS/integratedTests + git checkout develop + git pull + + +You then need to update the integratedTests 'hash' in your associated GEOS branch. + +.. code-block:: sh + + cd /path/to/GEOS/ + git add integratedTests + git commit -m "Updating the integratedTests hash" + git push origin user/feature/newFeature + + +At this point, you will need to wait for the CI/CD tests to run on github. +After they succeed, you can merge your branch into develop using the button on github. + + + +Tips +======= + + +**Parallel Tests**: On some development machines geosxats won't run parallel tests by default (e.g. on an linux laptop or workstation), and as a result many baselines will be skipped. +We highly recommend running tests and rebaselining on an MPI-aware platform. + +**Filtering Checks**: A common reason for rebaselining is that you have changed the name of an XML node in the input files. +While the baselines may be numerically identical, the restarts will fail because they contain different node names. +In this situation, it can be useful to add a filter to the restart check script using the *geos_ats.sh* script (see the `-e` and `-m` options in :ref:`Override Test Behavior` ) From ebb9fc0c08ca606baeb934edc5e4449738387e9e Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 22 Feb 2024 14:53:25 +0100 Subject: [PATCH 016/216] Revert "Merge commit 'c11ad8ecd2d0d0aba5cd0661eb6e72951252409d' into feature/dudes/table-layout" This reverts commit 8f74cfa7027ab13a3b82f0be10ba83fccf1f04ba. --- .devcontainer/devcontainer.json | 2 +- .github/workflows/ci_tests.yml | 15 +- host-configs/LLNL/quartz-base.cmake | 7 - ...4.1.2-openblas0.3.10-cuda11.7.1-sm70.cmake | 28 - host-configs/Stanford/sherlock-modules.sh | 17 +- .../benchmarks/SPE10/SPE10.ats | 19 - .../buckleyLeverettProblem.ats | 19 - .../isothermalLeakyWell.ats | 19 - .../thermalLeakyWell/thermalLeakyWell.ats | 19 - .../c1-ppu/c1_ppu.ats | 17 - .../compositionalMultiphaseFlow.ats | 91 --- .../benchmarks/Class09Pb3/Class09Pb3.ats | 24 - .../Egg/compositionalMultiphaseWell_Egg.ats | 26 - .../compositionalMultiphaseWell.ats | 88 --- .../efemFractureMechanics.ats | 68 -- .../hydraulicFracturing/Hydrofracturing.ats | 203 ------ .../hydrofractureSinglePhase2d.xml | 3 - .../kgdToughnessDominated_base.xml | 5 +- .../scripts/hydrofractureCurveChecks.py | 10 +- .../contactMechanics.ats | 51 -- inputFiles/main.ats | 21 - .../solidMechanicsMPM_dfgMovingGrid.ats | 20 - .../solidMechanicsMPM_particleRepartition.ats | 20 - .../solidMechanicsMPM_singleParticle.ats | 20 - .../multiphaseFlowFractures.ats | 25 - inputFiles/phaseField/PhaseFieldFracture.ats | 56 -- .../PoroElastic_Mandel_benchmark_fim.xml | 2 +- .../poroelasticCoupling_validation.ats | 91 --- .../poromechanics/poroElasticCoupling.ats | 281 -------- inputFiles/poromechanics/viscoPlastic.ats | 33 - ...ayPermeability_conformingFracture_base.xml | 3 +- ...c_conformingFracture_2d_faultSlip_base.xml | 5 +- ...conformingFracture_2d_openingFrac_base.xml | 5 +- .../poromechanicsFractures.ats | 74 -- inputFiles/proppant/proppantTransport.ats | 34 - inputFiles/simplePDE/SimpleSolvers.ats | 58 -- .../singlePhaseFlow/singlePhaseFlow.ats | 81 --- .../thermalSinglePhaseFlow.ats | 28 - .../fractureFlow_conforming_2d_vtk_input.xml | 3 +- .../fractureMatrixFlow_conforming_2d.xml | 3 +- .../impermeableFault_conforming_base.xml | 3 +- .../singlePhaseFlowFractures.ats | 86 --- .../singlePhaseWell/singlePhaseWell.ats | 58 -- inputFiles/solidMechanics/SSLE.ats | 19 - inputFiles/solidMechanics/anisotropic.ats | 36 - inputFiles/solidMechanics/beamBending.ats | 38 -- inputFiles/solidMechanics/gravity.ats | 20 - .../solidMechanics/plasticCubeReset.ats | 19 - inputFiles/solidMechanics/plasticWellbore.ats | 34 - inputFiles/solidMechanics/sedov.ats | 27 - inputFiles/solidMechanics/viscoPlastic.ats | 20 - inputFiles/solidMechanics/wellbore.ats | 19 - .../surfaceGeneration/SurfaceGenerator.ats | 46 -- .../thermalMultiphaseFlow.ats | 28 - ...ctureMatrixThermalFlow_conforming_base.xml | 2 +- .../thermalSinglePhaseFlowFractures.ats | 26 - .../thermoPoromechanics.ats | 32 - .../thermoPoromechanicsFractures.ats | 23 - .../wavePropagation/AcousticElasticSEM.ats | 20 - .../wavePropagation/AcousticFirstOrderSEM.ats | 44 -- inputFiles/wavePropagation/AcousticSEM.ats | 58 -- .../wavePropagation/ElasticFirstOrderSEM.ats | 44 -- inputFiles/wavePropagation/ElasticSEM.ats | 42 -- .../wellbore/thermoPoromechanics_wellbore.ats | 18 - inputFiles/wellbore/wellboreMesh.ats | 67 -- integratedTests | 2 +- scripts/ci_build_and_test_in_container.sh | 4 +- scripts/setupPythonEnvironment.bash | 14 +- src/CMakeLists.txt | 91 +-- .../Qk_Hexahedron_Lagrange_GaussLobatto.hpp | 2 +- .../physicsSolvers/CMakeLists.txt | 5 +- .../NonlinearSolverParameters.cpp | 39 -- .../NonlinearSolverParameters.hpp | 13 +- .../physicsSolvers/SolverBase.cpp | 181 ++--- .../physicsSolvers/SolverBase.hpp | 4 - .../contact/LagrangianContactSolver.cpp | 2 - .../SolidMechanicsEmbeddedFractures.cpp | 1 - .../fluidFlow/CompositionalMultiphaseBase.cpp | 122 ++-- .../fluidFlow/CompositionalMultiphaseBase.hpp | 12 +- .../CompositionalMultiphaseStatistics.cpp | 2 +- .../fluidFlow/FlowSolverBase.cpp | 96 +-- .../fluidFlow/FlowSolverBase.hpp | 18 +- .../ReactiveCompositionalMultiphaseOBL.cpp | 2 - .../fluidFlow/SinglePhaseBase.cpp | 39 +- .../fluidFlow/wells/WellSolverBase.cpp | 1 - ...mpositionalMultiphaseReservoirAndWells.hpp | 2 +- .../multiphysics/CoupledSolver.hpp | 63 +- .../multiphysics/HydrofractureSolver.cpp | 8 - .../multiphysics/HydrofractureSolver.hpp | 3 - .../HydrofractureSolverKernels.hpp | 46 +- .../multiphysics/MultiphasePoromechanics.cpp | 4 - .../multiphysics/PoromechanicsSolver.hpp | 3 + .../multiphysics/SinglePhasePoromechanics.cpp | 2 - ...ePhasePoromechanicsConformingFractures.cpp | 1 - ...glePhasePoromechanicsEmbeddedFractures.cpp | 2 - .../SinglePhaseReservoirAndWells.hpp | 2 +- .../simplePDE/PhaseFieldDamageFEM.cpp | 4 - .../simplePDE/PhaseFieldDamageFEM.hpp | 2 - .../SolidMechanicsLagrangianFEM.cpp | 5 - .../SolidMechanicsLagrangianFEM.hpp | 2 - .../AcousticElasticWaveEquationSEM.cpp | 53 +- .../AcousticElasticWaveEquationSEM.hpp | 29 +- .../wavePropagation/AcousticFields.hpp | 203 ------ .../AcousticFirstOrderWaveEquationSEM.cpp | 95 ++- .../AcousticFirstOrderWaveEquationSEM.hpp | 17 +- .../wavePropagation/AcousticVTIFields.hpp | 193 ------ .../AcousticVTIWaveEquationSEM.cpp | 152 ++--- .../AcousticVTIWaveEquationSEM.hpp | 3 +- .../AcousticVTIWaveEquationSEMKernel.hpp | 18 +- .../AcousticWaveEquationSEM.cpp | 202 +++--- .../AcousticWaveEquationSEM.hpp | 143 +++- .../AcousticWaveEquationSEMKernel.hpp | 9 +- .../wavePropagation/AcoustoElasticFields.hpp | 66 -- .../ElasticFirstOrderWaveEquationSEM.cpp | 181 ++--- .../ElasticFirstOrderWaveEquationSEM.hpp | 15 +- ...ElasticFirstOrderWaveEquationSEMKernel.hpp | 2 +- .../ElasticWaveEquationSEM.cpp | 207 +++--- .../ElasticWaveEquationSEM.hpp | 205 +++++- .../ElasticWaveEquationSEMKernel.hpp | 22 +- ...ticFields.hpp => WaveSolverBaseFields.hpp} | 294 +++++--- .../wavePropagation/WaveSolverUtils.hpp | 2 + .../docs/CompositionalMultiphaseFVM.rst | 3 - .../docs/CompositionalMultiphaseHybridFVM.rst | 3 - .../docs/ElasticFirstOrderSEM_other.rst | 6 - .../schema/docs/Hydrofracture.rst | 1 - .../schema/docs/NonlinearSolverParameters.rst | 2 - .../schema/docs/ProppantTransport.rst | 46 +- .../ReactiveCompositionalMultiphaseOBL.rst | 52 +- .../schema/docs/SinglePhaseFVM.rst | 34 +- .../schema/docs/SinglePhaseHybridFVM.rst | 34 +- .../schema/docs/SinglePhaseProppantFVM.rst | 34 +- src/coreComponents/schema/schema.xsd | 41 +- src/coreComponents/schema/schema.xsd.other | 12 - src/coreComponents/unitTests/CMakeLists.txt | 2 +- .../wavePropagationTests/CMakeLists.txt | 1 - .../testWavePropagationAcousticFirstOrder.cpp | 1 + .../testWavePropagationElasticFirstOrder.cpp | 303 --------- .../Contributing/IntegratedTests.rst | 634 +----------------- 138 files changed, 1508 insertions(+), 5034 deletions(-) delete mode 100644 host-configs/Stanford/sherlock-gcc10-ompi4.1.2-openblas0.3.10-cuda11.7.1-sm70.cmake delete mode 100644 inputFiles/compositionalMultiphaseFlow/benchmarks/SPE10/SPE10.ats delete mode 100644 inputFiles/compositionalMultiphaseFlow/benchmarks/buckleyLeverettProblem/buckleyLeverettProblem.ats delete mode 100644 inputFiles/compositionalMultiphaseFlow/benchmarks/isothermalLeakyWell/isothermalLeakyWell.ats delete mode 100644 inputFiles/compositionalMultiphaseFlow/benchmarks/thermalLeakyWell/thermalLeakyWell.ats delete mode 100644 inputFiles/compositionalMultiphaseFlow/c1-ppu/c1_ppu.ats delete mode 100644 inputFiles/compositionalMultiphaseFlow/compositionalMultiphaseFlow.ats delete mode 100644 inputFiles/compositionalMultiphaseWell/benchmarks/Class09Pb3/Class09Pb3.ats delete mode 100644 inputFiles/compositionalMultiphaseWell/benchmarks/Egg/compositionalMultiphaseWell_Egg.ats delete mode 100644 inputFiles/compositionalMultiphaseWell/compositionalMultiphaseWell.ats delete mode 100644 inputFiles/efemFractureMechanics/efemFractureMechanics.ats delete mode 100644 inputFiles/hydraulicFracturing/Hydrofracturing.ats delete mode 100644 inputFiles/lagrangianContactMechanics/contactMechanics.ats delete mode 100644 inputFiles/main.ats delete mode 100644 inputFiles/materialPointMethod/dfgMovingGrid/solidMechanicsMPM_dfgMovingGrid.ats delete mode 100644 inputFiles/materialPointMethod/particleRepartition/solidMechanicsMPM_particleRepartition.ats delete mode 100644 inputFiles/materialPointMethod/singleParticle/solidMechanicsMPM_singleParticle.ats delete mode 100644 inputFiles/multiphaseFlowFractures/multiphaseFlowFractures.ats delete mode 100644 inputFiles/phaseField/PhaseFieldFracture.ats delete mode 100644 inputFiles/poromechanics/nonlinearAcceleration/validationCase/poroelasticCoupling_validation.ats delete mode 100644 inputFiles/poromechanics/poroElasticCoupling.ats delete mode 100644 inputFiles/poromechanics/viscoPlastic.ats delete mode 100644 inputFiles/poromechanicsFractures/poromechanicsFractures.ats delete mode 100644 inputFiles/proppant/proppantTransport.ats delete mode 100644 inputFiles/simplePDE/SimpleSolvers.ats delete mode 100644 inputFiles/singlePhaseFlow/singlePhaseFlow.ats delete mode 100644 inputFiles/singlePhaseFlow/thermalSinglePhaseFlow.ats delete mode 100644 inputFiles/singlePhaseFlowFractures/singlePhaseFlowFractures.ats delete mode 100644 inputFiles/singlePhaseWell/singlePhaseWell.ats delete mode 100644 inputFiles/solidMechanics/SSLE.ats delete mode 100644 inputFiles/solidMechanics/anisotropic.ats delete mode 100644 inputFiles/solidMechanics/beamBending.ats delete mode 100644 inputFiles/solidMechanics/gravity.ats delete mode 100644 inputFiles/solidMechanics/plasticCubeReset.ats delete mode 100644 inputFiles/solidMechanics/plasticWellbore.ats delete mode 100644 inputFiles/solidMechanics/sedov.ats delete mode 100644 inputFiles/solidMechanics/viscoPlastic.ats delete mode 100644 inputFiles/solidMechanics/wellbore.ats delete mode 100644 inputFiles/surfaceGeneration/SurfaceGenerator.ats delete mode 100644 inputFiles/thermalMultiphaseFlow/thermalMultiphaseFlow.ats delete mode 100644 inputFiles/thermalSinglePhaseFlowFractures/thermalSinglePhaseFlowFractures.ats delete mode 100644 inputFiles/thermoPoromechanics/thermoPoromechanics.ats delete mode 100644 inputFiles/thermoPoromechanicsFractures/thermoPoromechanicsFractures.ats delete mode 100644 inputFiles/wavePropagation/AcousticElasticSEM.ats delete mode 100644 inputFiles/wavePropagation/AcousticFirstOrderSEM.ats delete mode 100644 inputFiles/wavePropagation/AcousticSEM.ats delete mode 100644 inputFiles/wavePropagation/ElasticFirstOrderSEM.ats delete mode 100644 inputFiles/wavePropagation/ElasticSEM.ats delete mode 100644 inputFiles/wellbore/thermoPoromechanics_wellbore.ats delete mode 100644 inputFiles/wellbore/wellboreMesh.ats delete mode 100644 src/coreComponents/physicsSolvers/wavePropagation/AcousticFields.hpp delete mode 100644 src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIFields.hpp delete mode 100644 src/coreComponents/physicsSolvers/wavePropagation/AcoustoElasticFields.hpp rename src/coreComponents/physicsSolvers/wavePropagation/{ElasticFields.hpp => WaveSolverBaseFields.hpp} (53%) delete mode 100644 src/coreComponents/unitTests/wavePropagationTests/testWavePropagationElasticFirstOrder.cpp diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7729845a464..68b2774c020 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ "build": { "dockerfile": "Dockerfile", "args": { - "GEOS_TPL_TAG": "256-147" + "GEOS_TPL_TAG": "254-134" } }, "runArgs": [ diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 46b45151698..ad4913ba5c6 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -167,8 +167,8 @@ jobs: DOCKER_REPOSITORY: geosx/sherlock-gcc10.1.0-openmpi4.1.2-openblas0.3.10-zlib1.2.11 ENABLE_HYPRE: ON ENABLE_TRILINOS: OFF - GCP_BUCKET: geosx/Sherlock-CPU HOST_CONFIG: host-configs/Stanford/sherlock-gcc10-ompi4.1.2-openblas0.3.10.cmake + GCP_BUCKET: geosx/Sherlock-CPU uses: ./.github/workflows/build_and_test.yml with: @@ -263,18 +263,6 @@ jobs: DOCKER_REPOSITORY: geosx/pecan-gpu-gcc8.2.0-openmpi4.0.1-mkl2019.5-cuda11.5.119 HOST_CONFIG: host-configs/TOTAL/pecan-GPU.cmake RUNS_ON: Runner_4core_16GB - - - name: Sherlock GPU (centos 7.9.2009, gcc 10.1.0, open-mpi 4.1.2, openblas 0.3.10, cuda 11.7.1,) - BUILD_AND_TEST_CLI_ARGS: "--no-run-unit-tests --no-install-schema" - CMAKE_BUILD_TYPE: Release - DOCKER_REPOSITORY: geosx/sherlock-gcc10.1.0-openmpi4.1.2-cuda11.7.1-openblas0.3.10-zlib1.2.11 - ENABLE_HYPRE_DEVICE: CUDA - ENABLE_HYPRE: ON - ENABLE_TRILINOS: OFF - GCP_BUCKET: geosx/Sherlock-GPU - HOST_CONFIG: host-configs/Stanford/sherlock-gcc10-ompi4.1.2-openblas0.3.10-cuda11.7.1-sm70.cmake - RUNS_ON: Runner_4core_16GB - uses: ./.github/workflows/build_and_test.yml with: BUILD_AND_TEST_CLI_ARGS: ${{ matrix.BUILD_AND_TEST_CLI_ARGS }} @@ -285,7 +273,6 @@ jobs: ENABLE_HYPRE_DEVICE: ${{ matrix.ENABLE_HYPRE_DEVICE }} ENABLE_HYPRE: ${{ matrix.ENABLE_HYPRE }} ENABLE_TRILINOS: ${{ matrix.ENABLE_TRILINOS }} - GCP_BUCKET: ${{ matrix.GCP_BUCKET }} HOST_CONFIG: ${{ matrix.HOST_CONFIG }} RUNS_ON: ${{ matrix.RUNS_ON }} secrets: inherit diff --git a/host-configs/LLNL/quartz-base.cmake b/host-configs/LLNL/quartz-base.cmake index 38047f8e0ce..f5ff404044c 100644 --- a/host-configs/LLNL/quartz-base.cmake +++ b/host-configs/LLNL/quartz-base.cmake @@ -58,12 +58,5 @@ set(MKL_LIBRARIES ${MKL_ROOT}/lib/intel64/libmkl_intel_lp64.so # ATS set(ATS_ARGUMENTS "--machine slurm36" CACHE STRING "") -# set(USER $ENV{USER} CACHE STRING "") -# set(ATS_WORKING_DIR "/p/lustre2/${USER}/integratedTests/${CONFIG_NAME}" CACHE PATH "") -# set(ATS_BASELINE_DIR "/p/lustre2/${USER}/integratedTests/baselines" CACHE PATH "") - -# Temporary argument for python module change testing -# set(GEOS_PYTHON_PACKAGES_BRANCH "feature/sherman/outOfPlaceATS" CACHE STRING "" FORCE) - include(${CMAKE_CURRENT_LIST_DIR}/../tpls.cmake) diff --git a/host-configs/Stanford/sherlock-gcc10-ompi4.1.2-openblas0.3.10-cuda11.7.1-sm70.cmake b/host-configs/Stanford/sherlock-gcc10-ompi4.1.2-openblas0.3.10-cuda11.7.1-sm70.cmake deleted file mode 100644 index 51031871d6b..00000000000 --- a/host-configs/Stanford/sherlock-gcc10-ompi4.1.2-openblas0.3.10-cuda11.7.1-sm70.cmake +++ /dev/null @@ -1,28 +0,0 @@ -include(${CMAKE_CURRENT_LIST_DIR}/sherlock-gcc10-ompi4.1.2-openblas0.3.10.cmake) - -# OpenMP options -set(ENABLE_OPENMP OFF CACHE BOOL "" FORCE) - -# CUDA options -set(ENABLE_CUDA ON CACHE BOOL "" FORCE) -set(CUDA_VERSION "11.7.1" CACHE PATH "") -set(CUDA_HOME "${SOFTWARE_ROOT}/cuda/${CUDA_VERSION}" CACHE PATH "") -set(CMAKE_CUDA_ARCHITECTURES "70" CACHE STRING "") -set(CUDA_ARCH "sm_${CMAKE_CUDA_ARCHITECTURES}" CACHE STRING "") -set(CUDA_TOOLKIT_ROOT_DIR "${CUDA_HOME}" CACHE STRING "") - -set(CONFIG_NAME "sherlock-gcc10-ompi4.1.2-openblas0.3.10-cuda${CUDA_VERSION}-${CUDA_ARCH}" CACHE PATH "" FORCE) - -set(CMAKE_CUDA_HOST_COMPILER ${MPI_CXX_COMPILER} CACHE STRING "") -set(CMAKE_CUDA_COMPILER ${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc CACHE STRING "") -set(CMAKE_CUDA_FLAGS "-restrict -arch ${CUDA_ARCH} --expt-extended-lambda --expt-relaxed-constexpr -Werror cross-execution-space-call,reorder,deprecated-declarations " CACHE STRING "") -set(CMAKE_CUDA_FLAGS_RELEASE "-O3 -DNDEBUG -Xcompiler -DNDEBUG -Xcompiler -O3" CACHE STRING "") -set(CMAKE_CUDA_FLAGS_RELWITHDEBINFO "-g -lineinfo ${CMAKE_CUDA_FLAGS_RELEASE}" CACHE STRING "") -set(CMAKE_CUDA_FLAGS_DEBUG "-g -G -O0 -Xcompiler -O0" CACHE STRING "") - -# LAI options -set(GEOSX_LA_INTERFACE "Hypre" CACHE STRING "" FORCE) -set(ENABLE_HYPRE ON CACHE BOOL "" FORCE) -set(ENABLE_HYPRE_DEVICE "CUDA" CACHE STRING "" FORCE) -set(ENABLE_PETSC OFF CACHE BOOL "" FORCE) -set(ENABLE_TRILINOS OFF CACHE BOOL "" FORCE) diff --git a/host-configs/Stanford/sherlock-modules.sh b/host-configs/Stanford/sherlock-modules.sh index 316116271e2..3bdbe8257c5 100755 --- a/host-configs/Stanford/sherlock-modules.sh +++ b/host-configs/Stanford/sherlock-modules.sh @@ -1,12 +1,11 @@ module load system -module load git -module load git-lfs -module load cmake +module load git/2.12.2 +module load git-lfs/2.4.0 +module load cmake/3.20.3 +module load ninja/1.9.0 +module load py-mpi4py/3.0.3_py36 +module load py-h5py/2.10.0_py36 module load gcc/10.1.0 -module load openmpi/4.1.2 -module load openblas/0.3.10 +module load openmpi/4.1.0 +module load cuda/11.2.0 module load libevent/2.1.12 # needed for silo -module load py-mpi4py/3.1.3_py39 -module load py-h5py/3.7.0_py39 -module unload cuda -module load cuda/11.7.1 diff --git a/inputFiles/compositionalMultiphaseFlow/benchmarks/SPE10/SPE10.ats b/inputFiles/compositionalMultiphaseFlow/benchmarks/SPE10/SPE10.ats deleted file mode 100644 index 3d37c8e5c7b..00000000000 --- a/inputFiles/compositionalMultiphaseFlow/benchmarks/SPE10/SPE10.ats +++ /dev/null @@ -1,19 +0,0 @@ -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-6 -restartcheck_params["rtol"] = 1.0E-5 - -decks = [ - TestDeck( - name="deadOilSpe10Layers84_85_smoke_2d", - description= - "Smoke test for SPE10 (2D displacement, 2-phase dead-oil, Brooks-Corey pairwise 2-phase relperm curves)", - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=49, - check_step=89, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), -] - -generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseFlow/benchmarks/buckleyLeverettProblem/buckleyLeverettProblem.ats b/inputFiles/compositionalMultiphaseFlow/benchmarks/buckleyLeverettProblem/buckleyLeverettProblem.ats deleted file mode 100644 index 30944577aa4..00000000000 --- a/inputFiles/compositionalMultiphaseFlow/benchmarks/buckleyLeverettProblem/buckleyLeverettProblem.ats +++ /dev/null @@ -1,19 +0,0 @@ -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-6 -restartcheck_params["rtol"] = 1.0E-5 - -decks = [ - TestDeck( - name="buckleyLeverett_smoke", - description= - "Smoke test for a CO2 core flood experiment (1D displacement, 2-phase dead-oil, Brooks-Corey pairwise 2-phase relperm curves)", - partitions=((1, 1, 1), (2, 1, 1)), - restart_step=9, - check_step=13, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseFlow/benchmarks/isothermalLeakyWell/isothermalLeakyWell.ats b/inputFiles/compositionalMultiphaseFlow/benchmarks/isothermalLeakyWell/isothermalLeakyWell.ats deleted file mode 100644 index acc7382aa8f..00000000000 --- a/inputFiles/compositionalMultiphaseFlow/benchmarks/isothermalLeakyWell/isothermalLeakyWell.ats +++ /dev/null @@ -1,19 +0,0 @@ -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-6 -restartcheck_params["rtol"] = 1.0E-5 - -decks = [ - TestDeck( - name="isothermalLeakyWell_smoke_3d", - description= - "Smoke test for isothermalLeakyWell (3D displacement, 2-phase dead-oil, hydrostatic initial condition)", - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=60, - check_step=104, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), -] - -generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseFlow/benchmarks/thermalLeakyWell/thermalLeakyWell.ats b/inputFiles/compositionalMultiphaseFlow/benchmarks/thermalLeakyWell/thermalLeakyWell.ats deleted file mode 100644 index f0a149ff298..00000000000 --- a/inputFiles/compositionalMultiphaseFlow/benchmarks/thermalLeakyWell/thermalLeakyWell.ats +++ /dev/null @@ -1,19 +0,0 @@ -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-6 -restartcheck_params["rtol"] = 1.0E-5 - -decks = [ - TestDeck( - name="thermalLeakyWell_smoke_3d", - description= - "Smoke test for thermalLeakyWell (3D displacement, 2-phase co2-brine, hydrostatic initial condition)", - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=60, - check_step=104, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), -] - -generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseFlow/c1-ppu/c1_ppu.ats b/inputFiles/compositionalMultiphaseFlow/c1-ppu/c1_ppu.ats deleted file mode 100644 index 52d47c61ff4..00000000000 --- a/inputFiles/compositionalMultiphaseFlow/c1-ppu/c1_ppu.ats +++ /dev/null @@ -1,17 +0,0 @@ -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-6 -restartcheck_params["rtol"] = 1.0E-5 - -decks = [ - TestDeck(name="grav_seg_c1ppu_hyst", - description="Smoke test for C1-PPU (1D displacement, C1-PPU)", - partitions=((1, 1, 1), (1, 1, 2)), - restart_step=87, - check_step=109, - restartcheck_params=RestartcheckParameters(atol=1e-4, rtol=1e-3)), -] - -generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseFlow/compositionalMultiphaseFlow.ats b/inputFiles/compositionalMultiphaseFlow/compositionalMultiphaseFlow.ats deleted file mode 100644 index a0072bc2653..00000000000 --- a/inputFiles/compositionalMultiphaseFlow/compositionalMultiphaseFlow.ats +++ /dev/null @@ -1,91 +0,0 @@ -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-6 -restartcheck_params["rtol"] = 1.0E-5 - -decks = [ - TestDeck( - name="4comp_2ph_1d", - description= - "Compositional multiphase flow test (1D displacement, 2-phase 4-component)", - partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), - restart_step=6, - check_step=11, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="4comp_2ph_cap_1d", - description= - "Compositional multiphase flow test (1D displacement, 2-phase 4-component, capillary pressure)", - partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), - restart_step=118, - check_step=218, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="deadoil_3ph_corey_1d", - description= - "Compositional multiphase flow test (1D displacement, 3-phase dead-oil, Brooks-Corey pairwise 2-phase relperm curves)", - partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), - restart_step=109, - check_step=209, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="co2_hybrid_1d", - description= - "Compositional co2-brine flow test (1D displacement, hybrid FVM, Brooks-Corey pairwise 2-phase relperm curves)", - partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), - restart_step=5, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="deadoil_3ph_baker_1d", - description= - "Compositional multiphase flow test (1D displacement, 3-phase dead-oil, Brooks-Corey-Baker 3-phase relperm curves)", - partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), - restart_step=109, - check_step=209, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="deadoil_3ph_staircase_3d", - description= - "Compositional multiphase flow test (3D staircase, 3-phase dead-oil, Brooks-Corey-Baker 3-phase relperm curves)", - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=28, - check_step=38, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="deadoil_3ph_staircase_hybrid_3d", - description= - "Compositional multiphase flow test (3D staircase, hybrid FVM, 3-phase dead-oil, Brooks-Corey-Baker 3-phase relperm curves)", - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=28, - check_step=38, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="deadoil_2ph_staircase_gravity_segregation_3d", - description= - "Compositional multiphase flow test (3D staircase, no-flow BC, 2-phase dead-oil, hysteresis)", - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=61, - check_step=121, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="co2_flux_3d", - description= - "Compositional co2-brine flow test (3D co2 injection, 2-phase co2-brine, Brooks-Corey 2-phase relperm curves)", - partitions=((1, 1, 1), (2, 2, 2), (3, 3, 3)), - restart_step=10, - check_step=20, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="deadoil_3ph_staircase_obl_3d", - description= - "Smoke test for a staircase deadoil test (3D displacement, 3-phase dead-oil, OBL)", - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=28, - check_step=38, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), -] - -generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseWell/benchmarks/Class09Pb3/Class09Pb3.ats b/inputFiles/compositionalMultiphaseWell/benchmarks/Class09Pb3/Class09Pb3.ats deleted file mode 100644 index f860f8651da..00000000000 --- a/inputFiles/compositionalMultiphaseWell/benchmarks/Class09Pb3/Class09Pb3.ats +++ /dev/null @@ -1,24 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-6 -restartcheck_params["rtol"] = 1.0E-5 - -# exclude any derivative fields from restart checks -# example field name: dGlobalComponentFraction_dPressure -#restartcheck_params["exclude"] = [r"d[A-Z]\w+_d[A-Z]\w+"] - -decks = [ - TestDeck( - name="class09_pb3_smoke_3d", - description= - "Smoke test for the Johansen model (3D displacement, structured mesh, CO2-brine)", - partitions=[(1, 1, 1), (2, 2, 2)], - restart_step=5, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), -] - -generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseWell/benchmarks/Egg/compositionalMultiphaseWell_Egg.ats b/inputFiles/compositionalMultiphaseWell/benchmarks/Egg/compositionalMultiphaseWell_Egg.ats deleted file mode 100644 index 065b75a6645..00000000000 --- a/inputFiles/compositionalMultiphaseWell/benchmarks/Egg/compositionalMultiphaseWell_Egg.ats +++ /dev/null @@ -1,26 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-6 -restartcheck_params["rtol"] = 1.0E-5 - -# exclude any derivative fields from restart checks -# example field name: dGlobalComponentFraction_dPressure -#restartcheck_params["exclude"] = [r"d[A-Z]\w+_d[A-Z]\w+"] - -decks = [ - TestDeck( - name="deadOilEgg_smoke_3d", - description= - "Smoke test for the Egg model (3D displacement, structured mesh, 2-phase dead-oil, many wells)", - partitions=[ - (1, 1, 1), - ], - restart_step=20, - check_step=35, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), -] - -generate_geos_tests(decks) diff --git a/inputFiles/compositionalMultiphaseWell/compositionalMultiphaseWell.ats b/inputFiles/compositionalMultiphaseWell/compositionalMultiphaseWell.ats deleted file mode 100644 index 6cfaf320a36..00000000000 --- a/inputFiles/compositionalMultiphaseWell/compositionalMultiphaseWell.ats +++ /dev/null @@ -1,88 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-6 -restartcheck_params["rtol"] = 1.0E-5 - -# exclude any derivative fields from restart checks -# example field name: dGlobalComponentFraction_dPressure -#restartcheck_params["exclude"] = [r"d[A-Z]\w+_d[A-Z]\w+"] - -decks = [ - TestDeck( - name="compositional_multiphase_wells_1d", - description= - "Compositional multiphase well test (1D displacement, 2-phase 4-component, 2 wells)", - partitions=[(1, 1, 1), (2, 1, 1)], - restart_step=5, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="compositional_multiphase_wells_2d", - description= - "Compositional multiphase flow test (2D displacement, 2-phase 4-component, 3 wells)", - partitions=[(1, 1, 1), (2, 2, 1)], - restart_step=3, - check_step=7, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="dead_oil_wells_2d", - description= - "Dead oil well test (2D displacement, 3-phase dead-oil, 3 wells)", - partitions=[(1, 1, 1), (2, 2, 1)], - restart_step=50, - check_step=100, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="dead_oil_wells_hybrid_2d", - description= - "Dead oil well test (2D displacement, hybrid FVM, 3-phase dead-oil, 3 wells)", - partitions=[(1, 1, 1), (2, 2, 1)], - restart_step=50, - check_step=100, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="black_oil_wells_saturated_3d", - description= - "Black oil well test (3D displacement, 3-phase black-oil, 2 wells)", - partitions=[(1, 1, 1), (2, 2, 1)], - restart_step=13, - check_step=25, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="black_oil_wells_unsaturated_3d", - description= - "Black oil well test (3D displacement, hybrid FVM, 3-phase black-oil, 2 wells)", - partitions=[(1, 1, 1), (2, 2, 1)], - restart_step=8, - check_step=12, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="staircase_co2_wells_3d", - description= - "CO2 well test (3D staircase, 2-phase 2-component, 2 wells)", - partitions=[(1, 1, 1), (2, 2, 2)], - restart_step=3, - check_step=5, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="staircase_co2_wells_hybrid_3d", - description= - "CO2 well test (3D staircase, unstructured mesh, hybrid FVM, 2-phase 2-component, 2 wells)", - partitions=[(1, 1, 1), (2, 2, 2)], - restart_step=0, - check_step=17, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="black_oil_wells_saturated_3d_stone2", - description= - "Black oil well test using stone2 interp (3D displacement, hybrid FVM, 3-phase black-oil, 2 wells)", - partitions=[(1, 1, 1), (2, 2, 1)], - restart_step=12, - check_step=25, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/efemFractureMechanics/efemFractureMechanics.ats b/inputFiles/efemFractureMechanics/efemFractureMechanics.ats deleted file mode 100644 index 8242a30cc6c..00000000000 --- a/inputFiles/efemFractureMechanics/efemFractureMechanics.ats +++ /dev/null @@ -1,68 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, CurveCheckParameters, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {'atol': 1e-08, 'rtol': 4e-07} - -curvecheck_params = {} -curvecheck_params["filename"] = "displacementJump_embeddedFrac.hdf5" -curvecheck_params["tolerance"] = [1e-5] -curvecheck_params["script_instructions"] = [[ - "./scripts/sneddonCurveChecks.py", "sneddon_curve_check_solution", - "displacementJump" -]] -curvecheck_params["curves"] = "displacementJump" - -decks = [ - TestDeck( - name="Sneddon_embeddedFrac_smoke", - description="Smoke test for Sneddon's problem with horizontal fracture", - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="Sneddon_embeddedFrac_benchmark", - description="Sneddon's problem with horizontal fracture (uses MGR)", - partitions=((1, 1, 1), ), - restart_step=0, - check_step=1, - curvecheck_params=CurveCheckParameters(**curvecheck_params)), - TestDeck( - name="Sneddon_embeddedFrac_staticCondensation_smoke", - description="Sneddon with horizontal fracture usic static condensation", - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="Sneddon_embeddedFrac_staticCondensation_benchmark", - description="Sneddon with horizontal fracture usic static condensation", - partitions=((1, 1, 1), ), - restart_step=0, - check_step=1, - curvecheck_params=CurveCheckParameters(**curvecheck_params)), - TestDeck( - name="SneddonRotated_smoke", - description='Sneddon with inclined fracture', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="EmbFrac_Compression_Frictionless_smoke", - description='Single efem fracture under compression - frictionless', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(atol= 1e-06, rtol= 4e-07)), - TestDeck( - name="EmbFrac_Compression_CoulombFriction_smoke", - description='Single efem fracture under compression - Coulomb friction', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(atol= 1e-06, rtol= 4e-07)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/hydraulicFracturing/Hydrofracturing.ats b/inputFiles/hydraulicFracturing/Hydrofracturing.ats deleted file mode 100644 index ab32dc09f55..00000000000 --- a/inputFiles/hydraulicFracturing/Hydrofracturing.ats +++ /dev/null @@ -1,203 +0,0 @@ -import copy -import geos_ats -from geos_ats.test_builder import generate_geos_tests, RestartcheckParameters, CurveCheckParameters, TestDeck - -# Define cases -kgd_viscosity_dominated = { - "name": "kgdViscosityDominated_smoke", - "description": "KGD fracture in viscosity-dominated regime", - "partitions": ((1, 1, 1), (2, 3, 1)), - "restart_step": 0, - "check_step": 1, - "tolerance": [2.3e-5, 27000.0], - "aperture_curve_method": "kgd_viscosity_dominated_aperture_curve", - "pressure_curve_method": "kgd_viscosity_dominated_pressure_curve" -} - -kgd_viscosity_dominated_poroelastic = { - "name": "kgdViscosityDominated_poroelastic_smoke", - "description": - "KGD fracture in viscosity-dominated regime in a poroelastic solid", - "partitions": ((1, 1, 1), (2, 3, 1)), - "restart_step": 0, - "check_step": 1 -} - -kgd_toughness_dominated = { - "name": "kgdToughnessDominated_smoke", - "description": "KGD fracture in toughness-dominated regime", - "partitions": ((1, 1, 1), (2, 3, 1)), - "restart_step": 0, - "check_step": 1, - "tolerance": [1e-5, 21000.0], - "aperture_curve_method": "kgd_toughness_dominated_aperture_curve", - "pressure_curve_method": "kgd_toughness_dominated_pressure_curve" -} - -kgd_toughness_dominated_poroelastic = { - "name": "kgdToughnessDominated_poroelastic_smoke", - "description": - "KGD fracture in toughness-dominated regime in a poroelastic solid", - "partitions": ((1, 1, 1), (2, 3, 1)), - "restart_step": 0, - "check_step": 1 -} - -kgd_validation = { - "name": "kgdValidation_smoke", - "description": "Validation example based on Rubin's experiment", - "partitions": ((1, 1, 1), (2, 2, 1)), - "restart_step": 0, - "check_step": 1 -} - -kgd_node_based_C3D6 = { - "name": "kgdNodeBased_C3D6_smoke", - "description": - "KGD hydrofracturing (node-based) problem with C3D6 element type", - "partitions": ((1, 1, 1), (3, 3, 1)), - "restart_step": 0, - "check_step": 1 -} - -kgd_edge_based_C3D6 = { - "name": "kgdEdgeBased_C3D6_smoke", - "description": - "KGD hydrofracturing (edge-based) problem with C3D6 element type", - "partitions": ((1, 1, 1), (3, 3, 1)), - "restart_step": 0, - "check_step": 1 -} - -heterogeneous_fracture = { - "name": "heterogeneousInSitu_smoke", - "description": "Single fracture within a heterogeneous reservoir", - "partitions": ((1, 1, 1), (2, 2, 1)), - "restart_step": 0, - "check_step": 4 -} - -penny_shaped_toughness_dominated = { - "name": "pennyShapedToughnessDominated_smoke", - "description": "Penny Shaped fracture in Toughness-dominated regime", - "partitions": ((1, 1, 1), (1, 3, 2)), - "restart_step": 0, - "check_step": 5, - "tolerance": [3.4e-6, 1e5], - "aperture_curve_method": "penny_shaped_toughness_dominated_aperture_curve", - "pressure_curve_method": "penny_shaped_toughness_dominated_pressure_curve" -} - -penny_shaped_toughness_dominated_poroelastic = { - "name": "pennyShapedToughnessDominated_poroelastic_smoke", - "description": - "Penny Shaped fracture in Toughness-dominated regime in a poroelastic solid", - "partitions": ((1, 1, 1), (1, 3, 2)), - "restart_step": 0, - "check_step": 5 -} - -penny_shaped_viscosity_dominated = { - "name": "pennyShapedViscosityDominated_smoke", - "description": "Penny Shaped fracture in Viscosity-dominated regime", - "partitions": ((1, 1, 1), (1, 2, 2)), - "restart_step": 0, - "check_step": 5, - "tolerance": [2.7e-3, 3e6], - "aperture_curve_method": "penny_shaped_viscosity_dominated_aperture_curve", - "pressure_curve_method": "penny_shaped_viscosity_dominated_pressure_curve" -} - -penny_shaped_viscosity_dominated_poroelastic = { - "name": "pennyShapedViscosityDominated_poroelastic_smoke", - "description": - "Penny Shaped fracture in Viscosity-dominated regime in a poroelastic solid", - "partitions": ((1, 1, 1), (1, 3, 2)), - "restart_step": 0, - "check_step": 5 -} - -pkn_viscosity_dominated = { - "name": "pknViscosityDominated_smoke", - "description": "PKN fracture in Viscosity-dominated regime", - "partitions": ((1, 1, 1), (1, 2, 2)), - "restart_step": 0, - "check_step": 5, - "tolerance": [1.8e-5, 2e5], - "aperture_curve_method": "pkn_viscosity_dominated_aperture_curve", - "pressure_curve_method": "pkn_viscosity_dominated_pressure_curve" -} - -pkn_viscosity_dominated_poroelastic = { - "name": "pknViscosityDominated_poroelastic_smoke", - "description": - "PKN fracture in Viscosity-dominated regime in a poroelastic solid", - "partitions": ((1, 1, 1), (1, 2, 2)), - "restart_step": 0, - "check_step": 5 -} - -sneddon = { - "name": "Sneddon_hydroFrac_smoke", - "description": "Sneddon type problem using a conforming discretization", - "partitions": ((1, 1, 1), (2, 2, 1)), - "restart_step": 1, - "check_step": 5 -} - -walsh_quarter_no_chombo = { - "name": "walshQuarterNoChombo_smoke", - "description": "Sneddon type problem using a conforming discretization", - "partitions": ((1, 1, 1), (2, 2, 2)), - "restart_step": 5, - "check_step": 5 -} - -decks = (kgd_viscosity_dominated, kgd_viscosity_dominated_poroelastic, - kgd_toughness_dominated, kgd_toughness_dominated_poroelastic, - kgd_validation, kgd_edge_based_C3D6, kgd_node_based_C3D6, - heterogeneous_fracture, penny_shaped_toughness_dominated, - penny_shaped_toughness_dominated_poroelastic, - penny_shaped_viscosity_dominated, - penny_shaped_viscosity_dominated_poroelastic, pkn_viscosity_dominated, - pkn_viscosity_dominated_poroelastic, sneddon, walsh_quarter_no_chombo) - -# Check parameters -restartcheck_params = RestartcheckParameters(atol=2.0E-4, rtol=1.0E-7) - -curvecheck_params_base = {} -curvecheck_params_base["filename"] = "hydrofracture_source_curves.hdf5" -curvecheck_params_base["tolerance"] = [1e-10, 1e-10] -curvecheck_params_base["script_instructions"] = [[ - "./scripts/hydrofractureCurveChecks.py", "tbd", "hydraulicAperture", - "source" -], ["./scripts/hydrofractureCurveChecks.py", "tbd", "pressure", "source"]] -curvecheck_params_base["curves"] = [["hydraulicAperture", "source"], - ["pressure", "source"]] - -deck_instances = [] -for deck in decks: - if ("aperture_curve_method" in deck) and ("pressure_curve_method" in deck): - curvecheck_params = copy.deepcopy(curvecheck_params_base) - curvecheck_params["script_instructions"][0][1] = deck[ - "aperture_curve_method"] - curvecheck_params["script_instructions"][1][1] = deck[ - "pressure_curve_method"] - - if ("tolerance" in deck): - curvecheck_params["tolerance"] = deck["tolerance"] - curvecheck_params = CurveCheckParameters(**curvecheck_params) - else: - curvecheck_params = None - - deck_instance = TestDeck(name=deck["name"], - description=deck["description"], - partitions=deck["partitions"], - restart_step=deck["restart_step"], - check_step=deck["check_step"], - restartcheck_params=restartcheck_params, - curvecheck_params=curvecheck_params) - - deck_instances.append(deck_instance) - -generate_geos_tests(deck_instances) diff --git a/inputFiles/hydraulicFracturing/hydrofractureSinglePhase2d.xml b/inputFiles/hydraulicFracturing/hydrofractureSinglePhase2d.xml index 4b935534255..ad68c034e65 100644 --- a/inputFiles/hydraulicFracturing/hydrofractureSinglePhase2d.xml +++ b/inputFiles/hydraulicFracturing/hydrofractureSinglePhase2d.xml @@ -5,7 +5,6 @@ gravityVector="{ 0.0, 0.0, 0.0 }"> diff --git a/inputFiles/hydraulicFracturing/kgdToughnessDominated_base.xml b/inputFiles/hydraulicFracturing/kgdToughnessDominated_base.xml index 686921aa1f3..f246ebf15ea 100644 --- a/inputFiles/hydraulicFracturing/kgdToughnessDominated_base.xml +++ b/inputFiles/hydraulicFracturing/kgdToughnessDominated_base.xml @@ -9,11 +9,10 @@ solidSolverName="lagsolve" flowSolverName="SinglePhaseFlow" surfaceGeneratorName="SurfaceGen" - logLevel="1" + logLevel="1" targetRegions="{ Fracture }" contactRelationName="fractureContact" - maxNumResolves="2" - useQuasiNewton="1"> + maxNumResolves="2"> - \ No newline at end of file + diff --git a/inputFiles/poromechanics/nonlinearAcceleration/validationCase/poroelasticCoupling_validation.ats b/inputFiles/poromechanics/nonlinearAcceleration/validationCase/poroelasticCoupling_validation.ats deleted file mode 100644 index ae39bd6c1d7..00000000000 --- a/inputFiles/poromechanics/nonlinearAcceleration/validationCase/poroelasticCoupling_validation.ats +++ /dev/null @@ -1,91 +0,0 @@ -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - - -class Description(object): - - def __init__(self, description_builder, label, owner, isIndependent): - """ - The ATS description of the test case for poro-elastic coupling. - - description_builder: callable - A callable taking the partition tuple in argument and returning the TestCase description. - label: str - The label of the TestCase - owner: str - The owner of the TestCase - isIndependent: boolean - Is the TestCase independent from other cases? - """ - self.description_builder = description_builder - self.label = label - self.owner = owner - self.isIndependent = isIndependent - - -def _n_ranks(partition): - """ - Returns the number of ranks for a given MPI partitioning. - - partition: iterable - The MPI cartesian partitioning. - (x, y, z) ranks are supposed to be integers (or None which will be considered as 1). - """ - result = 1 - # I wanted to do `filter( None, partition )` with the `filter` builtin function - # but it has been rewritten by ATS. This is sooo wrong :( - for n in partition: - result *= n if n else 1 - return result - - -def _build_poro_elastic_coupling_case(deck, cycles, partitions, description, - restartcheck_params): - """ - Generic function that build the poro-elastic cases. - A first run is done and a second takes an intermediate timestep to validate the restart. - - deck: str - XML input file - cycles: pair of integers - The (intermediate_cycle, last_cycle). First being the restart initial timestep. - The second being the last simulated cycle. - partitions: Iterable of length-3 iterables - The (x, y, z) parallel partitioning. - `None` can be provided when nothing has to be done in the considered direction. - description: Description - Description of the TestCase - restartcheck_params: dict - Restart validation parameters (relative or absolute tolerance mainly). - test_name_builder: callable - A callable taking the partition tuple in argument and returning the test name. - """ - - # The simulation will generate data for two cycles - intermediate_cycle, last_cycle = cycles - - return TestDeck( - name=deck.split(".")[0], - description=description.description_builder, - partitions=partitions, - restart_step=intermediate_cycle, - check_step=last_cycle, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) - - -def _build_NonlinearAccelerationValidation_cases(): - description = Description("Nonlinear acceleration validation problem ", - "auto", "Sohail Waziri", True) - restartcheck_params = {"atol": 1.0e-4, "rtol": 2.0e-6} - return _build_poro_elastic_coupling_case("validationCase.xml", (3, 6), - ((1, 1, 1), ), description, - restartcheck_params) - - -def test_poro_elastic_coupling_cases(): - deck_instances = [_build_NonlinearAccelerationValidation_cases()] - - generate_geos_tests(deck_instances) - - -test_poro_elastic_coupling_cases() diff --git a/inputFiles/poromechanics/poroElasticCoupling.ats b/inputFiles/poromechanics/poroElasticCoupling.ats deleted file mode 100644 index 6f3bf4afe32..00000000000 --- a/inputFiles/poromechanics/poroElasticCoupling.ats +++ /dev/null @@ -1,281 +0,0 @@ -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - - -class Description(object): - - def __init__(self, description_builder, label, owner, isIndependent): - """ - The ATS description of the test case for poro-elastic coupling. - - description_builder: callable - A callable taking the partition tuple in argument and returning the TestCase description. - label: str - The label of the TestCase - owner: str - The owner of the TestCase - isIndependent: boolean - Is the TestCase independent from other cases? - """ - self.description_builder = description_builder - self.label = label - self.owner = owner - self.isIndependent = isIndependent - - -def _n_ranks(partition): - """ - Returns the number of ranks for a given MPI partitioning. - - partition: iterable - The MPI cartesian partitioning. - (x, y, z) ranks are supposed to be integers (or None which will be considered as 1). - """ - result = 1 - # I wanted to do `filter( None, partition )` with the `filter` builtin function - # but it has been rewritten by ATS. This is sooo wrong :( - for n in partition: - result *= n if n else 1 - return result - - -def _build_poro_elastic_coupling_case(deck, cycles, partitions, description, - restartcheck_params): - """ - Generic function that build the poro-elastic cases. - A first run is done and a second takes an intermediate timestep to validate the restart. - - deck: str - XML input file - cycles: pair of integers - The (intermediate_cycle, last_cycle). First being the restart initial timestep. - The second being the last simulated cycle. - partitions: Iterable of length-3 iterables - The (x, y, z) parallel partitioning. - `None` can be provided when nothing has to be done in the considered direction. - description: Description - Description of the TestCase - restartcheck_params: dict - Restart validation parameters (relative or absolute tolerance mainly). - test_name_builder: callable - A callable taking the partition tuple in argument and returning the test name. - """ - - # The simulation will generate data for two cycles - intermediate_cycle, last_cycle = cycles - - return TestDeck( - name=deck.split(".")[0], - description=description.description_builder, - partitions=partitions, - restart_step=intermediate_cycle, - check_step=last_cycle, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) - - -def _build_Terzaghi_cases(): - description = Description("Terzaghi's 1D Consolidation", "auto", - "Nicola Castelletto", True) - restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} - return _build_poro_elastic_coupling_case("PoroElastic_Terzaghi_smoke.xml", - (50, 91), - ((1, 1, 1), (2, 1, 1), (7, 1, 1)), - description, restartcheck_params) - - -def _build_Mandel_fim_cases(): - description = Description("Mandel's 2D Consolidation on ranks", "auto", - "Nicola Castelletto, Jian Huang", True) - restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} - return _build_poro_elastic_coupling_case( - "PoroElastic_Mandel_smoke_fim.xml", (2, 4), - ((1, 1, 1), (3, 1, 1), (3, 1, 2)), description, restartcheck_params) - - -def _build_Mandel_sequential_cases(): - description = Description("Sequential Mandel's 2D Consolidation ", "auto", - "Nicola Castelletto, Jian Huang", True) - restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} - return _build_poro_elastic_coupling_case( - "PoroElastic_Mandel_smoke_sequential.xml", (2, 4), - ((1, 1, 1), (3, 1, 1), (3, 1, 2)), description, restartcheck_params) - - -def _build_Mandel_prism6_cases(): - description = Description( - "Mandel's 2D Consolidation using VEM-MFD on a prism mesh ", "auto", - "Andrea Borio, Francois Hamon", True) - restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} - return _build_poro_elastic_coupling_case( - "PoroElastic_Mandel_prism6_smoke.xml", (2, 4), ((1, 1, 1), ), - description, restartcheck_params) - - -def _build_Deadoil_fim_cases(): - description = Description("Deadoil 3 phase poroelastic case ", "auto", - "N. Castelletto & M. Cusini", True) - restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} - return _build_poro_elastic_coupling_case( - "PoroElastic_deadoil_3ph_baker_2d_fim.xml", (0, 15), - ((1, 1, 1), (2, 1, 2)), description, restartcheck_params) - - -def _build_Deadoil_sequential_cases(): - description = Description("Sequential Deadoil 3 phase poroelastic case ", - "auto", "N. Castelletto & M. Cusini", True) - restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} - return _build_poro_elastic_coupling_case( - "PoroElastic_deadoil_3ph_baker_2d_sequential.xml", (0, 15), - ((1, 1, 1), (2, 1, 2)), description, restartcheck_params) - - -def _build_PoroElasticWell_cases(): - description = Description("PoroElastic wellbore problem ", "auto", - "Jian Huang", True) - restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} - return _build_poro_elastic_coupling_case("PoroElasticWellbore_smoke.xml", - (2, 8), ((1, 1, 1), (2, 2, 1)), - description, restartcheck_params) - - -def _build_PoroDruckerPragerWell_cases(): - description = Description("PoroDruckerPrager wellbore problem", "auto", - "Jian Huang", True) - restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} - return _build_poro_elastic_coupling_case( - "PoroDruckerPragerWellbore_smoke.xml", (2, 8), ((1, 1, 1), (2, 2, 1)), - description, restartcheck_params) - - -def _build_PoroDelftEggWell_cases(): - description = Description("PoroDelftEgg wellbore problem ", "auto", - "Jian Huang", True) - restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} - return _build_poro_elastic_coupling_case("PoroDelftEggWellbore_smoke.xml", - (2, 8), ((1, 1, 1), (2, 2, 1)), - description, restartcheck_params) - - -def _build_PoroModifiedCamClayWell_cases(): - description = Description("PoroModifiedCamClay wellbore problem ", "auto", - "Jian Huang", True) - restartcheck_params = {"atol": 1.0e-8, "rtol": 2.0e-8} - return _build_poro_elastic_coupling_case( - "PoroModifiedCamClayWellbore_smoke.xml", (2, 8), - ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) - - -def _build_PoroImpermeableFault_cases(): - description = Description("Impermeable fault problem ", "auto", - "Jian Huang", True) - restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} - return _build_poro_elastic_coupling_case("impermeableFault_smoke.xml", - (0, 1), ((1, 1, 1), (2, 2, 1)), - description, restartcheck_params) - - -def _build_PoroPermeableFault_cases(): - description = Description("Permeable fault problem ", "auto", "Jian Huang", - True) - restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} - return _build_poro_elastic_coupling_case("permeableFault_smoke.xml", - (0, 1), ((1, 1, 1), (2, 2, 1)), - description, restartcheck_params) - - -def _build_PoroStaircaseSinglePhasePeacemanWell_fim_cases(): - description = Description( - "Staircase single-phase poroelastic problem with Peaceman wells ", - "auto", "Francois Hamon", True) - restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} - return _build_poro_elastic_coupling_case( - "PoroElastic_staircase_singlephase_3d_fim.xml", (6, 11), - ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) - - -def _build_PoroStaircaseSinglePhasePeacemanWell_sequential_cases(): - description = Description( - "Staircase single-phase poroelastic problem with Peaceman wells ", - "auto", "Francois Hamon", True) - restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} - return _build_poro_elastic_coupling_case( - "PoroElastic_staircase_singlephase_3d_sequential.xml", (6, 11), - ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) - - -def _build_PoroStaircaseCO2PeacemanWell_fim_cases(): - description = Description( - "Staircase CO2 poroelastic problem with Peaceman wells ", "auto", - "Francois Hamon", True) - restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} - return _build_poro_elastic_coupling_case( - "PoroElastic_staircase_co2_3d_fim.xml", (22, 33), - ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) - - -def _build_PoroStaircaseCO2PeacemanWell_sequential_cases(): - description = Description( - "Staircase CO2 poroelastic problem with Peaceman wells ", "auto", - "Francois Hamon", True) - restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} - return _build_poro_elastic_coupling_case( - "PoroElastic_staircase_co2_3d_sequential.xml", (22, 33), - ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) - - -def _build_PoroElasticPEBICO2FIM_cases(): - description = Description( - "CO2 poroelastic problem with VEM-TPFA (FIM) on a PEBI mesh ", "auto", - "Francois Hamon", True) - restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} - return _build_poro_elastic_coupling_case( - "PoroElastic_hybridHexPrism_co2_fim_3d.xml", (10, 20), - ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) - - -def _build_PoroElasticPEBICO2Sequential_cases(): - description = Description( - "CO2 poroelastic problem with VEM-TPFA (Sequential) on a PEBI mesh ", - "auto", "Francois Hamon", True) - restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} - return _build_poro_elastic_coupling_case( - "PoroElastic_hybridHexPrism_co2_sequential_3d.xml", (10, 20), - ((1, 1, 1), (2, 2, 1)), description, restartcheck_params) - - -def _build_PoroElasticGravity_cases(): - description = Description("Single-phase poroelastic problem with gravity ", - "auto", "Francois Hamon", True) - restartcheck_params = {"atol": 1.0e-5, "rtol": 2.0e-7} - return _build_poro_elastic_coupling_case("PoroElastic_gravity.xml", - (5, 10), ((1, 1, 1), (1, 1, 2)), - description, restartcheck_params) - - -def test_poro_elastic_coupling_cases(): - deck_instances = [ - _build_Terzaghi_cases(), - _build_Mandel_fim_cases(), - _build_Mandel_sequential_cases(), - _build_Mandel_prism6_cases(), - _build_Deadoil_fim_cases(), - _build_Deadoil_sequential_cases(), - _build_PoroElasticWell_cases(), - _build_PoroDruckerPragerWell_cases(), - _build_PoroDelftEggWell_cases(), - _build_PoroModifiedCamClayWell_cases(), - _build_PoroImpermeableFault_cases(), - _build_PoroPermeableFault_cases(), - _build_PoroStaircaseSinglePhasePeacemanWell_fim_cases(), - _build_PoroStaircaseSinglePhasePeacemanWell_sequential_cases(), - _build_PoroStaircaseCO2PeacemanWell_fim_cases(), - _build_PoroStaircaseCO2PeacemanWell_sequential_cases(), - _build_PoroElasticPEBICO2FIM_cases(), - _build_PoroElasticPEBICO2Sequential_cases(), - _build_PoroElasticGravity_cases() - ] - - generate_geos_tests(deck_instances) - - -test_poro_elastic_coupling_cases() diff --git a/inputFiles/poromechanics/viscoPlastic.ats b/inputFiles/poromechanics/viscoPlastic.ats deleted file mode 100644 index 1f2a7db87fe..00000000000 --- a/inputFiles/poromechanics/viscoPlastic.ats +++ /dev/null @@ -1,33 +0,0 @@ -import geos_ats -from geos_ats.test_builder import generate_geos_tests, RestartcheckParameters, TestDeck - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-5 -restartcheck_params["rtol"] = 1.0E-5 - -partitions = ((1, 1, 1), (1, 1, 2)) - -decks = [ - TestDeck( - name="PoroViscoDruckerPrager_smoke", - description="PoroViscoDruckerPrager wellbore problem", - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=2, - check_step=6, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="PoroViscoExtendedDruckerPrager_smoke", - description="PoroViscoExtendedDruckerPrager wellbore problem", - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=2, - check_step=6, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck(name="PoroViscoModifiedCamClay_smoke", - description="PoroViscoModifiedCamClay wellbore problem", - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=2, - check_step=6, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/poromechanicsFractures/ExponentialDecayPermeability_conformingFracture_base.xml b/inputFiles/poromechanicsFractures/ExponentialDecayPermeability_conformingFracture_base.xml index f8ddbc628cd..2393dc2477b 100644 --- a/inputFiles/poromechanicsFractures/ExponentialDecayPermeability_conformingFracture_base.xml +++ b/inputFiles/poromechanicsFractures/ExponentialDecayPermeability_conformingFracture_base.xml @@ -51,7 +51,8 @@ targetRegions="{ Domain, Fracture }"> + newtonMaxIter="8" + allowNonConverged="1"/> diff --git a/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_faultSlip_base.xml b/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_faultSlip_base.xml index 5d7235c36f6..c45bcbdb0e5 100644 --- a/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_faultSlip_base.xml +++ b/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_faultSlip_base.xml @@ -52,7 +52,8 @@ targetRegions="{ Domain, Fracture }"> + newtonMaxIter="8" + allowNonConverged="1"/> @@ -261,4 +262,4 @@ - + \ No newline at end of file diff --git a/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_openingFrac_base.xml b/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_openingFrac_base.xml index 6ffe3a235ab..543423eac0f 100644 --- a/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_openingFrac_base.xml +++ b/inputFiles/poromechanicsFractures/PoroElastic_conformingFracture_2d_openingFrac_base.xml @@ -51,7 +51,8 @@ targetRegions="{ Domain, Fracture }"> + newtonMaxIter="8" + allowNonConverged="1"/> @@ -162,4 +163,4 @@ values="{ 0.0, 1.5 }"/> - + \ No newline at end of file diff --git a/inputFiles/poromechanicsFractures/poromechanicsFractures.ats b/inputFiles/poromechanicsFractures/poromechanicsFractures.ats deleted file mode 100644 index 02dfc957812..00000000000 --- a/inputFiles/poromechanicsFractures/poromechanicsFractures.ats +++ /dev/null @@ -1,74 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {'atol': 1e-07, 'rtol': 4e-06} - -decks = [ - TestDeck( - name="SlipPermeability_pEDFM_smoke", - description='pEDFM slip dependent permeability case', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="WillisRichardsPermeability_efem-edfm_smoke", - description='WillisRichards Permeability model with EDFM', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=5, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="PoroElastic_conformingFracture_2d_openingFrac_horizontal_smoke", - description='PoroElastic conformingFracture 2d case', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="PoroElastic_conformingFracture_2d_openingFrac_vertical_smoke", - description='PoroElastic conformingFracture 2d case', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="PoroElastic_efem-edfm_pressurizedFrac_smoke", - description='poromechanics efem-edfm pressurized vertical frac', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="PoroElastic_efem-edfm_verticalFrac_smoke", - description='poromechanics efem-edfm vertical frac', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="PoroElastic_efem-edfm_inclinedFrac_smoke", - description='poromechanics efem-edfm inclined frac', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="ExponentialDecayPermeability_edfm_smoke", - description='Exponential Decay Permeability model with EDFM', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=5, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck(name="ExponentialDecayPermeability_conformingFracture_smoke", - description= - 'Exponential Decay Permeability model with conforming fracture', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=12, - restartcheck_params=RestartcheckParameters(atol=1e-05, - rtol=4e-04)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/proppant/proppantTransport.ats b/inputFiles/proppant/proppantTransport.ats deleted file mode 100644 index 9a9a0b99872..00000000000 --- a/inputFiles/proppant/proppantTransport.ats +++ /dev/null @@ -1,34 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 1e-10 -restartcheck_params['rtol'] = 4e-09 - -decks = [ - TestDeck( - name="FlowProppantTransport2d_smoke", - description= - 'Coupled Single phase flow and proppant transport test (2D, compressible, gravity, fracture flow)', - partitions=((1, 1, 1), (1, 2, 2), (1, 3, 3)), - restart_step=5, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="FlowProppantBedTransport2d_smoke", - description= - 'Proppant transport and bed-build-up test (2D, proppant, fracture flow)', - partitions=((1, 1, 1), (1, 2, 1), (1, 3, 1)), - restart_step=20, - check_step=40, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck(name="ProppantSlotTest_smoke", - description='Slot test on proppant transport with slickwater', - partitions=((1, 1, 1), (1, 3, 1), (1, 3, 3)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/simplePDE/SimpleSolvers.ats b/inputFiles/simplePDE/SimpleSolvers.ats deleted file mode 100644 index 8e5de718d0d..00000000000 --- a/inputFiles/simplePDE/SimpleSolvers.ats +++ /dev/null @@ -1,58 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 1e-08 -restartcheck_params['rtol'] = 2e-10 - -decks = [ - TestDeck( - name="10x10x10Hex_LaplaceFEM_smoke", - description='Testing the Laplace solver with Finite Elements', - partitions=((1, 1, 1), (2, 2, 2), (3, 3, 3)), - restart_step=1, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="50x10x5Hex_LaplaceFEM_smoke", - description='Testing the Laplace solver with Finite Elements', - partitions=((1, 1, 1), (2, 2, 2), (3, 3, 2)), - restart_step=1, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="10x10x10Hex_LaplaceVEM_smoke", - description= - 'Testing the Laplace solver with the Virtual Element Method (hexahedral cells)', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=1, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="15x5x10Tets_LaplaceVEM_smoke", - description= - 'Testing the Laplace solver with the Virtual Element Method (tetrahedral cells)', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=1, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="10x5x15Wedges_LaplaceVEM_smoke", - description= - 'Testing the Laplace solver with the Virtual Element Method (wedges)', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=1, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="hybridHexPrism_LaplaceVEM_smoke", - description= - 'Testing the Laplace solver with the Virtual Element Method (hexahedra and prisms)', - partitions=((1, 1, 1), (3, 1, 1)), - restart_step=1, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/singlePhaseFlow/singlePhaseFlow.ats b/inputFiles/singlePhaseFlow/singlePhaseFlow.ats deleted file mode 100644 index 2f0bb232b86..00000000000 --- a/inputFiles/singlePhaseFlow/singlePhaseFlow.ats +++ /dev/null @@ -1,81 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 1e-10 -restartcheck_params['rtol'] = 4e-09 - -decks = [ - TestDeck( - name="sourceFlux_1d", - description='Single phase flow test (1D, compressible, source flux)', - partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), - restart_step=10, - check_step=20, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="compressible_1d", - description='Single phase flow test (1D, compressible, Dirichlet BC)', - partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), - restart_step=10, - check_step=20, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="compressible_1d_2solids", - description= - 'Single phase flow test (1D, compressible, Dirichlet BC, 2 regions with different solids)', - partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), - restart_step=10, - check_step=20, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="incompressible_1d", - description= - 'Single phase flow test (1D, steady-state incompressible, Dirichlet BC)', - partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="incompressible_pebi3d", - description= - 'Single phase flow test (3D PEBI grid, steady-state incompressible, Dirichlet BC)', - partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="compressible_2d_2fluids", - description= - 'Single phase flow test (2D, compressible, Dirichlet BC, 2 regions with different fluids, trans multipliers)', - partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), - restart_step=10, - check_step=20, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="compressible_2d_2fluids_hybrid", - description= - 'Single phase flow test (2D, compressible, Dirichlet BC, 2 regions with different fluids, trans multipliers)', - partitions=((1, 1, 1), (2, 1, 1), (3, 1, 1)), - restart_step=10, - check_step=20, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="sourceFlux_2d", - description='Single phase flow test (2D, incompressible)', - partitions=((1, 1, 1), (2, 2, 1), (3, 3, 1)), - restart_step=10, - check_step=20, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="staircase_3d", - description= - 'Single phase flow test (3D, compressible, gravity, face boundary conditions)', - partitions=((1, 1, 1), (2, 2, 2), (3, 3, 3)), - restart_step=10, - check_step=20, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/singlePhaseFlow/thermalSinglePhaseFlow.ats b/inputFiles/singlePhaseFlow/thermalSinglePhaseFlow.ats deleted file mode 100644 index 532b1b1f989..00000000000 --- a/inputFiles/singlePhaseFlow/thermalSinglePhaseFlow.ats +++ /dev/null @@ -1,28 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 1e-06 -restartcheck_params['rtol'] = 1e-05 - -decks = [ - TestDeck( - name="thermalCompressible_2d_smoke", - description= - 'Pure thermal convection problem (2D, compressible, Dirichlet BC, thermal)', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=5, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="3D_10x10x10_thermalCompressible_smoke", - description= - 'Thermal single phase flow test (3D, compressible, Dirichlet BC, thermal)', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=6, - check_step=20, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/singlePhaseFlowFractures/fractureFlow_conforming_2d_vtk_input.xml b/inputFiles/singlePhaseFlowFractures/fractureFlow_conforming_2d_vtk_input.xml index 4b77e706571..3d7d8d4f16c 100644 --- a/inputFiles/singlePhaseFlowFractures/fractureFlow_conforming_2d_vtk_input.xml +++ b/inputFiles/singlePhaseFlowFractures/fractureFlow_conforming_2d_vtk_input.xml @@ -10,7 +10,8 @@ targetRegions="{ Region, Fracture }"> + newtonMaxIter="8" + allowNonConverged="1"/> diff --git a/inputFiles/singlePhaseFlowFractures/fractureMatrixFlow_conforming_2d.xml b/inputFiles/singlePhaseFlowFractures/fractureMatrixFlow_conforming_2d.xml index 1bc3e6b5c81..13d0917680a 100644 --- a/inputFiles/singlePhaseFlowFractures/fractureMatrixFlow_conforming_2d.xml +++ b/inputFiles/singlePhaseFlowFractures/fractureMatrixFlow_conforming_2d.xml @@ -10,7 +10,8 @@ targetRegions="{ Region2, Fracture }"> + newtonMaxIter="8" + allowNonConverged="1"/> diff --git a/inputFiles/singlePhaseFlowFractures/impermeableFault_conforming_base.xml b/inputFiles/singlePhaseFlowFractures/impermeableFault_conforming_base.xml index 3b4c2b58957..be9fc697ee2 100644 --- a/inputFiles/singlePhaseFlowFractures/impermeableFault_conforming_base.xml +++ b/inputFiles/singlePhaseFlowFractures/impermeableFault_conforming_base.xml @@ -10,7 +10,8 @@ targetRegions="{ RockMatrix, Fracture }"> + newtonMaxIter="8" + allowNonConverged="1"/> diff --git a/inputFiles/singlePhaseFlowFractures/singlePhaseFlowFractures.ats b/inputFiles/singlePhaseFlowFractures/singlePhaseFlowFractures.ats deleted file mode 100644 index 392c4217da4..00000000000 --- a/inputFiles/singlePhaseFlowFractures/singlePhaseFlowFractures.ats +++ /dev/null @@ -1,86 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 1e-10 -restartcheck_params['rtol'] = 4e-09 - -decks = [ - TestDeck( - name="fractureFlow_conforming_2d", - description= - 'Single phase flow test (2D, compressible, fracture flow, conforming)', - partitions=((1, 1, 1), (2, 1, 1), (4, 1, 1)), - restart_step=5, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="fractureJunctionFlow_conforming_2d", - description= - 'Single phase flow test (2D, compressible, intersecting fracture flow, conforming)', - partitions=((1, 1, 1), ), - restart_step=25, - check_step=50, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="fractureMatrixFlow_conforming_2d", - description= - 'Single phase flow test (2D, compressible, fracture/matrix flow)', - partitions=((1, 1, 1), (2, 2, 1), (3, 3, 1)), - restart_step=25, - check_step=50, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="fractureMatrixFlow_edfm_horizontalFrac_smoke", - description= - 'Single phase flow test (3D, incompressible, fracture/matrix flow, EDFM)', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=1, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="fractureMatrixFlow_edfm_inclinedFrac_smoke", - description= - 'Single phase flow test (3D, incompressible, fracture/matrix flow, EDFM)', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=1, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="fractureMatrixFlow_pedfm_impermeableFracture_smoke", - description='SinglePhase flow with pedfm', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="fractureMatrixFlowWithGravity_edfm_verticalFrac_smoke", - description='SinglePhase flow with edfm frac with gravity', - partitions=((1, 1, 1), (1, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="fractureMatrixFlowWithGravity_conforming_2d_smoke", - description='SinglePhase flow with conforming frac with gravity', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="fractureFlowWithGravity_conforming_2d_smoke", - description='SinglePhase flow in conforming frac with gravity', - partitions=((1, 1, 1), (1, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck(name="impermeableFault_conforming_smoke", - description='impermeable conforming fault', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/singlePhaseWell/singlePhaseWell.ats b/inputFiles/singlePhaseWell/singlePhaseWell.ats deleted file mode 100644 index 45bd8377dc5..00000000000 --- a/inputFiles/singlePhaseWell/singlePhaseWell.ats +++ /dev/null @@ -1,58 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 1e-09 -restartcheck_params['rtol'] = 4e-08 - -decks = [ - TestDeck( - name="compressible_single_phase_wells_1d", - description='Single phase well test (1D, compressible, 2 wells)', - partitions=((1, 1, 1), (2, 1, 1)), - restart_step=5, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="compressible_single_phase_wells_hybrid_1d", - description= - 'Single phase well test (1D, hybrid FVM, compressible, 2 wells)', - partitions=((1, 1, 1), (2, 1, 1)), - restart_step=5, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="incompressible_single_phase_wells_2d", - description='Single phase flow test (2D, incompressible, 3 wells)', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=5, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="incompressible_single_phase_wells_hybrid_2d", - description= - 'Single phase flow test (2D, hybrid FVM, incompressible, 3 wells)', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=5, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="staircase_single_phase_wells_3d", - description= - 'Single phase flow test (3D staircase, compressible, 2 wells)', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=5, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="staircase_single_phase_wells_hybrid_3d", - description= - 'Single phase flow test (3D staircase, hybrid FVM, compressible, 2 wells)', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=5, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/SSLE.ats b/inputFiles/solidMechanics/SSLE.ats deleted file mode 100644 index 38b590c519d..00000000000 --- a/inputFiles/solidMechanics/SSLE.ats +++ /dev/null @@ -1,19 +0,0 @@ -import geos_ats -from geos_ats.test_builder import generate_geos_tests, RestartcheckParameters, TestDeck - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-10 -restartcheck_params["rtol"] = 2.0E-13 - -partitions = ((1, 1, 1), (2, 2, 2), (3, 3, 3)) - -decks = [ - TestDeck(name="sedov_ssle_smoke", - description="Test the small strain linear elastic solver", - partitions=partitions, - restart_step=50, - check_step=100, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/anisotropic.ats b/inputFiles/solidMechanics/anisotropic.ats deleted file mode 100644 index a6afc13b144..00000000000 --- a/inputFiles/solidMechanics/anisotropic.ats +++ /dev/null @@ -1,36 +0,0 @@ -import geos_ats -from geos_ats.test_builder import generate_geos_tests, TestDeck, RestartcheckParameters - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-5 -restartcheck_params["rtol"] = 1.0E-5 - -partitions = ((1, 1, 1), (2, 2, 1)) - -decks = [ - TestDeck( - name="elasticHollowCylinder_isotropic_smoke", - description= - "Test the elastic hollow cylinder with an isotropic material", - partitions=partitions, - restart_step=0, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="elasticHollowCylinder_transverseIsotropic_smoke", - description= - "Test the elastic hollow cylinder with a transverse isotropic material", - partitions=partitions, - restart_step=0, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck(name="elasticHollowCylinder_orthotropic_smoke", - description= - "Test the elastic hollow cylinder with an orthotropic material", - partitions=partitions, - restart_step=0, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/beamBending.ats b/inputFiles/solidMechanics/beamBending.ats deleted file mode 100644 index 352a2ae5d3f..00000000000 --- a/inputFiles/solidMechanics/beamBending.ats +++ /dev/null @@ -1,38 +0,0 @@ -import geos_ats -from geos_ats.test_builder import RestartcheckParameters, CurveCheckParameters, TestDeck, generate_geos_tests - -restartcheck_params = RestartcheckParameters(atol=1.0E-3, rtol=1.0E-7) - -curvecheck_params = CurveCheckParameters( - filename='displacement_history.hdf5', - tolerance=[0.0002], - script_instructions=[[ - './beamBending_curve.py', 'curve', 'totalDisplacement', 'trace' - ]], - curves=[['totalDisplacement', 'trace']]) - -partitions = ((1, 1, 1), (2, 2, 2)) - -decks = [ - TestDeck(name="beamBending_smoke", - description="Tests beam bending.", - partitions=partitions, - restart_step=0, - check_step=1, - restartcheck_params=restartcheck_params, - curvecheck_params=curvecheck_params), - TestDeck(name="beamBending_vem_smoke", - description="Tests beam bending applying Virtual Elements.", - partitions=partitions, - restart_step=0, - check_step=1, - restartcheck_params=restartcheck_params), - TestDeck(name="beamBending_hybridHexPrism_smoke", - description="Tests beam bending on general polyhedral mesh.", - partitions=partitions, - restart_step=0, - check_step=1, - restartcheck_params=restartcheck_params) -] - -generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/gravity.ats b/inputFiles/solidMechanics/gravity.ats deleted file mode 100644 index 0da665c416e..00000000000 --- a/inputFiles/solidMechanics/gravity.ats +++ /dev/null @@ -1,20 +0,0 @@ -import geos_ats -from geos_ats.test_builder import generate_geos_tests, TestDeck, RestartcheckParameters - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-5 -restartcheck_params["rtol"] = 1.0E-5 - -partitions = ((1, 1, 1), (1, 1, 2)) - -decks = [ - TestDeck( - name="gravity", - description="Test the gravity application in solid mechanics solver", - partitions=partitions, - restart_step=1, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/plasticCubeReset.ats b/inputFiles/solidMechanics/plasticCubeReset.ats deleted file mode 100644 index 9efdc1738c5..00000000000 --- a/inputFiles/solidMechanics/plasticCubeReset.ats +++ /dev/null @@ -1,19 +0,0 @@ -import geos_ats -from geos_ats.test_builder import generate_geos_tests, RestartcheckParameters, TestDeck - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-5 -restartcheck_params["rtol"] = 1.0E-5 - -partitions = ((1, 1, 1), (1, 1, 2)) - -decks = [ - TestDeck(name="plasticCubeReset", - description="Test the initialization step of for solid mechanics", - partitions=partitions, - restart_step=4, - check_step=7, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/plasticWellbore.ats b/inputFiles/solidMechanics/plasticWellbore.ats deleted file mode 100644 index 4c285454533..00000000000 --- a/inputFiles/solidMechanics/plasticWellbore.ats +++ /dev/null @@ -1,34 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 1e-06 -restartcheck_params['rtol'] = 0.0001 - -decks = [ - TestDeck( - name="ModifiedCamClayWellbore_smoke", - description='test of wellbore mesh generation and simple loading', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=1, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="ExtendedDruckerPragerWellbore_smoke", - description= - 'test of wellbore with ExtendedDruckerPrager material and simple loading', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=1, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck(name="DruckerPragerWellbore_smoke", - description= - 'test of wellbore with DruckerPrager material and simple loading', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=1, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/sedov.ats b/inputFiles/solidMechanics/sedov.ats deleted file mode 100644 index 07d74a25999..00000000000 --- a/inputFiles/solidMechanics/sedov.ats +++ /dev/null @@ -1,27 +0,0 @@ -import geos_ats -from geos_ats.test_builder import generate_geos_tests, RestartcheckParameters, TestDeck, CurveCheckParameters - -restartcheck_params = {} -restartcheck_params["atol"] = 2.0E-10 -restartcheck_params["rtol"] = 2.0E-13 - -curvecheck_params = {} -curvecheck_params['filename'] = 'veloc_history.hdf5' -curvecheck_params['tolerance'] = 1e-10 -curvecheck_params['time_units'] = 'milliseconds' -curvecheck_params['curves'] = [['velocity', 'source']] - -partitions = ((1, 1, 1), (2, 2, 2), (3, 3, 3)) - -decks = [ - TestDeck( - name="sedov_finiteStrain_smoke", - description="Test the basic sedov problem and restart capabilities", - partitions=partitions, - restart_step=50, - check_step=100, - restartcheck_params=RestartcheckParameters(**restartcheck_params), - curvecheck_params=CurveCheckParameters(**curvecheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/viscoPlastic.ats b/inputFiles/solidMechanics/viscoPlastic.ats deleted file mode 100644 index e61a1ac8a92..00000000000 --- a/inputFiles/solidMechanics/viscoPlastic.ats +++ /dev/null @@ -1,20 +0,0 @@ -import geos_ats -from geos_ats.test_builder import generate_geos_tests, RestartcheckParameters, TestDeck - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-5 -restartcheck_params["rtol"] = 1.0E-5 - -partitions = ((1, 1, 1), (1, 1, 2)) - -decks = [ - TestDeck( - name="viscoExtendedDruckerPrager_relaxation_smoke", - description="Relaxation test with viscoplastic solver", - partitions=((1, 1, 1), (1, 1, 2)), - restart_step=0, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), -] - -generate_geos_tests(decks) diff --git a/inputFiles/solidMechanics/wellbore.ats b/inputFiles/solidMechanics/wellbore.ats deleted file mode 100644 index f858b683f22..00000000000 --- a/inputFiles/solidMechanics/wellbore.ats +++ /dev/null @@ -1,19 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 0.0001 -restartcheck_params['rtol'] = 0.0001 - -decks = [ - TestDeck( - name="KirschProblem_smoke", - description= - 'test of wellbore mesh generation and open well with simple loading', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), -] -generate_geos_tests(decks) diff --git a/inputFiles/surfaceGeneration/SurfaceGenerator.ats b/inputFiles/surfaceGeneration/SurfaceGenerator.ats deleted file mode 100644 index 58a7bdce307..00000000000 --- a/inputFiles/surfaceGeneration/SurfaceGenerator.ats +++ /dev/null @@ -1,46 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params["atol"] = 1.0E-5 -restartcheck_params["rtol"] = 2.0E-10 - -partitions = ((1, 1, 1), (2, 2, 2)) - -decks = [ - TestDeck( - name="SurfaceGenerator", - description= - "Test the basic surface generator problem and restart capabilities.", - partitions=partitions, - restart_step=2, - check_step=3, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="DryFrac_StaticPenny_PrismElem", - description= - "Testing the SIF calculation (node-based) for a penny-shaped fracture", - partitions=partitions, - restart_step=0, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="DryFrac_ThreeNodesPinched_HorizontalFrac", - description= - "Testing the SIF calculation (node-based) under three nodes pinched scenario (fracture plane parallel to model boundary)", - partitions=partitions, - restart_step=0, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="DryFrac_ThreeNodesPinched_SlantFrac", - description= - "Testing the SIF calculation (node-based) under three nodes pinched scenario (fracture plane for an angle of 45 degree with model boundary)", - partitions=partitions, - restart_step=0, - check_step=2, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/thermalMultiphaseFlow/thermalMultiphaseFlow.ats b/inputFiles/thermalMultiphaseFlow/thermalMultiphaseFlow.ats deleted file mode 100644 index 63f0a1eb79e..00000000000 --- a/inputFiles/thermalMultiphaseFlow/thermalMultiphaseFlow.ats +++ /dev/null @@ -1,28 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 1e-06 -restartcheck_params['rtol'] = 1e-05 - -decks = [ - TestDeck( - name="co2_thermal_2d", - description= - 'Thermal compositional co2-brine flow test (2D co2 injection, 2-phase co2-brine, Brooks-Corey relperm curves, thermal)', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=9, - check_step=11, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="co2_thermal_obl_3d", - description= - 'Smoke test for a co2-brine test (3D displacement, 2-phase co2-brine, thermal, OBL)', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=14, - check_step=19, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/thermalSinglePhaseFlowFractures/fractureMatrixThermalFlow_conforming_base.xml b/inputFiles/thermalSinglePhaseFlowFractures/fractureMatrixThermalFlow_conforming_base.xml index 6d25802c993..6a3c2e68250 100644 --- a/inputFiles/thermalSinglePhaseFlowFractures/fractureMatrixThermalFlow_conforming_base.xml +++ b/inputFiles/thermalSinglePhaseFlowFractures/fractureMatrixThermalFlow_conforming_base.xml @@ -17,7 +17,7 @@ + allowNonConverged="1"/> diff --git a/inputFiles/thermalSinglePhaseFlowFractures/thermalSinglePhaseFlowFractures.ats b/inputFiles/thermalSinglePhaseFlowFractures/thermalSinglePhaseFlowFractures.ats deleted file mode 100644 index ab39f64db8c..00000000000 --- a/inputFiles/thermalSinglePhaseFlowFractures/thermalSinglePhaseFlowFractures.ats +++ /dev/null @@ -1,26 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 1e-06 -restartcheck_params['rtol'] = 1e-05 - -decks = [ - TestDeck( - name="fractureMatrixThermalFlow_edfm_smoke", - description='Thermal single-phase flow with an edfm fracture.', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="fractureMatrixThermalFlow_conforming_smoke", - description='Thermal single-phase flow with a conforming fracture', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/thermoPoromechanics/thermoPoromechanics.ats b/inputFiles/thermoPoromechanics/thermoPoromechanics.ats deleted file mode 100644 index 561fe62ba25..00000000000 --- a/inputFiles/thermoPoromechanics/thermoPoromechanics.ats +++ /dev/null @@ -1,32 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {'atol': 1e-06, 'rtol': 4e-06} - -decks = [ - TestDeck( - name="ThermoPoroElastic_consolidation_smoke_fim", - description='1D thermo poro elastic case consolidation problem (FIM)', - partitions=((1, 1, 1), (1, 2, 1)), - restart_step=633, - check_step=683, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="ThermoPoroElastic_consolidation_smoke_sequential", - description= - '1D thermo poro elastic case consolidation problem (sequential)', - partitions=((1, 1, 1), (1, 2, 1)), - restart_step=633, - check_step=683, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="ThermoPoroElastic_staircase_co2_smoke", - description='Staircase thermo-poro-mechanics with cold CO2 injection', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=22, - check_step=33, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/thermoPoromechanicsFractures/thermoPoromechanicsFractures.ats b/inputFiles/thermoPoromechanicsFractures/thermoPoromechanicsFractures.ats deleted file mode 100644 index cca95c6e68e..00000000000 --- a/inputFiles/thermoPoromechanicsFractures/thermoPoromechanicsFractures.ats +++ /dev/null @@ -1,23 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {'atol': 1e-06, 'rtol': 4e-06} - -decks = [ - TestDeck( - name="ThermoPoroElastic_efem-edfm_verticalFrac_smoke", - description='Thermoporoelastic case with an embeded fracture', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck(name="ThermoPoroElastic_conforming_smoke", - description='Thermoporoelastic case with a conforming fracture', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/wavePropagation/AcousticElasticSEM.ats b/inputFiles/wavePropagation/AcousticElasticSEM.ats deleted file mode 100644 index 642390f5b7d..00000000000 --- a/inputFiles/wavePropagation/AcousticElasticSEM.ats +++ /dev/null @@ -1,20 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 0.0001 -restartcheck_params['rtol'] = 2e-05 - -decks = [ - TestDeck( - name="acouselas3D_Q2_abc_smoke", - description= - 'Acoustic Elastic solver (pseudo 2D), third-order FE, absorbing BC', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=10, - check_step=20, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), -] - -generate_geos_tests(decks) diff --git a/inputFiles/wavePropagation/AcousticFirstOrderSEM.ats b/inputFiles/wavePropagation/AcousticFirstOrderSEM.ats deleted file mode 100644 index 4eafac6e6bb..00000000000 --- a/inputFiles/wavePropagation/AcousticFirstOrderSEM.ats +++ /dev/null @@ -1,44 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 0.0001 -restartcheck_params['rtol'] = 2e-05 - -decks = [ - TestDeck( - name="acous3D_firstOrder_abc_smoke", - description= - 'Acoustic wave solver, first-order FE, first order formulation, absorbing BC', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="acous3D_firstOrder_fs_smoke", - description= - 'Acoustic wave solver, first-order FE, first order formulation, absorbing BC on the sides, free surface BC at the top', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="acous3D_Q3_firstOrder_abc_smoke", - description= - 'Acoustic wave solver, third-order FE, first order formulation, absorbing BC', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="acous3D_Q3_firstOrder_fs_smoke", - description= - 'Acoustic wave solver, third-order FE, first order formulation, absorbing BC on the sides, free surface BC at the top', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/wavePropagation/AcousticSEM.ats b/inputFiles/wavePropagation/AcousticSEM.ats deleted file mode 100644 index 006d7958153..00000000000 --- a/inputFiles/wavePropagation/AcousticSEM.ats +++ /dev/null @@ -1,58 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 0.0001 -restartcheck_params['rtol'] = 2e-05 - -decks = [ - TestDeck( - name="acous3D_abc_smoke", - description='Acoustic wave solver, first-order FE, absorbing BC', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="acous3D_abc_fs_smoke", - description= - 'Acoustic wave solver, first-order FE, absorbing BC on the sides, free surface BC at the top', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="acous3D_pml_smoke", - description= - 'Acoustic wave solver, first-order FE, perfectly matched layer BC', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=20, - check_step=40, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="acous3D_vti_smoke", - description= - 'Acoustic wave solver, first-order FE, vertical transverse isotropic', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="acous3D_Q3_abc_smoke", - description='Acoustic wave solver, third-order FE, absorbing BC', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="acous3D_Q3_abc_fs_smoke", - description= - 'Acoustic wave solver, third-order FE, absorbing BC on the sides, free surface BC at the top', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/wavePropagation/ElasticFirstOrderSEM.ats b/inputFiles/wavePropagation/ElasticFirstOrderSEM.ats deleted file mode 100644 index dfad33d399f..00000000000 --- a/inputFiles/wavePropagation/ElasticFirstOrderSEM.ats +++ /dev/null @@ -1,44 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 0.0001 -restartcheck_params['rtol'] = 2e-05 - -decks = [ - TestDeck( - name="elas3D_firstOrder_abc_smoke", - description= - 'Elastic wave solver, first-order FE, first order formulation, absorbing BC', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="elas3D_firstOrder_fs_smoke", - description= - 'Elastic wave solver, first-order FE, first order formulation, absorbing BC on the sides, free surface BC at the top', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="elas3D_Q3_firstOrder_abc_smoke", - description= - 'Elastic wave solver, third-order FE, first order formulation, absorbing BC', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="elas3D_Q3_firstOrder_fs_smoke", - description= - 'Elastic wave solver, third-order FE, first order formulation, absorbing BC on the sides, free surface BC at the top', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/wavePropagation/ElasticSEM.ats b/inputFiles/wavePropagation/ElasticSEM.ats deleted file mode 100644 index 7ea1adb9713..00000000000 --- a/inputFiles/wavePropagation/ElasticSEM.ats +++ /dev/null @@ -1,42 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 0.0001 -restartcheck_params['rtol'] = 2e-05 - -decks = [ - TestDeck( - name="elas3D_abc_smoke", - description='Elastic wave solver, first-order FE, absorbing BC', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="elas3D_abc_fs_smoke", - description= - 'Elastic wave solver, first-order FE, absorbing BC on the sides, free surface BC at the top', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="elas3D_Q3_abc_smoke", - description='Elastic wave solver, third-order FE, absorbing BC', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="elas3D_Q3_abc_fs_smoke", - description= - 'Elastic wave solver, third-order FE, absorbing BC on the sides, free surface BC at the top', - partitions=((1, 1, 1), (2, 2, 2)), - restart_step=100, - check_step=200, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] - -generate_geos_tests(decks) diff --git a/inputFiles/wellbore/thermoPoromechanics_wellbore.ats b/inputFiles/wellbore/thermoPoromechanics_wellbore.ats deleted file mode 100644 index 4541246b809..00000000000 --- a/inputFiles/wellbore/thermoPoromechanics_wellbore.ats +++ /dev/null @@ -1,18 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {'atol': 1e-06, 'rtol': 4e-06} - -decks = [ - TestDeck( - name="CasedThermoElasticWellbore_smoke", - description= - 'Near wellbore thermo elastic case simulated as a single-phase poromechanics case', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=5, - check_step=10, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), -] - -generate_geos_tests(decks) diff --git a/inputFiles/wellbore/wellboreMesh.ats b/inputFiles/wellbore/wellboreMesh.ats deleted file mode 100644 index 23086646dd8..00000000000 --- a/inputFiles/wellbore/wellboreMesh.ats +++ /dev/null @@ -1,67 +0,0 @@ -import os -import geos_ats -from geos_ats.test_builder import TestDeck, RestartcheckParameters, generate_geos_tests - -restartcheck_params = {} -restartcheck_params['atol'] = 0.0001 -restartcheck_params['rtol'] = 0.0001 - -decks = [ - TestDeck( - name="CasedElasticWellbore_smoke", - description='test of cased wellbore mesh generation and simple loading', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="CasedElasticWellbore_ImperfectInterfaces_smoke", - description= - 'test of cased wellbore mesh generation and contact mechanics', - partitions=[ - (1, 1, 1), - ], - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="CasedThermoElasticWellbore_ImperfectInterfaces_smoke", - description= - 'test the debonding of cased wellbore with thermoelastic solver', - partitions=[(1, 1, 1),], - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="DeviatedElasticWellbore_smoke", - description= - 'test a deviated wellbore problem with open hole completion', - partitions=((1, 1, 1), (3, 1, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="DeviatedPoroElasticWellbore_Injection_smoke", - description= - 'a deviated wellbore subjected to a fluid pressure loaded at wellbore wall', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="DeviatedPoroElasticWellbore_Drilling_smoke", - description= - 'drilling a deviated poro-elastic wellbore with in-situ stresses', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)), - TestDeck( - name="ThermoPoroElasticWellbore_smoke", - description='single-phase thermo-hydro-mechanical wellbore', - partitions=((1, 1, 1), (2, 2, 1)), - restart_step=0, - check_step=1, - restartcheck_params=RestartcheckParameters(**restartcheck_params)) -] -generate_geos_tests(decks) diff --git a/integratedTests b/integratedTests index 8f03e8e1c8d..511253b330d 160000 --- a/integratedTests +++ b/integratedTests @@ -1 +1 @@ -Subproject commit 8f03e8e1c8df683135db5968f244336fbf20c96e +Subproject commit 511253b330d2cce7ebbd0e65e317f72b6883b7bc diff --git a/scripts/ci_build_and_test_in_container.sh b/scripts/ci_build_and_test_in_container.sh index c292755a605..f74a0795b48 100755 --- a/scripts/ci_build_and_test_in_container.sh +++ b/scripts/ci_build_and_test_in_container.sh @@ -236,7 +236,7 @@ else if [[ ! -z "${DATA_BASENAME_WE}" ]]; then # Here we pack the installation. # The `--transform` parameter provides consistency between the tarball name and the unpacked folder. - or_die tar czf ${DATA_EXCHANGE_DIR}/${DATA_BASENAME_WE}.tar.gz --directory=${GEOSX_TPL_DIR}/.. --transform "s|^./|${DATA_BASENAME_WE}/|" . + or_die tar czf ${DATA_EXCHANGE_DIR}/${DATA_BASENAME_WE}.tar.gz --directory=${GEOSX_TPL_DIR}/.. --transform "s/^./${DATA_BASENAME_WE}/" . fi fi @@ -295,4 +295,4 @@ if [[ ! -z "${INTEGRATED_TEST_EXIT_STATUS+x}" ]]; then else echo "Exiting the build process with exit status 0." exit 0 -fi \ No newline at end of file +fi diff --git a/scripts/setupPythonEnvironment.bash b/scripts/setupPythonEnvironment.bash index edd5c91296f..8732edf3130 100755 --- a/scripts/setupPythonEnvironment.bash +++ b/scripts/setupPythonEnvironment.bash @@ -8,7 +8,6 @@ BIN_DIR= PACKAGE_DIR= TMP_CLONE_DIR= PIP_CMD="pip --disable-pip-version-check" -PACKAGE_BRANCH=main declare -a TARGET_PACKAGES=("geosx_mesh_tools_package" @@ -52,10 +51,6 @@ case $key in PACKAGE_DIR="$2" shift # past argument ;; - -r|--python-pkg-branch) - PACKAGE_BRANCH="$2" - shift # past argument - ;; -v|--verbose) VERBOSE=true shift # past argument @@ -66,7 +61,6 @@ case $key in echo "-p/--python-target \"Target parent python bin\"" echo "-b/--bin-dir \"Directory to link new scripts\"" echo "-d/--pkg-dir \"Directory containing target python packages\"" - echo "-t/--tool-branch \"Target branch for geosPythonPackages (default=main) \"" echo "-v/--verbose \"Increase verbosity level\"" echo "" exit @@ -101,10 +95,10 @@ fi echo "Checking for python packages..." if [[ -z "${PACKAGE_DIR}" ]] then - echo "Cloning the GEOS python package repository (branch=$PACKAGE_BRANCH)..." + echo "Cloning the GEOS python package repository..." TMP_CLONE_DIR=$(mktemp -d) PACKAGE_DIR=$TMP_CLONE_DIR/geosPythonPackages - git clone --depth 1 --branch $PACKAGE_BRANCH --single-branch https://github.com/GEOS-DEV/geosPythonPackages.git $PACKAGE_DIR + git clone --depth 1 --branch main --single-branch https://github.com/GEOS-DEV/geosPythonPackages.git $PACKAGE_DIR elif [ ! -d "${PACKAGE_DIR}/geosx_xml_tools_package" ] then echo "The specified package directory does not contain the expected targets." @@ -123,10 +117,10 @@ do # Try installing the package if $VERBOSE - INSTALL_MSG=$($PYTHON_TARGET -m $PIP_CMD install --upgrade $PACKAGE_DIR/$p) + INSTALL_MSG=$($PYTHON_TARGET -m $PIP_CMD install $PACKAGE_DIR/$p) INSTALL_RC=$? then - INSTALL_MSG=$($PYTHON_TARGET -m $PIP_CMD install --upgrade $PACKAGE_DIR/$p 2>&1) + INSTALL_MSG=$($PYTHON_TARGET -m $PIP_CMD install $PACKAGE_DIR/$p 2>&1) INSTALL_RC=$? fi diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7fb71e7cbe9..7041bf98ff1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -256,25 +256,19 @@ if ( Python3_EXECUTABLE ) message(WARNING "The \"virtualenv\" package was not found in the target python environment (${Python3_EXECUTABLE}). This package may be required to build PYGEOSX or the python development environment.") endif() - # Check for the requested branch of geosPythonPackages (used for testing) - if( NOT GEOS_PYTHON_PACKAGES_BRANCH ) - set(GEOS_PYTHON_PACKAGES_BRANCH "main" CACHE STRING "" FORCE) - endif() - + # Build targets set( GEOSX_PYTHON_TOOLS_BINS "${CMAKE_BINARY_DIR}/bin/preprocess_xml" "${CMAKE_BINARY_DIR}/bin/format_xml" ) add_custom_command( OUTPUT ${GEOSX_PYTHON_TOOLS_BINS} - COMMAND bash ${CMAKE_SOURCE_DIR}/../scripts/setupPythonEnvironment.bash -p ${PYTHON_POST_EXECUTABLE} -b ${CMAKE_BINARY_DIR}/bin --python-pkg-branch ${GEOS_PYTHON_PACKAGES_BRANCH} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) + COMMAND bash ${CMAKE_SOURCE_DIR}/../scripts/setupPythonEnvironment.bash -p ${PYTHON_POST_EXECUTABLE} -b ${CMAKE_BINARY_DIR}/bin + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) add_custom_target( geosx_python_tools DEPENDS ${GEOSX_PYTHON_TOOLS_BINS} ) - add_custom_target( geosx_python_tools_clean - COMMAND rm ${GEOSX_PYTHON_TOOLS_BINS} ) - add_custom_target( geosx_python_tools_test COMMAND ${CMAKE_BINARY_DIR}/python/geosx/bin/test_geosx_xml_tools COMMAND rm -r ${CMAKE_BINARY_DIR}/python/geosx_xml_tools_tests* @@ -297,81 +291,12 @@ endif() ################################ # Add integratedTests ################################ -if (NOT DEFINED ENABLE_ATS) - set( ENABLE_ATS true CACHE BOOL "") -endif() - - -if ( ENABLE_ATS ) - if (NOT DEFINED ATS_WORKING_DIR) - message( WARNING "ATS_WORKING_DIR is not defined (required for integrated testing system)" ) - message( WARNING "Defaulting to ${CMAKE_BINARY_DIR}/integratedTests/workingDir" ) - set( ATS_WORKING_DIR "${CMAKE_BINARY_DIR}/integratedTests/workingDir" CACHE PATH "") - endif() - - if (NOT DEFINED ATS_BASELINE_DIR) - message( WARNING "ATS_BASELINE_DIR is not defined (required for integrated testing system)" ) - message( WARNING "Defaulting to ${CMAKE_SOURCE_DIR}/../integratedTests" ) - set( ATS_BASELINE_DIR "${CMAKE_SOURCE_DIR}/../integratedTests" CACHE PATH "") - endif() - - if (NOT Python3_EXECUTABLE) - message( FATAL_ERROR "An appropriate version of python was not found (required for integrated testing system). Try setting Python3_ROOT_DIR and/or Python3_EXECUTABLE in your host config." ) - endif() - - # Setup testing - set( ATS_SCRIPT - "${CMAKE_BINARY_DIR}/integratedTests/geos_ats.sh" - ) - - add_custom_command( OUTPUT ${ATS_SCRIPT} - COMMAND ${CMAKE_BINARY_DIR}/bin/setup_ats_environment ${CMAKE_SOURCE_DIR}/.. ${CMAKE_BINARY_DIR} ${ATS_BASELINE_DIR} ${ATS_WORKING_DIR} ${ATS_ARGUMENTS} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - ) - - add_custom_target( ats_environment - DEPENDS geosx_python_tools - DEPENDS ${ATS_SCRIPT} ) - - add_custom_target( ats_run - COMMAND ${CMAKE_BINARY_DIR}/integratedTests/geos_ats.sh - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - DEPENDS ats_environment - ) - - add_custom_target( ats_clean - COMMAND ${CMAKE_BINARY_DIR}/integratedTests/geos_ats.sh -a veryclean - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - DEPENDS ats_environment - ) - - add_custom_target( ats_rebaseline - COMMAND ${CMAKE_BINARY_DIR}/integratedTests/geos_ats.sh -a rebaseline - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - DEPENDS ats_environment - ) - - add_custom_target( ats_rebaseline_failed - COMMAND ${CMAKE_BINARY_DIR}/integratedTests/geos_ats.sh -a rebaselinefailed - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - DEPENDS ats_environment - ) -endif() - - -# Python formatting -if ( ENABLE_YAPF ) - set( integrated_tests_python_sources ) - file( GLOB_RECURSE integrated_tests_python_sources "${CMAKE_SOURCE_DIR}/../inputFiles/*.py" ) - set( integrated_tests_ats_sources ) - file( GLOB_RECURSE integrated_tests_ats_sources "${CMAKE_SOURCE_DIR}/../inputFiles/*.ats" ) - - blt_add_code_checks( PREFIX integrated_tests_yapf_style - SOURCES ${integrated_tests_python_sources} ${integrated_tests_ats_sources} ${CMAKE_SOURCE_DIR}/coreComponents/dummy.cpp - YAPF_CFG_FILE ${PROJECT_SOURCE_DIR}/yapf.cfg ) +if( EXISTS "${CMAKE_SOURCE_DIR}/../integratedTests/CMakeLists.txt") + add_subdirectory( ${CMAKE_SOURCE_DIR}/../integratedTests integratedTests ) +else() + message( "Could not find the integratedTests submodule" ) endif() - # the following adds a `build_test` CMake target such that running `$ make build_test test` # builds the unit tests before running them get_property( tmp GLOBAL PROPERTY geos_tests_exe_list ) diff --git a/src/coreComponents/finiteElement/elementFormulations/Qk_Hexahedron_Lagrange_GaussLobatto.hpp b/src/coreComponents/finiteElement/elementFormulations/Qk_Hexahedron_Lagrange_GaussLobatto.hpp index 8b1c73c1b85..e8cead63acf 100644 --- a/src/coreComponents/finiteElement/elementFormulations/Qk_Hexahedron_Lagrange_GaussLobatto.hpp +++ b/src/coreComponents/finiteElement/elementFormulations/Qk_Hexahedron_Lagrange_GaussLobatto.hpp @@ -1320,7 +1320,7 @@ computeFirstOrderStiffnessTerm( localIndex const q, const real64 w02 = w * gia * gjc; func( ibc, abj, w02 * detJ, J, 0, 2 ); func( abj, ibc, w02 * detJ, J, 2, 0 ); - const real64 w01 = w * gia * gjb; + const real64 w01 = w * gia * gjc; func( ibc, ajc, w01 * detJ, J, 0, 1 ); func( ajc, ibc, w01 * detJ, J, 1, 0 ); } diff --git a/src/coreComponents/physicsSolvers/CMakeLists.txt b/src/coreComponents/physicsSolvers/CMakeLists.txt index 2dc8662f05c..def7de24ea1 100644 --- a/src/coreComponents/physicsSolvers/CMakeLists.txt +++ b/src/coreComponents/physicsSolvers/CMakeLists.txt @@ -130,20 +130,17 @@ set( physicsSolvers_headers surfaceGeneration/kernels/surfaceGenerationKernelsHelpers.hpp wavePropagation/WaveSolverBase.hpp wavePropagation/WaveSolverUtils.hpp - wavePropagation/AcousticFields.hpp + wavePropagation/WaveSolverBaseFields.hpp wavePropagation/AcousticWaveEquationSEM.hpp wavePropagation/AcousticWaveEquationSEMKernel.hpp - wavePropagation/ElasticFields.hpp wavePropagation/ElasticWaveEquationSEM.hpp wavePropagation/ElasticWaveEquationSEMKernel.hpp wavePropagation/ElasticFirstOrderWaveEquationSEM.hpp wavePropagation/ElasticFirstOrderWaveEquationSEMKernel.hpp wavePropagation/AcousticFirstOrderWaveEquationSEM.hpp wavePropagation/AcousticFirstOrderWaveEquationSEMKernel.hpp - wavePropagation/AcousticVTIFields.hpp wavePropagation/AcousticVTIWaveEquationSEM.hpp wavePropagation/AcousticVTIWaveEquationSEMKernel.hpp - wavePropagation/AcoustoElasticFields.hpp wavePropagation/AcousticElasticWaveEquationSEM.hpp wavePropagation/AcousticElasticWaveEquationSEMKernel.hpp ) diff --git a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp index 05946aa15b8..af316a23062 100644 --- a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp +++ b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp @@ -13,7 +13,6 @@ */ #include "NonlinearSolverParameters.hpp" -#include "common/Logger.hpp" namespace geos { @@ -55,11 +54,6 @@ NonlinearSolverParameters::NonlinearSolverParameters( string const & name, setDescription( "Line search cut factor. For instance, a value of 0.5 will result in the effective application of" " the last solution by a factor of (0.5, 0.25, 0.125, ...)" ); - registerWrapper( viewKeysStruct::lineSearchStartingIterationString(), &m_lineSearchStartingIteration ). - setApplyDefaultValue( 0 ). - setInputFlag( InputFlags::OPTIONAL ). - setDescription( "Iteration when line search starts." ); - registerWrapper( viewKeysStruct::normTypeString(), &m_normType ). setInputFlag( InputFlags::FALSE ). setApplyDefaultValue( solverBaseKernels::NormType::Linf ). @@ -172,39 +166,6 @@ void NonlinearSolverParameters::postProcessInput() GEOS_ERROR_IF_LE_MSG( m_timeStepDecreaseIterLimit, m_timeStepIncreaseIterLimit, getWrapperDataContext( viewKeysStruct::timeStepIncreaseIterLimString() ) << ": should be smaller than " << viewKeysStruct::timeStepDecreaseIterLimString() ); - - if( getLogLevel() > 0 ) - { - GEOS_LOG_RANK_0( "Nonlinear solver parameters:" ); - GEOS_LOG_RANK_0( GEOS_FMT( " Line search action = {}", EnumStrings< LineSearchAction >::toString( m_lineSearchAction ) ) ); - if( m_lineSearchAction != LineSearchAction::None ) - { - GEOS_LOG_RANK_0( GEOS_FMT( " Line search interpolation type = {}", EnumStrings< LineSearchInterpolationType >::toString( m_lineSearchInterpType ) ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Line search maximum number of cuts = {}", m_lineSearchMaxCuts ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Line search cut factor = {}", m_lineSearchCutFactor ) ); - } - GEOS_LOG_RANK_0( GEOS_FMT( " Norm type (flow solver) = {}", EnumStrings< solverBaseKernels::NormType >::toString( m_normType ) ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Minimum residual normalizer = {}", m_minNormalizer ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Convergence tolerance = {}", m_newtonTol ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Maximum iterations = {}", m_maxIterNewton ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Minimum iterations = {}", m_minIterNewton ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Maximum allowed residual norm = {}", m_maxAllowedResidualNorm ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Allow non-converged = {}", m_allowNonConverged ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Time step decrease iterations limit = {}", m_timeStepDecreaseIterLimit ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Time step increase iterations limit = {}", m_timeStepIncreaseIterLimit ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Time step decrease factor = {}", m_timeStepDecreaseFactor ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Time step increase factor = {}", m_timeStepDecreaseFactor ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Time step cut factor = {}", m_timeStepCutFactor ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Maximum time step cuts = {}", m_maxTimeStepCuts ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Maximum sub time steps = {}", m_maxSubSteps ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Maximum number of configuration attempts = {}", m_maxNumConfigurationAttempts ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Coupling type = {}", EnumStrings< CouplingType >::toString( m_couplingType ) ) ); - if( m_couplingType == CouplingType::Sequential ) - { - GEOS_LOG_RANK_0( GEOS_FMT( " Sequential convergence criterion = {}", EnumStrings< SequentialConvergenceCriterion >::toString( m_sequentialConvergenceCriterion ) ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " Subcycling = {}", m_subcyclingOption ) ); - } - } } diff --git a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.hpp b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.hpp index 9f9f93da0fc..2a41b03d7d4 100644 --- a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.hpp +++ b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.hpp @@ -63,7 +63,6 @@ class NonlinearSolverParameters : public dataRepository::Group m_lineSearchInterpType = params.m_lineSearchInterpType; m_lineSearchMaxCuts = params.m_lineSearchMaxCuts; m_lineSearchCutFactor = params.m_lineSearchCutFactor; - m_lineSearchStartingIteration = params.m_lineSearchStartingIteration; m_newtonTol = params.m_newtonTol; m_maxIterNewton = params.m_maxIterNewton; @@ -102,7 +101,6 @@ class NonlinearSolverParameters : public dataRepository::Group static constexpr char const * lineSearchMaxCutsString() { return "lineSearchMaxCuts"; } static constexpr char const * lineSearchCutFactorString() { return "lineSearchCutFactor"; } static constexpr char const * lineSearchInterpolationTypeString() { return "lineSearchInterpolationType"; } - static constexpr char const * lineSearchStartingIterationString() { return "lineSearchStartingIteration"; } static constexpr char const * normTypeString() { return "normType"; } static constexpr char const * minNormalizerString() { return "minNormalizer"; } @@ -167,8 +165,7 @@ class NonlinearSolverParameters : public dataRepository::Group enum class SequentialConvergenceCriterion : integer { ResidualNorm, ///< convergence achieved when the residual drops below a given norm - NumberOfNonlinearIterations, ///< convergence achieved when the subproblems convergence is achieved in less than minNewtonIteration - SolutionIncrements ///< convergence achieved when the solution increments are small enough + NumberOfNonlinearIterations ///< convergence achieved when the subproblems convergence is achieved in less than minNewtonIteration }; /** @@ -249,7 +246,7 @@ class NonlinearSolverParameters : public dataRepository::Group /// Flag to apply a line search. LineSearchAction m_lineSearchAction; - /// Flag to pick the type of line search + /// Flag to pick the type of linesearch LineSearchInterpolationType m_lineSearchInterpType; /// The maximum number of line search cuts to attempt. @@ -258,9 +255,6 @@ class NonlinearSolverParameters : public dataRepository::Group /// The reduction factor for each line search cut. real64 m_lineSearchCutFactor; - /// Iteration when line search starts - integer m_lineSearchStartingIteration; - /// Norm used to check the nonlinear loop convergence solverBaseKernels::NormType m_normType; @@ -343,8 +337,7 @@ ENUM_STRINGS( NonlinearSolverParameters::CouplingType, ENUM_STRINGS( NonlinearSolverParameters::SequentialConvergenceCriterion, "ResidualNorm", - "NumberOfNonlinearIterations", - "SolutionIncrements" ); + "NumberOfNonlinearIterations" ); ENUM_STRINGS( NonlinearSolverParameters::NonlinearAccelerationType, "None", diff --git a/src/coreComponents/physicsSolvers/SolverBase.cpp b/src/coreComponents/physicsSolvers/SolverBase.cpp index 59d5e29a041..5ea5eea1754 100644 --- a/src/coreComponents/physicsSolvers/SolverBase.cpp +++ b/src/coreComponents/physicsSolvers/SolverBase.cpp @@ -268,16 +268,7 @@ bool SolverBase::execute( real64 const time_n, if( dtRemaining > 0.0 ) { nextDt = setNextDt( dtAccepted, domain ); - if( nextDt < dtRemaining ) - { - // better to do two equal steps than one big and one small (even potentially tiny) - if( nextDt * 2 > dtRemaining ) - nextDt = dtRemaining / 2; - } - else - { - nextDt = dtRemaining; - } + nextDt = std::min( nextDt, dtRemaining ); } if( getLogLevel() >= 1 && dtRemaining > 0.0 ) @@ -307,13 +298,15 @@ real64 SolverBase::setNextDt( real64 const & currentDt, integer const iterIncreaseLimit = m_nonlinearSolverParameters.timeStepIncreaseIterLimit(); if( nextDtNewton > currentDt ) { - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( "{}: solver converged in less than {} iterations, time-step required will be increased.", - getName(), iterIncreaseLimit ) ); + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( + "{}: Newton solver converged in less than {} iterations, time-step required will be increased.", + getName(), iterIncreaseLimit )); } else if( nextDtNewton < currentDt ) { - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( "{}: solver converged in more than {} iterations, time-step required will be decreased.", - getName(), iterDecreaseLimit ) ); + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( + "{}: Newton solver converged in more than {} iterations, time-step required will be decreased.", + getName(), iterDecreaseLimit )); } } else // time step size decided based on state change @@ -480,8 +473,6 @@ bool SolverBase::lineSearch( real64 const & time_n, real64 const scaleFactor, real64 & lastResidual ) { - Timer timer( m_timers["line search"] ); - integer const maxNumberLineSearchCuts = m_nonlinearSolverParameters.m_lineSearchMaxCuts; real64 const lineSearchCutFactor = m_nonlinearSolverParameters.m_lineSearchCutFactor; @@ -499,39 +490,55 @@ bool SolverBase::lineSearch( real64 const & time_n, // main loop for the line search. for( integer lineSearchIteration = 0; lineSearchIteration < maxNumberLineSearchCuts; ++lineSearchIteration ) { - // cut the scale factor by half. This means that the scale factors will - // have values of -0.5, -0.25, -0.125, ... - localScaleFactor *= lineSearchCutFactor; - cumulativeScale += localScaleFactor; - - if( !checkSystemSolution( domain, dofManager, solution.values(), localScaleFactor ) ) { - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " Line search {}, solution check failed", lineSearchIteration ) ); - continue; + Timer timer( m_timers["apply solution"] ); + + // cut the scale factor by half. This means that the scale factors will + // have values of -0.5, -0.25, -0.125, ... + localScaleFactor *= lineSearchCutFactor; + cumulativeScale += localScaleFactor; + + if( !checkSystemSolution( domain, dofManager, solution.values(), localScaleFactor ) ) + { + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " Line search {}, solution check failed", lineSearchIteration ) ); + continue; + } + + applySystemSolution( dofManager, solution.values(), localScaleFactor, dt, domain ); } - applySystemSolution( dofManager, solution.values(), localScaleFactor, dt, domain ); + { + Timer timer( m_timers["update state"] ); - // update non-primary variables (constitutive models) - updateState( domain ); + // update non-primary variables (constitutive models) + updateState( domain ); + } - // re-assemble system - localMatrix.zero(); - rhs.zero(); + { + Timer timer( m_timers["assemble"] ); - arrayView1d< real64 > const localRhs = rhs.open(); - assembleSystem( time_n, dt, domain, dofManager, localMatrix, localRhs ); - applyBoundaryConditions( time_n, dt, domain, dofManager, localMatrix, localRhs ); - rhs.close(); + // re-assemble system + localMatrix.zero(); + rhs.zero(); + + arrayView1d< real64 > const localRhs = rhs.open(); + assembleSystem( time_n, dt, domain, dofManager, localMatrix, localRhs ); + applyBoundaryConditions( time_n, dt, domain, dofManager, localMatrix, localRhs ); + rhs.close(); + } if( getLogLevel() >= 1 && logger::internal::rank==0 ) { std::cout << GEOS_FMT( " Line search @ {:0.3f}: ", cumulativeScale ); } - // get residual norm - residualNorm = calculateResidualNorm( time_n, dt, domain, dofManager, rhs.values() ); - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " ( R ) = ( {:4.2e} )", residualNorm ) ); + { + Timer timer( m_timers["convergence check"] ); + + // get residual norm + residualNorm = calculateResidualNorm( time_n, dt, domain, dofManager, rhs.values() ); + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " ( R ) = ( {:4.2e} )", residualNorm ) ); + } // if the residual norm is less than the last residual, we can proceed to the // solution step @@ -558,8 +565,6 @@ bool SolverBase::lineSearchWithParabolicInterpolation( real64 const & time_n, real64 & lastResidual, real64 & residualNormT ) { - Timer timer( m_timers["line search"] ); - bool lineSearchSuccess = true; integer const maxNumberLineSearchCuts = m_nonlinearSolverParameters.m_lineSearchMaxCuts; @@ -581,55 +586,70 @@ bool SolverBase::lineSearchWithParabolicInterpolation( real64 const & time_n, while( residualNormT >= (1.0 - alpha*localScaleFactor)*residualNorm0 ) { - real64 const previousLocalScaleFactor = localScaleFactor; - // Apply the three point parabolic model - if( lineSearchIteration == 0 ) { - localScaleFactor *= sigma1; - } - else - { - localScaleFactor = interpolation::parabolicInterpolationThreePoints( lamc, lamm, ff0, ffT, ffm ); - } + Timer timer( m_timers["apply solution"] ); - // Update x; keep the books on lambda - real64 const deltaLocalScaleFactor = ( localScaleFactor - previousLocalScaleFactor ); - cumulativeScale += deltaLocalScaleFactor; + real64 const previousLocalScaleFactor = localScaleFactor; + // Apply the three point parabolic model + if( lineSearchIteration == 0 ) + { + localScaleFactor *= sigma1; + } + else + { + localScaleFactor = interpolation::parabolicInterpolationThreePoints( lamc, lamm, ff0, ffT, ffm ); + } - if( !checkSystemSolution( domain, dofManager, solution.values(), deltaLocalScaleFactor ) ) - { - GEOS_LOG_LEVEL_RANK_0( 1, " Line search " << lineSearchIteration << ", solution check failed" ); - continue; + // Update x; keep the books on lambda + real64 const deltaLocalScaleFactor = ( localScaleFactor - previousLocalScaleFactor ); + cumulativeScale += deltaLocalScaleFactor; + + if( !checkSystemSolution( domain, dofManager, solution.values(), deltaLocalScaleFactor ) ) + { + GEOS_LOG_LEVEL_RANK_0( 1, " Line search " << lineSearchIteration << ", solution check failed" ); + continue; + } + + applySystemSolution( dofManager, solution.values(), deltaLocalScaleFactor, dt, domain ); } - applySystemSolution( dofManager, solution.values(), deltaLocalScaleFactor, dt, domain ); + { + Timer timer( m_timers["update state"] ); - updateState( domain ); + updateState( domain ); + } lamm = lamc; lamc = localScaleFactor; // Keep the books on the function norms - // re-assemble system - // TODO: add a flag to avoid a completely useless Jacobian computation: rhs is enough - localMatrix.zero(); - rhs.zero(); + { + Timer timer( m_timers["assemble"] ); - arrayView1d< real64 > const localRhs = rhs.open(); - assembleSystem( time_n, dt, domain, dofManager, localMatrix, localRhs ); - applyBoundaryConditions( time_n, dt, domain, dofManager, localMatrix, localRhs ); - rhs.close(); + // re-assemble system + // TODO: add a flag to avoid a completely useless Jacobian computation: rhs is enough + localMatrix.zero(); + rhs.zero(); + + arrayView1d< real64 > const localRhs = rhs.open(); + assembleSystem( time_n, dt, domain, dofManager, localMatrix, localRhs ); + applyBoundaryConditions( time_n, dt, domain, dofManager, localMatrix, localRhs ); + rhs.close(); + } if( getLogLevel() >= 1 && logger::internal::rank==0 ) { std::cout << GEOS_FMT( " Line search @ {:0.3f}: ", cumulativeScale ); } - // get residual norm - residualNormT = calculateResidualNorm( time_n, dt, domain, dofManager, rhs.values() ); - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " ( R ) = ( {:4.2e} )", residualNormT ) ); + { + Timer timer( m_timers["convergence check"] ); + // get residual norm + residualNormT = calculateResidualNorm( time_n, dt, domain, dofManager, rhs.values() ); + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " ( R ) = ( {:4.2e} )", residualNormT ) ); + } ffm = ffT; ffT = residualNormT*residualNormT; lineSearchIteration += 1; @@ -875,6 +895,13 @@ bool SolverBase::solveNonlinearSystem( real64 const & time_n, GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " ( R ) = ( {:4.2e} )", residualNorm ) ); } + if( newtonIter > 0 ) + { + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " Last LinSolve(iter,res) = ( {:3}, {:4.2e} )", + m_linearSolverResult.numIterations, + m_linearSolverResult.residualReduction ) ); + } + // if the residual norm is less than the Newton tolerance we denote that we have // converged and break from the Newton loop immediately. if( residualNorm < newtonTol && newtonIter >= minNewtonIter ) @@ -897,7 +924,7 @@ bool SolverBase::solveNonlinearSystem( real64 const & time_n, // do line search in case residual has increased if( m_nonlinearSolverParameters.m_lineSearchAction != NonlinearSolverParameters::LineSearchAction::None - && residualNorm > lastResidual && newtonIter >= m_nonlinearSolverParameters.m_lineSearchStartingIteration ) + && residualNorm > lastResidual ) { bool lineSearchSuccess = false; if( m_nonlinearSolverParameters.m_lineSearchInterpType == NonlinearSolverParameters::LineSearchInterpolationType::Linear ) @@ -1219,10 +1246,6 @@ void SolverBase::solveLinearSystem( DofManager const & dofManager, m_linearSolverResult = solver->result(); } - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " Last LinSolve(iter,res) = ( {:3}, {:4.2e} )", - m_linearSolverResult.numIterations, - m_linearSolverResult.residualReduction ) ); - if( params.stopIfError ) { GEOS_ERROR_IF( m_linearSolverResult.breakdown(), getDataContext() << ": Linear solution breakdown -> simulation STOP" ); @@ -1347,18 +1370,6 @@ R1Tensor const SolverBase::gravityVector() const return rval; } -bool SolverBase::checkSequentialSolutionIncrements( DomainPartition & GEOS_UNUSED_PARAM( domain ) ) const -{ - // default behavior - assume converged - return true; -} - -void SolverBase::saveSequentialIterationState( DomainPartition & GEOS_UNUSED_PARAM( domain ) ) const -{ - // up to specific solver to save what is needed - GEOS_ERROR( "Call to SolverBase::saveSequentialIterationState. Method should be overloaded by the solver" ); -} - #if defined(GEOSX_USE_PYGEOSX) PyTypeObject * SolverBase::getPythonType() const { return python::getPySolverType(); } diff --git a/src/coreComponents/physicsSolvers/SolverBase.hpp b/src/coreComponents/physicsSolvers/SolverBase.hpp index b3390f828e6..f6174cd9b57 100644 --- a/src/coreComponents/physicsSolvers/SolverBase.hpp +++ b/src/coreComponents/physicsSolvers/SolverBase.hpp @@ -627,10 +627,6 @@ class SolverBase : public ExecutableGroup */ R1Tensor const gravityVector() const; - virtual bool checkSequentialSolutionIncrements( DomainPartition & domain ) const; - - virtual void saveSequentialIterationState( DomainPartition & domain ) const; - /** * @brief accessor for the linear solver parameters. * @return the linear solver parameter list diff --git a/src/coreComponents/physicsSolvers/contact/LagrangianContactSolver.cpp b/src/coreComponents/physicsSolvers/contact/LagrangianContactSolver.cpp index 7d3717e570a..9d81e6801ab 100644 --- a/src/coreComponents/physicsSolvers/contact/LagrangianContactSolver.cpp +++ b/src/coreComponents/physicsSolvers/contact/LagrangianContactSolver.cpp @@ -1741,8 +1741,6 @@ void LagrangianContactSolver::applySystemSolution( DofManager const & dofManager void LagrangianContactSolver::updateState( DomainPartition & domain ) { - GEOS_MARK_FUNCTION; - computeFaceDisplacementJump( domain ); } diff --git a/src/coreComponents/physicsSolvers/contact/SolidMechanicsEmbeddedFractures.cpp b/src/coreComponents/physicsSolvers/contact/SolidMechanicsEmbeddedFractures.cpp index 98ef126ae4c..54aac882187 100644 --- a/src/coreComponents/physicsSolvers/contact/SolidMechanicsEmbeddedFractures.cpp +++ b/src/coreComponents/physicsSolvers/contact/SolidMechanicsEmbeddedFractures.cpp @@ -731,7 +731,6 @@ void SolidMechanicsEmbeddedFractures::updateJump( DofManager const & dofManager, void SolidMechanicsEmbeddedFractures::updateState( DomainPartition & domain ) { - GEOS_MARK_FUNCTION; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, MeshLevel & mesh, diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp index b1a01eec570..b20d1018c4f 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.cpp @@ -150,11 +150,6 @@ CompositionalMultiphaseBase::CompositionalMultiphaseBase( const string & name, setApplyDefaultValue( isothermalCompositionalMultiphaseBaseKernels::minDensForDivision ). setDescription( "Minimum allowed global component density" ); - this->registerWrapper( viewKeyStruct::maxSequentialCompDensChangeString(), &m_maxSequentialCompDensChange ). - setSizedFromParent( 0 ). - setInputFlag( InputFlags::OPTIONAL ). - setApplyDefaultValue( 1.0 ). - setDescription( "Maximum (absolute) component density change in a sequential iteration, used for outer loop convergence check" ); } void CompositionalMultiphaseBase::postProcessInput() @@ -326,6 +321,26 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ); MultiFluidBase const & fluid = getConstitutiveModel< MultiFluidBase >( subRegion, fluidName ); + subRegion.registerField< pressure >( getName() ); + subRegion.registerField< pressure_n >( getName() ); + subRegion.registerField< initialPressure >( getName() ); + subRegion.registerField< deltaPressure >( getName() ); // for reporting/stats purposes + subRegion.registerField< bcPressure >( getName() ); // needed for the application of boundary conditions + if( m_isFixedStressPoromechanicsUpdate ) + { + subRegion.registerField< pressure_k >( getName() ); // needed for the fixed-stress porosity update + } + + // these fields are always registered for the evaluation of the fluid properties + subRegion.registerField< temperature >( getName() ); + subRegion.registerField< temperature_n >( getName() ); + subRegion.registerField< initialTemperature >( getName() ); + subRegion.registerField< bcTemperature >( getName() ); // needed for the application of boundary conditions + if( m_isFixedStressPoromechanicsUpdate ) + { + subRegion.registerField< temperature_k >( getName() ); // needed for the fixed-stress porosity update + } + subRegion.registerField< pressureScalingFactor >( getName() ); subRegion.registerField< temperatureScalingFactor >( getName() ); subRegion.registerField< globalCompDensityScalingFactor >( getName() ); @@ -338,12 +353,6 @@ void CompositionalMultiphaseBase::registerDataOnMesh( Group & meshBodies ) reference().resizeDimension< 1 >( m_numComponents ); subRegion.registerField< globalCompDensity_n >( getName() ). reference().resizeDimension< 1 >( m_numComponents ); - if( m_isFixedStressPoromechanicsUpdate ) - { - subRegion.registerField< globalCompDensity_k >( getName() ). - setDimLabels( 1, fluid.componentNames() ). - reference().resizeDimension< 1 >( m_numComponents ); - } subRegion.registerField< globalCompFraction >( getName() ). setDimLabels( 1, fluid.componentNames() ). @@ -623,6 +632,8 @@ real64 CompositionalMultiphaseBase::updatePhaseVolumeFraction( ObjectManagerBase dataGroup, fluid ); + maxDeltaPhaseVolFrac = MpiWrapper::max( maxDeltaPhaseVolFrac ); + return maxDeltaPhaseVolFrac; } @@ -1243,6 +1254,14 @@ CompositionalMultiphaseBase::implicitStepSetup( real64 const & GEOS_UNUSED_PARAM [&]( localIndex const, auto & subRegion ) { + arrayView1d< real64 const > const & pres = + subRegion.template getField< fields::flow::pressure >(); + arrayView1d< real64 const > const & initPres = + subRegion.template getField< fields::flow::initialPressure >(); + arrayView1d< real64 > const & deltaPres = + subRegion.template getField< fields::flow::deltaPressure >(); + isothermalCompositionalMultiphaseBaseKernels::StatisticsKernel:: + saveDeltaPressure< parallelDevicePolicy<> >( subRegion.size(), pres, initPres, deltaPres ); saveConvergedState( subRegion ); // update porosity, permeability @@ -2295,12 +2314,6 @@ void CompositionalMultiphaseBase::implicitStepComplete( real64 const & time, [&]( localIndex const, ElementSubRegionBase & subRegion ) { - // update deltaPressure - arrayView1d< real64 const > const pres = subRegion.getField< fields::flow::pressure >(); - arrayView1d< real64 const > const initPres = subRegion.getField< fields::flow::initialPressure >(); - arrayView1d< real64 > const deltaPres = subRegion.getField< fields::flow::deltaPressure >(); - isothermalCompositionalMultiphaseBaseKernels::StatisticsKernel:: - saveDeltaPressure< parallelDevicePolicy<> >( subRegion.size(), pres, initPres, deltaPres ); // Step 2: save the converged fluid state string const & fluidName = subRegion.getReference< string >( viewKeyStruct::fluidNamesString() ); @@ -2385,22 +2398,21 @@ void CompositionalMultiphaseBase::saveConvergedState( ElementSubRegionBase & sub arrayView2d< real64, compflow::USD_COMP > const & compDens_n = subRegion.template getField< fields::flow::globalCompDensity_n >(); compDens_n.setValues< parallelDevicePolicy<> >( compDens ); - if( m_isFixedStressPoromechanicsUpdate ) - { - arrayView2d< real64, compflow::USD_COMP > const & compDens_k = - subRegion.template getField< fields::flow::globalCompDensity_k >(); - compDens_k.setValues< parallelDevicePolicy<> >( compDens ); - } } -void CompositionalMultiphaseBase::saveSequentialIterationState( DomainPartition & domain ) const +void CompositionalMultiphaseBase::saveIterationState( DomainPartition & domain ) const { - FlowSolverBase::saveSequentialIterationState( domain ); + FlowSolverBase::saveIterationState( domain ); } -void CompositionalMultiphaseBase::saveSequentialIterationState( ElementSubRegionBase & subRegion ) const +void CompositionalMultiphaseBase::saveIterationState( ElementSubRegionBase & subRegion ) const { - FlowSolverBase::saveSequentialIterationState( subRegion ); + FlowSolverBase::saveIterationState( subRegion ); + + if( !subRegion.hasField< fields::flow::globalCompDensity_k >() ) + { + return; + } arrayView2d< real64 const, compflow::USD_COMP > const compDens = subRegion.template getField< fields::flow::globalCompDensity >(); arrayView2d< real64, compflow::USD_COMP > const compDens_k = subRegion.template getField< fields::flow::globalCompDensity_k >(); @@ -2410,8 +2422,6 @@ void CompositionalMultiphaseBase::saveSequentialIterationState( ElementSubRegion void CompositionalMultiphaseBase::updateState( DomainPartition & domain ) { - GEOS_MARK_FUNCTION; - real64 maxDeltaPhaseVolFrac = 0.0; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -2434,65 +2444,13 @@ void CompositionalMultiphaseBase::updateState( DomainPartition & domain ) } ); } ); - maxDeltaPhaseVolFrac = MpiWrapper::max( maxDeltaPhaseVolFrac ); - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " {}: Max phase volume fraction change = {}", getName(), fmt::format( "{:.{}f}", maxDeltaPhaseVolFrac, 4 ) ) ); } -bool CompositionalMultiphaseBase::checkSequentialSolutionIncrements( DomainPartition & domain ) const -{ - bool isConverged = FlowSolverBase::checkSequentialSolutionIncrements( domain ); - - integer const numComp = m_numComponents; - - real64 maxCompDensChange = 0.0; - forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, - MeshLevel & mesh, - arrayView1d< string const > const & regionNames ) - { - mesh.getElemManager().forElementSubRegions( regionNames, - [&]( localIndex const, - ElementSubRegionBase & subRegion ) - { - arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); - - arrayView2d< real64 const, compflow::USD_COMP > - const compDens = subRegion.getField< fields::flow::globalCompDensity >(); - arrayView2d< real64 const, compflow::USD_COMP > - const compDens_k = subRegion.getField< fields::flow::globalCompDensity_k >(); - - RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxCompDensChange( 0.0 ); - - forAll< parallelDevicePolicy<> >( subRegion.size(), [=] - GEOS_HOST_DEVICE ( localIndex - const ei ) - { - if( ghostRank[ei] < 0 ) - { - for( integer ic = 0; ic < numComp; ++ic ) - { - subRegionMaxCompDensChange.max( LvArray::math::abs( compDens[ei][ic] - compDens_k[ei][ic] ) ); - } - } - } ); - - maxCompDensChange = LvArray::math::max( maxCompDensChange, subRegionMaxCompDensChange.get() ); - } ); - } ); - - maxCompDensChange = MpiWrapper::max( maxCompDensChange ); - - string const unit = m_useMass ? "kg/m3" : "mol/m3"; - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " {}: Max component density change during outer iteration: {} {}", - getName(), fmt::format( "{:.{}f}", maxCompDensChange, 3 ), unit ) ); - - return isConverged && (maxCompDensChange < m_maxSequentialCompDensChange); -} - real64 CompositionalMultiphaseBase::setNextDt( const geos::real64 & currentDt, geos::DomainPartition & domain ) { - if( m_targetFlowCFL < 0 ) + if( m_targetFlowCFL<0 ) return SolverBase::setNextDt( currentDt, domain ); else return setNextDtBasedOnCFL( currentDt, domain ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp index 21e16c269d2..3c9c383aee6 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseBase.hpp @@ -153,7 +153,9 @@ class CompositionalMultiphaseBase : public FlowSolverBase virtual void saveConvergedState( ElementSubRegionBase & subRegion ) const override final; - virtual void saveSequentialIterationState( DomainPartition & domain ) const override final; + virtual void saveIterationState( DomainPartition & domain ) const override final; + + virtual void saveIterationState( ElementSubRegionBase & subRegion ) const override final; virtual void updateState( DomainPartition & domain ) override final; @@ -254,7 +256,6 @@ class CompositionalMultiphaseBase : public FlowSolverBase static constexpr char const * useTotalMassEquationString() { return "useTotalMassEquation"; } static constexpr char const * useSimpleAccumulationString() { return "useSimpleAccumulation"; } static constexpr char const * minCompDensString() { return "minCompDens"; } - static constexpr char const * maxSequentialCompDensChangeString() { return "maxSequentialCompDensChange"; } }; @@ -377,8 +378,6 @@ class CompositionalMultiphaseBase : public FlowSolverBase integer useTotalMassEquation() const { return m_useTotalMassEquation; } - virtual bool checkSequentialSolutionIncrements( DomainPartition & domain ) const override; - protected: virtual void postProcessInput() override; @@ -417,8 +416,6 @@ class CompositionalMultiphaseBase : public FlowSolverBase string const fieldKey, string const boundaryFieldKey ) const; - virtual void saveSequentialIterationState( ElementSubRegionBase & subRegion ) const override final; - /// the max number of fluid phases integer m_numPhases; @@ -482,9 +479,6 @@ class CompositionalMultiphaseBase : public FlowSolverBase /// name of the fluid constitutive model used as a reference for component/phase description string m_referenceFluidModelName; - /// maximum (absolute) component density change in a sequential iteration - real64 m_maxSequentialCompDensChange; - /// the targeted CFL for timestep real64 m_targetFlowCFL; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp index 137a760069d..5f7bf339c4b 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/CompositionalMultiphaseStatistics.cpp @@ -232,10 +232,10 @@ void CompositionalMultiphaseStatistics::computeRegionStatistics( real64 const ti arrayView1d< integer const > const elemGhostRank = subRegion.ghostRank(); arrayView1d< real64 const > const volume = subRegion.getElementVolume(); arrayView1d< real64 const > const pres = subRegion.getField< fields::flow::pressure >(); + arrayView1d< real64 > const deltaPres = subRegion.getField< fields::flow::deltaPressure >(); arrayView1d< real64 const > const temp = subRegion.getField< fields::flow::temperature >(); arrayView2d< real64 const, compflow::USD_PHASE > const phaseVolFrac = subRegion.getField< fields::flow::phaseVolumeFraction >(); - arrayView1d< real64 const > const deltaPres = subRegion.getField< fields::flow::deltaPressure >(); Group const & constitutiveModels = subRegion.getGroup( ElementSubRegionBase::groupKeyStruct::constitutiveModelsString() ); diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp index 26aec0a2c1a..62e21cd33f3 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.cpp @@ -121,28 +121,16 @@ FlowSolverBase::FlowSolverBase( string const & name, setInputFlag( InputFlags::OPTIONAL ). setDescription( "Flag indicating whether the problem is thermal or not." ); - this->registerWrapper( viewKeyStruct::allowNegativePressureString(), &m_allowNegativePressure ). - setApplyDefaultValue( 1 ). // negative pressure is allowed by default - setInputFlag( InputFlags::OPTIONAL ). - setDescription( "Flag indicating if negative pressure is allowed" ); - this->registerWrapper( viewKeyStruct::maxAbsolutePresChangeString(), &m_maxAbsolutePresChange ). setSizedFromParent( 0 ). setInputFlag( InputFlags::OPTIONAL ). setApplyDefaultValue( -1.0 ). // disabled by default setDescription( "Maximum (absolute) pressure change in a Newton iteration" ); - this->registerWrapper( viewKeyStruct::maxSequentialPresChangeString(), &m_maxSequentialPresChange ). - setSizedFromParent( 0 ). - setInputFlag( InputFlags::OPTIONAL ). - setApplyDefaultValue( 1e5 ). // 0.1 bar = 1e5 Pa - setDescription( "Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check" ); - - this->registerWrapper( viewKeyStruct::maxSequentialTempChangeString(), &m_maxSequentialTempChange ). - setSizedFromParent( 0 ). + this->registerWrapper( viewKeyStruct::allowNegativePressureString(), &m_allowNegativePressure ). + setApplyDefaultValue( 1 ). // negative pressure is allowed by default setInputFlag( InputFlags::OPTIONAL ). - setApplyDefaultValue( 0.1 ). - setDescription( "Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check" ); + setDescription( "Flag indicating if negative pressure is allowed" ); // allow the user to select a norm getNonlinearSolverParameters().getWrapper< solverBaseKernels::NormType >( NonlinearSolverParameters::viewKeysStruct::normTypeString() ).setInputFlag( InputFlags::OPTIONAL ); @@ -166,25 +154,6 @@ void FlowSolverBase::registerDataOnMesh( Group & meshBodies ) subRegion.registerField< fields::flow::gravityCoefficient >( getName() ). setApplyDefaultValue( 0.0 ); subRegion.registerField< fields::flow::netToGross >( getName() ); - - subRegion.registerField< fields::flow::pressure >( getName() ); - subRegion.registerField< fields::flow::pressure_n >( getName() ); - subRegion.registerField< fields::flow::initialPressure >( getName() ); - subRegion.registerField< fields::flow::deltaPressure >( getName() ); // for reporting/stats purposes - subRegion.registerField< fields::flow::bcPressure >( getName() ); // needed for the application of boundary conditions - if( m_isFixedStressPoromechanicsUpdate ) - { - subRegion.registerField< fields::flow::pressure_k >( getName() ); // needed for the fixed-stress porosity update - } - - subRegion.registerField< fields::flow::temperature >( getName() ); - subRegion.registerField< fields::flow::temperature_n >( getName() ); - subRegion.registerField< fields::flow::initialTemperature >( getName() ); - subRegion.registerField< fields::flow::bcTemperature >( getName() ); // needed for the application of boundary conditions - if( m_isFixedStressPoromechanicsUpdate ) - { - subRegion.registerField< fields::flow::temperature_k >( getName() ); // needed for the fixed-stress porosity update - } } ); elemManager.forElementSubRegionsComplete< SurfaceElementSubRegion >( [&]( localIndex const, @@ -252,9 +221,10 @@ void FlowSolverBase::saveConvergedState( ElementSubRegionBase & subRegion ) cons } } -void FlowSolverBase::saveSequentialIterationState( ElementSubRegionBase & subRegion ) const +void FlowSolverBase::saveIterationState( ElementSubRegionBase & subRegion ) const { - GEOS_ASSERT( m_isFixedStressPoromechanicsUpdate ); + if( !m_isFixedStressPoromechanicsUpdate ) + return; arrayView1d< real64 const > const pres = subRegion.template getField< fields::flow::pressure >(); arrayView1d< real64 const > const temp = subRegion.template getField< fields::flow::temperature >(); @@ -264,7 +234,7 @@ void FlowSolverBase::saveSequentialIterationState( ElementSubRegionBase & subReg temp_k.setValues< parallelDevicePolicy<> >( temp ); } -void FlowSolverBase::saveSequentialIterationState( DomainPartition & domain ) const +void FlowSolverBase::saveIterationState( DomainPartition & domain ) const { forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, @@ -274,7 +244,7 @@ void FlowSolverBase::saveSequentialIterationState( DomainPartition & domain ) co [&]( localIndex const, ElementSubRegionBase & subRegion ) { - saveSequentialIterationState( subRegion ); + saveIterationState( subRegion ); } ); } ); } @@ -785,54 +755,4 @@ void FlowSolverBase::updateStencilWeights( DomainPartition & domain ) const } ); } -bool FlowSolverBase::checkSequentialSolutionIncrements( DomainPartition & domain ) const -{ - real64 maxPresChange = 0.0; - real64 maxTempChange = 0.0; - forDiscretizationOnMeshTargets ( domain.getMeshBodies(), [&]( string const &, - MeshLevel & mesh, - arrayView1d< string const > const & regionNames ) - { - mesh.getElemManager().forElementSubRegions ( regionNames, - [&]( localIndex const, - ElementSubRegionBase & subRegion ) - { - arrayView1d< integer const > const ghostRank = subRegion.ghostRank(); - - arrayView1d< real64 const > const pres = subRegion.getField< fields::flow::pressure >(); - arrayView1d< real64 const > const pres_k = subRegion.getField< fields::flow::pressure_k >(); - arrayView1d< real64 const > const temp = subRegion.getField< fields::flow::temperature >(); - arrayView1d< real64 const > const temp_k = subRegion.getField< fields::flow::temperature_k >(); - - RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxPresChange( 0.0 ); - RAJA::ReduceMax< parallelDeviceReduce, real64 > subRegionMaxTempChange( 0.0 ); - - forAll< parallelDevicePolicy<> >( subRegion.size(), [=] GEOS_HOST_DEVICE ( localIndex const ei ) - { - if( ghostRank[ei] < 0 ) - { - subRegionMaxPresChange.max( LvArray::math::abs( pres[ei] - pres_k[ei] ) ); - subRegionMaxTempChange.max( LvArray::math::abs( temp[ei] - temp_k[ei] ) ); - } - } ); - - maxPresChange = LvArray::math::max( maxPresChange, subRegionMaxPresChange.get() ); - maxTempChange = LvArray::math::max( maxTempChange, subRegionMaxTempChange.get() ); - } ); - } ); - - maxPresChange = MpiWrapper::max( maxPresChange ); - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " {}: Max pressure change during outer iteration: {} Pa", - getName(), fmt::format( "{:.{}f}", maxPresChange, 3 ) ) ); - - if( m_isThermal ) - { - maxTempChange = MpiWrapper::max( maxTempChange ); - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " {}: Max temperature change during outer iteration: {} K", - getName(), fmt::format( "{:.{}f}", maxTempChange, 3 ) ) ); - } - - return (maxPresChange < m_maxSequentialPresChange) && (maxTempChange < m_maxSequentialTempChange); -} - } // namespace geos diff --git a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp index 0dac0799c6b..8fcb9d89522 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/FlowSolverBase.hpp @@ -73,8 +73,6 @@ class FlowSolverBase : public SolverBase static constexpr char const * solidInternalEnergyNamesString() { return "solidInternalEnergyNames"; } static constexpr char const * allowNegativePressureString() { return "allowNegativePressure"; } static constexpr char const * maxAbsolutePresChangeString() { return "maxAbsolutePressureChange"; } - static constexpr char const * maxSequentialPresChangeString() { return "maxSequentialPressureChange"; } - static constexpr char const * maxSequentialTempChangeString() { return "maxSequentialTemperatureChange"; } }; /** @@ -101,7 +99,7 @@ class FlowSolverBase : public SolverBase * @brief Utility function to save the iteration state (useful for sequential simulations) * @param[in] domain the domain partition */ - virtual void saveSequentialIterationState( DomainPartition & domain ) const override; + virtual void saveIterationState( DomainPartition & domain ) const; /** * @brief For each equilibrium initial condition, loop over all the target cells and compute the min/max elevation @@ -136,8 +134,6 @@ class FlowSolverBase : public SolverBase */ void allowNegativePressure() { m_allowNegativePressure = 1; } - virtual bool checkSequentialSolutionIncrements( DomainPartition & domain ) const override; - protected: /** @@ -163,7 +159,7 @@ class FlowSolverBase : public SolverBase * @brief Utility function to save the state at the end of a sequential iteration * @param[in] subRegion the element subRegion */ - virtual void saveSequentialIterationState( ElementSubRegionBase & subRegion ) const; + virtual void saveIterationState( ElementSubRegionBase & subRegion ) const; /** * @brief Helper function to compute/report the elements with small pore volumes @@ -189,17 +185,11 @@ class FlowSolverBase : public SolverBase /// enable the fixed stress poromechanics update of porosity bool m_isFixedStressPoromechanicsUpdate; - /// flag if negative pressure is allowed - integer m_allowNegativePressure; - /// maximum (absolute) pressure change in a Newton iteration real64 m_maxAbsolutePresChange; - /// maximum (absolute) pressure change in a sequential iteration - real64 m_maxSequentialPresChange; - - /// maximum (absolute) temperature change in a sequential iteration - real64 m_maxSequentialTempChange; + /// flag if negative pressure is allowed + integer m_allowNegativePressure; private: virtual void setConstitutiveNames( ElementSubRegionBase & subRegion ) const override; diff --git a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp index bbfe022fbf6..d360defde51 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/ReactiveCompositionalMultiphaseOBL.cpp @@ -1334,8 +1334,6 @@ void ReactiveCompositionalMultiphaseOBL::updateOBLOperators( ObjectManagerBase & void ReactiveCompositionalMultiphaseOBL::updateState( DomainPartition & domain ) { - GEOS_MARK_FUNCTION; - forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, arrayView1d< string const > const & regionNames ) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp index 1b344dc0130..c94e705ba3e 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/SinglePhaseBase.cpp @@ -80,8 +80,27 @@ void SinglePhaseBase::registerDataOnMesh( Group & meshBodies ) [&]( localIndex const, ElementSubRegionBase & subRegion ) { + subRegion.registerField< pressure >( getName() ); + subRegion.registerField< pressure_n >( getName() ); + subRegion.registerField< initialPressure >( getName() ); + subRegion.registerField< deltaPressure >( getName() ); // for reporting/stats purposes + subRegion.registerField< bcPressure >( getName() ); // needed for the application of boundary conditions + if( m_isFixedStressPoromechanicsUpdate ) + { + subRegion.registerField< pressure_k >( getName() ); // needed for the fixed-stress porosity update + } + subRegion.registerField< deltaVolume >( getName() ); + subRegion.registerField< temperature >( getName() ); + subRegion.registerField< temperature_n >( getName() ); + subRegion.registerField< initialTemperature >( getName() ); + subRegion.registerField< bcTemperature >( getName() ); // needed for the application of boundary conditions + if( m_isFixedStressPoromechanicsUpdate ) + { + subRegion.registerField< temperature_k >( getName() ); // needed for the fixed-stress porosity update + } + subRegion.registerField< mobility >( getName() ); subRegion.registerField< dMobility_dPressure >( getName() ); @@ -615,6 +634,12 @@ void SinglePhaseBase::implicitStepSetup( real64 const & GEOS_UNUSED_PARAM( time_ mesh.getElemManager().forElementSubRegions< CellElementSubRegion, SurfaceElementSubRegion >( regionNames, [&]( localIndex const, auto & subRegion ) { + arrayView1d< real64 const > const & pres = subRegion.template getField< fields::flow::pressure >(); + arrayView1d< real64 const > const & initPres = subRegion.template getField< fields::flow::initialPressure >(); + arrayView1d< real64 > const & deltaPres = subRegion.template getField< fields::flow::deltaPressure >(); + + singlePhaseBaseKernels::StatisticsKernel:: + saveDeltaPressure( subRegion.size(), pres, initPres, deltaPres ); saveConvergedState( subRegion ); arrayView1d< real64 > const & dVol = subRegion.template getField< fields::flow::deltaVolume >(); @@ -628,6 +653,7 @@ void SinglePhaseBase::implicitStepSetup( real64 const & GEOS_UNUSED_PARAM( time_ { updateSolidInternalEnergyModel( subRegion ); updateThermalConductivity( subRegion ); + } } ); @@ -654,6 +680,9 @@ void SinglePhaseBase::implicitStepSetup( real64 const & GEOS_UNUSED_PARAM( time_ } ); } ); + + + } void SinglePhaseBase::implicitStepComplete( real64 const & time, @@ -673,13 +702,6 @@ void SinglePhaseBase::implicitStepComplete( real64 const & time, mesh.getElemManager().forElementSubRegions( regionNames, [&]( localIndex const, ElementSubRegionBase & subRegion ) { - // update deltaPressure - arrayView1d< real64 const > const pres = subRegion.getField< fields::flow::pressure >(); - arrayView1d< real64 const > const initPres = subRegion.getField< fields::flow::initialPressure >(); - arrayView1d< real64 > const deltaPres = subRegion.getField< fields::flow::deltaPressure >(); - singlePhaseBaseKernels::StatisticsKernel:: - saveDeltaPressure( subRegion.size(), pres, initPres, deltaPres ); - arrayView1d< real64 const > const dVol = subRegion.getField< fields::flow::deltaVolume >(); arrayView1d< real64 > const vol = subRegion.getReference< array1d< real64 > >( CellElementSubRegion::viewKeyStruct::elementVolumeString() ); @@ -1191,8 +1213,8 @@ void SinglePhaseBase::keepFlowVariablesConstantDuringInitStep( real64 const time void SinglePhaseBase::updateState( DomainPartition & domain ) { - GEOS_MARK_FUNCTION; +// set mass fraction flag on fluid models forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, arrayView1d< string const > const & regionNames ) @@ -1213,6 +1235,7 @@ void SinglePhaseBase::updateState( DomainPartition & domain ) void SinglePhaseBase::resetStateToBeginningOfStep( DomainPartition & domain ) { + // set mass fraction flag on fluid models forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, arrayView1d< string const > const & regionNames ) diff --git a/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.cpp b/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.cpp index a25112cd74a..5086f5f2d83 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/wells/WellSolverBase.cpp @@ -196,7 +196,6 @@ void WellSolverBase::assembleSystem( real64 const time, void WellSolverBase::updateState( DomainPartition & domain ) { - GEOS_MARK_FUNCTION; forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, MeshLevel & mesh, diff --git a/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.hpp b/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.hpp index 108dfed9d80..6ffff4efd28 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/CompositionalMultiphaseReservoirAndWells.hpp @@ -106,7 +106,7 @@ class CompositionalMultiphaseReservoirAndWells : public CoupledReservoirAndWells void enableFixedStressPoromechanicsUpdate() { flowSolver()->enableFixedStressPoromechanicsUpdate(); } - virtual void saveSequentialIterationState( DomainPartition & domain ) const override final { flowSolver()->saveSequentialIterationState( domain ); } + void saveIterationState( DomainPartition & domain ) const { flowSolver()->saveIterationState( domain ); } protected: diff --git a/src/coreComponents/physicsSolvers/multiphysics/CoupledSolver.hpp b/src/coreComponents/physicsSolvers/multiphysics/CoupledSolver.hpp index 61b69720a39..ad49c26ea2c 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/CoupledSolver.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/CoupledSolver.hpp @@ -345,24 +345,6 @@ class CoupledSolver : public SolverBase /**@}*/ - virtual bool checkSequentialSolutionIncrements( DomainPartition & domain ) const override - { - bool isConverged = true; - forEachArgInTuple( m_solvers, [&]( auto & solver, auto ) - { - isConverged &= solver->checkSequentialSolutionIncrements( domain ); - } ); - return isConverged; - } - - virtual void saveSequentialIterationState( DomainPartition & domain ) const override - { - forEachArgInTuple( m_solvers, [&]( auto & solver, auto ) - { - solver->saveSequentialIterationState( domain ); - } ); - } - protected: /** @@ -399,10 +381,15 @@ class CoupledSolver : public SolverBase { GEOS_MARK_FUNCTION; - // Only build the sparsity pattern if the mesh has changed Timestamp const meshModificationTimestamp = getMeshModificationTimestamp( domain ); + + // First call Coupled Solver setup (important for poromechanics initialization for sequentially coupled) + implicitStepSetup( time_n, dt, domain ); + forEachArgInTuple( m_solvers, [&]( auto & solver, auto ) { + + // Only build the sparsity pattern if the mesh has changed if( meshModificationTimestamp > solver->getSystemSetupTimestamp() ) { solver->setupSystem( domain, @@ -412,9 +399,10 @@ class CoupledSolver : public SolverBase solver->getSystemSolution() ); solver->setSystemSetupTimestamp( meshModificationTimestamp ); } - } ); - implicitStepSetup( time_n, dt, domain ); + solver->implicitStepSetup( time_n, dt, domain ); + + } ); NonlinearSolverParameters & solverParams = getNonlinearSolverParameters(); integer const maxNumberDtCuts = solverParams.m_maxTimeStepCuts; @@ -475,12 +463,14 @@ class CoupledSolver : public SolverBase stepDt, domain ); - // save fields (e.g. pressure and temperature) at the end of this iteration - saveSequentialIterationState( domain ); - if( isConverged ) { - // exit outer loop + // Save Time step statistics for the subsolvers + forEachArgInTuple( m_solvers, [&]( auto & solver, + auto ) + { + solver->getSolverStatistics().saveTimeStepStatistics(); + } ); break; } else @@ -493,12 +483,7 @@ class CoupledSolver : public SolverBase if( isConverged ) { - // Save time step statistics for the subsolvers - forEachArgInTuple( m_solvers, [&]( auto & solver, auto ) - { - solver->getSolverStatistics().saveTimeStepStatistics(); - } ); - // get out of the time loop + // get out of time loop break; } else @@ -509,7 +494,8 @@ class CoupledSolver : public SolverBase // notify the solver statistics counter that this is a time step cut m_solverStatistics.logTimeStepCut(); - forEachArgInTuple( m_solvers, [&]( auto & solver, auto ) + forEachArgInTuple( m_solvers, [&]( auto & solver, + auto ) { solver->getSolverStatistics().logTimeStepCut(); } ); @@ -541,8 +527,7 @@ class CoupledSolver : public SolverBase * @param domain the domain partition * @param solverType the index of the solver withing this coupled solver. */ - virtual void mapSolutionBetweenSolvers( DomainPartition & domain, - integer const solverType ) + virtual void mapSolutionBetweenSolvers( DomainPartition & domain, integer const solverType ) { GEOS_UNUSED_VAR( domain, solverType ); } @@ -550,7 +535,7 @@ class CoupledSolver : public SolverBase bool checkSequentialConvergence( int const & iter, real64 const & time_n, real64 const & dt, - DomainPartition & domain ) + DomainPartition & domain ) const { NonlinearSolverParameters const & params = getNonlinearSolverParameters(); bool isConverged = true; @@ -561,10 +546,9 @@ class CoupledSolver : public SolverBase } else { - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " Iteration {:2}: outer-loop convergence check", iter + 1 ) ); - if( params.sequentialConvergenceCriterion() == NonlinearSolverParameters::SequentialConvergenceCriterion::ResidualNorm ) { + GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " Iteration {:2}: outer-loop convergence check", iter+1 ) ); real64 residualNorm = 0; // loop over all the single-physics solvers @@ -608,7 +592,6 @@ class CoupledSolver : public SolverBase } else if( params.sequentialConvergenceCriterion() == NonlinearSolverParameters::SequentialConvergenceCriterion::NumberOfNonlinearIterations ) { - // TODO also make recursive? forEachArgInTuple( m_solvers, [&]( auto & solver, auto ) { NonlinearSolverParameters const & singlePhysicsParams = solver->getNonlinearSolverParameters(); @@ -618,10 +601,6 @@ class CoupledSolver : public SolverBase } } ); } - else if( params.sequentialConvergenceCriterion() == NonlinearSolverParameters::SequentialConvergenceCriterion::SolutionIncrements ) - { - isConverged = checkSequentialSolutionIncrements( domain ); - } else { GEOS_ERROR( getDataContext() << ": Invalid sequential convergence criterion." ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.cpp b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.cpp index 1d52bfee359..236581534fc 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.cpp @@ -96,10 +96,6 @@ HydrofractureSolver< POROMECHANICS_SOLVER >::HydrofractureSolver( const string & setApplyDefaultValue( 0 ). setInputFlag( InputFlags::OPTIONAL ); - registerWrapper( viewKeyStruct::useQuasiNewtonString(), &m_useQuasiNewton ). - setApplyDefaultValue( 0 ). - setInputFlag( InputFlags::OPTIONAL ); - m_numResolves[0] = 0; // This may need to be different depending on whether poroelasticity is on or not. @@ -179,8 +175,6 @@ void HydrofractureSolver< POROMECHANICS_SOLVER >::postProcessInput() m_surfaceGenerator = &this->getParent().template getGroup< SurfaceGenerator >( m_surfaceGeneratorName ); flowSolver()->allowNegativePressure(); - - GEOS_LOG_RANK_0_IF( m_useQuasiNewton, GEOS_FMT( "{}: activated Quasi-Newton", this->getName())); } template< typename POROMECHANICS_SOLVER > @@ -840,7 +834,6 @@ assembleFluidMassResidualDerivativeWrtDisplacement( DomainPartition const & doma launch< parallelDevicePolicy<> >( subRegion.size(), rankOffset, contactWrapper, - m_useQuasiNewton, elemsToFaces, faceToNodeMap, faceNormal, @@ -860,7 +853,6 @@ assembleFluidMassResidualDerivativeWrtDisplacement( DomainPartition const & doma template< typename POROMECHANICS_SOLVER > void HydrofractureSolver< POROMECHANICS_SOLVER >::updateState( DomainPartition & domain ) { - GEOS_MARK_FUNCTION; Base::updateState( domain ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.hpp b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.hpp index 9ee4adcdd04..5deca2e42e9 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolver.hpp @@ -148,7 +148,6 @@ class HydrofractureSolver : public POROMECHANICS_SOLVER constexpr static char const * isMatrixPoroelasticString() { return "isMatrixPoroelastic"; } - constexpr static char const * useQuasiNewtonString() { return "useQuasiNewton"; } #ifdef GEOSX_USE_SEPARATION_COEFFICIENT constexpr static char const * separationCoeff0String() { return "separationCoeff0"; } @@ -211,8 +210,6 @@ class HydrofractureSolver : public POROMECHANICS_SOLVER integer m_isMatrixPoroelastic; - integer m_useQuasiNewton; // use Quasi-Newton (see https://arxiv.org/abs/2111.00264) - }; diff --git a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolverKernels.hpp b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolverKernels.hpp index fe23b8b491f..1a14d0b49dc 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolverKernels.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/HydrofractureSolverKernels.hpp @@ -205,7 +205,6 @@ struct FluidMassResidualDerivativeAssemblyKernel launch( localIndex const size, globalIndex const rankOffset, CONTACT_WRAPPER const & contactWrapper, - integer const useQuasiNewton, ArrayOfArraysView< localIndex const > const elemsToFaces, ArrayOfArraysView< localIndex const > const faceToNodeMap, arrayView2d< real64 const > const faceNormal, @@ -249,32 +248,29 @@ struct FluidMassResidualDerivativeAssemblyKernel 2 * numNodesPerFace * 3 ); } // - if( useQuasiNewton == 0 ) // when Quasi Newton is not enabled - add flux derivatives - { - localIndex const numColumns = dFluxResidual_dNormalJump.numNonZeros( ei ); - arraySlice1d< localIndex const > const & columns = dFluxResidual_dNormalJump.getColumns( ei ); - arraySlice1d< real64 const > const & values = dFluxResidual_dNormalJump.getEntries( ei ); + localIndex const numColumns = dFluxResidual_dNormalJump.numNonZeros( ei ); + arraySlice1d< localIndex const > const & columns = dFluxResidual_dNormalJump.getColumns( ei ); + arraySlice1d< real64 const > const & values = dFluxResidual_dNormalJump.getEntries( ei ); - for( localIndex kfe2 = 0; kfe2 < numColumns; ++kfe2 ) + for( localIndex kfe2 = 0; kfe2 < numColumns; ++kfe2 ) + { + computeFluxDerivative( kfe2, + numNodesPerFace, + columns, + values, + elemsToFaces, + faceToNodeMap, + dispDofNumber, + Nbar, + nodeDOF, + dRdU ); + + if( rowNumber >= 0 && rowNumber < localMatrix.numRows() ) { - computeFluxDerivative( kfe2, - numNodesPerFace, - columns, - values, - elemsToFaces, - faceToNodeMap, - dispDofNumber, - Nbar, - nodeDOF, - dRdU ); - - if( rowNumber >= 0 && rowNumber < localMatrix.numRows() ) - { - localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic >( rowNumber, - nodeDOF, - dRdU.data(), - 2 * numNodesPerFace * 3 ); - } + localMatrix.addToRowBinarySearchUnsorted< parallelDeviceAtomic >( rowNumber, + nodeDOF, + dRdU.data(), + 2 * numNodesPerFace * 3 ); } } } ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.cpp b/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.cpp index d748a62fb0c..98079dae637 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/MultiphasePoromechanics.cpp @@ -271,8 +271,6 @@ void MultiphasePoromechanics< FLOW_SOLVER >::assembleSystem( real64 const GEOS_U template< typename FLOW_SOLVER > void MultiphasePoromechanics< FLOW_SOLVER >::updateState( DomainPartition & domain ) { - GEOS_MARK_FUNCTION; - real64 maxDeltaPhaseVolFrac = 0.0; this->template forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, MeshLevel & mesh, @@ -292,8 +290,6 @@ void MultiphasePoromechanics< FLOW_SOLVER >::updateState( DomainPartition & doma } ); } ); - maxDeltaPhaseVolFrac = MpiWrapper::max( maxDeltaPhaseVolFrac ); - GEOS_LOG_LEVEL_RANK_0( 1, GEOS_FMT( " {}: Max phase volume fraction change = {}", this->getName(), GEOS_FMT( "{:.{}f}", maxDeltaPhaseVolFrac, 4 ) ) ); } diff --git a/src/coreComponents/physicsSolvers/multiphysics/PoromechanicsSolver.hpp b/src/coreComponents/physicsSolvers/multiphysics/PoromechanicsSolver.hpp index ed7734f4ab1..05eaca5fdef 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/PoromechanicsSolver.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/PoromechanicsSolver.hpp @@ -346,6 +346,9 @@ class PoromechanicsSolver : public CoupledSolver< FLOW_SOLVER, /// After the flow solver if( solverType == static_cast< integer >( SolverType::Flow ) ) { + // save pressure and temperature at the end of this iteration + flowSolver()->saveIterationState( domain ); + this->template forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&]( string const &, MeshLevel & mesh, arrayView1d< string const > const & regionNames ) diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.cpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.cpp index 15d25abcd1c..4ab8faa8214 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanics.cpp @@ -315,8 +315,6 @@ void SinglePhasePoromechanics< FLOW_SOLVER >::createPreconditioner() template< typename FLOW_SOLVER > void SinglePhasePoromechanics< FLOW_SOLVER >::updateState( DomainPartition & domain ) { - GEOS_MARK_FUNCTION; - this->template forDiscretizationOnMeshTargets( domain.getMeshBodies(), [&] ( string const &, MeshLevel & mesh, arrayView1d< string const > const & regionNames ) diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsConformingFractures.cpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsConformingFractures.cpp index 5884bcf05ad..93a32ddb123 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsConformingFractures.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsConformingFractures.cpp @@ -738,7 +738,6 @@ void SinglePhasePoromechanicsConformingFractures:: void SinglePhasePoromechanicsConformingFractures::updateState( DomainPartition & domain ) { - GEOS_MARK_FUNCTION; Base::updateState( domain ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsEmbeddedFractures.cpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsEmbeddedFractures.cpp index 34272cc7a52..a2ea2930021 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsEmbeddedFractures.cpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhasePoromechanicsEmbeddedFractures.cpp @@ -529,8 +529,6 @@ void SinglePhasePoromechanicsEmbeddedFractures::applySystemSolution( DofManager void SinglePhasePoromechanicsEmbeddedFractures::updateState( DomainPartition & domain ) { - GEOS_MARK_FUNCTION; - /// 1. update the reservoir SinglePhasePoromechanics::updateState( domain ); diff --git a/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.hpp b/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.hpp index ef7315a6c95..aca5b35eea0 100644 --- a/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.hpp +++ b/src/coreComponents/physicsSolvers/multiphysics/SinglePhaseReservoirAndWells.hpp @@ -93,7 +93,7 @@ class SinglePhaseReservoirAndWells : public CoupledReservoirAndWellsBase< SINGLE void enableFixedStressPoromechanicsUpdate() { flowSolver()->enableFixedStressPoromechanicsUpdate(); } - virtual void saveSequentialIterationState( DomainPartition & domain ) const override { flowSolver()->saveSequentialIterationState( domain ); } + void saveIterationState( DomainPartition & domain ) const { flowSolver()->saveIterationState( domain ); } protected: diff --git a/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.cpp b/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.cpp index 75818129611..4ba2a40c684 100644 --- a/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.cpp +++ b/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.cpp @@ -645,10 +645,6 @@ void PhaseFieldDamageFEM::applyIrreversibilityConstraint( DofManager const & dof } ); } -void PhaseFieldDamageFEM::saveSequentialIterationState( DomainPartition & GEOS_UNUSED_PARAM( domain ) ) const -{ - // nothing to save yet -} REGISTER_CATALOG_ENTRY( SolverBase, PhaseFieldDamageFEM, string const &, Group * const ) diff --git a/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.hpp b/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.hpp index 6c623e73fe3..5adaa2c23f2 100644 --- a/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.hpp +++ b/src/coreComponents/physicsSolvers/simplePDE/PhaseFieldDamageFEM.hpp @@ -131,8 +131,6 @@ class PhaseFieldDamageFEM : public SolverBase CRSMatrixView< real64, globalIndex const > const & localMatrix, arrayView1d< real64 > const & localRhs ); - virtual void saveSequentialIterationState( DomainPartition & domain ) const override; - enum class TimeIntegrationOption { SteadyState, diff --git a/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp b/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp index 58f8b7489a7..c6a0a2167d9 100644 --- a/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp +++ b/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.cpp @@ -1398,10 +1398,5 @@ void SolidMechanicsLagrangianFEM::enableFixedStressPoromechanicsUpdate() m_isFixedStressPoromechanicsUpdate = true; } -void SolidMechanicsLagrangianFEM::saveSequentialIterationState( DomainPartition & GEOS_UNUSED_PARAM( domain ) ) const -{ - // nothing to save -} - REGISTER_CATALOG_ENTRY( SolverBase, SolidMechanicsLagrangianFEM, string const &, dataRepository::Group * const ) } diff --git a/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.hpp b/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.hpp index af974e111cf..830c1096f46 100644 --- a/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.hpp +++ b/src/coreComponents/physicsSolvers/solidMechanics/SolidMechanicsLagrangianFEM.hpp @@ -227,8 +227,6 @@ class SolidMechanicsLagrangianFEM : public SolverBase void enableFixedStressPoromechanicsUpdate(); - virtual void saveSequentialIterationState( DomainPartition & domain ) const override; - struct viewKeyStruct : SolverBase::viewKeyStruct { static constexpr char const * cflFactorString() { return "cflFactor"; } diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.cpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.cpp index 590cfd0f084..3e0e5743550 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.cpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.cpp @@ -25,7 +25,6 @@ namespace geos { using namespace dataRepository; -using namespace fields; void AcousticElasticWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) { @@ -36,9 +35,9 @@ void AcousticElasticWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) arrayView1d< string const > const & ) { NodeManager & nodeManager = mesh.getNodeManager(); - nodeManager.registerField< acoustoelasticfields::CouplingVectorx >( getName() ); - nodeManager.registerField< acoustoelasticfields::CouplingVectory >( getName() ); - nodeManager.registerField< acoustoelasticfields::CouplingVectorz >( getName() ); + nodeManager.registerField< fields::CouplingVectorx >( getName() ); + nodeManager.registerField< fields::CouplingVectory >( getName() ); + nodeManager.registerField< fields::CouplingVectorz >( getName() ); } ); } @@ -81,13 +80,13 @@ void AcousticElasticWaveEquationSEM::initializePostInitialConditionsPreSubGroups arrayView2d< localIndex const > const faceToRegion = faceManager.elementRegionList(); arrayView2d< localIndex const > const faceToElement = faceManager.elementList(); - arrayView1d< real32 > const couplingVectorx = nodeManager.getField< acoustoelasticfields::CouplingVectorx >(); + arrayView1d< real32 > const couplingVectorx = nodeManager.getField< fields::CouplingVectorx >(); couplingVectorx.zero(); - arrayView1d< real32 > const couplingVectory = nodeManager.getField< acoustoelasticfields::CouplingVectory >(); + arrayView1d< real32 > const couplingVectory = nodeManager.getField< fields::CouplingVectory >(); couplingVectory.zero(); - arrayView1d< real32 > const couplingVectorz = nodeManager.getField< acoustoelasticfields::CouplingVectorz >(); + arrayView1d< real32 > const couplingVectorz = nodeManager.getField< fields::CouplingVectorz >(); couplingVectorz.zero(); elemManager.forElementRegions( m_acousRegions, [&] ( localIndex const regionIndex, ElementRegionBase const & elemRegion ) @@ -138,26 +137,26 @@ real64 AcousticElasticWaveEquationSEM::solverStep( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const acousticMass = nodeManager.getField< acousticfields::AcousticMassVector >(); - arrayView1d< real32 const > const elasticMass = nodeManager.getField< elasticfields::ElasticMassVector >(); - arrayView1d< localIndex const > const acousticFSNodeIndicator = nodeManager.getField< acousticfields::AcousticFreeSurfaceNodeIndicator >(); - arrayView1d< localIndex const > const elasticFSNodeIndicator = nodeManager.getField< elasticfields::ElasticFreeSurfaceNodeIndicator >(); - - arrayView1d< real32 const > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); - arrayView1d< real32 const > const ux_nm1 = nodeManager.getField< elasticfields::Displacementx_nm1 >(); - arrayView1d< real32 const > const uy_nm1 = nodeManager.getField< elasticfields::Displacementy_nm1 >(); - arrayView1d< real32 const > const uz_nm1 = nodeManager.getField< elasticfields::Displacementz_nm1 >(); - arrayView1d< real32 const > const ux_n = nodeManager.getField< elasticfields::Displacementx_n >(); - arrayView1d< real32 const > const uy_n = nodeManager.getField< elasticfields::Displacementy_n >(); - arrayView1d< real32 const > const uz_n = nodeManager.getField< elasticfields::Displacementz_n >(); - arrayView1d< real32 const > const atoex = nodeManager.getField< acoustoelasticfields::CouplingVectorx >(); - arrayView1d< real32 const > const atoey = nodeManager.getField< acoustoelasticfields::CouplingVectory >(); - arrayView1d< real32 const > const atoez = nodeManager.getField< acoustoelasticfields::CouplingVectorz >(); - - arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); + arrayView1d< real32 const > const acousticMass = nodeManager.getField< fields::AcousticMassVector >(); + arrayView1d< real32 const > const elasticMass = nodeManager.getField< fields::ElasticMassVector >(); + arrayView1d< localIndex > const acousticFSNodeIndicator = nodeManager.getField< fields::AcousticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex > const elasticFSNodeIndicator = nodeManager.getField< fields::ElasticFreeSurfaceNodeIndicator >(); + + arrayView1d< real32 const > const p_n = nodeManager.getField< fields::Pressure_n >(); + arrayView1d< real32 const > const ux_nm1 = nodeManager.getField< fields::Displacementx_nm1 >(); + arrayView1d< real32 const > const uy_nm1 = nodeManager.getField< fields::Displacementy_nm1 >(); + arrayView1d< real32 const > const uz_nm1 = nodeManager.getField< fields::Displacementz_nm1 >(); + arrayView1d< real32 const > const ux_n = nodeManager.getField< fields::Displacementx_n >(); + arrayView1d< real32 const > const uy_n = nodeManager.getField< fields::Displacementy_n >(); + arrayView1d< real32 const > const uz_n = nodeManager.getField< fields::Displacementz_n >(); + arrayView1d< real32 const > const atoex = nodeManager.getField< fields::CouplingVectorx >(); + arrayView1d< real32 const > const atoey = nodeManager.getField< fields::CouplingVectory >(); + arrayView1d< real32 const > const atoez = nodeManager.getField< fields::CouplingVectorz >(); + + arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< fields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< fields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< fields::Displacementz_np1 >(); real32 const dt2 = pow( dt, 2 ); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.hpp index ea72af060af..326b248abd8 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticElasticWaveEquationSEM.hpp @@ -23,7 +23,6 @@ #include "physicsSolvers/wavePropagation/ElasticWaveEquationSEM.hpp" #include "physicsSolvers/wavePropagation/AcousticWaveEquationSEM.hpp" #include "physicsSolvers/SolverBase.hpp" -#include "AcoustoElasticFields.hpp" #include namespace geos @@ -180,6 +179,34 @@ class AcousticElasticWaveEquationSEM : public CoupledWaveSolver< AcousticWaveEqu arrayView1d< string const > m_elasRegions; }; +namespace fields +{ + +DECLARE_FIELD( CouplingVectorx, + "couplingVectorx", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Coupling term on x." ); + +DECLARE_FIELD( CouplingVectory, + "couplingVectory", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Coupling term on y." ); + +DECLARE_FIELD( CouplingVectorz, + "couplingVectorz", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Coupling term on z." ); +} + } /* namespace geos */ #endif /* SRC_CORECOMPONENTS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICELASTICWAVEEQUATIONSEM_HPP_ */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticFields.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticFields.hpp deleted file mode 100644 index 903809d893b..00000000000 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticFields.hpp +++ /dev/null @@ -1,203 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2018-2020 TotalEnergies - * Copyright (c) 2019- GEOSX Contributors - * All rights reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - - -/** - * @file AcousticFields.hpp - */ - -#ifndef GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICFIELDS_HPP_ -#define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICFIELDS_HPP_ - -#include "common/DataLayouts.hpp" -#include "mesh/MeshFields.hpp" - - -namespace geos -{ - -namespace fields -{ - -namespace acousticfields -{ - -DECLARE_FIELD( Pressure_nm1, - "pressure_nm1", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Scalar pressure at time n-1." ); - -DECLARE_FIELD( Pressure_n, - "pressure_n", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Scalar pressure at time n." ); - - -DECLARE_FIELD( Pressure_np1, - "pressure_np1", - array1d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "Scalar pressure at time n+1." ); - -DECLARE_FIELD( PressureDoubleDerivative, - "pressureDoubleDerivative", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Double derivative of the pressure for each node to compute the gradient" ); - -DECLARE_FIELD( Velocity_x, - "velocity_x", - array2d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "Velocity in the x-direction." ); - -DECLARE_FIELD( Velocity_y, - "velocity_y", - array2d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "Velocity in the y-direction." ); - -DECLARE_FIELD( Velocity_z, - "velocity_z", - array2d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "Velocity in the z-direction." ); - -DECLARE_FIELD( PartialGradient, - "partialGradient", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Partiel gradient computed during backward propagation" ); - -DECLARE_FIELD( ForcingRHS, - "rhs", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "RHS" ); - -DECLARE_FIELD( AcousticMassVector, - "acousticMassVector", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal of the Mass Matrix." ); - -DECLARE_FIELD( StiffnessVector, - "stiffnessVector", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Stiffness vector contains R_h*Pressure_n." ); - -DECLARE_FIELD( DampingVector, - "dampingVector", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal of the Damping Matrix." ); - -DECLARE_FIELD( AcousticVelocity, - "acousticVelocity", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Medium velocity of the cell" ); - -DECLARE_FIELD( AcousticDensity, - "acousticDensity", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Medium density of the cell" ); - -DECLARE_FIELD( AcousticFreeSurfaceFaceIndicator, - "acousticFreeSurfaceFaceIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Free surface indicator, 1 if a face is on free surface 0 otherwise." ); - -DECLARE_FIELD( AcousticFreeSurfaceNodeIndicator, - "acousticFreeSurfaceNodeIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Free surface indicator, 1 if a node is on free surface 0 otherwise." ); - -DECLARE_FIELD( AuxiliaryVar1PML, - "auxiliaryVar1PML", - array2d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "PML vectorial auxiliary variable 1." ); - -DECLARE_FIELD( AuxiliaryVar2PML, - "auxiliaryVar2PML", - array2d< real32 >, - 0, - NOPLOT, - NO_WRITE, - "PML vectorial auxiliary variable 2." ); - -DECLARE_FIELD( AuxiliaryVar3PML, - "auxiliaryVar3PML", - array1d< real32 >, - 0, - NOPLOT, - NO_WRITE, - "PML scalar auxiliary variable 3." ); - -DECLARE_FIELD( AuxiliaryVar4PML, - "auxiliaryVar4PML", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "PML scalar auxiliary variable 4." ); - -} - -} - -} /* namespace geos */ - -#endif /* GEOS_PHYSICSSOLVERS_WAVEPROPAGATION__HPP_ACOUSTICFIELDS */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.cpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.cpp index 1ede25c9b42..bdc1f623278 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.cpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.cpp @@ -32,6 +32,7 @@ namespace geos using namespace dataRepository; using namespace fields; +//using namespace wavesolverfields; AcousticFirstOrderWaveEquationSEM::AcousticFirstOrderWaveEquationSEM( const std::string & name, Group * const parent ): @@ -93,25 +94,25 @@ void AcousticFirstOrderWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) { NodeManager & nodeManager = mesh.getNodeManager(); - nodeManager.registerField< acousticfields::Pressure_np1, - acousticfields::ForcingRHS, - acousticfields::AcousticMassVector, - acousticfields::DampingVector, - acousticfields::AcousticFreeSurfaceNodeIndicator >( getName() ); + nodeManager.registerField< wavesolverfields::Pressure_np1, + wavesolverfields::ForcingRHS, + wavesolverfields::AcousticMassVector, + wavesolverfields::DampingVector, + wavesolverfields::AcousticFreeSurfaceNodeIndicator >( getName() ); FaceManager & faceManager = mesh.getFaceManager(); - faceManager.registerField< acousticfields::AcousticFreeSurfaceFaceIndicator >( getName() ); + faceManager.registerField< wavesolverfields::AcousticFreeSurfaceFaceIndicator >( getName() ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< CellElementSubRegion >( [&]( CellElementSubRegion & subRegion ) { - subRegion.registerField< acousticfields::AcousticVelocity >( getName() ); - subRegion.registerField< acousticfields::AcousticDensity >( getName() ); + subRegion.registerField< wavesolverfields::AcousticVelocity >( getName() ); + subRegion.registerField< wavesolverfields::AcousticDensity >( getName() ); - subRegion.registerField< acousticfields::Velocity_x >( getName() ); - subRegion.registerField< acousticfields::Velocity_y >( getName() ); - subRegion.registerField< acousticfields::Velocity_z >( getName() ); + subRegion.registerField< wavesolverfields::Velocity_x >( getName() ); + subRegion.registerField< wavesolverfields::Velocity_y >( getName() ); + subRegion.registerField< wavesolverfields::Velocity_z >( getName() ); finiteElement::FiniteElementBase const & fe = subRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); @@ -122,9 +123,9 @@ void AcousticFirstOrderWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) constexpr localIndex numNodesPerElem = FE_TYPE::numNodes; - subRegion.getField< acousticfields::Velocity_x >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< acousticfields::Velocity_y >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< acousticfields::Velocity_z >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< wavesolverfields::Velocity_x >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< wavesolverfields::Velocity_y >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< wavesolverfields::Velocity_z >().resizeDimension< 1 >( numNodesPerElem ); } ); @@ -246,6 +247,28 @@ void AcousticFirstOrderWaveEquationSEM::precomputeSourceAndReceiverTerm( MeshLev } + +void AcousticFirstOrderWaveEquationSEM::addSourceToRightHandSide( integer const & cycleNumber, arrayView1d< real32 > const rhs ) +{ + arrayView2d< localIndex const > const sourceNodeIds = m_sourceNodeIds.toViewConst(); + arrayView2d< real64 const > const sourceConstants = m_sourceConstants.toViewConst(); + arrayView1d< localIndex const > const sourceIsAccessible = m_sourceIsAccessible.toViewConst(); + arrayView2d< real32 const > const sourceValue = m_sourceValue.toViewConst(); + + GEOS_THROW_IF( cycleNumber > sourceValue.size( 0 ), getDataContext() << ": Too many steps compared to array size", std::runtime_error ); + forAll< EXEC_POLICY >( sourceConstants.size( 0 ), [=] GEOS_HOST_DEVICE ( localIndex const isrc ) + { + if( sourceIsAccessible[isrc] == 1 ) + { + for( localIndex inode = 0; inode < sourceConstants.size( 1 ); ++inode ) + { + real32 const localIncrement = sourceConstants[isrc][inode] * sourceValue[cycleNumber][isrc]; + RAJA::atomicAdd< ATOMIC_POLICY >( &rhs[sourceNodeIds[isrc][inode]], localIncrement ); + } + } + } ); +} + void AcousticFirstOrderWaveEquationSEM::initializePostInitialConditionsPreSubGroups() { WaveSolverBase::initializePostInitialConditionsPreSubGroups(); @@ -271,23 +294,23 @@ void AcousticFirstOrderWaveEquationSEM::initializePostInitialConditionsPreSubGro ArrayOfArraysView< localIndex const > const facesToNodes = faceManager.nodeList().toViewConst(); // mass matrix to be computed in this function - arrayView1d< real32 > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); + arrayView1d< real32 > const mass = nodeManager.getField< wavesolverfields::AcousticMassVector >(); /// damping matrix to be computed for each dof in the boundary of the mesh - arrayView1d< real32 > const damping = nodeManager.getField< acousticfields::DampingVector >(); + arrayView1d< real32 > const damping = nodeManager.getField< wavesolverfields::DampingVector >(); damping.zero(); mass.zero(); /// get array of indicators: 1 if face is on the free surface; 0 otherwise - arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< acousticfields::AcousticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< wavesolverfields::AcousticFreeSurfaceFaceIndicator >(); mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const, CellElementSubRegion & elementSubRegion ) { arrayView2d< localIndex const, cells::NODE_MAP_USD > const elemsToNodes = elementSubRegion.nodeList(); arrayView2d< localIndex const > const elemsToFaces = elementSubRegion.faceList(); - arrayView1d< real32 const > const velocity = elementSubRegion.getField< acousticfields::AcousticVelocity >(); - arrayView1d< real32 const > const density = elementSubRegion.getField< acousticfields::AcousticDensity >(); + arrayView1d< real32 const > const velocity = elementSubRegion.getField< wavesolverfields::AcousticVelocity >(); + arrayView1d< real32 const > const density = elementSubRegion.getField< wavesolverfields::AcousticDensity >(); finiteElement::FiniteElementBase const & fe = elementSubRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); @@ -330,15 +353,15 @@ void AcousticFirstOrderWaveEquationSEM::applyFreeSurfaceBC( real64 const time, D FaceManager & faceManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getFaceManager(); NodeManager & nodeManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getNodeManager(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< wavesolverfields::Pressure_np1 >(); ArrayOfArraysView< localIndex const > const faceToNodeMap = faceManager.nodeList().toViewConst(); /// array of indicators: 1 if a face is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< acousticfields::AcousticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< wavesolverfields::AcousticFreeSurfaceFaceIndicator >(); /// array of indicators: 1 if a node is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< acousticfields::AcousticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< wavesolverfields::AcousticFreeSurfaceNodeIndicator >(); freeSurfaceFaceIndicator.zero(); @@ -432,21 +455,21 @@ real64 AcousticFirstOrderWaveEquationSEM::explicitStepInternal( real64 const & t arrayView2d< wsCoordType const, nodes::REFERENCE_POSITION_USD > const X = nodeManager.getField< fields::referencePosition32 >().toViewConst(); - arrayView1d< real32 const > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); - arrayView1d< real32 const > const damping = nodeManager.getField< acousticfields::DampingVector >(); + arrayView1d< real32 const > const mass = nodeManager.getField< wavesolverfields::AcousticMassVector >(); + arrayView1d< real32 const > const damping = nodeManager.getField< wavesolverfields::DampingVector >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< wavesolverfields::Pressure_np1 >(); - arrayView1d< real32 > const rhs = nodeManager.getField< acousticfields::ForcingRHS >(); + arrayView1d< real32 > const rhs = nodeManager.getField< wavesolverfields::ForcingRHS >(); mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const regionIndex, CellElementSubRegion & elementSubRegion ) { arrayView2d< localIndex const, cells::NODE_MAP_USD > const & elemsToNodes = elementSubRegion.nodeList(); - arrayView1d< real32 const > const density = elementSubRegion.getField< acousticfields::AcousticDensity >(); - arrayView2d< real32 > const velocity_x = elementSubRegion.getField< acousticfields::Velocity_x >(); - arrayView2d< real32 > const velocity_y = elementSubRegion.getField< acousticfields::Velocity_y >(); - arrayView2d< real32 > const velocity_z = elementSubRegion.getField< acousticfields::Velocity_z >(); + arrayView1d< real32 const > const density = elementSubRegion.getField< wavesolverfields::AcousticDensity >(); + arrayView2d< real32 > const velocity_x = elementSubRegion.getField< wavesolverfields::Velocity_x >(); + arrayView2d< real32 > const velocity_y = elementSubRegion.getField< wavesolverfields::Velocity_y >(); + arrayView2d< real32 > const velocity_z = elementSubRegion.getField< wavesolverfields::Velocity_z >(); finiteElement::FiniteElementBase const & fe = elementSubRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); finiteElement::FiniteElementDispatchHandler< SEM_FE_TYPES >::dispatch3D( fe, [&] ( auto const finiteElement ) @@ -500,8 +523,8 @@ real64 AcousticFirstOrderWaveEquationSEM::explicitStepInternal( real64 const & t } ); FieldIdentifiers fieldsToBeSync; - fieldsToBeSync.addFields( FieldLocation::Node, { acousticfields::Pressure_np1::key() } ); - fieldsToBeSync.addElementFields( {acousticfields::Velocity_x::key(), acousticfields::Velocity_y::key(), acousticfields::Velocity_z::key()}, regionNames ); + fieldsToBeSync.addFields( FieldLocation::Node, { wavesolverfields::Pressure_np1::key() } ); + fieldsToBeSync.addElementFields( {wavesolverfields::Velocity_x::key(), wavesolverfields::Velocity_y::key(), wavesolverfields::Velocity_z::key()}, regionNames ); CommunicationTools & syncFields = CommunicationTools::getInstance(); syncFields.synchronizeFields( fieldsToBeSync, @@ -527,13 +550,13 @@ void AcousticFirstOrderWaveEquationSEM::cleanup( real64 const time_n, integer co arrayView1d< string const > const & regionNames ) { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); + arrayView1d< real32 const > const p_np1 = nodeManager.getField< wavesolverfields::Pressure_np1 >(); mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const regionIndex, CellElementSubRegion & elementSubRegion ) { - arrayView2d< real32 > const velocity_x = elementSubRegion.getField< acousticfields::Velocity_x >(); - arrayView2d< real32 > const velocity_y = elementSubRegion.getField< acousticfields::Velocity_y >(); - arrayView2d< real32 > const velocity_z = elementSubRegion.getField< acousticfields::Velocity_z >(); + arrayView2d< real32 > const velocity_x = elementSubRegion.getField< wavesolverfields::Velocity_x >(); + arrayView2d< real32 > const velocity_y = elementSubRegion.getField< wavesolverfields::Velocity_y >(); + arrayView2d< real32 > const velocity_z = elementSubRegion.getField< wavesolverfields::Velocity_z >(); arrayView2d< real32 > const uxReceivers = m_uxNp1AtReceivers.toView(); arrayView2d< real32 > const uyReceivers = m_uyNp1AtReceivers.toView(); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.hpp index 14a6dc502ae..2ed6728bb22 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.hpp @@ -21,7 +21,7 @@ #define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICFIRSTORDERWAVEEQUATIONSEM_HPP_ #include "mesh/MeshFields.hpp" -#include "AcousticFields.hpp" +#include "WaveSolverBaseFields.hpp" #include "WaveSolverBase.hpp" namespace geos @@ -34,6 +34,12 @@ class AcousticFirstOrderWaveEquationSEM : public WaveSolverBase using EXEC_POLICY = parallelDevicePolicy< >; using ATOMIC_POLICY = parallelDeviceAtomic; + + /** + * @brief Safeguard for timeStep. Used to avoid memory issue due to too small value. + */ + static constexpr real64 epsilonLoc = 1e-8; + AcousticFirstOrderWaveEquationSEM( const std::string & name, Group * const parent ); @@ -67,6 +73,15 @@ class AcousticFirstOrderWaveEquationSEM : public WaveSolverBase integer const cycleNumber, DomainPartition & domain, bool const computeGradient ) override; + /**@}*/ + + /** + * @brief Multiply the precomputed term by the Ricker and add to the right-hand side + * @param cycleNumber the cycle number/step number of evaluation of the source + * @param rhs the right hand side vector to be computed + */ + virtual void addSourceToRightHandSide( integer const & cycleNumber, arrayView1d< real32 > const rhs ); + /** * @brief Initialize Perfectly Matched Layer (PML) information diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIFields.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIFields.hpp deleted file mode 100644 index a361d77e55c..00000000000 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIFields.hpp +++ /dev/null @@ -1,193 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2018-2020 TotalEnergies - * Copyright (c) 2019- GEOSX Contributors - * All rights reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - - -/** - * @file AcousticVTIFields.hpp - */ - -#ifndef GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICVTIFIELDS_HPP_ -#define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICVTIFIELDS_HPP_ - -#include "common/DataLayouts.hpp" -#include "mesh/MeshFields.hpp" - - -namespace geos -{ - -namespace fields -{ - -namespace acousticvtifields -{ - -DECLARE_FIELD( Delta, - "delta", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Delta thomsen anisotropy parameter" ); - -DECLARE_FIELD( Epsilon, - "epsilon", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Epsilon thomsen anisotropy parameter" ); - -DECLARE_FIELD( F, - "f", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "f quantity in VTI/TTI Fletcher's equations" ); - -DECLARE_FIELD( StiffnessVector_p, - "stiffnessVector_p", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Stiffness vector contains R_h*Pressure_n." ); - -DECLARE_FIELD( StiffnessVector_q, - "stiffnessVector_q", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Stiffness vector contains R_h*Pressure_n." ); - -DECLARE_FIELD( Pressure_p_nm1, - "pressure_p_nm1", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Scalar pressure at time n-1." ); - -DECLARE_FIELD( Pressure_p_n, - "pressure_p_n", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Scalar pressure at time n." ); - -DECLARE_FIELD( Pressure_p_np1, - "pressure_p_np1", - array1d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "Scalar pressure at time n+1." ); - -DECLARE_FIELD( Pressure_q_nm1, - "pressure_q_nm1", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Scalar auxiliary pressure q at time n-1." ); - -DECLARE_FIELD( Pressure_q_n, - "pressure_q_n", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Scalar auxiliary pressure q at time n." ); - -DECLARE_FIELD( Pressure_q_np1, - "pressure_q_np1", - array1d< real32 >, - 0, - LEVEL_0, - WRITE_AND_READ, - "Scalar auxiliary pressure q at time n+1." ); - -DECLARE_FIELD( DampingVector_p, - "dampingVector_p", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal of the Damping Matrix for p terms in p equation." ); - -DECLARE_FIELD( DampingVector_pq, - "dampingVector_pq", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal of the Damping Matrix for q terms in p equation." ); - -DECLARE_FIELD( DampingVector_q, - "dampingVector_q", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal of the Damping Matrix for q terms in q equation." ); - -DECLARE_FIELD( DampingVector_qp, - "dampingVector_qp", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Diagonal of the Damping Matrix for p terms in q equation." ); - -DECLARE_FIELD( LateralSurfaceFaceIndicator, - "lateralSurfaceFaceIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Free surface indicator, 1 if a face is on a lateral surface 0 otherwise." ); - -DECLARE_FIELD( LateralSurfaceNodeIndicator, - "lateralSurfaceNodeIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Lateral surface indicator, 1 if a face is on a lateral surface 0 otherwise." ); - -DECLARE_FIELD( BottomSurfaceFaceIndicator, - "bottomSurfaceFaceIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Bottom surface indicator, 1 if a face is on the bottom surface 0 otherwise." ); - -DECLARE_FIELD( BottomSurfaceNodeIndicator, - "bottomSurfaceNodeIndicator", - array1d< localIndex >, - 0, - NOPLOT, - WRITE_AND_READ, - "Bottom surface indicator, 1 if a face is on the bottom surface 0 otherwise." ); -} - -} - -} /* namespace geos */ - -#endif /* GEOS_PHYSICSSOLVERS_WAVEPROPAGATION__HPP_ACOUSTICVTIFIELDS */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.cpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.cpp index 967327730a6..08e6b724d8f 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.cpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.cpp @@ -27,12 +27,12 @@ #include "mesh/ElementType.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "WaveSolverUtils.hpp" +#include "WaveSolverBaseFields.hpp" namespace geos { using namespace dataRepository; -using namespace fields; AcousticVTIWaveEquationSEM::AcousticVTIWaveEquationSEM( const std::string & name, Group * const parent ): @@ -62,38 +62,38 @@ void AcousticVTIWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) { NodeManager & nodeManager = mesh.getNodeManager(); - nodeManager.registerField< acousticvtifields::Pressure_p_nm1, - acousticvtifields::Pressure_p_n, - acousticvtifields::Pressure_p_np1, - acousticvtifields::Pressure_q_nm1, - acousticvtifields::Pressure_q_n, - acousticvtifields::Pressure_q_np1, - acousticfields::ForcingRHS, - acousticfields::AcousticMassVector, - acousticvtifields::DampingVector_p, - acousticvtifields::DampingVector_pq, - acousticvtifields::DampingVector_q, - acousticvtifields::DampingVector_qp, - acousticvtifields::StiffnessVector_p, - acousticvtifields::StiffnessVector_q, - acousticfields::AcousticFreeSurfaceNodeIndicator, - acousticvtifields::LateralSurfaceNodeIndicator, - acousticvtifields::BottomSurfaceNodeIndicator >( getName() ); + nodeManager.registerField< fields::wavesolverfields::Pressure_p_nm1, + fields::wavesolverfields::Pressure_p_n, + fields::wavesolverfields::Pressure_p_np1, + fields::wavesolverfields::Pressure_q_nm1, + fields::wavesolverfields::Pressure_q_n, + fields::wavesolverfields::Pressure_q_np1, + fields::wavesolverfields::ForcingRHS, + fields::wavesolverfields::AcousticMassVector, + fields::wavesolverfields::DampingVector_p, + fields::wavesolverfields::DampingVector_pq, + fields::wavesolverfields::DampingVector_q, + fields::wavesolverfields::DampingVector_qp, + fields::wavesolverfields::StiffnessVector_p, + fields::wavesolverfields::StiffnessVector_q, + fields::wavesolverfields::AcousticFreeSurfaceNodeIndicator, + fields::wavesolverfields::LateralSurfaceNodeIndicator, + fields::wavesolverfields::BottomSurfaceNodeIndicator >( getName() ); FaceManager & faceManager = mesh.getFaceManager(); - faceManager.registerField< acousticfields::AcousticFreeSurfaceFaceIndicator >( getName() ); - faceManager.registerField< acousticvtifields::LateralSurfaceFaceIndicator >( getName() ); - faceManager.registerField< acousticvtifields::BottomSurfaceFaceIndicator >( getName() ); + faceManager.registerField< fields::wavesolverfields::AcousticFreeSurfaceFaceIndicator >( getName() ); + faceManager.registerField< fields::wavesolverfields::LateralSurfaceFaceIndicator >( getName() ); + faceManager.registerField< fields::wavesolverfields::BottomSurfaceFaceIndicator >( getName() ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< CellElementSubRegion >( [&]( CellElementSubRegion & subRegion ) { - subRegion.registerField< acousticvtifields::Delta >( getName() ); - subRegion.registerField< acousticvtifields::Epsilon >( getName() ); - subRegion.registerField< acousticvtifields::F >( getName() ); - subRegion.registerField< acousticfields::AcousticVelocity >( getName() ); + subRegion.registerField< fields::wavesolverfields::Delta >( getName() ); + subRegion.registerField< fields::wavesolverfields::Epsilon >( getName() ); + subRegion.registerField< fields::wavesolverfields::F >( getName() ); + subRegion.registerField< fields::wavesolverfields::AcousticVelocity >( getName() ); } ); } ); } @@ -248,22 +248,22 @@ void AcousticVTIWaveEquationSEM::initializePostInitialConditionsPreSubGroups() ArrayOfArraysView< localIndex const > const facesToNodes = faceManager.nodeList().toViewConst(); // mass matrix to be computed in this function - arrayView1d< real32 > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); + arrayView1d< real32 > const mass = nodeManager.getField< fields::wavesolverfields::AcousticMassVector >(); mass.zero(); /// damping matrices to be computed for each dof in the boundary of the mesh - arrayView1d< real32 > const damping_p = nodeManager.getField< acousticvtifields::DampingVector_p >(); - arrayView1d< real32 > const damping_pq = nodeManager.getField< acousticvtifields::DampingVector_pq >(); - arrayView1d< real32 > const damping_q = nodeManager.getField< acousticvtifields::DampingVector_q >(); - arrayView1d< real32 > const damping_qp = nodeManager.getField< acousticvtifields::DampingVector_qp >(); + arrayView1d< real32 > const damping_p = nodeManager.getField< fields::wavesolverfields::DampingVector_p >(); + arrayView1d< real32 > const damping_pq = nodeManager.getField< fields::wavesolverfields::DampingVector_pq >(); + arrayView1d< real32 > const damping_q = nodeManager.getField< fields::wavesolverfields::DampingVector_q >(); + arrayView1d< real32 > const damping_qp = nodeManager.getField< fields::wavesolverfields::DampingVector_qp >(); damping_p.zero(); damping_pq.zero(); damping_q.zero(); damping_qp.zero(); /// get array of indicators: 1 if face is on the free surface; 0 otherwise - arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< acousticfields::AcousticFreeSurfaceFaceIndicator >(); - arrayView1d< localIndex const > const lateralSurfaceFaceIndicator = faceManager.getField< acousticvtifields::LateralSurfaceFaceIndicator >(); - arrayView1d< localIndex const > const bottomSurfaceFaceIndicator = faceManager.getField< acousticvtifields::BottomSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< fields::wavesolverfields::AcousticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const lateralSurfaceFaceIndicator = faceManager.getField< fields::wavesolverfields::LateralSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const bottomSurfaceFaceIndicator = faceManager.getField< fields::wavesolverfields::BottomSurfaceFaceIndicator >(); mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const, CellElementSubRegion & elementSubRegion ) @@ -271,10 +271,10 @@ void AcousticVTIWaveEquationSEM::initializePostInitialConditionsPreSubGroups() arrayView2d< localIndex const, cells::NODE_MAP_USD > const elemsToNodes = elementSubRegion.nodeList(); arrayView2d< localIndex const > const elemsToFaces = elementSubRegion.faceList(); - arrayView1d< real32 const > const velocity = elementSubRegion.getField< acousticfields::AcousticVelocity >(); - arrayView1d< real32 const > const epsilon = elementSubRegion.getField< acousticvtifields::Epsilon >(); - arrayView1d< real32 const > const delta = elementSubRegion.getField< acousticvtifields::Delta >(); - arrayView1d< real32 const > const vti_f = elementSubRegion.getField< acousticvtifields::F >(); + arrayView1d< real32 const > const velocity = elementSubRegion.getField< fields::wavesolverfields::AcousticVelocity >(); + arrayView1d< real32 const > const epsilon = elementSubRegion.getField< fields::wavesolverfields::Epsilon >(); + arrayView1d< real32 const > const delta = elementSubRegion.getField< fields::wavesolverfields::Delta >(); + arrayView1d< real32 const > const vti_f = elementSubRegion.getField< fields::wavesolverfields::F >(); finiteElement::FiniteElementBase const & fe = elementSubRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); @@ -327,14 +327,14 @@ void AcousticVTIWaveEquationSEM::precomputeSurfaceFieldIndicator( DomainPartitio ArrayOfArraysView< localIndex const > const faceToNodeMap = faceManager.nodeList().toViewConst(); /// array of indicators: 1 if a face is on on lateral surface; 0 otherwise - arrayView1d< localIndex > const lateralSurfaceFaceIndicator = faceManager.getField< acousticvtifields::LateralSurfaceFaceIndicator >(); + arrayView1d< localIndex > const lateralSurfaceFaceIndicator = faceManager.getField< fields::wavesolverfields::LateralSurfaceFaceIndicator >(); /// array of indicators: 1 if a node is on on lateral surface; 0 otherwise - arrayView1d< localIndex > const lateralSurfaceNodeIndicator = nodeManager.getField< acousticvtifields::LateralSurfaceNodeIndicator >(); + arrayView1d< localIndex > const lateralSurfaceNodeIndicator = nodeManager.getField< fields::wavesolverfields::LateralSurfaceNodeIndicator >(); /// array of indicators: 1 if a face is on on bottom surface; 0 otherwise - arrayView1d< localIndex > const bottomSurfaceFaceIndicator = faceManager.getField< acousticvtifields::BottomSurfaceFaceIndicator >(); + arrayView1d< localIndex > const bottomSurfaceFaceIndicator = faceManager.getField< fields::wavesolverfields::BottomSurfaceFaceIndicator >(); /// array of indicators: 1 if a node is on on bottom surface; 0 otherwise - arrayView1d< localIndex > const bottomSurfaceNodeIndicator = nodeManager.getField< acousticvtifields::BottomSurfaceNodeIndicator >(); + arrayView1d< localIndex > const bottomSurfaceNodeIndicator = nodeManager.getField< fields::wavesolverfields::BottomSurfaceNodeIndicator >(); // Lateral surfaces fsManager.apply< FaceManager >( time, @@ -411,21 +411,21 @@ void AcousticVTIWaveEquationSEM::applyFreeSurfaceBC( real64 time, DomainPartitio FaceManager & faceManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getFaceManager(); NodeManager & nodeManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getNodeManager(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticvtifields::Pressure_p_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< acousticvtifields::Pressure_p_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticvtifields::Pressure_p_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< fields::wavesolverfields::Pressure_p_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_np1 >(); - arrayView1d< real32 > const q_nm1 = nodeManager.getField< acousticvtifields::Pressure_q_nm1 >(); - arrayView1d< real32 > const q_n = nodeManager.getField< acousticvtifields::Pressure_q_n >(); - arrayView1d< real32 > const q_np1 = nodeManager.getField< acousticvtifields::Pressure_q_np1 >(); + arrayView1d< real32 > const q_nm1 = nodeManager.getField< fields::wavesolverfields::Pressure_q_nm1 >(); + arrayView1d< real32 > const q_n = nodeManager.getField< fields::wavesolverfields::Pressure_q_n >(); + arrayView1d< real32 > const q_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_q_np1 >(); ArrayOfArraysView< localIndex const > const faceToNodeMap = faceManager.nodeList().toViewConst(); /// array of indicators: 1 if a face is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< acousticfields::AcousticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< fields::wavesolverfields::AcousticFreeSurfaceFaceIndicator >(); /// array of indicators: 1 if a node is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< acousticfields::AcousticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< fields::wavesolverfields::AcousticFreeSurfaceNodeIndicator >(); fsManager.apply< FaceManager >( time, domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ), @@ -485,13 +485,13 @@ real64 AcousticVTIWaveEquationSEM::explicitStepForward( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticvtifields::Pressure_p_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< acousticvtifields::Pressure_p_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticvtifields::Pressure_p_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< fields::wavesolverfields::Pressure_p_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_np1 >(); - arrayView1d< real32 > const q_nm1 = nodeManager.getField< acousticvtifields::Pressure_q_nm1 >(); - arrayView1d< real32 > const q_n = nodeManager.getField< acousticvtifields::Pressure_q_n >(); - arrayView1d< real32 > const q_np1 = nodeManager.getField< acousticvtifields::Pressure_q_np1 >(); + arrayView1d< real32 > const q_nm1 = nodeManager.getField< fields::wavesolverfields::Pressure_q_nm1 >(); + arrayView1d< real32 > const q_n = nodeManager.getField< fields::wavesolverfields::Pressure_q_n >(); + arrayView1d< real32 > const q_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_q_np1 >(); if( computeGradient ) { @@ -551,26 +551,26 @@ real64 AcousticVTIWaveEquationSEM::explicitStepInternal( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); - arrayView1d< real32 const > const damping_p = nodeManager.getField< acousticvtifields::DampingVector_p >(); - arrayView1d< real32 const > const damping_q = nodeManager.getField< acousticvtifields::DampingVector_q >(); - arrayView1d< real32 const > const damping_pq = nodeManager.getField< acousticvtifields::DampingVector_pq >(); - arrayView1d< real32 const > const damping_qp = nodeManager.getField< acousticvtifields::DampingVector_qp >(); + arrayView1d< real32 const > const mass = nodeManager.getField< fields::wavesolverfields::AcousticMassVector >(); + arrayView1d< real32 const > const damping_p = nodeManager.getField< fields::wavesolverfields::DampingVector_p >(); + arrayView1d< real32 const > const damping_q = nodeManager.getField< fields::wavesolverfields::DampingVector_q >(); + arrayView1d< real32 const > const damping_pq = nodeManager.getField< fields::wavesolverfields::DampingVector_pq >(); + arrayView1d< real32 const > const damping_qp = nodeManager.getField< fields::wavesolverfields::DampingVector_qp >(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticvtifields::Pressure_p_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< acousticvtifields::Pressure_p_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticvtifields::Pressure_p_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< fields::wavesolverfields::Pressure_p_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_np1 >(); - arrayView1d< real32 > const q_nm1 = nodeManager.getField< acousticvtifields::Pressure_q_nm1 >(); - arrayView1d< real32 > const q_n = nodeManager.getField< acousticvtifields::Pressure_q_n >(); - arrayView1d< real32 > const q_np1 = nodeManager.getField< acousticvtifields::Pressure_q_np1 >(); + arrayView1d< real32 > const q_nm1 = nodeManager.getField< fields::wavesolverfields::Pressure_q_nm1 >(); + arrayView1d< real32 > const q_n = nodeManager.getField< fields::wavesolverfields::Pressure_q_n >(); + arrayView1d< real32 > const q_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_q_np1 >(); - arrayView1d< localIndex const > const freeSurfaceNodeIndicator = nodeManager.getField< acousticfields::AcousticFreeSurfaceNodeIndicator >(); - arrayView1d< localIndex const > const lateralSurfaceNodeIndicator = nodeManager.getField< acousticvtifields::LateralSurfaceNodeIndicator >(); - arrayView1d< localIndex const > const bottomSurfaceNodeIndicator = nodeManager.getField< acousticvtifields::BottomSurfaceNodeIndicator >(); - arrayView1d< real32 > const stiffnessVector_p = nodeManager.getField< acousticvtifields::StiffnessVector_p >(); - arrayView1d< real32 > const stiffnessVector_q = nodeManager.getField< acousticvtifields::StiffnessVector_q >(); - arrayView1d< real32 > const rhs = nodeManager.getField< acousticfields::ForcingRHS >(); + arrayView1d< localIndex const > const freeSurfaceNodeIndicator = nodeManager.getField< fields::wavesolverfields::AcousticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex const > const lateralSurfaceNodeIndicator = nodeManager.getField< fields::wavesolverfields::LateralSurfaceNodeIndicator >(); + arrayView1d< localIndex const > const bottomSurfaceNodeIndicator = nodeManager.getField< fields::wavesolverfields::BottomSurfaceNodeIndicator >(); + arrayView1d< real32 > const stiffnessVector_p = nodeManager.getField< fields::wavesolverfields::StiffnessVector_p >(); + arrayView1d< real32 > const stiffnessVector_q = nodeManager.getField< fields::wavesolverfields::StiffnessVector_q >(); + arrayView1d< real32 > const rhs = nodeManager.getField< fields::wavesolverfields::ForcingRHS >(); auto kernelFactory = acousticVTIWaveEquationSEMKernels::ExplicitAcousticVTISEMFactory( dt ); @@ -637,8 +637,8 @@ real64 AcousticVTIWaveEquationSEM::explicitStepInternal( real64 const & time_n, /// synchronize pressure fields FieldIdentifiers fieldsToBeSync; - fieldsToBeSync.addFields( FieldLocation::Node, { acousticvtifields::Pressure_p_np1::key() } ); - fieldsToBeSync.addFields( FieldLocation::Node, { acousticvtifields::Pressure_q_np1::key() } ); + fieldsToBeSync.addFields( FieldLocation::Node, { fields::wavesolverfields::Pressure_p_np1::key() } ); + fieldsToBeSync.addFields( FieldLocation::Node, { fields::wavesolverfields::Pressure_q_np1::key() } ); CommunicationTools & syncFields = CommunicationTools::getInstance(); syncFields.synchronizeFields( fieldsToBeSync, @@ -680,8 +680,8 @@ void AcousticVTIWaveEquationSEM::cleanup( real64 const time_n, arrayView1d< string const > const & ) { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const p_n = nodeManager.getField< acousticvtifields::Pressure_p_n >(); - arrayView1d< real32 const > const p_np1 = nodeManager.getField< acousticvtifields::Pressure_p_np1 >(); + arrayView1d< real32 const > const p_n = nodeManager.getField< fields::wavesolverfields::Pressure_p_n >(); + arrayView1d< real32 const > const p_np1 = nodeManager.getField< fields::wavesolverfields::Pressure_p_np1 >(); arrayView2d< real32 > const pReceivers = m_pressureNp1AtReceivers.toView(); computeAllSeismoTraces( time_n, 0.0, p_np1, p_n, pReceivers ); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.hpp index 932568e3f6e..b0c152ec45e 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEM.hpp @@ -23,8 +23,7 @@ #include "mesh/MeshFields.hpp" #include "physicsSolvers/SolverBase.hpp" #include "WaveSolverBase.hpp" -#include "AcousticFields.hpp" -#include "AcousticVTIFields.hpp" +#include "WaveSolverBaseFields.hpp" namespace geos { diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEMKernel.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEMKernel.hpp index 72cd2da8d73..eba56694b26 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEMKernel.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticVTIWaveEquationSEMKernel.hpp @@ -21,12 +21,12 @@ #include "finiteElement/elementFormulations/Qk_Hexahedron_Lagrange_GaussLobatto.hpp" #include "finiteElement/kernelInterface/KernelBase.hpp" +#include "WaveSolverBaseFields.hpp" #include "WaveSolverUtils.hpp" -#include "AcousticVTIFields.hpp" + namespace geos { -using namespace fields; /// Namespace to contain the acoustic wave kernels. namespace acousticVTIWaveEquationSEMKernels @@ -430,13 +430,13 @@ class ExplicitAcousticVTISEM : public finiteElement::KernelBase< SUBREGION_TYPE, finiteElementSpace, inputConstitutiveType ), m_nodeCoords( nodeManager.getField< fields::referencePosition32 >() ), - m_p_n( nodeManager.getField< acousticvtifields::Pressure_p_n >() ), - m_q_n( nodeManager.getField< acousticvtifields::Pressure_q_n >() ), - m_stiffnessVector_p( nodeManager.getField< acousticvtifields::StiffnessVector_p >() ), - m_stiffnessVector_q( nodeManager.getField< acousticvtifields::StiffnessVector_q >() ), - m_epsilon( elementSubRegion.template getField< acousticvtifields::Epsilon >() ), - m_delta( elementSubRegion.template getField< acousticvtifields::Delta >() ), - m_vti_f( elementSubRegion.template getField< acousticvtifields::F >() ), + m_p_n( nodeManager.getField< fields::wavesolverfields::Pressure_p_n >() ), + m_q_n( nodeManager.getField< fields::wavesolverfields::Pressure_q_n >() ), + m_stiffnessVector_p( nodeManager.getField< fields::wavesolverfields::StiffnessVector_p >() ), + m_stiffnessVector_q( nodeManager.getField< fields::wavesolverfields::StiffnessVector_q >() ), + m_epsilon( elementSubRegion.template getField< fields::wavesolverfields::Epsilon >() ), + m_delta( elementSubRegion.template getField< fields::wavesolverfields::Delta >() ), + m_vti_f( elementSubRegion.template getField< fields::wavesolverfields::F >() ), m_dt( dt ) { GEOS_UNUSED_VAR( edgeManager ); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.cpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.cpp index 0dc0f3f97c7..d822d1b5a06 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.cpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.cpp @@ -32,7 +32,6 @@ namespace geos { using namespace dataRepository; -using namespace fields; AcousticWaveEquationSEM::AcousticWaveEquationSEM( const std::string & name, Group * const parent ): @@ -67,38 +66,38 @@ void AcousticWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) { NodeManager & nodeManager = mesh.getNodeManager(); - nodeManager.registerField< acousticfields::Pressure_nm1, - acousticfields::Pressure_n, - acousticfields::Pressure_np1, - acousticfields::PressureDoubleDerivative, - acousticfields::ForcingRHS, - acousticfields::AcousticMassVector, - acousticfields::DampingVector, - acousticfields::StiffnessVector, - acousticfields::AcousticFreeSurfaceNodeIndicator >( getName() ); + nodeManager.registerField< fields::Pressure_nm1, + fields::Pressure_n, + fields::Pressure_np1, + fields::PressureDoubleDerivative, + fields::ForcingRHS, + fields::AcousticMassVector, + fields::DampingVector, + fields::StiffnessVector, + fields::AcousticFreeSurfaceNodeIndicator >( getName() ); /// register PML auxiliary variables only when a PML is specified in the xml if( m_usePML ) { - nodeManager.registerField< acousticfields::AuxiliaryVar1PML, - acousticfields::AuxiliaryVar2PML, - acousticfields::AuxiliaryVar3PML, - acousticfields::AuxiliaryVar4PML >( getName() ); + nodeManager.registerField< fields::AuxiliaryVar1PML, + fields::AuxiliaryVar2PML, + fields::AuxiliaryVar3PML, + fields::AuxiliaryVar4PML >( getName() ); - nodeManager.getField< acousticfields::AuxiliaryVar1PML >().resizeDimension< 1 >( 3 ); - nodeManager.getField< acousticfields::AuxiliaryVar2PML >().resizeDimension< 1 >( 3 ); + nodeManager.getField< fields::AuxiliaryVar1PML >().resizeDimension< 1 >( 3 ); + nodeManager.getField< fields::AuxiliaryVar2PML >().resizeDimension< 1 >( 3 ); } FaceManager & faceManager = mesh.getFaceManager(); - faceManager.registerField< acousticfields::AcousticFreeSurfaceFaceIndicator >( getName() ); + faceManager.registerField< fields::AcousticFreeSurfaceFaceIndicator >( getName() ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< CellElementSubRegion >( [&]( CellElementSubRegion & subRegion ) { - subRegion.registerField< acousticfields::AcousticVelocity >( getName() ); - subRegion.registerField< acousticfields::AcousticDensity >( getName() ); - subRegion.registerField< acousticfields::PartialGradient >( getName() ); + subRegion.registerField< fields::AcousticVelocity >( getName() ); + subRegion.registerField< fields::AcousticDensity >( getName() ); + subRegion.registerField< fields::PartialGradient >( getName() ); } ); } ); @@ -262,15 +261,19 @@ void AcousticWaveEquationSEM::initializePostInitialConditionsPreSubGroups() ArrayOfArraysView< localIndex const > const facesToNodes = faceManager.nodeList().toViewConst(); // mass matrix to be computed in this function - arrayView1d< real32 > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); - mass.zero(); - + arrayView1d< real32 > const mass = nodeManager.getField< fields::AcousticMassVector >(); + { + GEOS_MARK_SCOPE( mass_zero ); + mass.zero(); + } /// damping matrix to be computed for each dof in the boundary of the mesh - arrayView1d< real32 > const damping = nodeManager.getField< acousticfields::DampingVector >(); - damping.zero(); - + arrayView1d< real32 > const damping = nodeManager.getField< fields::DampingVector >(); + { + GEOS_MARK_SCOPE( damping_zero ); + damping.zero(); + } /// get array of indicators: 1 if face is on the free surface; 0 otherwise - arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< acousticfields::AcousticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< fields::AcousticFreeSurfaceFaceIndicator >(); elemManager.forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const, CellElementSubRegion & elementSubRegion ) @@ -283,11 +286,11 @@ void AcousticWaveEquationSEM::initializePostInitialConditionsPreSubGroups() computeTargetNodeSet( elemsToNodes, elementSubRegion.size(), fe.getNumQuadraturePoints() ); - arrayView1d< real32 const > const velocity = elementSubRegion.getField< acousticfields::AcousticVelocity >(); - arrayView1d< real32 const > const density = elementSubRegion.getField< acousticfields::AcousticDensity >(); + arrayView1d< real32 const > const velocity = elementSubRegion.getField< fields::AcousticVelocity >(); + arrayView1d< real32 const > const density = elementSubRegion.getField< fields::AcousticDensity >(); /// Partial gradient if gradient as to be computed - arrayView1d< real32 > grad = elementSubRegion.getField< acousticfields::PartialGradient >(); + arrayView1d< real32 > grad = elementSubRegion.getField< fields::PartialGradient >(); grad.zero(); finiteElement::FiniteElementDispatchHandler< SEM_FE_TYPES >::dispatch3D( fe, [&] ( auto const finiteElement ) @@ -301,18 +304,19 @@ void AcousticWaveEquationSEM::initializePostInitialConditionsPreSubGroups() velocity, density, mass ); - - acousticWaveEquationSEMKernels::DampingMatrixKernel< FE_TYPE > kernelD( finiteElement ); - kernelD.template launch< EXEC_POLICY, ATOMIC_POLICY >( elementSubRegion.size(), - nodeCoords, - elemsToFaces, - facesToNodes, - facesDomainBoundaryIndicator, - freeSurfaceFaceIndicator, - velocity, - density, - damping ); - + { + GEOS_MARK_SCOPE( DampingMatrixKernel ); + acousticWaveEquationSEMKernels::DampingMatrixKernel< FE_TYPE > kernelD( finiteElement ); + kernelD.template launch< EXEC_POLICY, ATOMIC_POLICY >( elementSubRegion.size(), + nodeCoords, + elemsToFaces, + facesToNodes, + facesDomainBoundaryIndicator, + freeSurfaceFaceIndicator, + velocity, + density, + damping ); + } } ); } ); } ); @@ -330,17 +334,17 @@ void AcousticWaveEquationSEM::applyFreeSurfaceBC( real64 time, DomainPartition & FaceManager & faceManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getFaceManager(); NodeManager & nodeManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getNodeManager(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticfields::Pressure_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::Pressure_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< fields::Pressure_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); ArrayOfArraysView< localIndex const > const faceToNodeMap = faceManager.nodeList().toViewConst(); /// array of indicators: 1 if a face is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< acousticfields::AcousticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< fields::AcousticFreeSurfaceFaceIndicator >(); /// array of indicators: 1 if a node is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< acousticfields::AcousticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< fields::AcousticFreeSurfaceNodeIndicator >(); // freeSurfaceFaceIndicator.zero(); // freeSurfaceNodeIndicator.zero(); @@ -425,7 +429,7 @@ void AcousticWaveEquationSEM::initializePML() NodeManager & nodeManager = mesh.getNodeManager(); /// WARNING: the array below is one of the PML auxiliary variables - arrayView1d< real32 > const indicatorPML = nodeManager.getField< acousticfields::AuxiliaryVar4PML >(); + arrayView1d< real32 > const indicatorPML = nodeManager.getField< fields::AuxiliaryVar4PML >(); arrayView2d< wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords32 = nodeManager.getField< fields::referencePosition32 >().toViewConst(); indicatorPML.zero(); @@ -554,7 +558,7 @@ void AcousticWaveEquationSEM::initializePML() CellElementSubRegion::NodeMapType const & elemToNodes = subRegion.getReference< CellElementSubRegion::NodeMapType >( CellElementSubRegion::viewKeyStruct::nodeListString() ); traits::ViewTypeConst< CellElementSubRegion::NodeMapType > const elemToNodesViewConst = elemToNodes.toViewConst(); - arrayView1d< real32 const > const vel = subRegion.getReference< array1d< real32 > >( acousticfields::AcousticVelocity::key()); + arrayView1d< real32 const > const vel = subRegion.getReference< array1d< real32 > >( fields::AcousticVelocity::key()); finiteElement::FiniteElementBase const & fe = subRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); @@ -655,11 +659,11 @@ void AcousticWaveEquationSEM::applyPML( real64 const time, DomainPartition & dom NodeManager & nodeManager = mesh.getNodeManager(); /// Array views of the pressure p, PML auxiliary variables, and node coordinates - arrayView1d< real32 const > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); - arrayView2d< real32 const > const v_n = nodeManager.getField< acousticfields::AuxiliaryVar1PML >(); - arrayView2d< real32 > const grad_n = nodeManager.getField< acousticfields::AuxiliaryVar2PML >(); - arrayView1d< real32 > const divV_n = nodeManager.getField< acousticfields::AuxiliaryVar3PML >(); - arrayView1d< real32 const > const u_n = nodeManager.getField< acousticfields::AuxiliaryVar4PML >(); + arrayView1d< real32 const > const p_n = nodeManager.getField< fields::Pressure_n >(); + arrayView2d< real32 const > const v_n = nodeManager.getField< fields::AuxiliaryVar1PML >(); + arrayView2d< real32 > const grad_n = nodeManager.getField< fields::AuxiliaryVar2PML >(); + arrayView1d< real32 > const divV_n = nodeManager.getField< fields::AuxiliaryVar3PML >(); + arrayView1d< real32 const > const u_n = nodeManager.getField< fields::AuxiliaryVar4PML >(); arrayView2d< wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords32 = nodeManager.getField< fields::referencePosition32 >().toViewConst(); /// Select the subregions concerned by the PML (specified in the xml by the Field Specification) @@ -684,7 +688,7 @@ void AcousticWaveEquationSEM::applyPML( real64 const time, DomainPartition & dom traits::ViewTypeConst< CellElementSubRegion::NodeMapType > const elemToNodesViewConst = elemToNodes.toViewConst(); /// Array view of the wave speed - arrayView1d< real32 const > const vel = subRegion.getReference< array1d< real32 > >( acousticfields::AcousticVelocity::key()); + arrayView1d< real32 const > const vel = subRegion.getReference< array1d< real32 > >( fields::AcousticVelocity::key()); /// Get the object needed to determine the type of the element in the subregion finiteElement::FiniteElementBase const & @@ -753,14 +757,14 @@ real64 AcousticWaveEquationSEM::explicitStepForward( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticfields::Pressure_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::Pressure_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< fields::Pressure_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); if( computeGradient && cycleNumber >= 0 ) { - arrayView1d< real32 > const p_dt2 = nodeManager.getField< acousticfields::PressureDoubleDerivative >(); + arrayView1d< real32 > const p_dt2 = nodeManager.getField< fields::PressureDoubleDerivative >(); if( m_enableLifo ) { @@ -797,6 +801,10 @@ real64 AcousticWaveEquationSEM::explicitStepForward( real64 const & time_n, makeDirsForPath( dirName ); } + //std::string fileName = GEOS_FMT( "pressuredt2_{:06}_{:08}_{:04}.dat", m_shotIndex, cycleNumber, rank ); + //const int fileDesc = open( fileName.c_str(), O_CREAT | O_WRONLY | O_DIRECT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | + // S_IROTH | S_IWOTH ); + std::ofstream wf( fileName, std::ios::out | std::ios::binary ); GEOS_THROW_IF( !wf, getDataContext() << ": Could not open file "<< fileName << " for writing", @@ -831,11 +839,11 @@ real64 AcousticWaveEquationSEM::explicitStepBackward( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); + arrayView1d< real32 const > const mass = nodeManager.getField< fields::AcousticMassVector >(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticfields::Pressure_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::Pressure_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< fields::Pressure_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); EventManager const & event = getGroupByPath< EventManager >( "/Problem/Events" ); real64 const & maxTime = event.getReference< real64 >( EventManager::viewKeyStruct::maxTimeString() ); @@ -845,7 +853,7 @@ real64 AcousticWaveEquationSEM::explicitStepBackward( real64 const & time_n, { ElementRegionManager & elemManager = mesh.getElemManager(); - arrayView1d< real32 > const p_dt2 = nodeManager.getField< acousticfields::PressureDoubleDerivative >(); + arrayView1d< real32 > const p_dt2 = nodeManager.getField< fields::PressureDoubleDerivative >(); if( m_enableLifo ) { @@ -863,7 +871,11 @@ real64 AcousticWaveEquationSEM::explicitStepBackward( real64 const & time_n, GEOS_THROW_IF( !wf, getDataContext() << ": Could not open file "<< fileName << " for reading", InputError ); - + //std::string fileName = GEOS_FMT( "pressuredt2_{:06}_{:08}_{:04}.dat", m_shotIndex, cycleNumber, rank ); + //const int fileDesc = open( fileName.c_str(), O_RDONLY | O_DIRECT ); + //GEOS_ERROR_IF( fileDesc == -1, + // "Could not open file "<< fileName << " for reading: " << strerror( errno ) ); + // maybe better with registerTouch() p_dt2.move( MemorySpace::host, true ); wf.read( (char *)&p_dt2[0], p_dt2.size()*sizeof( real32 ) ); wf.close( ); @@ -872,8 +884,8 @@ real64 AcousticWaveEquationSEM::explicitStepBackward( real64 const & time_n, elemManager.forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const, CellElementSubRegion & elementSubRegion ) { - arrayView1d< real32 const > const velocity = elementSubRegion.getField< acousticfields::AcousticVelocity >(); - arrayView1d< real32 > grad = elementSubRegion.getField< acousticfields::PartialGradient >(); + arrayView1d< real32 const > const velocity = elementSubRegion.getField< fields::AcousticVelocity >(); + arrayView1d< real32 > grad = elementSubRegion.getField< fields::PartialGradient >(); arrayView2d< localIndex const, cells::NODE_MAP_USD > const & elemsToNodes = elementSubRegion.nodeList(); constexpr localIndex numNodesPerElem = 8; arrayView1d< integer const > const elemGhostRank = elementSubRegion.ghostRank(); @@ -902,12 +914,12 @@ void AcousticWaveEquationSEM::prepareNextTimestep( MeshLevel & mesh ) { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticfields::Pressure_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::Pressure_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< fields::Pressure_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); - arrayView1d< real32 > const stiffnessVector = nodeManager.getField< acousticfields::StiffnessVector >(); - arrayView1d< real32 > const rhs = nodeManager.getField< acousticfields::ForcingRHS >(); + arrayView1d< real32 > const stiffnessVector = nodeManager.getField< fields::StiffnessVector >(); + arrayView1d< real32 > const rhs = nodeManager.getField< fields::ForcingRHS >(); SortedArrayView< localIndex const > const solverTargetNodesSet = m_solverTargetNodesSet.toViewConst(); @@ -931,16 +943,16 @@ void AcousticWaveEquationSEM::computeUnknowns( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const mass = nodeManager.getField< acousticfields::AcousticMassVector >(); - arrayView1d< real32 const > const damping = nodeManager.getField< acousticfields::DampingVector >(); + arrayView1d< real32 const > const mass = nodeManager.getField< fields::AcousticMassVector >(); + arrayView1d< real32 const > const damping = nodeManager.getField< fields::DampingVector >(); - arrayView1d< real32 > const p_nm1 = nodeManager.getField< acousticfields::Pressure_nm1 >(); - arrayView1d< real32 > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); + arrayView1d< real32 > const p_nm1 = nodeManager.getField< fields::Pressure_nm1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< fields::Pressure_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); - arrayView1d< localIndex const > const freeSurfaceNodeIndicator = nodeManager.getField< acousticfields::AcousticFreeSurfaceNodeIndicator >(); - arrayView1d< real32 > const stiffnessVector = nodeManager.getField< acousticfields::StiffnessVector >(); - arrayView1d< real32 > const rhs = nodeManager.getField< acousticfields::ForcingRHS >(); + arrayView1d< localIndex const > const freeSurfaceNodeIndicator = nodeManager.getField< fields::AcousticFreeSurfaceNodeIndicator >(); + arrayView1d< real32 > const stiffnessVector = nodeManager.getField< fields::StiffnessVector >(); + arrayView1d< real32 > const rhs = nodeManager.getField< fields::ForcingRHS >(); auto kernelFactory = acousticWaveEquationSEMKernels::ExplicitAcousticSEMFactory( dt ); @@ -981,10 +993,10 @@ void AcousticWaveEquationSEM::computeUnknowns( real64 const & time_n, else { parametersPML const & param = getReference< parametersPML >( viewKeyStruct::parametersPMLString() ); - arrayView2d< real32 > const v_n = nodeManager.getField< acousticfields::AuxiliaryVar1PML >(); - arrayView2d< real32 > const grad_n = nodeManager.getField< acousticfields::AuxiliaryVar2PML >(); - arrayView1d< real32 > const divV_n = nodeManager.getField< acousticfields::AuxiliaryVar3PML >(); - arrayView1d< real32 > const u_n = nodeManager.getField< acousticfields::AuxiliaryVar4PML >(); + arrayView2d< real32 > const v_n = nodeManager.getField< fields::AuxiliaryVar1PML >(); + arrayView2d< real32 > const grad_n = nodeManager.getField< fields::AuxiliaryVar2PML >(); + arrayView1d< real32 > const divV_n = nodeManager.getField< fields::AuxiliaryVar3PML >(); + arrayView1d< real32 > const u_n = nodeManager.getField< fields::AuxiliaryVar4PML >(); arrayView2d< wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords32 = nodeManager.getField< fields::referencePosition32 >().toViewConst(); @@ -1051,21 +1063,21 @@ void AcousticWaveEquationSEM::synchronizeUnknowns( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); - arrayView1d< real32 > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); + arrayView1d< real32 > const p_n = nodeManager.getField< fields::Pressure_n >(); + arrayView1d< real32 > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); - arrayView1d< real32 > const stiffnessVector = nodeManager.getField< acousticfields::StiffnessVector >(); - arrayView1d< real32 > const rhs = nodeManager.getField< acousticfields::ForcingRHS >(); + arrayView1d< real32 > const stiffnessVector = nodeManager.getField< fields::StiffnessVector >(); + arrayView1d< real32 > const rhs = nodeManager.getField< fields::ForcingRHS >(); /// synchronize pressure fields FieldIdentifiers fieldsToBeSync; - fieldsToBeSync.addFields( FieldLocation::Node, { acousticfields::Pressure_np1::key() } ); + fieldsToBeSync.addFields( FieldLocation::Node, { fields::Pressure_np1::key() } ); if( m_usePML ) { fieldsToBeSync.addFields( FieldLocation::Node, { - acousticfields::AuxiliaryVar1PML::key(), - acousticfields::AuxiliaryVar4PML::key() } ); + fields::AuxiliaryVar1PML::key(), + fields::AuxiliaryVar4PML::key() } ); } CommunicationTools & syncFields = CommunicationTools::getInstance(); @@ -1081,8 +1093,8 @@ void AcousticWaveEquationSEM::synchronizeUnknowns( real64 const & time_n, if( m_usePML ) { - arrayView2d< real32 > const grad_n = nodeManager.getField< acousticfields::AuxiliaryVar2PML >(); - arrayView1d< real32 > const divV_n = nodeManager.getField< acousticfields::AuxiliaryVar3PML >(); + arrayView2d< real32 > const grad_n = nodeManager.getField< fields::AuxiliaryVar2PML >(); + arrayView1d< real32 > const divV_n = nodeManager.getField< fields::AuxiliaryVar3PML >(); grad_n.zero(); divV_n.zero(); } @@ -1123,8 +1135,8 @@ void AcousticWaveEquationSEM::cleanup( real64 const time_n, arrayView1d< string const > const & ) { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const p_n = nodeManager.getField< acousticfields::Pressure_n >(); - arrayView1d< real32 const > const p_np1 = nodeManager.getField< acousticfields::Pressure_np1 >(); + arrayView1d< real32 const > const p_n = nodeManager.getField< fields::Pressure_n >(); + arrayView1d< real32 const > const p_np1 = nodeManager.getField< fields::Pressure_np1 >(); arrayView2d< real32 > const pReceivers = m_pressureNp1AtReceivers.toView(); computeAllSeismoTraces( time_n, 0.0, p_np1, p_n, pReceivers ); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.hpp index 9396a8201bf..67ea9982df2 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEM.hpp @@ -23,7 +23,6 @@ #include "WaveSolverBase.hpp" #include "mesh/MeshFields.hpp" #include "physicsSolvers/SolverBase.hpp" -#include "AcousticFields.hpp" namespace geos { @@ -170,6 +169,148 @@ class AcousticWaveEquationSEM : public WaveSolverBase }; + +namespace fields +{ + +DECLARE_FIELD( Pressure_nm1, + "pressure_nm1", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Scalar pressure at time n-1." ); + +DECLARE_FIELD( Pressure_n, + "pressure_n", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Scalar pressure at time n." ); + +DECLARE_FIELD( Pressure_np1, + "pressure_np1", + array1d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "Scalar pressure at time n+1." ); + +DECLARE_FIELD( ForcingRHS, + "rhs", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "RHS" ); + +DECLARE_FIELD( AcousticMassVector, + "acousticMassVector", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Diagonal of the Mass Matrix." ); + +DECLARE_FIELD( DampingVector, + "dampingVector", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Diagonal of the Damping Matrix." ); + +DECLARE_FIELD( AcousticVelocity, + "acousticVelocity", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Medium velocity of the cell" ); + +DECLARE_FIELD( AcousticDensity, + "acousticDensity", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Medium density of the cell" ); + +DECLARE_FIELD( StiffnessVector, + "stiffnessVector", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Stiffness vector contains R_h*Pressure_n." ); + +DECLARE_FIELD( AcousticFreeSurfaceFaceIndicator, + "acousticFreeSurfaceFaceIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Free surface indicator, 1 if a face is on free surface 0 otherwise." ); + +DECLARE_FIELD( AcousticFreeSurfaceNodeIndicator, + "acousticFreeSurfaceNodeIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Free surface indicator, 1 if a node is on free surface 0 otherwise." ); + +DECLARE_FIELD( PressureDoubleDerivative, + "pressureDoubleDerivative", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Double derivative of the pressure for each node to compute the gradient" ); + +DECLARE_FIELD( PartialGradient, + "partialGradient", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Partiel gradient computed during backward propagation" ); + +DECLARE_FIELD( AuxiliaryVar1PML, + "auxiliaryVar1PML", + array2d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "PML vectorial auxiliary variable 1." ); + +DECLARE_FIELD( AuxiliaryVar2PML, + "auxiliaryVar2PML", + array2d< real32 >, + 0, + NOPLOT, + NO_WRITE, + "PML vectorial auxiliary variable 2." ); + +DECLARE_FIELD( AuxiliaryVar3PML, + "auxiliaryVar3PML", + array1d< real32 >, + 0, + NOPLOT, + NO_WRITE, + "PML scalar auxiliary variable 3." ); + +DECLARE_FIELD( AuxiliaryVar4PML, + "auxiliaryVar4PML", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "PML scalar auxiliary variable 4." ); + +} + } /* namespace geos */ #endif /* GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTICWAVEEQUATIONSEM_HPP_ */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEMKernel.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEMKernel.hpp index a0179b278d9..708cba74cd6 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEMKernel.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/AcousticWaveEquationSEMKernel.hpp @@ -24,13 +24,10 @@ #if !defined( GEOS_USE_HIP ) #include "finiteElement/elementFormulations/Qk_Hexahedron_Lagrange_GaussLobatto.hpp" #endif -#include "AcousticFields.hpp" namespace geos { -using namespace fields; - /// Namespace to contain the acoustic wave kernels. namespace acousticWaveEquationSEMKernels { @@ -739,9 +736,9 @@ class ExplicitAcousticSEM : public finiteElement::KernelBase< SUBREGION_TYPE, finiteElementSpace, inputConstitutiveType ), m_nodeCoords( nodeManager.getField< fields::referencePosition32 >() ), - m_p_n( nodeManager.getField< acousticfields::Pressure_n >() ), - m_stiffnessVector( nodeManager.getField< acousticfields::StiffnessVector >() ), - m_density( elementSubRegion.template getField< acousticfields::AcousticDensity >() ), + m_p_n( nodeManager.getField< fields::Pressure_n >() ), + m_stiffnessVector( nodeManager.getField< fields::StiffnessVector >() ), + m_density( elementSubRegion.template getField< fields::AcousticDensity >() ), m_dt( dt ) { GEOS_UNUSED_VAR( edgeManager ); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/AcoustoElasticFields.hpp b/src/coreComponents/physicsSolvers/wavePropagation/AcoustoElasticFields.hpp deleted file mode 100644 index bdc80bea84f..00000000000 --- a/src/coreComponents/physicsSolvers/wavePropagation/AcoustoElasticFields.hpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2018-2020 TotalEnergies - * Copyright (c) 2019- GEOSX Contributors - * All rights reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - - -/** - * @file AcoustoElasticFields.hpp - */ - -#ifndef GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTOELASTICFIELDS_HPP_ -#define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ACOUSTOELASTICFIELDS_HPP_ - -#include "common/DataLayouts.hpp" -#include "mesh/MeshFields.hpp" - - -namespace geos -{ - -namespace fields -{ - -namespace acoustoelasticfields -{ - -DECLARE_FIELD( CouplingVectorx, - "couplingVectorx", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Coupling term on x." ); - -DECLARE_FIELD( CouplingVectory, - "couplingVectory", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Coupling term on y." ); - -DECLARE_FIELD( CouplingVectorz, - "couplingVectorz", - array1d< real32 >, - 0, - NOPLOT, - WRITE_AND_READ, - "Coupling term on z." ); - -} - -} - -} /* namespace geos */ - -#endif /* GEOS_PHYSICSSOLVERS_WAVEPROPAGATION__HPP_ACOUSTOELASTICFIELDS */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.cpp b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.cpp index 5a2c9e053b8..512ee4e9ded 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.cpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.cpp @@ -54,32 +54,32 @@ ElasticFirstOrderWaveEquationSEM::ElasticFirstOrderWaveEquationSEM( const std::s setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); - registerWrapper( viewKeyStruct::sigmaxxNp1AtReceiversString(), &m_sigmaxxNp1AtReceivers ). + registerWrapper( viewKeyStruct::displacementzNp1AtReceiversString(), &m_sigmaxxNp1AtReceivers ). setInputFlag( InputFlags::FALSE ). setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); - registerWrapper( viewKeyStruct::sigmayyNp1AtReceiversString(), &m_sigmayyNp1AtReceivers ). + registerWrapper( viewKeyStruct::displacementzNp1AtReceiversString(), &m_sigmayyNp1AtReceivers ). setInputFlag( InputFlags::FALSE ). setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); - registerWrapper( viewKeyStruct::sigmazzNp1AtReceiversString(), &m_sigmazzNp1AtReceivers ). + registerWrapper( viewKeyStruct::displacementzNp1AtReceiversString(), &m_sigmazzNp1AtReceivers ). setInputFlag( InputFlags::FALSE ). setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); - registerWrapper( viewKeyStruct::sigmaxyNp1AtReceiversString(), &m_sigmaxyNp1AtReceivers ). + registerWrapper( viewKeyStruct::displacementzNp1AtReceiversString(), &m_sigmaxyNp1AtReceivers ). setInputFlag( InputFlags::FALSE ). setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); - registerWrapper( viewKeyStruct::sigmaxzNp1AtReceiversString(), &m_sigmaxzNp1AtReceivers ). + registerWrapper( viewKeyStruct::displacementzNp1AtReceiversString(), &m_sigmaxzNp1AtReceivers ). setInputFlag( InputFlags::FALSE ). setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); - registerWrapper( viewKeyStruct::sigmayzNp1AtReceiversString(), &m_sigmayzNp1AtReceivers ). + registerWrapper( viewKeyStruct::displacementzNp1AtReceiversString(), &m_sigmayzNp1AtReceivers ). setInputFlag( InputFlags::FALSE ). setSizedFromParent( 0 ). setDescription( "Displacement value at each receiver for each timestep (z-components)" ); @@ -117,35 +117,35 @@ void ElasticFirstOrderWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) { NodeManager & nodeManager = mesh.getNodeManager(); - nodeManager.registerField< elasticfields::Displacementx_np1, - elasticfields::Displacementy_np1, - elasticfields::Displacementz_np1, - elasticfields::ForcingRHS, - elasticfields::ElasticMassVector, - elasticfields::DampingVectorx, - elasticfields::DampingVectory, - elasticfields::DampingVectorz, - elasticfields::ElasticFreeSurfaceNodeIndicator >( getName() ); + nodeManager.registerField< wavesolverfields::Displacementx_np1, + wavesolverfields::Displacementy_np1, + wavesolverfields::Displacementz_np1, + wavesolverfields::ForcingRHS, + wavesolverfields::ElasticMassVector, + wavesolverfields::DampingVectorx, + wavesolverfields::DampingVectory, + wavesolverfields::DampingVectorz, + wavesolverfields::ElasticFreeSurfaceNodeIndicator >( getName() ); FaceManager & faceManager = mesh.getFaceManager(); - faceManager.registerField< elasticfields::ElasticFreeSurfaceFaceIndicator >( getName() ); + faceManager.registerField< wavesolverfields::ElasticFreeSurfaceFaceIndicator >( getName() ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< CellElementSubRegion >( [&]( CellElementSubRegion & subRegion ) { - subRegion.registerField< elasticfields::ElasticVelocityVp >( getName() ); - subRegion.registerField< elasticfields::ElasticVelocityVs >( getName() ); - subRegion.registerField< elasticfields::ElasticDensity >( getName() ); - subRegion.registerField< elasticfields::Lambda >( getName() ); - subRegion.registerField< elasticfields::Mu >( getName() ); - - subRegion.registerField< elasticfields::Stresstensorxx >( getName()); - subRegion.registerField< elasticfields::Stresstensoryy >( getName()); - subRegion.registerField< elasticfields::Stresstensorzz >( getName()); - subRegion.registerField< elasticfields::Stresstensorxy >( getName()); - subRegion.registerField< elasticfields::Stresstensorxz >( getName()); - subRegion.registerField< elasticfields::Stresstensoryz >( getName()); + subRegion.registerField< wavesolverfields::ElasticVelocityVp >( getName() ); + subRegion.registerField< wavesolverfields::ElasticVelocityVs >( getName() ); + subRegion.registerField< wavesolverfields::ElasticDensity >( getName() ); + subRegion.registerField< wavesolverfields::Lambda >( getName() ); + subRegion.registerField< wavesolverfields::Mu >( getName() ); + + subRegion.registerField< wavesolverfields::Stresstensorxx >( getName()); + subRegion.registerField< wavesolverfields::Stresstensoryy >( getName()); + subRegion.registerField< wavesolverfields::Stresstensorzz >( getName()); + subRegion.registerField< wavesolverfields::Stresstensorxy >( getName()); + subRegion.registerField< wavesolverfields::Stresstensorxz >( getName()); + subRegion.registerField< wavesolverfields::Stresstensoryz >( getName()); finiteElement::FiniteElementBase const & fe = subRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); @@ -156,12 +156,12 @@ void ElasticFirstOrderWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) constexpr localIndex numNodesPerElem = FE_TYPE::numNodes; - subRegion.getField< elasticfields::Stresstensorxx >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< elasticfields::Stresstensoryy >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< elasticfields::Stresstensorzz >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< elasticfields::Stresstensorxy >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< elasticfields::Stresstensorxz >().resizeDimension< 1 >( numNodesPerElem ); - subRegion.getField< elasticfields::Stresstensoryz >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< wavesolverfields::Stresstensorxx >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< wavesolverfields::Stresstensoryy >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< wavesolverfields::Stresstensorzz >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< wavesolverfields::Stresstensorxy >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< wavesolverfields::Stresstensorxz >().resizeDimension< 1 >( numNodesPerElem ); + subRegion.getField< wavesolverfields::Stresstensoryz >().resizeDimension< 1 >( numNodesPerElem ); } ); @@ -296,6 +296,31 @@ void ElasticFirstOrderWaveEquationSEM::precomputeSourceAndReceiverTerm( MeshLeve } ); } + +void ElasticFirstOrderWaveEquationSEM::addSourceToRightHandSide( integer const & cycleNumber, arrayView1d< real32 > const rhs ) +{ + arrayView2d< localIndex const > const sourceNodeIds = m_sourceNodeIds.toViewConst(); + arrayView2d< real64 const > const sourceConstants = m_sourceConstants.toViewConst(); + arrayView1d< localIndex const > const sourceIsAccessible = m_sourceIsAccessible.toViewConst(); + arrayView2d< real32 const > const sourceValue = m_sourceValue.toViewConst(); + + GEOS_THROW_IF( cycleNumber > sourceValue.size( 0 ), + getDataContext() << ": Too many steps compared to array size", + std::runtime_error ); + + forAll< serialPolicy >( m_sourceConstants.size( 0 ), [=] ( localIndex const isrc ) + { + if( sourceIsAccessible[isrc] == 1 ) + { + for( localIndex inode = 0; inode < m_sourceConstants.size( 1 ); ++inode ) + { + real32 const localIncrement = sourceConstants[isrc][inode] * sourceValue[cycleNumber][isrc]; + RAJA::atomicAdd< ATOMIC_POLICY >( &rhs[sourceNodeIds[isrc][inode]], localIncrement ); + } + } + } ); +} + void ElasticFirstOrderWaveEquationSEM::initializePostInitialConditionsPreSubGroups() { @@ -324,18 +349,18 @@ void ElasticFirstOrderWaveEquationSEM::initializePostInitialConditionsPreSubGrou ArrayOfArraysView< localIndex const > const facesToNodes = faceManager.nodeList().toViewConst(); // mass matrix to be computed in this function - arrayView1d< real32 > const mass = nodeManager.getField< elasticfields::ElasticMassVector >(); + arrayView1d< real32 > const mass = nodeManager.getField< wavesolverfields::ElasticMassVector >(); mass.zero(); /// damping matrix to be computed for each dof in the boundary of the mesh - arrayView1d< real32 > const dampingx = nodeManager.getField< elasticfields::DampingVectorx >(); - arrayView1d< real32 > const dampingy = nodeManager.getField< elasticfields::DampingVectory >(); - arrayView1d< real32 > const dampingz = nodeManager.getField< elasticfields::DampingVectorz >(); + arrayView1d< real32 > const dampingx = nodeManager.getField< wavesolverfields::DampingVectorx >(); + arrayView1d< real32 > const dampingy = nodeManager.getField< wavesolverfields::DampingVectory >(); + arrayView1d< real32 > const dampingz = nodeManager.getField< wavesolverfields::DampingVectorz >(); dampingx.zero(); dampingy.zero(); dampingz.zero(); /// get array of indicators: 1 if face is on the free surface; 0 otherwise - arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< elasticfields::ElasticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< wavesolverfields::ElasticFreeSurfaceFaceIndicator >(); mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const, CellElementSubRegion & elementSubRegion ) @@ -343,9 +368,9 @@ void ElasticFirstOrderWaveEquationSEM::initializePostInitialConditionsPreSubGrou arrayView2d< localIndex const, cells::NODE_MAP_USD > const elemsToNodes = elementSubRegion.nodeList(); arrayView2d< localIndex const > const elemsToFaces = elementSubRegion.faceList(); - arrayView1d< real32 > const density = elementSubRegion.getField< elasticfields::ElasticDensity >(); - arrayView1d< real32 > const velocityVp = elementSubRegion.getField< elasticfields::ElasticVelocityVp >(); - arrayView1d< real32 > const velocityVs = elementSubRegion.getField< elasticfields::ElasticVelocityVs >(); + arrayView1d< real32 > const density = elementSubRegion.getField< wavesolverfields::ElasticDensity >(); + arrayView1d< real32 > const velocityVp = elementSubRegion.getField< wavesolverfields::ElasticVelocityVp >(); + arrayView1d< real32 > const velocityVs = elementSubRegion.getField< wavesolverfields::ElasticVelocityVs >(); finiteElement::FiniteElementBase const & fe = elementSubRegion.getReference< finiteElement::FiniteElementBase >( getDiscretizationName() ); @@ -393,17 +418,17 @@ void ElasticFirstOrderWaveEquationSEM::applyFreeSurfaceBC( real64 const time, Do FaceManager & faceManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getFaceManager(); NodeManager & nodeManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getNodeManager(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< wavesolverfields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< wavesolverfields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< wavesolverfields::Displacementz_np1 >(); ArrayOfArraysView< localIndex const > const faceToNodeMap = faceManager.nodeList().toViewConst(); /// set array of indicators: 1 if a face is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< elasticfields::ElasticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< wavesolverfields::ElasticFreeSurfaceFaceIndicator >(); /// set array of indicators: 1 if a node is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< elasticfields::ElasticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< wavesolverfields::ElasticFreeSurfaceNodeIndicator >(); freeSurfaceFaceIndicator.zero(); freeSurfaceNodeIndicator.zero(); @@ -498,15 +523,15 @@ real64 ElasticFirstOrderWaveEquationSEM::explicitStepInternal( real64 const & ti arrayView2d< wsCoordType const, nodes::REFERENCE_POSITION_USD > const X = nodeManager.getField< fields::referencePosition32 >().toViewConst(); - arrayView1d< real32 const > const mass = nodeManager.getField< elasticfields::ElasticMassVector >(); - arrayView1d< real32 > const dampingx = nodeManager.getField< elasticfields::DampingVectorx >(); - arrayView1d< real32 > const dampingy = nodeManager.getField< elasticfields::DampingVectory >(); - arrayView1d< real32 > const dampingz = nodeManager.getField< elasticfields::DampingVectorz >(); + arrayView1d< real32 const > const mass = nodeManager.getField< wavesolverfields::ElasticMassVector >(); + arrayView1d< real32 > const dampingx = nodeManager.getField< wavesolverfields::DampingVectorx >(); + arrayView1d< real32 > const dampingy = nodeManager.getField< wavesolverfields::DampingVectory >(); + arrayView1d< real32 > const dampingz = nodeManager.getField< wavesolverfields::DampingVectorz >(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< wavesolverfields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< wavesolverfields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< wavesolverfields::Displacementz_np1 >(); mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const regionIndex, CellElementSubRegion & elementSubRegion ) @@ -514,19 +539,19 @@ real64 ElasticFirstOrderWaveEquationSEM::explicitStepInternal( real64 const & ti arrayView2d< localIndex const, cells::NODE_MAP_USD > const & elemsToNodes = elementSubRegion.nodeList(); - arrayView1d< real32 const > const velocityVp = elementSubRegion.getField< elasticfields::ElasticVelocityVp >(); - arrayView1d< real32 const > const velocityVs = elementSubRegion.getField< elasticfields::ElasticVelocityVs >(); - arrayView1d< real32 const > const density = elementSubRegion.getField< elasticfields::ElasticDensity >(); + arrayView1d< real32 const > const velocityVp = elementSubRegion.getField< wavesolverfields::ElasticVelocityVp >(); + arrayView1d< real32 const > const velocityVs = elementSubRegion.getField< wavesolverfields::ElasticVelocityVs >(); + arrayView1d< real32 const > const density = elementSubRegion.getField< wavesolverfields::ElasticDensity >(); - arrayView1d< real32 > const lambda = elementSubRegion.getField< elasticfields::Lambda >(); - arrayView1d< real32 > const mu = elementSubRegion.getField< elasticfields::Mu >(); + arrayView1d< real32 > const lambda = elementSubRegion.getField< wavesolverfields::Lambda >(); + arrayView1d< real32 > const mu = elementSubRegion.getField< wavesolverfields::Mu >(); - arrayView2d< real32 > const stressxx = elementSubRegion.getField< elasticfields::Stresstensorxx >(); - arrayView2d< real32 > const stressyy = elementSubRegion.getField< elasticfields::Stresstensoryy >(); - arrayView2d< real32 > const stresszz = elementSubRegion.getField< elasticfields::Stresstensorzz >(); - arrayView2d< real32 > const stressxy = elementSubRegion.getField< elasticfields::Stresstensorxy >(); - arrayView2d< real32 > const stressxz = elementSubRegion.getField< elasticfields::Stresstensorxz >(); - arrayView2d< real32 > const stressyz = elementSubRegion.getField< elasticfields::Stresstensoryz >(); + arrayView2d< real32 > const stressxx = elementSubRegion.getField< wavesolverfields::Stresstensorxx >(); + arrayView2d< real32 > const stressyy = elementSubRegion.getField< wavesolverfields::Stresstensoryy >(); + arrayView2d< real32 > const stresszz = elementSubRegion.getField< wavesolverfields::Stresstensorzz >(); + arrayView2d< real32 > const stressxy = elementSubRegion.getField< wavesolverfields::Stresstensorxy >(); + arrayView2d< real32 > const stressxz = elementSubRegion.getField< wavesolverfields::Stresstensorxz >(); + arrayView2d< real32 > const stressyz = elementSubRegion.getField< wavesolverfields::Stresstensoryz >(); finiteElement::FiniteElementBase const & @@ -605,10 +630,10 @@ real64 ElasticFirstOrderWaveEquationSEM::explicitStepInternal( real64 const & ti } ); FieldIdentifiers fieldsToBeSync; - fieldsToBeSync.addFields( FieldLocation::Node, { elasticfields::Displacementx_np1::key(), elasticfields::Displacementy_np1::key(), elasticfields::Displacementz_np1::key()} ); - fieldsToBeSync.addElementFields( {elasticfields::Stresstensorxx::key(), elasticfields::Stresstensoryy::key(), elasticfields::Stresstensorzz::key(), - elasticfields::Stresstensorxy::key(), - elasticfields::Stresstensorxz::key(), elasticfields::Stresstensoryz::key()}, regionNames ); + fieldsToBeSync.addFields( FieldLocation::Node, { wavesolverfields::Displacementx_np1::key(), wavesolverfields::Displacementy_np1::key(), wavesolverfields::Displacementz_np1::key()} ); + fieldsToBeSync.addElementFields( {wavesolverfields::Stresstensorxx::key(), wavesolverfields::Stresstensoryy::key(), wavesolverfields::Stresstensorzz::key(), + wavesolverfields::Stresstensorxy::key(), + wavesolverfields::Stresstensorxz::key(), wavesolverfields::Stresstensoryz::key()}, regionNames ); CommunicationTools & syncFields = CommunicationTools::getInstance(); @@ -651,12 +676,12 @@ void ElasticFirstOrderWaveEquationSEM::cleanup( real64 const time_n, mesh.getElemManager().forElementSubRegions< CellElementSubRegion >( regionNames, [&]( localIndex const regionIndex, CellElementSubRegion & elementSubRegion ) { - arrayView2d< real32 const > const stressxx = elementSubRegion.getField< elasticfields::Stresstensorxx >(); - arrayView2d< real32 const > const stressyy = elementSubRegion.getField< elasticfields::Stresstensoryy >(); - arrayView2d< real32 const > const stresszz = elementSubRegion.getField< elasticfields::Stresstensorzz >(); - arrayView2d< real32 const > const stressxy = elementSubRegion.getField< elasticfields::Stresstensorxy >(); - arrayView2d< real32 const > const stressxz = elementSubRegion.getField< elasticfields::Stresstensorxz >(); - arrayView2d< real32 const > const stressyz = elementSubRegion.getField< elasticfields::Stresstensoryz >(); + arrayView2d< real32 const > const stressxx = elementSubRegion.getField< wavesolverfields::Stresstensorxx >(); + arrayView2d< real32 const > const stressyy = elementSubRegion.getField< wavesolverfields::Stresstensoryy >(); + arrayView2d< real32 const > const stresszz = elementSubRegion.getField< wavesolverfields::Stresstensorzz >(); + arrayView2d< real32 const > const stressxy = elementSubRegion.getField< wavesolverfields::Stresstensorxy >(); + arrayView2d< real32 const > const stressxz = elementSubRegion.getField< wavesolverfields::Stresstensorxz >(); + arrayView2d< real32 const > const stressyz = elementSubRegion.getField< wavesolverfields::Stresstensoryz >(); arrayView2d< real32 > const sigmaxxReceivers = m_sigmaxxNp1AtReceivers.toView(); arrayView2d< real32 > const sigmayyReceivers = m_sigmayyNp1AtReceivers.toView(); @@ -678,9 +703,9 @@ void ElasticFirstOrderWaveEquationSEM::cleanup( real64 const time_n, m_receiverIsLocal, m_nsamplesSeismoTrace, sigmaxyReceivers, sigmaxzReceivers, sigmayzReceivers ); } ); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< wavesolverfields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< wavesolverfields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< wavesolverfields::Displacementz_np1 >(); // compute the seismic traces since last step. arrayView2d< real32 > const uxReceivers = m_displacementxNp1AtReceivers.toView(); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.hpp b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.hpp index b96d8697412..746051b0028 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.hpp @@ -21,7 +21,7 @@ #define SRC_CORECOMPONENTS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASTICFIRSTORDERWAVEEQUATIONSEM_HPP_ #include "mesh/MeshFields.hpp" -#include "ElasticFields.hpp" +#include "WaveSolverBaseFields.hpp" #include "WaveSolverBase.hpp" @@ -35,6 +35,8 @@ class ElasticFirstOrderWaveEquationSEM : public WaveSolverBase using EXEC_POLICY = parallelDevicePolicy< >; using ATOMIC_POLICY = parallelDeviceAtomic; + static constexpr real64 epsilonLoc = 1e-8; + ElasticFirstOrderWaveEquationSEM( const std::string & name, Group * const parent ); @@ -69,6 +71,15 @@ class ElasticFirstOrderWaveEquationSEM : public WaveSolverBase DomainPartition & domain, bool const computeGradient ) override; + /**@}*/ + + /** + * @brief Multiply the precomputed term by the Ricker and add to the right-hand side + * @param cycleNumber the cycle number/step number of evaluation of the source + * @param rhs the right hand side vector to be computed + */ + void addSourceToRightHandSide( integer const & cycleNumber, arrayView1d< real32 > const rhs ); + /** * @brief Initialize Perfectly Matched Layer (PML) information @@ -180,4 +191,4 @@ class ElasticFirstOrderWaveEquationSEM : public WaveSolverBase } /* namespace geos */ -#endif /* SRC_CORECOMPONENTS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASTICFIRSTORDERWAVEEQUATIONSEM_HPP_ */ +#endif /* SRC_CORECOMPONENTS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASSTICWAVEEQUATIONSEM_HPP_ */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEMKernel.hpp b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEMKernel.hpp index 8ab22a047d1..dd074679238 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEMKernel.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEMKernel.hpp @@ -628,4 +628,4 @@ struct VelocityComputation } // namespace geos -#endif //GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASTICFIRSTORDERWAVEEQUATIONSEMKERNEL_HPP_ +#endif //GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ElasticFirstOrderWaveEquationSEMKERNEL_HPP_ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.cpp b/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.cpp index 1d9e8fed402..3c91681eee6 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.cpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.cpp @@ -31,7 +31,6 @@ namespace geos { using namespace dataRepository; -using namespace fields; ElasticWaveEquationSEM::ElasticWaveEquationSEM( const std::string & name, Group * const parent ): @@ -99,7 +98,7 @@ void ElasticWaveEquationSEM::initializePreSubGroups() WaveSolverBase::initializePreSubGroups(); - localIndex const numNodesPerElem = WaveSolverBase::getNumNodesPerElem(); + localIndex const numNodesPerElem = getNumNodesPerElem(); localIndex const numSourcesGlobal = m_sourceCoordinates.size( 0 ); m_sourceConstantsx.resize( numSourcesGlobal, numNodesPerElem ); @@ -123,37 +122,37 @@ void ElasticWaveEquationSEM::registerDataOnMesh( Group & meshBodies ) { NodeManager & nodeManager = mesh.getNodeManager(); - nodeManager.registerField< elasticfields::Displacementx_nm1, - elasticfields::Displacementy_nm1, - elasticfields::Displacementz_nm1, - elasticfields::Displacementx_n, - elasticfields::Displacementy_n, - elasticfields::Displacementz_n, - elasticfields::Displacementx_np1, - elasticfields::Displacementy_np1, - elasticfields::Displacementz_np1, - elasticfields::ForcingRHSx, - elasticfields::ForcingRHSy, - elasticfields::ForcingRHSz, - elasticfields::ElasticMassVector, - elasticfields::DampingVectorx, - elasticfields::DampingVectory, - elasticfields::DampingVectorz, - elasticfields::StiffnessVectorx, - elasticfields::StiffnessVectory, - elasticfields::StiffnessVectorz, - elasticfields::ElasticFreeSurfaceNodeIndicator >( getName() ); + nodeManager.registerField< fields::Displacementx_nm1, + fields::Displacementy_nm1, + fields::Displacementz_nm1, + fields::Displacementx_n, + fields::Displacementy_n, + fields::Displacementz_n, + fields::Displacementx_np1, + fields::Displacementy_np1, + fields::Displacementz_np1, + fields::ForcingRHSx, + fields::ForcingRHSy, + fields::ForcingRHSz, + fields::ElasticMassVector, + fields::DampingVectorx, + fields::DampingVectory, + fields::DampingVectorz, + fields::StiffnessVectorx, + fields::StiffnessVectory, + fields::StiffnessVectorz, + fields::ElasticFreeSurfaceNodeIndicator >( getName() ); FaceManager & faceManager = mesh.getFaceManager(); - faceManager.registerField< elasticfields::ElasticFreeSurfaceFaceIndicator >( getName() ); + faceManager.registerField< fields::ElasticFreeSurfaceFaceIndicator >( getName() ); ElementRegionManager & elemManager = mesh.getElemManager(); elemManager.forElementSubRegions< CellElementSubRegion >( [&]( CellElementSubRegion & subRegion ) { - subRegion.registerField< elasticfields::ElasticVelocityVp >( getName() ); - subRegion.registerField< elasticfields::ElasticVelocityVs >( getName() ); - subRegion.registerField< elasticfields::ElasticDensity >( getName() ); + subRegion.registerField< fields::ElasticVelocityVp >( getName() ); + subRegion.registerField< fields::ElasticVelocityVs >( getName() ); + subRegion.registerField< fields::ElasticDensity >( getName() ); } ); } ); @@ -365,18 +364,18 @@ void ElasticWaveEquationSEM::initializePostInitialConditionsPreSubGroups() arrayView2d< wsCoordType const, nodes::REFERENCE_POSITION_USD > const nodeCoords = nodeManager.getField< fields::referencePosition32 >().toViewConst(); // mass matrix to be computed in this function - arrayView1d< real32 > const mass = nodeManager.getField< elasticfields::ElasticMassVector >(); + arrayView1d< real32 > const mass = nodeManager.getField< fields::ElasticMassVector >(); mass.zero(); /// damping matrix to be computed for each dof in the boundary of the mesh - arrayView1d< real32 > const dampingx = nodeManager.getField< elasticfields::DampingVectorx >(); - arrayView1d< real32 > const dampingy = nodeManager.getField< elasticfields::DampingVectory >(); - arrayView1d< real32 > const dampingz = nodeManager.getField< elasticfields::DampingVectorz >(); + arrayView1d< real32 > const dampingx = nodeManager.getField< fields::DampingVectorx >(); + arrayView1d< real32 > const dampingy = nodeManager.getField< fields::DampingVectory >(); + arrayView1d< real32 > const dampingz = nodeManager.getField< fields::DampingVectorz >(); dampingx.zero(); dampingy.zero(); dampingz.zero(); /// get array of indicators: 1 if face is on the free surface; 0 otherwise - arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< elasticfields::ElasticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex const > const freeSurfaceFaceIndicator = faceManager.getField< fields::ElasticFreeSurfaceFaceIndicator >(); arrayView1d< integer const > const & facesDomainBoundaryIndicator = faceManager.getDomainBoundaryIndicator(); ArrayOfArraysView< localIndex const > const facesToNodes = faceManager.nodeList().toViewConst(); arrayView2d< real64 const > const faceNormal = faceManager.faceNormal(); @@ -392,9 +391,9 @@ void ElasticWaveEquationSEM::initializePostInitialConditionsPreSubGroups() computeTargetNodeSet( elemsToNodes, elementSubRegion.size(), fe.getNumQuadraturePoints() ); - arrayView1d< real32 const > const density = elementSubRegion.getField< elasticfields::ElasticDensity >(); - arrayView1d< real32 const > const velocityVp = elementSubRegion.getField< elasticfields::ElasticVelocityVp >(); - arrayView1d< real32 const > const velocityVs = elementSubRegion.getField< elasticfields::ElasticVelocityVs >(); + arrayView1d< real32 const > const density = elementSubRegion.getField< fields::ElasticDensity >(); + arrayView1d< real32 const > const velocityVp = elementSubRegion.getField< fields::ElasticVelocityVp >(); + arrayView1d< real32 const > const velocityVs = elementSubRegion.getField< fields::ElasticVelocityVs >(); finiteElement::FiniteElementDispatchHandler< SEM_FE_TYPES >::dispatch3D( fe, [&] ( auto const finiteElement ) { @@ -438,23 +437,23 @@ void ElasticWaveEquationSEM::applyFreeSurfaceBC( real64 const time, DomainPartit FaceManager & faceManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getFaceManager(); NodeManager & nodeManager = domain.getMeshBody( 0 ).getMeshLevel( m_discretizationName ).getNodeManager(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); - arrayView1d< real32 > const ux_n = nodeManager.getField< elasticfields::Displacementx_n >(); - arrayView1d< real32 > const uy_n = nodeManager.getField< elasticfields::Displacementy_n >(); - arrayView1d< real32 > const uz_n = nodeManager.getField< elasticfields::Displacementz_n >(); - arrayView1d< real32 > const ux_nm1 = nodeManager.getField< elasticfields::Displacementx_nm1 >(); - arrayView1d< real32 > const uy_nm1 = nodeManager.getField< elasticfields::Displacementy_nm1 >(); - arrayView1d< real32 > const uz_nm1 = nodeManager.getField< elasticfields::Displacementz_nm1 >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< fields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< fields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< fields::Displacementz_np1 >(); + arrayView1d< real32 > const ux_n = nodeManager.getField< fields::Displacementx_n >(); + arrayView1d< real32 > const uy_n = nodeManager.getField< fields::Displacementy_n >(); + arrayView1d< real32 > const uz_n = nodeManager.getField< fields::Displacementz_n >(); + arrayView1d< real32 > const ux_nm1 = nodeManager.getField< fields::Displacementx_nm1 >(); + arrayView1d< real32 > const uy_nm1 = nodeManager.getField< fields::Displacementy_nm1 >(); + arrayView1d< real32 > const uz_nm1 = nodeManager.getField< fields::Displacementz_nm1 >(); ArrayOfArraysView< localIndex const > const faceToNodeMap = faceManager.nodeList().toViewConst(); /// set array of indicators: 1 if a face is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< elasticfields::ElasticFreeSurfaceFaceIndicator >(); + arrayView1d< localIndex > const freeSurfaceFaceIndicator = faceManager.getField< fields::ElasticFreeSurfaceFaceIndicator >(); /// set array of indicators: 1 if a node is on on free surface; 0 otherwise - arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< elasticfields::ElasticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex > const freeSurfaceNodeIndicator = nodeManager.getField< fields::ElasticFreeSurfaceNodeIndicator >(); fsManager.apply( time, @@ -536,30 +535,30 @@ void ElasticWaveEquationSEM::computeUnknowns( real64 const &, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const mass = nodeManager.getField< elasticfields::ElasticMassVector >(); - arrayView1d< real32 const > const dampingx = nodeManager.getField< elasticfields::DampingVectorx >(); - arrayView1d< real32 const > const dampingy = nodeManager.getField< elasticfields::DampingVectory >(); - arrayView1d< real32 const > const dampingz = nodeManager.getField< elasticfields::DampingVectorz >(); - arrayView1d< real32 > const stiffnessVectorx = nodeManager.getField< elasticfields::StiffnessVectorx >(); - arrayView1d< real32 > const stiffnessVectory = nodeManager.getField< elasticfields::StiffnessVectory >(); - arrayView1d< real32 > const stiffnessVectorz = nodeManager.getField< elasticfields::StiffnessVectorz >(); - - arrayView1d< real32 > const ux_nm1 = nodeManager.getField< elasticfields::Displacementx_nm1 >(); - arrayView1d< real32 > const uy_nm1 = nodeManager.getField< elasticfields::Displacementy_nm1 >(); - arrayView1d< real32 > const uz_nm1 = nodeManager.getField< elasticfields::Displacementz_nm1 >(); - arrayView1d< real32 > const ux_n = nodeManager.getField< elasticfields::Displacementx_n >(); - arrayView1d< real32 > const uy_n = nodeManager.getField< elasticfields::Displacementy_n >(); - arrayView1d< real32 > const uz_n = nodeManager.getField< elasticfields::Displacementz_n >(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); + arrayView1d< real32 const > const mass = nodeManager.getField< fields::ElasticMassVector >(); + arrayView1d< real32 const > const dampingx = nodeManager.getField< fields::DampingVectorx >(); + arrayView1d< real32 const > const dampingy = nodeManager.getField< fields::DampingVectory >(); + arrayView1d< real32 const > const dampingz = nodeManager.getField< fields::DampingVectorz >(); + arrayView1d< real32 > const stiffnessVectorx = nodeManager.getField< fields::StiffnessVectorx >(); + arrayView1d< real32 > const stiffnessVectory = nodeManager.getField< fields::StiffnessVectory >(); + arrayView1d< real32 > const stiffnessVectorz = nodeManager.getField< fields::StiffnessVectorz >(); + + arrayView1d< real32 > const ux_nm1 = nodeManager.getField< fields::Displacementx_nm1 >(); + arrayView1d< real32 > const uy_nm1 = nodeManager.getField< fields::Displacementy_nm1 >(); + arrayView1d< real32 > const uz_nm1 = nodeManager.getField< fields::Displacementz_nm1 >(); + arrayView1d< real32 > const ux_n = nodeManager.getField< fields::Displacementx_n >(); + arrayView1d< real32 > const uy_n = nodeManager.getField< fields::Displacementy_n >(); + arrayView1d< real32 > const uz_n = nodeManager.getField< fields::Displacementz_n >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< fields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< fields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< fields::Displacementz_np1 >(); /// get array of indicators: 1 if node on free surface; 0 otherwise - arrayView1d< localIndex const > const freeSurfaceNodeIndicator = nodeManager.getField< elasticfields::ElasticFreeSurfaceNodeIndicator >(); + arrayView1d< localIndex const > const freeSurfaceNodeIndicator = nodeManager.getField< fields::ElasticFreeSurfaceNodeIndicator >(); - arrayView1d< real32 > const rhsx = nodeManager.getField< elasticfields::ForcingRHSx >(); - arrayView1d< real32 > const rhsy = nodeManager.getField< elasticfields::ForcingRHSy >(); - arrayView1d< real32 > const rhsz = nodeManager.getField< elasticfields::ForcingRHSz >(); + arrayView1d< real32 > const rhsx = nodeManager.getField< fields::ForcingRHSx >(); + arrayView1d< real32 > const rhsy = nodeManager.getField< fields::ForcingRHSy >(); + arrayView1d< real32 > const rhsz = nodeManager.getField< fields::ForcingRHSz >(); auto kernelFactory = elasticWaveEquationSEMKernels::ExplicitElasticSEMFactory( dt ); @@ -610,27 +609,27 @@ void ElasticWaveEquationSEM::synchronizeUnknowns( real64 const & time_n, { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 > const stiffnessVectorx = nodeManager.getField< elasticfields::StiffnessVectorx >(); - arrayView1d< real32 > const stiffnessVectory = nodeManager.getField< elasticfields::StiffnessVectory >(); - arrayView1d< real32 > const stiffnessVectorz = nodeManager.getField< elasticfields::StiffnessVectorz >(); + arrayView1d< real32 > const stiffnessVectorx = nodeManager.getField< fields::StiffnessVectorx >(); + arrayView1d< real32 > const stiffnessVectory = nodeManager.getField< fields::StiffnessVectory >(); + arrayView1d< real32 > const stiffnessVectorz = nodeManager.getField< fields::StiffnessVectorz >(); - arrayView1d< real32 > const ux_nm1 = nodeManager.getField< elasticfields::Displacementx_nm1 >(); - arrayView1d< real32 > const uy_nm1 = nodeManager.getField< elasticfields::Displacementy_nm1 >(); - arrayView1d< real32 > const uz_nm1 = nodeManager.getField< elasticfields::Displacementz_nm1 >(); - arrayView1d< real32 > const ux_n = nodeManager.getField< elasticfields::Displacementx_n >(); - arrayView1d< real32 > const uy_n = nodeManager.getField< elasticfields::Displacementy_n >(); - arrayView1d< real32 > const uz_n = nodeManager.getField< elasticfields::Displacementz_n >(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); + arrayView1d< real32 > const ux_nm1 = nodeManager.getField< fields::Displacementx_nm1 >(); + arrayView1d< real32 > const uy_nm1 = nodeManager.getField< fields::Displacementy_nm1 >(); + arrayView1d< real32 > const uz_nm1 = nodeManager.getField< fields::Displacementz_nm1 >(); + arrayView1d< real32 > const ux_n = nodeManager.getField< fields::Displacementx_n >(); + arrayView1d< real32 > const uy_n = nodeManager.getField< fields::Displacementy_n >(); + arrayView1d< real32 > const uz_n = nodeManager.getField< fields::Displacementz_n >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< fields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< fields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< fields::Displacementz_np1 >(); - arrayView1d< real32 > const rhsx = nodeManager.getField< elasticfields::ForcingRHSx >(); - arrayView1d< real32 > const rhsy = nodeManager.getField< elasticfields::ForcingRHSy >(); - arrayView1d< real32 > const rhsz = nodeManager.getField< elasticfields::ForcingRHSz >(); + arrayView1d< real32 > const rhsx = nodeManager.getField< fields::ForcingRHSx >(); + arrayView1d< real32 > const rhsy = nodeManager.getField< fields::ForcingRHSy >(); + arrayView1d< real32 > const rhsz = nodeManager.getField< fields::ForcingRHSz >(); /// synchronize displacement fields FieldIdentifiers fieldsToBeSync; - fieldsToBeSync.addFields( FieldLocation::Node, { elasticfields::Displacementx_np1::key(), elasticfields::Displacementy_np1::key(), elasticfields::Displacementz_np1::key() } ); + fieldsToBeSync.addFields( FieldLocation::Node, { fields::Displacementx_np1::key(), fields::Displacementy_np1::key(), fields::Displacementz_np1::key() } ); CommunicationTools & syncFields = CommunicationTools::getInstance(); syncFields.synchronizeFields( fieldsToBeSync, @@ -663,23 +662,23 @@ void ElasticWaveEquationSEM::prepareNextTimestep( MeshLevel & mesh ) { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 > const ux_nm1 = nodeManager.getField< elasticfields::Displacementx_nm1 >(); - arrayView1d< real32 > const uy_nm1 = nodeManager.getField< elasticfields::Displacementy_nm1 >(); - arrayView1d< real32 > const uz_nm1 = nodeManager.getField< elasticfields::Displacementz_nm1 >(); - arrayView1d< real32 > const ux_n = nodeManager.getField< elasticfields::Displacementx_n >(); - arrayView1d< real32 > const uy_n = nodeManager.getField< elasticfields::Displacementy_n >(); - arrayView1d< real32 > const uz_n = nodeManager.getField< elasticfields::Displacementz_n >(); - arrayView1d< real32 > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); - arrayView1d< real32 > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); - arrayView1d< real32 > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); + arrayView1d< real32 > const ux_nm1 = nodeManager.getField< fields::Displacementx_nm1 >(); + arrayView1d< real32 > const uy_nm1 = nodeManager.getField< fields::Displacementy_nm1 >(); + arrayView1d< real32 > const uz_nm1 = nodeManager.getField< fields::Displacementz_nm1 >(); + arrayView1d< real32 > const ux_n = nodeManager.getField< fields::Displacementx_n >(); + arrayView1d< real32 > const uy_n = nodeManager.getField< fields::Displacementy_n >(); + arrayView1d< real32 > const uz_n = nodeManager.getField< fields::Displacementz_n >(); + arrayView1d< real32 > const ux_np1 = nodeManager.getField< fields::Displacementx_np1 >(); + arrayView1d< real32 > const uy_np1 = nodeManager.getField< fields::Displacementy_np1 >(); + arrayView1d< real32 > const uz_np1 = nodeManager.getField< fields::Displacementz_np1 >(); - arrayView1d< real32 > const stiffnessVectorx = nodeManager.getField< elasticfields::StiffnessVectorx >(); - arrayView1d< real32 > const stiffnessVectory = nodeManager.getField< elasticfields::StiffnessVectory >(); - arrayView1d< real32 > const stiffnessVectorz = nodeManager.getField< elasticfields::StiffnessVectorz >(); + arrayView1d< real32 > const stiffnessVectorx = nodeManager.getField< fields::StiffnessVectorx >(); + arrayView1d< real32 > const stiffnessVectory = nodeManager.getField< fields::StiffnessVectory >(); + arrayView1d< real32 > const stiffnessVectorz = nodeManager.getField< fields::StiffnessVectorz >(); - arrayView1d< real32 > const rhsx = nodeManager.getField< elasticfields::ForcingRHSx >(); - arrayView1d< real32 > const rhsy = nodeManager.getField< elasticfields::ForcingRHSy >(); - arrayView1d< real32 > const rhsz = nodeManager.getField< elasticfields::ForcingRHSz >(); + arrayView1d< real32 > const rhsx = nodeManager.getField< fields::ForcingRHSx >(); + arrayView1d< real32 > const rhsy = nodeManager.getField< fields::ForcingRHSy >(); + arrayView1d< real32 > const rhsz = nodeManager.getField< fields::ForcingRHSz >(); SortedArrayView< localIndex const > const solverTargetNodesSet = m_solverTargetNodesSet.toViewConst(); @@ -735,12 +734,14 @@ void ElasticWaveEquationSEM::cleanup( real64 const time_n, arrayView1d< string const > const & ) { NodeManager & nodeManager = mesh.getNodeManager(); - arrayView1d< real32 const > const ux_n = nodeManager.getField< elasticfields::Displacementx_n >(); - arrayView1d< real32 const > const ux_np1 = nodeManager.getField< elasticfields::Displacementx_np1 >(); - arrayView1d< real32 const > const uy_n = nodeManager.getField< elasticfields::Displacementy_n >(); - arrayView1d< real32 const > const uy_np1 = nodeManager.getField< elasticfields::Displacementy_np1 >(); - arrayView1d< real32 const > const uz_n = nodeManager.getField< elasticfields::Displacementz_n >(); - arrayView1d< real32 const > const uz_np1 = nodeManager.getField< elasticfields::Displacementz_np1 >(); + arrayView1d< real32 const > const ux_n = nodeManager.getField< fields::Displacementx_n >(); + arrayView1d< real32 const > const ux_np1 = nodeManager.getField< fields::Displacementx_np1 >(); + arrayView1d< real32 const > const uy_n = nodeManager.getField< fields::Displacementy_n >(); + arrayView1d< real32 const > const uy_np1 = nodeManager.getField< fields::Displacementy_np1 >(); + arrayView1d< real32 const > const uz_n = nodeManager.getField< fields::Displacementz_n >(); + arrayView1d< real32 const > const uz_np1 = nodeManager.getField< fields::Displacementz_np1 >(); + + if( m_useDAS == WaveSolverUtils::DASType::none ) { diff --git a/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.hpp b/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.hpp index 74d58e3cfd0..7d803b11a78 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEM.hpp @@ -23,7 +23,6 @@ #include "WaveSolverBase.hpp" #include "mesh/MeshFields.hpp" #include "physicsSolvers/SolverBase.hpp" -#include "ElasticFields.hpp" namespace geos { @@ -35,6 +34,11 @@ class ElasticWaveEquationSEM : public WaveSolverBase using EXEC_POLICY = parallelDevicePolicy< >; using ATOMIC_POLICY = parallelDeviceAtomic; + /** + * @brief Safeguard for timeStep. Used to avoid memory issue due to too small value. + */ + static constexpr real64 epsilonLoc = 1e-8; + ElasticWaveEquationSEM( const std::string & name, Group * const parent ); @@ -216,6 +220,205 @@ class ElasticWaveEquationSEM : public WaveSolverBase }; + +namespace fields +{ + +DECLARE_FIELD( Displacementx_nm1, + "displacementx_nm1", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "x-component of displacement at time n-1." ); + +DECLARE_FIELD( Displacementy_nm1, + "displacementy_nm1", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "y-component of displacement at time n-1." ); + +DECLARE_FIELD( Displacementz_nm1, + "displacementz_nm1", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "z-component of displacement at time n-1." ); + +DECLARE_FIELD( Displacementx_n, + "displacementx_n", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "x-component of displacement at time n." ); + +DECLARE_FIELD( Displacementy_n, + "displacementy_n", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "y-component of displacement at time n." ); + +DECLARE_FIELD( Displacementz_n, + "displacementz_n", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "z-component of displacement at time n." ); + +DECLARE_FIELD( Displacementx_np1, + "displacementx_np1", + array1d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "x-component of displacement at time n+1." ); + +DECLARE_FIELD( Displacementy_np1, + "displacementy_np1", + array1d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "y-component of displacement at time n+1." ); + +DECLARE_FIELD( Displacementz_np1, + "displacementz_np1", + array1d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "z-component of displacement at time n+1." ); + +DECLARE_FIELD( ForcingRHSx, + "rhsx", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "RHS for x-direction" ); + +DECLARE_FIELD( ForcingRHSy, + "rhsy", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "RHS for y-direction" ); + +DECLARE_FIELD( ForcingRHSz, + "rhsz", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "RHS for z-direction" ); + +DECLARE_FIELD( ElasticMassVector, + "elasticMassVector", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Diagonal Mass Matrix." ); + +DECLARE_FIELD( DampingVectorx, + "dampingVectorx", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Diagonal Damping Matrix in x-direction." ); + +DECLARE_FIELD( DampingVectory, + "dampingVectory", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Diagonal Damping Matrix in y-direction." ); + +DECLARE_FIELD( DampingVectorz, + "dampingVectorz", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Diagonal Damping Matrix in z-direction." ); + +DECLARE_FIELD( StiffnessVectorx, + "stiffnessVectorx", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "x-component of stiffness vector." ); + +DECLARE_FIELD( StiffnessVectory, + "stiffnessVectory", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "y-component of stiffness vector." ); + +DECLARE_FIELD( StiffnessVectorz, + "stiffnessVectorz", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "z-component of stiffness vector." ); + +DECLARE_FIELD( ElasticVelocityVp, + "elasticVelocityVp", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "P-waves speed in the cell" ); + +DECLARE_FIELD( ElasticVelocityVs, + "elasticVelocityVs", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "S-waves speed in the cell" ); + +DECLARE_FIELD( ElasticDensity, + "elasticDensity", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Medium density of the cell" ); + +DECLARE_FIELD( ElasticFreeSurfaceFaceIndicator, + "elasticFreeSurfaceFaceIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Free surface indicator, 1 if a face is on free surface 0 otherwise." ); + +DECLARE_FIELD( ElasticFreeSurfaceNodeIndicator, + "elasticFreeSurfaceNodeIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Free surface indicator, 1 if a node is on free surface 0 otherwise." ); + +} + + } /* namespace geos */ #endif /* SRC_CORECOMPONENTS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASSTICWAVEEQUATIONSEM_HPP_ */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEMKernel.hpp b/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEMKernel.hpp index 78b7292eda7..fe7e9d34aa2 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEMKernel.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/ElasticWaveEquationSEMKernel.hpp @@ -21,11 +21,11 @@ #include "finiteElement/kernelInterface/KernelBase.hpp" #include "WaveSolverUtils.hpp" -#include "ElasticFields.hpp" + namespace geos { -using namespace fields; + /// Namespace to contain the elastic wave kernels. namespace elasticWaveEquationSEMKernels { @@ -509,15 +509,15 @@ class ExplicitElasticSEM : public finiteElement::KernelBase< SUBREGION_TYPE, finiteElementSpace, inputConstitutiveType ), m_nodeCoords( nodeManager.getField< fields::referencePosition32 >() ), - m_ux_n( nodeManager.getField< elasticfields::Displacementx_n >() ), - m_uy_n( nodeManager.getField< elasticfields::Displacementy_n >() ), - m_uz_n( nodeManager.getField< elasticfields::Displacementz_n >() ), - m_stiffnessVectorx( nodeManager.getField< elasticfields::StiffnessVectorx >() ), - m_stiffnessVectory( nodeManager.getField< elasticfields::StiffnessVectory >() ), - m_stiffnessVectorz( nodeManager.getField< elasticfields::StiffnessVectorz >() ), - m_density( elementSubRegion.template getField< elasticfields::ElasticDensity >() ), - m_velocityVp( elementSubRegion.template getField< elasticfields::ElasticVelocityVp >() ), - m_velocityVs( elementSubRegion.template getField< elasticfields::ElasticVelocityVs >() ), + m_ux_n( nodeManager.getField< fields::Displacementx_n >() ), + m_uy_n( nodeManager.getField< fields::Displacementy_n >() ), + m_uz_n( nodeManager.getField< fields::Displacementz_n >() ), + m_stiffnessVectorx( nodeManager.getField< fields::StiffnessVectorx >() ), + m_stiffnessVectory( nodeManager.getField< fields::StiffnessVectory >() ), + m_stiffnessVectorz( nodeManager.getField< fields::StiffnessVectorz >() ), + m_density( elementSubRegion.template getField< fields::ElasticDensity >() ), + m_velocityVp( elementSubRegion.template getField< fields::ElasticVelocityVp >() ), + m_velocityVs( elementSubRegion.template getField< fields::ElasticVelocityVs >() ), m_dt( dt ) { GEOS_UNUSED_VAR( edgeManager ); diff --git a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFields.hpp b/src/coreComponents/physicsSolvers/wavePropagation/WaveSolverBaseFields.hpp similarity index 53% rename from src/coreComponents/physicsSolvers/wavePropagation/ElasticFields.hpp rename to src/coreComponents/physicsSolvers/wavePropagation/WaveSolverBaseFields.hpp index 8669c653534..333139c21c1 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/ElasticFields.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/WaveSolverBaseFields.hpp @@ -14,11 +14,11 @@ /** - * @file ElasticFields.hpp + * @file WaveSolverBaseFields.hpp */ -#ifndef GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASTICFIELDS_HPP_ -#define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_ELASTICFIELDS_HPP_ +#ifndef GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_WAVESOLVERBASEFIELDS_HPP_ +#define GEOS_PHYSICSSOLVERS_WAVEPROPAGATION_WAVESOLVERBASEFIELDS_HPP_ #include "common/DataLayouts.hpp" #include "mesh/MeshFields.hpp" @@ -29,128 +29,128 @@ namespace geos namespace fields { -namespace elasticfields +namespace wavesolverfields { -DECLARE_FIELD( Displacementx_nm1, - "displacementx_nm1", +DECLARE_FIELD( Delta, + "delta", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "x-component of displacement at time n-1." ); + "Delta thomsen anisotropy parameter" ); -DECLARE_FIELD( Displacementy_nm1, - "displacementy_nm1", +DECLARE_FIELD( Epsilon, + "epsilon", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "y-component of displacement at time n-1." ); + "Epsilon thomsen anisotropy parameter" ); -DECLARE_FIELD( Displacementz_nm1, - "displacementz_nm1", +DECLARE_FIELD( F, + "f", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "z-component of displacement at time n-1." ); + "f quantity in VTI/TTI Fletcher's equations" ); -DECLARE_FIELD( Displacementx_n, - "displacementx_n", +DECLARE_FIELD( StiffnessVector_p, + "stiffnessVector_p", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "x-component of displacement at time n." ); + "Stiffness vector contains R_h*Pressure_n." ); -DECLARE_FIELD( Displacementy_n, - "displacementy_n", +DECLARE_FIELD( StiffnessVector_q, + "stiffnessVector_q", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "y-component of displacement at time n." ); + "Stiffness vector contains R_h*Pressure_n." ); -DECLARE_FIELD( Displacementz_n, - "displacementz_n", +DECLARE_FIELD( Pressure_np1, + "pressure_np1", array1d< real32 >, 0, - NOPLOT, + LEVEL_0, WRITE_AND_READ, - "z-component of displacement at time n." ); + "Scalar pressure at time n+1." ); -DECLARE_FIELD( Displacementx_np1, - "displacementx_np1", +DECLARE_FIELD( Pressure_p_nm1, + "pressure_p_nm1", array1d< real32 >, 0, - LEVEL_0, + NOPLOT, WRITE_AND_READ, - "x-component of displacement at time n+1." ); + "Scalar pressure at time n-1." ); -DECLARE_FIELD( Displacementy_np1, - "displacementy_np1", +DECLARE_FIELD( Pressure_p_n, + "pressure_p_n", array1d< real32 >, 0, - LEVEL_0, + NOPLOT, WRITE_AND_READ, - "y-component of displacement at time n+1." ); + "Scalar pressure at time n." ); -DECLARE_FIELD( Displacementz_np1, - "displacementz_np1", +DECLARE_FIELD( Pressure_p_np1, + "pressure_p_np1", array1d< real32 >, 0, LEVEL_0, WRITE_AND_READ, - "z-component of displacement at time n+1." ); + "Scalar pressure at time n+1." ); -DECLARE_FIELD( Stresstensorxx, - "stresstensorxx", - array2d< real32 >, +DECLARE_FIELD( Pressure_q_nm1, + "pressure_q_nm1", + array1d< real32 >, 0, - LEVEL_0, + NOPLOT, WRITE_AND_READ, - "xx-components of the stress tensor." ); + "Scalar auxiliary pressure q at time n-1." ); -DECLARE_FIELD( Stresstensoryy, - "stresstensoryy", - array2d< real32 >, +DECLARE_FIELD( Pressure_q_n, + "pressure_q_n", + array1d< real32 >, 0, - LEVEL_0, + NOPLOT, WRITE_AND_READ, - "yy-components of the stress tensor." ); + "Scalar auxiliary pressure q at time n." ); -DECLARE_FIELD( Stresstensorzz, - "stresstensorzz", - array2d< real32 >, +DECLARE_FIELD( Pressure_q_np1, + "pressure_q_np1", + array1d< real32 >, 0, LEVEL_0, WRITE_AND_READ, - "zz-components of the stress tensor." ); + "Scalar auxiliary pressure q at time n+1." ); -DECLARE_FIELD( Stresstensorxy, - "stresstensorxy", +DECLARE_FIELD( Velocity_x, + "velocity_x", array2d< real32 >, 0, LEVEL_0, WRITE_AND_READ, - "xy-components of the stress tensor (symetric of yx-component)." ); + "Velocity in the x-direction." ); -DECLARE_FIELD( Stresstensorxz, - "stresstensorxz", +DECLARE_FIELD( Velocity_y, + "velocity_y", array2d< real32 >, 0, LEVEL_0, WRITE_AND_READ, - "xz-components of the stress tensor (symetric of zx-component)." ); + "Velocity in the y-direction." ); -DECLARE_FIELD( Stresstensoryz, - "stresstensoryz", +DECLARE_FIELD( Velocity_z, + "velocity_z", array2d< real32 >, 0, LEVEL_0, WRITE_AND_READ, - "yz-components of the stress tensor (symetric of zy-component)." ); + "Velocity in the z-direction." ); DECLARE_FIELD( ForcingRHS, "rhs", @@ -160,61 +160,197 @@ DECLARE_FIELD( ForcingRHS, WRITE_AND_READ, "RHS" ); -DECLARE_FIELD( ForcingRHSx, - "rhsx", +DECLARE_FIELD( AcousticMassVector, + "acousticMassVector", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "RHS for x-direction" ); + "Diagonal of the Mass Matrix." ); -DECLARE_FIELD( ForcingRHSy, - "rhsy", +DECLARE_FIELD( DampingVector, + "dampingVector", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "RHS for y-direction" ); + "Diagonal of the Damping Matrix." ); -DECLARE_FIELD( ForcingRHSz, - "rhsz", +DECLARE_FIELD( DampingVector_p, + "dampingVector_p", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "RHS for z-direction" ); + "Diagonal of the Damping Matrix for p terms in p equation." ); -DECLARE_FIELD( ElasticMassVector, - "elasticMassVector", +DECLARE_FIELD( DampingVector_pq, + "dampingVector_pq", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "Diagonal of the Mass Matrix." ); + "Diagonal of the Damping Matrix for q terms in p equation." ); -DECLARE_FIELD( StiffnessVectorx, - "stiffnessVectorx", +DECLARE_FIELD( DampingVector_q, + "dampingVector_q", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "x-component of stiffness vector." ); + "Diagonal of the Damping Matrix for q terms in q equation." ); -DECLARE_FIELD( StiffnessVectory, - "stiffnessVectory", +DECLARE_FIELD( DampingVector_qp, + "dampingVector_qp", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "y-component of stiffness vector." ); + "Diagonal of the Damping Matrix for p terms in q equation." ); -DECLARE_FIELD( StiffnessVectorz, - "stiffnessVectorz", +DECLARE_FIELD( AcousticVelocity, + "acousticVelocity", array1d< real32 >, 0, NOPLOT, WRITE_AND_READ, - "z-component of stiffness vector." ); + "Medium velocity of the cell" ); + +DECLARE_FIELD( AcousticDensity, + "acousticDensity", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Medium density of the cell" ); + +DECLARE_FIELD( AcousticFreeSurfaceFaceIndicator, + "acousticFreeSurfaceFaceIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Free surface indicator, 1 if a face is on free surface 0 otherwise." ); + +DECLARE_FIELD( AcousticFreeSurfaceNodeIndicator, + "acousticFreeSurfaceNodeIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Free surface indicator, 1 if a node is on free surface 0 otherwise." ); + +DECLARE_FIELD( LateralSurfaceFaceIndicator, + "lateralSurfaceFaceIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Free surface indicator, 1 if a face is on a lateral surface 0 otherwise." ); + +DECLARE_FIELD( LateralSurfaceNodeIndicator, + "lateralSurfaceNodeIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Lateral surface indicator, 1 if a face is on a lateral surface 0 otherwise." ); + +DECLARE_FIELD( BottomSurfaceFaceIndicator, + "bottomSurfaceFaceIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Bottom surface indicator, 1 if a face is on the bottom surface 0 otherwise." ); + +DECLARE_FIELD( BottomSurfaceNodeIndicator, + "bottomSurfaceNodeIndicator", + array1d< localIndex >, + 0, + NOPLOT, + WRITE_AND_READ, + "Bottom surface indicator, 1 if a face is on the bottom surface 0 otherwise." ); + +DECLARE_FIELD( ElasticMassVector, + "elasticMassVector", + array1d< real32 >, + 0, + NOPLOT, + WRITE_AND_READ, + "Diagonal of the Mass Matrix." ); + +DECLARE_FIELD( Displacementx_np1, + "displacementx_np1", + array1d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "x-component of displacement at time n+1." ); + +DECLARE_FIELD( Displacementy_np1, + "displacementy_np1", + array1d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "y-component of displacement at time n+1." ); + +DECLARE_FIELD( Displacementz_np1, + "displacementz_np1", + array1d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "z-component of displacement at time n+1." ); + +DECLARE_FIELD( Stresstensorxx, + "stresstensorxx", + array2d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "xx-components of the stress tensor." ); + +DECLARE_FIELD( Stresstensoryy, + "stresstensoryy", + array2d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "yy-components of the stress tensor." ); + +DECLARE_FIELD( Stresstensorzz, + "stresstensorzz", + array2d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "zz-components of the stress tensor." ); + +DECLARE_FIELD( Stresstensorxy, + "stresstensorxy", + array2d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "xy-components of the stress tensor (symetric of yx-component)." ); + +DECLARE_FIELD( Stresstensorxz, + "stresstensorxz", + array2d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "xz-components of the stress tensor (symetric of zx-component)." ); + +DECLARE_FIELD( Stresstensoryz, + "stresstensoryz", + array2d< real32 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "yz-components of the stress tensor (symetric of zy-component)." ); DECLARE_FIELD( DampingVectorx, "dampingVectorx", @@ -303,4 +439,4 @@ DECLARE_FIELD( Mu, } /* namespace geos */ -#endif /* GEOS_PHYSICSSOLVERS_WAVEPROPAGATION__HPP_ELASTICFIELDS */ +#endif /* GEOS_PHYSICSSOLVERS_WAVEPROPAGATION__HPP_WAVESOLVERBASEFIELDS */ diff --git a/src/coreComponents/physicsSolvers/wavePropagation/WaveSolverUtils.hpp b/src/coreComponents/physicsSolvers/wavePropagation/WaveSolverUtils.hpp index 5b9e91dbcb8..a1849fcbca2 100644 --- a/src/coreComponents/physicsSolvers/wavePropagation/WaveSolverUtils.hpp +++ b/src/coreComponents/physicsSolvers/wavePropagation/WaveSolverUtils.hpp @@ -30,6 +30,8 @@ namespace geos struct WaveSolverUtils { static constexpr real64 epsilonLoc = 1e-8; + static constexpr real64 eps64 = std::numeric_limits< real64 >::epsilon(); + static constexpr real32 eps32 = std::numeric_limits< real32 >::epsilon(); using EXEC_POLICY = parallelDevicePolicy< >; using wsCoordType = real32; diff --git a/src/coreComponents/schema/docs/CompositionalMultiphaseFVM.rst b/src/coreComponents/schema/docs/CompositionalMultiphaseFVM.rst index 7202cd18e81..beeff3f3b0a 100644 --- a/src/coreComponents/schema/docs/CompositionalMultiphaseFVM.rst +++ b/src/coreComponents/schema/docs/CompositionalMultiphaseFVM.rst @@ -17,9 +17,6 @@ maxAbsolutePressureChange real64 maxCompFractionChange real64 0.5 Maximum (absolute) change in a component fraction in a Newton iteration maxRelativePressureChange real64 0.5 Maximum (relative) change in pressure in a Newton iteration maxRelativeTemperatureChange real64 0.5 Maximum (relative) change in temperature in a Newton iteration -maxSequentialCompDensChange real64 1 Maximum (absolute) component density change in a sequential iteration, used for outer loop convergence check -maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check -maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check minCompDens real64 1e-10 Minimum allowed global component density miscibleDBC integer 0 Flag for enabling DBC formulation with/without miscibility name groupName required A name is required for any non-unique nodes diff --git a/src/coreComponents/schema/docs/CompositionalMultiphaseHybridFVM.rst b/src/coreComponents/schema/docs/CompositionalMultiphaseHybridFVM.rst index 4cdd10dd766..88c616ae31f 100644 --- a/src/coreComponents/schema/docs/CompositionalMultiphaseHybridFVM.rst +++ b/src/coreComponents/schema/docs/CompositionalMultiphaseHybridFVM.rst @@ -14,9 +14,6 @@ maxAbsolutePressureChange real64 -1 Maximum (a maxCompFractionChange real64 0.5 Maximum (absolute) change in a component fraction in a Newton iteration maxRelativePressureChange real64 0.5 Maximum (relative) change in pressure in a Newton iteration maxRelativeTemperatureChange real64 0.5 Maximum (relative) change in temperature in a Newton iteration -maxSequentialCompDensChange real64 1 Maximum (absolute) component density change in a sequential iteration, used for outer loop convergence check -maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check -maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check minCompDens real64 1e-10 Minimum allowed global component density name groupName required A name is required for any non-unique nodes solutionChangeScalingFactor real64 0.5 Damping factor for solution change targets diff --git a/src/coreComponents/schema/docs/ElasticFirstOrderSEM_other.rst b/src/coreComponents/schema/docs/ElasticFirstOrderSEM_other.rst index a5e6f05623a..d5e3c9c7a50 100644 --- a/src/coreComponents/schema/docs/ElasticFirstOrderSEM_other.rst +++ b/src/coreComponents/schema/docs/ElasticFirstOrderSEM_other.rst @@ -17,12 +17,6 @@ receiverConstants real64_array2d receiverIsLocal integer_array Flag that indicates whether the receiver is local to this MPI rank receiverNodeIds integer_array2d Indices of the nodes (in the right order) for each receiver point receiverRegion integer_array Region containing the receivers -sigmaxxNp1AtReceivers real32_array2d Displacement value at each receiver for each timestep (z-components) -sigmaxyNp1AtReceivers real32_array2d Displacement value at each receiver for each timestep (z-components) -sigmaxzNp1AtReceivers real32_array2d Displacement value at each receiver for each timestep (z-components) -sigmayyNp1AtReceivers real32_array2d Displacement value at each receiver for each timestep (z-components) -sigmayzNp1AtReceivers real32_array2d Displacement value at each receiver for each timestep (z-components) -sigmazzNp1AtReceivers real32_array2d Displacement value at each receiver for each timestep (z-components) sourceConstants real64_array2d Constant part of the source for the nodes listed in m_sourceNodeIds sourceElem integer_array Element containing the sources sourceIsAccessible integer_array Flag that indicates whether the source is local to this MPI rank diff --git a/src/coreComponents/schema/docs/Hydrofracture.rst b/src/coreComponents/schema/docs/Hydrofracture.rst index c65d103f356..8f484061b08 100644 --- a/src/coreComponents/schema/docs/Hydrofracture.rst +++ b/src/coreComponents/schema/docs/Hydrofracture.rst @@ -15,7 +15,6 @@ name groupName required A name is required for any solidSolverName groupNameRef required Name of the solid solver used by the coupled solver surfaceGeneratorName groupNameRef required Name of the surface generator to use in the hydrofracture solver targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. -useQuasiNewton integer 0 (no description available) LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` ========================= ================== ======== ====================================================================================================================================================================================================================================================================================================================== diff --git a/src/coreComponents/schema/docs/NonlinearSolverParameters.rst b/src/coreComponents/schema/docs/NonlinearSolverParameters.rst index 0a48c42e401..c8511aad1ff 100644 --- a/src/coreComponents/schema/docs/NonlinearSolverParameters.rst +++ b/src/coreComponents/schema/docs/NonlinearSolverParameters.rst @@ -16,7 +16,6 @@ lineSearchInterpolationType geos_NonlinearSolverParameters_LineSearchInterpol | * Linear | * Parabolic lineSearchMaxCuts integer 4 Maximum number of line search cuts. -lineSearchStartingIteration integer 0 Iteration when line search starts. logLevel integer 0 Log level maxAllowedResidualNorm real64 1e+09 Maximum value of residual norm that is allowed in a Newton loop maxNumConfigurationAttempts integer 10 Max number of times that the configuration can be changed @@ -33,7 +32,6 @@ normType geos_solverBaseKernels_NormType sequentialConvergenceCriterion geos_NonlinearSolverParameters_SequentialConvergenceCriterion ResidualNorm | Criterion used to check outer-loop convergence in sequential schemes. Valid options: | * ResidualNorm | * NumberOfNonlinearIterations - | * SolutionIncrements subcycling integer 0 Flag to decide whether to iterate between sequentially coupled solvers or not. timeStepCutFactor real64 0.5 Factor by which the time step will be cut if a timestep cut is required. timeStepDecreaseFactor real64 0.5 Factor by which the time step is decreased when the number of Newton iterations is large. diff --git a/src/coreComponents/schema/docs/ProppantTransport.rst b/src/coreComponents/schema/docs/ProppantTransport.rst index c7b0b39c500..7a8c3089ec0 100644 --- a/src/coreComponents/schema/docs/ProppantTransport.rst +++ b/src/coreComponents/schema/docs/ProppantTransport.rst @@ -1,28 +1,26 @@ -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== -Name Type Default Description -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== -allowNegativePressure integer 1 Flag indicating if negative pressure is allowed -bridgingFactor real64 0 Bridging factor used for bridging/screen-out calculation -cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] -criticalShieldsNumber real64 0 Critical Shields number -discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. -frictionCoefficient real64 0.03 Friction coefficient -initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. -isThermal integer 0 Flag indicating whether the problem is thermal or not. -logLevel integer 0 Log level -maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration -maxProppantConcentration real64 0.6 Maximum proppant concentration -maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check -maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check -name groupName required A name is required for any non-unique nodes -proppantDensity real64 2500 Proppant density -proppantDiameter real64 0.0004 Proppant diameter -targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. -updateProppantPacking integer 0 Flag that enables/disables proppant-packing update -LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` -NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +Name Type Default Description +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +allowNegativePressure integer 1 Flag indicating if negative pressure is allowed +bridgingFactor real64 0 Bridging factor used for bridging/screen-out calculation +cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] +criticalShieldsNumber real64 0 Critical Shields number +discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. +frictionCoefficient real64 0.03 Friction coefficient +initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. +isThermal integer 0 Flag indicating whether the problem is thermal or not. +logLevel integer 0 Log level +maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration +maxProppantConcentration real64 0.6 Maximum proppant concentration +name groupName required A name is required for any non-unique nodes +proppantDensity real64 2500 Proppant density +proppantDiameter real64 0.0004 Proppant diameter +targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. +updateProppantPacking integer 0 Flag that enables/disables proppant-packing update +LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` +NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== diff --git a/src/coreComponents/schema/docs/ReactiveCompositionalMultiphaseOBL.rst b/src/coreComponents/schema/docs/ReactiveCompositionalMultiphaseOBL.rst index da7fa66a198..af0ee1e1c5c 100644 --- a/src/coreComponents/schema/docs/ReactiveCompositionalMultiphaseOBL.rst +++ b/src/coreComponents/schema/docs/ReactiveCompositionalMultiphaseOBL.rst @@ -1,31 +1,29 @@ -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== -Name Type Default Description -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== -OBLOperatorsTableFile path required File containing OBL operator values -allowLocalOBLChopping integer 1 Allow keeping solution within OBL limits -allowNegativePressure integer 1 Flag indicating if negative pressure is allowed -cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] -componentNames string_array {} List of component names -discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. -enableEnergyBalance integer required Enable energy balance calculation and temperature degree of freedom -initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. -isThermal integer 0 Flag indicating whether the problem is thermal or not. -logLevel integer 0 Log level -maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration -maxCompFractionChange real64 1 Maximum (absolute) change in a component fraction between two Newton iterations -maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check -maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check -name groupName required A name is required for any non-unique nodes -numComponents integer required Number of components -numPhases integer required Number of phases -phaseNames groupNameRef_array {} List of fluid phases -targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. -transMultExp real64 1 Exponent of dynamic transmissibility multiplier -useDARTSL2Norm integer 1 Use L2 norm calculation similar to one used DARTS -LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` -NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +Name Type Default Description +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +OBLOperatorsTableFile path required File containing OBL operator values +allowLocalOBLChopping integer 1 Allow keeping solution within OBL limits +allowNegativePressure integer 1 Flag indicating if negative pressure is allowed +cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] +componentNames string_array {} List of component names +discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. +enableEnergyBalance integer required Enable energy balance calculation and temperature degree of freedom +initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. +isThermal integer 0 Flag indicating whether the problem is thermal or not. +logLevel integer 0 Log level +maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration +maxCompFractionChange real64 1 Maximum (absolute) change in a component fraction between two Newton iterations +name groupName required A name is required for any non-unique nodes +numComponents integer required Number of components +numPhases integer required Number of phases +phaseNames groupNameRef_array {} List of fluid phases +targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. +transMultExp real64 1 Exponent of dynamic transmissibility multiplier +useDARTSL2Norm integer 1 Use L2 norm calculation similar to one used DARTS +LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` +NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== diff --git a/src/coreComponents/schema/docs/SinglePhaseFVM.rst b/src/coreComponents/schema/docs/SinglePhaseFVM.rst index 6000056c728..1f7ecbc504a 100644 --- a/src/coreComponents/schema/docs/SinglePhaseFVM.rst +++ b/src/coreComponents/schema/docs/SinglePhaseFVM.rst @@ -1,22 +1,20 @@ -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== -Name Type Default Description -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== -allowNegativePressure integer 1 Flag indicating if negative pressure is allowed -cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] -discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. -initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. -isThermal integer 0 Flag indicating whether the problem is thermal or not. -logLevel integer 0 Log level -maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration -maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check -maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check -name groupName required A name is required for any non-unique nodes -targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. -temperature real64 0 Temperature -LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` -NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +Name Type Default Description +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +allowNegativePressure integer 1 Flag indicating if negative pressure is allowed +cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] +discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. +initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. +isThermal integer 0 Flag indicating whether the problem is thermal or not. +logLevel integer 0 Log level +maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration +name groupName required A name is required for any non-unique nodes +targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. +temperature real64 0 Temperature +LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` +NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== diff --git a/src/coreComponents/schema/docs/SinglePhaseHybridFVM.rst b/src/coreComponents/schema/docs/SinglePhaseHybridFVM.rst index 6000056c728..1f7ecbc504a 100644 --- a/src/coreComponents/schema/docs/SinglePhaseHybridFVM.rst +++ b/src/coreComponents/schema/docs/SinglePhaseHybridFVM.rst @@ -1,22 +1,20 @@ -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== -Name Type Default Description -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== -allowNegativePressure integer 1 Flag indicating if negative pressure is allowed -cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] -discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. -initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. -isThermal integer 0 Flag indicating whether the problem is thermal or not. -logLevel integer 0 Log level -maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration -maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check -maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check -name groupName required A name is required for any non-unique nodes -targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. -temperature real64 0 Temperature -LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` -NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +Name Type Default Description +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +allowNegativePressure integer 1 Flag indicating if negative pressure is allowed +cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] +discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. +initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. +isThermal integer 0 Flag indicating whether the problem is thermal or not. +logLevel integer 0 Log level +maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration +name groupName required A name is required for any non-unique nodes +targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. +temperature real64 0 Temperature +LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` +NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== diff --git a/src/coreComponents/schema/docs/SinglePhaseProppantFVM.rst b/src/coreComponents/schema/docs/SinglePhaseProppantFVM.rst index 6000056c728..1f7ecbc504a 100644 --- a/src/coreComponents/schema/docs/SinglePhaseProppantFVM.rst +++ b/src/coreComponents/schema/docs/SinglePhaseProppantFVM.rst @@ -1,22 +1,20 @@ -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== -Name Type Default Description -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== -allowNegativePressure integer 1 Flag indicating if negative pressure is allowed -cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] -discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. -initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. -isThermal integer 0 Flag indicating whether the problem is thermal or not. -logLevel integer 0 Log level -maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration -maxSequentialPressureChange real64 100000 Maximum (absolute) pressure change in a sequential iteration, used for outer loop convergence check -maxSequentialTemperatureChange real64 0.1 Maximum (absolute) temperature change in a sequential iteration, used for outer loop convergence check -name groupName required A name is required for any non-unique nodes -targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. -temperature real64 0 Temperature -LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` -NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` -============================== ================== ======== ======================================================================================================================================================================================================================================================================================================================== +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +Name Type Default Description +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== +allowNegativePressure integer 1 Flag indicating if negative pressure is allowed +cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] +discretization groupNameRef required Name of discretization object (defined in the :ref:`NumericalMethodsManager`) to use for this solver. For instance, if this is a Finite Element Solver, the name of a :ref:`FiniteElement` should be specified. If this is a Finite Volume Method, the name of a :ref:`FiniteVolume` discretization should be specified. +initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. +isThermal integer 0 Flag indicating whether the problem is thermal or not. +logLevel integer 0 Log level +maxAbsolutePressureChange real64 -1 Maximum (absolute) pressure change in a Newton iteration +name groupName required A name is required for any non-unique nodes +targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. +temperature real64 0 Temperature +LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` +NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` +========================= ================== ======== ======================================================================================================================================================================================================================================================================================================================== diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index 3ec4907afa8..30b6086298b 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -1868,8 +1868,6 @@ the relative residual norm satisfies: - - @@ -1892,8 +1890,7 @@ the relative residual norm satisfies: +* NumberOfNonlinearIterations--> @@ -1934,7 +1931,7 @@ the relative residual norm satisfies: - + @@ -2370,12 +2367,6 @@ the relative residual norm satisfies: - - - - - - @@ -2448,12 +2439,6 @@ the relative residual norm satisfies: - - - - - - @@ -2807,8 +2792,6 @@ Equal to 1 for surface conditions, and to 0 for reservoir conditions--> - - @@ -3003,10 +2986,6 @@ Local - Add stabilization only to interiors of macro elements.--> - - - - @@ -3047,10 +3026,6 @@ Local - Add stabilization only to interiors of macro elements.--> - - - - @@ -3085,10 +3060,6 @@ Local - Add stabilization only to interiors of macro elements.--> - - - - @@ -3115,10 +3086,6 @@ Local - Add stabilization only to interiors of macro elements.--> - - - - @@ -3233,10 +3200,6 @@ Local - Add stabilization only to interiors of macro elements.--> - - - - diff --git a/src/coreComponents/schema/schema.xsd.other b/src/coreComponents/schema/schema.xsd.other index 2f28666e192..7293c48421c 100644 --- a/src/coreComponents/schema/schema.xsd.other +++ b/src/coreComponents/schema/schema.xsd.other @@ -810,18 +810,6 @@ - - - - - - - - - - - - diff --git a/src/coreComponents/unitTests/CMakeLists.txt b/src/coreComponents/unitTests/CMakeLists.txt index 3d49c154263..ad8e50cf3fa 100644 --- a/src/coreComponents/unitTests/CMakeLists.txt +++ b/src/coreComponents/unitTests/CMakeLists.txt @@ -11,4 +11,4 @@ add_subdirectory( finiteVolumeTests ) add_subdirectory( fileIOTests ) add_subdirectory( fluidFlowTests ) add_subdirectory( wellsTests ) -add_subdirectory( wavePropagationTests ) +add_subdirectory( wavePropagationTests ) diff --git a/src/coreComponents/unitTests/wavePropagationTests/CMakeLists.txt b/src/coreComponents/unitTests/wavePropagationTests/CMakeLists.txt index a555936aeaf..b95a1dd7e3e 100644 --- a/src/coreComponents/unitTests/wavePropagationTests/CMakeLists.txt +++ b/src/coreComponents/unitTests/wavePropagationTests/CMakeLists.txt @@ -1,7 +1,6 @@ # Specify list of tests set( gtest_geosx_tests testWavePropagation.cpp - testWavePropagationElasticFirstOrder.cpp testWavePropagationDAS.cpp testWavePropagationAcousticFirstOrder.cpp ) diff --git a/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationAcousticFirstOrder.cpp b/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationAcousticFirstOrder.cpp index 2da611b46e7..9b787e6a7ab 100644 --- a/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationAcousticFirstOrder.cpp +++ b/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationAcousticFirstOrder.cpp @@ -22,6 +22,7 @@ #include "mainInterface/GeosxState.hpp" #include "physicsSolvers/PhysicsSolverManager.hpp" #include "physicsSolvers/wavePropagation/WaveSolverBase.hpp" +#include "physicsSolvers/wavePropagation/WaveSolverBaseFields.hpp" #include "physicsSolvers/wavePropagation/AcousticFirstOrderWaveEquationSEM.hpp" #include diff --git a/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationElasticFirstOrder.cpp b/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationElasticFirstOrder.cpp deleted file mode 100644 index f34f65d7a92..00000000000 --- a/src/coreComponents/unitTests/wavePropagationTests/testWavePropagationElasticFirstOrder.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2018-2020 Total, S.A - * Copyright (c) 2020- GEOSX Contributors - * All right reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - -// using some utility classes from the following unit test -#include "unitTests/fluidFlowTests/testCompFlowUtils.hpp" - -#include "common/DataTypes.hpp" -#include "mainInterface/initialization.hpp" -#include "mainInterface/ProblemManager.hpp" -#include "mesh/DomainPartition.hpp" -#include "mainInterface/GeosxState.hpp" -#include "physicsSolvers/PhysicsSolverManager.hpp" -#include "physicsSolvers/wavePropagation/WaveSolverBase.hpp" -#include "physicsSolvers/wavePropagation/ElasticFirstOrderWaveEquationSEM.hpp" - -#include - -using namespace geos; -using namespace geos::dataRepository; -using namespace geos::testing; - -CommandLineOptions g_commandLineOptions; - -// This unit test checks the interpolation done to extract seismic traces from a wavefield. -// It computes a seismogram at a receiver co-located with the source and compares it to the surrounding receivers. -char const * xmlInput = - R"xml( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - )xml"; - -class ElasticFirstOrderWaveEquationSEMTest : public ::testing::Test -{ -public: - - ElasticFirstOrderWaveEquationSEMTest(): - state( std::make_unique< CommandLineOptions >( g_commandLineOptions ) ) - {} - -protected: - - void SetUp() override - { - setupProblemFromXML( state.getProblemManager(), xmlInput ); - } - - static real64 constexpr time = 0.0; - static real64 constexpr dt = 5e-2; - static real64 constexpr eps = std::numeric_limits< real64 >::epsilon(); - - GeosxState state; - ElasticFirstOrderWaveEquationSEM * propagator; -}; - -real64 constexpr ElasticFirstOrderWaveEquationSEMTest::time; -real64 constexpr ElasticFirstOrderWaveEquationSEMTest::dt; -real64 constexpr ElasticFirstOrderWaveEquationSEMTest::eps; - -TEST_F( ElasticFirstOrderWaveEquationSEMTest, SeismoTrace ) -{ - - DomainPartition & domain = state.getProblemManager().getDomainPartition(); - propagator = &state.getProblemManager().getPhysicsSolverManager().getGroup< ElasticFirstOrderWaveEquationSEM >( "elasticFirstOrderSolver" ); - real64 time_n = time; - // run for 1s (20 steps) - for( int i=0; i<20; i++ ) - { - propagator->solverStep( time_n, dt, i, domain ); - time_n += dt; - } - // cleanup (triggers calculation of the remaining seismograms data points) - propagator->cleanup( 1.0, 20, 0, 0, domain ); - - // retrieve seismo - arrayView2d< real32 > const uxReceivers = propagator->getReference< array2d< real32 > >( ElasticFirstOrderWaveEquationSEM::viewKeyStruct::displacementxNp1AtReceiversString() ).toView(); - arrayView2d< real32 > const uyReceivers = propagator->getReference< array2d< real32 > >( ElasticFirstOrderWaveEquationSEM::viewKeyStruct::displacementyNp1AtReceiversString() ).toView(); - arrayView2d< real32 > const uzReceivers = propagator->getReference< array2d< real32 > >( ElasticFirstOrderWaveEquationSEM::viewKeyStruct::displacementzNp1AtReceiversString() ).toView(); - arrayView2d< real32 > const sigmaxxReceivers = propagator->getReference< array2d< real32 > >( ElasticFirstOrderWaveEquationSEM::viewKeyStruct::sigmaxxNp1AtReceiversString()).toView(); - arrayView2d< real32 > const sigmayyReceivers = propagator->getReference< array2d< real32 > >( ElasticFirstOrderWaveEquationSEM::viewKeyStruct::sigmayyNp1AtReceiversString()).toView(); - arrayView2d< real32 > const sigmazzReceivers = propagator->getReference< array2d< real32 > >( ElasticFirstOrderWaveEquationSEM::viewKeyStruct::sigmazzNp1AtReceiversString()).toView(); - // move it to CPU, if needed - uxReceivers.move( LvArray::MemorySpace::host, false ); - uyReceivers.move( LvArray::MemorySpace::host, false ); - uzReceivers.move( LvArray::MemorySpace::host, false ); - sigmaxxReceivers.move( LvArray::MemorySpace::host, false ); - sigmayyReceivers.move( LvArray::MemorySpace::host, false ); - sigmazzReceivers.move( LvArray::MemorySpace::host, false ); - - // check number of seismos and trace length - ASSERT_EQ( uxReceivers.size( 1 ), 10 ); - ASSERT_EQ( uxReceivers.size( 0 ), 21 ); - ASSERT_EQ( uyReceivers.size( 1 ), 10 ); - ASSERT_EQ( uyReceivers.size( 0 ), 21 ); - ASSERT_EQ( uzReceivers.size( 1 ), 10 ); - ASSERT_EQ( uzReceivers.size( 0 ), 21 ); - ASSERT_EQ( sigmaxxReceivers.size( 1 ), 10 ); - ASSERT_EQ( sigmaxxReceivers.size( 0 ), 21 ); - ASSERT_EQ( sigmayyReceivers.size( 1 ), 10 ); - ASSERT_EQ( sigmayyReceivers.size( 0 ), 21 ); - ASSERT_EQ( sigmazzReceivers.size( 1 ), 10 ); - ASSERT_EQ( sigmazzReceivers.size( 0 ), 21 ); - - // check seismo content. The pressure and velocity values cannot be directly checked as the problem is too small. - // Since the basis is linear, check that the seismograms are nonzero (for t>0) and the seismogram at the center is equal - // to the average of the others. - for( int i = 0; i < 21; i++ ) - { - if( i > 0 ) - { - ASSERT_TRUE( std::abs( uxReceivers[i][8] ) > 0 ); - ASSERT_TRUE( std::abs( uyReceivers[i][8] ) > 0 ); - ASSERT_TRUE( std::abs( uzReceivers[i][8] ) > 0 ); - ASSERT_TRUE( std::abs( sigmaxxReceivers[i][8] ) > 0 ); - ASSERT_TRUE( std::abs( sigmayyReceivers[i][8] ) > 0 ); - ASSERT_TRUE( std::abs( sigmazzReceivers[i][8] ) > 0 ); - } - double avgUx = 0; - double avgUy = 0; - double avgUz = 0; - double avgSxx = 0; - double avgSyy = 0; - double avgSzz = 0; - for( int r=0; r<8; r++ ) - { - avgUx += uxReceivers[i][r]; - avgUy += uyReceivers[i][r]; - avgUz += uzReceivers[i][r]; - avgSxx += sigmaxxReceivers[i][r]; - avgSyy += sigmayyReceivers[i][r]; - avgSzz += sigmazzReceivers[i][r]; - } - avgUx /= 8.0; - avgUy /= 8.0; - avgUz /= 8.0; - avgSxx /= 8.0; - avgSyy /= 8.0; - avgSzz /= 8.0; - ASSERT_TRUE( std::abs( uxReceivers[i][8] - avgUx ) < 0.00001 ); - ASSERT_TRUE( std::abs( uyReceivers[i][8] - avgUy ) < 0.00001 ); - ASSERT_TRUE( std::abs( uzReceivers[i][8] - avgUz ) < 0.00001 ); - ASSERT_TRUE( std::abs( sigmaxxReceivers[i][8] - avgSxx ) < 0.00001 ); - ASSERT_TRUE( std::abs( sigmayyReceivers[i][8] - avgSyy ) < 0.00001 ); - ASSERT_TRUE( std::abs( sigmazzReceivers[i][8] - avgSzz ) < 0.00001 ); - } -} - -int main( int argc, char * * argv ) -{ - ::testing::InitGoogleTest( &argc, argv ); - g_commandLineOptions = *geos::basicSetup( argc, argv ); - int const result = RUN_ALL_TESTS(); - geos::basicCleanup(); - return result; -} diff --git a/src/docs/sphinx/developerGuide/Contributing/IntegratedTests.rst b/src/docs/sphinx/developerGuide/Contributing/IntegratedTests.rst index f2e355372c2..034c41cc487 100644 --- a/src/docs/sphinx/developerGuide/Contributing/IntegratedTests.rst +++ b/src/docs/sphinx/developerGuide/Contributing/IntegratedTests.rst @@ -1,631 +1,3 @@ -.. _IntegratedTests: - -############################################################################### -Integrated Tests -############################################################################### - -About -================================= -*integratedTests* is a submodule of *GEOS* residing at the top level of the directory structure. -It defines a set of tests that will run *GEOS* with various *.xml* files and partitioning schemes using the `Automated Test System `_ (ATS). -For each scenario, test performance is evaluated by comparing output files to baselines recorded in this repository. - - -Structure -================================= - -The *integratedTests* repository includes a python package (*integratedTests/scripts/geos_ats_package*) and a directory containing test definitions (*integratedTests/tests/allTests*). -A typical test directory will include an *.ats* file, which defines the behavior of tests or points to child test directories, symbolic links to any required *.xml* files, and a directory containing baseline files. - - -.. code-block:: sh - - - integratedTests/ - - scripts/ - - geos_ats_package - - tests/ - - allTests/ - - main.ats/ - - sedov/ - - baselines/ - - sedov_XX/ - - - - sedov.ats - - sedov.xml - - -High level integrated test results are recorded in the GEOS build directory: */path/to/GEOS/build-xyz/integratedTests/TestsResults*. -These include *.log* and *.err* files for each test and a *test_results.html* summary file, which can be inspected in your browser. - - -.. note:: - Baseline files are stored using the git LFS (large file storage) plugin. - If you followed the suggested commands in the quickstart guide, then your environment is likely already setup. - - However, if lfs is not yet activated, then the contents of baseline files may look something like this: - - 0to100_restart_000000100/rank_0000003.hdf5 - version https://git-lfs.github.com/spec/v1 - oid sha256:09bbe1e92968852cb915b971af35b0bba519fae7cf5934f3abc7b709ea76308c - size 1761208 - - If this is the case, try running the following commands: ``git lfs install`` and ``git lfs pull``. - - - -How to Run the Tests -================================= - -In most cases, integrated tests processes can be triggered in the GEOS build directory with the following commands: - -* `make ats_environment` : Setup the testing environment (Note: this step is run by default for the other make targets). This process will install packages required for testing into the python environment defined in your current host config file. Depending on how you have built GEOS, you may be prompted to manually run the `make pygeosx` command and then re-run this step. -* `make ats_run` : Run all of the available tests (see the below note on testing resources). -* `make ats_clean` : Remove any unnecessary files created during the testing process (.vtk, .hdf5 files, etc.) -* `make ats_rebaseline` : Selectively update the baseline files for tests. -* `make ats_rebaseline_failed` : Automatically update the baseline files for any failed tests. - - -.. note:: - The `make_ats_environment` step will attempt to collect python packages github and pypi, so it should be run from a machine with internet access. - - -.. note:: - Running the integrated tests requires significant computational resources. - If you are on a shared system, we recommend that you only run `make ats_run` within an allocation. - - -.. note:: - We forward any arguments included in the `ATS_ARGUMENTS` cmake variable to the testing system. - For example, on LLNL Lassen builds we select a couple of runtime options: - set(ATS_ARGUMENTS "--ats jsrun_omp --ats jsrun_bind=packed" CACHE STRING "") - - -.. note:: - When running test or creating new baselines on LC systems, we recommend that you use the *quartz-gcc-12-release* configuration - - -Override Test Behavior -------------------------- - -For cases where you need additional control over the integrated tests behavior, you can use this script in your build directory: */path/to/GEOS/build-xyz/integratedTests/geos_ats.sh*. -To run the tests, simply call this script with any desired arguments (see the output of `geos_ats.sh --help` for additional details.) -Common options for this script include: - -* -a/--action : The type of action to run. Common options include: `run`, `veryclean`, `rebaseline`, and `rebaselinefailed`. -* -r/--restartCheckOverrides : Arguments to pass to the restart check function. Common options include: `skip_missing` (ignores any new/missing values in restart files) and `exclude parameter1 parameter2` (ignore these values in restart files). -* --machine : Set the ats machine type name. -* --ats : Pass an argument to the underlying ats framework. Running `geos_ats.sh --ats help` will show you a list of available options for your current machine. - - -Machine Definitions ------------------------- - -On many machines, ATS will automatically identify your machine's configuration and optimize it's performance. -If the tests fail to run or to properly leverage your machine's resources, you may need to manually configure the machine. -If you know the appropriate name for your machine in ATS (or the geos_ats package), then you can run `./geos_ats.sh --machine machine_name --ats help` to see a list of potential configuration options. - -The `openmpi` machine is a common option for non-LC systems. -For a system with 32 cores/node, an appropriate run command might look like: - -.. code-block:: sh - - ./geos_ats.sh --machine openmpi --ats openmpi_numnodes 32 --ats openmpi_args=--report-bindings --ats openmpi_args="--bind-to none" --ats openmpi_install "/path/to/openmpi/installation" - - -.. note:: - In this example, the path given by `openmpi_install` should include `bin/mpirun`. - - -.. note:: - When you have identified a set of arguments that work for your machine, we recommend recording in the `ATS_ARGUMENTS` cmake variable in your system host config file. - - -Test Filtering ------------------------- - -An arbitrary number of filter arguments can be supplied to ATS to limit the number of tests to be run. -Filter arguments should refer to an ATS test variable and use a python-syntax (e.g.: "'some_string' in ats_variable" or "ats_variable<10"). -These can be set via command-line arguments (possible via the `ATS_ARGUMENTS` variable): - -.. code-block:: sh - - ./geos_ats.sh --ats f "np==1" --ats f "'SinglePhaseFVM' in solvers" - - -or via an environment variable (`ATS_FILTER`): - -.. code-block:: sh - - export ATS_FILTER="np==1,'SinglePhaseFVM' in solvers" - - -Common ATS variables that you can filter tests include: - -* np : The number of parallel processes for the test -* label : The name of the test case (e.g.: "sedov_01") -* collection : The name of the parent test folder (e.g.: "contactMechanics") -* checks : A comma-separated list of checks (e.g.: "curve,restart") -* solvers : A comma-separated list of solver types (e.g.: "SinglePhaseFVM,SurfaceGenerator") -* outputs : A comma-separated list of output types (e.g.: "Restart,VTK") -* constitutive_models : A comma-separated list of constitutive model types (e.g.: "CompressibleSinglePhaseFluid,ElasticIsotropic") - - -Inspecting Test Results -================================= - -While the tests are running, the name and size of the active test will be periodically printed out to the screen. -Test result summaries will also be periodically written to the screen and files in */path/to/GEOS/build-xyz/integratedTests/TestsResults*. -For most users, we recommend inspecting the *test_results.html* file in your browser (e.g.: `firefox integratedTests/TestsResults/test_results.html`). -Tests will be organized by their status variable, which includes: - - -* *RUNNING* : The test is currently running -* *NOT RUN* : The test is waiting to start -* *PASSED* : The test and associated checks succeeded -* *FAIL RUN* : The test was unable to run (this often occurs when there is an error in the .ats file) -* *FAIL CHECK* : The test ran to completion, but failed either its restart or curve check -* *SKIPPED* : The test was skipped (likely due to lack of computational resources) - - -If each test ends up in the *PASSED* category, then you are likely done with the integrated testing procedure. -However, if tests end up in any other category, it is your responsibility to address the failure. -If you identify that a failure is due to an expected change in the code (e.g.: adding a new parameter to the xml structure or fixing a bug in an algorithm), you can follow the :ref:`rebaselining procedure `. -Otherwise, you will need to track down and potentially fix the issue that triggered the failure. - - -Test Output --------------------------------- - -Output files from the tests will be stored in the TestResults directory (*/path/to/GEOS/build-xyz/integratedTests/TestsResults*) or in a subdirectory next to their corresponding *.xml* file (*integratedTests/tests/allTests/testGroup/testName_xx*). -Using the serial beam bending test as an example, key output files include: - -* *beamBending_01.data* : Contains the standard output for all test steps. -* *beamBending_01.err* : Contains the standard error output for all test steps. -* *displacement_history.hdf5* : Contains time history information that is used as an input to the curve check step. -* *totalDisplacement_trace.png* : A figure displaying the results of the curve check step. -* *beamBending.geos.out* : Contains the standard output for only the geos run step. -* *beamBending_restart_000000010.restartcheck* which holds all of the standard output for only the *restartcheck* step. -* *beamBending_restart_000000010.0.diff.hdf5* which mimmics the hierarchy of the restart file and has links to the - -See :ref:`Restart Check ` and :ref:`Curve Check ` for further details on the test checks and output files. - - -.. _restart-check: - -Restart Check -================================= - -This check compares a restart file output at the end of a run against a baseline. -The python script that evaluates the diff is included in the `geos_ats` package, and is located here: *integratedTests/scripts/geos_ats_package/geos_ats/helpers/restart_check.py*. -The script compares the two restart files and writes out a *.restart_check* file with the results, as well as exiting with an error code if the files compare differently. -This script takes two positional arguments and a number of optional keyword arguments: - -* file_pattern : Regex specifying the restart file. If the regex matches multiple files the one with the greater string is selected. For example *restart_100.hdf5* wins out over *restart_088.hdf5*. -* baseline_pattern : Regex specifying the baseline file. -* -r/--relative : The relative tolerance for floating point comparison, the default is 0.0. -* -a/--absolute : The absolute tolerance for floating point comparison, the default is 0.0. -* -e/--exclude : A list of regex expressions that match paths in the restart file tree to exclude from comparison. The default is [.*/commandLine]. -* -w/-Werror : Force warnings to be treated as errors, default is false. -* -m/--skip-missing : Ignore values that are missing from either the baseline or target file. - -The itself starts off with a summary of the arguments. -The script begins by recording the arguments to the *.restart_check* file header, and then compares the *.root* restart files to their baseline. -If these match, the script will compare the linked *.hdf5* data files to their baseline. -If the script encounters any differences it will output an error message, and record a summary to the *.restart_check* file. - -The restart check step can be run in parallel using mpi via - -.. code-block:: sh - - mpirun -n NUM_PROCESSES python -m mpi4py restartcheck.py ... - -In this case rank zero reads in the restart root file and then each rank parses a subset of the data files creating a *.$RANK.restartcheck* file. Rank zero then merges the output from each of these files into the main *.restartcheck* file and prints it to standard output. - - -Scalar Error Example -------------------------------- - -An error message for scalar values looks as follows - -.. code-block:: sh - - Error: /datagroup_0000000/sidre/external/ProblemManager/domain/ConstitutiveManager/shale/YoungsModulus - Scalar values of types float64 and float64 differ: 22500000000.0, 10000022399.9. - -Where the first value is the value in the test's restart file and the second is the value in the baseline. - - -Array Error Example --------------------------------- - -An example of an error message for arrays is - -.. code-block:: sh - - Error: /datagroup_0000000/sidre/external/ProblemManager/domain/MeshBodies/mesh1/Level0/nodeManager/TotalDisplacement - Arrays of types float64 and float64 have 1836 values of which 1200 have differing values. - Statistics of the differences greater than 0: - max_index = (1834,), max = 2.47390764755, mean = 0.514503482629, std = 0.70212888881 - -This means that the max absolute difference is 2.47 which occurs at value 1834. Of the values that are not equal the mean absolute difference is 0.514 and the standard deviation of the absolute difference is 0.702. - -When the tolerances are non zero the comparison is a bit more complicated. From the *FileComparison.compareFloatArrays* method documentation - -.. code-block:: sh - - Entries x1 and x2 are considered equal iff - |x1 - x2| <= ATOL or |x1 - x2| <= RTOL * |x2|. - To measure the degree of difference a scaling factor q is introduced. The goal is now to minimize q such that - |x1 - x2| <= ATOL * q or |x1 - x2| <= RTOL * |x2| * q. - If RTOL * |x2| > ATOL - q = |x1 - x2| / (RTOL * |x2|) - else - q = |x1 - x2| / ATOL. - If the maximum value of q over all the entries is greater than 1.0 then the arrays are considered different and an error message is produced. - -An sample error message is - -.. code-block:: sh - - Error: /datagroup_0000000/sidre/external/ProblemManager/domain/MeshBodies/mesh1/Level0/nodeManager/TotalDisplacement - Arrays of types float64 and float64 have 1836 values of which 1200 fail both the relative and absolute tests. - Max absolute difference is at index (1834,): value = 2.07474948094, base_value = 4.54865712848 - Max relative difference is at index (67,): value = 0.00215842135281, base_value = 0.00591771127792 - Statistics of the q values greater than 1.0 defined by the absolute tolerance: N = 1200 - max = 16492717650.3, mean = 3430023217.52, std = 4680859258.74 - Statistics of the q values greater than 1.0 defined by the relative tolerance: N = 0 - - -The *.diff.hdf5* File ---------------------------------- - -Each error generated in the *restartcheck* step creates a group with three children in the *_diff.df5* file. -For example the error given above will generate a hdf5 group - -.. code-block:: sh - - /FILENAME/datagroup_0000000/sidre/external/ProblemManager/domain/MeshBodies/mesh1/Level0/nodeManager/TotalDisplacement - -with datasets *baseline*, *run* and *message* where *FILENAME* is the name of the restart data file being compared. -The *message* dataset contains a copy of the error message while *baseline* is a symbolic link to the baseline dataset and *run* is a sumbolic link to the dataset genereated by the run. -This allows for easy access to the raw data underlying the diff without data duplication. For example if you want to extract the datasets into python you could do this: - -.. code-block:: python - - import h5py - file_path = "beamBending_restart_000000003_diff.hdf5" - path_to_data = "/beamBending_restart_000000011_0000000.hdf5/datagroup_0000000/sidre/external/ProblemManager/domain/MeshBodies/mesh1/Level0/nodeManager/TotalDisplacement" - f = h5py.File("file_path", "r") - error_message = f["path_to_data/message"] - run_data = f["path_to_data/run"][:] - baseline_data = f["path_to_data/baseline"][:] - - # Now run_data and baseline_data are numpy arrays that you may use as you see fit. - rtol = 1e-10 - atol = 1e-15 - absolute_diff = np.abs(run_data - baseline_data) < atol - hybrid_diff = np.close(run_data, baseline_data, rtol, atol) - -When run in parallel each rank creates a *.$RANK.diff.hdf5* file which contains the diff of each data file processed by that rank. - - -.. _curve-check: - -Curve Check -================================= - -This check compares time history (*.hdf5*) curves generated during GEOS execution against baseline and/or analytic solutions. -In contrast to restart checks, curve checks are designed to be flexible with regards to things like mesh construction, time stepping, etc. -The python script that evaluates the diff is included in the `geos_ats` package, and is located here: *integratedTests/scripts/geos_ats_package/geos_ats/helpers/curve_check.py*. -The script renders the curve check results as a figure, and will throw an error if curves are out of tolerance. -This script takes two positional arguments and a number of optional keyword arguments: - -* filename : Path to the time history file. -* baseline : Path to the baseline file. -* -c/--curve : Add a curve to the check (value) or (value, setname). Multiple curves are allowed. -* -s/--script : Python script instructions for curve comparisons (path, function, value, setname) -* -t/--tolerance : The tolerance for each curve check diffs (||x-y||/N). Default is 0. -* -w/-Werror : Force warnings to be treated as errors, default is false. -* -o/--output : Output figures to this directory. Default is ./curve_check_figures -* -n/--n-column : Number of columns to use for the output figure. Default is 1. -* -u/--units-time : Time units for plots. Options include milliseconds, seconds (default), minutes, hours, days, years - - -The curve check script begins by checking the target time history file for expected key values. -These include the time array ("value Time"), location array ("value ReferencePosition setname" or "value elementCenter setname"), and value array ("value setname"). -Any missing values will be recorded as errors in the output. - -The script will then run and record any user-requested python script instructions. -To do this, python will attempt to import the file given by *path* and evaluate the target function, which should accept the time history data as keyword arguments. -Note: to avoid side effects, please ensure that any imported scripts are appropriately guarded if they also allow direct execution: - - -.. code-block:: python - - if __name__ == '__main__': - main() - - -This script will then check the size of the time history items, and will attempt to interpolate them if they do not match (currently, we only support interpolation in time). -Finally, the script will compare the time history values to the baseline values and any script-generated values. -If any curves do not match (`||x-y||/N > tol`), this will be recorded as an error. - - -Item Not Found Errors ----------------------------- - -The following error would indicate that the requested baseline file was not found: - -.. code-block:: sh - - baseline file not found: /path/to/baseline/file - - -This type of error can occur if you are adding a new test, or if you time history output failed. - - - -The following errors would indicate that values were not found in time history files: - -.. code-block:: sh - - Value not found in target file: value - Set not found in target file: setname - Could not find location string for parameter: value, search... - - -The following error would indicate that a given curve exceeded its tolerance compared to script-generated values: - - -.. code-block:: sh - - script_value_setname diff exceeds tolerance: ||t-b||/N=100.0, script_tolerance=1.0 - - - -Adding and Modifying Tests -================================= - - -ATS Configuration File ---------------------------------- - -Files with the *.ats* extension are used to configure the integratedTests. -They use a Python 3.x syntax, and have a set of ATS-related methods loaded into the scope (TestCase, geos, source, etc.). -The root configuration file (*integratedTests/tests/allTests/main.ats*) finds and includes any test definitions in its subdirectories. -The remaining configuration files typically add one or more tests with varying partitioning and input xml files to ATS. - -The *integratedTests/tests/allTests/sedov/sedov.ats* file shows how to add three groups of tests. -This file begins by defining a set of common parameters, which are used later: - -.. literalinclude:: ../../../../../integratedTests/tests/allTests/sedov/sedov.ats - :language: python - :start-after: # Integrated Test Docs Begin Parameters - :end-before: # Integrated Test Docs End Parameters - - -It then enters over the requested partitioning schemes: - -.. literalinclude:: ../../../../../integratedTests/tests/allTests/sedov/sedov.ats - :language: python - :start-after: # Integrated Test Docs Begin Test Loop - :end-before: # Integrated Test Docs End Test Loop - - -and registers a unique test case with the `TestCase` method, which accepts the following arguments: - -* name : The name of the test. The expected convention for this variable is 'testName_N' (N = number of ranks) or 'testName_X_Y_Z' (X, Y, and Z ranks per dimension) -* desc : A brief description of the test -* label : The test label (typically 'auto') -* owner : The point(s) of contact for the test -* independent : A flag indicating whether the test is dependent on another test (typically True) -* steps: A tuple containing the test steps (minimum length = 1) - - -Test steps are run sequentially, and are created with the `geos` method. -If a given test step fails, then it will produce an error and any subsequent steps will be canceled. -This method accepts the following keyword arguments: - -* deck : The name of the input xml file. -* np : The number of parallel processes required to run the step. -* ngpu : The number of GPU devices required to run the step. Note: this argument is typically ignored for geos builds/machines that are not configured to use GPU's. In addition, we typically expect that np=ngpu. -* x_partitions : The number of partitions to use along the x-dimension -* y_partitions : The number of partitions to use along the y-dimension -* z_partitions : The number of partitions to use along the z-dimension -* name : The header to use for output file names -* restartcheck_params : (optional) If this value is defined, run a restart check with these parameters (specified as a dictionary). -* curvecheck_params : (optional) If this value is defined, run a curve check with these parameters (specified as a dictionary). -* restart_file : (optional) The name of a restart file to resume from. To use this option, there must be a previous step that produces the selected restart file. -* baseline_pattern : (optional) The regex for the baseline files to use (required if the name of the step differs from the baseline) -* allow_rebaseline : A flag that indicates whether this step can be rebaselined. This is typically only true for the first step in a test case. - - -Note that a given *.ats* file can create any number of tests and link to any number of input xml files. -For any given test step, we expect that at least one restart or curve check be defined. - - -Creating a New Test Directory -------------------------------- - -To add a new set of tests, create a new folder in the `integratedTests/tests/allTests*` directory. -This folder needs to include at least one *.ats* file to be included in the integrated tests. -Using the sedov example, after creating *sedov.ats* the directory should look like - -.. code-block:: sh - - - integratedTests/tests/allTests/sedov/ - - sedov.ats - - sedov.xml (this file should be a symbolic link to a GEOS input file located somewhere within */path/to/GEOS/inputFiles*) - -At this point you should run the integrated tests (in the build directory run: `make ats_run`). -Assuming that the new *geos* step for your test case was successful, the subsequent *restartcheck* step will fail because the baselines have not yet been created. -At this point the directory should look like this: - -.. code-block:: sh - - - integratedTests/tests/allTests/sedov/ - - sedov/ - - ... - - ... - - sedov.ats - - sedov.xml - - ... - - -You can then follow the steps in the next section to record the initial baseline files. - - -.. _rebaselining-tests: - -Rebaselining Tests ----------------------------- - -Occasionally you may need to add or update baseline files in the repository (possibly due to feature changes in the code). -This process is called rebaselining. -We suggest the following workflow: - - -Step 1 -^^^^^^^^^ - -In the GEOS repository, create or checkout a branch with your modifications: - -.. code-block:: sh - - cd /path/to/GEOS - git checkout -b user/feature/newFeature - - -Add your changes, confirm that they produce the expected results, and get approval for a pull request. -If your branch needs to be rebaselined, make sure to indicate this in your pull request with the appropriate Label. - - -Step 2 -^^^^^^^^^ - -Go to the integratedTests submodule, checkout and pull develop, and create a branch with the same name as the one in the main GEOS repository: - -.. code-block:: sh - - cd /path/to/GEOS/integratedTests - git checkout develop - git pull - git checkout -b user/feature/newFeature - - -Step 3 -^^^^^^^^^ - -Go back to your GEOS build directory and run the integrated tests: - -.. code-block:: sh - - # Note: on shared machines, run these commands in an allocation - cd /path/to/GEOS/build-dir/ - make ats_run - - -Inspect the test results that fail and determine which need to be **legitimately** rebaselined. -Arbitrarily changing baselines defeats the purpose of the integrated tests. -In your PR discussion, please identify which tests will change and any unusual behavior. - - -Step 4 -^^^^^^^^^ - -We can then rebaseline the tests. -In most cases, you will want to rebaseline all of the tests marked as **FAILED**. -To do this you can run this command in the build directory: - -.. code-block:: sh - - make ats_rebaseline_failed - - -Otherwise, you can run the following command, and select whether tests should be rebaselined one at a time via a ``[y/n]`` prompt. - -.. code-block:: sh - - make ats_rebaseline_failed - - -Make sure to only answer ``y`` to the tests that you actually want to rebaseline, otherwise correct baselines for already passing tests will still be updated and bloat your pull request and repository size. - - -Step 5 -^^^^^^^^^ - -Confirm that the new baselines are working as expected. -You can do this by cleaning the test directories and re-running the tests: - -.. code-block:: sh - - # Note: on shared machines, run these commands in an allocation - cd /path/to/GEOS/build-dir/ - make ats_clean - make ats_run - - -At this point you should pass all the integratedTests. - - -Step 6 -^^^^^^^^^ - -Clean out unnecessary files and add new ones to the branch: - -.. code-block:: sh - - cd /path/to/GEOS/build-dir/ - make ats_clean - - # Check for new or modified files - cd /path/to/GEOS/integratedTests - git status - - # Add new or modified files - git add file_a file_b ... - git commit -m "Updating baselines" - git push origin user/feature/newFeature - - -Step 6 -^^^^^^^^^ - -If you haven't already done so, create a merge request for your integratedTests branch. -Once you have received approval for your PR and are ready to continue, you can click merge the branch by clicking the button on github. - -You should then checkout the develop branch of integratedTests and pull the new changes. - -.. code-block:: sh - - cd /path/to/GEOS/integratedTests - git checkout develop - git pull - - -You then need to update the integratedTests 'hash' in your associated GEOS branch. - -.. code-block:: sh - - cd /path/to/GEOS/ - git add integratedTests - git commit -m "Updating the integratedTests hash" - git push origin user/feature/newFeature - - -At this point, you will need to wait for the CI/CD tests to run on github. -After they succeed, you can merge your branch into develop using the button on github. - - - -Tips -======= - - -**Parallel Tests**: On some development machines geosxats won't run parallel tests by default (e.g. on an linux laptop or workstation), and as a result many baselines will be skipped. -We highly recommend running tests and rebaselining on an MPI-aware platform. - -**Filtering Checks**: A common reason for rebaselining is that you have changed the name of an XML node in the input files. -While the baselines may be numerically identical, the restarts will fail because they contain different node names. -In this situation, it can be useful to add a filter to the restart check script using the *geos_ats.sh* script (see the `-e` and `-m` options in :ref:`Override Test Behavior` ) +.. _IntegratedTests: + +.. include:: ../../../../../integratedTests/docs/getting_started.rst From ff37ac95e8351cd8d4c6cd76f39f0626751cabd0 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 22 Feb 2024 09:11:10 +0100 Subject: [PATCH 017/216] begin pvt tables logs - add write in log bool --- .../multifluid/CO2Brine/CO2BrineFluid.cpp | 53 ++++++++++++++--- .../multifluid/CO2Brine/CO2BrineFluid.hpp | 7 ++- .../fluid/multifluid/CO2Brine/PhaseModel.hpp | 12 ++-- .../CO2Brine/functions/BrineEnthalpy.cpp | 18 ++++-- .../CO2Brine/functions/BrineEnthalpy.hpp | 3 +- .../CO2Brine/functions/CO2Enthalpy.cpp | 17 ++++-- .../CO2Brine/functions/CO2Enthalpy.hpp | 3 +- .../CO2Brine/functions/CO2Solubility.cpp | 17 ++++-- .../CO2Brine/functions/CO2Solubility.hpp | 3 +- .../functions/EzrokhiBrineDensity.cpp | 18 ++++-- .../functions/EzrokhiBrineDensity.hpp | 3 +- .../functions/EzrokhiBrineViscosity.cpp | 16 +++-- .../functions/EzrokhiBrineViscosity.hpp | 3 +- .../functions/FenghourCO2Viscosity.cpp | 16 +++-- .../functions/FenghourCO2Viscosity.hpp | 3 +- .../CO2Brine/functions/FlashModelBase.hpp | 1 + .../CO2Brine/functions/NoOpPVTFunction.hpp | 5 +- .../CO2Brine/functions/PVTFunctionBase.hpp | 1 + .../functions/PhillipsBrineDensity.cpp | 16 +++-- .../functions/PhillipsBrineDensity.hpp | 3 +- .../functions/PhillipsBrineViscosity.cpp | 16 +++-- .../functions/PhillipsBrineViscosity.hpp | 3 +- .../functions/SpanWagnerCO2Density.cpp | 16 +++-- .../functions/SpanWagnerCO2Density.hpp | 3 +- .../CO2Brine/functions/WaterDensity.cpp | 17 ++++-- .../CO2Brine/functions/WaterDensity.hpp | 3 +- .../reactive/ReactiveBrineFluid.cpp | 34 +++++++++-- .../reactive/ReactiveBrineFluid.hpp | 8 ++- .../dataRepository/ConduitRestart.hpp | 1 + .../functions/TableFunction.cpp | 59 ++++++++++++++++++- .../functions/TableFunction.hpp | 4 +- .../mainInterface/ProblemManager.cpp | 7 ++- src/coreComponents/schema/schema.xsd | 12 ++++ .../testCO2BrinePVTModels.cpp | 2 + 34 files changed, 326 insertions(+), 77 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 0a02e19ad51..893bc9f5928 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -19,6 +19,7 @@ #include "constitutive/fluid/multifluid/MultiFluidFields.hpp" #include "constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionHelpers.hpp" +#include "constitutive/ConstitutiveManager.hpp" #include "common/Units.hpp" namespace geos @@ -101,6 +102,11 @@ CO2BrineFluid( string const & name, Group * const parent ): setRestartFlags( RestartFlags::NO_WRITE ). setDescription( "Names of solubility tables for each phase" ); + this->registerWrapper( viewKeyStruct::writeCSVFlagString(), &m_writeCSV ). + setInputFlag( InputFlags::OPTIONAL ). + setRestartFlags( RestartFlags::NO_WRITE ). + setDescription( "Write PVT tables into a CSV file" ); + // if this is a thermal model, we need to make sure that the arrays will be properly displayed and saved to restart if( isThermal() ) { @@ -121,19 +127,21 @@ bool CO2BrineFluid< PHASE1, PHASE2, FLASH >::isThermal() const PHASE2::Enthalpy::catalogName() != PVTProps::NoOpPVTFunction::catalogName() ); } - template< typename PHASE1, typename PHASE2, typename FLASH > std::unique_ptr< ConstitutiveBase > CO2BrineFluid< PHASE1, PHASE2, FLASH >:: deliverClone( string const & name, Group * const parent ) const { + std::cout<< "deliverClone" << std::endl; + std::cout<< LvArray::system::stackTrace( true ) << std::endl; + std::unique_ptr< ConstitutiveBase > clone = MultiFluidBase::deliverClone( name, parent ); CO2BrineFluid & newConstitutiveRelation = dynamicCast< CO2BrineFluid & >( *clone ); newConstitutiveRelation.m_p1Index = m_p1Index; newConstitutiveRelation.m_p2Index = m_p2Index; - newConstitutiveRelation.createPVTModels(); + newConstitutiveRelation.createPVTModels(true); return clone; } @@ -201,6 +209,15 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::initializePreSubGroups() template< typename PHASE1, typename PHASE2, typename FLASH > void CO2BrineFluid< PHASE1, PHASE2, FLASH >::postProcessInput() { + + if( m_isClone == true ) + return; + + if( getParent().getName() == "ConstitutiveModels" ) + { + m_isClone = true; + } + MultiFluidBase::postProcessInput(); GEOS_THROW_IF_NE_MSG( numFluidPhases(), 2, @@ -231,12 +248,27 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::postProcessInput() string const expectedGasPhaseNames[] = { "CO2", "co2", "gas", "Gas" }; m_p2Index = PVTFunctionHelpers::findName( m_phaseNames, expectedGasPhaseNames, viewKeyStruct::phaseNamesString() ); - createPVTModels(); + if(m_isClone == true) return; + + if(getParent().getName() == "ConstitutiveModels") + { + m_isClone = true; + } + + createPVTModels(m_isClone); } template< typename PHASE1, typename PHASE2, typename FLASH > -void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() +void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels(bool isClone) { + std::cout << "ConstitutiveManager " << ConstitutiveManager::groupKeyStruct::constitutiveModelsString() << std::endl; + + if( isClone ) + return; + + std::cout << "passed brine" << std::endl; + std::cout << m_isClone << std::endl; + // TODO: get rid of these external files and move into XML, this is too error prone // For now, to support the legacy input, we read all the input parameters at once in the arrays below, and then we create the models @@ -327,11 +359,16 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() InputError ); // then, we are ready to instantiate the phase models + + //temp + m_writeCSV = 1; + std::cout<< "CO2BRINE CALL" << std::endl; + std::cout<< LvArray::system::stackTrace( true ) << std::endl; + std::cout<< Group::getPath() << std::endl; m_phase1 = std::make_unique< PHASE1 >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, - getLogLevel() > 0 && logger::internal::rank==0 ); + m_writeCSV, getLogLevel() > 0 && logger::internal::rank==0 ); m_phase2 = std::make_unique< PHASE2 >( getName() + "_phaseModel2", phase2InputParams, m_componentNames, m_componentMolarWeight, - getLogLevel() > 0 && logger::internal::rank==0 ); - + m_writeCSV, getLogLevel() > 0 && logger::internal::rank==0 ); // 2) Create the flash model if( !m_flashModelParaFile.empty()) { @@ -356,6 +393,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() m_phaseNames, m_componentNames, m_componentMolarWeight, + m_writeCSV, getLogLevel() > 0 && logger::internal::rank==0 ); } } @@ -396,6 +434,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() m_phaseNames, m_componentNames, m_componentMolarWeight, + m_writeCSV, getLogLevel() > 0 && logger::internal::rank==0 ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp index b68851478f2..4611d8554e1 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp @@ -158,6 +158,7 @@ class CO2BrineFluid : public MultiFluidBase static constexpr char const * flashModelParaFileString() { return "flashModelParaFile"; } static constexpr char const * solubilityTablesString() { return "solubilityTableNames"; } static constexpr char const * phasePVTParaFilesString() { return "phasePVTParaFiles"; } + static constexpr char const * writeCSVFlagString() { return "writeCSV"; } }; protected: @@ -168,7 +169,7 @@ class CO2BrineFluid : public MultiFluidBase private: - void createPVTModels(); + void createPVTModels(bool isClone); /// Names of the files defining the viscosity and density models path_array m_phasePVTParaFiles; @@ -185,6 +186,10 @@ class CO2BrineFluid : public MultiFluidBase /// Index of the gas phase integer m_p2Index; + bool m_isClone = false; + + /// + integer m_writeCSV; /// Brine constitutive models std::unique_ptr< PHASE1 > m_phase1; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp index 9b8d794ee58..bebf52d1892 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp @@ -58,22 +58,26 @@ struct PhaseModel array1d< array1d< string > > const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ) + bool const printInCsv, + bool const printInLog ) : density( phaseModelName + "_" + Density::catalogName(), inputParams[InputParamOrder::DENSITY], componentNames, componentMolarWeight, - printTable ), + printInCsv, + printInLog ), viscosity( phaseModelName + "_" + Viscosity::catalogName(), inputParams[InputParamOrder::VISCOSITY], componentNames, componentMolarWeight, - printTable ), + printInCsv, + printInLog ), enthalpy( phaseModelName + "_" + Enthalpy::catalogName(), inputParams[InputParamOrder::ENTHALPY], componentNames, componentMolarWeight, - printTable ) + printInCsv, + printInLog ) {} /// The phase density model diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp index f7856a1696d..d0ad4d18fb8 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp @@ -191,7 +191,8 @@ BrineEnthalpy::BrineEnthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ): + bool const printInCsv, + bool const printInLog ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -204,11 +205,18 @@ BrineEnthalpy::BrineEnthalpy( string const & name, m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); m_brineEnthalpyTable = makeBrineEnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - if( printTable ) + + if( printInCsv || ( printInLog && m_CO2EnthalpyTable->numDimensions() >= 3 ) ) + { + m_CO2EnthalpyTable->printInCSV( m_CO2EnthalpyTable->getName() ); + m_brineEnthalpyTable->printInCSV( m_brineEnthalpyTable->getName() ); + } + if( printInLog && m_CO2EnthalpyTable->numDimensions() <= 2 ) { - m_CO2EnthalpyTable->print( m_CO2EnthalpyTable->getName() ); - m_brineEnthalpyTable->print( m_brineEnthalpyTable->getName() ); + m_CO2EnthalpyTable->printInLog( m_CO2EnthalpyTable->getName() ); + m_brineEnthalpyTable->printInLog( m_brineEnthalpyTable->getName() ); } + } void BrineEnthalpy::checkTablesParameters( real64 const pressure, @@ -232,7 +240,7 @@ BrineEnthalpy::createKernelWrapper() const m_waterIndex ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, BrineEnthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, BrineEnthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp index 1017ed50fea..d7c03854216 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp @@ -91,7 +91,8 @@ class BrineEnthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ); + bool const printInCsv, + bool const printInLog ); static string catalogName() { return "BrineEnthalpy"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp index da8b829f702..f7bbb3c8a7f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp @@ -256,7 +256,8 @@ CO2Enthalpy::CO2Enthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ): + bool const printInCsv, + bool const printInLog ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -265,8 +266,16 @@ CO2Enthalpy::CO2Enthalpy( string const & name, m_CO2Index = PVTFunctionHelpers::findName( componentNames, expectedCO2ComponentNames, "componentNames" ); m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - if( printTable ) - m_CO2EnthalpyTable->print( m_CO2EnthalpyTable->getName() ); + + + if( printInCsv || ( printInLog && m_CO2EnthalpyTable->numDimensions() >= 3 ) ) + { + m_CO2EnthalpyTable->printInCSV( m_CO2EnthalpyTable->getName() ); + } + if( printInLog && m_CO2EnthalpyTable->numDimensions() <= 2 ) + { + m_CO2EnthalpyTable->printInLog( m_CO2EnthalpyTable->getName() ); + } } @@ -308,7 +317,7 @@ CO2Enthalpy::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, CO2Enthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, CO2Enthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp index 5ce85a9645d..035d4b068bd 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp @@ -79,7 +79,8 @@ class CO2Enthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ); + bool const printInCsv, + bool const printInLog ); static string catalogName() { return "CO2Enthalpy"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp index ce4041bce68..784fad48221 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp @@ -365,7 +365,8 @@ CO2Solubility::CO2Solubility( string const & name, string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ): + bool const printInCsv, + bool const printInLog ): FlashModelBase( name, componentNames, componentMolarWeight ) @@ -391,10 +392,16 @@ CO2Solubility::CO2Solubility( string const & name, m_CO2SolubilityTable = makeSolubilityTable( inputParams, m_modelName, FunctionManager::getInstance() ); m_WaterVapourisationTable = makeVapourisationTable( inputParams, m_modelName, FunctionManager::getInstance() ); - if( printTable ) + + if( printInCsv || ( printInLog && m_CO2SolubilityTable->numDimensions() >= 3 ) ) + { + m_CO2SolubilityTable->printInCSV( m_CO2SolubilityTable->getName() ); + m_WaterVapourisationTable->printInCSV( m_WaterVapourisationTable->getName() ); + } + if( printInLog && m_CO2SolubilityTable->numDimensions() <= 2 ) { - m_CO2SolubilityTable->print( m_CO2SolubilityTable->getName() ); - m_WaterVapourisationTable->print( m_WaterVapourisationTable->getName() ); + m_CO2SolubilityTable->printInLog( m_CO2SolubilityTable->getName() ); + m_WaterVapourisationTable->printInLog( m_WaterVapourisationTable->getName() ); } } @@ -418,7 +425,7 @@ CO2Solubility::KernelWrapper CO2Solubility::createKernelWrapper() const m_phaseLiquidIndex ); } -REGISTER_CATALOG_ENTRY( FlashModelBase, CO2Solubility, string const &, string_array const &, string_array const &, string_array const &, array1d< real64 > const &, bool const ) +REGISTER_CATALOG_ENTRY( FlashModelBase, CO2Solubility, string const &, string_array const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp index bc0492008fa..bd0100052a5 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp @@ -109,7 +109,8 @@ class CO2Solubility : public FlashModelBase string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ); + bool const printInCsv, + bool const printInLog ); static string catalogName() { return "CO2Solubility"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp index ec24045a0fa..7272454c628 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp @@ -37,7 +37,8 @@ EzrokhiBrineDensity::EzrokhiBrineDensity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ): + bool const printInCsv, + bool const printInLog ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -51,11 +52,18 @@ EzrokhiBrineDensity::EzrokhiBrineDensity( string const & name, makeCoefficients( inputPara ); m_waterSatDensityTable = PureWaterProperties::makeSaturationDensityTable( m_functionName, FunctionManager::getInstance() ); m_waterSatPressureTable = PureWaterProperties::makeSaturationPressureTable( m_functionName, FunctionManager::getInstance() ); - if( printTable ) + + if( printInCsv || ( printInLog && m_waterSatDensityTable->numDimensions() >= 3 ) ) + { + m_waterSatDensityTable->printInCSV( m_waterSatDensityTable->getName() ); + m_waterSatPressureTable->printInLog( m_waterSatPressureTable->getName() ); + } + if( printInLog && m_waterSatDensityTable->numDimensions() <= 2 ) { - m_waterSatDensityTable->print( m_waterSatDensityTable->getName() ); - m_waterSatPressureTable->print( m_waterSatPressureTable->getName() ); + m_waterSatDensityTable->printInLog( m_waterSatDensityTable->getName() ); + m_waterSatPressureTable->printInLog( m_waterSatPressureTable->getName() ); } + } void EzrokhiBrineDensity::makeCoefficients( string_array const & inputPara ) @@ -102,7 +110,7 @@ EzrokhiBrineDensity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp index 0f66d19ba4e..6b32afd06c6 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp @@ -108,7 +108,8 @@ class EzrokhiBrineDensity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ); + bool const printInCsv, + bool const printInLog ); virtual ~EzrokhiBrineDensity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp index ec63aa192a9..d22f7a10101 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp @@ -37,7 +37,8 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ): + bool const printInCsv, + bool const printInLog ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -50,8 +51,15 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, makeCoefficients( inputPara ); m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); - if( printTable ) - m_waterViscosityTable->print( m_waterViscosityTable->getName() ); + + if( printInCsv || ( printInLog && m_waterViscosityTable->numDimensions() >= 3 ) ) + { + m_waterViscosityTable->printInCSV( m_waterViscosityTable->getName() ); + } + if( printInLog && m_waterViscosityTable->numDimensions() <= 2 ) + { + m_waterViscosityTable->printInLog( m_waterViscosityTable->getName() ); + } } void EzrokhiBrineViscosity::makeCoefficients( string_array const & inputPara ) @@ -93,7 +101,7 @@ EzrokhiBrineViscosity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp index f007f573f83..bf594c814f6 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp @@ -97,7 +97,8 @@ class EzrokhiBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ); + bool const printInCsv, + bool const printInLog ); virtual ~EzrokhiBrineViscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp index 741ab11f3c0..489d9265b1a 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp @@ -141,14 +141,22 @@ FenghourCO2Viscosity::FenghourCO2Viscosity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ) + bool const printInCsv, + bool const printInLog ) : PVTFunctionBase( name, componentNames, componentMolarWeight ) { m_CO2ViscosityTable = makeViscosityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - if( printTable ) - m_CO2ViscosityTable->print( m_CO2ViscosityTable->getName() ); + + if( printInCsv || ( printInLog && m_CO2ViscosityTable->numDimensions() >= 3 ) ) + { + m_CO2ViscosityTable->printInCSV( m_CO2ViscosityTable->getName() ); + } + if( printInLog && m_CO2ViscosityTable->numDimensions() <= 2 ) + { + m_CO2ViscosityTable->printInLog( m_CO2ViscosityTable->getName() ); + } } void FenghourCO2Viscosity::checkTablesParameters( real64 const pressure, @@ -165,7 +173,7 @@ FenghourCO2Viscosity::createKernelWrapper() const *m_CO2ViscosityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, FenghourCO2Viscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, FenghourCO2Viscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp index e8205e8745b..f766849c069 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp @@ -75,7 +75,8 @@ class FenghourCO2Viscosity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ); + bool const printInCsv, + bool const printInLog ); virtual ~FenghourCO2Viscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp index 314f7498dde..f183d8e9618 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp @@ -83,6 +83,7 @@ class FlashModelBase string_array const &, string_array const &, array1d< real64 > const &, + bool const, bool const >; static typename CatalogInterface::CatalogType & getCatalog() { diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp index 47721c43539..3382ae19261 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp @@ -70,12 +70,13 @@ class NoOpPVTFunction : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ) + bool const printInCsv, + bool const printInLog ) : PVTFunctionBase( name, componentNames, componentMolarWeight ) { - GEOS_UNUSED_VAR( inputPara, printTable ); + GEOS_UNUSED_VAR( inputPara, printInCsv, printInLog ); } virtual ~NoOpPVTFunction() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index 7bfea2c71a8..584fb66e324 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -117,6 +117,7 @@ class PVTFunctionBase array1d< string > const &, array1d< string > const &, array1d< real64 > const &, + bool const, bool const >; static typename CatalogInterface::CatalogType & getCatalog() { diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp index 6f57a276661..993fb0bc2b3 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp @@ -176,7 +176,8 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ): + bool const printInCsv, + bool const printInLog ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -188,8 +189,15 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, m_waterIndex = PVTFunctionHelpers::findName( componentNames, expectedWaterComponentNames, "componentNames" ); m_brineDensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - if( printTable ) - m_brineDensityTable->print( m_brineDensityTable->getName() ); + + if( printInCsv || ( printInLog && m_brineDensityTable->numDimensions() >= 3 ) ) + { + m_brineDensityTable->printInCSV( m_brineDensityTable->getName() ); + } + if( printInLog && m_brineDensityTable->numDimensions() <= 2 ) + { + m_brineDensityTable->printInLog( m_brineDensityTable->getName() ); + } } PhillipsBrineDensity::KernelWrapper @@ -208,7 +216,7 @@ void PhillipsBrineDensity::checkTablesParameters( real64 const pressure, m_brineDensityTable->checkCoord( temperature, 1 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp index 85208dd7e70..efc6dee2549 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp @@ -85,7 +85,8 @@ class PhillipsBrineDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ); + bool const printInCsv, + bool const printInLog ); static string catalogName() { return "PhillipsBrineDensity"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp index 0c8c8466256..e7347330109 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp @@ -36,14 +36,22 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ): + bool const printInCsv, + bool const printInLog ): PVTFunctionBase( name, componentNames, componentMolarWeight ) { m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); - if( printTable ) - m_waterViscosityTable->print( m_waterViscosityTable->getName() ); + if( printInCsv || ( printInLog && m_waterViscosityTable->numDimensions() >= 3 ) ) + { + m_waterViscosityTable->printInCSV( m_waterViscosityTable->getName() ); + } + if( printInLog && m_waterViscosityTable->numDimensions() <= 2 ) + { + m_waterViscosityTable->printInLog( m_waterViscosityTable->getName() ); + } + makeCoefficients( inputPara ); } @@ -91,7 +99,7 @@ PhillipsBrineViscosity::createKernelWrapper() const m_coef1 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp index 8edc4419d64..24983952936 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp @@ -83,7 +83,8 @@ class PhillipsBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ); + bool const printInCsv, + bool const printInLog ); virtual ~PhillipsBrineViscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp index 16a4a497ee7..fcc6d5fc18b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp @@ -278,7 +278,8 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ): + bool const printInCsv, + bool const printInLog ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -287,8 +288,15 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, m_CO2Index = PVTFunctionHelpers::findName( componentNames, expectedCO2ComponentNames, "componentNames" ); m_CO2DensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - if( printTable ) - m_CO2DensityTable->print( m_CO2DensityTable->getName() ); + + if( printInCsv || ( printInLog && m_CO2DensityTable->numDimensions() >= 3 ) ) + { + m_CO2DensityTable->printInCSV( m_CO2DensityTable->getName() ); + } + if( printInLog && m_CO2DensityTable->numDimensions() <= 2 ) + { + m_CO2DensityTable->printInLog( m_CO2DensityTable->getName() ); + } } void SpanWagnerCO2Density::checkTablesParameters( real64 const pressure, @@ -306,7 +314,7 @@ SpanWagnerCO2Density::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, SpanWagnerCO2Density, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, SpanWagnerCO2Density, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp index 181559cd7bd..85cf54a7aa0 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp @@ -80,7 +80,8 @@ class SpanWagnerCO2Density : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ); + bool const printInCsv, + bool const printInLog ); static string catalogName() { return "SpanWagnerCO2Density"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp index 244bdcd73c5..e8c764c2b34 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp @@ -36,15 +36,24 @@ WaterDensity::WaterDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ): + bool const printInCsv, + bool const printInLog ): PVTFunctionBase( name, componentNames, componentMolarWeight ) { GEOS_UNUSED_VAR( inputParams ); m_waterDensityTable = PureWaterProperties::makeSaturationDensityTable( m_functionName, FunctionManager::getInstance() ); - if( printTable ) - m_waterDensityTable->print( m_waterDensityTable->getName() ); + + if( printInCsv || ( printInLog && m_waterDensityTable->numDimensions() >= 3 ) ) + { + m_waterDensityTable->printInCSV( m_waterDensityTable->getName() ); + } + if( printInLog && m_waterDensityTable->numDimensions() <= 2 ) + { + m_waterDensityTable->printInLog( m_waterDensityTable->getName() ); + } + } void WaterDensity::checkTablesParameters( real64 const pressure, @@ -61,7 +70,7 @@ WaterDensity::createKernelWrapper() const *m_waterDensityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, WaterDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, WaterDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp index e1bb09c0276..6abd4412deb 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp @@ -75,7 +75,8 @@ class WaterDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printTable ); + bool const printInCsv, + bool const printInLog ); static string catalogName() { return "WaterDensity"; } virtual string getCatalogName() const final { return catalogName(); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp index f118a6a6819..4b87412e979 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp @@ -68,6 +68,11 @@ ReactiveBrineFluid( string const & name, Group * const parent ): setRestartFlags( RestartFlags::NO_WRITE ). setDescription( "Names of the files defining the parameters of the viscosity and density models" ); + this->registerWrapper( viewKeyStruct::writeCSVFlagString(), &m_writeCSV ). + setInputFlag( InputFlags::OPTIONAL ). + setRestartFlags( RestartFlags::NO_WRITE ). + setDescription( "Write PVT tables into a CSV file" ); + // if this is a thermal model, we need to make sure that the arrays will be properly displayed and saved to restart if( isThermal() ) { @@ -93,11 +98,12 @@ std::unique_ptr< ConstitutiveBase > ReactiveBrineFluid< PHASE > :: deliverClone( string const & name, Group * const parent ) const { + std::unique_ptr< ConstitutiveBase > clone = ReactiveMultiFluid::deliverClone( name, parent ); ReactiveBrineFluid & newConstitutiveRelation = dynamicCast< ReactiveBrineFluid & >( *clone ); - newConstitutiveRelation.createPVTModels(); + newConstitutiveRelation.createPVTModels( true ); return clone; } @@ -113,6 +119,14 @@ integer ReactiveBrineFluid< PHASE > ::getWaterPhaseIndex() const template< typename PHASE > void ReactiveBrineFluid< PHASE > ::postProcessInput() { + + if( m_isClone == true ) + return; + + if( getParent().getName() == "ConstitutiveModels" ) + { + m_isClone = true; + } ReactiveMultiFluid::postProcessInput(); GEOS_THROW_IF_NE_MSG( numFluidPhases(), 1, @@ -122,15 +136,27 @@ void ReactiveBrineFluid< PHASE > ::postProcessInput() GEOS_FMT( "{}: invalid number of values in attribute '{}'", getFullName() ), InputError ); - createPVTModels(); + if( m_isClone == true ) + return; + + if( getParent().getName() == "ConstitutiveModels" ) + { + m_isClone = true; + } + + createPVTModels( m_isClone ); } template< typename PHASE > -void ReactiveBrineFluid< PHASE > ::createPVTModels() +void ReactiveBrineFluid< PHASE > ::createPVTModels( bool isClone ) { // TODO: get rid of these external files and move into XML, this is too error prone // For now, to support the legacy input, we read all the input parameters at once in the arrays below, and then we create the models + + if( isClone ) + return; + array1d< array1d< string > > phase1InputParams; phase1InputParams.resize( 3 ); @@ -194,7 +220,7 @@ void ReactiveBrineFluid< PHASE > ::createPVTModels() // then, we are ready to instantiate the phase models m_phase = std::make_unique< PHASE >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, - getLogLevel() > 0 && logger::internal::rank==0 ); + m_writeCSV, getLogLevel() > 0 && logger::internal::rank==0 ); } template< typename PHASE > diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp index 0be8a28c8c9..75f3f98a74f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp @@ -151,6 +151,7 @@ class ReactiveBrineFluid : public ReactiveMultiFluid struct viewKeyStruct : ReactiveMultiFluid::viewKeyStruct { static constexpr char const * phasePVTParaFilesString() { return "phasePVTParaFiles"; } + static constexpr char const * writeCSVFlagString() { return "writeCSV"; } }; protected: @@ -159,11 +160,16 @@ class ReactiveBrineFluid : public ReactiveMultiFluid private: - void createPVTModels(); + void createPVTModels(bool isClone); + + bool m_isClone = false; /// Names of the files defining the viscosity and density models path_array m_phasePVTParaFiles; + /// @brief + integer m_writeCSV; + /// Brine constitutive models std::unique_ptr< PHASE > m_phase; diff --git a/src/coreComponents/dataRepository/ConduitRestart.hpp b/src/coreComponents/dataRepository/ConduitRestart.hpp index feb6ab216ca..360bc673871 100644 --- a/src/coreComponents/dataRepository/ConduitRestart.hpp +++ b/src/coreComponents/dataRepository/ConduitRestart.hpp @@ -55,6 +55,7 @@ struct conduitTypeInfo {}; // Native integer types +CONDUIT_TYPE_INFO( bool, CONDUIT_NATIVE_UNSIGNED_CHAR ); CONDUIT_TYPE_INFO( char, CONDUIT_NATIVE_CHAR ); CONDUIT_TYPE_INFO( signed char, CONDUIT_NATIVE_SIGNED_CHAR ); CONDUIT_TYPE_INFO( unsigned char, CONDUIT_NATIVE_UNSIGNED_CHAR ); diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 0a8751c28ab..ab3a8984eeb 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -20,6 +20,7 @@ #include "codingUtilities/Parsing.hpp" #include "common/DataTypes.hpp" #include "fileIO/Outputs/OutputBase.hpp" +#include "codingUtilities/Table.hpp" #include @@ -181,9 +182,9 @@ void TableFunction::checkCoord( real64 const coord, localIndex const dim ) const SimulationError ); } -void TableFunction::print( std::string const & filename ) const +void TableFunction::printInCSV( string const filename ) const { - std::ofstream os( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); + std::ofstream os( filename + ".csv" ); integer const numDimensions = LvArray::integerConversion< integer >( m_coordinates.size() ); @@ -252,6 +253,60 @@ void TableFunction::print( std::string const & filename ) const os.close(); } +void TableFunction::printInLog( string const filename ) const +{ + + integer const numDimensions = LvArray::integerConversion< integer >( m_coordinates.size() ); + std::cout << "in function printInLog " << numDimensions << std::endl; + if( numDimensions == 1 ) + { + Table pvtTable1D = Table( + { + string( units::getDescription( getDimUnit( 0 ))), + string( units::getDescription( m_valueUnit )) + } ); + pvtTable1D.setTitle( filename ); + arraySlice1d< real64 const > const coords = m_coordinates[0]; + + for( integer idx = 0; idx < m_values.size(); idx++ ) + { + pvtTable1D.addRow< 2 >( coords[idx], m_values[idx] ); + } + + pvtTable1D.draw(); + } + else if( numDimensions == 2 ) + { + arraySlice1d< real64 const > const coordsX = m_coordinates[0]; + arraySlice1d< real64 const > const coordsY = m_coordinates[1]; + integer const nX = coordsX.size(); + integer const nY = coordsY.size(); + std::vector< string > vecDescription; + vecDescription.push_back( string( units::getDescription( getDimUnit( 0 )))); + + for( integer idxY = 0; idxY < nY; idxY++ ) + { + string description = string( units::getDescription( getDimUnit( 1 ))) + "=" + std::to_string( coordsY[idxY] ); + vecDescription.push_back( description ); + } + + Table pvtTable2D = Table( vecDescription ); + + for( integer i = 0; i < nX; i++ ) + { + std::vector< string > vecValues; + vecValues.push_back( std::to_string( coordsX[i] )); + for( integer j = 0; j < nY; j++ ) + { + vecValues.push_back( std::to_string( m_values[ j*nX + i ] )); + } + } + + pvtTable2D.draw(); + } + +} + TableFunction::KernelWrapper TableFunction::createKernelWrapper() const { return { m_interpolationMethod, diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index 216fd08ca51..c35f97d5482 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -321,7 +321,9 @@ class TableFunction : public FunctionBase * @brief Print table into a CSV file (only 1d and 2d tables are supported) * @param filename Filename for output */ - void print( std::string const & filename ) const; + void printInCSV( string const filename ) const; + + void printInLog( string const filename ) const; /** * @brief Create an instance of the kernel wrapper diff --git a/src/coreComponents/mainInterface/ProblemManager.cpp b/src/coreComponents/mainInterface/ProblemManager.cpp index a2e032f567e..eb9bea9f0bc 100644 --- a/src/coreComponents/mainInterface/ProblemManager.cpp +++ b/src/coreComponents/mainInterface/ProblemManager.cpp @@ -150,6 +150,7 @@ Group * ProblemManager::createChild( string const & GEOS_UNUSED_PARAM( childKey void ProblemManager::problemSetup() { GEOS_MARK_FUNCTION; + postProcessInputRecursive(); generateMesh(); @@ -710,15 +711,17 @@ void ProblemManager::importFields() void ProblemManager::applyNumericalMethods() { - + std::cout << "getDomainPartition before " << std::endl; DomainPartition & domain = getDomainPartition(); ConstitutiveManager & constitutiveManager = domain.getGroup< ConstitutiveManager >( groupKeys.constitutiveManager ); + std::cout << "getMeshBodies before " << std::endl; Group & meshBodies = domain.getMeshBodies(); // this contains a key tuple< mesh body name, mesh level name, region name, subregion name> with a value of the number of quadrature // points. + std::cout << "calculateRegionQuadrature before " << std::endl; map< std::tuple< string, string, string, string >, localIndex > const regionQuadrature = calculateRegionQuadrature( meshBodies ); - + std::cout << "calculateRegionQuadrature done " << std::endl; setRegionQuadrature( meshBodies, constitutiveManager, regionQuadrature ); } diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index 3ec4907afa8..142be7dc55f 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -3925,6 +3925,8 @@ The expected format is "{ waterMax, oilMax }", in that order--> + + @@ -3945,6 +3947,8 @@ The expected format is "{ waterMax, oilMax }", in that order--> + + @@ -3965,6 +3969,8 @@ The expected format is "{ waterMax, oilMax }", in that order--> + + @@ -3985,6 +3991,8 @@ The expected format is "{ waterMax, oilMax }", in that order--> + + @@ -4956,6 +4964,8 @@ If you want to do a three-phase simulation, please use instead wettingIntermedia + + @@ -4970,6 +4980,8 @@ If you want to do a three-phase simulation, please use instead wettingIntermedia + + diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp index 723a30af1da..7a7cd9fdeac 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp @@ -366,6 +366,7 @@ std::unique_ptr< MODEL > makePVTFunction( string const & filename, strs, componentNames, componentMolarWeight, + true, true ); // print PVT tables } } @@ -408,6 +409,7 @@ std::unique_ptr< MODEL > makeFlashModel( string const & filename, phaseNames, componentNames, componentMolarWeight, + true, true ); // print PVT tables } } From 628f56bbac948efbe56180b935128ea750c7f394 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 22 Feb 2024 13:49:01 +0100 Subject: [PATCH 018/216] duplication log & csv fixed --- .../multifluid/CO2Brine/CO2BrineFluid.cpp | 56 +++++++------------ .../multifluid/CO2Brine/CO2BrineFluid.hpp | 2 +- .../CO2Brine/functions/BrineEnthalpy.cpp | 4 +- .../CO2Brine/functions/CO2Enthalpy.cpp | 1 - .../functions/EzrokhiBrineDensity.cpp | 2 +- .../functions/EzrokhiBrineViscosity.cpp | 2 +- .../CO2Brine/functions/NoOpPVTFunction.hpp | 2 +- .../functions/PhillipsBrineDensity.cpp | 2 +- .../functions/PhillipsBrineViscosity.cpp | 4 +- .../reactive/ReactiveBrineFluid.cpp | 23 +++----- .../reactive/ReactiveBrineFluid.hpp | 2 +- .../testCO2BrinePVTModels.cpp | 8 +-- 12 files changed, 42 insertions(+), 66 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 893bc9f5928..3224dec1d2f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -133,7 +133,6 @@ CO2BrineFluid< PHASE1, PHASE2, FLASH >:: deliverClone( string const & name, Group * const parent ) const { std::cout<< "deliverClone" << std::endl; - std::cout<< LvArray::system::stackTrace( true ) << std::endl; std::unique_ptr< ConstitutiveBase > clone = MultiFluidBase::deliverClone( name, parent ); @@ -141,7 +140,7 @@ deliverClone( string const & name, Group * const parent ) const newConstitutiveRelation.m_p1Index = m_p1Index; newConstitutiveRelation.m_p2Index = m_p2Index; - newConstitutiveRelation.createPVTModels(true); + newConstitutiveRelation.createPVTModels( true ); return clone; } @@ -209,15 +208,6 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::initializePreSubGroups() template< typename PHASE1, typename PHASE2, typename FLASH > void CO2BrineFluid< PHASE1, PHASE2, FLASH >::postProcessInput() { - - if( m_isClone == true ) - return; - - if( getParent().getName() == "ConstitutiveModels" ) - { - m_isClone = true; - } - MultiFluidBase::postProcessInput(); GEOS_THROW_IF_NE_MSG( numFluidPhases(), 2, @@ -248,28 +238,20 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::postProcessInput() string const expectedGasPhaseNames[] = { "CO2", "co2", "gas", "Gas" }; m_p2Index = PVTFunctionHelpers::findName( m_phaseNames, expectedGasPhaseNames, viewKeyStruct::phaseNamesString() ); - if(m_isClone == true) return; - - if(getParent().getName() == "ConstitutiveModels") + std::cout << "test clone " << m_isClone << std::endl; + std::cout << " getParent().getName() " << getParent().getName() << std::endl; + bool isClone = true; + if( getParent().getName() == "Constitutive" ) { - m_isClone = true; - } + isClone = false; + } - createPVTModels(m_isClone); + createPVTModels( isClone ); } template< typename PHASE1, typename PHASE2, typename FLASH > -void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels(bool isClone) +void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) { - std::cout << "ConstitutiveManager " << ConstitutiveManager::groupKeyStruct::constitutiveModelsString() << std::endl; - - if( isClone ) - return; - - std::cout << "passed brine" << std::endl; - std::cout << m_isClone << std::endl; - - // TODO: get rid of these external files and move into XML, this is too error prone // For now, to support the legacy input, we read all the input parameters at once in the arrays below, and then we create the models array1d< array1d< string > > phase1InputParams; @@ -362,13 +344,17 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels(bool isClone) //temp m_writeCSV = 1; - std::cout<< "CO2BRINE CALL" << std::endl; - std::cout<< LvArray::system::stackTrace( true ) << std::endl; std::cout<< Group::getPath() << std::endl; + std::cout << "test clone int create" << isClone << std::endl; + + bool const writeCSV = !isClone && m_writeCSV; + bool const writeInLog = !isClone && (getLogLevel() > 0 && logger::internal::rank==0); m_phase1 = std::make_unique< PHASE1 >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, - m_writeCSV, getLogLevel() > 0 && logger::internal::rank==0 ); + writeCSV, writeInLog ); m_phase2 = std::make_unique< PHASE2 >( getName() + "_phaseModel2", phase2InputParams, m_componentNames, m_componentMolarWeight, - m_writeCSV, getLogLevel() > 0 && logger::internal::rank==0 ); + writeCSV, writeInLog ); + + // 2) Create the flash model if( !m_flashModelParaFile.empty()) { @@ -393,8 +379,8 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels(bool isClone) m_phaseNames, m_componentNames, m_componentMolarWeight, - m_writeCSV, - getLogLevel() > 0 && logger::internal::rank==0 ); + writeCSV, + writeInLog ); } } else @@ -434,8 +420,8 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels(bool isClone) m_phaseNames, m_componentNames, m_componentMolarWeight, - m_writeCSV, - getLogLevel() > 0 && logger::internal::rank==0 ); + writeCSV, + writeInLog ); } GEOS_THROW_IF( m_flash == nullptr, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp index 4611d8554e1..89ad8cb2af9 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp @@ -186,7 +186,7 @@ class CO2BrineFluid : public MultiFluidBase /// Index of the gas phase integer m_p2Index; - bool m_isClone = false; + bool m_isClone = true; /// integer m_writeCSV; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp index d0ad4d18fb8..97a9b8377d2 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp @@ -209,12 +209,12 @@ BrineEnthalpy::BrineEnthalpy( string const & name, if( printInCsv || ( printInLog && m_CO2EnthalpyTable->numDimensions() >= 3 ) ) { m_CO2EnthalpyTable->printInCSV( m_CO2EnthalpyTable->getName() ); - m_brineEnthalpyTable->printInCSV( m_brineEnthalpyTable->getName() ); + m_brineEnthalpyTable->printInCSV( m_brineEnthalpyTable->getName() ); } if( printInLog && m_CO2EnthalpyTable->numDimensions() <= 2 ) { m_CO2EnthalpyTable->printInLog( m_CO2EnthalpyTable->getName() ); - m_brineEnthalpyTable->printInLog( m_brineEnthalpyTable->getName() ); + m_brineEnthalpyTable->printInLog( m_brineEnthalpyTable->getName() ); } } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp index f7bbb3c8a7f..0bfce5492be 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp @@ -267,7 +267,6 @@ CO2Enthalpy::CO2Enthalpy( string const & name, m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - if( printInCsv || ( printInLog && m_CO2EnthalpyTable->numDimensions() >= 3 ) ) { m_CO2EnthalpyTable->printInCSV( m_CO2EnthalpyTable->getName() ); diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp index 7272454c628..7bbd656b605 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp @@ -110,7 +110,7 @@ EzrokhiBrineDensity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp index d22f7a10101..a21c7aa66fa 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp @@ -52,7 +52,7 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, makeCoefficients( inputPara ); m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); - if( printInCsv || ( printInLog && m_waterViscosityTable->numDimensions() >= 3 ) ) + if( printInCsv || ( printInLog && m_waterViscosityTable->numDimensions() >= 3 ) ) { m_waterViscosityTable->printInCSV( m_waterViscosityTable->getName() ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp index 3382ae19261..02a43ace0f8 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp @@ -70,7 +70,7 @@ class NoOpPVTFunction : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, + bool const printInCsv, bool const printInLog ) : PVTFunctionBase( name, componentNames, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp index 993fb0bc2b3..f86d464d16d 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp @@ -189,7 +189,7 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, m_waterIndex = PVTFunctionHelpers::findName( componentNames, expectedWaterComponentNames, "componentNames" ); m_brineDensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - + if( printInCsv || ( printInLog && m_brineDensityTable->numDimensions() >= 3 ) ) { m_brineDensityTable->printInCSV( m_brineDensityTable->getName() ); diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp index e7347330109..cdba301cae1 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp @@ -43,6 +43,8 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, componentMolarWeight ) { m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); + makeCoefficients( inputPara ); + if( printInCsv || ( printInLog && m_waterViscosityTable->numDimensions() >= 3 ) ) { m_waterViscosityTable->printInCSV( m_waterViscosityTable->getName() ); @@ -51,8 +53,6 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, { m_waterViscosityTable->printInLog( m_waterViscosityTable->getName() ); } - - makeCoefficients( inputPara ); } void PhillipsBrineViscosity::makeCoefficients( string_array const & inputPara ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp index 4b87412e979..d144085d4f7 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp @@ -120,13 +120,6 @@ template< typename PHASE > void ReactiveBrineFluid< PHASE > ::postProcessInput() { - if( m_isClone == true ) - return; - - if( getParent().getName() == "ConstitutiveModels" ) - { - m_isClone = true; - } ReactiveMultiFluid::postProcessInput(); GEOS_THROW_IF_NE_MSG( numFluidPhases(), 1, @@ -136,9 +129,6 @@ void ReactiveBrineFluid< PHASE > ::postProcessInput() GEOS_FMT( "{}: invalid number of values in attribute '{}'", getFullName() ), InputError ); - if( m_isClone == true ) - return; - if( getParent().getName() == "ConstitutiveModels" ) { m_isClone = true; @@ -153,10 +143,6 @@ void ReactiveBrineFluid< PHASE > ::createPVTModels( bool isClone ) // TODO: get rid of these external files and move into XML, this is too error prone // For now, to support the legacy input, we read all the input parameters at once in the arrays below, and then we create the models - - if( isClone ) - return; - array1d< array1d< string > > phase1InputParams; phase1InputParams.resize( 3 ); @@ -217,10 +203,15 @@ void ReactiveBrineFluid< PHASE > ::createPVTModels( bool isClone ) ( PHASE::Enthalpy::catalogName() != PVTProps::NoOpPVTFunction::catalogName() ), GEOS_FMT( "{}: PVT model {} not found in input files", getFullName(), PHASE::Enthalpy::catalogName() ), InputError ); - + std::cout << "reactive brine" << isClone << std::endl; // then, we are ready to instantiate the phase models + + bool const writeCSV = !isClone && m_writeCSV; + bool const writeInLog = !isClone && (getLogLevel() > 0 && logger::internal::rank==0); + m_phase = std::make_unique< PHASE >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, - m_writeCSV, getLogLevel() > 0 && logger::internal::rank==0 ); + writeCSV, writeInLog); + } template< typename PHASE > diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp index 75f3f98a74f..df64ac10c33 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp @@ -162,7 +162,7 @@ class ReactiveBrineFluid : public ReactiveMultiFluid void createPVTModels(bool isClone); - bool m_isClone = false; + bool m_isClone = true; /// Names of the files defining the viscosity and density models path_array m_phasePVTParaFiles; diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp index 7a7cd9fdeac..db3ae90750b 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp @@ -366,8 +366,8 @@ std::unique_ptr< MODEL > makePVTFunction( string const & filename, strs, componentNames, componentMolarWeight, - true, - true ); // print PVT tables + true,// print PVT tables + true ); } } GEOS_ERROR_IF( pvtFunction == nullptr, @@ -409,8 +409,8 @@ std::unique_ptr< MODEL > makeFlashModel( string const & filename, phaseNames, componentNames, componentMolarWeight, - true, - true ); // print PVT tables + true, // print PVT tables + true ); } } GEOS_ERROR_IF( flashModel == nullptr, From e11a2bf70bc468da627fc6a6f58bd836eb8cdc8d Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 23 Feb 2024 14:43:28 +0100 Subject: [PATCH 019/216] CI correction ( uncrustify, missing doc ) --- .../codingUtilities/StringUtilities.hpp | 17 ++++++++-- src/coreComponents/codingUtilities/Table.hpp | 32 +++++++++++-------- src/coreComponents/common/Units.hpp | 8 +++-- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/coreComponents/codingUtilities/StringUtilities.hpp b/src/coreComponents/codingUtilities/StringUtilities.hpp index 2a6b2370f11..d3e3e1e71a6 100644 --- a/src/coreComponents/codingUtilities/StringUtilities.hpp +++ b/src/coreComponents/codingUtilities/StringUtilities.hpp @@ -255,12 +255,23 @@ constexpr bool endsWith( std::string_view str, std::string_view suffix ) str.compare( str.size()-suffix.size(), suffix.size(), suffix ) == 0; } +/** + * @brief Overloading operator (<<) for std::optional. + * + * This function displays the value contained in a std::optional object if one exists. + * Otherwise, it produces no output. + * + * @tparam T The type of the value contained std::optional. + * @param os An output stream (for example, std::cout). + * @param optValue std::optional value to display. + * @return The output stream + */ template< typename T > -std::ostream & operator<<( std::ostream & os, std::optional< T > const & t ) +std::ostream & operator<<( std::ostream & os, std::optional< T > const & optValue ) { - if( t ) + if( optValue ) { - os << t.value(); + os << optValue.value(); } return os; } diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index 397f456c4d4..0dbdbbe31d4 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -30,7 +30,8 @@ class Table enum Alignment { right, left, middle }; - enum MarginValue : integer { + enum MarginValue : integer + { tiny = 0, small = 1, medium = 2, @@ -64,35 +65,38 @@ class Table Table( std::vector< ColumnParam > const & columnParameter ); /** - * @brief Add a row the the table. The number of arguments must match with the number of header values - * @tparam N The Number of values passed to addRow. - * @tparam Args The values passed to addRow. - * @param args + * @brief Add a row the the table. + * + * @param N The number expected by the table + * @param Args The values passed to addRow (can be any type). + * @param args Cell values to be added to the line. + * + * @pre The number of arguments must correspond to the expected number of cells per line (N). */ template< size_t N, typename ... Args > - void addRow( Args const &... args ); + void addRow( Args const & ... args ); /** * @brief Add rows from vectors to the table. - * @param vecRows Vector who contains all table's rows + * @param vecRows Vector who contains all the table rows */ void addRowsFromVectors( std::vector< std::vector< string > > tableRows ); /** - * @brief Write the table into specified stream - * @param os An output stream. By defaut os is set to std::cout. + * @brief Write the table into a specified stream + * @param os An output stream (by default, std::cout) */ void draw( std::ostream & os = std::cout ); /** - * @brief Set the name of the table - * @param tableTitle The name of the table + * @brief Set the table name + * @param tableTitle The table name */ void setTitle( string_view tableTitle ); /** * @brief Set the minimal margin width between row content and borders. - * @param marginType + * @param marginType */ void setMargin( MarginValue marginType ); @@ -118,9 +122,9 @@ class Table }; /** - * @brief Fill the vector \p m_column with values from m_cellsRows who store all values in an unsorted order + * @brief Fill the vector (m_column) with values from m_cellsRows who store all values in an unsorted order */ - void fillColumnsValuesFromCellsRows( ); + void fillColumnsValuesFromCellsRows(); /** * @brief Split all header names by detecting the newline \\n character. diff --git a/src/coreComponents/common/Units.hpp b/src/coreComponents/common/Units.hpp index c91c217a4e1..e71897bc95c 100644 --- a/src/coreComponents/common/Units.hpp +++ b/src/coreComponents/common/Units.hpp @@ -246,12 +246,16 @@ struct GEOS_FMT_NS::formatter< geos::units::TimeFormatInfo > : GEOS_FMT_NS::form }; /** - * @brief Format the std::optional to a string. - * @return return the corresponding value string. If std::optional is empty retun an empty string + * @brief Format to be able to directly use a std::optional. + * @tparam T The type of the value contained std::optional and GEOS_FMT_NS::formatter. */ template< typename T > struct GEOS_FMT_NS::formatter< std::optional< T > > : GEOS_FMT_NS::formatter< T > { + /** + * @brief Format the std::optional to a string. + * @return return the corresponding value string. If std::optional is empty retun an empty string + */ auto format( std::optional< T > const & opt, format_context & ctx ) { if( opt ) From a8f9271393914a5fae9989fa38e089b6e0b1a3f5 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 23 Feb 2024 17:22:54 +0100 Subject: [PATCH 020/216] optionnal added to datatype --- src/coreComponents/common/DataTypes.hpp | 2 +- .../mesh/generators/WellGeneratorBase.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/common/DataTypes.hpp b/src/coreComponents/common/DataTypes.hpp index deba16a2f8a..98e5ecaddec 100644 --- a/src/coreComponents/common/DataTypes.hpp +++ b/src/coreComponents/common/DataTypes.hpp @@ -62,7 +62,7 @@ #include #include #include - +#include /** * top level geosx namespace contains all code that is specific to GEOSX */ diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 1c609a19cc0..115fe51e806 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -528,6 +528,14 @@ void WellGeneratorBase::debugWellGeometry() const { return; } + string sectionOutput; + string sectionName = "Section : Well generation"; + + sectionOutput = GEOS_FMT( "\n{:=^{}}\n", "=", sectionName.size() + 5 ); + sectionOutput += GEOS_FMT( "{:^{}}\n", sectionName, sectionName.size() + 5 ); + sectionOutput += GEOS_FMT( "{:=^{}}\n", "=", sectionName.size() + 5 ); + + std::cout << sectionOutput; std::vector< string > row; std::ostringstream oss; @@ -575,8 +583,8 @@ void WellGeneratorBase::debugWellGeometry() const } table.draw(); - Table tablePerforation = Table( {"Perforation no.", "Coordinates\nlong string", "connected toO" } ); - string titlePerfo = "Peforation table "; + Table tablePerforation = Table( {"Perforation no.", "Coordinates\nlong string", "connected to" } ); + string titlePerfo = "Peforation table"; tablePerforation.setTitle( titlePerfo ); for( globalIndex iperf = 0; iperf < m_numPerforations; ++iperf ) From 9ff17b94b23be0f7c4c631e47493dd679f497dff Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 27 Feb 2024 09:35:02 +0100 Subject: [PATCH 021/216] update doxygen for ci --- src/coreComponents/common/Units.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/coreComponents/common/Units.hpp b/src/coreComponents/common/Units.hpp index e71897bc95c..93651859856 100644 --- a/src/coreComponents/common/Units.hpp +++ b/src/coreComponents/common/Units.hpp @@ -247,13 +247,15 @@ struct GEOS_FMT_NS::formatter< geos::units::TimeFormatInfo > : GEOS_FMT_NS::form /** * @brief Format to be able to directly use a std::optional. - * @tparam T The type of the value contained std::optional and GEOS_FMT_NS::formatter. + * @param T The type of the value contained std::optional and GEOS_FMT_NS::formatter. */ template< typename T > struct GEOS_FMT_NS::formatter< std::optional< T > > : GEOS_FMT_NS::formatter< T > { /** * @brief Format the std::optional to a string. + * @param opt The std::optional< T > value to format + * @param ctx formatting state consisting of the formatting arguments and the output iterator * @return return the corresponding value string. If std::optional is empty retun an empty string */ auto format( std::optional< T > const & opt, format_context & ctx ) From d90c8b5591a1961b1a67559e8ec3255be8f4662d Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 27 Feb 2024 15:30:23 +0100 Subject: [PATCH 022/216] more logs added --- .../multifluid/CO2Brine/CO2BrineFluid.cpp | 29 ++++++------- .../functions/TableFunction.cpp | 41 +++++++++++++++---- .../functions/TableFunction.hpp | 8 +++- .../mainInterface/ProblemManager.cpp | 8 +--- 4 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 3224dec1d2f..74223a89de8 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -105,7 +105,8 @@ CO2BrineFluid( string const & name, Group * const parent ): this->registerWrapper( viewKeyStruct::writeCSVFlagString(), &m_writeCSV ). setInputFlag( InputFlags::OPTIONAL ). setRestartFlags( RestartFlags::NO_WRITE ). - setDescription( "Write PVT tables into a CSV file" ); + setDescription( "Write PVT tables into a CSV file" ). + setDefaultValue( 1 ); // if this is a thermal model, we need to make sure that the arrays will be properly displayed and saved to restart if( isThermal() ) @@ -132,8 +133,6 @@ std::unique_ptr< ConstitutiveBase > CO2BrineFluid< PHASE1, PHASE2, FLASH >:: deliverClone( string const & name, Group * const parent ) const { - std::cout<< "deliverClone" << std::endl; - std::unique_ptr< ConstitutiveBase > clone = MultiFluidBase::deliverClone( name, parent ); CO2BrineFluid & newConstitutiveRelation = dynamicCast< CO2BrineFluid & >( *clone ); @@ -238,11 +237,18 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::postProcessInput() string const expectedGasPhaseNames[] = { "CO2", "co2", "gas", "Gas" }; m_p2Index = PVTFunctionHelpers::findName( m_phaseNames, expectedGasPhaseNames, viewKeyStruct::phaseNamesString() ); - std::cout << "test clone " << m_isClone << std::endl; - std::cout << " getParent().getName() " << getParent().getName() << std::endl; bool isClone = true; if( getParent().getName() == "Constitutive" ) { + string sectionOutput; + string sectionName = "Section : PVT Table generation"; + + sectionOutput = GEOS_FMT( "\n{:=^{}}\n", "=", sectionName.size() + 5 ); + sectionOutput += GEOS_FMT( "{:^{}}\n", sectionName, sectionName.size() + 5 ); + sectionOutput += GEOS_FMT( "{:=^{}}\n\n", "=", sectionName.size() + 5 ); + + std::cout << sectionOutput; + isClone = false; } @@ -341,14 +347,9 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) InputError ); // then, we are ready to instantiate the phase models - - //temp - m_writeCSV = 1; - std::cout<< Group::getPath() << std::endl; - std::cout << "test clone int create" << isClone << std::endl; - bool const writeCSV = !isClone && m_writeCSV; - bool const writeInLog = !isClone && (getLogLevel() > 0 && logger::internal::rank==0); + bool const writeInLog = !isClone && (getLogLevel() >= 0 && logger::internal::rank==0); + m_phase1 = std::make_unique< PHASE1 >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, writeCSV, writeInLog ); m_phase2 = std::make_unique< PHASE2 >( getName() + "_phaseModel2", phase2InputParams, m_componentNames, m_componentMolarWeight, @@ -379,7 +380,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) m_phaseNames, m_componentNames, m_componentMolarWeight, - writeCSV, + writeCSV, writeInLog ); } } @@ -420,7 +421,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) m_phaseNames, m_componentNames, m_componentMolarWeight, - writeCSV, + writeCSV, writeInLog ); } diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index ab3a8984eeb..ae3abdd90a3 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -182,9 +182,9 @@ void TableFunction::checkCoord( real64 const coord, localIndex const dim ) const SimulationError ); } -void TableFunction::printInCSV( string const filename ) const +void TableFunction::printInCSV( string const & filename ) const { - std::ofstream os( filename + ".csv" ); + std::ofstream os( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); integer const numDimensions = LvArray::integerConversion< integer >( m_coordinates.size() ); @@ -253,11 +253,16 @@ void TableFunction::printInCSV( string const filename ) const os.close(); } -void TableFunction::printInLog( string const filename ) const +void TableFunction::printInLog( string const & filename ) const { integer const numDimensions = LvArray::integerConversion< integer >( m_coordinates.size() ); - std::cout << "in function printInLog " << numDimensions << std::endl; + + std::cout << GEOS_FMT( "CSV Generated to inputFiles/compositionalMultiphaseWell/{}/{}.csv \n", + OutputBase::getOutputDirectory(), + filename ); + std::cout << GEOS_FMT( "Values in the table are represented by : {}", units::getDescription( m_valueUnit )); + if( numDimensions == 1 ) { Table pvtTable1D = Table( @@ -282,6 +287,9 @@ void TableFunction::printInLog( string const filename ) const integer const nX = coordsX.size(); integer const nY = coordsY.size(); std::vector< string > vecDescription; + std::vector< std::vector< string > > vRowsValues; + integer nbRows = 0; + vecDescription.push_back( string( units::getDescription( getDimUnit( 0 )))); for( integer idxY = 0; idxY < nY; idxY++ ) @@ -291,18 +299,33 @@ void TableFunction::printInLog( string const filename ) const } Table pvtTable2D = Table( vecDescription ); + pvtTable2D.setTitle( filename ); for( integer i = 0; i < nX; i++ ) { - std::vector< string > vecValues; - vecValues.push_back( std::to_string( coordsX[i] )); + std::vector< string > vValues; + vValues.push_back( std::to_string( coordsX[i] )); for( integer j = 0; j < nY; j++ ) { - vecValues.push_back( std::to_string( m_values[ j*nX + i ] )); + vValues.push_back( std::to_string( m_values[ j*nX + i ] )); } + vRowsValues.push_back( vValues ); + nbRows++; + } + + if( nbRows <= 500 ) + { + pvtTable2D.addRowsFromVectors( vRowsValues ); + pvtTable2D.draw(); + } + else + { + string log = GEOS_FMT( "The {} PVT table exceeding 500 rows.\nTo visualize the tables, go to the generated csv \n", filename ); + Table pvtTable2DLog = Table( {Table::ColumnParam{{log}, Table::Alignment::left}} ); + pvtTable2DLog.setTitle( filename ); + pvtTable2DLog.draw(); } - - pvtTable2D.draw(); + } } diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index c35f97d5482..a6d0b8721bf 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -321,9 +321,13 @@ class TableFunction : public FunctionBase * @brief Print table into a CSV file (only 1d and 2d tables are supported) * @param filename Filename for output */ - void printInCSV( string const filename ) const; + void printInCSV( string const & filename ) const; - void printInLog( string const filename ) const; + /** + * @brief Print table to the log (only 1d and 2d tables are supported). + * @param filename Filename for output + */ + void printInLog( string const & filename ) const; /** * @brief Create an instance of the kernel wrapper diff --git a/src/coreComponents/mainInterface/ProblemManager.cpp b/src/coreComponents/mainInterface/ProblemManager.cpp index eb9bea9f0bc..110ad22ff51 100644 --- a/src/coreComponents/mainInterface/ProblemManager.cpp +++ b/src/coreComponents/mainInterface/ProblemManager.cpp @@ -711,26 +711,20 @@ void ProblemManager::importFields() void ProblemManager::applyNumericalMethods() { - std::cout << "getDomainPartition before " << std::endl; DomainPartition & domain = getDomainPartition(); ConstitutiveManager & constitutiveManager = domain.getGroup< ConstitutiveManager >( groupKeys.constitutiveManager ); - std::cout << "getMeshBodies before " << std::endl; Group & meshBodies = domain.getMeshBodies(); // this contains a key tuple< mesh body name, mesh level name, region name, subregion name> with a value of the number of quadrature // points. - std::cout << "calculateRegionQuadrature before " << std::endl; map< std::tuple< string, string, string, string >, localIndex > const regionQuadrature = calculateRegionQuadrature( meshBodies ); - std::cout << "calculateRegionQuadrature done " << std::endl; + setRegionQuadrature( meshBodies, constitutiveManager, regionQuadrature ); } - - map< std::pair< string, Group const * const >, arrayView1d< string const > const > ProblemManager::getDiscretizations() const { - map< std::pair< string, Group const * const >, arrayView1d< string const > const > meshDiscretizations; NumericalMethodsManager const & From 958d54267371d1af03a7769a8b70dd66eac337fe Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 28 Feb 2024 10:21:54 +0100 Subject: [PATCH 023/216] remove static_assert + constness --- src/coreComponents/codingUtilities/Table.cpp | 15 +++--- src/coreComponents/codingUtilities/Table.hpp | 16 ++---- .../codingUtilities/tests/testTable.cpp | 50 +++++++++---------- src/coreComponents/common/DataTypes.hpp | 23 +++++++++ src/coreComponents/common/Units.hpp | 23 --------- .../mesh/generators/WellGeneratorBase.cpp | 14 ++---- 6 files changed, 63 insertions(+), 78 deletions(-) diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp index 4ca16877214..dd8bdeb0438 100644 --- a/src/coreComponents/codingUtilities/Table.cpp +++ b/src/coreComponents/codingUtilities/Table.cpp @@ -29,7 +29,7 @@ namespace geos * @param spaces * @return A cell value */ -string buildValueCell( Table::Alignment const alignment, string_view value, integer spaces ) +string buildValueCell( Table::Alignment const alignment, string_view value, integer const spaces ) { switch( alignment ) { @@ -64,7 +64,7 @@ Table::Table( std::vector< ColumnParam > const & columnParameter ) } } -void Table::addRowsFromVectors( std::vector< std::vector< string > > tableRows ) +void Table::addRowsFromVectors( std::vector< std::vector< string > > const & tableRows ) { for( size_t indexRow = 0; indexRow < tableRows.size(); indexRow++ ) { @@ -215,7 +215,7 @@ void Table::computeAndBuildSeparator( string & topSeparator, string & sectionSep { for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) { - integer cellSize = m_columns[idxColumn].m_maxStringSize.length(); + integer const cellSize = m_columns[idxColumn].m_maxStringSize.length(); if( idxColumn == 0 ) { sectionSeparator += GEOS_FMT( "+{:-<{}}", "", ( cellSize + borderMargin )); @@ -235,7 +235,7 @@ void Table::computeAndBuildSeparator( string & topSeparator, string & sectionSep topSeparator = GEOS_FMT( "+{:-<{}}+", "", sectionSeparator.size() - 2 );// -2 for ++ } -void Table::buildTitleRow( string & titleRows, string topSeparator, string sectionSeparator ) +void Table::buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ) { titleRows = GEOS_FMT( "\n{}\n|", topSeparator ); titleRows += buildValueCell( Alignment::middle, @@ -245,7 +245,7 @@ void Table::buildTitleRow( string & titleRows, string topSeparator, string secti titleRows += GEOS_FMT( "{}\n", "|" ); } -void Table::buildSectionRows( string sectionSeparator, +void Table::buildSectionRows( string_view sectionSeparator, string & rows, integer const nbRows, Section const section ) @@ -265,7 +265,7 @@ void Table::buildSectionRows( string sectionSeparator, { cell = m_columns[idxColumn].columnValues[idxRow]; } - integer cellSize = m_columns[idxColumn].m_maxStringSize.length(); + integer const cellSize = m_columns[idxColumn].m_maxStringSize.length(); rows += buildValueCell( m_columns[idxColumn].parameter.alignment, cell, cellSize ); @@ -305,7 +305,6 @@ void Table::fillColumnsValuesFromCellsRows() void Table::draw( std::ostream & oss ) { - string tableOutput; string rows; string titleRows; string topSeparator; @@ -331,7 +330,7 @@ void Table::draw( std::ostream & oss ) buildSectionRows( sectionSeparator, rows, largestHeaderVectorSize, Section::header ); buildSectionRows( sectionSeparator, rows, m_cellsRows.size(), Section::values ); - tableOutput = titleRows + rows + '\n'; + string const tableOutput = titleRows + rows + '\n'; oss << tableOutput; } diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index 0dbdbbe31d4..0809cda41e9 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -67,20 +67,18 @@ class Table /** * @brief Add a row the the table. * - * @param N The number expected by the table * @param Args The values passed to addRow (can be any type). * @param args Cell values to be added to the line. * - * @pre The number of arguments must correspond to the expected number of cells per line (N). */ - template< size_t N, typename ... Args > + template< typename ... Args > void addRow( Args const & ... args ); /** * @brief Add rows from vectors to the table. * @param vecRows Vector who contains all the table rows */ - void addRowsFromVectors( std::vector< std::vector< string > > tableRows ); + void addRowsFromVectors( std::vector< std::vector< string > > const & tableRows ); /** * @brief Write the table into a specified stream @@ -171,7 +169,7 @@ class Table * @param topSeparator The top line separator * @param sectionSeparator The section line separator */ - void buildTitleRow( string & titleRows, string topSeparator, string sectionSeparator ); + void buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ); /** * @brief Build a section by specifying it's type ( header or section ) @@ -180,7 +178,7 @@ class Table * @param nbRows Indicates the number of lines in a section * @param section The section to be built */ - void buildSectionRows( string sectionSeparator, + void buildSectionRows( string_view sectionSeparator, string & rows, integer const nbRows, Section const section ); @@ -199,13 +197,9 @@ class Table }; -template< size_t N, typename ... Args > +template< typename ... Args > void Table::addRow( Args const &... args ) { - constexpr std::size_t nbColumn_ = sizeof...(args); - static_assert( nbColumn_ == N, - "The number of cells per line does not correspond to the number of parameters." ); - std::vector< string > rowsValues; int idx = 0; ( [&] { diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 92283c45e74..9078d4fae28 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -35,10 +35,10 @@ TEST( testTable, tableClass ) "Next\nelement"} ); tableTest.setTitle( "InternalWellGenerator well_injector1" ); - tableTest.addRow< 5 >( "value1", "[30.21543]", "3.0", 54, 0 ); - tableTest.addRow< 5 >( "", "", "", "", "" ); - tableTest.addRow< 5 >( "Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", "[30.21543]", "30.45465142", - 787442, 10 ); + tableTest.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); + tableTest.addRow( "", "", "", "", "" ); + tableTest.addRow( "Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", "[30.21543]", "30.45465142", + 787442, 10 ); tableTest.draw( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); @@ -65,9 +65,9 @@ TEST( testTable, tableClass ) "Next\nelement"} ); tableTest2.setTitle( "InternalWellGenerator well_injector1" ); - tableTest2.addRow< 5 >( "value1", "[30.21543]", "3.0", 54, 0 ); - tableTest2.addRow< 5 >( "", "", "", "", "" ); - tableTest2.addRow< 5 >( "value23", "[30.21543]", "30.45465142", 787442, 10 ); + tableTest2.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); + tableTest2.addRow( "", "", "", "", "" ); + tableTest2.addRow( "value23", "[30.21543]", "30.45465142", 787442, 10 ); tableTest2.draw( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); @@ -116,8 +116,8 @@ TEST( testTable, tableClass ) Table::ColumnParam{{"Next\nelement"}, Table::Alignment::right} } ); tableTest4.setTitle( "InternalWellGenerator well_injector1" ); - tableTest4.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest4.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest4.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest4.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest4.draw( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); @@ -144,8 +144,8 @@ TEST( testTable, tableClass ) } ); tableTest5.setTitle( "InternalWellGenerator well_injector1" ); - tableTest5.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest5.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest5.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest5.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest5.draw( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); @@ -170,8 +170,8 @@ TEST( testTable, tableClass ) Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, } ); tableTest6.setTitle( "InternalWellGenerator well_injector1" ); - tableTest6.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest6.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest6.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest6.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest6.draw( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); @@ -197,8 +197,8 @@ TEST( testTable, tableClass ) Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle, false}, } ); tableTest7.setTitle( "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); - tableTest7.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest7.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest7.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest7.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest7.draw( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); @@ -223,8 +223,8 @@ TEST( testTable, tableClass ) Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, } ); tableTest8.setTitle( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); - tableTest8.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest8.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest8.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest8.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest8.draw( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); @@ -246,8 +246,8 @@ TEST( testTable, tableClass ) } ); tableTest9.setTitle( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); - tableTest9.addRow< 1 >( "value1" ); - tableTest9.addRow< 1 >( "val1" ); + tableTest9.addRow( "value1" ); + tableTest9.addRow( "val1" ); tableTest9.draw( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); @@ -267,8 +267,8 @@ TEST( testTable, tableClass ) Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, } ); tableTest10.setTitle( "title1" ); - tableTest10.addRow< 1 >( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); - tableTest10.addRow< 1 >( "val1" ); + tableTest10.addRow( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + tableTest10.addRow( "val1" ); tableTest10.draw( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); @@ -308,8 +308,8 @@ TEST( testTable, tableClass ) Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::left}, Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, } ); - tableTest12.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest12.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest12.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest12.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest12.draw( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); @@ -334,8 +334,8 @@ TEST( testTable, tableClass ) } ); tableTest13.setTitle( "InternalWellGenerator well_injector1" ); tableTest13.setMargin( Table::MarginValue::tiny ); - tableTest13.addRow< 6 >( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest13.addRow< 6 >( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + tableTest13.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableTest13.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); tableTest13.draw( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); diff --git a/src/coreComponents/common/DataTypes.hpp b/src/coreComponents/common/DataTypes.hpp index 98e5ecaddec..6ec38a721ef 100644 --- a/src/coreComponents/common/DataTypes.hpp +++ b/src/coreComponents/common/DataTypes.hpp @@ -670,6 +670,29 @@ struct TypeName } +/** + * @brief Format to be able to directly use a std::optional. + * @param T The type of the value contained std::optional and GEOS_FMT_NS::formatter. + */ +template< typename T > +struct GEOS_FMT_NS::formatter< std::optional< T > > : GEOS_FMT_NS::formatter< T > +{ + /** + * @brief Format the std::optional to a string. + * @param opt The std::optional< T > value to format + * @param ctx formatting state consisting of the formatting arguments and the output iterator + * @return return the corresponding value string. If std::optional is empty retun an empty string + */ + auto format( std::optional< T > const & opt, format_context & ctx ) + { + if( opt ) + { + return GEOS_FMT_NS::formatter< T >::format( *opt, ctx ); + } + return GEOS_FMT_NS::format_to( ctx.out(), "" ); + } +}; + #endif /* GEOS_COMMON_DATATYPES_HPP */ diff --git a/src/coreComponents/common/Units.hpp b/src/coreComponents/common/Units.hpp index 93651859856..43e8fc680e3 100644 --- a/src/coreComponents/common/Units.hpp +++ b/src/coreComponents/common/Units.hpp @@ -245,27 +245,4 @@ struct GEOS_FMT_NS::formatter< geos::units::TimeFormatInfo > : GEOS_FMT_NS::form } }; -/** - * @brief Format to be able to directly use a std::optional. - * @param T The type of the value contained std::optional and GEOS_FMT_NS::formatter. - */ -template< typename T > -struct GEOS_FMT_NS::formatter< std::optional< T > > : GEOS_FMT_NS::formatter< T > -{ - /** - * @brief Format the std::optional to a string. - * @param opt The std::optional< T > value to format - * @param ctx formatting state consisting of the formatting arguments and the output iterator - * @return return the corresponding value string. If std::optional is empty retun an empty string - */ - auto format( std::optional< T > const & opt, format_context & ctx ) - { - if( opt ) - { - return GEOS_FMT_NS::formatter< T >::format( *opt, ctx ); - } - return GEOS_FMT_NS::format_to( ctx.out(), "" ); - } -}; - #endif //GEOS_MATH_PHYSICSCONSTANTS_HPP_ diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 115fe51e806..add98afe168 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -18,7 +18,7 @@ #include "mesh/generators/LineBlockABC.hpp" #include "LvArray/src/genericTensorOps.hpp" #include "codingUtilities/Table.hpp" -#include "common/Units.hpp" +#include "common/Format.hpp" namespace geos { using namespace dataRepository; @@ -528,14 +528,6 @@ void WellGeneratorBase::debugWellGeometry() const { return; } - string sectionOutput; - string sectionName = "Section : Well generation"; - - sectionOutput = GEOS_FMT( "\n{:=^{}}\n", "=", sectionName.size() + 5 ); - sectionOutput += GEOS_FMT( "{:^{}}\n", sectionName, sectionName.size() + 5 ); - sectionOutput += GEOS_FMT( "{:=^{}}\n", "=", sectionName.size() + 5 ); - - std::cout << sectionOutput; std::vector< string > row; std::ostringstream oss; @@ -578,7 +570,7 @@ void WellGeneratorBase::debugWellGeometry() const //std::cout << "Second well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; } } - table.addRow< 6 >( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, nextElement ); + table.addRow( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, nextElement ); } table.draw(); @@ -589,7 +581,7 @@ void WellGeneratorBase::debugWellGeometry() const for( globalIndex iperf = 0; iperf < m_numPerforations; ++iperf ) { - tablePerforation.addRow< 3 >( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); + tablePerforation.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); } tablePerforation.draw(); From f67e3d9ff85cc3badb20c33dfda94058af7c107f Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 29 Feb 2024 16:05:42 +0100 Subject: [PATCH 024/216] remove unused code --- .../mesh/generators/WellGeneratorBase.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index add98afe168..94b4c6821d5 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -538,8 +538,7 @@ void WellGeneratorBase::debugWellGeometry() const Table::ColumnParam{{"CoordZ"}, Table::Alignment::middle}, Table::ColumnParam{{"Prev\nElement"}, Table::Alignment::right}, Table::ColumnParam{{"Next\nElement"}, Table::Alignment::right}, - } - ); + } ); string titleName = "InternalWellGenerator " + getName(); table.setTitle( titleName ); @@ -559,23 +558,11 @@ void WellGeneratorBase::debugWellGeometry() const prevElement = m_prevElemId[iwelem][0]; } - for( globalIndex inode = 0; inode < m_numNodesPerElem; ++inode ) - { - if( inode == 0 ) - { - //std::cout << "First well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; - } - else - { - //std::cout << "Second well node: #" << m_elemToNodesMap[iwelem][inode] << std::endl; - } - } table.addRow( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, nextElement ); - } table.draw(); - Table tablePerforation = Table( {"Perforation no.", "Coordinates\nlong string", "connected to" } ); + Table tablePerforation = Table( {"Perforation no.", "Coordinates", "connected to" } ); string titlePerfo = "Peforation table"; tablePerforation.setTitle( titlePerfo ); From 5b8689a79b4b93375b639444afda8e961db3d2b1 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 4 Mar 2024 11:08:48 +0100 Subject: [PATCH 025/216] factorisation log pvt --- .../codingUtilities/StringUtilities.hpp | 17 ++++++++++++++--- .../fluid/multifluid/CO2Brine/CO2BrineFluid.cpp | 9 --------- .../CO2Brine/functions/BrineEnthalpy.cpp | 14 +++----------- .../CO2Brine/functions/CO2Enthalpy.cpp | 10 ++-------- .../CO2Brine/functions/CO2Solubility.cpp | 13 +++---------- .../CO2Brine/functions/CO2Solubility.hpp | 13 +++++++++++++ .../CO2Brine/functions/EzrokhiBrineDensity.cpp | 15 +++------------ .../functions/EzrokhiBrineViscosity.cpp | 9 +-------- .../CO2Brine/functions/FenghourCO2Viscosity.cpp | 9 +-------- .../CO2Brine/functions/PVTFunctionBase.hpp | 13 +++++++++++++ .../CO2Brine/functions/PhillipsBrineDensity.cpp | 9 +-------- .../functions/PhillipsBrineViscosity.cpp | 9 +-------- .../CO2Brine/functions/SpanWagnerCO2Density.cpp | 9 +-------- .../CO2Brine/functions/WaterDensity.cpp | 10 +--------- src/coreComponents/functions/TableFunction.hpp | 2 +- 15 files changed, 58 insertions(+), 103 deletions(-) diff --git a/src/coreComponents/codingUtilities/StringUtilities.hpp b/src/coreComponents/codingUtilities/StringUtilities.hpp index 2a6b2370f11..d3e3e1e71a6 100644 --- a/src/coreComponents/codingUtilities/StringUtilities.hpp +++ b/src/coreComponents/codingUtilities/StringUtilities.hpp @@ -255,12 +255,23 @@ constexpr bool endsWith( std::string_view str, std::string_view suffix ) str.compare( str.size()-suffix.size(), suffix.size(), suffix ) == 0; } +/** + * @brief Overloading operator (<<) for std::optional. + * + * This function displays the value contained in a std::optional object if one exists. + * Otherwise, it produces no output. + * + * @tparam T The type of the value contained std::optional. + * @param os An output stream (for example, std::cout). + * @param optValue std::optional value to display. + * @return The output stream + */ template< typename T > -std::ostream & operator<<( std::ostream & os, std::optional< T > const & t ) +std::ostream & operator<<( std::ostream & os, std::optional< T > const & optValue ) { - if( t ) + if( optValue ) { - os << t.value(); + os << optValue.value(); } return os; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 74223a89de8..0430f311443 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -240,15 +240,6 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::postProcessInput() bool isClone = true; if( getParent().getName() == "Constitutive" ) { - string sectionOutput; - string sectionName = "Section : PVT Table generation"; - - sectionOutput = GEOS_FMT( "\n{:=^{}}\n", "=", sectionName.size() + 5 ); - sectionOutput += GEOS_FMT( "{:^{}}\n", sectionName, sectionName.size() + 5 ); - sectionOutput += GEOS_FMT( "{:=^{}}\n\n", "=", sectionName.size() + 5 ); - - std::cout << sectionOutput; - isClone = false; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp index 97a9b8377d2..98674175551 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp @@ -206,19 +206,11 @@ BrineEnthalpy::BrineEnthalpy( string const & name, m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); m_brineEnthalpyTable = makeBrineEnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - if( printInCsv || ( printInLog && m_CO2EnthalpyTable->numDimensions() >= 3 ) ) - { - m_CO2EnthalpyTable->printInCSV( m_CO2EnthalpyTable->getName() ); - m_brineEnthalpyTable->printInCSV( m_brineEnthalpyTable->getName() ); - } - if( printInLog && m_CO2EnthalpyTable->numDimensions() <= 2 ) - { - m_CO2EnthalpyTable->printInLog( m_CO2EnthalpyTable->getName() ); - m_brineEnthalpyTable->printInLog( m_brineEnthalpyTable->getName() ); - } - + checkPrint( m_CO2EnthalpyTable, printInCsv, printInLog ); + checkPrint( m_brineEnthalpyTable, printInCsv, printInLog ); } + void BrineEnthalpy::checkTablesParameters( real64 const pressure, real64 const temperature ) const { diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp index 0bfce5492be..21145414ff7 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp @@ -267,14 +267,8 @@ CO2Enthalpy::CO2Enthalpy( string const & name, m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - if( printInCsv || ( printInLog && m_CO2EnthalpyTable->numDimensions() >= 3 ) ) - { - m_CO2EnthalpyTable->printInCSV( m_CO2EnthalpyTable->getName() ); - } - if( printInLog && m_CO2EnthalpyTable->numDimensions() <= 2 ) - { - m_CO2EnthalpyTable->printInLog( m_CO2EnthalpyTable->getName() ); - } + checkPrint( m_CO2EnthalpyTable, printInCsv, printInLog ); + checkPrint( m_CO2EnthalpyTable, printInCsv, printInLog ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp index 784fad48221..c1c02990f3e 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp @@ -393,16 +393,9 @@ CO2Solubility::CO2Solubility( string const & name, m_CO2SolubilityTable = makeSolubilityTable( inputParams, m_modelName, FunctionManager::getInstance() ); m_WaterVapourisationTable = makeVapourisationTable( inputParams, m_modelName, FunctionManager::getInstance() ); - if( printInCsv || ( printInLog && m_CO2SolubilityTable->numDimensions() >= 3 ) ) - { - m_CO2SolubilityTable->printInCSV( m_CO2SolubilityTable->getName() ); - m_WaterVapourisationTable->printInCSV( m_WaterVapourisationTable->getName() ); - } - if( printInLog && m_CO2SolubilityTable->numDimensions() <= 2 ) - { - m_CO2SolubilityTable->printInLog( m_CO2SolubilityTable->getName() ); - m_WaterVapourisationTable->printInLog( m_WaterVapourisationTable->getName() ); - } + checkPrint( m_CO2SolubilityTable, printInCsv, printInLog ); + checkPrint( m_WaterVapourisationTable, printInCsv, printInLog ); + } void CO2Solubility::checkTablesParameters( real64 const pressure, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp index bd0100052a5..4debc5fda58 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp @@ -121,6 +121,19 @@ class CO2Solubility : public FlashModelBase */ void checkTablesParameters( real64 pressure, real64 temperature ) const override final; + void checkPrint ( TableFunction const * table, bool const printInCsv, bool const printInLog + ) + { + if( printInCsv || ( printInLog && table->numDimensions() >= 3 ) ) + { + table->printInCSV( table->getName() ); + } + if( printInLog && table->numDimensions() <= 2 ) + { + table->printInLog( table->getName() ); + } + } + /// Type of kernel wrapper for in-kernel update using KernelWrapper = CO2SolubilityUpdate; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp index 7bbd656b605..f076950a7e7 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp @@ -53,17 +53,8 @@ EzrokhiBrineDensity::EzrokhiBrineDensity( string const & name, m_waterSatDensityTable = PureWaterProperties::makeSaturationDensityTable( m_functionName, FunctionManager::getInstance() ); m_waterSatPressureTable = PureWaterProperties::makeSaturationPressureTable( m_functionName, FunctionManager::getInstance() ); - if( printInCsv || ( printInLog && m_waterSatDensityTable->numDimensions() >= 3 ) ) - { - m_waterSatDensityTable->printInCSV( m_waterSatDensityTable->getName() ); - m_waterSatPressureTable->printInLog( m_waterSatPressureTable->getName() ); - } - if( printInLog && m_waterSatDensityTable->numDimensions() <= 2 ) - { - m_waterSatDensityTable->printInLog( m_waterSatDensityTable->getName() ); - m_waterSatPressureTable->printInLog( m_waterSatPressureTable->getName() ); - } - + checkPrint( m_waterSatPressureTable, printInCsv, printInLog ); + checkPrint( m_waterSatDensityTable, printInCsv, printInLog ); } void EzrokhiBrineDensity::makeCoefficients( string_array const & inputPara ) @@ -110,7 +101,7 @@ EzrokhiBrineDensity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp index a21c7aa66fa..86eb0447536 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp @@ -52,14 +52,7 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, makeCoefficients( inputPara ); m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); - if( printInCsv || ( printInLog && m_waterViscosityTable->numDimensions() >= 3 ) ) - { - m_waterViscosityTable->printInCSV( m_waterViscosityTable->getName() ); - } - if( printInLog && m_waterViscosityTable->numDimensions() <= 2 ) - { - m_waterViscosityTable->printInLog( m_waterViscosityTable->getName() ); - } + checkPrint( m_waterViscosityTable, printInCsv, printInLog ); } void EzrokhiBrineViscosity::makeCoefficients( string_array const & inputPara ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp index 489d9265b1a..3966d505340 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp @@ -149,14 +149,7 @@ FenghourCO2Viscosity::FenghourCO2Viscosity( string const & name, { m_CO2ViscosityTable = makeViscosityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - if( printInCsv || ( printInLog && m_CO2ViscosityTable->numDimensions() >= 3 ) ) - { - m_CO2ViscosityTable->printInCSV( m_CO2ViscosityTable->getName() ); - } - if( printInLog && m_CO2ViscosityTable->numDimensions() <= 2 ) - { - m_CO2ViscosityTable->printInLog( m_CO2ViscosityTable->getName() ); - } + checkPrint( m_CO2ViscosityTable, printInCsv, printInLog ); } void FenghourCO2Viscosity::checkTablesParameters( real64 const pressure, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index 584fb66e324..1b4837ebb90 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -20,6 +20,7 @@ #define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_FUNCTIONS_PVTFUNCTIONBASE_HPP_ #include "dataRepository/ObjectCatalog.hpp" +#include "functions/TableFunction.hpp" namespace geos { @@ -139,6 +140,18 @@ class PVTFunctionBase */ virtual void checkTablesParameters( real64 pressure, real64 temperature ) const = 0; + void checkPrint ( TableFunction const * table, bool const printInCsv, bool const printInLog ) + { + if( printInCsv || ( printInLog && table->numDimensions() >= 3 ) ) + { + table->printInCSV( table->getName() ); + } + if( printInLog && table->numDimensions() <= 2 ) + { + table->printInLog( table->getName() ); + } + } + protected: /// Name of the PVT function diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp index f86d464d16d..49dbb9bd295 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp @@ -190,14 +190,7 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, m_brineDensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - if( printInCsv || ( printInLog && m_brineDensityTable->numDimensions() >= 3 ) ) - { - m_brineDensityTable->printInCSV( m_brineDensityTable->getName() ); - } - if( printInLog && m_brineDensityTable->numDimensions() <= 2 ) - { - m_brineDensityTable->printInLog( m_brineDensityTable->getName() ); - } + checkPrint( m_brineDensityTable, printInCsv, printInLog ); } PhillipsBrineDensity::KernelWrapper diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp index cdba301cae1..8b7eb43125b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp @@ -45,14 +45,7 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); makeCoefficients( inputPara ); - if( printInCsv || ( printInLog && m_waterViscosityTable->numDimensions() >= 3 ) ) - { - m_waterViscosityTable->printInCSV( m_waterViscosityTable->getName() ); - } - if( printInLog && m_waterViscosityTable->numDimensions() <= 2 ) - { - m_waterViscosityTable->printInLog( m_waterViscosityTable->getName() ); - } + checkPrint( m_waterViscosityTable, printInCsv, printInLog ); } void PhillipsBrineViscosity::makeCoefficients( string_array const & inputPara ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp index fcc6d5fc18b..14c290421c3 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp @@ -289,14 +289,7 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, m_CO2DensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - if( printInCsv || ( printInLog && m_CO2DensityTable->numDimensions() >= 3 ) ) - { - m_CO2DensityTable->printInCSV( m_CO2DensityTable->getName() ); - } - if( printInLog && m_CO2DensityTable->numDimensions() <= 2 ) - { - m_CO2DensityTable->printInLog( m_CO2DensityTable->getName() ); - } + checkPrint( m_CO2DensityTable, printInCsv, printInLog ); } void SpanWagnerCO2Density::checkTablesParameters( real64 const pressure, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp index e8c764c2b34..bb46a26d030 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp @@ -45,15 +45,7 @@ WaterDensity::WaterDensity( string const & name, GEOS_UNUSED_VAR( inputParams ); m_waterDensityTable = PureWaterProperties::makeSaturationDensityTable( m_functionName, FunctionManager::getInstance() ); - if( printInCsv || ( printInLog && m_waterDensityTable->numDimensions() >= 3 ) ) - { - m_waterDensityTable->printInCSV( m_waterDensityTable->getName() ); - } - if( printInLog && m_waterDensityTable->numDimensions() <= 2 ) - { - m_waterDensityTable->printInLog( m_waterDensityTable->getName() ); - } - + checkPrint( m_waterDensityTable, printInCsv, printInLog ); } void WaterDensity::checkTablesParameters( real64 const pressure, diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index a6d0b8721bf..2e2de63e241 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -318,7 +318,7 @@ class TableFunction : public FunctionBase } /** - * @brief Print table into a CSV file (only 1d and 2d tables are supported) + * @brief Print table into a CSV file * @param filename Filename for output */ void printInCSV( string const & filename ) const; From 0fa76e343ff0e49e65f949ed28081dbc5de406dd Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 4 Mar 2024 11:27:45 +0100 Subject: [PATCH 026/216] doxygen added --- .../fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp | 6 ++++++ .../fluid/multifluid/reactive/ReactiveBrineFluid.cpp | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index 1b4837ebb90..69dcee9aa75 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -140,6 +140,12 @@ class PVTFunctionBase */ virtual void checkTablesParameters( real64 pressure, real64 temperature ) const = 0; + /** + * @brief Check if the log should be printed on log (standard output) and/or CSV files + * @param table The target table to be printed + * @param printInCsv Boolean for printing in CSV + * @param printInLog Boolean for printing in Log + */ void checkPrint ( TableFunction const * table, bool const printInCsv, bool const printInLog ) { if( printInCsv || ( printInLog && table->numDimensions() >= 3 ) ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp index d144085d4f7..b22a3ebeb57 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp @@ -203,15 +203,13 @@ void ReactiveBrineFluid< PHASE > ::createPVTModels( bool isClone ) ( PHASE::Enthalpy::catalogName() != PVTProps::NoOpPVTFunction::catalogName() ), GEOS_FMT( "{}: PVT model {} not found in input files", getFullName(), PHASE::Enthalpy::catalogName() ), InputError ); - std::cout << "reactive brine" << isClone << std::endl; - // then, we are ready to instantiate the phase models bool const writeCSV = !isClone && m_writeCSV; bool const writeInLog = !isClone && (getLogLevel() > 0 && logger::internal::rank==0); + // then, we are ready to instantiate the phase models m_phase = std::make_unique< PHASE >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, writeCSV, writeInLog); - } template< typename PHASE > From bb1ee01722b6499c54b1012efe41ecf1fefaaef9 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 4 Mar 2024 17:10:09 +0100 Subject: [PATCH 027/216] remove test parent name with constitutive --- .../fluid/multifluid/CO2Brine/CO2BrineFluid.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 0430f311443..3703ea2f291 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -237,13 +237,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::postProcessInput() string const expectedGasPhaseNames[] = { "CO2", "co2", "gas", "Gas" }; m_p2Index = PVTFunctionHelpers::findName( m_phaseNames, expectedGasPhaseNames, viewKeyStruct::phaseNamesString() ); - bool isClone = true; - if( getParent().getName() == "Constitutive" ) - { - isClone = false; - } - - createPVTModels( isClone ); + createPVTModels( false ); } template< typename PHASE1, typename PHASE2, typename FLASH > From aa2f78927574ddb55b7f76528541ffec1c828285 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 5 Mar 2024 14:25:44 +0100 Subject: [PATCH 028/216] remove unused code + add drawtostring method --- src/coreComponents/codingUtilities/Table.cpp | 9 +++++- src/coreComponents/codingUtilities/Table.hpp | 7 +++- .../codingUtilities/tests/testTable.cpp | 32 +++++++++---------- src/coreComponents/common/DataTypes.hpp | 13 ++++---- .../mesh/generators/WellGeneratorBase.cpp | 6 ++-- 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp index dd8bdeb0438..13ef1908d3c 100644 --- a/src/coreComponents/codingUtilities/Table.cpp +++ b/src/coreComponents/codingUtilities/Table.cpp @@ -303,7 +303,7 @@ void Table::fillColumnsValuesFromCellsRows() } } -void Table::draw( std::ostream & oss ) +void Table::drawToStream( std::ostream & oss ) { string rows; string titleRows; @@ -335,4 +335,11 @@ void Table::draw( std::ostream & oss ) oss << tableOutput; } +string Table::drawToString() +{ + std::ostringstream oss; + drawToStream( oss ); + return oss.str(); +} + } diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index 0809cda41e9..5202cbadf7a 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -80,11 +80,16 @@ class Table */ void addRowsFromVectors( std::vector< std::vector< string > > const & tableRows ); + /** + * @brief Write the table into a string + */ + string drawToString(); + /** * @brief Write the table into a specified stream * @param os An output stream (by default, std::cout) */ - void draw( std::ostream & os = std::cout ); + void drawToStream( std::ostream & os = std::cout ); /** * @brief Set the table name diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 9078d4fae28..6f873131116 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -13,8 +13,8 @@ */ // Source includes -#include "../Table.hpp" -#include "../../dataRepository/Group.hpp" +#include "codingUtilities/Table.hpp" +#include "dataRepository/Group.hpp" // TPL includes #include @@ -39,7 +39,7 @@ TEST( testTable, tableClass ) tableTest.addRow( "", "", "", "", "" ); tableTest.addRow( "Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", "[30.21543]", "30.45465142", 787442, 10 ); - tableTest.draw( oss ); + tableTest.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); @@ -68,7 +68,7 @@ TEST( testTable, tableClass ) tableTest2.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); tableTest2.addRow( "", "", "", "", "" ); tableTest2.addRow( "value23", "[30.21543]", "30.45465142", 787442, 10 ); - tableTest2.draw( oss ); + tableTest2.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); @@ -91,7 +91,7 @@ TEST( testTable, tableClass ) "CoordX", "C", "CoordZ", } ); tableTest3.setTitle( "InternalWellGenerator well_injector1" ); - tableTest3.draw( oss ); + tableTest3.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); @@ -118,7 +118,7 @@ TEST( testTable, tableClass ) tableTest4.setTitle( "InternalWellGenerator well_injector1" ); tableTest4.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); tableTest4.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest4.draw( oss ); + tableTest4.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); @@ -146,7 +146,7 @@ TEST( testTable, tableClass ) tableTest5.setTitle( "InternalWellGenerator well_injector1" ); tableTest5.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); tableTest5.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest5.draw( oss ); + tableTest5.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); @@ -172,7 +172,7 @@ TEST( testTable, tableClass ) tableTest6.setTitle( "InternalWellGenerator well_injector1" ); tableTest6.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); tableTest6.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest6.draw( oss ); + tableTest6.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); @@ -199,7 +199,7 @@ TEST( testTable, tableClass ) tableTest7.setTitle( "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); tableTest7.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); tableTest7.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest7.draw( oss ); + tableTest7.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); @@ -225,7 +225,7 @@ TEST( testTable, tableClass ) tableTest8.setTitle( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); tableTest8.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); tableTest8.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest8.draw( oss ); + tableTest8.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); @@ -248,7 +248,7 @@ TEST( testTable, tableClass ) tableTest9.setTitle( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); tableTest9.addRow( "value1" ); tableTest9.addRow( "val1" ); - tableTest9.draw( oss ); + tableTest9.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); @@ -269,7 +269,7 @@ TEST( testTable, tableClass ) tableTest10.setTitle( "title1" ); tableTest10.addRow( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); tableTest10.addRow( "val1" ); - tableTest10.draw( oss ); + tableTest10.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); @@ -288,7 +288,7 @@ TEST( testTable, tableClass ) Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, } ); tableTest11.setTitle( "title1" ); - tableTest11.draw( oss ); + tableTest11.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); @@ -310,7 +310,7 @@ TEST( testTable, tableClass ) } ); tableTest12.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); tableTest12.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest12.draw( oss ); + tableTest12.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); @@ -336,7 +336,7 @@ TEST( testTable, tableClass ) tableTest13.setMargin( Table::MarginValue::tiny ); tableTest13.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); tableTest13.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest13.draw( oss ); + tableTest13.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); @@ -368,7 +368,7 @@ TEST( testTable, tableClass ) tableTest14.setTitle( "InternalWellGenerator well_injector1" ); tableTest14.setMargin( Table::MarginValue::tiny ); tableTest14.addRowsFromVectors( vecValues ); - tableTest14.draw( oss ); + tableTest14.drawToStream( oss ); tableTestsOutput.push_back( oss.str() ); oss.clear(); oss.str( "" ); diff --git a/src/coreComponents/common/DataTypes.hpp b/src/coreComponents/common/DataTypes.hpp index 6ec38a721ef..a4371da71b3 100644 --- a/src/coreComponents/common/DataTypes.hpp +++ b/src/coreComponents/common/DataTypes.hpp @@ -53,17 +53,18 @@ //#include #include #include +#include #include +#include +#include +#include +#include #include #include -#include -#include #include #include -#include -#include -#include -/** + +/* * top level geosx namespace contains all code that is specific to GEOSX */ namespace geos diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 94b4c6821d5..39168eeec39 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -529,8 +529,6 @@ void WellGeneratorBase::debugWellGeometry() const return; } - std::vector< string > row; - std::ostringstream oss; Table table = Table( { Table::ColumnParam{{"Element no."}, Table::Alignment::right}, Table::ColumnParam{{"CoordX"}, Table::Alignment::middle}, @@ -560,7 +558,7 @@ void WellGeneratorBase::debugWellGeometry() const table.addRow( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, nextElement ); } - table.draw(); + table.drawToStream(); Table tablePerforation = Table( {"Perforation no.", "Coordinates", "connected to" } ); string titlePerfo = "Peforation table"; @@ -571,7 +569,7 @@ void WellGeneratorBase::debugWellGeometry() const tablePerforation.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); } - tablePerforation.draw(); + tablePerforation.drawToStream(); } From 8ff95c2e794e2a2eca1d892bdec69ec673c5451a Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 5 Mar 2024 14:28:12 +0100 Subject: [PATCH 029/216] uncrustify --- src/coreComponents/codingUtilities/Table.cpp | 2 +- src/coreComponents/codingUtilities/Table.hpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp index 13ef1908d3c..3aa41fd0162 100644 --- a/src/coreComponents/codingUtilities/Table.cpp +++ b/src/coreComponents/codingUtilities/Table.cpp @@ -339,7 +339,7 @@ string Table::drawToString() { std::ostringstream oss; drawToStream( oss ); - return oss.str(); + return oss.str(); } } diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp index 5202cbadf7a..e4099fb5c7c 100644 --- a/src/coreComponents/codingUtilities/Table.hpp +++ b/src/coreComponents/codingUtilities/Table.hpp @@ -82,6 +82,7 @@ class Table /** * @brief Write the table into a string + * @return A string table */ string drawToString(); From 957c7d76408f343c7fbf3c704d83be650da4c37f Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 8 Mar 2024 17:27:16 +0100 Subject: [PATCH 030/216] refacto Table first part --- src/coreComponents/codingUtilities/Table.cpp | 2 +- .../codingUtilities/TableData.cpp | 69 ++++ .../codingUtilities/TableData.hpp | 87 +++++ .../codingUtilities/TableFormatter.cpp | 342 ++++++++++++++++++ .../codingUtilities/TableFormatter.hpp | 137 +++++++ .../codingUtilities/TableLayout.cpp | 54 +++ .../codingUtilities/TableLayout.hpp | 92 +++++ 7 files changed, 782 insertions(+), 1 deletion(-) create mode 100644 src/coreComponents/codingUtilities/TableData.cpp create mode 100644 src/coreComponents/codingUtilities/TableData.hpp create mode 100644 src/coreComponents/codingUtilities/TableFormatter.cpp create mode 100644 src/coreComponents/codingUtilities/TableFormatter.hpp create mode 100644 src/coreComponents/codingUtilities/TableLayout.cpp create mode 100644 src/coreComponents/codingUtilities/TableLayout.hpp diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp index 3aa41fd0162..e1961656139 100644 --- a/src/coreComponents/codingUtilities/Table.cpp +++ b/src/coreComponents/codingUtilities/Table.cpp @@ -313,8 +313,8 @@ void Table::drawToStream( std::ostream & oss ) std::vector< std::vector< string > > splitHeader; size_t largestHeaderVectorSize = 0; - fillColumnsValuesFromCellsRows(); + parseAndStoreHeaderSections( largestHeaderVectorSize, splitHeader ); adjustHeaderSizesAndStore( largestHeaderVectorSize, splitHeader ); diff --git a/src/coreComponents/codingUtilities/TableData.cpp b/src/coreComponents/codingUtilities/TableData.cpp new file mode 100644 index 00000000000..1e36f2eea40 --- /dev/null +++ b/src/coreComponents/codingUtilities/TableData.cpp @@ -0,0 +1,69 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file TableData.cpp + */ + +#include "codingUtilities/TableData.hpp" + +namespace geos +{ + +// void TableData2D::printCount() +// { +// int nb=0, nbx=0, nby=0; + +// for( real64 x : columns ) +// { +// nbx++; +// } + +// for( real64 y : row ) +// { +// nby++; +// for( real64 x : columns ) +// { +// auto const dataIt = data.find( std::pair< real64, real64 >( x, y )); +// if( dataIt != data.end()) +// { +// nb++; +// } +// } +// } + +// std::cout<<"total = "< id = std::pair< real64, real64 >( x, y ); + auto const dataIt = data.find( id ); + if( dataIt != data.end()) + { + values.push_back( GEOS_FMT( "{}", dataIt->secondue )); + } + } + + m_rows.push_back( values ); + } +} +} diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp new file mode 100644 index 00000000000..d157a653fac --- /dev/null +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -0,0 +1,87 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file TableData.hpp + */ + +#ifndef GEOS_COMMON_TableData_HPP +#define GEOS_COMMON_TableData_HPP + +#include "common/DataTypes.hpp" + +namespace geos +{ + +class TableData +{ +public: + + /** + * @brief Add a row to the table. + * @param Args The values passed to addRow (can be any type). + * @param args Cell values to be added to the line. + */ + template< typename ... Args > + void addRow( Args const & ... args ); + + std::vector< std::vector< string > > m_rows; + +private: + std::vector< string > m_cellsValue; +}; + +class TableData2D : public TableData +{ +public: + + template< typename T > + void addCell( real64 x, real64 y, T value ); + // void printCount(); + void buildRows(); + +private: + std::map< std::pair< real64, real64 >, string > data; + std::set< real64 > columns; + std::set< real64 > row; +}; + +template< typename ... Args > +void TableData::addRow( Args const &... args ) +{ + int idx = 0; + ( [&] { + string cellValue = GEOS_FMT( "{}", args ); + // if( m_columns[idx].parameter.enabled ) + // { + m_cellsValue.push_back( cellValue ); + // } + } (), ...); + + m_rows.push_back( m_cellsValue ); +} + +template< typename T > +void TableData2D::addCell( real64 x, real64 y, T value ) +{ + std::pair< real64, real64 > id = std::pair< real64, real64 >( x, y ); + + data[id] = GEOS_FMT( "{}", value ); + columns.insert( x ); + row.insert( y ); +} + +} + +#endif diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp new file mode 100644 index 00000000000..3a6553493ff --- /dev/null +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -0,0 +1,342 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file TableFormatter.cpp + */ + +#include "codingUtilities/TableFormatter.hpp" + +namespace geos +{ + +TableFormatter::TableFormatter( TableLayout tableLayout ) +{ + m_columns = tableLayout.m_columns; +} + +void TableFormatter::fillTableColumnsFromRows( std::vector< std::vector< string > > const & rows ) +{ + std::vector< Column > & columns = tableLayout.m_columns(); + + for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) + { + for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) + { + columns[idxColumn].columnValues.push_back( rows[idxRow][idxColumn] ); + } + } + +} + +//----------------------------------------------// + +TableCSVFormatter::TableCSVFormatter( TableLayout tableLayout ) +{ + m_columns = tableLayout.m_columns; + +} + +string TableCSVFormatter::headerToString() +{ + string headerValues = ""; + + for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) + { + headerValues += m_columns[idxColumn].parameter.headerName[idxRow]; + } + + return headerValues; +} + +string TableCSVFormatter::dataToString( TableData2D tableData ) +{ + std::vector< std::vector< string > > rowsValues = tableData.m_rows; + string data; + + tableData.buildRows(); + + for( std::vector< string > row : rowsValues ) + { + for( string value : row ) + { + data += value + ","; + } + data += "\n"; + } + return data; +} + +string TableCSVFormatter::dataToString( TableData tableData ) +{ + std::vector< std::vector< string > > rowsValues = tableData.m_rows; + string data; + + fillTableColumnsFromRows( rowsValues ); + + for( std::vector< string > row : rowsValues ) + { + for( string value : row ) + { + data += value + ","; + } + data += "\n"; + } + return data; +} + +//----------------------------------------------// + +TableTextFormatter::TableTextFormatter( TableLayout tableLayout ): + TableFormatter( tableLayout ) +{} + +string TableTextFormatter::ToString( TableData2D & tableData ) +{ + tableData.buildRows(); + getTableBuilt( tableData.m_rows ); +} + +string TableTextFormatter::ToString( TableData & tableData ) +{ + return getTableBuilt( tableData.m_rows ); +} + +string TableTextFormatter::getTableBuilt( std::vector< std::vector< string > > rowsValues ) +{ + string titleRows; + string topSeparator; + string sectionSeparator; + + size_t largestHeaderVectorSize = 0; + std::vector< std::vector< string > > splitHeader; + fillTableColumnsFromRows( rowsValues ); + + parseAndStoreHeaderSections( largestHeaderVectorSize, splitHeader ); + adjustHeaderSizesAndStore( largestHeaderVectorSize, splitHeader ); + + findAndSetMaxStringSize(); + computeAndBuildSeparator( topSeparator, sectionSeparator ); + + if( !tableTitle.empty()) + { + buildTitleRow( titleRows, topSeparator, sectionSeparator ); + } + + string tableRows += GEOS_FMT( "{}\n", sectionSeparator ); + buildSectionRows( sectionSeparator, tableRows, largestHeaderVectorSize, TableLayout::Section::header ); + buildSectionRows( sectionSeparator, tableRows, rowsValues.size(), TableLayout::Section::values ); + + string const tableOutput = titleRows + tableRows + '\n'; + + return tableOutput; +} + +void TableTextFormatter::parseAndStoreHeaderSections( size_t & largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeader ) +{ + for( size_t columnParamIdx = 0; columnParamIdx< m_columns.size(); columnParamIdx++ ) + { + std::vector< string > splitHeaderParts; + + std::istringstream ss( tableLayout.m_columns[columnParamIdx].parameter.headerName[0] ); + string subHeaderName; + + while( getline( ss, subHeaderName, '\n' )) + { + splitHeaderParts.push_back( subHeaderName ); + } + + size_t const cellSize = splitHeaderParts.size(); + largestHeaderVectorSize = std::max( largestHeaderVectorSize, cellSize ); + + splitHeader.push_back( splitHeaderParts ); + } +} + +void TableTextFormatter::adjustHeaderSizesAndStore( size_t largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeader ) +{ + for( size_t columnParamIdx = 0; columnParamIdx < m_columns.size(); columnParamIdx++ ) + { + if( splitHeader[columnParamIdx].size() < largestHeaderVectorSize ) + { + integer const whiteRowToAdd = largestHeaderVectorSize - splitHeader[columnParamIdx].size(); + splitHeader[columnParamIdx].insert( splitHeader[columnParamIdx].end(), whiteRowToAdd, " " ); + } + m_columns[columnParamIdx].parameter.headerName = splitHeader[columnParamIdx]; + } +} + +void TableTextFormatter::findAndSetMaxStringSize() +{ + string maxStringSize = ""; + for( size_t idxColumn = 0; idxColumn < m_columns.size(); idxColumn++ ) + { + auto it = std::max_element( m_columns[idxColumn].parameter.headerName.begin(), + m_columns[idxColumn].parameter.headerName.end(), + []( const auto & a, const auto & b ) { + return a.size() < b.size(); + } ); + + maxStringSize = *it; + + for( size_t idxRow = 0; idxRow < rowsValues.size(); idxRow++ ) + { + string cell = m_columns[idxColumn].columnValues[idxRow]; + if( maxStringSize.length() < cell.length()) + { + maxStringSize = cell; + } + } + m_columns[idxColumn].m_maxStringSize = maxStringSize; + } +} + +void TableTextFormatter::computeAndSetMaxStringSize( string::size_type sectionlineLength, + string::size_type titleLineLength ) +{ + integer extraLinesPerColumn; + integer extraLines; + integer newStringSize; + + extraLines = titleLineLength - sectionlineLength; + extraLinesPerColumn = std::ceil( extraLines / m_columns.size() ); + + for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) + { + newStringSize = extraLinesPerColumn + m_columns[idxColumn].m_maxStringSize.size(); + if( idxColumn == m_columns.size() - 1 || m_columns.size() == 1 ) + { + m_columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", + m_columns[idxColumn].m_maxStringSize, + newStringSize + columnMargin ); + } + else + { + m_columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", + m_columns[idxColumn].m_maxStringSize, + newStringSize ); + } + } +} + +void TableTextFormatter::computeAndBuildSeparator( string & topSeparator, string & sectionSeparator ) +{ + string::size_type sectionlineLength = 0; + string::size_type titleLineLength = tableTitle.length() + ( marginTitle * 2 ); + integer nbSpaceBetweenColumn = ( ( m_columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); + if( !tableTitle.empty()) + { + tableTitle = GEOS_FMT( "{:^{}}", tableTitle, titleLineLength ); + } + + for( std::size_t i = 0; i < m_columns.size(); ++i ) + { + sectionlineLength += m_columns[i].m_maxStringSize.length(); + } + + sectionlineLength += nbSpaceBetweenColumn; + if( sectionlineLength < titleLineLength ) + { + computeAndSetMaxStringSize( sectionlineLength, titleLineLength ); + } + if( m_columns.size() == 1 ) + { + sectionSeparator += GEOS_FMT( "+{:-<{}}+", + "", + ( m_columns[0].m_maxStringSize.length() + (borderMargin - 1) + columnMargin )); + } + else + { + for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) + { + integer const cellSize = m_columns[idxColumn].m_maxStringSize.length(); + if( idxColumn == 0 ) + { + sectionSeparator += GEOS_FMT( "+{:-<{}}", "", ( cellSize + borderMargin )); + } + else if( idxColumn == (m_columns.size() - 1)) + { + sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); + sectionSeparator += GEOS_FMT( "{:->{}}", "+", ( cellSize + borderMargin + 1 ) ); + } + else + { + sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); + sectionSeparator += GEOS_FMT( "{:->{}}", "", cellSize ); + } + } + } + topSeparator = GEOS_FMT( "+{:-<{}}+", "", sectionSeparator.size() - 2 );// -2 for ++ +} + +void TableTextFormatter::buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ) +{ + titleRows = GEOS_FMT( "\n{}\n|", topSeparator ); + titleRows += buildValueCell( Alignment::middle, + tableTitle, + (sectionSeparator.length() - 2) // -2 for || + ); + titleRows += GEOS_FMT( "{}\n", "|" ); +} + +void TableTextFormatter::buildSectionRows( string_view sectionSeparator, + string & tableRows, + integer const nbRows, + TableLayout::Section const section ) +{ + for( integer idxRow = 0; idxRow< nbRows; idxRow++ ) + { + tableRows += GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); + for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) + { + string cell; + + if( section == Section::header ) + { + cell = m_columns[idxColumn].parameter.headerName[idxRow]; + } + else + { + cell = m_columns[idxColumn].columnValues[idxRow]; + } + integer const cellSize = m_columns[idxColumn].m_maxStringSize.length(); + tableRows += buildValueCell( m_columns[idxColumn].parameter.alignment, + cell, + cellSize ); + + if( idxColumn < m_columns.size() - 1 ) + { + tableRows += GEOS_FMT( "{:^{}}", "|", columnMargin ); + } + + } + if( m_columns.size() == 1 ) + { + tableRows += GEOS_FMT( "{:>{}}\n", "|", columnMargin ); + } + else + { + tableRows += GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); + } + + } + if( nbRows != 0 ) + { + tableRows += GEOS_FMT( "{}\n", sectionSeparator ); + } +} + +} diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp new file mode 100644 index 00000000000..31d80a0fe5d --- /dev/null +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -0,0 +1,137 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file TableFormatter.hpp + */ + +#ifndef GEOS_COMMON_TABLEFORMATTER_HPP +#define GEOS_COMMON_TABLEFORMATTER_HPP + + +#include "codingUtilities/TableData.hpp" +#include "codingUtilities/TableLayout.hpp" + +namespace geos +{ + +class TableFormatter +{ +public: + + TableFormatter( TableLayout tableLayout ); + + std::vector< TableLayout::Column > m_columns; + +private: + + /** + * @brief Fill the vector (m_column) in tableData with values from m_rows in tableLayout who store all values in an unsorted order + */ + void fillTableColumnsFromRows( std::vector< std::vector< string > > & tableData ); + +}; + +class TableCSVFormatter : public TableFormatter +{ +public: + + TableCSVFormatter( TableLayout tableLayout ); + + string dataToString( TableData2D tableData ); + + string dataToString( TableData tableData ); + + string headerToString(); + +}; + +class TableTextFormatter : public TableFormatter +{ + +public: + + TableTextFormatter( TableLayout tableLayout ); + + /** + * @brief return a string following the formatter + */ + string ToString( TableData tableData ); + +private: + + /** + * @brief Split all header names by detecting the newline \\n character. + * @param splitHeader A empty vector who will contain all split header names + * @param largestHeaderVectorSize The largest split header vector size + */ + void parseAndStoreHeaderSections( size_t & largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeader ); + + string & getTableBuilt( std::vector< std::vector< string > > rowsValues ); + /** + * @brief Iterate throught the header names vector. + * Adjust the size of each header vector by adding empty strings if needed. + * Store the modified header names in the corresponding column parameter. + * @param largestHeaderVectorSize The largest split header vector size + * @param splitHeader A vector containing all split header names + */ + void adjustHeaderSizesAndStore( size_t largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeader ); + + /** + * @brief For each column find and set the column's longest string + */ + void findAndSetMaxStringSize(); + + /** + * @brief Compute the largest string size in the table. If the table title is the largest string size in the table, recalculate for all + * columns the \p m_maxStringSize value by adding extra characters + * @param sectionlineLength The length of a section line + * @param titleLineLength The length of a title line + */ + void computeAndSetMaxStringSize( string::size_type sectionlineLength, + string::size_type titleLineLength ); + + /** + * @brief Compute and build the top and the section line separator + * @param topSeparator An empty string to be built + * @param sectionSeparator An empty string to be built + */ + void computeAndBuildSeparator( string & topSeparator, string & sectionSeparator ); + + /** + * @brief Build the table title section + * @param titleRows Rows containing the title section. + * @param topSeparator The top line separator + * @param sectionSeparator The section line separator + */ + void buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ); + + /** + * @brief Build a section by specifying it's type ( header or section ) + * @param sectionSeparator Line separator between sections + * @param rows A section row + * @param nbRows Indicates the number of lines in a section + * @param section The section to be built + */ + void buildSectionRows( string_view sectionSeparator, + string & rows, + integer const nbRows, + TableLayout::Section const section ); + +}; +} + +#endif diff --git a/src/coreComponents/codingUtilities/TableLayout.cpp b/src/coreComponents/codingUtilities/TableLayout.cpp new file mode 100644 index 00000000000..be4d72c5065 --- /dev/null +++ b/src/coreComponents/codingUtilities/TableLayout.cpp @@ -0,0 +1,54 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file TableData.hpp + */ + +#include "codingUtilities/TableLayout.hpp" + +namespace geos +{ + +TableLayout::TableLayout( std::vector< string > const & headers ) +{ + setMargin( MarginValue::medium ); + + for( size_t idx = 0; idx< headers.size(); idx++ ) + { + m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::middle, true}, {}, ""} ); + } +} + +TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter ) +{ + setMargin( MarginValue::medium ); + + for( size_t idx = 0; idx< columnParameter.size(); idx++ ) + { + if( columnParameter[idx].enabled ) + { + m_columns.push_back( {columnParameter[idx], {}, ""} ); + } + + } +} + +void TableLayout::setMargin( MarginValue marginType ) +{ + borderMargin = marginType; + columnMargin = integer( marginType ) * 2 + 1; +} + +} \ No newline at end of file diff --git a/src/coreComponents/codingUtilities/TableLayout.hpp b/src/coreComponents/codingUtilities/TableLayout.hpp new file mode 100644 index 00000000000..2322296a448 --- /dev/null +++ b/src/coreComponents/codingUtilities/TableLayout.hpp @@ -0,0 +1,92 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file TableLayout.hpp + */ + +#ifndef GEOS_COMMON_TABLELAYOUT_HPP +#define GEOS_COMMON_TABLELAYOUT_HPP + +#include "common/DataTypes.hpp" + +namespace geos +{ + +class TableLayout +{ + +public: + enum Alignment { right, left, middle }; + + enum MarginValue : integer + { + tiny = 0, + small = 1, + medium = 2, + large = 3 + }; + + /** + * @brief Structure to set up each colum parameters. + */ + struct ColumnParam + { + // A vector containing all string for a header name + std::vector< string > headerName; + // Alignment for a column. By default aligned to the right side + Alignment alignment = Alignment::right; + // A boolean to display a colummn + bool enabled = true; + }; + + /** + * @brief Construct a new Table object, all values in the table are centered by default + * @param columnNames + */ + TableLayout( std::vector< string > const & columnNames ); + + /** + * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels + * level + * @param columnParameter List of structures to set up each colum parameters. + */ + TableLayout( std::vector< ColumnParam > const & columnParameter ); + + void setMargin( MarginValue marginType ); + + enum Section { header, values }; + + /** + * @brief Struct for a column. + */ + struct Column + { + ColumnParam parameter; + // A vector containing all column values + std::vector< string > columnValues; + // The largest string in the column + string m_maxStringSize; + }; + + std::vector< Column > m_columns; + +private: + integer borderMargin; + integer columnMargin; + +}; +} + +#endif From 70d0a0113b18ed4a5d21020d1ca378f54ca8b6c0 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 11 Mar 2024 16:04:50 +0100 Subject: [PATCH 031/216] refortor still going up (missing doc and some minor refacto) --- .../codingUtilities/TableData.cpp | 2 +- .../codingUtilities/TableData.hpp | 19 +- .../codingUtilities/TableFormatter.cpp | 235 ++++++++++-------- .../codingUtilities/TableFormatter.hpp | 67 +++-- .../codingUtilities/TableLayout.cpp | 29 ++- .../codingUtilities/TableLayout.hpp | 68 ++++- .../mesh/generators/WellGeneratorBase.cpp | 49 ++-- 7 files changed, 317 insertions(+), 152 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.cpp b/src/coreComponents/codingUtilities/TableData.cpp index 1e36f2eea40..c9b36c9499a 100644 --- a/src/coreComponents/codingUtilities/TableData.cpp +++ b/src/coreComponents/codingUtilities/TableData.cpp @@ -59,7 +59,7 @@ void TableData2D::buildRows() auto const dataIt = data.find( id ); if( dataIt != data.end()) { - values.push_back( GEOS_FMT( "{}", dataIt->secondue )); + values.push_back( GEOS_FMT( "{}", dataIt->second )); } } diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index d157a653fac..edd2fe63c1b 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -38,17 +38,27 @@ class TableData std::vector< std::vector< string > > m_rows; -private: - std::vector< string > m_cellsValue; }; class TableData2D : public TableData { public: + /** + * @brief Add a cell to the table. + * Construct a map of pair and cell value + * @param T The value passed to addCell (can be any type). + * @param x The row index + * @param u The column index + * @param value Cell value to be added. + */ template< typename T > void addCell( real64 x, real64 y, T value ); // void printCount(); + + /** + * @brief Construct all rows from all cell values stored in map previously + */ void buildRows(); private: @@ -60,7 +70,8 @@ class TableData2D : public TableData template< typename ... Args > void TableData::addRow( Args const &... args ) { - int idx = 0; + //int idx = 0; + std::vector< string > m_cellsValue; ( [&] { string cellValue = GEOS_FMT( "{}", args ); // if( m_columns[idx].parameter.enabled ) @@ -77,7 +88,7 @@ void TableData2D::addCell( real64 x, real64 y, T value ) { std::pair< real64, real64 > id = std::pair< real64, real64 >( x, y ); - data[id] = GEOS_FMT( "{}", value ); + data[id] = GEOS_FMT( "{}", value ); columns.insert( x ); row.insert( y ); } diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index 3a6553493ff..078a30bd9e9 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -17,46 +17,45 @@ */ #include "codingUtilities/TableFormatter.hpp" - namespace geos { TableFormatter::TableFormatter( TableLayout tableLayout ) { - m_columns = tableLayout.m_columns; + m_tableLayout = tableLayout; } -void TableFormatter::fillTableColumnsFromRows( std::vector< std::vector< string > > const & rows ) +void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, + std::vector< std::vector< string > > const & rows ) { - std::vector< Column > & columns = tableLayout.m_columns(); - for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) { for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) { + std::cout << "column value " << rows[idxRow][idxColumn]; columns[idxColumn].columnValues.push_back( rows[idxRow][idxColumn] ); } + std::cout << std::endl; } - } //----------------------------------------------// TableCSVFormatter::TableCSVFormatter( TableLayout tableLayout ) { - m_columns = tableLayout.m_columns; - + m_tableLayout = tableLayout; } -string TableCSVFormatter::headerToString() +string TableCSVFormatter::headerToString( std::vector< TableLayout::Column > & columns, integer nbRows ) { string headerValues = ""; - - for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) + for( integer idxRow = 0; idxRow< nbRows; idxRow++ ) { - headerValues += m_columns[idxColumn].parameter.headerName[idxRow]; + for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) + { + headerValues += columns[idxColumn].parameter.columnName; + } } - return headerValues; } @@ -81,9 +80,10 @@ string TableCSVFormatter::dataToString( TableData2D tableData ) string TableCSVFormatter::dataToString( TableData tableData ) { std::vector< std::vector< string > > rowsValues = tableData.m_rows; + std::vector< TableLayout::Column > columns = m_tableLayout.m_columns; string data; - fillTableColumnsFromRows( rowsValues ); + fillTableColumnsFromRows( columns, rowsValues ); for( std::vector< string > row : rowsValues ) { @@ -98,64 +98,54 @@ string TableCSVFormatter::dataToString( TableData tableData ) //----------------------------------------------// +/** + * @brief Build a value cell given an alignment and spaces from "|" + * + * @param alignment + * @param value + * @param spaces + * @return A cell value + */ +string buildValueCell( TableLayout::Alignment const alignment, string_view value, integer const spaces ) +{ + switch( alignment ) + { + case TableLayout::right: return GEOS_FMT( "{:>{}}", value, spaces ); + case TableLayout::left: return GEOS_FMT( "{:<{}}", value, spaces ); + case TableLayout::middle: return GEOS_FMT( "{:^{}}", value, spaces ); + default: return GEOS_FMT( "{:<{}}", value, spaces ); + } +} + TableTextFormatter::TableTextFormatter( TableLayout tableLayout ): TableFormatter( tableLayout ) {} -string TableTextFormatter::ToString( TableData2D & tableData ) -{ - tableData.buildRows(); - getTableBuilt( tableData.m_rows ); -} - string TableTextFormatter::ToString( TableData & tableData ) { - return getTableBuilt( tableData.m_rows ); + return constructTable( tableData.m_rows ); } -string TableTextFormatter::getTableBuilt( std::vector< std::vector< string > > rowsValues ) +string TableTextFormatter::ToString( TableData2D & tableData ) { - string titleRows; - string topSeparator; - string sectionSeparator; - - size_t largestHeaderVectorSize = 0; - std::vector< std::vector< string > > splitHeader; - fillTableColumnsFromRows( rowsValues ); - - parseAndStoreHeaderSections( largestHeaderVectorSize, splitHeader ); - adjustHeaderSizesAndStore( largestHeaderVectorSize, splitHeader ); - - findAndSetMaxStringSize(); - computeAndBuildSeparator( topSeparator, sectionSeparator ); - - if( !tableTitle.empty()) - { - buildTitleRow( titleRows, topSeparator, sectionSeparator ); - } - - string tableRows += GEOS_FMT( "{}\n", sectionSeparator ); - buildSectionRows( sectionSeparator, tableRows, largestHeaderVectorSize, TableLayout::Section::header ); - buildSectionRows( sectionSeparator, tableRows, rowsValues.size(), TableLayout::Section::values ); - - string const tableOutput = titleRows + tableRows + '\n'; - - return tableOutput; + tableData.buildRows(); + return constructTable( tableData.m_rows ); } -void TableTextFormatter::parseAndStoreHeaderSections( size_t & largestHeaderVectorSize, +void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout::Column > & columns, + size_t & largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ) { - for( size_t columnParamIdx = 0; columnParamIdx< m_columns.size(); columnParamIdx++ ) + for( size_t columnParamIdx = 0; columnParamIdx< columns.size(); columnParamIdx++ ) { std::vector< string > splitHeaderParts; + //at this part column name isn't split + std::istringstream ss( columns[columnParamIdx].parameter.columnName ); + string subColumnNames; - std::istringstream ss( tableLayout.m_columns[columnParamIdx].parameter.headerName[0] ); - string subHeaderName; - - while( getline( ss, subHeaderName, '\n' )) + while( getline( ss, subColumnNames, '\n' )) { - splitHeaderParts.push_back( subHeaderName ); + splitHeaderParts.push_back( subColumnNames ); } size_t const cellSize = splitHeaderParts.size(); @@ -165,46 +155,49 @@ void TableTextFormatter::parseAndStoreHeaderSections( size_t & largestHeaderVect } } -void TableTextFormatter::adjustHeaderSizesAndStore( size_t largestHeaderVectorSize, +void TableTextFormatter::adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, + size_t largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ) { - for( size_t columnParamIdx = 0; columnParamIdx < m_columns.size(); columnParamIdx++ ) + for( size_t columnParamIdx = 0; columnParamIdx < columns.size(); columnParamIdx++ ) { if( splitHeader[columnParamIdx].size() < largestHeaderVectorSize ) { integer const whiteRowToAdd = largestHeaderVectorSize - splitHeader[columnParamIdx].size(); splitHeader[columnParamIdx].insert( splitHeader[columnParamIdx].end(), whiteRowToAdd, " " ); } - m_columns[columnParamIdx].parameter.headerName = splitHeader[columnParamIdx]; + columns[columnParamIdx].parameter.splitColumnName = splitHeader[columnParamIdx]; } } -void TableTextFormatter::findAndSetMaxStringSize() +void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, + size_t nbRows ) { string maxStringSize = ""; - for( size_t idxColumn = 0; idxColumn < m_columns.size(); idxColumn++ ) + for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) { - auto it = std::max_element( m_columns[idxColumn].parameter.headerName.begin(), - m_columns[idxColumn].parameter.headerName.end(), + auto it = std::max_element( columns[idxColumn].parameter.splitColumnName.begin(), + columns[idxColumn].parameter.splitColumnName.end(), []( const auto & a, const auto & b ) { return a.size() < b.size(); } ); maxStringSize = *it; - - for( size_t idxRow = 0; idxRow < rowsValues.size(); idxRow++ ) + for( size_t idxRow = 0; idxRow < nbRows; idxRow++ ) { - string cell = m_columns[idxColumn].columnValues[idxRow]; + string cell = columns[idxColumn].columnValues[idxRow]; + if( maxStringSize.length() < cell.length()) { maxStringSize = cell; } } - m_columns[idxColumn].m_maxStringSize = maxStringSize; + columns[idxColumn].m_maxStringSize = maxStringSize; } } -void TableTextFormatter::computeAndSetMaxStringSize( string::size_type sectionlineLength, +void TableTextFormatter::computeAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, + string::size_type sectionlineLength, string::size_type titleLineLength ) { integer extraLinesPerColumn; @@ -212,62 +205,70 @@ void TableTextFormatter::computeAndSetMaxStringSize( string::size_type sectionli integer newStringSize; extraLines = titleLineLength - sectionlineLength; - extraLinesPerColumn = std::ceil( extraLines / m_columns.size() ); + extraLinesPerColumn = std::ceil( extraLines / columns.size() ); - for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) + for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { - newStringSize = extraLinesPerColumn + m_columns[idxColumn].m_maxStringSize.size(); - if( idxColumn == m_columns.size() - 1 || m_columns.size() == 1 ) + newStringSize = extraLinesPerColumn + columns[idxColumn].m_maxStringSize.size(); + if( idxColumn == columns.size() - 1 || columns.size() == 1 ) { - m_columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", - m_columns[idxColumn].m_maxStringSize, - newStringSize + columnMargin ); + columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", + columns[idxColumn].m_maxStringSize, + newStringSize + m_tableLayout.getColumnMargin() ); } else { - m_columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", - m_columns[idxColumn].m_maxStringSize, - newStringSize ); + columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", + columns[idxColumn].m_maxStringSize, + newStringSize ); } } } -void TableTextFormatter::computeAndBuildSeparator( string & topSeparator, string & sectionSeparator ) +void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Column > & columns, + string & topSeparator, + string & sectionSeparator ) { + integer columnMargin = m_tableLayout.getColumnMargin(); + integer borderMargin = m_tableLayout.getColumnMargin(); + integer marginTitle = m_tableLayout.getMarginTitle(); + string tableTitle = string( m_tableLayout.getTitle() ); + string::size_type sectionlineLength = 0; string::size_type titleLineLength = tableTitle.length() + ( marginTitle * 2 ); - integer nbSpaceBetweenColumn = ( ( m_columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); + integer nbSpaceBetweenColumn = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); + if( !tableTitle.empty()) { tableTitle = GEOS_FMT( "{:^{}}", tableTitle, titleLineLength ); } - for( std::size_t i = 0; i < m_columns.size(); ++i ) + for( std::size_t i = 0; i < columns.size(); ++i ) { - sectionlineLength += m_columns[i].m_maxStringSize.length(); + sectionlineLength += columns[i].m_maxStringSize.length(); } sectionlineLength += nbSpaceBetweenColumn; if( sectionlineLength < titleLineLength ) { - computeAndSetMaxStringSize( sectionlineLength, titleLineLength ); + computeAndSetMaxStringSize( columns, sectionlineLength, titleLineLength ); } - if( m_columns.size() == 1 ) + if( columns.size() == 1 ) { sectionSeparator += GEOS_FMT( "+{:-<{}}+", "", - ( m_columns[0].m_maxStringSize.length() + (borderMargin - 1) + columnMargin )); + ( columns[0].m_maxStringSize.length() + (borderMargin - 1) + columnMargin )); } else { - for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) + for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { - integer const cellSize = m_columns[idxColumn].m_maxStringSize.length(); + integer const cellSize = columns[idxColumn].m_maxStringSize.length(); if( idxColumn == 0 ) { sectionSeparator += GEOS_FMT( "+{:-<{}}", "", ( cellSize + borderMargin )); } - else if( idxColumn == (m_columns.size() - 1)) + else if( idxColumn == (columns.size() - 1)) { sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); sectionSeparator += GEOS_FMT( "{:->{}}", "+", ( cellSize + borderMargin + 1 ) ); @@ -285,45 +286,49 @@ void TableTextFormatter::computeAndBuildSeparator( string & topSeparator, string void TableTextFormatter::buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ) { titleRows = GEOS_FMT( "\n{}\n|", topSeparator ); - titleRows += buildValueCell( Alignment::middle, - tableTitle, + titleRows += buildValueCell( TableLayout::Alignment::middle, + m_tableLayout.getTitle(), (sectionSeparator.length() - 2) // -2 for || ); titleRows += GEOS_FMT( "{}\n", "|" ); } -void TableTextFormatter::buildSectionRows( string_view sectionSeparator, +void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > & columns, + string_view sectionSeparator, string & tableRows, integer const nbRows, TableLayout::Section const section ) { + integer columnMargin = m_tableLayout.getColumnMargin(); + integer borderMargin = m_tableLayout.getColumnMargin(); + for( integer idxRow = 0; idxRow< nbRows; idxRow++ ) { tableRows += GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); - for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) + for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { string cell; - if( section == Section::header ) + if( section == TableLayout::Section::header ) { - cell = m_columns[idxColumn].parameter.headerName[idxRow]; + cell = columns[idxColumn].parameter.splitColumnName[idxRow]; } else { - cell = m_columns[idxColumn].columnValues[idxRow]; + cell = columns[idxColumn].columnValues[idxRow]; } - integer const cellSize = m_columns[idxColumn].m_maxStringSize.length(); - tableRows += buildValueCell( m_columns[idxColumn].parameter.alignment, + integer const cellSize = columns[idxColumn].m_maxStringSize.length(); + tableRows += buildValueCell( columns[idxColumn].parameter.alignment, cell, cellSize ); - if( idxColumn < m_columns.size() - 1 ) + if( idxColumn < columns.size() - 1 ) { tableRows += GEOS_FMT( "{:^{}}", "|", columnMargin ); } } - if( m_columns.size() == 1 ) + if( columns.size() == 1 ) { tableRows += GEOS_FMT( "{:>{}}\n", "|", columnMargin ); } @@ -339,4 +344,38 @@ void TableTextFormatter::buildSectionRows( string_view sectionSeparator, } } +string TableTextFormatter::constructTable( std::vector< std::vector< string > > & rowsValues ) +{ + string titleRows; + string topSeparator; + string sectionSeparator; + + size_t largestHeaderVectorSize = 0; + std::vector< std::vector< string > > splitHeader; + std::vector< TableLayout::Column > columns = m_tableLayout.m_columns; + + string tableTitle = string( m_tableLayout.getTitle()); + + fillTableColumnsFromRows( columns, rowsValues ); + + parseAndStoreHeaderSections( columns, largestHeaderVectorSize, splitHeader ); + adjustHeaderSizesAndStore( columns, largestHeaderVectorSize, splitHeader ); + + findAndSetMaxStringSize( columns, rowsValues.size()); + computeAndBuildSeparator( columns, topSeparator, sectionSeparator ); + + if( !tableTitle.empty()) + { + buildTitleRow( titleRows, topSeparator, sectionSeparator ); + } + + string tableRows = GEOS_FMT( "{}\n", sectionSeparator ); + buildSectionRows( columns, sectionSeparator, tableRows, largestHeaderVectorSize, TableLayout::Section::header ); + buildSectionRows( columns, sectionSeparator, tableRows, rowsValues.size(), TableLayout::Section::values ); + + string tableOutput = titleRows + tableRows + '\n'; + + return tableOutput; +} + } diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index 31d80a0fe5d..48612178741 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -19,7 +19,6 @@ #ifndef GEOS_COMMON_TABLEFORMATTER_HPP #define GEOS_COMMON_TABLEFORMATTER_HPP - #include "codingUtilities/TableData.hpp" #include "codingUtilities/TableLayout.hpp" @@ -30,30 +29,59 @@ class TableFormatter { public: - TableFormatter( TableLayout tableLayout ); + /** + * @brief Constructor by default + */ + TableFormatter() = default; - std::vector< TableLayout::Column > m_columns; + /** + * @brief Construct a new Table Formatter from a tableLayout + * @param tableLayout Contain all column names and optionnaly the table title + */ + TableFormatter( TableLayout tableLayout ); -private: + TableLayout m_tableLayout; /** * @brief Fill the vector (m_column) in tableData with values from m_rows in tableLayout who store all values in an unsorted order */ - void fillTableColumnsFromRows( std::vector< std::vector< string > > & tableData ); + void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, + std::vector< std::vector< string > > const & tableData ); }; class TableCSVFormatter : public TableFormatter { public: + /** + * @brief Constructor by default + */ + TableCSVFormatter() = default; + /** + * @brief Construct a new Table Formatter from a tableLayout + * @param tableLayout Contain all column names and optionnaly the table title + */ TableCSVFormatter( TableLayout tableLayout ); + /** + * @param tableData A 2-dimensions tabke + * @return A string of CSV data from a 2-dimensions table + */ string dataToString( TableData2D tableData ); + /** + * @param tableData A 2-dimensions tabke + * @return A string of CSV data from a 1-dimensions table + */ string dataToString( TableData tableData ); - string headerToString(); + /** + * @param columns + * @param nbRows + * @return string + */ + string headerToString( std::vector< TableLayout::Column > & columns, integer nbRows ); }; @@ -67,7 +95,12 @@ class TableTextFormatter : public TableFormatter /** * @brief return a string following the formatter */ - string ToString( TableData tableData ); + string ToString( TableData & tableData ); + + /** + * @brief return a string following the formatter + */ + string ToString( TableData2D & tableData ); private: @@ -76,10 +109,11 @@ class TableTextFormatter : public TableFormatter * @param splitHeader A empty vector who will contain all split header names * @param largestHeaderVectorSize The largest split header vector size */ - void parseAndStoreHeaderSections( size_t & largestHeaderVectorSize, + void parseAndStoreHeaderSections( std::vector< TableLayout::Column > & columns, + size_t & largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ); - string & getTableBuilt( std::vector< std::vector< string > > rowsValues ); + string constructTable( std::vector< std::vector< string > > & rowsValues ); /** * @brief Iterate throught the header names vector. * Adjust the size of each header vector by adding empty strings if needed. @@ -87,13 +121,14 @@ class TableTextFormatter : public TableFormatter * @param largestHeaderVectorSize The largest split header vector size * @param splitHeader A vector containing all split header names */ - void adjustHeaderSizesAndStore( size_t largestHeaderVectorSize, + void adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, + size_t largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ); /** * @brief For each column find and set the column's longest string */ - void findAndSetMaxStringSize(); + void findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, size_t nbRows ); /** * @brief Compute the largest string size in the table. If the table title is the largest string size in the table, recalculate for all @@ -101,7 +136,8 @@ class TableTextFormatter : public TableFormatter * @param sectionlineLength The length of a section line * @param titleLineLength The length of a title line */ - void computeAndSetMaxStringSize( string::size_type sectionlineLength, + void computeAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, + string::size_type sectionlineLength, string::size_type titleLineLength ); /** @@ -109,7 +145,9 @@ class TableTextFormatter : public TableFormatter * @param topSeparator An empty string to be built * @param sectionSeparator An empty string to be built */ - void computeAndBuildSeparator( string & topSeparator, string & sectionSeparator ); + void computeAndBuildSeparator( std::vector< TableLayout::Column > & columns, + string & topSeparator, + string & sectionSeparator ); /** * @brief Build the table title section @@ -126,7 +164,8 @@ class TableTextFormatter : public TableFormatter * @param nbRows Indicates the number of lines in a section * @param section The section to be built */ - void buildSectionRows( string_view sectionSeparator, + void buildSectionRows( std::vector< TableLayout::Column > & columns, + string_view sectionSeparator, string & rows, integer const nbRows, TableLayout::Section const section ); diff --git a/src/coreComponents/codingUtilities/TableLayout.cpp b/src/coreComponents/codingUtilities/TableLayout.cpp index be4d72c5065..aed9c7f876e 100644 --- a/src/coreComponents/codingUtilities/TableLayout.cpp +++ b/src/coreComponents/codingUtilities/TableLayout.cpp @@ -24,7 +24,6 @@ namespace geos TableLayout::TableLayout( std::vector< string > const & headers ) { setMargin( MarginValue::medium ); - for( size_t idx = 0; idx< headers.size(); idx++ ) { m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::middle, true}, {}, ""} ); @@ -45,10 +44,36 @@ TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter ) } } +void TableLayout::setTitle( string_view title ) +{ + tableTitle = title; +} + void TableLayout::setMargin( MarginValue marginType ) { borderMargin = marginType; columnMargin = integer( marginType ) * 2 + 1; } -} \ No newline at end of file +string_view TableLayout::getTitle() const +{ + return tableTitle; +} + + +integer const & TableLayout::getBorderMargin() const +{ + return borderMargin; +} + +integer const & TableLayout::getColumnMargin() const +{ + return columnMargin; +} + +integer const & TableLayout::getMarginTitle() const +{ + return marginTitle; +} + +} diff --git a/src/coreComponents/codingUtilities/TableLayout.hpp b/src/coreComponents/codingUtilities/TableLayout.hpp index 2322296a448..ddff87ccacb 100644 --- a/src/coreComponents/codingUtilities/TableLayout.hpp +++ b/src/coreComponents/codingUtilities/TableLayout.hpp @@ -38,19 +38,45 @@ class TableLayout large = 3 }; + enum Section { header, values }; + /** * @brief Structure to set up each colum parameters. */ struct ColumnParam { - // A vector containing all string for a header name - std::vector< string > headerName; + + string columnName; // Alignment for a column. By default aligned to the right side Alignment alignment = Alignment::right; // A boolean to display a colummn bool enabled = true; + // Vector containing substring column name delimited by "\n" + std::vector< string > splitColumnName; + + ColumnParam( const std::string & name, Alignment align ) + : columnName( name ), alignment( align ) + {} + + ColumnParam( const std::string & name, Alignment align, bool display ) + : columnName( name ), alignment( align ), enabled( display ) + {} }; + /** + * @brief Struct for a column. + */ + struct Column + { + ColumnParam parameter; + // A vector containing all column values + std::vector< string > columnValues; + // The largest string in the column + string m_maxStringSize; + }; + + TableLayout() = default; + /** * @brief Construct a new Table object, all values in the table are centered by default * @param columnNames @@ -64,27 +90,45 @@ class TableLayout */ TableLayout( std::vector< ColumnParam > const & columnParameter ); + /** + * @brief Set the minimal margin width between row content and borders. + * @param marginType + */ void setMargin( MarginValue marginType ); - enum Section { header, values }; + /** + * @brief Set the table name + * @param tableTitle The table name + */ + void setTitle( string_view tableTitle ); /** - * @brief Struct for a column. + * @return return the table name */ - struct Column - { - ColumnParam parameter; - // A vector containing all column values - std::vector< string > columnValues; - // The largest string in the column - string m_maxStringSize; - }; + string_view getTitle() const; + + /** + * @return return the border margin + */ + integer const & getBorderMargin() const; + + /** + * @return return the column margin + */ + integer const & getColumnMargin() const; + + /** + * @return return the margin title + */ + integer const & getMarginTitle() const; std::vector< Column > m_columns; private: + string tableTitle; integer borderMargin; integer columnMargin; + integer marginTitle = 2; }; } diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 39168eeec39..3a7c1c14c6c 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -17,7 +17,9 @@ #include "mesh/Perforation.hpp" #include "mesh/generators/LineBlockABC.hpp" #include "LvArray/src/genericTensorOps.hpp" -#include "codingUtilities/Table.hpp" +#include "codingUtilities/TableLayout.hpp" +#include "codingUtilities/TableData.hpp" +#include "codingUtilities/TableFormatter.hpp" #include "common/Format.hpp" namespace geos { @@ -529,18 +531,20 @@ void WellGeneratorBase::debugWellGeometry() const return; } - Table table = Table( { - Table::ColumnParam{{"Element no."}, Table::Alignment::right}, - Table::ColumnParam{{"CoordX"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordY"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordZ"}, Table::Alignment::middle}, - Table::ColumnParam{{"Prev\nElement"}, Table::Alignment::right}, - Table::ColumnParam{{"Next\nElement"}, Table::Alignment::right}, + TableLayout tableLayout = TableLayout( { + TableLayout::ColumnParam{"Element no.", TableLayout::Alignment::right}, + TableLayout::ColumnParam{"CoordX", TableLayout::Alignment::middle}, + TableLayout::ColumnParam{"CoordY", TableLayout::Alignment::middle}, + TableLayout::ColumnParam{"CoordZ", TableLayout::Alignment::middle}, + TableLayout::ColumnParam{"Prev\nElement", TableLayout::Alignment::right}, + TableLayout::ColumnParam{"Next\nElement", TableLayout::Alignment::right}, } ); - string titleName = "InternalWellGenerator " + getName(); - table.setTitle( titleName ); + tableLayout.setTitle( "InternalWellGenerator " + getName()); + //1. formatting data + TableData tableData; + //2. collecting data for( globalIndex iwelem = 0; iwelem < m_numElems; ++iwelem ) { std::optional< globalIndex > nextElement; @@ -555,21 +559,24 @@ void WellGeneratorBase::debugWellGeometry() const { prevElement = m_prevElemId[iwelem][0]; } - - table.addRow( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, nextElement ); + + tableData.addRow( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, nextElement ); } - table.drawToStream(); - Table tablePerforation = Table( {"Perforation no.", "Coordinates", "connected to" } ); - string titlePerfo = "Peforation table"; - tablePerforation.setTitle( titlePerfo ); + TableTextFormatter tableFormatter( tableLayout ); + GEOS_LOG_RANK_0( tableFormatter.ToString( tableData )); + //3. dumping - for( globalIndex iperf = 0; iperf < m_numPerforations; ++iperf ) - { - tablePerforation.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); - } + // Table tablePerforation = Table( {"Perforation no.", "Coordinates", "connected to" } ); + // string titlePerfo = "Peforation table"; + // tablePerforation.setTitle( titlePerfo ); + + // for( globalIndex iperf = 0; iperf < m_numPerforations; ++iperf ) + // { + // tablePerforation.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); + // } - tablePerforation.drawToStream(); + // tablePerforation.drawToStream(); } From f5251f56193be5f141d6264b62aa257290dc520e Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 11 Mar 2024 16:25:05 +0100 Subject: [PATCH 032/216] uncrustify + perfo example addded --- .../codingUtilities/TableData.hpp | 6 ++-- .../codingUtilities/TableFormatter.cpp | 21 +++++------ .../codingUtilities/TableFormatter.hpp | 12 +++---- .../mesh/generators/WellGeneratorBase.cpp | 35 ++++++++++--------- 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index edd2fe63c1b..092bf8a1882 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -55,9 +55,9 @@ class TableData2D : public TableData template< typename T > void addCell( real64 x, real64 y, T value ); // void printCount(); - + /** - * @brief Construct all rows from all cell values stored in map previously + * @brief Construct all rows from all cell values stored in map previously */ void buildRows(); @@ -71,7 +71,7 @@ template< typename ... Args > void TableData::addRow( Args const &... args ) { //int idx = 0; - std::vector< string > m_cellsValue; + std::vector< string > m_cellsValue; ( [&] { string cellValue = GEOS_FMT( "{}", args ); // if( m_columns[idx].parameter.enabled ) diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index 078a30bd9e9..1af281fb6a4 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -32,30 +32,29 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column { for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) { - std::cout << "column value " << rows[idxRow][idxColumn]; columns[idxColumn].columnValues.push_back( rows[idxRow][idxColumn] ); } - std::cout << std::endl; } } -//----------------------------------------------// +/////////////////////////////////////////////////////////////////////// +////// CSV Formatter implementation +/////////////////////////////////////////////////////////////////////// TableCSVFormatter::TableCSVFormatter( TableLayout tableLayout ) { m_tableLayout = tableLayout; } -string TableCSVFormatter::headerToString( std::vector< TableLayout::Column > & columns, integer nbRows ) +string TableCSVFormatter::headerToString( std::vector< TableLayout::Column > & columns ) { string headerValues = ""; - for( integer idxRow = 0; idxRow< nbRows; idxRow++ ) + + for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { - for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) - { - headerValues += columns[idxColumn].parameter.columnName; - } + headerValues += columns[idxColumn].parameter.columnName; } + return headerValues; } @@ -96,7 +95,9 @@ string TableCSVFormatter::dataToString( TableData tableData ) return data; } -//----------------------------------------------// +/////////////////////////////////////////////////////////////////////// +////// Log Formatter implementation +/////////////////////////////////////////////////////////////////////// /** * @brief Build a value cell given an alignment and spaces from "|" diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index 48612178741..e6b8774f322 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -66,22 +66,22 @@ class TableCSVFormatter : public TableFormatter /** * @param tableData A 2-dimensions tabke - * @return A string of CSV data from a 2-dimensions table + * @return A string of CSV data from a 2-dimensions table */ string dataToString( TableData2D tableData ); /** * @param tableData A 2-dimensions tabke - * @return A string of CSV data from a 1-dimensions table + * @return A string of CSV data from a 1-dimensions table */ string dataToString( TableData tableData ); /** - * @param columns - * @param nbRows - * @return string + * @param columns + * @param nbRows + * @return A string with all column names */ - string headerToString( std::vector< TableLayout::Column > & columns, integer nbRows ); + string headerToString( std::vector< TableLayout::Column > & columns ); }; diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 3a7c1c14c6c..317c087193c 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -531,7 +531,8 @@ void WellGeneratorBase::debugWellGeometry() const return; } - TableLayout tableLayout = TableLayout( { + //1. formatting data + TableLayout tableWellLayout = TableLayout( { TableLayout::ColumnParam{"Element no.", TableLayout::Alignment::right}, TableLayout::ColumnParam{"CoordX", TableLayout::Alignment::middle}, TableLayout::ColumnParam{"CoordY", TableLayout::Alignment::middle}, @@ -540,9 +541,9 @@ void WellGeneratorBase::debugWellGeometry() const TableLayout::ColumnParam{"Next\nElement", TableLayout::Alignment::right}, } ); - tableLayout.setTitle( "InternalWellGenerator " + getName()); - //1. formatting data - TableData tableData; + tableWellLayout.setTitle( "InternalWellGenerator " + getName()); + + TableData tableWellData; //2. collecting data for( globalIndex iwelem = 0; iwelem < m_numElems; ++iwelem ) @@ -559,24 +560,24 @@ void WellGeneratorBase::debugWellGeometry() const { prevElement = m_prevElemId[iwelem][0]; } - - tableData.addRow( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, nextElement ); - } - TableTextFormatter tableFormatter( tableLayout ); - GEOS_LOG_RANK_0( tableFormatter.ToString( tableData )); + tableWellData.addRow( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, nextElement ); + } //3. dumping + TableTextFormatter tableFormatter( tableWellLayout ); + GEOS_LOG_RANK_0( tableFormatter.ToString( tableWellData )); - // Table tablePerforation = Table( {"Perforation no.", "Coordinates", "connected to" } ); - // string titlePerfo = "Peforation table"; - // tablePerforation.setTitle( titlePerfo ); + TableLayout tableLayoutPerfo = TableLayout( {"Perforation no.", "Coordinates", "connected to" } ); + tableLayoutPerfo.setTitle( "Peforation table" ); - // for( globalIndex iperf = 0; iperf < m_numPerforations; ++iperf ) - // { - // tablePerforation.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); - // } + TableData tablePerfoData; + for( globalIndex iperf = 0; iperf < m_numPerforations; ++iperf ) + { + tablePerfoData.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); + } - // tablePerforation.drawToStream(); + TableTextFormatter tablePerfoLog( tableLayoutPerfo ); + GEOS_LOG_RANK_0( tablePerfoLog.ToString( tablePerfoData )); } From 1bec18ed4eaf9c78735600431ef6211ef55ff09f Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 11 Mar 2024 17:12:12 +0100 Subject: [PATCH 033/216] update test + margin correction --- .../codingUtilities/CMakeLists.txt | 8 +- .../codingUtilities/TableFormatter.cpp | 7 +- .../codingUtilities/tests/testTable.cpp | 549 +++++++----------- 3 files changed, 206 insertions(+), 358 deletions(-) diff --git a/src/coreComponents/codingUtilities/CMakeLists.txt b/src/coreComponents/codingUtilities/CMakeLists.txt index 5ccef926155..4ccfa5a2eab 100644 --- a/src/coreComponents/codingUtilities/CMakeLists.txt +++ b/src/coreComponents/codingUtilities/CMakeLists.txt @@ -9,7 +9,9 @@ set( codingUtilities_headers UnitTestUtilities.hpp Utilities.hpp traits.hpp - Table.hpp + TableFormatter.hpp + TableData.hpp + TableLayout.hpp ) # @@ -18,7 +20,9 @@ set( codingUtilities_headers set( codingUtilities_sources Parsing.cpp StringUtilities.cpp - Table.cpp ) + TableFormatter.cpp + TableData.cpp + TableLayout.cpp ) set( dependencyList ${parallelDeps} common fast_float ) diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index 1af281fb6a4..e8c78049cc9 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -186,13 +186,14 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu maxStringSize = *it; for( size_t idxRow = 0; idxRow < nbRows; idxRow++ ) { - string cell = columns[idxColumn].columnValues[idxRow]; + string cell = columns[idxColumn].columnValues[idxRow]; if( maxStringSize.length() < cell.length()) { maxStringSize = cell; } } + columns[idxColumn].m_maxStringSize = maxStringSize; } } @@ -231,7 +232,7 @@ void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Col string & sectionSeparator ) { integer columnMargin = m_tableLayout.getColumnMargin(); - integer borderMargin = m_tableLayout.getColumnMargin(); + integer borderMargin = m_tableLayout.getBorderMargin(); integer marginTitle = m_tableLayout.getMarginTitle(); string tableTitle = string( m_tableLayout.getTitle() ); @@ -301,7 +302,7 @@ void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > & TableLayout::Section const section ) { integer columnMargin = m_tableLayout.getColumnMargin(); - integer borderMargin = m_tableLayout.getColumnMargin(); + integer borderMargin = m_tableLayout.getBorderMargin(); for( integer idxRow = 0; idxRow< nbRows; idxRow++ ) { diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 6f873131116..9a3343772cc 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -13,7 +13,9 @@ */ // Source includes -#include "codingUtilities/Table.hpp" +#include "codingUtilities/TableData.hpp" +#include "codingUtilities/TableFormatter.hpp" +#include "codingUtilities/TableLayout.hpp" #include "dataRepository/Group.hpp" // TPL includes #include @@ -24,368 +26,209 @@ using namespace geos; TEST( testTable, tableClass ) { - std::vector< string > tableTestsOutput; - - std::ostringstream oss; - - Table tableTest( {"Well\nelement no.\nPV weighted\nbar", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement"} - ); - tableTest.setTitle( "InternalWellGenerator well_injector1" ); - tableTest.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); - tableTest.addRow( "", "", "", "", "" ); - tableTest.addRow( "Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", "[30.21543]", "30.45465142", - 787442, 10 ); - tableTest.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( tableTestsOutput[0], - "\n+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| Well | CordX | CoordZ | Prev | Next |\n" - "| element no. | | | element | element |\n" - "| PV weighted | | | | |\n" - "| bar | | | | |\n" - "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" - "| | | | | |\n" - "| Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | [30.21543] | 30.45465142 | 787442 | 10 |\n" - "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" - ); - - Table tableTest2( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement"} - ); - tableTest2.setTitle( "InternalWellGenerator well_injector1" ); - tableTest2.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); - tableTest2.addRow( "", "", "", "", "" ); - tableTest2.addRow( "value23", "[30.21543]", "30.45465142", 787442, 10 ); - tableTest2.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( tableTestsOutput[1], - "\n+---------------------------------------------------------------------------------------------------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| Duis fringilla, ligula sed porta fringilla, | CordX | CoordZ | Prev | Next |\n" - "| ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | | | element | element |\n" - "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" - "| | | | | |\n" - "| value23 | [30.21543] | 30.45465142 | 787442 | 10 |\n" - "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" - ); - - Table tableTest3 ( { - "Cras egestas ipsum a nisl. Vivamus variu\ndolor utsisicdis parturient montes,\nnascetur ridiculus mus. Duis fringilla, ligula sed porta fringilla, ligula wisicommodo felis,\nut adi\npiscing felis dui in enim. Suspendisse malesuada ultrices ante", - "CoordX", "C", "CoordZ", - } ); - tableTest3.setTitle( "InternalWellGenerator well_injector1" ); - tableTest3.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ ( tableTestsOutput[2], - "\n+-----------------------------------------------------------------------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+-------------------------------------------------------------------------------------------------+----------+-----+----------+\n" - "| Cras egestas ipsum a nisl. Vivamus variu | CoordX | C | CoordZ |\n" - "| dolor utsisicdis parturient montes, | | | |\n" - "| nascetur ridiculus mus. Duis fringilla, ligula sed porta fringilla, ligula wisicommodo felis, | | | |\n" - "| ut adi | | | |\n" - "| piscing felis dui in enim. Suspendisse malesuada ultrices ante | | | |\n" - "+-------------------------------------------------------------------------------------------------+----------+-----+----------+\n\n" - ); - - Table tableTest4( { - Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordX"}, Table::Alignment::left}, - Table::ColumnParam{{"C"}, Table::Alignment::left}, - Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, - Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::right}, - Table::ColumnParam{{"Next\nelement"}, Table::Alignment::right} - } ); - tableTest4.setTitle( "InternalWellGenerator well_injector1" ); - tableTest4.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest4.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest4.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( tableTestsOutput[3], - "\n+-----------------------------------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" - "| | | | | element | element |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" - ); - - Table tableTest5( { - Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordX"}, Table::Alignment::left}, - Table::ColumnParam{{"C"}, Table::Alignment::left}, - Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, - Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::right, false}, - Table::ColumnParam{{"Next\nelement"}, Table::Alignment::right, false}, - - } ); - tableTest5.setTitle( "InternalWellGenerator well_injector1" ); - tableTest5.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest5.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest5.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( tableTestsOutput[4], - "\n+-----------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+----------------+----------+-----------------------+-------------+\n" - "| Cras egestas | CoordX | C | CoordZ |\n" - "+----------------+----------+-----------------------+-------------+\n" - "| value1 | | 3.0 | 3.0129877 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 |\n" - "+----------------+----------+-----------------------+-------------+\n\n" - ); - - Table tableTest6( { - Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordX"}, Table::Alignment::left}, - Table::ColumnParam{{"C"}, Table::Alignment::left}, - Table::ColumnParam{{"CoordZ"}, Table::Alignment::middle}, - Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::right}, - Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, - } ); - tableTest6.setTitle( "InternalWellGenerator well_injector1" ); - tableTest6.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest6.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest6.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( tableTestsOutput[5], - "\n+-----------------------------------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" - "| | | | | element | element |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" - ); - - Table tableTest7( { - Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordX"}, Table::Alignment::right}, - Table::ColumnParam{{"C"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, - Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::left, false}, - Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle, false}, - } ); - tableTest7.setTitle( "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); - tableTest7.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest7.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest7.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( tableTestsOutput[6], - "\n+------------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" - "| Cras egestas | CoordX | C | CoordZ |\n" - "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" - "| value1 | | 3.0 | 3.0129877 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 |\n" - "+---------------------------+---------------------+----------------------------------+-----------------------------+\n\n" - ); - - Table tableTest8( { - Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordX"}, Table::Alignment::right}, - Table::ColumnParam{{"C"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, - Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::left}, - Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, - } ); - tableTest8.setTitle( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); - tableTest8.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest8.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest8.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( tableTestsOutput[7], - "\n+----------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "+-------------------+-------------+--------------------------+----------------+--------------+-------------------+\n" - "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" - "| | | | | element | element |\n" - "+-------------------+-------------+--------------------------+----------------+--------------+-------------------+\n" - "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+-------------------+-------------+--------------------------+----------------+--------------+-------------------+\n\n" - ); - - Table tableTest9( { - Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, - - } ); - tableTest9.setTitle( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); - tableTest9.addRow( "value1" ); - tableTest9.addRow( "val1" ); - tableTest9.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( tableTestsOutput[8], - "\n+-------------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "+-------------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas |\n" - "+-------------------------------------------------------------------------------------------------------------------+\n" - "| value1 |\n" - "| val1 |\n" - "+-------------------------------------------------------------------------------------------------------------------+\n\n" - ); + TableLayout tableLayout( {"Well\nelement no.\nPV weighted\nbar", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"} + ); + tableLayout.setTitle( "InternalWellGenerator well_injector1" ); + + TableData tableData; + tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); + tableData.addRow( "", "", "", "", "" ); + tableData.addRow( "Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", "[30.21543]", "30.45465142", + 787442, 10 ); + + TableTextFormatter tableText( tableLayout ); + EXPECT_EQ( tableText.ToString( + tableData ), + "\n+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| Well | CordX | CoordZ | Prev | Next |\n" + "| element no. | | | element | element |\n" + "| PV weighted | | | | |\n" + "| bar | | | | |\n" + "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" + "| | | | | |\n" + "| Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | [30.21543] | 30.45465142 | 787442 | 10 |\n" + "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" + ); + }; - Table tableTest10( { - Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, - } ); - tableTest10.setTitle( "title1" ); - tableTest10.addRow( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); - tableTest10.addRow( "val1" ); - tableTest10.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( tableTestsOutput[9], - "\n+--------------------------------------------------------------------------------------------------------------+\n" - "| title1 |\n" - "+--------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas |\n" - "+--------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "| val1 |\n" - "+--------------------------------------------------------------------------------------------------------------+\n\n" - ); + { + TableLayout tableLayout( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"} + ); + tableLayout.setTitle( "InternalWellGenerator well_injector1" ); + + TableData tableData; + tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); + tableData.addRow( "", "", "", "", "" ); + tableData.addRow( "value23", "[30.21543]", "30.45465142", 787442, 10 ); + + TableTextFormatter tableText( tableLayout ); + EXPECT_EQ( tableText.ToString( tableData ), + "\n+---------------------------------------------------------------------------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| Duis fringilla, ligula sed porta fringilla, | CordX | CoordZ | Prev | Next |\n" + "| ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | | | element | element |\n" + "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" + "| | | | | |\n" + "| value23 | [30.21543] | 30.45465142 | 787442 | 10 |\n" + "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" + ); + } - Table tableTest11( { - Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, - } ); - tableTest11.setTitle( "title1" ); - tableTest11.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( tableTestsOutput[10], - "\n+------------------+\n" - "| title1 |\n" - "+------------------+\n" - "| Cras egestas |\n" - "+------------------+\n\n" - ); + { + TableLayout tableLayout( { + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::right}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::right} + } + ); + tableLayout.setTitle( "InternalWellGenerator well_injector1" ); + + TableData tableData; + tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + + TableTextFormatter tableText( tableLayout ); + EXPECT_EQ( tableText.ToString( tableData ), + "\n+-----------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" + "| | | | | element | element |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" + ); + } - Table tableTest12( { - Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordX"}, Table::Alignment::right}, - Table::ColumnParam{{"C"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, - Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::left}, - Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, - } ); - tableTest12.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest12.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest12.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( tableTestsOutput[11], - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" - "| | | | | element | element |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" - ); + { + TableLayout tableLayout( { + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left, false}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::middle, false}, + } + ); + tableLayout.setTitle( "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + + TableData tableData; + tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + + TableTextFormatter tableText( tableLayout ); + EXPECT_EQ( tableText.ToString( tableData ), + "\n+------------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" + "| Cras egestas | CoordX | C | CoordZ |\n" + "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" + "| value1 | | 3.0 | 3.0129877 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 |\n" + "+---------------------------+---------------------+----------------------------------+-----------------------------+\n\n" + ); + } - Table tableTest13( { - Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordX"}, Table::Alignment::right}, - Table::ColumnParam{{"C"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, - Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::left}, - Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, - } ); - tableTest13.setTitle( "InternalWellGenerator well_injector1" ); - tableTest13.setMargin( Table::MarginValue::tiny ); - tableTest13.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableTest13.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - tableTest13.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( tableTestsOutput[12], - "\n+-----------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+------------+------+-------------------+---------+-------+-------+\n" - "|Cras egestas|CoordX| C |CoordZ |Prev | Next |\n" - "| | | | |element|element|\n" - "+------------+------+-------------------+---------+-------+-------+\n" - "| value1 | | 3.0 |3.0129877|2 | 1 |\n" - "| val1 | v|[3.045,42.02,89.25]|3 |10 | 3 |\n" - "+------------+------+-------------------+---------+-------+-------+\n\n" - ); + { + TableLayout tableLayout( { + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::middle}, + } + ); + tableLayout.setTitle( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + + TableData tableData; + tableData.addRow( "value1" ); + tableData.addRow( "val1" ); + + TableTextFormatter tableText( tableLayout ); + EXPECT_EQ( tableText.ToString( tableData ), + "\n+-------------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "+-------------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas |\n" + "+-------------------------------------------------------------------------------------------------------------------+\n" + "| value1 |\n" + "| val1 |\n" + "+-------------------------------------------------------------------------------------------------------------------+\n\n" + ); + } - std::vector< std::vector< std::string > > vecValues = { - {"value1", " ", "3.0", "3.0129877", "2", "1" }, - {"val1", "v", "[3.045,42.02,89.25]", "3", "10", "3" }, + { + TableLayout tableLayout( { + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::middle}, + } + ); + + TableData tableData; + tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + + TableTextFormatter tableText( tableLayout ); + EXPECT_EQ( tableText.ToString( tableData ), + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" + "| | | | | element | element |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" + ); }; - Table tableTest14( { - Table::ColumnParam{{"Cras egestas"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordX"}, Table::Alignment::right}, - Table::ColumnParam{{"C"}, Table::Alignment::middle}, - Table::ColumnParam{{"CoordZ"}, Table::Alignment::left}, - Table::ColumnParam{{"Prev\nelement"}, Table::Alignment::left}, - Table::ColumnParam{{"Next\nelement"}, Table::Alignment::middle}, - } ); - tableTest14.setTitle( "InternalWellGenerator well_injector1" ); - tableTest14.setMargin( Table::MarginValue::tiny ); - tableTest14.addRowsFromVectors( vecValues ); - tableTest14.drawToStream( oss ); - tableTestsOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( tableTestsOutput[13], - "\n+-----------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+------------+------+-------------------+---------+-------+-------+\n" - "|Cras egestas|CoordX| C |CoordZ |Prev | Next |\n" - "| | | | |element|element|\n" - "+------------+------+-------------------+---------+-------+-------+\n" - "| value1 | | 3.0 |3.0129877|2 | 1 |\n" - "| val1 | v|[3.045,42.02,89.25]|3 |10 | 3 |\n" - "+------------+------+-------------------+---------+-------+-------+\n\n" - ); + { + TableLayout tableLayout( { + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::middle}, + } ); + tableLayout.setTitle( "InternalWellGenerator well_injector1" ); + tableLayout.setMargin( TableLayout::MarginValue::tiny ); + + TableData tableData; + tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + + TableTextFormatter tableText( tableLayout ); + EXPECT_EQ( tableText.ToString( tableData ), + "\n+-----------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+------------+------+-------------------+---------+-------+-------+\n" + "|Cras egestas|CoordX| C |CoordZ |Prev | Next |\n" + "| | | | |element|element|\n" + "+------------+------+-------------------+---------+-------+-------+\n" + "| value1 | | 3.0 |3.0129877|2 | 1 |\n" + "| val1 | v|[3.045,42.02,89.25]|3 |10 | 3 |\n" + "+------------+------+-------------------+---------+-------+-------+\n\n" + ); + }; } - int main( int argc, char * * argv ) { testing::InitGoogleTest( &argc, argv ); From 2054bd41243d0f5669194fb3cbcdfbc182d70827 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 12 Mar 2024 17:08:20 +0100 Subject: [PATCH 034/216] added Formatter function, correction on TableData --- .../codingUtilities/TableData.cpp | 42 +++------ .../codingUtilities/TableData.hpp | 19 ++-- .../codingUtilities/TableFormatter.cpp | 86 ++++++++++++++----- .../codingUtilities/TableFormatter.hpp | 33 +++---- 4 files changed, 104 insertions(+), 76 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.cpp b/src/coreComponents/codingUtilities/TableData.cpp index c9b36c9499a..5052708c3a1 100644 --- a/src/coreComponents/codingUtilities/TableData.cpp +++ b/src/coreComponents/codingUtilities/TableData.cpp @@ -21,49 +21,29 @@ namespace geos { -// void TableData2D::printCount() -// { -// int nb=0, nbx=0, nby=0; - -// for( real64 x : columns ) -// { -// nbx++; -// } - -// for( real64 y : row ) -// { -// nby++; -// for( real64 x : columns ) -// { -// auto const dataIt = data.find( std::pair< real64, real64 >( x, y )); -// if( dataIt != data.end()) -// { -// nb++; -// } -// } -// } - -// std::cout<<"total = "< id = std::pair< real64, real64 >( x, y ); + std::pair< real64, real64 > id = std::pair< real64, real64 >( y, x ); auto const dataIt = data.find( id ); + if( dataIt != data.end()) { values.push_back( GEOS_FMT( "{}", dataIt->second )); } } - - m_rows.push_back( values ); + tableRows.push_back( values ); } } + } diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index 092bf8a1882..af54d458709 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -36,6 +36,10 @@ class TableData template< typename ... Args > void addRow( Args const & ... args ); + std::vector< std::vector< string > > & getTableDataRows(); + +private: + std::vector< std::vector< string > > m_rows; }; @@ -48,18 +52,16 @@ class TableData2D : public TableData * @brief Add a cell to the table. * Construct a map of pair and cell value * @param T The value passed to addCell (can be any type). - * @param x The row index - * @param u The column index * @param value Cell value to be added. */ template< typename T > void addCell( real64 x, real64 y, T value ); - // void printCount(); /** * @brief Construct all rows from all cell values stored in map previously + * @param tableRows Rows to be built */ - void buildRows(); + void buildRows( std::vector< std::vector< string > > & tableRows ); private: std::map< std::pair< real64, real64 >, string > data; @@ -84,13 +86,12 @@ void TableData::addRow( Args const &... args ) } template< typename T > -void TableData2D::addCell( real64 x, real64 y, T value ) +void TableData2D::addCell( real64 rowValue, real64 columnValue, T value ) { - std::pair< real64, real64 > id = std::pair< real64, real64 >( x, y ); - + std::pair< real64, real64 > id = std::pair< real64, real64 >( rowValue, columnValue ); data[id] = GEOS_FMT( "{}", value ); - columns.insert( x ); - row.insert( y ); + columns.insert( columnValue ); + row.insert( rowValue ); } } diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index e8c78049cc9..6a65cfe511e 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -46,49 +46,64 @@ TableCSVFormatter::TableCSVFormatter( TableLayout tableLayout ) m_tableLayout = tableLayout; } -string TableCSVFormatter::headerToString( std::vector< TableLayout::Column > & columns ) +string TableCSVFormatter::headerToString() { string headerValues = ""; + string separator = ","; - for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) + for( std::size_t idxColumn = 0; idxColumn < m_tableLayout.m_columns.size(); ++idxColumn ) { - headerValues += columns[idxColumn].parameter.columnName; + headerValues += m_tableLayout.m_columns[idxColumn].parameter.columnName; + if( idxColumn < m_tableLayout.m_columns.size() - 1 ) + { + headerValues += separator; + } } - + headerValues += "\n"; return headerValues; } -string TableCSVFormatter::dataToString( TableData2D tableData ) +string TableCSVFormatter::dataToString( TableData2D & tableData ) { - std::vector< std::vector< string > > rowsValues = tableData.m_rows; + string data; - tableData.buildRows(); + std::vector< std::vector< string > > rowsValues = tableData.getTableDataRows(); - for( std::vector< string > row : rowsValues ) + tableData.buildRows( rowsValues ); + + for( std::vector< string > const & row : rowsValues ) { - for( string value : row ) + for( size_t idxRow = 0; idxRow < row.size(); idxRow++ ) { - data += value + ","; + data += row[idxRow]; + if( idxRow < row.size() - 1 ) + { + data += ","; + } } data += "\n"; } return data; } -string TableCSVFormatter::dataToString( TableData tableData ) +string TableCSVFormatter::dataToString( TableData & tableData ) { - std::vector< std::vector< string > > rowsValues = tableData.m_rows; + std::vector< std::vector< string > > rowsValues = tableData.getTableDataRows(); std::vector< TableLayout::Column > columns = m_tableLayout.m_columns; string data; fillTableColumnsFromRows( columns, rowsValues ); - for( std::vector< string > row : rowsValues ) + for( std::vector< string > const & row : rowsValues ) { - for( string value : row ) + for( size_t idxRow = 0; idxRow < row.size(); idxRow++ ) { - data += value + ","; + data += row[idxRow]; + if( idxRow < row.size() - 1 ) + { + data += ","; + } } data += "\n"; } @@ -124,13 +139,45 @@ TableTextFormatter::TableTextFormatter( TableLayout tableLayout ): string TableTextFormatter::ToString( TableData & tableData ) { - return constructTable( tableData.m_rows ); + return constructAndReturnTable( tableData.getTableDataRows() ); } string TableTextFormatter::ToString( TableData2D & tableData ) { - tableData.buildRows(); - return constructTable( tableData.m_rows ); + std::vector< std::vector< string > > tableRows = tableData.getTableDataRows(); + tableData.buildRows( tableRows ); + return constructAndReturnTable( tableRows ); +} + +string TableTextFormatter::layoutToString() +{ + string titleRows; + string topSeparator; + string sectionSeparator; + + size_t largestHeaderVectorSize = 0; + std::vector< std::vector< string > > splitHeader; + std::vector< TableLayout::Column > columns = m_tableLayout.m_columns; + + string tableTitle = string( m_tableLayout.getTitle()); + + parseAndStoreHeaderSections( columns, largestHeaderVectorSize, splitHeader ); + adjustHeaderSizesAndStore( columns, largestHeaderVectorSize, splitHeader ); + + findAndSetMaxStringSize( columns, 0 ); + computeAndBuildSeparator( columns, topSeparator, sectionSeparator ); + + if( !tableTitle.empty()) + { + buildTitleRow( titleRows, topSeparator, sectionSeparator ); + } + + string tableRows = GEOS_FMT( "{}\n", sectionSeparator ); + buildSectionRows( columns, sectionSeparator, tableRows, largestHeaderVectorSize, TableLayout::Section::header ); + + string tableOutput = titleRows + tableRows + '\n'; + + return tableOutput; } void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout::Column > & columns, @@ -140,7 +187,6 @@ void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout:: for( size_t columnParamIdx = 0; columnParamIdx< columns.size(); columnParamIdx++ ) { std::vector< string > splitHeaderParts; - //at this part column name isn't split std::istringstream ss( columns[columnParamIdx].parameter.columnName ); string subColumnNames; @@ -346,7 +392,7 @@ void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > & } } -string TableTextFormatter::constructTable( std::vector< std::vector< string > > & rowsValues ) +string TableTextFormatter::constructAndReturnTable( std::vector< std::vector< string > > & rowsValues ) { string titleRows; string topSeparator; diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index e6b8774f322..3aff4e07c37 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -68,20 +68,18 @@ class TableCSVFormatter : public TableFormatter * @param tableData A 2-dimensions tabke * @return A string of CSV data from a 2-dimensions table */ - string dataToString( TableData2D tableData ); + string dataToString( TableData2D & tableData ); /** * @param tableData A 2-dimensions tabke * @return A string of CSV data from a 1-dimensions table */ - string dataToString( TableData tableData ); + string dataToString( TableData & tableData ); /** - * @param columns - * @param nbRows * @return A string with all column names */ - string headerToString( std::vector< TableLayout::Column > & columns ); + string headerToString(); }; @@ -93,15 +91,20 @@ class TableTextFormatter : public TableFormatter TableTextFormatter( TableLayout tableLayout ); /** - * @brief return a string following the formatter + * @brief return a table string from a TableData */ string ToString( TableData & tableData ); /** - * @brief return a string following the formatter + * @brief return a table string from a TableData2D */ string ToString( TableData2D & tableData ); + /** + * @return return a table string from a TableLayout + */ + string layoutToString(); + private: /** @@ -112,15 +115,6 @@ class TableTextFormatter : public TableFormatter void parseAndStoreHeaderSections( std::vector< TableLayout::Column > & columns, size_t & largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ); - - string constructTable( std::vector< std::vector< string > > & rowsValues ); - /** - * @brief Iterate throught the header names vector. - * Adjust the size of each header vector by adding empty strings if needed. - * Store the modified header names in the corresponding column parameter. - * @param largestHeaderVectorSize The largest split header vector size - * @param splitHeader A vector containing all split header names - */ void adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, size_t largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ); @@ -170,6 +164,13 @@ class TableTextFormatter : public TableFormatter integer const nbRows, TableLayout::Section const section ); + /** + * @brief Construct a table from a tableData + * @param rowsValues All values sorted by rows + * @return A table string + */ + string constructAndReturnTable( std::vector< std::vector< string > > & rowsValues ); + }; } From 37e18b419db5dc48aaa6ebe2d2c1bfeb707fbbdf Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 12 Mar 2024 17:24:10 +0100 Subject: [PATCH 035/216] Delete table..cpp/hpp --- src/coreComponents/codingUtilities/Table.cpp | 345 ------------------ src/coreComponents/codingUtilities/Table.hpp | 224 ------------ .../codingUtilities/TableData.cpp | 8 +- .../codingUtilities/TableData.hpp | 4 +- 4 files changed, 6 insertions(+), 575 deletions(-) delete mode 100644 src/coreComponents/codingUtilities/Table.cpp delete mode 100644 src/coreComponents/codingUtilities/Table.hpp diff --git a/src/coreComponents/codingUtilities/Table.cpp b/src/coreComponents/codingUtilities/Table.cpp deleted file mode 100644 index e1961656139..00000000000 --- a/src/coreComponents/codingUtilities/Table.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2018-2020 TotalEnergies - * Copyright (c) 2019- GEOSX Contributors - * All rights reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - -/** - * @file Table.cpp - */ - -#include "Table.hpp" - -namespace geos -{ - -/** - * @brief Build a value cell given an alignment and spaces from "|" - * - * @param alignment - * @param value - * @param spaces - * @return A cell value - */ -string buildValueCell( Table::Alignment const alignment, string_view value, integer const spaces ) -{ - switch( alignment ) - { - case Table::right: return GEOS_FMT( "{:>{}}", value, spaces ); - case Table::left: return GEOS_FMT( "{:<{}}", value, spaces ); - case Table::middle: return GEOS_FMT( "{:^{}}", value, spaces ); - default: return GEOS_FMT( "{:<{}}", value, spaces ); - } -} - -Table::Table( std::vector< string > const & headers ) -{ - setMargin( MarginValue::medium ); - - for( size_t idx = 0; idx< headers.size(); idx++ ) - { - m_columns.push_back( {Table::ColumnParam{{headers[idx]}, Alignment::middle, true}, {}, ""} ); - } -} - -Table::Table( std::vector< ColumnParam > const & columnParameter ) -{ - setMargin( MarginValue::medium ); - - for( size_t idx = 0; idx< columnParameter.size(); idx++ ) - { - if( columnParameter[idx].enabled ) - { - m_columns.push_back( {columnParameter[idx], {}, ""} ); - } - - } -} - -void Table::addRowsFromVectors( std::vector< std::vector< string > > const & tableRows ) -{ - for( size_t indexRow = 0; indexRow < tableRows.size(); indexRow++ ) - { - std::vector< string > rowsValues; - for( size_t indexValue = 0; indexValue < tableRows[indexRow].size(); indexValue++ ) - { - string cellValue = GEOS_FMT( "{}", tableRows[indexRow][indexValue] ); - if( m_columns[indexValue].parameter.enabled ) - { - rowsValues.push_back( cellValue ); - } - } - m_cellsRows.push_back( rowsValues ); - } -} - -void Table::parseAndStoreHeaderSections( size_t & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ) -{ - for( size_t columnParamIdx = 0; columnParamIdx< m_columns.size(); columnParamIdx++ ) - { - std::vector< string > splitHeaderParts; - std::istringstream ss( m_columns[columnParamIdx].parameter.headerName[0] ); - string subHeaderName; - - while( getline( ss, subHeaderName, '\n' )) - { - splitHeaderParts.push_back( subHeaderName ); - } - - size_t const cellSize = splitHeaderParts.size(); - largestHeaderVectorSize = std::max( largestHeaderVectorSize, cellSize ); - - splitHeader.push_back( splitHeaderParts ); - } -} - -void Table::adjustHeaderSizesAndStore( size_t largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ) -{ - for( size_t columnParamIdx = 0; columnParamIdx < m_columns.size(); columnParamIdx++ ) - { - if( splitHeader[columnParamIdx].size() < largestHeaderVectorSize ) - { - integer const whiteRowToAdd = largestHeaderVectorSize - splitHeader[columnParamIdx].size(); - splitHeader[columnParamIdx].insert( splitHeader[columnParamIdx].end(), whiteRowToAdd, " " ); - } - m_columns[columnParamIdx].parameter.headerName = splitHeader[columnParamIdx]; - } -} - -void Table::setTitle( string_view title_ ) -{ - tableTitle = title_; -} - -string_view Table::getTitle() -{ - return tableTitle; -} - -void Table::setMargin( MarginValue marginType ) -{ - borderMargin = marginType; - columnMargin = integer( marginType ) * 2 + 1; -} - -void Table::findAndSetMaxStringSize() -{ - string maxStringSize = ""; - for( size_t idxColumn = 0; idxColumn < m_columns.size(); idxColumn++ ) - { - auto it = std::max_element( m_columns[idxColumn].parameter.headerName.begin(), - m_columns[idxColumn].parameter.headerName.end(), - []( const auto & a, const auto & b ) { - return a.size() < b.size(); - } ); - - maxStringSize = *it; - - for( size_t idxRow = 0; idxRow < m_cellsRows.size(); idxRow++ ) - { - string cell = m_columns[idxColumn].columnValues[idxRow]; - if( maxStringSize.length() < cell.length()) - { - maxStringSize = cell; - } - } - m_columns[idxColumn].m_maxStringSize = maxStringSize; - } -} - -void Table::computeAndSetMaxStringSize( string::size_type sectionlineLength, - string::size_type titleLineLength ) -{ - integer extraLinesPerColumn; - integer extraLines; - integer newStringSize; - - extraLines = titleLineLength - sectionlineLength; - extraLinesPerColumn = std::ceil( extraLines / m_columns.size() ); - - for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) - { - newStringSize = extraLinesPerColumn + m_columns[idxColumn].m_maxStringSize.size(); - if( idxColumn == m_columns.size() - 1 || m_columns.size() == 1 ) - { - m_columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", - m_columns[idxColumn].m_maxStringSize, - newStringSize + columnMargin ); - } - else - { - m_columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", - m_columns[idxColumn].m_maxStringSize, - newStringSize ); - } - } -} - -void Table::computeAndBuildSeparator( string & topSeparator, string & sectionSeparator ) -{ - string::size_type sectionlineLength = 0; - string::size_type titleLineLength = tableTitle.length() + ( marginTitle * 2 ); - integer nbSpaceBetweenColumn = ( ( m_columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); - if( !tableTitle.empty()) - { - tableTitle = GEOS_FMT( "{:^{}}", tableTitle, titleLineLength ); - } - - for( std::size_t i = 0; i < m_columns.size(); ++i ) - { - sectionlineLength += m_columns[i].m_maxStringSize.length(); - } - - sectionlineLength += nbSpaceBetweenColumn; - if( sectionlineLength < titleLineLength ) - { - computeAndSetMaxStringSize( sectionlineLength, titleLineLength ); - } - if( m_columns.size() == 1 ) - { - sectionSeparator += GEOS_FMT( "+{:-<{}}+", - "", - ( m_columns[0].m_maxStringSize.length() + (borderMargin - 1) + columnMargin )); - } - else - { - for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) - { - integer const cellSize = m_columns[idxColumn].m_maxStringSize.length(); - if( idxColumn == 0 ) - { - sectionSeparator += GEOS_FMT( "+{:-<{}}", "", ( cellSize + borderMargin )); - } - else if( idxColumn == (m_columns.size() - 1)) - { - sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); - sectionSeparator += GEOS_FMT( "{:->{}}", "+", ( cellSize + borderMargin + 1 ) ); - } - else - { - sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); - sectionSeparator += GEOS_FMT( "{:->{}}", "", cellSize ); - } - } - } - topSeparator = GEOS_FMT( "+{:-<{}}+", "", sectionSeparator.size() - 2 );// -2 for ++ -} - -void Table::buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ) -{ - titleRows = GEOS_FMT( "\n{}\n|", topSeparator ); - titleRows += buildValueCell( Alignment::middle, - tableTitle, - (sectionSeparator.length() - 2) // -2 for || - ); - titleRows += GEOS_FMT( "{}\n", "|" ); -} - -void Table::buildSectionRows( string_view sectionSeparator, - string & rows, - integer const nbRows, - Section const section ) -{ - for( integer idxRow = 0; idxRow< nbRows; idxRow++ ) - { - rows += GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); - for( std::size_t idxColumn = 0; idxColumn < m_columns.size(); ++idxColumn ) - { - string cell; - - if( section == Section::header ) - { - cell = m_columns[idxColumn].parameter.headerName[idxRow]; - } - else - { - cell = m_columns[idxColumn].columnValues[idxRow]; - } - integer const cellSize = m_columns[idxColumn].m_maxStringSize.length(); - rows += buildValueCell( m_columns[idxColumn].parameter.alignment, - cell, - cellSize ); - - if( idxColumn < m_columns.size() - 1 ) - { - rows += GEOS_FMT( "{:^{}}", "|", columnMargin ); - } - - } - if( m_columns.size() == 1 ) - { - rows += GEOS_FMT( "{:>{}}\n", "|", columnMargin ); - } - else - { - rows += GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); - } - - } - if( nbRows != 0 ) - { - rows += GEOS_FMT( "{}\n", sectionSeparator ); - } -} - -void Table::fillColumnsValuesFromCellsRows() -{ - for( size_t idxRow = 0; idxRow < m_cellsRows.size(); idxRow++ ) - { - for( size_t idxColumn = 0; idxColumn < m_columns.size(); idxColumn++ ) - { - m_columns[idxColumn].columnValues.push_back( m_cellsRows[idxRow][idxColumn] ); - } - } -} - -void Table::drawToStream( std::ostream & oss ) -{ - string rows; - string titleRows; - string topSeparator; - string sectionSeparator; - - std::vector< std::vector< string > > splitHeader; - size_t largestHeaderVectorSize = 0; - - fillColumnsValuesFromCellsRows(); - - parseAndStoreHeaderSections( largestHeaderVectorSize, splitHeader ); - adjustHeaderSizesAndStore( largestHeaderVectorSize, splitHeader ); - - findAndSetMaxStringSize(); - computeAndBuildSeparator( topSeparator, sectionSeparator ); - - if( !tableTitle.empty()) - { - buildTitleRow( titleRows, topSeparator, sectionSeparator ); - } - - rows += GEOS_FMT( "{}\n", sectionSeparator ); - buildSectionRows( sectionSeparator, rows, largestHeaderVectorSize, Section::header ); - buildSectionRows( sectionSeparator, rows, m_cellsRows.size(), Section::values ); - - string const tableOutput = titleRows + rows + '\n'; - - oss << tableOutput; -} - -string Table::drawToString() -{ - std::ostringstream oss; - drawToStream( oss ); - return oss.str(); -} - -} diff --git a/src/coreComponents/codingUtilities/Table.hpp b/src/coreComponents/codingUtilities/Table.hpp deleted file mode 100644 index e4099fb5c7c..00000000000 --- a/src/coreComponents/codingUtilities/Table.hpp +++ /dev/null @@ -1,224 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2018-2020 TotalEnergies - * Copyright (c) 2019- GEOSX Contributors - * All rights reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - -/** - * @file Table.hpp - */ - -#ifndef GEOS_COMMON_TABLE_HPP -#define GEOS_COMMON_TABLE_HPP - -#include "common/DataTypes.hpp" - -namespace geos -{ - -class Table -{ -public: - - enum Alignment { right, left, middle }; - - enum MarginValue : integer - { - tiny = 0, - small = 1, - medium = 2, - large = 3 - }; - - /** - * @brief Structure to set up each colum parameters. - */ - struct ColumnParam - { - // A vector containing all string for a header name - std::vector< string > headerName; - // Alignment for a column. By default aligned to the right side - Alignment alignment = Alignment::right; - // A boolean to display a colummn - bool enabled = true; - }; - - /** - * @brief Construct a new Table object, all values in the table are centered by default - * @param columnNames - */ - Table( std::vector< string > const & columnNames ); - - /** - * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels - * level - * @param columnParameter List of structures to set up each colum parameters. - */ - Table( std::vector< ColumnParam > const & columnParameter ); - - /** - * @brief Add a row the the table. - * - * @param Args The values passed to addRow (can be any type). - * @param args Cell values to be added to the line. - * - */ - template< typename ... Args > - void addRow( Args const & ... args ); - - /** - * @brief Add rows from vectors to the table. - * @param vecRows Vector who contains all the table rows - */ - void addRowsFromVectors( std::vector< std::vector< string > > const & tableRows ); - - /** - * @brief Write the table into a string - * @return A string table - */ - string drawToString(); - - /** - * @brief Write the table into a specified stream - * @param os An output stream (by default, std::cout) - */ - void drawToStream( std::ostream & os = std::cout ); - - /** - * @brief Set the table name - * @param tableTitle The table name - */ - void setTitle( string_view tableTitle ); - - /** - * @brief Set the minimal margin width between row content and borders. - * @param marginType - */ - void setMargin( MarginValue marginType ); - - /** - * @return return the table name - */ - string_view getTitle(); - -private: - - enum Section { header, values }; - - /** - * @brief Struct for a column. - */ - struct Column - { - ColumnParam parameter; - // A vector containing all column values - std::vector< string > columnValues; - // The largest string in the column - string m_maxStringSize; - }; - - /** - * @brief Fill the vector (m_column) with values from m_cellsRows who store all values in an unsorted order - */ - void fillColumnsValuesFromCellsRows(); - - /** - * @brief Split all header names by detecting the newline \\n character. - * @param splitHeader A empty vector who will contain all split header names - * @param largestHeaderVectorSize The largest split header vector size - */ - void parseAndStoreHeaderSections( size_t & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ); - - /** - * @brief Iterate throught the header names vector. - * Adjust the size of each header vector by adding empty strings if needed. - * Store the modified header names in the corresponding column parameter. - * @param largestHeaderVectorSize The largest split header vector size - * @param splitHeader A vector containing all split header names - */ - void adjustHeaderSizesAndStore( size_t largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ); - - /** - * @brief For each column find and set the column's longest string - */ - void findAndSetMaxStringSize(); - - /** - * @brief Compute the largest string size in the table. If the table title is the largest string size in the table, recalculate for all - * columns the \p m_maxStringSize value by adding extra characters - * @param sectionlineLength The length of a section line - * @param titleLineLength The length of a title line - */ - void computeAndSetMaxStringSize( string::size_type sectionlineLength, - string::size_type titleLineLength ); - - /** - * @brief Compute and build the top and the section line separator - * @param topSeparator An empty string to be built - * @param sectionSeparator An empty string to be built - */ - void computeAndBuildSeparator( string & topSeparator, string & sectionSeparator ); - - /** - * @brief Build the table title section - * @param titleRows Rows containing the title section. - * @param topSeparator The top line separator - * @param sectionSeparator The section line separator - */ - void buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ); - - /** - * @brief Build a section by specifying it's type ( header or section ) - * @param sectionSeparator Line separator between sections - * @param rows A section row - * @param nbRows Indicates the number of lines in a section - * @param section The section to be built - */ - void buildSectionRows( string_view sectionSeparator, - string & rows, - integer const nbRows, - Section const section ); - - - //Vector who contains all rows in the table - std::vector< std::vector< string > > m_cellsRows; - std::vector< Column > m_columns; - - integer borderMargin; - integer columnMargin; - - string tableTitle; - - int marginTitle = 2; - -}; - -template< typename ... Args > -void Table::addRow( Args const &... args ) -{ - std::vector< string > rowsValues; - int idx = 0; - ( [&] { - string cellValue = GEOS_FMT( "{}", args ); - if( m_columns[idx].parameter.enabled ) - { - rowsValues.push_back( cellValue ); - } - } (), ...); - - m_cellsRows.push_back( rowsValues ); -} - -} - -#endif diff --git a/src/coreComponents/codingUtilities/TableData.cpp b/src/coreComponents/codingUtilities/TableData.cpp index 5052708c3a1..aa82a89133b 100644 --- a/src/coreComponents/codingUtilities/TableData.cpp +++ b/src/coreComponents/codingUtilities/TableData.cpp @@ -28,13 +28,13 @@ std::vector< std::vector< string > > & TableData::getTableDataRows() void TableData2D::buildRows( std::vector< std::vector< string > > & tableRows ) { - for( real64 const & y : row ) + for( real64 const & rowValue : rows ) { std::vector< string > values; - values.push_back( GEOS_FMT( "{}", y ) ); - for( real64 const & x : columns ) + values.push_back( GEOS_FMT( "{}", rowValue ) ); + for( real64 const & columnValue : columns ) { - std::pair< real64, real64 > id = std::pair< real64, real64 >( y, x ); + std::pair< real64, real64 > id = std::pair< real64, real64 >( rowValue, columnValue ); auto const dataIt = data.find( id ); if( dataIt != data.end()) diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index af54d458709..3c7534fa416 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -66,7 +66,7 @@ class TableData2D : public TableData private: std::map< std::pair< real64, real64 >, string > data; std::set< real64 > columns; - std::set< real64 > row; + std::set< real64 > rows; }; template< typename ... Args > @@ -91,7 +91,7 @@ void TableData2D::addCell( real64 rowValue, real64 columnValue, T value ) std::pair< real64, real64 > id = std::pair< real64, real64 >( rowValue, columnValue ); data[id] = GEOS_FMT( "{}", value ); columns.insert( columnValue ); - row.insert( rowValue ); + rows.insert( rowValue ); } } From 5ff7c68e72c26a95180d59cf6b60a23f2ee1f3b6 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 12 Mar 2024 17:32:06 +0100 Subject: [PATCH 036/216] small correction --- src/coreComponents/codingUtilities/TableFormatter.cpp | 6 +++--- src/coreComponents/codingUtilities/TableFormatter.hpp | 6 +++--- src/coreComponents/codingUtilities/TableLayout.hpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index 6a65cfe511e..26c54540334 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -20,7 +20,7 @@ namespace geos { -TableFormatter::TableFormatter( TableLayout tableLayout ) +TableFormatter::TableFormatter( TableLayout & tableLayout ) { m_tableLayout = tableLayout; } @@ -41,7 +41,7 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column ////// CSV Formatter implementation /////////////////////////////////////////////////////////////////////// -TableCSVFormatter::TableCSVFormatter( TableLayout tableLayout ) +TableCSVFormatter::TableCSVFormatter( TableLayout & tableLayout ) { m_tableLayout = tableLayout; } @@ -133,7 +133,7 @@ string buildValueCell( TableLayout::Alignment const alignment, string_view value } } -TableTextFormatter::TableTextFormatter( TableLayout tableLayout ): +TableTextFormatter::TableTextFormatter( TableLayout & tableLayout ): TableFormatter( tableLayout ) {} diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index 3aff4e07c37..c346b51f81d 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -38,7 +38,7 @@ class TableFormatter * @brief Construct a new Table Formatter from a tableLayout * @param tableLayout Contain all column names and optionnaly the table title */ - TableFormatter( TableLayout tableLayout ); + TableFormatter( TableLayout & tableLayout ); TableLayout m_tableLayout; @@ -62,7 +62,7 @@ class TableCSVFormatter : public TableFormatter * @brief Construct a new Table Formatter from a tableLayout * @param tableLayout Contain all column names and optionnaly the table title */ - TableCSVFormatter( TableLayout tableLayout ); + TableCSVFormatter( TableLayout & tableLayout ); /** * @param tableData A 2-dimensions tabke @@ -88,7 +88,7 @@ class TableTextFormatter : public TableFormatter public: - TableTextFormatter( TableLayout tableLayout ); + TableTextFormatter( TableLayout & tableLayout ); /** * @brief return a table string from a TableData diff --git a/src/coreComponents/codingUtilities/TableLayout.hpp b/src/coreComponents/codingUtilities/TableLayout.hpp index ddff87ccacb..39cc67fa98a 100644 --- a/src/coreComponents/codingUtilities/TableLayout.hpp +++ b/src/coreComponents/codingUtilities/TableLayout.hpp @@ -54,11 +54,11 @@ class TableLayout // Vector containing substring column name delimited by "\n" std::vector< string > splitColumnName; - ColumnParam( const std::string & name, Alignment align ) + ColumnParam( std::string const & name, Alignment align ) : columnName( name ), alignment( align ) {} - ColumnParam( const std::string & name, Alignment align, bool display ) + ColumnParam( std::string const & name, Alignment align, bool display ) : columnName( name ), alignment( align ), enabled( display ) {} }; From b360a1693201f9973cfc9753e77b5fb53738c84b Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 13 Mar 2024 09:37:16 +0100 Subject: [PATCH 037/216] doc updated --- .../codingUtilities/TableData.hpp | 7 ++++- .../codingUtilities/TableFormatter.hpp | 28 +++++++++++++------ .../codingUtilities/TableLayout.hpp | 18 ++++++++++-- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index 3c7534fa416..516ed6e6977 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -24,6 +24,7 @@ namespace geos { +// Class for managing table data class TableData { public: @@ -31,11 +32,14 @@ class TableData /** * @brief Add a row to the table. * @param Args The values passed to addRow (can be any type). - * @param args Cell values to be added to the line. + * @param args Cell values to be added to the row. */ template< typename ... Args > void addRow( Args const & ... args ); + /** + * @return The rows of the table + */ std::vector< std::vector< string > > & getTableDataRows(); private: @@ -44,6 +48,7 @@ class TableData }; +// Class for managing 2D table data class TableData2D : public TableData { public: diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index c346b51f81d..0fc22180f17 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -25,6 +25,7 @@ namespace geos { +// Class for formatting table data class TableFormatter { public: @@ -43,7 +44,9 @@ class TableFormatter TableLayout m_tableLayout; /** - * @brief Fill the vector (m_column) in tableData with values from m_rows in tableLayout who store all values in an unsorted order + * @brief Fill the vector (m_column) in tableData with values from m_rows in tableLayout, storing all values in an unsorted order. + * @param columns Vector of columns to be filled. + * @param tableData Vector of table data. */ void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & tableData ); @@ -65,19 +68,21 @@ class TableCSVFormatter : public TableFormatter TableCSVFormatter( TableLayout & tableLayout ); /** - * @param tableData A 2-dimensions tabke - * @return A string of CSV data from a 2-dimensions table + * @brief Convert the table data to a CSV string. + * @param tableData The 2D table data. + * @return The CSV string representation of the table data. */ string dataToString( TableData2D & tableData ); /** - * @param tableData A 2-dimensions tabke - * @return A string of CSV data from a 1-dimensions table + * @brief Convert the table data to a CSV string. + * @param tableData The 1D table data. + * @return The CSV string representation of the table data. */ string dataToString( TableData & tableData ); /** - * @return A string with all column names + * @return The string with all column names. */ string headerToString(); @@ -91,17 +96,22 @@ class TableTextFormatter : public TableFormatter TableTextFormatter( TableLayout & tableLayout ); /** - * @brief return a table string from a TableData + * @brief Convert the TableData to a table string. + * @param tableData The TableData to convert. + * @return The table string representation of the TableData. */ string ToString( TableData & tableData ); /** - * @brief return a table string from a TableData2D + * @brief Convert the TableData2D to a table string. + * @param tableData The TableData2D to convert. + * @return The table string representation of the TableData2D. */ string ToString( TableData2D & tableData ); /** - * @return return a table string from a TableLayout + * @brief Get a table string from the TableLayout. + * @return The table string representation of the TableLayout. */ string layoutToString(); diff --git a/src/coreComponents/codingUtilities/TableLayout.hpp b/src/coreComponents/codingUtilities/TableLayout.hpp index 39cc67fa98a..51f6aad19e2 100644 --- a/src/coreComponents/codingUtilities/TableLayout.hpp +++ b/src/coreComponents/codingUtilities/TableLayout.hpp @@ -38,6 +38,9 @@ class TableLayout large = 3 }; + /** + * @brief Enumeration for table sections. + */ enum Section { header, values }; /** @@ -54,10 +57,21 @@ class TableLayout // Vector containing substring column name delimited by "\n" std::vector< string > splitColumnName; + /** + * @brief Construct a ColumnParam object with the specified name and alignment. + * @param name The name of the column + * @param align The alignment of the column + */ ColumnParam( std::string const & name, Alignment align ) : columnName( name ), alignment( align ) {} + /** + * @brief Construct a ColumnParam object with the specified name, alignment, and display flag. + * @param name The name of the column + * @param align The alignment of the column + * @param display Flag indicating whether the column is enabled + */ ColumnParam( std::string const & name, Alignment align, bool display ) : columnName( name ), alignment( align ), enabled( display ) {} @@ -79,7 +93,7 @@ class TableLayout /** * @brief Construct a new Table object, all values in the table are centered by default - * @param columnNames + * @param columnNames The names of the columns */ TableLayout( std::vector< string > const & columnNames ); @@ -92,7 +106,7 @@ class TableLayout /** * @brief Set the minimal margin width between row content and borders. - * @param marginType + * @param marginType The margin value */ void setMargin( MarginValue marginType ); From dd5f42f427f7d90da43b0017bfda5b2b353e1272 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 13 Mar 2024 10:33:02 +0100 Subject: [PATCH 038/216] TableData2D small refacto + opti --- .../codingUtilities/TableData.cpp | 15 +++++++++-- .../codingUtilities/TableData.hpp | 15 +++++++---- .../codingUtilities/TableFormatter.cpp | 25 ++++++++----------- .../codingUtilities/TableFormatter.hpp | 13 +++------- 4 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.cpp b/src/coreComponents/codingUtilities/TableData.cpp index aa82a89133b..527cb45a812 100644 --- a/src/coreComponents/codingUtilities/TableData.cpp +++ b/src/coreComponents/codingUtilities/TableData.cpp @@ -26,8 +26,18 @@ std::vector< std::vector< string > > & TableData::getTableDataRows() return m_rows; } -void TableData2D::buildRows( std::vector< std::vector< string > > & tableRows ) + std::set< real64 > const & TableData2D::getColumns() const + { + return columns; + } + std::set< real64 > const & TableData2D::getRows() const + { + return rows; + } + +TableData TableData2D::buildTableData() const { + TableData tableDataToBeBuilt; for( real64 const & rowValue : rows ) { std::vector< string > values; @@ -42,8 +52,9 @@ void TableData2D::buildRows( std::vector< std::vector< string > > & tableRows ) values.push_back( GEOS_FMT( "{}", dataIt->second )); } } - tableRows.push_back( values ); + tableDataToBeBuilt.addRow( values ); } + return tableDataToBeBuilt; } } diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index 516ed6e6977..902ee33326d 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -37,7 +37,7 @@ class TableData template< typename ... Args > void addRow( Args const & ... args ); - /** + /** * @return The rows of the table */ std::vector< std::vector< string > > & getTableDataRows(); @@ -49,10 +49,12 @@ class TableData }; // Class for managing 2D table data -class TableData2D : public TableData +class TableData2D { public: + TableData tableData; + /** * @brief Add a cell to the table. * Construct a map of pair and cell value @@ -63,10 +65,13 @@ class TableData2D : public TableData void addCell( real64 x, real64 y, T value ); /** - * @brief Construct all rows from all cell values stored in map previously - * @param tableRows Rows to be built + * @brief Construct a TableData from a Table2D + * @return A TableData */ - void buildRows( std::vector< std::vector< string > > & tableRows ); + TableData buildTableData() const; + + std::set< real64 > const & getColumns() const; + std::set< real64 > const & getRows() const; private: std::map< std::pair< real64, real64 >, string > data; diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index 26c54540334..e7d2d112ec8 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -63,15 +63,17 @@ string TableCSVFormatter::headerToString() return headerValues; } -string TableCSVFormatter::dataToString( TableData2D & tableData ) +string TableCSVFormatter::dataToString( TableData2D & tableData2D ) { string data; + TableData tableData; + std::vector< std::vector< string > > rowsValues; - std::vector< std::vector< string > > rowsValues = tableData.getTableDataRows(); - - tableData.buildRows( rowsValues ); - + tableData = tableData2D.buildTableData(); + rowsValues = tableData.getTableDataRows(); + data.reserve(tableData2D.getColumns().size() * tableData2D.getRows().size()); + for( std::vector< string > const & row : rowsValues ) { for( size_t idxRow = 0; idxRow < row.size(); idxRow++ ) @@ -142,13 +144,6 @@ string TableTextFormatter::ToString( TableData & tableData ) return constructAndReturnTable( tableData.getTableDataRows() ); } -string TableTextFormatter::ToString( TableData2D & tableData ) -{ - std::vector< std::vector< string > > tableRows = tableData.getTableDataRows(); - tableData.buildRows( tableRows ); - return constructAndReturnTable( tableRows ); -} - string TableTextFormatter::layoutToString() { string titleRows; @@ -203,7 +198,7 @@ void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout:: } void TableTextFormatter::adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, - size_t largestHeaderVectorSize, + size_t const & largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ) { for( size_t columnParamIdx = 0; columnParamIdx < columns.size(); columnParamIdx++ ) @@ -218,7 +213,7 @@ void TableTextFormatter::adjustHeaderSizesAndStore( std::vector< TableLayout::Co } void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, - size_t nbRows ) + size_t const & nbRows ) { string maxStringSize = ""; for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) @@ -392,7 +387,7 @@ void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > & } } -string TableTextFormatter::constructAndReturnTable( std::vector< std::vector< string > > & rowsValues ) +string TableTextFormatter::constructAndReturnTable( std::vector< std::vector< string > > const & rowsValues ) { string titleRows; string topSeparator; diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index 0fc22180f17..c7768080ae2 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -102,13 +102,6 @@ class TableTextFormatter : public TableFormatter */ string ToString( TableData & tableData ); - /** - * @brief Convert the TableData2D to a table string. - * @param tableData The TableData2D to convert. - * @return The table string representation of the TableData2D. - */ - string ToString( TableData2D & tableData ); - /** * @brief Get a table string from the TableLayout. * @return The table string representation of the TableLayout. @@ -126,13 +119,13 @@ class TableTextFormatter : public TableFormatter size_t & largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ); void adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, - size_t largestHeaderVectorSize, + size_t const & largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ); /** * @brief For each column find and set the column's longest string */ - void findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, size_t nbRows ); + void findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, size_t const & nbRows ); /** * @brief Compute the largest string size in the table. If the table title is the largest string size in the table, recalculate for all @@ -179,7 +172,7 @@ class TableTextFormatter : public TableFormatter * @param rowsValues All values sorted by rows * @return A table string */ - string constructAndReturnTable( std::vector< std::vector< string > > & rowsValues ); + string constructAndReturnTable( std::vector< std::vector< string > > const & rowsValues ); }; } From 16b4ded19daf336047879845018802ef9e13823e Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 13 Mar 2024 10:35:00 +0100 Subject: [PATCH 039/216] first update for log in table function --- .../functions/TableFunction.cpp | 69 +++++++++++-------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index ae3abdd90a3..3423bc643e4 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -21,6 +21,10 @@ #include "common/DataTypes.hpp" #include "fileIO/Outputs/OutputBase.hpp" #include "codingUtilities/Table.hpp" +#include "codingUtilities/TableLayout.hpp" +#include "codingUtilities/TableData.hpp" +#include "codingUtilities/TableFormatter.hpp" + #include @@ -219,6 +223,7 @@ void TableFunction::printInCSV( string const & filename ) const r = r % div[d]; } // finally print out in right order + for( integer d = 0; d < numDimensions; d++ ) { arraySlice1d< real64 const > const coords = m_coordinates[d]; @@ -233,23 +238,29 @@ void TableFunction::printInCSV( string const & filename ) const arraySlice1d< real64 const > const coordsY = m_coordinates[1]; integer const nX = coordsX.size(); integer const nY = coordsY.size(); - os< columnNames; + + columnNames.push_back( string( units::getDescription( getDimUnit( 0 )))); + for( integer idxY = 0; idxY < nY; idxY++ ) { - os << "," << units::getDescription( getDimUnit( 1 )) << "=" << coordsY[j]; + string description = string( units::getDescription( getDimUnit( 1 ))) + "=" + std::to_string( coordsY[idxY] ); + columnNames.push_back( description ); } - os << "\n"; + TableLayout tableLayout( columnNames ); + + TableData2D tableData2D; for( integer i = 0; i < nX; i++ ) { - os << coordsX[i]; - for( integer j = 0; j < nY; j++ ) + for( integer y = 0; y < nY; y++ ) { - os << "," << m_values[ j*nX + i ]; + tableData2D.addCell( coordsX[i], y, m_values[ y*nX + i ] ); } - os << "\n"; } - } + TableCSVFormatter csvFormat( tableLayout ); + os << csvFormat.headerToString(); + os << csvFormat.dataToString( tableData2D ); + } os.close(); } @@ -257,7 +268,7 @@ void TableFunction::printInLog( string const & filename ) const { integer const numDimensions = LvArray::integerConversion< integer >( m_coordinates.size() ); - + std::cout << GEOS_FMT( "CSV Generated to inputFiles/compositionalMultiphaseWell/{}/{}.csv \n", OutputBase::getOutputDirectory(), filename ); @@ -265,20 +276,23 @@ void TableFunction::printInLog( string const & filename ) const if( numDimensions == 1 ) { - Table pvtTable1D = Table( - { + TableLayout tableLayout( { string( units::getDescription( getDimUnit( 0 ))), string( units::getDescription( m_valueUnit )) } ); - pvtTable1D.setTitle( filename ); + + tableLayout.setTitle( filename ); + + TableData tableData; arraySlice1d< real64 const > const coords = m_coordinates[0]; for( integer idx = 0; idx < m_values.size(); idx++ ) { - pvtTable1D.addRow< 2 >( coords[idx], m_values[idx] ); + tableData.addRow( coords[idx], m_values[idx] ); } - pvtTable1D.draw(); + TableTextFormatter logTable( tableLayout ); + GEOS_LOG_RANK_0( logTable.ToString( tableData )); } else if( numDimensions == 2 ) { @@ -298,36 +312,35 @@ void TableFunction::printInLog( string const & filename ) const vecDescription.push_back( description ); } - Table pvtTable2D = Table( vecDescription ); - pvtTable2D.setTitle( filename ); + TableLayout tableLayout( vecDescription ); + tableLayout.setTitle( filename ); + + TableData2D tableData2D; for( integer i = 0; i < nX; i++ ) { - std::vector< string > vValues; - vValues.push_back( std::to_string( coordsX[i] )); for( integer j = 0; j < nY; j++ ) { - vValues.push_back( std::to_string( m_values[ j*nX + i ] )); + tableData2D.addCell( coordsX[i], j, m_values[ j*nX + i ] ); } - vRowsValues.push_back( vValues ); nbRows++; } if( nbRows <= 500 ) { - pvtTable2D.addRowsFromVectors( vRowsValues ); - pvtTable2D.draw(); + TableTextFormatter table2DLog( tableLayout ); + GEOS_LOG_RANK_0( table2DLog.ToString( tableData2D )); } else { string log = GEOS_FMT( "The {} PVT table exceeding 500 rows.\nTo visualize the tables, go to the generated csv \n", filename ); - Table pvtTable2DLog = Table( {Table::ColumnParam{{log}, Table::Alignment::left}} ); - pvtTable2DLog.setTitle( filename ); - pvtTable2DLog.draw(); - } + TableLayout tableLayoutInfos( {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}} ); + tableLayoutInfos.setTitle( filename ); + TableTextFormatter tableLog( tableLayoutInfos ); + GEOS_LOG_RANK_0( tableLog.layoutToString() ); + } } - } TableFunction::KernelWrapper TableFunction::createKernelWrapper() const From 769beabf848da657dab918b71004460091d49b34 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 13 Mar 2024 11:02:47 +0100 Subject: [PATCH 040/216] uncrustify + small correction --- src/coreComponents/codingUtilities/TableData.cpp | 14 +++++++------- src/coreComponents/codingUtilities/TableData.hpp | 4 +--- .../codingUtilities/TableFormatter.cpp | 6 +++--- .../codingUtilities/TableFormatter.hpp | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.cpp b/src/coreComponents/codingUtilities/TableData.cpp index 527cb45a812..7f44f1324ae 100644 --- a/src/coreComponents/codingUtilities/TableData.cpp +++ b/src/coreComponents/codingUtilities/TableData.cpp @@ -26,14 +26,14 @@ std::vector< std::vector< string > > & TableData::getTableDataRows() return m_rows; } - std::set< real64 > const & TableData2D::getColumns() const - { +std::set< real64 > const & TableData2D::getColumns() const +{ return columns; - } - std::set< real64 > const & TableData2D::getRows() const - { - return rows; - } +} +std::set< real64 > const & TableData2D::getRows() const +{ + return rows; +} TableData TableData2D::buildTableData() const { diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index 902ee33326d..4e8598cb0ce 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -53,8 +53,6 @@ class TableData2D { public: - TableData tableData; - /** * @brief Add a cell to the table. * Construct a map of pair and cell value @@ -66,7 +64,7 @@ class TableData2D /** * @brief Construct a TableData from a Table2D - * @return A TableData + * @return A TableData */ TableData buildTableData() const; diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index e7d2d112ec8..9c492b5bedf 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -72,8 +72,8 @@ string TableCSVFormatter::dataToString( TableData2D & tableData2D ) tableData = tableData2D.buildTableData(); rowsValues = tableData.getTableDataRows(); - data.reserve(tableData2D.getColumns().size() * tableData2D.getRows().size()); - + data.reserve( tableData2D.getColumns().size() * tableData2D.getRows().size()); + for( std::vector< string > const & row : rowsValues ) { for( size_t idxRow = 0; idxRow < row.size(); idxRow++ ) @@ -139,7 +139,7 @@ TableTextFormatter::TableTextFormatter( TableLayout & tableLayout ): TableFormatter( tableLayout ) {} -string TableTextFormatter::ToString( TableData & tableData ) +string TableTextFormatter::ToString( TableData tableData ) { return constructAndReturnTable( tableData.getTableDataRows() ); } diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index c7768080ae2..b897c1e800c 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -100,7 +100,7 @@ class TableTextFormatter : public TableFormatter * @param tableData The TableData to convert. * @return The table string representation of the TableData. */ - string ToString( TableData & tableData ); + string ToString( TableData tableData ); /** * @brief Get a table string from the TableLayout. From 5fa478ca7cff25af137a02179b57194ed63b066d Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 13 Mar 2024 15:17:11 +0100 Subject: [PATCH 041/216] csv format / function correction --- .../codingUtilities/TableData.cpp | 6 +++++ .../codingUtilities/TableData.hpp | 6 ++++- .../codingUtilities/TableFormatter.cpp | 24 +++++++++---------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.cpp b/src/coreComponents/codingUtilities/TableData.cpp index 7f44f1324ae..3edf800a02a 100644 --- a/src/coreComponents/codingUtilities/TableData.cpp +++ b/src/coreComponents/codingUtilities/TableData.cpp @@ -21,6 +21,11 @@ namespace geos { +void TableData::addRow( std::vector< string > row ) +{ + m_rows.push_back( row ); +} + std::vector< std::vector< string > > & TableData::getTableDataRows() { return m_rows; @@ -51,6 +56,7 @@ TableData TableData2D::buildTableData() const { values.push_back( GEOS_FMT( "{}", dataIt->second )); } + } tableDataToBeBuilt.addRow( values ); } diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index 4e8598cb0ce..c92e282d668 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -37,6 +37,8 @@ class TableData template< typename ... Args > void addRow( Args const & ... args ); + void addRow( std::vector< string > row); + /** * @return The rows of the table */ @@ -53,6 +55,8 @@ class TableData2D { public: + TableData tableData; + /** * @brief Add a cell to the table. * Construct a map of pair and cell value @@ -64,7 +68,7 @@ class TableData2D /** * @brief Construct a TableData from a Table2D - * @return A TableData + * @return A TableData */ TableData buildTableData() const; diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index 9c492b5bedf..d1d27d9f357 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -65,27 +65,25 @@ string TableCSVFormatter::headerToString() string TableCSVFormatter::dataToString( TableData2D & tableData2D ) { - string data; - TableData tableData; - std::vector< std::vector< string > > rowsValues; + TableData tableData = tableData2D.buildTableData(); + std::vector< std::vector< string > > rowsValues = tableData.getTableDataRows(); - tableData = tableData2D.buildTableData(); - rowsValues = tableData.getTableDataRows(); data.reserve( tableData2D.getColumns().size() * tableData2D.getRows().size()); - for( std::vector< string > const & row : rowsValues ) + for( const auto & row : rowsValues ) { - for( size_t idxRow = 0; idxRow < row.size(); idxRow++ ) + for( size_t idxColumn = 0; idxColumn < row.size(); ++idxColumn ) { - data += row[idxRow]; - if( idxRow < row.size() - 1 ) + data += row[idxColumn]; + if( idxColumn < row.size() - 1 ) { data += ","; } } data += "\n"; } + return data; } @@ -97,12 +95,12 @@ string TableCSVFormatter::dataToString( TableData & tableData ) fillTableColumnsFromRows( columns, rowsValues ); - for( std::vector< string > const & row : rowsValues ) + for( const auto & row : rowsValues ) { - for( size_t idxRow = 0; idxRow < row.size(); idxRow++ ) + for( size_t idxColumn = 0; idxColumn < row.size(); ++idxColumn ) { - data += row[idxRow]; - if( idxRow < row.size() - 1 ) + data += row[idxColumn]; + if( idxColumn < row.size() - 1 ) { data += ","; } From 85494c712cd08e71ddbecc38630380eaeb53e728 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 13 Mar 2024 15:33:17 +0100 Subject: [PATCH 042/216] remove dataToString with 2D table parameter --- .../codingUtilities/TableFormatter.cpp | 26 +------------------ .../codingUtilities/TableFormatter.hpp | 9 +------ 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index d1d27d9f357..ffb543cc44c 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -63,31 +63,7 @@ string TableCSVFormatter::headerToString() return headerValues; } -string TableCSVFormatter::dataToString( TableData2D & tableData2D ) -{ - string data; - TableData tableData = tableData2D.buildTableData(); - std::vector< std::vector< string > > rowsValues = tableData.getTableDataRows(); - - data.reserve( tableData2D.getColumns().size() * tableData2D.getRows().size()); - - for( const auto & row : rowsValues ) - { - for( size_t idxColumn = 0; idxColumn < row.size(); ++idxColumn ) - { - data += row[idxColumn]; - if( idxColumn < row.size() - 1 ) - { - data += ","; - } - } - data += "\n"; - } - - return data; -} - -string TableCSVFormatter::dataToString( TableData & tableData ) +string TableCSVFormatter::dataToString( TableData tableData ) { std::vector< std::vector< string > > rowsValues = tableData.getTableDataRows(); std::vector< TableLayout::Column > columns = m_tableLayout.m_columns; diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index b897c1e800c..db2820e3afb 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -67,19 +67,12 @@ class TableCSVFormatter : public TableFormatter */ TableCSVFormatter( TableLayout & tableLayout ); - /** - * @brief Convert the table data to a CSV string. - * @param tableData The 2D table data. - * @return The CSV string representation of the table data. - */ - string dataToString( TableData2D & tableData ); - /** * @brief Convert the table data to a CSV string. * @param tableData The 1D table data. * @return The CSV string representation of the table data. */ - string dataToString( TableData & tableData ); + string dataToString( TableData tableData ); /** * @return The string with all column names. From 46e8d23c36e5d453aae328e204ba81c44f91d683 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 13 Mar 2024 16:28:52 +0100 Subject: [PATCH 043/216] code opti --- .../codingUtilities/TableData.hpp | 8 +------ .../codingUtilities/TableFormatter.cpp | 23 ++++++++++--------- .../codingUtilities/TableFormatter.hpp | 4 ++-- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index c92e282d668..a8b5b09a9f4 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -55,8 +55,6 @@ class TableData2D { public: - TableData tableData; - /** * @brief Add a cell to the table. * Construct a map of pair and cell value @@ -64,7 +62,7 @@ class TableData2D * @param value Cell value to be added. */ template< typename T > - void addCell( real64 x, real64 y, T value ); + void addCell( real64 rowValue, real64 columnValue, T value ); /** * @brief Construct a TableData from a Table2D @@ -84,14 +82,10 @@ class TableData2D template< typename ... Args > void TableData::addRow( Args const &... args ) { - //int idx = 0; std::vector< string > m_cellsValue; ( [&] { string cellValue = GEOS_FMT( "{}", args ); - // if( m_columns[idx].parameter.enabled ) - // { m_cellsValue.push_back( cellValue ); - // } } (), ...); m_rows.push_back( m_cellsValue ); diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index ffb543cc44c..4250145536c 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -46,7 +46,7 @@ TableCSVFormatter::TableCSVFormatter( TableLayout & tableLayout ) m_tableLayout = tableLayout; } -string TableCSVFormatter::headerToString() +string_view TableCSVFormatter::headerToString() { string headerValues = ""; string separator = ","; @@ -63,7 +63,7 @@ string TableCSVFormatter::headerToString() return headerValues; } -string TableCSVFormatter::dataToString( TableData tableData ) +string_view TableCSVFormatter::dataToString( TableData tableData ) { std::vector< std::vector< string > > rowsValues = tableData.getTableDataRows(); std::vector< TableLayout::Column > columns = m_tableLayout.m_columns; @@ -153,10 +153,10 @@ void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout:: size_t & largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ) { - for( size_t columnParamIdx = 0; columnParamIdx< columns.size(); columnParamIdx++ ) + for( auto const & column : columns ) { std::vector< string > splitHeaderParts; - std::istringstream ss( columns[columnParamIdx].parameter.columnName ); + std::istringstream ss( column.parameter.columnName ); string subColumnNames; while( getline( ss, subColumnNames, '\n' )) @@ -190,10 +190,10 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu size_t const & nbRows ) { string maxStringSize = ""; - for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) + for( auto & column : columns ) { - auto it = std::max_element( columns[idxColumn].parameter.splitColumnName.begin(), - columns[idxColumn].parameter.splitColumnName.end(), + auto it = std::max_element( column.parameter.splitColumnName.begin(), + column.parameter.splitColumnName.end(), []( const auto & a, const auto & b ) { return a.size() < b.size(); } ); @@ -201,7 +201,7 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu maxStringSize = *it; for( size_t idxRow = 0; idxRow < nbRows; idxRow++ ) { - string cell = columns[idxColumn].columnValues[idxRow]; + string cell = column.columnValues[idxRow]; if( maxStringSize.length() < cell.length()) { @@ -209,7 +209,7 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu } } - columns[idxColumn].m_maxStringSize = maxStringSize; + column.m_maxStringSize = maxStringSize; } } @@ -260,9 +260,9 @@ void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Col tableTitle = GEOS_FMT( "{:^{}}", tableTitle, titleLineLength ); } - for( std::size_t i = 0; i < columns.size(); ++i ) + for( auto const & column : columns ) { - sectionlineLength += columns[i].m_maxStringSize.length(); + sectionlineLength += column.m_maxStringSize.length(); } sectionlineLength += nbSpaceBetweenColumn; @@ -345,6 +345,7 @@ void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > & } } + if( columns.size() == 1 ) { tableRows += GEOS_FMT( "{:>{}}\n", "|", columnMargin ); diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index db2820e3afb..09e6d70c618 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -72,12 +72,12 @@ class TableCSVFormatter : public TableFormatter * @param tableData The 1D table data. * @return The CSV string representation of the table data. */ - string dataToString( TableData tableData ); + string_view dataToString( TableData tableData ); /** * @return The string with all column names. */ - string headerToString(); + string_view headerToString(); }; From c1ba824cc4210579a1f90c764c8fde65a86be39a Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 13 Mar 2024 16:42:44 +0100 Subject: [PATCH 044/216] add 2D table test --- .../codingUtilities/tests/testTable.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 9a3343772cc..70c05c6bf11 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -227,6 +227,32 @@ TEST( testTable, tableClass ) "+------------+------+-------------------+---------+-------+-------+\n\n" ); }; + + { + TableLayout tableLayout( {"FakePressure", "Value1", "Value2"} ); + TableData2D tableData; + + for( real64 p = 10000; p<20000; p+=5000 ) + { + for( real64 t = 400; t>=270; t+=-50.0 ) + { + real64 value = t/p; + tableData.addCell( t, p, value ); + } + } + + TableTextFormatter tableLog( tableLayout ); + EXPECT_EQ( tableLog.ToString( tableData.buildTableData()), + "+----------------+----------+------------------------+\n" + "| FakePressure | Value1 | Value2 |\n" + "+----------------+----------+------------------------+\n" + "| 300 | 0.03 | 0.02 |\n" + "| 350 | 0.035 | 0.023333333333333334 |\n" + "| 400 | 0.04 | 0.02666666666666667 |\n" + "+----------------+----------+------------------------+\n\n" + ); + + } } int main( int argc, char * * argv ) From 14ea4f5f6cdb168012630e8609b0a759dfcda0f6 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 13 Mar 2024 16:44:54 +0100 Subject: [PATCH 045/216] uncrustify --- src/coreComponents/codingUtilities/TableData.hpp | 4 ++-- src/coreComponents/codingUtilities/TableFormatter.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index a8b5b09a9f4..df15bf604a0 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -37,7 +37,7 @@ class TableData template< typename ... Args > void addRow( Args const & ... args ); - void addRow( std::vector< string > row); + void addRow( std::vector< string > row ); /** * @return The rows of the table @@ -66,7 +66,7 @@ class TableData2D /** * @brief Construct a TableData from a Table2D - * @return A TableData + * @return A TableData */ TableData buildTableData() const; diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index 4250145536c..d3df78ce48b 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -153,7 +153,7 @@ void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout:: size_t & largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ) { - for( auto const & column : columns ) + for( auto const & column : columns ) { std::vector< string > splitHeaderParts; std::istringstream ss( column.parameter.columnName ); @@ -345,7 +345,7 @@ void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > & } } - + if( columns.size() == 1 ) { tableRows += GEOS_FMT( "{:>{}}\n", "|", columnMargin ); From 1271875c93c6b5f7a8fcda45bafd47c7b70623b0 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 14 Mar 2024 15:24:14 +0100 Subject: [PATCH 046/216] Alignment::middle by center and compile time verifcation added --- .../codingUtilities/TableData.hpp | 4 +++- .../codingUtilities/TableFormatter.cpp | 4 ++-- .../codingUtilities/TableLayout.cpp | 2 +- .../codingUtilities/TableLayout.hpp | 2 +- .../codingUtilities/tests/testTable.cpp | 22 +++++++++---------- .../mesh/generators/WellGeneratorBase.cpp | 7 +++--- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index df15bf604a0..8051c889c4b 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -23,7 +23,8 @@ namespace geos { - +template< typename T > +constexpr bool is_string = std::is_same_v< T, std::string >; // Class for managing table data class TableData { @@ -85,6 +86,7 @@ void TableData::addRow( Args const &... args ) std::vector< string > m_cellsValue; ( [&] { string cellValue = GEOS_FMT( "{}", args ); + static_assert( is_string< decltype(cellValue) >, "An argunment passed in addRow cannot be converted to string" ); m_cellsValue.push_back( cellValue ); } (), ...); diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index d3df78ce48b..6a3cea6c132 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -104,7 +104,7 @@ string buildValueCell( TableLayout::Alignment const alignment, string_view value { case TableLayout::right: return GEOS_FMT( "{:>{}}", value, spaces ); case TableLayout::left: return GEOS_FMT( "{:<{}}", value, spaces ); - case TableLayout::middle: return GEOS_FMT( "{:^{}}", value, spaces ); + case TableLayout::center: return GEOS_FMT( "{:^{}}", value, spaces ); default: return GEOS_FMT( "{:<{}}", value, spaces ); } } @@ -303,7 +303,7 @@ void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Col void TableTextFormatter::buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ) { titleRows = GEOS_FMT( "\n{}\n|", topSeparator ); - titleRows += buildValueCell( TableLayout::Alignment::middle, + titleRows += buildValueCell( TableLayout::Alignment::center, m_tableLayout.getTitle(), (sectionSeparator.length() - 2) // -2 for || ); diff --git a/src/coreComponents/codingUtilities/TableLayout.cpp b/src/coreComponents/codingUtilities/TableLayout.cpp index aed9c7f876e..cff524cf316 100644 --- a/src/coreComponents/codingUtilities/TableLayout.cpp +++ b/src/coreComponents/codingUtilities/TableLayout.cpp @@ -26,7 +26,7 @@ TableLayout::TableLayout( std::vector< string > const & headers ) setMargin( MarginValue::medium ); for( size_t idx = 0; idx< headers.size(); idx++ ) { - m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::middle, true}, {}, ""} ); + m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::center, true}, {}, ""} ); } } diff --git a/src/coreComponents/codingUtilities/TableLayout.hpp b/src/coreComponents/codingUtilities/TableLayout.hpp index 51f6aad19e2..ba58a407058 100644 --- a/src/coreComponents/codingUtilities/TableLayout.hpp +++ b/src/coreComponents/codingUtilities/TableLayout.hpp @@ -28,7 +28,7 @@ class TableLayout { public: - enum Alignment { right, left, middle }; + enum Alignment { right, left, center }; enum MarginValue : integer { diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 70c05c6bf11..813fd87def6 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -90,7 +90,7 @@ TEST( testTable, tableClass ) { TableLayout tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::left}, TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::left}, TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, @@ -120,12 +120,12 @@ TEST( testTable, tableClass ) { TableLayout tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left, false}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::middle, false}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center, false}, } ); tableLayout.setTitle( "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); @@ -149,7 +149,7 @@ TEST( testTable, tableClass ) { TableLayout tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, } ); tableLayout.setTitle( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); @@ -173,12 +173,12 @@ TEST( testTable, tableClass ) { TableLayout tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, } ); @@ -200,12 +200,12 @@ TEST( testTable, tableClass ) { TableLayout tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::middle}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, } ); tableLayout.setTitle( "InternalWellGenerator well_injector1" ); tableLayout.setMargin( TableLayout::MarginValue::tiny ); diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 317c087193c..55b35c5a1e9 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -534,9 +534,9 @@ void WellGeneratorBase::debugWellGeometry() const //1. formatting data TableLayout tableWellLayout = TableLayout( { TableLayout::ColumnParam{"Element no.", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"CoordX", TableLayout::Alignment::middle}, - TableLayout::ColumnParam{"CoordY", TableLayout::Alignment::middle}, - TableLayout::ColumnParam{"CoordZ", TableLayout::Alignment::middle}, + TableLayout::ColumnParam{"CoordX", TableLayout::Alignment::center}, + TableLayout::ColumnParam{"CoordY", TableLayout::Alignment::center}, + TableLayout::ColumnParam{"CoordZ", TableLayout::Alignment::center}, TableLayout::ColumnParam{"Prev\nElement", TableLayout::Alignment::right}, TableLayout::ColumnParam{"Next\nElement", TableLayout::Alignment::right}, } ); @@ -563,6 +563,7 @@ void WellGeneratorBase::debugWellGeometry() const tableWellData.addRow( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, nextElement ); } + //3. dumping TableTextFormatter tableFormatter( tableWellLayout ); GEOS_LOG_RANK_0( tableFormatter.ToString( tableWellData )); From d39fa0009b018855f5849b501b5765fdeb221a12 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 14 Mar 2024 17:45:56 +0100 Subject: [PATCH 047/216] PR review --- .../codingUtilities/TableFormatter.cpp | 8 +++- .../codingUtilities/TableFormatter.hpp | 4 +- .../codingUtilities/TableLayout.cpp | 11 ++--- .../codingUtilities/TableLayout.hpp | 10 +--- .../codingUtilities/tests/testTable.cpp | 24 ++++------ .../mesh/generators/WellGeneratorBase.cpp | 48 ++++++++++--------- .../mesh/generators/WellGeneratorBase.hpp | 3 +- 7 files changed, 51 insertions(+), 57 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index 6a3cea6c132..f8aa27608ea 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -20,7 +20,7 @@ namespace geos { -TableFormatter::TableFormatter( TableLayout & tableLayout ) +TableFormatter::TableFormatter( TableLayout const & tableLayout ) { m_tableLayout = tableLayout; } @@ -105,7 +105,7 @@ string buildValueCell( TableLayout::Alignment const alignment, string_view value case TableLayout::right: return GEOS_FMT( "{:>{}}", value, spaces ); case TableLayout::left: return GEOS_FMT( "{:<{}}", value, spaces ); case TableLayout::center: return GEOS_FMT( "{:^{}}", value, spaces ); - default: return GEOS_FMT( "{:<{}}", value, spaces ); + default: return GEOS_FMT( "{:>{}}", value, spaces ); } } @@ -113,6 +113,10 @@ TableTextFormatter::TableTextFormatter( TableLayout & tableLayout ): TableFormatter( tableLayout ) {} +TableTextFormatter::TableTextFormatter( std::vector< string > const & columnNames ) + : TableFormatter( TableLayout( columnNames )) +{} + string TableTextFormatter::ToString( TableData tableData ) { return constructAndReturnTable( tableData.getTableDataRows() ); diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index 09e6d70c618..99c44bcc91d 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -39,7 +39,7 @@ class TableFormatter * @brief Construct a new Table Formatter from a tableLayout * @param tableLayout Contain all column names and optionnaly the table title */ - TableFormatter( TableLayout & tableLayout ); + TableFormatter( TableLayout const & tableLayout ); TableLayout m_tableLayout; @@ -88,6 +88,8 @@ class TableTextFormatter : public TableFormatter TableTextFormatter( TableLayout & tableLayout ); + TableTextFormatter( std::vector< string > const & columnNames ); + /** * @brief Convert the TableData to a table string. * @param tableData The TableData to convert. diff --git a/src/coreComponents/codingUtilities/TableLayout.cpp b/src/coreComponents/codingUtilities/TableLayout.cpp index cff524cf316..c18d4363ea5 100644 --- a/src/coreComponents/codingUtilities/TableLayout.cpp +++ b/src/coreComponents/codingUtilities/TableLayout.cpp @@ -21,7 +21,8 @@ namespace geos { -TableLayout::TableLayout( std::vector< string > const & headers ) +TableLayout::TableLayout( std::vector< string > const & headers, string const & title ): + tableTitle( title ) { setMargin( MarginValue::medium ); for( size_t idx = 0; idx< headers.size(); idx++ ) @@ -30,7 +31,8 @@ TableLayout::TableLayout( std::vector< string > const & headers ) } } -TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter ) +TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title ): + tableTitle( title ) { setMargin( MarginValue::medium ); @@ -44,11 +46,6 @@ TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter ) } } -void TableLayout::setTitle( string_view title ) -{ - tableTitle = title; -} - void TableLayout::setMargin( MarginValue marginType ) { borderMargin = marginType; diff --git a/src/coreComponents/codingUtilities/TableLayout.hpp b/src/coreComponents/codingUtilities/TableLayout.hpp index ba58a407058..84e706028b5 100644 --- a/src/coreComponents/codingUtilities/TableLayout.hpp +++ b/src/coreComponents/codingUtilities/TableLayout.hpp @@ -95,14 +95,14 @@ class TableLayout * @brief Construct a new Table object, all values in the table are centered by default * @param columnNames The names of the columns */ - TableLayout( std::vector< string > const & columnNames ); + TableLayout( std::vector< string > const & columnNames, string const & title = "" ); /** * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels * level * @param columnParameter List of structures to set up each colum parameters. */ - TableLayout( std::vector< ColumnParam > const & columnParameter ); + TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title = "" ); /** * @brief Set the minimal margin width between row content and borders. @@ -110,12 +110,6 @@ class TableLayout */ void setMargin( MarginValue marginType ); - /** - * @brief Set the table name - * @param tableTitle The table name - */ - void setTitle( string_view tableTitle ); - /** * @return return the table name */ diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 813fd87def6..5571ed395fb 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -31,9 +31,9 @@ TEST( testTable, tableClass ) "CordX", "CoordZ", "Prev\nelement", - "Next\nelement"} + "Next\nelement"}, + "InternalWellGenerator well_injector1" ); - tableLayout.setTitle( "InternalWellGenerator well_injector1" ); TableData tableData; tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); @@ -64,9 +64,7 @@ TEST( testTable, tableClass ) "CordX", "CoordZ", "Prev\nelement", - "Next\nelement"} - ); - tableLayout.setTitle( "InternalWellGenerator well_injector1" ); + "Next\nelement"}, "InternalWellGenerator well_injector1" ); TableData tableData; tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); @@ -96,9 +94,7 @@ TEST( testTable, tableClass ) TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::right}, TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::right} - } - ); - tableLayout.setTitle( "InternalWellGenerator well_injector1" ); + }, "InternalWellGenerator well_injector1" ); TableData tableData; tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); @@ -126,9 +122,7 @@ TEST( testTable, tableClass ) TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left, false}, TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center, false}, - } - ); - tableLayout.setTitle( "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + }, "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); TableData tableData; tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); @@ -150,9 +144,7 @@ TEST( testTable, tableClass ) { TableLayout tableLayout( { TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - } - ); - tableLayout.setTitle( "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + }, "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); TableData tableData; tableData.addRow( "value1" ); @@ -206,8 +198,8 @@ TEST( testTable, tableClass ) TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, - } ); - tableLayout.setTitle( "InternalWellGenerator well_injector1" ); + }, "InternalWellGenerator well_injector1" ); + tableLayout.setMargin( TableLayout::MarginValue::tiny ); TableData tableData; diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 55b35c5a1e9..3ff71468d9e 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -146,7 +146,8 @@ void WellGeneratorBase::generateWellGeometry( ) if( getLogLevel() >= 1 ) { - debugWellGeometry(); + logInternalWell(); + logPerforationTable(); } } @@ -524,28 +525,14 @@ void WellGeneratorBase::mergePerforations( array1d< array1d< localIndex > > cons } } -void WellGeneratorBase::debugWellGeometry() const +void WellGeneratorBase::logInternalWell() const { if( MpiWrapper::commRank( MPI_COMM_GEOSX ) != 0 ) { return; } - //1. formatting data - TableLayout tableWellLayout = TableLayout( { - TableLayout::ColumnParam{"Element no.", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"CoordX", TableLayout::Alignment::center}, - TableLayout::ColumnParam{"CoordY", TableLayout::Alignment::center}, - TableLayout::ColumnParam{"CoordZ", TableLayout::Alignment::center}, - TableLayout::ColumnParam{"Prev\nElement", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"Next\nElement", TableLayout::Alignment::right}, - } ); - - tableWellLayout.setTitle( "InternalWellGenerator " + getName()); - TableData tableWellData; - - //2. collecting data for( globalIndex iwelem = 0; iwelem < m_numElems; ++iwelem ) { std::optional< globalIndex > nextElement; @@ -561,25 +548,42 @@ void WellGeneratorBase::debugWellGeometry() const prevElement = m_prevElemId[iwelem][0]; } - tableWellData.addRow( iwelem, m_elemCenterCoords[iwelem][0], m_elemCenterCoords[iwelem][1], m_elemCenterCoords[iwelem][2], prevElement, nextElement ); + tableWellData.addRow( iwelem, + m_elemCenterCoords[iwelem][0], + m_elemCenterCoords[iwelem][1], + m_elemCenterCoords[iwelem][2], + prevElement, + nextElement ); } - //3. dumping + string wellTitle = "InternalWellGenerator " + getName(); + TableLayout tableWellLayout = TableLayout( { + TableLayout::ColumnParam{"Element no.", TableLayout::Alignment::right}, + TableLayout::ColumnParam{"CoordX", TableLayout::Alignment::center}, + TableLayout::ColumnParam{"CoordY", TableLayout::Alignment::center}, + TableLayout::ColumnParam{"CoordZ", TableLayout::Alignment::center}, + TableLayout::ColumnParam{"Prev\nElement", TableLayout::Alignment::right}, + TableLayout::ColumnParam{"Next\nElement", TableLayout::Alignment::right}, + }, wellTitle ); + + TableTextFormatter tableFormatter( tableWellLayout ); GEOS_LOG_RANK_0( tableFormatter.ToString( tableWellData )); +} - TableLayout tableLayoutPerfo = TableLayout( {"Perforation no.", "Coordinates", "connected to" } ); - tableLayoutPerfo.setTitle( "Peforation table" ); - +void WellGeneratorBase::logPerforationTable() const +{ TableData tablePerfoData; for( globalIndex iperf = 0; iperf < m_numPerforations; ++iperf ) { tablePerfoData.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); } + TableLayout tableLayoutPerfo = TableLayout( {"Perforation no.", "Coordinates", "connected to" }, + "Perforation table" ); + TableTextFormatter tablePerfoLog( tableLayoutPerfo ); GEOS_LOG_RANK_0( tablePerfoLog.ToString( tablePerfoData )); - } } diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.hpp b/src/coreComponents/mesh/generators/WellGeneratorBase.hpp index a4c6cb5f577..1482bce5d4c 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.hpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.hpp @@ -301,7 +301,8 @@ class WellGeneratorBase : public WellGeneratorABC ///@} /// @cond DO_NOT_DOCUMENT - void debugWellGeometry() const; + void logInternalWell() const; + void logPerforationTable() const; /// @endcond /// Global number of perforations From c58be1e60228e022727a7d0625f8a22e4b0facb3 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 14 Mar 2024 23:49:44 +0100 Subject: [PATCH 048/216] 2nd wave of pr review --- .../codingUtilities/TableData.cpp | 17 ++++++---- .../codingUtilities/TableData.hpp | 32 ++++++++++++++----- .../codingUtilities/TableLayout.cpp | 18 +++++------ .../codingUtilities/TableLayout.hpp | 10 +++--- .../codingUtilities/tests/testTable.cpp | 10 +++++- 5 files changed, 58 insertions(+), 29 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.cpp b/src/coreComponents/codingUtilities/TableData.cpp index 3edf800a02a..c2380d5b0b9 100644 --- a/src/coreComponents/codingUtilities/TableData.cpp +++ b/src/coreComponents/codingUtilities/TableData.cpp @@ -26,6 +26,11 @@ void TableData::addRow( std::vector< string > row ) m_rows.push_back( row ); } +void TableData::clear() +{ + m_rows.clear(); +} + std::vector< std::vector< string > > & TableData::getTableDataRows() { return m_rows; @@ -33,26 +38,26 @@ std::vector< std::vector< string > > & TableData::getTableDataRows() std::set< real64 > const & TableData2D::getColumns() const { - return columns; + return m_columns; } std::set< real64 > const & TableData2D::getRows() const { - return rows; + return m_rows; } TableData TableData2D::buildTableData() const { TableData tableDataToBeBuilt; - for( real64 const & rowValue : rows ) + for( real64 const & rowValue : m_rows ) { std::vector< string > values; values.push_back( GEOS_FMT( "{}", rowValue ) ); - for( real64 const & columnValue : columns ) + for( real64 const & columnValue : m_columns ) { std::pair< real64, real64 > id = std::pair< real64, real64 >( rowValue, columnValue ); - auto const dataIt = data.find( id ); + auto const dataIt = m_data.find( id ); - if( dataIt != data.end()) + if( dataIt != m_data.end()) { values.push_back( GEOS_FMT( "{}", dataIt->second )); } diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index 8051c889c4b..3d5dc49be66 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -25,7 +25,7 @@ namespace geos { template< typename T > constexpr bool is_string = std::is_same_v< T, std::string >; -// Class for managing table data +// Class for managing table m_data class TableData { public: @@ -38,8 +38,17 @@ class TableData template< typename ... Args > void addRow( Args const & ... args ); + /** + * @brief Add a row to the table + * @param row A vector of string who contains cell Values + */ void addRow( std::vector< string > row ); + /** + * @brief Reset data in the table + */ + void clear(); + /** * @return The rows of the table */ @@ -51,7 +60,7 @@ class TableData }; -// Class for managing 2D table data +// Class for managing 2D table m_data class TableData2D { public: @@ -71,13 +80,20 @@ class TableData2D */ TableData buildTableData() const; + /** + * @return return all columns values for 2D table + */ std::set< real64 > const & getColumns() const; + + /** + * @return return all rows values for 2D table + */ std::set< real64 > const & getRows() const; private: - std::map< std::pair< real64, real64 >, string > data; - std::set< real64 > columns; - std::set< real64 > rows; + std::map< std::pair< real64, real64 >, string > m_data; + std::set< real64 > m_columns; + std::set< real64 > m_rows; }; template< typename ... Args > @@ -97,9 +113,9 @@ template< typename T > void TableData2D::addCell( real64 rowValue, real64 columnValue, T value ) { std::pair< real64, real64 > id = std::pair< real64, real64 >( rowValue, columnValue ); - data[id] = GEOS_FMT( "{}", value ); - columns.insert( columnValue ); - rows.insert( rowValue ); + m_data[id] = GEOS_FMT( "{}", value ); + m_columns.insert( columnValue ); + m_rows.insert( rowValue ); } } diff --git a/src/coreComponents/codingUtilities/TableLayout.cpp b/src/coreComponents/codingUtilities/TableLayout.cpp index c18d4363ea5..75fa5026145 100644 --- a/src/coreComponents/codingUtilities/TableLayout.cpp +++ b/src/coreComponents/codingUtilities/TableLayout.cpp @@ -22,7 +22,7 @@ namespace geos { TableLayout::TableLayout( std::vector< string > const & headers, string const & title ): - tableTitle( title ) + m_tableTitle( title ) { setMargin( MarginValue::medium ); for( size_t idx = 0; idx< headers.size(); idx++ ) @@ -32,7 +32,7 @@ TableLayout::TableLayout( std::vector< string > const & headers, string const & } TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title ): - tableTitle( title ) + m_tableTitle( title ) { setMargin( MarginValue::medium ); @@ -46,31 +46,31 @@ TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter, st } } -void TableLayout::setMargin( MarginValue marginType ) +void TableLayout::setMargin( MarginValue marginValue ) { - borderMargin = marginType; - columnMargin = integer( marginType ) * 2 + 1; + m_borderMargin = marginValue; + m_columnMargin = integer( marginValue ) * 2 + 1; } string_view TableLayout::getTitle() const { - return tableTitle; + return m_tableTitle; } integer const & TableLayout::getBorderMargin() const { - return borderMargin; + return m_borderMargin; } integer const & TableLayout::getColumnMargin() const { - return columnMargin; + return m_columnMargin; } integer const & TableLayout::getMarginTitle() const { - return marginTitle; + return m_marginTitle; } } diff --git a/src/coreComponents/codingUtilities/TableLayout.hpp b/src/coreComponents/codingUtilities/TableLayout.hpp index 84e706028b5..de71c9fbcb4 100644 --- a/src/coreComponents/codingUtilities/TableLayout.hpp +++ b/src/coreComponents/codingUtilities/TableLayout.hpp @@ -108,7 +108,7 @@ class TableLayout * @brief Set the minimal margin width between row content and borders. * @param marginType The margin value */ - void setMargin( MarginValue marginType ); + void setMargin( MarginValue marginValue ); /** * @return return the table name @@ -133,10 +133,10 @@ class TableLayout std::vector< Column > m_columns; private: - string tableTitle; - integer borderMargin; - integer columnMargin; - integer marginTitle = 2; + string m_tableTitle; + integer m_borderMargin; + integer m_columnMargin; + integer m_marginTitle = 2; }; } diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 5571ed395fb..39a3f3df94b 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -26,6 +26,7 @@ using namespace geos; TEST( testTable, tableClass ) { + //table with empty row { TableLayout tableLayout( {"Well\nelement no.\nPV weighted\nbar", "CordX", @@ -59,6 +60,7 @@ TEST( testTable, tableClass ) ); }; + //same but with different values { TableLayout tableLayout( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", "CordX", @@ -86,6 +88,7 @@ TEST( testTable, tableClass ) ); } + //table with TableLayout::ColumnParam { TableLayout tableLayout( { TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, @@ -114,6 +117,7 @@ TEST( testTable, tableClass ) ); } + //test with hidden column { TableLayout tableLayout( { TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, @@ -140,7 +144,8 @@ TEST( testTable, tableClass ) "+---------------------------+---------------------+----------------------------------+-----------------------------+\n\n" ); } - + + //test with 1 column { TableLayout tableLayout( { TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, @@ -163,6 +168,7 @@ TEST( testTable, tableClass ) ); } + //test without title { TableLayout tableLayout( { TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, @@ -190,6 +196,7 @@ TEST( testTable, tableClass ) ); }; + //test with tiny margin { TableLayout tableLayout( { TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, @@ -220,6 +227,7 @@ TEST( testTable, tableClass ) ); }; + //test 2D table { TableLayout tableLayout( {"FakePressure", "Value1", "Value2"} ); TableData2D tableData; From 1d4bdb449237da2098586859f2dc9802e8a29cc8 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 15 Mar 2024 15:15:19 +0100 Subject: [PATCH 049/216] update compile time verification for table value --- .../codingUtilities/TableData.hpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index 3d5dc49be66..1cc024d326c 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -23,9 +23,19 @@ namespace geos { + +#if __cplusplus < 202002L +template< class T > +static constexpr bool has_formatter = fmt::has_formatter< fmt::remove_cvref_t< T >, fmt::format_context >(); +#else template< typename T > -constexpr bool is_string = std::is_same_v< T, std::string >; -// Class for managing table m_data +concept has_formatter = requires ( T& v, std::format_context ctx ) +{ + std::formatter< std::remove_cvref_t< T > >().format( v, ctx ); +}; +#endif + +// Class for managing table data class TableData { public: @@ -101,8 +111,8 @@ void TableData::addRow( Args const &... args ) { std::vector< string > m_cellsValue; ( [&] { + static_assert( has_formatter< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); string cellValue = GEOS_FMT( "{}", args ); - static_assert( is_string< decltype(cellValue) >, "An argunment passed in addRow cannot be converted to string" ); m_cellsValue.push_back( cellValue ); } (), ...); @@ -112,6 +122,7 @@ void TableData::addRow( Args const &... args ) template< typename T > void TableData2D::addCell( real64 rowValue, real64 columnValue, T value ) { + static_assert( has_formatter< decltype(value) >, "Argument passed in addCell cannot be converted to string" ); std::pair< real64, real64 > id = std::pair< real64, real64 >( rowValue, columnValue ); m_data[id] = GEOS_FMT( "{}", value ); m_columns.insert( columnValue ); From 0bff84742f0fc53e607277ce6ea2657d4e1ca008 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 15 Mar 2024 15:22:35 +0100 Subject: [PATCH 050/216] some update --- .../codingUtilities/TableData.cpp | 20 ++++++---- .../codingUtilities/TableData.hpp | 2 + .../codingUtilities/TableFormatter.cpp | 38 +++---------------- .../codingUtilities/TableFormatter.hpp | 11 +----- .../codingUtilities/TableLayout.cpp | 2 +- 5 files changed, 24 insertions(+), 49 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.cpp b/src/coreComponents/codingUtilities/TableData.cpp index 527cb45a812..3edf800a02a 100644 --- a/src/coreComponents/codingUtilities/TableData.cpp +++ b/src/coreComponents/codingUtilities/TableData.cpp @@ -21,19 +21,24 @@ namespace geos { +void TableData::addRow( std::vector< string > row ) +{ + m_rows.push_back( row ); +} + std::vector< std::vector< string > > & TableData::getTableDataRows() { return m_rows; } - std::set< real64 > const & TableData2D::getColumns() const - { +std::set< real64 > const & TableData2D::getColumns() const +{ return columns; - } - std::set< real64 > const & TableData2D::getRows() const - { - return rows; - } +} +std::set< real64 > const & TableData2D::getRows() const +{ + return rows; +} TableData TableData2D::buildTableData() const { @@ -51,6 +56,7 @@ TableData TableData2D::buildTableData() const { values.push_back( GEOS_FMT( "{}", dataIt->second )); } + } tableDataToBeBuilt.addRow( values ); } diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index 902ee33326d..c92e282d668 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -37,6 +37,8 @@ class TableData template< typename ... Args > void addRow( Args const & ... args ); + void addRow( std::vector< string > row); + /** * @return The rows of the table */ diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index e7d2d112ec8..ffb543cc44c 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -63,33 +63,7 @@ string TableCSVFormatter::headerToString() return headerValues; } -string TableCSVFormatter::dataToString( TableData2D & tableData2D ) -{ - - string data; - TableData tableData; - std::vector< std::vector< string > > rowsValues; - - tableData = tableData2D.buildTableData(); - rowsValues = tableData.getTableDataRows(); - data.reserve(tableData2D.getColumns().size() * tableData2D.getRows().size()); - - for( std::vector< string > const & row : rowsValues ) - { - for( size_t idxRow = 0; idxRow < row.size(); idxRow++ ) - { - data += row[idxRow]; - if( idxRow < row.size() - 1 ) - { - data += ","; - } - } - data += "\n"; - } - return data; -} - -string TableCSVFormatter::dataToString( TableData & tableData ) +string TableCSVFormatter::dataToString( TableData tableData ) { std::vector< std::vector< string > > rowsValues = tableData.getTableDataRows(); std::vector< TableLayout::Column > columns = m_tableLayout.m_columns; @@ -97,12 +71,12 @@ string TableCSVFormatter::dataToString( TableData & tableData ) fillTableColumnsFromRows( columns, rowsValues ); - for( std::vector< string > const & row : rowsValues ) + for( const auto & row : rowsValues ) { - for( size_t idxRow = 0; idxRow < row.size(); idxRow++ ) + for( size_t idxColumn = 0; idxColumn < row.size(); ++idxColumn ) { - data += row[idxRow]; - if( idxRow < row.size() - 1 ) + data += row[idxColumn]; + if( idxColumn < row.size() - 1 ) { data += ","; } @@ -139,7 +113,7 @@ TableTextFormatter::TableTextFormatter( TableLayout & tableLayout ): TableFormatter( tableLayout ) {} -string TableTextFormatter::ToString( TableData & tableData ) +string TableTextFormatter::ToString( TableData tableData ) { return constructAndReturnTable( tableData.getTableDataRows() ); } diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index c7768080ae2..db2820e3afb 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -67,19 +67,12 @@ class TableCSVFormatter : public TableFormatter */ TableCSVFormatter( TableLayout & tableLayout ); - /** - * @brief Convert the table data to a CSV string. - * @param tableData The 2D table data. - * @return The CSV string representation of the table data. - */ - string dataToString( TableData2D & tableData ); - /** * @brief Convert the table data to a CSV string. * @param tableData The 1D table data. * @return The CSV string representation of the table data. */ - string dataToString( TableData & tableData ); + string dataToString( TableData tableData ); /** * @return The string with all column names. @@ -100,7 +93,7 @@ class TableTextFormatter : public TableFormatter * @param tableData The TableData to convert. * @return The table string representation of the TableData. */ - string ToString( TableData & tableData ); + string ToString( TableData tableData ); /** * @brief Get a table string from the TableLayout. diff --git a/src/coreComponents/codingUtilities/TableLayout.cpp b/src/coreComponents/codingUtilities/TableLayout.cpp index aed9c7f876e..0818185bbc9 100644 --- a/src/coreComponents/codingUtilities/TableLayout.cpp +++ b/src/coreComponents/codingUtilities/TableLayout.cpp @@ -26,7 +26,7 @@ TableLayout::TableLayout( std::vector< string > const & headers ) setMargin( MarginValue::medium ); for( size_t idx = 0; idx< headers.size(); idx++ ) { - m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::middle, true}, {}, ""} ); + m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::right, true}, {}, ""} ); } } From 8553441bcbb04992b662170a8f7f94b4c0a29bc3 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 15 Mar 2024 15:23:02 +0100 Subject: [PATCH 051/216] pvt_log updated --- src/coreComponents/functions/TableFunction.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 3423bc643e4..71c000dbdd8 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -20,7 +20,6 @@ #include "codingUtilities/Parsing.hpp" #include "common/DataTypes.hpp" #include "fileIO/Outputs/OutputBase.hpp" -#include "codingUtilities/Table.hpp" #include "codingUtilities/TableLayout.hpp" #include "codingUtilities/TableData.hpp" #include "codingUtilities/TableFormatter.hpp" @@ -259,7 +258,7 @@ void TableFunction::printInCSV( string const & filename ) const TableCSVFormatter csvFormat( tableLayout ); os << csvFormat.headerToString(); - os << csvFormat.dataToString( tableData2D ); + os << csvFormat.dataToString( tableData2D.buildTableData() ); } os.close(); } @@ -329,7 +328,7 @@ void TableFunction::printInLog( string const & filename ) const if( nbRows <= 500 ) { TableTextFormatter table2DLog( tableLayout ); - GEOS_LOG_RANK_0( table2DLog.ToString( tableData2D )); + GEOS_LOG_RANK_0( table2DLog.ToString( tableData2D.buildTableData() )); } else { From 22b16e91ca029d600d9a6e46ed60aa34189db8a4 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 15 Mar 2024 15:39:05 +0100 Subject: [PATCH 052/216] update pvt log --- .../codingUtilities/TableData.hpp | 2 - .../functions/TableFunction.cpp | 56 +++++++++---------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index 6be3cf52bc0..1cc024d326c 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -48,8 +48,6 @@ class TableData template< typename ... Args > void addRow( Args const & ... args ); - void addRow( std::vector< string > row); - /** * @brief Add a row to the table * @param row A vector of string who contains cell Values diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 71c000dbdd8..4b44651a929 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -239,14 +239,6 @@ void TableFunction::printInCSV( string const & filename ) const integer const nY = coordsY.size(); std::vector< string > columnNames; - columnNames.push_back( string( units::getDescription( getDimUnit( 0 )))); - for( integer idxY = 0; idxY < nY; idxY++ ) - { - string description = string( units::getDescription( getDimUnit( 1 ))) + "=" + std::to_string( coordsY[idxY] ); - columnNames.push_back( description ); - } - TableLayout tableLayout( columnNames ); - TableData2D tableData2D; for( integer i = 0; i < nX; i++ ) { @@ -256,6 +248,14 @@ void TableFunction::printInCSV( string const & filename ) const } } + columnNames.push_back( string( units::getDescription( getDimUnit( 0 )))); + for( integer idxY = 0; idxY < nY; idxY++ ) + { + string description = string( units::getDescription( getDimUnit( 1 ))) + "=" + std::to_string( coordsY[idxY] ); + columnNames.push_back( description ); + } + TableLayout tableLayout( columnNames ); + TableCSVFormatter csvFormat( tableLayout ); os << csvFormat.headerToString(); os << csvFormat.dataToString( tableData2D.buildTableData() ); @@ -275,13 +275,6 @@ void TableFunction::printInLog( string const & filename ) const if( numDimensions == 1 ) { - TableLayout tableLayout( { - string( units::getDescription( getDimUnit( 0 ))), - string( units::getDescription( m_valueUnit )) - } ); - - tableLayout.setTitle( filename ); - TableData tableData; arraySlice1d< real64 const > const coords = m_coordinates[0]; @@ -290,6 +283,11 @@ void TableFunction::printInLog( string const & filename ) const tableData.addRow( coords[idx], m_values[idx] ); } + TableLayout tableLayout( { + string( units::getDescription( getDimUnit( 0 ))), + string( units::getDescription( m_valueUnit )) + }, filename ); + TableTextFormatter logTable( tableLayout ); GEOS_LOG_RANK_0( logTable.ToString( tableData )); } @@ -303,19 +301,8 @@ void TableFunction::printInLog( string const & filename ) const std::vector< std::vector< string > > vRowsValues; integer nbRows = 0; - vecDescription.push_back( string( units::getDescription( getDimUnit( 0 )))); - - for( integer idxY = 0; idxY < nY; idxY++ ) - { - string description = string( units::getDescription( getDimUnit( 1 ))) + "=" + std::to_string( coordsY[idxY] ); - vecDescription.push_back( description ); - } - - TableLayout tableLayout( vecDescription ); - tableLayout.setTitle( filename ); - + //1. collect TableData2D tableData2D; - for( integer i = 0; i < nX; i++ ) { for( integer j = 0; j < nY; j++ ) @@ -327,15 +314,26 @@ void TableFunction::printInLog( string const & filename ) const if( nbRows <= 500 ) { + //2. format + vecDescription.push_back( string( units::getDescription( getDimUnit( 0 )))); + for( integer idxY = 0; idxY < nY; idxY++ ) + { + string description = string( units::getDescription( getDimUnit( 1 ))) + "=" + std::to_string( coordsY[idxY] ); + vecDescription.push_back( description ); + } + TableLayout tableLayout( vecDescription, filename ); + + //3. log TableTextFormatter table2DLog( tableLayout ); GEOS_LOG_RANK_0( table2DLog.ToString( tableData2D.buildTableData() )); } else { + //2. format string log = GEOS_FMT( "The {} PVT table exceeding 500 rows.\nTo visualize the tables, go to the generated csv \n", filename ); - TableLayout tableLayoutInfos( {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}} ); - tableLayoutInfos.setTitle( filename ); + TableLayout tableLayoutInfos( {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}}, filename ); + //3. log TableTextFormatter tableLog( tableLayoutInfos ); GEOS_LOG_RANK_0( tableLog.layoutToString() ); } From 429920c03d56766db201de39cb218a4d6e6bcfd4 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 15 Mar 2024 15:49:14 +0100 Subject: [PATCH 053/216] add missing doc + uncrustify --- src/coreComponents/codingUtilities/TableFormatter.cpp | 8 ++++---- src/coreComponents/codingUtilities/TableFormatter.hpp | 7 +++++++ src/coreComponents/codingUtilities/TableLayout.cpp | 2 +- src/coreComponents/codingUtilities/tests/testTable.cpp | 2 +- src/coreComponents/mesh/generators/WellGeneratorBase.cpp | 1 - 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index f8aa27608ea..32e2316cdb7 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -93,10 +93,10 @@ string_view TableCSVFormatter::dataToString( TableData tableData ) /** * @brief Build a value cell given an alignment and spaces from "|" * - * @param alignment - * @param value - * @param spaces - * @return A cell value + * @param alignment The aligment of cell value + * @param value The cell value + * @param spaces The number of spaces in the cell + * @return A formated cell */ string buildValueCell( TableLayout::Alignment const alignment, string_view value, integer const spaces ) { diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index 99c44bcc91d..b08976f93d4 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -113,6 +113,13 @@ class TableTextFormatter : public TableFormatter void parseAndStoreHeaderSections( std::vector< TableLayout::Column > & columns, size_t & largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ); + + /** + * @brief Set the same vector size for each split header and merge it into columns + * @param columns The table columns to be merged + * @param largestHeaderVectorSize The reference value for adjusting splitHeader vector + * @param splitHeader The vector containing all split headers + */ void adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, size_t const & largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ); diff --git a/src/coreComponents/codingUtilities/TableLayout.cpp b/src/coreComponents/codingUtilities/TableLayout.cpp index 75fa5026145..33dd0676971 100644 --- a/src/coreComponents/codingUtilities/TableLayout.cpp +++ b/src/coreComponents/codingUtilities/TableLayout.cpp @@ -27,7 +27,7 @@ TableLayout::TableLayout( std::vector< string > const & headers, string const & setMargin( MarginValue::medium ); for( size_t idx = 0; idx< headers.size(); idx++ ) { - m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::center, true}, {}, ""} ); + m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::right, true}, {}, ""} ); } } diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 39a3f3df94b..96229e19b54 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -144,7 +144,7 @@ TEST( testTable, tableClass ) "+---------------------------+---------------------+----------------------------------+-----------------------------+\n\n" ); } - + //test with 1 column { TableLayout tableLayout( { diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 3ff71468d9e..12e8b2e4bc2 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -566,7 +566,6 @@ void WellGeneratorBase::logInternalWell() const TableLayout::ColumnParam{"Next\nElement", TableLayout::Alignment::right}, }, wellTitle ); - TableTextFormatter tableFormatter( tableWellLayout ); GEOS_LOG_RANK_0( tableFormatter.ToString( tableWellData )); } From 965a9720b158cfaec77b37f389e79ddcb7a3c3d8 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 18 Mar 2024 16:51:29 +0100 Subject: [PATCH 054/216] constness update + refacto on text formatter --- .../codingUtilities/TableData.cpp | 4 +- .../codingUtilities/TableData.hpp | 12 +- .../codingUtilities/TableFormatter.cpp | 159 ++++++++---------- .../codingUtilities/TableFormatter.hpp | 52 +++--- .../codingUtilities/tests/testTable.cpp | 42 ++--- 5 files changed, 119 insertions(+), 150 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.cpp b/src/coreComponents/codingUtilities/TableData.cpp index c2380d5b0b9..e70153a56f9 100644 --- a/src/coreComponents/codingUtilities/TableData.cpp +++ b/src/coreComponents/codingUtilities/TableData.cpp @@ -21,7 +21,7 @@ namespace geos { -void TableData::addRow( std::vector< string > row ) +void TableData::addRow( std::vector< string > const & row ) { m_rows.push_back( row ); } @@ -31,7 +31,7 @@ void TableData::clear() m_rows.clear(); } -std::vector< std::vector< string > > & TableData::getTableDataRows() +std::vector< std::vector< string > > const & TableData::getTableDataRows() const { return m_rows; } diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index 1cc024d326c..5c21721a0af 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -52,7 +52,7 @@ class TableData * @brief Add a row to the table * @param row A vector of string who contains cell Values */ - void addRow( std::vector< string > row ); + void addRow( std::vector< string > const & row ); /** * @brief Reset data in the table @@ -62,7 +62,7 @@ class TableData /** * @return The rows of the table */ - std::vector< std::vector< string > > & getTableDataRows(); + std::vector< std::vector< string > > const & getTableDataRows() const; private: @@ -82,7 +82,7 @@ class TableData2D * @param value Cell value to be added. */ template< typename T > - void addCell( real64 rowValue, real64 columnValue, T value ); + void addCell( real64 rowValue, real64 columnValue, T const & value ); /** * @brief Construct a TableData from a Table2D @@ -112,7 +112,7 @@ void TableData::addRow( Args const &... args ) std::vector< string > m_cellsValue; ( [&] { static_assert( has_formatter< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); - string cellValue = GEOS_FMT( "{}", args ); + string const cellValue = GEOS_FMT( "{}", args ); m_cellsValue.push_back( cellValue ); } (), ...); @@ -120,10 +120,10 @@ void TableData::addRow( Args const &... args ) } template< typename T > -void TableData2D::addCell( real64 rowValue, real64 columnValue, T value ) +void TableData2D::addCell( real64 const rowValue, real64 const columnValue, T const & value ) { static_assert( has_formatter< decltype(value) >, "Argument passed in addCell cannot be converted to string" ); - std::pair< real64, real64 > id = std::pair< real64, real64 >( rowValue, columnValue ); + std::pair< real64, real64 > const id = std::pair< real64, real64 >( rowValue, columnValue ); m_data[id] = GEOS_FMT( "{}", value ); m_columns.insert( columnValue ); m_rows.insert( rowValue ); diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index 32e2316cdb7..32230ac2328 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -26,7 +26,7 @@ TableFormatter::TableFormatter( TableLayout const & tableLayout ) } void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > const & rows ) + std::vector< std::vector< string > > const & rows ) const { for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) { @@ -41,49 +41,46 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column ////// CSV Formatter implementation /////////////////////////////////////////////////////////////////////// -TableCSVFormatter::TableCSVFormatter( TableLayout & tableLayout ) +TableCSVFormatter::TableCSVFormatter( TableLayout const & tableLayout ) { m_tableLayout = tableLayout; } -string_view TableCSVFormatter::headerToString() +string_view TableCSVFormatter::headerToString() const { - string headerValues = ""; - string separator = ","; + std::stringstream oss; + constexpr string_view separator = ","; for( std::size_t idxColumn = 0; idxColumn < m_tableLayout.m_columns.size(); ++idxColumn ) { - headerValues += m_tableLayout.m_columns[idxColumn].parameter.columnName; + oss << m_tableLayout.m_columns[idxColumn].parameter.columnName; if( idxColumn < m_tableLayout.m_columns.size() - 1 ) { - headerValues += separator; + oss << separator; } } - headerValues += "\n"; - return headerValues; + oss << "\n"; + return oss.str(); } -string_view TableCSVFormatter::dataToString( TableData tableData ) +string_view TableCSVFormatter::dataToString( TableData const & tableData ) const { - std::vector< std::vector< string > > rowsValues = tableData.getTableDataRows(); - std::vector< TableLayout::Column > columns = m_tableLayout.m_columns; - string data; - - fillTableColumnsFromRows( columns, rowsValues ); + std::vector< std::vector< string > > const rowsValues = tableData.getTableDataRows(); + std::ostringstream oss; for( const auto & row : rowsValues ) { for( size_t idxColumn = 0; idxColumn < row.size(); ++idxColumn ) { - data += row[idxColumn]; + oss << row[idxColumn]; if( idxColumn < row.size() - 1 ) { - data += ","; + oss << ","; } } - data += "\n"; + oss << "\n"; } - return data; + return oss.str(); } /////////////////////////////////////////////////////////////////////// @@ -109,7 +106,7 @@ string buildValueCell( TableLayout::Alignment const alignment, string_view value } } -TableTextFormatter::TableTextFormatter( TableLayout & tableLayout ): +TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): TableFormatter( tableLayout ) {} @@ -117,45 +114,52 @@ TableTextFormatter::TableTextFormatter( std::vector< string > const & columnName : TableFormatter( TableLayout( columnNames )) {} -string TableTextFormatter::ToString( TableData tableData ) +string TableTextFormatter::toString( TableData const & tableData ) const { - return constructAndReturnTable( tableData.getTableDataRows() ); + std::ostringstream tableOutput; + string sectionSeparator; + std::vector< TableLayout::Column > columns = m_tableLayout.m_columns; + integer const nbRows = tableData.getTableDataRows().size(); + + fillTableColumnsFromRows( columns, tableData.getTableDataRows() ); + + layoutToString( tableOutput, columns, nbRows, sectionSeparator ); + buildSectionRows( columns, sectionSeparator, tableOutput, nbRows, TableLayout::Section::values ); + tableOutput << '\n'; + + return tableOutput.str(); } -string TableTextFormatter::layoutToString() +void TableTextFormatter::layoutToString( std::ostringstream & tableOutput, + std::vector< TableLayout::Column > & columns, + integer const nbRow, + string & sectionSeparator ) const { string titleRows; string topSeparator; - string sectionSeparator; - size_t largestHeaderVectorSize = 0; std::vector< std::vector< string > > splitHeader; - std::vector< TableLayout::Column > columns = m_tableLayout.m_columns; - - string tableTitle = string( m_tableLayout.getTitle()); + string const tableTitle = string( m_tableLayout.getTitle()); parseAndStoreHeaderSections( columns, largestHeaderVectorSize, splitHeader ); adjustHeaderSizesAndStore( columns, largestHeaderVectorSize, splitHeader ); - findAndSetMaxStringSize( columns, 0 ); + findAndSetMaxStringSize( columns, nbRow ); computeAndBuildSeparator( columns, topSeparator, sectionSeparator ); if( !tableTitle.empty()) { buildTitleRow( titleRows, topSeparator, sectionSeparator ); + tableOutput << titleRows; } - string tableRows = GEOS_FMT( "{}\n", sectionSeparator ); - buildSectionRows( columns, sectionSeparator, tableRows, largestHeaderVectorSize, TableLayout::Section::header ); - - string tableOutput = titleRows + tableRows + '\n'; - - return tableOutput; + tableOutput << sectionSeparator + '\n'; + buildSectionRows( columns, sectionSeparator, tableOutput, largestHeaderVectorSize, TableLayout::Section::header ); } -void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout::Column > & columns, +void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout::Column > const & columns, size_t & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ) + std::vector< std::vector< string > > & splitHeader ) const { for( auto const & column : columns ) { @@ -177,7 +181,7 @@ void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout:: void TableTextFormatter::adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, size_t const & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ) + std::vector< std::vector< string > > & splitHeader ) const { for( size_t columnParamIdx = 0; columnParamIdx < columns.size(); columnParamIdx++ ) { @@ -191,7 +195,7 @@ void TableTextFormatter::adjustHeaderSizesAndStore( std::vector< TableLayout::Co } void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, - size_t const & nbRows ) + size_t const & nbRows ) const { string maxStringSize = ""; for( auto & column : columns ) @@ -218,8 +222,8 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu } void TableTextFormatter::computeAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, - string::size_type sectionlineLength, - string::size_type titleLineLength ) + string::size_type const sectionlineLength, + string::size_type const titleLineLength ) const { integer extraLinesPerColumn; integer extraLines; @@ -248,16 +252,16 @@ void TableTextFormatter::computeAndSetMaxStringSize( std::vector< TableLayout::C void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Column > & columns, string & topSeparator, - string & sectionSeparator ) + string & sectionSeparator ) const { - integer columnMargin = m_tableLayout.getColumnMargin(); - integer borderMargin = m_tableLayout.getBorderMargin(); - integer marginTitle = m_tableLayout.getMarginTitle(); + integer const columnMargin = m_tableLayout.getColumnMargin(); + integer const borderMargin = m_tableLayout.getBorderMargin(); + integer const marginTitle = m_tableLayout.getMarginTitle(); string tableTitle = string( m_tableLayout.getTitle() ); string::size_type sectionlineLength = 0; - string::size_type titleLineLength = tableTitle.length() + ( marginTitle * 2 ); - integer nbSpaceBetweenColumn = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); + string::size_type const titleLineLength = tableTitle.length() + ( marginTitle * 2 ); + integer const nbSpaceBetweenColumn = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); if( !tableTitle.empty()) { @@ -301,31 +305,33 @@ void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Col } } } - topSeparator = GEOS_FMT( "+{:-<{}}+", "", sectionSeparator.size() - 2 );// -2 for ++ + topSeparator = GEOS_FMT( "+{:-<{}}+", "", sectionSeparator.size() - 2 ); // -2 for ++ } -void TableTextFormatter::buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ) +void TableTextFormatter::buildTitleRow( string & titleRows, + string_view topSeparator, + string_view sectionSeparator ) const { titleRows = GEOS_FMT( "\n{}\n|", topSeparator ); titleRows += buildValueCell( TableLayout::Alignment::center, m_tableLayout.getTitle(), - (sectionSeparator.length() - 2) // -2 for || + (sectionSeparator.length() - 2) // -2 for || ); titleRows += GEOS_FMT( "{}\n", "|" ); } void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > & columns, string_view sectionSeparator, - string & tableRows, + std::ostringstream & tableRows, integer const nbRows, - TableLayout::Section const section ) + TableLayout::Section const section ) const { - integer columnMargin = m_tableLayout.getColumnMargin(); - integer borderMargin = m_tableLayout.getBorderMargin(); + integer const columnMargin = m_tableLayout.getColumnMargin(); + integer const borderMargin = m_tableLayout.getBorderMargin(); for( integer idxRow = 0; idxRow< nbRows; idxRow++ ) { - tableRows += GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); + tableRows << GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { string cell; @@ -339,65 +345,32 @@ void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > & cell = columns[idxColumn].columnValues[idxRow]; } integer const cellSize = columns[idxColumn].m_maxStringSize.length(); - tableRows += buildValueCell( columns[idxColumn].parameter.alignment, + tableRows << buildValueCell( columns[idxColumn].parameter.alignment, cell, cellSize ); if( idxColumn < columns.size() - 1 ) { - tableRows += GEOS_FMT( "{:^{}}", "|", columnMargin ); + tableRows << GEOS_FMT( "{:^{}}", "|", columnMargin ); } } if( columns.size() == 1 ) { - tableRows += GEOS_FMT( "{:>{}}\n", "|", columnMargin ); + tableRows << GEOS_FMT( "{:>{}}\n", "|", columnMargin ); } else { - tableRows += GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); + tableRows << GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); } } if( nbRows != 0 ) { - tableRows += GEOS_FMT( "{}\n", sectionSeparator ); + tableRows << GEOS_FMT( "{}\n", sectionSeparator ); } } -string TableTextFormatter::constructAndReturnTable( std::vector< std::vector< string > > const & rowsValues ) -{ - string titleRows; - string topSeparator; - string sectionSeparator; - - size_t largestHeaderVectorSize = 0; - std::vector< std::vector< string > > splitHeader; - std::vector< TableLayout::Column > columns = m_tableLayout.m_columns; - - string tableTitle = string( m_tableLayout.getTitle()); - - fillTableColumnsFromRows( columns, rowsValues ); - - parseAndStoreHeaderSections( columns, largestHeaderVectorSize, splitHeader ); - adjustHeaderSizesAndStore( columns, largestHeaderVectorSize, splitHeader ); - - findAndSetMaxStringSize( columns, rowsValues.size()); - computeAndBuildSeparator( columns, topSeparator, sectionSeparator ); - - if( !tableTitle.empty()) - { - buildTitleRow( titleRows, topSeparator, sectionSeparator ); - } - - string tableRows = GEOS_FMT( "{}\n", sectionSeparator ); - buildSectionRows( columns, sectionSeparator, tableRows, largestHeaderVectorSize, TableLayout::Section::header ); - buildSectionRows( columns, sectionSeparator, tableRows, rowsValues.size(), TableLayout::Section::values ); - - string tableOutput = titleRows + tableRows + '\n'; - - return tableOutput; -} } diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index b08976f93d4..73d432a6079 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -41,16 +41,17 @@ class TableFormatter */ TableFormatter( TableLayout const & tableLayout ); - TableLayout m_tableLayout; - /** * @brief Fill the vector (m_column) in tableData with values from m_rows in tableLayout, storing all values in an unsorted order. * @param columns Vector of columns to be filled. * @param tableData Vector of table data. */ void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > const & tableData ); + std::vector< std::vector< string > > const & tableData ) const; +protected: + + TableLayout m_tableLayout; }; class TableCSVFormatter : public TableFormatter @@ -65,19 +66,19 @@ class TableCSVFormatter : public TableFormatter * @brief Construct a new Table Formatter from a tableLayout * @param tableLayout Contain all column names and optionnaly the table title */ - TableCSVFormatter( TableLayout & tableLayout ); + TableCSVFormatter( TableLayout const & tableLayout ); /** * @brief Convert the table data to a CSV string. * @param tableData The 1D table data. * @return The CSV string representation of the table data. */ - string_view dataToString( TableData tableData ); + string_view dataToString( TableData const & tableData ) const; /** * @return The string with all column names. */ - string_view headerToString(); + string_view headerToString() const; }; @@ -86,7 +87,7 @@ class TableTextFormatter : public TableFormatter public: - TableTextFormatter( TableLayout & tableLayout ); + TableTextFormatter( TableLayout const & tableLayout ); TableTextFormatter( std::vector< string > const & columnNames ); @@ -95,13 +96,16 @@ class TableTextFormatter : public TableFormatter * @param tableData The TableData to convert. * @return The table string representation of the TableData. */ - string ToString( TableData tableData ); + string toString( TableData const & tableData ) const; /** * @brief Get a table string from the TableLayout. * @return The table string representation of the TableLayout. */ - string layoutToString(); + void layoutToString( std::ostringstream & tableOutput, + std::vector< TableLayout::Column > & columns, + integer const nbRows, + string & sectionSeparator ) const; private: @@ -110,24 +114,24 @@ class TableTextFormatter : public TableFormatter * @param splitHeader A empty vector who will contain all split header names * @param largestHeaderVectorSize The largest split header vector size */ - void parseAndStoreHeaderSections( std::vector< TableLayout::Column > & columns, + void parseAndStoreHeaderSections( std::vector< TableLayout::Column > const & columns, size_t & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ); + std::vector< std::vector< string > > & splitHeader ) const; /** * @brief Set the same vector size for each split header and merge it into columns * @param columns The table columns to be merged * @param largestHeaderVectorSize The reference value for adjusting splitHeader vector - * @param splitHeader The vector containing all split headers + * @param splitHeader The vector containing all split headers */ void adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, size_t const & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ); + std::vector< std::vector< string > > & splitHeader ) const; /** * @brief For each column find and set the column's longest string */ - void findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, size_t const & nbRows ); + void findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, size_t const & nbRows ) const; /** * @brief Compute the largest string size in the table. If the table title is the largest string size in the table, recalculate for all @@ -136,8 +140,8 @@ class TableTextFormatter : public TableFormatter * @param titleLineLength The length of a title line */ void computeAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, - string::size_type sectionlineLength, - string::size_type titleLineLength ); + string::size_type const sectionlineLength, + string::size_type const titleLineLength ) const; /** * @brief Compute and build the top and the section line separator @@ -146,7 +150,7 @@ class TableTextFormatter : public TableFormatter */ void computeAndBuildSeparator( std::vector< TableLayout::Column > & columns, string & topSeparator, - string & sectionSeparator ); + string & sectionSeparator ) const; /** * @brief Build the table title section @@ -154,7 +158,7 @@ class TableTextFormatter : public TableFormatter * @param topSeparator The top line separator * @param sectionSeparator The section line separator */ - void buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ); + void buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ) const; /** * @brief Build a section by specifying it's type ( header or section ) @@ -165,17 +169,9 @@ class TableTextFormatter : public TableFormatter */ void buildSectionRows( std::vector< TableLayout::Column > & columns, string_view sectionSeparator, - string & rows, + std::ostringstream & rows, integer const nbRows, - TableLayout::Section const section ); - - /** - * @brief Construct a table from a tableData - * @param rowsValues All values sorted by rows - * @return A table string - */ - string constructAndReturnTable( std::vector< std::vector< string > > const & rowsValues ); - + TableLayout::Section const section ) const; }; } diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 96229e19b54..fe2260abbef 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -43,19 +43,19 @@ TEST( testTable, tableClass ) 787442, 10 ); TableTextFormatter tableText( tableLayout ); - EXPECT_EQ( tableText.ToString( + EXPECT_EQ( tableText.toString( tableData ), "\n+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n" "| InternalWellGenerator well_injector1 |\n" "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| Well | CordX | CoordZ | Prev | Next |\n" - "| element no. | | | element | element |\n" - "| PV weighted | | | | |\n" - "| bar | | | | |\n" + "| Well | CordX | CoordZ | Prev | Next |\n" + "| element no. | | | element | element |\n" + "| PV weighted | | | | |\n" + "| bar | | | | |\n" "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" + "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" "| | | | | |\n" - "| Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | [30.21543] | 30.45465142 | 787442 | 10 |\n" + "| Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | [30.21543] | 30.45465142 | 787442 | 10 |\n" "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" ); }; @@ -74,16 +74,16 @@ TEST( testTable, tableClass ) tableData.addRow( "value23", "[30.21543]", "30.45465142", 787442, 10 ); TableTextFormatter tableText( tableLayout ); - EXPECT_EQ( tableText.ToString( tableData ), + EXPECT_EQ( tableText.toString( tableData ), "\n+---------------------------------------------------------------------------------------------------------------------------------------------------------+\n" "| InternalWellGenerator well_injector1 |\n" "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| Duis fringilla, ligula sed porta fringilla, | CordX | CoordZ | Prev | Next |\n" + "| Duis fringilla, ligula sed porta fringilla, | CordX | CoordZ | Prev | Next |\n" "| ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | | | element | element |\n" "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" + "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" "| | | | | |\n" - "| value23 | [30.21543] | 30.45465142 | 787442 | 10 |\n" + "| value23 | [30.21543] | 30.45465142 | 787442 | 10 |\n" "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" ); } @@ -104,7 +104,7 @@ TEST( testTable, tableClass ) tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); TableTextFormatter tableText( tableLayout ); - EXPECT_EQ( tableText.ToString( tableData ), + EXPECT_EQ( tableText.toString( tableData ), "\n+-----------------------------------------------------------------------------------------+\n" "| InternalWellGenerator well_injector1 |\n" "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" @@ -133,7 +133,7 @@ TEST( testTable, tableClass ) tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); TableTextFormatter tableText( tableLayout ); - EXPECT_EQ( tableText.ToString( tableData ), + EXPECT_EQ( tableText.toString( tableData ), "\n+------------------------------------------------------------------------------------------------------------------+\n" "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" @@ -156,7 +156,7 @@ TEST( testTable, tableClass ) tableData.addRow( "val1" ); TableTextFormatter tableText( tableLayout ); - EXPECT_EQ( tableText.ToString( tableData ), + EXPECT_EQ( tableText.toString( tableData ), "\n+-------------------------------------------------------------------------------------------------------------------+\n" "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" "+-------------------------------------------------------------------------------------------------------------------+\n" @@ -185,7 +185,7 @@ TEST( testTable, tableClass ) tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); TableTextFormatter tableText( tableLayout ); - EXPECT_EQ( tableText.ToString( tableData ), + EXPECT_EQ( tableText.toString( tableData ), "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" "| | | | | element | element |\n" @@ -214,7 +214,7 @@ TEST( testTable, tableClass ) tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); TableTextFormatter tableText( tableLayout ); - EXPECT_EQ( tableText.ToString( tableData ), + EXPECT_EQ( tableText.toString( tableData ), "\n+-----------------------------------------------------------------+\n" "| InternalWellGenerator well_injector1 |\n" "+------------+------+-------------------+---------+-------+-------+\n" @@ -242,13 +242,13 @@ TEST( testTable, tableClass ) } TableTextFormatter tableLog( tableLayout ); - EXPECT_EQ( tableLog.ToString( tableData.buildTableData()), + EXPECT_EQ( tableLog.toString( tableData.buildTableData()), "+----------------+----------+------------------------+\n" - "| FakePressure | Value1 | Value2 |\n" + "| FakePressure | Value1 | Value2 |\n" "+----------------+----------+------------------------+\n" - "| 300 | 0.03 | 0.02 |\n" - "| 350 | 0.035 | 0.023333333333333334 |\n" - "| 400 | 0.04 | 0.02666666666666667 |\n" + "| 300 | 0.03 | 0.02 |\n" + "| 350 | 0.035 | 0.023333333333333334 |\n" + "| 400 | 0.04 | 0.02666666666666667 |\n" "+----------------+----------+------------------------+\n\n" ); From 6e49ebcfab0d36f58e1c31985de80218a2eec815 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 18 Mar 2024 18:03:30 +0100 Subject: [PATCH 055/216] PR correction --- .../codingUtilities/TableFormatter.cpp | 19 +++++++++++++++---- .../codingUtilities/TableFormatter.hpp | 17 +++++++++++++---- .../codingUtilities/TableLayout.cpp | 5 +++++ .../codingUtilities/TableLayout.hpp | 18 ++++++++++++------ 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index 32230ac2328..23266d21c28 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -51,10 +51,10 @@ string_view TableCSVFormatter::headerToString() const std::stringstream oss; constexpr string_view separator = ","; - for( std::size_t idxColumn = 0; idxColumn < m_tableLayout.m_columns.size(); ++idxColumn ) + for( std::size_t idxColumn = 0; idxColumn < m_tableLayout.getColumns().size(); ++idxColumn ) { - oss << m_tableLayout.m_columns[idxColumn].parameter.columnName; - if( idxColumn < m_tableLayout.m_columns.size() - 1 ) + oss << m_tableLayout.getColumns()[idxColumn].parameter.columnName; + if( idxColumn < m_tableLayout.getColumns().size() - 1 ) { oss << separator; } @@ -118,7 +118,7 @@ string TableTextFormatter::toString( TableData const & tableData ) const { std::ostringstream tableOutput; string sectionSeparator; - std::vector< TableLayout::Column > columns = m_tableLayout.m_columns; + std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); integer const nbRows = tableData.getTableDataRows().size(); fillTableColumnsFromRows( columns, tableData.getTableDataRows() ); @@ -130,6 +130,17 @@ string TableTextFormatter::toString( TableData const & tableData ) const return tableOutput.str(); } +string TableTextFormatter::layoutToString() const +{ + std::ostringstream tableOutput; + std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); + string sectionSeparator; + + layoutToString( tableOutput, columns, 0, sectionSeparator ); + + return tableOutput.str(); +} + void TableTextFormatter::layoutToString( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, integer const nbRow, diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index 73d432a6079..2b2f3123fe8 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -99,16 +99,25 @@ class TableTextFormatter : public TableFormatter string toString( TableData const & tableData ) const; /** - * @brief Get a table string from the TableLayout. - * @return The table string representation of the TableLayout. + *@brief Converts a TableLayout into a formatted string representation. + * @return string + */ + string layoutToString() const; + +private: + + /** + * @brief Converts a TableLayout into a formatted representation. + * @param tableOutput The output stream + * @param columns The vectors of table columns + * @param nbRows Number of rows in the table + * @param sectionSeparator An empty string for building the section separator */ void layoutToString( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, integer const nbRows, string & sectionSeparator ) const; -private: - /** * @brief Split all header names by detecting the newline \\n character. * @param splitHeader A empty vector who will contain all split header names diff --git a/src/coreComponents/codingUtilities/TableLayout.cpp b/src/coreComponents/codingUtilities/TableLayout.cpp index 33dd0676971..4fae15ffaca 100644 --- a/src/coreComponents/codingUtilities/TableLayout.cpp +++ b/src/coreComponents/codingUtilities/TableLayout.cpp @@ -52,6 +52,11 @@ void TableLayout::setMargin( MarginValue marginValue ) m_columnMargin = integer( marginValue ) * 2 + 1; } +std::vector< TableLayout::Column > const & TableLayout::getColumns() const +{ + return m_columns; +} + string_view TableLayout::getTitle() const { return m_tableTitle; diff --git a/src/coreComponents/codingUtilities/TableLayout.hpp b/src/coreComponents/codingUtilities/TableLayout.hpp index de71c9fbcb4..b768b3e74e7 100644 --- a/src/coreComponents/codingUtilities/TableLayout.hpp +++ b/src/coreComponents/codingUtilities/TableLayout.hpp @@ -111,28 +111,34 @@ class TableLayout void setMargin( MarginValue marginValue ); /** - * @return return the table name + * @brief Get the columns vector + * + * @return std::vector< Column > const& + */ + std::vector< Column > const & getColumns() const; + + /** + * @return Get the table name */ string_view getTitle() const; /** - * @return return the border margin + * @return Get the border margin */ integer const & getBorderMargin() const; /** - * @return return the column margin + * @return Get the column margin */ integer const & getColumnMargin() const; /** - * @return return the margin title + * @return Get the margin title */ integer const & getMarginTitle() const; - std::vector< Column > m_columns; - private: + std::vector< Column > m_columns; string m_tableTitle; integer m_borderMargin; integer m_columnMargin; From c1fb3ddab8bd4ce769d5633f670674297fe6a5a1 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 19 Mar 2024 10:48:58 +0100 Subject: [PATCH 056/216] move has_formatter to format.hpp, doc correction --- src/coreComponents/codingUtilities/TableData.hpp | 12 +----------- .../codingUtilities/TableFormatter.hpp | 2 +- src/coreComponents/codingUtilities/TableLayout.hpp | 12 +++++------- src/coreComponents/common/Format.hpp | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index 5c21721a0af..03d807ea72f 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -20,21 +20,11 @@ #define GEOS_COMMON_TableData_HPP #include "common/DataTypes.hpp" +#include "common/Format.hpp" namespace geos { -#if __cplusplus < 202002L -template< class T > -static constexpr bool has_formatter = fmt::has_formatter< fmt::remove_cvref_t< T >, fmt::format_context >(); -#else -template< typename T > -concept has_formatter = requires ( T& v, std::format_context ctx ) -{ - std::formatter< std::remove_cvref_t< T > >().format( v, ctx ); -}; -#endif - // Class for managing table data class TableData { diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index 2b2f3123fe8..56cf1fe4eec 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -99,7 +99,7 @@ class TableTextFormatter : public TableFormatter string toString( TableData const & tableData ) const; /** - *@brief Converts a TableLayout into a formatted string representation. + * @brief Converts a TableLayout into a formatted string representation. * @return string */ string layoutToString() const; diff --git a/src/coreComponents/codingUtilities/TableLayout.hpp b/src/coreComponents/codingUtilities/TableLayout.hpp index b768b3e74e7..b09c830ee46 100644 --- a/src/coreComponents/codingUtilities/TableLayout.hpp +++ b/src/coreComponents/codingUtilities/TableLayout.hpp @@ -111,29 +111,27 @@ class TableLayout void setMargin( MarginValue marginValue ); /** - * @brief Get the columns vector - * - * @return std::vector< Column > const& + * @return The columns vector */ std::vector< Column > const & getColumns() const; /** - * @return Get the table name + * @return The table name */ string_view getTitle() const; /** - * @return Get the border margin + * @return The border margin */ integer const & getBorderMargin() const; /** - * @return Get the column margin + * @return The column margin */ integer const & getColumnMargin() const; /** - * @return Get the margin title + * @return The margin title */ integer const & getMarginTitle() const; diff --git a/src/coreComponents/common/Format.hpp b/src/coreComponents/common/Format.hpp index e2a73a8789c..f468aea1c0b 100644 --- a/src/coreComponents/common/Format.hpp +++ b/src/coreComponents/common/Format.hpp @@ -102,6 +102,20 @@ constexpr auto GEOS_FMT_NS::detail::has_const_formatter_impl< GEOS_FMT_NS::forma return true; } #endif + +/** + * @brief evaluates at compile time if a fmt::formatter exists for a given type + */ +#if __cplusplus < 202002L +template< class T > +static constexpr bool has_formatter = fmt::has_formatter< fmt::remove_cvref_t< T >, fmt::format_context >(); +#else +template< typename T > +concept has_formatter = requires ( T& v, std::format_context ctx ) +{ + std::formatter< std::remove_cvref_t< T > >().format( v, ctx ); +}; +#endif // End of the workaround for fmt compilation issues #endif //GEOS_COMMON_FORMAT_HPP_ From e0c6ca2850bb31fccac951423d3de0a8a9b83e6c Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 19 Mar 2024 10:49:47 +0100 Subject: [PATCH 057/216] log level correction --- .../mesh/generators/WellGeneratorBase.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 12e8b2e4bc2..2461b0d6eb9 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -144,7 +144,7 @@ void WellGeneratorBase::generateWellGeometry( ) // make sure that the perforation locations are valid checkPerforationLocationsValidity(); - if( getLogLevel() >= 1 ) + if( getLogLevel() >= 1 && logger::internal::rank == 0 ) { logInternalWell(); logPerforationTable(); @@ -527,11 +527,6 @@ void WellGeneratorBase::mergePerforations( array1d< array1d< localIndex > > cons void WellGeneratorBase::logInternalWell() const { - if( MpiWrapper::commRank( MPI_COMM_GEOSX ) != 0 ) - { - return; - } - TableData tableWellData; for( globalIndex iwelem = 0; iwelem < m_numElems; ++iwelem ) { @@ -556,7 +551,7 @@ void WellGeneratorBase::logInternalWell() const nextElement ); } - string wellTitle = "InternalWellGenerator " + getName(); + string wellTitle = GEOS_FMT( "Well '{}' Element Table", getName() ); TableLayout tableWellLayout = TableLayout( { TableLayout::ColumnParam{"Element no.", TableLayout::Alignment::right}, TableLayout::ColumnParam{"CoordX", TableLayout::Alignment::center}, @@ -567,7 +562,7 @@ void WellGeneratorBase::logInternalWell() const }, wellTitle ); TableTextFormatter tableFormatter( tableWellLayout ); - GEOS_LOG_RANK_0( tableFormatter.ToString( tableWellData )); + GEOS_LOG_RANK_0( tableFormatter.toString( tableWellData )); } void WellGeneratorBase::logPerforationTable() const @@ -582,7 +577,6 @@ void WellGeneratorBase::logPerforationTable() const "Perforation table" ); TableTextFormatter tablePerfoLog( tableLayoutPerfo ); - GEOS_LOG_RANK_0( tablePerfoLog.ToString( tablePerfoData )); } } From 7221c0f145fe26cde330b39d0687d6e0b9dc0b73 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 20 Mar 2024 14:12:33 +0100 Subject: [PATCH 058/216] perfo log correctly displayed --- src/coreComponents/mesh/generators/WellGeneratorBase.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 2461b0d6eb9..f56a5dc72fa 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -573,10 +573,9 @@ void WellGeneratorBase::logPerforationTable() const tablePerfoData.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); } - TableLayout tableLayoutPerfo = TableLayout( {"Perforation no.", "Coordinates", "connected to" }, - "Perforation table" ); - + TableLayout tableLayoutPerfo ( {"Perforation no.", "Coordinates", "connected to" }, "Perforation table" ); TableTextFormatter tablePerfoLog( tableLayoutPerfo ); + GEOS_LOG_RANK_0( tablePerfoLog.toString( tablePerfoData )); } } From 82098d81a2c7b24bd029431faf1a13fd5627612c Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 21 Mar 2024 10:08:26 +0100 Subject: [PATCH 059/216] remove ; to scope bracket --- src/coreComponents/codingUtilities/tests/testTable.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index fe2260abbef..25eed3e0fe8 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -58,7 +58,7 @@ TEST( testTable, tableClass ) "| Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | [30.21543] | 30.45465142 | 787442 | 10 |\n" "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" ); - }; + } //same but with different values { @@ -194,7 +194,7 @@ TEST( testTable, tableClass ) "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" ); - }; + } //test with tiny margin { @@ -225,7 +225,7 @@ TEST( testTable, tableClass ) "| val1 | v|[3.045,42.02,89.25]|3 |10 | 3 |\n" "+------------+------+-------------------+---------+-------+-------+\n\n" ); - }; + } //test 2D table { From 75ed072ade835e66841ee49467e80e1f81978a00 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 21 Mar 2024 10:14:23 +0100 Subject: [PATCH 060/216] doc correction format.hpp --- src/coreComponents/common/Format.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/common/Format.hpp b/src/coreComponents/common/Format.hpp index f468aea1c0b..ae40f1d85ad 100644 --- a/src/coreComponents/common/Format.hpp +++ b/src/coreComponents/common/Format.hpp @@ -104,7 +104,7 @@ constexpr auto GEOS_FMT_NS::detail::has_const_formatter_impl< GEOS_FMT_NS::forma #endif /** - * @brief evaluates at compile time if a fmt::formatter exists for a given type + * evaluates at compile time if a fmt::formatter exists for a given type */ #if __cplusplus < 202002L template< class T > @@ -115,7 +115,6 @@ concept has_formatter = requires ( T& v, std::format_context ctx ) { std::formatter< std::remove_cvref_t< T > >().format( v, ctx ); }; -#endif -// End of the workaround for fmt compilation issues +#endif // End of the workaround for fmt compilation issues #endif //GEOS_COMMON_FORMAT_HPP_ From 346992013ad50e58ad0c4af856cd9d6bcbb6b778 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 21 Mar 2024 10:16:12 +0100 Subject: [PATCH 061/216] format.hpp doc --- src/coreComponents/common/Format.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/common/Format.hpp b/src/coreComponents/common/Format.hpp index ae40f1d85ad..b6a318e0345 100644 --- a/src/coreComponents/common/Format.hpp +++ b/src/coreComponents/common/Format.hpp @@ -95,7 +95,7 @@ struct fmt::formatter< T, std::enable_if_t< std::is_enum< T >::value > > // but later removed: // https://github.com/fmtlib/fmt/commit/466e0650ec2d153d255a40ec230eb77d7f1c3334 // This workaround bypasse the check for a const formatter whenever the foramt context GEOS_FMT_NS::format_context is used -#ifdef GEOS_USE_FMT_CONST_FORMATTER_WORKAROUND +#ifdef GEOS_USE_FMT_CONST_FORMATTER_WORKAROUND // End of the workaround for fmt compilation issues template< > constexpr auto GEOS_FMT_NS::detail::has_const_formatter_impl< GEOS_FMT_NS::format_context >( ... ) -> bool { @@ -104,7 +104,7 @@ constexpr auto GEOS_FMT_NS::detail::has_const_formatter_impl< GEOS_FMT_NS::forma #endif /** - * evaluates at compile time if a fmt::formatter exists for a given type + * Evaluates at compile time if a fmt::formatter exists for a given type */ #if __cplusplus < 202002L template< class T > @@ -115,6 +115,6 @@ concept has_formatter = requires ( T& v, std::format_context ctx ) { std::formatter< std::remove_cvref_t< T > >().format( v, ctx ); }; -#endif // End of the workaround for fmt compilation issues +#endif #endif //GEOS_COMMON_FORMAT_HPP_ From 052f1fa721ec8f238f552205bf8beb6355fff469 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 21 Mar 2024 10:28:01 +0100 Subject: [PATCH 062/216] last correction --- src/coreComponents/common/Format.hpp | 4 ++-- src/coreComponents/mesh/generators/WellGeneratorBase.cpp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/common/Format.hpp b/src/coreComponents/common/Format.hpp index b6a318e0345..80fb6facbf6 100644 --- a/src/coreComponents/common/Format.hpp +++ b/src/coreComponents/common/Format.hpp @@ -95,13 +95,13 @@ struct fmt::formatter< T, std::enable_if_t< std::is_enum< T >::value > > // but later removed: // https://github.com/fmtlib/fmt/commit/466e0650ec2d153d255a40ec230eb77d7f1c3334 // This workaround bypasse the check for a const formatter whenever the foramt context GEOS_FMT_NS::format_context is used -#ifdef GEOS_USE_FMT_CONST_FORMATTER_WORKAROUND // End of the workaround for fmt compilation issues +#ifdef GEOS_USE_FMT_CONST_FORMATTER_WORKAROUND template< > constexpr auto GEOS_FMT_NS::detail::has_const_formatter_impl< GEOS_FMT_NS::format_context >( ... ) -> bool { return true; } -#endif +#endif // End of the workaround for fmt compilation issues /** * Evaluates at compile time if a fmt::formatter exists for a given type diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index f56a5dc72fa..6b3b56eae7c 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -573,7 +573,8 @@ void WellGeneratorBase::logPerforationTable() const tablePerfoData.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); } - TableLayout tableLayoutPerfo ( {"Perforation no.", "Coordinates", "connected to" }, "Perforation table" ); + TableLayout tableLayoutPerfo ( {"Perforation no.", "Coordinates", "connected to"}, + GEOS_FMT( "Well '{}' Perforation Table", getName() ) ); TableTextFormatter tablePerfoLog( tableLayoutPerfo ); GEOS_LOG_RANK_0( tablePerfoLog.toString( tablePerfoData )); } From 838f36ea1c0c52112c228bcb49640ba835762ad6 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 25 Mar 2024 11:04:29 +0100 Subject: [PATCH 063/216] cmake fix --- src/coreComponents/codingUtilities/tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/codingUtilities/tests/CMakeLists.txt b/src/coreComponents/codingUtilities/tests/CMakeLists.txt index 92039f77300..bb5f8eed36c 100644 --- a/src/coreComponents/codingUtilities/tests/CMakeLists.txt +++ b/src/coreComponents/codingUtilities/tests/CMakeLists.txt @@ -3,7 +3,7 @@ set( testSources testGeosxTraits.cpp testStringUtilities.cpp testParsing.cpp - testTable.cpp ) + testTable.cpp testUtilities.cpp ) set( dependencyList gtest codingUtilities ${parallelDeps} ) From 1139117cea99a012cb2b8e84b7229a512bfbe15c Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 25 Mar 2024 11:15:25 +0100 Subject: [PATCH 064/216] test return string --- src/coreComponents/codingUtilities/TableFormatter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index 23266d21c28..ebdada19f9e 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -63,7 +63,7 @@ string_view TableCSVFormatter::headerToString() const return oss.str(); } -string_view TableCSVFormatter::dataToString( TableData const & tableData ) const +string TableCSVFormatter::dataToString( TableData const & tableData ) const { std::vector< std::vector< string > > const rowsValues = tableData.getTableDataRows(); std::ostringstream oss; From 13a6d091f06f1df270da689fbf56c7b0d0a6210f Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 25 Mar 2024 11:21:29 +0100 Subject: [PATCH 065/216] fix hpp --- src/coreComponents/codingUtilities/TableFormatter.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index 56cf1fe4eec..e7cd76d2f89 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -73,7 +73,7 @@ class TableCSVFormatter : public TableFormatter * @param tableData The 1D table data. * @return The CSV string representation of the table data. */ - string_view dataToString( TableData const & tableData ) const; + string dataToString( TableData const & tableData ) const; /** * @return The string with all column names. From cfeec17ae7c22090b5100fd55598b00f9e96bb8f Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 25 Mar 2024 11:30:16 +0100 Subject: [PATCH 066/216] fix error with string_view --- src/coreComponents/codingUtilities/TableFormatter.cpp | 2 +- src/coreComponents/codingUtilities/TableFormatter.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index ebdada19f9e..f030def644a 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -46,7 +46,7 @@ TableCSVFormatter::TableCSVFormatter( TableLayout const & tableLayout ) m_tableLayout = tableLayout; } -string_view TableCSVFormatter::headerToString() const +string TableCSVFormatter::headerToString() const { std::stringstream oss; constexpr string_view separator = ","; diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index e7cd76d2f89..21a6292fc69 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -78,7 +78,7 @@ class TableCSVFormatter : public TableFormatter /** * @return The string with all column names. */ - string_view headerToString() const; + string headerToString() const; }; From f735cd114b2fbc2596248aad6e0e3b041e5cd512 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 25 Mar 2024 14:09:18 +0100 Subject: [PATCH 067/216] uncrustify --- src/coreComponents/common/Format.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/common/Format.hpp b/src/coreComponents/common/Format.hpp index 80fb6facbf6..c6ceee14a56 100644 --- a/src/coreComponents/common/Format.hpp +++ b/src/coreComponents/common/Format.hpp @@ -95,7 +95,7 @@ struct fmt::formatter< T, std::enable_if_t< std::is_enum< T >::value > > // but later removed: // https://github.com/fmtlib/fmt/commit/466e0650ec2d153d255a40ec230eb77d7f1c3334 // This workaround bypasse the check for a const formatter whenever the foramt context GEOS_FMT_NS::format_context is used -#ifdef GEOS_USE_FMT_CONST_FORMATTER_WORKAROUND +#ifdef GEOS_USE_FMT_CONST_FORMATTER_WORKAROUND template< > constexpr auto GEOS_FMT_NS::detail::has_const_formatter_impl< GEOS_FMT_NS::format_context >( ... ) -> bool { @@ -115,6 +115,6 @@ concept has_formatter = requires ( T& v, std::format_context ctx ) { std::formatter< std::remove_cvref_t< T > >().format( v, ctx ); }; -#endif +#endif #endif //GEOS_COMMON_FORMAT_HPP_ From 755805a153d69ae543a479e97fab46b289a1b8df Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 26 Mar 2024 11:02:05 +0100 Subject: [PATCH 068/216] Correction melvin PR --- src/coreComponents/codingUtilities/TableData.hpp | 2 +- src/coreComponents/codingUtilities/TableFormatter.cpp | 7 ++++++- src/coreComponents/codingUtilities/TableFormatter.hpp | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index 03d807ea72f..a56386e2adb 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -106,7 +106,7 @@ void TableData::addRow( Args const &... args ) m_cellsValue.push_back( cellValue ); } (), ...); - m_rows.push_back( m_cellsValue ); + addRow( m_cellsValue ); } template< typename T > diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index f030def644a..3f708a0cf68 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -49,7 +49,7 @@ TableCSVFormatter::TableCSVFormatter( TableLayout const & tableLayout ) string TableCSVFormatter::headerToString() const { std::stringstream oss; - constexpr string_view separator = ","; + static constexpr string_view separator = ","; for( std::size_t idxColumn = 0; idxColumn < m_tableLayout.getColumns().size(); ++idxColumn ) { @@ -83,6 +83,11 @@ string TableCSVFormatter::dataToString( TableData const & tableData ) const return oss.str(); } +string TableCSVFormatter::toString( TableData const & tableData ) const +{ + return headerToString() + dataToString( tableData ); +} + /////////////////////////////////////////////////////////////////////// ////// Log Formatter implementation /////////////////////////////////////////////////////////////////////// diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index 21a6292fc69..a623af6347a 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -80,6 +80,13 @@ class TableCSVFormatter : public TableFormatter */ string headerToString() const; + /** + * @brief Convert the TableData to a table string. + * @param tableData The TableData to convert. + * @return The table string representation of the TableData. + */ + string toString( TableData const & tableData ) const; + }; class TableTextFormatter : public TableFormatter From 6264d87338177f86d04a5994c90da4f0d13e0299 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 27 Mar 2024 22:06:34 +0100 Subject: [PATCH 069/216] correction review PR --- .../codingUtilities/TableFormatter.cpp | 10 ++-- .../codingUtilities/TableFormatter.hpp | 9 ---- .../codingUtilities/TableLayout.hpp | 2 - .../codingUtilities/tests/testTable.cpp | 52 +++++++++---------- .../mesh/generators/WellGeneratorBase.cpp | 14 ++--- 5 files changed, 38 insertions(+), 49 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index 3f708a0cf68..a55c1561323 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -20,10 +20,9 @@ namespace geos { -TableFormatter::TableFormatter( TableLayout const & tableLayout ) -{ - m_tableLayout = tableLayout; -} +TableFormatter::TableFormatter( TableLayout const & tableLayout ): + m_tableLayout( tableLayout ) +{} void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & rows ) const @@ -41,7 +40,8 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column ////// CSV Formatter implementation /////////////////////////////////////////////////////////////////////// -TableCSVFormatter::TableCSVFormatter( TableLayout const & tableLayout ) +TableCSVFormatter::TableCSVFormatter( TableLayout const & tableLayout ): + TableFormatter( tableLayout ) { m_tableLayout = tableLayout; } diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index a623af6347a..dc5f99067a6 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -30,11 +30,6 @@ class TableFormatter { public: - /** - * @brief Constructor by default - */ - TableFormatter() = default; - /** * @brief Construct a new Table Formatter from a tableLayout * @param tableLayout Contain all column names and optionnaly the table title @@ -57,10 +52,6 @@ class TableFormatter class TableCSVFormatter : public TableFormatter { public: - /** - * @brief Constructor by default - */ - TableCSVFormatter() = default; /** * @brief Construct a new Table Formatter from a tableLayout diff --git a/src/coreComponents/codingUtilities/TableLayout.hpp b/src/coreComponents/codingUtilities/TableLayout.hpp index b09c830ee46..cc0981b27f9 100644 --- a/src/coreComponents/codingUtilities/TableLayout.hpp +++ b/src/coreComponents/codingUtilities/TableLayout.hpp @@ -89,8 +89,6 @@ 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 diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 25eed3e0fe8..bd58cc3cf1d 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -28,13 +28,13 @@ TEST( testTable, tableClass ) //table with empty row { - TableLayout tableLayout( {"Well\nelement no.\nPV weighted\nbar", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement"}, - "InternalWellGenerator well_injector1" - ); + TableLayout const tableLayout( {"Well\nelement no.\nPV weighted\nbar", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"}, + "InternalWellGenerator well_injector1" + ); TableData tableData; tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); @@ -42,7 +42,7 @@ TEST( testTable, tableClass ) tableData.addRow( "Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", "[30.21543]", "30.45465142", 787442, 10 ); - TableTextFormatter tableText( tableLayout ); + TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), "\n+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n" @@ -62,18 +62,18 @@ TEST( testTable, tableClass ) //same but with different values { - TableLayout tableLayout( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement"}, "InternalWellGenerator well_injector1" ); + TableLayout const tableLayout( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"}, "InternalWellGenerator well_injector1" ); TableData tableData; tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); tableData.addRow( "", "", "", "", "" ); tableData.addRow( "value23", "[30.21543]", "30.45465142", 787442, 10 ); - TableTextFormatter tableText( tableLayout ); + TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), "\n+---------------------------------------------------------------------------------------------------------------------------------------------------------+\n" "| InternalWellGenerator well_injector1 |\n" @@ -90,7 +90,7 @@ TEST( testTable, tableClass ) //table with TableLayout::ColumnParam { - TableLayout tableLayout( { + TableLayout const tableLayout( { TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::left}, TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::left}, @@ -103,7 +103,7 @@ TEST( testTable, tableClass ) tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - TableTextFormatter tableText( tableLayout ); + TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), "\n+-----------------------------------------------------------------------------------------+\n" "| InternalWellGenerator well_injector1 |\n" @@ -119,7 +119,7 @@ TEST( testTable, tableClass ) //test with hidden column { - TableLayout tableLayout( { + TableLayout const tableLayout( { TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, @@ -132,7 +132,7 @@ TEST( testTable, tableClass ) tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - TableTextFormatter tableText( tableLayout ); + TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), "\n+------------------------------------------------------------------------------------------------------------------+\n" "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" @@ -147,7 +147,7 @@ TEST( testTable, tableClass ) //test with 1 column { - TableLayout tableLayout( { + TableLayout const tableLayout( { TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, }, "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); @@ -155,7 +155,7 @@ TEST( testTable, tableClass ) tableData.addRow( "value1" ); tableData.addRow( "val1" ); - TableTextFormatter tableText( tableLayout ); + TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), "\n+-------------------------------------------------------------------------------------------------------------------+\n" "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" @@ -170,7 +170,7 @@ TEST( testTable, tableClass ) //test without title { - TableLayout tableLayout( { + TableLayout const tableLayout( { TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, @@ -178,13 +178,13 @@ TEST( testTable, tableClass ) TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, } - ); + ); TableData tableData; tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - TableTextFormatter tableText( tableLayout ); + TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" @@ -213,7 +213,7 @@ TEST( testTable, tableClass ) tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - TableTextFormatter tableText( tableLayout ); + TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), "\n+-----------------------------------------------------------------+\n" "| InternalWellGenerator well_injector1 |\n" @@ -229,7 +229,7 @@ TEST( testTable, tableClass ) //test 2D table { - TableLayout tableLayout( {"FakePressure", "Value1", "Value2"} ); + TableLayout const tableLayout( {"FakePressure", "Value1", "Value2"} ); TableData2D tableData; for( real64 p = 10000; p<20000; p+=5000 ) @@ -241,7 +241,7 @@ TEST( testTable, tableClass ) } } - TableTextFormatter tableLog( tableLayout ); + TableTextFormatter const tableLog( tableLayout ); EXPECT_EQ( tableLog.toString( tableData.buildTableData()), "+----------------+----------+------------------------+\n" "| FakePressure | Value1 | Value2 |\n" diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 6b3b56eae7c..4e097dc0a9a 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -144,7 +144,7 @@ void WellGeneratorBase::generateWellGeometry( ) // make sure that the perforation locations are valid checkPerforationLocationsValidity(); - if( getLogLevel() >= 1 && logger::internal::rank == 0 ) + if( getLogLevel() >= 1 && MpiWrapper::commRank() == 0 ) { logInternalWell(); logPerforationTable(); @@ -551,8 +551,8 @@ void WellGeneratorBase::logInternalWell() const nextElement ); } - string wellTitle = GEOS_FMT( "Well '{}' Element Table", getName() ); - TableLayout tableWellLayout = TableLayout( { + string const wellTitle = GEOS_FMT( "Well '{}' Element Table", getName() ); + TableLayout const tableWellLayout = TableLayout( { TableLayout::ColumnParam{"Element no.", TableLayout::Alignment::right}, TableLayout::ColumnParam{"CoordX", TableLayout::Alignment::center}, TableLayout::ColumnParam{"CoordY", TableLayout::Alignment::center}, @@ -561,7 +561,7 @@ void WellGeneratorBase::logInternalWell() const TableLayout::ColumnParam{"Next\nElement", TableLayout::Alignment::right}, }, wellTitle ); - TableTextFormatter tableFormatter( tableWellLayout ); + TableTextFormatter const tableFormatter( tableWellLayout ); GEOS_LOG_RANK_0( tableFormatter.toString( tableWellData )); } @@ -573,9 +573,9 @@ void WellGeneratorBase::logPerforationTable() const tablePerfoData.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); } - TableLayout tableLayoutPerfo ( {"Perforation no.", "Coordinates", "connected to"}, - GEOS_FMT( "Well '{}' Perforation Table", getName() ) ); - TableTextFormatter tablePerfoLog( tableLayoutPerfo ); + TableLayout const tableLayoutPerfo ( {"Perforation no.", "Coordinates", "connected to"}, + GEOS_FMT( "Well '{}' Perforation Table", getName() ) ); + TableTextFormatter const tablePerfoLog( tableLayoutPerfo ); GEOS_LOG_RANK_0( tablePerfoLog.toString( tablePerfoData )); } From 21021c7c65d18eb7522d2a15f8ee8b5048389c23 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 27 Mar 2024 23:30:39 +0100 Subject: [PATCH 070/216] setMargin private --- .../codingUtilities/TableLayout.hpp | 13 +++-- .../codingUtilities/tests/testTable.cpp | 55 ++++++++++--------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableLayout.hpp b/src/coreComponents/codingUtilities/TableLayout.hpp index cc0981b27f9..622a631c5bb 100644 --- a/src/coreComponents/codingUtilities/TableLayout.hpp +++ b/src/coreComponents/codingUtilities/TableLayout.hpp @@ -102,12 +102,6 @@ class TableLayout */ TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title = "" ); - /** - * @brief Set the minimal margin width between row content and borders. - * @param marginType The margin value - */ - void setMargin( MarginValue marginValue ); - /** * @return The columns vector */ @@ -134,6 +128,13 @@ class TableLayout integer const & getMarginTitle() const; private: + + /** + * @brief Set the minimal margin width between row content and borders. + * @param marginType The margin value + */ + void setMargin( MarginValue marginValue ); + std::vector< Column > m_columns; string m_tableTitle; integer m_borderMargin; diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index bd58cc3cf1d..80132e0e49f 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -195,37 +195,38 @@ TEST( testTable, tableClass ) "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" ); } - + + // if setMargin used elsewhere make it public //test with tiny margin - { - TableLayout tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, - }, "InternalWellGenerator well_injector1" ); + // { + // TableLayout tableLayout( { + // TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, + // TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, + // TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, + // TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + // TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, + // TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, + // }, "InternalWellGenerator well_injector1" ); - tableLayout.setMargin( TableLayout::MarginValue::tiny ); + // //tableLayout.setMargin( TableLayout::MarginValue::tiny ); - TableData tableData; - tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + // TableData tableData; + // tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + // tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - TableTextFormatter const tableText( tableLayout ); - EXPECT_EQ( tableText.toString( tableData ), - "\n+-----------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+------------+------+-------------------+---------+-------+-------+\n" - "|Cras egestas|CoordX| C |CoordZ |Prev | Next |\n" - "| | | | |element|element|\n" - "+------------+------+-------------------+---------+-------+-------+\n" - "| value1 | | 3.0 |3.0129877|2 | 1 |\n" - "| val1 | v|[3.045,42.02,89.25]|3 |10 | 3 |\n" - "+------------+------+-------------------+---------+-------+-------+\n\n" - ); - } + // TableTextFormatter const tableText( tableLayout ); + // EXPECT_EQ( tableText.toString( tableData ), + // "\n+-----------------------------------------------------------------+\n" + // "| InternalWellGenerator well_injector1 |\n" + // "+------------+------+-------------------+---------+-------+-------+\n" + // "|Cras egestas|CoordX| C |CoordZ |Prev | Next |\n" + // "| | | | |element|element|\n" + // "+------------+------+-------------------+---------+-------+-------+\n" + // "| value1 | | 3.0 |3.0129877|2 | 1 |\n" + // "| val1 | v|[3.045,42.02,89.25]|3 |10 | 3 |\n" + // "+------------+------+-------------------+---------+-------+-------+\n\n" + // ); + // } //test 2D table { From 3a34e279a96e21fe167070182907829f7e1d11a8 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 27 Mar 2024 23:33:37 +0100 Subject: [PATCH 071/216] uncrustify --- src/coreComponents/codingUtilities/TableLayout.hpp | 2 +- src/coreComponents/codingUtilities/tests/testTable.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableLayout.hpp b/src/coreComponents/codingUtilities/TableLayout.hpp index 622a631c5bb..4034ca3b6c9 100644 --- a/src/coreComponents/codingUtilities/TableLayout.hpp +++ b/src/coreComponents/codingUtilities/TableLayout.hpp @@ -134,7 +134,7 @@ class TableLayout * @param marginType The margin value */ void setMargin( MarginValue marginValue ); - + std::vector< Column > m_columns; string m_tableTitle; integer m_borderMargin; diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/codingUtilities/tests/testTable.cpp index 80132e0e49f..06e82397716 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/codingUtilities/tests/testTable.cpp @@ -195,7 +195,7 @@ TEST( testTable, tableClass ) "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" ); } - + // if setMargin used elsewhere make it public //test with tiny margin // { @@ -208,7 +208,7 @@ TEST( testTable, tableClass ) // TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, // }, "InternalWellGenerator well_injector1" ); - // //tableLayout.setMargin( TableLayout::MarginValue::tiny ); + // //tableLayout.setMargin( TableLayout::MarginValue::tiny ); // TableData tableData; // tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); From 76789ba4f43589d97b5748d9becc59880f52b928 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 28 Mar 2024 09:20:19 +0100 Subject: [PATCH 072/216] remove constructor vector string --- src/coreComponents/codingUtilities/TableFormatter.cpp | 4 ---- src/coreComponents/codingUtilities/TableFormatter.hpp | 2 -- 2 files changed, 6 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/codingUtilities/TableFormatter.cpp index a55c1561323..aac6fccc11a 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/codingUtilities/TableFormatter.cpp @@ -115,10 +115,6 @@ TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): TableFormatter( tableLayout ) {} -TableTextFormatter::TableTextFormatter( std::vector< string > const & columnNames ) - : TableFormatter( TableLayout( columnNames )) -{} - string TableTextFormatter::toString( TableData const & tableData ) const { std::ostringstream tableOutput; diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/codingUtilities/TableFormatter.hpp index dc5f99067a6..06b24dea55b 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/codingUtilities/TableFormatter.hpp @@ -87,8 +87,6 @@ class TableTextFormatter : public TableFormatter TableTextFormatter( TableLayout const & tableLayout ); - TableTextFormatter( std::vector< string > const & columnNames ); - /** * @brief Convert the TableData to a table string. * @param tableData The TableData to convert. From 2d1cded1d8a438f1169c0e934bd4ca520d364049 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 28 Mar 2024 13:45:32 +0100 Subject: [PATCH 073/216] Table Data logs --- src/coreComponents/codingUtilities/TableData.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/codingUtilities/TableData.hpp index a56386e2adb..3bc8fc0f39b 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/codingUtilities/TableData.hpp @@ -66,17 +66,18 @@ class TableData2D public: /** - * @brief Add a cell to the table. - * Construct a map of pair and cell value - * @param T The value passed to addCell (can be any type). + * @brief Add a cell to the table. If necessary, create automatically the containing column & row. + * @tparam T The value passed to addCell (can be any type). * @param value Cell value to be added. + * @param rowValue The value of the row containing the cell. + * @param columnValue The value of the column containing the cell. */ template< typename T > void addCell( real64 rowValue, real64 columnValue, T const & value ); /** - * @brief Construct a TableData from a Table2D - * @return A TableData + * @brief Construct a TableData from the provided cells. + * @return A TableData with all cell values within increasing row & column. The row & columns names */ TableData buildTableData() const; From 8fedfd8f5709cdf6cd96e40fbb3a3d722d5903bf Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 29 Mar 2024 11:32:21 +0100 Subject: [PATCH 074/216] move table to common + pr correction --- src/coreComponents/codingUtilities/CMakeLists.txt | 7 +------ src/coreComponents/codingUtilities/tests/CMakeLists.txt | 1 - src/coreComponents/common/CMakeLists.txt | 6 ++++++ .../{codingUtilities => common}/TableData.cpp | 4 ++-- .../{codingUtilities => common}/TableData.hpp | 2 +- .../{codingUtilities => common}/TableFormatter.cpp | 2 +- .../{codingUtilities => common}/TableFormatter.hpp | 4 ++-- .../{codingUtilities => common}/TableLayout.cpp | 2 +- .../{codingUtilities => common}/TableLayout.hpp | 0 src/coreComponents/common/unitTests/CMakeLists.txt | 1 + .../tests => common/unitTests}/testTable.cpp | 6 +++--- src/coreComponents/mesh/generators/WellGeneratorBase.cpp | 6 +++--- 12 files changed, 21 insertions(+), 20 deletions(-) rename src/coreComponents/{codingUtilities => common}/TableData.cpp (92%) rename src/coreComponents/{codingUtilities => common}/TableData.hpp (97%) rename src/coreComponents/{codingUtilities => common}/TableFormatter.cpp (99%) rename src/coreComponents/{codingUtilities => common}/TableFormatter.hpp (98%) rename src/coreComponents/{codingUtilities => common}/TableLayout.cpp (97%) rename src/coreComponents/{codingUtilities => common}/TableLayout.hpp (100%) rename src/coreComponents/{codingUtilities/tests => common/unitTests}/testTable.cpp (99%) diff --git a/src/coreComponents/codingUtilities/CMakeLists.txt b/src/coreComponents/codingUtilities/CMakeLists.txt index 4ccfa5a2eab..53ee0981125 100644 --- a/src/coreComponents/codingUtilities/CMakeLists.txt +++ b/src/coreComponents/codingUtilities/CMakeLists.txt @@ -9,9 +9,6 @@ set( codingUtilities_headers UnitTestUtilities.hpp Utilities.hpp traits.hpp - TableFormatter.hpp - TableData.hpp - TableLayout.hpp ) # @@ -20,9 +17,7 @@ set( codingUtilities_headers set( codingUtilities_sources Parsing.cpp StringUtilities.cpp - TableFormatter.cpp - TableData.cpp - TableLayout.cpp ) + ) set( dependencyList ${parallelDeps} common fast_float ) diff --git a/src/coreComponents/codingUtilities/tests/CMakeLists.txt b/src/coreComponents/codingUtilities/tests/CMakeLists.txt index bb5f8eed36c..85042471be1 100644 --- a/src/coreComponents/codingUtilities/tests/CMakeLists.txt +++ b/src/coreComponents/codingUtilities/tests/CMakeLists.txt @@ -3,7 +3,6 @@ set( testSources testGeosxTraits.cpp testStringUtilities.cpp testParsing.cpp - testTable.cpp testUtilities.cpp ) set( dependencyList gtest codingUtilities ${parallelDeps} ) diff --git a/src/coreComponents/common/CMakeLists.txt b/src/coreComponents/common/CMakeLists.txt index 5600a8fae85..fc3703b3637 100644 --- a/src/coreComponents/common/CMakeLists.txt +++ b/src/coreComponents/common/CMakeLists.txt @@ -15,6 +15,9 @@ set( common_headers Path.hpp Span.hpp Stopwatch.hpp + TableFormatter.hpp + TableData.hpp + TableLayout.hpp Timer.hpp Tensor.hpp TimingMacros.hpp @@ -43,6 +46,9 @@ set( common_sources Logger.cpp MpiWrapper.cpp Path.cpp + TableFormatter.cpp + TableData.cpp + TableLayout.cpp initializeEnvironment.cpp Units.cpp ) diff --git a/src/coreComponents/codingUtilities/TableData.cpp b/src/coreComponents/common/TableData.cpp similarity index 92% rename from src/coreComponents/codingUtilities/TableData.cpp rename to src/coreComponents/common/TableData.cpp index e70153a56f9..1d29d5ef760 100644 --- a/src/coreComponents/codingUtilities/TableData.cpp +++ b/src/coreComponents/common/TableData.cpp @@ -16,7 +16,7 @@ * @file TableData.cpp */ -#include "codingUtilities/TableData.hpp" +#include "common/TableData.hpp" namespace geos { @@ -54,7 +54,7 @@ TableData TableData2D::buildTableData() const values.push_back( GEOS_FMT( "{}", rowValue ) ); for( real64 const & columnValue : m_columns ) { - std::pair< real64, real64 > id = std::pair< real64, real64 >( rowValue, columnValue ); + std::pair< real64, real64 > id = std::make_pair( rowValue, columnValue ); auto const dataIt = m_data.find( id ); if( dataIt != m_data.end()) diff --git a/src/coreComponents/codingUtilities/TableData.hpp b/src/coreComponents/common/TableData.hpp similarity index 97% rename from src/coreComponents/codingUtilities/TableData.hpp rename to src/coreComponents/common/TableData.hpp index 3bc8fc0f39b..3598a27f1df 100644 --- a/src/coreComponents/codingUtilities/TableData.hpp +++ b/src/coreComponents/common/TableData.hpp @@ -114,7 +114,7 @@ template< typename T > void TableData2D::addCell( real64 const rowValue, real64 const columnValue, T const & value ) { static_assert( has_formatter< decltype(value) >, "Argument passed in addCell cannot be converted to string" ); - std::pair< real64, real64 > const id = std::pair< real64, real64 >( rowValue, columnValue ); + std::pair< real64, real64 > const id = std::make_pair( rowValue, columnValue ); m_data[id] = GEOS_FMT( "{}", value ); m_columns.insert( columnValue ); m_rows.insert( rowValue ); diff --git a/src/coreComponents/codingUtilities/TableFormatter.cpp b/src/coreComponents/common/TableFormatter.cpp similarity index 99% rename from src/coreComponents/codingUtilities/TableFormatter.cpp rename to src/coreComponents/common/TableFormatter.cpp index aac6fccc11a..57479bfbfd4 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.cpp +++ b/src/coreComponents/common/TableFormatter.cpp @@ -16,7 +16,7 @@ * @file TableFormatter.cpp */ -#include "codingUtilities/TableFormatter.hpp" +#include "common/TableFormatter.hpp" namespace geos { diff --git a/src/coreComponents/codingUtilities/TableFormatter.hpp b/src/coreComponents/common/TableFormatter.hpp similarity index 98% rename from src/coreComponents/codingUtilities/TableFormatter.hpp rename to src/coreComponents/common/TableFormatter.hpp index 06b24dea55b..33d82e73898 100644 --- a/src/coreComponents/codingUtilities/TableFormatter.hpp +++ b/src/coreComponents/common/TableFormatter.hpp @@ -19,8 +19,8 @@ #ifndef GEOS_COMMON_TABLEFORMATTER_HPP #define GEOS_COMMON_TABLEFORMATTER_HPP -#include "codingUtilities/TableData.hpp" -#include "codingUtilities/TableLayout.hpp" +#include "common/TableData.hpp" +#include "common/TableLayout.hpp" namespace geos { diff --git a/src/coreComponents/codingUtilities/TableLayout.cpp b/src/coreComponents/common/TableLayout.cpp similarity index 97% rename from src/coreComponents/codingUtilities/TableLayout.cpp rename to src/coreComponents/common/TableLayout.cpp index 4fae15ffaca..abd9c6818ba 100644 --- a/src/coreComponents/codingUtilities/TableLayout.cpp +++ b/src/coreComponents/common/TableLayout.cpp @@ -16,7 +16,7 @@ * @file TableData.hpp */ -#include "codingUtilities/TableLayout.hpp" +#include "common/TableLayout.hpp" namespace geos { diff --git a/src/coreComponents/codingUtilities/TableLayout.hpp b/src/coreComponents/common/TableLayout.hpp similarity index 100% rename from src/coreComponents/codingUtilities/TableLayout.hpp rename to src/coreComponents/common/TableLayout.hpp diff --git a/src/coreComponents/common/unitTests/CMakeLists.txt b/src/coreComponents/common/unitTests/CMakeLists.txt index 814fd512cec..08932fb1b1d 100644 --- a/src/coreComponents/common/unitTests/CMakeLists.txt +++ b/src/coreComponents/common/unitTests/CMakeLists.txt @@ -4,6 +4,7 @@ set( gtest_geosx_tests testFixedSizeDeque.cpp testTypeDispatch.cpp testLifoStorage.cpp + testTable.cpp testUnits.cpp ) if ( ENABLE_CALIPER ) diff --git a/src/coreComponents/codingUtilities/tests/testTable.cpp b/src/coreComponents/common/unitTests/testTable.cpp similarity index 99% rename from src/coreComponents/codingUtilities/tests/testTable.cpp rename to src/coreComponents/common/unitTests/testTable.cpp index 06e82397716..4aa91589582 100644 --- a/src/coreComponents/codingUtilities/tests/testTable.cpp +++ b/src/coreComponents/common/unitTests/testTable.cpp @@ -13,9 +13,9 @@ */ // Source includes -#include "codingUtilities/TableData.hpp" -#include "codingUtilities/TableFormatter.hpp" -#include "codingUtilities/TableLayout.hpp" +#include "common/TableData.hpp" +#include "common/TableFormatter.hpp" +#include "common/TableLayout.hpp" #include "dataRepository/Group.hpp" // TPL includes #include diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 4e097dc0a9a..21bf4f79889 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -17,9 +17,9 @@ #include "mesh/Perforation.hpp" #include "mesh/generators/LineBlockABC.hpp" #include "LvArray/src/genericTensorOps.hpp" -#include "codingUtilities/TableLayout.hpp" -#include "codingUtilities/TableData.hpp" -#include "codingUtilities/TableFormatter.hpp" +#include "common/TableLayout.hpp" +#include "common/TableData.hpp" +#include "common/TableFormatter.hpp" #include "common/Format.hpp" namespace geos { From 13f975a4e43fc9ee961eb86359cdaa9c6d517691 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 29 Mar 2024 13:59:09 +0100 Subject: [PATCH 075/216] correction from merging --- .../CO2Brine/functions/CO2Solubility.cpp | 1 - .../functions/TableFunction.cpp | 24 +++++++++---------- .../testCO2SpycherPruessModels.cpp | 1 + 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp index f991175ee3f..af64d0be3c3 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp @@ -257,7 +257,6 @@ CO2Solubility::CO2Solubility( string const & name, std::tie( m_CO2SolubilityTable, m_WaterVapourisationTable ) = makeSolubilityTables( m_modelName, inputParams, solubilityModel ); - checkPrint( m_CO2SolubilityTable, printInCsv, printInLog ); checkPrint( m_WaterVapourisationTable, printInCsv, printInLog ); diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 4b44651a929..9a4bf3732e8 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -20,9 +20,9 @@ #include "codingUtilities/Parsing.hpp" #include "common/DataTypes.hpp" #include "fileIO/Outputs/OutputBase.hpp" -#include "codingUtilities/TableLayout.hpp" -#include "codingUtilities/TableData.hpp" -#include "codingUtilities/TableFormatter.hpp" +#include "common/TableLayout.hpp" +#include "common/TableData.hpp" +#include "common/TableFormatter.hpp" #include @@ -254,7 +254,7 @@ void TableFunction::printInCSV( string const & filename ) const string description = string( units::getDescription( getDimUnit( 1 ))) + "=" + std::to_string( coordsY[idxY] ); columnNames.push_back( description ); } - TableLayout tableLayout( columnNames ); + TableLayout const tableLayout( columnNames ); TableCSVFormatter csvFormat( tableLayout ); os << csvFormat.headerToString(); @@ -283,13 +283,13 @@ void TableFunction::printInLog( string const & filename ) const tableData.addRow( coords[idx], m_values[idx] ); } - TableLayout tableLayout( { + TableLayout const tableLayout( { string( units::getDescription( getDimUnit( 0 ))), string( units::getDescription( m_valueUnit )) }, filename ); - TableTextFormatter logTable( tableLayout ); - GEOS_LOG_RANK_0( logTable.ToString( tableData )); + TableTextFormatter const logTable( tableLayout ); + GEOS_LOG_RANK_0( logTable.toString( tableData )); } else if( numDimensions == 2 ) { @@ -321,20 +321,20 @@ void TableFunction::printInLog( string const & filename ) const string description = string( units::getDescription( getDimUnit( 1 ))) + "=" + std::to_string( coordsY[idxY] ); vecDescription.push_back( description ); } - TableLayout tableLayout( vecDescription, filename ); + TableLayout const tableLayout( vecDescription, filename ); //3. log - TableTextFormatter table2DLog( tableLayout ); - GEOS_LOG_RANK_0( table2DLog.ToString( tableData2D.buildTableData() )); + TableTextFormatter const table2DLog( tableLayout ); + GEOS_LOG_RANK_0( table2DLog.toString( tableData2D.buildTableData() )); } else { //2. format string log = GEOS_FMT( "The {} PVT table exceeding 500 rows.\nTo visualize the tables, go to the generated csv \n", filename ); - TableLayout tableLayoutInfos( {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}}, filename ); + TableLayout const tableLayoutInfos( {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}}, filename ); //3. log - TableTextFormatter tableLog( tableLayoutInfos ); + TableTextFormatter const tableLog( tableLayoutInfos ); GEOS_LOG_RANK_0( tableLog.layoutToString() ); } } diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp index 7a248a4007b..95e5b003ec8 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp @@ -87,6 +87,7 @@ CO2SolubilitySpycherPruessTestFixture::makeFlashModel( string const & fileConten phaseNames, componentNames, componentMolarWeight, + false, false ); } From f7dbdcf7197b04d19bcb6079980e5982f3e397b1 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 29 Mar 2024 14:51:14 +0100 Subject: [PATCH 076/216] minor correction --- src/coreComponents/common/TableFormatter.cpp | 12 ++++++------ src/coreComponents/common/TableFormatter.hpp | 2 +- src/coreComponents/common/TableLayout.cpp | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/coreComponents/common/TableFormatter.cpp b/src/coreComponents/common/TableFormatter.cpp index 57479bfbfd4..8549ac87d13 100644 --- a/src/coreComponents/common/TableFormatter.cpp +++ b/src/coreComponents/common/TableFormatter.cpp @@ -27,9 +27,9 @@ TableFormatter::TableFormatter( TableLayout const & tableLayout ): void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & rows ) const { - for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) + for( size_t idxRow = 0; idxRow < rows.size(); ++idxRow ) { - for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) + for( size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { columns[idxColumn].columnValues.push_back( rows[idxRow][idxColumn] ); } @@ -195,7 +195,7 @@ void TableTextFormatter::adjustHeaderSizesAndStore( std::vector< TableLayout::Co size_t const & largestHeaderVectorSize, std::vector< std::vector< string > > & splitHeader ) const { - for( size_t columnParamIdx = 0; columnParamIdx < columns.size(); columnParamIdx++ ) + for( size_t columnParamIdx = 0; columnParamIdx < columns.size(); ++columnParamIdx ) { if( splitHeader[columnParamIdx].size() < largestHeaderVectorSize ) { @@ -219,7 +219,7 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu } ); maxStringSize = *it; - for( size_t idxRow = 0; idxRow < nbRows; idxRow++ ) + for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) { string cell = column.columnValues[idxRow]; @@ -332,7 +332,7 @@ void TableTextFormatter::buildTitleRow( string & titleRows, titleRows += GEOS_FMT( "{}\n", "|" ); } -void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > & columns, +void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > const & columns, string_view sectionSeparator, std::ostringstream & tableRows, integer const nbRows, @@ -341,7 +341,7 @@ void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > & integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); - for( integer idxRow = 0; idxRow< nbRows; idxRow++ ) + for( integer idxRow = 0; idxRow< nbRows; ++idxRow ) { tableRows << GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) diff --git a/src/coreComponents/common/TableFormatter.hpp b/src/coreComponents/common/TableFormatter.hpp index 33d82e73898..873d754e19e 100644 --- a/src/coreComponents/common/TableFormatter.hpp +++ b/src/coreComponents/common/TableFormatter.hpp @@ -172,7 +172,7 @@ class TableTextFormatter : public TableFormatter * @param nbRows Indicates the number of lines in a section * @param section The section to be built */ - void buildSectionRows( std::vector< TableLayout::Column > & columns, + void buildSectionRows( std::vector< TableLayout::Column > const & columns, string_view sectionSeparator, std::ostringstream & rows, integer const nbRows, diff --git a/src/coreComponents/common/TableLayout.cpp b/src/coreComponents/common/TableLayout.cpp index abd9c6818ba..3b4d84ddf2d 100644 --- a/src/coreComponents/common/TableLayout.cpp +++ b/src/coreComponents/common/TableLayout.cpp @@ -25,7 +25,7 @@ TableLayout::TableLayout( std::vector< string > const & headers, string const & m_tableTitle( title ) { setMargin( MarginValue::medium ); - for( size_t idx = 0; idx< headers.size(); idx++ ) + for( size_t idx = 0; idx< headers.size(); ++idx ) { m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::right, true}, {}, ""} ); } @@ -36,7 +36,7 @@ TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter, st { setMargin( MarginValue::medium ); - for( size_t idx = 0; idx< columnParameter.size(); idx++ ) + for( size_t idx = 0; idx< columnParameter.size(); ++idx ) { if( columnParameter[idx].enabled ) { From 4f34fc24f556381077072402020b9d16df1c28c5 Mon Sep 17 00:00:00 2001 From: MelReyCG <122801580+MelReyCG@users.noreply.github.com> Date: Tue, 2 Apr 2024 15:57:41 +0200 Subject: [PATCH 077/216] gracefully breaking your code :) - make this work - check which methods can be private - move every table class to fileIO --- src/coreComponents/common/TableData.cpp | 40 +++++++++++++------ src/coreComponents/common/TableData.hpp | 24 +++++------ src/coreComponents/common/TableLayout.cpp | 8 ++-- src/coreComponents/common/TableLayout.hpp | 4 +- .../functions/TableFunction.cpp | 13 +++--- 5 files changed, 50 insertions(+), 39 deletions(-) diff --git a/src/coreComponents/common/TableData.cpp b/src/coreComponents/common/TableData.cpp index 1d29d5ef760..1e0cbb7fe11 100644 --- a/src/coreComponents/common/TableData.cpp +++ b/src/coreComponents/common/TableData.cpp @@ -45,26 +45,40 @@ std::set< real64 > const & TableData2D::getRows() const return m_rows; } -TableData TableData2D::buildTableData() const +TableData TableData2D::buildTableData( std::vector< string > & columnNames, + string_view rowFmt, string_view columnFmt ) const { TableData tableDataToBeBuilt; - for( real64 const & rowValue : m_rows ) - { - std::vector< string > values; - values.push_back( GEOS_FMT( "{}", rowValue ) ); - for( real64 const & columnValue : m_columns ) - { - std::pair< real64, real64 > id = std::make_pair( rowValue, columnValue ); - auto const dataIt = m_data.find( id ); + std::set< real64 > columnValues; - if( dataIt != m_data.end()) + { // insert row value and row cell values + std::vector< string > currentRowValues; + RowType currentRow = m_data.begin()->first.first; + currentRowValues.push_back( GEOS_FMT( rowFmt, currentRow ) ); + for( auto const & [rowColumnPair, cellValue] : m_data ) + { + if( rowColumnPair.first == currentRow ) { - values.push_back( GEOS_FMT( "{}", dataIt->second )); + currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); + columnValues.insert( rowColumnPair.second ); + } + else // we are changing line + { + tableDataToBeBuilt.addRow( currentRowValues ); + currentRowValues.clear(); + currentRowValues.push_back( GEOS_FMT( rowFmt, currentRow ) ); + firstRow = false; } - } - tableDataToBeBuilt.addRow( values ); } + + // fill columnNames + std::transform( columnValues.begin(), columnValues.end(), + std::back_inserter( columnValues, columnValues.begin() ), + [&] ( real64 const columnValue ) { + return GEOS_FMT( columnFmt, columnValue ); + } ); + return tableDataToBeBuilt; } diff --git a/src/coreComponents/common/TableData.hpp b/src/coreComponents/common/TableData.hpp index 3598a27f1df..9eab003a2af 100644 --- a/src/coreComponents/common/TableData.hpp +++ b/src/coreComponents/common/TableData.hpp @@ -79,7 +79,8 @@ class TableData2D * @brief Construct a TableData from the provided cells. * @return A TableData with all cell values within increasing row & column. The row & columns names */ - TableData buildTableData() const; + TableData buildTableData( std::vector< string > & columnNames, + string_view rowFmt = "{{}}", string_view columnFmt = "{{}}" ) const; /** * @return return all columns values for 2D table @@ -92,9 +93,11 @@ class TableData2D std::set< real64 > const & getRows() const; private: - std::map< std::pair< real64, real64 >, string > m_data; - std::set< real64 > m_columns; - std::set< real64 > m_rows; + using RowType = real64; + using ColumnType = real64; + + /// @brief all cell values by their [ row, column ] + std::map< std::pair< RowType, ColumnType >, string > m_data; }; template< typename ... Args > @@ -102,10 +105,10 @@ void TableData::addRow( Args const &... args ) { std::vector< string > m_cellsValue; ( [&] { - static_assert( has_formatter< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); - string const cellValue = GEOS_FMT( "{}", args ); - m_cellsValue.push_back( cellValue ); - } (), ...); + static_assert( has_formatter< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); + string const cellValue = GEOS_FMT( "{}", args ); + m_cellsValue.push_back( cellValue ); + } (), ...); addRow( m_cellsValue ); } @@ -114,10 +117,7 @@ template< typename T > void TableData2D::addCell( real64 const rowValue, real64 const columnValue, T const & value ) { static_assert( has_formatter< decltype(value) >, "Argument passed in addCell cannot be converted to string" ); - std::pair< real64, real64 > const id = std::make_pair( rowValue, columnValue ); - m_data[id] = GEOS_FMT( "{}", value ); - m_columns.insert( columnValue ); - m_rows.insert( rowValue ); + m_data[rowValue][columnValue] = GEOS_FMT( "{}", value ); } } diff --git a/src/coreComponents/common/TableLayout.cpp b/src/coreComponents/common/TableLayout.cpp index abd9c6818ba..6606313f90e 100644 --- a/src/coreComponents/common/TableLayout.cpp +++ b/src/coreComponents/common/TableLayout.cpp @@ -21,22 +21,22 @@ namespace geos { -TableLayout::TableLayout( std::vector< string > const & headers, string const & title ): +TableLayout::TableLayout( std::initializer_list< string > const & headers, string const & title ): m_tableTitle( title ) { setMargin( MarginValue::medium ); - for( size_t idx = 0; idx< headers.size(); idx++ ) + for( size_t idx = 0; idx< headers.size(); idx++ ) // foreach! { m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::right, true}, {}, ""} ); } } -TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title ): +TableLayout::TableLayout( std::initializer_list< ColumnParam > const & columnParameter, string const & title ): m_tableTitle( title ) { setMargin( MarginValue::medium ); - for( size_t idx = 0; idx< columnParameter.size(); idx++ ) + for( size_t idx = 0; idx< columnParameter.size(); idx++ ) // foreach! { if( columnParameter[idx].enabled ) { diff --git a/src/coreComponents/common/TableLayout.hpp b/src/coreComponents/common/TableLayout.hpp index 4034ca3b6c9..93ad87d3796 100644 --- a/src/coreComponents/common/TableLayout.hpp +++ b/src/coreComponents/common/TableLayout.hpp @@ -93,14 +93,14 @@ class TableLayout * @brief Construct a new Table object, all values in the table are centered by default * @param columnNames The names of the columns */ - TableLayout( std::vector< string > const & columnNames, string const & title = "" ); + TableLayout( std::initializer_list< string > const & columnNames, string const & title = "" ); /** * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels * level * @param columnParameter List of structures to set up each colum parameters. */ - TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title = "" ); + TableLayout( std::initializer_list< ColumnParam > const & columnParameter, string const & title = "" ); /** * @return The columns vector diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 9a4bf3732e8..8c045c3c347 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -237,23 +237,20 @@ void TableFunction::printInCSV( string const & filename ) const arraySlice1d< real64 const > const coordsY = m_coordinates[1]; integer const nX = coordsX.size(); integer const nY = coordsY.size(); - std::vector< string > columnNames; TableData2D tableData2D; for( integer i = 0; i < nX; i++ ) { for( integer y = 0; y < nY; y++ ) { - tableData2D.addCell( coordsX[i], y, m_values[ y*nX + i ] ); + tableData2D.addCell( coordsX[i], coordsY[y], m_values[ y*nX + i ] ); } } - columnNames.push_back( string( units::getDescription( getDimUnit( 0 )))); - for( integer idxY = 0; idxY < nY; idxY++ ) - { - string description = string( units::getDescription( getDimUnit( 1 ))) + "=" + std::to_string( coordsY[idxY] ); - columnNames.push_back( description ); - } + std::set< string > columnNames; + string const rowFmt = GEOS_FMT( "{} = {{}}", units::getDescription( getDimUnit( 0 ) ) ); + string const columnFmt = GEOS_FMT( "{} = {{}}", units::getDescription( getDimUnit( 1 ) ) ); + TableData tableData = tableData2D.buildTableData( columnNames, rowFmt, columnFmt ); TableLayout const tableLayout( columnNames ); TableCSVFormatter csvFormat( tableLayout ); From 1cb2cc0053438f88d570c89c23d78b57f8be114d Mon Sep 17 00:00:00 2001 From: MelReyCG <122801580+MelReyCG@users.noreply.github.com> Date: Tue, 2 Apr 2024 16:59:22 +0200 Subject: [PATCH 078/216] improving proposal + added TODOs --- src/coreComponents/common/TableData.cpp | 39 ++++++++------------ src/coreComponents/common/TableData.hpp | 4 +- src/coreComponents/common/TableFormatter.cpp | 4 ++ src/coreComponents/common/TableFormatter.hpp | 1 + 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/coreComponents/common/TableData.cpp b/src/coreComponents/common/TableData.cpp index 1e0cbb7fe11..b65c01be1ef 100644 --- a/src/coreComponents/common/TableData.cpp +++ b/src/coreComponents/common/TableData.cpp @@ -49,36 +49,27 @@ TableData TableData2D::buildTableData( std::vector< string > & columnNames, string_view rowFmt, string_view columnFmt ) const { TableData tableDataToBeBuilt; - std::set< real64 > columnValues; - { // insert row value and row cell values + // looping over first line to fill columnNames + columnNames.clear(); + for( auto const & [columnValue, GEOS_UNUSED_VAR( cellValue )] : m_data.begin()->second ) + { + columnNames.push_back( GEOS_FMT( columnFmt, columnValue ) ); + ++columnCount; + } + + // insert row value and row cell values + for( auto const & [rowValue, rowMap] : m_data ) + { std::vector< string > currentRowValues; - RowType currentRow = m_data.begin()->first.first; - currentRowValues.push_back( GEOS_FMT( rowFmt, currentRow ) ); - for( auto const & [rowColumnPair, cellValue] : m_data ) + currentRowValues.push_back( GEOS_FMT( rowFmt, rowValue ) ); + for( auto const & [columnValue, cellValue] : m_data ) { - if( rowColumnPair.first == currentRow ) - { - currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); - columnValues.insert( rowColumnPair.second ); - } - else // we are changing line - { - tableDataToBeBuilt.addRow( currentRowValues ); - currentRowValues.clear(); - currentRowValues.push_back( GEOS_FMT( rowFmt, currentRow ) ); - firstRow = false; - } + currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); } + tableDataToBeBuilt.addRow( currentRowValues ); } - // fill columnNames - std::transform( columnValues.begin(), columnValues.end(), - std::back_inserter( columnValues, columnValues.begin() ), - [&] ( real64 const columnValue ) { - return GEOS_FMT( columnFmt, columnValue ); - } ); - return tableDataToBeBuilt; } diff --git a/src/coreComponents/common/TableData.hpp b/src/coreComponents/common/TableData.hpp index 9eab003a2af..f73da4e0fd5 100644 --- a/src/coreComponents/common/TableData.hpp +++ b/src/coreComponents/common/TableData.hpp @@ -96,8 +96,8 @@ class TableData2D using RowType = real64; using ColumnType = real64; - /// @brief all cell values by their [ row, column ] - std::map< std::pair< RowType, ColumnType >, string > m_data; + /// @brief all cell values by their [ row ][ column ] + std::map< RowType, std::map< ColumnType, string > > m_data; }; template< typename ... Args > diff --git a/src/coreComponents/common/TableFormatter.cpp b/src/coreComponents/common/TableFormatter.cpp index 57479bfbfd4..76bdf1a93dd 100644 --- a/src/coreComponents/common/TableFormatter.cpp +++ b/src/coreComponents/common/TableFormatter.cpp @@ -27,8 +27,11 @@ TableFormatter::TableFormatter( TableLayout const & tableLayout ): void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & rows ) const { + //TODO : reserve for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) { + //TODO : reserve + //TODO : if rows[idxRow].size()!=columns.size() ERROR/THROW/WARNING/ignore for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) { columns[idxColumn].columnValues.push_back( rows[idxRow][idxColumn] ); @@ -70,6 +73,7 @@ string TableCSVFormatter::dataToString( TableData const & tableData ) const for( const auto & row : rowsValues ) { + //TODO : if row.size()!=tableLayout.columnsCount ERROR/THROW/WARNING/ignore for( size_t idxColumn = 0; idxColumn < row.size(); ++idxColumn ) { oss << row[idxColumn]; diff --git a/src/coreComponents/common/TableFormatter.hpp b/src/coreComponents/common/TableFormatter.hpp index 33d82e73898..b25210651e7 100644 --- a/src/coreComponents/common/TableFormatter.hpp +++ b/src/coreComponents/common/TableFormatter.hpp @@ -96,6 +96,7 @@ class TableTextFormatter : public TableFormatter /** * @brief Converts a TableLayout into a formatted string representation. + * Allows to print only the header of the Table. * @return string */ string layoutToString() const; From 615a16db0f01cb34a509578bf7730368f928daff Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 3 Apr 2024 17:30:07 +0200 Subject: [PATCH 079/216] Refactor conversion TableData2 => TableData1D --- src/coreComponents/common/TableData.cpp | 30 ++++++---------- src/coreComponents/common/TableData.hpp | 34 +++++++++---------- src/coreComponents/common/TableLayout.cpp | 16 ++++----- src/coreComponents/common/TableLayout.hpp | 4 +-- .../common/unitTests/testTable.cpp | 28 +++++++++------ .../functions/TableFunction.cpp | 29 ++++++++-------- 6 files changed, 69 insertions(+), 72 deletions(-) diff --git a/src/coreComponents/common/TableData.cpp b/src/coreComponents/common/TableData.cpp index b65c01be1ef..4ac421ef2c9 100644 --- a/src/coreComponents/common/TableData.cpp +++ b/src/coreComponents/common/TableData.cpp @@ -36,26 +36,17 @@ std::vector< std::vector< string > > const & TableData::getTableDataRows() const return m_rows; } -std::set< real64 > const & TableData2D::getColumns() const +TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, + string_view rowFmt, + string_view columnFmt ) const { - return m_columns; -} -std::set< real64 > const & TableData2D::getRows() const -{ - return m_rows; -} - -TableData TableData2D::buildTableData( std::vector< string > & columnNames, - string_view rowFmt, string_view columnFmt ) const -{ - TableData tableDataToBeBuilt; + TableData2D::Conversion1D tableData1D; + tableData1D.headerNames.push_back( string( targetUnit ) ); // looping over first line to fill columnNames - columnNames.clear(); - for( auto const & [columnValue, GEOS_UNUSED_VAR( cellValue )] : m_data.begin()->second ) + for( auto const & [ columnValue, cellValue] : m_data.begin()->second ) { - columnNames.push_back( GEOS_FMT( columnFmt, columnValue ) ); - ++columnCount; + tableData1D.headerNames.push_back( GEOS_FMT( columnFmt, columnValue ) ); } // insert row value and row cell values @@ -63,14 +54,15 @@ TableData TableData2D::buildTableData( std::vector< string > & columnNames, { std::vector< string > currentRowValues; currentRowValues.push_back( GEOS_FMT( rowFmt, rowValue ) ); - for( auto const & [columnValue, cellValue] : m_data ) + for( auto const & [columnValue, cellValue] : rowMap ) { currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); + // TODO : if columnValue[i] != headerNames[i] error/warning/drop/ignore } - tableDataToBeBuilt.addRow( currentRowValues ); + tableData1D.tableData.addRow( currentRowValues ); } - return tableDataToBeBuilt; + return tableData1D; } } diff --git a/src/coreComponents/common/TableData.hpp b/src/coreComponents/common/TableData.hpp index f73da4e0fd5..3a87f3a8574 100644 --- a/src/coreComponents/common/TableData.hpp +++ b/src/coreComponents/common/TableData.hpp @@ -65,6 +65,12 @@ class TableData2D { public: + struct Conversion1D + { + std::vector< string > headerNames; + TableData tableData; + }; + /** * @brief Add a cell to the table. If necessary, create automatically the containing column & row. * @tparam T The value passed to addCell (can be any type). @@ -77,20 +83,14 @@ class TableData2D /** * @brief Construct a TableData from the provided cells. - * @return A TableData with all cell values within increasing row & column. The row & columns names - */ - TableData buildTableData( std::vector< string > & columnNames, - string_view rowFmt = "{{}}", string_view columnFmt = "{{}}" ) const; - - /** - * @return return all columns values for 2D table - */ - std::set< real64 > const & getColumns() const; - - /** - * @return return all rows values for 2D table + * @param targetUnit The table unit + * @param rowFmt The y axis units of the table. + * @param columnFmt The x axis units of the table. + * The axis units can be customize, I.E with targetUnits = pressure [K]: + * GEOS_FMT( "{} = {{}}", targetUnits) => "pressure [K] = {}" + * @return A struct containing The columnNames and the TableData */ - std::set< real64 > const & getRows() const; + Conversion1D buildTableData( string_view targetUnit, string_view rowFmt = "{{}}", string_view columnFmt = "{{}}" ) const; private: using RowType = real64; @@ -105,10 +105,10 @@ void TableData::addRow( Args const &... args ) { std::vector< string > m_cellsValue; ( [&] { - static_assert( has_formatter< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); - string const cellValue = GEOS_FMT( "{}", args ); - m_cellsValue.push_back( cellValue ); - } (), ...); + static_assert( has_formatter< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); + string const cellValue = GEOS_FMT( "{}", args ); + m_cellsValue.push_back( cellValue ); + } (), ...); addRow( m_cellsValue ); } diff --git a/src/coreComponents/common/TableLayout.cpp b/src/coreComponents/common/TableLayout.cpp index 6606313f90e..734d8102b63 100644 --- a/src/coreComponents/common/TableLayout.cpp +++ b/src/coreComponents/common/TableLayout.cpp @@ -21,28 +21,26 @@ namespace geos { -TableLayout::TableLayout( std::initializer_list< string > const & headers, string const & title ): +TableLayout::TableLayout( std::vector< string > const & headers, string const & title ): m_tableTitle( title ) { setMargin( MarginValue::medium ); - for( size_t idx = 0; idx< headers.size(); idx++ ) // foreach! + for( auto const & columnHeader : headers ) { - m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::right, true}, {}, ""} ); + m_columns.push_back( {TableLayout::ColumnParam{{columnHeader}, Alignment::right, true}, {}, ""} ); } } -TableLayout::TableLayout( std::initializer_list< ColumnParam > const & columnParameter, string const & title ): +TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameters, string const & title ): m_tableTitle( title ) { setMargin( MarginValue::medium ); - - for( size_t idx = 0; idx< columnParameter.size(); idx++ ) // foreach! + for( auto const & columnParameter : columnParameters ) { - if( columnParameter[idx].enabled ) + if( columnParameter.enabled ) { - m_columns.push_back( {columnParameter[idx], {}, ""} ); + m_columns.push_back( {columnParameter, {}, ""} ); } - } } diff --git a/src/coreComponents/common/TableLayout.hpp b/src/coreComponents/common/TableLayout.hpp index 93ad87d3796..4034ca3b6c9 100644 --- a/src/coreComponents/common/TableLayout.hpp +++ b/src/coreComponents/common/TableLayout.hpp @@ -93,14 +93,14 @@ class TableLayout * @brief Construct a new Table object, all values in the table are centered by default * @param columnNames The names of the columns */ - TableLayout( std::initializer_list< string > const & columnNames, string const & title = "" ); + TableLayout( std::vector< string > const & columnNames, string const & title = "" ); /** * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels * level * @param columnParameter List of structures to set up each colum parameters. */ - TableLayout( std::initializer_list< ColumnParam > const & columnParameter, string const & title = "" ); + TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title = "" ); /** * @return The columns vector diff --git a/src/coreComponents/common/unitTests/testTable.cpp b/src/coreComponents/common/unitTests/testTable.cpp index 4aa91589582..c6edd86881b 100644 --- a/src/coreComponents/common/unitTests/testTable.cpp +++ b/src/coreComponents/common/unitTests/testTable.cpp @@ -230,7 +230,7 @@ TEST( testTable, tableClass ) //test 2D table { - TableLayout const tableLayout( {"FakePressure", "Value1", "Value2"} ); + //collect TableData2D tableData; for( real64 p = 10000; p<20000; p+=5000 ) @@ -242,17 +242,25 @@ TEST( testTable, tableClass ) } } + //convert + string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + TableData2D::Conversion1D tableconverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + + //format + TableLayout const tableLayout( tableconverted.headerNames ); + + //log TableTextFormatter const tableLog( tableLayout ); - EXPECT_EQ( tableLog.toString( tableData.buildTableData()), - "+----------------+----------+------------------------+\n" - "| FakePressure | Value1 | Value2 |\n" - "+----------------+----------+------------------------+\n" - "| 300 | 0.03 | 0.02 |\n" - "| 350 | 0.035 | 0.023333333333333334 |\n" - "| 400 | 0.04 | 0.02666666666666667 |\n" - "+----------------+----------+------------------------+\n\n" + EXPECT_EQ( tableLog.toString( tableconverted.tableData ), + "+---------------------+--------------------+------------------------+\n" + "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" + "+---------------------+--------------------+------------------------+\n" + "| Temperature = 300 | 0.03 | 0.02 |\n" + "| Temperature = 350 | 0.035 | 0.023333333333333334 |\n" + "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" + "+---------------------+--------------------+------------------------+\n\n" ); - } } diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 8c045c3c347..746a72749ca 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -246,23 +246,23 @@ void TableFunction::printInCSV( string const & filename ) const tableData2D.addCell( coordsX[i], coordsY[y], m_values[ y*nX + i ] ); } } - - std::set< string > columnNames; string const rowFmt = GEOS_FMT( "{} = {{}}", units::getDescription( getDimUnit( 0 ) ) ); string const columnFmt = GEOS_FMT( "{} = {{}}", units::getDescription( getDimUnit( 1 ) ) ); - TableData tableData = tableData2D.buildTableData( columnNames, rowFmt, columnFmt ); - TableLayout const tableLayout( columnNames ); + TableData2D::Conversion1D const tableConverted = tableData2D.buildTableData( string( units::getDescription( m_valueUnit )), + rowFmt, + columnFmt ); + TableLayout const tableLayout( tableConverted.headerNames ); TableCSVFormatter csvFormat( tableLayout ); + os << csvFormat.headerToString(); - os << csvFormat.dataToString( tableData2D.buildTableData() ); + os << csvFormat.dataToString( tableConverted.tableData ); } os.close(); } void TableFunction::printInLog( string const & filename ) const { - integer const numDimensions = LvArray::integerConversion< integer >( m_coordinates.size() ); std::cout << GEOS_FMT( "CSV Generated to inputFiles/compositionalMultiphaseWell/{}/{}.csv \n", @@ -304,7 +304,7 @@ void TableFunction::printInLog( string const & filename ) const { for( integer j = 0; j < nY; j++ ) { - tableData2D.addCell( coordsX[i], j, m_values[ j*nX + i ] ); + tableData2D.addCell( coordsX[i], coordsY[j], m_values[ j*nX + i ] ); } nbRows++; } @@ -312,17 +312,16 @@ void TableFunction::printInLog( string const & filename ) const if( nbRows <= 500 ) { //2. format - vecDescription.push_back( string( units::getDescription( getDimUnit( 0 )))); - for( integer idxY = 0; idxY < nY; idxY++ ) - { - string description = string( units::getDescription( getDimUnit( 1 ))) + "=" + std::to_string( coordsY[idxY] ); - vecDescription.push_back( description ); - } - TableLayout const tableLayout( vecDescription, filename ); + string const rowFmt = GEOS_FMT( "{} = {{}}", units::getDescription( getDimUnit( 0 ) ) ); + string const columnFmt = GEOS_FMT( "{} = {{}}", units::getDescription( getDimUnit( 1 ) ) ); + TableData2D::Conversion1D const tableConverted = tableData2D.buildTableData( string( units::getDescription( m_valueUnit )), + rowFmt, + columnFmt ); + TableLayout const tableLayout( tableConverted.headerNames, filename ); //3. log TableTextFormatter const table2DLog( tableLayout ); - GEOS_LOG_RANK_0( table2DLog.toString( tableData2D.buildTableData() )); + GEOS_LOG_RANK_0( table2DLog.toString( tableConverted.tableData )); } else { From 73756650c12a9eaef7648b40092188d06c03373e Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 4 Apr 2024 11:12:51 +0200 Subject: [PATCH 080/216] refactor method to convert 2Dtable => 1D table --- src/coreComponents/common/TableData.cpp | 48 +++++++++---------- src/coreComponents/common/TableData.hpp | 38 ++++++++------- src/coreComponents/common/TableFormatter.cpp | 12 ++++- .../common/unitTests/testTable.cpp | 28 +++++++---- 4 files changed, 71 insertions(+), 55 deletions(-) diff --git a/src/coreComponents/common/TableData.cpp b/src/coreComponents/common/TableData.cpp index 1d29d5ef760..8f7b368454c 100644 --- a/src/coreComponents/common/TableData.cpp +++ b/src/coreComponents/common/TableData.cpp @@ -36,36 +36,34 @@ std::vector< std::vector< string > > const & TableData::getTableDataRows() const return m_rows; } -std::set< real64 > const & TableData2D::getColumns() const +TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, + string_view rowFmt, + string_view columnFmt ) const { - return m_columns; -} -std::set< real64 > const & TableData2D::getRows() const -{ - return m_rows; -} + TableData2D::Conversion1D tableData1D; -TableData TableData2D::buildTableData() const -{ - TableData tableDataToBeBuilt; - for( real64 const & rowValue : m_rows ) + tableData1D.headerNames.push_back( string( targetUnit ) ); + // looping over first line to fill columnNames + for( auto const & [ columnValue, cellValue] : m_data.begin()->second ) { - std::vector< string > values; - values.push_back( GEOS_FMT( "{}", rowValue ) ); - for( real64 const & columnValue : m_columns ) - { - std::pair< real64, real64 > id = std::make_pair( rowValue, columnValue ); - auto const dataIt = m_data.find( id ); - - if( dataIt != m_data.end()) - { - values.push_back( GEOS_FMT( "{}", dataIt->second )); - } + tableData1D.headerNames.push_back( GEOS_FMT( columnFmt, columnValue ) ); + } + // insert row value and row cell values + for( auto const & [rowValue, rowMap] : m_data ) + { + std::vector< string > currentRowValues; + currentRowValues.push_back( GEOS_FMT( rowFmt, rowValue ) ); + integer idxColumn = 0; + for( auto const & [columnValue, cellValue] : rowMap ) + { + currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); + ++idxColumn; } - tableDataToBeBuilt.addRow( values ); + idxColumn = 0; + tableData1D.tableData.addRow( currentRowValues ); } - return tableDataToBeBuilt; -} + return tableData1D; +} } diff --git a/src/coreComponents/common/TableData.hpp b/src/coreComponents/common/TableData.hpp index 3598a27f1df..ab807a34f2c 100644 --- a/src/coreComponents/common/TableData.hpp +++ b/src/coreComponents/common/TableData.hpp @@ -65,6 +65,12 @@ class TableData2D { public: + struct Conversion1D + { + std::vector< string > headerNames; + TableData tableData; + }; + /** * @brief Add a cell to the table. If necessary, create automatically the containing column & row. * @tparam T The value passed to addCell (can be any type). @@ -77,24 +83,22 @@ class TableData2D /** * @brief Construct a TableData from the provided cells. - * @return A TableData with all cell values within increasing row & column. The row & columns names - */ - TableData buildTableData() const; - - /** - * @return return all columns values for 2D table + * @param targetUnit The table unit + * @param rowFmt The y axis units of the table. + * @param columnFmt The x axis units of the table. + * The axis units can be customize, I.E with targetUnits = pressure [K]: + * GEOS_FMT( "{} = {{}}", targetUnits) => "pressure [K] = {}" + * @return A struct containing The columnNames and the TableData */ - std::set< real64 > const & getColumns() const; + Conversion1D buildTableData( string_view targetUnit, string_view rowFmt = "{{}}", string_view columnFmt = "{{}}" ) const; - /** - * @return return all rows values for 2D table - */ - std::set< real64 > const & getRows() const; private: - std::map< std::pair< real64, real64 >, string > m_data; - std::set< real64 > m_columns; - std::set< real64 > m_rows; + using RowType = real64; + using ColumnType = real64; + + /// @brief all cell values by their [ row ][ column ] + std::map< RowType, std::map< ColumnType, string > > m_data; }; template< typename ... Args > @@ -114,12 +118,10 @@ template< typename T > void TableData2D::addCell( real64 const rowValue, real64 const columnValue, T const & value ) { static_assert( has_formatter< decltype(value) >, "Argument passed in addCell cannot be converted to string" ); - std::pair< real64, real64 > const id = std::make_pair( rowValue, columnValue ); - m_data[id] = GEOS_FMT( "{}", value ); - m_columns.insert( columnValue ); - m_rows.insert( rowValue ); + m_data[rowValue][columnValue] = GEOS_FMT( "{}", value ); } + } #endif diff --git a/src/coreComponents/common/TableFormatter.cpp b/src/coreComponents/common/TableFormatter.cpp index 8549ac87d13..7f8ee69215d 100644 --- a/src/coreComponents/common/TableFormatter.cpp +++ b/src/coreComponents/common/TableFormatter.cpp @@ -27,9 +27,17 @@ TableFormatter::TableFormatter( TableLayout const & tableLayout ): void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & rows ) const { - for( size_t idxRow = 0; idxRow < rows.size(); ++idxRow ) + for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) { - for( size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) + if( rows[idxRow].size()!=columns.size()) + { + + GEOS_WARNING( GEOS_FMT( "{}{}{}", "The number of columns in row ", + idxRow, + " that has been collected is not equal to the columns expected when TableLayout was initialized" )); + } + columns[idxRow].columnValues.reserve( rows[idxRow].size() ); + for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) { columns[idxColumn].columnValues.push_back( rows[idxRow][idxColumn] ); } diff --git a/src/coreComponents/common/unitTests/testTable.cpp b/src/coreComponents/common/unitTests/testTable.cpp index 4aa91589582..c6edd86881b 100644 --- a/src/coreComponents/common/unitTests/testTable.cpp +++ b/src/coreComponents/common/unitTests/testTable.cpp @@ -230,7 +230,7 @@ TEST( testTable, tableClass ) //test 2D table { - TableLayout const tableLayout( {"FakePressure", "Value1", "Value2"} ); + //collect TableData2D tableData; for( real64 p = 10000; p<20000; p+=5000 ) @@ -242,17 +242,25 @@ TEST( testTable, tableClass ) } } + //convert + string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + TableData2D::Conversion1D tableconverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + + //format + TableLayout const tableLayout( tableconverted.headerNames ); + + //log TableTextFormatter const tableLog( tableLayout ); - EXPECT_EQ( tableLog.toString( tableData.buildTableData()), - "+----------------+----------+------------------------+\n" - "| FakePressure | Value1 | Value2 |\n" - "+----------------+----------+------------------------+\n" - "| 300 | 0.03 | 0.02 |\n" - "| 350 | 0.035 | 0.023333333333333334 |\n" - "| 400 | 0.04 | 0.02666666666666667 |\n" - "+----------------+----------+------------------------+\n\n" + EXPECT_EQ( tableLog.toString( tableconverted.tableData ), + "+---------------------+--------------------+------------------------+\n" + "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" + "+---------------------+--------------------+------------------------+\n" + "| Temperature = 300 | 0.03 | 0.02 |\n" + "| Temperature = 350 | 0.035 | 0.023333333333333334 |\n" + "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" + "+---------------------+--------------------+------------------------+\n\n" ); - } } From d590513f7b75b8c440e430779e07a79d1d4154fd Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 4 Apr 2024 11:27:30 +0200 Subject: [PATCH 081/216] CI correction --- src/coreComponents/common/TableFormatter.hpp | 4 ++++ src/coreComponents/common/TableLayout.hpp | 1 - src/coreComponents/mesh/generators/WellGeneratorBase.cpp | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/common/TableFormatter.hpp b/src/coreComponents/common/TableFormatter.hpp index 873d754e19e..1132f880c43 100644 --- a/src/coreComponents/common/TableFormatter.hpp +++ b/src/coreComponents/common/TableFormatter.hpp @@ -85,6 +85,10 @@ class TableTextFormatter : public TableFormatter public: + /** + * @brief Construct a new TableFormatter from a tableLayout + * @param tableLayout Contain all column names and optionnaly the table title + */ TableTextFormatter( TableLayout const & tableLayout ); /** diff --git a/src/coreComponents/common/TableLayout.hpp b/src/coreComponents/common/TableLayout.hpp index 4034ca3b6c9..2040a792857 100644 --- a/src/coreComponents/common/TableLayout.hpp +++ b/src/coreComponents/common/TableLayout.hpp @@ -48,7 +48,6 @@ class TableLayout */ struct ColumnParam { - string columnName; // Alignment for a column. By default aligned to the right side Alignment alignment = Alignment::right; diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 21bf4f79889..9a7727b3358 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -554,9 +554,9 @@ void WellGeneratorBase::logInternalWell() const string const wellTitle = GEOS_FMT( "Well '{}' Element Table", getName() ); TableLayout const tableWellLayout = TableLayout( { TableLayout::ColumnParam{"Element no.", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"CoordX", TableLayout::Alignment::center}, - TableLayout::ColumnParam{"CoordY", TableLayout::Alignment::center}, - TableLayout::ColumnParam{"CoordZ", TableLayout::Alignment::center}, + TableLayout::ColumnParam{"CoordX", TableLayout::Alignment::right}, + TableLayout::ColumnParam{"CoordY", TableLayout::Alignment::right}, + TableLayout::ColumnParam{"CoordZ", TableLayout::Alignment::right}, TableLayout::ColumnParam{"Prev\nElement", TableLayout::Alignment::right}, TableLayout::ColumnParam{"Next\nElement", TableLayout::Alignment::right}, }, wellTitle ); From 7f6b79b43d35fa9533e56efd51df975dbaa828ec Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 4 Apr 2024 12:03:37 +0200 Subject: [PATCH 082/216] move table to fileIO --- src/coreComponents/common/CMakeLists.txt | 6 - .../common/unitTests/CMakeLists.txt | 1 - src/coreComponents/fileIO/CMakeLists.txt | 6 + src/coreComponents/fileIO/Table/TableData.cpp | 69 +++ src/coreComponents/fileIO/Table/TableData.hpp | 127 ++++++ .../fileIO/Table/TableFormatter.cpp | 396 ++++++++++++++++++ .../fileIO/Table/TableFormatter.hpp | 187 +++++++++ .../fileIO/Table/TableLayout.cpp | 81 ++++ .../fileIO/Table/TableLayout.hpp | 146 +++++++ .../fileIO/Table/unitsTest/CMakeLists.txt | 18 + .../fileIO/Table/unitsTest/testTable.cpp | 271 ++++++++++++ .../mesh/generators/WellGeneratorBase.cpp | 6 +- 12 files changed, 1304 insertions(+), 10 deletions(-) create mode 100644 src/coreComponents/fileIO/Table/TableData.cpp create mode 100644 src/coreComponents/fileIO/Table/TableData.hpp create mode 100644 src/coreComponents/fileIO/Table/TableFormatter.cpp create mode 100644 src/coreComponents/fileIO/Table/TableFormatter.hpp create mode 100644 src/coreComponents/fileIO/Table/TableLayout.cpp create mode 100644 src/coreComponents/fileIO/Table/TableLayout.hpp create mode 100644 src/coreComponents/fileIO/Table/unitsTest/CMakeLists.txt create mode 100644 src/coreComponents/fileIO/Table/unitsTest/testTable.cpp diff --git a/src/coreComponents/common/CMakeLists.txt b/src/coreComponents/common/CMakeLists.txt index fc3703b3637..5600a8fae85 100644 --- a/src/coreComponents/common/CMakeLists.txt +++ b/src/coreComponents/common/CMakeLists.txt @@ -15,9 +15,6 @@ set( common_headers Path.hpp Span.hpp Stopwatch.hpp - TableFormatter.hpp - TableData.hpp - TableLayout.hpp Timer.hpp Tensor.hpp TimingMacros.hpp @@ -46,9 +43,6 @@ set( common_sources Logger.cpp MpiWrapper.cpp Path.cpp - TableFormatter.cpp - TableData.cpp - TableLayout.cpp initializeEnvironment.cpp Units.cpp ) diff --git a/src/coreComponents/common/unitTests/CMakeLists.txt b/src/coreComponents/common/unitTests/CMakeLists.txt index 08932fb1b1d..814fd512cec 100644 --- a/src/coreComponents/common/unitTests/CMakeLists.txt +++ b/src/coreComponents/common/unitTests/CMakeLists.txt @@ -4,7 +4,6 @@ set( gtest_geosx_tests testFixedSizeDeque.cpp testTypeDispatch.cpp testLifoStorage.cpp - testTable.cpp testUnits.cpp ) if ( ENABLE_CALIPER ) diff --git a/src/coreComponents/fileIO/CMakeLists.txt b/src/coreComponents/fileIO/CMakeLists.txt index c479846cc79..e2cef4b3e96 100644 --- a/src/coreComponents/fileIO/CMakeLists.txt +++ b/src/coreComponents/fileIO/CMakeLists.txt @@ -6,6 +6,9 @@ set( fileIO_headers Outputs/OutputUtilities.hpp Outputs/PythonOutput.hpp Outputs/RestartOutput.hpp + Table/TableLayout.hpp + Table/TableFormatter.hpp + Table/TableData.hpp Outputs/TimeHistoryOutput.hpp timeHistory/HDFFile.hpp timeHistory/HistoryCollectionBase.hpp @@ -22,6 +25,9 @@ set( fileIO_sources Outputs/OutputUtilities.cpp Outputs/PythonOutput.cpp Outputs/RestartOutput.cpp + Table/TableLayout.cpp + Table/TableFormatter.cpp + Table/TableData.cpp Outputs/TimeHistoryOutput.cpp timeHistory/HDFFile.cpp timeHistory/HistoryCollectionBase.cpp diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp new file mode 100644 index 00000000000..0073ec41730 --- /dev/null +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -0,0 +1,69 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file TableData.cpp + */ + +#include "TableData.hpp" + +namespace geos +{ + +void TableData::addRow( std::vector< string > const & row ) +{ + m_rows.push_back( row ); +} + +void TableData::clear() +{ + m_rows.clear(); +} + +std::vector< std::vector< string > > const & TableData::getTableDataRows() const +{ + return m_rows; +} + +TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, + string_view rowFmt, + string_view columnFmt ) const +{ + TableData2D::Conversion1D tableData1D; + + tableData1D.headerNames.push_back( string( targetUnit ) ); + // looping over first line to fill columnNames + for( auto const & [ columnValue, cellValue] : m_data.begin()->second ) + { + tableData1D.headerNames.push_back( GEOS_FMT( columnFmt, columnValue ) ); + } + + // insert row value and row cell values + for( auto const & [rowValue, rowMap] : m_data ) + { + std::vector< string > currentRowValues; + currentRowValues.push_back( GEOS_FMT( rowFmt, rowValue ) ); + integer idxColumn = 0; + for( auto const & [columnValue, cellValue] : rowMap ) + { + currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); + ++idxColumn; + } + idxColumn = 0; + tableData1D.tableData.addRow( currentRowValues ); + } + + return tableData1D; +} +} diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp new file mode 100644 index 00000000000..ab807a34f2c --- /dev/null +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -0,0 +1,127 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file TableData.hpp + */ + +#ifndef GEOS_COMMON_TableData_HPP +#define GEOS_COMMON_TableData_HPP + +#include "common/DataTypes.hpp" +#include "common/Format.hpp" + +namespace geos +{ + +// Class for managing table data +class TableData +{ +public: + + /** + * @brief Add a row to the table. + * @param Args The values passed to addRow (can be any type). + * @param args Cell values to be added to the row. + */ + template< typename ... Args > + void addRow( Args const & ... args ); + + /** + * @brief Add a row to the table + * @param row A vector of string who contains cell Values + */ + void addRow( std::vector< string > const & row ); + + /** + * @brief Reset data in the table + */ + void clear(); + + /** + * @return The rows of the table + */ + std::vector< std::vector< string > > const & getTableDataRows() const; + +private: + + std::vector< std::vector< string > > m_rows; + +}; + +// Class for managing 2D table m_data +class TableData2D +{ +public: + + struct Conversion1D + { + std::vector< string > headerNames; + TableData tableData; + }; + + /** + * @brief Add a cell to the table. If necessary, create automatically the containing column & row. + * @tparam T The value passed to addCell (can be any type). + * @param value Cell value to be added. + * @param rowValue The value of the row containing the cell. + * @param columnValue The value of the column containing the cell. + */ + template< typename T > + void addCell( real64 rowValue, real64 columnValue, T const & value ); + + /** + * @brief Construct a TableData from the provided cells. + * @param targetUnit The table unit + * @param rowFmt The y axis units of the table. + * @param columnFmt The x axis units of the table. + * The axis units can be customize, I.E with targetUnits = pressure [K]: + * GEOS_FMT( "{} = {{}}", targetUnits) => "pressure [K] = {}" + * @return A struct containing The columnNames and the TableData + */ + Conversion1D buildTableData( string_view targetUnit, string_view rowFmt = "{{}}", string_view columnFmt = "{{}}" ) const; + + +private: + using RowType = real64; + using ColumnType = real64; + + /// @brief all cell values by their [ row ][ column ] + std::map< RowType, std::map< ColumnType, string > > m_data; +}; + +template< typename ... Args > +void TableData::addRow( Args const &... args ) +{ + std::vector< string > m_cellsValue; + ( [&] { + static_assert( has_formatter< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); + string const cellValue = GEOS_FMT( "{}", args ); + m_cellsValue.push_back( cellValue ); + } (), ...); + + addRow( m_cellsValue ); +} + +template< typename T > +void TableData2D::addCell( real64 const rowValue, real64 const columnValue, T const & value ) +{ + static_assert( has_formatter< decltype(value) >, "Argument passed in addCell cannot be converted to string" ); + m_data[rowValue][columnValue] = GEOS_FMT( "{}", value ); +} + + +} + +#endif diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp new file mode 100644 index 00000000000..fb2b19beefb --- /dev/null +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -0,0 +1,396 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file TableFormatter.cpp + */ + +#include "TableFormatter.hpp" +namespace geos +{ + +TableFormatter::TableFormatter( TableLayout const & tableLayout ): + m_tableLayout( tableLayout ) +{} + +void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, + std::vector< std::vector< string > > const & rows ) const +{ + for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) + { + if( rows[idxRow].size()!=columns.size()) + { + + GEOS_WARNING( GEOS_FMT( "{}{}{}", "The number of columns in row ", + idxRow, + " that has been collected is not equal to the columns expected when TableLayout was initialized" )); + } + columns[idxRow].columnValues.reserve( rows[idxRow].size() ); + for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) + { + columns[idxColumn].columnValues.push_back( rows[idxRow][idxColumn] ); + } + } +} + +/////////////////////////////////////////////////////////////////////// +////// CSV Formatter implementation +/////////////////////////////////////////////////////////////////////// + +TableCSVFormatter::TableCSVFormatter( TableLayout const & tableLayout ): + TableFormatter( tableLayout ) +{ + m_tableLayout = tableLayout; +} + +string TableCSVFormatter::headerToString() const +{ + std::stringstream oss; + static constexpr string_view separator = ","; + + for( std::size_t idxColumn = 0; idxColumn < m_tableLayout.getColumns().size(); ++idxColumn ) + { + oss << m_tableLayout.getColumns()[idxColumn].parameter.columnName; + if( idxColumn < m_tableLayout.getColumns().size() - 1 ) + { + oss << separator; + } + } + oss << "\n"; + return oss.str(); +} + +string TableCSVFormatter::dataToString( TableData const & tableData ) const +{ + std::vector< std::vector< string > > const rowsValues = tableData.getTableDataRows(); + std::ostringstream oss; + + for( const auto & row : rowsValues ) + { + for( size_t idxColumn = 0; idxColumn < row.size(); ++idxColumn ) + { + oss << row[idxColumn]; + if( idxColumn < row.size() - 1 ) + { + oss << ","; + } + } + oss << "\n"; + } + return oss.str(); +} + +string TableCSVFormatter::toString( TableData const & tableData ) const +{ + return headerToString() + dataToString( tableData ); +} + +/////////////////////////////////////////////////////////////////////// +////// Log Formatter implementation +/////////////////////////////////////////////////////////////////////// + +/** + * @brief Build a value cell given an alignment and spaces from "|" + * + * @param alignment The aligment of cell value + * @param value The cell value + * @param spaces The number of spaces in the cell + * @return A formated cell + */ +string buildValueCell( TableLayout::Alignment const alignment, string_view value, integer const spaces ) +{ + switch( alignment ) + { + case TableLayout::right: return GEOS_FMT( "{:>{}}", value, spaces ); + case TableLayout::left: return GEOS_FMT( "{:<{}}", value, spaces ); + case TableLayout::center: return GEOS_FMT( "{:^{}}", value, spaces ); + default: return GEOS_FMT( "{:>{}}", value, spaces ); + } +} + +TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): + TableFormatter( tableLayout ) +{} + +string TableTextFormatter::toString( TableData const & tableData ) const +{ + std::ostringstream tableOutput; + string sectionSeparator; + std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); + integer const nbRows = tableData.getTableDataRows().size(); + + fillTableColumnsFromRows( columns, tableData.getTableDataRows() ); + + layoutToString( tableOutput, columns, nbRows, sectionSeparator ); + buildSectionRows( columns, sectionSeparator, tableOutput, nbRows, TableLayout::Section::values ); + tableOutput << '\n'; + + return tableOutput.str(); +} + +string TableTextFormatter::layoutToString() const +{ + std::ostringstream tableOutput; + std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); + string sectionSeparator; + + layoutToString( tableOutput, columns, 0, sectionSeparator ); + + return tableOutput.str(); +} + +void TableTextFormatter::layoutToString( std::ostringstream & tableOutput, + std::vector< TableLayout::Column > & columns, + integer const nbRow, + string & sectionSeparator ) const +{ + string titleRows; + string topSeparator; + size_t largestHeaderVectorSize = 0; + std::vector< std::vector< string > > splitHeader; + string const tableTitle = string( m_tableLayout.getTitle()); + + parseAndStoreHeaderSections( columns, largestHeaderVectorSize, splitHeader ); + adjustHeaderSizesAndStore( columns, largestHeaderVectorSize, splitHeader ); + + findAndSetMaxStringSize( columns, nbRow ); + computeAndBuildSeparator( columns, topSeparator, sectionSeparator ); + + if( !tableTitle.empty()) + { + buildTitleRow( titleRows, topSeparator, sectionSeparator ); + tableOutput << titleRows; + } + + tableOutput << sectionSeparator + '\n'; + buildSectionRows( columns, sectionSeparator, tableOutput, largestHeaderVectorSize, TableLayout::Section::header ); +} + +void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout::Column > const & columns, + size_t & largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeader ) const +{ + for( auto const & column : columns ) + { + std::vector< string > splitHeaderParts; + std::istringstream ss( column.parameter.columnName ); + string subColumnNames; + + while( getline( ss, subColumnNames, '\n' )) + { + splitHeaderParts.push_back( subColumnNames ); + } + + size_t const cellSize = splitHeaderParts.size(); + largestHeaderVectorSize = std::max( largestHeaderVectorSize, cellSize ); + + splitHeader.push_back( splitHeaderParts ); + } +} + +void TableTextFormatter::adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, + size_t const & largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeader ) const +{ + for( size_t columnParamIdx = 0; columnParamIdx < columns.size(); ++columnParamIdx ) + { + if( splitHeader[columnParamIdx].size() < largestHeaderVectorSize ) + { + integer const whiteRowToAdd = largestHeaderVectorSize - splitHeader[columnParamIdx].size(); + splitHeader[columnParamIdx].insert( splitHeader[columnParamIdx].end(), whiteRowToAdd, " " ); + } + columns[columnParamIdx].parameter.splitColumnName = splitHeader[columnParamIdx]; + } +} + +void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, + size_t const & nbRows ) const +{ + string maxStringSize = ""; + for( auto & column : columns ) + { + auto it = std::max_element( column.parameter.splitColumnName.begin(), + column.parameter.splitColumnName.end(), + []( const auto & a, const auto & b ) { + return a.size() < b.size(); + } ); + + maxStringSize = *it; + for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) + { + string cell = column.columnValues[idxRow]; + + if( maxStringSize.length() < cell.length()) + { + maxStringSize = cell; + } + } + + column.m_maxStringSize = maxStringSize; + } +} + +void TableTextFormatter::computeAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, + string::size_type const sectionlineLength, + string::size_type const titleLineLength ) const +{ + integer extraLinesPerColumn; + integer extraLines; + integer newStringSize; + + extraLines = titleLineLength - sectionlineLength; + extraLinesPerColumn = std::ceil( extraLines / columns.size() ); + + for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) + { + newStringSize = extraLinesPerColumn + columns[idxColumn].m_maxStringSize.size(); + if( idxColumn == columns.size() - 1 || columns.size() == 1 ) + { + columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", + columns[idxColumn].m_maxStringSize, + newStringSize + m_tableLayout.getColumnMargin() ); + } + else + { + columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", + columns[idxColumn].m_maxStringSize, + newStringSize ); + } + } +} + +void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Column > & columns, + string & topSeparator, + string & sectionSeparator ) const +{ + integer const columnMargin = m_tableLayout.getColumnMargin(); + integer const borderMargin = m_tableLayout.getBorderMargin(); + integer const marginTitle = m_tableLayout.getMarginTitle(); + string tableTitle = string( m_tableLayout.getTitle() ); + + string::size_type sectionlineLength = 0; + string::size_type const titleLineLength = tableTitle.length() + ( marginTitle * 2 ); + integer const nbSpaceBetweenColumn = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); + + if( !tableTitle.empty()) + { + tableTitle = GEOS_FMT( "{:^{}}", tableTitle, titleLineLength ); + } + + for( auto const & column : columns ) + { + sectionlineLength += column.m_maxStringSize.length(); + } + + sectionlineLength += nbSpaceBetweenColumn; + if( sectionlineLength < titleLineLength ) + { + computeAndSetMaxStringSize( columns, sectionlineLength, titleLineLength ); + } + if( columns.size() == 1 ) + { + sectionSeparator += GEOS_FMT( "+{:-<{}}+", + "", + ( columns[0].m_maxStringSize.length() + (borderMargin - 1) + columnMargin )); + } + else + { + for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) + { + integer const cellSize = columns[idxColumn].m_maxStringSize.length(); + if( idxColumn == 0 ) + { + sectionSeparator += GEOS_FMT( "+{:-<{}}", "", ( cellSize + borderMargin )); + } + else if( idxColumn == (columns.size() - 1)) + { + sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); + sectionSeparator += GEOS_FMT( "{:->{}}", "+", ( cellSize + borderMargin + 1 ) ); + } + else + { + sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); + sectionSeparator += GEOS_FMT( "{:->{}}", "", cellSize ); + } + } + } + topSeparator = GEOS_FMT( "+{:-<{}}+", "", sectionSeparator.size() - 2 ); // -2 for ++ +} + +void TableTextFormatter::buildTitleRow( string & titleRows, + string_view topSeparator, + string_view sectionSeparator ) const +{ + titleRows = GEOS_FMT( "\n{}\n|", topSeparator ); + titleRows += buildValueCell( TableLayout::Alignment::center, + m_tableLayout.getTitle(), + (sectionSeparator.length() - 2) // -2 for || + ); + titleRows += GEOS_FMT( "{}\n", "|" ); +} + +void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > const & columns, + string_view sectionSeparator, + std::ostringstream & tableRows, + integer const nbRows, + TableLayout::Section const section ) const +{ + integer const columnMargin = m_tableLayout.getColumnMargin(); + integer const borderMargin = m_tableLayout.getBorderMargin(); + + for( integer idxRow = 0; idxRow< nbRows; ++idxRow ) + { + tableRows << GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); + for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) + { + string cell; + + if( section == TableLayout::Section::header ) + { + cell = columns[idxColumn].parameter.splitColumnName[idxRow]; + } + else + { + cell = columns[idxColumn].columnValues[idxRow]; + } + integer const cellSize = columns[idxColumn].m_maxStringSize.length(); + tableRows << buildValueCell( columns[idxColumn].parameter.alignment, + cell, + cellSize ); + + if( idxColumn < columns.size() - 1 ) + { + tableRows << GEOS_FMT( "{:^{}}", "|", columnMargin ); + } + + } + + if( columns.size() == 1 ) + { + tableRows << GEOS_FMT( "{:>{}}\n", "|", columnMargin ); + } + else + { + tableRows << GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); + } + + } + if( nbRows != 0 ) + { + tableRows << GEOS_FMT( "{}\n", sectionSeparator ); + } +} + + +} diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp new file mode 100644 index 00000000000..372c8b7c329 --- /dev/null +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -0,0 +1,187 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file TableFormatter.hpp + */ + +#ifndef GEOS_COMMON_TABLEFORMATTER_HPP +#define GEOS_COMMON_TABLEFORMATTER_HPP + +#include "TableData.hpp" +#include "TableLayout.hpp" + +namespace geos +{ + +// Class for formatting table data +class TableFormatter +{ +public: + + /** + * @brief Construct a new Table Formatter from a tableLayout + * @param tableLayout Contain all column names and optionnaly the table title + */ + TableFormatter( TableLayout const & tableLayout ); + + /** + * @brief Fill the vector (m_column) in tableData with values from m_rows in tableLayout, storing all values in an unsorted order. + * @param columns Vector of columns to be filled. + * @param tableData Vector of table data. + */ + void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, + std::vector< std::vector< string > > const & tableData ) const; + +protected: + + TableLayout m_tableLayout; +}; + +class TableCSVFormatter : public TableFormatter +{ +public: + + /** + * @brief Construct a new Table Formatter from a tableLayout + * @param tableLayout Contain all column names and optionnaly the table title + */ + TableCSVFormatter( TableLayout const & tableLayout ); + + /** + * @brief Convert the table data to a CSV string. + * @param tableData The 1D table data. + * @return The CSV string representation of the table data. + */ + string dataToString( TableData const & tableData ) const; + + /** + * @return The string with all column names. + */ + string headerToString() const; + + /** + * @brief Convert the TableData to a table string. + * @param tableData The TableData to convert. + * @return The table string representation of the TableData. + */ + string toString( TableData const & tableData ) const; + +}; + +class TableTextFormatter : public TableFormatter +{ + +public: + + /** + * @brief Construct a new TableFormatter from a tableLayout + * @param tableLayout Contain all column names and optionnaly the table title + */ + TableTextFormatter( TableLayout const & tableLayout ); + + /** + * @brief Convert the TableData to a table string. + * @param tableData The TableData to convert. + * @return The table string representation of the TableData. + */ + string toString( TableData const & tableData ) const; + + /** + * @brief Converts a TableLayout into a formatted string representation. + * @return string + */ + string layoutToString() const; + +private: + + /** + * @brief Converts a TableLayout into a formatted representation. + * @param tableOutput The output stream + * @param columns The vectors of table columns + * @param nbRows Number of rows in the table + * @param sectionSeparator An empty string for building the section separator + */ + void layoutToString( std::ostringstream & tableOutput, + std::vector< TableLayout::Column > & columns, + integer const nbRows, + string & sectionSeparator ) const; + + /** + * @brief Split all header names by detecting the newline \\n character. + * @param splitHeader A empty vector who will contain all split header names + * @param largestHeaderVectorSize The largest split header vector size + */ + void parseAndStoreHeaderSections( std::vector< TableLayout::Column > const & columns, + size_t & largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeader ) const; + + /** + * @brief Set the same vector size for each split header and merge it into columns + * @param columns The table columns to be merged + * @param largestHeaderVectorSize The reference value for adjusting splitHeader vector + * @param splitHeader The vector containing all split headers + */ + void adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, + size_t const & largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeader ) const; + + /** + * @brief For each column find and set the column's longest string + */ + void findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, size_t const & nbRows ) const; + + /** + * @brief Compute the largest string size in the table. If the table title is the largest string size in the table, recalculate for all + * columns the \p m_maxStringSize value by adding extra characters + * @param sectionlineLength The length of a section line + * @param titleLineLength The length of a title line + */ + void computeAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, + string::size_type const sectionlineLength, + string::size_type const titleLineLength ) const; + + /** + * @brief Compute and build the top and the section line separator + * @param topSeparator An empty string to be built + * @param sectionSeparator An empty string to be built + */ + void computeAndBuildSeparator( std::vector< TableLayout::Column > & columns, + string & topSeparator, + string & sectionSeparator ) const; + + /** + * @brief Build the table title section + * @param titleRows Rows containing the title section. + * @param topSeparator The top line separator + * @param sectionSeparator The section line separator + */ + void buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ) const; + + /** + * @brief Build a section by specifying it's type ( header or section ) + * @param sectionSeparator Line separator between sections + * @param rows A section row + * @param nbRows Indicates the number of lines in a section + * @param section The section to be built + */ + void buildSectionRows( std::vector< TableLayout::Column > const & columns, + string_view sectionSeparator, + std::ostringstream & rows, + integer const nbRows, + TableLayout::Section const section ) const; +}; +} + +#endif diff --git a/src/coreComponents/fileIO/Table/TableLayout.cpp b/src/coreComponents/fileIO/Table/TableLayout.cpp new file mode 100644 index 00000000000..eb9134f7695 --- /dev/null +++ b/src/coreComponents/fileIO/Table/TableLayout.cpp @@ -0,0 +1,81 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file TableData.hpp + */ + +#include "TableLayout.hpp" + +namespace geos +{ + +TableLayout::TableLayout( std::vector< string > const & headers, string const & title ): + m_tableTitle( title ) +{ + setMargin( MarginValue::medium ); + for( size_t idx = 0; idx< headers.size(); ++idx ) + { + m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::right, true}, {}, ""} ); + } +} + +TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title ): + m_tableTitle( title ) +{ + setMargin( MarginValue::medium ); + + for( size_t idx = 0; idx< columnParameter.size(); ++idx ) + { + if( columnParameter[idx].enabled ) + { + m_columns.push_back( {columnParameter[idx], {}, ""} ); + } + + } +} + +void TableLayout::setMargin( MarginValue marginValue ) +{ + m_borderMargin = marginValue; + m_columnMargin = integer( marginValue ) * 2 + 1; +} + +std::vector< TableLayout::Column > const & TableLayout::getColumns() const +{ + return m_columns; +} + +string_view TableLayout::getTitle() const +{ + return m_tableTitle; +} + + +integer const & TableLayout::getBorderMargin() const +{ + return m_borderMargin; +} + +integer const & TableLayout::getColumnMargin() const +{ + return m_columnMargin; +} + +integer const & TableLayout::getMarginTitle() const +{ + return m_marginTitle; +} + +} diff --git a/src/coreComponents/fileIO/Table/TableLayout.hpp b/src/coreComponents/fileIO/Table/TableLayout.hpp new file mode 100644 index 00000000000..2040a792857 --- /dev/null +++ b/src/coreComponents/fileIO/Table/TableLayout.hpp @@ -0,0 +1,146 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +/** + * @file TableLayout.hpp + */ + +#ifndef GEOS_COMMON_TABLELAYOUT_HPP +#define GEOS_COMMON_TABLELAYOUT_HPP + +#include "common/DataTypes.hpp" + +namespace geos +{ + +class TableLayout +{ + +public: + enum Alignment { right, left, center }; + + enum MarginValue : integer + { + tiny = 0, + small = 1, + medium = 2, + large = 3 + }; + + /** + * @brief Enumeration for table sections. + */ + enum Section { header, values }; + + /** + * @brief Structure to set up each colum parameters. + */ + struct ColumnParam + { + string columnName; + // Alignment for a column. By default aligned to the right side + Alignment alignment = Alignment::right; + // A boolean to display a colummn + bool enabled = true; + // Vector containing substring column name delimited by "\n" + std::vector< string > splitColumnName; + + /** + * @brief Construct a ColumnParam object with the specified name and alignment. + * @param name The name of the column + * @param align The alignment of the column + */ + ColumnParam( std::string const & name, Alignment align ) + : columnName( name ), alignment( align ) + {} + + /** + * @brief Construct a ColumnParam object with the specified name, alignment, and display flag. + * @param name The name of the column + * @param align The alignment of the column + * @param display Flag indicating whether the column is enabled + */ + ColumnParam( std::string const & name, Alignment align, bool display ) + : columnName( name ), alignment( align ), enabled( display ) + {} + }; + + /** + * @brief Struct for a column. + */ + struct Column + { + ColumnParam parameter; + // A vector containing all column values + std::vector< string > columnValues; + // The largest string in the column + string m_maxStringSize; + }; + + /** + * @brief Construct a new Table object, all values in the table are centered by default + * @param columnNames The names of the columns + */ + TableLayout( std::vector< string > const & columnNames, string const & title = "" ); + + /** + * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels + * level + * @param columnParameter List of structures to set up each colum parameters. + */ + TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title = "" ); + + /** + * @return The columns vector + */ + std::vector< Column > const & getColumns() const; + + /** + * @return The table name + */ + string_view getTitle() const; + + /** + * @return The border margin + */ + integer const & getBorderMargin() const; + + /** + * @return The column margin + */ + integer const & getColumnMargin() const; + + /** + * @return The margin title + */ + integer const & getMarginTitle() const; + +private: + + /** + * @brief Set the minimal margin width between row content and borders. + * @param marginType The margin value + */ + void setMargin( MarginValue marginValue ); + + std::vector< Column > m_columns; + string m_tableTitle; + integer m_borderMargin; + integer m_columnMargin; + integer m_marginTitle = 2; + +}; +} + +#endif diff --git a/src/coreComponents/fileIO/Table/unitsTest/CMakeLists.txt b/src/coreComponents/fileIO/Table/unitsTest/CMakeLists.txt new file mode 100644 index 00000000000..09ced06d546 --- /dev/null +++ b/src/coreComponents/fileIO/Table/unitsTest/CMakeLists.txt @@ -0,0 +1,18 @@ +# Specify list of tests +set( gtest_geosx_tests + testTable.cpp ) + +set( dependencyList ${parallelDeps} common hdf5 gtest ) + +# Add gtest C++ based tests +foreach(test ${gtest_geosx_tests}) + get_filename_component( test_name ${test} NAME_WE ) + blt_add_executable( NAME ${test_name} + SOURCES ${test} + OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY} + DEPENDS_ON ${dependencyList} ) + + geos_add_test( NAME ${test_name} + COMMAND ${test_name} ) + +endforeach() diff --git a/src/coreComponents/fileIO/Table/unitsTest/testTable.cpp b/src/coreComponents/fileIO/Table/unitsTest/testTable.cpp new file mode 100644 index 00000000000..fea7ec2113b --- /dev/null +++ b/src/coreComponents/fileIO/Table/unitsTest/testTable.cpp @@ -0,0 +1,271 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 TotalEnergies + * Copyright (c) 2019- GEOSX Contributors + * All rights reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +// Source includes +#include "fileIO/Table/TableData.hpp" +#include "fileIO/Table/TableFormatter.hpp" +#include "fileIO/Table/TableLayout.hpp" +#include "dataRepository/Group.hpp" +// TPL includes +#include + +using namespace geos; + + +TEST( testTable, tableClass ) +{ + + //table with empty row + { + TableLayout const tableLayout( {"Well\nelement no.\nPV weighted\nbar", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"}, + "InternalWellGenerator well_injector1" + ); + + TableData tableData; + tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); + tableData.addRow( "", "", "", "", "" ); + tableData.addRow( "Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", "[30.21543]", "30.45465142", + 787442, 10 ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( + tableData ), + "\n+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| Well | CordX | CoordZ | Prev | Next |\n" + "| element no. | | | element | element |\n" + "| PV weighted | | | | |\n" + "| bar | | | | |\n" + "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" + "| | | | | |\n" + "| Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | [30.21543] | 30.45465142 | 787442 | 10 |\n" + "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" + ); + } + + //same but with different values + { + TableLayout const tableLayout( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"}, "InternalWellGenerator well_injector1" ); + + TableData tableData; + tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); + tableData.addRow( "", "", "", "", "" ); + tableData.addRow( "value23", "[30.21543]", "30.45465142", 787442, 10 ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableData ), + "\n+---------------------------------------------------------------------------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| Duis fringilla, ligula sed porta fringilla, | CordX | CoordZ | Prev | Next |\n" + "| ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | | | element | element |\n" + "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" + "| | | | | |\n" + "| value23 | [30.21543] | 30.45465142 | 787442 | 10 |\n" + "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" + ); + } + + //table with TableLayout::ColumnParam + { + TableLayout const tableLayout( { + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::right}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::right} + }, "InternalWellGenerator well_injector1" ); + + TableData tableData; + tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableData ), + "\n+-----------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" + "| | | | | element | element |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" + ); + } + + //test with hidden column + { + TableLayout const tableLayout( { + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left, false}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center, false}, + }, "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + + TableData tableData; + tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableData ), + "\n+------------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" + "| Cras egestas | CoordX | C | CoordZ |\n" + "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" + "| value1 | | 3.0 | 3.0129877 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 |\n" + "+---------------------------+---------------------+----------------------------------+-----------------------------+\n\n" + ); + } + + //test with 1 column + { + TableLayout const tableLayout( { + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, + }, "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + + TableData tableData; + tableData.addRow( "value1" ); + tableData.addRow( "val1" ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableData ), + "\n+-------------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "+-------------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas |\n" + "+-------------------------------------------------------------------------------------------------------------------+\n" + "| value1 |\n" + "| val1 |\n" + "+-------------------------------------------------------------------------------------------------------------------+\n\n" + ); + } + + //test without title + { + TableLayout const tableLayout( { + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, + } + ); + + TableData tableData; + tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableData ), + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" + "| | | | | element | element |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" + ); + } + + // if setMargin used elsewhere make it public + //test with tiny margin + // { + // TableLayout tableLayout( { + // TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, + // TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, + // TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, + // TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + // TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, + // TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, + // }, "InternalWellGenerator well_injector1" ); + + // //tableLayout.setMargin( TableLayout::MarginValue::tiny ); + + // TableData tableData; + // tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + // tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + + // TableTextFormatter const tableText( tableLayout ); + // EXPECT_EQ( tableText.toString( tableData ), + // "\n+-----------------------------------------------------------------+\n" + // "| InternalWellGenerator well_injector1 |\n" + // "+------------+------+-------------------+---------+-------+-------+\n" + // "|Cras egestas|CoordX| C |CoordZ |Prev | Next |\n" + // "| | | | |element|element|\n" + // "+------------+------+-------------------+---------+-------+-------+\n" + // "| value1 | | 3.0 |3.0129877|2 | 1 |\n" + // "| val1 | v|[3.045,42.02,89.25]|3 |10 | 3 |\n" + // "+------------+------+-------------------+---------+-------+-------+\n\n" + // ); + // } + + //test 2D table + { + //collect + TableData2D tableData; + + for( real64 p = 10000; p<20000; p+=5000 ) + { + for( real64 t = 400; t>=270; t+=-50.0 ) + { + real64 value = t/p; + tableData.addCell( t, p, value ); + } + } + + //convert + string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + TableData2D::Conversion1D tableconverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + + //format + TableLayout const tableLayout( tableconverted.headerNames ); + + //log + TableTextFormatter const tableLog( tableLayout ); + EXPECT_EQ( tableLog.toString( tableconverted.tableData ), + "+---------------------+--------------------+------------------------+\n" + "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" + "+---------------------+--------------------+------------------------+\n" + "| Temperature = 300 | 0.03 | 0.02 |\n" + "| Temperature = 350 | 0.035 | 0.023333333333333334 |\n" + "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" + "+---------------------+--------------------+------------------------+\n\n" + ); + } +} + +int main( int argc, char * * argv ) +{ + testing::InitGoogleTest( &argc, argv ); + return RUN_ALL_TESTS();; +} diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 9a7727b3358..dee088ac575 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -17,9 +17,9 @@ #include "mesh/Perforation.hpp" #include "mesh/generators/LineBlockABC.hpp" #include "LvArray/src/genericTensorOps.hpp" -#include "common/TableLayout.hpp" -#include "common/TableData.hpp" -#include "common/TableFormatter.hpp" +#include "fileIO/Table/TableLayout.hpp" +#include "fileIO/Table/TableData.hpp" +#include "fileIO/Table/TableFormatter.hpp" #include "common/Format.hpp" namespace geos { From 73f8374ccd62a99e3dbece2ba062f4776079586b Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 4 Apr 2024 14:14:56 +0200 Subject: [PATCH 083/216] update some doc --- src/coreComponents/common/TableData.cpp | 69 --- src/coreComponents/common/TableData.hpp | 127 ------ src/coreComponents/common/TableFormatter.cpp | 396 ------------------ src/coreComponents/common/TableFormatter.hpp | 187 --------- src/coreComponents/common/TableLayout.cpp | 81 ---- src/coreComponents/common/TableLayout.hpp | 146 ------- .../common/unitTests/testTable.cpp | 271 ------------ src/coreComponents/fileIO/Table/TableData.hpp | 8 +- .../fileIO/Table/TableFormatter.hpp | 2 +- 9 files changed, 5 insertions(+), 1282 deletions(-) delete mode 100644 src/coreComponents/common/TableData.cpp delete mode 100644 src/coreComponents/common/TableData.hpp delete mode 100644 src/coreComponents/common/TableFormatter.cpp delete mode 100644 src/coreComponents/common/TableFormatter.hpp delete mode 100644 src/coreComponents/common/TableLayout.cpp delete mode 100644 src/coreComponents/common/TableLayout.hpp delete mode 100644 src/coreComponents/common/unitTests/testTable.cpp diff --git a/src/coreComponents/common/TableData.cpp b/src/coreComponents/common/TableData.cpp deleted file mode 100644 index 8f7b368454c..00000000000 --- a/src/coreComponents/common/TableData.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2018-2020 TotalEnergies - * Copyright (c) 2019- GEOSX Contributors - * All rights reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - -/** - * @file TableData.cpp - */ - -#include "common/TableData.hpp" - -namespace geos -{ - -void TableData::addRow( std::vector< string > const & row ) -{ - m_rows.push_back( row ); -} - -void TableData::clear() -{ - m_rows.clear(); -} - -std::vector< std::vector< string > > const & TableData::getTableDataRows() const -{ - return m_rows; -} - -TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, - string_view rowFmt, - string_view columnFmt ) const -{ - TableData2D::Conversion1D tableData1D; - - tableData1D.headerNames.push_back( string( targetUnit ) ); - // looping over first line to fill columnNames - for( auto const & [ columnValue, cellValue] : m_data.begin()->second ) - { - tableData1D.headerNames.push_back( GEOS_FMT( columnFmt, columnValue ) ); - } - - // insert row value and row cell values - for( auto const & [rowValue, rowMap] : m_data ) - { - std::vector< string > currentRowValues; - currentRowValues.push_back( GEOS_FMT( rowFmt, rowValue ) ); - integer idxColumn = 0; - for( auto const & [columnValue, cellValue] : rowMap ) - { - currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); - ++idxColumn; - } - idxColumn = 0; - tableData1D.tableData.addRow( currentRowValues ); - } - - return tableData1D; -} -} diff --git a/src/coreComponents/common/TableData.hpp b/src/coreComponents/common/TableData.hpp deleted file mode 100644 index ab807a34f2c..00000000000 --- a/src/coreComponents/common/TableData.hpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2018-2020 TotalEnergies - * Copyright (c) 2019- GEOSX Contributors - * All rights reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - -/** - * @file TableData.hpp - */ - -#ifndef GEOS_COMMON_TableData_HPP -#define GEOS_COMMON_TableData_HPP - -#include "common/DataTypes.hpp" -#include "common/Format.hpp" - -namespace geos -{ - -// Class for managing table data -class TableData -{ -public: - - /** - * @brief Add a row to the table. - * @param Args The values passed to addRow (can be any type). - * @param args Cell values to be added to the row. - */ - template< typename ... Args > - void addRow( Args const & ... args ); - - /** - * @brief Add a row to the table - * @param row A vector of string who contains cell Values - */ - void addRow( std::vector< string > const & row ); - - /** - * @brief Reset data in the table - */ - void clear(); - - /** - * @return The rows of the table - */ - std::vector< std::vector< string > > const & getTableDataRows() const; - -private: - - std::vector< std::vector< string > > m_rows; - -}; - -// Class for managing 2D table m_data -class TableData2D -{ -public: - - struct Conversion1D - { - std::vector< string > headerNames; - TableData tableData; - }; - - /** - * @brief Add a cell to the table. If necessary, create automatically the containing column & row. - * @tparam T The value passed to addCell (can be any type). - * @param value Cell value to be added. - * @param rowValue The value of the row containing the cell. - * @param columnValue The value of the column containing the cell. - */ - template< typename T > - void addCell( real64 rowValue, real64 columnValue, T const & value ); - - /** - * @brief Construct a TableData from the provided cells. - * @param targetUnit The table unit - * @param rowFmt The y axis units of the table. - * @param columnFmt The x axis units of the table. - * The axis units can be customize, I.E with targetUnits = pressure [K]: - * GEOS_FMT( "{} = {{}}", targetUnits) => "pressure [K] = {}" - * @return A struct containing The columnNames and the TableData - */ - Conversion1D buildTableData( string_view targetUnit, string_view rowFmt = "{{}}", string_view columnFmt = "{{}}" ) const; - - -private: - using RowType = real64; - using ColumnType = real64; - - /// @brief all cell values by their [ row ][ column ] - std::map< RowType, std::map< ColumnType, string > > m_data; -}; - -template< typename ... Args > -void TableData::addRow( Args const &... args ) -{ - std::vector< string > m_cellsValue; - ( [&] { - static_assert( has_formatter< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); - string const cellValue = GEOS_FMT( "{}", args ); - m_cellsValue.push_back( cellValue ); - } (), ...); - - addRow( m_cellsValue ); -} - -template< typename T > -void TableData2D::addCell( real64 const rowValue, real64 const columnValue, T const & value ) -{ - static_assert( has_formatter< decltype(value) >, "Argument passed in addCell cannot be converted to string" ); - m_data[rowValue][columnValue] = GEOS_FMT( "{}", value ); -} - - -} - -#endif diff --git a/src/coreComponents/common/TableFormatter.cpp b/src/coreComponents/common/TableFormatter.cpp deleted file mode 100644 index 7f8ee69215d..00000000000 --- a/src/coreComponents/common/TableFormatter.cpp +++ /dev/null @@ -1,396 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2018-2020 TotalEnergies - * Copyright (c) 2019- GEOSX Contributors - * All rights reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - -/** - * @file TableFormatter.cpp - */ - -#include "common/TableFormatter.hpp" -namespace geos -{ - -TableFormatter::TableFormatter( TableLayout const & tableLayout ): - m_tableLayout( tableLayout ) -{} - -void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > const & rows ) const -{ - for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) - { - if( rows[idxRow].size()!=columns.size()) - { - - GEOS_WARNING( GEOS_FMT( "{}{}{}", "The number of columns in row ", - idxRow, - " that has been collected is not equal to the columns expected when TableLayout was initialized" )); - } - columns[idxRow].columnValues.reserve( rows[idxRow].size() ); - for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) - { - columns[idxColumn].columnValues.push_back( rows[idxRow][idxColumn] ); - } - } -} - -/////////////////////////////////////////////////////////////////////// -////// CSV Formatter implementation -/////////////////////////////////////////////////////////////////////// - -TableCSVFormatter::TableCSVFormatter( TableLayout const & tableLayout ): - TableFormatter( tableLayout ) -{ - m_tableLayout = tableLayout; -} - -string TableCSVFormatter::headerToString() const -{ - std::stringstream oss; - static constexpr string_view separator = ","; - - for( std::size_t idxColumn = 0; idxColumn < m_tableLayout.getColumns().size(); ++idxColumn ) - { - oss << m_tableLayout.getColumns()[idxColumn].parameter.columnName; - if( idxColumn < m_tableLayout.getColumns().size() - 1 ) - { - oss << separator; - } - } - oss << "\n"; - return oss.str(); -} - -string TableCSVFormatter::dataToString( TableData const & tableData ) const -{ - std::vector< std::vector< string > > const rowsValues = tableData.getTableDataRows(); - std::ostringstream oss; - - for( const auto & row : rowsValues ) - { - for( size_t idxColumn = 0; idxColumn < row.size(); ++idxColumn ) - { - oss << row[idxColumn]; - if( idxColumn < row.size() - 1 ) - { - oss << ","; - } - } - oss << "\n"; - } - return oss.str(); -} - -string TableCSVFormatter::toString( TableData const & tableData ) const -{ - return headerToString() + dataToString( tableData ); -} - -/////////////////////////////////////////////////////////////////////// -////// Log Formatter implementation -/////////////////////////////////////////////////////////////////////// - -/** - * @brief Build a value cell given an alignment and spaces from "|" - * - * @param alignment The aligment of cell value - * @param value The cell value - * @param spaces The number of spaces in the cell - * @return A formated cell - */ -string buildValueCell( TableLayout::Alignment const alignment, string_view value, integer const spaces ) -{ - switch( alignment ) - { - case TableLayout::right: return GEOS_FMT( "{:>{}}", value, spaces ); - case TableLayout::left: return GEOS_FMT( "{:<{}}", value, spaces ); - case TableLayout::center: return GEOS_FMT( "{:^{}}", value, spaces ); - default: return GEOS_FMT( "{:>{}}", value, spaces ); - } -} - -TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): - TableFormatter( tableLayout ) -{} - -string TableTextFormatter::toString( TableData const & tableData ) const -{ - std::ostringstream tableOutput; - string sectionSeparator; - std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); - integer const nbRows = tableData.getTableDataRows().size(); - - fillTableColumnsFromRows( columns, tableData.getTableDataRows() ); - - layoutToString( tableOutput, columns, nbRows, sectionSeparator ); - buildSectionRows( columns, sectionSeparator, tableOutput, nbRows, TableLayout::Section::values ); - tableOutput << '\n'; - - return tableOutput.str(); -} - -string TableTextFormatter::layoutToString() const -{ - std::ostringstream tableOutput; - std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); - string sectionSeparator; - - layoutToString( tableOutput, columns, 0, sectionSeparator ); - - return tableOutput.str(); -} - -void TableTextFormatter::layoutToString( std::ostringstream & tableOutput, - std::vector< TableLayout::Column > & columns, - integer const nbRow, - string & sectionSeparator ) const -{ - string titleRows; - string topSeparator; - size_t largestHeaderVectorSize = 0; - std::vector< std::vector< string > > splitHeader; - string const tableTitle = string( m_tableLayout.getTitle()); - - parseAndStoreHeaderSections( columns, largestHeaderVectorSize, splitHeader ); - adjustHeaderSizesAndStore( columns, largestHeaderVectorSize, splitHeader ); - - findAndSetMaxStringSize( columns, nbRow ); - computeAndBuildSeparator( columns, topSeparator, sectionSeparator ); - - if( !tableTitle.empty()) - { - buildTitleRow( titleRows, topSeparator, sectionSeparator ); - tableOutput << titleRows; - } - - tableOutput << sectionSeparator + '\n'; - buildSectionRows( columns, sectionSeparator, tableOutput, largestHeaderVectorSize, TableLayout::Section::header ); -} - -void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout::Column > const & columns, - size_t & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ) const -{ - for( auto const & column : columns ) - { - std::vector< string > splitHeaderParts; - std::istringstream ss( column.parameter.columnName ); - string subColumnNames; - - while( getline( ss, subColumnNames, '\n' )) - { - splitHeaderParts.push_back( subColumnNames ); - } - - size_t const cellSize = splitHeaderParts.size(); - largestHeaderVectorSize = std::max( largestHeaderVectorSize, cellSize ); - - splitHeader.push_back( splitHeaderParts ); - } -} - -void TableTextFormatter::adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, - size_t const & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ) const -{ - for( size_t columnParamIdx = 0; columnParamIdx < columns.size(); ++columnParamIdx ) - { - if( splitHeader[columnParamIdx].size() < largestHeaderVectorSize ) - { - integer const whiteRowToAdd = largestHeaderVectorSize - splitHeader[columnParamIdx].size(); - splitHeader[columnParamIdx].insert( splitHeader[columnParamIdx].end(), whiteRowToAdd, " " ); - } - columns[columnParamIdx].parameter.splitColumnName = splitHeader[columnParamIdx]; - } -} - -void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, - size_t const & nbRows ) const -{ - string maxStringSize = ""; - for( auto & column : columns ) - { - auto it = std::max_element( column.parameter.splitColumnName.begin(), - column.parameter.splitColumnName.end(), - []( const auto & a, const auto & b ) { - return a.size() < b.size(); - } ); - - maxStringSize = *it; - for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) - { - string cell = column.columnValues[idxRow]; - - if( maxStringSize.length() < cell.length()) - { - maxStringSize = cell; - } - } - - column.m_maxStringSize = maxStringSize; - } -} - -void TableTextFormatter::computeAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, - string::size_type const sectionlineLength, - string::size_type const titleLineLength ) const -{ - integer extraLinesPerColumn; - integer extraLines; - integer newStringSize; - - extraLines = titleLineLength - sectionlineLength; - extraLinesPerColumn = std::ceil( extraLines / columns.size() ); - - for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) - { - newStringSize = extraLinesPerColumn + columns[idxColumn].m_maxStringSize.size(); - if( idxColumn == columns.size() - 1 || columns.size() == 1 ) - { - columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", - columns[idxColumn].m_maxStringSize, - newStringSize + m_tableLayout.getColumnMargin() ); - } - else - { - columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", - columns[idxColumn].m_maxStringSize, - newStringSize ); - } - } -} - -void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Column > & columns, - string & topSeparator, - string & sectionSeparator ) const -{ - integer const columnMargin = m_tableLayout.getColumnMargin(); - integer const borderMargin = m_tableLayout.getBorderMargin(); - integer const marginTitle = m_tableLayout.getMarginTitle(); - string tableTitle = string( m_tableLayout.getTitle() ); - - string::size_type sectionlineLength = 0; - string::size_type const titleLineLength = tableTitle.length() + ( marginTitle * 2 ); - integer const nbSpaceBetweenColumn = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); - - if( !tableTitle.empty()) - { - tableTitle = GEOS_FMT( "{:^{}}", tableTitle, titleLineLength ); - } - - for( auto const & column : columns ) - { - sectionlineLength += column.m_maxStringSize.length(); - } - - sectionlineLength += nbSpaceBetweenColumn; - if( sectionlineLength < titleLineLength ) - { - computeAndSetMaxStringSize( columns, sectionlineLength, titleLineLength ); - } - if( columns.size() == 1 ) - { - sectionSeparator += GEOS_FMT( "+{:-<{}}+", - "", - ( columns[0].m_maxStringSize.length() + (borderMargin - 1) + columnMargin )); - } - else - { - for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) - { - integer const cellSize = columns[idxColumn].m_maxStringSize.length(); - if( idxColumn == 0 ) - { - sectionSeparator += GEOS_FMT( "+{:-<{}}", "", ( cellSize + borderMargin )); - } - else if( idxColumn == (columns.size() - 1)) - { - sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); - sectionSeparator += GEOS_FMT( "{:->{}}", "+", ( cellSize + borderMargin + 1 ) ); - } - else - { - sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); - sectionSeparator += GEOS_FMT( "{:->{}}", "", cellSize ); - } - } - } - topSeparator = GEOS_FMT( "+{:-<{}}+", "", sectionSeparator.size() - 2 ); // -2 for ++ -} - -void TableTextFormatter::buildTitleRow( string & titleRows, - string_view topSeparator, - string_view sectionSeparator ) const -{ - titleRows = GEOS_FMT( "\n{}\n|", topSeparator ); - titleRows += buildValueCell( TableLayout::Alignment::center, - m_tableLayout.getTitle(), - (sectionSeparator.length() - 2) // -2 for || - ); - titleRows += GEOS_FMT( "{}\n", "|" ); -} - -void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > const & columns, - string_view sectionSeparator, - std::ostringstream & tableRows, - integer const nbRows, - TableLayout::Section const section ) const -{ - integer const columnMargin = m_tableLayout.getColumnMargin(); - integer const borderMargin = m_tableLayout.getBorderMargin(); - - for( integer idxRow = 0; idxRow< nbRows; ++idxRow ) - { - tableRows << GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); - for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) - { - string cell; - - if( section == TableLayout::Section::header ) - { - cell = columns[idxColumn].parameter.splitColumnName[idxRow]; - } - else - { - cell = columns[idxColumn].columnValues[idxRow]; - } - integer const cellSize = columns[idxColumn].m_maxStringSize.length(); - tableRows << buildValueCell( columns[idxColumn].parameter.alignment, - cell, - cellSize ); - - if( idxColumn < columns.size() - 1 ) - { - tableRows << GEOS_FMT( "{:^{}}", "|", columnMargin ); - } - - } - - if( columns.size() == 1 ) - { - tableRows << GEOS_FMT( "{:>{}}\n", "|", columnMargin ); - } - else - { - tableRows << GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); - } - - } - if( nbRows != 0 ) - { - tableRows << GEOS_FMT( "{}\n", sectionSeparator ); - } -} - - -} diff --git a/src/coreComponents/common/TableFormatter.hpp b/src/coreComponents/common/TableFormatter.hpp deleted file mode 100644 index 1132f880c43..00000000000 --- a/src/coreComponents/common/TableFormatter.hpp +++ /dev/null @@ -1,187 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2018-2020 TotalEnergies - * Copyright (c) 2019- GEOSX Contributors - * All rights reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - -/** - * @file TableFormatter.hpp - */ - -#ifndef GEOS_COMMON_TABLEFORMATTER_HPP -#define GEOS_COMMON_TABLEFORMATTER_HPP - -#include "common/TableData.hpp" -#include "common/TableLayout.hpp" - -namespace geos -{ - -// Class for formatting table data -class TableFormatter -{ -public: - - /** - * @brief Construct a new Table Formatter from a tableLayout - * @param tableLayout Contain all column names and optionnaly the table title - */ - TableFormatter( TableLayout const & tableLayout ); - - /** - * @brief Fill the vector (m_column) in tableData with values from m_rows in tableLayout, storing all values in an unsorted order. - * @param columns Vector of columns to be filled. - * @param tableData Vector of table data. - */ - void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > const & tableData ) const; - -protected: - - TableLayout m_tableLayout; -}; - -class TableCSVFormatter : public TableFormatter -{ -public: - - /** - * @brief Construct a new Table Formatter from a tableLayout - * @param tableLayout Contain all column names and optionnaly the table title - */ - TableCSVFormatter( TableLayout const & tableLayout ); - - /** - * @brief Convert the table data to a CSV string. - * @param tableData The 1D table data. - * @return The CSV string representation of the table data. - */ - string dataToString( TableData const & tableData ) const; - - /** - * @return The string with all column names. - */ - string headerToString() const; - - /** - * @brief Convert the TableData to a table string. - * @param tableData The TableData to convert. - * @return The table string representation of the TableData. - */ - string toString( TableData const & tableData ) const; - -}; - -class TableTextFormatter : public TableFormatter -{ - -public: - - /** - * @brief Construct a new TableFormatter from a tableLayout - * @param tableLayout Contain all column names and optionnaly the table title - */ - TableTextFormatter( TableLayout const & tableLayout ); - - /** - * @brief Convert the TableData to a table string. - * @param tableData The TableData to convert. - * @return The table string representation of the TableData. - */ - string toString( TableData const & tableData ) const; - - /** - * @brief Converts a TableLayout into a formatted string representation. - * @return string - */ - string layoutToString() const; - -private: - - /** - * @brief Converts a TableLayout into a formatted representation. - * @param tableOutput The output stream - * @param columns The vectors of table columns - * @param nbRows Number of rows in the table - * @param sectionSeparator An empty string for building the section separator - */ - void layoutToString( std::ostringstream & tableOutput, - std::vector< TableLayout::Column > & columns, - integer const nbRows, - string & sectionSeparator ) const; - - /** - * @brief Split all header names by detecting the newline \\n character. - * @param splitHeader A empty vector who will contain all split header names - * @param largestHeaderVectorSize The largest split header vector size - */ - void parseAndStoreHeaderSections( std::vector< TableLayout::Column > const & columns, - size_t & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ) const; - - /** - * @brief Set the same vector size for each split header and merge it into columns - * @param columns The table columns to be merged - * @param largestHeaderVectorSize The reference value for adjusting splitHeader vector - * @param splitHeader The vector containing all split headers - */ - void adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, - size_t const & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ) const; - - /** - * @brief For each column find and set the column's longest string - */ - void findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, size_t const & nbRows ) const; - - /** - * @brief Compute the largest string size in the table. If the table title is the largest string size in the table, recalculate for all - * columns the \p m_maxStringSize value by adding extra characters - * @param sectionlineLength The length of a section line - * @param titleLineLength The length of a title line - */ - void computeAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, - string::size_type const sectionlineLength, - string::size_type const titleLineLength ) const; - - /** - * @brief Compute and build the top and the section line separator - * @param topSeparator An empty string to be built - * @param sectionSeparator An empty string to be built - */ - void computeAndBuildSeparator( std::vector< TableLayout::Column > & columns, - string & topSeparator, - string & sectionSeparator ) const; - - /** - * @brief Build the table title section - * @param titleRows Rows containing the title section. - * @param topSeparator The top line separator - * @param sectionSeparator The section line separator - */ - void buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ) const; - - /** - * @brief Build a section by specifying it's type ( header or section ) - * @param sectionSeparator Line separator between sections - * @param rows A section row - * @param nbRows Indicates the number of lines in a section - * @param section The section to be built - */ - void buildSectionRows( std::vector< TableLayout::Column > const & columns, - string_view sectionSeparator, - std::ostringstream & rows, - integer const nbRows, - TableLayout::Section const section ) const; -}; -} - -#endif diff --git a/src/coreComponents/common/TableLayout.cpp b/src/coreComponents/common/TableLayout.cpp deleted file mode 100644 index 3b4d84ddf2d..00000000000 --- a/src/coreComponents/common/TableLayout.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2018-2020 TotalEnergies - * Copyright (c) 2019- GEOSX Contributors - * All rights reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - -/** - * @file TableData.hpp - */ - -#include "common/TableLayout.hpp" - -namespace geos -{ - -TableLayout::TableLayout( std::vector< string > const & headers, string const & title ): - m_tableTitle( title ) -{ - setMargin( MarginValue::medium ); - for( size_t idx = 0; idx< headers.size(); ++idx ) - { - m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::right, true}, {}, ""} ); - } -} - -TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title ): - m_tableTitle( title ) -{ - setMargin( MarginValue::medium ); - - for( size_t idx = 0; idx< columnParameter.size(); ++idx ) - { - if( columnParameter[idx].enabled ) - { - m_columns.push_back( {columnParameter[idx], {}, ""} ); - } - - } -} - -void TableLayout::setMargin( MarginValue marginValue ) -{ - m_borderMargin = marginValue; - m_columnMargin = integer( marginValue ) * 2 + 1; -} - -std::vector< TableLayout::Column > const & TableLayout::getColumns() const -{ - return m_columns; -} - -string_view TableLayout::getTitle() const -{ - return m_tableTitle; -} - - -integer const & TableLayout::getBorderMargin() const -{ - return m_borderMargin; -} - -integer const & TableLayout::getColumnMargin() const -{ - return m_columnMargin; -} - -integer const & TableLayout::getMarginTitle() const -{ - return m_marginTitle; -} - -} diff --git a/src/coreComponents/common/TableLayout.hpp b/src/coreComponents/common/TableLayout.hpp deleted file mode 100644 index 2040a792857..00000000000 --- a/src/coreComponents/common/TableLayout.hpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2018-2020 TotalEnergies - * Copyright (c) 2019- GEOSX Contributors - * All rights reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - -/** - * @file TableLayout.hpp - */ - -#ifndef GEOS_COMMON_TABLELAYOUT_HPP -#define GEOS_COMMON_TABLELAYOUT_HPP - -#include "common/DataTypes.hpp" - -namespace geos -{ - -class TableLayout -{ - -public: - enum Alignment { right, left, center }; - - enum MarginValue : integer - { - tiny = 0, - small = 1, - medium = 2, - large = 3 - }; - - /** - * @brief Enumeration for table sections. - */ - enum Section { header, values }; - - /** - * @brief Structure to set up each colum parameters. - */ - struct ColumnParam - { - string columnName; - // Alignment for a column. By default aligned to the right side - Alignment alignment = Alignment::right; - // A boolean to display a colummn - bool enabled = true; - // Vector containing substring column name delimited by "\n" - std::vector< string > splitColumnName; - - /** - * @brief Construct a ColumnParam object with the specified name and alignment. - * @param name The name of the column - * @param align The alignment of the column - */ - ColumnParam( std::string const & name, Alignment align ) - : columnName( name ), alignment( align ) - {} - - /** - * @brief Construct a ColumnParam object with the specified name, alignment, and display flag. - * @param name The name of the column - * @param align The alignment of the column - * @param display Flag indicating whether the column is enabled - */ - ColumnParam( std::string const & name, Alignment align, bool display ) - : columnName( name ), alignment( align ), enabled( display ) - {} - }; - - /** - * @brief Struct for a column. - */ - struct Column - { - ColumnParam parameter; - // A vector containing all column values - std::vector< string > columnValues; - // The largest string in the column - string m_maxStringSize; - }; - - /** - * @brief Construct a new Table object, all values in the table are centered by default - * @param columnNames The names of the columns - */ - TableLayout( std::vector< string > const & columnNames, string const & title = "" ); - - /** - * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels - * level - * @param columnParameter List of structures to set up each colum parameters. - */ - TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title = "" ); - - /** - * @return The columns vector - */ - std::vector< Column > const & getColumns() const; - - /** - * @return The table name - */ - string_view getTitle() const; - - /** - * @return The border margin - */ - integer const & getBorderMargin() const; - - /** - * @return The column margin - */ - integer const & getColumnMargin() const; - - /** - * @return The margin title - */ - integer const & getMarginTitle() const; - -private: - - /** - * @brief Set the minimal margin width between row content and borders. - * @param marginType The margin value - */ - void setMargin( MarginValue marginValue ); - - std::vector< Column > m_columns; - string m_tableTitle; - integer m_borderMargin; - integer m_columnMargin; - integer m_marginTitle = 2; - -}; -} - -#endif diff --git a/src/coreComponents/common/unitTests/testTable.cpp b/src/coreComponents/common/unitTests/testTable.cpp deleted file mode 100644 index c6edd86881b..00000000000 --- a/src/coreComponents/common/unitTests/testTable.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/* - * ------------------------------------------------------------------------------------------------------------ - * SPDX-License-Identifier: LGPL-2.1-only - * - * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC - * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University - * Copyright (c) 2018-2020 TotalEnergies - * Copyright (c) 2019- GEOSX Contributors - * All rights reserved - * - * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. - * ------------------------------------------------------------------------------------------------------------ - */ - -// Source includes -#include "common/TableData.hpp" -#include "common/TableFormatter.hpp" -#include "common/TableLayout.hpp" -#include "dataRepository/Group.hpp" -// TPL includes -#include - -using namespace geos; - - -TEST( testTable, tableClass ) -{ - - //table with empty row - { - TableLayout const tableLayout( {"Well\nelement no.\nPV weighted\nbar", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement"}, - "InternalWellGenerator well_injector1" - ); - - TableData tableData; - tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); - tableData.addRow( "", "", "", "", "" ); - tableData.addRow( "Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", "[30.21543]", "30.45465142", - 787442, 10 ); - - TableTextFormatter const tableText( tableLayout ); - EXPECT_EQ( tableText.toString( - tableData ), - "\n+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| Well | CordX | CoordZ | Prev | Next |\n" - "| element no. | | | element | element |\n" - "| PV weighted | | | | |\n" - "| bar | | | | |\n" - "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" - "| | | | | |\n" - "| Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | [30.21543] | 30.45465142 | 787442 | 10 |\n" - "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" - ); - } - - //same but with different values - { - TableLayout const tableLayout( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement"}, "InternalWellGenerator well_injector1" ); - - TableData tableData; - tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); - tableData.addRow( "", "", "", "", "" ); - tableData.addRow( "value23", "[30.21543]", "30.45465142", 787442, 10 ); - - TableTextFormatter const tableText( tableLayout ); - EXPECT_EQ( tableText.toString( tableData ), - "\n+---------------------------------------------------------------------------------------------------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| Duis fringilla, ligula sed porta fringilla, | CordX | CoordZ | Prev | Next |\n" - "| ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | | | element | element |\n" - "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" - "| | | | | |\n" - "| value23 | [30.21543] | 30.45465142 | 787442 | 10 |\n" - "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" - ); - } - - //table with TableLayout::ColumnParam - { - TableLayout const tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::right} - }, "InternalWellGenerator well_injector1" ); - - TableData tableData; - tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - - TableTextFormatter const tableText( tableLayout ); - EXPECT_EQ( tableText.toString( tableData ), - "\n+-----------------------------------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" - "| | | | | element | element |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" - ); - } - - //test with hidden column - { - TableLayout const tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left, false}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center, false}, - }, "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); - - TableData tableData; - tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - - TableTextFormatter const tableText( tableLayout ); - EXPECT_EQ( tableText.toString( tableData ), - "\n+------------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" - "| Cras egestas | CoordX | C | CoordZ |\n" - "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" - "| value1 | | 3.0 | 3.0129877 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 |\n" - "+---------------------------+---------------------+----------------------------------+-----------------------------+\n\n" - ); - } - - //test with 1 column - { - TableLayout const tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - }, "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); - - TableData tableData; - tableData.addRow( "value1" ); - tableData.addRow( "val1" ); - - TableTextFormatter const tableText( tableLayout ); - EXPECT_EQ( tableText.toString( tableData ), - "\n+-------------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "+-------------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas |\n" - "+-------------------------------------------------------------------------------------------------------------------+\n" - "| value1 |\n" - "| val1 |\n" - "+-------------------------------------------------------------------------------------------------------------------+\n\n" - ); - } - - //test without title - { - TableLayout const tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, - } - ); - - TableData tableData; - tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - - TableTextFormatter const tableText( tableLayout ); - EXPECT_EQ( tableText.toString( tableData ), - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" - "| | | | | element | element |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" - ); - } - - // if setMargin used elsewhere make it public - //test with tiny margin - // { - // TableLayout tableLayout( { - // TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - // TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - // TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, - // TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - // TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, - // TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, - // }, "InternalWellGenerator well_injector1" ); - - // //tableLayout.setMargin( TableLayout::MarginValue::tiny ); - - // TableData tableData; - // tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - // tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - - // TableTextFormatter const tableText( tableLayout ); - // EXPECT_EQ( tableText.toString( tableData ), - // "\n+-----------------------------------------------------------------+\n" - // "| InternalWellGenerator well_injector1 |\n" - // "+------------+------+-------------------+---------+-------+-------+\n" - // "|Cras egestas|CoordX| C |CoordZ |Prev | Next |\n" - // "| | | | |element|element|\n" - // "+------------+------+-------------------+---------+-------+-------+\n" - // "| value1 | | 3.0 |3.0129877|2 | 1 |\n" - // "| val1 | v|[3.045,42.02,89.25]|3 |10 | 3 |\n" - // "+------------+------+-------------------+---------+-------+-------+\n\n" - // ); - // } - - //test 2D table - { - //collect - TableData2D tableData; - - for( real64 p = 10000; p<20000; p+=5000 ) - { - for( real64 t = 400; t>=270; t+=-50.0 ) - { - real64 value = t/p; - tableData.addCell( t, p, value ); - } - } - - //convert - string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); - string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::Conversion1D tableconverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - - //format - TableLayout const tableLayout( tableconverted.headerNames ); - - //log - TableTextFormatter const tableLog( tableLayout ); - EXPECT_EQ( tableLog.toString( tableconverted.tableData ), - "+---------------------+--------------------+------------------------+\n" - "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" - "+---------------------+--------------------+------------------------+\n" - "| Temperature = 300 | 0.03 | 0.02 |\n" - "| Temperature = 350 | 0.035 | 0.023333333333333334 |\n" - "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" - "+---------------------+--------------------+------------------------+\n\n" - ); - } -} - -int main( int argc, char * * argv ) -{ - testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS();; -} diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index ab807a34f2c..5399cd7a05a 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -40,7 +40,7 @@ class TableData /** * @brief Add a row to the table - * @param row A vector of string who contains cell Values + * @param row A vector of string representing a row */ void addRow( std::vector< string > const & row ); @@ -82,12 +82,12 @@ class TableData2D void addCell( real64 rowValue, real64 columnValue, T const & value ); /** - * @brief Construct a TableData from the provided cells. + * @brief Convert and return a struct containing a 1D Table and the column vector from a TableData2D * @param targetUnit The table unit * @param rowFmt The y axis units of the table. * @param columnFmt The x axis units of the table. - * The axis units can be customize, I.E with targetUnits = pressure [K]: - * GEOS_FMT( "{} = {{}}", targetUnits) => "pressure [K] = {}" + * The axis units can be customize, by default display the axis unit. I.E with yaxis = pressure [K]: + * GEOS_FMT( "{} = {{}}", yaxis) => "pressure [K] = {}" * @return A struct containing The columnNames and the TableData */ Conversion1D buildTableData( string_view targetUnit, string_view rowFmt = "{{}}", string_view columnFmt = "{{}}" ) const; diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 372c8b7c329..02832f6dc73 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -39,7 +39,7 @@ class TableFormatter /** * @brief Fill the vector (m_column) in tableData with values from m_rows in tableLayout, storing all values in an unsorted order. * @param columns Vector of columns to be filled. - * @param tableData Vector of table data. + * @param tableData Vector containing all rows filled with values */ void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & tableData ) const; From ae4968b129f8fbfede316baa281d5ed8d94e2d03 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 4 Apr 2024 17:33:33 +0200 Subject: [PATCH 084/216] first part test 2D table crash --- src/coreComponents/fileIO/CMakeLists.txt | 5 +++++ src/coreComponents/fileIO/Table/TableData.cpp | 18 +++++++++++++++--- src/coreComponents/fileIO/Table/TableData.hpp | 13 ++++++------- .../fileIO/Table/TableFormatter.cpp | 19 ++++++++++++------- .../fileIO/Table/TableFormatter.hpp | 8 ++++---- .../{unitsTest => unitTests}/CMakeLists.txt | 2 +- .../{unitsTest => unitTests}/testTable.cpp | 17 +++++++++++++++++ 7 files changed, 60 insertions(+), 22 deletions(-) rename src/coreComponents/fileIO/Table/{unitsTest => unitTests}/CMakeLists.txt (89%) rename src/coreComponents/fileIO/Table/{unitsTest => unitTests}/testTable.cpp (96%) diff --git a/src/coreComponents/fileIO/CMakeLists.txt b/src/coreComponents/fileIO/CMakeLists.txt index e2cef4b3e96..a37d8cdfc41 100644 --- a/src/coreComponents/fileIO/CMakeLists.txt +++ b/src/coreComponents/fileIO/CMakeLists.txt @@ -94,4 +94,9 @@ blt_add_library( NAME fileIO target_include_directories( fileIO PUBLIC ${CMAKE_SOURCE_DIR}/coreComponents ) +if( GEOS_ENABLE_TESTS ) + add_subdirectory( Table/unitTests ) +endif() + + diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 0073ec41730..f5cf8f1f6ba 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -41,29 +41,41 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, string_view columnFmt ) const { TableData2D::Conversion1D tableData1D; + std::vector< real64 > headerValues; tableData1D.headerNames.push_back( string( targetUnit ) ); // looping over first line to fill columnNames for( auto const & [ columnValue, cellValue] : m_data.begin()->second ) { tableData1D.headerNames.push_back( GEOS_FMT( columnFmt, columnValue ) ); + headerValues.push_back( columnValue ); } // insert row value and row cell values + bool flag = 1; for( auto const & [rowValue, rowMap] : m_data ) { + integer i = 0; std::vector< string > currentRowValues; currentRowValues.push_back( GEOS_FMT( rowFmt, rowValue ) ); - integer idxColumn = 0; for( auto const & [columnValue, cellValue] : rowMap ) { + if( std::abs( columnValue - headerValues[i] ) < 0.01 ) + { + flag = 0; + } + currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); - ++idxColumn; + ++i; } - idxColumn = 0; tableData1D.tableData.addRow( currentRowValues ); } + if( !flag ) + { + GEOS_WARNING( "Mismatch between columnValue and headerValue" ); + } + return tableData1D; } } diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 5399cd7a05a..71c32a77a71 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -82,16 +82,15 @@ class TableData2D void addCell( real64 rowValue, real64 columnValue, T const & value ); /** - * @brief Convert and return a struct containing a 1D Table and the column vector from a TableData2D - * @param targetUnit The table unit + * @return Convert and return a struct containing a 1D Table and the column names list from a TableData2D + * @param dataDescription The table dataDescription shown at the top left side * @param rowFmt The y axis units of the table. * @param columnFmt The x axis units of the table. - * The axis units can be customize, by default display the axis unit. I.E with yaxis = pressure [K]: - * GEOS_FMT( "{} = {{}}", yaxis) => "pressure [K] = {}" - * @return A struct containing The columnNames and the TableData + * @note The rows and columns FMT can be customized. The bracket "{}" will be replaced by the axis value. + * 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 targetUnit, string_view rowFmt = "{{}}", string_view columnFmt = "{{}}" ) const; - + Conversion1D buildTableData( string_view dataDescription, string_view rowFmt = "{}", string_view columnFmt = "{}" ) const; private: using RowType = real64; diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index fb2b19beefb..a425b4aaef8 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -27,20 +27,25 @@ TableFormatter::TableFormatter( TableLayout const & tableLayout ): void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & rows ) const { + bool flag = 1; for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) { - if( rows[idxRow].size()!=columns.size()) - { - GEOS_WARNING( GEOS_FMT( "{}{}{}", "The number of columns in row ", - idxRow, - " that has been collected is not equal to the columns expected when TableLayout was initialized" )); - } - columns[idxRow].columnValues.reserve( rows[idxRow].size() ); + + // columns[idxRow].columnValues.reserve( rows[idxRow].size() ); for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) { columns[idxColumn].columnValues.push_back( rows[idxRow][idxColumn] ); } + + if( rows[idxRow].size()!=columns.size()) + { + flag = 0; + } + } + if( !flag ) + { + GEOS_WARNING( "The number of columns in rows that has been collected is not equal to the columns expected when TableLayout was initialized" ); } } diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 02832f6dc73..5de41185e2f 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -36,6 +36,10 @@ class TableFormatter */ TableFormatter( TableLayout const & tableLayout ); +protected: + + TableLayout m_tableLayout; + /** * @brief Fill the vector (m_column) in tableData with values from m_rows in tableLayout, storing all values in an unsorted order. * @param columns Vector of columns to be filled. @@ -43,10 +47,6 @@ class TableFormatter */ void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & tableData ) const; - -protected: - - TableLayout m_tableLayout; }; class TableCSVFormatter : public TableFormatter diff --git a/src/coreComponents/fileIO/Table/unitsTest/CMakeLists.txt b/src/coreComponents/fileIO/Table/unitTests/CMakeLists.txt similarity index 89% rename from src/coreComponents/fileIO/Table/unitsTest/CMakeLists.txt rename to src/coreComponents/fileIO/Table/unitTests/CMakeLists.txt index 09ced06d546..4db71486656 100644 --- a/src/coreComponents/fileIO/Table/unitsTest/CMakeLists.txt +++ b/src/coreComponents/fileIO/Table/unitTests/CMakeLists.txt @@ -2,7 +2,7 @@ set( gtest_geosx_tests testTable.cpp ) -set( dependencyList ${parallelDeps} common hdf5 gtest ) +set( dependencyList gtest fileIO ${parallelDeps} ) # Add gtest C++ based tests foreach(test ${gtest_geosx_tests}) diff --git a/src/coreComponents/fileIO/Table/unitsTest/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp similarity index 96% rename from src/coreComponents/fileIO/Table/unitsTest/testTable.cpp rename to src/coreComponents/fileIO/Table/unitTests/testTable.cpp index fea7ec2113b..e228ffd009d 100644 --- a/src/coreComponents/fileIO/Table/unitsTest/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -262,6 +262,23 @@ TEST( testTable, tableClass ) "+---------------------+--------------------+------------------------+\n\n" ); } + + //test 2D table + { + //collect + // TableData2D tableData; + + // tableData.addCell( 300, 10000, 0.03 ); + // tableData.addCell( 300, 15000, 0.02 ); + // tableData.addCell( 350, 10000, 0.035 ); + // tableData.addCell( 400, 10000, 0.04 ); + // tableData.addCell( 400, 15000, 0.02666666666666667 ); + + // //convert + // string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + // string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + // EXPECT_ANY_THROW( tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt )); + } } int main( int argc, char * * argv ) From 92a1644d2a5e5ba5c8aed04e0fa24e94a4cb05c5 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 5 Apr 2024 16:40:57 +0200 Subject: [PATCH 085/216] add test/warning for table conversion 2D => 1D and warning for filling table columns from rows --- src/coreComponents/fileIO/Table/TableData.cpp | 21 ++++-- src/coreComponents/fileIO/Table/TableData.hpp | 1 + .../fileIO/Table/TableFormatter.cpp | 10 +-- .../fileIO/Table/unitTests/testTable.cpp | 75 +++++++++++++++---- 4 files changed, 83 insertions(+), 24 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index f5cf8f1f6ba..2e18d78a970 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -42,8 +42,10 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, { TableData2D::Conversion1D tableData1D; std::vector< real64 > headerValues; + std::vector< size_t > rowsLength; tableData1D.headerNames.push_back( string( targetUnit ) ); + // looping over first line to fill columnNames for( auto const & [ columnValue, cellValue] : m_data.begin()->second ) { @@ -51,8 +53,10 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, headerValues.push_back( columnValue ); } + rowsLength.reserve( headerValues.size()); + // insert row value and row cell values - bool flag = 1; + bool flag = true; for( auto const & [rowValue, rowMap] : m_data ) { integer i = 0; @@ -60,20 +64,27 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, currentRowValues.push_back( GEOS_FMT( rowFmt, rowValue ) ); for( auto const & [columnValue, cellValue] : rowMap ) { - if( std::abs( columnValue - headerValues[i] ) < 0.01 ) + if( std::abs( columnValue - headerValues[i] ) > 0.01 ) { - flag = 0; + flag = false; } - currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); ++i; } tableData1D.tableData.addRow( currentRowValues ); + rowsLength.push_back( currentRowValues.size()); + } + + if( std::adjacent_find( rowsLength.begin(), rowsLength.end(), std::not_equal_to<>() ) != rowsLength.end() ) + { + flag = false; + GEOS_WARNING( "Cell(s) are missing in row" ); } if( !flag ) { - GEOS_WARNING( "Mismatch between columnValue and headerValue" ); + tableData1D.isConsistent = flag; + GEOS_WARNING( "Table isn't consistent" ); } return tableData1D; diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 71c32a77a71..5991f0a7f48 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -69,6 +69,7 @@ class TableData2D { std::vector< string > headerNames; TableData tableData; + bool isConsistent = true; }; /** diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index a425b4aaef8..b00e9c5d15b 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -27,12 +27,10 @@ TableFormatter::TableFormatter( TableLayout const & tableLayout ): void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & rows ) const { - bool flag = 1; + bool isConsistent = true; for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) { - - - // columns[idxRow].columnValues.reserve( rows[idxRow].size() ); + columns[idxRow].columnValues.reserve( rows[idxRow].size() ); for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) { columns[idxColumn].columnValues.push_back( rows[idxRow][idxColumn] ); @@ -40,10 +38,10 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column if( rows[idxRow].size()!=columns.size()) { - flag = 0; + isConsistent = false; } } - if( !flag ) + if( !isConsistent ) { GEOS_WARNING( "The number of columns in rows that has been collected is not equal to the columns expected when TableLayout was initialized" ); } diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index e228ffd009d..da664175748 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -19,9 +19,14 @@ #include "dataRepository/Group.hpp" // TPL includes #include +#include using namespace geos; +void failNonFatallyOnFalse( bool param ) +{ + EXPECT_TRUE( param ) << "Mismatch between columnValue and headerValue"; +} TEST( testTable, tableClass ) { @@ -263,22 +268,66 @@ TEST( testTable, tableClass ) ); } - //test 2D table + //test 2D table rows not equal (fatal failure ?) { //collect - // TableData2D tableData; - - // tableData.addCell( 300, 10000, 0.03 ); - // tableData.addCell( 300, 15000, 0.02 ); - // tableData.addCell( 350, 10000, 0.035 ); - // tableData.addCell( 400, 10000, 0.04 ); - // tableData.addCell( 400, 15000, 0.02666666666666667 ); - - // //convert - // string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); - // string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - // EXPECT_ANY_THROW( tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt )); + TableData2D tableData; + + tableData.addCell( 300, 10000, 0.03 ); + tableData.addCell( 300, 15000, 0.02 ); + tableData.addCell( 350, 10000, 0.035 ); + tableData.addCell( 350, 10000, 0.035 ); + tableData.addCell( 400, 10000, 0.04 ); + tableData.addCell( 400, 15000, 0.02666666666666667 ); + + //convert + string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + + EXPECT_FALSE( tableConverted.isConsistent ); } + + //test 2D table column mismatch + { + //collect + TableData2D tableData; + + tableData.addCell( 300, 10000, 0.03 ); + tableData.addCell( 300, 15000, 0.02 ); + tableData.addCell( 350, 10000, 0.035 ); + tableData.addCell( 350, 5000, 0.035 ); + tableData.addCell( 400, 10000, 0.04 ); + tableData.addCell( 400, 15000, 0.02666666666666667 ); + + //convert + string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + + EXPECT_FALSE( tableConverted.isConsistent ); + } + + //test 2D make sure test isn't trigger when table is consistent + { + //collect + TableData2D tableData; + + tableData.addCell( 300, 10000, 0.03 ); + tableData.addCell( 300, 15000, 0.02 ); + tableData.addCell( 350, 10000, 0.035 ); + tableData.addCell( 350, 15000, 0.035 ); + tableData.addCell( 400, 10000, 0.04 ); + tableData.addCell( 400, 15000, 0.02666666666666667 ); + + //convert + string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + + EXPECT_TRUE( tableConverted.isConsistent ); + } + } int main( int argc, char * * argv ) From e6b2e6d6b56cba5b373767813a1356e305ea6e10 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 8 Apr 2024 09:45:13 +0200 Subject: [PATCH 086/216] ci correction --- src/coreComponents/fileIO/Table/TableLayout.hpp | 2 ++ src/coreComponents/fileIO/Table/unitTests/testTable.cpp | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableLayout.hpp b/src/coreComponents/fileIO/Table/TableLayout.hpp index 2040a792857..97cdbce2be7 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.hpp +++ b/src/coreComponents/fileIO/Table/TableLayout.hpp @@ -91,6 +91,7 @@ class TableLayout /** * @brief Construct a new Table object, all values in the table are centered by default * @param columnNames The names of the columns + * @param title The table name */ TableLayout( std::vector< string > const & columnNames, string const & title = "" ); @@ -98,6 +99,7 @@ class TableLayout * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels * level * @param columnParameter List of structures to set up each colum parameters. + * @param title The table name */ TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title = "" ); diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index da664175748..d42c917aa42 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -200,8 +200,9 @@ TEST( testTable, tableClass ) "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" ); } - - // if setMargin used elsewhere make it public + //////////// + //////// If setMargin used elsewhere make it public and remove comments for this test + //////////// //test with tiny margin // { // TableLayout tableLayout( { From 18db53330e581d8267f9feaeb4e5abb206abca1b Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 9 Apr 2024 15:33:19 +0200 Subject: [PATCH 087/216] test ci correction for c++ < 17 --- src/coreComponents/fileIO/Table/TableData.cpp | 11 +++++++++++ src/coreComponents/fileIO/Table/TableData.hpp | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 2e18d78a970..d2ef6ae0a2e 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -75,11 +75,22 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, rowsLength.push_back( currentRowValues.size()); } + #if __cplusplus < 202002L + for( auto it = rowsLength.begin(); it != rowsLength.end(); ++it ) + { + if( it != rowsLength.begin() && *it != *(it - 1)) + { + flag = false; + GEOS_WARNING( "Cell(s) are missing in row" ); + } + } +#else if( std::adjacent_find( rowsLength.begin(), rowsLength.end(), std::not_equal_to<>() ) != rowsLength.end() ) { flag = false; GEOS_WARNING( "Cell(s) are missing in row" ); } + #endif if( !flag ) { diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 5991f0a7f48..0b7acd24283 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -32,7 +32,7 @@ class TableData /** * @brief Add a row to the table. - * @param Args The values passed to addRow (can be any type). + * The values passed to addRow (can be any type). * @param args Cell values to be added to the row. */ template< typename ... Args > From 31126e108a2da27ad6878be1bb833ab89e644e62 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 9 Apr 2024 17:06:28 +0200 Subject: [PATCH 088/216] test ci table2D example 1 --- src/coreComponents/fileIO/Table/TableData.cpp | 14 ++--------- .../fileIO/Table/unitTests/testTable.cpp | 24 +++++++++---------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index d2ef6ae0a2e..343a487f508 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -64,7 +64,8 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, currentRowValues.push_back( GEOS_FMT( rowFmt, rowValue ) ); for( auto const & [columnValue, cellValue] : rowMap ) { - if( std::abs( columnValue - headerValues[i] ) > 0.01 ) + //check is if the column are offset + if( std::abs( columnValue - headerValues[i] ) > 0.0 ) { flag = false; } @@ -75,22 +76,11 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, rowsLength.push_back( currentRowValues.size()); } - #if __cplusplus < 202002L - for( auto it = rowsLength.begin(); it != rowsLength.end(); ++it ) - { - if( it != rowsLength.begin() && *it != *(it - 1)) - { - flag = false; - GEOS_WARNING( "Cell(s) are missing in row" ); - } - } -#else if( std::adjacent_find( rowsLength.begin(), rowsLength.end(), std::not_equal_to<>() ) != rowsLength.end() ) { flag = false; GEOS_WARNING( "Cell(s) are missing in row" ); } - #endif if( !flag ) { diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index d42c917aa42..1f7894b9d6a 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -292,21 +292,21 @@ TEST( testTable, tableClass ) //test 2D table column mismatch { //collect - TableData2D tableData; + // TableData2D tableData; - tableData.addCell( 300, 10000, 0.03 ); - tableData.addCell( 300, 15000, 0.02 ); - tableData.addCell( 350, 10000, 0.035 ); - tableData.addCell( 350, 5000, 0.035 ); - tableData.addCell( 400, 10000, 0.04 ); - tableData.addCell( 400, 15000, 0.02666666666666667 ); + // tableData.addCell( 300, 10000, 0.03 ); + // tableData.addCell( 300, 15000, 0.02 ); + // tableData.addCell( 350, 10000, 0.035 ); + // tableData.addCell( 350, 5000, 0.035 ); + // tableData.addCell( 400, 10000, 0.04 ); + // tableData.addCell( 400, 15000, 0.02666666666666667 ); - //convert - string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); - string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + // //convert + // string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + // string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + // TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - EXPECT_FALSE( tableConverted.isConsistent ); + // EXPECT_FALSE( tableConverted.isConsistent ); } //test 2D make sure test isn't trigger when table is consistent From d481454fc5173ec71d81e06b43c5e40ade15a025 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 9 Apr 2024 17:12:47 +0200 Subject: [PATCH 089/216] test ci Table2D test 1 & 2 --- .../fileIO/Table/unitTests/testTable.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index 1f7894b9d6a..2b37211791f 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -271,22 +271,22 @@ TEST( testTable, tableClass ) //test 2D table rows not equal (fatal failure ?) { - //collect - TableData2D tableData; + // //collect + // TableData2D tableData; - tableData.addCell( 300, 10000, 0.03 ); - tableData.addCell( 300, 15000, 0.02 ); - tableData.addCell( 350, 10000, 0.035 ); - tableData.addCell( 350, 10000, 0.035 ); - tableData.addCell( 400, 10000, 0.04 ); - tableData.addCell( 400, 15000, 0.02666666666666667 ); + // tableData.addCell( 300, 10000, 0.03 ); + // tableData.addCell( 300, 15000, 0.02 ); + // tableData.addCell( 350, 10000, 0.035 ); + // tableData.addCell( 350, 10000, 0.035 ); + // tableData.addCell( 400, 10000, 0.04 ); + // tableData.addCell( 400, 15000, 0.02666666666666667 ); - //convert - string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); - string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + // //convert + // string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + // string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + // TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - EXPECT_FALSE( tableConverted.isConsistent ); + // EXPECT_FALSE( tableConverted.isConsistent ); } //test 2D table column mismatch From 6a7bfe847bb4be0462e605ee778b7dd07fbd9449 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 9 Apr 2024 17:18:49 +0200 Subject: [PATCH 090/216] test ci Table2D test 1 & 2 & 3 --- .../fileIO/Table/unitTests/testTable.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index 2b37211791f..b49ece23d68 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -312,21 +312,21 @@ TEST( testTable, tableClass ) //test 2D make sure test isn't trigger when table is consistent { //collect - TableData2D tableData; + // TableData2D tableData; - tableData.addCell( 300, 10000, 0.03 ); - tableData.addCell( 300, 15000, 0.02 ); - tableData.addCell( 350, 10000, 0.035 ); - tableData.addCell( 350, 15000, 0.035 ); - tableData.addCell( 400, 10000, 0.04 ); - tableData.addCell( 400, 15000, 0.02666666666666667 ); + // tableData.addCell( 300, 10000, 0.03 ); + // tableData.addCell( 300, 15000, 0.02 ); + // tableData.addCell( 350, 10000, 0.035 ); + // tableData.addCell( 350, 15000, 0.035 ); + // tableData.addCell( 400, 10000, 0.04 ); + // tableData.addCell( 400, 15000, 0.02666666666666667 ); - //convert - string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); - string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + // //convert + // string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + // string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + // TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - EXPECT_TRUE( tableConverted.isConsistent ); + // EXPECT_TRUE( tableConverted.isConsistent ); } } From e01523b3d4b9904d043a2d682cb5781fd5df2a8f Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 10 Apr 2024 10:18:39 +0200 Subject: [PATCH 091/216] add virtual destructor TableFormatter + minor variable refacto --- .../fileIO/Table/TableFormatter.cpp | 22 ++++++------- .../fileIO/Table/TableFormatter.hpp | 32 +++++++++++++++---- .../fileIO/Table/TableLayout.hpp | 12 ++++--- 3 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index b00e9c5d15b..5e61faef242 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -30,10 +30,10 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column bool isConsistent = true; for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) { - columns[idxRow].columnValues.reserve( rows[idxRow].size() ); + columns[idxRow].m_columnValues.reserve( rows[idxRow].size() ); for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) { - columns[idxColumn].columnValues.push_back( rows[idxRow][idxColumn] ); + columns[idxColumn].m_columnValues.push_back( rows[idxRow][idxColumn] ); } if( rows[idxRow].size()!=columns.size()) @@ -64,7 +64,7 @@ string TableCSVFormatter::headerToString() const for( std::size_t idxColumn = 0; idxColumn < m_tableLayout.getColumns().size(); ++idxColumn ) { - oss << m_tableLayout.getColumns()[idxColumn].parameter.columnName; + oss << m_tableLayout.getColumns()[idxColumn].m_parameter.columnName; if( idxColumn < m_tableLayout.getColumns().size() - 1 ) { oss << separator; @@ -187,7 +187,7 @@ void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout:: for( auto const & column : columns ) { std::vector< string > splitHeaderParts; - std::istringstream ss( column.parameter.columnName ); + std::istringstream ss( column.m_parameter.columnName ); string subColumnNames; while( getline( ss, subColumnNames, '\n' )) @@ -213,7 +213,7 @@ void TableTextFormatter::adjustHeaderSizesAndStore( std::vector< TableLayout::Co integer const whiteRowToAdd = largestHeaderVectorSize - splitHeader[columnParamIdx].size(); splitHeader[columnParamIdx].insert( splitHeader[columnParamIdx].end(), whiteRowToAdd, " " ); } - columns[columnParamIdx].parameter.splitColumnName = splitHeader[columnParamIdx]; + columns[columnParamIdx].m_parameter.splitColumnName = splitHeader[columnParamIdx]; } } @@ -223,8 +223,8 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu string maxStringSize = ""; for( auto & column : columns ) { - auto it = std::max_element( column.parameter.splitColumnName.begin(), - column.parameter.splitColumnName.end(), + auto it = std::max_element( column.m_parameter.splitColumnName.begin(), + column.m_parameter.splitColumnName.end(), []( const auto & a, const auto & b ) { return a.size() < b.size(); } ); @@ -232,7 +232,7 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu maxStringSize = *it; for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) { - string cell = column.columnValues[idxRow]; + string cell = column.m_columnValues[idxRow]; if( maxStringSize.length() < cell.length()) { @@ -361,14 +361,14 @@ void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > co if( section == TableLayout::Section::header ) { - cell = columns[idxColumn].parameter.splitColumnName[idxRow]; + cell = columns[idxColumn].m_parameter.splitColumnName[idxRow]; } else { - cell = columns[idxColumn].columnValues[idxRow]; + cell = columns[idxColumn].m_columnValues[idxRow]; } integer const cellSize = columns[idxColumn].m_maxStringSize.length(); - tableRows << buildValueCell( columns[idxColumn].parameter.alignment, + tableRows << buildValueCell( columns[idxColumn].m_parameter.alignment, cell, cellSize ); diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 5de41185e2f..00a395213d7 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -25,10 +25,15 @@ namespace geos { -// Class for formatting table data +/** + * @brief abstract class for formatting table data + */ class TableFormatter { -public: + +protected: + + TableLayout m_tableLayout; /** * @brief Construct a new Table Formatter from a tableLayout @@ -36,19 +41,24 @@ class TableFormatter */ TableFormatter( TableLayout const & tableLayout ); -protected: - - TableLayout m_tableLayout; + /** + * @brief Destroy the Table Formatter object + */ + virtual ~TableFormatter() = default; /** - * @brief Fill the vector (m_column) in tableData with values from m_rows in tableLayout, storing all values in an unsorted order. + * @brief Fill the vector (m_column) in tableData with values from rows stored in tableLayout. * @param columns Vector of columns to be filled. * @param tableData Vector containing all rows filled with values */ void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & tableData ) const; + }; +/** + * @brief + */ class TableCSVFormatter : public TableFormatter { public: @@ -59,6 +69,11 @@ class TableCSVFormatter : public TableFormatter */ TableCSVFormatter( TableLayout const & tableLayout ); + /** + * @brief Destroy the TableCSVFormatter object + */ + virtual ~TableCSVFormatter() = default; + /** * @brief Convert the table data to a CSV string. * @param tableData The 1D table data. @@ -91,6 +106,11 @@ class TableTextFormatter : public TableFormatter */ TableTextFormatter( TableLayout const & tableLayout ); + /** + * @brief Destroy the Table Text Formatter object + */ + virtual ~TableTextFormatter() = default; + /** * @brief Convert the TableData to a table string. * @param tableData The TableData to convert. diff --git a/src/coreComponents/fileIO/Table/TableLayout.hpp b/src/coreComponents/fileIO/Table/TableLayout.hpp index 97cdbce2be7..d79a8c6af7d 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.hpp +++ b/src/coreComponents/fileIO/Table/TableLayout.hpp @@ -24,6 +24,9 @@ namespace geos { +/** + * @brief + */ class TableLayout { @@ -81,10 +84,11 @@ class TableLayout */ struct Column { - ColumnParam parameter; - // A vector containing all column values - std::vector< string > columnValues; - // The largest string in the column + /// Structure who contains parameters for a column + ColumnParam m_parameter; + /// A vector containing all column values + std::vector< string > m_columnValues; + /// The largest string in the column string m_maxStringSize; }; From 978674e3fa43da513ed05f2e372b87a7d74c1dbb Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 10 Apr 2024 16:05:58 +0200 Subject: [PATCH 092/216] bug correction + missing doc + test small refacto --- src/coreComponents/fileIO/Table/TableData.cpp | 2 - src/coreComponents/fileIO/Table/TableData.hpp | 11 +- .../fileIO/Table/TableFormatter.cpp | 38 +- .../fileIO/Table/TableFormatter.hpp | 13 +- .../fileIO/Table/TableLayout.cpp | 5 - .../fileIO/Table/TableLayout.hpp | 9 +- .../fileIO/Table/unitTests/testTable.cpp | 517 +++++++++--------- 7 files changed, 314 insertions(+), 281 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 343a487f508..97b9488d3f9 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -53,8 +53,6 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, headerValues.push_back( columnValue ); } - rowsLength.reserve( headerValues.size()); - // insert row value and row cell values bool flag = true; for( auto const & [rowValue, rowMap] : m_data ) diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 0b7acd24283..774e8c4c562 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -25,7 +25,9 @@ namespace geos { -// Class for managing table data +/** + * @brief Class for managing table data + */ class TableData { public: @@ -60,15 +62,20 @@ class TableData }; -// Class for managing 2D table m_data +/** + * @brief Class for managing 2D table m_data + */ class TableData2D { public: struct Conversion1D { + /// Vector containing all columns names std::vector< string > headerNames; + /// TableData to be built TableData tableData; + /// Indicate if there are any inconsistencies when TableDate2d is converted bool isConsistent = true; }; diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 5e61faef242..86f71550ccc 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -30,17 +30,21 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column bool isConsistent = true; for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) { - columns[idxRow].m_columnValues.reserve( rows[idxRow].size() ); for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) { - columns[idxColumn].m_columnValues.push_back( rows[idxRow][idxColumn] ); + // Case of a disabled column when we initialized + if( m_tableLayout.getColumns()[idxColumn].m_parameter.enabled ) + { + columns[idxColumn].m_columnValues.push_back( rows[idxRow][idxColumn] ); + } } - if( rows[idxRow].size()!=columns.size()) + if( rows[idxRow].size()!=columns.size() ) { isConsistent = false; } } + if( !isConsistent ) { GEOS_WARNING( "The number of columns in rows that has been collected is not equal to the columns expected when TableLayout was initialized" ); @@ -122,6 +126,28 @@ string buildValueCell( TableLayout::Alignment const alignment, string_view value } } +/** + * @brief Detect columns not displayed from TableLayout and therefore modify columns / tableDataRows vectors + * @param columns Vector built in TableLayout containing all columns with their parameters + * @param tableDataRows Vector built in TableData containing all rows values + */ +void formatColumnsFromLayout( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > & tableDataRows ) +{ + integer idxColumn = 0; + for( auto & column : columns ) + { + if( !column.m_parameter.enabled ) + { + columns.erase( columns.begin() + idxColumn ); + for( auto & row : tableDataRows ) + { + row.erase( row.begin() + idxColumn ); + } + } + ++idxColumn; + } +} + TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): TableFormatter( tableLayout ) {} @@ -131,9 +157,11 @@ string TableTextFormatter::toString( TableData const & tableData ) const std::ostringstream tableOutput; string sectionSeparator; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); - integer const nbRows = tableData.getTableDataRows().size(); + std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); + integer const nbRows = tableDataRows.size(); - fillTableColumnsFromRows( columns, tableData.getTableDataRows() ); + formatColumnsFromLayout( columns, tableDataRows ); + fillTableColumnsFromRows( columns, tableDataRows ); layoutToString( tableOutput, columns, nbRows, sectionSeparator ); buildSectionRows( columns, sectionSeparator, tableOutput, nbRows, TableLayout::Section::values ); diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 00a395213d7..87e8579cd0a 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -44,7 +44,7 @@ class TableFormatter /** * @brief Destroy the Table Formatter object */ - virtual ~TableFormatter() = default; + virtual ~TableFormatter() = default; /** * @brief Fill the vector (m_column) in tableData with values from rows stored in tableLayout. @@ -53,11 +53,11 @@ class TableFormatter */ void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & tableData ) const; - + }; /** - * @brief + * @brief class for CSV formatting */ class TableCSVFormatter : public TableFormatter { @@ -72,7 +72,7 @@ class TableCSVFormatter : public TableFormatter /** * @brief Destroy the TableCSVFormatter object */ - virtual ~TableCSVFormatter() = default; + virtual ~TableCSVFormatter() = default; /** * @brief Convert the table data to a CSV string. @@ -95,6 +95,9 @@ class TableCSVFormatter : public TableFormatter }; +/** + * @brief class for log formatting + */ class TableTextFormatter : public TableFormatter { @@ -109,7 +112,7 @@ class TableTextFormatter : public TableFormatter /** * @brief Destroy the Table Text Formatter object */ - virtual ~TableTextFormatter() = default; + virtual ~TableTextFormatter() = default; /** * @brief Convert the TableData to a table string. diff --git a/src/coreComponents/fileIO/Table/TableLayout.cpp b/src/coreComponents/fileIO/Table/TableLayout.cpp index eb9134f7695..e4f44f018c0 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.cpp +++ b/src/coreComponents/fileIO/Table/TableLayout.cpp @@ -35,14 +35,9 @@ TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter, st m_tableTitle( title ) { setMargin( MarginValue::medium ); - for( size_t idx = 0; idx< columnParameter.size(); ++idx ) { - if( columnParameter[idx].enabled ) - { m_columns.push_back( {columnParameter[idx], {}, ""} ); - } - } } diff --git a/src/coreComponents/fileIO/Table/TableLayout.hpp b/src/coreComponents/fileIO/Table/TableLayout.hpp index d79a8c6af7d..4ff78d65a61 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.hpp +++ b/src/coreComponents/fileIO/Table/TableLayout.hpp @@ -25,7 +25,7 @@ namespace geos { /** - * @brief + * @brief Class for setup the table layout */ class TableLayout { @@ -51,12 +51,13 @@ class TableLayout */ struct ColumnParam { + /// Name for a column string columnName; - // Alignment for a column. By default aligned to the right side + /// Alignment for a column. By default aligned to the right side Alignment alignment = Alignment::right; - // A boolean to display a colummn + /// A boolean to display a colummn bool enabled = true; - // Vector containing substring column name delimited by "\n" + /// Vector containing substring column name delimited by "\n" std::vector< string > splitColumnName; /** diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index b49ece23d68..2b96a30e16b 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -1,3 +1,4 @@ + /* * ------------------------------------------------------------------------------------------------------------ * SPDX-License-Identifier: LGPL-2.1-only @@ -23,183 +24,279 @@ using namespace geos; -void failNonFatallyOnFalse( bool param ) +TEST( testTable, tableEmptyRow ) { - EXPECT_TRUE( param ) << "Mismatch between columnValue and headerValue"; + //table with empty row + TableLayout const tableLayout( {"Well\nelement no.\nPV weighted\nbar", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"}, + "InternalWellGenerator well_injector1" + ); + + TableData tableData; + tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); + tableData.addRow( "", "", "", "", "" ); + tableData.addRow( "Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", "[30.21543]", "30.45465142", + 787442, 10 ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( + tableData ), + "\n+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| Well | CordX | CoordZ | Prev | Next |\n" + "| element no. | | | element | element |\n" + "| PV weighted | | | | |\n" + "| bar | | | | |\n" + "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" + "| | | | | |\n" + "| Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | [30.21543] | 30.45465142 | 787442 | 10 |\n" + "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" + ); } -TEST( testTable, tableClass ) +TEST( testTable, tableClassic ) { + TableLayout const tableLayout( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"}, "InternalWellGenerator well_injector1" ); + + TableData tableData; + tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); + tableData.addRow( "", "", "", "", "" ); + tableData.addRow( "value23", "[30.21543]", "30.45465142", 787442, 10 ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableData ), + "\n+---------------------------------------------------------------------------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| Duis fringilla, ligula sed porta fringilla, | CordX | CoordZ | Prev | Next |\n" + "| ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | | | element | element |\n" + "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" + "| | | | | |\n" + "| value23 | [30.21543] | 30.45465142 | 787442 | 10 |\n" + "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" + ); +} - //table with empty row - { - TableLayout const tableLayout( {"Well\nelement no.\nPV weighted\nbar", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement"}, - "InternalWellGenerator well_injector1" - ); - - TableData tableData; - tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); - tableData.addRow( "", "", "", "", "" ); - tableData.addRow( "Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", "[30.21543]", "30.45465142", - 787442, 10 ); - - TableTextFormatter const tableText( tableLayout ); - EXPECT_EQ( tableText.toString( - tableData ), - "\n+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| Well | CordX | CoordZ | Prev | Next |\n" - "| element no. | | | element | element |\n" - "| PV weighted | | | | |\n" - "| bar | | | | |\n" - "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" - "| | | | | |\n" - "| Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | [30.21543] | 30.45465142 | 787442 | 10 |\n" - "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" - ); - } +TEST( testTable, tableColumnParamClassic ) +{ + TableLayout const tableLayout( { + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::right}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::right} + }, "InternalWellGenerator well_injector1" ); + + TableData tableData; + tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableData ), + "\n+-----------------------------------------------------------------------------------------+\n" + "| InternalWellGenerator well_injector1 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" + "| | | | | element | element |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" + ); +} - //same but with different values - { - TableLayout const tableLayout( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement"}, "InternalWellGenerator well_injector1" ); - - TableData tableData; - tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); - tableData.addRow( "", "", "", "", "" ); - tableData.addRow( "value23", "[30.21543]", "30.45465142", 787442, 10 ); - - TableTextFormatter const tableText( tableLayout ); - EXPECT_EQ( tableText.toString( tableData ), - "\n+---------------------------------------------------------------------------------------------------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| Duis fringilla, ligula sed porta fringilla, | CordX | CoordZ | Prev | Next |\n" - "| ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | | | element | element |\n" - "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" - "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" - "| | | | | |\n" - "| value23 | [30.21543] | 30.45465142 | 787442 | 10 |\n" - "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" - ); - } +TEST( testTable, tableHiddenColumn ) +{ + TableLayout const tableLayout( { + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left, false}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center, false}, + }, "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + + TableData tableData; + tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableData ), + "\n+------------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" + "| Cras egestas | CoordX | C | CoordZ |\n" + "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" + "| value1 | | 3.0 | 3.0129877 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 |\n" + "+---------------------------+---------------------+----------------------------------+-----------------------------+\n\n" + ); +} - //table with TableLayout::ColumnParam - { - TableLayout const tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::right} - }, "InternalWellGenerator well_injector1" ); - - TableData tableData; - tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - - TableTextFormatter const tableText( tableLayout ); - EXPECT_EQ( tableText.toString( tableData ), - "\n+-----------------------------------------------------------------------------------------+\n" - "| InternalWellGenerator well_injector1 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" - "| | | | | element | element |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" - ); - } +TEST( testTable, tableUniqueColumn ) +{ + TableLayout const tableLayout( { + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, + }, "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + + TableData tableData; + tableData.addRow( "value1" ); + tableData.addRow( "val1" ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableData ), + "\n+-------------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "+-------------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas |\n" + "+-------------------------------------------------------------------------------------------------------------------+\n" + "| value1 |\n" + "| val1 |\n" + "+-------------------------------------------------------------------------------------------------------------------+\n\n" + ); +} - //test with hidden column - { - TableLayout const tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left, false}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center, false}, - }, "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); - - TableData tableData; - tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - - TableTextFormatter const tableText( tableLayout ); - EXPECT_EQ( tableText.toString( tableData ), - "\n+------------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" - "| Cras egestas | CoordX | C | CoordZ |\n" - "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" - "| value1 | | 3.0 | 3.0129877 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 |\n" - "+---------------------------+---------------------+----------------------------------+-----------------------------+\n\n" - ); +TEST( testTable, tableEmptyTitle ) +{ + TableLayout const tableLayout( { + TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, } + ); + + TableData tableData; + tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); + tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableData ), + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" + "| | | | | element | element |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" + "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" + ); +} + +TEST( testTable, table2DTable ) +{ + //collect + TableData2D tableData; - //test with 1 column + for( real64 p = 10000; p<20000; p+=5000 ) { - TableLayout const tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - }, "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); - - TableData tableData; - tableData.addRow( "value1" ); - tableData.addRow( "val1" ); - - TableTextFormatter const tableText( tableLayout ); - EXPECT_EQ( tableText.toString( tableData ), - "\n+-------------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "+-------------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas |\n" - "+-------------------------------------------------------------------------------------------------------------------+\n" - "| value1 |\n" - "| val1 |\n" - "+-------------------------------------------------------------------------------------------------------------------+\n\n" - ); + for( real64 t = 400; t>=270; t+=-50.0 ) + { + real64 value = t/p; + tableData.addCell( t, p, value ); + } } - //test without title + //convert + string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + TableData2D::Conversion1D tableconverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + + //format + TableLayout const tableLayout( tableconverted.headerNames ); + + //log + TableTextFormatter const tableLog( tableLayout ); + EXPECT_EQ( tableLog.toString( tableconverted.tableData ), + "+---------------------+--------------------+------------------------+\n" + "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" + "+---------------------+--------------------+------------------------+\n" + "| Temperature = 300 | 0.03 | 0.02 |\n" + "| Temperature = 350 | 0.035 | 0.023333333333333334 |\n" + "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" + "+---------------------+--------------------+------------------------+\n\n" + ); +} + +TEST( testTable, table2DInequalRows ) +{ + //collect + TableData2D tableData; + + tableData.addCell( 300, 10000, 0.03 ); + tableData.addCell( 300, 15000, 0.02 ); + tableData.addCell( 350, 10000, 0.035 ); + tableData.addCell( 350, 10000, 0.035 ); + tableData.addCell( 400, 10000, 0.04 ); + tableData.addCell( 400, 15000, 0.02666666666666667 ); + + //convert + string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + + EXPECT_FALSE( tableConverted.isConsistent ); +} + +TEST( testTable, table2DColumnMismatch ) +{ + //test 2D table column mismatch { - TableLayout const tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, - } - ); - - TableData tableData; - tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); - - TableTextFormatter const tableText( tableLayout ); - EXPECT_EQ( tableText.toString( tableData ), - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" - "| | | | | element | element |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" - "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" - ); + // collect + TableData2D tableData; + + tableData.addCell( 300, 10000, 0.03 ); + tableData.addCell( 300, 15000, 0.02 ); + tableData.addCell( 350, 10000, 0.035 ); + tableData.addCell( 350, 5000, 0.035 ); + tableData.addCell( 400, 10000, 0.04 ); + tableData.addCell( 400, 15000, 0.02666666666666667 ); + + //convert + string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + + EXPECT_FALSE( tableConverted.isConsistent ); } +} + + +TEST( testTable, table2DConsistent ) +{ + //test 2D make sure test isn't trigger when table is consistent + //collect + TableData2D tableData; + + tableData.addCell( 300, 10000, 0.03 ); + tableData.addCell( 300, 15000, 0.02 ); + tableData.addCell( 350, 10000, 0.035 ); + tableData.addCell( 350, 15000, 0.035 ); + tableData.addCell( 400, 10000, 0.04 ); + tableData.addCell( 400, 15000, 0.02666666666666667 ); + + //convert + string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + + EXPECT_TRUE( tableConverted.isConsistent ); +} + +TEST( testTable, tableSetMargin ) +{ //////////// //////// If setMargin used elsewhere make it public and remove comments for this test //////////// @@ -233,102 +330,6 @@ TEST( testTable, tableClass ) // "+------------+------+-------------------+---------+-------+-------+\n\n" // ); // } - - //test 2D table - { - //collect - TableData2D tableData; - - for( real64 p = 10000; p<20000; p+=5000 ) - { - for( real64 t = 400; t>=270; t+=-50.0 ) - { - real64 value = t/p; - tableData.addCell( t, p, value ); - } - } - - //convert - string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); - string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::Conversion1D tableconverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - - //format - TableLayout const tableLayout( tableconverted.headerNames ); - - //log - TableTextFormatter const tableLog( tableLayout ); - EXPECT_EQ( tableLog.toString( tableconverted.tableData ), - "+---------------------+--------------------+------------------------+\n" - "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" - "+---------------------+--------------------+------------------------+\n" - "| Temperature = 300 | 0.03 | 0.02 |\n" - "| Temperature = 350 | 0.035 | 0.023333333333333334 |\n" - "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" - "+---------------------+--------------------+------------------------+\n\n" - ); - } - - //test 2D table rows not equal (fatal failure ?) - { - // //collect - // TableData2D tableData; - - // tableData.addCell( 300, 10000, 0.03 ); - // tableData.addCell( 300, 15000, 0.02 ); - // tableData.addCell( 350, 10000, 0.035 ); - // tableData.addCell( 350, 10000, 0.035 ); - // tableData.addCell( 400, 10000, 0.04 ); - // tableData.addCell( 400, 15000, 0.02666666666666667 ); - - // //convert - // string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); - // string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - // TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - - // EXPECT_FALSE( tableConverted.isConsistent ); - } - - //test 2D table column mismatch - { - //collect - // TableData2D tableData; - - // tableData.addCell( 300, 10000, 0.03 ); - // tableData.addCell( 300, 15000, 0.02 ); - // tableData.addCell( 350, 10000, 0.035 ); - // tableData.addCell( 350, 5000, 0.035 ); - // tableData.addCell( 400, 10000, 0.04 ); - // tableData.addCell( 400, 15000, 0.02666666666666667 ); - - // //convert - // string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); - // string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - // TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - - // EXPECT_FALSE( tableConverted.isConsistent ); - } - - //test 2D make sure test isn't trigger when table is consistent - { - //collect - // TableData2D tableData; - - // tableData.addCell( 300, 10000, 0.03 ); - // tableData.addCell( 300, 15000, 0.02 ); - // tableData.addCell( 350, 10000, 0.035 ); - // tableData.addCell( 350, 15000, 0.035 ); - // tableData.addCell( 400, 10000, 0.04 ); - // tableData.addCell( 400, 15000, 0.02666666666666667 ); - - // //convert - // string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); - // string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - // TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - - // EXPECT_TRUE( tableConverted.isConsistent ); - } - } int main( int argc, char * * argv ) From da95c91559707fce1de4c121c1b733815c9ca76f Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 10 Apr 2024 16:42:48 +0200 Subject: [PATCH 093/216] missig doc ... --- src/coreComponents/fileIO/Table/TableData.hpp | 1 + src/coreComponents/fileIO/Table/TableFormatter.hpp | 1 + src/coreComponents/fileIO/Table/TableLayout.hpp | 3 +++ 3 files changed, 5 insertions(+) diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 774e8c4c562..7180f81f1e4 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -69,6 +69,7 @@ class TableData2D { public: + /// Struct containing conversion informations struct Conversion1D { /// Vector containing all columns names diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 87e8579cd0a..2b54941b42a 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -33,6 +33,7 @@ class TableFormatter protected: + /// Layout for a table TableLayout m_tableLayout; /** diff --git a/src/coreComponents/fileIO/Table/TableLayout.hpp b/src/coreComponents/fileIO/Table/TableLayout.hpp index 4ff78d65a61..762d01d7c52 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.hpp +++ b/src/coreComponents/fileIO/Table/TableLayout.hpp @@ -31,8 +31,11 @@ class TableLayout { public: + + /// Type of aligment for a column enum Alignment { right, left, center }; + /// Space to apply between all data and border enum MarginValue : integer { tiny = 0, From 79acc00552332eba64d8fe595959d26540cfe32b Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 11 Apr 2024 17:31:29 +0200 Subject: [PATCH 094/216] start management logError in table + todo refacto functions in TableFormatter --- src/coreComponents/fileIO/Table/TableData.cpp | 33 +++- src/coreComponents/fileIO/Table/TableData.hpp | 19 +- .../fileIO/Table/TableFormatter.cpp | 140 ++++++++++----- .../fileIO/Table/TableFormatter.hpp | 32 ++-- .../fileIO/Table/TableLayout.hpp | 8 +- .../fileIO/Table/unitTests/testTable.cpp | 162 +++++++++--------- 6 files changed, 240 insertions(+), 154 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 97b9488d3f9..51cdcc2b5b1 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -36,6 +36,21 @@ std::vector< std::vector< string > > const & TableData::getTableDataRows() const return m_rows; } +string const & TableData::getErrorMsgConversion() const +{ + return errorMsgConversion; +} + +void TableData::setErrorMsgConversion( string const & msg ) +{ + if( msg.empty() ) + { + errorMsgConversion =+"\n" + msg; + return; + } + errorMsgConversion = msg; +} + TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, string_view rowFmt, string_view columnFmt ) const @@ -74,18 +89,22 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, rowsLength.push_back( currentRowValues.size()); } - if( std::adjacent_find( rowsLength.begin(), rowsLength.end(), std::not_equal_to<>() ) != rowsLength.end() ) + if( !flag ) { - flag = false; - GEOS_WARNING( "Cell(s) are missing in row" ); + tableData1D.tableData.setErrorMsgConversion( "Table isn't consistent, One or more cells are not in the right place" ); } - if( !flag ) + if( std::adjacent_find( rowsLength.begin(), rowsLength.end(), std::not_equal_to<>() ) != rowsLength.end() ) { - tableData1D.isConsistent = flag; - GEOS_WARNING( "Table isn't consistent" ); + if( !flag ) + { + tableData1D.tableData.setErrorMsgConversion( "Cell(s) are missing in row" ); + } + else + { + tableData1D.tableData.setErrorMsgConversion( "Cell(s) are missing in row" ); + } } - return tableData1D; } } diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 7180f81f1e4..6f1d552581f 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -56,10 +56,25 @@ class TableData */ std::vector< std::vector< string > > const & getTableDataRows() const; -private: + /** + * @brief Get the Error Msg Conversion string + * @return The error msg conversion + */ + string const & getErrorMsgConversion() const; + /** + * @brief Set the Error Msg Conversion object + * @param msg The error msg to set + */ + void setErrorMsgConversion( string const & msg ); + +protected: + /// vector containing all rows with cell values std::vector< std::vector< string > > m_rows; + /// store error if there are any inconsistencies when we convert TableData2D => TableData + string errorMsgConversion; + }; /** @@ -76,8 +91,6 @@ class TableData2D std::vector< string > headerNames; /// TableData to be built TableData tableData; - /// Indicate if there are any inconsistencies when TableDate2d is converted - bool isConsistent = true; }; /** diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 86f71550ccc..3fcc856b20b 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -25,14 +25,15 @@ TableFormatter::TableFormatter( TableLayout const & tableLayout ): {} void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > const & rows ) const + std::vector< std::vector< string > > const & rows, + string & msgTableError ) const { bool isConsistent = true; for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) { for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) { - // Case of a disabled column when we initialized + // Case of a hidden column during initialization if( m_tableLayout.getColumns()[idxColumn].m_parameter.enabled ) { columns[idxColumn].m_columnValues.push_back( rows[idxRow][idxColumn] ); @@ -47,7 +48,14 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column if( !isConsistent ) { - GEOS_WARNING( "The number of columns in rows that has been collected is not equal to the columns expected when TableLayout was initialized" ); + if( msgTableError.empty()) + { + msgTableError = "The number of columns displayed on the table does not match to the columns that have been initialized in TableLayout"; + } + else + { + msgTableError += "\nThe number of columns displayed on the table does not match to the columns that have been initialized in TableLayout"; + } } } @@ -108,14 +116,13 @@ string TableCSVFormatter::toString( TableData const & tableData ) const /////////////////////////////////////////////////////////////////////// /** - * @brief Build a value cell given an alignment and spaces from "|" - * + * @brief Build cell given an alignment, a value and spaces * @param alignment The aligment of cell value * @param value The cell value * @param spaces The number of spaces in the cell * @return A formated cell */ -string buildValueCell( TableLayout::Alignment const alignment, string_view value, integer const spaces ) +string buildCell( TableLayout::Alignment const alignment, string_view value, integer const spaces ) { switch( alignment ) { @@ -127,7 +134,7 @@ string buildValueCell( TableLayout::Alignment const alignment, string_view value } /** - * @brief Detect columns not displayed from TableLayout and therefore modify columns / tableDataRows vectors + * @brief Detect columns who are not displayed from TableLayout and therefore modify columns / tableDataRows vectors * @param columns Vector built in TableLayout containing all columns with their parameters * @param tableDataRows Vector built in TableData containing all rows values */ @@ -158,50 +165,48 @@ string TableTextFormatter::toString( TableData const & tableData ) const string sectionSeparator; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); + string msgTableError = tableData.getErrorMsgConversion(); integer const nbRows = tableDataRows.size(); formatColumnsFromLayout( columns, tableDataRows ); - fillTableColumnsFromRows( columns, tableDataRows ); - - layoutToString( tableOutput, columns, nbRows, sectionSeparator ); + fillTableColumnsFromRows( columns, tableDataRows, msgTableError ); + layoutToString( tableOutput, columns, nbRows, sectionSeparator, msgTableError ); buildSectionRows( columns, sectionSeparator, tableOutput, nbRows, TableLayout::Section::values ); tableOutput << '\n'; return tableOutput.str(); } -string TableTextFormatter::layoutToString() const -{ - std::ostringstream tableOutput; - std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); - string sectionSeparator; - - layoutToString( tableOutput, columns, 0, sectionSeparator ); - - return tableOutput.str(); -} - void TableTextFormatter::layoutToString( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, integer const nbRow, - string & sectionSeparator ) const + string & sectionSeparator, + string & msgTableError ) const { - string titleRows; + string topRow = ""; string topSeparator; size_t largestHeaderVectorSize = 0; std::vector< std::vector< string > > splitHeader; - string const tableTitle = string( m_tableLayout.getTitle()); + string tableTitle = string( m_tableLayout.getTitle()); parseAndStoreHeaderSections( columns, largestHeaderVectorSize, splitHeader ); adjustHeaderSizesAndStore( columns, largestHeaderVectorSize, splitHeader ); findAndSetMaxStringSize( columns, nbRow ); - computeAndBuildSeparator( columns, topSeparator, sectionSeparator ); + computeAndBuildSeparator( columns, topSeparator, sectionSeparator, msgTableError ); + + if( !msgTableError.empty()) + { + buildTopRow( topRow, msgTableError, topSeparator, sectionSeparator ); + tableOutput << topRow; + topRow.clear(); + } if( !tableTitle.empty()) { - buildTitleRow( titleRows, topSeparator, sectionSeparator ); - tableOutput << titleRows; + buildTopRow( topRow, tableTitle, topSeparator, sectionSeparator ); + tableOutput << topRow; + topRow.clear(); } tableOutput << sectionSeparator + '\n'; @@ -303,15 +308,20 @@ void TableTextFormatter::computeAndSetMaxStringSize( std::vector< TableLayout::C void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Column > & columns, string & topSeparator, - string & sectionSeparator ) const + string & sectionSeparator, + string & msgTableError ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); integer const marginTitle = m_tableLayout.getMarginTitle(); string tableTitle = string( m_tableLayout.getTitle() ); + string maxTopString = tableTitle; string::size_type sectionlineLength = 0; string::size_type const titleLineLength = tableTitle.length() + ( marginTitle * 2 ); + string::size_type msgTableErrorLength = marginTitle * 2; + string::size_type maxTopLineLength = titleLineLength; + integer const nbSpaceBetweenColumn = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); if( !tableTitle.empty()) @@ -319,16 +329,42 @@ void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Col tableTitle = GEOS_FMT( "{:^{}}", tableTitle, titleLineLength ); } + if( !msgTableError.empty() ) + { + std::vector< string > errorMsgs; + std::istringstream ss( msgTableError ); + string msg; + + while( getline( ss, msg, '\n' )) + { + errorMsgs.push_back( msg ); + } + + auto it = std::max_element( errorMsgs.begin(), errorMsgs.end(), + []( const auto & a, const auto & b ) { + return a.size() < b.size(); + } ); + string maxStringSize = *it; + + msgTableErrorLength += maxStringSize.size(); + + if( maxTopLineLength < msgTableErrorLength ) + { + maxTopLineLength = msgTableErrorLength; + } + } + for( auto const & column : columns ) { sectionlineLength += column.m_maxStringSize.length(); } - sectionlineLength += nbSpaceBetweenColumn; - if( sectionlineLength < titleLineLength ) + + if( sectionlineLength < maxTopLineLength ) { - computeAndSetMaxStringSize( columns, sectionlineLength, titleLineLength ); + computeAndSetMaxStringSize( columns, sectionlineLength, maxTopLineLength ); } + if( columns.size() == 1 ) { sectionSeparator += GEOS_FMT( "+{:-<{}}+", @@ -359,16 +395,34 @@ void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Col topSeparator = GEOS_FMT( "+{:-<{}}+", "", sectionSeparator.size() - 2 ); // -2 for ++ } -void TableTextFormatter::buildTitleRow( string & titleRows, - string_view topSeparator, - string_view sectionSeparator ) const +void TableTextFormatter::buildTopRow( string & topRow, + string & msg, + string_view topSeparator, + string_view sectionSeparator ) const { - titleRows = GEOS_FMT( "\n{}\n|", topSeparator ); - titleRows += buildValueCell( TableLayout::Alignment::center, - m_tableLayout.getTitle(), - (sectionSeparator.length() - 2) // -2 for || - ); - titleRows += GEOS_FMT( "{}\n", "|" ); + std::cout << msg << std::endl; + size_t nbLine = std::count_if( msg.begin(), msg.end(), []( char c ){return c =='\n';} ) + 1; + std::cout << "nbLine " << nbLine << std::endl; + std::vector< string > messages; + std::istringstream ss( msg ); + string subMsg; + + while( getline( ss, subMsg, '\n' )) + { + messages.push_back( subMsg ); + } + + topRow += GEOS_FMT( "{}\n", topSeparator ); + for( size_t idxLine = 0; idxLine< nbLine; ++idxLine ) + { + topRow += GEOS_FMT( "{}", "|" ); + topRow += buildCell( TableLayout::Alignment::center, + messages[idxLine], + (sectionSeparator.length() - 2) // -2 for || + ); + topRow += GEOS_FMT( "{}\n", "|" ); + } + } void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > const & columns, @@ -396,9 +450,9 @@ void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > co cell = columns[idxColumn].m_columnValues[idxRow]; } integer const cellSize = columns[idxColumn].m_maxStringSize.length(); - tableRows << buildValueCell( columns[idxColumn].m_parameter.alignment, - cell, - cellSize ); + tableRows << buildCell( columns[idxColumn].m_parameter.alignment, + cell, + cellSize ); if( idxColumn < columns.size() - 1 ) { diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 2b54941b42a..258ce24c0a9 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -53,7 +53,8 @@ class TableFormatter * @param tableData Vector containing all rows filled with values */ void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > const & tableData ) const; + std::vector< std::vector< string > > const & tableData, + string & msgTableError ) const; }; @@ -75,6 +76,11 @@ class TableCSVFormatter : public TableFormatter */ virtual ~TableCSVFormatter() = default; + /** + * @return The string with all column names. + */ + string headerToString() const; + /** * @brief Convert the table data to a CSV string. * @param tableData The 1D table data. @@ -82,11 +88,6 @@ class TableCSVFormatter : public TableFormatter */ string dataToString( TableData const & tableData ) const; - /** - * @return The string with all column names. - */ - string headerToString() const; - /** * @brief Convert the TableData to a table string. * @param tableData The TableData to convert. @@ -122,12 +123,6 @@ class TableTextFormatter : public TableFormatter */ string toString( TableData const & tableData ) const; - /** - * @brief Converts a TableLayout into a formatted string representation. - * @return string - */ - string layoutToString() const; - private: /** @@ -140,7 +135,8 @@ class TableTextFormatter : public TableFormatter void layoutToString( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, integer const nbRows, - string & sectionSeparator ) const; + string & sectionSeparator, + string & msgTableError ) const; /** * @brief Split all header names by detecting the newline \\n character. @@ -183,15 +179,17 @@ class TableTextFormatter : public TableFormatter */ void computeAndBuildSeparator( std::vector< TableLayout::Column > & columns, string & topSeparator, - string & sectionSeparator ) const; + string & sectionSeparator, + string & msgTableError ) const; /** - * @brief Build the table title section - * @param titleRows Rows containing the title section. + * @brief Build a row at the top of the table + * @param topRow A row being built at the top of the table. + * @param msg A message to be display. * @param topSeparator The top line separator * @param sectionSeparator The section line separator */ - void buildTitleRow( string & titleRows, string_view topSeparator, string_view sectionSeparator ) const; + void buildTopRow( string & topRow, string & msg, string_view topSeparator, string_view sectionSeparator ) const; /** * @brief Build a section by specifying it's type ( header or section ) diff --git a/src/coreComponents/fileIO/Table/TableLayout.hpp b/src/coreComponents/fileIO/Table/TableLayout.hpp index 762d01d7c52..f25a146f4c4 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.hpp +++ b/src/coreComponents/fileIO/Table/TableLayout.hpp @@ -136,14 +136,16 @@ class TableLayout */ integer const & getMarginTitle() const; -private: - - /** + /** * @brief Set the minimal margin width between row content and borders. * @param marginType The margin value */ void setMargin( MarginValue marginValue ); +private: + + + std::vector< Column > m_columns; string m_tableTitle; integer m_borderMargin; diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index 2b96a30e16b..c44cc304f47 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -230,70 +230,70 @@ TEST( testTable, table2DTable ) ); } -TEST( testTable, table2DInequalRows ) -{ - //collect - TableData2D tableData; - - tableData.addCell( 300, 10000, 0.03 ); - tableData.addCell( 300, 15000, 0.02 ); - tableData.addCell( 350, 10000, 0.035 ); - tableData.addCell( 350, 10000, 0.035 ); - tableData.addCell( 400, 10000, 0.04 ); - tableData.addCell( 400, 15000, 0.02666666666666667 ); - - //convert - string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); - string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - - EXPECT_FALSE( tableConverted.isConsistent ); -} - -TEST( testTable, table2DColumnMismatch ) -{ - //test 2D table column mismatch - { - // collect - TableData2D tableData; - - tableData.addCell( 300, 10000, 0.03 ); - tableData.addCell( 300, 15000, 0.02 ); - tableData.addCell( 350, 10000, 0.035 ); - tableData.addCell( 350, 5000, 0.035 ); - tableData.addCell( 400, 10000, 0.04 ); - tableData.addCell( 400, 15000, 0.02666666666666667 ); - - //convert - string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); - string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - - EXPECT_FALSE( tableConverted.isConsistent ); - } -} - - -TEST( testTable, table2DConsistent ) -{ - //test 2D make sure test isn't trigger when table is consistent - //collect - TableData2D tableData; - - tableData.addCell( 300, 10000, 0.03 ); - tableData.addCell( 300, 15000, 0.02 ); - tableData.addCell( 350, 10000, 0.035 ); - tableData.addCell( 350, 15000, 0.035 ); - tableData.addCell( 400, 10000, 0.04 ); - tableData.addCell( 400, 15000, 0.02666666666666667 ); - - //convert - string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); - string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - - EXPECT_TRUE( tableConverted.isConsistent ); -} +// TEST( testTable, table2DInequalRows ) +// { +// //collect +// TableData2D tableData; + +// tableData.addCell( 300, 10000, 0.03 ); +// tableData.addCell( 300, 15000, 0.02 ); +// tableData.addCell( 350, 10000, 0.035 ); +// tableData.addCell( 350, 10000, 0.035 ); +// tableData.addCell( 400, 10000, 0.04 ); +// tableData.addCell( 400, 15000, 0.02666666666666667 ); + +// //convert +// string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); +// string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); +// TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + +// EXPECT_FALSE( tableConverted.isConsistent ); +// } + +// TEST( testTable, table2DColumnMismatch ) +// { +// //test 2D table column mismatch +// { +// // collect +// TableData2D tableData; + +// tableData.addCell( 300, 10000, 0.03 ); +// tableData.addCell( 300, 15000, 0.02 ); +// tableData.addCell( 350, 10000, 0.035 ); +// tableData.addCell( 350, 5000, 0.035 ); +// tableData.addCell( 400, 10000, 0.04 ); +// tableData.addCell( 400, 15000, 0.02666666666666667 ); + +// //convert +// string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); +// string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); +// TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + +// EXPECT_FALSE( tableConverted.isConsistent ); +// } +// } + + +// TEST( testTable, table2DConsistent ) +// { +// //test 2D make sure test isn't trigger when table is consistent +// //collect +// TableData2D tableData; + +// tableData.addCell( 300, 10000, 0.03 ); +// tableData.addCell( 300, 15000, 0.02 ); +// tableData.addCell( 350, 10000, 0.035 ); +// tableData.addCell( 350, 15000, 0.035 ); +// tableData.addCell( 400, 10000, 0.04 ); +// tableData.addCell( 400, 15000, 0.02666666666666667 ); + +// //convert +// string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); +// string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); +// TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + +// EXPECT_TRUE( tableConverted.isConsistent ); +// } TEST( testTable, tableSetMargin ) { @@ -303,31 +303,31 @@ TEST( testTable, tableSetMargin ) //test with tiny margin // { // TableLayout tableLayout( { - // TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - // TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - // TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, - // TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - // TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, - // TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, + // TableLayout::ColumnParam{{"Colonne 1"}, TableLayout::Alignment::center}, + // TableLayout::ColumnParam{{"Colonne 2"}, TableLayout::Alignment::center}, + // TableLayout::ColumnParam{{"Colonne 3"}, TableLayout::Alignment::right}, + // TableLayout::ColumnParam{{"Colonne 4"}, TableLayout::Alignment::right}, + // TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::right}, + // TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::right}, // }, "InternalWellGenerator well_injector1" ); // //tableLayout.setMargin( TableLayout::MarginValue::tiny ); // TableData tableData; - // tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); - // tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); + // tableData.addRow( "value 1", "long value 1", "3.0034", 3.0129877, "" , 1 ); + // tableData.addRow( "value 1", "long value 2", "100.45", 4.0129877, 1 , 2 ); // TableTextFormatter const tableText( tableLayout ); // EXPECT_EQ( tableText.toString( tableData ), - // "\n+-----------------------------------------------------------------+\n" - // "| InternalWellGenerator well_injector1 |\n" - // "+------------+------+-------------------+---------+-------+-------+\n" - // "|Cras egestas|CoordX| C |CoordZ |Prev | Next |\n" - // "| | | | |element|element|\n" - // "+------------+------+-------------------+---------+-------+-------+\n" - // "| value1 | | 3.0 |3.0129877|2 | 1 |\n" - // "| val1 | v|[3.045,42.02,89.25]|3 |10 | 3 |\n" - // "+------------+------+-------------------+---------+-------+-------+\n\n" +// "\n+----------------------------------------------------------+\n" +// "| InternalWellGenerator well_injector1 |\n" +// "+---------+------------+---------+---------+-------+-------+\n" +// "|Colonne 1| Colonne 2 |Colonne 3|Colonne 4| Prev| Next|\n" +// "| | | | |element|element|\n" +// "+---------+------------+---------+---------+-------+-------+\n" +// "| value 1 |long value 1| 3.0034|3.0129877| | 1|\n" +// "| value 1 |long value 2| 100.45|4.0129877| 1| 2|\n" +// "+---------+------------+---------+---------+-------+-------+\n\n" // ); // } } From 24f92d99ac196a1186f1348df825b2efc2fcf6b6 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 12 Apr 2024 15:31:26 +0200 Subject: [PATCH 095/216] TableFormatter refacto + clean up --- src/coreComponents/fileIO/Table/TableData.cpp | 18 +- src/coreComponents/fileIO/Table/TableData.hpp | 6 +- .../fileIO/Table/TableFormatter.cpp | 168 +++++++++--------- .../fileIO/Table/TableFormatter.hpp | 84 ++++++--- .../fileIO/Table/unitTests/testTable.cpp | 4 +- 5 files changed, 149 insertions(+), 131 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 51cdcc2b5b1..1c5170d340f 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -36,19 +36,14 @@ std::vector< std::vector< string > > const & TableData::getTableDataRows() const return m_rows; } -string const & TableData::getErrorMsgConversion() const +std::vector< string > const & TableData::getErrorMsgConversion() const { return errorMsgConversion; } void TableData::setErrorMsgConversion( string const & msg ) { - if( msg.empty() ) - { - errorMsgConversion =+"\n" + msg; - return; - } - errorMsgConversion = msg; + errorMsgConversion.push_back( msg ); } TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, @@ -96,14 +91,7 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, if( std::adjacent_find( rowsLength.begin(), rowsLength.end(), std::not_equal_to<>() ) != rowsLength.end() ) { - if( !flag ) - { - tableData1D.tableData.setErrorMsgConversion( "Cell(s) are missing in row" ); - } - else - { - tableData1D.tableData.setErrorMsgConversion( "Cell(s) are missing in row" ); - } + tableData1D.tableData.setErrorMsgConversion( "Cell(s) are missing in row" ); } return tableData1D; } diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 6f1d552581f..a4c36cf2eb1 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -60,7 +60,7 @@ class TableData * @brief Get the Error Msg Conversion string * @return The error msg conversion */ - string const & getErrorMsgConversion() const; + std::vector< string > const & getErrorMsgConversion() const; /** * @brief Set the Error Msg Conversion object @@ -72,8 +72,8 @@ class TableData /// vector containing all rows with cell values std::vector< std::vector< string > > m_rows; - /// store error if there are any inconsistencies when we convert TableData2D => TableData - string errorMsgConversion; + /// store error if there are any inconsistencies related to the table, i e : when we convert TableData2D => TableData + std::vector< string > errorMsgConversion; }; diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 3fcc856b20b..9415a5d836c 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -16,6 +16,7 @@ * @file TableFormatter.cpp */ +#include #include "TableFormatter.hpp" namespace geos { @@ -26,7 +27,7 @@ TableFormatter::TableFormatter( TableLayout const & tableLayout ): void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & rows, - string & msgTableError ) const + std::vector< string > & msgTableError ) const { bool isConsistent = true; for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) @@ -48,13 +49,9 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column if( !isConsistent ) { - if( msgTableError.empty()) + if( msgTableError.size() == 0 ) { - msgTableError = "The number of columns displayed on the table does not match to the columns that have been initialized in TableLayout"; - } - else - { - msgTableError += "\nThe number of columns displayed on the table does not match to the columns that have been initialized in TableLayout"; + msgTableError.push_back( "The number of columns displayed on the table does not match to the columns that have been initialized in TableLayout" ); } } } @@ -165,12 +162,14 @@ string TableTextFormatter::toString( TableData const & tableData ) const string sectionSeparator; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); - string msgTableError = tableData.getErrorMsgConversion(); + std::vector< string > msgTableError = tableData.getErrorMsgConversion(); integer const nbRows = tableDataRows.size(); formatColumnsFromLayout( columns, tableDataRows ); fillTableColumnsFromRows( columns, tableDataRows, msgTableError ); - layoutToString( tableOutput, columns, nbRows, sectionSeparator, msgTableError ); + + tableOutput << '\n'; + layoutToString( tableOutput, columns, msgTableError, sectionSeparator ); buildSectionRows( columns, sectionSeparator, tableOutput, nbRows, TableLayout::Section::values ); tableOutput << '\n'; @@ -179,35 +178,23 @@ string TableTextFormatter::toString( TableData const & tableData ) const void TableTextFormatter::layoutToString( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, - integer const nbRow, - string & sectionSeparator, - string & msgTableError ) const + std::vector< string > & msgTableError, + string & sectionSeparator ) const { - string topRow = ""; string topSeparator; size_t largestHeaderVectorSize = 0; std::vector< std::vector< string > > splitHeader; - string tableTitle = string( m_tableLayout.getTitle()); + string const tableTitle = string( m_tableLayout.getTitle()); parseAndStoreHeaderSections( columns, largestHeaderVectorSize, splitHeader ); adjustHeaderSizesAndStore( columns, largestHeaderVectorSize, splitHeader ); - findAndSetMaxStringSize( columns, nbRow ); - computeAndBuildSeparator( columns, topSeparator, sectionSeparator, msgTableError ); + findAndSetMaxStringSize( columns ); + computeTableMaxLineLength( columns, msgTableError ); + buildTableSeparators( columns, topSeparator, sectionSeparator ); - if( !msgTableError.empty()) - { - buildTopRow( topRow, msgTableError, topSeparator, sectionSeparator ); - tableOutput << topRow; - topRow.clear(); - } - - if( !tableTitle.empty()) - { - buildTopRow( topRow, tableTitle, topSeparator, sectionSeparator ); - tableOutput << topRow; - topRow.clear(); - } + addTopRow( tableOutput, msgTableError, topSeparator, sectionSeparator ); + addTopRow( tableOutput, tableTitle, topSeparator, sectionSeparator ); tableOutput << sectionSeparator + '\n'; buildSectionRows( columns, sectionSeparator, tableOutput, largestHeaderVectorSize, TableLayout::Section::header ); @@ -250,10 +237,9 @@ void TableTextFormatter::adjustHeaderSizesAndStore( std::vector< TableLayout::Co } } -void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, - size_t const & nbRows ) const +void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns ) const { - string maxStringSize = ""; + string maxStringSize; for( auto & column : columns ) { auto it = std::max_element( column.m_parameter.splitColumnName.begin(), @@ -261,9 +247,9 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu []( const auto & a, const auto & b ) { return a.size() < b.size(); } ); - maxStringSize = *it; - for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) + + for( size_t idxRow = 0; idxRow < column.m_columnValues.size(); ++idxRow ) { string cell = column.m_columnValues[idxRow]; @@ -277,20 +263,14 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu } } -void TableTextFormatter::computeAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, - string::size_type const sectionlineLength, - string::size_type const titleLineLength ) const +void TableTextFormatter::recalculateMaxStringSize( std::vector< TableLayout::Column > & columns, + integer const extraLines ) const { - integer extraLinesPerColumn; - integer extraLines; - integer newStringSize; - - extraLines = titleLineLength - sectionlineLength; - extraLinesPerColumn = std::ceil( extraLines / columns.size() ); + integer const extraLinesPerColumn = std::ceil( extraLines / columns.size() ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { - newStringSize = extraLinesPerColumn + columns[idxColumn].m_maxStringSize.size(); + integer newStringSize = extraLinesPerColumn + columns[idxColumn].m_maxStringSize.size(); if( idxColumn == columns.size() - 1 || columns.size() == 1 ) { columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", @@ -306,47 +286,28 @@ void TableTextFormatter::computeAndSetMaxStringSize( std::vector< TableLayout::C } } -void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Column > & columns, - string & topSeparator, - string & sectionSeparator, - string & msgTableError ) const +void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Column > & columns, + std::vector< string > & msgTableError ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); integer const marginTitle = m_tableLayout.getMarginTitle(); - string tableTitle = string( m_tableLayout.getTitle() ); - string maxTopString = tableTitle; + string const tableTitle = string( m_tableLayout.getTitle() ); string::size_type sectionlineLength = 0; - string::size_type const titleLineLength = tableTitle.length() + ( marginTitle * 2 ); + string::size_type maxTopLineLength = tableTitle.length() + ( marginTitle * 2 ); string::size_type msgTableErrorLength = marginTitle * 2; - string::size_type maxTopLineLength = titleLineLength; - integer const nbSpaceBetweenColumn = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); - if( !tableTitle.empty()) - { - tableTitle = GEOS_FMT( "{:^{}}", tableTitle, titleLineLength ); - } - - if( !msgTableError.empty() ) + if( msgTableError.size() != 0 ) { - std::vector< string > errorMsgs; - std::istringstream ss( msgTableError ); - string msg; - - while( getline( ss, msg, '\n' )) - { - errorMsgs.push_back( msg ); - } - - auto it = std::max_element( errorMsgs.begin(), errorMsgs.end(), + auto it = std::max_element( msgTableError.begin(), msgTableError.end(), []( const auto & a, const auto & b ) { return a.size() < b.size(); } ); string maxStringSize = *it; - msgTableErrorLength += maxStringSize.size(); + msgTableErrorLength += maxStringSize.size() + 1; // for \n set later if( maxTopLineLength < msgTableErrorLength ) { @@ -362,8 +323,17 @@ void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Col if( sectionlineLength < maxTopLineLength ) { - computeAndSetMaxStringSize( columns, sectionlineLength, maxTopLineLength ); + integer const extraLines = maxTopLineLength - sectionlineLength; + recalculateMaxStringSize( columns, extraLines ); } +} + +void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column > & columns, + string & topSeparator, + string & sectionSeparator ) const +{ + integer const columnMargin = m_tableLayout.getColumnMargin(); + integer const borderMargin = m_tableLayout.getBorderMargin(); if( columns.size() == 1 ) { @@ -393,16 +363,47 @@ void TableTextFormatter::computeAndBuildSeparator( std::vector< TableLayout::Col } } topSeparator = GEOS_FMT( "+{:-<{}}+", "", sectionSeparator.size() - 2 ); // -2 for ++ + +} + +void TableTextFormatter::addTopRow( std::ostringstream & tableOutput, + string const & msg, + string_view topSeparator, + string_view sectionSeparator ) const +{ + if( !msg.empty()) + { + buildTopRow( tableOutput, msg, topSeparator, sectionSeparator ); + } +} + +void TableTextFormatter::addTopRow( std::ostringstream & tableOutput, + std::vector< string > const & msg, + string_view topSeparator, + string_view sectionSeparator ) const +{ + if( msg.size() != 0 ) + { + string strConcat; + for( const std::string & str : msg ) + { + if( !strConcat.empty()) + { + strConcat += '\n'; + } + strConcat += str; + } + buildTopRow( tableOutput, strConcat, topSeparator, sectionSeparator ); + } } -void TableTextFormatter::buildTopRow( string & topRow, - string & msg, + +void TableTextFormatter::buildTopRow( std::ostringstream & tableOutput, + string const & msg, string_view topSeparator, string_view sectionSeparator ) const { - std::cout << msg << std::endl; size_t nbLine = std::count_if( msg.begin(), msg.end(), []( char c ){return c =='\n';} ) + 1; - std::cout << "nbLine " << nbLine << std::endl; std::vector< string > messages; std::istringstream ss( msg ); string subMsg; @@ -412,17 +413,16 @@ void TableTextFormatter::buildTopRow( string & topRow, messages.push_back( subMsg ); } - topRow += GEOS_FMT( "{}\n", topSeparator ); + tableOutput << GEOS_FMT( "{}\n", topSeparator ); for( size_t idxLine = 0; idxLine< nbLine; ++idxLine ) - { - topRow += GEOS_FMT( "{}", "|" ); - topRow += buildCell( TableLayout::Alignment::center, - messages[idxLine], - (sectionSeparator.length() - 2) // -2 for || - ); - topRow += GEOS_FMT( "{}\n", "|" ); + { + tableOutput << GEOS_FMT( "{}", "|" ); + tableOutput << buildCell( TableLayout::Alignment::center, + messages[idxLine], + (sectionSeparator.length() - 2) // -2 for || + ); + tableOutput << GEOS_FMT( "{}\n", "|" ); } - } void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > const & columns, diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 258ce24c0a9..8cf005c0786 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -54,7 +54,7 @@ class TableFormatter */ void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & tableData, - string & msgTableError ) const; + std::vector< string > & msgTableError ) const; }; @@ -128,15 +128,14 @@ class TableTextFormatter : public TableFormatter /** * @brief Converts a TableLayout into a formatted representation. * @param tableOutput The output stream - * @param columns The vectors of table columns - * @param nbRows Number of rows in the table + * @param columns The vector containing all table columns + * @param msgTableError A vector containg all error related to the table * @param sectionSeparator An empty string for building the section separator */ void layoutToString( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, - integer const nbRows, - string & sectionSeparator, - string & msgTableError ) const; + std::vector< string > & msgTableError, + string & sectionSeparator ) const; /** * @brief Split all header names by detecting the newline \\n character. @@ -159,37 +158,68 @@ class TableTextFormatter : public TableFormatter /** * @brief For each column find and set the column's longest string + * @param columns The vector containg all columns */ - void findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, size_t const & nbRows ) const; + void findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns ) const; /** - * @brief Compute the largest string size in the table. If the table title is the largest string size in the table, recalculate for all - * columns the \p m_maxStringSize value by adding extra characters - * @param sectionlineLength The length of a section line - * @param titleLineLength The length of a title line + * @brief recalculate the largest string size for each columns + * @param extraLines Extra characters to be added to \p m_maxStringSize of each columns */ - void computeAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, - string::size_type const sectionlineLength, - string::size_type const titleLineLength ) const; + void recalculateMaxStringSize( std::vector< TableLayout::Column > & columns, integer const extraLines ) const; /** - * @brief Compute and build the top and the section line separator - * @param topSeparator An empty string to be built - * @param sectionSeparator An empty string to be built + * @brief Compute the max table line length + * @param columns Vector of column containing containing the largest string for each column + * @param msgTableError Vector containing all error messages */ - void computeAndBuildSeparator( std::vector< TableLayout::Column > & columns, - string & topSeparator, - string & sectionSeparator, - string & msgTableError ) const; + void computeTableMaxLineLength( std::vector< TableLayout::Column > & columns, + std::vector< string > & msgTableError ) const; /** - * @brief Build a row at the top of the table - * @param topRow A row being built at the top of the table. - * @param msg A message to be display. - * @param topSeparator The top line separator - * @param sectionSeparator The section line separator + * @brief Build all separator needed from length information contained in columns vector + * @param topSeparator Top separator to be built + * @param sectionSeparator section separator to be built */ - void buildTopRow( string & topRow, string & msg, string_view topSeparator, string_view sectionSeparator ) const; + void buildTableSeparators( std::vector< TableLayout::Column > & columns, + string & topSeparator, + string & sectionSeparator ) const; + + /** + * @brief add a row on top of the table + * @param tableOutput The output stream + * @param msg Vector of string to display + * @param topSeparator The top table separator + * @param sectionSeparator The section table separator + */ + void addTopRow( std::ostringstream & tableOutput, + std::vector< string > const & msg, + string_view topSeparator, + string_view sectionSeparator ) const; + + /** + * @brief Add a row on top of the table + * @param tableOutput The output stream + * @param msg The string to display + * @param topSeparator The top table separator + * @param sectionSeparator The section table separator + */ + void addTopRow( std::ostringstream & tableOutput, + string const & msg, + string_view topSeparator, + string_view sectionSeparator ) const; + + /** + * @brief Build a row at the top of the table + * @param tableOutput The output stream + * @param msg The string to display. + * @param topSeparator The top table separator + * @param sectionSeparator The section table separator + */ + void buildTopRow( std::ostringstream & tableOutput, + string const & msg, + string_view topSeparator, + string_view sectionSeparator ) const; /** * @brief Build a section by specifying it's type ( header or section ) diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index c44cc304f47..385993a754b 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -185,7 +185,7 @@ TEST( testTable, tableEmptyTitle ) TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "\n+----------------+----------+-----------------------+-------------+-----------+-----------+\n" "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" "| | | | | element | element |\n" "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" @@ -220,7 +220,7 @@ TEST( testTable, table2DTable ) //log TableTextFormatter const tableLog( tableLayout ); EXPECT_EQ( tableLog.toString( tableconverted.tableData ), - "+---------------------+--------------------+------------------------+\n" + "\n+---------------------+--------------------+------------------------+\n" "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" "+---------------------+--------------------+------------------------+\n" "| Temperature = 300 | 0.03 | 0.02 |\n" From 5a70c33e7ac5ab413a8bebfa1601039bbbde55a7 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 12 Apr 2024 15:59:38 +0200 Subject: [PATCH 096/216] uncrustify --- src/coreComponents/fileIO/Table/TableLayout.cpp | 2 +- src/coreComponents/fileIO/Table/TableLayout.hpp | 4 ++-- src/coreComponents/fileIO/Table/unitTests/testTable.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableLayout.cpp b/src/coreComponents/fileIO/Table/TableLayout.cpp index e4f44f018c0..33ef05ab722 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.cpp +++ b/src/coreComponents/fileIO/Table/TableLayout.cpp @@ -37,7 +37,7 @@ TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter, st setMargin( MarginValue::medium ); for( size_t idx = 0; idx< columnParameter.size(); ++idx ) { - m_columns.push_back( {columnParameter[idx], {}, ""} ); + m_columns.push_back( {columnParameter[idx], {}, ""} ); } } diff --git a/src/coreComponents/fileIO/Table/TableLayout.hpp b/src/coreComponents/fileIO/Table/TableLayout.hpp index f25a146f4c4..adbb45fab5a 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.hpp +++ b/src/coreComponents/fileIO/Table/TableLayout.hpp @@ -136,9 +136,9 @@ class TableLayout */ integer const & getMarginTitle() const; - /** + /** * @brief Set the minimal margin width between row content and borders. - * @param marginType The margin value + * @param marginValue The margin value */ void setMargin( MarginValue marginValue ); diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index 385993a754b..48ede02e334 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -328,8 +328,8 @@ TEST( testTable, tableSetMargin ) // "| value 1 |long value 1| 3.0034|3.0129877| | 1|\n" // "| value 1 |long value 2| 100.45|4.0129877| 1| 2|\n" // "+---------+------------+---------+---------+-------+-------+\n\n" - // ); - // } +// ); +// } } int main( int argc, char * * argv ) From 95f3a9dcc391e49e863c2568fe52df1fca54cbc5 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 15 Apr 2024 10:54:28 +0200 Subject: [PATCH 097/216] small doc update --- src/coreComponents/fileIO/Table/TableData.cpp | 5 +++-- src/coreComponents/fileIO/Table/TableData.hpp | 6 +++--- src/coreComponents/fileIO/Table/TableFormatter.cpp | 5 +---- src/coreComponents/fileIO/Table/TableFormatter.hpp | 11 +++++++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 1c5170d340f..a19579427bf 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -38,12 +38,12 @@ std::vector< std::vector< string > > const & TableData::getTableDataRows() const std::vector< string > const & TableData::getErrorMsgConversion() const { - return errorMsgConversion; + return errorsMsg; } void TableData::setErrorMsgConversion( string const & msg ) { - errorMsgConversion.push_back( msg ); + errorsMsg.push_back( msg ); } TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, @@ -93,6 +93,7 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, { tableData1D.tableData.setErrorMsgConversion( "Cell(s) are missing in row" ); } + return tableData1D; } } diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index a4c36cf2eb1..36bd60a2471 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -72,8 +72,8 @@ class TableData /// vector containing all rows with cell values std::vector< std::vector< string > > m_rows; - /// store error if there are any inconsistencies related to the table, i e : when we convert TableData2D => TableData - std::vector< string > errorMsgConversion; + /// store error if there are any inconsistencies related to the table + std::vector< string > errorsMsg; }; @@ -104,7 +104,7 @@ class TableData2D void addCell( real64 rowValue, real64 columnValue, T const & value ); /** - * @return Convert and return a struct containing a 1D Table and the column names list from a TableData2D + * @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 * @param rowFmt The y axis units of the table. * @param columnFmt The x axis units of the table. diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 9415a5d836c..cdf17a1f9ef 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -49,10 +49,7 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column if( !isConsistent ) { - if( msgTableError.size() == 0 ) - { - msgTableError.push_back( "The number of columns displayed on the table does not match to the columns that have been initialized in TableLayout" ); - } + msgTableError.push_back( "The number of columns displayed on the table does not match to the columns that have been initialized in TableLayout" ); } } diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 8cf005c0786..81354f19afe 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -164,6 +164,7 @@ class TableTextFormatter : public TableFormatter /** * @brief recalculate the largest string size for each columns + * @param columns Vector containing all table columns * @param extraLines Extra characters to be added to \p m_maxStringSize of each columns */ void recalculateMaxStringSize( std::vector< TableLayout::Column > & columns, integer const extraLines ) const; @@ -178,6 +179,7 @@ class TableTextFormatter : public TableFormatter /** * @brief Build all separator needed from length information contained in columns vector + * @param columns Vector containing all table columns * @param topSeparator Top separator to be built * @param sectionSeparator section separator to be built */ @@ -186,9 +188,9 @@ class TableTextFormatter : public TableFormatter string & sectionSeparator ) const; /** - * @brief add a row on top of the table + * @brief Add a row on top of the table * @param tableOutput The output stream - * @param msg Vector of string to display + * @param msg Vector of string(s) to display * @param topSeparator The top table separator * @param sectionSeparator The section table separator */ @@ -200,7 +202,7 @@ class TableTextFormatter : public TableFormatter /** * @brief Add a row on top of the table * @param tableOutput The output stream - * @param msg The string to display + * @param msg The message to display * @param topSeparator The top table separator * @param sectionSeparator The section table separator */ @@ -212,7 +214,7 @@ class TableTextFormatter : public TableFormatter /** * @brief Build a row at the top of the table * @param tableOutput The output stream - * @param msg The string to display. + * @param msg The converted string to display. * @param topSeparator The top table separator * @param sectionSeparator The section table separator */ @@ -223,6 +225,7 @@ class TableTextFormatter : public TableFormatter /** * @brief Build a section by specifying it's type ( header or section ) + * @param columns Vector containing all table columns * @param sectionSeparator Line separator between sections * @param rows A section row * @param nbRows Indicates the number of lines in a section From 77351b9b3fce3ba1c2430e036bcc55c92128ec4d Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 15 Apr 2024 17:14:07 +0200 Subject: [PATCH 098/216] some error management update --- src/coreComponents/fileIO/Table/TableData.cpp | 14 +- src/coreComponents/fileIO/Table/TableData.hpp | 12 +- .../fileIO/Table/TableFormatter.cpp | 63 ++++---- .../fileIO/Table/TableFormatter.hpp | 26 ++-- .../fileIO/Table/TableLayout.hpp | 2 - .../fileIO/Table/unitTests/testTable.cpp | 135 +++++++----------- 6 files changed, 115 insertions(+), 137 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index a19579427bf..7b17bea0cec 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -23,6 +23,10 @@ namespace geos void TableData::addRow( std::vector< string > const & row ) { + if( m_rows.size() != 0 && row.size() != m_rows[m_rows.size() - 1].size() ) + { + errorsMsg.insert( "Number of row cells ins't consistent with the number of columns." ); + } m_rows.push_back( row ); } @@ -36,14 +40,14 @@ std::vector< std::vector< string > > const & TableData::getTableDataRows() const return m_rows; } -std::vector< string > const & TableData::getErrorMsgConversion() const +std::set< string > const & TableData::getErrorMsgs() const { return errorsMsg; } -void TableData::setErrorMsgConversion( string const & msg ) +void TableData::setErrorMsgs( string const & msg ) { - errorsMsg.push_back( msg ); + errorsMsg.insert( msg ); } TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, @@ -86,12 +90,12 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, if( !flag ) { - tableData1D.tableData.setErrorMsgConversion( "Table isn't consistent, One or more cells are not in the right place" ); + tableData1D.tableData.setErrorMsgs( "Table isn't consistent, One or more cells are not in the right place" ); } if( std::adjacent_find( rowsLength.begin(), rowsLength.end(), std::not_equal_to<>() ) != rowsLength.end() ) { - tableData1D.tableData.setErrorMsgConversion( "Cell(s) are missing in row" ); + tableData1D.tableData.setErrorMsgs( "Cell(s) are missing in row" ); } return tableData1D; diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 36bd60a2471..5a624574733 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -57,23 +57,23 @@ class TableData std::vector< std::vector< string > > const & getTableDataRows() const; /** - * @brief Get the Error Msg Conversion string - * @return The error msg conversion + * @brief Get all error messages + * @return The set of error messages */ - std::vector< string > const & getErrorMsgConversion() const; + std::set< string > const & getErrorMsgs() const; /** - * @brief Set the Error Msg Conversion object + * @brief Set an error message * @param msg The error msg to set */ - void setErrorMsgConversion( string const & msg ); + void setErrorMsgs( string const & msg ); protected: /// vector containing all rows with cell values std::vector< std::vector< string > > m_rows; /// store error if there are any inconsistencies related to the table - std::vector< string > errorsMsg; + std::set< string > errorsMsg; }; diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index cdf17a1f9ef..bbea0b3bdf3 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -25,13 +25,19 @@ TableFormatter::TableFormatter( TableLayout const & tableLayout ): m_tableLayout( tableLayout ) {} +// msgTableError a sortir void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > const & rows, - std::vector< string > & msgTableError ) const + std::vector< std::vector< string > > & rows ) const { - bool isConsistent = true; + for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) { + if( rows[idxRow].size() != columns.size()) + { + integer cellToAdd = columns.size() - rows[idxRow].size(); + rows[idxRow].insert( rows[idxRow].end(), cellToAdd, " " ); + } + for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) { // Case of a hidden column during initialization @@ -40,16 +46,6 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column columns[idxColumn].m_columnValues.push_back( rows[idxRow][idxColumn] ); } } - - if( rows[idxRow].size()!=columns.size() ) - { - isConsistent = false; - } - } - - if( !isConsistent ) - { - msgTableError.push_back( "The number of columns displayed on the table does not match to the columns that have been initialized in TableLayout" ); } } @@ -159,11 +155,11 @@ string TableTextFormatter::toString( TableData const & tableData ) const string sectionSeparator; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); - std::vector< string > msgTableError = tableData.getErrorMsgConversion(); + std::set< string > msgTableError = tableData.getErrorMsgs(); integer const nbRows = tableDataRows.size(); formatColumnsFromLayout( columns, tableDataRows ); - fillTableColumnsFromRows( columns, tableDataRows, msgTableError ); + fillTableColumnsFromRows( columns, tableDataRows ); tableOutput << '\n'; layoutToString( tableOutput, columns, msgTableError, sectionSeparator ); @@ -175,7 +171,7 @@ string TableTextFormatter::toString( TableData const & tableData ) const void TableTextFormatter::layoutToString( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, - std::vector< string > & msgTableError, + std::set< string > & msgTableError, string & sectionSeparator ) const { string topSeparator; @@ -190,8 +186,8 @@ void TableTextFormatter::layoutToString( std::ostringstream & tableOutput, computeTableMaxLineLength( columns, msgTableError ); buildTableSeparators( columns, topSeparator, sectionSeparator ); - addTopRow( tableOutput, msgTableError, topSeparator, sectionSeparator ); - addTopRow( tableOutput, tableTitle, topSeparator, sectionSeparator ); + addTopRow( tableOutput, msgTableError, topSeparator, sectionSeparator, TableLayout::Alignment::left ); + addTopRow( tableOutput, tableTitle, topSeparator, sectionSeparator, TableLayout::Alignment::center ); tableOutput << sectionSeparator + '\n'; buildSectionRows( columns, sectionSeparator, tableOutput, largestHeaderVectorSize, TableLayout::Section::header ); @@ -284,18 +280,17 @@ void TableTextFormatter::recalculateMaxStringSize( std::vector< TableLayout::Col } void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Column > & columns, - std::vector< string > & msgTableError ) const + std::set< string > & msgTableError ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); - integer const marginTitle = m_tableLayout.getMarginTitle(); string const tableTitle = string( m_tableLayout.getTitle() ); - - string::size_type sectionlineLength = 0; - string::size_type maxTopLineLength = tableTitle.length() + ( marginTitle * 2 ); - string::size_type msgTableErrorLength = marginTitle * 2; integer const nbSpaceBetweenColumn = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); + string::size_type sectionlineLength = nbSpaceBetweenColumn; + string::size_type maxTopLineLength = tableTitle.length(); + string::size_type msgTableErrorLength = borderMargin; + if( msgTableError.size() != 0 ) { auto it = std::max_element( msgTableError.begin(), msgTableError.end(), @@ -316,7 +311,6 @@ void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Co { sectionlineLength += column.m_maxStringSize.length(); } - sectionlineLength += nbSpaceBetweenColumn; if( sectionlineLength < maxTopLineLength ) { @@ -366,18 +360,20 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column void TableTextFormatter::addTopRow( std::ostringstream & tableOutput, string const & msg, string_view topSeparator, - string_view sectionSeparator ) const + string_view sectionSeparator, + TableLayout::Alignment alignment ) const { if( !msg.empty()) { - buildTopRow( tableOutput, msg, topSeparator, sectionSeparator ); + buildTopRow( tableOutput, msg, topSeparator, sectionSeparator, alignment ); } } void TableTextFormatter::addTopRow( std::ostringstream & tableOutput, - std::vector< string > const & msg, + std::set< string > const & msg, string_view topSeparator, - string_view sectionSeparator ) const + string_view sectionSeparator, + TableLayout::Alignment alignment ) const { if( msg.size() != 0 ) { @@ -388,9 +384,9 @@ void TableTextFormatter::addTopRow( std::ostringstream & tableOutput, { strConcat += '\n'; } - strConcat += str; + strConcat += GEOS_FMT( "{:>{}}", str, m_tableLayout.getBorderMargin() + str.size() ); } - buildTopRow( tableOutput, strConcat, topSeparator, sectionSeparator ); + buildTopRow( tableOutput, strConcat, topSeparator, sectionSeparator, alignment ); } } @@ -398,7 +394,8 @@ void TableTextFormatter::addTopRow( std::ostringstream & tableOutput, void TableTextFormatter::buildTopRow( std::ostringstream & tableOutput, string const & msg, string_view topSeparator, - string_view sectionSeparator ) const + string_view sectionSeparator, + TableLayout::Alignment alignment ) const { size_t nbLine = std::count_if( msg.begin(), msg.end(), []( char c ){return c =='\n';} ) + 1; std::vector< string > messages; @@ -414,7 +411,7 @@ void TableTextFormatter::buildTopRow( std::ostringstream & tableOutput, for( size_t idxLine = 0; idxLine< nbLine; ++idxLine ) { tableOutput << GEOS_FMT( "{}", "|" ); - tableOutput << buildCell( TableLayout::Alignment::center, + tableOutput << buildCell( alignment, messages[idxLine], (sectionSeparator.length() - 2) // -2 for || ); diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 81354f19afe..53fcee454b2 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -48,13 +48,12 @@ class TableFormatter virtual ~TableFormatter() = default; /** - * @brief Fill the vector (m_column) in tableData with values from rows stored in tableLayout. + * @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 */ void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > const & tableData, - std::vector< string > & msgTableError ) const; + std::vector< std::vector< string > > & tableData ) const; }; @@ -134,13 +133,14 @@ class TableTextFormatter : public TableFormatter */ void layoutToString( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, - std::vector< string > & msgTableError, + std::set< string > & msgTableError, string & sectionSeparator ) const; /** * @brief Split all header names by detecting the newline \\n character. - * @param splitHeader A empty vector who will contain all split header names + * @param columns The vector containg all columns * @param largestHeaderVectorSize The largest split header vector size + * @param splitHeader A empty vector who will contain all split header names */ void parseAndStoreHeaderSections( std::vector< TableLayout::Column > const & columns, size_t & largestHeaderVectorSize, @@ -175,7 +175,7 @@ class TableTextFormatter : public TableFormatter * @param msgTableError Vector containing all error messages */ void computeTableMaxLineLength( std::vector< TableLayout::Column > & columns, - std::vector< string > & msgTableError ) const; + std::set< string > & msgTableError ) const; /** * @brief Build all separator needed from length information contained in columns vector @@ -193,11 +193,13 @@ class TableTextFormatter : public TableFormatter * @param msg Vector of string(s) to display * @param topSeparator The top table separator * @param sectionSeparator The section table separator + * @param alignment The aligment for a row */ void addTopRow( std::ostringstream & tableOutput, - std::vector< string > const & msg, + std::set< string > const & msg, string_view topSeparator, - string_view sectionSeparator ) const; + string_view sectionSeparator, + TableLayout::Alignment alignment ) const; /** * @brief Add a row on top of the table @@ -205,11 +207,13 @@ class TableTextFormatter : public TableFormatter * @param msg The message to display * @param topSeparator The top table separator * @param sectionSeparator The section table separator + * @param alignment The aligment for a row */ void addTopRow( std::ostringstream & tableOutput, string const & msg, string_view topSeparator, - string_view sectionSeparator ) const; + string_view sectionSeparator, + TableLayout::Alignment alignment ) const; /** * @brief Build a row at the top of the table @@ -217,11 +221,13 @@ class TableTextFormatter : public TableFormatter * @param msg The converted string to display. * @param topSeparator The top table separator * @param sectionSeparator The section table separator + * @param alignment The aligment for a row */ void buildTopRow( std::ostringstream & tableOutput, string const & msg, string_view topSeparator, - string_view sectionSeparator ) const; + string_view sectionSeparator, + TableLayout::Alignment alignment ) const; /** * @brief Build a section by specifying it's type ( header or section ) diff --git a/src/coreComponents/fileIO/Table/TableLayout.hpp b/src/coreComponents/fileIO/Table/TableLayout.hpp index adbb45fab5a..ba3fe478c89 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.hpp +++ b/src/coreComponents/fileIO/Table/TableLayout.hpp @@ -144,8 +144,6 @@ class TableLayout private: - - std::vector< Column > m_columns; string m_tableTitle; integer m_borderMargin; diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index 48ede02e334..db96b9fbdd2 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -133,15 +133,14 @@ TEST( testTable, tableHiddenColumn ) TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), - "\n+------------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" - "| Cras egestas | CoordX | C | CoordZ |\n" - "+---------------------------+---------------------+----------------------------------+-----------------------------+\n" - "| value1 | | 3.0 | 3.0129877 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 |\n" - "+---------------------------+---------------------+----------------------------------+-----------------------------+\n\n" - ); + "\n+--------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "+--------------------------+--------------------+---------------------------------+----------------------------+\n" + "| Cras egestas | CoordX | C | CoordZ |\n" + "+--------------------------+--------------------+---------------------------------+----------------------------+\n" + "| value1 | | 3.0 | 3.0129877 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 |\n" + "+--------------------------+--------------------+---------------------------------+----------------------------+\n\n" ); } TEST( testTable, tableUniqueColumn ) @@ -156,15 +155,14 @@ TEST( testTable, tableUniqueColumn ) TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), - "\n+-------------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "+-------------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas |\n" - "+-------------------------------------------------------------------------------------------------------------------+\n" - "| value1 |\n" - "| val1 |\n" - "+-------------------------------------------------------------------------------------------------------------------+\n\n" - ); + "\n+---------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "+---------------------------------------------------------------------------------------------------------------+\n" + "| Cras egestas |\n" + "+---------------------------------------------------------------------------------------------------------------+\n" + "| value1 |\n" + "| val1 |\n" + "+---------------------------------------------------------------------------------------------------------------+\n\n" ); } TEST( testTable, tableEmptyTitle ) @@ -230,70 +228,45 @@ TEST( testTable, table2DTable ) ); } -// TEST( testTable, table2DInequalRows ) -// { -// //collect -// TableData2D tableData; - -// tableData.addCell( 300, 10000, 0.03 ); -// tableData.addCell( 300, 15000, 0.02 ); -// tableData.addCell( 350, 10000, 0.035 ); -// tableData.addCell( 350, 10000, 0.035 ); -// tableData.addCell( 400, 10000, 0.04 ); -// tableData.addCell( 400, 15000, 0.02666666666666667 ); - -// //convert -// string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); -// string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); -// TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - -// EXPECT_FALSE( tableConverted.isConsistent ); -// } - -// TEST( testTable, table2DColumnMismatch ) -// { -// //test 2D table column mismatch -// { -// // collect -// TableData2D tableData; - -// tableData.addCell( 300, 10000, 0.03 ); -// tableData.addCell( 300, 15000, 0.02 ); -// tableData.addCell( 350, 10000, 0.035 ); -// tableData.addCell( 350, 5000, 0.035 ); -// tableData.addCell( 400, 10000, 0.04 ); -// tableData.addCell( 400, 15000, 0.02666666666666667 ); - -// //convert -// string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); -// string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); -// TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - -// EXPECT_FALSE( tableConverted.isConsistent ); -// } -// } - -// TEST( testTable, table2DConsistent ) -// { -// //test 2D make sure test isn't trigger when table is consistent -// //collect -// TableData2D tableData; - -// tableData.addCell( 300, 10000, 0.03 ); -// tableData.addCell( 300, 15000, 0.02 ); -// tableData.addCell( 350, 10000, 0.035 ); -// tableData.addCell( 350, 15000, 0.035 ); -// tableData.addCell( 400, 10000, 0.04 ); -// tableData.addCell( 400, 15000, 0.02666666666666667 ); - -// //convert -// string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); -// string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); -// TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); - -// EXPECT_TRUE( tableConverted.isConsistent ); -// } +TEST( testTable, table2DColumnMismatch ) +{ + //test 2D table column mismatch + { + // collect + TableData2D tableData; + + tableData.addCell( 300, 10000, 0.03 ); + tableData.addCell( 300, 15000, 0.02 ); + tableData.addCell( 350, 10000, 0.035 ); + tableData.addCell( 350, 10000, 0.035 ); + tableData.addCell( 400, 10000, 0.04 ); + tableData.addCell( 400, 15000, 0.02666666666666667 ); + + //convert + string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); + string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); + TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); + + //format + TableLayout const tableLayout( tableConverted.headerNames ); + + //log + TableTextFormatter const tableLog( tableLayout ); + EXPECT_EQ( tableLog.toString( tableConverted.tableData ), + "\n+-----------------------------------------------------------------------+\n" + "| Cell(s) are missing in row |\n" + "| Number of row cells ins't consistent with the number of columns. |\n" + "+---------------------+--------------------+----------------------------+\n" + "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" + "+---------------------+--------------------+----------------------------+\n" + "| Temperature = 300 | 0.03 | 0.02 |\n" + "| Temperature = 350 | 0.035 | |\n" + "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" + "+---------------------+--------------------+----------------------------+\n\n" + ); + } +} TEST( testTable, tableSetMargin ) { From da67c056c3e20eab180df5da500641dcfc62af5f Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 17 Apr 2024 11:26:22 +0200 Subject: [PATCH 099/216] renaming & simplifying --- src/coreComponents/fileIO/Table/TableData.cpp | 31 ++-- src/coreComponents/fileIO/Table/TableData.hpp | 10 +- .../fileIO/Table/TableFormatter.cpp | 136 ++++++++---------- .../fileIO/Table/TableFormatter.hpp | 72 +++------- .../fileIO/Table/unitTests/testTable.cpp | 2 +- 5 files changed, 109 insertions(+), 142 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 7b17bea0cec..de8c0220299 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -23,9 +23,13 @@ namespace geos void TableData::addRow( std::vector< string > const & row ) { - if( m_rows.size() != 0 && row.size() != m_rows[m_rows.size() - 1].size() ) + if( m_rows.size() != 0 && row.size() != m_rows[m_rows.size() - 1].size() ) { - errorsMsg.insert( "Number of row cells ins't consistent with the number of columns." ); + string msg = "Number of row cells ins't consistent with the number of columns."; + if( std::find( errorsMsg.begin(), errorsMsg.end(), msg ) == errorsMsg.end()) + { + errorsMsg.push_back( msg ); + } } m_rows.push_back( row ); } @@ -40,14 +44,21 @@ std::vector< std::vector< string > > const & TableData::getTableDataRows() const return m_rows; } -std::set< string > const & TableData::getErrorMsgs() const +std::vector< string > const & TableData::getErrorMsgs() const { return errorsMsg; } -void TableData::setErrorMsgs( string const & msg ) +void TableData::addErrorMsgs( string const & msg ) { - errorsMsg.insert( msg ); + std::vector< string > splitHeaderParts; + std::istringstream ss( msg ); + string splitErrors; + + while( getline( ss, splitErrors, '\n' )) + { + errorsMsg.push_back( splitErrors ); + } } TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, @@ -68,7 +79,7 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, } // insert row value and row cell values - bool flag = true; + bool isConsistant = true; for( auto const & [rowValue, rowMap] : m_data ) { integer i = 0; @@ -79,7 +90,7 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, //check is if the column are offset if( std::abs( columnValue - headerValues[i] ) > 0.0 ) { - flag = false; + isConsistant = false; } currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); ++i; @@ -88,14 +99,14 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, rowsLength.push_back( currentRowValues.size()); } - if( !flag ) + if( !isConsistant ) { - tableData1D.tableData.setErrorMsgs( "Table isn't consistent, One or more cells are not in the right place" ); + tableData1D.tableData.addErrorMsgs( "Table isn't consistent, One or more cells are not in the right place" ); } if( std::adjacent_find( rowsLength.begin(), rowsLength.end(), std::not_equal_to<>() ) != rowsLength.end() ) { - tableData1D.tableData.setErrorMsgs( "Cell(s) are missing in row" ); + tableData1D.tableData.addErrorMsgs( "Cell(s) are missing in row" ); } return tableData1D; diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 5a624574733..27ced16665c 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -58,22 +58,22 @@ class TableData /** * @brief Get all error messages - * @return The set of error messages + * @return The vector of error messages */ - std::set< string > const & getErrorMsgs() const; + std::vector< string > const & getErrorMsgs() const; /** * @brief Set an error message - * @param msg The error msg to set + * @param msg The error msg to vector */ - void setErrorMsgs( string const & msg ); + void addErrorMsgs( string const & msg ); protected: /// vector containing all rows with cell values std::vector< std::vector< string > > m_rows; /// store error if there are any inconsistencies related to the table - std::set< string > errorsMsg; + std::vector< string > errorsMsg; }; diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index bbea0b3bdf3..8d6b29eb1a3 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -32,7 +32,7 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) { - if( rows[idxRow].size() != columns.size()) + if( rows[idxRow].size() < columns.size() ) { integer cellToAdd = columns.size() - rows[idxRow].size(); rows[idxRow].insert( rows[idxRow].end(), cellToAdd, " " ); @@ -155,47 +155,46 @@ string TableTextFormatter::toString( TableData const & tableData ) const string sectionSeparator; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); - std::set< string > msgTableError = tableData.getErrorMsgs(); - integer const nbRows = tableDataRows.size(); + std::vector< string > msgTableError = tableData.getErrorMsgs(); + integer const nbValuesRows = tableDataRows.size(); formatColumnsFromLayout( columns, tableDataRows ); fillTableColumnsFromRows( columns, tableDataRows ); - tableOutput << '\n'; - layoutToString( tableOutput, columns, msgTableError, sectionSeparator ); - buildSectionRows( columns, sectionSeparator, tableOutput, nbRows, TableLayout::Section::values ); + outputLayout( tableOutput, columns, msgTableError, sectionSeparator ); + outputSectionRows( columns, sectionSeparator, tableOutput, nbValuesRows, TableLayout::Section::values ); tableOutput << '\n'; return tableOutput.str(); } -void TableTextFormatter::layoutToString( std::ostringstream & tableOutput, - std::vector< TableLayout::Column > & columns, - std::set< string > & msgTableError, - string & sectionSeparator ) const +void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, + std::vector< TableLayout::Column > & columns, + std::vector< string > & msgTableError, + string & sectionSeparator ) const { string topSeparator; - size_t largestHeaderVectorSize = 0; + size_t nbHeaderRows = 0; std::vector< std::vector< string > > splitHeader; string const tableTitle = string( m_tableLayout.getTitle()); - parseAndStoreHeaderSections( columns, largestHeaderVectorSize, splitHeader ); - adjustHeaderSizesAndStore( columns, largestHeaderVectorSize, splitHeader ); - + splitAndSetColumnNames( columns, nbHeaderRows, splitHeader ); findAndSetMaxStringSize( columns ); + computeTableMaxLineLength( columns, msgTableError ); buildTableSeparators( columns, topSeparator, sectionSeparator ); - addTopRow( tableOutput, msgTableError, topSeparator, sectionSeparator, TableLayout::Alignment::left ); - addTopRow( tableOutput, tableTitle, topSeparator, sectionSeparator, TableLayout::Alignment::center ); + tableOutput << '\n'; + outputTopRows( tableOutput, msgTableError, topSeparator, TableLayout::Alignment::left ); + outputTopRows( tableOutput, {tableTitle}, topSeparator, TableLayout::Alignment::center ); + tableOutput << GEOS_FMT( "{}\n", sectionSeparator ); - tableOutput << sectionSeparator + '\n'; - buildSectionRows( columns, sectionSeparator, tableOutput, largestHeaderVectorSize, TableLayout::Section::header ); + outputSectionRows( columns, sectionSeparator, tableOutput, nbHeaderRows, TableLayout::Section::header ); } -void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout::Column > const & columns, - size_t & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ) const +void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Column > & columns, + size_t & nbHeaderRows, + std::vector< std::vector< string > > & splitHeader ) const { for( auto const & column : columns ) { @@ -209,21 +208,16 @@ void TableTextFormatter::parseAndStoreHeaderSections( std::vector< TableLayout:: } size_t const cellSize = splitHeaderParts.size(); - largestHeaderVectorSize = std::max( largestHeaderVectorSize, cellSize ); + nbHeaderRows = std::max( nbHeaderRows, cellSize ); splitHeader.push_back( splitHeaderParts ); } -} -void TableTextFormatter::adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, - size_t const & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ) const -{ for( size_t columnParamIdx = 0; columnParamIdx < columns.size(); ++columnParamIdx ) { - if( splitHeader[columnParamIdx].size() < largestHeaderVectorSize ) + if( splitHeader[columnParamIdx].size() < nbHeaderRows ) { - integer const whiteRowToAdd = largestHeaderVectorSize - splitHeader[columnParamIdx].size(); + integer const whiteRowToAdd = nbHeaderRows - splitHeader[columnParamIdx].size(); splitHeader[columnParamIdx].insert( splitHeader[columnParamIdx].end(), whiteRowToAdd, " " ); } columns[columnParamIdx].m_parameter.splitColumnName = splitHeader[columnParamIdx]; @@ -256,15 +250,15 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu } } -void TableTextFormatter::recalculateMaxStringSize( std::vector< TableLayout::Column > & columns, - integer const extraLines ) const +void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > & columns, + integer const extraCharacters ) const { - integer const extraLinesPerColumn = std::ceil( extraLines / columns.size() ); + integer const extraCharactersPerColumn = std::ceil( extraCharacters / columns.size() ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { - integer newStringSize = extraLinesPerColumn + columns[idxColumn].m_maxStringSize.size(); - if( idxColumn == columns.size() - 1 || columns.size() == 1 ) + integer newStringSize = extraCharactersPerColumn + columns[idxColumn].m_maxStringSize.size(); + if( idxColumn == columns.size() - 1 ) { columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", columns[idxColumn].m_maxStringSize, @@ -280,7 +274,7 @@ void TableTextFormatter::recalculateMaxStringSize( std::vector< TableLayout::Col } void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Column > & columns, - std::set< string > & msgTableError ) const + std::vector< string > & msgTableError ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); @@ -314,8 +308,8 @@ void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Co if( sectionlineLength < maxTopLineLength ) { - integer const extraLines = maxTopLineLength - sectionlineLength; - recalculateMaxStringSize( columns, extraLines ); + integer const extraCharacters = maxTopLineLength - sectionlineLength; + increaseColumnsSize( columns, extraCharacters ); } } @@ -357,36 +351,30 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column } -void TableTextFormatter::addTopRow( std::ostringstream & tableOutput, - string const & msg, - string_view topSeparator, - string_view sectionSeparator, - TableLayout::Alignment alignment ) const +void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, + std::vector< string > const & msg, + string_view topSeparator, + TableLayout::Alignment alignment ) const { - if( !msg.empty()) - { - buildTopRow( tableOutput, msg, topSeparator, sectionSeparator, alignment ); - } -} - -void TableTextFormatter::addTopRow( std::ostringstream & tableOutput, - std::set< string > const & msg, - string_view topSeparator, - string_view sectionSeparator, - TableLayout::Alignment alignment ) const -{ - if( msg.size() != 0 ) + if( msg.size() != 0 && msg[0] != "" ) { string strConcat; + integer borderMargin = 0; + + if( alignment == TableLayout::Alignment::left ) + { + borderMargin = m_tableLayout.getBorderMargin(); + } + for( const std::string & str : msg ) { if( !strConcat.empty()) { strConcat += '\n'; } - strConcat += GEOS_FMT( "{:>{}}", str, m_tableLayout.getBorderMargin() + str.size() ); + strConcat += GEOS_FMT( "{:>{}}", str, borderMargin + str.size() ); } - buildTopRow( tableOutput, strConcat, topSeparator, sectionSeparator, alignment ); + buildTopRow( tableOutput, strConcat, topSeparator, alignment ); } } @@ -394,7 +382,6 @@ void TableTextFormatter::addTopRow( std::ostringstream & tableOutput, void TableTextFormatter::buildTopRow( std::ostringstream & tableOutput, string const & msg, string_view topSeparator, - string_view sectionSeparator, TableLayout::Alignment alignment ) const { size_t nbLine = std::count_if( msg.begin(), msg.end(), []( char c ){return c =='\n';} ) + 1; @@ -411,26 +398,23 @@ void TableTextFormatter::buildTopRow( std::ostringstream & tableOutput, for( size_t idxLine = 0; idxLine< nbLine; ++idxLine ) { tableOutput << GEOS_FMT( "{}", "|" ); - tableOutput << buildCell( alignment, - messages[idxLine], - (sectionSeparator.length() - 2) // -2 for || - ); + tableOutput << buildCell( alignment, messages[idxLine], (topSeparator.length() - 2)); tableOutput << GEOS_FMT( "{}\n", "|" ); } } -void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > const & columns, - string_view sectionSeparator, - std::ostringstream & tableRows, - integer const nbRows, - TableLayout::Section const section ) const +void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > const & columns, + string_view sectionSeparator, + std::ostringstream & tableOutput, + integer const nbRows, + TableLayout::Section const section ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); for( integer idxRow = 0; idxRow< nbRows; ++idxRow ) { - tableRows << GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); + tableOutput << GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { string cell; @@ -444,32 +428,30 @@ void TableTextFormatter::buildSectionRows( std::vector< TableLayout::Column > co cell = columns[idxColumn].m_columnValues[idxRow]; } integer const cellSize = columns[idxColumn].m_maxStringSize.length(); - tableRows << buildCell( columns[idxColumn].m_parameter.alignment, - cell, - cellSize ); + tableOutput << buildCell( columns[idxColumn].m_parameter.alignment, + cell, + cellSize ); if( idxColumn < columns.size() - 1 ) { - tableRows << GEOS_FMT( "{:^{}}", "|", columnMargin ); + tableOutput << GEOS_FMT( "{:^{}}", "|", columnMargin ); } } if( columns.size() == 1 ) { - tableRows << GEOS_FMT( "{:>{}}\n", "|", columnMargin ); + tableOutput << GEOS_FMT( "{:>{}}\n", "|", columnMargin ); } else { - tableRows << GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); + tableOutput << GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); } } if( nbRows != 0 ) { - tableRows << GEOS_FMT( "{}\n", sectionSeparator ); + tableOutput << GEOS_FMT( "{}\n", sectionSeparator ); } } - - } diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 53fcee454b2..af0c2c4cbd0 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -131,30 +131,21 @@ class TableTextFormatter : public TableFormatter * @param msgTableError A vector containg all error related to the table * @param sectionSeparator An empty string for building the section separator */ - void layoutToString( std::ostringstream & tableOutput, - std::vector< TableLayout::Column > & columns, - std::set< string > & msgTableError, - string & sectionSeparator ) const; + void outputLayout( std::ostringstream & tableOutput, + std::vector< TableLayout::Column > & columns, + std::vector< string > & msgTableError, + string & sectionSeparator ) const; /** - * @brief Split all header names by detecting the newline \\n character. + * @brief Split all header names by detecting the newline \\n character. and + * set the same vector size for each split header and merge it into columns * @param columns The vector containg all columns * @param largestHeaderVectorSize The largest split header vector size * @param splitHeader A empty vector who will contain all split header names */ - void parseAndStoreHeaderSections( std::vector< TableLayout::Column > const & columns, - size_t & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ) const; - - /** - * @brief Set the same vector size for each split header and merge it into columns - * @param columns The table columns to be merged - * @param largestHeaderVectorSize The reference value for adjusting splitHeader vector - * @param splitHeader The vector containing all split headers - */ - void adjustHeaderSizesAndStore( std::vector< TableLayout::Column > & columns, - size_t const & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ) const; + void splitAndSetColumnNames( std::vector< TableLayout::Column > & columns, + size_t & largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeader ) const; /** * @brief For each column find and set the column's longest string @@ -165,9 +156,9 @@ class TableTextFormatter : public TableFormatter /** * @brief recalculate the largest string size for each columns * @param columns Vector containing all table columns - * @param extraLines Extra characters to be added to \p m_maxStringSize of each columns + * @param extraCharacters Extra characters to be added to \p m_maxStringSize of each columns */ - void recalculateMaxStringSize( std::vector< TableLayout::Column > & columns, integer const extraLines ) const; + void increaseColumnsSize( std::vector< TableLayout::Column > & columns, integer const extraCharacters ) const; /** * @brief Compute the max table line length @@ -175,7 +166,7 @@ class TableTextFormatter : public TableFormatter * @param msgTableError Vector containing all error messages */ void computeTableMaxLineLength( std::vector< TableLayout::Column > & columns, - std::set< string > & msgTableError ) const; + std::vector< string > & msgTableError ) const; /** * @brief Build all separator needed from length information contained in columns vector @@ -192,56 +183,39 @@ class TableTextFormatter : public TableFormatter * @param tableOutput The output stream * @param msg Vector of string(s) to display * @param topSeparator The top table separator - * @param sectionSeparator The section table separator - * @param alignment The aligment for a row - */ - void addTopRow( std::ostringstream & tableOutput, - std::set< string > const & msg, - string_view topSeparator, - string_view sectionSeparator, - TableLayout::Alignment alignment ) const; - - /** - * @brief Add a row on top of the table - * @param tableOutput The output stream - * @param msg The message to display - * @param topSeparator The top table separator - * @param sectionSeparator The section table separator * @param alignment The aligment for a row */ - void addTopRow( std::ostringstream & tableOutput, - string const & msg, - string_view topSeparator, - string_view sectionSeparator, - TableLayout::Alignment alignment ) const; + void outputTopRows( std::ostringstream & tableOutput, + std::vector< string > const & msg, + string_view topSeparator, + TableLayout::Alignment alignment ) const; /** * @brief Build a row at the top of the table * @param tableOutput The output stream * @param msg The converted string to display. * @param topSeparator The top table separator - * @param sectionSeparator The section table separator * @param alignment The aligment for a row */ void buildTopRow( std::ostringstream & tableOutput, string const & msg, string_view topSeparator, - string_view sectionSeparator, TableLayout::Alignment alignment ) const; /** - * @brief Build a section by specifying it's type ( header or section ) + * @brief Output a section by specifying it's type ( header or section ) * @param columns Vector containing all table columns * @param sectionSeparator Line separator between sections * @param rows A section row * @param nbRows Indicates the number of lines in a section * @param section The section to be built + * @note Add the ending line if there are one or more rows */ - void buildSectionRows( std::vector< TableLayout::Column > const & columns, - string_view sectionSeparator, - std::ostringstream & rows, - integer const nbRows, - TableLayout::Section const section ) const; + void outputSectionRows( std::vector< TableLayout::Column > const & columns, + string_view sectionSeparator, + std::ostringstream & rows, + integer const nbRows, + TableLayout::Section const section ) const; }; } diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index db96b9fbdd2..fc0b799a9de 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -255,8 +255,8 @@ TEST( testTable, table2DColumnMismatch ) TableTextFormatter const tableLog( tableLayout ); EXPECT_EQ( tableLog.toString( tableConverted.tableData ), "\n+-----------------------------------------------------------------------+\n" - "| Cell(s) are missing in row |\n" "| Number of row cells ins't consistent with the number of columns. |\n" + "| Cell(s) are missing in row |\n" "+---------------------+--------------------+----------------------------+\n" "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" "+---------------------+--------------------+----------------------------+\n" From a9612bbd098b669fdf41c3745529e0db313af10e Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 17 Apr 2024 16:15:55 +0200 Subject: [PATCH 100/216] add case for fill all column in case of table 2D --- src/coreComponents/fileIO/Table/TableData.cpp | 30 ++++++++----------- src/coreComponents/fileIO/Table/TableData.hpp | 4 +++ .../fileIO/Table/TableFormatter.cpp | 2 +- .../fileIO/Table/unitTests/testTable.cpp | 19 ++++++------ 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index de8c0220299..79b367133a8 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -25,7 +25,7 @@ void TableData::addRow( std::vector< string > const & row ) { if( m_rows.size() != 0 && row.size() != m_rows[m_rows.size() - 1].size() ) { - string msg = "Number of row cells ins't consistent with the number of columns."; + string msg = "Remarks : some cells may be missing"; if( std::find( errorsMsg.begin(), errorsMsg.end(), msg ) == errorsMsg.end()) { errorsMsg.push_back( msg ); @@ -71,44 +71,40 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, tableData1D.headerNames.push_back( string( targetUnit ) ); - // looping over first line to fill columnNames - for( auto const & [ columnValue, cellValue] : m_data.begin()->second ) + for( auto const & columnValue : columnValues ) { tableData1D.headerNames.push_back( GEOS_FMT( columnFmt, columnValue ) ); headerValues.push_back( columnValue ); } // insert row value and row cell values - bool isConsistant = true; for( auto const & [rowValue, rowMap] : m_data ) { integer i = 0; std::vector< string > currentRowValues; + integer idxColumn = 0; + currentRowValues.push_back( GEOS_FMT( rowFmt, rowValue ) ); for( auto const & [columnValue, cellValue] : rowMap ) { - //check is if the column are offset - if( std::abs( columnValue - headerValues[i] ) > 0.0 ) + //check if column numbers in the evaluated row is consistent + if( columnValue > headerValues[i] ) { - isConsistant = false; + while( columnValue > headerValues[idxColumn] ) + { + currentRowValues.push_back( "" ); + ++idxColumn; + } } currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); + ++idxColumn; ++i; } + tableData1D.tableData.addRow( currentRowValues ); rowsLength.push_back( currentRowValues.size()); } - if( !isConsistant ) - { - tableData1D.tableData.addErrorMsgs( "Table isn't consistent, One or more cells are not in the right place" ); - } - - if( std::adjacent_find( rowsLength.begin(), rowsLength.end(), std::not_equal_to<>() ) != rowsLength.end() ) - { - tableData1D.tableData.addErrorMsgs( "Cell(s) are missing in row" ); - } - return tableData1D; } } diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 27ced16665c..09353ddbf5d 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -120,6 +120,9 @@ class TableData2D /// @brief all cell values by their [ row ][ column ] std::map< RowType, std::map< ColumnType, string > > m_data; + + /// @brief Store all column values when adding cell + std::set< real64 > columnValues; }; template< typename ... Args > @@ -139,6 +142,7 @@ template< typename T > void TableData2D::addCell( real64 const rowValue, real64 const columnValue, T const & value ) { static_assert( has_formatter< decltype(value) >, "Argument passed in addCell cannot be converted to string" ); + columnValues.insert( columnValue ); m_data[rowValue][columnValue] = GEOS_FMT( "{}", value ); } diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 8d6b29eb1a3..05e8bb4b69a 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -40,7 +40,7 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) { - // Case of a hidden column during initialization + // in case of a hidden column during initialization if( m_tableLayout.getColumns()[idxColumn].m_parameter.enabled ) { columns[idxColumn].m_columnValues.push_back( rows[idxRow][idxColumn] ); diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index fc0b799a9de..f49146881fd 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -254,16 +254,15 @@ TEST( testTable, table2DColumnMismatch ) //log TableTextFormatter const tableLog( tableLayout ); EXPECT_EQ( tableLog.toString( tableConverted.tableData ), - "\n+-----------------------------------------------------------------------+\n" - "| Number of row cells ins't consistent with the number of columns. |\n" - "| Cell(s) are missing in row |\n" - "+---------------------+--------------------+----------------------------+\n" - "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" - "+---------------------+--------------------+----------------------------+\n" - "| Temperature = 300 | 0.03 | 0.02 |\n" - "| Temperature = 350 | 0.035 | |\n" - "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" - "+---------------------+--------------------+----------------------------+\n\n" + "\n+------------------------------------------------------------------+\n" + "| Remarks : some cells may be missing |\n" + "+---------------------+--------------------+-----------------------+\n" + "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" + "+---------------------+--------------------+-----------------------+\n" + "| Temperature = 300 | 0.03 | 0.02 |\n" + "| Temperature = 350 | 0.035 | |\n" + "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" + "+---------------------+--------------------+-----------------------+\n\n" ); } } From 89f859a7cfb0d39452751d02bd51411fc9826761 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 17 Apr 2024 17:37:01 +0200 Subject: [PATCH 101/216] simplification --- src/coreComponents/fileIO/Table/TableData.cpp | 2 +- .../fileIO/Table/TableFormatter.cpp | 50 +++---------------- .../fileIO/Table/TableFormatter.hpp | 12 ----- 3 files changed, 8 insertions(+), 56 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 79b367133a8..2a88d088f4b 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -55,7 +55,7 @@ void TableData::addErrorMsgs( string const & msg ) std::istringstream ss( msg ); string splitErrors; - while( getline( ss, splitErrors, '\n' )) + while( std::getline( ss, splitErrors, '\n' )) { errorsMsg.push_back( splitErrors ); } diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 05e8bb4b69a..c34a23d8ff1 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -153,10 +153,10 @@ string TableTextFormatter::toString( TableData const & tableData ) const { std::ostringstream tableOutput; string sectionSeparator; - std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); + std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); - std::vector< string > msgTableError = tableData.getErrorMsgs(); - integer const nbValuesRows = tableDataRows.size(); + std::vector< string > msgTableError = tableData.getErrorMsgs(); + integer const nbValuesRows = tableDataRows.size(); formatColumnsFromLayout( columns, tableDataRows ); fillTableColumnsFromRows( columns, tableDataRows ); @@ -245,7 +245,6 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu maxStringSize = cell; } } - column.m_maxStringSize = maxStringSize; } } @@ -358,48 +357,13 @@ void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, { if( msg.size() != 0 && msg[0] != "" ) { - string strConcat; - integer borderMargin = 0; - - if( alignment == TableLayout::Alignment::left ) - { - borderMargin = m_tableLayout.getBorderMargin(); - } - + tableOutput << GEOS_FMT( "{}\n", topSeparator ); for( const std::string & str : msg ) { - if( !strConcat.empty()) - { - strConcat += '\n'; - } - strConcat += GEOS_FMT( "{:>{}}", str, borderMargin + str.size() ); + tableOutput << "|" << string( m_tableLayout.getBorderMargin() , ' ' ); + tableOutput << buildCell( alignment, str, (topSeparator.length() - 6)); + tableOutput << string( m_tableLayout.getBorderMargin() , ' ' ) << "|\n"; } - buildTopRow( tableOutput, strConcat, topSeparator, alignment ); - } -} - - -void TableTextFormatter::buildTopRow( std::ostringstream & tableOutput, - string const & msg, - string_view topSeparator, - TableLayout::Alignment alignment ) const -{ - size_t nbLine = std::count_if( msg.begin(), msg.end(), []( char c ){return c =='\n';} ) + 1; - std::vector< string > messages; - std::istringstream ss( msg ); - string subMsg; - - while( getline( ss, subMsg, '\n' )) - { - messages.push_back( subMsg ); - } - - tableOutput << GEOS_FMT( "{}\n", topSeparator ); - for( size_t idxLine = 0; idxLine< nbLine; ++idxLine ) - { - tableOutput << GEOS_FMT( "{}", "|" ); - tableOutput << buildCell( alignment, messages[idxLine], (topSeparator.length() - 2)); - tableOutput << GEOS_FMT( "{}\n", "|" ); } } diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index af0c2c4cbd0..133df168434 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -190,18 +190,6 @@ class TableTextFormatter : public TableFormatter string_view topSeparator, TableLayout::Alignment alignment ) const; - /** - * @brief Build a row at the top of the table - * @param tableOutput The output stream - * @param msg The converted string to display. - * @param topSeparator The top table separator - * @param alignment The aligment for a row - */ - void buildTopRow( std::ostringstream & tableOutput, - string const & msg, - string_view topSeparator, - TableLayout::Alignment alignment ) const; - /** * @brief Output a section by specifying it's type ( header or section ) * @param columns Vector containing all table columns From ef5085c8fafe965af0339a851d13fcc279dfd80f Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 18 Apr 2024 14:20:34 +0200 Subject: [PATCH 102/216] code optimization --- src/coreComponents/fileIO/Table/TableData.cpp | 13 ++- .../fileIO/Table/TableFormatter.cpp | 87 ++++++++----------- .../fileIO/Table/TableFormatter.hpp | 4 +- .../fileIO/Table/TableLayout.cpp | 14 +-- .../fileIO/Table/TableLayout.hpp | 4 +- 5 files changed, 54 insertions(+), 68 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 2a88d088f4b..3f0f70d0d2c 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -80,15 +80,15 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, // insert row value and row cell values for( auto const & [rowValue, rowMap] : m_data ) { - integer i = 0; std::vector< string > currentRowValues; - integer idxColumn = 0; - + currentRowValues.reserve( rowMap.size() ); currentRowValues.push_back( GEOS_FMT( rowFmt, rowValue ) ); + + integer idxColumn = 0; for( auto const & [columnValue, cellValue] : rowMap ) { //check if column numbers in the evaluated row is consistent - if( columnValue > headerValues[i] ) + if( columnValue > headerValues[idxColumn] ) { while( columnValue > headerValues[idxColumn] ) { @@ -98,11 +98,10 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, } currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); ++idxColumn; - ++i; } - tableData1D.tableData.addRow( currentRowValues ); - rowsLength.push_back( currentRowValues.size()); + tableData1D.tableData.addRow( std::move( currentRowValues ) ); + rowsLength.push_back( currentRowValues.size() ); } return tableData1D; diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index c34a23d8ff1..7fc460c468d 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -25,7 +25,6 @@ TableFormatter::TableFormatter( TableLayout const & tableLayout ): m_tableLayout( tableLayout ) {} -// msgTableError a sortir void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > & rows ) const { @@ -34,16 +33,14 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column { if( rows[idxRow].size() < columns.size() ) { - integer cellToAdd = columns.size() - rows[idxRow].size(); - rows[idxRow].insert( rows[idxRow].end(), cellToAdd, " " ); + rows[idxRow].resize( columns.size(), " " ); } for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) { - // in case of a hidden column during initialization if( m_tableLayout.getColumns()[idxColumn].m_parameter.enabled ) { - columns[idxColumn].m_columnValues.push_back( rows[idxRow][idxColumn] ); + columns[idxColumn].m_columnValues.push_back( std::move( rows[idxRow][idxColumn] ) ); } } } @@ -175,10 +172,10 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, { string topSeparator; size_t nbHeaderRows = 0; - std::vector< std::vector< string > > splitHeader; + std::vector< std::vector< string > > splitHeaders; string const tableTitle = string( m_tableLayout.getTitle()); - splitAndSetColumnNames( columns, nbHeaderRows, splitHeader ); + splitAndSetColumnNames( columns, nbHeaderRows, splitHeaders ); findAndSetMaxStringSize( columns ); computeTableMaxLineLength( columns, msgTableError ); @@ -194,8 +191,10 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Column > & columns, size_t & nbHeaderRows, - std::vector< std::vector< string > > & splitHeader ) const + std::vector< std::vector< string > > & splitHeaders ) const { + + splitHeaders.reserve( columns.size() ); for( auto const & column : columns ) { std::vector< string > splitHeaderParts; @@ -207,45 +206,38 @@ void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Colum splitHeaderParts.push_back( subColumnNames ); } - size_t const cellSize = splitHeaderParts.size(); - nbHeaderRows = std::max( nbHeaderRows, cellSize ); - - splitHeader.push_back( splitHeaderParts ); + splitHeaders.push_back( std::move( splitHeaderParts ) ); } - for( size_t columnParamIdx = 0; columnParamIdx < columns.size(); ++columnParamIdx ) + nbHeaderRows = std::max_element( splitHeaders.begin(), splitHeaders.end(), + []( auto const & v1, auto const & v2 ) { return v1.size() < v2.size(); } )->size(); + + for( auto & headerParts : splitHeaders ) { - if( splitHeader[columnParamIdx].size() < nbHeaderRows ) + if( headerParts.size() < nbHeaderRows ) { - integer const whiteRowToAdd = nbHeaderRows - splitHeader[columnParamIdx].size(); - splitHeader[columnParamIdx].insert( splitHeader[columnParamIdx].end(), whiteRowToAdd, " " ); + headerParts.resize( nbHeaderRows, " " ); } - columns[columnParamIdx].m_parameter.splitColumnName = splitHeader[columnParamIdx]; + columns[&headerParts - &splitHeaders[0]].m_parameter.splitColumnName = std::move( headerParts ); } + } void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns ) const { - string maxStringSize; for( auto & column : columns ) { - auto it = std::max_element( column.m_parameter.splitColumnName.begin(), - column.m_parameter.splitColumnName.end(), - []( const auto & a, const auto & b ) { - return a.size() < b.size(); - } ); - maxStringSize = *it; + auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnName.begin(), column.m_parameter.splitColumnName.end(), + []( const auto & a, const auto & b ) {return a.size() < b.size();} ); + column.m_maxStringSize = maxStringSizeHeader; - for( size_t idxRow = 0; idxRow < column.m_columnValues.size(); ++idxRow ) + for( auto const & cell : column.m_columnValues ) { - string cell = column.m_columnValues[idxRow]; - - if( maxStringSize.length() < cell.length()) + if( column.m_maxStringSize.length() < cell.length()) { - maxStringSize = cell; + column.m_maxStringSize = cell; } } - column.m_maxStringSize = maxStringSize; } } @@ -278,13 +270,12 @@ void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Co integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); string const tableTitle = string( m_tableLayout.getTitle() ); - integer const nbSpaceBetweenColumn = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); - string::size_type sectionlineLength = nbSpaceBetweenColumn; + string::size_type sectionlineLength = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2);; string::size_type maxTopLineLength = tableTitle.length(); string::size_type msgTableErrorLength = borderMargin; - if( msgTableError.size() != 0 ) + if( !msgTableError.empty() ) { auto it = std::max_element( msgTableError.begin(), msgTableError.end(), []( const auto & a, const auto & b ) { @@ -293,17 +284,11 @@ void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Co string maxStringSize = *it; msgTableErrorLength += maxStringSize.size() + 1; // for \n set later - - if( maxTopLineLength < msgTableErrorLength ) - { - maxTopLineLength = msgTableErrorLength; - } + maxTopLineLength = std::max( maxTopLineLength, msgTableErrorLength ); } - for( auto const & column : columns ) - { - sectionlineLength += column.m_maxStringSize.length(); - } + sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, + []( auto sum, const auto & column ){ return sum + column.m_maxStringSize.length();} ); if( sectionlineLength < maxTopLineLength ) { @@ -358,11 +343,11 @@ void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, if( msg.size() != 0 && msg[0] != "" ) { tableOutput << GEOS_FMT( "{}\n", topSeparator ); - for( const std::string & str : msg ) + for( std::string const & str : msg ) { - tableOutput << "|" << string( m_tableLayout.getBorderMargin() , ' ' ); + tableOutput << "|" << string( m_tableLayout.getBorderMargin(), ' ' ); tableOutput << buildCell( alignment, str, (topSeparator.length() - 6)); - tableOutput << string( m_tableLayout.getBorderMargin() , ' ' ) << "|\n"; + tableOutput << string( m_tableLayout.getBorderMargin(), ' ' ) << "|\n"; } } } @@ -382,19 +367,19 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { string cell; + TableLayout::Column const currentColumn = columns[idxColumn]; + integer const cellSize = currentColumn.m_maxStringSize.length(); if( section == TableLayout::Section::header ) { - cell = columns[idxColumn].m_parameter.splitColumnName[idxRow]; + cell = currentColumn.m_parameter.splitColumnName[idxRow]; } else { - cell = columns[idxColumn].m_columnValues[idxRow]; + cell = currentColumn.m_columnValues[idxRow]; } - integer const cellSize = columns[idxColumn].m_maxStringSize.length(); - tableOutput << buildCell( columns[idxColumn].m_parameter.alignment, - cell, - cellSize ); + + tableOutput << buildCell( currentColumn.m_parameter.alignment, cell, cellSize ); if( idxColumn < columns.size() - 1 ) { diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 133df168434..7b62e4defb2 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -141,11 +141,11 @@ class TableTextFormatter : public TableFormatter * set the same vector size for each split header and merge it into columns * @param columns The vector containg all columns * @param largestHeaderVectorSize The largest split header vector size - * @param splitHeader A empty vector who will contain all split header names + * @param splitHeaders A empty vector who will contain all split header names */ void splitAndSetColumnNames( std::vector< TableLayout::Column > & columns, size_t & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeader ) const; + std::vector< std::vector< string > > & splitHeaders ) const; /** * @brief For each column find and set the column's longest string diff --git a/src/coreComponents/fileIO/Table/TableLayout.cpp b/src/coreComponents/fileIO/Table/TableLayout.cpp index 33ef05ab722..51d0bfb4906 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.cpp +++ b/src/coreComponents/fileIO/Table/TableLayout.cpp @@ -21,23 +21,25 @@ namespace geos { -TableLayout::TableLayout( std::vector< string > const & headers, string const & title ): +TableLayout::TableLayout( std::vector< string > const & columnNames, string const & title ): m_tableTitle( title ) { setMargin( MarginValue::medium ); - for( size_t idx = 0; idx< headers.size(); ++idx ) + m_columns.reserve( columnNames.size() ); + for( auto const & name : columnNames ) { - m_columns.push_back( {TableLayout::ColumnParam{{headers[idx]}, Alignment::right, true}, {}, ""} ); + m_columns.push_back( {TableLayout::ColumnParam{{name}, Alignment::right, true}, {}, ""} ); } } -TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title ): +TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameters, string const & title ): m_tableTitle( title ) { setMargin( MarginValue::medium ); - for( size_t idx = 0; idx< columnParameter.size(); ++idx ) + m_columns.reserve( columnParameters.size() ); + for( auto const & param : columnParameters ) { - m_columns.push_back( {columnParameter[idx], {}, ""} ); + m_columns.push_back( { param, {}, ""} ); } } diff --git a/src/coreComponents/fileIO/Table/TableLayout.hpp b/src/coreComponents/fileIO/Table/TableLayout.hpp index ba3fe478c89..a8579f342d3 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.hpp +++ b/src/coreComponents/fileIO/Table/TableLayout.hpp @@ -106,10 +106,10 @@ class TableLayout /** * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels * level - * @param columnParameter List of structures to set up each colum parameters. + * @param columnParameters List of structures to set up each colum parameters. * @param title The table name */ - TableLayout( std::vector< ColumnParam > const & columnParameter, string const & title = "" ); + TableLayout( std::vector< ColumnParam > const & columnParameters, string const & title = "" ); /** * @return The columns vector From 294db78c13a2ad6bf0ae14ddcb1ab13ca447ac26 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 18 Apr 2024 17:53:54 +0200 Subject: [PATCH 103/216] remove useless std::move --- src/coreComponents/fileIO/Table/TableData.cpp | 9 +++------ src/coreComponents/fileIO/Table/TableFormatter.cpp | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 3f0f70d0d2c..07b5e003426 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -88,13 +88,10 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, for( auto const & [columnValue, cellValue] : rowMap ) { //check if column numbers in the evaluated row is consistent - if( columnValue > headerValues[idxColumn] ) + while( columnValue > headerValues[idxColumn] ) { - while( columnValue > headerValues[idxColumn] ) - { - currentRowValues.push_back( "" ); - ++idxColumn; - } + currentRowValues.push_back( "" ); + ++idxColumn; } currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); ++idxColumn; diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 7fc460c468d..58e4d0c6897 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -40,7 +40,7 @@ void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column { if( m_tableLayout.getColumns()[idxColumn].m_parameter.enabled ) { - columns[idxColumn].m_columnValues.push_back( std::move( rows[idxRow][idxColumn] ) ); + columns[idxColumn].m_columnValues.push_back( rows[idxRow][idxColumn] ); } } } @@ -218,7 +218,7 @@ void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Colum { headerParts.resize( nbHeaderRows, " " ); } - columns[&headerParts - &splitHeaders[0]].m_parameter.splitColumnName = std::move( headerParts ); + columns[&headerParts - &splitHeaders[0]].m_parameter.splitColumnName = headerParts; } } From 9f23f62a8377813dff31d79226b0532a7ea7f81a Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 19 Apr 2024 16:13:37 +0200 Subject: [PATCH 104/216] refacto build separator + reviews --- src/coreComponents/fileIO/Table/TableData.cpp | 10 +- src/coreComponents/fileIO/Table/TableData.hpp | 6 +- .../fileIO/Table/TableFormatter.cpp | 120 ++++++++---------- .../fileIO/Table/TableFormatter.hpp | 35 +++-- .../fileIO/Table/TableLayout.hpp | 2 +- .../fileIO/Table/unitTests/testTable.cpp | 86 +++++++------ 6 files changed, 131 insertions(+), 128 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 07b5e003426..a1b4b357b09 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -26,9 +26,9 @@ void TableData::addRow( std::vector< string > const & row ) if( m_rows.size() != 0 && row.size() != m_rows[m_rows.size() - 1].size() ) { string msg = "Remarks : some cells may be missing"; - if( std::find( errorsMsg.begin(), errorsMsg.end(), msg ) == errorsMsg.end()) + if( std::find( m_errorsMsg.begin(), m_errorsMsg.end(), msg ) == m_errorsMsg.end()) { - errorsMsg.push_back( msg ); + m_errorsMsg.push_back( msg ); } } m_rows.push_back( row ); @@ -46,7 +46,7 @@ std::vector< std::vector< string > > const & TableData::getTableDataRows() const std::vector< string > const & TableData::getErrorMsgs() const { - return errorsMsg; + return m_errorsMsg; } void TableData::addErrorMsgs( string const & msg ) @@ -57,7 +57,7 @@ void TableData::addErrorMsgs( string const & msg ) while( std::getline( ss, splitErrors, '\n' )) { - errorsMsg.push_back( splitErrors ); + m_errorsMsg.push_back( splitErrors ); } } @@ -71,7 +71,7 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, tableData1D.headerNames.push_back( string( targetUnit ) ); - for( auto const & columnValue : columnValues ) + for( auto const & columnValue : m_columnValues ) { tableData1D.headerNames.push_back( GEOS_FMT( columnFmt, columnValue ) ); headerValues.push_back( columnValue ); diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 09353ddbf5d..67e779d119f 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -73,7 +73,7 @@ class TableData std::vector< std::vector< string > > m_rows; /// store error if there are any inconsistencies related to the table - std::vector< string > errorsMsg; + std::vector< string > m_errorsMsg; }; @@ -122,7 +122,7 @@ class TableData2D std::map< RowType, std::map< ColumnType, string > > m_data; /// @brief Store all column values when adding cell - std::set< real64 > columnValues; + std::set< real64 > m_columnValues; }; template< typename ... Args > @@ -142,7 +142,7 @@ template< typename T > void TableData2D::addCell( real64 const rowValue, real64 const columnValue, T const & value ) { static_assert( has_formatter< decltype(value) >, "Argument passed in addCell cannot be converted to string" ); - columnValues.insert( columnValue ); + m_columnValues.insert( columnValue ); m_data[rowValue][columnValue] = GEOS_FMT( "{}", value ); } diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 58e4d0c6897..0533b7ded6c 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -25,27 +25,6 @@ TableFormatter::TableFormatter( TableLayout const & tableLayout ): m_tableLayout( tableLayout ) {} -void TableFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > & rows ) const -{ - - for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) - { - if( rows[idxRow].size() < columns.size() ) - { - rows[idxRow].resize( columns.size(), " " ); - } - - for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) - { - if( m_tableLayout.getColumns()[idxColumn].m_parameter.enabled ) - { - columns[idxColumn].m_columnValues.push_back( rows[idxRow][idxColumn] ); - } - } - } -} - /////////////////////////////////////////////////////////////////////// ////// CSV Formatter implementation /////////////////////////////////////////////////////////////////////// @@ -125,7 +104,8 @@ string buildCell( TableLayout::Alignment const alignment, string_view value, int * @param columns Vector built in TableLayout containing all columns with their parameters * @param tableDataRows Vector built in TableData containing all rows values */ -void formatColumnsFromLayout( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > & tableDataRows ) +void formatColumnsFromLayout( std::vector< TableLayout::Column > & columns, + std::vector< std::vector< string > > & tableDataRows ) { integer idxColumn = 0; for( auto & column : columns ) @@ -146,13 +126,33 @@ TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): TableFormatter( tableLayout ) {} +void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, + std::vector< std::vector< string > > & rows ) const +{ + for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) + { + if( rows[idxRow].size() < columns.size() ) + { + rows[idxRow].resize( columns.size(), " " ); + } + + for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) + { + if( m_tableLayout.getColumns()[idxColumn].m_parameter.enabled ) + { + columns[idxColumn].m_columnValues.push_back( rows[idxRow][idxColumn] ); + } + } + } +} + string TableTextFormatter::toString( TableData const & tableData ) const { std::ostringstream tableOutput; string sectionSeparator; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); - std::vector< string > msgTableError = tableData.getErrorMsgs(); + std::vector< string > const & msgTableError = tableData.getErrorMsgs(); integer const nbValuesRows = tableDataRows.size(); formatColumnsFromLayout( columns, tableDataRows ); @@ -167,7 +167,7 @@ string TableTextFormatter::toString( TableData const & tableData ) const void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, - std::vector< string > & msgTableError, + std::vector< string > const & msgTableError, string & sectionSeparator ) const { string topSeparator; @@ -182,8 +182,8 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, buildTableSeparators( columns, topSeparator, sectionSeparator ); tableOutput << '\n'; - outputTopRows( tableOutput, msgTableError, topSeparator, TableLayout::Alignment::left ); outputTopRows( tableOutput, {tableTitle}, topSeparator, TableLayout::Alignment::center ); + outputTopRows( tableOutput, msgTableError, topSeparator, TableLayout::Alignment::left ); tableOutput << GEOS_FMT( "{}\n", sectionSeparator ); outputSectionRows( columns, sectionSeparator, tableOutput, nbHeaderRows, TableLayout::Section::header ); @@ -218,7 +218,7 @@ void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Colum { headerParts.resize( nbHeaderRows, " " ); } - columns[&headerParts - &splitHeaders[0]].m_parameter.splitColumnName = headerParts; + columns[&headerParts - &splitHeaders[0]].m_parameter.splitColumnNameLines = headerParts; } } @@ -227,7 +227,8 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu { for( auto & column : columns ) { - auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnName.begin(), column.m_parameter.splitColumnName.end(), + auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnNameLines.begin(), + column.m_parameter.splitColumnNameLines.end(), []( const auto & a, const auto & b ) {return a.size() < b.size();} ); column.m_maxStringSize = maxStringSizeHeader; @@ -265,13 +266,13 @@ void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > } void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Column > & columns, - std::vector< string > & msgTableError ) const + std::vector< string > const & msgTableError ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); string const tableTitle = string( m_tableLayout.getTitle() ); - string::size_type sectionlineLength = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2);; + string::size_type sectionlineLength = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); string::size_type maxTopLineLength = tableTitle.length(); string::size_type msgTableErrorLength = borderMargin; @@ -288,7 +289,8 @@ void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Co } sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, - []( auto sum, const auto & column ){ return sum + column.m_maxStringSize.length();} ); + []( auto sum, const auto & column ) + { return sum + column.m_maxStringSize.length();} ); if( sectionlineLength < maxTopLineLength ) { @@ -297,42 +299,33 @@ void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Co } } -void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column > & columns, +void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column > const & columns, string & topSeparator, string & sectionSeparator ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); - if( columns.size() == 1 ) + std::vector< string > colStringLines; + + string const spaceBetweenColumns = GEOS_FMT( "{:-^{}}", verticalLine, columnMargin ); + + sectionSeparator = GEOS_FMT( "{}{:-<{}}", verticalLine, "", borderMargin ); + for( auto const & col : columns ) { - sectionSeparator += GEOS_FMT( "+{:-<{}}+", - "", - ( columns[0].m_maxStringSize.length() + (borderMargin - 1) + columnMargin )); + colStringLines.push_back( string( integer( col.m_maxStringSize.length()), '-' )); } - else + + sectionSeparator += colStringLines[0]; + for( size_t i = 1; i < colStringLines.size(); i++ ) { - for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) - { - integer const cellSize = columns[idxColumn].m_maxStringSize.length(); - if( idxColumn == 0 ) - { - sectionSeparator += GEOS_FMT( "+{:-<{}}", "", ( cellSize + borderMargin )); - } - else if( idxColumn == (columns.size() - 1)) - { - sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); - sectionSeparator += GEOS_FMT( "{:->{}}", "+", ( cellSize + borderMargin + 1 ) ); - } - else - { - sectionSeparator += GEOS_FMT( "{:-^{}}", "+", columnMargin ); - sectionSeparator += GEOS_FMT( "{:->{}}", "", cellSize ); - } - } + sectionSeparator += spaceBetweenColumns + colStringLines[i]; } - topSeparator = GEOS_FMT( "+{:-<{}}+", "", sectionSeparator.size() - 2 ); // -2 for ++ + sectionSeparator += GEOS_FMT( "{:-<{}}{}", "", borderMargin, verticalLine ); + + // -2 for starting and ending char + topSeparator = GEOS_FMT( "{}{:-<{}}{}", verticalLine, "", sectionSeparator.size() - 2, verticalLine ); } void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, @@ -368,11 +361,16 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c { string cell; TableLayout::Column const currentColumn = columns[idxColumn]; + auto const & currentColumnTexts = section == TableLayout::Section::header ? + columns[idxColumn].m_parameter.splitColumnNameLines : + columns[idxColumn].m_columnValues; + cell = currentColumnTexts[idxRow]; + integer const cellSize = currentColumn.m_maxStringSize.length(); if( section == TableLayout::Section::header ) { - cell = currentColumn.m_parameter.splitColumnName[idxRow]; + cell = currentColumn.m_parameter.splitColumnNameLines[idxRow]; } else { @@ -388,15 +386,7 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c } - if( columns.size() == 1 ) - { - tableOutput << GEOS_FMT( "{:>{}}\n", "|", columnMargin ); - } - else - { - tableOutput << GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); - } - + tableOutput << GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); } if( nbRows != 0 ) { diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 7b62e4defb2..641d7c88ea9 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -46,15 +46,6 @@ class TableFormatter * @brief Destroy the Table Formatter object */ virtual ~TableFormatter() = default; - - /** - * @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 - */ - void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > & tableData ) const; - }; /** @@ -124,6 +115,23 @@ class TableTextFormatter : public TableFormatter private: + /// symbol for the extremity of a delemitor + static constexpr string_view sideCross = "+"; + /// symbol to delimit a table column + static constexpr string_view innerCross = "+"; + /// symbol for separator construction + static constexpr string_view verticalLine = "-"; + /// for the extremity of a row + static constexpr string_view 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 + */ + void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, + std::vector< std::vector< string > > & tableData ) const; + /** * @brief Converts a TableLayout into a formatted representation. * @param tableOutput The output stream @@ -133,7 +141,7 @@ class TableTextFormatter : public TableFormatter */ void outputLayout( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, - std::vector< string > & msgTableError, + std::vector< string > const & msgTableError, string & sectionSeparator ) const; /** @@ -158,7 +166,8 @@ class TableTextFormatter : public TableFormatter * @param columns Vector containing all table columns * @param extraCharacters Extra characters to be added to \p m_maxStringSize of each columns */ - void increaseColumnsSize( std::vector< TableLayout::Column > & columns, integer const extraCharacters ) const; + void increaseColumnsSize( std::vector< TableLayout::Column > & columns, + integer const extraCharacters ) const; /** * @brief Compute the max table line length @@ -166,7 +175,7 @@ class TableTextFormatter : public TableFormatter * @param msgTableError Vector containing all error messages */ void computeTableMaxLineLength( std::vector< TableLayout::Column > & columns, - std::vector< string > & msgTableError ) const; + std::vector< string > const & msgTableError ) const; /** * @brief Build all separator needed from length information contained in columns vector @@ -174,7 +183,7 @@ class TableTextFormatter : public TableFormatter * @param topSeparator Top separator to be built * @param sectionSeparator section separator to be built */ - void buildTableSeparators( std::vector< TableLayout::Column > & columns, + void buildTableSeparators( std::vector< TableLayout::Column > const & columns, string & topSeparator, string & sectionSeparator ) const; diff --git a/src/coreComponents/fileIO/Table/TableLayout.hpp b/src/coreComponents/fileIO/Table/TableLayout.hpp index a8579f342d3..6f7cd1d640e 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.hpp +++ b/src/coreComponents/fileIO/Table/TableLayout.hpp @@ -61,7 +61,7 @@ class TableLayout /// A boolean to display a colummn bool enabled = true; /// Vector containing substring column name delimited by "\n" - std::vector< string > splitColumnName; + std::vector< string > splitColumnNameLines; /** * @brief Construct a ColumnParam object with the specified name and alignment. diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index f49146881fd..cd025083d50 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -44,18 +44,18 @@ TEST( testTable, tableEmptyRow ) TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), - "\n+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n" + "\n-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n" "| InternalWellGenerator well_injector1 |\n" - "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n" "| Well | CordX | CoordZ | Prev | Next |\n" "| element no. | | | element | element |\n" "| PV weighted | | | | |\n" "| bar | | | | |\n" - "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n" "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" "| | | | | |\n" "| Duis fringilla, ligula sed porta fringilla, ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | [30.21543] | 30.45465142 | 787442 | 10 |\n" - "+----------------------------------------------------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" + "-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n" ); } @@ -74,16 +74,16 @@ TEST( testTable, tableClassic ) TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), - "\n+---------------------------------------------------------------------------------------------------------------------------------------------------------+\n" + "\n-----------------------------------------------------------------------------------------------------------------------------------------------------------\n" "| InternalWellGenerator well_injector1 |\n" - "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "-----------------------------------------------------------------------------------------------------------------------------------------------------------\n" "| Duis fringilla, ligula sed porta fringilla, | CordX | CoordZ | Prev | Next |\n" "| ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | | | element | element |\n" - "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n" + "-----------------------------------------------------------------------------------------------------------------------------------------------------------\n" "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" "| | | | | |\n" "| value23 | [30.21543] | 30.45465142 | 787442 | 10 |\n" - "+--------------------------------------------------------------------------------------------------+--------------+---------------+-----------+-----------+\n\n" + "-----------------------------------------------------------------------------------------------------------------------------------------------------------\n\n" ); } @@ -104,15 +104,15 @@ TEST( testTable, tableColumnParamClassic ) TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), - "\n+-----------------------------------------------------------------------------------------+\n" + "\n-------------------------------------------------------------------------------------------\n" "| InternalWellGenerator well_injector1 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "-------------------------------------------------------------------------------------------\n" "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" "| | | | | element | element |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "-------------------------------------------------------------------------------------------\n" "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" + "-------------------------------------------------------------------------------------------\n\n" ); } @@ -133,14 +133,14 @@ TEST( testTable, tableHiddenColumn ) TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), - "\n+--------------------------------------------------------------------------------------------------------------+\n" + "\n----------------------------------------------------------------------------------------------------------------\n" "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "+--------------------------+--------------------+---------------------------------+----------------------------+\n" + "----------------------------------------------------------------------------------------------------------------\n" "| Cras egestas | CoordX | C | CoordZ |\n" - "+--------------------------+--------------------+---------------------------------+----------------------------+\n" + "----------------------------------------------------------------------------------------------------------------\n" "| value1 | | 3.0 | 3.0129877 |\n" "| val1 | v | [3.045,42.02,89.25] | 3 |\n" - "+--------------------------+--------------------+---------------------------------+----------------------------+\n\n" ); + "----------------------------------------------------------------------------------------------------------------\n\n" ); } TEST( testTable, tableUniqueColumn ) @@ -155,14 +155,14 @@ TEST( testTable, tableUniqueColumn ) TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), - "\n+---------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "+---------------------------------------------------------------------------------------------------------------+\n" - "| Cras egestas |\n" - "+---------------------------------------------------------------------------------------------------------------+\n" - "| value1 |\n" - "| val1 |\n" - "+---------------------------------------------------------------------------------------------------------------+\n\n" ); + "\n---------------------------------------------------------------------------------------------------------------\n" + "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "---------------------------------------------------------------------------------------------------------------\n" + "| Cras egestas |\n" + "---------------------------------------------------------------------------------------------------------------\n" + "| value1 |\n" + "| val1 |\n" + "---------------------------------------------------------------------------------------------------------------\n\n" ); } TEST( testTable, tableEmptyTitle ) @@ -183,13 +183,13 @@ TEST( testTable, tableEmptyTitle ) TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), - "\n+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "\n-------------------------------------------------------------------------------------------\n" "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" "| | | | | element | element |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n" + "-------------------------------------------------------------------------------------------\n" "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" - "+----------------+----------+-----------------------+-------------+-----------+-----------+\n\n" + "-------------------------------------------------------------------------------------------\n\n" ); } @@ -210,7 +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::Conversion1D tableconverted = tableData.buildTableData( "Viscosity kg*s", + rowFmt, + columnFmt ); //format TableLayout const tableLayout( tableconverted.headerNames ); @@ -218,13 +220,13 @@ TEST( testTable, table2DTable ) //log TableTextFormatter const tableLog( tableLayout ); EXPECT_EQ( tableLog.toString( tableconverted.tableData ), - "\n+---------------------+--------------------+------------------------+\n" + "\n---------------------------------------------------------------------\n" "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" - "+---------------------+--------------------+------------------------+\n" + "---------------------------------------------------------------------\n" "| Temperature = 300 | 0.03 | 0.02 |\n" "| Temperature = 350 | 0.035 | 0.023333333333333334 |\n" "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" - "+---------------------+--------------------+------------------------+\n\n" + "---------------------------------------------------------------------\n\n" ); } @@ -246,7 +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::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", + rowFmt, + columnFmt ); //format TableLayout const tableLayout( tableConverted.headerNames ); @@ -254,15 +258,15 @@ TEST( testTable, table2DColumnMismatch ) //log TableTextFormatter const tableLog( tableLayout ); EXPECT_EQ( tableLog.toString( tableConverted.tableData ), - "\n+------------------------------------------------------------------+\n" + "\n--------------------------------------------------------------------\n" "| Remarks : some cells may be missing |\n" - "+---------------------+--------------------+-----------------------+\n" + "--------------------------------------------------------------------\n" "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" - "+---------------------+--------------------+-----------------------+\n" + "--------------------------------------------------------------------\n" "| Temperature = 300 | 0.03 | 0.02 |\n" "| Temperature = 350 | 0.035 | |\n" "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" - "+---------------------+--------------------+-----------------------+\n\n" + "--------------------------------------------------------------------\n\n" ); } } @@ -291,15 +295,15 @@ TEST( testTable, tableSetMargin ) // TableTextFormatter const tableText( tableLayout ); // EXPECT_EQ( tableText.toString( tableData ), -// "\n+----------------------------------------------------------+\n" +// "\n------------------------------------------------------------\n" // "| InternalWellGenerator well_injector1 |\n" -// "+---------+------------+---------+---------+-------+-------+\n" +// "------------------------------------------------------------\n" // "|Colonne 1| Colonne 2 |Colonne 3|Colonne 4| Prev| Next|\n" // "| | | | |element|element|\n" -// "+---------+------------+---------+---------+-------+-------+\n" +// "------------------------------------------------------------\n" // "| value 1 |long value 1| 3.0034|3.0129877| | 1|\n" // "| value 1 |long value 2| 100.45|4.0129877| 1| 2|\n" -// "+---------+------------+---------+---------+-------+-------+\n\n" +// "------------------------------------------------------------\n\n" // ); // } } @@ -307,5 +311,5 @@ TEST( testTable, tableSetMargin ) int main( int argc, char * * argv ) { testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS();; + return RUN_ALL_TESTS(); } From 9809699718140ab66fcb797d5400fa40d52c1d91 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 19 Apr 2024 16:36:36 +0200 Subject: [PATCH 105/216] final review correction --- src/coreComponents/fileIO/Table/TableData.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index a1b4b357b09..401eb08c492 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -84,17 +84,15 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, currentRowValues.reserve( rowMap.size() ); currentRowValues.push_back( GEOS_FMT( rowFmt, rowValue ) ); - integer idxColumn = 0; + std::set< real64 >::const_iterator columnIt = m_columnValues.begin(); for( auto const & [columnValue, cellValue] : rowMap ) { - //check if column numbers in the evaluated row is consistent - while( columnValue > headerValues[idxColumn] ) + // if a column value(s) is/are missing, insert empty entry(ies) + while( columnValue > *( columnIt++ ) && columnIt != m_columnValues.end() ) { currentRowValues.push_back( "" ); - ++idxColumn; } currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); - ++idxColumn; } tableData1D.tableData.addRow( std::move( currentRowValues ) ); From 46a6abe4696563ea6ba6c7595b45e1bef395b6e9 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 22 Apr 2024 10:53:44 +0200 Subject: [PATCH 106/216] method display layout added --- .../fileIO/Table/TableFormatter.cpp | 10 ++++++++++ .../fileIO/Table/TableFormatter.hpp | 5 +++++ .../fileIO/Table/unitTests/testTable.cpp | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 0533b7ded6c..b4ce0e4ddaf 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -146,6 +146,16 @@ void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Col } } +string TableTextFormatter::layoutToString() const +{ + std::ostringstream tableOutput; + string sectionSeparator; + std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); + + outputLayout( tableOutput, columns, {}, sectionSeparator ); + return tableOutput.str(); +} + string TableTextFormatter::toString( TableData const & tableData ) const { std::ostringstream tableOutput; diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 641d7c88ea9..e5c6e1e774c 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -106,6 +106,11 @@ class TableTextFormatter : public TableFormatter */ virtual ~TableTextFormatter() = default; + /** + * @return A TableLayout converted into a formatted representation. + */ + string layoutToString() const; + /** * @brief Convert the TableData to a table string. * @param tableData The TableData to convert. diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index cd025083d50..98dabc25d84 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -271,6 +271,25 @@ 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" + "| fluid1_phaseModel1_PhillipsBrineDensity_table |\n" + "-------------------------------------------------------------------------------------\n" + "| The fluid1_phaseModel1_PhillipsBrineDensity_table PVT table exceeding 500 rows. |\n" + "| To visualize the tables, go to the generated csv |\n" + "-------------------------------------------------------------------------------------\n" + ); +} + TEST( testTable, tableSetMargin ) { //////////// From 9de9d639c1c65bef62312550b5376f74204d91d9 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 22 Apr 2024 10:54:15 +0200 Subject: [PATCH 107/216] small correction after merge --- .../fileIO/Table/TableFormatter.cpp | 11 +++++++++++ .../fileIO/Table/TableFormatter.hpp | 5 +++++ .../fileIO/Table/unitTests/testTable.cpp | 19 +++++++++++++++++++ .../functions/TableFunction.cpp | 6 +++--- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 0533b7ded6c..2e8bfe722e0 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -146,6 +146,16 @@ void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Col } } +string TableTextFormatter::layoutToString() const +{ + std::ostringstream tableOutput; + string sectionSeparator; + std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); + + outputLayout( tableOutput, columns, {}, sectionSeparator ); + return tableOutput.str(); +} + string TableTextFormatter::toString( TableData const & tableData ) const { std::ostringstream tableOutput; @@ -165,6 +175,7 @@ string TableTextFormatter::toString( TableData const & tableData ) const return tableOutput.str(); } + void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, std::vector< string > const & msgTableError, diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 641d7c88ea9..e5c6e1e774c 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -106,6 +106,11 @@ class TableTextFormatter : public TableFormatter */ virtual ~TableTextFormatter() = default; + /** + * @return A TableLayout converted into a formatted representation. + */ + string layoutToString() const; + /** * @brief Convert the TableData to a table string. * @param tableData The TableData to convert. diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index cd025083d50..98dabc25d84 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -271,6 +271,25 @@ 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" + "| fluid1_phaseModel1_PhillipsBrineDensity_table |\n" + "-------------------------------------------------------------------------------------\n" + "| The fluid1_phaseModel1_PhillipsBrineDensity_table PVT table exceeding 500 rows. |\n" + "| To visualize the tables, go to the generated csv |\n" + "-------------------------------------------------------------------------------------\n" + ); +} + TEST( testTable, tableSetMargin ) { //////////// diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 480d45e0620..6c1fcb51899 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -20,9 +20,9 @@ #include "codingUtilities/Parsing.hpp" #include "common/DataTypes.hpp" #include "fileIO/Outputs/OutputBase.hpp" -#include "common/TableLayout.hpp" -#include "common/TableData.hpp" -#include "common/TableFormatter.hpp" +#include "fileIO/Table/TableLayout.hpp" +#include "fileIO/Table/TableData.hpp" +#include "fileIO/Table/TableFormatter.hpp" #include From fe80c594ca141c27147317c429250d2a1901eff0 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 13 May 2024 14:07:29 +0200 Subject: [PATCH 108/216] review correction #1 --- src/coreComponents/common/Format.hpp | 4 +-- src/coreComponents/fileIO/Table/TableData.cpp | 14 +++------ src/coreComponents/fileIO/Table/TableData.hpp | 29 +++++++++---------- .../fileIO/Table/TableFormatter.cpp | 14 +++------ 4 files changed, 23 insertions(+), 38 deletions(-) diff --git a/src/coreComponents/common/Format.hpp b/src/coreComponents/common/Format.hpp index c6ceee14a56..a61f88f29cc 100644 --- a/src/coreComponents/common/Format.hpp +++ b/src/coreComponents/common/Format.hpp @@ -108,10 +108,10 @@ constexpr auto GEOS_FMT_NS::detail::has_const_formatter_impl< GEOS_FMT_NS::forma */ #if __cplusplus < 202002L template< class T > -static constexpr bool has_formatter = fmt::has_formatter< fmt::remove_cvref_t< T >, fmt::format_context >(); +static constexpr bool has_formatter_v = fmt::has_formatter< fmt::remove_cvref_t< T >, fmt::format_context >(); #else template< typename T > -concept has_formatter = requires ( T& v, std::format_context ctx ) +concept has_formatter_v = requires ( T& v, std::format_context ctx ) { std::formatter< std::remove_cvref_t< T > >().format( v, ctx ); }; diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 401eb08c492..0d64dbc7d7c 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -28,7 +28,7 @@ void TableData::addRow( std::vector< string > const & row ) string msg = "Remarks : some cells may be missing"; if( std::find( m_errorsMsg.begin(), m_errorsMsg.end(), msg ) == m_errorsMsg.end()) { - m_errorsMsg.push_back( msg ); + addErrorMsg(msg); } } m_rows.push_back( row ); @@ -37,6 +37,7 @@ void TableData::addRow( std::vector< string > const & row ) void TableData::clear() { m_rows.clear(); + m_errorsMsg.clear(); } std::vector< std::vector< string > > const & TableData::getTableDataRows() const @@ -49,16 +50,9 @@ std::vector< string > const & TableData::getErrorMsgs() const return m_errorsMsg; } -void TableData::addErrorMsgs( string const & msg ) +void TableData::addErrorMsg( string const & msg ) { - std::vector< string > splitHeaderParts; - std::istringstream ss( msg ); - string splitErrors; - - while( std::getline( ss, splitErrors, '\n' )) - { - m_errorsMsg.push_back( splitErrors ); - } + m_errorsMsg.push_back( msg ); } TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 67e779d119f..0737483cdf0 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -31,7 +31,6 @@ namespace geos class TableData { public: - /** * @brief Add a row to the table. * The values passed to addRow (can be any type). @@ -62,12 +61,6 @@ class TableData */ std::vector< string > const & getErrorMsgs() const; - /** - * @brief Set an error message - * @param msg The error msg to vector - */ - void addErrorMsgs( string const & msg ); - protected: /// vector containing all rows with cell values std::vector< std::vector< string > > m_rows; @@ -75,6 +68,13 @@ class TableData /// store error if there are any inconsistencies related to the table std::vector< string > m_errorsMsg; +private: + /** + * @brief Set an error message + * @param msg The error msg to vector + */ + void addErrorMsg( string const & msg ); + }; /** @@ -83,7 +83,9 @@ class TableData class TableData2D { public: - + using RowType = real64; + using ColumnType = real64; + /// Struct containing conversion informations struct Conversion1D { @@ -101,7 +103,7 @@ class TableData2D * @param columnValue The value of the column containing the cell. */ template< typename T > - void addCell( real64 rowValue, real64 columnValue, T const & value ); + void addCell( RowType rowValue, ColumnType columnValue, T const & value ); /** * @return Convert and return a struct containing a 1D Table, the column names list from a TableData2D and any errors related to the table @@ -115,9 +117,6 @@ class TableData2D Conversion1D buildTableData( string_view dataDescription, string_view rowFmt = "{}", string_view columnFmt = "{}" ) const; private: - using RowType = real64; - using ColumnType = real64; - /// @brief all cell values by their [ row ][ column ] std::map< RowType, std::map< ColumnType, string > > m_data; @@ -130,7 +129,7 @@ void TableData::addRow( Args const &... args ) { std::vector< string > m_cellsValue; ( [&] { - static_assert( has_formatter< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); + static_assert( has_formatter_v< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); string const cellValue = GEOS_FMT( "{}", args ); m_cellsValue.push_back( cellValue ); } (), ...); @@ -141,12 +140,10 @@ void TableData::addRow( Args const &... args ) template< typename T > void TableData2D::addCell( real64 const rowValue, real64 const columnValue, T const & value ) { - static_assert( has_formatter< decltype(value) >, "Argument passed in addCell cannot be converted to string" ); + static_assert( has_formatter_v< decltype(value) >, "Argument passed in addCell cannot be converted to string" ); m_columnValues.insert( columnValue ); m_data[rowValue][columnValue] = GEOS_FMT( "{}", value ); } - } - #endif diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index b4ce0e4ddaf..43e5741a401 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -17,6 +17,7 @@ */ #include +#include "codingUtilities/StringUtilities.hpp" #include "TableFormatter.hpp" namespace geos { @@ -59,16 +60,9 @@ string TableCSVFormatter::dataToString( TableData const & tableData ) const for( const auto & row : rowsValues ) { - for( size_t idxColumn = 0; idxColumn < row.size(); ++idxColumn ) - { - oss << row[idxColumn]; - if( idxColumn < row.size() - 1 ) - { - oss << ","; - } - } - oss << "\n"; + oss << stringutilities::join( row.cbegin(), row.cend(), ",") << "\n"; } + return oss.str(); } @@ -162,7 +156,7 @@ string TableTextFormatter::toString( TableData const & tableData ) const string sectionSeparator; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); - std::vector< string > const & msgTableError = tableData.getErrorMsgs(); + std::vector< string > const & msgTableError = tableData.getErrorMsgs(); integer const nbValuesRows = tableDataRows.size(); formatColumnsFromLayout( columns, tableDataRows ); From abb994e950465f1bcae1126e416d1f6ca91bac88 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 17 May 2024 15:04:26 +0200 Subject: [PATCH 109/216] variables renamed --- .../fileIO/Table/TableFormatter.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 43e5741a401..7f1bd78c154 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -60,7 +60,7 @@ string TableCSVFormatter::dataToString( TableData const & tableData ) const for( const auto & row : rowsValues ) { - oss << stringutilities::join( row.cbegin(), row.cend(), ",") << "\n"; + oss << stringutilities::join( row.cbegin(), row.cend(), "," ) << "\n"; } return oss.str(); @@ -282,13 +282,12 @@ void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Co if( !msgTableError.empty() ) { - auto it = std::max_element( msgTableError.begin(), msgTableError.end(), - []( const auto & a, const auto & b ) { + auto maxStringSize = *(std::max_element( msgTableError.begin(), msgTableError.end(), + []( const auto & a, const auto & b ) { return a.size() < b.size(); - } ); - string maxStringSize = *it; + } )); - msgTableErrorLength += maxStringSize.size() + 1; // for \n set later + msgTableErrorLength += maxStringSize.size() + 1; // +1 for \n set later maxTopLineLength = std::max( maxTopLineLength, msgTableErrorLength ); } @@ -310,25 +309,26 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); - std::vector< string > colStringLines; + std::vector< string > maxStringPerColumn; string const spaceBetweenColumns = GEOS_FMT( "{:-^{}}", verticalLine, columnMargin ); sectionSeparator = GEOS_FMT( "{}{:-<{}}", verticalLine, "", borderMargin ); for( auto const & col : columns ) { - colStringLines.push_back( string( integer( col.m_maxStringSize.length()), '-' )); + maxStringPerColumn.push_back( string( integer( col.m_maxStringSize.length()), '-' )); } - sectionSeparator += colStringLines[0]; - for( size_t i = 1; i < colStringLines.size(); i++ ) + sectionSeparator += maxStringPerColumn[0]; + + for( size_t i = 1; i < maxStringPerColumn.size(); i++ ) { - sectionSeparator += spaceBetweenColumns + colStringLines[i]; + sectionSeparator += spaceBetweenColumns + maxStringPerColumn[i]; } sectionSeparator += GEOS_FMT( "{:-<{}}{}", "", borderMargin, verticalLine ); - // -2 for starting and ending char + // -2 because we can have this pattern +---+ topSeparator = GEOS_FMT( "{}{:-<{}}{}", verticalLine, "", sectionSeparator.size() - 2, verticalLine ); } From c851b38c7d8991fe03124f86c9e0e0357e4c6519 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 23 May 2024 17:10:09 +0200 Subject: [PATCH 110/216] uncrustify + doc --- src/coreComponents/fileIO/Table/TableData.cpp | 2 +- src/coreComponents/fileIO/Table/TableData.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 0d64dbc7d7c..dd26e9d0262 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -28,7 +28,7 @@ void TableData::addRow( std::vector< string > const & row ) string msg = "Remarks : some cells may be missing"; if( std::find( m_errorsMsg.begin(), m_errorsMsg.end(), msg ) == m_errorsMsg.end()) { - addErrorMsg(msg); + addErrorMsg( msg ); } } m_rows.push_back( row ); diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 0737483cdf0..0d4a189cc62 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -85,7 +85,7 @@ class TableData2D public: using RowType = real64; using ColumnType = real64; - + /// Struct containing conversion informations struct Conversion1D { From 0ae0c74099ae08a4e6e59f9cd215f99bd9e15c4f Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 23 May 2024 17:10:33 +0200 Subject: [PATCH 111/216] doc --- src/coreComponents/fileIO/Table/TableData.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 0d4a189cc62..51301f689c0 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -83,7 +83,10 @@ class TableData class TableData2D { public: + + /// Type real64 for a row using RowType = real64; + /// Type real64 for a column using ColumnType = real64; /// Struct containing conversion informations From e9639ea91467053ce7c74a0b477ef26d10109013 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 24 May 2024 16:45:12 +0200 Subject: [PATCH 112/216] remove unused code --- src/coreComponents/fileIO/Table/TableData.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index dd26e9d0262..aa56b2f8afc 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -60,7 +60,6 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, string_view columnFmt ) const { TableData2D::Conversion1D tableData1D; - std::vector< real64 > headerValues; std::vector< size_t > rowsLength; tableData1D.headerNames.push_back( string( targetUnit ) ); @@ -68,7 +67,6 @@ TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, for( auto const & columnValue : m_columnValues ) { tableData1D.headerNames.push_back( GEOS_FMT( columnFmt, columnValue ) ); - headerValues.push_back( columnValue ); } // insert row value and row cell values From 924d9559aa18e4dc967814eb1a83813210fa94f8 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 27 May 2024 11:07:52 +0200 Subject: [PATCH 113/216] syntax correction --- .../CO2Brine/functions/BrineEnthalpy.cpp | 4 +-- .../CO2Brine/functions/CO2Enthalpy.cpp | 4 +-- .../CO2Brine/functions/CO2Solubility.cpp | 4 +-- .../CO2Brine/functions/CO2Solubility.hpp | 18 ++++++++----- .../functions/EzrokhiBrineDensity.cpp | 4 +-- .../functions/EzrokhiBrineViscosity.cpp | 2 +- .../functions/FenghourCO2Viscosity.cpp | 2 +- .../CO2Brine/functions/PVTFunctionBase.hpp | 2 +- .../functions/PhillipsBrineDensity.cpp | 2 +- .../functions/PhillipsBrineViscosity.cpp | 2 +- .../functions/SpanWagnerCO2Density.cpp | 2 +- .../CO2Brine/functions/WaterDensity.cpp | 2 +- .../functions/TableFunction.cpp | 26 +++++++++---------- 13 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp index 98674175551..2b93e14b54f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp @@ -206,8 +206,8 @@ BrineEnthalpy::BrineEnthalpy( string const & name, m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); m_brineEnthalpyTable = makeBrineEnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - checkPrint( m_CO2EnthalpyTable, printInCsv, printInLog ); - checkPrint( m_brineEnthalpyTable, printInCsv, printInLog ); + checkTableOutput( m_CO2EnthalpyTable, printInCsv, printInLog ); + checkTableOutput( m_brineEnthalpyTable, printInCsv, printInLog ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp index 21145414ff7..beda83ad15b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp @@ -267,8 +267,8 @@ CO2Enthalpy::CO2Enthalpy( string const & name, m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - checkPrint( m_CO2EnthalpyTable, printInCsv, printInLog ); - checkPrint( m_CO2EnthalpyTable, printInCsv, printInLog ); + checkTableOutput( m_CO2EnthalpyTable, printInCsv, printInLog ); + checkTableOutput( m_CO2EnthalpyTable, printInCsv, printInLog ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp index af64d0be3c3..6ba9fe83f3d 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp @@ -257,8 +257,8 @@ CO2Solubility::CO2Solubility( string const & name, std::tie( m_CO2SolubilityTable, m_WaterVapourisationTable ) = makeSolubilityTables( m_modelName, inputParams, solubilityModel ); - checkPrint( m_CO2SolubilityTable, printInCsv, printInLog ); - checkPrint( m_WaterVapourisationTable, printInCsv, printInLog ); + checkTableOutput( m_CO2SolubilityTable, printInCsv, printInLog ); + checkTableOutput( m_WaterVapourisationTable, printInCsv, printInLog ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp index f050f8685a0..0d9089d5def 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp @@ -128,17 +128,23 @@ class CO2Solubility : public FlashModelBase */ void checkTablesParameters( real64 pressure, real64 temperature ) const override final; - void checkPrint ( TableFunction const * table, bool const printInCsv, bool const printInLog - ) + /** + * @brief Check whether we print to screen or to a csv file + * @param table + * @param printInCsv + * @param printInLog + */ + void checkTableOutput( TableFunction const * table, bool const printInCsv, bool const printInLog + ) { - if( printInCsv || ( printInLog && table->numDimensions() >= 3 ) ) - { - table->printInCSV( table->getName() ); - } if( printInLog && table->numDimensions() <= 2 ) { table->printInLog( table->getName() ); } + if( printInCsv || ( printInLog && table->numDimensions() >= 3 ) ) + { + table->printInCSV( table->getName() ); + } } /// Type of kernel wrapper for in-kernel update diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp index f076950a7e7..bdb752f90c1 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp @@ -53,8 +53,8 @@ EzrokhiBrineDensity::EzrokhiBrineDensity( string const & name, m_waterSatDensityTable = PureWaterProperties::makeSaturationDensityTable( m_functionName, FunctionManager::getInstance() ); m_waterSatPressureTable = PureWaterProperties::makeSaturationPressureTable( m_functionName, FunctionManager::getInstance() ); - checkPrint( m_waterSatPressureTable, printInCsv, printInLog ); - checkPrint( m_waterSatDensityTable, printInCsv, printInLog ); + checkTableOutput( m_waterSatPressureTable, printInCsv, printInLog ); + checkTableOutput( m_waterSatDensityTable, printInCsv, printInLog ); } void EzrokhiBrineDensity::makeCoefficients( string_array const & inputPara ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp index 86eb0447536..ad601ccdfea 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp @@ -52,7 +52,7 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, makeCoefficients( inputPara ); m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); - checkPrint( m_waterViscosityTable, printInCsv, printInLog ); + checkTableOutput( m_waterViscosityTable, printInCsv, printInLog ); } void EzrokhiBrineViscosity::makeCoefficients( string_array const & inputPara ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp index 3966d505340..5c21be4c08c 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp @@ -149,7 +149,7 @@ FenghourCO2Viscosity::FenghourCO2Viscosity( string const & name, { m_CO2ViscosityTable = makeViscosityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - checkPrint( m_CO2ViscosityTable, printInCsv, printInLog ); + checkTableOutput( m_CO2ViscosityTable, printInCsv, printInLog ); } void FenghourCO2Viscosity::checkTablesParameters( real64 const pressure, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index 69dcee9aa75..b9f3d09cdf7 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -146,7 +146,7 @@ class PVTFunctionBase * @param printInCsv Boolean for printing in CSV * @param printInLog Boolean for printing in Log */ - void checkPrint ( TableFunction const * table, bool const printInCsv, bool const printInLog ) + void checkTableOutput ( TableFunction const * table, bool const printInCsv, bool const printInLog ) { if( printInCsv || ( printInLog && table->numDimensions() >= 3 ) ) { diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp index 49dbb9bd295..9f596a67114 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp @@ -190,7 +190,7 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, m_brineDensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - checkPrint( m_brineDensityTable, printInCsv, printInLog ); + checkTableOutput( m_brineDensityTable, printInCsv, printInLog ); } PhillipsBrineDensity::KernelWrapper diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp index 8b7eb43125b..e1ef7fa085e 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp @@ -45,7 +45,7 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); makeCoefficients( inputPara ); - checkPrint( m_waterViscosityTable, printInCsv, printInLog ); + checkTableOutput( m_waterViscosityTable, printInCsv, printInLog ); } void PhillipsBrineViscosity::makeCoefficients( string_array const & inputPara ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp index 14c290421c3..33f02a73ba3 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp @@ -289,7 +289,7 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, m_CO2DensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - checkPrint( m_CO2DensityTable, printInCsv, printInLog ); + checkTableOutput( m_CO2DensityTable, printInCsv, printInLog ); } void SpanWagnerCO2Density::checkTablesParameters( real64 const pressure, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp index bb46a26d030..5a86df14359 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp @@ -45,7 +45,7 @@ WaterDensity::WaterDensity( string const & name, GEOS_UNUSED_VAR( inputParams ); m_waterDensityTable = PureWaterProperties::makeSaturationDensityTable( m_functionName, FunctionManager::getInstance() ); - checkPrint( m_waterDensityTable, printInCsv, printInLog ); + checkTableOutput( m_waterDensityTable, printInCsv, printInLog ); } void WaterDensity::checkTablesParameters( real64 const pressure, diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 9a4bf3732e8..cb1a213dba7 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -188,7 +188,9 @@ void TableFunction::checkCoord( real64 const coord, localIndex const dim ) const void TableFunction::printInCSV( string const & filename ) const { std::ofstream os( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); - + GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to inputFiles/compositionalMultiphaseWell/{}/{}.csv \n", + OutputBase::getOutputDirectory(), + filename )); integer const numDimensions = LvArray::integerConversion< integer >( m_coordinates.size() ); if( numDimensions != 2 ) @@ -263,15 +265,12 @@ void TableFunction::printInCSV( string const & filename ) const os.close(); } -void TableFunction::printInLog( string const & filename ) const +void TableFunction::printInLog( string const & title ) const { integer const numDimensions = LvArray::integerConversion< integer >( m_coordinates.size() ); - std::cout << GEOS_FMT( "CSV Generated to inputFiles/compositionalMultiphaseWell/{}/{}.csv \n", - OutputBase::getOutputDirectory(), - filename ); - std::cout << GEOS_FMT( "Values in the table are represented by : {}", units::getDescription( m_valueUnit )); + GEOS_LOG_RANK_0( GEOS_FMT( "Values in the table are represented by : {}", units::getDescription( m_valueUnit ))); if( numDimensions == 1 ) { @@ -286,7 +285,7 @@ void TableFunction::printInLog( string const & filename ) const TableLayout const tableLayout( { string( units::getDescription( getDimUnit( 0 ))), string( units::getDescription( m_valueUnit )) - }, filename ); + }, title ); TableTextFormatter const logTable( tableLayout ); GEOS_LOG_RANK_0( logTable.toString( tableData )); @@ -297,8 +296,7 @@ void TableFunction::printInLog( string const & filename ) const arraySlice1d< real64 const > const coordsY = m_coordinates[1]; integer const nX = coordsX.size(); integer const nY = coordsY.size(); - std::vector< string > vecDescription; - std::vector< std::vector< string > > vRowsValues; + std::vector< string > columnNames; integer nbRows = 0; //1. collect @@ -315,13 +313,13 @@ void TableFunction::printInLog( string const & filename ) const if( nbRows <= 500 ) { //2. format - vecDescription.push_back( string( units::getDescription( getDimUnit( 0 )))); + columnNames.push_back( string( units::getDescription( getDimUnit( 0 )))); for( integer idxY = 0; idxY < nY; idxY++ ) { string description = string( units::getDescription( getDimUnit( 1 ))) + "=" + std::to_string( coordsY[idxY] ); - vecDescription.push_back( description ); + columnNames.push_back( description ); } - TableLayout const tableLayout( vecDescription, filename ); + TableLayout const tableLayout( columnNames, title ); //3. log TableTextFormatter const table2DLog( tableLayout ); @@ -330,8 +328,8 @@ void TableFunction::printInLog( string const & filename ) const else { //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 ); + string log = GEOS_FMT( "The {} PVT table exceeding 500 rows.\nTo visualize the tables, go to the generated csv \n", title ); + TableLayout const tableLayoutInfos( {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}}, title ); //3. log TableTextFormatter const tableLog( tableLayoutInfos ); From ac0cec8bbf2d9be3c864bdfbf92c18584cb3c5ca Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 27 May 2024 11:42:54 +0200 Subject: [PATCH 114/216] variable correction --- src/coreComponents/functions/TableFunction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 01c9cf6db81..0055ee897b8 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -318,7 +318,7 @@ void TableFunction::printInLog( string const & title ) const TableData2D::Conversion1D const tableConverted = tableData2D.buildTableData( string( units::getDescription( m_valueUnit )), rowFmt, columnFmt ); - TableLayout const tableLayout( tableConverted.headerNames, filename ); + TableLayout const tableLayout( tableConverted.headerNames, title ); //3. log TableTextFormatter const table2DLog( tableLayout ); From d6415a778a2169a27d926dcddbc5b6b944a72502 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 30 May 2024 10:52:42 +0200 Subject: [PATCH 115/216] doc + code clarification --- src/coreComponents/fileIO/Table/TableData.hpp | 13 +- .../fileIO/Table/TableFormatter.cpp | 140 ++++++++++-------- .../fileIO/Table/TableFormatter.hpp | 21 +-- .../fileIO/Table/TableLayout.cpp | 2 +- .../fileIO/Table/TableLayout.hpp | 8 +- 5 files changed, 100 insertions(+), 84 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 51301f689c0..e7dbbb12075 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -61,13 +61,6 @@ class TableData */ std::vector< string > const & getErrorMsgs() const; -protected: - /// vector containing all rows with cell values - std::vector< std::vector< string > > m_rows; - - /// store error if there are any inconsistencies related to the table - std::vector< string > m_errorsMsg; - private: /** * @brief Set an error message @@ -75,6 +68,12 @@ class TableData */ void addErrorMsg( string const & msg ); + /// vector containing all rows with cell values + std::vector< std::vector< string > > m_rows; + + /// store error if there are any inconsistencies related to the table + std::vector< string > m_errorsMsg; + }; /** diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 7f1bd78c154..024c3168cfd 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -143,17 +143,17 @@ void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Col string TableTextFormatter::layoutToString() const { std::ostringstream tableOutput; - string sectionSeparator; + string sectionSeparatingLine; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); - outputLayout( tableOutput, columns, {}, sectionSeparator ); + outputLayout( tableOutput, columns, {}, sectionSeparatingLine ); return tableOutput.str(); } string TableTextFormatter::toString( TableData const & tableData ) const { std::ostringstream tableOutput; - string sectionSeparator; + string sectionSeparatingLine; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); std::vector< string > const & msgTableError = tableData.getErrorMsgs(); @@ -162,8 +162,8 @@ string TableTextFormatter::toString( TableData const & tableData ) const formatColumnsFromLayout( columns, tableDataRows ); fillTableColumnsFromRows( columns, tableDataRows ); - outputLayout( tableOutput, columns, msgTableError, sectionSeparator ); - outputSectionRows( columns, sectionSeparator, tableOutput, nbValuesRows, TableLayout::Section::values ); + outputLayout( tableOutput, columns, msgTableError, sectionSeparatingLine ); + outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbValuesRows, TableLayout::Section::values ); tableOutput << '\n'; return tableOutput.str(); @@ -172,7 +172,7 @@ string TableTextFormatter::toString( TableData const & tableData ) const void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, std::vector< string > const & msgTableError, - string & sectionSeparator ) const + string & sectionSeparatingLine ) const { string topSeparator; size_t nbHeaderRows = 0; @@ -182,15 +182,15 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, splitAndSetColumnNames( columns, nbHeaderRows, splitHeaders ); findAndSetMaxStringSize( columns ); - computeTableMaxLineLength( columns, msgTableError ); - buildTableSeparators( columns, topSeparator, sectionSeparator ); + computeTableWidth( columns, msgTableError ); + buildTableSeparators( columns, topSeparator, sectionSeparatingLine ); tableOutput << '\n'; outputTopRows( tableOutput, {tableTitle}, topSeparator, TableLayout::Alignment::center ); outputTopRows( tableOutput, msgTableError, topSeparator, TableLayout::Alignment::left ); - tableOutput << GEOS_FMT( "{}\n", sectionSeparator ); + tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - outputSectionRows( columns, sectionSeparator, tableOutput, nbHeaderRows, TableLayout::Section::header ); + outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbHeaderRows, TableLayout::Section::header ); } void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Column > & columns, @@ -269,17 +269,8 @@ void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > } } -void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Column > & columns, - std::vector< string > const & msgTableError ) const +void computeTableErrorLength( std::vector< string > const & msgTableError, string::size_type & msgTableErrorLength ) { - integer const columnMargin = m_tableLayout.getColumnMargin(); - integer const borderMargin = m_tableLayout.getBorderMargin(); - string const tableTitle = string( m_tableLayout.getTitle() ); - - string::size_type sectionlineLength = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); - string::size_type maxTopLineLength = tableTitle.length(); - string::size_type msgTableErrorLength = borderMargin; - if( !msgTableError.empty() ) { auto maxStringSize = *(std::max_element( msgTableError.begin(), msgTableError.end(), @@ -287,14 +278,33 @@ void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Co return a.size() < b.size(); } )); - msgTableErrorLength += maxStringSize.size() + 1; // +1 for \n set later - maxTopLineLength = std::max( maxTopLineLength, msgTableErrorLength ); + msgTableErrorLength += maxStringSize.size() + 1; // max string size + line return at the end } +} +void computeTableSectionLength( std::vector< TableLayout::Column > & columns, string::size_type & sectionlineLength ) +{ sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, []( auto sum, const auto & column ) { return sum + column.m_maxStringSize.length();} ); +} +void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & columns, + std::vector< string > const & msgTableError ) const +{ + integer const columnMargin = m_tableLayout.getColumnMargin(); + integer const borderMargin = m_tableLayout.getBorderMargin(); + string const tableTitle = string( m_tableLayout.getTitle() ); + + string::size_type sectionLengthWithSpacing = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); + string::size_type sectionlineLength = sectionLengthWithSpacing; + string::size_type maxTopLineLength = tableTitle.length(); + string::size_type msgTableErrorLength = borderMargin; + + computeTableErrorLength( msgTableError, msgTableErrorLength ); + computeTableSectionLength( columns, sectionlineLength ); + + maxTopLineLength = std::max( maxTopLineLength, msgTableErrorLength ); if( sectionlineLength < maxTopLineLength ) { integer const extraCharacters = maxTopLineLength - sectionlineLength; @@ -302,34 +312,47 @@ void TableTextFormatter::computeTableMaxLineLength( std::vector< TableLayout::Co } } +std::string repeatString( std::string_view str, int count ) +{ + std::string result; + for( int i = 0; i < count; ++i ) + { + result += str; + } + return result; +} + + void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column > const & columns, string & topSeparator, - string & sectionSeparator ) const + string & sectionSeparatingLine ) const { - integer const columnMargin = m_tableLayout.getColumnMargin(); - integer const borderMargin = m_tableLayout.getBorderMargin(); + { // section separator line + integer const columnMargin = m_tableLayout.getColumnMargin(); + integer const borderMargin = m_tableLayout.getBorderMargin(); - std::vector< string > maxStringPerColumn; + std::vector< string > maxStringPerColumn; + for( auto const & column : columns ) + { + maxStringPerColumn.push_back( repeatString( verticalLine, column.m_maxStringSize.length()) ); + } - string const spaceBetweenColumns = GEOS_FMT( "{:-^{}}", verticalLine, columnMargin ); + // Append the first column separator string + sectionSeparatingLine += maxStringPerColumn[0]; + string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", verticalLine, columnMargin ); + sectionSeparatingLine = stringutilities::join( maxStringPerColumn, patternBetweenColumns ); - sectionSeparator = GEOS_FMT( "{}{:-<{}}", verticalLine, "", borderMargin ); - for( auto const & col : columns ) - { - maxStringPerColumn.push_back( string( integer( col.m_maxStringSize.length()), '-' )); + //Append the left border to sectionSeparatingLine + sectionSeparatingLine += GEOS_FMT( "{}{:-<{}}", verticalLine, "", borderMargin ); + //Append the right border to sectionSeparatingLine + sectionSeparatingLine += GEOS_FMT( "{:-<{}}{}", "", borderMargin, verticalLine ); } - sectionSeparator += maxStringPerColumn[0]; - - for( size_t i = 1; i < maxStringPerColumn.size(); i++ ) - { - sectionSeparator += spaceBetweenColumns + maxStringPerColumn[i]; + { // top line separator + // -2 because we can have '+' to the extremity of top separator + integer const topSeparatorLength = sectionSeparatingLine.size() - 2; + topSeparator = GEOS_FMT( "{}{:-<{}}{}", verticalLine, "", topSeparatorLength, verticalLine ); } - - sectionSeparator += GEOS_FMT( "{:-<{}}{}", "", borderMargin, verticalLine ); - - // -2 because we can have this pattern +---+ - topSeparator = GEOS_FMT( "{}{:-<{}}{}", verticalLine, "", sectionSeparator.size() - 2, verticalLine ); } void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, @@ -342,7 +365,7 @@ void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, tableOutput << GEOS_FMT( "{}\n", topSeparator ); for( std::string const & str : msg ) { - tableOutput << "|" << string( m_tableLayout.getBorderMargin(), ' ' ); + tableOutput << horizontalLine << string( m_tableLayout.getBorderMargin(), ' ' ); tableOutput << buildCell( alignment, str, (topSeparator.length() - 6)); tableOutput << string( m_tableLayout.getBorderMargin(), ' ' ) << "|\n"; } @@ -350,7 +373,7 @@ void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, } void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > const & columns, - string_view sectionSeparator, + string_view sectionSeparatingLine, std::ostringstream & tableOutput, integer const nbRows, TableLayout::Section const section ) const @@ -360,41 +383,34 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c for( integer idxRow = 0; idxRow< nbRows; ++idxRow ) { - tableOutput << GEOS_FMT( "{:<{}}", "|", 1 + borderMargin ); + // Append the left border + tableOutput << GEOS_FMT( "{:<{}}", horizontalLine, 1 + borderMargin ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { - string cell; TableLayout::Column const currentColumn = columns[idxColumn]; - auto const & currentColumnTexts = section == TableLayout::Section::header ? - columns[idxColumn].m_parameter.splitColumnNameLines : - columns[idxColumn].m_columnValues; - cell = currentColumnTexts[idxRow]; - + auto const & columnContent = section == TableLayout::Section::header ? + columns[idxColumn].m_parameter.splitColumnNameLines : + columns[idxColumn].m_columnValues; + string cell = columnContent[idxRow]; integer const cellSize = currentColumn.m_maxStringSize.length(); - if( section == TableLayout::Section::header ) - { - cell = currentColumn.m_parameter.splitColumnNameLines[idxRow]; - } - else - { - cell = currentColumn.m_columnValues[idxRow]; - } - tableOutput << buildCell( currentColumn.m_parameter.alignment, cell, cellSize ); + // Add space between column if( idxColumn < columns.size() - 1 ) { - tableOutput << GEOS_FMT( "{:^{}}", "|", columnMargin ); + tableOutput << GEOS_FMT( "{:^{}}", horizontalLine, columnMargin ); } } - tableOutput << GEOS_FMT( "{:>{}}\n", "|", borderMargin + 1 ); + // Append right border with line return + tableOutput << GEOS_FMT( "{:>{}}\n", horizontalLine, borderMargin + 1 ); } + if( nbRows != 0 ) { - tableOutput << GEOS_FMT( "{}\n", sectionSeparator ); + tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); } } } diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index e5c6e1e774c..a1843894c3b 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -142,12 +142,12 @@ class TableTextFormatter : public TableFormatter * @param tableOutput The output stream * @param columns The vector containing all table columns * @param msgTableError A vector containg all error related to the table - * @param sectionSeparator An empty string for building the section separator + * @param sectionSeparatingLine An empty string for building the section separator */ void outputLayout( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, std::vector< string > const & msgTableError, - string & sectionSeparator ) const; + string & sectionSeparatingLine ) const; /** * @brief Split all header names by detecting the newline \\n character. and @@ -175,22 +175,23 @@ class TableTextFormatter : public TableFormatter integer const extraCharacters ) const; /** - * @brief Compute the max table line length + * @brief Compute the max table line length, taking into account the length of : title, error, columns header and content + * Increase the size of the columns if necessary * @param columns Vector of column containing containing the largest string for each column * @param msgTableError Vector containing all error messages */ - void computeTableMaxLineLength( std::vector< TableLayout::Column > & columns, - std::vector< string > const & msgTableError ) const; + void computeTableWidth( std::vector< TableLayout::Column > & columns, + std::vector< string > const & msgTableError ) const; /** - * @brief Build all separator needed from length information contained in columns vector + * @brief Build all separators needed from content length contained in the columns vector * @param columns Vector containing all table columns * @param topSeparator Top separator to be built - * @param sectionSeparator section separator to be built + * @param sectionSeparatingLine Line section separator to be built */ void buildTableSeparators( std::vector< TableLayout::Column > const & columns, string & topSeparator, - string & sectionSeparator ) const; + string & sectionSeparatingLine ) const; /** * @brief Add a row on top of the table @@ -207,14 +208,14 @@ class TableTextFormatter : public TableFormatter /** * @brief Output a section by specifying it's type ( header or section ) * @param columns Vector containing all table columns - * @param sectionSeparator Line separator between sections + * @param sectionSeparatingLine Line separator between sections * @param rows A section row * @param nbRows Indicates the number of lines in a section * @param section The section to be built * @note Add the ending line if there are one or more rows */ void outputSectionRows( std::vector< TableLayout::Column > const & columns, - string_view sectionSeparator, + string_view sectionSeparatingLine, std::ostringstream & rows, integer const nbRows, TableLayout::Section const section ) const; diff --git a/src/coreComponents/fileIO/Table/TableLayout.cpp b/src/coreComponents/fileIO/Table/TableLayout.cpp index 51d0bfb4906..726a92eab36 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.cpp +++ b/src/coreComponents/fileIO/Table/TableLayout.cpp @@ -72,7 +72,7 @@ integer const & TableLayout::getColumnMargin() const integer const & TableLayout::getMarginTitle() const { - return m_marginTitle; + return m_titleMargin; } } diff --git a/src/coreComponents/fileIO/Table/TableLayout.hpp b/src/coreComponents/fileIO/Table/TableLayout.hpp index 6f7cd1d640e..f19759ae453 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.hpp +++ b/src/coreComponents/fileIO/Table/TableLayout.hpp @@ -122,12 +122,12 @@ class TableLayout string_view getTitle() const; /** - * @return The border margin + * @return The border margin, number of spaces at both left and right table sides */ integer const & getBorderMargin() const; /** - * @return The column margin + * @return The column margin, numbers of spaces separating both left and right side from each column content */ integer const & getColumnMargin() const; @@ -137,7 +137,7 @@ class TableLayout integer const & getMarginTitle() const; /** - * @brief Set the minimal margin width between row content and borders. + * @brief Set the minimal margin width between cell content and borders. * @param marginValue The margin value */ void setMargin( MarginValue marginValue ); @@ -148,7 +148,7 @@ class TableLayout string m_tableTitle; integer m_borderMargin; integer m_columnMargin; - integer m_marginTitle = 2; + integer m_titleMargin = 2; }; } From eaa89195c1f495262e5354d9b68902fd26911bd9 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 31 May 2024 10:47:16 +0200 Subject: [PATCH 116/216] more code simplification --- .../fileIO/Table/TableFormatter.cpp | 55 +++++++------------ .../fileIO/Table/TableFormatter.hpp | 8 +-- 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 024c3168cfd..d49204653d8 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -250,22 +250,17 @@ void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > integer const extraCharacters ) const { integer const extraCharactersPerColumn = std::ceil( extraCharacters / columns.size() ); - for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { - integer newStringSize = extraCharactersPerColumn + columns[idxColumn].m_maxStringSize.size(); + integer newMaxStringSize = extraCharactersPerColumn + columns[idxColumn].m_maxStringSize.size(); if( idxColumn == columns.size() - 1 ) { - columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", - columns[idxColumn].m_maxStringSize, - newStringSize + m_tableLayout.getColumnMargin() ); - } - else - { - columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", - columns[idxColumn].m_maxStringSize, - newStringSize ); + newMaxStringSize += m_tableLayout.getColumnMargin(); } + + columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", + columns[idxColumn].m_maxStringSize, + newMaxStringSize ); } } @@ -312,16 +307,6 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & } } -std::string repeatString( std::string_view str, int count ) -{ - std::string result; - for( int i = 0; i < count; ++i ) - { - result += str; - } - return result; -} - void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column > const & columns, string & topSeparator, @@ -334,24 +319,24 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column std::vector< string > maxStringPerColumn; for( auto const & column : columns ) { - maxStringPerColumn.push_back( repeatString( verticalLine, column.m_maxStringSize.length()) ); + maxStringPerColumn.push_back( string( column.m_maxStringSize.length(), m_horizontalLine ) ); } - // Append the first column separator string - sectionSeparatingLine += maxStringPerColumn[0]; - string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", verticalLine, columnMargin ); - sectionSeparatingLine = stringutilities::join( maxStringPerColumn, patternBetweenColumns ); + string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", m_horizontalLine, columnMargin ); + + std::string const leftBorder = GEOS_FMT( "{}{:-<{}}", m_horizontalLine, "", borderMargin ); + std::string const rightBorder = GEOS_FMT( "{}{:-<{}}", m_horizontalLine, "", borderMargin ); + std::string const columnJoin = stringutilities::join( maxStringPerColumn, patternBetweenColumns ); - //Append the left border to sectionSeparatingLine - sectionSeparatingLine += GEOS_FMT( "{}{:-<{}}", verticalLine, "", borderMargin ); - //Append the right border to sectionSeparatingLine - sectionSeparatingLine += GEOS_FMT( "{:-<{}}{}", "", borderMargin, verticalLine ); + std::ostringstream oss; + oss << leftBorder << columnJoin << rightBorder; + sectionSeparatingLine = oss.str(); } { // top line separator // -2 because we can have '+' to the extremity of top separator integer const topSeparatorLength = sectionSeparatingLine.size() - 2; - topSeparator = GEOS_FMT( "{}{:-<{}}{}", verticalLine, "", topSeparatorLength, verticalLine ); + topSeparator = GEOS_FMT( "{}{:-<{}}{}", m_horizontalLine, "", topSeparatorLength, m_horizontalLine ); } } @@ -365,7 +350,7 @@ void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, tableOutput << GEOS_FMT( "{}\n", topSeparator ); for( std::string const & str : msg ) { - tableOutput << horizontalLine << string( m_tableLayout.getBorderMargin(), ' ' ); + tableOutput << m_verticalLine << string( m_tableLayout.getBorderMargin(), ' ' ); tableOutput << buildCell( alignment, str, (topSeparator.length() - 6)); tableOutput << string( m_tableLayout.getBorderMargin(), ' ' ) << "|\n"; } @@ -384,7 +369,7 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c for( integer idxRow = 0; idxRow< nbRows; ++idxRow ) { // Append the left border - tableOutput << GEOS_FMT( "{:<{}}", horizontalLine, 1 + borderMargin ); + tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, 1 + borderMargin ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { TableLayout::Column const currentColumn = columns[idxColumn]; @@ -399,13 +384,13 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c // Add space between column if( idxColumn < columns.size() - 1 ) { - tableOutput << GEOS_FMT( "{:^{}}", horizontalLine, columnMargin ); + tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } } // Append right border with line return - tableOutput << GEOS_FMT( "{:>{}}\n", horizontalLine, borderMargin + 1 ); + tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, borderMargin + 1 ); } if( nbRows != 0 ) diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index a1843894c3b..06af4dfdae3 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -121,13 +121,13 @@ class TableTextFormatter : public TableFormatter private: /// symbol for the extremity of a delemitor - static constexpr string_view sideCross = "+"; + static constexpr char m_sideCross = '+'; /// symbol to delimit a table column - static constexpr string_view innerCross = "+"; + static constexpr char m_innerCross = '+'; /// symbol for separator construction - static constexpr string_view verticalLine = "-"; + static constexpr char m_verticalLine = '|'; /// for the extremity of a row - static constexpr string_view horizontalLine = "|"; + static constexpr char m_horizontalLine = '-'; /**F * @brief Fill the vector (m_column) in tableData with values from rows stored in tableData. From 138541b8e3c5cf34ce6d345e08028a8c5f5c9bbe Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 3 Jun 2024 15:49:05 +0200 Subject: [PATCH 117/216] remove addErrorMsg function --- src/coreComponents/fileIO/Table/TableData.cpp | 7 +------ src/coreComponents/fileIO/Table/TableData.hpp | 5 ----- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index aa56b2f8afc..2dbf7dfbe18 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -28,7 +28,7 @@ void TableData::addRow( std::vector< string > const & row ) string msg = "Remarks : some cells may be missing"; if( std::find( m_errorsMsg.begin(), m_errorsMsg.end(), msg ) == m_errorsMsg.end()) { - addErrorMsg( msg ); + m_errorsMsg.push_back( msg ); } } m_rows.push_back( row ); @@ -50,11 +50,6 @@ std::vector< string > const & TableData::getErrorMsgs() const return m_errorsMsg; } -void TableData::addErrorMsg( string const & msg ) -{ - m_errorsMsg.push_back( msg ); -} - TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, string_view rowFmt, string_view columnFmt ) const diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index e7dbbb12075..a3cf6a16d5c 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -62,11 +62,6 @@ class TableData std::vector< string > const & getErrorMsgs() const; private: - /** - * @brief Set an error message - * @param msg The error msg to vector - */ - void addErrorMsg( string const & msg ); /// vector containing all rows with cell values std::vector< std::vector< string > > m_rows; From 3f74746bb5effd6a9874f99d4bf2a2fde405b887 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 3 Jun 2024 15:57:13 +0200 Subject: [PATCH 118/216] merge --- .github/workflows/build_and_test.yml | 84 +++++++++++++++---- .github/workflows/ci_tests.yml | 2 +- .integrated_tests.yaml | 3 +- BASELINE_NOTES.md | 8 ++ .../Sneddon_embeddedFrac_base.xml | 3 +- ...kgdToughnessDominated_poroelastic_base.xml | 2 +- ...kgdViscosityDominated_poroelastic_base.xml | 2 +- ...pedToughnessDominated_poroelastic_base.xml | 2 +- ...pedViscosityDominated_poroelastic_base.xml | 2 +- ...pknViscosityDominated_poroelastic_base.xml | 2 +- .../SeismicityRate_poromechanics_1d_smoke.xml | 2 +- .../PoroDelftEggWellbore_base.xml | 2 +- .../PoroDruckerPragerWellbore_base.xml | 2 +- .../PoroElasticWellbore_base.xml | 2 +- .../poromechanics/PoroElastic_Mandel_base.xml | 2 +- .../PoroElastic_Mandel_prism6_base_hybrid.xml | 2 +- .../PoroElastic_Terzaghi_base_direct.xml | 2 +- .../PoroElastic_Terzaghi_base_iterative.xml | 2 +- .../PoroElastic_deadoil_3ph_baker_2d_base.xml | 2 +- .../poromechanics/PoroElastic_gravity.xml | 2 +- .../PoroElastic_hybridHexPrism_co2_base.xml | 2 +- .../PoroElastic_staircase_co2_3d_base.xml | 4 +- ...oElastic_staircase_singlephase_3d_base.xml | 4 +- .../PoroModifiedCamClayWellbore_base.xml | 2 +- .../PoroViscoDruckerPrager_base.xml | 2 +- .../PoroViscoExtendedDruckerPrager_base.xml | 2 +- .../PoroViscoModifiedCamClay_base.xml | 2 +- .../poromechanics/faultPoroelastic_base.xml | 2 +- .../smallEggModel/smallEggModel.xml | 2 +- .../validationCase/validationCase.xml | 4 +- ...ayPermeability_conformingFracture_base.xml | 2 +- ...ExponentialDecayPermeability_edfm_base.xml | 2 +- ...c_conformingFracture_2d_faultSlip_base.xml | 2 +- ...conformingFracture_2d_openingFrac_base.xml | 2 +- .../PoroElastic_efem-edfm_base.xml | 2 +- .../PoroElastic_efem-edfm_eggModel_large.xml | 2 +- .../PoroElastic_efem-edfm_eggModel_small.xml | 2 +- .../PoroElastic_efem-edfm_pennyCrack_base.xml | 2 +- ...lastic_efem-edfm_pressurizedFrac_smoke.xml | 2 +- .../SlipPermeability_embeddedFrac.xml | 2 +- .../SlipPermeability_pEDFM_base.xml | 2 +- ...lisRichardsPermeability_efem-edfm_base.xml | 2 +- .../ThermoPoroElastic_consolidation_base.xml | 2 +- .../ThermoPoroElastic_staircase_co2_smoke.xml | 4 +- .../ThermoPoroElastic_base.xml | 2 +- ...moPoroElastic_efem-edfm_eggModel_small.xml | 2 +- ...asticWellbore_ImperfectInterfaces_base.xml | 6 +- .../CasedThermoElasticWellbore_base.xml | 6 +- ...iatedPoroElasticWellbore_Drilling_base.xml | 2 +- ...atedPoroElasticWellbore_Injection_base.xml | 2 +- .../ThermoPoroElasticWellbore_base.xml | 2 +- scripts/ci_build_and_test_in_container.sh | 8 +- src/CMakeLists.txt | 4 +- .../constitutive/solid/CoupledSolidBase.hpp | 2 +- .../constitutive/solid/PorousSolid.cpp | 6 ++ .../constitutive/solid/PorousSolid.hpp | 7 +- .../solid/porosity/BiotPorosity.cpp | 16 +++- .../solid/porosity/BiotPorosity.hpp | 33 +++++--- .../solid/porosity/PorosityFields.hpp | 10 ++- .../schema/docs/BiotPorosity.rst | 2 +- .../schema/docs/BiotPorosity_other.rst | 1 + src/coreComponents/schema/schema.xsd | 4 +- src/coreComponents/schema/schema.xsd.other | 2 + .../Contributing/IntegratedTests.rst | 18 ++-- 64 files changed, 211 insertions(+), 110 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 4b57484ceac..4824e37d2a7 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -54,9 +54,6 @@ on: RUNS_ON: required: true type: string - UPLOAD_BASELINES: - required: false - type: string USE_SCCACHE: required: false type: boolean @@ -64,6 +61,9 @@ on: REQUIRED_LABEL: required: false type: string + LOCAL_BASELINE_DIR: + required: false + type: string secrets: GOOGLE_CLOUD_GCP: required: false @@ -142,7 +142,7 @@ jobs: SHORT_COMMIT=${COMMIT:0:7} script_args+=(--install-dir-basename GEOSX-${SHORT_COMMIT}) - # All the data exchanged with the docker container is eventually meant to be send to the cloud. + # All the data exchanged with the docker container is eventually meant to be sent to the cloud. if [[ ! -z "${{ inputs.GCP_BUCKET }}" ]]; then if [ "${{ inputs.BUILD_TYPE }}" = "build" ]; then DATA_BASENAME=GEOSX-and-TPL-${SHORT_COMMIT}.tar.gz @@ -205,6 +205,45 @@ jobs: script_args+=(--code-coverage) fi + if [[ -n "${{ inputs.LOCAL_BASELINE_DIR }}" ]]; then + # Extract the 'baseline' value + + # Define the path to the YAML file + YAML_FILE_PATH="${GITHUB_WORKSPACE}/.integrated_tests.yaml" + + # Verify the YAML file path + if [[ ! -f "${YAML_FILE_PATH}" ]]; then + echo "Error: File $YAML_FILE_PATH does not exist." + else + echo "Found integratedTests file: $YAML_FILE_PATH." + fi + + # Extract the baseline field + BASELINE_FULL_PATH=$(grep -A 2 'baselines:' "${YAML_FILE_PATH}" | grep 'baseline:' | awk '{print $2}') + + # Remove the 'integratedTests/' prefix + BASELINE_TAG=${BASELINE_FULL_PATH#integratedTests/} + echo "Baseline: ${BASELINE_TAG}" + + # Extract the folder name + PR_NUMBER=$(echo "$BASELINE_TAG" | grep -o 'pr[0-9]*') + PR_BASELINE_FOLDER_NAME=baselines_${PR_NUMBER} + echo "Baseline folder name: ${PR_BASELINE_FOLDER_NAME}" + + CURRENT_BASELINE_DIR=${{ inputs.LOCAL_BASELINE_DIR }}/${PR_BASELINE_FOLDER_NAME} + echo "Current baseline dir: ${CURRENT_BASELINE_DIR}" + + if [ -d ${CURRENT_BASELINE_DIR} ];then + echo "Current baseline dir found." + ls -l ${CURRENT_BASELINE_DIR} + + # We defined a mount point and mount it read-only inside the container. + CURRENT_BASELINE_DIR_MOUNT=/tmp/geos/baselines + docker_args+=(--volume=${CURRENT_BASELINE_DIR}:${CURRENT_BASELINE_DIR_MOUNT}:ro) + else + echo "Current baselines directory (${CURRENT_BASELINE_DIR}) not found" + fi + fi echo running "docker run \ ${docker_args[@]} \ @@ -241,22 +280,33 @@ jobs: echo "Download integrated test logs here: https://storage.googleapis.com/${{ inputs.GCP_BUCKET }}/test_logs_${DATA_BASENAME}" fi - # if $UPLOAD_BASELINES; then - if [ -f ${DATA_EXCHANGE_DIR}/baseline_${DATA_BASENAME} ];then - CLOUDSDK_PYTHON=python3 gsutil cp -a public-read ${DATA_EXCHANGE_DIR}/baseline_${DATA_BASENAME} gs://${{ inputs.GCP_BUCKET }}/ - echo "Download test baselines here: https://storage.googleapis.com/${{ inputs.GCP_BUCKET }}/baseline_${DATA_BASENAME}" - echo "New baseline ID: baseline_${DATA_BASENAME::-7}" - else - echo "Baselines ${DATA_EXCHANGE_DIR}/baseline_${DATA_BASENAME} were not uploaded. Likeyly because no rebaseline was necessary." + if [ -f ${DATA_EXCHANGE_DIR}/baseline_${DATA_BASENAME} ];then + + if [[ -n "${{ inputs.LOCAL_BASELINE_DIR }}" ]]; then + # 1. We copy the baselines to a local directory to store them + + # 1.a Create the new target directory to store the new baselines + THIS_PR_NUMBER=pr${{ github.event.number }} + NEW_PR_BASELINE_FOLDER_NAME=baselines_${THIS_PR_NUMBER} + TARGET_DIR="${{ inputs.LOCAL_BASELINE_DIR }}/${NEW_PR_BASELINE_FOLDER_NAME}" + echo "Create folder ${TARGET_DIR}" + mkdir -p "${TARGET_DIR}" + + # 1.b We copy the new baselines to the new target directory + SOURCE_FILE="${DATA_EXCHANGE_DIR}/baseline_${DATA_BASENAME}" + echo "Copy ${SOURCE_FILE} to ${TARGET_DIR}" + cp "${SOURCE_FILE}" "${TARGET_DIR}" fi - # fi + + # 2. We push the baselines to the cloud + CLOUDSDK_PYTHON=python3 gsutil cp -a public-read ${DATA_EXCHANGE_DIR}/baseline_${DATA_BASENAME} gs://${{ inputs.GCP_BUCKET }}/ + echo "Download test baselines here: https://storage.googleapis.com/${{ inputs.GCP_BUCKET }}/baseline_${DATA_BASENAME}" + echo "New baseline ID: baseline_${DATA_BASENAME::-7}" + else + echo "Baselines ${DATA_EXCHANGE_DIR}/baseline_${DATA_BASENAME} were not uploaded. Likeyly because no rebaseline was necessary." + fi fi fi - - # manually remove the workspace to avoid issues with the next job when using self-hosted runners - if [ -d "${GITHUB_WORKSPACE}/integratedTests" ]; then - rm -rf ${GITHUB_WORKSPACE}/integratedTests - fi exit ${EXIT_STATUS} diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 386bb1ac00c..197dcf0f078 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -205,7 +205,7 @@ jobs: DOCKER_CERTS_DIR: "/usr/local/share/ca-certificates" DOCKER_CERTS_UPDATE_COMMAND: "update-ca-certificates" REQUIRED_LABEL: "ci: run integrated tests" - UPLOAD_BASELINES: "ci: upload test baselines" + LOCAL_BASELINE_DIR: /data/GEOS/baselines baseline_log: needs: [is_not_draft_pull_request] diff --git a/.integrated_tests.yaml b/.integrated_tests.yaml index a84e426153e..5c56e1c922f 100644 --- a/.integrated_tests.yaml +++ b/.integrated_tests.yaml @@ -1,7 +1,6 @@ ---- baselines: bucket: geosx - baseline: integratedTests/baseline_integratedTests-pr3125-5101-7764ffb + baseline: integratedTests/baseline_integratedTests-pr3050-5325-9f50d94 allow_fail: all: '' diff --git a/BASELINE_NOTES.md b/BASELINE_NOTES.md index ba258828e45..7c366a17b31 100644 --- a/BASELINE_NOTES.md +++ b/BASELINE_NOTES.md @@ -6,6 +6,14 @@ 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 #3050 (2024-05-20) +===================== +Spatially varying grain bulk modulus. Rebaseline of all poromechanics cases needed. + +PR #3141 (2024-05-28) +===================== +Test cashing baselines locally. + PR #3125 (2024-05-16) ===================== Remove field to store pressure gradient cell-wise for solvers that don't need it. diff --git a/inputFiles/efemFractureMechanics/Sneddon_embeddedFrac_base.xml b/inputFiles/efemFractureMechanics/Sneddon_embeddedFrac_base.xml index 354cc55e5b4..5ff5c97f6fc 100644 --- a/inputFiles/efemFractureMechanics/Sneddon_embeddedFrac_base.xml +++ b/inputFiles/efemFractureMechanics/Sneddon_embeddedFrac_base.xml @@ -105,7 +105,8 @@ + format="binary" + plotFileRoot="sneddon_embFrac"/> diff --git a/inputFiles/poromechanics/PoroElastic_gravity.xml b/inputFiles/poromechanics/PoroElastic_gravity.xml index 54aacf9ee1f..ce1a82c80c6 100644 --- a/inputFiles/poromechanics/PoroElastic_gravity.xml +++ b/inputFiles/poromechanics/PoroElastic_gravity.xml @@ -110,7 +110,7 @@ diff --git a/inputFiles/poromechanics/PoroElastic_staircase_co2_3d_base.xml b/inputFiles/poromechanics/PoroElastic_staircase_co2_3d_base.xml index 14f540a6a30..c2aea226cf6 100755 --- a/inputFiles/poromechanics/PoroElastic_staircase_co2_3d_base.xml +++ b/inputFiles/poromechanics/PoroElastic_staircase_co2_3d_base.xml @@ -113,7 +113,7 @@ permeabilityComponents="{ 9.8e-13, 9.8e-13, 9.8e-13 }"/> diff --git a/inputFiles/poromechanics/PoroElastic_staircase_singlephase_3d_base.xml b/inputFiles/poromechanics/PoroElastic_staircase_singlephase_3d_base.xml index bea4a79c816..3b25c03e021 100755 --- a/inputFiles/poromechanics/PoroElastic_staircase_singlephase_3d_base.xml +++ b/inputFiles/poromechanics/PoroElastic_staircase_singlephase_3d_base.xml @@ -110,7 +110,7 @@ permeabilityComponents="{ 9.8e-13, 9.8e-13, 9.8e-13 }"/> diff --git a/inputFiles/poromechanics/PoroModifiedCamClayWellbore_base.xml b/inputFiles/poromechanics/PoroModifiedCamClayWellbore_base.xml index 9f005e4fc44..39e5a33f29a 100644 --- a/inputFiles/poromechanics/PoroModifiedCamClayWellbore_base.xml +++ b/inputFiles/poromechanics/PoroModifiedCamClayWellbore_base.xml @@ -40,7 +40,7 @@ /> diff --git a/inputFiles/poromechanics/nonlinearAcceleration/smallEggModel/smallEggModel.xml b/inputFiles/poromechanics/nonlinearAcceleration/smallEggModel/smallEggModel.xml index a8259a6e66d..caf219bb716 100755 --- a/inputFiles/poromechanics/nonlinearAcceleration/smallEggModel/smallEggModel.xml +++ b/inputFiles/poromechanics/nonlinearAcceleration/smallEggModel/smallEggModel.xml @@ -202,7 +202,7 @@ diff --git a/inputFiles/poromechanics/nonlinearAcceleration/validationCase/validationCase.xml b/inputFiles/poromechanics/nonlinearAcceleration/validationCase/validationCase.xml index e307a69edcf..9b460dbba01 100755 --- a/inputFiles/poromechanics/nonlinearAcceleration/validationCase/validationCase.xml +++ b/inputFiles/poromechanics/nonlinearAcceleration/validationCase/validationCase.xml @@ -241,7 +241,7 @@ permeabilityComponents="{ 9.869233e-14, 9.869233e-14, 9.869233e-15 }"/> diff --git a/inputFiles/poromechanicsFractures/ExponentialDecayPermeability_conformingFracture_base.xml b/inputFiles/poromechanicsFractures/ExponentialDecayPermeability_conformingFracture_base.xml index 9f47a0127e8..0a1704fd9c5 100644 --- a/inputFiles/poromechanicsFractures/ExponentialDecayPermeability_conformingFracture_base.xml +++ b/inputFiles/poromechanicsFractures/ExponentialDecayPermeability_conformingFracture_base.xml @@ -120,7 +120,7 @@ diff --git a/inputFiles/thermoPoromechanics/ThermoPoroElastic_staircase_co2_smoke.xml b/inputFiles/thermoPoromechanics/ThermoPoroElastic_staircase_co2_smoke.xml index 4a570a3d38f..c292cd722a6 100644 --- a/inputFiles/thermoPoromechanics/ThermoPoroElastic_staircase_co2_smoke.xml +++ b/inputFiles/thermoPoromechanics/ThermoPoroElastic_staircase_co2_smoke.xml @@ -161,7 +161,7 @@ permeabilityComponents="{ 9.8e-13, 9.8e-13, 9.8e-13 }"/> @@ -182,7 +182,7 @@ permeabilityComponents="{ 9.8e-16, 9.8e-16, 9.8e-16 }"/> diff --git a/inputFiles/thermoPoromechanicsFractures/ThermoPoroElastic_base.xml b/inputFiles/thermoPoromechanicsFractures/ThermoPoroElastic_base.xml index dd727469509..c44c9d3baec 100644 --- a/inputFiles/thermoPoromechanicsFractures/ThermoPoroElastic_base.xml +++ b/inputFiles/thermoPoromechanicsFractures/ThermoPoroElastic_base.xml @@ -43,7 +43,7 @@ + defaultGrainBulkModulus="159.4202899e9"/> + defaultGrainBulkModulus="2.298850575e9"/> + defaultGrainBulkModulus="5.535714286e9"/> diff --git a/inputFiles/wellbore/CasedThermoElasticWellbore_base.xml b/inputFiles/wellbore/CasedThermoElasticWellbore_base.xml index 133d834fdd3..4486857c364 100644 --- a/inputFiles/wellbore/CasedThermoElasticWellbore_base.xml +++ b/inputFiles/wellbore/CasedThermoElasticWellbore_base.xml @@ -94,17 +94,17 @@ + defaultGrainBulkModulus="159.4202899e9"/> + defaultGrainBulkModulus="2.298850575e9"/> + defaultGrainBulkModulus="5.535714286e9"/> diff --git a/inputFiles/wellbore/DeviatedPoroElasticWellbore_Drilling_base.xml b/inputFiles/wellbore/DeviatedPoroElasticWellbore_Drilling_base.xml index 5d6697daa66..787e7e42b5b 100644 --- a/inputFiles/wellbore/DeviatedPoroElasticWellbore_Drilling_base.xml +++ b/inputFiles/wellbore/DeviatedPoroElasticWellbore_Drilling_base.xml @@ -75,7 +75,7 @@ diff --git a/scripts/ci_build_and_test_in_container.sh b/scripts/ci_build_and_test_in_container.sh index 867475b8c84..347ea362660 100755 --- a/scripts/ci_build_and_test_in_container.sh +++ b/scripts/ci_build_and_test_in_container.sh @@ -282,11 +282,11 @@ if [[ "${RUN_INTEGRATED_TESTS}" = true ]]; then # The tests are not run using ninja (`ninja --verbose ats_run`) because it swallows the output while all the simulations are running. # We directly use the script instead... - # echo "Available baselines:" - # ls -lah ${DATA_EXCHANGE_DIR} | grep baseline + echo "Available baselines:" + ls -lR /tmp/geos/baselines echo "Running integrated tests..." - integratedTests/geos_ats.sh --baselineCacheDirectory ${DATA_EXCHANGE_DIR} + integratedTests/geos_ats.sh --baselineCacheDirectory /tmp/geos/baselines tar -czf ${DATA_EXCHANGE_DIR}/test_logs_${DATA_BASENAME_WE}.tar.gz integratedTests/TestResults echo "Checking results..." @@ -304,7 +304,7 @@ if [[ "${RUN_INTEGRATED_TESTS}" = true ]]; then integratedTests/geos_ats.sh -a rebaselinefailed echo "Packing baselines..." - integratedTests/geos_ats.sh -a pack_baselines --baselineArchiveName ${DATA_EXCHANGE_DIR}/baseline_${DATA_BASENAME_WE}.tar.gz --baselineCacheDirectory ${DATA_EXCHANGE_DIR} + integratedTests/geos_ats.sh -a pack_baselines --baselineArchiveName ${DATA_EXCHANGE_DIR}/baseline_${DATA_BASENAME_WE}.tar.gz --baselineCacheDirectory /tmp/geos/baselines INTEGRATED_TEST_EXIT_STATUS=1 fi diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 61c5fc427e2..91fa8bd7f86 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -232,8 +232,8 @@ install( FILES ${CMAKE_BINARY_DIR}/schema.xsd ################################ # Add python environment setup ################################ -# message(WARNING "Temporarily changing the geosPythonBranch to feature/sherman/baselineStorage") -# set(GEOS_PYTHON_PACKAGES_BRANCH "branch name" CACHE STRING "" FORCE) +# message(WARNING "Temporarily changing the geosPythonBranch to cusini/fix-streak-cert-fail") +# set(GEOS_PYTHON_PACKAGES_BRANCH "cusini/fix-streak-cert-fail" CACHE STRING "" FORCE) if ( Python3_EXECUTABLE ) diff --git a/src/coreComponents/constitutive/solid/CoupledSolidBase.hpp b/src/coreComponents/constitutive/solid/CoupledSolidBase.hpp index 35306907a4e..cea3367d3e6 100644 --- a/src/coreComponents/constitutive/solid/CoupledSolidBase.hpp +++ b/src/coreComponents/constitutive/solid/CoupledSolidBase.hpp @@ -202,7 +202,7 @@ class CoupledSolidBase : public ConstitutiveBase /** * @brief initialize the constitutive models fields. */ - void initializeState() const + virtual void initializeState() const { getBasePorosityModel().initializeState(); getBasePermModel().initializeState(); diff --git a/src/coreComponents/constitutive/solid/PorousSolid.cpp b/src/coreComponents/constitutive/solid/PorousSolid.cpp index ed9cadb7bca..f427e523873 100644 --- a/src/coreComponents/constitutive/solid/PorousSolid.cpp +++ b/src/coreComponents/constitutive/solid/PorousSolid.cpp @@ -46,6 +46,12 @@ PorousSolid< SOLID_TYPE >::PorousSolid( string const & name, Group * const paren template< typename SOLID_TYPE > PorousSolid< SOLID_TYPE >::~PorousSolid() = default; +template< typename SOLID_TYPE > +void PorousSolid< SOLID_TYPE >::initializeState() const +{ + CoupledSolid< SOLID_TYPE, BiotPorosity, ConstantPermeability >::initializeState(); +} + // Register all PorousSolid model types. typedef PorousSolid< ElasticIsotropic > PorousElasticIsotropic; typedef PorousSolid< ElasticTransverseIsotropic > PorousElasticTransverseIsotropic; diff --git a/src/coreComponents/constitutive/solid/PorousSolid.hpp b/src/coreComponents/constitutive/solid/PorousSolid.hpp index 078ca36ce7d..154f047692c 100644 --- a/src/coreComponents/constitutive/solid/PorousSolid.hpp +++ b/src/coreComponents/constitutive/solid/PorousSolid.hpp @@ -127,7 +127,7 @@ class PorousSolidUpdates : public CoupledSolidUpdates< SOLID_TYPE, BiotPorosity, } // Save the derivative of solid density wrt pressure for the computation of the body force - dSolidDensity_dPressure = m_porosityUpdate.dGrainDensity_dPressure(); + dSolidDensity_dPressure = m_porosityUpdate.dGrainDensity_dPressure( k ); } GEOS_HOST_DEVICE @@ -367,6 +367,11 @@ class PorousSolid : public CoupledSolid< SOLID_TYPE, BiotPorosity, ConstantPerme getPermModel() ); } + /** + * @brief initialize the constitutive models fields. + */ + virtual void initializeState() const override final; + /** * @brief Const/non-mutable accessor for density * @return Accessor diff --git a/src/coreComponents/constitutive/solid/porosity/BiotPorosity.cpp b/src/coreComponents/constitutive/solid/porosity/BiotPorosity.cpp index 861bfed8fe5..ec781ad0d8f 100644 --- a/src/coreComponents/constitutive/solid/porosity/BiotPorosity.cpp +++ b/src/coreComponents/constitutive/solid/porosity/BiotPorosity.cpp @@ -18,6 +18,7 @@ #include "BiotPorosity.hpp" #include "PorosityFields.hpp" +#include "constitutive/solid/SolidBase.hpp" namespace geos { @@ -31,8 +32,9 @@ namespace constitutive BiotPorosity::BiotPorosity( string const & name, Group * const parent ): PorosityBase( name, parent ) { - registerWrapper( viewKeyStruct::grainBulkModulusString(), &m_grainBulkModulus ). + registerWrapper( viewKeyStruct::defaultGrainBulkModulusString(), &m_defaultGrainBulkModulus ). setInputFlag( InputFlags::REQUIRED ). + setApplyDefaultValue( -1.0 ). setDescription( "Grain bulk modulus" ); registerWrapper( viewKeyStruct::defaultThermalExpansionCoefficientString(), &m_defaultThermalExpansionCoefficient ). @@ -46,8 +48,12 @@ BiotPorosity::BiotPorosity( string const & name, Group * const parent ): setDescription( "Flag enabling uniaxial approximation in fixed stress update" ); registerField( fields::porosity::biotCoefficient{}, &m_biotCoefficient ). - setApplyDefaultValue( 1.0 ); // this is useful for sequential simulations, for the first flow solve - // ultimately, we want to be able to load the biotCoefficient from input directly, and this won't be necessary anymore + setApplyDefaultValue( 1.0 ). + setDescription( "Biot coefficient" ); + + registerField( fields::porosity::grainBulkModulus{}, &m_grainBulkModulus ). + setApplyDefaultValue( -1.0 ). + setDescription( "Grain Bulk modulus." ); registerField( fields::porosity::thermalExpansionCoefficient{}, &m_thermalExpansionCoefficient ); @@ -78,6 +84,10 @@ void BiotPorosity::postProcessInput() getWrapper< array1d< real64 > >( fields::porosity::thermalExpansionCoefficient::key() ). setApplyDefaultValue( m_defaultThermalExpansionCoefficient ); + + // set results as array default values + getWrapper< array1d< real64 > >( fields::porosity::grainBulkModulus::key() ). + setApplyDefaultValue( m_defaultGrainBulkModulus ); } void BiotPorosity::initializeState() const diff --git a/src/coreComponents/constitutive/solid/porosity/BiotPorosity.hpp b/src/coreComponents/constitutive/solid/porosity/BiotPorosity.hpp index 4d64b0d9416..a6ae9e38815 100644 --- a/src/coreComponents/constitutive/solid/porosity/BiotPorosity.hpp +++ b/src/coreComponents/constitutive/solid/porosity/BiotPorosity.hpp @@ -56,7 +56,7 @@ class BiotPorosityUpdates : public PorosityBaseUpdates arrayView1d< real64 > const & averageMeanTotalStressIncrement_k, arrayView1d< real64 > const & bulkModulus, arrayView1d< real64 > const & shearModulus, - real64 const & grainBulkModulus, + arrayView1d< real64 > const & grainBulkModulus, integer const useUniaxialFixedStress ): PorosityBaseUpdates( newPorosity, porosity_n, dPorosity_dPressure, @@ -77,10 +77,10 @@ class BiotPorosityUpdates : public PorosityBaseUpdates real64 getBiotCoefficient( localIndex const k ) const { return m_biotCoefficient[k]; } GEOS_HOST_DEVICE - real64 getGrainBulkModulus() const { return m_grainBulkModulus; } + real64 getGrainBulkModulus( localIndex const k ) const { return m_grainBulkModulus[k]; } GEOS_HOST_DEVICE - real64 dGrainDensity_dPressure() const { return 1.0 / m_grainBulkModulus; } + real64 dGrainDensity_dPressure( localIndex const k ) const { return 1.0 / m_grainBulkModulus[k]; } GEOS_HOST_DEVICE void updateFromPressureTemperatureAndStrain( localIndex const k, @@ -92,7 +92,7 @@ class BiotPorosityUpdates : public PorosityBaseUpdates real64 & dPorosity_dPressure, real64 & dPorosity_dTemperature ) const { - real64 const biotSkeletonModulusInverse = (m_biotCoefficient[k] - m_referencePorosity[k]) / m_grainBulkModulus; + real64 const biotSkeletonModulusInverse = (m_biotCoefficient[k] - m_referencePorosity[k]) / m_grainBulkModulus[k]; real64 const porosityThermalExpansion = 3 * m_thermalExpansionCoefficient[k] * ( m_biotCoefficient[k] - m_referencePorosity[k] ); real64 const porosity = m_porosity_n[k][q] @@ -123,9 +123,10 @@ class BiotPorosityUpdates : public PorosityBaseUpdates real64 const & thermalExpansionCoefficient, real64 const & averageMeanTotalStressIncrement_k, real64 const & bulkModulus, - real64 const & fixedStressModulus ) const + real64 const & fixedStressModulus, + real64 const & grainBulkModulus ) const { - real64 const biotSkeletonModulusInverse = (biotCoefficient - referencePorosity) / m_grainBulkModulus; + real64 const biotSkeletonModulusInverse = (biotCoefficient - referencePorosity) / grainBulkModulus; real64 const porosityThermalExpansion = 3 * thermalExpansionCoefficient * ( biotCoefficient - referencePorosity ); real64 const pressureCoefficient = biotCoefficient * biotCoefficient / bulkModulus; real64 const temperatureCoefficient = 3 * biotCoefficient * thermalExpansionCoefficient; @@ -175,7 +176,8 @@ class BiotPorosityUpdates : public PorosityBaseUpdates m_thermalExpansionCoefficient[k], m_averageMeanTotalStressIncrement_k[k], m_bulkModulus[k], - fixedStressModulus ); + fixedStressModulus, + m_grainBulkModulus[k] ); } GEOS_HOST_DEVICE @@ -184,7 +186,8 @@ class BiotPorosityUpdates : public PorosityBaseUpdates { m_bulkModulus[k] = bulkModulus; m_shearModulus[k] = shearModulus; - m_biotCoefficient[k] = 1 - bulkModulus / m_grainBulkModulus; + + m_biotCoefficient[k] = 1.0 - bulkModulus / m_grainBulkModulus[k]; } GEOS_HOST_DEVICE @@ -198,7 +201,7 @@ class BiotPorosityUpdates : public PorosityBaseUpdates protected: /// Grain bulk modulus (read from XML) - real64 const m_grainBulkModulus; + arrayView1d< real64 > const m_grainBulkModulus; /// View on the thermal expansion coefficients (read from XML) arrayView1d< real64 const > const m_thermalExpansionCoefficient; @@ -236,7 +239,7 @@ class BiotPorosity : public PorosityBase struct viewKeyStruct : public PorosityBase::viewKeyStruct { - static constexpr char const *grainBulkModulusString() { return "grainBulkModulus"; } + static constexpr char const *defaultGrainBulkModulusString() { return "defaultGrainBulkModulus"; } static constexpr char const *meanTotalStressIncrementString() { return "meanTotalStressIncrement"; } @@ -249,6 +252,8 @@ class BiotPorosity : public PorosityBase static constexpr char const *defaultThermalExpansionCoefficientString() { return "defaultPorosityTEC"; } static constexpr char const *useUniaxialFixedStressString() { return "useUniaxialFixedStress"; } + + static constexpr char const *defaultBiotCoefficientString() { return "defaultBiotCoefficient"; } } viewKeys; virtual void initializeState() const override final; @@ -313,6 +318,9 @@ class BiotPorosity : public PorosityBase /// Thermal expansion coefficients (read from XML) array1d< real64 > m_thermalExpansionCoefficient; + /// Default value of the Biot coefficient (read from XML) + real64 m_defaultBiotCoefficient; + /// Biot coefficients (update in the update class, not read in input) array1d< real64 > m_biotCoefficient; @@ -329,7 +337,10 @@ class BiotPorosity : public PorosityBase array1d< real64 > m_averageMeanTotalStressIncrement_k; /// Grain bulk modulus (read from XML) - real64 m_grainBulkModulus; + real64 m_defaultGrainBulkModulus; + + /// Grain bulk modulus (can be specified in XML) + array1d< real64 > m_grainBulkModulus; /// Flag enabling uniaxial approximation in fixed stress update integer m_useUniaxialFixedStress; diff --git a/src/coreComponents/constitutive/solid/porosity/PorosityFields.hpp b/src/coreComponents/constitutive/solid/porosity/PorosityFields.hpp index f36a43b440f..98d2a82e339 100644 --- a/src/coreComponents/constitutive/solid/porosity/PorosityFields.hpp +++ b/src/coreComponents/constitutive/solid/porosity/PorosityFields.hpp @@ -82,7 +82,7 @@ DECLARE_FIELD( biotCoefficient, "biotCoefficient", array1d< real64 >, 0, - NOPLOT, + LEVEL_0, WRITE_AND_READ, "Biot coefficient" ); @@ -110,6 +110,14 @@ DECLARE_FIELD( averageMeanTotalStressIncrement_k, NO_WRITE, "Mean total stress increment averaged over quadrature points at the previous sequential iteration" ); +DECLARE_FIELD( grainBulkModulus, + "grainBulkModulus", + array1d< real64 >, + 0, + LEVEL_0, + WRITE_AND_READ, + "Biot coefficient" ); + } diff --git a/src/coreComponents/schema/docs/BiotPorosity.rst b/src/coreComponents/schema/docs/BiotPorosity.rst index 1045d74ae9e..e0098540256 100644 --- a/src/coreComponents/schema/docs/BiotPorosity.rst +++ b/src/coreComponents/schema/docs/BiotPorosity.rst @@ -3,9 +3,9 @@ ======================== ========= ======== =========================================================== Name Type Default Description ======================== ========= ======== =========================================================== +defaultGrainBulkModulus real64 required Grain bulk modulus defaultPorosityTEC real64 0 Default thermal expansion coefficient defaultReferencePorosity real64 required Default value of the reference porosity -grainBulkModulus real64 required Grain bulk modulus name groupName required A name is required for any non-unique nodes useUniaxialFixedStress integer 0 Flag enabling uniaxial approximation in fixed stress update ======================== ========= ======== =========================================================== diff --git a/src/coreComponents/schema/docs/BiotPorosity_other.rst b/src/coreComponents/schema/docs/BiotPorosity_other.rst index d5bd2487301..335965a9ad6 100644 --- a/src/coreComponents/schema/docs/BiotPorosity_other.rst +++ b/src/coreComponents/schema/docs/BiotPorosity_other.rst @@ -7,6 +7,7 @@ averageMeanTotalStressIncrement_k real64_array Mean total stress increment ave biotCoefficient real64_array Biot coefficient dPorosity_dPressure real64_array2d Derivative of rock porosity with respect to pressure dPorosity_dTemperature real64_array2d Derivative of rock porosity with respect to temperature +grainBulkModulus real64_array Grain Bulk modulus. initialPorosity real64_array2d Initial porosity meanTotalStressIncrement_k real64_array2d Mean total stress increment at quadrature points at the previous sequential iteration porosity real64_array2d Rock porosity diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index 00397845810..3ee8c96a670 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -3894,12 +3894,12 @@ Local - Add stabilization only to interiors of macro elements.--> + + - - diff --git a/src/coreComponents/schema/schema.xsd.other b/src/coreComponents/schema/schema.xsd.other index a96f1c1e5d0..b337dd2d503 100644 --- a/src/coreComponents/schema/schema.xsd.other +++ b/src/coreComponents/schema/schema.xsd.other @@ -1455,6 +1455,8 @@ + + diff --git a/src/docs/sphinx/developerGuide/Contributing/IntegratedTests.rst b/src/docs/sphinx/developerGuide/Contributing/IntegratedTests.rst index 93ad45c3576..3b5c325ce13 100644 --- a/src/docs/sphinx/developerGuide/Contributing/IntegratedTests.rst +++ b/src/docs/sphinx/developerGuide/Contributing/IntegratedTests.rst @@ -510,15 +510,15 @@ This process is called rebaselining. We suggest the following workflow: -#. Step 1. Open a pull request for your branch on github and select the **ci: run integrated tests** and **ci: upload test baselines** labels -#. Step 2. Wait for the tests to finish -#. Step 3. Download and unpack the new baselines from the link provided at the bottom of the test logs -#. Step 4. Inspect the test results using the *test_results.html* file -#. Step 5. Verify that the changes in the baseline files are desired -#. Step 6. Update the baseline ID in the *GEOS/.integrated_tests.yaml* file -#. Step 7. Add a justification for the baseline changes to the *GEOS/BASELINE_NOTES.md* file -#. Step 8. Commit your changes and push the code -#. Step 9. Wait for the CI tests to re-run and verify that the integrated tests step passed +#. Open a pull request for your branch on github and select the **ci: run integrated tests** label +#. Wait for the tests to finish +#. Download and unpack the new baselines from the link provided at the bottom of the test logs +#. Inspect the test results using the *test_results.html* file +#. Verify that the changes in the baseline files are desired +#. Update the baseline ID in the *GEOS/.integrated_tests.yaml* file +#. Add a justification for the baseline changes to the *GEOS/BASELINE_NOTES.md* file +#. Commit your changes and push the code +#. Wait for the CI tests to re-run and verify that the integrated tests step passed From 1f2424711041c0961c0d889316dc10b8c956d5fa Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 3 Jun 2024 17:00:52 +0200 Subject: [PATCH 119/216] uncrustify --- .../constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp | 2 +- .../fluid/multifluid/reactive/ReactiveBrineFluid.cpp | 2 +- .../fluid/multifluid/reactive/ReactiveBrineFluid.hpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp index 9996775e9ac..8b6cd2ea969 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp @@ -169,7 +169,7 @@ class CO2BrineFluid : public MultiFluidBase private: - void createPVTModels(bool isClone); + void createPVTModels( bool isClone ); /// Names of the files defining the viscosity and density models path_array m_phasePVTParaFiles; diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp index 656a12fd9e4..504dd10820c 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp @@ -209,7 +209,7 @@ void ReactiveBrineFluid< PHASE > ::createPVTModels( bool isClone ) // then, we are ready to instantiate the phase models m_phase = std::make_unique< PHASE >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, - writeCSV, writeInLog); + writeCSV, writeInLog ); } template< typename PHASE > diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp index df64ac10c33..b9a14126a44 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp @@ -160,14 +160,14 @@ class ReactiveBrineFluid : public ReactiveMultiFluid private: - void createPVTModels(bool isClone); + void createPVTModels( bool isClone ); bool m_isClone = true; /// Names of the files defining the viscosity and density models path_array m_phasePVTParaFiles; - /// @brief + /// @brief integer m_writeCSV; /// Brine constitutive models From b1ec0d030b45c5c84edff8fd16d77300a1c0b330 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 5 Jun 2024 15:48:48 +0200 Subject: [PATCH 120/216] begin refacto in table function for more clarity --- src/coreComponents/fileIO/Table/TableData.cpp | 34 ++++ src/coreComponents/fileIO/Table/TableData.hpp | 26 +++ .../fileIO/Table/TableFormatter.cpp | 84 +-------- .../fileIO/Table/TableFormatter.hpp | 13 +- .../functions/TableFunction.cpp | 162 ++++++++---------- .../functions/TableFunction.hpp | 37 ++-- 6 files changed, 157 insertions(+), 199 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 2dbf7dfbe18..badb76435fa 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -50,6 +50,40 @@ std::vector< string > const & TableData::getErrorMsgs() const return m_errorsMsg; } +void TableData2D::collect2DData( arraySlice1d< real64 const > const rowAxis, + arraySlice1d< real64 const > const columnAxis, + arrayView1d< real64 const > values ) +{ + arraySlice1d< real64 const > const coordsX = rowAxis; + arraySlice1d< real64 const > const coordsY = columnAxis; + integer const nX = coordsX.size(); + integer const nY = coordsY.size(); + + for( integer i = 0; i < nX; i++ ) + { + for( integer y = 0; y < nY; y++ ) + { + addCell( rowAxis[i], columnAxis[y], values[ y*nX + i ] ); + } + } +} + +TableData2D::Conversion1D TableData2D::convert2DData( units::Unit valueUnit, + string_view rowUnitDescription, + string_view columnUnitDescription ) +{ + string const rowFmt = GEOS_FMT( "{} = {{}}", rowUnitDescription ); + string const columnFmt = GEOS_FMT( "{} = {{}}", columnUnitDescription ); + return buildTableData( string( units::getDescription( valueUnit )), + rowFmt, + columnFmt ); +} + +size_t TableData2D::getNbRows() const +{ + return m_data.size(); +} + TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, string_view rowFmt, string_view columnFmt ) const diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index a3cf6a16d5c..15f3673e8df 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -19,6 +19,7 @@ #ifndef GEOS_COMMON_TableData_HPP #define GEOS_COMMON_TableData_HPP +#include "common/Units.hpp" #include "common/DataTypes.hpp" #include "common/Format.hpp" @@ -102,6 +103,31 @@ class TableData2D template< typename T > void addCell( RowType rowValue, ColumnType columnValue, T const & value ); + /** + * @brief + * + * @param rowAxis + * @param columnAxis + * @param values + */ + void collect2DData( arraySlice1d< real64 const > const rowAxis, + arraySlice1d< real64 const > const columnAxis, + arrayView1d< real64 const > values ); + + /** + * @brief + * + * @param valueUnit + * @param rowUnitDescription + * @param columnUnitDescription + * @return TableData2D::Conversion1D + */ + TableData2D::Conversion1D convert2DData( units::Unit valueUnit, + string_view rowUnitDescription, + string_view columnUnitDescription ); + + size_t getNbRows() const; + /** * @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 diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index e22ae6a9f41..35699fc3927 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -144,10 +144,8 @@ string TableTextFormatter::layoutToString() const { std::ostringstream tableOutput; string sectionSeparatingLine; - string sectionSeparatingLine; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); - outputLayout( tableOutput, columns, {}, sectionSeparatingLine ); outputLayout( tableOutput, columns, {}, sectionSeparatingLine ); return tableOutput.str(); } @@ -156,7 +154,6 @@ string TableTextFormatter::toString( TableData const & tableData ) const { std::ostringstream tableOutput; string sectionSeparatingLine; - string sectionSeparatingLine; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); std::vector< string > const & msgTableError = tableData.getErrorMsgs(); @@ -165,8 +162,6 @@ string TableTextFormatter::toString( TableData const & tableData ) const formatColumnsFromLayout( columns, tableDataRows ); fillTableColumnsFromRows( columns, tableDataRows ); - outputLayout( tableOutput, columns, msgTableError, sectionSeparatingLine ); - outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbValuesRows, TableLayout::Section::values ); outputLayout( tableOutput, columns, msgTableError, sectionSeparatingLine ); outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbValuesRows, TableLayout::Section::values ); tableOutput << '\n'; @@ -178,7 +173,6 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, std::vector< string > const & msgTableError, string & sectionSeparatingLine ) const - string & sectionSeparatingLine ) const { string topSeparator; size_t nbHeaderRows = 0; @@ -188,8 +182,6 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, splitAndSetColumnNames( columns, nbHeaderRows, splitHeaders ); findAndSetMaxStringSize( columns ); - computeTableWidth( columns, msgTableError ); - buildTableSeparators( columns, topSeparator, sectionSeparatingLine ); computeTableWidth( columns, msgTableError ); buildTableSeparators( columns, topSeparator, sectionSeparatingLine ); @@ -197,10 +189,8 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, outputTopRows( tableOutput, {tableTitle}, topSeparator, TableLayout::Alignment::center ); outputTopRows( tableOutput, msgTableError, topSeparator, TableLayout::Alignment::left ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbHeaderRows, TableLayout::Section::header ); - outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbHeaderRows, TableLayout::Section::header ); } void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Column > & columns, @@ -262,26 +252,18 @@ void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > integer const extraCharactersPerColumn = std::ceil( extraCharacters / columns.size() ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { - integer newMaxMaxStringSize = extraCharactersPerColumn + columns[idxColumn].m_maxStringSize.size(); + integer newMaxStringSize = extraCharactersPerColumn + columns[idxColumn].m_maxStringSize.size(); if( idxColumn == columns.size() - 1 ) { newMaxStringSize += m_tableLayout.getColumnMargin(); - newMaxStringSize += m_tableLayout.getColumnMargin(); } columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", columns[idxColumn].m_maxStringSize, newMaxStringSize ); } - - columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", - columns[idxColumn].m_maxStringSize, - newMaxStringSize ); - } } -void computeTableErrorLength( std::vector< string > const & msgTableError, string::size_type & msgTableErrorLength ) -{ void computeTableErrorLength( std::vector< string > const & msgTableError, string::size_type & msgTableErrorLength ) { if( !msgTableError.empty() ) @@ -294,12 +276,7 @@ void computeTableErrorLength( std::vector< string > const & msgTableError, strin msgTableErrorLength += maxStringSize.size() + 1; // max string size + line return at the end } } - msgTableErrorLength += maxStringSize.size() + 1; // max string size + line return at the end - } -} -void computeTableSectionLength( std::vector< TableLayout::Column > & columns, string::size_type & sectionlineLength ) -{ void computeTableSectionLength( std::vector< TableLayout::Column > & columns, string::size_type & sectionlineLength ) { sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, @@ -307,24 +284,6 @@ void computeTableSectionLength( std::vector< TableLayout::Column > & columns, st { return sum + column.m_maxStringSize.length();} ); } -void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & columns, - std::vector< string > const & msgTableError ) const -{ - integer const columnMargin = m_tableLayout.getColumnMargin(); - integer const borderMargin = m_tableLayout.getBorderMargin(); - string const tableTitle = string( m_tableLayout.getTitle() ); - - string::size_type sectionLengthWithSpacing = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); - string::size_type sectionlineLength = sectionLengthWithSpacing; - string::size_type maxTopLineLength = tableTitle.length(); - string::size_type msgTableErrorLength = borderMargin; - - computeTableErrorLength( msgTableError, msgTableErrorLength ); - computeTableSectionLength( columns, sectionlineLength ); - - maxTopLineLength = std::max( maxTopLineLength, msgTableErrorLength ); -} - void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & columns, std::vector< string > const & msgTableError ) const { @@ -349,26 +308,14 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & } - void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column > const & columns, string & topSeparator, string & sectionSeparatingLine ) const - string & sectionSeparatingLine ) const { { // section separator line integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); - { // section separator line - integer const columnMargin = m_tableLayout.getColumnMargin(); - integer const borderMargin = m_tableLayout.getBorderMargin(); - - std::vector< string > maxStringPerColumn; - for( auto const & column : columns ) - { - maxStringPerColumn.push_back( string( column.m_maxStringSize.length(), m_horizontalLine ) ); - } - string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", m_horizontalLine, columnMargin ); std::vector< string > maxStringPerColumn; for( auto const & column : columns ) { @@ -386,20 +333,6 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column sectionSeparatingLine = oss.str(); } - { // top line separator - // -2 because we can have '+' to the extremity of top separator - integer const topSeparatorLength = sectionSeparatingLine.size() - 2; - topSeparator = GEOS_FMT( "{}{:-<{}}{}", m_horizontalLine, "", topSeparatorLength, m_horizontalLine ); - } - std::string const leftBorder = GEOS_FMT( "{}{:-<{}}", m_horizontalLine, "", borderMargin ); - std::string const rightBorder = GEOS_FMT( "{}{:-<{}}", m_horizontalLine, "", borderMargin ); - std::string const columnJoin = stringutilities::join( maxStringPerColumn, patternBetweenColumns ); - - std::ostringstream oss; - oss << leftBorder << columnJoin << rightBorder; - sectionSeparatingLine = oss.str(); - } - { // top line separator // -2 because we can have '+' to the extremity of top separator integer const topSeparatorLength = sectionSeparatingLine.size() - 2; @@ -417,7 +350,6 @@ void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, tableOutput << GEOS_FMT( "{}\n", topSeparator ); for( std::string const & str : msg ) { - tableOutput << m_verticalLine << string( m_tableLayout.getBorderMargin(), ' ' ); tableOutput << m_verticalLine << string( m_tableLayout.getBorderMargin(), ' ' ); tableOutput << buildCell( alignment, str, (topSeparator.length() - 6)); tableOutput << string( m_tableLayout.getBorderMargin(), ' ' ) << "|\n"; @@ -426,7 +358,6 @@ void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, } void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > const & columns, - string_view sectionSeparatingLine, string_view sectionSeparatingLine, std::ostringstream & tableOutput, integer const nbRows, @@ -437,8 +368,6 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c for( integer idxRow = 0; idxRow< nbRows; ++idxRow ) { - // Append the left border - tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, 1 + borderMargin ); // Append the left border tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, 1 + borderMargin ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) @@ -448,34 +377,25 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c columns[idxColumn].m_parameter.splitColumnNameLines : columns[idxColumn].m_columnValues; string cell = columnContent[idxRow]; - auto const & columnContent = section == TableLayout::Section::header ? - columns[idxColumn].m_parameter.splitColumnNameLines : - columns[idxColumn].m_columnValues; - string cell = columnContent[idxRow]; integer const cellSize = currentColumn.m_maxStringSize.length(); tableOutput << buildCell( currentColumn.m_parameter.alignment, cell, cellSize ); - // Add space between column // Add space between column if( idxColumn < columns.size() - 1 ) { tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); - tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } } // Append right border with line return tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, borderMargin + 1 ); - // Append right border with line return - tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, borderMargin + 1 ); } - if( nbRows != 0 ) { tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); } } -} +} \ No newline at end of file diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index bd65bdc2bf3..0aae19a73a0 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -139,13 +139,11 @@ class TableTextFormatter : public TableFormatter * @param columns The vector containing all table columns * @param msgTableError A vector containg all error related to the table * @param sectionSeparatingLine An empty string for building the section separator - * @param sectionSeparatingLine An empty string for building the section separator */ void outputLayout( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, std::vector< string > const & msgTableError, string & sectionSeparatingLine ) const; - string & sectionSeparatingLine ) const; /** * @brief Split all header names by detecting the newline \\n character. and @@ -173,8 +171,6 @@ class TableTextFormatter : public TableFormatter integer const extraCharacters ) const; /** - * @brief Compute the max table line length, taking into account the length of : title, error, columns header and content - * Increase the size of the columns if necessary * @brief Compute the max table line length, taking into account the length of : title, error, columns header and content * Increase the size of the columns if necessary * @param columns Vector of column containing containing the largest string for each column @@ -182,21 +178,16 @@ class TableTextFormatter : public TableFormatter */ void computeTableWidth( std::vector< TableLayout::Column > & columns, std::vector< string > const & msgTableError ) const; - void computeTableWidth( std::vector< TableLayout::Column > & columns, - std::vector< string > const & msgTableError ) const; /** - * @brief Build all separators needed from content length contained in the columns vector * @brief Build all separators needed from content length contained in the columns vector * @param columns Vector containing all table columns * @param topSeparator Top separator to be built * @param sectionSeparatingLine Line section separator to be built - * @param sectionSeparatingLine Line section separator to be built */ void buildTableSeparators( std::vector< TableLayout::Column > const & columns, string & topSeparator, string & sectionSeparatingLine ) const; - string & sectionSeparatingLine ) const; /** * @brief Add a row on top of the table @@ -214,14 +205,12 @@ class TableTextFormatter : public TableFormatter * @brief Output a section by specifying it's type ( header or section ) * @param columns Vector containing all table columns * @param sectionSeparatingLine Line separator between sections - * @param sectionSeparatingLine Line separator between sections * @param rows A section row * @param nbRows Indicates the number of lines in a section * @param section The section to be built * @note Add the ending line if there are one or more rows */ void outputSectionRows( std::vector< TableLayout::Column > const & columns, - string_view sectionSeparatingLine, string_view sectionSeparatingLine, std::ostringstream & rows, integer const nbRows, @@ -229,4 +218,4 @@ class TableTextFormatter : public TableFormatter }; } -#endif +#endif \ No newline at end of file diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 0055ee897b8..ee47fd7a0a8 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -20,9 +20,6 @@ #include "codingUtilities/Parsing.hpp" #include "common/DataTypes.hpp" #include "fileIO/Outputs/OutputBase.hpp" -#include "fileIO/Table/TableLayout.hpp" -#include "fileIO/Table/TableData.hpp" -#include "fileIO/Table/TableFormatter.hpp" #include @@ -188,6 +185,56 @@ void TableFunction::checkCoord( real64 const coord, localIndex const dim ) const SimulationError ); } +void TableFunction::printCSVHeader( std::ofstream & os, integer const numDimensions ) const +{ + for( integer d = 0; d < numDimensions; d++ ) + { + os << units::getDescription( getDimUnit( d )) << ","; + } + os << units::getDescription( m_valueUnit ) << "\n"; +} + +void TableFunction::printCSVValues( std::ofstream & os, integer const numDimensions ) const +{ + // prepare dividers + std::vector< integer > div( numDimensions ); + div[0] = 1; + for( integer d = 1; d < numDimensions; d++ ) + { + div[d] = div[d-1] * m_coordinates[d-1].size(); + } + // loop through all the values + for( integer v = 0; v < m_values.size(); v++ ) + { + // find coords indices + std::vector< integer > idx( numDimensions ); + integer r = v; + for( integer d = numDimensions-1; d >= 0; d-- ) + { + idx[d] = r / div[d]; + r = r % div[d]; + } + // finally print out in right order + + for( integer d = 0; d < numDimensions; d++ ) + { + arraySlice1d< real64 const > const coords = m_coordinates[d]; + os << coords[idx[d]] << ","; + } + os << m_values[v] << "\n"; + } +} + +void TableFunction::convertTable2D( TableData2D::Conversion1D & tableConverted ) const +{ + TableData2D tableData2D; + tableData2D.collect2DData( m_coordinates[0], m_coordinates[1], m_values ); + + tableConverted = tableData2D.convert2DData( m_valueUnit, + units::getDescription( getDimUnit( 0 ) ), + units::getDescription( getDimUnit( 1 ) )); +} + void TableFunction::printInCSV( string const & filename ) const { std::ofstream os( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); @@ -198,70 +245,19 @@ void TableFunction::printInCSV( string const & filename ) const if( numDimensions != 2 ) { - // print header - - for( integer d = 0; d < numDimensions; d++ ) - { - os << units::getDescription( getDimUnit( d )) << ","; - } - os << units::getDescription( m_valueUnit ) << "\n"; - - // print values - - // prepare dividers - std::vector< integer > div( numDimensions ); - div[0] = 1; - for( integer d = 1; d < numDimensions; d++ ) - { - div[d] = div[d-1] * m_coordinates[d-1].size(); - } - // loop through all the values - for( integer v = 0; v < m_values.size(); v++ ) - { - // find coords indices - std::vector< integer > idx( numDimensions ); - integer r = v; - for( integer d = numDimensions-1; d >= 0; d-- ) - { - idx[d] = r / div[d]; - r = r % div[d]; - } - // finally print out in right order - - for( integer d = 0; d < numDimensions; d++ ) - { - arraySlice1d< real64 const > const coords = m_coordinates[d]; - os << coords[idx[d]] << ","; - } - os << m_values[v] << "\n"; - } + printCSVHeader( os, numDimensions ); + printCSVValues( os, numDimensions ); } else // numDimensions == 2 { - arraySlice1d< real64 const > const coordsX = m_coordinates[0]; - arraySlice1d< real64 const > const coordsY = m_coordinates[1]; - integer const nX = coordsX.size(); - integer const nY = coordsY.size(); - - TableData2D tableData2D; - for( integer i = 0; i < nX; i++ ) - { - for( integer y = 0; y < nY; y++ ) - { - tableData2D.addCell( coordsX[i], coordsY[y], m_values[ y*nX + i ] ); - } - } - string const rowFmt = GEOS_FMT( "{} = {{}}", units::getDescription( getDimUnit( 0 ) ) ); - string const columnFmt = GEOS_FMT( "{} = {{}}", units::getDescription( getDimUnit( 1 ) ) ); - TableData2D::Conversion1D const tableConverted = tableData2D.buildTableData( string( units::getDescription( m_valueUnit )), - rowFmt, - columnFmt ); - - TableLayout const tableLayout( tableConverted.headerNames ); + //1. + TableData2D::Conversion1D tableConverted; + convertTable2D( tableConverted ); + //2. + TableLayout tableLayout( tableConverted.headerNames ); + //3. TableCSVFormatter csvFormat( tableLayout ); - - os << csvFormat.headerToString(); - os << csvFormat.dataToString( tableConverted.tableData ); + os << csvFormat.headerToString() << csvFormat.dataToString( tableConverted.tableData ); } os.close(); } @@ -292,45 +288,27 @@ void TableFunction::printInLog( string const & title ) const } else if( numDimensions == 2 ) { - arraySlice1d< real64 const > const coordsX = m_coordinates[0]; - arraySlice1d< real64 const > const coordsY = m_coordinates[1]; - integer const nX = coordsX.size(); - integer const nY = coordsY.size(); - std::vector< string > columnNames; - integer nbRows = 0; - - //1. collect TableData2D tableData2D; - for( integer i = 0; i < nX; i++ ) - { - for( integer j = 0; j < nY; j++ ) - { - tableData2D.addCell( coordsX[i], coordsY[j], m_values[ j*nX + i ] ); - } - nbRows++; - } - - if( nbRows <= 500 ) + integer const nX = m_coordinates[0].size(); + integer const nY = m_coordinates[1].size(); + if( nX * nY <= 500 ) { - //2. format - string const rowFmt = GEOS_FMT( "{} = {{}}", units::getDescription( getDimUnit( 0 ) ) ); - string const columnFmt = GEOS_FMT( "{} = {{}}", units::getDescription( getDimUnit( 1 ) ) ); - TableData2D::Conversion1D const tableConverted = tableData2D.buildTableData( string( units::getDescription( m_valueUnit )), - rowFmt, - columnFmt ); - TableLayout const tableLayout( tableConverted.headerNames, title ); - - //3. log + // log table2D + //1. + TableData2D::Conversion1D tableConverted; + convertTable2D( tableConverted ); + //2. + TableLayout tableLayout( tableConverted.headerNames, title ); + //3. TableTextFormatter const table2DLog( tableLayout ); GEOS_LOG_RANK_0( table2DLog.toString( tableConverted.tableData )); } else { - //2. format + // log informative string log = GEOS_FMT( "The {} PVT table exceeding 500 rows.\nTo visualize the tables, go to the generated csv \n", title ); TableLayout const tableLayoutInfos( {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}}, title ); - //3. log TableTextFormatter const tableLog( tableLayoutInfos ); GEOS_LOG_RANK_0( tableLog.layoutToString() ); } diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index 2e2de63e241..6e67fa33f55 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -23,6 +23,9 @@ #include "codingUtilities/EnumStrings.hpp" #include "LvArray/src/tensorOps.hpp" +#include "fileIO/Table/TableData.hpp" +#include "fileIO/Table/TableLayout.hpp" +#include "fileIO/Table/TableFormatter.hpp" #include "common/Units.hpp" namespace geos @@ -238,6 +241,24 @@ class TableFunction : public FunctionBase */ void checkCoord( real64 coord, localIndex dim ) const; + void printCSVHeader( std::ofstream & os, integer const numDimensions ) const; + + void printCSVValues( std::ofstream & os, integer const numDimensions ) const; + + void convertTable2D( TableData2D::Conversion1D & tableConverted ) const; + + /** + * @brief Print table into a CSV file + * @param filename Filename for output + */ + void printInCSV( string const & filename ) const; + + /** + * @brief Print table to the log (only 1d and 2d tables are supported). + * @param filename Filename for output + */ + void printInLog( string const & filename ) const; + /** * @brief @return Number of table dimensions */ @@ -276,7 +297,9 @@ class TableFunction : public FunctionBase * @return The unit of a coordinate dimension, or units::Unknown if no units has been specified. */ units::Unit getDimUnit( localIndex const dim ) const - { return size_t(dim) < m_dimUnits.size() ? m_dimUnits[dim] : units::Unknown; } + { + return size_t(dim) < m_dimUnits.size() ? m_dimUnits[dim] : units::Unknown; + } /** * @brief Set the interpolation method @@ -317,18 +340,6 @@ class TableFunction : public FunctionBase m_valueUnit = unit; } - /** - * @brief Print table into a CSV file - * @param filename Filename for output - */ - void printInCSV( string const & filename ) const; - - /** - * @brief Print table to the log (only 1d and 2d tables are supported). - * @param filename Filename for output - */ - void printInLog( string const & filename ) const; - /** * @brief Create an instance of the kernel wrapper * @return the kernel wrapper From b62161a04a5d50a9c6293e54c50e2defdb699ddc Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 5 Jun 2024 16:01:58 +0200 Subject: [PATCH 121/216] continue refato --- .../functions/TableFunction.cpp | 31 +++++++++---------- .../functions/TableFunction.hpp | 4 +-- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index ee47fd7a0a8..323d44c2a48 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -185,16 +185,16 @@ void TableFunction::checkCoord( real64 const coord, localIndex const dim ) const SimulationError ); } -void TableFunction::printCSVHeader( std::ofstream & os, integer const numDimensions ) const +void TableFunction::printCSVHeader( std::ofstream & logStream, integer const numDimensions ) const { for( integer d = 0; d < numDimensions; d++ ) { - os << units::getDescription( getDimUnit( d )) << ","; + logStream << units::getDescription( getDimUnit( d )) << ","; } - os << units::getDescription( m_valueUnit ) << "\n"; + logStream << units::getDescription( m_valueUnit ) << "\n"; } -void TableFunction::printCSVValues( std::ofstream & os, integer const numDimensions ) const +void TableFunction::printCSVValues( std::ofstream & logStream, integer const numDimensions ) const { // prepare dividers std::vector< integer > div( numDimensions ); @@ -215,13 +215,12 @@ void TableFunction::printCSVValues( std::ofstream & os, integer const numDimensi r = r % div[d]; } // finally print out in right order - for( integer d = 0; d < numDimensions; d++ ) { arraySlice1d< real64 const > const coords = m_coordinates[d]; - os << coords[idx[d]] << ","; + logStream << coords[idx[d]] << ","; } - os << m_values[v] << "\n"; + logStream << m_values[v] << "\n"; } } @@ -229,7 +228,6 @@ void TableFunction::convertTable2D( TableData2D::Conversion1D & tableConverted ) { TableData2D tableData2D; tableData2D.collect2DData( m_coordinates[0], m_coordinates[1], m_values ); - tableConverted = tableData2D.convert2DData( m_valueUnit, units::getDescription( getDimUnit( 0 ) ), units::getDescription( getDimUnit( 1 ) )); @@ -237,7 +235,7 @@ void TableFunction::convertTable2D( TableData2D::Conversion1D & tableConverted ) void TableFunction::printInCSV( string const & filename ) const { - std::ofstream os( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); + std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to inputFiles/compositionalMultiphaseWell/{}/{}.csv \n", OutputBase::getOutputDirectory(), filename )); @@ -245,8 +243,8 @@ void TableFunction::printInCSV( string const & filename ) const if( numDimensions != 2 ) { - printCSVHeader( os, numDimensions ); - printCSVValues( os, numDimensions ); + printCSVHeader( logStream, numDimensions ); + printCSVValues( logStream, numDimensions ); } else // numDimensions == 2 { @@ -257,9 +255,9 @@ void TableFunction::printInCSV( string const & filename ) const TableLayout tableLayout( tableConverted.headerNames ); //3. TableCSVFormatter csvFormat( tableLayout ); - os << csvFormat.headerToString() << csvFormat.dataToString( tableConverted.tableData ); + logStream << csvFormat.headerToString() << csvFormat.dataToString( tableConverted.tableData ); } - os.close(); + logStream.close(); } void TableFunction::printInLog( string const & title ) const @@ -270,25 +268,24 @@ void TableFunction::printInLog( string const & title ) const if( numDimensions == 1 ) { + //1. TableData tableData; arraySlice1d< real64 const > const coords = m_coordinates[0]; - for( integer idx = 0; idx < m_values.size(); idx++ ) { tableData.addRow( coords[idx], m_values[idx] ); } - + //2. TableLayout const tableLayout( { string( units::getDescription( getDimUnit( 0 ))), string( units::getDescription( m_valueUnit )) }, title ); - + //3. TableTextFormatter const logTable( tableLayout ); GEOS_LOG_RANK_0( logTable.toString( tableData )); } else if( numDimensions == 2 ) { - TableData2D tableData2D; integer const nX = m_coordinates[0].size(); integer const nY = m_coordinates[1].size(); if( nX * nY <= 500 ) diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index 6e67fa33f55..0753e18a41c 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -241,9 +241,9 @@ class TableFunction : public FunctionBase */ void checkCoord( real64 coord, localIndex dim ) const; - void printCSVHeader( std::ofstream & os, integer const numDimensions ) const; + void printCSVHeader( std::ofstream & logStream, integer const numDimensions ) const; - void printCSVValues( std::ofstream & os, integer const numDimensions ) const; + void printCSVValues( std::ofstream & logStream, integer const numDimensions ) const; void convertTable2D( TableData2D::Conversion1D & tableConverted ) const; From 98764af33140e15787d3d983470d6ba2175c035f Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 7 Jun 2024 15:16:23 +0200 Subject: [PATCH 122/216] refacto continuing ( commit works ) --- .../CO2Brine/functions/CO2Solubility.hpp | 22 ++- .../CO2Brine/functions/PVTFunctionBase.hpp | 19 ++- src/coreComponents/fileIO/Table/TableData.cpp | 28 +-- src/coreComponents/fileIO/Table/TableData.hpp | 31 +--- .../fileIO/Table/TableFormatter.cpp | 11 +- .../fileIO/Table/TableFormatter.hpp | 56 ++++-- .../fileIO/Table/TableLayout.hpp | 2 + .../fileIO/Table/unitTests/testTable.cpp | 4 +- .../functions/TableFunction.cpp | 159 ++++++++++-------- .../functions/TableFunction.hpp | 43 +++-- 10 files changed, 221 insertions(+), 154 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp index 0d9089d5def..650a5fa2308 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp @@ -24,6 +24,7 @@ #include "constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionHelpers.hpp" #include "constitutive/fluid/multifluid/Layouts.hpp" #include "constitutive/fluid/multifluid/MultiFluidUtils.hpp" +#include "fileIO/Table/TableFormatter.hpp" #include "functions/TableFunction.hpp" namespace geos @@ -130,20 +131,27 @@ class CO2Solubility : public FlashModelBase /** * @brief Check whether we print to screen or to a csv file - * @param table + * @param tableData * @param printInCsv * @param printInLog */ - void checkTableOutput( TableFunction const * table, bool const printInCsv, bool const printInLog - ) + void checkTableOutput( TableFunction const * tableData, bool const printInCsv, bool const printInLog ) { - if( printInLog && table->numDimensions() <= 2 ) + if( printInLog && tableData->numDimensions() <= 2 ) { - table->printInLog( table->getName() ); + TableTextFormatter textFormatter; + GEOS_LOG_RANK_0( textFormatter.toString( *tableData )); } - if( printInCsv || ( printInLog && table->numDimensions() >= 3 ) ) + if( printInCsv || ( printInLog && tableData->numDimensions() >= 3 ) ) { - table->printInCSV( table->getName() ); + string const filename = tableData->getName(); + std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); + GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to inputFiles/compositionalMultiphaseWell/{}/{}.csv \n", + OutputBase::getOutputDirectory(), + filename )); + + TableCSVFormatter csvFormatter; + logStream << csvFormatter.toString( *tableData ); } } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index b9f3d09cdf7..b8ab7c4af70 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -20,6 +20,7 @@ #define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_FUNCTIONS_PVTFUNCTIONBASE_HPP_ #include "dataRepository/ObjectCatalog.hpp" +#include "fileIO/Table/TableFormatter.hpp" #include "functions/TableFunction.hpp" namespace geos @@ -146,15 +147,23 @@ class PVTFunctionBase * @param printInCsv Boolean for printing in CSV * @param printInLog Boolean for printing in Log */ - void checkTableOutput ( TableFunction const * table, bool const printInCsv, bool const printInLog ) + void checkTableOutput( TableFunction const * tableData, bool const printInCsv, bool const printInLog ) { - if( printInCsv || ( printInLog && table->numDimensions() >= 3 ) ) + if( printInLog && tableData->numDimensions() <= 2 ) { - table->printInCSV( table->getName() ); + TableTextFormatter textFormatter; + GEOS_LOG_RANK_0( textFormatter.toString( *tableData )); } - if( printInLog && table->numDimensions() <= 2 ) + + if( printInCsv || ( printInLog && tableData->numDimensions() >= 3 ) ) { - table->printInLog( table->getName() ); + string const filename = tableData->getName(); + std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); + GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to inputFiles/compositionalMultiphaseWell/{}/{}.csv \n", + OutputBase::getOutputDirectory(), + filename )); + TableCSVFormatter csvFormatter; + logStream << csvFormatter.toString( *tableData ); } } diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index badb76435fa..c56d5f856f1 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -50,14 +50,12 @@ std::vector< string > const & TableData::getErrorMsgs() const return m_errorsMsg; } -void TableData2D::collect2DData( arraySlice1d< real64 const > const rowAxis, - arraySlice1d< real64 const > const columnAxis, +void TableData2D::collect2DData( arraySlice1d< real64 const > rowAxis, + arraySlice1d< real64 const > columnAxis, arrayView1d< real64 const > values ) { - arraySlice1d< real64 const > const coordsX = rowAxis; - arraySlice1d< real64 const > const coordsY = columnAxis; - integer const nX = coordsX.size(); - integer const nY = coordsY.size(); + integer const nX = rowAxis.size(); + integer const nY = columnAxis.size(); for( integer i = 0; i < nX; i++ ) { @@ -68,12 +66,16 @@ void TableData2D::collect2DData( arraySlice1d< real64 const > const rowAxis, } } -TableData2D::Conversion1D TableData2D::convert2DData( units::Unit valueUnit, - string_view rowUnitDescription, - string_view columnUnitDescription ) +TableData2D::TableDataConversion TableData2D::convertTable2D( arrayView1d< real64 const > const values, + units::Unit valueUnit, + ArrayOfArraysView< real64 const > coordinates, + string_view rowAxisDescription, + string_view columnAxisDescription ) { - string const rowFmt = GEOS_FMT( "{} = {{}}", rowUnitDescription ); - string const columnFmt = GEOS_FMT( "{} = {{}}", columnUnitDescription ); + string const rowFmt = GEOS_FMT( "{} = {{}}", rowAxisDescription ); + string const columnFmt = GEOS_FMT( "{} = {{}}", columnAxisDescription ); + + collect2DData( coordinates[0], coordinates[1], values ); return buildTableData( string( units::getDescription( valueUnit )), rowFmt, columnFmt ); @@ -84,11 +86,11 @@ size_t TableData2D::getNbRows() const return m_data.size(); } -TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, +TableData2D::TableDataConversion TableData2D::buildTableData( string_view targetUnit, string_view rowFmt, string_view columnFmt ) const { - TableData2D::Conversion1D tableData1D; + TableData2D::TableDataConversion tableData1D; std::vector< size_t > rowsLength; tableData1D.headerNames.push_back( string( targetUnit ) ); diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 15f3673e8df..ec28a3ebc42 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -85,7 +85,7 @@ class TableData2D using ColumnType = real64; /// Struct containing conversion informations - struct Conversion1D + struct TableDataConversion { /// Vector containing all columns names std::vector< string > headerNames; @@ -103,28 +103,15 @@ class TableData2D template< typename T > void addCell( RowType rowValue, ColumnType columnValue, T const & value ); - /** - * @brief - * - * @param rowAxis - * @param columnAxis - * @param values - */ - void collect2DData( arraySlice1d< real64 const > const rowAxis, - arraySlice1d< real64 const > const columnAxis, + void collect2DData( arraySlice1d< real64 const > rowAxis, + arraySlice1d< real64 const > columnAxis, arrayView1d< real64 const > values ); - /** - * @brief - * - * @param valueUnit - * @param rowUnitDescription - * @param columnUnitDescription - * @return TableData2D::Conversion1D - */ - TableData2D::Conversion1D convert2DData( units::Unit valueUnit, - string_view rowUnitDescription, - string_view columnUnitDescription ); + TableData2D::TableDataConversion convertTable2D( arrayView1d< real64 const > const values, + units::Unit valueUnit, + ArrayOfArraysView< real64 const > coordinates, + string_view rowAxisDescription, + string_view columnAxisDescription ); size_t getNbRows() const; @@ -137,7 +124,7 @@ 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; + TableDataConversion buildTableData( string_view dataDescription, string_view rowFmt = "{}", string_view columnFmt = "{}" ) const; private: /// @brief all cell values by their [ row ][ column ] diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 35699fc3927..8b79a1f07a3 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -16,8 +16,6 @@ * @file TableFormatter.cpp */ -#include -#include "codingUtilities/StringUtilities.hpp" #include "TableFormatter.hpp" namespace geos { @@ -66,7 +64,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 ); } @@ -150,7 +149,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; @@ -398,4 +398,5 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); } } -} \ No newline at end of file + +} diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 0aae19a73a0..9dedaca292e 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -21,6 +21,10 @@ #include "TableData.hpp" #include "TableLayout.hpp" +#include "common/Units.hpp" +#include +#include "codingUtilities/StringUtilities.hpp" +#include "fileIO/Outputs/OutputBase.hpp" namespace geos { @@ -36,6 +40,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 @@ -55,6 +61,11 @@ 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 @@ -79,28 +90,44 @@ 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 soruce 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 table 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 */ @@ -112,11 +139,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: @@ -125,7 +153,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 @@ -216,6 +244,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 \ No newline at end of file +#endif diff --git a/src/coreComponents/fileIO/Table/TableLayout.hpp b/src/coreComponents/fileIO/Table/TableLayout.hpp index f19759ae453..29b9e205421 100644 --- a/src/coreComponents/fileIO/Table/TableLayout.hpp +++ b/src/coreComponents/fileIO/Table/TableLayout.hpp @@ -96,6 +96,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 diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index 98dabc25d84..4eec9af150e 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -210,7 +210,7 @@ TEST( testTable, table2DTable ) //convert string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::Conversion1D tableconverted = tableData.buildTableData( "Viscosity kg*s", + TableData2D::TableDataConversion tableconverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); @@ -248,7 +248,7 @@ TEST( testTable, table2DColumnMismatch ) //convert string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::Conversion1D tableConverted = tableData.buildTableData( "Viscosity kg*s", + TableData2D::TableDataConversion tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 323d44c2a48..0dde2ab2326 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -20,8 +20,6 @@ #include "codingUtilities/Parsing.hpp" #include "common/DataTypes.hpp" #include "fileIO/Outputs/OutputBase.hpp" - - #include namespace geos @@ -185,26 +183,52 @@ void TableFunction::checkCoord( real64 const coord, localIndex const dim ) const SimulationError ); } -void TableFunction::printCSVHeader( std::ofstream & logStream, integer const numDimensions ) const +TableFunction::KernelWrapper TableFunction::createKernelWrapper() const +{ + return { m_interpolationMethod, + m_coordinates.toViewConst(), + m_values.toViewConst() }; +} + +real64 TableFunction::evaluate( real64 const * const input ) const +{ + return m_kernelWrapper.compute( input ); +} + +TableFunction::KernelWrapper::KernelWrapper( InterpolationType const interpolationMethod, + ArrayOfArraysView< real64 const > const & coordinates, + arrayView1d< real64 const > const & values ) + : + m_interpolationMethod( interpolationMethod ), + m_coordinates( coordinates ), + m_values( values ) +{} + +void collectHeader( std::ostringstream & formatterStream, + TableFunction const & tableFunction, + integer const numDimensions ) { for( integer d = 0; d < numDimensions; d++ ) { - logStream << units::getDescription( getDimUnit( d )) << ","; + formatterStream << units::getDescription( tableFunction.getDimUnit( d )) << ","; } - logStream << units::getDescription( m_valueUnit ) << "\n"; + formatterStream << units::getDescription( valueUnit ) << "\n"; } -void TableFunction::printCSVValues( std::ofstream & logStream, integer const numDimensions ) const +void collectValues( std::ostringstream & formatterStream, + integer const numDimensions, + ArrayOfArraysView< real64 const > coordinates, + arrayView1d< real64 const > const values ) { // prepare dividers std::vector< integer > div( numDimensions ); div[0] = 1; for( integer d = 1; d < numDimensions; d++ ) { - div[d] = div[d-1] * m_coordinates[d-1].size(); + div[d] = div[d-1] * coordinates[d-1].size(); } // loop through all the values - for( integer v = 0; v < m_values.size(); v++ ) + for( integer v = 0; v < values.size(); v++ ) { // find coords indices std::vector< integer > idx( numDimensions ); @@ -217,121 +241,110 @@ void TableFunction::printCSVValues( std::ofstream & logStream, integer const num // finally print out in right order for( integer d = 0; d < numDimensions; d++ ) { - arraySlice1d< real64 const > const coords = m_coordinates[d]; - logStream << coords[idx[d]] << ","; + arraySlice1d< real64 const > const coords = coordinates[d]; + formatterStream << coords[idx[d]] << ","; } - logStream << m_values[v] << "\n"; + formatterStream << values[v] << "\n"; } } -void TableFunction::convertTable2D( TableData2D::Conversion1D & tableConverted ) const +template<> +string TableCSVFormatter::toString< TableFunction >( TableFunction const & tableFunction ) const { - TableData2D tableData2D; - tableData2D.collect2DData( m_coordinates[0], m_coordinates[1], m_values ); - tableConverted = tableData2D.convert2DData( m_valueUnit, - units::getDescription( getDimUnit( 0 ) ), - units::getDescription( getDimUnit( 1 ) )); -} - -void TableFunction::printInCSV( string const & filename ) const -{ - std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); - GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to inputFiles/compositionalMultiphaseWell/{}/{}.csv \n", - OutputBase::getOutputDirectory(), - filename )); - integer const numDimensions = LvArray::integerConversion< integer >( m_coordinates.size() ); + ArrayOfArraysView< real64 const > coordinates = tableFunction.getCoordinates(); + arrayView1d< real64 const > const values = tableFunction.getValues(); + units::Unit valueUnit = tableFunction.getValueUnits(); + std::ostringstream formatterStream; + integer const numDimensions = LvArray::integerConversion< integer >( coordinates.size() ); if( numDimensions != 2 ) { - printCSVHeader( logStream, numDimensions ); - printCSVValues( logStream, numDimensions ); + collectHeader( std::ostringstream & formatterStream, + TableFunction const & tableFunction, + integer const numDimensions ); + collectValues( formatterStream, numDimensions, coordinates, values ); } else // numDimensions == 2 { //1. - TableData2D::Conversion1D tableConverted; - convertTable2D( tableConverted ); + TableData2D tableData2D; + TableData2D::TableDataConversion tableConverted; + tableConverted = tableData2D.convertTable2D( values, + valueUnit, + coordinates, + units::getDescription( tableFunction.getDimUnit( 0 ) ), + units::getDescription( tableFunction.getDimUnit( 1 ) ) ); //2. TableLayout tableLayout( tableConverted.headerNames ); //3. TableCSVFormatter csvFormat( tableLayout ); - logStream << csvFormat.headerToString() << csvFormat.dataToString( tableConverted.tableData ); + formatterStream << csvFormat.headerToString() << csvFormat.dataToString( tableConverted.tableData ); } - logStream.close(); + return formatterStream.str(); } -void TableFunction::printInLog( string const & title ) const +template<> +string TableTextFormatter::toString< TableFunction >( TableFunction const & tableFunction ) const { - integer const numDimensions = LvArray::integerConversion< integer >( m_coordinates.size() ); + ArrayOfArraysView< real64 const > coordinates = tableFunction.getCoordinates(); + units::Unit valueUnit = tableFunction.getValueUnits(); + arrayView1d< real64 const > const values = tableFunction.getValues(); + integer const numDimensions = LvArray::integerConversion< integer >( coordinates.size() ); + string const filename = tableFunction.getName(); + string logOutput; - GEOS_LOG_RANK_0( GEOS_FMT( "Values in the table are represented by : {}", units::getDescription( m_valueUnit ))); + GEOS_LOG_RANK_0( GEOS_FMT( "Values in the table are represented by : {}", units::getDescription( valueUnit ))); if( numDimensions == 1 ) { //1. TableData tableData; - arraySlice1d< real64 const > const coords = m_coordinates[0]; - for( integer idx = 0; idx < m_values.size(); idx++ ) + arraySlice1d< real64 const > const coords = coordinates[0]; + for( integer idx = 0; idx < values.size(); idx++ ) { - tableData.addRow( coords[idx], m_values[idx] ); + tableData.addRow( coords[idx], values[idx] ); } //2. TableLayout const tableLayout( { - string( units::getDescription( getDimUnit( 0 ))), - string( units::getDescription( m_valueUnit )) - }, title ); + string( units::getDescription( tableFunction.getDimUnit( 0 ))), + string( units::getDescription( valueUnit )) + }, filename ); //3. TableTextFormatter const logTable( tableLayout ); - GEOS_LOG_RANK_0( logTable.toString( tableData )); + logOutput = logTable.toString( tableData ); } else if( numDimensions == 2 ) { - integer const nX = m_coordinates[0].size(); - integer const nY = m_coordinates[1].size(); + integer const nX = coordinates[0].size(); + integer const nY = coordinates[1].size(); if( nX * nY <= 500 ) { - // log table2D //1. - TableData2D::Conversion1D tableConverted; - convertTable2D( tableConverted ); + TableData2D tableData2D; + TableData2D::TableConversionData tableConverted; + tableConverted = tableData2D.convertTable2D( values, + valueUnit, + coordinates, + units::getDescription( tableFunction.getDimUnit( 0 ) ), + units::getDescription( tableFunction.getDimUnit( 1 ) )); //2. - TableLayout tableLayout( tableConverted.headerNames, title ); + TableLayout tableLayout( tableConverted.headerNames, filename ); //3. TableTextFormatter const table2DLog( tableLayout ); - GEOS_LOG_RANK_0( table2DLog.toString( tableConverted.tableData )); + logOutput = table2DLog.toString( tableConverted.tableData ); } else { // log informative - string log = GEOS_FMT( "The {} PVT table exceeding 500 rows.\nTo visualize the tables, go to the generated csv \n", title ); - TableLayout const tableLayoutInfos( {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}}, title ); - + 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 ); TableTextFormatter const tableLog( tableLayoutInfos ); - GEOS_LOG_RANK_0( tableLog.layoutToString() ); + logOutput = tableLog.layoutToString(); } } + return logOutput; } -TableFunction::KernelWrapper TableFunction::createKernelWrapper() const -{ - return { m_interpolationMethod, - m_coordinates.toViewConst(), - m_values.toViewConst() }; -} - -real64 TableFunction::evaluate( real64 const * const input ) const -{ - return m_kernelWrapper.compute( input ); -} - -TableFunction::KernelWrapper::KernelWrapper( InterpolationType const interpolationMethod, - ArrayOfArraysView< real64 const > const & coordinates, - arrayView1d< real64 const > const & values ) - : - m_interpolationMethod( interpolationMethod ), - m_coordinates( coordinates ), - m_values( values ) -{} REGISTER_CATALOG_ENTRY( FunctionBase, TableFunction, string const &, Group * const ) diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index 0753e18a41c..9be87d040b7 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -241,23 +241,17 @@ class TableFunction : public FunctionBase */ void checkCoord( real64 coord, localIndex dim ) const; - void printCSVHeader( std::ofstream & logStream, integer const numDimensions ) const; - - void printCSVValues( std::ofstream & logStream, integer const numDimensions ) const; - - void convertTable2D( TableData2D::Conversion1D & tableConverted ) const; - - /** - * @brief Print table into a CSV file - * @param filename Filename for output - */ - void printInCSV( string const & filename ) const; - - /** - * @brief Print table to the log (only 1d and 2d tables are supported). - * @param filename Filename for output - */ - void printInLog( string const & filename ) const; + // /** + // * @brief Print table into a CSV file + // * @param filename Filename for output + // */ + // void printInCSV( string const & filename ) const; + + // /** + // * @brief Print table to the log (only 1d and 2d tables are supported). + // * @param filename Filename for output + // */ + // void printInLog( string const & filename ) const; /** * @brief @return Number of table dimensions @@ -340,6 +334,15 @@ class TableFunction : public FunctionBase m_valueUnit = unit; } + /** + * @brief Set the table value units + * @param unit The unit of the values + */ + units::Unit getValueUnit() const + { + return m_valueUnit; + } + /** * @brief Create an instance of the kernel wrapper * @return the kernel wrapper @@ -690,6 +693,12 @@ ENUM_STRINGS( TableFunction::InterpolationType, "upper", "lower" ); +template<> +string TableTextFormatter::toString< TableFunction >( TableFunction const & tableData ) const; + +template<> +string TableCSVFormatter::toString< TableFunction >( TableFunction const & tableData ) const; + } /* namespace geos */ #endif /* GEOS_FUNCTIONS_TABLEFUNCTION_HPP_ */ From 809194584c60a90bac0661fa62ebc72bd028cc05 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 7 Jun 2024 17:08:55 +0200 Subject: [PATCH 123/216] missing doxygen --- .../CO2Brine/functions/CO2Solubility.hpp | 2 +- .../CO2Brine/functions/PVTFunctionBase.hpp | 2 +- src/coreComponents/fileIO/Table/TableData.cpp | 32 ++++++++--------- src/coreComponents/fileIO/Table/TableData.hpp | 35 +++++++++++++------ .../fileIO/Table/TableFormatter.hpp | 1 - .../fileIO/Table/unitTests/testTable.cpp | 4 +-- .../functions/TableFunction.cpp | 20 +++++------ .../functions/TableFunction.hpp | 2 -- 8 files changed, 55 insertions(+), 43 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp index 650a5fa2308..42a66eac77e 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp @@ -24,7 +24,7 @@ #include "constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionHelpers.hpp" #include "constitutive/fluid/multifluid/Layouts.hpp" #include "constitutive/fluid/multifluid/MultiFluidUtils.hpp" -#include "fileIO/Table/TableFormatter.hpp" +#include "fileIO/Outputs/OutputBase.hpp" #include "functions/TableFunction.hpp" namespace geos diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index b8ab7c4af70..c3c50389833 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -20,7 +20,7 @@ #define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_FUNCTIONS_PVTFUNCTIONBASE_HPP_ #include "dataRepository/ObjectCatalog.hpp" -#include "fileIO/Table/TableFormatter.hpp" +#include "fileIO/Outputs/OutputBase.hpp" #include "functions/TableFunction.hpp" namespace geos diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index c56d5f856f1..c4bb8ccf546 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -50,32 +50,32 @@ std::vector< string > const & TableData::getErrorMsgs() const return m_errorsMsg; } -void TableData2D::collect2DData( arraySlice1d< real64 const > rowAxis, - arraySlice1d< real64 const > columnAxis, - arrayView1d< real64 const > values ) +void TableData2D::collectTableValues( arraySlice1d< real64 const > rowAxisValues, + arraySlice1d< real64 const > columnAxisValues, + arrayView1d< real64 const > values ) { - integer const nX = rowAxis.size(); - integer const nY = columnAxis.size(); + 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( rowAxis[i], columnAxis[y], values[ y*nX + i ] ); + addCell( rowAxisValues[i], columnAxisValues[y], values[ y*nX + i ] ); } } } -TableData2D::TableDataConversion TableData2D::convertTable2D( arrayView1d< real64 const > const values, - units::Unit valueUnit, - ArrayOfArraysView< real64 const > coordinates, - string_view rowAxisDescription, - string_view columnAxisDescription ) +TableData2D::TableConversionData 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 ); - collect2DData( coordinates[0], coordinates[1], values ); + collectTableValues( coordinates[0], coordinates[1], values ); return buildTableData( string( units::getDescription( valueUnit )), rowFmt, columnFmt ); @@ -86,11 +86,11 @@ size_t TableData2D::getNbRows() const return m_data.size(); } -TableData2D::TableDataConversion TableData2D::buildTableData( string_view targetUnit, - string_view rowFmt, - string_view columnFmt ) const +TableData2D::TableConversionData TableData2D::buildTableData( string_view targetUnit, + string_view rowFmt, + string_view columnFmt ) const { - TableData2D::TableDataConversion tableData1D; + TableData2D::TableConversionData tableData1D; std::vector< size_t > rowsLength; tableData1D.headerNames.push_back( string( targetUnit ) ); diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index ec28a3ebc42..333c7294874 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -85,9 +85,10 @@ class TableData2D using ColumnType = real64; /// Struct containing conversion informations - struct TableDataConversion + struct TableConversionData { /// Vector containing all columns names + /// A header value is presented as "pressure [K] = {}" std::vector< string > headerNames; /// TableData to be built TableData tableData; @@ -103,15 +104,29 @@ class TableData2D template< typename T > void addCell( RowType rowValue, ColumnType columnValue, T const & value ); - void collect2DData( arraySlice1d< real64 const > rowAxis, - arraySlice1d< real64 const > columnAxis, - arrayView1d< real64 const > values ); + /** + * @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 ); - TableData2D::TableDataConversion convertTable2D( arrayView1d< real64 const > const values, - units::Unit valueUnit, - ArrayOfArraysView< real64 const > coordinates, - string_view rowAxisDescription, - string_view columnAxisDescription ); + /** + * @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::TableConversionData convertTable2D( arrayView1d< real64 const > const values, + units::Unit const valueUnit, + ArrayOfArraysView< real64 const > const coordinates, + string_view rowAxisDescription, + string_view columnAxisDescription ); size_t getNbRows() const; @@ -124,7 +139,7 @@ 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] = {}" */ - TableDataConversion buildTableData( string_view dataDescription, string_view rowFmt = "{}", string_view columnFmt = "{}" ) const; + TableConversionData buildTableData( string_view dataDescription, string_view rowFmt = "{}", string_view columnFmt = "{}" ) const; private: /// @brief all cell values by their [ row ][ column ] diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 9dedaca292e..344b172f5b0 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -24,7 +24,6 @@ #include "common/Units.hpp" #include #include "codingUtilities/StringUtilities.hpp" -#include "fileIO/Outputs/OutputBase.hpp" namespace geos { diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index 4eec9af150e..94b2592d079 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -210,7 +210,7 @@ TEST( testTable, table2DTable ) //convert string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::TableDataConversion tableconverted = tableData.buildTableData( "Viscosity kg*s", + TableData2D::TableConversionData tableconverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); @@ -248,7 +248,7 @@ TEST( testTable, table2DColumnMismatch ) //convert string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::TableDataConversion tableConverted = tableData.buildTableData( "Viscosity kg*s", + TableData2D::TableConversionData tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 0dde2ab2326..803c128dd8e 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -17,9 +17,10 @@ */ #include "TableFunction.hpp" +#include "fileIO/Table/TableData.hpp" +#include "fileIO/Table/TableLayout.hpp" #include "codingUtilities/Parsing.hpp" #include "common/DataTypes.hpp" -#include "fileIO/Outputs/OutputBase.hpp" #include namespace geos @@ -206,7 +207,8 @@ TableFunction::KernelWrapper::KernelWrapper( InterpolationType const interpolati void collectHeader( std::ostringstream & formatterStream, TableFunction const & tableFunction, - integer const numDimensions ) + integer const numDimensions, + units::Unit const valueUnit ) { for( integer d = 0; d < numDimensions; d++ ) { @@ -217,7 +219,7 @@ void collectHeader( std::ostringstream & formatterStream, void collectValues( std::ostringstream & formatterStream, integer const numDimensions, - ArrayOfArraysView< real64 const > coordinates, + ArrayOfArraysView< real64 const > const coordinates, arrayView1d< real64 const > const values ) { // prepare dividers @@ -251,24 +253,22 @@ void collectValues( std::ostringstream & formatterStream, template<> string TableCSVFormatter::toString< TableFunction >( TableFunction const & tableFunction ) const { - ArrayOfArraysView< real64 const > coordinates = tableFunction.getCoordinates(); + ArrayOfArraysView< real64 const > const coordinates = tableFunction.getCoordinates(); arrayView1d< real64 const > const values = tableFunction.getValues(); - units::Unit valueUnit = tableFunction.getValueUnits(); + units::Unit const valueUnit = tableFunction.getValueUnit(); std::ostringstream formatterStream; integer const numDimensions = LvArray::integerConversion< integer >( coordinates.size() ); if( numDimensions != 2 ) { - collectHeader( std::ostringstream & formatterStream, - TableFunction const & tableFunction, - integer const numDimensions ); + collectHeader( formatterStream, tableFunction, numDimensions, valueUnit ); collectValues( formatterStream, numDimensions, coordinates, values ); } else // numDimensions == 2 { //1. TableData2D tableData2D; - TableData2D::TableDataConversion tableConverted; + TableData2D::TableConversionData tableConverted; tableConverted = tableData2D.convertTable2D( values, valueUnit, coordinates, @@ -287,7 +287,7 @@ template<> string TableTextFormatter::toString< TableFunction >( TableFunction const & tableFunction ) const { ArrayOfArraysView< real64 const > coordinates = tableFunction.getCoordinates(); - units::Unit valueUnit = tableFunction.getValueUnits(); + units::Unit const valueUnit = tableFunction.getValueUnit(); arrayView1d< real64 const > const values = tableFunction.getValues(); integer const numDimensions = LvArray::integerConversion< integer >( coordinates.size() ); string const filename = tableFunction.getName(); diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index 9be87d040b7..50401e4946c 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -23,8 +23,6 @@ #include "codingUtilities/EnumStrings.hpp" #include "LvArray/src/tensorOps.hpp" -#include "fileIO/Table/TableData.hpp" -#include "fileIO/Table/TableLayout.hpp" #include "fileIO/Table/TableFormatter.hpp" #include "common/Units.hpp" From 1c8d7a96281cf2e4c3dc908a489204b60eda1733 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 7 Jun 2024 17:13:02 +0200 Subject: [PATCH 124/216] correction fun name --- src/coreComponents/functions/TableFunction.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 803c128dd8e..5e73bcd1770 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -205,7 +205,7 @@ TableFunction::KernelWrapper::KernelWrapper( InterpolationType const interpolati m_values( values ) {} -void collectHeader( std::ostringstream & formatterStream, +void collectHeaders( std::ostringstream & formatterStream, TableFunction const & tableFunction, integer const numDimensions, units::Unit const valueUnit ) @@ -261,10 +261,10 @@ string TableCSVFormatter::toString< TableFunction >( TableFunction const & table integer const numDimensions = LvArray::integerConversion< integer >( coordinates.size() ); if( numDimensions != 2 ) { - collectHeader( formatterStream, tableFunction, numDimensions, valueUnit ); + collectHeaders( formatterStream, tableFunction, numDimensions, valueUnit ); collectValues( formatterStream, numDimensions, coordinates, values ); } - else // numDimensions == 2 + else { //1. TableData2D tableData2D; @@ -335,7 +335,6 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl } else { - // log informative 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 ); TableTextFormatter const tableLog( tableLayoutInfos ); @@ -345,7 +344,6 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl return logOutput; } - REGISTER_CATALOG_ENTRY( FunctionBase, TableFunction, string const &, Group * const ) } // end of namespace geos From 2c17324a70bcf845e4d512cecc3cf1d6173bde9d Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 10 Jun 2024 09:47:02 +0200 Subject: [PATCH 125/216] missing doc --- .../functions/TableFunction.cpp | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 5e73bcd1770..e9b4ccf4f96 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -205,10 +205,17 @@ TableFunction::KernelWrapper::KernelWrapper( InterpolationType const interpolati m_values( values ) {} +/** + * @brief Retrieve all data headers from a table function + * @param formatterStream The stream who contains the csv table string + * @param tableFunction The table function to be process + * @param numDimensions Numbers of axes in the table + * @param valueUnit The table unit value + */ void collectHeaders( std::ostringstream & formatterStream, - TableFunction const & tableFunction, - integer const numDimensions, - units::Unit const valueUnit ) + TableFunction const & tableFunction, + integer const numDimensions, + units::Unit const valueUnit ) { for( integer d = 0; d < numDimensions; d++ ) { @@ -217,6 +224,13 @@ void collectHeaders( std::ostringstream & formatterStream, formatterStream << units::getDescription( valueUnit ) << "\n"; } +/** + * @brief Retrieve all data values + * @param formatterStream The stream who contains the csv table string + * @param numDimensions Numbers of axes in the table + * @param coordinates The tables axis values + * @param values The table values to be retrived + */ void collectValues( std::ostringstream & formatterStream, integer const numDimensions, ArrayOfArraysView< real64 const > const coordinates, @@ -268,7 +282,7 @@ string TableCSVFormatter::toString< TableFunction >( TableFunction const & table { //1. TableData2D tableData2D; - TableData2D::TableConversionData tableConverted; + TableData2D::TableConversionData tableConverted; tableConverted = tableData2D.convertTable2D( values, valueUnit, coordinates, From 0dddcf5c17c7dead68c51cee1d0d05acc1d2ae54 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 10 Jun 2024 10:34:42 +0200 Subject: [PATCH 126/216] uncrustify + doc --- src/coreComponents/fileIO/Table/TableData.hpp | 4 ++-- .../fileIO/Table/TableFormatter.hpp | 6 ++++-- .../fileIO/Table/unitTests/testTable.cpp | 12 ++++++------ src/coreComponents/functions/TableFunction.hpp | 17 +++++++++++++---- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 333c7294874..160430f0c4a 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -108,14 +108,14 @@ class TableData2D * @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 + * @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 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 diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 344b172f5b0..41a9621172a 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -90,7 +90,8 @@ class TableCSVFormatter : public TableFormatter /** * @brief Convert a data source to a CSV string. - * @tparam DATASOURCE The soruce to convert + * @tparam DATASOURCE The source to convert + * @param tableData The data source to convert * @return The CSV string representation of a data source. */ template< typename DATASOURCE > @@ -99,7 +100,7 @@ class TableCSVFormatter : public TableFormatter }; /** - * @brief Convert the TableData to a table string. + * @brief Convert the TableData to a CSV string. * @param tableData The TableData to convert. * @return The CSV string representation of the TableData. */ @@ -140,6 +141,7 @@ class TableTextFormatter : public TableFormatter /** * @brief Convert a data source to a table string. * @param tableData The data source to convert. + * @param tableData The data source to convert * @return The table string representation of the TableData. */ template< typename DATASOURCE > diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index 94b2592d079..123eb7f0d48 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -210,9 +210,9 @@ TEST( testTable, table2DTable ) //convert string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::TableConversionData tableconverted = tableData.buildTableData( "Viscosity kg*s", - rowFmt, - columnFmt ); + TableData2D::TableConversionData tableconverted = tableData.buildTableData( "Viscosity kg*s", + rowFmt, + columnFmt ); //format TableLayout const tableLayout( tableconverted.headerNames ); @@ -248,9 +248,9 @@ TEST( testTable, table2DColumnMismatch ) //convert string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::TableConversionData tableConverted = tableData.buildTableData( "Viscosity kg*s", - rowFmt, - columnFmt ); + TableData2D::TableConversionData tableConverted = tableData.buildTableData( "Viscosity kg*s", + rowFmt, + columnFmt ); //format TableLayout const tableLayout( tableConverted.headerNames ); diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index 50401e4946c..91cac4ed2d5 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -332,10 +332,9 @@ class TableFunction : public FunctionBase m_valueUnit = unit; } - /** - * @brief Set the table value units - * @param unit The unit of the values - */ +/** + * @return The unit of the table values + */ units::Unit getValueUnit() const { return m_valueUnit; @@ -691,9 +690,19 @@ ENUM_STRINGS( TableFunction::InterpolationType, "upper", "lower" ); +/** + * @brief Template specialisation to convert a TableFunction to a CSV string. + * @param tableData The TableFunction object to convert. + * @return The CSV string representation of the TableFunction. + */ template<> string TableTextFormatter::toString< TableFunction >( TableFunction const & tableData ) const; +/** + * @brief Template specialisation to convert a TableFunction to a table string. + * @param tableData The TableFunction object to convert. + * @return The table string representation of the TableFunction. + */ template<> string TableCSVFormatter::toString< TableFunction >( TableFunction const & tableData ) const; From 7ee093ba7772bdb57b89f37b3e6cd41caa545cd6 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 10 Jun 2024 10:38:33 +0200 Subject: [PATCH 127/216] Doxygen check --- src/coreComponents/fileIO/Table/TableData.cpp | 5 ----- src/coreComponents/fileIO/Table/TableData.hpp | 2 -- src/coreComponents/fileIO/Table/TableFormatter.hpp | 1 - 3 files changed, 8 deletions(-) diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index c4bb8ccf546..7d142d47a61 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -81,11 +81,6 @@ TableData2D::TableConversionData TableData2D::convertTable2D( arrayView1d< real6 columnFmt ); } -size_t TableData2D::getNbRows() const -{ - return m_data.size(); -} - TableData2D::TableConversionData TableData2D::buildTableData( string_view targetUnit, string_view rowFmt, string_view columnFmt ) const diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 160430f0c4a..c083e7fbe28 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -128,8 +128,6 @@ class TableData2D string_view rowAxisDescription, string_view columnAxisDescription ); - size_t getNbRows() const; - /** * @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 diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 41a9621172a..5293b980efe 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -141,7 +141,6 @@ class TableTextFormatter : public TableFormatter /** * @brief Convert a data source to a table string. * @param tableData The data source to convert. - * @param tableData The data source to convert * @return The table string representation of the TableData. */ template< typename DATASOURCE > From 86fe90b8652a4b91dcd178ba2aad343a89aa2475 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 14 Jun 2024 15:34:20 +0200 Subject: [PATCH 128/216] review correction + add pvtOptions struct --- .../multifluid/CO2Brine/CO2BrineFluid.cpp | 27 ++++++++++++------- .../fluid/multifluid/CO2Brine/PhaseModel.hpp | 15 +++++------ .../CO2Brine/functions/BrineEnthalpy.cpp | 9 +++---- .../CO2Brine/functions/BrineEnthalpy.hpp | 3 +-- .../CO2Brine/functions/CO2Enthalpy.cpp | 9 +++---- .../CO2Brine/functions/CO2Enthalpy.hpp | 3 +-- .../CO2Brine/functions/CO2Solubility.cpp | 7 +++-- .../CO2Brine/functions/CO2Solubility.hpp | 17 +++++------- .../functions/EzrokhiBrineDensity.cpp | 9 +++---- .../functions/EzrokhiBrineDensity.hpp | 3 +-- .../functions/EzrokhiBrineViscosity.cpp | 7 +++-- .../functions/EzrokhiBrineViscosity.hpp | 3 +-- .../functions/FenghourCO2Viscosity.cpp | 7 +++-- .../functions/FenghourCO2Viscosity.hpp | 3 +-- .../CO2Brine/functions/FlashModelBase.hpp | 12 +++++++-- .../CO2Brine/functions/NoOpPVTFunction.hpp | 5 ++-- .../CO2Brine/functions/PVTFunctionBase.hpp | 27 ++++++++++++------- .../functions/PhillipsBrineDensity.cpp | 7 +++-- .../functions/PhillipsBrineDensity.hpp | 3 +-- .../functions/PhillipsBrineViscosity.cpp | 7 +++-- .../functions/PhillipsBrineViscosity.hpp | 3 +-- .../functions/SpanWagnerCO2Density.cpp | 7 +++-- .../functions/SpanWagnerCO2Density.hpp | 3 +-- .../CO2Brine/functions/WaterDensity.cpp | 7 +++-- .../CO2Brine/functions/WaterDensity.hpp | 3 +-- .../reactive/ReactiveBrineFluid.cpp | 8 +++--- .../dataRepository/ConduitRestart.hpp | 1 - .../fileIO/Table/TableFormatter.cpp | 2 ++ .../fileIO/Table/TableFormatter.hpp | 11 +++++--- .../functions/TableFunction.cpp | 2 -- .../functions/TableFunction.hpp | 12 --------- 31 files changed, 117 insertions(+), 125 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 8f0daec5278..8983b8f4e90 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -335,13 +335,13 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) InputError ); // then, we are ready to instantiate the phase models - bool const writeCSV = !isClone && m_writeCSV; - bool const writeInLog = !isClone && (getLogLevel() >= 0 && logger::internal::rank==0); + PVTFunctionBase::PVTOutputOptions pvtOpts = { + !isClone && m_writeCSV,// writeCSV + !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog + }; - m_phase1 = std::make_unique< PHASE1 >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, - writeCSV, writeInLog ); - m_phase2 = std::make_unique< PHASE2 >( getName() + "_phaseModel2", phase2InputParams, m_componentNames, m_componentMolarWeight, - writeCSV, writeInLog ); + m_phase1 = std::make_unique< PHASE1 >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, pvtOpts ); + m_phase2 = std::make_unique< PHASE2 >( getName() + "_phaseModel2", phase2InputParams, m_componentNames, m_componentMolarWeight, pvtOpts ); // 2) Create the flash model @@ -363,13 +363,16 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) { if( strs[1] == FLASH::catalogName() ) { + FlashModelBase::PVTOutputOptions flashOpts = { + !isClone && m_writeCSV,// writeCSV + !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog + }; m_flash = std::make_unique< FLASH >( getName() + '_' + FLASH::catalogName(), strs, m_phaseNames, m_componentNames, m_componentMolarWeight, - writeCSV, - writeInLog ); + flashOpts ); } } else @@ -405,13 +408,17 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) { strs[2] = m_solubilityTables[0]; } + FlashModelBase::PVTOutputOptions flashOpts = { + !isClone && m_writeCSV,// writeCSV + !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog + }; + m_flash = std::make_unique< FLASH >( getName() + '_' + FLASH::catalogName(), strs, m_phaseNames, m_componentNames, m_componentMolarWeight, - writeCSV, - writeInLog ); + flashOpts ); } GEOS_THROW_IF( m_flash == nullptr, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp index bebf52d1892..b242cd26154 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp @@ -19,6 +19,8 @@ #ifndef GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_PHASEMODEL_HPP_ #define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_PHASEMODEL_HPP_ +#include "functions/PVTFunctionBase.hpp" + namespace geos { @@ -53,31 +55,28 @@ struct PhaseModel * @param[in] inputParams input parameters read from files * @param[in] componentNames names of the components * @param[in] componentMolarWeight molar weights of the components + * @param[in] pvtOpts Struct output options */ PhaseModel( string const & phaseModelName, array1d< array1d< string > > const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ) + geos::constitutive::PVTProps::PVTFunctionBase::PVTOutputOptions pvtOpts ) : density( phaseModelName + "_" + Density::catalogName(), inputParams[InputParamOrder::DENSITY], componentNames, componentMolarWeight, - printInCsv, - printInLog ), + pvtOpts ), viscosity( phaseModelName + "_" + Viscosity::catalogName(), inputParams[InputParamOrder::VISCOSITY], componentNames, componentMolarWeight, - printInCsv, - printInLog ), + pvtOpts ), enthalpy( phaseModelName + "_" + Enthalpy::catalogName(), inputParams[InputParamOrder::ENTHALPY], componentNames, componentMolarWeight, - printInCsv, - printInLog ) + pvtOpts ) {} /// The phase density model diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp index 2b93e14b54f..60aed8c03ee 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp @@ -191,8 +191,7 @@ BrineEnthalpy::BrineEnthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ): + PVTOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -206,8 +205,8 @@ BrineEnthalpy::BrineEnthalpy( string const & name, m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); m_brineEnthalpyTable = makeBrineEnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - checkTableOutput( m_CO2EnthalpyTable, printInCsv, printInLog ); - checkTableOutput( m_brineEnthalpyTable, printInCsv, printInLog ); + handleTableOutputOptions( m_CO2EnthalpyTable, pvtOpts ); + handleTableOutputOptions( m_brineEnthalpyTable, pvtOpts ); } @@ -232,7 +231,7 @@ BrineEnthalpy::createKernelWrapper() const m_waterIndex ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, BrineEnthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, BrineEnthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp index d7c03854216..fe9b1e38758 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp @@ -91,8 +91,7 @@ class BrineEnthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ); + PVTOutputOptions pvtOpts ); static string catalogName() { return "BrineEnthalpy"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp index beda83ad15b..9108a627e57 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp @@ -256,8 +256,7 @@ CO2Enthalpy::CO2Enthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ): + PVTOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -267,8 +266,8 @@ CO2Enthalpy::CO2Enthalpy( string const & name, m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - checkTableOutput( m_CO2EnthalpyTable, printInCsv, printInLog ); - checkTableOutput( m_CO2EnthalpyTable, printInCsv, printInLog ); + handleTableOutputOptions( m_CO2EnthalpyTable, pvtOpts ); + handleTableOutputOptions( m_CO2EnthalpyTable, pvtOpts ); } @@ -310,7 +309,7 @@ CO2Enthalpy::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, CO2Enthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, CO2Enthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp index 035d4b068bd..8620f98a6f4 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp @@ -79,8 +79,7 @@ class CO2Enthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ); + PVTOutputOptions pvtOpts ); static string catalogName() { return "CO2Enthalpy"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp index 6ba9fe83f3d..3c17cece3b4 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp @@ -220,8 +220,7 @@ CO2Solubility::CO2Solubility( string const & name, string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ): + PVTOutputOptions pvtOpts ): FlashModelBase( name, componentNames, componentMolarWeight ) @@ -257,8 +256,8 @@ CO2Solubility::CO2Solubility( string const & name, std::tie( m_CO2SolubilityTable, m_WaterVapourisationTable ) = makeSolubilityTables( m_modelName, inputParams, solubilityModel ); - checkTableOutput( m_CO2SolubilityTable, printInCsv, printInLog ); - checkTableOutput( m_WaterVapourisationTable, printInCsv, printInLog ); + handleTableOutputOptions( m_CO2SolubilityTable, pvtOpts ); + handleTableOutputOptions( m_WaterVapourisationTable, pvtOpts ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp index 42a66eac77e..bd0fbc43ecf 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp @@ -20,7 +20,6 @@ #define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_FUNCTIONS_CO2SOLUBILITY_HPP_ #include "FlashModelBase.hpp" - #include "constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionHelpers.hpp" #include "constitutive/fluid/multifluid/Layouts.hpp" #include "constitutive/fluid/multifluid/MultiFluidUtils.hpp" @@ -117,8 +116,7 @@ class CO2Solubility : public FlashModelBase string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ); + geos::constitutive::PVTProps::FlashModelBase::PVTOutputOptions pvtOpts ); static string catalogName() { return "CO2Solubility"; } @@ -130,19 +128,18 @@ class CO2Solubility : public FlashModelBase void checkTablesParameters( real64 pressure, real64 temperature ) const override final; /** - * @brief Check whether we print to screen or to a csv file - * @param tableData - * @param printInCsv - * @param printInLog + * @brief Print the table(s) in the log and/or CSV files when requested by the user. + * @param tableData The target table to be printed + * @param pvtOpts Struct containing output options */ - void checkTableOutput( TableFunction const * tableData, bool const printInCsv, bool const printInLog ) + void handleTableOutputOptions( TableFunction const * tableData, PVTOutputOptions pvtOpts ) { - if( printInLog && tableData->numDimensions() <= 2 ) + if( pvtOpts.writeInLog && tableData->numDimensions() <= 2 ) { TableTextFormatter textFormatter; GEOS_LOG_RANK_0( textFormatter.toString( *tableData )); } - if( printInCsv || ( printInLog && tableData->numDimensions() >= 3 ) ) + if( pvtOpts.writeCSV || ( pvtOpts.writeInLog && tableData->numDimensions() >= 3 ) ) { string const filename = tableData->getName(); std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp index bdb752f90c1..2d259fe59f3 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp @@ -37,8 +37,7 @@ EzrokhiBrineDensity::EzrokhiBrineDensity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ): + PVTOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -53,8 +52,8 @@ EzrokhiBrineDensity::EzrokhiBrineDensity( string const & name, m_waterSatDensityTable = PureWaterProperties::makeSaturationDensityTable( m_functionName, FunctionManager::getInstance() ); m_waterSatPressureTable = PureWaterProperties::makeSaturationPressureTable( m_functionName, FunctionManager::getInstance() ); - checkTableOutput( m_waterSatPressureTable, printInCsv, printInLog ); - checkTableOutput( m_waterSatDensityTable, printInCsv, printInLog ); + handleTableOutputOptions( m_waterSatPressureTable, pvtOpts ); + handleTableOutputOptions( m_waterSatDensityTable, pvtOpts ); } void EzrokhiBrineDensity::makeCoefficients( string_array const & inputPara ) @@ -101,7 +100,7 @@ EzrokhiBrineDensity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp index 6b32afd06c6..ad6dcd6bd4e 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp @@ -108,8 +108,7 @@ class EzrokhiBrineDensity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ); + PVTOutputOptions pvtOpts ); virtual ~EzrokhiBrineDensity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp index ad601ccdfea..ef8e57cbdca 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp @@ -37,8 +37,7 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ): + PVTOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -52,7 +51,7 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, makeCoefficients( inputPara ); m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); - checkTableOutput( m_waterViscosityTable, printInCsv, printInLog ); + handleTableOutputOptions( m_waterViscosityTable, pvtOpts ); } void EzrokhiBrineViscosity::makeCoefficients( string_array const & inputPara ) @@ -94,7 +93,7 @@ EzrokhiBrineViscosity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp index bf594c814f6..30f5359d2a7 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp @@ -97,8 +97,7 @@ class EzrokhiBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ); + PVTOutputOptions pvtOpts ); virtual ~EzrokhiBrineViscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp index 5c21be4c08c..b7b48d348ab 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp @@ -141,15 +141,14 @@ FenghourCO2Viscosity::FenghourCO2Viscosity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ) + PVTOutputOptions pvtOpts ) : PVTFunctionBase( name, componentNames, componentMolarWeight ) { m_CO2ViscosityTable = makeViscosityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - checkTableOutput( m_CO2ViscosityTable, printInCsv, printInLog ); + handleTableOutputOptions( m_CO2ViscosityTable, pvtOpts ); } void FenghourCO2Viscosity::checkTablesParameters( real64 const pressure, @@ -166,7 +165,7 @@ FenghourCO2Viscosity::createKernelWrapper() const *m_CO2ViscosityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, FenghourCO2Viscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, FenghourCO2Viscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp index f766849c069..e3c760fed9d 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp @@ -75,8 +75,7 @@ class FenghourCO2Viscosity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ); + PVTOutputOptions pvtOpts ); virtual ~FenghourCO2Viscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp index f183d8e9618..a46e5a06c6d 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp @@ -77,14 +77,22 @@ class FlashModelBase virtual ~FlashModelBase() = default; + /// Struct containing output options + struct PVTOutputOptions + { + /// Output PVT in CSV file + bool writeCSV; + /// Output PVT in log + bool writeInLog; + }; + using CatalogInterface = dataRepository::CatalogInterface< FlashModelBase, string const &, string_array const &, string_array const &, string_array const &, array1d< real64 > const &, - bool const, - bool const >; + PVTOutputOptions >; static typename CatalogInterface::CatalogType & getCatalog() { static CatalogInterface::CatalogType catalog; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp index 02a43ace0f8..6b00e3e9560 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp @@ -70,13 +70,12 @@ class NoOpPVTFunction : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ) + PVTOutputOptions pvtOpts ) : PVTFunctionBase( name, componentNames, componentMolarWeight ) { - GEOS_UNUSED_VAR( inputPara, printInCsv, printInLog ); + GEOS_UNUSED_VAR( inputPara, pvtOpts ); } virtual ~NoOpPVTFunction() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index c3c50389833..d115ae0adf3 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -114,13 +114,23 @@ class PVTFunctionBase virtual ~PVTFunctionBase() = default; + + /// Struct containing output options + struct PVTOutputOptions + { + /// Output PVT in CSV file + bool writeCSV; + /// Output PVT in log + bool writeInLog; + }; + + using CatalogInterface = dataRepository::CatalogInterface< PVTFunctionBase, string const &, array1d< string > const &, array1d< string > const &, array1d< real64 > const &, - bool const, - bool const >; + PVTOutputOptions >; static typename CatalogInterface::CatalogType & getCatalog() { static CatalogInterface::CatalogType catalog; @@ -142,20 +152,19 @@ class PVTFunctionBase virtual void checkTablesParameters( real64 pressure, real64 temperature ) const = 0; /** - * @brief Check if the log should be printed on log (standard output) and/or CSV files - * @param table The target table to be printed - * @param printInCsv Boolean for printing in CSV - * @param printInLog Boolean for printing in Log + * @brief Print the table(s) in the log and/or CSV files when requested by the user. + * @param tableData The target table to be printed + * @param pvtOpts Struct containing output options */ - void checkTableOutput( TableFunction const * tableData, bool const printInCsv, bool const printInLog ) + void handleTableOutputOptions( TableFunction const * tableData, PVTOutputOptions pvtOpts ) { - if( printInLog && tableData->numDimensions() <= 2 ) + if( pvtOpts.writeInLog && tableData->numDimensions() <= 2 ) { TableTextFormatter textFormatter; GEOS_LOG_RANK_0( textFormatter.toString( *tableData )); } - if( printInCsv || ( printInLog && tableData->numDimensions() >= 3 ) ) + if( pvtOpts.writeCSV || ( pvtOpts.writeInLog && tableData->numDimensions() >= 3 ) ) { string const filename = tableData->getName(); std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp index 9f596a67114..9752ad19350 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp @@ -176,8 +176,7 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ): + PVTOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -190,7 +189,7 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, m_brineDensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - checkTableOutput( m_brineDensityTable, printInCsv, printInLog ); + handleTableOutputOptions( m_brineDensityTable, pvtOpts ); } PhillipsBrineDensity::KernelWrapper @@ -209,7 +208,7 @@ void PhillipsBrineDensity::checkTablesParameters( real64 const pressure, m_brineDensityTable->checkCoord( temperature, 1 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp index efc6dee2549..b464dc5a07b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp @@ -85,8 +85,7 @@ class PhillipsBrineDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ); + PVTOutputOptions pvtOpts ); static string catalogName() { return "PhillipsBrineDensity"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp index e1ef7fa085e..f5db1c82014 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp @@ -36,8 +36,7 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ): + PVTOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -45,7 +44,7 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); makeCoefficients( inputPara ); - checkTableOutput( m_waterViscosityTable, printInCsv, printInLog ); + handleTableOutputOptions( m_waterViscosityTable, pvtOpts ); } void PhillipsBrineViscosity::makeCoefficients( string_array const & inputPara ) @@ -92,7 +91,7 @@ PhillipsBrineViscosity::createKernelWrapper() const m_coef1 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp index 24983952936..f31f7f016fd 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp @@ -83,8 +83,7 @@ class PhillipsBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ); + PVTOutputOptions pvtOpts ); virtual ~PhillipsBrineViscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp index 33f02a73ba3..7c88fc484be 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp @@ -278,8 +278,7 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ): + PVTOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -289,7 +288,7 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, m_CO2DensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - checkTableOutput( m_CO2DensityTable, printInCsv, printInLog ); + handleTableOutputOptions( m_CO2DensityTable, pvtOpts ); } void SpanWagnerCO2Density::checkTablesParameters( real64 const pressure, @@ -307,7 +306,7 @@ SpanWagnerCO2Density::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, SpanWagnerCO2Density, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, SpanWagnerCO2Density, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp index 85cf54a7aa0..f1ff891969b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp @@ -80,8 +80,7 @@ class SpanWagnerCO2Density : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ); + PVTOutputOptions pvtOpts ); static string catalogName() { return "SpanWagnerCO2Density"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp index 5a86df14359..9f2035c21ed 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp @@ -36,8 +36,7 @@ WaterDensity::WaterDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ): + PVTOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -45,7 +44,7 @@ WaterDensity::WaterDensity( string const & name, GEOS_UNUSED_VAR( inputParams ); m_waterDensityTable = PureWaterProperties::makeSaturationDensityTable( m_functionName, FunctionManager::getInstance() ); - checkTableOutput( m_waterDensityTable, printInCsv, printInLog ); + handleTableOutputOptions( m_waterDensityTable, pvtOpts ); } void WaterDensity::checkTablesParameters( real64 const pressure, @@ -62,7 +61,7 @@ WaterDensity::createKernelWrapper() const *m_waterDensityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, WaterDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, bool const, bool const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, WaterDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp index 6abd4412deb..afb4de2613c 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp @@ -75,8 +75,7 @@ class WaterDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - bool const printInCsv, - bool const printInLog ); + PVTOutputOptions pvtOpts ); static string catalogName() { return "WaterDensity"; } virtual string getCatalogName() const final { return catalogName(); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp index 504dd10820c..408f3411eba 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp @@ -204,12 +204,14 @@ void ReactiveBrineFluid< PHASE > ::createPVTModels( bool isClone ) GEOS_FMT( "{}: PVT model {} not found in input files", getFullName(), PHASE::Enthalpy::catalogName() ), InputError ); - bool const writeCSV = !isClone && m_writeCSV; - bool const writeInLog = !isClone && (getLogLevel() > 0 && logger::internal::rank==0); + PVTFunctionBase::PVTOutputOptions pvtOpts = { + !isClone && m_writeCSV,// writeCSV + !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog + }; // then, we are ready to instantiate the phase models m_phase = std::make_unique< PHASE >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, - writeCSV, writeInLog ); + pvtOpts ); } template< typename PHASE > diff --git a/src/coreComponents/dataRepository/ConduitRestart.hpp b/src/coreComponents/dataRepository/ConduitRestart.hpp index 360bc673871..feb6ab216ca 100644 --- a/src/coreComponents/dataRepository/ConduitRestart.hpp +++ b/src/coreComponents/dataRepository/ConduitRestart.hpp @@ -55,7 +55,6 @@ struct conduitTypeInfo {}; // Native integer types -CONDUIT_TYPE_INFO( bool, CONDUIT_NATIVE_UNSIGNED_CHAR ); CONDUIT_TYPE_INFO( char, CONDUIT_NATIVE_CHAR ); CONDUIT_TYPE_INFO( signed char, CONDUIT_NATIVE_SIGNED_CHAR ); CONDUIT_TYPE_INFO( unsigned char, CONDUIT_NATIVE_UNSIGNED_CHAR ); diff --git a/src/coreComponents/fileIO/Table/TableFormatter.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index 8b79a1f07a3..6ef7383f605 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -17,6 +17,8 @@ */ #include "TableFormatter.hpp" +#include +#include "codingUtilities/StringUtilities.hpp" namespace geos { diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 5293b980efe..7ba8f94b1da 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -22,8 +22,7 @@ #include "TableData.hpp" #include "TableLayout.hpp" #include "common/Units.hpp" -#include -#include "codingUtilities/StringUtilities.hpp" + namespace geos { @@ -63,7 +62,9 @@ class TableCSVFormatter : public TableFormatter /** * @brief Construct a new Table Formatter */ - TableCSVFormatter(): TableFormatter( TableLayout()) {} + TableCSVFormatter(): + TableFormatter( TableLayout() ) + {} /** * @brief Construct a new Table Formatter from a tableLayout @@ -119,7 +120,9 @@ class TableTextFormatter : public TableFormatter /** * @brief Construct a new TableFormatter */ - TableTextFormatter(): TableFormatter( TableLayout()) {} + TableTextFormatter(): + TableFormatter( TableLayout() ) + {} /** * @brief Construct a new TableFormatter from a tableLayout diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index e9b4ccf4f96..d8ee23a7b82 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -17,8 +17,6 @@ */ #include "TableFunction.hpp" -#include "fileIO/Table/TableData.hpp" -#include "fileIO/Table/TableLayout.hpp" #include "codingUtilities/Parsing.hpp" #include "common/DataTypes.hpp" #include diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index 91cac4ed2d5..fd37bfe36bb 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -239,18 +239,6 @@ class TableFunction : public FunctionBase */ void checkCoord( real64 coord, localIndex dim ) const; - // /** - // * @brief Print table into a CSV file - // * @param filename Filename for output - // */ - // void printInCSV( string const & filename ) const; - - // /** - // * @brief Print table to the log (only 1d and 2d tables are supported). - // * @param filename Filename for output - // */ - // void printInLog( string const & filename ) const; - /** * @brief @return Number of table dimensions */ From 28b68f09fe372b4a2a141a5edd07051852d725f0 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 14 Jun 2024 15:34:43 +0200 Subject: [PATCH 129/216] missing test correction --- .../constitutiveTests/testCO2BrinePVTModels.cpp | 16 +++++++++++----- .../testCO2SpycherPruessModels.cpp | 8 ++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp index db3ae90750b..170da4fd48a 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp @@ -360,14 +360,18 @@ std::unique_ptr< MODEL > makePVTFunction( string const & filename, { array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( str ); + PVTFunctionBase::PVTOutputOptions pvtOpts = { + true,// writeCSV + true, // writeInLog + }; + if( strs.size()>1 && strs[0] == key ) { pvtFunction = std::make_unique< MODEL >( strs[1], strs, componentNames, componentMolarWeight, - true,// print PVT tables - true ); + pvtOpts ); } } GEOS_ERROR_IF( pvtFunction == nullptr, @@ -401,7 +405,10 @@ std::unique_ptr< MODEL > makeFlashModel( string const & filename, while( std::getline( is, str ) ) { array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( str ); - + FlashModelBase::PVTOutputOptions flashOpts = { + true, // writeCSV + true, // writeInLog + }; if( strs.size()>1 && strs[0] == key ) { flashModel = std::make_unique< MODEL >( strs[1], @@ -409,8 +416,7 @@ std::unique_ptr< MODEL > makeFlashModel( string const & filename, phaseNames, componentNames, componentMolarWeight, - true, // print PVT tables - true ); + flashOpts); } } GEOS_ERROR_IF( flashModel == nullptr, diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp index 95e5b003ec8..2517eb978d5 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp @@ -82,13 +82,17 @@ CO2SolubilitySpycherPruessTestFixture::makeFlashModel( string const & fileConten // Read file parameters array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( fileContent ); + FlashModelBase::PVTOutputOptions flashOpts = { + false, // writeCSV + false, // writeInLog + }; + return std::make_unique< CO2Solubility >( strs[1], strs, phaseNames, componentNames, componentMolarWeight, - false, - false ); + flashOpts ); } TEST_P( CO2SolubilitySpycherPruessTestFixture, testExpectedValues ) From 7f1b8ab699288d6efec9c5d8938b24a274195ecc Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 14 Jun 2024 16:39:36 +0200 Subject: [PATCH 130/216] pvtOpt struct renaming + fct move to FlashModel --- .../multifluid/CO2Brine/CO2BrineFluid.cpp | 6 ++-- .../fluid/multifluid/CO2Brine/PhaseModel.hpp | 2 +- .../CO2Brine/functions/BrineEnthalpy.cpp | 4 +-- .../CO2Brine/functions/BrineEnthalpy.hpp | 2 +- .../CO2Brine/functions/CO2Enthalpy.cpp | 4 +-- .../CO2Brine/functions/CO2Enthalpy.hpp | 2 +- .../CO2Brine/functions/CO2Solubility.cpp | 2 +- .../CO2Brine/functions/CO2Solubility.hpp | 27 +--------------- .../functions/EzrokhiBrineDensity.cpp | 4 +-- .../functions/EzrokhiBrineDensity.hpp | 2 +- .../functions/EzrokhiBrineViscosity.cpp | 4 +-- .../functions/EzrokhiBrineViscosity.hpp | 2 +- .../functions/FenghourCO2Viscosity.cpp | 4 +-- .../functions/FenghourCO2Viscosity.hpp | 2 +- .../CO2Brine/functions/FlashModelBase.hpp | 31 +++++++++++++++++-- .../CO2Brine/functions/NoOpPVTFunction.hpp | 2 +- .../CO2Brine/functions/PVTFunctionBase.hpp | 6 ++-- .../functions/PhillipsBrineDensity.cpp | 4 +-- .../functions/PhillipsBrineDensity.hpp | 2 +- .../functions/PhillipsBrineViscosity.cpp | 4 +-- .../functions/PhillipsBrineViscosity.hpp | 2 +- .../functions/SpanWagnerCO2Density.cpp | 4 +-- .../functions/SpanWagnerCO2Density.hpp | 2 +- .../CO2Brine/functions/WaterDensity.cpp | 4 +-- .../CO2Brine/functions/WaterDensity.hpp | 2 +- .../reactive/ReactiveBrineFluid.cpp | 2 +- .../functions/TableFunction.hpp | 2 +- .../testCO2BrinePVTModels.cpp | 16 +++++----- .../testCO2SpycherPruessModels.cpp | 2 +- 29 files changed, 77 insertions(+), 75 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 8983b8f4e90..5c71cdff9ee 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -335,7 +335,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) InputError ); // then, we are ready to instantiate the phase models - PVTFunctionBase::PVTOutputOptions pvtOpts = { + PVTFunctionBase::TableOutputOptions pvtOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog }; @@ -363,7 +363,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) { if( strs[1] == FLASH::catalogName() ) { - FlashModelBase::PVTOutputOptions flashOpts = { + FlashModelBase::TableOutputOptions flashOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog }; @@ -408,7 +408,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) { strs[2] = m_solubilityTables[0]; } - FlashModelBase::PVTOutputOptions flashOpts = { + FlashModelBase::TableOutputOptions flashOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog }; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp index b242cd26154..7cab79bd0f2 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp @@ -61,7 +61,7 @@ struct PhaseModel array1d< array1d< string > > const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - geos::constitutive::PVTProps::PVTFunctionBase::PVTOutputOptions pvtOpts ) + geos::constitutive::PVTProps::PVTFunctionBase::TableOutputOptions pvtOpts ) : density( phaseModelName + "_" + Density::catalogName(), inputParams[InputParamOrder::DENSITY], componentNames, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp index 60aed8c03ee..ae0e5263cc1 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp @@ -191,7 +191,7 @@ BrineEnthalpy::BrineEnthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ): + TableOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -231,7 +231,7 @@ BrineEnthalpy::createKernelWrapper() const m_waterIndex ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, BrineEnthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, BrineEnthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp index fe9b1e38758..e85cbd3d58e 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp @@ -91,7 +91,7 @@ class BrineEnthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ); + TableOutputOptions pvtOpts ); static string catalogName() { return "BrineEnthalpy"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp index 9108a627e57..bbe65ca484c 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp @@ -256,7 +256,7 @@ CO2Enthalpy::CO2Enthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ): + TableOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -309,7 +309,7 @@ CO2Enthalpy::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, CO2Enthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, CO2Enthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp index 8620f98a6f4..23106d5519f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp @@ -79,7 +79,7 @@ class CO2Enthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ); + TableOutputOptions pvtOpts ); static string catalogName() { return "CO2Enthalpy"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp index 3c17cece3b4..589d329dac3 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp @@ -220,7 +220,7 @@ CO2Solubility::CO2Solubility( string const & name, string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ): + TableOutputOptions pvtOpts ): FlashModelBase( name, componentNames, componentMolarWeight ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp index bd0fbc43ecf..6ff83c5ee06 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp @@ -116,7 +116,7 @@ class CO2Solubility : public FlashModelBase string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - geos::constitutive::PVTProps::FlashModelBase::PVTOutputOptions pvtOpts ); + geos::constitutive::PVTProps::FlashModelBase::TableOutputOptions pvtOpts ); static string catalogName() { return "CO2Solubility"; } @@ -127,31 +127,6 @@ class CO2Solubility : public FlashModelBase */ void checkTablesParameters( real64 pressure, real64 temperature ) const override final; - /** - * @brief Print the table(s) in the log and/or CSV files when requested by the user. - * @param tableData The target table to be printed - * @param pvtOpts Struct containing output options - */ - void handleTableOutputOptions( TableFunction const * tableData, PVTOutputOptions pvtOpts ) - { - if( pvtOpts.writeInLog && tableData->numDimensions() <= 2 ) - { - TableTextFormatter textFormatter; - GEOS_LOG_RANK_0( textFormatter.toString( *tableData )); - } - if( pvtOpts.writeCSV || ( pvtOpts.writeInLog && tableData->numDimensions() >= 3 ) ) - { - string const filename = tableData->getName(); - std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); - GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to inputFiles/compositionalMultiphaseWell/{}/{}.csv \n", - OutputBase::getOutputDirectory(), - filename )); - - TableCSVFormatter csvFormatter; - logStream << csvFormatter.toString( *tableData ); - } - } - /// Type of kernel wrapper for in-kernel update using KernelWrapper = CO2SolubilityUpdate; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp index 2d259fe59f3..96e6f598bdb 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp @@ -37,7 +37,7 @@ EzrokhiBrineDensity::EzrokhiBrineDensity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ): + TableOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -100,7 +100,7 @@ EzrokhiBrineDensity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp index ad6dcd6bd4e..d8529eb71c6 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp @@ -108,7 +108,7 @@ class EzrokhiBrineDensity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ); + TableOutputOptions pvtOpts ); virtual ~EzrokhiBrineDensity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp index ef8e57cbdca..2c2b04e355a 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp @@ -37,7 +37,7 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ): + TableOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -93,7 +93,7 @@ EzrokhiBrineViscosity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp index 30f5359d2a7..aade8e1be43 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp @@ -97,7 +97,7 @@ class EzrokhiBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ); + TableOutputOptions pvtOpts ); virtual ~EzrokhiBrineViscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp index b7b48d348ab..5664dbdd8c1 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp @@ -141,7 +141,7 @@ FenghourCO2Viscosity::FenghourCO2Viscosity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ) + TableOutputOptions pvtOpts ) : PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -165,7 +165,7 @@ FenghourCO2Viscosity::createKernelWrapper() const *m_CO2ViscosityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, FenghourCO2Viscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, FenghourCO2Viscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp index e3c760fed9d..30fe382c5e6 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp @@ -75,7 +75,7 @@ class FenghourCO2Viscosity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ); + TableOutputOptions pvtOpts ); virtual ~FenghourCO2Viscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp index a46e5a06c6d..42d35493458 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp @@ -20,6 +20,8 @@ #define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_FUNCTIONS_FLASHMODELBASE_HPP_ #include "dataRepository/ObjectCatalog.hpp" +#include "fileIO/Outputs/OutputBase.hpp" +#include "functions/TableFunction.hpp" namespace geos { @@ -78,7 +80,7 @@ class FlashModelBase virtual ~FlashModelBase() = default; /// Struct containing output options - struct PVTOutputOptions + struct TableOutputOptions { /// Output PVT in CSV file bool writeCSV; @@ -92,7 +94,7 @@ class FlashModelBase string_array const &, string_array const &, array1d< real64 > const &, - PVTOutputOptions >; + TableOutputOptions >; static typename CatalogInterface::CatalogType & getCatalog() { static CatalogInterface::CatalogType catalog; @@ -109,6 +111,31 @@ class FlashModelBase */ virtual void checkTablesParameters( real64 pressure, real64 temperature ) const = 0; + /** + * @brief Print the table(s) in the log and/or CSV files when requested by the user. + * @param tableData The target table to be printed + * @param pvtOpts Struct containing output options + */ + void handleTableOutputOptions( TableFunction const * tableData, TableOutputOptions pvtOpts ) + { + if( pvtOpts.writeInLog && tableData->numDimensions() <= 2 ) + { + TableTextFormatter textFormatter; + GEOS_LOG_RANK_0( textFormatter.toString( *tableData )); + } + if( pvtOpts.writeCSV || ( pvtOpts.writeInLog && tableData->numDimensions() >= 3 ) ) + { + string const filename = tableData->getName(); + std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); + GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to inputFiles/compositionalMultiphaseWell/{}/{}.csv \n", + OutputBase::getOutputDirectory(), + filename )); + + TableCSVFormatter csvFormatter; + logStream << csvFormatter.toString( *tableData ); + } + } + string const & flashModelName() const { return m_modelName; } protected: diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp index 6b00e3e9560..dce0837e078 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp @@ -70,7 +70,7 @@ class NoOpPVTFunction : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ) + TableOutputOptions pvtOpts ) : PVTFunctionBase( name, componentNames, componentMolarWeight ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index d115ae0adf3..5c7a0eeaa24 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -116,7 +116,7 @@ class PVTFunctionBase /// Struct containing output options - struct PVTOutputOptions + struct TableOutputOptions { /// Output PVT in CSV file bool writeCSV; @@ -130,7 +130,7 @@ class PVTFunctionBase array1d< string > const &, array1d< string > const &, array1d< real64 > const &, - PVTOutputOptions >; + TableOutputOptions >; static typename CatalogInterface::CatalogType & getCatalog() { static CatalogInterface::CatalogType catalog; @@ -156,7 +156,7 @@ class PVTFunctionBase * @param tableData The target table to be printed * @param pvtOpts Struct containing output options */ - void handleTableOutputOptions( TableFunction const * tableData, PVTOutputOptions pvtOpts ) + void handleTableOutputOptions( TableFunction const * tableData, TableOutputOptions pvtOpts ) { if( pvtOpts.writeInLog && tableData->numDimensions() <= 2 ) { diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp index 9752ad19350..9d3373eb54e 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp @@ -176,7 +176,7 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ): + TableOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -208,7 +208,7 @@ void PhillipsBrineDensity::checkTablesParameters( real64 const pressure, m_brineDensityTable->checkCoord( temperature, 1 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp index b464dc5a07b..325e452d3db 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp @@ -85,7 +85,7 @@ class PhillipsBrineDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ); + TableOutputOptions pvtOpts ); static string catalogName() { return "PhillipsBrineDensity"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp index f5db1c82014..a5efc57385d 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp @@ -36,7 +36,7 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ): + TableOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -91,7 +91,7 @@ PhillipsBrineViscosity::createKernelWrapper() const m_coef1 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp index f31f7f016fd..f4826ff5086 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp @@ -83,7 +83,7 @@ class PhillipsBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ); + TableOutputOptions pvtOpts ); virtual ~PhillipsBrineViscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp index 7c88fc484be..75fd4691ef6 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp @@ -278,7 +278,7 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ): + TableOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -306,7 +306,7 @@ SpanWagnerCO2Density::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, SpanWagnerCO2Density, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, SpanWagnerCO2Density, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp index f1ff891969b..873777c3b79 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp @@ -80,7 +80,7 @@ class SpanWagnerCO2Density : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ); + TableOutputOptions pvtOpts ); static string catalogName() { return "SpanWagnerCO2Density"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp index 9f2035c21ed..dd7604c3865 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp @@ -36,7 +36,7 @@ WaterDensity::WaterDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ): + TableOutputOptions pvtOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -61,7 +61,7 @@ WaterDensity::createKernelWrapper() const *m_waterDensityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, WaterDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::PVTOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, WaterDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp index afb4de2613c..2d8cbcd3722 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp @@ -75,7 +75,7 @@ class WaterDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTOutputOptions pvtOpts ); + TableOutputOptions pvtOpts ); static string catalogName() { return "WaterDensity"; } virtual string getCatalogName() const final { return catalogName(); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp index 408f3411eba..2556284ef78 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp @@ -204,7 +204,7 @@ void ReactiveBrineFluid< PHASE > ::createPVTModels( bool isClone ) GEOS_FMT( "{}: PVT model {} not found in input files", getFullName(), PHASE::Enthalpy::catalogName() ), InputError ); - PVTFunctionBase::PVTOutputOptions pvtOpts = { + PVTFunctionBase::TableOutputOptions pvtOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog }; diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index fd37bfe36bb..03062c77aec 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -321,7 +321,7 @@ class TableFunction : public FunctionBase } /** - * @return The unit of the table values + * @return The table unit */ units::Unit getValueUnit() const { diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp index 170da4fd48a..110b132cdd0 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp @@ -360,9 +360,9 @@ std::unique_ptr< MODEL > makePVTFunction( string const & filename, { array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( str ); - PVTFunctionBase::PVTOutputOptions pvtOpts = { - true,// writeCSV - true, // writeInLog + PVTFunctionBase::TableOutputOptions pvtOpts = { + true,// writeCSV + true, // writeInLog }; if( strs.size()>1 && strs[0] == key ) @@ -405,10 +405,10 @@ std::unique_ptr< MODEL > makeFlashModel( string const & filename, while( std::getline( is, str ) ) { array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( str ); - FlashModelBase::PVTOutputOptions flashOpts = { - true, // writeCSV - true, // writeInLog - }; + FlashModelBase::TableOutputOptions flashOpts = { + true, // writeCSV + true, // writeInLog + }; if( strs.size()>1 && strs[0] == key ) { flashModel = std::make_unique< MODEL >( strs[1], @@ -416,7 +416,7 @@ std::unique_ptr< MODEL > makeFlashModel( string const & filename, phaseNames, componentNames, componentMolarWeight, - flashOpts); + flashOpts ); } } GEOS_ERROR_IF( flashModel == nullptr, diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp index 2517eb978d5..72a948e8f8a 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp @@ -82,7 +82,7 @@ CO2SolubilitySpycherPruessTestFixture::makeFlashModel( string const & fileConten // Read file parameters array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( fileContent ); - FlashModelBase::PVTOutputOptions flashOpts = { + FlashModelBase::TableOutputOptions flashOpts = { false, // writeCSV false, // writeInLog }; From 3da5e829a1ee149e4cd53c35bad488267576544c Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 14 Jun 2024 16:54:42 +0200 Subject: [PATCH 131/216] xsd/rst generation --- .../schema/docs/CO2BrineEzrokhiFluid.rst | 1 + .../docs/CO2BrineEzrokhiThermalFluid.rst | 1 + .../schema/docs/CO2BrinePhillipsFluid.rst | 1 + .../docs/CO2BrinePhillipsThermalFluid.rst | 1 + .../docs/HydrofractureInitialization.rst | 12 ++++++++++ .../HydrofractureInitialization_other.rst | 9 ++++++++ .../schema/docs/ReactiveBrine.rst | 1 + .../schema/docs/ReactiveBrineThermal.rst | 1 + src/coreComponents/schema/docs/Tasks.rst | 1 + .../schema/docs/Tasks_other.rst | 1 + src/coreComponents/schema/schema.xsd | 23 +++++++++++++++---- src/coreComponents/schema/schema.xsd.other | 2 ++ src/docs/sphinx/CompleteXMLSchema.rst | 14 +++++++++++ 13 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 src/coreComponents/schema/docs/HydrofractureInitialization.rst create mode 100644 src/coreComponents/schema/docs/HydrofractureInitialization_other.rst diff --git a/src/coreComponents/schema/docs/CO2BrineEzrokhiFluid.rst b/src/coreComponents/schema/docs/CO2BrineEzrokhiFluid.rst index 8d5cb05986a..bbd0e58f1af 100644 --- a/src/coreComponents/schema/docs/CO2BrineEzrokhiFluid.rst +++ b/src/coreComponents/schema/docs/CO2BrineEzrokhiFluid.rst @@ -12,6 +12,7 @@ name groupName required A name is required for any non- phaseNames groupNameRef_array {} List of fluid phases phasePVTParaFiles path_array required Names of the files defining the parameters of the viscosity and density models solubilityTableNames string_array {} Names of solubility tables for each phase +writeCSV integer 1 Write PVT tables into a CSV file ==================== ================== ======== ============================================================================================================ diff --git a/src/coreComponents/schema/docs/CO2BrineEzrokhiThermalFluid.rst b/src/coreComponents/schema/docs/CO2BrineEzrokhiThermalFluid.rst index 8d5cb05986a..bbd0e58f1af 100644 --- a/src/coreComponents/schema/docs/CO2BrineEzrokhiThermalFluid.rst +++ b/src/coreComponents/schema/docs/CO2BrineEzrokhiThermalFluid.rst @@ -12,6 +12,7 @@ name groupName required A name is required for any non- phaseNames groupNameRef_array {} List of fluid phases phasePVTParaFiles path_array required Names of the files defining the parameters of the viscosity and density models solubilityTableNames string_array {} Names of solubility tables for each phase +writeCSV integer 1 Write PVT tables into a CSV file ==================== ================== ======== ============================================================================================================ diff --git a/src/coreComponents/schema/docs/CO2BrinePhillipsFluid.rst b/src/coreComponents/schema/docs/CO2BrinePhillipsFluid.rst index 8d5cb05986a..bbd0e58f1af 100644 --- a/src/coreComponents/schema/docs/CO2BrinePhillipsFluid.rst +++ b/src/coreComponents/schema/docs/CO2BrinePhillipsFluid.rst @@ -12,6 +12,7 @@ name groupName required A name is required for any non- phaseNames groupNameRef_array {} List of fluid phases phasePVTParaFiles path_array required Names of the files defining the parameters of the viscosity and density models solubilityTableNames string_array {} Names of solubility tables for each phase +writeCSV integer 1 Write PVT tables into a CSV file ==================== ================== ======== ============================================================================================================ diff --git a/src/coreComponents/schema/docs/CO2BrinePhillipsThermalFluid.rst b/src/coreComponents/schema/docs/CO2BrinePhillipsThermalFluid.rst index 8d5cb05986a..bbd0e58f1af 100644 --- a/src/coreComponents/schema/docs/CO2BrinePhillipsThermalFluid.rst +++ b/src/coreComponents/schema/docs/CO2BrinePhillipsThermalFluid.rst @@ -12,6 +12,7 @@ name groupName required A name is required for any non- phaseNames groupNameRef_array {} List of fluid phases phasePVTParaFiles path_array required Names of the files defining the parameters of the viscosity and density models solubilityTableNames string_array {} Names of solubility tables for each phase +writeCSV integer 1 Write PVT tables into a CSV file ==================== ================== ======== ============================================================================================================ diff --git a/src/coreComponents/schema/docs/HydrofractureInitialization.rst b/src/coreComponents/schema/docs/HydrofractureInitialization.rst new file mode 100644 index 00000000000..18e3a0dd9e7 --- /dev/null +++ b/src/coreComponents/schema/docs/HydrofractureInitialization.rst @@ -0,0 +1,12 @@ + + +============================ ============ ======== =========================================== +Name Type Default Description +============================ ============ ======== =========================================== +logLevel integer 0 Log level +name groupName required A name is required for any non-unique nodes +poromechanicsSolverName groupNameRef required Name of the poromechanics solver +solidMechanicsStatisticsName groupNameRef Name of the solid mechanics statistics +============================ ============ ======== =========================================== + + diff --git a/src/coreComponents/schema/docs/HydrofractureInitialization_other.rst b/src/coreComponents/schema/docs/HydrofractureInitialization_other.rst new file mode 100644 index 00000000000..adf1c1b8aec --- /dev/null +++ b/src/coreComponents/schema/docs/HydrofractureInitialization_other.rst @@ -0,0 +1,9 @@ + + +==== ==== ============================ +Name Type Description +==== ==== ============================ + (no documentation available) +==== ==== ============================ + + diff --git a/src/coreComponents/schema/docs/ReactiveBrine.rst b/src/coreComponents/schema/docs/ReactiveBrine.rst index d710c396a38..9d0af7f1a17 100644 --- a/src/coreComponents/schema/docs/ReactiveBrine.rst +++ b/src/coreComponents/schema/docs/ReactiveBrine.rst @@ -9,6 +9,7 @@ componentNames string_array {} List of component names name groupName required A name is required for any non-unique nodes phaseNames groupNameRef_array {} List of fluid phases phasePVTParaFiles path_array required Names of the files defining the parameters of the viscosity and density models +writeCSV integer 0 Write PVT tables into a CSV file ==================== ================== ======== ============================================================================================================ diff --git a/src/coreComponents/schema/docs/ReactiveBrineThermal.rst b/src/coreComponents/schema/docs/ReactiveBrineThermal.rst index d710c396a38..9d0af7f1a17 100644 --- a/src/coreComponents/schema/docs/ReactiveBrineThermal.rst +++ b/src/coreComponents/schema/docs/ReactiveBrineThermal.rst @@ -9,6 +9,7 @@ componentNames string_array {} List of component names name groupName required A name is required for any non-unique nodes phaseNames groupNameRef_array {} List of fluid phases phasePVTParaFiles path_array required Names of the files defining the parameters of the viscosity and density models +writeCSV integer 0 Write PVT tables into a CSV file ==================== ================== ======== ============================================================================================================ diff --git a/src/coreComponents/schema/docs/Tasks.rst b/src/coreComponents/schema/docs/Tasks.rst index 95301497c5c..d6225666e9f 100644 --- a/src/coreComponents/schema/docs/Tasks.rst +++ b/src/coreComponents/schema/docs/Tasks.rst @@ -5,6 +5,7 @@ Name Type Default Descrip =========================================================== ==== ======= ====================================================================== CompositionalMultiphaseReservoirPoromechanicsInitialization node :ref:`XML_CompositionalMultiphaseReservoirPoromechanicsInitialization` CompositionalMultiphaseStatistics node :ref:`XML_CompositionalMultiphaseStatistics` +HydrofractureInitialization node :ref:`XML_HydrofractureInitialization` MultiphasePoromechanicsInitialization node :ref:`XML_MultiphasePoromechanicsInitialization` PVTDriver node :ref:`XML_PVTDriver` PackCollection node :ref:`XML_PackCollection` diff --git a/src/coreComponents/schema/docs/Tasks_other.rst b/src/coreComponents/schema/docs/Tasks_other.rst index dca37a26a99..0ab09cd94e0 100644 --- a/src/coreComponents/schema/docs/Tasks_other.rst +++ b/src/coreComponents/schema/docs/Tasks_other.rst @@ -5,6 +5,7 @@ Name Type Description =========================================================== ==== ================================================================================ CompositionalMultiphaseReservoirPoromechanicsInitialization node :ref:`DATASTRUCTURE_CompositionalMultiphaseReservoirPoromechanicsInitialization` CompositionalMultiphaseStatistics node :ref:`DATASTRUCTURE_CompositionalMultiphaseStatistics` +HydrofractureInitialization node :ref:`DATASTRUCTURE_HydrofractureInitialization` MultiphasePoromechanicsInitialization node :ref:`DATASTRUCTURE_MultiphasePoromechanicsInitialization` PVTDriver node :ref:`DATASTRUCTURE_PVTDriver` PackCollection node :ref:`DATASTRUCTURE_PackCollection` diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index 6e985df782e..37fc8d16726 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -471,6 +471,10 @@ + + + + @@ -3602,6 +3606,7 @@ Local - Add stabilization only to interiors of macro elements.--> + @@ -3641,6 +3646,16 @@ Local - Add stabilization only to interiors of macro elements.--> + + + + + + + + + + @@ -4021,7 +4036,7 @@ The expected format is "{ waterMax, oilMax }", in that order--> - + @@ -4043,7 +4058,7 @@ The expected format is "{ waterMax, oilMax }", in that order--> - + @@ -4065,7 +4080,7 @@ The expected format is "{ waterMax, oilMax }", in that order--> - + @@ -4087,7 +4102,7 @@ The expected format is "{ waterMax, oilMax }", in that order--> - + diff --git a/src/coreComponents/schema/schema.xsd.other b/src/coreComponents/schema/schema.xsd.other index b337dd2d503..c0c6ca13246 100644 --- a/src/coreComponents/schema/schema.xsd.other +++ b/src/coreComponents/schema/schema.xsd.other @@ -1295,6 +1295,7 @@ + @@ -1310,6 +1311,7 @@ + diff --git a/src/docs/sphinx/CompleteXMLSchema.rst b/src/docs/sphinx/CompleteXMLSchema.rst index 7ab5a264d15..c24749cc36a 100644 --- a/src/docs/sphinx/CompleteXMLSchema.rst +++ b/src/docs/sphinx/CompleteXMLSchema.rst @@ -577,6 +577,13 @@ Element: Hydrofracture .. include:: ../../coreComponents/schema/docs/Hydrofracture.rst +.. _XML_HydrofractureInitialization: + +Element: HydrofractureInitialization +==================================== +.. include:: ../../coreComponents/schema/docs/HydrofractureInitialization.rst + + .. _XML_HydrostaticEquilibrium: Element: HydrostaticEquilibrium @@ -2016,6 +2023,13 @@ Datastructure: Hydrofracture .. include:: ../../coreComponents/schema/docs/Hydrofracture_other.rst +.. _DATASTRUCTURE_HydrofractureInitialization: + +Datastructure: HydrofractureInitialization +========================================== +.. include:: ../../coreComponents/schema/docs/HydrofractureInitialization_other.rst + + .. _DATASTRUCTURE_HydrostaticEquilibrium: Datastructure: HydrostaticEquilibrium From fd605f7e137d196996010e498322999f42ad7dde Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 17 Jun 2024 11:50:23 +0200 Subject: [PATCH 132/216] review pavel --- .../constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp | 4 ++++ .../constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp | 2 +- .../fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp | 4 ++-- .../fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp | 4 ++-- .../fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp | 4 ++-- .../fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp | 2 +- .../multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp | 4 ++-- .../multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp | 2 +- .../multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp | 2 +- .../fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp | 2 +- .../fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp | 2 +- .../multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp | 2 +- .../multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp | 2 +- .../multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp | 2 +- .../fluid/multifluid/CO2Brine/functions/WaterDensity.cpp | 2 +- .../fluid/multifluid/reactive/ReactiveBrineFluid.hpp | 4 ++++ 16 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp index 8b6cd2ea969..53ffc4364ca 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp @@ -169,6 +169,10 @@ class CO2BrineFluid : public MultiFluidBase private: + /** + * @brief Create a PVT Model and output them + * @param isClone Check if we have a clone of this constitutive model. If so don't regenarate.output + */ void createPVTModels( bool isClone ); /// Names of the files defining the viscosity and density models diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp index 7cab79bd0f2..8c59e191db0 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp @@ -61,7 +61,7 @@ struct PhaseModel array1d< array1d< string > > const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - geos::constitutive::PVTProps::PVTFunctionBase::TableOutputOptions pvtOpts ) + PVTProps::PVTFunctionBase::TableOutputOptions pvtOpts ) : density( phaseModelName + "_" + Density::catalogName(), inputParams[InputParamOrder::DENSITY], componentNames, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp index ae0e5263cc1..8aba6e50ee2 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp @@ -205,8 +205,8 @@ BrineEnthalpy::BrineEnthalpy( string const & name, m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); m_brineEnthalpyTable = makeBrineEnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - handleTableOutputOptions( m_CO2EnthalpyTable, pvtOpts ); - handleTableOutputOptions( m_brineEnthalpyTable, pvtOpts ); + outputPVTTableData( m_CO2EnthalpyTable, pvtOpts ); + outputPVTTableData( m_brineEnthalpyTable, pvtOpts ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp index bbe65ca484c..f684a6e264f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp @@ -266,8 +266,8 @@ CO2Enthalpy::CO2Enthalpy( string const & name, m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - handleTableOutputOptions( m_CO2EnthalpyTable, pvtOpts ); - handleTableOutputOptions( m_CO2EnthalpyTable, pvtOpts ); + outputPVTTableData( m_CO2EnthalpyTable, pvtOpts ); + outputPVTTableData( m_CO2EnthalpyTable, pvtOpts ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp index 589d329dac3..0e98064476b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp @@ -256,8 +256,8 @@ CO2Solubility::CO2Solubility( string const & name, std::tie( m_CO2SolubilityTable, m_WaterVapourisationTable ) = makeSolubilityTables( m_modelName, inputParams, solubilityModel ); - handleTableOutputOptions( m_CO2SolubilityTable, pvtOpts ); - handleTableOutputOptions( m_WaterVapourisationTable, pvtOpts ); + outputPVTTableData( m_CO2SolubilityTable, pvtOpts ); + outputPVTTableData( m_WaterVapourisationTable, pvtOpts ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp index 6ff83c5ee06..af322953198 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp @@ -116,7 +116,7 @@ class CO2Solubility : public FlashModelBase string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - geos::constitutive::PVTProps::FlashModelBase::TableOutputOptions pvtOpts ); + PVTProps::FlashModelBase::TableOutputOptions pvtOpts ); static string catalogName() { return "CO2Solubility"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp index 96e6f598bdb..e13c9dd37fd 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp @@ -52,8 +52,8 @@ EzrokhiBrineDensity::EzrokhiBrineDensity( string const & name, m_waterSatDensityTable = PureWaterProperties::makeSaturationDensityTable( m_functionName, FunctionManager::getInstance() ); m_waterSatPressureTable = PureWaterProperties::makeSaturationPressureTable( m_functionName, FunctionManager::getInstance() ); - handleTableOutputOptions( m_waterSatPressureTable, pvtOpts ); - handleTableOutputOptions( m_waterSatDensityTable, pvtOpts ); + outputPVTTableData( m_waterSatPressureTable, pvtOpts ); + outputPVTTableData( m_waterSatDensityTable, pvtOpts ); } void EzrokhiBrineDensity::makeCoefficients( string_array const & inputPara ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp index 2c2b04e355a..8cc92975e96 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp @@ -51,7 +51,7 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, makeCoefficients( inputPara ); m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); - handleTableOutputOptions( m_waterViscosityTable, pvtOpts ); + outputPVTTableData( m_waterViscosityTable, pvtOpts ); } void EzrokhiBrineViscosity::makeCoefficients( string_array const & inputPara ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp index 5664dbdd8c1..203589e3182 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp @@ -148,7 +148,7 @@ FenghourCO2Viscosity::FenghourCO2Viscosity( string const & name, { m_CO2ViscosityTable = makeViscosityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - handleTableOutputOptions( m_CO2ViscosityTable, pvtOpts ); + outputPVTTableData( m_CO2ViscosityTable, pvtOpts ); } void FenghourCO2Viscosity::checkTablesParameters( real64 const pressure, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp index 42d35493458..af03c788526 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp @@ -116,7 +116,7 @@ class FlashModelBase * @param tableData The target table to be printed * @param pvtOpts Struct containing output options */ - void handleTableOutputOptions( TableFunction const * tableData, TableOutputOptions pvtOpts ) + void outputPVTTableData( TableFunction const * tableData, TableOutputOptions pvtOpts ) { if( pvtOpts.writeInLog && tableData->numDimensions() <= 2 ) { diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index 5c7a0eeaa24..118c29494ad 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -156,7 +156,7 @@ class PVTFunctionBase * @param tableData The target table to be printed * @param pvtOpts Struct containing output options */ - void handleTableOutputOptions( TableFunction const * tableData, TableOutputOptions pvtOpts ) + void outputPVTTableData( TableFunction const * tableData, TableOutputOptions pvtOpts ) { if( pvtOpts.writeInLog && tableData->numDimensions() <= 2 ) { diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp index 9d3373eb54e..32f09200178 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp @@ -189,7 +189,7 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, m_brineDensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - handleTableOutputOptions( m_brineDensityTable, pvtOpts ); + outputPVTTableData( m_brineDensityTable, pvtOpts ); } PhillipsBrineDensity::KernelWrapper diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp index a5efc57385d..c707b794551 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp @@ -44,7 +44,7 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); makeCoefficients( inputPara ); - handleTableOutputOptions( m_waterViscosityTable, pvtOpts ); + outputPVTTableData( m_waterViscosityTable, pvtOpts ); } void PhillipsBrineViscosity::makeCoefficients( string_array const & inputPara ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp index 75fd4691ef6..31c85cf374a 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp @@ -288,7 +288,7 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, m_CO2DensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - handleTableOutputOptions( m_CO2DensityTable, pvtOpts ); + outputPVTTableData( m_CO2DensityTable, pvtOpts ); } void SpanWagnerCO2Density::checkTablesParameters( real64 const pressure, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp index dd7604c3865..7db5656395a 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp @@ -44,7 +44,7 @@ WaterDensity::WaterDensity( string const & name, GEOS_UNUSED_VAR( inputParams ); m_waterDensityTable = PureWaterProperties::makeSaturationDensityTable( m_functionName, FunctionManager::getInstance() ); - handleTableOutputOptions( m_waterDensityTable, pvtOpts ); + outputPVTTableData( m_waterDensityTable, pvtOpts ); } void WaterDensity::checkTablesParameters( real64 const pressure, diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp index b9a14126a44..ec884839b15 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp @@ -160,6 +160,10 @@ class ReactiveBrineFluid : public ReactiveMultiFluid private: + /** + * @brief Create a PVT Model and output them + * @param isClone Check if we have a clone of this constitutive model. If so don't regenarate.output + */ void createPVTModels( bool isClone ); bool m_isClone = true; From 5cbaeecc2e0880e89dd1899ac2f987c349e67b5f Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 18 Jun 2024 09:43:59 +0200 Subject: [PATCH 133/216] renaming --- .../fluid/multifluid/CO2Brine/CO2BrineFluid.cpp | 14 +++++++------- .../fluid/multifluid/CO2Brine/CO2BrineFluid.hpp | 2 +- .../fluid/multifluid/CO2Brine/PhaseModel.hpp | 10 +++++----- .../CO2Brine/functions/BrineEnthalpy.cpp | 6 +++--- .../CO2Brine/functions/BrineEnthalpy.hpp | 2 +- .../multifluid/CO2Brine/functions/CO2Enthalpy.cpp | 6 +++--- .../multifluid/CO2Brine/functions/CO2Enthalpy.hpp | 2 +- .../CO2Brine/functions/CO2Solubility.cpp | 6 +++--- .../CO2Brine/functions/CO2Solubility.hpp | 2 +- .../CO2Brine/functions/EzrokhiBrineDensity.cpp | 6 +++--- .../CO2Brine/functions/EzrokhiBrineDensity.hpp | 2 +- .../CO2Brine/functions/EzrokhiBrineViscosity.cpp | 4 ++-- .../CO2Brine/functions/EzrokhiBrineViscosity.hpp | 2 +- .../CO2Brine/functions/FenghourCO2Viscosity.cpp | 4 ++-- .../CO2Brine/functions/FenghourCO2Viscosity.hpp | 2 +- .../CO2Brine/functions/FlashModelBase.hpp | 8 ++++---- .../CO2Brine/functions/NoOpPVTFunction.hpp | 4 ++-- .../CO2Brine/functions/PVTFunctionBase.hpp | 8 ++++---- .../CO2Brine/functions/PhillipsBrineDensity.cpp | 4 ++-- .../CO2Brine/functions/PhillipsBrineDensity.hpp | 2 +- .../CO2Brine/functions/PhillipsBrineViscosity.cpp | 4 ++-- .../CO2Brine/functions/PhillipsBrineViscosity.hpp | 2 +- .../CO2Brine/functions/SpanWagnerCO2Density.cpp | 4 ++-- .../CO2Brine/functions/SpanWagnerCO2Density.hpp | 2 +- .../multifluid/CO2Brine/functions/WaterDensity.cpp | 4 ++-- .../multifluid/CO2Brine/functions/WaterDensity.hpp | 2 +- .../multifluid/reactive/ReactiveBrineFluid.cpp | 4 ++-- .../multifluid/reactive/ReactiveBrineFluid.hpp | 2 +- .../constitutiveTests/testCO2BrinePVTModels.cpp | 8 ++++---- .../testCO2SpycherPruessModels.cpp | 4 ++-- 30 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 5c71cdff9ee..3b6a81ff927 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -335,13 +335,13 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) InputError ); // then, we are ready to instantiate the phase models - PVTFunctionBase::TableOutputOptions pvtOpts = { + PVTFunctionBase::TableOutputOptions pvtOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog }; - m_phase1 = std::make_unique< PHASE1 >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, pvtOpts ); - m_phase2 = std::make_unique< PHASE2 >( getName() + "_phaseModel2", phase2InputParams, m_componentNames, m_componentMolarWeight, pvtOpts ); + m_phase1 = std::make_unique< PHASE1 >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, pvtOutputOpts ); + m_phase2 = std::make_unique< PHASE2 >( getName() + "_phaseModel2", phase2InputParams, m_componentNames, m_componentMolarWeight, pvtOutputOpts ); // 2) Create the flash model @@ -363,7 +363,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) { if( strs[1] == FLASH::catalogName() ) { - FlashModelBase::TableOutputOptions flashOpts = { + FlashModelBase::TableOutputOptions flashOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog }; @@ -372,7 +372,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) m_phaseNames, m_componentNames, m_componentMolarWeight, - flashOpts ); + flashOutputOpts ); } } else @@ -408,7 +408,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) { strs[2] = m_solubilityTables[0]; } - FlashModelBase::TableOutputOptions flashOpts = { + FlashModelBase::TableOutputOptions flashOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog }; @@ -418,7 +418,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) m_phaseNames, m_componentNames, m_componentMolarWeight, - flashOpts ); + flashOutputOpts ); } GEOS_THROW_IF( m_flash == nullptr, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp index 53ffc4364ca..4d054112806 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp @@ -171,7 +171,7 @@ class CO2BrineFluid : public MultiFluidBase /** * @brief Create a PVT Model and output them - * @param isClone Check if we have a clone of this constitutive model. If so don't regenarate.output + * @param isClone If we are in the case of a clone of a constitutive mode, don't regenerate the output */ void createPVTModels( bool isClone ); diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp index 8c59e191db0..7eb3cb0e0c8 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp @@ -55,28 +55,28 @@ struct PhaseModel * @param[in] inputParams input parameters read from files * @param[in] componentNames names of the components * @param[in] componentMolarWeight molar weights of the components - * @param[in] pvtOpts Struct output options + * @param[in] pvtOutputOpts Struct output options */ PhaseModel( string const & phaseModelName, array1d< array1d< string > > const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTProps::PVTFunctionBase::TableOutputOptions pvtOpts ) + PVTProps::PVTFunctionBase::TableOutputOptions pvtOutputOpts ) : density( phaseModelName + "_" + Density::catalogName(), inputParams[InputParamOrder::DENSITY], componentNames, componentMolarWeight, - pvtOpts ), + pvtOutputOpts ), viscosity( phaseModelName + "_" + Viscosity::catalogName(), inputParams[InputParamOrder::VISCOSITY], componentNames, componentMolarWeight, - pvtOpts ), + pvtOutputOpts ), enthalpy( phaseModelName + "_" + Enthalpy::catalogName(), inputParams[InputParamOrder::ENTHALPY], componentNames, componentMolarWeight, - pvtOpts ) + pvtOutputOpts ) {} /// The phase density model diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp index 8aba6e50ee2..bcf0f29e443 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp @@ -191,7 +191,7 @@ BrineEnthalpy::BrineEnthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ): + TableOutputOptions pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -205,8 +205,8 @@ BrineEnthalpy::BrineEnthalpy( string const & name, m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); m_brineEnthalpyTable = makeBrineEnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_CO2EnthalpyTable, pvtOpts ); - outputPVTTableData( m_brineEnthalpyTable, pvtOpts ); + outputPVTTableData( m_CO2EnthalpyTable, pvtOutputOpts ); + outputPVTTableData( m_brineEnthalpyTable, pvtOutputOpts ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp index e85cbd3d58e..3b5ba11bc22 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp @@ -91,7 +91,7 @@ class BrineEnthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ); + TableOutputOptions pvtOutputOpts ); static string catalogName() { return "BrineEnthalpy"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp index f684a6e264f..f74d755b103 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp @@ -256,7 +256,7 @@ CO2Enthalpy::CO2Enthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ): + TableOutputOptions pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -266,8 +266,8 @@ CO2Enthalpy::CO2Enthalpy( string const & name, m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_CO2EnthalpyTable, pvtOpts ); - outputPVTTableData( m_CO2EnthalpyTable, pvtOpts ); + outputPVTTableData( m_CO2EnthalpyTable, pvtOutputOpts ); + outputPVTTableData( m_CO2EnthalpyTable, pvtOutputOpts ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp index 23106d5519f..4eb8b9c593b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp @@ -79,7 +79,7 @@ class CO2Enthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ); + TableOutputOptions pvtOutputOpts ); static string catalogName() { return "CO2Enthalpy"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp index 0e98064476b..b94a757ad90 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp @@ -220,7 +220,7 @@ CO2Solubility::CO2Solubility( string const & name, string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ): + TableOutputOptions pvtOutputOpts ): FlashModelBase( name, componentNames, componentMolarWeight ) @@ -256,8 +256,8 @@ CO2Solubility::CO2Solubility( string const & name, std::tie( m_CO2SolubilityTable, m_WaterVapourisationTable ) = makeSolubilityTables( m_modelName, inputParams, solubilityModel ); - outputPVTTableData( m_CO2SolubilityTable, pvtOpts ); - outputPVTTableData( m_WaterVapourisationTable, pvtOpts ); + outputPVTTableData( m_CO2SolubilityTable, pvtOutputOpts ); + outputPVTTableData( m_WaterVapourisationTable, pvtOutputOpts ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp index af322953198..0ab12b6ca80 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp @@ -116,7 +116,7 @@ class CO2Solubility : public FlashModelBase string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTProps::FlashModelBase::TableOutputOptions pvtOpts ); + PVTProps::FlashModelBase::TableOutputOptions pvtOutputOpts ); static string catalogName() { return "CO2Solubility"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp index e13c9dd37fd..e59472dc959 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp @@ -37,7 +37,7 @@ EzrokhiBrineDensity::EzrokhiBrineDensity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ): + TableOutputOptions pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -52,8 +52,8 @@ EzrokhiBrineDensity::EzrokhiBrineDensity( string const & name, m_waterSatDensityTable = PureWaterProperties::makeSaturationDensityTable( m_functionName, FunctionManager::getInstance() ); m_waterSatPressureTable = PureWaterProperties::makeSaturationPressureTable( m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_waterSatPressureTable, pvtOpts ); - outputPVTTableData( m_waterSatDensityTable, pvtOpts ); + outputPVTTableData( m_waterSatPressureTable, pvtOutputOpts ); + outputPVTTableData( m_waterSatDensityTable, pvtOutputOpts ); } void EzrokhiBrineDensity::makeCoefficients( string_array const & inputPara ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp index d8529eb71c6..5f046aea0d6 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp @@ -108,7 +108,7 @@ class EzrokhiBrineDensity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ); + TableOutputOptions pvtOutputOpts ); virtual ~EzrokhiBrineDensity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp index 8cc92975e96..8a530e5479f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp @@ -37,7 +37,7 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ): + TableOutputOptions pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -51,7 +51,7 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, makeCoefficients( inputPara ); m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_waterViscosityTable, pvtOpts ); + outputPVTTableData( m_waterViscosityTable, pvtOutputOpts ); } void EzrokhiBrineViscosity::makeCoefficients( string_array const & inputPara ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp index aade8e1be43..aa2a2d9eb66 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp @@ -97,7 +97,7 @@ class EzrokhiBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ); + TableOutputOptions pvtOutputOpts ); virtual ~EzrokhiBrineViscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp index 203589e3182..b95590eb708 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp @@ -141,14 +141,14 @@ FenghourCO2Viscosity::FenghourCO2Viscosity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ) + TableOutputOptions pvtOutputOpts ) : PVTFunctionBase( name, componentNames, componentMolarWeight ) { m_CO2ViscosityTable = makeViscosityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_CO2ViscosityTable, pvtOpts ); + outputPVTTableData( m_CO2ViscosityTable, pvtOutputOpts ); } void FenghourCO2Viscosity::checkTablesParameters( real64 const pressure, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp index 30fe382c5e6..824dcd31086 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp @@ -75,7 +75,7 @@ class FenghourCO2Viscosity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ); + TableOutputOptions pvtOutputOpts ); virtual ~FenghourCO2Viscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp index af03c788526..ff38e7eb1be 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp @@ -114,16 +114,16 @@ class FlashModelBase /** * @brief Print the table(s) in the log and/or CSV files when requested by the user. * @param tableData The target table to be printed - * @param pvtOpts Struct containing output options + * @param pvtOutputOpts Struct containing output options */ - void outputPVTTableData( TableFunction const * tableData, TableOutputOptions pvtOpts ) + void outputPVTTableData( TableFunction const * tableData, TableOutputOptions pvtOutputOpts ) { - if( pvtOpts.writeInLog && tableData->numDimensions() <= 2 ) + if( pvtOutputOpts.writeInLog && tableData->numDimensions() <= 2 ) { TableTextFormatter textFormatter; GEOS_LOG_RANK_0( textFormatter.toString( *tableData )); } - if( pvtOpts.writeCSV || ( pvtOpts.writeInLog && tableData->numDimensions() >= 3 ) ) + if( pvtOutputOpts.writeCSV || ( pvtOutputOpts.writeInLog && tableData->numDimensions() >= 3 ) ) { string const filename = tableData->getName(); std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp index dce0837e078..3102e5adf79 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp @@ -70,12 +70,12 @@ class NoOpPVTFunction : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ) + TableOutputOptions pvtOutputOpts ) : PVTFunctionBase( name, componentNames, componentMolarWeight ) { - GEOS_UNUSED_VAR( inputPara, pvtOpts ); + GEOS_UNUSED_VAR( inputPara, pvtOutputOpts ); } virtual ~NoOpPVTFunction() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index 118c29494ad..5ab7b065f6c 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -154,17 +154,17 @@ class PVTFunctionBase /** * @brief Print the table(s) in the log and/or CSV files when requested by the user. * @param tableData The target table to be printed - * @param pvtOpts Struct containing output options + * @param pvtOutputOpts Struct containing output options */ - void outputPVTTableData( TableFunction const * tableData, TableOutputOptions pvtOpts ) + void outputPVTTableData( TableFunction const * tableData, TableOutputOptions pvtOutputOpts ) { - if( pvtOpts.writeInLog && tableData->numDimensions() <= 2 ) + if( pvtOutputOpts.writeInLog && tableData->numDimensions() <= 2 ) { TableTextFormatter textFormatter; GEOS_LOG_RANK_0( textFormatter.toString( *tableData )); } - if( pvtOpts.writeCSV || ( pvtOpts.writeInLog && tableData->numDimensions() >= 3 ) ) + if( pvtOutputOpts.writeCSV || ( pvtOutputOpts.writeInLog && tableData->numDimensions() >= 3 ) ) { string const filename = tableData->getName(); std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp index 32f09200178..6eb519eb037 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp @@ -176,7 +176,7 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ): + TableOutputOptions pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -189,7 +189,7 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, m_brineDensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_brineDensityTable, pvtOpts ); + outputPVTTableData( m_brineDensityTable, pvtOutputOpts ); } PhillipsBrineDensity::KernelWrapper diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp index 325e452d3db..5f284aba184 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp @@ -85,7 +85,7 @@ class PhillipsBrineDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ); + TableOutputOptions pvtOutputOpts ); static string catalogName() { return "PhillipsBrineDensity"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp index c707b794551..1594d687824 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp @@ -36,7 +36,7 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ): + TableOutputOptions pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -44,7 +44,7 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); makeCoefficients( inputPara ); - outputPVTTableData( m_waterViscosityTable, pvtOpts ); + outputPVTTableData( m_waterViscosityTable, pvtOutputOpts ); } void PhillipsBrineViscosity::makeCoefficients( string_array const & inputPara ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp index f4826ff5086..b53f2fa07ce 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp @@ -83,7 +83,7 @@ class PhillipsBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ); + TableOutputOptions pvtOutputOpts ); virtual ~PhillipsBrineViscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp index 31c85cf374a..090c051232d 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp @@ -278,7 +278,7 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ): + TableOutputOptions pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -288,7 +288,7 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, m_CO2DensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_CO2DensityTable, pvtOpts ); + outputPVTTableData( m_CO2DensityTable, pvtOutputOpts ); } void SpanWagnerCO2Density::checkTablesParameters( real64 const pressure, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp index 873777c3b79..2fbbf2e47b2 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp @@ -80,7 +80,7 @@ class SpanWagnerCO2Density : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ); + TableOutputOptions pvtOutputOpts ); static string catalogName() { return "SpanWagnerCO2Density"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp index 7db5656395a..2873d4e13fe 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp @@ -36,7 +36,7 @@ WaterDensity::WaterDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ): + TableOutputOptions pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -44,7 +44,7 @@ WaterDensity::WaterDensity( string const & name, GEOS_UNUSED_VAR( inputParams ); m_waterDensityTable = PureWaterProperties::makeSaturationDensityTable( m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_waterDensityTable, pvtOpts ); + outputPVTTableData( m_waterDensityTable, pvtOutputOpts ); } void WaterDensity::checkTablesParameters( real64 const pressure, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp index 2d8cbcd3722..f547ff30203 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp @@ -75,7 +75,7 @@ class WaterDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOpts ); + TableOutputOptions pvtOutputOpts ); static string catalogName() { return "WaterDensity"; } virtual string getCatalogName() const final { return catalogName(); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp index 2556284ef78..7b2e145fab5 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp @@ -204,14 +204,14 @@ void ReactiveBrineFluid< PHASE > ::createPVTModels( bool isClone ) GEOS_FMT( "{}: PVT model {} not found in input files", getFullName(), PHASE::Enthalpy::catalogName() ), InputError ); - PVTFunctionBase::TableOutputOptions pvtOpts = { + PVTFunctionBase::TableOutputOptions pvtOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog }; // then, we are ready to instantiate the phase models m_phase = std::make_unique< PHASE >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, - pvtOpts ); + pvtOutputOpts ); } template< typename PHASE > diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp index ec884839b15..eb92499058a 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp @@ -162,7 +162,7 @@ class ReactiveBrineFluid : public ReactiveMultiFluid /** * @brief Create a PVT Model and output them - * @param isClone Check if we have a clone of this constitutive model. If so don't regenarate.output + * @param isClone If we are in the case of a clone of a constitutive mode, don't regenerate the output */ void createPVTModels( bool isClone ); diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp index 110b132cdd0..afe7fd587aa 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp @@ -360,7 +360,7 @@ std::unique_ptr< MODEL > makePVTFunction( string const & filename, { array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( str ); - PVTFunctionBase::TableOutputOptions pvtOpts = { + PVTFunctionBase::TableOutputOptions pvtOutputOpts = { true,// writeCSV true, // writeInLog }; @@ -371,7 +371,7 @@ std::unique_ptr< MODEL > makePVTFunction( string const & filename, strs, componentNames, componentMolarWeight, - pvtOpts ); + pvtOutputOpts ); } } GEOS_ERROR_IF( pvtFunction == nullptr, @@ -405,7 +405,7 @@ std::unique_ptr< MODEL > makeFlashModel( string const & filename, while( std::getline( is, str ) ) { array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( str ); - FlashModelBase::TableOutputOptions flashOpts = { + FlashModelBase::TableOutputOptions flashOutputOpts = { true, // writeCSV true, // writeInLog }; @@ -416,7 +416,7 @@ std::unique_ptr< MODEL > makeFlashModel( string const & filename, phaseNames, componentNames, componentMolarWeight, - flashOpts ); + flashOutputOpts ); } } GEOS_ERROR_IF( flashModel == nullptr, diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp index 72a948e8f8a..de0d8598c48 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp @@ -82,7 +82,7 @@ CO2SolubilitySpycherPruessTestFixture::makeFlashModel( string const & fileConten // Read file parameters array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( fileContent ); - FlashModelBase::TableOutputOptions flashOpts = { + FlashModelBase::TableOutputOptions flashOutputOpts = { false, // writeCSV false, // writeInLog }; @@ -92,7 +92,7 @@ CO2SolubilitySpycherPruessTestFixture::makeFlashModel( string const & fileConten phaseNames, componentNames, componentMolarWeight, - flashOpts ); + flashOutputOpts ); } TEST_P( CO2SolubilitySpycherPruessTestFixture, testExpectedValues ) From 684a405932e6f490a0f4a5184be0b38733556d2e Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 19 Jun 2024 14:25:42 +0200 Subject: [PATCH 134/216] review update --- .../fluid/multifluid/CO2Brine/CO2BrineFluid.cpp | 7 +++---- .../constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp | 2 +- .../fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp | 4 ++-- .../fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp | 2 +- .../fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp | 4 ++-- .../fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp | 2 +- .../fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp | 2 +- .../fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp | 2 +- .../multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp | 4 ++-- .../multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp | 2 +- .../CO2Brine/functions/EzrokhiBrineViscosity.cpp | 4 ++-- .../CO2Brine/functions/EzrokhiBrineViscosity.hpp | 2 +- .../multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp | 4 ++-- .../multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp | 2 +- .../fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp | 4 ++-- .../multifluid/CO2Brine/functions/NoOpPVTFunction.hpp | 2 +- .../multifluid/CO2Brine/functions/PVTFunctionBase.hpp | 6 +++--- .../multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp | 4 ++-- .../multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp | 2 +- .../CO2Brine/functions/PhillipsBrineViscosity.cpp | 4 ++-- .../CO2Brine/functions/PhillipsBrineViscosity.hpp | 2 +- .../multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp | 4 ++-- .../multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp | 2 +- .../fluid/multifluid/CO2Brine/functions/WaterDensity.cpp | 4 ++-- .../fluid/multifluid/CO2Brine/functions/WaterDensity.hpp | 2 +- .../fluid/multifluid/reactive/ReactiveBrineFluid.cpp | 5 +++-- src/coreComponents/functions/TableFunction.cpp | 2 +- .../unitTests/constitutiveTests/testCO2BrinePVTModels.cpp | 4 ++-- .../constitutiveTests/testCO2SpycherPruessModels.cpp | 2 +- 29 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 3b6a81ff927..43156d6ebec 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -19,7 +19,6 @@ #include "constitutive/fluid/multifluid/MultiFluidFields.hpp" #include "constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionHelpers.hpp" -#include "constitutive/ConstitutiveManager.hpp" #include "common/Units.hpp" namespace geos @@ -335,7 +334,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) InputError ); // then, we are ready to instantiate the phase models - PVTFunctionBase::TableOutputOptions pvtOutputOpts = { + PVTFunctionBase::TableOutputOptions const pvtOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog }; @@ -363,7 +362,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) { if( strs[1] == FLASH::catalogName() ) { - FlashModelBase::TableOutputOptions flashOutputOpts = { + FlashModelBase::TableOutputOptions const flashOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog }; @@ -408,7 +407,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) { strs[2] = m_solubilityTables[0]; } - FlashModelBase::TableOutputOptions flashOutputOpts = { + FlashModelBase::TableOutputOptions const flashOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog }; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp index 7eb3cb0e0c8..349a9422347 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp @@ -61,7 +61,7 @@ struct PhaseModel array1d< array1d< string > > const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTProps::PVTFunctionBase::TableOutputOptions pvtOutputOpts ) + PVTProps::PVTFunctionBase::TableOutputOptions const pvtOutputOpts ) : density( phaseModelName + "_" + Density::catalogName(), inputParams[InputParamOrder::DENSITY], componentNames, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp index bcf0f29e443..df991576f6b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp @@ -191,7 +191,7 @@ BrineEnthalpy::BrineEnthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ): + TableOutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -231,7 +231,7 @@ BrineEnthalpy::createKernelWrapper() const m_waterIndex ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, BrineEnthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, BrineEnthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp index 3b5ba11bc22..b774c574ab0 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp @@ -91,7 +91,7 @@ class BrineEnthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ); + TableOutputOptions const pvtOutputOpts ); static string catalogName() { return "BrineEnthalpy"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp index f74d755b103..8f3f470d047 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp @@ -256,7 +256,7 @@ CO2Enthalpy::CO2Enthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ): + TableOutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -309,7 +309,7 @@ CO2Enthalpy::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, CO2Enthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, CO2Enthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp index 4eb8b9c593b..27c0b17f450 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp @@ -79,7 +79,7 @@ class CO2Enthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ); + TableOutputOptions const pvtOutputOpts ); static string catalogName() { return "CO2Enthalpy"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp index b94a757ad90..2434a3ce8a9 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp @@ -220,7 +220,7 @@ CO2Solubility::CO2Solubility( string const & name, string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ): + TableOutputOptions const pvtOutputOpts ): FlashModelBase( name, componentNames, componentMolarWeight ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp index 0ab12b6ca80..c6c8d248a7b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp @@ -116,7 +116,7 @@ class CO2Solubility : public FlashModelBase string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTProps::FlashModelBase::TableOutputOptions pvtOutputOpts ); + PVTProps::FlashModelBase::TableOutputOptions const pvtOutputOpts ); static string catalogName() { return "CO2Solubility"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp index e59472dc959..5ae763f3fbf 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp @@ -37,7 +37,7 @@ EzrokhiBrineDensity::EzrokhiBrineDensity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ): + TableOutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -100,7 +100,7 @@ EzrokhiBrineDensity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp index 5f046aea0d6..f86e6d61b8f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp @@ -108,7 +108,7 @@ class EzrokhiBrineDensity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ); + TableOutputOptions const pvtOutputOpts ); virtual ~EzrokhiBrineDensity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp index 8a530e5479f..d03842a9573 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp @@ -37,7 +37,7 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ): + TableOutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -93,7 +93,7 @@ EzrokhiBrineViscosity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp index aa2a2d9eb66..504b19f6c47 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp @@ -97,7 +97,7 @@ class EzrokhiBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ); + TableOutputOptions const pvtOutputOpts ); virtual ~EzrokhiBrineViscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp index b95590eb708..f5d065ad55a 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp @@ -141,7 +141,7 @@ FenghourCO2Viscosity::FenghourCO2Viscosity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ) + TableOutputOptions const pvtOutputOpts ) : PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -165,7 +165,7 @@ FenghourCO2Viscosity::createKernelWrapper() const *m_CO2ViscosityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, FenghourCO2Viscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, FenghourCO2Viscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp index 824dcd31086..062a2b8813a 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp @@ -75,7 +75,7 @@ class FenghourCO2Viscosity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ); + TableOutputOptions const pvtOutputOpts ); virtual ~FenghourCO2Viscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp index ff38e7eb1be..80fc8dad562 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp @@ -94,7 +94,7 @@ class FlashModelBase string_array const &, string_array const &, array1d< real64 > const &, - TableOutputOptions >; + TableOutputOptions const >; static typename CatalogInterface::CatalogType & getCatalog() { static CatalogInterface::CatalogType catalog; @@ -116,7 +116,7 @@ class FlashModelBase * @param tableData The target table to be printed * @param pvtOutputOpts Struct containing output options */ - void outputPVTTableData( TableFunction const * tableData, TableOutputOptions pvtOutputOpts ) + void outputPVTTableData( TableFunction const * tableData, TableOutputOptions const pvtOutputOpts ) { if( pvtOutputOpts.writeInLog && tableData->numDimensions() <= 2 ) { diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp index 3102e5adf79..431d9430f47 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp @@ -70,7 +70,7 @@ class NoOpPVTFunction : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ) + TableOutputOptions const pvtOutputOpts ) : PVTFunctionBase( name, componentNames, componentMolarWeight ) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index 5ab7b065f6c..8ed88ae2261 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -130,7 +130,7 @@ class PVTFunctionBase array1d< string > const &, array1d< string > const &, array1d< real64 > const &, - TableOutputOptions >; + TableOutputOptions const >; static typename CatalogInterface::CatalogType & getCatalog() { static CatalogInterface::CatalogType catalog; @@ -156,7 +156,7 @@ class PVTFunctionBase * @param tableData The target table to be printed * @param pvtOutputOpts Struct containing output options */ - void outputPVTTableData( TableFunction const * tableData, TableOutputOptions pvtOutputOpts ) + void outputPVTTableData( TableFunction const * tableData, TableOutputOptions const pvtOutputOpts ) { if( pvtOutputOpts.writeInLog && tableData->numDimensions() <= 2 ) { @@ -168,7 +168,7 @@ class PVTFunctionBase { string const filename = tableData->getName(); std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); - GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to inputFiles/compositionalMultiphaseWell/{}/{}.csv \n", + GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to {}/{}.csv \n", OutputBase::getOutputDirectory(), filename )); TableCSVFormatter csvFormatter; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp index 6eb519eb037..ae4d21ed125 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp @@ -176,7 +176,7 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ): + TableOutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -208,7 +208,7 @@ void PhillipsBrineDensity::checkTablesParameters( real64 const pressure, m_brineDensityTable->checkCoord( temperature, 1 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp index 5f284aba184..b39dd305aae 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp @@ -85,7 +85,7 @@ class PhillipsBrineDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ); + TableOutputOptions const pvtOutputOpts ); static string catalogName() { return "PhillipsBrineDensity"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp index 1594d687824..cf979f17f4a 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp @@ -36,7 +36,7 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ): + TableOutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -91,7 +91,7 @@ PhillipsBrineViscosity::createKernelWrapper() const m_coef1 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) } // end namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp index b53f2fa07ce..3052af844c5 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp @@ -83,7 +83,7 @@ class PhillipsBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ); + TableOutputOptions const pvtOutputOpts ); virtual ~PhillipsBrineViscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp index 090c051232d..138135c5ab0 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp @@ -278,7 +278,7 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ): + TableOutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -306,7 +306,7 @@ SpanWagnerCO2Density::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, SpanWagnerCO2Density, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, SpanWagnerCO2Density, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp index 2fbbf2e47b2..ae8e604ef3e 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp @@ -80,7 +80,7 @@ class SpanWagnerCO2Density : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ); + TableOutputOptions const pvtOutputOpts ); static string catalogName() { return "SpanWagnerCO2Density"; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp index 2873d4e13fe..86c4cb47284 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp @@ -36,7 +36,7 @@ WaterDensity::WaterDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ): + TableOutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -61,7 +61,7 @@ WaterDensity::createKernelWrapper() const *m_waterDensityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, WaterDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, WaterDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) } // namespace PVTProps diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp index f547ff30203..ccbec855408 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp @@ -75,7 +75,7 @@ class WaterDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions pvtOutputOpts ); + TableOutputOptions const pvtOutputOpts ); static string catalogName() { return "WaterDensity"; } virtual string getCatalogName() const final { return catalogName(); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp index 7b2e145fab5..afdcc963e3f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp @@ -19,6 +19,7 @@ #include "constitutive/fluid/multifluid/MultiFluidFields.hpp" #include "constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionHelpers.hpp" +#include "constitutive/ConstitutiveManager.hpp" #include "common/Units.hpp" namespace geos @@ -129,7 +130,7 @@ void ReactiveBrineFluid< PHASE > ::postProcessInput() GEOS_FMT( "{}: invalid number of values in attribute '{}'", getFullName() ), InputError ); - if( getParent().getName() == "ConstitutiveModels" ) + if( getParent().getName() == ConstitutiveManager::groupKeyStruct::constitutiveModelsString() ) { m_isClone = true; } @@ -204,7 +205,7 @@ void ReactiveBrineFluid< PHASE > ::createPVTModels( bool isClone ) GEOS_FMT( "{}: PVT model {} not found in input files", getFullName(), PHASE::Enthalpy::catalogName() ), InputError ); - PVTFunctionBase::TableOutputOptions pvtOutputOpts = { + PVTFunctionBase::TableOutputOptions const pvtOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog }; diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index d8ee23a7b82..a2f029c5344 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -329,7 +329,7 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl { integer const nX = coordinates[0].size(); integer const nY = coordinates[1].size(); - if( nX * nY <= 500 ) + if( nX * nY <= 50000 ) { //1. TableData2D tableData2D; diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp index afe7fd587aa..dffb5d76992 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp @@ -360,7 +360,7 @@ std::unique_ptr< MODEL > makePVTFunction( string const & filename, { array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( str ); - PVTFunctionBase::TableOutputOptions pvtOutputOpts = { + PVTFunctionBase::TableOutputOptions const pvtOutputOpts = { true,// writeCSV true, // writeInLog }; @@ -405,7 +405,7 @@ std::unique_ptr< MODEL > makeFlashModel( string const & filename, while( std::getline( is, str ) ) { array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( str ); - FlashModelBase::TableOutputOptions flashOutputOpts = { + FlashModelBase::TableOutputOptions const flashOutputOpts = { true, // writeCSV true, // writeInLog }; diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp index de0d8598c48..30197041720 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp @@ -82,7 +82,7 @@ CO2SolubilitySpycherPruessTestFixture::makeFlashModel( string const & fileConten // Read file parameters array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( fileContent ); - FlashModelBase::TableOutputOptions flashOutputOpts = { + FlashModelBase::TableOutputOptions const flashOutputOpts = { false, // writeCSV false, // writeInLog }; From ae86942a1d2aceb75cd9bb83f3843bd71865f9dd Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 19 Jun 2024 14:37:34 +0200 Subject: [PATCH 135/216] revert a modif --- src/coreComponents/functions/TableFunction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index a2f029c5344..d8ee23a7b82 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -329,7 +329,7 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl { integer const nX = coordinates[0].size(); integer const nY = coordinates[1].size(); - if( nX * nY <= 50000 ) + if( nX * nY <= 500 ) { //1. TableData2D tableData2D; From c69fbeea585a92422d17c898f27159e055c3ae44 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 19 Jun 2024 15:29:09 +0200 Subject: [PATCH 136/216] uncrustify --- .../constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp | 2 +- .../fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp index 349a9422347..61dfb62eeab 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp @@ -61,7 +61,7 @@ struct PhaseModel array1d< array1d< string > > const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTProps::PVTFunctionBase::TableOutputOptions const pvtOutputOpts ) + PVTProps::PVTFunctionBase::TableOutputOptions const pvtOutputOpts ) : density( phaseModelName + "_" + Density::catalogName(), inputParams[InputParamOrder::DENSITY], componentNames, diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp index df991576f6b..62decdcea9e 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp @@ -191,7 +191,7 @@ BrineEnthalpy::BrineEnthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ): + TableOutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) From fa3218c8b02bae0301a3123d207b3aa170865832 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 26 Jun 2024 17:17:47 +0200 Subject: [PATCH 137/216] melvin review --- src/coreComponents/constitutive/ConstitutiveBase.cpp | 3 ++- src/coreComponents/constitutive/ConstitutiveBase.hpp | 6 ++++++ .../fluid/multifluid/CO2Brine/CO2BrineFluid.cpp | 12 +++++++++--- .../fluid/multifluid/CO2Brine/CO2BrineFluid.hpp | 2 +- .../fluid/multifluid/CO2Brine/PhaseModel.hpp | 2 +- .../fluid/multifluid/reactive/ReactiveBrineFluid.cpp | 12 ++++-------- .../fluid/multifluid/reactive/ReactiveBrineFluid.hpp | 4 +--- src/coreComponents/fileIO/Table/TableFormatter.hpp | 2 -- src/coreComponents/functions/TableFunction.cpp | 10 ++++------ 9 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/coreComponents/constitutive/ConstitutiveBase.cpp b/src/coreComponents/constitutive/ConstitutiveBase.cpp index e55cb851a69..6a821823a5f 100644 --- a/src/coreComponents/constitutive/ConstitutiveBase.cpp +++ b/src/coreComponents/constitutive/ConstitutiveBase.cpp @@ -29,7 +29,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 ); } diff --git a/src/coreComponents/constitutive/ConstitutiveBase.hpp b/src/coreComponents/constitutive/ConstitutiveBase.hpp index b0f9adbf148..622795bced0 100644 --- a/src/coreComponents/constitutive/ConstitutiveBase.hpp +++ b/src/coreComponents/constitutive/ConstitutiveBase.hpp @@ -112,6 +112,10 @@ class ConstitutiveBase : public dataRepository::Group localIndex numQuadraturePoints() const { return m_numQuadraturePoints; } + bool isClone() const { return m_isClone; } + + void setIsClone( bool const newState ) { m_isClone = newState; } + virtual std::vector< string > getSubRelationNames() const { return {}; } /** @@ -162,6 +166,8 @@ class ConstitutiveBase : public dataRepository::Group private: localIndex m_numQuadraturePoints; + + bool m_isClone; }; } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index be46fb897fa..9c5c1848ec8 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -138,7 +138,8 @@ deliverClone( string const & name, Group * const parent ) const newConstitutiveRelation.m_p1Index = m_p1Index; newConstitutiveRelation.m_p2Index = m_p2Index; - newConstitutiveRelation.createPVTModels( true ); + newConstitutiveRelation.setIsClone( true ); + newConstitutiveRelation.createPVTModels( newConstitutiveRelation.isClone() ); return clone; } @@ -240,13 +241,18 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::postProcessInput() string const expectedGasPhaseNames[] = { "CO2", "co2", "gas", "Gas" }; m_p2Index = PVTFunctionHelpers::findName( m_phaseNames, expectedGasPhaseNames, viewKeyStruct::phaseNamesString() ); - - createPVTModels( false ); + createPVTModels( isClone() ); } +/** + * @brief Create a PVT Model and output them + * @param isClone If we are in the case of a clone of a constitutive mode, never the output + */ template< typename PHASE1, typename PHASE2, typename FLASH > void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) { + + std::cout << " ISCLONE " << isClone < > phase1InputParams; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp index 4d054112806..f798fabde2c 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp @@ -171,7 +171,7 @@ class CO2BrineFluid : public MultiFluidBase /** * @brief Create a PVT Model and output them - * @param isClone If we are in the case of a clone of a constitutive mode, don't regenerate the output + * @param isClone If we are in the case of a clone of a constitutive mode, never the output */ void createPVTModels( bool isClone ); diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp index 61dfb62eeab..84724b8eeff 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp @@ -55,7 +55,7 @@ struct PhaseModel * @param[in] inputParams input parameters read from files * @param[in] componentNames names of the components * @param[in] componentMolarWeight molar weights of the components - * @param[in] pvtOutputOpts Struct output options + * @param[in] pvtOutputOpts Output struct options */ PhaseModel( string const & phaseModelName, array1d< array1d< string > > const & inputParams, diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp index afdcc963e3f..de7ba6ed64b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp @@ -104,7 +104,8 @@ deliverClone( string const & name, Group * const parent ) const ReactiveBrineFluid & newConstitutiveRelation = dynamicCast< ReactiveBrineFluid & >( *clone ); - newConstitutiveRelation.createPVTModels( true ); + newConstitutiveRelation.setIsClone( true ); + newConstitutiveRelation.createPVTModels( newConstitutiveRelation.isClone() ); return clone; } @@ -130,16 +131,11 @@ void ReactiveBrineFluid< PHASE > ::postProcessInput() GEOS_FMT( "{}: invalid number of values in attribute '{}'", getFullName() ), InputError ); - if( getParent().getName() == ConstitutiveManager::groupKeyStruct::constitutiveModelsString() ) - { - m_isClone = true; - } - - createPVTModels( m_isClone ); + createPVTModels( isClone() ); } template< typename PHASE > -void ReactiveBrineFluid< PHASE > ::createPVTModels( bool isClone ) +void ReactiveBrineFluid< PHASE > ::createPVTModels( bool isClone) { // TODO: get rid of these external files and move into XML, this is too error prone diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp index eb92499058a..ded71df48cb 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp @@ -162,12 +162,10 @@ class ReactiveBrineFluid : public ReactiveMultiFluid /** * @brief Create a PVT Model and output them - * @param isClone If we are in the case of a clone of a constitutive mode, don't regenerate the output + * @param isClone If we are in the case of a clone of a constitutive mode, never the output */ void createPVTModels( bool isClone ); - bool m_isClone = true; - /// Names of the files defining the viscosity and density models path_array m_phasePVTParaFiles; diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 7ba8f94b1da..4dc8f1d88c9 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -21,8 +21,6 @@ #include "TableData.hpp" #include "TableLayout.hpp" -#include "common/Units.hpp" - namespace geos { diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index d8ee23a7b82..0438bf27590 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -309,19 +309,18 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl if( numDimensions == 1 ) { - //1. TableData tableData; arraySlice1d< real64 const > const coords = coordinates[0]; for( integer idx = 0; idx < values.size(); idx++ ) { tableData.addRow( coords[idx], values[idx] ); } - //2. + TableLayout const tableLayout( { string( units::getDescription( tableFunction.getDimUnit( 0 ))), string( units::getDescription( valueUnit )) }, filename ); - //3. + TableTextFormatter const logTable( tableLayout ); logOutput = logTable.toString( tableData ); } @@ -331,7 +330,6 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl integer const nY = coordinates[1].size(); if( nX * nY <= 500 ) { - //1. TableData2D tableData2D; TableData2D::TableConversionData tableConverted; tableConverted = tableData2D.convertTable2D( values, @@ -339,9 +337,9 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl coordinates, units::getDescription( tableFunction.getDimUnit( 0 ) ), units::getDescription( tableFunction.getDimUnit( 1 ) )); - //2. + TableLayout tableLayout( tableConverted.headerNames, filename ); - //3. + TableTextFormatter const table2DLog( tableLayout ); logOutput = table2DLog.toString( tableConverted.tableData ); } From 5c808f80ebe8dd1a51b3c50d96680f1fcd3da5b2 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 26 Jun 2024 17:35:12 +0200 Subject: [PATCH 138/216] fix --- .../fluid/multifluid/CO2Brine/CO2BrineFluid.cpp | 10 +++++----- .../fluid/multifluid/CO2Brine/CO2BrineFluid.hpp | 3 +-- .../fluid/multifluid/reactive/ReactiveBrineFluid.cpp | 8 ++++---- .../fluid/multifluid/reactive/ReactiveBrineFluid.hpp | 3 +-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 9c5c1848ec8..25e5e9ebab2 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -139,7 +139,7 @@ deliverClone( string const & name, Group * const parent ) const newConstitutiveRelation.m_p2Index = m_p2Index; newConstitutiveRelation.setIsClone( true ); - newConstitutiveRelation.createPVTModels( newConstitutiveRelation.isClone() ); + newConstitutiveRelation.createPVTModels(); return clone; } @@ -241,7 +241,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::postProcessInput() string const expectedGasPhaseNames[] = { "CO2", "co2", "gas", "Gas" }; m_p2Index = PVTFunctionHelpers::findName( m_phaseNames, expectedGasPhaseNames, viewKeyStruct::phaseNamesString() ); - createPVTModels( isClone() ); + createPVTModels(); } /** @@ -249,10 +249,8 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::postProcessInput() * @param isClone If we are in the case of a clone of a constitutive mode, never the output */ template< typename PHASE1, typename PHASE2, typename FLASH > -void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) +void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() { - - std::cout << " ISCLONE " << isClone < > phase1InputParams; @@ -342,6 +340,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) InputError ); // then, we are ready to instantiate the phase models + bool const isClone = this->isClone(); PVTFunctionBase::TableOutputOptions const pvtOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog @@ -415,6 +414,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels( bool isClone ) { strs[2] = m_solubilityTables[0]; } + FlashModelBase::TableOutputOptions const flashOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp index f798fabde2c..8ff9a7c5a1b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp @@ -171,9 +171,8 @@ class CO2BrineFluid : public MultiFluidBase /** * @brief Create a PVT Model and output them - * @param isClone If we are in the case of a clone of a constitutive mode, never the output */ - void createPVTModels( bool isClone ); + void createPVTModels(); /// Names of the files defining the viscosity and density models path_array m_phasePVTParaFiles; diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp index de7ba6ed64b..86dba4015fe 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp @@ -105,7 +105,7 @@ deliverClone( string const & name, Group * const parent ) const ReactiveBrineFluid & newConstitutiveRelation = dynamicCast< ReactiveBrineFluid & >( *clone ); newConstitutiveRelation.setIsClone( true ); - newConstitutiveRelation.createPVTModels( newConstitutiveRelation.isClone() ); + newConstitutiveRelation.createPVTModels(); return clone; } @@ -131,13 +131,12 @@ void ReactiveBrineFluid< PHASE > ::postProcessInput() GEOS_FMT( "{}: invalid number of values in attribute '{}'", getFullName() ), InputError ); - createPVTModels( isClone() ); + createPVTModels(); } template< typename PHASE > -void ReactiveBrineFluid< PHASE > ::createPVTModels( bool isClone) +void ReactiveBrineFluid< PHASE > ::createPVTModels() { - // TODO: get rid of these external files and move into XML, this is too error prone // For now, to support the legacy input, we read all the input parameters at once in the arrays below, and then we create the models array1d< array1d< string > > phase1InputParams; @@ -201,6 +200,7 @@ void ReactiveBrineFluid< PHASE > ::createPVTModels( bool isClone) GEOS_FMT( "{}: PVT model {} not found in input files", getFullName(), PHASE::Enthalpy::catalogName() ), InputError ); + bool const isClone = this->isClone(); PVTFunctionBase::TableOutputOptions const pvtOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp index ded71df48cb..96a088dfec1 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp @@ -162,9 +162,8 @@ class ReactiveBrineFluid : public ReactiveMultiFluid /** * @brief Create a PVT Model and output them - * @param isClone If we are in the case of a clone of a constitutive mode, never the output */ - void createPVTModels( bool isClone ); + void createPVTModels(); /// Names of the files defining the viscosity and density models path_array m_phasePVTParaFiles; From 57c23b2a93e259922a1c8671b4faabbe96b9c040 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 4 Jul 2024 09:35:58 +0200 Subject: [PATCH 139/216] pr pavel correction --- .../constitutive/ConstitutiveBase.cpp | 7 +++ .../constitutive/ConstitutiveBase.hpp | 4 +- .../multifluid/CO2Brine/CO2BrineFluid.cpp | 3 +- .../reactive/ReactiveBrineFluid.cpp | 2 +- .../schema/docs/CO2BrineEzrokhiFluid.rst | 2 +- .../docs/CO2BrineEzrokhiThermalFluid.rst | 2 +- .../schema/docs/CO2BrinePhillipsFluid.rst | 2 +- .../docs/CO2BrinePhillipsThermalFluid.rst | 2 +- .../schema/docs/Hydrofracture.rst | 59 ++++++++++--------- src/coreComponents/schema/schema.xsd | 8 +-- 10 files changed, 51 insertions(+), 40 deletions(-) diff --git a/src/coreComponents/constitutive/ConstitutiveBase.cpp b/src/coreComponents/constitutive/ConstitutiveBase.cpp index 6a821823a5f..8a2361a7570 100644 --- a/src/coreComponents/constitutive/ConstitutiveBase.cpp +++ b/src/coreComponents/constitutive/ConstitutiveBase.cpp @@ -72,6 +72,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 @@ -84,6 +89,8 @@ ConstitutiveBase::deliverClone( string const & name, wrapper.copyWrapper( this->getWrapperBase( wrapper.getName() ) ); } ); + newModel->setIsClone( true ); + return newModel; } diff --git a/src/coreComponents/constitutive/ConstitutiveBase.hpp b/src/coreComponents/constitutive/ConstitutiveBase.hpp index 622795bced0..adf7b26e796 100644 --- a/src/coreComponents/constitutive/ConstitutiveBase.hpp +++ b/src/coreComponents/constitutive/ConstitutiveBase.hpp @@ -114,8 +114,6 @@ class ConstitutiveBase : public dataRepository::Group bool isClone() const { return m_isClone; } - void setIsClone( bool const newState ) { m_isClone = newState; } - virtual std::vector< string > getSubRelationNames() const { return {}; } /** @@ -165,6 +163,8 @@ class ConstitutiveBase : public dataRepository::Group private: + void setIsClone( bool const newState ); + localIndex m_numQuadraturePoints; bool m_isClone; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index fc37eb5bbf2..64ba4d92bdb 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -105,7 +105,7 @@ CO2BrineFluid( string const & name, Group * const parent ): setInputFlag( InputFlags::OPTIONAL ). setRestartFlags( RestartFlags::NO_WRITE ). setDescription( "Write PVT tables into a CSV file" ). - setDefaultValue( 1 ); + setDefaultValue( 0 ); // if this is a thermal model, we need to make sure that the arrays will be properly displayed and saved to restart if( isThermal() ) @@ -138,7 +138,6 @@ deliverClone( string const & name, Group * const parent ) const newConstitutiveRelation.m_p1Index = m_p1Index; newConstitutiveRelation.m_p2Index = m_p2Index; - newConstitutiveRelation.setIsClone( true ); newConstitutiveRelation.createPVTModels(); return clone; diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp index 14e1cbd7aed..32f6ceee0f9 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp @@ -70,6 +70,7 @@ ReactiveBrineFluid( string const & name, Group * const parent ): setDescription( "Names of the files defining the parameters of the viscosity and density models" ); this->registerWrapper( viewKeyStruct::writeCSVFlagString(), &m_writeCSV ). + setApplyDefaultValue( 0 ). setInputFlag( InputFlags::OPTIONAL ). setRestartFlags( RestartFlags::NO_WRITE ). setDescription( "Write PVT tables into a CSV file" ); @@ -104,7 +105,6 @@ deliverClone( string const & name, Group * const parent ) const ReactiveBrineFluid & newConstitutiveRelation = dynamicCast< ReactiveBrineFluid & >( *clone ); - newConstitutiveRelation.setIsClone( true ); newConstitutiveRelation.createPVTModels(); return clone; diff --git a/src/coreComponents/schema/docs/CO2BrineEzrokhiFluid.rst b/src/coreComponents/schema/docs/CO2BrineEzrokhiFluid.rst index bbd0e58f1af..ea8921a885a 100644 --- a/src/coreComponents/schema/docs/CO2BrineEzrokhiFluid.rst +++ b/src/coreComponents/schema/docs/CO2BrineEzrokhiFluid.rst @@ -12,7 +12,7 @@ name groupName required A name is required for any non- phaseNames groupNameRef_array {} List of fluid phases phasePVTParaFiles path_array required Names of the files defining the parameters of the viscosity and density models solubilityTableNames string_array {} Names of solubility tables for each phase -writeCSV integer 1 Write PVT tables into a CSV file +writeCSV integer 0 Write PVT tables into a CSV file ==================== ================== ======== ============================================================================================================ diff --git a/src/coreComponents/schema/docs/CO2BrineEzrokhiThermalFluid.rst b/src/coreComponents/schema/docs/CO2BrineEzrokhiThermalFluid.rst index bbd0e58f1af..ea8921a885a 100644 --- a/src/coreComponents/schema/docs/CO2BrineEzrokhiThermalFluid.rst +++ b/src/coreComponents/schema/docs/CO2BrineEzrokhiThermalFluid.rst @@ -12,7 +12,7 @@ name groupName required A name is required for any non- phaseNames groupNameRef_array {} List of fluid phases phasePVTParaFiles path_array required Names of the files defining the parameters of the viscosity and density models solubilityTableNames string_array {} Names of solubility tables for each phase -writeCSV integer 1 Write PVT tables into a CSV file +writeCSV integer 0 Write PVT tables into a CSV file ==================== ================== ======== ============================================================================================================ diff --git a/src/coreComponents/schema/docs/CO2BrinePhillipsFluid.rst b/src/coreComponents/schema/docs/CO2BrinePhillipsFluid.rst index bbd0e58f1af..ea8921a885a 100644 --- a/src/coreComponents/schema/docs/CO2BrinePhillipsFluid.rst +++ b/src/coreComponents/schema/docs/CO2BrinePhillipsFluid.rst @@ -12,7 +12,7 @@ name groupName required A name is required for any non- phaseNames groupNameRef_array {} List of fluid phases phasePVTParaFiles path_array required Names of the files defining the parameters of the viscosity and density models solubilityTableNames string_array {} Names of solubility tables for each phase -writeCSV integer 1 Write PVT tables into a CSV file +writeCSV integer 0 Write PVT tables into a CSV file ==================== ================== ======== ============================================================================================================ diff --git a/src/coreComponents/schema/docs/CO2BrinePhillipsThermalFluid.rst b/src/coreComponents/schema/docs/CO2BrinePhillipsThermalFluid.rst index bbd0e58f1af..ea8921a885a 100644 --- a/src/coreComponents/schema/docs/CO2BrinePhillipsThermalFluid.rst +++ b/src/coreComponents/schema/docs/CO2BrinePhillipsThermalFluid.rst @@ -12,7 +12,7 @@ name groupName required A name is required for any non- phaseNames groupNameRef_array {} List of fluid phases phasePVTParaFiles path_array required Names of the files defining the parameters of the viscosity and density models solubilityTableNames string_array {} Names of solubility tables for each phase -writeCSV integer 1 Write PVT tables into a CSV file +writeCSV integer 0 Write PVT tables into a CSV file ==================== ================== ======== ============================================================================================================ diff --git a/src/coreComponents/schema/docs/Hydrofracture.rst b/src/coreComponents/schema/docs/Hydrofracture.rst index 250756df110..896a5cb77b0 100644 --- a/src/coreComponents/schema/docs/Hydrofracture.rst +++ b/src/coreComponents/schema/docs/Hydrofracture.rst @@ -1,27 +1,32 @@ -============================= =================================================================================================================================== ======== ====================================================================================================================================================================================================================================================================================================================== -Name Type Default Description -============================= =================================================================================================================================== ======== ====================================================================================================================================================================================================================================================================================================================== -cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] -contactRelationName groupNameRef required Name of contact relation to enforce constraints on fracture boundary. -flowSolverName groupNameRef required Name of the flow solver used by the coupled solver -initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. -isMatrixPoroelastic integer 0 (no description available) -isThermal integer 0 Flag indicating whether the problem is thermal or not. Set isThermal="1" to enable the thermal coupling -logLevel integer 0 Log level -maxNumResolves integer 10 Value to indicate how many resolves may be executed to perform surface generation after the execution of flow and mechanics solver. -name groupName required A name is required for any non-unique nodes -newFractureInitializationType geos_HydrofractureSolver >_InitializationType Pressure Type of new fracture element initialization. Can be Pressure or Displacement. -solidSolverName groupNameRef required Name of the solid solver used by the coupled solver -stabilizationMultiplier real64 1 Constant multiplier of stabilization strength -stabilizationRegionNames groupNameRef_array {} Regions where stabilization is applied. -stabilizationType geos_stabilization_StabilizationType None | StabilizationType. Options are: - | None- Add no stabilization to mass equation - | Global- Add jump stabilization to all faces - | Local- Add jump stabilization on interior of macro elements -surfaceGeneratorName groupNameRef required Name of the surface generator to use in the hydrofracture solver -targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. -useQuasiNewton integer 0 (no description available) -writeLinearSystem integer 0 Write matrix, rhs, solution to screen ( = 1) or file ( = 2). -LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` -NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` -============================= =================================================================================================================================== ======== ====================================================================================================================================================================================================================================================================================================================== \ No newline at end of file + + +===================================== =================================================================================================================================== ======== ====================================================================================================================================================================================================================================================================================================================== +Name Type Default Description +===================================== =================================================================================================================================== ======== ====================================================================================================================================================================================================================================================================================================================== +cflFactor real64 0.5 Factor to apply to the `CFL condition `_ when calculating the maximum allowable time step. Values should be in the interval (0,1] +contactRelationName groupNameRef required Name of contact relation to enforce constraints on fracture boundary. +flowSolverName groupNameRef required Name of the flow solver used by the coupled solver +initialDt real64 1e+99 Initial time-step value required by the solver to the event manager. +isLaggingFractureStencilWeightsUpdate integer 0 Flag to determine whether or not to apply lagging update for the fracture stencil weights. +isMatrixPoroelastic integer 0 (no description available) +isThermal integer 0 Flag indicating whether the problem is thermal or not. Set isThermal="1" to enable the thermal coupling +logLevel integer 0 Log level +maxNumResolves integer 10 Value to indicate how many resolves may be executed to perform surface generation after the execution of flow and mechanics solver. +name groupName required A name is required for any non-unique nodes +newFractureInitializationType geos_HydrofractureSolver >_InitializationType Pressure Type of new fracture element initialization. Can be Pressure or Displacement. +solidSolverName groupNameRef required Name of the solid solver used by the coupled solver +stabilizationMultiplier real64 1 Constant multiplier of stabilization strength +stabilizationRegionNames groupNameRef_array {} Regions where stabilization is applied. +stabilizationType geos_stabilization_StabilizationType None | StabilizationType. Options are: + | None- Add no stabilization to mass equation + | Global- Add jump stabilization to all faces + | Local- Add jump stabilization on interior of macro elements +surfaceGeneratorName groupNameRef required Name of the surface generator to use in the hydrofracture solver +targetRegions groupNameRef_array required Allowable regions that the solver may be applied to. Note that this does not indicate that the solver will be applied to these regions, only that allocation will occur such that the solver may be applied to these regions. The decision about what regions this solver will beapplied to rests in the EventManager. +useQuasiNewton integer 0 (no description available) +writeLinearSystem integer 0 Write matrix, rhs, solution to screen ( = 1) or file ( = 2). +LinearSolverParameters node unique :ref:`XML_LinearSolverParameters` +NonlinearSolverParameters node unique :ref:`XML_NonlinearSolverParameters` +===================================== =================================================================================================================================== ======== ====================================================================================================================================================================================================================================================================================================================== + + diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index e13d682f754..29685d6a2e1 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -4349,7 +4349,7 @@ The expected format is "{ waterMax, oilMax }", in that order--> - + @@ -4371,7 +4371,7 @@ The expected format is "{ waterMax, oilMax }", in that order--> - + @@ -4393,7 +4393,7 @@ The expected format is "{ waterMax, oilMax }", in that order--> - + @@ -4415,7 +4415,7 @@ The expected format is "{ waterMax, oilMax }", in that order--> - + From 83c80b2ca654aa0fa22d57ca0d0bdb3adfdcb880 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 4 Jul 2024 11:39:33 +0200 Subject: [PATCH 140/216] missing doxygen --- src/coreComponents/constitutive/ConstitutiveBase.hpp | 1 + .../constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp | 4 +--- .../constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/constitutive/ConstitutiveBase.hpp b/src/coreComponents/constitutive/ConstitutiveBase.hpp index adf7b26e796..a55ed038902 100644 --- a/src/coreComponents/constitutive/ConstitutiveBase.hpp +++ b/src/coreComponents/constitutive/ConstitutiveBase.hpp @@ -167,6 +167,7 @@ class ConstitutiveBase : public dataRepository::Group localIndex m_numQuadraturePoints; + /// Indicate if this constitutive model a clone bool m_isClone; }; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp index e88171dc190..0da26cab2c0 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp @@ -189,9 +189,7 @@ class CO2BrineFluid : public MultiFluidBase /// Index of the gas phase integer m_p2Index; - bool m_isClone = true; - - /// + /// Output csv file containing informations about PVT integer m_writeCSV; /// Brine constitutive models diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp index 84724b8eeff..5c82ef00856 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp @@ -55,7 +55,7 @@ struct PhaseModel * @param[in] inputParams input parameters read from files * @param[in] componentNames names of the components * @param[in] componentMolarWeight molar weights of the components - * @param[in] pvtOutputOpts Output struct options + * @param[in] pvtOutputOpts A structure containing generated table output options */ PhaseModel( string const & phaseModelName, array1d< array1d< string > > const & inputParams, From 5e8d0afdb2402703b5836d93d616070d8a0cc0ab Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 4 Jul 2024 14:21:49 +0200 Subject: [PATCH 141/216] remove unused code --- src/coreComponents/fileIO/Table/unitTests/testTable.cpp | 3 +-- src/coreComponents/functions/TableFunction.cpp | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index 123eb7f0d48..c606b18885c 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -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" diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 0438bf27590..d850e7d6bf8 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -278,7 +278,6 @@ string TableCSVFormatter::toString< TableFunction >( TableFunction const & table } else { - //1. TableData2D tableData2D; TableData2D::TableConversionData tableConverted; tableConverted = tableData2D.convertTable2D( values, @@ -286,9 +285,9 @@ string TableCSVFormatter::toString< TableFunction >( TableFunction const & table coordinates, units::getDescription( tableFunction.getDimUnit( 0 ) ), units::getDescription( tableFunction.getDimUnit( 1 ) ) ); - //2. + TableLayout tableLayout( tableConverted.headerNames ); - //3. + TableCSVFormatter csvFormat( tableLayout ); formatterStream << csvFormat.headerToString() << csvFormat.dataToString( tableConverted.tableData ); } From 547bf9e813a9e8e090525e62c1f769cd1284803a Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 8 Jul 2024 15:59:48 +0200 Subject: [PATCH 142/216] review melvin --- .../fluid/multifluid/CO2Brine/CO2BrineFluid.cpp | 12 ++++++++++-- .../fluid/multifluid/reactive/ReactiveBrineFluid.hpp | 2 +- src/coreComponents/fileIO/Table/TableData.cpp | 6 +++--- src/coreComponents/fileIO/Table/TableData.hpp | 6 +++--- .../fileIO/Table/unitTests/testTable.cpp | 4 ++-- src/coreComponents/functions/TableFunction.cpp | 4 ++-- src/coreComponents/functions/TableFunction.hpp | 5 +---- 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 64ba4d92bdb..44cd8496ecc 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -345,8 +345,16 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog }; - m_phase1 = std::make_unique< PHASE1 >( getName() + "_phaseModel1", phase1InputParams, m_componentNames, m_componentMolarWeight, pvtOutputOpts ); - m_phase2 = std::make_unique< PHASE2 >( getName() + "_phaseModel2", phase2InputParams, m_componentNames, m_componentMolarWeight, pvtOutputOpts ); + m_phase1 = std::make_unique< PHASE1 >( getName() + "_phaseModel1", + phase1InputParams, + m_componentNames, + m_componentMolarWeight, + pvtOutputOpts ); + m_phase2 = std::make_unique< PHASE2 >( getName() + "_phaseModel2", + phase2InputParams, + m_componentNames, + m_componentMolarWeight, + pvtOutputOpts ); // 2) Create the flash model diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp index 249d0e1fcc0..15984ffc79f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp @@ -168,7 +168,7 @@ class ReactiveBrineFluid : public ReactiveMultiFluid /// Names of the files defining the viscosity and density models path_array m_phasePVTParaFiles; - /// @brief + /// Output csv file containing informations about PVT integer m_writeCSV; /// Brine constitutive models diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 7d142d47a61..bb4c338e1ca 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -66,7 +66,7 @@ void TableData2D::collectTableValues( arraySlice1d< real64 const > rowAxisValues } } -TableData2D::TableConversionData TableData2D::convertTable2D( arrayView1d< real64 const > const values, +TableData2D::TableDataHolder TableData2D::convertTable2D( arrayView1d< real64 const > const values, units::Unit const valueUnit, ArrayOfArraysView< real64 const > const coordinates, string_view rowAxisDescription, @@ -81,11 +81,11 @@ TableData2D::TableConversionData TableData2D::convertTable2D( arrayView1d< real6 columnFmt ); } -TableData2D::TableConversionData TableData2D::buildTableData( string_view targetUnit, +TableData2D::TableDataHolder TableData2D::buildTableData( string_view targetUnit, string_view rowFmt, string_view columnFmt ) const { - TableData2D::TableConversionData tableData1D; + TableData2D::TableDataHolder tableData1D; std::vector< size_t > rowsLength; tableData1D.headerNames.push_back( string( targetUnit ) ); diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index c083e7fbe28..9d2568afad2 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -85,7 +85,7 @@ class TableData2D using ColumnType = real64; /// Struct containing conversion informations - struct TableConversionData + struct TableDataHolder { /// Vector containing all columns names /// A header value is presented as "pressure [K] = {}" @@ -122,7 +122,7 @@ class TableData2D * @param columnAxisDescription The description for a column unit value * @return A struct containing the tableData converted and all header values ; */ - TableData2D::TableConversionData convertTable2D( arrayView1d< real64 const > const values, + TableData2D::TableDataHolder convertTable2D( arrayView1d< real64 const > const values, units::Unit const valueUnit, ArrayOfArraysView< real64 const > const coordinates, string_view rowAxisDescription, @@ -137,7 +137,7 @@ 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] = {}" */ - TableConversionData 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 ] diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index c606b18885c..e17432860aa 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -210,7 +210,7 @@ TEST( testTable, table2DTable ) //convert string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::TableConversionData tableconverted = tableData.buildTableData( "Viscosity kg*s", + TableData2D::TableDataHolder tableconverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); @@ -248,7 +248,7 @@ TEST( testTable, table2DColumnMismatch ) //convert string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::TableConversionData tableConverted = tableData.buildTableData( "Viscosity kg*s", + TableData2D::TableDataHolder tableConverted = tableData.buildTableData( "Viscosity kg*s", rowFmt, columnFmt ); diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index d850e7d6bf8..1a286e52e2d 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -279,7 +279,7 @@ string TableCSVFormatter::toString< TableFunction >( TableFunction const & table else { TableData2D tableData2D; - TableData2D::TableConversionData tableConverted; + TableData2D::TableDataHolder tableConverted; tableConverted = tableData2D.convertTable2D( values, valueUnit, coordinates, @@ -330,7 +330,7 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl if( nX * nY <= 500 ) { TableData2D tableData2D; - TableData2D::TableConversionData tableConverted; + TableData2D::TableDataHolder tableConverted; tableConverted = tableData2D.convertTable2D( values, valueUnit, coordinates, diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index 03062c77aec..7622470ab15 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -323,10 +323,7 @@ class TableFunction : public FunctionBase /** * @return The table unit */ - units::Unit getValueUnit() const - { - return m_valueUnit; - } + units::Unit getValueUnit() const { return m_valueUnit; } /** * @brief Create an instance of the kernel wrapper From 37482aaef0e10e39bfe66f60a563bdc96564b228 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 8 Jul 2024 16:12:14 +0200 Subject: [PATCH 143/216] doxygen + uncrustify --- src/coreComponents/constitutive/ConstitutiveBase.hpp | 7 +++++++ .../fluid/multifluid/CO2Brine/CO2BrineFluid.cpp | 4 ---- .../fluid/multifluid/CO2Brine/CO2BrineFluid.hpp | 2 +- .../fluid/multifluid/reactive/ReactiveBrineFluid.hpp | 2 +- src/coreComponents/fileIO/Table/TableData.cpp | 12 ++++++------ src/coreComponents/fileIO/Table/TableData.hpp | 8 ++++---- .../fileIO/Table/unitTests/testTable.cpp | 8 ++++---- src/coreComponents/functions/TableFunction.cpp | 2 +- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/coreComponents/constitutive/ConstitutiveBase.hpp b/src/coreComponents/constitutive/ConstitutiveBase.hpp index a55ed038902..b4fc9ba1879 100644 --- a/src/coreComponents/constitutive/ConstitutiveBase.hpp +++ b/src/coreComponents/constitutive/ConstitutiveBase.hpp @@ -112,6 +112,9 @@ 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 {}; } @@ -163,6 +166,10 @@ 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; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 44cd8496ecc..e8ec244305c 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -243,10 +243,6 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::postInputInitialization() createPVTModels(); } -/** - * @brief Create a PVT Model and output them - * @param isClone If we are in the case of a clone of a constitutive mode, never the output - */ template< typename PHASE1, typename PHASE2, typename FLASH > void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() { diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp index 0da26cab2c0..bf973c47a65 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.hpp @@ -189,7 +189,7 @@ class CO2BrineFluid : public MultiFluidBase /// Index of the gas phase integer m_p2Index; - /// Output csv file containing informations about PVT + /// Output csv file containing informations about PVT integer m_writeCSV; /// Brine constitutive models diff --git a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp index 15984ffc79f..be2d67910e8 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.hpp @@ -168,7 +168,7 @@ class ReactiveBrineFluid : public ReactiveMultiFluid /// Names of the files defining the viscosity and density models path_array m_phasePVTParaFiles; - /// Output csv file containing informations about PVT + /// Output csv file containing informations about PVT integer m_writeCSV; /// Brine constitutive models diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index bb4c338e1ca..955bdd94528 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -67,10 +67,10 @@ void TableData2D::collectTableValues( arraySlice1d< real64 const > rowAxisValues } TableData2D::TableDataHolder TableData2D::convertTable2D( arrayView1d< real64 const > const values, - units::Unit const valueUnit, - ArrayOfArraysView< real64 const > const coordinates, - string_view rowAxisDescription, - string_view columnAxisDescription ) + 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 ); @@ -82,8 +82,8 @@ TableData2D::TableDataHolder TableData2D::convertTable2D( arrayView1d< real64 co } TableData2D::TableDataHolder TableData2D::buildTableData( string_view targetUnit, - string_view rowFmt, - string_view columnFmt ) const + string_view rowFmt, + string_view columnFmt ) const { TableData2D::TableDataHolder tableData1D; std::vector< size_t > rowsLength; diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 9d2568afad2..61d2574f683 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -123,10 +123,10 @@ class TableData2D * @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 ); + 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 diff --git a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp index e17432860aa..fd2e1436153 100644 --- a/src/coreComponents/fileIO/Table/unitTests/testTable.cpp +++ b/src/coreComponents/fileIO/Table/unitTests/testTable.cpp @@ -211,8 +211,8 @@ TEST( testTable, table2DTable ) string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); TableData2D::TableDataHolder tableconverted = tableData.buildTableData( "Viscosity kg*s", - rowFmt, - columnFmt ); + rowFmt, + columnFmt ); //format TableLayout const tableLayout( tableconverted.headerNames ); @@ -249,8 +249,8 @@ TEST( testTable, table2DColumnMismatch ) string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); TableData2D::TableDataHolder tableConverted = tableData.buildTableData( "Viscosity kg*s", - rowFmt, - columnFmt ); + rowFmt, + columnFmt ); //format TableLayout const tableLayout( tableConverted.headerNames ); diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 1a286e52e2d..c82e6e99769 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -287,7 +287,7 @@ string TableCSVFormatter::toString< TableFunction >( TableFunction const & table units::getDescription( tableFunction.getDimUnit( 1 ) ) ); TableLayout tableLayout( tableConverted.headerNames ); - + TableCSVFormatter csvFormat( tableLayout ); formatterStream << csvFormat.headerToString() << csvFormat.dataToString( tableConverted.tableData ); } From 7e7492daf7d71ad9d1c459011d1408eaa3aa3c96 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 8 Jul 2024 16:14:11 +0200 Subject: [PATCH 144/216] revert space applied --- src/coreComponents/mainInterface/ProblemManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coreComponents/mainInterface/ProblemManager.cpp b/src/coreComponents/mainInterface/ProblemManager.cpp index 0dca8195b97..1b2e3a1b0a9 100644 --- a/src/coreComponents/mainInterface/ProblemManager.cpp +++ b/src/coreComponents/mainInterface/ProblemManager.cpp @@ -718,6 +718,7 @@ void ProblemManager::importFields() void ProblemManager::applyNumericalMethods() { + DomainPartition & domain = getDomainPartition(); ConstitutiveManager & constitutiveManager = domain.getGroup< ConstitutiveManager >( groupKeys.constitutiveManager ); Group & meshBodies = domain.getMeshBodies(); @@ -729,9 +730,12 @@ void ProblemManager::applyNumericalMethods() setRegionQuadrature( meshBodies, constitutiveManager, regionQuadrature ); } + + map< std::pair< string, Group const * const >, arrayView1d< string const > const > ProblemManager::getDiscretizations() const { + map< std::pair< string, Group const * const >, arrayView1d< string const > const > meshDiscretizations; NumericalMethodsManager const & From d6c3a8a4736dc3bc7722ebbb100548275a6ed614 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 8 Jul 2024 16:14:35 +0200 Subject: [PATCH 145/216] uncrustify --- src/coreComponents/mainInterface/ProblemManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/mainInterface/ProblemManager.cpp b/src/coreComponents/mainInterface/ProblemManager.cpp index 1b2e3a1b0a9..0bb27174919 100644 --- a/src/coreComponents/mainInterface/ProblemManager.cpp +++ b/src/coreComponents/mainInterface/ProblemManager.cpp @@ -735,7 +735,7 @@ void ProblemManager::applyNumericalMethods() map< std::pair< string, Group const * const >, arrayView1d< string const > const > ProblemManager::getDiscretizations() const { - + map< std::pair< string, Group const * const >, arrayView1d< string const > const > meshDiscretizations; NumericalMethodsManager const & From c0c1d6bf620704411ee5a45758c86bb1c4538355 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 12 Jul 2024 16:55:39 +0200 Subject: [PATCH 146/216] nb character lines fix --- src/coreComponents/fileIO/Table/TableData.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreComponents/fileIO/Table/TableData.hpp b/src/coreComponents/fileIO/Table/TableData.hpp index 61d2574f683..7511fde7e30 100644 --- a/src/coreComponents/fileIO/Table/TableData.hpp +++ b/src/coreComponents/fileIO/Table/TableData.hpp @@ -137,7 +137,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] = {}" */ - TableDataHolder 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 ] From 3c0997a6212a7375996f646fa87ab5874f878b8f Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 25 Jul 2024 14:37:07 +0200 Subject: [PATCH 147/216] fix print screen level condition --- .../constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index e8ec244305c..e3723f9a994 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -338,7 +338,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() bool const isClone = this->isClone(); PVTFunctionBase::TableOutputOptions const pvtOutputOpts = { !isClone && m_writeCSV,// writeCSV - !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog + !isClone && (getLogLevel() > 0 && logger::internal::rank==0), // writeInLog }; m_phase1 = std::make_unique< PHASE1 >( getName() + "_phaseModel1", @@ -374,7 +374,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() { FlashModelBase::TableOutputOptions const flashOutputOpts = { !isClone && m_writeCSV,// writeCSV - !isClone && (getLogLevel() >= 0 && logger::internal::rank==0), // writeInLog + !isClone && (getLogLevel() > 0 && logger::internal::rank==0), // writeInLog }; m_flash = std::make_unique< FLASH >( getName() + '_' + FLASH::catalogName(), strs, From 53d4ea0201f6fc8a827596506b93395321bcefaf Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 21 Aug 2024 15:35:00 +0200 Subject: [PATCH 148/216] small fix --- src/coreComponents/functions/TableFunction.hpp | 2 +- .../schema/docs/HydraulicApertureTable.rst | 12 ++++++++++++ .../schema/docs/HydraulicApertureTable_other.rst | 9 +++++++++ src/coreComponents/schema/docs/VTKMesh.rst | 4 ++-- src/coreComponents/schema/schema.xsd | 8 ++++---- 5 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/coreComponents/schema/docs/HydraulicApertureTable.rst create mode 100644 src/coreComponents/schema/docs/HydraulicApertureTable_other.rst diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index 0c4be7b52af..93cd1df2dbd 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -24,7 +24,7 @@ #include "codingUtilities/EnumStrings.hpp" #include "LvArray/src/tensorOps.hpp" -#include "fileIO/Table/TableFormatter.hpp" +#include "common/format/table/TableFormatter.hpp" #include "common/Units.hpp" namespace geos diff --git a/src/coreComponents/schema/docs/HydraulicApertureTable.rst b/src/coreComponents/schema/docs/HydraulicApertureTable.rst new file mode 100644 index 00000000000..396fc421971 --- /dev/null +++ b/src/coreComponents/schema/docs/HydraulicApertureTable.rst @@ -0,0 +1,12 @@ + + +================= ============ ======== ============================================================================================================================================================================================================================================================================================================================================================================================================================================================= +Name Type Default Description +================= ============ ======== ============================================================================================================================================================================================================================================================================================================================================================================================================================================================= +apertureTableName groupNameRef required Name of the aperture table +apertureTolerance real64 1e-09 Value to be used to avoid floating point errors in expressions involving aperture. For example in the case of dividing by the actual aperture (not the effective aperture that results from the aperture function) this value may be used to avoid the 1/0 error. Note that this value may have some physical significance in its usage, as it may be used to smooth out highly nonlinear behavior associated with 1/0 in addition to avoiding the 1/0 error. +name groupName required A name is required for any non-unique nodes +referenceAperture real64 1e-06 Reference hydraulic aperture. It is the aperture at zero normal stress. +================= ============ ======== ============================================================================================================================================================================================================================================================================================================================================================================================================================================================= + + diff --git a/src/coreComponents/schema/docs/HydraulicApertureTable_other.rst b/src/coreComponents/schema/docs/HydraulicApertureTable_other.rst new file mode 100644 index 00000000000..adf1c1b8aec --- /dev/null +++ b/src/coreComponents/schema/docs/HydraulicApertureTable_other.rst @@ -0,0 +1,9 @@ + + +==== ==== ============================ +Name Type Description +==== ==== ============================ + (no documentation available) +==== ==== ============================ + + diff --git a/src/coreComponents/schema/docs/VTKMesh.rst b/src/coreComponents/schema/docs/VTKMesh.rst index 3c6616c3087..f8365fa847f 100644 --- a/src/coreComponents/schema/docs/VTKMesh.rst +++ b/src/coreComponents/schema/docs/VTKMesh.rst @@ -4,7 +4,7 @@ Name Type Default Description ====================== ======================== ========= ============================================================================================================================================================================================================================================================================================================================================================================================================================================================================ faceBlocks groupNameRef_array {} For multi-block files, names of the face mesh block. -fieldNamesInGEOS groupNameRef_array {} Names of the volumic fields in GEOS to import into +fieldNamesInGEOS groupNameRef_array {} Names of the volumic fields in GEOS to import into fieldsToImport groupNameRef_array {} Volumic fields to be imported from the external mesh file file path required Path to the mesh file logLevel integer 0 Log level @@ -15,7 +15,7 @@ partitionMethod geos_vtk_PartitionMethod parmetis Method (library) used partitionRefinement integer 1 Number of partitioning refinement iterations (defaults to 1, recommended value).A value of 0 disables graph partitioning and keeps simple kd-tree partitions (not recommended). Values higher than 1 may lead to slightly improved partitioning, but yield diminishing returns. regionAttribute groupNameRef attribute Name of the VTK cell attribute to use as region marker scale R1Tensor {1,1,1} Scale the coordinates of the vertices by given scale factors (after translation) -surfacicFieldsInGEOS groupNameRef_array {} Names of the surfacic fields in GEOS to import into +surfacicFieldsInGEOS groupNameRef_array {} Names of the surfacic fields in GEOS to import into surfacicFieldsToImport groupNameRef_array {} Surfacic fields to be imported from the external mesh file translate R1Tensor {0,0,0} Translate the coordinates of the vertices by a given vector (prior to scaling) useGlobalIds integer 0 Controls the use of global IDs in the input file for cells and points. If set to 0 (default value), the GlobalId arrays in the input mesh are used if available, and generated otherwise. If set to a negative value, the GlobalId arrays in the input mesh are not used, and generated global Ids are automatically generated. If set to a positive value, the GlobalId arrays in the input mesh are used and required, and the simulation aborts if they are not available diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index 69d60e83e18..2e674e258d6 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -1691,8 +1691,8 @@ stress - traction is applied to the faces as specified by the inner product of i - - + + @@ -1711,8 +1711,8 @@ stress - traction is applied to the faces as specified by the inner product of i - - + + From 49c939c7895f8ad1ff36e86f85c2dc9fa70e7d0d Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 22 Aug 2024 10:10:18 +0200 Subject: [PATCH 149/216] small change in path indaction --- .../fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp index 3cca4d52f0e..644dfc09e16 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp @@ -128,7 +128,7 @@ class FlashModelBase { string const filename = tableData->getName(); std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); - GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to inputFiles/compositionalMultiphaseWell/{}/{}.csv \n", + GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to {}/{}.csv \n", OutputBase::getOutputDirectory(), filename )); From b707111c7bc85db310087c8c3c59d92314144fb3 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 6 Sep 2024 14:01:11 +0200 Subject: [PATCH 150/216] [DRAFT] column fill with subvalues --- .../common/format/table/TableFormatter.cpp | 196 ++++++++++++++---- .../common/format/table/TableFormatter.hpp | 16 +- .../common/format/table/TableLayout.cpp | 48 ++++- .../common/format/table/TableLayout.hpp | 30 ++- .../format/table/unitTests/testTable.cpp | 30 +++ .../CO2Brine/functions/FlashModelBase.hpp | 5 +- .../CO2Brine/functions/PVTFunctionBase.hpp | 5 +- .../functions/TableFunction.cpp | 2 +- 8 files changed, 262 insertions(+), 70 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 719cc2f2192..9f71a367388 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -21,6 +21,7 @@ #include #include "common/format/StringUtilities.hpp" #include "TableFormatter.hpp" + namespace geos { @@ -78,6 +79,17 @@ string TableCSVFormatter::toString< TableData >( TableData const & tableData ) c ////// Log Formatter implementation /////////////////////////////////////////////////////////////////////// +void transpose( std::vector< std::vector< std::string > > & dest, std::vector< std::vector< std::string > > & source ) +{ + for( size_t idxRow = 0; idxRow < source.size(); ++idxRow ) + { + for( size_t idxCol = 0; idxCol < source[idxRow].size(); ++idxCol ) + { + dest[idxCol][idxRow] = source[idxRow][idxCol]; + } + } +} + /** * @brief Build cell given an alignment, a value and spaces * @param alignment The aligment of cell value @@ -128,23 +140,54 @@ TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): {} void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > & rows ) const + std::vector< std::vector< string > > const & columnsValues ) const { - for( size_t idxRow = 0; idxRow < rows.size(); idxRow++ ) + size_t realNbColumn = 0; + size_t columnWithSubColumns = 0; + + // Compute index column because we will iterate through columnsValues + for( auto & column : columns ) { - if( rows[idxRow].size() < columns.size() ) + if( column.subColumn.empty()) { - rows[idxRow].resize( columns.size(), " " ); + ++realNbColumn; } + else + { + ++columnWithSubColumns; + realNbColumn += columnWithSubColumns - column.m_parameter.subColumns.size(); + } + } - for( size_t idxColumn = 0; idxColumn < columns.size(); idxColumn++ ) + std::vector< std::vector< std::string > > subColumnValues; + auto currentColumn = 0; + for( size_t idxRow = 0; idxRow < realNbColumn; idxRow++ ) + { + auto & column = columns[idxRow]; + if( column.subColumn.size() > 0 ) { - if( m_tableLayout.getColumns()[idxColumn].m_parameter.enabled ) - { - columns[idxColumn].m_columnValues.push_back( rows[idxRow][idxColumn] ); - } + auto startSubColumn = columnsValues.begin() + currentColumn; + auto endSubColumn = columnsValues.begin() + currentColumn + column.m_parameter.subColumns.size(); + subColumnValues = std::vector< std::vector< std::string > >( startSubColumn, endSubColumn ); + fillTableColumnsFromRows( column.subColumn, subColumnValues ); + currentColumn += column.subColumn.size(); + } + else + { + column.m_columnValues = columnsValues[currentColumn++]; } + } + + for( const auto & row : columnsValues ) + { + for( const auto & value : row ) + { + std::cout << value << " "; + } + std::cout << std::endl; + } + std::cout << "End fillTableColumnsFromRows" << std::endl; } string TableTextFormatter::layoutToString() const @@ -166,12 +209,15 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); std::vector< string > const & msgTableError = tableData.getErrorMsgs(); integer const nbValuesRows = tableDataRows.size(); - formatColumnsFromLayout( columns, tableDataRows ); - fillTableColumnsFromRows( columns, tableDataRows ); + + std::vector< std::vector< std::string > > columnsValues( tableDataRows[0].size(), std::vector< std::string >( tableDataRows.size())); + transpose( columnsValues, tableDataRows ); + + fillTableColumnsFromRows( columns, columnsValues ); outputLayout( tableOutput, columns, msgTableError, sectionSeparatingLine ); - outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbValuesRows, TableLayout::Section::values ); + outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbValuesRows, 0, TableLayout::Section::values ); tableOutput << '\n'; return tableOutput.str(); @@ -188,17 +234,23 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, string const tableTitle = string( m_tableLayout.getTitle()); splitAndSetColumnNames( columns, nbHeaderRows, splitHeaders ); - findAndSetMaxStringSize( columns ); + std::cout << "split finished " << std::endl; + std::string maxStringSize = " "; + findAndSetMaxStringSize( columns, maxStringSize ); + std::cout << "find finished " << std::endl; computeTableWidth( columns, msgTableError ); + std::cout << "computeTableWidth finished " << std::endl; buildTableSeparators( columns, topSeparator, sectionSeparatingLine ); + std::cout << "buildTableSeparators finished " << std::endl; tableOutput << '\n'; outputTopRows( tableOutput, {tableTitle}, topSeparator, TableLayout::Alignment::center ); outputTopRows( tableOutput, msgTableError, topSeparator, TableLayout::Alignment::left ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbHeaderRows, TableLayout::Section::header ); + outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbHeaderRows, 0, TableLayout::Section::header ); + std::cout << "outputSectionRows finished " << tableOutput.str() < & columns, @@ -207,7 +259,7 @@ void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Colum { splitHeaders.reserve( columns.size() ); - for( auto const & column : columns ) + for( auto & column : columns ) { std::vector< string > splitHeaderParts; std::istringstream ss( column.m_parameter.columnName ); @@ -219,6 +271,13 @@ void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Colum } splitHeaders.push_back( std::move( splitHeaderParts ) ); + + if( !column.subColumn.empty()) + { + std::vector< std::vector< string > > splitSubColHeaders; + size_t nbHeaderSubColRows = 0; + splitAndSetColumnNames( column.subColumn, nbHeaderSubColRows, splitSubColHeaders ); + } } nbHeaderRows = std::max_element( splitHeaders.begin(), splitHeaders.end(), @@ -235,14 +294,23 @@ void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Colum } -void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns ) const +void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, std::string & maxStringSize ) const { + std::vector< std::string > maxStringsColumn; + maxStringsColumn.reserve( columns.size()); + + // max header columns length for( auto & column : columns ) { auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnNameLines.begin(), column.m_parameter.splitColumnNameLines.end(), []( const auto & a, const auto & b ) {return a.size() < b.size();} ); column.m_maxStringSize = maxStringSizeHeader; + maxStringsColumn.push_back( column.m_parameter.columnName ); + } + + for( auto & column : columns ) + { for( auto const & cell : column.m_columnValues ) { @@ -251,6 +319,19 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu column.m_maxStringSize = cell; } } + + if( !column.subColumn.empty()) + { + findAndSetMaxStringSize( column.subColumn, column.m_maxStringSize ); + } + std::cout << "verif max string size before " << column.m_maxStringSize << std::endl; + if( column.m_maxStringSize.length() > maxStringSize.length()) + { + maxStringSize = std::accumulate( maxStringsColumn.begin(), maxStringsColumn.end(), std::string()); + } + + std::cout << "verif max string size after " << column.m_maxStringSize << std::endl; + } } @@ -272,24 +353,24 @@ void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > } } -void computeTableErrorLength( std::vector< string > const & msgTableError, string::size_type & msgTableErrorLength ) +void computeTableSectionLength( std::vector< TableLayout::Column > & columns, string::size_type & sectionlineLength, string_view maxColumnStringSize ) { - if( !msgTableError.empty() ) + sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, + [&]( auto sum, auto & column ) -> auto { - auto maxStringSize = *(std::max_element( msgTableError.begin(), msgTableError.end(), - []( const auto & a, const auto & b ) { - return a.size() < b.size(); - } )); - - msgTableErrorLength += maxStringSize.size() + 1; // max string size + line return at the end - } -} + if( !column.subColumn.empty()) + { + computeTableSectionLength( column.subColumn, sectionlineLength, column.m_maxStringSize ); + } -void computeTableSectionLength( std::vector< TableLayout::Column > & columns, string::size_type & sectionlineLength ) -{ - sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, - []( auto sum, const auto & column ) - { return sum + column.m_maxStringSize.length();} ); + if( !column.m_maxStringSize.compare( maxColumnStringSize )) + { + return sum; + } + std::cout << " alors je calcul" << column.m_maxStringSize << " egal " << sum << std::endl; + return static_cast< decltype(sum) >(sum + column.m_maxStringSize.length()); + } ); + std::cout << " fincalcul" << sectionlineLength << std::endl; } void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & columns, @@ -299,14 +380,26 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & integer const borderMargin = m_tableLayout.getBorderMargin(); string const tableTitle = string( m_tableLayout.getTitle() ); - string::size_type sectionLengthWithSpacing = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); - string::size_type sectionlineLength = sectionLengthWithSpacing; - string::size_type maxTopLineLength = tableTitle.length(); + // compute table error msg length string::size_type msgTableErrorLength = borderMargin; + { + if( !msgTableError.empty() ) + { + auto maxStringSize = *(std::max_element( msgTableError.begin(), msgTableError.end(), + []( const auto & a, const auto & b ) { + return a.size() < b.size(); + } )); - computeTableErrorLength( msgTableError, msgTableErrorLength ); - computeTableSectionLength( columns, sectionlineLength ); + msgTableErrorLength += maxStringSize.size() + 1; // max string size + line return at the end + } + } + // compute table section length + string::size_type sectionLengthWithSpacing = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); + string::size_type sectionlineLength = sectionLengthWithSpacing; + computeTableSectionLength( columns, sectionlineLength, " " ); + + string::size_type maxTopLineLength = tableTitle.length(); maxTopLineLength = std::max( maxTopLineLength, msgTableErrorLength ); if( sectionlineLength < maxTopLineLength ) { @@ -320,7 +413,7 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column string & topSeparator, string & sectionSeparatingLine ) const { - { // section separator line + { // section separator line integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); @@ -341,8 +434,8 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column sectionSeparatingLine = oss.str(); } - { // top line separator - // -2 because we can have '+' to the extremity of top separator + { // top line separator + // -2 because we can have '+' to the extremity of top separator integer const topSeparatorLength = sectionSeparatingLine.size() - 2; topSeparator = GEOS_FMT( "{}{:-<{}}{}", m_horizontalLine, "", topSeparatorLength, m_horizontalLine ); } @@ -369,21 +462,26 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c string_view sectionSeparatingLine, std::ostringstream & tableOutput, integer const nbRows, + size_t const nbSubColumns, TableLayout::Section const section ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); - - for( integer idxRow = 0; idxRow< nbRows; ++idxRow ) + size_t const nbColumns = nbSubColumns + columns.size(); + std::cout << nbRows << std::endl; + std::cout << nbColumns << std::endl; + std::cout << "testeuh"<< std::endl; + for( auto idxRow = 0; idxRow< nbRows; ++idxRow ) { // Append the left border tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, 1 + borderMargin ); - for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) + for( std::size_t idxColumn = 0; idxColumn < nbColumns; ++idxColumn ) { - TableLayout::Column const currentColumn = columns[idxColumn]; + auto & column = columns[idxColumn]; + TableLayout::Column const currentColumn = column; auto const & columnContent = section == TableLayout::Section::header ? - columns[idxColumn].m_parameter.splitColumnNameLines : - columns[idxColumn].m_columnValues; + column.m_parameter.splitColumnNameLines : + column.m_columnValues; string cell = columnContent.at( idxRow ); integer const cellSize = currentColumn.m_maxStringSize.length(); @@ -394,17 +492,23 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c { tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } - } // Append right border with line return tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, borderMargin + 1 ); + + // if( !column.subColumn.empty() ) + // { + // outputSectionRows( column.subColumn, sectionSeparatingLine, tableOutput, nbRows, columns.size(), section ); + // } } if( nbRows != 0 ) { tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); } + + } } diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 6e114278606..ee62efa2623 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -161,7 +161,7 @@ class TableTextFormatter : public TableFormatter * @param tableData Vector containing all rows filled with values */ void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > & tableData ) const; + std::vector< std::vector< string > > const & tableData ) const; /** * @brief Converts a TableLayout into a formatted representation. @@ -190,7 +190,7 @@ class TableTextFormatter : public TableFormatter * @brief For each column find and set the column's longest string * @param columns The vector containg all columns */ - void findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns ) const; + void findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, std::string & maxStringSize ) const; /** * @brief recalculate the largest string size for each columns @@ -237,14 +237,16 @@ class TableTextFormatter : public TableFormatter * @param sectionSeparatingLine Line separator between sections * @param rows A section row * @param nbRows Indicates the number of lines in a section + * @param nbSubColumns * @param section The section to be built * @note Add the ending line if there are one or more rows */ - void outputSectionRows( std::vector< TableLayout::Column > const & columns, - string_view sectionSeparatingLine, - std::ostringstream & rows, - integer const nbRows, - TableLayout::Section const section ) const; + void outputSectionRows( std::vector< TableLayout::Column > const & columns, + string_view sectionSeparatingLine, + std::ostringstream & tableOutput, + integer const nbRows, + size_t const nbSubColumns, + TableLayout::Section const section ) const; }; /** diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index b3de6f6b917..bc4fdb668e7 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -16,12 +16,44 @@ /** * @file TableData.hpp */ - #include "TableLayout.hpp" namespace geos { +void addColumn( std::vector< TableLayout::ColumnParam > const & columnsParam, std::vector< TableLayout::Column > & columns ) +{ + for( const auto & columnParam : columnsParam ) + { + std::cout << "columnParam -- " << columnParam.columnName << std::endl; + bool subColum = false; + std::vector< TableLayout::Column > subColumnsToAdd; + TableLayout::Column columnToAdd = {columnParam, {}, "", {}}; + for( const auto & subColumnsName: columnParam.subColumns ) + { + std::cout << "subColumnsParam -- " << subColumnsName << std::endl; + subColum = true; + TableLayout::Column subColumn= {subColumnsName, {}, "", {}}; + subColumnsToAdd.push_back( subColumn ); + columnToAdd = { columnParam, {}, "", subColumnsToAdd }; + } + if( subColum ) + { + columns.push_back( columnToAdd ); + } + else + { + columns.push_back( { columnParam, {}, "", {}} ); + } + } + + for( auto const & columnt : columns ) + { + std::cout << "regarde après le addColumn " << columnt.m_parameter.columnName << std::endl ; + } + +} + TableLayout::TableLayout( std::vector< string > const & columnNames, string const & title ): m_tableTitle( title ) { @@ -29,21 +61,21 @@ TableLayout::TableLayout( std::vector< string > const & columnNames, string cons m_columns.reserve( columnNames.size() ); for( auto const & name : columnNames ) { - m_columns.push_back( {TableLayout::ColumnParam{{name}, Alignment::right, true}, {}, ""} ); + m_columns.push_back( {TableLayout::ColumnParam{{name}, Alignment::right, true}, {}, "", {}} ); } } -TableLayout::TableLayout( std::vector< ColumnParam > const & columnParameters, string const & title ): +TableLayout::TableLayout( std::vector< ColumnParam > const & columnParams, string const & title ): m_tableTitle( title ) { setMargin( MarginValue::medium ); - m_columns.reserve( columnParameters.size() ); - for( auto const & param : columnParameters ) - { - m_columns.push_back( { param, {}, ""} ); - } + //m_columns.reserve( columnParams.size() ); + std::cout << "TEST ADD COLUMN " << std::endl; + addColumn( columnParams, m_columns ); + } + void TableLayout::setMargin( MarginValue marginValue ) { m_borderMargin = marginValue; diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index edd56c41c16..7f74af3bcc8 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -21,6 +21,7 @@ #define GEOS_COMMON_FORMAT_TABLE_TABLELAYOUT_HPP #include "common/DataTypes.hpp" +#include namespace geos { @@ -32,7 +33,6 @@ class TableLayout { public: - /// Type of aligment for a column enum Alignment { right, left, center }; @@ -61,9 +61,19 @@ class TableLayout Alignment alignment = Alignment::right; /// A boolean to display a colummn bool enabled = true; + /// + std::vector< string > subColumns; /// Vector containing substring column name delimited by "\n" std::vector< string > splitColumnNameLines; + /** + * @brief Construct a ColumnParam object with the specified name and alignment. + * @param name The name of the column + */ + ColumnParam( std::string const & name ) + : columnName( name ) + {} + /** * @brief Construct a ColumnParam object with the specified name and alignment. * @param name The name of the column @@ -82,6 +92,16 @@ class TableLayout ColumnParam( std::string const & name, Alignment align, bool display ) : columnName( name ), alignment( align ), enabled( display ) {} + + /** + * @brief Construct a ColumnParam object with the specified name, alignment, and display flag. + * @param name The name of the column + * @param align The alignment of the column + * @param display Flag indicating whether the column is enabled + */ + ColumnParam( std::string const & name, Alignment align, bool display, std::vector< string > columns ) + : columnName( name ), alignment( align ), enabled( display ), subColumns( columns ) + {} }; /** @@ -95,6 +115,9 @@ class TableLayout std::vector< string > m_columnValues; /// The largest string in the column string m_maxStringSize; + //sub divison of a column + std::vector< Column > subColumn; + }; TableLayout() = default; @@ -103,14 +126,17 @@ class TableLayout * @brief Construct a new Table object, all values in the table are centered by default * @param columnNames The names of the columns * @param title The table name + * @param subColumns */ - TableLayout( std::vector< string > const & columnNames, string const & title = "" ); + TableLayout( std::vector< string > const & columnNames, + string const & title = "" ); /** * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels * level * @param columnParameters List of structures to set up each colum parameters. * @param title The table name + * @param subColumns */ TableLayout( std::vector< ColumnParam > const & columnParameters, string const & title = "" ); diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index d7a6cd9abbe..7167d4aa6b5 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -289,6 +289,36 @@ TEST( testTable, layoutTable ) ); } +// TEST( testTable, subColumns ) +// { +// { +// //format +// TableLayout const tableLayout( +// {TableLayout::ColumnParam{" ", TableLayout::Alignment::right}} +// {TableLayout::ColumnParam{"Column1", TableLayout::Alignment::right}}, +// {TableLayout::ColumnParam{"Nodes ", TableLayout::Alignment::right, {"Local, Ghost"}}}, +// {TableLayout::ColumnParam{"Column3", TableLayout::Alignment::right}} +// ); + +// TableData tableData; +// tableData.addRow( "min", "125", "375,000", 23,562, 2.0f); +// tableData.addRow( "max", "360", "390,150", 38,712, 10.0f ); + +// TableTextFormatter const tableLog( tableLayout ); +// EXPECT_EQ( tableLog.toString( tableData ), +// "\n--------------------------------------------------------------------\n" +// "| Remarks : some cells may be missing |\n" +// "--------------------------------------------------------------------\n" +// "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" +// "--------------------------------------------------------------------\n" +// "| Temperature = 300 | 0.03 | 0.02 |\n" +// "| Temperature = 350 | 0.035 | |\n" +// "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" +// "--------------------------------------------------------------------\n\n" +// ); +// } +// } + TEST( testTable, tableSetMargin ) { //////////// diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp index 644dfc09e16..e0fa430003f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp @@ -21,7 +21,6 @@ #define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_FUNCTIONS_FLASHMODELBASE_HPP_ #include "dataRepository/ObjectCatalog.hpp" -#include "fileIO/Outputs/OutputBase.hpp" #include "functions/TableFunction.hpp" namespace geos @@ -127,9 +126,9 @@ class FlashModelBase if( pvtOutputOpts.writeCSV || ( pvtOutputOpts.writeInLog && tableData->numDimensions() >= 3 ) ) { string const filename = tableData->getName(); - std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); + std::ofstream logStream( joinPath( FunctionBase::getOutputDirectory(), filename + ".csv" ) ); GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to {}/{}.csv \n", - OutputBase::getOutputDirectory(), + FunctionBase::getOutputDirectory(), filename )); TableCSVFormatter csvFormatter; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index 95042cdd910..d5e838b996f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -21,7 +21,6 @@ #define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_FUNCTIONS_PVTFUNCTIONBASE_HPP_ #include "dataRepository/ObjectCatalog.hpp" -#include "fileIO/Outputs/OutputBase.hpp" #include "functions/TableFunction.hpp" namespace geos @@ -168,9 +167,9 @@ class PVTFunctionBase if( pvtOutputOpts.writeCSV || ( pvtOutputOpts.writeInLog && tableData->numDimensions() >= 3 ) ) { string const filename = tableData->getName(); - std::ofstream logStream( joinPath( OutputBase::getOutputDirectory(), filename + ".csv" ) ); + std::ofstream logStream( joinPath( FunctionBase::getOutputDirectory(), filename + ".csv" ) ); GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to {}/{}.csv \n", - OutputBase::getOutputDirectory(), + FunctionBase::getOutputDirectory(), filename )); TableCSVFormatter csvFormatter; logStream << csvFormatter.toString( *tableData ); diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 6208f04a8e1..f852e3da3d3 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -317,7 +317,7 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl tableData.addRow( coords[idx], values[idx] ); } - TableLayout const tableLayout( { + TableLayout const tableLayout( std::vector{ string( units::getDescription( tableFunction.getDimUnit( 0 ))), string( units::getDescription( valueUnit )) }, filename ); From d486a8a8bc4370a9006aea746f9d9076c6aebd33 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 6 Sep 2024 15:48:06 +0200 Subject: [PATCH 151/216] [DRAFT ] subsection draw --- .../common/format/table/TableFormatter.cpp | 77 +++++++++++++------ .../common/format/table/TableFormatter.hpp | 2 - .../common/format/table/TableLayout.cpp | 2 - .../common/format/table/TableLayout.hpp | 2 +- 4 files changed, 53 insertions(+), 30 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 9f71a367388..89adffd446d 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -187,7 +187,6 @@ void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Col } std::cout << std::endl; } - std::cout << "End fillTableColumnsFromRows" << std::endl; } string TableTextFormatter::layoutToString() const @@ -217,7 +216,7 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) fillTableColumnsFromRows( columns, columnsValues ); outputLayout( tableOutput, columns, msgTableError, sectionSeparatingLine ); - outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbValuesRows, 0, TableLayout::Section::values ); + outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbValuesRows, TableLayout::Section::values ); tableOutput << '\n'; return tableOutput.str(); @@ -234,22 +233,20 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, string const tableTitle = string( m_tableLayout.getTitle()); splitAndSetColumnNames( columns, nbHeaderRows, splitHeaders ); - std::cout << "split finished " << std::endl; + std::string maxStringSize = " "; findAndSetMaxStringSize( columns, maxStringSize ); - std::cout << "find finished " << std::endl; computeTableWidth( columns, msgTableError ); - std::cout << "computeTableWidth finished " << std::endl; buildTableSeparators( columns, topSeparator, sectionSeparatingLine ); - std::cout << "buildTableSeparators finished " << std::endl; tableOutput << '\n'; outputTopRows( tableOutput, {tableTitle}, topSeparator, TableLayout::Alignment::center ); outputTopRows( tableOutput, msgTableError, topSeparator, TableLayout::Alignment::left ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbHeaderRows, 0, TableLayout::Section::header ); + outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbHeaderRows, TableLayout::Section::header ); + //subcolumn std::cout << "outputSectionRows finished " << tableOutput.str() < maxStringsColumn; maxStringsColumn.reserve( columns.size()); - // max header columns length + // max header columns length for( auto & column : columns ) { auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnNameLines.begin(), @@ -324,14 +321,25 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu { findAndSetMaxStringSize( column.subColumn, column.m_maxStringSize ); } - std::cout << "verif max string size before " << column.m_maxStringSize << std::endl; + if( column.m_maxStringSize.length() > maxStringSize.length()) { - maxStringSize = std::accumulate( maxStringsColumn.begin(), maxStringsColumn.end(), std::string()); + integer spacesToAdd = m_tableLayout.getColumnMargin(); + bool isFirstIteration = true; + maxStringSize = std::accumulate( maxStringsColumn.begin(), maxStringsColumn.end(), std::string(), + [spacesToAdd, &isFirstIteration]( std::string acc, const std::string & curr ) { + if( isFirstIteration ) + { + isFirstIteration = false; + return curr; + } + else + { + return std::move( acc ) + std::string( spacesToAdd, ' ' ) + curr; + } + } ); } - std::cout << "verif max string size after " << column.m_maxStringSize << std::endl; - } } @@ -367,10 +375,8 @@ void computeTableSectionLength( std::vector< TableLayout::Column > & columns, st { return sum; } - std::cout << " alors je calcul" << column.m_maxStringSize << " egal " << sum << std::endl; return static_cast< decltype(sum) >(sum + column.m_maxStringSize.length()); } ); - std::cout << " fincalcul" << sectionlineLength << std::endl; } void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & columns, @@ -462,21 +468,22 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c string_view sectionSeparatingLine, std::ostringstream & tableOutput, integer const nbRows, - size_t const nbSubColumns, TableLayout::Section const section ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); - size_t const nbColumns = nbSubColumns + columns.size(); - std::cout << nbRows << std::endl; - std::cout << nbColumns << std::endl; - std::cout << "testeuh"<< std::endl; + size_t const nbColumns = columns.size(); + bool containSubColumn = false; + + std::cout << " tt" << nbColumns << std::endl; + std::cout << " gg" << columns.size() - 1 < c { tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } - } + if( !column.subColumn.empty() ) + { + containSubColumn = true; + } + } // Append right border with line return tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, borderMargin + 1 ); - - // if( !column.subColumn.empty() ) - // { - // outputSectionRows( column.subColumn, sectionSeparatingLine, tableOutput, nbRows, columns.size(), section ); - // } } if( nbRows != 0 ) @@ -508,6 +514,27 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); } + if( section == TableLayout::Section::header && containSubColumn ) + { + std::vector< TableLayout::Column > rowSubColumns; + + for( auto const & column : columns ) + { + if( column.subColumn.empty() ) + { + TableLayout::Column emptyColumn = {TableLayout::ColumnParam{""}, {}, column.m_maxStringSize, {}}; + rowSubColumns.push_back( emptyColumn ); + } + else + { + for( auto const & subColumn : column.subColumn ) + { + rowSubColumns.push_back( subColumn ); + } + } + } + outputSectionRows( rowSubColumns, sectionSeparatingLine, tableOutput, 1, TableLayout::Section::header ); + } } diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index ee62efa2623..42cb9bc54b0 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -237,7 +237,6 @@ class TableTextFormatter : public TableFormatter * @param sectionSeparatingLine Line separator between sections * @param rows A section row * @param nbRows Indicates the number of lines in a section - * @param nbSubColumns * @param section The section to be built * @note Add the ending line if there are one or more rows */ @@ -245,7 +244,6 @@ class TableTextFormatter : public TableFormatter string_view sectionSeparatingLine, std::ostringstream & tableOutput, integer const nbRows, - size_t const nbSubColumns, TableLayout::Section const section ) const; }; diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index bc4fdb668e7..bbde16c26da 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -25,13 +25,11 @@ void addColumn( std::vector< TableLayout::ColumnParam > const & columnsParam, st { for( const auto & columnParam : columnsParam ) { - std::cout << "columnParam -- " << columnParam.columnName << std::endl; bool subColum = false; std::vector< TableLayout::Column > subColumnsToAdd; TableLayout::Column columnToAdd = {columnParam, {}, "", {}}; for( const auto & subColumnsName: columnParam.subColumns ) { - std::cout << "subColumnsParam -- " << subColumnsName << std::endl; subColum = true; TableLayout::Column subColumn= {subColumnsName, {}, "", {}}; subColumnsToAdd.push_back( subColumn ); diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 7f74af3bcc8..b7ebab0393d 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -64,7 +64,7 @@ class TableLayout /// std::vector< string > subColumns; /// Vector containing substring column name delimited by "\n" - std::vector< string > splitColumnNameLines; + std::vector< string > splitColumnNameLines = {""}; /** * @brief Construct a ColumnParam object with the specified name and alignment. From a1848974e01ffc57892afb33e85f91cfede18017 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 6 Sep 2024 16:43:29 +0200 Subject: [PATCH 152/216] [DRAFT] First table sub version, missing spaces --- .../common/format/table/TableFormatter.cpp | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 89adffd446d..45b4108c6d7 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -148,15 +148,20 @@ void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Col // Compute index column because we will iterate through columnsValues for( auto & column : columns ) { + ++columnWithSubColumns; if( column.subColumn.empty()) { ++realNbColumn; } else { - ++columnWithSubColumns; + std::cout << " columnWithSubColumns " << columnWithSubColumns << std::endl; + std::cout << " realNbColumn " << realNbColumn << std::endl; + std::cout << " column.m_parameter.subColumns.size() " << column.m_parameter.subColumns.size() << std::endl<< std::endl; + realNbColumn += columnWithSubColumns - column.m_parameter.subColumns.size(); } + } std::vector< std::vector< std::string > > subColumnValues; @@ -164,12 +169,25 @@ void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Col for( size_t idxRow = 0; idxRow < realNbColumn; idxRow++ ) { auto & column = columns[idxRow]; - if( column.subColumn.size() > 0 ) + std::cout << " trasnform " << realNbColumn << column.m_parameter.columnName<< std::endl; + if( !column.subColumn.empty() ) { auto startSubColumn = columnsValues.begin() + currentColumn; auto endSubColumn = columnsValues.begin() + currentColumn + column.m_parameter.subColumns.size(); subColumnValues = std::vector< std::vector< std::string > >( startSubColumn, endSubColumn ); + std::cout << " trasnform " << std::endl; fillTableColumnsFromRows( column.subColumn, subColumnValues ); + + std::vector< std::string > concatenatedValues; + + std::transform( subColumnValues.begin(), subColumnValues.end(), std::back_inserter( concatenatedValues ), + []( const auto & subVector ) { return std::accumulate( subVector.begin(), subVector.end(), std::string{} ); } ); + for( const auto & value : concatenatedValues ) + { + std::cout << value << " "; + } + + column.m_columnValues = concatenatedValues; currentColumn += column.subColumn.size(); } else @@ -233,7 +251,7 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, string const tableTitle = string( m_tableLayout.getTitle()); splitAndSetColumnNames( columns, nbHeaderRows, splitHeaders ); - + std::string maxStringSize = " "; findAndSetMaxStringSize( columns, maxStringSize ); @@ -483,9 +501,10 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, 1 + borderMargin ); for( std::size_t idxColumn = 0; idxColumn < nbColumns; ++idxColumn ) { - std::cout << "1" << std::endl; auto & column = columns[idxColumn]; TableLayout::Column const currentColumn = column; + + //il est vide car si sous colonnes, m_columnValues = { } :( auto const & columnContent = section == TableLayout::Section::header ? column.m_parameter.splitColumnNameLines : column.m_columnValues; From eef11e663ce59e1759b019fbcf497f3374de0c98 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 9 Sep 2024 17:53:09 +0200 Subject: [PATCH 153/216] [DRAFT] subVales added --- .../common/format/table/TableFormatter.cpp | 122 ++++++++++++------ .../common/format/table/TableLayout.cpp | 25 +++- .../common/format/table/TableLayout.hpp | 16 +++ 3 files changed, 123 insertions(+), 40 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 45b4108c6d7..5b91f022d54 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -169,25 +169,49 @@ void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Col for( size_t idxRow = 0; idxRow < realNbColumn; idxRow++ ) { auto & column = columns[idxRow]; - std::cout << " trasnform " << realNbColumn << column.m_parameter.columnName<< std::endl; if( !column.subColumn.empty() ) { + std::cout << "ezrzrezre" << std::endl; auto startSubColumn = columnsValues.begin() + currentColumn; auto endSubColumn = columnsValues.begin() + currentColumn + column.m_parameter.subColumns.size(); subColumnValues = std::vector< std::vector< std::string > >( startSubColumn, endSubColumn ); - std::cout << " trasnform " << std::endl; fillTableColumnsFromRows( column.subColumn, subColumnValues ); - std::vector< std::string > concatenatedValues; - - std::transform( subColumnValues.begin(), subColumnValues.end(), std::back_inserter( concatenatedValues ), - []( const auto & subVector ) { return std::accumulate( subVector.begin(), subVector.end(), std::string{} ); } ); - for( const auto & value : concatenatedValues ) + std::vector< std::vector< std::string > > tSubColumnValues( subColumnValues[0].size(), std::vector< std::string >( subColumnValues.size())); + transpose( tSubColumnValues, subColumnValues ); + for( const auto & rowValues : tSubColumnValues ) { - std::cout << value << " "; + std::vector< std::string > concatenatedValues; + for( const auto & vv : rowValues ) + { + concatenatedValues.push_back( vv ); + std::cout << " push_back "<< vv << " " << std::endl; + } + + std::string maxStringCell = std::accumulate( concatenatedValues.begin(), concatenatedValues.end(), std::string(), + []( std::string acc, const std::string & str ) { + if( acc.empty()) + { + std::cout << "acc.empty() " << str << std::endl; + return str; + } + else + { + std::cout << "!acc.empty() " << acc << " " << str <( TableData const & tableData ) std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); std::vector< string > const & msgTableError = tableData.getErrorMsgs(); integer const nbValuesRows = tableDataRows.size(); + + std::cout << "V AU "<< m_tableLayout.getTableOpts().maxTableColumns << std::endl; formatColumnsFromLayout( columns, tableDataRows ); std::vector< std::vector< std::string > > columnsValues( tableDataRows[0].size(), std::vector< std::string >( tableDataRows.size())); @@ -320,13 +338,13 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnNameLines.begin(), column.m_parameter.splitColumnNameLines.end(), []( const auto & a, const auto & b ) {return a.size() < b.size();} ); - column.m_maxStringSize = maxStringSizeHeader; + if( column.m_maxStringSize.length() < maxStringSizeHeader.length()) + column.m_maxStringSize = maxStringSizeHeader; maxStringsColumn.push_back( column.m_parameter.columnName ); } for( auto & column : columns ) { - for( auto const & cell : column.m_columnValues ) { if( column.m_maxStringSize.length() < cell.length()) @@ -482,6 +500,24 @@ void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, } } +void TableTextFormatter::outputSubSection( std::vector< TableLayout::Column > const & columns, + std::ostringstream & tableOutput, + size_t idxRow +// TableLayout::Section const section + ) const +{ + integer const columnMargin = m_tableLayout.getColumnMargin(); + for( auto const & column : columns ) + { + std::cout << " outputSubSection " << column.m_columnValues[idxRow] << std::endl; + tableOutput << buildCell( column.m_parameter.alignment, + column.m_columnValues[idxRow], + column.m_maxStringSize.length() ); + tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); + } + +} + void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > const & columns, string_view sectionSeparatingLine, std::ostringstream & tableOutput, @@ -490,35 +526,47 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); - size_t const nbColumns = columns.size(); + // size_t const nbColumns = section == TableLayout::Section::header ? columns.size() : m_tableLayout.getTableOpts().maxTableColumns; bool containSubColumn = false; - - std::cout << " tt" << nbColumns << std::endl; - std::cout << " gg" << columns.size() - 1 < c } outputSectionRows( rowSubColumns, sectionSeparatingLine, tableOutput, 1, TableLayout::Section::header ); } - + std::cout<< "C TERMINER" << std::endl; } } diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index bbde16c26da..786ce61a38a 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -47,7 +47,7 @@ void addColumn( std::vector< TableLayout::ColumnParam > const & columnsParam, st for( auto const & columnt : columns ) { - std::cout << "regarde après le addColumn " << columnt.m_parameter.columnName << std::endl ; + std::cout << "regarde après le addColumn " << columnt.m_parameter.columnName << std::endl; } } @@ -67,10 +67,24 @@ TableLayout::TableLayout( std::vector< ColumnParam > const & columnParams, strin m_tableTitle( title ) { setMargin( MarginValue::medium ); - //m_columns.reserve( columnParams.size() ); - std::cout << "TEST ADD COLUMN " << std::endl; addColumn( columnParams, m_columns ); + TableLayout::TableOpts tableOpts( {m_columns, 0} ); + + //TODO rename cette partie + for( auto & column : m_columns ) + { + if( !column.subColumn.empty()) + { + tableOpts.maxTableColumns += column.subColumn.size(); + }else{ + ++tableOpts.maxTableColumns; + } + std::cout << " realNbColumn " << tableOpts.maxTableColumns << std::endl; + } + + m_tableOpts = tableOpts; + } @@ -85,6 +99,11 @@ std::vector< TableLayout::Column > const & TableLayout::getColumns() const return m_columns; } +TableLayout::TableOpts const & TableLayout::getTableOpts() const +{ + return m_tableOpts; +} + string_view TableLayout::getTitle() const { return m_tableTitle; diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index b7ebab0393d..10e37ffee32 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -104,6 +104,8 @@ class TableLayout {} }; + + //TODO ENLEVER LES _ /** * @brief Struct for a column. */ @@ -120,6 +122,12 @@ class TableLayout }; + struct TableOpts + { + std::vector< Column > columns; + size_t maxTableColumns; + }; + TableLayout() = default; /** @@ -143,7 +151,12 @@ class TableLayout /** * @return The columns vector */ + std::vector< Column > const & getColumns() const; + /** + * @return The columns vector + */ + TableOpts const & getTableOpts() const; /** * @return The table name @@ -174,6 +187,9 @@ class TableLayout private: std::vector< Column > m_columns; + TableOpts m_tableOpts; + + string m_tableTitle; integer m_borderMargin; integer m_columnMargin; From 4cd35f517aa87609974fc7300c9b1eb4f16793bd Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 10 Sep 2024 14:45:53 +0200 Subject: [PATCH 154/216] Table well formated + some opti --- .../common/format/table/TableFormatter.cpp | 110 +++++++----------- .../common/format/table/TableFormatter.hpp | 22 +++- 2 files changed, 58 insertions(+), 74 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 5b91f022d54..dbb0d02b170 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -282,8 +282,6 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbHeaderRows, TableLayout::Section::header ); - //subcolumn - std::cout << "outputSectionRows finished " << tableOutput.str() < & columns, @@ -329,22 +327,20 @@ void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Colum void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, std::string & maxStringSize ) const { - std::vector< std::string > maxStringsColumn; - maxStringsColumn.reserve( columns.size()); + std::vector< std::string > maxStringColumns; + maxStringColumns.reserve( columns.size()); - // max header columns length + // TODO RECHECKPOUR LES 2 FOR LOOP for( auto & column : columns ) { + maxStringColumns.push_back( column.m_parameter.columnName ); + auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnNameLines.begin(), column.m_parameter.splitColumnNameLines.end(), []( const auto & a, const auto & b ) {return a.size() < b.size();} ); - if( column.m_maxStringSize.length() < maxStringSizeHeader.length()) - column.m_maxStringSize = maxStringSizeHeader; - maxStringsColumn.push_back( column.m_parameter.columnName ); - } - for( auto & column : columns ) - { + column.m_maxStringSize = std::max( column.m_maxStringSize, maxStringSizeHeader ); + for( auto const & cell : column.m_columnValues ) { if( column.m_maxStringSize.length() < cell.length()) @@ -353,16 +349,15 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu } } - if( !column.subColumn.empty()) - { - findAndSetMaxStringSize( column.subColumn, column.m_maxStringSize ); - } + } - if( column.m_maxStringSize.length() > maxStringSize.length()) + for( auto & column : columns ) + { + if( column.m_maxStringSize.length() < maxStringSize.length()) { integer spacesToAdd = m_tableLayout.getColumnMargin(); bool isFirstIteration = true; - maxStringSize = std::accumulate( maxStringsColumn.begin(), maxStringsColumn.end(), std::string(), + maxStringSize = std::accumulate( maxStringColumns.begin(), maxStringColumns.end(), std::string(), [spacesToAdd, &isFirstIteration]( std::string acc, const std::string & curr ) { if( isFirstIteration ) { @@ -371,11 +366,16 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu } else { - return std::move( acc ) + std::string( spacesToAdd, ' ' ) + curr; + return acc + std::string( spacesToAdd, ' ' ) + curr; } } ); + + } + + if( !column.subColumn.empty()) + { + findAndSetMaxStringSize( column.subColumn, column.m_maxStringSize ); } - std::cout << "verif max string size after " << column.m_maxStringSize << std::endl; } } @@ -502,18 +502,29 @@ void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, void TableTextFormatter::outputSubSection( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, - size_t idxRow -// TableLayout::Section const section - ) const + TableLayout::Section const section, + size_t const idxRow ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); - for( auto const & column : columns ) + if( section == TableLayout::Section::header ) { - std::cout << " outputSubSection " << column.m_columnValues[idxRow] << std::endl; - tableOutput << buildCell( column.m_parameter.alignment, - column.m_columnValues[idxRow], - column.m_maxStringSize.length() ); - tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); + for( auto const & column : columns ) + { + tableOutput << buildCell( column.m_parameter.alignment, + column.m_parameter.splitColumnNameLines[idxRow], + column.m_maxStringSize.length() ); + tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); + } + } + else + { + for( auto const & column : columns ) + { + tableOutput << buildCell( column.m_parameter.alignment, + column.m_columnValues[idxRow], + column.m_maxStringSize.length() ); + tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); + } } } @@ -526,37 +537,28 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); - // size_t const nbColumns = section == TableLayout::Section::header ? columns.size() : m_tableLayout.getTableOpts().maxTableColumns; - bool containSubColumn = false; for( auto idxRow = 0; idxRow< nbRows; ++idxRow ) { // Append the left border tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, 1 + borderMargin ); - //std::cout << "nbColumns "<< nbColumns << std::endl; - for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { auto & column = columns[idxColumn]; - std::cout << "column.m_columnValues "<< column.m_parameter.columnName << std::endl; - if( section == TableLayout::Section::values && !column.subColumn.empty()) //TODO oeut etre commenté section == // - // TableLayout::Section::value + if( !column.subColumn.empty()) { - outputSubSection( column.subColumn, tableOutput, idxRow /*TableLayout::Section::values*/ ); + outputSubSection( column.subColumn, tableOutput, section, idxRow ); } else { TableLayout::Column const currentColumn = column; - auto const & columnContent = section == TableLayout::Section::header ? column.m_parameter.splitColumnNameLines : column.m_columnValues; string cell = columnContent.at( idxRow ); integer const cellSize = currentColumn.m_maxStringSize.length(); - tableOutput << buildCell( currentColumn.m_parameter.alignment, cell, cellSize ); - // std::cout << " tableOutput " << tableOutput.str() << std::endl; // Add space between column if( idxColumn < columns.size() - 1 ) @@ -564,13 +566,6 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } } - - - - if( !column.subColumn.empty() ) - { - containSubColumn = true; - } } // Append right border with line return tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, borderMargin + 1 ); @@ -580,29 +575,6 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c { tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); } - - if( section == TableLayout::Section::header && containSubColumn ) - { - std::vector< TableLayout::Column > rowSubColumns; - - for( auto const & column : columns ) - { - if( column.subColumn.empty() ) - { - TableLayout::Column emptyColumn = {TableLayout::ColumnParam{""}, {}, column.m_maxStringSize, {}}; - rowSubColumns.push_back( emptyColumn ); - } - else - { - for( auto const & subColumn : column.subColumn ) - { - rowSubColumns.push_back( subColumn ); - } - } - } - outputSectionRows( rowSubColumns, sectionSeparatingLine, tableOutput, 1, TableLayout::Section::header ); - } - std::cout<< "C TERMINER" << std::endl; } } diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 42cb9bc54b0..3c742fb3271 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -240,11 +240,23 @@ class TableTextFormatter : public TableFormatter * @param section The section to be built * @note Add the ending line if there are one or more rows */ - void outputSectionRows( std::vector< TableLayout::Column > const & columns, - string_view sectionSeparatingLine, - std::ostringstream & tableOutput, - integer const nbRows, - TableLayout::Section const section ) const; + void outputSectionRows( std::vector< TableLayout::Column > const & columns, + string_view sectionSeparatingLine, + std::ostringstream & tableOutput, + integer const nbRows, + TableLayout::Section const section ) const; + + /** + * @brief + * + * @param columns + * @param tableOutput + * @param idxRow + */ + void outputSubSection( std::vector< TableLayout::Column > const & columns, + std::ostringstream & tableOutput, + TableLayout::Section const section, + size_t const idxRow ) const; }; /** From 111cb13e61d98ffef1a72f9b700705717044e2a2 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 11 Sep 2024 10:04:18 +0200 Subject: [PATCH 155/216] fix heade + some simplification --- .../common/format/table/TableFormatter.cpp | 200 +++++++----------- .../common/format/table/TableLayout.cpp | 11 - 2 files changed, 81 insertions(+), 130 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index dbb0d02b170..a0fee9a138e 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -140,87 +140,32 @@ TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): {} void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > const & columnsValues ) const + std::vector< std::vector< std::string > > const & columnsValues ) const { - size_t realNbColumn = 0; - size_t columnWithSubColumns = 0; - - // Compute index column because we will iterate through columnsValues + size_t currentColumn = 0; for( auto & column : columns ) { - ++columnWithSubColumns; if( column.subColumn.empty()) { - ++realNbColumn; + column.m_columnValues = columnsValues[currentColumn++]; } else { - std::cout << " columnWithSubColumns " << columnWithSubColumns << std::endl; - std::cout << " realNbColumn " << realNbColumn << std::endl; - std::cout << " column.m_parameter.subColumns.size() " << column.m_parameter.subColumns.size() << std::endl<< std::endl; - - realNbColumn += columnWithSubColumns - column.m_parameter.subColumns.size(); - } - - } - - std::vector< std::vector< std::string > > subColumnValues; - auto currentColumn = 0; - for( size_t idxRow = 0; idxRow < realNbColumn; idxRow++ ) - { - auto & column = columns[idxRow]; - if( !column.subColumn.empty() ) - { - std::cout << "ezrzrezre" << std::endl; - auto startSubColumn = columnsValues.begin() + currentColumn; - auto endSubColumn = columnsValues.begin() + currentColumn + column.m_parameter.subColumns.size(); - subColumnValues = std::vector< std::vector< std::string > >( startSubColumn, endSubColumn ); + std::vector< std::vector< std::string > > subColumnValues( columnsValues.begin() + currentColumn, + columnsValues.begin() + currentColumn + column.m_parameter.subColumns.size()); fillTableColumnsFromRows( column.subColumn, subColumnValues ); std::vector< std::vector< std::string > > tSubColumnValues( subColumnValues[0].size(), std::vector< std::string >( subColumnValues.size())); transpose( tSubColumnValues, subColumnValues ); + + column.m_maxStringSize.clear(); for( const auto & rowValues : tSubColumnValues ) { - std::vector< std::string > concatenatedValues; - for( const auto & vv : rowValues ) - { - concatenatedValues.push_back( vv ); - std::cout << " push_back "<< vv << " " << std::endl; - } - - std::string maxStringCell = std::accumulate( concatenatedValues.begin(), concatenatedValues.end(), std::string(), - []( std::string acc, const std::string & str ) { - if( acc.empty()) - { - std::cout << "acc.empty() " << str << std::endl; - return str; - } - else - { - std::cout << "!acc.empty() " << acc << " " << str < columns = m_tableLayout.getColumns(); - + std::cout << " layoutToString "<< std::endl; outputLayout( tableOutput, columns, {}, sectionSeparatingLine ); return tableOutput.str(); } @@ -243,7 +188,6 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) std::vector< string > const & msgTableError = tableData.getErrorMsgs(); integer const nbValuesRows = tableDataRows.size(); - std::cout << "V AU "<< m_tableLayout.getTableOpts().maxTableColumns << std::endl; formatColumnsFromLayout( columns, tableDataRows ); std::vector< std::vector< std::string > > columnsValues( tableDataRows[0].size(), std::vector< std::string >( tableDataRows.size())); @@ -269,7 +213,6 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, string const tableTitle = string( m_tableLayout.getTitle()); splitAndSetColumnNames( columns, nbHeaderRows, splitHeaders ); - std::string maxStringSize = " "; findAndSetMaxStringSize( columns, maxStringSize ); @@ -280,7 +223,7 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, outputTopRows( tableOutput, {tableTitle}, topSeparator, TableLayout::Alignment::center ); outputTopRows( tableOutput, msgTableError, topSeparator, TableLayout::Alignment::left ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - + std::cout << " header nb col " << columns.size() << std::endl; outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbHeaderRows, TableLayout::Section::header ); } @@ -330,46 +273,46 @@ void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Colu std::vector< std::string > maxStringColumns; maxStringColumns.reserve( columns.size()); - // TODO RECHECKPOUR LES 2 FOR LOOP for( auto & column : columns ) { maxStringColumns.push_back( column.m_parameter.columnName ); - auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnNameLines.begin(), - column.m_parameter.splitColumnNameLines.end(), + { // find max column header width + auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnNameLines.begin(), + column.m_parameter.splitColumnNameLines.end(), + []( const auto & a, const auto & b ) {return a.size() < b.size();} ); + column.m_maxStringSize = std::max( column.m_maxStringSize, maxStringSizeHeader ); + } + if( column.m_columnValues.empty()) + return; + { // find max column values width + auto const maxStringSizeCell = *std::max_element( column.m_columnValues.begin(), + column.m_columnValues.end(), []( const auto & a, const auto & b ) {return a.size() < b.size();} ); - - column.m_maxStringSize = std::max( column.m_maxStringSize, maxStringSizeHeader ); - - for( auto const & cell : column.m_columnValues ) - { - if( column.m_maxStringSize.length() < cell.length()) + if( column.m_maxStringSize.length() < maxStringSizeCell.length()) { - column.m_maxStringSize = cell; + column.m_maxStringSize = maxStringSizeCell; } } - } - - for( auto & column : columns ) - { - if( column.m_maxStringSize.length() < maxStringSize.length()) - { - integer spacesToAdd = m_tableLayout.getColumnMargin(); - bool isFirstIteration = true; - maxStringSize = std::accumulate( maxStringColumns.begin(), maxStringColumns.end(), std::string(), - [spacesToAdd, &isFirstIteration]( std::string acc, const std::string & curr ) { - if( isFirstIteration ) - { - isFirstIteration = false; - return curr; - } - else - { - return acc + std::string( spacesToAdd, ' ' ) + curr; - } - } ); - + { // subcolumn case + if( column.m_maxStringSize.length() < maxStringSize.length()) + { + integer const spacesToAdd = m_tableLayout.getColumnMargin(); + bool isFirstIteration = true; + maxStringSize = std::accumulate( maxStringColumns.begin(), maxStringColumns.end(), std::string(), + [spacesToAdd, &isFirstIteration]( std::string acc, const std::string & curr ) { + if( isFirstIteration ) + { + isFirstIteration = false; + return curr; + } + else + { + return acc + std::string( spacesToAdd, ' ' ) + curr; + } + } ); + } } if( !column.subColumn.empty()) @@ -506,25 +449,14 @@ void TableTextFormatter::outputSubSection( std::vector< TableLayout::Column > co size_t const idxRow ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); - if( section == TableLayout::Section::header ) + + std::cout << section << std::endl; + for( auto const & column : columns ) { - for( auto const & column : columns ) - { - tableOutput << buildCell( column.m_parameter.alignment, - column.m_parameter.splitColumnNameLines[idxRow], - column.m_maxStringSize.length() ); - tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); - } - } - else - { - for( auto const & column : columns ) - { - tableOutput << buildCell( column.m_parameter.alignment, - column.m_columnValues[idxRow], - column.m_maxStringSize.length() ); - tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); - } + tableOutput << buildCell( column.m_parameter.alignment, + column.m_columnValues[idxRow], + column.m_maxStringSize.length() ); + tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } } @@ -537,6 +469,7 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); + bool containSubColumn = false; for( auto idxRow = 0; idxRow< nbRows; ++idxRow ) { // Append the left border @@ -544,9 +477,9 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { - auto & column = columns[idxColumn]; + auto const & column = columns[idxColumn]; - if( !column.subColumn.empty()) + if( section == TableLayout::Section::values && !column.subColumn.empty()) { outputSubSection( column.subColumn, tableOutput, section, idxRow ); } @@ -566,6 +499,11 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } } + + if( !column.subColumn.empty() ) + { + containSubColumn = true; + } } // Append right border with line return tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, borderMargin + 1 ); @@ -575,6 +513,30 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c { tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); } + + //check and build sub row header + if( section == TableLayout::Section::header && containSubColumn ) + { + std::vector< TableLayout::Column > rowSubColumns; + + for( auto const & column : columns ) + { + if( column.subColumn.empty() ) + { + TableLayout::Column emptyColumn = {TableLayout::ColumnParam{""}, {}, column.m_maxStringSize, {}}; + rowSubColumns.push_back( emptyColumn ); + } + else + { + for( auto const & subColumn : column.subColumn ) + { + rowSubColumns.push_back( subColumn ); + } + } + } + outputSectionRows( rowSubColumns, sectionSeparatingLine, tableOutput, 1, TableLayout::Section::header ); + } + } } diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 786ce61a38a..6b8795729c4 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -44,12 +44,6 @@ void addColumn( std::vector< TableLayout::ColumnParam > const & columnsParam, st columns.push_back( { columnParam, {}, "", {}} ); } } - - for( auto const & columnt : columns ) - { - std::cout << "regarde après le addColumn " << columnt.m_parameter.columnName << std::endl; - } - } TableLayout::TableLayout( std::vector< string > const & columnNames, string const & title ): @@ -70,8 +64,6 @@ TableLayout::TableLayout( std::vector< ColumnParam > const & columnParams, strin addColumn( columnParams, m_columns ); TableLayout::TableOpts tableOpts( {m_columns, 0} ); - - //TODO rename cette partie for( auto & column : m_columns ) { if( !column.subColumn.empty()) @@ -80,11 +72,8 @@ TableLayout::TableLayout( std::vector< ColumnParam > const & columnParams, strin }else{ ++tableOpts.maxTableColumns; } - std::cout << " realNbColumn " << tableOpts.maxTableColumns << std::endl; } - m_tableOpts = tableOpts; - } From 50512aecf1cc33d724b3e6310737faab6ac85eb2 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 12 Sep 2024 16:47:57 +0200 Subject: [PATCH 156/216] new version with multiples sub column --- .../common/format/table/TableFormatter.cpp | 253 ++++++++++-------- .../common/format/table/TableFormatter.hpp | 23 +- .../common/format/table/TableLayout.cpp | 10 +- .../common/format/table/TableLayout.hpp | 4 +- 4 files changed, 156 insertions(+), 134 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index a0fee9a138e..a5d6757cbb2 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -79,7 +79,7 @@ string TableCSVFormatter::toString< TableData >( TableData const & tableData ) c ////// Log Formatter implementation /////////////////////////////////////////////////////////////////////// -void transpose( std::vector< std::vector< std::string > > & dest, std::vector< std::vector< std::string > > & source ) +void transpose( std::vector< std::vector< std::string > > & dest, std::vector< std::vector< std::string > > const & source ) { for( size_t idxRow = 0; idxRow < source.size(); ++idxRow ) { @@ -97,7 +97,7 @@ void transpose( std::vector< std::vector< std::string > > & dest, std::vector< s * @param spaces The number of spaces in the cell * @return A formated cell */ -string buildCell( TableLayout::Alignment const alignment, string_view value, integer const spaces ) +string buildCell( TableLayout::Alignment const alignment, string_view value, size_t const spaces ) { switch( alignment ) { @@ -140,30 +140,37 @@ TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): {} void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< std::string > > const & columnsValues ) const + std::vector< std::vector< std::string > > const & tableDataRows, + bool isSubColumn ) const { size_t currentColumn = 0; + std::vector< std::vector< std::string > > tColumnsValues( tableDataRows[0].size(), std::vector< std::string >( tableDataRows.size())); + if( !isSubColumn ) + { + transpose( tColumnsValues, tableDataRows ); + } + for( auto & column : columns ) { if( column.subColumn.empty()) { - column.m_columnValues = columnsValues[currentColumn++]; + column.m_columnValues = !isSubColumn ? + tColumnsValues[currentColumn++] : tableDataRows[currentColumn++]; } else { - std::vector< std::vector< std::string > > subColumnValues( columnsValues.begin() + currentColumn, - columnsValues.begin() + currentColumn + column.m_parameter.subColumns.size()); - fillTableColumnsFromRows( column.subColumn, subColumnValues ); + std::cout << " nb sous col "<< column.m_parameter.subColumns.size() << std::endl; + std::vector< std::vector< std::string > > subColumnValues( tColumnsValues.begin() + currentColumn, + tColumnsValues.begin() + currentColumn + column.m_parameter.subColumns.size()); + fillTableColumnsFromRows( column.subColumn, subColumnValues, true ); - std::vector< std::vector< std::string > > tSubColumnValues( subColumnValues[0].size(), std::vector< std::string >( subColumnValues.size())); + std::vector< std::vector< std::string > > tSubColumnValues( subColumnValues[0].size(), std::vector< std::string >( subColumnValues.size()) ); transpose( tSubColumnValues, subColumnValues ); - - column.m_maxStringSize.clear(); - for( const auto & rowValues : tSubColumnValues ) + for( const auto & columnValues : tSubColumnValues ) { - column.m_columnValues = rowValues; + column.m_columnValues.insert( column.m_columnValues.end(), columnValues.begin(), columnValues.end() ); } - currentColumn += column.m_parameter.subColumns.size(); + currentColumn += subColumnValues.size(); } } } @@ -173,7 +180,6 @@ string TableTextFormatter::layoutToString() const std::ostringstream tableOutput; string sectionSeparatingLine; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); - std::cout << " layoutToString "<< std::endl; outputLayout( tableOutput, columns, {}, sectionSeparatingLine ); return tableOutput.str(); } @@ -189,12 +195,7 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) integer const nbValuesRows = tableDataRows.size(); formatColumnsFromLayout( columns, tableDataRows ); - - std::vector< std::vector< std::string > > columnsValues( tableDataRows[0].size(), std::vector< std::string >( tableDataRows.size())); - transpose( columnsValues, tableDataRows ); - - fillTableColumnsFromRows( columns, columnsValues ); - + fillTableColumnsFromRows( columns, tableDataRows, false ); outputLayout( tableOutput, columns, msgTableError, sectionSeparatingLine ); outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbValuesRows, TableLayout::Section::values ); tableOutput << '\n'; @@ -211,10 +212,13 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, size_t nbHeaderRows = 0; std::vector< std::vector< string > > splitHeaders; string const tableTitle = string( m_tableLayout.getTitle()); + std::string maxStringSize = " "; splitAndSetColumnNames( columns, nbHeaderRows, splitHeaders ); - std::string maxStringSize = " "; - findAndSetMaxStringSize( columns, maxStringSize ); + for( auto & column : columns ) + { + findAndSetMaxStringSize( column, column.m_maxStringSize, 0 ); + } computeTableWidth( columns, msgTableError ); buildTableSeparators( columns, topSeparator, sectionSeparatingLine ); @@ -223,7 +227,6 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, outputTopRows( tableOutput, {tableTitle}, topSeparator, TableLayout::Alignment::center ); outputTopRows( tableOutput, msgTableError, topSeparator, TableLayout::Alignment::left ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - std::cout << " header nb col " << columns.size() << std::endl; outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbHeaderRows, TableLayout::Section::header ); } @@ -268,94 +271,80 @@ void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Colum } -void TableTextFormatter::findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, std::string & maxStringSize ) const +void TableTextFormatter::findAndSetMaxStringSize( TableLayout::Column & column, std::vector< std::string > & maxStringSize, integer const idxMaxString ) const { - std::vector< std::string > maxStringColumns; - maxStringColumns.reserve( columns.size()); + string maxStringColumn = ""; - for( auto & column : columns ) + {// header case + auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnNameLines.begin(), + column.m_parameter.splitColumnNameLines.end(), + []( const auto & a, const auto & b ) {return a.size() < b.size();} ); + maxStringColumn = maxStringSizeHeader; + maxStringSize.push_back( maxStringSizeHeader ); + } + + std::cout << "- debug maxString 1- "<< column.m_parameter.columnName << std::endl; + for( auto const & value : maxStringSize ) { - maxStringColumns.push_back( column.m_parameter.columnName ); + std::cout << value << " "; + } + std::cout << std::endl; - { // find max column header width - auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnNameLines.begin(), - column.m_parameter.splitColumnNameLines.end(), - []( const auto & a, const auto & b ) {return a.size() < b.size();} ); - column.m_maxStringSize = std::max( column.m_maxStringSize, maxStringSizeHeader ); - } - if( column.m_columnValues.empty()) - return; - { // find max column values width + { // values case + if( column.subColumn.empty() ) + { auto const maxStringSizeCell = *std::max_element( column.m_columnValues.begin(), column.m_columnValues.end(), []( const auto & a, const auto & b ) {return a.size() < b.size();} ); - if( column.m_maxStringSize.length() < maxStringSizeCell.length()) - { - column.m_maxStringSize = maxStringSizeCell; - } - } - - { // subcolumn case - if( column.m_maxStringSize.length() < maxStringSize.length()) + if( maxStringColumn.length() < maxStringSizeCell.length()) { - integer const spacesToAdd = m_tableLayout.getColumnMargin(); - bool isFirstIteration = true; - maxStringSize = std::accumulate( maxStringColumns.begin(), maxStringColumns.end(), std::string(), - [spacesToAdd, &isFirstIteration]( std::string acc, const std::string & curr ) { - if( isFirstIteration ) - { - isFirstIteration = false; - return curr; - } - else - { - return acc + std::string( spacesToAdd, ' ' ) + curr; - } - } ); + maxStringColumn = maxStringSizeCell; } } + } - if( !column.subColumn.empty()) + { // affectation + if( maxStringSize[idxMaxString].length() < maxStringColumn.length() ) { - findAndSetMaxStringSize( column.subColumn, column.m_maxStringSize ); + maxStringSize[idxMaxString] = maxStringColumn ; } } -} -void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > & columns, - integer const extraCharacters ) const -{ - integer const extraCharactersPerColumn = std::ceil( extraCharacters / columns.size() ); - for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) - { - integer newMaxStringSize = extraCharactersPerColumn + columns[idxColumn].m_maxStringSize.size(); - if( idxColumn == columns.size() - 1 ) + { // subcolumn values case + if( !column.subColumn.empty() ) { - newMaxStringSize += m_tableLayout.getColumnMargin(); - } + integer idxSubColumn = 0; + column.m_maxStringSize.clear(); + for( auto & subC : column.subColumn ) + { + + findAndSetMaxStringSize( subC, column.m_maxStringSize, idxSubColumn ); + + std::cout << "- debug maxString - "<< column.m_parameter.columnName << std::endl; + for( auto const & value : column.m_maxStringSize ) + { + std::cout << value << " "; + } + + //TODO Condition pour check Nodes et tout les cols OU ALORS DEPLACER AU DEBUT + std::cout << std::endl; - columns[idxColumn].m_maxStringSize = GEOS_FMT( "{:>{}}", - columns[idxColumn].m_maxStringSize, - newMaxStringSize ); + idxSubColumn++; + } + } } -} -void computeTableSectionLength( std::vector< TableLayout::Column > & columns, string::size_type & sectionlineLength, string_view maxColumnStringSize ) -{ - sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, - [&]( auto sum, auto & column ) -> auto + std::cout << "- debug maxString 2- "<< column.m_parameter.columnName << std::endl; //TODO DOU VIENS LE NODE JE VOIS + for( auto const & value : column.m_maxStringSize ) { - if( !column.subColumn.empty()) - { - computeTableSectionLength( column.subColumn, sectionlineLength, column.m_maxStringSize ); - } + std::cout << value << " "; + } + std::cout << std::endl; - if( !column.m_maxStringSize.compare( maxColumnStringSize )) - { - return sum; - } - return static_cast< decltype(sum) >(sum + column.m_maxStringSize.length()); - } ); + if( column.m_maxStringSize.empty() ) + { + column.m_maxStringSize.push_back( maxStringColumn ); + } } void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & columns, @@ -375,22 +364,43 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & return a.size() < b.size(); } )); - msgTableErrorLength += maxStringSize.size() + 1; // max string size + line return at the end + msgTableErrorLength += maxStringSize.size() + 1; // max string size + line return at the end } } - // compute table section length string::size_type sectionLengthWithSpacing = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); string::size_type sectionlineLength = sectionLengthWithSpacing; - computeTableSectionLength( columns, sectionlineLength, " " ); + { // compute table section length TODO A FONCTION + integer const spacesToAdd = m_tableLayout.getColumnMargin(); + bool isFirstIteration = true; + sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, + [&]( auto sum, auto & column ) -> auto + { + std::string maxStringSize = std::accumulate( column.m_maxStringSize.begin(), column.m_maxStringSize.end(), std::string(), + [spacesToAdd, &isFirstIteration]( std::string acc, const std::string & curr ) { + if( isFirstIteration ) + { + isFirstIteration = false; + return curr; + } + else + { + return acc + std::string( spacesToAdd, ' ' ) + curr; + } + } ); + + return static_cast< decltype(sum) >(sum + maxStringSize.length()); + } ); + } string::size_type maxTopLineLength = tableTitle.length(); maxTopLineLength = std::max( maxTopLineLength, msgTableErrorLength ); - if( sectionlineLength < maxTopLineLength ) - { - integer const extraCharacters = maxTopLineLength - sectionlineLength; - increaseColumnsSize( columns, extraCharacters ); - } + maxTopLineLength = std::max( maxTopLineLength, sectionlineLength ); + std::cout << "- max length - " << sectionlineLength << " " << maxTopLineLength << std::endl; + + //refaire le calcul du max string par colonnes ici + + } @@ -403,11 +413,20 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column integer const borderMargin = m_tableLayout.getBorderMargin(); std::vector< string > maxStringPerColumn; - for( auto const & column : columns ) + for( auto const & column : columns ) //TODO Check ca { - maxStringPerColumn.push_back( string( column.m_maxStringSize.length(), m_horizontalLine ) ); + std::for_each( column.m_maxStringSize.begin(), column.m_maxStringSize.end(), [&] ( std::string maxString ) { + maxStringPerColumn.push_back( string( maxString.length(), m_horizontalLine ) ); + } ); } + std::cout << "seprator" << std::endl; + for( auto const & seprator : maxStringPerColumn ) + { + std::cout << seprator; + } + std::cout << std::endl; + string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", m_horizontalLine, columnMargin ); std::string const leftBorder = GEOS_FMT( "{}{:-<{}}", m_horizontalLine, "", borderMargin ); @@ -445,32 +464,28 @@ void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, void TableTextFormatter::outputSubSection( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, - TableLayout::Section const section, - size_t const idxRow ) const + integer idxRow ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); - - std::cout << section << std::endl; - for( auto const & column : columns ) + for( size_t idxCol = 0; idxCol< columns.size(); ++idxCol ) { - tableOutput << buildCell( column.m_parameter.alignment, - column.m_columnValues[idxRow], - column.m_maxStringSize.length() ); + tableOutput << buildCell( columns[idxCol].m_parameter.alignment, + columns[idxCol].m_columnValues[idxRow], + columns[idxCol].m_maxStringSize[0].length() ); tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } - } void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > const & columns, string_view sectionSeparatingLine, std::ostringstream & tableOutput, - integer const nbRows, + size_t const nbRows, TableLayout::Section const section ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); bool containSubColumn = false; - for( auto idxRow = 0; idxRow< nbRows; ++idxRow ) + for( size_t idxRow = 0; idxRow< nbRows; ++idxRow ) { // Append the left border tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, 1 + borderMargin ); @@ -481,7 +496,7 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c if( section == TableLayout::Section::values && !column.subColumn.empty()) { - outputSubSection( column.subColumn, tableOutput, section, idxRow ); + outputSubSection( column.subColumn, tableOutput, idxRow ); } else { @@ -490,7 +505,19 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c column.m_parameter.splitColumnNameLines : column.m_columnValues; string cell = columnContent.at( idxRow ); - integer const cellSize = currentColumn.m_maxStringSize.length(); + bool isFirstIteration = true; + integer const cellSize = std::accumulate( column.m_maxStringSize.begin(), column.m_maxStringSize.end(), 0, + [&isFirstIteration, &columnMargin]( int sum, const std::string & str ) { + if( isFirstIteration ) + { + isFirstIteration = false; + return sum + str.length(); + } + else + { + return sum + columnMargin + str.length(); + } + } ); tableOutput << buildCell( currentColumn.m_parameter.alignment, cell, cellSize ); // Add space between column diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 3c742fb3271..7c67844e4a9 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -161,7 +161,8 @@ class TableTextFormatter : public TableFormatter * @param tableData Vector containing all rows filled with values */ void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > const & tableData ) const; + std::vector< std::vector< string > > const & tableData, + bool isSubColumn ) const; /** * @brief Converts a TableLayout into a formatted representation. @@ -188,17 +189,13 @@ class TableTextFormatter : public TableFormatter /** * @brief For each column find and set the column's longest string + * + * * @param columns The vector containg all columns */ - void findAndSetMaxStringSize( std::vector< TableLayout::Column > & columns, std::string & maxStringSize ) const; - - /** - * @brief recalculate the largest string size for each columns - * @param columns Vector containing all table columns - * @param extraCharacters Extra characters to be added to \p m_maxStringSize of each columns - */ - void increaseColumnsSize( std::vector< TableLayout::Column > & columns, - integer const extraCharacters ) const; + void findAndSetMaxStringSize( TableLayout::Column & columns, + std::vector< std::string > & maxStringSize, + integer const idxColumn ) const; /** * @brief Compute the max table line length, taking into account the length of : title, error, columns header and content @@ -243,7 +240,7 @@ class TableTextFormatter : public TableFormatter void outputSectionRows( std::vector< TableLayout::Column > const & columns, string_view sectionSeparatingLine, std::ostringstream & tableOutput, - integer const nbRows, + size_t const nbRows, TableLayout::Section const section ) const; /** @@ -251,12 +248,10 @@ class TableTextFormatter : public TableFormatter * * @param columns * @param tableOutput - * @param idxRow */ void outputSubSection( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, - TableLayout::Section const section, - size_t const idxRow ) const; + integer idxCell ) const; }; /** diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 6b8795729c4..9df9c4d629b 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -27,13 +27,13 @@ void addColumn( std::vector< TableLayout::ColumnParam > const & columnsParam, st { bool subColum = false; std::vector< TableLayout::Column > subColumnsToAdd; - TableLayout::Column columnToAdd = {columnParam, {}, "", {}}; + TableLayout::Column columnToAdd = {columnParam, {}, {}, {}}; for( const auto & subColumnsName: columnParam.subColumns ) { subColum = true; - TableLayout::Column subColumn= {subColumnsName, {}, "", {}}; + TableLayout::Column subColumn= {subColumnsName, {}, {}, {}}; subColumnsToAdd.push_back( subColumn ); - columnToAdd = { columnParam, {}, "", subColumnsToAdd }; + columnToAdd = { columnParam, {}, {}, subColumnsToAdd }; } if( subColum ) { @@ -41,7 +41,7 @@ void addColumn( std::vector< TableLayout::ColumnParam > const & columnsParam, st } else { - columns.push_back( { columnParam, {}, "", {}} ); + columns.push_back( { columnParam, {}, {}, {}} ); } } } @@ -53,7 +53,7 @@ TableLayout::TableLayout( std::vector< string > const & columnNames, string cons m_columns.reserve( columnNames.size() ); for( auto const & name : columnNames ) { - m_columns.push_back( {TableLayout::ColumnParam{{name}, Alignment::right, true}, {}, "", {}} ); + m_columns.push_back( {TableLayout::ColumnParam{{name}, Alignment::right, true}, {}, {}, {}} ); } } diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 10e37ffee32..4d3b1786d3d 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -115,8 +115,8 @@ class TableLayout ColumnParam m_parameter; /// A vector containing all column values std::vector< string > m_columnValues; - /// The largest string in the column - string m_maxStringSize; + /// The largest string(s) in the column + std::vector< string > m_maxStringSize; //sub divison of a column std::vector< Column > subColumn; From 267d065c514fcf321d601092eeaa4c40beedc07d Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 13 Sep 2024 10:41:39 +0200 Subject: [PATCH 157/216] some opti --- .../common/format/table/TableFormatter.cpp | 144 +++++++++--------- .../common/format/table/TableFormatter.hpp | 22 ++- 2 files changed, 87 insertions(+), 79 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index a5d6757cbb2..13bbb64669e 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -167,7 +167,7 @@ void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Col std::vector< std::vector< std::string > > tSubColumnValues( subColumnValues[0].size(), std::vector< std::string >( subColumnValues.size()) ); transpose( tSubColumnValues, subColumnValues ); for( const auto & columnValues : tSubColumnValues ) - { + { // add all subcolumn values in parent column column.m_columnValues.insert( column.m_columnValues.end(), columnValues.begin(), columnValues.end() ); } currentColumn += subColumnValues.size(); @@ -197,7 +197,7 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) formatColumnsFromLayout( columns, tableDataRows ); fillTableColumnsFromRows( columns, tableDataRows, false ); outputLayout( tableOutput, columns, msgTableError, sectionSeparatingLine ); - outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbValuesRows, TableLayout::Section::values ); + outputValuesSectionRows( columns, tableOutput, nbValuesRows, sectionSeparatingLine ); tableOutput << '\n'; return tableOutput.str(); @@ -227,7 +227,7 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, outputTopRows( tableOutput, {tableTitle}, topSeparator, TableLayout::Alignment::center ); outputTopRows( tableOutput, msgTableError, topSeparator, TableLayout::Alignment::left ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbHeaderRows, TableLayout::Section::header ); + outputHeaderSectionRows( columns, tableOutput, nbHeaderRows, sectionSeparatingLine ); } void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Column > & columns, @@ -306,7 +306,7 @@ void TableTextFormatter::findAndSetMaxStringSize( TableLayout::Column & column, { // affectation if( maxStringSize[idxMaxString].length() < maxStringColumn.length() ) { - maxStringSize[idxMaxString] = maxStringColumn ; + maxStringSize[idxMaxString] = maxStringColumn; } } @@ -317,7 +317,7 @@ void TableTextFormatter::findAndSetMaxStringSize( TableLayout::Column & column, column.m_maxStringSize.clear(); for( auto & subC : column.subColumn ) { - + findAndSetMaxStringSize( subC, column.m_maxStringSize, idxSubColumn ); std::cout << "- debug maxString - "<< column.m_parameter.columnName << std::endl; @@ -334,7 +334,7 @@ void TableTextFormatter::findAndSetMaxStringSize( TableLayout::Column & column, } } - std::cout << "- debug maxString 2- "<< column.m_parameter.columnName << std::endl; //TODO DOU VIENS LE NODE JE VOIS + std::cout << "- debug maxString 2- "<< column.m_parameter.columnName << std::endl; //TODO DOU VIENS LE NODE JE VOIS for( auto const & value : column.m_maxStringSize ) { std::cout << value << " "; @@ -354,9 +354,8 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & integer const borderMargin = m_tableLayout.getBorderMargin(); string const tableTitle = string( m_tableLayout.getTitle() ); - // compute table error msg length string::size_type msgTableErrorLength = borderMargin; - { + { // compute table error msg length if( !msgTableError.empty() ) { auto maxStringSize = *(std::max_element( msgTableError.begin(), msgTableError.end(), @@ -370,26 +369,13 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & string::size_type sectionLengthWithSpacing = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); string::size_type sectionlineLength = sectionLengthWithSpacing; - { // compute table section length TODO A FONCTION - integer const spacesToAdd = m_tableLayout.getColumnMargin(); - bool isFirstIteration = true; + string const spaces = std::string( m_tableLayout.getColumnMargin(), ' ' ); + { sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, [&]( auto sum, auto & column ) -> auto { - std::string maxStringSize = std::accumulate( column.m_maxStringSize.begin(), column.m_maxStringSize.end(), std::string(), - [spacesToAdd, &isFirstIteration]( std::string acc, const std::string & curr ) { - if( isFirstIteration ) - { - isFirstIteration = false; - return curr; - } - else - { - return acc + std::string( spacesToAdd, ' ' ) + curr; - } - } ); - - return static_cast< decltype(sum) >(sum + maxStringSize.length()); + std::string sumOfString = stringutilities::join( column.m_maxStringSize, spaces ); + return static_cast< decltype(sum) >(sum + sumOfString.length()); } ); } @@ -420,15 +406,7 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column } ); } - std::cout << "seprator" << std::endl; - for( auto const & seprator : maxStringPerColumn ) - { - std::cout << seprator; - } - std::cout << std::endl; - - string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", m_horizontalLine, columnMargin ); - + std::string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", m_horizontalLine, columnMargin ); std::string const leftBorder = GEOS_FMT( "{}{:-<{}}", m_horizontalLine, "", borderMargin ); std::string const rightBorder = GEOS_FMT( "{}{:-<{}}", m_horizontalLine, "", borderMargin ); std::string const columnJoin = stringutilities::join( maxStringPerColumn, patternBetweenColumns ); @@ -476,49 +454,32 @@ void TableTextFormatter::outputSubSection( std::vector< TableLayout::Column > co } } -void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > const & columns, - string_view sectionSeparatingLine, - std::ostringstream & tableOutput, - size_t const nbRows, - TableLayout::Section const section ) const +void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Column > const & columns, + std::ostringstream & tableOutput, + size_t const nbRows, + string_view sectionSeparatingLine ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); - bool containSubColumn = false; - for( size_t idxRow = 0; idxRow< nbRows; ++idxRow ) + string const spaces = std::string( columnMargin, ' ' ); + for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) { // Append the left border - tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, 1 + borderMargin ); + tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, 1 + borderMargin ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { auto const & column = columns[idxColumn]; - if( section == TableLayout::Section::values && !column.subColumn.empty()) + if( !column.subColumn.empty()) { outputSubSection( column.subColumn, tableOutput, idxRow ); } else { - TableLayout::Column const currentColumn = column; - auto const & columnContent = section == TableLayout::Section::header ? - column.m_parameter.splitColumnNameLines : - column.m_columnValues; - string cell = columnContent.at( idxRow ); - bool isFirstIteration = true; - integer const cellSize = std::accumulate( column.m_maxStringSize.begin(), column.m_maxStringSize.end(), 0, - [&isFirstIteration, &columnMargin]( int sum, const std::string & str ) { - if( isFirstIteration ) - { - isFirstIteration = false; - return sum + str.length(); - } - else - { - return sum + columnMargin + str.length(); - } - } ); - tableOutput << buildCell( currentColumn.m_parameter.alignment, cell, cellSize ); + string cell = column.m_columnValues.at( idxRow ); + std::string cellSize = stringutilities::join( column.m_maxStringSize, spaces ); + tableOutput << buildCell( column.m_parameter.alignment, cell, cellSize.length()); // Add space between column if( idxColumn < columns.size() - 1 ) @@ -527,7 +488,46 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c } } - if( !column.subColumn.empty() ) + } + // Append right border with line return + tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, borderMargin + 1 ); + } + + if( nbRows != 0 ) + { + tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); + } +} + +void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Column > const & columns, + std::ostringstream & tableOutput, + size_t const nbRows, + string_view sectionSeparatingLine ) const +{ + integer const columnMargin = m_tableLayout.getColumnMargin(); + integer const borderMargin = m_tableLayout.getBorderMargin(); + string const spaces = std::string( columnMargin, ' ' ); + bool containSubColumn = false; + + for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) + { + // Append the left border + tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, 1 + borderMargin ); + + for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) + { + auto const & column = columns[idxColumn]; + string cell = column.m_parameter.splitColumnNameLines.at( idxRow ); + std::string cellSize = stringutilities::join( column.m_maxStringSize, spaces ); + tableOutput << buildCell( column.m_parameter.alignment, cell, cellSize.length()); + + // Add space between columns + if( idxColumn < columns.size() - 1 ) + { + tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); + } + + if( !column.subColumn.empty()) { containSubColumn = true; } @@ -541,29 +541,25 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); } - //check and build sub row header - if( section == TableLayout::Section::header && containSubColumn ) + // Check and build subrow header + if( containSubColumn ) { std::vector< TableLayout::Column > rowSubColumns; for( auto const & column : columns ) { - if( column.subColumn.empty() ) + if( column.subColumn.empty()) { - TableLayout::Column emptyColumn = {TableLayout::ColumnParam{""}, {}, column.m_maxStringSize, {}}; - rowSubColumns.push_back( emptyColumn ); + rowSubColumns.push_back( {TableLayout::ColumnParam{""}, {}, column.m_maxStringSize, {}} ); } else { - for( auto const & subColumn : column.subColumn ) - { - rowSubColumns.push_back( subColumn ); - } + rowSubColumns.insert( rowSubColumns.end(), column.subColumn.begin(), column.subColumn.end()); } } - outputSectionRows( rowSubColumns, sectionSeparatingLine, tableOutput, 1, TableLayout::Section::header ); + outputHeaderSectionRows( rowSubColumns, tableOutput, 1, sectionSeparatingLine ); } - } + } diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 7c67844e4a9..f7c8b1604e8 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -237,11 +237,23 @@ class TableTextFormatter : public TableFormatter * @param section The section to be built * @note Add the ending line if there are one or more rows */ - void outputSectionRows( std::vector< TableLayout::Column > const & columns, - string_view sectionSeparatingLine, - std::ostringstream & tableOutput, - size_t const nbRows, - TableLayout::Section const section ) const; + void outputValuesSectionRows( std::vector< TableLayout::Column > const & columns, + std::ostringstream & tableOutput, + size_t const nbRows, + string_view sectionSeparatingLine ) const; + + /** + * @brief + * + * @param columns + * @param tableOutput + * @param nbRows + * @param sectionSeparatingLine + */ + void outputHeaderSectionRows( std::vector< TableLayout::Column > const & columns, + std::ostringstream & tableOutput, + size_t const nbRows, + string_view sectionSeparatingLine ) const; /** * @brief From 985c88c77942e02511196e395229e6d6d1de0ba6 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 13 Sep 2024 16:49:24 +0200 Subject: [PATCH 158/216] some refactor --- .../common/format/table/TableFormatter.cpp | 274 ++++++++---------- .../common/format/table/TableFormatter.hpp | 95 +++--- 2 files changed, 182 insertions(+), 187 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 13bbb64669e..e16dd2e5df0 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -113,8 +113,8 @@ string buildCell( TableLayout::Alignment const alignment, string_view value, siz * @param columns Vector built in TableLayout containing all columns with their parameters * @param tableDataRows Vector built in TableData containing all rows values */ -void formatColumnsFromLayout( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > & tableDataRows ) +void updateVisibleColumns( std::vector< TableLayout::Column > & columns, + std::vector< std::vector< string > > & tableDataRows ) { integer idxColumn = 0; for( auto iterColumn = columns.begin(); iterColumn!=columns.end(); ) @@ -139,9 +139,9 @@ TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): TableFormatter( tableLayout ) {} -void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< std::string > > const & tableDataRows, - bool isSubColumn ) const +void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout::Column > & columns, + std::vector< std::vector< std::string > > const & tableDataRows, + bool isSubColumn ) const { size_t currentColumn = 0; std::vector< std::vector< std::string > > tColumnsValues( tableDataRows[0].size(), std::vector< std::string >( tableDataRows.size())); @@ -159,10 +159,9 @@ void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Col } else { - std::cout << " nb sous col "<< column.m_parameter.subColumns.size() << std::endl; std::vector< std::vector< std::string > > subColumnValues( tColumnsValues.begin() + currentColumn, tColumnsValues.begin() + currentColumn + column.m_parameter.subColumns.size()); - fillTableColumnsFromRows( column.subColumn, subColumnValues, true ); + populateColumnsFromTableData( column.subColumn, subColumnValues, true ); std::vector< std::vector< std::string > > tSubColumnValues( subColumnValues[0].size(), std::vector< std::string >( subColumnValues.size()) ); transpose( tSubColumnValues, subColumnValues ); @@ -178,9 +177,21 @@ void TableTextFormatter::fillTableColumnsFromRows( std::vector< TableLayout::Col string TableTextFormatter::layoutToString() const { std::ostringstream tableOutput; - string sectionSeparatingLine; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); - outputLayout( tableOutput, columns, {}, sectionSeparatingLine ); + string const tableTitle = string( m_tableLayout.getTitle()); + size_t nbHeaderRows = 0; + TableData tableData; + std::string sectionSeparatingLine; + std::string topSeparator; + + prepareAndBuildTable( columns, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); + + tableOutput << '\n'; //TODO Fonction + outputTitleRow( tableOutput, topSeparator ); + tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); + + outputHeaderSectionRows( columns, tableOutput, nbHeaderRows, sectionSeparatingLine ); + return tableOutput.str(); } @@ -188,54 +199,70 @@ template<> string TableTextFormatter::toString< TableData >( TableData const & tableData ) const { std::ostringstream tableOutput; - string sectionSeparatingLine; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); - std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); - std::vector< string > const & msgTableError = tableData.getErrorMsgs(); - integer const nbValuesRows = tableDataRows.size(); + size_t nbHeaderRows = 0; + std::string sectionSeparatingLine; + std::string topSeparator; - formatColumnsFromLayout( columns, tableDataRows ); - fillTableColumnsFromRows( columns, tableDataRows, false ); - outputLayout( tableOutput, columns, msgTableError, sectionSeparatingLine ); - outputValuesSectionRows( columns, tableOutput, nbValuesRows, sectionSeparatingLine ); - tableOutput << '\n'; + prepareAndBuildTable( columns, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); + + outputTable( tableOutput, columns, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); return tableOutput.str(); } -void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, - std::vector< TableLayout::Column > & columns, - std::vector< string > const & msgTableError, - string & sectionSeparatingLine ) const +void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::Column > & columns, + TableData const & tableData, + size_t & nbHeaderRows, + std::string & sectionSeparatingLine, + std::string & topSeparator ) const { - string topSeparator; - size_t nbHeaderRows = 0; + std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); std::vector< std::vector< string > > splitHeaders; - string const tableTitle = string( m_tableLayout.getTitle()); - std::string maxStringSize = " "; - splitAndSetColumnNames( columns, nbHeaderRows, splitHeaders ); + if( !tableData.getTableDataRows().empty()) + { + updateVisibleColumns( columns, tableDataRows ); + populateColumnsFromTableData( columns, tableDataRows, false ); + } + + splitAndMergeColumnHeaders( columns, nbHeaderRows, splitHeaders ); + for( auto & column : columns ) { - findAndSetMaxStringSize( column, column.m_maxStringSize, 0 ); + findAndSetLongestColumnString( column, column.m_maxStringSize, 0 ); } + computeTableWidth( columns ); + buildTableSeparators( columns, sectionSeparatingLine, topSeparator ); +} - computeTableWidth( columns, msgTableError ); - buildTableSeparators( columns, topSeparator, sectionSeparatingLine ); +void TableTextFormatter::outputTable( std::ostringstream & tableOutput, + std::vector< TableLayout::Column > & columns, + TableData const & tableData, + size_t & nbHeaderRows, + std::string const & sectionSeparatingLine, + std::string const & topSeparator ) const +{ + integer const nbValuesRows = tableData.getTableDataRows().size(); - tableOutput << '\n'; - outputTopRows( tableOutput, {tableTitle}, topSeparator, TableLayout::Alignment::center ); - outputTopRows( tableOutput, msgTableError, topSeparator, TableLayout::Alignment::left ); + tableOutput << '\n'; //TODO Fonction + outputTitleRow( tableOutput, topSeparator ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); + outputHeaderSectionRows( columns, tableOutput, nbHeaderRows, sectionSeparatingLine ); + + outputValuesSectionRows( columns, tableOutput, nbValuesRows, sectionSeparatingLine ); + + tableOutput << '\n'; } -void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Column > & columns, - size_t & nbHeaderRows, - std::vector< std::vector< string > > & splitHeaders ) const +void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::Column > & columns, + size_t & nbHeaderRows, + std::vector< std::vector< string > > & splitHeaders ) const { splitHeaders.reserve( columns.size() ); + for( auto & column : columns ) { std::vector< string > splitHeaderParts; @@ -253,7 +280,7 @@ void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Colum { std::vector< std::vector< string > > splitSubColHeaders; size_t nbHeaderSubColRows = 0; - splitAndSetColumnNames( column.subColumn, nbHeaderSubColRows, splitSubColHeaders ); + splitAndMergeColumnHeaders( column.subColumn, nbHeaderSubColRows, splitSubColHeaders ); } } @@ -266,30 +293,22 @@ void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Colum { headerParts.resize( nbHeaderRows, " " ); } - columns[&headerParts - &splitHeaders[0]].m_parameter.splitColumnNameLines = headerParts; + columns[&headerParts - &splitHeaders[0]].m_parameter.splitColumnNames = headerParts; } } -void TableTextFormatter::findAndSetMaxStringSize( TableLayout::Column & column, std::vector< std::string > & maxStringSize, integer const idxMaxString ) const +void TableTextFormatter::findAndSetLongestColumnString( TableLayout::Column & column, std::vector< std::string > & maxStringSize, integer const idxMaxString ) const { - string maxStringColumn = ""; - - {// header case - auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnNameLines.begin(), - column.m_parameter.splitColumnNameLines.end(), + string maxStringColumn; + { // header case + auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnNames.begin(), + column.m_parameter.splitColumnNames.end(), []( const auto & a, const auto & b ) {return a.size() < b.size();} ); maxStringColumn = maxStringSizeHeader; maxStringSize.push_back( maxStringSizeHeader ); } - std::cout << "- debug maxString 1- "<< column.m_parameter.columnName << std::endl; - for( auto const & value : maxStringSize ) - { - std::cout << value << " "; - } - std::cout << std::endl; - { // values case if( column.subColumn.empty() ) { @@ -303,74 +322,41 @@ void TableTextFormatter::findAndSetMaxStringSize( TableLayout::Column & column, } } - { // affectation + { // Update max string size if necessary if( maxStringSize[idxMaxString].length() < maxStringColumn.length() ) { maxStringSize[idxMaxString] = maxStringColumn; } } - { // subcolumn values case + { // subcolumn values case if( !column.subColumn.empty() ) { - integer idxSubColumn = 0; column.m_maxStringSize.clear(); - for( auto & subC : column.subColumn ) + for( size_t idxSubColumn = 0; idxSubColumn < column.subColumn.size(); ++idxSubColumn ) { - - findAndSetMaxStringSize( subC, column.m_maxStringSize, idxSubColumn ); - - std::cout << "- debug maxString - "<< column.m_parameter.columnName << std::endl; - for( auto const & value : column.m_maxStringSize ) - { - std::cout << value << " "; - } - - //TODO Condition pour check Nodes et tout les cols OU ALORS DEPLACER AU DEBUT - std::cout << std::endl; - - idxSubColumn++; + findAndSetLongestColumnString( column.subColumn[idxSubColumn], column.m_maxStringSize, idxSubColumn ); } } } - std::cout << "- debug maxString 2- "<< column.m_parameter.columnName << std::endl; //TODO DOU VIENS LE NODE JE VOIS - for( auto const & value : column.m_maxStringSize ) - { - std::cout << value << " "; - } - std::cout << std::endl; - if( column.m_maxStringSize.empty() ) { column.m_maxStringSize.push_back( maxStringColumn ); } } -void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & columns, - std::vector< string > const & msgTableError ) const +void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & columns ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); string const tableTitle = string( m_tableLayout.getTitle() ); - string::size_type msgTableErrorLength = borderMargin; - { // compute table error msg length - if( !msgTableError.empty() ) - { - auto maxStringSize = *(std::max_element( msgTableError.begin(), msgTableError.end(), - []( const auto & a, const auto & b ) { - return a.size() < b.size(); - } )); - - msgTableErrorLength += maxStringSize.size() + 1; // max string size + line return at the end - } - } - - string::size_type sectionLengthWithSpacing = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); + string::size_type const sectionLengthWithSpacing = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); string::size_type sectionlineLength = sectionLengthWithSpacing; string const spaces = std::string( m_tableLayout.getColumnMargin(), ' ' ); - { + + { // Compute total length of all columns with margins sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, [&]( auto sum, auto & column ) -> auto { @@ -380,65 +366,45 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & } string::size_type maxTopLineLength = tableTitle.length(); - maxTopLineLength = std::max( maxTopLineLength, msgTableErrorLength ); - maxTopLineLength = std::max( maxTopLineLength, sectionlineLength ); - std::cout << "- max length - " << sectionlineLength << " " << maxTopLineLength << std::endl; - - //refaire le calcul du max string par colonnes ici - - + maxTopLineLength = std::max( {maxTopLineLength, sectionlineLength} ); } void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column > const & columns, - string & topSeparator, - string & sectionSeparatingLine ) const + std::string & sectionSeparatingLine, + std::string & topSeparator ) const { - { // section separator line - integer const columnMargin = m_tableLayout.getColumnMargin(); - integer const borderMargin = m_tableLayout.getBorderMargin(); + integer const columnMargin = m_tableLayout.getColumnMargin(); + integer const borderMargin = m_tableLayout.getBorderMargin(); - std::vector< string > maxStringPerColumn; - for( auto const & column : columns ) //TODO Check ca - { - std::for_each( column.m_maxStringSize.begin(), column.m_maxStringSize.end(), [&] ( std::string maxString ) { - maxStringPerColumn.push_back( string( maxString.length(), m_horizontalLine ) ); - } ); - } + std::vector< string > maxStringsPerColumn; + for( auto const & column : columns ) + { + std::for_each( column.m_maxStringSize.begin(), column.m_maxStringSize.end(), [&] ( std::string maxString ) { + maxStringsPerColumn.push_back( string( maxString.length(), m_horizontalLine ) ); + } ); + } - std::string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", m_horizontalLine, columnMargin ); - std::string const leftBorder = GEOS_FMT( "{}{:-<{}}", m_horizontalLine, "", borderMargin ); - std::string const rightBorder = GEOS_FMT( "{}{:-<{}}", m_horizontalLine, "", borderMargin ); - std::string const columnJoin = stringutilities::join( maxStringPerColumn, patternBetweenColumns ); + std::string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", m_horizontalLine, columnMargin ); + std::string const leftBorder = GEOS_FMT( "{}{:-<{}}", m_horizontalLine, "", borderMargin - 1 ); + std::string const rightBorder = GEOS_FMT( "{}{:-<{}}", m_horizontalLine, "", borderMargin - 1 ); - std::ostringstream oss; - oss << leftBorder << columnJoin << rightBorder; - sectionSeparatingLine = oss.str(); - } + // Join all parts to form the section separating line + std::string const columnJoin = stringutilities::join( maxStringsPerColumn, patternBetweenColumns ); + std::ostringstream oss; + oss << leftBorder << columnJoin << rightBorder; + sectionSeparatingLine = oss.str(); - { // top line separator - // -2 because we can have '+' to the extremity of top separator - integer const topSeparatorLength = sectionSeparatingLine.size() - 2; - topSeparator = GEOS_FMT( "{}{:-<{}}{}", m_horizontalLine, "", topSeparatorLength, m_horizontalLine ); - } + integer const topSeparatorLength = sectionSeparatingLine.size() - 2; // Adjust for border characters + topSeparator = GEOS_FMT( "{}{:-<{}}{}", m_horizontalLine, "", topSeparatorLength, m_horizontalLine ); } -void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, - std::vector< string > const & msg, - string_view topSeparator, - TableLayout::Alignment alignment ) const -{ - if( msg.size() != 0 && msg[0] != "" ) - { - tableOutput << GEOS_FMT( "{}\n", topSeparator ); - for( std::string const & str : msg ) - { - tableOutput << m_verticalLine << string( m_tableLayout.getBorderMargin(), ' ' ); - tableOutput << buildCell( alignment, str, (topSeparator.length() - 6)); - tableOutput << string( m_tableLayout.getBorderMargin(), ' ' ) << "|\n"; - } - } -} +// void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, +// std::vector< string > const & msg, +// string_view topSeparator, +// TableLayout::Alignment alignment, +// string_view sectionSeparatingLine ) const +// {} void TableTextFormatter::outputSubSection( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, @@ -457,15 +423,16 @@ void TableTextFormatter::outputSubSection( std::vector< TableLayout::Column > co void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, size_t const nbRows, - string_view sectionSeparatingLine ) const + std::string const & sectionSeparatingLine ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); string const spaces = std::string( columnMargin, ' ' ); + for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) { // Append the left border - tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, 1 + borderMargin ); + tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, borderMargin ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { @@ -490,7 +457,7 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu } // Append right border with line return - tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, borderMargin + 1 ); + tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, borderMargin ); } if( nbRows != 0 ) @@ -499,10 +466,23 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu } } +void TableTextFormatter::outputTitleRow( std::ostringstream & tableOutput, + std::string const & topSeparator ) const +{ + string const tableTitle = string( m_tableLayout.getTitle()); + if( !tableTitle.empty() ) + { + tableOutput << GEOS_FMT( "{}\n", topSeparator ); + tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, m_tableLayout.getBorderMargin()); + tableOutput << buildCell( TableLayout::Alignment::left, tableTitle, (topSeparator.length() - 6)); + tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, m_tableLayout.getBorderMargin() ); + } +} + void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, size_t const nbRows, - string_view sectionSeparatingLine ) const + std::string const & sectionSeparatingLine ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); @@ -512,12 +492,12 @@ void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Colu for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) { // Append the left border - tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, 1 + borderMargin ); + tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, borderMargin ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { auto const & column = columns[idxColumn]; - string cell = column.m_parameter.splitColumnNameLines.at( idxRow ); + string cell = column.m_parameter.splitColumnNames.at( idxRow ); std::string cellSize = stringutilities::join( column.m_maxStringSize, spaces ); tableOutput << buildCell( column.m_parameter.alignment, cell, cellSize.length()); @@ -533,7 +513,7 @@ void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Colu } } // Append right border with line return - tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, borderMargin + 1 ); + tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, borderMargin ); } if( nbRows != 0 ) diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index f7c8b1604e8..f3fcb7b3ccb 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -115,7 +115,6 @@ class TableTextFormatter : public TableFormatter { public: - /** * @brief Construct a new TableFormatter */ @@ -156,25 +155,37 @@ class TableTextFormatter : public TableFormatter static constexpr char m_horizontalLine = '-'; /** - * @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 + * @brief + * @param columns + * @param nbHeaderRows */ - void fillTableColumnsFromRows( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< string > > const & tableData, - bool isSubColumn ) const; + void prepareAndBuildTable( std::vector< TableLayout::Column > & columns, + TableData const & tableData, + size_t & nbHeaderRows, + std::string & sectionSeparatingLine, + std::string & topSeparator ) const; +/** + * @brief + * + * @param tableOutput + * @param columns + * @param nbHeaderRows + */ + void outputTable( std::ostringstream & tableOutput, + std::vector< TableLayout::Column > & columns, + TableData const & tableData, + size_t & nbHeaderRows, + std::string const & sectionSeparatingLine, + std::string const & topSeparator ) const; /** - * @brief Converts a TableLayout into a formatted representation. - * @param tableOutput The output stream - * @param columns The vector containing all table columns - * @param msgTableError A vector containg all error related to the table - * @param sectionSeparatingLine An empty string for building the section separator + * @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 */ - void outputLayout( std::ostringstream & tableOutput, - std::vector< TableLayout::Column > & columns, - std::vector< string > const & msgTableError, - string & sectionSeparatingLine ) const; + void populateColumnsFromTableData( std::vector< TableLayout::Column > & columns, + std::vector< std::vector< string > > const & tableData, + bool isSubColumn ) const; /** * @brief Split all header names by detecting the newline \\n character. and @@ -183,38 +194,34 @@ class TableTextFormatter : public TableFormatter * @param largestHeaderVectorSize The largest split header vector size * @param splitHeaders A empty vector who will contain all split header names */ - void splitAndSetColumnNames( std::vector< TableLayout::Column > & columns, - size_t & largestHeaderVectorSize, - std::vector< std::vector< string > > & splitHeaders ) const; + void splitAndMergeColumnHeaders( std::vector< TableLayout::Column > & columns, + size_t & largestHeaderVectorSize, + std::vector< std::vector< string > > & splitHeaders ) const; /** * @brief For each column find and set the column's longest string - * - * + * @param maxStringSize The largest string(s) in the column * @param columns The vector containg all columns + * @param idxColumn The current index of the column */ - void findAndSetMaxStringSize( TableLayout::Column & columns, - std::vector< std::string > & maxStringSize, - integer const idxColumn ) const; + void findAndSetLongestColumnString( TableLayout::Column & column, + std::vector< std::string > & maxStringSize, + integer const idxColumn ) const; /** * @brief Compute the max table line length, taking into account the length of : title, error, columns header and content * Increase the size of the columns if necessary * @param columns Vector of column containing containing the largest string for each column - * @param msgTableError Vector containing all error messages */ - void computeTableWidth( std::vector< TableLayout::Column > & columns, - std::vector< string > const & msgTableError ) const; + void computeTableWidth( std::vector< TableLayout::Column > & columns ) const; /** * @brief Build all separators needed from content length contained in the columns vector * @param columns Vector containing all table columns - * @param topSeparator Top separator to be built - * @param sectionSeparatingLine Line section separator to be built */ void buildTableSeparators( std::vector< TableLayout::Column > const & columns, - string & topSeparator, - string & sectionSeparatingLine ) const; + std::string & sectionSeparatingLine, + std::string & topSeparator ) const; /** * @brief Add a row on top of the table @@ -226,7 +233,8 @@ class TableTextFormatter : public TableFormatter void outputTopRows( std::ostringstream & tableOutput, std::vector< string > const & msg, string_view topSeparator, - TableLayout::Alignment alignment ) const; + TableLayout::Alignment alignment, + string_view sectionSeparatingLine ) const; /** * @brief Output a section by specifying it's type ( header or section ) @@ -240,20 +248,27 @@ class TableTextFormatter : public TableFormatter void outputValuesSectionRows( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, size_t const nbRows, - string_view sectionSeparatingLine ) const; + std::string const & sectionSeparatingLine ) const; /** - * @brief - * - * @param columns - * @param tableOutput - * @param nbRows - * @param sectionSeparatingLine + * @brief Construct a new output Title Row object + * @param topSeparator + */ + void outputTitleRow( std::ostringstream & tableOutput, + std::string const & topSeparator ) const; + + /** + * @brief + * + * @param columns + * @param tableOutput + * @param nbRows + * @param sectionSeparatingLine */ void outputHeaderSectionRows( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, size_t const nbRows, - string_view sectionSeparatingLine ) const; + std::string const & sectionSeparatingLine ) const; /** * @brief From 59e31341c304191817d51046f59274789140db62 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 13 Sep 2024 16:56:05 +0200 Subject: [PATCH 159/216] getter margin adjustment --- src/coreComponents/common/format/table/TableLayout.cpp | 2 +- src/coreComponents/common/format/table/TableLayout.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 9df9c4d629b..7b9d488238b 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -79,7 +79,7 @@ TableLayout::TableLayout( std::vector< ColumnParam > const & columnParams, strin void TableLayout::setMargin( MarginValue marginValue ) { - m_borderMargin = marginValue; + m_borderMargin = marginValue + 1 ; m_columnMargin = integer( marginValue ) * 2 + 1; } diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 4d3b1786d3d..78d19a396b7 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -64,7 +64,7 @@ class TableLayout /// std::vector< string > subColumns; /// Vector containing substring column name delimited by "\n" - std::vector< string > splitColumnNameLines = {""}; + std::vector< string > splitColumnNames = {""}; /** * @brief Construct a ColumnParam object with the specified name and alignment. @@ -164,7 +164,7 @@ class TableLayout string_view getTitle() const; /** - * @return The border margin, number of spaces at both left and right table sides + * @return The border margin, number of spaces at both left and right table sides plus vertical character */ integer const & getBorderMargin() const; From b7bdb04bad627dd5522d9e5393cc0ed5d251b6a1 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 13 Sep 2024 16:56:22 +0200 Subject: [PATCH 160/216] moving code --- .../common/format/table/TableFormatter.cpp | 81 +++++++++---------- 1 file changed, 38 insertions(+), 43 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index e16dd2e5df0..6ae1355db51 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -13,6 +13,8 @@ * ------------------------------------------------------------------------------------------------------------ */ + +//TODO REAJUSTER LAPPEL DES FONCTIONS /** * @file TableFormatter.cpp */ @@ -139,41 +141,6 @@ TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): TableFormatter( tableLayout ) {} -void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< std::string > > const & tableDataRows, - bool isSubColumn ) const -{ - size_t currentColumn = 0; - std::vector< std::vector< std::string > > tColumnsValues( tableDataRows[0].size(), std::vector< std::string >( tableDataRows.size())); - if( !isSubColumn ) - { - transpose( tColumnsValues, tableDataRows ); - } - - for( auto & column : columns ) - { - if( column.subColumn.empty()) - { - column.m_columnValues = !isSubColumn ? - tColumnsValues[currentColumn++] : tableDataRows[currentColumn++]; - } - else - { - std::vector< std::vector< std::string > > subColumnValues( tColumnsValues.begin() + currentColumn, - tColumnsValues.begin() + currentColumn + column.m_parameter.subColumns.size()); - populateColumnsFromTableData( column.subColumn, subColumnValues, true ); - - std::vector< std::vector< std::string > > tSubColumnValues( subColumnValues[0].size(), std::vector< std::string >( subColumnValues.size()) ); - transpose( tSubColumnValues, subColumnValues ); - for( const auto & columnValues : tSubColumnValues ) - { // add all subcolumn values in parent column - column.m_columnValues.insert( column.m_columnValues.end(), columnValues.begin(), columnValues.end() ); - } - currentColumn += subColumnValues.size(); - } - } -} - string TableTextFormatter::layoutToString() const { std::ostringstream tableOutput; @@ -189,7 +156,7 @@ string TableTextFormatter::layoutToString() const tableOutput << '\n'; //TODO Fonction outputTitleRow( tableOutput, topSeparator ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - + outputHeaderSectionRows( columns, tableOutput, nbHeaderRows, sectionSeparatingLine ); return tableOutput.str(); @@ -256,6 +223,41 @@ void TableTextFormatter::outputTable( std::ostringstream & tableOutput, tableOutput << '\n'; } +void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout::Column > & columns, + std::vector< std::vector< std::string > > const & tableDataRows, + bool isSubColumn ) const +{ + size_t currentColumn = 0; + std::vector< std::vector< std::string > > tColumnsValues( tableDataRows[0].size(), std::vector< std::string >( tableDataRows.size())); + if( !isSubColumn ) + { + transpose( tColumnsValues, tableDataRows ); + } + + for( auto & column : columns ) + { + if( column.subColumn.empty()) + { + column.m_columnValues = !isSubColumn ? + tColumnsValues[currentColumn++] : tableDataRows[currentColumn++]; + } + else + { + std::vector< std::vector< std::string > > subColumnValues( tColumnsValues.begin() + currentColumn, + tColumnsValues.begin() + currentColumn + column.m_parameter.subColumns.size()); + populateColumnsFromTableData( column.subColumn, subColumnValues, true ); + + std::vector< std::vector< std::string > > tSubColumnValues( subColumnValues[0].size(), std::vector< std::string >( subColumnValues.size()) ); + transpose( tSubColumnValues, subColumnValues ); + for( const auto & columnValues : tSubColumnValues ) + { // add all subcolumn values in parent column + column.m_columnValues.insert( column.m_columnValues.end(), columnValues.begin(), columnValues.end() ); + } + currentColumn += subColumnValues.size(); + } + } +} + void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::Column > & columns, size_t & nbHeaderRows, std::vector< std::vector< string > > & splitHeaders ) const @@ -399,13 +401,6 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column topSeparator = GEOS_FMT( "{}{:-<{}}{}", m_horizontalLine, "", topSeparatorLength, m_horizontalLine ); } -// void TableTextFormatter::outputTopRows( std::ostringstream & tableOutput, -// std::vector< string > const & msg, -// string_view topSeparator, -// TableLayout::Alignment alignment, -// string_view sectionSeparatingLine ) const -// {} - void TableTextFormatter::outputSubSection( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, integer idxRow ) const From 2d50cdacfdb3359fd7de4c0b094702f1eb6ef411 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 16 Sep 2024 10:07:32 +0200 Subject: [PATCH 161/216] varaible refactor + unused code --- .../common/format/table/TableFormatter.cpp | 60 +++++++++---------- .../common/format/table/TableLayout.cpp | 17 ------ .../common/format/table/TableLayout.hpp | 19 +----- 3 files changed, 32 insertions(+), 64 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 6ae1355db51..7f0a28856ec 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -48,7 +48,7 @@ string TableCSVFormatter::headerToString() const for( std::size_t idxColumn = 0; idxColumn < m_tableLayout.getColumns().size(); ++idxColumn ) { - oss << m_tableLayout.getColumns()[idxColumn].m_parameter.columnName; + oss << m_tableLayout.getColumns()[idxColumn].parameter.columnName; if( idxColumn < m_tableLayout.getColumns().size() - 1 ) { oss << separator; @@ -121,7 +121,7 @@ void updateVisibleColumns( std::vector< TableLayout::Column > & columns, integer idxColumn = 0; for( auto iterColumn = columns.begin(); iterColumn!=columns.end(); ) { - if( !iterColumn->m_parameter.enabled ) + if( !iterColumn->parameter.enabled ) { iterColumn = columns.erase( iterColumn ); for( auto & row : tableDataRows ) @@ -145,7 +145,6 @@ string TableTextFormatter::layoutToString() const { std::ostringstream tableOutput; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); - string const tableTitle = string( m_tableLayout.getTitle()); size_t nbHeaderRows = 0; TableData tableData; std::string sectionSeparatingLine; @@ -156,7 +155,6 @@ string TableTextFormatter::layoutToString() const tableOutput << '\n'; //TODO Fonction outputTitleRow( tableOutput, topSeparator ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - outputHeaderSectionRows( columns, tableOutput, nbHeaderRows, sectionSeparatingLine ); return tableOutput.str(); @@ -166,7 +164,7 @@ template<> string TableTextFormatter::toString< TableData >( TableData const & tableData ) const { std::ostringstream tableOutput; - std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); + std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); size_t nbHeaderRows = 0; std::string sectionSeparatingLine; std::string topSeparator; @@ -197,7 +195,7 @@ void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::Column for( auto & column : columns ) { - findAndSetLongestColumnString( column, column.m_maxStringSize, 0 ); + findAndSetLongestColumnString( column, column.maxStringSize, 0 ); } computeTableWidth( columns ); buildTableSeparators( columns, sectionSeparatingLine, topSeparator ); @@ -238,20 +236,20 @@ void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout: { if( column.subColumn.empty()) { - column.m_columnValues = !isSubColumn ? + column.columnValues = !isSubColumn ? tColumnsValues[currentColumn++] : tableDataRows[currentColumn++]; } else { std::vector< std::vector< std::string > > subColumnValues( tColumnsValues.begin() + currentColumn, - tColumnsValues.begin() + currentColumn + column.m_parameter.subColumns.size()); + tColumnsValues.begin() + currentColumn + column.parameter.subColumns.size()); populateColumnsFromTableData( column.subColumn, subColumnValues, true ); std::vector< std::vector< std::string > > tSubColumnValues( subColumnValues[0].size(), std::vector< std::string >( subColumnValues.size()) ); transpose( tSubColumnValues, subColumnValues ); for( const auto & columnValues : tSubColumnValues ) { // add all subcolumn values in parent column - column.m_columnValues.insert( column.m_columnValues.end(), columnValues.begin(), columnValues.end() ); + column.columnValues.insert( column.columnValues.end(), columnValues.begin(), columnValues.end() ); } currentColumn += subColumnValues.size(); } @@ -268,7 +266,7 @@ void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::C for( auto & column : columns ) { std::vector< string > splitHeaderParts; - std::istringstream ss( column.m_parameter.columnName ); + std::istringstream ss( column.parameter.columnName ); string subColumnNames; while( getline( ss, subColumnNames, '\n' )) @@ -295,7 +293,7 @@ void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::C { headerParts.resize( nbHeaderRows, " " ); } - columns[&headerParts - &splitHeaders[0]].m_parameter.splitColumnNames = headerParts; + columns[&headerParts - &splitHeaders[0]].parameter.splitColumnNames = headerParts; } } @@ -304,8 +302,8 @@ void TableTextFormatter::findAndSetLongestColumnString( TableLayout::Column & co { string maxStringColumn; { // header case - auto const maxStringSizeHeader = *std::max_element( column.m_parameter.splitColumnNames.begin(), - column.m_parameter.splitColumnNames.end(), + auto const maxStringSizeHeader = *std::max_element( column.parameter.splitColumnNames.begin(), + column.parameter.splitColumnNames.end(), []( const auto & a, const auto & b ) {return a.size() < b.size();} ); maxStringColumn = maxStringSizeHeader; maxStringSize.push_back( maxStringSizeHeader ); @@ -314,8 +312,8 @@ void TableTextFormatter::findAndSetLongestColumnString( TableLayout::Column & co { // values case if( column.subColumn.empty() ) { - auto const maxStringSizeCell = *std::max_element( column.m_columnValues.begin(), - column.m_columnValues.end(), + auto const maxStringSizeCell = *std::max_element( column.columnValues.begin(), + column.columnValues.end(), []( const auto & a, const auto & b ) {return a.size() < b.size();} ); if( maxStringColumn.length() < maxStringSizeCell.length()) { @@ -334,17 +332,17 @@ void TableTextFormatter::findAndSetLongestColumnString( TableLayout::Column & co { // subcolumn values case if( !column.subColumn.empty() ) { - column.m_maxStringSize.clear(); + column.maxStringSize.clear(); for( size_t idxSubColumn = 0; idxSubColumn < column.subColumn.size(); ++idxSubColumn ) { - findAndSetLongestColumnString( column.subColumn[idxSubColumn], column.m_maxStringSize, idxSubColumn ); + findAndSetLongestColumnString( column.subColumn[idxSubColumn], column.maxStringSize, idxSubColumn ); } } } - if( column.m_maxStringSize.empty() ) + if( column.maxStringSize.empty() ) { - column.m_maxStringSize.push_back( maxStringColumn ); + column.maxStringSize.push_back( maxStringColumn ); } } @@ -362,7 +360,7 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, [&]( auto sum, auto & column ) -> auto { - std::string sumOfString = stringutilities::join( column.m_maxStringSize, spaces ); + std::string sumOfString = stringutilities::join( column.maxStringSize, spaces ); return static_cast< decltype(sum) >(sum + sumOfString.length()); } ); } @@ -382,7 +380,7 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column std::vector< string > maxStringsPerColumn; for( auto const & column : columns ) { - std::for_each( column.m_maxStringSize.begin(), column.m_maxStringSize.end(), [&] ( std::string maxString ) { + std::for_each( column.maxStringSize.begin(), column.maxStringSize.end(), [&] ( std::string maxString ) { maxStringsPerColumn.push_back( string( maxString.length(), m_horizontalLine ) ); } ); } @@ -408,9 +406,9 @@ void TableTextFormatter::outputSubSection( std::vector< TableLayout::Column > co integer const columnMargin = m_tableLayout.getColumnMargin(); for( size_t idxCol = 0; idxCol< columns.size(); ++idxCol ) { - tableOutput << buildCell( columns[idxCol].m_parameter.alignment, - columns[idxCol].m_columnValues[idxRow], - columns[idxCol].m_maxStringSize[0].length() ); + tableOutput << buildCell( columns[idxCol].parameter.alignment, + columns[idxCol].columnValues[idxRow], + columns[idxCol].maxStringSize[0].length() ); tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } } @@ -439,9 +437,9 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu } else { - string cell = column.m_columnValues.at( idxRow ); - std::string cellSize = stringutilities::join( column.m_maxStringSize, spaces ); - tableOutput << buildCell( column.m_parameter.alignment, cell, cellSize.length()); + string cell = column.columnValues.at( idxRow ); + std::string cellSize = stringutilities::join( column.maxStringSize, spaces ); + tableOutput << buildCell( column.parameter.alignment, cell, cellSize.length()); // Add space between column if( idxColumn < columns.size() - 1 ) @@ -492,9 +490,9 @@ void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Colu for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { auto const & column = columns[idxColumn]; - string cell = column.m_parameter.splitColumnNames.at( idxRow ); - std::string cellSize = stringutilities::join( column.m_maxStringSize, spaces ); - tableOutput << buildCell( column.m_parameter.alignment, cell, cellSize.length()); + string cell = column.parameter.splitColumnNames.at( idxRow ); + std::string cellSize = stringutilities::join( column.maxStringSize, spaces ); + tableOutput << buildCell( column.parameter.alignment, cell, cellSize.length()); // Add space between columns if( idxColumn < columns.size() - 1 ) @@ -525,7 +523,7 @@ void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Colu { if( column.subColumn.empty()) { - rowSubColumns.push_back( {TableLayout::ColumnParam{""}, {}, column.m_maxStringSize, {}} ); + rowSubColumns.push_back( {TableLayout::ColumnParam{""}, {}, column.maxStringSize, {}} ); } else { diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 7b9d488238b..5e990dfc4bb 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -62,18 +62,6 @@ TableLayout::TableLayout( std::vector< ColumnParam > const & columnParams, strin { setMargin( MarginValue::medium ); addColumn( columnParams, m_columns ); - - TableLayout::TableOpts tableOpts( {m_columns, 0} ); - for( auto & column : m_columns ) - { - if( !column.subColumn.empty()) - { - tableOpts.maxTableColumns += column.subColumn.size(); - }else{ - ++tableOpts.maxTableColumns; - } - } - m_tableOpts = tableOpts; } @@ -88,11 +76,6 @@ std::vector< TableLayout::Column > const & TableLayout::getColumns() const return m_columns; } -TableLayout::TableOpts const & TableLayout::getTableOpts() const -{ - return m_tableOpts; -} - string_view TableLayout::getTitle() const { return m_tableTitle; diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 78d19a396b7..1abf3ecfb94 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -105,29 +105,22 @@ class TableLayout }; - //TODO ENLEVER LES _ /** * @brief Struct for a column. */ struct Column { /// Structure who contains parameters for a column - ColumnParam m_parameter; + ColumnParam parameter; /// A vector containing all column values - std::vector< string > m_columnValues; + std::vector< string > columnValues; /// The largest string(s) in the column - std::vector< string > m_maxStringSize; + std::vector< string > maxStringSize; //sub divison of a column std::vector< Column > subColumn; }; - struct TableOpts - { - std::vector< Column > columns; - size_t maxTableColumns; - }; - TableLayout() = default; /** @@ -153,10 +146,6 @@ class TableLayout */ std::vector< Column > const & getColumns() const; - /** - * @return The columns vector - */ - TableOpts const & getTableOpts() const; /** * @return The table name @@ -187,8 +176,6 @@ class TableLayout private: std::vector< Column > m_columns; - TableOpts m_tableOpts; - string m_tableTitle; integer m_borderMargin; From f0644cda7ef56cb9249039838c694d907806c916 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 17 Sep 2024 10:59:23 +0200 Subject: [PATCH 162/216] test passed + hpp doxygen + uncrustify --- .../common/format/table/TableFormatter.cpp | 54 +++++++++- .../common/format/table/TableFormatter.hpp | 98 ++++++++++--------- .../common/format/table/TableLayout.cpp | 2 +- .../format/table/unitTests/testTable.cpp | 73 +++----------- 4 files changed, 118 insertions(+), 109 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 7f0a28856ec..b2214df7654 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -81,6 +81,24 @@ string TableCSVFormatter::toString< TableData >( TableData const & tableData ) c ////// Log Formatter implementation /////////////////////////////////////////////////////////////////////// +void distributeSpaces( std::vector< std::string > & vec, int totalSpaces ) +{ + int numElements = vec.size(); + int baseSpaces = totalSpaces / numElements; + int extraSpaces = totalSpaces % numElements; + + for( int i = 0; i < numElements; ++i ) + { + + vec[i] += std::string( baseSpaces, ' ' ); + + if( i < extraSpaces ) + { + vec[i] += ' '; + } + } +} + void transpose( std::vector< std::vector< std::string > > & dest, std::vector< std::vector< std::string > > const & source ) { for( size_t idxRow = 0; idxRow < source.size(); ++idxRow ) @@ -190,13 +208,13 @@ void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::Column updateVisibleColumns( columns, tableDataRows ); populateColumnsFromTableData( columns, tableDataRows, false ); } - splitAndMergeColumnHeaders( columns, nbHeaderRows, splitHeaders ); for( auto & column : columns ) { findAndSetLongestColumnString( column, column.maxStringSize, 0 ); } + computeTableWidth( columns ); buildTableSeparators( columns, sectionSeparatingLine, topSeparator ); } @@ -237,7 +255,7 @@ void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout: if( column.subColumn.empty()) { column.columnValues = !isSubColumn ? - tColumnsValues[currentColumn++] : tableDataRows[currentColumn++]; + tColumnsValues[currentColumn++] : tableDataRows[currentColumn++]; } else { @@ -310,7 +328,7 @@ void TableTextFormatter::findAndSetLongestColumnString( TableLayout::Column & co } { // values case - if( column.subColumn.empty() ) + if( column.subColumn.empty() && !column.columnValues.empty()) { auto const maxStringSizeCell = *std::max_element( column.columnValues.begin(), column.columnValues.end(), @@ -365,8 +383,34 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & } ); } - string::size_type maxTopLineLength = tableTitle.length(); + string::size_type maxTopLineLength = tableTitle.length() + m_tableLayout.getBorderMargin() * 2; maxTopLineLength = std::max( {maxTopLineLength, sectionlineLength} ); + + if( sectionlineLength < maxTopLineLength ) + { + integer const extraCharacters = maxTopLineLength - sectionlineLength; + increaseColumnsSize( columns, extraCharacters ); + } +} + +void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > & columns, + integer const extraCharacters ) const +{ + integer const extraCharactersPerColumn = std::ceil( extraCharacters / columns.size() ); + for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) + { + if( !columns[idxColumn].subColumn.empty()) + { + distributeSpaces( columns[idxColumn].maxStringSize, extraCharacters ); + increaseColumnsSize( columns[idxColumn].subColumn, extraCharacters ); + } + else + { + std::string & cell = columns[idxColumn].maxStringSize[0]; + integer newMaxStringSize = extraCharactersPerColumn + cell.size(); + cell = GEOS_FMT( "{:>{}}", cell, newMaxStringSize ); + } + } } @@ -467,7 +511,7 @@ void TableTextFormatter::outputTitleRow( std::ostringstream & tableOutput, { tableOutput << GEOS_FMT( "{}\n", topSeparator ); tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, m_tableLayout.getBorderMargin()); - tableOutput << buildCell( TableLayout::Alignment::left, tableTitle, (topSeparator.length() - 6)); + tableOutput << buildCell( TableLayout::Alignment::center, tableTitle, (topSeparator.length() - 6)); tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, m_tableLayout.getBorderMargin() ); } } diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index f3fcb7b3ccb..372120539c1 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -155,9 +155,13 @@ class TableTextFormatter : public TableFormatter static constexpr char m_horizontalLine = '-'; /** - * @brief - * @param columns - * @param nbHeaderRows + * @brief Prepare all the columns with the appropriate values and formatting separator + * @param columns The vector containg all columns. Each column contains its own + * parameters (such as name, alignment, etc.) and column values. + * @param tableData Vector containing all rows filled with values + * @param nbHeaderRows A variable to be calculated which will contain the number of header lines to be displayed + * @param sectionSeparatingLine The row table separator + * @param topSeparator The top table separator */ void prepareAndBuildTable( std::vector< TableLayout::Column > & columns, TableData const & tableData, @@ -165,11 +169,13 @@ class TableTextFormatter : public TableFormatter std::string & sectionSeparatingLine, std::string & topSeparator ) const; /** - * @brief - * - * @param tableOutput - * @param columns - * @param nbHeaderRows + * @brief Displays the complete table + * @param tableOutput The output stream + * @param columns The vector containg all columns + * @param tableData Vector containing all rows filled with values + * @param nbHeaderRows A variable to be calculated which will contain the number of header lines to be displayed + * @param sectionSeparatingLine The row table separator + * @param topSeparator The top table separator */ void outputTable( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, @@ -179,9 +185,12 @@ class TableTextFormatter : public TableFormatter std::string const & topSeparator ) const; /** - * @brief Fill the vector (m_column) in tableData with values from rows stored in tableData. - * @param columns Vector of columns to be filled. + * @brief Populate all the column values with values extracted the table data. + * @param columns The vector containg all columns * @param tableData Vector containing all rows filled with values + * @param isSubColumn A boolean indicating whether the current column is a subcolumn. + * + * @note Use transposition for populating column with no subColumn */ void populateColumnsFromTableData( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & tableData, @@ -191,18 +200,21 @@ class TableTextFormatter : public TableFormatter * @brief Split all header names by detecting the newline \\n character. and * set the same vector size for each split header and merge it into columns * @param columns The vector containg all columns - * @param largestHeaderVectorSize The largest split header vector size + * @param nbHeaderRows Variable which will contain the number of header lines to be displayed * @param splitHeaders A empty vector who will contain all split header names */ void splitAndMergeColumnHeaders( std::vector< TableLayout::Column > & columns, - size_t & largestHeaderVectorSize, + size_t & nbHeaderRows, std::vector< std::vector< string > > & splitHeaders ) const; /** * @brief For each column find and set the column's longest string - * @param maxStringSize The largest string(s) in the column - * @param columns The vector containg all columns + * @param column The current column to be processed + * @param maxStringSize Store the longest string(s) for each column. * @param idxColumn The current index of the column + * + * @note Compares the longest string from the header with the longest string from the column values. + * If the column contains subcolumns, it recursively applies the same logic to them */ void findAndSetLongestColumnString( TableLayout::Column & column, std::vector< std::string > & maxStringSize, @@ -216,34 +228,29 @@ class TableTextFormatter : public TableFormatter void computeTableWidth( std::vector< TableLayout::Column > & columns ) const; /** - * @brief Build all separators needed from content length contained in the columns vector + * @brief Increase each column size if the title is larger than all the columns * @param columns Vector containing all table columns + * @param extraCharacters ExtraCharacters to be distributed between each columns */ - void buildTableSeparators( std::vector< TableLayout::Column > const & columns, - std::string & sectionSeparatingLine, - std::string & topSeparator ) const; + void increaseColumnsSize( std::vector< TableLayout::Column > & columns, + integer const extraCharacters ) const; /** - * @brief Add a row on top of the table - * @param tableOutput The output stream - * @param msg Vector of string(s) to display + * @brief Build all separators needed from content length contained in the columns vector + * @param columns Vector containing all table columns + * @param sectionSeparatingLine The row table separator * @param topSeparator The top table separator - * @param alignment The aligment for a row */ - void outputTopRows( std::ostringstream & tableOutput, - std::vector< string > const & msg, - string_view topSeparator, - TableLayout::Alignment alignment, - string_view sectionSeparatingLine ) const; + void buildTableSeparators( std::vector< TableLayout::Column > const & columns, + std::string & sectionSeparatingLine, + std::string & topSeparator ) const; /** - * @brief Output a section by specifying it's type ( header or section ) + * @brief Output the values rows in the table * @param columns Vector containing all table columns - * @param sectionSeparatingLine Line separator between sections - * @param rows A section row - * @param nbRows Indicates the number of lines in a section - * @param section The section to be built - * @note Add the ending line if there are one or more rows + * @param tableOutput The output stream + * @param nbRows The total number of rows to output. + * @param sectionSeparatingLine The row table separator */ void outputValuesSectionRows( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, @@ -251,19 +258,18 @@ class TableTextFormatter : public TableFormatter std::string const & sectionSeparatingLine ) const; /** - * @brief Construct a new output Title Row object - * @param topSeparator + * @brief utput the title row in the table + * @param topSeparator The top separator string */ void outputTitleRow( std::ostringstream & tableOutput, std::string const & topSeparator ) const; /** - * @brief - * - * @param columns - * @param tableOutput - * @param nbRows - * @param sectionSeparatingLine + * @brief Output the header rows in the table + * @param columns Vector containing all table columns + * @param tableOutput The output stream + * @param nbRows The total number of rows to output. + * @param sectionSeparatingLine The row table separator */ void outputHeaderSectionRows( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, @@ -271,14 +277,14 @@ class TableTextFormatter : public TableFormatter std::string const & sectionSeparatingLine ) const; /** - * @brief - * - * @param columns - * @param tableOutput + * @brief Output the sub column row + * @param columns Vector containing the subcolumn values + * @param tableOutput The output stream + * @param The current row in the table */ void outputSubSection( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, - integer idxCell ) const; + integer idxRow ) const; }; /** diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 5e990dfc4bb..9e994be1355 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -67,7 +67,7 @@ TableLayout::TableLayout( std::vector< ColumnParam > const & columnParams, strin void TableLayout::setMargin( MarginValue marginValue ) { - m_borderMargin = marginValue + 1 ; + m_borderMargin = marginValue + 1; m_columnMargin = integer( marginValue ) * 2 + 1; } diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index 7167d4aa6b5..bcd32958104 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -133,14 +133,14 @@ TEST( testTable, tableHiddenColumn ) TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), - "\n----------------------------------------------------------------------------------------------------------------\n" - "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "----------------------------------------------------------------------------------------------------------------\n" - "| Cras egestas | CoordX | C | CoordZ |\n" - "----------------------------------------------------------------------------------------------------------------\n" - "| value1 | | 3.0 | 3.0129877 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 |\n" - "----------------------------------------------------------------------------------------------------------------\n\n" ); + "\n---------------------------------------------------------------------------------------------------------------\n" + "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "---------------------------------------------------------------------------------------------------------------\n" + "| Cras egestas | CoordX | C | CoordZ |\n" + "---------------------------------------------------------------------------------------------------------------\n" + "| value1 | | 3.0 | 3.0129877 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 |\n" + "---------------------------------------------------------------------------------------------------------------\n\n" ); } TEST( testTable, tableUniqueColumn ) @@ -155,14 +155,14 @@ TEST( testTable, tableUniqueColumn ) TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), - "\n---------------------------------------------------------------------------------------------------------------\n" - "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "---------------------------------------------------------------------------------------------------------------\n" - "| Cras egestas |\n" - "---------------------------------------------------------------------------------------------------------------\n" - "| value1 |\n" - "| val1 |\n" - "---------------------------------------------------------------------------------------------------------------\n\n" ); + "\n--------------------------------------------------------------------------------------------------------------\n" + "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "--------------------------------------------------------------------------------------------------------------\n" + "| Cras egestas |\n" + "--------------------------------------------------------------------------------------------------------------\n" + "| value1 |\n" + "| val1 |\n" + "--------------------------------------------------------------------------------------------------------------\n\n" ); } TEST( testTable, tableEmptyTitle ) @@ -230,47 +230,6 @@ TEST( testTable, table2DTable ) ); } - -TEST( testTable, table2DColumnMismatch ) -{ - //test 2D table column mismatch - { - // collect - TableData2D tableData; - - tableData.addCell( 300, 10000, 0.03 ); - tableData.addCell( 300, 15000, 0.02 ); - tableData.addCell( 350, 10000, 0.035 ); - tableData.addCell( 350, 10000, 0.035 ); - tableData.addCell( 400, 10000, 0.04 ); - tableData.addCell( 400, 15000, 0.02666666666666667 ); - - //convert - string const rowFmt = GEOS_FMT( "{} = {{}}", "Temperature" ); - string const columnFmt = GEOS_FMT( "{} = {{}}", "Pression" ); - TableData2D::TableDataHolder tableConverted = tableData.buildTableData( "Viscosity kg*s", - rowFmt, - columnFmt ); - - //format - TableLayout const tableLayout( tableConverted.headerNames ); - - //log - TableTextFormatter const tableLog( tableLayout ); - EXPECT_EQ( tableLog.toString( tableConverted.tableData ), - "\n--------------------------------------------------------------------\n" - "| Remarks : some cells may be missing |\n" - "--------------------------------------------------------------------\n" - "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" - "--------------------------------------------------------------------\n" - "| Temperature = 300 | 0.03 | 0.02 |\n" - "| Temperature = 350 | 0.035 | |\n" - "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" - "--------------------------------------------------------------------\n\n" - ); - } -} - TEST( testTable, layoutTable ) { string filename = "fluid1_phaseModel1_PhillipsBrineDensity_table"; From 6fc69e376e59cf219c3dde28736b44416d9928f8 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 18 Sep 2024 15:40:12 +0200 Subject: [PATCH 163/216] update test --- .../format/table/unitTests/testTable.cpp | 142 +++++++++--------- 1 file changed, 70 insertions(+), 72 deletions(-) diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index bcd32958104..12acef5e4f2 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -27,13 +27,13 @@ using namespace geos; TEST( testTable, tableEmptyRow ) { //table with empty row - TableLayout const tableLayout( {"Well\nelement no.\nPV weighted\nbar", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement"}, - "InternalWellGenerator well_injector1" - ); + TableLayout tableLayout( "Well\nelement no.\nPV weighted\nbar", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement" ); + string const title = "InternalWellGenerator well_injector1"; + tableLayout.setTitle( title ); TableData tableData; tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); @@ -61,11 +61,13 @@ TEST( testTable, tableEmptyRow ) TEST( testTable, tableClassic ) { - TableLayout const tableLayout( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement"}, "InternalWellGenerator well_injector1" ); + TableLayout tableLayout( "Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement" ); + string const title = "InternalWellGenerator well_injector1"; + tableLayout.setTitle( title ); TableData tableData; tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); @@ -89,14 +91,14 @@ TEST( testTable, tableClassic ) TEST( testTable, tableColumnParamClassic ) { - TableLayout const tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::right} - }, "InternalWellGenerator well_injector1" ); + TableLayout tableLayout( TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::right}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::right} ); + string const title = "InternalWellGenerator well_injector1"; + tableLayout.setTitle( title ); TableData tableData; tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); @@ -118,14 +120,14 @@ TEST( testTable, tableColumnParamClassic ) TEST( testTable, tableHiddenColumn ) { - TableLayout const tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left, false}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center, false}, - }, "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + TableLayout tableLayout( TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left, false}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center, false} ); + string const title = "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis"; + tableLayout.setTitle( title ); TableData tableData; tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); @@ -145,9 +147,9 @@ TEST( testTable, tableHiddenColumn ) TEST( testTable, tableUniqueColumn ) { - TableLayout const tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - }, "Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis" ); + TableLayout tableLayout( TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center} ); + string const title = "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis"; + tableLayout.setTitle( title ); TableData tableData; tableData.addRow( "value1" ); @@ -167,15 +169,12 @@ TEST( testTable, tableUniqueColumn ) TEST( testTable, tableEmptyTitle ) { - TableLayout const tableLayout( { - TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center}, - } - ); + TableLayout tableLayout( TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, + TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, + TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, + TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center} ); TableData tableData; tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); @@ -215,7 +214,7 @@ TEST( testTable, table2DTable ) columnFmt ); //format - TableLayout const tableLayout( tableconverted.headerNames ); + TableLayout tableLayout( tableconverted.headerNames ); //log TableTextFormatter const tableLog( tableLayout ); @@ -233,9 +232,9 @@ TEST( testTable, table2DTable ) TEST( testTable, layoutTable ) { string filename = "fluid1_phaseModel1_PhillipsBrineDensity_table"; - 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 ); + TableLayout tableLayoutInfos( {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}} ); + tableLayoutInfos.setTitle( filename ); TableTextFormatter const tableLog( tableLayoutInfos ); EXPECT_EQ( tableLog.layoutToString(), @@ -248,35 +247,34 @@ TEST( testTable, layoutTable ) ); } -// TEST( testTable, subColumns ) -// { -// { -// //format -// TableLayout const tableLayout( -// {TableLayout::ColumnParam{" ", TableLayout::Alignment::right}} -// {TableLayout::ColumnParam{"Column1", TableLayout::Alignment::right}}, -// {TableLayout::ColumnParam{"Nodes ", TableLayout::Alignment::right, {"Local, Ghost"}}}, -// {TableLayout::ColumnParam{"Column3", TableLayout::Alignment::right}} -// ); - -// TableData tableData; -// tableData.addRow( "min", "125", "375,000", 23,562, 2.0f); -// tableData.addRow( "max", "360", "390,150", 38,712, 10.0f ); - -// TableTextFormatter const tableLog( tableLayout ); -// EXPECT_EQ( tableLog.toString( tableData ), -// "\n--------------------------------------------------------------------\n" -// "| Remarks : some cells may be missing |\n" -// "--------------------------------------------------------------------\n" -// "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" -// "--------------------------------------------------------------------\n" -// "| Temperature = 300 | 0.03 | 0.02 |\n" -// "| Temperature = 350 | 0.035 | |\n" -// "| Temperature = 400 | 0.04 | 0.02666666666666667 |\n" -// "--------------------------------------------------------------------\n\n" -// ); -// } -// } +TEST( testTable, subColumns ) +{ + { + TableLayout tableLayout( " ", + "Column1", + TableLayout::ColumnParam{"Nodes ", TableLayout::Alignment::right, true, {"Locales", "Ghost", "Active"}}, + "Column3", + TableLayout::ColumnParam{"Column4 ", TableLayout::Alignment::right, true, {"Locales", "Ghost"}}, + "Column5" ); + + TableData tableData; + tableData.addRow( "min", "125", "375,0001", " YES", 2354654, 562, 43.0, 43.0, 562, 5 ); + tableData.addRow( "max", "360", "390,1", " YES", 383213213, 712, 48.0, 47.0, 72, 2 ); + + TableTextFormatter tableLog( tableLayout ); + + EXPECT_EQ( tableLog.toString( tableData ), + "\n--------------------------------------------------------------------------------------------------------\n" + "| | Column1 | Nodes | Column3 | Column4 | Column5 |\n" + "--------------------------------------------------------------------------------------------------------\n" + "| | | Locales | Ghost | Active | | Locales | Ghost | |\n" + "--------------------------------------------------------------------------------------------------------\n" + "| min | 125 | 375,0001 | YES | 2354654 | 562 | 43 | 43 | 562 |\n" + "| max | 360 | 390,1 | YES | 383213213 | 712 | 48 | 47 | 72 |\n" + "--------------------------------------------------------------------------------------------------------\n\n" + ); + } +} TEST( testTable, tableSetMargin ) { From c369b22300abca9af3dd0015add2aded0bf03e50 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 18 Sep 2024 15:42:10 +0200 Subject: [PATCH 164/216] update output pre existing --- .../common/initializeEnvironment.cpp | 4 +- .../functions/TableFunction.cpp | 9 +- src/coreComponents/mesh/DomainPartition.cpp | 115 ++++++++++-------- .../mesh/generators/WellGeneratorBase.cpp | 20 +-- .../physicsSolvers/LinearSolverParameters.cpp | 9 +- .../NonlinearSolverParameters.cpp | 9 +- .../fluidFlow/StencilDataCollection.cpp | 6 +- 7 files changed, 94 insertions(+), 78 deletions(-) diff --git a/src/coreComponents/common/initializeEnvironment.cpp b/src/coreComponents/common/initializeEnvironment.cpp index 03bf8bfcea0..f3d7e856d29 100644 --- a/src/coreComponents/common/initializeEnvironment.cpp +++ b/src/coreComponents/common/initializeEnvironment.cpp @@ -342,11 +342,11 @@ static void addUmpireHighWaterMarks() pushStatsIntoAdiak( allocatorName + " rank max", mark ); } - TableLayout const memoryStatLayout ( {"Umpire Memory Pool\n(reserved / % over total)", + TableLayout const memoryStatLayout ( "Umpire Memory Pool\n(reserved / % over total)", "Min over ranks", "Max over ranks", "Avg over ranks", - "Sum over ranks" } ); + "Sum over ranks" ); TableTextFormatter const memoryStatLog( memoryStatLayout ); GEOS_LOG_RANK_0( memoryStatLog.toString( tableData )); diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index f852e3da3d3..b14b3b62a25 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -317,7 +317,7 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl tableData.addRow( coords[idx], values[idx] ); } - TableLayout const tableLayout( std::vector{ + TableLayout const tableLayout( std::vector< std::string >{ string( units::getDescription( tableFunction.getDimUnit( 0 ))), string( units::getDescription( valueUnit )) }, filename ); @@ -339,7 +339,8 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl units::getDescription( tableFunction.getDimUnit( 0 ) ), units::getDescription( tableFunction.getDimUnit( 1 ) )); - TableLayout tableLayout( tableConverted.headerNames, filename ); + TableLayout tableLayout( tableConverted.headerNames ); + tableLayout.setTitle( filename ); TableTextFormatter const table2DLog( tableLayout ); logOutput = table2DLog.toString( tableConverted.tableData ); @@ -347,7 +348,9 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl else { 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 ); + TableLayout tableLayoutInfos( TableLayout::ColumnParam{{log}, TableLayout::Alignment::left} ); + tableLayoutInfos.setTitle( filename ); + TableTextFormatter const tableLog( tableLayoutInfos ); logOutput = tableLog.layoutToString(); } diff --git a/src/coreComponents/mesh/DomainPartition.cpp b/src/coreComponents/mesh/DomainPartition.cpp index 381e5d2f1bd..0465757128f 100644 --- a/src/coreComponents/mesh/DomainPartition.cpp +++ b/src/coreComponents/mesh/DomainPartition.cpp @@ -18,6 +18,9 @@ */ #include "DomainPartition.hpp" +#include "common/format/table/TableData.hpp" +#include "common/format/table/TableFormatter.hpp" +#include "common/format/table/TableLayout.hpp" #include "common/DataTypes.hpp" #include "common/TimingMacros.hpp" @@ -322,7 +325,6 @@ void DomainPartition::addNeighbors( const unsigned int idim, void DomainPartition::outputPartitionInformation() const { - auto numberOfEntities = []( ObjectManagerBase const & objectManager ) { return std::make_pair( objectManager.getNumberOfLocalIndices(), objectManager.getNumberOfGhosts() ); @@ -408,45 +410,33 @@ void DomainPartition::outputPartitionInformation() const real64 const maxElemRatio = maxRatios[3]; GEOS_LOG_RANK_0( " MeshBody: " + meshBody.getName() + " MeshLevel: " + meshLevel.getName() + "\n" ); - GEOS_LOG_RANK_0( " |------------------------------------------------------------------------------------------------------------------------------------------------|" ); - GEOS_LOG_RANK_0( " | | Nodes | Edges | Faces | Elems |" ); - GEOS_LOG_RANK_0( " |------------------------------------------------------------------------------------------------------------------------------------------------|" ); - GEOS_LOG_RANK_0( GEOS_FMT( " |min(local/total)| {:4.2f} | {:4.2f} | {:4.2f} | {:4.2f} | ", - minNodeRatio, - minEdgeRatio, - minFaceRatio, - minElemRatio ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " |max(local/total)| {:4.2f} | {:4.2f} | {:4.2f} | {:4.2f} | ", - maxNodeRatio, - maxEdgeRatio, - maxFaceRatio, - maxElemRatio ) ); - GEOS_LOG_RANK_0( " |------------------------------------------------------------------------------------------------------------------------------------------------|" ); - GEOS_LOG_RANK_0( " | Rank | local | ghost | local | ghost | local | ghost | local | ghost |" ); - GEOS_LOG_RANK_0( " |----------------|---------------|---------------|---------------|---------------|---------------|---------------|---------------|---------------|" ); - - - GEOS_LOG_RANK_0( GEOS_FMT( " | min | {:>13} | {:>13} | {:>13} | {:>13} | {:>13} | {:>13} | {:>13} | {:>13} |", - addCommaSeparators( minNumLocalNodes ), - addCommaSeparators( minNumGhostNodes ), - addCommaSeparators( minNumLocalEdges ), - addCommaSeparators( minNumGhostEdges ), - addCommaSeparators( minNumLocalFaces ), - addCommaSeparators( minNumGhostFaces ), - addCommaSeparators( minNumLocalElems ), - addCommaSeparators( minNumGhostElems ) ) ); - - GEOS_LOG_RANK_0( GEOS_FMT( " | max | {:>13} | {:>13} | {:>13} | {:>13} | {:>13} | {:>13} | {:>13} | {:>13} |", - addCommaSeparators( maxNumLocalNodes ), - addCommaSeparators( maxNumGhostNodes ), - addCommaSeparators( maxNumLocalEdges ), - addCommaSeparators( maxNumGhostEdges ), - addCommaSeparators( maxNumLocalFaces ), - addCommaSeparators( maxNumGhostFaces ), - addCommaSeparators( maxNumLocalElems ), - addCommaSeparators( maxNumGhostElems ) ) ); - - GEOS_LOG_RANK_0( " |------------------------------------------------------------------------------------------------------------------------------------------------|" ); + TableLayout tableLayout( "Rank", + TableLayout::ColumnParam{"Nodes ", TableLayout::Alignment::center, true, {"local", "ghost"}}, + TableLayout::ColumnParam{"Edges ", TableLayout::Alignment::center, true, {"local", "ghost"}}, + TableLayout::ColumnParam{"Faces ", TableLayout::Alignment::center, true, {"local", "ghost"}}, + TableLayout::ColumnParam{"Elems ", TableLayout::Alignment::center, true, {"local", "ghost"}} ); + tableLayout.setMargin( TableLayout::MarginValue::large ); + tableLayout.noWrapLine(); + + TableData tableData; + tableData.addRow( "min", + addCommaSeparators( minNumLocalNodes ), + addCommaSeparators( minNumGhostNodes ), + addCommaSeparators( minNumLocalEdges ), + addCommaSeparators( minNumGhostEdges ), + addCommaSeparators( minNumLocalFaces ), + addCommaSeparators( minNumGhostFaces ), + addCommaSeparators( minNumLocalElems ), + addCommaSeparators( minNumGhostElems )); + tableData.addRow( "max", + addCommaSeparators( maxNumLocalNodes ), + addCommaSeparators( maxNumGhostNodes ), + addCommaSeparators( maxNumLocalEdges ), + addCommaSeparators( maxNumGhostEdges ), + addCommaSeparators( maxNumLocalFaces ), + addCommaSeparators( maxNumGhostFaces ), + addCommaSeparators( maxNumLocalElems ), + addCommaSeparators( maxNumGhostElems )); // output in rank order int const thisRank = MpiWrapper::commRank(); @@ -454,21 +444,44 @@ void DomainPartition::outputPartitionInformation() const { if( rank == thisRank ) { - GEOS_LOG( GEOS_FMT( " | {:14} | {:>13} | {:>13} | {:>13} | {:>13} | {:>13} | {:>13} | {:>13} | {:>13} | ", - rank, - addCommaSeparators( numLocalNodes ), - addCommaSeparators( numGhostNodes ), - addCommaSeparators( numLocalEdges ), - addCommaSeparators( numGhostEdges ), - addCommaSeparators( numLocalFaces ), - addCommaSeparators( numGhostFaces ), - addCommaSeparators( numLocalElems ), - addCommaSeparators( numGhostElems ) ) ); + tableData.addRow( rank, + addCommaSeparators( numLocalNodes ), + addCommaSeparators( numGhostNodes ), + addCommaSeparators( numLocalEdges ), + addCommaSeparators( numGhostEdges ), + addCommaSeparators( numLocalFaces ), + addCommaSeparators( numGhostFaces ), + addCommaSeparators( numLocalElems ), + addCommaSeparators( numGhostElems )); } MpiWrapper::barrier(); } MpiWrapper::barrier(); - GEOS_LOG_RANK_0( " |------------------------------------------------------------------------------------------------------------------------------------------------|" ); + TableTextFormatter tableLog( tableLayout ); + GEOS_LOG_RANK_0( tableLog.toString( tableData )); + + TableLayout tableLayoutRatio( "Rank", + "Nodes ", + "Edges ", + "Faces ", + "Elems "); + tableLayout.setMargin( TableLayout::MarginValue::large ); + + TableData tableDataRatio; + tableDataRatio.addRow( "min(local/total)", + minNodeRatio, + minEdgeRatio, + minFaceRatio, + minElemRatio ); + tableDataRatio.addRow( "min(local/total)", + maxNodeRatio, + maxEdgeRatio, + maxFaceRatio, + maxElemRatio ); + + tableLayout.removeSubColumn(); + TableTextFormatter tableLogRatio( tableLayoutRatio ); + GEOS_LOG_RANK_0( tableLogRatio.toString( tableDataRatio )); } } ); } diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 2b96c0755d3..6d09f37ced1 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -551,14 +551,14 @@ void WellGeneratorBase::logInternalWell() const } string const wellTitle = GEOS_FMT( "Well '{}' Element Table", getName() ); - TableLayout const tableWellLayout = TableLayout( { - TableLayout::ColumnParam{"Element no.", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"CoordX", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"CoordY", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"CoordZ", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"Prev\nElement", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"Next\nElement", TableLayout::Alignment::right}, - }, wellTitle ); + TableLayout tableWellLayout = TableLayout( + TableLayout::ColumnParam{"Element no.", TableLayout::Alignment::right}, + TableLayout::ColumnParam{"CoordX", TableLayout::Alignment::right}, + TableLayout::ColumnParam{"CoordY", TableLayout::Alignment::right}, + TableLayout::ColumnParam{"CoordZ", TableLayout::Alignment::right}, + TableLayout::ColumnParam{"Prev\nElement", TableLayout::Alignment::right}, + TableLayout::ColumnParam{"Next\nElement", TableLayout::Alignment::right} ); + tableWellLayout.setTitle( wellTitle ); TableTextFormatter const tableFormatter( tableWellLayout ); GEOS_LOG_RANK_0( tableFormatter.toString( tableWellData )); @@ -572,8 +572,8 @@ void WellGeneratorBase::logPerforationTable() const tablePerfoData.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); } - TableLayout const tableLayoutPerfo ( {"Perforation no.", "Coordinates", "connected to"}, - GEOS_FMT( "Well '{}' Perforation Table", getName() ) ); + TableLayout const tableLayoutPerfo ( "Perforation no.", "Coordinates", "connected to" ); + tableLayoutPerfo.setTitle( GEOS_FMT( "Well '{}' Perforation Table", getName())); TableTextFormatter const tablePerfoLog( tableLayoutPerfo ); GEOS_LOG_RANK_0( tablePerfoLog.toString( tablePerfoData )); } diff --git a/src/coreComponents/physicsSolvers/LinearSolverParameters.cpp b/src/coreComponents/physicsSolvers/LinearSolverParameters.cpp index 153703c0eb0..2cdd319eee1 100644 --- a/src/coreComponents/physicsSolvers/LinearSolverParameters.cpp +++ b/src/coreComponents/physicsSolvers/LinearSolverParameters.cpp @@ -326,10 +326,11 @@ void LinearSolverParametersInput::print() tableData.addRow( "ILU(T) threshold factor", m_parameters.ifact.threshold ); } } - TableLayout const tableLayout = TableLayout( { - TableLayout::ColumnParam{"Parameter", TableLayout::Alignment::left}, - TableLayout::ColumnParam{"Value", TableLayout::Alignment::left}, - }, GEOS_FMT( "{}: linear solver", getParent().getName() ) ); + TableLayout tableLayout = TableLayout( + TableLayout::ColumnParam{"Parameter", TableLayout::Alignment::left}, + TableLayout::ColumnParam{"Value", TableLayout::Alignment::left} + ); + tableLayout.setTitle( GEOS_FMT( "{}: linear solver", getParent().getName() ) ); TableTextFormatter const tableFormatter( tableLayout ); GEOS_LOG_RANK_0( tableFormatter.toString( tableData )); } diff --git a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp index 8316485d56f..a1975893259 100644 --- a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp +++ b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp @@ -229,10 +229,11 @@ void NonlinearSolverParameters::print() const tableData.addRow( "Sequential convergence criterion", m_sequentialConvergenceCriterion ); tableData.addRow( "Subcycling", m_subcyclingOption ); } - TableLayout const tableLayout = TableLayout( { - TableLayout::ColumnParam{"Parameter", TableLayout::Alignment::left}, - TableLayout::ColumnParam{"Value", TableLayout::Alignment::left}, - }, GEOS_FMT( "{}: nonlinear solver", getParent().getName() ) ); + TableLayout tableLayout = TableLayout( + TableLayout::ColumnParam{"Parameter", TableLayout::Alignment::left}, + TableLayout::ColumnParam{"Value", TableLayout::Alignment::left} + ); + tableLayout.setTitle( GEOS_FMT( "{}: nonlinear solver", getParent().getName() )); TableTextFormatter const tableFormatter( tableLayout ); GEOS_LOG_RANK_0( tableFormatter.toString( tableData )); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/StencilDataCollection.cpp b/src/coreComponents/physicsSolvers/fluidFlow/StencilDataCollection.cpp index dcd795ec3ed..5d7ae1091a8 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/StencilDataCollection.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/StencilDataCollection.cpp @@ -236,10 +236,8 @@ string formatKernelDataExtract( arrayView1d< StencilDataCollection::KernelConnec kernelIterator->m_transmissibility[0], kernelIterator->m_transmissibility[1] ); } - TableLayout const tableLayout{ - { "regionId A/B", "subRegionId A/B", "elementId A/B", "transmissibilityAB", "transmissibilityBA" }, - GEOS_FMT( "Kernel data (real row count = {})", kernelData.size() ) - }; + TableLayout tableLayout = TableLayout( "regionId A/B", "subRegionId A/B", "elementId A/B", "transmissibilityAB", "transmissibilityBA" ); + tableLayout.setTitle( GEOS_FMT( "Kernel data (real row count = {})", kernelData.size() )); TableTextFormatter const tableFormatter{ tableLayout }; return tableFormatter.toString( tableData ); } From c1c3137b44a99064d2378b23e4966e4301386c11 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 18 Sep 2024 15:42:39 +0200 Subject: [PATCH 165/216] some refacto and adding functions --- .../common/format/table/TableFormatter.cpp | 17 ++- .../common/format/table/TableLayout.cpp | 59 ++++++---- .../common/format/table/TableLayout.hpp | 104 ++++++++++++++++-- 3 files changed, 145 insertions(+), 35 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index b2214df7654..b093ae769a7 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -170,7 +170,7 @@ string TableTextFormatter::layoutToString() const prepareAndBuildTable( columns, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); - tableOutput << '\n'; //TODO Fonction + tableOutput << '\n'; outputTitleRow( tableOutput, topSeparator ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); outputHeaderSectionRows( columns, tableOutput, nbHeaderRows, sectionSeparatingLine ); @@ -202,7 +202,6 @@ void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::Column { std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); std::vector< std::vector< string > > splitHeaders; - if( !tableData.getTableDataRows().empty()) { updateVisibleColumns( columns, tableDataRows ); @@ -244,6 +243,7 @@ void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout: bool isSubColumn ) const { size_t currentColumn = 0; + std::vector< std::vector< std::string > > tColumnsValues( tableDataRows[0].size(), std::vector< std::string >( tableDataRows.size())); if( !isSubColumn ) { @@ -493,8 +493,17 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu } } - // Append right border with line return - tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, borderMargin ); + + if( columns[columns.size() - 1].subColumn.empty()) + { + // Append right border + tableOutput << GEOS_FMT( "{:>{}}", m_verticalLine, borderMargin ); + } + + if( idxRow != nbRows - 1 || !m_tableLayout.isLineWrapped()) + { + tableOutput << "\n"; + } } if( nbRows != 0 ) diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 9e994be1355..64a41115ee7 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -21,49 +21,66 @@ namespace geos { -void addColumn( std::vector< TableLayout::ColumnParam > const & columnsParam, std::vector< TableLayout::Column > & columns ) +void addColumns( std::vector< TableLayout::ColumnParam > const & columnsParam, std::vector< TableLayout::Column > & columns ) { for( const auto & columnParam : columnsParam ) { - bool subColum = false; - std::vector< TableLayout::Column > subColumnsToAdd; - TableLayout::Column columnToAdd = {columnParam, {}, {}, {}}; - for( const auto & subColumnsName: columnParam.subColumns ) + if( !columnParam.subColumns.empty() ) { - subColum = true; - TableLayout::Column subColumn= {subColumnsName, {}, {}, {}}; - subColumnsToAdd.push_back( subColumn ); - columnToAdd = { columnParam, {}, {}, subColumnsToAdd }; - } - if( subColum ) - { - columns.push_back( columnToAdd ); + std::vector< TableLayout::Column > subColumns; + for( const auto & subColumnsName: columnParam.subColumns ) + { + subColumns.push_back( TableLayout::Column{subColumnsName} ); + } + columns.push_back( TableLayout::Column{columnParam, subColumns} ); } else { - columns.push_back( { columnParam, {}, {}, {}} ); + columns.push_back( TableLayout::Column{columnParam} ); } } } -TableLayout::TableLayout( std::vector< string > const & columnNames, string const & title ): - m_tableTitle( title ) +TableLayout::TableLayout( std::vector< string > const & columnNames ) { setMargin( MarginValue::medium ); + + std::vector< TableLayout::ColumnParam > columnParams; m_columns.reserve( columnNames.size() ); + columnParams.reserve( columnNames.size() ); + for( auto const & name : columnNames ) { - m_columns.push_back( {TableLayout::ColumnParam{{name}, Alignment::right, true}, {}, {}, {}} ); + columnParams.push_back( TableLayout::ColumnParam{{name}} ); } + + addColumns( columnParams, m_columns ); } -TableLayout::TableLayout( std::vector< ColumnParam > const & columnParams, string const & title ): - m_tableTitle( title ) +void TableLayout::setTitle( std::string const & title ) { - setMargin( MarginValue::medium ); - addColumn( columnParams, m_columns ); + m_tableTitle = title; +} + +void TableLayout::noWrapLine() +{ + m_wrapLine = false; } +bool TableLayout::isLineWrapped() const +{ + return m_wrapLine; +} +void TableLayout::removeSubColumn() +{ + for( auto & column : m_columns ) + { + if( !column.subColumn.empty() ) + { + column.subColumn.clear(); + } + } +} void TableLayout::setMargin( MarginValue marginValue ) { diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 1abf3ecfb94..1662e4ec19f 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -119,6 +119,24 @@ class TableLayout //sub divison of a column std::vector< Column > subColumn; + Column( ColumnParam columnParam ) + : parameter( columnParam ) + {} + + Column( ColumnParam columnParam, std::vector< Column > subColumnInit ) + : parameter( columnParam ), subColumn( subColumnInit ) + {} + + Column( ColumnParam columnParam, + std::vector< string > columnValuesInit, + std::vector< string > maxStringSizeInit, + std::vector< Column > subColumnInit ) + : parameter( columnParam ), + columnValues( columnValuesInit ), + maxStringSize( maxStringSizeInit ), + subColumn( subColumnInit ) + {} + }; TableLayout() = default; @@ -129,17 +147,23 @@ class TableLayout * @param title The table name * @param subColumns */ - TableLayout( std::vector< string > const & columnNames, - string const & title = "" ); + TableLayout( std::vector< string > const & columnNames ); - /** - * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels - * level - * @param columnParameters List of structures to set up each colum parameters. - * @param title The table name - * @param subColumns - */ - TableLayout( std::vector< ColumnParam > const & columnParameters, string const & title = "" ); + // /** + // * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels + // * level + // * @param columnParameters List of structures to set up each colum parameters. + // * @param title The table name + // * @param subColumns + // */ + // TableLayout( std::vector< ColumnParam > const & columnParameters, string const & title = "" ); + + template< typename ... Args > + TableLayout( Args &&... args ) + { + setMargin( MarginValue::medium ); + processArguments( std::forward< Args >( args )... ); + } /** * @return The columns vector @@ -152,6 +176,23 @@ class TableLayout */ string_view getTitle() const; + /** + * @param title The table title + */ + void setTitle( std::string const & title ); + + /** + * @brief + */ + void noWrapLine(); + + /** + * @brief + */ + bool isLineWrapped() const; + + void removeSubColumn(); + /** * @return The border margin, number of spaces at both left and right table sides plus vertical character */ @@ -175,8 +216,51 @@ class TableLayout private: + template< typename T, typename ... Ts > + void processArguments( T && arg, Ts &&... args ) + { + addToData( std::forward< T >( arg )); + if constexpr (sizeof...(args) > 0) + { + processArguments( std::forward< Ts >( args )... ); + } + } + + void addToData( const std::vector< std::string > & args ) + { + for( const auto & arg : args ) + { + addToData( std::string( arg )); + } + } + + void addToData( std::string && arg ) + { + m_columns.push_back( TableLayout::ColumnParam{{arg}} ); + } + + void addToData( ColumnParam && arg ) + { + if( !arg.subColumns.empty() ) + { + std::vector< TableLayout::Column > subColumns; + for( const auto & subColumnsName: arg.subColumns ) + { + subColumns.push_back( TableLayout::Column{subColumnsName} ); + } + m_columns.push_back( TableLayout::Column{arg, subColumns} ); + } + else + { + m_columns.push_back( TableLayout::Column{arg} ); + } + + } + std::vector< Column > m_columns; + bool m_wrapLine = false; + string m_tableTitle; integer m_borderMargin; integer m_columnMargin; From 6b33bcc9af69bcfe37e4c4219f4b977a8ee7172d Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 18 Sep 2024 16:18:45 +0200 Subject: [PATCH 166/216] small fix --- src/coreComponents/mesh/generators/WellGeneratorBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 6d09f37ced1..33ffcb49bb4 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -572,7 +572,7 @@ void WellGeneratorBase::logPerforationTable() const tablePerfoData.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); } - TableLayout const tableLayoutPerfo ( "Perforation no.", "Coordinates", "connected to" ); + TableLayout tableLayoutPerfo ( "Perforation no.", "Coordinates", "connected to" ); tableLayoutPerfo.setTitle( GEOS_FMT( "Well '{}' Perforation Table", getName())); TableTextFormatter const tablePerfoLog( tableLayoutPerfo ); GEOS_LOG_RANK_0( tablePerfoLog.toString( tablePerfoData )); From 70400ccb02189bbc9b4e3454caed44a7a5ef2c03 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 18 Sep 2024 16:19:14 +0200 Subject: [PATCH 167/216] missing doxygen --- .../common/format/table/TableLayout.cpp | 30 ++++++ .../common/format/table/TableLayout.hpp | 91 ++++++++++--------- 2 files changed, 80 insertions(+), 41 deletions(-) diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 64a41115ee7..0a62294b8b9 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -114,4 +114,34 @@ integer const & TableLayout::getMarginTitle() const return m_titleMargin; } +void TableLayout::addToColumns( const std::vector< std::string > & columnNames ) +{ + for( const auto & columnName : columnNames ) + { + addToColumns( std::string( columnName )); + } +} + +void TableLayout::addToColumns( std::string && columnName ) +{ + m_columns.push_back( TableLayout::ColumnParam{ {columnName} } ); +} + +void TableLayout::addToColumns( ColumnParam && columnParam ) +{ + if( !columnParam.subColumns.empty()) + { + std::vector< TableLayout::Column > subColumns; + for( const auto & subColumnsName : columnParam.subColumns ) + { + subColumns.push_back( TableLayout::Column{ subColumnsName } ); + } + m_columns.push_back( TableLayout::Column{ columnParam, subColumns } ); + } + else + { + m_columns.push_back( TableLayout::Column{ columnParam } ); + } +} + } diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 1662e4ec19f..ada36df7018 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -119,14 +119,30 @@ class TableLayout //sub divison of a column std::vector< Column > subColumn; + /** + * @brief Constructs a Column with the given parameter. + * @param columnParam The parameters for the column. + */ Column( ColumnParam columnParam ) : parameter( columnParam ) {} + /** + * @brief Constructs a Column with the given parameters. + * @param columnParam The parameters for the column. + * @param subColumnInit The values in the column. + */ Column( ColumnParam columnParam, std::vector< Column > subColumnInit ) : parameter( columnParam ), subColumn( subColumnInit ) {} + /** + * @brief Constructs a Column with the given parameters. + * @param columnParam The parameters for the column. + * @param columnValuesInit The values in the column. + * @param maxStringSizeInit The largest string(s) in the column. + * @param subColumnInit The sub-columns of the column. + */ Column( ColumnParam columnParam, std::vector< string > columnValuesInit, std::vector< string > maxStringSizeInit, @@ -149,19 +165,15 @@ class TableLayout */ TableLayout( std::vector< string > const & columnNames ); - // /** - // * @brief Construct a new Table object by specifying value alignment and optionally their displays based to log levels - // * level - // * @param columnParameters List of structures to set up each colum parameters. - // * @param title The table name - // * @param subColumns - // */ - // TableLayout( std::vector< ColumnParam > const & columnParameters, string const & title = "" ); - + /** + * @brief Construct a new Table Layout object + * @tparam Args Process only string, vector < string > and ColumnParam type + * @param args Variadics to be processed + */ template< typename ... Args > TableLayout( Args &&... args ) { - setMargin( MarginValue::medium ); + setMargin( MarginValue::large ); processArguments( std::forward< Args >( args )... ); } @@ -182,15 +194,18 @@ class TableLayout void setTitle( std::string const & title ); /** - * @brief + * @brief */ void noWrapLine(); /** - * @brief + * @brief Remove the line return at the end of the table */ bool isLineWrapped() const; + /** + * @brief Remove all subcolumn in all columns + */ void removeSubColumn(); /** @@ -216,46 +231,40 @@ class TableLayout private: + /** + * @brief Recursively processes a variable number of arguments and adds them to the table data. + * @tparam T The first argument + * @tparam Ts The remaining arguments + * @param arg The first argument to be processed + * @param args The remaining arguments to be processed + */ template< typename T, typename ... Ts > void processArguments( T && arg, Ts &&... args ) { - addToData( std::forward< T >( arg )); + addToColumns( std::forward< T >( arg )); if constexpr (sizeof...(args) > 0) { processArguments( std::forward< Ts >( args )... ); } } - void addToData( const std::vector< std::string > & args ) - { - for( const auto & arg : args ) - { - addToData( std::string( arg )); - } - } - - void addToData( std::string && arg ) - { - m_columns.push_back( TableLayout::ColumnParam{{arg}} ); - } + /** + * @brief Create and add columns to the columns vector + * @param columnNames The columns name + */ + void addToColumns( const std::vector< std::string > & columnNames ); - void addToData( ColumnParam && arg ) - { - if( !arg.subColumns.empty() ) - { - std::vector< TableLayout::Column > subColumns; - for( const auto & subColumnsName: arg.subColumns ) - { - subColumns.push_back( TableLayout::Column{subColumnsName} ); - } - m_columns.push_back( TableLayout::Column{arg, subColumns} ); - } - else - { - m_columns.push_back( TableLayout::Column{arg} ); - } +/** + * @brief Create and add a column to the columns vector + * @param columnName The column name + */ + void addToColumns( std::string && columnName ); - } +/** + * @brief Create and add a column to the columns vector given a ColumnParam + * @param columnParam The columnParam + */ + void addToColumns( ColumnParam && columnParam ); std::vector< Column > m_columns; From 4f8002b1e4475cc4ef762d6bf3c1e459e5579ef4 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 18 Sep 2024 16:48:17 +0200 Subject: [PATCH 168/216] small tweaks --- .../common/format/table/TableFormatter.cpp | 6 +++-- .../common/format/table/TableLayout.cpp | 23 +++++++++++------- .../common/format/table/TableLayout.hpp | 24 ++++++++++--------- src/coreComponents/mesh/DomainPartition.cpp | 2 +- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index b093ae769a7..a1e6b37377a 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -500,7 +500,7 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu tableOutput << GEOS_FMT( "{:>{}}", m_verticalLine, borderMargin ); } - if( idxRow != nbRows - 1 || !m_tableLayout.isLineWrapped()) + if( idxRow != nbRows - 1 || !m_tableLayout.isLineWrapEnabled()) { tableOutput << "\n"; } @@ -520,7 +520,9 @@ void TableTextFormatter::outputTitleRow( std::ostringstream & tableOutput, { tableOutput << GEOS_FMT( "{}\n", topSeparator ); tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, m_tableLayout.getBorderMargin()); - tableOutput << buildCell( TableLayout::Alignment::center, tableTitle, (topSeparator.length() - 6)); + tableOutput << buildCell( TableLayout::Alignment::center, + tableTitle, + (topSeparator.length() - (m_tableLayout.getBorderMargin() * 2))); tableOutput << GEOS_FMT( "{:>{}}\n", m_verticalLine, m_tableLayout.getBorderMargin() ); } } diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 0a62294b8b9..d9355ac1ace 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -57,20 +57,31 @@ TableLayout::TableLayout( std::vector< string > const & columnNames ) addColumns( columnParams, m_columns ); } -void TableLayout::setTitle( std::string const & title ) +TableLayout & TableLayout::setTitle( std::string const & title ) { m_tableTitle = title; + return *this; } -void TableLayout::noWrapLine() +TableLayout & TableLayout::disableLineWrap() { m_wrapLine = false; + return *this; } -bool TableLayout::isLineWrapped() const +TableLayout & TableLayout::setMargin( MarginValue marginValue ) +{ + m_borderMargin = marginValue + 1; + m_columnMargin = integer( marginValue ) * 2 + 1; + + return *this; +} + +bool TableLayout::isLineWrapEnabled() const { return m_wrapLine; } + void TableLayout::removeSubColumn() { for( auto & column : m_columns ) @@ -82,12 +93,6 @@ void TableLayout::removeSubColumn() } } -void TableLayout::setMargin( MarginValue marginValue ) -{ - m_borderMargin = marginValue + 1; - m_columnMargin = integer( marginValue ) * 2 + 1; -} - std::vector< TableLayout::Column > const & TableLayout::getColumns() const { return m_columns; diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index ada36df7018..dee89ce6c06 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -104,7 +104,6 @@ class TableLayout {} }; - /** * @brief Struct for a column. */ @@ -190,18 +189,27 @@ class TableLayout /** * @param title The table title + * @return The tableLayout reference + */ + TableLayout & setTitle( std::string const & title ); + + /** + * @brief Remove the last return line a the end of the table + * @return The tableLayout reference */ - void setTitle( std::string const & title ); + TableLayout & disableLineWrap(); /** - * @brief + * @brief Set the minimal margin width between cell content and borders. + * @param marginValue The margin value + * @return The tableLayout reference */ - void noWrapLine(); + TableLayout & setMargin( MarginValue marginValue ); /** * @brief Remove the line return at the end of the table */ - bool isLineWrapped() const; + bool isLineWrapEnabled() const; /** * @brief Remove all subcolumn in all columns @@ -223,12 +231,6 @@ class TableLayout */ integer const & getMarginTitle() const; - /** - * @brief Set the minimal margin width between cell content and borders. - * @param marginValue The margin value - */ - void setMargin( MarginValue marginValue ); - private: /** diff --git a/src/coreComponents/mesh/DomainPartition.cpp b/src/coreComponents/mesh/DomainPartition.cpp index 0465757128f..88fc3c37f67 100644 --- a/src/coreComponents/mesh/DomainPartition.cpp +++ b/src/coreComponents/mesh/DomainPartition.cpp @@ -416,7 +416,7 @@ void DomainPartition::outputPartitionInformation() const TableLayout::ColumnParam{"Faces ", TableLayout::Alignment::center, true, {"local", "ghost"}}, TableLayout::ColumnParam{"Elems ", TableLayout::Alignment::center, true, {"local", "ghost"}} ); tableLayout.setMargin( TableLayout::MarginValue::large ); - tableLayout.noWrapLine(); + tableLayout.disableLineWrap(); TableData tableData; tableData.addRow( "min", From f870e6754bfe1dde4284668fc281cbc84c1a3fc0 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 19 Sep 2024 11:35:25 +0200 Subject: [PATCH 169/216] const variable --- src/coreComponents/common/format/table/TableFormatter.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index e8a94451bea..4a5d619b0a8 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -227,7 +227,7 @@ void TableTextFormatter::outputTable( std::ostringstream & tableOutput, { integer const nbValuesRows = tableData.getTableDataRows().size(); - tableOutput << '\n'; //TODO Fonction + tableOutput << '\n'; outputTitleRow( tableOutput, topSeparator ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); @@ -481,8 +481,8 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu } else { - string cell = column.columnValues.at( idxRow ); - std::string cellSize = stringutilities::join( column.maxStringSize, spaces ); + string const cell = column.columnValues.at( idxRow ); + std::string const cellSize = stringutilities::join( column.maxStringSize, spaces ); tableOutput << buildCell( column.parameter.alignment, cell, cellSize.length()); // Add space between column From 41fb6d57552a76f4a8db215ee8b68ca47f9698ec Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 19 Sep 2024 11:35:46 +0200 Subject: [PATCH 170/216] small refactor --- .../common/format/table/TableLayout.cpp | 81 ++++++------------- .../common/format/table/TableLayout.hpp | 26 +++--- 2 files changed, 40 insertions(+), 67 deletions(-) diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 2f0cc2bb6dc..c1ae7e5c016 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -21,40 +21,42 @@ namespace geos { -void addColumns( std::vector< TableLayout::ColumnParam > const & columnsParam, std::vector< TableLayout::Column > & columns ) +void TableLayout::addColumns( std::vector< TableLayout::ColumnParam > & columnsParam ) { - for( const auto & columnParam : columnsParam ) + for( auto && columnParam : columnsParam ) { - if( !columnParam.subColumns.empty() ) - { - std::vector< TableLayout::Column > subColumns; - for( const auto & subColumnsName: columnParam.subColumns ) - { - subColumns.push_back( TableLayout::Column{subColumnsName} ); - } - columns.push_back( TableLayout::Column{columnParam, subColumns} ); - } - else - { - columns.push_back( TableLayout::Column{columnParam} ); - } + addToColumns( std::move( columnParam ) ); } } -TableLayout::TableLayout( std::vector< string > const & columnNames ) +void TableLayout::addToColumns( const std::vector< std::string > & columnNames ) { - setMargin( MarginValue::medium ); + for( const auto & columnName : columnNames ) + { + addToColumns( std::string( columnName ) ); + } +} - std::vector< TableLayout::ColumnParam > columnParams; - m_columns.reserve( columnNames.size() ); - columnParams.reserve( columnNames.size() ); +void TableLayout::addToColumns( std::string && columnName ) +{ + m_columns.push_back( TableLayout::ColumnParam{ {columnName} } ); +} - for( auto const & name : columnNames ) +void TableLayout::addToColumns( ColumnParam && columnParam ) +{ + if( !columnParam.subColumns.empty()) + { + std::vector< TableLayout::Column > subColumns; + for( const auto & subColumnsName : columnParam.subColumns ) + { + subColumns.push_back( TableLayout::Column{ subColumnsName } ); + } + m_columns.push_back( TableLayout::Column{ columnParam, subColumns } ); + } + else { - columnParams.push_back( TableLayout::ColumnParam{{name}} ); + m_columns.push_back( TableLayout::Column{ columnParam } ); } - - addColumns( columnParams, m_columns ); } TableLayout & TableLayout::setTitle( std::string const & title ) @@ -103,7 +105,6 @@ string_view TableLayout::getTitle() const return m_tableTitle; } - integer const & TableLayout::getBorderMargin() const { return m_borderMargin; @@ -119,34 +120,4 @@ integer const & TableLayout::getMarginTitle() const return m_titleMargin; } -void TableLayout::addToColumns( const std::vector< std::string > & columnNames ) -{ - for( const auto & columnName : columnNames ) - { - addToColumns( std::string( columnName )); - } -} - -void TableLayout::addToColumns( std::string && columnName ) -{ - m_columns.push_back( TableLayout::ColumnParam{ {columnName} } ); -} - -void TableLayout::addToColumns( ColumnParam && columnParam ) -{ - if( !columnParam.subColumns.empty()) - { - std::vector< TableLayout::Column > subColumns; - for( const auto & subColumnsName : columnParam.subColumns ) - { - subColumns.push_back( TableLayout::Column{ subColumnsName } ); - } - m_columns.push_back( TableLayout::Column{ columnParam, subColumns } ); - } - else - { - m_columns.push_back( TableLayout::Column{ columnParam } ); - } -} - } diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 913b62ae2bb..0e43f4bf60b 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -156,14 +156,6 @@ class TableLayout TableLayout() = default; - /** - * @brief Construct a new Table object, all values in the table are centered by default - * @param columnNames The names of the columns - * @param title The table name - * @param subColumns - */ - TableLayout( std::vector< string > const & columnNames ); - /** * @brief Construct a new Table Layout object * @tparam Args Process only string, vector < string > and ColumnParam type @@ -202,12 +194,13 @@ class TableLayout /** * @brief Set the minimal margin width between cell content and borders. * @param marginValue The margin value - * @return The tableLayout reference + * @return The tableLayout reference */ TableLayout & setMargin( MarginValue marginValue ); /** - * @brief Remove the line return at the end of the table + * @brief Check whether we have a line return at the end of the table or not + * */ bool isLineWrapEnabled() const; @@ -233,6 +226,8 @@ class TableLayout private: + void addColumns( std::vector< TableLayout::ColumnParam > & columnsParam ); + /** * @brief Recursively processes a variable number of arguments and adds them to the table data. * @tparam T The first argument @@ -250,14 +245,21 @@ class TableLayout } } + // Fonction générique pour ajouter une ou plusieurs colonnes + template< typename T > + void addSingleColumn( T && column ) + { + m_columns.push_back( TableLayout::Column{std::forward< T >( column )} ); + } + /** - * @brief Create and add columns to the columns vector + * @brief Create and add columns to the columns vector given a string vector * @param columnNames The columns name */ void addToColumns( const std::vector< std::string > & columnNames ); /** - * @brief Create and add a column to the columns vector + * @brief Create and add a column to the columns vector given a string * @param columnName The column name */ void addToColumns( std::string && columnName ); From ed6c14bd0005728b4c3d1ecd6055789d4c24d46f Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 19 Sep 2024 11:44:47 +0200 Subject: [PATCH 171/216] doxygen improved --- .../common/format/table/TableFormatter.hpp | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 6ec652fdea1..67f14f73ac6 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -159,8 +159,8 @@ class TableTextFormatter : public TableFormatter * @param columns The vector containg all columns. Each column contains its own * parameters (such as name, alignment, etc.) and column values. * @param tableData Vector containing all rows filled with values - * @param nbHeaderRows A variable to be calculated which will contain the number of header lines to be displayed - * @param sectionSeparatingLine The row table separator + * @param nbHeaderRows Number of header rows, which will be calculated based on column headers and their formatting. + * @param sectionSeparatingLine Separator string used between sections of the table * @param topSeparator The top table separator */ void prepareAndBuildTable( std::vector< TableLayout::Column > & columns, @@ -174,7 +174,7 @@ class TableTextFormatter : public TableFormatter * @param columns The vector containg all columns * @param tableData Vector containing all rows filled with values * @param nbHeaderRows A variable to be calculated which will contain the number of header lines to be displayed - * @param sectionSeparatingLine The row table separator + * @param sectionSeparatingLine Separator string used between sections of the table * @param topSeparator The top table separator */ void outputTable( std::ostringstream & tableOutput, @@ -185,10 +185,10 @@ class TableTextFormatter : public TableFormatter std::string const & topSeparator ) const; /** - * @brief Populate all the column values with values extracted the table data. - * @param columns The vector containg all columns + * @brief Populate all the column values with values extracted from the table data. + * @param columns Vector of columns to populate. * @param tableData Vector containing all rows filled with values - * @param isSubColumn A boolean indicating whether the current column is a subcolumn. + * @param isSubColumn Boolean indicating if the current column is a subcolumn * * @note Use transposition for populating column with no subColumn */ @@ -201,7 +201,7 @@ class TableTextFormatter : public TableFormatter * set the same vector size for each split header and merge it into columns * @param columns The vector containg all columns * @param nbHeaderRows Variable which will contain the number of header lines to be displayed - * @param splitHeaders A empty vector who will contain all split header names + * @param splitHeaders Vector to store the split header names for each column */ void splitAndMergeColumnHeaders( std::vector< TableLayout::Column > & columns, size_t & nbHeaderRows, @@ -209,7 +209,7 @@ class TableTextFormatter : public TableFormatter /** * @brief For each column find and set the column's longest string - * @param column The current column to be processed + * @param column The column to process. * @param maxStringSize Store the longest string(s) for each column. * @param idxColumn The current index of the column * @@ -221,7 +221,7 @@ class TableTextFormatter : public TableFormatter integer const idxColumn ) const; /** - * @brief Compute the max table line length, taking into account the length of : title, error, columns header and content + * @brief Compute the max table line length, taking into account the length of : title, columns header and values * Increase the size of the columns if necessary * @param columns Vector of column containing containing the largest string for each column */ @@ -236,9 +236,9 @@ class TableTextFormatter : public TableFormatter integer const extraCharacters ) const; /** - * @brief Build all separators needed from content length contained in the columns vector + * @brief Builds the table's separating lines based on the content length of the columns. * @param columns Vector containing all table columns - * @param sectionSeparatingLine The row table separator + * @param sectionSeparatingLine Separator string used between sections of the table * @param topSeparator The top table separator */ void buildTableSeparators( std::vector< TableLayout::Column > const & columns, @@ -249,8 +249,8 @@ class TableTextFormatter : public TableFormatter * @brief Output the values rows in the table * @param columns Vector containing all table columns * @param tableOutput The output stream - * @param nbRows The total number of rows to output. - * @param sectionSeparatingLine The row table separator + * @param nbRows Total number of rows to output. + * @param sectionSeparatingLine Separator string used between sections of the table */ void outputValuesSectionRows( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, @@ -258,7 +258,7 @@ class TableTextFormatter : public TableFormatter std::string const & sectionSeparatingLine ) const; /** - * @brief utput the title row in the table + * @brief Output the title row in the table * @param topSeparator The top separator string */ void outputTitleRow( std::ostringstream & tableOutput, @@ -269,7 +269,7 @@ class TableTextFormatter : public TableFormatter * @param columns Vector containing all table columns * @param tableOutput The output stream * @param nbRows The total number of rows to output. - * @param sectionSeparatingLine The row table separator + * @param sectionSeparatingLine Separator string used between sections of the table */ void outputHeaderSectionRows( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, @@ -277,10 +277,10 @@ class TableTextFormatter : public TableFormatter std::string const & sectionSeparatingLine ) const; /** - * @brief Output the sub column row + * @brief Outputs subcolumns for the given row in the table. * @param columns Vector containing the subcolumn values * @param tableOutput The output stream - * @param The current row in the table + * @param idxRow Index of the current row in the table */ void outputSubSection( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, From eb17f4233aecd15407a41f56ecbe14c1c0a449e0 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 20 Sep 2024 13:32:45 +0200 Subject: [PATCH 172/216] fix margin if title largest --- .../common/format/table/TableFormatter.cpp | 25 ++++++++++--------- .../common/format/table/TableFormatter.hpp | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 4a5d619b0a8..e01bc0edb96 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -377,7 +377,7 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & { // Compute total length of all columns with margins sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, [&]( auto sum, auto & column ) -> auto - { + { // take into account subColumn std::string sumOfString = stringutilities::join( column.maxStringSize, spaces ); return static_cast< decltype(sum) >(sum + sumOfString.length()); } ); @@ -385,35 +385,36 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & string::size_type maxTopLineLength = tableTitle.length() + m_tableLayout.getBorderMargin() * 2; maxTopLineLength = std::max( {maxTopLineLength, sectionlineLength} ); - if( sectionlineLength < maxTopLineLength ) { - integer const extraCharacters = maxTopLineLength - sectionlineLength; + real64 const extraCharacters = maxTopLineLength - sectionlineLength; increaseColumnsSize( columns, extraCharacters ); } } void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > & columns, - integer const extraCharacters ) const + real64 const extraCharacters ) const { - integer const extraCharactersPerColumn = std::ceil( extraCharacters / columns.size() ); + real64 const extraCharactersPerColumn = std::floor( (extraCharacters) / columns.size() ); + integer rest = extraCharacters - (extraCharactersPerColumn * columns.size() ) ; for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { if( !columns[idxColumn].subColumn.empty()) { - distributeSpaces( columns[idxColumn].maxStringSize, extraCharacters ); - increaseColumnsSize( columns[idxColumn].subColumn, extraCharacters ); + distributeSpaces( columns[idxColumn].maxStringSize, (int)extraCharactersPerColumn ); + increaseColumnsSize( columns[idxColumn].subColumn, extraCharactersPerColumn ); } else { std::string & cell = columns[idxColumn].maxStringSize[0]; - integer newMaxStringSize = extraCharactersPerColumn + cell.size(); + integer newMaxStringSize = idxColumn == 0 ? + extraCharactersPerColumn + cell.size() + rest : + extraCharactersPerColumn + cell.size(); cell = GEOS_FMT( "{:>{}}", cell, newMaxStringSize ); } } } - void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column > const & columns, std::string & sectionSeparatingLine, std::string & topSeparator ) const @@ -430,8 +431,8 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column } std::string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", m_horizontalLine, columnMargin ); - std::string const leftBorder = GEOS_FMT( "{}{:-<{}}", m_horizontalLine, "", borderMargin - 1 ); - std::string const rightBorder = GEOS_FMT( "{}{:-<{}}", m_horizontalLine, "", borderMargin - 1 ); + std::string const leftBorder = GEOS_FMT( "{:-<{}}", m_horizontalLine, borderMargin ); + std::string const rightBorder = GEOS_FMT( "{:-<{}}", m_horizontalLine, borderMargin ); // Join all parts to form the section separating line std::string const columnJoin = stringutilities::join( maxStringsPerColumn, patternBetweenColumns ); @@ -439,7 +440,7 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column oss << leftBorder << columnJoin << rightBorder; sectionSeparatingLine = oss.str(); - integer const topSeparatorLength = sectionSeparatingLine.size() - 2; // Adjust for border characters + integer const topSeparatorLength = sectionSeparatingLine.size() -2; // Adjust for border characters topSeparator = GEOS_FMT( "{}{:-<{}}{}", m_horizontalLine, "", topSeparatorLength, m_horizontalLine ); } diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 67f14f73ac6..6d107082f99 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -233,7 +233,7 @@ class TableTextFormatter : public TableFormatter * @param extraCharacters ExtraCharacters to be distributed between each columns */ void increaseColumnsSize( std::vector< TableLayout::Column > & columns, - integer const extraCharacters ) const; + real64 const extraCharacters ) const; /** * @brief Builds the table's separating lines based on the content length of the columns. From 582e1683b49ac848ac5e6357c5b2a230291bf66b Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 20 Sep 2024 13:33:16 +0200 Subject: [PATCH 173/216] add init_list constructor --- .../common/format/table/TableLayout.cpp | 8 ++--- .../common/format/table/TableLayout.hpp | 34 +++++++++++++++++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index c1ae7e5c016..5e07ddf6415 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -39,7 +39,7 @@ void TableLayout::addToColumns( const std::vector< std::string > & columnNames ) void TableLayout::addToColumns( std::string && columnName ) { - m_columns.push_back( TableLayout::ColumnParam{ {columnName} } ); + m_columns.emplace_back( TableLayout::ColumnParam{ {columnName} } ); } void TableLayout::addToColumns( ColumnParam && columnParam ) @@ -49,13 +49,13 @@ void TableLayout::addToColumns( ColumnParam && columnParam ) std::vector< TableLayout::Column > subColumns; for( const auto & subColumnsName : columnParam.subColumns ) { - subColumns.push_back( TableLayout::Column{ subColumnsName } ); + subColumns.emplace_back( TableLayout::Column{ subColumnsName } ); } - m_columns.push_back( TableLayout::Column{ columnParam, subColumns } ); + m_columns.emplace_back( TableLayout::Column{ columnParam, subColumns } ); } else { - m_columns.push_back( TableLayout::Column{ columnParam } ); + m_columns.emplace_back( TableLayout::Column{ columnParam } ); } } diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 0e43f4bf60b..61f13f5222b 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -164,10 +164,18 @@ class TableLayout template< typename ... Args > TableLayout( Args &&... args ) { - setMargin( MarginValue::large ); + setMargin( MarginValue::medium ); processArguments( std::forward< Args >( args )... ); } + TableLayout( std::string const & title, + std::initializer_list< std::variant< std::string, TableLayout::ColumnParam > > args ) + { + setMargin( MarginValue::medium ); + setTitle( title ); + processArguments( args ); + } + /** * @return The columns vector */ @@ -199,7 +207,7 @@ class TableLayout TableLayout & setMargin( MarginValue marginValue ); /** - * @brief Check whether we have a line return at the end of the table or not + * @brief Check whether we have a line return at the end of the table or not * */ bool isLineWrapEnabled() const; @@ -228,6 +236,26 @@ class TableLayout void addColumns( std::vector< TableLayout::ColumnParam > & columnsParam ); + void processArguments( std::initializer_list< std::variant< std::string, TableLayout::ColumnParam > > args ) + { + for( const auto & arg : args ) + { + std::visit( [this]( auto && value ) { + // Si c'est un ColumnParam, on crée une copie locale et on la déplace + if constexpr (std::is_same_v< std::decay_t< decltype(value) >, TableLayout::ColumnParam >) + { + auto local_copy = value; + addToColumns( std::move( local_copy ) ); + } + else + { + addToColumns( std::forward< decltype(value) >( value ) ); + } + }, arg ); + + } + } + /** * @brief Recursively processes a variable number of arguments and adds them to the table data. * @tparam T The first argument @@ -256,7 +284,7 @@ class TableLayout * @brief Create and add columns to the columns vector given a string vector * @param columnNames The columns name */ - void addToColumns( const std::vector< std::string > & columnNames ); + void addToColumns( std::vector< std::string > const & columnNames ); /** * @brief Create and add a column to the columns vector given a string From 5cfe033153e9ce57b8f149ac70a033bd1d3c454a Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 23 Sep 2024 11:00:21 +0200 Subject: [PATCH 174/216] adding setMargin + small cleaning --- .../common/format/table/TableFormatter.cpp | 6 +- .../common/format/table/TableLayout.cpp | 39 +++++---- .../common/format/table/TableLayout.hpp | 79 +++++++++++-------- 3 files changed, 73 insertions(+), 51 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index e01bc0edb96..b9d035de189 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -137,7 +137,7 @@ void updateVisibleColumns( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > & tableDataRows ) { integer idxColumn = 0; - for( auto iterColumn = columns.begin(); iterColumn!=columns.end(); ) + for( auto iterColumn = columns.begin(); iterColumn != columns.end(); ) { if( !iterColumn->parameter.enabled ) { @@ -396,7 +396,7 @@ void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > real64 const extraCharacters ) const { real64 const extraCharactersPerColumn = std::floor( (extraCharacters) / columns.size() ); - integer rest = extraCharacters - (extraCharactersPerColumn * columns.size() ) ; + integer rest = extraCharacters - (extraCharactersPerColumn * columns.size() ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { if( !columns[idxColumn].subColumn.empty()) @@ -465,7 +465,7 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); - string const spaces = std::string( columnMargin, ' ' ); + string const spaces = std::string( columnMargin - 1, ' ' ); for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) { diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 5e07ddf6415..5630abd1a7a 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -21,14 +21,6 @@ namespace geos { -void TableLayout::addColumns( std::vector< TableLayout::ColumnParam > & columnsParam ) -{ - for( auto && columnParam : columnsParam ) - { - addToColumns( std::move( columnParam ) ); - } -} - void TableLayout::addToColumns( const std::vector< std::string > & columnNames ) { for( const auto & columnName : columnNames ) @@ -37,25 +29,25 @@ void TableLayout::addToColumns( const std::vector< std::string > & columnNames ) } } -void TableLayout::addToColumns( std::string && columnName ) +void TableLayout::addToColumns( std::string const & columnName ) { - m_columns.emplace_back( TableLayout::ColumnParam{ {columnName} } ); + m_columns.push_back( TableLayout::ColumnParam{ columnName } ); } -void TableLayout::addToColumns( ColumnParam && columnParam ) +void TableLayout::addToColumns( ColumnParam const & columnParam ) { if( !columnParam.subColumns.empty()) { std::vector< TableLayout::Column > subColumns; for( const auto & subColumnsName : columnParam.subColumns ) { - subColumns.emplace_back( TableLayout::Column{ subColumnsName } ); + subColumns.push_back( TableLayout::Column{ TableLayout::ColumnParam{subColumnsName, columnParam.alignment} } ); } - m_columns.emplace_back( TableLayout::Column{ columnParam, subColumns } ); + m_columns.push_back( TableLayout::Column{ columnParam, subColumns } ); } else { - m_columns.emplace_back( TableLayout::Column{ columnParam } ); + m_columns.push_back( TableLayout::Column{ columnParam } ); } } @@ -73,12 +65,19 @@ TableLayout & TableLayout::disableLineWrap() TableLayout & TableLayout::setMargin( MarginValue marginValue ) { - m_borderMargin = marginValue + 1; + m_marginValue = marginValue; + m_borderMargin = marginValue + 1; // margin + border character m_columnMargin = integer( marginValue ) * 2 + 1; return *this; } +TableLayout & TableLayout::setAlignment( TableLayout::Alignment alignment ) +{ + m_defaultAlignment = alignment; + return *this; +} + bool TableLayout::isLineWrapEnabled() const { return m_wrapLine; @@ -115,9 +114,19 @@ integer const & TableLayout::getColumnMargin() const return m_columnMargin; } +integer const & TableLayout::getMarginValue() const +{ + return m_marginValue; +} + integer const & TableLayout::getMarginTitle() const { return m_titleMargin; } +TableLayout::Alignment TableLayout::getDefaultAlignment() const +{ + return m_defaultAlignment; +} + } diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 61f13f5222b..f36a097f078 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -58,10 +58,10 @@ class TableLayout /// Name for a column string columnName; /// Alignment for a column. By default aligned to the right side - Alignment alignment = Alignment::right; + Alignment alignment; /// A boolean to display a colummn bool enabled = true; - /// + /// Vector containing sub columns name std::vector< string > subColumns; /// Vector containing substring column name delimited by "\n" std::vector< string > splitColumnNames = {""}; @@ -83,6 +83,15 @@ class TableLayout : columnName( name ), alignment( align ) {} + /** + * @brief Construct a ColumnParam object with the specified name and alignment. + * @param name The name of the column + * @param align The alignment of the column + */ + ColumnParam( std::string const & name, std::vector< string > subsColumns ) + : columnName( name ), subColumns( subsColumns ) + {} + /** * @brief Construct a ColumnParam object with the specified name, alignment, and display flag. * @param name The name of the column @@ -164,6 +173,7 @@ class TableLayout template< typename ... Args > TableLayout( Args &&... args ) { + setAlignment( Alignment::center ); setMargin( MarginValue::medium ); processArguments( std::forward< Args >( args )... ); } @@ -171,6 +181,7 @@ class TableLayout TableLayout( std::string const & title, std::initializer_list< std::variant< std::string, TableLayout::ColumnParam > > args ) { + setAlignment( Alignment::center ); setMargin( MarginValue::medium ); setTitle( title ); processArguments( args ); @@ -206,9 +217,15 @@ class TableLayout */ TableLayout & setMargin( MarginValue marginValue ); + /** + * @brief Set the default table alignment + * @param marginValue The table alignment + * @return The tableLayout reference + */ + TableLayout & setAlignment( Alignment alignment ); + /** * @brief Check whether we have a line return at the end of the table or not - * */ bool isLineWrapEnabled() const; @@ -223,36 +240,38 @@ class TableLayout integer const & getBorderMargin() const; /** - * @return The column margin, numbers of spaces separating both left and right side from each column content + * @return The column margin, numbers of spaces separating both left and right side from a vertical line */ integer const & getColumnMargin() const; + /** + * @return The table margin value + */ + integer const & getMarginValue() const; + /** * @return The margin title */ integer const & getMarginTitle() const; -private: + /** + * @brief Get the table default aligment + */ + TableLayout::Alignment getDefaultAlignment() const; - void addColumns( std::vector< TableLayout::ColumnParam > & columnsParam ); +private: + /** + * @brief Add a column to the table given an initializer_list of string & ColumnParam + * @param args An initializer_list containing either string or columnParam + */ void processArguments( std::initializer_list< std::variant< std::string, TableLayout::ColumnParam > > args ) { - for( const auto & arg : args ) + for( auto const & arg : args ) { - std::visit( [this]( auto && value ) { - // Si c'est un ColumnParam, on crée une copie locale et on la déplace - if constexpr (std::is_same_v< std::decay_t< decltype(value) >, TableLayout::ColumnParam >) - { - auto local_copy = value; - addToColumns( std::move( local_copy ) ); - } - else - { - addToColumns( std::forward< decltype(value) >( value ) ); - } + std::visit( [this]( auto const & value ) { + addToColumns( value ); }, arg ); - } } @@ -273,38 +292,32 @@ class TableLayout } } - // Fonction générique pour ajouter une ou plusieurs colonnes - template< typename T > - void addSingleColumn( T && column ) - { - m_columns.push_back( TableLayout::Column{std::forward< T >( column )} ); - } - /** * @brief Create and add columns to the columns vector given a string vector * @param columnNames The columns name */ void addToColumns( std::vector< std::string > const & columnNames ); -/** - * @brief Create and add a column to the columns vector given a string - * @param columnName The column name - */ - void addToColumns( std::string && columnName ); + /** + * @brief Create and add a column to the columns vector given a string + * @param columnName The column name + */ + void addToColumns( std::string const & columnName ); /** * @brief Create and add a column to the columns vector given a ColumnParam * @param columnParam The columnParam */ - void addToColumns( ColumnParam && columnParam ); + void addToColumns( ColumnParam const & columnParam ); std::vector< Column > m_columns; bool m_wrapLine = false; - + TableLayout::Alignment m_defaultAlignment = TableLayout::Alignment::right; string m_tableTitle; integer m_borderMargin; integer m_columnMargin; + integer m_marginValue; integer m_titleMargin = 2; }; From 674e2719bccb29352d5fd3577d2b2384ccf601d5 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 23 Sep 2024 11:34:34 +0200 Subject: [PATCH 175/216] fix unwanted empty space --- .../common/format/table/TableFormatter.cpp | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index b9d035de189..d649b6964ab 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -454,7 +454,10 @@ void TableTextFormatter::outputSubSection( std::vector< TableLayout::Column > co tableOutput << buildCell( columns[idxCol].parameter.alignment, columns[idxCol].columnValues[idxRow], columns[idxCol].maxStringSize[0].length() ); - tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); + if( idxCol < columns.size() - 1 ) + { + tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); + } } } @@ -485,21 +488,17 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu string const cell = column.columnValues.at( idxRow ); std::string const cellSize = stringutilities::join( column.maxStringSize, spaces ); tableOutput << buildCell( column.parameter.alignment, cell, cellSize.length()); - - // Add space between column - if( idxColumn < columns.size() - 1 ) - { - tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); - } + } + + if( idxColumn < columns.size() - 1 ) + { + tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } } - if( columns[columns.size() - 1].subColumn.empty()) - { - // Append right border - tableOutput << GEOS_FMT( "{:>{}}", m_verticalLine, borderMargin ); - } + // Append right border + tableOutput << GEOS_FMT( "{:>{}}", m_verticalLine, borderMargin ); if( idxRow != nbRows - 1 || !m_tableLayout.isLineWrapEnabled()) { From 380da9f6be0aef46a76302036d27ed80d8f024b5 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 23 Sep 2024 11:35:44 +0200 Subject: [PATCH 176/216] test working + log domainPartiton --- .../format/table/unitTests/testTable.cpp | 77 +++++++++---------- src/coreComponents/mesh/DomainPartition.cpp | 38 ++++----- 2 files changed, 52 insertions(+), 63 deletions(-) diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index e94270f066c..703fe668fee 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -157,14 +157,14 @@ TEST( testTable, tableUniqueColumn ) TableTextFormatter const tableText( tableLayout ); EXPECT_EQ( tableText.toString( tableData ), - "\n--------------------------------------------------------------------------------------------------------------\n" - "| Cras egestas ipsu a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" - "--------------------------------------------------------------------------------------------------------------\n" - "| Cras egestas |\n" - "--------------------------------------------------------------------------------------------------------------\n" - "| value1 |\n" - "| val1 |\n" - "--------------------------------------------------------------------------------------------------------------\n\n" ); + "\n---------------------------------------------------------------------------------------------------------------\n" + "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis |\n" + "---------------------------------------------------------------------------------------------------------------\n" + "| Cras egestas |\n" + "---------------------------------------------------------------------------------------------------------------\n" + "| value1 |\n" + "| val1 |\n" + "---------------------------------------------------------------------------------------------------------------\n\n" ); } TEST( testTable, tableEmptyTitle ) @@ -276,41 +276,34 @@ TEST( testTable, subColumns ) } } -TEST( testTable, tableSetMargin ) +TEST( testTable, variadicTest ) { - //////////// - //////// If setMargin used elsewhere make it public and remove comments for this test - //////////// - //test with tiny margin - // { - // TableLayout tableLayout( { - // TableLayout::ColumnParam{{"Colonne 1"}, TableLayout::Alignment::center}, - // TableLayout::ColumnParam{{"Colonne 2"}, TableLayout::Alignment::center}, - // TableLayout::ColumnParam{{"Colonne 3"}, TableLayout::Alignment::right}, - // TableLayout::ColumnParam{{"Colonne 4"}, TableLayout::Alignment::right}, - // TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::right}, - // TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::right}, - // }, "InternalWellGenerator well_injector1" ); - - // //tableLayout.setMargin( TableLayout::MarginValue::tiny ); - - // TableData tableData; - // tableData.addRow( "value 1", "long value 1", "3.0034", 3.0129877, "" , 1 ); - // tableData.addRow( "value 1", "long value 2", "100.45", 4.0129877, 1 , 2 ); - - // TableTextFormatter const tableText( tableLayout ); - // EXPECT_EQ( tableText.toString( tableData ), -// "\n------------------------------------------------------------\n" -// "| InternalWellGenerator well_injector1 |\n" -// "------------------------------------------------------------\n" -// "|Colonne 1| Colonne 2 |Colonne 3|Colonne 4| Prev| Next|\n" -// "| | | | |element|element|\n" -// "------------------------------------------------------------\n" -// "| value 1 |long value 1| 3.0034|3.0129877| | 1|\n" -// "| value 1 |long value 2| 100.45|4.0129877| 1| 2|\n" -// "------------------------------------------------------------\n\n" -// ); -// } + { + TableLayout const layoutTest( "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis nascetur ridiculus mus", + { "Rank", + TableLayout::ColumnParam{"Nodes", TableLayout::Alignment::center, true, {"local", "ghost"}}, + "Edge", + TableLayout::ColumnParam{"Faces", TableLayout::Alignment::center, true, {"local", "ghost"}}, + TableLayout::ColumnParam{"Elems", TableLayout::Alignment::center, true, {"local", "ghost"}} } ); + + TableData data; + data.addRow( "min(local/total)", 1, 2, 3, 4, 5, 6, 7 ); + data.addRow( "min(local/total)", 1, 2, 3, 4, 5, 6, 7 ); + TableTextFormatter log( layoutTest ); + std::cout << " alors bon " << log.toString( data ) << std::endl; + EXPECT_EQ( log.toString( data ), + "\n--------------------------------------------------------------------------------------------------------------------------------------\n" + "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis nascetur ridiculus mus |\n" + "--------------------------------------------------------------------------------------------------------------------------------------\n" + "| Rank | Nodes | Edge | Faces | Elems |\n" + "--------------------------------------------------------------------------------------------------------------------------------------\n" + "| | local | ghost | | local | ghost | local | ghost |\n" + "--------------------------------------------------------------------------------------------------------------------------------------\n" + "| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n" + "| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n" + "--------------------------------------------------------------------------------------------------------------------------------------\n\n" + ); + } } int main( int argc, char * * argv ) diff --git a/src/coreComponents/mesh/DomainPartition.cpp b/src/coreComponents/mesh/DomainPartition.cpp index 14353aa3c84..d1b1bfe0725 100644 --- a/src/coreComponents/mesh/DomainPartition.cpp +++ b/src/coreComponents/mesh/DomainPartition.cpp @@ -347,7 +347,6 @@ void DomainPartition::outputPartitionInformation() const GEOS_LOG_RANK_0( "MPI Partition information:" ); - forMeshBodies( [&]( MeshBody const & meshBody ) { meshBody.getMeshLevels().forSubGroupsIndex< MeshLevel >( [&]( int const level, MeshLevel const & meshLevel ) @@ -410,12 +409,14 @@ void DomainPartition::outputPartitionInformation() const real64 const maxElemRatio = maxRatios[3]; GEOS_LOG_RANK_0( " MeshBody: " + meshBody.getName() + " MeshLevel: " + meshLevel.getName() + "\n" ); + TableLayout tableLayout( "Rank", - TableLayout::ColumnParam{"Nodes ", TableLayout::Alignment::center, true, {"local", "ghost"}}, - TableLayout::ColumnParam{"Edges ", TableLayout::Alignment::center, true, {"local", "ghost"}}, - TableLayout::ColumnParam{"Faces ", TableLayout::Alignment::center, true, {"local", "ghost"}}, - TableLayout::ColumnParam{"Elems ", TableLayout::Alignment::center, true, {"local", "ghost"}} ); - tableLayout.setMargin( TableLayout::MarginValue::large ); + TableLayout::ColumnParam{"Nodes", {"local", "ghost"}}, + TableLayout::ColumnParam{"Edges", {"local", "ghost"}}, + TableLayout::ColumnParam{"Faces", {"local", "ghost"}}, + TableLayout::ColumnParam{"Elems", {"local", "ghost"}} ); + tableLayout.setMargin( TableLayout::MarginValue::large ) + .setAlignment( TableLayout::Alignment::center ); tableLayout.disableLineWrap(); TableData tableData; @@ -460,24 +461,20 @@ void DomainPartition::outputPartitionInformation() const TableTextFormatter tableLog( tableLayout ); GEOS_LOG_RANK_0( tableLog.toString( tableData )); - TableLayout tableLayoutRatio( "Rank", - "Nodes ", - "Edges ", - "Faces ", - "Elems "); + TableLayout tableLayoutRatio( "Rank", "Nodes ", "Edges ", "Faces ", "Elems " ); tableLayout.setMargin( TableLayout::MarginValue::large ); - + TableData tableDataRatio; tableDataRatio.addRow( "min(local/total)", - minNodeRatio, - minEdgeRatio, - minFaceRatio, - minElemRatio ); + minNodeRatio, + minEdgeRatio, + minFaceRatio, + minElemRatio ); tableDataRatio.addRow( "min(local/total)", - maxNodeRatio, - maxEdgeRatio, - maxFaceRatio, - maxElemRatio ); + maxNodeRatio, + maxEdgeRatio, + maxFaceRatio, + maxElemRatio ); tableLayout.removeSubColumn(); TableTextFormatter tableLogRatio( tableLayoutRatio ); @@ -485,7 +482,6 @@ void DomainPartition::outputPartitionInformation() const } } ); } - ); } From 37c97219cf6902d38a7b4f5cd69ec84fde75a070 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 23 Sep 2024 14:43:55 +0200 Subject: [PATCH 177/216] uncrustify + some renaming --- .../common/format/table/TableFormatter.cpp | 84 ++++++++++--------- .../common/format/table/TableFormatter.hpp | 28 +++---- .../common/format/table/TableLayout.cpp | 10 +-- .../common/format/table/TableLayout.hpp | 40 +++++---- 4 files changed, 87 insertions(+), 75 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index d649b6964ab..c98d866bda8 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -81,7 +81,7 @@ string TableCSVFormatter::toString< TableData >( TableData const & tableData ) c ////// Log Formatter implementation /////////////////////////////////////////////////////////////////////// -void distributeSpaces( std::vector< std::string > & vec, int totalSpaces ) +void distributeSpaces( std::vector< string > & vec, int totalSpaces ) { int numElements = vec.size(); int baseSpaces = totalSpaces / numElements; @@ -90,7 +90,7 @@ void distributeSpaces( std::vector< std::string > & vec, int totalSpaces ) for( int i = 0; i < numElements; ++i ) { - vec[i] += std::string( baseSpaces, ' ' ); + vec[i] += string( baseSpaces, ' ' ); if( i < extraSpaces ) { @@ -99,7 +99,7 @@ void distributeSpaces( std::vector< std::string > & vec, int totalSpaces ) } } -void transpose( std::vector< std::vector< std::string > > & dest, std::vector< std::vector< std::string > > const & source ) +void transpose( std::vector< std::vector< string > > & dest, std::vector< std::vector< string > > const & source ) { for( size_t idxRow = 0; idxRow < source.size(); ++idxRow ) { @@ -165,8 +165,8 @@ string TableTextFormatter::layoutToString() const std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); size_t nbHeaderRows = 0; TableData tableData; - std::string sectionSeparatingLine; - std::string topSeparator; + string sectionSeparatingLine; + string topSeparator; prepareAndBuildTable( columns, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); @@ -184,8 +184,8 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) std::ostringstream tableOutput; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); size_t nbHeaderRows = 0; - std::string sectionSeparatingLine; - std::string topSeparator; + string sectionSeparatingLine; + string topSeparator; prepareAndBuildTable( columns, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); @@ -197,8 +197,8 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::Column > & columns, TableData const & tableData, size_t & nbHeaderRows, - std::string & sectionSeparatingLine, - std::string & topSeparator ) const + string & sectionSeparatingLine, + string & topSeparator ) const { std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); std::vector< std::vector< string > > splitHeaders; @@ -222,8 +222,8 @@ void TableTextFormatter::outputTable( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, TableData const & tableData, size_t & nbHeaderRows, - std::string const & sectionSeparatingLine, - std::string const & topSeparator ) const + string_view sectionSeparatingLine, + string_view topSeparator ) const { integer const nbValuesRows = tableData.getTableDataRows().size(); @@ -239,12 +239,13 @@ void TableTextFormatter::outputTable( std::ostringstream & tableOutput, } void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout::Column > & columns, - std::vector< std::vector< std::string > > const & tableDataRows, + std::vector< std::vector< string > > const & tableDataRows, bool isSubColumn ) const { size_t currentColumn = 0; - std::vector< std::vector< std::string > > tColumnsValues( tableDataRows[0].size(), std::vector< std::string >( tableDataRows.size())); + std::vector< std::vector< string > > tColumnsValues( tableDataRows[0].size(), + std::vector< string >( tableDataRows.size())); if( !isSubColumn ) { transpose( tColumnsValues, tableDataRows ); @@ -259,11 +260,12 @@ void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout: } else { - std::vector< std::vector< std::string > > subColumnValues( tColumnsValues.begin() + currentColumn, - tColumnsValues.begin() + currentColumn + column.parameter.subColumns.size()); + std::vector< std::vector< string > > subColumnValues( tColumnsValues.begin() + currentColumn, + tColumnsValues.begin() + currentColumn + column.parameter.subColumns.size()); populateColumnsFromTableData( column.subColumn, subColumnValues, true ); - std::vector< std::vector< std::string > > tSubColumnValues( subColumnValues[0].size(), std::vector< std::string >( subColumnValues.size()) ); + std::vector< std::vector< string > > tSubColumnValues( subColumnValues[0].size(), + std::vector< string >( subColumnValues.size()) ); transpose( tSubColumnValues, subColumnValues ); for( const auto & columnValues : tSubColumnValues ) { // add all subcolumn values in parent column @@ -303,7 +305,10 @@ void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::C } nbHeaderRows = std::max_element( splitHeaders.begin(), splitHeaders.end(), - []( auto const & v1, auto const & v2 ) { return v1.size() < v2.size(); } )->size(); + []( auto const & v1, auto const & v2 ) + { + return v1.size() < v2.size(); + } )->size(); for( auto & headerParts : splitHeaders ) { @@ -316,7 +321,9 @@ void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::C } -void TableTextFormatter::findAndSetLongestColumnString( TableLayout::Column & column, std::vector< std::string > & maxStringSize, integer const idxMaxString ) const +void TableTextFormatter::findAndSetLongestColumnString( TableLayout::Column & column, + std::vector< string > & maxStringSize, + integer const idxMaxString ) const { string maxStringColumn; { // header case @@ -353,7 +360,9 @@ void TableTextFormatter::findAndSetLongestColumnString( TableLayout::Column & co column.maxStringSize.clear(); for( size_t idxSubColumn = 0; idxSubColumn < column.subColumn.size(); ++idxSubColumn ) { - findAndSetLongestColumnString( column.subColumn[idxSubColumn], column.maxStringSize, idxSubColumn ); + findAndSetLongestColumnString( column.subColumn[idxSubColumn], + column.maxStringSize, + idxSubColumn ); } } } @@ -372,13 +381,13 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & string::size_type const sectionLengthWithSpacing = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); string::size_type sectionlineLength = sectionLengthWithSpacing; - string const spaces = std::string( m_tableLayout.getColumnMargin(), ' ' ); + string const spaces = string( m_tableLayout.getColumnMargin(), ' ' ); { // Compute total length of all columns with margins sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, [&]( auto sum, auto & column ) -> auto { // take into account subColumn - std::string sumOfString = stringutilities::join( column.maxStringSize, spaces ); + string sumOfString = stringutilities::join( column.maxStringSize, spaces ); return static_cast< decltype(sum) >(sum + sumOfString.length()); } ); } @@ -406,7 +415,7 @@ void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > } else { - std::string & cell = columns[idxColumn].maxStringSize[0]; + string & cell = columns[idxColumn].maxStringSize[0]; integer newMaxStringSize = idxColumn == 0 ? extraCharactersPerColumn + cell.size() + rest : extraCharactersPerColumn + cell.size(); @@ -416,8 +425,8 @@ void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > } void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column > const & columns, - std::string & sectionSeparatingLine, - std::string & topSeparator ) const + string & sectionSeparatingLine, + string & topSeparator ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); @@ -425,17 +434,16 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column std::vector< string > maxStringsPerColumn; for( auto const & column : columns ) { - std::for_each( column.maxStringSize.begin(), column.maxStringSize.end(), [&] ( std::string maxString ) { + std::for_each( column.maxStringSize.begin(), column.maxStringSize.end(), [&] ( string maxString ) { maxStringsPerColumn.push_back( string( maxString.length(), m_horizontalLine ) ); } ); } - std::string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", m_horizontalLine, columnMargin ); - std::string const leftBorder = GEOS_FMT( "{:-<{}}", m_horizontalLine, borderMargin ); - std::string const rightBorder = GEOS_FMT( "{:-<{}}", m_horizontalLine, borderMargin ); + string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", m_horizontalLine, columnMargin ); + string const leftBorder = GEOS_FMT( "{:-<{}}", m_horizontalLine, borderMargin ); + string const rightBorder = GEOS_FMT( "{:-<{}}", m_horizontalLine, borderMargin ); - // Join all parts to form the section separating line - std::string const columnJoin = stringutilities::join( maxStringsPerColumn, patternBetweenColumns ); + string const columnJoin = stringutilities::join( maxStringsPerColumn, patternBetweenColumns ); std::ostringstream oss; oss << leftBorder << columnJoin << rightBorder; sectionSeparatingLine = oss.str(); @@ -464,11 +472,11 @@ void TableTextFormatter::outputSubSection( std::vector< TableLayout::Column > co void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, size_t const nbRows, - std::string const & sectionSeparatingLine ) const + string_view sectionSeparatingLine ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); - string const spaces = std::string( columnMargin - 1, ' ' ); + string const spaces = string( columnMargin - 1, ' ' ); for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) { @@ -486,10 +494,10 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu else { string const cell = column.columnValues.at( idxRow ); - std::string const cellSize = stringutilities::join( column.maxStringSize, spaces ); + string const cellSize = stringutilities::join( column.maxStringSize, spaces ); tableOutput << buildCell( column.parameter.alignment, cell, cellSize.length()); } - + if( idxColumn < columns.size() - 1 ) { tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); @@ -513,7 +521,7 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu } void TableTextFormatter::outputTitleRow( std::ostringstream & tableOutput, - std::string const & topSeparator ) const + string_view topSeparator ) const { string const tableTitle = string( m_tableLayout.getTitle()); if( !tableTitle.empty() ) @@ -530,11 +538,11 @@ void TableTextFormatter::outputTitleRow( std::ostringstream & tableOutput, void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, size_t const nbRows, - std::string const & sectionSeparatingLine ) const + string_view sectionSeparatingLine ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); - string const spaces = std::string( columnMargin, ' ' ); + string const spaces = string( columnMargin, ' ' ); bool containSubColumn = false; for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) @@ -546,7 +554,7 @@ void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Colu { auto const & column = columns[idxColumn]; string cell = column.parameter.splitColumnNames.at( idxRow ); - std::string cellSize = stringutilities::join( column.maxStringSize, spaces ); + string cellSize = stringutilities::join( column.maxStringSize, spaces ); tableOutput << buildCell( column.parameter.alignment, cell, cellSize.length()); // Add space between columns diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 6d107082f99..7ef95af5d48 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -166,13 +166,13 @@ class TableTextFormatter : public TableFormatter void prepareAndBuildTable( std::vector< TableLayout::Column > & columns, TableData const & tableData, size_t & nbHeaderRows, - std::string & sectionSeparatingLine, - std::string & topSeparator ) const; + string & sectionSeparatingLine, + string & topSeparator ) const; /** * @brief Displays the complete table * @param tableOutput The output stream - * @param columns The vector containg all columns - * @param tableData Vector containing all rows filled with values + * @param columns Tector containg all columns + * @param tableData Vector conhe vtaining all rows filled with values * @param nbHeaderRows A variable to be calculated which will contain the number of header lines to be displayed * @param sectionSeparatingLine Separator string used between sections of the table * @param topSeparator The top table separator @@ -181,16 +181,14 @@ class TableTextFormatter : public TableFormatter std::vector< TableLayout::Column > & columns, TableData const & tableData, size_t & nbHeaderRows, - std::string const & sectionSeparatingLine, - std::string const & topSeparator ) const; + string_view sectionSeparatingLine, + string_view topSeparator ) const; /** - * @brief Populate all the column values with values extracted from the table data. + * @brief Populate all the column values with values extracted from the table data. * @param columns Vector of columns to populate. * @param tableData Vector containing all rows filled with values * @param isSubColumn Boolean indicating if the current column is a subcolumn - * - * @note Use transposition for populating column with no subColumn */ void populateColumnsFromTableData( std::vector< TableLayout::Column > & columns, std::vector< std::vector< string > > const & tableData, @@ -217,7 +215,7 @@ class TableTextFormatter : public TableFormatter * If the column contains subcolumns, it recursively applies the same logic to them */ void findAndSetLongestColumnString( TableLayout::Column & column, - std::vector< std::string > & maxStringSize, + std::vector< string > & maxStringSize, integer const idxColumn ) const; /** @@ -242,8 +240,8 @@ class TableTextFormatter : public TableFormatter * @param topSeparator The top table separator */ void buildTableSeparators( std::vector< TableLayout::Column > const & columns, - std::string & sectionSeparatingLine, - std::string & topSeparator ) const; + string & sectionSeparatingLine, + string & topSeparator ) const; /** * @brief Output the values rows in the table @@ -255,14 +253,14 @@ class TableTextFormatter : public TableFormatter void outputValuesSectionRows( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, size_t const nbRows, - std::string const & sectionSeparatingLine ) const; + string_view sectionSeparatingLine ) const; /** * @brief Output the title row in the table * @param topSeparator The top separator string */ void outputTitleRow( std::ostringstream & tableOutput, - std::string const & topSeparator ) const; + string_view topSeparator ) const; /** * @brief Output the header rows in the table @@ -274,7 +272,7 @@ class TableTextFormatter : public TableFormatter void outputHeaderSectionRows( std::vector< TableLayout::Column > const & columns, std::ostringstream & tableOutput, size_t const nbRows, - std::string const & sectionSeparatingLine ) const; + string_view sectionSeparatingLine ) const; /** * @brief Outputs subcolumns for the given row in the table. diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 5630abd1a7a..cfc6759fa3b 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -21,15 +21,15 @@ namespace geos { -void TableLayout::addToColumns( const std::vector< std::string > & columnNames ) +void TableLayout::addToColumns( const std::vector< string > & columnNames ) { for( const auto & columnName : columnNames ) { - addToColumns( std::string( columnName ) ); + addToColumns( string( columnName ) ); } } -void TableLayout::addToColumns( std::string const & columnName ) +void TableLayout::addToColumns( string_view columnName ) { m_columns.push_back( TableLayout::ColumnParam{ columnName } ); } @@ -51,7 +51,7 @@ void TableLayout::addToColumns( ColumnParam const & columnParam ) } } -TableLayout & TableLayout::setTitle( std::string const & title ) +TableLayout & TableLayout::setTitle( string_view title ) { m_tableTitle = title; return *this; @@ -65,7 +65,7 @@ TableLayout & TableLayout::disableLineWrap() TableLayout & TableLayout::setMargin( MarginValue marginValue ) { - m_marginValue = marginValue; + m_marginValue = marginValue; m_borderMargin = marginValue + 1; // margin + border character m_columnMargin = integer( marginValue ) * 2 + 1; diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index f36a097f078..c0bc8e84173 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -67,10 +67,10 @@ class TableLayout std::vector< string > splitColumnNames = {""}; /** - * @brief Construct a ColumnParam object with the specified name and alignment. + * @brief Construct a ColumnParam object with the specified name * @param name The name of the column */ - ColumnParam( std::string const & name ) + ColumnParam( string_view name ) : columnName( name ) {} @@ -79,7 +79,7 @@ class TableLayout * @param name The name of the column * @param align The alignment of the column */ - ColumnParam( std::string const & name, Alignment align ) + ColumnParam( string_view name, Alignment align ) : columnName( name ), alignment( align ) {} @@ -88,7 +88,7 @@ class TableLayout * @param name The name of the column * @param align The alignment of the column */ - ColumnParam( std::string const & name, std::vector< string > subsColumns ) + ColumnParam( string_view name, std::vector< string > subsColumns ) : columnName( name ), subColumns( subsColumns ) {} @@ -98,7 +98,7 @@ class TableLayout * @param align The alignment of the column * @param display Flag indicating whether the column is enabled */ - ColumnParam( std::string const & name, Alignment align, bool display ) + ColumnParam( string_view name, Alignment align, bool display ) : columnName( name ), alignment( align ), enabled( display ) {} @@ -108,23 +108,24 @@ class TableLayout * @param align The alignment of the column * @param display Flag indicating whether the column is enabled */ - ColumnParam( std::string const & name, Alignment align, bool display, std::vector< string > columns ) + ColumnParam( string_view name, Alignment align, bool display, std::vector< string > columns ) : columnName( name ), alignment( align ), enabled( display ), subColumns( columns ) {} }; /** * @brief Struct for a column. + * Each column contains its own parameters (such as name, alignment, etc.) and column values. */ struct Column { /// Structure who contains parameters for a column ColumnParam parameter; - /// A vector containing all column values + /// A vector containing all columns values std::vector< string > columnValues; /// The largest string(s) in the column std::vector< string > maxStringSize; - //sub divison of a column + /// Vector containing all sub columns subdivison std::vector< Column > subColumn; /** @@ -138,7 +139,7 @@ class TableLayout /** * @brief Constructs a Column with the given parameters. * @param columnParam The parameters for the column. - * @param subColumnInit The values in the column. + * @param subColumnInit The subcolumns contained in the colum */ Column( ColumnParam columnParam, std::vector< Column > subColumnInit ) : parameter( columnParam ), subColumn( subColumnInit ) @@ -178,8 +179,13 @@ class TableLayout processArguments( std::forward< Args >( args )... ); } - TableLayout( std::string const & title, - std::initializer_list< std::variant< std::string, TableLayout::ColumnParam > > args ) + /** + * @brief Construct a new Table Layout object + * @param title The table title + * @param args An initializer_list containing string / columnParam + */ + TableLayout( string_view title, + std::initializer_list< std::variant< string, TableLayout::ColumnParam > > args ) { setAlignment( Alignment::center ); setMargin( MarginValue::medium ); @@ -202,7 +208,7 @@ class TableLayout * @param title The table title * @return The tableLayout reference */ - TableLayout & setTitle( std::string const & title ); + TableLayout & setTitle( string_view title ); /** * @brief Remove the last return line a the end of the table @@ -263,9 +269,9 @@ class TableLayout /** * @brief Add a column to the table given an initializer_list of string & ColumnParam - * @param args An initializer_list containing either string or columnParam + * @param args An initializer_list containing string / columnParam */ - void processArguments( std::initializer_list< std::variant< std::string, TableLayout::ColumnParam > > args ) + void processArguments( std::initializer_list< std::variant< string, TableLayout::ColumnParam > > args ) { for( auto const & arg : args ) { @@ -296,17 +302,17 @@ class TableLayout * @brief Create and add columns to the columns vector given a string vector * @param columnNames The columns name */ - void addToColumns( std::vector< std::string > const & columnNames ); + void addToColumns( std::vector< string > const & columnNames ); /** * @brief Create and add a column to the columns vector given a string * @param columnName The column name */ - void addToColumns( std::string const & columnName ); + void addToColumns( string_view columnName ); /** * @brief Create and add a column to the columns vector given a ColumnParam - * @param columnParam The columnParam + * @param columnParam Vector containing addition information on the column */ void addToColumns( ColumnParam const & columnParam ); From f9f1111d9a72fed248a6445df5e7745592545e10 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 24 Sep 2024 10:55:04 +0200 Subject: [PATCH 178/216] fix default alignment not defined correctly --- .../common/format/table/TableFormatter.cpp | 14 +++++---- .../common/format/table/TableLayout.cpp | 2 +- .../common/format/table/TableLayout.hpp | 7 +++-- .../format/table/unitTests/testTable.cpp | 29 ++++++++++++++++--- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index c98d866bda8..14284a54644 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -227,15 +227,18 @@ void TableTextFormatter::outputTable( std::ostringstream & tableOutput, { integer const nbValuesRows = tableData.getTableDataRows().size(); - tableOutput << '\n'; + if( m_tableLayout.isLineWrapEnabled()){ + tableOutput << '\n'; + } outputTitleRow( tableOutput, topSeparator ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); outputHeaderSectionRows( columns, tableOutput, nbHeaderRows, sectionSeparatingLine ); outputValuesSectionRows( columns, tableOutput, nbValuesRows, sectionSeparatingLine ); - - tableOutput << '\n'; + if( m_tableLayout.isLineWrapEnabled()){ + tableOutput << '\n'; + } } void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout::Column > & columns, @@ -508,10 +511,9 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu // Append right border tableOutput << GEOS_FMT( "{:>{}}", m_verticalLine, borderMargin ); - if( idxRow != nbRows - 1 || !m_tableLayout.isLineWrapEnabled()) - { + tableOutput << "\n"; - } + } if( nbRows != 0 ) diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index cfc6759fa3b..60c1598c9b9 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -31,7 +31,7 @@ void TableLayout::addToColumns( const std::vector< string > & columnNames ) void TableLayout::addToColumns( string_view columnName ) { - m_columns.push_back( TableLayout::ColumnParam{ columnName } ); + m_columns.push_back( TableLayout::ColumnParam{ columnName, getDefaultAlignment() } ); } void TableLayout::addToColumns( ColumnParam const & columnParam ) diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index c0bc8e84173..33f751a7c7c 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -174,7 +174,7 @@ class TableLayout template< typename ... Args > TableLayout( Args &&... args ) { - setAlignment( Alignment::center ); + setAlignment( Alignment::right ); setMargin( MarginValue::medium ); processArguments( std::forward< Args >( args )... ); } @@ -187,7 +187,7 @@ class TableLayout TableLayout( string_view title, std::initializer_list< std::variant< string, TableLayout::ColumnParam > > args ) { - setAlignment( Alignment::center ); + setAlignment( Alignment::right ); setMargin( MarginValue::medium ); setTitle( title ); processArguments( args ); @@ -237,6 +237,7 @@ class TableLayout /** * @brief Remove all subcolumn in all columns + * Can be used if we want to reuse a TableLayout without keep subcolumns */ void removeSubColumn(); @@ -318,7 +319,7 @@ class TableLayout std::vector< Column > m_columns; - bool m_wrapLine = false; + bool m_wrapLine = true; TableLayout::Alignment m_defaultAlignment = TableLayout::Alignment::right; string m_tableTitle; integer m_borderMargin; diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index 703fe668fee..a2ea2cce8d0 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -290,21 +290,42 @@ TEST( testTable, variadicTest ) data.addRow( "min(local/total)", 1, 2, 3, 4, 5, 6, 7 ); data.addRow( "min(local/total)", 1, 2, 3, 4, 5, 6, 7 ); TableTextFormatter log( layoutTest ); - std::cout << " alors bon " << log.toString( data ) << std::endl; EXPECT_EQ( log.toString( data ), "\n--------------------------------------------------------------------------------------------------------------------------------------\n" "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis nascetur ridiculus mus |\n" "--------------------------------------------------------------------------------------------------------------------------------------\n" - "| Rank | Nodes | Edge | Faces | Elems |\n" + "| Rank | Nodes | Edge | Faces | Elems |\n" "--------------------------------------------------------------------------------------------------------------------------------------\n" "| | local | ghost | | local | ghost | local | ghost |\n" "--------------------------------------------------------------------------------------------------------------------------------------\n" - "| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n" - "| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n" + "| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n" + "| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n" "--------------------------------------------------------------------------------------------------------------------------------------\n\n" ); } } +TEST( testTable, testLineWrap ) +{ + TableLayout tableLayout( "Cras egestas", "CoordX", "C", "CoordZ", "Prev\nelement", "Next\nelement" ); + tableLayout.setTitle( "title" ).setMargin( TableLayout::MarginValue::tiny ).disableLineWrap(); + + TableData tableData; + tableData.addRow( "1", "2", "3.0", 3.0129877, 2.0f, 1 ); + tableData.addRow( "1", "2", "3.0", 3.0129877, 2.0f, 1 ); + + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableData ), + "---------------------------------------------------\n" + "| title |\n" + "---------------------------------------------------\n" + "|Cras egestas|CoordX| C| CoordZ| Prev| Next|\n" + "| | | | |element|element|\n" + "---------------------------------------------------\n" + "| 1| 2|3.0|3.0129877| 2| 1|\n" + "| 1| 2|3.0|3.0129877| 2| 1|\n" + "---------------------------------------------------\n" + ); +} int main( int argc, char * * argv ) { From aa98cf2cea3a9a5300ac54f5e0dfbeb67ef985f6 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 25 Sep 2024 14:07:17 +0200 Subject: [PATCH 179/216] xsd --- src/coreComponents/schema/schema.xsd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index 89fccd1c641..d28dacf4e1d 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -2851,7 +2851,7 @@ Equal to 1 for surface conditions, and to 0 for reservoir conditions--> - + @@ -3213,11 +3213,11 @@ Local- Add jump stabilization on interior of macro elements--> - + - + From db50180fd0550fe8ff502ad340cbcf12290ac839 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 2 Oct 2024 13:43:50 +0200 Subject: [PATCH 180/216] fix after merge --- .../multifluid/CO2Brine/CO2BrineFluid.cpp | 2 +- .../CO2Brine/functions/FlashModelBase.hpp | 27 +------------- .../CO2Brine/functions/PVTFunctionBase.hpp | 37 ------------------- .../functions/TableFunction.cpp | 6 +-- 4 files changed, 5 insertions(+), 67 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 44e40132533..71d28e5a2a6 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -331,7 +331,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() // then, we are ready to instantiate the phase models bool const isClone = this->isClone(); - PVTFunctionBase::TableOutputOptions const pvtOutputOpts = { + TableFunction::OutputOptions const pvtOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() > 0 && logger::internal::rank==0), // writeInLog }; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp index ec1be9e4a93..9092fed1bd1 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp @@ -88,32 +88,7 @@ class FlashModelBase * @throw a SimulationError if one of the input values is out of bound. */ virtual void checkTablesParameters( real64 pressure, real64 temperature ) const = 0; - - /** - * @brief Print the table(s) in the log and/or CSV files when requested by the user. - * @param tableData The target table to be printed - * @param pvtOutputOpts Struct containing output options - */ - void outputPVTTableData( TableFunction const * tableData, TableOutputOptions const pvtOutputOpts ) - { - if( pvtOutputOpts.writeInLog && tableData->numDimensions() <= 2 ) - { - TableTextFormatter textFormatter; - GEOS_LOG_RANK_0( textFormatter.toString( *tableData )); - } - if( pvtOutputOpts.writeCSV || ( pvtOutputOpts.writeInLog && tableData->numDimensions() >= 3 ) ) - { - string const filename = tableData->getName(); - std::ofstream logStream( joinPath( FunctionBase::getOutputDirectory(), filename + ".csv" ) ); - GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to {}/{}.csv \n", - FunctionBase::getOutputDirectory(), - filename )); - - TableCSVFormatter csvFormatter; - logStream << csvFormatter.toString( *tableData ); - } - } - + string const & flashModelName() const { return m_modelName; } protected: diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index ae1d41a0459..288125a2643 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -114,18 +114,6 @@ class PVTFunctionBase virtual ~PVTFunctionBase() = default; - - /// Struct containing output options - struct TableOutputOptions - { - /// Output PVT in CSV file - bool writeCSV; - /// Output PVT in log - bool writeInLog; - }; - - - virtual string getCatalogName() const = 0; string const & functionName() const { return m_functionName; } @@ -140,31 +128,6 @@ class PVTFunctionBase */ virtual void checkTablesParameters( real64 pressure, real64 temperature ) const = 0; - /** - * @brief Print the table(s) in the log and/or CSV files when requested by the user. - * @param tableData The target table to be printed - * @param pvtOutputOpts Struct containing output options - */ - void outputPVTTableData( TableFunction const * tableData, TableOutputOptions const pvtOutputOpts ) - { - if( pvtOutputOpts.writeInLog && tableData->numDimensions() <= 2 ) - { - TableTextFormatter textFormatter; - GEOS_LOG_RANK_0( textFormatter.toString( *tableData )); - } - - if( pvtOutputOpts.writeCSV || ( pvtOutputOpts.writeInLog && tableData->numDimensions() >= 3 ) ) - { - string const filename = tableData->getName(); - std::ofstream logStream( joinPath( FunctionBase::getOutputDirectory(), filename + ".csv" ) ); - GEOS_LOG_RANK_0( GEOS_FMT( "CSV Generated to {}/{}.csv \n", - FunctionBase::getOutputDirectory(), - filename )); - TableCSVFormatter csvFormatter; - logStream << csvFormatter.toString( *tableData ); - } - } - protected: /// Name of the PVT function diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 2e1897e7629..dd256b60edc 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -336,10 +336,10 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl tableData.addRow( coords[idx], values[idx] ); } - TableLayout const tableLayout( { + TableLayout const tableLayout( filename, { string( units::getDescription( tableFunction.getDimUnit( 0 ))), string( units::getDescription( valueUnit )) - }, filename ); + } ); TableTextFormatter const logTable( tableLayout ); logOutput = logTable.toString( tableData ); @@ -366,7 +366,7 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl else { 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 ); + TableLayout const tableLayoutInfos( filename, {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}} ); TableTextFormatter const tableLog( tableLayoutInfos ); logOutput = tableLog.layoutToString(); } From 377eea948200328f5dda23ffe0646b508c7316bd Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 2 Oct 2024 13:45:41 +0200 Subject: [PATCH 181/216] uncrustify --- .../common/format/table/TableFormatter.cpp | 12 +++++++----- src/coreComponents/common/initializeEnvironment.cpp | 8 ++++---- .../fluid/multifluid/CO2Brine/CO2BrineFluid.cpp | 2 +- .../multifluid/CO2Brine/functions/FlashModelBase.hpp | 2 +- src/coreComponents/schema/schema.xsd | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 14284a54644..1afe22a48eb 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -227,7 +227,8 @@ void TableTextFormatter::outputTable( std::ostringstream & tableOutput, { integer const nbValuesRows = tableData.getTableDataRows().size(); - if( m_tableLayout.isLineWrapEnabled()){ + if( m_tableLayout.isLineWrapEnabled()) + { tableOutput << '\n'; } outputTitleRow( tableOutput, topSeparator ); @@ -236,7 +237,8 @@ void TableTextFormatter::outputTable( std::ostringstream & tableOutput, outputHeaderSectionRows( columns, tableOutput, nbHeaderRows, sectionSeparatingLine ); outputValuesSectionRows( columns, tableOutput, nbValuesRows, sectionSeparatingLine ); - if( m_tableLayout.isLineWrapEnabled()){ + if( m_tableLayout.isLineWrapEnabled()) + { tableOutput << '\n'; } } @@ -511,9 +513,9 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu // Append right border tableOutput << GEOS_FMT( "{:>{}}", m_verticalLine, borderMargin ); - - tableOutput << "\n"; - + + tableOutput << "\n"; + } if( nbRows != 0 ) diff --git a/src/coreComponents/common/initializeEnvironment.cpp b/src/coreComponents/common/initializeEnvironment.cpp index 07f157b0cf5..17d0d4bfbc0 100644 --- a/src/coreComponents/common/initializeEnvironment.cpp +++ b/src/coreComponents/common/initializeEnvironment.cpp @@ -346,10 +346,10 @@ static void addUmpireHighWaterMarks() } TableLayout const memoryStatLayout ( "Umpire Memory Pool\n(reserved / % over total)", - "Min over ranks", - "Max over ranks", - "Avg over ranks", - "Sum over ranks" ); + "Min over ranks", + "Max over ranks", + "Avg over ranks", + "Sum over ranks" ); TableTextFormatter const memoryStatLog( memoryStatLayout ); GEOS_LOG_RANK_0( memoryStatLog.toString( tableData )); diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 71d28e5a2a6..c90b6c296f6 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -331,7 +331,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() // then, we are ready to instantiate the phase models bool const isClone = this->isClone(); - TableFunction::OutputOptions const pvtOutputOpts = { + TableFunction::OutputOptions const pvtOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() > 0 && logger::internal::rank==0), // writeInLog }; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp index 9092fed1bd1..c73e21df7a5 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp @@ -88,7 +88,7 @@ class FlashModelBase * @throw a SimulationError if one of the input values is out of bound. */ virtual void checkTablesParameters( real64 pressure, real64 temperature ) const = 0; - + string const & flashModelName() const { return m_modelName; } protected: diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index a8430b98131..d6018bf6391 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -2946,7 +2946,7 @@ Equal to 1 for surface conditions, and to 0 for reservoir conditions--> - + @@ -2969,7 +2969,7 @@ Local- Add jump stabilization on interior of macro elements--> - + From 6f70e9b8e2e94845471eb31c1fc50089f6d60331 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 2 Oct 2024 14:08:17 +0200 Subject: [PATCH 182/216] doc small correction + replace layoutTostring -> toString --- .../common/format/table/TableFormatter.cpp | 2 +- .../common/format/table/TableFormatter.hpp | 18 +++++++++--------- .../format/table/unitTests/testTable.cpp | 2 +- src/coreComponents/functions/TableFunction.cpp | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 1afe22a48eb..c486488c33b 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -159,7 +159,7 @@ TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): TableFormatter( tableLayout ) {} -string TableTextFormatter::layoutToString() const +string TableTextFormatter::toString() const { std::ostringstream tableOutput; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 7ef95af5d48..2f5acc16476 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -137,7 +137,7 @@ class TableTextFormatter : public TableFormatter /** * @return A TableLayout converted into a formatted representation. */ - string layoutToString() const; + string toString() const; /** * @brief Convert a data source to a table string. @@ -161,7 +161,7 @@ class TableTextFormatter : public TableFormatter * @param tableData Vector containing all rows filled with values * @param nbHeaderRows Number of header rows, which will be calculated based on column headers and their formatting. * @param sectionSeparatingLine Separator string used between sections of the table - * @param topSeparator The top table separator + * @param topSeparator The table top separator */ void prepareAndBuildTable( std::vector< TableLayout::Column > & columns, TableData const & tableData, @@ -171,11 +171,11 @@ class TableTextFormatter : public TableFormatter /** * @brief Displays the complete table * @param tableOutput The output stream - * @param columns Tector containg all columns - * @param tableData Vector conhe vtaining all rows filled with values - * @param nbHeaderRows A variable to be calculated which will contain the number of header lines to be displayed + * @param columns Vector containg all columns + * @param tableData Vector containing all rows filled with values + * @param nbHeaderRows A variable to be calculated which will contain the number of header lines * @param sectionSeparatingLine Separator string used between sections of the table - * @param topSeparator The top table separator + * @param topSeparator The table top separator */ void outputTable( std::ostringstream & tableOutput, std::vector< TableLayout::Column > & columns, @@ -185,7 +185,7 @@ class TableTextFormatter : public TableFormatter string_view topSeparator ) const; /** - * @brief Populate all the column values with values extracted from the table data. + * @brief Populate all the column values with values extracted from TableData. * @param columns Vector of columns to populate. * @param tableData Vector containing all rows filled with values * @param isSubColumn Boolean indicating if the current column is a subcolumn @@ -219,7 +219,7 @@ class TableTextFormatter : public TableFormatter integer const idxColumn ) const; /** - * @brief Compute the max table line length, taking into account the length of : title, columns header and values + * @brief Compute the max table line length, taking into account the length of : title, columns header/values * Increase the size of the columns if necessary * @param columns Vector of column containing containing the largest string for each column */ @@ -237,7 +237,7 @@ class TableTextFormatter : public TableFormatter * @brief Builds the table's separating lines based on the content length of the columns. * @param columns Vector containing all table columns * @param sectionSeparatingLine Separator string used between sections of the table - * @param topSeparator The top table separator + * @param topSeparator The table top separator */ void buildTableSeparators( std::vector< TableLayout::Column > const & columns, string & sectionSeparatingLine, diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index a2ea2cce8d0..2b6ca853e96 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -237,7 +237,7 @@ TEST( testTable, layoutTable ) tableLayoutInfos.setTitle( filename ); TableTextFormatter const tableLog( tableLayoutInfos ); - EXPECT_EQ( tableLog.layoutToString(), + EXPECT_EQ( tableLog.toString(), "\n-------------------------------------------------------------------------------------\n" "| fluid1_phaseModel1_PhillipsBrineDensity_table |\n" "-------------------------------------------------------------------------------------\n" diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index dd256b60edc..ad1d1ff7d64 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -368,7 +368,7 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl string log = GEOS_FMT( "The {} PVT table exceeding 500 rows.\nTo visualize the tables, go to the generated csv \n", filename ); TableLayout const tableLayoutInfos( filename, {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}} ); TableTextFormatter const tableLog( tableLayoutInfos ); - logOutput = tableLog.layoutToString(); + logOutput = tableLog.toString(); } } return logOutput; From 79cbc8e1686a2a27b31c3885347e6d23c396a272 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 2 Oct 2024 15:01:06 +0200 Subject: [PATCH 183/216] missing doc + small adjustment --- .../common/format/table/TableFormatter.cpp | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index c486488c33b..2a2040fcbf3 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -81,6 +81,11 @@ string TableCSVFormatter::toString< TableData >( TableData const & tableData ) c ////// Log Formatter implementation /////////////////////////////////////////////////////////////////////// +/** + * @brief distributes spaces equally from a string vector + * @param vec The vector where we adding spaces + * @param totalSpaces Total spaces to be distributed + */ void distributeSpaces( std::vector< string > & vec, int totalSpaces ) { int numElements = vec.size(); @@ -89,7 +94,6 @@ void distributeSpaces( std::vector< string > & vec, int totalSpaces ) for( int i = 0; i < numElements; ++i ) { - vec[i] += string( baseSpaces, ' ' ); if( i < extraSpaces ) @@ -181,7 +185,6 @@ string TableTextFormatter::toString() const template<> string TableTextFormatter::toString< TableData >( TableData const & tableData ) const { - std::ostringstream tableOutput; std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); size_t nbHeaderRows = 0; string sectionSeparatingLine; @@ -189,6 +192,7 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) prepareAndBuildTable( columns, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); + std::ostringstream tableOutput; outputTable( tableOutput, columns, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); return tableOutput.str(); @@ -201,12 +205,13 @@ void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::Column string & topSeparator ) const { std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); - std::vector< std::vector< string > > splitHeaders; - if( !tableData.getTableDataRows().empty()) + if( !tableDataRows.empty()) { updateVisibleColumns( columns, tableDataRows ); populateColumnsFromTableData( columns, tableDataRows, false ); } + + std::vector< std::vector< string > > splitHeaders; splitAndMergeColumnHeaders( columns, nbHeaderRows, splitHeaders ); for( auto & column : columns ) @@ -248,7 +253,6 @@ void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout: bool isSubColumn ) const { size_t currentColumn = 0; - std::vector< std::vector< string > > tColumnsValues( tableDataRows[0].size(), std::vector< string >( tableDataRows.size())); if( !isSubColumn ) @@ -265,15 +269,16 @@ void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout: } else { - std::vector< std::vector< string > > subColumnValues( tColumnsValues.begin() + currentColumn, - tColumnsValues.begin() + currentColumn + column.parameter.subColumns.size()); + auto subColumnStartIdx = tColumnsValues.begin() + currentColumn; + std::vector< std::vector< string > > subColumnValues( subColumnStartIdx, + subColumnStartIdx + column.parameter.subColumns.size()); populateColumnsFromTableData( column.subColumn, subColumnValues, true ); std::vector< std::vector< string > > tSubColumnValues( subColumnValues[0].size(), std::vector< string >( subColumnValues.size()) ); transpose( tSubColumnValues, subColumnValues ); for( const auto & columnValues : tSubColumnValues ) - { // add all subcolumn values in parent column + { // add all subcolumn values in parent column column.columnValues.insert( column.columnValues.end(), columnValues.begin(), columnValues.end() ); } currentColumn += subColumnValues.size(); @@ -293,13 +298,12 @@ void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::C std::vector< string > splitHeaderParts; std::istringstream ss( column.parameter.columnName ); string subColumnNames; - while( getline( ss, subColumnNames, '\n' )) { splitHeaderParts.push_back( subColumnNames ); } - splitHeaders.push_back( std::move( splitHeaderParts ) ); + splitHeaders.push_back( splitHeaderParts ); if( !column.subColumn.empty()) { @@ -410,7 +414,7 @@ void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > real64 const extraCharacters ) const { real64 const extraCharactersPerColumn = std::floor( (extraCharacters) / columns.size() ); - integer rest = extraCharacters - (extraCharactersPerColumn * columns.size() ); + integer overflowCharacters = extraCharacters - (extraCharactersPerColumn * columns.size() ); for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { if( !columns[idxColumn].subColumn.empty()) @@ -422,7 +426,7 @@ void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > { string & cell = columns[idxColumn].maxStringSize[0]; integer newMaxStringSize = idxColumn == 0 ? - extraCharactersPerColumn + cell.size() + rest : + extraCharactersPerColumn + cell.size() + overflowCharacters : extraCharactersPerColumn + cell.size(); cell = GEOS_FMT( "{:>{}}", cell, newMaxStringSize ); } @@ -433,9 +437,6 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column string & sectionSeparatingLine, string & topSeparator ) const { - integer const columnMargin = m_tableLayout.getColumnMargin(); - integer const borderMargin = m_tableLayout.getBorderMargin(); - std::vector< string > maxStringsPerColumn; for( auto const & column : columns ) { @@ -444,6 +445,8 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column } ); } + integer const columnMargin = m_tableLayout.getColumnMargin(); + integer const borderMargin = m_tableLayout.getBorderMargin(); string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", m_horizontalLine, columnMargin ); string const leftBorder = GEOS_FMT( "{:-<{}}", m_horizontalLine, borderMargin ); string const rightBorder = GEOS_FMT( "{:-<{}}", m_horizontalLine, borderMargin ); @@ -453,7 +456,7 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column oss << leftBorder << columnJoin << rightBorder; sectionSeparatingLine = oss.str(); - integer const topSeparatorLength = sectionSeparatingLine.size() -2; // Adjust for border characters + integer const topSeparatorLength = sectionSeparatingLine.size() - 2; // Adjust for border characters topSeparator = GEOS_FMT( "{}{:-<{}}{}", m_horizontalLine, "", topSeparatorLength, m_horizontalLine ); } From a32cedc050a3f47e13581fc3cc393c4d2d525ea6 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 3 Oct 2024 14:11:59 +0200 Subject: [PATCH 184/216] minor update --- .../common/format/table/TableFormatter.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 2a2040fcbf3..c18e3539da0 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -60,7 +60,8 @@ string TableCSVFormatter::headerToString() const string TableCSVFormatter::dataToString( TableData const & tableData ) const { - std::vector< std::vector< string > > const rowsValues = tableData.getTableDataRows(); + + std::vector< std::vector< string > > const rowsValues( tableData.getTableDataRows() ); std::ostringstream oss; for( const auto & row : rowsValues ) @@ -166,7 +167,7 @@ TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): string TableTextFormatter::toString() const { std::ostringstream tableOutput; - std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); + std::vector< TableLayout::Column > columns( m_tableLayout.getColumns()); size_t nbHeaderRows = 0; TableData tableData; string sectionSeparatingLine; @@ -185,7 +186,7 @@ string TableTextFormatter::toString() const template<> string TableTextFormatter::toString< TableData >( TableData const & tableData ) const { - std::vector< TableLayout::Column > columns = m_tableLayout.getColumns(); + std::vector< TableLayout::Column > columns( m_tableLayout.getColumns()); size_t nbHeaderRows = 0; string sectionSeparatingLine; string topSeparator; @@ -204,7 +205,7 @@ void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::Column string & sectionSeparatingLine, string & topSeparator ) const { - std::vector< std::vector< string > > tableDataRows = tableData.getTableDataRows(); + std::vector< std::vector< string > > tableDataRows( tableData.getTableDataRows()); if( !tableDataRows.empty()) { updateVisibleColumns( columns, tableDataRows ); @@ -290,7 +291,6 @@ void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::C size_t & nbHeaderRows, std::vector< std::vector< string > > & splitHeaders ) const { - splitHeaders.reserve( columns.size() ); for( auto & column : columns ) @@ -604,5 +604,4 @@ void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Colu } } - } From 8f744188df1d5cedb969550941a0228a8f18e39e Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 3 Oct 2024 14:12:15 +0200 Subject: [PATCH 185/216] xsd --- src/coreComponents/schema/schema.xsd.other | 130 ++++++++++----------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/src/coreComponents/schema/schema.xsd.other b/src/coreComponents/schema/schema.xsd.other index d59f6b947e5..215191d89f5 100644 --- a/src/coreComponents/schema/schema.xsd.other +++ b/src/coreComponents/schema/schema.xsd.other @@ -471,7 +471,7 @@ - + @@ -553,7 +553,7 @@ - + @@ -590,7 +590,7 @@ - + @@ -641,7 +641,7 @@ - + @@ -682,7 +682,7 @@ - + @@ -715,7 +715,7 @@ - + @@ -726,7 +726,7 @@ - + @@ -739,7 +739,7 @@ - + @@ -752,7 +752,7 @@ - + @@ -768,7 +768,7 @@ - + @@ -802,7 +802,7 @@ - + @@ -865,7 +865,7 @@ - + @@ -896,7 +896,7 @@ - + @@ -909,7 +909,7 @@ - + @@ -922,7 +922,7 @@ - + @@ -935,7 +935,7 @@ - + @@ -948,7 +948,7 @@ - + @@ -963,7 +963,7 @@ - + @@ -974,7 +974,7 @@ - + @@ -987,7 +987,7 @@ - + @@ -998,7 +998,7 @@ - + @@ -1009,7 +1009,7 @@ - + @@ -1022,7 +1022,7 @@ - + @@ -1033,7 +1033,7 @@ - + @@ -1044,7 +1044,7 @@ - + @@ -1057,7 +1057,7 @@ - + @@ -1072,7 +1072,7 @@ - + @@ -1087,7 +1087,7 @@ - + @@ -1100,7 +1100,7 @@ - + @@ -1115,7 +1115,7 @@ - + @@ -1126,7 +1126,7 @@ - + @@ -1139,7 +1139,7 @@ - + @@ -1152,7 +1152,7 @@ - + @@ -1168,7 +1168,7 @@ - + @@ -1183,7 +1183,7 @@ - + @@ -1200,7 +1200,7 @@ - + @@ -1217,7 +1217,7 @@ - + @@ -1232,7 +1232,7 @@ - + @@ -1245,7 +1245,7 @@ - + @@ -1284,7 +1284,7 @@ - + @@ -1313,7 +1313,7 @@ - + @@ -1404,7 +1404,7 @@ - + @@ -2958,7 +2958,7 @@ - + @@ -2986,7 +2986,7 @@ - + @@ -3005,11 +3005,11 @@ - + - + @@ -3019,7 +3019,7 @@ - + @@ -3029,11 +3029,11 @@ - + - + @@ -3043,7 +3043,7 @@ - + @@ -3053,7 +3053,7 @@ - + @@ -3063,7 +3063,7 @@ - + @@ -3087,7 +3087,7 @@ - + @@ -3105,7 +3105,7 @@ - + @@ -3117,7 +3117,7 @@ - + @@ -3129,7 +3129,7 @@ - + @@ -3137,11 +3137,11 @@ - + - + @@ -3164,7 +3164,7 @@ - + @@ -3190,7 +3190,7 @@ - + @@ -3211,7 +3211,7 @@ - + @@ -3241,7 +3241,7 @@ - + @@ -3255,7 +3255,7 @@ - + @@ -3282,7 +3282,7 @@ - + @@ -3319,7 +3319,7 @@ - + From 7d838334d8435cecc0011ca5a9461a527efd3929 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 3 Oct 2024 14:33:24 +0200 Subject: [PATCH 186/216] remove todo --- src/coreComponents/common/format/table/TableFormatter.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index c18e3539da0..19290b923f9 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -14,7 +14,6 @@ */ -//TODO REAJUSTER LAPPEL DES FONCTIONS /** * @file TableFormatter.cpp */ From 24ab8faa6ecb8d57d17830e5dcbdd6fe7bf233fd Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 3 Oct 2024 16:04:58 +0200 Subject: [PATCH 187/216] small things forgotten --- .../fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp | 3 +-- .../fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp index c73e21df7a5..d4a49f334b2 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp @@ -21,7 +21,6 @@ #define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_FUNCTIONS_FLASHMODELBASE_HPP_ #include "dataRepository/ObjectCatalog.hpp" -#include "functions/TableFunction.hpp" namespace geos { @@ -110,4 +109,4 @@ class FlashModelBase } // end namespace geos -#endif //GEOS_CONSTITUTIVE_FLUID_PVTFUNCTIONS_FLASHMODELBASE_HPP_ +#endif //GEOS_CONSTITUTIVE_FLUID_PVTFUNCTIONS_FLASHMODELBASE_HPP_ \ No newline at end of file diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index 288125a2643..f292450d852 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -21,7 +21,6 @@ #define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_FUNCTIONS_PVTFUNCTIONBASE_HPP_ #include "dataRepository/ObjectCatalog.hpp" -#include "functions/TableFunction.hpp" namespace geos { @@ -114,6 +113,7 @@ class PVTFunctionBase virtual ~PVTFunctionBase() = default; + virtual string getCatalogName() const = 0; string const & functionName() const { return m_functionName; } @@ -147,4 +147,4 @@ class PVTFunctionBase } // end namespace geos -#endif //GEOS_CONSTITUTIVE_FLUID_PVTFUNCTIONS_PVTFUNCTIONBASE_HPP_ +#endif //GEOS_CONSTITUTIVE_FLUID_PVTFUNCTIONS_PVTFUNCTIONBASE_HPP_ \ No newline at end of file From 1f1d2b591d14f3fa4bee7f9a928c60224bd7e04b Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 4 Oct 2024 16:39:09 +0200 Subject: [PATCH 188/216] fix pvt test --- .../common/format/table/TableLayout.hpp | 41 +++++++++++++------ .../CO2Brine/functions/FlashModelBase.hpp | 2 +- .../CO2Brine/functions/PVTFunctionBase.hpp | 2 +- .../functions/TableFunction.cpp | 7 +--- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 33f751a7c7c..c357f4503ed 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -71,7 +71,7 @@ class TableLayout * @param name The name of the column */ ColumnParam( string_view name ) - : columnName( name ) + : columnName( name ), alignment( m_defaultAlignment ) {} /** @@ -86,10 +86,10 @@ class TableLayout /** * @brief Construct a ColumnParam object with the specified name and alignment. * @param name The name of the column - * @param align The alignment of the column + * @param subsColumns Vector containing subcolumn values */ ColumnParam( string_view name, std::vector< string > subsColumns ) - : columnName( name ), subColumns( subsColumns ) + : columnName( name ), subColumns( subsColumns ), alignment( m_defaultAlignment ) {} /** @@ -107,9 +107,10 @@ class TableLayout * @param name The name of the column * @param align The alignment of the column * @param display Flag indicating whether the column is enabled + * @param columns Vector containing subcolumn values */ - ColumnParam( string_view name, Alignment align, bool display, std::vector< string > columns ) - : columnName( name ), alignment( align ), enabled( display ), subColumns( columns ) + ColumnParam( string_view name, Alignment align, bool display, std::vector< string > subsColumns ) + : columnName( name ), alignment( align ), enabled( display ), subColumns( subsColumns ) {} }; @@ -168,15 +169,16 @@ class TableLayout /** * @brief Construct a new Table Layout object - * @tparam Args Process only string, vector < string > and ColumnParam type - * @param args Variadics to be processed + * @param title The table title + * @param args An initializer_list containing string / columnParam */ - template< typename ... Args > - TableLayout( Args &&... args ) + TableLayout( string_view title, + std::initializer_list< std::variant< string, TableLayout::ColumnParam > > args ) { setAlignment( Alignment::right ); setMargin( MarginValue::medium ); - processArguments( std::forward< Args >( args )... ); + setTitle( title ); + processArguments( args ); } /** @@ -185,12 +187,25 @@ class TableLayout * @param args An initializer_list containing string / columnParam */ TableLayout( string_view title, - std::initializer_list< std::variant< string, TableLayout::ColumnParam > > args ) + std::vector< string > args ) { setAlignment( Alignment::right ); setMargin( MarginValue::medium ); setTitle( title ); - processArguments( args ); + addToColumns( args ); + } + + /** + * @brief Construct a new Table Layout object + * @tparam Args Process only string, vector < string > and ColumnParam type + * @param args Variadics to be processed + */ + template< typename ... Args > + TableLayout( Args &&... args ) + { + setAlignment( Alignment::right ); + setMargin( MarginValue::medium ); + processArguments( std::forward< Args >( args )... ); } /** @@ -225,7 +240,7 @@ class TableLayout /** * @brief Set the default table alignment - * @param marginValue The table alignment + * @param alignment The table alignment * @return The tableLayout reference */ TableLayout & setAlignment( Alignment alignment ); diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp index d4a49f334b2..acef1ec1ab0 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp @@ -109,4 +109,4 @@ class FlashModelBase } // end namespace geos -#endif //GEOS_CONSTITUTIVE_FLUID_PVTFUNCTIONS_FLASHMODELBASE_HPP_ \ No newline at end of file +#endif //GEOS_CONSTITUTIVE_FLUID_PVTFUNCTIONS_FLASHMODELBASE_HPP_ diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index f292450d852..135d7c899c4 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -147,4 +147,4 @@ class PVTFunctionBase } // end namespace geos -#endif //GEOS_CONSTITUTIVE_FLUID_PVTFUNCTIONS_PVTFUNCTIONBASE_HPP_ \ No newline at end of file +#endif //GEOS_CONSTITUTIVE_FLUID_PVTFUNCTIONS_PVTFUNCTIONBASE_HPP_ diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index ad1d1ff7d64..d2c5d187ac6 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -322,7 +322,7 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl units::Unit const valueUnit = tableFunction.getValueUnit(); arrayView1d< real64 const > const values = tableFunction.getValues(); integer const numDimensions = LvArray::integerConversion< integer >( coordinates.size() ); - string const filename = tableFunction.getName(); + std::string_view filename = tableFunction.getName(); string logOutput; GEOS_LOG_RANK_0( GEOS_FMT( "Values in the table are represented by : {}", units::getDescription( valueUnit ))); @@ -335,12 +335,10 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl { tableData.addRow( coords[idx], values[idx] ); } - TableLayout const tableLayout( filename, { string( units::getDescription( tableFunction.getDimUnit( 0 ))), string( units::getDescription( valueUnit )) } ); - TableTextFormatter const logTable( tableLayout ); logOutput = logTable.toString( tableData ); } @@ -358,8 +356,7 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl units::getDescription( tableFunction.getDimUnit( 0 ) ), units::getDescription( tableFunction.getDimUnit( 1 ) )); - TableLayout tableLayout( tableConverted.headerNames, filename ); - + TableLayout tableLayout( filename, tableConverted.headerNames ); TableTextFormatter const table2DLog( tableLayout ); logOutput = table2DLog.toString( tableConverted.tableData ); } From 04a494bbb25a8746a4d5ad4033cd8a437e51c5a1 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 7 Oct 2024 10:04:18 +0200 Subject: [PATCH 189/216] doxygen & failed test --- .../common/format/table/TableFormatter.hpp | 3 ++- .../common/format/table/TableLayout.cpp | 13 +---------- .../common/format/table/TableLayout.hpp | 22 +++---------------- src/coreComponents/mesh/DomainPartition.cpp | 3 +-- 4 files changed, 7 insertions(+), 34 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 2f5acc16476..d9e9099d0ce 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -135,7 +135,8 @@ class TableTextFormatter : public TableFormatter virtual ~TableTextFormatter() = default; /** - * @return A TableLayout converted into a formatted representation. + * @return A TableLayout string representation, + * The TableTextFormatter receives hasn't receive any data, so only the top part is returned. */ string toString() const; diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 60c1598c9b9..94b96594bdb 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -31,7 +31,7 @@ void TableLayout::addToColumns( const std::vector< string > & columnNames ) void TableLayout::addToColumns( string_view columnName ) { - m_columns.push_back( TableLayout::ColumnParam{ columnName, getDefaultAlignment() } ); + m_columns.push_back( TableLayout::ColumnParam{ columnName, TableLayout::Alignment::right } ); } void TableLayout::addToColumns( ColumnParam const & columnParam ) @@ -72,12 +72,6 @@ TableLayout & TableLayout::setMargin( MarginValue marginValue ) return *this; } -TableLayout & TableLayout::setAlignment( TableLayout::Alignment alignment ) -{ - m_defaultAlignment = alignment; - return *this; -} - bool TableLayout::isLineWrapEnabled() const { return m_wrapLine; @@ -124,9 +118,4 @@ integer const & TableLayout::getMarginTitle() const return m_titleMargin; } -TableLayout::Alignment TableLayout::getDefaultAlignment() const -{ - return m_defaultAlignment; -} - } diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index c357f4503ed..73d75213ead 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -58,7 +58,7 @@ class TableLayout /// Name for a column string columnName; /// Alignment for a column. By default aligned to the right side - Alignment alignment; + Alignment alignment = Alignment::right; /// A boolean to display a colummn bool enabled = true; /// Vector containing sub columns name @@ -71,7 +71,7 @@ class TableLayout * @param name The name of the column */ ColumnParam( string_view name ) - : columnName( name ), alignment( m_defaultAlignment ) + : columnName( name ) {} /** @@ -89,7 +89,7 @@ class TableLayout * @param subsColumns Vector containing subcolumn values */ ColumnParam( string_view name, std::vector< string > subsColumns ) - : columnName( name ), subColumns( subsColumns ), alignment( m_defaultAlignment ) + : columnName( name ), subColumns( subsColumns ) {} /** @@ -175,7 +175,6 @@ class TableLayout TableLayout( string_view title, std::initializer_list< std::variant< string, TableLayout::ColumnParam > > args ) { - setAlignment( Alignment::right ); setMargin( MarginValue::medium ); setTitle( title ); processArguments( args ); @@ -189,7 +188,6 @@ class TableLayout TableLayout( string_view title, std::vector< string > args ) { - setAlignment( Alignment::right ); setMargin( MarginValue::medium ); setTitle( title ); addToColumns( args ); @@ -203,7 +201,6 @@ class TableLayout template< typename ... Args > TableLayout( Args &&... args ) { - setAlignment( Alignment::right ); setMargin( MarginValue::medium ); processArguments( std::forward< Args >( args )... ); } @@ -238,13 +235,6 @@ class TableLayout */ TableLayout & setMargin( MarginValue marginValue ); - /** - * @brief Set the default table alignment - * @param alignment The table alignment - * @return The tableLayout reference - */ - TableLayout & setAlignment( Alignment alignment ); - /** * @brief Check whether we have a line return at the end of the table or not */ @@ -276,11 +266,6 @@ class TableLayout */ integer const & getMarginTitle() const; - /** - * @brief Get the table default aligment - */ - TableLayout::Alignment getDefaultAlignment() const; - private: /** @@ -335,7 +320,6 @@ class TableLayout std::vector< Column > m_columns; bool m_wrapLine = true; - TableLayout::Alignment m_defaultAlignment = TableLayout::Alignment::right; string m_tableTitle; integer m_borderMargin; integer m_columnMargin; diff --git a/src/coreComponents/mesh/DomainPartition.cpp b/src/coreComponents/mesh/DomainPartition.cpp index d1b1bfe0725..a10d3cfa2af 100644 --- a/src/coreComponents/mesh/DomainPartition.cpp +++ b/src/coreComponents/mesh/DomainPartition.cpp @@ -415,8 +415,7 @@ void DomainPartition::outputPartitionInformation() const TableLayout::ColumnParam{"Edges", {"local", "ghost"}}, TableLayout::ColumnParam{"Faces", {"local", "ghost"}}, TableLayout::ColumnParam{"Elems", {"local", "ghost"}} ); - tableLayout.setMargin( TableLayout::MarginValue::large ) - .setAlignment( TableLayout::Alignment::center ); + tableLayout.setMargin( TableLayout::MarginValue::large ); tableLayout.disableLineWrap(); TableData tableData; From 88cf2a3a268399626cacbca6aa8c79abed7d30f0 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 7 Oct 2024 10:07:44 +0200 Subject: [PATCH 190/216] doxygen --- src/coreComponents/common/format/table/TableLayout.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 73d75213ead..5517dd1ada7 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -107,7 +107,7 @@ class TableLayout * @param name The name of the column * @param align The alignment of the column * @param display Flag indicating whether the column is enabled - * @param columns Vector containing subcolumn values + * @param subsColumns Vector containing subcolumn values */ ColumnParam( string_view name, Alignment align, bool display, std::vector< string > subsColumns ) : columnName( name ), alignment( align ), enabled( display ), subColumns( subsColumns ) @@ -236,7 +236,7 @@ class TableLayout TableLayout & setMargin( MarginValue marginValue ); /** - * @brief Check whether we have a line return at the end of the table or not + * @return whether we have a line return at the end of the table or not */ bool isLineWrapEnabled() const; From cd84b82d9994caef767446b665f73b2537fe70a0 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 7 Oct 2024 15:31:07 +0200 Subject: [PATCH 191/216] variable renaming --- .../common/format/table/TableFormatter.cpp | 200 +++++++++--------- .../common/format/table/TableFormatter.hpp | 80 +++---- .../common/format/table/TableLayout.cpp | 18 +- .../common/format/table/TableLayout.hpp | 86 ++++---- .../format/table/unitTests/testTable.cpp | 50 ++--- .../functions/TableFunction.cpp | 2 +- src/coreComponents/mesh/DomainPartition.cpp | 8 +- .../mesh/generators/WellGeneratorBase.cpp | 12 +- .../physicsSolvers/LinearSolverParameters.cpp | 4 +- .../NonlinearSolverParameters.cpp | 4 +- 10 files changed, 232 insertions(+), 232 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 19290b923f9..3ba61701089 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -47,7 +47,7 @@ string TableCSVFormatter::headerToString() const for( std::size_t idxColumn = 0; idxColumn < m_tableLayout.getColumns().size(); ++idxColumn ) { - oss << m_tableLayout.getColumns()[idxColumn].parameter.columnName; + oss << m_tableLayout.getColumns()[idxColumn].column.columnName; if( idxColumn < m_tableLayout.getColumns().size() - 1 ) { oss << separator; @@ -133,19 +133,19 @@ string buildCell( TableLayout::Alignment const alignment, string_view value, siz } /** - * @brief Detect columns who are not displayed from TableLayout and therefore modify columns / tableDataRows vectors - * @param columns Vector built in TableLayout containing all columns with their parameters + * @brief Detect tableColumnsData who are not displayed from TableLayout and therefore modify tableColumnsData / tableDataRows vectors + * @param tableColumnsData Vector built in TableLayout containing all tableColumnsData with their parameters * @param tableDataRows Vector built in TableData containing all rows values */ -void updateVisibleColumns( std::vector< TableLayout::Column > & columns, +void updateVisibleColumns( std::vector< TableLayout::TableColumnData > & tableColumnsData, std::vector< std::vector< string > > & tableDataRows ) { integer idxColumn = 0; - for( auto iterColumn = columns.begin(); iterColumn != columns.end(); ) + for( auto iterColumn = tableColumnsData.begin(); iterColumn != tableColumnsData.end(); ) { - if( !iterColumn->parameter.enabled ) + if( !iterColumn->column.enabled ) { - iterColumn = columns.erase( iterColumn ); + iterColumn = tableColumnsData.erase( iterColumn ); for( auto & row : tableDataRows ) { row.erase( row.begin() + idxColumn ); @@ -166,18 +166,18 @@ TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): string TableTextFormatter::toString() const { std::ostringstream tableOutput; - std::vector< TableLayout::Column > columns( m_tableLayout.getColumns()); + std::vector< TableLayout::TableColumnData > tableColumnsData( m_tableLayout.getColumns()); size_t nbHeaderRows = 0; TableData tableData; string sectionSeparatingLine; string topSeparator; - prepareAndBuildTable( columns, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); + prepareAndBuildTable( tableColumnsData, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); tableOutput << '\n'; outputTitleRow( tableOutput, topSeparator ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - outputHeaderSectionRows( columns, tableOutput, nbHeaderRows, sectionSeparatingLine ); + outputHeaderSectionRows( tableColumnsData, tableOutput, nbHeaderRows, sectionSeparatingLine ); return tableOutput.str(); } @@ -185,20 +185,20 @@ string TableTextFormatter::toString() const template<> string TableTextFormatter::toString< TableData >( TableData const & tableData ) const { - std::vector< TableLayout::Column > columns( m_tableLayout.getColumns()); + std::vector< TableLayout::TableColumnData > tableColumnsData( m_tableLayout.getColumns()); size_t nbHeaderRows = 0; string sectionSeparatingLine; string topSeparator; - prepareAndBuildTable( columns, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); + prepareAndBuildTable( tableColumnsData, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); std::ostringstream tableOutput; - outputTable( tableOutput, columns, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); + outputTable( tableOutput, tableColumnsData, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); return tableOutput.str(); } -void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::Column > & columns, +void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::TableColumnData > & tableColumnsData, TableData const & tableData, size_t & nbHeaderRows, string & sectionSeparatingLine, @@ -207,24 +207,24 @@ void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::Column std::vector< std::vector< string > > tableDataRows( tableData.getTableDataRows()); if( !tableDataRows.empty()) { - updateVisibleColumns( columns, tableDataRows ); - populateColumnsFromTableData( columns, tableDataRows, false ); + updateVisibleColumns( tableColumnsData, tableDataRows ); + populateColumnsFromTableData( tableColumnsData, tableDataRows, false ); } std::vector< std::vector< string > > splitHeaders; - splitAndMergeColumnHeaders( columns, nbHeaderRows, splitHeaders ); + splitAndMergeColumnHeaders( tableColumnsData, nbHeaderRows, splitHeaders ); - for( auto & column : columns ) + for( auto & tableColumnData : tableColumnsData ) { - findAndSetLongestColumnString( column, column.maxStringSize, 0 ); + findAndSetLongestColumnString( tableColumnData, tableColumnData.maxStringSize, 0 ); } - computeTableWidth( columns ); - buildTableSeparators( columns, sectionSeparatingLine, topSeparator ); + computeTableWidth( tableColumnsData ); + buildTableSeparators( tableColumnsData, sectionSeparatingLine, topSeparator ); } void TableTextFormatter::outputTable( std::ostringstream & tableOutput, - std::vector< TableLayout::Column > & columns, + std::vector< TableLayout::TableColumnData > & tableColumnsData, TableData const & tableData, size_t & nbHeaderRows, string_view sectionSeparatingLine, @@ -239,16 +239,16 @@ void TableTextFormatter::outputTable( std::ostringstream & tableOutput, outputTitleRow( tableOutput, topSeparator ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - outputHeaderSectionRows( columns, tableOutput, nbHeaderRows, sectionSeparatingLine ); + outputHeaderSectionRows( tableColumnsData, tableOutput, nbHeaderRows, sectionSeparatingLine ); - outputValuesSectionRows( columns, tableOutput, nbValuesRows, sectionSeparatingLine ); + outputValuesSectionRows( tableColumnsData, tableOutput, nbValuesRows, sectionSeparatingLine ); if( m_tableLayout.isLineWrapEnabled()) { tableOutput << '\n'; } } -void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout::Column > & columns, +void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout::TableColumnData > & tableColumnsData, std::vector< std::vector< string > > const & tableDataRows, bool isSubColumn ) const { @@ -260,42 +260,42 @@ void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout: transpose( tColumnsValues, tableDataRows ); } - for( auto & column : columns ) + for( auto & tableColumnData : tableColumnsData ) { - if( column.subColumn.empty()) + if( tableColumnData.subColumn.empty()) { - column.columnValues = !isSubColumn ? - tColumnsValues[currentColumn++] : tableDataRows[currentColumn++]; + tableColumnData.columnValues = !isSubColumn ? + tColumnsValues[currentColumn++] : tableDataRows[currentColumn++]; } else { auto subColumnStartIdx = tColumnsValues.begin() + currentColumn; std::vector< std::vector< string > > subColumnValues( subColumnStartIdx, - subColumnStartIdx + column.parameter.subColumns.size()); - populateColumnsFromTableData( column.subColumn, subColumnValues, true ); + subColumnStartIdx + tableColumnData.column.subColumns.size()); + populateColumnsFromTableData( tableColumnData.subColumn, subColumnValues, true ); std::vector< std::vector< string > > tSubColumnValues( subColumnValues[0].size(), std::vector< string >( subColumnValues.size()) ); transpose( tSubColumnValues, subColumnValues ); for( const auto & columnValues : tSubColumnValues ) - { // add all subcolumn values in parent column - column.columnValues.insert( column.columnValues.end(), columnValues.begin(), columnValues.end() ); + { // add all subcolumn values in parent tableColumnData + tableColumnData.columnValues.insert( tableColumnData.columnValues.end(), columnValues.begin(), columnValues.end() ); } currentColumn += subColumnValues.size(); } } } -void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::Column > & columns, +void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::TableColumnData > & tableColumnsData, size_t & nbHeaderRows, std::vector< std::vector< string > > & splitHeaders ) const { - splitHeaders.reserve( columns.size() ); + splitHeaders.reserve( tableColumnsData.size() ); - for( auto & column : columns ) + for( auto & tableColumnData : tableColumnsData ) { std::vector< string > splitHeaderParts; - std::istringstream ss( column.parameter.columnName ); + std::istringstream ss( tableColumnData.column.columnName ); string subColumnNames; while( getline( ss, subColumnNames, '\n' )) { @@ -304,11 +304,11 @@ void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::C splitHeaders.push_back( splitHeaderParts ); - if( !column.subColumn.empty()) + if( !tableColumnData.subColumn.empty()) { std::vector< std::vector< string > > splitSubColHeaders; size_t nbHeaderSubColRows = 0; - splitAndMergeColumnHeaders( column.subColumn, nbHeaderSubColRows, splitSubColHeaders ); + splitAndMergeColumnHeaders( tableColumnData.subColumn, nbHeaderSubColRows, splitSubColHeaders ); } } @@ -324,29 +324,29 @@ void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::C { headerParts.resize( nbHeaderRows, " " ); } - columns[&headerParts - &splitHeaders[0]].parameter.splitColumnNames = headerParts; + tableColumnsData[&headerParts - &splitHeaders[0]].column.splitColumnNames = headerParts; } } -void TableTextFormatter::findAndSetLongestColumnString( TableLayout::Column & column, +void TableTextFormatter::findAndSetLongestColumnString( TableLayout::TableColumnData & tableColumnData, std::vector< string > & maxStringSize, integer const idxMaxString ) const { string maxStringColumn; { // header case - auto const maxStringSizeHeader = *std::max_element( column.parameter.splitColumnNames.begin(), - column.parameter.splitColumnNames.end(), + auto const maxStringSizeHeader = *std::max_element( tableColumnData.column.splitColumnNames.begin(), + tableColumnData.column.splitColumnNames.end(), []( const auto & a, const auto & b ) {return a.size() < b.size();} ); maxStringColumn = maxStringSizeHeader; maxStringSize.push_back( maxStringSizeHeader ); } { // values case - if( column.subColumn.empty() && !column.columnValues.empty()) + if( tableColumnData.subColumn.empty() && !tableColumnData.columnValues.empty()) { - auto const maxStringSizeCell = *std::max_element( column.columnValues.begin(), - column.columnValues.end(), + auto const maxStringSizeCell = *std::max_element( tableColumnData.columnValues.begin(), + tableColumnData.columnValues.end(), []( const auto & a, const auto & b ) {return a.size() < b.size();} ); if( maxStringColumn.length() < maxStringSizeCell.length()) { @@ -363,39 +363,39 @@ void TableTextFormatter::findAndSetLongestColumnString( TableLayout::Column & co } { // subcolumn values case - if( !column.subColumn.empty() ) + if( !tableColumnData.subColumn.empty() ) { - column.maxStringSize.clear(); - for( size_t idxSubColumn = 0; idxSubColumn < column.subColumn.size(); ++idxSubColumn ) + tableColumnData.maxStringSize.clear(); + for( size_t idxSubColumn = 0; idxSubColumn < tableColumnData.subColumn.size(); ++idxSubColumn ) { - findAndSetLongestColumnString( column.subColumn[idxSubColumn], - column.maxStringSize, + findAndSetLongestColumnString( tableColumnData.subColumn[idxSubColumn], + tableColumnData.maxStringSize, idxSubColumn ); } } } - if( column.maxStringSize.empty() ) + if( tableColumnData.maxStringSize.empty() ) { - column.maxStringSize.push_back( maxStringColumn ); + tableColumnData.maxStringSize.push_back( maxStringColumn ); } } -void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & columns ) const +void TableTextFormatter::computeTableWidth( std::vector< TableLayout::TableColumnData > & tableColumnsData ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); string const tableTitle = string( m_tableLayout.getTitle() ); - string::size_type const sectionLengthWithSpacing = ( ( columns.size() - 1 ) * columnMargin ) + (borderMargin * 2); + string::size_type const sectionLengthWithSpacing = ( ( tableColumnsData.size() - 1 ) * columnMargin ) + (borderMargin * 2); string::size_type sectionlineLength = sectionLengthWithSpacing; string const spaces = string( m_tableLayout.getColumnMargin(), ' ' ); - { // Compute total length of all columns with margins - sectionlineLength += std::accumulate( columns.begin(), columns.end(), 0, - [&]( auto sum, auto & column ) -> auto + { // Compute total length of all tableColumnsData with margins + sectionlineLength += std::accumulate( tableColumnsData.begin(), tableColumnsData.end(), 0, + [&]( auto sum, auto & tableColumnData ) -> auto { // take into account subColumn - string sumOfString = stringutilities::join( column.maxStringSize, spaces ); + string sumOfString = stringutilities::join( tableColumnData.maxStringSize, spaces ); return static_cast< decltype(sum) >(sum + sumOfString.length()); } ); } @@ -405,25 +405,25 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::Column > & if( sectionlineLength < maxTopLineLength ) { real64 const extraCharacters = maxTopLineLength - sectionlineLength; - increaseColumnsSize( columns, extraCharacters ); + increaseColumnsSize( tableColumnsData, extraCharacters ); } } -void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > & columns, +void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::TableColumnData > & tableColumnsData, real64 const extraCharacters ) const { - real64 const extraCharactersPerColumn = std::floor( (extraCharacters) / columns.size() ); - integer overflowCharacters = extraCharacters - (extraCharactersPerColumn * columns.size() ); - for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) + real64 const extraCharactersPerColumn = std::floor( (extraCharacters) / tableColumnsData.size() ); + integer overflowCharacters = extraCharacters - (extraCharactersPerColumn * tableColumnsData.size() ); + for( std::size_t idxColumn = 0; idxColumn < tableColumnsData.size(); ++idxColumn ) { - if( !columns[idxColumn].subColumn.empty()) + if( !tableColumnsData[idxColumn].subColumn.empty()) { - distributeSpaces( columns[idxColumn].maxStringSize, (int)extraCharactersPerColumn ); - increaseColumnsSize( columns[idxColumn].subColumn, extraCharactersPerColumn ); + distributeSpaces( tableColumnsData[idxColumn].maxStringSize, (int)extraCharactersPerColumn ); + increaseColumnsSize( tableColumnsData[idxColumn].subColumn, extraCharactersPerColumn ); } else { - string & cell = columns[idxColumn].maxStringSize[0]; + string & cell = tableColumnsData[idxColumn].maxStringSize[0]; integer newMaxStringSize = idxColumn == 0 ? extraCharactersPerColumn + cell.size() + overflowCharacters : extraCharactersPerColumn + cell.size(); @@ -432,14 +432,14 @@ void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::Column > } } -void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column > const & columns, +void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::TableColumnData > const & tableColumnsData, string & sectionSeparatingLine, string & topSeparator ) const { std::vector< string > maxStringsPerColumn; - for( auto const & column : columns ) + for( auto const & tableColumnData : tableColumnsData ) { - std::for_each( column.maxStringSize.begin(), column.maxStringSize.end(), [&] ( string maxString ) { + std::for_each( tableColumnData.maxStringSize.begin(), tableColumnData.maxStringSize.end(), [&] ( string maxString ) { maxStringsPerColumn.push_back( string( maxString.length(), m_horizontalLine ) ); } ); } @@ -459,24 +459,24 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::Column topSeparator = GEOS_FMT( "{}{:-<{}}{}", m_horizontalLine, "", topSeparatorLength, m_horizontalLine ); } -void TableTextFormatter::outputSubSection( std::vector< TableLayout::Column > const & columns, +void TableTextFormatter::outputSubSection( std::vector< TableLayout::TableColumnData > const & tableColumnsData, std::ostringstream & tableOutput, integer idxRow ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); - for( size_t idxCol = 0; idxCol< columns.size(); ++idxCol ) + for( size_t idxCol = 0; idxCol< tableColumnsData.size(); ++idxCol ) { - tableOutput << buildCell( columns[idxCol].parameter.alignment, - columns[idxCol].columnValues[idxRow], - columns[idxCol].maxStringSize[0].length() ); - if( idxCol < columns.size() - 1 ) + tableOutput << buildCell( tableColumnsData[idxCol].column.alignment, + tableColumnsData[idxCol].columnValues[idxRow], + tableColumnsData[idxCol].maxStringSize[0].length() ); + if( idxCol < tableColumnsData.size() - 1 ) { tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } } } -void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Column > const & columns, +void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::TableColumnData > const & tableColumnsData, std::ostringstream & tableOutput, size_t const nbRows, string_view sectionSeparatingLine ) const @@ -490,22 +490,22 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu // Append the left border tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, borderMargin ); - for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) + for( std::size_t idxColumn = 0; idxColumn < tableColumnsData.size(); ++idxColumn ) { - auto const & column = columns[idxColumn]; + auto const & tableColumnData = tableColumnsData[idxColumn]; - if( !column.subColumn.empty()) + if( !tableColumnData.subColumn.empty()) { - outputSubSection( column.subColumn, tableOutput, idxRow ); + outputSubSection( tableColumnData.subColumn, tableOutput, idxRow ); } else { - string const cell = column.columnValues.at( idxRow ); - string const cellSize = stringutilities::join( column.maxStringSize, spaces ); - tableOutput << buildCell( column.parameter.alignment, cell, cellSize.length()); + string const cell = tableColumnData.columnValues.at( idxRow ); + string const cellSize = stringutilities::join( tableColumnData.maxStringSize, spaces ); + tableOutput << buildCell( tableColumnData.column.alignment, cell, cellSize.length()); } - if( idxColumn < columns.size() - 1 ) + if( idxColumn < tableColumnsData.size() - 1 ) { tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } @@ -541,7 +541,7 @@ void TableTextFormatter::outputTitleRow( std::ostringstream & tableOutput, } } -void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Column > const & columns, +void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::TableColumnData > const & tableColumnsData, std::ostringstream & tableOutput, size_t const nbRows, string_view sectionSeparatingLine ) const @@ -556,20 +556,20 @@ void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Colu // Append the left border tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, borderMargin ); - for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) + for( std::size_t idxColumn = 0; idxColumn < tableColumnsData.size(); ++idxColumn ) { - auto const & column = columns[idxColumn]; - string cell = column.parameter.splitColumnNames.at( idxRow ); - string cellSize = stringutilities::join( column.maxStringSize, spaces ); - tableOutput << buildCell( column.parameter.alignment, cell, cellSize.length()); + auto const & tableColumnData = tableColumnsData[idxColumn]; + string cell = tableColumnData.column.splitColumnNames.at( idxRow ); + string cellSize = stringutilities::join( tableColumnData.maxStringSize, spaces ); + tableOutput << buildCell( tableColumnData.column.alignment, cell, cellSize.length()); - // Add space between columns - if( idxColumn < columns.size() - 1 ) + // Add space between tableColumnsData + if( idxColumn < tableColumnsData.size() - 1 ) { tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } - if( !column.subColumn.empty()) + if( !tableColumnData.subColumn.empty()) { containSubColumn = true; } @@ -586,17 +586,17 @@ void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Colu // Check and build subrow header if( containSubColumn ) { - std::vector< TableLayout::Column > rowSubColumns; + std::vector< TableLayout::TableColumnData > rowSubColumns; - for( auto const & column : columns ) + for( auto const & tableColumnData : tableColumnsData ) { - if( column.subColumn.empty()) + if( tableColumnData.subColumn.empty()) { - rowSubColumns.push_back( {TableLayout::ColumnParam{""}, {}, column.maxStringSize, {}} ); + rowSubColumns.push_back( {TableLayout::Column{""}, {}, tableColumnData.maxStringSize, {}} ); } else { - rowSubColumns.insert( rowSubColumns.end(), column.subColumn.begin(), column.subColumn.end()); + rowSubColumns.insert( rowSubColumns.end(), tableColumnData.subColumn.begin(), tableColumnData.subColumn.end()); } } outputHeaderSectionRows( rowSubColumns, tableOutput, 1, sectionSeparatingLine ); diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index d9e9099d0ce..58ca16a3ae8 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -41,7 +41,7 @@ class TableFormatter /** * @brief Construct a new Table Formatter from a tableLayout - * @param tableLayout Contain all column names and optionnaly the table title + * @param tableLayout Contain all tableColumnData names and optionnaly the table title */ TableFormatter( TableLayout const & tableLayout ); @@ -67,7 +67,7 @@ class TableCSVFormatter : public TableFormatter /** * @brief Construct a new Table Formatter from a tableLayout - * @param tableLayout Contain all column names and optionnaly the table title + * @param tableLayout Contain all tableColumnData names and optionnaly the table title */ TableCSVFormatter( TableLayout const & tableLayout ); @@ -77,7 +77,7 @@ class TableCSVFormatter : public TableFormatter virtual ~TableCSVFormatter() = default; /** - * @return The string with all column names. + * @return The string with all tableColumnData names. */ string headerToString() const; @@ -124,7 +124,7 @@ class TableTextFormatter : public TableFormatter /** * @brief Construct a new TableFormatter from a tableLayout - * @param tableLayout Contain all column names and optionnaly the table title + * @param tableLayout Contain all tableColumnData names and optionnaly the table title */ TableTextFormatter( TableLayout const & tableLayout ); @@ -156,15 +156,15 @@ class TableTextFormatter : public TableFormatter static constexpr char m_horizontalLine = '-'; /** - * @brief Prepare all the columns with the appropriate values and formatting separator - * @param columns The vector containg all columns. Each column contains its own + * @brief Prepare all the tableColumnsData with the appropriate values and formatting separator + * @param tableColumnsData The vector containg all tableColumnsData . Each tableColumnData contains its own * parameters (such as name, alignment, etc.) and column values. * @param tableData Vector containing all rows filled with values - * @param nbHeaderRows Number of header rows, which will be calculated based on column headers and their formatting. + * @param nbHeaderRows Number of header rows, which will be calculated based on tableColumnData headers and their formatting. * @param sectionSeparatingLine Separator string used between sections of the table * @param topSeparator The table top separator */ - void prepareAndBuildTable( std::vector< TableLayout::Column > & columns, + void prepareAndBuildTable( std::vector< TableLayout::TableColumnData > & tableColumnsData, TableData const & tableData, size_t & nbHeaderRows, string & sectionSeparatingLine, @@ -172,86 +172,86 @@ class TableTextFormatter : public TableFormatter /** * @brief Displays the complete table * @param tableOutput The output stream - * @param columns Vector containg all columns + * @param tableColumnsData Vector containg all tableColumnsData * @param tableData Vector containing all rows filled with values * @param nbHeaderRows A variable to be calculated which will contain the number of header lines * @param sectionSeparatingLine Separator string used between sections of the table * @param topSeparator The table top separator */ void outputTable( std::ostringstream & tableOutput, - std::vector< TableLayout::Column > & columns, + std::vector< TableLayout::TableColumnData > & tableColumnsData, TableData const & tableData, size_t & nbHeaderRows, string_view sectionSeparatingLine, string_view topSeparator ) const; /** - * @brief Populate all the column values with values extracted from TableData. - * @param columns Vector of columns to populate. + * @brief Populate all the tableColumnData values with values extracted from TableData. + * @param tableColumnsData Vector of tableColumnsData to populate. * @param tableData Vector containing all rows filled with values - * @param isSubColumn Boolean indicating if the current column is a subcolumn + * @param isSubColumn Boolean indicating if the current tableColumnData is a subcolumn */ - void populateColumnsFromTableData( std::vector< TableLayout::Column > & columns, + void populateColumnsFromTableData( std::vector< TableLayout::TableColumnData > & tableColumnsData, std::vector< std::vector< string > > const & tableData, bool isSubColumn ) const; /** * @brief Split all header names by detecting the newline \\n character. and - * set the same vector size for each split header and merge it into columns - * @param columns The vector containg all columns + * set the same vector size for each split header and merge it into tableColumnsData + * @param tableColumnsData The vector containg all tableColumnsData * @param nbHeaderRows Variable which will contain the number of header lines to be displayed - * @param splitHeaders Vector to store the split header names for each column + * @param splitHeaders Vector to store the split header names for each tableColumnData */ - void splitAndMergeColumnHeaders( std::vector< TableLayout::Column > & columns, + void splitAndMergeColumnHeaders( std::vector< TableLayout::TableColumnData > & tableColumnsData, size_t & nbHeaderRows, std::vector< std::vector< string > > & splitHeaders ) const; /** - * @brief For each column find and set the column's longest string - * @param column The column to process. - * @param maxStringSize Store the longest string(s) for each column. - * @param idxColumn The current index of the column + * @brief For each tableColumnData find and set the column's longest string + * @param tableColumnData The tableColumnData to process. + * @param maxStringSize Store the longest string(s) for each tableColumnData. + * @param idxColumn The current index of the tableColumnData * * @note Compares the longest string from the header with the longest string from the column values. * If the column contains subcolumns, it recursively applies the same logic to them */ - void findAndSetLongestColumnString( TableLayout::Column & column, + void findAndSetLongestColumnString( TableLayout::TableColumnData & tableColumnData, std::vector< string > & maxStringSize, integer const idxColumn ) const; /** - * @brief Compute the max table line length, taking into account the length of : title, columns header/values - * Increase the size of the columns if necessary - * @param columns Vector of column containing containing the largest string for each column + * @brief Compute the max table line length, taking into account the length of : title, tableColumnsData header/values + * Increase the size of the tableColumnsData if necessary + * @param tableColumnsData Vector of tableColumnData containing containing the largest string for each tableColumnData */ - void computeTableWidth( std::vector< TableLayout::Column > & columns ) const; + void computeTableWidth( std::vector< TableLayout::TableColumnData > & tableColumnsData ) const; /** - * @brief Increase each column size if the title is larger than all the columns - * @param columns Vector containing all table columns - * @param extraCharacters ExtraCharacters to be distributed between each columns + * @brief Increase each tableColumnData size if the title is larger than all the tableColumnsData + * @param tableColumnsData Vector containing all table tableColumnsData + * @param extraCharacters ExtraCharacters to be distributed between each tableColumnsData */ - void increaseColumnsSize( std::vector< TableLayout::Column > & columns, + void increaseColumnsSize( std::vector< TableLayout::TableColumnData > & tableColumnsData, real64 const extraCharacters ) const; /** - * @brief Builds the table's separating lines based on the content length of the columns. - * @param columns Vector containing all table columns + * @brief Builds the table's separating lines based on the content length of the tableColumnsData . + * @param tableColumnsData Vector containing all table tableColumnsData * @param sectionSeparatingLine Separator string used between sections of the table * @param topSeparator The table top separator */ - void buildTableSeparators( std::vector< TableLayout::Column > const & columns, + void buildTableSeparators( std::vector< TableLayout::TableColumnData > const & tableColumnsData, string & sectionSeparatingLine, string & topSeparator ) const; /** * @brief Output the values rows in the table - * @param columns Vector containing all table columns + * @param tableColumnsData Vector containing all table tableColumnsData * @param tableOutput The output stream * @param nbRows Total number of rows to output. * @param sectionSeparatingLine Separator string used between sections of the table */ - void outputValuesSectionRows( std::vector< TableLayout::Column > const & columns, + void outputValuesSectionRows( std::vector< TableLayout::TableColumnData > const & tableColumnsData, std::ostringstream & tableOutput, size_t const nbRows, string_view sectionSeparatingLine ) const; @@ -265,23 +265,23 @@ class TableTextFormatter : public TableFormatter /** * @brief Output the header rows in the table - * @param columns Vector containing all table columns + * @param tableColumnsData Vector containing all table tableColumnsData * @param tableOutput The output stream * @param nbRows The total number of rows to output. * @param sectionSeparatingLine Separator string used between sections of the table */ - void outputHeaderSectionRows( std::vector< TableLayout::Column > const & columns, + void outputHeaderSectionRows( std::vector< TableLayout::TableColumnData > const & tableColumnsData, std::ostringstream & tableOutput, size_t const nbRows, string_view sectionSeparatingLine ) const; /** * @brief Outputs subcolumns for the given row in the table. - * @param columns Vector containing the subcolumn values + * @param tableColumnsData Vector containing the subcolumn values * @param tableOutput The output stream * @param idxRow Index of the current row in the table */ - void outputSubSection( std::vector< TableLayout::Column > const & columns, + void outputSubSection( std::vector< TableLayout::TableColumnData > const & tableColumnsData, std::ostringstream & tableOutput, integer idxRow ) const; }; diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 94b96594bdb..ad3322eb6a3 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -31,23 +31,23 @@ void TableLayout::addToColumns( const std::vector< string > & columnNames ) void TableLayout::addToColumns( string_view columnName ) { - m_columns.push_back( TableLayout::ColumnParam{ columnName, TableLayout::Alignment::right } ); + m_columns.push_back( TableLayout::Column{ columnName, TableLayout::Alignment::right } ); } -void TableLayout::addToColumns( ColumnParam const & columnParam ) +void TableLayout::addToColumns( Column const & column ) { - if( !columnParam.subColumns.empty()) + if( !column.subColumns.empty()) { - std::vector< TableLayout::Column > subColumns; - for( const auto & subColumnsName : columnParam.subColumns ) + std::vector< TableLayout::TableColumnData > subColumns; + for( const auto & subColumnsName : column.subColumns ) { - subColumns.push_back( TableLayout::Column{ TableLayout::ColumnParam{subColumnsName, columnParam.alignment} } ); + subColumns.push_back( TableLayout::TableColumnData { TableLayout::Column{ subColumnsName, column.alignment } } ); } - m_columns.push_back( TableLayout::Column{ columnParam, subColumns } ); + m_columns.push_back( TableLayout::TableColumnData { column, subColumns } ); } else { - m_columns.push_back( TableLayout::Column{ columnParam } ); + m_columns.push_back( TableLayout::TableColumnData { column } ); } } @@ -88,7 +88,7 @@ void TableLayout::removeSubColumn() } } -std::vector< TableLayout::Column > const & TableLayout::getColumns() const +std::vector< TableLayout::TableColumnData > const & TableLayout::getColumns() const { return m_columns; } diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 5517dd1ada7..e3f56a71a2b 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -51,9 +51,9 @@ class TableLayout enum Section { header, values }; /** - * @brief Structure to set up each colum parameters. + * @brief Structure to set up each colum. */ - struct ColumnParam + struct Column { /// Name for a column string columnName; @@ -67,49 +67,49 @@ class TableLayout std::vector< string > splitColumnNames = {""}; /** - * @brief Construct a ColumnParam object with the specified name + * @brief Construct a Column object with the specified name * @param name The name of the column */ - ColumnParam( string_view name ) + Column( string_view name ) : columnName( name ) {} /** - * @brief Construct a ColumnParam object with the specified name and alignment. + * @brief Construct a Column object with the specified name and alignment. * @param name The name of the column * @param align The alignment of the column */ - ColumnParam( string_view name, Alignment align ) + Column( string_view name, Alignment align ) : columnName( name ), alignment( align ) {} /** - * @brief Construct a ColumnParam object with the specified name and alignment. + * @brief Construct a Column object with the specified name and alignment. * @param name The name of the column * @param subsColumns Vector containing subcolumn values */ - ColumnParam( string_view name, std::vector< string > subsColumns ) + Column( string_view name, std::vector< string > subsColumns ) : columnName( name ), subColumns( subsColumns ) {} /** - * @brief Construct a ColumnParam object with the specified name, alignment, and display flag. + * @brief Construct a Column object with the specified name, alignment, and display flag. * @param name The name of the column * @param align The alignment of the column * @param display Flag indicating whether the column is enabled */ - ColumnParam( string_view name, Alignment align, bool display ) + Column( string_view name, Alignment align, bool display ) : columnName( name ), alignment( align ), enabled( display ) {} /** - * @brief Construct a ColumnParam object with the specified name, alignment, and display flag. + * @brief Construct a Column object with the specified name, alignment, and display flag. * @param name The name of the column * @param align The alignment of the column * @param display Flag indicating whether the column is enabled * @param subsColumns Vector containing subcolumn values */ - ColumnParam( string_view name, Alignment align, bool display, std::vector< string > subsColumns ) + Column( string_view name, Alignment align, bool display, std::vector< string > subsColumns ) : columnName( name ), alignment( align ), enabled( display ), subColumns( subsColumns ) {} }; @@ -118,46 +118,46 @@ class TableLayout * @brief Struct for a column. * Each column contains its own parameters (such as name, alignment, etc.) and column values. */ - struct Column + struct TableColumnData { /// Structure who contains parameters for a column - ColumnParam parameter; + Column column; /// A vector containing all columns values std::vector< string > columnValues; /// The largest string(s) in the column std::vector< string > maxStringSize; /// Vector containing all sub columns subdivison - std::vector< Column > subColumn; + std::vector< TableColumnData > subColumn; /** - * @brief Constructs a Column with the given parameter. - * @param columnParam The parameters for the column. + * @brief Constructs a TableColumnData with the given column. + * @param col The parameters for the column. */ - Column( ColumnParam columnParam ) - : parameter( columnParam ) + TableColumnData ( Column col ) + : column( col ) {} /** - * @brief Constructs a Column with the given parameters. - * @param columnParam The parameters for the column. + * @brief Constructs a TableColumnData with the given parameters. + * @param col The parameters for the column. * @param subColumnInit The subcolumns contained in the colum */ - Column( ColumnParam columnParam, std::vector< Column > subColumnInit ) - : parameter( columnParam ), subColumn( subColumnInit ) + TableColumnData ( Column col, std::vector< TableColumnData > subColumnInit ) + : column( col ), subColumn( subColumnInit ) {} /** - * @brief Constructs a Column with the given parameters. - * @param columnParam The parameters for the column. + * @brief Constructs a TableColumnData with the given parameters. + * @param col The parameters for the column. * @param columnValuesInit The values in the column. * @param maxStringSizeInit The largest string(s) in the column. * @param subColumnInit The sub-columns of the column. */ - Column( ColumnParam columnParam, - std::vector< string > columnValuesInit, - std::vector< string > maxStringSizeInit, - std::vector< Column > subColumnInit ) - : parameter( columnParam ), + TableColumnData ( Column col, + std::vector< string > columnValuesInit, + std::vector< string > maxStringSizeInit, + std::vector< TableColumnData > subColumnInit ) + : column( col ), columnValues( columnValuesInit ), maxStringSize( maxStringSizeInit ), subColumn( subColumnInit ) @@ -170,10 +170,10 @@ class TableLayout /** * @brief Construct a new Table Layout object * @param title The table title - * @param args An initializer_list containing string / columnParam + * @param args An initializer_list containing string / column */ TableLayout( string_view title, - std::initializer_list< std::variant< string, TableLayout::ColumnParam > > args ) + std::initializer_list< std::variant< string, TableLayout::Column > > args ) { setMargin( MarginValue::medium ); setTitle( title ); @@ -183,7 +183,7 @@ class TableLayout /** * @brief Construct a new Table Layout object * @param title The table title - * @param args An initializer_list containing string / columnParam + * @param args An initializer_list containing string / column */ TableLayout( string_view title, std::vector< string > args ) @@ -195,7 +195,7 @@ class TableLayout /** * @brief Construct a new Table Layout object - * @tparam Args Process only string, vector < string > and ColumnParam type + * @tparam Args Process only string, vector < string > and Column type * @param args Variadics to be processed */ template< typename ... Args > @@ -209,7 +209,7 @@ class TableLayout * @return The columns vector */ - std::vector< Column > const & getColumns() const; + std::vector< TableColumnData > const & getColumns() const; /** * @return The table name @@ -236,7 +236,7 @@ class TableLayout TableLayout & setMargin( MarginValue marginValue ); /** - * @return whether we have a line return at the end of the table or not + * @return whether we have a line return at the end of the table or not */ bool isLineWrapEnabled() const; @@ -269,10 +269,10 @@ class TableLayout private: /** - * @brief Add a column to the table given an initializer_list of string & ColumnParam - * @param args An initializer_list containing string / columnParam + * @brief Add a column to the table given an initializer_list of string & TableColumnData + * @param args An initializer_list containing string / column */ - void processArguments( std::initializer_list< std::variant< string, TableLayout::ColumnParam > > args ) + void processArguments( std::initializer_list< std::variant< string, TableLayout::Column > > args ) { for( auto const & arg : args ) { @@ -312,12 +312,12 @@ class TableLayout void addToColumns( string_view columnName ); /** - * @brief Create and add a column to the columns vector given a ColumnParam - * @param columnParam Vector containing addition information on the column + * @brief Create and add a column to the columns vector given a Column + * @param column Vector containing addition information on the column */ - void addToColumns( ColumnParam const & columnParam ); + void addToColumns( Column const & column ); - std::vector< Column > m_columns; + std::vector< TableColumnData > m_columns; bool m_wrapLine = true; string m_tableTitle; diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index 2b6ca853e96..089378b3ddc 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -91,12 +91,12 @@ TEST( testTable, tableClassic ) TEST( testTable, tableColumnParamClassic ) { - TableLayout tableLayout( TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::right} ); + TableLayout tableLayout( TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::Column{{"CoordX"}, TableLayout::Alignment::left}, + TableLayout::Column{{"C"}, TableLayout::Alignment::left}, + TableLayout::Column{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::Column{{"Prev\nelement"}, TableLayout::Alignment::right}, + TableLayout::Column{{"Next\nelement"}, TableLayout::Alignment::right} ); string const title = "InternalWellGenerator well_injector1"; tableLayout.setTitle( title ); @@ -120,12 +120,12 @@ TEST( testTable, tableColumnParamClassic ) TEST( testTable, tableHiddenColumn ) { - TableLayout tableLayout( TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left, false}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center, false} ); + TableLayout tableLayout( TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::Column{{"CoordX"}, TableLayout::Alignment::right}, + TableLayout::Column{{"C"}, TableLayout::Alignment::center}, + TableLayout::Column{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::Column{{"Prev\nelement"}, TableLayout::Alignment::left, false}, + TableLayout::Column{{"Next\nelement"}, TableLayout::Alignment::center, false} ); string const title = "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis"; tableLayout.setTitle( title ); @@ -147,7 +147,7 @@ TEST( testTable, tableHiddenColumn ) TEST( testTable, tableUniqueColumn ) { - TableLayout tableLayout( TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center} ); + TableLayout tableLayout( TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center} ); string const title = "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis"; tableLayout.setTitle( title ); @@ -169,12 +169,12 @@ TEST( testTable, tableUniqueColumn ) TEST( testTable, tableEmptyTitle ) { - TableLayout tableLayout( TableLayout::ColumnParam{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::ColumnParam{{"C"}, TableLayout::Alignment::center}, - TableLayout::ColumnParam{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::left}, - TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::center} ); + TableLayout tableLayout( TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::Column{{"CoordX"}, TableLayout::Alignment::right}, + TableLayout::Column{{"C"}, TableLayout::Alignment::center}, + TableLayout::Column{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::Column{{"Prev\nelement"}, TableLayout::Alignment::left}, + TableLayout::Column{{"Next\nelement"}, TableLayout::Alignment::center} ); TableData tableData; tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); @@ -233,7 +233,7 @@ TEST( testTable, layoutTable ) { string filename = "fluid1_phaseModel1_PhillipsBrineDensity_table"; string log = GEOS_FMT( "The {} PVT table exceeding 500 rows.\nTo visualize the tables, go to the generated csv \n", filename ); - TableLayout tableLayoutInfos( {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}} ); + TableLayout tableLayoutInfos( {TableLayout::Column{{log}, TableLayout::Alignment::left}} ); tableLayoutInfos.setTitle( filename ); TableTextFormatter const tableLog( tableLayoutInfos ); @@ -252,9 +252,9 @@ TEST( testTable, subColumns ) { TableLayout tableLayout( " ", "Column1", - TableLayout::ColumnParam{"Nodes ", TableLayout::Alignment::right, true, {"Locales", "Ghost", "Active"}}, + TableLayout::Column{"Nodes ", TableLayout::Alignment::right, true, {"Locales", "Ghost", "Active"}}, "Column3", - TableLayout::ColumnParam{"Column4 ", TableLayout::Alignment::right, true, {"Locales", "Ghost"}}, + TableLayout::Column{"Column4 ", TableLayout::Alignment::right, true, {"Locales", "Ghost"}}, "Column5" ); TableData tableData; @@ -281,10 +281,10 @@ TEST( testTable, variadicTest ) { TableLayout const layoutTest( "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis nascetur ridiculus mus", { "Rank", - TableLayout::ColumnParam{"Nodes", TableLayout::Alignment::center, true, {"local", "ghost"}}, + TableLayout::Column{"Nodes", TableLayout::Alignment::center, true, {"local", "ghost"}}, "Edge", - TableLayout::ColumnParam{"Faces", TableLayout::Alignment::center, true, {"local", "ghost"}}, - TableLayout::ColumnParam{"Elems", TableLayout::Alignment::center, true, {"local", "ghost"}} } ); + TableLayout::Column{"Faces", TableLayout::Alignment::center, true, {"local", "ghost"}}, + TableLayout::Column{"Elems", TableLayout::Alignment::center, true, {"local", "ghost"}} } ); TableData data; data.addRow( "min(local/total)", 1, 2, 3, 4, 5, 6, 7 ); diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index d2c5d187ac6..e1b4946ae6f 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -363,7 +363,7 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl else { string log = GEOS_FMT( "The {} PVT table exceeding 500 rows.\nTo visualize the tables, go to the generated csv \n", filename ); - TableLayout const tableLayoutInfos( filename, {TableLayout::ColumnParam{{log}, TableLayout::Alignment::left}} ); + TableLayout const tableLayoutInfos( filename, {TableLayout::Column{{log}, TableLayout::Alignment::left}} ); TableTextFormatter const tableLog( tableLayoutInfos ); logOutput = tableLog.toString(); } diff --git a/src/coreComponents/mesh/DomainPartition.cpp b/src/coreComponents/mesh/DomainPartition.cpp index a10d3cfa2af..5746276b77d 100644 --- a/src/coreComponents/mesh/DomainPartition.cpp +++ b/src/coreComponents/mesh/DomainPartition.cpp @@ -411,10 +411,10 @@ void DomainPartition::outputPartitionInformation() const GEOS_LOG_RANK_0( " MeshBody: " + meshBody.getName() + " MeshLevel: " + meshLevel.getName() + "\n" ); TableLayout tableLayout( "Rank", - TableLayout::ColumnParam{"Nodes", {"local", "ghost"}}, - TableLayout::ColumnParam{"Edges", {"local", "ghost"}}, - TableLayout::ColumnParam{"Faces", {"local", "ghost"}}, - TableLayout::ColumnParam{"Elems", {"local", "ghost"}} ); + TableLayout::Column{"Nodes", {"local", "ghost"}}, + TableLayout::Column{"Edges", {"local", "ghost"}}, + TableLayout::Column{"Faces", {"local", "ghost"}}, + TableLayout::Column{"Elems", {"local", "ghost"}} ); tableLayout.setMargin( TableLayout::MarginValue::large ); tableLayout.disableLineWrap(); diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 45d53391f6b..4b02392889c 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -552,12 +552,12 @@ void WellGeneratorBase::logInternalWell() const string const wellTitle = GEOS_FMT( "Well '{}' Element Table", getName() ); TableLayout tableWellLayout = TableLayout( - TableLayout::ColumnParam{"Element no.", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"CoordX", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"CoordY", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"CoordZ", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"Prev\nElement", TableLayout::Alignment::right}, - TableLayout::ColumnParam{"Next\nElement", TableLayout::Alignment::right} ); + TableLayout::Column{"Element no.", TableLayout::Alignment::right}, + TableLayout::Column{"CoordX", TableLayout::Alignment::right}, + TableLayout::Column{"CoordY", TableLayout::Alignment::right}, + TableLayout::Column{"CoordZ", TableLayout::Alignment::right}, + TableLayout::Column{"Prev\nElement", TableLayout::Alignment::right}, + TableLayout::Column{"Next\nElement", TableLayout::Alignment::right} ); tableWellLayout.setTitle( wellTitle ); TableTextFormatter const tableFormatter( tableWellLayout ); diff --git a/src/coreComponents/physicsSolvers/LinearSolverParameters.cpp b/src/coreComponents/physicsSolvers/LinearSolverParameters.cpp index c08f7a65ff9..1867dbe6302 100644 --- a/src/coreComponents/physicsSolvers/LinearSolverParameters.cpp +++ b/src/coreComponents/physicsSolvers/LinearSolverParameters.cpp @@ -342,8 +342,8 @@ void LinearSolverParametersInput::print() } } TableLayout tableLayout = TableLayout( - TableLayout::ColumnParam{"Parameter", TableLayout::Alignment::left}, - TableLayout::ColumnParam{"Value", TableLayout::Alignment::left} + TableLayout::Column{"Parameter", TableLayout::Alignment::left}, + TableLayout::Column{"Value", TableLayout::Alignment::left} ); tableLayout.setTitle( GEOS_FMT( "{}: linear solver", getParent().getName() ) ); TableTextFormatter const tableFormatter( tableLayout ); diff --git a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp index e1f880103ee..c3949b70912 100644 --- a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp +++ b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp @@ -236,8 +236,8 @@ void NonlinearSolverParameters::print() const tableData.addRow( "Subcycling", m_subcyclingOption ); } TableLayout tableLayout = TableLayout( - TableLayout::ColumnParam{"Parameter", TableLayout::Alignment::left}, - TableLayout::ColumnParam{"Value", TableLayout::Alignment::left} + TableLayout::Column{"Parameter", TableLayout::Alignment::left}, + TableLayout::Column{"Value", TableLayout::Alignment::left} ); tableLayout.setTitle( GEOS_FMT( "{}: nonlinear solver", getParent().getName() )); TableTextFormatter const tableFormatter( tableLayout ); From 169ffc823ad93c1a7b9f5372478e631837a87e8f Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 7 Oct 2024 17:03:46 +0200 Subject: [PATCH 192/216] adding a way to set up alignment for header and values --- .../common/format/table/TableFormatter.cpp | 12 ++-- .../common/format/table/TableLayout.cpp | 24 +++++-- .../common/format/table/TableLayout.hpp | 54 +++++++++++----- .../format/table/unitTests/testTable.cpp | 64 ++++++++++--------- .../mesh/generators/WellGeneratorBase.cpp | 14 ++-- 5 files changed, 104 insertions(+), 64 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 3ba61701089..fae1335cf2a 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -115,7 +115,7 @@ void transpose( std::vector< std::vector< string > > & dest, std::vector< std::v } /** - * @brief Build cell given an alignment, a value and spaces + * @brief Build cell given an alignment, a value and spaces * @param alignment The aligment of cell value * @param value The cell value * @param spaces The number of spaces in the cell @@ -466,7 +466,7 @@ void TableTextFormatter::outputSubSection( std::vector< TableLayout::TableColumn integer const columnMargin = m_tableLayout.getColumnMargin(); for( size_t idxCol = 0; idxCol< tableColumnsData.size(); ++idxCol ) { - tableOutput << buildCell( tableColumnsData[idxCol].column.alignment, + tableOutput << buildCell( tableColumnsData[idxCol].column.alignmentSettings.valueAlignment, tableColumnsData[idxCol].columnValues[idxRow], tableColumnsData[idxCol].maxStringSize[0].length() ); if( idxCol < tableColumnsData.size() - 1 ) @@ -502,7 +502,9 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Tabl { string const cell = tableColumnData.columnValues.at( idxRow ); string const cellSize = stringutilities::join( tableColumnData.maxStringSize, spaces ); - tableOutput << buildCell( tableColumnData.column.alignment, cell, cellSize.length()); + tableOutput << buildCell( tableColumnData.column.alignmentSettings.valueAlignment, + cell, + cellSize.length()); } if( idxColumn < tableColumnsData.size() - 1 ) @@ -561,7 +563,9 @@ void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Tabl auto const & tableColumnData = tableColumnsData[idxColumn]; string cell = tableColumnData.column.splitColumnNames.at( idxRow ); string cellSize = stringutilities::join( tableColumnData.maxStringSize, spaces ); - tableOutput << buildCell( tableColumnData.column.alignment, cell, cellSize.length()); + tableOutput << buildCell( tableColumnData.column.alignmentSettings.headerAlignment, + cell, + cellSize.length()); // Add space between tableColumnsData if( idxColumn < tableColumnsData.size() - 1 ) diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index ad3322eb6a3..d4d571e736b 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -31,7 +31,7 @@ void TableLayout::addToColumns( const std::vector< string > & columnNames ) void TableLayout::addToColumns( string_view columnName ) { - m_columns.push_back( TableLayout::Column{ columnName, TableLayout::Alignment::right } ); + m_tableColumnsData.push_back( TableLayout::Column{ columnName } ); } void TableLayout::addToColumns( Column const & column ) @@ -41,13 +41,16 @@ void TableLayout::addToColumns( Column const & column ) std::vector< TableLayout::TableColumnData > subColumns; for( const auto & subColumnsName : column.subColumns ) { - subColumns.push_back( TableLayout::TableColumnData { TableLayout::Column{ subColumnsName, column.alignment } } ); + subColumns.push_back( + TableLayout::TableColumnData { + TableLayout::Column{ subColumnsName, column.alignmentSettings.headerAlignment } + } ); } - m_columns.push_back( TableLayout::TableColumnData { column, subColumns } ); + m_tableColumnsData.push_back( TableLayout::TableColumnData { column, subColumns } ); } else { - m_columns.push_back( TableLayout::TableColumnData { column } ); + m_tableColumnsData.push_back( TableLayout::TableColumnData { column } ); } } @@ -72,6 +75,15 @@ TableLayout & TableLayout::setMargin( MarginValue marginValue ) return *this; } +TableLayout & TableLayout::setValuesAlignment( TableLayout::Alignment alignment ) +{ + for( auto & tableColumnData : m_tableColumnsData ) + { + tableColumnData.column.alignmentSettings.valueAlignment = alignment; + } + return *this; +} + bool TableLayout::isLineWrapEnabled() const { return m_wrapLine; @@ -79,7 +91,7 @@ bool TableLayout::isLineWrapEnabled() const void TableLayout::removeSubColumn() { - for( auto & column : m_columns ) + for( auto & column : m_tableColumnsData ) { if( !column.subColumn.empty() ) { @@ -90,7 +102,7 @@ void TableLayout::removeSubColumn() std::vector< TableLayout::TableColumnData > const & TableLayout::getColumns() const { - return m_columns; + return m_tableColumnsData; } string_view TableLayout::getTitle() const diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index e3f56a71a2b..246767ae5ab 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -50,6 +50,17 @@ class TableLayout */ enum Section { header, values }; + /** + * @brief Structure to set up values alignment for each colum. + */ + struct ColumnAlignment + { + /// Alignment for column name. By default aligned to center + Alignment headerAlignment = Alignment::center; + /// Alignment for column values. By default aligned to right side + Alignment valueAlignment = Alignment::right; + }; + /** * @brief Structure to set up each colum. */ @@ -57,8 +68,8 @@ class TableLayout { /// Name for a column string columnName; - /// Alignment for a column. By default aligned to the right side - Alignment alignment = Alignment::right; + /// Alignment for column name. By default aligned to center + ColumnAlignment alignmentSettings; /// A boolean to display a colummn bool enabled = true; /// Vector containing sub columns name @@ -75,16 +86,16 @@ class TableLayout {} /** - * @brief Construct a Column object with the specified name and alignment. + * @brief Construct a Column object with the specified name and alignments. * @param name The name of the column - * @param align The alignment of the column + * @param headerAlign The column name alignment */ - Column( string_view name, Alignment align ) - : columnName( name ), alignment( align ) + Column( string_view name, Alignment headerAlign ) + : columnName( name ), alignmentSettings( {headerAlign, Alignment::right} ) {} /** - * @brief Construct a Column object with the specified name and alignment. + * @brief Construct a Column object with the specified name and alignments. * @param name The name of the column * @param subsColumns Vector containing subcolumn values */ @@ -93,24 +104,29 @@ class TableLayout {} /** - * @brief Construct a Column object with the specified name, alignment, and display flag. + * @brief Construct a Column object with the specified name, alignments, and display flag. * @param name The name of the column - * @param align The alignment of the column + * @param headerAlign The column name alignment * @param display Flag indicating whether the column is enabled */ - Column( string_view name, Alignment align, bool display ) - : columnName( name ), alignment( align ), enabled( display ) + Column( string_view name, Alignment headerAlign, bool display ) + : columnName( name ), + alignmentSettings( {headerAlign, Alignment::right} ), + enabled( display ) {} /** - * @brief Construct a Column object with the specified name, alignment, and display flag. + * @brief Construct a Column object with the specified name, alignments, and display flag. * @param name The name of the column - * @param align The alignment of the column + * @param headerAlign The column name alignment * @param display Flag indicating whether the column is enabled * @param subsColumns Vector containing subcolumn values */ - Column( string_view name, Alignment align, bool display, std::vector< string > subsColumns ) - : columnName( name ), alignment( align ), enabled( display ), subColumns( subsColumns ) + Column( string_view name, Alignment headerAlign, bool display, std::vector< string > subsColumns ) + : columnName( name ), + alignmentSettings( {headerAlign, Alignment::right} ), + enabled( display ), + subColumns( subsColumns ) {} }; @@ -235,6 +251,12 @@ class TableLayout */ TableLayout & setMargin( MarginValue marginValue ); + /** + * @brief Set the column values alignment + * @param alignment column values alignment + */ + TableLayout & setValuesAlignment( TableLayout::Alignment alignment ); + /** * @return whether we have a line return at the end of the table or not */ @@ -317,7 +339,7 @@ class TableLayout */ void addToColumns( Column const & column ); - std::vector< TableColumnData > m_columns; + std::vector< TableColumnData > m_tableColumnsData; bool m_wrapLine = true; string m_tableTitle; diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index 089378b3ddc..e1d4a3dd6e2 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -47,10 +47,10 @@ TEST( testTable, tableEmptyRow ) "\n-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n" "| InternalWellGenerator well_injector1 |\n" "-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n" - "| Well | CordX | CoordZ | Prev | Next |\n" - "| element no. | | | element | element |\n" - "| PV weighted | | | | |\n" - "| bar | | | | |\n" + "| Well | CordX | CoordZ | Prev | Next |\n" + "| element no. | | | element | element |\n" + "| PV weighted | | | | |\n" + "| bar | | | | |\n" "-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n" "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" "| | | | | |\n" @@ -79,7 +79,7 @@ TEST( testTable, tableClassic ) "\n-----------------------------------------------------------------------------------------------------------------------------------------------------------\n" "| InternalWellGenerator well_injector1 |\n" "-----------------------------------------------------------------------------------------------------------------------------------------------------------\n" - "| Duis fringilla, ligula sed porta fringilla, | CordX | CoordZ | Prev | Next |\n" + "| Duis fringilla, ligula sed porta fringilla, | CordX | CoordZ | Prev | Next |\n" "| ligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante | | | element | element |\n" "-----------------------------------------------------------------------------------------------------------------------------------------------------------\n" "| value1 | [30.21543] | 3.0 | 54 | 0 |\n" @@ -89,7 +89,7 @@ TEST( testTable, tableClassic ) ); } -TEST( testTable, tableColumnParamClassic ) +TEST( testTable, tableColumnParamClassic ) //TODO { TableLayout tableLayout( TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center}, TableLayout::Column{{"CoordX"}, TableLayout::Alignment::left}, @@ -97,6 +97,7 @@ TEST( testTable, tableColumnParamClassic ) TableLayout::Column{{"CoordZ"}, TableLayout::Alignment::left}, TableLayout::Column{{"Prev\nelement"}, TableLayout::Alignment::right}, TableLayout::Column{{"Next\nelement"}, TableLayout::Alignment::right} ); + tableLayout.setValuesAlignment( TableLayout::Alignment::right ); string const title = "InternalWellGenerator well_injector1"; tableLayout.setTitle( title ); @@ -112,13 +113,13 @@ TEST( testTable, tableColumnParamClassic ) "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" "| | | | | element | element |\n" "-------------------------------------------------------------------------------------------\n" - "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" + "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" "-------------------------------------------------------------------------------------------\n\n" ); } -TEST( testTable, tableHiddenColumn ) +TEST( testTable, tableHiddenColumn ) // TODO { TableLayout tableLayout( TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center}, TableLayout::Column{{"CoordX"}, TableLayout::Alignment::right}, @@ -127,7 +128,7 @@ TEST( testTable, tableHiddenColumn ) TableLayout::Column{{"Prev\nelement"}, TableLayout::Alignment::left, false}, TableLayout::Column{{"Next\nelement"}, TableLayout::Alignment::center, false} ); string const title = "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis"; - tableLayout.setTitle( title ); + tableLayout.setTitle( title ).setValuesAlignment( TableLayout::Alignment::left ); TableData tableData; tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); @@ -140,8 +141,8 @@ TEST( testTable, tableHiddenColumn ) "---------------------------------------------------------------------------------------------------------------\n" "| Cras egestas | CoordX | C | CoordZ |\n" "---------------------------------------------------------------------------------------------------------------\n" - "| value1 | | 3.0 | 3.0129877 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 |\n" + "| value1 | | 3.0 | 3.0129877 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 |\n" "---------------------------------------------------------------------------------------------------------------\n\n" ); } @@ -162,8 +163,8 @@ TEST( testTable, tableUniqueColumn ) "---------------------------------------------------------------------------------------------------------------\n" "| Cras egestas |\n" "---------------------------------------------------------------------------------------------------------------\n" - "| value1 |\n" - "| val1 |\n" + "| value1 |\n" + "| val1 |\n" "---------------------------------------------------------------------------------------------------------------\n\n" ); } @@ -186,8 +187,8 @@ TEST( testTable, tableEmptyTitle ) "| Cras egestas | CoordX | C | CoordZ | Prev | Next |\n" "| | | | | element | element |\n" "-------------------------------------------------------------------------------------------\n" - "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" - "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" + "| value1 | | 3.0 | 3.0129877 | 2 | 1 |\n" + "| val1 | v | [3.045,42.02,89.25] | 3 | 10 | 3 |\n" "-------------------------------------------------------------------------------------------\n\n" ); } @@ -217,10 +218,10 @@ TEST( testTable, table2DTable ) TableLayout tableLayout( tableconverted.headerNames ); //log - TableTextFormatter const tableLog( tableLayout ); - EXPECT_EQ( tableLog.toString( tableconverted.tableData ), + TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableconverted.tableData ), "\n---------------------------------------------------------------------\n" - "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" + "| Viscosity kg*s | Pression = 10000 | Pression = 15000 |\n" "---------------------------------------------------------------------\n" "| Temperature = 300 | 0.03 | 0.02 |\n" "| Temperature = 350 | 0.035 | 0.023333333333333334 |\n" @@ -236,8 +237,8 @@ TEST( testTable, layoutTable ) TableLayout tableLayoutInfos( {TableLayout::Column{{log}, TableLayout::Alignment::left}} ); tableLayoutInfos.setTitle( filename ); - TableTextFormatter const tableLog( tableLayoutInfos ); - EXPECT_EQ( tableLog.toString(), + TableTextFormatter const tableText( tableLayoutInfos ); + EXPECT_EQ( tableText.toString(), "\n-------------------------------------------------------------------------------------\n" "| fluid1_phaseModel1_PhillipsBrineDensity_table |\n" "-------------------------------------------------------------------------------------\n" @@ -261,9 +262,9 @@ TEST( testTable, subColumns ) tableData.addRow( "min", "125", "375,0001", " YES", 2354654, 562, 43.0, 43.0, 562, 5 ); tableData.addRow( "max", "360", "390,1", " YES", 383213213, 712, 48.0, 47.0, 72, 2 ); - TableTextFormatter tableLog( tableLayout ); + TableTextFormatter tableText( tableLayout ); - EXPECT_EQ( tableLog.toString( tableData ), + EXPECT_EQ( tableText.toString( tableData ), "\n--------------------------------------------------------------------------------------------------------\n" "| | Column1 | Nodes | Column3 | Column4 | Column5 |\n" "--------------------------------------------------------------------------------------------------------\n" @@ -286,20 +287,20 @@ TEST( testTable, variadicTest ) TableLayout::Column{"Faces", TableLayout::Alignment::center, true, {"local", "ghost"}}, TableLayout::Column{"Elems", TableLayout::Alignment::center, true, {"local", "ghost"}} } ); - TableData data; - data.addRow( "min(local/total)", 1, 2, 3, 4, 5, 6, 7 ); - data.addRow( "min(local/total)", 1, 2, 3, 4, 5, 6, 7 ); + TableData tableData; + tableData.addRow( "min(local/total)", 1, 2, 3, 4, 5, 6, 7 ); + tableData.addRow( "min(local/total)", 1, 2, 3, 4, 5, 6, 7 ); TableTextFormatter log( layoutTest ); - EXPECT_EQ( log.toString( data ), + EXPECT_EQ( log.toString( tableData ), "\n--------------------------------------------------------------------------------------------------------------------------------------\n" "| Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis nascetur ridiculus mus |\n" "--------------------------------------------------------------------------------------------------------------------------------------\n" - "| Rank | Nodes | Edge | Faces | Elems |\n" + "| Rank | Nodes | Edge | Faces | Elems |\n" "--------------------------------------------------------------------------------------------------------------------------------------\n" "| | local | ghost | | local | ghost | local | ghost |\n" "--------------------------------------------------------------------------------------------------------------------------------------\n" - "| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n" - "| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n" + "| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n" + "| min(local/total) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |\n" "--------------------------------------------------------------------------------------------------------------------------------------\n\n" ); } @@ -314,11 +315,12 @@ TEST( testTable, testLineWrap ) tableData.addRow( "1", "2", "3.0", 3.0129877, 2.0f, 1 ); TableTextFormatter const tableText( tableLayout ); + EXPECT_EQ( tableText.toString( tableData ), "---------------------------------------------------\n" "| title |\n" "---------------------------------------------------\n" - "|Cras egestas|CoordX| C| CoordZ| Prev| Next|\n" + "|Cras egestas|CoordX| C | CoordZ | Prev | Next |\n" "| | | | |element|element|\n" "---------------------------------------------------\n" "| 1| 2|3.0|3.0129877| 2| 1|\n" diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 4b02392889c..6de2150f075 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -551,13 +551,13 @@ void WellGeneratorBase::logInternalWell() const } string const wellTitle = GEOS_FMT( "Well '{}' Element Table", getName() ); - TableLayout tableWellLayout = TableLayout( - TableLayout::Column{"Element no.", TableLayout::Alignment::right}, - TableLayout::Column{"CoordX", TableLayout::Alignment::right}, - TableLayout::Column{"CoordY", TableLayout::Alignment::right}, - TableLayout::Column{"CoordZ", TableLayout::Alignment::right}, - TableLayout::Column{"Prev\nElement", TableLayout::Alignment::right}, - TableLayout::Column{"Next\nElement", TableLayout::Alignment::right} ); + TableLayout tableWellLayout( + "Element no.", + "CoordX", + "CoordY", + "CoordZ", + "Prev\nElement", + "Next\nElement" ); tableWellLayout.setTitle( wellTitle ); TableTextFormatter const tableFormatter( tableWellLayout ); From 16b4e4e26d2353eca81948ebc5dabd8338f29b40 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 8 Oct 2024 09:22:11 +0200 Subject: [PATCH 193/216] missing doc --- src/coreComponents/common/format/table/TableLayout.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 246767ae5ab..f59ed1c95a9 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -254,6 +254,7 @@ class TableLayout /** * @brief Set the column values alignment * @param alignment column values alignment + * @return The tableLayout reference */ TableLayout & setValuesAlignment( TableLayout::Alignment alignment ); From 6583325d0044c22afbf07634cda3e29a14fe53a0 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 17 Oct 2024 09:50:19 +0200 Subject: [PATCH 194/216] update layout constructor --- .../common/format/table/TableLayout.hpp | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index f59ed1c95a9..0abbc096c6c 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -181,6 +181,8 @@ class TableLayout }; + using TableLayoutArgs = std::initializer_list< std::variant< string_view, TableLayout::Column > >; + TableLayout() = default; /** @@ -189,11 +191,14 @@ class TableLayout * @param args An initializer_list containing string / column */ TableLayout( string_view title, - std::initializer_list< std::variant< string, TableLayout::Column > > args ) + std::vector< TableLayout::Column > & columns ) { setMargin( MarginValue::medium ); setTitle( title ); - processArguments( args ); + for( auto const & column :columns ) + { + addToColumns( column ); + } } /** @@ -202,23 +207,36 @@ class TableLayout * @param args An initializer_list containing string / column */ TableLayout( string_view title, - std::vector< string > args ) + TableLayoutArgs args ) { setMargin( MarginValue::medium ); setTitle( title ); - addToColumns( args ); + processArguments( args ); + } + + /** + * @brief Construct a new Table Layout object + * @param title The table title + * @param args An initializer_list containing string / column + */ + + TableLayout( TableLayoutArgs args ) + { + setMargin( MarginValue::medium ); + processArguments( args ); } /** * @brief Construct a new Table Layout object - * @tparam Args Process only string, vector < string > and Column type - * @param args Variadics to be processed + * @param title The table title + * @param args An initializer_list containing string / column */ - template< typename ... Args > - TableLayout( Args &&... args ) + TableLayout( string_view title, + std::vector< string > args ) { setMargin( MarginValue::medium ); - processArguments( std::forward< Args >( args )... ); + setTitle( title ); + addToColumns( args ); } /** @@ -295,7 +313,7 @@ class TableLayout * @brief Add a column to the table given an initializer_list of string & TableColumnData * @param args An initializer_list containing string / column */ - void processArguments( std::initializer_list< std::variant< string, TableLayout::Column > > args ) + void processArguments( TableLayoutArgs args ) { for( auto const & arg : args ) { From 61ffd56e364b877a51ef23379d6af18783315cd2 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 17 Oct 2024 09:59:12 +0200 Subject: [PATCH 195/216] update tableLayout declaration --- .../format/table/unitTests/testTable.cpp | 74 +++++++++---------- .../common/initializeEnvironment.cpp | 10 +-- .../functions/TableFunction.cpp | 4 +- src/coreComponents/mesh/DomainPartition.cpp | 10 +-- .../mesh/generators/WellGeneratorBase.cpp | 16 ++-- .../physicsSolvers/LinearSolverParameters.cpp | 8 +- .../NonlinearSolverParameters.cpp | 9 +-- .../fluidFlow/StencilDataCollection.cpp | 4 +- 8 files changed, 66 insertions(+), 69 deletions(-) diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index e1d4a3dd6e2..4ee152fb3d4 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -27,11 +27,11 @@ using namespace geos; TEST( testTable, tableEmptyRow ) { //table with empty row - TableLayout tableLayout( "Well\nelement no.\nPV weighted\nbar", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement" ); + TableLayout tableLayout( {"Well\nelement no.\nPV weighted\nbar", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"} ); string const title = "InternalWellGenerator well_injector1"; tableLayout.setTitle( title ); @@ -61,11 +61,11 @@ TEST( testTable, tableEmptyRow ) TEST( testTable, tableClassic ) { - TableLayout tableLayout( "Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement" ); + TableLayout tableLayout( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"} ); string const title = "InternalWellGenerator well_injector1"; tableLayout.setTitle( title ); @@ -91,12 +91,12 @@ TEST( testTable, tableClassic ) TEST( testTable, tableColumnParamClassic ) //TODO { - TableLayout tableLayout( TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::Column{{"CoordX"}, TableLayout::Alignment::left}, - TableLayout::Column{{"C"}, TableLayout::Alignment::left}, - TableLayout::Column{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::Column{{"Prev\nelement"}, TableLayout::Alignment::right}, - TableLayout::Column{{"Next\nelement"}, TableLayout::Alignment::right} ); + TableLayout tableLayout( {TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::Column{{"CoordX"}, TableLayout::Alignment::left}, + TableLayout::Column{{"C"}, TableLayout::Alignment::left}, + TableLayout::Column{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::Column{{"Prev\nelement"}, TableLayout::Alignment::right}, + TableLayout::Column{{"Next\nelement"}, TableLayout::Alignment::right}} ); tableLayout.setValuesAlignment( TableLayout::Alignment::right ); string const title = "InternalWellGenerator well_injector1"; tableLayout.setTitle( title ); @@ -121,12 +121,12 @@ TEST( testTable, tableColumnParamClassic ) //TODO TEST( testTable, tableHiddenColumn ) // TODO { - TableLayout tableLayout( TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::Column{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::Column{{"C"}, TableLayout::Alignment::center}, - TableLayout::Column{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::Column{{"Prev\nelement"}, TableLayout::Alignment::left, false}, - TableLayout::Column{{"Next\nelement"}, TableLayout::Alignment::center, false} ); + TableLayout tableLayout( {TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::Column{{"CoordX"}, TableLayout::Alignment::right}, + TableLayout::Column{{"C"}, TableLayout::Alignment::center}, + TableLayout::Column{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::Column{{"Prev\nelement"}, TableLayout::Alignment::left, false}, + TableLayout::Column{{"Next\nelement"}, TableLayout::Alignment::center, false}} ); string const title = "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis"; tableLayout.setTitle( title ).setValuesAlignment( TableLayout::Alignment::left ); @@ -148,7 +148,7 @@ TEST( testTable, tableHiddenColumn ) // TODO TEST( testTable, tableUniqueColumn ) { - TableLayout tableLayout( TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center} ); + TableLayout tableLayout( {TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center}} ); string const title = "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis"; tableLayout.setTitle( title ); @@ -170,12 +170,12 @@ TEST( testTable, tableUniqueColumn ) TEST( testTable, tableEmptyTitle ) { - TableLayout tableLayout( TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center}, - TableLayout::Column{{"CoordX"}, TableLayout::Alignment::right}, - TableLayout::Column{{"C"}, TableLayout::Alignment::center}, - TableLayout::Column{{"CoordZ"}, TableLayout::Alignment::left}, - TableLayout::Column{{"Prev\nelement"}, TableLayout::Alignment::left}, - TableLayout::Column{{"Next\nelement"}, TableLayout::Alignment::center} ); + TableLayout tableLayout( {TableLayout::Column{{"Cras egestas"}, TableLayout::Alignment::center}, + TableLayout::Column{{"CoordX"}, TableLayout::Alignment::right}, + TableLayout::Column{{"C"}, TableLayout::Alignment::center}, + TableLayout::Column{{"CoordZ"}, TableLayout::Alignment::left}, + TableLayout::Column{{"Prev\nelement"}, TableLayout::Alignment::left}, + TableLayout::Column{{"Next\nelement"}, TableLayout::Alignment::center}} ); TableData tableData; tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); @@ -215,7 +215,7 @@ TEST( testTable, table2DTable ) columnFmt ); //format - TableLayout tableLayout( tableconverted.headerNames ); + TableLayout tableLayout( "", tableconverted.headerNames ); //log TableTextFormatter const tableText( tableLayout ); @@ -251,12 +251,12 @@ TEST( testTable, layoutTable ) TEST( testTable, subColumns ) { { - TableLayout tableLayout( " ", - "Column1", - TableLayout::Column{"Nodes ", TableLayout::Alignment::right, true, {"Locales", "Ghost", "Active"}}, - "Column3", - TableLayout::Column{"Column4 ", TableLayout::Alignment::right, true, {"Locales", "Ghost"}}, - "Column5" ); + TableLayout tableLayout( {" ", + "Column1", + TableLayout::Column{"Nodes ", TableLayout::Alignment::right, true, {"Locales", "Ghost", "Active"}}, + "Column3", + TableLayout::Column{"Column4 ", TableLayout::Alignment::right, true, {"Locales", "Ghost"}}, + "Column5"} ); TableData tableData; tableData.addRow( "min", "125", "375,0001", " YES", 2354654, 562, 43.0, 43.0, 562, 5 ); @@ -307,7 +307,7 @@ TEST( testTable, variadicTest ) } TEST( testTable, testLineWrap ) { - TableLayout tableLayout( "Cras egestas", "CoordX", "C", "CoordZ", "Prev\nelement", "Next\nelement" ); + TableLayout tableLayout( {"Cras egestas", "CoordX", "C", "CoordZ", "Prev\nelement", "Next\nelement"} ); tableLayout.setTitle( "title" ).setMargin( TableLayout::MarginValue::tiny ).disableLineWrap(); TableData tableData; diff --git a/src/coreComponents/common/initializeEnvironment.cpp b/src/coreComponents/common/initializeEnvironment.cpp index 17d0d4bfbc0..3f3403163b3 100644 --- a/src/coreComponents/common/initializeEnvironment.cpp +++ b/src/coreComponents/common/initializeEnvironment.cpp @@ -345,11 +345,11 @@ static void addUmpireHighWaterMarks() pushStatsIntoAdiak( allocatorName + " rank max", mark ); } - TableLayout const memoryStatLayout ( "Umpire Memory Pool\n(reserved / % over total)", - "Min over ranks", - "Max over ranks", - "Avg over ranks", - "Sum over ranks" ); + TableLayout const memoryStatLayout ( { "Umpire Memory Pool\n(reserved / % over total)", + "Min over ranks", + "Max over ranks", + "Avg over ranks", + "Sum over ranks" } ); TableTextFormatter const memoryStatLog( memoryStatLayout ); GEOS_LOG_RANK_0( memoryStatLog.toString( tableData )); diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index e1b4946ae6f..16fb8efb135 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -307,7 +307,7 @@ string TableCSVFormatter::toString< TableFunction >( TableFunction const & table units::getDescription( tableFunction.getDimUnit( 0 ) ), units::getDescription( tableFunction.getDimUnit( 1 ) ) ); - TableLayout tableLayout( tableConverted.headerNames ); + TableLayout tableLayout( "", tableConverted.headerNames ); TableCSVFormatter csvFormat( tableLayout ); formatterStream << csvFormat.headerToString() << csvFormat.dataToString( tableConverted.tableData ); @@ -356,7 +356,7 @@ string TableTextFormatter::toString< TableFunction >( TableFunction const & tabl units::getDescription( tableFunction.getDimUnit( 0 ) ), units::getDescription( tableFunction.getDimUnit( 1 ) )); - TableLayout tableLayout( filename, tableConverted.headerNames ); + TableLayout const tableLayout( filename, tableConverted.headerNames ); TableTextFormatter const table2DLog( tableLayout ); logOutput = table2DLog.toString( tableConverted.tableData ); } diff --git a/src/coreComponents/mesh/DomainPartition.cpp b/src/coreComponents/mesh/DomainPartition.cpp index 5746276b77d..ed611c9492e 100644 --- a/src/coreComponents/mesh/DomainPartition.cpp +++ b/src/coreComponents/mesh/DomainPartition.cpp @@ -411,10 +411,10 @@ void DomainPartition::outputPartitionInformation() const GEOS_LOG_RANK_0( " MeshBody: " + meshBody.getName() + " MeshLevel: " + meshLevel.getName() + "\n" ); TableLayout tableLayout( "Rank", - TableLayout::Column{"Nodes", {"local", "ghost"}}, - TableLayout::Column{"Edges", {"local", "ghost"}}, - TableLayout::Column{"Faces", {"local", "ghost"}}, - TableLayout::Column{"Elems", {"local", "ghost"}} ); + {TableLayout::Column{"Nodes", {"local", "ghost"}}, + TableLayout::Column{"Edges", {"local", "ghost"}}, + TableLayout::Column{"Faces", {"local", "ghost"}}, + TableLayout::Column{"Elems", {"local", "ghost"}}} ); tableLayout.setMargin( TableLayout::MarginValue::large ); tableLayout.disableLineWrap(); @@ -460,7 +460,7 @@ void DomainPartition::outputPartitionInformation() const TableTextFormatter tableLog( tableLayout ); GEOS_LOG_RANK_0( tableLog.toString( tableData )); - TableLayout tableLayoutRatio( "Rank", "Nodes ", "Edges ", "Faces ", "Elems " ); + TableLayout tableLayoutRatio( {"Rank", "Nodes ", "Edges ", "Faces ", "Elems "} ); tableLayout.setMargin( TableLayout::MarginValue::large ); TableData tableDataRatio; diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 1a912347b78..9f0d2a851a3 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -552,12 +552,12 @@ void WellGeneratorBase::logInternalWell() const string const wellTitle = GEOS_FMT( "Well '{}' Element Table", getName() ); TableLayout tableWellLayout( - "Element no.", - "CoordX", - "CoordY", - "CoordZ", - "Prev\nElement", - "Next\nElement" ); + {"Element no.", + "CoordX", + "CoordY", + "CoordZ", + "Prev\nElement", + "Next\nElement"} ); tableWellLayout.setTitle( wellTitle ); TableTextFormatter const tableFormatter( tableWellLayout ); @@ -572,8 +572,8 @@ void WellGeneratorBase::logPerforationTable() const tablePerfoData.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); } - TableLayout const tableLayoutPerfo ( {"Perforation no.", "Coordinates", "Well element no."}, - GEOS_FMT( "Well '{}' Perforation Table", getName() ) ); + TableLayout const tableLayoutPerfo ( GEOS_FMT( "Well '{}' Perforation Table", getName()), + { "Perforation no.", "Coordinates", "Well element no." } ); TableTextFormatter const tablePerfoLog( tableLayoutPerfo ); GEOS_LOG_RANK_0( tablePerfoLog.toString( tablePerfoData )); } diff --git a/src/coreComponents/physicsSolvers/LinearSolverParameters.cpp b/src/coreComponents/physicsSolvers/LinearSolverParameters.cpp index 1867dbe6302..5a8746a0510 100644 --- a/src/coreComponents/physicsSolvers/LinearSolverParameters.cpp +++ b/src/coreComponents/physicsSolvers/LinearSolverParameters.cpp @@ -341,11 +341,9 @@ void LinearSolverParametersInput::print() tableData.addRow( "ILU(T) threshold factor", m_parameters.ifact.threshold ); } } - TableLayout tableLayout = TableLayout( - TableLayout::Column{"Parameter", TableLayout::Alignment::left}, - TableLayout::Column{"Value", TableLayout::Alignment::left} - ); - tableLayout.setTitle( GEOS_FMT( "{}: linear solver", getParent().getName() ) ); + TableLayout const tableLayout = TableLayout( GEOS_FMT( "{}: linear solver", getParent().getName() ), + { TableLayout::Column{"Parameter", TableLayout::Alignment::left}, + TableLayout::Column{"Value", TableLayout::Alignment::left} } ); TableTextFormatter const tableFormatter( tableLayout ); GEOS_LOG_RANK_0( tableFormatter.toString( tableData )); } diff --git a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp index c3949b70912..2fab0260705 100644 --- a/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp +++ b/src/coreComponents/physicsSolvers/NonlinearSolverParameters.cpp @@ -235,11 +235,10 @@ void NonlinearSolverParameters::print() const tableData.addRow( "Sequential convergence criterion", m_sequentialConvergenceCriterion ); tableData.addRow( "Subcycling", m_subcyclingOption ); } - TableLayout tableLayout = TableLayout( - TableLayout::Column{"Parameter", TableLayout::Alignment::left}, - TableLayout::Column{"Value", TableLayout::Alignment::left} - ); - tableLayout.setTitle( GEOS_FMT( "{}: nonlinear solver", getParent().getName() )); + TableLayout const tableLayout = TableLayout( GEOS_FMT( "{}: nonlinear solver", getParent().getName() ), + { TableLayout::Column{"Parameter", TableLayout::Alignment::left}, + TableLayout::Column{"Value", TableLayout::Alignment::left} } + ); TableTextFormatter const tableFormatter( tableLayout ); GEOS_LOG_RANK_0( tableFormatter.toString( tableData )); } diff --git a/src/coreComponents/physicsSolvers/fluidFlow/StencilDataCollection.cpp b/src/coreComponents/physicsSolvers/fluidFlow/StencilDataCollection.cpp index 5d7ae1091a8..ba14e8b2ba1 100644 --- a/src/coreComponents/physicsSolvers/fluidFlow/StencilDataCollection.cpp +++ b/src/coreComponents/physicsSolvers/fluidFlow/StencilDataCollection.cpp @@ -236,8 +236,8 @@ string formatKernelDataExtract( arrayView1d< StencilDataCollection::KernelConnec kernelIterator->m_transmissibility[0], kernelIterator->m_transmissibility[1] ); } - TableLayout tableLayout = TableLayout( "regionId A/B", "subRegionId A/B", "elementId A/B", "transmissibilityAB", "transmissibilityBA" ); - tableLayout.setTitle( GEOS_FMT( "Kernel data (real row count = {})", kernelData.size() )); + TableLayout const tableLayout = TableLayout( GEOS_FMT( "Kernel data (real row count = {})", kernelData.size() ), + {"regionId A/B", "subRegionId A/B", "elementId A/B", "transmissibilityAB", "transmissibilityBA"} ); TableTextFormatter const tableFormatter{ tableLayout }; return tableFormatter.toString( tableData ); } From a2a7273f970581b6adb47ca9da26b7a3769968f1 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 17 Oct 2024 11:27:04 +0200 Subject: [PATCH 196/216] renaming, doxygen, small simpl --- .../common/format/table/TableFormatter.cpp | 43 ++++++++---- .../common/format/table/TableFormatter.hpp | 4 +- .../common/format/table/TableLayout.cpp | 4 +- .../common/format/table/TableLayout.hpp | 48 ++++++------- src/coreComponents/schema/schema.xsd | 70 +++++++++++++++++++ 5 files changed, 128 insertions(+), 41 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index fae1335cf2a..6e6018b5604 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -103,7 +103,8 @@ void distributeSpaces( std::vector< string > & vec, int totalSpaces ) } } -void transpose( std::vector< std::vector< string > > & dest, std::vector< std::vector< string > > const & source ) +void transpose( std::vector< std::vector< string > > & dest, + std::vector< std::vector< string > > const & source ) { for( size_t idxRow = 0; idxRow < source.size(); ++idxRow ) { @@ -193,7 +194,7 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) prepareAndBuildTable( tableColumnsData, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); std::ostringstream tableOutput; - outputTable( tableOutput, tableColumnsData, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); + outputTable( tableOutput, tableColumnsData, nbHeaderRows, sectionSeparatingLine, topSeparator ); return tableOutput.str(); } @@ -225,12 +226,11 @@ void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::TableCo void TableTextFormatter::outputTable( std::ostringstream & tableOutput, std::vector< TableLayout::TableColumnData > & tableColumnsData, - TableData const & tableData, size_t & nbHeaderRows, string_view sectionSeparatingLine, string_view topSeparator ) const { - integer const nbValuesRows = tableData.getTableDataRows().size(); + integer const nbValuesRows = tableColumnsData[0].columnValues.size(); if( m_tableLayout.isLineWrapEnabled()) { @@ -269,9 +269,10 @@ void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout: } else { + size_t nbSubColumns = tableColumnData.column.subColumnNames.size(); auto subColumnStartIdx = tColumnsValues.begin() + currentColumn; std::vector< std::vector< string > > subColumnValues( subColumnStartIdx, - subColumnStartIdx + tableColumnData.column.subColumns.size()); + subColumnStartIdx + nbSubColumns ); populateColumnsFromTableData( tableColumnData.subColumn, subColumnValues, true ); std::vector< std::vector< string > > tSubColumnValues( subColumnValues[0].size(), @@ -279,7 +280,9 @@ void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout: transpose( tSubColumnValues, subColumnValues ); for( const auto & columnValues : tSubColumnValues ) { // add all subcolumn values in parent tableColumnData - tableColumnData.columnValues.insert( tableColumnData.columnValues.end(), columnValues.begin(), columnValues.end() ); + tableColumnData.columnValues.insert( tableColumnData.columnValues.end(), + columnValues.begin(), + columnValues.end() ); } currentColumn += subColumnValues.size(); } @@ -337,7 +340,11 @@ void TableTextFormatter::findAndSetLongestColumnString( TableLayout::TableColumn { // header case auto const maxStringSizeHeader = *std::max_element( tableColumnData.column.splitColumnNames.begin(), tableColumnData.column.splitColumnNames.end(), - []( const auto & a, const auto & b ) {return a.size() < b.size();} ); + []( const auto & a, const auto & b ) + { + return a.size() < b.size(); + } ); + maxStringColumn = maxStringSizeHeader; maxStringSize.push_back( maxStringSizeHeader ); } @@ -347,7 +354,11 @@ void TableTextFormatter::findAndSetLongestColumnString( TableLayout::TableColumn { auto const maxStringSizeCell = *std::max_element( tableColumnData.columnValues.begin(), tableColumnData.columnValues.end(), - []( const auto & a, const auto & b ) {return a.size() < b.size();} ); + []( const auto & a, const auto & b ) + { + return a.size() < b.size(); + } ); + if( maxStringColumn.length() < maxStringSizeCell.length()) { maxStringColumn = maxStringSizeCell; @@ -387,7 +398,12 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::TableColum integer const borderMargin = m_tableLayout.getBorderMargin(); string const tableTitle = string( m_tableLayout.getTitle() ); - string::size_type const sectionLengthWithSpacing = ( ( tableColumnsData.size() - 1 ) * columnMargin ) + (borderMargin * 2); + string::size_type numColumns = tableColumnsData.size() - 1; + string::size_type spacing = numColumns * columnMargin; + string::size_type margins = borderMargin * 2; + + string::size_type const sectionLengthWithSpacing = spacing + margins; + string::size_type sectionlineLength = sectionLengthWithSpacing; string const spaces = string( m_tableLayout.getColumnMargin(), ' ' ); @@ -400,7 +416,7 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::TableColum } ); } - string::size_type maxTopLineLength = tableTitle.length() + m_tableLayout.getBorderMargin() * 2; + string::size_type maxTopLineLength = tableTitle.length() + margins; maxTopLineLength = std::max( {maxTopLineLength, sectionlineLength} ); if( sectionlineLength < maxTopLineLength ) { @@ -439,7 +455,8 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::TableCo std::vector< string > maxStringsPerColumn; for( auto const & tableColumnData : tableColumnsData ) { - std::for_each( tableColumnData.maxStringSize.begin(), tableColumnData.maxStringSize.end(), [&] ( string maxString ) { + std::for_each( tableColumnData.maxStringSize.begin(), tableColumnData.maxStringSize.end(), + [&] ( string maxString ) { maxStringsPerColumn.push_back( string( maxString.length(), m_horizontalLine ) ); } ); } @@ -600,7 +617,9 @@ void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Tabl } else { - rowSubColumns.insert( rowSubColumns.end(), tableColumnData.subColumn.begin(), tableColumnData.subColumn.end()); + rowSubColumns.insert( rowSubColumns.end(), + tableColumnData.subColumn.begin(), + tableColumnData.subColumn.end()); } } outputHeaderSectionRows( rowSubColumns, tableOutput, 1, sectionSeparatingLine ); diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 58ca16a3ae8..17536f8f6d5 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -158,7 +158,7 @@ class TableTextFormatter : public TableFormatter /** * @brief Prepare all the tableColumnsData with the appropriate values and formatting separator * @param tableColumnsData The vector containg all tableColumnsData . Each tableColumnData contains its own - * parameters (such as name, alignment, etc.) and column values. + * parameters (such as name, alignment, etc.). * @param tableData Vector containing all rows filled with values * @param nbHeaderRows Number of header rows, which will be calculated based on tableColumnData headers and their formatting. * @param sectionSeparatingLine Separator string used between sections of the table @@ -173,14 +173,12 @@ class TableTextFormatter : public TableFormatter * @brief Displays the complete table * @param tableOutput The output stream * @param tableColumnsData Vector containg all tableColumnsData - * @param tableData Vector containing all rows filled with values * @param nbHeaderRows A variable to be calculated which will contain the number of header lines * @param sectionSeparatingLine Separator string used between sections of the table * @param topSeparator The table top separator */ void outputTable( std::ostringstream & tableOutput, std::vector< TableLayout::TableColumnData > & tableColumnsData, - TableData const & tableData, size_t & nbHeaderRows, string_view sectionSeparatingLine, string_view topSeparator ) const; diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index d4d571e736b..39594f225cd 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -36,10 +36,10 @@ void TableLayout::addToColumns( string_view columnName ) void TableLayout::addToColumns( Column const & column ) { - if( !column.subColumns.empty()) + if( !column.subColumnNames.empty()) { std::vector< TableLayout::TableColumnData > subColumns; - for( const auto & subColumnsName : column.subColumns ) + for( const auto & subColumnsName : column.subColumnNames ) { subColumns.push_back( TableLayout::TableColumnData { diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 0abbc096c6c..ddbe32372d6 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -33,6 +33,7 @@ class TableLayout { public: + /// Type of aligment for a column enum Alignment { right, left, center }; @@ -55,7 +56,7 @@ class TableLayout */ struct ColumnAlignment { - /// Alignment for column name. By default aligned to center + /// Alignment for column name. By default aligned to center Alignment headerAlignment = Alignment::center; /// Alignment for column values. By default aligned to right side Alignment valueAlignment = Alignment::right; @@ -73,21 +74,21 @@ class TableLayout /// A boolean to display a colummn bool enabled = true; /// Vector containing sub columns name - std::vector< string > subColumns; + std::vector< string > subColumnNames; /// Vector containing substring column name delimited by "\n" std::vector< string > splitColumnNames = {""}; /** - * @brief Construct a Column object with the specified name - * @param name The name of the column + * @brief Construct a Column object with the given parameters + * @param name The Column name */ Column( string_view name ) : columnName( name ) {} /** - * @brief Construct a Column object with the specified name and alignments. - * @param name The name of the column + * @brief Construct a Column object with the given parameters + * @param name The Column name * @param headerAlign The column name alignment */ Column( string_view name, Alignment headerAlign ) @@ -95,17 +96,17 @@ class TableLayout {} /** - * @brief Construct a Column object with the specified name and alignments. - * @param name The name of the column - * @param subsColumns Vector containing subcolumn values + * @brief Construct a Column object with the given parameters + * @param name The Column name + * @param subColumnNames Vector containing subcolumn names */ - Column( string_view name, std::vector< string > subsColumns ) - : columnName( name ), subColumns( subsColumns ) + Column( string_view name, std::vector< string > && subColumnNamesInit ) + : columnName( name ), subColumnNames( subColumnNamesInit ) {} /** - * @brief Construct a Column object with the specified name, alignments, and display flag. - * @param name The name of the column + * @brief Construct a Column object with the given parameters + * @param name The Column name * @param headerAlign The column name alignment * @param display Flag indicating whether the column is enabled */ @@ -116,29 +117,29 @@ class TableLayout {} /** - * @brief Construct a Column object with the specified name, alignments, and display flag. - * @param name The name of the column + * @brief Construct a Column object with the given parameters + * @param name The Column name * @param headerAlign The column name alignment * @param display Flag indicating whether the column is enabled - * @param subsColumns Vector containing subcolumn values + * @param subsColumns Vector containing subcolumn names */ - Column( string_view name, Alignment headerAlign, bool display, std::vector< string > subsColumns ) + Column( string_view name, Alignment headerAlign, bool display, std::vector< string > && subColumnNamesInit ) : columnName( name ), alignmentSettings( {headerAlign, Alignment::right} ), enabled( display ), - subColumns( subsColumns ) + subColumnNames( subColumnNamesInit ) {} }; /** - * @brief Struct for a column. - * Each column contains its own parameters (such as name, alignment, etc.) and column values. + * @brief Struct for a TableColumnData. + * Each column contains its own parameters (such as name, alignment, etc.). */ struct TableColumnData { /// Structure who contains parameters for a column Column column; - /// A vector containing all columns values + /// A vector containing all the values of a column std::vector< string > columnValues; /// The largest string(s) in the column std::vector< string > maxStringSize; @@ -154,7 +155,7 @@ class TableLayout {} /** - * @brief Constructs a TableColumnData with the given parameters. + * @brief Constructs a TableColumnData with the given parameters. * @param col The parameters for the column. * @param subColumnInit The subcolumns contained in the colum */ @@ -220,7 +221,7 @@ class TableLayout * @param args An initializer_list containing string / column */ - TableLayout( TableLayoutArgs args ) + TableLayout( TableLayoutArgs args ) { setMargin( MarginValue::medium ); processArguments( args ); @@ -242,7 +243,6 @@ class TableLayout /** * @return The columns vector */ - std::vector< TableColumnData > const & getColumns() const; /** diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index 133fb0acdc7..29260494faf 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -437,6 +437,10 @@ + + + + @@ -519,6 +523,10 @@ + + + + @@ -2197,6 +2205,7 @@ the relative residual norm satisfies: + @@ -3912,6 +3921,51 @@ Level 0 outputs no specific information for this solver. Higher levels require m + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -3927,6 +3981,8 @@ Local- Add jump stabilization on interior of macro elements--> + + @@ -4374,6 +4430,7 @@ Level 0 outputs no specific information for this solver. Higher levels require m + @@ -4554,6 +4611,19 @@ Level 0 outputs no specific information for this solver. Higher levels require m + + + + + + + + + + From adb8dc0e8a14d6443aad2680cf1b794390729a82 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 17 Oct 2024 11:37:10 +0200 Subject: [PATCH 197/216] missing doc --- src/coreComponents/common/format/table/TableLayout.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index ddbe32372d6..ed9225e9a0b 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -98,7 +98,7 @@ class TableLayout /** * @brief Construct a Column object with the given parameters * @param name The Column name - * @param subColumnNames Vector containing subcolumn names + * @param subColumnNamesInit Vector containing subcolumn names */ Column( string_view name, std::vector< string > && subColumnNamesInit ) : columnName( name ), subColumnNames( subColumnNamesInit ) @@ -121,7 +121,7 @@ class TableLayout * @param name The Column name * @param headerAlign The column name alignment * @param display Flag indicating whether the column is enabled - * @param subsColumns Vector containing subcolumn names + * @param subColumnNamesInit Vector containing subcolumn names */ Column( string_view name, Alignment headerAlign, bool display, std::vector< string > && subColumnNamesInit ) : columnName( name ), @@ -182,6 +182,7 @@ class TableLayout }; + /// Alias for an initializer list of variants that can contain either a string or a layout column. using TableLayoutArgs = std::initializer_list< std::variant< string_view, TableLayout::Column > >; TableLayout() = default; @@ -189,7 +190,7 @@ class TableLayout /** * @brief Construct a new Table Layout object * @param title The table title - * @param args An initializer_list containing string / column + * @param columns A vector containing all column initialized */ TableLayout( string_view title, std::vector< TableLayout::Column > & columns ) @@ -217,7 +218,6 @@ class TableLayout /** * @brief Construct a new Table Layout object - * @param title The table title * @param args An initializer_list containing string / column */ From 6c06d4d334044baffb41372c179b7476abe8dd58 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 17 Oct 2024 17:51:26 +0200 Subject: [PATCH 198/216] remove unacessary code --- src/coreComponents/common/format/table/TableData.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/coreComponents/common/format/table/TableData.cpp b/src/coreComponents/common/format/table/TableData.cpp index dcbec10a01a..2354365f20f 100644 --- a/src/coreComponents/common/format/table/TableData.cpp +++ b/src/coreComponents/common/format/table/TableData.cpp @@ -87,7 +87,6 @@ TableData2D::TableDataHolder TableData2D::buildTableData( string_view targetUnit string_view columnFmt ) const { TableData2D::TableDataHolder tableData1D; - std::vector< size_t > rowsLength; tableData1D.headerNames.push_back( string( targetUnit ) ); @@ -114,8 +113,7 @@ TableData2D::TableDataHolder TableData2D::buildTableData( string_view targetUnit currentRowValues.push_back( GEOS_FMT( "{}", cellValue ) ); } - tableData1D.tableData.addRow( std::move( currentRowValues ) ); - rowsLength.push_back( currentRowValues.size() ); + tableData1D.tableData.addRow( currentRowValues ); } return tableData1D; From b0d731a4e1e44a9267e1887aa425772e7b022ec8 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 21 Oct 2024 09:41:34 +0200 Subject: [PATCH 199/216] xsd --- src/coreComponents/schema/schema.xsd.other | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/coreComponents/schema/schema.xsd.other b/src/coreComponents/schema/schema.xsd.other index e982b4f9e2b..5474981e8d5 100644 --- a/src/coreComponents/schema/schema.xsd.other +++ b/src/coreComponents/schema/schema.xsd.other @@ -534,6 +534,7 @@ + @@ -1156,6 +1157,21 @@ + + + + + + + + + + + + + + + @@ -1337,6 +1353,7 @@ + @@ -1366,6 +1383,7 @@ + From f27c10170a11a3bf5354a1c94d9095b4c5ec3b7f Mon Sep 17 00:00:00 2001 From: Arnaud DUDES <155963334+arng40@users.noreply.github.com> Date: Mon, 21 Oct 2024 10:34:15 +0200 Subject: [PATCH 200/216] Delete src/coreComponents/schema/schema.xsd --- src/coreComponents/schema/schema.xsd | 6478 -------------------------- 1 file changed, 6478 deletions(-) delete mode 100644 src/coreComponents/schema/schema.xsd diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd deleted file mode 100644 index 6c137c9f37f..00000000000 --- a/src/coreComponents/schema/schema.xsd +++ /dev/null @@ -1,6478 +0,0 @@ - - - - GEOSX Input Schema - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 3acc8a137a5da03a077d31e1e3b539c81bada82e Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 21 Oct 2024 11:00:11 +0200 Subject: [PATCH 201/216] xsd regenrate --- src/coreComponents/schema/schema.xsd | 6478 ++++++++++++++++++++++++++ 1 file changed, 6478 insertions(+) create mode 100644 src/coreComponents/schema/schema.xsd diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd new file mode 100644 index 00000000000..6c137c9f37f --- /dev/null +++ b/src/coreComponents/schema/schema.xsd @@ -0,0 +1,6478 @@ + + + + GEOSX Input Schema + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 76a022c6a9568671c561d8fc580a98e86ad74ad4 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 21 Oct 2024 16:36:54 +0200 Subject: [PATCH 202/216] test ci fix --- src/coreComponents/mesh/DomainPartition.cpp | 94 ++++++++++----------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/src/coreComponents/mesh/DomainPartition.cpp b/src/coreComponents/mesh/DomainPartition.cpp index ed611c9492e..1cfc861f0de 100644 --- a/src/coreComponents/mesh/DomainPartition.cpp +++ b/src/coreComponents/mesh/DomainPartition.cpp @@ -399,14 +399,14 @@ void DomainPartition::outputPartitionInformation() const real64 maxRatios[4] = {0}; MpiWrapper::allReduce( ratios, minRatios, 4, MPI_MIN, MPI_COMM_WORLD ); MpiWrapper::allReduce( ratios, maxRatios, 4, MPI_MAX, MPI_COMM_WORLD ); - real64 const minNodeRatio = minRatios[0]; - real64 const maxNodeRatio = maxRatios[0]; - real64 const minEdgeRatio = minRatios[1]; - real64 const maxEdgeRatio = maxRatios[1]; - real64 const minFaceRatio = minRatios[2]; - real64 const maxFaceRatio = maxRatios[2]; - real64 const minElemRatio = minRatios[3]; - real64 const maxElemRatio = maxRatios[3]; + // real64 const minNodeRatio = minRatios[0]; + // real64 const maxNodeRatio = maxRatios[0]; + // real64 const minEdgeRatio = minRatios[1]; + // real64 const maxEdgeRatio = maxRatios[1]; + // real64 const minFaceRatio = minRatios[2]; + // real64 const maxFaceRatio = maxRatios[2]; + // real64 const minElemRatio = minRatios[3]; + // real64 const maxElemRatio = maxRatios[3]; GEOS_LOG_RANK_0( " MeshBody: " + meshBody.getName() + " MeshLevel: " + meshLevel.getName() + "\n" ); @@ -439,45 +439,45 @@ void DomainPartition::outputPartitionInformation() const addCommaSeparators( maxNumGhostElems )); // output in rank order - int const thisRank = MpiWrapper::commRank(); - for( int rank=0; rank Date: Mon, 21 Oct 2024 17:13:13 +0200 Subject: [PATCH 203/216] update output domain partition (fix ci) --- src/coreComponents/mesh/DomainPartition.cpp | 96 ++++++++++----------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/src/coreComponents/mesh/DomainPartition.cpp b/src/coreComponents/mesh/DomainPartition.cpp index 1cfc861f0de..64ecf5ef3d6 100644 --- a/src/coreComponents/mesh/DomainPartition.cpp +++ b/src/coreComponents/mesh/DomainPartition.cpp @@ -399,19 +399,20 @@ void DomainPartition::outputPartitionInformation() const real64 maxRatios[4] = {0}; MpiWrapper::allReduce( ratios, minRatios, 4, MPI_MIN, MPI_COMM_WORLD ); MpiWrapper::allReduce( ratios, maxRatios, 4, MPI_MAX, MPI_COMM_WORLD ); - // real64 const minNodeRatio = minRatios[0]; - // real64 const maxNodeRatio = maxRatios[0]; - // real64 const minEdgeRatio = minRatios[1]; - // real64 const maxEdgeRatio = maxRatios[1]; - // real64 const minFaceRatio = minRatios[2]; - // real64 const maxFaceRatio = maxRatios[2]; - // real64 const minElemRatio = minRatios[3]; - // real64 const maxElemRatio = maxRatios[3]; + real64 const minNodeRatio = minRatios[0]; + real64 const maxNodeRatio = maxRatios[0]; + real64 const minEdgeRatio = minRatios[1]; + real64 const maxEdgeRatio = maxRatios[1]; + real64 const minFaceRatio = minRatios[2]; + real64 const maxFaceRatio = maxRatios[2]; + real64 const minElemRatio = minRatios[3]; + real64 const maxElemRatio = maxRatios[3]; GEOS_LOG_RANK_0( " MeshBody: " + meshBody.getName() + " MeshLevel: " + meshLevel.getName() + "\n" ); TableLayout tableLayout( "Rank", - {TableLayout::Column{"Nodes", {"local", "ghost"}}, + {" ", + TableLayout::Column{"Nodes", {"local", "ghost"}}, TableLayout::Column{"Edges", {"local", "ghost"}}, TableLayout::Column{"Faces", {"local", "ghost"}}, TableLayout::Column{"Elems", {"local", "ghost"}}} ); @@ -439,45 +440,44 @@ void DomainPartition::outputPartitionInformation() const addCommaSeparators( maxNumGhostElems )); // output in rank order - // int const thisRank = MpiWrapper::commRank(); - // for( int rank=0; rank Date: Mon, 21 Oct 2024 17:49:32 +0200 Subject: [PATCH 204/216] some renaming --- .../common/format/table/TableLayout.cpp | 2 +- src/coreComponents/mesh/DomainPartition.cpp | 114 +++++++++--------- .../mesh/generators/WellGeneratorBase.cpp | 48 ++++---- 3 files changed, 81 insertions(+), 83 deletions(-) diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 39594f225cd..4fe58e18f3c 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -25,7 +25,7 @@ void TableLayout::addToColumns( const std::vector< string > & columnNames ) { for( const auto & columnName : columnNames ) { - addToColumns( string( columnName ) ); + addToColumns( columnName ); } } diff --git a/src/coreComponents/mesh/DomainPartition.cpp b/src/coreComponents/mesh/DomainPartition.cpp index 64ecf5ef3d6..0b53cd2611b 100644 --- a/src/coreComponents/mesh/DomainPartition.cpp +++ b/src/coreComponents/mesh/DomainPartition.cpp @@ -410,34 +410,34 @@ void DomainPartition::outputPartitionInformation() const GEOS_LOG_RANK_0( " MeshBody: " + meshBody.getName() + " MeshLevel: " + meshLevel.getName() + "\n" ); - TableLayout tableLayout( "Rank", - {" ", - TableLayout::Column{"Nodes", {"local", "ghost"}}, - TableLayout::Column{"Edges", {"local", "ghost"}}, - TableLayout::Column{"Faces", {"local", "ghost"}}, - TableLayout::Column{"Elems", {"local", "ghost"}}} ); - tableLayout.setMargin( TableLayout::MarginValue::large ); - tableLayout.disableLineWrap(); - - TableData tableData; - tableData.addRow( "min", - addCommaSeparators( minNumLocalNodes ), - addCommaSeparators( minNumGhostNodes ), - addCommaSeparators( minNumLocalEdges ), - addCommaSeparators( minNumGhostEdges ), - addCommaSeparators( minNumLocalFaces ), - addCommaSeparators( minNumGhostFaces ), - addCommaSeparators( minNumLocalElems ), - addCommaSeparators( minNumGhostElems )); - tableData.addRow( "max", - addCommaSeparators( maxNumLocalNodes ), - addCommaSeparators( maxNumGhostNodes ), - addCommaSeparators( maxNumLocalEdges ), - addCommaSeparators( maxNumGhostEdges ), - addCommaSeparators( maxNumLocalFaces ), - addCommaSeparators( maxNumGhostFaces ), - addCommaSeparators( maxNumLocalElems ), - addCommaSeparators( maxNumGhostElems )); + TableLayout layoutPartition( "Rank", + {" ", + TableLayout::Column{"Nodes", {"local", "ghost"}}, + TableLayout::Column{"Edges", {"local", "ghost"}}, + TableLayout::Column{"Faces", {"local", "ghost"}}, + TableLayout::Column{"Elems", {"local", "ghost"}}} ); + layoutPartition.setMargin( TableLayout::MarginValue::large ); + layoutPartition.disableLineWrap(); + + TableData dataPartition; + dataPartition.addRow( "min", + addCommaSeparators( minNumLocalNodes ), + addCommaSeparators( minNumGhostNodes ), + addCommaSeparators( minNumLocalEdges ), + addCommaSeparators( minNumGhostEdges ), + addCommaSeparators( minNumLocalFaces ), + addCommaSeparators( minNumGhostFaces ), + addCommaSeparators( minNumLocalElems ), + addCommaSeparators( minNumGhostElems )); + dataPartition.addRow( "max", + addCommaSeparators( maxNumLocalNodes ), + addCommaSeparators( maxNumGhostNodes ), + addCommaSeparators( maxNumLocalEdges ), + addCommaSeparators( maxNumGhostEdges ), + addCommaSeparators( maxNumLocalFaces ), + addCommaSeparators( maxNumGhostFaces ), + addCommaSeparators( maxNumLocalElems ), + addCommaSeparators( maxNumGhostElems )); // output in rank order int const thisRank = MpiWrapper::commRank(); @@ -445,39 +445,39 @@ void DomainPartition::outputPartitionInformation() const { if( rank == thisRank ) { - tableData.addRow( rank, - addCommaSeparators( numLocalNodes ), - addCommaSeparators( numGhostNodes ), - addCommaSeparators( numLocalEdges ), - addCommaSeparators( numGhostEdges ), - addCommaSeparators( numLocalFaces ), - addCommaSeparators( numGhostFaces ), - addCommaSeparators( numLocalElems ), - addCommaSeparators( numGhostElems )); + dataPartition.addRow( rank, + addCommaSeparators( numLocalNodes ), + addCommaSeparators( numGhostNodes ), + addCommaSeparators( numLocalEdges ), + addCommaSeparators( numGhostEdges ), + addCommaSeparators( numLocalFaces ), + addCommaSeparators( numGhostFaces ), + addCommaSeparators( numLocalElems ), + addCommaSeparators( numGhostElems )); } MpiWrapper::barrier(); } MpiWrapper::barrier(); - TableTextFormatter tableLog( tableLayout ); - GEOS_LOG_RANK_0( tableLog.toString( tableData )); - - TableLayout tableLayoutRatio( {"Rank", "Nodes ", "Edges ", "Faces ", "Elems "} ); - tableLayoutRatio.setMargin( TableLayout::MarginValue::large ); - - TableData tableDataRatio; - tableDataRatio.addRow( "min(local/total)", - minNodeRatio, - minEdgeRatio, - minFaceRatio, - minElemRatio ); - tableDataRatio.addRow( "min(local/total)", - maxNodeRatio, - maxEdgeRatio, - maxFaceRatio, - maxElemRatio ); - - TableTextFormatter tableLogRatio( tableLayoutRatio ); - GEOS_LOG_RANK_0( tableLogRatio.toString( tableDataRatio )); + TableTextFormatter logPartition( layoutPartition ); + GEOS_LOG_RANK_0( logPartition.toString( dataPartition )); + + TableLayout layoutPartitionRatio( {"Rank", "Nodes ", "Edges ", "Faces ", "Elems "} ); + layoutPartitionRatio.setMargin( TableLayout::MarginValue::large ); + + TableData dataPartitionRatio; + dataPartitionRatio.addRow( "min(local/total)", + minNodeRatio, + minEdgeRatio, + minFaceRatio, + minElemRatio ); + dataPartitionRatio.addRow( "min(local/total)", + maxNodeRatio, + maxEdgeRatio, + maxFaceRatio, + maxElemRatio ); + + TableTextFormatter logPartitionRation( layoutPartitionRatio ); + GEOS_LOG_RANK_0( logPartitionRation.toString( dataPartitionRatio )); } } ); } diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index 9f0d2a851a3..dae451ea4c9 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -526,7 +526,7 @@ void WellGeneratorBase::mergePerforations( array1d< array1d< localIndex > > cons void WellGeneratorBase::logInternalWell() const { - TableData tableWellData; + TableData wellData; for( globalIndex iwelem = 0; iwelem < m_numElems; ++iwelem ) { std::optional< globalIndex > nextElement; @@ -542,40 +542,38 @@ void WellGeneratorBase::logInternalWell() const prevElement = m_prevElemId[iwelem][0]; } - tableWellData.addRow( iwelem, - m_elemCenterCoords[iwelem][0], - m_elemCenterCoords[iwelem][1], - m_elemCenterCoords[iwelem][2], - prevElement, - nextElement ); + wellData.addRow( iwelem, + m_elemCenterCoords[iwelem][0], + m_elemCenterCoords[iwelem][1], + m_elemCenterCoords[iwelem][2], + prevElement, + nextElement ); } - string const wellTitle = GEOS_FMT( "Well '{}' Element Table", getName() ); - TableLayout tableWellLayout( - {"Element no.", - "CoordX", - "CoordY", - "CoordZ", - "Prev\nElement", - "Next\nElement"} ); - tableWellLayout.setTitle( wellTitle ); - - TableTextFormatter const tableFormatter( tableWellLayout ); - GEOS_LOG_RANK_0( tableFormatter.toString( tableWellData )); + TableLayout const wellLayout( GEOS_FMT( "Well '{}' Element Table", getName() ), + {"Element no.", + "CoordX", + "CoordY", + "CoordZ", + "Prev\nElement", + "Next\nElement"} ); + + TableTextFormatter const wellFormatter( wellLayout ); + GEOS_LOG_RANK_0( wellFormatter.toString( wellData )); } void WellGeneratorBase::logPerforationTable() const { - TableData tablePerfoData; + TableData dataPerforation; for( globalIndex iperf = 0; iperf < m_numPerforations; ++iperf ) { - tablePerfoData.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); + dataPerforation.addRow( iperf, m_perfCoords[iperf], m_perfElemId[iperf] ); } - TableLayout const tableLayoutPerfo ( GEOS_FMT( "Well '{}' Perforation Table", getName()), - { "Perforation no.", "Coordinates", "Well element no." } ); - TableTextFormatter const tablePerfoLog( tableLayoutPerfo ); - GEOS_LOG_RANK_0( tablePerfoLog.toString( tablePerfoData )); + TableLayout const layoutPerforation ( GEOS_FMT( "Well '{}' Perforation Table", getName()), + { "Perforation no.", "Coordinates", "Well element no." } ); + TableTextFormatter const logPerforation( layoutPerforation ); + GEOS_LOG_RANK_0( logPerforation.toString( dataPerforation )); } } From 346d8dc8e886af3e171440686e8e5103ff2b6cfb Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 23 Oct 2024 14:47:57 +0200 Subject: [PATCH 205/216] remove unnecessary code --- src/coreComponents/common/format/table/TableLayout.hpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index ed9225e9a0b..7877501fda6 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -330,14 +330,10 @@ class TableLayout * @param arg The first argument to be processed * @param args The remaining arguments to be processed */ - template< typename T, typename ... Ts > - void processArguments( T && arg, Ts &&... args ) + template< typename ... Ts > + void processArguments( Ts &... args ) { - addToColumns( std::forward< T >( arg )); - if constexpr (sizeof...(args) > 0) - { - processArguments( std::forward< Ts >( args )... ); - } + addToColumns( args ... ); } /** From cabdbcb852578a5ee80700c5fb82245ce1dc0642 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 28 Oct 2024 11:41:55 +0100 Subject: [PATCH 206/216] doc --- src/coreComponents/common/format/table/TableLayout.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 7877501fda6..c4e1a756468 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -325,9 +325,7 @@ class TableLayout /** * @brief Recursively processes a variable number of arguments and adds them to the table data. - * @tparam T The first argument * @tparam Ts The remaining arguments - * @param arg The first argument to be processed * @param args The remaining arguments to be processed */ template< typename ... Ts > From 43f9664d1f92b29b2e65c7e570ac74678895fdb1 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 29 Oct 2024 14:26:05 +0100 Subject: [PATCH 207/216] missing const --- .../format/table/unitTests/testTable.cpp | 70 +++++++++---------- .../functions/TableFunction.cpp | 2 +- src/coreComponents/mesh/DomainPartition.cpp | 3 +- 3 files changed, 34 insertions(+), 41 deletions(-) diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index 4ee152fb3d4..5a4fbdfab61 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -27,13 +27,12 @@ using namespace geos; TEST( testTable, tableEmptyRow ) { //table with empty row - TableLayout tableLayout( {"Well\nelement no.\nPV weighted\nbar", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement"} ); - string const title = "InternalWellGenerator well_injector1"; - tableLayout.setTitle( title ); + TableLayout const tableLayout( "InternalWellGenerator well_injector1", + {"Well\nelement no.\nPV weighted\nbar", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"} ); TableData tableData; tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); @@ -61,13 +60,12 @@ TEST( testTable, tableEmptyRow ) TEST( testTable, tableClassic ) { - TableLayout tableLayout( {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", - "CordX", - "CoordZ", - "Prev\nelement", - "Next\nelement"} ); - string const title = "InternalWellGenerator well_injector1"; - tableLayout.setTitle( title ); + TableLayout const tableLayout( "InternalWellGenerator well_injector1", + {"Duis fringilla, ligula sed porta fringilla,\nligula wisi commodo felis,ut adipiscing felis dui in enim. Suspendisse malesuada ultrices ante", + "CordX", + "CoordZ", + "Prev\nelement", + "Next\nelement"} ); TableData tableData; tableData.addRow( "value1", "[30.21543]", "3.0", 54, 0 ); @@ -98,18 +96,15 @@ TEST( testTable, tableColumnParamClassic ) //TODO TableLayout::Column{{"Prev\nelement"}, TableLayout::Alignment::right}, TableLayout::Column{{"Next\nelement"}, TableLayout::Alignment::right}} ); tableLayout.setValuesAlignment( TableLayout::Alignment::right ); - string const title = "InternalWellGenerator well_injector1"; - tableLayout.setTitle( title ); TableData tableData; tableData.addRow( "value1", " ", "3.0", 3.0129877, 2.0f, 1 ); tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); TableTextFormatter const tableText( tableLayout ); + std::cout << tableText.toString( tableData ) <( TableFunction const & table units::getDescription( tableFunction.getDimUnit( 0 ) ), units::getDescription( tableFunction.getDimUnit( 1 ) ) ); - TableLayout tableLayout( "", tableConverted.headerNames ); + TableLayout const tableLayout( "", tableConverted.headerNames ); TableCSVFormatter csvFormat( tableLayout ); formatterStream << csvFormat.headerToString() << csvFormat.dataToString( tableConverted.tableData ); diff --git a/src/coreComponents/mesh/DomainPartition.cpp b/src/coreComponents/mesh/DomainPartition.cpp index 0b53cd2611b..2c648b4b608 100644 --- a/src/coreComponents/mesh/DomainPartition.cpp +++ b/src/coreComponents/mesh/DomainPartition.cpp @@ -416,8 +416,7 @@ void DomainPartition::outputPartitionInformation() const TableLayout::Column{"Edges", {"local", "ghost"}}, TableLayout::Column{"Faces", {"local", "ghost"}}, TableLayout::Column{"Elems", {"local", "ghost"}}} ); - layoutPartition.setMargin( TableLayout::MarginValue::large ); - layoutPartition.disableLineWrap(); + layoutPartition.setMargin( TableLayout::MarginValue::large ).disableLineWrap(); TableData dataPartition; dataPartition.addRow( "min", From 23006868d5165943fdb55ef607112f4ee49569c3 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 29 Oct 2024 15:02:44 +0100 Subject: [PATCH 208/216] renaming & signature & const --- .../common/format/table/TableFormatter.cpp | 4 ++-- .../common/format/table/TableLayout.cpp | 4 ++-- .../common/format/table/TableLayout.hpp | 18 +++++++++--------- .../format/table/unitTests/testTable.cpp | 10 +++++----- src/coreComponents/mesh/DomainPartition.cpp | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 6e6018b5604..6b30b66d2f6 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -232,7 +232,7 @@ void TableTextFormatter::outputTable( std::ostringstream & tableOutput, { integer const nbValuesRows = tableColumnsData[0].columnValues.size(); - if( m_tableLayout.isLineWrapEnabled()) + if( m_tableLayout.isLineBreakEnabled()) { tableOutput << '\n'; } @@ -242,7 +242,7 @@ void TableTextFormatter::outputTable( std::ostringstream & tableOutput, outputHeaderSectionRows( tableColumnsData, tableOutput, nbHeaderRows, sectionSeparatingLine ); outputValuesSectionRows( tableColumnsData, tableOutput, nbValuesRows, sectionSeparatingLine ); - if( m_tableLayout.isLineWrapEnabled()) + if( m_tableLayout.isLineBreakEnabled()) { tableOutput << '\n'; } diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 4fe58e18f3c..06d382d04ad 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -60,7 +60,7 @@ TableLayout & TableLayout::setTitle( string_view title ) return *this; } -TableLayout & TableLayout::disableLineWrap() +TableLayout & TableLayout::disableLineBreak() { m_wrapLine = false; return *this; @@ -84,7 +84,7 @@ TableLayout & TableLayout::setValuesAlignment( TableLayout::Alignment alignment return *this; } -bool TableLayout::isLineWrapEnabled() const +bool TableLayout::isLineBreakEnabled() const { return m_wrapLine; } diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index c4e1a756468..f3536ad198b 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -159,7 +159,7 @@ class TableLayout * @param col The parameters for the column. * @param subColumnInit The subcolumns contained in the colum */ - TableColumnData ( Column col, std::vector< TableColumnData > subColumnInit ) + TableColumnData ( Column col, std::vector< TableColumnData > const & subColumnInit ) : column( col ), subColumn( subColumnInit ) {} @@ -170,10 +170,10 @@ class TableLayout * @param maxStringSizeInit The largest string(s) in the column. * @param subColumnInit The sub-columns of the column. */ - TableColumnData ( Column col, - std::vector< string > columnValuesInit, - std::vector< string > maxStringSizeInit, - std::vector< TableColumnData > subColumnInit ) + TableColumnData ( Column const & col, + std::vector< string > const & columnValuesInit, + std::vector< string > const & maxStringSizeInit, + std::vector< TableColumnData > const & subColumnInit ) : column( col ), columnValues( columnValuesInit ), maxStringSize( maxStringSizeInit ), @@ -257,10 +257,10 @@ class TableLayout TableLayout & setTitle( string_view title ); /** - * @brief Remove the last return line a the end of the table + * @brief Remove the return line at the end & begenning of the table * @return The tableLayout reference */ - TableLayout & disableLineWrap(); + TableLayout & disableLineBreak(); /** * @brief Set the minimal margin width between cell content and borders. @@ -277,9 +277,9 @@ class TableLayout TableLayout & setValuesAlignment( TableLayout::Alignment alignment ); /** - * @return whether we have a line return at the end of the table or not + * @return check if the line break at the end & beginning is activated */ - bool isLineWrapEnabled() const; + bool isLineBreakEnabled() const; /** * @brief Remove all subcolumn in all columns diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index 5a4fbdfab61..b2bf3ed494a 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -247,9 +247,9 @@ TEST( testTable, subColumns ) { TableLayout const tableLayout( {" ", "Column1", - TableLayout::Column{"Nodes ", TableLayout::Alignment::right, true, {"Locales", "Ghost", "Active"}}, + TableLayout::Column{"Nodes", TableLayout::Alignment::right, true, {"Locales", "Ghost", "Active"}}, "Column3", - TableLayout::Column{"Column4 ", TableLayout::Alignment::right, true, {"Locales", "Ghost"}}, + TableLayout::Column{"Column4", TableLayout::Alignment::right, true, {"Locales", "Ghost"}}, "Column5"} ); TableData tableData; @@ -260,7 +260,7 @@ TEST( testTable, subColumns ) EXPECT_EQ( tableText.toString( tableData ), "\n--------------------------------------------------------------------------------------------------------\n" - "| | Column1 | Nodes | Column3 | Column4 | Column5 |\n" + "| | Column1 | Nodes | Column3 | Column4 | Column5 |\n" "--------------------------------------------------------------------------------------------------------\n" "| | | Locales | Ghost | Active | | Locales | Ghost | |\n" "--------------------------------------------------------------------------------------------------------\n" @@ -299,10 +299,10 @@ TEST( testTable, variadicTest ) ); } } -TEST( testTable, testLineWrap ) +TEST( testTable, testLineBreak ) { TableLayout tableLayout( {"Cras egestas", "CoordX", "C", "CoordZ", "Prev\nelement", "Next\nelement"} ); - tableLayout.setTitle( "title" ).setMargin( TableLayout::MarginValue::tiny ).disableLineWrap(); + tableLayout.setTitle( "title" ).setMargin( TableLayout::MarginValue::tiny ).disableLineBreak(); TableData tableData; tableData.addRow( "1", "2", "3.0", 3.0129877, 2.0f, 1 ); diff --git a/src/coreComponents/mesh/DomainPartition.cpp b/src/coreComponents/mesh/DomainPartition.cpp index 2c648b4b608..4469411a9b6 100644 --- a/src/coreComponents/mesh/DomainPartition.cpp +++ b/src/coreComponents/mesh/DomainPartition.cpp @@ -416,7 +416,7 @@ void DomainPartition::outputPartitionInformation() const TableLayout::Column{"Edges", {"local", "ghost"}}, TableLayout::Column{"Faces", {"local", "ghost"}}, TableLayout::Column{"Elems", {"local", "ghost"}}} ); - layoutPartition.setMargin( TableLayout::MarginValue::large ).disableLineWrap(); + layoutPartition.setMargin( TableLayout::MarginValue::large ).disableLineBreak(); TableData dataPartition; dataPartition.addRow( "min", From e1af681bf35a2628dc85e0b91c43b1bf6f8998d3 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 30 Oct 2024 11:21:12 +0100 Subject: [PATCH 209/216] improve populate table values --- .../common/format/table/TableFormatter.cpp | 58 ++++++++++--------- .../common/format/table/TableFormatter.hpp | 3 +- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 6b30b66d2f6..2d524948b54 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -209,7 +209,7 @@ void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::TableCo if( !tableDataRows.empty()) { updateVisibleColumns( tableColumnsData, tableDataRows ); - populateColumnsFromTableData( tableColumnsData, tableDataRows, false ); + populateColumnsFromTableData( tableColumnsData, tableDataRows ); } std::vector< std::vector< string > > splitHeaders; @@ -248,47 +248,53 @@ void TableTextFormatter::outputTable( std::ostringstream & tableOutput, } } +void populateSubColumnsFromTableData( TableLayout::TableColumnData & tableColumnData, + std::vector< std::vector< string > > const & valuesByColumn, + size_t & idxColumn ) +{ + size_t idxSubColumn = idxColumn; + for( auto & subColumnData : tableColumnData.subColumn ) + { + subColumnData.columnValues = valuesByColumn[idxSubColumn++]; + } + + size_t nbSubColumns = tableColumnData.column.subColumnNames.size(); + auto subColumnStartIter = valuesByColumn.begin() + idxColumn; + std::vector< std::vector< string > > valuesBySubColumn( subColumnStartIter, + subColumnStartIter + nbSubColumns ); + for( const auto & columnValues : valuesBySubColumn ) + { // add all subcolumn values in parent tableColumnData + tableColumnData.columnValues.insert( tableColumnData.columnValues.end(), + columnValues.begin(), + columnValues.end() ); + } + idxColumn += nbSubColumns; +} + void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout::TableColumnData > & tableColumnsData, - std::vector< std::vector< string > > const & tableDataRows, - bool isSubColumn ) const + std::vector< std::vector< string > > const & tableDataRows ) const { size_t currentColumn = 0; - std::vector< std::vector< string > > tColumnsValues( tableDataRows[0].size(), + std::vector< std::vector< string > > valuesByColumn( tableDataRows[0].size(), std::vector< string >( tableDataRows.size())); - if( !isSubColumn ) - { - transpose( tColumnsValues, tableDataRows ); - } + + // to insert directly the values in each columns, we fill with the transposed tableDataRows (row major->column major) + transpose( valuesByColumn, tableDataRows ); for( auto & tableColumnData : tableColumnsData ) { if( tableColumnData.subColumn.empty()) { - tableColumnData.columnValues = !isSubColumn ? - tColumnsValues[currentColumn++] : tableDataRows[currentColumn++]; + tableColumnData.columnValues = valuesByColumn[currentColumn++]; } else { - size_t nbSubColumns = tableColumnData.column.subColumnNames.size(); - auto subColumnStartIdx = tColumnsValues.begin() + currentColumn; - std::vector< std::vector< string > > subColumnValues( subColumnStartIdx, - subColumnStartIdx + nbSubColumns ); - populateColumnsFromTableData( tableColumnData.subColumn, subColumnValues, true ); - - std::vector< std::vector< string > > tSubColumnValues( subColumnValues[0].size(), - std::vector< string >( subColumnValues.size()) ); - transpose( tSubColumnValues, subColumnValues ); - for( const auto & columnValues : tSubColumnValues ) - { // add all subcolumn values in parent tableColumnData - tableColumnData.columnValues.insert( tableColumnData.columnValues.end(), - columnValues.begin(), - columnValues.end() ); - } - currentColumn += subColumnValues.size(); + populateSubColumnsFromTableData( tableColumnData, valuesByColumn, currentColumn ); } } } + void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::TableColumnData > & tableColumnsData, size_t & nbHeaderRows, std::vector< std::vector< string > > & splitHeaders ) const diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 17536f8f6d5..3b16a7d08c0 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -190,8 +190,7 @@ class TableTextFormatter : public TableFormatter * @param isSubColumn Boolean indicating if the current tableColumnData is a subcolumn */ void populateColumnsFromTableData( std::vector< TableLayout::TableColumnData > & tableColumnsData, - std::vector< std::vector< string > > const & tableData, - bool isSubColumn ) const; + std::vector< std::vector< string > > const & tableData ) const; /** * @brief Split all header names by detecting the newline \\n character. and From b87cee9b6dd95f637406299a04098d110f223cdc Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 30 Oct 2024 14:52:12 +0100 Subject: [PATCH 210/216] renaming, some function refactoring & simplification --- .../common/format/table/TableFormatter.cpp | 210 +++++++++--------- .../common/format/table/TableFormatter.hpp | 52 ++--- .../common/format/table/TableLayout.cpp | 10 +- .../common/format/table/TableLayout.hpp | 26 +-- 4 files changed, 140 insertions(+), 158 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 2d524948b54..9a113ad2d94 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -82,15 +82,16 @@ string TableCSVFormatter::toString< TableData >( TableData const & tableData ) c /////////////////////////////////////////////////////////////////////// /** - * @brief distributes spaces equally from a string vector + * @brief Given spaces number, distribute it over all string vector * @param vec The vector where we adding spaces - * @param totalSpaces Total spaces to be distributed + * @param totalSpaces Total spaces to distribute over all strings */ void distributeSpaces( std::vector< string > & vec, int totalSpaces ) { int numElements = vec.size(); - int baseSpaces = totalSpaces / numElements; - int extraSpaces = totalSpaces % numElements; + auto dv = std::div( totalSpaces, numElements ); + int baseSpaces = dv.quot; + int extraSpaces = dv.rem; for( int i = 0; i < numElements; ++i ) { @@ -138,7 +139,7 @@ string buildCell( TableLayout::Alignment const alignment, string_view value, siz * @param tableColumnsData Vector built in TableLayout containing all tableColumnsData with their parameters * @param tableDataRows Vector built in TableData containing all rows values */ -void updateVisibleColumns( std::vector< TableLayout::TableColumnData > & tableColumnsData, +void updateVisibleColumns( std::vector< TableLayout::ColumnStructure > & tableColumnsData, std::vector< std::vector< string > > & tableDataRows ) { integer idxColumn = 0; @@ -167,18 +168,17 @@ TableTextFormatter::TableTextFormatter( TableLayout const & tableLayout ): string TableTextFormatter::toString() const { std::ostringstream tableOutput; - std::vector< TableLayout::TableColumnData > tableColumnsData( m_tableLayout.getColumns()); - size_t nbHeaderRows = 0; + std::vector< TableLayout::ColumnStructure > tableColumnsData( m_tableLayout.getColumns()); TableData tableData; string sectionSeparatingLine; string topSeparator; - prepareAndBuildTable( tableColumnsData, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); + prepareAndBuildTable( tableColumnsData, tableData, sectionSeparatingLine, topSeparator ); tableOutput << '\n'; outputTitleRow( tableOutput, topSeparator ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - outputHeaderSectionRows( tableColumnsData, tableOutput, nbHeaderRows, sectionSeparatingLine ); + outputHeaderSectionRows( tableColumnsData, tableOutput, sectionSeparatingLine ); return tableOutput.str(); } @@ -186,22 +186,20 @@ string TableTextFormatter::toString() const template<> string TableTextFormatter::toString< TableData >( TableData const & tableData ) const { - std::vector< TableLayout::TableColumnData > tableColumnsData( m_tableLayout.getColumns()); - size_t nbHeaderRows = 0; + std::vector< TableLayout::ColumnStructure > tableColumnsData( m_tableLayout.getColumns()); string sectionSeparatingLine; string topSeparator; - prepareAndBuildTable( tableColumnsData, tableData, nbHeaderRows, sectionSeparatingLine, topSeparator ); + prepareAndBuildTable( tableColumnsData, tableData, sectionSeparatingLine, topSeparator ); std::ostringstream tableOutput; - outputTable( tableOutput, tableColumnsData, nbHeaderRows, sectionSeparatingLine, topSeparator ); + outputTable( tableOutput, tableColumnsData, sectionSeparatingLine, topSeparator ); return tableOutput.str(); } -void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::TableColumnData > & tableColumnsData, +void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::ColumnStructure > & tableColumnsData, TableData const & tableData, - size_t & nbHeaderRows, string & sectionSeparatingLine, string & topSeparator ) const { @@ -213,7 +211,7 @@ void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::TableCo } std::vector< std::vector< string > > splitHeaders; - splitAndMergeColumnHeaders( tableColumnsData, nbHeaderRows, splitHeaders ); + splitAndMergeColumnHeaders( tableColumnsData, splitHeaders ); for( auto & tableColumnData : tableColumnsData ) { @@ -225,13 +223,10 @@ void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::TableCo } void TableTextFormatter::outputTable( std::ostringstream & tableOutput, - std::vector< TableLayout::TableColumnData > & tableColumnsData, - size_t & nbHeaderRows, + std::vector< TableLayout::ColumnStructure > & tableColumnsData, string_view sectionSeparatingLine, string_view topSeparator ) const { - integer const nbValuesRows = tableColumnsData[0].columnValues.size(); - if( m_tableLayout.isLineBreakEnabled()) { tableOutput << '\n'; @@ -239,16 +234,16 @@ void TableTextFormatter::outputTable( std::ostringstream & tableOutput, outputTitleRow( tableOutput, topSeparator ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - outputHeaderSectionRows( tableColumnsData, tableOutput, nbHeaderRows, sectionSeparatingLine ); + outputHeaderSectionRows( tableColumnsData, tableOutput, sectionSeparatingLine ); - outputValuesSectionRows( tableColumnsData, tableOutput, nbValuesRows, sectionSeparatingLine ); + outputValuesSectionRows( tableColumnsData, tableOutput, sectionSeparatingLine ); if( m_tableLayout.isLineBreakEnabled()) { tableOutput << '\n'; } } -void populateSubColumnsFromTableData( TableLayout::TableColumnData & tableColumnData, +void populateSubColumnsFromTableData( TableLayout::ColumnStructure & tableColumnData, std::vector< std::vector< string > > const & valuesByColumn, size_t & idxColumn ) { @@ -271,7 +266,7 @@ void populateSubColumnsFromTableData( TableLayout::TableColumnData & tableColumn idxColumn += nbSubColumns; } -void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout::TableColumnData > & tableColumnsData, +void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout::ColumnStructure > & tableColumnsData, std::vector< std::vector< string > > const & tableDataRows ) const { size_t currentColumn = 0; @@ -295,12 +290,9 @@ void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout: } -void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::TableColumnData > & tableColumnsData, - size_t & nbHeaderRows, +void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::ColumnStructure > & tableColumnsData, std::vector< std::vector< string > > & splitHeaders ) const { - splitHeaders.reserve( tableColumnsData.size() ); - for( auto & tableColumnData : tableColumnsData ) { std::vector< string > splitHeaderParts; @@ -316,13 +308,12 @@ void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::T if( !tableColumnData.subColumn.empty()) { std::vector< std::vector< string > > splitSubColHeaders; - size_t nbHeaderSubColRows = 0; - splitAndMergeColumnHeaders( tableColumnData.subColumn, nbHeaderSubColRows, splitSubColHeaders ); + splitAndMergeColumnHeaders( tableColumnData.subColumn, splitSubColHeaders ); } } - nbHeaderRows = std::max_element( splitHeaders.begin(), splitHeaders.end(), - []( auto const & v1, auto const & v2 ) + size_t nbHeaderRows = std::max_element( splitHeaders.begin(), splitHeaders.end(), + []( auto const & v1, auto const & v2 ) { return v1.size() < v2.size(); } )->size(); @@ -338,7 +329,7 @@ void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::T } -void TableTextFormatter::findAndSetLongestColumnString( TableLayout::TableColumnData & tableColumnData, +void TableTextFormatter::findAndSetLongestColumnString( TableLayout::ColumnStructure & tableColumnData, std::vector< string > & maxStringSize, integer const idxMaxString ) const { @@ -398,7 +389,7 @@ void TableTextFormatter::findAndSetLongestColumnString( TableLayout::TableColumn } } -void TableTextFormatter::computeTableWidth( std::vector< TableLayout::TableColumnData > & tableColumnsData ) const +void TableTextFormatter::computeTableWidth( std::vector< TableLayout::ColumnStructure > & tableColumnsData ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); @@ -431,7 +422,7 @@ void TableTextFormatter::computeTableWidth( std::vector< TableLayout::TableColum } } -void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::TableColumnData > & tableColumnsData, +void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::ColumnStructure > & tableColumnsData, real64 const extraCharacters ) const { real64 const extraCharactersPerColumn = std::floor( (extraCharacters) / tableColumnsData.size() ); @@ -454,7 +445,7 @@ void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::TableCol } } -void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::TableColumnData > const & tableColumnsData, +void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::ColumnStructure > const & tableColumnsData, string & sectionSeparatingLine, string & topSeparator ) const { @@ -482,74 +473,6 @@ void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::TableCo topSeparator = GEOS_FMT( "{}{:-<{}}{}", m_horizontalLine, "", topSeparatorLength, m_horizontalLine ); } -void TableTextFormatter::outputSubSection( std::vector< TableLayout::TableColumnData > const & tableColumnsData, - std::ostringstream & tableOutput, - integer idxRow ) const -{ - integer const columnMargin = m_tableLayout.getColumnMargin(); - for( size_t idxCol = 0; idxCol< tableColumnsData.size(); ++idxCol ) - { - tableOutput << buildCell( tableColumnsData[idxCol].column.alignmentSettings.valueAlignment, - tableColumnsData[idxCol].columnValues[idxRow], - tableColumnsData[idxCol].maxStringSize[0].length() ); - if( idxCol < tableColumnsData.size() - 1 ) - { - tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); - } - } -} - -void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::TableColumnData > const & tableColumnsData, - std::ostringstream & tableOutput, - size_t const nbRows, - string_view sectionSeparatingLine ) const -{ - integer const columnMargin = m_tableLayout.getColumnMargin(); - integer const borderMargin = m_tableLayout.getBorderMargin(); - string const spaces = string( columnMargin - 1, ' ' ); - - for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) - { - // Append the left border - tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, borderMargin ); - - for( std::size_t idxColumn = 0; idxColumn < tableColumnsData.size(); ++idxColumn ) - { - auto const & tableColumnData = tableColumnsData[idxColumn]; - - if( !tableColumnData.subColumn.empty()) - { - outputSubSection( tableColumnData.subColumn, tableOutput, idxRow ); - } - else - { - string const cell = tableColumnData.columnValues.at( idxRow ); - string const cellSize = stringutilities::join( tableColumnData.maxStringSize, spaces ); - tableOutput << buildCell( tableColumnData.column.alignmentSettings.valueAlignment, - cell, - cellSize.length()); - } - - if( idxColumn < tableColumnsData.size() - 1 ) - { - tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); - } - - } - - // Append right border - tableOutput << GEOS_FMT( "{:>{}}", m_verticalLine, borderMargin ); - - - tableOutput << "\n"; - - } - - if( nbRows != 0 ) - { - tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - } -} void TableTextFormatter::outputTitleRow( std::ostringstream & tableOutput, string_view topSeparator ) const @@ -566,16 +489,15 @@ void TableTextFormatter::outputTitleRow( std::ostringstream & tableOutput, } } -void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::TableColumnData > const & tableColumnsData, +void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::ColumnStructure > const & tableColumnsData, std::ostringstream & tableOutput, - size_t const nbRows, string_view sectionSeparatingLine ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); string const spaces = string( columnMargin, ' ' ); bool containSubColumn = false; - + size_t nbRows = tableColumnsData[0].column.splitColumnNames.size(); for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) { // Append the left border @@ -613,7 +535,7 @@ void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Tabl // Check and build subrow header if( containSubColumn ) { - std::vector< TableLayout::TableColumnData > rowSubColumns; + std::vector< TableLayout::ColumnStructure > rowSubColumns; for( auto const & tableColumnData : tableColumnsData ) { @@ -628,7 +550,77 @@ void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Tabl tableColumnData.subColumn.end()); } } - outputHeaderSectionRows( rowSubColumns, tableOutput, 1, sectionSeparatingLine ); + outputHeaderSectionRows( rowSubColumns, tableOutput, sectionSeparatingLine ); + + } +} + +void TableTextFormatter::outputSubSection( std::vector< TableLayout::ColumnStructure > const & tableColumnsData, + std::ostringstream & tableOutput, + integer idxRow ) const +{ + integer const columnMargin = m_tableLayout.getColumnMargin(); + for( size_t idxCol = 0; idxCol< tableColumnsData.size(); ++idxCol ) + { + tableOutput << buildCell( tableColumnsData[idxCol].column.alignmentSettings.valueAlignment, + tableColumnsData[idxCol].columnValues[idxRow], + tableColumnsData[idxCol].maxStringSize[0].length() ); + if( idxCol < tableColumnsData.size() - 1 ) + { + tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); + } + } +} + +void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::ColumnStructure > const & tableColumnsData, + std::ostringstream & tableOutput, + string_view sectionSeparatingLine ) const +{ + size_t const nbRows = tableColumnsData[0].columnValues.size(); + integer const columnMargin = m_tableLayout.getColumnMargin(); + integer const borderMargin = m_tableLayout.getBorderMargin(); + string const spaces = string( columnMargin - 1, ' ' ); + + for( size_t idxRow = 0; idxRow < nbRows; ++idxRow ) + { + // Append the left border + tableOutput << GEOS_FMT( "{:<{}}", m_verticalLine, borderMargin ); + + for( std::size_t idxColumn = 0; idxColumn < tableColumnsData.size(); ++idxColumn ) + { + auto const & tableColumnData = tableColumnsData[idxColumn]; + + if( !tableColumnData.subColumn.empty()) + { + outputSubSection( tableColumnData.subColumn, tableOutput, idxRow ); + } + else + { + string const cell = tableColumnData.columnValues.at( idxRow ); + string const cellSize = stringutilities::join( tableColumnData.maxStringSize, spaces ); + tableOutput << buildCell( tableColumnData.column.alignmentSettings.valueAlignment, + cell, + cellSize.length()); + } + + if( idxColumn < tableColumnsData.size() - 1 ) + { + tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); + } + + } + + // Append right border + tableOutput << GEOS_FMT( "{:>{}}", m_verticalLine, borderMargin ); + + + tableOutput << "\n"; + + } + + if( nbRows != 0 ) + { + tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); } } diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 3b16a7d08c0..c022bda362d 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -136,7 +136,7 @@ class TableTextFormatter : public TableFormatter /** * @return A TableLayout string representation, - * The TableTextFormatter receives hasn't receive any data, so only the top part is returned. + * The TableTextFormatter receives hasn't receive any data, so only the header part is returned. */ string toString() const; @@ -160,26 +160,22 @@ class TableTextFormatter : public TableFormatter * @param tableColumnsData The vector containg all tableColumnsData . Each tableColumnData contains its own * parameters (such as name, alignment, etc.). * @param tableData Vector containing all rows filled with values - * @param nbHeaderRows Number of header rows, which will be calculated based on tableColumnData headers and their formatting. * @param sectionSeparatingLine Separator string used between sections of the table * @param topSeparator The table top separator */ - void prepareAndBuildTable( std::vector< TableLayout::TableColumnData > & tableColumnsData, + void prepareAndBuildTable( std::vector< TableLayout::ColumnStructure > & tableColumnsData, TableData const & tableData, - size_t & nbHeaderRows, string & sectionSeparatingLine, string & topSeparator ) const; /** * @brief Displays the complete table * @param tableOutput The output stream * @param tableColumnsData Vector containg all tableColumnsData - * @param nbHeaderRows A variable to be calculated which will contain the number of header lines * @param sectionSeparatingLine Separator string used between sections of the table * @param topSeparator The table top separator */ void outputTable( std::ostringstream & tableOutput, - std::vector< TableLayout::TableColumnData > & tableColumnsData, - size_t & nbHeaderRows, + std::vector< TableLayout::ColumnStructure > & tableColumnsData, string_view sectionSeparatingLine, string_view topSeparator ) const; @@ -189,18 +185,16 @@ class TableTextFormatter : public TableFormatter * @param tableData Vector containing all rows filled with values * @param isSubColumn Boolean indicating if the current tableColumnData is a subcolumn */ - void populateColumnsFromTableData( std::vector< TableLayout::TableColumnData > & tableColumnsData, + void populateColumnsFromTableData( std::vector< TableLayout::ColumnStructure > & tableColumnsData, std::vector< std::vector< string > > const & tableData ) const; /** * @brief Split all header names by detecting the newline \\n character. and * set the same vector size for each split header and merge it into tableColumnsData * @param tableColumnsData The vector containg all tableColumnsData - * @param nbHeaderRows Variable which will contain the number of header lines to be displayed * @param splitHeaders Vector to store the split header names for each tableColumnData */ - void splitAndMergeColumnHeaders( std::vector< TableLayout::TableColumnData > & tableColumnsData, - size_t & nbHeaderRows, + void splitAndMergeColumnHeaders( std::vector< TableLayout::ColumnStructure > & tableColumnsData, std::vector< std::vector< string > > & splitHeaders ) const; /** @@ -212,7 +206,7 @@ class TableTextFormatter : public TableFormatter * @note Compares the longest string from the header with the longest string from the column values. * If the column contains subcolumns, it recursively applies the same logic to them */ - void findAndSetLongestColumnString( TableLayout::TableColumnData & tableColumnData, + void findAndSetLongestColumnString( TableLayout::ColumnStructure & tableColumnData, std::vector< string > & maxStringSize, integer const idxColumn ) const; @@ -221,14 +215,14 @@ class TableTextFormatter : public TableFormatter * Increase the size of the tableColumnsData if necessary * @param tableColumnsData Vector of tableColumnData containing containing the largest string for each tableColumnData */ - void computeTableWidth( std::vector< TableLayout::TableColumnData > & tableColumnsData ) const; + void computeTableWidth( std::vector< TableLayout::ColumnStructure > & tableColumnsData ) const; /** * @brief Increase each tableColumnData size if the title is larger than all the tableColumnsData * @param tableColumnsData Vector containing all table tableColumnsData * @param extraCharacters ExtraCharacters to be distributed between each tableColumnsData */ - void increaseColumnsSize( std::vector< TableLayout::TableColumnData > & tableColumnsData, + void increaseColumnsSize( std::vector< TableLayout::ColumnStructure > & tableColumnsData, real64 const extraCharacters ) const; /** @@ -237,22 +231,10 @@ class TableTextFormatter : public TableFormatter * @param sectionSeparatingLine Separator string used between sections of the table * @param topSeparator The table top separator */ - void buildTableSeparators( std::vector< TableLayout::TableColumnData > const & tableColumnsData, + void buildTableSeparators( std::vector< TableLayout::ColumnStructure > const & tableColumnsData, string & sectionSeparatingLine, string & topSeparator ) const; - /** - * @brief Output the values rows in the table - * @param tableColumnsData Vector containing all table tableColumnsData - * @param tableOutput The output stream - * @param nbRows Total number of rows to output. - * @param sectionSeparatingLine Separator string used between sections of the table - */ - void outputValuesSectionRows( std::vector< TableLayout::TableColumnData > const & tableColumnsData, - std::ostringstream & tableOutput, - size_t const nbRows, - string_view sectionSeparatingLine ) const; - /** * @brief Output the title row in the table * @param topSeparator The top separator string @@ -264,12 +246,10 @@ class TableTextFormatter : public TableFormatter * @brief Output the header rows in the table * @param tableColumnsData Vector containing all table tableColumnsData * @param tableOutput The output stream - * @param nbRows The total number of rows to output. * @param sectionSeparatingLine Separator string used between sections of the table */ - void outputHeaderSectionRows( std::vector< TableLayout::TableColumnData > const & tableColumnsData, + void outputHeaderSectionRows( std::vector< TableLayout::ColumnStructure > const & tableColumnsData, std::ostringstream & tableOutput, - size_t const nbRows, string_view sectionSeparatingLine ) const; /** @@ -278,9 +258,19 @@ class TableTextFormatter : public TableFormatter * @param tableOutput The output stream * @param idxRow Index of the current row in the table */ - void outputSubSection( std::vector< TableLayout::TableColumnData > const & tableColumnsData, + void outputSubSection( std::vector< TableLayout::ColumnStructure > const & tableColumnsData, std::ostringstream & tableOutput, integer idxRow ) const; + + /** + * @brief Output the values rows in the table + * @param tableColumnsData Vector containing all table tableColumnsData + * @param tableOutput The output stream + * @param sectionSeparatingLine Separator string used between sections of the table + */ + void outputValuesSectionRows( std::vector< TableLayout::ColumnStructure > const & tableColumnsData, + std::ostringstream & tableOutput, + string_view sectionSeparatingLine ) const; }; /** diff --git a/src/coreComponents/common/format/table/TableLayout.cpp b/src/coreComponents/common/format/table/TableLayout.cpp index 06d382d04ad..1ed322c8c04 100644 --- a/src/coreComponents/common/format/table/TableLayout.cpp +++ b/src/coreComponents/common/format/table/TableLayout.cpp @@ -38,19 +38,19 @@ void TableLayout::addToColumns( Column const & column ) { if( !column.subColumnNames.empty()) { - std::vector< TableLayout::TableColumnData > subColumns; + std::vector< TableLayout::ColumnStructure > subColumns; for( const auto & subColumnsName : column.subColumnNames ) { subColumns.push_back( - TableLayout::TableColumnData { + TableLayout::ColumnStructure { TableLayout::Column{ subColumnsName, column.alignmentSettings.headerAlignment } } ); } - m_tableColumnsData.push_back( TableLayout::TableColumnData { column, subColumns } ); + m_tableColumnsData.push_back( TableLayout::ColumnStructure { column, subColumns } ); } else { - m_tableColumnsData.push_back( TableLayout::TableColumnData { column } ); + m_tableColumnsData.push_back( TableLayout::ColumnStructure { column } ); } } @@ -100,7 +100,7 @@ void TableLayout::removeSubColumn() } } -std::vector< TableLayout::TableColumnData > const & TableLayout::getColumns() const +std::vector< TableLayout::ColumnStructure > const & TableLayout::getColumns() const { return m_tableColumnsData; } diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index f3536ad198b..d5d4c0ba171 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -132,10 +132,10 @@ class TableLayout }; /** - * @brief Struct for a TableColumnData. + * @brief Struct for a ColumnStructure. * Each column contains its own parameters (such as name, alignment, etc.). */ - struct TableColumnData + struct ColumnStructure { /// Structure who contains parameters for a column Column column; @@ -144,36 +144,36 @@ class TableLayout /// The largest string(s) in the column std::vector< string > maxStringSize; /// Vector containing all sub columns subdivison - std::vector< TableColumnData > subColumn; + std::vector< ColumnStructure > subColumn; /** - * @brief Constructs a TableColumnData with the given column. + * @brief Constructs a ColumnStructure with the given column. * @param col The parameters for the column. */ - TableColumnData ( Column col ) + ColumnStructure ( Column col ) : column( col ) {} /** - * @brief Constructs a TableColumnData with the given parameters. + * @brief Constructs a ColumnStructure with the given parameters. * @param col The parameters for the column. * @param subColumnInit The subcolumns contained in the colum */ - TableColumnData ( Column col, std::vector< TableColumnData > const & subColumnInit ) + ColumnStructure ( Column col, std::vector< ColumnStructure > const & subColumnInit ) : column( col ), subColumn( subColumnInit ) {} /** - * @brief Constructs a TableColumnData with the given parameters. + * @brief Constructs a ColumnStructure with the given parameters. * @param col The parameters for the column. * @param columnValuesInit The values in the column. * @param maxStringSizeInit The largest string(s) in the column. * @param subColumnInit The sub-columns of the column. */ - TableColumnData ( Column const & col, + ColumnStructure ( Column const & col, std::vector< string > const & columnValuesInit, std::vector< string > const & maxStringSizeInit, - std::vector< TableColumnData > const & subColumnInit ) + std::vector< ColumnStructure > const & subColumnInit ) : column( col ), columnValues( columnValuesInit ), maxStringSize( maxStringSizeInit ), @@ -243,7 +243,7 @@ class TableLayout /** * @return The columns vector */ - std::vector< TableColumnData > const & getColumns() const; + std::vector< ColumnStructure > const & getColumns() const; /** * @return The table name @@ -310,7 +310,7 @@ class TableLayout private: /** - * @brief Add a column to the table given an initializer_list of string & TableColumnData + * @brief Add a column to the table given an initializer_list of string & ColumnStructure * @param args An initializer_list containing string / column */ void processArguments( TableLayoutArgs args ) @@ -352,7 +352,7 @@ class TableLayout */ void addToColumns( Column const & column ); - std::vector< TableColumnData > m_tableColumnsData; + std::vector< ColumnStructure > m_tableColumnsData; bool m_wrapLine = true; string m_tableTitle; From 8ea7e56426717df55f7ad3ea672d64b549945bc3 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 31 Oct 2024 11:05:42 +0100 Subject: [PATCH 211/216] cout removed, assert added, doc update --- .../common/format/table/TableFormatter.cpp | 4 ++++ .../common/format/table/TableLayout.hpp | 2 +- .../common/format/table/unitTests/testTable.cpp | 15 +++++++-------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 9a113ad2d94..3834b658ee1 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -21,6 +21,7 @@ #include "TableFormatter.hpp" #include #include "common/format/StringUtilities.hpp" +#include "common/logger/Logger.hpp" #include "TableFormatter.hpp" namespace geos @@ -107,6 +108,9 @@ void distributeSpaces( std::vector< string > & vec, int totalSpaces ) void transpose( std::vector< std::vector< string > > & dest, std::vector< std::vector< string > > const & source ) { + GEOS_ERROR_IF( dest.size() != source[0].size(), "Dest matrix must have the number of rows equal to the number of columns in the source matrix" ); + GEOS_ERROR_IF( dest[0].size() != source.size(), "Dest matrix must have the number of columns equal to the number of rows in the source matrix." ); + for( size_t idxRow = 0; idxRow < source.size(); ++idxRow ) { for( size_t idxCol = 0; idxCol < source[idxRow].size(); ++idxCol ) diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index d5d4c0ba171..88df7faac5d 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -141,7 +141,7 @@ class TableLayout Column column; /// A vector containing all the values of a column std::vector< string > columnValues; - /// The largest string(s) in the column + /// Vector of string containing the largest string for a column and its subColumns std::vector< string > maxStringSize; /// Vector containing all sub columns subdivison std::vector< ColumnStructure > subColumn; diff --git a/src/coreComponents/common/format/table/unitTests/testTable.cpp b/src/coreComponents/common/format/table/unitTests/testTable.cpp index b2bf3ed494a..b56b3777c94 100644 --- a/src/coreComponents/common/format/table/unitTests/testTable.cpp +++ b/src/coreComponents/common/format/table/unitTests/testTable.cpp @@ -102,7 +102,6 @@ TEST( testTable, tableColumnParamClassic ) //TODO tableData.addRow( "val1", "v", "[3.045,42.02,89.25]", 3.0, 10.0f, 3 ); TableTextFormatter const tableText( tableLayout ); - std::cout << tableText.toString( tableData ) < Date: Thu, 31 Oct 2024 11:33:19 +0100 Subject: [PATCH 212/216] move assert --- src/coreComponents/common/format/table/TableFormatter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 3834b658ee1..2eea4c80b1f 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -108,11 +108,11 @@ void distributeSpaces( std::vector< string > & vec, int totalSpaces ) void transpose( std::vector< std::vector< string > > & dest, std::vector< std::vector< string > > const & source ) { - GEOS_ERROR_IF( dest.size() != source[0].size(), "Dest matrix must have the number of rows equal to the number of columns in the source matrix" ); - GEOS_ERROR_IF( dest[0].size() != source.size(), "Dest matrix must have the number of columns equal to the number of rows in the source matrix." ); for( size_t idxRow = 0; idxRow < source.size(); ++idxRow ) { + GEOS_ERROR_IF( dest.size() != source[0].size(), "Dest matrix must have the number of rows equal to the number of columns in the source matrix" ); + GEOS_ERROR_IF( dest[0].size() != source.size(), "Dest matrix must have the number of columns equal to the number of rows in the source matrix." ); for( size_t idxCol = 0; idxCol < source[idxRow].size(); ++idxCol ) { dest[idxCol][idxRow] = source[idxRow][idxCol]; From e77ea500b638e240c0245b268ca1729e202af0f8 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 31 Oct 2024 11:33:46 +0100 Subject: [PATCH 213/216] add idx... --- src/coreComponents/common/format/table/TableFormatter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 2eea4c80b1f..ff7f7f7d1fc 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -111,8 +111,8 @@ void transpose( std::vector< std::vector< string > > & dest, for( size_t idxRow = 0; idxRow < source.size(); ++idxRow ) { - GEOS_ERROR_IF( dest.size() != source[0].size(), "Dest matrix must have the number of rows equal to the number of columns in the source matrix" ); - GEOS_ERROR_IF( dest[0].size() != source.size(), "Dest matrix must have the number of columns equal to the number of rows in the source matrix." ); + GEOS_ERROR_IF( dest.size() != source[idxRow].size(), "Dest matrix must have the number of rows equal to the number of columns in the source matrix" ); + GEOS_ERROR_IF( dest[idxRow].size() != source.size(), "Dest matrix must have the number of columns equal to the number of rows in the source matrix." ); for( size_t idxCol = 0; idxCol < source[idxRow].size(); ++idxCol ) { dest[idxCol][idxRow] = source[idxRow][idxCol]; From ac61e5dfff5a3a7a95c220430654da553ea9f56f Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 5 Nov 2024 14:10:23 +0100 Subject: [PATCH 214/216] replace string vector on ColumnStructure --- .../common/format/table/TableFormatter.cpp | 225 +++++++----------- .../common/format/table/TableFormatter.hpp | 29 +-- .../common/format/table/TableLayout.hpp | 5 +- 3 files changed, 96 insertions(+), 163 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index ff7f7f7d1fc..18543c6947e 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -82,37 +82,16 @@ string TableCSVFormatter::toString< TableData >( TableData const & tableData ) c ////// Log Formatter implementation /////////////////////////////////////////////////////////////////////// -/** - * @brief Given spaces number, distribute it over all string vector - * @param vec The vector where we adding spaces - * @param totalSpaces Total spaces to distribute over all strings - */ -void distributeSpaces( std::vector< string > & vec, int totalSpaces ) -{ - int numElements = vec.size(); - auto dv = std::div( totalSpaces, numElements ); - int baseSpaces = dv.quot; - int extraSpaces = dv.rem; - - for( int i = 0; i < numElements; ++i ) - { - vec[i] += string( baseSpaces, ' ' ); - - if( i < extraSpaces ) - { - vec[i] += ' '; - } - } -} - void transpose( std::vector< std::vector< string > > & dest, std::vector< std::vector< string > > const & source ) { for( size_t idxRow = 0; idxRow < source.size(); ++idxRow ) { - GEOS_ERROR_IF( dest.size() != source[idxRow].size(), "Dest matrix must have the number of rows equal to the number of columns in the source matrix" ); - GEOS_ERROR_IF( dest[idxRow].size() != source.size(), "Dest matrix must have the number of columns equal to the number of rows in the source matrix." ); + // GEOS_ERROR_IF( dest.size() != source[idxRow].size(), "Dest matrix must have the number of rows equal to the number of columns in the + // source matrix" ); + // GEOS_ERROR_IF( dest[idxRow].size() != source.size(), "Dest matrix must have the number of columns equal to the number of rows in the + // source matrix." ); for( size_t idxCol = 0; idxCol < source[idxRow].size(); ++idxCol ) { dest[idxCol][idxRow] = source[idxRow][idxCol]; @@ -214,16 +193,15 @@ void TableTextFormatter::prepareAndBuildTable( std::vector< TableLayout::ColumnS populateColumnsFromTableData( tableColumnsData, tableDataRows ); } - std::vector< std::vector< string > > splitHeaders; - splitAndMergeColumnHeaders( tableColumnsData, splitHeaders ); + std::vector< std::vector< string > > allDividedHeaderParts; + splitAndMergeColumnHeaders( tableColumnsData, allDividedHeaderParts ); for( auto & tableColumnData : tableColumnsData ) { - findAndSetLongestColumnString( tableColumnData, tableColumnData.maxStringSize, 0 ); + findAndSetLongestColumnString( tableColumnData ); } - computeTableWidth( tableColumnsData ); - buildTableSeparators( tableColumnsData, sectionSeparatingLine, topSeparator ); + computeAndBuildTableSeparator( tableColumnsData, sectionSeparatingLine, topSeparator ); } void TableTextFormatter::outputTable( std::ostringstream & tableOutput, @@ -252,9 +230,9 @@ void populateSubColumnsFromTableData( TableLayout::ColumnStructure & tableColumn size_t & idxColumn ) { size_t idxSubColumn = idxColumn; - for( auto & subColumnData : tableColumnData.subColumn ) + for( auto & subColumn : tableColumnData.subColumn ) { - subColumnData.columnValues = valuesByColumn[idxSubColumn++]; + subColumn.columnValues = valuesByColumn[idxSubColumn++]; } size_t nbSubColumns = tableColumnData.column.subColumnNames.size(); @@ -295,49 +273,48 @@ void TableTextFormatter::populateColumnsFromTableData( std::vector< TableLayout: void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::ColumnStructure > & tableColumnsData, - std::vector< std::vector< string > > & splitHeaders ) const + std::vector< std::vector< string > > & allDividedHeaderParts ) const { for( auto & tableColumnData : tableColumnsData ) { - std::vector< string > splitHeaderParts; + std::vector< string > dividedHeaderParts; std::istringstream ss( tableColumnData.column.columnName ); string subColumnNames; while( getline( ss, subColumnNames, '\n' )) { - splitHeaderParts.push_back( subColumnNames ); + dividedHeaderParts.push_back( subColumnNames ); } - splitHeaders.push_back( splitHeaderParts ); + allDividedHeaderParts.push_back( dividedHeaderParts ); if( !tableColumnData.subColumn.empty()) { - std::vector< std::vector< string > > splitSubColHeaders; - splitAndMergeColumnHeaders( tableColumnData.subColumn, splitSubColHeaders ); + std::vector< std::vector< string > > dividedSubColHeaders; + splitAndMergeColumnHeaders( tableColumnData.subColumn, dividedSubColHeaders ); } } - size_t nbHeaderRows = std::max_element( splitHeaders.begin(), splitHeaders.end(), + size_t nbHeaderRows = std::max_element( allDividedHeaderParts.begin(), allDividedHeaderParts.end(), []( auto const & v1, auto const & v2 ) { return v1.size() < v2.size(); } )->size(); - for( auto & headerParts : splitHeaders ) + for( auto & headerDivided : allDividedHeaderParts ) { - if( headerParts.size() < nbHeaderRows ) + if( headerDivided.size() < nbHeaderRows ) { - headerParts.resize( nbHeaderRows, " " ); + headerDivided.resize( nbHeaderRows, " " ); } - tableColumnsData[&headerParts - &splitHeaders[0]].column.splitColumnNames = headerParts; + tableColumnsData[&headerDivided - &allDividedHeaderParts[0]].column.splitColumnNames = headerDivided; } } -void TableTextFormatter::findAndSetLongestColumnString( TableLayout::ColumnStructure & tableColumnData, - std::vector< string > & maxStringSize, - integer const idxMaxString ) const +void TableTextFormatter::findAndSetLongestColumnString( TableLayout::ColumnStructure & tableColumnData ) const { - string maxStringColumn; + size_t & maxStringSizeColumn = tableColumnData.maxStringSize; + { // header case auto const maxStringSizeHeader = *std::max_element( tableColumnData.column.splitColumnNames.begin(), tableColumnData.column.splitColumnNames.end(), @@ -345,12 +322,10 @@ void TableTextFormatter::findAndSetLongestColumnString( TableLayout::ColumnStruc { return a.size() < b.size(); } ); - - maxStringColumn = maxStringSizeHeader; - maxStringSize.push_back( maxStringSizeHeader ); + maxStringSizeColumn = maxStringSizeHeader.length(); } - { // values case + { // cells case if( tableColumnData.subColumn.empty() && !tableColumnData.columnValues.empty()) { auto const maxStringSizeCell = *std::max_element( tableColumnData.columnValues.begin(), @@ -359,125 +334,89 @@ void TableTextFormatter::findAndSetLongestColumnString( TableLayout::ColumnStruc { return a.size() < b.size(); } ); - - if( maxStringColumn.length() < maxStringSizeCell.length()) + if( maxStringSizeColumn < maxStringSizeCell.length()) { - maxStringColumn = maxStringSizeCell; + maxStringSizeColumn = maxStringSizeCell.length(); } } } - { // Update max string size if necessary - if( maxStringSize[idxMaxString].length() < maxStringColumn.length() ) - { - maxStringSize[idxMaxString] = maxStringColumn; - } - } - { // subcolumn values case + size_t totalLengthSubColumns = 0; + size_t lengthSubColumns = 0; if( !tableColumnData.subColumn.empty() ) { - tableColumnData.maxStringSize.clear(); - for( size_t idxSubColumn = 0; idxSubColumn < tableColumnData.subColumn.size(); ++idxSubColumn ) + for( auto & subColumn : tableColumnData.subColumn ) { - findAndSetLongestColumnString( tableColumnData.subColumn[idxSubColumn], - tableColumnData.maxStringSize, - idxSubColumn ); + findAndSetLongestColumnString( subColumn ); + totalLengthSubColumns += subColumn.maxStringSize; + lengthSubColumns += subColumn.maxStringSize; + if( &subColumn != &tableColumnData.subColumn[0] ) + { + totalLengthSubColumns += m_tableLayout.getColumnMargin(); + } } } - } - if( tableColumnData.maxStringSize.empty() ) - { - tableColumnData.maxStringSize.push_back( maxStringColumn ); + if( lengthSubColumns > tableColumnData.maxStringSize ) + { + tableColumnData.maxStringSize = totalLengthSubColumns; + } } + } -void TableTextFormatter::computeTableWidth( std::vector< TableLayout::ColumnStructure > & tableColumnsData ) const +void TableTextFormatter::computeAndBuildTableSeparator( std::vector< TableLayout::ColumnStructure > & tableColumnsData, + string & sectionSeparatingLine, + string & topSeparator ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); string const tableTitle = string( m_tableLayout.getTitle() ); - string::size_type numColumns = tableColumnsData.size() - 1; - string::size_type spacing = numColumns * columnMargin; - string::size_type margins = borderMargin * 2; - - string::size_type const sectionLengthWithSpacing = spacing + margins; - - string::size_type sectionlineLength = sectionLengthWithSpacing; - string const spaces = string( m_tableLayout.getColumnMargin(), ' ' ); - - { // Compute total length of all tableColumnsData with margins - sectionlineLength += std::accumulate( tableColumnsData.begin(), tableColumnsData.end(), 0, - [&]( auto sum, auto & tableColumnData ) -> auto - { // take into account subColumn - string sumOfString = stringutilities::join( tableColumnData.maxStringSize, spaces ); - return static_cast< decltype(sum) >(sum + sumOfString.length()); - } ); + size_t const numColumns = tableColumnsData.size() - 1; + size_t const spacingBetweenColumns = numColumns * (size_t) columnMargin; + size_t const margins = (size_t) borderMargin * 2; + size_t sectionlineLength = spacingBetweenColumns + margins; + for( auto const & tableColumnData : tableColumnsData ) + { + sectionlineLength += tableColumnData.maxStringSize; } - string::size_type maxTopLineLength = tableTitle.length() + margins; + size_t maxTopLineLength = tableTitle.length() + margins; maxTopLineLength = std::max( {maxTopLineLength, sectionlineLength} ); if( sectionlineLength < maxTopLineLength ) { - real64 const extraCharacters = maxTopLineLength - sectionlineLength; + size_t const extraCharacters = maxTopLineLength - sectionlineLength; increaseColumnsSize( tableColumnsData, extraCharacters ); + sectionlineLength = maxTopLineLength; } + + sectionSeparatingLine = GEOS_FMT( "{:-^{}}", m_horizontalLine, sectionlineLength ); + integer const topSeparatorLength = maxTopLineLength - 2; // Adjust for border characters + topSeparator = GEOS_FMT( "{}{:-<{}}{}", m_horizontalLine, "", topSeparatorLength, m_horizontalLine ); } void TableTextFormatter::increaseColumnsSize( std::vector< TableLayout::ColumnStructure > & tableColumnsData, - real64 const extraCharacters ) const + size_t const extraCharacters ) const { - real64 const extraCharactersPerColumn = std::floor( (extraCharacters) / tableColumnsData.size() ); - integer overflowCharacters = extraCharacters - (extraCharactersPerColumn * tableColumnsData.size() ); - for( std::size_t idxColumn = 0; idxColumn < tableColumnsData.size(); ++idxColumn ) + size_t const extraCharactersPerColumn = std::floor( (extraCharacters) / tableColumnsData.size() ); + size_t const overflowCharacters = extraCharacters - (extraCharactersPerColumn * tableColumnsData.size() ); + for( auto & tableColumnData : tableColumnsData ) { - if( !tableColumnsData[idxColumn].subColumn.empty()) - { - distributeSpaces( tableColumnsData[idxColumn].maxStringSize, (int)extraCharactersPerColumn ); - increaseColumnsSize( tableColumnsData[idxColumn].subColumn, extraCharactersPerColumn ); - } - else + if( !tableColumnData.subColumn.empty()) { - string & cell = tableColumnsData[idxColumn].maxStringSize[0]; - integer newMaxStringSize = idxColumn == 0 ? - extraCharactersPerColumn + cell.size() + overflowCharacters : - extraCharactersPerColumn + cell.size(); - cell = GEOS_FMT( "{:>{}}", cell, newMaxStringSize ); + increaseColumnsSize( tableColumnData.subColumn, extraCharactersPerColumn ); } - } -} -void TableTextFormatter::buildTableSeparators( std::vector< TableLayout::ColumnStructure > const & tableColumnsData, - string & sectionSeparatingLine, - string & topSeparator ) const -{ - std::vector< string > maxStringsPerColumn; - for( auto const & tableColumnData : tableColumnsData ) - { - std::for_each( tableColumnData.maxStringSize.begin(), tableColumnData.maxStringSize.end(), - [&] ( string maxString ) { - maxStringsPerColumn.push_back( string( maxString.length(), m_horizontalLine ) ); - } ); + size_t const cellSize = tableColumnData.maxStringSize; + integer const newMaxStringSize = &tableColumnData == &tableColumnsData[0] ? + extraCharactersPerColumn + cellSize + overflowCharacters : + extraCharactersPerColumn + cellSize; + tableColumnData.maxStringSize = newMaxStringSize; } - - integer const columnMargin = m_tableLayout.getColumnMargin(); - integer const borderMargin = m_tableLayout.getBorderMargin(); - string const patternBetweenColumns = GEOS_FMT( "{:-^{}}", m_horizontalLine, columnMargin ); - string const leftBorder = GEOS_FMT( "{:-<{}}", m_horizontalLine, borderMargin ); - string const rightBorder = GEOS_FMT( "{:-<{}}", m_horizontalLine, borderMargin ); - - string const columnJoin = stringutilities::join( maxStringsPerColumn, patternBetweenColumns ); - std::ostringstream oss; - oss << leftBorder << columnJoin << rightBorder; - sectionSeparatingLine = oss.str(); - - integer const topSeparatorLength = sectionSeparatingLine.size() - 2; // Adjust for border characters - topSeparator = GEOS_FMT( "{}{:-<{}}{}", m_horizontalLine, "", topSeparatorLength, m_horizontalLine ); } - void TableTextFormatter::outputTitleRow( std::ostringstream & tableOutput, string_view topSeparator ) const { @@ -510,11 +449,11 @@ void TableTextFormatter::outputHeaderSectionRows( std::vector< TableLayout::Colu for( std::size_t idxColumn = 0; idxColumn < tableColumnsData.size(); ++idxColumn ) { auto const & tableColumnData = tableColumnsData[idxColumn]; - string cell = tableColumnData.column.splitColumnNames.at( idxRow ); - string cellSize = stringutilities::join( tableColumnData.maxStringSize, spaces ); + string const cell = tableColumnData.column.splitColumnNames.at( idxRow ); + size_t const cellSize = tableColumnData.maxStringSize; tableOutput << buildCell( tableColumnData.column.alignmentSettings.headerAlignment, cell, - cellSize.length()); + cellSize ); // Add space between tableColumnsData if( idxColumn < tableColumnsData.size() - 1 ) @@ -564,12 +503,14 @@ void TableTextFormatter::outputSubSection( std::vector< TableLayout::ColumnStruc integer idxRow ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); - for( size_t idxCol = 0; idxCol< tableColumnsData.size(); ++idxCol ) + for( auto const & tableColumnData : tableColumnsData ) { - tableOutput << buildCell( tableColumnsData[idxCol].column.alignmentSettings.valueAlignment, - tableColumnsData[idxCol].columnValues[idxRow], - tableColumnsData[idxCol].maxStringSize[0].length() ); - if( idxCol < tableColumnsData.size() - 1 ) + string const cell = tableColumnData.columnValues[idxRow]; + size_t const cellSize = tableColumnData.maxStringSize; + tableOutput << buildCell( tableColumnData.column.alignmentSettings.valueAlignment, + cell, + cellSize ); + if( &tableColumnData < &tableColumnsData.back() ) { tableOutput << GEOS_FMT( "{:^{}}", m_verticalLine, columnMargin ); } @@ -601,10 +542,10 @@ void TableTextFormatter::outputValuesSectionRows( std::vector< TableLayout::Colu else { string const cell = tableColumnData.columnValues.at( idxRow ); - string const cellSize = stringutilities::join( tableColumnData.maxStringSize, spaces ); + size_t const cellSize = tableColumnData.maxStringSize; tableOutput << buildCell( tableColumnData.column.alignmentSettings.valueAlignment, cell, - cellSize.length()); + cellSize ); } if( idxColumn < tableColumnsData.size() - 1 ) diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index c022bda362d..0f59f324578 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -192,10 +192,10 @@ class TableTextFormatter : public TableFormatter * @brief Split all header names by detecting the newline \\n character. and * set the same vector size for each split header and merge it into tableColumnsData * @param tableColumnsData The vector containg all tableColumnsData - * @param splitHeaders Vector to store the split header names for each tableColumnData + * @param allDividedHeaderParts Vector to store the split header names for each tableColumnData */ void splitAndMergeColumnHeaders( std::vector< TableLayout::ColumnStructure > & tableColumnsData, - std::vector< std::vector< string > > & splitHeaders ) const; + std::vector< std::vector< string > > & allDividedHeaderParts ) const; /** * @brief For each tableColumnData find and set the column's longest string @@ -206,16 +206,19 @@ class TableTextFormatter : public TableFormatter * @note Compares the longest string from the header with the longest string from the column values. * If the column contains subcolumns, it recursively applies the same logic to them */ - void findAndSetLongestColumnString( TableLayout::ColumnStructure & tableColumnData, - std::vector< string > & maxStringSize, - integer const idxColumn ) const; + void findAndSetLongestColumnString( TableLayout::ColumnStructure & tableColumnData ) const; /** * @brief Compute the max table line length, taking into account the length of : title, tableColumnsData header/values - * Increase the size of the tableColumnsData if necessary + * Increase the size of the tableColumnsData if necessary then builds the table's separating lines + * * @param tableColumnsData Vector of tableColumnData containing containing the largest string for each tableColumnData + * @param sectionSeparatingLine Separator string used between sections of the table + * @param topSeparator The table top separator */ - void computeTableWidth( std::vector< TableLayout::ColumnStructure > & tableColumnsData ) const; + void computeAndBuildTableSeparator( std::vector< TableLayout::ColumnStructure > & tableColumnsData, + string & sectionSeparatingLine, + string & topSeparato ) const; /** * @brief Increase each tableColumnData size if the title is larger than all the tableColumnsData @@ -223,17 +226,7 @@ class TableTextFormatter : public TableFormatter * @param extraCharacters ExtraCharacters to be distributed between each tableColumnsData */ void increaseColumnsSize( std::vector< TableLayout::ColumnStructure > & tableColumnsData, - real64 const extraCharacters ) const; - - /** - * @brief Builds the table's separating lines based on the content length of the tableColumnsData . - * @param tableColumnsData Vector containing all table tableColumnsData - * @param sectionSeparatingLine Separator string used between sections of the table - * @param topSeparator The table top separator - */ - void buildTableSeparators( std::vector< TableLayout::ColumnStructure > const & tableColumnsData, - string & sectionSeparatingLine, - string & topSeparator ) const; + size_t const extraCharacters ) const; /** * @brief Output the title row in the table diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 88df7faac5d..eb2d280c619 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -142,7 +142,7 @@ class TableLayout /// A vector containing all the values of a column std::vector< string > columnValues; /// Vector of string containing the largest string for a column and its subColumns - std::vector< string > maxStringSize; + size_t maxStringSize; /// Vector containing all sub columns subdivison std::vector< ColumnStructure > subColumn; @@ -172,14 +172,13 @@ class TableLayout */ ColumnStructure ( Column const & col, std::vector< string > const & columnValuesInit, - std::vector< string > const & maxStringSizeInit, + size_t const maxStringSizeInit, std::vector< ColumnStructure > const & subColumnInit ) : column( col ), columnValues( columnValuesInit ), maxStringSize( maxStringSizeInit ), subColumn( subColumnInit ) {} - }; /// Alias for an initializer list of variants that can contain either a string or a layout column. From d81654c9e94e398c51366a81e758a86470c48e9c Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 6 Nov 2024 10:04:18 +0100 Subject: [PATCH 215/216] remove code / doc --- .../common/format/table/TableFormatter.cpp | 4 +--- .../common/format/table/TableFormatter.hpp | 9 ++++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 18543c6947e..8d65d1f6244 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -343,14 +343,12 @@ void TableTextFormatter::findAndSetLongestColumnString( TableLayout::ColumnStruc { // subcolumn values case size_t totalLengthSubColumns = 0; - size_t lengthSubColumns = 0; if( !tableColumnData.subColumn.empty() ) { for( auto & subColumn : tableColumnData.subColumn ) { findAndSetLongestColumnString( subColumn ); totalLengthSubColumns += subColumn.maxStringSize; - lengthSubColumns += subColumn.maxStringSize; if( &subColumn != &tableColumnData.subColumn[0] ) { totalLengthSubColumns += m_tableLayout.getColumnMargin(); @@ -358,7 +356,7 @@ void TableTextFormatter::findAndSetLongestColumnString( TableLayout::ColumnStruc } } - if( lengthSubColumns > tableColumnData.maxStringSize ) + if( totalLengthSubColumns > tableColumnData.maxStringSize ) { tableColumnData.maxStringSize = totalLengthSubColumns; } diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 0f59f324578..d474b60c80a 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -190,7 +190,7 @@ class TableTextFormatter : public TableFormatter /** * @brief Split all header names by detecting the newline \\n character. and - * set the same vector size for each split header and merge it into tableColumnsData + * set the same vector size for each divided header and merge it into tableColumnsData * @param tableColumnsData The vector containg all tableColumnsData * @param allDividedHeaderParts Vector to store the split header names for each tableColumnData */ @@ -210,19 +210,18 @@ class TableTextFormatter : public TableFormatter /** * @brief Compute the max table line length, taking into account the length of : title, tableColumnsData header/values - * Increase the size of the tableColumnsData if necessary then builds the table's separating lines - * + * Increase the size of the tableColumnsData if necessary, then builds the table's separating lines * @param tableColumnsData Vector of tableColumnData containing containing the largest string for each tableColumnData * @param sectionSeparatingLine Separator string used between sections of the table * @param topSeparator The table top separator */ void computeAndBuildTableSeparator( std::vector< TableLayout::ColumnStructure > & tableColumnsData, string & sectionSeparatingLine, - string & topSeparato ) const; + string & topSeparator ) const; /** * @brief Increase each tableColumnData size if the title is larger than all the tableColumnsData - * @param tableColumnsData Vector containing all table tableColumnsData + * @param tableColumnsData Vector containing all table tableColumnsData * @param extraCharacters ExtraCharacters to be distributed between each tableColumnsData */ void increaseColumnsSize( std::vector< TableLayout::ColumnStructure > & tableColumnsData, From e56d538bb837aece6c0e66bdc21e6acd1b57a8f9 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 7 Nov 2024 10:36:25 +0100 Subject: [PATCH 216/216] add assert for transporse --- src/coreComponents/common/format/table/TableFormatter.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 8d65d1f6244..992cba9b46d 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -88,10 +88,8 @@ void transpose( std::vector< std::vector< string > > & dest, for( size_t idxRow = 0; idxRow < source.size(); ++idxRow ) { - // GEOS_ERROR_IF( dest.size() != source[idxRow].size(), "Dest matrix must have the number of rows equal to the number of columns in the - // source matrix" ); - // GEOS_ERROR_IF( dest[idxRow].size() != source.size(), "Dest matrix must have the number of columns equal to the number of rows in the - // source matrix." ); + GEOS_ERROR_IF( dest.size() != source[idxRow].size(), "Dest matrix must have the number of rows equal to the number of columns in the" \ + "source matrix" ); for( size_t idxCol = 0; idxCol < source[idxRow].size(); ++idxCol ) { dest[idxCol][idxRow] = source[idxRow][idxCol];