From 751a91919fb8d1a4f806f65d197be0dade06be0f Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 9 Feb 2024 16:11:56 +0100 Subject: [PATCH 001/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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/206] 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 e4fea40402fd4b00c094b94058e4dd4734a6c80d Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 29 Feb 2024 14:45:37 +0100 Subject: [PATCH 024/206] first version Section --- .../codingUtilities/CMakeLists.txt | 4 +- .../codingUtilities/Section.cpp | 117 ++++++++++++++++++ .../codingUtilities/Section.hpp | 100 +++++++++++++++ src/coreComponents/events/EventManager.cpp | 25 ++-- .../mesh/generators/WellGeneratorBase.cpp | 8 +- 5 files changed, 241 insertions(+), 13 deletions(-) create mode 100644 src/coreComponents/codingUtilities/Section.cpp create mode 100644 src/coreComponents/codingUtilities/Section.hpp diff --git a/src/coreComponents/codingUtilities/CMakeLists.txt b/src/coreComponents/codingUtilities/CMakeLists.txt index 5ccef926155..3aa4d954b6b 100644 --- a/src/coreComponents/codingUtilities/CMakeLists.txt +++ b/src/coreComponents/codingUtilities/CMakeLists.txt @@ -10,6 +10,7 @@ set( codingUtilities_headers Utilities.hpp traits.hpp Table.hpp + Section.hpp ) # @@ -18,7 +19,8 @@ set( codingUtilities_headers set( codingUtilities_sources Parsing.cpp StringUtilities.cpp - Table.cpp ) + Table.cpp + Section.cpp ) set( dependencyList ${parallelDeps} common fast_float ) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp new file mode 100644 index 00000000000..6befa7e366a --- /dev/null +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -0,0 +1,117 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * 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 Section.cpp + */ + +#include "Section.hpp" + +namespace geos +{ + +void Section::setName( string_view title ) +{ + m_sectionTitle = title; +} + +void Section::addDescription( string const & description ) +{ + m_vDescriptions.push_back( description ); +} + +void Section::computeMaxRowSize( string const & title, + std::vector< string > const & rowsDescription ) +{ + integer marginBorder = 2; + integer nbSpecialChar = 2; + integer maxDescriptionLength = 0; + integer titleLength = title.length() + marginBorder * 2 + nbSpecialChar * 2; + + if( rowsDescription.size() == 0 ) + { + m_rowLength = titleLength; + return; + } + + auto it = std::max_element( rowsDescription.begin(), + rowsDescription.end(), + []( const auto & a, const auto & b ) { + return a.size() < b.size(); + } ); + + string maxDescriptionSize = *it; + + maxDescriptionLength = integer( maxDescriptionSize.length()) + marginBorder * 2 + nbSpecialChar * 2; + + m_rowLength = maxDescriptionLength > titleLength ? maxDescriptionLength : titleLength; +} + +void Section::buildLineSection( string & lineSection ) +{ + lineSection = GEOS_FMT( "{:#>{}}\n", "", m_rowLength ); +} + +void Section::addTitleRow( string & sectionToBeBuilt, string const & title ) +{ + sectionToBeBuilt += GEOS_FMT( "##{:^{}}##\n", title, m_rowLength - 4 ); +} + +void Section::addEndSectionRow( string & sectionToBeBuilt, string const & title ) +{ + sectionToBeBuilt += GEOS_FMT( "##{:^{}}##\n", title, m_rowLength - 4 ); +} + +void Section::addDescriptionRows( string & sectionToBeBuilt, std::vector< string > const & rowValues ) +{ + for( string rowValue : rowValues ) + { + sectionToBeBuilt += GEOS_FMT( "## {:<{}}##\n", rowValue, m_rowLength - 6 ); + } +} + +void Section::begin( std::ostream & oss ) +{ + string lineSection; + string sectionToBeBuilt; + string titleToAdd = "Section : " + m_sectionTitle; + + computeMaxRowSize( titleToAdd, m_vDescriptions ); + buildLineSection( lineSection ); + + sectionToBeBuilt += '\n' + lineSection; + addTitleRow( sectionToBeBuilt, titleToAdd ); + sectionToBeBuilt += lineSection; + addDescriptionRows( sectionToBeBuilt, m_vDescriptions ); + sectionToBeBuilt += '\n'; + + oss << sectionToBeBuilt; +} + +void Section::end( std::ostream & oss ) +{ + string lineSection; + string sectionToBeBuilt; + string titleToAdd = "End : " + m_sectionTitle; + + buildLineSection( lineSection ); + + sectionToBeBuilt += '\n'; + addTitleRow( sectionToBeBuilt, titleToAdd ); + sectionToBeBuilt += lineSection; + sectionToBeBuilt += '\n'; + + oss << sectionToBeBuilt; +} +} diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/codingUtilities/Section.hpp new file mode 100644 index 00000000000..62286607937 --- /dev/null +++ b/src/coreComponents/codingUtilities/Section.hpp @@ -0,0 +1,100 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * 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 Section.hpp + */ + +#ifndef GEOS_COMMON_SECTION_HPP +#define GEOS_COMMON_SECTION_HPP + +#include "common/DataTypes.hpp" + +namespace geos +{ + +class Section +{ +public: + + /** + * @brief Set the name of the section + * @param m_sectionTitle The name of the section + */ + void setName( string_view m_sectionTitle ); + + /** + * @brief Add a description to the section + * @param description The string value of the description + */ + void addDescription( string const & description ); + + /** + * @brief Draw the first part of the section. It include the title and, optionnaly, the description(s); + * @param os An output stream (by default, std::cout) + */ + void begin( std::ostream & os = std::cout ); + + /** + * @brief Draw the last part of the section. It include the title + * @param oss An output stream (by default, std::cout) + */ + void end( std::ostream & oss = std::cout ); +private: + + /** + * @brief Compute the max sectionToBeBuilt size (m_rowLength) between title and the description(s) + * @param m_sectionTitle The title of the table + * @param vDescriptions The vector of descriptions + */ + void computeMaxRowSize( string const & m_sectionTitle, + std::vector< string > const & vDescriptions ); + + /** + * @brief Build the line section in order to build the section + * @param lineSection An empty string + */ + void buildLineSection( string & lineSection ); + + /** + * @brief Build and add the title to the first part of the section + * @param sectionToBeBuilt The current section being built + * @param title The section name + */ + void addTitleRow( string & sectionToBeBuilt, string const & title ); + + /** + * @brief Build and add the title to the last part of the section + * @param sectionToBeBuilt The current section being built + * @param title The section name + */ + void addEndSectionRow( string & sectionToBeBuilt, string const & title ); + + /** + * @brief Build and add the descriptions to the first part of the section + * @param sectionToBeBuilt The current section being built + * @param rowsValue The vector of descriptions + */ + void addDescriptionRows( string & sectionToBeBuilt, std::vector< string > const & rowsValue ); + + std::vector< string > m_vDescriptions; + + string m_sectionTitle; + integer m_rowLength; +}; +} + + + +#endif diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index 3ebb6c2af44..69b06e9f2c3 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -22,6 +22,7 @@ #include "events/EventBase.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "common/Units.hpp" +#include "codingUtilities/Section.hpp" namespace geos { @@ -170,6 +171,18 @@ bool EventManager::run( DomainPartition & domain ) #endif } + string timeDescription = "- Time: " + units::TimeFormatInfo::fromSeconds( m_time ).toString(); + string deltaDescription = "- Delta time: " + units::TimeFormatInfo::fromSeconds( m_dt ).toString(); + string cycleDescription = "- Cycle: " + std::to_string( m_cycle ); + + Section section; + section.setName( "TIMESTEP START" ); + section.addDescription( timeDescription ); + section.addDescription( deltaDescription ); + section.addDescription( cycleDescription ); + // The formating here is a work in progress. + section.begin(); + outputTime(); // Execute @@ -207,6 +220,7 @@ bool EventManager::run( DomainPartition & domain ) } } + section.end(); // Increment time/cycle, reset the subevent counter m_time += m_dt; ++m_cycle; @@ -226,17 +240,6 @@ bool EventManager::run( DomainPartition & domain ) void EventManager::outputTime() const { - // The formating here is a work in progress. - GEOS_LOG_RANK_0( GEOS_FMT( "\n" - "------------------- TIMESTEP START -------------------\n" - " - Time: {}\n" - " - Delta Time: {}\n" - " - Cycle: {}\n" - "------------------------------------------------------\n\n", - units::TimeFormatInfo::fromSeconds( m_time ), - units::TimeFormatInfo::fromSeconds( m_dt ), - m_cycle )); - // We are keeping the old outputs to keep compatibility with current log reading scripts. if( m_timeOutputFormat==TimeOutputFormat::full ) { diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index add98afe168..cf1da1604ed 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -18,6 +18,7 @@ #include "mesh/generators/LineBlockABC.hpp" #include "LvArray/src/genericTensorOps.hpp" #include "codingUtilities/Table.hpp" +#include "codingUtilities/Section.hpp" #include "common/Format.hpp" namespace geos { @@ -531,6 +532,11 @@ void WellGeneratorBase::debugWellGeometry() const std::vector< string > row; std::ostringstream oss; + + Section wellGeneratorSection; + wellGeneratorSection.setName("Well generator"); + wellGeneratorSection.begin(); + Table table = Table( { Table::ColumnParam{{"Element no."}, Table::Alignment::right}, Table::ColumnParam{{"CoordX"}, Table::Alignment::middle}, @@ -585,7 +591,7 @@ void WellGeneratorBase::debugWellGeometry() const } tablePerforation.draw(); - + wellGeneratorSection.end(); } } From f67e3d9ff85cc3badb20c33dfda94058af7c107f Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 29 Feb 2024 16:05:42 +0100 Subject: [PATCH 025/206] 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 14920eff255550e8b23404a60d68c0f14fa33619 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 29 Feb 2024 16:42:15 +0100 Subject: [PATCH 026/206] function min width added --- src/coreComponents/codingUtilities/Section.cpp | 16 ++++++++++++++-- src/coreComponents/codingUtilities/Section.hpp | 18 +++++++++++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp index 6befa7e366a..0d0fb0f0b8e 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -17,10 +17,15 @@ */ #include "Section.hpp" +#include namespace geos { +Section::Section(): + m_rowMinWidth( 20 ) +{} + void Section::setName( string_view title ) { m_sectionTitle = title; @@ -31,6 +36,11 @@ void Section::addDescription( string const & description ) m_vDescriptions.push_back( description ); } +void Section::setMinWidth( integer const & minWidth ) +{ + m_rowMinWidth = minWidth; +} + void Section::computeMaxRowSize( string const & title, std::vector< string > const & rowsDescription ) { @@ -39,9 +49,11 @@ void Section::computeMaxRowSize( string const & title, integer maxDescriptionLength = 0; integer titleLength = title.length() + marginBorder * 2 + nbSpecialChar * 2; + + m_rowLength = std::max( m_rowMinWidth, titleLength ); + if( rowsDescription.size() == 0 ) { - m_rowLength = titleLength; return; } @@ -55,7 +67,7 @@ void Section::computeMaxRowSize( string const & title, maxDescriptionLength = integer( maxDescriptionSize.length()) + marginBorder * 2 + nbSpecialChar * 2; - m_rowLength = maxDescriptionLength > titleLength ? maxDescriptionLength : titleLength; + m_rowLength = std::max( maxDescriptionLength, m_rowLength ); } void Section::buildLineSection( string & lineSection ) diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/codingUtilities/Section.hpp index 62286607937..0de85b67985 100644 --- a/src/coreComponents/codingUtilities/Section.hpp +++ b/src/coreComponents/codingUtilities/Section.hpp @@ -28,6 +28,8 @@ class Section { public: + Section(); + /** * @brief Set the name of the section * @param m_sectionTitle The name of the section @@ -40,6 +42,11 @@ class Section */ void addDescription( string const & description ); + /** + * @brief Set the minimal width of a row + * @param minWidth the minnimal width to set + */ + void setMinWidth( integer const & minWidth ); /** * @brief Draw the first part of the section. It include the title and, optionnaly, the description(s); * @param os An output stream (by default, std::cout) @@ -68,21 +75,21 @@ class Section void buildLineSection( string & lineSection ); /** - * @brief Build and add the title to the first part of the section + * @brief Build and add the title to the first part of the section * @param sectionToBeBuilt The current section being built - * @param title The section name + * @param title The section name */ void addTitleRow( string & sectionToBeBuilt, string const & title ); /** * @brief Build and add the title to the last part of the section * @param sectionToBeBuilt The current section being built - * @param title The section name + * @param title The section name */ void addEndSectionRow( string & sectionToBeBuilt, string const & title ); - + /** - * @brief Build and add the descriptions to the first part of the section + * @brief Build and add the descriptions to the first part of the section * @param sectionToBeBuilt The current section being built * @param rowsValue The vector of descriptions */ @@ -92,6 +99,7 @@ class Section string m_sectionTitle; integer m_rowLength; + integer m_rowMinWidth; }; } From 57d2fb5437710a3202a6ee5b5b51726f785c0e5f Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 29 Feb 2024 17:19:37 +0100 Subject: [PATCH 027/206] setup testSection(empty for the moment) --- .../codingUtilities/tests/CMakeLists.txt | 3 +- .../codingUtilities/tests/testSection.cpp | 84 +++++++++++++++++++ src/coreComponents/events/EventManager.cpp | 1 + 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/coreComponents/codingUtilities/tests/testSection.cpp diff --git a/src/coreComponents/codingUtilities/tests/CMakeLists.txt b/src/coreComponents/codingUtilities/tests/CMakeLists.txt index 734991b3b91..521e056782f 100644 --- a/src/coreComponents/codingUtilities/tests/CMakeLists.txt +++ b/src/coreComponents/codingUtilities/tests/CMakeLists.txt @@ -3,7 +3,8 @@ set( testSources testGeosxTraits.cpp testStringUtilities.cpp testParsing.cpp - testTable.cpp ) + testTable.cpp + testSection.cpp ) set( dependencyList gtest codingUtilities ${parallelDeps} ) diff --git a/src/coreComponents/codingUtilities/tests/testSection.cpp b/src/coreComponents/codingUtilities/tests/testSection.cpp new file mode 100644 index 00000000000..d86445a214a --- /dev/null +++ b/src/coreComponents/codingUtilities/tests/testSection.cpp @@ -0,0 +1,84 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * 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. + * ------------------------------------------------------------------------------------------------------------ + */ + +#include "../../dataRepository/Group.hpp" +// TPL includes +#include "codingUtilities/Section.hpp" +#include + +using namespace geos; + +TEST( sectionTable, sectionClass ) +{ + std::vector< string > testSectionOutput; + + std::ostringstream oss; + + Section section1; + section1.setName( "section name" ); + section1.begin( oss ); + testSectionOutput.push_back( oss.str() ); + oss.clear(); + oss.str( "" ); + EXPECT_EQ( testSectionOutput[0], "" ); + + section1.end( oss ); + testSectionOutput.push_back( oss.str() ); + oss.clear(); + oss.str( "" ); + EXPECT_EQ( testSectionOutput[1], "" ); + + Section section2; + section2.setName( "section name" ); + section2.addDescription( "description name" ); + section2.begin( oss ); + testSectionOutput.push_back( oss.str() ); + oss.clear(); + oss.str( "" ); + EXPECT_EQ( testSectionOutput[2], "" ); + + Section section3; + section3.setName( "section name" ); + section3.addDescription( "description name 1" ); + section3.addDescription( "description name 2" ); + section3.begin( oss ); + testSectionOutput.push_back( oss.str() ); + oss.clear(); + oss.str( "" ); + EXPECT_EQ( testSectionOutput[3], "" ); + + Section section4; + section4.setName( "section name" ); + section4.addDescription( "description name 1" ); + section4.addDescription( "description name 2" ); + section4.setMinWidth( 100 ); + section4.begin( oss ); + testSectionOutput.push_back( oss.str() ); + oss.clear(); + oss.str( "" ); + EXPECT_EQ( testSectionOutput[4], "" ); + section4.end( oss ); + testSectionOutput.push_back( oss.str() ); + oss.clear(); + oss.str( "" ); + EXPECT_EQ( testSectionOutput[5], "" ); + + +} + +int main( int argc, char * * argv ) +{ + testing::InitGoogleTest( &argc, argv ); + return RUN_ALL_TESTS();; +} diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index 69b06e9f2c3..e8d7a04da83 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -180,6 +180,7 @@ bool EventManager::run( DomainPartition & domain ) section.addDescription( timeDescription ); section.addDescription( deltaDescription ); section.addDescription( cycleDescription ); + section.setMinWidth(100); // The formating here is a work in progress. section.begin(); From 3c928da09d50def6b0c57195e279c6c4900f80b1 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 1 Mar 2024 15:57:02 +0100 Subject: [PATCH 028/206] test section finished --- .../codingUtilities/tests/testSection.cpp | 110 ++++++++++-------- 1 file changed, 61 insertions(+), 49 deletions(-) diff --git a/src/coreComponents/codingUtilities/tests/testSection.cpp b/src/coreComponents/codingUtilities/tests/testSection.cpp index d86445a214a..94935a1f30a 100644 --- a/src/coreComponents/codingUtilities/tests/testSection.cpp +++ b/src/coreComponents/codingUtilities/tests/testSection.cpp @@ -19,61 +19,73 @@ using namespace geos; -TEST( sectionTable, sectionClass ) +TEST( testSection, sectionClass ) { - std::vector< string > testSectionOutput; std::ostringstream oss; - Section section1; - section1.setName( "section name" ); - section1.begin( oss ); - testSectionOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( testSectionOutput[0], "" ); + //testing section format with only title + { + Section section; + section.setName( "section name" ); + section.begin( oss ); + EXPECT_EQ( oss.str(), + "\n##############################\n" + "## Section : section name ##\n" + "##############################\n\n" + ); + oss.clear(); + oss.str( "" ); + section.end( oss ); + EXPECT_EQ( oss.str(), + "\n## End : section name ##\n" + "##############################\n\n" + ); + oss.clear(); + oss.str( "" ); + } - section1.end( oss ); - testSectionOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( testSectionOutput[1], "" ); - - Section section2; - section2.setName( "section name" ); - section2.addDescription( "description name" ); - section2.begin( oss ); - testSectionOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( testSectionOutput[2], "" ); - - Section section3; - section3.setName( "section name" ); - section3.addDescription( "description name 1" ); - section3.addDescription( "description name 2" ); - section3.begin( oss ); - testSectionOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( testSectionOutput[3], "" ); - - Section section4; - section4.setName( "section name" ); - section4.addDescription( "description name 1" ); - section4.addDescription( "description name 2" ); - section4.setMinWidth( 100 ); - section4.begin( oss ); - testSectionOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( testSectionOutput[4], "" ); - section4.end( oss ); - testSectionOutput.push_back( oss.str() ); - oss.clear(); - oss.str( "" ); - EXPECT_EQ( testSectionOutput[5], "" ); + //testing section format with title and one description + { + Section section; + section.setName( "section name" ); + section.addDescription( "description name" ); + section.begin( oss ); + EXPECT_EQ( oss.str(), + "\n##############################\n" + "## Section : section name ##\n" + "##############################\n" + "## description name ##\n\n" + ); + oss.clear(); + oss.str( "" ); + } + //testing section format with title and multiple description with min width + { + Section section; + section.setName( "section name" ); + section.addDescription( "description name 1" ); + section.addDescription( "description name 2" ); + section.setMinWidth( 100 ); + section.begin( oss ); + EXPECT_EQ( oss.str(), + "\n####################################################################################################\n" + "## Section : section name ##\n" + "####################################################################################################\n" + "## description name 1 ##\n" + "## description name 2 ##\n\n" + ); + oss.clear(); + oss.str( "" ); + section.end( oss ); + EXPECT_EQ( oss.str(), + "\n## End : section name ##\n" + "####################################################################################################\n\n" + ); + oss.clear(); + oss.str( "" ); + } } From 5b8689a79b4b93375b639444afda8e961db3d2b1 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 4 Mar 2024 11:08:48 +0100 Subject: [PATCH 029/206] 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 030/206] 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 36981d7032aa2f6082dc281f38754e7b12a6aa47 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 4 Mar 2024 11:38:31 +0100 Subject: [PATCH 031/206] doc correction --- src/coreComponents/codingUtilities/Section.cpp | 1 - src/coreComponents/codingUtilities/Section.hpp | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp index 0d0fb0f0b8e..c26be44a3c3 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -49,7 +49,6 @@ void Section::computeMaxRowSize( string const & title, integer maxDescriptionLength = 0; integer titleLength = title.length() + marginBorder * 2 + nbSpecialChar * 2; - m_rowLength = std::max( m_rowMinWidth, titleLength ); if( rowsDescription.size() == 0 ) diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/codingUtilities/Section.hpp index 0de85b67985..314f74a9aa7 100644 --- a/src/coreComponents/codingUtilities/Section.hpp +++ b/src/coreComponents/codingUtilities/Section.hpp @@ -44,11 +44,12 @@ class Section /** * @brief Set the minimal width of a row - * @param minWidth the minnimal width to set + * @param minWidth the minimal width of the table */ void setMinWidth( integer const & minWidth ); + /** - * @brief Draw the first part of the section. It include the title and, optionnaly, the description(s); + * @brief Draw the first part of the section. It include the title and optionnaly, the description(s); * @param os An output stream (by default, std::cout) */ void begin( std::ostream & os = std::cout ); @@ -61,7 +62,7 @@ class Section private: /** - * @brief Compute the max sectionToBeBuilt size (m_rowLength) between title and the description(s) + * @brief Compute the max string size (m_rowLength) between title and the description(s) * @param m_sectionTitle The title of the table * @param vDescriptions The vector of descriptions */ From bb1ee01722b6499c54b1012efe41ecf1fefaaef9 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 4 Mar 2024 17:10:09 +0100 Subject: [PATCH 032/206] 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 033/206] 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 034/206] 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 035/206] 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 036/206] 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 037/206] 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 038/206] 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 039/206] 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 040/206] 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 041/206] 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 042/206] 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 043/206] 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 044/206] 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 045/206] 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 046/206] 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 047/206] 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 048/206] 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 049/206] 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 050/206] 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 051/206] 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 052/206] 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 053/206] 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 054/206] 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 055/206] 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 056/206] 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 057/206] 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 058/206] 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 059/206] 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 060/206] 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 061/206] 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 062/206] 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 063/206] 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 064/206] 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 065/206] 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 066/206] 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 067/206] 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 068/206] 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 069/206] 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 070/206] 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 071/206] 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 072/206] 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 073/206] 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 074/206] 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 075/206] 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 076/206] 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 077/206] 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 078/206] 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 079/206] 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 080/206] 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 081/206] 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 e5365a0ad04833592ded1c1f905217564398f174 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 29 Mar 2024 16:18:58 +0100 Subject: [PATCH 082/206] merging correction --- .../codingUtilities/Section.cpp | 4 ++-- src/coreComponents/events/EventManager.cpp | 13 +++++++----- .../mesh/generators/WellGeneratorBase.cpp | 21 ------------------- 3 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp index c26be44a3c3..4b6ede9798b 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -44,8 +44,8 @@ void Section::setMinWidth( integer const & minWidth ) void Section::computeMaxRowSize( string const & title, std::vector< string > const & rowsDescription ) { - integer marginBorder = 2; - integer nbSpecialChar = 2; + static constexpr integer marginBorder = 2; + static constexpr integer nbSpecialChar = 2; integer maxDescriptionLength = 0; integer titleLength = title.length() + marginBorder * 2 + nbSpecialChar * 2; diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index e8d7a04da83..0f20a139f4c 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -176,11 +176,14 @@ bool EventManager::run( DomainPartition & domain ) string cycleDescription = "- Cycle: " + std::to_string( m_cycle ); Section section; - section.setName( "TIMESTEP START" ); - section.addDescription( timeDescription ); - section.addDescription( deltaDescription ); - section.addDescription( cycleDescription ); - section.setMinWidth(100); + section.setName( "section name" ); + section.addDescription( "description name 1" ); + section.addDescription( "description name 2" ); + section.setMinWidth( 100 ); + // section.addDescription( deltaDescription ); + // section.addDescription( cycleDescription ); + + // section.setMinWidth(100); // The formating here is a work in progress. section.begin(); diff --git a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp index df3efbc34ce..077718c7126 100644 --- a/src/coreComponents/mesh/generators/WellGeneratorBase.cpp +++ b/src/coreComponents/mesh/generators/WellGeneratorBase.cpp @@ -526,27 +526,6 @@ void WellGeneratorBase::mergePerforations( array1d< array1d< localIndex > > cons } } -void WellGeneratorBase::logInternalWell() const -{ - TableData tableWellData; - - Section wellGeneratorSection; - wellGeneratorSection.setName("Well generator"); - wellGeneratorSection.begin(); - - 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}, - } - ); - - string titleName = "InternalWellGenerator " + getName(); - table.setTitle( titleName ); - void WellGeneratorBase::logInternalWell() const { TableData tableWellData; 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 083/206] 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 084/206] 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 085/206] 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 086/206] 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 087/206] 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 088/206] 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 089/206] 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 090/206] 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 091/206] 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 092/206] 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 093/206] 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 094/206] 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 095/206] 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 096/206] 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 097/206] 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 098/206] 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 099/206] 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 100/206] 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 101/206] 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 102/206] 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 103/206] 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 104/206] 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 105/206] 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 106/206] 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 107/206] 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 108/206] 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 109/206] 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 110/206] 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 111/206] 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 112/206] 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 113/206] 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 114/206] 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 769d84d86d1feef2dd473d0fef66fc9212282384 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 15 May 2024 11:16:04 +0200 Subject: [PATCH 115/206] units test section refacto --- .../codingUtilities/Section.cpp | 2 +- .../codingUtilities/tests/testSection.cpp | 119 +++++++++--------- 2 files changed, 58 insertions(+), 63 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp index c26be44a3c3..ee630c315b6 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -96,7 +96,7 @@ void Section::begin( std::ostream & oss ) { string lineSection; string sectionToBeBuilt; - string titleToAdd = "Section : " + m_sectionTitle; + string const titleToAdd = "Section : " + m_sectionTitle; computeMaxRowSize( titleToAdd, m_vDescriptions ); buildLineSection( lineSection ); diff --git a/src/coreComponents/codingUtilities/tests/testSection.cpp b/src/coreComponents/codingUtilities/tests/testSection.cpp index 94935a1f30a..4c80d173d20 100644 --- a/src/coreComponents/codingUtilities/tests/testSection.cpp +++ b/src/coreComponents/codingUtilities/tests/testSection.cpp @@ -19,74 +19,69 @@ using namespace geos; -TEST( testSection, sectionClass ) +TEST( testSection, sectionWithTitle ) { - std::ostringstream oss; + Section section; + section.setName( "section name" ); + section.begin( oss ); + EXPECT_EQ( oss.str(), + "\n##############################\n" + "## Section : section name ##\n" + "##############################\n\n" + ); + oss.clear(); + oss.str( "" ); - //testing section format with only title - { - Section section; - section.setName( "section name" ); - section.begin( oss ); - EXPECT_EQ( oss.str(), - "\n##############################\n" - "## Section : section name ##\n" - "##############################\n\n" - ); - oss.clear(); - oss.str( "" ); - section.end( oss ); - EXPECT_EQ( oss.str(), - "\n## End : section name ##\n" - "##############################\n\n" - ); - oss.clear(); - oss.str( "" ); - } + section.end( oss ); + EXPECT_EQ( oss.str(), + "\n## End : section name ##\n" + "##############################\n\n" + ); + oss.clear(); +} - //testing section format with title and one description - { - Section section; - section.setName( "section name" ); - section.addDescription( "description name" ); - section.begin( oss ); - EXPECT_EQ( oss.str(), - "\n##############################\n" - "## Section : section name ##\n" - "##############################\n" - "## description name ##\n\n" - ); - oss.clear(); - oss.str( "" ); - } +TEST( testSection, sectionWithTitleAndOneDescription ) +{ + std::ostringstream oss; + Section section; + section.setName( "section name" ); + section.addDescription( "description name" ); + section.begin( oss ); + EXPECT_EQ( oss.str(), + "\n##############################\n" + "## Section : section name ##\n" + "##############################\n" + "## description name ##\n\n" + ); + oss.clear(); +} - //testing section format with title and multiple description with min width - { - Section section; - section.setName( "section name" ); - section.addDescription( "description name 1" ); - section.addDescription( "description name 2" ); - section.setMinWidth( 100 ); - section.begin( oss ); - EXPECT_EQ( oss.str(), - "\n####################################################################################################\n" - "## Section : section name ##\n" - "####################################################################################################\n" - "## description name 1 ##\n" - "## description name 2 ##\n\n" - ); - oss.clear(); - oss.str( "" ); - section.end( oss ); - EXPECT_EQ( oss.str(), - "\n## End : section name ##\n" - "####################################################################################################\n\n" - ); - oss.clear(); - oss.str( "" ); - } +TEST( testSection, sectionWithSetWidth ) +{ + std::ostringstream oss; + Section section; + section.setName( "section name" ); + section.addDescription( "description name 1" ); + section.addDescription( "description name 2" ); + section.setMinWidth( 100 ); + section.begin( oss ); + EXPECT_EQ( oss.str(), + "\n####################################################################################################\n" + "## Section : section name ##\n" + "####################################################################################################\n" + "## description name 1 ##\n" + "## description name 2 ##\n\n" + ); + oss.clear(); + oss.str( "" ); + section.end( oss ); + EXPECT_EQ( oss.str(), + "\n## End : section name ##\n" + "####################################################################################################\n\n" + ); + oss.clear(); } int main( int argc, char * * argv ) From abb994e950465f1bcae1126e416d1f6ca91bac88 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 17 May 2024 15:04:26 +0200 Subject: [PATCH 116/206] 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 117/206] 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 118/206] 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 119/206] 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 d55db27594ca5c7142b0808f6575dc1a8b7286aa Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 27 May 2024 10:10:44 +0200 Subject: [PATCH 120/206] update syntax --- src/coreComponents/codingUtilities/Section.cpp | 14 +++++++------- src/coreComponents/codingUtilities/Section.hpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp index 71bc48de8c4..d184eb39f51 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -74,12 +74,12 @@ void Section::buildLineSection( string & lineSection ) lineSection = GEOS_FMT( "{:#>{}}\n", "", m_rowLength ); } -void Section::addTitleRow( string & sectionToBeBuilt, string const & title ) +void Section::addTitleRow( string & sectionToBeBuilt, string_view title ) { sectionToBeBuilt += GEOS_FMT( "##{:^{}}##\n", title, m_rowLength - 4 ); } -void Section::addEndSectionRow( string & sectionToBeBuilt, string const & title ) +void Section::addEndSectionRow( string & sectionToBeBuilt, string_view title ) { sectionToBeBuilt += GEOS_FMT( "##{:^{}}##\n", title, m_rowLength - 4 ); } @@ -96,13 +96,13 @@ void Section::begin( std::ostream & oss ) { string lineSection; string sectionToBeBuilt; - string const titleToAdd = "Section : " + m_sectionTitle; + string const titleToDisplay = "Section : " + m_sectionTitle; - computeMaxRowSize( titleToAdd, m_vDescriptions ); + computeMaxRowSize( titleToDisplay, m_vDescriptions ); buildLineSection( lineSection ); sectionToBeBuilt += '\n' + lineSection; - addTitleRow( sectionToBeBuilt, titleToAdd ); + addTitleRow( sectionToBeBuilt, titleToDisplay ); sectionToBeBuilt += lineSection; addDescriptionRows( sectionToBeBuilt, m_vDescriptions ); sectionToBeBuilt += '\n'; @@ -114,12 +114,12 @@ void Section::end( std::ostream & oss ) { string lineSection; string sectionToBeBuilt; - string titleToAdd = "End : " + m_sectionTitle; + string titleToDisplay = "End : " + m_sectionTitle; buildLineSection( lineSection ); sectionToBeBuilt += '\n'; - addTitleRow( sectionToBeBuilt, titleToAdd ); + addTitleRow( sectionToBeBuilt, titleToDisplay ); sectionToBeBuilt += lineSection; sectionToBeBuilt += '\n'; diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/codingUtilities/Section.hpp index 314f74a9aa7..52292c38056 100644 --- a/src/coreComponents/codingUtilities/Section.hpp +++ b/src/coreComponents/codingUtilities/Section.hpp @@ -80,14 +80,14 @@ class Section * @param sectionToBeBuilt The current section being built * @param title The section name */ - void addTitleRow( string & sectionToBeBuilt, string const & title ); + void addTitleRow( string & sectionToBeBuilt, string_view title ); /** * @brief Build and add the title to the last part of the section * @param sectionToBeBuilt The current section being built * @param title The section name */ - void addEndSectionRow( string & sectionToBeBuilt, string const & title ); + void addEndSectionRow( string & sectionToBeBuilt, string_view title ); /** * @brief Build and add the descriptions to the first part of the section From 924d9559aa18e4dc967814eb1a83813210fa94f8 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 27 May 2024 11:07:52 +0200 Subject: [PATCH 121/206] 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 122/206] 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 123/206] 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 124/206] 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 125/206] 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 126/206] 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 127/206] 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 128/206] 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 129/206] 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 130/206] 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 131/206] 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 132/206] 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 133/206] 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 134/206] 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 135/206] 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 136/206] 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 137/206] 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 138/206] 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 139/206] 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 140/206] 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 141/206] 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 142/206] 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 143/206] 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 144/206] 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 145/206] 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 146/206] 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 147/206] 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 3b2fd4bdcdb90d5a5140be81a3a2ce816cec408e Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 4 Jul 2024 10:48:26 +0200 Subject: [PATCH 148/206] debug first merge --- .../codingUtilities/CMakeLists.txt | 1 + .../codingUtilities/tests/CMakeLists.txt | 1 - src/coreComponents/common/CMakeLists.txt | 6 - src/coreComponents/common/TableData.cpp | 71 ---- src/coreComponents/common/TableData.hpp | 125 ------ src/coreComponents/common/TableFormatter.cpp | 388 ------------------ src/coreComponents/common/TableFormatter.hpp | 183 --------- src/coreComponents/common/TableLayout.cpp | 81 ---- src/coreComponents/common/TableLayout.hpp | 147 ------- .../common/unitTests/CMakeLists.txt | 1 - .../common/unitTests/testTable.cpp | 263 ------------ src/coreComponents/fileIO/Table/TableData.cpp | 39 +- src/coreComponents/fileIO/Table/TableData.hpp | 30 +- .../fileIO/Table/TableFormatter.cpp | 9 +- .../fileIO/Table/TableFormatter.hpp | 55 ++- .../fileIO/Table/TableLayout.hpp | 2 + .../fileIO/Table/unitTests/testTable.cpp | 12 +- .../physicsSolvers/FieldStatisticsBase.hpp | 2 +- 18 files changed, 125 insertions(+), 1291 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/codingUtilities/CMakeLists.txt b/src/coreComponents/codingUtilities/CMakeLists.txt index ae0e20ddef7..ece6d72babf 100644 --- a/src/coreComponents/codingUtilities/CMakeLists.txt +++ b/src/coreComponents/codingUtilities/CMakeLists.txt @@ -18,6 +18,7 @@ set( codingUtilities_headers set( codingUtilities_sources Parsing.cpp StringUtilities.cpp + Section.cpp ) set( dependencyList ${parallelDeps} common fast_float ) diff --git a/src/coreComponents/codingUtilities/tests/CMakeLists.txt b/src/coreComponents/codingUtilities/tests/CMakeLists.txt index 24db43bf9c8..92a02cfeb3f 100644 --- a/src/coreComponents/codingUtilities/tests/CMakeLists.txt +++ b/src/coreComponents/codingUtilities/tests/CMakeLists.txt @@ -10,7 +10,6 @@ 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/common/CMakeLists.txt b/src/coreComponents/common/CMakeLists.txt index b1f5ccaf8e3..1d829c19f2d 100644 --- a/src/coreComponents/common/CMakeLists.txt +++ b/src/coreComponents/common/CMakeLists.txt @@ -16,9 +16,6 @@ set( common_headers Path.hpp Span.hpp Stopwatch.hpp - TableFormatter.hpp - TableData.hpp - TableLayout.hpp Timer.hpp Tensor.hpp TimingMacros.hpp @@ -48,9 +45,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/TableData.cpp b/src/coreComponents/common/TableData.cpp deleted file mode 100644 index 1d29d5ef760..00000000000 --- a/src/coreComponents/common/TableData.cpp +++ /dev/null @@ -1,71 +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; -} - -std::set< real64 > const & TableData2D::getColumns() const -{ - return m_columns; -} -std::set< real64 > const & TableData2D::getRows() const -{ - return m_rows; -} - -TableData TableData2D::buildTableData() 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 ); - - if( dataIt != m_data.end()) - { - values.push_back( GEOS_FMT( "{}", dataIt->second )); - } - - } - tableDataToBeBuilt.addRow( values ); - } - return tableDataToBeBuilt; -} - -} diff --git a/src/coreComponents/common/TableData.hpp b/src/coreComponents/common/TableData.hpp deleted file mode 100644 index 3598a27f1df..00000000000 --- a/src/coreComponents/common/TableData.hpp +++ /dev/null @@ -1,125 +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: - - /** - * @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. - * @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 - */ - 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 > m_data; - std::set< real64 > m_columns; - std::set< real64 > m_rows; -}; - -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" ); - 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 ); -} - -} - -#endif diff --git a/src/coreComponents/common/TableFormatter.cpp b/src/coreComponents/common/TableFormatter.cpp deleted file mode 100644 index 57479bfbfd4..00000000000 --- a/src/coreComponents/common/TableFormatter.cpp +++ /dev/null @@ -1,388 +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++ ) - { - 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 > & 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 33d82e73898..00000000000 --- a/src/coreComponents/common/TableFormatter.hpp +++ /dev/null @@ -1,183 +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: - - 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 > & 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 abd9c6818ba..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 4034ca3b6c9..00000000000 --- a/src/coreComponents/common/TableLayout.hpp +++ /dev/null @@ -1,147 +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/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/common/unitTests/testTable.cpp b/src/coreComponents/common/unitTests/testTable.cpp deleted file mode 100644 index 4aa91589582..00000000000 --- a/src/coreComponents/common/unitTests/testTable.cpp +++ /dev/null @@ -1,263 +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 - { - TableLayout const 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 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" - ); - - } -} - -int main( int argc, char * * argv ) -{ - testing::InitGoogleTest( &argc, argv ); - return RUN_ALL_TESTS();; -} diff --git a/src/coreComponents/fileIO/Table/TableData.cpp b/src/coreComponents/fileIO/Table/TableData.cpp index 2dbf7dfbe18..7d142d47a61 100644 --- a/src/coreComponents/fileIO/Table/TableData.cpp +++ b/src/coreComponents/fileIO/Table/TableData.cpp @@ -50,11 +50,42 @@ std::vector< string > const & TableData::getErrorMsgs() const return m_errorsMsg; } -TableData2D::Conversion1D TableData2D::buildTableData( string_view targetUnit, - string_view rowFmt, - string_view columnFmt ) const +void TableData2D::collectTableValues( arraySlice1d< real64 const > rowAxisValues, + arraySlice1d< real64 const > columnAxisValues, + arrayView1d< real64 const > values ) { - TableData2D::Conversion1D tableData1D; + integer const nX = rowAxisValues.size(); + integer const nY = columnAxisValues.size(); + + for( integer i = 0; i < nX; i++ ) + { + for( integer y = 0; y < nY; y++ ) + { + addCell( rowAxisValues[i], columnAxisValues[y], values[ y*nX + i ] ); + } + } +} + +TableData2D::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 ); + + collectTableValues( coordinates[0], coordinates[1], values ); + return buildTableData( string( units::getDescription( valueUnit )), + rowFmt, + columnFmt ); +} + +TableData2D::TableConversionData TableData2D::buildTableData( string_view targetUnit, + string_view rowFmt, + string_view columnFmt ) const +{ + 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 a3cf6a16d5c..c083e7fbe28 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" @@ -84,9 +85,10 @@ class TableData2D using ColumnType = real64; /// Struct containing conversion informations - struct Conversion1D + 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; @@ -102,6 +104,30 @@ class TableData2D template< typename T > void addCell( RowType rowValue, ColumnType columnValue, T const & value ); + /** + * @brief Collects all the values needed to build the table + * @param rowAxisValues Vector containing all row axis values + * @param columnAxisValues Vector containing all column axis values + * @param values Vector containing all table values + */ + void collectTableValues( arraySlice1d< real64 const > rowAxisValues, + arraySlice1d< real64 const > columnAxisValues, + arrayView1d< real64 const > values ); + + /** + * @param values Vector containing all table values + * @param valueUnit The table unit value + * @param coordinates Array containing row/column axis values + * @param rowAxisDescription The description for a row unit value + * @param columnAxisDescription The description for a column unit value + * @return A struct containing the tableData converted and all header values ; + */ + TableData2D::TableConversionData convertTable2D( arrayView1d< real64 const > const values, + units::Unit const valueUnit, + ArrayOfArraysView< real64 const > const coordinates, + string_view rowAxisDescription, + string_view columnAxisDescription ); + /** * @return Convert and return a struct containing a 1D Table, the column names list from a TableData2D and any errors related to the table * @param dataDescription The table dataDescription shown at the top left side @@ -111,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] = {}" */ - Conversion1D 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.cpp b/src/coreComponents/fileIO/Table/TableFormatter.cpp index d49204653d8..6ef7383f605 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.cpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.cpp @@ -16,9 +16,9 @@ * @file TableFormatter.cpp */ +#include "TableFormatter.hpp" #include #include "codingUtilities/StringUtilities.hpp" -#include "TableFormatter.hpp" namespace geos { @@ -66,7 +66,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 +151,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 +400,5 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); } } + } diff --git a/src/coreComponents/fileIO/Table/TableFormatter.hpp b/src/coreComponents/fileIO/Table/TableFormatter.hpp index 1e18452b562..4dc8f1d88c9 100644 --- a/src/coreComponents/fileIO/Table/TableFormatter.hpp +++ b/src/coreComponents/fileIO/Table/TableFormatter.hpp @@ -36,6 +36,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 +57,13 @@ class TableCSVFormatter : public TableFormatter { public: + /** + * @brief Construct a new Table Formatter + */ + TableCSVFormatter(): + TableFormatter( TableLayout() ) + {} + /** * @brief Construct a new Table Formatter from a tableLayout * @param tableLayout Contain all column names and optionnaly the table title @@ -79,28 +88,47 @@ class TableCSVFormatter : public TableFormatter string dataToString( TableData const & tableData ) const; /** - * @brief Convert the TableData to a table string. - * @param tableData The TableData to convert. - * @return The table string representation of the TableData. + * @brief Convert a data source to a CSV string. + * @tparam DATASOURCE The source to convert + * @param tableData The data source to convert + * @return The CSV string representation of a data source. */ - string toString( TableData const & tableData ) const; + template< typename DATASOURCE > + string toString( DATASOURCE const & tableData ) const; }; +/** + * @brief Convert the TableData to a CSV string. + * @param tableData The TableData to convert. + * @return The CSV string representation of the TableData. + */ +template<> +string TableCSVFormatter::toString< TableData >( TableData const & tableData ) const; + + /** * @brief class for log formatting */ class TableTextFormatter : public TableFormatter { - public: + + /** + * @brief Construct a new TableFormatter + */ + TableTextFormatter(): + TableFormatter( TableLayout() ) + {} + /** * @brief Construct a new TableFormatter from a tableLayout * @param tableLayout Contain all column names and optionnaly the table title */ TableTextFormatter( TableLayout const & tableLayout ); + /** * @brief Destroy the Table Text Formatter object */ @@ -112,11 +140,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 +154,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 +245,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 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..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::Conversion1D 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::Conversion1D 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/physicsSolvers/FieldStatisticsBase.hpp b/src/coreComponents/physicsSolvers/FieldStatisticsBase.hpp index ff692298342..02d005b6858 100644 --- a/src/coreComponents/physicsSolvers/FieldStatisticsBase.hpp +++ b/src/coreComponents/physicsSolvers/FieldStatisticsBase.hpp @@ -58,7 +58,7 @@ class FieldStatisticsBase : public TaskBase setDescription( "Name of the " + SOLVER::coupledSolverAttributePrefix() + " solver" ); this->registerWrapper( viewKeyStruct::writeCSVFlagString(), &m_writeCSV ). - setApplyDefaultValue( 0 ). + setApplyDefaultValue( 1 ). setInputFlag( dataRepository::InputFlags::OPTIONAL ). setDescription( "Write statistics into a CSV file" ); } From 83c80b2ca654aa0fa22d57ca0d0bdb3adfdcb880 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 4 Jul 2024 11:39:33 +0200 Subject: [PATCH 149/206] 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 150/206] 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 e1a795997c4467f7ce341c9e4a41f39756861f70 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 4 Jul 2024 17:33:50 +0200 Subject: [PATCH 151/206] IN PROGRESS: first path for dynamic section --- .../codingUtilities/Section.cpp | 54 +++++++++++++++++- .../codingUtilities/Section.hpp | 16 +++++- .../multifluid/CO2Brine/CO2BrineFluid.cpp | 1 - src/coreComponents/dataRepository/Group.cpp | 1 + src/coreComponents/events/EventManager.cpp | 57 +++++++++---------- src/coreComponents/events/EventManager.hpp | 3 +- .../functions/TableFunction.cpp | 3 - .../mainInterface/ProblemManager.cpp | 7 ++- 8 files changed, 101 insertions(+), 41 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp index d184eb39f51..b94d4d50f42 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -33,7 +33,13 @@ void Section::setName( string_view title ) void Section::addDescription( string const & description ) { - m_vDescriptions.push_back( description ); + m_descriptions.push_back( description ); +} + +void Section::addDescription( string const & descriptionName, std::vector< string > const & descriptionValues ) +{ + m_descriptionsValues.push_back( descriptionValues ); + m_descriptionNames.push_back( descriptionName ); } void Section::setMinWidth( integer const & minWidth ) @@ -92,19 +98,59 @@ void Section::addDescriptionRows( string & sectionToBeBuilt, std::vector< string } } +void Section::clear() +{ + m_descriptions.clear(); + m_sectionTitle.clear(); +} + void Section::begin( std::ostream & oss ) { string lineSection; string sectionToBeBuilt; string const titleToDisplay = "Section : " + m_sectionTitle; - computeMaxRowSize( titleToDisplay, m_vDescriptions ); + //TODO function and test and refacto below + if( m_descriptionsValues.empty()) + { + int maxLenName = 0; + computeMaxRowSize( "", m_descriptionNames ); + maxLenName = m_rowLength; + + if( m_descriptionsValues.length == 1 ) + { + m_descriptions.push_back( GEOS_FMT( " - {}:{}", m_descriptionNames[0], m_descriptionsValues[0] )); + } + else + { + int i = 0; + for( std::vector< string > descriptionsValues : m_descriptionsValues ) + { + string description = GEOS_FMT( " - {}:", m_descriptionNames[i] ); + for( string values: descriptionsValues ) + { + description += GEOS_FMT( "{:-<{}}", values, m_rowLength ); + m_descriptions.push_back(); + + } + i++; + } + } + } + + // check if descvalues empty + // split descValues into m_descriptions and set marginValues by default 0 + // marginValues is used to construct m_description so just here (?) + + //and back to normal... just need to format m_descriptions ! + //don't forget to rename variable and functions et to remove unused function ! + computeMaxRowSize( titleToDisplay, m_descriptions ); buildLineSection( lineSection ); sectionToBeBuilt += '\n' + lineSection; addTitleRow( sectionToBeBuilt, titleToDisplay ); sectionToBeBuilt += lineSection; - addDescriptionRows( sectionToBeBuilt, m_vDescriptions ); + addDescriptionRows( sectionToBeBuilt, m_descriptions ); sectionToBeBuilt += '\n'; oss << sectionToBeBuilt; @@ -124,5 +170,7 @@ void Section::end( std::ostream & oss ) sectionToBeBuilt += '\n'; oss << sectionToBeBuilt; + + clear(); } } diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/codingUtilities/Section.hpp index 52292c38056..99914612e63 100644 --- a/src/coreComponents/codingUtilities/Section.hpp +++ b/src/coreComponents/codingUtilities/Section.hpp @@ -36,6 +36,12 @@ class Section */ void setName( string_view m_sectionTitle ); + /** + * @brief Add a description to the section + * @param description The string value of the description + */ + void addDescription( string const & descriptionName, std::vector< string > const & descriptionValues ); + /** * @brief Add a description to the section * @param description The string value of the description @@ -75,6 +81,11 @@ class Section */ void buildLineSection( string & lineSection ); + /** + * @brief Clear all private field related to the current section + */ + void clear(); + /** * @brief Build and add the title to the first part of the section * @param sectionToBeBuilt The current section being built @@ -96,7 +107,10 @@ class Section */ void addDescriptionRows( string & sectionToBeBuilt, std::vector< string > const & rowsValue ); - std::vector< string > m_vDescriptions; + std::vector< string > m_descriptions; + + std::vector< string > m_descriptionNames; + std::vector< std::vector< string > > m_descriptionsValues; string m_sectionTitle; integer m_rowLength; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 64ba4d92bdb..00ba86294a4 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -348,7 +348,6 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() 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 if( !m_flashModelParaFile.empty()) { diff --git a/src/coreComponents/dataRepository/Group.cpp b/src/coreComponents/dataRepository/Group.cpp index a6cc0126a8e..8d81716a94b 100644 --- a/src/coreComponents/dataRepository/Group.cpp +++ b/src/coreComponents/dataRepository/Group.cpp @@ -354,6 +354,7 @@ void Group::initialize_postMeshGeneration() void Group::initialize() { + initializePreSubGroups(); array1d< string > initOrder; diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index bcefacfa6ed..cbe3c7a1be4 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -22,7 +22,6 @@ #include "events/EventBase.hpp" #include "mesh/mpiCommunications/CommunicationTools.hpp" #include "common/Units.hpp" -#include "codingUtilities/Section.hpp" namespace geos { @@ -170,25 +169,10 @@ bool EventManager::run( DomainPartition & domain ) m_dt = dt_global; #endif } - - string timeDescription = "- Time: " + units::TimeFormatInfo::fromSeconds( m_time ).toString(); - string deltaDescription = "- Delta time: " + units::TimeFormatInfo::fromSeconds( m_dt ).toString(); - string cycleDescription = "- Cycle: " + std::to_string( m_cycle ); - Section section; - section.setName( "section name" ); - section.addDescription( "description name 1" ); - section.addDescription( "description name 2" ); - section.setMinWidth( 100 ); - // section.addDescription( deltaDescription ); - // section.addDescription( cycleDescription ); - - // section.setMinWidth(100); - // The formating here is a work in progress. + outputTime( section ); section.begin(); - outputTime(); - // Execute for(; m_currentSubEventnumSubGroups(); ++m_currentSubEvent ) { @@ -242,7 +226,7 @@ bool EventManager::run( DomainPartition & domain ) return false; } -void EventManager::outputTime() const +void EventManager::outputTime( Section & section ) const { const bool isTimeLimited = m_maxTime < std::numeric_limits< real64 >::max(); const bool isCycleLimited = m_maxCycle < std::numeric_limits< integer >::max(); @@ -262,19 +246,30 @@ void EventManager::outputTime() const m_maxCycle, ( 100.0 * m_cycle ) / m_maxCycle ); }; - // The formating here is a work in progress. - GEOS_LOG_RANK_0( "\n------------------------- TIMESTEP START -------------------------" ); - GEOS_LOG_RANK_0( GEOS_FMT( " - Time: {}{}", - timeInfo.toUnfoldedString(), - isTimeLimited ? timeCompletionUnfoldedString() : "" ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " ({}{})", - timeInfo.toSecondsString(), - isTimeLimited ? timeCompletionSecondsString() : "" ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " - Delta Time: {}", units::TimeFormatInfo::fromSeconds( m_dt ) ) ); - GEOS_LOG_RANK_0( GEOS_FMT( " - Cycle: {}{}", - m_cycle, - isCycleLimited ? cycleCompletionString() : "" ) ); - GEOS_LOG_RANK_0( "--------------------------------------------------------------------\n" ); + string timeCompletionUnfolded = isTimeLimited ? timeCompletionUnfoldedString() : ""; + string timeCompletionSecond = isTimeLimited ? timeCompletionSecondsString() : ""; + string cycleLimited = isCycleLimited ? cycleCompletionString() : ""; + + string timeInfosUnfolded = timeInfo.toUnfoldedString() + timeCompletionUnfolded; + string timeCompletionSeconds = timeInfo.toSecondsString() + timeCompletionSecond; + + section.setName( "TIMESTEP START" ); + section.addDescription( "Time", timeCompletionUnfolded, timeCompletionSeconds ); + section.addDescription( GEOS_FMT( "- Delta Time: {}", units::TimeFormatInfo::fromSecxonds( m_dt ) )); + section.addDescription( GEOS_FMT( "- Cycle: {}{}", m_cycle, cycleLimited ) ); + + // GEOS_LOG_RANK_0( "\n------------------------- TIMESTEP START -------------------------" ); + // GEOS_LOG_RANK_0( GEOS_FMT( " - Time: {}{}", + // timeInfo.toUnfoldedString(), + // isTimeLimited ? timeCompletionUnfoldedString() : "" ) ); + // GEOS_LOG_RANK_0( GEOS_FMT( " ({}{})", + // timeInfo.toSecondsString(), + // isTimeLimited ? timeCompletionSecondsString() : "" ) ); + // GEOS_LOG_RANK_0( GEOS_FMT( " - Delta Time: {}", units::TimeFormatInfo::fromSeconds( m_dt ) ) ); + // GEOS_LOG_RANK_0( GEOS_FMT( " - Cycle: {}{}", + // m_cycle, + // isCycleLimited ? cycleCompletionString() : "" ) ); + // GEOS_LOG_RANK_0( "--------------------------------------------------------------------\n" ); // We are keeping the old outputs to keep compatibility with current log reading scripts. if( m_timeOutputFormat==TimeOutputFormat::full ) diff --git a/src/coreComponents/events/EventManager.hpp b/src/coreComponents/events/EventManager.hpp index c839346d19a..e795501d008 100644 --- a/src/coreComponents/events/EventManager.hpp +++ b/src/coreComponents/events/EventManager.hpp @@ -18,6 +18,7 @@ #include "dataRepository/Group.hpp" #include "EventBase.hpp" +#include "codingUtilities/Section.hpp" namespace geos { @@ -133,7 +134,7 @@ class EventManager : public dataRepository::Group * @brief ouput time information to the log * */ - void outputTime() const; + void outputTime( Section & section ) const; /// Min time for a simulation real64 m_minTime; diff --git a/src/coreComponents/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 0438bf27590..0599c329f5f 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,7 @@ 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 ); } diff --git a/src/coreComponents/mainInterface/ProblemManager.cpp b/src/coreComponents/mainInterface/ProblemManager.cpp index 0dca8195b97..3167c0be4b9 100644 --- a/src/coreComponents/mainInterface/ProblemManager.cpp +++ b/src/coreComponents/mainInterface/ProblemManager.cpp @@ -30,6 +30,7 @@ #include "events/tasks/TasksManager.hpp" #include "events/EventManager.hpp" #include "finiteElement/FiniteElementDiscretization.hpp" +#include "codingUtilities/Section.hpp" #include "finiteElement/FiniteElementDiscretizationManager.hpp" #include "finiteVolume/FluxApproximationBase.hpp" #include "finiteVolume/HybridMimeticDiscretization.hpp" @@ -150,12 +151,16 @@ Group * ProblemManager::createChild( string const & GEOS_UNUSED_PARAM( childKey void ProblemManager::problemSetup() { GEOS_MARK_FUNCTION; + Section section; + postInputInitializationRecursive(); + section.setName( "Mesh generation" ); + section.begin(); generateMesh(); + section.end(); // initialize_postMeshGeneration(); - applyNumericalMethods(); registerDataOnMeshRecursive( getDomainPartition().getMeshBodies() ); From 7cf52dde15d1b8204afcd15dc78481387f6f8e07 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 5 Jul 2024 16:20:33 +0200 Subject: [PATCH 152/206] 2path of refacto --- .../codingUtilities/Section.cpp | 135 +++++++----------- .../codingUtilities/Section.hpp | 78 +++++----- src/coreComponents/events/EventManager.cpp | 17 +-- 3 files changed, 103 insertions(+), 127 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp index b94d4d50f42..40c489a3ead 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -36,12 +36,6 @@ void Section::addDescription( string const & description ) m_descriptions.push_back( description ); } -void Section::addDescription( string const & descriptionName, std::vector< string > const & descriptionValues ) -{ - m_descriptionsValues.push_back( descriptionValues ); - m_descriptionNames.push_back( descriptionName ); -} - void Section::setMinWidth( integer const & minWidth ) { m_rowMinWidth = minWidth; @@ -50,10 +44,7 @@ void Section::setMinWidth( integer const & minWidth ) void Section::computeMaxRowSize( string const & title, std::vector< string > const & rowsDescription ) { - static constexpr integer marginBorder = 2; - static constexpr integer nbSpecialChar = 2; - integer maxDescriptionLength = 0; - integer titleLength = title.length() + marginBorder * 2 + nbSpecialChar * 2; + integer const titleLength = title.length() + m_marginBorder * 2 + m_nbSpecialChar * 2; m_rowLength = std::max( m_rowMinWidth, titleLength ); @@ -64,112 +55,86 @@ void Section::computeMaxRowSize( string const & title, auto it = std::max_element( rowsDescription.begin(), rowsDescription.end(), - []( const auto & a, const auto & b ) { + []( auto const & a, auto const & b ) { return a.size() < b.size(); } ); - string maxDescriptionSize = *it; + string const maxDescriptionSize = *it; - maxDescriptionLength = integer( maxDescriptionSize.length()) + marginBorder * 2 + nbSpecialChar * 2; + integer const maxDescriptionLength = integer( maxDescriptionSize.length()) + m_marginBorder * 2 + m_nbSpecialChar * 2; m_rowLength = std::max( maxDescriptionLength, m_rowLength ); } -void Section::buildLineSection( string & lineSection ) -{ - lineSection = GEOS_FMT( "{:#>{}}\n", "", m_rowLength ); -} - -void Section::addTitleRow( string & sectionToBeBuilt, string_view title ) +void Section::buildAlignDescription() { - sectionToBeBuilt += GEOS_FMT( "##{:^{}}##\n", title, m_rowLength - 4 ); -} - -void Section::addEndSectionRow( string & sectionToBeBuilt, string_view title ) -{ - sectionToBeBuilt += GEOS_FMT( "##{:^{}}##\n", title, m_rowLength - 4 ); -} - -void Section::addDescriptionRows( string & sectionToBeBuilt, std::vector< string > const & rowValues ) -{ - for( string rowValue : rowValues ) + int idxDescription = 0; + for( auto const & descriptionsValues : m_descriptionsValues ) { - sectionToBeBuilt += GEOS_FMT( "## {:<{}}##\n", rowValue, m_rowLength - 6 ); + m_descriptions.push_back( GEOS_FMT( "- {}: {}", + m_descriptionNames[idxDescription], + descriptionsValues[0] ) ); + for( size_t idxValue = 1; idxValue < descriptionsValues.size(); idxValue++ ) + { + integer const descriptionLength = m_descriptionNames[idxDescription].length() + m_embeddingName; + m_descriptions.push_back( GEOS_FMT( "{:>{}}{}", " ", + descriptionLength, + descriptionsValues[idxValue] ) ); + } + idxDescription++; } } + void Section::clear() { m_descriptions.clear(); + m_descriptionNames.clear(); + m_descriptionsValues.clear(); m_sectionTitle.clear(); + } void Section::begin( std::ostream & oss ) { - string lineSection; - string sectionToBeBuilt; - string const titleToDisplay = "Section : " + m_sectionTitle; - - //TODO function and test and refacto below - if( m_descriptionsValues.empty()) + if( !m_descriptionsValues.empty()) { - int maxLenName = 0; - computeMaxRowSize( "", m_descriptionNames ); - maxLenName = m_rowLength; - - if( m_descriptionsValues.length == 1 ) - { - m_descriptions.push_back( GEOS_FMT( " - {}:{}", m_descriptionNames[0], m_descriptionsValues[0] )); - } - else - { - int i = 0; - for( std::vector< string > descriptionsValues : m_descriptionsValues ) - { - string description = GEOS_FMT( " - {}:", m_descriptionNames[i] ); - for( string values: descriptionsValues ) - { - description += GEOS_FMT( "{:-<{}}", values, m_rowLength ); - m_descriptions.push_back(); - - } - i++; - } - } + buildAlignDescription(); } - // check if descvalues empty - // split descValues into m_descriptions and set marginValues by default 0 - // marginValues is used to construct m_description so just here (?) + computeMaxRowSize( m_sectionTitle, m_descriptions ); - //and back to normal... just need to format m_descriptions ! - //don't forget to rename variable and functions et to remove unused function ! - computeMaxRowSize( titleToDisplay, m_descriptions ); - buildLineSection( lineSection ); + string const lineSection = GEOS_FMT( "{:#>{}}\n", "", m_rowLength ); + int const titleLength = m_rowLength - m_nbSpecialChar * 2; + int const descriptionLength = m_rowLength - m_nbSpecialChar * 2 - m_marginBorder; - sectionToBeBuilt += '\n' + lineSection; - addTitleRow( sectionToBeBuilt, titleToDisplay ); - sectionToBeBuilt += lineSection; - addDescriptionRows( sectionToBeBuilt, m_descriptions ); - sectionToBeBuilt += '\n'; + //section title + oss << '\n'; + oss << lineSection; + oss << GEOS_FMT( "##{:^{}}##\n", m_sectionTitle, titleLength ); - oss << sectionToBeBuilt; + //section descriptions + oss << lineSection; + for( string & description : m_descriptions ) + { + oss << GEOS_FMT( "##{:<{}}{:<{}}##", " ", m_marginBorder, description, descriptionLength ); + if( &description != &m_descriptions.back()) + { + oss << '\n'; + } + } } void Section::end( std::ostream & oss ) { - string lineSection; - string sectionToBeBuilt; - string titleToDisplay = "End : " + m_sectionTitle; - - buildLineSection( lineSection ); - - sectionToBeBuilt += '\n'; - addTitleRow( sectionToBeBuilt, titleToDisplay ); - sectionToBeBuilt += lineSection; - sectionToBeBuilt += '\n'; - - oss << sectionToBeBuilt; + string const title = "End : " + m_sectionTitle; + int const titleLength = m_rowLength - m_nbSpecialChar * 2; + string lineSection = GEOS_FMT( "{:#^{}}\n", "", m_rowLength ); + + oss << '\n'; + oss << GEOS_FMT( "##{:^{}}##\n", title, titleLength ); + oss << lineSection; + oss << '\n'; clear(); } diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/codingUtilities/Section.hpp index 99914612e63..fd21963d628 100644 --- a/src/coreComponents/codingUtilities/Section.hpp +++ b/src/coreComponents/codingUtilities/Section.hpp @@ -37,10 +37,13 @@ class Section void setName( string_view m_sectionTitle ); /** - * @brief Add a description to the section - * @param description The string value of the description + * @brief Add a description to the section and composed by a description name and variadic values. + * Use to align variadic values of the same description + * @param descriptionName The description name + * @param args Values to be aligned. */ - void addDescription( string const & descriptionName, std::vector< string > const & descriptionValues ); + template< typename ... Args > + void addDescription( string const & descriptionName, Args const & ... args ); /** * @brief Add a description to the section @@ -50,7 +53,7 @@ class Section /** * @brief Set the minimal width of a row - * @param minWidth the minimal width of the table + * @param minWidth The minimal width of the table */ void setMinWidth( integer const & minWidth ); @@ -65,57 +68,64 @@ class Section * @param oss An output stream (by default, std::cout) */ void end( std::ostream & oss = std::cout ); + private: /** * @brief Compute the max string size (m_rowLength) between title and the description(s) - * @param m_sectionTitle The title of the table - * @param vDescriptions The vector of descriptions + * @param m_sectionTitle The table title + * @param descriptions The descriptions vector */ void computeMaxRowSize( string const & m_sectionTitle, - std::vector< string > const & vDescriptions ); - + std::vector< string > const & descriptions ); /** - * @brief Build the line section in order to build the section - * @param lineSection An empty string + * @brief Build a description from the name and variadic values descriptions */ - void buildLineSection( string & lineSection ); + void buildAlignDescription(); /** - * @brief Clear all private field related to the current section + * @brief Cleans all buffers used in the construction of a section */ void clear(); - /** - * @brief Build and add the title to the first part of the section - * @param sectionToBeBuilt The current section being built - * @param title The section name - */ - void addTitleRow( string & sectionToBeBuilt, string_view title ); - - /** - * @brief Build and add the title to the last part of the section - * @param sectionToBeBuilt The current section being built - * @param title The section name - */ - void addEndSectionRow( string & sectionToBeBuilt, string_view title ); - - /** - * @brief Build and add the descriptions to the first part of the section - * @param sectionToBeBuilt The current section being built - * @param rowsValue The vector of descriptions - */ - void addDescriptionRows( string & sectionToBeBuilt, std::vector< string > const & rowsValue ); - + /// Vector containing all description std::vector< string > m_descriptions; - + /// Used if the variadic addDescription has been called + /// Containing all "key" description name std::vector< string > m_descriptionNames; + /// Used if the variadic addDescription has been called + /// Containing all description values std::vector< std::vector< string > > m_descriptionsValues; + /// title of section string m_sectionTitle; + /// section length integer m_rowLength; + /// min width of section length integer m_rowMinWidth; + + /// description border margin + static constexpr integer m_marginBorder = 2; + /// character used as border + static constexpr integer m_nbSpecialChar = 2; + /// (Temporary ?) special char with key name. I.E =>- "name": => 3char + static constexpr integer m_embeddingName = 4; + }; + +template< typename ... Args > +void Section::addDescription( string const & descriptionName, Args const &... args ) +{ + std::vector< string > descriptions; + ( [&] { + static_assert( has_formatter_v< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); + string const value = GEOS_FMT( "{}", args ); + descriptions.push_back( value ); + } (), ...); + + m_descriptionsValues.push_back( descriptions ); + m_descriptionNames.push_back( descriptionName ); +} } diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index cbe3c7a1be4..51f7d4a7f01 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -246,17 +246,18 @@ void EventManager::outputTime( Section & section ) const m_maxCycle, ( 100.0 * m_cycle ) / m_maxCycle ); }; - string timeCompletionUnfolded = isTimeLimited ? timeCompletionUnfoldedString() : ""; - string timeCompletionSecond = isTimeLimited ? timeCompletionSecondsString() : ""; - string cycleLimited = isCycleLimited ? cycleCompletionString() : ""; + string const timeCompletionUnfolded = isTimeLimited ? timeCompletionUnfoldedString() : ""; + string const timeCompletionSecond = isTimeLimited ? timeCompletionSecondsString() : ""; + string const cycleLimited = isCycleLimited ? cycleCompletionString() : ""; - string timeInfosUnfolded = timeInfo.toUnfoldedString() + timeCompletionUnfolded; - string timeCompletionSeconds = timeInfo.toSecondsString() + timeCompletionSecond; + string const timeInfosUnfolded = timeInfo.toUnfoldedString() + timeCompletionUnfolded; + string const timeCompletionSeconds = timeInfo.toSecondsString() + timeCompletionSecond; section.setName( "TIMESTEP START" ); - section.addDescription( "Time", timeCompletionUnfolded, timeCompletionSeconds ); - section.addDescription( GEOS_FMT( "- Delta Time: {}", units::TimeFormatInfo::fromSecxonds( m_dt ) )); - section.addDescription( GEOS_FMT( "- Cycle: {}{}", m_cycle, cycleLimited ) ); + section.addDescription( "Time", timeInfosUnfolded, timeCompletionSeconds ); + section.addDescription( "Delta Time", units::TimeFormatInfo::fromSeconds( m_dt ).toString() ); + section.addDescription( "Cycle", m_cycle, cycleLimited ); + section.setMinWidth(70); // GEOS_LOG_RANK_0( "\n------------------------- TIMESTEP START -------------------------" ); // GEOS_LOG_RANK_0( GEOS_FMT( " - Time: {}{}", From 2bd3e7d1df4b680bd9069d45551a4367fc6fad85 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 5 Jul 2024 16:24:34 +0200 Subject: [PATCH 153/206] int => integer --- src/coreComponents/codingUtilities/Section.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp index 40c489a3ead..be273dc9600 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -68,7 +68,7 @@ void Section::computeMaxRowSize( string const & title, void Section::buildAlignDescription() { - int idxDescription = 0; + integer idxDescription = 0; for( auto const & descriptionsValues : m_descriptionsValues ) { m_descriptions.push_back( GEOS_FMT( "- {}: {}", @@ -105,8 +105,8 @@ void Section::begin( std::ostream & oss ) computeMaxRowSize( m_sectionTitle, m_descriptions ); string const lineSection = GEOS_FMT( "{:#>{}}\n", "", m_rowLength ); - int const titleLength = m_rowLength - m_nbSpecialChar * 2; - int const descriptionLength = m_rowLength - m_nbSpecialChar * 2 - m_marginBorder; + integer const titleLength = m_rowLength - m_nbSpecialChar * 2; + integer const descriptionLength = m_rowLength - m_nbSpecialChar * 2 - m_marginBorder; //section title oss << '\n'; @@ -128,7 +128,7 @@ void Section::begin( std::ostream & oss ) void Section::end( std::ostream & oss ) { string const title = "End : " + m_sectionTitle; - int const titleLength = m_rowLength - m_nbSpecialChar * 2; + integer const titleLength = m_rowLength - m_nbSpecialChar * 2; string lineSection = GEOS_FMT( "{:#^{}}\n", "", m_rowLength ); oss << '\n'; From d81d7c44af53366368560670a74133e22ef7def4 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 5 Jul 2024 16:29:20 +0200 Subject: [PATCH 154/206] string_view => string --- src/coreComponents/codingUtilities/Section.cpp | 2 +- src/coreComponents/codingUtilities/Section.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp index be273dc9600..e6f98e48f35 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -41,7 +41,7 @@ void Section::setMinWidth( integer const & minWidth ) m_rowMinWidth = minWidth; } -void Section::computeMaxRowSize( string const & title, +void Section::computeMaxRowSize( string_view title, std::vector< string > const & rowsDescription ) { integer const titleLength = title.length() + m_marginBorder * 2 + m_nbSpecialChar * 2; diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/codingUtilities/Section.hpp index fd21963d628..77ebb39d50b 100644 --- a/src/coreComponents/codingUtilities/Section.hpp +++ b/src/coreComponents/codingUtilities/Section.hpp @@ -76,7 +76,7 @@ class Section * @param m_sectionTitle The table title * @param descriptions The descriptions vector */ - void computeMaxRowSize( string const & m_sectionTitle, + void computeMaxRowSize( string_view m_sectionTitle, std::vector< string > const & descriptions ); /** * @brief Build a description from the name and variadic values descriptions From 5da394c6295b6b35171d19877c69b5e3b99ec25e Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 5 Jul 2024 16:33:13 +0200 Subject: [PATCH 155/206] add line return --- src/coreComponents/codingUtilities/Section.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp index e6f98e48f35..b30b48fafe2 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -123,6 +123,7 @@ void Section::begin( std::ostream & oss ) oss << '\n'; } } + oss << '\n'; } void Section::end( std::ostream & oss ) From 834bf7a397f36402dd6d904490005919c7c429c7 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 5 Jul 2024 16:36:58 +0200 Subject: [PATCH 156/206] uncrustify --- src/coreComponents/codingUtilities/Section.hpp | 4 ++-- src/coreComponents/events/EventManager.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/codingUtilities/Section.hpp index 77ebb39d50b..9687c82372f 100644 --- a/src/coreComponents/codingUtilities/Section.hpp +++ b/src/coreComponents/codingUtilities/Section.hpp @@ -39,7 +39,7 @@ class Section /** * @brief Add a description to the section and composed by a description name and variadic values. * Use to align variadic values of the same description - * @param descriptionName The description name + * @param descriptionName The description name * @param args Values to be aligned. */ template< typename ... Args > @@ -79,7 +79,7 @@ class Section void computeMaxRowSize( string_view m_sectionTitle, std::vector< string > const & descriptions ); /** - * @brief Build a description from the name and variadic values descriptions + * @brief Build a description from the name and variadic values descriptions */ void buildAlignDescription(); diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index 51f7d4a7f01..4820f804fbe 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -257,7 +257,7 @@ void EventManager::outputTime( Section & section ) const section.addDescription( "Time", timeInfosUnfolded, timeCompletionSeconds ); section.addDescription( "Delta Time", units::TimeFormatInfo::fromSeconds( m_dt ).toString() ); section.addDescription( "Cycle", m_cycle, cycleLimited ); - section.setMinWidth(70); + section.setMinWidth( 70 ); // GEOS_LOG_RANK_0( "\n------------------------- TIMESTEP START -------------------------" ); // GEOS_LOG_RANK_0( GEOS_FMT( " - Time: {}{}", From 4f5fa5b8afde6b9ee25af376e66968b667aa8b37 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 8 Jul 2024 14:01:22 +0200 Subject: [PATCH 157/206] update doxygen / improve code --- .../codingUtilities/Section.cpp | 59 +++++++++---------- .../codingUtilities/Section.hpp | 38 ++++++------ .../codingUtilities/tests/testSection.cpp | 53 +++++++++++++---- src/coreComponents/events/EventManager.cpp | 13 ---- 4 files changed, 86 insertions(+), 77 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp index b30b48fafe2..c62ede74c2d 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -44,7 +44,8 @@ void Section::setMinWidth( integer const & minWidth ) void Section::computeMaxRowSize( string_view title, std::vector< string > const & rowsDescription ) { - integer const titleLength = title.length() + m_marginBorder * 2 + m_nbSpecialChar * 2; + std::string const footerStr = "End : "; + integer const titleLength = footerStr.length() + title.length() + m_marginBorder * 2 + m_nbSpecialChar * 2; m_rowLength = std::max( m_rowMinWidth, titleLength ); @@ -66,74 +67,70 @@ void Section::computeMaxRowSize( string_view title, m_rowLength = std::max( maxDescriptionLength, m_rowLength ); } -void Section::buildAlignDescription() +void Section::formatAndInsertDescriptions( std::string const & descriptionName, + std::vector< string > const & descriptionValues ) { - integer idxDescription = 0; - for( auto const & descriptionsValues : m_descriptionsValues ) + integer const descriptionLength = descriptionName.length() + m_embeddingName; + m_descriptions.push_back( GEOS_FMT( "- {}: {}", descriptionName, descriptionValues[0] ) ); + for( size_t idxValue = 1; idxValue < descriptionValues.size(); idxValue++ ) { - m_descriptions.push_back( GEOS_FMT( "- {}: {}", - m_descriptionNames[idxDescription], - descriptionsValues[0] ) ); - for( size_t idxValue = 1; idxValue < descriptionsValues.size(); idxValue++ ) - { - integer const descriptionLength = m_descriptionNames[idxDescription].length() + m_embeddingName; - m_descriptions.push_back( GEOS_FMT( "{:>{}}{}", " ", - descriptionLength, - descriptionsValues[idxValue] ) ); - } - idxDescription++; + m_descriptions.push_back( GEOS_FMT( "{:>{}}{}", " ", + descriptionLength, + descriptionValues[idxValue] ) ); } } - void Section::clear() { m_descriptions.clear(); - m_descriptionNames.clear(); - m_descriptionsValues.clear(); m_sectionTitle.clear(); - } void Section::begin( std::ostream & oss ) { - if( !m_descriptionsValues.empty()) - { - buildAlignDescription(); - } - computeMaxRowSize( m_sectionTitle, m_descriptions ); string const lineSection = GEOS_FMT( "{:#>{}}\n", "", m_rowLength ); integer const titleLength = m_rowLength - m_nbSpecialChar * 2; integer const descriptionLength = m_rowLength - m_nbSpecialChar * 2 - m_marginBorder; - //section title + //build section title oss << '\n'; oss << lineSection; oss << GEOS_FMT( "##{:^{}}##\n", m_sectionTitle, titleLength ); - //section descriptions + //build section descriptions oss << lineSection; - for( string & description : m_descriptions ) + + if( m_descriptions.empty()) + { + oss << '\n'; + return; + } + + for( string const & description : m_descriptions ) { oss << GEOS_FMT( "##{:<{}}{:<{}}##", " ", m_marginBorder, description, descriptionLength ); if( &description != &m_descriptions.back()) { oss << '\n'; } + else + { + oss << "\n\n"; + } } - oss << '\n'; } void Section::end( std::ostream & oss ) { - string const title = "End : " + m_sectionTitle; + std::string footerTitle = "End : " + m_sectionTitle; + integer const titleLength = m_rowLength - m_nbSpecialChar * 2; - string lineSection = GEOS_FMT( "{:#^{}}\n", "", m_rowLength ); + string const lineSection = GEOS_FMT( "{:#^{}}\n", "", m_rowLength ); oss << '\n'; - oss << GEOS_FMT( "##{:^{}}##\n", title, titleLength ); + oss << GEOS_FMT( "##{:^{}}##\n", footerTitle, titleLength ); oss << lineSection; oss << '\n'; diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/codingUtilities/Section.hpp index 9687c82372f..5eb35c8a3bf 100644 --- a/src/coreComponents/codingUtilities/Section.hpp +++ b/src/coreComponents/codingUtilities/Section.hpp @@ -37,10 +37,10 @@ class Section void setName( string_view m_sectionTitle ); /** - * @brief Add a description to the section and composed by a description name and variadic values. - * Use to align variadic values of the same description + * @brief Add a description to the section by concatening a description name and descriptions values. * @param descriptionName The description name - * @param args Values to be aligned. + * @param args Descriptions values to be aligned. + * Descriptions values can be be any types and will be aligned */ template< typename ... Args > void addDescription( string const & descriptionName, Args const & ... args ); @@ -75,27 +75,26 @@ class Section * @brief Compute the max string size (m_rowLength) between title and the description(s) * @param m_sectionTitle The table title * @param descriptions The descriptions vector + * @return The max row length of the section */ void computeMaxRowSize( string_view m_sectionTitle, - std::vector< string > const & descriptions ); + std::vector< string > const & descriptions ); + /** - * @brief Build a description from the name and variadic values descriptions + * @brief Build a description from the name and description values + * @param descriptionName The decription name + * @param decriptionsValues The description values */ - void buildAlignDescription(); + void formatAndInsertDescriptions( std::string const & descriptionName, + std::vector< string > const & decriptionsValues ); /** * @brief Cleans all buffers used in the construction of a section */ void clear(); - /// Vector containing all description + /// Vector containing all descriptions std::vector< string > m_descriptions; - /// Used if the variadic addDescription has been called - /// Containing all "key" description name - std::vector< string > m_descriptionNames; - /// Used if the variadic addDescription has been called - /// Containing all description values - std::vector< std::vector< string > > m_descriptionsValues; /// title of section string m_sectionTitle; @@ -106,9 +105,9 @@ class Section /// description border margin static constexpr integer m_marginBorder = 2; - /// character used as border + /// numbers of character used as border static constexpr integer m_nbSpecialChar = 2; - /// (Temporary ?) special char with key name. I.E =>- "name": => 3char + /// (Temporary ?) special char with key name. I.E =>- "description": => 3char ("-", " ",":") static constexpr integer m_embeddingName = 4; }; @@ -116,18 +115,15 @@ class Section template< typename ... Args > void Section::addDescription( string const & descriptionName, Args const &... args ) { - std::vector< string > descriptions; + std::vector< string > descriptionsValues; ( [&] { static_assert( has_formatter_v< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); string const value = GEOS_FMT( "{}", args ); - descriptions.push_back( value ); + descriptionsValues.push_back( value ); } (), ...); - m_descriptionsValues.push_back( descriptions ); - m_descriptionNames.push_back( descriptionName ); + formatAndInsertDescriptions( descriptionName, descriptionsValues ); } } - - #endif diff --git a/src/coreComponents/codingUtilities/tests/testSection.cpp b/src/coreComponents/codingUtilities/tests/testSection.cpp index 4c80d173d20..6f1e68b9eae 100644 --- a/src/coreComponents/codingUtilities/tests/testSection.cpp +++ b/src/coreComponents/codingUtilities/tests/testSection.cpp @@ -12,8 +12,7 @@ * ------------------------------------------------------------------------------------------------------------ */ -#include "../../dataRepository/Group.hpp" -// TPL includes +#include "common/DataTypes.hpp" #include "codingUtilities/Section.hpp" #include @@ -26,17 +25,17 @@ TEST( testSection, sectionWithTitle ) section.setName( "section name" ); section.begin( oss ); EXPECT_EQ( oss.str(), - "\n##############################\n" - "## Section : section name ##\n" - "##############################\n\n" + "\n##########################\n" + "## section name ##\n" + "##########################\n\n" ); oss.clear(); oss.str( "" ); section.end( oss ); EXPECT_EQ( oss.str(), - "\n## End : section name ##\n" - "##############################\n\n" + "\n## End : section name ##\n" + "##########################\n\n" ); oss.clear(); } @@ -49,10 +48,10 @@ TEST( testSection, sectionWithTitleAndOneDescription ) section.addDescription( "description name" ); section.begin( oss ); EXPECT_EQ( oss.str(), - "\n##############################\n" - "## Section : section name ##\n" - "##############################\n" - "## description name ##\n\n" + "\n##########################\n" + "## section name ##\n" + "##########################\n" + "## description name ##\n\n" ); oss.clear(); } @@ -68,7 +67,7 @@ TEST( testSection, sectionWithSetWidth ) section.begin( oss ); EXPECT_EQ( oss.str(), "\n####################################################################################################\n" - "## Section : section name ##\n" + "## section name ##\n" "####################################################################################################\n" "## description name 1 ##\n" "## description name 2 ##\n\n" @@ -84,6 +83,36 @@ TEST( testSection, sectionWithSetWidth ) oss.clear(); } +TEST( testSection, sectionMultipleDescriptions ) +{ + std::ostringstream oss; + Section section; + section.setName( "TIMESTEP START" ); + section.addDescription( "Time", "00h08m20s out of 2d, 21h26m40s (0% completed)", "500 s / 250000 s" ); + section.addDescription( "Delta Time", "00h16m40s (1000 s)" ); + section.addDescription( "- Cycle: 1" ); + section.setMinWidth( 70 ); + section.begin( oss ); + EXPECT_EQ ( oss.str(), + "\n######################################################################\n" + "## TIMESTEP START ##\n" + "######################################################################\n" + "## - Time: 00h08m20s out of 2d, 21h26m40s (0% completed) ##\n" + "## 500 s / 250000 s ##\n" + "## - Delta Time: 00h16m40s (1000 s) ##\n" + "## - Cycle: 1 ##\n\n" + ); + oss.clear(); + oss.str( "" ); + + section.end( oss ); + EXPECT_EQ( oss.str(), + "\n## End : TIMESTEP START ##\n" + "######################################################################\n\n" + ); + oss.clear(); +} + int main( int argc, char * * argv ) { testing::InitGoogleTest( &argc, argv ); diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index 4820f804fbe..e806955d59b 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -259,19 +259,6 @@ void EventManager::outputTime( Section & section ) const section.addDescription( "Cycle", m_cycle, cycleLimited ); section.setMinWidth( 70 ); - // GEOS_LOG_RANK_0( "\n------------------------- TIMESTEP START -------------------------" ); - // GEOS_LOG_RANK_0( GEOS_FMT( " - Time: {}{}", - // timeInfo.toUnfoldedString(), - // isTimeLimited ? timeCompletionUnfoldedString() : "" ) ); - // GEOS_LOG_RANK_0( GEOS_FMT( " ({}{})", - // timeInfo.toSecondsString(), - // isTimeLimited ? timeCompletionSecondsString() : "" ) ); - // GEOS_LOG_RANK_0( GEOS_FMT( " - Delta Time: {}", units::TimeFormatInfo::fromSeconds( m_dt ) ) ); - // GEOS_LOG_RANK_0( GEOS_FMT( " - Cycle: {}{}", - // m_cycle, - // isCycleLimited ? cycleCompletionString() : "" ) ); - // GEOS_LOG_RANK_0( "--------------------------------------------------------------------\n" ); - // We are keeping the old outputs to keep compatibility with current log reading scripts. if( m_timeOutputFormat==TimeOutputFormat::full ) { From 547bf9e813a9e8e090525e62c1f769cd1284803a Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 8 Jul 2024 15:59:48 +0200 Subject: [PATCH 158/206] 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 159/206] 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 160/206] 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 161/206] 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 48e2b7de698dbf9fc3a08fec4283516892debb64 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 8 Jul 2024 16:16:49 +0200 Subject: [PATCH 162/206] uncrustify --- src/coreComponents/codingUtilities/Section.hpp | 2 +- src/coreComponents/dataRepository/Group.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/codingUtilities/Section.hpp index 5eb35c8a3bf..7e28dcfa569 100644 --- a/src/coreComponents/codingUtilities/Section.hpp +++ b/src/coreComponents/codingUtilities/Section.hpp @@ -78,7 +78,7 @@ class Section * @return The max row length of the section */ void computeMaxRowSize( string_view m_sectionTitle, - std::vector< string > const & descriptions ); + std::vector< string > const & descriptions ); /** * @brief Build a description from the name and description values diff --git a/src/coreComponents/dataRepository/Group.cpp b/src/coreComponents/dataRepository/Group.cpp index 8d81716a94b..e0e88608110 100644 --- a/src/coreComponents/dataRepository/Group.cpp +++ b/src/coreComponents/dataRepository/Group.cpp @@ -354,7 +354,7 @@ void Group::initialize_postMeshGeneration() void Group::initialize() { - + initializePreSubGroups(); array1d< string > initOrder; From 4dc39354de373eed92b0ba7a5d09f362df492b0c Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 8 Jul 2024 17:46:06 +0200 Subject: [PATCH 163/206] small rweaks --- src/coreComponents/codingUtilities/Section.cpp | 10 +--------- src/coreComponents/codingUtilities/Section.hpp | 7 +------ 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp index c62ede74c2d..e93bff810e9 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -80,12 +80,6 @@ void Section::formatAndInsertDescriptions( std::string const & descriptionName, } } -void Section::clear() -{ - m_descriptions.clear(); - m_sectionTitle.clear(); -} - void Section::begin( std::ostream & oss ) { computeMaxRowSize( m_sectionTitle, m_descriptions ); @@ -122,7 +116,7 @@ void Section::begin( std::ostream & oss ) } } -void Section::end( std::ostream & oss ) +void Section::end( std::ostream & oss ) const { std::string footerTitle = "End : " + m_sectionTitle; @@ -133,7 +127,5 @@ void Section::end( std::ostream & oss ) oss << GEOS_FMT( "##{:^{}}##\n", footerTitle, titleLength ); oss << lineSection; oss << '\n'; - - clear(); } } diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/codingUtilities/Section.hpp index 7e28dcfa569..589ab1fdaed 100644 --- a/src/coreComponents/codingUtilities/Section.hpp +++ b/src/coreComponents/codingUtilities/Section.hpp @@ -67,7 +67,7 @@ class Section * @brief Draw the last part of the section. It include the title * @param oss An output stream (by default, std::cout) */ - void end( std::ostream & oss = std::cout ); + void end( std::ostream & oss = std::cout ) const; private: @@ -88,11 +88,6 @@ class Section void formatAndInsertDescriptions( std::string const & descriptionName, std::vector< string > const & decriptionsValues ); - /** - * @brief Cleans all buffers used in the construction of a section - */ - void clear(); - /// Vector containing all descriptions std::vector< string > m_descriptions; From 3caa16c57b9eb964c2ca7b8b9c3320a9828b0096 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 10 Jul 2024 11:36:20 +0200 Subject: [PATCH 164/206] melvin review --- .../codingUtilities/Section.cpp | 69 ++++++++----------- .../codingUtilities/Section.hpp | 26 +++---- .../codingUtilities/tests/testSection.cpp | 26 +++---- src/coreComponents/events/EventManager.cpp | 7 +- .../mainInterface/ProblemManager.cpp | 7 +- 5 files changed, 56 insertions(+), 79 deletions(-) diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/codingUtilities/Section.cpp index e93bff810e9..dbf40d4ba80 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/codingUtilities/Section.cpp @@ -22,18 +22,14 @@ namespace geos { -Section::Section(): +Section::Section( string_view sectionTitle ): + m_sectionTitle( string( sectionTitle ) ), m_rowMinWidth( 20 ) {} -void Section::setName( string_view title ) +void Section::addDescription( string_view description ) { - m_sectionTitle = title; -} - -void Section::addDescription( string const & description ) -{ - m_descriptions.push_back( description ); + m_descriptions.push_back( string( description ) ); } void Section::setMinWidth( integer const & minWidth ) @@ -41,10 +37,10 @@ void Section::setMinWidth( integer const & minWidth ) m_rowMinWidth = minWidth; } -void Section::computeMaxRowSize( string_view title, - std::vector< string > const & rowsDescription ) +void Section::computeMaxWidth( string_view title, + std::vector< string > const & rowsDescription ) { - std::string const footerStr = "End : "; + string const footerStr = "End : "; integer const titleLength = footerStr.length() + title.length() + m_marginBorder * 2 + m_nbSpecialChar * 2; m_rowLength = std::max( m_rowMinWidth, titleLength ); @@ -54,77 +50,72 @@ void Section::computeMaxRowSize( string_view title, return; } - auto it = std::max_element( rowsDescription.begin(), - rowsDescription.end(), + auto it = std::max_element( rowsDescription.begin(), rowsDescription.end(), []( auto const & a, auto const & b ) { return a.size() < b.size(); } ); string const maxDescriptionSize = *it; - integer const maxDescriptionLength = integer( maxDescriptionSize.length()) + m_marginBorder * 2 + m_nbSpecialChar * 2; + integer const maxDescriptionLength = integer( maxDescriptionSize.length()) + + m_marginBorder * 2 + m_nbSpecialChar * 2; m_rowLength = std::max( maxDescriptionLength, m_rowLength ); } -void Section::formatAndInsertDescriptions( std::string const & descriptionName, +void Section::formatAndInsertDescriptions( string_view descriptionName, std::vector< string > const & descriptionValues ) { - integer const descriptionLength = descriptionName.length() + m_embeddingName; - m_descriptions.push_back( GEOS_FMT( "- {}: {}", descriptionName, descriptionValues[0] ) ); + string const descNameFormatted = GEOS_FMT( "- {}: ", string( descriptionName )); + integer const descNameLength = descNameFormatted.length(); + m_descriptions.push_back( GEOS_FMT( "{}{}", descNameFormatted, descriptionValues[0] ) ); for( size_t idxValue = 1; idxValue < descriptionValues.size(); idxValue++ ) { m_descriptions.push_back( GEOS_FMT( "{:>{}}{}", " ", - descriptionLength, + descNameLength, descriptionValues[idxValue] ) ); } } -void Section::begin( std::ostream & oss ) +void Section::beginSection( std::ostream & oss ) { - computeMaxRowSize( m_sectionTitle, m_descriptions ); + computeMaxWidth( m_sectionTitle, m_descriptions ); string const lineSection = GEOS_FMT( "{:#>{}}\n", "", m_rowLength ); + string const horizontalChars = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); integer const titleLength = m_rowLength - m_nbSpecialChar * 2; integer const descriptionLength = m_rowLength - m_nbSpecialChar * 2 - m_marginBorder; //build section title oss << '\n'; oss << lineSection; - oss << GEOS_FMT( "##{:^{}}##\n", m_sectionTitle, titleLength ); + oss << GEOS_FMT( "{}{:^{}}{}\n", horizontalChars, m_sectionTitle, titleLength, horizontalChars ); //build section descriptions oss << lineSection; - if( m_descriptions.empty()) - { - oss << '\n'; - return; - } - - for( string const & description : m_descriptions ) + if( !m_descriptions.empty()) { - oss << GEOS_FMT( "##{:<{}}{:<{}}##", " ", m_marginBorder, description, descriptionLength ); - if( &description != &m_descriptions.back()) + for( string const & description : m_descriptions ) { + oss << horizontalChars; + oss << GEOS_FMT( "{:<{}}{:<{}}", " ", m_marginBorder, description, descriptionLength ); + oss << horizontalChars; oss << '\n'; } - else - { - oss << "\n\n"; - } } + oss << "\n"; } -void Section::end( std::ostream & oss ) const +void Section::endSection( std::ostream & oss ) const { - std::string footerTitle = "End : " + m_sectionTitle; - - integer const titleLength = m_rowLength - m_nbSpecialChar * 2; + string const footerTitle = GEOS_FMT( "{} {}", "End :", m_sectionTitle ); string const lineSection = GEOS_FMT( "{:#^{}}\n", "", m_rowLength ); + string const horizontalChars = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); + integer const titleLength = m_rowLength - m_nbSpecialChar * 2; oss << '\n'; - oss << GEOS_FMT( "##{:^{}}##\n", footerTitle, titleLength ); + oss << GEOS_FMT( "{}{:^{}}{}\n", horizontalChars, footerTitle, titleLength, horizontalChars ); oss << lineSection; oss << '\n'; } diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/codingUtilities/Section.hpp index 589ab1fdaed..3299146b055 100644 --- a/src/coreComponents/codingUtilities/Section.hpp +++ b/src/coreComponents/codingUtilities/Section.hpp @@ -28,13 +28,7 @@ class Section { public: - Section(); - - /** - * @brief Set the name of the section - * @param m_sectionTitle The name of the section - */ - void setName( string_view m_sectionTitle ); + Section( string_view m_sectionTitle ); /** * @brief Add a description to the section by concatening a description name and descriptions values. @@ -43,13 +37,13 @@ class Section * Descriptions values can be be any types and will be aligned */ template< typename ... Args > - void addDescription( string const & descriptionName, Args const & ... args ); + void addDescription( string_view descriptionName, Args const & ... args ); /** * @brief Add a description to the section * @param description The string value of the description */ - void addDescription( string const & description ); + void addDescription( string_view description ); /** * @brief Set the minimal width of a row @@ -61,13 +55,13 @@ class Section * @brief Draw the first part of the section. It include the title and optionnaly, the description(s); * @param os An output stream (by default, std::cout) */ - void begin( std::ostream & os = std::cout ); + void beginSection( std::ostream & os = std::cout ); /** * @brief Draw the last part of the section. It include the title * @param oss An output stream (by default, std::cout) */ - void end( std::ostream & oss = std::cout ) const; + void endSection( std::ostream & oss = std::cout ) const; private: @@ -77,15 +71,15 @@ class Section * @param descriptions The descriptions vector * @return The max row length of the section */ - void computeMaxRowSize( string_view m_sectionTitle, - std::vector< string > const & descriptions ); + void computeMaxWidth( string_view m_sectionTitle, + std::vector< string > const & descriptions ); /** * @brief Build a description from the name and description values * @param descriptionName The decription name * @param decriptionsValues The description values */ - void formatAndInsertDescriptions( std::string const & descriptionName, + void formatAndInsertDescriptions( string_view descriptionName, std::vector< string > const & decriptionsValues ); /// Vector containing all descriptions @@ -102,13 +96,11 @@ class Section static constexpr integer m_marginBorder = 2; /// numbers of character used as border static constexpr integer m_nbSpecialChar = 2; - /// (Temporary ?) special char with key name. I.E =>- "description": => 3char ("-", " ",":") - static constexpr integer m_embeddingName = 4; }; template< typename ... Args > -void Section::addDescription( string const & descriptionName, Args const &... args ) +void Section::addDescription( string_view descriptionName, Args const &... args ) { std::vector< string > descriptionsValues; ( [&] { diff --git a/src/coreComponents/codingUtilities/tests/testSection.cpp b/src/coreComponents/codingUtilities/tests/testSection.cpp index 6f1e68b9eae..88816e326bd 100644 --- a/src/coreComponents/codingUtilities/tests/testSection.cpp +++ b/src/coreComponents/codingUtilities/tests/testSection.cpp @@ -21,9 +21,8 @@ using namespace geos; TEST( testSection, sectionWithTitle ) { std::ostringstream oss; - Section section; - section.setName( "section name" ); - section.begin( oss ); + Section section( "section name" ); + section.beginSection( oss ); EXPECT_EQ( oss.str(), "\n##########################\n" "## section name ##\n" @@ -32,7 +31,7 @@ TEST( testSection, sectionWithTitle ) oss.clear(); oss.str( "" ); - section.end( oss ); + section.endSection( oss ); EXPECT_EQ( oss.str(), "\n## End : section name ##\n" "##########################\n\n" @@ -43,10 +42,9 @@ TEST( testSection, sectionWithTitle ) TEST( testSection, sectionWithTitleAndOneDescription ) { std::ostringstream oss; - Section section; - section.setName( "section name" ); + Section section( "section name" ); section.addDescription( "description name" ); - section.begin( oss ); + section.beginSection( oss ); EXPECT_EQ( oss.str(), "\n##########################\n" "## section name ##\n" @@ -59,12 +57,11 @@ TEST( testSection, sectionWithTitleAndOneDescription ) TEST( testSection, sectionWithSetWidth ) { std::ostringstream oss; - Section section; - section.setName( "section name" ); + Section section( "section name" ); section.addDescription( "description name 1" ); section.addDescription( "description name 2" ); section.setMinWidth( 100 ); - section.begin( oss ); + section.beginSection( oss ); EXPECT_EQ( oss.str(), "\n####################################################################################################\n" "## section name ##\n" @@ -75,7 +72,7 @@ TEST( testSection, sectionWithSetWidth ) oss.clear(); oss.str( "" ); - section.end( oss ); + section.endSection( oss ); EXPECT_EQ( oss.str(), "\n## End : section name ##\n" "####################################################################################################\n\n" @@ -86,13 +83,12 @@ TEST( testSection, sectionWithSetWidth ) TEST( testSection, sectionMultipleDescriptions ) { std::ostringstream oss; - Section section; - section.setName( "TIMESTEP START" ); + Section section( "TIMESTEP START" ); section.addDescription( "Time", "00h08m20s out of 2d, 21h26m40s (0% completed)", "500 s / 250000 s" ); section.addDescription( "Delta Time", "00h16m40s (1000 s)" ); section.addDescription( "- Cycle: 1" ); section.setMinWidth( 70 ); - section.begin( oss ); + section.beginSection( oss ); EXPECT_EQ ( oss.str(), "\n######################################################################\n" "## TIMESTEP START ##\n" @@ -105,7 +101,7 @@ TEST( testSection, sectionMultipleDescriptions ) oss.clear(); oss.str( "" ); - section.end( oss ); + section.endSection( oss ); EXPECT_EQ( oss.str(), "\n## End : TIMESTEP START ##\n" "######################################################################\n\n" diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index e806955d59b..5ea9fae2dcd 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -169,9 +169,9 @@ bool EventManager::run( DomainPartition & domain ) m_dt = dt_global; #endif } - Section section; + Section section( "TIMESTEP START" ); outputTime( section ); - section.begin(); + section.beginSection(); // Execute for(; m_currentSubEventnumSubGroups(); ++m_currentSubEvent ) @@ -208,7 +208,7 @@ bool EventManager::run( DomainPartition & domain ) } } - section.end(); + section.endSection(); // Increment time/cycle, reset the subevent counter m_time += m_dt; ++m_cycle; @@ -253,7 +253,6 @@ void EventManager::outputTime( Section & section ) const string const timeInfosUnfolded = timeInfo.toUnfoldedString() + timeCompletionUnfolded; string const timeCompletionSeconds = timeInfo.toSecondsString() + timeCompletionSecond; - section.setName( "TIMESTEP START" ); section.addDescription( "Time", timeInfosUnfolded, timeCompletionSeconds ); section.addDescription( "Delta Time", units::TimeFormatInfo::fromSeconds( m_dt ).toString() ); section.addDescription( "Cycle", m_cycle, cycleLimited ); diff --git a/src/coreComponents/mainInterface/ProblemManager.cpp b/src/coreComponents/mainInterface/ProblemManager.cpp index 3167c0be4b9..b0b8937340f 100644 --- a/src/coreComponents/mainInterface/ProblemManager.cpp +++ b/src/coreComponents/mainInterface/ProblemManager.cpp @@ -151,14 +151,13 @@ Group * ProblemManager::createChild( string const & GEOS_UNUSED_PARAM( childKey void ProblemManager::problemSetup() { GEOS_MARK_FUNCTION; - Section section; postInputInitializationRecursive(); - section.setName( "Mesh generation" ); - section.begin(); + Section section( "Mesh generation" ); + section.beginSection(); generateMesh(); - section.end(); + section.endSection(); // initialize_postMeshGeneration(); applyNumericalMethods(); From ae1f98f54131b0b025e884e5c3f504aa05ad8db1 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 10 Jul 2024 11:39:51 +0200 Subject: [PATCH 165/206] doxygen --- src/coreComponents/codingUtilities/Section.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/codingUtilities/Section.hpp index 3299146b055..eb11824a5e8 100644 --- a/src/coreComponents/codingUtilities/Section.hpp +++ b/src/coreComponents/codingUtilities/Section.hpp @@ -28,6 +28,10 @@ class Section { public: + /** + * @brief Construct a new Section + * @param m_sectionTitle The section title + */ Section( string_view m_sectionTitle ); /** From 61c27debe8c91019136ef566105b0d601b5ad3ac Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 12 Jul 2024 16:42:11 +0200 Subject: [PATCH 166/206] melvin review #2 --- .../codingUtilities/CMakeLists.txt | 2 -- .../codingUtilities/tests/CMakeLists.txt | 1 - src/coreComponents/events/EventManager.hpp | 2 +- src/coreComponents/fileIO/CMakeLists.txt | 3 +++ .../section}/Section.cpp | 25 +++++++++---------- .../section}/Section.hpp | 9 ++++--- .../fileIO/section/unitTests/CMakeLists.txt | 18 +++++++++++++ .../section/unitTests}/testSection.cpp | 20 +++++++-------- .../mainInterface/ProblemManager.cpp | 2 +- 9 files changed, 51 insertions(+), 31 deletions(-) rename src/coreComponents/{codingUtilities => fileIO/section}/Section.cpp (79%) rename src/coreComponents/{codingUtilities => fileIO/section}/Section.hpp (93%) create mode 100644 src/coreComponents/fileIO/section/unitTests/CMakeLists.txt rename src/coreComponents/{codingUtilities/tests => fileIO/section/unitTests}/testSection.cpp (82%) diff --git a/src/coreComponents/codingUtilities/CMakeLists.txt b/src/coreComponents/codingUtilities/CMakeLists.txt index ece6d72babf..53ee0981125 100644 --- a/src/coreComponents/codingUtilities/CMakeLists.txt +++ b/src/coreComponents/codingUtilities/CMakeLists.txt @@ -9,7 +9,6 @@ set( codingUtilities_headers UnitTestUtilities.hpp Utilities.hpp traits.hpp - Section.hpp ) # @@ -18,7 +17,6 @@ set( codingUtilities_headers set( codingUtilities_sources Parsing.cpp StringUtilities.cpp - Section.cpp ) set( dependencyList ${parallelDeps} common fast_float ) diff --git a/src/coreComponents/codingUtilities/tests/CMakeLists.txt b/src/coreComponents/codingUtilities/tests/CMakeLists.txt index 92a02cfeb3f..f6009a67062 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 - testSection.cpp testUtilities.cpp ) set( dependencyList gtest codingUtilities ${parallelDeps} ) diff --git a/src/coreComponents/events/EventManager.hpp b/src/coreComponents/events/EventManager.hpp index e795501d008..3b4ceebdfe2 100644 --- a/src/coreComponents/events/EventManager.hpp +++ b/src/coreComponents/events/EventManager.hpp @@ -18,7 +18,7 @@ #include "dataRepository/Group.hpp" #include "EventBase.hpp" -#include "codingUtilities/Section.hpp" +#include "fileIO/section/Section.hpp" namespace geos { diff --git a/src/coreComponents/fileIO/CMakeLists.txt b/src/coreComponents/fileIO/CMakeLists.txt index 93b1a3d0b5e..3f278d0af31 100644 --- a/src/coreComponents/fileIO/CMakeLists.txt +++ b/src/coreComponents/fileIO/CMakeLists.txt @@ -6,6 +6,7 @@ set( fileIO_headers Outputs/OutputUtilities.hpp Outputs/PythonOutput.hpp Outputs/RestartOutput.hpp + section/Section.hpp Table/TableLayout.hpp Table/TableFormatter.hpp Table/TableData.hpp @@ -25,6 +26,7 @@ set( fileIO_sources Outputs/OutputUtilities.cpp Outputs/PythonOutput.cpp Outputs/RestartOutput.cpp + section/Section.cpp Table/TableLayout.cpp Table/TableFormatter.cpp Table/TableData.cpp @@ -96,6 +98,7 @@ target_include_directories( fileIO PUBLIC ${CMAKE_SOURCE_DIR}/coreComponents ) if( GEOS_ENABLE_TESTS ) add_subdirectory( Table/unitTests ) + add_subdirectory( section/unitTests ) endif() diff --git a/src/coreComponents/codingUtilities/Section.cpp b/src/coreComponents/fileIO/section/Section.cpp similarity index 79% rename from src/coreComponents/codingUtilities/Section.cpp rename to src/coreComponents/fileIO/section/Section.cpp index dbf40d4ba80..6e377539556 100644 --- a/src/coreComponents/codingUtilities/Section.cpp +++ b/src/coreComponents/fileIO/section/Section.cpp @@ -24,7 +24,7 @@ namespace geos Section::Section( string_view sectionTitle ): m_sectionTitle( string( sectionTitle ) ), - m_rowMinWidth( 20 ) + m_rowMinWidth( 70 ) {} void Section::addDescription( string_view description ) @@ -37,13 +37,12 @@ void Section::setMinWidth( integer const & minWidth ) m_rowMinWidth = minWidth; } -void Section::computeMaxWidth( string_view title, +void Section::computeWidth( string_view title, std::vector< string > const & rowsDescription ) { - string const footerStr = "End : "; - integer const titleLength = footerStr.length() + title.length() + m_marginBorder * 2 + m_nbSpecialChar * 2; + integer const titleLength = m_footerTitle.length() + title.length() + m_marginBorder * 2 + m_nbSpecialChar * 2; - m_rowLength = std::max( m_rowMinWidth, titleLength ); + m_sectionWidth = std::max( m_rowMinWidth, titleLength ); if( rowsDescription.size() == 0 ) { @@ -60,7 +59,7 @@ void Section::computeMaxWidth( string_view title, integer const maxDescriptionLength = integer( maxDescriptionSize.length()) + m_marginBorder * 2 + m_nbSpecialChar * 2; - m_rowLength = std::max( maxDescriptionLength, m_rowLength ); + m_sectionWidth = std::max( maxDescriptionLength, m_sectionWidth ); } void Section::formatAndInsertDescriptions( string_view descriptionName, @@ -79,12 +78,12 @@ void Section::formatAndInsertDescriptions( string_view descriptionName, void Section::beginSection( std::ostream & oss ) { - computeMaxWidth( m_sectionTitle, m_descriptions ); + computeWidth( m_sectionTitle, m_descriptions ); - string const lineSection = GEOS_FMT( "{:#>{}}\n", "", m_rowLength ); + string const lineSection = GEOS_FMT( "{:#>{}}\n", "", m_sectionWidth ); string const horizontalChars = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); - integer const titleLength = m_rowLength - m_nbSpecialChar * 2; - integer const descriptionLength = m_rowLength - m_nbSpecialChar * 2 - m_marginBorder; + integer const titleLength = m_sectionWidth - m_nbSpecialChar * 2; + integer const descriptionLength = m_sectionWidth - m_nbSpecialChar * 2 - m_marginBorder; //build section title oss << '\n'; @@ -109,10 +108,10 @@ void Section::beginSection( std::ostream & oss ) void Section::endSection( std::ostream & oss ) const { - string const footerTitle = GEOS_FMT( "{} {}", "End :", m_sectionTitle ); - string const lineSection = GEOS_FMT( "{:#^{}}\n", "", m_rowLength ); + string const footerTitle = GEOS_FMT( "{}{}", m_footerTitle, m_sectionTitle ); + string const lineSection = GEOS_FMT( "{:#^{}}\n", "", m_sectionWidth ); string const horizontalChars = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); - integer const titleLength = m_rowLength - m_nbSpecialChar * 2; + integer const titleLength = m_sectionWidth - m_nbSpecialChar * 2; oss << '\n'; oss << GEOS_FMT( "{}{:^{}}{}\n", horizontalChars, footerTitle, titleLength, horizontalChars ); diff --git a/src/coreComponents/codingUtilities/Section.hpp b/src/coreComponents/fileIO/section/Section.hpp similarity index 93% rename from src/coreComponents/codingUtilities/Section.hpp rename to src/coreComponents/fileIO/section/Section.hpp index eb11824a5e8..796143114fc 100644 --- a/src/coreComponents/codingUtilities/Section.hpp +++ b/src/coreComponents/fileIO/section/Section.hpp @@ -70,12 +70,12 @@ class Section private: /** - * @brief Compute the max string size (m_rowLength) between title and the description(s) + * @brief Compute the max string size (m_sectionWidth) between title and the description(s) * @param m_sectionTitle The table title * @param descriptions The descriptions vector * @return The max row length of the section */ - void computeMaxWidth( string_view m_sectionTitle, + void computeWidth( string_view m_sectionTitle, std::vector< string > const & descriptions ); /** @@ -92,7 +92,7 @@ class Section /// title of section string m_sectionTitle; /// section length - integer m_rowLength; + integer m_sectionWidth; /// min width of section length integer m_rowMinWidth; @@ -101,6 +101,9 @@ class Section /// numbers of character used as border static constexpr integer m_nbSpecialChar = 2; + /// Start title footer string + static string_view constexpr m_footerTitle = "End : "; + }; template< typename ... Args > diff --git a/src/coreComponents/fileIO/section/unitTests/CMakeLists.txt b/src/coreComponents/fileIO/section/unitTests/CMakeLists.txt new file mode 100644 index 00000000000..eadc140567d --- /dev/null +++ b/src/coreComponents/fileIO/section/unitTests/CMakeLists.txt @@ -0,0 +1,18 @@ +# Specify list of tests +set( gtest_geosx_tests + testSection.cpp ) + +set( dependencyList gtest fileIO ${parallelDeps} ) + +# 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/codingUtilities/tests/testSection.cpp b/src/coreComponents/fileIO/section/unitTests/testSection.cpp similarity index 82% rename from src/coreComponents/codingUtilities/tests/testSection.cpp rename to src/coreComponents/fileIO/section/unitTests/testSection.cpp index 88816e326bd..f2424d42503 100644 --- a/src/coreComponents/codingUtilities/tests/testSection.cpp +++ b/src/coreComponents/fileIO/section/unitTests/testSection.cpp @@ -13,7 +13,7 @@ */ #include "common/DataTypes.hpp" -#include "codingUtilities/Section.hpp" +#include "fileIO/section/Section.hpp" #include using namespace geos; @@ -24,17 +24,17 @@ TEST( testSection, sectionWithTitle ) Section section( "section name" ); section.beginSection( oss ); EXPECT_EQ( oss.str(), - "\n##########################\n" - "## section name ##\n" - "##########################\n\n" + "\n######################################################################\n" + "## section name ##\n" + "######################################################################\n\n" ); oss.clear(); oss.str( "" ); section.endSection( oss ); EXPECT_EQ( oss.str(), - "\n## End : section name ##\n" - "##########################\n\n" + "\n## End : section name ##\n" + "######################################################################\n\n" ); oss.clear(); } @@ -46,10 +46,10 @@ TEST( testSection, sectionWithTitleAndOneDescription ) section.addDescription( "description name" ); section.beginSection( oss ); EXPECT_EQ( oss.str(), - "\n##########################\n" - "## section name ##\n" - "##########################\n" - "## description name ##\n\n" + "\n######################################################################\n" + "## section name ##\n" + "######################################################################\n" + "## description name ##\n\n" ); oss.clear(); } diff --git a/src/coreComponents/mainInterface/ProblemManager.cpp b/src/coreComponents/mainInterface/ProblemManager.cpp index b0b8937340f..576481d23b0 100644 --- a/src/coreComponents/mainInterface/ProblemManager.cpp +++ b/src/coreComponents/mainInterface/ProblemManager.cpp @@ -30,7 +30,7 @@ #include "events/tasks/TasksManager.hpp" #include "events/EventManager.hpp" #include "finiteElement/FiniteElementDiscretization.hpp" -#include "codingUtilities/Section.hpp" +#include "fileIO/section/Section.hpp" #include "finiteElement/FiniteElementDiscretizationManager.hpp" #include "finiteVolume/FluxApproximationBase.hpp" #include "finiteVolume/HybridMimeticDiscretization.hpp" From c0c1d6bf620704411ee5a45758c86bb1c4538355 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 12 Jul 2024 16:55:39 +0200 Subject: [PATCH 167/206] 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 168/206] 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 169/206] 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 170/206] 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 ca6188eacc3b500184b1ecab2291d426d57acddb Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 29 Aug 2024 14:52:52 +0200 Subject: [PATCH 171/206] fix after merge --- .../fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp | 5 ++--- .../fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp | 6 ++---- src/coreComponents/schema/schema.xsd | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) 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..3c209d8e2e0 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 @@ -164,13 +163,12 @@ class PVTFunctionBase 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( 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/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index 7b7a454cea3..0a2ef24dd74 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -2657,7 +2657,7 @@ Local- Add jump stabilization on interior of macro elements--> - + From e6b63ca4ce824f4d9946bbc59ffdd1d580048a92 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 4 Sep 2024 17:14:50 +0200 Subject: [PATCH 172/206] move outputPvt to tableFunction --- .../multifluid/CO2Brine/CO2BrineFluid.cpp | 7 ++-- .../fluid/multifluid/CO2Brine/PhaseModel.hpp | 2 +- .../CO2Brine/functions/BrineEnthalpy.cpp | 8 ++-- .../CO2Brine/functions/BrineEnthalpy.hpp | 2 +- .../CO2Brine/functions/CO2Enthalpy.cpp | 8 ++-- .../CO2Brine/functions/CO2Enthalpy.hpp | 2 +- .../CO2Brine/functions/CO2Solubility.cpp | 6 +-- .../CO2Brine/functions/CO2Solubility.hpp | 2 +- .../functions/EzrokhiBrineDensity.cpp | 8 ++-- .../functions/EzrokhiBrineDensity.hpp | 2 +- .../functions/EzrokhiBrineViscosity.cpp | 6 +-- .../functions/EzrokhiBrineViscosity.hpp | 2 +- .../functions/FenghourCO2Viscosity.cpp | 6 +-- .../functions/FenghourCO2Viscosity.hpp | 2 +- .../CO2Brine/functions/FlashModelBase.hpp | 37 +------------------ .../CO2Brine/functions/NoOpPVTFunction.hpp | 2 +- .../CO2Brine/functions/PVTFunctionBase.hpp | 37 +------------------ .../functions/PhillipsBrineDensity.cpp | 6 +-- .../functions/PhillipsBrineDensity.hpp | 2 +- .../functions/PhillipsBrineViscosity.cpp | 6 +-- .../functions/PhillipsBrineViscosity.hpp | 2 +- .../functions/SpanWagnerCO2Density.cpp | 6 +-- .../functions/SpanWagnerCO2Density.hpp | 2 +- .../CO2Brine/functions/WaterDensity.cpp | 6 +-- .../CO2Brine/functions/WaterDensity.hpp | 2 +- .../reactive/ReactiveBrineFluid.cpp | 2 +- .../functions/TableFunction.cpp | 19 ++++++++++ .../functions/TableFunction.hpp | 17 +++++++++ .../docs/CompositionalMultiphaseWell.rst | 2 +- .../testCO2BrinePVTModels.cpp | 4 +- .../testCO2SpycherPruessModels.cpp | 2 +- 31 files changed, 92 insertions(+), 125 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 63c0a0c87df..3f8ce9be266 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -330,7 +330,8 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() // then, we are ready to instantiate the phase models bool const isClone = this->isClone(); - PVTFunctionBase::TableOutputOptions const pvtOutputOpts = { + std::cout << "GET PATH -- " << this->getPath() << std::endl; + TableFunction::outputOptions const pvtOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() > 0 && logger::internal::rank==0), // writeInLog }; @@ -366,7 +367,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() { if( strs[1] == FLASH::catalogName() ) { - FlashModelBase::TableOutputOptions const flashOutputOpts = { + TableFunction::TableFunction::outputOptions const flashOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() > 0 && logger::internal::rank==0), // writeInLog }; @@ -412,7 +413,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() strs[2] = m_solubilityTables[0]; } - FlashModelBase::TableOutputOptions const flashOutputOpts = { + TableFunction::outputOptions 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 43e6ae39f20..03d17cb6528 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp @@ -62,7 +62,7 @@ struct PhaseModel array1d< array1d< string > > const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTProps::PVTFunctionBase::TableOutputOptions const pvtOutputOpts ) + TableFunction::outputOptions 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 dc8c2975cab..eb2aa25b578 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp @@ -192,7 +192,7 @@ BrineEnthalpy::BrineEnthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ): + TableFunction::outputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -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() ); - outputPVTTableData( m_CO2EnthalpyTable, pvtOutputOpts ); - outputPVTTableData( m_brineEnthalpyTable, pvtOutputOpts ); + m_CO2EnthalpyTable->outputPVTTableData( pvtOutputOpts ); + m_brineEnthalpyTable->outputPVTTableData( pvtOutputOpts ); } @@ -232,7 +232,7 @@ BrineEnthalpy::createKernelWrapper() const m_waterIndex ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, BrineEnthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, BrineEnthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions 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 45cc9ee0c37..5560e567d1e 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp @@ -92,7 +92,7 @@ class BrineEnthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ); + TableFunction::outputOptions 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 070a4027ec9..4c8bac27c7c 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp @@ -257,7 +257,7 @@ CO2Enthalpy::CO2Enthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ): + TableFunction::outputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -267,8 +267,8 @@ CO2Enthalpy::CO2Enthalpy( string const & name, m_CO2EnthalpyTable = makeCO2EnthalpyTable( inputParams, m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_CO2EnthalpyTable, pvtOutputOpts ); - outputPVTTableData( m_CO2EnthalpyTable, pvtOutputOpts ); + m_CO2EnthalpyTable->outputPVTTableData( pvtOutputOpts ); + m_CO2EnthalpyTable->outputPVTTableData( pvtOutputOpts ); } @@ -310,7 +310,7 @@ CO2Enthalpy::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, CO2Enthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, CO2Enthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions 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 2971d142970..27eb0f00c19 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp @@ -80,7 +80,7 @@ class CO2Enthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ); + TableFunction::outputOptions 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 ef0ad52e3b0..6eeeb10b807 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp @@ -221,7 +221,7 @@ CO2Solubility::CO2Solubility( string const & name, string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ): + TableFunction::outputOptions const pvtOutputOpts ): FlashModelBase( name, componentNames, componentMolarWeight ) @@ -257,8 +257,8 @@ CO2Solubility::CO2Solubility( string const & name, std::tie( m_CO2SolubilityTable, m_WaterVapourisationTable ) = makeSolubilityTables( m_modelName, inputParams, solubilityModel ); - outputPVTTableData( m_CO2SolubilityTable, pvtOutputOpts ); - outputPVTTableData( m_WaterVapourisationTable, pvtOutputOpts ); + m_CO2SolubilityTable->outputPVTTableData( pvtOutputOpts ); + m_WaterVapourisationTable->outputPVTTableData( pvtOutputOpts ); } diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp index dd24073dc2c..a2d23e9f2dd 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp @@ -117,7 +117,7 @@ class CO2Solubility : public FlashModelBase string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - PVTProps::FlashModelBase::TableOutputOptions const pvtOutputOpts ); + TableFunction::outputOptions 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 60ed3300e1f..cc1d1506533 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp @@ -38,7 +38,7 @@ EzrokhiBrineDensity::EzrokhiBrineDensity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ): + TableFunction::outputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -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() ); - outputPVTTableData( m_waterSatPressureTable, pvtOutputOpts ); - outputPVTTableData( m_waterSatDensityTable, pvtOutputOpts ); + m_waterSatPressureTable->outputPVTTableData( pvtOutputOpts ); + m_waterSatDensityTable->outputPVTTableData( pvtOutputOpts ); } void EzrokhiBrineDensity::makeCoefficients( string_array const & inputPara ) @@ -101,7 +101,7 @@ EzrokhiBrineDensity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions 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 c22fe2a461a..e3b45934d86 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp @@ -109,7 +109,7 @@ class EzrokhiBrineDensity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ); + TableFunction::outputOptions 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 a3daf85b546..0a78ec373e5 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp @@ -38,7 +38,7 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ): + TableFunction::outputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -52,7 +52,7 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, makeCoefficients( inputPara ); m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_waterViscosityTable, pvtOutputOpts ); + m_waterViscosityTable->outputPVTTableData( pvtOutputOpts ); } void EzrokhiBrineViscosity::makeCoefficients( string_array const & inputPara ) @@ -94,7 +94,7 @@ EzrokhiBrineViscosity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions 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 00e0463228b..eaaff9dffb0 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp @@ -98,7 +98,7 @@ class EzrokhiBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ); + TableFunction::outputOptions 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 93287b5e9fd..51e93a4ab63 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp @@ -142,14 +142,14 @@ FenghourCO2Viscosity::FenghourCO2Viscosity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ) + TableFunction::outputOptions const pvtOutputOpts ) : PVTFunctionBase( name, componentNames, componentMolarWeight ) { m_CO2ViscosityTable = makeViscosityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_CO2ViscosityTable, pvtOutputOpts ); + m_CO2ViscosityTable->outputPVTTableData( pvtOutputOpts ); } void FenghourCO2Viscosity::checkTablesParameters( real64 const pressure, @@ -166,7 +166,7 @@ FenghourCO2Viscosity::createKernelWrapper() const *m_CO2ViscosityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, FenghourCO2Viscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, FenghourCO2Viscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions 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 66538cf3921..c939ef35843 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp @@ -76,7 +76,7 @@ class FenghourCO2Viscosity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ); + TableFunction::outputOptions 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 e0fa430003f..c688241f5bc 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp @@ -79,22 +79,12 @@ class FlashModelBase virtual ~FlashModelBase() = default; - /// Struct containing output options - struct TableOutputOptions - { - /// 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 &, - TableOutputOptions const >; + array1d< real64 > const & >; static typename CatalogInterface::CatalogType & getCatalog() { static CatalogInterface::CatalogType catalog; @@ -111,31 +101,6 @@ 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 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/NoOpPVTFunction.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp index 64ccc545fda..f5843e572df 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp @@ -71,7 +71,7 @@ class NoOpPVTFunction : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ) + TableFunction::outputOptions 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 3c209d8e2e0..c8517c01543 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -114,23 +114,12 @@ class PVTFunctionBase virtual ~PVTFunctionBase() = default; - - /// Struct containing output options - struct TableOutputOptions - { - /// 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 &, - TableOutputOptions const >; + TableFunction::outputOptions const >; static typename CatalogInterface::CatalogType & getCatalog() { static CatalogInterface::CatalogType catalog; @@ -151,30 +140,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/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp index b0dab96bc31..208cec11700 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp @@ -177,7 +177,7 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ): + TableFunction::outputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -190,7 +190,7 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, m_brineDensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_brineDensityTable, pvtOutputOpts ); + m_brineDensityTable->outputPVTTableData( pvtOutputOpts ); } PhillipsBrineDensity::KernelWrapper @@ -209,7 +209,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 const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions 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 8f1d268ecbd..edf48c38bda 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp @@ -86,7 +86,7 @@ class PhillipsBrineDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ); + TableFunction::outputOptions 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 56a1b9a899a..c8a4ff343a4 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp @@ -37,7 +37,7 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ): + TableFunction::outputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -45,7 +45,7 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, m_waterViscosityTable = PureWaterProperties::makeSaturationViscosityTable( m_functionName, FunctionManager::getInstance() ); makeCoefficients( inputPara ); - outputPVTTableData( m_waterViscosityTable, pvtOutputOpts ); + m_waterViscosityTable->outputPVTTableData( pvtOutputOpts ); } void PhillipsBrineViscosity::makeCoefficients( string_array const & inputPara ) @@ -92,7 +92,7 @@ PhillipsBrineViscosity::createKernelWrapper() const m_coef1 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions 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 700f40b9abe..a832e92174a 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp @@ -84,7 +84,7 @@ class PhillipsBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ); + TableFunction::outputOptions 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 2cddfbd29ce..2539a0fae2c 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp @@ -279,7 +279,7 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ): + TableFunction::outputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -289,7 +289,7 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, m_CO2DensityTable = makeDensityTable( inputParams, m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_CO2DensityTable, pvtOutputOpts ); + m_CO2DensityTable->outputPVTTableData( pvtOutputOpts ); } void SpanWagnerCO2Density::checkTablesParameters( real64 const pressure, @@ -307,7 +307,7 @@ SpanWagnerCO2Density::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, SpanWagnerCO2Density, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, SpanWagnerCO2Density, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions 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 d39dc501c9f..46eae34b134 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp @@ -81,7 +81,7 @@ class SpanWagnerCO2Density : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ); + TableFunction::outputOptions 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 e1c93f941f5..9b3ebadeab9 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp @@ -37,7 +37,7 @@ WaterDensity::WaterDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ): + TableFunction::outputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -45,7 +45,7 @@ WaterDensity::WaterDensity( string const & name, GEOS_UNUSED_VAR( inputParams ); m_waterDensityTable = PureWaterProperties::makeSaturationDensityTable( m_functionName, FunctionManager::getInstance() ); - outputPVTTableData( m_waterDensityTable, pvtOutputOpts ); + m_waterDensityTable->outputPVTTableData( pvtOutputOpts ); } void WaterDensity::checkTablesParameters( real64 const pressure, @@ -62,7 +62,7 @@ WaterDensity::createKernelWrapper() const *m_waterDensityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, WaterDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, PVTFunctionBase::TableOutputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, WaterDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions 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 d7309fc193e..621e93cc5a5 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp @@ -76,7 +76,7 @@ class WaterDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableOutputOptions const pvtOutputOpts ); + TableFunction::outputOptions 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 eb4f84d1ae0..29b31c927c7 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp @@ -201,7 +201,7 @@ void ReactiveBrineFluid< PHASE > ::createPVTModels() InputError ); 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/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 6208f04a8e1..1cdd18dfe21 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -264,6 +264,25 @@ void collectValues( std::ostringstream & formatterStream, } } +void TableFunction::outputPVTTableData( outputOptions const pvtOutputOpts ) const +{ + if( pvtOutputOpts.writeInLog && this->numDimensions() <= 2 ) + { + TableTextFormatter textFormatter; + GEOS_LOG_RANK_0( textFormatter.toString( *this )); + } + if( pvtOutputOpts.writeCSV || ( pvtOutputOpts.writeInLog && this->numDimensions() >= 3 ) ) + { + string const filename = this->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( *this ); + } +} + template<> string TableCSVFormatter::toString< TableFunction >( TableFunction const & tableFunction ) const { diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index 93cd1df2dbd..d24e8bb5af1 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -48,6 +48,15 @@ class TableFunction : public FunctionBase Lower }; + /// Struct containing output options + struct outputOptions + { + /// Output PVT in CSV file + bool writeCSV; + /// Output PVT in log + bool writeInLog; + }; + /// maximum dimensions for the coordinates in the table static constexpr integer maxDimensions = 4; @@ -326,6 +335,13 @@ class TableFunction : public FunctionBase */ units::Unit getValueUnit() const { return m_valueUnit; } + + /** + * @brief Print the table(s) in the log and/or CSV files when requested by the user. + * @param pvtOutputOpts Struct containing output options + */ + void outputPVTTableData( outputOptions const pvtOutputOpts ) const; + /** * @brief Create an instance of the kernel wrapper * @return the kernel wrapper @@ -357,6 +373,7 @@ class TableFunction : public FunctionBase */ void readFile( string const & filename, array1d< real64 > & target ); + /// Coordinates for 1D table array1d< real64 > m_tableCoordinates1D; diff --git a/src/coreComponents/schema/docs/CompositionalMultiphaseWell.rst b/src/coreComponents/schema/docs/CompositionalMultiphaseWell.rst index 197e006821f..d484d65a68b 100644 --- a/src/coreComponents/schema/docs/CompositionalMultiphaseWell.rst +++ b/src/coreComponents/schema/docs/CompositionalMultiphaseWell.rst @@ -9,7 +9,7 @@ initialDt real64 1e+99 Initial time-step 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 -maxRelativeCompDensChange real64 1.79769e+308 Maximum (relative) change in a component density between two Newton iterations +maxRelativeCompDensChange real64 1.79769e+208 Maximum (relative) change in a component density between two Newton iterations maxRelativePressureChange real64 1 Maximum (relative) change in pressure between two Newton iterations (recommended with rate control) 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. diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp index 060c04f4e76..57ae2d621e2 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp @@ -361,7 +361,7 @@ std::unique_ptr< MODEL > makePVTFunction( string const & filename, { array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( str ); - PVTFunctionBase::TableOutputOptions const pvtOutputOpts = { + TableFunction::outputOptions const pvtOutputOpts = { true,// writeCSV true, // writeInLog }; @@ -406,7 +406,7 @@ std::unique_ptr< MODEL > makeFlashModel( string const & filename, while( std::getline( is, str ) ) { array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( str ); - FlashModelBase::TableOutputOptions const flashOutputOpts = { + TableFunction::outputOptions const flashOutputOpts = { true, // writeCSV true, // writeInLog }; diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp index 8643598e6e8..21e7a07189a 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp @@ -83,7 +83,7 @@ CO2SolubilitySpycherPruessTestFixture::makeFlashModel( string const & fileConten // Read file parameters array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( fileContent ); - FlashModelBase::TableOutputOptions const flashOutputOpts = { + TableFunction::outputOptions const flashOutputOpts = { false, // writeCSV false, // writeInLog }; From f45679fc15f87ed814a92ca066e4f5dd7b14cebd Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 4 Sep 2024 17:25:19 +0200 Subject: [PATCH 173/206] uppercase correction --- .../fluid/multifluid/CO2Brine/CO2BrineFluid.cpp | 6 +++--- .../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 +- .../multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp | 4 ++-- .../multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp | 2 +- .../multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp | 4 ++-- .../multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp | 2 +- .../fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp | 2 +- .../fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp | 2 +- .../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 | 2 +- src/coreComponents/functions/TableFunction.cpp | 2 +- src/coreComponents/functions/TableFunction.hpp | 4 ++-- .../unitTests/constitutiveTests/testCO2BrinePVTModels.cpp | 4 ++-- .../constitutiveTests/testCO2SpycherPruessModels.cpp | 2 +- 29 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 3f8ce9be266..aceff7bd603 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(); std::cout << "GET PATH -- " << this->getPath() << std::endl; - TableFunction::outputOptions const pvtOutputOpts = { + TableFunction::OutputOptions const pvtOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() > 0 && logger::internal::rank==0), // writeInLog }; @@ -367,7 +367,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() { if( strs[1] == FLASH::catalogName() ) { - TableFunction::TableFunction::outputOptions const flashOutputOpts = { + TableFunction::TableFunction::OutputOptions const flashOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() > 0 && logger::internal::rank==0), // writeInLog }; @@ -413,7 +413,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() strs[2] = m_solubilityTables[0]; } - TableFunction::outputOptions const flashOutputOpts = { + TableFunction::OutputOptions 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 03d17cb6528..82b840e832b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp @@ -62,7 +62,7 @@ struct PhaseModel array1d< array1d< string > > const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ) + TableFunction::OutputOptions 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 eb2aa25b578..090b1a239f6 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp @@ -192,7 +192,7 @@ BrineEnthalpy::BrineEnthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ): + TableFunction::OutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -232,7 +232,7 @@ BrineEnthalpy::createKernelWrapper() const m_waterIndex ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, BrineEnthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, BrineEnthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions 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 5560e567d1e..ea28cae5169 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.hpp @@ -92,7 +92,7 @@ class BrineEnthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ); + TableFunction::OutputOptions 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 4c8bac27c7c..92a551fe3b6 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp @@ -257,7 +257,7 @@ CO2Enthalpy::CO2Enthalpy( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ): + TableFunction::OutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -310,7 +310,7 @@ CO2Enthalpy::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, CO2Enthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, CO2Enthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions 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 27eb0f00c19..0baf1b6e3db 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.hpp @@ -80,7 +80,7 @@ class CO2Enthalpy : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ); + TableFunction::OutputOptions 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 6eeeb10b807..b19b04dc95f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.cpp @@ -221,7 +221,7 @@ CO2Solubility::CO2Solubility( string const & name, string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ): + TableFunction::OutputOptions 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 a2d23e9f2dd..52b776ea04d 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Solubility.hpp @@ -117,7 +117,7 @@ class CO2Solubility : public FlashModelBase string_array const & phaseNames, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ); + TableFunction::OutputOptions 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 cc1d1506533..90b47b44ba2 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp @@ -38,7 +38,7 @@ EzrokhiBrineDensity::EzrokhiBrineDensity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ): + TableFunction::OutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -101,7 +101,7 @@ EzrokhiBrineDensity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions 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 e3b45934d86..43fb0dc684d 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.hpp @@ -109,7 +109,7 @@ class EzrokhiBrineDensity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ); + TableFunction::OutputOptions 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 0a78ec373e5..316cde822ed 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp @@ -38,7 +38,7 @@ EzrokhiBrineViscosity::EzrokhiBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ): + TableFunction::OutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -94,7 +94,7 @@ EzrokhiBrineViscosity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions 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 eaaff9dffb0..3ab512f0c02 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.hpp @@ -98,7 +98,7 @@ class EzrokhiBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ); + TableFunction::OutputOptions 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 51e93a4ab63..a7607bd37d5 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp @@ -142,7 +142,7 @@ FenghourCO2Viscosity::FenghourCO2Viscosity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ) + TableFunction::OutputOptions const pvtOutputOpts ) : PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -166,7 +166,7 @@ FenghourCO2Viscosity::createKernelWrapper() const *m_CO2ViscosityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, FenghourCO2Viscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, FenghourCO2Viscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions 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 c939ef35843..2964e8d8abc 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.hpp @@ -76,7 +76,7 @@ class FenghourCO2Viscosity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ); + TableFunction::OutputOptions const pvtOutputOpts ); virtual ~FenghourCO2Viscosity() override = default; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp index f5843e572df..a1a539921da 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/NoOpPVTFunction.hpp @@ -71,7 +71,7 @@ class NoOpPVTFunction : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ) + TableFunction::OutputOptions 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 c8517c01543..b478888442f 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp @@ -119,7 +119,7 @@ class PVTFunctionBase array1d< string > const &, array1d< string > const &, array1d< real64 > const &, - TableFunction::outputOptions const >; + TableFunction::OutputOptions const >; static typename CatalogInterface::CatalogType & getCatalog() { static CatalogInterface::CatalogType catalog; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp index 208cec11700..fa99ce2f424 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp @@ -177,7 +177,7 @@ PhillipsBrineDensity::PhillipsBrineDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ): + TableFunction::OutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -209,7 +209,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 &, TableFunction::outputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions 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 edf48c38bda..2696e788ae5 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.hpp @@ -86,7 +86,7 @@ class PhillipsBrineDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ); + TableFunction::OutputOptions 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 c8a4ff343a4..485f559440b 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp @@ -37,7 +37,7 @@ PhillipsBrineViscosity::PhillipsBrineViscosity( string const & name, string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ): + TableFunction::OutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -92,7 +92,7 @@ PhillipsBrineViscosity::createKernelWrapper() const m_coef1 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions 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 a832e92174a..df3b2f12f82 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.hpp @@ -84,7 +84,7 @@ class PhillipsBrineViscosity : public PVTFunctionBase string_array const & inputPara, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ); + TableFunction::OutputOptions 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 2539a0fae2c..6949e04e6bc 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp @@ -279,7 +279,7 @@ SpanWagnerCO2Density::SpanWagnerCO2Density( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ): + TableFunction::OutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -307,7 +307,7 @@ SpanWagnerCO2Density::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, SpanWagnerCO2Density, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, SpanWagnerCO2Density, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions 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 46eae34b134..3d3818392f7 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.hpp @@ -81,7 +81,7 @@ class SpanWagnerCO2Density : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ); + TableFunction::OutputOptions 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 9b3ebadeab9..17d2b6f5809 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp @@ -37,7 +37,7 @@ WaterDensity::WaterDensity( string const & name, string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ): + TableFunction::OutputOptions const pvtOutputOpts ): PVTFunctionBase( name, componentNames, componentMolarWeight ) @@ -62,7 +62,7 @@ WaterDensity::createKernelWrapper() const *m_waterDensityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, WaterDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::outputOptions const ) +REGISTER_CATALOG_ENTRY( PVTFunctionBase, WaterDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions 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 621e93cc5a5..35f0ee158b8 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.hpp @@ -76,7 +76,7 @@ class WaterDensity : public PVTFunctionBase string_array const & inputParams, string_array const & componentNames, array1d< real64 > const & componentMolarWeight, - TableFunction::outputOptions const pvtOutputOpts ); + TableFunction::OutputOptions 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 29b31c927c7..a7219cae14d 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/reactive/ReactiveBrineFluid.cpp @@ -201,7 +201,7 @@ void ReactiveBrineFluid< PHASE > ::createPVTModels() InputError ); 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/functions/TableFunction.cpp b/src/coreComponents/functions/TableFunction.cpp index 1cdd18dfe21..24bb8dda81d 100644 --- a/src/coreComponents/functions/TableFunction.cpp +++ b/src/coreComponents/functions/TableFunction.cpp @@ -264,7 +264,7 @@ void collectValues( std::ostringstream & formatterStream, } } -void TableFunction::outputPVTTableData( outputOptions const pvtOutputOpts ) const +void TableFunction::outputPVTTableData( OutputOptions const pvtOutputOpts ) const { if( pvtOutputOpts.writeInLog && this->numDimensions() <= 2 ) { diff --git a/src/coreComponents/functions/TableFunction.hpp b/src/coreComponents/functions/TableFunction.hpp index d24e8bb5af1..6d869bf2efe 100644 --- a/src/coreComponents/functions/TableFunction.hpp +++ b/src/coreComponents/functions/TableFunction.hpp @@ -49,7 +49,7 @@ class TableFunction : public FunctionBase }; /// Struct containing output options - struct outputOptions + struct OutputOptions { /// Output PVT in CSV file bool writeCSV; @@ -340,7 +340,7 @@ class TableFunction : public FunctionBase * @brief Print the table(s) in the log and/or CSV files when requested by the user. * @param pvtOutputOpts Struct containing output options */ - void outputPVTTableData( outputOptions const pvtOutputOpts ) const; + void outputPVTTableData( OutputOptions const pvtOutputOpts ) const; /** * @brief Create an instance of the kernel wrapper diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp index 57ae2d621e2..f2e69936e60 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2BrinePVTModels.cpp @@ -361,7 +361,7 @@ std::unique_ptr< MODEL > makePVTFunction( string const & filename, { array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( str ); - TableFunction::outputOptions const pvtOutputOpts = { + TableFunction::OutputOptions const pvtOutputOpts = { true,// writeCSV true, // writeInLog }; @@ -406,7 +406,7 @@ std::unique_ptr< MODEL > makeFlashModel( string const & filename, while( std::getline( is, str ) ) { array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( str ); - TableFunction::outputOptions const flashOutputOpts = { + TableFunction::OutputOptions const flashOutputOpts = { true, // writeCSV true, // writeInLog }; diff --git a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp index 21e7a07189a..28b0ee77dfb 100644 --- a/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp +++ b/src/coreComponents/unitTests/constitutiveTests/testCO2SpycherPruessModels.cpp @@ -83,7 +83,7 @@ CO2SolubilitySpycherPruessTestFixture::makeFlashModel( string const & fileConten // Read file parameters array1d< string > const strs = stringutilities::tokenizeBySpaces< array1d >( fileContent ); - TableFunction::outputOptions const flashOutputOpts = { + TableFunction::OutputOptions const flashOutputOpts = { false, // writeCSV false, // writeInLog }; From 4ea8034c2e570ca2a2414e50742ac8bec5634589 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 5 Sep 2024 11:37:59 +0200 Subject: [PATCH 174/206] removing dead code --- .../multifluid/CO2Brine/functions/BrineEnthalpy.cpp | 2 -- .../multifluid/CO2Brine/functions/CO2Enthalpy.cpp | 2 -- .../CO2Brine/functions/EzrokhiBrineDensity.cpp | 2 -- .../CO2Brine/functions/EzrokhiBrineViscosity.cpp | 2 -- .../CO2Brine/functions/FenghourCO2Viscosity.cpp | 2 -- .../CO2Brine/functions/FlashModelBase.hpp | 13 ------------- .../CO2Brine/functions/PVTFunctionBase.hpp | 12 ------------ .../CO2Brine/functions/PhillipsBrineDensity.cpp | 2 -- .../CO2Brine/functions/PhillipsBrineViscosity.cpp | 2 -- .../CO2Brine/functions/SpanWagnerCO2Density.cpp | 2 -- .../multifluid/CO2Brine/functions/WaterDensity.cpp | 2 -- 11 files changed, 43 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp index 090b1a239f6..94a17cb31ec 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/BrineEnthalpy.cpp @@ -232,8 +232,6 @@ BrineEnthalpy::createKernelWrapper() const m_waterIndex ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, BrineEnthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions const ) - } // namespace PVTProps } // namespace constitutive diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp index 92a551fe3b6..ae63d8e545e 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/CO2Enthalpy.cpp @@ -310,8 +310,6 @@ CO2Enthalpy::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, CO2Enthalpy, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions const ) - } // namespace PVTProps } // namespace constitutive diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp index 90b47b44ba2..abcbd08cb48 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineDensity.cpp @@ -101,8 +101,6 @@ EzrokhiBrineDensity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions const ) - } // end namespace PVTProps } // namespace constitutive diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp index 316cde822ed..7e2692d65f7 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/EzrokhiBrineViscosity.cpp @@ -94,8 +94,6 @@ EzrokhiBrineViscosity::createKernelWrapper() const m_coef2 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, EzrokhiBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions const ) - } // end namespace PVTProps } // namespace constitutive diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp index a7607bd37d5..ee52947f1a5 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FenghourCO2Viscosity.cpp @@ -166,8 +166,6 @@ FenghourCO2Viscosity::createKernelWrapper() const *m_CO2ViscosityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, FenghourCO2Viscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions const ) - } // end namespace PVTProps } // namespace constitutive diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/FlashModelBase.hpp index c688241f5bc..ddf64628db7 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 { @@ -79,18 +78,6 @@ class FlashModelBase virtual ~FlashModelBase() = default; - using CatalogInterface = dataRepository::CatalogInterface< FlashModelBase, - string const &, - string_array const &, - string_array const &, - string_array const &, - array1d< real64 > const & >; - static typename CatalogInterface::CatalogType & getCatalog() - { - static CatalogInterface::CatalogType catalog; - return catalog; - } - virtual string getCatalogName() const = 0; /** diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionBase.hpp index b478888442f..3c46e4ea145 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,17 +113,6 @@ class PVTFunctionBase virtual ~PVTFunctionBase() = default; - using CatalogInterface = dataRepository::CatalogInterface< PVTFunctionBase, - string const &, - array1d< string > const &, - array1d< string > const &, - array1d< real64 > const &, - TableFunction::OutputOptions const >; - static typename CatalogInterface::CatalogType & getCatalog() - { - static CatalogInterface::CatalogType catalog; - return catalog; - } virtual string getCatalogName() const = 0; diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp index fa99ce2f424..57d67db8603 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineDensity.cpp @@ -209,8 +209,6 @@ 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 &, TableFunction::OutputOptions const ) - } // namespace PVTProps } // namespace constitutive diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp index 485f559440b..9c355af93ac 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/PhillipsBrineViscosity.cpp @@ -92,8 +92,6 @@ PhillipsBrineViscosity::createKernelWrapper() const m_coef1 ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, PhillipsBrineViscosity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions const ) - } // end namespace PVTProps } // namespace constitutive diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp index 6949e04e6bc..fa24bcac482 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/SpanWagnerCO2Density.cpp @@ -307,8 +307,6 @@ SpanWagnerCO2Density::createKernelWrapper() const m_CO2Index ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, SpanWagnerCO2Density, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions const ) - } // namespace PVTProps } // namespace constitutive diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp index 17d2b6f5809..7ed320ad907 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/functions/WaterDensity.cpp @@ -62,8 +62,6 @@ WaterDensity::createKernelWrapper() const *m_waterDensityTable ); } -REGISTER_CATALOG_ENTRY( PVTFunctionBase, WaterDensity, string const &, string_array const &, string_array const &, array1d< real64 > const &, TableFunction::OutputOptions const ) - } // namespace PVTProps } // namespace constitutive From 3f35dc717ef84d73d3202a74b0f6e3dea1f55b84 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 5 Sep 2024 11:40:45 +0200 Subject: [PATCH 175/206] remove unused code --- .../constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index aceff7bd603..85b6b8e9fb6 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -330,7 +330,6 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() // then, we are ready to instantiate the phase models bool const isClone = this->isClone(); - std::cout << "GET PATH -- " << this->getPath() << std::endl; TableFunction::OutputOptions const pvtOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() > 0 && logger::internal::rank==0), // writeInLog @@ -367,7 +366,7 @@ void CO2BrineFluid< PHASE1, PHASE2, FLASH >::createPVTModels() { if( strs[1] == FLASH::catalogName() ) { - TableFunction::TableFunction::OutputOptions const flashOutputOpts = { + TableFunction::OutputOptions const flashOutputOpts = { !isClone && m_writeCSV,// writeCSV !isClone && (getLogLevel() > 0 && logger::internal::rank==0), // writeInLog }; From 231bad710acbc7051fe0204812722fc488c6f6fc Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 5 Sep 2024 14:19:56 +0200 Subject: [PATCH 176/206] missing import --- .../constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp | 1 + .../constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp index 85b6b8e9fb6..4832b45d5fe 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/CO2BrineFluid.cpp @@ -21,6 +21,7 @@ #include "constitutive/fluid/multifluid/MultiFluidFields.hpp" #include "constitutive/fluid/multifluid/CO2Brine/functions/PVTFunctionHelpers.hpp" #include "common/Units.hpp" +#include "functions/TableFunction.hpp" namespace geos { diff --git a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp index 82b840e832b..4e964127526 100644 --- a/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp +++ b/src/coreComponents/constitutive/fluid/multifluid/CO2Brine/PhaseModel.hpp @@ -20,7 +20,7 @@ #ifndef GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_PHASEMODEL_HPP_ #define GEOS_CONSTITUTIVE_FLUID_MULTIFLUID_CO2BRINE_PHASEMODEL_HPP_ -#include "functions/PVTFunctionBase.hpp" +#include "functions/TableFunction.hpp" namespace geos { From 57f3a45d65926abaa35a5c6a9793662cebc8202d Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 24 Sep 2024 14:13:01 +0200 Subject: [PATCH 177/206] xsd --- src/coreComponents/schema/schema.xsd | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index d28dacf4e1d..d6018bf6391 100644 --- a/src/coreComponents/schema/schema.xsd +++ b/src/coreComponents/schema/schema.xsd @@ -1770,6 +1770,10 @@ stress - traction is applied to the faces as specified by the inner product of i + + + + @@ -1822,6 +1826,8 @@ stress - traction is applied to the faces as specified by the inner product of i + + +* Require - Use line search. If smaller residual than starting resdual is not achieved, cut time-step.--> @@ -1922,10 +1928,12 @@ the relative residual norm satisfies: - + + + @@ -1941,15 +1949,15 @@ the relative residual norm satisfies: - + - + - + - + - + - + @@ -4091,7 +4091,7 @@ Local- Add jump stabilization on interior of macro elements--> - + @@ -4113,7 +4113,7 @@ Local- Add jump stabilization on interior of macro elements--> - + @@ -4128,7 +4128,7 @@ Local- Add jump stabilization on interior of macro elements--> - Log Level 3 details values for each region.--> - + From ed4c723febb897b5417a71066bbff32b5e016692 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 7 Oct 2024 11:37:42 +0200 Subject: [PATCH 181/206] refacto section with adding description at the end of section --- src/coreComponents/fileIO/section/Section.cpp | 117 ++++++++---------- src/coreComponents/fileIO/section/Section.hpp | 21 ++-- .../fileIO/section/unitTests/testSection.cpp | 12 +- 3 files changed, 67 insertions(+), 83 deletions(-) diff --git a/src/coreComponents/fileIO/section/Section.cpp b/src/coreComponents/fileIO/section/Section.cpp index e651746b3ad..273eeac148f 100644 --- a/src/coreComponents/fileIO/section/Section.cpp +++ b/src/coreComponents/fileIO/section/Section.cpp @@ -24,7 +24,7 @@ namespace geos Section::Section( string_view sectionTitle ): m_sectionTitle( string( sectionTitle ) ), - m_rowMinWidth( 70 ) + m_sectionWidth( sectionTitle.length() ) {} void Section::addDescription( string_view description ) @@ -42,111 +42,98 @@ void Section::setMinWidth( integer const & minWidth ) m_rowMinWidth = minWidth; } -void Section::computeWidth() -{ - integer const titleLength = m_footerTitle.length() + m_sectionTitle.length(); - integer maxDescriptionLength = titleLength; - - if( !m_descriptions.empty()) - { - auto it = std::max_element( m_descriptions.begin(), m_descriptions.end(), - []( auto const & a, auto const & b ) { - return a.size() < b.size(); - } ); - string const maxDescriptionSize = *it; - maxDescriptionLength = std::max( (integer)maxDescriptionSize.length(), maxDescriptionLength ); - } - - if( !m_endLogMessages.empty()) - { - auto it = std::max_element( m_endLogMessages.begin(), m_endLogMessages.end(), - []( auto const & a, auto const & b ) { - return a.size() < b.size(); - } ); - string const maxDescriptionSize = *it; - maxDescriptionLength = std::max( (integer)maxDescriptionSize.length(), maxDescriptionLength ); - } - - m_sectionWidth = maxDescriptionLength + m_marginBorder * 2 + m_nbSpecialChar * 2; -} - void Section::formatAndInsertDescriptions( std::vector< string > & descriptionContainer, string_view descriptionName, std::vector< string > const & descriptionValues ) { - string const descNameFormatted = GEOS_FMT( "- {}: ", string( descriptionName )); - integer const descNameLength = descNameFormatted.length(); - descriptionContainer.push_back( GEOS_FMT( "{}{}", descNameFormatted, descriptionValues[0] ) ); + string descriptionNameFormatted = GEOS_FMT( "- {}: ", string( descriptionName )); + string const descriptionFormatted = GEOS_FMT( "{}{}", descriptionNameFormatted, descriptionValues[0] ); + integer spacesFromBorder = m_marginBorder * 2 + m_nbSpecialChar * 2; + integer const completeDescriptionLength = descriptionFormatted.length() + spacesFromBorder; + descriptionContainer.push_back( descriptionFormatted ); + + m_sectionWidth = std::max( completeDescriptionLength, m_sectionWidth ); + for( size_t idxValue = 1; idxValue < descriptionValues.size(); idxValue++ ) { - descriptionContainer.push_back( GEOS_FMT( "{:>{}}{}", " ", - descNameLength, - descriptionValues[idxValue] ) ); + size_t const spaces = descriptionValues[idxValue].length() + descriptionNameFormatted.length(); + descriptionContainer.push_back( GEOS_FMT( "{:>{}}", descriptionValues[idxValue], spaces ) ); } } -string Section::constructDescriptionsWithContainer( std::vector< string > const & descriptions, integer const length ) const +string Section::constructDescriptionsWithContainer( std::vector< string > const & descriptions ) const { std::ostringstream oss; for( const auto & description : descriptions ) { - constructDescription( oss, description, length ); + integer const rowDescriptionLength = m_sectionWidth - m_nbSpecialChar * 2 - m_marginBorder; + constructDescription( oss, description, rowDescriptionLength ); } return oss.str(); } -void Section::constructDescription( std::ostringstream & oss, string const & description, integer length ) const +void Section::constructDescription( std::ostringstream & oss, + string const & description, + integer const remainingLength ) const { - oss << m_borderSpaces; - oss << GEOS_FMT( "{:<{}}{:<{}}", " ", m_marginBorder, description, length ); - oss << m_borderSpaces << '\n'; + string borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); + oss << borderCharacters; + oss << GEOS_FMT( "{:<{}}{:<{}}", " ", m_marginBorder, description, remainingLength ); + oss << borderCharacters << '\n'; } -void Section::beginSection( std::ostream & oss ) +void Section::outputSection( std::ostream & oss, string_view topPart, string_view bottomPart ) const { - computeWidth(); + oss << '\n'; + oss << topPart; + oss << bottomPart; + oss << '\n'; +} +void Section::beginSection( std::ostream & oss ) +{ + m_sectionWidth = std::max( m_sectionWidth, m_rowMinWidth ); m_lineSection = GEOS_FMT( "{:#>{}}\n", "", m_sectionWidth ); - m_borderSpaces = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); + string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); integer const titleLength = m_sectionWidth - m_nbSpecialChar * 2; - integer const descriptionLength = m_sectionWidth - m_nbSpecialChar * 2 - m_marginBorder; string descriptions; if( !m_descriptions.empty()) { - descriptions = constructDescriptionsWithContainer( m_descriptions, descriptionLength ); + descriptions = constructDescriptionsWithContainer( m_descriptions ); } - //TODO fonction output (args) - oss << '\n'; - oss << m_lineSection; - oss << GEOS_FMT( "{}{:^{}}{}\n", m_borderSpaces, m_sectionTitle, titleLength, m_borderSpaces );//TODO refacto here - oss << m_lineSection; - oss << descriptions; - oss << '\n'; + string titleRowFormatted = GEOS_FMT( "{}{:^{}}{}\n", + borderCharacters, + m_sectionTitle, + titleLength, + borderCharacters ); + + string topPart = GEOS_FMT( "{}{}{}", m_lineSection, titleRowFormatted, m_lineSection ); + string bottomPart = descriptions; + outputSection( oss, topPart, bottomPart ); } -void Section::endSection( std::ostream & oss ) const +void Section::endSection( std::ostream & os ) const { string const footerTitle = GEOS_FMT( "{}{}", m_footerTitle, m_sectionTitle ); string const lineSection = GEOS_FMT( "{:#^{}}\n", "", m_sectionWidth ); - string const horizontalChars = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); - + string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); integer const titleLength = m_sectionWidth - m_nbSpecialChar * 2; - integer const descriptionLength = m_sectionWidth - m_nbSpecialChar * 2 - m_marginBorder; - string endDescriptions; + string topPart; if( !m_endLogMessages.empty() ) { - endDescriptions = constructDescriptionsWithContainer( m_endLogMessages, descriptionLength ); + topPart = GEOS_FMT( "{}{}", constructDescriptionsWithContainer( m_endLogMessages ), m_lineSection ); } - //TODO fonction output (args) - oss << '\n'; - oss << GEOS_FMT( "{}{:^{}}{}\n", horizontalChars, footerTitle, titleLength, horizontalChars ); - oss << lineSection; - oss << endDescriptions; - oss << '\n'; + string titleRowFormatted = GEOS_FMT( "{}{:^{}}{}\n", + borderCharacters, + footerTitle, + titleLength, + borderCharacters ); + string bottomPart = GEOS_FMT( "{}{}", titleRowFormatted, m_lineSection ); + outputSection( os, topPart, bottomPart ); } } diff --git a/src/coreComponents/fileIO/section/Section.hpp b/src/coreComponents/fileIO/section/Section.hpp index 7969be4ae62..0359ac8171f 100644 --- a/src/coreComponents/fileIO/section/Section.hpp +++ b/src/coreComponents/fileIO/section/Section.hpp @@ -86,10 +86,10 @@ class Section private: - /** - * @brief Compute the max string size (m_sectionWidth) between title and the description(s) - */ - void computeWidth(); + // /** + // * @brief Compute the max string size (m_sectionWidth) between title and the description(s) + // */ + // void computeWidth(); /** * @brief Build a description from the name and description values @@ -100,9 +100,13 @@ class Section string_view descriptionName, std::vector< string > const & decriptionsValues ); - string constructDescriptionsWithContainer( std::vector< string > const & descriptions, integer length ) const; + string constructDescriptionsWithContainer( std::vector< string > const & descriptions ) const; + + void constructDescription( std::ostringstream & oss, + string const & description, + integer const remainingLength ) const; - void constructDescription( std::ostringstream & oss, string const & description, integer length ) const; + void outputSection( std::ostream & oss, string_view topPart, string_view bottomPart ) const; /// Vector containing all descriptions std::vector< string > m_descriptions; @@ -114,7 +118,7 @@ class Section /// section length integer m_sectionWidth; /// min width of section length - integer m_rowMinWidth; + integer m_rowMinWidth = 70; /// description border margin static constexpr integer m_marginBorder = 2; @@ -123,9 +127,6 @@ class Section /// string m_lineSection; - /// - string m_borderSpaces; - /// Start title footer string static string_view constexpr m_footerTitle = "End : "; diff --git a/src/coreComponents/fileIO/section/unitTests/testSection.cpp b/src/coreComponents/fileIO/section/unitTests/testSection.cpp index 9430b1226a5..38392c7faa1 100644 --- a/src/coreComponents/fileIO/section/unitTests/testSection.cpp +++ b/src/coreComponents/fileIO/section/unitTests/testSection.cpp @@ -114,15 +114,9 @@ TEST( testSection, sectionEndDescription ) std::ostringstream oss; Section section( "TIMESTEP START" ); section.addDescription( "description" ); - section.addEndDescription("test end description"); + section.addEndDescription( "test end description" ); section.setMinWidth( 70 ); section.beginSection( oss ); - // EXPECT_EQ ( oss.str(), - // "\n######################################################################\n" - // "## TIMESTEP START ##\n" - // "######################################################################\n" - // "## - Time: 00h08m20s out of 2d, 21h26m40s (0% completed) ##\n" - // ); oss.clear(); oss.str( "" ); @@ -131,7 +125,9 @@ TEST( testSection, sectionEndDescription ) std::cout << " end section \n" << oss.str() << std::endl; EXPECT_EQ( oss.str(), - "\n## End : TIMESTEP START ##\n" + "\n## test end description ##\n" + "######################################################################\n" + "## End : TIMESTEP START ##\n" "######################################################################\n\n" ); oss.clear(); From 26806da3d1383a67b6d1b088a69fa5a0d3411fad Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 7 Oct 2024 14:21:10 +0200 Subject: [PATCH 182/206] doxygen --- .../common/format/table/TableFormatter.cpp | 2 +- src/coreComponents/fileIO/section/Section.cpp | 32 +++++++------------ src/coreComponents/fileIO/section/Section.hpp | 32 +++++++++++-------- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index fad1274a500..0625ffac6d6 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -156,7 +156,7 @@ string TableTextFormatter::layoutToString() const return tableOutput.str(); } -template <> +template<> string TableTextFormatter::toString( TableData const & tableData ) const { std::ostringstream tableOutput; diff --git a/src/coreComponents/fileIO/section/Section.cpp b/src/coreComponents/fileIO/section/Section.cpp index 273eeac148f..4648dae76e1 100644 --- a/src/coreComponents/fileIO/section/Section.cpp +++ b/src/coreComponents/fileIO/section/Section.cpp @@ -61,20 +61,20 @@ void Section::formatAndInsertDescriptions( std::vector< string > & descriptionCo } } -string Section::constructDescriptionsWithContainer( std::vector< string > const & descriptions ) const +string Section::constructDescriptionsFromVector( std::vector< string > const & descriptions ) const { std::ostringstream oss; for( const auto & description : descriptions ) { integer const rowDescriptionLength = m_sectionWidth - m_nbSpecialChar * 2 - m_marginBorder; - constructDescription( oss, description, rowDescriptionLength ); + formatDescription( oss, description, rowDescriptionLength ); } return oss.str(); } -void Section::constructDescription( std::ostringstream & oss, - string const & description, - integer const remainingLength ) const +void Section::formatDescription( std::ostringstream & oss, + string const & description, + integer const remainingLength ) const { string borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); oss << borderCharacters; @@ -82,18 +82,10 @@ void Section::constructDescription( std::ostringstream & oss, oss << borderCharacters << '\n'; } -void Section::outputSection( std::ostream & oss, string_view topPart, string_view bottomPart ) const -{ - oss << '\n'; - oss << topPart; - oss << bottomPart; - oss << '\n'; -} - void Section::beginSection( std::ostream & oss ) { m_sectionWidth = std::max( m_sectionWidth, m_rowMinWidth ); - m_lineSection = GEOS_FMT( "{:#>{}}\n", "", m_sectionWidth ); + horizontalBorder = GEOS_FMT( "{:#>{}}\n", "", m_sectionWidth ); string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); integer const titleLength = m_sectionWidth - m_nbSpecialChar * 2; @@ -101,7 +93,7 @@ void Section::beginSection( std::ostream & oss ) if( !m_descriptions.empty()) { - descriptions = constructDescriptionsWithContainer( m_descriptions ); + descriptions = constructDescriptionsFromVector( m_descriptions ); } string titleRowFormatted = GEOS_FMT( "{}{:^{}}{}\n", @@ -110,9 +102,9 @@ void Section::beginSection( std::ostream & oss ) titleLength, borderCharacters ); - string topPart = GEOS_FMT( "{}{}{}", m_lineSection, titleRowFormatted, m_lineSection ); + string topPart = GEOS_FMT( "{}{}{}", horizontalBorder, titleRowFormatted, horizontalBorder ); string bottomPart = descriptions; - outputSection( oss, topPart, bottomPart ); + oss << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } void Section::endSection( std::ostream & os ) const @@ -125,7 +117,7 @@ void Section::endSection( std::ostream & os ) const if( !m_endLogMessages.empty() ) { - topPart = GEOS_FMT( "{}{}", constructDescriptionsWithContainer( m_endLogMessages ), m_lineSection ); + topPart = GEOS_FMT( "{}{}", constructDescriptionsFromVector( m_endLogMessages ), horizontalBorder ); } string titleRowFormatted = GEOS_FMT( "{}{:^{}}{}\n", @@ -133,7 +125,7 @@ void Section::endSection( std::ostream & os ) const footerTitle, titleLength, borderCharacters ); - string bottomPart = GEOS_FMT( "{}{}", titleRowFormatted, m_lineSection ); - outputSection( os, topPart, bottomPart ); + string bottomPart = GEOS_FMT( "{}{}", titleRowFormatted, horizontalBorder ); + oss << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } } diff --git a/src/coreComponents/fileIO/section/Section.hpp b/src/coreComponents/fileIO/section/Section.hpp index 0359ac8171f..6accafa338b 100644 --- a/src/coreComponents/fileIO/section/Section.hpp +++ b/src/coreComponents/fileIO/section/Section.hpp @@ -25,7 +25,6 @@ namespace geos { -// TODO ? SectionData ? class Section { public: @@ -86,11 +85,6 @@ class Section private: - // /** - // * @brief Compute the max string size (m_sectionWidth) between title and the description(s) - // */ - // void computeWidth(); - /** * @brief Build a description from the name and description values * @param descriptionName The decription name @@ -100,13 +94,23 @@ class Section string_view descriptionName, std::vector< string > const & decriptionsValues ); - string constructDescriptionsWithContainer( std::vector< string > const & descriptions ) const; - - void constructDescription( std::ostringstream & oss, - string const & description, - integer const remainingLength ) const; + /** + * @brief Constructs a string from a vector of descriptions. + * @param descriptions A vector of string containing the descriptions + * @return A string containing all the formatted descriptions. + */ + string constructDescriptionsWithVector( std::vector< string > const & descriptions ) const; - void outputSection( std::ostream & oss, string_view topPart, string_view bottomPart ) const; + /** + * @brief Formats a description and adds it to an output stream + * @param oss The output stream + * @param description The description to be formatted + * @param remainingLength The remaining length available for the description + * after accounting for borders and margins + */ + void formatDescription( std::ostringstream & oss, + string const & description, + integer const remainingLength ) const; /// Vector containing all descriptions std::vector< string > m_descriptions; @@ -125,8 +129,8 @@ class Section /// numbers of character used as border static constexpr integer m_nbSpecialChar = 2; - /// - string m_lineSection; + /// String containing horizontal border + string horizontalBorder; /// Start title footer string static string_view constexpr m_footerTitle = "End : "; From cb6d2140f6e47a3840f076fd35d451ffee5715eb Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 8 Oct 2024 16:59:58 +0200 Subject: [PATCH 183/206] doxygen and type --- src/coreComponents/fileIO/section/Section.cpp | 6 +++--- src/coreComponents/fileIO/section/Section.hpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/coreComponents/fileIO/section/Section.cpp b/src/coreComponents/fileIO/section/Section.cpp index 4648dae76e1..494c14d6967 100644 --- a/src/coreComponents/fileIO/section/Section.cpp +++ b/src/coreComponents/fileIO/section/Section.cpp @@ -82,7 +82,7 @@ void Section::formatDescription( std::ostringstream & oss, oss << borderCharacters << '\n'; } -void Section::beginSection( std::ostream & oss ) +void Section::beginSection( std::ostream & os ) { m_sectionWidth = std::max( m_sectionWidth, m_rowMinWidth ); horizontalBorder = GEOS_FMT( "{:#>{}}\n", "", m_sectionWidth ); @@ -104,7 +104,7 @@ void Section::beginSection( std::ostream & oss ) string topPart = GEOS_FMT( "{}{}{}", horizontalBorder, titleRowFormatted, horizontalBorder ); string bottomPart = descriptions; - oss << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); + os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } void Section::endSection( std::ostream & os ) const @@ -126,6 +126,6 @@ void Section::endSection( std::ostream & os ) const titleLength, borderCharacters ); string bottomPart = GEOS_FMT( "{}{}", titleRowFormatted, horizontalBorder ); - oss << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); + os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } } diff --git a/src/coreComponents/fileIO/section/Section.hpp b/src/coreComponents/fileIO/section/Section.hpp index 6accafa338b..eec2bfef6f6 100644 --- a/src/coreComponents/fileIO/section/Section.hpp +++ b/src/coreComponents/fileIO/section/Section.hpp @@ -38,7 +38,7 @@ class Section /** * @brief Add a description to the section by concatening a description name and descriptions values. * @param descriptionName The description name - * @param args Descriptions values to be aligned. + * @param args Descriptions values to be concatened. * Descriptions values can be be any types and will be aligned */ template< typename ... Args > @@ -53,7 +53,7 @@ class Section /** * @brief Add a description to the end of the section by concatening a description name and descriptions values. * @param descriptionName The description name - * @param args Descriptions values to be aligned. + * @param args Descriptions values to be concatened. * Descriptions values can be be any types and will be aligned */ template< typename ... Args > @@ -99,7 +99,7 @@ class Section * @param descriptions A vector of string containing the descriptions * @return A string containing all the formatted descriptions. */ - string constructDescriptionsWithVector( std::vector< string > const & descriptions ) const; + string constructDescriptionsFromVector( std::vector< string > const & descriptions ) const; /** * @brief Formats a description and adds it to an output stream From 7a9b2b9d09a7b848000104624cca839a95560c98 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 10 Oct 2024 11:40:03 +0200 Subject: [PATCH 184/206] firstPass renaming --- .../common/format/table/TableFormatter.cpp | 8 +++---- .../common/format/table/TableFormatter.hpp | 2 +- .../common/format/table/TableLayout.hpp | 2 +- src/coreComponents/events/EventManager.cpp | 4 ++-- src/coreComponents/events/EventManager.hpp | 4 ++-- src/coreComponents/fileIO/CMakeLists.txt | 4 ++-- .../section/{Section.cpp => LogPart.cpp} | 22 +++++++++---------- .../section/{Section.hpp => LogPart.hpp} | 12 +++++----- .../fileIO/section/unitTests/testSection.cpp | 12 +++++----- .../mainInterface/ProblemManager.cpp | 4 ++-- 10 files changed, 37 insertions(+), 37 deletions(-) rename src/coreComponents/fileIO/section/{Section.cpp => LogPart.cpp} (88%) rename src/coreComponents/fileIO/section/{Section.hpp => LogPart.hpp} (95%) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 0625ffac6d6..f1cc49e979c 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -170,7 +170,7 @@ string TableTextFormatter::toString( TableData const & tableData ) const fillTableColumnsFromRows( columns, tableDataRows ); outputLayout( tableOutput, columns, msgTableError, sectionSeparatingLine ); - outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbValuesRows, TableLayout::Section::values ); + outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbValuesRows, TableLayout::LogPart::values ); tableOutput << '\n'; return tableOutput.str(); @@ -197,7 +197,7 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, 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, TableLayout::LogPart::header ); } void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Column > & columns, @@ -368,7 +368,7 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c string_view sectionSeparatingLine, std::ostringstream & tableOutput, integer const nbRows, - TableLayout::Section const section ) const + TableLayout::LogPart const section ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); @@ -380,7 +380,7 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { TableLayout::Column const currentColumn = columns[idxColumn]; - auto const & columnContent = section == TableLayout::Section::header ? + auto const & columnContent = section == TableLayout::LogPart::header ? columns[idxColumn].m_parameter.splitColumnNameLines : columns[idxColumn].m_columnValues; string cell = columnContent.at( idxRow ); diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 165533445b6..1774d95e4b9 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -244,7 +244,7 @@ class TableTextFormatter : public TableFormatter string_view sectionSeparatingLine, std::ostringstream & rows, integer const nbRows, - TableLayout::Section const section ) const; + TableLayout::LogPart const section ) const; }; /** diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index 4f24fa5559c..dcf860db91c 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -48,7 +48,7 @@ class TableLayout /** * @brief Enumeration for table sections. */ - enum Section { header, values }; + enum LogPart { header, values }; /** * @brief Structure to set up each colum parameters. diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index bb3e5095b83..9fd625d843a 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -170,7 +170,7 @@ bool EventManager::run( DomainPartition & domain ) m_dt = dt_global; #endif } - Section section( "TIMESTEP START" ); + LogPart section( "TIMESTEP START" ); outputTime( section ); section.beginSection(); @@ -227,7 +227,7 @@ bool EventManager::run( DomainPartition & domain ) return false; } -void EventManager::outputTime( Section & section ) const +void EventManager::outputTime( LogPart & section ) const { const bool isTimeLimited = m_maxTime < std::numeric_limits< real64 >::max(); const bool isCycleLimited = m_maxCycle < std::numeric_limits< integer >::max(); diff --git a/src/coreComponents/events/EventManager.hpp b/src/coreComponents/events/EventManager.hpp index 14b2bb85ece..6062a28a732 100644 --- a/src/coreComponents/events/EventManager.hpp +++ b/src/coreComponents/events/EventManager.hpp @@ -19,7 +19,7 @@ #include "dataRepository/Group.hpp" #include "EventBase.hpp" -#include "fileIO/section/Section.hpp" +#include "fileIO/section/LogPart.hpp" namespace geos { @@ -135,7 +135,7 @@ class EventManager : public dataRepository::Group * @brief ouput time information to the log * */ - void outputTime( Section & section ) const; + void outputTime( LogPart & section ) const; /// Min time for a simulation real64 m_minTime; diff --git a/src/coreComponents/fileIO/CMakeLists.txt b/src/coreComponents/fileIO/CMakeLists.txt index 4fb2641bcfc..813c41af62a 100644 --- a/src/coreComponents/fileIO/CMakeLists.txt +++ b/src/coreComponents/fileIO/CMakeLists.txt @@ -6,7 +6,7 @@ set( fileIO_headers Outputs/OutputUtilities.hpp Outputs/PythonOutput.hpp Outputs/RestartOutput.hpp - section/Section.hpp + section/LogPart.hpp Outputs/TimeHistoryOutput.hpp timeHistory/HDFFile.hpp timeHistory/HistoryCollectionBase.hpp @@ -23,7 +23,7 @@ set( fileIO_sources Outputs/OutputUtilities.cpp Outputs/PythonOutput.cpp Outputs/RestartOutput.cpp - section/Section.cpp + section/LogPart.cpp Outputs/TimeHistoryOutput.cpp timeHistory/HDFFile.cpp timeHistory/HistoryCollectionBase.cpp diff --git a/src/coreComponents/fileIO/section/Section.cpp b/src/coreComponents/fileIO/section/LogPart.cpp similarity index 88% rename from src/coreComponents/fileIO/section/Section.cpp rename to src/coreComponents/fileIO/section/LogPart.cpp index 494c14d6967..53ae464c312 100644 --- a/src/coreComponents/fileIO/section/Section.cpp +++ b/src/coreComponents/fileIO/section/LogPart.cpp @@ -13,36 +13,36 @@ */ /** - * @file Section.cpp + * @file LogPart.cpp */ -#include "Section.hpp" +#include "LogPart.hpp" #include namespace geos { -Section::Section( string_view sectionTitle ): +LogPart::LogPart( string_view sectionTitle ): m_sectionTitle( string( sectionTitle ) ), m_sectionWidth( sectionTitle.length() ) {} -void Section::addDescription( string_view description ) +void LogPart::addDescription( string_view description ) { m_descriptions.push_back( string( description ) ); } -void Section::addEndDescription( string_view description ) +void LogPart::addEndDescription( string_view description ) { m_endLogMessages.push_back( string( description ) ); } -void Section::setMinWidth( integer const & minWidth ) +void LogPart::setMinWidth( integer const & minWidth ) { m_rowMinWidth = minWidth; } -void Section::formatAndInsertDescriptions( std::vector< string > & descriptionContainer, +void LogPart::formatAndInsertDescriptions( std::vector< string > & descriptionContainer, string_view descriptionName, std::vector< string > const & descriptionValues ) { @@ -61,7 +61,7 @@ void Section::formatAndInsertDescriptions( std::vector< string > & descriptionCo } } -string Section::constructDescriptionsFromVector( std::vector< string > const & descriptions ) const +string LogPart::constructDescriptionsFromVector( std::vector< string > const & descriptions ) const { std::ostringstream oss; for( const auto & description : descriptions ) @@ -72,7 +72,7 @@ string Section::constructDescriptionsFromVector( std::vector< string > const & d return oss.str(); } -void Section::formatDescription( std::ostringstream & oss, +void LogPart::formatDescription( std::ostringstream & oss, string const & description, integer const remainingLength ) const { @@ -82,7 +82,7 @@ void Section::formatDescription( std::ostringstream & oss, oss << borderCharacters << '\n'; } -void Section::beginSection( std::ostream & os ) +void LogPart::beginSection( std::ostream & os ) { m_sectionWidth = std::max( m_sectionWidth, m_rowMinWidth ); horizontalBorder = GEOS_FMT( "{:#>{}}\n", "", m_sectionWidth ); @@ -107,7 +107,7 @@ void Section::beginSection( std::ostream & os ) os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } -void Section::endSection( std::ostream & os ) const +void LogPart::endSection( std::ostream & os ) const { string const footerTitle = GEOS_FMT( "{}{}", m_footerTitle, m_sectionTitle ); string const lineSection = GEOS_FMT( "{:#^{}}\n", "", m_sectionWidth ); diff --git a/src/coreComponents/fileIO/section/Section.hpp b/src/coreComponents/fileIO/section/LogPart.hpp similarity index 95% rename from src/coreComponents/fileIO/section/Section.hpp rename to src/coreComponents/fileIO/section/LogPart.hpp index eec2bfef6f6..2b175ab3073 100644 --- a/src/coreComponents/fileIO/section/Section.hpp +++ b/src/coreComponents/fileIO/section/LogPart.hpp @@ -13,7 +13,7 @@ */ /** - * @file Section.hpp + * @file LogPart.hpp */ #ifndef GEOS_COMMON_SECTION_HPP @@ -25,15 +25,15 @@ namespace geos { -class Section +class LogPart { public: /** - * @brief Construct a new Section + * @brief Construct a new LogPart * @param m_sectionTitle The section title */ - Section( string_view m_sectionTitle ); + LogPart( string_view m_sectionTitle ); /** * @brief Add a description to the section by concatening a description name and descriptions values. @@ -138,7 +138,7 @@ class Section }; template< typename ... Args > -void Section::addDescription( string_view descriptionName, Args const &... args ) +void LogPart::addDescription( string_view descriptionName, Args const &... args ) { std::vector< string > descriptionsValues; ( [&] { @@ -151,7 +151,7 @@ void Section::addDescription( string_view descriptionName, Args const &... args } template< typename ... Args > -void Section::addEndDescription( string_view descriptionName, Args const &... args ) +void LogPart::addEndDescription( string_view descriptionName, Args const &... args ) { std::vector< string > descriptionsValues; ( [&] { diff --git a/src/coreComponents/fileIO/section/unitTests/testSection.cpp b/src/coreComponents/fileIO/section/unitTests/testSection.cpp index 38392c7faa1..2adb498f13d 100644 --- a/src/coreComponents/fileIO/section/unitTests/testSection.cpp +++ b/src/coreComponents/fileIO/section/unitTests/testSection.cpp @@ -13,7 +13,7 @@ */ #include "common/DataTypes.hpp" -#include "fileIO/section/Section.hpp" +#include "fileIO/section/LogPart.hpp" #include using namespace geos; @@ -21,7 +21,7 @@ using namespace geos; TEST( testSection, sectionWithTitle ) { std::ostringstream oss; - Section section( "section name" ); + LogPart section( "section name" ); section.beginSection( oss ); EXPECT_EQ( oss.str(), "\n######################################################################\n" @@ -42,7 +42,7 @@ TEST( testSection, sectionWithTitle ) TEST( testSection, sectionWithTitleAndOneDescription ) { std::ostringstream oss; - Section section( "section name" ); + LogPart section( "section name" ); section.addDescription( "description name" ); section.beginSection( oss ); EXPECT_EQ( oss.str(), @@ -57,7 +57,7 @@ TEST( testSection, sectionWithTitleAndOneDescription ) TEST( testSection, sectionWithSetWidth ) { std::ostringstream oss; - Section section( "section name" ); + LogPart section( "section name" ); section.addDescription( "description name 1" ); section.addDescription( "description name 2" ); section.setMinWidth( 100 ); @@ -83,7 +83,7 @@ TEST( testSection, sectionWithSetWidth ) TEST( testSection, sectionMultipleDescriptions ) { std::ostringstream oss; - Section section( "TIMESTEP START" ); + LogPart section( "TIMESTEP START" ); section.addDescription( "Time", "00h08m20s out of 2d, 21h26m40s (0% completed)", "500 s / 250000 s" ); section.addDescription( "Delta Time", "00h16m40s (1000 s)" ); section.addDescription( "- Cycle: 1" ); @@ -112,7 +112,7 @@ TEST( testSection, sectionMultipleDescriptions ) TEST( testSection, sectionEndDescription ) { std::ostringstream oss; - Section section( "TIMESTEP START" ); + LogPart section( "TIMESTEP START" ); section.addDescription( "description" ); section.addEndDescription( "test end description" ); section.setMinWidth( 70 ); diff --git a/src/coreComponents/mainInterface/ProblemManager.cpp b/src/coreComponents/mainInterface/ProblemManager.cpp index e11e52504a6..1878af94ced 100644 --- a/src/coreComponents/mainInterface/ProblemManager.cpp +++ b/src/coreComponents/mainInterface/ProblemManager.cpp @@ -32,7 +32,7 @@ #include "events/tasks/TasksManager.hpp" #include "events/EventManager.hpp" #include "finiteElement/FiniteElementDiscretization.hpp" -#include "fileIO/section/Section.hpp" +#include "fileIO/section/LogPart.hpp" #include "finiteElement/FiniteElementDiscretizationManager.hpp" #include "finiteVolume/FluxApproximationBase.hpp" #include "finiteVolume/HybridMimeticDiscretization.hpp" @@ -169,7 +169,7 @@ void ProblemManager::problemSetup() postInputInitializationRecursive(); - Section section( "Mesh generation" ); + LogPart section( "Mesh generation" ); section.beginSection(); generateMesh(); section.endSection(); From e34f174445cd2ebe2574bab9a4a5be72e1a1f3f6 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 17 Oct 2024 13:20:00 +0200 Subject: [PATCH 185/206] 2nd pass of renaming --- src/coreComponents/events/EventManager.cpp | 18 +++---- src/coreComponents/events/EventManager.hpp | 2 +- src/coreComponents/fileIO/CMakeLists.txt | 6 +-- .../fileIO/{section => logPart}/LogPart.cpp | 4 +- .../fileIO/{section => logPart}/LogPart.hpp | 4 +- .../unitTests/CMakeLists.txt | 2 +- .../unitTests/testLogPart.cpp} | 52 +++++++++---------- .../mainInterface/ProblemManager.cpp | 8 +-- 8 files changed, 48 insertions(+), 48 deletions(-) rename src/coreComponents/fileIO/{section => logPart}/LogPart.cpp (97%) rename src/coreComponents/fileIO/{section => logPart}/LogPart.hpp (97%) rename src/coreComponents/fileIO/{section => logPart}/unitTests/CMakeLists.txt (95%) rename src/coreComponents/fileIO/{section/unitTests/testSection.cpp => logPart/unitTests/testLogPart.cpp} (82%) diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index 9fd625d843a..4a879633ef3 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -170,9 +170,9 @@ bool EventManager::run( DomainPartition & domain ) m_dt = dt_global; #endif } - LogPart section( "TIMESTEP START" ); - outputTime( section ); - section.beginSection(); + LogPart logPart( "TIMESTEP START" ); + outputTime( logPart ); + logPart.begin(); // Execute for(; m_currentSubEventnumSubGroups(); ++m_currentSubEvent ) @@ -209,7 +209,7 @@ bool EventManager::run( DomainPartition & domain ) } } - section.endSection(); + logPart.end(); // Increment time/cycle, reset the subevent counter m_time += m_dt; ++m_cycle; @@ -227,7 +227,7 @@ bool EventManager::run( DomainPartition & domain ) return false; } -void EventManager::outputTime( LogPart & section ) const +void EventManager::outputTime( LogPart & logPart ) const { const bool isTimeLimited = m_maxTime < std::numeric_limits< real64 >::max(); const bool isCycleLimited = m_maxCycle < std::numeric_limits< integer >::max(); @@ -254,10 +254,10 @@ void EventManager::outputTime( LogPart & section ) const string const timeInfosUnfolded = timeInfo.toUnfoldedString() + timeCompletionUnfolded; string const timeCompletionSeconds = timeInfo.toSecondsString() + timeCompletionSecond; - section.addDescription( "Time", timeInfosUnfolded, timeCompletionSeconds ); - section.addDescription( "Delta Time", units::TimeFormatInfo::fromSeconds( m_dt ).toString() ); - section.addDescription( "Cycle", m_cycle, cycleLimited ); - section.setMinWidth( 70 ); + logPart.addDescription( "Time", timeInfosUnfolded, timeCompletionSeconds ); + logPart.addDescription( "Delta Time", units::TimeFormatInfo::fromSeconds( m_dt ).toString() ); + logPart.addDescription( "Cycle", m_cycle, cycleLimited ); + logPart.setMinWidth( 70 ); // We are keeping the old outputs to keep compatibility with current log reading scripts. if( m_timeOutputFormat==TimeOutputFormat::full ) diff --git a/src/coreComponents/events/EventManager.hpp b/src/coreComponents/events/EventManager.hpp index 6062a28a732..5540039e0b7 100644 --- a/src/coreComponents/events/EventManager.hpp +++ b/src/coreComponents/events/EventManager.hpp @@ -19,7 +19,7 @@ #include "dataRepository/Group.hpp" #include "EventBase.hpp" -#include "fileIO/section/LogPart.hpp" +#include "fileIO/logPart/LogPart.hpp" namespace geos { diff --git a/src/coreComponents/fileIO/CMakeLists.txt b/src/coreComponents/fileIO/CMakeLists.txt index 813c41af62a..27a64b2a1c3 100644 --- a/src/coreComponents/fileIO/CMakeLists.txt +++ b/src/coreComponents/fileIO/CMakeLists.txt @@ -6,7 +6,7 @@ set( fileIO_headers Outputs/OutputUtilities.hpp Outputs/PythonOutput.hpp Outputs/RestartOutput.hpp - section/LogPart.hpp + logPart/LogPart.hpp Outputs/TimeHistoryOutput.hpp timeHistory/HDFFile.hpp timeHistory/HistoryCollectionBase.hpp @@ -23,7 +23,7 @@ set( fileIO_sources Outputs/OutputUtilities.cpp Outputs/PythonOutput.cpp Outputs/RestartOutput.cpp - section/LogPart.cpp + logPart/LogPart.cpp Outputs/TimeHistoryOutput.cpp timeHistory/HDFFile.cpp timeHistory/HistoryCollectionBase.cpp @@ -98,7 +98,7 @@ target_include_directories( fileIO PUBLIC ${CMAKE_SOURCE_DIR}/coreComponents ) install( TARGETS fileIO LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib ) if( GEOS_ENABLE_TESTS ) - add_subdirectory( section/unitTests ) + add_subdirectory( logPart/unitTests ) endif( ) diff --git a/src/coreComponents/fileIO/section/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp similarity index 97% rename from src/coreComponents/fileIO/section/LogPart.cpp rename to src/coreComponents/fileIO/logPart/LogPart.cpp index 53ae464c312..21e18abbd14 100644 --- a/src/coreComponents/fileIO/section/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -82,7 +82,7 @@ void LogPart::formatDescription( std::ostringstream & oss, oss << borderCharacters << '\n'; } -void LogPart::beginSection( std::ostream & os ) +void LogPart::begin( std::ostream & os ) { m_sectionWidth = std::max( m_sectionWidth, m_rowMinWidth ); horizontalBorder = GEOS_FMT( "{:#>{}}\n", "", m_sectionWidth ); @@ -107,7 +107,7 @@ void LogPart::beginSection( std::ostream & os ) os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } -void LogPart::endSection( std::ostream & os ) const +void LogPart::end( std::ostream & os ) const { string const footerTitle = GEOS_FMT( "{}{}", m_footerTitle, m_sectionTitle ); string const lineSection = GEOS_FMT( "{:#^{}}\n", "", m_sectionWidth ); diff --git a/src/coreComponents/fileIO/section/LogPart.hpp b/src/coreComponents/fileIO/logPart/LogPart.hpp similarity index 97% rename from src/coreComponents/fileIO/section/LogPart.hpp rename to src/coreComponents/fileIO/logPart/LogPart.hpp index 2b175ab3073..6dd4c99eff6 100644 --- a/src/coreComponents/fileIO/section/LogPart.hpp +++ b/src/coreComponents/fileIO/logPart/LogPart.hpp @@ -75,13 +75,13 @@ class LogPart * @brief Draw the first part of the section. It include the title and optionnaly, the description(s); * @param os An output stream (by default, std::cout) */ - void beginSection( std::ostream & os = std::cout ); + void begin( std::ostream & os = std::cout ); /** * @brief Draw the last part of the section. It include the title * @param oss An output stream (by default, std::cout) */ - void endSection( std::ostream & oss = std::cout ) const; + void end( std::ostream & oss = std::cout ) const; private: diff --git a/src/coreComponents/fileIO/section/unitTests/CMakeLists.txt b/src/coreComponents/fileIO/logPart/unitTests/CMakeLists.txt similarity index 95% rename from src/coreComponents/fileIO/section/unitTests/CMakeLists.txt rename to src/coreComponents/fileIO/logPart/unitTests/CMakeLists.txt index eadc140567d..8297f46d077 100644 --- a/src/coreComponents/fileIO/section/unitTests/CMakeLists.txt +++ b/src/coreComponents/fileIO/logPart/unitTests/CMakeLists.txt @@ -1,6 +1,6 @@ # Specify list of tests set( gtest_geosx_tests - testSection.cpp ) + testLogPart.cpp ) set( dependencyList gtest fileIO ${parallelDeps} ) diff --git a/src/coreComponents/fileIO/section/unitTests/testSection.cpp b/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp similarity index 82% rename from src/coreComponents/fileIO/section/unitTests/testSection.cpp rename to src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp index 2adb498f13d..a3525d1c9b1 100644 --- a/src/coreComponents/fileIO/section/unitTests/testSection.cpp +++ b/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp @@ -13,7 +13,7 @@ */ #include "common/DataTypes.hpp" -#include "fileIO/section/LogPart.hpp" +#include "fileIO/logPart/LogPart.hpp" #include using namespace geos; @@ -21,8 +21,8 @@ using namespace geos; TEST( testSection, sectionWithTitle ) { std::ostringstream oss; - LogPart section( "section name" ); - section.beginSection( oss ); + LogPart logPart( "section name" ); + logPart.begin( oss ); EXPECT_EQ( oss.str(), "\n######################################################################\n" "## section name ##\n" @@ -31,7 +31,7 @@ TEST( testSection, sectionWithTitle ) oss.clear(); oss.str( "" ); - section.endSection( oss ); + logPart.end( oss ); EXPECT_EQ( oss.str(), "\n## End : section name ##\n" "######################################################################\n\n" @@ -42,9 +42,9 @@ TEST( testSection, sectionWithTitle ) TEST( testSection, sectionWithTitleAndOneDescription ) { std::ostringstream oss; - LogPart section( "section name" ); - section.addDescription( "description name" ); - section.beginSection( oss ); + LogPart logPart( "section name" ); + logPart.addDescription( "description name" ); + logPart.begin( oss ); EXPECT_EQ( oss.str(), "\n######################################################################\n" "## section name ##\n" @@ -57,11 +57,11 @@ TEST( testSection, sectionWithTitleAndOneDescription ) TEST( testSection, sectionWithSetWidth ) { std::ostringstream oss; - LogPart section( "section name" ); - section.addDescription( "description name 1" ); - section.addDescription( "description name 2" ); - section.setMinWidth( 100 ); - section.beginSection( oss ); + LogPart logPart( "section name" ); + logPart.addDescription( "description name 1" ); + logPart.addDescription( "description name 2" ); + logPart.setMinWidth( 100 ); + logPart.begin( oss ); EXPECT_EQ( oss.str(), "\n####################################################################################################\n" "## section name ##\n" @@ -72,7 +72,7 @@ TEST( testSection, sectionWithSetWidth ) oss.clear(); oss.str( "" ); - section.endSection( oss ); + logPart.end( oss ); EXPECT_EQ( oss.str(), "\n## End : section name ##\n" "####################################################################################################\n\n" @@ -83,12 +83,12 @@ TEST( testSection, sectionWithSetWidth ) TEST( testSection, sectionMultipleDescriptions ) { std::ostringstream oss; - LogPart section( "TIMESTEP START" ); - section.addDescription( "Time", "00h08m20s out of 2d, 21h26m40s (0% completed)", "500 s / 250000 s" ); - section.addDescription( "Delta Time", "00h16m40s (1000 s)" ); - section.addDescription( "- Cycle: 1" ); - section.setMinWidth( 70 ); - section.beginSection( oss ); + LogPart logPart( "TIMESTEP START" ); + logPart.addDescription( "Time", "00h08m20s out of 2d, 21h26m40s (0% completed)", "500 s / 250000 s" ); + logPart.addDescription( "Delta Time", "00h16m40s (1000 s)" ); + logPart.addDescription( "- Cycle: 1" ); + logPart.setMinWidth( 70 ); + logPart.begin( oss ); EXPECT_EQ ( oss.str(), "\n######################################################################\n" "## TIMESTEP START ##\n" @@ -101,7 +101,7 @@ TEST( testSection, sectionMultipleDescriptions ) oss.clear(); oss.str( "" ); - section.endSection( oss ); + logPart.end( oss ); EXPECT_EQ( oss.str(), "\n## End : TIMESTEP START ##\n" "######################################################################\n\n" @@ -112,15 +112,15 @@ TEST( testSection, sectionMultipleDescriptions ) TEST( testSection, sectionEndDescription ) { std::ostringstream oss; - LogPart section( "TIMESTEP START" ); - section.addDescription( "description" ); - section.addEndDescription( "test end description" ); - section.setMinWidth( 70 ); - section.beginSection( oss ); + LogPart logPart( "TIMESTEP START" ); + logPart.addDescription( "description" ); + logPart.addEndDescription( "test end description" ); + logPart.setMinWidth( 70 ); + logPart.begin( oss ); oss.clear(); oss.str( "" ); - section.endSection( oss ); + logPart.end( oss ); std::cout << " end section \n" << oss.str() << std::endl; diff --git a/src/coreComponents/mainInterface/ProblemManager.cpp b/src/coreComponents/mainInterface/ProblemManager.cpp index 1878af94ced..f0f64d9b71e 100644 --- a/src/coreComponents/mainInterface/ProblemManager.cpp +++ b/src/coreComponents/mainInterface/ProblemManager.cpp @@ -32,7 +32,7 @@ #include "events/tasks/TasksManager.hpp" #include "events/EventManager.hpp" #include "finiteElement/FiniteElementDiscretization.hpp" -#include "fileIO/section/LogPart.hpp" +#include "fileIO/logPart/LogPart.hpp" #include "finiteElement/FiniteElementDiscretizationManager.hpp" #include "finiteVolume/FluxApproximationBase.hpp" #include "finiteVolume/HybridMimeticDiscretization.hpp" @@ -169,10 +169,10 @@ void ProblemManager::problemSetup() postInputInitializationRecursive(); - LogPart section( "Mesh generation" ); - section.beginSection(); + LogPart logPart( "Mesh generation" ); + logPart.begin(); generateMesh(); - section.endSection(); + logPart.end(); // initialize_postMeshGeneration(); applyNumericalMethods(); From aada6fc536bce0fed69125cf6febc15a6d7ff95e Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 17 Oct 2024 14:50:04 +0200 Subject: [PATCH 186/206] renaming, const value, ... --- src/coreComponents/fileIO/logPart/LogPart.cpp | 39 +++++++++---------- src/coreComponents/fileIO/logPart/LogPart.hpp | 16 ++++++-- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/coreComponents/fileIO/logPart/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp index 21e18abbd14..ad9a956217e 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -46,9 +46,9 @@ void LogPart::formatAndInsertDescriptions( std::vector< string > & descriptionCo string_view descriptionName, std::vector< string > const & descriptionValues ) { - string descriptionNameFormatted = GEOS_FMT( "- {}: ", string( descriptionName )); + string const descriptionNameFormatted = GEOS_FMT( "- {}: ", string( descriptionName )); string const descriptionFormatted = GEOS_FMT( "{}{}", descriptionNameFormatted, descriptionValues[0] ); - integer spacesFromBorder = m_marginBorder * 2 + m_nbSpecialChar * 2; + integer const spacesFromBorder = m_marginBorder * 2 + m_nbBorderChar * 2; integer const completeDescriptionLength = descriptionFormatted.length() + spacesFromBorder; descriptionContainer.push_back( descriptionFormatted ); @@ -66,17 +66,17 @@ string LogPart::constructDescriptionsFromVector( std::vector< string > const & d std::ostringstream oss; for( const auto & description : descriptions ) { - integer const rowDescriptionLength = m_sectionWidth - m_nbSpecialChar * 2 - m_marginBorder; + integer const rowDescriptionLength = m_sectionWidth - m_nbBorderChar * 2 - m_marginBorder; formatDescription( oss, description, rowDescriptionLength ); } return oss.str(); } void LogPart::formatDescription( std::ostringstream & oss, - string const & description, + string_view description, integer const remainingLength ) const { - string borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); + string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbBorderChar ); oss << borderCharacters; oss << GEOS_FMT( "{:<{}}{:<{}}", " ", m_marginBorder, description, remainingLength ); oss << borderCharacters << '\n'; @@ -85,47 +85,44 @@ void LogPart::formatDescription( std::ostringstream & oss, void LogPart::begin( std::ostream & os ) { m_sectionWidth = std::max( m_sectionWidth, m_rowMinWidth ); - horizontalBorder = GEOS_FMT( "{:#>{}}\n", "", m_sectionWidth ); - string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); + integer const titleRowLength = m_sectionWidth - m_nbBorderChar * 2; - integer const titleLength = m_sectionWidth - m_nbSpecialChar * 2; string descriptions; - if( !m_descriptions.empty()) { descriptions = constructDescriptionsFromVector( m_descriptions ); } - + string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbBorderChar ); string titleRowFormatted = GEOS_FMT( "{}{:^{}}{}\n", borderCharacters, m_sectionTitle, - titleLength, + titleRowLength, borderCharacters ); - string topPart = GEOS_FMT( "{}{}{}", horizontalBorder, titleRowFormatted, horizontalBorder ); - string bottomPart = descriptions; + m_horizontalBorder = GEOS_FMT( "{:#>{}}\n", "", m_sectionWidth ); + string const topPart = GEOS_FMT( "{}{}{}", m_horizontalBorder, titleRowFormatted, m_horizontalBorder ); + string const bottomPart = descriptions; os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } void LogPart::end( std::ostream & os ) const { - string const footerTitle = GEOS_FMT( "{}{}", m_footerTitle, m_sectionTitle ); - string const lineSection = GEOS_FMT( "{:#^{}}\n", "", m_sectionWidth ); - string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbSpecialChar ); - integer const titleLength = m_sectionWidth - m_nbSpecialChar * 2; string topPart; - if( !m_endLogMessages.empty() ) { - topPart = GEOS_FMT( "{}{}", constructDescriptionsFromVector( m_endLogMessages ), horizontalBorder ); + topPart = GEOS_FMT( "{}{}", constructDescriptionsFromVector( m_endLogMessages ), m_horizontalBorder ); } + string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbBorderChar ); + string const footerTitle = GEOS_FMT( "{}{}", m_footerTitle, m_sectionTitle ); + integer const titleRowLength = m_sectionWidth - m_nbBorderChar * 2; string titleRowFormatted = GEOS_FMT( "{}{:^{}}{}\n", borderCharacters, footerTitle, - titleLength, + titleRowLength, borderCharacters ); - string bottomPart = GEOS_FMT( "{}{}", titleRowFormatted, horizontalBorder ); + string const bottomPart = GEOS_FMT( "{}{}", titleRowFormatted, m_horizontalBorder ); os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } + } diff --git a/src/coreComponents/fileIO/logPart/LogPart.hpp b/src/coreComponents/fileIO/logPart/LogPart.hpp index 6dd4c99eff6..847d60ec969 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.hpp +++ b/src/coreComponents/fileIO/logPart/LogPart.hpp @@ -109,9 +109,19 @@ class LogPart * after accounting for borders and margins */ void formatDescription( std::ostringstream & oss, - string const & description, + string_view description, integer const remainingLength ) const; +/** + * @brief Formats a log section with a title and optional descriptions. + * @param title The title of the log section to be formatted. + * @param titleRowLength The length of the title row + * @param descriptions Optional descriptions to include below the title; + * if empty, only the title will be displayed. + * @return A formatted string containing the top and bottom parts of the log section + */ + string formatLogSection( string_view title, integer titleRowLength, string_view descriptions ) const; + /// Vector containing all descriptions std::vector< string > m_descriptions; /// title of section @@ -127,10 +137,10 @@ class LogPart /// description border margin static constexpr integer m_marginBorder = 2; /// numbers of character used as border - static constexpr integer m_nbSpecialChar = 2; + static constexpr integer m_nbBorderChar = 2; /// String containing horizontal border - string horizontalBorder; + string m_horizontalBorder; /// Start title footer string static string_view constexpr m_footerTitle = "End : "; From a6acda4a6c718c92e365cfe595c1254c45019c50 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 17 Oct 2024 14:55:52 +0200 Subject: [PATCH 187/206] test fix + doxygen --- src/coreComponents/fileIO/logPart/LogPart.cpp | 2 +- src/coreComponents/fileIO/logPart/LogPart.hpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/coreComponents/fileIO/logPart/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp index ad9a956217e..cfd5f78fb8d 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -73,7 +73,7 @@ string LogPart::constructDescriptionsFromVector( std::vector< string > const & d } void LogPart::formatDescription( std::ostringstream & oss, - string_view description, + string const & description, integer const remainingLength ) const { string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbBorderChar ); diff --git a/src/coreComponents/fileIO/logPart/LogPart.hpp b/src/coreComponents/fileIO/logPart/LogPart.hpp index 847d60ec969..cbf6b123a58 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.hpp +++ b/src/coreComponents/fileIO/logPart/LogPart.hpp @@ -25,7 +25,10 @@ namespace geos { -class LogPart +/** + * @brief Class for displaying different steps of simulation + */ +class LogPart { public: @@ -109,7 +112,7 @@ class LogPart * after accounting for borders and margins */ void formatDescription( std::ostringstream & oss, - string_view description, + string const & description, integer const remainingLength ) const; /** From a60e76454c0a1379b41a366564db8b84f0116467 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 17 Oct 2024 15:03:47 +0200 Subject: [PATCH 188/206] uncrustify --- src/coreComponents/fileIO/logPart/LogPart.hpp | 4 +- src/coreComponents/schema/schema.xsd | 70 +++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/coreComponents/fileIO/logPart/LogPart.hpp b/src/coreComponents/fileIO/logPart/LogPart.hpp index cbf6b123a58..8aa2fe23d41 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.hpp +++ b/src/coreComponents/fileIO/logPart/LogPart.hpp @@ -26,9 +26,9 @@ namespace geos { /** - * @brief Class for displaying different steps of simulation + * @brief Class for displaying different steps of simulation */ -class LogPart +class LogPart { public: diff --git a/src/coreComponents/schema/schema.xsd b/src/coreComponents/schema/schema.xsd index 25a739a9662..0f6e096a789 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 27761a45729fd9b6ebf0ae02cf5b8dc39ceabbb1 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 23 Oct 2024 10:05:41 +0200 Subject: [PATCH 189/206] 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 215191d89f5..d14c56725c8 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 2ec377ef8e8bf547b4cb8429effc650e03e00172 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 23 Oct 2024 11:19:08 +0200 Subject: [PATCH 190/206] refacto --- src/coreComponents/fileIO/logPart/LogPart.cpp | 75 +++++++++---------- src/coreComponents/fileIO/logPart/LogPart.hpp | 62 ++++++--------- 2 files changed, 56 insertions(+), 81 deletions(-) diff --git a/src/coreComponents/fileIO/logPart/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp index cfd5f78fb8d..9a163c2abee 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -25,7 +25,9 @@ namespace geos LogPart::LogPart( string_view sectionTitle ): m_sectionTitle( string( sectionTitle ) ), m_sectionWidth( sectionTitle.length() ) -{} +{ + m_footerTitle = GEOS_FMT( "End : {}", m_sectionTitle ); +} void LogPart::addDescription( string_view description ) { @@ -43,65 +45,65 @@ void LogPart::setMinWidth( integer const & minWidth ) } void LogPart::formatAndInsertDescriptions( std::vector< string > & descriptionContainer, - string_view descriptionName, - std::vector< string > const & descriptionValues ) + string_view name, + std::vector< string > const & values ) { - string const descriptionNameFormatted = GEOS_FMT( "- {}: ", string( descriptionName )); - string const descriptionFormatted = GEOS_FMT( "{}{}", descriptionNameFormatted, descriptionValues[0] ); + string const nameFormatted = GEOS_FMT( "- {}: ", string( name )); + string const descriptionFormatted = GEOS_FMT( "{}{}", nameFormatted, values[0] ); integer const spacesFromBorder = m_marginBorder * 2 + m_nbBorderChar * 2; integer const completeDescriptionLength = descriptionFormatted.length() + spacesFromBorder; descriptionContainer.push_back( descriptionFormatted ); m_sectionWidth = std::max( completeDescriptionLength, m_sectionWidth ); - for( size_t idxValue = 1; idxValue < descriptionValues.size(); idxValue++ ) + for( size_t idxValue = 1; idxValue < values.size(); idxValue++ ) { - size_t const spaces = descriptionValues[idxValue].length() + descriptionNameFormatted.length(); - descriptionContainer.push_back( GEOS_FMT( "{:>{}}", descriptionValues[idxValue], spaces ) ); + size_t const spaces = values[idxValue].length() + nameFormatted.length(); + descriptionContainer.push_back( GEOS_FMT( "{:>{}}", values[idxValue], spaces ) ); } } -string LogPart::constructDescriptionsFromVector( std::vector< string > const & descriptions ) const +string LogPart::buildDescriptionPart( std::vector< string > const & descriptions ) const { std::ostringstream oss; - for( const auto & description : descriptions ) + for( auto const & description : descriptions ) { - integer const rowDescriptionLength = m_sectionWidth - m_nbBorderChar * 2 - m_marginBorder; - formatDescription( oss, description, rowDescriptionLength ); + integer const remainingLength = m_sectionWidth - m_nbBorderChar * 2 - m_marginBorder; + string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbBorderChar ); + oss << borderCharacters; + oss << GEOS_FMT( "{:<{}}{:<{}}", " ", m_marginBorder, description, remainingLength ); + oss << borderCharacters << '\n'; } return oss.str(); } -void LogPart::formatDescription( std::ostringstream & oss, - string const & description, - integer const remainingLength ) const +string LogPart::buildTitlePart( string_view title ) const { - string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbBorderChar ); - oss << borderCharacters; - oss << GEOS_FMT( "{:<{}}{:<{}}", " ", m_marginBorder, description, remainingLength ); - oss << borderCharacters << '\n'; + std::ostringstream oss; + integer const titleRowLength = m_sectionWidth - m_nbBorderChar * 2; + string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbBorderChar ); + oss << GEOS_FMT( "{}{:^{}}{}\n", + borderCharacters, + title, + titleRowLength, + borderCharacters ); + return oss.str(); } void LogPart::begin( std::ostream & os ) { m_sectionWidth = std::max( m_sectionWidth, m_rowMinWidth ); - integer const titleRowLength = m_sectionWidth - m_nbBorderChar * 2; - string descriptions; + string bottomPart; if( !m_descriptions.empty()) { - descriptions = constructDescriptionsFromVector( m_descriptions ); + bottomPart = buildDescriptionPart( m_descriptions ); } - string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbBorderChar ); - string titleRowFormatted = GEOS_FMT( "{}{:^{}}{}\n", - borderCharacters, - m_sectionTitle, - titleRowLength, - borderCharacters ); m_horizontalBorder = GEOS_FMT( "{:#>{}}\n", "", m_sectionWidth ); - string const topPart = GEOS_FMT( "{}{}{}", m_horizontalBorder, titleRowFormatted, m_horizontalBorder ); - string const bottomPart = descriptions; + string topPart = GEOS_FMT( "{}{}{}", m_horizontalBorder, + buildTitlePart( m_sectionTitle ), + m_horizontalBorder ); os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } @@ -110,18 +112,9 @@ void LogPart::end( std::ostream & os ) const string topPart; if( !m_endLogMessages.empty() ) { - topPart = GEOS_FMT( "{}{}", constructDescriptionsFromVector( m_endLogMessages ), m_horizontalBorder ); + topPart = GEOS_FMT( "{}{}", buildDescriptionPart( m_endLogMessages ), m_horizontalBorder ); } - - string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbBorderChar ); - string const footerTitle = GEOS_FMT( "{}{}", m_footerTitle, m_sectionTitle ); - integer const titleRowLength = m_sectionWidth - m_nbBorderChar * 2; - string titleRowFormatted = GEOS_FMT( "{}{:^{}}{}\n", - borderCharacters, - footerTitle, - titleRowLength, - borderCharacters ); - string const bottomPart = GEOS_FMT( "{}{}", titleRowFormatted, m_horizontalBorder ); + string bottomPart = GEOS_FMT( "{}{}", buildTitlePart( m_footerTitle ), m_horizontalBorder ); os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } diff --git a/src/coreComponents/fileIO/logPart/LogPart.hpp b/src/coreComponents/fileIO/logPart/LogPart.hpp index 8aa2fe23d41..ebe52cf3b41 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.hpp +++ b/src/coreComponents/fileIO/logPart/LogPart.hpp @@ -40,12 +40,12 @@ class LogPart /** * @brief Add a description to the section by concatening a description name and descriptions values. - * @param descriptionName The description name + * @param name The description name * @param args Descriptions values to be concatened. * Descriptions values can be be any types and will be aligned */ template< typename ... Args > - void addDescription( string_view descriptionName, Args const & ... args ); + void addDescription( string_view name, Args const & ... args ); /** * @brief Add a description to the section @@ -55,12 +55,12 @@ class LogPart /** * @brief Add a description to the end of the section by concatening a description name and descriptions values. - * @param descriptionName The description name + * @param name The description name * @param args Descriptions values to be concatened. * Descriptions values can be be any types and will be aligned */ template< typename ... Args > - void addEndDescription( string_view descriptionName, Args const & ... args ); + void addEndDescription( string_view name, Args const & ... args ); /** * @brief Add a description to the end of the section @@ -90,40 +90,24 @@ class LogPart /** * @brief Build a description from the name and description values - * @param descriptionName The decription name + * @param name The decription name * @param decriptionsValues The description values */ void formatAndInsertDescriptions( std::vector< string > & descriptionContainer, - string_view descriptionName, + string_view name, std::vector< string > const & decriptionsValues ); /** - * @brief Constructs a string from a vector of descriptions. - * @param descriptions A vector of string containing the descriptions - * @return A string containing all the formatted descriptions. + * @brief Constructs the string section title of the log part. + * @param title The title to be set */ - string constructDescriptionsFromVector( std::vector< string > const & descriptions ) const; + string buildTitlePart( string_view title ) const; /** - * @brief Formats a description and adds it to an output stream - * @param oss The output stream - * @param description The description to be formatted - * @param remainingLength The remaining length available for the description - * after accounting for borders and margins + * @brief Constructs the string section descriptions of the log part. + * @param descriptions The description to be formatted */ - void formatDescription( std::ostringstream & oss, - string const & description, - integer const remainingLength ) const; - -/** - * @brief Formats a log section with a title and optional descriptions. - * @param title The title of the log section to be formatted. - * @param titleRowLength The length of the title row - * @param descriptions Optional descriptions to include below the title; - * if empty, only the title will be displayed. - * @return A formatted string containing the top and bottom parts of the log section - */ - string formatLogSection( string_view title, integer titleRowLength, string_view descriptions ) const; + string buildDescriptionPart( std::vector< string > const & descriptions ) const; /// Vector containing all descriptions std::vector< string > m_descriptions; @@ -132,6 +116,8 @@ class LogPart /// title of section string m_sectionTitle; + /// Start title footer string + string m_footerTitle; /// section length integer m_sectionWidth; /// min width of section length @@ -144,36 +130,32 @@ class LogPart /// String containing horizontal border string m_horizontalBorder; - - /// Start title footer string - static string_view constexpr m_footerTitle = "End : "; - }; template< typename ... Args > -void LogPart::addDescription( string_view descriptionName, Args const &... args ) +void LogPart::addDescription( string_view name, Args const &... args ) { - std::vector< string > descriptionsValues; + std::vector< string > values; ( [&] { static_assert( has_formatter_v< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); string const value = GEOS_FMT( "{}", args ); - descriptionsValues.push_back( value ); + values.push_back( value ); } (), ...); - formatAndInsertDescriptions( m_descriptions, descriptionName, descriptionsValues ); + formatAndInsertDescriptions( m_descriptions, name, values ); } template< typename ... Args > -void LogPart::addEndDescription( string_view descriptionName, Args const &... args ) +void LogPart::addEndDescription( string_view name, Args const &... args ) { - std::vector< string > descriptionsValues; + std::vector< string > values; ( [&] { static_assert( has_formatter_v< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); string const value = GEOS_FMT( "{}", args ); - descriptionsValues.push_back( value ); + values.push_back( value ); } (), ...); - formatAndInsertDescriptions( m_endLogMessages, descriptionName, descriptionsValues ); + formatAndInsertDescriptions( m_endLogMessages, name, values ); } } From 29e046e93c878766d2ef0a98b49c40833821e806 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 6 Nov 2024 16:03:08 +0100 Subject: [PATCH 191/206] renaming and simpl --- .../common/format/table/TableFormatter.cpp | 8 +- .../common/format/table/TableFormatter.hpp | 2 +- .../common/format/table/TableLayout.hpp | 2 +- src/coreComponents/events/EventManager.cpp | 2 +- src/coreComponents/fileIO/logPart/LogPart.cpp | 73 ++++++++++--------- src/coreComponents/fileIO/logPart/LogPart.hpp | 48 ++++++------ .../fileIO/logPart/unitTests/testLogPart.cpp | 17 +++-- 7 files changed, 84 insertions(+), 68 deletions(-) diff --git a/src/coreComponents/common/format/table/TableFormatter.cpp b/src/coreComponents/common/format/table/TableFormatter.cpp index 0d4a18b92de..56f529bdcee 100644 --- a/src/coreComponents/common/format/table/TableFormatter.cpp +++ b/src/coreComponents/common/format/table/TableFormatter.cpp @@ -171,7 +171,7 @@ string TableTextFormatter::toString< TableData >( TableData const & tableData ) fillTableColumnsFromRows( columns, tableDataRows ); outputLayout( tableOutput, columns, msgTableError, sectionSeparatingLine ); - outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbValuesRows, TableLayout::LogPart::values ); + outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbValuesRows, TableLayout::Section::values ); tableOutput << '\n'; return tableOutput.str(); @@ -198,7 +198,7 @@ void TableTextFormatter::outputLayout( std::ostringstream & tableOutput, outputTopRows( tableOutput, msgTableError, topSeparator, TableLayout::Alignment::left ); tableOutput << GEOS_FMT( "{}\n", sectionSeparatingLine ); - outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbHeaderRows, TableLayout::LogPart::header ); + outputSectionRows( columns, sectionSeparatingLine, tableOutput, nbHeaderRows, TableLayout::Section::header ); } void TableTextFormatter::splitAndSetColumnNames( std::vector< TableLayout::Column > & columns, @@ -369,7 +369,7 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c string_view sectionSeparatingLine, std::ostringstream & tableOutput, integer const nbRows, - TableLayout::LogPart const section ) const + TableLayout::Section const section ) const { integer const columnMargin = m_tableLayout.getColumnMargin(); integer const borderMargin = m_tableLayout.getBorderMargin(); @@ -381,7 +381,7 @@ void TableTextFormatter::outputSectionRows( std::vector< TableLayout::Column > c for( std::size_t idxColumn = 0; idxColumn < columns.size(); ++idxColumn ) { TableLayout::Column const currentColumn = columns[idxColumn]; - auto const & columnContent = section == TableLayout::LogPart::header ? + auto const & columnContent = section == TableLayout::Section::header ? columns[idxColumn].m_parameter.splitColumnNameLines : columns[idxColumn].m_columnValues; string cell = columnContent.at( idxRow ); diff --git a/src/coreComponents/common/format/table/TableFormatter.hpp b/src/coreComponents/common/format/table/TableFormatter.hpp index 1774d95e4b9..165533445b6 100644 --- a/src/coreComponents/common/format/table/TableFormatter.hpp +++ b/src/coreComponents/common/format/table/TableFormatter.hpp @@ -244,7 +244,7 @@ class TableTextFormatter : public TableFormatter string_view sectionSeparatingLine, std::ostringstream & rows, integer const nbRows, - TableLayout::LogPart const section ) const; + TableLayout::Section const section ) const; }; /** diff --git a/src/coreComponents/common/format/table/TableLayout.hpp b/src/coreComponents/common/format/table/TableLayout.hpp index dcf860db91c..4f24fa5559c 100644 --- a/src/coreComponents/common/format/table/TableLayout.hpp +++ b/src/coreComponents/common/format/table/TableLayout.hpp @@ -48,7 +48,7 @@ class TableLayout /** * @brief Enumeration for table sections. */ - enum LogPart { header, values }; + enum Section { header, values }; /** * @brief Structure to set up each colum parameters. diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index 4a879633ef3..c6c58fafd90 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -170,7 +170,7 @@ bool EventManager::run( DomainPartition & domain ) m_dt = dt_global; #endif } - LogPart logPart( "TIMESTEP START" ); + LogPart logPart( "TIMESTEP" ); outputTime( logPart ); logPart.begin(); diff --git a/src/coreComponents/fileIO/logPart/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp index 9a163c2abee..565c13a8b99 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -22,54 +22,61 @@ namespace geos { -LogPart::LogPart( string_view sectionTitle ): - m_sectionTitle( string( sectionTitle ) ), - m_sectionWidth( sectionTitle.length() ) +LogPart::LogPart( string_view logPartTitle ): + m_logPartTitle( string( logPartTitle ) ), + m_logPartWidth( std::max((size_t)m_rowMinWidth, logPartTitle.length()) ) { - m_footerTitle = GEOS_FMT( "End : {}", m_sectionTitle ); + m_footerTitle = GEOS_FMT( "End of {}", m_logPartTitle ); } void LogPart::addDescription( string_view description ) { - m_descriptions.push_back( string( description ) ); + m_beginningDescs.push_back( string( description ) ); } void LogPart::addEndDescription( string_view description ) { - m_endLogMessages.push_back( string( description ) ); + m_endDescs.push_back( string( description ) ); } void LogPart::setMinWidth( integer const & minWidth ) { m_rowMinWidth = minWidth; + m_logPartWidth = std::max( m_rowMinWidth, m_logPartWidth ); } -void LogPart::formatAndInsertDescriptions( std::vector< string > & descriptionContainer, +void LogPart::formatAndInsertDescriptions( std::vector< string > & formattedDescriptions, string_view name, - std::vector< string > const & values ) + std::vector< string > const & descriptionValues ) { string const nameFormatted = GEOS_FMT( "- {}: ", string( name )); - string const descriptionFormatted = GEOS_FMT( "{}{}", nameFormatted, values[0] ); + + // format each description with name and the first value + string const descriptionFormatted = GEOS_FMT( "{}{}", nameFormatted, descriptionValues[0] ); + integer const spacesFromBorder = m_marginBorder * 2 + m_nbBorderChar * 2; - integer const completeDescriptionLength = descriptionFormatted.length() + spacesFromBorder; - descriptionContainer.push_back( descriptionFormatted ); + integer const rowLength = descriptionFormatted.length() + spacesFromBorder; + + formattedDescriptions.push_back( descriptionFormatted ); - m_sectionWidth = std::max( completeDescriptionLength, m_sectionWidth ); + m_logPartWidth = std::max( rowLength, m_logPartWidth ); - for( size_t idxValue = 1; idxValue < values.size(); idxValue++ ) + //format remaining description lines + for( size_t idxValue = 1; idxValue < descriptionValues.size(); idxValue++ ) { - size_t const spaces = values[idxValue].length() + nameFormatted.length(); - descriptionContainer.push_back( GEOS_FMT( "{:>{}}", values[idxValue], spaces ) ); + size_t const spaces = descriptionValues[idxValue].length() + nameFormatted.length(); + formattedDescriptions.push_back( GEOS_FMT( "{:>{}}", descriptionValues[idxValue], spaces ) ); } } -string LogPart::buildDescriptionPart( std::vector< string > const & descriptions ) const +string LogPart::buildDescriptionPart( std::vector< string > const & formattedDescriptions ) const { std::ostringstream oss; - for( auto const & description : descriptions ) + for( auto const & description : formattedDescriptions ) { - integer const remainingLength = m_sectionWidth - m_nbBorderChar * 2 - m_marginBorder; - string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbBorderChar ); + // length of white space to add after the formatted description + integer const remainingLength = m_logPartWidth - m_nbBorderChar * 2 - m_marginBorder; + string const borderCharacters = string( m_nbBorderChar, m_borderCharacter ); oss << borderCharacters; oss << GEOS_FMT( "{:<{}}{:<{}}", " ", m_marginBorder, description, remainingLength ); oss << borderCharacters << '\n'; @@ -80,8 +87,8 @@ string LogPart::buildDescriptionPart( std::vector< string > const & descriptions string LogPart::buildTitlePart( string_view title ) const { std::ostringstream oss; - integer const titleRowLength = m_sectionWidth - m_nbBorderChar * 2; - string const borderCharacters = GEOS_FMT( "{:#<{}}", "", m_nbBorderChar ); + integer const titleRowLength = m_logPartWidth - m_nbBorderChar * 2; + string const borderCharacters = string( m_nbBorderChar, m_borderCharacter ); oss << GEOS_FMT( "{}{:^{}}{}\n", borderCharacters, title, @@ -90,31 +97,31 @@ string LogPart::buildTitlePart( string_view title ) const return oss.str(); } -void LogPart::begin( std::ostream & os ) +void LogPart::begin( std::ostream & os ) const { - m_sectionWidth = std::max( m_sectionWidth, m_rowMinWidth ); - string bottomPart; - if( !m_descriptions.empty()) + if( !m_beginningDescs.empty()) { - bottomPart = buildDescriptionPart( m_descriptions ); + bottomPart = buildDescriptionPart( m_beginningDescs ); } - m_horizontalBorder = GEOS_FMT( "{:#>{}}\n", "", m_sectionWidth ); - string topPart = GEOS_FMT( "{}{}{}", m_horizontalBorder, - buildTitlePart( m_sectionTitle ), - m_horizontalBorder ); + string const horizontalBorder = string( m_logPartWidth, m_borderCharacter ); + string topPart = GEOS_FMT( "{}\n{}{}\n", horizontalBorder, + buildTitlePart( m_logPartTitle ), + horizontalBorder ); os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } void LogPart::end( std::ostream & os ) const { string topPart; - if( !m_endLogMessages.empty() ) + string const horizontalBorder = string( m_logPartWidth, m_borderCharacter ); + if( !m_endDescs.empty() ) { - topPart = GEOS_FMT( "{}{}", buildDescriptionPart( m_endLogMessages ), m_horizontalBorder ); + topPart = GEOS_FMT( "{}{}\n", buildDescriptionPart( m_endDescs ), horizontalBorder ); } - string bottomPart = GEOS_FMT( "{}{}", buildTitlePart( m_footerTitle ), m_horizontalBorder ); + + string const bottomPart = GEOS_FMT( "{}{}\n", buildTitlePart( m_footerTitle ), horizontalBorder ); os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } diff --git a/src/coreComponents/fileIO/logPart/LogPart.hpp b/src/coreComponents/fileIO/logPart/LogPart.hpp index ebe52cf3b41..35e3d8604d8 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.hpp +++ b/src/coreComponents/fileIO/logPart/LogPart.hpp @@ -34,12 +34,12 @@ class LogPart /** * @brief Construct a new LogPart - * @param m_sectionTitle The section title + * @param m_logPartTitle The logPart title */ - LogPart( string_view m_sectionTitle ); + LogPart( string_view m_logPartTitle ); /** - * @brief Add a description to the section by concatening a description name and descriptions values. + * @brief Add a description to the logPart by concatening a description name and descriptions values. * @param name The description name * @param args Descriptions values to be concatened. * Descriptions values can be be any types and will be aligned @@ -48,13 +48,13 @@ class LogPart void addDescription( string_view name, Args const & ... args ); /** - * @brief Add a description to the section + * @brief Add a description to the logPart * @param description The string value of the description */ void addDescription( string_view description ); /** - * @brief Add a description to the end of the section by concatening a description name and descriptions values. + * @brief Add a description to the end of the logPart by concatening a description name and descriptions values. * @param name The description name * @param args Descriptions values to be concatened. * Descriptions values can be be any types and will be aligned @@ -63,7 +63,7 @@ class LogPart void addEndDescription( string_view name, Args const & ... args ); /** - * @brief Add a description to the end of the section + * @brief Add a description to the end of the logPart * @param description The string value of the description */ void addEndDescription( string_view description ); @@ -75,13 +75,13 @@ class LogPart void setMinWidth( integer const & minWidth ); /** - * @brief Draw the first part of the section. It include the title and optionnaly, the description(s); + * @brief Draw the first part of the logPart. It include the title and optionnaly, the end description(s). * @param os An output stream (by default, std::cout) */ - void begin( std::ostream & os = std::cout ); + void begin( std::ostream & os = std::cout ) const; /** - * @brief Draw the last part of the section. It include the title + * @brief Draw the last part of the logPart. It include the title * @param oss An output stream (by default, std::cout) */ void end( std::ostream & oss = std::cout ) const; @@ -93,40 +93,42 @@ class LogPart * @param name The decription name * @param decriptionsValues The description values */ - void formatAndInsertDescriptions( std::vector< string > & descriptionContainer, + void formatAndInsertDescriptions( std::vector< string > & formattedDescriptions, string_view name, std::vector< string > const & decriptionsValues ); /** - * @brief Constructs the string section title of the log part. + * @brief Constructs the string logPart title of the log part. * @param title The title to be set */ string buildTitlePart( string_view title ) const; /** - * @brief Constructs the string section descriptions of the log part. + * @brief Constructs the string logPart descriptions of the log part. * @param descriptions The description to be formatted */ - string buildDescriptionPart( std::vector< string > const & descriptions ) const; + string buildDescriptionPart( std::vector< string > const & formattedDescriptions ) const; /// Vector containing all descriptions - std::vector< string > m_descriptions; - /// title of section - std::vector< string > m_endLogMessages; + std::vector< string > m_beginningDescs; + /// title of logPart + std::vector< string > m_endDescs; - /// title of section - string m_sectionTitle; + /// title of logPart + string m_logPartTitle; /// Start title footer string string m_footerTitle; - /// section length - integer m_sectionWidth; - /// min width of section length + /// min width of logPart length integer m_rowMinWidth = 70; + /// logPart length + integer m_logPartWidth; /// description border margin static constexpr integer m_marginBorder = 2; /// numbers of character used as border static constexpr integer m_nbBorderChar = 2; + /// character used for logPart construction + static constexpr integer m_borderCharacter = '#'; /// String containing horizontal border string m_horizontalBorder; @@ -142,7 +144,7 @@ void LogPart::addDescription( string_view name, Args const &... args ) values.push_back( value ); } (), ...); - formatAndInsertDescriptions( m_descriptions, name, values ); + formatAndInsertDescriptions( m_beginningDescs, name, values ); } template< typename ... Args > @@ -155,7 +157,7 @@ void LogPart::addEndDescription( string_view name, Args const &... args ) values.push_back( value ); } (), ...); - formatAndInsertDescriptions( m_endLogMessages, name, values ); + formatAndInsertDescriptions( m_endDescs, name, values ); } } diff --git a/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp b/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp index a3525d1c9b1..7afa6566eb1 100644 --- a/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp +++ b/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp @@ -23,6 +23,7 @@ TEST( testSection, sectionWithTitle ) std::ostringstream oss; LogPart logPart( "section name" ); logPart.begin( oss ); + std::cout << oss.str() << std::endl; EXPECT_EQ( oss.str(), "\n######################################################################\n" "## section name ##\n" @@ -32,8 +33,9 @@ TEST( testSection, sectionWithTitle ) oss.str( "" ); logPart.end( oss ); + std::cout << oss.str() << std::endl; EXPECT_EQ( oss.str(), - "\n## End : section name ##\n" + "\n## End of section name ##\n" "######################################################################\n\n" ); oss.clear(); @@ -45,6 +47,7 @@ TEST( testSection, sectionWithTitleAndOneDescription ) LogPart logPart( "section name" ); logPart.addDescription( "description name" ); logPart.begin( oss ); + std::cout << oss.str() << std::endl; EXPECT_EQ( oss.str(), "\n######################################################################\n" "## section name ##\n" @@ -62,6 +65,7 @@ TEST( testSection, sectionWithSetWidth ) logPart.addDescription( "description name 2" ); logPart.setMinWidth( 100 ); logPart.begin( oss ); + std::cout << oss.str() << std::endl; EXPECT_EQ( oss.str(), "\n####################################################################################################\n" "## section name ##\n" @@ -73,8 +77,9 @@ TEST( testSection, sectionWithSetWidth ) oss.str( "" ); logPart.end( oss ); + std::cout << oss.str() << std::endl; EXPECT_EQ( oss.str(), - "\n## End : section name ##\n" + "\n## End of section name ##\n" "####################################################################################################\n\n" ); oss.clear(); @@ -89,6 +94,7 @@ TEST( testSection, sectionMultipleDescriptions ) logPart.addDescription( "- Cycle: 1" ); logPart.setMinWidth( 70 ); logPart.begin( oss ); + std::cout << oss.str() << std::endl; EXPECT_EQ ( oss.str(), "\n######################################################################\n" "## TIMESTEP START ##\n" @@ -102,8 +108,9 @@ TEST( testSection, sectionMultipleDescriptions ) oss.str( "" ); logPart.end( oss ); + std::cout << oss.str() << std::endl; EXPECT_EQ( oss.str(), - "\n## End : TIMESTEP START ##\n" + "\n## End of TIMESTEP START ##\n" "######################################################################\n\n" ); oss.clear(); @@ -122,12 +129,12 @@ TEST( testSection, sectionEndDescription ) logPart.end( oss ); - std::cout << " end section \n" << oss.str() << std::endl; + std::cout << oss.str() << std::endl; EXPECT_EQ( oss.str(), "\n## test end description ##\n" "######################################################################\n" - "## End : TIMESTEP START ##\n" + "## End of TIMESTEP START ##\n" "######################################################################\n\n" ); oss.clear(); From 64403318c40f023ce19e36b67c2cff822b9e1046 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 6 Nov 2024 16:07:36 +0100 Subject: [PATCH 192/206] uncrustify --- src/coreComponents/fileIO/logPart/LogPart.cpp | 7 ++++--- .../fileIO/logPart/unitTests/testLogPart.cpp | 9 --------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/coreComponents/fileIO/logPart/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp index 565c13a8b99..5f6b5b7b13d 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -106,9 +106,10 @@ void LogPart::begin( std::ostream & os ) const } string const horizontalBorder = string( m_logPartWidth, m_borderCharacter ); - string topPart = GEOS_FMT( "{}\n{}{}\n", horizontalBorder, - buildTitlePart( m_logPartTitle ), - horizontalBorder ); + string const topPart = GEOS_FMT( "{}\n{}{}\n", + horizontalBorder, + buildTitlePart( m_logPartTitle ), + horizontalBorder ); os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } diff --git a/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp b/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp index 7afa6566eb1..0b4b5b99968 100644 --- a/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp +++ b/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp @@ -23,7 +23,6 @@ TEST( testSection, sectionWithTitle ) std::ostringstream oss; LogPart logPart( "section name" ); logPart.begin( oss ); - std::cout << oss.str() << std::endl; EXPECT_EQ( oss.str(), "\n######################################################################\n" "## section name ##\n" @@ -33,7 +32,6 @@ TEST( testSection, sectionWithTitle ) oss.str( "" ); logPart.end( oss ); - std::cout << oss.str() << std::endl; EXPECT_EQ( oss.str(), "\n## End of section name ##\n" "######################################################################\n\n" @@ -47,7 +45,6 @@ TEST( testSection, sectionWithTitleAndOneDescription ) LogPart logPart( "section name" ); logPart.addDescription( "description name" ); logPart.begin( oss ); - std::cout << oss.str() << std::endl; EXPECT_EQ( oss.str(), "\n######################################################################\n" "## section name ##\n" @@ -65,7 +62,6 @@ TEST( testSection, sectionWithSetWidth ) logPart.addDescription( "description name 2" ); logPart.setMinWidth( 100 ); logPart.begin( oss ); - std::cout << oss.str() << std::endl; EXPECT_EQ( oss.str(), "\n####################################################################################################\n" "## section name ##\n" @@ -77,7 +73,6 @@ TEST( testSection, sectionWithSetWidth ) oss.str( "" ); logPart.end( oss ); - std::cout << oss.str() << std::endl; EXPECT_EQ( oss.str(), "\n## End of section name ##\n" "####################################################################################################\n\n" @@ -94,7 +89,6 @@ TEST( testSection, sectionMultipleDescriptions ) logPart.addDescription( "- Cycle: 1" ); logPart.setMinWidth( 70 ); logPart.begin( oss ); - std::cout << oss.str() << std::endl; EXPECT_EQ ( oss.str(), "\n######################################################################\n" "## TIMESTEP START ##\n" @@ -108,7 +102,6 @@ TEST( testSection, sectionMultipleDescriptions ) oss.str( "" ); logPart.end( oss ); - std::cout << oss.str() << std::endl; EXPECT_EQ( oss.str(), "\n## End of TIMESTEP START ##\n" "######################################################################\n\n" @@ -129,8 +122,6 @@ TEST( testSection, sectionEndDescription ) logPart.end( oss ); - std::cout << oss.str() << std::endl; - EXPECT_EQ( oss.str(), "\n## test end description ##\n" "######################################################################\n" From 447aaf2e33dfd76152ff282714b467f5dfe7ac59 Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 7 Nov 2024 15:36:00 +0100 Subject: [PATCH 193/206] revert --- src/coreComponents/dataRepository/Group.cpp | 1 - src/coreComponents/physicsSolvers/FieldStatisticsBase.hpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/coreComponents/dataRepository/Group.cpp b/src/coreComponents/dataRepository/Group.cpp index 2840aab5014..abbf6379fa9 100644 --- a/src/coreComponents/dataRepository/Group.cpp +++ b/src/coreComponents/dataRepository/Group.cpp @@ -356,7 +356,6 @@ void Group::initialize_postMeshGeneration() void Group::initialize() { - initializePreSubGroups(); array1d< string > initOrder; diff --git a/src/coreComponents/physicsSolvers/FieldStatisticsBase.hpp b/src/coreComponents/physicsSolvers/FieldStatisticsBase.hpp index 1aa801769b1..512edb7af7e 100644 --- a/src/coreComponents/physicsSolvers/FieldStatisticsBase.hpp +++ b/src/coreComponents/physicsSolvers/FieldStatisticsBase.hpp @@ -58,7 +58,7 @@ class FieldStatisticsBase : public TaskBase setDescription( "Name of the " + SOLVER::coupledSolverAttributePrefix() + " solver" ); this->registerWrapper( viewKeyStruct::writeCSVFlagString(), &m_writeCSV ). - setApplyDefaultValue( 1 ). + setApplyDefaultValue( 0 ). setInputFlag( dataRepository::InputFlags::OPTIONAL ). setDescription( "Write statistics into a CSV file" ); } From 38815d9203bb183006b645d70de4379289804bf2 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 19 Nov 2024 09:15:13 +0100 Subject: [PATCH 194/206] rename --- src/coreComponents/mainInterface/ProblemManager.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/coreComponents/mainInterface/ProblemManager.cpp b/src/coreComponents/mainInterface/ProblemManager.cpp index 2815e45847a..db99153cd0a 100644 --- a/src/coreComponents/mainInterface/ProblemManager.cpp +++ b/src/coreComponents/mainInterface/ProblemManager.cpp @@ -172,10 +172,17 @@ void ProblemManager::problemSetup() logPart.end(); // initialize_postMeshGeneration(); + LogPart logPart( "NumericalMethods" ); + logPart.begin(); applyNumericalMethods(); + LogPart logPart( "Mesh data registration :" ); + logPart.begin(); registerDataOnMeshRecursive( getDomainPartition().getMeshBodies() ); + LogPart logPart( "Group & subgroups initializatf:H6svfHYlX:KJr!@gIqya-3J8GYGj\yz9;GAg?~ + ion" ); + logPart.begin(); initialize(); importFields(); From 5d3d677084ebb53698cb6ab72457519a6466030f Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 9 Dec 2024 11:49:56 +0100 Subject: [PATCH 195/206] rename --- .../mainInterface/ProblemManager.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/coreComponents/mainInterface/ProblemManager.cpp b/src/coreComponents/mainInterface/ProblemManager.cpp index db99153cd0a..f783d0458f1 100644 --- a/src/coreComponents/mainInterface/ProblemManager.cpp +++ b/src/coreComponents/mainInterface/ProblemManager.cpp @@ -166,23 +166,22 @@ void ProblemManager::problemSetup() postInputInitializationRecursive(); - LogPart logPart( "Mesh generation" ); - logPart.begin(); + LogPart meshLogPart( "Mesh generation" ); + meshLogPart.begin(); generateMesh(); - logPart.end(); + meshLogPart.end(); // initialize_postMeshGeneration(); - LogPart logPart( "NumericalMethods" ); - logPart.begin(); + LogPart nmLogPart( "NumericalMethods" ); + nmLogPart.begin(); applyNumericalMethods(); - LogPart logPart( "Mesh data registration :" ); - logPart.begin(); + LogPart meshDataLogPart( "Mesh data registration :" ); + meshDataLogPart.begin(); registerDataOnMeshRecursive( getDomainPartition().getMeshBodies() ); - LogPart logPart( "Group & subgroups initializatf:H6svfHYlX:KJr!@gIqya-3J8GYGj\yz9;GAg?~ - ion" ); - logPart.begin(); + LogPart grpLogPart( "Group & subgroups initialization" ); + grpLogPart.begin(); initialize(); importFields(); From ca632ffba05554d1b183b5c3bd5f17250f5fedb8 Mon Sep 17 00:00:00 2001 From: arng40 Date: Tue, 10 Dec 2024 10:30:27 +0100 Subject: [PATCH 196/206] struture update --- src/coreComponents/events/EventManager.cpp | 6 +- src/coreComponents/fileIO/logPart/LogPart.cpp | 119 +++++++++++------- src/coreComponents/fileIO/logPart/LogPart.hpp | 80 +++++------- .../fileIO/logPart/unitTests/testLogPart.cpp | 24 ++-- .../mainInterface/ProblemManager.cpp | 3 + 5 files changed, 118 insertions(+), 114 deletions(-) diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index b479b94ef33..800a7bd1e09 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -254,9 +254,9 @@ void EventManager::outputTime( LogPart & logPart ) const string const timeInfosUnfolded = timeInfo.toUnfoldedString() + timeCompletionUnfolded; string const timeCompletionSeconds = timeInfo.toSecondsString() + timeCompletionSecond; - logPart.addDescription( "Time", timeInfosUnfolded, timeCompletionSeconds ); - logPart.addDescription( "Delta Time", units::TimeFormatInfo::fromSeconds( m_dt ).toString() ); - logPart.addDescription( "Cycle", m_cycle, cycleLimited ); + logPart.addDescription( "- Time :", timeInfosUnfolded, timeCompletionSeconds ); + logPart.addDescription( "- Delta Time :", units::TimeFormatInfo::fromSeconds( m_dt ).toString() ); + logPart.addDescription( "- Cycle :", m_cycle, cycleLimited ); logPart.setMinWidth( 70 ); // We are keeping the old outputs to keep compatibility with current log reading scripts. diff --git a/src/coreComponents/fileIO/logPart/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp index 5f6b5b7b13d..08b5707e272 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -26,103 +26,128 @@ LogPart::LogPart( string_view logPartTitle ): m_logPartTitle( string( logPartTitle ) ), m_logPartWidth( std::max((size_t)m_rowMinWidth, logPartTitle.length()) ) { - m_footerTitle = GEOS_FMT( "End of {}", m_logPartTitle ); + m_footerTitle = GEOS_FMT( "{}", m_logPartTitle ); } -void LogPart::addDescription( string_view description ) +void LogPart::addDescription( string const & description ) { - m_beginningDescs.push_back( string( description ) ); + m_descriptionNames.push_back( description ); + m_descriptionValues.push_back( std::vector< string >() ); } -void LogPart::addEndDescription( string_view description ) -{ - m_endDescs.push_back( string( description ) ); -} -void LogPart::setMinWidth( integer const & minWidth ) +void LogPart::setMinWidth( size_t const & minWidth ) { m_rowMinWidth = minWidth; m_logPartWidth = std::max( m_rowMinWidth, m_logPartWidth ); } -void LogPart::formatAndInsertDescriptions( std::vector< string > & formattedDescriptions, - string_view name, - std::vector< string > const & descriptionValues ) +void LogPart::formatDescriptions() { - string const nameFormatted = GEOS_FMT( "- {}: ", string( name )); - - // format each description with name and the first value - string const descriptionFormatted = GEOS_FMT( "{}{}", nameFormatted, descriptionValues[0] ); - - integer const spacesFromBorder = m_marginBorder * 2 + m_nbBorderChar * 2; - integer const rowLength = descriptionFormatted.length() + spacesFromBorder; - - formattedDescriptions.push_back( descriptionFormatted ); - - m_logPartWidth = std::max( rowLength, m_logPartWidth ); + size_t maxNameSize = 1; + for( auto const & name : m_descriptionNames ) + { + size_t idx = &name - &(*m_descriptionNames.begin()); + if( !m_descriptionValues[idx].empty()) + { + maxNameSize = std::max( maxNameSize, name.size() ); + } + } - //format remaining description lines - for( size_t idxValue = 1; idxValue < descriptionValues.size(); idxValue++ ) + size_t const spacesFromBorder = m_borderMargin * 2 + m_nbBorderChar * 2; + for( size_t idxName = 0; idxName < m_descriptionNames.size(); idxName++ ) { - size_t const spaces = descriptionValues[idxValue].length() + nameFormatted.length(); - formattedDescriptions.push_back( GEOS_FMT( "{:>{}}", descriptionValues[idxValue], spaces ) ); + if( m_descriptionValues[idxName].empty()) + { + m_formattedDescriptions.push_back( m_descriptionNames[idxName] ); + } + else + { + string name = m_descriptionNames[idxName]; + string spaces = string( maxNameSize - name.size(), ' ' ); + string nameFormatted = GEOS_FMT( "{}{} ", name, spaces ); + + m_formattedDescriptions.push_back( GEOS_FMT( "{}{}", nameFormatted, m_descriptionValues[idxName][0] )); + m_logPartWidth = m_formattedDescriptions[idxName].size() + spacesFromBorder; + + for( size_t idxValue = 1; idxValue < m_descriptionValues[idxName].size(); idxValue++ ) + { + m_formattedDescriptions.push_back( GEOS_FMT( "{:>{}}", m_descriptionValues[idxName][idxValue], + nameFormatted.size() + m_descriptionValues[idxName][idxValue].size() )); + m_logPartWidth = std::max( m_logPartWidth, + m_formattedDescriptions[idxValue].size() + spacesFromBorder ); + } + } + } + + m_logPartWidth = std::max( m_rowMinWidth, m_logPartWidth ); } -string LogPart::buildDescriptionPart( std::vector< string > const & formattedDescriptions ) const +string LogPart::buildDescriptionPart() { std::ostringstream oss; - for( auto const & description : formattedDescriptions ) + for( auto const & description : m_formattedDescriptions ) { // length of white space to add after the formatted description - integer const remainingLength = m_logPartWidth - m_nbBorderChar * 2 - m_marginBorder; + size_t const remainingLength = m_logPartWidth - m_nbBorderChar * 2 - m_borderMargin; string const borderCharacters = string( m_nbBorderChar, m_borderCharacter ); oss << borderCharacters; - oss << GEOS_FMT( "{:<{}}{:<{}}", " ", m_marginBorder, description, remainingLength ); + oss << GEOS_FMT( "{:<{}}{:<{}}", " ", m_borderMargin, description, remainingLength ); oss << borderCharacters << '\n'; } return oss.str(); } -string LogPart::buildTitlePart( string_view title ) const +void LogPart::clear() +{ + m_formattedDescriptions.clear(); + m_descriptionNames.clear(); + m_descriptionValues.clear(); +} + +string LogPart::buildTitlePart() { std::ostringstream oss; - integer const titleRowLength = m_logPartWidth - m_nbBorderChar * 2; + size_t const titleRowLength = m_logPartWidth - m_nbBorderChar * 2; string const borderCharacters = string( m_nbBorderChar, m_borderCharacter ); oss << GEOS_FMT( "{}{:^{}}{}\n", borderCharacters, - title, + m_footerTitle, titleRowLength, borderCharacters ); return oss.str(); } -void LogPart::begin( std::ostream & os ) const +void LogPart::begin( std::ostream & os ) { - string bottomPart; - if( !m_beginningDescs.empty()) + string bottomPart = ""; + if( !m_descriptionNames.empty()) { - bottomPart = buildDescriptionPart( m_beginningDescs ); + formatDescriptions(); } + bottomPart = buildDescriptionPart(); - string const horizontalBorder = string( m_logPartWidth, m_borderCharacter ); + string const line = string( m_logPartWidth, m_borderCharacter ); string const topPart = GEOS_FMT( "{}\n{}{}\n", - horizontalBorder, - buildTitlePart( m_logPartTitle ), - horizontalBorder ); + line, + buildTitlePart(), + line ); os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); + clear(); } -void LogPart::end( std::ostream & os ) const +void LogPart::end( std::ostream & os ) { - string topPart; - string const horizontalBorder = string( m_logPartWidth, m_borderCharacter ); - if( !m_endDescs.empty() ) + string topPart = ""; + string const line = string( m_logPartWidth, m_borderCharacter ); + if( !m_descriptionNames.empty() ) { - topPart = GEOS_FMT( "{}{}\n", buildDescriptionPart( m_endDescs ), horizontalBorder ); + formatDescriptions(); + topPart = GEOS_FMT( "{}{}\n", buildDescriptionPart(), line ); } - string const bottomPart = GEOS_FMT( "{}{}\n", buildTitlePart( m_footerTitle ), horizontalBorder ); + string const bottomPart = GEOS_FMT( "{}{}\n", buildTitlePart(), line ); os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } diff --git a/src/coreComponents/fileIO/logPart/LogPart.hpp b/src/coreComponents/fileIO/logPart/LogPart.hpp index 35e3d8604d8..5aab86ef594 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.hpp +++ b/src/coreComponents/fileIO/logPart/LogPart.hpp @@ -45,46 +45,31 @@ class LogPart * Descriptions values can be be any types and will be aligned */ template< typename ... Args > - void addDescription( string_view name, Args const & ... args ); + void addDescription( string const & name, Args const & ... args ); /** * @brief Add a description to the logPart * @param description The string value of the description */ - void addDescription( string_view description ); - - /** - * @brief Add a description to the end of the logPart by concatening a description name and descriptions values. - * @param name The description name - * @param args Descriptions values to be concatened. - * Descriptions values can be be any types and will be aligned - */ - template< typename ... Args > - void addEndDescription( string_view name, Args const & ... args ); - - /** - * @brief Add a description to the end of the logPart - * @param description The string value of the description - */ - void addEndDescription( string_view description ); + void addDescription( string const & description ); /** * @brief Set the minimal width of a row * @param minWidth The minimal width of the table */ - void setMinWidth( integer const & minWidth ); + void setMinWidth( size_t const & minWidth ); /** * @brief Draw the first part of the logPart. It include the title and optionnaly, the end description(s). * @param os An output stream (by default, std::cout) */ - void begin( std::ostream & os = std::cout ) const; + void begin( std::ostream & os = std::cout ); /** * @brief Draw the last part of the logPart. It include the title * @param oss An output stream (by default, std::cout) */ - void end( std::ostream & oss = std::cout ) const; + void end( std::ostream & oss = std::cout ); private: @@ -93,49 +78,52 @@ class LogPart * @param name The decription name * @param decriptionsValues The description values */ - void formatAndInsertDescriptions( std::vector< string > & formattedDescriptions, - string_view name, - std::vector< string > const & decriptionsValues ); + void formatDescriptions(); /** * @brief Constructs the string logPart title of the log part. - * @param title The title to be set */ - string buildTitlePart( string_view title ) const; + string buildTitlePart(); /** * @brief Constructs the string logPart descriptions of the log part. - * @param descriptions The description to be formatted */ - string buildDescriptionPart( std::vector< string > const & formattedDescriptions ) const; + string buildDescriptionPart(); - /// Vector containing all descriptions - std::vector< string > m_beginningDescs; - /// title of logPart - std::vector< string > m_endDescs; + /** + * @brief Clear all buffer + */ + void clear(); + + /// Vector containing formatted description + std::vector< string > m_formattedDescriptions; + /// Name of the description, formatted to be : [Name] : [Values1]\n[Values2] + std::vector< string > m_descriptionNames; + /// Values in the descrpption the description + std::vector< std::vector< string > > m_descriptionValues; /// title of logPart string m_logPartTitle; - /// Start title footer string + /// Title footer string string m_footerTitle; /// min width of logPart length - integer m_rowMinWidth = 70; + size_t m_rowMinWidth = 70; /// logPart length - integer m_logPartWidth; + size_t m_logPartWidth; /// description border margin - static constexpr integer m_marginBorder = 2; + static constexpr size_t m_borderMargin = 2; /// numbers of character used as border - static constexpr integer m_nbBorderChar = 2; + static constexpr size_t m_nbBorderChar = 2; /// character used for logPart construction - static constexpr integer m_borderCharacter = '#'; + static constexpr size_t m_borderCharacter = '#'; /// String containing horizontal border string m_horizontalBorder; }; template< typename ... Args > -void LogPart::addDescription( string_view name, Args const &... args ) +void LogPart::addDescription( string const & name, Args const &... args ) { std::vector< string > values; ( [&] { @@ -143,22 +131,10 @@ void LogPart::addDescription( string_view name, Args const &... args ) string const value = GEOS_FMT( "{}", args ); values.push_back( value ); } (), ...); - - formatAndInsertDescriptions( m_beginningDescs, name, values ); + m_descriptionNames.push_back( name ); + m_descriptionValues.push_back( values ); } -template< typename ... Args > -void LogPart::addEndDescription( string_view name, Args const &... args ) -{ - std::vector< string > values; - ( [&] { - static_assert( has_formatter_v< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); - string const value = GEOS_FMT( "{}", args ); - values.push_back( value ); - } (), ...); - - formatAndInsertDescriptions( m_endDescs, name, values ); -} } #endif diff --git a/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp b/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp index 0b4b5b99968..f3875df9512 100644 --- a/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp +++ b/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp @@ -33,7 +33,7 @@ TEST( testSection, sectionWithTitle ) logPart.end( oss ); EXPECT_EQ( oss.str(), - "\n## End of section name ##\n" + "\n## section name ##\n" "######################################################################\n\n" ); oss.clear(); @@ -74,7 +74,7 @@ TEST( testSection, sectionWithSetWidth ) logPart.end( oss ); EXPECT_EQ( oss.str(), - "\n## End of section name ##\n" + "\n## section name ##\n" "####################################################################################################\n\n" ); oss.clear(); @@ -84,26 +84,26 @@ TEST( testSection, sectionMultipleDescriptions ) { std::ostringstream oss; LogPart logPart( "TIMESTEP START" ); - logPart.addDescription( "Time", "00h08m20s out of 2d, 21h26m40s (0% completed)", "500 s / 250000 s" ); - logPart.addDescription( "Delta Time", "00h16m40s (1000 s)" ); - logPart.addDescription( "- Cycle: 1" ); + logPart.addDescription( "- Time :", "00h08m20s out of 2d, 21h26m40s (0% completed)", "500 s / 250000 s" ); + logPart.addDescription( "- Delta Time :", "00h16m40s (1000 s)" ); + logPart.addDescription( "Description test" ); logPart.setMinWidth( 70 ); logPart.begin( oss ); EXPECT_EQ ( oss.str(), "\n######################################################################\n" "## TIMESTEP START ##\n" "######################################################################\n" - "## - Time: 00h08m20s out of 2d, 21h26m40s (0% completed) ##\n" - "## 500 s / 250000 s ##\n" - "## - Delta Time: 00h16m40s (1000 s) ##\n" - "## - Cycle: 1 ##\n\n" + "## - Time : 00h08m20s out of 2d, 21h26m40s (0% completed) ##\n" + "## 500 s / 250000 s ##\n" + "## - Delta Time : 00h16m40s (1000 s) ##\n" + "## Description test ##\n\n" ); oss.clear(); oss.str( "" ); logPart.end( oss ); EXPECT_EQ( oss.str(), - "\n## End of TIMESTEP START ##\n" + "\n## TIMESTEP START ##\n" "######################################################################\n\n" ); oss.clear(); @@ -114,18 +114,18 @@ TEST( testSection, sectionEndDescription ) std::ostringstream oss; LogPart logPart( "TIMESTEP START" ); logPart.addDescription( "description" ); - logPart.addEndDescription( "test end description" ); logPart.setMinWidth( 70 ); logPart.begin( oss ); oss.clear(); oss.str( "" ); + logPart.addDescription( "test end description" ); logPart.end( oss ); EXPECT_EQ( oss.str(), "\n## test end description ##\n" "######################################################################\n" - "## End of TIMESTEP START ##\n" + "## TIMESTEP START ##\n" "######################################################################\n\n" ); oss.clear(); diff --git a/src/coreComponents/mainInterface/ProblemManager.cpp b/src/coreComponents/mainInterface/ProblemManager.cpp index 77fbd2a4c59..eea9df60f8b 100644 --- a/src/coreComponents/mainInterface/ProblemManager.cpp +++ b/src/coreComponents/mainInterface/ProblemManager.cpp @@ -178,14 +178,17 @@ void ProblemManager::problemSetup() LogPart nmLogPart( "NumericalMethods" ); nmLogPart.begin(); applyNumericalMethods(); + nmLogPart.end(); LogPart meshDataLogPart( "Mesh data registration :" ); meshDataLogPart.begin(); registerDataOnMeshRecursive( getDomainPartition().getMeshBodies() ); + meshDataLogPart.end(); LogPart grpLogPart( "Group & subgroups initialization" ); grpLogPart.begin(); initialize(); + grpLogPart.end(); importFields(); } From 11f157826731f39d0192c396b7afba92017acf18 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 22 Jan 2025 13:39:30 +0100 Subject: [PATCH 197/206] constness --- src/coreComponents/events/EventManager.cpp | 1 - src/coreComponents/fileIO/logPart/LogPart.cpp | 29 ++++++++++--------- .../mainInterface/ProblemManager.cpp | 21 ++++++-------- .../physicsSolvers/PhysicsSolverBase.cpp | 24 ++++++++++----- 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index b99ba609cde..4b2ca7b17fd 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -210,7 +210,6 @@ bool EventManager::run( DomainPartition & domain ) } } - logPart.end(); // Increment time/cycle, reset the subevent counter m_time += m_dt; ++m_cycle; diff --git a/src/coreComponents/fileIO/logPart/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp index 08b5707e272..0957c326304 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -45,9 +45,11 @@ void LogPart::setMinWidth( size_t const & minWidth ) void LogPart::formatDescriptions() { size_t maxNameSize = 1; + for( auto const & name : m_descriptionNames ) { - size_t idx = &name - &(*m_descriptionNames.begin()); + size_t const idx = &name - &(*m_descriptionNames.begin()); + if( !m_descriptionValues[idx].empty()) { maxNameSize = std::max( maxNameSize, name.size() ); @@ -55,30 +57,31 @@ void LogPart::formatDescriptions() } size_t const spacesFromBorder = m_borderMargin * 2 + m_nbBorderChar * 2; + for( size_t idxName = 0; idxName < m_descriptionNames.size(); idxName++ ) { + if( m_descriptionValues[idxName].empty()) { m_formattedDescriptions.push_back( m_descriptionNames[idxName] ); } else { - string name = m_descriptionNames[idxName]; - string spaces = string( maxNameSize - name.size(), ' ' ); - string nameFormatted = GEOS_FMT( "{}{} ", name, spaces ); + string_view name = m_descriptionNames[idxName]; + string_view spaces = std::string( maxNameSize - name.size(), ' ' ); + string_view nameFormatted = GEOS_FMT( "{}{} ", name, spaces ); m_formattedDescriptions.push_back( GEOS_FMT( "{}{}", nameFormatted, m_descriptionValues[idxName][0] )); - m_logPartWidth = m_formattedDescriptions[idxName].size() + spacesFromBorder; + m_logPartWidth = std::max( m_logPartWidth, m_formattedDescriptions[idxName].size() + spacesFromBorder ); for( size_t idxValue = 1; idxValue < m_descriptionValues[idxName].size(); idxValue++ ) { m_formattedDescriptions.push_back( GEOS_FMT( "{:>{}}", m_descriptionValues[idxName][idxValue], - nameFormatted.size() + m_descriptionValues[idxName][idxValue].size() )); + nameFormatted.size() + m_descriptionValues[idxName][idxValue].size() )); m_logPartWidth = std::max( m_logPartWidth, - m_formattedDescriptions[idxValue].size() + spacesFromBorder ); + m_formattedDescriptions.back().size() + spacesFromBorder ); } } - } m_logPartWidth = std::max( m_rowMinWidth, m_logPartWidth ); @@ -111,11 +114,11 @@ string LogPart::buildTitlePart() std::ostringstream oss; size_t const titleRowLength = m_logPartWidth - m_nbBorderChar * 2; string const borderCharacters = string( m_nbBorderChar, m_borderCharacter ); - oss << GEOS_FMT( "{}{:^{}}{}\n", - borderCharacters, - m_footerTitle, - titleRowLength, - borderCharacters ); + oss << GEOS_FMT( "{}{:^{}}{}\n", + borderCharacters, + m_footerTitle, + titleRowLength, + borderCharacters ); return oss.str(); } diff --git a/src/coreComponents/mainInterface/ProblemManager.cpp b/src/coreComponents/mainInterface/ProblemManager.cpp index 08461b262f7..22f30818b15 100644 --- a/src/coreComponents/mainInterface/ProblemManager.cpp +++ b/src/coreComponents/mainInterface/ProblemManager.cpp @@ -172,28 +172,25 @@ void ProblemManager::problemSetup() postInputInitializationRecursive(); - LogPart meshLogPart( "Mesh generation" ); - meshLogPart.begin(); + LogPart meshGenerationLog( "Mesh generation" ); + meshGenerationLog.begin(); generateMesh(); - meshLogPart.end(); + meshGenerationLog.end(); // initialize_postMeshGeneration(); - LogPart nmLogPart( "NumericalMethods" ); - nmLogPart.begin(); + LogPart numericalMethodLog( "Numerical Methods" ); + numericalMethodLog.begin(); applyNumericalMethods(); - nmLogPart.end(); + numericalMethodLog.end(); - LogPart meshDataLogPart( "Mesh data registration :" ); - meshDataLogPart.begin(); registerDataOnMeshRecursive( getDomainPartition().getMeshBodies() ); - meshDataLogPart.end(); - LogPart grpLogPart( "Group & subgroups initialization" ); - grpLogPart.begin(); initialize(); - grpLogPart.end(); + LogPart importFieldsLog( "Import fields" ); + importFieldsLog.begin(); importFields(); + importFieldsLog.end(); } diff --git a/src/coreComponents/physicsSolvers/PhysicsSolverBase.cpp b/src/coreComponents/physicsSolvers/PhysicsSolverBase.cpp index e0eefbde8c2..117f8153f58 100644 --- a/src/coreComponents/physicsSolvers/PhysicsSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/PhysicsSolverBase.cpp @@ -16,6 +16,7 @@ #include "PhysicsSolverBase.hpp" #include "PhysicsSolverManager.hpp" +#include "fileIO/logPart/LogPart.hpp" #include "common/TimingMacros.hpp" #include "linearAlgebra/solvers/KrylovSolver.hpp" #include "mesh/DomainPartition.hpp" @@ -350,18 +351,27 @@ void PhysicsSolverBase::logEndOfCycleInformation( integer const cycleNumber, integer const numOfSubSteps, std::vector< real64 > const & subStepDt ) const { - // The formating here is a work in progress. - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, "\n------------------------- TIMESTEP END -------------------------" ); - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( " - Cycle: {}", cycleNumber ) ); - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( " - N substeps: {}", numOfSubSteps ) ); - std::string logMessage = " - dt:"; + LogPart endTimeStep( "TIMESTEP END" ); + endTimeStep.addDescription( "- Cycle:", cycleNumber ); + endTimeStep.addDescription( "- N substeps:", numOfSubSteps ); + std::string logMessage; for( integer i = 0; i < numOfSubSteps; ++i ) { logMessage += " " + units::TimeFormatInfo::fromSeconds( subStepDt[i] ).toString(); } + endTimeStep.addDescription( "- dt:", logMessage ); + endTimeStep.end(); + + + // The formating here is a work in progress. + // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, "\n------------------------- TIMESTEP END -------------------------" ); + // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( " - Cycle: {}", cycleNumber ) ); + // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( " - N substeps: {}", numOfSubSteps ) ); + + // Log the complete message once - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, logMessage ); - GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, "------------------------------------------------------------------\n" ); + // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, logMessage ); + // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, "------------------------------------------------------------------\n" ); } real64 PhysicsSolverBase::setNextDt( real64 const & currentDt, From 32413aa9b82465bae88846636840a9d82596954d Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 22 Jan 2025 17:00:02 +0100 Subject: [PATCH 198/206] update logPart --- src/coreComponents/events/EventManager.cpp | 3 + src/coreComponents/fileIO/logPart/LogPart.cpp | 109 +++++++++--------- src/coreComponents/fileIO/logPart/LogPart.hpp | 85 +++++++++----- .../fileIO/logPart/unitTests/testLogPart.cpp | 11 +- 4 files changed, 122 insertions(+), 86 deletions(-) diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index 4b2ca7b17fd..e5ec1a1da54 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -210,6 +210,9 @@ bool EventManager::run( DomainPartition & domain ) } } + + + logPart.end(); // Increment time/cycle, reset the subevent counter m_time += m_dt; ++m_cycle; diff --git a/src/coreComponents/fileIO/logPart/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp index 0957c326304..63d54d79ce6 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -22,101 +22,105 @@ namespace geos { -LogPart::LogPart( string_view logPartTitle ): - m_logPartTitle( string( logPartTitle ) ), - m_logPartWidth( std::max((size_t)m_rowMinWidth, logPartTitle.length()) ) +LogPart::LogPart( string_view logPartTitle ) { - m_footerTitle = GEOS_FMT( "{}", m_logPartTitle ); + m_startDesc.m_logPartWidth = std::max((size_t)m_rowMinWidth, logPartTitle.length()); + m_endDesc.m_logPartWidth = std::max((size_t)m_rowMinWidth, logPartTitle.length()); + + m_startDesc.m_title = logPartTitle; + m_endDesc.m_title = GEOS_FMT( "{}{}", m_prefixEndTitle, logPartTitle ); } void LogPart::addDescription( string const & description ) { - m_descriptionNames.push_back( description ); - m_descriptionValues.push_back( std::vector< string >() ); + m_startDesc.m_descriptionNames.push_back( description ); + m_startDesc.m_descriptionValues.push_back( std::vector< string >() ); +} + +void LogPart::addEndDescription( string const & description ) +{ + m_endDesc.m_descriptionNames.push_back( description ); + m_endDesc.m_descriptionValues.push_back( std::vector< string >() ); } void LogPart::setMinWidth( size_t const & minWidth ) { m_rowMinWidth = minWidth; - m_logPartWidth = std::max( m_rowMinWidth, m_logPartWidth ); + m_startDesc.m_logPartWidth = std::max( m_rowMinWidth, m_startDesc.m_logPartWidth ); + m_endDesc.m_logPartWidth = std::max( m_rowMinWidth, m_endDesc.m_logPartWidth ); } -void LogPart::formatDescriptions() +void LogPart::formatDescriptions( LogPart::Description & description ) { size_t maxNameSize = 1; - - for( auto const & name : m_descriptionNames ) + std::vector< string > & descriptionName = description.m_descriptionNames; + std::vector< std::vector< string > > & descriptionValues = description.m_descriptionValues; + for( auto const & name : descriptionName ) { - size_t const idx = &name - &(*m_descriptionNames.begin()); + size_t const idx = &name - &(*descriptionName.begin()); - if( !m_descriptionValues[idx].empty()) + if( !descriptionValues[idx].empty()) { maxNameSize = std::max( maxNameSize, name.size() ); } } - size_t const spacesFromBorder = m_borderMargin * 2 + m_nbBorderChar * 2; - - for( size_t idxName = 0; idxName < m_descriptionNames.size(); idxName++ ) + std::vector< string > & formattedDescriptionLines = description.m_formattedDescriptionLines; + size_t logPartWidth = description.m_logPartWidth; + for( size_t idxName = 0; idxName < descriptionName.size(); idxName++ ) { - if( m_descriptionValues[idxName].empty()) + if( descriptionValues[idxName].empty()) { - m_formattedDescriptions.push_back( m_descriptionNames[idxName] ); + formattedDescriptionLines.push_back( descriptionName[idxName] ); } else { - string_view name = m_descriptionNames[idxName]; - string_view spaces = std::string( maxNameSize - name.size(), ' ' ); - string_view nameFormatted = GEOS_FMT( "{}{} ", name, spaces ); + string const name = descriptionName[idxName]; + // +1 for extra space in case of delimiter ":" + string const spaces = std::string( maxNameSize - name.size() + 1, ' ' ); + string const nameFormatted = GEOS_FMT( "{}{}", name, spaces ); - m_formattedDescriptions.push_back( GEOS_FMT( "{}{}", nameFormatted, m_descriptionValues[idxName][0] )); - m_logPartWidth = std::max( m_logPartWidth, m_formattedDescriptions[idxName].size() + spacesFromBorder ); + formattedDescriptionLines.push_back( GEOS_FMT( "{}{}", nameFormatted, descriptionValues[idxName][0] )); + logPartWidth = std::max( logPartWidth, formattedDescriptionLines[idxName].size() ); - for( size_t idxValue = 1; idxValue < m_descriptionValues[idxName].size(); idxValue++ ) + for( size_t idxValue = 1; idxValue < descriptionValues[idxName].size(); idxValue++ ) { - m_formattedDescriptions.push_back( GEOS_FMT( "{:>{}}", m_descriptionValues[idxName][idxValue], - nameFormatted.size() + m_descriptionValues[idxName][idxValue].size() )); - m_logPartWidth = std::max( m_logPartWidth, - m_formattedDescriptions.back().size() + spacesFromBorder ); + formattedDescriptionLines.push_back( + GEOS_FMT( "{:>{}}", descriptionValues[idxName][idxValue], + nameFormatted.size() + descriptionValues[idxName][idxValue].size() )); + logPartWidth = std::max( logPartWidth, formattedDescriptionLines.back().size() ); } } } - m_logPartWidth = std::max( m_rowMinWidth, m_logPartWidth ); + logPartWidth = std::max( m_rowMinWidth, logPartWidth ); } -string LogPart::buildDescriptionPart() +string LogPart::buildDescriptionPart( LogPart::Description const & description ) { std::ostringstream oss; - for( auto const & description : m_formattedDescriptions ) + for( auto const & formattedDescription : description.m_formattedDescriptionLines ) { // length of white space to add after the formatted description - size_t const remainingLength = m_logPartWidth - m_nbBorderChar * 2 - m_borderMargin; + size_t const remainingLength = description.m_logPartWidth - m_nbBorderChar * 2 - m_borderMargin; string const borderCharacters = string( m_nbBorderChar, m_borderCharacter ); oss << borderCharacters; - oss << GEOS_FMT( "{:<{}}{:<{}}", " ", m_borderMargin, description, remainingLength ); + oss << GEOS_FMT( "{:<{}}{:<{}}", " ", m_borderMargin, formattedDescription, remainingLength ); oss << borderCharacters << '\n'; } return oss.str(); } -void LogPart::clear() -{ - m_formattedDescriptions.clear(); - m_descriptionNames.clear(); - m_descriptionValues.clear(); -} - -string LogPart::buildTitlePart() +string LogPart::buildTitlePart( LogPart::Description const & description ) { std::ostringstream oss; - size_t const titleRowLength = m_logPartWidth - m_nbBorderChar * 2; + size_t const titleRowLength = description.m_logPartWidth - m_nbBorderChar * 2; string const borderCharacters = string( m_nbBorderChar, m_borderCharacter ); oss << GEOS_FMT( "{}{:^{}}{}\n", borderCharacters, - m_footerTitle, + description.m_title, titleRowLength, borderCharacters ); return oss.str(); @@ -125,32 +129,31 @@ string LogPart::buildTitlePart() void LogPart::begin( std::ostream & os ) { string bottomPart = ""; - if( !m_descriptionNames.empty()) + if( !m_startDesc.m_descriptionNames.empty()) { - formatDescriptions(); + formatDescriptions( m_startDesc ); } - bottomPart = buildDescriptionPart(); + bottomPart = buildDescriptionPart( m_startDesc ); - string const line = string( m_logPartWidth, m_borderCharacter ); + string const line = string( m_startDesc.m_logPartWidth, m_borderCharacter ); string const topPart = GEOS_FMT( "{}\n{}{}\n", line, - buildTitlePart(), + buildTitlePart( m_startDesc ), line ); os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); - clear(); } void LogPart::end( std::ostream & os ) { string topPart = ""; - string const line = string( m_logPartWidth, m_borderCharacter ); - if( !m_descriptionNames.empty() ) + string const line = string( m_endDesc.m_logPartWidth, m_borderCharacter ); + if( !m_endDesc.m_descriptionNames.empty() ) { - formatDescriptions(); - topPart = GEOS_FMT( "{}{}\n", buildDescriptionPart(), line ); + formatDescriptions( m_endDesc ); + topPart = GEOS_FMT( "{}{}\n", buildDescriptionPart( m_endDesc ), line ); } - string const bottomPart = GEOS_FMT( "{}{}\n", buildTitlePart(), line ); + string const bottomPart = GEOS_FMT( "{}{}\n", buildTitlePart( m_endDesc ), line ); os << GEOS_FMT( "\n{}{}\n", topPart, bottomPart ); } diff --git a/src/coreComponents/fileIO/logPart/LogPart.hpp b/src/coreComponents/fileIO/logPart/LogPart.hpp index 5aab86ef594..20969d25fd0 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.hpp +++ b/src/coreComponents/fileIO/logPart/LogPart.hpp @@ -26,7 +26,7 @@ namespace geos { /** - * @brief Class for displaying different steps of simulation + * @brief Class for displaying section for different steps of simulation */ class LogPart { @@ -39,20 +39,35 @@ class LogPart LogPart( string_view m_logPartTitle ); /** - * @brief Add a description to the logPart by concatening a description name and descriptions values. + * @brief Add a description to the opening logPart by concatening a description name and descriptions values. * @param name The description name * @param args Descriptions values to be concatened. - * Descriptions values can be be any types and will be aligned + * @note Descriptions values can be be any formatted types. Values will be aligned altogether. */ template< typename ... Args > void addDescription( string const & name, Args const & ... args ); /** - * @brief Add a description to the logPart + * @brief Add a description to the opening logPart * @param description The string value of the description */ void addDescription( string const & description ); + /** + * @brief Add a description to the closing logPart by concatening a description name and descriptions values. + * @param name The description name + * @param args Descriptions values to be concatened. + * @note Descriptions values can be be any formatted types. Values will be aligned altogether. + */ + template< typename ... Args > + void addEndDescription( string const & name, Args const & ... args ); + + /** + * @brief Add a description to the closing logPart + * @param description The string value of the description + */ + void addEndDescription( string const & description ); + /** * @brief Set the minimal width of a row * @param minWidth The minimal width of the table @@ -73,43 +88,45 @@ class LogPart private: + struct Description + { + /// Title footer string + string m_title; + + /// Name of the description, formatted to be : [Name] : [Values1]\n[Values2] + std::vector< string > m_descriptionNames; + /// Values in the descrpption the description + std::vector< std::vector< string > > m_descriptionValues; + /// Vector containing the descriptions formatted by formatDescriptions() + std::vector< string > m_formattedDescriptionLines; + + /// logPart length + size_t m_logPartWidth; + }; + /** * @brief Build a description from the name and description values * @param name The decription name * @param decriptionsValues The description values */ - void formatDescriptions(); + void formatDescriptions( LogPart::Description & description ); /** * @brief Constructs the string logPart title of the log part. */ - string buildTitlePart(); + string buildTitlePart( LogPart::Description const & description ); /** * @brief Constructs the string logPart descriptions of the log part. */ - string buildDescriptionPart(); + string buildDescriptionPart( LogPart::Description const & description ); - /** - * @brief Clear all buffer - */ - void clear(); - - /// Vector containing formatted description - std::vector< string > m_formattedDescriptions; - /// Name of the description, formatted to be : [Name] : [Values1]\n[Values2] - std::vector< string > m_descriptionNames; - /// Values in the descrpption the description - std::vector< std::vector< string > > m_descriptionValues; - - /// title of logPart - string m_logPartTitle; - /// Title footer string - string m_footerTitle; + string const m_prefixEndTitle = "End of "; /// min width of logPart length size_t m_rowMinWidth = 70; - /// logPart length - size_t m_logPartWidth; + + Description m_startDesc = { "", {}, {}, {}, m_rowMinWidth}; + Description m_endDesc = { "", {}, {}, {}, m_rowMinWidth}; /// description border margin static constexpr size_t m_borderMargin = 2; @@ -131,8 +148,22 @@ void LogPart::addDescription( string const & name, Args const &... args ) string const value = GEOS_FMT( "{}", args ); values.push_back( value ); } (), ...); - m_descriptionNames.push_back( name ); - m_descriptionValues.push_back( values ); + m_startDesc.m_descriptionNames.push_back( name ); + m_startDesc.m_descriptionValues.push_back( values ); +} + +template< typename ... Args > +void LogPart::addEndDescription( string const & name, Args const &... args ) +{ + std::vector< string > values; + ( [&] { + static_assert( has_formatter_v< decltype(args) >, "Argument passed in addRow cannot be converted to string" ); + string const value = GEOS_FMT( "{}", args ); + values.push_back( value ); + } (), ...); + + m_endDesc.m_descriptionNames.push_back( name ); + m_endDesc.m_descriptionValues.push_back( values ); } } diff --git a/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp b/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp index f3875df9512..2fc945a1e50 100644 --- a/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp +++ b/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp @@ -33,7 +33,7 @@ TEST( testSection, sectionWithTitle ) logPart.end( oss ); EXPECT_EQ( oss.str(), - "\n## section name ##\n" + "\n## End of section name ##\n" "######################################################################\n\n" ); oss.clear(); @@ -74,7 +74,7 @@ TEST( testSection, sectionWithSetWidth ) logPart.end( oss ); EXPECT_EQ( oss.str(), - "\n## section name ##\n" + "\n## End of section name ##\n" "####################################################################################################\n\n" ); oss.clear(); @@ -103,7 +103,7 @@ TEST( testSection, sectionMultipleDescriptions ) logPart.end( oss ); EXPECT_EQ( oss.str(), - "\n## TIMESTEP START ##\n" + "\n## End of TIMESTEP START ##\n" "######################################################################\n\n" ); oss.clear(); @@ -113,19 +113,18 @@ TEST( testSection, sectionEndDescription ) { std::ostringstream oss; LogPart logPart( "TIMESTEP START" ); - logPart.addDescription( "description" ); + logPart.addEndDescription( "test end description" ); logPart.setMinWidth( 70 ); logPart.begin( oss ); oss.clear(); oss.str( "" ); - logPart.addDescription( "test end description" ); logPart.end( oss ); EXPECT_EQ( oss.str(), "\n## test end description ##\n" "######################################################################\n" - "## TIMESTEP START ##\n" + "## End of TIMESTEP START ##\n" "######################################################################\n\n" ); oss.clear(); From 319da206fa789e950fc986a9fb335bcc26ffc106 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 22 Jan 2025 17:02:14 +0100 Subject: [PATCH 199/206] uncrustify :) --- src/coreComponents/events/EventManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index e5ec1a1da54..f286be366b4 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -210,7 +210,7 @@ bool EventManager::run( DomainPartition & domain ) } } - + logPart.end(); // Increment time/cycle, reset the subevent counter From 30f908635d3d3d903ca0b2a809712e77d1617142 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 22 Jan 2025 17:20:40 +0100 Subject: [PATCH 200/206] clean up --- src/coreComponents/fileIO/logPart/LogPart.cpp | 2 -- src/coreComponents/fileIO/logPart/LogPart.hpp | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreComponents/fileIO/logPart/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp index 63d54d79ce6..6eddf58602c 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -94,8 +94,6 @@ void LogPart::formatDescriptions( LogPart::Description & description ) } } } - - logPartWidth = std::max( m_rowMinWidth, logPartWidth ); } string LogPart::buildDescriptionPart( LogPart::Description const & description ) diff --git a/src/coreComponents/fileIO/logPart/LogPart.hpp b/src/coreComponents/fileIO/logPart/LogPart.hpp index 20969d25fd0..10f022b324f 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.hpp +++ b/src/coreComponents/fileIO/logPart/LogPart.hpp @@ -144,7 +144,8 @@ void LogPart::addDescription( string const & name, Args const &... args ) { std::vector< string > values; ( [&] { - static_assert( has_formatter_v< 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 value = GEOS_FMT( "{}", args ); values.push_back( value ); } (), ...); @@ -157,7 +158,8 @@ void LogPart::addEndDescription( string const & name, Args const &... args ) { std::vector< string > values; ( [&] { - static_assert( has_formatter_v< 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 value = GEOS_FMT( "{}", args ); values.push_back( value ); } (), ...); From 23950f78a177dab8073ec9a5b327edac27d8d717 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 22 Jan 2025 17:21:53 +0100 Subject: [PATCH 201/206] doxygen --- src/coreComponents/fileIO/logPart/LogPart.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/coreComponents/fileIO/logPart/LogPart.hpp b/src/coreComponents/fileIO/logPart/LogPart.hpp index 10f022b324f..0ef47266201 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.hpp +++ b/src/coreComponents/fileIO/logPart/LogPart.hpp @@ -121,7 +121,9 @@ class LogPart */ string buildDescriptionPart( LogPart::Description const & description ); + /// prefix to append to the title of closing section string const m_prefixEndTitle = "End of "; + /// min width of logPart length size_t m_rowMinWidth = 70; From 877c64e3b8a25d3b4b12478808b3fe15e66274a3 Mon Sep 17 00:00:00 2001 From: arng40 Date: Fri, 24 Jan 2025 17:32:31 +0100 Subject: [PATCH 202/206] first attempt to relocate log end timestep --- .../dataRepository/ExecutableGroup.hpp | 14 +++++++ src/coreComponents/events/EventBase.cpp | 1 - src/coreComponents/events/EventBase.hpp | 19 +++++---- src/coreComponents/events/EventManager.cpp | 41 ++++++++++++++++++- src/coreComponents/events/EventManager.hpp | 5 +++ .../physicsSolvers/PhysicsSolverBase.cpp | 37 +++-------------- .../physicsSolvers/PhysicsSolverBase.hpp | 11 ----- 7 files changed, 75 insertions(+), 53 deletions(-) diff --git a/src/coreComponents/dataRepository/ExecutableGroup.hpp b/src/coreComponents/dataRepository/ExecutableGroup.hpp index b1751f3e1f0..c7e9923a0f9 100644 --- a/src/coreComponents/dataRepository/ExecutableGroup.hpp +++ b/src/coreComponents/dataRepository/ExecutableGroup.hpp @@ -119,8 +119,22 @@ class ExecutableGroup : public dataRepository::Group */ TimesteppingBehavior getTimesteppingBehavior() const { return m_timesteppingBehavior; } + std::vector< real64 > const & getSubStepDt() const { return m_subStepDt; } + + std::vector< real64 > & getSubStepDt() { return m_subStepDt; } + + integer const & getNumOfSubSteps() const { return m_numOfSubSteps; } + + integer & getNumOfSubSteps() { return m_numOfSubSteps; } + + void setNumOfSubSteps( integer nbStep ) { m_numOfSubSteps = nbStep;} + private: + std::vector< real64 > m_subStepDt = {}; + + integer m_numOfSubSteps = 0; + TimesteppingBehavior m_timesteppingBehavior = TimesteppingBehavior::DoesNotDetermineTimeStepSize; }; diff --git a/src/coreComponents/events/EventBase.cpp b/src/coreComponents/events/EventBase.cpp index 52b3c386c2d..bed4a034585 100644 --- a/src/coreComponents/events/EventBase.cpp +++ b/src/coreComponents/events/EventBase.cpp @@ -361,7 +361,6 @@ void EventBase::getExecutionOrder( array1d< integer > & eventCounters ) } ); } - void EventBase::setProgressIndicator( array1d< integer > & eventCounters ) { // Calculate the event progress indicator diff --git a/src/coreComponents/events/EventBase.hpp b/src/coreComponents/events/EventBase.hpp index c3e4920b188..8cf84ce7aae 100644 --- a/src/coreComponents/events/EventBase.hpp +++ b/src/coreComponents/events/EventBase.hpp @@ -167,6 +167,11 @@ class EventBase : public ExecutableGroup */ void getExecutionOrder( array1d< integer > & eventCounters ); + std::vector< real64 > const & getSubStepDt() const { return m_target->getSubStepDt(); } + + integer const & getNumOfSubSteps() const { return m_target->getNumOfSubSteps(); } + + /** * @brief Update the event progress for the event/sub-events. * @note This method is used to determine how to handle the timestamp for an event @@ -270,6 +275,13 @@ class EventBase : public ExecutableGroup return m_eventTarget; } + /** + * @brief Get the target of this event. + * @return The target of this event. + */ + ExecutableGroup * getEventTarget() const + { return m_target; } + protected: /** @@ -301,13 +313,6 @@ class EventBase : public ExecutableGroup void setForecast( integer forecast ) { m_eventForecast = forecast; } - /** - * @brief Get the target of this event. - * @return The target of this event. - */ - ExecutableGroup * getEventTarget() const - { return m_target; } - /** * @brief Is the event active? * @param time The time at which we want to check if the event is active. diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index f286be366b4..609da79feee 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -174,7 +174,8 @@ bool EventManager::run( DomainPartition & domain ) LogPart logPart( "TIMESTEP" ); outputTime( logPart ); logPart.begin(); - + std::vector< real64 > subStepDt; + integer numTimeSteps = 0; // Execute for(; m_currentSubEventnumSubGroups(); ++m_currentSubEvent ) { @@ -189,6 +190,7 @@ bool EventManager::run( DomainPartition & domain ) // Execute, signal events bool earlyReturn = false; + std::cout << " pp d" << subEvent->getEventTarget()->getTimesteppingBehavior()<hasToPrepareForExec() ) { subEvent->signalToPrepareForExecution( m_time, m_dt, m_cycle, domain ); @@ -196,6 +198,14 @@ bool EventManager::run( DomainPartition & domain ) else if( subEvent->isReadyForExec() ) { earlyReturn = subEvent->execute( m_time, m_dt, m_cycle, 0, 0, domain ); + + if( subEvent->getEventTarget()->getTimesteppingBehavior() == ExecutableGroup::TimesteppingBehavior::DeterminesTimeStepSize ) + { + + subStepDt = subEvent->getSubStepDt(); + numTimeSteps = subEvent->getNumOfSubSteps(); + } + } // Check the exit flag @@ -211,8 +221,8 @@ bool EventManager::run( DomainPartition & domain ) } + logEndOfCycleInformation( logPart, m_cycle, numTimeSteps, subStepDt ); - logPart.end(); // Increment time/cycle, reset the subevent counter m_time += m_dt; ++m_cycle; @@ -298,4 +308,31 @@ void EventManager::outputTime( LogPart & logPart ) const } } +void EventManager::logEndOfCycleInformation( LogPart & logpart, + integer const cycleNumber, + integer const numOfSubSteps, + std::vector< real64 > const & subStepDt ) const +{ + logpart.addEndDescription( "- Cycle:", cycleNumber ); + logpart.addEndDescription( "- N substeps:", numOfSubSteps ); + std::string logMessage; + for( integer i = 0; i < numOfSubSteps; ++i ) + { + logMessage += " " + units::TimeFormatInfo::fromSeconds( subStepDt[i] ).toString(); + } + logpart.addEndDescription( "- dt:", logMessage ); + logpart.end(); + + + // The formating here is a work in progress. + // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, "\n------------------------- TIMESTEP END -------------------------" ); + // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( " - Cycle: {}", cycleNumber ) ); + // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( " - N substeps: {}", numOfSubSteps ) ); + + + // Log the complete message once + // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, logMessage ); + // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, "------------------------------------------------------------------\n" ); +} + } /* namespace geos */ diff --git a/src/coreComponents/events/EventManager.hpp b/src/coreComponents/events/EventManager.hpp index 872d26a5692..7e32e2f65d4 100644 --- a/src/coreComponents/events/EventManager.hpp +++ b/src/coreComponents/events/EventManager.hpp @@ -137,6 +137,11 @@ class EventManager : public dataRepository::Group */ void outputTime( LogPart & section ) const; + void logEndOfCycleInformation( LogPart & logpart, + integer const cycleNumber, + integer const numOfSubSteps, + std::vector< real64 > const & subStepDt ) const; + /// Min time for a simulation real64 m_minTime; diff --git a/src/coreComponents/physicsSolvers/PhysicsSolverBase.cpp b/src/coreComponents/physicsSolvers/PhysicsSolverBase.cpp index 117f8153f58..d9857b3dcdd 100644 --- a/src/coreComponents/physicsSolvers/PhysicsSolverBase.cpp +++ b/src/coreComponents/physicsSolvers/PhysicsSolverBase.cpp @@ -277,8 +277,10 @@ bool PhysicsSolverBase::execute( real64 const time_n, integer const maxSubSteps = m_nonlinearSolverParameters.m_maxSubSteps; // Keep track of substeps. It is useful to output these. - std::vector< real64 > subStepDt( maxSubSteps, 0.0 ); - integer numOfSubSteps = 0; + std::vector< real64 > & subStepDt = getSubStepDt(); + subStepDt.resize( maxSubSteps, 0.0 ); + + setNumOfSubSteps( 0 ); for( integer subStep = 0; subStep < maxSubSteps && dtRemaining > 0.0; ++subStep ) { @@ -289,7 +291,7 @@ bool PhysicsSolverBase::execute( real64 const time_n, nextDt, cycleNumber, domain ); - numOfSubSteps++; + getNumOfSubSteps()++; subStepDt[subStep] = dtAccepted; // increment the cumulative number of nonlinear and linear iterations @@ -342,38 +344,9 @@ bool PhysicsSolverBase::execute( real64 const time_n, m_numTimestepsSinceLastDtCut++; } - logEndOfCycleInformation( cycleNumber, numOfSubSteps, subStepDt ); - return false; } -void PhysicsSolverBase::logEndOfCycleInformation( integer const cycleNumber, - integer const numOfSubSteps, - std::vector< real64 > const & subStepDt ) const -{ - LogPart endTimeStep( "TIMESTEP END" ); - endTimeStep.addDescription( "- Cycle:", cycleNumber ); - endTimeStep.addDescription( "- N substeps:", numOfSubSteps ); - std::string logMessage; - for( integer i = 0; i < numOfSubSteps; ++i ) - { - logMessage += " " + units::TimeFormatInfo::fromSeconds( subStepDt[i] ).toString(); - } - endTimeStep.addDescription( "- dt:", logMessage ); - endTimeStep.end(); - - - // The formating here is a work in progress. - // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, "\n------------------------- TIMESTEP END -------------------------" ); - // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( " - Cycle: {}", cycleNumber ) ); - // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( " - N substeps: {}", numOfSubSteps ) ); - - - // Log the complete message once - // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, logMessage ); - // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, "------------------------------------------------------------------\n" ); -} - real64 PhysicsSolverBase::setNextDt( real64 const & currentDt, DomainPartition & domain ) { diff --git a/src/coreComponents/physicsSolvers/PhysicsSolverBase.hpp b/src/coreComponents/physicsSolvers/PhysicsSolverBase.hpp index 95a87f1a87f..5ac6a394f90 100644 --- a/src/coreComponents/physicsSolvers/PhysicsSolverBase.hpp +++ b/src/coreComponents/physicsSolvers/PhysicsSolverBase.hpp @@ -1076,17 +1076,6 @@ class PhysicsSolverBase : public ExecutableGroup real64 const & dt, integer const cycleNumber, DomainPartition & domain ); - - /** - * @brief output information about the cycle to the log - * @param cycleNumber the current cycle number - * @param numOfSubSteps the number of substeps taken - * @param subStepDt the time step size for each substep - */ - void logEndOfCycleInformation( integer const cycleNumber, - integer const numOfSubSteps, - std::vector< real64 > const & subStepDt ) const; - }; template< typename CONSTITUTIVE_BASE_TYPE > From 143322fc2aa06bd421a0898ed4e72726b3805e71 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 27 Jan 2025 17:09:58 +0100 Subject: [PATCH 203/206] =?UTF-8?q?=F0=9F=8E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/coreComponents/events/EventManager.cpp | 25 ++--- src/coreComponents/fileIO/logPart/LogPart.cpp | 96 ++++++++++++++++--- src/coreComponents/fileIO/logPart/LogPart.hpp | 22 +++-- 3 files changed, 108 insertions(+), 35 deletions(-) diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index 609da79feee..221bb97071b 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -315,24 +315,19 @@ void EventManager::logEndOfCycleInformation( LogPart & logpart, { logpart.addEndDescription( "- Cycle:", cycleNumber ); logpart.addEndDescription( "- N substeps:", numOfSubSteps ); - std::string logMessage; - for( integer i = 0; i < numOfSubSteps; ++i ) + std::stringstream logMessage; + std::cout << units::TimeFormatInfo::fromSeconds( subStepDt[0] ).toString() << std::endl; + for( integer i = 0; i < 25; ++i ) { - logMessage += " " + units::TimeFormatInfo::fromSeconds( subStepDt[i] ).toString(); + if (i > 0) + { + logMessage << ", "; + } + logMessage << "00h00m01s (1 s)"; } - logpart.addEndDescription( "- dt:", logMessage ); + logpart.addEndDescription( "- dt:", logMessage.str() ); + logpart.setMaxWidth( 100 );//todo min > max logpart.end(); - - - // The formating here is a work in progress. - // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, "\n------------------------- TIMESTEP END -------------------------" ); - // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( " - Cycle: {}", cycleNumber ) ); - // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, GEOS_FMT( " - N substeps: {}", numOfSubSteps ) ); - - - // Log the complete message once - // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, logMessage ); - // GEOS_LOG_LEVEL_INFO_RANK_0( logInfo::TimeStep, "------------------------------------------------------------------\n" ); } } /* namespace geos */ diff --git a/src/coreComponents/fileIO/logPart/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp index 6eddf58602c..87404c37d08 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -34,13 +34,13 @@ LogPart::LogPart( string_view logPartTitle ) void LogPart::addDescription( string const & description ) { m_startDesc.m_descriptionNames.push_back( description ); - m_startDesc.m_descriptionValues.push_back( std::vector< string >() ); + m_startDesc.m_descriptionsValues.push_back( std::vector< string >() ); } void LogPart::addEndDescription( string const & description ) { m_endDesc.m_descriptionNames.push_back( description ); - m_endDesc.m_descriptionValues.push_back( std::vector< string >() ); + m_endDesc.m_descriptionsValues.push_back( std::vector< string >() ); } @@ -51,45 +51,115 @@ void LogPart::setMinWidth( size_t const & minWidth ) m_endDesc.m_logPartWidth = std::max( m_rowMinWidth, m_endDesc.m_logPartWidth ); } +void LogPart::setMaxWidth( size_t const & maxWidth ) +{ + m_startDesc.m_logPartMaxWidth = std::min( maxWidth, m_startDesc.m_logPartMaxWidth ); + m_endDesc.m_logPartMaxWidth = std::min( maxWidth, m_endDesc.m_logPartMaxWidth ); +} + +std::vector< string > splitAndFormatStringByDelimiter( string & description, size_t maxLength, char delimiter = ',' ) +{ + std::vector< string > formattedDescription; + size_t idxBeginCapture = 0; + size_t idxEndCapture = 0; + std::vector< std::string > descriptions; + std::stringstream currLine; + for( auto strIt = description.begin(); strIt != description.end(); ++strIt ) + { + if( *strIt == delimiter ) + { + size_t const dist = std::distance( description.begin(), strIt ) + 1; + idxEndCapture = dist - idxEndCapture; + if( dist > maxLength ) + { + formattedDescription.push_back( currLine.str() ); + currLine.str( "" ); + } + currLine << description.substr( idxBeginCapture, idxEndCapture ); + idxBeginCapture = dist; + } + } + formattedDescription.push_back( description.substr( idxBeginCapture ) ); + + return formattedDescription; +} + void LogPart::formatDescriptions( LogPart::Description & description ) { size_t maxNameSize = 1; std::vector< string > & descriptionName = description.m_descriptionNames; - std::vector< std::vector< string > > & descriptionValues = description.m_descriptionValues; + std::vector< std::vector< string > > & m_descriptionsValues = description.m_descriptionsValues; + for( auto const & name : descriptionName ) { size_t const idx = &name - &(*descriptionName.begin()); - if( !descriptionValues[idx].empty()) + if( !m_descriptionsValues[idx].empty()) { maxNameSize = std::max( maxNameSize, name.size() ); } } std::vector< string > & formattedDescriptionLines = description.m_formattedDescriptionLines; - size_t logPartWidth = description.m_logPartWidth; + size_t & logPartWidth = description.m_logPartWidth; + size_t & logPartMaxWidth = description.m_logPartMaxWidth; for( size_t idxName = 0; idxName < descriptionName.size(); idxName++ ) { + string & name = descriptionName[idxName]; + std::vector< string > & values = m_descriptionsValues[idxName]; - if( descriptionValues[idxName].empty()) + if( values.empty()) { - formattedDescriptionLines.push_back( descriptionName[idxName] ); + if( name.size() > logPartMaxWidth ) + { + std::vector< string > formattedName = splitAndFormatStringByDelimiter( name, logPartMaxWidth ); + for( auto const & format : formattedName ) + { + formattedDescriptionLines.push_back( format ); + } + } + else + { + formattedDescriptionLines.push_back( name ); + } } else { - string const name = descriptionName[idxName]; // +1 for extra space in case of delimiter ":" string const spaces = std::string( maxNameSize - name.size() + 1, ' ' ); - string const nameFormatted = GEOS_FMT( "{}{}", name, spaces ); + string const formattedName = GEOS_FMT( "{}{}", name, spaces ); + + string firstValue = values[0]; + + if( formattedName.size() + firstValue.size() > logPartMaxWidth ) + { + std::vector< string > formattedDescription = + splitAndFormatStringByDelimiter( firstValue, logPartMaxWidth - formattedName.size()); + for( auto const & format : formattedDescription ) + { + if( &format == &formattedDescription.front()) + { + + formattedDescriptionLines.push_back( GEOS_FMT( "{}{}", formattedName, format )); + } + else + { + formattedDescriptionLines.push_back( + GEOS_FMT( "{:>{}}", format, formattedName.size() + format.size() )); + } + } + } + else + { + formattedDescriptionLines.push_back( GEOS_FMT( "{}{}", formattedName, firstValue )); + } - formattedDescriptionLines.push_back( GEOS_FMT( "{}{}", nameFormatted, descriptionValues[idxName][0] )); logPartWidth = std::max( logPartWidth, formattedDescriptionLines[idxName].size() ); - for( size_t idxValue = 1; idxValue < descriptionValues[idxName].size(); idxValue++ ) + for( size_t idxValue = 1; idxValue < values.size(); idxValue++ ) { formattedDescriptionLines.push_back( - GEOS_FMT( "{:>{}}", descriptionValues[idxName][idxValue], - nameFormatted.size() + descriptionValues[idxName][idxValue].size() )); + GEOS_FMT( "{:>{}}", values[idxValue], formattedName.size() + values[idxValue].size() )); logPartWidth = std::max( logPartWidth, formattedDescriptionLines.back().size() ); } } diff --git a/src/coreComponents/fileIO/logPart/LogPart.hpp b/src/coreComponents/fileIO/logPart/LogPart.hpp index 0ef47266201..640cfc993b5 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.hpp +++ b/src/coreComponents/fileIO/logPart/LogPart.hpp @@ -74,6 +74,12 @@ class LogPart */ void setMinWidth( size_t const & minWidth ); + /** + * @brief Set the minimal width of a row + * @param minWidth The minimal width of the table + */ + void setMaxWidth( size_t const & maxWidth ); + /** * @brief Draw the first part of the logPart. It include the title and optionnaly, the end description(s). * @param os An output stream (by default, std::cout) @@ -95,13 +101,15 @@ class LogPart /// Name of the description, formatted to be : [Name] : [Values1]\n[Values2] std::vector< string > m_descriptionNames; - /// Values in the descrpption the description - std::vector< std::vector< string > > m_descriptionValues; + /// Values in the description + std::vector< std::vector< string > > m_descriptionsValues; /// Vector containing the descriptions formatted by formatDescriptions() std::vector< string > m_formattedDescriptionLines; /// logPart length size_t m_logPartWidth; + /// logPart length + size_t m_logPartMaxWidth; }; /** @@ -125,10 +133,10 @@ class LogPart string const m_prefixEndTitle = "End of "; /// min width of logPart length - size_t m_rowMinWidth = 70; + size_t m_rowMinWidth = 50; - Description m_startDesc = { "", {}, {}, {}, m_rowMinWidth}; - Description m_endDesc = { "", {}, {}, {}, m_rowMinWidth}; + Description m_startDesc = { "", {}, {}, {}, m_rowMinWidth, SIZE_MAX}; + Description m_endDesc = { "", {}, {}, {}, m_rowMinWidth, SIZE_MAX }; /// description border margin static constexpr size_t m_borderMargin = 2; @@ -152,7 +160,7 @@ void LogPart::addDescription( string const & name, Args const &... args ) values.push_back( value ); } (), ...); m_startDesc.m_descriptionNames.push_back( name ); - m_startDesc.m_descriptionValues.push_back( values ); + m_startDesc.m_descriptionsValues.push_back( values ); } template< typename ... Args > @@ -167,7 +175,7 @@ void LogPart::addEndDescription( string const & name, Args const &... args ) } (), ...); m_endDesc.m_descriptionNames.push_back( name ); - m_endDesc.m_descriptionValues.push_back( values ); + m_endDesc.m_descriptionsValues.push_back( values ); } } From 192f28bddc08c52356aa5a143b0ae4a1962ea9c9 Mon Sep 17 00:00:00 2001 From: arng40 Date: Mon, 27 Jan 2025 18:01:40 +0100 Subject: [PATCH 204/206] automatic lr, 1st pass --- src/coreComponents/fileIO/logPart/LogPart.cpp | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/coreComponents/fileIO/logPart/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp index 87404c37d08..3b6e9940ebc 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -61,22 +61,28 @@ std::vector< string > splitAndFormatStringByDelimiter( string & description, siz { std::vector< string > formattedDescription; size_t idxBeginCapture = 0; - size_t idxEndCapture = 0; - std::vector< std::string > descriptions; + size_t limitCharTracker = 0; std::stringstream currLine; + size_t prevIdxChar = 0; for( auto strIt = description.begin(); strIt != description.end(); ++strIt ) { if( *strIt == delimiter ) { - size_t const dist = std::distance( description.begin(), strIt ) + 1; - idxEndCapture = dist - idxEndCapture; - if( dist > maxLength ) + size_t const idxChar = std::distance( description.begin(), strIt ) + 1; + + limitCharTracker += (idxChar - idxBeginCapture); + size_t captureLength = idxChar - prevIdxChar; + + currLine << description.substr( idxBeginCapture, captureLength ); + + idxBeginCapture = idxChar; + prevIdxChar = idxChar; + if( limitCharTracker > maxLength ) { formattedDescription.push_back( currLine.str() ); currLine.str( "" ); + limitCharTracker = 0; } - currLine << description.substr( idxBeginCapture, idxEndCapture ); - idxBeginCapture = dist; } } formattedDescription.push_back( description.substr( idxBeginCapture ) ); @@ -133,6 +139,7 @@ void LogPart::formatDescriptions( LogPart::Description & description ) if( formattedName.size() + firstValue.size() > logPartMaxWidth ) { + std::cout << "logPartMaxWidth " << logPartMaxWidth << std::endl; std::vector< string > formattedDescription = splitAndFormatStringByDelimiter( firstValue, logPartMaxWidth - formattedName.size()); for( auto const & format : formattedDescription ) From 9f2c013ba9d3b8f0fb816576bcb8bb81785a92f6 Mon Sep 17 00:00:00 2001 From: arng40 Date: Wed, 29 Jan 2025 17:12:47 +0100 Subject: [PATCH 205/206] new version lr working & clean --- src/coreComponents/events/EventManager.cpp | 20 +- src/coreComponents/fileIO/logPart/LogPart.cpp | 178 ++++++++++-------- src/coreComponents/fileIO/logPart/LogPart.hpp | 61 ++++-- .../fileIO/logPart/unitTests/testLogPart.cpp | 75 ++++++-- 4 files changed, 218 insertions(+), 116 deletions(-) diff --git a/src/coreComponents/events/EventManager.cpp b/src/coreComponents/events/EventManager.cpp index 221bb97071b..6ed4d613454 100644 --- a/src/coreComponents/events/EventManager.cpp +++ b/src/coreComponents/events/EventManager.cpp @@ -190,7 +190,6 @@ bool EventManager::run( DomainPartition & domain ) // Execute, signal events bool earlyReturn = false; - std::cout << " pp d" << subEvent->getEventTarget()->getTimesteppingBehavior()<hasToPrepareForExec() ) { subEvent->signalToPrepareForExecution( m_time, m_dt, m_cycle, domain ); @@ -267,10 +266,10 @@ void EventManager::outputTime( LogPart & logPart ) const string const timeInfosUnfolded = timeInfo.toUnfoldedString() + timeCompletionUnfolded; string const timeCompletionSeconds = timeInfo.toSecondsString() + timeCompletionSecond; - logPart.addDescription( "- Time :", timeInfosUnfolded, timeCompletionSeconds ); - logPart.addDescription( "- Delta Time :", units::TimeFormatInfo::fromSeconds( m_dt ).toString() ); - logPart.addDescription( "- Cycle :", m_cycle, cycleLimited ); - logPart.setMinWidth( 70 ); + logPart.addDescription( "- Time : ", timeInfosUnfolded, timeCompletionSeconds ); + logPart.addDescription( "- Delta Time : ", units::TimeFormatInfo::fromSeconds( m_dt ).toString() ); + logPart.addDescription( "- Cycle : ", m_cycle, cycleLimited ); + logPart.setMaxWidth(70 ); // We are keeping the old outputs to keep compatibility with current log reading scripts. if( m_timeOutputFormat==TimeOutputFormat::full ) @@ -313,20 +312,19 @@ void EventManager::logEndOfCycleInformation( LogPart & logpart, integer const numOfSubSteps, std::vector< real64 > const & subStepDt ) const { - logpart.addEndDescription( "- Cycle:", cycleNumber ); - logpart.addEndDescription( "- N substeps:", numOfSubSteps ); + logpart.addEndDescription( "- Cycle: ", cycleNumber ); + logpart.addEndDescription( "- N substeps: ", numOfSubSteps ); std::stringstream logMessage; std::cout << units::TimeFormatInfo::fromSeconds( subStepDt[0] ).toString() << std::endl; - for( integer i = 0; i < 25; ++i ) + for( integer i = 0; i < numOfSubSteps; ++i ) { if (i > 0) { logMessage << ", "; } - logMessage << "00h00m01s (1 s)"; + logMessage << units::TimeFormatInfo::fromSeconds( subStepDt[i] ).toString(); } - logpart.addEndDescription( "- dt:", logMessage.str() ); - logpart.setMaxWidth( 100 );//todo min > max + logpart.addEndDescription( "- dt: ", logMessage.str() ); logpart.end(); } diff --git a/src/coreComponents/fileIO/logPart/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp index 3b6e9940ebc..71d784c8efb 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -17,16 +17,15 @@ */ #include "LogPart.hpp" +#include "common/format/StringUtilities.hpp" #include +using namespace geos::stringutilities; namespace geos { LogPart::LogPart( string_view logPartTitle ) { - m_startDesc.m_logPartWidth = std::max((size_t)m_rowMinWidth, logPartTitle.length()); - m_endDesc.m_logPartWidth = std::max((size_t)m_rowMinWidth, logPartTitle.length()); - m_startDesc.m_title = logPartTitle; m_endDesc.m_title = GEOS_FMT( "{}{}", m_prefixEndTitle, logPartTitle ); } @@ -46,131 +45,134 @@ void LogPart::addEndDescription( string const & description ) void LogPart::setMinWidth( size_t const & minWidth ) { - m_rowMinWidth = minWidth; - m_startDesc.m_logPartWidth = std::max( m_rowMinWidth, m_startDesc.m_logPartWidth ); - m_endDesc.m_logPartWidth = std::max( m_rowMinWidth, m_endDesc.m_logPartWidth ); + m_startDesc.m_logPartMinWidth = minWidth; + m_endDesc.m_logPartMinWidth = minWidth; } void LogPart::setMaxWidth( size_t const & maxWidth ) { - m_startDesc.m_logPartMaxWidth = std::min( maxWidth, m_startDesc.m_logPartMaxWidth ); - m_endDesc.m_logPartMaxWidth = std::min( maxWidth, m_endDesc.m_logPartMaxWidth ); + m_startDesc.m_logPartMaxWidth = maxWidth; + m_endDesc.m_logPartMaxWidth = maxWidth; +} + +string_view ltrim( string_view s ) +{ + std::size_t const first = s.find_first_not_of( " " ); + if( first != string::npos ) + { + return s.substr( first, ( s.size() - first ) ); + } + return {}; } -std::vector< string > splitAndFormatStringByDelimiter( string & description, size_t maxLength, char delimiter = ',' ) +std::vector< string > splitAndFormatStringByDelimiter( string const & description, size_t maxLength ) { std::vector< string > formattedDescription; - size_t idxBeginCapture = 0; - size_t limitCharTracker = 0; - std::stringstream currLine; - size_t prevIdxChar = 0; - for( auto strIt = description.begin(); strIt != description.end(); ++strIt ) + size_t startIdx = 0; + size_t endIdx = 0; + size_t captureIdx = 0; + size_t spaceIdx = 0; + while( endIdx < description.size()) { - if( *strIt == delimiter ) + endIdx = description.find( ' ', spaceIdx ); + if( endIdx == std::string::npos ) { - size_t const idxChar = std::distance( description.begin(), strIt ) + 1; - - limitCharTracker += (idxChar - idxBeginCapture); - size_t captureLength = idxChar - prevIdxChar; - - currLine << description.substr( idxBeginCapture, captureLength ); - - idxBeginCapture = idxChar; - prevIdxChar = idxChar; - if( limitCharTracker > maxLength ) + if( description.substr( startIdx ).size() >= maxLength ) + { + formattedDescription.push_back( string( ltrim( description.substr( startIdx, captureIdx )))); + formattedDescription.push_back( string( ltrim( description.substr( startIdx + captureIdx ))) ); + } + else { - formattedDescription.push_back( currLine.str() ); - currLine.str( "" ); - limitCharTracker = 0; + formattedDescription.push_back( string( ltrim( description.substr( startIdx, endIdx )))); } } - } - formattedDescription.push_back( description.substr( idxBeginCapture ) ); + else + { + size_t partLength = endIdx - startIdx; + if( partLength >= maxLength ) + { + formattedDescription.push_back( string( ltrim( description.substr( startIdx, captureIdx )))); + startIdx = spaceIdx; + captureIdx = 0; + } + spaceIdx = endIdx + 1; + captureIdx = partLength; + } + } return formattedDescription; } void LogPart::formatDescriptions( LogPart::Description & description ) { - size_t maxNameSize = 1; - std::vector< string > & descriptionName = description.m_descriptionNames; - std::vector< std::vector< string > > & m_descriptionsValues = description.m_descriptionsValues; - - for( auto const & name : descriptionName ) - { - size_t const idx = &name - &(*descriptionName.begin()); - - if( !m_descriptionsValues[idx].empty()) - { - maxNameSize = std::max( maxNameSize, name.size() ); - } - } - - std::vector< string > & formattedDescriptionLines = description.m_formattedDescriptionLines; + auto & names = description.m_descriptionNames; + auto & valuesList = description.m_descriptionsValues; size_t & logPartWidth = description.m_logPartWidth; size_t & logPartMaxWidth = description.m_logPartMaxWidth; - for( size_t idxName = 0; idxName < descriptionName.size(); idxName++ ) + size_t & logPartMinWidth = description.m_logPartMinWidth; + size_t & logPartMaxNameWidth = description.m_logPartMaxNameWidth; + std::vector< string > & formattedLines = description.m_formattedDescriptionLines; + + size_t buildingChars = m_nbBorderChar * 2 + m_borderMargin; + for( size_t idxName = 0; idxName < names.size(); idxName++ ) { - string & name = descriptionName[idxName]; - std::vector< string > & values = m_descriptionsValues[idxName]; + string const & name = names[idxName]; + auto const & values = valuesList[idxName]; if( values.empty()) { if( name.size() > logPartMaxWidth ) { - std::vector< string > formattedName = splitAndFormatStringByDelimiter( name, logPartMaxWidth ); - for( auto const & format : formattedName ) - { - formattedDescriptionLines.push_back( format ); - } + auto formattedName = splitAndFormatStringByDelimiter( name, logPartMaxWidth - buildingChars ); + formattedLines.insert( formattedLines.end(), formattedName.begin(), formattedName.end()); } else { - formattedDescriptionLines.push_back( name ); + formattedLines.push_back( name ); } } else { - // +1 for extra space in case of delimiter ":" - string const spaces = std::string( maxNameSize - name.size() + 1, ' ' ); + string const spaces = std::string( logPartMaxNameWidth - name.size(), ' ' ); string const formattedName = GEOS_FMT( "{}{}", name, spaces ); - - string firstValue = values[0]; - - if( formattedName.size() + firstValue.size() > logPartMaxWidth ) + string const firstValue = values[0]; + size_t const formattedLineWidth = formattedName.size() + firstValue.size() + buildingChars; + if( formattedLineWidth > logPartMaxWidth ) { - std::cout << "logPartMaxWidth " << logPartMaxWidth << std::endl; - std::vector< string > formattedDescription = - splitAndFormatStringByDelimiter( firstValue, logPartMaxWidth - formattedName.size()); + auto formattedDescription = + splitAndFormatStringByDelimiter( firstValue, logPartMaxWidth - formattedName.size() - buildingChars ); for( auto const & format : formattedDescription ) { if( &format == &formattedDescription.front()) { - - formattedDescriptionLines.push_back( GEOS_FMT( "{}{}", formattedName, format )); + formattedLines.push_back( GEOS_FMT( "{}{}", formattedName, format )); } else { - formattedDescriptionLines.push_back( - GEOS_FMT( "{:>{}}", format, formattedName.size() + format.size() )); + formattedLines.push_back( GEOS_FMT( "{:>{}}", format, formattedName.size() + format.size() ) ); } } } else { - formattedDescriptionLines.push_back( GEOS_FMT( "{}{}", formattedName, firstValue )); + formattedLines.push_back( GEOS_FMT( "{}{}", formattedName, firstValue )); } - logPartWidth = std::max( logPartWidth, formattedDescriptionLines[idxName].size() ); + logPartWidth = std::max( logPartWidth, formattedLines[idxName].size() ); for( size_t idxValue = 1; idxValue < values.size(); idxValue++ ) { - formattedDescriptionLines.push_back( + formattedLines.push_back( GEOS_FMT( "{:>{}}", values[idxValue], formattedName.size() + values[idxValue].size() )); - logPartWidth = std::max( logPartWidth, formattedDescriptionLines.back().size() ); + logPartWidth = std::max( logPartWidth, formattedLines.back().size() ); } + logPartWidth += m_nbBorderChar * 2; + if( logPartWidth > logPartMaxWidth ) + logPartWidth = logPartMaxWidth; } } + logPartWidth = std::max( logPartWidth, logPartMinWidth ); } string LogPart::buildDescriptionPart( LogPart::Description const & description ) @@ -201,10 +203,34 @@ string LogPart::buildTitlePart( LogPart::Description const & description ) return oss.str(); } +void LogPart::computeInitialLogWidth( LogPart::Description & description, + std::vector< string > const & descriptionNames, + std::vector< std::vector< string > > m_descriptionsValues ) +{ + + if( !descriptionNames.empty() ) + { + size_t maxStringSize = 0; + for( size_t idxDescription = 0; idxDescription < descriptionNames.size(); idxDescription++ ) + { + if( !m_descriptionsValues[idxDescription].empty()) + { + maxStringSize = std::max( maxStringSize, descriptionNames[idxDescription].size() ); + } + } + + description.m_logPartMaxNameWidth = maxStringSize; + } +} + void LogPart::begin( std::ostream & os ) { string bottomPart = ""; - if( !m_startDesc.m_descriptionNames.empty()) + auto & descriptionNames = m_startDesc.m_descriptionNames; + + computeInitialLogWidth( m_startDesc, descriptionNames, m_startDesc.m_descriptionsValues ); + + if( !descriptionNames.empty()) { formatDescriptions( m_startDesc ); } @@ -221,10 +247,14 @@ void LogPart::begin( std::ostream & os ) void LogPart::end( std::ostream & os ) { string topPart = ""; + auto & descriptionNames = m_endDesc.m_descriptionNames; + + computeInitialLogWidth( m_endDesc, descriptionNames, m_endDesc.m_descriptionsValues ); + + formatDescriptions( m_endDesc ); string const line = string( m_endDesc.m_logPartWidth, m_borderCharacter ); - if( !m_endDesc.m_descriptionNames.empty() ) + if( !descriptionNames.empty() ) { - formatDescriptions( m_endDesc ); topPart = GEOS_FMT( "{}{}\n", buildDescriptionPart( m_endDesc ), line ); } diff --git a/src/coreComponents/fileIO/logPart/LogPart.hpp b/src/coreComponents/fileIO/logPart/LogPart.hpp index 640cfc993b5..3bfbd261672 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.hpp +++ b/src/coreComponents/fileIO/logPart/LogPart.hpp @@ -101,7 +101,7 @@ class LogPart /// Name of the description, formatted to be : [Name] : [Values1]\n[Values2] std::vector< string > m_descriptionNames; - /// Values in the description + /// Values in the description std::vector< std::vector< string > > m_descriptionsValues; /// Vector containing the descriptions formatted by formatDescriptions() std::vector< string > m_formattedDescriptionLines; @@ -110,8 +110,29 @@ class LogPart size_t m_logPartWidth; /// logPart length size_t m_logPartMaxWidth; + /// min width of logPart length + size_t m_logPartMinWidth; + /// min width of logPart length + size_t m_logPartMaxNameWidth; }; + /** + * @brief Add a description to a specific section + * @param name The description name + * @param args Descriptions values to be concatened. + * @note Descriptions values can be be any formatted types. Values will be aligned altogether. + */ + template< typename ... Args > + void addDescriptionBySection( LogPart::Description & description, string const & name, Args const &... args ); + + /** + * @brief Computes the initial log width based on the provided description and names. + * @param description A description object that contains the current log part + * @param descriptionNames A vector containing all name used in the log Part + */ + void computeInitialLogWidth( LogPart::Description & description, + std::vector< string > const & descriptionNames, + std::vector< std::vector< string > > m_descriptionsValues ); /** * @brief Build a description from the name and description values * @param name The decription name @@ -132,11 +153,8 @@ class LogPart /// prefix to append to the title of closing section string const m_prefixEndTitle = "End of "; - /// min width of logPart length - size_t m_rowMinWidth = 50; - - Description m_startDesc = { "", {}, {}, {}, m_rowMinWidth, SIZE_MAX}; - Description m_endDesc = { "", {}, {}, {}, m_rowMinWidth, SIZE_MAX }; + Description m_startDesc = { "", {}, {}, {}, 50, SIZE_MAX, 50, 0 }; + Description m_endDesc = { "", {}, {}, {}, 50, SIZE_MAX, 50, 0 }; /// description border margin static constexpr size_t m_borderMargin = 2; @@ -150,32 +168,35 @@ class LogPart }; template< typename ... Args > -void LogPart::addDescription( string const & name, Args const &... args ) +void LogPart::addDescriptionBySection( Description & description, string const & name, Args const &... args ) { std::vector< string > values; + size_t maxValueSize = 0; + ( [&] { static_assert( has_formatter_v< decltype(args) >, - "Argument passed in addRow cannot be converted to string" ); + "Argument passed cannot be converted to string" ); string const value = GEOS_FMT( "{}", args ); values.push_back( value ); + maxValueSize = std::max( maxValueSize, value.size()); } (), ...); - m_startDesc.m_descriptionNames.push_back( name ); - m_startDesc.m_descriptionsValues.push_back( values ); + + description.m_descriptionNames.push_back( name ); + description.m_descriptionsValues.push_back( values ); + description.m_logPartWidth = std::min( description.m_logPartWidth, maxValueSize + 6 ); + } template< typename ... Args > -void LogPart::addEndDescription( string const & name, Args const &... args ) +void LogPart::addDescription( string const & name, Args const &... args ) { - std::vector< string > values; - ( [&] { - static_assert( has_formatter_v< decltype(args) >, - "Argument passed in addRow cannot be converted to string" ); - string const value = GEOS_FMT( "{}", args ); - values.push_back( value ); - } (), ...); + addDescriptionBySection( m_startDesc, name, args ... ); +} - m_endDesc.m_descriptionNames.push_back( name ); - m_endDesc.m_descriptionsValues.push_back( values ); +template< typename ... Args > +void LogPart::addEndDescription( string const & name, Args const &... args ) +{ + addDescriptionBySection( m_endDesc, name, args ... ); } } diff --git a/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp b/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp index 2fc945a1e50..353e5a2d8da 100644 --- a/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp +++ b/src/coreComponents/fileIO/logPart/unitTests/testLogPart.cpp @@ -24,17 +24,17 @@ TEST( testSection, sectionWithTitle ) LogPart logPart( "section name" ); logPart.begin( oss ); EXPECT_EQ( oss.str(), - "\n######################################################################\n" - "## section name ##\n" - "######################################################################\n\n" + "\n##################################################\n" + "## section name ##\n" + "##################################################\n\n" ); oss.clear(); oss.str( "" ); logPart.end( oss ); EXPECT_EQ( oss.str(), - "\n## End of section name ##\n" - "######################################################################\n\n" + "\n## End of section name ##\n" + "##################################################\n\n" ); oss.clear(); } @@ -46,10 +46,10 @@ TEST( testSection, sectionWithTitleAndOneDescription ) logPart.addDescription( "description name" ); logPart.begin( oss ); EXPECT_EQ( oss.str(), - "\n######################################################################\n" - "## section name ##\n" - "######################################################################\n" - "## description name ##\n\n" + "\n##################################################\n" + "## section name ##\n" + "##################################################\n" + "## description name ##\n\n" ); oss.clear(); } @@ -84,8 +84,8 @@ TEST( testSection, sectionMultipleDescriptions ) { std::ostringstream oss; LogPart logPart( "TIMESTEP START" ); - logPart.addDescription( "- Time :", "00h08m20s out of 2d, 21h26m40s (0% completed)", "500 s / 250000 s" ); - logPart.addDescription( "- Delta Time :", "00h16m40s (1000 s)" ); + logPart.addDescription( "- Time : ", "00h08m20s out of 2d, 21h26m40s (0% completed)", "500 s / 250000 s" ); + logPart.addDescription( "- Delta Time : ", "00h16m40s (1000 s)" ); logPart.addDescription( "Description test" ); logPart.setMinWidth( 70 ); logPart.begin( oss ); @@ -130,6 +130,59 @@ TEST( testSection, sectionEndDescription ) oss.clear(); } +TEST( testSection, valuesMultiLines ) +{ + std::ostringstream oss; + LogPart logPart( "TIMESTEP START" ); + logPart.addDescription( "dummy name : ", "long dummy values, long dummy values1, long dummy values2, long dummy values3" ); + logPart.addDescription( "dummy name : ", "long dummy values", "long dummy values", "long dummy values", "long dummy values" ); + logPart.addDescription( "dummy name : ", "small dummy value" ); + logPart.addDescription( "dummy name, long dummy values, long dummy values, long dummy values, long dummy values" ); + + logPart.addEndDescription( "dummy name : ", "long dummy end values, long dummy end values, long dummy end values, long dummy end values" ); + logPart.addEndDescription( "dummy name : ", "long dummy end values", "long dummy end values", "long dummy end values", "long dummy end values" ); + logPart.addEndDescription( "dummy name : ", "small dummy end value" ); + logPart.addEndDescription( "Ceci est un timestep extremement long 10h00h00545ms ( 1h 30 s en heure)" ); + logPart.setMaxWidth( 50 ); + logPart.begin( oss ); + EXPECT_EQ( oss.str(), + "\n##################################################\n" + "## TIMESTEP START ##\n" + "##################################################\n" + "## dummy name : long dummy values, long dummy ##\n" + "## values1, long dummy values2, ##\n" + "## long dummy values3 ##\n" + "## dummy name : long dummy values ##\n" + "## long dummy values ##\n" + "## long dummy values ##\n" + "## long dummy values ##\n" + "## dummy name : small dummy value ##\n" + "## dummy name, long dummy values, long dummy ##\n" + "## values, long dummy values, long dummy ##\n" + "## values ##\n\n" ); + oss.clear(); + oss.str( "" ); + + logPart.end( oss ); + EXPECT_EQ( oss.str(), + "\n## dummy name : long dummy end values, long ##\n" + "## dummy end values, long dummy ##\n" + "## end values, long dummy end ##\n" + "## values ##\n" + "## dummy name : long dummy end values ##\n" + "## long dummy end values ##\n" + "## long dummy end values ##\n" + "## long dummy end values ##\n" + "## dummy name : small dummy end value ##\n" + "## Ceci est un timestep extremement long ##\n" + "## 10h00h00545ms ( 1h 30 s en heure) ##\n" + "##################################################\n" + "## End of TIMESTEP START ##\n" + "##################################################\n\n" + ); + oss.clear(); +} + int main( int argc, char * * argv ) { testing::InitGoogleTest( &argc, argv ); From b0485e5e348b149b77eda3ae7975b8750147d72e Mon Sep 17 00:00:00 2001 From: arng40 Date: Thu, 30 Jan 2025 11:38:07 +0100 Subject: [PATCH 206/206] fix some case --- src/coreComponents/fileIO/logPart/LogPart.cpp | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/coreComponents/fileIO/logPart/LogPart.cpp b/src/coreComponents/fileIO/logPart/LogPart.cpp index 71d784c8efb..a0903a3f135 100644 --- a/src/coreComponents/fileIO/logPart/LogPart.cpp +++ b/src/coreComponents/fileIO/logPart/LogPart.cpp @@ -141,7 +141,7 @@ void LogPart::formatDescriptions( LogPart::Description & description ) if( formattedLineWidth > logPartMaxWidth ) { auto formattedDescription = - splitAndFormatStringByDelimiter( firstValue, logPartMaxWidth - formattedName.size() - buildingChars ); + splitAndFormatStringByDelimiter( firstValue, logPartMaxWidth - formattedName.size() - buildingChars ); for( auto const & format : formattedDescription ) { if( &format == &formattedDescription.front()) @@ -167,11 +167,15 @@ void LogPart::formatDescriptions( LogPart::Description & description ) GEOS_FMT( "{:>{}}", values[idxValue], formattedName.size() + values[idxValue].size() )); logPartWidth = std::max( logPartWidth, formattedLines.back().size() ); } - logPartWidth += m_nbBorderChar * 2; - if( logPartWidth > logPartMaxWidth ) - logPartWidth = logPartMaxWidth; } + } + if( logPartWidth > logPartMaxWidth ) + logPartWidth = logPartMaxWidth; + + if( logPartWidth != logPartMinWidth ) + logPartWidth += buildingChars; + logPartWidth = std::max( logPartWidth, logPartMinWidth ); } @@ -180,11 +184,10 @@ string LogPart::buildDescriptionPart( LogPart::Description const & description ) std::ostringstream oss; for( auto const & formattedDescription : description.m_formattedDescriptionLines ) { - // length of white space to add after the formatted description - size_t const remainingLength = description.m_logPartWidth - m_nbBorderChar * 2 - m_borderMargin; string const borderCharacters = string( m_nbBorderChar, m_borderCharacter ); oss << borderCharacters; - oss << GEOS_FMT( "{:<{}}{:<{}}", " ", m_borderMargin, formattedDescription, remainingLength ); + oss << GEOS_FMT( "{:<{}}{:<{}}", " ", m_borderMargin, + formattedDescription, description.m_logPartWidth - m_nbBorderChar * 2 - m_borderMargin ); oss << borderCharacters << '\n'; } return oss.str(); @@ -193,12 +196,12 @@ string LogPart::buildDescriptionPart( LogPart::Description const & description ) string LogPart::buildTitlePart( LogPart::Description const & description ) { std::ostringstream oss; - size_t const titleRowLength = description.m_logPartWidth - m_nbBorderChar * 2; + size_t const titleRowLength = description.m_logPartWidth; string const borderCharacters = string( m_nbBorderChar, m_borderCharacter ); oss << GEOS_FMT( "{}{:^{}}{}\n", borderCharacters, description.m_title, - titleRowLength, + titleRowLength - 4, borderCharacters ); return oss.str(); } @@ -234,6 +237,7 @@ void LogPart::begin( std::ostream & os ) { formatDescriptions( m_startDesc ); } + bottomPart = buildDescriptionPart( m_startDesc ); string const line = string( m_startDesc.m_logPartWidth, m_borderCharacter ); @@ -252,6 +256,7 @@ void LogPart::end( std::ostream & os ) computeInitialLogWidth( m_endDesc, descriptionNames, m_endDesc.m_descriptionsValues ); formatDescriptions( m_endDesc ); + string const line = string( m_endDesc.m_logPartWidth, m_borderCharacter ); if( !descriptionNames.empty() ) {