Skip to content

Commit de80192

Browse files
committed
upgrade MDAL to 0.3.0
1 parent 24a1e8e commit de80192

21 files changed

+1354
-151
lines changed

external/mdal/cmake/FindNetCDF.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,3 @@ FIND_LIBRARY (NETCDF_LIBRARY
2828
INCLUDE (FindPackageHandleStandardArgs)
2929
FIND_PACKAGE_HANDLE_STANDARD_ARGS (NetCDF
3030
DEFAULT_MSG NETCDF_LIBRARY NETCDF_INCLUDE_DIR)
31-

external/mdal/cmake_templates/mdal_config.hpp.in

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#cmakedefine HAVE_NETCDF
1111

12+
#cmakedefine HAVE_XML
13+
1214
#endif // MDAL_CONFIG_HPP
1315

1416

external/mdal/frmts/mdal_2dm.cpp

+33-16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <vector>
1313
#include <map>
1414
#include <cassert>
15+
#include <limits>
1516

1617
#include "mdal_2dm.hpp"
1718
#include "mdal.h"
@@ -63,7 +64,6 @@ size_t MDAL::Mesh2dm::vertexIndex( size_t vertexID ) const
6364
return vertexID;
6465
}
6566

66-
6767
MDAL::Driver2dm::Driver2dm():
6868
Driver( DRIVER_NAME,
6969
"2DM Mesh File",
@@ -135,6 +135,9 @@ std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile,
135135
std::vector<Vertex> vertices( vertexCount );
136136
std::vector<Face> faces( faceCount );
137137

138+
// Basement 3.x supports definition of elevation for cell centers
139+
std::vector<double> elementCenteredElevation;
140+
138141
in.clear();
139142
in.seekg( 0, std::ios::beg );
140143

@@ -146,30 +149,40 @@ std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile,
146149

147150
while ( std::getline( in, line ) )
148151
{
149-
if ( startsWith( line, "E4Q" ) )
152+
if ( startsWith( line, "E4Q" ) ||
153+
startsWith( line, "E3T" )
154+
)
150155
{
151156
chunks = split( line, ' ' );
152157
assert( faceIndex < faceCount );
153158

159+
const size_t faceVertexCount = MDAL::toSizeT( line[1] );
160+
assert( ( faceVertexCount == 3 ) || ( faceVertexCount == 4 ) );
161+
154162
Face &face = faces[faceIndex];
155-
face.resize( 4 );
163+
face.resize( faceVertexCount );
164+
165+
// chunks format here
166+
// E** id vertex_id1, vertex_id2, ... material_id (elevation - optional)
167+
// vertex ids are numbered from 1
156168
// Right now we just store node IDs here - we will convert them to node indices afterwards
157-
for ( size_t i = 0; i < 4; ++i )
158-
face[i] = toSizeT( chunks[i + 2] ) - 1; // 2dm is numbered from 1
169+
assert( chunks.size() > faceVertexCount + 1 );
159170

160-
faceIndex++;
161-
}
162-
else if ( startsWith( line, "E3T" ) )
163-
{
164-
chunks = split( line, ' ' );
165-
assert( faceIndex < faceCount );
171+
for ( size_t i = 0; i < faceVertexCount; ++i )
172+
face[i] = MDAL::toSizeT( chunks[i + 2] ) - 1; // 2dm is numbered from 1
166173

167-
Face &face = faces[faceIndex];
168-
face.resize( 3 );
169-
// Right now we just store node IDs here - we will convert them to node indices afterwards
170-
for ( size_t i = 0; i < 3; ++i )
174+
// OK, now find out if there is optional cell elevation (BASEMENT 3.x)
175+
if ( chunks.size() == faceVertexCount + 4 )
171176
{
172-
face[i] = toSizeT( chunks[i + 2] ) - 1; // 2dm is numbered from 1
177+
178+
// initialize dataset if it is still empty
179+
if ( elementCenteredElevation.empty() )
180+
{
181+
elementCenteredElevation = std::vector<double>( faceCount, std::numeric_limits<double>::quiet_NaN() );
182+
}
183+
184+
// add Bed Elevation (Face) value
185+
elementCenteredElevation[faceIndex] = MDAL::toDouble( chunks[ faceVertexCount + 3 ] );
173186
}
174187

175188
faceIndex++;
@@ -236,6 +249,10 @@ std::unique_ptr<MDAL::Mesh> MDAL::Driver2dm::load( const std::string &meshFile,
236249
);
237250
mesh->faces = faces;
238251
mesh->vertices = vertices;
252+
253+
// Add Bed Elevations
254+
MDAL::addFaceScalarDatasetGroup( mesh.get(), elementCenteredElevation, "Bed Elevation (Face)" );
239255
MDAL::addBedElevationDatasetGroup( mesh.get(), vertices );
256+
240257
return std::unique_ptr<Mesh>( mesh.release() );
241258
}

external/mdal/frmts/mdal_2dm.hpp

+19
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ namespace MDAL
4242
std::map<size_t, size_t> mVertexIDtoIndex;
4343
};
4444

45+
/**
46+
* 2DM format specification used in TUFLOW and BASEMENET solvers
47+
* Text file format representing mesh vertices (ND) and faces (E**)
48+
* ND id x y z
49+
* Supports lines, triangles and polygons up to 9 vertices (implemented triangles and quads)
50+
* E3T id 1 2 3 mat_id -> face type, id, vertex indices ..., material index
51+
*
52+
* full specification here: https://www.xmswiki.com/wiki/SMS:2D_Mesh_Files_*.2dm
53+
*
54+
* Exception for the official specification is for recognition of cell-centered
55+
* elevation values supported by BASEMENT 3.x releases
56+
* If face definition has extra column, it is parsed and recognized as
57+
* elevation, e.g. format for triangle
58+
* E3T id 1 2 3 mat_id elevation
59+
* and added automatically as "Bed Elevation (Face)"
60+
*
61+
* Note that some 2dm formats do have some extra columns after mat_id column with
62+
* data with unknown origin/name (e.g. tests/data/2dm/regular_grid.2dm)
63+
*/
4564
class Driver2dm: public Driver
4665
{
4766
public:

external/mdal/frmts/mdal_cf.cpp

+1-14
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ MDAL::cfdataset_info_map MDAL::DriverCF::parseDatasetGroupInfo()
125125
}
126126
while ( true );
127127

128-
if ( dsinfo_map.size() == 0 )
129-
{
130-
throw MDAL_Status::Err_InvalidData;
131-
}
128+
if ( dsinfo_map.size() == 0 ) throw MDAL_Status::Err_InvalidData;
132129

133130
return dsinfo_map;
134131
}
@@ -388,16 +385,6 @@ void MDAL::CFDimensions::setDimension( MDAL::CFDimensions::Type type,
388385
mCount[type] = count;
389386
}
390387

