From: michael Date: Sat, 12 Dec 2020 13:00:48 +0000 (+0100) Subject: Added functions to set and extract field values X-Git-Tag: V9_7_0~98 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cdb5b9215bff5c12e3f00ddceb73f78b07b89008;p=tools%2Fsolverlab.git Added functions to set and extract field values --- diff --git a/CDMATH/mesh/inc/Field.hxx b/CDMATH/mesh/inc/Field.hxx index 4323fe0..70cfc80 100755 --- a/CDMATH/mesh/inc/Field.hxx +++ b/CDMATH/mesh/inc/Field.hxx @@ -225,6 +225,12 @@ class Field const double* getValues ( void ) const ; + void getValues ( Vector myVector ) const ; + + void setValues ( Vector values ) ; + + void setValues ( double * values, int nbValues ) ; + const std::string getName ( void ) const; const Mesh& getMesh ( void ) const ; diff --git a/CDMATH/mesh/src/Field.cxx b/CDMATH/mesh/src/Field.cxx index ad36403..2934d6a 100755 --- a/CDMATH/mesh/src/Field.cxx +++ b/CDMATH/mesh/src/Field.cxx @@ -17,6 +17,8 @@ #include #include +#include + using namespace MEDCoupling; using namespace std; @@ -682,6 +684,39 @@ Field::getValues ( void ) const return _field->getArray()->getConstPointer() ; } +//---------------------------------------------------------------------- +void +Field::getValues ( Vector myVector ) const +//---------------------------------------------------------------------- +{ + if( myVector.size() != _field->getNumberOfTuples() * _field->getNumberOfComponents() ) + throw CdmathException("Error : Field::getValues requires a vector having the same number of component as fiedl values"); + + const double * fieldValues = _field->getArray()->getConstPointer(); + double * vectorValues = myVector.getValues().getValues(); + + memcpy(vectorValues, fieldValues,myVector.size()*sizeof(double)) ; +} + +void +Field::setValues ( Vector myVector ) +//---------------------------------------------------------------------- +{ + if( myVector.size() != _field->getNumberOfTuples() * _field->getNumberOfComponents() ) + throw CdmathException("Error : Field::setValues requires a vector having the same number of component as fiedl values"); + + double * vectorValues = myVector.getValues().getValues(); + + setValues ( vectorValues, myVector.size() ); +} + +void +Field::setValues ( double * values, int nbValues ) +{ + double * fieldValues = _field->getArray()->getPointer() ; + memcpy(fieldValues,values,nbValues*sizeof(double)) ; +} + //---------------------------------------------------------------------- const string Field::getName ( void ) const