Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions cmake/test/testFloatFromChars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
#include <charconv>
#include <string_view>

int main()
int
main()
{
const auto s = std::string_view { "2.71828" };
const auto s = std::string_view {"2.71828"};
auto e = 0.0;
std::from_chars(s.data(), s.data() + s.size(), e);
}
95 changes: 42 additions & 53 deletions examples/art2dgf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,41 @@
copyright holders.
*/

#include <dune/common/version.hh>
#include <dune/common/fvector.hh>
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>
#include <dune/common/version.hh>

#include <algorithm>
#include <fstream>
#include <stdexcept>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>

namespace Ewoms {
namespace Ewoms
{
/*!
* \brief Reads in mesh files in the ART format.
*
* This file format is used to specify grids with fractures.
*/

struct Art2DGF
{
struct Art2DGF {
/*!
* \brief Create the Grid
*/
static void convert( const std::string& artFileName,
std::ostream& dgfFile,
const unsigned precision = 16 )
static void convert(const std::string& artFileName, std::ostream& dgfFile, const unsigned precision = 16)
{
using Scalar = double;
using GlobalPosition = Dune::FieldVector< Scalar, 2 >;
using GlobalPosition = Dune::FieldVector<Scalar, 2>;
enum ParseMode { Vertex, Edge, Element, Finished };
std::vector< std::pair<GlobalPosition, unsigned> > vertexPos;
std::vector<std::pair<unsigned, unsigned> > edges;
std::vector<std::pair<unsigned, unsigned> > fractureEdges;
std::vector<std::vector<unsigned> > elements;
std::vector<std::pair<GlobalPosition, unsigned>> vertexPos;
std::vector<std::pair<unsigned, unsigned>> edges;
std::vector<std::pair<unsigned, unsigned>> fractureEdges;
std::vector<std::vector<unsigned>> elements;
std::ifstream inStream(artFileName);
if (!inStream.is_open()) {
throw std::runtime_error("File '"+artFileName
+"' does not exist or is not readable");
throw std::runtime_error("File '" + artFileName + "' does not exist or is not readable");
}
std::string curLine;
ParseMode curParseMode = Vertex;
Expand All @@ -73,16 +70,13 @@ namespace Ewoms {

// remove leading whitespace
unsigned numLeadingSpaces = 0;
while (curLine.size() > numLeadingSpaces
&& std::isspace(curLine[numLeadingSpaces]))
while (curLine.size() > numLeadingSpaces && std::isspace(curLine[numLeadingSpaces]))
++numLeadingSpaces;
curLine = curLine.substr(numLeadingSpaces,
curLine.size() - numLeadingSpaces);
curLine = curLine.substr(numLeadingSpaces, curLine.size() - numLeadingSpaces);

// remove trailing whitespace
unsigned numTrailingSpaces = 0;
while (curLine.size() > numTrailingSpaces
&& std::isspace(curLine[curLine.size() - numTrailingSpaces]))
while (curLine.size() > numTrailingSpaces && std::isspace(curLine[curLine.size() - numTrailingSpaces]))
++numTrailingSpaces;
curLine.erase(numTrailingSpaces);

Expand All @@ -108,9 +102,8 @@ namespace Ewoms {
// coordinate. the last number is the Z coordinate
// which we ignore (so far)
iss >> coord[0] >> coord[1];
vertexPos.push_back( std::make_pair( coord, 0 ) );
}
else if (curParseMode == Edge) {
vertexPos.push_back(std::make_pair(coord, 0));
} else if (curParseMode == Edge) {
// read an edge and update the fracture mapper

// read the data attached to the edge
Expand Down Expand Up @@ -141,11 +134,10 @@ namespace Ewoms {
// add the edge to the fracture mapper if it is a fracture
if (dataVal < 0) {
fractureEdges.push_back(edge);
vertexPos[ edge.first ].second = 1;
vertexPos[ edge.second ].second = 1;
vertexPos[edge.first].second = 1;
vertexPos[edge.second].second = 1;
}
}
else if (curParseMode == Element) {
} else if (curParseMode == Element) {
// skip the data attached to an element
std::istringstream iss(curLine);
int dataVal;
Expand Down Expand Up @@ -206,9 +198,8 @@ namespace Ewoms {
if (mat.determinant() < 0)
std::swap(vertIndices[2], vertIndices[1]);

elements.push_back( vertIndices );
}
else if (curParseMode == Finished) {
elements.push_back(vertIndices);
} else if (curParseMode == Finished) {
assert(curLine.size() == 0);
}
}
Expand All @@ -218,23 +209,21 @@ namespace Ewoms {
dgfFile << "GridParameter" << std::endl
<< "overlap 1" << std::endl
<< "closure green" << std::endl
<< "#" << std::endl << std::endl;
<< "#" << std::endl
<< std::endl;

dgfFile << "Vertex" << std::endl;
const bool hasFractures = fractureEdges.size() > 0;
if( hasFractures )
{
if (hasFractures) {
dgfFile << "parameters 1" << std::endl;
}
dgfFile << std::scientific;
dgfFile.precision( precision );
dgfFile.precision(precision);
const size_t vxSize = vertexPos.size();
for( size_t i=0; i<vxSize; ++i)
{
dgfFile << vertexPos[ i ].first;
if( hasFractures )
{
dgfFile << " " << vertexPos[ i ].second;
for (size_t i = 0; i < vxSize; ++i) {
dgfFile << vertexPos[i].first;
if (hasFractures) {
dgfFile << " " << vertexPos[i].second;
}
dgfFile << std::endl;
}
Expand All @@ -243,11 +232,10 @@ namespace Ewoms {

dgfFile << "Simplex" << std::endl;
const size_t elSize = elements.size();
for( size_t i=0; i<elSize; ++i )
{
const size_t elVx = elements[ i ].size();
for( size_t j=0; j<elVx; ++j )
dgfFile << elements[ i ][ j ] << " ";
for (size_t i = 0; i < elSize; ++i) {
const size_t elVx = elements[i].size();
for (size_t j = 0; j < elVx; ++j)
dgfFile << elements[i][j] << " ";
dgfFile << std::endl;
}

Expand All @@ -257,11 +245,12 @@ namespace Ewoms {
dgfFile << "#" << std::endl << std::endl;
dgfFile << "#" << std::endl;
}
};
};

} // namespace Ewoms

int main( int argc, char** argv )
int
main(int argc, char** argv)
{
if (argc != 2) {
std::cout << "Converts a grid file from the ART file format to DGF (Dune grid format)\n"
Expand All @@ -272,13 +261,13 @@ int main( int argc, char** argv )
return 1;
}

std::string filename( argv[ 1 ] );
std::string dgfname( filename );
std::string filename(argv[1]);
std::string dgfname(filename);
dgfname += ".dgf";

std::cout << "Converting ART file \"" << filename << "\" to DGF file \"" << dgfname << "\"\n";
std::ofstream dgfFile( dgfname );
Ewoms::Art2DGF::convert( filename, dgfFile );
std::ofstream dgfFile(dgfname);
Ewoms::Art2DGF::convert(filename, dgfFile);

return 0;
}
23 changes: 12 additions & 11 deletions examples/co2_ptflash_ecfv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,35 @@
*/
#include "config.h"

#include <opm/models/utils/start.hh>
#include "problems/co2ptflashproblem.hh"
#include <opm/models/utils/start.hh>


namespace Opm::Properties {
namespace Opm::Properties
{

namespace TTag {
namespace TTag
{
struct CO2PTEcfvProblem {
using InheritsFrom = std::tuple<CO2PTBaseProblem, FlashModel>;
};
}
using InheritsFrom = std::tuple<CO2PTBaseProblem, FlashModel>;
};
} // namespace TTag

template <class TypeTag>
struct SpatialDiscretizationSplice<TypeTag, TTag::CO2PTEcfvProblem>
{
struct SpatialDiscretizationSplice<TypeTag, TTag::CO2PTEcfvProblem> {
using type = TTag::EcfvDiscretization;
};

template <class TypeTag>
struct LocalLinearizerSplice<TypeTag, TTag::CO2PTEcfvProblem>
{
struct LocalLinearizerSplice<TypeTag, TTag::CO2PTEcfvProblem> {
using type = TTag::AutoDiffLocalLinearizer;
};


} // namespace Opm::Properties

int main(int argc, char **argv)
int
main(int argc, char** argv)
{
using EcfvProblemTypeTag = Opm::Properties::TTag::CO2PTEcfvProblem;
return Opm::start<EcfvProblemTypeTag>(argc, argv, true);
Expand Down
54 changes: 31 additions & 23 deletions examples/co2injection_flash_ecfv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,61 @@
#include <opm/material/common/quad.hpp>
#endif

#include <opm/models/io/dgfvanguard.hh>
#include <opm/models/utils/start.hh>
#include <opm/models/flash/flashmodel.hh>
#include <opm/models/discretization/ecfv/ecfvdiscretization.hh>
#include "problems/co2injectionflash.hh"
#include "problems/co2injectionproblem.hh"
#include <opm/models/discretization/ecfv/ecfvdiscretization.hh>
#include <opm/models/flash/flashmodel.hh>
#include <opm/models/io/dgfvanguard.hh>
#include <opm/models/utils/start.hh>

namespace Opm::Properties {
namespace Opm::Properties
{

// Create new type tags
namespace TTag {
namespace TTag
{

struct Co2InjectionFlashEcfvProblem
{ using InheritsFrom = std::tuple<Co2InjectionBaseProblem, FlashModel>; };
struct Co2InjectionFlashEcfvProblem {
using InheritsFrom = std::tuple<Co2InjectionBaseProblem, FlashModel>;
};

} // end namespace TTag

template<class TypeTag>
struct SpatialDiscretizationSplice<TypeTag, TTag::Co2InjectionFlashEcfvProblem>
{ using type = TTag::EcfvDiscretization; };
template <class TypeTag>
struct SpatialDiscretizationSplice<TypeTag, TTag::Co2InjectionFlashEcfvProblem> {
using type = TTag::EcfvDiscretization;
};

// use automatic differentiation for this simulator
template<class TypeTag>
struct LocalLinearizerSplice<TypeTag, TTag::Co2InjectionFlashEcfvProblem>
{ using type = TTag::AutoDiffLocalLinearizer; };
template <class TypeTag>
struct LocalLinearizerSplice<TypeTag, TTag::Co2InjectionFlashEcfvProblem> {
using type = TTag::AutoDiffLocalLinearizer;
};

// use the flash solver adapted to the CO2 injection problem
template<class TypeTag>
struct FlashSolver<TypeTag, TTag::Co2InjectionFlashEcfvProblem>
{ using type = Opm::Co2InjectionFlash<GetPropType<TypeTag, Properties::Scalar>,
GetPropType<TypeTag, Properties::FluidSystem>>; };
template <class TypeTag>
struct FlashSolver<TypeTag, TTag::Co2InjectionFlashEcfvProblem> {
using type = Opm::Co2InjectionFlash<GetPropType<TypeTag, Properties::Scalar>,
GetPropType<TypeTag, Properties::FluidSystem>>;
};

// the flash model has serious problems with the numerical
// precision. if quadruple precision math is available, we use it,
// else we increase the tolerance of the Newton solver
#if HAVE_QUAD
template<class TypeTag>
struct Scalar<TypeTag, TTag::Co2InjectionFlashEcfvProblem>
{ using type = quad; };
template <class TypeTag>
struct Scalar<TypeTag, TTag::Co2InjectionFlashEcfvProblem> {
using type = quad;
};
#endif

} // namespace Opm::Properties

int main(int argc, char **argv)
int
main(int argc, char** argv)
{
using EcfvProblemTypeTag = Opm::Properties::TTag::Co2InjectionFlashEcfvProblem;
#if ! HAVE_QUAD
#if !HAVE_QUAD
Opm::Co2InjectionTolerance = 1e-5;
#endif
return Opm::start<EcfvProblemTypeTag>(argc, argv, true);
Expand Down
Loading