Back to index

salome-med  6.5.0
Public Member Functions | Private Attributes
MEDMEM::_field< T > Class Template Reference

#include <MEDMEM_DriverTools.hxx>

Collaboration diagram for MEDMEM::_field< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 _field (MED_EN::med_type_champ theType, int nb_sub, int total_nb_comp)
std::vector< T > & addComponent (int nb_values)
std::list< std::pair< FIELD_
*, int > > 
getField (std::vector< _groupe > &groupes) const
virtual void dump (std::ostream &) const

Private Attributes

std::vector< std::vector< T > > comp_values

Detailed Description

template<class T>
class MEDMEM::_field< T >

Definition at line 198 of file MEDMEM_DriverTools.hxx.


Constructor & Destructor Documentation

template<class T>
MEDMEM::_field< T >::_field ( MED_EN::med_type_champ  theType,
int  nb_sub,
int  total_nb_comp 
) [inline]

Definition at line 202 of file MEDMEM_DriverTools.hxx.

    : _fieldBase( theType, nb_sub ) { comp_values.reserve( total_nb_comp ); }

Member Function Documentation

template<class T >
std::vector< T > & MEDMEM::_field< T >::addComponent ( int  nb_values)

Definition at line 355 of file MEDMEM_DriverTools.hxx.

{
  comp_values.push_back( std::vector< T >() );
  std::vector< T >& res = comp_values.back();
  res.resize( nb_values );
  return res;
}
template<class T >
void MEDMEM::_field< T >::dump ( std::ostream &  os) const [virtual]

Definition at line 566 of file MEDMEM_DriverTools.hxx.

{
  _fieldBase::dump(os);
  os << endl;
  for ( int i = 0 ; i < (int)comp_values.size(); ++i )
  {
    os << "    " << i+1 << "-th component, nb values: " << comp_values[ i ].size() << endl;
  }
}
template<class T >
std::list< std::pair< FIELD_ *, int > > MEDMEM::_field< T >::getField ( std::vector< _groupe > &  groupes) const

Definition at line 369 of file MEDMEM_DriverTools.hxx.