391-
size_t MDAL::CFDimensions::faceCount() const
392-
{
393-
return size( Face2D ) + size( Line1D );
394-
}
395-
396-
size_t MDAL::CFDimensions::vertexCount() const
397-
{
398-
return size( Vertex1D ) + size( Vertex2D );
399-
}
400-
401388
bool MDAL::CFDimensions::isDatasetType( MDAL::CFDimensions::Type type ) const
402389
{
403390
return (

external/mdal/frmts/mdal_cf.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ namespace MDAL
4141
size_t size( Type type ) const;
4242
//! Sets a dimension
4343
void setDimension( Type type, size_t count, int ncid = -1 );
44-
//! Returns number of faces (1D + 2D)
45-
size_t faceCount() const;
46-
//! Returns number of vertices (1D + 2D)
47-
size_t vertexCount() const;
4844
//! Returns whether the type is one that case be used for datasets definition
4945
bool isDatasetType( Type type ) const;
5046

external/mdal/frmts/mdal_flo2d.cpp

-17
Original file line numberDiff line numberDiff line change
@@ -502,23 +502,6 @@ void MDAL::DriverFlo2D::createMesh( const std::vector<CellCenter> &cells, double
502502
mMesh->vertices = vertices;
503503
}
504504

505-
bool MDAL::DriverFlo2D::isFlo2DFile( const std::string &fileName )
506-
{
507-
std::vector<std::string> required_files =
508-
{
509-
"CADPTS.DAT",
510-
"FPLAIN.DAT"
511-
};
512-
513-
for ( const std::string &str : required_files )
514-
{
515-
std::string fn( fileNameFromDir( fileName, str ) );
516-
if ( !fileExists( fn ) )
517-
return false;
518-
}
519-
return true;
520-
}
521-
522505
bool MDAL::DriverFlo2D::parseHDF5Datasets( const std::string &datFileName )
523506
{
524507
//return true on error

external/mdal/frmts/mdal_flo2d.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ namespace MDAL
2525
bool canRead( const std::string &uri ) override;
2626
std::unique_ptr< Mesh > load( const std::string &resultsFile, MDAL_Status *status ) override;
2727

28-
static bool isFlo2DFile( const std::string &fileName );
29-
3028
private:
3129
struct CellCenter
3230
{

external/mdal/frmts/mdal_hec2d.cpp

+7-28
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,36 @@
1818
static HdfFile openHdfFile( const std::string &fileName )
1919
{
2020
HdfFile file( fileName );
21-
if ( !file.isValid() )
22-
{
23-
throw MDAL_Status::Err_UnknownFormat;
24-
}
21+
if ( !file.isValid() ) throw MDAL_Status::Err_UnknownFormat;
2522
return file;
2623
}
2724

2825
static HdfGroup openHdfGroup( const HdfFile &hdfFile, const std::string &name )
2926
{
3027
HdfGroup grp = hdfFile.group( name );
31-
if ( !grp.isValid() )
32-
{
33-
throw MDAL_Status::Err_UnknownFormat;
34-
}
28+
if ( !grp.isValid() ) throw MDAL_Status::Err_UnknownFormat;
3529
return grp;
3630
}
3731

3832
static HdfGroup openHdfGroup( const HdfGroup &hdfGroup, const std::string &name )
3933
{
4034
HdfGroup grp = hdfGroup.group( name );
41-
if ( !grp.isValid() )
42-
{
43-
throw MDAL_Status::Err_UnknownFormat;
44-
}
35+
if ( !grp.isValid() ) throw MDAL_Status::Err_UnknownFormat;
4536
return grp;
4637
}
4738

4839
static HdfDataset openHdfDataset( const HdfGroup &hdfGroup, const std::string &name )
4940
{
5041
HdfDataset dsFileType = hdfGroup.dataset( name );
51-
if ( !dsFileType.isValid() )
52-
{
53-
throw MDAL_Status::Err_UnknownFormat;
54-
}
42+
if ( !dsFileType.isValid() ) throw MDAL_Status::Err_UnknownFormat;
5543
return dsFileType;
5644
}
5745

5846

5947
static std::string openHdfAttribute( const HdfFile &hdfFile, const std::string &name )
6048
{
6149
HdfAttribute attr = hdfFile.attribute( name );
62-
if ( !attr.isValid() )
63-
{
64-
throw MDAL_Status::Err_UnknownFormat;
65-
}
50+
if ( !attr.isValid() ) throw MDAL_Status::Err_UnknownFormat;
6651
return attr.readString();
6752
}
6853

@@ -360,10 +345,7 @@ std::vector<std::string> MDAL::DriverHec2D::read2DFlowAreasNamesOld( HdfGroup gG
360345
{
361346
HdfDataset dsNames = openHdfDataset( gGeom2DFlowAreas, "Names" );
362347
std::vector<std::string> names = dsNames.readArrayString();
363-
if ( names.empty() )
364-
{
365-
throw MDAL_Status::Err_InvalidData;
366-
}
348+
if ( names.empty() ) throw MDAL_Status::Err_InvalidData;
367349
return names;
368350
}
369351

@@ -432,10 +414,7 @@ std::vector<std::string> MDAL::DriverHec2D::read2DFlowAreasNames505( HdfGroup gG
432414
H5Tclose( attributeHID );
433415
H5Tclose( stringHID );
434416
std::vector<std::string> names;
435-
if ( attributes.empty() )
436-
{
437-
throw MDAL_Status::Err_InvalidData;
438-
}
417+
if ( attributes.empty() ) throw MDAL_Status::Err_InvalidData;
439418

440419
for ( const auto &attr : attributes )
441420
{

0 commit comments

Comments
 (0)