Files
LBPM/IO/Reader.cpp

528 lines
22 KiB
C++
Raw Normal View History

2018-06-11 15:19:05 -04:00
/*
Copyright 2013--2018 James E. McClure, Virginia Polytechnic & State University
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include "IO/Reader.h"
#include "IO/HDF5_IO.h"
2021-03-17 10:24:14 -04:00
#include "IO/IOHelpers.h"
2014-11-04 21:58:20 -05:00
#include "IO/Mesh.h"
#include "IO/MeshDatabase.h"
2017-01-31 08:22:29 -05:00
#include "IO/silo.h"
#include "common/Utilities.h"
2017-01-31 08:22:29 -05:00
#include <ProfilerApp.h>
2021-03-17 10:24:14 -04:00
#include <cstdio>
#include <fstream>
#include <iostream>
2021-03-17 10:24:14 -04:00
#include <map>
#include <string.h>
#include <vector>
2014-11-04 21:58:20 -05:00
2015-02-13 11:43:41 -05:00
// Inline function to read line without a return argument
2021-03-17 10:24:14 -04:00
static inline void fgetl( char *str, int num, FILE *stream )
2015-02-13 11:43:41 -05:00
{
2021-03-17 10:24:14 -04:00
char *ptr = fgets( str, num, stream );
if ( 0 ) {
char *temp = (char *) &ptr;
temp++;
}
}
// Check if the file exists
bool fileExists( const std::string &filename )
2015-02-13 11:43:41 -05:00
{
2021-03-17 10:24:14 -04:00
std::ifstream ifile( filename.c_str() );
return ifile.good();
2015-02-13 11:43:41 -05:00
}
// Get the path to a file
2021-03-17 10:24:14 -04:00
std::string IO::getPath( const std::string &filename )
{
2021-03-17 10:24:14 -04:00
std::string file( filename );
size_t k1 = file.rfind( 47 );
size_t k2 = file.rfind( 92 );
if ( k1 == std::string::npos ) {
k1 = 0;
}
if ( k2 == std::string::npos ) {
k2 = 0;
}
return file.substr( 0, std::max( k1, k2 ) );
}
2021-03-16 17:21:52 -04:00
// List the timesteps in the given directory (dumps.LBPM)
2021-03-17 10:24:14 -04:00
std::vector<std::string> IO::readTimesteps( const std::string &path, const std::string &format )
{
2021-03-16 17:21:52 -04:00
// Get the name of the summary filename
std::string filename = path + "/";
2021-03-17 10:24:14 -04:00
if ( format == "old" || format == "new" ) {
2021-03-16 17:21:52 -04:00
filename += "summary.LBM";
2021-03-17 10:24:14 -04:00
} else if ( format == "silo" ) {
2021-03-16 17:21:52 -04:00
filename += "LBM.visit";
} else if ( format == "hdf5" ) {
filename += "LBM.visit";
2021-03-17 10:24:14 -04:00
} else if ( format == "auto" ) {
bool test_old = fileExists( path + "/summary.LBM" );
bool test_new = fileExists( path + "/LBM.visit" );
if ( test_old && test_new ) {
2021-03-17 10:24:14 -04:00
ERROR( "Unable to determine format (both summary.LBM and LBM.visit exist)" );
} else if ( test_old ) {
filename += "summary.LBM";
} else if ( test_new ) {
2021-03-17 10:24:14 -04:00
filename += "LBM.visit";
} else {
ERROR( "Unable to determine format (neither summary.LBM or LBM.visit exist)" );
}
} else {
2021-03-16 17:21:52 -04:00
ERROR( "Unknown format: " + format );
2021-03-17 10:24:14 -04:00
}
PROFILE_START( "readTimesteps" );
2021-03-16 17:21:52 -04:00
// Read the data
2021-03-17 10:24:14 -04:00
FILE *fid = fopen( filename.c_str(), "rb" );
if ( fid == NULL )
ERROR( "Error opening file" );
std::vector<std::string> timesteps;
char buf[1000];
2021-03-17 10:24:14 -04:00
while ( fgets( buf, sizeof( buf ), fid ) != NULL ) {
std::string line( buf );
line.resize( line.size() - 1 );
2017-01-31 08:22:29 -05:00
auto pos = line.find( "summary.silo" );
if ( pos != std::string::npos )
line.resize( pos );
pos = line.find( "summary.xmf" );
2017-01-31 08:22:29 -05:00
if ( pos != std::string::npos )
2021-03-17 10:24:14 -04:00
line.resize( pos );
if ( line.empty() )
continue;
2021-03-17 10:24:14 -04:00
timesteps.push_back( line );
}
2021-03-17 10:24:14 -04:00
fclose( fid );
PROFILE_STOP( "readTimesteps" );
return timesteps;
return timesteps;
}
2021-03-17 10:24:14 -04:00
// Get the maximum number of domains
int IO::maxDomains( const std::string &path, const std::string &format, const Utilities::MPI &comm )
{
int rank = comm.getRank();
int n_domains = 0;
if ( rank == 0 ) {
// Get the timesteps
auto timesteps = IO::readTimesteps( path, format );
ASSERT( !timesteps.empty() );
// Get the database for the first domain
auto db = IO::getMeshList( path, timesteps[0] );
for ( size_t i = 0; i < db.size(); i++ )
n_domains = std::max<int>( n_domains, db[i].domains.size() );
}
return comm.bcast( n_domains, 0 );
}
2021-03-16 17:21:52 -04:00
// Read the data for the given timestep
2021-03-17 10:24:14 -04:00
std::vector<IO::MeshDataStruct> IO::readData(
const std::string &path, const std::string &timestep, int rank )
2021-03-16 17:21:52 -04:00
{
// Get the mesh databases
auto db = IO::getMeshList( path, timestep );
// Create the data
2021-03-17 10:24:14 -04:00
std::vector<IO::MeshDataStruct> data( db.size() );
for ( size_t i = 0; i < data.size(); i++ ) {
2021-03-16 17:21:52 -04:00
data[i].precision = IO::DataType::Double;
2021-03-17 10:24:14 -04:00
data[i].meshName = db[i].name;
data[i].mesh = getMesh( path, timestep, db[i], rank );
2021-03-16 17:21:52 -04:00
data[i].vars.resize( db[i].variables.size() );
2021-03-17 10:24:14 -04:00
for ( size_t j = 0; j < db[i].variables.size(); j++ )
data[i].vars[j] = getVariable( path, timestep, db[i], rank, db[i].variables[j].name );
INSIST( data[i].check(), "Failed check of " + data[i].meshName );
2021-03-16 17:21:52 -04:00
}
return data;
}
// Read the list of variables for the given timestep
2021-03-17 10:24:14 -04:00
std::vector<IO::MeshDatabase> IO::getMeshList(
const std::string &path, const std::string &timestep )
{
std::string filename = path + "/" + timestep + "/LBM.summary";
return IO::read( filename );
}
// Read the given mesh domain
2021-03-17 10:24:14 -04:00
std::shared_ptr<IO::Mesh> IO::getMesh( const std::string &path, const std::string &timestep,
const IO::MeshDatabase &meshDatabase, int domain )
{
2021-03-17 10:24:14 -04:00
PROFILE_START( "getMesh" );
std::shared_ptr<IO::Mesh> mesh;
if ( meshDatabase.format == FileFormat::OLD ) {
// Old format (binary doubles)
2014-11-04 21:58:20 -05:00
std::string filename = path + "/" + timestep + "/" + meshDatabase.domains[domain].file;
2021-03-17 10:24:14 -04:00
FILE *fid = fopen( filename.c_str(), "rb" );
INSIST( fid != NULL, "Error opening file" );
fseek( fid, 0, SEEK_END );
2021-03-17 10:24:14 -04:00
size_t bytes = ftell( fid );
size_t N_max = bytes / sizeof( double ) + 1000;
double *data = new double[N_max];
2021-03-17 10:24:14 -04:00
fseek( fid, 0, SEEK_SET );
size_t count = fread( data, sizeof( double ), N_max, fid );
fclose( fid );
if ( count % 3 != 0 )
ERROR( "Error reading file" );
if ( meshDatabase.type == IO::MeshType::PointMesh ) {
size_t N = count / 3;
auto pointlist = std::make_shared<PointList>( N );
2021-03-17 10:24:14 -04:00
std::vector<Point> &P = pointlist->points;
for ( size_t i = 0; i < N; i++ ) {
P[i].x = data[3 * i + 0];
P[i].y = data[3 * i + 1];
P[i].z = data[3 * i + 2];
}
mesh = pointlist;
2021-03-17 10:24:14 -04:00
} else if ( meshDatabase.type == IO::MeshType::SurfaceMesh ) {
if ( count % 9 != 0 )
ERROR( "Error reading file (2)" );
size_t N_tri = count / 9;
auto trilist = std::make_shared<TriList>( N_tri );
2021-03-17 10:24:14 -04:00
std::vector<Point> &A = trilist->A;
std::vector<Point> &B = trilist->B;
std::vector<Point> &C = trilist->C;
for ( size_t i = 0; i < N_tri; i++ ) {
A[i].x = data[9 * i + 0];
A[i].y = data[9 * i + 1];
A[i].z = data[9 * i + 2];
B[i].x = data[9 * i + 3];
B[i].y = data[9 * i + 4];
B[i].z = data[9 * i + 5];
C[i].x = data[9 * i + 6];
C[i].y = data[9 * i + 7];
C[i].z = data[9 * i + 8];
}
mesh = trilist;
2021-03-17 10:24:14 -04:00
} else if ( meshDatabase.type == IO::MeshType::VolumeMesh ) {
// this was never supported in the old format
mesh = std::make_shared<DomainMesh>();
} else {
2021-03-17 10:24:14 -04:00
ERROR( "Unknown mesh type" );
}
2021-03-17 10:24:14 -04:00
delete[] data;
} else if ( meshDatabase.format == FileFormat::NEW ||
meshDatabase.format == FileFormat::NEW_SINGLE ) {
2021-03-17 10:24:14 -04:00
const DatabaseEntry &database = meshDatabase.domains[domain];
std::string filename = path + "/" + timestep + "/" + database.file;
FILE *fid = fopen( filename.c_str(), "rb" );
fseek( fid, database.offset, SEEK_SET );
2014-11-04 21:58:20 -05:00
char line[1000];
2021-03-17 10:24:14 -04:00
fgetl( line, 1000, fid );
size_t i1 = find( line, ':' );
size_t i2 = find( &line[i1 + 1], ':' ) + i1 + 1;
size_t bytes = atol( &line[i2 + 1] );
char *data = new char[bytes];
size_t count = fread( data, 1, bytes, fid );
fclose( fid );
ASSERT( count == bytes );
if ( meshDatabase.meshClass == "PointList" ) {
mesh = std::make_shared<IO::PointList>();
2021-03-17 10:24:14 -04:00
} else if ( meshDatabase.meshClass == "TriMesh" ) {
mesh = std::make_shared<IO::TriMesh>();
2021-03-17 10:24:14 -04:00
} else if ( meshDatabase.meshClass == "TriList" ) {
mesh = std::make_shared<IO::TriList>();
2021-03-17 10:24:14 -04:00
} else if ( meshDatabase.meshClass == "DomainMesh" ) {
mesh = std::make_shared<IO::DomainMesh>();
2014-11-04 21:58:20 -05:00
} else {
2021-03-17 10:24:14 -04:00
ERROR( "Unknown mesh class" );
2014-11-04 21:58:20 -05:00
}
2021-03-17 10:24:14 -04:00
mesh->unpack( std::pair<size_t, void *>( bytes, data ) );
delete[] data;
} else if ( meshDatabase.format == FileFormat::SILO ) {
2017-01-31 08:22:29 -05:00
// Reading a silo file
#ifdef USE_SILO
2021-03-17 10:24:14 -04:00
const DatabaseEntry &database = meshDatabase.domains[domain];
std::string filename = path + "/" + timestep + "/" + database.file;
auto fid = silo::open( filename, silo::READ );
if ( meshDatabase.meshClass == "PointList" ) {
Array<double> coords = silo::readPointMesh<double>( fid, database.name );
2021-03-17 10:24:14 -04:00
ASSERT( coords.size( 1 ) == 3 );
auto mesh2 = std::make_shared<IO::PointList>( coords.size( 0 ) );
2021-03-17 10:24:14 -04:00
for ( size_t i = 0; i < coords.size( 1 ); i++ ) {
mesh2->points[i].x = coords( i, 0 );
mesh2->points[i].y = coords( i, 1 );
mesh2->points[i].z = coords( i, 2 );
2017-02-03 11:26:08 -05:00
}
mesh = mesh2;
2021-03-17 10:24:14 -04:00
} else if ( meshDatabase.meshClass == "TriMesh" || meshDatabase.meshClass == "TriList" ) {
2017-02-03 11:26:08 -05:00
Array<double> coords;
Array<int> tri;
silo::readTriMesh( fid, database.name, coords, tri );
2021-03-17 10:24:14 -04:00
ASSERT( tri.size( 1 ) == 3 && coords.size( 1 ) == 3 );
int N_tri = tri.size( 0 );
int N_point = coords.size( 0 );
auto mesh2 = std::make_shared<IO::TriMesh>( N_tri, N_point );
2021-03-17 10:24:14 -04:00
for ( int i = 0; i < N_point; i++ ) {
mesh2->vertices->points[i].x = coords( i, 0 );
mesh2->vertices->points[i].y = coords( i, 1 );
mesh2->vertices->points[i].z = coords( i, 2 );
2017-02-03 11:26:08 -05:00
}
2021-03-17 10:24:14 -04:00
for ( int i = 0; i < N_tri; i++ ) {
mesh2->A[i] = tri( i, 0 );
mesh2->B[i] = tri( i, 1 );
mesh2->C[i] = tri( i, 2 );
2017-02-03 11:26:08 -05:00
}
2021-03-17 10:24:14 -04:00
if ( meshDatabase.meshClass == "TriMesh" ) {
2017-02-03 11:26:08 -05:00
mesh = mesh2;
2021-03-17 10:24:14 -04:00
} else if ( meshDatabase.meshClass == "TriList" ) {
2017-02-03 11:26:08 -05:00
auto trilist = IO::getTriList( std::dynamic_pointer_cast<IO::Mesh>( mesh2 ) );
2021-03-17 10:24:14 -04:00
mesh = trilist;
2017-02-03 11:26:08 -05:00
}
2021-03-17 10:24:14 -04:00
} else if ( meshDatabase.meshClass == "DomainMesh" ) {
2017-01-31 08:22:29 -05:00
std::vector<double> range;
std::vector<int> N;
silo::readUniformMesh( fid, database.name, range, N );
2021-03-17 10:24:14 -04:00
auto rankinfo = silo::read<int>( fid, database.name + "_rankinfo" );
2017-01-31 08:22:29 -05:00
RankInfoStruct rank_data( rankinfo[0], rankinfo[1], rankinfo[2], rankinfo[3] );
mesh = std::make_shared<IO::DomainMesh>( rank_data, N[0], N[1], N[2],
range[1] - range[0], range[3] - range[2], range[5] - range[4] );
2017-01-31 08:22:29 -05:00
} else {
2021-03-17 10:24:14 -04:00
ERROR( "Unknown mesh class" );
2017-01-31 08:22:29 -05:00
}
silo::close( fid );
#else
2021-03-17 10:24:14 -04:00
ERROR( "Build without silo support" );
#endif
} else if ( meshDatabase.format == FileFormat::HDF5 ) {
// Reading an hdf5 file
#ifdef USE_HDF5
auto &database = meshDatabase.domains[domain];
auto filename = path + "/" + timestep + "/" + database.file;
auto fid = IO::HDF5::openHDF5( filename, "r" );
auto gid = IO::HDF5::openGroup( fid, database.name );
if ( meshDatabase.meshClass == "PointList" ) {
std::vector<double> x, y, z;
IO::HDF5::readHDF5( gid, "x", x );
IO::HDF5::readHDF5( gid, "y", y );
IO::HDF5::readHDF5( gid, "z", z );
ASSERT( y.size() == x.size() && z.size() == x.size() );
auto mesh2 = std::make_shared<IO::PointList>( x.size() );
for ( size_t i = 0; i < x.size(); i++ ) {
mesh2->points[i].x = x[i];
mesh2->points[i].y = y[i];
mesh2->points[i].z = z[i];
}
mesh = mesh2;
} else if ( meshDatabase.meshClass == "TriMesh" || meshDatabase.meshClass == "TriList" ) {
// Read the points
std::vector<double> x, y, z;
IO::HDF5::readHDF5( gid, "x", x );
IO::HDF5::readHDF5( gid, "y", y );
IO::HDF5::readHDF5( gid, "z", z );
// Read the triangles
Array<int> tri;
IO::HDF5::readHDF5( gid, "tri", tri );
ASSERT( tri.size( 0 ) == 3 );
size_t N_tri = tri.size( 1 );
size_t N_point = x.size();
auto mesh2 = std::make_shared<IO::TriMesh>( N_tri, N_point );
for ( size_t i = 0; i < N_point; i++ ) {
mesh2->vertices->points[i].x = x[i];
mesh2->vertices->points[i].y = y[i];
mesh2->vertices->points[i].z = z[i];
}
for ( size_t i = 0; i < N_tri; i++ ) {
mesh2->A[i] = tri( 0, i );
mesh2->B[i] = tri( 1, i );
mesh2->C[i] = tri( 2, i );
}
if ( meshDatabase.meshClass == "TriMesh" ) {
mesh = mesh2;
} else if ( meshDatabase.meshClass == "TriList" ) {
auto trilist = IO::getTriList( std::dynamic_pointer_cast<IO::Mesh>( mesh2 ) );
mesh = trilist;
}
} else if ( meshDatabase.meshClass == "DomainMesh" ) {
std::vector<double> range;
std::vector<int> N;
std::vector<int> rankinfo;
IO::HDF5::readHDF5( gid, "range", range );
IO::HDF5::readHDF5( gid, "N", N );
IO::HDF5::readHDF5( gid, "rankinfo", rankinfo );
RankInfoStruct rank_data( rankinfo[0], rankinfo[1], rankinfo[2], rankinfo[3] );
mesh = std::make_shared<IO::DomainMesh>( rank_data, N[0], N[1], N[2],
range[1] - range[0], range[3] - range[2], range[5] - range[4] );
} else {
ERROR( "Unknown mesh class" );
}
IO::HDF5::closeGroup( gid );
IO::HDF5::closeHDF5( fid );
#else
ERROR( "Build without hdf5 support" );
2017-01-31 08:22:29 -05:00
#endif
} else {
2021-03-17 10:24:14 -04:00
ERROR( "Unknown format" );
}
2021-03-17 10:24:14 -04:00
PROFILE_STOP( "getMesh" );
return mesh;
}
2014-11-04 21:58:20 -05:00
// Read the given variable for the given mesh domain
2021-03-17 10:24:14 -04:00
std::shared_ptr<IO::Variable> IO::getVariable( const std::string &path, const std::string &timestep,
const MeshDatabase &meshDatabase, int domain, const std::string &variable )
2014-11-04 21:58:20 -05:00
{
2021-03-17 10:24:14 -04:00
std::pair<std::string, std::string> key( meshDatabase.domains[domain].name, variable );
auto it = meshDatabase.variable_data.find( key );
2021-03-17 10:24:14 -04:00
if ( it == meshDatabase.variable_data.end() )
return std::shared_ptr<IO::Variable>();
2017-02-03 11:26:08 -05:00
std::shared_ptr<IO::Variable> var;
if ( meshDatabase.format == FileFormat::NEW || meshDatabase.format == FileFormat::NEW_SINGLE ) {
2021-03-17 10:24:14 -04:00
const DatabaseEntry &database = it->second;
std::string filename = path + "/" + timestep + "/" + database.file;
FILE *fid = fopen( filename.c_str(), "rb" );
fseek( fid, database.offset, SEEK_SET );
2017-02-03 11:26:08 -05:00
char line[1000];
2021-03-17 10:24:14 -04:00
fgetl( line, 1000, fid );
size_t i1 = find( line, ':' );
size_t i2 = find( &line[i1 + 1], ':' ) + i1 + 1;
std::vector<std::string> values = splitList( &line[i2 + 1], ',' );
ASSERT( values.size() == 5 );
int dim = atoi( values[0].c_str() );
auto type = values[1];
2021-03-17 10:24:14 -04:00
size_t N = atol( values[2].c_str() );
size_t bytes = atol( values[3].c_str() );
std::string precision = values[4];
var = std::make_shared<IO::Variable>();
2021-03-17 10:24:14 -04:00
var->dim = dim;
var->type = getVariableType( type );
2021-03-17 10:24:14 -04:00
var->name = variable;
var->data.resize( N, dim );
if ( precision == "double" ) {
size_t count = fread( var->data.data(), sizeof( double ), N * dim, fid );
ASSERT( count * sizeof( double ) == bytes );
2017-02-03 11:26:08 -05:00
} else {
2021-03-17 10:24:14 -04:00
ERROR( "Format not implimented" );
2017-02-03 11:26:08 -05:00
}
2021-03-17 10:24:14 -04:00
fclose( fid );
} else if ( meshDatabase.format == FileFormat::SILO ) {
2017-02-03 11:26:08 -05:00
// Reading a silo file
#ifdef USE_SILO
2021-03-17 10:24:14 -04:00
const auto &database = meshDatabase.domains[domain];
2017-02-03 11:26:08 -05:00
auto variableDatabase = meshDatabase.getVariableDatabase( variable );
2021-03-17 10:24:14 -04:00
std::string filename = path + "/" + timestep + "/" + database.file;
auto fid = silo::open( filename, silo::READ );
var = std::make_shared<Variable>( variableDatabase.dim, variableDatabase.type, variable );
2021-03-17 10:24:14 -04:00
if ( meshDatabase.meshClass == "PointList" ) {
var->data = silo::readPointMeshVariable<double>( fid, variable );
2021-03-17 10:24:14 -04:00
} else if ( meshDatabase.meshClass == "TriMesh" || meshDatabase.meshClass == "TriList" ) {
var->data = silo::readTriMeshVariable<double>( fid, variable );
2021-03-17 10:24:14 -04:00
} else if ( meshDatabase.meshClass == "DomainMesh" ) {
var->data = silo::readUniformMeshVariable<double>( fid, variable );
2017-02-03 11:26:08 -05:00
} else {
2021-03-17 10:24:14 -04:00
ERROR( "Unknown mesh class" );
2017-02-03 11:26:08 -05:00
}
silo::close( fid );
#else
2021-03-17 10:24:14 -04:00
ERROR( "Build without silo support" );
2017-02-03 11:26:08 -05:00
#endif
} else if ( meshDatabase.format == FileFormat::HDF5 ) {
// Reading an hdf5 file
#ifdef USE_HDF5
auto &database = meshDatabase.domains[domain];
auto varDatabase = meshDatabase.getVariableDatabase( variable );
auto filename = path + "/" + timestep + "/" + database.file;
var = std::make_shared<Variable>( varDatabase.dim, varDatabase.type, variable );
auto fid = IO::HDF5::openHDF5( filename, "r" );
auto gid = IO::HDF5::openGroup( fid, database.name );
IO::HDF5::readHDF5( gid, var->name, var->data );
IO::HDF5::closeHDF5( fid );
if ( meshDatabase.meshClass == "PointList" || meshDatabase.meshClass == "TriMesh" ||
meshDatabase.meshClass == "TriList" ) {
if ( var->data.ndim() == 2 && var->data.size( 0 ) == 3 )
var->data = var->data.permute( { 1, 0 } );
} else if ( meshDatabase.meshClass == "DomainMesh" ) {
if ( var->data.ndim() == 4 && var->data.size( 0 ) == 3 )
var->data = var->data.permute( { 1, 2, 3, 0 } );
} else {
ERROR( "Unknown mesh class" );
}
#else
ERROR( "Build without silo support" );
#endif
2014-11-05 16:54:18 -05:00
} else {
2021-03-17 10:24:14 -04:00
ERROR( "Unknown format" );
2014-11-05 16:54:18 -05:00
}
return var;
2014-11-04 21:58:20 -05:00
}
/****************************************************
2021-03-17 10:24:14 -04:00
* Reformat the variable to match the mesh *
****************************************************/
void IO::reformatVariable( const IO::Mesh &mesh, IO::Variable &var )
{
if ( mesh.className() == "DomainMesh" ) {
2021-03-17 10:24:14 -04:00
const IO::DomainMesh &mesh2 = dynamic_cast<const IO::DomainMesh &>( mesh );
if ( var.type == VariableType::NodeVariable ) {
2021-03-17 10:24:14 -04:00
size_t N2 =
var.data.length() / ( ( mesh2.nx + 1 ) * ( mesh2.ny + 1 ) * ( mesh2.nz + 1 ) );
ASSERT(
( mesh2.nx + 1 ) * ( mesh2.ny + 1 ) * ( mesh2.nz + 1 ) * N2 == var.data.length() );
var.data.reshape(
{ (size_t) mesh2.nx + 1, (size_t) mesh2.ny + 1, (size_t) mesh2.nz + 1, N2 } );
} else if ( var.type == VariableType::EdgeVariable ) {
2021-03-17 10:24:14 -04:00
ERROR( "Not finished" );
} else if ( var.type == VariableType::SurfaceVariable ) {
2021-03-17 10:24:14 -04:00
ERROR( "Not finished" );
} else if ( var.type == VariableType::VolumeVariable ) {
2021-03-17 10:24:14 -04:00
size_t N2 = var.data.length() / ( mesh2.nx * mesh2.ny * mesh2.nz );
ASSERT( mesh2.nx * mesh2.ny * mesh2.nz * N2 == var.data.length() );
var.data.reshape( { (size_t) mesh2.nx, (size_t) mesh2.ny, (size_t) mesh2.nz, N2 } );
} else {
2021-03-17 10:24:14 -04:00
ERROR( "Invalid variable type" );
}
} else if ( mesh.className() == "PointList" ) {
2021-03-17 10:24:14 -04:00
const IO::PointList &mesh2 = dynamic_cast<const IO::PointList &>( mesh );
size_t N = mesh2.points.size();
size_t N_var = var.data.length() / N;
ASSERT( N * N_var == var.data.length() );
2017-02-03 11:26:08 -05:00
var.data.reshape( { N, N_var } );
2021-03-17 10:24:14 -04:00
} else if ( mesh.className() == "TriMesh" || mesh.className() == "TriList" ) {
std::shared_ptr<Mesh> mesh_ptr( const_cast<Mesh *>( &mesh ), []( void * ) {} );
2017-02-03 11:26:08 -05:00
std::shared_ptr<TriMesh> mesh2 = getTriMesh( mesh_ptr );
if ( var.type == VariableType::NodeVariable ) {
2021-03-17 10:24:14 -04:00
size_t N = mesh2->vertices->points.size();
size_t N_var = var.data.length() / N;
ASSERT( N * N_var == var.data.length() );
2017-02-03 11:26:08 -05:00
var.data.reshape( { N, N_var } );
} else if ( var.type == VariableType::EdgeVariable ) {
2021-03-17 10:24:14 -04:00
ERROR( "Not finished" );
} else if ( var.type == VariableType::SurfaceVariable ) {
2021-03-17 10:24:14 -04:00
ERROR( "Not finished" );
} else if ( var.type == VariableType::VolumeVariable ) {
2021-03-17 10:24:14 -04:00
size_t N = mesh2->A.size();
size_t N_var = var.data.length() / N;
ASSERT( N * N_var == var.data.length() );
2017-02-03 11:26:08 -05:00
var.data.reshape( { N, N_var } );
} else {
2021-03-17 10:24:14 -04:00
ERROR( "Invalid variable type" );
2017-02-03 11:26:08 -05:00
}
} else {
2021-03-17 10:24:14 -04:00
ERROR( "Unknown mesh type" );
}
}