/*!
* Returns number of tuples expected regarding the spatial discretization of \a this
- * field and number of entities in the underlying mesh.
+ * field and number of entities in the underlying mesh. This method behaves exactly as MEDCouplingFieldDouble::getNumberOfTuples.
* \return int - the number of expected tuples.
* \throw If the spatial discretization of \a this field is NULL.
* \throw If the mesh is not set.
}
/*!
+ * Use MEDCouplingField::getNumberOfTuplesExpected instead of this method. This method will be removed soon, because it is
+ * confusing compared to getNumberOfComponents() and getNumberOfValues() behaviour.
+ *
* Returns number of tuples in \a this field, that depends on
* - the number of entities in the underlying mesh
* - \ref MEDCouplingSpatialDisc "spatial discretization" of \a this field (e.g. number
* of Gauss points if \a this->getTypeOfField() ==
* \ref ParaMEDMEM::ON_GAUSS_PT "ON_GAUSS_PT").
*
- * The returned value does **not depend** on the number of tuples in the data array
+ * The returned value does \b not \b depend on the number of tuples in the data array
* (which has to be equal to the returned value), \b contrary to
* getNumberOfComponents() and getNumberOfValues() that retrieve information from the
- * data array.
+ * data array (Sorry, it is confusing !).
+ * So \b this \b method \b behaves \b exactly \b as MEDCouplingField::getNumberOfTuplesExpected \b method.
+ *
* \warning No checkCoherency() is done here.
* For more info on the data arrays, see \ref MEDCouplingArrayPage.
* \return int - the number of tuples.
* \throw If the mesh is not set.
* \throw If the spatial discretization of \a this field is NULL.
* \throw If the spatial discretization is not fully defined.
+ * \sa MEDCouplingField::getNumberOfTuplesExpected
*/
int MEDCouplingFieldDouble::getNumberOfTuples() const
{
+ //std::cerr << " ******* MEDCouplingFieldDouble::getNumberOfTuples is deprecated : use MEDCouplingField::getNumberOfTuplesExpected instead ! ******" << std::endl;
if(!_mesh)
throw INTERP_KERNEL::Exception("Impossible to retrieve number of tuples because no mesh specified !");
if(!((const MEDCouplingFieldDiscretization *)_type))
#include "DEC.hxx"
#include "ICoCoField.hxx"
#include "ICoCoMEDField.hxx"
-#include "ICoCoTrioField.hxx"
#include "MPIProcessorGroup.hxx"
#include <cmath>
#include "ParaMESH.hxx"
#include "ICoCoField.hxx"
#include "ICoCoMEDField.hxx"
-#include "ICoCoTrioField.hxx"
#include "MPIProcessorGroup.hxx"
#include <cmath>
_source_group(&source_group),
_target_group(&target_group),
_owns_field(false),
- _owns_groups(false),
- _icoco_field(0)
+ _owns_groups(false)
{
_union_group = source_group.fuse(target_group);
}
- DisjointDEC::DisjointDEC(const DisjointDEC& s):DEC(s),_local_field(0),_union_group(0),_source_group(0),_target_group(0),_owns_field(false),_owns_groups(false),_icoco_field(0)
+ DisjointDEC::DisjointDEC(const DisjointDEC& s):DEC(s),_local_field(0),_union_group(0),_source_group(0),_target_group(0),_owns_field(false),_owns_groups(false)
{
copyInstance(s);
}
DisjointDEC::DisjointDEC(const std::set<int>& source_ids, const std::set<int>& target_ids, const MPI_Comm& world_comm):_local_field(0),
_owns_field(false),
- _owns_groups(true),
- _icoco_field(0)
+ _owns_groups(true)
{
ParaMEDMEM::CommInterface comm;
// Create the list of procs including source and target
_owns_groups=false;
_source_group=0;
_target_group=0;
- delete _icoco_field;
- _icoco_field=0;
delete _union_group;
_union_group=0;
}
will be updated by a recvData() call.
Reversely, if the processor is on the sending end, the field will be read, possibly transformed, and sent appropriately to the other side.
*/
- void DisjointDEC::attachLocalField(const ParaFIELD* field, bool ownPt)
+ void DisjointDEC::attachLocalField(const ParaFIELD *field, bool ownPt)
{
if(!isInUnion())
return ;
and sent appropriately to the other side.
*/
- void DisjointDEC::attachLocalField(MEDCouplingFieldDouble* field)
+ void DisjointDEC::attachLocalField(MEDCouplingFieldDouble *field)
{
if(!isInUnion())
return ;
- a ICOCo::TrioField, that is created from tables extracted from a TRIO-U structure.
*/
- void DisjointDEC::attachLocalField(const ICoCo::Field* field)
+ void DisjointDEC::attachLocalField(const ICoCo::MEDField *field)
{
if(!isInUnion())
return ;
- const ICoCo::MEDField* medfield=dynamic_cast<const ICoCo::MEDField*> (field);
- if(medfield !=0)
- {
- attachLocalField(medfield->getField());
- return;
- }
- const ICoCo::TrioField* triofield=dynamic_cast<const ICoCo::TrioField*> (field);
- if (triofield !=0)
- {
- /* Strange part of code localgroup not used !
- ProcessorGroup* localgroup;
- if (_source_group->containsMyRank())
- localgroup=_source_group;
- else
- localgroup=_target_group;*/
- delete _icoco_field;
-
- _icoco_field=new ICoCo::MEDField(*const_cast<ICoCo::TrioField* >(triofield));
- attachLocalField(_icoco_field);
- return;
- }
- throw INTERP_KERNEL::Exception("incompatible field type");
+ if(!field)
+ throw INTERP_KERNEL::Exception("DisjointDEC::attachLocalField : ICoCo::MEDField pointer is NULL !");
+ attachLocalField(field->getField());
}
/*!
namespace ICoCo
{
- class Field;
+ class MEDField;
}
namespace ParaMEDMEM
class DisjointDEC : public DEC
{
public:
- DisjointDEC():_local_field(0),_union_group(0),_source_group(0),_target_group(0),_owns_field(false),_owns_groups(false),_icoco_field(0) { }
+ DisjointDEC():_local_field(0),_union_group(0),_source_group(0),_target_group(0),_owns_field(false),_owns_groups(false) { }
DisjointDEC(ProcessorGroup& source_group, ProcessorGroup& target_group);
DisjointDEC(const DisjointDEC&);
DisjointDEC &operator=(const DisjointDEC& s);
DisjointDEC(const std::set<int>& src_ids, const std::set<int>& trg_ids,
const MPI_Comm& world_comm=MPI_COMM_WORLD);
void setNature(NatureOfField nature);
- void attachLocalField( MEDCouplingFieldDouble* field);
- void attachLocalField(const ParaFIELD* field, bool ownPt=false);
- void attachLocalField(const ICoCo::Field* field);
+ void attachLocalField( MEDCouplingFieldDouble *field);
+ void attachLocalField(const ParaFIELD *field, bool ownPt=false);
+ void attachLocalField(const ICoCo::MEDField *field);
virtual void prepareSourceDE() = 0;
virtual void prepareTargetDE() = 0;
const CommInterface* _comm_interface;
bool _owns_field;
bool _owns_groups;
- private:
- ICoCo::Field* _icoco_field;
};
}
}
else
{
- vector <int> size (group->size());
+ vector <int> size2(group->size());
int myworldrank=group->myRank();
for (int iproc=0; iproc<group->size();iproc++)
{
int sendlocal=topotemp->globalToLocal(global);
if (sendlocal!=-1)
{
- size[iproc]++;
+ size2[iproc]++;
_explicit_mapping.pushBackElem(make_pair(iproc,sendlocal));
}
}
using namespace ICoCo;
using std::string;
-Field::Field() {
- _name=new string;
+Field::Field()
+{
}
-Field::~Field() {
- delete _name;
+Field::~Field()
+{
}
-void Field::setName(const string& name) {
- *_name=name;
+void Field::setName(const string& name)
+{
+ _name=name;
}
-const string& Field::getName() const {
- return *_name;
+const string& Field::getName() const
+{
+ return _name;
}
-const char* Field::getCharName() const {
- return _name->c_str();
+const char *Field::getCharName() const
+{
+ return _name.c_str();
}
#ifndef _ICoCoField_included_
#define _ICoCoField_included_
-#include <string>
-
-namespace ICoCo {
+#include <string>
- class Field {
+namespace ICoCo
+{
+ class Field
+ {
public:
Field();
virtual ~Field();
void setName(const std::string& name);
const std::string& getName() const;
- const char* getCharName() const;
-
+ const char *getCharName() const;
private:
- std::string* _name;
+ std::string _name;
};
}
+
#endif
//
#include "ICoCoMEDField.hxx"
-#include "ICoCoTrioField.hxx"
#include "ProcessorGroup.hxx"
#include "MEDCouplingUMesh.hxx"
#include "MEDCouplingFieldDouble.hxx"
namespace ICoCo
{
- /*! Constructor directly attaching a MEDCouplingUMesh and a MEDCouplingFieldDouble
+ /*! Constructor directly attaching a MEDCouplingFieldDouble
the object does not take the control the objects pointed by
- \a mesh and \a field.
+ \a field.
*/
- MEDField::MEDField(ParaMEDMEM::MEDCouplingUMesh* mesh, ParaMEDMEM::MEDCouplingFieldDouble* field):
- _mesh(mesh),
- _field(field)
+ MEDField::MEDField(ParaMEDMEM::MEDCouplingFieldDouble *field):_field(field)
{
- if(_mesh)
- _mesh->incrRef();
if(_field)
_field->incrRef();
}
-
- MEDField::MEDField(TrioField& triofield)
- {
- _mesh = ParaMEDMEM::MEDCouplingUMesh::New();
- _mesh->setMeshDimension(triofield._space_dim);
- ParaMEDMEM::DataArrayDouble *myCoords=ParaMEDMEM::DataArrayDouble::New();
- myCoords->alloc(triofield._nbnodes,triofield._space_dim);
- _mesh->setCoords(myCoords);
- myCoords->decrRef();
- double *ptr=myCoords->getPointer();
- std::copy(triofield._coords,triofield._coords+triofield._space_dim*triofield._nbnodes,ptr);
- _mesh->allocateCells(triofield._nb_elems);
- INTERP_KERNEL::NormalizedCellType elemtype;
- switch (triofield._mesh_dim)
- {
- case 1:
- switch (triofield._nodes_per_elem)
- {
- case 2:
- elemtype=INTERP_KERNEL::NORM_SEG2;
- break;
- default:
- throw INTERP_KERNEL::Exception("incompatible Trio field - wrong nb of nodes per elem");
- }
- case 2:
- switch (triofield._nodes_per_elem)
- {
- case 3:
- elemtype=INTERP_KERNEL::NORM_TRI3;
- break;
- case 4 :
- elemtype=INTERP_KERNEL::NORM_QUAD4;
- break;
- default:
- throw INTERP_KERNEL::Exception("incompatible Trio field - wrong nb of nodes per elem");
- }
- break;
- case 3:
- switch (triofield._nodes_per_elem)
- {
- case 4:
- elemtype=INTERP_KERNEL::NORM_TETRA4;
- break;
- case 8 :
- elemtype=INTERP_KERNEL::NORM_HEXA8;
- break;
- default:
- throw INTERP_KERNEL::Exception("incompatible Trio field - wrong nb of nodes per elem");
- }
- break;
- default:
- throw INTERP_KERNEL::Exception("incompatible Trio field - wrong mesh dimension");
- }
- //creating a connectivity table that complies to MED (1 indexing)
- //and passing it to _mesh
- int* conn=new int[triofield._nodes_per_elem];
- _mesh->setMeshDimension(triofield._mesh_dim);
- for (int i=0; i<triofield._nb_elems;i++)
- {
- for(int j=0;j<triofield._nodes_per_elem;j++)
- {
- conn[j]=(triofield._connectivity)[i*triofield._nodes_per_elem+j];
- }
- _mesh->insertNextCell(elemtype,triofield._nodes_per_elem,conn);
- }
- delete[] conn;
-
- _mesh->finishInsertingCells();
-
- //field on the sending end
- int nb_case=triofield.nb_values();
- if (triofield._type==0)
- {
- _field = ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
- }
- else
- {
- _field = ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES,ParaMEDMEM::ONE_TIME );
- }
- _field->setMesh(_mesh);
- _field->setNature(ParaMEDMEM::ConservativeVolumic);
- ParaMEDMEM::DataArrayDouble *fieldArr=ParaMEDMEM::DataArrayDouble::New();
- fieldArr->alloc(_field->getNumberOfTuples(),triofield._nb_field_components);
- _field->setName(triofield.getName().c_str());
- std::string meshName("SupportOf_"); meshName+=_field->getName();
- _mesh->setName(meshName.c_str());
- _field->setTime(triofield._time1,0,triofield._itnumber);
- if (triofield._field!=0)
- {
- for (int i =0; i<nb_case; i++)
- for (int j=0; j<triofield._nb_field_components; j++)
- {
- fieldArr->setIJ(i,j,triofield._field[i*triofield._nb_field_components+j]);
- }
- }
- //field on the receiving end
- else
- {
- // the trio field points to the pointer inside the MED field
- triofield._field=const_cast<double*> (fieldArr->getPointer());
- for (int i=0; i<triofield._nb_field_components*nb_case;i++)
- triofield._field[i]=0.0;
- }
- _field->setArray(fieldArr);
- fieldArr->decrRef();
- }
MEDField::~MEDField()
{
if(_field)
_field->decrRef();
- if(_mesh)
- _mesh->decrRef();
}
}
class MEDField : public ICoCo::Field
{
public:
- MEDField():_mesh(0),_field(0) { }
- MEDField(ParaMEDMEM::MEDCouplingUMesh* mesh, ParaMEDMEM::MEDCouplingFieldDouble* field);
- MEDField(TrioField&);
+ MEDField():_field(0) { }
+ MEDField(ParaMEDMEM::MEDCouplingFieldDouble* field);
virtual ~MEDField();
- ParaMEDMEM::MEDCouplingFieldDouble* getField() const { return _field; }
- ParaMEDMEM::MEDCouplingUMesh* getMesh()const { return _mesh; }
+ ParaMEDMEM::MEDCouplingFieldDouble *getField() const { return _field; }
+ const ParaMEDMEM::MEDCouplingMesh *getMesh() const { return _field->getMesh(); }
private:
- ParaMEDMEM::MEDCouplingUMesh* _mesh;
- ParaMEDMEM::MEDCouplingFieldDouble* _field;
+ ParaMEDMEM::MEDCouplingFieldDouble *_field;
};
}
// version 1.2 10/05/2010
#include <ICoCoTrioField.hxx>
+
+#include "ICoCoMEDField.hxx"
+#include "MEDCouplingUMesh.hxx"
+#include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingAutoRefCountObjectPtr.hxx"
+
#include <string.h>
#include <iostream>
#include <iomanip>
}
+/*!
+ * This method is non const only due to this->_field that can be modified (to point to the same zone than returned object).
+ * So \b warning, to access to \a this->_field only when the returned object is alive.
+ */
+MEDField *TrioField::build_medfield()
+{
+ ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingUMesh> mesh(ParaMEDMEM::MEDCouplingUMesh::New("",_mesh_dim));
+ ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> coo(ParaMEDMEM::DataArrayDouble::New()); coo->alloc(_nbnodes,_space_dim);
+ mesh->setCoords(coo);
+ double *ptr(coo->getPointer());
+ std::copy(_coords,_coords+_space_dim*_nbnodes,ptr);
+ mesh->allocateCells(_nb_elems);
+ INTERP_KERNEL::NormalizedCellType elemtype;
+ switch(_mesh_dim)
+ {
+ case 1:
+ {
+ switch (_nodes_per_elem)
+ {
+ case 2:
+ elemtype=INTERP_KERNEL::NORM_SEG2;
+ break;
+ default:
+ throw INTERP_KERNEL::Exception("incompatible Trio field - wrong nb of nodes per elem");
+ }
+ break;
+ }
+ case 2:
+ {
+ switch (_nodes_per_elem)
+ {
+ case 3:
+ elemtype=INTERP_KERNEL::NORM_TRI3;
+ break;
+ case 4 :
+ elemtype=INTERP_KERNEL::NORM_QUAD4;
+ break;
+ default:
+ throw INTERP_KERNEL::Exception("incompatible Trio field - wrong nb of nodes per elem");
+ }
+ break;
+ }
+ case 3:
+ {
+ switch (_nodes_per_elem)
+ {
+ case 4:
+ elemtype=INTERP_KERNEL::NORM_TETRA4;
+ break;
+ case 8 :
+ elemtype=INTERP_KERNEL::NORM_HEXA8;
+ break;
+ default:
+ throw INTERP_KERNEL::Exception("incompatible Trio field - wrong nb of nodes per elem");
+ }
+ break;
+ default:
+ throw INTERP_KERNEL::Exception("incompatible Trio field - wrong mesh dimension");
+ }
+ }
+ //creating a connectivity table that complies to MED (1 indexing)
+ //and passing it to _mesh
+ ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> field;
+ int *conn(new int[_nodes_per_elem]);
+ for (int i=0; i<_nb_elems;i++)
+ {
+ for(int j=0;j<_nodes_per_elem;j++)
+ {
+ conn[j]=_connectivity[i*_nodes_per_elem+j];
+ }
+ mesh->insertNextCell(elemtype,_nodes_per_elem,conn);
+ }
+ delete [] conn;
+ mesh->finishInsertingCells();
+ //
+ //field on the sending end
+ int nb_case=nb_values();
+ if (_type==0)
+ {
+ field = ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
+ }
+ else
+ {
+ field = ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES,ParaMEDMEM::ONE_TIME );
+ }
+ field->setMesh(mesh);
+ field->setNature(ParaMEDMEM::ConservativeVolumic);
+ ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> fieldArr(ParaMEDMEM::DataArrayDouble::New());
+ fieldArr->alloc(field->getNumberOfTuplesExpected(),_nb_field_components);
+ field->setName(getName().c_str());
+ std::string meshName("SupportOf_"); meshName+=getName();
+ mesh->setName(meshName.c_str());
+ field->setTime(_time1,0,_itnumber);
+ if (_field!=0)
+ {
+ for (int i =0; i<nb_case; i++)
+ for (int j=0; j<_nb_field_components; j++)
+ {
+ fieldArr->setIJ(i,j,_field[i*_nb_field_components+j]);
+ }
+ }
+ //field on the receiving end
+ else
+ {
+ // the trio field points to the pointer inside the MED field
+ _field=fieldArr->getPointer();
+ for (int i=0; i<_nb_field_components*nb_case;i++)
+ _field[i]=0.0;
+ }
+ field->setArray(fieldArr);
+ return new MEDField(field);
+}
+
#include <ICoCoField.hxx>
namespace ICoCo {
-
+ class MEDField;
//////////////////////////////////////////////////////////////////////////////
//
// .DESCRIPTION
void save(std::ostream& os) const;
void restore(std::istream& in);
int nb_values() const ;
-
+ MEDField *build_medfield();
public:
int _type ; // 0 elem 1 nodes
int _mesh_dim;
ParaMEDMEM::MEDCouplingUMesh* mesh;
ParaMEDMEM::ParaMESH* paramesh;
ParaMEDMEM::ParaFIELD* parafield;
- ICoCo::Field* icocofield ;
+ ICoCo::MEDField* icocofield ;
string filename_xml1 = getResourceFile("square1_split");
string filename_xml2 = getResourceFile("square2_split");
value[ielem]=1.0;
// ICoCo::Field* icocofield=new ICoCo::MEDField(paramesh,parafield);
- icocofield=new ICoCo::MEDField((MEDCouplingUMesh *)paramesh->getCellMesh(),parafield->getField());
+ icocofield=new ICoCo::MEDField(parafield->getField());
dec.setMethod(srcMeth);
dec.attachLocalField(icocofield);
}
for(int ielem=0; ielem<nb_local;ielem++)
value[ielem]=0.0;
// ICoCo::Field* icocofield=new ICoCo::MEDField(paramesh,parafield);
- icocofield=new ICoCo::MEDField((MEDCouplingUMesh *)paramesh->getCellMesh(),parafield->getField());
+ icocofield=new ICoCo::MEDField(parafield->getField());
dec.setMethod(targetMeth);
dec.attachLocalField(icocofield);
}
ParaMEDMEM::MEDCouplingUMesh* mesh;
ParaMEDMEM::ParaMESH* paramesh;
ParaMEDMEM::ParaFIELD* parafield;
- ICoCo::Field* icocofield ;
+ ICoCo::MEDField* icocofield ;
string tmp_dir = getenv("TMP");
if (tmp_dir == "")
value[ielem]=1.0;
// ICoCo::Field* icocofield=new ICoCo::MEDField(paramesh,parafield);
- icocofield=new ICoCo::MEDField((MEDCouplingUMesh *)paramesh->getCellMesh(),parafield->getField());
+ icocofield=new ICoCo::MEDField(parafield->getField());
dec.setMethod(srcMeth);
dec.attachLocalField(icocofield);
}
for(int ielem=0; ielem<nb_local;ielem++)
value[ielem]=0.0;
// ICoCo::Field* icocofield=new ICoCo::MEDField(paramesh,parafield);
- icocofield=new ICoCo::MEDField((MEDCouplingUMesh *)paramesh->getCellMesh(),parafield->getField());
+ icocofield=new ICoCo::MEDField(parafield->getField());
dec.setMethod(targetMeth);
dec.attachLocalField(icocofield);
}
ParaMEDMEM::ParaMESH* paramesh;
ParaMEDMEM::ParaFIELD* parafield;
- ICoCo::Field* icocofield ;
+ ICoCo::MEDField* icocofield ;
string tmp_dir = getenv("TMP");
if (tmp_dir == "")
value[ielem]=0.0;
// ICoCo::Field* icocofield=new ICoCo::MEDField(paramesh,parafield);
- icocofield=new ICoCo::MEDField((MEDCouplingUMesh *)paramesh->getCellMesh(),parafield->getField());
+ icocofield=new ICoCo::MEDField(parafield->getField());
dec.attachLocalField(icocofield);
for(int ielem=0; ielem<nb_local;ielem++)
value[ielem]=0.0;
// ICoCo::Field* icocofield=new ICoCo::MEDField(paramesh,parafield);
- icocofield=new ICoCo::MEDField((MEDCouplingUMesh *)paramesh->getCellMesh(),parafield->getField());
+ icocofield=new ICoCo::MEDField(parafield->getField());
dec.attachLocalField(icocofield);
}
ParaMEDMEM::MEDCouplingUMesh* mesh;
ParaMEDMEM::ParaMESH* paramesh;
ParaMEDMEM::ParaFIELD* parafield;
- ICoCo::Field* icocofield ;
+ ICoCo::MEDField* icocofield ;
// To remove tmp files from disk
ParaMEDMEMTest_TmpFilesRemover aRemover;
for(int ielem=0; ielem<nb_local;ielem++)
value[ielem]=1.0;
- icocofield=new ICoCo::MEDField((MEDCouplingUMesh *)paramesh->getCellMesh(),parafield->getField());
+ icocofield=new ICoCo::MEDField(parafield->getField());
dec.attachLocalField(icocofield);
}
double *value=parafield->getField()->getArray()->getPointer();
for(int ielem=0; ielem<nb_local;ielem++)
value[ielem]=0.0;
- icocofield=new ICoCo::MEDField((MEDCouplingUMesh *)paramesh->getCellMesh(),parafield->getField());
+ icocofield=new ICoCo::MEDField(parafield->getField());
dec.attachLocalField(icocofield);
}