{
  const char* LOC = "_field< T >::getField()";

  std::list<std::pair< FIELD_*, int> > res;

  // gauss array data
  int nbtypegeo = 0;
  vector<int> nbelgeoc(2,0), nbgaussgeo(2,0);

  int i_comp_tot = 0, nb_fields = 0;
  std::set<int> supp_id_set; // to create a new field when support repeats if hasCommonSupport()
  std::vector< _sub_data >::const_iterator sub_data, sub_end = _sub.end();

  _groupe*  grp = 0;
  GROUP* medGrp = 0;
  if ( hasCommonSupport() ) // several subs are combined into one field
  {
    grp    = & groupes[ _group_id ];
    medGrp = grp->medGroup;
    if ( !grp || grp->empty() || !medGrp || !medGrp->getNumberOfTypes())
      return res;

    // Make gauss array data
    nbtypegeo = medGrp->getNumberOfTypes();
    nbelgeoc  .resize( nbtypegeo + 1, 0 );
    nbgaussgeo.resize( nbtypegeo + 1, 0 );
    const int *                nbElemByType = medGrp->getNumberOfElements();
    const MED_EN::medGeometryElement* types = medGrp->getTypes();
    for (int iType = 0; iType < nbtypegeo; ++iType) {
      // nb elem by type
      nbelgeoc  [ iType+1 ] = nbelgeoc[ iType ] + nbElemByType[ iType ];
      // nb gauss by type; find a sub for a geo type
      for ( sub_data = _sub.begin(); sub_data != sub_end; ++sub_data ) {
        _groupe & sub_grp = groupes[ sub_data->_supp_id ];
        if ( !sub_grp.empty() && sub_grp.mailles[0]->geometricType == types[ iType ])
          break;
      }
      ASSERT_MED( sub_data != sub_end );
      nbgaussgeo[ iType+1 ] = sub_data->nbGauss();
    }
  }
  typedef typename MEDMEM_ArrayInterface<T,FullInterlace,NoGauss>::Array TArrayNoGauss;
  typedef typename MEDMEM_ArrayInterface<T,FullInterlace,Gauss>::Array   TArrayGauss;
  FIELD< T, FullInterlace > * f = 0;
  TArrayNoGauss * arrayNoGauss = 0;
  TArrayGauss   * arrayGauss = 0;

  // loop on subs of this field
  int i_sub = 1;
  for ( sub_data = _sub.begin(); sub_data != sub_end; ++sub_data, ++i_sub )
  {
    // nb values in a field
    if ( !hasCommonSupport() ) {
      grp    = & groupes[ sub_data->_supp_id ];
      medGrp = grp->medGroup;
    }
    int nb_val = grp->size();

    // check validity of a sub_data
    bool validSub = true;
    if ( !nb_val ) {
      INFOS_MED("Skip field <" << _name << ">: invalid supporting group "
            << (hasCommonSupport() ? _group_id : sub_data->_supp_id )
            << " of " << i_sub << "-th subcomponent" );
      validSub = false;
    }
    if ( !sub_data->isValidNbGauss() ) {
      INFOS_MED("Skip field <" << _name << ">: different nb of gauss points in components ");
      validSub = false;
    }
    if ( !validSub ) {
      if ( hasCommonSupport() ) {
        if ( !res.empty() ) {
          if(f)
            f->removeReference();
          res.clear();
        }
        return res;
      }
      i_comp_tot += sub_data->nbComponents();
      continue;
    }

    // Create a field

    if ( !f || !hasCommonSupport() || !supp_id_set.insert( sub_data->_supp_id ).second )
    {
      ++nb_fields;
      supp_id_set.clear();
      arrayNoGauss = 0;
      arrayGauss = 0;

      f = new FIELD< T, FullInterlace >();

      f->setNumberOfComponents( sub_data->nbComponents() );
      f->setComponentsNames( & sub_data->_comp_names[ 0 ] );
      f->setNumberOfValues ( nb_val );
      f->setName( _name );
      f->setDescription( _description );
      vector<string> str( sub_data->nbComponents() );
      f->setComponentsDescriptions( &str[0] );
      f->setMEDComponentsUnits( &str[0] );
      if ( !hasCommonSupport() && nb_fields > 1 )
      {
        f->setName( MEDMEM::STRING(_name) << "_Sub_" << nb_fields );
        INFOS_MED("Warning: field |" <<_name<<"| is incompatible with MED format (has "
                  "sub-fields of different nature), so we map its sub-field #"<< nb_fields <<
                  " into a separate field |"<<f->getName() << "|");
      }
      res.push_back( make_pair( f , hasCommonSupport() ? _group_id : sub_data->_supp_id ));
      MESSAGE_MED(" MAKE " << nb_fields << "-th field <" << _name << "> on group_id " << _group_id );

      // make an array
      if ( !sub_data->hasGauss() ) {
        arrayNoGauss = new TArrayNoGauss( sub_data->nbComponents(), nb_val );
        f->setArray( arrayNoGauss );
      }
      else {
        if ( !hasCommonSupport() ) {
          nbtypegeo = 1;
          nbelgeoc  [1] = nb_val;
          nbgaussgeo[1] = sub_data->nbGauss();
        }
        arrayGauss = new TArrayGauss(sub_data->nbComponents(), nb_val,
                                     nbtypegeo, & nbelgeoc[0], & nbgaussgeo[0]);
        f->setArray( arrayGauss );

        // PAL11040 "GIBI driver for Castem fields with Gauss point values"
        const MED_EN::medGeometryElement* types = medGrp->getTypes();
        for (int iGeom = 0; iGeom < nbtypegeo; ++iGeom) {
          ostringstream name;
          name << "Gauss_" << nbgaussgeo[iGeom+1] << "points_on" << types[iGeom] << "geom";
          GAUSS_LOCALIZATION_* loc = GAUSS_LOCALIZATION_::makeDefaultLocalization
            (name.str(), types[iGeom], nbgaussgeo[iGeom+1]);
          f->setGaussLocalization( types[iGeom], loc );
        }
      }
    }

    // Set values

    // get nb elements in a group
    _groupe & sub_grp = groupes[ sub_data->_supp_id ];
    int nb_supp_elems = sub_grp.mailles.size();
    int nb_gauss      = sub_data->nbGauss();
    MESSAGE_MED("insert sub data, group_id: " << sub_data->_supp_id <<
            ", nb values: "               << comp_values[ i_comp_tot ].size() <<
            ", relocMap size: "           << sub_grp.relocMap.size() <<
            ", nb mailles: "              << nb_supp_elems);

#ifdef CASTEM_FULL_INTERLACE
    const int gauss_step = 1;
    const int elem_step = nb_gauss;
#else
    const int gauss_step = nb_supp_elems;
    const int elem_step = 1;
#endif
    int i; // elem index
    // loop on components of a sub
    for ( int i_comp = 1; i_comp <= sub_data->nbComponents(); ++i_comp )
    {
      // store values
      const std::vector< T > & values = comp_values[ i_comp_tot++ ];
      bool oneValue = ( values.size() == 1 );
      ASSERT_MED( oneValue || (int)values.size() == nb_supp_elems * nb_gauss );
      for ( int k = 0; k < nb_supp_elems; ++k )
      {
        const T& val = oneValue ? values[ 0 ] : values[ k * elem_step ];
        const _maille& ma = sub_grp.maille( k );
        if ( medGrp->isOnAllElements() ) {
          i = ma.ordre();
        }
        else {
          std::map<unsigned,int>::const_iterator ordre_i = grp->relocMap.find( ma.ordre() );
          if ( ordre_i == grp->relocMap.end() )
            throw MEDEXCEPTION (LOCALIZED(STRING(LOC) << ", cant find elem index. "
                                          << k << "-th elem: " << ma));
          i = ordre_i->second;
        }
        if ( arrayNoGauss ) {
          arrayNoGauss->setIJ( i, i_comp, val );
        }
        else {
          const T* pVal = & val;
          for ( int iGauss = 1; iGauss <= nb_gauss; ++iGauss, pVal += gauss_step )
            arrayGauss->setIJK( i, i_comp, iGauss, *pVal);
        }
      }
    }
  } // loop on subs of the field

  return res;
}

Here is the call graph for this function:


Member Data Documentation

template<class T>
std::vector< std::vector< T > > MEDMEM::_field< T >::comp_values [private]

Definition at line 200 of file MEDMEM_DriverTools.hxx.


The documentation for this class was generated from the following file: