Skip to content

Commit

Permalink
ADIOS1: Complex Support
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Dec 18, 2019
1 parent a75e557 commit 2582c2d
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 8 deletions.
9 changes: 9 additions & 0 deletions include/openPMD/IO/ADIOS/ADIOS1Auxiliary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ getBP1DataType(Datatype dtype)
case DT::LONG_DOUBLE:
case DT::VEC_LONG_DOUBLE:
return adios_long_double;
case DT::CFLOAT:
case DT::VEC_CFLOAT:
return adios_complex;
case DT::CDOUBLE:
case DT::VEC_CDOUBLE:
return adios_double_complex;
case DT::CLONG_DOUBLE:
case DT::VEC_CLONG_DOUBLE:
throw unsupported_data_error("No native equivalent for Datatype::CLONG_DOUBLE found.");
case DT::STRING:
return adios_string;
case DT::VEC_STRING:
Expand Down
91 changes: 83 additions & 8 deletions src/IO/ADIOS/CommonADIOS1IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <complex>
#include <tuple>
#include <string>

Expand Down Expand Up @@ -185,6 +186,23 @@ CommonADIOS1IOHandlerImpl::flush_attribute(int64_t group, std::string const& nam
*ptr = att.get< long double >();
break;
}
case DT::CFLOAT:
{
auto ptr = reinterpret_cast< std::complex< float >* >(values.get());
*ptr = att.get< std::complex< float > >();
break;
}
case DT::CDOUBLE:
{
auto ptr = reinterpret_cast< std::complex< double >* >(values.get());
*ptr = att.get< std::complex< double > >();
break;
}
case DT::CLONG_DOUBLE:
{
throw std::runtime_error("[ADIOS1] Unknown Attribute datatype (CLONG_DOUBLE)");
break;
}
case DT::STRING:
{
auto const & v = att.get< std::string >();
Expand Down Expand Up @@ -296,6 +314,27 @@ CommonADIOS1IOHandlerImpl::flush_attribute(int64_t group, std::string const& nam
ptr[i] = vec[i];
break;
}
case DT::VEC_CFLOAT:
{
auto ptr = reinterpret_cast< std::complex< float >* >(values.get());
auto const& vec = att.get< std::vector< std::complex< float > > >();
for( size_t i = 0; i < vec.size(); ++i )
ptr[i] = vec[i];
break;
}
case DT::VEC_CDOUBLE:
{
auto ptr = reinterpret_cast< std::complex< double >* >(values.get());
auto const& vec = att.get< std::vector< std::complex< double > > >();
for( size_t i = 0; i < vec.size(); ++i )
ptr[i] = vec[i];
break;
}
case DT::VEC_CLONG_DOUBLE:
{
throw std::runtime_error("[ADIOS1] Unknown Attribute datatype (VEC_CLONG_DOUBLE)");
break;
}
case DT::VEC_STRING:
{
auto ptr = reinterpret_cast< char** >(values.get());
Expand Down Expand Up @@ -668,11 +707,15 @@ CommonADIOS1IOHandlerImpl::openDataset(Writable* writable,
case adios_long_double:
dtype = DT::LONG_DOUBLE;
break;
case adios_complex:
dtype = DT::CFLOAT;
break;
case adios_double_complex:
dtype = DT::CDOUBLE;
break;

case adios_string:
case adios_string_array:
case adios_complex:
case adios_double_complex:
default:
throw unsupported_data_error("[ADIOS1] Datatype not implemented for ADIOS dataset writing");
}
Expand Down Expand Up @@ -822,6 +865,8 @@ CommonADIOS1IOHandlerImpl::readDataset(Writable* writable,
using DT = Datatype;
case DT::DOUBLE:
case DT::FLOAT:
case DT::CDOUBLE:
case DT::CFLOAT:
case DT::SHORT:
case DT::INT:
case DT::LONG:
Expand Down Expand Up @@ -935,14 +980,18 @@ CommonADIOS1IOHandlerImpl::readAttribute(Writable* writable,
case adios_long_double:
size /= sizeof(long double);
break;
case adios_complex:
size /= 8;
break;
case adios_double_complex:
size /= 16;
break;
case adios_string:
break;
case adios_string_array:
size /= sizeof(char*);
break;

case adios_complex:
case adios_double_complex:
default:
throw unsupported_data_error(
"[ADIOS1] readAttribute: Unsupported ADIOS1 attribute datatype '" +
Expand Down Expand Up @@ -1120,6 +1169,14 @@ CommonADIOS1IOHandlerImpl::readAttribute(Writable* writable,
dtype = DT::LONG_DOUBLE;
a = Attribute(*reinterpret_cast< long double* >(data));
break;
case adios_complex:
dtype = DT::CFLOAT;
a = Attribute(*reinterpret_cast< std::complex<float>* >(data));
break;
case adios_double_complex:
dtype = DT::CDOUBLE;
a = Attribute(*reinterpret_cast< std::complex<double>* >(data));
break;
case adios_string:
{
dtype = DT::STRING;
Expand All @@ -1142,8 +1199,6 @@ CommonADIOS1IOHandlerImpl::readAttribute(Writable* writable,
a = Attribute(vs);
break;
}
case adios_complex:
case adios_double_complex:
default:
throw unsupported_data_error(
"[ADIOS1] readAttribute: Unsupported ADIOS1 attribute datatype '" +
Expand Down Expand Up @@ -1294,6 +1349,28 @@ CommonADIOS1IOHandlerImpl::readAttribute(Writable* writable,
a = Attribute(vld);
break;
}
case adios_complex:
{
dtype = DT::VEC_CFLOAT;
auto cf4 = reinterpret_cast< std::complex<float>* >(data);
std::vector< std::complex<float> > vcf;
vcf.resize(size);
for( int i = 0; i < size; ++i )
vcf[i] = cf4[i];
a = Attribute(vcf);
break;
}
case adios_double_complex:
{
dtype = DT::VEC_CDOUBLE;
auto cd8 = reinterpret_cast< std::complex<double>* >(data);
std::vector< std::complex<double> > vcd;
vcd.resize(size);
for( int i = 0; i < size; ++i )
vcd[i] = cd8[i];
a = Attribute(vcd);
break;
}
case adios_string:
{
dtype = DT::STRING;
Expand All @@ -1316,8 +1393,6 @@ CommonADIOS1IOHandlerImpl::readAttribute(Writable* writable,
break;
}

case adios_complex:
case adios_double_complex:
default:
throw unsupported_data_error(
"[ADIOS1] readAttribute: Unsupported ADIOS1 attribute datatype '" +
Expand Down

0 comments on commit 2582c2d

Please sign in to comment.