Salome HOME
Updated path
[tools/solverlab.git] / CDMATH / mesh / src / Field.cxx
index 64044f634f34169ed5982786d9a7bc8ba035cdef..b7a4e94c363105167337b89efc0127702074a129 100755 (executable)
@@ -17,6 +17,8 @@
 
 #include <fstream>
 #include <sstream>
+#include <cstring>
+
 using namespace MEDCoupling;
 using namespace std;
 
@@ -68,10 +70,10 @@ void Field::buildFieldMemoryStructure()
        {
                _field=MEDCouplingFieldDouble::New(ON_CELLS);
                array->alloc(_mesh.getNumberOfFaces(),_numberOfComponents);
-               DataArrayInt *desc=DataArrayInt::New();
-               DataArrayInt *descI=DataArrayInt::New();
-               DataArrayInt *revDesc=DataArrayInt::New();
-               DataArrayInt *revDescI=DataArrayInt::New();
+               DataArrayIdType *desc=DataArrayIdType::New();
+               DataArrayIdType *descI=DataArrayIdType::New();
+               DataArrayIdType *revDesc=DataArrayIdType::New();
+               DataArrayIdType *revDescI=DataArrayIdType::New();
                MEDCouplingUMesh *m3=mu->buildDescendingConnectivity(desc,descI,revDesc,revDescI);
                _field->setMesh(m3);
                desc->decrRef();
@@ -401,18 +403,21 @@ Field::readFieldMed( const std::string & fileNameRadical,
 }
 
 
-DoubleTab
+Vector
 Field::getNormEuclidean() const
 {
-       DoubleTab norm(getNumberOfElements(),_field->magnitude()->getArray()->getConstPointer());
-       return norm;
+       Vector result(_numberOfComponents);
+       DoubleTab norm(_numberOfComponents,_field->magnitude()->getArray()->getConstPointer());
+       result.setValues(norm);
+       
+       return result;
 }
 
 double
 Field::max(int component) const
 {
-       if( component >= getNumberOfComponents() )
-               throw CdmathException("double Field::max() : component number should be smaller than field number of components");
+       if( component >= getNumberOfComponents() || component < 0)
+               throw CdmathException("double Field::max() : component number should be between 0 and the field number of components");
                
        double result=-1e100;
        for(int i=0; i<getNumberOfElements() ; i++)
@@ -425,8 +430,8 @@ Field::max(int component) const
 double
 Field::min(int component) const
 {
-       if( component >= getNumberOfComponents() )
-               throw CdmathException("double Field::min() : component number should be smaller than field number of components");
+       if( component >= getNumberOfComponents() || component < 0)
+               throw CdmathException("double Field::min() : component number should be between 0 and the field number of components");
                
        double result=1e100;
        for(int i=0; i<getNumberOfElements() ; i++)
@@ -545,14 +550,12 @@ Field::normMax ( ) const
 //----------------------------------------------------------------------
 {
        int nbComp=_field->getNumberOfComponents();
-       int nbElems=getNumberOfElements();
-
-       Vector result(nbComp);//Vector containing the Linfinity norm of each component
+       double res[nbComp];//Pointer containing the L2 norm of each component
+       _field->normMax(res);
+       Vector result(nbComp);//Vector containing the L2 norm of each component
 
-       for(int i=0; i<nbElems ; i++)
-        for(int j=0; j<nbComp ; j++)
-            if(fabs((*this)(i,j))>result(j))
-                result(j)=fabs((*this)(i,j));
+       for(int i=0; i<nbComp ; i++)
+               result(i)=res[i];
 
        return result;
 }
@@ -681,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
@@ -1072,6 +1108,15 @@ Field::getValuesOnComponent(int compo) const
        return v;
 }
 
+std::vector< double > 
+Field::getFieldValues(int compo) const 
+{
+       std::vector< double > v(getNumberOfElements());
+       for(int i=0;i<getNumberOfElements();i++)
+               v[i]=(*this)(i,compo);
+       return v;
+}
+
 std::ostream& operator<<(std::ostream& out, const Field& field )
 {
        cout << "Field " << field.getName() << " : " << endl ;