if(_mesh)
_mesh->decrRef();
_mesh=mesh;
+ declareAsNew();
if(_mesh)
{
_mesh->incrRef();
return _discr_per_cell;
}
+void MEDCouplingFieldDiscretizationPerCell::setArrayOfDiscIds(const DataArrayInt *adids) throw(INTERP_KERNEL::Exception)
+{
+ if(adids!=_discr_per_cell)
+ {
+ if(_discr_per_cell)
+ _discr_per_cell->decrRef();
+ _discr_per_cell=const_cast<DataArrayInt *>(adids);
+ if(_discr_per_cell)
+ _discr_per_cell->incrRef();
+ declareAsNew();
+ }
+}
+
MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss()
{
}
_loc.clear();
}
+void MEDCouplingFieldDiscretizationGauss::setGaussLocalization(int locId, const MEDCouplingGaussLocalization& loc) throw(INTERP_KERNEL::Exception)
+{
+ if(locId<0)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::setGaussLocalization : localization id has to be >=0 !");
+ int sz=(int)_loc.size();
+ MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR);
+ if(locId>=sz)
+ _loc.resize(locId+1,gLoc);
+ _loc[locId]=loc;
+}
+
+void MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector(int newSz) throw(INTERP_KERNEL::Exception)
+{
+ if(newSz<0)
+ throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::resizeLocalizationVector : new size has to be >=0 !");
+ MEDCouplingGaussLocalization gLoc(INTERP_KERNEL::NORM_ERROR);
+ _loc.resize(newSz,gLoc);
+}
+
MEDCouplingGaussLocalization& MEDCouplingFieldDiscretizationGauss::getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception)
{
checkLocalizationId(locId);
//
return ret.retn();
}
-
{
public:
const DataArrayInt *getArrayOfDiscIds() const;
+ void setArrayOfDiscIds(const DataArrayInt *adids) throw(INTERP_KERNEL::Exception);
void checkNoOrphanCells() const throw(INTERP_KERNEL::Exception);
std::vector<DataArrayInt *> splitIntoSingleGaussDicrPerCellType(std::vector< int >& locIds) const throw(INTERP_KERNEL::Exception);
protected:
void setGaussLocalizationOnCells(const MEDCouplingMesh *m, const int *begin, const int *end, const std::vector<double>& refCoo,
const std::vector<double>& gsCoo, const std::vector<double>& wg) throw(INTERP_KERNEL::Exception);
void clearGaussLocalizations() throw(INTERP_KERNEL::Exception);
+ void setGaussLocalization(int locId, const MEDCouplingGaussLocalization& loc) throw(INTERP_KERNEL::Exception);
+ void resizeLocalizationVector(int newSz) throw(INTERP_KERNEL::Exception);
MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception);
int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception);
int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception);
std::ostringstream ret;
ret << "FieldDouble with name : \"" << getName() << "\"\n";
ret << "Description of field is : \"" << getDescription() << "\"\n";
- ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n";
- ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n";
- ret << "FieldDouble nature of field is : " << MEDCouplingNatureOfField::GetRepr(_nature) << "\n";
+ if(_type)
+ { ret << "FieldDouble space discretization is : " << _type->getStringRepr() << "\n"; }
+ else
+ { ret << "FieldDouble has no spatial discretization !\n"; }
+ if(_time_discr)
+ { ret << "FieldDouble time discretization is : " << _time_discr->getStringRepr() << "\n"; }
+ else
+ { ret << "FieldDouble has no time discretization !\n"; }
+ ret << "FieldDouble nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
if(getArray())
{
- int nbOfCompo=getArray()->getNumberOfComponents();
- ret << "FieldDouble default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n";
- ret << "FieldDouble default array has following info on components : ";
- for(int i=0;i<nbOfCompo;i++)
- ret << "\"" << getArray()->getInfoOnComponent(i) << "\" ";
- ret << "\n";
+ if(getArray()->isAllocated())
+ {
+ int nbOfCompo=getArray()->getNumberOfComponents();
+ ret << "FieldDouble default array has " << nbOfCompo << " components and " << getArray()->getNumberOfTuples() << " tuples.\n";
+ ret << "FieldDouble default array has following info on components : ";
+ for(int i=0;i<nbOfCompo;i++)
+ ret << "\"" << getArray()->getInfoOnComponent(i) << "\" ";
+ ret << "\n";
+ }
+ else
+ {
+ ret << "Array set but not allocated !\n";
+ }
}
if(_mesh)
ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
std::ostringstream ret;
ret << "FieldTemplate with name : \"" << getName() << "\"\n";
ret << "Description of field is : \"" << getDescription() << "\"\n";
- ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n";
- ret << "FieldTemplate nature of field is : " << MEDCouplingNatureOfField::GetRepr(_nature) << "\n";
+ if(_type)
+ { ret << "FieldTemplate space discretization is : " << _type->getStringRepr() << "\n"; }
+ else
+ { ret << "FieldTemplate has no spatial discretization !\n"; }
+ ret << "FieldTemplate nature of field is : \"" << MEDCouplingNatureOfField::GetReprNoThrow(_nature) << "\"\n";
if(_mesh)
ret << "Mesh support information :\n__________________________\n" << _mesh->simpleRepr();
else
throw e;
}
+ParaMEDMEM::MEDCouplingGaussLocalization::MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType typ) throw(INTERP_KERNEL::Exception)
+try:_type(typ)
+{
+ INTERP_KERNEL::CellModel::GetCellModel(_type);
+}
+catch(INTERP_KERNEL::Exception& e)
+ {
+ _type=INTERP_KERNEL::NORM_ERROR;
+ throw e;
+ }
+
+void ParaMEDMEM::MEDCouplingGaussLocalization::setType(INTERP_KERNEL::NormalizedCellType typ) throw(INTERP_KERNEL::Exception)
+{
+ INTERP_KERNEL::CellModel::GetCellModel(typ);//throws if not found. This is a check
+ _type=typ;
+}
+
void ParaMEDMEM::MEDCouplingGaussLocalization::checkCoherency() const throw(INTERP_KERNEL::Exception)
{
const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_type);
_weight[gaussPtIdInCell]=newVal;
}
+void ParaMEDMEM::MEDCouplingGaussLocalization::setRefCoords(const std::vector<double>& refCoo) throw(INTERP_KERNEL::Exception)
+{
+ _ref_coord=refCoo;
+}
+
+void ParaMEDMEM::MEDCouplingGaussLocalization::setGaussCoords(const std::vector<double>& gsCoo) throw(INTERP_KERNEL::Exception)
+{
+ _gauss_coord=gsCoo;
+}
+
+void ParaMEDMEM::MEDCouplingGaussLocalization::setWeights(const std::vector<double>& w) throw(INTERP_KERNEL::Exception)
+{
+ _weight=w;
+}
+
/*!
* The format of 'tinyData' parameter is the same than pushed in method ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationIntInfo.
*/
public:
MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType type, const std::vector<double>& refCoo,
const std::vector<double>& gsCoo, const std::vector<double>& w) throw(INTERP_KERNEL::Exception);
+ MEDCouplingGaussLocalization(INTERP_KERNEL::NormalizedCellType typ) throw(INTERP_KERNEL::Exception);
INTERP_KERNEL::NormalizedCellType getType() const { return _type; }
+ void setType(INTERP_KERNEL::NormalizedCellType typ) throw(INTERP_KERNEL::Exception);
int getNumberOfGaussPt() const { return (int)_weight.size(); }
int getDimension() const;
int getNumberOfPtsInRefCell() const;
void setRefCoord(int ptIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception);
void setGaussCoord(int gaussPtIdInCell, int comp, double newVal) throw(INTERP_KERNEL::Exception);
void setWeight(int gaussPtIdInCell, double newVal) throw(INTERP_KERNEL::Exception);
+ void setRefCoords(const std::vector<double>& refCoo) throw(INTERP_KERNEL::Exception);
+ void setGaussCoords(const std::vector<double>& gsCoo) throw(INTERP_KERNEL::Exception);
+ void setWeights(const std::vector<double>& w) throw(INTERP_KERNEL::Exception);
//
static MEDCouplingGaussLocalization BuildNewInstanceFromTinyInfo(int dim, const std::vector<int>& tinyData);
static bool AreAlmostEqual(const std::vector<double>& v1, const std::vector<double>& v2, double eps);
std::size_t pos2=std::distance(POS_OF_NATUREOFFIELD,pos);
return REPR_OF_NATUREOFFIELD[pos2];
}
+
+ std::string MEDCouplingNatureOfField::GetReprNoThrow(NatureOfField nat)
+ {
+ const int *pos=std::find(POS_OF_NATUREOFFIELD,POS_OF_NATUREOFFIELD+NB_OF_POSSIBILITIES,(int)nat);
+ if(pos==POS_OF_NATUREOFFIELD+NB_OF_POSSIBILITIES)
+ return std::string("Unrecognized nature of field !");
+ std::size_t pos2=std::distance(POS_OF_NATUREOFFIELD,pos);
+ return std::string(REPR_OF_NATUREOFFIELD[pos2]);
+ }
}
{
public:
MEDCOUPLING_EXPORT static const char *GetRepr(NatureOfField nat) throw(INTERP_KERNEL::Exception);
+ MEDCOUPLING_EXPORT static std::string GetReprNoThrow(NatureOfField nat);
private:
static const int NB_OF_POSSIBILITIES=5;
static const char *REPR_OF_NATUREOFFIELD[NB_OF_POSSIBILITIES];
self.assertTrue(d.isEqual(DataArrayInt([0,0,0,0,0,0])))
self.assertTrue(e.isEqual(DataArrayInt([0,1,2,3,4,5,6])))
pass
+
+ def testSwigAdvGauss(self):
+ f=MEDCouplingFieldTemplate(ON_GAUSS_PT)
+ f.setDiscretization(None)
+ f.__repr__() ; f.__str__()
+ #
+ f=MEDCouplingFieldTemplate(ON_GAUSS_PT)
+ d=f.getDiscretization()
+ i=DataArrayInt() ; i.alloc(10,1) ; i.iota(1)
+ d.setArrayOfDiscIds(i)
+ f.__repr__() ; f.__str__()
+ i2=d.getArrayOfDiscIds()
+ self.assertEqual(i.__repr__(),i2.__repr__())
+ #
+ f=MEDCouplingFieldDouble(ON_GAUSS_PT)
+ f.setDiscretization(None)
+ f.__repr__() ; f.__str__()
+ #
+ f=MEDCouplingFieldDouble(ON_GAUSS_PT)
+ d=f.getDiscretization()
+ i=DataArrayInt() ; i.alloc(10,1) ; i.iota(1)
+ d.setArrayOfDiscIds(i)
+ f.__repr__() ; f.__str__()
+ #
+ gl=MEDCouplingGaussLocalization(NORM_SEG2,[0,1],[0.5],[1.])
+ gl.setWeights([3.])
+ gl.__repr__() ; gl.__str__()
+ gl=MEDCouplingGaussLocalization(NORM_ERROR)
+ gl.setWeights([3.])
+ gl.__repr__() ; gl.__str__()
+ pass
def setUp(self):
pass
}
}
+ %extend MEDCouplingGaussLocalization
+ {
+ std::string __str__() const throw(INTERP_KERNEL::Exception)
+ {
+ return self->getStringRepr();
+ }
+
+ std::string __repr__() const throw(INTERP_KERNEL::Exception)
+ {
+ std::ostringstream oss; oss << "MEDCouplingGaussLocalization C++ instance at " << self << "." << std::endl;
+ oss << self->getStringRepr();
+ return oss.str();
+ }
+ }
+
class MEDCouplingMesh : public RefCountObject, public TimeLabel
{
public: